diff --git a/packages/designer/src/designer/document/node/props/prop.ts b/packages/designer/src/designer/document/node/props/prop.ts index 9b91be6fa..5a9680541 100644 --- a/packages/designer/src/designer/document/node/props/prop.ts +++ b/packages/designer/src/designer/document/node/props/prop.ts @@ -205,6 +205,9 @@ export default class Prop implements IPropParent { if (this.type === 'list') { return this.size === other.size ? 1 : 2; } + if (this.type === 'map') { + return 1; + } // 'literal' | 'map' | 'expression' | 'slot' return this.code === other.code ? 0 : 2; @@ -286,25 +289,12 @@ export default class Prop implements IPropParent { */ get(path: string | number, stash = true): Prop | null { const type = this._type; - // todo: support list get if (type !== 'map' && type !== 'list' && type !== 'unset' && !stash) { return null; } const maps = type === 'map' ? this.maps : null; const items = type === 'list' ? this.items : null; - let prop: any; - if (type === 'list') { - if (isValidArrayIndex(path, this.size)) { - prop = items![path]; - } - } else if (type === 'map') { - prop = maps?.get(path); - } - - if (prop) { - return prop; - } let entry = path; let nest = ''; @@ -314,22 +304,23 @@ export default class Prop implements IPropParent { nest = path.slice(i + 1); if (nest) { entry = path.slice(0, i); - - if (type === 'list') { - if (isValidArrayIndex(entry, this.size)) { - prop = items![entry]; - } - } else if (type === 'map') { - prop = maps?.get(entry); - } - - if (prop) { - return prop.get(nest, stash); - } } } } + let prop: any; + if (type === 'list') { + if (isValidArrayIndex(entry, this.size)) { + prop = items![entry]; + } + } else if (type === 'map') { + prop = maps?.get(entry); + } + + if (prop) { + return nest ? prop.get(nest, stash) : prop; + } + if (stash) { if (!this.stash) { this.stash = new PropStash(this.props, item => { @@ -549,7 +540,7 @@ export function isProp(obj: any): obj is Prop { return obj && obj.isProp; } -function isValidArrayIndex(key: any, limit = -1): key is number { +export function isValidArrayIndex(key: any, limit = -1): key is number { const n = parseFloat(String(key)); return n >= 0 && Math.floor(n) === n && isFinite(n) && (limit < 0 || n < limit); } diff --git a/packages/designer/src/designer/document/node/props/props.ts b/packages/designer/src/designer/document/node/props/props.ts index c604ef88c..3d655c7bb 100644 --- a/packages/designer/src/designer/document/node/props/props.ts +++ b/packages/designer/src/designer/document/node/props/props.ts @@ -81,7 +81,7 @@ export default class Props implements IPropParent { }); } - export(serialize = false): { props?: PropsMap | PropsList; extras?: object} { + export(serialize = false): { props?: PropsMap | PropsList; extras?: object } { if (this.items.length < 1) { return {}; } @@ -126,15 +126,17 @@ export default class Props implements IPropParent { }); } - return { props, extras }; + return { props, extras }; } /** * 根据 path 路径查询属性 * - * @useStash 如果没有则临时生成一个 + * @param stash 如果没有则临时生成一个 */ - query(path: string, useStash: boolean = true): Prop | null { + query(path: string, stash = true): Prop | null { + return this.get(path, stash); + // todo: future support list search let matchedLength = 0; let firstMatched = null; if (this.items) { @@ -165,7 +167,7 @@ export default class Props implements IPropParent { if (firstMatched) { ret = firstMatched.get(path.slice(matchedLength + 1), true); } - if (!ret && useStash) { + if (!ret && stash) { return this.stash.get(path); } @@ -174,10 +176,26 @@ export default class Props implements IPropParent { /** * 获取某个属性, 如果不存在,临时获取一个待写入 - * @param useStash 强制 + * @param stash 强制 */ - get(name: string, useStash = false): Prop | null { - return this.maps.get(name) || (useStash && this.stash.get(name)) || null; + get(path: string, stash = false): Prop | null { + let entry = path; + let nest = ''; + const i = path.indexOf('.'); + if (i > 0) { + nest = path.slice(i + 1); + if (nest) { + entry = path.slice(0, i); + } + } + + const prop = this.maps.get(entry) || (stash && this.stash.get(entry)) || null; + + if (prop) { + return nest ? prop.get(nest, stash) : prop; + } + + return null; } /** diff --git a/packages/plugin-settings/src/builtin-setters/array-setter/index.tsx b/packages/plugin-settings/src/builtin-setters/array-setter/index.tsx index f68e3dd58..8c802ceea 100644 --- a/packages/plugin-settings/src/builtin-setters/array-setter/index.tsx +++ b/packages/plugin-settings/src/builtin-setters/array-setter/index.tsx @@ -137,6 +137,8 @@ export class ListSetter extends Component { // check is ObjectSetter then check if show columns } + console.info(this.state.items); + const { items } = this.state; const scrollToLast = this.scrollToLast; this.scrollToLast = false; @@ -265,7 +267,7 @@ export default class ArraySetter extends Component<{ return (