@dxos/app-graph 0.8.4-main.406dc2a → 0.8.4-main.548089c
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 +173 -195
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +173 -195
- 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 +13 -13
- package/dist/types/src/graph-builder.d.ts.map +1 -1
- package/dist/types/src/graph.d.ts +18 -18
- package/dist/types/src/graph.d.ts.map +1 -1
- package/dist/types/src/stories/EchoGraph.stories.d.ts.map +1 -1
- package/dist/types/src/testing.d.ts +2 -2
- package/dist/types/src/testing.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +22 -22
- package/src/graph-builder.test.ts +26 -26
- package/src/graph-builder.ts +42 -40
- package/src/graph.test.ts +2 -2
- package/src/graph.ts +89 -49
- package/src/signals-integration.test.ts +4 -4
- package/src/stories/EchoGraph.stories.tsx +15 -8
- package/src/stories/Tree.tsx +1 -1
- package/src/testing.ts +3 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
2
|
|
|
3
3
|
// src/graph.ts
|
|
4
|
-
import {
|
|
4
|
+
import { Atom, Registry } from "@effect-atom/atom-react";
|
|
5
5
|
import * as Function from "effect/Function";
|
|
6
6
|
import * as Option from "effect/Option";
|
|
7
7
|
import * as Record from "effect/Record";
|
|
@@ -10,26 +10,13 @@ import { todo } from "@dxos/debug";
|
|
|
10
10
|
import { invariant } from "@dxos/invariant";
|
|
11
11
|
import { log } from "@dxos/log";
|
|
12
12
|
import { isNonNullable } from "@dxos/util";
|
|
13
|
-
function _define_property(obj, key, value) {
|
|
14
|
-
if (key in obj) {
|
|
15
|
-
Object.defineProperty(obj, key, {
|
|
16
|
-
value,
|
|
17
|
-
enumerable: true,
|
|
18
|
-
configurable: true,
|
|
19
|
-
writable: true
|
|
20
|
-
});
|
|
21
|
-
} else {
|
|
22
|
-
obj[key] = value;
|
|
23
|
-
}
|
|
24
|
-
return obj;
|
|
25
|
-
}
|
|
26
13
|
var __dxlog_file = "/__w/dxos/dxos/packages/sdk/app-graph/src/graph.ts";
|
|
27
14
|
var graphSymbol = Symbol("graph");
|
|
28
15
|
var getGraph = (node) => {
|
|
29
16
|
const graph = node[graphSymbol];
|
|
30
17
|
invariant(graph, "Node is not associated with a graph.", {
|
|
31
18
|
F: __dxlog_file,
|
|
32
|
-
L:
|
|
19
|
+
L: 29,
|
|
33
20
|
S: void 0,
|
|
34
21
|
A: [
|
|
35
22
|
"graph",
|
|
@@ -43,6 +30,108 @@ var ROOT_TYPE = "dxos.org/type/GraphRoot";
|
|
|
43
30
|
var ACTION_TYPE = "dxos.org/type/GraphAction";
|
|
44
31
|
var ACTION_GROUP_TYPE = "dxos.org/type/GraphActionGroup";
|
|
45
32
|
var Graph = class {
|
|
33
|
+
onNodeChanged = new Event();
|
|
34
|
+
_onExpand;
|
|
35
|
+
_onInitialize;
|
|
36
|
+
_onRemoveNode;
|
|
37
|
+
_registry;
|
|
38
|
+
_expanded = Record.empty();
|
|
39
|
+
_initialized = Record.empty();
|
|
40
|
+
_initialEdges = Record.empty();
|
|
41
|
+
_initialNodes = Record.fromEntries([
|
|
42
|
+
[
|
|
43
|
+
ROOT_ID,
|
|
44
|
+
this._constructNode({
|
|
45
|
+
id: ROOT_ID,
|
|
46
|
+
type: ROOT_TYPE,
|
|
47
|
+
data: null,
|
|
48
|
+
properties: {}
|
|
49
|
+
})
|
|
50
|
+
]
|
|
51
|
+
]);
|
|
52
|
+
/** @internal */
|
|
53
|
+
_node = Atom.family((id) => {
|
|
54
|
+
const initial = Option.flatten(Record.get(this._initialNodes, id));
|
|
55
|
+
return Atom.make(initial).pipe(Atom.keepAlive, Atom.withLabel(`graph:node:${id}`));
|
|
56
|
+
});
|
|
57
|
+
_nodeOrThrow = Atom.family((id) => {
|
|
58
|
+
return Atom.make((get2) => {
|
|
59
|
+
const node = get2(this._node(id));
|
|
60
|
+
invariant(Option.isSome(node), `Node not available: ${id}`, {
|
|
61
|
+
F: __dxlog_file,
|
|
62
|
+
L: 267,
|
|
63
|
+
S: this,
|
|
64
|
+
A: [
|
|
65
|
+
"Option.isSome(node)",
|
|
66
|
+
"`Node not available: ${id}`"
|
|
67
|
+
]
|
|
68
|
+
});
|
|
69
|
+
return node.value;
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
_edges = Atom.family((id) => {
|
|
73
|
+
const initial = Record.get(this._initialEdges, id).pipe(Option.getOrElse(() => ({
|
|
74
|
+
inbound: [],
|
|
75
|
+
outbound: []
|
|
76
|
+
})));
|
|
77
|
+
return Atom.make(initial).pipe(Atom.keepAlive, Atom.withLabel(`graph:edges:${id}`));
|
|
78
|
+
});
|
|
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) => {
|
|
83
|
+
const [id, relation] = key.split("$");
|
|
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}`));
|
|
87
|
+
});
|
|
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}`));
|
|
92
|
+
});
|
|
93
|
+
_json = Atom.family((id) => {
|
|
94
|
+
return Atom.make((get2) => {
|
|
95
|
+
const toJSON = (node, seen = []) => {
|
|
96
|
+
const nodes = get2(this.connections(node.id));
|
|
97
|
+
const obj = {
|
|
98
|
+
id: node.id,
|
|
99
|
+
type: node.type
|
|
100
|
+
};
|
|
101
|
+
if (node.properties.label) {
|
|
102
|
+
obj.label = node.properties.label;
|
|
103
|
+
}
|
|
104
|
+
if (nodes.length) {
|
|
105
|
+
obj.nodes = nodes.map((n) => {
|
|
106
|
+
const nextSeen = [
|
|
107
|
+
...seen,
|
|
108
|
+
node.id
|
|
109
|
+
];
|
|
110
|
+
return nextSeen.includes(n.id) ? void 0 : toJSON(n, nextSeen);
|
|
111
|
+
}).filter(isNonNullable);
|
|
112
|
+
}
|
|
113
|
+
return obj;
|
|
114
|
+
};
|
|
115
|
+
const root = get2(this.nodeOrThrow(id));
|
|
116
|
+
return toJSON(root);
|
|
117
|
+
}).pipe(Atom.withLabel(`graph:json:${id}`));
|
|
118
|
+
});
|
|
119
|
+
constructor({ registry, nodes, edges, onInitialize, onExpand, onRemoveNode } = {}) {
|
|
120
|
+
this._registry = registry ?? Registry.make();
|
|
121
|
+
this._onInitialize = onInitialize;
|
|
122
|
+
this._onExpand = onExpand;
|
|
123
|
+
this._onRemoveNode = onRemoveNode;
|
|
124
|
+
if (nodes) {
|
|
125
|
+
nodes.forEach((node) => {
|
|
126
|
+
Record.set(this._initialNodes, node.id, this._constructNode(node));
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
if (edges) {
|
|
130
|
+
Object.entries(edges).forEach(([source, edges2]) => {
|
|
131
|
+
Record.set(this._initialEdges, source, edges2);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
46
135
|
toJSON(id = ROOT_ID) {
|
|
47
136
|
return this._registry.get(this._json(id));
|
|
48
137
|
}
|
|
@@ -89,7 +178,7 @@ var Graph = class {
|
|
|
89
178
|
initialized
|
|
90
179
|
}, {
|
|
91
180
|
F: __dxlog_file,
|
|
92
|
-
L:
|
|
181
|
+
L: 399,
|
|
93
182
|
S: this,
|
|
94
183
|
C: (f, a) => f(...a)
|
|
95
184
|
});
|
|
@@ -106,7 +195,7 @@ var Graph = class {
|
|
|
106
195
|
expanded
|
|
107
196
|
}, {
|
|
108
197
|
F: __dxlog_file,
|
|
109
|
-
L:
|
|
198
|
+
L: 409,
|
|
110
199
|
S: this,
|
|
111
200
|
C: (f, a) => f(...a)
|
|
112
201
|
});
|
|
@@ -116,7 +205,7 @@ var Graph = class {
|
|
|
116
205
|
}
|
|
117
206
|
}
|
|
118
207
|
addNodes(nodes) {
|
|
119
|
-
|
|
208
|
+
Atom.batch(() => {
|
|
120
209
|
nodes.map((node) => this.addNode(node));
|
|
121
210
|
});
|
|
122
211
|
}
|
|
@@ -136,7 +225,7 @@ var Graph = class {
|
|
|
136
225
|
propertiesChanged
|
|
137
226
|
}, {
|
|
138
227
|
F: __dxlog_file,
|
|
139
|
-
L:
|
|
228
|
+
L: 431,
|
|
140
229
|
S: this,
|
|
141
230
|
C: (f, a) => f(...a)
|
|
142
231
|
});
|
|
@@ -148,7 +237,7 @@ var Graph = class {
|
|
|
148
237
|
properties
|
|
149
238
|
}, {
|
|
150
239
|
F: __dxlog_file,
|
|
151
|
-
L:
|
|
240
|
+
L: 438,
|
|
152
241
|
S: this,
|
|
153
242
|
C: (f, a) => f(...a)
|
|
154
243
|
});
|
|
@@ -176,7 +265,7 @@ var Graph = class {
|
|
|
176
265
|
properties
|
|
177
266
|
}, {
|
|
178
267
|
F: __dxlog_file,
|
|
179
|
-
L:
|
|
268
|
+
L: 450,
|
|
180
269
|
S: this,
|
|
181
270
|
C: (f, a) => f(...a)
|
|
182
271
|
});
|
|
@@ -206,7 +295,7 @@ var Graph = class {
|
|
|
206
295
|
}
|
|
207
296
|
}
|
|
208
297
|
removeNodes(ids, edges = false) {
|
|
209
|
-
|
|
298
|
+
Atom.batch(() => {
|
|
210
299
|
ids.map((id) => this.removeNode(id, edges));
|
|
211
300
|
});
|
|
212
301
|
}
|
|
@@ -234,7 +323,7 @@ var Graph = class {
|
|
|
234
323
|
this._onRemoveNode?.(id);
|
|
235
324
|
}
|
|
236
325
|
addEdges(edges) {
|
|
237
|
-
|
|
326
|
+
Atom.batch(() => {
|
|
238
327
|
edges.map((edge) => this.addEdge(edge));
|
|
239
328
|
});
|
|
240
329
|
}
|
|
@@ -247,7 +336,7 @@ var Graph = class {
|
|
|
247
336
|
target: edgeArg.target
|
|
248
337
|
}, {
|
|
249
338
|
F: __dxlog_file,
|
|
250
|
-
L:
|
|
339
|
+
L: 505,
|
|
251
340
|
S: this,
|
|
252
341
|
C: (f, a) => f(...a)
|
|
253
342
|
});
|
|
@@ -267,7 +356,7 @@ var Graph = class {
|
|
|
267
356
|
target: edgeArg.target
|
|
268
357
|
}, {
|
|
269
358
|
F: __dxlog_file,
|
|
270
|
-
L:
|
|
359
|
+
L: 518,
|
|
271
360
|
S: this,
|
|
272
361
|
C: (f, a) => f(...a)
|
|
273
362
|
});
|
|
@@ -281,7 +370,7 @@ var Graph = class {
|
|
|
281
370
|
}
|
|
282
371
|
}
|
|
283
372
|
removeEdges(edges, removeOrphans = false) {
|
|
284
|
-
|
|
373
|
+
Atom.batch(() => {
|
|
285
374
|
edges.map((edge) => this.removeEdge(edge, removeOrphans));
|
|
286
375
|
});
|
|
287
376
|
}
|
|
@@ -391,109 +480,10 @@ var Graph = class {
|
|
|
391
480
|
...node
|
|
392
481
|
});
|
|
393
482
|
}
|
|
394
|
-
constructor({ registry, nodes, edges, onInitialize, onExpand, onRemoveNode } = {}) {
|
|
395
|
-
_define_property(this, "onNodeChanged", new Event());
|
|
396
|
-
_define_property(this, "_onExpand", void 0);
|
|
397
|
-
_define_property(this, "_onInitialize", void 0);
|
|
398
|
-
_define_property(this, "_onRemoveNode", void 0);
|
|
399
|
-
_define_property(this, "_registry", void 0);
|
|
400
|
-
_define_property(this, "_expanded", Record.empty());
|
|
401
|
-
_define_property(this, "_initialized", Record.empty());
|
|
402
|
-
_define_property(this, "_initialEdges", Record.empty());
|
|
403
|
-
_define_property(this, "_initialNodes", Record.fromEntries([
|
|
404
|
-
[
|
|
405
|
-
ROOT_ID,
|
|
406
|
-
this._constructNode({
|
|
407
|
-
id: ROOT_ID,
|
|
408
|
-
type: ROOT_TYPE,
|
|
409
|
-
data: null,
|
|
410
|
-
properties: {}
|
|
411
|
-
})
|
|
412
|
-
]
|
|
413
|
-
]));
|
|
414
|
-
_define_property(this, "_node", Rx.family((id) => {
|
|
415
|
-
const initial = Option.flatten(Record.get(this._initialNodes, id));
|
|
416
|
-
return Rx.make(initial).pipe(Rx.keepAlive, Rx.withLabel(`graph:node:${id}`));
|
|
417
|
-
}));
|
|
418
|
-
_define_property(this, "_nodeOrThrow", Rx.family((id) => {
|
|
419
|
-
return Rx.make((get2) => {
|
|
420
|
-
const node = get2(this._node(id));
|
|
421
|
-
invariant(Option.isSome(node), `Node not available: ${id}`, {
|
|
422
|
-
F: __dxlog_file,
|
|
423
|
-
L: 254,
|
|
424
|
-
S: this,
|
|
425
|
-
A: [
|
|
426
|
-
"Option.isSome(node)",
|
|
427
|
-
"`Node not available: ${id}`"
|
|
428
|
-
]
|
|
429
|
-
});
|
|
430
|
-
return node.value;
|
|
431
|
-
});
|
|
432
|
-
}));
|
|
433
|
-
_define_property(this, "_edges", Rx.family((id) => {
|
|
434
|
-
const initial = Record.get(this._initialEdges, id).pipe(Option.getOrElse(() => ({
|
|
435
|
-
inbound: [],
|
|
436
|
-
outbound: []
|
|
437
|
-
})));
|
|
438
|
-
return Rx.make(initial).pipe(Rx.keepAlive, Rx.withLabel(`graph:edges:${id}`));
|
|
439
|
-
}));
|
|
440
|
-
_define_property(this, "_connections", Rx.family((key) => {
|
|
441
|
-
return Rx.make((get2) => {
|
|
442
|
-
const [id, relation] = key.split("$");
|
|
443
|
-
const edges2 = get2(this._edges(id));
|
|
444
|
-
return edges2[relation].map((id2) => get2(this._node(id2))).filter(Option.isSome).map((o) => o.value);
|
|
445
|
-
}).pipe(Rx.withLabel(`graph:connections:${key}`));
|
|
446
|
-
}));
|
|
447
|
-
_define_property(this, "_actions", Rx.family((id) => {
|
|
448
|
-
return Rx.make((get2) => {
|
|
449
|
-
return get2(this._connections(`${id}$outbound`)).filter((node) => node.type === ACTION_TYPE || node.type === ACTION_GROUP_TYPE);
|
|
450
|
-
}).pipe(Rx.withLabel(`graph:actions:${id}`));
|
|
451
|
-
}));
|
|
452
|
-
_define_property(this, "_json", Rx.family((id) => {
|
|
453
|
-
return Rx.make((get2) => {
|
|
454
|
-
const toJSON = (node, seen = []) => {
|
|
455
|
-
const nodes2 = get2(this.connections(node.id));
|
|
456
|
-
const obj = {
|
|
457
|
-
id: node.id,
|
|
458
|
-
type: node.type
|
|
459
|
-
};
|
|
460
|
-
if (node.properties.label) {
|
|
461
|
-
obj.label = node.properties.label;
|
|
462
|
-
}
|
|
463
|
-
if (nodes2.length) {
|
|
464
|
-
obj.nodes = nodes2.map((n) => {
|
|
465
|
-
const nextSeen = [
|
|
466
|
-
...seen,
|
|
467
|
-
node.id
|
|
468
|
-
];
|
|
469
|
-
return nextSeen.includes(n.id) ? void 0 : toJSON(n, nextSeen);
|
|
470
|
-
}).filter(isNonNullable);
|
|
471
|
-
}
|
|
472
|
-
return obj;
|
|
473
|
-
};
|
|
474
|
-
const root = get2(this.nodeOrThrow(id));
|
|
475
|
-
return toJSON(root);
|
|
476
|
-
}).pipe(Rx.withLabel(`graph:json:${id}`));
|
|
477
|
-
}));
|
|
478
|
-
this._registry = registry ?? Registry.make();
|
|
479
|
-
this._onInitialize = onInitialize;
|
|
480
|
-
this._onExpand = onExpand;
|
|
481
|
-
this._onRemoveNode = onRemoveNode;
|
|
482
|
-
if (nodes) {
|
|
483
|
-
nodes.forEach((node) => {
|
|
484
|
-
Record.set(this._initialNodes, node.id, this._constructNode(node));
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
if (edges) {
|
|
488
|
-
Object.entries(edges).forEach(([source, edges2]) => {
|
|
489
|
-
Record.set(this._initialEdges, source, edges2);
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
483
|
};
|
|
494
484
|
|
|
495
485
|
// src/graph-builder.ts
|
|
496
|
-
import {
|
|
486
|
+
import { Atom as Atom2, Registry as Registry2 } from "@effect-atom/atom-react";
|
|
497
487
|
import { effect } from "@preact/signals-core";
|
|
498
488
|
import * as Array from "effect/Array";
|
|
499
489
|
import * as Function2 from "effect/Function";
|
|
@@ -510,27 +500,14 @@ var isActionGroup = (data) => isGraphNode(data) ? data.data === actionGroupSymbo
|
|
|
510
500
|
var isActionLike = (data) => isAction(data) || isActionGroup(data);
|
|
511
501
|
|
|
512
502
|
// src/graph-builder.ts
|
|
513
|
-
function _define_property2(obj, key, value) {
|
|
514
|
-
if (key in obj) {
|
|
515
|
-
Object.defineProperty(obj, key, {
|
|
516
|
-
value,
|
|
517
|
-
enumerable: true,
|
|
518
|
-
configurable: true,
|
|
519
|
-
writable: true
|
|
520
|
-
});
|
|
521
|
-
} else {
|
|
522
|
-
obj[key] = value;
|
|
523
|
-
}
|
|
524
|
-
return obj;
|
|
525
|
-
}
|
|
526
503
|
var __dxlog_file2 = "/__w/dxos/dxos/packages/sdk/app-graph/src/graph-builder.ts";
|
|
527
504
|
var createExtension = (extension) => {
|
|
528
505
|
const { id, position = "static", relation = "outbound", resolver: _resolver, connector: _connector, actions: _actions, actionGroups: _actionGroups } = extension;
|
|
529
506
|
const getId = (key) => `${id}/${key}`;
|
|
530
|
-
const resolver = _resolver &&
|
|
531
|
-
const connector = _connector &&
|
|
532
|
-
const actionGroups = _actionGroups &&
|
|
533
|
-
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}`)));
|
|
534
511
|
return [
|
|
535
512
|
resolver ? {
|
|
536
513
|
id: getId("resolver"),
|
|
@@ -541,7 +518,7 @@ var createExtension = (extension) => {
|
|
|
541
518
|
id: getId("connector"),
|
|
542
519
|
position,
|
|
543
520
|
relation,
|
|
544
|
-
connector:
|
|
521
|
+
connector: Atom2.family((node) => Atom2.make((get2) => {
|
|
545
522
|
try {
|
|
546
523
|
return get2(connector(node));
|
|
547
524
|
} catch {
|
|
@@ -550,19 +527,19 @@ var createExtension = (extension) => {
|
|
|
550
527
|
node
|
|
551
528
|
}, {
|
|
552
529
|
F: __dxlog_file2,
|
|
553
|
-
L:
|
|
530
|
+
L: 114,
|
|
554
531
|
S: void 0,
|
|
555
532
|
C: (f, a) => f(...a)
|
|
556
533
|
});
|
|
557
534
|
return [];
|
|
558
535
|
}
|
|
559
|
-
}).pipe(
|
|
536
|
+
}).pipe(Atom2.withLabel(`graph-builder:connector:${id}`)))
|
|
560
537
|
} : void 0,
|
|
561
538
|
actionGroups ? {
|
|
562
539
|
id: getId("actionGroups"),
|
|
563
540
|
position,
|
|
564
541
|
relation: "outbound",
|
|
565
|
-
connector:
|
|
542
|
+
connector: Atom2.family((node) => Atom2.make((get2) => {
|
|
566
543
|
try {
|
|
567
544
|
return get2(actionGroups(node)).map((arg) => ({
|
|
568
545
|
...arg,
|
|
@@ -575,19 +552,19 @@ var createExtension = (extension) => {
|
|
|
575
552
|
node
|
|
576
553
|
}, {
|
|
577
554
|
F: __dxlog_file2,
|
|
578
|
-
L:
|
|
555
|
+
L: 135,
|
|
579
556
|
S: void 0,
|
|
580
557
|
C: (f, a) => f(...a)
|
|
581
558
|
});
|
|
582
559
|
return [];
|
|
583
560
|
}
|
|
584
|
-
}).pipe(
|
|
561
|
+
}).pipe(Atom2.withLabel(`graph-builder:connector:actionGroups:${id}`)))
|
|
585
562
|
} : void 0,
|
|
586
563
|
actions ? {
|
|
587
564
|
id: getId("actions"),
|
|
588
565
|
position,
|
|
589
566
|
relation: "outbound",
|
|
590
|
-
connector:
|
|
567
|
+
connector: Atom2.family((node) => Atom2.make((get2) => {
|
|
591
568
|
try {
|
|
592
569
|
return get2(actions(node)).map((arg) => ({
|
|
593
570
|
...arg,
|
|
@@ -599,13 +576,13 @@ var createExtension = (extension) => {
|
|
|
599
576
|
node
|
|
600
577
|
}, {
|
|
601
578
|
F: __dxlog_file2,
|
|
602
|
-
L:
|
|
579
|
+
L: 152,
|
|
603
580
|
S: void 0,
|
|
604
581
|
C: (f, a) => f(...a)
|
|
605
582
|
});
|
|
606
583
|
return [];
|
|
607
584
|
}
|
|
608
|
-
}).pipe(
|
|
585
|
+
}).pipe(Atom2.withLabel(`graph-builder:connector:actions:${id}`)))
|
|
609
586
|
} : void 0
|
|
610
587
|
].filter(isNonNullable2);
|
|
611
588
|
};
|
|
@@ -623,6 +600,22 @@ var flattenExtensions = (extension, acc = []) => {
|
|
|
623
600
|
}
|
|
624
601
|
};
|
|
625
602
|
var GraphBuilder = class _GraphBuilder {
|
|
603
|
+
// TODO(wittjosiah): Use Context.
|
|
604
|
+
_subscriptions = /* @__PURE__ */ new Map();
|
|
605
|
+
_extensions = Atom2.make(Record2.empty()).pipe(Atom2.keepAlive, Atom2.withLabel("graph-builder:extensions"));
|
|
606
|
+
_initialized = {};
|
|
607
|
+
_registry;
|
|
608
|
+
_graph;
|
|
609
|
+
constructor({ registry, ...params } = {}) {
|
|
610
|
+
this._registry = registry ?? Registry2.make();
|
|
611
|
+
this._graph = new Graph({
|
|
612
|
+
...params,
|
|
613
|
+
registry: this._registry,
|
|
614
|
+
onExpand: (id, relation) => this._onExpand(id, relation),
|
|
615
|
+
onInitialize: (id) => this._onInitialize(id),
|
|
616
|
+
onRemoveNode: (id) => this._onRemoveNode(id)
|
|
617
|
+
});
|
|
618
|
+
}
|
|
626
619
|
static from(pickle, registry) {
|
|
627
620
|
if (!pickle) {
|
|
628
621
|
return new _GraphBuilder({
|
|
@@ -692,6 +685,27 @@ var GraphBuilder = class _GraphBuilder {
|
|
|
692
685
|
this._subscriptions.forEach((unsubscribe) => unsubscribe());
|
|
693
686
|
this._subscriptions.clear();
|
|
694
687
|
}
|
|
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);
|
|
691
|
+
});
|
|
692
|
+
});
|
|
693
|
+
_connectors = Atom2.family((key) => {
|
|
694
|
+
return Atom2.make((get2) => {
|
|
695
|
+
const [id, relation] = key.split("+");
|
|
696
|
+
const node = this._graph.node(id);
|
|
697
|
+
return Function2.pipe(
|
|
698
|
+
get2(this._extensions),
|
|
699
|
+
Record2.values,
|
|
700
|
+
// TODO(wittjosiah): Sort on write rather than read.
|
|
701
|
+
Array.sortBy(byPosition),
|
|
702
|
+
Array.filter(({ relation: _relation = "outbound" }) => _relation === relation),
|
|
703
|
+
Array.map(({ connector }) => connector?.(node)),
|
|
704
|
+
Array.filter(isNonNullable2),
|
|
705
|
+
Array.flatMap((result) => get2(result))
|
|
706
|
+
);
|
|
707
|
+
}).pipe(Atom2.withLabel(`graph-builder:connectors:${key}`));
|
|
708
|
+
});
|
|
695
709
|
_onExpand(id, relation) {
|
|
696
710
|
log2("onExpand", {
|
|
697
711
|
id,
|
|
@@ -699,7 +713,7 @@ var GraphBuilder = class _GraphBuilder {
|
|
|
699
713
|
registry: getDebugName(this._registry)
|
|
700
714
|
}, {
|
|
701
715
|
F: __dxlog_file2,
|
|
702
|
-
L:
|
|
716
|
+
L: 329,
|
|
703
717
|
S: this,
|
|
704
718
|
C: (f, a) => f(...a)
|
|
705
719
|
});
|
|
@@ -716,12 +730,12 @@ var GraphBuilder = class _GraphBuilder {
|
|
|
716
730
|
removed
|
|
717
731
|
}, {
|
|
718
732
|
F: __dxlog_file2,
|
|
719
|
-
L:
|
|
733
|
+
L: 340,
|
|
720
734
|
S: this,
|
|
721
735
|
C: (f, a) => f(...a)
|
|
722
736
|
});
|
|
723
737
|
const update = () => {
|
|
724
|
-
|
|
738
|
+
Atom2.batch(() => {
|
|
725
739
|
this._graph.removeEdges(removed.map((target) => ({
|
|
726
740
|
source: id,
|
|
727
741
|
target
|
|
@@ -753,7 +767,7 @@ var GraphBuilder = class _GraphBuilder {
|
|
|
753
767
|
id
|
|
754
768
|
}, {
|
|
755
769
|
F: __dxlog_file2,
|
|
756
|
-
L:
|
|
770
|
+
L: 377,
|
|
757
771
|
S: this,
|
|
758
772
|
C: (f, a) => f(...a)
|
|
759
773
|
});
|
|
@@ -783,45 +797,9 @@ var GraphBuilder = class _GraphBuilder {
|
|
|
783
797
|
this._subscriptions.get(id)?.();
|
|
784
798
|
this._subscriptions.delete(id);
|
|
785
799
|
}
|
|
786
|
-
constructor({ registry, ...params } = {}) {
|
|
787
|
-
_define_property2(this, "_subscriptions", /* @__PURE__ */ new Map());
|
|
788
|
-
_define_property2(this, "_extensions", Rx2.make(Record2.empty()).pipe(Rx2.keepAlive, Rx2.withLabel("graph-builder:extensions")));
|
|
789
|
-
_define_property2(this, "_initialized", {});
|
|
790
|
-
_define_property2(this, "_registry", void 0);
|
|
791
|
-
_define_property2(this, "_graph", void 0);
|
|
792
|
-
_define_property2(this, "_resolvers", Rx2.family((id) => {
|
|
793
|
-
return Rx2.make((get2) => {
|
|
794
|
-
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);
|
|
795
|
-
});
|
|
796
|
-
}));
|
|
797
|
-
_define_property2(this, "_connectors", Rx2.family((key) => {
|
|
798
|
-
return Rx2.make((get2) => {
|
|
799
|
-
const [id, relation] = key.split("+");
|
|
800
|
-
const node = this._graph.node(id);
|
|
801
|
-
return Function2.pipe(
|
|
802
|
-
get2(this._extensions),
|
|
803
|
-
Record2.values,
|
|
804
|
-
// TODO(wittjosiah): Sort on write rather than read.
|
|
805
|
-
Array.sortBy(byPosition),
|
|
806
|
-
Array.filter(({ relation: _relation = "outbound" }) => _relation === relation),
|
|
807
|
-
Array.map(({ connector }) => connector?.(node)),
|
|
808
|
-
Array.filter(isNonNullable2),
|
|
809
|
-
Array.flatMap((result) => get2(result))
|
|
810
|
-
);
|
|
811
|
-
}).pipe(Rx2.withLabel(`graph-builder:connectors:${key}`));
|
|
812
|
-
}));
|
|
813
|
-
this._registry = registry ?? Registry2.make();
|
|
814
|
-
this._graph = new Graph({
|
|
815
|
-
...params,
|
|
816
|
-
registry: this._registry,
|
|
817
|
-
onExpand: (id, relation) => this._onExpand(id, relation),
|
|
818
|
-
onInitialize: (id) => this._onInitialize(id),
|
|
819
|
-
onRemoveNode: (id) => this._onRemoveNode(id)
|
|
820
|
-
});
|
|
821
|
-
}
|
|
822
800
|
};
|
|
823
801
|
var rxFromSignal = (cb) => {
|
|
824
|
-
return
|
|
802
|
+
return Atom2.make((get2) => {
|
|
825
803
|
const dispose = effect(() => {
|
|
826
804
|
get2.setSelf(cb());
|
|
827
805
|
});
|
|
@@ -829,8 +807,8 @@ var rxFromSignal = (cb) => {
|
|
|
829
807
|
return cb();
|
|
830
808
|
});
|
|
831
809
|
};
|
|
832
|
-
var observableFamily =
|
|
833
|
-
return
|
|
810
|
+
var observableFamily = Atom2.family((observable) => {
|
|
811
|
+
return Atom2.make((get2) => {
|
|
834
812
|
const subscription = observable.subscribe((value) => get2.setSelf(value));
|
|
835
813
|
get2.addFinalizer(() => subscription.unsubscribe());
|
|
836
814
|
return observable.get();
|