This commit is contained in:
2025-12-06 02:19:51 +01:00
parent 2215f70952
commit 7cc224cf92

View File

@@ -131,27 +131,12 @@
setTimeout(() => {
const ReferenceModel = defaultType.model.extend({
defaults: {
...defaultType.model.prototype.defaults,
components: [],
editable: false,
removable: true,
draggable: true,
copyable: true,
droppable: false,
traits: [
{ type: 'text', name: 'lib-id', label: 'Library ID', changeProp: true },
{ type: 'text', name: 'lib-kind', label: 'Library Kind', changeProp: true },
],
'lib-id': '',
'lib-kind': '',
startContent: '',
rawHtml: '',
},
initialize(props = {}, opts = {}) {
defaultType.model.prototype.initialize.apply(this, [props, opts]);
this.applyReferenceDefaults();
this.on('change:lib-kind change:lib-id', () => {
this.ensureReferenceMetadata();
this.reloadComponentContent();
@@ -172,6 +157,39 @@
}
},
applyReferenceDefaults() {
const enforced = {
editable: false,
removable: true,
draggable: true,
copyable: true,
droppable: false,
'lib-id': this.get('lib-id') || '',
'lib-kind': this.get('lib-kind') || '',
rawHtml: this.get('rawHtml') || '',
};
Object.entries(enforced).forEach(([key, value]) => {
if (typeof this.get(key) === 'undefined') {
this.set(key, value, { silent: true });
}
});
const traits = this.get('traits');
const hasLibTraits = Array.isArray(traits) && traits.some(t => t?.name === 'lib-id' || t?.name === 'lib-kind');
if (!hasLibTraits) {
this.set('traits', [
{ type: 'text', name: 'lib-id', label: 'Library ID', changeProp: true },
{ type: 'text', name: 'lib-kind', label: 'Library Kind', changeProp: true },
], { silent: true });
}
const comps = this.components?.();
if (comps && typeof comps.reset === 'function' && comps.length) {
comps.reset([]);
}
},
ensureReferenceMetadata() {
const attrsCurrent = this.get('attributes') || {};
let attrs = Array.isArray(attrsCurrent) ? {} : { ...attrsCurrent };