@dxos/react-ui-graph 0.8.4-main.f5c0578 → 0.8.4-main.fcfe5033a5

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 (82) hide show
  1. package/README.md +5 -7
  2. package/dist/lib/browser/chunk-LKC455GK.mjs +52 -0
  3. package/dist/lib/browser/chunk-LKC455GK.mjs.map +7 -0
  4. package/dist/lib/browser/index.mjs +1089 -240
  5. package/dist/lib/browser/index.mjs.map +4 -4
  6. package/dist/lib/browser/meta.json +1 -1
  7. package/dist/lib/browser/testing/index.mjs +16 -16
  8. package/dist/lib/browser/testing/index.mjs.map +3 -3
  9. package/dist/lib/node-esm/chunk-JE4KZCUF.mjs +54 -0
  10. package/dist/lib/node-esm/chunk-JE4KZCUF.mjs.map +7 -0
  11. package/dist/lib/node-esm/index.mjs +1089 -240
  12. package/dist/lib/node-esm/index.mjs.map +4 -4
  13. package/dist/lib/node-esm/meta.json +1 -1
  14. package/dist/lib/node-esm/testing/index.mjs +16 -16
  15. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  16. package/dist/types/src/components/Graph/Graph.d.ts +4 -5
  17. package/dist/types/src/components/Graph/Graph.d.ts.map +1 -1
  18. package/dist/types/src/components/Graph/Graph.stories.d.ts +17 -8
  19. package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
  20. package/dist/types/src/components/Mesh/Mesh.stories.d.ts +9 -5
  21. package/dist/types/src/components/Mesh/Mesh.stories.d.ts.map +1 -1
  22. package/dist/types/src/components/SVG/Root.d.ts +4 -4
  23. package/dist/types/src/components/SVG/Root.d.ts.map +1 -1
  24. package/dist/types/src/components/SVG/SVG.d.ts +14 -17
  25. package/dist/types/src/components/SVG/SVG.d.ts.map +1 -1
  26. package/dist/types/src/components/SVG/Svg.stories.d.ts +11 -9
  27. package/dist/types/src/components/SVG/Svg.stories.d.ts.map +1 -1
  28. package/dist/types/src/fx/fx.stories.d.ts +16 -15
  29. package/dist/types/src/fx/fx.stories.d.ts.map +1 -1
  30. package/dist/types/src/graph/projector/graph-drag.d.ts.map +1 -1
  31. package/dist/types/src/graph/projector/graph-force-projector.d.ts +1 -1
  32. package/dist/types/src/graph/projector/graph-force-projector.d.ts.map +1 -1
  33. package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts +1 -1
  34. package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts.map +1 -1
  35. package/dist/types/src/graph/projector/graph-projector.d.ts +2 -2
  36. package/dist/types/src/graph/projector/graph-projector.d.ts.map +1 -1
  37. package/dist/types/src/graph/projector/graph-radial-projector.d.ts +1 -1
  38. package/dist/types/src/graph/projector/graph-radial-projector.d.ts.map +1 -1
  39. package/dist/types/src/graph/projector/graph-relational-projector.d.ts +1 -1
  40. package/dist/types/src/graph/projector/graph-relational-projector.d.ts.map +1 -1
  41. package/dist/types/src/graph/renderer/graph-renderer.d.ts.map +1 -1
  42. package/dist/types/src/graph/types.d.ts +1 -1
  43. package/dist/types/src/graph/types.d.ts.map +1 -1
  44. package/dist/types/src/stories/hooks.stories.d.ts +14 -9
  45. package/dist/types/src/stories/hooks.stories.d.ts.map +1 -1
  46. package/dist/types/src/testing/data.d.ts +4 -4
  47. package/dist/types/src/testing/data.d.ts.map +1 -1
  48. package/dist/types/src/testing/hooks.d.ts +2 -16
  49. package/dist/types/src/testing/hooks.d.ts.map +1 -1
  50. package/dist/types/src/testing/model.d.ts +4 -8
  51. package/dist/types/src/testing/model.d.ts.map +1 -1
  52. package/dist/types/src/util/fraction.d.ts +1 -1
  53. package/dist/types/tsconfig.tsbuildinfo +1 -1
  54. package/package.json +31 -26
  55. package/src/components/Graph/Graph.stories.tsx +61 -56
  56. package/src/components/Graph/Graph.tsx +24 -16
  57. package/src/components/Mesh/Mesh.stories.tsx +9 -9
  58. package/src/components/SVG/Grid.tsx +1 -1
  59. package/src/components/SVG/Markers.tsx +1 -1
  60. package/src/components/SVG/Root.tsx +14 -7
  61. package/src/components/SVG/SVG.tsx +10 -2
  62. package/src/components/SVG/Svg.stories.tsx +22 -19
  63. package/src/fx/fx.stories.tsx +17 -15
  64. package/src/graph/projector/graph-drag.ts +0 -1
  65. package/src/graph/projector/graph-force-projector.ts +1 -2
  66. package/src/graph/projector/graph-hierarchical-projector.ts +3 -4
  67. package/src/graph/projector/graph-projector.ts +2 -3
  68. package/src/graph/projector/graph-radial-projector.ts +1 -2
  69. package/src/graph/projector/graph-relational-projector.ts +3 -4
  70. package/src/graph/renderer/graph-renderer.ts +0 -1
  71. package/src/graph/types.ts +1 -1
  72. package/src/hooks/useStateRef.ts +1 -1
  73. package/src/stories/hooks.stories.tsx +38 -31
  74. package/src/testing/data.ts +14 -14
  75. package/src/testing/hooks.ts +3 -4
  76. package/src/testing/model.ts +6 -6
  77. package/src/util/fraction.ts +1 -1
  78. package/styles/graph.css +292 -43
  79. package/dist/lib/browser/chunk-HLAKLUDC.mjs +0 -958
  80. package/dist/lib/browser/chunk-HLAKLUDC.mjs.map +0 -7
  81. package/dist/lib/node-esm/chunk-O6GWCXDC.mjs +0 -960
  82. package/dist/lib/node-esm/chunk-O6GWCXDC.mjs.map +0 -7
@@ -1,31 +1,14 @@
1
1
  import {
2
- EventEmitter,
3
- FractionUtil,
4
- GridController,
5
- SVGContext,
6
- SVGContextProvider,
7
- Scale,
8
- Screen,
9
- Vector,
10
- ZoomHandler,
11
- getCircumferencePoints,
12
- normal,
13
- offsetPoints,
14
2
  useDynamicRef,
15
- useGrid,
16
3
  useStateRef,
17
- useSvgContext,
18
- useTimestamp,
19
- useZoom
20
- } from "./chunk-HLAKLUDC.mjs";
4
+ useTimestamp
5
+ } from "./chunk-LKC455GK.mjs";
21
6
 
22
7
  // src/components/Graph/Graph.tsx
23
- import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
24
- import { effect } from "@preact/signals-core";
25
- import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from "react";
8
+ import React, { forwardRef, useEffect as useEffect3, useImperativeHandle, useMemo as useMemo3, useRef as useRef3 } from "react";
26
9
  import { combine } from "@dxos/async";
27
10
  import { log as log6 } from "@dxos/log";
28
- import { mx } from "@dxos/react-ui-theme";
11
+ import { mx } from "@dxos/ui-theme";
29
12
 
30
13
  // src/graph/markers.ts
31
14
  import { line, select } from "d3";
@@ -178,14 +161,585 @@ var emptyGraph = {
178
161
  edges: []
179
162
  };
180
163
 
