@bpmn-nova/studio 0.3.8-preview → 0.4.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/README.md +2 -2
- package/dist/canvas.js +97 -25
- package/dist/config.js +42 -0
- package/dist/context-menu.js +41 -32
- package/dist/controller.js +45 -19
- package/dist/index.d.ts +59 -2
- package/dist/index.js +1 -0
- package/dist/interactions.js +6 -1
- package/dist/modules/bpmn-model/index.d.ts +2 -1
- package/dist/modules/bpmn-model/index.js +12 -10
- package/dist/modules/core/gateway.js +16 -13
- package/dist/modules/core/index.d.ts +6 -4
- package/dist/modules/core/model.js +12 -7
- package/dist/modules/designer/index.d.ts +5 -1
- package/dist/modules/designer/index.js +36 -15
- package/dist/modules/export-svg/index.d.ts +12 -5
- package/dist/modules/export-svg/preview.js +34 -24
- package/dist/modules/export-svg/render.js +102 -50
- package/dist/modules/i18n/index.d.ts +647 -0
- package/dist/modules/i18n/index.js +247 -0
- package/dist/modules/i18n/locales/en-US.js +823 -0
- package/dist/modules/i18n/locales/zh-CN.js +805 -0
- package/dist/modules/node-presentation/index.d.ts +3 -2
- package/dist/modules/node-presentation/index.js +14 -11
- package/dist/modules/palette/index.d.ts +6 -1
- package/dist/modules/palette/index.js +26 -8
- package/dist/modules/palette/panel.js +44 -6
- package/dist/modules/properties/index.d.ts +2 -1
- package/dist/modules/properties/index.js +2 -2
- package/dist/modules/properties-activiti/index.js +84 -59
- package/dist/modules/properties-bpmn/index.js +151 -128
- package/dist/modules/properties-core/index.d.ts +9 -3
- package/dist/modules/properties-core/index.js +16 -4
- package/dist/modules/properties-flowable/index.js +55 -34
- package/dist/modules/properties-renderer/index.d.ts +5 -1
- package/dist/modules/properties-renderer/index.js +110 -42
- package/dist/modules/renderer-svg/index.d.ts +6 -2
- package/dist/modules/renderer-svg/index.js +113 -38
- package/dist/modules/runtime/index.d.ts +33 -5
- package/dist/modules/runtime/index.js +97 -73
- package/dist/modules/runtime/time.js +89 -4
- package/dist/modules/runtime/visits.js +6 -4
- package/dist/modules/theme/index.d.ts +5 -2
- package/dist/modules/theme/index.js +8 -4
- package/dist/modules/viewer/index.d.ts +28 -7
- package/dist/modules/viewer/index.js +213 -56
- package/dist/modules/viewer/runtime-content.js +26 -20
- package/dist/modules/viewer/runtime-trace.js +43 -25
- package/dist/modules/viewer/timeline.js +103 -36
- package/dist/shell.js +279 -75
- package/dist/sidebars.js +3 -1
- package/dist/styles.css +6 -3
- package/llms-full.txt +296 -49
- package/llms.txt +4 -4
- package/package.json +2 -3
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { cloneModel, createEdge, getScopeGraph, NODE_DEFINITIONS } from '../core/index.js';
|
|
2
|
+
import { createI18n, DEFAULT_I18N, resolveI18n } from '../i18n/index.js';
|
|
2
3
|
import { createDefaultIconRegistry, createIconElement } from '../icons/index.js';
|
|
3
4
|
import { DiagramRenderer } from '../renderer-svg/index.js';
|
|
4
5
|
import { compareRuntimeOrder, createRuntimePresentation, formatRuntimeInstant, normalizeRuntime, parseRuntimeInstant } from '../runtime/index.js';
|
|
@@ -19,8 +20,28 @@ function element(tag, className, text) {
|
|
|
19
20
|
return node;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
const OUTCOME_KEYS = Object.freeze({
|
|
24
|
+
approved: 'viewer.outcomes.approved',
|
|
25
|
+
rejected: 'viewer.outcomes.rejected',
|
|
26
|
+
returned: 'viewer.outcomes.returned',
|
|
27
|
+
submitted: 'viewer.outcomes.submitted',
|
|
28
|
+
pending: 'viewer.outcomes.pending',
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
function outcomeLabel(outcome, i18n = DEFAULT_I18N) {
|
|
32
|
+
const key = OUTCOME_KEYS[outcome];
|
|
33
|
+
return (key ? i18n.t(key) : '') || outcome || '';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function formatViewerTime(viewer, value, surface, field, overrides = null) {
|
|
37
|
+
const i18n = resolveI18n(overrides?.i18n || viewer?.i18n || overrides);
|
|
38
|
+
return formatRuntimeInstant(value, {
|
|
39
|
+
formatRuntimeTime: overrides?.formatRuntimeTime !== undefined ? overrides.formatRuntimeTime : viewer?.formatRuntimeTime,
|
|
40
|
+
runtimeTimeFormat: overrides?.runtimeTimeFormat !== undefined ? overrides.runtimeTimeFormat : viewer?.runtimeTimeFormat,
|
|
41
|
+
surface,
|
|
42
|
+
field,
|
|
43
|
+
locale: i18n.locale,
|
|
44
|
+
});
|
|
24
45
|
}
|
|
25
46
|
|
|
26
47
|
const defaultDetailsIconRegistry = createDefaultIconRegistry();
|
|
@@ -39,7 +60,7 @@ function runtimeDetailsCloseButton({ viewer, label, close }) {
|
|
|
39
60
|
return button;
|
|
40
61
|
}
|
|
41
62
|
|
|
42
|
-
function renderRuntimeAction({ container, viewer, action, resolveAsset, compact = false }) {
|
|
63
|
+
function renderRuntimeAction({ container, viewer, action, resolveAsset, compact = false, i18n = DEFAULT_I18N, timeOverrides = null }) {
|
|
43
64
|
const appearance = viewer?.runtimeAppearance?.resolveAction(action) || { label: action.label, tone: 'neutral' };
|
|
44
65
|
const article = element('article', `mb-runtime-action type-${action.type}${compact ? ' is-compact' : ''}`);
|
|
45
66
|
article.dataset.runtimeActionId = action.id;
|
|
@@ -47,41 +68,58 @@ function renderRuntimeAction({ container, viewer, action, resolveAsset, compact
|
|
|
47
68
|
const header = element('header', 'mb-runtime-action-head');
|
|
48
69
|
const heading = element('div', 'mb-runtime-action-heading');
|
|
49
70
|
heading.append(
|
|
50
|
-
element('strong', '', action.actor?.name || '
|
|
71
|
+
element('strong', '', action.actor?.name || i18n.t('viewer.details.systemActor')),
|
|
51
72
|
element('em', '', appearance.label),
|
|
52
73
|
);
|
|
53
74
|
header.appendChild(heading);
|
|
54
|
-
|
|
75
|
+
const occurred = formatViewerTime(viewer, action.occurredAt, 'details', 'occurred', timeOverrides);
|
|
76
|
+
if (occurred) header.appendChild(element('time', '', occurred));
|
|
55
77
|
article.appendChild(header);
|
|
56
|
-
if (action.targets?.length)
|
|
57
|
-
|
|
78
|
+
if (action.targets?.length) {
|
|
79
|
+
article.appendChild(element('div', 'mb-runtime-action-targets', i18n.t('viewer.details.targets', {
|
|
80
|
+
names: action.targets.map((target) => target.name).join(i18n.t('common.listSeparator')),
|
|
81
|
+
})));
|
|
82
|
+
}
|
|
83
|
+
if (action.targetElementId && !action.targets?.length) {
|
|
84
|
+
article.appendChild(element('div', 'mb-runtime-action-targets', i18n.t('viewer.details.targetElement', { id: action.targetElementId })));
|
|
85
|
+
}
|
|
58
86
|
renderRuntimeApprovalContent({
|
|
59
87
|
container: article,
|
|
60
88
|
action,
|
|
61
89
|
resolveAsset,
|
|
62
90
|
compact,
|
|
63
91
|
onPreview: (asset, sourceAction) => viewer?._openRuntimeAssetPreview(asset, sourceAction),
|
|
92
|
+
i18n,
|
|
64
93
|
});
|
|
65
94
|
container.appendChild(article);
|
|
66
95
|
return article;
|
|
67
96
|
}
|
|
68
97
|
|
|
69
|
-
export function renderDefaultRuntimeDetails({ container, viewer, node, presentation, close, resolveAsset }) {
|
|
98
|
+
export function renderDefaultRuntimeDetails({ container, viewer, node, presentation, close, resolveAsset, i18n = null, locale, messages, formatRuntimeTime, runtimeTimeFormat }) {
|
|
99
|
+
const translator = resolveI18n({ i18n: i18n || viewer?.i18n, locale, messages });
|
|
100
|
+
const timeOverrides = { i18n: translator, formatRuntimeTime, runtimeTimeFormat };
|
|
70
101
|
const popover = element('section', 'mb-runtime-details-popover');
|
|
71
102
|
popover.setAttribute('role', 'dialog');
|
|
72
|
-
popover.setAttribute('aria-label',
|
|
103
|
+
popover.setAttribute('aria-label', translator.t('viewer.details.ariaLabel', { name: node.name || translator.t('viewer.details.fallbackNodeName') }));
|
|
73
104
|
popover.tabIndex = -1;
|
|
74
105
|
const header = element('header', 'mb-runtime-details-head');
|
|
75
106
|
const heading = element('div', 'mb-runtime-details-heading');
|
|
76
|
-
heading.append(
|
|
107
|
+
heading.append(
|
|
108
|
+
element('strong', '', node.name || translator.t('viewer.details.fallbackTitle')),
|
|
109
|
+
element('span', '', presentation.round > 1 ? translator.t('viewer.details.roundLabel', { round: presentation.round }) : translator.t('viewer.details.traceSubtitle')),
|
|
110
|
+
);
|
|
77
111
|
const status = element('em', `status-${presentation.status}`, presentation.statusLabel);
|
|
78
112
|
applyRuntimeTone(status, viewer?.runtimeAppearance?.resolveStatus(presentation.status));
|
|
79
|
-
const closeButton = runtimeDetailsCloseButton({ viewer, label: '
|
|
113
|
+
const closeButton = runtimeDetailsCloseButton({ viewer, label: translator.t('viewer.details.closeLabel'), close });
|
|
80
114
|
header.append(heading, status, closeButton);
|
|
81
115
|
popover.appendChild(header);
|
|
82
116
|
|
|
83
117
|
if (presentation.approvalMode || presentation.total > 1) {
|
|
84
|
-
const mode = presentation.approvalMode === 'all'
|
|
118
|
+
const mode = presentation.approvalMode === 'all'
|
|
119
|
+
? translator.t(presentation.multiInstanceMode === 'sequential' ? 'viewer.details.approvalModeAllSequential' : 'viewer.details.approvalModeAll')
|
|
120
|
+
: presentation.approvalMode === 'any'
|
|
121
|
+
? translator.t('viewer.details.approvalModeAny')
|
|
122
|
+
: translator.t('viewer.details.approvalModeMulti');
|
|
85
123
|
const summary = element('div', 'mb-runtime-details-progress');
|
|
86
124
|
summary.append(element('span', '', mode), element('strong', '', `${presentation.completed}/${presentation.total || presentation.required}`));
|
|
87
125
|
popover.appendChild(summary);
|
|
@@ -100,11 +138,13 @@ export function renderDefaultRuntimeDetails({ container, viewer, node, presentat
|
|
|
100
138
|
}
|
|
101
139
|
const copy = element('div', 'mb-runtime-details-person-copy');
|
|
102
140
|
const title = element('div', 'mb-runtime-details-person-title');
|
|
103
|
-
const recordStatus = element('em', `status-${record.status}`, outcomeLabel(record.outcome) || presentation.statusLabel);
|
|
141
|
+
const recordStatus = element('em', `status-${record.status}`, outcomeLabel(record.outcome, translator) || presentation.statusLabel);
|
|
104
142
|
applyRuntimeTone(recordStatus, viewer?.runtimeAppearance?.resolveStatus(record.status));
|
|
105
|
-
title.append(element('strong', '', record.participant?.name || record.assignee || '
|
|
143
|
+
title.append(element('strong', '', record.participant?.name || record.assignee || translator.t('runtime.summary.pendingAssignee')), recordStatus);
|
|
106
144
|
copy.appendChild(title);
|
|
107
|
-
const
|
|
145
|
+
const startText = formatViewerTime(viewer, record.startTime, 'details', 'start', timeOverrides);
|
|
146
|
+
const endText = formatViewerTime(viewer, record.endTime, 'details', 'end', timeOverrides);
|
|
147
|
+
const time = [startText, endText].filter(Boolean).join(' — ');
|
|
108
148
|
if (time) copy.appendChild(element('time', '', time));
|
|
109
149
|
row.append(avatar, copy);
|
|
110
150
|
body.appendChild(row);
|
|
@@ -115,16 +155,19 @@ export function renderDefaultRuntimeDetails({ container, viewer, node, presentat
|
|
|
115
155
|
visits.forEach((visit) => {
|
|
116
156
|
if (presentation.visits.length > 1) {
|
|
117
157
|
const historical = visit.effective === false || visit.superseded;
|
|
118
|
-
body.appendChild(element('div', 'mb-runtime-details-round',
|
|
158
|
+
body.appendChild(element('div', 'mb-runtime-details-round', translator.t(
|
|
159
|
+
historical ? 'viewer.details.roundHistorical' : 'viewer.details.roundLabel',
|
|
160
|
+
{ round: visit.round },
|
|
161
|
+
)));
|
|
119
162
|
}
|
|
120
163
|
[...visit.records].reverse().forEach(appendRecord);
|
|
121
164
|
[...visit.actions].reverse().forEach((action) => {
|
|
122
|
-
renderRuntimeAction({ container: body, viewer, action, resolveAsset });
|
|
165
|
+
renderRuntimeAction({ container: body, viewer, action, resolveAsset, i18n: translator, timeOverrides });
|
|
123
166
|
renderedActionIds.add(action.id);
|
|
124
167
|
});
|
|
125
168
|
});
|
|
126
169
|
[...presentation.actions].reverse().filter((action) => !renderedActionIds.has(action.id)).forEach((action) => {
|
|
127
|
-
renderRuntimeAction({ container: body, viewer, action, resolveAsset });
|
|
170
|
+
renderRuntimeAction({ container: body, viewer, action, resolveAsset, i18n: translator, timeOverrides });
|
|
128
171
|
renderedActionIds.add(action.id);
|
|
129
172
|
});
|
|
130
173
|
|
|
@@ -132,8 +175,11 @@ export function renderDefaultRuntimeDetails({ container, viewer, node, presentat
|
|
|
132
175
|
abnormal.forEach((transition) => {
|
|
133
176
|
const block = element('article', `mb-runtime-details-transition type-${transition.type}`);
|
|
134
177
|
applyRuntimeTone(block, viewer?.runtimeAppearance?.resolveTransition(transition).tone);
|
|
135
|
-
block.appendChild(element('strong', '',
|
|
136
|
-
|
|
178
|
+
block.appendChild(element('strong', '', translator.t(
|
|
179
|
+
transition.type === 'reject' ? 'viewer.details.rejectedTo' : 'viewer.details.returnedTo',
|
|
180
|
+
{ target: transition.targetName || transition.targetElementId },
|
|
181
|
+
)));
|
|
182
|
+
const meta = [transition.operator, formatViewerTime(viewer, transition.occurredAt || transition.time, 'details', 'occurred', timeOverrides)].filter(Boolean).join(' · ');
|
|
137
183
|
if (meta) block.appendChild(element('span', '', meta));
|
|
138
184
|
if (transition.action && !renderedActionIds.has(transition.action.id)) {
|
|
139
185
|
renderRuntimeApprovalContent({
|
|
@@ -141,6 +187,7 @@ export function renderDefaultRuntimeDetails({ container, viewer, node, presentat
|
|
|
141
187
|
action: transition.action,
|
|
142
188
|
resolveAsset,
|
|
143
189
|
onPreview: (asset, action) => viewer?._openRuntimeAssetPreview(asset, action),
|
|
190
|
+
i18n: translator,
|
|
144
191
|
});
|
|
145
192
|
} else if (!transition.action && transition.comment) block.appendChild(element('p', '', transition.comment));
|
|
146
193
|
body.appendChild(block);
|
|
@@ -161,27 +208,43 @@ export function renderDefaultRuntimeTransitionDetails({
|
|
|
161
208
|
locateSource,
|
|
162
209
|
locateTarget,
|
|
163
210
|
resolveAsset,
|
|
211
|
+
i18n = null,
|
|
212
|
+
locale,
|
|
213
|
+
messages,
|
|
214
|
+
formatRuntimeTime,
|
|
215
|
+
runtimeTimeFormat,
|
|
164
216
|
}) {
|
|
165
|
-
const
|
|
217
|
+
const translator = resolveI18n({ i18n: i18n || viewer?.i18n, locale, messages });
|
|
218
|
+
const timeOverrides = { i18n: translator, formatRuntimeTime, runtimeTimeFormat };
|
|
219
|
+
const isReturn = transition.type === 'return';
|
|
220
|
+
const actionLabel = translator.t(isReturn ? 'runtime.transitions.return' : 'runtime.transitions.reject');
|
|
221
|
+
const sourceLabel = sourceNode?.name || transition.sourceName || translator.t('viewer.transitionDetails.fallbackNodeName');
|
|
166
222
|
const popover = element('section', 'mb-runtime-details-popover mb-runtime-transition-details');
|
|
167
223
|
popover.setAttribute('role', 'dialog');
|
|
168
|
-
popover.setAttribute('aria-label',
|
|
224
|
+
popover.setAttribute('aria-label', translator.t(
|
|
225
|
+
isReturn ? 'viewer.transitionDetails.returnRecordAria' : 'viewer.transitionDetails.rejectRecordAria',
|
|
226
|
+
{ source: sourceLabel },
|
|
227
|
+
));
|
|
169
228
|
popover.tabIndex = -1;
|
|
170
229
|
|
|
171
230
|
const header = element('header', 'mb-runtime-details-head');
|
|
172
231
|
const heading = element('div', 'mb-runtime-details-heading');
|
|
173
232
|
heading.append(
|
|
174
|
-
element('strong', '', sourceNode?.name || transition.sourceName || '
|
|
175
|
-
element('span', '',
|
|
233
|
+
element('strong', '', sourceNode?.name || transition.sourceName || translator.t('viewer.transitionDetails.fallbackTitle')),
|
|
234
|
+
element('span', '', translator.t(isReturn ? 'viewer.transitionDetails.returnRecord' : 'viewer.transitionDetails.rejectRecord')),
|
|
176
235
|
);
|
|
177
|
-
const status = element('em', 'status-rejected',
|
|
236
|
+
const status = element('em', 'status-rejected', translator.t(isReturn ? 'viewer.transitionDetails.returnedBadge' : 'viewer.transitionDetails.rejectedBadge'));
|
|
178
237
|
applyRuntimeTone(status, viewer?.runtimeAppearance?.resolveTransition(transition).tone);
|
|
179
|
-
const closeButton = runtimeDetailsCloseButton({
|
|
238
|
+
const closeButton = runtimeDetailsCloseButton({
|
|
239
|
+
viewer,
|
|
240
|
+
label: translator.t(isReturn ? 'viewer.transitionDetails.closeReturnDetails' : 'viewer.transitionDetails.closeRejectDetails'),
|
|
241
|
+
close,
|
|
242
|
+
});
|
|
180
243
|
header.append(heading, status, closeButton);
|
|
181
244
|
|
|
182
245
|
const body = element('div', 'mb-runtime-details-body');
|
|
183
246
|
const actor = element('article', 'mb-runtime-transition-actor');
|
|
184
|
-
const actorName = transition.action?.actor?.name || transition.operator || '
|
|
247
|
+
const actorName = transition.action?.actor?.name || transition.operator || translator.t('viewer.transitionDetails.unknownOperator');
|
|
185
248
|
const avatar = element('span', 'mb-runtime-details-avatar', actorName.slice(0, 1));
|
|
186
249
|
const actorCopy = element('div', 'mb-runtime-details-person-copy');
|
|
187
250
|
const actorTitle = element('div', 'mb-runtime-details-person-title');
|
|
@@ -192,20 +255,24 @@ export function renderDefaultRuntimeTransitionDetails({
|
|
|
192
255
|
actorStatus,
|
|
193
256
|
);
|
|
194
257
|
actorCopy.appendChild(actorTitle);
|
|
195
|
-
const time =
|
|
258
|
+
const time = formatViewerTime(viewer, transition.action?.occurredAt || transition.occurredAt || transition.time, 'transition', 'occurred', timeOverrides);
|
|
196
259
|
if (time) actorCopy.appendChild(element('time', '', time));
|
|
197
260
|
actor.append(avatar, actorCopy);
|
|
198
261
|
body.appendChild(actor);
|
|
199
262
|
|
|
200
263
|
const target = element('article', `mb-runtime-details-transition type-${transition.type}`);
|
|
201
264
|
applyRuntimeTone(target, viewer?.runtimeAppearance?.resolveTransition(transition).tone);
|
|
202
|
-
target.appendChild(element('strong', '',
|
|
265
|
+
target.appendChild(element('strong', '', translator.t(
|
|
266
|
+
isReturn ? 'viewer.transitionDetails.returnedTo' : 'viewer.transitionDetails.rejectedTo',
|
|
267
|
+
{ target: targetNode?.name || transition.targetName || transition.targetElementId },
|
|
268
|
+
)));
|
|
203
269
|
if (transition.action) {
|
|
204
270
|
renderRuntimeApprovalContent({
|
|
205
271
|
container: target,
|
|
206
272
|
action: transition.action,
|
|
207
273
|
resolveAsset,
|
|
208
274
|
onPreview: (asset, action) => viewer?._openRuntimeAssetPreview(asset, action),
|
|
275
|
+
i18n: translator,
|
|
209
276
|
});
|
|
210
277
|
} else if (transition.comment) target.appendChild(element('p', '', transition.comment));
|
|
211
278
|
body.appendChild(target);
|
|
@@ -217,11 +284,11 @@ export function renderDefaultRuntimeTransitionDetails({
|
|
|
217
284
|
}
|
|
218
285
|
|
|
219
286
|
const footer = element('footer', 'mb-runtime-transition-actions');
|
|
220
|
-
const sourceButton = element('button', '', '
|
|
287
|
+
const sourceButton = element('button', '', translator.t('viewer.transitionDetails.locateSource'));
|
|
221
288
|
sourceButton.type = 'button';
|
|
222
289
|
sourceButton.disabled = !sourceNode;
|
|
223
290
|
sourceButton.addEventListener('click', locateSource);
|
|
224
|
-
const targetButton = element('button', '', '
|
|
291
|
+
const targetButton = element('button', '', translator.t('viewer.transitionDetails.locateTarget'));
|
|
225
292
|
targetButton.type = 'button';
|
|
226
293
|
targetButton.disabled = !targetNode;
|
|
227
294
|
targetButton.addEventListener('click', locateTarget);
|
|
@@ -336,7 +403,6 @@ function projectRuntime(runtime, projectedModel) {
|
|
|
336
403
|
return { ...normalized, transitions, edgeVisits: projectedEdgeVisits, visitedEdges: projectedVisited };
|
|
337
404
|
}
|
|
338
405
|
|
|
339
|
-
const DEFAULT_TIMELINE_DESCRIPTION = '按实际处理顺序展示';
|
|
340
406
|
const DEFAULT_RUNTIME_DETAILS_LAYOUT = Object.freeze({
|
|
341
407
|
desktop: Object.freeze({ placement: 'popover' }),
|
|
342
408
|
mobile: Object.freeze({ placement: 'bottom' }),
|
|
@@ -366,10 +432,19 @@ export class BpmnViewer {
|
|
|
366
432
|
this.container = options.container;
|
|
367
433
|
this.themeController = options.themeController || new ThemeController({ root: this.container, theme: options.theme, onChange: options.onThemeChange });
|
|
368
434
|
this._ownsThemeController = !options.themeController;
|
|
435
|
+
if (options.i18n) {
|
|
436
|
+
this.i18n = resolveI18n(options.i18n);
|
|
437
|
+
this._ownsI18n = false;
|
|
438
|
+
} else {
|
|
439
|
+
this.i18n = createI18n({ locale: options.locale, messages: options.messages });
|
|
440
|
+
this._ownsI18n = true;
|
|
441
|
+
}
|
|
442
|
+
this.formatRuntimeTime = typeof options.formatRuntimeTime === 'function' ? options.formatRuntimeTime : null;
|
|
443
|
+
this.runtimeTimeFormat = options.runtimeTimeFormat && typeof options.runtimeTimeFormat === 'object' ? { ...options.runtimeTimeFormat } : null;
|
|
369
444
|
this.runtimeAppearanceOptions = options.runtimeAppearance || {};
|
|
370
|
-
this.runtimeAppearance = createRuntimeAppearance(this.runtimeAppearanceOptions);
|
|
445
|
+
this.runtimeAppearance = createRuntimeAppearance(this.runtimeAppearanceOptions, { i18n: this.i18n });
|
|
371
446
|
this.model = options.model;
|
|
372
|
-
this.runtime = options.runtime ? normalizeRuntime(options.runtime) : null;
|
|
447
|
+
this.runtime = options.runtime ? normalizeRuntime(options.runtime, { i18n: this.i18n }) : null;
|
|
373
448
|
this.responsive = options.responsive === true;
|
|
374
449
|
this.projection = options.projection || (this.runtime && this.responsive ? 'auto' : this.runtime ? 'approval' : 'standard');
|
|
375
450
|
this.activeProjection = 'standard';
|
|
@@ -435,6 +510,9 @@ export class BpmnViewer {
|
|
|
435
510
|
if (this._ownsThemeController) this.themeController.destroy();
|
|
436
511
|
throw error;
|
|
437
512
|
}
|
|
513
|
+
this._offI18n = typeof this.i18n.subscribe === 'function'
|
|
514
|
+
? this.i18n.subscribe(() => this._handleLocaleChange())
|
|
515
|
+
: null;
|
|
438
516
|
this._resizeObserver = typeof ResizeObserver === 'function'
|
|
439
517
|
? new ResizeObserver(() => {
|
|
440
518
|
this._refreshAutoProjection();
|
|
@@ -447,6 +525,30 @@ export class BpmnViewer {
|
|
|
447
525
|
this._resizeObserver?.observe(options.container);
|
|
448
526
|
}
|
|
449
527
|
|
|
528
|
+
_handleLocaleChange() {
|
|
529
|
+
this.runtimeAppearance = createRuntimeAppearance(this.runtimeAppearanceOptions, { i18n: this.i18n });
|
|
530
|
+
this.refresh({ preserveViewport: true });
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
setLocale(locale, messages) {
|
|
534
|
+
if (!this._ownsI18n) {
|
|
535
|
+
this._offI18n?.();
|
|
536
|
+
this.i18n = createI18n({ locale: locale ?? this.i18n.locale, messages });
|
|
537
|
+
this._ownsI18n = true;
|
|
538
|
+
this._offI18n = this.i18n.subscribe(() => this._handleLocaleChange());
|
|
539
|
+
if (this.renderer && !(this.renderer instanceof RuntimeTimelineHost)) {
|
|
540
|
+
this.renderer._offI18n?.();
|
|
541
|
+
this.renderer.i18n = this.i18n;
|
|
542
|
+
this.renderer._ownsI18n = false;
|
|
543
|
+
}
|
|
544
|
+
this._handleLocaleChange();
|
|
545
|
+
return this.i18n.getState();
|
|
546
|
+
}
|
|
547
|
+
return this.i18n.setLocale(locale, messages);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
getLocale() { return this.i18n.locale; }
|
|
551
|
+
|
|
450
552
|
_resolveProjection() {
|
|
451
553
|
if (this.projection !== 'auto') return this.projection;
|
|
452
554
|
if (!this.runtime) return 'standard';
|
|
@@ -481,8 +583,8 @@ export class BpmnViewer {
|
|
|
481
583
|
const previousProjection = this.activeProjection;
|
|
482
584
|
this.activeProjection = this._resolveProjection();
|
|
483
585
|
if (this.runtime && ['approval', 'compact'].includes(this.activeProjection)) {
|
|
484
|
-
const sourcePresentation = this.runtimePresenter({ model: this.model, runtime: this.runtime, appearance: this.runtimeAppearance });
|
|
485
|
-
this.traceProjection = this.runtimeTraceProjector({ model: this.model, runtime: this.runtime, presentation: sourcePresentation, options: this.runtimeTraceOptions });
|
|
586
|
+
const sourcePresentation = this.runtimePresenter({ model: this.model, runtime: this.runtime, appearance: this.runtimeAppearance, i18n: this.i18n });
|
|
587
|
+
this.traceProjection = this.runtimeTraceProjector({ model: this.model, runtime: this.runtime, presentation: sourcePresentation, options: this.runtimeTraceOptions, i18n: this.i18n });
|
|
486
588
|
this.projectedModel = this.traceProjection.graphModel;
|
|
487
589
|
this.projectedRuntime = this.traceProjection.graphRuntime;
|
|
488
590
|
} else {
|
|
@@ -490,7 +592,7 @@ export class BpmnViewer {
|
|
|
490
592
|
this.projectedModel = projectModel(this.model, this.activeProjection);
|
|
491
593
|
this.projectedRuntime = projectRuntime(this.runtime, this.projectedModel);
|
|
492
594
|
}
|
|
493
|
-
this.runtimePresentation = this.runtimePresenter({ model: this.projectedModel, runtime: this.projectedRuntime, appearance: this.runtimeAppearance });
|
|
595
|
+
this.runtimePresentation = this.runtimePresenter({ model: this.projectedModel, runtime: this.projectedRuntime, appearance: this.runtimeAppearance, i18n: this.i18n });
|
|
494
596
|
if (previousProjection !== this.activeProjection) this.onProjectionChange({ requested: this.projection, active: this.activeProjection });
|
|
495
597
|
}
|
|
496
598
|
|
|
@@ -508,8 +610,8 @@ export class BpmnViewer {
|
|
|
508
610
|
return result == null ? null : String(result);
|
|
509
611
|
};
|
|
510
612
|
return {
|
|
511
|
-
title: resolve(this.timelineOptions.title, this.model.name || '
|
|
512
|
-
description: resolve(this.timelineOptions.description,
|
|
613
|
+
title: resolve(this.timelineOptions.title, this.model.name || this.i18n.t('timeline.defaultTitle')),
|
|
614
|
+
description: resolve(this.timelineOptions.description, this.i18n.t('timeline.defaultDescription')),
|
|
513
615
|
};
|
|
514
616
|
}
|
|
515
617
|
|
|
@@ -599,6 +701,10 @@ export class BpmnViewer {
|
|
|
599
701
|
iconRegistry: this.options.iconRegistry,
|
|
600
702
|
appearance: this.runtimeAppearance,
|
|
601
703
|
themeState: this.themeController.getState(),
|
|
704
|
+
i18n: this.i18n,
|
|
705
|
+
formatRuntimeTime: this.formatRuntimeTime,
|
|
706
|
+
runtimeTimeFormat: this.runtimeTimeFormat,
|
|
707
|
+
formatTime: (value, field = 'occurred') => formatViewerTime(this, value, 'timeline', field),
|
|
602
708
|
resolveAsset: (asset, purpose, action) => this._resolveRuntimeAsset(asset, purpose, action),
|
|
603
709
|
onAssetPreview: (asset, action) => this._openRuntimeAssetPreview(asset, action),
|
|
604
710
|
renderer: this.runtimeTimelineRenderer,
|
|
@@ -639,6 +745,8 @@ export class BpmnViewer {
|
|
|
639
745
|
}
|
|
640
746
|
this.renderer = new DiagramRenderer(this.container, {
|
|
641
747
|
themeController: this.themeController,
|
|
748
|
+
i18n: this.i18n,
|
|
749
|
+
autoSyncI18n: false,
|
|
642
750
|
model: this.projectedModel,
|
|
643
751
|
visualModel: this.model,
|
|
644
752
|
runtime: this.projectedRuntime,
|
|
@@ -810,15 +918,15 @@ export class BpmnViewer {
|
|
|
810
918
|
const root = element('div', 'mb-runtime-asset-preview');
|
|
811
919
|
root.setAttribute('role', 'dialog');
|
|
812
920
|
root.setAttribute('aria-modal', 'true');
|
|
813
|
-
root.setAttribute('aria-label',
|
|
921
|
+
root.setAttribute('aria-label', this.i18n.t('viewer.assets.imagePreviewAria', { name: asset.name }));
|
|
814
922
|
root.addEventListener('pointerdown', (event) => { if (event.target === root) this.closeRuntimeAssetPreview(); });
|
|
815
923
|
const dialog = element('section', 'mb-runtime-asset-preview-dialog');
|
|
816
924
|
const header = element('header', 'mb-runtime-asset-preview-head');
|
|
817
925
|
header.appendChild(element('strong', '', asset.name));
|
|
818
|
-
const close = runtimeDetailsCloseButton({ viewer: this, label: '
|
|
926
|
+
const close = runtimeDetailsCloseButton({ viewer: this, label: this.i18n.t('viewer.assets.closeImagePreview'), close: () => this.closeRuntimeAssetPreview() });
|
|
819
927
|
header.appendChild(close);
|
|
820
928
|
const body = element('div', 'mb-runtime-asset-preview-body');
|
|
821
|
-
const state = element('span', 'mb-runtime-asset-preview-state', '
|
|
929
|
+
const state = element('span', 'mb-runtime-asset-preview-state', this.i18n.t('viewer.assets.imageLoading'));
|
|
822
930
|
body.appendChild(state);
|
|
823
931
|
dialog.append(header, body);
|
|
824
932
|
root.appendChild(dialog);
|
|
@@ -826,14 +934,14 @@ export class BpmnViewer {
|
|
|
826
934
|
this._assetPreviewRoot = root;
|
|
827
935
|
Promise.resolve(this._resolveRuntimeAsset(asset, 'preview', action)).then((url) => {
|
|
828
936
|
if (!root.isConnected) return;
|
|
829
|
-
if (!url) { state.textContent = '
|
|
937
|
+
if (!url) { state.textContent = this.i18n.t('viewer.assets.unavailable'); return; }
|
|
830
938
|
const image = document.createElement('img');
|
|
831
939
|
image.alt = asset.name;
|
|
832
940
|
image.addEventListener('load', () => {
|
|
833
941
|
if (root.isConnected) body.replaceChildren(image);
|
|
834
942
|
}, { once: true });
|
|
835
943
|
image.addEventListener('error', () => {
|
|
836
|
-
if (root.isConnected) state.textContent = '
|
|
944
|
+
if (root.isConnected) state.textContent = this.i18n.t('viewer.assets.unavailable');
|
|
837
945
|
}, { once: true });
|
|
838
946
|
image.src = url;
|
|
839
947
|
});
|
|
@@ -869,6 +977,8 @@ export class BpmnViewer {
|
|
|
869
977
|
resolveAsset: (asset, purpose, action) => this._resolveRuntimeAsset(asset, purpose, action),
|
|
870
978
|
themeState: this.themeController.getState(),
|
|
871
979
|
runtimeAppearance: this.runtimeAppearance,
|
|
980
|
+
i18n: this.i18n,
|
|
981
|
+
formatTime: (value, field = 'occurred') => formatViewerTime(this, value, 'details', field),
|
|
872
982
|
}) || null;
|
|
873
983
|
this._prepareRuntimeDetailsMotion(layout);
|
|
874
984
|
this._positionRuntimeDetails(anchor, layout);
|
|
@@ -911,6 +1021,8 @@ export class BpmnViewer {
|
|
|
911
1021
|
resolveAsset: (asset, purpose, action) => this._resolveRuntimeAsset(asset, purpose, action),
|
|
912
1022
|
themeState: this.themeController.getState(),
|
|
913
1023
|
runtimeAppearance: this.runtimeAppearance,
|
|
1024
|
+
i18n: this.i18n,
|
|
1025
|
+
formatTime: (value, field = 'occurred') => formatViewerTime(this, value, 'transition', field),
|
|
914
1026
|
locateSource: () => locate(sourceNode),
|
|
915
1027
|
locateTarget: () => locate(targetNode),
|
|
916
1028
|
}) || null;
|
|
@@ -949,9 +1061,10 @@ export class BpmnViewer {
|
|
|
949
1061
|
let left = target.left - host.left + target.width / 2 - width / 2;
|
|
950
1062
|
left = Math.max(12, Math.min(left, host.width - width - 12));
|
|
951
1063
|
let top = target.top - host.top - height - 10;
|
|
952
|
-
if (top < 12) top =
|
|
1064
|
+
if (top < 12) top = target.bottom - host.top + 10;
|
|
1065
|
+
top = Math.max(12, Math.min(top, host.height - height - 12));
|
|
953
1066
|
popover.style.left = `${Math.max(12, left)}px`;
|
|
954
|
-
popover.style.top = `${
|
|
1067
|
+
popover.style.top = `${top}px`;
|
|
955
1068
|
}
|
|
956
1069
|
|
|
957
1070
|
closeRuntimeDetails() {
|
|
@@ -1006,7 +1119,8 @@ export class BpmnViewer {
|
|
|
1006
1119
|
const viewport = this.renderer?.getViewportState?.();
|
|
1007
1120
|
if (viewport) this._lastViewport = viewport;
|
|
1008
1121
|
} else if (kind === 'timeline') {
|
|
1009
|
-
this.
|
|
1122
|
+
const scrollTop = this.renderer?.getScrollTop?.() ?? this.container.scrollTop ?? 0;
|
|
1123
|
+
this._timelineScroll = this._containerHasSize() ? scrollTop : (scrollTop || this._timelineScroll || 0);
|
|
1010
1124
|
}
|
|
1011
1125
|
return {
|
|
1012
1126
|
kind,
|
|
@@ -1033,6 +1147,10 @@ export class BpmnViewer {
|
|
|
1033
1147
|
...this._resolveTimelineOptions(),
|
|
1034
1148
|
appearance: this.runtimeAppearance,
|
|
1035
1149
|
themeState: this.themeController.getState(),
|
|
1150
|
+
i18n: this.i18n,
|
|
1151
|
+
formatRuntimeTime: this.formatRuntimeTime,
|
|
1152
|
+
runtimeTimeFormat: this.runtimeTimeFormat,
|
|
1153
|
+
formatTime: (value, field = 'occurred') => formatViewerTime(this, value, 'timeline', field),
|
|
1036
1154
|
});
|
|
1037
1155
|
this.renderer.render();
|
|
1038
1156
|
}
|
|
@@ -1048,12 +1166,16 @@ export class BpmnViewer {
|
|
|
1048
1166
|
if (target.kind === 'node') {
|
|
1049
1167
|
const node = this.model.nodes.find((item) => item.id === target.id);
|
|
1050
1168
|
const presentation = node ? this.runtimePresentation.getNode(node.id) : null;
|
|
1051
|
-
|
|
1169
|
+
const anchor = target.anchor?.isConnected
|
|
1170
|
+
? target.anchor
|
|
1171
|
+
: this.container?.querySelector?.(`[data-node-id="${target.id}"]`) || null;
|
|
1172
|
+
if (node && presentation?.hasDetails) this.openRuntimeDetails(node, presentation, anchor);
|
|
1052
1173
|
return;
|
|
1053
1174
|
}
|
|
1054
1175
|
if (target.kind === 'transition') {
|
|
1055
1176
|
const transition = this.runtimePresentation.getTransition(target.id);
|
|
1056
|
-
|
|
1177
|
+
const anchor = target.anchor?.isConnected ? target.anchor : null;
|
|
1178
|
+
if (transition) this._openRuntimeTransitionDetails(transition, anchor);
|
|
1057
1179
|
}
|
|
1058
1180
|
}
|
|
1059
1181
|
|
|
@@ -1074,7 +1196,12 @@ export class BpmnViewer {
|
|
|
1074
1196
|
this._silentViewport = true;
|
|
1075
1197
|
try {
|
|
1076
1198
|
if (kind === 'diagram' && preserveViewport && this._lastViewport) this.renderer.setViewportState?.(this._lastViewport);
|
|
1077
|
-
if (kind === 'timeline'
|
|
1199
|
+
if (kind === 'timeline') {
|
|
1200
|
+
const scrollTop = preserveViewport ? (this._timelineScroll || 0) : 0;
|
|
1201
|
+
this._timelineScroll = scrollTop;
|
|
1202
|
+
if (typeof this.renderer?.setScrollTop === 'function') this.renderer.setScrollTop(scrollTop);
|
|
1203
|
+
else this.container.scrollTop = scrollTop;
|
|
1204
|
+
}
|
|
1078
1205
|
} finally {
|
|
1079
1206
|
this._silentViewport = false;
|
|
1080
1207
|
}
|
|
@@ -1088,7 +1215,7 @@ export class BpmnViewer {
|
|
|
1088
1215
|
this.refresh({ preserveViewport: same });
|
|
1089
1216
|
}
|
|
1090
1217
|
setRuntime(runtime) {
|
|
1091
|
-
const next = runtime ? normalizeRuntime(runtime) : null;
|
|
1218
|
+
const next = runtime ? normalizeRuntime(runtime, { i18n: this.i18n }) : null;
|
|
1092
1219
|
const sameInstance = Boolean(this.runtime) && Boolean(next) && (this.runtime.processInstanceId || '') === (next.processInstanceId || '');
|
|
1093
1220
|
this.runtime = next;
|
|
1094
1221
|
this.mode = this.options.mode === 'instance' || this.runtime ? 'instance' : 'viewer';
|
|
@@ -1104,13 +1231,21 @@ export class BpmnViewer {
|
|
|
1104
1231
|
else this._pendingFit = true;
|
|
1105
1232
|
});
|
|
1106
1233
|
}
|
|
1107
|
-
setDisplayOptions({ timeline, runtimeDetails, runtimeTraceOptions, runtimeAssetResolver, replace = false } = {}) {
|
|
1234
|
+
setDisplayOptions({ timeline, runtimeDetails, runtimeTraceOptions, runtimeAssetResolver, formatRuntimeTime, runtimeTimeFormat, replace = false } = {}) {
|
|
1108
1235
|
let changed = false;
|
|
1109
1236
|
if (runtimeAssetResolver !== undefined) {
|
|
1110
1237
|
this.runtimeAssetResolver = runtimeAssetResolver || null;
|
|
1111
1238
|
this._svgExportAssetCache.clear();
|
|
1112
1239
|
changed = true;
|
|
1113
1240
|
}
|
|
1241
|
+
if (replace || formatRuntimeTime !== undefined) {
|
|
1242
|
+
this.formatRuntimeTime = typeof formatRuntimeTime === 'function' ? formatRuntimeTime : null;
|
|
1243
|
+
changed = true;
|
|
1244
|
+
}
|
|
1245
|
+
if (replace || runtimeTimeFormat !== undefined) {
|
|
1246
|
+
this.runtimeTimeFormat = runtimeTimeFormat && typeof runtimeTimeFormat === 'object' ? { ...runtimeTimeFormat } : null;
|
|
1247
|
+
changed = true;
|
|
1248
|
+
}
|
|
1114
1249
|
if (replace || runtimeTraceOptions !== undefined) {
|
|
1115
1250
|
this.runtimeTraceOptions = replace
|
|
1116
1251
|
? { ...(runtimeTraceOptions || {}) }
|
|
@@ -1132,17 +1267,33 @@ export class BpmnViewer {
|
|
|
1132
1267
|
getThemeState() { return this.themeController.getState(); }
|
|
1133
1268
|
setRuntimeAppearance(runtimeAppearance) {
|
|
1134
1269
|
this.runtimeAppearanceOptions = runtimeAppearance || {};
|
|
1135
|
-
this.runtimeAppearance = createRuntimeAppearance(this.runtimeAppearanceOptions);
|
|
1270
|
+
this.runtimeAppearance = createRuntimeAppearance(this.runtimeAppearanceOptions, { i18n: this.i18n });
|
|
1136
1271
|
this.refresh({ preserveViewport: true });
|
|
1137
1272
|
}
|
|
1138
1273
|
refreshPresentation() {
|
|
1274
|
+
if (this.mode === 'instance') {
|
|
1275
|
+
this.refresh({ preserveViewport: true });
|
|
1276
|
+
return;
|
|
1277
|
+
}
|
|
1139
1278
|
if (this.mode !== 'viewer' || (this.runtime && this.activeProjection === 'compact')) return;
|
|
1140
1279
|
this.renderer?.refreshPresentation?.();
|
|
1141
1280
|
}
|
|
1142
1281
|
exportSvg(options = {}) {
|
|
1143
1282
|
const isTimeline = Boolean(this.runtime && this.activeProjection === 'compact' && this.traceProjection);
|
|
1144
|
-
const label = isTimeline
|
|
1283
|
+
const label = isTimeline
|
|
1284
|
+
? this.i18n.t('exportSvg.defaultLabels.timeline')
|
|
1285
|
+
: this.activeProjection === 'approval'
|
|
1286
|
+
? this.i18n.t('exportSvg.defaultLabels.approval')
|
|
1287
|
+
: this.runtime
|
|
1288
|
+
? this.i18n.t('exportSvg.defaultLabels.standard')
|
|
1289
|
+
: this.i18n.t('exportSvg.defaultLabels.viewer');
|
|
1145
1290
|
const filename = options.filename || this.svgExportOptions.filename || `${this.model.name || this.model.id || 'process'}-${label}`;
|
|
1291
|
+
const formatRuntimeTime = options.formatRuntimeTime !== undefined
|
|
1292
|
+
? options.formatRuntimeTime
|
|
1293
|
+
: (this.svgExportOptions.formatRuntimeTime !== undefined ? this.svgExportOptions.formatRuntimeTime : this.formatRuntimeTime);
|
|
1294
|
+
const runtimeTimeFormat = options.runtimeTimeFormat !== undefined
|
|
1295
|
+
? options.runtimeTimeFormat
|
|
1296
|
+
: (this.svgExportOptions.runtimeTimeFormat !== undefined ? this.svgExportOptions.runtimeTimeFormat : this.runtimeTimeFormat);
|
|
1146
1297
|
if (isTimeline) {
|
|
1147
1298
|
const timeline = this._resolveTimelineOptions();
|
|
1148
1299
|
return exportRuntimeTimelineSvg({
|
|
@@ -1155,11 +1306,14 @@ export class BpmnViewer {
|
|
|
1155
1306
|
themeController: this.themeController,
|
|
1156
1307
|
iconRegistry: this.options.iconRegistry,
|
|
1157
1308
|
runtimeAppearance: this.runtimeAppearance,
|
|
1309
|
+
i18n: this.i18n,
|
|
1310
|
+
formatRuntimeTime,
|
|
1311
|
+
runtimeTimeFormat,
|
|
1158
1312
|
resolveAsset: (asset, purpose, action) => this._resolveRuntimeAsset(asset, purpose, action, options.signal),
|
|
1159
1313
|
assetCache: this._svgExportAssetCache,
|
|
1160
1314
|
timelineRenderer: this.svgExportOptions.runtimeTimelineRenderer,
|
|
1161
1315
|
label,
|
|
1162
|
-
}, { ...this.svgExportOptions, ...options, filename });
|
|
1316
|
+
}, { ...this.svgExportOptions, ...options, filename, formatRuntimeTime, runtimeTimeFormat });
|
|
1163
1317
|
}
|
|
1164
1318
|
return this.renderer.exportSvg({ ...this.svgExportOptions, ...options, filename, label });
|
|
1165
1319
|
}
|
|
@@ -1170,8 +1324,9 @@ export class BpmnViewer {
|
|
|
1170
1324
|
}
|
|
1171
1325
|
this._svgExportPreview = openSvgExportPreview({
|
|
1172
1326
|
container: this.container,
|
|
1173
|
-
title: options.previewTitle || '
|
|
1327
|
+
title: options.previewTitle || this.i18n.t('exportSvg.preview.defaultTitle'),
|
|
1174
1328
|
initialTheme: options.theme || 'current',
|
|
1329
|
+
i18n: this.i18n,
|
|
1175
1330
|
createArtifact: (previewOptions) => this.exportSvg({ ...options, ...previewOptions }),
|
|
1176
1331
|
onClose: () => { this._svgExportPreview = null; },
|
|
1177
1332
|
onDownload: options.onDownload,
|
|
@@ -1181,6 +1336,8 @@ export class BpmnViewer {
|
|
|
1181
1336
|
fitView() { this.renderer.fitView(); }
|
|
1182
1337
|
zoomBy(delta) { this.renderer.zoomBy(delta); }
|
|
1183
1338
|
destroy() {
|
|
1339
|
+
this._offI18n?.();
|
|
1340
|
+
this._offI18n = null;
|
|
1184
1341
|
this._sidebarTransitionActive = false;
|
|
1185
1342
|
this._sidebarViewport = null;
|
|
1186
1343
|
this._svgExportPreview?.close?.({ immediate: true });
|