@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.
Files changed (55) hide show
  1. package/README.md +2 -2
  2. package/dist/canvas.js +97 -25
  3. package/dist/config.js +42 -0
  4. package/dist/context-menu.js +41 -32
  5. package/dist/controller.js +45 -19
  6. package/dist/index.d.ts +59 -2
  7. package/dist/index.js +1 -0
  8. package/dist/interactions.js +6 -1
  9. package/dist/modules/bpmn-model/index.d.ts +2 -1
  10. package/dist/modules/bpmn-model/index.js +12 -10
  11. package/dist/modules/core/gateway.js +16 -13
  12. package/dist/modules/core/index.d.ts +6 -4
  13. package/dist/modules/core/model.js +12 -7
  14. package/dist/modules/designer/index.d.ts +5 -1
  15. package/dist/modules/designer/index.js +36 -15
  16. package/dist/modules/export-svg/index.d.ts +12 -5
  17. package/dist/modules/export-svg/preview.js +34 -24
  18. package/dist/modules/export-svg/render.js +102 -50
  19. package/dist/modules/i18n/index.d.ts +647 -0
  20. package/dist/modules/i18n/index.js +247 -0
  21. package/dist/modules/i18n/locales/en-US.js +823 -0
  22. package/dist/modules/i18n/locales/zh-CN.js +805 -0
  23. package/dist/modules/node-presentation/index.d.ts +3 -2
  24. package/dist/modules/node-presentation/index.js +14 -11
  25. package/dist/modules/palette/index.d.ts +6 -1
  26. package/dist/modules/palette/index.js +26 -8
  27. package/dist/modules/palette/panel.js +44 -6
  28. package/dist/modules/properties/index.d.ts +2 -1
  29. package/dist/modules/properties/index.js +2 -2
  30. package/dist/modules/properties-activiti/index.js +84 -59
  31. package/dist/modules/properties-bpmn/index.js +151 -128
  32. package/dist/modules/properties-core/index.d.ts +9 -3
  33. package/dist/modules/properties-core/index.js +16 -4
  34. package/dist/modules/properties-flowable/index.js +55 -34
  35. package/dist/modules/properties-renderer/index.d.ts +5 -1
  36. package/dist/modules/properties-renderer/index.js +110 -42
  37. package/dist/modules/renderer-svg/index.d.ts +6 -2
  38. package/dist/modules/renderer-svg/index.js +113 -38
  39. package/dist/modules/runtime/index.d.ts +33 -5
  40. package/dist/modules/runtime/index.js +97 -73
  41. package/dist/modules/runtime/time.js +89 -4
  42. package/dist/modules/runtime/visits.js +6 -4
  43. package/dist/modules/theme/index.d.ts +5 -2
  44. package/dist/modules/theme/index.js +8 -4
  45. package/dist/modules/viewer/index.d.ts +28 -7
  46. package/dist/modules/viewer/index.js +213 -56
  47. package/dist/modules/viewer/runtime-content.js +26 -20
  48. package/dist/modules/viewer/runtime-trace.js +43 -25
  49. package/dist/modules/viewer/timeline.js +103 -36
  50. package/dist/shell.js +279 -75
  51. package/dist/sidebars.js +3 -1
  52. package/dist/styles.css +6 -3
  53. package/llms-full.txt +296 -49
  54. package/llms.txt +4 -4
  55. package/package.json +2 -3
package/README.md CHANGED
@@ -4,14 +4,14 @@ BPMN Nova 的 Vanilla JavaScript / TypeScript 完整入口,提供流程设计
4
4
 
5
5
  > **English summary:** The complete framework-neutral BPMN Nova package for process design, viewing, approval traces, themes, properties, and pure SVG export.
6
6
 
7
- > 当前版本为 `0.3.8-preview`。请使用 `@preview` 安装,并在生产接入前验证目标 BPMN XML 与引擎扩展。
7
+ > 当前版本为 `0.4.0`。在生产接入前请验证目标 BPMN XML 与引擎扩展。
8
8
 
