@bpmn-io/element-template-changelog 0.0.0-stage → 0.2.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,87 @@
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
+ ### Configuration
47
+
48
+ The changelog renders into `document.body`. Configure a `container` (element or selector) to render it elsewhere, e.g. within your application's theme scope:
49
+
50
+ ```javascript
51
+ const modeler = new BpmnModeler({
52
+ elementTemplateChangelog: {
53
+ container: '#properties-panel'
54
+ },
55
+ ...
56
+ });
57
+ ```
58
+
59
+
60
+ ## Build and Run
61
+
62
+ Prepare the project by installing all dependencies:
63
+
64
+ ```sh
65
+ npm install
66
+ ```
67
+
68
+ Then, depending on your use-case you may run any of the following commands:
69
+
70
+ ```sh
71
+ # lint and run all tests
72
+ npm run all
73
+
74
+ # spin up the playground
75
+ npm start
76
+
77
+ # run the full development setup
78
+ npm run dev
79
+ ```
80
+
81
+ > [!NOTE]
82
+ > We do not generate any build artifacts. Required parts of the library should be bundled by consuming libraries as needed instead.
83
+
84
+
85
+ ## License
86
+
87
+ MIT
@@ -0,0 +1,148 @@
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-surface-subtle: hsl(225, 10%, 97%);
12
+ --bio-text: hsl(225, 10%, 15%);
13
+ --bio-text-on-primary: hsl(0, 0%, 100%);
14
+ --bio-border: hsl(225, 10%, 75%);
15
+ --bio-border-subtle: hsl(225, 10%, 85%);
16
+ --bio-primary: hsl(205, 100%, 40%);
17
+ --bio-primary-hover: hsl(205, 100%, 35%);
18
+ --bio-info: hsl(205, 100%, 40%);
19
+ --bio-focus-ring: hsla(205, 100%, 40%, 0.35);
20
+ --bio-shadow: hsla(0, 0%, 0%, 30%);
21
+ --bio-radius-md: 3px;
22
+ --bio-radius-lg: 4px;
23
+ }
24
+
25
+ .element-template-changelog {
26
+ --changelog-backdrop-color: hsla(0, 0%, 16%, 20%);
27
+ --changelog-background-color: var(--bio-surface-overlay);
28
+ --changelog-color: var(--bio-text);
29
+ --changelog-border-color: var(--bio-border-subtle);
30
+ --changelog-link-color: var(--bio-info);
31
+ --changelog-shadow-color: var(--bio-shadow);
32
+ --changelog-border-radius: var(--bio-radius-lg);
33
+ --changelog-spacing: 16px;
34
+ --changelog-font-family: Helvetica, Arial, sans-serif;
35
+ --changelog-focus-ring-color: var(--bio-focus-ring);
36
+ --changelog-action-background-color: var(--bio-surface-overlay);
37
+ --changelog-action-hover-background-color: var(--bio-surface-subtle);
38
+ --changelog-action-border-color: var(--bio-border);
39
+ --changelog-action-border-radius: var(--bio-radius-md);
40
+ --changelog-action-color: var(--bio-text);
41
+ --changelog-primary-action-background-color: var(--bio-primary);
42
+ --changelog-primary-action-hover-background-color: var(--bio-primary-hover);
43
+ --changelog-primary-action-color: var(--bio-text-on-primary);
44
+
45
+ flex-direction: column;
46
+ width: min(640px, calc(100vw - 40px));
47
+ max-height: 80vh;
48
+ margin: auto;
49
+ padding: 0;
50
+ border: none;
51
+ background: var(--changelog-background-color);
52
+ color: var(--changelog-color);
53
+ border-radius: var(--changelog-border-radius);
54
+ box-shadow: 0 1px 4px var(--changelog-shadow-color);
55
+ font-family: var(--changelog-font-family);
56
+ font-size: 14px;
57
+ line-height: 1.3;
58
+ }
59
+
60
+ .element-template-changelog[open] {
61
+ display: flex;
62
+ }
63
+
64
+ .element-template-changelog::backdrop {
65
+ background: var(--changelog-backdrop-color);
66
+ }
67
+
68
+ .element-template-changelog-title {
69
+ margin: 0;
70
+ padding: var(--changelog-spacing);
71
+ font-size: 16px;
72
+ font-weight: bold;
73
+ }
74
+
75
+ .element-template-changelog-changes {
76
+ display: flex;
77
+ flex-direction: column;
78
+ gap: var(--changelog-spacing);
79
+ min-height: 0;
80
+ margin: 0;
81
+ padding: var(--changelog-spacing);
82
+ overflow: auto;
83
+ border-block: solid 1px var(--changelog-border-color);
84
+ }
85
+
86
+ .element-template-changelog-change-title {
87
+ margin: 0;
88
+ font-size: 14px;
89
+ font-weight: bold;
90
+ }
91
+
92
+ .element-template-changelog-change-text {
93
+ margin: 4px 0 0;
94
+ font-family: monospace;
95
+ font-size: 13px;
96
+ white-space: pre-wrap;
97
+ overflow-wrap: anywhere;
98
+ }
99
+
100
+ .element-template-changelog-link {
101
+ color: var(--changelog-link-color);
102
+ text-decoration: underline;
103
+ }
104
+
105
+ .element-template-changelog-actions {
106
+ display: flex;
107
+ gap: 8px;
108
+ justify-content: flex-end;
109
+ margin: 0;
110
+ padding: var(--changelog-spacing);
111
+ }
112
+
113
+ .element-template-changelog-action {
114
+ padding: 6px 12px;
115
+ border: solid 1px var(--changelog-action-border-color);
116
+ border-radius: var(--changelog-action-border-radius);
117
+ background: var(--changelog-action-background-color);
118
+ color: var(--changelog-action-color);
119
+ font: inherit;
120
+ cursor: pointer;
121
+ }
122
+
123
+ .element-template-changelog-action:hover {
124
+ background: var(--changelog-action-hover-background-color);
125
+ }
126
+
127
+ .element-template-changelog-action-primary {
128
+ border-color: var(--changelog-primary-action-background-color);
129
+ background: var(--changelog-primary-action-background-color);
130
+ color: var(--changelog-primary-action-color);
131
+ }
132
+
133
+ .element-template-changelog-action-primary:hover {
134
+ border-color: var(--changelog-primary-action-hover-background-color);
135
+ background: var(--changelog-primary-action-hover-background-color);
136
+ }
137
+
138
+ .element-template-changelog-action:focus-visible {
139
+ outline: none;
140
+ box-shadow: 0 0 0 2px var(--changelog-focus-ring-color);
141
+ }
142
+
143
+ /* keep focus visible where box-shadow is dropped (e.g. Windows High Contrast) */
144
+ @media (forced-colors: active) {
145
+ .element-template-changelog-action:focus-visible {
146
+ outline: 2px solid Highlight;
147
+ }
148
+ }
@@ -0,0 +1,206 @@
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
+ * container?: HTMLElement | string
18
+ * } } ElementTemplateChangelogConfig
19
+ *
20
+ * @typedef { {
21
+ * oldTemplate: Object,
22
+ * newTemplate: Object,
23
+ * changes: Change[]
24
+ * } } ChangelogContext
25
+ */
26
+
27
+ /**
28
+ * Shows the changes of an element template update or migration, as requested
29
+ * via `elementTemplates.reviewChanges`, and applies the new template once
30
+ * confirmed.
31
+ *
32
+ * Renders into `config.container` (element or selector), or `document.body`.
33
+ *
34
+ * @param {ElementTemplateChangelogConfig} config
35
+ * @param {EventBus} eventBus
36
+ * @param {ElementTemplates} elementTemplates
37
+ * @param {Function} translate
38
+ */
39
+ export default function ElementTemplateChangelog(config, eventBus, elementTemplates, translate) {
40
+ this._config = config || {};
41
+ this._translate = translate;
42
+ this._cancels = new Set();
43
+
44
+ eventBus.on('diagram.destroy', () => {
45
+ this._cancels.forEach(cancel => cancel());
46
+ });
47
+
48
+ eventBus.on('elementTemplates.reviewChanges', event => {
49
+ const {
50
+ element,
51
+ newTemplate
52
+ } = event;
53
+
54
+ this.open(event).then(() => {
55
+ elementTemplates.applyTemplate(element, newTemplate);
56
+ }).catch(error => {
57
+ if (error !== 'user-canceled') {
58
+ console.error('elementTemplates.reviewChanges :: error', error);
59
+ }
60
+ });
61
+ });
62
+ }
63
+
64
+ ElementTemplateChangelog.$inject = [
65
+ 'config.elementTemplateChangelog',
66
+ 'eventBus',
67
+ 'elementTemplates',
68
+ 'translate'
69
+ ];
70
+
71
+ /**
72
+ * Open the changelog for the given change of templates.
73
+ *
74
+ * @param {ChangelogContext} context
75
+ *
76
+ * @return {Promise<void>} resolved once confirmed, rejected with `user-canceled` otherwise
77
+ */
78
+ ElementTemplateChangelog.prototype.open = function(context) {
79
+ const translate = this._translate;
80
+
81
+ return new Promise((resolve, reject) => {
82
+ const container = document.createElement('div');
83
+
84
+ const close = () => {
85
+ this._cancels.delete(onCancel);
86
+
87
+ render(null, container);
88
+ container.remove();
89
+ };
90
+
91
+ const onConfirm = () => {
92
+ close();
93
+ resolve();
94
+ };
95
+
96
+ const onCancel = () => {
97
+ close();
98
+ reject('user-canceled');
99
+ };
100
+
101
+ this._cancels.add(onCancel);
102
+
103
+ getContainer(this._config.container).appendChild(container);
104
+
105
+ render(html`
106
+ <${ Changelog }
107
+ ...${ context }
108
+ translate=${ translate }
109
+ onConfirm=${ onConfirm }
110
+ onCancel=${ onCancel } />
111
+ `, container);
112
+ });
113
+ };
114
+
115
+ function Changelog({ oldTemplate, newTemplate, changes, translate, onConfirm, onCancel }) {
116
+ const isUpdate = oldTemplate.id === newTemplate.id;
117
+
118
+ const title = isUpdate
119
+ ? translate('Update {name} to version {version}', { name: newTemplate.name, version: newTemplate.version })
120
+ : translate('Migrate from {from} to {to}', { from: oldTemplate.name, to: newTemplate.name });
121
+
122
+ const dialogRef = useRef();
123
+
124
+ // a modal dialog traps focus, and restores it once closed
125
+ useLayoutEffect(() => {
126
+ const dialog = dialogRef.current;
127
+
128
+ dialog.showModal();
129
+
130
+ return () => dialog.close();
131
+ }, []);
132
+
133
+ const onBackdropClick = event => event.target === event.currentTarget && onCancel();
134
+
135
+ return html`
136
+ <dialog
137
+ ref=${ dialogRef }
138
+ class="element-template-changelog bio-theme-parent"
139
+ aria-label=${ title }
140
+ onCancel=${ onCancel }
141
+ onClick=${ onBackdropClick }>
142
+ <h3 class="element-template-changelog-title">${ title }</h3>
143
+ <div class="element-template-changelog-changes">
144
+ ${ changes.map(change => html`
145
+ <section class="element-template-changelog-change">
146
+ <h4 class="element-template-changelog-change-title">${ getChangeTitle(change, oldTemplate, translate) }</h4>
147
+ <pre class="element-template-changelog-change-text">${ renderText(change.text) }</pre>
148
+ </section>
149
+ `) }
150
+ </div>
151
+ <div class="element-template-changelog-actions">
152
+ <button class="element-template-changelog-action" onClick=${ onCancel }>${ translate('Cancel') }</button>
153
+ <button class="element-template-changelog-action element-template-changelog-action-primary" autofocus onClick=${ onConfirm }>
154
+ ${ isUpdate ? translate('Update') : translate('Migrate') }
155
+ </button>
156
+ </div>
157
+ </dialog>
158
+ `;
159
+ }
160
+
161
+ function getContainer(container) {
162
+ if (typeof container === 'string') {
163
+ return document.querySelector(container);
164
+ }
165
+
166
+ return container || document.body;
167
+ }
168
+
169
+ /**
170
+ * Title a change by the step that contributes it.
171
+ */
172
+ function getChangeTitle(change, oldTemplate, translate) {
173
+ const {
174
+ type,
175
+ template,
176
+ version
177
+ } = change;
178
+
179
+ if (type === 'migration') {
180
+ return translate('{from} → {to}', { from: oldTemplate.name, to: template.name });
181
+ }
182
+
183
+ return translate('{name} v{version}', { name: template.name, version });
184
+ }
185
+
186
+ /**
187
+ * Render untrusted Markdown as raw text, with clickable http(s) links.
188
+ */
189
+ function renderText(text) {
190
+ const parts = [];
191
+
192
+ let index = 0;
193
+
194
+ for (const match of text.matchAll(/https?:\/\/[^\s()<>"']+/g)) {
195
+ parts.push(
196
+ text.slice(index, match.index),
197
+ html`<a class="element-template-changelog-link" href=${ match[0] } target="_blank" rel="noopener noreferrer">${ match[0] }</a>`
198
+ );
199
+
200
+ index = match.index + match[0].length;
201
+ }
202
+
203
+ parts.push(text.slice(index));
204
+
205
+ return parts;
206
+ }
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.2.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.41.0",
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
+ }