@graphty/graphty-element 2.6.2 → 3.0.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.
Files changed (163) hide show
  1. package/dist/ai.js +3 -3
  2. package/dist/catalog.js +53 -54
  3. package/dist/chunks/{AiManager-4iQpsJW1.js → AiManager-Bhh0rR_p.js} +706 -655
  4. package/dist/chunks/GraphSession-DPoTaT3b.js +21175 -0
  5. package/dist/chunks/{GraphtyLogger-B_O67a6c.js → GraphtyLogger-BtcBJQPL.js} +1 -1
  6. package/dist/chunks/{VoiceInputAdapter-Cc6mHXTI.js → VoiceInputAdapter-CdLsJ_nG.js} +1 -1
  7. package/dist/chunks/{XRPivotCameraController-BLa89LXn.js → XRPivotCameraController-CiLJ9Gz6.js} +2 -2
  8. package/dist/chunks/algorithms-qij74zEN.js +6811 -0
  9. package/dist/chunks/{capability-check-Am2zliFj.js → capability-check-BbgTejS3.js} +1 -1
  10. package/dist/chunks/definePalette-BYt2Llxs.js +1333 -0
  11. package/dist/chunks/fields-5uVC1Pll.js +4999 -0
  12. package/dist/chunks/{format-detection-BHwrAVzW.js → format-detection-FKaDMshR.js} +1 -1
  13. package/dist/chunks/{index-BkBLbvui.js → index-Cc_6D9hV.js} +6034 -7127
  14. package/dist/chunks/interpolation-Dk206AhZ.js +105 -0
  15. package/dist/chunks/paletteRegistry-De3CGdst.js +357 -0
  16. package/dist/chunks/parse-SVp77JbE.js +669 -0
  17. package/dist/chunks/{pluginRegistry-Bs8bEkz9.js → pluginRegistry-Ddfl6Mv2.js} +27 -24
  18. package/dist/chunks/{registry-BdGvyZou.js → registry-CgMqldp4.js} +1 -1
  19. package/dist/chunks/{DataSource-BL2UzPff.js → sources-BbAJCDIH.js} +279 -108
  20. package/dist/commands.d.ts +128 -19
  21. package/dist/commands.js +49 -1
  22. package/dist/custom-elements.json +1 -1
  23. package/dist/extend.d.ts +10 -2
  24. package/dist/extend.js +64 -57
  25. package/dist/graphty-catalog.json +6 -3
  26. package/dist/graphty.bundle.js +267177 -240648
  27. package/dist/graphty.js +84 -78
  28. package/dist/index.d.ts +4 -0
  29. package/dist/logging.js +2 -2
  30. package/dist/schema.js +70 -71
  31. package/dist/session.d.ts +5 -6
  32. package/dist/session.js +40 -86
  33. package/dist/src/Edge.d.ts +31 -67
  34. package/dist/src/Graph.d.ts +335 -77
  35. package/dist/src/Node.d.ts +36 -3
  36. package/dist/src/NodeBehavior.d.ts +28 -0
  37. package/dist/src/Styles.d.ts +15 -4
  38. package/dist/src/acceleration/AccelerationController.d.ts +8 -0
  39. package/dist/src/acceleration/narrow.d.ts +9 -1
  40. package/dist/src/acceleration/types.d.ts +10 -0
  41. package/dist/src/ai/AiController.d.ts +12 -0
  42. package/dist/src/ai/AiManager.d.ts +7 -0
  43. package/dist/src/ai/commands/AlgorithmCommands.d.ts +1 -1
  44. package/dist/src/ai/commands/LayoutCommands.d.ts +1 -1
  45. package/dist/src/ai/commands/StyleCommands.d.ts +1 -1
  46. package/dist/src/ai/commands/types.d.ts +20 -1
  47. package/dist/src/algorithms/Algorithm.d.ts +21 -4
  48. package/dist/src/algorithms/BFSAlgorithm.d.ts +0 -9
  49. package/dist/src/algorithms/BellmanFordAlgorithm.d.ts +0 -14
  50. package/dist/src/algorithms/DFSAlgorithm.d.ts +1 -1
  51. package/dist/src/algorithms/FloydWarshallAlgorithm.d.ts +5 -0
  52. package/dist/src/algorithms/GirvanNewmanAlgorithm.d.ts +5 -0
  53. package/dist/src/algorithms/LeidenAlgorithm.d.ts +5 -0
  54. package/dist/src/algorithms/PageRankAlgorithm.d.ts +1 -1
  55. package/dist/src/algorithms/StronglyConnectedComponentsAlgorithm.d.ts +1 -1
  56. package/dist/src/algorithms/metrics/fields.d.ts +23 -1
  57. package/dist/src/algorithms/utils/graphUtils.d.ts +13 -1
  58. package/dist/src/catalog/paletteRegistry.d.ts +4 -4
  59. package/dist/src/catalog/registry.d.ts +3 -2
  60. package/dist/src/catalog/types.d.ts +18 -1
  61. package/dist/src/config/GraphStyle.d.ts +1 -1
  62. package/dist/src/config/StyleTemplate.d.ts +2 -2
  63. package/dist/src/config/xr-config-schema.d.ts +4 -4
  64. package/dist/src/data/CSVDataSource.d.ts +77 -22
  65. package/dist/src/data/ErrorAggregator.d.ts +5 -0
  66. package/dist/src/data/GEXFDataSource.d.ts +12 -61
  67. package/dist/src/data/GraphMLDataSource.d.ts +3 -44
  68. package/dist/src/data/GraphStore.d.ts +322 -15
  69. package/dist/src/data/JsonDataSource.d.ts +43 -1
  70. package/dist/src/data/graph-io-import.d.ts +89 -0
  71. package/dist/src/data/graph-io-records.d.ts +64 -0
  72. package/dist/src/data/lane.d.ts +23 -0
  73. package/dist/src/data/positions.d.ts +13 -0
  74. package/dist/src/data/seedPosition.d.ts +16 -0
  75. package/dist/src/errors/GraphtyError.d.ts +3 -1
  76. package/dist/src/errors/codes.d.ts +23 -0
  77. package/dist/src/events.d.ts +12 -0
  78. package/dist/src/graphty-element.d.ts +149 -54
  79. package/dist/src/input/types.d.ts +2 -0
  80. package/dist/src/layout/D3GraphLayoutEngine.d.ts +17 -3
  81. package/dist/src/layout/FixedLayoutEngine.d.ts +20 -4
  82. package/dist/src/layout/KamadaKawaiLayoutEngine.d.ts +6 -0
  83. package/dist/src/layout/LayoutEngine.d.ts +214 -116
  84. package/dist/src/layout/NGraphLayoutEngine.d.ts +10 -3
  85. package/dist/src/layout/SimulationLayoutEngine.d.ts +8 -3
  86. package/dist/src/managers/AlgorithmManager.d.ts +24 -5
  87. package/dist/src/managers/DataManager.d.ts +258 -181
  88. package/dist/src/managers/EventManager.d.ts +5 -2
  89. package/dist/src/managers/GraphContext.d.ts +7 -0
  90. package/dist/src/managers/InputManager.d.ts +11 -0
  91. package/dist/src/managers/LayoutManager.d.ts +129 -50
  92. package/dist/src/managers/RenderManager.d.ts +14 -1
  93. package/dist/src/managers/UpdateManager.d.ts +20 -0
  94. package/dist/src/screenshot/ScreenshotCapture.d.ts +1 -1
  95. package/dist/src/session/GraphSession.d.ts +83 -6
  96. package/dist/src/session/commands/algo.d.ts +169 -0
  97. package/dist/src/session/commands/config.d.ts +45 -0
  98. package/dist/src/session/commands/data.d.ts +178 -0
  99. package/dist/src/session/commands/doors.d.ts +93 -0
  100. package/dist/src/session/commands/index.d.ts +20 -0
  101. package/dist/src/session/commands/layout.d.ts +104 -0
  102. package/dist/src/session/commands/positions.d.ts +30 -0
  103. package/dist/src/session/commands/sets.d.ts +113 -0
  104. package/dist/src/session/commands/style.d.ts +92 -0
  105. package/dist/src/session/commands/view.d.ts +57 -0
  106. package/dist/src/session/commands/visibility.d.ts +41 -0
  107. package/dist/src/session/data.d.ts +131 -4
  108. package/dist/src/session/index.d.ts +1 -1
  109. package/dist/src/session/planning.d.ts +25 -8
  110. package/dist/src/session/project/Dispatcher.d.ts +905 -0
  111. package/dist/src/session/project/History.d.ts +382 -0
  112. package/dist/src/session/project/arrangement.d.ts +247 -0
  113. package/dist/src/session/project/derive.d.ts +132 -0
  114. package/dist/src/session/project/digest.d.ts +33 -0
  115. package/dist/src/session/project/draft.d.ts +194 -0
  116. package/dist/src/session/project/graphOps.d.ts +304 -0
  117. package/dist/src/session/project/ingest.d.ts +364 -0
  118. package/dist/src/session/project/state.d.ts +145 -0
  119. package/dist/src/session/project/strict.d.ts +68 -0
  120. package/dist/src/session/results/RunResult.d.ts +48 -0
  121. package/dist/src/session/results/statistics.d.ts +20 -0
  122. package/dist/src/session/runs/Run.d.ts +80 -4
  123. package/dist/src/session/runs/RunsApi.d.ts +23 -6
  124. package/dist/src/session/runs/types.d.ts +25 -6
  125. package/dist/src/session/scope/ElementMask.d.ts +14 -0
  126. package/dist/src/session/scope/ScopeApi.d.ts +3 -22
  127. package/dist/src/session/scope/spaces.d.ts +29 -0
  128. package/dist/src/session/sealed.d.ts +22 -0
  129. package/dist/src/session/selection/SelectionApi.d.ts +14 -4
  130. package/dist/src/session/sets/SetsApi.d.ts +13 -5
  131. package/dist/src/session/sets/store.d.ts +54 -53
  132. package/dist/src/session/sets/types.d.ts +5 -2
  133. package/dist/src/session/styles/Layer.d.ts +5 -0
  134. package/dist/src/session/styles/StylesApi.d.ts +68 -17
  135. package/dist/src/session/styles/autoApply.d.ts +64 -53
  136. package/dist/src/session/styles/index.d.ts +3 -3
  137. package/dist/src/session/styles/predicate.d.ts +7 -0
  138. package/dist/src/session/styles/repaint.d.ts +16 -1
  139. package/dist/src/session/styles/sources.d.ts +1 -1
  140. package/dist/src/session/types.d.ts +625 -54
  141. package/dist/src/session/visibility/VisibilityApi.d.ts +38 -18
  142. package/dist/src/session/visibility/filter.d.ts +10 -0
  143. package/dist/src/simple/defineAlgorithm.d.ts +28 -0
  144. package/dist/src/simple/defineLayout.d.ts +35 -0
  145. package/dist/src/simple/defineLogDestination.d.ts +31 -0
  146. package/dist/src/simple/definePalette.d.ts +26 -0
  147. package/dist/src/simple/definition.d.ts +106 -0
  148. package/dist/src/simple/options.d.ts +33 -0
  149. package/dist/src/simple/source.d.ts +49 -0
  150. package/dist/src/simple/types.d.ts +366 -0
  151. package/dist/src/simple/view.d.ts +107 -0
  152. package/dist/webgpu.js +2 -2
  153. package/package.json +10 -12
  154. package/dist/chunks/GraphSession-BhuHSXIo.js +0 -12819
  155. package/dist/chunks/GraphStyle-Cwr55SAE.js +0 -65
  156. package/dist/chunks/algorithms-BJ6DQMOe.js +0 -3777
  157. package/dist/chunks/detect-fyuVnlCT.js +0 -88
  158. package/dist/chunks/interpolation-DY-PNpqX.js +0 -43
  159. package/dist/chunks/optionsFromZod-CKMYSwTz.js +0 -3636
  160. package/dist/chunks/paletteRegistry-BCFSwJGK.js +0 -1196
  161. package/dist/chunks/parse-BMTqt4SS.js +0 -3658
  162. package/dist/src/data/csv-variant-detection.d.ts +0 -29
  163. package/dist/src/data/ingest.d.ts +0 -104
