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