Skip to content

Commit

Permalink
fix: remove some deprecated apis
Browse files Browse the repository at this point in the history
  • Loading branch information
1ncounter committed Apr 14, 2024
1 parent 0831277 commit 35db123
Show file tree
Hide file tree
Showing 23 changed files with 96 additions and 139 deletions.
1 change: 0 additions & 1 deletion packages/designer/src/designer/designer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
IPublicTypeNpmInfo,
IPublicModelEditor,
IPublicTypePropsList,
IPublicTypeNodeSchema,
IPublicTypePropsTransducer,
IShellModelFactory,
IPublicModelDragObject,
Expand Down
14 changes: 7 additions & 7 deletions packages/designer/src/designer/drag-ghost/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, ReactElement } from 'react';
import { observer, observable, Title, makeObservable } from '@alilc/lowcode-editor-core';
import { observer, observable, Title, makeObservable, action } from '@alilc/lowcode-editor-core';
import { Designer } from '../designer';
import { isSimulatorHost } from '../../simulator';
import './ghost.less';
Expand Down Expand Up @@ -30,15 +30,15 @@ export default class DragGhost extends Component<{ designer: Designer }> {
super(props);
makeObservable(this);
this.dispose = [
this.dragon.onDragstart((e) => {
this.dragon.onDragstart(action((e) => {
if (e.originalEvent.type.slice(0, 4) === 'drag') {
return;
}
this.titles = this.getTitles(e.dragObject!) as any;
this.x = e.globalX;
this.y = e.globalY;
}),
this.dragon.onDrag((e) => {
})),
this.dragon.onDrag(action((e) => {
this.x = e.globalX;
this.y = e.globalY;
if (isSimulatorHost(e.sensor)) {
Expand All @@ -49,12 +49,12 @@ export default class DragGhost extends Component<{ designer: Designer }> {
}
}
this.isAbsoluteLayoutContainer = false;
}),
this.dragon.onDragend(() => {
})),
this.dragon.onDragend(action(() => {
this.titles = null;
this.x = 0;
this.y = 0;
}),
})),
];
}

Expand Down
6 changes: 0 additions & 6 deletions packages/designer/src/designer/setting/setting-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ export interface ISettingField

clearValue(): void;

valueChange(options: IPublicTypeSetValueOptions): void;

createField(config: IPublicTypeFieldConfig): ISettingField;

onEffect(action: () => void): IPublicTypeDisposable;
Expand Down Expand Up @@ -258,8 +256,6 @@ export class SettingField extends SettingPropEntry implements ISettingField {
if (Array.isArray(data) && data[0] && data[0].__sid__) {
return;
}

this.valueChange();
}

@action
Expand Down Expand Up @@ -304,8 +300,6 @@ export class SettingField extends SettingPropEntry implements ISettingField {
if (Array.isArray(data) && data[0] && data[0].__sid__) {
return;
}

this.valueChange(options);
}

onEffect(action: () => void): IPublicTypeDisposable {
Expand Down
12 changes: 1 addition & 11 deletions packages/designer/src/designer/setting/setting-prop-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
IPublicTypeFieldExtraProps,
IPublicTypeSetValueOptions,
} from '@alilc/lowcode-types';
import { uniqueId, isJSExpression, isSettingField } from '@alilc/lowcode-utils';
import { uniqueId, isJSExpression } from '@alilc/lowcode-utils';
import { ISettingEntry } from './setting-entry-type';
import { INode } from '../../document';
import type { IComponentMeta } from '../../component-meta';
Expand All @@ -29,8 +29,6 @@ export interface ISettingPropEntry extends ISettingEntry {

get name(): string | number | undefined;

valueChange(options: IPublicTypeSetValueOptions): void;

getKey(): string | number | undefined;

setKey(key: string | number): void;
Expand All @@ -49,8 +47,6 @@ export interface ISettingPropEntry extends ISettingEntry {

setValue(
val: any,
isHotValue?: boolean,
force?: boolean,
extraOptions?: IPublicTypeSetValueOptions,
): void;

Expand Down Expand Up @@ -231,8 +227,6 @@ export class SettingPropEntry implements ISettingPropEntry {
*/
setValue(
val: any,
isHotValue?: boolean,
force?: boolean,
extraOptions?: IPublicTypeSetValueOptions,
) {
const oldValue = this.getValue();
Expand All @@ -250,10 +244,6 @@ export class SettingPropEntry implements ISettingPropEntry {
}
}
this.notifyValueChange(oldValue, val);
// 如果 fromSetHotValue,那么在 setHotValue 中已经调用过 valueChange 了
if (!extraOptions?.fromSetHotValue) {
this.valueChange(extraOptions);
}
}

/**
Expand Down
34 changes: 8 additions & 26 deletions packages/designer/src/document/node/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ReactElement } from 'react';
import {
observable,
computed,
autorun,
makeObservable,
runInAction,
wrapWithEventSwitch,
Expand Down Expand Up @@ -295,7 +294,6 @@ implements
this._children = new NodeChildren(this as INode, this.initialChildren(children));
this._children.internalInitParent();
this.props.merge(this.upgradeProps(this.initProps(props || {})), this.upgradeProps(extras));
this.setupAutoruns();
}

this.initBuiltinProps();
Expand Down Expand Up @@ -343,18 +341,6 @@ implements
return this.document.designer.transformProps(props, this, IPublicEnumTransformStage.Upgrade);
}

private setupAutoruns() {
const { autoruns } = this.componentMeta.advanced;
if (!autoruns || autoruns.length < 1) {
return;
}
this.autoruns = autoruns.map((item) => {
return autorun(() => {
item.autorun(this.props.getNode().settingEntry.get(item.name)?.internalToShellField());
});
});
}

private initialChildren(
children: IPublicTypeNodeData | IPublicTypeNodeData[] | undefined,
): IPublicTypeNodeData[] {
Expand Down Expand Up @@ -840,7 +826,7 @@ implements
}

import(data: Schema, checkId = false) {
const { componentName, id, children, props, ...extras } = data;
const { children, props, ...extras } = data;
if (this.isSlot()) {
foreachReverse(
this.children!,
Expand Down Expand Up @@ -894,17 +880,6 @@ implements
const _extras_: { [key: string]: any } = {
...extras,
};
/* istanbul ignore next */
Object.keys(this._addons).forEach((key) => {
const addon = this._addons[key];
if (addon) {
if (addon.isProp) {
(props as any)[getConvertedExtraKey(key)] = addon.exportData();
} else {
_extras_[key] = addon.exportData();
}
}
});

const schema: any = {
...baseSchema,
Expand Down Expand Up @@ -1146,6 +1121,13 @@ implements
this.emitter.removeListener('propChange', wrappedFunc);
};
}

/**
* todo: fixed types
*/
getDOMNode(): HTMLElement {
return document.body;
}
}