@@ -94,6 +94,7 @@ export declare class ElementPositions {
94
94
  */
95
95
  private pins;
96
96
  private rows;
97
+ private moves;
97
98
  /**
98
99
  * Allocate the backing array, every row unplaced and unpinned.
99
100
  * @param capacity - rows to reserve before the first growth; a non-negative integer
@@ -104,6 +105,18 @@ export declare class ElementPositions {
104
105
  * @returns the current capacity in rows
105
106
  */
106
107
  get capacity(): number;
108
+ /**
109
+ * Moves whenever coordinates are written on purpose: by {@link ElementPositions.write}, which
110
+ * every layout, drag and placement goes through, and by {@link ElementPositions.moved}, which a
111
+ * writer that fills the array {@link ElementPositions.view} lends (a GPU readback, a restore)
112
+ * calls once per batch. Seeding a new row and renumbering rows do not move it: those follow
113
+ * the graph, not the arrangement. The undo history compares it with the generation of its
114
+ * last capture to tell whether the lane has moved since (design/undo/undo-design.md 6.4).
115
+ * @returns the generation
116
+ */
117
+ get generation(): number;
118
+ /** Say that coordinates were written straight into the lent array. */
119
+ moved(): void;
107
120
  /**
108
121
  * Rows currently in use. Equals the last snapshot's nodeCount.
109
122
  * @returns the live row count
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The file-unit coordinate a record carries, in the two shapes the element's own data has always
3
+ * used, or null when it carries none.
4
+ *
5
+ * `{ x, y, z? }` is what `FixedLayoutEngine` reads off `node.data` today
6
+ * (`src/layout/FixedLayoutEngine.ts`), and `[x, y]` / `[x, y, z]` is the array form the importers
7
+ * produce. A missing z is 0, not NaN: a 2D record IS placed, on the z = 0 plane, and NaN is
8
+ * reserved for "no layout has run".
9
+ *
10
+ * Anything non-finite makes the WHOLE record unseeded rather than partly seeded. A row stored with
11
+ * one NaN component reports itself PLACED (`ElementPositions.isPlaced` tests x), so a layout would
12
+ * never repair it and the mesh would vanish; left unseeded, the node is laid out like any other.
13
+ * @param record - the raw node record
14
+ * @returns the file-unit triple, or null when there is nothing usable to seed
15
+ */
16
+ export declare function readSeedPosition(record: Record<string | number, unknown>): [number, number, number] | null;
@@ -12,7 +12,9 @@ import { type GraphtyErrorCode } from "./codes";
12
12
  * It answers "who was doing this" without the consumer parsing a message, and it is what an
13
13
  * error panel groups on.
14
14
  */
15
- export type GraphtyErrorSource = "data" | "run" | "layout" | "style" | "view" | "acceleration" | "registry" | "config";
15
+ export type GraphtyErrorSource = "data" | "run" | "layout" | "style" | "view" | "acceleration" | "registry" | "config"
16
+ /** Undo, redo, transactions and the one path every change to project state takes. */
17
+ | "history";
16
18
  /**
17
19
  * The thing a failure belongs to, when it belongs to a thing rather than to the session.
18
20
  *
@@ -308,6 +308,29 @@ export type GraphtyErrorCode =
308
308
  * was disposed. The caller creates a new session; nothing about the disposed one recovers.
309
309
  */
310
310
  | "E_DISPOSED"
311
+ /**
312
+ * An extension's own code threw: a function in a simple-tier definition (an algorithm's
313
+ * `node`, a layout's `place`), called by the element. `details.extension` is the extension's
314
+ * id, `details.member` the function, and `cause` the original error. The extension's author
315
+ * fixes their code; this is not a defect in graphty-element, which is what `E_INTERNAL` means.
316
+ */
317
+ | "E_EXTENSION_FAILED"
318
+ /**
319
+ * A command was dispatched through a transaction's `tx` after the transaction's callback had
320
+ * settled, so the step it belonged to was already recorded. `details.transaction` names the
321
+ * transaction. The caller dispatches everything the transaction should contain before its
322
+ * callback returns (awaiting what it needs), or dispatches later work through the session as
323
+ * its own step.
324
+ */
325
+ | "E_TRANSACTION_CLOSED"
326
+ /**
327
+ * A command needs a node or edge id (or a whole graph or pin slice) that an open transaction
328
+ * has written and holds until it is recorded. It fails at once rather than waiting, because
329
+ * the transaction's callback may itself be waiting on this command. `details.transaction`
330
+ * names the transaction and `details.key` the held key. The caller dispatches the command
331
+ * through that transaction's `tx`, or dispatches it again once the transaction has settled.
332
+ */
333
+ | "E_HELD_BY_TRANSACTION"
311
334
  /**
312
335
  * An invariant inside the element broke. This is a bug in graphty-element, not in the call.
313
336
  * `details` and `cause` carry whatever is safe to report. The caller files an issue with the
@@ -8,6 +8,7 @@ import type { Edge } from "./Edge";
8
8
  import type { Graph } from "./Graph";
9
9
  import type { Node } from "./Node";
10
10
  import type { StyleChange } from "./session/styles/StylesApi";
11
+ import type { HistoryCause } from "./session/types";
11
12
  export type EventType = GraphEventType | NodeEventType | EdgeEventType | AiEventType;
12
13
  export type EventCallbackType = (evt: GraphEvent | NodeEvent | EdgeEvent | AiEvent) => void;
13
14
  type AnyEvent = GraphEvent | NodeEvent | EdgeEvent | AiEvent;
@@ -71,6 +72,8 @@ export interface GraphDataLoadedEvent {
71
72
  */
72
73
  loadId?: number;
73
74
  };
