Skip to content

Commit

Permalink
feat: add config for engines
Browse files Browse the repository at this point in the history
  • Loading branch information
jarekdanielak committed Dec 6, 2024
1 parent c585fd4 commit 5bf2e78
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
26 changes: 24 additions & 2 deletions src/cloud-element-templates/ElementTemplates.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import {
isArray,
isFunction
} from 'min-dash';

import {
getTemplateId,
getTemplateVersion
Expand All @@ -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) {
Expand Down Expand Up @@ -75,12 +88,21 @@ export default class ElementTemplates extends DefaultElementTemplates {

return context.element;
}

getEngines() {
return this._engines;
}

setEngines(engines) {
this._engines = engines;
}
}

ElementTemplates.$inject = [
'templateElementFactory',
'commandStack',
'eventBus',
'modeling',
'injector'
'injector',
'config.elementTemplates',
];
23 changes: 22 additions & 1 deletion src/cloud-element-templates/ElementTemplatesLoader.js
Original file line number Diff line number Diff line change
@@ -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<TemplateDescriptor>|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);

Expand Down

0 comments on commit 5bf2e78

Please sign in to comment.