From 5bf2e78cbd6edf2346cc1f27da5ce394096a420e 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 | 26 +++++++++++++++++-- .../ElementTemplatesLoader.js | 23 +++++++++++++++- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/cloud-element-templates/ElementTemplates.js b/src/cloud-element-templates/ElementTemplates.js index 08df40ea..9c54de67 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,18 @@ 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 config is function or array, we don't want to use it + if (!(isArray(this._config) || isFunction(this._config))) { + this._config = config || {}; + this._engines = this._config.engines; + } } _getTemplateId(element) { @@ -75,6 +88,14 @@ export default class ElementTemplates extends DefaultElementTemplates { return context.element; } + + getEngines() { + return this._engines; + } + + setEngines(engines) { + this._engines = engines; + } } ElementTemplates.$inject = [ @@ -82,5 +103,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..3bd12229 100644 --- a/src/cloud-element-templates/ElementTemplatesLoader.js +++ b/src/cloud-element-templates/ElementTemplatesLoader.js @@ -1,9 +1,30 @@ +import { + isFunction, + isArray +} from 'min-dash'; + 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) { + + let loadTemplates; + + if (isArray(config) || isFunction(config)) { + loadTemplates = config; + } + + if (config && config.loadTemplates) { + loadTemplates = config.loadTemplates; + } super(loadTemplates, eventBus, elementTemplates, moddle);