75
+ /** What loaded it; absent for a load that does not yet come through the session's history. */
76
+ cause?: HistoryCause;
74
77
  }
75
78
  export interface GraphDataAddedEvent {
76
79
  type: "data-added";
@@ -78,6 +81,13 @@ export interface GraphDataAddedEvent {
78
81
  count: number;
79
82
  shouldStartLayout: boolean;
80
83
  shouldZoomToFit: boolean;
84
+ /**
85
+ * What added the rows: a command, or undo, redo or a rollback bringing them back. Absent for a
86
+ * load that does not yet come through the session's history (a data source, a file, a URL).
87
+ * The element starts a layout, frames the camera and runs the on-load algorithms only for
88
+ * rows a command or such a load added, never for rows undo or redo brought back.
89
+ */
90
+ cause?: HistoryCause;
81
91
  }
82
92
  /**
83
93
  * Emitted by DataManager after every freeze, once the element's position column is attached to the
@@ -281,6 +291,8 @@ export interface ElementsRemovedEvent {
281
291
  nodes: NodeId[];
282
292
  /** Every edge that was attached to one of them, and therefore went with it. */
283
293
  edges: EdgeId[];
294
+ /** What removed them; absent for a removal that does not yet come through the history. */
295
+ cause?: HistoryCause;
284
296
  }
