@dxos/app-graph 0.8.4-main.9be5663bfe → 0.8.4-main.abd8ff62ef

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 (33) hide show
  1. package/dist/lib/browser/{chunk-W47H2NND.mjs → chunk-3T75MQOS.mjs} +42 -166
  2. package/dist/lib/browser/chunk-3T75MQOS.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -1
  4. package/dist/lib/browser/index.mjs.map +2 -2
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/testing/index.mjs +1 -1
  7. package/dist/lib/node-esm/{chunk-LYZWNJ7J.mjs → chunk-UEXRLXMS.mjs} +42 -166
  8. package/dist/lib/node-esm/chunk-UEXRLXMS.mjs.map +7 -0
  9. package/dist/lib/node-esm/index.mjs +1 -1
  10. package/dist/lib/node-esm/index.mjs.map +2 -2
  11. package/dist/lib/node-esm/meta.json +1 -1
  12. package/dist/lib/node-esm/testing/index.mjs +1 -1
  13. package/dist/types/src/atoms.d.ts.map +1 -1
  14. package/dist/types/src/graph-builder.d.ts +1 -1
  15. package/dist/types/src/graph-builder.d.ts.map +1 -1
  16. package/dist/types/src/graph.d.ts.map +1 -1
  17. package/dist/types/src/node-matcher.d.ts +2 -2
  18. package/dist/types/src/node-matcher.d.ts.map +1 -1
  19. package/dist/types/src/node.d.ts +2 -2
  20. package/dist/types/src/node.d.ts.map +1 -1
  21. package/dist/types/src/stories/EchoGraph.stories.d.ts.map +1 -1
  22. package/dist/types/src/testing/setup-graph-builder.d.ts.map +1 -1
  23. package/dist/types/src/util.d.ts +1 -0
  24. package/dist/types/src/util.d.ts.map +1 -1
  25. package/dist/types/tsconfig.tsbuildinfo +1 -1
  26. package/package.json +19 -26
  27. package/src/graph-builder.test.ts +126 -0
  28. package/src/graph-builder.ts +18 -0
  29. package/src/node-matcher.ts +2 -2
  30. package/src/stories/EchoGraph.stories.tsx +2 -2
  31. package/src/util.ts +9 -3
  32. package/dist/lib/browser/chunk-W47H2NND.mjs.map +0 -7
  33. package/dist/lib/node-esm/chunk-LYZWNJ7J.mjs.map +0 -7
@@ -61,8 +61,12 @@ var secondaryKey = (...parts) => parts.join(SECONDARY);
61
61
  var secondaryParts = (key) => key.split(SECONDARY);
62
62
  var normalizeRelation = (relation2) => relation2 == null ? childRelation() : typeof relation2 === "string" ? relation(relation2) : relation2;
63
63
  var shallowEqual = (a, b) => {
64
- if (a === b) return true;
65
- if (a == null || b == null || typeof a !== "object" || typeof b !== "object") return false;
64
+ if (a === b) {
65
+ return true;
66
+ }
67
+ if (a == null || b == null || typeof a !== "object" || typeof b !== "object") {
68
+ return false;
69
+ }
66
70
  const keysA = Object.keys(a);
67
71
  const keysB = Object.keys(b);
68
72
  if (keysA.length !== keysB.length) {
@@ -76,7 +80,7 @@ var nodeArgsUnchanged = (prev, next) => {
76
80
  }
77
81
  return prev.every((prevNode, idx) => {
78
82
  const nextNode = next[idx];
79
- return prevNode.id === nextNode.id && prevNode.type === nextNode.type && shallowEqual(prevNode.data, nextNode.data) && shallowEqual(prevNode.properties, nextNode.properties);
83
+ return prevNode.id === nextNode.id && prevNode.type === nextNode.type && shallowEqual(prevNode.data, nextNode.data) && shallowEqual(prevNode.properties, nextNode.properties) && nodeArgsUnchanged(prevNode.nodes ?? [], nextNode.nodes ?? []);
80
84
  });
81
85
  };
82
86
  var qualifyId = (parentId, ...segmentIds) => [
@@ -84,15 +88,7 @@ var qualifyId = (parentId, ...segmentIds) => [
84
88
  ...segmentIds
85
89
  ].join(PATH);
86
90
  var validateSegmentId = (id) => {
87
- invariant(!id.includes(PATH), `Node segment ID must not contain '${PATH}': ${id}`, {
88
- F: __dxlog_file,
89
- L: 78,
90
- S: void 0,
91
- A: [
92
- "!id.includes(PATH)",
93
- "`Node segment ID must not contain '${PATH}': ${id}`"
94
- ]
95
- });
91
+ invariant(!id.includes(PATH), `Node segment ID must not contain '${PATH}': ${id}`, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 56, S: void 0, A: ["!id.includes(PATH)", "`Node segment ID must not contain '${PATH}': ${id}`"] });
96
92
  };
97
93
  var getParentId = (qualifiedId) => {
98
94
  const lastSlash = qualifiedId.lastIndexOf(PATH);
@@ -147,15 +143,7 @@ var __dxlog_file2 = "/__w/dxos/dxos/packages/sdk/app-graph/src/graph.ts";
147
143
  var graphSymbol = /* @__PURE__ */ Symbol("graph");
148
144
  var getGraph = (node) => {
149
145
  const graph = node[graphSymbol];
150
- invariant2(graph, "Node is not associated with a graph.", {
151
- F: __dxlog_file2,
152
- L: 33,
153
- S: void 0,
154
- A: [
155
- "graph",
156
- "'Node is not associated with a graph.'"
157
- ]
158
- });
146
+ invariant2(graph, "Node is not associated with a graph.", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 21, S: void 0, A: ["graph", "'Node is not associated with a graph.'"] });
159
147
  return graph;
160
148
  };
161
149
  var GraphTypeId = /* @__PURE__ */ Symbol.for("@dxos/app-graph/Graph");
@@ -194,15 +182,7 @@ var GraphImpl = class {
194
182
  _nodeOrThrow = Atom.family((id) => {
195
183
  return Atom.make((get2) => {
196
184
  const node = get2(this._node(id));
197
- invariant2(Option.isSome(node), `Node not available: ${id}`, {
198
- F: __dxlog_file2,
199
- L: 172,
200
- S: this,
201
- A: [
202
- "Option.isSome(node)",
203
- "`Node not available: ${id}`"
204
- ]
205
- });
185
+ invariant2(Option.isSome(node), `Node not available: ${id}`, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 67, S: this, A: ["Option.isSome(node)", "`Node not available: ${id}`"] });
206
186
  return node.value;
207
187
  });
208
188
  });
@@ -373,15 +353,7 @@ function getConnections(graphOrId, idOrRelation, relation2) {
373
353
  } else {
374
354
  const graph = graphOrId;
375
355
  const id = idOrRelation;
376
- invariant2(relation2 !== void 0, "Relation is required.", {
377
- F: __dxlog_file2,
378
- L: 449,
379
- S: this,
380
- A: [
381
- "relation !== undefined",
382
- "'Relation is required.'"
383
- ]
384
- });
356
+ invariant2(relation2 !== void 0, "Relation is required.", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 272, S: this, A: ["relation !== undefined", "'Relation is required.'"] });
385
357
  const rel = relation2;
386
358
  return getConnectionsImpl(graph, id, rel);
387
359
  }
@@ -518,12 +490,7 @@ var initializeImpl = async (graph, id) => {
518
490
  log("initialize", {
519
491
  id,
520
492
  initialized
521
- }, {
522
- F: __dxlog_file2,
523
- L: 671,
524
- S: void 0,
525
- C: (f, a) => f(...a)
526
- });
493
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 431, S: void 0 });
527
494
  if (!initialized) {
528
495
  Record.set(internal._initialized, id, true);
529
496
  await internal._onInitialize?.(id);
@@ -549,24 +516,14 @@ var expandImpl = (graph, id, relation2) => {
549
516
  log("expand", {
550
517
  key,
551
518
  deferred: true
552
- }, {
553
- F: __dxlog_file2,
554
- L: 717,
555
- S: void 0,
556
- C: (f, a) => f(...a)
557
- });
519
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 463, S: void 0 });
558
520
  return graph;
559
521
  }
560
522
  const expanded = Record.get(internal._expanded, key).pipe(Option.getOrElse(() => false));
