@bpmn-nova/studio 0.3.9-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 +13 -0
- package/dist/context-menu.js +41 -32
- package/dist/controller.js +45 -19
- package/dist/index.d.ts +47 -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 +258 -75
- package/dist/sidebars.js +3 -1
- package/dist/styles.css +3 -2
- package/llms-full.txt +241 -46
- package/llms.txt +4 -4
- package/package.json +2 -3
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { DEFAULT_I18N, resolveI18n } from '../i18n/index.js';
|
|
2
|
+
|
|
1
3
|
function element(tag, className, text) {
|
|
2
4
|
const node = document.createElement(tag);
|
|
3
5
|
if (className) node.className = className;
|
|
@@ -17,56 +19,56 @@ function assetMeta(asset) {
|
|
|
17
19
|
return [asset.mediaType, formatRuntimeAssetSize(asset.size)].filter(Boolean).join(' · ');
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
function unavailable(target, label =
|
|
22
|
+
function unavailable(target, i18n = DEFAULT_I18N, label = null) {
|
|
21
23
|
target.classList.add('is-unavailable');
|
|
22
24
|
target.setAttribute('aria-disabled', 'true');
|
|
23
25
|
const state = target.querySelector('.mb-runtime-asset-state');
|
|
24
|
-
if (state) state.textContent = label;
|
|
26
|
+
if (state) state.textContent = label || i18n.t('viewer.assets.unavailable');
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
function renderImage({ host, asset, action, resolveAsset, onPreview, compact, alt }) {
|
|
29
|
+
function renderImage({ host, asset, action, resolveAsset, onPreview, compact, alt, i18n = DEFAULT_I18N }) {
|
|
28
30
|
const button = element('button', 'mb-runtime-asset-image is-loading');
|
|
29
31
|
button.type = 'button';
|
|
30
|
-
button.setAttribute('aria-label',
|
|
31
|
-
const state = element('span', 'mb-runtime-asset-state', '
|
|
32
|
+
button.setAttribute('aria-label', i18n.t('viewer.assets.previewImageAria', { name: alt || asset.name }));
|
|
33
|
+
const state = element('span', 'mb-runtime-asset-state', i18n.t('viewer.assets.imageLoading'));
|
|
32
34
|
button.appendChild(state);
|
|
33
35
|
host.appendChild(button);
|
|
34
36
|
Promise.resolve(resolveAsset?.(asset, 'thumbnail', action)).then((url) => {
|
|
35
37
|
if (!button.isConnected) return;
|
|
36
|
-
if (!url) { unavailable(button); return; }
|
|
38
|
+
if (!url) { unavailable(button, i18n); return; }
|
|
37
39
|
const image = document.createElement('img');
|
|
38
40
|
image.alt = alt || asset.name;
|
|
39
41
|
image.loading = 'lazy';
|
|
40
42
|
image.addEventListener('error', () => {
|
|
41
43
|
if (!button.isConnected) return;
|
|
42
|
-
button.replaceChildren(element('span', 'mb-runtime-asset-state', '
|
|
43
|
-
unavailable(button);
|
|
44
|
+
button.replaceChildren(element('span', 'mb-runtime-asset-state', i18n.t('viewer.assets.unavailable')));
|
|
45
|
+
unavailable(button, i18n);
|
|
44
46
|
}, { once: true });
|
|
45
47
|
image.src = url;
|
|
46
48
|
button.replaceChildren(image);
|
|
47
49
|
button.classList.remove('is-loading');
|
|
48
50
|
button.addEventListener('click', () => onPreview?.(asset, action));
|
|
49
|
-
}).catch(() => { if (button.isConnected) unavailable(button); });
|
|
51
|
+
}).catch(() => { if (button.isConnected) unavailable(button, i18n); });
|
|
50
52
|
if (!compact) button.title = assetMeta(asset);
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
function renderFile({ host, asset, action, resolveAsset }) {
|
|
55
|
+
function renderFile({ host, asset, action, resolveAsset, i18n = DEFAULT_I18N }) {
|
|
54
56
|
const link = element('a', 'mb-runtime-asset-file is-loading');
|
|
55
|
-
link.setAttribute('aria-label',
|
|
57
|
+
link.setAttribute('aria-label', i18n.t('viewer.assets.downloadFileAria', { name: asset.name }));
|
|
56
58
|
const copy = element('span', 'mb-runtime-asset-file-copy');
|
|
57
59
|
copy.append(element('strong', '', asset.name), element('small', '', assetMeta(asset)));
|
|
58
|
-
link.append(copy, element('span', 'mb-runtime-asset-state', '
|
|
60
|
+
link.append(copy, element('span', 'mb-runtime-asset-state', i18n.t('viewer.assets.preparingDownload')));
|
|
59
61
|
host.appendChild(link);
|
|
60
62
|
Promise.resolve(resolveAsset?.(asset, 'download', action)).then((url) => {
|
|
61
63
|
if (!link.isConnected) return;
|
|
62
|
-
if (!url) { unavailable(link); return; }
|
|
64
|
+
if (!url) { unavailable(link, i18n); return; }
|
|
63
65
|
link.href = url;
|
|
64
66
|
link.target = '_blank';
|
|
65
67
|
link.rel = 'noopener noreferrer';
|
|
66
68
|
link.download = asset.name;
|
|
67
69
|
link.classList.remove('is-loading');
|
|
68
|
-
link.querySelector('.mb-runtime-asset-state').textContent = '
|
|
69
|
-
}).catch(() => { if (link.isConnected) unavailable(link); });
|
|
70
|
+
link.querySelector('.mb-runtime-asset-state').textContent = i18n.t('viewer.assets.download');
|
|
71
|
+
}).catch(() => { if (link.isConnected) unavailable(link, i18n); });
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
export function renderRuntimeApprovalContent({
|
|
@@ -76,7 +78,11 @@ export function renderRuntimeApprovalContent({
|
|
|
76
78
|
onPreview,
|
|
77
79
|
compact = false,
|
|
78
80
|
imageLimit = compact ? 3 : Number.POSITIVE_INFINITY,
|
|
81
|
+
i18n = null,
|
|
82
|
+
locale,
|
|
83
|
+
messages,
|
|
79
84
|
}) {
|
|
85
|
+
const translator = resolveI18n({ i18n, locale, messages });
|
|
80
86
|
const content = action?.content || { plainText: '', blocks: [], assets: [] };
|
|
81
87
|
const assets = new Map((content.assets || []).map((asset) => [asset.id, asset]));
|
|
82
88
|
const root = element('div', `mb-runtime-action-content${compact ? ' is-compact' : ''}`);
|
|
@@ -94,21 +100,21 @@ export function renderRuntimeApprovalContent({
|
|
|
94
100
|
if (imageCount > imageLimit) return;
|
|
95
101
|
const asset = assets.get(block.assetId);
|
|
96
102
|
if (!asset || !asset.mediaType.startsWith('image/')) {
|
|
97
|
-
media.appendChild(element('span', 'mb-runtime-asset-unsupported', '
|
|
103
|
+
media.appendChild(element('span', 'mb-runtime-asset-unsupported', translator.t('viewer.assets.imageUnavailable')));
|
|
98
104
|
} else {
|
|
99
|
-
renderImage({ host: media, asset, action, resolveAsset, onPreview, compact, alt: block.alt });
|
|
105
|
+
renderImage({ host: media, asset, action, resolveAsset, onPreview, compact, alt: block.alt, i18n: translator });
|
|
100
106
|
}
|
|
101
107
|
rendered += 1;
|
|
102
108
|
return;
|
|
103
109
|
}
|
|
104
110
|
if (block.type === 'file') {
|
|
105
111
|
const asset = assets.get(block.assetId);
|
|
106
|
-
if (!asset) media.appendChild(element('span', 'mb-runtime-asset-unsupported', '
|
|
107
|
-
else renderFile({ host: media, asset, action, resolveAsset });
|
|
112
|
+
if (!asset) media.appendChild(element('span', 'mb-runtime-asset-unsupported', translator.t('viewer.assets.fileUnavailable')));
|
|
113
|
+
else renderFile({ host: media, asset, action, resolveAsset, i18n: translator });
|
|
108
114
|
rendered += 1;
|
|
109
115
|
return;
|
|
110
116
|
}
|
|
111
|
-
root.appendChild(element('p', 'mb-runtime-asset-unsupported',
|
|
117
|
+
root.appendChild(element('p', 'mb-runtime-asset-unsupported', translator.t('viewer.assets.unsupportedContent', { type: block.type || 'unknown' })));
|
|
112
118
|
rendered += 1;
|
|
113
119
|
});
|
|
114
120
|
|
|
@@ -6,8 +6,11 @@ import {
|
|
|
6
6
|
getScopeGraph,
|
|
7
7
|
NODE_DEFINITIONS,
|
|
8
8
|
} from '../core/index.js';
|
|
9
|
+
import { DEFAULT_I18N, resolveI18n } from '../i18n/index.js';
|
|
9
10
|
import { compareRuntimeOrder, createRuntimePresentation, normalizeRuntime, parseRuntimeInstant } from '../runtime/index.js';
|
|
10
11
|
|
|
12
|
+
const KNOWN_STATUSES = new Set(['active', 'completed', 'failed', 'cancelled', 'skipped', 'idle', 'rejected', 'returned']);
|
|
13
|
+
|
|
11
14
|
const HUMAN_TASKS = new Set(['userTask', 'manualTask', 'callActivity']);
|
|
12
15
|
const AUTOMATED_TASKS = new Set(['serviceTask', 'scriptTask', 'businessRuleTask', 'sendTask', 'receiveTask']);
|
|
13
16
|
const CONDITIONAL_GATEWAYS = new Set(['exclusiveGateway', 'inclusiveGateway', 'eventBasedGateway', 'complexGateway']);
|
|
@@ -45,19 +48,24 @@ function visitStatus(records) {
|
|
|
45
48
|
return 'completed';
|
|
46
49
|
}
|
|
47
50
|
|
|
48
|
-
function statusLabel(status, records) {
|
|
51
|
+
function statusLabel(status, records, i18n = DEFAULT_I18N) {
|
|
49
52
|
const outcome = records.map((record) => record.outcome).filter(Boolean).at(-1);
|
|
50
|
-
if (outcome === 'rejected') return '
|
|
51
|
-
if (outcome === 'returned') return '
|
|
53
|
+
if (outcome === 'rejected') return i18n.t('runtime.status.rejected');
|
|
54
|
+
if (outcome === 'returned') return i18n.t('runtime.status.returned');
|
|
52
55
|
const participants = records.map((record) => record.participant).filter((participant) => participant?.name);
|
|
53
56
|
const completed = records.filter((record) => record.status === 'completed').length;
|
|
54
57
|
const total = Math.max(records.reduce((value, record) => Math.max(value, Number(record.totalInstances) || 0), 0), records.length, participants.length);
|
|
55
58
|
const approvalMode = records.find((record) => record.approvalMode)?.approvalMode;
|
|
56
59
|
const multiInstanceMode = records.find((record) => record.multiInstanceMode)?.multiInstanceMode;
|
|
57
|
-
if (approvalMode === 'all')
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
if (approvalMode === 'all') {
|
|
61
|
+
return i18n.t(
|
|
62
|
+
multiInstanceMode === 'sequential' ? 'runtime.status.sequentialCountersign' : 'runtime.status.countersign',
|
|
63
|
+
{ completed, total },
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
if (approvalMode === 'any') return i18n.t('runtime.status.orSign', { completed, total });
|
|
67
|
+
if (participants.length > 1) return i18n.t('runtime.status.multiApproval', { completed, total });
|
|
68
|
+
return KNOWN_STATUSES.has(status) ? i18n.t(`runtime.status.${status}`) : status;
|
|
61
69
|
}
|
|
62
70
|
|
|
63
71
|
function uniqueParticipants(records) {
|
|
@@ -71,8 +79,8 @@ function uniqueParticipants(records) {
|
|
|
71
79
|
});
|
|
72
80
|
}
|
|
73
81
|
|
|
74
|
-
function participantSummary(participants) {
|
|
75
|
-
const visible = participants.slice(0, 2).map((participant) => participant.name).join('
|
|
82
|
+
function participantSummary(participants, i18n = DEFAULT_I18N) {
|
|
83
|
+
const visible = participants.slice(0, 2).map((participant) => participant.name).join(i18n.t('common.listSeparator'));
|
|
76
84
|
return participants.length > 2 ? `${visible} +${participants.length - 2}` : visible;
|
|
77
85
|
}
|
|
78
86
|
|
|
@@ -320,7 +328,7 @@ function projectRuntime(runtime, graphModel, presentation) {
|
|
|
320
328
|
return { ...runtime, transitions, visitedEdges: [...new Set(projectedVisited)], edgeVisits: projectedEdgeVisits };
|
|
321
329
|
}
|
|
322
330
|
|
|
323
|
-
function buildVisitItems(model, runtime, presentation, predictedNodeIds, orderedPredictedIds, options) {
|
|
331
|
+
function buildVisitItems(model, runtime, presentation, predictedNodeIds, orderedPredictedIds, options, i18n = DEFAULT_I18N) {
|
|
324
332
|
const nodeMap = new Map(model.nodes.map((node) => [node.id, node]));
|
|
325
333
|
const transitionActionIds = new Set(presentation.getTransitions().map((transition) => transition.actionId).filter(Boolean));
|
|
326
334
|
const groups = new Map();
|
|
@@ -354,13 +362,13 @@ function buildVisitItems(model, runtime, presentation, predictedNodeIds, ordered
|
|
|
354
362
|
elementId: group.node.id,
|
|
355
363
|
visitId: group.visitId,
|
|
356
364
|
round,
|
|
357
|
-
name: group.node.name || NODE_DEFINITIONS[group.node.type]?.label || group.node.id,
|
|
365
|
+
name: group.node.name || i18n.elementTypeLabel(group.node.type, NODE_DEFINITIONS[group.node.type]?.label) || group.node.id,
|
|
358
366
|
nodeType: group.node.type,
|
|
359
367
|
automated: AUTOMATED_TASKS.has(group.node.type),
|
|
360
368
|
status,
|
|
361
|
-
statusLabel: statusLabel(status, group.records),
|
|
369
|
+
statusLabel: statusLabel(status, group.records, i18n),
|
|
362
370
|
participants,
|
|
363
|
-
summary: participantSummary(participants) || presentation.getNode(group.node.id).summary,
|
|
371
|
+
summary: participantSummary(participants, i18n) || presentation.getNode(group.node.id).summary,
|
|
364
372
|
records: group.records,
|
|
365
373
|
actions,
|
|
366
374
|
latestAction,
|
|
@@ -372,6 +380,7 @@ function buildVisitItems(model, runtime, presentation, predictedNodeIds, ordered
|
|
|
372
380
|
startTime,
|
|
373
381
|
endTime,
|
|
374
382
|
time: endTime || startTime || '',
|
|
383
|
+
timeField: endTime ? 'end' : (startTime ? 'start' : 'occurred'),
|
|
375
384
|
outcome: group.records.map((record) => record.outcome).filter(Boolean).at(-1) || '',
|
|
376
385
|
comment: latestAction?.plainText || group.records.map((record) => record.comment).filter(Boolean).at(-1) || '',
|
|
377
386
|
predicted: false,
|
|
@@ -389,13 +398,13 @@ function buildVisitItems(model, runtime, presentation, predictedNodeIds, ordered
|
|
|
389
398
|
elementId: node.id,
|
|
390
399
|
visitId: null,
|
|
391
400
|
round: 0,
|
|
392
|
-
name: node.name || NODE_DEFINITIONS[node.type]?.label || node.id,
|
|
401
|
+
name: node.name || i18n.elementTypeLabel(node.type, NODE_DEFINITIONS[node.type]?.label) || node.id,
|
|
393
402
|
nodeType: node.type,
|
|
394
403
|
automated: false,
|
|
395
404
|
status: 'idle',
|
|
396
|
-
statusLabel: '
|
|
405
|
+
statusLabel: i18n.t('runtime.status.idle'),
|
|
397
406
|
participants: [],
|
|
398
|
-
summary: '
|
|
407
|
+
summary: i18n.t('runtime.trace.predictedSummary'),
|
|
399
408
|
records: [],
|
|
400
409
|
actions: [],
|
|
401
410
|
latestAction: null,
|
|
@@ -407,6 +416,7 @@ function buildVisitItems(model, runtime, presentation, predictedNodeIds, ordered
|
|
|
407
416
|
startTime: '',
|
|
408
417
|
endTime: '',
|
|
409
418
|
time: '',
|
|
419
|
+
timeField: 'occurred',
|
|
410
420
|
outcome: '',
|
|
411
421
|
comment: '',
|
|
412
422
|
predicted: true,
|
|
@@ -421,9 +431,10 @@ function buildVisitItems(model, runtime, presentation, predictedNodeIds, ordered
|
|
|
421
431
|
type: transition.type,
|
|
422
432
|
name: transition.label,
|
|
423
433
|
status: transition.state,
|
|
424
|
-
statusLabel: transition.type === 'reject' ? '
|
|
434
|
+
statusLabel: i18n.t(transition.type === 'reject' ? 'runtime.transitions.reject' : 'runtime.transitions.return'),
|
|
425
435
|
summary: transition.operator || '',
|
|
426
436
|
time: transition.occurredAt || transition.time || '',
|
|
437
|
+
timeField: 'occurred',
|
|
427
438
|
comment: transition.action?.plainText || transition.comment || '',
|
|
428
439
|
actions: transition.action ? [transition.action] : [],
|
|
429
440
|
latestAction: transition.action || null,
|
|
@@ -478,7 +489,7 @@ function firstVisibleFrom(edge, maps, visibleElementIds, allowedEdgeIds) {
|
|
|
478
489
|
return null;
|
|
479
490
|
}
|
|
480
491
|
|
|
481
|
-
function buildParallelGroups(model, items, maps, allowedEdgeIds) {
|
|
492
|
+
function buildParallelGroups(model, items, maps, allowedEdgeIds, i18n = DEFAULT_I18N) {
|
|
482
493
|
const itemByElement = new Map();
|
|
483
494
|
for (const item of items.filter((entry) => entry.kind !== 'transition')) {
|
|
484
495
|
if (!itemByElement.has(item.elementId) || item.predicted) itemByElement.set(item.elementId, item);
|
|
@@ -495,7 +506,7 @@ function buildParallelGroups(model, items, maps, allowedEdgeIds) {
|
|
|
495
506
|
id: `TraceGroup_${gateway.id}`,
|
|
496
507
|
kind: 'parallel',
|
|
497
508
|
gatewayId: gateway.id,
|
|
498
|
-
label: gateway.name || '
|
|
509
|
+
label: gateway.name || i18n.t('runtime.trace.parallelGroupDefault'),
|
|
499
510
|
itemIds,
|
|
500
511
|
completed: children.filter((item) => item.status === 'completed').length,
|
|
501
512
|
total: children.length,
|
|
@@ -506,16 +517,21 @@ function buildParallelGroups(model, items, maps, allowedEdgeIds) {
|
|
|
506
517
|
return groups;
|
|
507
518
|
}
|
|
508
519
|
|
|
509
|
-
export function createRuntimeTraceProjection({ model, runtime, presentation, options = {} } = {}) {
|
|
520
|
+
export function createRuntimeTraceProjection({ model, runtime, presentation, options = {}, i18n = null, locale, messages } = {}) {
|
|
510
521
|
if (!model) throw new Error('createRuntimeTraceProjection requires model.');
|
|
522
|
+
const translator = resolveI18n({
|
|
523
|
+
i18n: i18n || options?.i18n,
|
|
524
|
+
locale: locale !== undefined ? locale : options?.locale,
|
|
525
|
+
messages: messages !== undefined ? messages : options?.messages,
|
|
526
|
+
});
|
|
511
527
|
const rootModel = getScopeGraph(model, model.id);
|
|
512
|
-
const normalizedSource = normalizeRuntime(runtime);
|
|
528
|
+
const normalizedSource = normalizeRuntime(runtime, { i18n: translator });
|
|
513
529
|
const collapsed = collapseRuntimeToRoot(model, rootModel, normalizedSource);
|
|
514
530
|
const normalized = collapsed.runtime;
|
|
515
531
|
const hasCollapsedActivities = collapsed.activitySources.size > 0;
|
|
516
532
|
const runtimePresentation = !hasCollapsedActivities && presentation
|
|
517
533
|
? presentation
|
|
518
|
-
: createRuntimePresentation({ model: rootModel, runtime: normalized });
|
|
534
|
+
: createRuntimePresentation({ model: rootModel, runtime: normalized, i18n: translator });
|
|
519
535
|
const maps = graphMaps(rootModel);
|
|
520
536
|
const historicalEdgeIds = inferVisitedEdges(rootModel, normalized, maps.outgoing);
|
|
521
537
|
const effectiveVisited = new Set([...historicalEdgeIds].filter((edgeId) => !runtimePresentation.getEdge(edgeId).superseded));
|
|
@@ -537,12 +553,14 @@ export function createRuntimeTraceProjection({ model, runtime, presentation, opt
|
|
|
537
553
|
})).map((node) => node.id));
|
|
538
554
|
const graphModel = buildProjectedGraph({ model: rootModel, visibleIds, allowedEdgeIds, maps });
|
|
539
555
|
const graphRuntime = projectRuntime(normalized, graphModel, runtimePresentation);
|
|
540
|
-
const items = buildVisitItems(rootModel, normalized, runtimePresentation, prediction.nodeIds, prediction.orderedNodeIds, options);
|
|
556
|
+
const items = buildVisitItems(rootModel, normalized, runtimePresentation, prediction.nodeIds, prediction.orderedNodeIds, options, translator);
|
|
541
557
|
const links = buildTimelineLinks(items, maps, historicalEdgeIds, allowedEdgeIds);
|
|
542
|
-
const groups = buildParallelGroups(rootModel, items, maps, allowedEdgeIds);
|
|
558
|
+
const groups = buildParallelGroups(rootModel, items, maps, allowedEdgeIds, translator);
|
|
543
559
|
const warnings = [];
|
|
544
560
|
for (const record of normalizedSource.activities) {
|
|
545
|
-
if (!model.nodes.some((node) => node.id === record.elementId))
|
|
561
|
+
if (!model.nodes.some((node) => node.id === record.elementId)) {
|
|
562
|
+
warnings.push(translator.t('runtime.trace.missingElementWarning', { elementId: record.elementId }));
|
|
563
|
+
}
|
|
546
564
|
}
|
|
547
565
|
const nodeMappings = Object.fromEntries(graphModel.nodes.map((node) => [
|
|
548
566
|
node.id,
|
|
@@ -1,9 +1,18 @@
|
|
|
1
|
+
import { DEFAULT_I18N, resolveI18n } from '../i18n/index.js';
|
|
1
2
|
import { createDefaultIconRegistry, createIconElement } from '../icons/index.js';
|
|
2
3
|
import { formatRuntimeInstant } from '../runtime/index.js';
|
|
3
4
|
import { renderRuntimeApprovalContent } from './runtime-content.js';
|
|
4
5
|
import { renderRuntimeAvatarStack, shouldRenderTimelineAvatars } from './runtime-avatar.js';
|
|
5
6
|
import { applyRuntimeTone } from '../theme/index.js';
|
|
6
7
|
|
|
8
|
+
const RESULT_KEYS = Object.freeze({
|
|
9
|
+
approved: 'timeline.results.approved',
|
|
10
|
+
rejected: 'timeline.results.rejected',
|
|
11
|
+
returned: 'timeline.results.returned',
|
|
12
|
+
submitted: 'timeline.results.submitted',
|
|
13
|
+
pending: 'timeline.results.pending',
|
|
14
|
+
});
|
|
15
|
+
|
|
7
16
|
function element(tag, className, text) {
|
|
8
17
|
const node = document.createElement(tag);
|
|
9
18
|
if (className) node.className = className;
|
|
@@ -27,64 +36,82 @@ function icon(registry, id, className = 'nova-icon nova-icon-md') {
|
|
|
27
36
|
return host;
|
|
28
37
|
}
|
|
29
38
|
|
|
30
|
-
function resultText(item) {
|
|
31
|
-
const
|
|
32
|
-
return
|
|
39
|
+
function resultText(item, i18n = DEFAULT_I18N) {
|
|
40
|
+
const key = RESULT_KEYS[item.outcome];
|
|
41
|
+
return (key ? i18n.t(key) : '') || item.statusLabel || '';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function formatTime(value, field = 'occurred', timeConfig = null) {
|
|
45
|
+
return formatRuntimeInstant(value, {
|
|
46
|
+
formatRuntimeTime: timeConfig?.formatRuntimeTime,
|
|
47
|
+
runtimeTimeFormat: timeConfig?.runtimeTimeFormat,
|
|
48
|
+
surface: 'timeline',
|
|
49
|
+
field,
|
|
50
|
+
locale: timeConfig?.locale || 'zh-CN',
|
|
51
|
+
});
|
|
33
52
|
}
|
|
34
53
|
|
|
35
|
-
function
|
|
36
|
-
|
|
54
|
+
function timelineItemTimeField(item) {
|
|
55
|
+
if (item?.timeField) return item.timeField;
|
|
56
|
+
if (item?.kind === 'transition') return 'occurred';
|
|
57
|
+
if (item?.status === 'active') return 'start';
|
|
58
|
+
return 'end';
|
|
37
59
|
}
|
|
38
60
|
|
|
39
|
-
function renderParticipants(item) {
|
|
61
|
+
function renderParticipants(item, i18n = DEFAULT_I18N) {
|
|
40
62
|
if ((item.participants || []).length < 2) return null;
|
|
41
63
|
const details = element('details', 'mb-runtime-timeline-participants');
|
|
42
|
-
const summary = element('summary', '',
|
|
64
|
+
const summary = element('summary', '', i18n.t('timeline.participantsToggle', { count: item.participants.length }));
|
|
43
65
|
const list = element('div', 'mb-runtime-timeline-participant-list');
|
|
44
66
|
item.participants.forEach((participant) => list.appendChild(element('span', '', participant.name)));
|
|
45
67
|
details.append(summary, list);
|
|
46
68
|
return details;
|
|
47
69
|
}
|
|
48
70
|
|
|
49
|
-
function renderTimelineAction({ container, action, resolveAsset, onAssetPreview, appearance }) {
|
|
71
|
+
function renderTimelineAction({ container, action, resolveAsset, onAssetPreview, appearance, i18n = DEFAULT_I18N, timeConfig = null }) {
|
|
50
72
|
const actionAppearance = appearance?.resolveAction(action) || { label: action.label, tone: 'neutral' };
|
|
51
73
|
const article = element('article', `mb-runtime-timeline-action type-${action.type}`);
|
|
52
74
|
applyRuntimeTone(article, actionAppearance.tone);
|
|
53
75
|
const header = element('header', 'mb-runtime-timeline-action-head');
|
|
54
76
|
header.append(
|
|
55
77
|
element('strong', '', actionAppearance.label),
|
|
56
|
-
element('span', '', [action.actor?.name, formatTime(action.occurredAt)].filter(Boolean).join(' · ')),
|
|
78
|
+
element('span', '', [action.actor?.name, formatTime(action.occurredAt, 'occurred', timeConfig)].filter(Boolean).join(' · ')),
|
|
57
79
|
);
|
|
58
80
|
article.appendChild(header);
|
|
59
|
-
if (action.targets?.length)
|
|
81
|
+
if (action.targets?.length) {
|
|
82
|
+
article.appendChild(element('div', 'mb-runtime-action-targets', i18n.t('timeline.targets', {
|
|
83
|
+
names: action.targets.map((target) => target.name).join(i18n.t('common.listSeparator')),
|
|
84
|
+
})));
|
|
85
|
+
}
|
|
60
86
|
renderRuntimeApprovalContent({
|
|
61
87
|
container: article,
|
|
62
88
|
action,
|
|
63
89
|
resolveAsset,
|
|
64
90
|
compact: true,
|
|
65
91
|
onPreview: onAssetPreview,
|
|
92
|
+
i18n,
|
|
66
93
|
});
|
|
67
94
|
container.appendChild(article);
|
|
68
95
|
}
|
|
69
96
|
|
|
70
|
-
function renderTimelineActions({ item, resolveAsset, onAssetPreview, appearance }) {
|
|
97
|
+
function renderTimelineActions({ item, resolveAsset, onAssetPreview, appearance, i18n = DEFAULT_I18N, timeConfig = null }) {
|
|
71
98
|
const actions = item.actions || [];
|
|
72
99
|
if (!actions.length) return null;
|
|
73
100
|
const host = element('div', 'mb-runtime-timeline-actions');
|
|
74
101
|
const newest = actions.at(-1);
|
|
75
|
-
renderTimelineAction({ container: host, action: newest, resolveAsset, onAssetPreview, appearance });
|
|
102
|
+
renderTimelineAction({ container: host, action: newest, resolveAsset, onAssetPreview, appearance, i18n, timeConfig });
|
|
76
103
|
if (actions.length > 1) {
|
|
77
104
|
const details = element('details', 'mb-runtime-timeline-action-history');
|
|
78
|
-
const summary = element('summary', '',
|
|
105
|
+
const summary = element('summary', '', i18n.t('timeline.earlierActions', { count: actions.length - 1 }));
|
|
79
106
|
const body = element('div', 'mb-runtime-timeline-action-history-body');
|
|
80
|
-
[...actions].slice(0, -1).reverse().forEach((action) => renderTimelineAction({ container: body, action, resolveAsset, onAssetPreview, appearance }));
|
|
107
|
+
[...actions].slice(0, -1).reverse().forEach((action) => renderTimelineAction({ container: body, action, resolveAsset, onAssetPreview, appearance, i18n, timeConfig }));
|
|
81
108
|
details.append(summary, body);
|
|
82
109
|
host.appendChild(details);
|
|
83
110
|
}
|
|
84
111
|
return host;
|
|
85
112
|
}
|
|
86
113
|
|
|
87
|
-
function renderActivityItem({ item, registry, conditionLabel, onItemClick, onDetailsRequest, resolveAsset, onAssetPreview, appearance, compact = false }) {
|
|
114
|
+
function renderActivityItem({ item, registry, conditionLabel, onItemClick, onDetailsRequest, resolveAsset, onAssetPreview, appearance, i18n = DEFAULT_I18N, timeConfig = null, compact = false }) {
|
|
88
115
|
const article = element('article', `mb-runtime-timeline-item status-${item.status}${item.predicted ? ' is-predicted' : ''}${compact ? ' is-group-child' : ''}`);
|
|
89
116
|
applyRuntimeTone(article, appearance?.resolveStatus(item.status));
|
|
90
117
|
article.dataset.traceItemId = item.id;
|
|
@@ -94,13 +121,21 @@ function renderActivityItem({ item, registry, conditionLabel, onItemClick, onDet
|
|
|
94
121
|
const card = element('div', 'mb-runtime-timeline-card');
|
|
95
122
|
const trigger = element('button', 'mb-runtime-timeline-card-main');
|
|
96
123
|
trigger.type = 'button';
|
|
97
|
-
trigger.setAttribute('aria-label',
|
|
124
|
+
trigger.setAttribute('aria-label', i18n.t('timeline.itemAria', {
|
|
125
|
+
name: item.name,
|
|
126
|
+
status: item.statusLabel,
|
|
127
|
+
summary: item.summary,
|
|
128
|
+
comment: item.comment,
|
|
129
|
+
}));
|
|
98
130
|
const heading = element('div', 'mb-runtime-timeline-heading');
|
|
99
131
|
const title = element('strong', '', item.name);
|
|
100
|
-
if (item.round > 1) title.appendChild(element('small', '',
|
|
101
|
-
heading.append(title, element('em', '', resultText(item)));
|
|
132
|
+
if (item.round > 1) title.appendChild(element('small', '', i18n.t('timeline.round', { round: item.round })));
|
|
133
|
+
heading.append(title, element('em', '', resultText(item, i18n)));
|
|
102
134
|
const meta = element('div', 'mb-runtime-timeline-meta');
|
|
103
|
-
meta.append(
|
|
135
|
+
meta.append(
|
|
136
|
+
element('span', '', item.summary || (item.automated ? item.statusLabel : '')),
|
|
137
|
+
element('time', '', formatTime(item.time, timelineItemTimeField(item), timeConfig)),
|
|
138
|
+
);
|
|
104
139
|
const copy = element('div', 'mb-runtime-timeline-card-copy');
|
|
105
140
|
copy.append(heading, meta);
|
|
106
141
|
const avatars = shouldRenderTimelineAvatars(item) ? renderRuntimeAvatarStack(item.participants) : null;
|
|
@@ -115,18 +150,18 @@ function renderActivityItem({ item, registry, conditionLabel, onItemClick, onDet
|
|
|
115
150
|
onDetailsRequest?.(item, event.currentTarget, event);
|
|
116
151
|
});
|
|
117
152
|
card.appendChild(trigger);
|
|
118
|
-
const actions = renderTimelineActions({ item, resolveAsset, onAssetPreview, appearance });
|
|
153
|
+
const actions = renderTimelineActions({ item, resolveAsset, onAssetPreview, appearance, i18n, timeConfig });
|
|
119
154
|
if (actions) card.appendChild(actions);
|
|
120
155
|
const content = element('div', 'mb-runtime-timeline-content');
|
|
121
156
|
if (conditionLabel) content.appendChild(element('span', 'mb-runtime-timeline-condition', conditionLabel));
|
|
122
157
|
content.appendChild(card);
|
|
123
|
-
const participants = renderParticipants(item);
|
|
158
|
+
const participants = renderParticipants(item, i18n);
|
|
124
159
|
if (participants) content.appendChild(participants);
|
|
125
160
|
article.append(rail, content);
|
|
126
161
|
return article;
|
|
127
162
|
}
|
|
128
163
|
|
|
129
|
-
function renderTransitionItem({ item, registry, onItemClick, onTransitionRequest, resolveAsset, onAssetPreview, appearance }) {
|
|
164
|
+
function renderTransitionItem({ item, registry, onItemClick, onTransitionRequest, resolveAsset, onAssetPreview, appearance, i18n = DEFAULT_I18N, timeConfig = null }) {
|
|
130
165
|
const article = element('article', `mb-runtime-timeline-item mb-runtime-timeline-transition type-${item.type}`);
|
|
131
166
|
applyRuntimeTone(article, appearance?.resolveTransition(item).tone);
|
|
132
167
|
article.dataset.traceItemId = item.id;
|
|
@@ -137,7 +172,7 @@ function renderTransitionItem({ item, registry, onItemClick, onTransitionRequest
|
|
|
137
172
|
button.type = 'button';
|
|
138
173
|
button.append(
|
|
139
174
|
element('strong', '', item.name),
|
|
140
|
-
element('span', '', [item.summary, formatTime(item.time)].filter(Boolean).join(' · ')),
|
|
175
|
+
element('span', '', [item.summary, formatTime(item.time, 'occurred', timeConfig)].filter(Boolean).join(' · ')),
|
|
141
176
|
);
|
|
142
177
|
button.addEventListener('click', (event) => {
|
|
143
178
|
onItemClick?.(item, event);
|
|
@@ -146,13 +181,13 @@ function renderTransitionItem({ item, registry, onItemClick, onTransitionRequest
|
|
|
146
181
|
card.appendChild(button);
|
|
147
182
|
const action = item.actions?.[0];
|
|
148
183
|
if (action) {
|
|
149
|
-
renderRuntimeApprovalContent({ container: card, action, resolveAsset, compact: true, onPreview: onAssetPreview });
|
|
184
|
+
renderRuntimeApprovalContent({ container: card, action, resolveAsset, compact: true, onPreview: onAssetPreview, i18n });
|
|
150
185
|
} else if (item.comment) card.appendChild(element('p', 'mb-runtime-action-paragraph', item.comment));
|
|
151
186
|
article.append(rail, card);
|
|
152
187
|
return article;
|
|
153
188
|
}
|
|
154
189
|
|
|
155
|
-
function renderParallelGroup({ group, children, registry, linkByTarget, onItemClick, onDetailsRequest, resolveAsset, onAssetPreview, appearance }) {
|
|
190
|
+
function renderParallelGroup({ group, children, registry, linkByTarget, onItemClick, onDetailsRequest, resolveAsset, onAssetPreview, appearance, i18n = DEFAULT_I18N, timeConfig = null }) {
|
|
156
191
|
const details = element('details', `mb-runtime-timeline-group status-${group.status}`);
|
|
157
192
|
applyRuntimeTone(details, appearance?.resolveStatus(group.status));
|
|
158
193
|
details.dataset.traceGroupId = group.id;
|
|
@@ -160,7 +195,7 @@ function renderParallelGroup({ group, children, registry, linkByTarget, onItemCl
|
|
|
160
195
|
summary.append(
|
|
161
196
|
icon(registry, statusIconId(group.status), 'nova-icon nova-icon-lg'),
|
|
162
197
|
element('strong', '', group.label),
|
|
163
|
-
element('span', '',
|
|
198
|
+
element('span', '', i18n.t('timeline.parallelCompleted', { completed: group.completed, total: group.total })),
|
|
164
199
|
);
|
|
165
200
|
const body = element('div', 'mb-runtime-timeline-group-body');
|
|
166
201
|
children.sort((a, b) => a.order - b.order).forEach((item) => body.appendChild(renderActivityItem({
|
|
@@ -172,6 +207,8 @@ function renderParallelGroup({ group, children, registry, linkByTarget, onItemCl
|
|
|
172
207
|
resolveAsset,
|
|
173
208
|
onAssetPreview,
|
|
174
209
|
appearance,
|
|
210
|
+
i18n,
|
|
211
|
+
timeConfig,
|
|
175
212
|
compact: true,
|
|
176
213
|
})));
|
|
177
214
|
details.append(summary, body);
|
|
@@ -191,10 +228,19 @@ export function renderDefaultRuntimeTimeline({
|
|
|
191
228
|
resolveAsset,
|
|
192
229
|
onAssetPreview,
|
|
193
230
|
appearance,
|
|
231
|
+
i18n = null,
|
|
232
|
+
locale,
|
|
233
|
+
messages,
|
|
234
|
+
formatRuntimeTime = null,
|
|
235
|
+
runtimeTimeFormat = null,
|
|
194
236
|
}) {
|
|
237
|
+
const translator = resolveI18n({ i18n: i18n || appearance?.i18n, locale, messages });
|
|
238
|
+
const timeConfig = { formatRuntimeTime, runtimeTimeFormat, locale: translator.locale };
|
|
195
239
|
const registry = iconRegistry || createDefaultIconRegistry();
|
|
196
240
|
const root = element('section', 'mb-runtime-timeline');
|
|
197
|
-
root.setAttribute('aria-label',
|
|
241
|
+
root.setAttribute('aria-label', translator.t('timeline.ariaLabel', {
|
|
242
|
+
title: title || model.name || translator.t('timeline.fallbackProcessName'),
|
|
243
|
+
}));
|
|
198
244
|
const list = element('div', 'mb-runtime-timeline-list');
|
|
199
245
|
const linkByTarget = new Map(projection.links.map((link) => [link.targetItemId, link]));
|
|
200
246
|
const groupedIds = new Set(projection.groups.flatMap((group) => group.itemIds));
|
|
@@ -215,11 +261,13 @@ export function renderDefaultRuntimeTimeline({
|
|
|
215
261
|
resolveAsset,
|
|
216
262
|
onAssetPreview,
|
|
217
263
|
appearance,
|
|
264
|
+
i18n: translator,
|
|
265
|
+
timeConfig,
|
|
218
266
|
}));
|
|
219
267
|
return;
|
|
220
268
|
}
|
|
221
269
|
if (entry.kind === 'transition') {
|
|
222
|
-
list.appendChild(renderTransitionItem({ item: entry, registry, onItemClick, onTransitionRequest, resolveAsset, onAssetPreview, appearance }));
|
|
270
|
+
list.appendChild(renderTransitionItem({ item: entry, registry, onItemClick, onTransitionRequest, resolveAsset, onAssetPreview, appearance, i18n: translator, timeConfig }));
|
|
223
271
|
return;
|
|
224
272
|
}
|
|
225
273
|
list.appendChild(renderActivityItem({
|
|
@@ -231,9 +279,11 @@ export function renderDefaultRuntimeTimeline({
|
|
|
231
279
|
resolveAsset,
|
|
232
280
|
onAssetPreview,
|
|
233
281
|
appearance,
|
|
282
|
+
i18n: translator,
|
|
283
|
+
timeConfig,
|
|
234
284
|
}));
|
|
235
285
|
});
|
|
236
|
-
if (!sequence.length) list.appendChild(element('div', 'mb-runtime-timeline-empty', '
|
|
286
|
+
if (!sequence.length) list.appendChild(element('div', 'mb-runtime-timeline-empty', translator.t('timeline.empty')));
|
|
237
287
|
if (title !== null || description !== null) {
|
|
238
288
|
const header = element('header', 'mb-runtime-timeline-header');
|
|
239
289
|
if (title !== null) header.appendChild(element('strong', '', title));
|
|
@@ -253,33 +303,50 @@ export class RuntimeTimelineHost {
|
|
|
253
303
|
this.selection = null;
|
|
254
304
|
this._cleanup = null;
|
|
255
305
|
this.container.innerHTML = '';
|
|
306
|
+
this.container.scrollTop = 0;
|
|
256
307
|
this.container.classList.remove('mb-diagram-host');
|
|
257
308
|
this.container.classList.add('mb-runtime-timeline-host');
|
|
309
|
+
const doc = this.container.ownerDocument || document;
|
|
310
|
+
this.scrollContainer = doc.createElement('div');
|
|
311
|
+
this.scrollContainer.className = 'mb-runtime-timeline-scroll';
|
|
312
|
+
this.container.appendChild(this.scrollContainer);
|
|
258
313
|
this.render();
|
|
259
314
|
}
|
|
260
315
|
|
|
316
|
+
getScrollTop() {
|
|
317
|
+
return this.scrollContainer?.scrollTop || 0;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
setScrollTop(value) {
|
|
321
|
+
if (!this.scrollContainer) return;
|
|
322
|
+
this.scrollContainer.scrollTop = Math.max(0, Number(value) || 0);
|
|
323
|
+
}
|
|
324
|
+
|
|
261
325
|
render() {
|
|
262
|
-
|
|
326
|
+
if (!this.scrollContainer) return;
|
|
327
|
+
const scrollTop = this.getScrollTop();
|
|
263
328
|
this._cleanup?.();
|
|
264
|
-
this.
|
|
329
|
+
this.scrollContainer.replaceChildren();
|
|
265
330
|
const renderer = this.options.renderer || renderDefaultRuntimeTimeline;
|
|
266
|
-
this._cleanup = renderer({ container: this.
|
|
267
|
-
this.
|
|
331
|
+
this._cleanup = renderer({ container: this.scrollContainer, iconRegistry: this.iconRegistry, ...this.options }) || null;
|
|
332
|
+
this.setScrollTop(scrollTop);
|
|
268
333
|
}
|
|
269
334
|
|
|
270
335
|
setSelection(selection) {
|
|
271
336
|
this.selection = selection;
|
|
272
|
-
this.
|
|
337
|
+
this.scrollContainer?.querySelectorAll('[data-element-id]').forEach((node) => node.classList.toggle('is-selected', selection?.kind === 'node' && node.dataset.elementId === selection.id));
|
|
273
338
|
}
|
|
274
339
|
|
|
275
|
-
fitView() { this.
|
|
340
|
+
fitView() { this.setScrollTop(0); }
|
|
276
341
|
zoomBy() {}
|
|
277
342
|
actualSize() {}
|
|
278
343
|
|
|
279
344
|
destroy() {
|
|
280
345
|
this._cleanup?.();
|
|
281
346
|
this._cleanup = null;
|
|
282
|
-
this.
|
|
347
|
+
this.scrollContainer?.replaceChildren();
|
|
348
|
+
this.scrollContainer?.remove();
|
|
349
|
+
this.scrollContainer = null;
|
|
283
350
|
this.container.classList.remove('mb-runtime-timeline-host');
|
|
284
351
|
}
|
|
285
352
|
}
|