164
+ // src/util/events.ts
165
+ var EventEmitter = class {
166
+ _listeners = /* @__PURE__ */ new Set();
167
+ clear() {
168
+ this._listeners.clear();
169
+ }
170
+ on(onEvent) {
171
+ this._listeners.add(onEvent);
172
+ return () => this._listeners.delete(onEvent);
173
+ }
174
+ emit(value) {
175
+ this._listeners.forEach((listener) => listener(value));
176
+ }
177
+ };
178
+
179
+ // src/util/fraction.ts
180
+ import { invariant as invariant2 } from "@dxos/invariant";
181
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/util/fraction.ts";
182
+ var FractionUtil = class _FractionUtil {
183
+ /**
184
+ * Convert number to fraction.
185
+ * @param n
186
+ */
187
+ static toFraction = (n) => {
188
+ return typeof n === "number" ? [
189
+ n,
190
+ 1
191
+ ] : n;
192
+ };
193
+ static validate = (...fraction) => {
194
+ fraction.forEach(([n, d]) => {
195
+ if (!Number.isFinite(n) || !Number.isFinite(d) || d === 0) {
196
+ throw new Error(`Invalid fraction: ${n}/${d}`);
197
+ }
198
+ });
199
+ return fraction;
200
+ };
201
+ /**
202
+ * @param {Fraction}
203
+ * Convert to rounded-sm number.
204
+ */
205
+ static toNumber = ([n, d]) => {
206
+ _FractionUtil.validate([
207
+ n,
208
+ d
209
+ ]);
210
+ return n / d;
211
+ };
212
+ /**
213
+ * Round the number to the nearest fraction.
214
+ * Example: 3/5 => 1/1; 3/5 (precision 2) => 1/2.
215
+ * @param {Fraction}
216
+ * @param p Precision (e.g., 1/2, 1/4, etc.)
217
+ */
218
+ static round = ([n, d], p = 1) => {
219
+ _FractionUtil.validate([
220
+ n,
221
+ d
222
+ ]);
223
+ const v = Math.round(_FractionUtil.toNumber(_FractionUtil.divide([
224
+ n,
225
+ d
226
+ ], [
227
+ 1,
228
+ p
229
+ ])));
230
+ return _FractionUtil.simplify([
231
+ v,
232
+ p
233
+ ]);
234
+ };
235
+ //
236
+ // Boolean.
237
+ //
238
+ /**
239
+ * Tests if equals.
240
+ * @param n1
241
+ * @param n2
242
+ */
243
+ static equals = (n1, n2) => {
244
+ return n1[0] * n2[1] === n1[1] * n2[0];
245
+ };
246
+ /**
247
+ * @param {Fraction}
248
+ * True if zero.
249
+ */
250
+ static isZero = ([n]) => {
251
+ return n === 0;
252
+ };
253
+ //
254
+ // Normalization.
255
+ //
256
+ /**
257
+ * Simplify fraction finding LCDs.
258
+ * @param n
259
+ * @param d
260
+ */
261
+ static simplify = ([n, d]) => {
262
+ _FractionUtil.validate([
263
+ n,
264
+ d
265
+ ]);
266
+ if (d < 1) {
267
+ const t = n / d;
268
+ if (Math.floor(t) === t) {
269
+ n = t;
270
+ d = 1;
271
+ }
272
+ }
273
+ const fn = _FractionUtil.factors(n).reverse();
274
+ const fd = _FractionUtil.factors(d).reverse();
275
+ let c;
276
+ for (let i = 0; i < fn.length; i++) {
277
+ c = fd.find((n2) => n2 === fn[i]);
278
+ if (c) {
279
+ return [
280
+ n / c,
281
+ d / c
282
+ ];
283
+ }
284
+ }
285
+ return [
286
+ n,
287
+ d
288
+ ];
289
+ };
290
+ /**
291
+ * Return common factors.
292
+ * @param n
293
+ */
294
+ static factors = (n) => {
295
+ invariant2(Number.isFinite(n), `Invalid number: ${n}`, {
296
+ F: __dxlog_file2,
297
+ L: 113,
298
+ S: this,
299
+ A: [
300
+ "Number.isFinite(n)",
301
+ "`Invalid number: ${n}`"
302
+ ]
303
+ });
304
+ const factors = [
305
+ 1
306
+ ];
307
+ if (Number.isSafeInteger(n)) {
308
+ let f = 1;
309
+ do {
310
+ if (n % ++f === 0) {
311
+ factors.push(f);
312
+ }
313
+ } while (n / f > 1 && f < 100);
314
+ }
315
+ return factors;
316
+ };
317
+ //
318
+ // Basic arithmetic.
319
+ //
320
+ /**
321
+ * @param n1
322
+ * @param n2
323
+ */
324
+ static add = (n1, n2) => {
325
+ _FractionUtil.validate(n1, n2);
326
+ const d = n1[1] * n2[1];
327
+ const n = n1[0] * n2[1] + n2[0] * n1[1];
328
+ return _FractionUtil.simplify([
329
+ n,
330
+ d
331
+ ]);
332
+ };
333
+ /**
334
+ * @param n1
335
+ * @param n2
336
+ */
337
+ static subtract = (n1, n2) => {
338
+ _FractionUtil.validate(n1, n2);
339
+ const d = n1[1] * n2[1];
340
+ const n = n1[0] * n2[1] - n2[0] * n1[1];
341
+ return _FractionUtil.simplify([
342
+ n,
343
+ d
344
+ ]);
345
+ };
346
+ /**
347
+ * @param n1
348
+ * @param n2
349
+ */
350
+ static multiply = (n1, n2) => {
351
+ _FractionUtil.validate(n1, n2);
352
+ const n = n1[0] * n2[0];
353
+ const d = n1[1] * n2[1];
354
+ return _FractionUtil.simplify([
355
+ n,
356
+ d
357
+ ]);
358
+ };
359
+ /**
360
+ * @param n1
361
+ * @param n2
362
+ */
363
+ static divide = (n1, n2) => {
364
+ _FractionUtil.validate(n1, n2);
365
+ const n = n1[0] * n2[1];
366
+ const d = n1[1] * n2[0];
367
+ return _FractionUtil.simplify([
368
+ n,
369
+ d
370
+ ]);
371
+ };
372
+ };
373
+
374
+ // src/util/points.ts
375
+ var getCircumferencePoints = (p1, p2, r1 = 0, r2 = 0) => {
376
+ const [x1, y1] = p1;
377
+ const [x2, y2] = p2;
378
+ const theta = Math.atan2(x2 - x1, y2 - y1);
379
+ return [
380
+ [
381
+ // p1
382
+ x1 + (r1 === 0 ? 0 : r1 * Math.sin(theta)),
383
+ y1 + (r1 === 0 ? 0 : r1 * Math.cos(theta))
384
+ ],
385
+ [
386
+ // p2
387
+ x2 - (r2 === 0 ? 0 : r2 * Math.cos(Math.PI / 2 - theta)),
388
+ y2 - (r2 === 0 ? 0 : r2 * Math.sin(Math.PI / 2 - theta))
389
+ ]
390
+ ];
391
+ };
392
+ var normal = (p1, p2) => {
393
+ const dx = p2[0] - p1[0];
394
+ const dy = p2[1] - p1[1];
395
+ const len = Math.hypot(dx, dy);
396
+ return [
397
+ dy / len,
398
+ -dx / len
399
+ ];
400
+ };
401
+ var offsetPoints = (points, distance, closed) => {
402
+ const len = points.length;
403
+ const out = [];
404
+ for (let i = 0; i < len; i++) {
405
+ const p0 = points[(i - 1 + len) % len];
406
+ const p1 = points[i];
407
+ const p2 = points[(i + 1) % len];
408
+ const n1 = normal(p0, p1);
409
+ const n2 = normal(p1, p2);
410
+ const nx = (n1[0] + n2[0]) / 2;
411
+ const ny = (n1[1] + n2[1]) / 2;
412
+ const norm = Math.hypot(nx, ny) || 1;
413
+ out.push([
414
+ p1[0] + distance * nx / norm,
415
+ p1[1] + distance * ny / norm
416
+ ]);
417
+ if (!closed && (i === 0 || i === len - 1)) {
418
+ out[i] = [
419
+ p1[0] + distance * normal(p0, p1)[0],
420
+ p1[1] + distance * normal(p0, p1)[1]
421
+ ];
422
+ }
423
+ }
424
+ return out;
425
+ };
426
+
427
+ // src/util/scale.ts
428
+ import { zoomIdentity } from "d3";
429
+ var Scale = class {
430
+ _gridSize;
431
+ _transform;
432
+ constructor(_gridSize = 32) {
433
+ this._gridSize = _gridSize;
434
+ }
435
+ get gridSize() {
436
+ return this._gridSize;
437
+ }
438
+ get transform() {
439
+ return this._transform || zoomIdentity;
440
+ }
441
+ setTransform(transform) {
442
+ if (this._transform?.x === transform.x && this._transform?.y === transform.y && this._transform?.k === transform.k) {
443
+ return false;
444
+ }
445
+ this._transform = transform;
446
+ return true;
447
+ }
448
+ /**
449
+ * Translate a screen point to a logical point.
450
+ * @param point
451
+ */
452
+ translate(point) {
453
+ const { x, y, k } = this._transform ?? {
454
+ x: 0,
455
+ y: 0,
456
+ k: 1
457
+ };
458
+ return [
459
+ (point[0] - x) / k,
460
+ (point[1] - y) / k
461
+ ];
462
+ }
463
+ /**
464
+ * Map model to screen.
465
+ * Model points are represented by fractions (to preserve precision) and use normal cartesian coordinates.
466
+ */
467
+ model = {
468
+ // TODO(burdon): Precision depends on scale.
469
+ snapValues: (array) => array.map((n) => FractionUtil.round(n)),
470
+ snapVertex: ({ x, y }) => {
471
+ const [sx, sy] = this.model.snapValues([
472
+ x,
473
+ y
474
+ ]);
475
+ return {
476
+ x: sx,
477
+ y: sy
478
+ };
479
+ },
480
+ snapBounds: ({ x, y, width, height }) => {
481
+ [x, y, width, height] = this.model.snapValues([
482
+ x,
483
+ y,
484
+ width,
485
+ height
486
+ ]);
487
+ return {
488
+ x,
489
+ y,
490
+ width,
491
+ height
492
+ };
493
+ },
494
+ toValue: (value) => {
495
+ return Math.round(FractionUtil.toNumber(value) * this._gridSize);
496
+ },
497
+ toValues: (values) => {
498
+ return values.map((value) => Math.round(FractionUtil.toNumber(value) * this._gridSize));
499
+ },
500
+ toPoint: (point) => {
501
+ const [x, y] = this.model.toValues([
502
+ point.x,
503
+ point.y
504
+ ]);
505
+ return [
506
+ x,
507
+ y === 0 ? 0 : -y
508
+ ];
509
+ },
510
+ toBounds: ({ x, y, width, height }) => {
511
+ const point = this.model.toPoint({
512
+ x,
513
+ y
514
+ });
515
+ const [width2, height2] = this.model.toValues([
516
+ width,
517
+ height
518
+ ]);
519
+ return {
520
+ x: point[0],
521
+ y: point[1] - height2,
522
+ width: width2,
523
+ height: height2
524
+ };
525
+ }
526
+ };
527
+ /**
528
+ * Map screen to model.
529
+ * Screen points are represented by floating numbers and use translated SVG coordinates (with the y-axis inverted).
530
+ */
531
+ screen = {
532
+ snapValues: (array) => array.map((n) => Math.round(n / this._gridSize) * this._gridSize),
533
+ snapPoint: ([x, y]) => [
534
+ x,
535
+ y
536
+ ].map((n) => Math.round(n / this._gridSize) * this._gridSize),
537
+ snapBounds: ({ x, y, width, height }) => {
538
+ [x, y, width, height] = this.screen.snapValues([
539
+ x,
540
+ y,
541
+ width,
542
+ height
543
+ ]);
544
+ return {
545
+ x,
546
+ y,
547
+ width,
548
+ height
549
+ };
550
+ },
551
+ toValue: (value) => {
552
+ return FractionUtil.divide(FractionUtil.toFraction(value), [
553
+ this._gridSize,
554
+ 1
555
+ ]);
556
+ },
557
+ toValues: (values) => {
558
+ return values.map((value) => FractionUtil.divide(FractionUtil.toFraction(value), [
559
+ this._gridSize,
560
+ 1
561
+ ]));
562
+ },
563
+ toVertex: (point) => {
564
+ const [x, y] = point;
565
+ return {
566
+ x: FractionUtil.toFraction(x / this._gridSize),
567
+ y: FractionUtil.toFraction(-y / this._gridSize)
568
+ };
569
+ },
570
+ toBounds: (bounds) => {
571
+ const { x, y } = this.screen.toVertex([
572
+ bounds.x,
573
+ bounds.y
574
+ ]);
575
+ const [width, height] = this.screen.toValues([
576
+ bounds.width,
577
+ bounds.height
578
+ ]);
579
+ return {
580
+ x,
581
+ y: FractionUtil.subtract(y, height),
582
+ width,
583
+ height
584
+ };
585
+ }
586
+ };
587
+ };
588
+
589
+ // src/util/screen.ts
590
+ var Screen = class {
591
+ static createBounds = ([x1, y1], [x2, y2], mod = {}) => {
592
+ const { constrain, center } = mod;
593
+ const x = Math.min(x1, x2);
594
+ const y = Math.min(y1, y2);
595
+ let width = Math.abs(x2 - x1);
596
+ let height = Math.abs(y2 - y1);
597
+ if (constrain) {
598
+ width = height = Math.max(width, height);
599
+ }
600
+ if (center) {
601
+ return {
602
+ x: x - width,
603
+ y: y - height,
604
+ width: width * 2,
605
+ height: height * 2
606
+ };
607
+ } else {
608
+ return {
609
+ x,
610
+ y,
611
+ width,
612
+ height
613
+ };
614
+ }
615
+ };
616
+ static center = ({ x, y, width, height }) => {
617
+ return [
618
+ x + width / 2,
619
+ y + height / 2
620
+ ];
621
+ };
622
+ static contains = (bounds, point) => {
623
+ const [x, y] = point;
624
+ if (x < bounds.x || y < bounds.y) {
625
+ return false;
626
+ }
627
+ if (x > bounds.x + bounds.width || y > bounds.y + bounds.height) {
628
+ return false;
629
+ }
630
+ return true;
631
+ };
632
+ /**
633
+ * Distance between two points.
634
+ * @param p1
635
+ * @param p2
636
+ */
637
+ static len = (p1, p2) => {
638
+ return Math.sqrt(Math.pow(Math.abs(p1[0] - p2[0]), 2) + Math.pow(Math.abs(p1[1] - p2[1]), 2));
639
+ };
640
+ /**
641
+ * Distance to line segment.
642
+ * https://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment#1501725
643
+ * @param v1
644
+ * @param v2
645
+ * @param p
646
+ */
647
+ static normal = (v1, v2, p) => {
648
+ const d2 = (p1, p2) => Math.pow(Math.abs(p1[0] - p2[0]), 2) + Math.pow(Math.abs(p1[1] - p2[1]), 2);
649
+ let d;
650
+ const len2 = d2(v1, v2);
651
+ if (len2 === 0) {
652
+ d = d2(p, v1);
653
+ } else {
654
+ let t = ((p[0] - v1[0]) * (v2[0] - v1[0]) + (p[1] - v1[1]) * (v2[1] - v1[1])) / len2;
655
+ t = Math.max(0, Math.min(1, t));
656
+ d = d2(p, [
657
+ v1[0] + t * (v2[0] - v1[0]),
658
+ v1[1] + t * (v2[1] - v1[1])
659
+ ]);
660
+ }
661
+ return Math.sqrt(d);
662
+ };
663
+ };
664
+
665
+ // src/util/vector.ts
666
+ var Vector = class {
667
+ /**
668
+ * Convert to Vertex.
669
+ * @param x
670
+ * @param y
671
+ */
672
+ static toVertex = ({ x, y }) => ({
673
+ x: FractionUtil.toFraction(x),
674
+ y: FractionUtil.toFraction(y)
675
+ });
676
+ /**
677
+ * Convert to Bounds.
678
+ * @param bounds
679
+ */
680
+ static toBounds = ({ x, y, width, height }) => ({
681
+ x: FractionUtil.toFraction(x),
682
+ y: FractionUtil.toFraction(y),
683
+ width: FractionUtil.toFraction(width),
684
+ height: FractionUtil.toFraction(height)
685
+ });
686
+ /**
687
+ * Calculate center point.
688
+ * @param bounds
689
+ */
690
+ static center = ({ x, y, width, height }) => {
691
+ const cx = FractionUtil.add(x, FractionUtil.multiply(width, [
692
+ 1,
693
+ 2
694
+ ]));
695
+ const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
696
+ 1,
697
+ 2
698
+ ]));
699
+ return {
700
+ x: cx,
701
+ y: cy
702
+ };
703
+ };
704
+ /**
705
+ * Calculate centered left edge.
706
+ * @param bounds
707
+ */
708
+ static left = ({ x, y, height }) => {
709
+ const cx = x;
710
+ const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
711
+ 1,
712
+ 2
713
+ ]));
714
+ return {
715
+ x: cx,
716
+ y: cy
717
+ };
718
+ };
719
+ /**
720
+ * Calculate centered right edge.
721
+ * @param bounds
722
+ */
723
+ static right = ({ x, y, width, height }) => {
724
+ const cx = FractionUtil.add(x, width);
725
+ const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
726
+ 1,
727
+ 2
728
+ ]));
729
+ return {
730
+ x: cx,
731
+ y: cy
732
+ };
733
+ };
734
+ };
735
+
181
736
  // src/graph/projector/projector.ts
