mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-13 01:21:58 +00:00
feat: 修复状态切换失效
This commit is contained in:
parent
7f794bd141
commit
2e3f60d86c
@ -1,10 +1,11 @@
|
||||
import { obx, computed } from '@ali/lowcode-editor-core';
|
||||
import { obx, computed, autorun } from '@ali/lowcode-editor-core';
|
||||
import { IEditor, isJSExpression } from '@ali/lowcode-types';
|
||||
import { uniqueId } from '@ali/lowcode-utils';
|
||||
import { SettingEntry } from './setting-entry';
|
||||
import { Node } from '../../document';
|
||||
import { ComponentMeta } from '../../component-meta';
|
||||
import { Designer } from '../designer';
|
||||
import { EventEmitter } from 'events';
|
||||
|
||||
export class SettingPropEntry implements SettingEntry {
|
||||
// === static properties ===
|
||||
@ -20,6 +21,8 @@ export class SettingPropEntry implements SettingEntry {
|
||||
readonly type: 'field' | 'group';
|
||||
readonly id = uniqueId('entry');
|
||||
|
||||
readonly emitter = new EventEmitter();
|
||||
|
||||
// ==== dynamic properties ====
|
||||
@obx.ref private _name: string | number;
|
||||
get name() {
|
||||
@ -59,6 +62,14 @@ export class SettingPropEntry implements SettingEntry {
|
||||
this.isSingle = parent.isSingle;
|
||||
this.designer = parent.designer;
|
||||
this.top = parent.top;
|
||||
|
||||
autorun(({ firstRun }) => {
|
||||
const value = this.getValue();
|
||||
if (firstRun) {
|
||||
return;
|
||||
}
|
||||
this.emitter.emit('valuechange', value);
|
||||
});
|
||||
}
|
||||
|
||||
getId() {
|
||||
@ -88,7 +99,7 @@ export class SettingPropEntry implements SettingEntry {
|
||||
const propName = this.path.join('.');
|
||||
let l = this.nodes.length;
|
||||
while (l-- > 1) {
|
||||
this.nodes[l].getProp(propName)?.remove()
|
||||
this.nodes[l].getProp(propName)?.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@ -117,7 +128,6 @@ export class SettingPropEntry implements SettingEntry {
|
||||
if (setValue) {
|
||||
setValue(this, val);
|
||||
}
|
||||
// TODO: emit value change
|
||||
}
|
||||
|
||||
/**
|
||||
@ -170,9 +180,21 @@ export class SettingPropEntry implements SettingEntry {
|
||||
return this.top;
|
||||
}
|
||||
|
||||
onValueChange() {
|
||||
// TODO:
|
||||
return () => {};
|
||||
onValueChange(func: () => any) {
|
||||
this.emitter.on('valuechange', func);
|
||||
|
||||
return () => {
|
||||
this.emitter.removeListener('valuechange', func);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
valueChange() {
|
||||
console.warn('valueChange deprecated');
|
||||
|
||||
this.emitter.emit('valuechange');
|
||||
}
|
||||
|
||||
getDefaultValue() {
|
||||
|
||||
@ -10,6 +10,7 @@ import {
|
||||
SlotSchema,
|
||||
PageSchema,
|
||||
ComponentSchema,
|
||||
NodeStatus,
|
||||
} from '@ali/lowcode-types';
|
||||
import { Props, EXTRA_KEY_PREFIX } from './props/props';
|
||||
import { DocumentModel } from '../document-model';
|
||||
@ -483,7 +484,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
}
|
||||
|
||||
const { props = {}, extras } = this.props.export(stage) || {};
|
||||
const _extras_: {[key: string]: any} = {
|
||||
const _extras_: { [key: string]: any } = {
|
||||
...extras,
|
||||
};
|
||||
if (_extras_) {
|
||||
@ -597,16 +598,34 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
this.children?.mergeChildren(remover, adder, sorter);
|
||||
}
|
||||
|
||||
@obx.val status: NodeStatus = {
|
||||
inPlaceEditing: false,
|
||||
locking: false,
|
||||
pseudo: false,
|
||||
};
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
getStatus() {
|
||||
return 'default';
|
||||
getStatus(field?: keyof NodeStatus) {
|
||||
if (field && this.status[field] != null) {
|
||||
return this.status[field];
|
||||
}
|
||||
|
||||
return this.status;
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
setStatus() {}
|
||||
setStatus(field: keyof NodeStatus, flag: boolean) {
|
||||
if (!this.status.hasOwnProperty(field)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (flag !== this.status[field]) {
|
||||
this.status[field] = flag;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
@ -666,9 +685,9 @@ export interface LeafNode extends Node {
|
||||
readonly children: null;
|
||||
}
|
||||
|
||||
export interface SlotNode extends ParentalNode<SlotSchema> {}
|
||||
export interface PageNode extends ParentalNode<PageSchema> {}
|
||||
export interface ComponentNode extends ParentalNode<ComponentSchema> {}
|
||||
export type SlotNode = ParentalNode<SlotSchema>;
|
||||
export type PageNode = ParentalNode<PageSchema>;
|
||||
export type ComponentNode = ParentalNode<ComponentSchema>;
|
||||
export type RootNode = PageNode | ComponentNode;
|
||||
|
||||
export function isNode(node: any): node is Node {
|
||||
|
||||
@ -13,3 +13,4 @@ export * from './utils';
|
||||
export * from './value-type';
|
||||
export * from './setter-config';
|
||||
export * from './setting-target';
|
||||
export * from './node';
|
||||
|
||||
5
packages/types/src/node.ts
Normal file
5
packages/types/src/node.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export interface NodeStatus {
|
||||
locking: boolean;
|
||||
pseudo: boolean;
|
||||
inPlaceEditing: boolean;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user