add settingsEntry

This commit is contained in:
kangwei 2020-06-22 21:10:55 +08:00
parent f51bd34737
commit be4a58fc14
4 changed files with 9 additions and 6 deletions

View File

@ -21,6 +21,7 @@ import { ComponentMeta } from '../../component-meta';
import { ExclusiveGroup, isExclusiveGroup } from './exclusive-group';
import { TransformStage } from './transform-stage';
import { ReactElement } from 'react';
import { SettingTopEntry } from 'designer/src/designer';
/**
*
@ -142,6 +143,8 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
return this.componentMeta.icon;
}
readonly settingEntry: SettingTopEntry;
constructor(readonly document: DocumentModel, nodeSchema: Schema) {
const { componentName, id, children, props, ...extras } = nodeSchema;
this.id = id || `node_${document.nextId()}`;
@ -161,6 +164,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
if (this.componentMeta.isModal) {
this.getExtraProp('hidden', true)?.setValue(true);
}
this.settingEntry = this.document.designer.createSettingEntry([ this ]);
}
private transformProps(props: any): any {
@ -384,7 +388,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
// todo
}
replaceWith(schema: Schema, migrate = false) {
replaceWith(schema: Schema, migrate = false): any {
// reuse the same id? or replaceSelection
schema = Object.assign({}, migrate ? this.export() : {}, schema);
return this.parent?.replaceChild(this, schema);
@ -396,7 +400,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
* @param {Node} node
* @param {object} data
*/
replaceChild(node: Node, data: any) {
replaceChild(node: Node, data: any): Node {
if (this.children?.has(node)) {
const selected = this.document.selection.has(node.id);

View File

@ -711,8 +711,7 @@ export function upgradeMetadata(oldConfig: OldPrototypeConfig) {
experimental.initialChildren =
typeof initialChildren === 'function'
? (node: any) => {
const props = designer.createSettingEntry(editor, [ node ]);
return initialChildren.call(node, props);
return initialChildren.call(node, node.settingEntry);
}
: initialChildren;
}

View File

@ -59,7 +59,7 @@ function filterReducer(props: any, node: Node): any {
return;
}
try {
if (item.filter(node.getProp(item.name) as any, props[item.name]) === false) {
if (item.filter(node.settingEntry.getProp(item.name), props[item.name]) === false) {
delete newProps[item.name];
}
} catch (e) {

View File

@ -67,7 +67,7 @@ export class SettingsMain {
this.designer = nodes[0].document.designer;
}
this._settings = this.designer.createSettingEntry(this.editor, nodes);
this._settings = this.designer.createSettingEntry(nodes);
}
purge() {