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

fix: remove console.log statements, update test, and purge children i… #2959

Merged
merged 4 commits into from
Mar 7, 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
1 change: 1 addition & 0 deletions packages/designer/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const jestConfig = {
// testMatch: ['**/selection.test.ts'],
// testMatch: ['**/plugin/sequencify.test.ts'],
// testMatch: ['**/builtin-simulator/utils/parse-metadata.test.ts'],
// testMatch: ['**/setting/setting-top-entry.test.ts'],
transformIgnorePatterns: [
`/node_modules/(?!${esModules})/`,
],
Expand Down
2 changes: 1 addition & 1 deletion packages/designer/src/designer/dragon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { setNativeSelection, cursor } from '@alilc/lowcode-utils';
import { INode, Node } from '../document';
import { ISimulatorHost, isSimulatorHost } from '../simulator';
import { IDesigner } from './designer';
import type { IDesigner } from './designer';
import { makeEventsHandler } from '../utils/misc';

export interface ILocateEvent extends IPublicModelLocateEvent {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IPublicApiSetters, IPublicModelEditor } from '@alilc/lowcode-types';
import { IDesigner } from '../designer';
import { INode } from '../../document';
import { ISettingField } from './setting-field';
import type { IPublicApiSetters, IPublicModelEditor } from '@alilc/lowcode-types';
import type { IDesigner } from '../designer';
import type { INode } from '../../document';
import type { ISettingField } from './setting-field';

export interface ISettingEntry {
readonly designer: IDesigner | undefined;
Expand Down
58 changes: 5 additions & 53 deletions packages/designer/src/designer/setting/setting-field.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ReactNode } from 'react';
import {
IPublicTypeTitleContent,
IPublicTypeSetterType,
Expand All @@ -7,18 +6,15 @@ import {
IPublicTypeFieldConfig,
IPublicTypeCustomView,
IPublicTypeDisposable,
IPublicModelSettingField,
IBaseModelSettingField,
} from '@alilc/lowcode-types';
import type {
IPublicTypeSetValueOptions,
} from '@alilc/lowcode-types';
import { Transducer } from './utils';
import { ISettingPropEntry, SettingPropEntry } from './setting-prop-entry';
import { SettingPropEntry } from './setting-prop-entry';
import { computed, obx, makeObservable, action, untracked, intl } from '@alilc/lowcode-editor-core';
import { cloneDeep, isCustomView, isDynamicSetter, isJSExpression } from '@alilc/lowcode-utils';
import { ISettingTopEntry } from './setting-top-entry';
import { IComponentMeta, INode } from '@alilc/lowcode-designer';
import type { ISettingTopEntry } from './setting-top-entry';

function getSettingFieldCollectorKey(parent: ISettingTopEntry | ISettingField, config: IPublicTypeFieldConfig) {
let cur = parent;
Expand All @@ -32,53 +28,7 @@ function getSettingFieldCollectorKey(parent: ISettingTopEntry | ISettingField, c
return path.join('.');
}

export interface ISettingField extends ISettingPropEntry, Omit<IBaseModelSettingField<
ISettingTopEntry,
ISettingField,
IComponentMeta,
INode
>, 'setValue' | 'key' | 'node'> {
readonly isSettingField: true;

readonly isRequired: boolean;

readonly isGroup: boolean;

extraProps: IPublicTypeFieldExtraProps;

get items(): Array<ISettingField | IPublicTypeCustomView>;

get title(): string | ReactNode | undefined;

get setter(): IPublicTypeSetterType | null;

get expanded(): boolean;

get valueState(): number;

setExpanded(value: boolean): void;

purge(): void;

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

clearValue(): void;

valueChange(options: IPublicTypeSetValueOptions): void;

createField(config: IPublicTypeFieldConfig): ISettingField;

onEffect(action: () => void): IPublicTypeDisposable;

internalToShellField(): IPublicModelSettingField;
}

export class SettingField extends SettingPropEntry implements ISettingField {
export class SettingField extends SettingPropEntry {
readonly isSettingField = true;

readonly isRequired: boolean;
Expand Down Expand Up @@ -321,3 +271,5 @@ export class SettingField extends SettingPropEntry implements ISettingField {
export function isSettingField(obj: any): obj is ISettingField {
return obj && obj.isSettingField;
}

export type ISettingField = typeof SettingField;
12 changes: 6 additions & 6 deletions packages/designer/src/designer/setting/setting-prop-entry.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { obx, computed, makeObservable, runInAction, IEventBus, createModuleEventBus } from '@alilc/lowcode-editor-core';
import { GlobalEvent, IPublicApiSetters, IPublicModelEditor, IPublicModelSettingField, IPublicTypeFieldExtraProps, IPublicTypeSetValueOptions } from '@alilc/lowcode-types';
import { uniqueId, isJSExpression } from '@alilc/lowcode-utils';
import { ISettingEntry } from './setting-entry-type';
import { INode } from '../../document';
import { uniqueId, isJSExpression, isSettingField } from '@alilc/lowcode-utils';
import type { ISettingEntry } from './setting-entry-type';
import type { INode } from '../../document';
import type { IComponentMeta } from '../../component-meta';
import { IDesigner } from '../designer';
import { ISettingTopEntry } from './setting-top-entry';
import { ISettingField, isSettingField } from './setting-field';
import type { IDesigner } from '../designer';
import type { ISettingTopEntry } from './setting-top-entry';
import type { ISettingField } from './setting-field';

export interface ISettingPropEntry extends ISettingEntry {
readonly isGroup: boolean;
Expand Down
65 changes: 29 additions & 36 deletions packages/designer/src/designer/setting/setting-top-entry.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { IPublicTypeCustomView, IPublicModelEditor, IPublicModelSettingTopEntry, IPublicApiSetters } from '@alilc/lowcode-types';
import { isCustomView } from '@alilc/lowcode-utils';
import { computed, IEventBus, createModuleEventBus } from '@alilc/lowcode-editor-core';
import { ISettingEntry } from './setting-entry-type';
import { ISettingField, SettingField } from './setting-field';
import { INode } from '../../document';
import { computed, IEventBus, createModuleEventBus, obx, makeObservable } from '@alilc/lowcode-editor-core';
import { SettingField } from './setting-field';
import type { ISettingEntry } from './setting-entry-type';
import type { ISettingField } from './setting-field';
import type { INode } from '../../document';
import type { IComponentMeta } from '../../component-meta';
import { IDesigner } from '../designer';
import type { IDesigner } from '../designer';

function generateSessionId(nodes: INode[]) {
return nodes
Expand All @@ -14,33 +15,17 @@ function generateSessionId(nodes: INode[]) {
.join(',');
}

export interface ISettingTopEntry extends ISettingEntry, IPublicModelSettingTopEntry<
export interface ISettingTopEntry extends SettingTopEntry {}

export class SettingTopEntry implements ISettingEntry, IPublicModelSettingTopEntry<
INode,
ISettingField
> {
readonly top: ISettingTopEntry;

readonly parent: ISettingTopEntry;

readonly path: never[];

items: Array<ISettingField | IPublicTypeCustomView>;

componentMeta: IComponentMeta | null;

purge(): void;

getExtraPropValue(propName: string): void;

setExtraPropValue(propName: string, value: any): void;
}

export class SettingTopEntry implements ISettingTopEntry {
private emitter: IEventBus = createModuleEventBus('SettingTopEntry');

private _items: Array<SettingField | IPublicTypeCustomView> = [];
private _items: Array<ISettingField | IPublicTypeCustomView> = [];

private _componentMeta: IComponentMeta | null = null;
private _componentMeta: IComponentMeta | null | undefined = null;

private _isSame = true;

Expand Down Expand Up @@ -75,7 +60,7 @@ export class SettingTopEntry implements ISettingTopEntry {
}

get isLocked(): boolean {
return this.first.isLocked;
return this.first?.isLocked ?? false;
}

/**
Expand All @@ -87,7 +72,11 @@ export class SettingTopEntry implements ISettingTopEntry {

readonly id: string;

readonly first: INode;
@computed get first(): INode | null {
return this._first;
}

@obx.ref _first: INode | null;

readonly designer: IDesigner | undefined;

Expand All @@ -96,12 +85,14 @@ export class SettingTopEntry implements ISettingTopEntry {
disposeFunctions: any[] = [];

constructor(readonly editor: IPublicModelEditor, readonly nodes: INode[]) {
makeObservable(this);

if (!Array.isArray(nodes) || nodes.length < 1) {
throw new ReferenceError('nodes should not be empty');
}
this.id = generateSessionId(nodes);
this.first = nodes[0];
this.designer = this.first.document?.designer;
this._first = nodes[0];
this.designer = this._first.document?.designer;
this.setters = editor.get('setters') as IPublicApiSetters;

// setups
Expand All @@ -116,7 +107,7 @@ export class SettingTopEntry implements ISettingTopEntry {
private setupComponentMeta() {
// todo: enhance compile a temp configure.compiled
const { first } = this;
const meta = first.componentMeta;
const meta = first?.componentMeta;
const l = this.nodes.length;
let theSame = true;
for (let i = 1; i < l; i++) {
Expand Down Expand Up @@ -160,7 +151,7 @@ export class SettingTopEntry implements ISettingTopEntry {
/**
* 获取当前属性值
*/
@computed getValue(): any {
getValue(): any {
return this.first?.propsData;
}

Expand Down Expand Up @@ -202,14 +193,14 @@ export class SettingTopEntry implements ISettingTopEntry {
* 获取子级属性值
*/
getPropValue(propName: string | number): any {
return this.first.getProp(propName.toString(), true)?.getValue();
return this.first?.getProp(propName.toString(), true)?.getValue();
}

/**
* 获取顶层附属属性值
*/
getExtraPropValue(propName: string) {
return this.first.getExtraProp(propName, false)?.getValue();
return this.first?.getExtraProp(propName, false)?.getValue();
}

/**
Expand Down Expand Up @@ -244,8 +235,9 @@ export class SettingTopEntry implements ISettingTopEntry {
this.disposeItems();
this._settingFieldMap = {};
this.emitter.removeAllListeners();
this.disposeFunctions.forEach(f => f());
this.disposeFunctions.forEach(f => f?.());
this.disposeFunctions = [];
this._first = null;
}

getProp(propName: string | number) {
Expand Down Expand Up @@ -274,7 +266,7 @@ export class SettingTopEntry implements ISettingTopEntry {
}

getPage() {
return this.first.document;
return this.first?.document;
}

/**
Expand All @@ -292,6 +284,7 @@ export class SettingTopEntry implements ISettingTopEntry {
interface Purgeable {
purge(): void;
}

function isPurgeable(obj: any): obj is Purgeable {
return obj && obj.purge;
}
6 changes: 3 additions & 3 deletions packages/designer/src/document/document-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ import {
isDragNodeDataObject,
isNode,
} from '@alilc/lowcode-utils';
import { IProject } from '../project';
import { ISimulatorHost } from '../simulator';
import type { IProject } from '../project';
import type { ISimulatorHost } from '../simulator';
import type { IComponentMeta } from '../component-meta';
import { IDesigner, IHistory } from '../designer';
import type { IDesigner, IHistory } from '../designer';
import { insertChildren, insertChild, IRootNode } from './node/node';
import type { INode } from './node/node';
import { Selection, ISelection } from './selection';
Expand Down
2 changes: 1 addition & 1 deletion packages/designer/src/document/document-view.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component } from 'react';
import classNames from 'classnames';
import { observer } from '@alilc/lowcode-editor-core';
import { DocumentModel, IDocumentModel } from './document-model';
import type { IDocumentModel } from './document-model';
import { BuiltinSimulatorHostView } from '../builtin-simulator';

@observer
Expand Down
2 changes: 1 addition & 1 deletion packages/designer/src/document/history.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { reaction, untracked, IEventBus, createModuleEventBus } from '@alilc/lowcode-editor-core';
import { IPublicTypeNodeSchema, IPublicModelHistory, IPublicTypeDisposable } from '@alilc/lowcode-types';
import { Logger } from '@alilc/lowcode-utils';
import { IDocumentModel } from '../designer';
import type { IDocumentModel } from '../designer';

const logger = new Logger({ level: 'warn', bizName: 'history' });

Expand Down
Loading
Loading