@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
@@ -27,6 +27,7 @@ import {
27
27
  validateParallelGateway,
28
28
  } from './modules/core/index.js';
29
29
  import { exportBpmn, importBpmn } from './modules/bpmn-model/index.js';
30
+ import { createI18n, resolveI18n } from './modules/i18n/index.js';
30
31
  import {
31
32
  applySelectionArrangement,
32
33
  mergeSelectionRefs,
@@ -96,6 +97,9 @@ export class BpmnStudioController {
96
97
  allowedNodeTypes,
97
98
  allowedEdgeTypes,
98
99
  config,
100
+ i18n = null,
101
+ locale,
102
+ messages,
99
103
  } = options;
100
104
  if (!model) throw new Error('BpmnStudioController requires a model.');
101
105
  const legacy = {};
@@ -103,6 +107,8 @@ export class BpmnStudioController {
103
107
  if (Object.prototype.hasOwnProperty.call(options, 'allowedNodeTypes')) legacy.allowedNodeTypes = allowedNodeTypes;
104
108
  if (Object.prototype.hasOwnProperty.call(options, 'allowedEdgeTypes')) legacy.allowedEdgeTypes = allowedEdgeTypes;
105
109
  const normalizedConfig = normalizeStudioConfig(config, { legacy });
110
+ this._ownsI18n = !i18n;
111
+ this.i18n = i18n ? resolveI18n(i18n) : createI18n({ locale, messages });
106
112
  this._allowedNodeTypes = normalizeAllowedNodeTypes(normalizedConfig.modeling.allowedNodeTypes);
107
113
  this._allowedEdgeTypes = normalizeAllowedEdgeTypes(normalizedConfig.modeling.allowedEdgeTypes);
108
114
  this._nodeLimits = normalizedConfig.modeling.nodeLimits || null;
@@ -150,10 +156,22 @@ export class BpmnStudioController {
150
156
  redo: () => this.redo(),
151
157
  });
152
158
  for (const extension of extensions) this.registerExtension(extension);
159
+ this._offI18n = this.i18n.subscribe((state) => {
160
+ this._emit('localeChanged', { locale: state.locale, resolvedLocale: state.resolvedLocale });
161
+ });
153
162
  }
154
163
 
155
164
  get model() { return this._model; }
156
165
 
166
+ setLocale(locale, messages) {
167
+ this.i18n.setLocale(locale, messages);
168
+ return this.getLocale();
169
+ }
170
+
171
+ getLocale() {
172
+ return this.i18n.getState();
173
+ }
174
+
157
175
  allowsNodeType(nodeType) {
158
176
  return Boolean(NODE_DEFINITIONS[nodeType])
159
177
  && nodeType !== 'generic'
@@ -191,7 +209,11 @@ export class BpmnStudioController {
191
209
  nodeLimitReason(nodeType, count = 1) {
192
210
  const limit = this._nodeLimits?.[nodeType];
193
211
  if (!limit || this._countNodesOfType(nodeType) + count <= limit.max) return null;
194
- return `最多 ${limit.max} 个${NODE_DEFINITIONS[nodeType]?.label || nodeType}`;
212
+ return this.i18n.t('modeling.nodeLimitExceeded', {
213
+ max: limit.max,
214
+ label: this.i18n.elementTypeLabel(nodeType, NODE_DEFINITIONS[nodeType]?.label),
215
+ nodeType,
216
+ });
195
217
  }
196
218
 
197
219
  _assertAllowedModel(model) {
@@ -236,6 +258,7 @@ export class BpmnStudioController {
236
258
  : null,
237
259
  activeScopeId: this.activeScopeId,
238
260
  scopePath: getScopePath(this._model, this.activeScopeId),
261
+ locale: this.i18n.locale,
239
262
  };
240
263
  }
241
264
 
@@ -322,8 +345,8 @@ export class BpmnStudioController {
322
345
  scopeId: this.activeScopeId,
323
346
  width: Math.max(CONTAINMENT_LIMITS.groupMinWidth, bounds.width + padding * 2),
324
347
  height: Math.max(CONTAINMENT_LIMITS.groupMinHeight, bounds.height + padding * 2),
325
- properties: { categoryValue: '分组' },
326
- });
348
+ properties: { categoryValue: this.i18n.t('modeling.defaultGroupCategory') },
349
+ }, { i18n: this.i18n });
327
350
  const firstIndex = Math.min(...groupable.map((node) => this._model.nodes.indexOf(node)));
328
351
  this._model.nodes.splice(Math.max(0, firstIndex), 0, group);
329
352
  });
