@miragon/create-append-c7 0.1.0 → 1.0.1
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/CHANGELOG.md +34 -0
- package/README.md +104 -16
- package/dist/ApplyTemplateOnShapeCreateBehavior.d.ts +9 -0
- package/dist/ApplyTemplateOnShapeCreateBehavior.js +31 -0
- package/dist/ExtendElementTemplates.d.ts +2 -12
- package/dist/ExtendElementTemplates.js +7 -9
- package/dist/TemplateElementFactory.d.ts +18 -34
- package/dist/TemplateElementFactory.js +41 -56
- package/dist/index.d.ts +5 -3
- package/dist/index.js +6 -4
- package/package.json +58 -38
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [1.0.1](https://github.com/Miragon/create-append-c7/compare/v1.0.0...v1.0.1) (2026-09-11)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### 🐞 Bug Fixes
|
|
7
|
+
|
|
8
|
+
* **ci:** match npm trusted publisher environment ([#12](https://github.com/Miragon/create-append-c7/issues/12)) ([279077b](https://github.com/Miragon/create-append-c7/commit/279077b67e886cc3b5ddf75f80340afc0b8f813c))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### 🛠️ Misc
|
|
12
|
+
|
|
13
|
+
* **deps-dev:** bump bpmn-js-create-append-anything ([#11](https://github.com/Miragon/create-append-c7/issues/11)) ([084b545](https://github.com/Miragon/create-append-c7/commit/084b54552a54ed30f1d7c1558304613b57406480))
|
|
14
|
+
|
|
15
|
+
## [1.0.0](https://github.com/Miragon/create-append-c7/compare/v0.1.0...v1.0.0) (2026-09-11)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### ⚠ BREAKING CHANGES
|
|
19
|
+
|
|
20
|
+
* apply C7 template bindings during placement ([#3](https://github.com/Miragon/create-append-c7/issues/3))
|
|
21
|
+
|
|
22
|
+
### 🐞 Bug Fixes
|
|
23
|
+
|
|
24
|
+
* apply C7 template bindings during placement ([#3](https://github.com/Miragon/create-append-c7/issues/3)) ([62dc687](https://github.com/Miragon/create-append-c7/commit/62dc687f91864faef2b0fa57346fb4e3c4fde3e8))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### 🛠️ Misc
|
|
28
|
+
|
|
29
|
+
* **ci:** enable dependabot ([#6](https://github.com/Miragon/create-append-c7/issues/6)) ([b8cf694](https://github.com/Miragon/create-append-c7/commit/b8cf6942b302ed037b15b427df971edb0452925e))
|
|
30
|
+
* **deps-dev:** bump the npm-major group with 2 updates ([#9](https://github.com/Miragon/create-append-c7/issues/9)) ([b4479bf](https://github.com/Miragon/create-append-c7/commit/b4479bfb75bc975cf886fb5b22406942707cc73a))
|
|
31
|
+
* **deps-dev:** bump the npm-minor-patch group with 2 updates ([#8](https://github.com/Miragon/create-append-c7/issues/8)) ([ec0935a](https://github.com/Miragon/create-append-c7/commit/ec0935ae55f8d248f1efc8b29913b498446e4f83))
|
|
32
|
+
* **deps:** bump the github-actions-all group with 2 updates ([#7](https://github.com/Miragon/create-append-c7/issues/7)) ([3f459b4](https://github.com/Miragon/create-append-c7/commit/3f459b412279e380249d1ce4a5cfe489f08a5039))
|
|
33
|
+
* migrate development and publishing to Yarn 4 ([#10](https://github.com/Miragon/create-append-c7/issues/10)) ([d443588](https://github.com/Miragon/create-append-c7/commit/d443588866bed87addbd2b89ce21d2e505ed13ef))
|
|
34
|
+
* **repo:** polish repository and automate releases ([#4](https://github.com/Miragon/create-append-c7/issues/4)) ([4d82e17](https://github.com/Miragon/create-append-c7/commit/4d82e170637985b5260985dc79f9b80fa2764cfc))
|
package/README.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @miragon/create-append-c7
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@miragon/create-append-c7)
|
|
4
|
+
[](https://github.com/Miragon/create-append-c7/actions/workflows/build.yml)
|
|
5
|
+
[](./LICENSE)
|
|
6
|
+
|
|
7
|
+
A [bpmn-js](https://github.com/bpmn-io/bpmn-js) DI module that polyfills
|
|
8
|
+
`elementTemplates.createElement()` for the **Camunda 7** modeler, so the
|
|
9
|
+
[`bpmn-js-create-append-anything`](https://github.com/bpmn-io/bpmn-js-create-append-anything)
|
|
10
|
+
plugin can create elements that already carry an element template.
|
|
11
|
+
|
|
3
12
|
> **Renamed package.** This is the continuation of
|
|
4
13
|
> [`@miragon/miranum-create-append-c7-element-templates`](https://www.npmjs.com/package/@miragon/miranum-create-append-c7-element-templates).
|
|
5
14
|
> npm packages cannot be renamed in place, so the project moved to this
|
|
@@ -7,18 +16,19 @@
|
|
|
7
16
|
> receives no further updates — switch your dependency to
|
|
8
17
|
> `@miragon/create-append-c7`.
|
|
9
18
|
|
|
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
19
|
## Why this exists
|
|
16
20
|
|
|
17
21
|
`bpmn-js-create-append-anything` calls `elementTemplates.createElement(template)`
|
|
18
|
-
to instantiate a shape
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
to instantiate a shape. The Camunda 7 element-templates build does **not** ship
|
|
23
|
+
that method, so append-anything cannot create template-preconfigured elements
|
|
24
|
+
out of the box. This module patches the missing method onto the C7
|
|
25
|
+
element-templates service at modeler startup.
|
|
26
|
+
|
|
27
|
+
The returned preview already has the resolved BPMN type, event definition, and
|
|
28
|
+
template identity. Template bindings are deliberately deferred until the shape
|
|
29
|
+
is placed on a diagram. This lets bindings safely access the process definitions
|
|
30
|
+
and keeps creation, configuration, and automatic-append connections in one undo
|
|
31
|
+
step.
|
|
22
32
|
|
|
23
33
|
> The Camunda 8 (Cloud) build already ships `createElement`, so this polyfill is
|
|
24
34
|
> only needed for the Camunda 7 (Platform) modeler.
|
|
@@ -26,7 +36,7 @@ the missing method onto the C7 element-templates service at modeler startup.
|
|
|
26
36
|
## Install
|
|
27
37
|
|
|
28
38
|
```bash
|
|
29
|
-
|
|
39
|
+
yarn add @miragon/create-append-c7
|
|
30
40
|
```
|
|
31
41
|
|
|
32
42
|
### Peer dependencies
|
|
@@ -37,7 +47,20 @@ hosts as peer dependencies:
|
|
|
37
47
|
| Peer | Supported range |
|
|
38
48
|
|---|---|
|
|
39
49
|
| `bpmn-js` | `^18.0.0` |
|
|
40
|
-
| `bpmn-js-create-append-anything` | `^1.2.0` |
|
|
50
|
+
| `bpmn-js-create-append-anything` | `^1.2.0 \|\| ^2.0.0` |
|
|
51
|
+
| `bpmn-js-element-templates` | `^2.27.0` |
|
|
52
|
+
|
|
53
|
+
The tested host combinations are:
|
|
54
|
+
|
|
55
|
+
| bpmn-js | Create/append | Element templates |
|
|
56
|
+
|---:|---:|---:|
|
|
57
|
+
| 18.16.1 | 1.2.0 | 2.27.0 |
|
|
58
|
+
| 18.25.1 | 2.0.0 | 2.33.0 |
|
|
59
|
+
| 18.28.0 | 1.2.0 | 2.35.0 |
|
|
60
|
+
| 18.28.0 | 2.0.0 | 2.35.0 |
|
|
61
|
+
|
|
62
|
+
Create/append 2.x itself requires bpmn-js 18.22 or newer; its stricter host
|
|
63
|
+
requirements still apply.
|
|
41
64
|
|
|
42
65
|
## Usage
|
|
43
66
|
|
|
@@ -45,20 +68,85 @@ Register the module as an `additionalModule` when you construct the Camunda 7
|
|
|
45
68
|
modeler:
|
|
46
69
|
|
|
47
70
|
```ts
|
|
71
|
+
import { ElementTemplatesCoreModule } from "bpmn-js-element-templates/core";
|
|
72
|
+
import { CreateAppendElementTemplatesModule } from "bpmn-js-create-append-anything";
|
|
48
73
|
import { CreateAppendC7ElementTemplatesModule } from "@miragon/create-append-c7";
|
|
74
|
+
import camundaModdle from "camunda-bpmn-moddle/resources/camunda.json";
|
|
49
75
|
|
|
50
76
|
const modeler = new BpmnModeler({
|
|
51
77
|
additionalModules: [
|
|
78
|
+
ElementTemplatesCoreModule,
|
|
79
|
+
CreateAppendElementTemplatesModule,
|
|
52
80
|
CreateAppendC7ElementTemplatesModule,
|
|
53
|
-
// ...your other modules (e.g. CreateAppendElementTemplatesModule)
|
|
54
81
|
],
|
|
82
|
+
moddleExtensions: {
|
|
83
|
+
camunda: camundaModdle,
|
|
84
|
+
},
|
|
55
85
|
});
|
|
56
86
|
```
|
|
57
87
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
88
|
+
Register the C7 element-templates module and create/append module as normal; this
|
|
89
|
+
adapter does not install either host module for you. It patches
|
|
90
|
+
`elementTemplates.createElement` only when the host service does not already
|
|
91
|
+
provide it. Native implementations and their `templateElementFactory` service
|
|
92
|
+
are left untouched, regardless of module registration order.
|
|
93
|
+
|
|
94
|
+
The example uses the headless `ElementTemplatesCoreModule`. Applications that
|
|
95
|
+
show template controls in the properties panel can register
|
|
96
|
+
`ElementTemplatesPropertiesProviderModule` and its properties-panel dependencies
|
|
97
|
+
instead; that module already includes the C7 core.
|
|
98
|
+
|
|
99
|
+
`createElement(template, options?)` accepts omitted or empty options. C8-style
|
|
100
|
+
template presets are not supported and a supplied `presetId` throws before a
|
|
101
|
+
shape is allocated.
|
|
102
|
+
|
|
103
|
+
## Timing and undo behavior
|
|
104
|
+
|
|
105
|
+
Starting with 0.2.0, `createElement()` returns a detached preview without applied
|
|
106
|
+
bindings. Bindings are applied by the upstream C7
|
|
107
|
+
`propertiesPanel.camunda.changeTemplate` command during `shape.create`. Direct
|
|
108
|
+
callers that previously inspected bindings before placement must move that work
|
|
109
|
+
after creation completes.
|
|
110
|
+
|
|
111
|
+
Canceled previews do not affect the diagram or command history. Once placed,
|
|
112
|
+
one undo removes the whole configured creation; redo restores the recorded
|
|
113
|
+
bindings without applying them a second time.
|
|
114
|
+
|
|
115
|
+
## Development
|
|
116
|
+
|
|
117
|
+
Use Node.js 22 and Corepack. The repository pins Yarn 4.18.0 and uses
|
|
118
|
+
`node_modules` for dependency resolution.
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
corepack enable
|
|
122
|
+
yarn install --immutable
|
|
123
|
+
yarn playwright install chromium
|
|
124
|
+
yarn check
|
|
125
|
+
yarn npm audit --all --recursive --severity high
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
`yarn check` runs the Chromium tests and validates the package contents;
|
|
129
|
+
`prepack` builds the JavaScript and declarations. Use `yarn build` to compile
|
|
130
|
+
without running tests. Commit `yarn.lock` when changing dependencies.
|
|
131
|
+
|
|
132
|
+
## Releases
|
|
133
|
+
|
|
134
|
+
Maintainers use [Conventional Commits](https://www.conventionalcommits.org/) to
|
|
135
|
+
drive version bumps and release notes. Merge the release-please PR to create the
|
|
136
|
+
matching GitHub release and publish it to npm using Yarn and OIDC Trusted
|
|
137
|
+
Publishing. If publishing fails, retry the failed publish job from that original
|
|
138
|
+
release workflow run. Already-published
|
|
139
|
+
versions are skipped. Manual Publish workflow runs only validate the package;
|
|
140
|
+
they never upload it. The supplied release tag must match the package version.
|
|
141
|
+
|
|
142
|
+
For a local publish preview after installing Chromium, run:
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
yarn npm publish --access public --dry-run
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Publishing runs the browser tests in `prepublish` and builds in `prepack`.
|
|
61
149
|
|
|
62
150
|
## License
|
|
63
151
|
|
|
64
|
-
[MIT](./LICENSE)
|
|
152
|
+
Licensed under the [MIT License](./LICENSE). Copyright © 2026 Miragon GmbH.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TemplateElementFactory } from "./TemplateElementFactory";
|
|
2
|
+
/**
|
|
3
|
+
* Applies templates to adapter-created shapes as part of the surrounding
|
|
4
|
+
* shape.create transaction, after the shape has been attached to the model.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ApplyTemplateOnShapeCreateBehavior {
|
|
7
|
+
static $inject: string[];
|
|
8
|
+
constructor(eventBus: any, commandStack: any, templateElementFactory: TemplateElementFactory);
|
|
9
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApplyTemplateOnShapeCreateBehavior = void 0;
|
|
4
|
+
const APPLY_TEMPLATE_PRIORITY = 1500;
|
|
5
|
+
/**
|
|
6
|
+
* Applies templates to adapter-created shapes as part of the surrounding
|
|
7
|
+
* shape.create transaction, after the shape has been attached to the model.
|
|
8
|
+
*/
|
|
9
|
+
class ApplyTemplateOnShapeCreateBehavior {
|
|
10
|
+
constructor(eventBus, commandStack, templateElementFactory) {
|
|
11
|
+
eventBus.on("commandStack.shape.create.postExecute", APPLY_TEMPLATE_PRIORITY, (event) => {
|
|
12
|
+
const element = event.context.shape;
|
|
13
|
+
const template = templateElementFactory.getPendingTemplate(element);
|
|
14
|
+
if (!template) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
commandStack.execute("propertiesPanel.camunda.changeTemplate", {
|
|
18
|
+
element,
|
|
19
|
+
oldTemplate: null,
|
|
20
|
+
newTemplate: omitElementType(template),
|
|
21
|
+
});
|
|
22
|
+
templateElementFactory.consumePendingTemplate(element);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.ApplyTemplateOnShapeCreateBehavior = ApplyTemplateOnShapeCreateBehavior;
|
|
27
|
+
ApplyTemplateOnShapeCreateBehavior.$inject = ["eventBus", "commandStack", "c7TemplateElementFactory"];
|
|
28
|
+
function omitElementType(template) {
|
|
29
|
+
const { elementType: _elementType, ...templateWithoutElementType } = template;
|
|
30
|
+
return templateWithoutElementType;
|
|
31
|
+
}
|
|
@@ -1,13 +1,3 @@
|
|
|
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
1
|
/**
|
|
12
2
|
* DI initialiser that patches `createElement` onto the C7 element templates
|
|
13
3
|
* service instance at startup.
|
|
@@ -20,7 +10,7 @@ export declare class ExtendElementTemplates {
|
|
|
20
10
|
* the {@link TemplateElementFactory}.
|
|
21
11
|
*
|
|
22
12
|
* @param elementTemplates The bpmn-js element templates service.
|
|
23
|
-
* @param
|
|
13
|
+
* @param injector The modeler's dependency injector, used only for the C7 fallback.
|
|
24
14
|
*/
|
|
25
|
-
constructor(elementTemplates: any,
|
|
15
|
+
constructor(elementTemplates: any, injector: any);
|
|
26
16
|
}
|
|
@@ -12,19 +12,17 @@ class ExtendElementTemplates {
|
|
|
12
12
|
* the {@link TemplateElementFactory}.
|
|
13
13
|
*
|
|
14
14
|
* @param elementTemplates The bpmn-js element templates service.
|
|
15
|
-
* @param
|
|
15
|
+
* @param injector The modeler's dependency injector, used only for the C7 fallback.
|
|
16
16
|
*/
|
|
17
|
-
constructor(elementTemplates,
|
|
17
|
+
constructor(elementTemplates, injector) {
|
|
18
18
|
if (typeof elementTemplates.createElement === "function") {
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return templateElementFactory.create(template);
|
|
26
|
-
};
|
|
21
|
+
const templateElementFactory = injector.get("c7TemplateElementFactory");
|
|
22
|
+
// Instantiation registers the shape-create listener.
|
|
23
|
+
injector.get("c7ApplyTemplateOnShapeCreateBehavior");
|
|
24
|
+
elementTemplates.createElement = (template, options) => templateElementFactory.create(template, options);
|
|
27
25
|
}
|
|
28
26
|
}
|
|
29
27
|
exports.ExtendElementTemplates = ExtendElementTemplates;
|
|
30
|
-
ExtendElementTemplates.$inject = ["elementTemplates", "
|
|
28
|
+
ExtendElementTemplates.$inject = ["elementTemplates", "injector"];
|
|
@@ -1,51 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The subset of the C7 element-template schema needed by the adapter.
|
|
3
|
+
* Additional template fields are deliberately retained for the upstream
|
|
4
|
+
* change-template command.
|
|
3
5
|
*/
|
|
4
|
-
interface C7ElementTemplate {
|
|
6
|
+
export interface C7ElementTemplate {
|
|
5
7
|
id: string;
|
|
6
8
|
version?: number;
|
|
7
|
-
appliesTo
|
|
9
|
+
appliesTo?: string[];
|
|
8
10
|
elementType?: {
|
|
9
11
|
value?: string;
|
|
10
12
|
eventDefinition?: string;
|
|
11
13
|
};
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
}
|
|
16
|
+
export interface CreateElementOptions {
|
|
17
|
+
presetId?: string;
|
|
12
18
|
}
|
|
13
19
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
20
|
+
* Creates detached C7 shapes and remembers the template that must be applied
|
|
21
|
+
* once the shape is attached to a diagram.
|
|
16
22
|
*/
|
|
17
23
|
export declare class TemplateElementFactory {
|
|
18
24
|
static $inject: string[];
|
|
19
|
-
private readonly commandStack;
|
|
20
25
|
private readonly elementFactory;
|
|
26
|
+
private readonly pendingTemplates;
|
|
27
|
+
constructor(elementFactory: any);
|
|
21
28
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
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.
|
|
29
|
+
* Create a detached preview. No editing command is executed here because
|
|
30
|
+
* C7 bindings may need the shape's parent and the diagram definitions.
|
|
48
31
|
*/
|
|
49
|
-
|
|
32
|
+
create(template: C7ElementTemplate, options?: CreateElementOptions): any;
|
|
33
|
+
getPendingTemplate(element: object): C7ElementTemplate | undefined;
|
|
34
|
+
consumePendingTemplate(element: object): void;
|
|
50
35
|
}
|
|
51
|
-
export {};
|
|
@@ -1,73 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
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
4
|
const ModelUtil_1 = require("bpmn-js/lib/util/ModelUtil");
|
|
13
5
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
6
|
+
* Creates detached C7 shapes and remembers the template that must be applied
|
|
7
|
+
* once the shape is attached to a diagram.
|
|
16
8
|
*/
|
|
17
9
|
class TemplateElementFactory {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
* @param elementFactory The bpmn-js element factory service.
|
|
21
|
-
*/
|
|
22
|
-
constructor(commandStack, elementFactory) {
|
|
23
|
-
this.commandStack = commandStack;
|
|
10
|
+
constructor(elementFactory) {
|
|
11
|
+
this.pendingTemplates = new WeakMap();
|
|
24
12
|
this.elementFactory = elementFactory;
|
|
25
13
|
}
|
|
26
14
|
/**
|
|
27
|
-
*
|
|
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.
|
|
15
|
+
* Create a detached preview. No editing command is executed here because
|
|
16
|
+
* C7 bindings may need the shape's parent and the diagram definitions.
|
|
50
17
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
18
|
+
create(template, options = {}) {
|
|
19
|
+
if (!template) {
|
|
20
|
+
throw new Error("template is missing");
|
|
21
|
+
}
|
|
22
|
+
if (options?.presetId !== undefined) {
|
|
23
|
+
throw new Error("C7 element template presets are not supported");
|
|
24
|
+
}
|
|
25
|
+
const selectedTemplate = cloneTemplate(template);
|
|
26
|
+
const type = selectedTemplate.elementType?.value ?? selectedTemplate.appliesTo?.[0];
|
|
27
|
+
if (!type) {
|
|
28
|
+
throw new Error("template element type is missing");
|
|
29
|
+
}
|
|
54
30
|
const attrs = { type };
|
|
55
|
-
if (elementType?.eventDefinition) {
|
|
56
|
-
attrs.eventDefinitionType = elementType.eventDefinition;
|
|
31
|
+
if (selectedTemplate.elementType?.eventDefinition) {
|
|
32
|
+
attrs.eventDefinitionType = selectedTemplate.elementType.eventDefinition;
|
|
57
33
|
}
|
|
58
|
-
|
|
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) {
|
|
34
|
+
const element = this.elementFactory.createShape(attrs);
|
|
67
35
|
const businessObject = (0, ModelUtil_1.getBusinessObject)(element);
|
|
68
|
-
businessObject.set("camunda:modelerTemplate",
|
|
69
|
-
businessObject.set("camunda:modelerTemplateVersion",
|
|
36
|
+
businessObject.set("camunda:modelerTemplate", selectedTemplate.id);
|
|
37
|
+
businessObject.set("camunda:modelerTemplateVersion", selectedTemplate.version);
|
|
38
|
+
this.pendingTemplates.set(element, selectedTemplate);
|
|
39
|
+
return element;
|
|
40
|
+
}
|
|
41
|
+
getPendingTemplate(element) {
|
|
42
|
+
return this.pendingTemplates.get(element);
|
|
43
|
+
}
|
|
44
|
+
consumePendingTemplate(element) {
|
|
45
|
+
this.pendingTemplates.delete(element);
|
|
70
46
|
}
|
|
71
47
|
}
|
|
72
48
|
exports.TemplateElementFactory = TemplateElementFactory;
|
|
73
|
-
TemplateElementFactory.$inject = ["
|
|
49
|
+
TemplateElementFactory.$inject = ["elementFactory"];
|
|
50
|
+
function cloneTemplate(value) {
|
|
51
|
+
if (Array.isArray(value)) {
|
|
52
|
+
return value.map((entry) => cloneTemplate(entry));
|
|
53
|
+
}
|
|
54
|
+
if (value && typeof value === "object") {
|
|
55
|
+
return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, cloneTemplate(entry)]));
|
|
56
|
+
}
|
|
57
|
+
return value;
|
|
58
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,15 +5,17 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Register as an `additionalModule` when creating the C7 bpmn-js modeler:
|
|
7
7
|
* ```ts
|
|
8
|
-
* import { CreateAppendC7ElementTemplatesModule } from "@miragon/create-append-c7
|
|
8
|
+
* import { CreateAppendC7ElementTemplatesModule } from "@miragon/create-append-c7";
|
|
9
9
|
*
|
|
10
10
|
* new BpmnModeler({ additionalModules: [CreateAppendC7ElementTemplatesModule] });
|
|
11
11
|
* ```
|
|
12
12
|
*/
|
|
13
|
+
import { ApplyTemplateOnShapeCreateBehavior } from "./ApplyTemplateOnShapeCreateBehavior";
|
|
13
14
|
import { ExtendElementTemplates } from "./ExtendElementTemplates";
|
|
14
15
|
import { TemplateElementFactory } from "./TemplateElementFactory";
|
|
15
16
|
export declare const CreateAppendC7ElementTemplatesModule: {
|
|
16
17
|
__init__: string[];
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
c7ExtendedElementTemplates: (string | typeof ExtendElementTemplates)[];
|
|
19
|
+
c7TemplateElementFactory: (string | typeof TemplateElementFactory)[];
|
|
20
|
+
c7ApplyTemplateOnShapeCreateBehavior: (string | typeof ApplyTemplateOnShapeCreateBehavior)[];
|
|
19
21
|
};
|
package/dist/index.js
CHANGED
|
@@ -8,15 +8,17 @@ exports.CreateAppendC7ElementTemplatesModule = void 0;
|
|
|
8
8
|
*
|
|
9
9
|
* Register as an `additionalModule` when creating the C7 bpmn-js modeler:
|
|
10
10
|
* ```ts
|
|
11
|
-
* import { CreateAppendC7ElementTemplatesModule } from "@miragon/create-append-c7
|
|
11
|
+
* import { CreateAppendC7ElementTemplatesModule } from "@miragon/create-append-c7";
|
|
12
12
|
*
|
|
13
13
|
* new BpmnModeler({ additionalModules: [CreateAppendC7ElementTemplatesModule] });
|
|
14
14
|
* ```
|
|
15
15
|
*/
|
|
16
|
+
const ApplyTemplateOnShapeCreateBehavior_1 = require("./ApplyTemplateOnShapeCreateBehavior");
|
|
16
17
|
const ExtendElementTemplates_1 = require("./ExtendElementTemplates");
|
|
17
18
|
const TemplateElementFactory_1 = require("./TemplateElementFactory");
|
|
18
19
|
exports.CreateAppendC7ElementTemplatesModule = {
|
|
19
|
-
__init__: ["
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
__init__: ["c7ExtendedElementTemplates"],
|
|
21
|
+
c7ExtendedElementTemplates: ["type", ExtendElementTemplates_1.ExtendElementTemplates],
|
|
22
|
+
c7TemplateElementFactory: ["type", TemplateElementFactory_1.TemplateElementFactory],
|
|
23
|
+
c7ApplyTemplateOnShapeCreateBehavior: ["type", ApplyTemplateOnShapeCreateBehavior_1.ApplyTemplateOnShapeCreateBehavior],
|
|
22
24
|
};
|
package/package.json
CHANGED
|
@@ -1,39 +1,59 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
2
|
+
"name": "@miragon/create-append-c7",
|
|
3
|
+
"version": "1.0.1",
|
|
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
|
+
"test": "vitest run --browser.enabled",
|
|
14
|
+
"test:browser": "vitest run --browser.enabled",
|
|
15
|
+
"check": "yarn test && yarn pack --dry-run",
|
|
16
|
+
"prepack": "yarn build",
|
|
17
|
+
"prepublish": "yarn test"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"bpmn-js",
|
|
21
|
+
"bpmn-io",
|
|
22
|
+
"bpmn-js-element-templates",
|
|
23
|
+
"bpmn-js-create-append-anything",
|
|
24
|
+
"camunda-7"
|
|
25
|
+
],
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/Miragon/create-append-c7"
|
|
29
|
+
},
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/Miragon/create-append-c7/issues"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"bpmn-js": "^18.0.0",
|
|
38
|
+
"bpmn-js-create-append-anything": "^1.2.0 || ^2.0.0",
|
|
39
|
+
"bpmn-js-element-templates": "^2.27.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@bpmn-io/properties-panel": "3.54.1",
|
|
43
|
+
"@vitest/browser-playwright": "5.0.0",
|
|
44
|
+
"bpmn-js": "18.28.0",
|
|
45
|
+
"bpmn-js-create-append-anything": "2.1.0",
|
|
46
|
+
"bpmn-js-element-templates": "2.35.0",
|
|
47
|
+
"bpmn-js-properties-panel": "5.65.0",
|
|
48
|
+
"camunda-bpmn-js-behaviors": "1.18.0",
|
|
49
|
+
"camunda-bpmn-moddle": "8.0.1",
|
|
50
|
+
"diagram-js": "15.26.0",
|
|
51
|
+
"moddle": "8.2.1",
|
|
52
|
+
"playwright": "1.63.0",
|
|
53
|
+
"typescript": "7.0.2",
|
|
54
|
+
"vite": "8.3.0",
|
|
55
|
+
"vitest": "5.0.0",
|
|
56
|
+
"zeebe-bpmn-moddle": "2.0.0"
|
|
57
|
+
},
|
|
58
|
+
"packageManager": "yarn@4.18.0"
|
|
59
|
+
}
|