Skip to content

Commit

Permalink
feat(setter): add field ts
Browse files Browse the repository at this point in the history
  • Loading branch information
liujuping committed Jan 26, 2024
1 parent 0e65f02 commit d6faa21
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
6 changes: 3 additions & 3 deletions packages/editor-core/src/di/setter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ReactNode } from 'react';
import { IPublicApiSetters, IPublicTypeCustomView, IPublicTypeRegisteredSetter } from '@alilc/lowcode-types';
import { IPublicApiSetters, IPublicModelSettingField, IPublicTypeCustomView, IPublicTypeRegisteredSetter } from '@alilc/lowcode-types';
import { createContent, isCustomView } from '@alilc/lowcode-utils';

const settersMap = new Map<string, IPublicTypeRegisteredSetter & {
Expand Down Expand Up @@ -28,7 +28,7 @@ export function registerSetter(
if (!setter.initialValue) {
const initial = getInitialFromSetter(setter.component);
if (initial) {
setter.initialValue = (field: any) => {
setter.initialValue = (field: IPublicModelSettingField) => {
return initial.call(field, field.getValue());
};
}
Expand Down Expand Up @@ -81,7 +81,7 @@ export class Setters implements ISetters {
if (!setter.initialValue) {
const initial = getInitialFromSetter(setter.component);
if (initial) {
setter.initialValue = (field: any) => {
setter.initialValue = (field: IPublicModelSettingField) => {
return initial.call(field, field.getValue());
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class SettingFieldView extends Component<SettingFieldViewProps, SettingFieldView

const value = this.value;

let _onChange = extraProps?.onChange;
let onChangeAPI = extraProps?.onChange;
let stageName = this.stageName;

return createField(
Expand Down Expand Up @@ -261,7 +261,7 @@ class SettingFieldView extends Component<SettingFieldViewProps, SettingFieldView
value,
});
field.setValue(value, true);
if (_onChange) _onChange(value, field);
if (onChangeAPI) onChangeAPI(value, field.internalToShellField());
},
onInitial: () => {
if (initialValue == null) {
Expand Down
3 changes: 2 additions & 1 deletion packages/editor-skeleton/src/transducers/parse-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
IPublicTypeTransformedComponentMetadata,
IPublicTypeOneOfType,
ConfigureSupportEvent,
IPublicModelSettingField,
} from '@alilc/lowcode-types';

function propConfigToFieldConfig(propConfig: IPublicTypePropConfig): IPublicTypeFieldConfig {
Expand Down Expand Up @@ -102,7 +103,7 @@ function propTypeToSetter(propType: IPublicTypePropType): IPublicTypeSetterType
},
},
isRequired,
initialValue: (field: any) => {
initialValue: (field: IPublicModelSettingField) => {
const data: any = {};
items.forEach((item: any) => {
let initial = item.defaultValue;
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/shell/type/field-extra-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ export interface IPublicTypeFieldExtraProps {
/**
* onChange 事件
*/
onChange?: (value: any, field: any) => void;
onChange?: (value: any, field: IPublicModelSettingField) => void;
}
7 changes: 5 additions & 2 deletions packages/types/src/shell/type/registered-setter.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { IPublicModelSettingField } from '../model';
import { IPublicTypeCustomView, IPublicTypeTitleContent } from './';

export interface IPublicTypeRegisteredSetter {
component: IPublicTypeCustomView;
defaultProps?: object;
title?: IPublicTypeTitleContent;

/**
* for MixedSetter to check this setter if available
*/
condition?: (field: any) => boolean;
condition?: (field: IPublicModelSettingField) => boolean;

/**
* for MixedSetter to manual change to this setter
*/
initialValue?: any | ((field: any) => any);
initialValue?: any | ((field: IPublicModelSettingField) => any);
recommend?: boolean;
// 标识是否为动态 setter,默认为 true
isDynamic?: boolean;
Expand Down

0 comments on commit d6faa21

Please sign in to comment.