@@ -430,7 +453,7 @@ export class BpmnStudioController {
430
453
  if (nodeType === 'participant') {
431
454
  mergedPreset.properties = { ...(mergedPreset.properties || {}), processRef: mergedPreset.properties?.processRef || this._model.id };
432
455
  }
433
- node = createNode(nodeType, position.x, position.y, { ...mergedPreset, scopeId: this.activeScopeId });
456
+ node = createNode(nodeType, position.x, position.y, { ...mergedPreset, scopeId: this.activeScopeId }, { i18n: this.i18n });
434
457
  this._model.nodes.push(node);
435
458
  if (nodeType === 'lane') {
436
459
  const participant = resolveContainment(this._model).getParticipantAt({
@@ -472,7 +495,7 @@ export class BpmnStudioController {
472
495
  this._commit('create-template', () => {
473
496
  for (const spec of nodeSpecs) {
474
497
  const offset = spec.offset || { x: 0, y: 0 };
475
- const node = createNode(spec.nodeType, Math.round(point.x + (offset.x || 0)), Math.round(point.y + (offset.y || 0)), { ...mergeNodePreset(spec.preset), scopeId: this.activeScopeId });
498
+ const node = createNode(spec.nodeType, Math.round(point.x + (offset.x || 0)), Math.round(point.y + (offset.y || 0)), { ...mergeNodePreset(spec.preset), scopeId: this.activeScopeId }, { i18n: this.i18n });
476
499
  byKey.set(spec.key, node);
477
500
  result.nodes.push(node);
478
501
  this._model.nodes.push(node);
@@ -646,7 +669,7 @@ export class BpmnStudioController {
646
669
  if (!node || !def || !this.canChangeNodeType(id, type) || node.type === type) return false;
647
670
  if (isEmbeddedSubProcess(node) && !isEmbeddedSubProcess(type) && hasScopeChildren(this._model, id)) return false;
648
671
  this._commit('change-node-type', () => {
649
- const next = createNode(type, node.x, node.y, { id: node.id, name: node.name });
672
+ const next = createNode(type, node.x, node.y, { id: node.id, name: node.name }, { i18n: this.i18n });
650
673
  Object.assign(node, { type, bpmnType: def.bpmnType, width: def.width, height: def.height, originalLocalName: def.localName });
651
674
  node.isExpanded = isEmbeddedSubProcess(type) ? false : undefined;
652
675
  node.properties = { ...next.properties, ...node.properties };
@@ -672,9 +695,9 @@ export class BpmnStudioController {
672
695
  : source.y + source.height / 2 - def.height / 2 + (outgoingCount ? outgoingCount * (def.height + spacing.nodeGap) : 0);
673
696
  let node;
674
697
  this._commit('quick-add', () => {
675
- node = createNode(type, Math.round(x), Math.round(y), { ...mergeNodePreset(preset), scopeId: elementScopeId(this._model, source) });
698
+ node = createNode(type, Math.round(x), Math.round(y), { ...mergeNodePreset(preset), scopeId: elementScopeId(this._model, source) }, { i18n: this.i18n });
676
699
  this._model.nodes.push(node);
677
- this._model.edges.push(createEdge(sourceId, node.id, { name: NODE_DEFINITIONS[source.type]?.kind === 'gateway' ? `分支 ${outgoingCount + 1}` : '', scopeId: elementScopeId(this._model, source) }));
700
+ this._model.edges.push(createEdge(sourceId, node.id, { name: NODE_DEFINITIONS[source.type]?.kind === 'gateway' ? this.i18n.t('modeling.branchName', { index: outgoingCount + 1 }) : '', scopeId: elementScopeId(this._model, source) }));
678
701
  });
679
702
  this.select({ kind: 'node', id: node.id });
680
703
  return node;
@@ -741,30 +764,31 @@ export class BpmnStudioController {
741
764
  return true;
742
765
  }
743
766
  exportXml(engine) { return exportBpmn(this._model, engine); }
744
- importXml(xml, engine) { const model = importBpmn(xml, engine); this.setModel(model); return model; }
767
+ importXml(xml, engine) { const model = importBpmn(xml, engine, { i18n: this.i18n }); this.setModel(model); return model; }
745
768
 
746
769
  validate() {
770
+ const i18n = this.i18n;
747
771
  const issues = [];
748
772
  const starts = this._model.nodes.filter((node) => NODE_DEFINITIONS[node.type]?.eventStage === 'start');
749
773
  const ends = this._model.nodes.filter((node) => NODE_DEFINITIONS[node.type]?.eventStage === 'end');
750
- if (!starts.length) issues.push({ level: 'error', message: '流程至少需要一个开始事件。' });
751
- if (!ends.length) issues.push({ level: 'warning', message: '建议至少配置一个结束事件。' });
774
+ if (!starts.length) issues.push({ level: 'error', message: i18n.t('validation.missingStartEvent') });
775
+ if (!ends.length) issues.push({ level: 'warning', message: i18n.t('validation.missingEndEvent') });
752
776
  const scopeIssues = getScopeIntegrityIssues(this._model);
753
777
  const invalidScopeEdges = new Set(scopeIssues.filter((issue) => issue.kind === 'edge').map((issue) => issue.id));
754
778
  for (const issue of scopeIssues.filter((item) => item.kind === 'node')) {
755
- issues.push({ level: 'error', elementId: issue.id, message: '节点引用了不存在或无效的子流程作用域。' });
779
+ issues.push({ level: 'error', elementId: issue.id, message: i18n.t('validation.invalidSubProcessScope') });
756
780
  }
757
781
  for (const edge of this._model.edges) {
758
- if (!getNode(this._model, edge.source) || !getNode(this._model, edge.target)) issues.push({ level: 'error', elementId: edge.id, message: '连线引用了不存在的节点。' });
759
- else if (invalidScopeEdges.has(edge.id)) issues.push({ level: 'error', elementId: edge.id, message: '连线不能跨越流程或子流程作用域。' });
760
- if ((edge.type || 'sequenceFlow') === 'sequenceFlow' && edge.source === edge.target) issues.push({ level: 'error', elementId: edge.id, message: '顺序流不能连接到自身。' });
782
+ if (!getNode(this._model, edge.source) || !getNode(this._model, edge.target)) issues.push({ level: 'error', elementId: edge.id, message: i18n.t('validation.edgeMissingNode') });
783
+ else if (invalidScopeEdges.has(edge.id)) issues.push({ level: 'error', elementId: edge.id, message: i18n.t('validation.edgeCrossScope') });
784
+ if ((edge.type || 'sequenceFlow') === 'sequenceFlow' && edge.source === edge.target) issues.push({ level: 'error', elementId: edge.id, message: i18n.t('validation.sequenceFlowSelfLoop') });
761
785
  }
762
786
  for (const node of this._model.nodes) {
763
787
  const definition = NODE_DEFINITIONS[node.type] || NODE_DEFINITIONS.generic;
764
- if (node.type === 'serviceTask' && !node.properties?.implementation) issues.push({ level: 'warning', elementId: node.id, message: `${node.name}: 服务任务尚未配置实现。` });
765
- if (node.type === 'userTask' && !node.properties?.assignee && !node.properties?.candidateUsers && !node.properties?.candidateGroups) issues.push({ level: 'warning', elementId: node.id, message: `${node.name}: 用户任务尚未配置处理人。` });
766
- if (definition.kind === 'boundary' && !node.properties?.attachedToRef) issues.push({ level: 'warning', elementId: node.id, message: `${node.name}: 边界事件尚未选择附着活动。` });
767
- for (const message of validateParallelGateway(this._model, node)) issues.push({ level: 'warning', elementId: node.id, message: `${node.name}: ${message}` });
788
+ if (node.type === 'serviceTask' && !node.properties?.implementation) issues.push({ level: 'warning', elementId: node.id, message: i18n.t('validation.serviceTaskMissingImpl', { name: node.name }) });
789
+ if (node.type === 'userTask' && !node.properties?.assignee && !node.properties?.candidateUsers && !node.properties?.candidateGroups) issues.push({ level: 'warning', elementId: node.id, message: i18n.t('validation.userTaskMissingAssignee', { name: node.name }) });
790
+ if (definition.kind === 'boundary' && !node.properties?.attachedToRef) issues.push({ level: 'warning', elementId: node.id, message: i18n.t('validation.boundaryMissingTarget', { name: node.name }) });
791
+ for (const message of validateParallelGateway(this._model, node, { i18n })) issues.push({ level: 'warning', elementId: node.id, message: i18n.t('validation.nodeIssue', { name: node.name, message }) });
768
792
  }
769
793
  return issues;
770
794
  }
@@ -810,6 +834,8 @@ export class BpmnStudioController {
810
834
  }
811
835
 
812
836
  destroy() {
837
+ this._offI18n?.();
838
+ this._offI18n = null;
813
839
  for (const cleanup of this._extensions.values()) cleanup?.();
814
840
  this._extensions.clear();
815
841
  this._listeners.clear();
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './modules/i18n/index.js'
1
2
  export * from './modules/core/index.js'
2
3
  export * from './modules/bpmn-model/index.js'
3
4
  export * from './modules/runtime/index.js'
@@ -32,7 +33,15 @@ import type { RuntimeTimelineSvgRenderer, SvgExportArtifact, SvgExportOptions, S
32
33
  import type {
33
34
  ActivityInstance as RuntimeActivityInstance,
34
35
  ProcessInstanceSnapshot as RuntimeProcessInstanceSnapshot,
36
+ RuntimeTimeFormatOptions,
37
+ RuntimeTimeFormatter,
35
38
  } from './modules/runtime/index.js'
39
+ import type {
40
+ I18nController,
41
+ NovaI18nState,
42
+ NovaLocale,
43
+ NovaMessagesOverride,
44
+ } from './modules/i18n/index.js'
36
45
  import type { NovaThemeInput, NovaThemeMode, NovaThemeState, RuntimeAppearanceOptions, RuntimeAppearanceResolver } from './modules/theme/index.js'
37
46
  import type {
38
47
  RuntimeDetailsRenderer,
@@ -150,6 +159,11 @@ export interface ViewerOptions {
150
159
  timeline?: ViewerTimelineOptions
151
160
  runtimeDetails?: RuntimeDetailsOptions
152
161
  runtimeTraceOptions?: RuntimeTraceProjectionOptions
162
+ formatRuntimeTime?: RuntimeTimeFormatter | null
163
+ runtimeTimeFormat?: RuntimeTimeFormatOptions | null
164
+ i18n?: I18nController | null
165
+ locale?: NovaLocale
166
+ messages?: NovaMessagesOverride | null
153
167
  onTraceClick?: (event: RuntimeTraceClickEvent) => void
154
168
  runtimePresenter?: (context: { model: ProcessModel; runtime: ProcessInstanceSnapshot | null; appearance: RuntimeAppearanceResolver }) => RuntimePresentation
155
169
  runtimeTraceProjector?: import('./modules/viewer/index.js').ViewerOptions['runtimeTraceProjector']
@@ -178,11 +192,13 @@ export class BpmnViewer {
178
192
  setModel(model: ProcessModel): void
179
193
  setRuntime(runtime: ProcessInstanceSnapshot | null): void
180
194
  refreshPresentation(): void
181
- setDisplayOptions(options: { timeline?: ViewerTimelineOptions; runtimeDetails?: RuntimeDetailsOptions; runtimeTraceOptions?: RuntimeTraceProjectionOptions; runtimeAssetResolver?: import('./modules/viewer/index.js').RuntimeAssetResolver | null; replace?: boolean }): void
195
+ setDisplayOptions(options: { timeline?: ViewerTimelineOptions; runtimeDetails?: RuntimeDetailsOptions; runtimeTraceOptions?: RuntimeTraceProjectionOptions; runtimeAssetResolver?: import('./modules/viewer/index.js').RuntimeAssetResolver | null; formatRuntimeTime?: RuntimeTimeFormatter | null; runtimeTimeFormat?: RuntimeTimeFormatOptions | null; replace?: boolean }): void
182
196
  setProjection(projection: ViewerProjection): void
183
197
  setTheme(theme: NovaThemeInput): NovaThemeState
184
198
  setThemeMode(mode: NovaThemeMode): NovaThemeState
185
199
  getThemeState(): NovaThemeState
200
+ setLocale(locale?: NovaLocale | null, messages?: NovaMessagesOverride | null): NovaI18nState
201
+ getLocale(): NovaI18nState
186
202
  exportSvg(options?: SvgExportOptions): Promise<SvgExportArtifact>
187
203
  openSvgExportPreview(options?: SvgExportOptions & { previewTitle?: string; onDownload?: (artifact: SvgExportArtifact) => void }): SvgExportPreviewController
188
204
  setRuntimeAppearance(options: RuntimeAppearanceOptions | null): void
@@ -212,6 +228,7 @@ export interface StudioState {
212
228
  nodeLimits: StudioNodeLimits | null
213
229
  activeScopeId: string
214
230
  scopePath: Array<{ id: string; name: string; kind: 'process' | 'subProcess' }>
231
+ locale: string
215
232
  }
216
233
  export interface StudioValidationIssue {
217
234
  level: 'error' | 'warning'
@@ -252,11 +269,23 @@ export interface StudioRightPanelConfig extends StudioSidebarConfig {
252
269
  /** Defaults to flex. In scroll mode Nova scrolls the entire supplied content. */
253
270
  layout?: 'flex' | 'scroll'
254
271
  }
272
+ /** Floating head in the top-left corner of the design canvas. Since 0.3.9-preview. */
273
+ export interface StudioCanvasHeadConfig {
274
+ /** Show the "编辑模式" badge. Defaults to true. */
275
+ editingMode?: boolean
276
+ /**
277
+ * `always` (default) shows the scope path at every level; `nested` shows it only
278
+ * inside nested scopes such as sub-processes. The back button only appears in
279
+ * nested scopes either way. With nothing to show, the head takes no space.
280
+ */
281
+ scopePath?: 'always' | 'nested'
282
+ }
255
283
  export interface StudioUiConfig {
256
284
  controlSize?: StudioControlSize
257
285
  regions?: StudioShellRegions
258
286
  leftPanel?: StudioSidebarConfig
259
287
  rightPanel?: StudioRightPanelConfig
288
+ canvasHead?: StudioCanvasHeadConfig
260
289
  sidebarWidth?: {
261
290
  left?: number
262
291
  right?: number
@@ -268,6 +297,8 @@ export interface StudioViewerConfig {
268
297
  timeline?: ViewerTimelineOptions
269
298
  runtimeDetails?: RuntimeDetailsOptions
270
299
  runtimeTraceOptions?: RuntimeTraceProjectionOptions
300
+ formatRuntimeTime?: RuntimeTimeFormatter | null
301
+ runtimeTimeFormat?: RuntimeTimeFormatOptions | null
271
302
  }
272
303
  export type StudioSvgExportOptions = SvgExportOptions & {
273
304
  label?: string
@@ -289,6 +320,9 @@ export interface StudioControllerOptions {
289
320
  historyLimit?: number
290
321
  extensions?: StudioExtension[]
291
322
  config?: BpmnStudioConfig
323
+ i18n?: I18nController | null
324
+ locale?: NovaLocale
325
+ messages?: NovaMessagesOverride | null
292
326
  /** @deprecated Use config.modeling.propertiesProfile. */
293
327
  propertiesProfile?: 'business' | 'developer'
294
328
  /** @deprecated Use config.modeling.allowedNodeTypes. */
@@ -330,7 +364,7 @@ export interface StudioCommands {
330
364
  redo(): boolean
331
365
  }
332
366
  export interface StudioEvent {
333
- type: 'modelChanged' | 'selectionChanged' | 'historyChanged' | 'scopeChanged' | 'propertiesProfileChanged' | string
367
+ type: 'modelChanged' | 'selectionChanged' | 'historyChanged' | 'scopeChanged' | 'propertiesProfileChanged' | 'localeChanged' | string
334
368
  reason?: string
335
369
  state: StudioState
336
370
  [key: string]: unknown
@@ -339,11 +373,14 @@ export function canCreateSequenceFlow(model: ProcessModel, sourceId: string, tar
339
373
  export class BpmnStudioController {
340
374
  constructor(options: StudioControllerOptions)
341
375
  readonly model: ProcessModel
376
+ readonly i18n: I18nController
342
377
  selection: ElementSelection | null
343
378
  connectingSource: string | null
344
379
  activeScopeId: string
345
380
  propertiesProfile: 'business' | 'developer'
346
381
  readonly commands: StudioCommands
382
+ setLocale(locale?: NovaLocale | null, messages?: NovaMessagesOverride | null): NovaI18nState
383
+ getLocale(): NovaI18nState
347
384
  getState(): StudioState
348
385
  getSelectedElement(): StudioState['selectedElement']
349
386
  getActiveGraph(): ProcessModel
@@ -434,6 +471,7 @@ export type ContextMenuTarget =
434
471
  export interface ContextMenuContext {
435
472
  studio: BpmnStudioController
436
473
  canvas: BpmnCanvas
474
+ i18n?: I18nController
437
475
  target: ContextMenuTarget
438
476
  selection: ElementSelection | null
439
477
  position?: Point
@@ -463,6 +501,7 @@ export type SelectionToolbarSlot = (context: {
463
501
  container: HTMLElement
464
502
  studio: BpmnStudioController
465
503
  canvas: BpmnCanvas
504
+ i18n?: I18nController
466
505
  selection: Extract<ElementSelection, { kind: 'multi' }>
467
506
  elements: BpmnNode[]
468
507
  bounds: SelectionRect
@@ -494,6 +533,9 @@ export interface BpmnCanvasOptions {
494
533
  pointerMode?: 'select' | 'marquee' | 'pan'
495
534
  theme?: NovaThemeInput
496
535
  onThemeChange?: (state: NovaThemeState) => void
536
+ i18n?: I18nController | null
537
+ locale?: NovaLocale
538
+ messages?: NovaMessagesOverride | null
497
539
  }
498
540
  export interface CanvasRevealElementOptions {
499
541
  /** Restrict the lookup to nodes or edges; by id alone nodes are searched first. */
@@ -524,6 +566,8 @@ export class BpmnCanvas {
524
566
  setTheme(theme: NovaThemeInput): NovaThemeState
525
567
  setThemeMode(mode: NovaThemeMode): NovaThemeState
526
568
  getThemeState(): NovaThemeState
569
+ setLocale(locale?: NovaLocale | null, messages?: NovaMessagesOverride | null): NovaI18nState
570
+ getLocale(): NovaI18nState
527
571
  exportSvg(options?: SvgExportOptions): Promise<SvgExportArtifact>
528
572
  openSvgExportPreview(options?: SvgExportOptions & { previewTitle?: string; onDownload?: (artifact: SvgExportArtifact) => void }): SvgExportPreviewController
529
573
  closeContextMenu(): void
@@ -584,6 +628,9 @@ export interface StudioValidationEvent {
584
628
  export interface StudioShellSlotContext {
585
629
  studio: BpmnStudioController
586
630
  shell: BpmnStudioShell
631
+ readonly i18n: I18nController
632
+ getLocale(): NovaI18nState
633
+ setLocale(locale?: NovaLocale | null, messages?: NovaMessagesOverride | null): NovaI18nState
587
634
  canvas: BpmnCanvas
588
635
  actions: StudioShellActions
589
636
  readonly ui: StudioUiContext
@@ -642,6 +689,8 @@ export interface StudioShellOptions {
642
689
  runtimeTraceOptions?: RuntimeTraceProjectionOptions
643
690
  timeline?: ViewerTimelineOptions
644
691
  runtimeDetails?: RuntimeDetailsOptions
692
+ formatRuntimeTime?: RuntimeTimeFormatter | null
693
+ runtimeTimeFormat?: RuntimeTimeFormatOptions | null
645
694
  }
646
695
  nodeSubtitleResolver?: NodeSubtitleResolver
647
696
  slots?: StudioShellSlots
@@ -666,6 +715,11 @@ export interface StudioShellOptions {
666
715
  runtimeDetails?: RuntimeDetailsOptions
667
716
  /** @deprecated Use config.viewer.runtimeTraceOptions. */
668
717
  runtimeTraceOptions?: RuntimeTraceProjectionOptions
718
+ formatRuntimeTime?: RuntimeTimeFormatter | null
719
+ runtimeTimeFormat?: RuntimeTimeFormatOptions | null
720
+ i18n?: I18nController | null
721
+ locale?: NovaLocale
722
+ messages?: NovaMessagesOverride | null
669
723
  theme?: NovaThemeInput
670
724
  runtimeAppearance?: RuntimeAppearanceOptions
671
725
  /** @deprecated Use config.export. */
@@ -674,10 +728,13 @@ export interface StudioShellOptions {
674
728
  }
675
729
  export class BpmnStudioShell {
676
730
  constructor(options: StudioShellOptions)
731
+ readonly i18n: I18nController
677
732
  readonly actions: StudioShellActions
678
733
  readonly ui: StudioUiContext
679
734
  canvas?: BpmnCanvas
680
735
  viewer?: BpmnViewer
736
+ setLocale(locale?: NovaLocale | null, messages?: NovaMessagesOverride | null): NovaI18nState
737
+ getLocale(): NovaI18nState
681
738
  getMode(): StudioMode
682
739
  getAllowedModes(): readonly StudioMode[]
683
740
  subscribeMode(listener: (event: StudioModeChangeEvent) => void): () => void
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './modules/i18n/index.js';
1
2
  export * from './modules/core/index.js';
2
3
  export * from './modules/bpmn-model/index.js';
3
4
  export * from './modules/runtime/index.js';
@@ -1,4 +1,5 @@
1
1
  import { NODE_DEFINITIONS } from './modules/core/index.js';
2
+ import { resolveI18n } from './modules/i18n/index.js';
2
3
 
3
4
  export const CREATE_INTENT_MIME = 'application/x-bpmn-nova-create-intent+json';
4
5
 
@@ -74,7 +75,11 @@ export class InteractionController {
74
75
  _nodeLimitReason(nodeType, count = 1) {
75
76
  const reason = this.studio.nodeLimitReason?.(nodeType, count);
76
77
  if (reason) return reason;
77
- return `已达${NODE_DEFINITIONS[nodeType]?.label || nodeType}数量上限`;
78
+ const i18n = resolveI18n(this.studio?.i18n);
79
+ return i18n.t('modeling.nodeLimitReached', {
80
+ label: i18n.elementTypeLabel(nodeType, NODE_DEFINITIONS[nodeType]?.label),
81
+ nodeType,
82
+ });
78
83
  }
79
84
 
80
85
  drop(session, pointer, canvas) {
@@ -1,4 +1,5 @@
1
1
  import type { EngineId, ProcessModel } from '../core/index.js'
2
+ import type { NovaI18nOptions } from '../i18n/index.js'
2
3
  import type { FlowableEngineProfile } from '../engine-flowable/index.js'
3
4
  import type { ActivitiEngineProfile } from '../engine-activiti/index.js'
4
5
 
@@ -7,5 +8,5 @@ export const engineProfiles: {
7
8
  activiti: ActivitiEngineProfile
8
9
  }
9
10
  export function detectEngineFromXml(xml: string): EngineId
10
- export function importBpmn(xml: string, engineHint?: EngineId): ProcessModel
11
+ export function importBpmn(xml: string, engineHint?: EngineId, options?: NovaI18nOptions | null): ProcessModel
11
12
  export function exportBpmn(model: ProcessModel, engineOverride?: EngineId): string
@@ -1,3 +1,4 @@
1
+ import { resolveI18n } from '../i18n/index.js';
1
2
  import {
2
3
  applyContainmentOperation,
3
4
  createEmptyProcess,
@@ -139,7 +140,7 @@ function parseEventProperties(el, def) {
139
140
  return props;
140
141
  }
141
142
 
142
- function parseCommonNode(el, profile, shapeMap, fallbackIndex = 0) {
143
+ function parseCommonNode(el, profile, shapeMap, fallbackIndex = 0, i18n = null) {
143
144
  const type = inferType(el);
144
145
  const def = NODE_DEFINITIONS[type] || NODE_DEFINITIONS.generic;
145
146
  const id = el.getAttribute('id') || `Imported_${fallbackIndex + 1}`;
@@ -223,7 +224,7 @@ function parseCommonNode(el, profile, shapeMap, fallbackIndex = 0) {
223
224
 
224
225
  return createNode(type, bounds.x, bounds.y, {
225
226
  id,
226
- name: el.getAttribute('name') || def.label,
227
+ name: el.getAttribute('name') || (i18n ? i18n.elementTypeLabel(type, def.label) : def.label),
227
228
  width: bounds.width || def.width,
228
229
  height: bounds.height || def.height,
229
230
  bpmnType: def.bpmnType,
@@ -232,22 +233,23 @@ function parseCommonNode(el, profile, shapeMap, fallbackIndex = 0) {
232
233
  unknownAttributes,
233
234
  extensionElements,
234
235
  defaultFlowId: el.getAttribute('default') || '',
235
- });
236
+ }, i18n ? { i18n } : null);
236
237
  }
237
238
 
238
- export function importBpmn(xml, engineHint) {
239
+ export function importBpmn(xml, engineHint, options = null) {
240
+ const i18n = resolveI18n(options);
239
241
  if (typeof DOMParser === 'undefined') throw new Error('importBpmn currently requires a browser DOMParser.');
240
242
  const doc = new DOMParser().parseFromString(xml, 'application/xml');
241
243
  const parserError = doc.querySelector('parsererror');
242
- if (parserError) throw new Error(`BPMN XML 解析失败: ${parserError.textContent.trim()}`);
244
+ if (parserError) throw new Error(i18n.t('validation.import.xmlParseFailed', { detail: parserError.textContent.trim() }));
243
245
 
244
246
  const definitions = doc.documentElement;
245
247
  const engine = engineHint || detectEngineFromXml(xml);
246
248
  const profile = getProfile(engine);
247
249
  const process = Array.from(definitions.children).find((el) => el.localName === 'process');
248
- if (!process) throw new Error('未找到 <process> 元素。');
250
+ if (!process) throw new Error(i18n.t('validation.import.missingProcessElement'));
249
251
 
250
- const model = createEmptyProcess(engine);
252
+ const model = createEmptyProcess(engine, { i18n });
251
253
  model.id = process.getAttribute('id') || 'Process_1';
252
254
  model.name = process.getAttribute('name') || model.id;
253
255
  model.isExecutable = process.getAttribute('isExecutable') !== 'false';
@@ -304,7 +306,7 @@ export function importBpmn(xml, engineHint) {
304
306
  if (el.localName === 'sequenceFlow') { sequenceEls.push({ el, scopeId }); continue; }
305
307
  if (el.localName === 'association') { associationEls.push({ el, scopeId }); continue; }
306
308
  if (skipLocals.has(el.localName)) continue;
307
- const node = parseCommonNode(el, profile, shapeMap, model.nodes.length);
309
+ const node = parseCommonNode(el, profile, shapeMap, model.nodes.length, i18n);
308
310
  node.scopeId = scopeId;
309
311
  if (isEmbeddedSubProcess(node)) node.isExpanded = false;
310
312
  model.nodes.push(node);
@@ -319,7 +321,7 @@ export function importBpmn(xml, engineHint) {
319
321
  }
320
322
 
321
323
  for (const lane of Array.from(process.querySelectorAll(':scope > laneSet > lane'))) {
322
- const node = parseCommonNode(lane, profile, shapeMap, model.nodes.length);
324
+ const node = parseCommonNode(lane, profile, shapeMap, model.nodes.length, i18n);
323
325
  node.type = 'lane'; node.bpmnType = 'bpmn:Lane'; node.originalLocalName = 'lane';
324
326
  node.scopeId = model.id;
325
327
  node.properties.flowNodeRefs = Array.from(lane.children).filter((child) => child.localName === 'flowNodeRef').map((child) => child.textContent.trim());
@@ -329,7 +331,7 @@ export function importBpmn(xml, engineHint) {
329
331
  const collaboration = Array.from(definitions.children).find((el) => el.localName === 'collaboration');
330
332
  if (collaboration) {
331
333
  for (const participant of Array.from(collaboration.children).filter((el) => el.localName === 'participant')) {
332
- const node = parseCommonNode(participant, profile, shapeMap, model.nodes.length);
334
+ const node = parseCommonNode(participant, profile, shapeMap, model.nodes.length, i18n);
333
335
  node.type = 'participant'; node.bpmnType = 'bpmn:Participant'; node.originalLocalName = 'participant';
334
336
  node.scopeId = model.id;
335
337
  node.properties.processRef = participant.getAttribute('processRef') || '';
@@ -1,3 +1,5 @@
1
+ import { DEFAULT_I18N, resolveI18n } from '../i18n/index.js';
2
+
1
3
  const sequenceFlowsFor = (model, predicate) => (model?.edges || [])
2
4
  .filter((edge) => (edge.type || 'sequenceFlow') === 'sequenceFlow')
3
5
  .filter(predicate);
@@ -25,25 +27,26 @@ function inferGatewayDirection(incoming, outgoing) {
25
27
  return 'Unspecified';
26
28
  }
27
29
 
28
- function roleIssues(effective, incoming, outgoing) {
30
+ function roleIssues(effective, incoming, outgoing, i18n = DEFAULT_I18N) {
29
31
  const issues = [];
30
32
  if (effective === 'Converging') {
31
- if (incoming.length < 2) issues.push('并行汇聚至少需要两条入口线路。');
32
- if (outgoing.length !== 1) issues.push('并行汇聚通常应只有一条出口线路。');
33
+ if (incoming.length < 2) issues.push(i18n.t('validation.parallelGateway.convergingMinIncoming'));
34
+ if (outgoing.length !== 1) issues.push(i18n.t('validation.parallelGateway.convergingSingleOutgoing'));
33
35
  } else if (effective === 'Diverging') {
34
- if (incoming.length !== 1) issues.push('并行分支通常应只有一条入口线路。');
35
- if (outgoing.length < 2) issues.push('并行分支至少需要两条出口线路。');
36
+ if (incoming.length !== 1) issues.push(i18n.t('validation.parallelGateway.divergingSingleIncoming'));
37
+ if (outgoing.length < 2) issues.push(i18n.t('validation.parallelGateway.divergingMinOutgoing'));
36
38
  } else if (effective === 'Mixed') {
37
- issues.push('并行网关同时存在多个入口和多个出口,建议拆分为汇聚与分支两个网关。');
39
+ issues.push(i18n.t('validation.parallelGateway.mixedNotAllowed'));
38
40
  } else {
39
- issues.push('当前线路不足,暂时无法判断并行分支或并行汇聚。');
41
+ issues.push(i18n.t('validation.parallelGateway.ambiguousTopology'));
40
42
  }
41
- if (outgoing.some((edge) => String(edge.condition || '').trim())) issues.push('并行网关出口不应设置条件表达式。');
42
- if (outgoing.some((edge) => edge.isDefault)) issues.push('并行网关不支持默认出口。');
43
+ if (outgoing.some((edge) => String(edge.condition || '').trim())) issues.push(i18n.t('validation.parallelGateway.noConditionAllowed'));
44
+ if (outgoing.some((edge) => edge.isDefault)) issues.push(i18n.t('validation.parallelGateway.noDefaultAllowed'));
43
45
  return issues;
44
46
  }
45
47
 
46
- export function resolveGatewayRole(model, node) {
48
+ export function resolveGatewayRole(model, node, options = null) {
49
+ const i18n = options ? resolveI18n(options) : DEFAULT_I18N;
47
50
  const incoming = sequenceFlowsFor(model, (edge) => edge.target === node?.id);
48
51
  const outgoing = sequenceFlowsFor(model, (edge) => edge.source === node?.id);
49
52
  const declared = node?.properties?.gatewayDirection || 'Unspecified';
@@ -62,11 +65,11 @@ export function resolveGatewayRole(model, node) {
62
65
  : contradictoryTopology || invalidOutgoing
63
66
  ? 'conflict'
64
67
  : topologyComplete ? 'valid' : 'incomplete';
65
- const issues = roleIssues(effective, incoming, outgoing);
68
+ const issues = roleIssues(effective, incoming, outgoing, i18n);
66
69
  return { declared, inferred, effective, incoming, outgoing, topologyComplete, status, issues };
67
70
  }
68
71
 
69
- export function validateParallelGateway(model, node) {
72
+ export function validateParallelGateway(model, node, options = null) {
70
73
  if (node?.type !== 'parallelGateway') return [];
71
- return [...resolveGatewayRole(model, node).issues];
74
+ return [...resolveGatewayRole(model, node, options).issues];
72
75
  }
@@ -1,3 +1,5 @@
1
+ import type { NovaI18nOptions } from '../i18n/index.js'
2
+
1
3
  export type EngineId = 'flowable' | 'activiti'
2
4
  export type NodeType =
3
5
  | 'startEvent' | 'messageStartEvent' | 'timerStartEvent' | 'conditionalStartEvent' | 'signalStartEvent' | 'errorStartEvent' | 'escalationStartEvent' | 'compensationStartEvent'
@@ -116,9 +118,9 @@ export const NODE_DEFINITIONS: Record<NodeType | 'generic', NodeDefinition>
116
118
  export const PALETTE_GROUPS: Array<{ id: string; label: string; types: NodeType[] }>
117
119
  export const EDGE_DEFINITIONS: Record<EdgeType, { bpmnType: string; label: string }>
118
120
  export function uid(prefix?: string): string
119
- export function createNode(type: NodeType, x?: number, y?: number, overrides?: Partial<BpmnNode>): BpmnNode
121
+ export function createNode(type: NodeType, x?: number, y?: number, overrides?: Partial<BpmnNode>, options?: NovaI18nOptions | null): BpmnNode
120
122
  export function createEdge(source: string, target: string, overrides?: Partial<BpmnEdge>): BpmnEdge
121
- export function createEmptyProcess(engine?: EngineId): ProcessModel
123
+ export function createEmptyProcess(engine?: EngineId, options?: NovaI18nOptions | null): ProcessModel
122
124
  export function cloneModel<T extends ProcessModel>(model: T): T
123
125
  export function getNode(model: ProcessModel, id: string): BpmnNode | null
124
126
  export function getEdge(model: ProcessModel, id: string): BpmnEdge | null
@@ -233,8 +235,8 @@ export interface GatewayRoleResolution {
233
235
  issues: string[]
234
236
  }
235
237
  export const PARALLEL_GATEWAY_PRESETS: Readonly<Record<'diverging' | 'converging', Readonly<{ id: string; label: string; iconId: string; nodeType: 'parallelGateway'; preset: Partial<BpmnNode> }>>>
236
- export function resolveGatewayRole(model: ProcessModel, node: BpmnNode): GatewayRoleResolution
237
- export function validateParallelGateway(model: ProcessModel, node: BpmnNode): string[]
238
+ export function resolveGatewayRole(model: ProcessModel, node: BpmnNode, options?: NovaI18nOptions | null): GatewayRoleResolution
239
+ export function validateParallelGateway(model: ProcessModel, node: BpmnNode, options?: NovaI18nOptions | null): string[]
238
240
 
239
241
  export interface RuntimeTransitionRouteOptions {
240
242
  occupiedRoutes?: Array<Point[] | { points: Point[] }>
@@ -1,3 +1,5 @@
1
+ import { resolveI18n } from '../i18n/index.js';
2
+
1
3
  export const NODE_DEFINITIONS = {
2
4
  // Events — start
3
5
  startEvent: { bpmnType: 'bpmn:StartEvent', localName: 'startEvent', label: '开始事件', icon: '', kind: 'event', eventStage: 'start', eventDefinition: null, width: 56, height: 56, palette: 'startEvents' },
@@ -101,7 +103,7 @@ export function uid(prefix = 'Element') {
101
103
  return `${prefix}_${Date.now().toString(36)}_${idSeed.toString(36)}`;
102
104
  }
103
105
 
104
- function defaultNodeProperties(type, def, overrides = {}) {
106
+ function defaultNodeProperties(type, def, overrides = {}, i18n = null) {
105
107
  const props = {
106
108
  documentation: '',
107
109
  loopType: 'none',
@@ -134,7 +136,7 @@ function defaultNodeProperties(type, def, overrides = {}) {
134
136
  if (type === 'eventBasedGateway') Object.assign(props, { instantiate: false, eventGatewayType: 'Exclusive' });
135
137
  if (type === 'complexGateway') Object.assign(props, { activationCondition: '' });
136
138
  if (def.eventDefinition === 'compensate') Object.assign(props, { activityRef: '', waitForCompletion: true });
137
- if (type === 'textAnnotation') Object.assign(props, { text: '说明文字', textFormat: 'text/plain' });
139
+ if (type === 'textAnnotation') Object.assign(props, { text: i18n ? i18n.t('modeling.defaultAnnotationText') : '说明文字', textFormat: 'text/plain' });
138
140
  if (type === 'dataObjectReference') Object.assign(props, { dataObjectRef: '', dataState: '' });
139
141
  if (type === 'dataStoreReference') Object.assign(props, { dataStoreRef: '', dataState: '' });
140
142
  if (type === 'group') Object.assign(props, { categoryValue: '' });
@@ -144,18 +146,20 @@ function defaultNodeProperties(type, def, overrides = {}) {
144
146
  return { ...props, ...(overrides.properties || {}) };
145
147
  }
146
148
 
147
- export function createNode(type, x = 100, y = 100, overrides = {}) {
149
+ export function createNode(type, x = 100, y = 100, overrides = {}, options = null) {
148
150
  const def = NODE_DEFINITIONS[type] || NODE_DEFINITIONS.generic;
151
+ const i18n = options ? resolveI18n(options) : null;
152
+ const defaultName = i18n ? i18n.elementTypeLabel(type, def.label) : def.label;
149
153
  const base = {
150
154
  id: uid(type),
151
155
  type,
152
156
  bpmnType: def.bpmnType,
153
- name: overrides.name || def.label,
157
+ name: overrides.name || defaultName,
154
158
  x,
155
159
  y,
156
160
  width: def.width,
157
161
  height: def.height,
158
- properties: defaultNodeProperties(type, def, overrides),
162
+ properties: defaultNodeProperties(type, def, overrides, i18n),
159
163
  unknownAttributes: [],
160
164
  extensionElements: [],
161
165
  ...(['subProcess', 'eventSubProcess', 'transaction', 'adHocSubProcess'].includes(type) ? { isExpanded: false } : {}),
@@ -182,10 +186,11 @@ export function createEdge(source, target, overrides = {}) {
182
186
  };
183
187
  }
184
188
 
185
- export function createEmptyProcess(engine = 'flowable') {
189
+ export function createEmptyProcess(engine = 'flowable', options = null) {
190
+ const i18n = options ? resolveI18n(options) : null;
186
191
  return {
187
192
  id: 'Process_1',
188
- name: '未命名流程',
193
+ name: i18n ? i18n.t('modeling.defaultProcessName') : '未命名流程',
189
194
  engine,
190
195
  isExecutable: true,
191
196
  targetNamespace: 'urn:bpmn-nova:process',