9
9
  ![BPMN Nova 流程设计器](https://raw.githubusercontent.com/daxiangme/bpmn-nova/dev/docs/assets/bpmn-nova-designer.jpg)
10
10
 
11
11
  ## 安装
12
12
 
13
13
  ```bash
14
- npm install @bpmn-nova/studio@preview
14
+ npm install @bpmn-nova/studio
15
15
  ```
16
16
 
17
17
  Vanilla JavaScript / TypeScript 项目选择本包;React 18+ 和 Vue 3.3+ 项目分别选择 `@bpmn-nova/react` 或 `@bpmn-nova/vue`。
package/dist/canvas.js CHANGED
@@ -13,6 +13,7 @@ import {
13
13
  } from './modules/core/index.js';
14
14
  import { DiagramRenderer, ZOOM_LIMITS } from './modules/renderer-svg/index.js';
15
15
  import { hydrateIcons } from './modules/icons/index.js';
16
+ import { createI18n, resolveI18n } from './modules/i18n/index.js';
16
17
  import { canCreateSequenceFlow } from './controller.js';
17
18
  import { createDefaultContextMenuRegistry } from './context-menu.js';
18
19
  import { CREATE_INTENT_MIME } from './interactions.js';
@@ -62,11 +63,25 @@ function viewportStateCenteredOn(bounds, viewportRect, zoom) {
62
63
  }
63
64
 
64
65
  export class BpmnCanvas {
65
- constructor({ container, studio, rendererOptions = {}, nodeSubtitleResolver = rendererOptions.nodeSubtitleResolver, interactions = null, selectionToolbar = null, contextMenu = null, contextMenuRegistry = createDefaultContextMenuRegistry(), pointerMode = 'select', themeController = null, theme = null, onThemeChange = null } = {}) {
66
+ constructor({ container, studio, rendererOptions = {}, nodeSubtitleResolver = rendererOptions.nodeSubtitleResolver, interactions = null, selectionToolbar = null, contextMenu = null, contextMenuRegistry = createDefaultContextMenuRegistry(), pointerMode = 'select', themeController = null, theme = null, onThemeChange = null, i18n = null, locale, messages } = {}) {
66
67
  if (!container) throw new Error('BpmnCanvas requires a container.');
67
68
  if (!studio) throw new Error('BpmnCanvas requires a studio controller.');
68
69
  this.container = container;
69
70
  this.studio = studio;
71
+ const hasExplicitLocale = locale !== undefined || messages !== undefined;
72
+ if (i18n) {
73
+ this._ownsI18n = false;
74
+ this.i18n = resolveI18n(i18n);
75
+ } else if (hasExplicitLocale) {
76
+ this._ownsI18n = true;
77
+ this.i18n = createI18n({ locale, messages });
78
+ } else if (studio.i18n) {
79
+ this._ownsI18n = false;
80
+ this.i18n = resolveI18n(studio.i18n);
81
+ } else {
82
+ this._ownsI18n = true;
83
+ this.i18n = createI18n();
84
+ }
70
85
  this.interactions = interactions;
71
86
  this.selectionToolbarSlot = selectionToolbar;
72
87
  this.contextMenuSlot = contextMenu;
@@ -78,6 +93,7 @@ export class BpmnCanvas {
78
93
  const onViewportChange = rendererOptions.onViewportChange;
79
94
  this.renderer = new DiagramRenderer(container, {
80
95
  ...rendererOptions,
96
+ i18n: this.i18n,
81
97
  nodeSubtitleResolver,
82
98
  themeController,
83
99
  theme,
@@ -125,6 +141,7 @@ export class BpmnCanvas {
125
141
  this._buildContextMenu();
126
142
  this.renderer.setSelection(studio.selection);
127
143
  this._offStudio = studio.subscribe((event) => this._onStudioEvent(event));
144
+ this._offI18n = this.i18n.subscribe(() => this._syncLocaleChrome());
128
145
  this._onKeyDown = (event) => this._handleKeyDown(event);
129
146
  this._onKeyUp = (event) => {
130
147
  if (event.code === 'Space') this.renderer.setSpacePressed(false);
@@ -146,27 +163,33 @@ export class BpmnCanvas {
146
163
  this._renderSelectionToolbar();
147
164
  }
148
165
 
166
+ _pointerModeItems() {
167
+ return [
168
+ { mode: 'select', iconId: 'ui.pointer', label: this.i18n.t('canvas.pointerModes.select'), title: this.i18n.t('canvas.pointerModes.selectTitle') },
169
+ { mode: 'marquee', iconId: 'ui.marquee', label: this.i18n.t('canvas.pointerModes.marquee'), title: this.i18n.t('canvas.pointerModes.marqueeTitle') },
170
+ { mode: 'pan', iconId: 'ui.hand', label: this.i18n.t('canvas.pointerModes.pan'), title: this.i18n.t('canvas.pointerModes.panTitle') },
171
+ ];
172
+ }
173
+
149
174
  _buildPointerToolbar() {
150
175
  const toolbar = domNode('div', 'nova-pointer-toolbar');
151
176
  toolbar.setAttribute('role', 'toolbar');
152
- toolbar.setAttribute('aria-label', '画布操作模式');
177
+ toolbar.setAttribute('aria-label', this.i18n.t('canvas.pointerToolbarAria'));
153
178
  toolbar.addEventListener('pointerdown', (event) => event.stopPropagation());
154
179
  this._pointerModeButtons = new Map();
155
- const items = [
156
- { mode: 'select', iconId: 'ui.pointer', label: '单选', title: '单选与移动节点' },
157
- { mode: 'marquee', iconId: 'ui.marquee', label: '框选', title: '拖动空白区域框选节点' },
158
- { mode: 'pan', iconId: 'ui.hand', label: '拖动', title: '拖动画布' },
159
- ];
160
- for (const item of items) {
180
+ this._pointerModeLabels = new Map();
181
+ for (const item of this._pointerModeItems()) {
161
182
  const button = domNode('button', 'nova-pointer-mode');
162
183
  button.type = 'button';
163
184
  button.dataset.pointerMode = item.mode;
164
185
  button.title = item.title;
165
186
  button.setAttribute('aria-label', item.title);
166
- button.append(toolbarIcon(item.iconId), domNode('span', '', item.label));
187
+ const labelEl = domNode('span', '', item.label);
188
+ button.append(toolbarIcon(item.iconId), labelEl);
167
189
  button.addEventListener('click', () => this.setPointerMode(item.mode));
168
190
  toolbar.appendChild(button);
169
191
  this._pointerModeButtons.set(item.mode, button);
192
+ this._pointerModeLabels.set(item.mode, labelEl);
170
193
  }
171
194
  this._pointerToolbar = toolbar;
172
195
  this.container.appendChild(toolbar);
@@ -174,6 +197,32 @@ export class BpmnCanvas {
174
197
  this.setPointerMode(this.pointerMode);
175
198
  }
176
199
 
200
+ _syncLocaleChrome() {
201
+ if (this._pointerToolbar) {
202
+ this._pointerToolbar.setAttribute('aria-label', this.i18n.t('canvas.pointerToolbarAria'));
203
+ for (const item of this._pointerModeItems()) {
204
+ const button = this._pointerModeButtons?.get(item.mode);
205
+ const labelEl = this._pointerModeLabels?.get(item.mode);
206
+ if (button) {
207
+ button.title = item.title;
208
+ button.setAttribute('aria-label', item.title);
209
+ }
210
+ if (labelEl) labelEl.textContent = item.label;
211
+ }
212
+ }
213
+ if (this._contextMenu) {
214
+ this._contextMenu.setAttribute('aria-label', this.i18n.t('contextMenu.ariaLabel'));
215
+ if (!this._contextMenu.hidden && this._contextMenuState) {
216
+ const { target, position, keyboard } = this._contextMenuState;
217
+ this._openContextMenu(target, position, keyboard);
218
+ }
219
+ }
220
+ if (this._selectionToolbar) {
221
+ this._selectionToolbar.setAttribute('aria-label', this.i18n.t('canvas.selectionToolbarAria'));
222
+ this._renderSelectionToolbar();
223
+ }
224
+ }
225
+
177
226
  setPointerMode(mode) {
178
227
  if (!['select', 'marquee', 'pan'].includes(mode)) return false;
179
228
  this.pointerMode = mode;
@@ -193,7 +242,7 @@ export class BpmnCanvas {
193
242
  this._contextMenu = domNode('div', 'nova-context-menu');
194
243
  this._contextMenu.hidden = true;
195
244
  this._contextMenu.setAttribute('role', 'menu');
196
- this._contextMenu.setAttribute('aria-label', '画布快捷操作');
245
+ this._contextMenu.setAttribute('aria-label', this.i18n.t('contextMenu.ariaLabel'));
197
246
  this._contextMenu.addEventListener('pointerdown', (event) => event.stopPropagation());
198
247
  this._contextMenu.addEventListener('contextmenu', (event) => event.preventDefault());
199
248
  this._contextMenu.addEventListener('keydown', (event) => this._handleContextMenuKeyDown(event));
@@ -262,7 +311,7 @@ export class BpmnCanvas {
262
311
  this.closeContextMenu();
263
312
  this._selectionToolbar?.querySelectorAll('details[open]').forEach((details) => { details.open = false; });
264
313
  this.renderer.closeTransientOverlays?.();
265
- const context = { studio: this.studio, canvas: this, target, selection: this.studio.selection, position };
314
+ const context = { studio: this.studio, canvas: this, i18n: this.i18n, target, selection: this.studio.selection, position };
266
315
  const actions = this.contextMenuRegistry?.resolve?.(context) || [];
267
316
  if (!actions.length) return false;
268
317
  this._contextMenuState = { ...context, actions, keyboard };
@@ -288,9 +337,9 @@ export class BpmnCanvas {
288
337
 
289
338
  _renderDefaultContextMenu(actions) {
290
339
  const submenuGroups = {
291
- align: { label: '对齐', iconId: 'ui.alignCenterHorizontal' },
292
- distribute: { label: '等距分布', iconId: 'ui.distributeHorizontal' },
293
- pointer: { label: '操作模式', iconId: 'ui.pointer' },
340
+ align: { label: this.i18n.t('contextMenu.groups.align'), iconId: 'ui.alignCenterHorizontal' },
341
+ distribute: { label: this.i18n.t('contextMenu.groups.distribute'), iconId: 'ui.distributeHorizontal' },
342
+ pointer: { label: this.i18n.t('contextMenu.groups.pointer'), iconId: 'ui.pointer' },
294
343
  };
295
344
  let previousGroup = null;
296
345
  for (let index = 0; index < actions.length;) {
@@ -455,7 +504,7 @@ export class BpmnCanvas {
455
504
  this._selectionToolbar = domNode('div', 'nova-selection-toolbar');
456
505
  this._selectionToolbar.hidden = true;
457
506
  this._selectionToolbar.setAttribute('role', 'toolbar');
458
- this._selectionToolbar.setAttribute('aria-label', '选区布局工具栏');
507
+ this._selectionToolbar.setAttribute('aria-label', this.i18n.t('canvas.selectionToolbarAria'));
459
508
  this._selectionToolbar.addEventListener('pointerdown', (event) => event.stopPropagation());
460
509
  this.container.appendChild(this._selectionToolbar);
461
510
  }
@@ -495,6 +544,7 @@ export class BpmnCanvas {
495
544
  container: this._selectionToolbar,
496
545
  studio: this.studio,
497
546
  canvas: this,
547
+ i18n: this.i18n,
498
548
  selection: this.studio.selection,
499
549
  elements: diagramNodes,
500
550
  bounds,
@@ -542,23 +592,29 @@ export class BpmnCanvas {
542
592
  };
543
593
  const separator = () => domNode('span', 'nova-selection-separator');
544
594
  const alignmentItems = [
545
- ['left', 'ui.alignLeft', '左对齐'], ['centerX', 'ui.alignCenterHorizontal', '水平居中'], ['right', 'ui.alignRight', '右对齐'],
546
- ['top', 'ui.alignTop', '顶部对齐'], ['centerY', 'ui.alignCenterVertical', '垂直居中'], ['bottom', 'ui.alignBottom', '底部对齐'],
595
+ ['left', 'ui.alignLeft', this.i18n.t('contextMenu.actions.alignLeft')],
596
+ ['centerX', 'ui.alignCenterHorizontal', this.i18n.t('contextMenu.actions.alignCenterX')],
597
+ ['right', 'ui.alignRight', this.i18n.t('contextMenu.actions.alignRight')],
598
+ ['top', 'ui.alignTop', this.i18n.t('contextMenu.actions.alignTop')],
599
+ ['centerY', 'ui.alignCenterVertical', this.i18n.t('contextMenu.actions.alignCenterY')],
600
+ ['bottom', 'ui.alignBottom', this.i18n.t('contextMenu.actions.alignBottom')],
547
601
  ].map(([value, iconId, title]) => ({ id: `align-${value}`, iconId, title, action: () => actions.align(value) }));
548
602
  const distributeItems = [
549
- { id: 'distribute-horizontal', iconId: 'ui.distributeHorizontal', title: '水平等距', action: () => actions.distribute('horizontal'), disabled: nodes.length < 3 },
550
- { id: 'distribute-vertical', iconId: 'ui.distributeVertical', title: '垂直等距', action: () => actions.distribute('vertical'), disabled: nodes.length < 3 },
603
+ { id: 'distribute-horizontal', iconId: 'ui.distributeHorizontal', title: this.i18n.t('contextMenu.actions.distributeHorizontal'), action: () => actions.distribute('horizontal'), disabled: nodes.length < 3 },
604
+ { id: 'distribute-vertical', iconId: 'ui.distributeVertical', title: this.i18n.t('contextMenu.actions.distributeVertical'), action: () => actions.distribute('vertical'), disabled: nodes.length < 3 },
551
605
  ];
606
+ const groupLabel = this.i18n.t('canvas.selectionActions.group');
607
+ const layoutLabel = this.i18n.t('canvas.selectionActions.layout');
552
608
  this._selectionToolbar.append(
553
- button('group', 'ui.layoutSelection', '创建分组', actions.group, { label: '创建分组', disabled: this.studio.allowsNodeType?.('group') === false || !groupableNodes.length || groupableNodes.length !== diagramNodes.length }),
609
+ button('group', 'ui.layoutSelection', groupLabel, actions.group, { label: groupLabel, disabled: this.studio.allowsNodeType?.('group') === false || !groupableNodes.length || groupableNodes.length !== diagramNodes.length }),
554
610
  separator(),
555
- menu('align', 'ui.alignCenterHorizontal', '对齐选区', alignmentItems, nodes.length < 2),
556
- menu('distribute', 'ui.distributeHorizontal', '等距分布', distributeItems, nodes.length < 3),
611
+ menu('align', 'ui.alignCenterHorizontal', this.i18n.t('canvas.selectionActions.align'), alignmentItems, nodes.length < 2),
612
+ menu('distribute', 'ui.distributeHorizontal', this.i18n.t('canvas.selectionActions.distribute'), distributeItems, nodes.length < 3),
557
613
  separator(),
558
- button('layout', 'ui.layoutSelection', '美化选区', actions.layout, { label: '美化选区', disabled: nodes.length < 2 }),
559
- button('reroute', 'ui.rerouteSelection', '优化选区连线', actions.reroute, { disabled: nodes.length < 1 }),
614
+ button('layout', 'ui.layoutSelection', layoutLabel, actions.layout, { label: layoutLabel, disabled: nodes.length < 2 }),
615
+ button('reroute', 'ui.rerouteSelection', this.i18n.t('canvas.selectionActions.reroute'), actions.reroute, { disabled: nodes.length < 1 }),
560
616
  separator(),
561
- button('fit', 'ui.fitSelection', '适应选区', actions.fit),
617
+ button('fit', 'ui.fitSelection', this.i18n.t('canvas.selectionActions.fit'), actions.fit),
562
618
  );
563
619
  hydrateIcons(this._selectionToolbar, this.renderer.iconRegistry);
564
620
  this._positionSelectionToolbar();
@@ -995,8 +1051,24 @@ export class BpmnCanvas {
995
1051
  setTheme(theme) { return this.renderer.setTheme(theme); }
996
1052
  setThemeMode(mode) { return this.renderer.setThemeMode(mode); }
997
1053
  getThemeState() { return this.renderer.getThemeState(); }
1054
+ setLocale(locale, messages) {
1055
+ if (!this._ownsI18n) {
1056
+ this._offI18n?.();
1057
+ this.i18n = createI18n({ locale, messages });
1058
+ this._ownsI18n = true;
1059
+ this._offI18n = this.i18n.subscribe(() => this._syncLocaleChrome());
1060
+ this.renderer.setLocale(locale, messages);
1061
+ this._syncLocaleChrome();
1062
+ } else {
1063
+ this.i18n.setLocale(locale, messages);
1064
+ }
1065
+ return this.getLocale();
1066
+ }
1067
+ getLocale() { return this.i18n.getState(); }
998
1068
  destroy() {
999
1069
  this._offStudio?.();
1070
+ this._offI18n?.();
1071
+ this._offI18n = null;
1000
1072
  this.container.removeEventListener('keydown', this._onKeyDown);
1001
1073
  this.container.removeEventListener('keyup', this._onKeyUp);
1002
1074
  this.container.removeEventListener('dragover', this._onDragOver);
package/dist/config.js CHANGED
@@ -159,6 +159,34 @@ export function normalizeStudioRegions(regions, current = DEFAULT_STUDIO_SHELL_R
159
159
  return { ...current, ...regions };
160
160
  }
161
161
 
162
+ const CANVAS_HEAD_KEYS = Object.freeze(['editingMode', 'scopePath']);
163
+ const CANVAS_HEAD_SCOPE_PATHS = Object.freeze(['always', 'nested']);
164
+
165
+ export const DEFAULT_STUDIO_CANVAS_HEAD = Object.freeze({
166
+ editingMode: true,
167
+ scopePath: 'always',
168
+ });
169
+
170
+ export function normalizeStudioCanvasHead(value) {
171
+ if (value === undefined || value === null) return DEFAULT_STUDIO_CANVAS_HEAD;
172
+ assertObject(value, 'config.ui.canvasHead');
173
+ for (const key of Object.keys(value)) {
174
+ if (!CANVAS_HEAD_KEYS.includes(key)) {
175
+ throw new TypeError(`config.ui.canvasHead contains unknown option "${key}"; expected editingMode or scopePath.`);
176
+ }
177
+ }
178
+ if (value.editingMode !== undefined && typeof value.editingMode !== 'boolean') {
179
+ throw new TypeError('config.ui.canvasHead.editingMode must be a boolean.');
180
+ }
181
+ if (value.scopePath !== undefined && !CANVAS_HEAD_SCOPE_PATHS.includes(value.scopePath)) {
182
+ throw new TypeError('config.ui.canvasHead.scopePath must be "always" or "nested".');
183
+ }
184
+ return Object.freeze({
185
+ editingMode: value.editingMode ?? DEFAULT_STUDIO_CANVAS_HEAD.editingMode,
186
+ scopePath: value.scopePath ?? DEFAULT_STUDIO_CANVAS_HEAD.scopePath,
187
+ });
188
+ }
189
+
162
190
  function normalizeProjectionOptions(value) {
163
191
  if (value === undefined || value === null) return undefined;
164
192
  if (!Array.isArray(value)) throw new TypeError('config.viewer.projectionOptions must be a readonly array.');
@@ -211,6 +239,8 @@ function applyLegacyConfig(target, legacy) {
211
239
  timeline: ['viewer', 'timeline'],
212
240
  runtimeDetails: ['viewer', 'runtimeDetails'],
213
241
  runtimeTraceOptions: ['viewer', 'runtimeTraceOptions'],
242
+ formatRuntimeTime: ['viewer', 'formatRuntimeTime'],
243
+ runtimeTimeFormat: ['viewer', 'runtimeTimeFormat'],
214
244
  })) {
215
245
  if (hasOwn(legacy, key) && legacy[key] !== undefined) assignPath(target, path[0], path[1], legacy[key]);
216
246
  }
@@ -251,6 +281,7 @@ export function normalizeStudioConfig(config, { fallback = null, legacy = null }
251
281
  regions: Object.freeze(normalizeStudioRegions(uiInput.regions, {})),
252
282
  leftPanel: normalizeSidebarConfig(uiInput.leftPanel, 'left'),
253
283
  rightPanel: normalizeSidebarConfig(uiInput.rightPanel, 'right'),
284
+ canvasHead: normalizeStudioCanvasHead(uiInput.canvasHead),
254
285
  sidebarWidth: Object.freeze({
255
286
  left: normalizeSidebarWidth(leftWidth, 244, 'config.ui.sidebarWidth.left'),
256
287
  right: normalizeSidebarWidth(rightWidth, 360, 'config.ui.sidebarWidth.right'),
@@ -260,12 +291,23 @@ export function normalizeStudioConfig(config, { fallback = null, legacy = null }
260
291
  const timeline = optionalObject(viewerInput.timeline, 'config.viewer.timeline');
261
292
  const runtimeDetails = optionalObject(viewerInput.runtimeDetails, 'config.viewer.runtimeDetails');
262
293
  const runtimeTraceOptions = optionalObject(viewerInput.runtimeTraceOptions, 'config.viewer.runtimeTraceOptions');
294
+ const formatRuntimeTime = viewerInput.formatRuntimeTime === undefined || viewerInput.formatRuntimeTime === null
295
+ ? undefined
296
+ : viewerInput.formatRuntimeTime;
297
+ if (formatRuntimeTime !== undefined && typeof formatRuntimeTime !== 'function') {
298
+ throw new TypeError('config.viewer.formatRuntimeTime must be a function.');
299
+ }
300
+ const runtimeTimeFormat = viewerInput.runtimeTimeFormat === undefined || viewerInput.runtimeTimeFormat === null
301
+ ? undefined
302
+ : optionalObject(viewerInput.runtimeTimeFormat, 'config.viewer.runtimeTimeFormat');
263
303
  const viewer = {
264
304
  responsive,
265
305
  ...(projectionOptions ? { projectionOptions } : {}),
266
306
  ...(timeline ? { timeline } : {}),
267
307
  ...(runtimeDetails ? { runtimeDetails } : {}),
268
308
  ...(runtimeTraceOptions ? { runtimeTraceOptions } : {}),
309
+ ...(formatRuntimeTime ? { formatRuntimeTime } : {}),
310
+ ...(runtimeTimeFormat ? { runtimeTimeFormat } : {}),
269
311
  };
270
312
  const exportOptions = merged.export === undefined || merged.export === null
271
313
  ? undefined
@@ -4,6 +4,7 @@ import {
4
4
  getNode,
5
5
  isEmbeddedSubProcess,
6
6
  } from './modules/core/index.js';
7
+ import { resolveI18n } from './modules/i18n/index.js';
7
8
  import { selectedDiagramNodes, selectedGroupableNodes, selectedLayoutNodes } from './selection-layout.js';
8
9
 
9
10
  function insert(actions, action) {
@@ -36,18 +37,24 @@ function action(config) {
36
37
 
37
38
  const flowKinds = new Set(['event', 'boundary', 'task', 'container', 'gateway']);
38
39
 
39
- function canvasActions() {
40
+ function contextI18n(context) {
41
+ return resolveI18n(context?.i18n || context?.studio?.i18n || context);
42
+ }
43
+
44
+ function canvasActions(context) {
45
+ const i18n = contextI18n(context);
40
46
  return [
41
- action({ id: 'canvas.fit', label: '最佳视图', iconId: 'ui.fitView', execute: ({ canvas }) => canvas.fitView(72) }),
42
- action({ id: 'canvas.beautify', label: '美化当前流程', iconId: 'ui.magic', execute: ({ studio }) => studio.commands.beautify() }),
43
- action({ id: 'canvas.reroute', label: '优化全部连线', iconId: 'ui.rerouteSelection', execute: ({ studio }) => studio.commands.rerouteEdges() }),
44
- action({ id: 'pointer.select', label: '单选', iconId: 'ui.pointer', group: 'pointer', execute: ({ canvas }) => canvas.setPointerMode('select') }),
45
- action({ id: 'pointer.marquee', label: '框选', iconId: 'ui.marquee', group: 'pointer', execute: ({ canvas }) => canvas.setPointerMode('marquee') }),
46
- action({ id: 'pointer.pan', label: '拖动', iconId: 'ui.hand', group: 'pointer', execute: ({ canvas }) => canvas.setPointerMode('pan') }),
47
+ action({ id: 'canvas.fit', label: i18n.t('contextMenu.actions.canvasFit'), iconId: 'ui.fitView', execute: ({ canvas }) => canvas.fitView(72) }),
48
+ action({ id: 'canvas.beautify', label: i18n.t('contextMenu.actions.canvasBeautify'), iconId: 'ui.magic', execute: ({ studio }) => studio.commands.beautify() }),
49
+ action({ id: 'canvas.reroute', label: i18n.t('contextMenu.actions.canvasReroute'), iconId: 'ui.rerouteSelection', execute: ({ studio }) => studio.commands.rerouteEdges() }),
50
+ action({ id: 'pointer.select', label: i18n.t('contextMenu.actions.pointerSelect'), iconId: 'ui.pointer', group: 'pointer', execute: ({ canvas }) => canvas.setPointerMode('select') }),
51
+ action({ id: 'pointer.marquee', label: i18n.t('contextMenu.actions.pointerMarquee'), iconId: 'ui.marquee', group: 'pointer', execute: ({ canvas }) => canvas.setPointerMode('marquee') }),
52
+ action({ id: 'pointer.pan', label: i18n.t('contextMenu.actions.pointerPan'), iconId: 'ui.hand', group: 'pointer', execute: ({ canvas }) => canvas.setPointerMode('pan') }),
47
53
  ];
48
54
  }
49
55
 
50
56
  function nodeActions(context) {
57
+ const i18n = contextI18n(context);
51
58
  const node = getNode(context.studio.model, context.target.id);
52
59
  if (!node) return [];
53
60
  const definition = NODE_DEFINITIONS[node.type] || NODE_DEFINITIONS.generic;
@@ -55,62 +62,64 @@ function nodeActions(context) {
55
62
  const actions = [];
56
63
  if (canOutgoing) {
57
64
  actions.push(
58
- action({ id: 'node.quickAdd', label: '快捷添加下一节点', iconId: 'ui.add', execute: ({ canvas, target }) => canvas.openQuickAdd(target.id) }),
59
- action({ id: 'node.connect', label: '连接已有节点', iconId: 'ui.connect', execute: ({ canvas, target }) => canvas.startConnect(target.id) }),
65
+ action({ id: 'node.quickAdd', label: i18n.t('contextMenu.actions.nodeQuickAdd'), iconId: 'ui.add', execute: ({ canvas, target }) => canvas.openQuickAdd(target.id) }),
66
+ action({ id: 'node.connect', label: i18n.t('contextMenu.actions.nodeConnect'), iconId: 'ui.connect', execute: ({ canvas, target }) => canvas.startConnect(target.id) }),
60
67
  );
61
68
  }
62
69
  if (isEmbeddedSubProcess(node)) {
63
- actions.push(action({ id: 'node.enterScope', label: '进入子流程', iconId: 'ui.enterScope', group: 'navigation', execute: ({ studio, target }) => studio.enterScope(target.id) }));
70
+ actions.push(action({ id: 'node.enterScope', label: i18n.t('contextMenu.actions.nodeEnterScope'), iconId: 'ui.enterScope', group: 'navigation', execute: ({ studio, target }) => studio.enterScope(target.id) }));
64
71
  }
65
72
  if (definition.kind === 'group') {
66
- actions.push(action({ id: 'node.ungroup', label: '取消分组', iconId: 'ui.layoutSelection', execute: ({ studio, target }) => studio.commands.ungroup(target.id) }));
73
+ actions.push(action({ id: 'node.ungroup', label: i18n.t('contextMenu.actions.nodeUngroup'), iconId: 'ui.layoutSelection', execute: ({ studio, target }) => studio.commands.ungroup(target.id) }));
67
74
  return actions;
68
75
  }
69
- actions.push(action({ id: 'selection.delete', label: '删除节点', iconId: 'ui.delete', group: 'danger', danger: true, execute: ({ studio, target }) => studio.commands.remove(target) }));
76
+ actions.push(action({ id: 'selection.delete', label: i18n.t('contextMenu.actions.nodeDelete'), iconId: 'ui.delete', group: 'danger', danger: true, execute: ({ studio, target }) => studio.commands.remove(target) }));
70
77
  return actions;
71
78
  }
72
79
 
73
80
  function edgeActions(context) {
81
+ const i18n = contextI18n(context);
74
82
  const edge = getEdge(context.studio.model, context.target.id);
75
83
  if (!edge) return [];
76
84
  return [
77
- action({ id: 'edge.rename', label: '编辑连线名称', iconId: 'ui.edit', execute: ({ canvas, target }) => canvas.editEdgeName(target.id) }),
78
- action({ id: 'edge.resetRoute', label: '恢复自动路由', iconId: 'ui.rerouteSelection', disabled: !edge.waypoints?.length, execute: ({ studio, target }) => studio.commands.resetEdgeRoute(target.id) }),
79
- action({ id: 'edge.locateSource', label: '定位起点', iconId: 'ui.locateSource', group: 'navigation', execute: ({ studio }) => studio.select({ kind: 'node', id: edge.source }) }),
80
- action({ id: 'edge.locateTarget', label: '定位终点', iconId: 'ui.locateTarget', group: 'navigation', execute: ({ studio }) => studio.select({ kind: 'node', id: edge.target }) }),
81
- action({ id: 'selection.delete', label: '删除连线', iconId: 'ui.delete', group: 'danger', danger: true, execute: ({ studio, target }) => studio.commands.remove(target) }),
85
+ action({ id: 'edge.rename', label: i18n.t('contextMenu.actions.edgeRename'), iconId: 'ui.edit', execute: ({ canvas, target }) => canvas.editEdgeName(target.id) }),
86
+ action({ id: 'edge.resetRoute', label: i18n.t('contextMenu.actions.edgeResetRoute'), iconId: 'ui.rerouteSelection', disabled: !edge.waypoints?.length, execute: ({ studio, target }) => studio.commands.resetEdgeRoute(target.id) }),
87
+ action({ id: 'edge.locateSource', label: i18n.t('contextMenu.actions.edgeLocateSource'), iconId: 'ui.locateSource', group: 'navigation', execute: ({ studio }) => studio.select({ kind: 'node', id: edge.source }) }),
88
+ action({ id: 'edge.locateTarget', label: i18n.t('contextMenu.actions.edgeLocateTarget'), iconId: 'ui.locateTarget', group: 'navigation', execute: ({ studio }) => studio.select({ kind: 'node', id: edge.target }) }),
89
+ action({ id: 'selection.delete', label: i18n.t('contextMenu.actions.edgeDelete'), iconId: 'ui.delete', group: 'danger', danger: true, execute: ({ studio, target }) => studio.commands.remove(target) }),
82
90
  ];
83
91
  }
84
92
 
85
93
  const alignments = [
86
- ['left', '左对齐', 'ui.alignLeft'],
87
- ['centerX', '水平居中', 'ui.alignCenterHorizontal'],
88
- ['right', '右对齐', 'ui.alignRight'],
89
- ['top', '顶部对齐', 'ui.alignTop'],
90
- ['centerY', '垂直居中', 'ui.alignCenterVertical'],
91
- ['bottom', '底部对齐', 'ui.alignBottom'],
94
+ ['left', 'contextMenu.actions.alignLeft', 'ui.alignLeft'],
95
+ ['centerX', 'contextMenu.actions.alignCenterX', 'ui.alignCenterHorizontal'],
96
+ ['right', 'contextMenu.actions.alignRight', 'ui.alignRight'],
97
+ ['top', 'contextMenu.actions.alignTop', 'ui.alignTop'],
98
+ ['centerY', 'contextMenu.actions.alignCenterY', 'ui.alignCenterVertical'],
99
+ ['bottom', 'contextMenu.actions.alignBottom', 'ui.alignBottom'],
92
100
  ];
93
101
 
94
102
  function multiActions(context) {
103
+ const i18n = contextI18n(context);
95
104
  const nodes = selectedLayoutNodes(context.studio.model, context.selection, context.studio.activeScopeId);
96
105
  const diagramNodes = selectedDiagramNodes(context.studio.model, context.selection, context.studio.activeScopeId);
97
106
  const groupableNodes = selectedGroupableNodes(context.studio.model, context.selection, context.studio.activeScopeId);
98
- const actions = alignments.map(([alignment, label, iconId]) => action({
107
+ const actions = alignments.map(([alignment, labelKey, iconId]) => action({
99
108
  id: `selection.align.${alignment}`,
100
- label,
109
+ label: i18n.t(labelKey),
101
110
  iconId,
102
111
  group: 'align',
103
112
  disabled: nodes.length < 2,
104
113
  execute: ({ studio }) => studio.arrangeSelection({ type: 'align', alignment }),
105
114
  }));
106
115
  actions.push(
107
- action({ id: 'selection.group', label: '创建分组', iconId: 'ui.layoutSelection', group: 'layout', disabled: context.studio.allowsNodeType?.('group') === false || !groupableNodes.length || groupableNodes.length !== diagramNodes.length, execute: ({ studio }) => studio.commands.groupSelection() }),
108
- action({ id: 'selection.distribute.horizontal', label: '水平等距', iconId: 'ui.distributeHorizontal', group: 'distribute', disabled: nodes.length < 3, execute: ({ studio }) => studio.arrangeSelection({ type: 'distribute', axis: 'horizontal' }) }),
109
- action({ id: 'selection.distribute.vertical', label: '垂直等距', iconId: 'ui.distributeVertical', group: 'distribute', disabled: nodes.length < 3, execute: ({ studio }) => studio.arrangeSelection({ type: 'distribute', axis: 'vertical' }) }),
110
- action({ id: 'selection.layout', label: '美化选区', iconId: 'ui.layoutSelection', group: 'layout', disabled: nodes.length < 2, execute: ({ studio }) => studio.arrangeSelection({ type: 'layout' }) }),
111
- action({ id: 'selection.reroute', label: '优化关联连线', iconId: 'ui.rerouteSelection', group: 'layout', disabled: nodes.length < 1, execute: ({ studio }) => studio.arrangeSelection({ type: 'reroute' }) }),
112
- action({ id: 'selection.fit', label: '适应选区', iconId: 'ui.fitSelection', group: 'layout', disabled: nodes.length < 1, execute: ({ canvas }) => canvas.fitSelection() }),
113
- action({ id: 'selection.delete', label: '删除选区', iconId: 'ui.delete', group: 'danger', danger: true, execute: ({ studio, selection }) => studio.commands.remove(selection) }),
116
+ action({ id: 'selection.group', label: i18n.t('contextMenu.actions.selectionGroup'), iconId: 'ui.layoutSelection', group: 'layout', disabled: context.studio.allowsNodeType?.('group') === false || !groupableNodes.length || groupableNodes.length !== diagramNodes.length, execute: ({ studio }) => studio.commands.groupSelection() }),
117
+ action({ id: 'selection.distribute.horizontal', label: i18n.t('contextMenu.actions.distributeHorizontal'), iconId: 'ui.distributeHorizontal', group: 'distribute', disabled: nodes.length < 3, execute: ({ studio }) => studio.arrangeSelection({ type: 'distribute', axis: 'horizontal' }) }),
118
+ action({ id: 'selection.distribute.vertical', label: i18n.t('contextMenu.actions.distributeVertical'), iconId: 'ui.distributeVertical', group: 'distribute', disabled: nodes.length < 3, execute: ({ studio }) => studio.arrangeSelection({ type: 'distribute', axis: 'vertical' }) }),
119
+ action({ id: 'selection.layout', label: i18n.t('contextMenu.actions.selectionLayout'), iconId: 'ui.layoutSelection', group: 'layout', disabled: nodes.length < 2, execute: ({ studio }) => studio.arrangeSelection({ type: 'layout' }) }),
120
+ action({ id: 'selection.reroute', label: i18n.t('contextMenu.actions.selectionReroute'), iconId: 'ui.rerouteSelection', group: 'layout', disabled: nodes.length < 1, execute: ({ studio }) => studio.arrangeSelection({ type: 'reroute' }) }),
121
+ action({ id: 'selection.fit', label: i18n.t('contextMenu.actions.selectionFit'), iconId: 'ui.fitSelection', group: 'layout', disabled: nodes.length < 1, execute: ({ canvas }) => canvas.fitSelection() }),
122
+ action({ id: 'selection.delete', label: i18n.t('contextMenu.actions.selectionDelete'), iconId: 'ui.delete', group: 'danger', danger: true, execute: ({ studio, selection }) => studio.commands.remove(selection) }),
114
123
  );
115
124
  return actions;
116
125
  }