力皓 e18a3863cf fix: 修复 prop 无法删除最后一个 item
refactor(test): 增加 prop/props 部分的单测
refactor: 不再给非 vc 组件传入 _leaf
2020-12-15 09:59:51 +08:00

54 lines
1.4 KiB
TypeScript

import { isI18NObject } from './is-object';
import get from 'lodash.get';
import { ComponentMeta } from '@ali/lowcode-designer';
export function isUseI18NSetter(prototype: any, propName: string) {
const configure = prototype?.options?.configure;
if (Array.isArray(configure)) {
return configure.some(c => {
return c.name === propName && c?.setter?.type?.displayName === 'I18nSetter';
});
}
return false;
}
export function convertToI18NObject(v: string | object, locale: string = 'zh_CN') {
if (isI18NObject(v)) return v;
return { type: 'i18n', use: locale, [locale]: v };
}
export function isString(v: any): v is string {
return typeof v === 'string';
}
function _innerWaitForThing(obj: any, path: string): Promise<any> {
const timeGap = 200;
return new Promise((resolve, reject) => {
setTimeout(() => {
const thing = get(obj, path);
if (thing) {
return resolve(thing);
}
reject();
}, timeGap);
}).catch(() => {
return _innerWaitForThing(obj, path);
});
}
export function waitForThing(obj: any, path: string): Promise<any> {
const thing = get(obj, path);
if (thing) {
return Promise.resolve(thing);
}
return _innerWaitForThing(obj, path);
}
/**
* 判断当前 meta 是否从 vc prototype 转换而来
* @param meta
*/
export function isFromVC(meta: ComponentMeta) {
return !!meta?.getMetadata()?.experimental;
}