mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-12 03:01:16 +00:00
feat: update setter types
This commit is contained in:
parent
4a18f71ebc
commit
aab8a3a10e
@ -1,8 +1,7 @@
|
|||||||
import { ReactNode } from 'react';
|
import { ReactNode } from 'react';
|
||||||
import { IPublicTypeCustomView, IPublicTypeRegisteredSetter } from '@alilc/lowcode-types';
|
import { IPublicApiSetters, IPublicTypeCustomView, IPublicTypeRegisteredSetter } from '@alilc/lowcode-types';
|
||||||
import { createContent, isCustomView } from '@alilc/lowcode-utils';
|
import { createContent, isCustomView } from '@alilc/lowcode-utils';
|
||||||
|
|
||||||
|
|
||||||
const settersMap = new Map<string, IPublicTypeRegisteredSetter & {
|
const settersMap = new Map<string, IPublicTypeRegisteredSetter & {
|
||||||
type: string;
|
type: string;
|
||||||
}>();
|
}>();
|
||||||
@ -44,13 +43,17 @@ function getInitialFromSetter(setter: any) {
|
|||||||
) || null; // eslint-disable-line
|
) || null; // eslint-disable-line
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Setters {
|
export interface ISetters extends IPublicApiSetters {
|
||||||
constructor(readonly viewName: string = 'global') {}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Setters implements ISetters {
|
||||||
settersMap = new Map<string, IPublicTypeRegisteredSetter & {
|
settersMap = new Map<string, IPublicTypeRegisteredSetter & {
|
||||||
type: string;
|
type: string;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
|
constructor(readonly viewName: string = 'global') {}
|
||||||
|
|
||||||
getSetter = (type: string): IPublicTypeRegisteredSetter | null => {
|
getSetter = (type: string): IPublicTypeRegisteredSetter | null => {
|
||||||
return this.settersMap.get(type) || null;
|
return this.settersMap.get(type) || null;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,14 +1,13 @@
|
|||||||
import { Component, MouseEvent, Fragment } from 'react';
|
import { Component, MouseEvent, Fragment, ReactNode } from 'react';
|
||||||
import { shallowIntl, observer, obx, engineConfig, runInAction } from '@alilc/lowcode-editor-core';
|
import { shallowIntl, observer, obx, engineConfig, runInAction } from '@alilc/lowcode-editor-core';
|
||||||
import { createContent, isJSSlot, isSetterConfig } from '@alilc/lowcode-utils';
|
import { createContent, isJSSlot, isSetterConfig } from '@alilc/lowcode-utils';
|
||||||
import { Skeleton, Stage } from '@alilc/lowcode-editor-skeleton';
|
import { Skeleton, Stage } from '@alilc/lowcode-editor-skeleton';
|
||||||
import { IPublicTypeCustomView } from '@alilc/lowcode-types';
|
import { IPublicApiSetters, IPublicTypeCustomView, IPublicTypeDynamicProps } from '@alilc/lowcode-types';
|
||||||
import { ISettingEntry, IComponentMeta, ISettingField, isSettingField, ISettingTopEntry } from '@alilc/lowcode-designer';
|
import { ISettingEntry, IComponentMeta, ISettingField, isSettingField, ISettingTopEntry } from '@alilc/lowcode-designer';
|
||||||
import { createField } from '../field';
|
import { createField } from '../field';
|
||||||
import PopupService, { PopupPipe } from '../popup';
|
import PopupService, { PopupPipe } from '../popup';
|
||||||
import { SkeletonContext } from '../../context';
|
import { SkeletonContext } from '../../context';
|
||||||
import { intl } from '../../locale';
|
import { intl } from '../../locale';
|
||||||
import { Setters } from '@alilc/lowcode-shell';
|
|
||||||
|
|
||||||
function isStandardComponent(componentMeta: IComponentMeta | null) {
|
function isStandardComponent(componentMeta: IComponentMeta | null) {
|
||||||
if (!componentMeta) return false;
|
if (!componentMeta) return false;
|
||||||
@ -40,7 +39,7 @@ class SettingFieldView extends Component<SettingFieldViewProps, SettingFieldView
|
|||||||
|
|
||||||
stageName: string | undefined;
|
stageName: string | undefined;
|
||||||
|
|
||||||
setters?: Setters;
|
setters?: IPublicApiSetters;
|
||||||
|
|
||||||
constructor(props: SettingFieldViewProps) {
|
constructor(props: SettingFieldViewProps) {
|
||||||
super(props);
|
super(props);
|
||||||
@ -112,7 +111,9 @@ class SettingFieldView extends Component<SettingFieldViewProps, SettingFieldView
|
|||||||
const { defaultValue } = extraProps;
|
const { defaultValue } = extraProps;
|
||||||
|
|
||||||
const { setter } = this.field;
|
const { setter } = this.field;
|
||||||
let setterProps: any = {};
|
let setterProps: {
|
||||||
|
setters?: (ReactNode | string)[];
|
||||||
|
} & Record<string, unknown> | IPublicTypeDynamicProps = {};
|
||||||
let setterType: any;
|
let setterType: any;
|
||||||
let initialValue: any = null;
|
let initialValue: any = null;
|
||||||
|
|
||||||
@ -236,7 +237,7 @@ class SettingFieldView extends Component<SettingFieldViewProps, SettingFieldView
|
|||||||
...extraProps,
|
...extraProps,
|
||||||
},
|
},
|
||||||
!stageName &&
|
!stageName &&
|
||||||
this.setters.createSetterContent(setterType, {
|
this.setters?.createSetterContent(setterType, {
|
||||||
...shallowIntl(setterProps),
|
...shallowIntl(setterProps),
|
||||||
forceInline: extraProps.forceInline,
|
forceInline: extraProps.forceInline,
|
||||||
key: field.id,
|
key: field.id,
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { IPublicTypeCustomView, IPublicApiSetters, IPublicTypeRegisteredSetter } from '@alilc/lowcode-types';
|
import { IPublicTypeCustomView, IPublicApiSetters, IPublicTypeRegisteredSetter } from '@alilc/lowcode-types';
|
||||||
import { Setters as InnerSetters, globalContext } from '@alilc/lowcode-editor-core';
|
import { ISetters, globalContext, untracked } from '@alilc/lowcode-editor-core';
|
||||||
import { ReactNode } from 'react';
|
import { ReactNode } from 'react';
|
||||||
import { getLogger } from '@alilc/lowcode-utils';
|
import { getLogger } from '@alilc/lowcode-utils';
|
||||||
|
|
||||||
@ -9,26 +9,28 @@ const settersSymbol = Symbol('setters');
|
|||||||
const logger = getLogger({ level: 'warn', bizName: 'shell-setters' });
|
const logger = getLogger({ level: 'warn', bizName: 'shell-setters' });
|
||||||
|
|
||||||
export class Setters implements IPublicApiSetters {
|
export class Setters implements IPublicApiSetters {
|
||||||
readonly [innerSettersSymbol]: InnerSetters;
|
readonly [innerSettersSymbol]: ISetters;
|
||||||
|
|
||||||
get [settersSymbol](): InnerSetters {
|
get [settersSymbol](): ISetters {
|
||||||
if (this.workspaceMode) {
|
if (this.workspaceMode) {
|
||||||
return this[innerSettersSymbol];
|
return this[innerSettersSymbol];
|
||||||
}
|
}
|
||||||
|
|
||||||
const workspace = globalContext.get('workspace');
|
const workspace = globalContext.get('workspace');
|
||||||
if (workspace.isActive) {
|
if (workspace.isActive) {
|
||||||
if (!workspace.window.innerSetters) {
|
return untracked(() => {
|
||||||
logger.error('setter api 调用时机出现问题,请检查');
|
if (!workspace.window.innerSetters) {
|
||||||
return this[innerSettersSymbol];
|
logger.error('setter api 调用时机出现问题,请检查');
|
||||||
}
|
return this[innerSettersSymbol];
|
||||||
return workspace.window.innerSetters;
|
}
|
||||||
|
return workspace.window.innerSetters;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return this[innerSettersSymbol];
|
return this[innerSettersSymbol];
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(innerSetters: InnerSetters, readonly workspaceMode = false) {
|
constructor(innerSetters: ISetters, readonly workspaceMode = false) {
|
||||||
this[innerSettersSymbol] = innerSetters;
|
this[innerSettersSymbol] = innerSetters;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,6 +66,9 @@ export class Setters implements IPublicApiSetters {
|
|||||||
return this[settersSymbol].registerSetter(typeOrMaps, setter);
|
return this[settersSymbol].registerSetter(typeOrMaps, setter);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
createSetterContent = (setter: any, props: Record<string, any>): ReactNode => {
|
createSetterContent = (setter: any, props: Record<string, any>): ReactNode => {
|
||||||
return this[settersSymbol].createSetterContent(setter, props);
|
return this[settersSymbol].createSetterContent(setter, props);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
|
import { ReactNode } from 'react';
|
||||||
|
|
||||||
import { IPublicTypeRegisteredSetter, IPublicTypeCustomView } from '../type';
|
import { IPublicTypeRegisteredSetter, IPublicTypeCustomView } from '../type';
|
||||||
|
|
||||||
export interface IPublicApiSetters {
|
export interface IPublicApiSetters {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取指定 setter
|
* 获取指定 setter
|
||||||
* get setter by type
|
* get setter by type
|
||||||
@ -29,4 +32,9 @@ export interface IPublicApiSetters {
|
|||||||
typeOrMaps: string | { [key: string]: IPublicTypeCustomView | IPublicTypeRegisteredSetter },
|
typeOrMaps: string | { [key: string]: IPublicTypeCustomView | IPublicTypeRegisteredSetter },
|
||||||
setter?: IPublicTypeCustomView | IPublicTypeRegisteredSetter | undefined
|
setter?: IPublicTypeCustomView | IPublicTypeRegisteredSetter | undefined
|
||||||
): void;
|
): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
createSetterContent (setter: any, props: Record<string, any>): ReactNode;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user