Skip to content

Commit

Permalink
fix: change autorun params to IPublicModelSettingField
Browse files Browse the repository at this point in the history
  • Loading branch information
liujuping authored and JackLian committed Apr 3, 2023
1 parent 9b7462b commit 2b82b3e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
2 changes: 2 additions & 0 deletions packages/designer/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const jestConfig = {
// testMatch: ['(/tests?/.*(test))\\.[jt]s$'],
// testMatch: ['**/document/node/node.add.test.ts'],
// testMatch: ['**/setting-field.test.ts'],
// testMatch: ['**/node.test.ts'],
// testMatch: ['**/builtin-hotkey.test.ts'],
transformIgnorePatterns: [
`/node_modules/(?!${esModules})/`,
],
Expand Down
4 changes: 2 additions & 2 deletions packages/designer/src/designer/setting/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { isValidElement } from 'react';
import { IPublicTypeFieldConfig, IPublicTypeSetterConfig } from '@alilc/lowcode-types';
import { isSetterConfig, isDynamicSetter } from '@alilc/lowcode-utils';
import { SettingField } from './setting-field';
import { ISettingField } from './setting-field';

function getHotterFromSetter(setter) {
return setter && (setter.Hotter || (setter.type && setter.type.Hotter)) || []; // eslint-disable-line
Expand Down Expand Up @@ -35,7 +35,7 @@ export class Transducer {

context: any;

constructor(context: SettingField, config: { setter: IPublicTypeFieldConfig['setter'] }) {
constructor(context: ISettingField, config: { setter: IPublicTypeFieldConfig['setter'] }) {
let { setter } = config;

// 1. validElement
Expand Down
3 changes: 1 addition & 2 deletions packages/designer/src/document/node/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import type { IExclusiveGroup } from './exclusive-group';
import { includeSlot, removeSlot } from '../../utils/slot';
import { foreachReverse } from '../../utils/tree';
import { NodeRemoveOptions, EDITOR_EVENT } from '../../types';
import { Prop as ShellProp } from '@alilc/lowcode-shell';

export interface NodeStatus {
locking: boolean;
Expand Down Expand Up @@ -432,7 +431,7 @@ export class Node<Schema extends IPublicTypeNodeSchema = IPublicTypeNodeSchema>
}
this.autoruns = autoruns.map((item) => {
return autorun(() => {
item.autorun(ShellProp.create(this.props.get(item.name, true))!);
item.autorun(this.props.getNode().settingEntry.get(item.name)?.internalToShellField());
});
});
}
Expand Down
11 changes: 10 additions & 1 deletion packages/designer/tests/document/node/node.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
// @ts-nocheck
import '../../fixtures/window';
import { set } from '../../utils';
import { Editor } from '@alilc/lowcode-editor-core';
import {
Editor,
globalContext,
Setters as InnerSetters,
} from '@alilc/lowcode-editor-core';
import { Project } from '../../../src/project/project';
import { Workspace as InnerWorkspace } from '@alilc/lowcode-workspace';
import { DocumentModel } from '../../../src/document/document-model';
import {
isRootNode,
Expand All @@ -23,6 +28,7 @@ import rootContentMetadata from '../../fixtures/component-metadata/root-content'
import rootFooterMetadata from '../../fixtures/component-metadata/root-footer';
import { shellModelFactory } from '../../../../engine/src/modules/shell-model-factory';
import { isNode } from '@alilc/lowcode-utils';
import { Setters } from '@alilc/lowcode-shell';

describe('Node 方法测试', () => {
let editor: Editor;
Expand All @@ -35,6 +41,9 @@ describe('Node 方法测试', () => {
designer = new Designer({ editor, shellModelFactory });
project = designer.project;
doc = new DocumentModel(project, formSchema);
editor.set('setters', new Setters(new InnerSetters()));
!globalContext.has(Editor) && globalContext.register(editor, Editor);
!globalContext.has('workspace') && globalContext.register(new InnerWorkspace(), 'workspace');
});

afterEach(() => {
Expand Down
9 changes: 4 additions & 5 deletions packages/engine/src/inner-plugins/builtin-hotkey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,9 @@ function getSuitablePlaceForNode(targetNode: IPublicModelNode, node: IPublicMode
if (node?.componentMeta?.isModal) {
return { container: focusNode, ref };
}
const canDropInFn = document.checkNesting;

if (!ref && focusNode && targetNode.contains(focusNode)) {
if (canDropInFn(focusNode, dragNodeObject)) {
if (document.checkNesting(focusNode, dragNodeObject)) {
return { container: focusNode };
}

Expand All @@ -191,7 +190,7 @@ function getSuitablePlaceForNode(targetNode: IPublicModelNode, node: IPublicMode
if (!c.isContainerNode) {
return false;
}
if (canDropInFn(c, dragNodeObject)) {
if (document.checkNesting(c, dragNodeObject)) {
return true;
}
return false;
Expand All @@ -201,15 +200,15 @@ function getSuitablePlaceForNode(targetNode: IPublicModelNode, node: IPublicMode
return { container: dropElement, ref };
}

if (canDropInFn(targetNode, dragNodeObject)) {
if (document.checkNesting(targetNode, dragNodeObject)) {
return { container: targetNode, ref };
}

return null;
}

if (targetNode.isContainerNode) {
if (canDropInFn(targetNode, dragNodeObject)) {
if (document.checkNesting(targetNode, dragNodeObject)) {
return { container: targetNode, ref };
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/types/src/shell/type/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MouseEvent } from 'react';
import { IPublicTypePropType, IPublicTypeComponentAction } from './';
import { IPublicModelNode, IPublicModelProp, IPublicModelSettingField } from '../model';
import { IPublicModelNode, IPublicModelSettingField } from '../model';

/**
* 嵌套控制函数
Expand Down Expand Up @@ -102,7 +102,7 @@ export interface IPublicTypeFilterItem {
}
export interface IPublicTypeAutorunItem {
name: string;
autorun: (prop: IPublicModelProp) => any;
autorun: (target: IPublicModelSettingField | null) => any;
}

// thinkof Array
Expand Down

0 comments on commit 2b82b3e

Please sign in to comment.