@bpmn-io/element-template-changelog 0.0.0-stage → 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 ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License
2
+
3
+ Copyright (C) 2026-present camunda services GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9
+ of the Software, and to permit persons to whom the Software is furnished to do
10
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,73 @@
1
- # Temporary Holding Version
1
+ # `@bpmn-io/element-template-changelog`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![CI](https://github.com/bpmn-io/element-template-changelog/actions/workflows/CI.yml/badge.svg)](https://github.com/bpmn-io/element-template-changelog/actions/workflows/CI.yml)
4
+
5
+ A simple _review changes_ component for [`bpmn-js-element-templates`](https://github.com/bpmn-io/bpmn-js-element-templates).
6
+
7
+ ![screenshot](./resources/screenshot.png)
8
+
9
+
10
+ ## Usage
11
+
12
+ ```javascript
13
+ import BpmnModeler from 'bpmn-js/lib/Modeler';
14
+
15
+ import '@bpmn-io/element-template-changelog/assets/element-template-changelog.css';
16
+
17
+ import ElementTemplateChangelogModule from '@bpmn-io/element-template-changelog';
18
+
19
+ const modeler = new BpmnModeler({
20
+ additionalModules: [
21
+ ...
22
+ ElementTemplateChangelogModule
23
+ ],
24
+ ...
25
+ });
26
+
27
+ // review via the properties panel, _OR_
28
+ // open the changelog programmatically
29
+ const elementTemplates = modeler.get('elementTemplates');
30
+
31
+ const update = elementTemplates.getUpdate(element);
32
+
33
+ const { changes } = elementTemplates.getUpdateDetails(element, update.template);
34
+
35
+ await modeler.get('elementTemplateChangelog').open({
36
+ oldTemplate: elementTemplates.get(element),
37
+ newTemplate: update.template,
38
+ changes
39
+ });
40
+
41
+ // apply the new template, once confirmed
42
+ elementTemplates.applyTemplate(element, update.template);
43
+ ```
44
+
45
+
46
+ ## Build and Run
47
+
48
+ Prepare the project by installing all dependencies:
49
+
50
+ ```sh
51
+ npm install
52
+ ```
53
+
54
+ Then, depending on your use-case you may run any of the following commands:
55
+
56
+ ```sh
57
+ # lint and run all tests
58
+ npm run all
59
+
60
+ # spin up the playground
61
+ npm start
62
+
63
+ # run the full development setup
64
+ npm run dev
65
+ ```
66
+
67
+ > [!NOTE]
68
+ > We do not generate any build artifacts. Required parts of the library should be bundled by consuming libraries as needed instead.
69
+
70
+
71
+ ## License
72
+
73
+ MIT
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Semantic tokens, copied from `@bpmn-io/theme` to style the changelog
3
+ * according to this theme.
4
+ *
5
+ * Names and values of the tokens should stay intact with the `@bpmn-io/theme`
6
+ * source of truth, to ensure matching styles and allow overrides with an
7
+ * alternative theme.
8
+ */
9
+ .bio-theme-parent {
10
+ --bio-surface-overlay: hsl(0, 0%, 100%);
11
+ --bio-text: hsl(225, 10%, 15%);
12
+ --bio-border-subtle: hsl(225, 10%, 85%);
13
+ --bio-info: hsl(205, 100%, 40%);
14
+ --bio-shadow: hsla(0, 0%, 0%, 30%);
15
+ --bio-radius-lg: 4px;
16
+ }
17
+
18
+ .element-template-changelog {
19
+ --changelog-backdrop-color: hsla(0, 0%, 16%, 20%);
20
+ --changelog-background-color: var(--bio-surface-overlay);
21
+ --changelog-color: var(--bio-text);
22
+ --changelog-border-color: var(--bio-border-subtle);
23
+ --changelog-link-color: var(--bio-info);
24
+ --changelog-shadow-color: var(--bio-shadow);
25
+ --changelog-border-radius: var(--bio-radius-lg);
26
+ --changelog-spacing: 16px;
27
+
28
+ flex-direction: column;
29
+ width: min(640px, calc(100vw - 40px));
30
+ max-height: 80vh;
31
+ padding: 0;
32
+ border: none;
33
+ background: var(--changelog-background-color);
34
+ color: var(--changelog-color);
35
+ border-radius: var(--changelog-border-radius);
36
+ box-shadow: 0 1px 4px var(--changelog-shadow-color);
37
+ font-family: Helvetica, Arial, sans-serif;
38
+ font-size: 14px;
39
+ line-height: 1.3;
40
+ }
41
+
42
+ .element-template-changelog[open] {
43
+ display: flex;
44
+ }
45
+
46
+ .element-template-changelog::backdrop {
47
+ background: var(--changelog-backdrop-color);
48
+ }
49
+
50
+ .element-template-changelog > * {
51
+ margin: 0;
52
+ padding: var(--changelog-spacing);
53
+ }
54
+
55
+ .element-template-changelog .changes {
56
+ display: flex;
57
+ flex-direction: column;
58
+ gap: var(--changelog-spacing);
59
+ min-height: 0;
60
+ overflow: auto;
61
+ border-block: solid 1px var(--changelog-border-color);
62
+ }
63
+
64
+ .element-template-changelog h4 {
65
+ margin: 0;
66
+ }
67
+
68
+ .element-template-changelog pre {
69
+ margin: 4px 0 0;
70
+ white-space: pre-wrap;
71
+ overflow-wrap: anywhere;
72
+ }
73
+
74
+ .element-template-changelog a {
75
+ color: var(--changelog-link-color);
76
+ }
77
+
78
+ .element-template-changelog .actions {
79
+ display: flex;
80
+ gap: 8px;
81
+ justify-content: flex-end;
82
+ }
@@ -0,0 +1,189 @@
1
+ import {
2
+ html,
3
+ render,
4
+ useLayoutEffect,
5
+ useRef
6
+ } from 'diagram-js/lib/ui/index.js';
7
+
8
+ /**
9
+ * @typedef { {
10
+ * type: 'update' | 'migration',
11
+ * template: Object,
12
+ * version?: number,
13
+ * text: string
14
+ * } } Change
15
+ *
16
+ * @typedef { {
17
+ * oldTemplate: Object,
18
+ * newTemplate: Object,
19
+ * changes: Change[]
20
+ * } } ChangelogContext
21
+ */
22
+
23
+ /**
24
+ * Shows the changes of an element template update or migration, as requested
25
+ * via `elementTemplates.reviewChanges`, and applies the new template once
26
+ * confirmed.
27
+ *
28
+ * @param {EventBus} eventBus
29
+ * @param {ElementTemplates} elementTemplates
30
+ * @param {Function} translate
31
+ */
32
+ export default function ElementTemplateChangelog(eventBus, elementTemplates, translate) {
33
+ this._translate = translate;
34
+ this._cancels = new Set();
35
+
36
+ eventBus.on('diagram.destroy', () => {
37
+ this._cancels.forEach(cancel => cancel());
38
+ });
39
+
40
+ eventBus.on('elementTemplates.reviewChanges', event => {
41
+ const {
42
+ element,
43
+ newTemplate
44
+ } = event;
45
+
46
+ this.open(event).then(() => {
47
+ elementTemplates.applyTemplate(element, newTemplate);
48
+ }).catch(error => {
49
+ if (error !== 'user-canceled') {
50
+ console.error('elementTemplates.reviewChanges :: error', error);
51
+ }
52
+ });
53
+ });
54
+ }
55
+
56
+ ElementTemplateChangelog.$inject = [
57
+ 'eventBus',
58
+ 'elementTemplates',
59
+ 'translate'
60
+ ];
61
+
62
+ /**
63
+ * Open the changelog for the given change of templates.
64
+ *
65
+ * @param {ChangelogContext} context
66
+ *
67
+ * @return {Promise<void>} resolved once confirmed, rejected with `user-canceled` otherwise
68
+ */
69
+ ElementTemplateChangelog.prototype.open = function(context) {
70
+ const translate = this._translate;
71
+
72
+ return new Promise((resolve, reject) => {
73
+ const container = document.createElement('div');
74
+
75
+ const close = () => {
76
+ this._cancels.delete(onCancel);
77
+
78
+ render(null, container);
79
+ container.remove();
80
+ };
81
+
82
+ const onConfirm = () => {
83
+ close();
84
+ resolve();
85
+ };
86
+
87
+ const onCancel = () => {
88
+ close();
89
+ reject('user-canceled');
90
+ };
91
+
92
+ this._cancels.add(onCancel);
93
+
94
+ document.body.appendChild(container);
95
+
96
+ render(html`
97
+ <${ Changelog }
98
+ ...${ context }
99
+ translate=${ translate }
100
+ onConfirm=${ onConfirm }
101
+ onCancel=${ onCancel } />
102
+ `, container);
103
+ });
104
+ };
105
+
106
+ function Changelog({ oldTemplate, newTemplate, changes, translate, onConfirm, onCancel }) {
107
+ const isUpdate = oldTemplate.id === newTemplate.id;
108
+
109
+ const title = isUpdate
110
+ ? translate('Update {name} to version {version}', { name: newTemplate.name, version: newTemplate.version })
111
+ : translate('Migrate from {from} to {to}', { from: oldTemplate.name, to: newTemplate.name });
112
+
113
+ const dialogRef = useRef();
114
+
115
+ // a modal dialog traps focus, and restores it once closed
116
+ useLayoutEffect(() => {
117
+ const dialog = dialogRef.current;
118
+
119
+ dialog.showModal();
120
+
121
+ return () => dialog.close();
122
+ }, []);
123
+
124
+ const onBackdropClick = event => event.target === event.currentTarget && onCancel();
125
+
126
+ return html`
127
+ <dialog
128
+ ref=${ dialogRef }
129
+ class="element-template-changelog bio-theme-parent"
130
+ aria-labelledby="element-template-changelog-title"
131
+ onCancel=${ onCancel }
132
+ onClick=${ onBackdropClick }>
133
+ <h3 id="element-template-changelog-title">${ title }</h3>
134
+ <div class="changes">
135
+ ${ changes.map(change => html`
136
+ <section class="change">
137
+ <h4>${ getChangeTitle(change, oldTemplate, translate) }</h4>
138
+ <pre>${ renderText(change.text) }</pre>
139
+ </section>
140
+ `) }
141
+ </div>
142
+ <div class="actions">
143
+ <button onClick=${ onCancel }>${ translate('Cancel') }</button>
144
+ <button autofocus onClick=${ onConfirm }>
145
+ ${ isUpdate ? translate('Update') : translate('Migrate') }
146
+ </button>
147
+ </div>
148
+ </dialog>
149
+ `;
150
+ }
151
+
152
+ /**
153
+ * Title a change by the step that contributes it.
154
+ */
155
+ function getChangeTitle(change, oldTemplate, translate) {
156
+ const {
157
+ type,
158
+ template,
159
+ version
160
+ } = change;
161
+
162
+ if (type === 'migration') {
163
+ return translate('{from} → {to}', { from: oldTemplate.name, to: template.name });
164
+ }
165
+
166
+ return translate('{name} v{version}', { name: template.name, version });
167
+ }
168
+
169
+ /**
170
+ * Render untrusted Markdown as raw text, with clickable http(s) links.
171
+ */
172
+ function renderText(text) {
173
+ const parts = [];
174
+
175
+ let index = 0;
176
+
177
+ for (const match of text.matchAll(/https?:\/\/[^\s()<>"']+/g)) {
178
+ parts.push(
179
+ text.slice(index, match.index),
180
+ html`<a href=${ match[0] } target="_blank" rel="noopener noreferrer">${ match[0] }</a>`
181
+ );
182
+
183
+ index = match.index + match[0].length;
184
+ }
185
+
186
+ parts.push(text.slice(index));
187
+
188
+ return parts;
189
+ }
package/lib/index.js ADDED
@@ -0,0 +1,8 @@
1
+ import ElementTemplateChangelog from './ElementTemplateChangelog.js';
2
+
3
+ export default {
4
+ __init__: [
5
+ 'elementTemplateChangelog'
6
+ ],
7
+ elementTemplateChangelog: [ 'type', ElementTemplateChangelog ]
8
+ };
package/package.json CHANGED
@@ -1,6 +1,63 @@
1
1
  {
2
2
  "name": "@bpmn-io/element-template-changelog",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Review the changes of element template updates and migrations",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": "./lib/index.js",
8
+ "./assets/element-template-changelog.css": "./assets/element-template-changelog.css",
9
+ "./package.json": "./package.json"
10
+ },
11
+ "scripts": {
12
+ "all": "run-s lint lint:theme test",
13
+ "lint": "eslint .",
14
+ "test": "karma start karma.conf.cjs",
15
+ "dev": "npm test -- --no-single-run --auto-watch",
16
+ "start": "cross-env SINGLE_START=true npm run dev",
17
+ "lint:theme": "bpmn-io-theme-validate assets/element-template-changelog.css"
18
+ },
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "author": {
23
+ "name": "Nico Rehwaldt",
24
+ "url": "https://github.com/nikku"
25
+ },
26
+ "repository": "https://github.com/bpmn-io/element-template-changelog.git",
27
+ "license": "MIT",
28
+ "peerDependencies": {
29
+ "diagram-js": ">= 15.15.0"
30
+ },
31
+ "sideEffects": [
32
+ "*.css"
33
+ ],
34
+ "files": [
35
+ "lib",
36
+ "assets"
37
+ ],
38
+ "devDependencies": {
39
+ "@bpmn-io/properties-panel": "^3.60.2",
40
+ "@bpmn-io/theme": "^0.3.0",
41
+ "bpmn-js": "^18.33.1",
42
+ "bpmn-js-element-templates": "^2.40.3",
43
+ "bpmn-js-properties-panel": "^5.65.4",
44
+ "camunda-bpmn-js-behaviors": "^1.18.0",
45
+ "chai": "^6.3.0",
46
+ "cross-env": "^10.1.0",
47
+ "diagram-js": "^15.30.1",
48
+ "eslint": "^9.39.5",
49
+ "eslint-plugin-bpmn-io": "^2.4.0",
50
+ "karma": "^6.4.4",
51
+ "karma-chrome-launcher-2": "^3.3.0",
52
+ "karma-debug-launcher": "^0.0.5",
53
+ "karma-env-preprocessor": "^0.1.1",
54
+ "karma-firefox-launcher": "^2.1.3",
55
+ "karma-mocha": "^2.0.1",
56
+ "karma-tldr-reporter": "^1.0.0",
57
+ "karma-webpack": "^5.0.1",
58
+ "mocha": "^12.0.3",
59
+ "npm-run-all2": "^9.0.4",
60
+ "webpack": "^5.112.2",
61
+ "zeebe-bpmn-moddle": "^2.0.0"
62
+ }
63
+ }