@dxos/app-graph 0.8.4-main.fd6878d → 0.8.4-main.fffef41
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.
- package/dist/lib/browser/index.mjs +112 -107
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +112 -107
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/graph-builder.d.ts +16 -16
- package/dist/types/src/graph-builder.d.ts.map +1 -1
- package/dist/types/src/graph.d.ts +19 -19
- package/dist/types/src/graph.d.ts.map +1 -1
- package/dist/types/src/stories/EchoGraph.stories.d.ts +8 -10
- package/dist/types/src/stories/EchoGraph.stories.d.ts.map +1 -1
- package/dist/types/src/testing.d.ts +3 -3
- package/dist/types/src/testing.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +31 -32
- package/src/graph-builder.test.ts +34 -33
- package/src/graph-builder.ts +50 -45
- package/src/graph.test.ts +3 -3
- package/src/graph.ts +115 -73
- package/src/signals-integration.test.ts +29 -28
- package/src/stories/EchoGraph.stories.tsx +34 -26
- package/src/stories/Tree.tsx +1 -1
- package/src/testing.ts +4 -4
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
2
|
|
|
3
3
|
// src/graph.ts
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
4
|
+
import { Atom, Registry } from "@effect-atom/atom-react";
|
|
5
|
+
import * as Function from "effect/Function";
|
|
6
|
+
import * as Option from "effect/Option";
|
|
7
|
+
import * as Record from "effect/Record";
|
|
6
8
|
import { Event, Trigger } from "@dxos/async";
|
|
7
9
|
import { todo } from "@dxos/debug";
|
|
8
10
|
import { invariant } from "@dxos/invariant";
|
|
@@ -14,7 +16,7 @@ var getGraph = (node) => {
|
|
|
14
16
|
const graph = node[graphSymbol];
|
|
15
17
|
invariant(graph, "Node is not associated with a graph.", {
|
|
16
18
|
F: __dxlog_file,
|
|
17
|
-
L:
|
|
19
|
+
L: 29,
|
|
18
20
|
S: void 0,
|
|
19
21
|
A: [
|
|
20
22
|
"graph",
|
|
@@ -48,16 +50,16 @@ var Graph = class {
|
|
|
48
50
|
]
|
|
49
51
|
]);
|
|
50
52
|
/** @internal */
|
|
51
|
-
_node =
|
|
53
|
+
_node = Atom.family((id) => {
|
|
52
54
|
const initial = Option.flatten(Record.get(this._initialNodes, id));
|
|
53
|
-
return
|
|
55
|
+
return Atom.make(initial).pipe(Atom.keepAlive, Atom.withLabel(`graph:node:${id}`));
|
|
54
56
|
});
|
|
55
|
-
_nodeOrThrow =
|
|
56
|
-
return
|
|
57
|
-
const node =
|
|
57
|
+
_nodeOrThrow = Atom.family((id) => {
|
|
58
|
+
return Atom.make((get2) => {
|
|
59
|
+
const node = get2(this._node(id));
|
|
58
60
|
invariant(Option.isSome(node), `Node not available: ${id}`, {
|
|
59
61
|
F: __dxlog_file,
|
|
60
|
-
L:
|
|
62
|
+
L: 267,
|
|
61
63
|
S: this,
|
|
62
64
|
A: [
|
|
63
65
|
"Option.isSome(node)",
|
|
@@ -67,33 +69,33 @@ var Graph = class {
|
|
|
67
69
|
return node.value;
|
|
68
70
|
});
|
|
69
71
|
});
|
|
70
|
-
_edges =
|
|
72
|
+
_edges = Atom.family((id) => {
|
|
71
73
|
const initial = Record.get(this._initialEdges, id).pipe(Option.getOrElse(() => ({
|
|
72
74
|
inbound: [],
|
|
73
75
|
outbound: []
|
|
74
76
|
})));
|
|
75
|
-
return
|
|
77
|
+
return Atom.make(initial).pipe(Atom.keepAlive, Atom.withLabel(`graph:edges:${id}`));
|
|
76
78
|
});
|
|
77
|
-
// NOTE: Currently the argument to the family needs to be referentially stable for the
|
|
78
|
-
// TODO(wittjosiah):
|
|
79
|
-
_connections =
|
|
80
|
-
return
|
|
79
|
+
// NOTE: Currently the argument to the family needs to be referentially stable for the atom to be referentially stable.
|
|
80
|
+
// TODO(wittjosiah): Atom feature request, support for something akin to `ComplexMap` to allow for complex arguments.
|
|
81
|
+
_connections = Atom.family((key) => {
|
|
82
|
+
return Atom.make((get2) => {
|
|
81
83
|
const [id, relation] = key.split("$");
|
|
82
|
-
const edges =
|
|
83
|
-
return edges[relation].map((id2) =>
|
|
84
|
-
}).pipe(
|
|
84
|
+
const edges = get2(this._edges(id));
|
|
85
|
+
return edges[relation].map((id2) => get2(this._node(id2))).filter(Option.isSome).map((o) => o.value);
|
|
86
|
+
}).pipe(Atom.withLabel(`graph:connections:${key}`));
|
|
85
87
|
});
|
|
86
|
-
_actions =
|
|
87
|
-
return
|
|
88
|
-
return
|
|
89
|
-
}).pipe(
|
|
88
|
+
_actions = Atom.family((id) => {
|
|
89
|
+
return Atom.make((get2) => {
|
|
90
|
+
return get2(this._connections(`${id}$outbound`)).filter((node) => node.type === ACTION_TYPE || node.type === ACTION_GROUP_TYPE);
|
|
91
|
+
}).pipe(Atom.withLabel(`graph:actions:${id}`));
|
|
90
92
|
});
|
|
91
|
-
_json =
|
|
92
|
-
return
|
|
93
|
+
_json = Atom.family((id) => {
|
|
94
|
+
return Atom.make((get2) => {
|
|
93
95
|
const toJSON = (node, seen = []) => {
|
|
94
|
-
const nodes =
|
|
96
|
+
const nodes = get2(this.connections(node.id));
|
|
95
97
|
const obj = {
|
|
96
|
-
id: node.id
|
|
98
|
+
id: node.id,
|
|
97
99
|
type: node.type
|
|
98
100
|
};
|
|
99
101
|
if (node.properties.label) {
|
|
@@ -110,9 +112,9 @@ var Graph = class {
|
|
|
110
112
|
}
|
|
111
113
|
return obj;
|
|
112
114
|
};
|
|
113
|
-
const root =
|
|
115
|
+
const root = get2(this.nodeOrThrow(id));
|
|
114
116
|
return toJSON(root);
|
|
115
|
-
}).pipe(
|
|
117
|
+
}).pipe(Atom.withLabel(`graph:json:${id}`));
|
|
116
118
|
});
|
|
117
119
|
constructor({ registry, nodes, edges, onInitialize, onExpand, onRemoveNode } = {}) {
|
|
118
120
|
this._registry = registry ?? Registry.make();
|
|
@@ -176,7 +178,7 @@ var Graph = class {
|
|
|
176
178
|
initialized
|
|
177
179
|
}, {
|
|
178
180
|
F: __dxlog_file,
|
|
179
|
-
L:
|
|
181
|
+
L: 399,
|
|
180
182
|
S: this,
|
|
181
183
|
C: (f, a) => f(...a)
|
|
182
184
|
});
|
|
@@ -193,7 +195,7 @@ var Graph = class {
|
|
|
193
195
|
expanded
|
|
194
196
|
}, {
|
|
195
197
|
F: __dxlog_file,
|
|
196
|
-
L:
|
|
198
|
+
L: 409,
|
|
197
199
|
S: this,
|
|
198
200
|
C: (f, a) => f(...a)
|
|
199
201
|
});
|
|
@@ -203,14 +205,14 @@ var Graph = class {
|
|
|
203
205
|
}
|
|
204
206
|
}
|
|
205
207
|
addNodes(nodes) {
|
|
206
|
-
|
|
208
|
+
Atom.batch(() => {
|
|
207
209
|
nodes.map((node) => this.addNode(node));
|
|
208
210
|
});
|
|
209
211
|
}
|
|
210
212
|
addNode({ nodes, edges, ...nodeArg }) {
|
|
211
213
|
const { id, type, data = null, properties = {} } = nodeArg;
|
|
212
|
-
const
|
|
213
|
-
const node = this._registry.get(
|
|
214
|
+
const nodeAtom = this._node(id);
|
|
215
|
+
const node = this._registry.get(nodeAtom);
|
|
214
216
|
Option.match(node, {
|
|
215
217
|
onSome: (node2) => {
|
|
216
218
|
const typeChanged = node2.type !== type;
|
|
@@ -223,7 +225,7 @@ var Graph = class {
|
|
|
223
225
|
propertiesChanged
|
|
224
226
|
}, {
|
|
225
227
|
F: __dxlog_file,
|
|
226
|
-
L:
|
|
228
|
+
L: 431,
|
|
227
229
|
S: this,
|
|
228
230
|
C: (f, a) => f(...a)
|
|
229
231
|
});
|
|
@@ -235,7 +237,7 @@ var Graph = class {
|
|
|
235
237
|
properties
|
|
236
238
|
}, {
|
|
237
239
|
F: __dxlog_file,
|
|
238
|
-
L:
|
|
240
|
+
L: 438,
|
|
239
241
|
S: this,
|
|
240
242
|
C: (f, a) => f(...a)
|
|
241
243
|
});
|
|
@@ -248,7 +250,7 @@ var Graph = class {
|
|
|
248
250
|
...properties
|
|
249
251
|
}
|
|
250
252
|
});
|
|
251
|
-
this._registry.set(
|
|
253
|
+
this._registry.set(nodeAtom, newNode);
|
|
252
254
|
this.onNodeChanged.emit({
|
|
253
255
|
id,
|
|
254
256
|
node: newNode
|
|
@@ -263,7 +265,7 @@ var Graph = class {
|
|
|
263
265
|
properties
|
|
264
266
|
}, {
|
|
265
267
|
F: __dxlog_file,
|
|
266
|
-
L:
|
|
268
|
+
L: 450,
|
|
267
269
|
S: this,
|
|
268
270
|
C: (f, a) => f(...a)
|
|
269
271
|
});
|
|
@@ -273,7 +275,7 @@ var Graph = class {
|
|
|
273
275
|
data,
|
|
274
276
|
properties
|
|
275
277
|
});
|
|
276
|
-
this._registry.set(
|
|
278
|
+
this._registry.set(nodeAtom, newNode);
|
|
277
279
|
this.onNodeChanged.emit({
|
|
278
280
|
id,
|
|
279
281
|
node: newNode
|
|
@@ -293,13 +295,13 @@ var Graph = class {
|
|
|
293
295
|
}
|
|
294
296
|
}
|
|
295
297
|
removeNodes(ids, edges = false) {
|
|
296
|
-
|
|
298
|
+
Atom.batch(() => {
|
|
297
299
|
ids.map((id) => this.removeNode(id, edges));
|
|
298
300
|
});
|
|
299
301
|
}
|
|
300
302
|
removeNode(id, edges = false) {
|
|
301
|
-
const
|
|
302
|
-
this._registry.set(
|
|
303
|
+
const nodeAtom = this._node(id);
|
|
304
|
+
this._registry.set(nodeAtom, Option.none());
|
|
303
305
|
this.onNodeChanged.emit({
|
|
304
306
|
id,
|
|
305
307
|
node: Option.none()
|
|
@@ -321,24 +323,24 @@ var Graph = class {
|
|
|
321
323
|
this._onRemoveNode?.(id);
|
|
322
324
|
}
|
|
323
325
|
addEdges(edges) {
|
|
324
|
-
|
|
326
|
+
Atom.batch(() => {
|
|
325
327
|
edges.map((edge) => this.addEdge(edge));
|
|
326
328
|
});
|
|
327
329
|
}
|
|
328
330
|
addEdge(edgeArg) {
|
|
329
|
-
const
|
|
330
|
-
const source = this._registry.get(
|
|
331
|
+
const sourceAtom = this._edges(edgeArg.source);
|
|
332
|
+
const source = this._registry.get(sourceAtom);
|
|
331
333
|
if (!source.outbound.includes(edgeArg.target)) {
|
|
332
334
|
log("add outbound edge", {
|
|
333
335
|
source: edgeArg.source,
|
|
334
336
|
target: edgeArg.target
|
|
335
337
|
}, {
|
|
336
338
|
F: __dxlog_file,
|
|
337
|
-
L:
|
|
339
|
+
L: 505,
|
|
338
340
|
S: this,
|
|
339
341
|
C: (f, a) => f(...a)
|
|
340
342
|
});
|
|
341
|
-
this._registry.set(
|
|
343
|
+
this._registry.set(sourceAtom, {
|
|
342
344
|
inbound: source.inbound,
|
|
343
345
|
outbound: [
|
|
344
346
|
...source.outbound,
|
|
@@ -346,19 +348,19 @@ var Graph = class {
|
|
|
346
348
|
]
|
|
347
349
|
});
|
|
348
350
|
}
|
|
349
|
-
const
|
|
350
|
-
const target = this._registry.get(
|
|
351
|
+
const targetAtom = this._edges(edgeArg.target);
|
|
352
|
+
const target = this._registry.get(targetAtom);
|
|
351
353
|
if (!target.inbound.includes(edgeArg.source)) {
|
|
352
354
|
log("add inbound edge", {
|
|
353
355
|
source: edgeArg.source,
|
|
354
356
|
target: edgeArg.target
|
|
355
357
|
}, {
|
|
356
358
|
F: __dxlog_file,
|
|
357
|
-
L:
|
|
359
|
+
L: 518,
|
|
358
360
|
S: this,
|
|
359
361
|
C: (f, a) => f(...a)
|
|
360
362
|
});
|
|
361
|
-
this._registry.set(
|
|
363
|
+
this._registry.set(targetAtom, {
|
|
362
364
|
inbound: [
|
|
363
365
|
...target.inbound,
|
|
364
366
|
edgeArg.source
|
|
@@ -368,30 +370,30 @@ var Graph = class {
|
|
|
368
370
|
}
|
|
369
371
|
}
|
|
370
372
|
removeEdges(edges, removeOrphans = false) {
|
|
371
|
-
|
|
373
|
+
Atom.batch(() => {
|
|
372
374
|
edges.map((edge) => this.removeEdge(edge, removeOrphans));
|
|
373
375
|
});
|
|
374
376
|
}
|
|
375
377
|
removeEdge(edgeArg, removeOrphans = false) {
|
|
376
|
-
const
|
|
377
|
-
const source = this._registry.get(
|
|
378
|
+
const sourceAtom = this._edges(edgeArg.source);
|
|
379
|
+
const source = this._registry.get(sourceAtom);
|
|
378
380
|
if (source.outbound.includes(edgeArg.target)) {
|
|
379
|
-
this._registry.set(
|
|
381
|
+
this._registry.set(sourceAtom, {
|
|
380
382
|
inbound: source.inbound,
|
|
381
383
|
outbound: source.outbound.filter((id) => id !== edgeArg.target)
|
|
382
384
|
});
|
|
383
385
|
}
|
|
384
|
-
const
|
|
385
|
-
const target = this._registry.get(
|
|
386
|
+
const targetAtom = this._edges(edgeArg.target);
|
|
387
|
+
const target = this._registry.get(targetAtom);
|
|
386
388
|
if (target.inbound.includes(edgeArg.source)) {
|
|
387
|
-
this._registry.set(
|
|
389
|
+
this._registry.set(targetAtom, {
|
|
388
390
|
inbound: target.inbound.filter((id) => id !== edgeArg.source),
|
|
389
391
|
outbound: target.outbound
|
|
390
392
|
});
|
|
391
393
|
}
|
|
392
394
|
if (removeOrphans) {
|
|
393
|
-
const source2 = this._registry.get(
|
|
394
|
-
const target2 = this._registry.get(
|
|
395
|
+
const source2 = this._registry.get(sourceAtom);
|
|
396
|
+
const target2 = this._registry.get(targetAtom);
|
|
395
397
|
if (source2.outbound.length === 0 && source2.inbound.length === 0 && edgeArg.source !== ROOT_ID) {
|
|
396
398
|
this.removeNodes([
|
|
397
399
|
edgeArg.source
|
|
@@ -405,15 +407,15 @@ var Graph = class {
|
|
|
405
407
|
}
|
|
406
408
|
}
|
|
407
409
|
sortEdges(id, relation, order) {
|
|
408
|
-
const
|
|
409
|
-
const edges = this._registry.get(
|
|
410
|
+
const edgesAtom = this._edges(id);
|
|
411
|
+
const edges = this._registry.get(edgesAtom);
|
|
410
412
|
const unsorted = edges[relation].filter((id2) => !order.includes(id2)) ?? [];
|
|
411
413
|
const sorted = order.filter((id2) => edges[relation].includes(id2)) ?? [];
|
|
412
414
|
edges[relation].splice(0, edges[relation].length, ...[
|
|
413
415
|
...sorted,
|
|
414
416
|
...unsorted
|
|
415
417
|
]);
|
|
416
|
-
this._registry.set(
|
|
418
|
+
this._registry.set(edgesAtom, edges);
|
|
417
419
|
}
|
|
418
420
|
traverse({ visitor, source = ROOT_ID, relation = "outbound" }, path = []) {
|
|
419
421
|
if (path.includes(source)) {
|
|
@@ -437,7 +439,7 @@ var Graph = class {
|
|
|
437
439
|
]));
|
|
438
440
|
}
|
|
439
441
|
getPath({ source = "root", target }) {
|
|
440
|
-
return pipe(this.getNode(source), Option.flatMap((node) => {
|
|
442
|
+
return Function.pipe(this.getNode(source), Option.flatMap((node) => {
|
|
441
443
|
let found = Option.none();
|
|
442
444
|
this.traverse({
|
|
443
445
|
source: node.id,
|
|
@@ -481,9 +483,12 @@ var Graph = class {
|
|
|
481
483
|
};
|
|
482
484
|
|
|
483
485
|
// src/graph-builder.ts
|
|
484
|
-
import {
|
|
486
|
+
import { Atom as Atom2, Registry as Registry2 } from "@effect-atom/atom-react";
|
|
485
487
|
import { effect } from "@preact/signals-core";
|
|
486
|
-
import
|
|
488
|
+
import * as Array from "effect/Array";
|
|
489
|
+
import * as Function2 from "effect/Function";
|
|
490
|
+
import * as Option2 from "effect/Option";
|
|
491
|
+
import * as Record2 from "effect/Record";
|
|
487
492
|
import { log as log2 } from "@dxos/log";
|
|
488
493
|
import { byPosition, getDebugName, isNode, isNonNullable as isNonNullable2 } from "@dxos/util";
|
|
489
494
|
|
|
@@ -499,10 +504,10 @@ var __dxlog_file2 = "/__w/dxos/dxos/packages/sdk/app-graph/src/graph-builder.ts"
|
|
|
499
504
|
var createExtension = (extension) => {
|
|
500
505
|
const { id, position = "static", relation = "outbound", resolver: _resolver, connector: _connector, actions: _actions, actionGroups: _actionGroups } = extension;
|
|
501
506
|
const getId = (key) => `${id}/${key}`;
|
|
502
|
-
const resolver = _resolver &&
|
|
503
|
-
const connector = _connector &&
|
|
504
|
-
const actionGroups = _actionGroups &&
|
|
505
|
-
const actions = _actions &&
|
|
507
|
+
const resolver = _resolver && Atom2.family((id2) => _resolver(id2).pipe(Atom2.withLabel(`graph-builder:_resolver:${id2}`)));
|
|
508
|
+
const connector = _connector && Atom2.family((node) => _connector(node).pipe(Atom2.withLabel(`graph-builder:_connector:${id}`)));
|
|
509
|
+
const actionGroups = _actionGroups && Atom2.family((node) => _actionGroups(node).pipe(Atom2.withLabel(`graph-builder:_actionGroups:${id}`)));
|
|
510
|
+
const actions = _actions && Atom2.family((node) => _actions(node).pipe(Atom2.withLabel(`graph-builder:_actions:${id}`)));
|
|
506
511
|
return [
|
|
507
512
|
resolver ? {
|
|
508
513
|
id: getId("resolver"),
|
|
@@ -513,30 +518,30 @@ var createExtension = (extension) => {
|
|
|
513
518
|
id: getId("connector"),
|
|
514
519
|
position,
|
|
515
520
|
relation,
|
|
516
|
-
connector:
|
|
521
|
+
connector: Atom2.family((node) => Atom2.make((get2) => {
|
|
517
522
|
try {
|
|
518
|
-
return
|
|
523
|
+
return get2(connector(node));
|
|
519
524
|
} catch {
|
|
520
525
|
log2.warn("Error in connector", {
|
|
521
526
|
id: getId("connector"),
|
|
522
527
|
node
|
|
523
528
|
}, {
|
|
524
529
|
F: __dxlog_file2,
|
|
525
|
-
L:
|
|
530
|
+
L: 114,
|
|
526
531
|
S: void 0,
|
|
527
532
|
C: (f, a) => f(...a)
|
|
528
533
|
});
|
|
529
534
|
return [];
|
|
530
535
|
}
|
|
531
|
-
}).pipe(
|
|
536
|
+
}).pipe(Atom2.withLabel(`graph-builder:connector:${id}`)))
|
|
532
537
|
} : void 0,
|
|
533
538
|
actionGroups ? {
|
|
534
539
|
id: getId("actionGroups"),
|
|
535
540
|
position,
|
|
536
541
|
relation: "outbound",
|
|
537
|
-
connector:
|
|
542
|
+
connector: Atom2.family((node) => Atom2.make((get2) => {
|
|
538
543
|
try {
|
|
539
|
-
return
|
|
544
|
+
return get2(actionGroups(node)).map((arg) => ({
|
|
540
545
|
...arg,
|
|
541
546
|
data: actionGroupSymbol,
|
|
542
547
|
type: ACTION_GROUP_TYPE
|
|
@@ -547,21 +552,21 @@ var createExtension = (extension) => {
|
|
|
547
552
|
node
|
|
548
553
|
}, {
|
|
549
554
|
F: __dxlog_file2,
|
|
550
|
-
L:
|
|
555
|
+
L: 135,
|
|
551
556
|
S: void 0,
|
|
552
557
|
C: (f, a) => f(...a)
|
|
553
558
|
});
|
|
554
559
|
return [];
|
|
555
560
|
}
|
|
556
|
-
}).pipe(
|
|
561
|
+
}).pipe(Atom2.withLabel(`graph-builder:connector:actionGroups:${id}`)))
|
|
557
562
|
} : void 0,
|
|
558
563
|
actions ? {
|
|
559
564
|
id: getId("actions"),
|
|
560
565
|
position,
|
|
561
566
|
relation: "outbound",
|
|
562
|
-
connector:
|
|
567
|
+
connector: Atom2.family((node) => Atom2.make((get2) => {
|
|
563
568
|
try {
|
|
564
|
-
return
|
|
569
|
+
return get2(actions(node)).map((arg) => ({
|
|
565
570
|
...arg,
|
|
566
571
|
type: ACTION_TYPE
|
|
567
572
|
}));
|
|
@@ -571,13 +576,13 @@ var createExtension = (extension) => {
|
|
|
571
576
|
node
|
|
572
577
|
}, {
|
|
573
578
|
F: __dxlog_file2,
|
|
574
|
-
L:
|
|
579
|
+
L: 152,
|
|
575
580
|
S: void 0,
|
|
576
581
|
C: (f, a) => f(...a)
|
|
577
582
|
});
|
|
578
583
|
return [];
|
|
579
584
|
}
|
|
580
|
-
}).pipe(
|
|
585
|
+
}).pipe(Atom2.withLabel(`graph-builder:connector:actions:${id}`)))
|
|
581
586
|
} : void 0
|
|
582
587
|
].filter(isNonNullable2);
|
|
583
588
|
};
|
|
@@ -597,7 +602,7 @@ var flattenExtensions = (extension, acc = []) => {
|
|
|
597
602
|
var GraphBuilder = class _GraphBuilder {
|
|
598
603
|
// TODO(wittjosiah): Use Context.
|
|
599
604
|
_subscriptions = /* @__PURE__ */ new Map();
|
|
600
|
-
_extensions =
|
|
605
|
+
_extensions = Atom2.make(Record2.empty()).pipe(Atom2.keepAlive, Atom2.withLabel("graph-builder:extensions"));
|
|
601
606
|
_initialized = {};
|
|
602
607
|
_registry;
|
|
603
608
|
_graph;
|
|
@@ -680,26 +685,26 @@ var GraphBuilder = class _GraphBuilder {
|
|
|
680
685
|
this._subscriptions.forEach((unsubscribe) => unsubscribe());
|
|
681
686
|
this._subscriptions.clear();
|
|
682
687
|
}
|
|
683
|
-
_resolvers =
|
|
684
|
-
return
|
|
685
|
-
return
|
|
688
|
+
_resolvers = Atom2.family((id) => {
|
|
689
|
+
return Atom2.make((get2) => {
|
|
690
|
+
return Function2.pipe(get2(this._extensions), Record2.values, Array.sortBy(byPosition), Array.map(({ resolver }) => resolver), Array.filter(isNonNullable2), Array.map((resolver) => get2(resolver(id))), Array.filter(isNonNullable2), Array.head);
|
|
686
691
|
});
|
|
687
692
|
});
|
|
688
|
-
_connectors =
|
|
689
|
-
return
|
|
693
|
+
_connectors = Atom2.family((key) => {
|
|
694
|
+
return Atom2.make((get2) => {
|
|
690
695
|
const [id, relation] = key.split("+");
|
|
691
696
|
const node = this._graph.node(id);
|
|
692
|
-
return
|
|
693
|
-
|
|
697
|
+
return Function2.pipe(
|
|
698
|
+
get2(this._extensions),
|
|
694
699
|
Record2.values,
|
|
695
700
|
// TODO(wittjosiah): Sort on write rather than read.
|
|
696
701
|
Array.sortBy(byPosition),
|
|
697
702
|
Array.filter(({ relation: _relation = "outbound" }) => _relation === relation),
|
|
698
703
|
Array.map(({ connector }) => connector?.(node)),
|
|
699
704
|
Array.filter(isNonNullable2),
|
|
700
|
-
Array.flatMap((result) =>
|
|
705
|
+
Array.flatMap((result) => get2(result))
|
|
701
706
|
);
|
|
702
|
-
}).pipe(
|
|
707
|
+
}).pipe(Atom2.withLabel(`graph-builder:connectors:${key}`));
|
|
703
708
|
});
|
|
704
709
|
_onExpand(id, relation) {
|
|
705
710
|
log2("onExpand", {
|
|
@@ -708,7 +713,7 @@ var GraphBuilder = class _GraphBuilder {
|
|
|
708
713
|
registry: getDebugName(this._registry)
|
|
709
714
|
}, {
|
|
710
715
|
F: __dxlog_file2,
|
|
711
|
-
L:
|
|
716
|
+
L: 329,
|
|
712
717
|
S: this,
|
|
713
718
|
C: (f, a) => f(...a)
|
|
714
719
|
});
|
|
@@ -725,12 +730,12 @@ var GraphBuilder = class _GraphBuilder {
|
|
|
725
730
|
removed
|
|
726
731
|
}, {
|
|
727
732
|
F: __dxlog_file2,
|
|
728
|
-
L:
|
|
733
|
+
L: 340,
|
|
729
734
|
S: this,
|
|
730
735
|
C: (f, a) => f(...a)
|
|
731
736
|
});
|
|
732
737
|
const update = () => {
|
|
733
|
-
|
|
738
|
+
Atom2.batch(() => {
|
|
734
739
|
this._graph.removeEdges(removed.map((target) => ({
|
|
735
740
|
source: id,
|
|
736
741
|
target
|
|
@@ -762,7 +767,7 @@ var GraphBuilder = class _GraphBuilder {
|
|
|
762
767
|
id
|
|
763
768
|
}, {
|
|
764
769
|
F: __dxlog_file2,
|
|
765
|
-
L:
|
|
770
|
+
L: 377,
|
|
766
771
|
S: this,
|
|
767
772
|
C: (f, a) => f(...a)
|
|
768
773
|
});
|
|
@@ -793,23 +798,23 @@ var GraphBuilder = class _GraphBuilder {
|
|
|
793
798
|
this._subscriptions.delete(id);
|
|
794
799
|
}
|
|
795
800
|
};
|
|
796
|
-
var
|
|
797
|
-
return
|
|
801
|
+
var atomFromSignal = (cb) => {
|
|
802
|
+
return Atom2.make((get2) => {
|
|
798
803
|
const dispose = effect(() => {
|
|
799
|
-
|
|
804
|
+
get2.setSelf(cb());
|
|
800
805
|
});
|
|
801
|
-
|
|
806
|
+
get2.addFinalizer(() => dispose());
|
|
802
807
|
return cb();
|
|
803
808
|
});
|
|
804
809
|
};
|
|
805
|
-
var observableFamily =
|
|
806
|
-
return
|
|
807
|
-
const subscription = observable.subscribe((value) =>
|
|
808
|
-
|
|
810
|
+
var observableFamily = Atom2.family((observable) => {
|
|
811
|
+
return Atom2.make((get2) => {
|
|
812
|
+
const subscription = observable.subscribe((value) => get2.setSelf(value));
|
|
813
|
+
get2.addFinalizer(() => subscription.unsubscribe());
|
|
809
814
|
return observable.get();
|
|
810
815
|
});
|
|
811
816
|
});
|
|
812
|
-
var
|
|
817
|
+
var atomFromObservable = (observable) => {
|
|
813
818
|
return observableFamily(observable);
|
|
814
819
|
};
|
|
815
820
|
export {
|
|
@@ -820,14 +825,14 @@ export {
|
|
|
820
825
|
ROOT_ID,
|
|
821
826
|
ROOT_TYPE,
|
|
822
827
|
actionGroupSymbol,
|
|
828
|
+
atomFromObservable,
|
|
829
|
+
atomFromSignal,
|
|
823
830
|
createExtension,
|
|
824
831
|
flattenExtensions,
|
|
825
832
|
getGraph,
|
|
826
833
|
isAction,
|
|
827
834
|
isActionGroup,
|
|
828
835
|
isActionLike,
|
|
829
|
-
isGraphNode
|
|
830
|
-
rxFromObservable,
|
|
831
|
-
rxFromSignal
|
|
836
|
+
isGraphNode
|
|
832
837
|
};
|
|
833
838
|
//# sourceMappingURL=index.mjs.map
|