fix: documentModel 里的 addon 相关函数跟原 vision 实现对齐

This commit is contained in:
力皓 2020-12-03 15:56:37 +08:00
parent 3c000decb5
commit b0ea54806e
3 changed files with 30 additions and 9 deletions

View File

@ -73,7 +73,7 @@ export class DocumentModel {
/** /**
* @deprecated * @deprecated
*/ */
private _addons: { [key: string]: { exportData: () => any; isProp: boolean;} } = {}; private _addons: Array<{ name: string, exportData: any }> = [];
/** /**
* *
@ -573,8 +573,26 @@ export class DocumentModel {
* @deprecated * @deprecated
*/ */
getAddonData(name: string) { getAddonData(name: string) {
const addon = this._addons[name]; const addon = this._addons.find((item) => item.name === name);
return addon?.exportData(); if (addon) {
return addon.exportData();
}
}
/**
* @deprecated
*/
exportAddonData() {
const addons = {};
this._addons.forEach((addon) => {
const data = addon.exportData();
if (data === null) {
delete addons[addon.name];
} else {
addons[addon.name] = data;
}
});
return addons;
} }
/** /**
@ -584,13 +602,16 @@ export class DocumentModel {
if (['id', 'params', 'layout'].indexOf(name) > -1) { if (['id', 'params', 'layout'].indexOf(name) > -1) {
throw new Error('addon name cannot be id, params, layout'); throw new Error('addon name cannot be id, params, layout');
} }
if (this._addons[name]) { const i = this._addons.findIndex((item) => item.name === name);
throw new Error(`node addon ${name} exists`); if (i > -1) {
this._addons.splice(i, 1);
} }
this._addons[name] = exportData; this._addons.push({
exportData,
name,
});
} }
acceptRootNodeVisitor( acceptRootNodeVisitor(
visitorName = 'default', visitorName = 'default',
visitorFn: (node: RootNode) => any, visitorFn: (node: RootNode) => any,

View File

@ -49,7 +49,7 @@ export class SettingsPrimaryPane extends Component<{ editor: Editor; config: any
<div className="lc-settings-navigator"> <div className="lc-settings-navigator">
{createIcon(settings.componentMeta?.icon, { className: 'lc-settings-navigator-icon' })} {createIcon(settings.componentMeta?.icon, { className: 'lc-settings-navigator-icon' })}
<Title title={settings.componentMeta!.title} /> <Title title={settings.componentMeta!.title} />
<span>x {settings.nodes.length}</span> <span> x {settings.nodes.length}</span>
</div> </div>
); );
} }

View File

@ -57,5 +57,5 @@
"publishConfig": { "publishConfig": {
"registry": "https://registry.npm.alibaba-inc.com" "registry": "https://registry.npm.alibaba-inc.com"
}, },
"homepage": "https://unpkg.alibaba-inc.com/@ali/lowcode-rax-simulator-renderer@0.13.1-26/build/index.html" "homepage": "https://unpkg.alibaba-inc.com/@ali/lowcode-rax-simulator-renderer@0.13.1-27/build/index.html"
} }