function ensureNode(node: any, document: IDocumentModel): INode {
Expand Down
13 changes: 8 additions & 5 deletions packages/designer/src/document/node/props/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ export class Props implements Omit<IBaseModelProps<IProp>, | 'getExtraProp' | 'g

private purged = false;

constructor(owner: INode, value?: IPublicTypePropsMap | IPublicTypePropsList | null, extras?: ExtrasObject) {
constructor(
owner: INode,
value?: IPublicTypePropsMap | IPublicTypePropsList | null,
extras?: ExtrasObject
) {
makeObservable(this);
this.owner = owner;
if (Array.isArray(value)) {
Expand Down Expand Up @@ -166,10 +170,9 @@ export class Props implements Omit<IBaseModelProps<IProp>, | 'getExtraProp' | 'g
allProps[name] = value;
}
});
// compatible vision
const transformedProps = this.transformToStatic(allProps);
Object.keys(transformedProps).forEach((name) => {
const value = transformedProps[name];

Object.keys(allProps).forEach((name) => {
const value = allProps[name];
if (typeof name === 'string' && name.startsWith(EXTRA_KEY_PREFIX)) {
name = getOriginalExtraKey(name);
extras[name] = value;
Expand Down
30 changes: 2 additions & 28 deletions packages/editor-core/src/di/setter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ReactNode } from 'react';
import { IPublicApiSetters, IPublicModelSettingField, IPublicTypeCustomView, IPublicTypeRegisteredSetter } from '@alilc/lowcode-types';
import { createContent, isCustomView } from '@alilc/lowcode-utils';
import { isCustomView } from '@alilc/lowcode-utils';

const settersMap = new Map<string, IPublicTypeRegisteredSetter & {
type: string;
Expand Down Expand Up @@ -44,9 +43,7 @@ function getInitialFromSetter(setter: any) {
) || null; // eslint-disable-line
}

export interface ISetters extends IPublicApiSetters {}

export class Setters implements ISetters {
export class Setters implements IPublicApiSetters {
settersMap = new Map<string, IPublicTypeRegisteredSetter & {
type: string;
}>();
Expand Down Expand Up @@ -91,27 +88,4 @@ export class Setters implements ISetters {
getSettersMap = () => {
return this.settersMap;
};

createSetterContent = (setter: any, props: Record<string, any>): ReactNode => {
if (typeof setter === 'string') {
setter = this.getSetter(setter);
if (!setter) {
return null;
}
if (setter.defaultProps) {
props = {
...setter.defaultProps,
...props,
};
}
setter = setter.component;
}

// Fusion 的表单组件都是通过 'value' in props 来判断是否使用 defaultValue
if ('value' in props && typeof props.value === 'undefined') {
delete props.value;
}

return createContent(setter, props);
};
}
6 changes: 3 additions & 3 deletions packages/editor-core/src/utils/obx.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { observer } from 'mobx-react';
import { configure } from 'mobx';
import * as mobx from 'mobx';

configure({ enforceActions: 'never' });
mobx.configure({ enforceActions: 'never' });

export {
observable,
Expand All @@ -18,4 +18,4 @@ export {
} from 'mobx';
export type { IReactionDisposer, IReactionPublic, IReactionOptions } from 'mobx';

export { observer };
export { observer, mobx };
2 changes: 1 addition & 1 deletion packages/editor-core/src/widgets/title/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class Title extends Component<IPublicTypeTitleProps> {
return null;
}

const intlLabel = intl(String(label));
const intlLabel = intl(label as IPublicTypeI18nData);

if (typeof intlLabel !== 'string') {
return <span className="lc-title-txt">{intlLabel}</span>;
Expand Down
6 changes: 5 additions & 1 deletion packages/editor-skeleton/src/components/field/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ export interface FieldProps {
[extra: string]: any;
}

export function createField(props: FieldProps, children: ReactNode, type?: 'accordion' | 'inline' | 'block' | 'plain' | 'popup' | 'entry'): ReactNode {
export function createField(
props: FieldProps,
children:ReactNode,
type?: 'accordion' | 'inline' | 'block' | 'plain' | 'popup' | 'entry'
): ReactNode {
if (type === 'popup') {
return createElement(PopupField, props, children);
}
Expand Down

0 comments on commit 35db123

Please sign in to comment.