Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(setter): add field ts #2891

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading