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