mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-03-06 10:27:22 +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 { IEditor, isJSExpression } from '@ali/lowcode-types';
|
||||||
import { uniqueId } from '@ali/lowcode-utils';
|
import { uniqueId } from '@ali/lowcode-utils';
|
||||||
import { SettingEntry } from './setting-entry';
|
import { SettingEntry } from './setting-entry';
|
||||||
import { Node } from '../../document';
|
import { Node } from '../../document';
|
||||||
import { ComponentMeta } from '../../component-meta';
|
import { ComponentMeta } from '../../component-meta';
|
||||||
import { Designer } from '../designer';
|
import { Designer } from '../designer';
|
||||||
|
import { EventEmitter } from 'events';
|
||||||
|
|
||||||
export class SettingPropEntry implements SettingEntry {
|
export class SettingPropEntry implements SettingEntry {
|
||||||
// === static properties ===
|
// === static properties ===
|
||||||
@ -20,6 +21,8 @@ export class SettingPropEntry implements SettingEntry {
|
|||||||
readonly type: 'field' | 'group';
|
readonly type: 'field' | 'group';
|
||||||
readonly id = uniqueId('entry');
|
readonly id = uniqueId('entry');
|
||||||
|
|
||||||
|
readonly emitter = new EventEmitter();
|
||||||
|
|
||||||
// ==== dynamic properties ====
|
// ==== dynamic properties ====
|
||||||
@obx.ref private _name: string | number;
|
@obx.ref private _name: string | number;
|
||||||
get name() {
|
get name() {
|
||||||
@ -59,6 +62,14 @@ export class SettingPropEntry implements SettingEntry {
|
|||||||
this.isSingle = parent.isSingle;
|
this.isSingle = parent.isSingle;
|
||||||
this.designer = parent.designer;
|
this.designer = parent.designer;
|
||||||
this.top = parent.top;
|
this.top = parent.top;
|
||||||
|
|
||||||
|
autorun(({ firstRun }) => {
|
||||||
|
const value = this.getValue();
|
||||||
|
if (firstRun) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.emitter.emit('valuechange', value);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getId() {
|
getId() {
|
||||||
@ -88,7 +99,7 @@ export class SettingPropEntry implements SettingEntry {
|
|||||||
const propName = this.path.join('.');
|
const propName = this.path.join('.');
|
||||||
let l = this.nodes.length;
|
let l = this.nodes.length;
|
||||||
while (l-- > 1) {
|
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) {
|
if (setValue) {
|
||||||
setValue(this, val);
|
setValue(this, val);
|
||||||
}
|
}
|
||||||
// TODO: emit value change
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -170,9 +180,21 @@ export class SettingPropEntry implements SettingEntry {
|
|||||||
return this.top;
|
return this.top;
|
||||||
}
|
}
|
||||||
|
|
||||||
onValueChange() {
|
onValueChange(func: () => any) {
|
||||||
// TODO:
|
this.emitter.on('valuechange', func);
|
||||||
return () => {};
|
|
||||||
|
return () => {
|
||||||
|
this.emitter.removeListener('valuechange', func);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
valueChange() {
|
||||||
|
console.warn('valueChange deprecated');
|
||||||
|
|
||||||
|
this.emitter.emit('valuechange');
|
||||||
}
|
}
|
||||||
|
|
||||||
getDefaultValue() {
|
getDefaultValue() {
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import {
|
|||||||
SlotSchema,
|
SlotSchema,
|
||||||
PageSchema,
|
PageSchema,
|
||||||
ComponentSchema,
|
ComponentSchema,
|
||||||
|
NodeStatus,
|
||||||
} from '@ali/lowcode-types';
|
} from '@ali/lowcode-types';
|
||||||
import { Props, EXTRA_KEY_PREFIX } from './props/props';
|
import { Props, EXTRA_KEY_PREFIX } from './props/props';
|
||||||
import { DocumentModel } from '../document-model';
|
import { DocumentModel } from '../document-model';
|
||||||
@ -483,7 +484,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { props = {}, extras } = this.props.export(stage) || {};
|
const { props = {}, extras } = this.props.export(stage) || {};
|
||||||
const _extras_: {[key: string]: any} = {
|
const _extras_: { [key: string]: any } = {
|
||||||
...extras,
|
...extras,
|
||||||
};
|
};
|
||||||
if (_extras_) {
|
if (_extras_) {
|
||||||
@ -597,16 +598,34 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
|||||||
this.children?.mergeChildren(remover, adder, sorter);
|
this.children?.mergeChildren(remover, adder, sorter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@obx.val status: NodeStatus = {
|
||||||
|
inPlaceEditing: false,
|
||||||
|
locking: false,
|
||||||
|
pseudo: false,
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
getStatus() {
|
getStatus(field?: keyof NodeStatus) {
|
||||||
return 'default';
|
if (field && this.status[field] != null) {
|
||||||
|
return this.status[field];
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.status;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
setStatus() {}
|
setStatus(field: keyof NodeStatus, flag: boolean) {
|
||||||
|
if (!this.status.hasOwnProperty(field)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flag !== this.status[field]) {
|
||||||
|
this.status[field] = flag;
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
@ -666,9 +685,9 @@ export interface LeafNode extends Node {
|
|||||||
readonly children: null;
|
readonly children: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SlotNode extends ParentalNode<SlotSchema> {}
|
export type SlotNode = ParentalNode<SlotSchema>;
|
||||||
export interface PageNode extends ParentalNode<PageSchema> {}
|
export type PageNode = ParentalNode<PageSchema>;
|
||||||
export interface ComponentNode extends ParentalNode<ComponentSchema> {}
|
export type ComponentNode = ParentalNode<ComponentSchema>;
|
||||||
export type RootNode = PageNode | ComponentNode;
|
export type RootNode = PageNode | ComponentNode;
|
||||||
|
|
||||||
export function isNode(node: any): node is Node {
|
export function isNode(node: any): node is Node {
|
||||||
|
|||||||
@ -13,3 +13,4 @@ export * from './utils';
|
|||||||
export * from './value-type';
|
export * from './value-type';
|
||||||
export * from './setter-config';
|
export * from './setter-config';
|
||||||
export * from './setting-target';
|
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