561
523
  log("expand", {
562
524
  key,
563
525
  expanded
564
- }, {
565
- F: __dxlog_file2,
566
- L: 722,
567
- S: void 0,
568
- C: (f, a) => f(...a)
569
- });
526
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 470, S: void 0 });
570
527
  if (!expanded) {
571
528
  Record.set(internal._expanded, key, true);
572
529
  internal._onExpand?.(id, normalizedRelation);
@@ -581,15 +538,7 @@ function expand(graphOrId, idOrRelation, relation2) {
581
538
  } else {
582
539
  const graph = graphOrId;
583
540
  const id = idOrRelation;
584
- invariant2(relation2 !== void 0, "Relation is required.", {
585
- F: __dxlog_file2,
586
- L: 758,
587
- S: this,
588
- A: [
589
- "relation !== undefined",
590
- "'Relation is required.'"
591
- ]
592
- });
541
+ invariant2(relation2 !== void 0, "Relation is required.", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 490, S: this, A: ["relation !== undefined", "'Relation is required.'"] });
593
542
  const rel = relation2;
594
543
  return expandImpl(graph, id, rel);
595
544
  }
@@ -658,24 +607,14 @@ var addNodeImpl = (graph, nodeArg) => {
658
607
  typeChanged,
659
608
  dataChanged,
660
609
  propertiesChanged
661
- }, {
662
- F: __dxlog_file2,
663
- L: 880,
664
- S: void 0,
665
- C: (f, a) => f(...a)
666
- });
610
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 565, S: void 0 });
667
611
  if (typeChanged || dataChanged || propertiesChanged) {
668
612
  log("updating node", {
669
613
  id,
670
614
  type,
671
615
  data,
672
616
  properties
673
- }, {
674
- F: __dxlog_file2,
675
- L: 887,
676
- S: void 0,
677
- C: (f, a) => f(...a)
678
- });
617
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 572, S: void 0 });
679
618
  const newNode = Option.some({
680
619
  ...existing,
681
620
  ...rest,
@@ -699,12 +638,7 @@ var addNodeImpl = (graph, nodeArg) => {
699
638
  type,
700
639
  data,
701
640
  properties
702
- }, {
703
- F: __dxlog_file2,
704
- L: 900,
705
- S: void 0,
706
- C: (f, a) => f(...a)
707
- });
641
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 596, S: void 0 });
708
642
  const newNode = internal._constructNode({
709
643
  id,
710
644
  type,
@@ -845,12 +779,7 @@ var addEdgeImpl = (graph, edgeArg) => {
845
779
  source: edgeArg.source,
846
780
  target: edgeArg.target,
847
781
  relation: relationId
848
- }, {
849
- F: __dxlog_file2,
850
- L: 1083,
851
- S: void 0,
852
- C: (f, a) => f(...a)
853
- });
782
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 758, S: void 0 });
854
783
  internal._registry.set(sourceAtom, {
855
784
  ...source,
856
785
  [relationId]: [
@@ -867,12 +796,7 @@ var addEdgeImpl = (graph, edgeArg) => {
867
796
  source: edgeArg.source,
868
797
  target: edgeArg.target,
869
798
  relation: inverseId
870
- }, {
871
- F: __dxlog_file2,
872
- L: 1091,
873
- S: void 0,
874
- C: (f, a) => f(...a)
875
- });
799
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 775, S: void 0 });
876
800
  internal._registry.set(targetAtom, {
877
801
  ...target,
878
802
  [inverseId]: [
@@ -972,39 +896,15 @@ var relationKey = (relation2) => {
972
896
  };
973
897
  var relationFromKey = (encoded) => {
974
898
  const parts = secondaryParts(encoded);
975
- invariant2(parts.length === 2 && parts[0].length > 0 && parts[1].length > 0, `Invalid relation key: ${encoded}`, {
976
- F: __dxlog_file2,
977
- L: 1236,
978
- S: void 0,
979
- A: [
980
- "parts.length === 2 && parts[0].length > 0 && parts[1].length > 0",
981
- "`Invalid relation key: ${encoded}`"
982
- ]
983
- });
899
+ invariant2(parts.length === 2 && parts[0].length > 0 && parts[1].length > 0, `Invalid relation key: ${encoded}`, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 894, S: void 0, A: ["parts.length === 2 && parts[0].length > 0 && parts[1].length > 0", "`Invalid relation key: ${encoded}`"] });
984
900
  const [kind, directionRaw] = parts;
985
- invariant2(directionRaw === "outbound" || directionRaw === "inbound", `Invalid relation direction: ${directionRaw}`, {
986
- F: __dxlog_file2,
987
- L: 1238,
988
- S: void 0,
989
- A: [
990
- "directionRaw === 'outbound' || directionRaw === 'inbound'",
991
- "`Invalid relation direction: ${directionRaw}`"
992
- ]
993
- });
901
+ invariant2(directionRaw === "outbound" || directionRaw === "inbound", `Invalid relation direction: ${directionRaw}`, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 896, S: void 0, A: ["directionRaw === 'outbound' || directionRaw === 'inbound'", "`Invalid relation direction: ${directionRaw}`"] });
994
902
  return relation(kind, directionRaw);
995
903
  };
996
904
  var connectionKey = (id, relation2) => primaryKey(id, relationKey(relation2));
997
905
  var relationFromConnectionKey = (key) => {
998
906
  const [id, encodedRelation] = primaryParts(key);
999
- invariant2(id && encodedRelation, `Invalid connection key: ${key}`, {
1000
- F: __dxlog_file2,
1001
- L: 1246,
1002
- S: void 0,
1003
- A: [
1004
- "id && encodedRelation",
1005
- "`Invalid connection key: ${key}`"
1006
- ]
1007
- });
907
+ invariant2(id && encodedRelation, `Invalid connection key: ${key}`, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 902, S: void 0, A: ["id && encodedRelation", "`Invalid connection key: ${key}`"] });
1008
908
  return {
1009
909
  id,
1010
910
  relation: relationFromKey(encodedRelation)
@@ -1103,6 +1003,8 @@ var GraphBuilderImpl = class {
1103
1003
  _dirtyConnectors = /* @__PURE__ */ new Map();
1104
1004
  /** Last-flushed node IDs per connector key, used for edge removal on update. */
1105
1005
  _connectorPrevious = /* @__PURE__ */ new Map();
1006
+ /** All inline-descendant IDs per connector key, used to remove stale inline nodes on update. */
1007
+ _connectorPreviousInlineIds = /* @__PURE__ */ new Map();
1106
1008
  /** Last-flushed node args per connector key, used for change detection. */
1107
1009
  _connectorPreviousArgs = /* @__PURE__ */ new Map();
1108
1010
  /** Whether a dirty-flush task is already scheduled. */
@@ -1141,6 +1043,11 @@ var GraphBuilderImpl = class {
1141
1043
  const removed = previous.filter((pid) => !ids.includes(pid));
1142
1044
  this._connectorPrevious.set(key, ids);
1143
1045
  this._connectorPreviousArgs.set(key, nodes);
1046
+ const currentInlineIds = collectAllInlineIds(nodes);
1047
+ const previousInlineIds = this._connectorPreviousInlineIds.get(key) ?? [];
1048
+ const staleInlineIds = previousInlineIds.filter((pid) => !currentInlineIds.includes(pid));
1049
+ this._connectorPreviousInlineIds.set(key, currentInlineIds);
1050
+ removeNodes(this._graph, staleInlineIds, true);
1144
1051
  removeEdges(this._graph, removed.map((target) => ({
1145
1052
  source: id,
1146
1053
  target,
@@ -1207,12 +1114,7 @@ var GraphBuilderImpl = class {
1207
1114
  id,
1208
1115
  relation: relation2,
1209
1116
  registry: getDebugName(this._registry)
1210
- }, {
1211
- F: __dxlog_file3,
1212
- L: 269,
1213
- S: this,
1214
- C: (f, a) => f(...a)
1215
- });
1117
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 136, S: this });
1216
1118
  this._expandRelation(id, relation2);
1217
1119
  if (relation2.kind === "child" && relation2.direction === "outbound") {
1218
1120
  expand(this._graph, id, "action");
@@ -1235,12 +1137,7 @@ var GraphBuilderImpl = class {
1235
1137
  id,
1236
1138
  relation: relation2,
1237
1139
  ids
1238
- }, {
1239
- F: __dxlog_file3,
1240
- L: 296,
1241
- S: this,
1242
- C: (f, a) => f(...a)
1243
- });
1140
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 160, S: this });
1244
1141
  this._dirtyConnectors.set(key, {
1245
1142
  nodes,
1246
1143
  previous
@@ -1254,12 +1151,7 @@ var GraphBuilderImpl = class {
1254
1151
  async _onInitialize(id) {
1255
1152
  log2("onInitialize", {
1256
1153
  id
1257
- }, {
1258
- F: __dxlog_file3,
1259
- L: 307,
1260
- S: this,
1261
- C: (f, a) => f(...a)
1262
- });
1154
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 176, S: this });
1263
1155
  const resolver = this._resolvers(id);
1264
1156
  const cancel = this._registry.subscribe(resolver, (node) => {
1265
1157
  const trigger = this._initialized[id];
@@ -1442,12 +1334,7 @@ var createExtensionRaw = (extension) => {
1442
1334
  id: getId("connector"),
1443
1335
  node,
1444
1336
  error
1445
- }, {
1446
- F: __dxlog_file3,
1447
- L: 609,
1448
- S: void 0,
1449
- C: (f, a) => f(...a)
1450
- });
1337
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 383, S: void 0 });
1451
1338
  return [];
1452
1339
  }
1453
1340
  }).pipe(Atom2.withLabel(`graph-builder:connector:${id}`)))
