fix: remove some deprecated apis

This commit is contained in:
1ncounter 2024-04-14 21:10:12 +08:00
parent 0831277dc0
commit 35db123cbf
23 changed files with 97 additions and 140 deletions

View File

@ -7,7 +7,6 @@ import {
IPublicTypeNpmInfo,
IPublicModelEditor,
IPublicTypePropsList,
IPublicTypeNodeSchema,
IPublicTypePropsTransducer,
IShellModelFactory,
IPublicModelDragObject,

View File

@ -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';
@ -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)) {
@ -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;
}),
})),
];
}

View File

@ -71,8 +71,6 @@ export interface ISettingField
clearValue(): void;
valueChange(options: IPublicTypeSetValueOptions): void;
createField(config: IPublicTypeFieldConfig): ISettingField;
onEffect(action: () => void): IPublicTypeDisposable;
@ -258,8 +256,6 @@ export class SettingField extends SettingPropEntry implements ISettingField {
if (Array.isArray(data) && data[0] && data[0].__sid__) {
return;
}
this.valueChange();
}
@action
@ -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 {

View File

@ -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';
@ -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;
@ -49,8 +47,6 @@ export interface ISettingPropEntry extends ISettingEntry {
setValue(
val: any,
isHotValue?: boolean,
force?: boolean,
extraOptions?: IPublicTypeSetValueOptions,
): void;
@ -231,8 +227,6 @@ export class SettingPropEntry implements ISettingPropEntry {
*/
setValue(
val: any,
isHotValue?: boolean,
force?: boolean,
extraOptions?: IPublicTypeSetValueOptions,
) {
const oldValue = this.getValue();
@ -250,10 +244,6 @@ export class SettingPropEntry implements ISettingPropEntry {
}
}
this.notifyValueChange(oldValue, val);
// 如果 fromSetHotValue那么在 setHotValue 中已经调用过 valueChange 了
if (!extraOptions?.fromSetHotValue) {
this.valueChange(extraOptions);
}
}
/**

View File

@ -2,7 +2,6 @@ import { ReactElement } from 'react';
import {
observable,
computed,
autorun,
makeObservable,
runInAction,
wrapWithEventSwitch,
@ -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();
@ -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[] {
@ -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!,
@ -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,
@ -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 {

View File

@ -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)) {
@ -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;

View File

@ -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;
@ -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;
}>();
@ -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);
};
}

View File

@ -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,
@ -18,4 +18,4 @@ export {
} from 'mobx';
export type { IReactionDisposer, IReactionPublic, IReactionOptions } from 'mobx';
export { observer };
export { observer, mobx };

View File

@ -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>;

View File

@ -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);
}

View File

@ -1,10 +1,11 @@
import { Component, MouseEvent, Fragment, ReactNode } from 'react';
import { shallowIntl, observer, observable, engineConfig, runInAction } from '@alilc/lowcode-editor-core';
import { observer, observable, engineConfig, runInAction, shallowIntl } from '@alilc/lowcode-editor-core';
import {
createContent,
isJSSlot,
isSetterConfig,
shouldUseVariableSetter,
isSettingField
} from '@alilc/lowcode-utils';
import { Skeleton } from '../../skeleton';
import { Stage } from '../../widget/stage';
@ -17,7 +18,6 @@ import {
ISettingEntry,
IComponentMeta,
ISettingField,
isSettingField,
ISettingTopEntry,
} from '@alilc/lowcode-designer';
import { createField } from '../field';
@ -41,7 +41,7 @@ function isStandardComponent(componentMeta: IComponentMeta | null) {
function isInitialValueNotEmpty(initialValue: any) {
if (isJSSlot(initialValue)) {
return (
// @ts-ignore visible 为 false 代表默认不展示
// @ts-expect-error visible 为 false 代表默认不展示
initialValue.visible !== false &&
Array.isArray(initialValue.value) &&
initialValue.value.length > 0
@ -247,13 +247,38 @@ class SettingFieldView extends Component<SettingFieldViewProps, SettingFieldView
return null;
}
const { setterProps = {}, setterType, initialValue = null } = this.setterInfo;
const value = this.value;
const onChangeAPI = extraProps?.onChange;
const stageName = this.stageName;
const {
setterProps = {},
setterType,
initialValue = null,
} = this.setterInfo;
const onChangeAPI = extraProps?.onChange;
const createSetterContent = (setter: any, props: Record<string, any>): ReactNode => {
if (typeof setter === 'string') {
setter = this.setters?.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);
};
return createField(
{
meta: field?.componentMeta?.npm || field?.componentMeta?.componentName || '',
@ -268,8 +293,7 @@ class SettingFieldView extends Component<SettingFieldViewProps, SettingFieldView
stageName,
...extraProps,
},
!stageName &&
this.setters?.createSetterContent(setterType, {
!stageName && createSetterContent(setterType, {
...shallowIntl(setterProps),
forceInline: extraProps.forceInline,
key: field.id,
@ -278,12 +302,11 @@ class SettingFieldView extends Component<SettingFieldViewProps, SettingFieldView
selected: field.top?.getNode()?.internalToShellNode(),
field: field.internalToShellField(),
// === IO
value, // reaction point
value: this.value, // reaction point
initialValue,
onChange: (value: any) => {
this.setState({
fromOnChange: true,
// eslint-disable-next-line react/no-unused-state
value,
});
field.setValue(value, true);
@ -298,7 +321,6 @@ class SettingFieldView extends Component<SettingFieldViewProps, SettingFieldView
? initialValue(field.internalToShellField())
: initialValue;
this.setState({
// eslint-disable-next-line react/no-unused-state
value,
});
field.setValue(value, true);

View File

@ -18,6 +18,8 @@ import { SkeletonContext } from '../../context';
import { intl } from '../../locale';
import { createIcon, isSettingField } from '@alilc/lowcode-utils';
import './style.less';
interface ISettingsPrimaryPaneProps {
engineEditor: Editor;
config?: any;
@ -200,7 +202,6 @@ export class SettingsPrimaryPane extends Component<
{(skeleton) => {
if (skeleton) {
return (
// @ts-ignore
<StageBox skeleton={skeleton} target={settings} key={settings.id}>
<SettingsPane target={settings} usePopup={false} />
</StageBox>

View File

@ -123,26 +123,27 @@ const designer = new Designer({ editor, shellModelFactory });
editor.set('designer', designer);
const { project: innerProject } = designer;
const project = new Project(innerProject);
editor.set('project', project);
const innerHotkey = new InnerHotkey();
const hotkey = new Hotkey(innerHotkey);
const project = new Project(innerProject);
editor.set('innerHotkey', innerHotkey);
const skeleton = new Skeleton(innerSkeleton, 'any', false);
const innerSetters = new InnerSetters();
const setters = new Setters(innerSetters);
editor.set('setters', setters);
const material = new Material(editor);
editor.set('material', material);
const innerCommand = new InnerCommand();
const command = new Command(
innerCommand,
engineContext as IPublicModelPluginContext
);
const material = new Material(editor);
const commonUI = new CommonUI(editor);
editor.set('project', project);
editor.set('setters', setters);
editor.set('material', material);
editor.set('innerHotkey', innerHotkey);
const config = new Config(engineConfig);
const event = new Event(commonEvent, { prefix: 'common' });
const logger = new Logger({ level: 'warn', bizName: 'common' });

View File

@ -1,4 +1,4 @@
import { ISettingField, isSettingField } from '@alilc/lowcode-designer';
import { ISettingField } from '@alilc/lowcode-designer';
import {
IPublicTypeCompositeValue,
IPublicTypeFieldConfig,
@ -16,7 +16,7 @@ import { settingFieldSymbol } from '../symbols';
import { Node as ShellNode } from './node';
import { SettingTopEntry, SettingTopEntry as ShellSettingTopEntry } from './setting-top-entry';
import { ComponentMeta as ShellComponentMeta } from './component-meta';
import { isCustomView } from '@alilc/lowcode-utils';
import { isCustomView, isSettingField } from '@alilc/lowcode-utils';
export class SettingField implements IPublicModelSettingField {
private readonly [settingFieldSymbol]: ISettingField;

View File

@ -30,6 +30,7 @@
},
"dependencies": {
"@alifd/next": "^1.27.8",
"@alilc/lowcode-editor-core": "workspace:*",
"@alilc/lowcode-types": "workspace:*",
"@alilc/lowcode-utils": "workspace:*",
"classnames": "^2.5.1",
@ -44,6 +45,7 @@
},
"peerDependencies": {
"@alifd/next": "^1.27.8",
"@alilc/lowcode-editor-core": "workspace:*",
"@alilc/lowcode-types": "workspace:*",
"@alilc/lowcode-utils": "workspace:*",
"react": "^18.2.0",

View File

@ -1,5 +1,6 @@
import { PureComponent } from 'react';
import classNames from 'classnames';
import { Title } from '@alilc/lowcode-editor-core';
import TreeNode from '../controllers/tree-node';
import TreeNodeView from './tree-node';
import { IPublicModelExclusiveGroup, IPublicTypeDisposable, IPublicTypeLocationChildrenDetail } from '@alilc/lowcode-types';
@ -119,7 +120,6 @@ class TreeNodeChildren extends PureComponent<{
let groupContents: any[] = [];
let currentGrp: IPublicModelExclusiveGroup;
const { filterWorking, matchSelf, keywords } = this.state;
const Title = this.props.treeNode.pluginContext.common.editorCabin.Title;
const endGroup = () => {
if (groupContents.length > 0) {
@ -194,7 +194,6 @@ class TreeNodeSlots extends PureComponent<{
if (!treeNode.hasSlots()) {
return null;
}
const Title = this.props.treeNode.pluginContext.common.editorCabin.Title;
return (
<div
className={classNames('tree-node-slots', {

View File

@ -1,5 +1,6 @@
import { KeyboardEvent, FocusEvent, Fragment, PureComponent } from 'react';
import classNames from 'classnames';
import { Title, Tip } from '@alilc/lowcode-editor-core';
import { createIcon } from '@alilc/lowcode-utils';
import { IPublicApiEvent } from '@alilc/lowcode-types';
import TreeNode from '../controllers/tree-node';
@ -165,8 +166,7 @@ export default class TreeTitle extends PureComponent<{
};
}
const Extra = pluginContext.extraTitle as any;
const { intlNode, common, config } = pluginContext;
const { Tip, Title } = common.editorCabin;
const { intlNode, config } = pluginContext;
const couldHide = availableActions.includes('hide');
const couldLock = availableActions.includes('lock');
const couldUnlock = availableActions.includes('unlock');
@ -235,7 +235,6 @@ export default class TreeTitle extends PureComponent<{
/>
) : (
<Fragment>
{/* @ts-ignore */}
<Title
title={this.state.title}
match={filterWorking && matchSelf}
@ -245,7 +244,6 @@ export default class TreeTitle extends PureComponent<{
{node.slotFor && (
<a className="tree-node-tag slot">
{/* todo: click redirect to prop */}
{/* @ts-ignore */}
<Tip>{intlNode('Slot for {prop}', { prop: node.slotFor.key })}</Tip>
</a>
)}
@ -253,7 +251,6 @@ export default class TreeTitle extends PureComponent<{
<a className="tree-node-tag loop">
{/* todo: click todo something */}
<IconLoop />
{/* @ts-ignore */}
<Tip>{intlNode('Loop')}</Tip>
</a>
)}
@ -261,7 +258,6 @@ export default class TreeTitle extends PureComponent<{
<a className="tree-node-tag cond">
{/* todo: click todo something */}
<IconCond />
{/* @ts-ignore */}
<Tip>{intlNode('Conditional')}</Tip>
</a>
)}
@ -282,12 +278,10 @@ class DeleteBtn extends PureComponent<{
onClick: () => void;
}> {
render() {
const { intl, common } = this.props.treeNode.pluginContext;
const { Tip } = common.editorCabin;
const { intl } = this.props.treeNode.pluginContext;
return (
<div className="tree-node-delete-btn" onClick={this.props.onClick}>
<IconDelete />
{/* @ts-ignore */}
<Tip>{intl('Delete')}</Tip>
</div>
);
@ -299,12 +293,10 @@ class RenameBtn extends PureComponent<{
onClick: (e: any) => void;
}> {
render() {
const { intl, common } = this.props.treeNode.pluginContext;
const { Tip } = common.editorCabin;
const { intl } = this.props.treeNode.pluginContext;
return (
<div className="tree-node-rename-btn" onClick={this.props.onClick}>
<IconSetting />
{/* @ts-ignore */}
<Tip>{intl('Rename')}</Tip>
</div>
);
@ -317,8 +309,7 @@ class LockBtn extends PureComponent<{
}> {
render() {
const { treeNode, locked } = this.props;
const { intl, common } = this.props.treeNode.pluginContext;
const { Tip } = common.editorCabin;
const { intl } = this.props.treeNode.pluginContext;
return (
<div
className="tree-node-lock-btn"
@ -346,8 +337,7 @@ class HideBtn extends PureComponent<
> {
render() {
const { treeNode, hidden } = this.props;
const { intl, common } = treeNode.pluginContext;
const { Tip } = common.editorCabin;
const { intl } = treeNode.pluginContext;
return (
<div
className="tree-node-hide-btn"

View File

@ -5,6 +5,6 @@ export default defineConfig(async () => {
return baseConfigFn({
name: 'LowCodePluginOutlinePane',
defaultFormats: ['es', 'cjs'],
entry: 'src/index.tsx'
entry: 'src/index.tsx',
})
});

View File

@ -1,5 +1,3 @@
import { ReactNode } from 'react';
import { IPublicTypeRegisteredSetter, IPublicTypeCustomView } from '../type';
export interface IPublicApiSetters {

View File

@ -447,4 +447,5 @@ export interface IBaseModelNode<
};
}
export interface IPublicModelNode extends IBaseModelNode<IPublicModelDocumentModel, IPublicModelNode> {}
export interface IPublicModelNode extends
IBaseModelNode<IPublicModelDocumentModel, IPublicModelNode> {}

View File

@ -1,6 +1,6 @@
import { isValidElement } from 'react';
import { isReactComponent } from '../is-react';
import { IPublicTypeCustomView } from '@alilc/lowcode-types';
import { isReactComponent } from '../is-react';
export function isCustomView(obj: any): obj is IPublicTypeCustomView {
if (!obj) {

View File

@ -2,9 +2,6 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"paths": {
"@alilc/lowcode-*": ["packages/*"]
}
},
"include": ["src"]
}

View File

@ -37,7 +37,7 @@
"paths": {
"@alilc/lowcode-*": ["packages/*/src"]
},
"types": ["vitest/globals", "node"]
"types": ["vite/client", "vitest/globals", "node"]
},
"exclude": ["**/dist", "node_modules"]
}