182
737
  var Projector = class {
183
738
  _context;
184
- updated;
739
+ updated = new EventEmitter();
185
740
  _options;
186
741
  constructor(_context, options) {
187
742
  this._context = _context;
188
- this.updated = new EventEmitter();
189
743
  this._options = Object.assign({
190
744
  idAccessor: defaultIdAccessor
191
745
  }, options);
@@ -315,7 +869,7 @@ var forcePoint = ({ x, y, strength = 0.01 }) => {
315
869
  };
316
870
 
317
871
  // src/graph/projector/graph-force-projector.ts
318
- var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-force-projector.ts";
872
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-force-projector.ts";
319
873
  var getValue = (valueOrFunction, invoker, defaultValue) => {
320
874
  return (typeof valueOrFunction === "function" ? invoker(valueOrFunction) : valueOrFunction) ?? defaultValue;
321
875
  };
@@ -388,8 +942,8 @@ var GraphForceProjector = class extends GraphProjector {
388
942
  edges: graph?.edges.length
389
943
  }
390
944
  }, {
391
- F: __dxlog_file2,
392
- L: 227,
945
+ F: __dxlog_file3,
946
+ L: 226,
393
947
  S: this,
394
948
  C: (f, a) => f(...a)
395
949
  });
@@ -443,8 +997,8 @@ var GraphForceProjector = class extends GraphProjector {
443
997
  log("updateForces", {
444
998
  forces
445
999
  }, {
446
- F: __dxlog_file2,
447
- L: 288,
1000
+ F: __dxlog_file3,
1001
+ L: 287,
448
1002
  S: this,
449
1003
  C: (f, a) => f(...a)
450
1004
  });
@@ -516,7 +1070,7 @@ import { log as log3 } from "@dxos/log";
516
1070
  // src/graph/projector/graph-radial-projector.ts
517
1071
  import { easeCubic, timer } from "d3";
518
1072
  import { log as log2 } from "@dxos/log";
519
- var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-radial-projector.ts";
1073
+ var __dxlog_file4 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-radial-projector.ts";
520
1074
  var GraphRadialProjector = class extends GraphProjector {
521
1075
  _timer;
522
1076
  findNode(x, y, radius) {
@@ -529,8 +1083,8 @@ var GraphRadialProjector = class extends GraphProjector {
529
1083
  edges: graph?.edges.length
530
1084
  }
531
1085
  }, {
532
- F: __dxlog_file3,
533
- L: 32,
1086
+ F: __dxlog_file4,
1087
+ L: 31,
534
1088
  S: this,
535
1089
  C: (f, a) => f(...a)
536
1090
  });
@@ -629,7 +1183,7 @@ var layoutVertical = (x, y, h, n) => {
629
1183
  };
630
1184
 
631
1185
  // src/graph/projector/graph-hierarchical-projector.ts
632
- var __dxlog_file4 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-hierarchical-projector.ts";
1186
+ var __dxlog_file5 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-hierarchical-projector.ts";
633
1187
  var GraphHierarchicalProjector = class extends GraphRadialProjector {
634
1188
  onUpdate(graph) {
635
1189
  log3("onUpdate", {
@@ -637,15 +1191,15 @@ var GraphHierarchicalProjector = class extends GraphRadialProjector {
637
1191
  nodes: graph?.nodes.length,
638
1192
  edges: graph?.edges.length
639
1193
  },
640
- selection: this.selection?.selected.value
1194
+ selection: this.selection?.getSelectedIds()
641
1195
  }, {
642
- F: __dxlog_file4,
643
- L: 24,
1196
+ F: __dxlog_file5,
1197
+ L: 23,
644
1198
  S: this,
645
1199
  C: (f, a) => f(...a)
646
1200
  });
647
1201
  this.mergeData(graph);
648
- const selected = this.selection?.selected.value?.[0];
1202
+ const selected = this.selection?.getSelectedIds()[0];
649
1203
  if (selected) {
650
1204
  const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
651
1205
  if (node) {
@@ -692,7 +1246,7 @@ var GraphHierarchicalProjector = class extends GraphRadialProjector {
692
1246
 
693
1247
  // src/graph/projector/graph-relational-projector.ts
694
1248
  import { log as log4 } from "@dxos/log";
695
- var __dxlog_file5 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-relational-projector.ts";
1249
+ var __dxlog_file6 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-relational-projector.ts";
696
1250
  var GraphRelationalProjector = class extends GraphRadialProjector {
697
1251
  onUpdate(graph) {
698
1252
  log4("onUpdate", {
@@ -700,15 +1254,15 @@ var GraphRelationalProjector = class extends GraphRadialProjector {
700
1254
  nodes: graph?.nodes.length,
701
1255
  edges: graph?.edges.length
702
1256
  },
703
- selection: this.selection?.selected.value
1257
+ selection: this.selection?.getSelectedIds()
704
1258
  }, {
705
- F: __dxlog_file5,
706
- L: 24,
1259
+ F: __dxlog_file6,
1260
+ L: 23,
707
1261
  S: this,
708
1262
  C: (f, a) => f(...a)
709
1263
  });
710
1264
  this.mergeData(graph);
711
- const selected = this.selection?.selected.value?.[0];
1265
+ const selected = this.selection?.getSelectedIds()[0];
712
1266
  if (selected) {
713
1267
  const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
714
1268
  if (node) {
@@ -815,8 +1369,8 @@ var createBullets = (group, nodeId, options = {}) => {
815
1369
  };
816
1370
 
817
1371
  // src/graph/renderer/renderer.ts
818
- import { invariant as invariant2 } from "@dxos/invariant";
819
- var __dxlog_file6 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/renderer.ts";
1372
+ import { invariant as invariant3 } from "@dxos/invariant";
1373
+ var __dxlog_file7 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/renderer.ts";
820
1374
  var Renderer = class {
821
1375
  _context;
822
1376
  _root;
@@ -832,8 +1386,8 @@ var Renderer = class {
832
1386
  return this._context;
833
1387
  }
834
1388
  get root() {
835
- invariant2(this._root.current, "SVG root is not initialized", {
836
- F: __dxlog_file6,
1389
+ invariant3(this._root.current, "SVG root is not initialized", {
1390
+ F: __dxlog_file7,
837
1391
  L: 40,
838
1392
  S: this,
839
1393
  A: [
@@ -849,13 +1403,13 @@ var Renderer = class {
849
1403
  };
850
1404
 
851
1405
  // src/graph/renderer/graph-renderer.ts
852
- var __dxlog_file7 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/graph-renderer.ts";
1406
+ var __dxlog_file8 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/graph-renderer.ts";
853
1407
  var createLine2 = line2();
854
1408
  var GraphRenderer = class extends Renderer {
855
1409
  render(layout) {
856
1410
  log5("render", layout, {
857
- F: __dxlog_file7,
858
- L: 63,
1411
+ F: __dxlog_file8,
1412
+ L: 62,
859
1413
  S: this,
860
1414
  C: (f, a) => f(...a)
861
1415
  });
@@ -1002,8 +1556,8 @@ var updateNode2 = (group, options) => {
1002
1556
  log5.error("updateNode", {
1003
1557
  error: error?.message
1004
1558
  }, {
1005
- F: __dxlog_file7,
1006
- L: 305,
1559
+ F: __dxlog_file8,
1560
+ L: 304,
1007
1561
  S: void 0,
1008
1562
  C: (f, a) => f(...a)
1009
1563
  });
@@ -1058,8 +1612,8 @@ var updateEdge = (group, options, nodeGroup) => {
1058
1612
  log5.error("updateEdge", {
1059
1613
  error: error?.message
1060
1614
  }, {
1061
- F: __dxlog_file7,
1062
- L: 417,
1615
+ F: __dxlog_file8,
1616
+ L: 416,
1063
1617
  S: void 0,
1064
1618
  C: (f, a) => f(...a)
1065
1619
  });
@@ -1140,112 +1694,427 @@ var linkerRenderer = (root, { source, target, point } = {}) => {
1140
1694
  });
1141
1695
  };
1142
1696
 
1697
+ // src/hooks/useGrid.ts
1698
+ import { line as line4, range, select as select5 } from "d3";
1699
+ import { useEffect, useMemo, useRef } from "react";
1700
+
1701
+ // src/hooks/useSvgContext.ts
1702
+ import { createContext, useContext } from "react";
1703
+ import { createRef } from "react";
1704
+ import { raise } from "@dxos/debug";
1705
+ var SVGContext = class {
1706
+ _ref = createRef();
1707
+ _scale;
1708
+ _centered;
1709
+ _size;
1710
+ _center;
1711
+ resized = new EventEmitter();
1712
+ constructor({ scale = new Scale(), centered = true }) {
1713
+ this._scale = scale;
1714
+ this._centered = centered;
1715
+ }
1716
+ get ref() {
1717
+ return this._ref;
1718
+ }
1719
+ get svg() {
1720
+ return this._ref.current;
1721
+ }
1722
+ get scale() {
1723
+ return this._scale;
1724
+ }
1725
+ get center() {
1726
+ return this._center;
1727
+ }
1728
+ get size() {
1729
+ return this._size;
1730
+ }
1731
+ /**
1732
+ * https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/viewBox
1733
+ */
1734
+ get viewBox() {
1735
+ const [x, y] = this.center;
1736
+ return `${x},${y},${this._size.width},${this._size.height}`;
1737
+ }
1738
+ setSize(size) {
1739
+ this._size = {
1740
+ ...size
1741
+ };
1742
+ this._center = this._centered ? [
1743
+ -Math.floor(size.width / 2),
1744
+ -Math.floor(size.height / 2)
1745
+ ] : [
1746
+ 0,
1747
+ 0
1748
+ ];
1749
+ this.resized.emit(this);
1750
+ }
1751
+ setTransform(transform) {
1752
+ if (this._scale.setTransform(transform)) {
1753
+ this.resized.emit(this);
1754
+ }
1755
+ }
1756
+ /**
1757
+ * https://developer.mozilla.org/en-US/docs/Web/API/Document/elementFromPoint
1758
+ * @param point
1759
+ */
1760
+ elementFromPoint(point) {
1761
+ const [x, y] = point;
1762
+ const [cx, cy] = this._center;
1763
+ return document.elementFromPoint(cx + x, cy + y);
1764
+ }
1765
+ };
1766
+ var SVGContextType = createContext(void 0);
1767
+ var SVGContextProvider = SVGContextType.Provider;
1768
+ var useSvgContext = () => {
1769
+ return useContext(SVGContextType) ?? raise(new Error("Missing SVGRoot"));
1770
+ };
1771
+
1772
+ // src/hooks/useGrid.ts
1773
+ var createLine4 = line4();
1774
+ var createGrid = (context, options) => {
1775
+ if (!context.size) {
1776
+ return [];
1777
+ }
1778
+ const paths = [];
1779
+ const { width, height } = context.size;
1780
+ const { x, y, k } = context.scale.transform;
1781
+ const s = 1 / k;
1782
+ const w = width * s;
1783
+ const h = height * s;
1784
+ const dx = -(x + width / 2) * s;
1785
+ const dy = -(y + height / 2) * s;
1786
+ if (options.axis) {
1787
+ const axis = [
1788
+ [
1789
+ [
1790
+ 0,
1791
+ dy
1792
+ ],
1793
+ [
1794
+ 0,
1795
+ dy + h
1796
+ ]
1797
+ ],
1798
+ [
1799
+ [
1800
+ dx,
1801
+ 0
1802
+ ],
1803
+ [
1804
+ dx + w,
1805
+ 0
1806
+ ]
1807
+ ]
1808
+ ];
1809
+ paths.push({
1810
+ id: "axis",
1811
+ class: "dx-axis",
1812
+ path: axis.map((line5) => createLine4(line5)).join()
1813
+ });
1814
+ }
1815
+ if (options.grid) {
1816
+ const mod = (n, size, delta = 0) => Math.floor(n / size + delta) * size;
1817
+ const majorSize = context.scale.gridSize;
1818
+ const xMajor = range(-mod((x + width / 2) * s, majorSize), mod((-x + width / 2) * s, majorSize, 1), majorSize);
1819
+ const yMajor = range(-mod((y + height / 2) * s, majorSize), mod((-y + height / 2) * s, majorSize, 1), majorSize);
1820
+ const major = [
1821
+ ...xMajor.filter((x2) => !options.axis || x2).map((x2) => [
1822
+ [
1823
+ x2,
1824
+ dy
1825
+ ],
1826
+ [
1827
+ x2,
1828
+ dy + h
1829
+ ]
1830
+ ]),
1831
+ ...yMajor.filter((y2) => !options.axis || y2).map((y2) => [
1832
+ [
1833
+ dx,
1834
+ y2
1835
+ ],
1836
+ [
1837
+ dx + w,
1838
+ y2
1839
+ ]
1840
+ ])
1841
+ ];
1842
+ paths.push({
1843
+ id: "major",
1844
+ class: "dx-major",
1845
+ path: major.map((line5) => createLine4(line5)).join()
1846
+ });
1847
+ const minorSize = Math.pow(2, Math.round(Math.log2(s * context.scale.gridSize)));
1848
+ if (majorSize > minorSize) {
1849
+ const xMinor = range(-mod((x + width / 2) * s, minorSize), mod((-x + width / 2) * s, minorSize, 1), minorSize);
1850
+ const yMinor = range(-mod((y + height / 2) * s, minorSize), mod((-y + height / 2) * s, minorSize, 1), minorSize);
1851
+ const minor = [
1852
+ ...xMinor.filter((x2) => xMajor.indexOf(x2) === -1).map((x2) => [
1853
+ [
1854
+ x2,
1855
+ dy
1856
+ ],
1857
+ [
1858
+ x2,
1859
+ dy + h
1860
+ ]
1861
+ ]),
1862
+ ...yMinor.filter((y2) => yMajor.indexOf(y2) === -1).map((y2) => [
1863
+ [
1864
+ dx,
1865
+ y2
1866
+ ],
1867
+ [
1868
+ dx + w,
1869
+ y2
1870
+ ]
1871
+ ])
1872
+ ];
1873
+ paths.push({
1874
+ id: "minor",
1875
+ class: "dx-minor",
1876
+ path: minor.map((line5) => createLine4(line5)).join()
1877
+ });
1878
+ }
1879
+ }
1880
+ return paths;
1881
+ };
1882
+ var defaultGridOptions = {
1883
+ visible: true,
1884
+ axis: true,
1885
+ grid: true
1886
+ };
1887
+ var GridController = class {
1888
+ _ref;
1889
+ _context;
1890
+ _options;
1891
+ _visible = false;
1892
+ constructor(_ref, _context, _options) {
1893
+ this._ref = _ref;
1894
+ this._context = _context;
1895
+ this._options = _options;
1896
+ this._visible = this._options.visible ?? true;
1897
+ }
1898
+ get ref() {
1899
+ return this._ref;
1900
+ }
1901
+ get visible() {
1902
+ return this._visible;
1903
+ }
1904
+ draw() {
1905
+ if (!this._context.size) {
1906
+ return;
1907
+ }
1908
+ const paths = this._visible ? createGrid(this._context, this._options) : [];
1909
+ const root = select5(this._ref.current);
1910
+ root.selectAll("path").data(paths, (path) => path.id).join("path").style("pointer-events", "none").attr("d", (d) => d.path).attr("class", (d) => d.class);
1911
+ const transform = this._context.scale.transform;
1912
+ if (transform) {
1913
+ root.attr("transform", transform);
1914
+ root.attr("stroke-width", 1 / transform.k);
1915
+ }
1916
+ }
1917
+ setVisible(visible) {
1918
+ this._visible = visible;
1919
+ this.draw();
1920
+ return this;
1921
+ }
1922
+ };
1923
+ var useGrid = (options = defaultGridOptions) => {
1924
+ const ref = useRef(null);
1925
+ const context = useSvgContext();
1926
+ const controller = useMemo(() => new GridController(ref, context, options), []);
1927
+ useEffect(() => context.resized.on(() => controller.draw()), [
1928
+ context,
1929
+ controller
1930
+ ]);
1931
+ return controller;
1932
+ };
1933
+
1934
+ // src/hooks/useZoom.ts
1935
+ import { select as select6, zoom, zoomIdentity as zoomIdentity2 } from "d3";
1936
+ import defaultsDeep from "lodash.defaultsdeep";
1937
+ import { useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2 } from "react";
1938
+ var defaultZoomOptions = {
1939
+ enabled: true,
1940
+ extent: [
1941
+ 1 / 4,
1942
+ 4
1943
+ ],
1944
+ onDblClick: (zoom2) => zoom2.reset()
1945
+ };
1946
+ var ZoomHandler = class {
1947
+ _ref;
1948
+ _context;
1949
+ _zoom;
1950
+ _options;
1951
+ _enabled;
1952
+ constructor(_ref, _context, options) {
1953
+ this._ref = _ref;
1954
+ this._context = _context;
1955
+ this._options = defaultsDeep({}, options, defaultZoomOptions);
1956
+ this._enabled = this._options.enabled ?? true;
1957
+ this._zoom = zoom().scaleExtent(this._options.extent ?? defaultZoomOptions.extent);
1958
+ }
1959
+ /**
1960
+ * Gets the reference which the transform is applied to.
1961
+ */
1962
+ get ref() {
1963
+ return this._ref;
1964
+ }
1965
+ get zoom() {
1966
+ return this._zoom;
1967
+ }
1968
+ init() {
1969
+ this.setEnabled(this._enabled);
1970
+ this.reset(0);
1971
+ return this;
1972
+ }
1973
+ setEnabled(enable) {
1974
+ if (enable) {
1975
+ select6(this._context.svg).call(this._zoom).on(
1976
+ "dblclick.zoom",
1977
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1978
+ // @ts-ignore
1979
+ this._options?.onDblClick ? () => {
1980
+ this._options?.onDblClick(this);
1981
+ } : null
1982
+ );
1983
+ } else {
1984
+ select6(this._context.svg).on(".zoom", null);
1985
+ }
1986
+ this._enabled = enable;
1987
+ return this;
1988
+ }
1989
+ reset(duration = 500) {
1990
+ const scale = 1;
1991
+ const transform = zoomIdentity2.scale(scale);
1992
+ select6(this._context.svg).transition().duration(duration).call(this._zoom.transform, transform);
1993
+ return this;
1994
+ }
1995
+ };
1996
+ var useZoom = (options = defaultZoomOptions) => {
1997
+ const context = useSvgContext();
1998
+ const ref = useRef2(null);
1999
+ const handler = useMemo2(() => new ZoomHandler(ref, context, options), [
2000
+ context,
2001
+ options
2002
+ ]);
2003
+ useEffect2(() => {
2004
+ handler.zoom.on("zoom", ({ transform }) => {
2005
+ context.setTransform(transform);
2006
+ select6(ref.current).attr("transform", transform);
2007
+ });
2008
+ handler.init();
2009
+ }, [
2010
+ handler
2011
+ ]);
2012
+ return handler;
2013
+ };
2014
+
1143
2015
  // src/components/Graph/Graph.tsx
1144
- var __dxlog_file8 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/components/Graph/Graph.tsx";
1145
- var GraphInner = ({ classNames, model, projector: _projector, renderer: _renderer, drag: drag2, arrows, onSelect, onInspect, ...props }, forwardedRef) => {
1146
- var _effect = _useSignals();
1147
- try {
1148
- const context = useSvgContext();
1149
- const graphRef = useRef();
1150
- const { projector, renderer } = useMemo(() => {
1151
- let projector2 = _projector;
1152
- if (!projector2) {
1153
- projector2 = new GraphForceProjector(context);
1154
- }
1155
- let renderer2 = _renderer;
1156
- if (!renderer2) {
1157
- renderer2 = new GraphRenderer(context, graphRef, {
1158
- ...props,
1159
- // TODO(burdon): Replace drag when projector is updated.
1160
- drag: drag2 ? createGraphDrag(context, projector2) : void 0,
1161
- arrows: {
1162
- end: arrows
1163
- },
1164
- onNodeClick: onSelect ? (node, event) => onSelect(node, event) : void 0,
1165
- onNodePointerEnter: onInspect ? (node, event) => onInspect(node, event) : void 0
2016
+ var __dxlog_file9 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/components/Graph/Graph.tsx";
2017
+ var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rendererProp, drag: drag2, arrows, onSelect, onInspect, ...props }, forwardedRef) => {
2018
+ const context = useSvgContext();
2019
+ const graphRef = useRef3(null);
2020
+ const { projector, renderer } = useMemo3(() => {
2021
+ let projector2 = projectorProp;
2022
+ if (!projector2) {
2023
+ projector2 = new GraphForceProjector(context);
2024
+ }
2025
+ let renderer2 = rendererProp;
2026
+ if (!renderer2) {
2027
+ renderer2 = new GraphRenderer(context, graphRef, {
2028
+ ...props,
2029
+ // TODO(burdon): Replace drag when projector is updated.
2030
+ drag: drag2 ? createGraphDrag(context, projector2) : void 0,
2031
+ arrows: {
2032
+ end: arrows
2033
+ },
2034
+ onNodeClick: onSelect ? (node, event) => onSelect(node, event) : void 0,
2035
+ onNodePointerEnter: onInspect ? (node, event) => onInspect(node, event) : void 0
2036
+ });
2037
+ }
2038
+ return {
2039
+ projector: projector2,
2040
+ renderer: renderer2
2041
+ };
2042
+ }, [
2043
+ context,
2044
+ projectorProp,
2045
+ rendererProp,
2046
+ drag2
2047
+ ]);
2048
+ useImperativeHandle(forwardedRef, () => ({
2049
+ refresh: () => {
2050
+ projector.updateData(model?.graph);
2051
+ },
2052
+ repaint: () => {
2053
+ renderer.render(projector.layout);
2054
+ },
2055
+ findNode: (id) => {
2056
+ return graphRef.current?.querySelector(`g[data-id="${id}"]`);
2057
+ }
2058
+ }), [
2059
+ model,
2060
+ projector,
2061
+ renderer
2062
+ ]);
2063
+ useEffect3(() => {
2064
+ projector.updateData(model?.graph);
2065
+ const unsubscribeModel = model ? model.subscribe(() => {
2066
+ projector.updateData(model?.graph);
2067
+ }) : void 0;
2068
+ return combine(unsubscribeModel, projector.updated.on(({ layout }) => {
2069
+ try {
2070
+ renderer.render(layout);
2071
+ } catch (error) {
2072
+ void projector.stop();
2073
+ log6.catch(error, void 0, {
2074
+ F: __dxlog_file9,
2075
+ L: 116,
2076
+ S: void 0,
2077
+ C: (f, a) => f(...a)
1166
2078
  });
1167
2079
  }
1168
- return {
1169
- projector: projector2,
1170
- renderer: renderer2
1171
- };
1172
- }, [
1173
- context,
1174
- _projector,
1175
- _renderer,
1176
- drag2
1177
- ]);
1178
- useImperativeHandle(forwardedRef, () => ({
1179
- refresh: () => {
1180
- projector.updateData(model?.graph);
1181
- },
1182
- repaint: () => {
1183
- renderer.render(projector.layout);
1184
- },
1185
- findNode: (id) => {
1186
- return graphRef.current?.querySelector(`g[data-id="${id}"]`);
1187
- }
1188
- }), [
1189
- model,
1190
- projector,
1191
- renderer
1192
- ]);
1193
- useEffect(() => {
1194
- return combine(effect(() => {
1195
- projector.updateData(model?.graph);
1196
- }), projector.updated.on(({ layout }) => {
1197
- try {
1198
- renderer.render(layout);
1199
- } catch (error) {
1200
- void projector.stop();
1201
- log6.catch(error, void 0, {
1202
- F: __dxlog_file8,
1203
- L: 108,
1204
- S: void 0,
1205
- C: (f, a) => f(...a)
1206
- });
1207
- }
1208
- }));
1209
- }, [
1210
- model,
1211
- projector,
1212
- renderer
1213
- ]);
1214
- useEffect(() => {
1215
- void projector.start();
1216
- return () => {
1217
- void projector.stop();
1218
- };
1219
- }, [
1220
- projector
1221
- ]);
1222
- return /* @__PURE__ */ React.createElement("g", {
1223
- ref: graphRef,
1224
- className: mx("dx-graph", classNames)
1225
- });
1226
- } finally {
1227
- _effect.f();
1228
- }
2080
+ }));
2081
+ }, [
2082
+ model,
2083
+ projector,
2084
+ renderer
2085
+ ]);
2086
+ useEffect3(() => {
2087
+ void projector.start();
2088
+ return () => {
2089
+ void projector.stop();
2090
+ };
2091
+ }, [
2092
+ projector
2093
+ ]);
2094
+ return /* @__PURE__ */ React.createElement("g", {
2095
+ ref: graphRef,
2096
+ className: mx("dx-graph", classNames)
2097
+ });
1229
2098
  };
1230
2099
  var Graph = /* @__PURE__ */ forwardRef(GraphInner);
1231
2100
 
1232
2101
  // src/components/Mesh/Mesh.tsx
1233
- import { geoPath, select as select5 } from "d3";
1234
- import { useEffect as useEffect2 } from "react";
2102
+ import { geoPath, select as select7 } from "d3";
2103
+ import { useEffect as useEffect4 } from "react";
1235
2104
  import { feature, mesh } from "topojson-client";
1236
2105
  var Mesh = ({ radius = 16, value = 0.5 }) => {
1237
2106
  const { svg, size } = useSvgContext();
1238
- useEffect2(() => {
2107
+ useEffect4(() => {
1239
2108
  if (size) {
1240
2109
  const topology = hexTopology(size, radius, value);
1241
2110
  const projection = hexProjection(radius);
1242
2111
  const path = geoPath().projection(projection);
1243
- select5(svg).append("g").attr("class", "hexagon").selectAll("path").data(topology.objects.hexagons.geometries).enter().append("path").attr("d", (d) => path(feature(topology, d))).attr("class", (d) => d.properties?.fill ? "fill" : null);
1244
- select5(svg).append("path").datum(mesh(topology, topology.objects.hexagons)).attr("class", "mesh").attr("d", path);
2112
+ select7(svg).append("g").attr("class", "hexagon").selectAll("path").data(topology.objects.hexagons.geometries).enter().append("path").attr("d", (d) => path(feature(topology, d))).attr("class", (d) => d.properties?.fill ? "fill" : null);
2113
+ select7(svg).append("path").datum(mesh(topology, topology.objects.hexagons)).attr("class", "mesh").attr("d", path);
1245
2114
  const redraw = (border) => {
1246
2115
  border.attr("d", path(mesh(topology, topology.objects.hexagons, (a, b) => a.properties.fill !== b.properties.fill)));
1247
2116
  };
1248
- select5(svg).append("path").attr("class", "border").call(redraw);
2117
+ select7(svg).append("path").attr("class", "border").call(redraw);
1249
2118
  }
1250
2119
  }, [
1251
2120
  svg,
@@ -1362,115 +2231,96 @@ var hexProjection = (radius) => {
1362
2231
  };
1363
2232
 
1364
2233
  // src/components/SVG/Grid.tsx
1365
- import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
1366
2234
  import React2 from "react";
1367
- import { mx as mx2 } from "@dxos/react-ui-theme";
2235
+ import { mx as mx2 } from "@dxos/ui-theme";
1368
2236
  var Grid = ({ classNames, ...props }) => {
1369
- var _effect = _useSignals2();
1370
- try {
1371
- const { ref } = useGrid(props);
1372
- return /* @__PURE__ */ React2.createElement("g", {
1373
- ref,
1374
- className: mx2("dx-grid", classNames)
1375
- });
1376
- } finally {
1377
- _effect.f();
1378
- }
2237
+ const { ref } = useGrid(props);
2238
+ return /* @__PURE__ */ React2.createElement("g", {
2239
+ ref,
2240
+ className: mx2("dx-grid", classNames)
2241
+ });
1379
2242
  };
1380
2243
 
1381
2244
  // src/components/SVG/Markers.tsx
1382
- import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
1383
- import { select as select6 } from "d3";
1384
- import React3, { useEffect as useEffect3, useRef as useRef2 } from "react";
2245
+ import { select as select8 } from "d3";
2246
+ import React3, { useEffect as useEffect5, useRef as useRef4 } from "react";
1385
2247
  var Markers = ({ arrowSize, className }) => {
1386
- var _effect = _useSignals3();
1387
- try {
1388
- const ref = useRef2();
1389
- useEffect3(() => {
1390
- select6(ref.current).call(createMarkers({
1391
- arrowSize
1392
- }));
1393
- }, [
1394
- ref
1395
- ]);
1396
- return /* @__PURE__ */ React3.createElement("defs", {
1397
- ref,
1398
- className
1399
- });
1400
- } finally {
1401
- _effect.f();
1402
- }
2248
+ const ref = useRef4(null);
2249
+ useEffect5(() => {
2250
+ select8(ref.current).call(createMarkers({
2251
+ arrowSize
2252
+ }));
2253
+ }, [
2254
+ ref
2255
+ ]);
2256
+ return /* @__PURE__ */ React3.createElement("defs", {
2257
+ ref,
2258
+ className
2259
+ });
1403
2260
  };
1404
2261
 
1405
2262
  // src/components/SVG/Root.tsx
1406
- import { useSignals as _useSignals4 } from "@preact-signals/safe-react/tracking";
1407
- import { select as select7 } from "d3";
1408
- import React4, { forwardRef as forwardRef2, useEffect as useEffect4, useImperativeHandle as useImperativeHandle2, useMemo as useMemo2 } from "react";
2263
+ import { select as select9 } from "d3";
2264
+ import React4, { forwardRef as forwardRef2, useEffect as useEffect6, useImperativeHandle as useImperativeHandle2, useMemo as useMemo4 } from "react";
1409
2265
  import { useResizeDetector } from "react-resize-detector";
1410
- import { mx as mx3 } from "@dxos/react-ui-theme";
1411
- var Root = /* @__PURE__ */ forwardRef2(({ classNames, children, ...props }, ref) => {
1412
- var _effect = _useSignals4();
1413
- try {
1414
- const { ref: containerRef, width = 0, height = 0 } = useResizeDetector({
1415
- refreshRate: 200
2266
+ import { composableProps, mx as mx3 } from "@dxos/ui-theme";
2267
+ var Root = /* @__PURE__ */ forwardRef2(({ children, scale, centered, ...props }, ref) => {
2268
+ const { ref: containerRef, width = 0, height = 0 } = useResizeDetector({
2269
+ refreshRate: 200
2270
+ });
2271
+ const context = useMemo4(() => {
2272
+ return new SVGContext({
2273
+ scale,
2274
+ centered
1416
2275
  });
1417
- const context = useMemo2(() => {
1418
- return new SVGContext(props);
1419
- }, [
1420
- props.scale,
1421
- props.centered
1422
- ]);
1423
- useImperativeHandle2(ref, () => context, [
1424
- context
1425
- ]);
1426
- useEffect4(() => {
1427
- if (width && height) {
1428
- context.setSize({
1429
- width,
1430
- height
1431
- });
1432
- select7(context.svg).attr("display", "block").attr("viewBox", context.viewBox).attr("width", width).attr("height", height);
1433
- }
1434
- }, [
1435
- context,
1436
- width,
1437
- height
1438
- ]);
1439
- const ready = width !== 0 && height !== 0;
1440
- return /* @__PURE__ */ React4.createElement(SVGContextProvider, {
1441
- value: context
1442
- }, /* @__PURE__ */ React4.createElement("div", {
1443
- ref: containerRef,
1444
- className: mx3("grid grow overflow-hidden", classNames)
1445
- }, /* @__PURE__ */ React4.createElement("svg", {
1446
- xmlns: "http://www.w3.org/2000/svg",
1447
- ref: context.ref,
1448
- className: mx3("transition-opacity opacity-0 duration-1000", ready && "opacity-100")
1449
- }, ready && children)));
1450
- } finally {
1451
- _effect.f();
1452
- }
2276
+ }, [
2277
+ scale,
2278
+ centered
2279
+ ]);
2280
+ useImperativeHandle2(ref, () => context, [
2281
+ context
2282
+ ]);
2283
+ useEffect6(() => {
2284
+ if (width && height) {
2285
+ context.setSize({
2286
+ width,
2287
+ height
2288
+ });
2289
+ select9(context.svg).attr("display", "block").attr("viewBox", context.viewBox).attr("width", width).attr("height", height);
2290
+ }
2291
+ }, [
2292
+ context,
2293
+ width,
2294
+ height
2295
+ ]);
2296
+ const ready = width !== 0 && height !== 0;
2297
+ return /* @__PURE__ */ React4.createElement(SVGContextProvider, {
2298
+ value: context
2299
+ }, /* @__PURE__ */ React4.createElement("div", {
2300
+ ...composableProps(props, {
2301
+ classNames: "dx-expander"
2302
+ }),
2303
+ ref: containerRef
2304
+ }, /* @__PURE__ */ React4.createElement("svg", {
2305
+ xmlns: "http://www.w3.org/2000/svg",
2306
+ ref: context.ref,
2307
+ className: mx3("transition-opacity opacity-0 duration-1000", ready && "opacity-100")
2308
+ }, ready && children)));
1453
2309
  });
1454
2310
 
1455
2311
  // src/components/SVG/Zoom.tsx
1456
- import { useSignals as _useSignals5 } from "@preact-signals/safe-react/tracking";
1457
- import React5, { memo, useMemo as useMemo3 } from "react";
2312
+ import React5, { memo, useMemo as useMemo5 } from "react";
1458
2313
  var Zoom = /* @__PURE__ */ memo(({ extent, className, children }) => {
1459
- var _effect = _useSignals5();
1460
- try {
1461
- const options = useMemo3(() => ({
1462
- extent
1463
- }), [
1464
- JSON.stringify(extent)
1465
- ]);
1466
- const zoom = useZoom(options);
1467
- return /* @__PURE__ */ React5.createElement("g", {
1468
- ref: zoom.ref,
1469
- className
1470
- }, children);
1471
- } finally {
1472
- _effect.f();
1473
- }
2314
+ const options = useMemo5(() => ({
2315
+ extent
2316
+ }), [
2317
+ JSON.stringify(extent)
2318
+ ]);
2319
+ const zoom2 = useZoom(options);
2320
+ return /* @__PURE__ */ React5.createElement("g", {
2321
+ ref: zoom2.ref,
2322
+ className
2323
+ }, children);
1474
2324
  });
1475
2325
 
1476
2326
  // src/components/SVG/SVG.tsx
@@ -1484,7 +2334,7 @@ var SVG = {
1484
2334
  };
1485
2335
 
1486
2336
  // src/fx/pulsar.ts
1487
- import { easeCubicOut as easeCubicOut2, select as select8 } from "d3";
2337
+ import { easeCubicOut as easeCubicOut2, select as select10 } from "d3";
1488
2338
  var PROP_PULSAR_ACTIVE = "dx-pulsar-active";
1489
2339
  (function(Pulsar2) {
1490
2340
  Pulsar2.has = (group) => group.select("circle.dx-pulsar").empty();
@@ -1499,10 +2349,10 @@ var PROP_PULSAR_ACTIVE = "dx-pulsar-active";
1499
2349
  var startAnimation = (pulsar, r, options = {}) => {
1500
2350
  const { period = 1e3, duration = 800, ratio = 3 } = options;
1501
2351
  return pulsar.attr("r", r).attr("opacity", 1).transition("pulsar").delay(period - Date.now() % period).duration(Math.min(duration, period - 20)).ease(easeCubicOut2).attr("r", r * ratio).attr("opacity", -0.1).on("end", function() {
1502
- if (select8(this).property(PROP_PULSAR_ACTIVE)) {
1503
- startAnimation(select8(this), r, options);
2352
+ if (select10(this).property(PROP_PULSAR_ACTIVE)) {
2353
+ startAnimation(select10(this), r, options);
1504
2354
  } else {
1505
- select8(this).remove();
2355
+ select10(this).remove();
1506
2356
  }
1507
2357
  });
1508
2358
  };
@@ -1513,7 +2363,6 @@ export {
1513
2363
  Graph,
1514
2364
  GraphForceProjector,
1515
2365
  GraphHierarchicalProjector,
1516
- GraphInner,
1517
2366
  GraphProjector,
1518
2367
  GraphRadialProjector,
1519
2368
  GraphRelationalProjector,