285
297
  export interface SelectionChangedEvent {
286
298
  type: "selection-changed";
@@ -10,6 +10,8 @@ import type { ScreenshotOptions, ScreenshotResult } from "./screenshot/types.js"
10
10
  import type { GraphSession } from "./session";
11
11
  import type { Run, StartOptions } from "./session/runs";
12
12
  import type { SelectionDelta, SelectionOp, SelectionTarget } from "./session/selection";
13
+ import type { DefaultPalettes } from "./session/styles";
14
+ import type { TransactionScope } from "./session/types";
13
15
  /**
14
16
  * Graphty creates a graph
15
17
  */
@@ -97,6 +99,28 @@ export declare class Graphty extends LitElement {
97
99
  * ```
98
100
  */
99
101
  select(target: SelectionTarget, op?: SelectionOp): Promise<SelectionDelta>;
102
+ /**
103
+ * Choose the palette a colour binding uses when it names none, one per palette kind.
104
+ *
105
+ * Forwarded from `session.styles.setDefaultPalettes`. A default is resolved when a style
106
+ * layer is written, so a saved document always names a concrete palette: call it before
107
+ * loading data or adding layers. A later call warns and names the layers that keep the
108
+ * previous default, or with `reapply: true` repaints them with the new one.
109
+ * @param palettes - A palette id per kind: `categorical`, `sequential` and `diverging`.
110
+ * @param options - How a late call treats the layers already written.
111
+ * @param options.reapply - True re-resolves the layers that took the previous default.
112
+ * @since 2.7.0
113
+ * @example
114
+ * ```ts
115
+ * import { definePalette } from "@graphty/graphty-element/extend";
116
+ *
117
+ * definePalette({ id: "acme-brand", kind: "categorical", colors: ["#0B1D51", "#1B7F79"] });
118
+ * element.setDefaultPalettes({ categorical: "acme-brand" });
119
+ * ```
120
+ */
121
+ setDefaultPalettes(palettes: DefaultPalettes, options?: {
122
+ readonly reapply?: boolean;
123
+ }): void;
100
124
  /**
101
125
  * Called when the element is added to the DOM. Sets up the graph container and resize observer.
102
126
  */
@@ -149,7 +173,8 @@ export declare class Graphty extends LitElement {
149
173
  */
150
174
  get nodeData(): Record<string, unknown>[] | undefined;
151
175
  /**
152
- * Sets the node data array. Replaces the graph's nodes with these.
176
+ * Replaces the graph's nodes with these, as one undoable step: a node the array names again
177
+ * keeps its row and its edges, and one it no longer names goes, with its edges.
153
178
  */
154
179
  set nodeData(value: Record<string, unknown>[] | undefined);
155
180
  /**
@@ -181,7 +206,7 @@ export declare class Graphty extends LitElement {
181
206
  */
182
207
  get edgeData(): Record<string, unknown>[] | undefined;
183
208
  /**
184
- * Sets the edge data array. Triggers addition of edges to the graph.
209
+ * Replaces the graph's edges with these, as one undoable step.
185
210
  */
186
211
  set edgeData(value: Record<string, unknown>[] | undefined);
187
212
  /**
@@ -191,8 +216,8 @@ export declare class Graphty extends LitElement {
191
216
  */
192
217
  get dataSource(): string | undefined;
193
218
  /**
194
- * Sets the data source type. Starts a load when combined with dataSourceConfig; see
195
- * `dataSourceConfig` for what a second assignment does.
219
+ * Sets the data source type. Loads the graph from it, replacing what the graph held, once the
220
+ * configuration is set too.
196
221
  */
197
222
  set dataSource(value: string | undefined);
198
223
  /**
@@ -202,35 +227,21 @@ export declare class Graphty extends LitElement {
202
227
  */
203
228
  get dataSourceConfig(): Record<string, unknown> | undefined;
204
229
  /**
205
- * Sets the data source configuration. Starts a load when combined with dataSource.
206
- *
207
- * Every assignment of the pair starts a load, and assigning both halves in one task starts
208
- * one. Assigning the pair already loaded -- the same type and the same config object --
209
- * starts none, unless that load failed; pass a new object to load again. The first load adds
210
- * to the graph; each later one REPLACES it, but only once the new source has parsed -- a
211
- * malformed or empty source leaves the graph as it was and reports `data-loading-error`.
212
- * The pair assigned LAST wins: a slower earlier load that finishes afterwards is dropped.
213
- * Every event about the load carries its `loadId`. A caller that wants to await the load
214
- * calls `loadFromUrl`, `loadFromFile` or `addDataFromSource` instead.
230
+ * Sets the data source configuration. Loads the graph from it, replacing what the graph
231
+ * held, once the type is set too.
215
232
  */
216
233
  set dataSourceConfig(value: Record<string, unknown> | undefined);
217
234
  /**
218
- * Removes every node and edge, and forgets the data-source pair. A load still in flight is
235
+ * Removes every node and edge, as one undoable step. The data source goes with them, so the
236
+ * next `dataSource` / `dataSourceConfig` assignment loads afresh. A load still in flight is
219
237
  * abandoned: it rejects with `E_SUPERSEDED` and adds nothing.
220
- *
221
- * The next pair assigned after it loads into an empty graph, as the first one did.
222
- *
223
- * The two properties are reset with it, and deliberately through the private fields
224
- * rather than the setters: a setter would call `#tryInitializeDataSource` again, and
225
- * leaving the old pair in place would let the next half-assignment load the NEW
226
- * source against the OLD config.
227
238
  */
228
239
  clearData(): void;
229
240
  /**
230
241
  * A jmespath string that can be used to select the unique node identifier
231
242
  * for each node. Defaults to "id", as in `{id: 42}` is the identifier of
232
243
  * the node.
233
- * @returns JMESPath string or undefined if not set
244
+ * @returns The value set on this element, else the value in effect (undefined when that is none)
234
245
  */
235
246
  get nodeIdPath(): string | undefined;
236
247
  /**
@@ -245,7 +256,7 @@ export declare class Graphty extends LitElement {
245
256
  * then `from`/`to`, deciding once per batch of edge records. Setting this settles the question
246
257
  * and turns the probe off, and a record that does not answer it is then a rejected record
247
258
  * rather than a reason to guess again.
248
- * @returns JMESPath string or undefined if not set
259
+ * @returns The value set on this element, else the value in effect (undefined when that is none)
249
260
  */
250
261
  get edgeSrcIdPath(): string | undefined;
251
262
  /**
@@ -257,7 +268,7 @@ export declare class Graphty extends LitElement {
257
268
  * jmespath that describes where to find the destination node identifier for this edge.
258
269
  *
259
270
  * Unset by default, which means PROBE; see {@link edgeSrcIdPath}.
260
- * @returns JMESPath string or undefined if not set
271
+ * @returns The value set on this element, else the value in effect (undefined when that is none)
261
272
  */
262
273
  get edgeDstIdPath(): string | undefined;
263
274
  /**
@@ -279,7 +290,7 @@ export declare class Graphty extends LitElement {
279
290
  * ```html
280
291
  * <graphty-element edge-id-path="edgeId"></graphty-element>
281
292
  * ```
282
- * @returns JMESPath string or undefined if not set
293
+ * @returns The value set on this element, else the value in effect (undefined when that is none)
283
294
  */
284
295
  get edgeIdPath(): string | undefined;
285
296
  /**
@@ -302,7 +313,7 @@ export declare class Graphty extends LitElement {
302
313
  * ```html
303
314
  * <graphty-element repeated-edges="sum"></graphty-element>
304
315
  * ```
305
- * @returns The policy, or undefined when none has been set on this element
316
+ * @returns The value set on this element, else the value in effect (undefined when that is none)
306
317
  */
307
318
  get repeatedEdges(): DuplicatePolicy | undefined;
308
319
  /**
@@ -320,7 +331,7 @@ export declare class Graphty extends LitElement {
320
331
  * ```html
321
332
  * <graphty-element node-label-path="name"></graphty-element>
322
333
  * ```
323
- * @returns JMESPath string or undefined if not set
334
+ * @returns The value set on this element, else the value in effect (undefined when that is none)
324
335
  */
325
336
  get nodeLabelPath(): string | undefined;
326
337
  /**
@@ -338,7 +349,7 @@ export declare class Graphty extends LitElement {
338
349
  * ```html
339
350
  * <graphty-element edge-weight-path="cost"></graphty-element>
340
351
  * ```
341
- * @returns JMESPath string or undefined if not set
352
+ * @returns The value set on this element, else the value in effect (undefined when that is none)
342
353
  */
343
354
  get edgeWeightPath(): string | undefined;
344
355
  /**
@@ -362,7 +373,7 @@ export declare class Graphty extends LitElement {
362
373
  * ```html
363
374
  * <graphty-element position-scale="0.01"></graphty-element>
364
375
  * ```
365
- * @returns The multiplier, or undefined when none has been set on this element
376
+ * @returns The value set on this element, else the value in effect (undefined when that is none)
366
377
  */
367
378
  get positionScale(): number | undefined;
368
379
  /**
@@ -382,7 +393,7 @@ export declare class Graphty extends LitElement {
382
393
  * ```html
383
394
  * <graphty-element directed="true"></graphty-element>
384
395
  * ```
385
- * @returns The setting, or undefined when none has been set on this element
396
+ * @returns The value set on this element, else the value in effect ("auto" by default)
386
397
  */
387
398
  get directed(): boolean | "auto" | undefined;
388
399
  /**
@@ -416,7 +427,9 @@ export declare class Graphty extends LitElement {
416
427
  */
417
428
  get layout(): string | undefined;
418
429
  /**
419
- * Sets the layout algorithm. Triggers layout recalculation with merged config.
430
+ * Sets the layout algorithm: one undoable step, which undo takes back to the layout, the
431
+ * engine and the options before it. Assigned with `layoutConfig` in the same tick, the two are
432
+ * one step.
420
433
  */
421
434
  set layout(value: string | undefined);
422
435
  /**
@@ -426,7 +439,7 @@ export declare class Graphty extends LitElement {
426
439
  */
427
440
  get layoutConfig(): Record<string, unknown> | undefined;
428
441
  /**
429
- * Sets layout-specific configuration. Updates active layout if one is set.
442
+ * Sets layout-specific configuration: the layout is drawn again with it, as one undoable step.
430
443
  */
431
444
  set layoutConfig(value: Record<string, unknown> | undefined);
432
445
  /**
@@ -484,7 +497,8 @@ export declare class Graphty extends LitElement {
484
497
  * element.layoutBehavior = { layout: { preSteps: 1000 } };
485
498
  * element.layoutBehavior = { labels: { declutter: true } };
486
499
  * ```
487
- * @returns The behaviour settings, or undefined when none have been set on this element
500
+ * @returns The view preferences set on this element, with the pacing settings saved in the
501
+ * project (`preSteps`, `stepMultiplier`, `minDelta`) as they are in effect
488
502
  */
489
503
  get layoutBehavior(): GraphBehaviorConfig | undefined;
490
504
  /**
@@ -512,7 +526,7 @@ export declare class Graphty extends LitElement {
512
526
  * ```typescript
513
527
  * element.selectionStyle = { color: "#00BCD4", scale: 1.8 };
514
528
  * ```
515
- * @returns The highlight settings, or undefined when none have been set on this element
529
+ * @returns The value set on this element, else the value in effect (undefined when that is none)
516
530
  */
517
531
  get selectionStyle(): GraphSelectionStyleInput | undefined;
518
532
  /**
@@ -542,7 +556,7 @@ export declare class Graphty extends LitElement {
542
556
  * element.algorithmsOnLoad = ["degree", { algorithm: "pagerank", style: { size: [1, 5] } }];
543
557
  * element.runAlgorithmsOnLoad = true;
544
558
  * ```
545
- * @returns The entries, or undefined when none have been set on this element
559
+ * @returns The value set on this element, else the value in effect (undefined when that is none)
546
560
  */
547
561
  get algorithmsOnLoad(): readonly AlgorithmOnLoad[] | undefined;
548
562
  /**
@@ -571,7 +585,8 @@ export declare class Graphty extends LitElement {
571
585
  */
572
586
  get viewMode(): ViewMode | undefined;
573
587
  /**
574
- * Sets the view mode. Switches camera and rendering mode accordingly.
588
+ * Sets the view mode. Switching between 2D and 3D is one undoable step; entering VR or AR is
589
+ * not a step, and from 2D it switches to 3D first in the same step.
575
590
  */
576
591
  set viewMode(value: ViewMode | undefined);
577
592
  /**
@@ -603,7 +618,7 @@ export declare class Graphty extends LitElement {
603
618
  * ```html
604
619
  * <graphty-element background='{"backgroundType":"color","color":"black"}'></graphty-element>
605
620
  * ```
606
- * @returns The background, or undefined when none has been set on this element
621
+ * @returns The background set on this element, else the one in effect
607
622
  */
608
623
  get background(): GraphBackgroundConfig | undefined;
609
624
  /**
@@ -641,13 +656,27 @@ export declare class Graphty extends LitElement {
641
656
  * A boolean attribute: its presence turns it on, as `hidden` does. It was read as a string,
642
657
  * so `<graphty-element run-algorithms-on-load>` handed the setter "" -- which is false -- and
643
658
  * the documented HTML form ran nothing.
644
- * @returns Boolean flag or undefined if not set
659
+ * @returns The value set on this element, else the value in effect (undefined when that is none)
645
660
  */
646
661
  get runAlgorithmsOnLoad(): boolean | undefined;
647
662
  /**
648
663
  * Sets whether to run algorithms when a style template loads. Updates graph configuration.
649
664
  */
650
665
  set runAlgorithmsOnLoad(value: boolean | undefined);
666
+ /**
667
+ * Whether the element handles the undo keys itself: Ctrl+Z (Cmd+Z on macOS) undoes one step
668
+ * and Ctrl+Shift+Z or Ctrl+Y redoes it, while the graph's canvas has keyboard focus. On by
669
+ * default. A handled key has its default prevented, so a host page binding the same keys
670
+ * skips a keydown whose `defaultPrevented` is set; or turns this off with
671
+ * `history-keys="false"` and calls `session.undo()` itself.
672
+ * @returns Whether the undo keys are handled.
673
+ * @since 3.0.0
674
+ */
675
+ get historyKeys(): boolean;
676
+ /**
677
+ * Turns the element's own undo keys on or off.
678
+ */
679
+ set historyKeys(value: boolean);
651
680
  /**
652
681
  * Enable detailed performance profiling.
653
682
  * When enabled, hierarchical timing and advanced statistics will be collected.
@@ -955,11 +984,46 @@ export declare class Graphty extends LitElement {
955
984
  */
956
985
  resetCamera(options?: import("./screenshot/types.js").CameraAnimationOptions): Promise<void>;
957
986
  /**
958
- * Save current camera state as a named preset.
959
- * Available from Phase 5 onwards.
987
+ * Move the camera one step nearer or further, the way a Zoom in or Zoom out button does.
988
+ * One step is a factor of 1.25 on the 3D camera's distance or the 2D camera's zoom. Not an
989
+ * undoable step: the camera is view state.
990
+ * @param direction - `"in"` to approach, `"out"` to withdraw.
991
+ * @param options - Animation options
992
+ * @returns Promise that resolves when the camera has moved
993
+ * @since 3.0.0
994
+ * @example
995
+ * ```typescript
996
+ * await element.zoomStep("out");
997
+ * ```
998
+ */
999
+ zoomStep(direction: "in" | "out", options?: import("./screenshot/types.js").CameraAnimationOptions): Promise<void>;
1000
+ /**
1001
+ * Centre the camera on the selected nodes, keeping where it stands. With nothing selected
1002
+ * the camera does not move. Not an undoable step: the camera is view state.
1003
+ * @param options - Animation options
1004
+ * @returns Promise that resolves when the camera has moved
1005
+ * @since 3.0.0
1006
+ * @example
1007
+ * ```typescript
1008
+ * await element.session.selection.apply({ nodes: ["n1"] });
1009
+ * await element.zoomToSelection();
1010
+ * ```
1011
+ */
1012
+ zoomToSelection(options?: import("./screenshot/types.js").CameraAnimationOptions): Promise<void>;
1013
+ /**
1014
+ * Save the current camera state as a named preset. One undoable step.
960
1015
  * @param name - Name for the preset
1016
+ * @param camera - The camera state to save instead of where the camera is now
1017
+ * @throws A `GraphtyError` with `E_PROTECTED` when a camera view already answers to the name.
1018
+ */
1019
+ saveCameraPreset(name: string, camera?: import("./screenshot/types.js").CameraState): void;
1020
+ /**
1021
+ * Forget a preset saved with `saveCameraPreset` or `importCameraPresets`. One undoable step.
1022
+ * @param name - The name it was saved under
1023
+ * @returns Settles once the step is recorded; rejects with `E_BAD_COMMAND` when nothing is
1024
+ * saved under the name
961
1025
  */
962
- saveCameraPreset(name: string): void;
1026
+ removeCameraPreset(name: string): Promise<void>;
963
1027
  /**
964
1028
  * Load a camera preset (built-in or user-defined).
965
1029
  * Available from Phase 5 onwards.
@@ -983,8 +1047,7 @@ export declare class Graphty extends LitElement {
983
1047
  */
984
1048
  exportCameraPresets(): Record<string, import("./screenshot/types.js").CameraState>;
985
1049
  /**
986
- * Import user-defined presets from JSON
987
- * Available from Phase 5 onwards
1050
+ * Import user-defined presets from JSON, as one undoable step
988
1051
  * @param presets - Record of preset names to their state
989
1052
  */
990
1053
  importCameraPresets(presets: Record<string, import("./screenshot/types.js").CameraState>): void;
@@ -1054,7 +1117,7 @@ export declare class Graphty extends LitElement {
1054
1117
  */
1055
1118
  addEdges(edges: import("./config").AdHocData[], options?: import("./managers").AddEdgesOptions & import("./utils/queue-migration").QueueableOptions): Promise<void>;
1056
1119
  /**
1057
- * Remove nodes from the graph.
1120
+ * Remove nodes from the graph, and every edge attached to one, as one undoable step.
1058
1121
  * @param nodeIds - Array of node IDs to remove
1059
1122
  * @param options - Queue options for operation ordering
1060
1123
  * @returns Promise that resolves when nodes are removed
@@ -1066,7 +1129,18 @@ export declare class Graphty extends LitElement {
1066
1129
  */
1067
1130
  removeNodes(nodeIds: (string | number)[], options?: import("./utils/queue-migration").QueueableOptions): Promise<void>;
1068
1131
  /**
1069
- * Update node data.
1132
+ * Remove edges from the graph, as one undoable step.
1133
+ * @param edgeIds - The element-assigned edge ids
1134
+ * @param options - Queue options for operation ordering
1135
+ * @returns Promise that resolves when the edges are removed
1136
+ * @example
1137
+ * ```typescript
1138
+ * await element.removeEdges(['0', '3']);
1139
+ * ```
1140
+ */
1141
+ removeEdges(edgeIds: string[], options?: import("./utils/queue-migration").QueueableOptions): Promise<void>;
1142
+ /**
1143
+ * Update node data, as one undoable step.
1070
1144
  * @param updates - Array of update objects with id and properties to update
1071
1145
  * @param options - Queue options for operation ordering
1072
1146
  * @returns Promise that resolves when nodes are updated
@@ -1082,6 +1156,21 @@ export declare class Graphty extends LitElement {
1082
1156
  id: string | number;
1083
1157
  [key: string]: unknown;
1084
1158
  }[], options?: import("./utils/queue-migration").QueueableOptions): Promise<void>;
1159
+ /**
1160
+ * Update edge data, as one undoable step. Keys not named are kept; an id the graph does not
1161
+ * hold is skipped.
1162
+ * @param updates - The edge id and the new values of each edge
1163
+ * @param options - Queue options for operation ordering
1164
+ * @returns Promise that resolves when the edges are updated
1165
+ * @example
1166
+ * ```typescript
1167
+ * await element.updateEdges([{ id: "0", label: "knows" }]);
1168
+ * ```
1169
+ */
1170
+ updateEdges(updates: {
1171
+ id: string;
1172
+ [key: string]: unknown;
1173
+ }[], options?: import("./utils/queue-migration").QueueableOptions): Promise<void>;
1085
1174
  /**
1086
1175
  * Add data from a data source.
1087
1176
  *
@@ -1453,20 +1542,26 @@ export declare class Graphty extends LitElement {
1453
1542
  */
1454
1543
  get isFrameStable(): boolean;
1455
1544
  /**
1456
- * Execute multiple operations as a batch.
1457
- * @param fn - Function containing batch operations
1458
- * @returns Promise that resolves when batch completes
1545
+ * Make several changes one undoable step.
1546
+ *
1547
+ * `fn` receives `tx`, the session as seen from inside the step: what it does through `tx` is
1548
+ * recorded as one step once `fn` settles, and a throw rolls all of it back. A call on the
1549
+ * element itself while `fn` runs is a step of its own, and logs a warning naming the `tx`
1550
+ * verb to use instead. The same as `session.transaction`, with a default label.
1551
+ * @param fn - The changes, made through `tx`.
1552
+ * @param label - The step's label in the history.
1553
+ * @returns Once the step is recorded and drawn.
1459
1554
  * @since 1.5.0
1460
1555
  * @example
1461
1556
  * ```typescript
1462
- * await element.batchOperations(async () => {
1463
- * await element.addNodes(nodes);
1464
- * await element.addEdges(edges);
1465
- * await element.setLayout('circular');
1557
+ * await element.batchOperations(async (tx) => {
1558
+ * await tx.data.addNodes(nodes);
1559
+ * await tx.data.addEdges(edges);
1560
+ * await tx.layout.set("circular");
1466
1561
  * });
1467
1562
  * ```
1468
1563
  */
1469
- batchOperations(fn: () => Promise<void> | void): Promise<void>;
1564
+ batchOperations(fn: (tx: TransactionScope) => Promise<void> | void, label?: string): Promise<void>;
1470
1565
  /**
1471
1566
  * Subscribe to graph events.
1472
1567
  * @param type - Event type to listen for
@@ -37,4 +37,6 @@ export interface KeyboardInfo {
37
37
  shiftKey: boolean;
38
38
  altKey: boolean;
39
39
  metaKey: boolean;
40
+ /** Cancels the DOM event's default action, so a host listening further out can skip it. */
41
+ preventDefault?: () => void;
40
42
  }
@@ -109,7 +109,14 @@ export declare class D3GraphEngine extends LayoutEngine {
109
109
  * @param n - The node to set position for
110
110
  * @param newPos - The new position coordinates
111
111
  */
112
- setNodePosition(n: Node, newPos: Position): void;
112
+ protected setNodePosition(n: Node, newPos: Position): void;
113
+ /**
114
+ * Take the position array as this engine's own. Nodes still waiting for the next refresh are
115
+ * taken into the simulation first: undo and rollback rebuild the nodes they bring back, and a
116
+ * node left waiting would be placed by d3's own initial layout at its first tick -- over the
117
+ * coordinates the restore wrote for it.
118
+ */
119
+ loadArrangement(): void;
113
120
  /**
114
121
  * Get the position of an edge based on its endpoint positions
115
122
  * @param e - The edge to get position for
@@ -120,12 +127,12 @@ export declare class D3GraphEngine extends LayoutEngine {
120
127
  * Pin a node to its current position
121
128
  * @param n - The node to pin
122
129
  */
123
- pin(n: Node): void;
130
+ protected pin(n: Node): void;
124
131
  /**
125
132
  * Unpin a node to allow it to move freely
126
133
  * @param n - The node to unpin
127
134
  */
128
- unpin(n: Node): void;
135
+ protected unpin(n: Node): void;
129
136
  /**
130
137
  * Holds the nodes a scoped layout may not move, as d3 fixes a node: at its current position.
131
138
  *
@@ -161,6 +168,13 @@ export declare class D3GraphEngine extends LayoutEngine {
161
168
  * @param e - the edge leaving the graph
162
169
  */
163
170
  removeEdge(e: Edge): void;
171
+ /**
172
+ * Strict state: {@link LayoutEngine.edgeProblems} over the links and the edges still waiting
173
+ * for the next refresh, each once, with both endpoints held.
174
+ * @param drawn - The edges the element draws.
175
+ * @returns One sentence per problem.
176
+ */
177
+ protected edgeProblems(drawn: ReadonlyMap<string, Edge>): string[];
164
178
  private _getMappedNode;
165
179
  private _getMappedEdge;
166
180
  }
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod/v4";
2
2
  import { type OptionsSchema } from "../config";
3
+ import type { Node } from "../Node";
3
4
  import { SimpleLayoutEngine } from "./LayoutEngine";
4
5
  declare const FixedLayoutConfig: z.ZodObject<{
5
6
  dim: z.ZodDefault<z.ZodNumber>;
@@ -8,9 +9,17 @@ declare const FixedLayoutConfig: z.ZodObject<{
8
9
  type FixedLayoutConfigType = z.infer<typeof FixedLayoutConfig>;
9
10
  type FixedLayoutOpts = Partial<FixedLayoutConfigType>;
10
11
  /**
11
- * Fixed layout engine that doesn't move nodes - uses positions from node data
12
+ * The fixed layout: every node goes to its `data.position`, and then stays where it is put.
13
+ *
14
+ * The first time an engine lays out, every node carrying a `data.position` is placed there (scaled
15
+ * by `data.knownFields.positionScale`), whatever an earlier layout left in the element's position
16
+ * array -- switching to "fixed" means "put the nodes where the data says". After that the engine
17
+ * keeps what the array holds, so a drag survives a later recompute; a node added later reaches the
18
+ * array from its own `data.position` when the graph is frozen. A node with no coordinates at all
19
+ * is placed at the origin.
12
20
  */
13
21
  export declare class FixedLayout extends SimpleLayoutEngine {
22
+ #private;
14
23
  static type: string;
15
24
  static maxDimensions: number;
16
25
  static zodOptionsSchema: OptionsSchema;
@@ -22,12 +31,19 @@ export declare class FixedLayout extends SimpleLayoutEngine {
22
31
  */
23
32
  constructor(opts?: FixedLayoutOpts);
24
33
  /**
25
- * Add a node and apply its fixed position immediately
34
+ * Add a node, and put its mesh at its `data.position` straight away.
35
+ *
36
+ * The array is not touched here: the node's row is seeded from the same `data.position` when
37
+ * the graph is next frozen, which is before this engine next reads it. This only spares the
38
+ * node the frames between its arrival and that read, which it would otherwise spend wherever a
39
+ * new mesh starts -- and a caller that reads a node's mesh position as soon as the add has
40
+ * finished, as the element's own tests do, gets the node's place rather than that.
26
41
  * @param n - The node to add
27
42
  */
28
- addNode(n: import("../Node.js").Node): void;
43
+ addNode(n: Node): void;
29
44
  /**
30
- * Read positions from node data and apply them directly
45
+ * Place every node at its data position on the first run; later, keep every placed row. An
46
+ * unplaced row goes to the origin.
31
47
  */
32
48
  doLayout(): void;
33
49
  }