@miragon/create-append-c7 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +64 -0
- package/dist/ExtendElementTemplates.d.ts +26 -0
- package/dist/ExtendElementTemplates.js +30 -0
- package/dist/TemplateElementFactory.d.ts +51 -0
- package/dist/TemplateElementFactory.js +73 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +22 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Miragon GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# @miragon/create-append-c7
|
|
2
|
+
|
|
3
|
+
> **Renamed package.** This is the continuation of
|
|
4
|
+
> [`@miragon/miranum-create-append-c7-element-templates`](https://www.npmjs.com/package/@miragon/miranum-create-append-c7-element-templates).
|
|
5
|
+
> npm packages cannot be renamed in place, so the project moved to this
|
|
6
|
+
> de-prefixed name starting at `0.1.0`. The legacy package is deprecated and
|
|
7
|
+
> receives no further updates — switch your dependency to
|
|
8
|
+
> `@miragon/create-append-c7`.
|
|
9
|
+
|
|
10
|
+
A [bpmn-js](https://github.com/bpmn-io/bpmn-js) DI module that polyfills
|
|
11
|
+
`elementTemplates.createElement()` for the **Camunda 7** modeler, so the
|
|
12
|
+
[`bpmn-js-create-append-anything`](https://github.com/bpmn-io/bpmn-js-create-append-anything)
|
|
13
|
+
plugin can create elements that already carry an element template.
|
|
14
|
+
|
|
15
|
+
## Why this exists
|
|
16
|
+
|
|
17
|
+
`bpmn-js-create-append-anything` calls `elementTemplates.createElement(template)`
|
|
18
|
+
to instantiate a shape that is preconfigured with a template. The Camunda 7
|
|
19
|
+
element-templates build does **not** ship `createElement`, so append-anything
|
|
20
|
+
cannot create template-preconfigured elements out of the box. This module patches
|
|
21
|
+
the missing method onto the C7 element-templates service at modeler startup.
|
|
22
|
+
|
|
23
|
+
> The Camunda 8 (Cloud) build already ships `createElement`, so this polyfill is
|
|
24
|
+
> only needed for the Camunda 7 (Platform) modeler.
|
|
25
|
+
|
|
26
|
+
## Install
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @miragon/create-append-c7
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Peer dependencies
|
|
33
|
+
|
|
34
|
+
This module is a thin add-on to your existing bpmn-js stack and declares its
|
|
35
|
+
hosts as peer dependencies:
|
|
36
|
+
|
|
37
|
+
| Peer | Supported range |
|
|
38
|
+
|---|---|
|
|
39
|
+
| `bpmn-js` | `^18.0.0` |
|
|
40
|
+
| `bpmn-js-create-append-anything` | `^1.2.0` |
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
Register the module as an `additionalModule` when you construct the Camunda 7
|
|
45
|
+
modeler:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { CreateAppendC7ElementTemplatesModule } from "@miragon/create-append-c7";
|
|
49
|
+
|
|
50
|
+
const modeler = new BpmnModeler({
|
|
51
|
+
additionalModules: [
|
|
52
|
+
CreateAppendC7ElementTemplatesModule,
|
|
53
|
+
// ...your other modules (e.g. CreateAppendElementTemplatesModule)
|
|
54
|
+
],
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The module installs itself on init: it patches `elementTemplates.createElement`
|
|
59
|
+
only when the host service does not already provide it, so it is safe to leave
|
|
60
|
+
registered even if a future bpmn-js / Camunda build adds the method natively.
|
|
61
|
+
|
|
62
|
+
## License
|
|
63
|
+
|
|
64
|
+
[MIT](./LICENSE)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Polyfills `elementTemplates.createElement()` on the C7 element templates
|
|
3
|
+
* service if the method does not already exist.
|
|
4
|
+
*
|
|
5
|
+
* The `bpmn-js-create-append-anything` plugin calls `createElement()` to
|
|
6
|
+
* produce a shape preconfigured with a template, but the Camunda 7
|
|
7
|
+
* properties panel does not ship this method. This class bridges the gap
|
|
8
|
+
* by delegating to {@link TemplateElementFactory}.
|
|
9
|
+
*/
|
|
10
|
+
import type { TemplateElementFactory } from "./TemplateElementFactory";
|
|
11
|
+
/**
|
|
12
|
+
* DI initialiser that patches `createElement` onto the C7 element templates
|
|
13
|
+
* service instance at startup.
|
|
14
|
+
*/
|
|
15
|
+
export declare class ExtendElementTemplates {
|
|
16
|
+
static $inject: string[];
|
|
17
|
+
/**
|
|
18
|
+
* Checks whether `createElement` already exists on the element templates
|
|
19
|
+
* service. If not, assigns it as an instance method that delegates to
|
|
20
|
+
* the {@link TemplateElementFactory}.
|
|
21
|
+
*
|
|
22
|
+
* @param elementTemplates The bpmn-js element templates service.
|
|
23
|
+
* @param templateElementFactory The factory that creates template-preconfigured shapes.
|
|
24
|
+
*/
|
|
25
|
+
constructor(elementTemplates: any, templateElementFactory: TemplateElementFactory);
|
|
26
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExtendElementTemplates = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* DI initialiser that patches `createElement` onto the C7 element templates
|
|
6
|
+
* service instance at startup.
|
|
7
|
+
*/
|
|
8
|
+
class ExtendElementTemplates {
|
|
9
|
+
/**
|
|
10
|
+
* Checks whether `createElement` already exists on the element templates
|
|
11
|
+
* service. If not, assigns it as an instance method that delegates to
|
|
12
|
+
* the {@link TemplateElementFactory}.
|
|
13
|
+
*
|
|
14
|
+
* @param elementTemplates The bpmn-js element templates service.
|
|
15
|
+
* @param templateElementFactory The factory that creates template-preconfigured shapes.
|
|
16
|
+
*/
|
|
17
|
+
constructor(elementTemplates, templateElementFactory) {
|
|
18
|
+
if (typeof elementTemplates.createElement === "function") {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
elementTemplates.createElement = (template) => {
|
|
22
|
+
if (!template) {
|
|
23
|
+
throw new Error("template is missing");
|
|
24
|
+
}
|
|
25
|
+
return templateElementFactory.create(template);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.ExtendElementTemplates = ExtendElementTemplates;
|
|
30
|
+
ExtendElementTemplates.$inject = ["elementTemplates", "templateElementFactory"];
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subset of the element template schema needed to create a preconfigured shape.
|
|
3
|
+
*/
|
|
4
|
+
interface C7ElementTemplate {
|
|
5
|
+
id: string;
|
|
6
|
+
version?: number;
|
|
7
|
+
appliesTo: string[];
|
|
8
|
+
elementType?: {
|
|
9
|
+
value?: string;
|
|
10
|
+
eventDefinition?: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Factory that produces bpmn-js shapes with a Camunda 7 element template
|
|
15
|
+
* already applied, ready for placement on the canvas.
|
|
16
|
+
*/
|
|
17
|
+
export declare class TemplateElementFactory {
|
|
18
|
+
static $inject: string[];
|
|
19
|
+
private readonly commandStack;
|
|
20
|
+
private readonly elementFactory;
|
|
21
|
+
/**
|
|
22
|
+
* @param commandStack The bpmn-js command stack service.
|
|
23
|
+
* @param elementFactory The bpmn-js element factory service.
|
|
24
|
+
*/
|
|
25
|
+
constructor(commandStack: any, elementFactory: any);
|
|
26
|
+
/**
|
|
27
|
+
* Creates a shape with the given element template applied.
|
|
28
|
+
*
|
|
29
|
+
* @param template The element template to apply.
|
|
30
|
+
* @returns The created bpmn-js shape with template bindings applied.
|
|
31
|
+
*/
|
|
32
|
+
create(template: C7ElementTemplate): any;
|
|
33
|
+
/**
|
|
34
|
+
* Creates the base shape from the template's type information.
|
|
35
|
+
*
|
|
36
|
+
* Uses `elementType.value` if specified, otherwise falls back to the
|
|
37
|
+
* first entry in `appliesTo`.
|
|
38
|
+
*
|
|
39
|
+
* @param template The element template.
|
|
40
|
+
* @returns The created bpmn-js shape.
|
|
41
|
+
*/
|
|
42
|
+
private createShape;
|
|
43
|
+
/**
|
|
44
|
+
* Stamps the template ID and version onto the element's business object.
|
|
45
|
+
*
|
|
46
|
+
* @param element The bpmn-js shape.
|
|
47
|
+
* @param template The element template.
|
|
48
|
+
*/
|
|
49
|
+
private setModelerTemplate;
|
|
50
|
+
}
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TemplateElementFactory = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Creates bpmn-js shapes preconfigured with a Camunda 7 element template.
|
|
6
|
+
*
|
|
7
|
+
* Handles the three-step process:
|
|
8
|
+
* 1. Create the base shape from the template's `appliesTo` / `elementType`.
|
|
9
|
+
* 2. Stamp `camunda:modelerTemplate` and version onto the business object.
|
|
10
|
+
* 3. Execute the properties-panel command to apply template bindings.
|
|
11
|
+
*/
|
|
12
|
+
const ModelUtil_1 = require("bpmn-js/lib/util/ModelUtil");
|
|
13
|
+
/**
|
|
14
|
+
* Factory that produces bpmn-js shapes with a Camunda 7 element template
|
|
15
|
+
* already applied, ready for placement on the canvas.
|
|
16
|
+
*/
|
|
17
|
+
class TemplateElementFactory {
|
|
18
|
+
/**
|
|
19
|
+
* @param commandStack The bpmn-js command stack service.
|
|
20
|
+
* @param elementFactory The bpmn-js element factory service.
|
|
21
|
+
*/
|
|
22
|
+
constructor(commandStack, elementFactory) {
|
|
23
|
+
this.commandStack = commandStack;
|
|
24
|
+
this.elementFactory = elementFactory;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates a shape with the given element template applied.
|
|
28
|
+
*
|
|
29
|
+
* @param template The element template to apply.
|
|
30
|
+
* @returns The created bpmn-js shape with template bindings applied.
|
|
31
|
+
*/
|
|
32
|
+
create(template) {
|
|
33
|
+
const element = this.createShape(template);
|
|
34
|
+
this.setModelerTemplate(element, template);
|
|
35
|
+
this.commandStack.execute("propertiesPanel.camunda.changeTemplate", {
|
|
36
|
+
element,
|
|
37
|
+
oldTemplate: null,
|
|
38
|
+
newTemplate: template,
|
|
39
|
+
});
|
|
40
|
+
return element;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Creates the base shape from the template's type information.
|
|
44
|
+
*
|
|
45
|
+
* Uses `elementType.value` if specified, otherwise falls back to the
|
|
46
|
+
* first entry in `appliesTo`.
|
|
47
|
+
*
|
|
48
|
+
* @param template The element template.
|
|
49
|
+
* @returns The created bpmn-js shape.
|
|
50
|
+
*/
|
|
51
|
+
createShape(template) {
|
|
52
|
+
const { appliesTo, elementType } = template;
|
|
53
|
+
const type = elementType?.value ?? appliesTo[0];
|
|
54
|
+
const attrs = { type };
|
|
55
|
+
if (elementType?.eventDefinition) {
|
|
56
|
+
attrs.eventDefinitionType = elementType.eventDefinition;
|
|
57
|
+
}
|
|
58
|
+
return this.elementFactory.createShape(attrs);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Stamps the template ID and version onto the element's business object.
|
|
62
|
+
*
|
|
63
|
+
* @param element The bpmn-js shape.
|
|
64
|
+
* @param template The element template.
|
|
65
|
+
*/
|
|
66
|
+
setModelerTemplate(element, template) {
|
|
67
|
+
const businessObject = (0, ModelUtil_1.getBusinessObject)(element);
|
|
68
|
+
businessObject.set("camunda:modelerTemplate", template.id);
|
|
69
|
+
businessObject.set("camunda:modelerTemplateVersion", template.version);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.TemplateElementFactory = TemplateElementFactory;
|
|
73
|
+
TemplateElementFactory.$inject = ["commandStack", "elementFactory"];
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bpmn-js DI module that polyfills `elementTemplates.createElement()` for
|
|
3
|
+
* the Camunda 7 modeler, enabling the `bpmn-js-create-append-anything`
|
|
4
|
+
* plugin to create template-preconfigured elements.
|
|
5
|
+
*
|
|
6
|
+
* Register as an `additionalModule` when creating the C7 bpmn-js modeler:
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { CreateAppendC7ElementTemplatesModule } from "@miragon/create-append-c7-element-templates";
|
|
9
|
+
*
|
|
10
|
+
* new BpmnModeler({ additionalModules: [CreateAppendC7ElementTemplatesModule] });
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
import { ExtendElementTemplates } from "./ExtendElementTemplates";
|
|
14
|
+
import { TemplateElementFactory } from "./TemplateElementFactory";
|
|
15
|
+
export declare const CreateAppendC7ElementTemplatesModule: {
|
|
16
|
+
__init__: string[];
|
|
17
|
+
extendedElementTemplates: (string | typeof ExtendElementTemplates)[];
|
|
18
|
+
templateElementFactory: (string | typeof TemplateElementFactory)[];
|
|
19
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CreateAppendC7ElementTemplatesModule = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* bpmn-js DI module that polyfills `elementTemplates.createElement()` for
|
|
6
|
+
* the Camunda 7 modeler, enabling the `bpmn-js-create-append-anything`
|
|
7
|
+
* plugin to create template-preconfigured elements.
|
|
8
|
+
*
|
|
9
|
+
* Register as an `additionalModule` when creating the C7 bpmn-js modeler:
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { CreateAppendC7ElementTemplatesModule } from "@miragon/create-append-c7-element-templates";
|
|
12
|
+
*
|
|
13
|
+
* new BpmnModeler({ additionalModules: [CreateAppendC7ElementTemplatesModule] });
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
const ExtendElementTemplates_1 = require("./ExtendElementTemplates");
|
|
17
|
+
const TemplateElementFactory_1 = require("./TemplateElementFactory");
|
|
18
|
+
exports.CreateAppendC7ElementTemplatesModule = {
|
|
19
|
+
__init__: ["extendedElementTemplates"],
|
|
20
|
+
extendedElementTemplates: ["type", ExtendElementTemplates_1.ExtendElementTemplates],
|
|
21
|
+
templateElementFactory: ["type", TemplateElementFactory_1.TemplateElementFactory],
|
|
22
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@miragon/create-append-c7",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Polyfills elementTemplates.createElement() for the Camunda 7 bpmn-js modeler, enabling bpmn-js-create-append-anything to create template-preconfigured elements.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc -p tsconfig.lib.json"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"bpmn-js",
|
|
16
|
+
"bpmn-io",
|
|
17
|
+
"bpmn-js-element-templates",
|
|
18
|
+
"bpmn-js-create-append-anything",
|
|
19
|
+
"camunda-7"
|
|
20
|
+
],
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/Miragon/create-append-c7"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/Miragon/create-append-c7/issues"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"bpmn-js": "^18.0.0",
|
|
33
|
+
"bpmn-js-create-append-anything": "^1.2.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"bpmn-js": "18.16.1",
|
|
37
|
+
"typescript": "6.0.3"
|
|
38
|
+
}
|
|
39
|
+
}
|