@@ -1468,12 +1355,7 @@ var createExtensionRaw = (extension) => {
1468
1355
  id: getId("actionGroups"),
1469
1356
  node,
1470
1357
  error
1471
- }, {
1472
- F: __dxlog_file3,
1473
- L: 630,
1474
- S: void 0,
1475
- C: (f, a) => f(...a)
1476
- });
1358
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 404, S: void 0 });
1477
1359
  return [];
1478
1360
  }
1479
1361
  }).pipe(Atom2.withLabel(`graph-builder:connector:actionGroups:${id}`)))
@@ -1493,12 +1375,7 @@ var createExtensionRaw = (extension) => {
1493
1375
  id: getId("actions"),
1494
1376
  node,
1495
1377
  error
1496
- }, {
1497
- F: __dxlog_file3,
1498
- L: 647,
1499
- S: void 0,
1500
- C: (f, a) => f(...a)
1501
- });
1378
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 424, S: void 0 });
1502
1379
  return [];
1503
1380
  }
1504
1381
  }).pipe(Atom2.withLabel(`graph-builder:connector:actions:${id}`)))
@@ -1510,12 +1387,7 @@ var runEffectSyncWithFallback = (effect, context2, extensionId, fallback) => {
1510
1387
  log2.warn("Extension failed", {
1511
1388
  extension: extensionId,
1512
1389
  error
1513
- }, {
1514
- F: __dxlog_file3,
1515
- L: 690,
1516
- S: void 0,
1517
- C: (f, a) => f(...a)
1518
- });
1390
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 441, S: void 0 });
1519
1391
  return Effect.succeed(fallback);
1520
1392
  })));
1521
1393
  };
@@ -1563,6 +1435,10 @@ var qualifyNodeArgs = (parentId) => (nodes) => nodes.map((node) => {
1563
1435
  nodes: node.nodes ? qualifyNodeArgs(qualified)(node.nodes) : void 0
1564
1436
  };
1565
1437
  });
1438
+ var collectAllInlineIds = (nodes) => nodes.flatMap((node) => node.nodes ? [
1439
+ ...node.nodes.map((child) => child.id),
1440
+ ...collectAllInlineIds(node.nodes)
1441
+ ] : []);
1566
1442
  var connectorKey = (id, relation2) => primaryKey(id, relationKey(relation2));
1567
1443
  var relationFromConnectorKey = (key) => {
1568
1444
  const [id, encodedRelation] = primaryParts(key);
@@ -1601,4 +1477,4 @@ export {
1601
1477
  flush,
1602
1478
  graph_builder_exports
1603
1479
  };
1604
- //# sourceMappingURL=chunk-W47H2NND.mjs.map
1480
+ //# sourceMappingURL=chunk-3T75MQOS.mjs.map