@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.
Files changed (55) hide show
  1. package/README.md +2 -2
  2. package/dist/canvas.js +97 -25
  3. package/dist/config.js +13 -0
  4. package/dist/context-menu.js +41 -32
  5. package/dist/controller.js +45 -19
  6. package/dist/index.d.ts +47 -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 +258 -75
  51. package/dist/sidebars.js +3 -1
  52. package/dist/styles.css +3 -2
  53. package/llms-full.txt +241 -46
  54. package/llms.txt +4 -4
  55. package/package.json +2 -3
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'
@@ -280,6 +297,8 @@ export interface StudioViewerConfig {
280
297
  timeline?: ViewerTimelineOptions
281
298
  runtimeDetails?: RuntimeDetailsOptions
282
299
  runtimeTraceOptions?: RuntimeTraceProjectionOptions
300
+ formatRuntimeTime?: RuntimeTimeFormatter | null
301
+ runtimeTimeFormat?: RuntimeTimeFormatOptions | null
283
302
  }
284
303
  export type StudioSvgExportOptions = SvgExportOptions & {
285
304
  label?: string
@@ -301,6 +320,9 @@ export interface StudioControllerOptions {
301
320
  historyLimit?: number
302
321
  extensions?: StudioExtension[]
303
322
  config?: BpmnStudioConfig
323
+ i18n?: I18nController | null
324
+ locale?: NovaLocale
325
+ messages?: NovaMessagesOverride | null
304
326
  /** @deprecated Use config.modeling.propertiesProfile. */
305
327
  propertiesProfile?: 'business' | 'developer'
306
328
  /** @deprecated Use config.modeling.allowedNodeTypes. */
@@ -342,7 +364,7 @@ export interface StudioCommands {
342
364
  redo(): boolean
343
365
  }
344
366
  export interface StudioEvent {
345
- type: 'modelChanged' | 'selectionChanged' | 'historyChanged' | 'scopeChanged' | 'propertiesProfileChanged' | string
367
+ type: 'modelChanged' | 'selectionChanged' | 'historyChanged' | 'scopeChanged' | 'propertiesProfileChanged' | 'localeChanged' | string
346
368
  reason?: string
347
369
  state: StudioState
348
370
  [key: string]: unknown
@@ -351,11 +373,14 @@ export function canCreateSequenceFlow(model: ProcessModel, sourceId: string, tar
351
373
  export class BpmnStudioController {
352
374
  constructor(options: StudioControllerOptions)
353
375
  readonly model: ProcessModel
376
+ readonly i18n: I18nController
354
377
  selection: ElementSelection | null
355
378
  connectingSource: string | null
356
379
  activeScopeId: string
357
380
  propertiesProfile: 'business' | 'developer'
358
381
  readonly commands: StudioCommands
382
+ setLocale(locale?: NovaLocale | null, messages?: NovaMessagesOverride | null): NovaI18nState
383
+ getLocale(): NovaI18nState
359
384
  getState(): StudioState
360
385
  getSelectedElement(): StudioState['selectedElement']
361
386
  getActiveGraph(): ProcessModel
@@ -446,6 +471,7 @@ export type ContextMenuTarget =
446
471
  export interface ContextMenuContext {
447
472
  studio: BpmnStudioController
448
473
  canvas: BpmnCanvas
474
+ i18n?: I18nController
449
475
  target: ContextMenuTarget
450
476
  selection: ElementSelection | null
451
477
  position?: Point
@@ -475,6 +501,7 @@ export type SelectionToolbarSlot = (context: {
475
501
  container: HTMLElement
476
502
  studio: BpmnStudioController
477
503
  canvas: BpmnCanvas
504
+ i18n?: I18nController
478
505
  selection: Extract<ElementSelection, { kind: 'multi' }>
479
506
  elements: BpmnNode[]
480
507
  bounds: SelectionRect
@@ -506,6 +533,9 @@ export interface BpmnCanvasOptions {
506
533
  pointerMode?: 'select' | 'marquee' | 'pan'
507
534
  theme?: NovaThemeInput
508
535
  onThemeChange?: (state: NovaThemeState) => void
536
+ i18n?: I18nController | null
537
+ locale?: NovaLocale
538
+ messages?: NovaMessagesOverride | null
509
539
  }
510
540
  export interface CanvasRevealElementOptions {
511
541
  /** Restrict the lookup to nodes or edges; by id alone nodes are searched first. */
@@ -536,6 +566,8 @@ export class BpmnCanvas {
536
566
  setTheme(theme: NovaThemeInput): NovaThemeState
537
567
  setThemeMode(mode: NovaThemeMode): NovaThemeState
538
568
  getThemeState(): NovaThemeState
569
+ setLocale(locale?: NovaLocale | null, messages?: NovaMessagesOverride | null): NovaI18nState
570
+ getLocale(): NovaI18nState
539
571
  exportSvg(options?: SvgExportOptions): Promise<SvgExportArtifact>
540
572
  openSvgExportPreview(options?: SvgExportOptions & { previewTitle?: string; onDownload?: (artifact: SvgExportArtifact) => void }): SvgExportPreviewController
541
573
  closeContextMenu(): void
@@ -596,6 +628,9 @@ export interface StudioValidationEvent {
596
628
  export interface StudioShellSlotContext {
597
629
  studio: BpmnStudioController
598
630
  shell: BpmnStudioShell
631
+ readonly i18n: I18nController
632
+ getLocale(): NovaI18nState
633
+ setLocale(locale?: NovaLocale | null, messages?: NovaMessagesOverride | null): NovaI18nState
599
634
  canvas: BpmnCanvas
600
635
  actions: StudioShellActions
601
636
  readonly ui: StudioUiContext
@@ -654,6 +689,8 @@ export interface StudioShellOptions {
654
689
  runtimeTraceOptions?: RuntimeTraceProjectionOptions
655
690
  timeline?: ViewerTimelineOptions
656
691
  runtimeDetails?: RuntimeDetailsOptions
692
+ formatRuntimeTime?: RuntimeTimeFormatter | null
693
+ runtimeTimeFormat?: RuntimeTimeFormatOptions | null
657
694
  }
658
695
  nodeSubtitleResolver?: NodeSubtitleResolver
659
696
  slots?: StudioShellSlots
@@ -678,6 +715,11 @@ export interface StudioShellOptions {
678
715
  runtimeDetails?: RuntimeDetailsOptions
679
716
  /** @deprecated Use config.viewer.runtimeTraceOptions. */
680
717
  runtimeTraceOptions?: RuntimeTraceProjectionOptions
718
+ formatRuntimeTime?: RuntimeTimeFormatter | null
719
+ runtimeTimeFormat?: RuntimeTimeFormatOptions | null
720
+ i18n?: I18nController | null
721
+ locale?: NovaLocale
722
+ messages?: NovaMessagesOverride | null
681
723
  theme?: NovaThemeInput
682
724
  runtimeAppearance?: RuntimeAppearanceOptions
683
725
  /** @deprecated Use config.export. */
@@ -686,10 +728,13 @@ export interface StudioShellOptions {
686
728
  }
687
729
  export class BpmnStudioShell {
688
730
  constructor(options: StudioShellOptions)
731
+ readonly i18n: I18nController
689
732
  readonly actions: StudioShellActions
690
733
  readonly ui: StudioUiContext
691
734
  canvas?: BpmnCanvas
692
735
  viewer?: BpmnViewer
736
+ setLocale(locale?: NovaLocale | null, messages?: NovaMessagesOverride | null): NovaI18nState
737
+ getLocale(): NovaI18nState
693
738
  getMode(): StudioMode
694
739
  getAllowedModes(): readonly StudioMode[]
695
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',
@@ -8,6 +8,7 @@ import type {
8
8
  ProcessModel,
9
9
  } from '../core/index.js'
10
10
  import type { DiagramRenderer } from '../renderer-svg/index.js'
11
+ import type { I18nController, NovaI18nOptions, NovaLocale, NovaLocaleState, NovaMessagesOverride } from '../i18n/index.js'
11
12
  import type { NovaThemeInput, NovaThemeMode, NovaThemeState, ThemeController } from '../theme/index.js'
12
13
  import type { SvgExportArtifact, SvgExportOptions, SvgExportPreviewController, SvgNodeRenderer } from '../export-svg/index.js'
13
14
 
@@ -18,7 +19,7 @@ export interface DesignerState {
18
19
  canRedo: boolean
19
20
  engine: EngineId
20
21
  }
21
- export interface DesignerOptions {
22
+ export interface DesignerOptions extends NovaI18nOptions {
22
23
  container: HTMLElement
23
24
  model: ProcessModel
24
25
  historyLimit?: number
@@ -35,6 +36,7 @@ export interface DesignerOptions {
35
36
  export function normalizeCanvasCoordinate(value: unknown): number
36
37
  export function canSequenceConnect(model: ProcessModel, sourceId: string, targetId: string): boolean
37
38
  export class BpmnDesigner {
39
+ readonly i18n: I18nController
38
40
  constructor(options: DesignerOptions)
39
41
  model: ProcessModel
40
42
  selection: ElementSelection | null
@@ -54,6 +56,8 @@ export class BpmnDesigner {
54
56
  openSvgExportPreview(options?: SvgExportOptions & { previewTitle?: string; onDownload?: (artifact: SvgExportArtifact) => void }): SvgExportPreviewController
55
57
  importXml(xml: string, engineHint?: EngineId): ProcessModel
56
58
  validate(): Array<{ level: 'error' | 'warning'; elementId?: string; message: string }>
59
+ setLocale(locale?: NovaLocale | null, messages?: NovaMessagesOverride | null): NovaLocaleState
60
+ getLocale(): string
57
61
  setTheme(theme: NovaThemeInput): NovaThemeState
58
62
  setThemeMode(mode: NovaThemeMode): NovaThemeState
59
63
  getThemeState(): NovaThemeState
@@ -1,4 +1,5 @@
1
1
  import { applyContainmentOperation, createNode, createEdge, getNode, getEdge, clearConnectedWaypoints, cloneModel, HistoryStack, autoLayout, beautify, snapNodePosition, NODE_DEFINITIONS, LAYOUT_DENSITIES, resolveSwimlaneLabelPlacement, validateParallelGateway } from '../core/index.js';
2
+ import { createI18n, resolveI18n } from '../i18n/index.js';
2
3
  import { DiagramRenderer } from '../renderer-svg/index.js';
3
4
  import { importBpmn, exportBpmn } from '../bpmn-model/index.js';
4
5
 
@@ -40,6 +41,13 @@ export class BpmnDesigner {
40
41
  constructor(options = {}) {
41
42
  if (!options.container) throw new Error('BpmnDesigner requires container.');
42
43
  this.model = options.model;
44
+ if (options.i18n) {
45
+ this.i18n = resolveI18n(options.i18n);
46
+ this._ownsI18n = false;
47
+ } else {
48
+ this.i18n = createI18n({ locale: options.locale, messages: options.messages });
49
+ this._ownsI18n = true;
50
+ }
43
51
  this.onChange = options.onChange || (() => {});
44
52
  this.onSelectionChange = options.onSelectionChange || (() => {});
45
53
  this.onStateChange = options.onStateChange || (() => {});
@@ -53,6 +61,7 @@ export class BpmnDesigner {
53
61
  themeController: options.themeController,
54
62
  theme: options.theme,
55
63
  onThemeChange: options.onThemeChange,
64
+ i18n: this.i18n,
56
65
  svgExport: options.svgExport,
57
66
  model: this.model,
58
67
  mode: 'design',
@@ -79,6 +88,17 @@ export class BpmnDesigner {
79
88
  this.renderer.destroy();
80
89
  }
81
90
 
91
+ setLocale(locale, messages) {
92
+ if (!this._ownsI18n) {
93
+ this.i18n = createI18n({ locale: locale ?? this.i18n.locale, messages });
94
+ this._ownsI18n = true;
95
+ this.renderer.setLocale(locale, messages);
96
+ return this.i18n.getState();
97
+ }
98
+ return this.i18n.setLocale(locale, messages);
99
+ }
100
+ getLocale() { return this.i18n.locale; }
101
+
82
102
  setTheme(theme) { return this.renderer.setTheme(theme); }
83
103
  setThemeMode(mode) { return this.renderer.setThemeMode(mode); }
84
104
  getThemeState() { return this.renderer.getThemeState(); }
@@ -161,7 +181,7 @@ export class BpmnDesigner {
161
181
  addNode(type, x, y, overrides = {}) {
162
182
  let created;
163
183
  this._commit('add-node', () => {
164
- created = createNode(type, x, y, overrides);
184
+ created = createNode(type, x, y, overrides, { i18n: this.i18n });
165
185
  this.model.nodes.push(created);
166
186
  });
167
187
  this.select({ kind: 'node', id: created.id });
@@ -203,10 +223,10 @@ export class BpmnDesigner {
203
223
  let created;
204
224
  let edge;
205
225
  this._commit('quick-add', () => {
206
- created = createNode(type, Math.round(x), Math.round(y), preset);
226
+ created = createNode(type, Math.round(x), Math.round(y), preset, { i18n: this.i18n });
207
227
  this.model.nodes.push(created);
208
228
  edge = createEdge(sourceId, created.id, {
209
- name: sourceDef.kind === 'gateway' ? `分支 ${outgoingCount + 1}` : '',
229
+ name: sourceDef.kind === 'gateway' ? this.i18n.t('modeling.branchName', { index: outgoingCount + 1 }) : '',
210
230
  });
211
231
  this.model.edges.push(edge);
212
232
  });
@@ -454,7 +474,7 @@ export class BpmnDesigner {
454
474
  }
455
475
 
456
476
  importXml(xml, engineHint) {
457
- const model = importBpmn(xml, engineHint);
477
+ const model = importBpmn(xml, engineHint, { i18n: this.i18n });
458
478
  this.setModel(model, { resetHistory: true });
459
479
  requestAnimationFrame(() => this.renderer.fitReadable(72));
460
480
  return model;
@@ -468,31 +488,32 @@ export class BpmnDesigner {
468
488
  openSvgExportPreview(options) { return this.renderer.openSvgExportPreview(options); }
469
489
 
470
490
  validate() {
491
+ const t = (key, params) => this.i18n.t(key, params);
471
492
  const issues = [];
472
493
  const starts = this.model.nodes.filter((n) => NODE_DEFINITIONS[n.type]?.eventStage === 'start');
473
494
  const ends = this.model.nodes.filter((n) => NODE_DEFINITIONS[n.type]?.eventStage === 'end');
474
- if (!starts.length) issues.push({ level: 'error', message: '流程至少需要一个开始事件。' });
475
- if (!ends.length) issues.push({ level: 'warning', message: '建议至少配置一个结束事件。' });
495
+ if (!starts.length) issues.push({ level: 'error', message: t('validation.missingStartEvent') });
496
+ if (!ends.length) issues.push({ level: 'warning', message: t('validation.missingEndEvent') });
476
497
  for (const edge of this.model.edges) {
477
- if (!getNode(this.model, edge.source) || !getNode(this.model, edge.target)) issues.push({ level: 'error', elementId: edge.id, message: '连线引用了不存在的节点。' });
478
- if ((edge.type || 'sequenceFlow') === 'sequenceFlow' && edge.source === edge.target) issues.push({ level: 'error', elementId: edge.id, message: '顺序流不能连接到自身。' });
498
+ if (!getNode(this.model, edge.source) || !getNode(this.model, edge.target)) issues.push({ level: 'error', elementId: edge.id, message: t('validation.edgeMissingNode') });
499
+ if ((edge.type || 'sequenceFlow') === 'sequenceFlow' && edge.source === edge.target) issues.push({ level: 'error', elementId: edge.id, message: t('validation.sequenceFlowSelfLoop') });
479
500
  }
480
501
  for (const node of this.model.nodes) {
481
502
  const def = NODE_DEFINITIONS[node.type] || NODE_DEFINITIONS.generic;
482
- if (node.type === 'serviceTask' && !node.properties?.implementation) issues.push({ level: 'warning', elementId: node.id, message: `${node.name}: 服务任务尚未配置实现。` });
483
- if (node.type === 'userTask' && !node.properties?.assignee && !node.properties?.candidateUsers && !node.properties?.candidateGroups) issues.push({ level: 'warning', elementId: node.id, message: `${node.name}: 用户任务尚未配置处理人。` });
503
+ if (node.type === 'serviceTask' && !node.properties?.implementation) issues.push({ level: 'warning', elementId: node.id, message: t('validation.serviceTaskMissingImpl', { name: node.name }) });
504
+ if (node.type === 'userTask' && !node.properties?.assignee && !node.properties?.candidateUsers && !node.properties?.candidateGroups) issues.push({ level: 'warning', elementId: node.id, message: t('validation.userTaskMissingAssignee', { name: node.name }) });
484
505
  if (def.kind === 'gateway') {
485
506
  const outgoing = this.model.edges.filter((e) => e.source === node.id && (e.type || 'sequenceFlow') === 'sequenceFlow');
486
507
  if (node.type === 'parallelGateway') {
487
- for (const message of validateParallelGateway(this.model, node)) issues.push({ level: 'warning', elementId: node.id, message: `${node.name}: ${message}` });
488
- } else if (outgoing.length < 2) issues.push({ level: 'warning', elementId: node.id, message: `${node.name}: 网关通常需要至少两个出口。` });
508
+ for (const message of validateParallelGateway(this.model, node, { i18n: this.i18n })) issues.push({ level: 'warning', elementId: node.id, message: t('validation.nodeIssue', { name: node.name, message }) });
509
+ } else if (outgoing.length < 2) issues.push({ level: 'warning', elementId: node.id, message: t('validation.gatewayNeedsTwoOutgoing', { name: node.name }) });
489
510
  if (['exclusiveGateway', 'inclusiveGateway'].includes(node.type)) {
490
511
  const unnamed = outgoing.filter((edge) => !edge.name);
491
- if (outgoing.length >= 2 && unnamed.length) issues.push({ level: 'warning', elementId: node.id, message: `${node.name}: 建议为每条分支线路设置名称,便于审批展示和运行追踪。` });
512
+ if (outgoing.length >= 2 && unnamed.length) issues.push({ level: 'warning', elementId: node.id, message: t('validation.gatewayBranchNeedsName', { name: node.name }) });
492
513
  }
493
514
  }
494
- if (def.kind === 'boundary' && !node.properties?.attachedToRef) issues.push({ level: 'warning', elementId: node.id, message: `${node.name}: 边界事件尚未选择附着活动。` });
495
- if (def.eventDefinition === 'timer' && !node.properties?.timerValue) issues.push({ level: 'warning', elementId: node.id, message: `${node.name}: 定时事件尚未配置定时表达式。` });
515
+ if (def.kind === 'boundary' && !node.properties?.attachedToRef) issues.push({ level: 'warning', elementId: node.id, message: t('validation.boundaryMissingTarget', { name: node.name }) });
516
+ if (def.eventDefinition === 'timer' && !node.properties?.timerValue) issues.push({ level: 'warning', elementId: node.id, message: t('validation.timerMissingExpression', { name: node.name }) });
496
517
  }
497
518
  return issues;
498
519
  }