@stocksharp/diagram 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/canvas-renderer.js +28 -22
- package/dist/esm/canvas-renderer.js.map +1 -1
- package/dist/esm/core/action-registry.js +24 -0
- package/dist/esm/core/action-registry.js.map +1 -1
- package/dist/esm/core/document.js +85 -28
- package/dist/esm/core/document.js.map +1 -1
- package/dist/esm/core/json.js +17 -0
- package/dist/esm/core/json.js.map +1 -0
- package/dist/esm/core/model.js +4 -0
- package/dist/esm/core/model.js.map +1 -1
- package/dist/esm/core/state.js +16 -2
- package/dist/esm/core/state.js.map +1 -1
- package/dist/esm/diagram/catalog.js +17 -5
- package/dist/esm/diagram/catalog.js.map +1 -1
- package/dist/esm/diagram/event-emitter.js +10 -0
- package/dist/esm/diagram/event-emitter.js.map +1 -1
- package/dist/esm/diagram/stocksharp-diagram.js +58 -56
- package/dist/esm/diagram/stocksharp-diagram.js.map +1 -1
- package/dist/esm/diagram/types.js +2 -1
- package/dist/esm/diagram/types.js.map +1 -1
- package/dist/esm/embed.js +121 -38
- package/dist/esm/embed.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/ssdiagram.js +297 -145
- package/dist/ssdiagram.js.map +4 -4
- package/dist/types/canvas-renderer.d.ts +3 -5
- package/dist/types/canvas-renderer.d.ts.map +1 -1
- package/dist/types/core/action-registry.d.ts +7 -0
- package/dist/types/core/action-registry.d.ts.map +1 -1
- package/dist/types/core/document.d.ts.map +1 -1
- package/dist/types/core/json.d.ts +11 -0
- package/dist/types/core/json.d.ts.map +1 -0
- package/dist/types/core/model.d.ts +10 -1
- package/dist/types/core/model.d.ts.map +1 -1
- package/dist/types/core/state.d.ts +24 -1
- package/dist/types/core/state.d.ts.map +1 -1
- package/dist/types/diagram/api.d.ts +6 -6
- package/dist/types/diagram/api.d.ts.map +1 -1
- package/dist/types/diagram/catalog.d.ts +2 -1
- package/dist/types/diagram/catalog.d.ts.map +1 -1
- package/dist/types/diagram/event-emitter.d.ts +6 -1
- package/dist/types/diagram/event-emitter.d.ts.map +1 -1
- package/dist/types/diagram/palette.d.ts +1 -1
- package/dist/types/diagram/palette.d.ts.map +1 -1
- package/dist/types/diagram/stocksharp-diagram.d.ts +29 -22
- package/dist/types/diagram/stocksharp-diagram.d.ts.map +1 -1
- package/dist/types/diagram/types.d.ts +4 -4
- package/dist/types/diagram/types.d.ts.map +1 -1
- package/dist/types/embed.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/canvas-renderer.ts +26 -24
- package/src/core/action-registry.ts +25 -0
- package/src/core/document.ts +91 -31
- package/src/core/json.ts +16 -0
- package/src/core/model.ts +14 -1
- package/src/core/state.ts +41 -3
- package/src/diagram/api.ts +6 -5
- package/src/diagram/catalog.ts +18 -6
- package/src/diagram/event-emitter.ts +12 -1
- package/src/diagram/palette.ts +1 -1
- package/src/diagram/stocksharp-diagram.ts +79 -76
- package/src/diagram/types.ts +6 -5
- package/src/embed.ts +140 -39
- package/src/index.ts +4 -0
package/src/diagram/catalog.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EventEmitter } from './event-emitter.js';
|
|
2
2
|
import { Node, NodeInit, PortType, PortTypeInit } from './types.js';
|
|
3
3
|
|
|
4
|
-
export interface CatalogEvents
|
|
4
|
+
export interface CatalogEvents {
|
|
5
5
|
portTypesChanged: PortType[];
|
|
6
6
|
nodeTypesChanged: Node[];
|
|
7
7
|
}
|
|
@@ -35,21 +35,33 @@ export class StockSharpCatalog extends EventEmitter<CatalogEvents> {
|
|
|
35
35
|
// imported node ("Element type is missing from the palette"). Node.id
|
|
36
36
|
// keeps its original casing so save/load round-trips unchanged.
|
|
37
37
|
addNodeType(node: Node | NodeInit): void {
|
|
38
|
-
|
|
38
|
+
// Copied on the way in as well as on the way out: otherwise the caller
|
|
39
|
+
// keeps a handle on the stored definition and can edit it afterwards.
|
|
40
|
+
// The clone covers the init branch too -- Node's constructor keeps the
|
|
41
|
+
// caller's Port instances and parameters array as they are.
|
|
42
|
+
const n = (node instanceof Node ? node : new Node(node)).clone();
|
|
39
43
|
this.nodeTypes.set(n.id.toLowerCase(), n);
|
|
40
|
-
this.
|
|
44
|
+
this.emitNodeTypesChanged();
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
removeNodeType(id: string): void {
|
|
44
48
|
this.nodeTypes.delete(id.toLowerCase());
|
|
45
|
-
this.
|
|
49
|
+
this.emitNodeTypesChanged();
|
|
46
50
|
}
|
|
47
51
|
|
|
48
52
|
getNodeType(id: string): Node | null {
|
|
49
|
-
return this.nodeTypes.get(id.toLowerCase()) ?? null;
|
|
53
|
+
return this.nodeTypes.get(id.toLowerCase())?.clone() ?? null;
|
|
50
54
|
}
|
|
51
55
|
|
|
52
56
|
getNodeTypes(): Node[] {
|
|
53
|
-
return Array.from(this.nodeTypes.values());
|
|
57
|
+
return Array.from(this.nodeTypes.values(), (node) => node.clone());
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Node definitions are mutable, so the payload has to be a copy of each one.
|
|
61
|
+
// Building a catalog is a loop of addNodeType calls, which would make that
|
|
62
|
+
// quadratic; skipping it while nobody listens keeps catalog construction --
|
|
63
|
+
// where no subscriber exists yet -- as cheap as it was.
|
|
64
|
+
private emitNodeTypesChanged(): void {
|
|
65
|
+
if (this.hasHandlers('nodeTypesChanged')) this.emit('nodeTypesChanged', this.getNodeTypes());
|
|
54
66
|
}
|
|
55
67
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export type EventHandler<T> = (payload: T) => void;
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// TEvents is constrained to object rather than Record<string, unknown>: the
|
|
4
|
+
// latter forces every event map to carry a string index signature, which
|
|
5
|
+
// collapses keyof TEvents to string and lets any misspelled name compile.
|
|
6
|
+
export class EventEmitter<TEvents extends object> {
|
|
4
7
|
private readonly handlers = new Map<keyof TEvents, Set<EventHandler<unknown>>>();
|
|
5
8
|
|
|
6
9
|
on<K extends keyof TEvents>(event: K, handler: EventHandler<TEvents[K]>): () => void {
|
|
@@ -38,6 +41,14 @@ export class EventEmitter<TEvents extends Record<string, unknown>> {
|
|
|
38
41
|
}
|
|
39
42
|
}
|
|
40
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Whether anyone is listening. Lets a subject skip building a payload that
|
|
46
|
+
* is expensive to produce and that nothing would read.
|
|
47
|
+
*/
|
|
48
|
+
protected hasHandlers<K extends keyof TEvents>(event: K): boolean {
|
|
49
|
+
return (this.handlers.get(event)?.size ?? 0) > 0;
|
|
50
|
+
}
|
|
51
|
+
|
|
41
52
|
protected clearEventHandlers(): void {
|
|
42
53
|
this.handlers.clear();
|
|
43
54
|
}
|
package/src/diagram/palette.ts
CHANGED
|
@@ -22,7 +22,7 @@ export interface PaletteContextMenuPayload extends PaletteNodePayload {
|
|
|
22
22
|
y: number;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export interface PaletteEvents
|
|
25
|
+
export interface PaletteEvents {
|
|
26
26
|
selectionChanged: PaletteSelectionChangedPayload;
|
|
27
27
|
nodeActivated: PaletteNodePayload;
|
|
28
28
|
contextMenuRequested: PaletteContextMenuPayload;
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
parseDiagramViewState,
|
|
7
7
|
serializeDiagramViewState,
|
|
8
8
|
} from '../core/view-state.js';
|
|
9
|
-
import type { DiagramDocument } from '../core/model.js';
|
|
9
|
+
import type { DiagramDocument, PortDynamicMode } from '../core/model.js';
|
|
10
10
|
import { DiagramActionRegistry } from '../core/action-registry.js';
|
|
11
11
|
import type {
|
|
12
12
|
DiagramGlobalErrorKind,
|
|
@@ -14,6 +14,7 @@ import type {
|
|
|
14
14
|
DiagramPortRuntimeState,
|
|
15
15
|
DiagramRuntimeState,
|
|
16
16
|
DiagramSelection,
|
|
17
|
+
DiagramSnapshot,
|
|
17
18
|
DiagramViewState,
|
|
18
19
|
} from '../core/state.js';
|
|
19
20
|
import {
|
|
@@ -77,7 +78,6 @@ export class StockSharpDiagram extends EventEmitter<DiagramEvents> {
|
|
|
77
78
|
private fullscreen = false;
|
|
78
79
|
private fullscreenButtonVisible = true;
|
|
79
80
|
private fullscreenLabels: DiagramFullscreenLabels = { enter: 'Enter fullscreen', exit: 'Exit fullscreen' };
|
|
80
|
-
private linkValidator: LinkValidator | null = null;
|
|
81
81
|
private readonly contextActions = new DiagramActionRegistry<ContextCommand, ContextActionContext>();
|
|
82
82
|
|
|
83
83
|
constructor(options: DiagramOptions) {
|
|
@@ -105,7 +105,6 @@ export class StockSharpDiagram extends EventEmitter<DiagramEvents> {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
setLinkValidator(validator: LinkValidator | null): void {
|
|
108
|
-
this.linkValidator = validator;
|
|
109
108
|
this.canvas.setLinkValidator(validator === null ? null : ({ fromNode, fromPort, toNode, toPort }) => validator({
|
|
110
109
|
fromNode: this.fromCanvasNode(fromNode),
|
|
111
110
|
fromPort: this.fromCanvasPort(fromPort),
|
|
@@ -178,7 +177,7 @@ export class StockSharpDiagram extends EventEmitter<DiagramEvents> {
|
|
|
178
177
|
this.canvas.setGridSnap(enabled, size);
|
|
179
178
|
}
|
|
180
179
|
|
|
181
|
-
getGridSnap(): DiagramGridSettings {
|
|
180
|
+
getGridSnap(): DiagramSnapshot<DiagramGridSettings> {
|
|
182
181
|
return this.canvas.getGridSnap();
|
|
183
182
|
}
|
|
184
183
|
|
|
@@ -202,29 +201,33 @@ export class StockSharpDiagram extends EventEmitter<DiagramEvents> {
|
|
|
202
201
|
this.canvas.removeLink(this.toCanvasLink(link));
|
|
203
202
|
}
|
|
204
203
|
|
|
205
|
-
|
|
206
|
-
|
|
204
|
+
/** False when nothing changed: no such node or port, or the edit was a no-op. */
|
|
205
|
+
addPort(nodeId: string, direction: PortDirection, port: Port): boolean {
|
|
206
|
+
return this.canvas.addPort(nodeId, direction, this.toCanvasPort(port));
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
-
|
|
210
|
-
|
|
209
|
+
/** False when nothing changed: no such node or port, or the edit was a no-op. */
|
|
210
|
+
removePort(nodeId: string, direction: PortDirection, portId: string): boolean {
|
|
211
|
+
return this.canvas.removePort(nodeId, direction, portId);
|
|
211
212
|
}
|
|
212
213
|
|
|
213
|
-
|
|
214
|
-
|
|
214
|
+
/** False when nothing changed: no such node or port, or the edit was a no-op. */
|
|
215
|
+
updatePortType(nodeId: string, direction: PortDirection, portId: string, type: string): boolean {
|
|
216
|
+
return this.canvas.updatePortType(nodeId, direction, portId, type);
|
|
215
217
|
}
|
|
216
218
|
|
|
217
219
|
updatePort(nodeId: string, direction: PortDirection, portId: string, patch: PortUpdate): boolean {
|
|
218
220
|
return this.canvas.updatePort(nodeId, direction, portId, patch);
|
|
219
221
|
}
|
|
220
222
|
|
|
223
|
+
/** False when nothing changed: no such node or port, or the edit was a no-op. */
|
|
221
224
|
setNodePorts(
|
|
222
225
|
nodeId: string,
|
|
223
|
-
inPorts: ReadonlyArray<{ key: string; name: string; description: string; type: string; maxLinks: number; availableTypes?: string[]; isDynamic?: boolean; dynamicMode?:
|
|
224
|
-
outPorts: ReadonlyArray<{ key: string; name: string; description: string; type: string; maxLinks: number; availableTypes?: string[]; isDynamic?: boolean; dynamicMode?:
|
|
225
|
-
):
|
|
226
|
+
inPorts: ReadonlyArray<{ key: string; name: string; description: string; type: string; maxLinks: number; availableTypes?: string[]; isDynamic?: boolean; dynamicMode?: PortDynamicMode }>,
|
|
227
|
+
outPorts: ReadonlyArray<{ key: string; name: string; description: string; type: string; maxLinks: number; availableTypes?: string[]; isDynamic?: boolean; dynamicMode?: PortDynamicMode }>,
|
|
228
|
+
): boolean {
|
|
226
229
|
const current = this.canvas.findNode(nodeId);
|
|
227
|
-
if (current === undefined) return;
|
|
230
|
+
if (current === undefined) return false;
|
|
228
231
|
const convert = (port: typeof inPorts[number]): CanvasPortInit => ({
|
|
229
232
|
id: port.key,
|
|
230
233
|
name: port.name,
|
|
@@ -243,15 +246,17 @@ export class StockSharpDiagram extends EventEmitter<DiagramEvents> {
|
|
|
243
246
|
for (const sibling of current.outPorts.filter((port) => port.isSibling)) {
|
|
244
247
|
if (!nextOut.some((port) => port.id === sibling.id)) nextOut.push(sibling.toInit());
|
|
245
248
|
}
|
|
246
|
-
this.canvas.setNodePorts(nodeId, nextIn, nextOut);
|
|
249
|
+
return this.canvas.setNodePorts(nodeId, nextIn, nextOut);
|
|
247
250
|
}
|
|
248
251
|
|
|
249
|
-
|
|
250
|
-
|
|
252
|
+
/** False when nothing changed: no such node or port, or the edit was a no-op. */
|
|
253
|
+
updateNode(nodeId: string, patch: { name?: string; description?: string; color?: string; border?: string }): boolean {
|
|
254
|
+
return this.canvas.updateNode(nodeId, patch);
|
|
251
255
|
}
|
|
252
256
|
|
|
253
|
-
|
|
254
|
-
|
|
257
|
+
/** False when nothing changed: no such node or port, or the edit was a no-op. */
|
|
258
|
+
setNodeMessage(nodeId: string, message: string): boolean {
|
|
259
|
+
return this.canvas.updateNode(nodeId, { message });
|
|
255
260
|
}
|
|
256
261
|
|
|
257
262
|
setNodeError(nodeId: string, message: string, options: NodeErrorOptions = {}): boolean {
|
|
@@ -262,11 +267,11 @@ export class StockSharpDiagram extends EventEmitter<DiagramEvents> {
|
|
|
262
267
|
return this.canvas.clearNodeError(nodeId, kind);
|
|
263
268
|
}
|
|
264
269
|
|
|
265
|
-
getRuntimeState(): DiagramRuntimeState {
|
|
270
|
+
getRuntimeState(): DiagramSnapshot<DiagramRuntimeState> {
|
|
266
271
|
return this.canvas.getRuntimeState();
|
|
267
272
|
}
|
|
268
273
|
|
|
269
|
-
setRuntimeState(state: DiagramRuntimeState): void {
|
|
274
|
+
setRuntimeState(state: DiagramSnapshot<DiagramRuntimeState>): void {
|
|
270
275
|
this.canvas.setRuntimeState(state);
|
|
271
276
|
}
|
|
272
277
|
|
|
@@ -291,12 +296,14 @@ export class StockSharpDiagram extends EventEmitter<DiagramEvents> {
|
|
|
291
296
|
this.canvas.setGlobalError(message, kind);
|
|
292
297
|
}
|
|
293
298
|
|
|
294
|
-
|
|
295
|
-
|
|
299
|
+
/** False when nothing changed: no such node or port, or the edit was a no-op. */
|
|
300
|
+
setNodeParamValue(nodeId: string, paramName: string, value: string | undefined): boolean {
|
|
301
|
+
return this.canvas.setNodeParamValue(nodeId, paramName, value);
|
|
296
302
|
}
|
|
297
303
|
|
|
298
|
-
|
|
299
|
-
|
|
304
|
+
/** False when nothing changed: no such node or port, or the edit was a no-op. */
|
|
305
|
+
setNodeName(nodeId: string, value: string): boolean {
|
|
306
|
+
return this.canvas.updateNode(nodeId, { name: value });
|
|
300
307
|
}
|
|
301
308
|
|
|
302
309
|
/** Groups host-driven document edits into one undo/redo operation. */
|
|
@@ -312,7 +319,7 @@ export class StockSharpDiagram extends EventEmitter<DiagramEvents> {
|
|
|
312
319
|
this.canvas.setReadOnly(readonly);
|
|
313
320
|
}
|
|
314
321
|
|
|
315
|
-
getInteractionPermissions(): DiagramInteractionPermissions {
|
|
322
|
+
getInteractionPermissions(): DiagramSnapshot<DiagramInteractionPermissions> {
|
|
316
323
|
return this.canvas.getInteractionPermissions();
|
|
317
324
|
}
|
|
318
325
|
|
|
@@ -341,11 +348,11 @@ export class StockSharpDiagram extends EventEmitter<DiagramEvents> {
|
|
|
341
348
|
this.canvas.setZoom(scale);
|
|
342
349
|
}
|
|
343
350
|
|
|
344
|
-
getViewState(): DiagramViewState {
|
|
351
|
+
getViewState(): DiagramSnapshot<DiagramViewState> {
|
|
345
352
|
return this.canvas.getViewState();
|
|
346
353
|
}
|
|
347
354
|
|
|
348
|
-
setViewState(state: DiagramViewState): void {
|
|
355
|
+
setViewState(state: DiagramSnapshot<DiagramViewState>): void {
|
|
349
356
|
this.canvas.setViewState(state);
|
|
350
357
|
this.overviewContainer?.classList.toggle('hidden', !state.overviewVisible);
|
|
351
358
|
}
|
|
@@ -365,7 +372,7 @@ export class StockSharpDiagram extends EventEmitter<DiagramEvents> {
|
|
|
365
372
|
return this.canvas.takeScreenshot(options);
|
|
366
373
|
}
|
|
367
374
|
|
|
368
|
-
getSelection(): DiagramSelection {
|
|
375
|
+
getSelection(): DiagramSnapshot<DiagramSelection> {
|
|
369
376
|
return this.canvas.getSelection();
|
|
370
377
|
}
|
|
371
378
|
|
|
@@ -400,12 +407,12 @@ export class StockSharpDiagram extends EventEmitter<DiagramEvents> {
|
|
|
400
407
|
}
|
|
401
408
|
|
|
402
409
|
/** Text of the fullscreen button, for a host that renders in another language. */
|
|
403
|
-
setFullscreenLabels(labels: DiagramFullscreenLabels): void {
|
|
410
|
+
setFullscreenLabels(labels: DiagramSnapshot<DiagramFullscreenLabels>): void {
|
|
404
411
|
this.fullscreenLabels = labels;
|
|
405
412
|
this.updateFullscreenButton();
|
|
406
413
|
}
|
|
407
414
|
|
|
408
|
-
getFullscreenLabels(): DiagramFullscreenLabels {
|
|
415
|
+
getFullscreenLabels(): DiagramSnapshot<DiagramFullscreenLabels> {
|
|
409
416
|
return { ...this.fullscreenLabels };
|
|
410
417
|
}
|
|
411
418
|
|
|
@@ -760,51 +767,47 @@ export class StockSharpDiagram extends EventEmitter<DiagramEvents> {
|
|
|
760
767
|
|
|
761
768
|
private registerContextActions(): void {
|
|
762
769
|
const permissions = () => this.canvas.getInteractionPermissions();
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
this.contextActions.register({
|
|
805
|
-
id: 'help',
|
|
806
|
-
canExecute: ({ nodes }) => this.helpEnabled && nodes.length > 0,
|
|
807
|
-
execute: ({ nodes }) => this.emit('nodeHelp', { nodes }),
|
|
770
|
+
// Keyed by ContextCommand, so a command added to the union without an
|
|
771
|
+
// entry here fails to compile rather than quietly missing from the menu.
|
|
772
|
+
// Key order is menu order.
|
|
773
|
+
this.contextActions.registerAll({
|
|
774
|
+
undo: {
|
|
775
|
+
canExecute: () => this.canUndo(),
|
|
776
|
+
execute: () => this.undo(),
|
|
777
|
+
},
|
|
778
|
+
redo: {
|
|
779
|
+
canExecute: () => this.canRedo(),
|
|
780
|
+
execute: () => this.redo(),
|
|
781
|
+
},
|
|
782
|
+
cut: {
|
|
783
|
+
canExecute: ({ nodes }) => nodes.length > 0 && permissions().copy && permissions().deleteSelection,
|
|
784
|
+
execute: () => this.cutSelection(),
|
|
785
|
+
},
|
|
786
|
+
copy: {
|
|
787
|
+
canExecute: ({ nodes }) => nodes.length > 0 && permissions().copy,
|
|
788
|
+
execute: () => this.copySelection(),
|
|
789
|
+
},
|
|
790
|
+
paste: {
|
|
791
|
+
canExecute: () => this.canvas.hasClipboard() && permissions().paste,
|
|
792
|
+
execute: () => this.pasteSelection(),
|
|
793
|
+
},
|
|
794
|
+
open: {
|
|
795
|
+
canExecute: ({ nodes }) => nodes.length === 1 && nodes[0].openAction.length > 0,
|
|
796
|
+
execute: ({ nodes }) => this.emit('nodeOpen', { nodes }),
|
|
797
|
+
},
|
|
798
|
+
delete: {
|
|
799
|
+
canExecute: ({ selection }) => permissions().deleteSelection
|
|
800
|
+
&& (selection.nodeIds.length > 0 || selection.linkIds.length > 0),
|
|
801
|
+
execute: () => this.canvas.deleteSelection(),
|
|
802
|
+
},
|
|
803
|
+
properties: {
|
|
804
|
+
canExecute: ({ nodes }) => nodes.length > 0,
|
|
805
|
+
execute: ({ nodes }) => this.emit('nodeProperties', { nodes }),
|
|
806
|
+
},
|
|
807
|
+
help: {
|
|
808
|
+
canExecute: ({ nodes }) => this.helpEnabled && nodes.length > 0,
|
|
809
|
+
execute: ({ nodes }) => this.emit('nodeHelp', { nodes }),
|
|
810
|
+
},
|
|
808
811
|
});
|
|
809
812
|
}
|
|
810
813
|
|
package/src/diagram/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { toPortDynamicMode } from '../core/model.js';
|
|
2
|
+
import type { JsonObject, PortDynamicMode } from '../core/model.js';
|
|
2
3
|
|
|
3
4
|
// Core data model — node/port catalog (palette) and the live diagram (DiagramNode + Link).
|
|
4
5
|
|
|
@@ -29,7 +30,7 @@ export interface PortInit {
|
|
|
29
30
|
/// True when this port can be added/removed at runtime on a node.
|
|
30
31
|
isDynamic?: boolean;
|
|
31
32
|
/// "" / "manual" / "onConnect" — see PalettePortDto.dynamicMode docs.
|
|
32
|
-
dynamicMode?:
|
|
33
|
+
dynamicMode?: PortDynamicMode;
|
|
33
34
|
/// True when this port was spawned by the grow-on-connect pipeline.
|
|
34
35
|
/// Distinguishes anchor + runtime siblings on save (only siblings are
|
|
35
36
|
/// persisted in the diagram blob; anchors come from the palette schema).
|
|
@@ -47,7 +48,7 @@ export class Port {
|
|
|
47
48
|
maxLinks: number;
|
|
48
49
|
availableTypes: string[];
|
|
49
50
|
isDynamic: boolean;
|
|
50
|
-
dynamicMode:
|
|
51
|
+
dynamicMode: PortDynamicMode;
|
|
51
52
|
isSibling: boolean;
|
|
52
53
|
|
|
53
54
|
constructor(init: PortInit) {
|
|
@@ -58,7 +59,7 @@ export class Port {
|
|
|
58
59
|
this.maxLinks = typeof init.maxLinks === 'number' ? init.maxLinks : 0;
|
|
59
60
|
this.availableTypes = init.availableTypes ?? [];
|
|
60
61
|
this.isDynamic = init.isDynamic ?? false;
|
|
61
|
-
this.dynamicMode = init.dynamicMode
|
|
62
|
+
this.dynamicMode = toPortDynamicMode(init.dynamicMode);
|
|
62
63
|
this.isSibling = init.isSibling ?? false;
|
|
63
64
|
}
|
|
64
65
|
|
|
@@ -268,7 +269,7 @@ export interface PortData {
|
|
|
268
269
|
/// the anchor port spawns a sibling
|
|
269
270
|
/// on each link drop and the link is rerouted to the sibling.
|
|
270
271
|
isDynamic?: boolean;
|
|
271
|
-
dynamicMode?:
|
|
272
|
+
dynamicMode?: PortDynamicMode;
|
|
272
273
|
/// True when this port was spawned by the dynamic-growth pipeline rather
|
|
273
274
|
/// than declared on the palette element. Persists in the diagram blob so
|
|
274
275
|
/// reload restores the same set of sibling sockets.
|