@visuallyjs/browser-ui 1.2.7 → 1.2.8
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/js/visuallyjs.browser-ui.cjs.js +68 -68
- package/js/visuallyjs.browser-ui.esm.js +67 -67
- package/package.json +1 -1
- package/types/browser-ui/components/index.d.ts +1 -0
- package/types/browser-ui/components/inspector/index.d.ts +0 -1
- package/types/browser-ui/components/shape-type-inspector/index.d.ts +1 -0
- package/types/browser-ui/components/{inspector → shape-type-inspector}/shape-type-inspector.d.ts +2 -2
- package/types/browser-ui/plugins/graph-propagation/index.d.ts +26 -0
- package/types/browser-ui/plugins/index.d.ts +1 -0
- package/types/browser-ui/shape-library/shape-library-definitions.d.ts +4 -0
- package/types/browser-ui/surface-renderer/diagrams/definitions.d.ts +87 -0
- package/types/browser-ui/surface-renderer/diagrams/diagram.d.ts +1 -0
- package/types/browser-ui/surface-renderer/shape-palette.d.ts +1 -0
- package/types/core/graph-propagation/definitions.d.ts +41 -0
- package/types/core/graph-propagation/engine.d.ts +63 -0
- package/types/core/graph-propagation/index.d.ts +2 -0
- package/types/core/index.d.ts +1 -0
- package/types/version.d.ts +1 -1
package/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './shape-type-inspector';
|
package/types/browser-ui/components/{inspector → shape-type-inspector}/shape-type-inspector.d.ts
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ShapePropertyDefinition } from "../../shape-library";
|
|
2
|
-
import { VanillaInspector } from "
|
|
2
|
+
import { VanillaInspector } from "../inspector/vanilla-inspector";
|
|
3
3
|
import { Base } from "../../../core";
|
|
4
|
-
import { VanillaInspectorOptions } from "
|
|
4
|
+
import { VanillaInspectorOptions } from "../inspector/definitions";
|
|
5
5
|
import { BrowserUI } from "../../browser-visuallyjs-instance";
|
|
6
6
|
/**
|
|
7
7
|
* Generates an HTML string in the Recado template format for all configurable
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Calculator, GraphPropagationEngine } from "../../../core/graph-propagation";
|
|
2
|
+
import { BrowserUI } from "../../browser-visuallyjs-instance";
|
|
3
|
+
import { BaseBrowserUIPlugin, BrowserUIPlugin, BrowserUIPluginOptions } from "../browser-ui-plugin";
|
|
4
|
+
/** Plugin type for graph value propagation. */
|
|
5
|
+
export declare const PLUGIN_TYPE_GRAPH_PROPAGATION = "graphPropagation";
|
|
6
|
+
/** Options for the graph propagation plugin. */
|
|
7
|
+
export interface GraphPropagationEnginePluginOptions<ValueType, StateType = unknown> extends BrowserUIPluginOptions {
|
|
8
|
+
/** Calculator functions keyed by node or group type. */
|
|
9
|
+
calculators: Record<string, Calculator<ValueType, StateType>>;
|
|
10
|
+
/** Model property used for propagated values. Defaults to `value`. */
|
|
11
|
+
property?: string;
|
|
12
|
+
/** Model property used for calculated node state. Defaults to `computed`. */
|
|
13
|
+
stateProperty?: string;
|
|
14
|
+
}
|
|
15
|
+
/** Browser UI plugin that runs a GraphPropagationEngine against the UI's model. */
|
|
16
|
+
export declare class GraphPropagationEnginePlugin<ValueType = unknown, StateType = unknown> extends BaseBrowserUIPlugin implements BrowserUIPlugin<GraphPropagationEnginePluginOptions<ValueType, StateType>> {
|
|
17
|
+
static type: string;
|
|
18
|
+
id: string;
|
|
19
|
+
ui: BrowserUI;
|
|
20
|
+
engine: GraphPropagationEngine<ValueType, StateType>;
|
|
21
|
+
initialise(ui: BrowserUI, options: GraphPropagationEnginePluginOptions<ValueType, StateType>): boolean;
|
|
22
|
+
destroy(): void;
|
|
23
|
+
reset(): void;
|
|
24
|
+
}
|
|
25
|
+
/** Gets the graph propagation plugin attached to a UI, if present. */
|
|
26
|
+
export declare function getGraphPropagationPlugin(ui: BrowserUI): GraphPropagationEnginePlugin | null;
|
|
@@ -271,6 +271,10 @@ export interface ShapePropertyDefinition {
|
|
|
271
271
|
* The data type of the property, telling the inspector which UI control to render by default. For properties that include a `values` array (and also properties of type boolean) you can override the choice of UI control via the `editor` option.
|
|
272
272
|
*/
|
|
273
273
|
type: ShapePropertyType;
|
|
274
|
+
/**
|
|
275
|
+
* If true, inspectors display this property's value without an editable control.
|
|
276
|
+
*/
|
|
277
|
+
readOnly?: boolean;
|
|
274
278
|
/**
|
|
275
279
|
* The default value for this property if it hasn't been explicitly set.
|
|
276
280
|
*/
|
|
@@ -2,6 +2,7 @@ import { LabelBackgroundOptions, LabelPosition, ShapeSet } from "../../shape-lib
|
|
|
2
2
|
import { Group, ObjectData, PointXY, Size, Vertex, Node, BeforeConnectInterceptor } from "../../../core";
|
|
3
3
|
import { DiagramCell } from "./diagram-cell";
|
|
4
4
|
import { GridOptions, UIExportOptions, UICoreDefaults, EdgeEventOptions, OverlaySpec, ConnectorSpec, NodeEventOptions, GroupMapping, NodeMapping, AnchorSpec, EdgePropertyMappings, MagnetizeOptions, PaintStyle, OverlayVisibility, EdgeDeleteConfirmationFunction, LabelBackgroundStyle, FontSpec } from "../../../ui";
|
|
5
|
+
import type { BindableViewEvent } from "../../../ui";
|
|
5
6
|
import { SurfaceSaveData } from "../definitions";
|
|
6
7
|
import { BrowserElement } from "../../util";
|
|
7
8
|
import { PaletteMode, AutoEdgeConnectOptions, CanDropOnEdgeFilter } from "../../components/palette/palette-options";
|
|
@@ -11,6 +12,65 @@ import { EdgeSnapOptions, EdgeInputMethod } from "../../edge-handler-base";
|
|
|
11
12
|
import { DiagramActionMediator } from "./mediator";
|
|
12
13
|
import { OnVertexAddedCallback } from "../../definitions";
|
|
13
14
|
import { PreparedShape } from "../shape-palette-options";
|
|
15
|
+
import { GraphPropagationEnginePluginOptions } from "../../plugins";
|
|
16
|
+
import type { BrowserUIModel } from "../../browser-ui";
|
|
17
|
+
import type { BrowserUI } from "../../browser-visuallyjs-instance";
|
|
18
|
+
import type { Diagram } from "./diagram";
|
|
19
|
+
/**
|
|
20
|
+
* Payload passed to a cell template event callback.
|
|
21
|
+
* @group Diagrams
|
|
22
|
+
* @category Events
|
|
23
|
+
*/
|
|
24
|
+
export interface DiagramCellTemplateEventCallbackPayload<E extends Event = Event> {
|
|
25
|
+
/**
|
|
26
|
+
* The diagram cell whose rendered template contained the matching event target.
|
|
27
|
+
*/
|
|
28
|
+
cell: DiagramCell;
|
|
29
|
+
/**
|
|
30
|
+
* The backing vertex for the cell.
|
|
31
|
+
*/
|
|
32
|
+
vertex: Node | Group;
|
|
33
|
+
/**
|
|
34
|
+
* The original browser event.
|
|
35
|
+
*/
|
|
36
|
+
event: E;
|
|
37
|
+
/**
|
|
38
|
+
* The element inside the rendered shape template that matched the configured selector.
|
|
39
|
+
*/
|
|
40
|
+
eventTarget: BrowserElement;
|
|
41
|
+
/**
|
|
42
|
+
* The diagram that owns the cell.
|
|
43
|
+
*/
|
|
44
|
+
diagram: Diagram;
|
|
45
|
+
/**
|
|
46
|
+
* The underlying VisuallyJs model.
|
|
47
|
+
*/
|
|
48
|
+
model: BrowserUIModel;
|
|
49
|
+
/**
|
|
50
|
+
* The UI that rendered the diagram.
|
|
51
|
+
*/
|
|
52
|
+
ui: BrowserUI;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Callback invoked for an event on an element inside a rendered cell template.
|
|
56
|
+
* @group Diagrams
|
|
57
|
+
* @category Events
|
|
58
|
+
*/
|
|
59
|
+
export type DiagramCellTemplateEventCallback<E extends Event = Event> = (p: DiagramCellTemplateEventCallbackPayload<E>) => any;
|
|
60
|
+
/**
|
|
61
|
+
* A map of event names to callbacks for a single selector inside a rendered cell template.
|
|
62
|
+
* @group Diagrams
|
|
63
|
+
* @category Events
|
|
64
|
+
*/
|
|
65
|
+
export type DiagramCellTemplateEventMap = {
|
|
66
|
+
[K in BindableViewEvent]?: DiagramCellTemplateEventCallback;
|
|
67
|
+
} & Record<string, DiagramCellTemplateEventCallback | undefined>;
|
|
68
|
+
/**
|
|
69
|
+
* A map of CSS selectors to event/callback maps for elements inside rendered cell templates.
|
|
70
|
+
* @group Diagrams
|
|
71
|
+
* @category Events
|
|
72
|
+
*/
|
|
73
|
+
export type DiagramCellTemplateEvents = Record<string, DiagramCellTemplateEventMap>;
|
|
14
74
|
/**
|
|
15
75
|
* Options for the {@link Diagram.addLink method}
|
|
16
76
|
* @group Diagrams
|
|
@@ -353,6 +413,26 @@ export interface DiagramOptions {
|
|
|
353
413
|
* Optional event mappings for all cells.
|
|
354
414
|
*/
|
|
355
415
|
events?: NodeEventOptions<any>;
|
|
416
|
+
/**
|
|
417
|
+
* Optional delegated event mappings for elements inside rendered cell templates. Keys are CSS selectors
|
|
418
|
+
* that match elements inside a shape template, and values are maps of event names to callbacks.
|
|
419
|
+
*
|
|
420
|
+
* The callback receives the {@link DiagramCell} associated with the matching element, plus the backing
|
|
421
|
+
* vertex, the original browser event, the matching element, the diagram, the model and the UI.
|
|
422
|
+
*
|
|
423
|
+
* For example:
|
|
424
|
+
*
|
|
425
|
+
* ```ts
|
|
426
|
+
* cells:{
|
|
427
|
+
* templateEvents:{
|
|
428
|
+
* ".delete":{
|
|
429
|
+
* tap:({cell}) => cell.remove()
|
|
430
|
+
* }
|
|
431
|
+
* }
|
|
432
|
+
* }
|
|
433
|
+
* ```
|
|
434
|
+
*/
|
|
435
|
+
templateEvents?: DiagramCellTemplateEvents;
|
|
356
436
|
/**
|
|
357
437
|
* Optional behaviour mapping for groups in the diagram. For many setups, you won't need to use this, as the other options in the `cells` config are quite extensive and can be used to configure many things. For some setups you may need to provide config for group behaviour, such as whether or not vertices can be dragged in/out, whether the group should be resizable, etc. You can also provide group-specific event mappings here. Any `events` you provide here will be merged with the internal event registrations made by the diagram, but if you provide a `template` it will be ignored.
|
|
358
438
|
*/
|
|
@@ -366,6 +446,9 @@ export interface DiagramOptions {
|
|
|
366
446
|
* Optional mapping for nodes in the diagram. For many setups, you won't need to use this, as the other options in the `cells` config are quite extensive and can be used to configure many things. Any `events` you provide here will be merged with the internal event registrations made by the diagram, but if you provide a `template` it will be ignored.
|
|
367
447
|
*/
|
|
368
448
|
nodes?: DiagramNodeMapping;
|
|
449
|
+
/**
|
|
450
|
+
* Options controlling how resize functions.
|
|
451
|
+
*/
|
|
369
452
|
resize?: {
|
|
370
453
|
/**
|
|
371
454
|
* Width/height to use for resize handles. Defaults to 20 pixels.
|
|
@@ -483,6 +566,10 @@ export interface DiagramOptions {
|
|
|
483
566
|
* Controls whether line crossings are shown by a visual cue. Defaults to false. You can either supply a boolean and have the panbuttons plugin initialize with its default settings, or supply your own settings.
|
|
484
567
|
*/
|
|
485
568
|
lineCrossings?: boolean | LineCrossingsPluginOptions;
|
|
569
|
+
/**
|
|
570
|
+
* If provided, a graph propagation engine will be used to propagate changes to the graph.
|
|
571
|
+
*/
|
|
572
|
+
graphPropagation?: GraphPropagationEnginePluginOptions<any>;
|
|
486
573
|
}
|
|
487
574
|
/**
|
|
488
575
|
* Options for a palette for a diagram.
|
|
@@ -15,6 +15,7 @@ export declare const ATTRIBUTE_DATA_SHAPE_ID = "data-shape-id";
|
|
|
15
15
|
*/
|
|
16
16
|
export declare class ShapePalette<T extends ObjectData> {
|
|
17
17
|
private ui;
|
|
18
|
+
_$_iconTemplateEngine: BrowserUiRecado;
|
|
18
19
|
_$_templateEngine: BrowserUiRecado;
|
|
19
20
|
_$_palette: Palette;
|
|
20
21
|
_$_userDataGenerator: DataGeneratorFunction;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Node } from "../model/graph";
|
|
2
|
+
/**
|
|
3
|
+
* Terminal id used when an edge connects directly to a node or group instead of a named port.
|
|
4
|
+
* For example, junctions and probes use this as their implicit input/output terminal.
|
|
5
|
+
*/
|
|
6
|
+
export declare const DEFAULT_TERMINAL = "default";
|
|
7
|
+
/**
|
|
8
|
+
* Result returned by a node calculator.
|
|
9
|
+
* @typeParam ValueType Defines the type of the node's output values.
|
|
10
|
+
* @typeParam StateType Defines the type of the node's internal state.
|
|
11
|
+
*/
|
|
12
|
+
export type NodeEvaluation<ValueType, StateType = unknown> = {
|
|
13
|
+
/**
|
|
14
|
+
* Values made available to downstream edges, keyed by terminal id. Keys are port ids such as"out"`, or `DEFAULT_TERMINAL` for direct node connections
|
|
15
|
+
*/
|
|
16
|
+
outputs?: Record<string, ValueType | undefined>;
|
|
17
|
+
/**
|
|
18
|
+
* Derived node state (such as display text, validation details, or cached intermediate results) written to the node's configured state property.
|
|
19
|
+
*/
|
|
20
|
+
state?: StateType;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Helper API passed to calculators so they can read upstream values without knowing graph details.
|
|
24
|
+
* @typeParam ValueType Defines the type of the node's output values.
|
|
25
|
+
*/
|
|
26
|
+
export interface EvaluationContext<ValueType> {
|
|
27
|
+
/**
|
|
28
|
+
* Reads the value connected to one input terminal. Omit `terminalId` or pass `DEFAULT_TERMINAL` for direct node-body connections. Otherwise terminalId is assumed to map to a port ID on the node.
|
|
29
|
+
*/
|
|
30
|
+
input: (terminalId?: string) => ValueType | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Reads named input terminals in order. When omitted, reads every edge connected directly to the node body, in edge order.
|
|
33
|
+
*/
|
|
34
|
+
inputs: (terminalIds?: string[]) => Array<ValueType | undefined>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Evaluates a node from its current upstream inputs - the function has access to the `input(...)` and `inputs(..)` methods on the evaluation context that is passed in, for resolving the input values on the node.
|
|
38
|
+
* @typeParam ValueType Defines the type of the node's output values.
|
|
39
|
+
* @typeParam StateType Defines the type of the node's internal state.
|
|
40
|
+
*/
|
|
41
|
+
export type Calculator<ValueType, StateType = unknown> = (node: Node, context: EvaluationContext<ValueType>) => NodeEvaluation<ValueType, StateType> | undefined;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { VisuallyJsModel } from "../toolkit";
|
|
2
|
+
import { Calculator } from "./definitions";
|
|
3
|
+
/**
|
|
4
|
+
* Full calculation output before it is written back to the model.
|
|
5
|
+
*/
|
|
6
|
+
type CalculationResult<ValueType, StateType> = {
|
|
7
|
+
/** Propagated values keyed by concrete vertex id, for example `nodeId.out`. */
|
|
8
|
+
values: Map<string, ValueType>;
|
|
9
|
+
/** Computed node states keyed by node or group id. */
|
|
10
|
+
states: Map<string, StateType>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Propagates computed values through a VisuallyJS graph.
|
|
14
|
+
*
|
|
15
|
+
* The engine treats each node or group as the unit of computation. A calculator is registered per
|
|
16
|
+
* vertex type, reads upstream values through an `EvaluationContext`, and returns output terminal
|
|
17
|
+
* values plus optional internal state for that vertex.
|
|
18
|
+
*
|
|
19
|
+
* Output keys are terminal ids: use a port id for named ports, or `DEFAULT_TERMINAL` for edges
|
|
20
|
+
* connected directly to the node/group body. During propagation, the engine maps those terminal ids
|
|
21
|
+
* back to concrete graph vertices and writes propagated values to `property` on target vertices.
|
|
22
|
+
*
|
|
23
|
+
* Calculator `state` is not propagated across edges. It is written to the owning node/group under
|
|
24
|
+
* `stateProperty`, making it suitable for display data, validation results, summaries, or cached
|
|
25
|
+
* derived values.
|
|
26
|
+
*
|
|
27
|
+
* To integrate, define calculators keyed by node/group type, construct the engine with a
|
|
28
|
+
* `VisuallyJsModel`, and read propagated values from vertices using `property` and computed state
|
|
29
|
+
* from nodes/groups using `stateProperty`.
|
|
30
|
+
*/
|
|
31
|
+
export declare class GraphPropagationEngine<ValueType, StateType = unknown> {
|
|
32
|
+
private model;
|
|
33
|
+
private calculators;
|
|
34
|
+
private _suspended;
|
|
35
|
+
private _property;
|
|
36
|
+
private _stateProperty;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a propagation engine and binds it to model update events.
|
|
39
|
+
*
|
|
40
|
+
* Edge additions/removals and data updates on connected vertices trigger recalculation on the
|
|
41
|
+
* next animation frame. Updates produced by the engine are applied in one model transaction.
|
|
42
|
+
*
|
|
43
|
+
* @param model Model whose nodes, groups, ports, and edges should participate in propagation.
|
|
44
|
+
* @param calculators Calculator functions keyed by node/group type.
|
|
45
|
+
* @param property Data property used for propagated vertex values. Defaults to `"value"`.
|
|
46
|
+
* @param stateProperty Data property used for computed node/group state. Defaults to `"computed"`.
|
|
47
|
+
*/
|
|
48
|
+
constructor(model: VisuallyJsModel, calculators: Record<string, Calculator<ValueType, StateType>>, property?: string, stateProperty?: string);
|
|
49
|
+
/**
|
|
50
|
+
* Runs propagation immediately and writes the result back to the model.
|
|
51
|
+
*
|
|
52
|
+
* `knownValues` can seed the value cache for this run. Keys must be concrete vertex ids, such
|
|
53
|
+
* as a node id or full port id. This is useful when an edited source value is already known and
|
|
54
|
+
* should be used before the model has been fully re-read.
|
|
55
|
+
*/
|
|
56
|
+
calculate(knownValues?: Record<string, ValueType>): CalculationResult<ValueType, StateType>;
|
|
57
|
+
/**
|
|
58
|
+
* The main entry point for the calculation. Iterates through all nodes, resolves their new state, and updates the model if the state has changed.
|
|
59
|
+
*/
|
|
60
|
+
private _calculate;
|
|
61
|
+
private _apply;
|
|
62
|
+
}
|
|
63
|
+
export {};
|
package/types/core/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from './model/path';
|
|
|
8
8
|
export * from './model/anchor';
|
|
9
9
|
export * from './datamodel/data-model';
|
|
10
10
|
export * from './datamodel/vertex-definition';
|
|
11
|
+
export * from './graph-propagation';
|
|
11
12
|
export * from './layout';
|
|
12
13
|
export * from "./geom";
|
|
13
14
|
export * from './color-generator';
|
package/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "1.2.
|
|
1
|
+
export declare const VERSION = "1.2.8";
|