From 71b86f9937c10a8b88a99bcac4813998982285a2 Mon Sep 17 00:00:00 2001 From: Jarek Danielak Date: Fri, 6 Dec 2024 14:32:12 +0100 Subject: [PATCH] feat: add config for engines --- .../ElementTemplates.js | 25 +++++++++++++++++-- .../ElementTemplatesLoader.js | 10 ++++++-- .../ElementTemplatesLoader.js | 15 ++++++++--- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/cloud-element-templates/ElementTemplates.js b/src/cloud-element-templates/ElementTemplates.js index 08df40ea..91a45d9e 100644 --- a/src/cloud-element-templates/ElementTemplates.js +++ b/src/cloud-element-templates/ElementTemplates.js @@ -1,3 +1,8 @@ +import { + isArray, + isFunction +} from 'min-dash'; + import { getTemplateId, getTemplateVersion @@ -9,10 +14,17 @@ import { default as DefaultElementTemplates } from '../element-templates/Element * Registry for element templates. */ export default class ElementTemplates extends DefaultElementTemplates { - constructor(templateElementFactory, commandStack, eventBus, modeling, injector) { + constructor(templateElementFactory, commandStack, eventBus, modeling, injector, config) { super(commandStack, eventBus, modeling, injector); this._templateElementFactory = templateElementFactory; + this._config = {}; + this._engines = {}; + + if (!(isArray(this._config) || isFunction(this._config))) { + this._config = config || {}; + this._engines = this._config.engines; + } } _getTemplateId(element) { @@ -75,6 +87,14 @@ export default class ElementTemplates extends DefaultElementTemplates { return context.element; } + + getEngines() { + return this._engines; + } + + setEngines(engines) { + this._engines = engines; + } } ElementTemplates.$inject = [ @@ -82,5 +102,6 @@ ElementTemplates.$inject = [ 'commandStack', 'eventBus', 'modeling', - 'injector' + 'injector', + 'config.elementTemplates', ]; diff --git a/src/cloud-element-templates/ElementTemplatesLoader.js b/src/cloud-element-templates/ElementTemplatesLoader.js index 2892b944..50c57c5e 100644 --- a/src/cloud-element-templates/ElementTemplatesLoader.js +++ b/src/cloud-element-templates/ElementTemplatesLoader.js @@ -2,10 +2,16 @@ import { Validator } from './Validator'; import { default as TemplatesLoader } from '../element-templates/ElementTemplatesLoader'; +/** + * @param {Object|Array|Function} config + * @param {EventBus} eventBus + * @param {ElementTemplates} elementTemplates + * @param {Moddle} moddle + */ export default class ElementTemplatesLoader extends TemplatesLoader { - constructor(loadTemplates, eventBus, elementTemplates, moddle) { + constructor(config, eventBus, elementTemplates, moddle) { - super(loadTemplates, eventBus, elementTemplates, moddle); + super(config, eventBus, elementTemplates, moddle); this._elementTemplates = elementTemplates; } diff --git a/src/element-templates/ElementTemplatesLoader.js b/src/element-templates/ElementTemplatesLoader.js index f8c42ed1..e31da305 100644 --- a/src/element-templates/ElementTemplatesLoader.js +++ b/src/element-templates/ElementTemplatesLoader.js @@ -1,6 +1,7 @@ import { isFunction, - isUndefined + isUndefined, + isArray, } from 'min-dash'; import { Validator } from './Validator'; @@ -20,12 +21,20 @@ import { Validator } from './Validator'; * @param {Moddle} moddle */ export default class ElementTemplatesLoader { - constructor(loadTemplates, eventBus, elementTemplates, moddle) { - this._loadTemplates = loadTemplates; + constructor(config, eventBus, elementTemplates, moddle) { + this._loadTemplates; this._eventBus = eventBus; this._elementTemplates = elementTemplates; this._moddle = moddle; + if (isArray(config) || isFunction(config)) { + this._loadTemplates = config; + } + + if (config && config.loadTemplates) { + this._loadTemplates = config.loadTemplates; + } + eventBus.on('diagram.init', () => { this.reload(); });