@bpmn-nova/studio 0.3.9-preview → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/canvas.js +97 -25
- package/dist/config.js +13 -0
- package/dist/context-menu.js +41 -32
- package/dist/controller.js +45 -19
- package/dist/flow-tree.d.ts +4 -0
- package/dist/flow-tree.js +14 -0
- package/dist/index.d.ts +47 -2
- package/dist/index.js +1 -0
- package/dist/interactions.js +6 -1
- package/dist/modules/bpmn-model/index.d.ts +2 -1
- package/dist/modules/bpmn-model/index.js +12 -10
- package/dist/modules/core/gateway.js +16 -13
- package/dist/modules/core/index.d.ts +6 -4
- package/dist/modules/core/model.js +12 -7
- package/dist/modules/designer/index.d.ts +5 -1
- package/dist/modules/designer/index.js +36 -15
- package/dist/modules/export-svg/index.d.ts +12 -5
- package/dist/modules/export-svg/preview.js +34 -24
- package/dist/modules/export-svg/render.js +102 -50
- package/dist/modules/flow-tree/controller.js +364 -0
- package/dist/modules/flow-tree/index.d.ts +248 -0
- package/dist/modules/flow-tree/index.js +5 -0
- package/dist/modules/flow-tree/operations.js +484 -0
- package/dist/modules/flow-tree/sample.js +445 -0
- package/dist/modules/flow-tree/schema.js +588 -0
- package/dist/modules/flow-tree/validate.js +125 -0
- package/dist/modules/flow-tree-bpmn/compiler.js +547 -0
- package/dist/modules/flow-tree-bpmn/decompiler.js +524 -0
- package/dist/modules/flow-tree-bpmn/expression.js +135 -0
- package/dist/modules/flow-tree-bpmn/index.d.ts +53 -0
- package/dist/modules/flow-tree-bpmn/index.js +14 -0
- package/dist/modules/flow-tree-renderer/canvas.js +1003 -0
- package/dist/modules/flow-tree-renderer/export-svg.js +325 -0
- package/dist/modules/flow-tree-renderer/index.d.ts +143 -0
- package/dist/modules/flow-tree-renderer/index.js +3 -0
- package/dist/modules/flow-tree-renderer/shell.js +970 -0
- package/dist/modules/i18n/index.d.ts +647 -0
- package/dist/modules/i18n/index.js +247 -0
- package/dist/modules/i18n/locales/en-US.js +1222 -0
- package/dist/modules/i18n/locales/zh-CN.js +1204 -0
- package/dist/modules/icons/index.js +23 -0
- package/dist/modules/node-presentation/index.d.ts +3 -2
- package/dist/modules/node-presentation/index.js +14 -11
- package/dist/modules/palette/index.d.ts +6 -1
- package/dist/modules/palette/index.js +26 -8
- package/dist/modules/palette/panel.js +44 -6
- package/dist/modules/properties/index.d.ts +2 -1
- package/dist/modules/properties/index.js +2 -2
- package/dist/modules/properties-activiti/index.js +84 -59
- package/dist/modules/properties-bpmn/index.js +151 -128
- package/dist/modules/properties-core/index.d.ts +9 -3
- package/dist/modules/properties-core/index.js +16 -4
- package/dist/modules/properties-flow-tree/index.d.ts +56 -0
- package/dist/modules/properties-flow-tree/index.js +2 -0
- package/dist/modules/properties-flow-tree/panel.js +1136 -0
- package/dist/modules/properties-flow-tree/widgets.js +625 -0
- package/dist/modules/properties-flowable/index.js +55 -34
- package/dist/modules/properties-renderer/index.d.ts +5 -1
- package/dist/modules/properties-renderer/index.js +110 -42
- package/dist/modules/renderer-svg/index.d.ts +6 -2
- package/dist/modules/renderer-svg/index.js +113 -38
- package/dist/modules/runtime/index.d.ts +33 -5
- package/dist/modules/runtime/index.js +97 -73
- package/dist/modules/runtime/time.js +89 -4
- package/dist/modules/runtime/visits.js +6 -4
- package/dist/modules/theme/index.d.ts +5 -2
- package/dist/modules/theme/index.js +8 -4
- package/dist/modules/viewer/index.d.ts +28 -7
- package/dist/modules/viewer/index.js +223 -58
- package/dist/modules/viewer/runtime-content.js +26 -20
- package/dist/modules/viewer/runtime-trace.js +43 -25
- package/dist/modules/viewer/timeline.js +103 -36
- package/dist/shell.js +258 -75
- package/dist/sidebars.js +3 -1
- package/dist/styles.css +2371 -2
- package/llms-full.txt +586 -47
- package/llms.txt +6 -5
- package/package.json +7 -3
|
@@ -0,0 +1,1003 @@
|
|
|
1
|
+
import { createI18n, resolveI18n } from '../i18n/index.js';
|
|
2
|
+
import { createDefaultIconRegistry, hydrateIcons } from '../icons/index.js';
|
|
3
|
+
import { ThemeController, applyRuntimeTone, createRuntimeAppearance } from '../theme/index.js';
|
|
4
|
+
import { createRuntimePresentation } from '../runtime/index.js';
|
|
5
|
+
import { renderDefaultRuntimeDetails } from '../viewer/index.js';
|
|
6
|
+
import { openSvgExportPreview } from '../export-svg/index.js';
|
|
7
|
+
import {
|
|
8
|
+
FLOW_TREE_NODE_DEFINITIONS,
|
|
9
|
+
countBranchSteps,
|
|
10
|
+
findFlowTreeNode,
|
|
11
|
+
formatFlowTreeNodeSummary,
|
|
12
|
+
isRouteNode,
|
|
13
|
+
resolveFlowTreeTypeLabel,
|
|
14
|
+
} from '../flow-tree/index.js';
|
|
15
|
+
import { compileFlowTreeToBpmn } from '../flow-tree-bpmn/index.js';
|
|
16
|
+
import { exportFlowTreeSvg } from './export-svg.js';
|
|
17
|
+
|
|
18
|
+
const ZOOM_MIN = 0.3;
|
|
19
|
+
const ZOOM_MAX = 2.0;
|
|
20
|
+
|
|
21
|
+
function el(tag, className = '', text = undefined) {
|
|
22
|
+
const node = document.createElement(tag);
|
|
23
|
+
if (className) node.className = className;
|
|
24
|
+
if (text !== undefined) node.textContent = text;
|
|
25
|
+
return node;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function icon(id, className = 'nova-icon nova-icon-sm') {
|
|
29
|
+
const span = el('span', className);
|
|
30
|
+
span.dataset.icon = id;
|
|
31
|
+
return span;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function clamp(value, min, max) {
|
|
35
|
+
return Math.max(min, Math.min(max, value));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export class FlowTreeCanvas {
|
|
39
|
+
constructor(options = {}) {
|
|
40
|
+
const {
|
|
41
|
+
container,
|
|
42
|
+
controller,
|
|
43
|
+
mode = 'design',
|
|
44
|
+
runtime = null,
|
|
45
|
+
runtimeAppearance = null,
|
|
46
|
+
runtimeAssetResolver = null,
|
|
47
|
+
formatRuntimeTime = null,
|
|
48
|
+
runtimeTimeFormat = null,
|
|
49
|
+
nodeSummaryResolver = null,
|
|
50
|
+
nodeCardRenderer = null,
|
|
51
|
+
iconRegistry = createDefaultIconRegistry(),
|
|
52
|
+
themeController = null,
|
|
53
|
+
theme = null,
|
|
54
|
+
onThemeChange = null,
|
|
55
|
+
onNodeClick = null,
|
|
56
|
+
onViewportChange = null,
|
|
57
|
+
i18n = null,
|
|
58
|
+
locale,
|
|
59
|
+
messages,
|
|
60
|
+
} = options;
|
|
61
|
+
|
|
62
|
+
if (!container) throw new Error('FlowTreeCanvas requires a container.');
|
|
63
|
+
if (!controller) throw new Error('FlowTreeCanvas requires a FlowTreeController.');
|
|
64
|
+
|
|
65
|
+
this.container = container;
|
|
66
|
+
this.controller = controller;
|
|
67
|
+
this.mode = ['design', 'viewer', 'instance'].includes(mode) ? mode : 'design';
|
|
68
|
+
this.runtime = runtime;
|
|
69
|
+
this.runtimeAppearanceOptions = runtimeAppearance || {};
|
|
70
|
+
this.runtimeAssetResolver = runtimeAssetResolver;
|
|
71
|
+
this.formatRuntimeTime = formatRuntimeTime;
|
|
72
|
+
this.runtimeTimeFormat = runtimeTimeFormat;
|
|
73
|
+
this.nodeSummaryResolver = nodeSummaryResolver;
|
|
74
|
+
this.nodeCardRenderer = nodeCardRenderer;
|
|
75
|
+
this.iconRegistry = iconRegistry;
|
|
76
|
+
this.onNodeClick = onNodeClick;
|
|
77
|
+
this.onViewportChange = onViewportChange;
|
|
78
|
+
|
|
79
|
+
if (i18n) {
|
|
80
|
+
this.i18n = resolveI18n(i18n);
|
|
81
|
+
this._ownsI18n = false;
|
|
82
|
+
} else if (locale !== undefined || messages !== undefined) {
|
|
83
|
+
this.i18n = createI18n({ locale, messages });
|
|
84
|
+
this._ownsI18n = true;
|
|
85
|
+
} else if (controller.i18n) {
|
|
86
|
+
this.i18n = controller.i18n;
|
|
87
|
+
this._ownsI18n = false;
|
|
88
|
+
} else {
|
|
89
|
+
this.i18n = createI18n();
|
|
90
|
+
this._ownsI18n = true;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
this.themeController = themeController || new ThemeController({ root: container, theme, onChange: onThemeChange });
|
|
94
|
+
this._ownsThemeController = !themeController;
|
|
95
|
+
this.runtimeAppearance = createRuntimeAppearance(this.runtimeAppearanceOptions, { i18n: this.i18n });
|
|
96
|
+
|
|
97
|
+
this.zoom = 1;
|
|
98
|
+
this.pan = { x: 0, y: 0 };
|
|
99
|
+
this._panning = null;
|
|
100
|
+
this._draggingNodeId = null;
|
|
101
|
+
this._addMenu = null;
|
|
102
|
+
this._addMenuAnchor = null;
|
|
103
|
+
this._pendingCardDown = null;
|
|
104
|
+
this._knownNodeIds = new Set();
|
|
105
|
+
this._hasRenderedOnce = false;
|
|
106
|
+
this._hasInitialFit = false;
|
|
107
|
+
this._transformAnimTimer = null;
|
|
108
|
+
this._detailsCleanup = null;
|
|
109
|
+
this._detailsRoot = null;
|
|
110
|
+
this._cardCleanups = [];
|
|
111
|
+
this._svgExportPreview = null;
|
|
112
|
+
this._runtimePresentation = null;
|
|
113
|
+
|
|
114
|
+
this._buildFrame();
|
|
115
|
+
this._bindEvents();
|
|
116
|
+
|
|
117
|
+
this._offController = controller.subscribe((event) => {
|
|
118
|
+
if (event.type === 'localeChanged') {
|
|
119
|
+
this.runtimeAppearance = createRuntimeAppearance(this.runtimeAppearanceOptions, { i18n: this.i18n });
|
|
120
|
+
}
|
|
121
|
+
this.render();
|
|
122
|
+
});
|
|
123
|
+
this._offI18n = this._ownsI18n ? this.i18n.subscribe(() => {
|
|
124
|
+
this.runtimeAppearance = createRuntimeAppearance(this.runtimeAppearanceOptions, { i18n: this.i18n });
|
|
125
|
+
this.render();
|
|
126
|
+
}) : null;
|
|
127
|
+
|
|
128
|
+
if (typeof ResizeObserver !== 'undefined') {
|
|
129
|
+
this._resizeObserver = new ResizeObserver(() => {
|
|
130
|
+
if (!this._hasInitialFit) this.fitView(56, { animate: false });
|
|
131
|
+
});
|
|
132
|
+
this._resizeObserver.observe(this.viewport);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
this.render();
|
|
136
|
+
requestAnimationFrame(() => this.fitView(56, { animate: false }));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
_t(key, params) {
|
|
140
|
+
return this.i18n.t(key, params);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
_buildFrame() {
|
|
144
|
+
this.container.innerHTML = '';
|
|
145
|
+
this.container.classList.add('nova-ft-canvas');
|
|
146
|
+
this.container.tabIndex = this.container.tabIndex >= 0 ? this.container.tabIndex : 0;
|
|
147
|
+
|
|
148
|
+
this.viewport = el('div', 'ft-viewport');
|
|
149
|
+
this.stage = el('div', 'ft-stage');
|
|
150
|
+
this.treeHost = el('div', 'ft-tree-host');
|
|
151
|
+
this.stage.appendChild(this.treeHost);
|
|
152
|
+
this.viewport.appendChild(this.stage);
|
|
153
|
+
|
|
154
|
+
this.overlayHost = el('div', 'ft-overlay-host');
|
|
155
|
+
this.container.append(this.viewport, this.overlayHost);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
_bindEvents() {
|
|
159
|
+
this._onWheel = (event) => {
|
|
160
|
+
if (event.target?.closest?.('.ft-add-menu, .mb-runtime-details-popover')) return;
|
|
161
|
+
event.preventDefault();
|
|
162
|
+
this._stopTransformAnimation();
|
|
163
|
+
if (event.ctrlKey || event.metaKey) {
|
|
164
|
+
const factor = event.deltaY < 0 ? 1.1 : 0.9;
|
|
165
|
+
this._zoomAtClientPoint(this.zoom * factor, event.clientX, event.clientY, { animate: false });
|
|
166
|
+
} else {
|
|
167
|
+
this.pan.x -= event.deltaX;
|
|
168
|
+
this.pan.y -= event.deltaY;
|
|
169
|
+
this._applyTransform({ animate: false });
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
this._onPointerDown = (event) => {
|
|
174
|
+
if (event.button !== 0) return;
|
|
175
|
+
const cardOrEnd = event.target?.closest?.('.ft-card, .ft-end-node');
|
|
176
|
+
if (cardOrEnd) {
|
|
177
|
+
if (!event.target?.closest?.('.ft-card-action, .ft-branch-shift')) {
|
|
178
|
+
const nodeId = cardOrEnd.dataset?.ftNodeId;
|
|
179
|
+
if (nodeId) {
|
|
180
|
+
this._pendingCardDown = {
|
|
181
|
+
nodeId,
|
|
182
|
+
x: event.clientX,
|
|
183
|
+
y: event.clientY,
|
|
184
|
+
handled: false,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (event.target?.closest?.('.ft-add-btn, .ft-add-branch-btn, .ft-add-menu, .ft-branch-collapsed-pill, .mb-runtime-details-popover, button, input')) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
this._stopTransformAnimation();
|
|
194
|
+
this._closeAddMenu();
|
|
195
|
+
this.closeRuntimeDetails();
|
|
196
|
+
this._panning = {
|
|
197
|
+
startX: event.clientX,
|
|
198
|
+
startY: event.clientY,
|
|
199
|
+
originX: this.pan.x,
|
|
200
|
+
originY: this.pan.y,
|
|
201
|
+
moved: false,
|
|
202
|
+
};
|
|
203
|
+
this.viewport.classList.add('is-panning');
|
|
204
|
+
this.viewport.setPointerCapture?.(event.pointerId);
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
this._onPointerMove = (event) => {
|
|
208
|
+
if (!this._panning) return;
|
|
209
|
+
const dx = event.clientX - this._panning.startX;
|
|
210
|
+
const dy = event.clientY - this._panning.startY;
|
|
211
|
+
if (Math.hypot(dx, dy) > 3) this._panning.moved = true;
|
|
212
|
+
this.pan.x = this._panning.originX + dx;
|
|
213
|
+
this.pan.y = this._panning.originY + dy;
|
|
214
|
+
this._applyTransform({ animate: false });
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
this._onPointerUp = (event) => {
|
|
218
|
+
if (this._pendingCardDown) {
|
|
219
|
+
const pending = this._pendingCardDown;
|
|
220
|
+
const moved = Math.hypot(event.clientX - pending.x, event.clientY - pending.y) > 6;
|
|
221
|
+
queueMicrotask(() => {
|
|
222
|
+
if (this._pendingCardDown === pending) this._pendingCardDown = null;
|
|
223
|
+
if (!moved && !pending.handled && !this._draggingNodeId && this.container.isConnected) {
|
|
224
|
+
this._activateNodeById(pending.nodeId);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
if (!this._panning) return;
|
|
229
|
+
const wasClick = !this._panning.moved;
|
|
230
|
+
this._panning = null;
|
|
231
|
+
this.viewport.classList.remove('is-panning');
|
|
232
|
+
this.viewport.releasePointerCapture?.(event.pointerId);
|
|
233
|
+
if (wasClick) {
|
|
234
|
+
this.container.focus({ preventScroll: true });
|
|
235
|
+
if (this.mode === 'design') {
|
|
236
|
+
this.controller.commands.select({ kind: 'process', id: this.controller.document.id });
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
this._onOutsidePointerDown = (event) => {
|
|
242
|
+
if (this._addMenu && !this._addMenu.contains(event.target) && !event.target?.closest?.('.ft-add-btn')) {
|
|
243
|
+
this._closeAddMenu();
|
|
244
|
+
}
|
|
245
|
+
if (this._detailsRoot && !this._detailsRoot.contains(event.target) && !event.target?.closest?.('.ft-card')) {
|
|
246
|
+
this.closeRuntimeDetails();
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
this._onKeyDown = (event) => {
|
|
251
|
+
if (event.key === 'Escape') {
|
|
252
|
+
this._closeAddMenu();
|
|
253
|
+
this.closeRuntimeDetails();
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (this.mode !== 'design') return;
|
|
257
|
+
if (event.target?.closest?.('input, textarea, select, [contenteditable="true"]')) return;
|
|
258
|
+
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === 'z') {
|
|
259
|
+
event.preventDefault();
|
|
260
|
+
if (event.shiftKey) this.controller.commands.redo();
|
|
261
|
+
else this.controller.commands.undo();
|
|
262
|
+
} else if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === 'y') {
|
|
263
|
+
event.preventDefault();
|
|
264
|
+
this.controller.commands.redo();
|
|
265
|
+
} else if (event.key === 'Delete' || event.key === 'Backspace') {
|
|
266
|
+
const selected = this.controller.getSelectedNode();
|
|
267
|
+
if (selected && !['starter', 'end'].includes(selected.type)) {
|
|
268
|
+
event.preventDefault();
|
|
269
|
+
this.controller.commands.removeNode(selected.id);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
this.viewport.addEventListener('wheel', this._onWheel, { passive: false });
|
|
275
|
+
this.viewport.addEventListener('pointerdown', this._onPointerDown);
|
|
276
|
+
window.addEventListener('pointermove', this._onPointerMove);
|
|
277
|
+
window.addEventListener('pointerup', this._onPointerUp);
|
|
278
|
+
document.addEventListener('pointerdown', this._onOutsidePointerDown, true);
|
|
279
|
+
this.container.addEventListener('keydown', this._onKeyDown);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
_stopTransformAnimation() {
|
|
283
|
+
if (this._transformAnimTimer) {
|
|
284
|
+
clearTimeout(this._transformAnimTimer);
|
|
285
|
+
this._transformAnimTimer = null;
|
|
286
|
+
}
|
|
287
|
+
this.stage?.classList.remove('is-animating');
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
_applyTransform({ animate = false } = {}) {
|
|
291
|
+
if (animate) {
|
|
292
|
+
this.stage.classList.add('is-animating');
|
|
293
|
+
if (this._transformAnimTimer) clearTimeout(this._transformAnimTimer);
|
|
294
|
+
this._transformAnimTimer = setTimeout(() => {
|
|
295
|
+
this.stage?.classList.remove('is-animating');
|
|
296
|
+
this._transformAnimTimer = null;
|
|
297
|
+
}, 220);
|
|
298
|
+
} else {
|
|
299
|
+
this._stopTransformAnimation();
|
|
300
|
+
}
|
|
301
|
+
this.stage.style.transform = `translate3d(${Math.round(this.pan.x)}px, ${Math.round(this.pan.y)}px, 0) scale(${this.zoom})`;
|
|
302
|
+
this.onViewportChange?.({ zoom: this.zoom, pan: { ...this.pan } });
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
_zoomAtClientPoint(nextZoom, clientX, clientY, { animate = false } = {}) {
|
|
306
|
+
const rect = this.viewport.getBoundingClientRect();
|
|
307
|
+
const clamped = Math.round(clamp(nextZoom, ZOOM_MIN, ZOOM_MAX) * 100) / 100;
|
|
308
|
+
const vx = clientX - rect.left;
|
|
309
|
+
const vy = clientY - rect.top;
|
|
310
|
+
const worldX = (vx - this.pan.x) / this.zoom;
|
|
311
|
+
const worldY = (vy - this.pan.y) / this.zoom;
|
|
312
|
+
this.zoom = clamped;
|
|
313
|
+
this.pan.x = vx - worldX * this.zoom;
|
|
314
|
+
this.pan.y = vy - worldY * this.zoom;
|
|
315
|
+
this._applyTransform({ animate });
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
zoomIn() {
|
|
319
|
+
const rect = this.viewport.getBoundingClientRect();
|
|
320
|
+
this._zoomAtClientPoint(this.zoom + 0.1, rect.left + rect.width / 2, rect.top + rect.height / 2, { animate: true });
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
zoomOut() {
|
|
324
|
+
const rect = this.viewport.getBoundingClientRect();
|
|
325
|
+
this._zoomAtClientPoint(this.zoom - 0.1, rect.left + rect.width / 2, rect.top + rect.height / 2, { animate: true });
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
actualSize() {
|
|
329
|
+
const rect = this.viewport.getBoundingClientRect();
|
|
330
|
+
const contentW = Math.max(this.treeHost.offsetWidth, this.treeHost.scrollWidth) || 260;
|
|
331
|
+
this.zoom = 1;
|
|
332
|
+
this.pan.x = Math.round((rect.width - contentW) / 2);
|
|
333
|
+
this.pan.y = 32;
|
|
334
|
+
this._applyTransform({ animate: true });
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
fitView(padding = 28, { animate = false } = {}) {
|
|
338
|
+
const rect = this.viewport.getBoundingClientRect();
|
|
339
|
+
if (rect.width < 10 || rect.height < 10) return;
|
|
340
|
+
this._hasInitialFit = true;
|
|
341
|
+
const contentW = Math.max(this.treeHost.offsetWidth, this.treeHost.scrollWidth) || 260;
|
|
342
|
+
const contentH = Math.max(this.treeHost.offsetHeight, this.treeHost.scrollHeight) || 360;
|
|
343
|
+
const scaleX = (rect.width - padding * 2) / Math.max(contentW, 1);
|
|
344
|
+
const scaleY = (rect.height - padding * 2) / Math.max(contentH, 1);
|
|
345
|
+
const nextZoom = clamp(Math.min(scaleX, scaleY, 1), ZOOM_MIN, 1);
|
|
346
|
+
this.zoom = Math.round(nextZoom * 20) / 20;
|
|
347
|
+
this.pan.x = Math.round((rect.width - contentW * this.zoom) / 2);
|
|
348
|
+
this.pan.y = Math.round(contentH * this.zoom < rect.height - padding * 2
|
|
349
|
+
? (rect.height - contentH * this.zoom) / 2
|
|
350
|
+
: padding);
|
|
351
|
+
this._applyTransform({ animate });
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
revealNode(nodeId) {
|
|
355
|
+
const card = this.treeHost.querySelector(`[data-ft-node-id="${CSS.escape(nodeId)}"]`);
|
|
356
|
+
if (!card) return false;
|
|
357
|
+
const vpRect = this.viewport.getBoundingClientRect();
|
|
358
|
+
const cardRect = card.getBoundingClientRect();
|
|
359
|
+
const targetX = vpRect.left + vpRect.width / 2;
|
|
360
|
+
const targetY = vpRect.top + vpRect.height * 0.38;
|
|
361
|
+
this.pan.x += targetX - (cardRect.left + cardRect.width / 2);
|
|
362
|
+
this.pan.y += targetY - (cardRect.top + cardRect.height / 2);
|
|
363
|
+
this._applyTransform({ animate: true });
|
|
364
|
+
card.classList.remove('is-pulsed');
|
|
365
|
+
void card.offsetWidth;
|
|
366
|
+
card.classList.add('is-pulsed');
|
|
367
|
+
return true;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
_activateNodeById(nodeId) {
|
|
371
|
+
const node = findFlowTreeNode(this.controller.document, nodeId);
|
|
372
|
+
if (!node) return;
|
|
373
|
+
this._closeAddMenu();
|
|
374
|
+
this.controller.commands.select({ kind: 'node', id: node.id });
|
|
375
|
+
this.container.focus({ preventScroll: true });
|
|
376
|
+
const runtimeState = this.mode === 'instance' ? this._runtimePresentation?.getNode?.(node.id) : null;
|
|
377
|
+
this.onNodeClick?.(node, runtimeState);
|
|
378
|
+
if (this.mode === 'instance' && runtimeState && (runtimeState.records?.length || runtimeState.actions?.length || runtimeState.status !== 'idle')) {
|
|
379
|
+
this._openRuntimeDetails(node, runtimeState);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
getViewportState() {
|
|
384
|
+
return { zoom: this.zoom, pan: { ...this.pan } };
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
setViewportState(state) {
|
|
388
|
+
if (!state) return false;
|
|
389
|
+
this.zoom = clamp(Number(state.zoom) || 1, ZOOM_MIN, ZOOM_MAX);
|
|
390
|
+
this.pan = { x: Number(state.pan?.x || 0), y: Number(state.pan?.y || 0) };
|
|
391
|
+
this._applyTransform();
|
|
392
|
+
return true;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
setMode(mode) {
|
|
396
|
+
if (!['design', 'viewer', 'instance'].includes(mode)) return;
|
|
397
|
+
this.mode = mode;
|
|
398
|
+
this._closeAddMenu();
|
|
399
|
+
this.closeRuntimeDetails();
|
|
400
|
+
this.render();
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
setRuntime(runtime) {
|
|
404
|
+
this.runtime = runtime;
|
|
405
|
+
this.closeRuntimeDetails();
|
|
406
|
+
this.render();
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
setTheme(theme) { return this.themeController.setTheme(theme); }
|
|
410
|
+
setLocale(locale, messages) {
|
|
411
|
+
if (!this._ownsI18n && this.controller?.setLocale) return this.controller.setLocale(locale, messages);
|
|
412
|
+
return this.i18n.setLocale(locale, messages);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
exportSvg(options = {}) {
|
|
416
|
+
return exportFlowTreeSvg({
|
|
417
|
+
document: this.controller.document,
|
|
418
|
+
runtimePresentation: this.mode === 'instance' ? this._runtimePresentation : null,
|
|
419
|
+
runtimeAppearance: this.runtimeAppearance,
|
|
420
|
+
themeController: this.themeController,
|
|
421
|
+
iconRegistry: this.iconRegistry,
|
|
422
|
+
nodeRegistry: this.controller.nodeRegistry,
|
|
423
|
+
nodeSummaryResolver: this.nodeSummaryResolver,
|
|
424
|
+
i18n: this.i18n,
|
|
425
|
+
}, options);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
openSvgExportPreview(options = {}) {
|
|
429
|
+
if (this._svgExportPreview && !this._svgExportPreview.closed) {
|
|
430
|
+
this._svgExportPreview.focus();
|
|
431
|
+
return this._svgExportPreview;
|
|
432
|
+
}
|
|
433
|
+
this._svgExportPreview = openSvgExportPreview({
|
|
434
|
+
container: this.container,
|
|
435
|
+
title: options.previewTitle || this._t('exportSvg.preview.defaultTitle'),
|
|
436
|
+
initialTheme: options.theme || 'current',
|
|
437
|
+
i18n: this.i18n,
|
|
438
|
+
createArtifact: (previewOptions) => this.exportSvg({ ...options, ...previewOptions }),
|
|
439
|
+
onClose: () => { this._svgExportPreview = null; },
|
|
440
|
+
onDownload: options.onDownload,
|
|
441
|
+
});
|
|
442
|
+
return this._svgExportPreview;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
_closeAddMenu() {
|
|
446
|
+
if (this._addMenu) {
|
|
447
|
+
this._addMenu.remove();
|
|
448
|
+
this._addMenu = null;
|
|
449
|
+
}
|
|
450
|
+
this._addMenuAnchor = null;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
closeRuntimeDetails() {
|
|
454
|
+
this._detailsCleanup?.();
|
|
455
|
+
this._detailsCleanup = null;
|
|
456
|
+
this._detailsRoot = null;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
_openRuntimeDetails(node, presentation) {
|
|
460
|
+
this.closeRuntimeDetails();
|
|
461
|
+
if (!presentation) return;
|
|
462
|
+
const host = el('div', 'ft-runtime-details-wrap');
|
|
463
|
+
this.overlayHost.appendChild(host);
|
|
464
|
+
this._detailsRoot = host;
|
|
465
|
+
const cleanup = renderDefaultRuntimeDetails({
|
|
466
|
+
container: host,
|
|
467
|
+
viewer: {
|
|
468
|
+
i18n: this.i18n,
|
|
469
|
+
runtimeAppearance: this.runtimeAppearance,
|
|
470
|
+
formatRuntimeTime: this.formatRuntimeTime,
|
|
471
|
+
runtimeTimeFormat: this.runtimeTimeFormat,
|
|
472
|
+
},
|
|
473
|
+
node,
|
|
474
|
+
presentation,
|
|
475
|
+
close: () => this.closeRuntimeDetails(),
|
|
476
|
+
resolveAsset: this.runtimeAssetResolver,
|
|
477
|
+
i18n: this.i18n,
|
|
478
|
+
formatRuntimeTime: this.formatRuntimeTime,
|
|
479
|
+
runtimeTimeFormat: this.runtimeTimeFormat,
|
|
480
|
+
});
|
|
481
|
+
this._detailsCleanup = () => {
|
|
482
|
+
cleanup?.();
|
|
483
|
+
host.remove();
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
_openAddMenu(anchorButton, containerRef, index, hasTrailingSteps) {
|
|
488
|
+
if (this._addMenu && this._addMenuAnchor === anchorButton) {
|
|
489
|
+
this._closeAddMenu();
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
this._closeAddMenu();
|
|
493
|
+
this._addMenuAnchor = anchorButton;
|
|
494
|
+
const menu = el('div', 'ft-add-menu');
|
|
495
|
+
menu.setAttribute('role', 'dialog');
|
|
496
|
+
menu.setAttribute('aria-label', this._t('flowTree.addMenu.title'));
|
|
497
|
+
|
|
498
|
+
const header = el('div', 'ft-add-menu-head');
|
|
499
|
+
header.append(
|
|
500
|
+
el('strong', '', this._t('flowTree.addMenu.title')),
|
|
501
|
+
(() => {
|
|
502
|
+
const closeBtn = el('button', 'ft-icon-btn');
|
|
503
|
+
closeBtn.type = 'button';
|
|
504
|
+
closeBtn.appendChild(icon('ui.close', 'nova-icon nova-icon-xs'));
|
|
505
|
+
closeBtn.addEventListener('click', () => this._closeAddMenu());
|
|
506
|
+
return closeBtn;
|
|
507
|
+
})(),
|
|
508
|
+
);
|
|
509
|
+
menu.appendChild(header);
|
|
510
|
+
|
|
511
|
+
let wrapFollowing = false;
|
|
512
|
+
if (hasTrailingSteps) {
|
|
513
|
+
const wrapLabel = el('label', 'ft-add-menu-wrap');
|
|
514
|
+
const checkbox = document.createElement('input');
|
|
515
|
+
checkbox.type = 'checkbox';
|
|
516
|
+
checkbox.addEventListener('change', () => { wrapFollowing = checkbox.checked; });
|
|
517
|
+
wrapLabel.append(checkbox, el('span', '', this._t('flowTree.addMenu.wrapFollowing')));
|
|
518
|
+
menu.appendChild(wrapLabel);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
const insertable = this.controller.nodeRegistry.listInsertable();
|
|
522
|
+
const groups = [
|
|
523
|
+
{ id: 'approval', title: this._t('flowTree.addMenu.groups.approval') },
|
|
524
|
+
{ id: 'routing', title: this._t('flowTree.addMenu.groups.routing') },
|
|
525
|
+
{ id: 'automation', title: this._t('flowTree.addMenu.groups.automation') },
|
|
526
|
+
{ id: 'custom', title: this._t('flowTree.addMenu.groups.custom') },
|
|
527
|
+
];
|
|
528
|
+
|
|
529
|
+
for (const group of groups) {
|
|
530
|
+
const items = insertable.filter((item) => (item.group || 'custom') === group.id);
|
|
531
|
+
if (!items.length) continue;
|
|
532
|
+
const section = el('div', 'ft-add-menu-group');
|
|
533
|
+
section.appendChild(el('div', 'ft-add-menu-group-title', group.title));
|
|
534
|
+
const grid = el('div', 'ft-add-menu-grid');
|
|
535
|
+
for (const def of items) {
|
|
536
|
+
const btn = el('button', `ft-add-menu-item tone-${def.tone || 'primary'}`);
|
|
537
|
+
btn.type = 'button';
|
|
538
|
+
const iconWrap = el('span', `ft-add-menu-icon tone-${def.tone || 'primary'}`);
|
|
539
|
+
iconWrap.appendChild(icon(def.iconId || 'flowTree.trigger', 'nova-icon nova-icon-sm'));
|
|
540
|
+
const copy = el('span', 'ft-add-menu-copy');
|
|
541
|
+
const label = resolveFlowTreeTypeLabel(def.type, { i18n: this.i18n, nodeRegistry: this.controller.nodeRegistry });
|
|
542
|
+
const descKey = `flowTree.nodeDescriptions.${def.type}`;
|
|
543
|
+
const desc = def.description || (this.i18n.t(descKey) !== descKey ? this.i18n.t(descKey) : '');
|
|
544
|
+
copy.append(el('strong', '', label), ...(desc ? [el('small', '', desc)] : []));
|
|
545
|
+
btn.append(iconWrap, copy);
|
|
546
|
+
btn.addEventListener('click', () => {
|
|
547
|
+
this._closeAddMenu();
|
|
548
|
+
if (def.kind === 'route') {
|
|
549
|
+
this.controller.commands.insertRoute(containerRef, index, def.type, { wrapFollowingSteps: wrapFollowing });
|
|
550
|
+
} else {
|
|
551
|
+
this.controller.commands.insertStep(containerRef, index, def.type);
|
|
552
|
+
}
|
|
553
|
+
});
|
|
554
|
+
grid.appendChild(btn);
|
|
555
|
+
}
|
|
556
|
+
section.appendChild(grid);
|
|
557
|
+
menu.appendChild(section);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
this.overlayHost.appendChild(menu);
|
|
561
|
+
hydrateIcons(menu, this.iconRegistry);
|
|
562
|
+
|
|
563
|
+
const hostRect = this.container.getBoundingClientRect();
|
|
564
|
+
const btnRect = anchorButton.getBoundingClientRect();
|
|
565
|
+
const menuRect = menu.getBoundingClientRect();
|
|
566
|
+
const bottomSafe = 54;
|
|
567
|
+
let left = btnRect.left - hostRect.left + btnRect.width / 2 - menuRect.width / 2;
|
|
568
|
+
let top = btnRect.bottom - hostRect.top + 8;
|
|
569
|
+
left = clamp(left, 12, Math.max(12, hostRect.width - menuRect.width - 12));
|
|
570
|
+
if (top + menuRect.height > hostRect.height - bottomSafe) {
|
|
571
|
+
const aboveTop = btnRect.top - hostRect.top - menuRect.height - 8;
|
|
572
|
+
top = aboveTop >= 12
|
|
573
|
+
? aboveTop
|
|
574
|
+
: clamp(hostRect.height - menuRect.height - bottomSafe, 12, Math.max(12, hostRect.height - menuRect.height - 12));
|
|
575
|
+
}
|
|
576
|
+
menu.style.left = `${Math.round(left)}px`;
|
|
577
|
+
menu.style.top = `${Math.round(top)}px`;
|
|
578
|
+
this._addMenu = menu;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
_buildAddSlot(containerRef, index, totalLength) {
|
|
582
|
+
const slot = el('div', 'ft-add-slot');
|
|
583
|
+
slot.dataset.ftContainer = JSON.stringify(containerRef);
|
|
584
|
+
slot.dataset.ftIndex = String(index);
|
|
585
|
+
|
|
586
|
+
const lineTop = el('span', 'ft-spine-line');
|
|
587
|
+
const lineBottom = el('span', 'ft-spine-line');
|
|
588
|
+
|
|
589
|
+
if (this.mode === 'design') {
|
|
590
|
+
const btn = el('button', 'ft-add-btn');
|
|
591
|
+
btn.type = 'button';
|
|
592
|
+
btn.title = this._t('flowTree.canvas.addNodeAria');
|
|
593
|
+
btn.setAttribute('aria-label', this._t('flowTree.canvas.addNodeAria'));
|
|
594
|
+
btn.appendChild(icon('ui.add', 'nova-icon nova-icon-xs'));
|
|
595
|
+
btn.addEventListener('click', (event) => {
|
|
596
|
+
event.stopPropagation();
|
|
597
|
+
this._openAddMenu(btn, containerRef, index, index < totalLength);
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
// Drag-and-drop dropzone
|
|
601
|
+
slot.addEventListener('dragover', (event) => {
|
|
602
|
+
if (!this._draggingNodeId) return;
|
|
603
|
+
if (!this.controller.commands.canMoveNode(this._draggingNodeId, containerRef)) return;
|
|
604
|
+
event.preventDefault();
|
|
605
|
+
slot.classList.add('is-drop-active');
|
|
606
|
+
});
|
|
607
|
+
slot.addEventListener('dragleave', (event) => {
|
|
608
|
+
if (!slot.contains(event.relatedTarget)) slot.classList.remove('is-drop-active');
|
|
609
|
+
});
|
|
610
|
+
slot.addEventListener('drop', (event) => {
|
|
611
|
+
event.preventDefault();
|
|
612
|
+
slot.classList.remove('is-drop-active');
|
|
613
|
+
const dragId = this._draggingNodeId || event.dataTransfer?.getData('text/plain');
|
|
614
|
+
this._endDragVisuals();
|
|
615
|
+
if (dragId) this.controller.commands.moveNode(dragId, containerRef, index);
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
const dropHint = el('span', 'ft-drop-hint', this._t('flowTree.canvas.dropHere'));
|
|
619
|
+
slot.append(lineTop, btn, dropHint, lineBottom);
|
|
620
|
+
} else {
|
|
621
|
+
slot.classList.add('is-readonly');
|
|
622
|
+
slot.append(lineTop);
|
|
623
|
+
}
|
|
624
|
+
return slot;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
_endDragVisuals() {
|
|
628
|
+
this._draggingNodeId = null;
|
|
629
|
+
this.container.classList.remove('is-dragging-node');
|
|
630
|
+
this.treeHost.querySelectorAll('.is-drop-eligible, .is-drop-active, .is-dragging').forEach((node) => {
|
|
631
|
+
node.classList.remove('is-drop-eligible', 'is-drop-active', 'is-dragging');
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
_buildNodeCard(node, { doc, selection, issuesByNode, routeContext = null, renderedNodeIds = null }) {
|
|
636
|
+
const def = this.controller.nodeRegistry.resolve(node.type) || FLOW_TREE_NODE_DEFINITIONS[node.type] || { tone: 'primary', iconId: 'flowTree.trigger', deletable: true, draggable: true };
|
|
637
|
+
const isSelected = selection?.kind === 'node' && selection.id === node.id;
|
|
638
|
+
const nodeIssues = issuesByNode.get(node.id) || [];
|
|
639
|
+
const hasError = nodeIssues.some((item) => item.level === 'error');
|
|
640
|
+
const hasWarning = !hasError && nodeIssues.some((item) => item.level === 'warning');
|
|
641
|
+
const runtimeState = this.mode === 'instance' ? this._runtimePresentation?.getNode?.(node.id) : null;
|
|
642
|
+
|
|
643
|
+
const isBranch = Boolean(routeContext);
|
|
644
|
+
const isEntering = this._hasRenderedOnce && !this._knownNodeIds.has(node.id);
|
|
645
|
+
renderedNodeIds?.add(node.id);
|
|
646
|
+
const card = el('article', [
|
|
647
|
+
'ft-card',
|
|
648
|
+
isBranch ? 'is-branch-card' : 'is-action-card',
|
|
649
|
+
`type-${node.type}`,
|
|
650
|
+
`tone-${def.tone || 'primary'}`,
|
|
651
|
+
isSelected ? 'is-selected' : '',
|
|
652
|
+
isEntering ? 'is-entering' : '',
|
|
653
|
+
hasError ? 'has-error' : hasWarning ? 'has-warning' : '',
|
|
654
|
+
runtimeState ? `runtime-${runtimeState.status}` : '',
|
|
655
|
+
node.isDefault ? 'is-default-branch' : '',
|
|
656
|
+
].filter(Boolean).join(' '));
|
|
657
|
+
card.dataset.ftNodeId = node.id;
|
|
658
|
+
card.dataset.ftNodeType = node.type;
|
|
659
|
+
|
|
660
|
+
if (runtimeState && runtimeState.status !== 'idle') {
|
|
661
|
+
applyRuntimeTone(card, this.runtimeAppearance.resolveStatus(runtimeState.status));
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
if (this.mode === 'design' && def.draggable && !routeContext) {
|
|
665
|
+
card.draggable = true;
|
|
666
|
+
card.addEventListener('dragstart', (event) => {
|
|
667
|
+
this._draggingNodeId = node.id;
|
|
668
|
+
card.classList.add('is-dragging');
|
|
669
|
+
this.container.classList.add('is-dragging-node');
|
|
670
|
+
event.dataTransfer?.setData('text/plain', node.id);
|
|
671
|
+
this.treeHost.querySelectorAll('.ft-add-slot').forEach((slotEl) => {
|
|
672
|
+
try {
|
|
673
|
+
const ref = JSON.parse(slotEl.dataset.ftContainer || '{}');
|
|
674
|
+
if (this.controller.commands.canMoveNode(node.id, ref)) slotEl.classList.add('is-drop-eligible');
|
|
675
|
+
} catch {
|
|
676
|
+
// ignore
|
|
677
|
+
}
|
|
678
|
+
});
|
|
679
|
+
});
|
|
680
|
+
card.addEventListener('dragend', () => this._endDragVisuals());
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
card.addEventListener('click', (event) => {
|
|
684
|
+
if (event.target?.closest?.('.ft-card-action, .ft-branch-shift')) return;
|
|
685
|
+
event.stopPropagation();
|
|
686
|
+
if (this._pendingCardDown && this._pendingCardDown.nodeId === node.id) {
|
|
687
|
+
this._pendingCardDown.handled = true;
|
|
688
|
+
}
|
|
689
|
+
this._activateNodeById(node.id);
|
|
690
|
+
});
|
|
691
|
+
|
|
692
|
+
// Custom card renderer hook
|
|
693
|
+
if (typeof this.nodeCardRenderer === 'function') {
|
|
694
|
+
const cleanup = this.nodeCardRenderer({
|
|
695
|
+
container: card,
|
|
696
|
+
node,
|
|
697
|
+
document: doc,
|
|
698
|
+
mode: this.mode,
|
|
699
|
+
selected: isSelected,
|
|
700
|
+
issues: nodeIssues,
|
|
701
|
+
runtimeState,
|
|
702
|
+
controller: this.controller,
|
|
703
|
+
i18n: this.i18n,
|
|
704
|
+
});
|
|
705
|
+
if (typeof cleanup === 'function') this._cardCleanups.push(cleanup);
|
|
706
|
+
return card;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
// Classic DingTalk/Feishu left/right edge priority handles on condition/inclusive branches
|
|
710
|
+
if (this.mode === 'design' && routeContext && !node.isDefault && routeContext.route.type !== 'parallelRoute') {
|
|
711
|
+
const movableMax = routeContext.route.branches.filter((b) => !b.isDefault).length - 1;
|
|
712
|
+
if (routeContext.branchIndex > 0) {
|
|
713
|
+
const leftShift = el('button', 'ft-branch-shift is-left');
|
|
714
|
+
leftShift.type = 'button';
|
|
715
|
+
leftShift.title = this._t('flowTree.canvas.moveLeft');
|
|
716
|
+
leftShift.setAttribute('aria-label', this._t('flowTree.canvas.moveLeft'));
|
|
717
|
+
leftShift.appendChild(icon('flowTree.moveLeft', 'nova-icon nova-icon-xs'));
|
|
718
|
+
leftShift.addEventListener('click', (e) => {
|
|
719
|
+
e.stopPropagation();
|
|
720
|
+
this.controller.commands.reorderBranch(routeContext.route.id, routeContext.branchIndex, routeContext.branchIndex - 1);
|
|
721
|
+
});
|
|
722
|
+
card.appendChild(leftShift);
|
|
723
|
+
}
|
|
724
|
+
if (routeContext.branchIndex < movableMax) {
|
|
725
|
+
const rightShift = el('button', 'ft-branch-shift is-right');
|
|
726
|
+
rightShift.type = 'button';
|
|
727
|
+
rightShift.title = this._t('flowTree.canvas.moveRight');
|
|
728
|
+
rightShift.setAttribute('aria-label', this._t('flowTree.canvas.moveRight'));
|
|
729
|
+
rightShift.appendChild(icon('flowTree.moveRight', 'nova-icon nova-icon-xs'));
|
|
730
|
+
rightShift.addEventListener('click', (e) => {
|
|
731
|
+
e.stopPropagation();
|
|
732
|
+
this.controller.commands.reorderBranch(routeContext.route.id, routeContext.branchIndex, routeContext.branchIndex + 1);
|
|
733
|
+
});
|
|
734
|
+
card.appendChild(rightShift);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
// Standard DingTalk / Feishu style FlowTree card
|
|
739
|
+
const header = el('header', 'ft-card-head');
|
|
740
|
+
const titleGroup = el('div', 'ft-card-title-group');
|
|
741
|
+
const iconBadge = el('span', 'ft-card-icon');
|
|
742
|
+
iconBadge.appendChild(icon(def.iconId || 'flowTree.trigger', 'nova-icon nova-icon-xs'));
|
|
743
|
+
const title = el('strong', 'ft-card-title', node.name || resolveFlowTreeTypeLabel(node.type, { i18n: this.i18n, nodeRegistry: this.controller.nodeRegistry }));
|
|
744
|
+
titleGroup.append(iconBadge, title);
|
|
745
|
+
header.appendChild(titleGroup);
|
|
746
|
+
|
|
747
|
+
// Branch priority label or runtime status pill
|
|
748
|
+
const badges = el('div', 'ft-card-head-right');
|
|
749
|
+
if (routeContext) {
|
|
750
|
+
if (node.isDefault) {
|
|
751
|
+
badges.appendChild(el('span', 'ft-card-priority is-muted', this._t('flowTree.canvas.defaultBranchBadge')));
|
|
752
|
+
} else if (routeContext.route.type !== 'parallelRoute') {
|
|
753
|
+
badges.appendChild(el('span', 'ft-card-priority', this._t('flowTree.canvas.priorityBadge', { priority: node.priority })));
|
|
754
|
+
}
|
|
755
|
+
} else if (runtimeState && runtimeState.status !== 'idle') {
|
|
756
|
+
badges.appendChild(el('span', 'ft-card-pill is-runtime', runtimeState.statusLabel));
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
if (this.mode === 'design') {
|
|
760
|
+
const actions = el('div', 'ft-card-actions');
|
|
761
|
+
if (routeContext) {
|
|
762
|
+
const collapsed = this.controller.isBranchCollapsed(node.id);
|
|
763
|
+
const collapseBtn = el('button', 'ft-card-action');
|
|
764
|
+
collapseBtn.type = 'button';
|
|
765
|
+
collapseBtn.title = this._t(collapsed ? 'flowTree.canvas.expandBranch' : 'flowTree.canvas.collapseBranch');
|
|
766
|
+
collapseBtn.appendChild(icon(collapsed ? 'flowTree.expand' : 'flowTree.collapse', 'nova-icon nova-icon-xs'));
|
|
767
|
+
collapseBtn.addEventListener('click', (e) => {
|
|
768
|
+
e.stopPropagation();
|
|
769
|
+
this.controller.commands.toggleBranchCollapse(node.id);
|
|
770
|
+
});
|
|
771
|
+
actions.appendChild(collapseBtn);
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
if (def.deletable && !node.isDefault) {
|
|
775
|
+
const dupBtn = el('button', 'ft-card-action');
|
|
776
|
+
dupBtn.type = 'button';
|
|
777
|
+
dupBtn.title = this._t('flowTree.canvas.duplicateNode');
|
|
778
|
+
dupBtn.appendChild(icon('flowTree.copy', 'nova-icon nova-icon-xs'));
|
|
779
|
+
dupBtn.addEventListener('click', (e) => {
|
|
780
|
+
e.stopPropagation();
|
|
781
|
+
this.controller.commands.duplicateNode(node.id);
|
|
782
|
+
});
|
|
783
|
+
actions.appendChild(dupBtn);
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
const canDeleteBranch = !routeContext || !node.isDefault || routeContext.route.branches.length <= 2;
|
|
787
|
+
if (def.deletable && canDeleteBranch) {
|
|
788
|
+
const delBtn = el('button', 'ft-card-action is-danger');
|
|
789
|
+
delBtn.type = 'button';
|
|
790
|
+
delBtn.title = this._t('flowTree.canvas.deleteNode');
|
|
791
|
+
delBtn.appendChild(icon('ui.close', 'nova-icon nova-icon-xs'));
|
|
792
|
+
delBtn.addEventListener('click', (e) => {
|
|
793
|
+
e.stopPropagation();
|
|
794
|
+
this.controller.commands.removeNode(node.id);
|
|
795
|
+
});
|
|
796
|
+
actions.appendChild(delBtn);
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
if (actions.childNodes.length) badges.appendChild(actions);
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
header.appendChild(badges);
|
|
803
|
+
card.appendChild(header);
|
|
804
|
+
|
|
805
|
+
// Body summary
|
|
806
|
+
const body = el('div', 'ft-card-body');
|
|
807
|
+
const summaryText = this.mode === 'instance' && runtimeState && (runtimeState.summary || runtimeState.latestAction?.plainText)
|
|
808
|
+
? [runtimeState.summary, runtimeState.latestAction?.plainText].filter(Boolean).join(' · ')
|
|
809
|
+
: formatFlowTreeNodeSummary(node, {
|
|
810
|
+
i18n: this.i18n,
|
|
811
|
+
nodeRegistry: this.controller.nodeRegistry,
|
|
812
|
+
nodeSummaryResolver: this.nodeSummaryResolver,
|
|
813
|
+
document: doc,
|
|
814
|
+
});
|
|
815
|
+
|
|
816
|
+
const isPlaceholder = !runtimeState && (
|
|
817
|
+
summaryText === this._t('flowTree.canvas.unconfigured')
|
|
818
|
+
|| summaryText === this._t('flowTree.summaries.conditionUnconfigured')
|
|
819
|
+
|| summaryText === this._t('flowTree.summaries.ccUnconfigured')
|
|
820
|
+
|| summaryText === this._t('flowTree.summaries.delayUnconfigured')
|
|
821
|
+
|| summaryText === this._t('flowTree.summaries.triggerUnconfigured')
|
|
822
|
+
|| summaryText === this._t('flowTree.summaries.subFlowUnconfigured')
|
|
823
|
+
);
|
|
824
|
+
|
|
825
|
+
const summaryEl = el('div', `ft-card-summary${isPlaceholder ? ' is-placeholder' : ''}`, summaryText);
|
|
826
|
+
body.appendChild(summaryEl);
|
|
827
|
+
body.appendChild(icon('flowTree.chevronRight', 'nova-icon nova-icon-xs ft-card-chevron'));
|
|
828
|
+
card.appendChild(body);
|
|
829
|
+
|
|
830
|
+
// Issue micro-bar
|
|
831
|
+
if (nodeIssues.length && this.mode === 'design') {
|
|
832
|
+
const foot = el('div', `ft-card-issue is-${hasError ? 'error' : 'warning'}`);
|
|
833
|
+
foot.append(icon('flowTree.warning', 'nova-icon nova-icon-xs'), el('span', '', nodeIssues[0].message));
|
|
834
|
+
card.appendChild(foot);
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
return card;
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
_buildRouteBlock(route, ctx) {
|
|
841
|
+
const block = el('div', `ft-route-block type-${route.type}`);
|
|
842
|
+
block.dataset.ftRouteId = route.id;
|
|
843
|
+
|
|
844
|
+
if (this.mode === 'design') {
|
|
845
|
+
const addLabelKey = route.type === 'parallelRoute'
|
|
846
|
+
? 'flowTree.canvas.addParallelBranch'
|
|
847
|
+
: route.type === 'inclusiveRoute'
|
|
848
|
+
? 'flowTree.canvas.addInclusiveBranch'
|
|
849
|
+
: 'flowTree.canvas.addConditionBranch';
|
|
850
|
+
const addBranchBtn = el('button', 'ft-add-branch-btn');
|
|
851
|
+
addBranchBtn.type = 'button';
|
|
852
|
+
addBranchBtn.append(icon('ui.add', 'nova-icon nova-icon-xs'), el('span', '', this._t(addLabelKey)));
|
|
853
|
+
addBranchBtn.addEventListener('click', (event) => {
|
|
854
|
+
event.stopPropagation();
|
|
855
|
+
this.controller.commands.addBranch(route.id);
|
|
856
|
+
});
|
|
857
|
+
block.appendChild(addBranchBtn);
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
const row = el('div', 'ft-branch-row');
|
|
861
|
+
(route.branches || []).forEach((branch, branchIndex) => {
|
|
862
|
+
const col = el('div', 'ft-branch-col');
|
|
863
|
+
if (branchIndex === 0) col.classList.add('is-first');
|
|
864
|
+
if (branchIndex === route.branches.length - 1) col.classList.add('is-last');
|
|
865
|
+
|
|
866
|
+
const topStem = el('span', 'ft-branch-top-stem');
|
|
867
|
+
const cardWrap = el('div', 'ft-card-wrap');
|
|
868
|
+
cardWrap.append(
|
|
869
|
+
el('span', 'ft-entry-arrow'),
|
|
870
|
+
this._buildNodeCard(branch, {
|
|
871
|
+
...ctx,
|
|
872
|
+
routeContext: { route, branchIndex },
|
|
873
|
+
}),
|
|
874
|
+
);
|
|
875
|
+
|
|
876
|
+
const collapsed = this.controller.isBranchCollapsed(branch.id);
|
|
877
|
+
const inner = el('div', 'ft-branch-body');
|
|
878
|
+
if (collapsed) {
|
|
879
|
+
const count = countBranchSteps(branch);
|
|
880
|
+
const pill = el('button', 'ft-branch-collapsed-pill', this._t('flowTree.canvas.collapsedCount', { count }));
|
|
881
|
+
pill.type = 'button';
|
|
882
|
+
pill.addEventListener('click', (event) => {
|
|
883
|
+
event.stopPropagation();
|
|
884
|
+
this.controller.commands.toggleBranchCollapse(branch.id);
|
|
885
|
+
});
|
|
886
|
+
inner.append(el('span', 'ft-spine-line'), pill, el('span', 'ft-spine-line'));
|
|
887
|
+
} else {
|
|
888
|
+
const branchRef = { kind: 'branch', branchId: branch.id, routeId: route.id };
|
|
889
|
+
inner.appendChild(this._buildAddSlot(branchRef, 0, branch.steps.length));
|
|
890
|
+
branch.steps.forEach((childStep, childIndex) => {
|
|
891
|
+
inner.appendChild(this._buildStepElement(childStep, ctx));
|
|
892
|
+
inner.appendChild(this._buildAddSlot(branchRef, childIndex + 1, branch.steps.length));
|
|
893
|
+
});
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
const bottomFiller = el('span', 'ft-branch-bottom-filler');
|
|
897
|
+
col.append(topStem, cardWrap, inner, bottomFiller);
|
|
898
|
+
row.appendChild(col);
|
|
899
|
+
});
|
|
900
|
+
|
|
901
|
+
block.appendChild(row);
|
|
902
|
+
return block;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
_buildStepElement(step, ctx) {
|
|
906
|
+
if (isRouteNode(step)) {
|
|
907
|
+
return this._buildRouteBlock(step, ctx);
|
|
908
|
+
}
|
|
909
|
+
const wrap = el('div', 'ft-step-wrap');
|
|
910
|
+
wrap.append(el('span', 'ft-entry-arrow'), this._buildNodeCard(step, ctx));
|
|
911
|
+
return wrap;
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
render() {
|
|
915
|
+
this._cardCleanups.splice(0).forEach((fn) => fn?.());
|
|
916
|
+
const state = this.controller.getState();
|
|
917
|
+
const doc = state.document;
|
|
918
|
+
|
|
919
|
+
if (this.mode === 'instance' && this.runtime) {
|
|
920
|
+
const compiledModel = compileFlowTreeToBpmn(doc, { i18n: this.i18n, nodeRegistry: this.controller.nodeRegistry });
|
|
921
|
+
this._runtimePresentation = createRuntimePresentation({
|
|
922
|
+
model: compiledModel,
|
|
923
|
+
runtime: this.runtime,
|
|
924
|
+
appearance: this.runtimeAppearance,
|
|
925
|
+
i18n: this.i18n,
|
|
926
|
+
});
|
|
927
|
+
} else {
|
|
928
|
+
this._runtimePresentation = null;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
const issuesByNode = new Map();
|
|
932
|
+
for (const issue of state.validationIssues || []) {
|
|
933
|
+
if (!issue.nodeId) continue;
|
|
934
|
+
if (!issuesByNode.has(issue.nodeId)) issuesByNode.set(issue.nodeId, []);
|
|
935
|
+
issuesByNode.get(issue.nodeId).push(issue);
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
const renderedNodeIds = new Set();
|
|
939
|
+
const ctx = { doc, selection: state.selection, issuesByNode, renderedNodeIds };
|
|
940
|
+
const tree = el('div', 'ft-tree');
|
|
941
|
+
|
|
942
|
+
// Starter
|
|
943
|
+
tree.appendChild(this._buildNodeCard(doc.starter, ctx));
|
|
944
|
+
const rootRef = { kind: 'root' };
|
|
945
|
+
tree.appendChild(this._buildAddSlot(rootRef, 0, doc.steps.length));
|
|
946
|
+
|
|
947
|
+
// Main steps
|
|
948
|
+
doc.steps.forEach((step, index) => {
|
|
949
|
+
tree.appendChild(this._buildStepElement(step, ctx));
|
|
950
|
+
tree.appendChild(this._buildAddSlot(rootRef, index + 1, doc.steps.length));
|
|
951
|
+
});
|
|
952
|
+
|
|
953
|
+
// End node (DingTalk / Feishu style end dot + caption)
|
|
954
|
+
const endRuntime = this.mode === 'instance' ? this._runtimePresentation?.getNode?.(doc.end.id) : null;
|
|
955
|
+
const endWrap = el('div', [
|
|
956
|
+
'ft-end-node',
|
|
957
|
+
state.selection?.kind === 'node' && state.selection.id === doc.end.id ? 'is-selected' : '',
|
|
958
|
+
endRuntime && endRuntime.status !== 'idle' ? `runtime-${endRuntime.status}` : '',
|
|
959
|
+
].filter(Boolean).join(' '));
|
|
960
|
+
endWrap.dataset.ftNodeId = doc.end.id;
|
|
961
|
+
endWrap.append(
|
|
962
|
+
el('span', 'ft-entry-arrow'),
|
|
963
|
+
el('span', 'ft-end-dot'),
|
|
964
|
+
el('span', 'ft-end-label', doc.end.name || this._t('flowTree.defaultEndName')),
|
|
965
|
+
);
|
|
966
|
+
endWrap.addEventListener('click', (event) => {
|
|
967
|
+
event.stopPropagation();
|
|
968
|
+
if (this._pendingCardDown && this._pendingCardDown.nodeId === doc.end.id) {
|
|
969
|
+
this._pendingCardDown.handled = true;
|
|
970
|
+
}
|
|
971
|
+
this._activateNodeById(doc.end.id);
|
|
972
|
+
});
|
|
973
|
+
tree.appendChild(endWrap);
|
|
974
|
+
|
|
975
|
+
this.treeHost.replaceChildren(tree);
|
|
976
|
+
this._knownNodeIds = renderedNodeIds;
|
|
977
|
+
this._hasRenderedOnce = true;
|
|
978
|
+
this.container.dataset.mode = this.mode;
|
|
979
|
+
hydrateIcons(this.treeHost, this.iconRegistry);
|
|
980
|
+
this._applyTransform({ animate: false });
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
destroy() {
|
|
984
|
+
this._stopTransformAnimation();
|
|
985
|
+
this._resizeObserver?.disconnect();
|
|
986
|
+
this._resizeObserver = null;
|
|
987
|
+
this._closeAddMenu();
|
|
988
|
+
this.closeRuntimeDetails();
|
|
989
|
+
this._svgExportPreview?.close?.({ immediate: true });
|
|
990
|
+
this._cardCleanups.splice(0).forEach((fn) => fn?.());
|
|
991
|
+
this._offController?.();
|
|
992
|
+
this._offI18n?.();
|
|
993
|
+
this.viewport?.removeEventListener('wheel', this._onWheel);
|
|
994
|
+
this.viewport?.removeEventListener('pointerdown', this._onPointerDown);
|
|
995
|
+
window.removeEventListener('pointermove', this._onPointerMove);
|
|
996
|
+
window.removeEventListener('pointerup', this._onPointerUp);
|
|
997
|
+
document.removeEventListener('pointerdown', this._onOutsidePointerDown, true);
|
|
998
|
+
this.container.removeEventListener('keydown', this._onKeyDown);
|
|
999
|
+
this.container.innerHTML = '';
|
|
1000
|
+
this.container.classList.remove('nova-ft-canvas', 'is-dragging-node');
|
|
1001
|
+
if (this._ownsThemeController) this.themeController.destroy();
|
|
1002
|
+
}
|
|
1003
|
+
}
|