@dxos/graph 0.8.4-main.8360d9e660 → 0.8.4-main.8baae0fced
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/LICENSE +102 -5
- package/dist/lib/browser/index.mjs +20 -140
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +20 -140
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/Graph.d.ts.map +1 -1
- package/dist/types/src/GraphModel.d.ts +2 -2
- package/dist/types/src/GraphModel.d.ts.map +1 -1
- package/dist/types/src/selection.d.ts +6 -2
- package/dist/types/src/selection.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -15
- package/src/GraphModel.ts +2 -2
- package/src/selection.ts +11 -2
package/LICENSE
CHANGED
|
@@ -1,8 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
Copyright (c) 2022 DXOS
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
## Abbreviation
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
FSL-1.1-Apache-2.0
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 DXOS
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
91
|
+
the date we make the Software available. On or after that date, you may use the
|
|
92
|
+
Software under the Apache License, Version 2.0, in which case the following
|
|
93
|
+
will apply:
|
|
94
|
+
|
|
95
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
96
|
+
this file except in compliance with the License.
|
|
97
|
+
|
|
98
|
+
You may obtain a copy of the License at
|
|
99
|
+
|
|
100
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
101
|
+
|
|
102
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
103
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
104
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
105
|
+
specific language governing permissions and limitations under the License.
|
|
@@ -9,13 +9,13 @@ import { Atom, Registry } from "@effect-atom/atom-react";
|
|
|
9
9
|
import { invariant } from "@dxos/invariant";
|
|
10
10
|
var __dxlog_file = "/__w/dxos/dxos/packages/common/graph/src/selection.ts";
|
|
11
11
|
var SelectionModel = class {
|
|
12
|
-
_singleSelect;
|
|
13
12
|
_registry;
|
|
14
13
|
_selected;
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
_mode;
|
|
15
|
+
constructor({ mode = "multi" } = {}) {
|
|
17
16
|
this._registry = Registry.make();
|
|
18
17
|
this._selected = Atom.make(/* @__PURE__ */ new Set());
|
|
18
|
+
this._mode = mode;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Returns the selected IDs atom for subscription.
|
|
@@ -62,17 +62,9 @@ var SelectionModel = class {
|
|
|
62
62
|
this._registry.set(this._selected, /* @__PURE__ */ new Set());
|
|
63
63
|
}
|
|
64
64
|
add(id) {
|
|
65
|
-
invariant(id, void 0, {
|
|
66
|
-
F: __dxlog_file,
|
|
67
|
-
L: 76,
|
|
68
|
-
S: this,
|
|
69
|
-
A: [
|
|
70
|
-
"id",
|
|
71
|
-
""
|
|
72
|
-
]
|
|
73
|
-
});
|
|
65
|
+
invariant(id, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 59, S: this, A: ["id", ""] });
|
|
74
66
|
const current = this._registry.get(this._selected);
|
|
75
|
-
this._registry.set(this._selected, new Set(this.
|
|
67
|
+
this._registry.set(this._selected, new Set(this._mode === "single" ? [
|
|
76
68
|
id
|
|
77
69
|
] : [
|
|
78
70
|
...Array.from(current.values()),
|
|
@@ -80,15 +72,7 @@ var SelectionModel = class {
|
|
|
80
72
|
]));
|
|
81
73
|
}
|
|
82
74
|
remove(id) {
|
|
83
|
-
invariant(id, void 0, {
|
|
84
|
-
F: __dxlog_file,
|
|
85
|
-
L: 85,
|
|
86
|
-
S: this,
|
|
87
|
-
A: [
|
|
88
|
-
"id",
|
|
89
|
-
""
|
|
90
|
-
]
|
|
91
|
-
});
|
|
75
|
+
invariant(id, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 69, S: this, A: ["id", ""] });
|
|
92
76
|
const current = this._registry.get(this._selected);
|
|
93
77
|
this._registry.set(this._selected, new Set(Array.from(current.values()).filter((_id) => _id !== id)));
|
|
94
78
|
}
|
|
@@ -140,24 +124,8 @@ var Edge = Schema.Struct({
|
|
|
140
124
|
});
|
|
141
125
|
var KEY_REGEX = /\w+/;
|
|
142
126
|
var createEdgeId = ({ source, target, relation }) => {
|
|
143
|
-
invariant2(source.match(KEY_REGEX), `invalid source: ${source}`, {
|
|
144
|
-
|
|
145
|
-
L: 54,
|
|
146
|
-
S: void 0,
|
|
147
|
-
A: [
|
|
148
|
-
"source.match(KEY_REGEX)",
|
|
149
|
-
"`invalid source: ${source}`"
|
|
150
|
-
]
|
|
151
|
-
});
|
|
152
|
-
invariant2(target.match(KEY_REGEX), `invalid target: ${target}`, {
|
|
153
|
-
F: __dxlog_file2,
|
|
154
|
-
L: 55,
|
|
155
|
-
S: void 0,
|
|
156
|
-
A: [
|
|
157
|
-
"target.match(KEY_REGEX)",
|
|
158
|
-
"`invalid target: ${target}`"
|
|
159
|
-
]
|
|
160
|
-
});
|
|
127
|
+
invariant2(source.match(KEY_REGEX), `invalid source: ${source}`, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 27, S: void 0, A: ["source.match(KEY_REGEX)", "`invalid source: ${source}`"] });
|
|
128
|
+
invariant2(target.match(KEY_REGEX), `invalid target: ${target}`, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 28, S: void 0, A: ["target.match(KEY_REGEX)", "`invalid target: ${target}`"] });
|
|
161
129
|
return [
|
|
162
130
|
source,
|
|
163
131
|
relation,
|
|
@@ -166,15 +134,7 @@ var createEdgeId = ({ source, target, relation }) => {
|
|
|
166
134
|
};
|
|
167
135
|
var parseEdgeId = (id) => {
|
|
168
136
|
const [source, relation, target] = id.split("_");
|
|
169
|
-
invariant2(source.length && target.length, void 0, {
|
|
170
|
-
F: __dxlog_file2,
|
|
171
|
-
L: 61,
|
|
172
|
-
S: void 0,
|
|
173
|
-
A: [
|
|
174
|
-
"source.length && target.length",
|
|
175
|
-
""
|
|
176
|
-
]
|
|
177
|
-
});
|
|
137
|
+
invariant2(source.length && target.length, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 37, S: void 0, A: ["source.length && target.length", ""] });
|
|
178
138
|
return {
|
|
179
139
|
source,
|
|
180
140
|
relation: relation.length ? relation : void 0,
|
|
@@ -212,7 +172,7 @@ var ReadonlyGraphModel = class {
|
|
|
212
172
|
/**
|
|
213
173
|
* NOTE: Pass in simple Graph or Live.
|
|
214
174
|
* @param graph - The graph data.
|
|
215
|
-
* @param change - Optional function to wrap mutations (e.g., Obj.
|
|
175
|
+
* @param change - Optional function to wrap mutations (e.g., Obj.update for ECHO objects).
|
|
216
176
|
*/
|
|
217
177
|
constructor(graph, change) {
|
|
218
178
|
this._graph = graph ?? {
|
|
@@ -318,24 +278,8 @@ var AbstractGraphModel = class extends ReadonlyGraphModel {
|
|
|
318
278
|
return this;
|
|
319
279
|
}
|
|
320
280
|
addNode(node) {
|
|
321
|
-
invariant3(node.id, "ID is required", {
|
|
322
|
-
|
|
323
|
-
L: 184,
|
|
324
|
-
S: this,
|
|
325
|
-
A: [
|
|
326
|
-
"node.id",
|
|
327
|
-
"'ID is required'"
|
|
328
|
-
]
|
|
329
|
-
});
|
|
330
|
-
invariant3(!this.findNode(node.id), `node already exists: ${node.id}`, {
|
|
331
|
-
F: __dxlog_file3,
|
|
332
|
-
L: 185,
|
|
333
|
-
S: this,
|
|
334
|
-
A: [
|
|
335
|
-
"!this.findNode(node.id)",
|
|
336
|
-
"`node already exists: ${node.id}`"
|
|
337
|
-
]
|
|
338
|
-
});
|
|
281
|
+
invariant3(node.id, "ID is required", { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 126, S: this, A: ["node.id", "'ID is required'"] });
|
|
282
|
+
invariant3(!this.findNode(node.id), `node already exists: ${node.id}`, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 127, S: this, A: ["!this.findNode(node.id)", "`node already exists: ${node.id}`"] });
|
|
339
283
|
this._mutate((graph) => {
|
|
340
284
|
graph.nodes.push(node);
|
|
341
285
|
});
|
|
@@ -345,39 +289,15 @@ var AbstractGraphModel = class extends ReadonlyGraphModel {
|
|
|
345
289
|
return nodes.map((node) => this.addNode(node));
|
|
346
290
|
}
|
|
347
291
|
addEdge(edge) {
|
|
348
|
-
invariant3(edge.source, void 0, {
|
|
349
|
-
|
|
350
|
-
L: 197,
|
|
351
|
-
S: this,
|
|
352
|
-
A: [
|
|
353
|
-
"edge.source",
|
|
354
|
-
""
|
|
355
|
-
]
|
|
356
|
-
});
|
|
357
|
-
invariant3(edge.target, void 0, {
|
|
358
|
-
F: __dxlog_file3,
|
|
359
|
-
L: 198,
|
|
360
|
-
S: this,
|
|
361
|
-
A: [
|
|
362
|
-
"edge.target",
|
|
363
|
-
""
|
|
364
|
-
]
|
|
365
|
-
});
|
|
292
|
+
invariant3(edge.source, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 137, S: this, A: ["edge.source", ""] });
|
|
293
|
+
invariant3(edge.target, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 138, S: this, A: ["edge.target", ""] });
|
|
366
294
|
if (!edge.id) {
|
|
367
295
|
edge = {
|
|
368
296
|
id: createEdgeId(edge),
|
|
369
297
|
...edge
|
|
370
298
|
};
|
|
371
299
|
}
|
|
372
|
-
invariant3(!this.findNode(edge.id), void 0, {
|
|
373
|
-
F: __dxlog_file3,
|
|
374
|
-
L: 203,
|
|
375
|
-
S: this,
|
|
376
|
-
A: [
|
|
377
|
-
"!this.findNode(edge.id!)",
|
|
378
|
-
""
|
|
379
|
-
]
|
|
380
|
-
});
|
|
300
|
+
invariant3(!this.findNode(edge.id), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 146, S: this, A: ["!this.findNode(edge.id)", ""] });
|
|
381
301
|
this._mutate((graph) => {
|
|
382
302
|
graph.edges.push(edge);
|
|
383
303
|
});
|
|
@@ -504,24 +424,8 @@ var ReactiveGraphModel = class _ReactiveGraphModel extends GraphModel {
|
|
|
504
424
|
return this;
|
|
505
425
|
}
|
|
506
426
|
addNode(node) {
|
|
507
|
-
invariant3(node.id, "ID is required", {
|
|
508
|
-
|
|
509
|
-
L: 376,
|
|
510
|
-
S: this,
|
|
511
|
-
A: [
|
|
512
|
-
"node.id",
|
|
513
|
-
"'ID is required'"
|
|
514
|
-
]
|
|
515
|
-
});
|
|
516
|
-
invariant3(!this.findNode(node.id), `node already exists: ${node.id}`, {
|
|
517
|
-
F: __dxlog_file3,
|
|
518
|
-
L: 377,
|
|
519
|
-
S: this,
|
|
520
|
-
A: [
|
|
521
|
-
"!this.findNode(node.id)",
|
|
522
|
-
"`node already exists: ${node.id}`"
|
|
523
|
-
]
|
|
524
|
-
});
|
|
427
|
+
invariant3(node.id, "ID is required", { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 280, S: this, A: ["node.id", "'ID is required'"] });
|
|
428
|
+
invariant3(!this.findNode(node.id), `node already exists: ${node.id}`, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 281, S: this, A: ["!this.findNode(node.id)", "`node already exists: ${node.id}`"] });
|
|
525
429
|
const current = this._registry.get(this._graphAtom);
|
|
526
430
|
this._registry.set(this._graphAtom, {
|
|
527
431
|
...current,
|
|
@@ -533,39 +437,15 @@ var ReactiveGraphModel = class _ReactiveGraphModel extends GraphModel {
|
|
|
533
437
|
return node;
|
|
534
438
|
}
|
|
535
439
|
addEdge(edge) {
|
|
536
|
-
invariant3(edge.source, void 0, {
|
|
537
|
-
|
|
538
|
-
L: 387,
|
|
539
|
-
S: this,
|
|
540
|
-
A: [
|
|
541
|
-
"edge.source",
|
|
542
|
-
""
|
|
543
|
-
]
|
|
544
|
-
});
|
|
545
|
-
invariant3(edge.target, void 0, {
|
|
546
|
-
F: __dxlog_file3,
|
|
547
|
-
L: 388,
|
|
548
|
-
S: this,
|
|
549
|
-
A: [
|
|
550
|
-
"edge.target",
|
|
551
|
-
""
|
|
552
|
-
]
|
|
553
|
-
});
|
|
440
|
+
invariant3(edge.source, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 293, S: this, A: ["edge.source", ""] });
|
|
441
|
+
invariant3(edge.target, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 294, S: this, A: ["edge.target", ""] });
|
|
554
442
|
if (!edge.id) {
|
|
555
443
|
edge = {
|
|
556
444
|
id: createEdgeId(edge),
|
|
557
445
|
...edge
|
|
558
446
|
};
|
|
559
447
|
}
|
|
560
|
-
invariant3(!this.findNode(edge.id), void 0, {
|
|
561
|
-
F: __dxlog_file3,
|
|
562
|
-
L: 392,
|
|
563
|
-
S: this,
|
|
564
|
-
A: [
|
|
565
|
-
"!this.findNode(edge.id!)",
|
|
566
|
-
""
|
|
567
|
-
]
|
|
568
|
-
});
|
|
448
|
+
invariant3(!this.findNode(edge.id), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 301, S: this, A: ["!this.findNode(edge.id)", ""] });
|
|
569
449
|
const current = this._registry.get(this._graphAtom);
|
|
570
450
|
this._registry.set(this._graphAtom, {
|
|
571
451
|
...current,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/selection.ts", "../../../src/Graph.ts", "../../../src/GraphModel.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Atom, Registry } from '@effect-atom/atom-react';\n\nimport { invariant } from '@dxos/invariant';\n\n/**\n * Reactive selection model.\n */\nexport class SelectionModel {\n private readonly _registry: Registry.Registry;\n private readonly _selected: Atom.Writable<Set<string>>;\n\n constructor(private readonly _singleSelect: boolean = false) {\n this._registry = Registry.make();\n this._selected = Atom.make<Set<string>>(new Set<string>());\n }\n\n /**\n * Returns the selected IDs atom for subscription.\n */\n get selected(): Atom.Atom<Set<string>> {\n return this._selected;\n }\n\n /**\n * Gets the current selected IDs as a Set.\n */\n getSelected(): Set<string> {\n return this._registry.get(this._selected);\n }\n\n /**\n * Gets the current selected IDs as an array.\n */\n getSelectedIds(): string[] {\n return Array.from(this._registry.get(this._selected).values());\n }\n\n /**\n * Subscribe to selection changes.\n */\n subscribe(cb: (selected: Set<string>) => void): () => void {\n // Prime the atom by reading before subscribing.\n this._registry.get(this._selected);\n\n return this._registry.subscribe(this._selected, () => {\n cb(this._registry.get(this._selected));\n });\n }\n\n toJSON(): { selected: string[] } {\n return {\n selected: this.getSelectedIds(),\n };\n }\n\n /**\n * Gets the current selection size.\n */\n getSize(): number {\n return this._registry.get(this._selected).size;\n }\n\n contains(id: string): boolean {\n return this._registry.get(this._selected).has(id);\n }\n\n clear(): void {\n this._registry.set(this._selected, new Set());\n }\n\n add(id: string): void {\n invariant(id);\n const current = this._registry.get(this._selected);\n this._registry.set(\n this._selected,\n new Set<string>(this._singleSelect ? [id] : [...Array.from(current.values()), id]),\n );\n }\n\n remove(id: string): void {\n invariant(id);\n const current = this._registry.get(this._selected);\n this._registry.set(this._selected, new Set<string>(Array.from(current.values()).filter((_id) => _id !== id)));\n }\n\n // TODO(burdon): Handle single select.\n\n setSelected(ids: string[], subtract = false): void {\n const current = this._registry.get(this._selected);\n this._registry.set(this._selected, new Set([...(subtract ? Array.from(current.values()) : []), ...ids]));\n }\n\n toggleSelected(ids: string[], subtract = false): void {\n const current = this._registry.get(this._selected);\n const set = new Set<string>(subtract ? Array.from(current.values()) : undefined);\n ids.forEach((id) => {\n if (current.has(id)) {\n set.delete(id);\n } else {\n set.add(id);\n }\n });\n\n this._registry.set(this._selected, set);\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Schema from 'effect/Schema';\n\nimport { invariant } from '@dxos/invariant';\nimport { type Specialize } from '@dxos/util';\n\n//\n// Node\n//\n\nexport const Node = Schema.Struct({\n id: Schema.String,\n type: Schema.optional(Schema.String),\n data: Schema.optional(Schema.Any),\n});\n\ninterface BaseNode extends Schema.Schema.Type<typeof Node> {}\n\nexport declare namespace Node {\n export type Any = Specialize<BaseNode, { data?: any }>;\n export type Node<Data = any> = Specialize<BaseNode, { data: Data }>;\n}\n\n//\n// Edge\n//\n\nexport const Edge = Schema.Struct({\n id: Schema.String,\n type: Schema.optional(Schema.String),\n source: Schema.String,\n target: Schema.String,\n data: Schema.optional(Schema.Any),\n});\n\ninterface BaseEdge extends Schema.Schema.Type<typeof Edge> {}\n\nexport declare namespace Edge {\n export type Any = Specialize<BaseEdge, { data?: any }>;\n export type Edge<Data = any> = Specialize<BaseEdge, { data: Data }>;\n}\n\nconst KEY_REGEX = /\\w+/;\n\n// NOTE: The `relation` is different from the `type`.\ntype EdgeMeta = { source: string; target: string; relation?: string };\n\nexport const createEdgeId = ({ source, target, relation }: EdgeMeta) => {\n invariant(source.match(KEY_REGEX), `invalid source: ${source}`);\n invariant(target.match(KEY_REGEX), `invalid target: ${target}`);\n return [source, relation, target].join('_');\n};\n\nexport const parseEdgeId = (id: string): EdgeMeta => {\n const [source, relation, target] = id.split('_');\n invariant(source.length && target.length);\n return { source, relation: relation.length ? relation : undefined, target };\n};\n\n//\n// Graph\n//\n\nexport const Graph = Schema.Struct({\n id: Schema.optional(Schema.String),\n nodes: Schema.mutable(Schema.Array(Node)),\n edges: Schema.mutable(Schema.Array(Edge)),\n});\n\nexport interface Any extends Schema.Schema.Type<typeof Graph> {}\n\nexport type Graph<Node extends Node.Any, Edge extends Edge.Any> = Specialize<\n Any,\n {\n nodes: Node[];\n edges: Edge[];\n }\n>;\n", "//\n// Copyright 2024 DXOS.org\n//\n\n// @import-as-namespace\n\nimport { Atom, type Registry } from '@effect-atom/atom-react';\n\nimport { inspectCustom } from '@dxos/debug';\nimport { failedInvariant, invariant } from '@dxos/invariant';\nimport { type MakeOptional, isTruthy, removeBy } from '@dxos/util';\n\nimport * as Graph from './Graph';\n\n/**\n * Optional function to wrap mutations (e.g., for ECHO objects that require Obj.change).\n */\nexport type GraphChangeFunction = (fn: () => void) => void;\n\n/**\n * Readonly Graph wrapper.\n */\nexport class ReadonlyGraphModel<\n Node extends Graph.Node.Any = Graph.Node.Any,\n Edge extends Graph.Edge.Any = Graph.Edge.Any,\n> {\n protected readonly _graph: Graph.Graph<Node, Edge>;\n /**\n * Optional function to wrap mutations.\n * When set, all graph mutations are wrapped in this function.\n */\n protected readonly _change?: GraphChangeFunction;\n\n /**\n * NOTE: Pass in simple Graph or Live.\n * @param graph - The graph data.\n * @param change - Optional function to wrap mutations (e.g., Obj.change for ECHO objects).\n */\n constructor(graph?: Graph.Graph<Node, Edge>, change?: GraphChangeFunction) {\n this._graph = graph ?? {\n nodes: [],\n edges: [],\n };\n this._change = change;\n }\n\n [inspectCustom]() {\n return this.toJSON();\n }\n\n /**\n * Return stable sorted JSON representation of graph.\n */\n toJSON() {\n return {\n nodes: this.nodes.length,\n edges: this.edges.length,\n };\n }\n\n get graph(): Graph.Graph<Node, Edge> {\n return this._graph;\n }\n\n get nodes(): Node[] {\n return this._graph.nodes;\n }\n\n get edges(): Edge[] {\n return this._graph.edges;\n }\n\n //\n // Nodes\n //\n\n findNode(id: string): Node | undefined {\n return this.nodes.find((node) => node.id === id);\n }\n\n getNode(id: string): Node {\n return this.findNode(id) ?? failedInvariant();\n }\n\n filterNodes({ type }: Partial<Graph.Node.Any> = {}): Node[] {\n return this.nodes.filter((node) => !type || type === node.type);\n }\n\n //\n // Edges\n //\n\n findEdge(id: string): Edge | undefined {\n return this.edges.find((edge) => edge.id === id);\n }\n\n getEdge(id: string): Edge {\n return this.findEdge(id) ?? failedInvariant();\n }\n\n filterEdges({ type, source, target }: Partial<Graph.Edge.Any> = {}): Edge[] {\n return this.edges.filter(\n (edge) =>\n (!type || type === edge.type) && (!source || source === edge.source) && (!target || target === edge.target),\n );\n }\n\n //\n // Traverse\n //\n\n traverse(root: Node): Node[] {\n return this._traverse(root);\n }\n\n private _traverse(root: Node, visited: Set<string> = new Set()): Node[] {\n if (visited.has(root.id)) {\n return [];\n }\n\n visited.add(root.id);\n const targets = this.filterEdges({ source: root.id })\n .map((edge) => this.getNode(edge.target))\n .filter(isTruthy);\n\n return [root, ...targets.flatMap((target) => this._traverse(target, visited))];\n }\n}\n\n/**\n * Mutable Graph wrapper.\n */\nexport abstract class AbstractGraphModel<\n Node extends Graph.Node.Any = Graph.Node.Any,\n Edge extends Graph.Edge.Any = Graph.Edge.Any,\n Model extends AbstractGraphModel<Node, Edge, Model, Builder> = any,\n Builder extends AbstractBuilder<Node, Edge, Model> = AbstractBuilder<Node, Edge, Model>,\n> extends ReadonlyGraphModel<Node, Edge> {\n /**\n * Allows chaining.\n */\n abstract get builder(): Builder;\n\n /**\n * Shallow copy of provided graph.\n */\n abstract copy(graph?: Partial<Graph.Graph<Node, Edge>>): Model;\n\n /**\n * Execute a mutation on the graph.\n * If a change function is set, wraps the mutation in it.\n */\n protected _mutate(fn: (graph: Graph.Graph<Node, Edge>) => void): void {\n if (this._change != null) {\n this._change(() => fn(this._graph));\n } else {\n fn(this._graph);\n }\n }\n\n clear(): this {\n this._mutate((graph) => {\n graph.nodes.length = 0;\n graph.edges.length = 0;\n });\n return this;\n }\n\n addGraph(graph: Model): this {\n this.addNodes(graph.nodes);\n this.addEdges(graph.edges);\n return this;\n }\n\n addGraphs(graphs: Model[]): this {\n graphs.forEach((graph) => {\n this.addNodes(graph.nodes);\n this.addEdges(graph.edges);\n });\n return this;\n }\n\n addNode(node: Node): Node {\n invariant(node.id, 'ID is required');\n invariant(!this.findNode(node.id), `node already exists: ${node.id}`);\n this._mutate((graph) => {\n graph.nodes.push(node);\n });\n return node;\n }\n\n addNodes(nodes: Node[]): Node[] {\n return nodes.map((node) => this.addNode(node));\n }\n\n addEdge(edge: MakeOptional<Edge, 'id'>): Edge {\n invariant(edge.source);\n invariant(edge.target);\n if (!edge.id) {\n // TODO(burdon): Generate random id.\n edge = { id: Graph.createEdgeId(edge), ...edge };\n }\n invariant(!this.findNode(edge.id!));\n this._mutate((graph) => {\n graph.edges.push(edge as Edge);\n });\n return edge as Edge;\n }\n\n addEdges(edges: Edge[]): Edge[] {\n return edges.map((edge) => this.addEdge(edge));\n }\n\n removeNode(id: string): Model {\n let removedEdges: Edge[] = [];\n let removedNodes: Node[] = [];\n this._mutate((graph) => {\n removedEdges = removeBy<Edge>(graph.edges as Edge[], (edge) => edge.source === id || edge.target === id);\n removedNodes = removeBy<Node>(graph.nodes as Node[], (node) => node.id === id);\n });\n return this.copy({ nodes: removedNodes, edges: removedEdges });\n }\n\n removeNodes(ids: string[]): Model {\n const graphs = ids.map((id) => this.removeNode(id));\n return this.copy().addGraphs(graphs);\n }\n\n removeEdge(id: string): Model {\n let removedEdges: Edge[] = [];\n this._mutate((graph) => {\n removedEdges = removeBy<Edge>(graph.edges as Edge[], (edge) => edge.id === id);\n });\n return this.copy({ nodes: [], edges: removedEdges });\n }\n\n removeEdges(ids: string[]): Model {\n const graphs = ids.map((id) => this.removeEdge(id));\n return this.copy().addGraphs(graphs);\n }\n}\n\n/**\n * Chainable builder wrapper\n */\nexport abstract class AbstractBuilder<\n Node extends Graph.Node.Any,\n Edge extends Graph.Edge.Any,\n Model extends GraphModel<Node, Edge>,\n> {\n constructor(protected readonly _model: Model) {}\n\n get model(): Model {\n return this._model;\n }\n\n call(cb: (builder: this) => void): this {\n cb(this);\n return this;\n }\n\n getNode(id: string): Node {\n return this.model.getNode(id);\n }\n\n addNode(node: Node): this {\n this._model.addNode(node);\n return this;\n }\n\n addEdge(edge: MakeOptional<Edge, 'id'>): this {\n this._model.addEdge(edge);\n return this;\n }\n\n addNodes(nodes: Node[]): this {\n this._model.addNodes(nodes);\n return this;\n }\n\n addEdges(edges: Edge[]): this {\n this._model.addEdges(edges);\n return this;\n }\n}\n\n/**\n * Basic model.\n */\nexport class GraphModel<\n Node extends Graph.Node.Any = Graph.Node.Any,\n Edge extends Graph.Edge.Any = Graph.Edge.Any,\n> extends AbstractGraphModel<Node, Edge, GraphModel<Node, Edge>, Builder<Node, Edge>> {\n override get builder() {\n return new Builder<Node, Edge>(this);\n }\n\n override copy(graph?: Partial<Graph.Graph<Node, Edge>>): GraphModel<Node, Edge> {\n return new GraphModel<Node, Edge>(graph as Graph.Graph<Node, Edge>);\n }\n}\n\nexport type Subscription = <Node extends Graph.Node.Any = Graph.Node.Any, Edge extends Graph.Edge.Any = Graph.Edge.Any>(\n model: ReactiveGraphModel<Node, Edge>,\n graph: Graph.Graph<Node, Edge>,\n) => void;\n\n/**\n * Basic reactive model using Effect Atoms.\n */\n// NOTE: Unlike Preact Signals' `live()` which uses proxies for transparent reactivity,\n// Effect Atom requires explicit `registry.set()` calls. All mutation methods must be\n// overridden to update the atom immutably rather than mutating `_graph` directly.\nexport class ReactiveGraphModel<\n Node extends Graph.Node.Any = Graph.Node.Any,\n Edge extends Graph.Edge.Any = Graph.Edge.Any,\n> extends GraphModel<Node, Edge> {\n private readonly _graphAtom: Atom.Writable<Graph.Graph<Node, Edge>>;\n\n constructor(\n private readonly _registry: Registry.Registry,\n graph?: Partial<Graph.Graph<Node, Edge>>,\n ) {\n const initialGraph: Graph.Graph<Node, Edge> = {\n nodes: (graph?.nodes ?? []) as Node[],\n edges: (graph?.edges ?? []) as Edge[],\n };\n super(initialGraph);\n this._graphAtom = Atom.make<Graph.Graph<Node, Edge>>(initialGraph);\n }\n\n get registry(): Registry.Registry {\n return this._registry;\n }\n\n /**\n * Get the graph atom for reactive subscriptions.\n */\n get graphAtom(): Atom.Writable<Graph.Graph<Node, Edge>> {\n return this._graphAtom;\n }\n\n override get graph(): Graph.Graph<Node, Edge> {\n return this._registry.get(this._graphAtom);\n }\n\n override get nodes(): Node[] {\n return this.graph.nodes;\n }\n\n override get edges(): Edge[] {\n return this.graph.edges;\n }\n\n override copy(graph?: Partial<Graph.Graph<Node, Edge>>): ReactiveGraphModel<Node, Edge> {\n return new ReactiveGraphModel<Node, Edge>(this._registry, graph);\n }\n\n override clear(): this {\n this._registry.set(this._graphAtom, {\n nodes: [],\n edges: [],\n });\n return this;\n }\n\n /**\n * Set the entire graph at once, triggering a single notification.\n */\n setGraph(graph: Graph.Graph<Node, Edge>): this {\n this._registry.set(this._graphAtom, graph);\n return this;\n }\n\n override addNode(node: Node): Node {\n invariant(node.id, 'ID is required');\n invariant(!this.findNode(node.id), `node already exists: ${node.id}`);\n const current = this._registry.get(this._graphAtom);\n this._registry.set(this._graphAtom, {\n ...current,\n nodes: [...current.nodes, node],\n });\n return node;\n }\n\n override addEdge(edge: MakeOptional<Edge, 'id'>): Edge {\n invariant(edge.source);\n invariant(edge.target);\n if (!edge.id) {\n edge = { id: Graph.createEdgeId(edge), ...edge };\n }\n invariant(!this.findNode(edge.id!));\n const current = this._registry.get(this._graphAtom);\n this._registry.set(this._graphAtom, {\n ...current,\n edges: [...current.edges, edge as Edge],\n });\n return edge as Edge;\n }\n\n override removeNode(id: string): ReactiveGraphModel<Node, Edge> {\n const current = this._registry.get(this._graphAtom);\n const removedEdges = current.edges.filter((edge) => edge.source === id || edge.target === id);\n const removedNodes = current.nodes.filter((node) => node.id === id);\n\n this._registry.set(this._graphAtom, {\n nodes: current.nodes.filter((node) => node.id !== id),\n edges: current.edges.filter((edge) => edge.source !== id && edge.target !== id),\n });\n\n return this.copy({ nodes: removedNodes, edges: removedEdges });\n }\n\n override removeEdge(id: string): ReactiveGraphModel<Node, Edge> {\n const current = this._registry.get(this._graphAtom);\n const removedEdges = current.edges.filter((edge) => edge.id === id);\n\n this._registry.set(this._graphAtom, {\n ...current,\n edges: current.edges.filter((edge) => edge.id !== id),\n });\n\n return this.copy({ nodes: [], edges: removedEdges });\n }\n\n /**\n * Subscribe to graph changes.\n */\n subscribe(cb: Subscription, fire = false): () => void {\n if (fire) {\n cb(this, this.graph);\n }\n\n // Prime the atom by reading before subscribing to avoid double-fire on first mutation.\n this._registry.get(this._graphAtom);\n\n return this._registry.subscribe(this._graphAtom, () => {\n cb(this, this.graph);\n });\n }\n}\n\n/**\n * Basic builder.\n */\nexport class Builder<\n Node extends Graph.Node.Any = Graph.Node.Any,\n Edge extends Graph.Edge.Any = Graph.Edge.Any,\n> extends AbstractBuilder<Node, Edge, GraphModel<Node, Edge>> {\n override call(cb: (builder: this) => void): this {\n cb(this);\n return this;\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;AAIA,SAASA,MAAMC,gBAAgB;AAE/B,SAASC,iBAAiB
|
|
6
|
-
"names": ["Atom", "Registry", "invariant", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Atom, Registry } from '@effect-atom/atom-react';\n\nimport { invariant } from '@dxos/invariant';\n\nexport type SelectionMode = 'single' | 'multi';\n\nexport type SelectionModelProps = {\n mode?: SelectionMode;\n};\n\n/**\n * Reactive selection model.\n */\n// TODO(burdon): Reconcile with react-ui-attention.\nexport class SelectionModel {\n private readonly _registry: Registry.Registry;\n private readonly _selected: Atom.Writable<Set<string>>;\n private readonly _mode: SelectionMode;\n\n constructor({ mode = 'multi' }: SelectionModelProps = {}) {\n this._registry = Registry.make();\n this._selected = Atom.make<Set<string>>(new Set<string>());\n this._mode = mode;\n }\n\n /**\n * Returns the selected IDs atom for subscription.\n */\n get selected(): Atom.Atom<Set<string>> {\n return this._selected;\n }\n\n /**\n * Gets the current selected IDs as a Set.\n */\n getSelected(): Set<string> {\n return this._registry.get(this._selected);\n }\n\n /**\n * Gets the current selected IDs as an array.\n */\n getSelectedIds(): string[] {\n return Array.from(this._registry.get(this._selected).values());\n }\n\n /**\n * Subscribe to selection changes.\n */\n subscribe(cb: (selected: Set<string>) => void): () => void {\n // Prime the atom by reading before subscribing.\n this._registry.get(this._selected);\n\n return this._registry.subscribe(this._selected, () => {\n cb(this._registry.get(this._selected));\n });\n }\n\n toJSON(): { selected: string[] } {\n return {\n selected: this.getSelectedIds(),\n };\n }\n\n /**\n * Gets the current selection size.\n */\n getSize(): number {\n return this._registry.get(this._selected).size;\n }\n\n contains(id: string): boolean {\n return this._registry.get(this._selected).has(id);\n }\n\n clear(): void {\n this._registry.set(this._selected, new Set());\n }\n\n add(id: string): void {\n invariant(id);\n const current = this._registry.get(this._selected);\n this._registry.set(\n this._selected,\n new Set<string>(this._mode === 'single' ? [id] : [...Array.from(current.values()), id]),\n );\n }\n\n remove(id: string): void {\n invariant(id);\n const current = this._registry.get(this._selected);\n this._registry.set(this._selected, new Set<string>(Array.from(current.values()).filter((_id) => _id !== id)));\n }\n\n // TODO(burdon): Handle single select.\n\n setSelected(ids: string[], subtract = false): void {\n const current = this._registry.get(this._selected);\n this._registry.set(this._selected, new Set([...(subtract ? Array.from(current.values()) : []), ...ids]));\n }\n\n toggleSelected(ids: string[], subtract = false): void {\n const current = this._registry.get(this._selected);\n const set = new Set<string>(subtract ? Array.from(current.values()) : undefined);\n ids.forEach((id) => {\n if (current.has(id)) {\n set.delete(id);\n } else {\n set.add(id);\n }\n });\n\n this._registry.set(this._selected, set);\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Schema from 'effect/Schema';\n\nimport { invariant } from '@dxos/invariant';\nimport { type Specialize } from '@dxos/util';\n\n//\n// Node\n//\n\nexport const Node = Schema.Struct({\n id: Schema.String,\n type: Schema.optional(Schema.String),\n data: Schema.optional(Schema.Any),\n});\n\ninterface BaseNode extends Schema.Schema.Type<typeof Node> {}\n\nexport declare namespace Node {\n export type Any = Specialize<BaseNode, { data?: any }>;\n export type Node<Data = any> = Specialize<BaseNode, { data: Data }>;\n}\n\n//\n// Edge\n//\n\nexport const Edge = Schema.Struct({\n id: Schema.String,\n type: Schema.optional(Schema.String),\n source: Schema.String,\n target: Schema.String,\n data: Schema.optional(Schema.Any),\n});\n\ninterface BaseEdge extends Schema.Schema.Type<typeof Edge> {}\n\nexport declare namespace Edge {\n export type Any = Specialize<BaseEdge, { data?: any }>;\n export type Edge<Data = any> = Specialize<BaseEdge, { data: Data }>;\n}\n\nconst KEY_REGEX = /\\w+/;\n\n// NOTE: The `relation` is different from the `type`.\ntype EdgeMeta = { source: string; target: string; relation?: string };\n\nexport const createEdgeId = ({ source, target, relation }: EdgeMeta) => {\n invariant(source.match(KEY_REGEX), `invalid source: ${source}`);\n invariant(target.match(KEY_REGEX), `invalid target: ${target}`);\n return [source, relation, target].join('_');\n};\n\nexport const parseEdgeId = (id: string): EdgeMeta => {\n const [source, relation, target] = id.split('_');\n invariant(source.length && target.length);\n return { source, relation: relation.length ? relation : undefined, target };\n};\n\n//\n// Graph\n//\n\nexport const Graph = Schema.Struct({\n id: Schema.optional(Schema.String),\n nodes: Schema.mutable(Schema.Array(Node)),\n edges: Schema.mutable(Schema.Array(Edge)),\n});\n\nexport interface Any extends Schema.Schema.Type<typeof Graph> {}\n\nexport type Graph<Node extends Node.Any, Edge extends Edge.Any> = Specialize<\n Any,\n {\n nodes: Node[];\n edges: Edge[];\n }\n>;\n", "//\n// Copyright 2024 DXOS.org\n//\n\n// @import-as-namespace\n\nimport { Atom, type Registry } from '@effect-atom/atom-react';\n\nimport { inspectCustom } from '@dxos/debug';\nimport { failedInvariant, invariant } from '@dxos/invariant';\nimport { type MakeOptional, isTruthy, removeBy } from '@dxos/util';\n\nimport * as Graph from './Graph';\n\n/**\n * Optional function to wrap mutations (e.g., for ECHO objects that require Obj.update).\n */\nexport type GraphChangeFunction = (fn: () => void) => void;\n\n/**\n * Readonly Graph wrapper.\n */\nexport class ReadonlyGraphModel<\n Node extends Graph.Node.Any = Graph.Node.Any,\n Edge extends Graph.Edge.Any = Graph.Edge.Any,\n> {\n protected readonly _graph: Graph.Graph<Node, Edge>;\n /**\n * Optional function to wrap mutations.\n * When set, all graph mutations are wrapped in this function.\n */\n protected readonly _change?: GraphChangeFunction;\n\n /**\n * NOTE: Pass in simple Graph or Live.\n * @param graph - The graph data.\n * @param change - Optional function to wrap mutations (e.g., Obj.update for ECHO objects).\n */\n constructor(graph?: Graph.Graph<Node, Edge>, change?: GraphChangeFunction) {\n this._graph = graph ?? {\n nodes: [],\n edges: [],\n };\n this._change = change;\n }\n\n [inspectCustom]() {\n return this.toJSON();\n }\n\n /**\n * Return stable sorted JSON representation of graph.\n */\n toJSON() {\n return {\n nodes: this.nodes.length,\n edges: this.edges.length,\n };\n }\n\n get graph(): Graph.Graph<Node, Edge> {\n return this._graph;\n }\n\n get nodes(): Node[] {\n return this._graph.nodes;\n }\n\n get edges(): Edge[] {\n return this._graph.edges;\n }\n\n //\n // Nodes\n //\n\n findNode(id: string): Node | undefined {\n return this.nodes.find((node) => node.id === id);\n }\n\n getNode(id: string): Node {\n return this.findNode(id) ?? failedInvariant();\n }\n\n filterNodes({ type }: Partial<Graph.Node.Any> = {}): Node[] {\n return this.nodes.filter((node) => !type || type === node.type);\n }\n\n //\n // Edges\n //\n\n findEdge(id: string): Edge | undefined {\n return this.edges.find((edge) => edge.id === id);\n }\n\n getEdge(id: string): Edge {\n return this.findEdge(id) ?? failedInvariant();\n }\n\n filterEdges({ type, source, target }: Partial<Graph.Edge.Any> = {}): Edge[] {\n return this.edges.filter(\n (edge) =>\n (!type || type === edge.type) && (!source || source === edge.source) && (!target || target === edge.target),\n );\n }\n\n //\n // Traverse\n //\n\n traverse(root: Node): Node[] {\n return this._traverse(root);\n }\n\n private _traverse(root: Node, visited: Set<string> = new Set()): Node[] {\n if (visited.has(root.id)) {\n return [];\n }\n\n visited.add(root.id);\n const targets = this.filterEdges({ source: root.id })\n .map((edge) => this.getNode(edge.target))\n .filter(isTruthy);\n\n return [root, ...targets.flatMap((target) => this._traverse(target, visited))];\n }\n}\n\n/**\n * Mutable Graph wrapper.\n */\nexport abstract class AbstractGraphModel<\n Node extends Graph.Node.Any = Graph.Node.Any,\n Edge extends Graph.Edge.Any = Graph.Edge.Any,\n Model extends AbstractGraphModel<Node, Edge, Model, Builder> = any,\n Builder extends AbstractBuilder<Node, Edge, Model> = AbstractBuilder<Node, Edge, Model>,\n> extends ReadonlyGraphModel<Node, Edge> {\n /**\n * Allows chaining.\n */\n abstract get builder(): Builder;\n\n /**\n * Shallow copy of provided graph.\n */\n abstract copy(graph?: Partial<Graph.Graph<Node, Edge>>): Model;\n\n /**\n * Execute a mutation on the graph.\n * If a change function is set, wraps the mutation in it.\n */\n protected _mutate(fn: (graph: Graph.Graph<Node, Edge>) => void): void {\n if (this._change != null) {\n this._change(() => fn(this._graph));\n } else {\n fn(this._graph);\n }\n }\n\n clear(): this {\n this._mutate((graph) => {\n graph.nodes.length = 0;\n graph.edges.length = 0;\n });\n return this;\n }\n\n addGraph(graph: Model): this {\n this.addNodes(graph.nodes);\n this.addEdges(graph.edges);\n return this;\n }\n\n addGraphs(graphs: Model[]): this {\n graphs.forEach((graph) => {\n this.addNodes(graph.nodes);\n this.addEdges(graph.edges);\n });\n return this;\n }\n\n addNode(node: Node): Node {\n invariant(node.id, 'ID is required');\n invariant(!this.findNode(node.id), `node already exists: ${node.id}`);\n this._mutate((graph) => {\n graph.nodes.push(node);\n });\n return node;\n }\n\n addNodes(nodes: Node[]): Node[] {\n return nodes.map((node) => this.addNode(node));\n }\n\n addEdge(edge: MakeOptional<Edge, 'id'>): Edge {\n invariant(edge.source);\n invariant(edge.target);\n if (!edge.id) {\n // TODO(burdon): Generate random id.\n edge = { id: Graph.createEdgeId(edge), ...edge };\n }\n invariant(!this.findNode(edge.id!));\n this._mutate((graph) => {\n graph.edges.push(edge as Edge);\n });\n return edge as Edge;\n }\n\n addEdges(edges: Edge[]): Edge[] {\n return edges.map((edge) => this.addEdge(edge));\n }\n\n removeNode(id: string): Model {\n let removedEdges: Edge[] = [];\n let removedNodes: Node[] = [];\n this._mutate((graph) => {\n removedEdges = removeBy<Edge>(graph.edges as Edge[], (edge) => edge.source === id || edge.target === id);\n removedNodes = removeBy<Node>(graph.nodes as Node[], (node) => node.id === id);\n });\n return this.copy({ nodes: removedNodes, edges: removedEdges });\n }\n\n removeNodes(ids: string[]): Model {\n const graphs = ids.map((id) => this.removeNode(id));\n return this.copy().addGraphs(graphs);\n }\n\n removeEdge(id: string): Model {\n let removedEdges: Edge[] = [];\n this._mutate((graph) => {\n removedEdges = removeBy<Edge>(graph.edges as Edge[], (edge) => edge.id === id);\n });\n return this.copy({ nodes: [], edges: removedEdges });\n }\n\n removeEdges(ids: string[]): Model {\n const graphs = ids.map((id) => this.removeEdge(id));\n return this.copy().addGraphs(graphs);\n }\n}\n\n/**\n * Chainable builder wrapper\n */\nexport abstract class AbstractBuilder<\n Node extends Graph.Node.Any,\n Edge extends Graph.Edge.Any,\n Model extends GraphModel<Node, Edge>,\n> {\n constructor(protected readonly _model: Model) {}\n\n get model(): Model {\n return this._model;\n }\n\n call(cb: (builder: this) => void): this {\n cb(this);\n return this;\n }\n\n getNode(id: string): Node {\n return this.model.getNode(id);\n }\n\n addNode(node: Node): this {\n this._model.addNode(node);\n return this;\n }\n\n addEdge(edge: MakeOptional<Edge, 'id'>): this {\n this._model.addEdge(edge);\n return this;\n }\n\n addNodes(nodes: Node[]): this {\n this._model.addNodes(nodes);\n return this;\n }\n\n addEdges(edges: Edge[]): this {\n this._model.addEdges(edges);\n return this;\n }\n}\n\n/**\n * Basic model.\n */\nexport class GraphModel<\n Node extends Graph.Node.Any = Graph.Node.Any,\n Edge extends Graph.Edge.Any = Graph.Edge.Any,\n> extends AbstractGraphModel<Node, Edge, GraphModel<Node, Edge>, Builder<Node, Edge>> {\n override get builder() {\n return new Builder<Node, Edge>(this);\n }\n\n override copy(graph?: Partial<Graph.Graph<Node, Edge>>): GraphModel<Node, Edge> {\n return new GraphModel<Node, Edge>(graph as Graph.Graph<Node, Edge>);\n }\n}\n\nexport type Subscription = <Node extends Graph.Node.Any = Graph.Node.Any, Edge extends Graph.Edge.Any = Graph.Edge.Any>(\n model: ReactiveGraphModel<Node, Edge>,\n graph: Graph.Graph<Node, Edge>,\n) => void;\n\n/**\n * Basic reactive model using Effect Atoms.\n */\n// NOTE: Unlike Preact Signals' `live()` which uses proxies for transparent reactivity,\n// Effect Atom requires explicit `registry.set()` calls. All mutation methods must be\n// overridden to update the atom immutably rather than mutating `_graph` directly.\nexport class ReactiveGraphModel<\n Node extends Graph.Node.Any = Graph.Node.Any,\n Edge extends Graph.Edge.Any = Graph.Edge.Any,\n> extends GraphModel<Node, Edge> {\n private readonly _graphAtom: Atom.Writable<Graph.Graph<Node, Edge>>;\n\n constructor(\n private readonly _registry: Registry.Registry,\n graph?: Partial<Graph.Graph<Node, Edge>>,\n ) {\n const initialGraph: Graph.Graph<Node, Edge> = {\n nodes: (graph?.nodes ?? []) as Node[],\n edges: (graph?.edges ?? []) as Edge[],\n };\n super(initialGraph);\n this._graphAtom = Atom.make<Graph.Graph<Node, Edge>>(initialGraph);\n }\n\n get registry(): Registry.Registry {\n return this._registry;\n }\n\n /**\n * Get the graph atom for reactive subscriptions.\n */\n get graphAtom(): Atom.Writable<Graph.Graph<Node, Edge>> {\n return this._graphAtom;\n }\n\n override get graph(): Graph.Graph<Node, Edge> {\n return this._registry.get(this._graphAtom);\n }\n\n override get nodes(): Node[] {\n return this.graph.nodes;\n }\n\n override get edges(): Edge[] {\n return this.graph.edges;\n }\n\n override copy(graph?: Partial<Graph.Graph<Node, Edge>>): ReactiveGraphModel<Node, Edge> {\n return new ReactiveGraphModel<Node, Edge>(this._registry, graph);\n }\n\n override clear(): this {\n this._registry.set(this._graphAtom, {\n nodes: [],\n edges: [],\n });\n return this;\n }\n\n /**\n * Set the entire graph at once, triggering a single notification.\n */\n setGraph(graph: Graph.Graph<Node, Edge>): this {\n this._registry.set(this._graphAtom, graph);\n return this;\n }\n\n override addNode(node: Node): Node {\n invariant(node.id, 'ID is required');\n invariant(!this.findNode(node.id), `node already exists: ${node.id}`);\n const current = this._registry.get(this._graphAtom);\n this._registry.set(this._graphAtom, {\n ...current,\n nodes: [...current.nodes, node],\n });\n return node;\n }\n\n override addEdge(edge: MakeOptional<Edge, 'id'>): Edge {\n invariant(edge.source);\n invariant(edge.target);\n if (!edge.id) {\n edge = { id: Graph.createEdgeId(edge), ...edge };\n }\n invariant(!this.findNode(edge.id!));\n const current = this._registry.get(this._graphAtom);\n this._registry.set(this._graphAtom, {\n ...current,\n edges: [...current.edges, edge as Edge],\n });\n return edge as Edge;\n }\n\n override removeNode(id: string): ReactiveGraphModel<Node, Edge> {\n const current = this._registry.get(this._graphAtom);\n const removedEdges = current.edges.filter((edge) => edge.source === id || edge.target === id);\n const removedNodes = current.nodes.filter((node) => node.id === id);\n\n this._registry.set(this._graphAtom, {\n nodes: current.nodes.filter((node) => node.id !== id),\n edges: current.edges.filter((edge) => edge.source !== id && edge.target !== id),\n });\n\n return this.copy({ nodes: removedNodes, edges: removedEdges });\n }\n\n override removeEdge(id: string): ReactiveGraphModel<Node, Edge> {\n const current = this._registry.get(this._graphAtom);\n const removedEdges = current.edges.filter((edge) => edge.id === id);\n\n this._registry.set(this._graphAtom, {\n ...current,\n edges: current.edges.filter((edge) => edge.id !== id),\n });\n\n return this.copy({ nodes: [], edges: removedEdges });\n }\n\n /**\n * Subscribe to graph changes.\n */\n subscribe(cb: Subscription, fire = false): () => void {\n if (fire) {\n cb(this, this.graph);\n }\n\n // Prime the atom by reading before subscribing to avoid double-fire on first mutation.\n this._registry.get(this._graphAtom);\n\n return this._registry.subscribe(this._graphAtom, () => {\n cb(this, this.graph);\n });\n }\n}\n\n/**\n * Basic builder.\n */\nexport class Builder<\n Node extends Graph.Node.Any = Graph.Node.Any,\n Edge extends Graph.Edge.Any = Graph.Edge.Any,\n> extends AbstractBuilder<Node, Edge, GraphModel<Node, Edge>> {\n override call(cb: (builder: this) => void): this {\n cb(this);\n return this;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;AAIA,SAASA,MAAMC,gBAAgB;AAE/B,SAASC,iBAAiB;AAQ1B,IAAA,eAAA;AAMmBC,IAAAA,iBAAAA,MAAsC;EACtCC;EAEjB;;cAEOD,EAAAA,OAAYH,QAAKK,IAAkB,CAAA,GAAIC;AAC5C,SAAKF,YAAQG,SAAAA,KAAAA;AACf,SAAA,YAAA,KAAA,KAAA,oBAAA,IAAA,CAAA;AAEA,SAAA,QAAA;;;;;EAKA,IAAA,WAAA;AAEA,WAAA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AAA,WAAA,EAAA;;WAAuB/B,KAAOkC,KAAAA;MAAa,OAAA;MAC9D,OAAA;IAESI,CAAAA;;aAEDJ,IAAAA;AAEN,UAAKW,UAAUI,KAAI,UAAKN,IAAU,KAAE,UAAA;UAClC,eAAU,QAAA,MAAA,OAAA,CAAA,SAAA,KAAA,OAAA,EAAA;SACV3C,UAAOgD,IAAQhD,KAAK,YAAS+B;MAC/B,GAAA;MAEA,OAAW,QAAM,MAAA,OAAA,CAAA,SAAA,KAAA,OAAA,EAAA;;WAAa/B,KAAOkC,KAAAA;MAAa,OAAA,CAAA;MACpD,OAAA;IAEA,CAAA;;;;;YAKO,IAAI,OAAO/B,OAAK;AACrB,QAAA,MAAA;AAEA,SAAA,MAAA,KAAA,KAAA;IACA;SAGEiD,UAAS,IAAKjD,KAAK,UAAA;AACrB,WAAA,KAAA,UAAA,UAAA,KAAA,YAAA,MAAA;AACF,SAAA,MAAA,KAAA,KAAA;IACF,CAAA;EAEA;;AAQO,IAAI,UAAJ,cAAI,gBAAA;OACP,IAAA;AACF,OAAA,IAAA;AACF,WAAA;;;",
|
|
6
|
+
"names": ["Atom", "Registry", "invariant", "_selected", "_mode", "make", "Set", "mode", "_registry", "cb", "get", "toJSON", "selected", "contains", "clear", "id", "remove", "current", "Array", "values", "filter", "_id", "setSelected", "subtract", "ids", "toggleSelected", "set", "forEach", "has", "delete", "add", "Schema", "invariant", "__dxlog_file", "type", "String", "data", "source", "target", "optional", "KEY_REGEX", "relation", "join", "parseEdgeId", "nodes", "Array", "edges", "Atom", "inspectCustom", "failedInvariant", "invariant", "isTruthy", "removeBy", "__dxlog_file", "nodes", "edges", "_change", "inspectCustom", "graph", "getNode", "filterNodes", "type", "getEdge", "filterEdges", "source", "target", "_traverse", "root", "visited", "Set", "id", "targets", "fn", "_graph", "clear", "addGraph", "addEdges", "addGraphs", "graphs", "addNodes", "addNode", "node", "invariant", "_mutate", "push", "addEdge", "edge", "removeNode", "removedNodes", "removedEdges", "removeBy", "removeNodes", "copy", "removeEdge", "removeEdges", "_model", "model", "call", "_graphAtom", "initialGraph", "_registry", "registry", "Atom", "current", "set", "Graph", "filter", "cb"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/selection.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/selection.ts":{"bytes":10953,"imports":[{"path":"@effect-atom/atom-react","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true}],"format":"esm"},"src/Graph.ts":{"bytes":6561,"imports":[{"path":"effect/Schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true}],"format":"esm"},"src/GraphModel.ts":{"bytes":39344,"imports":[{"path":"@effect-atom/atom-react","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"src/Graph.ts","kind":"import-statement","original":"./Graph"}],"format":"esm"},"src/index.ts":{"bytes":679,"imports":[{"path":"src/selection.ts","kind":"import-statement","original":"./selection"},{"path":"src/Graph.ts","kind":"import-statement","original":"./Graph"},{"path":"src/GraphModel.ts","kind":"import-statement","original":"./GraphModel"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":28014},"dist/lib/browser/index.mjs":{"imports":[{"path":"@effect-atom/atom-react","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"effect/Schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@effect-atom/atom-react","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["Graph","GraphModel","SelectionModel"],"entryPoint":"src/index.ts","inputs":{"src/selection.ts":{"bytesInOutput":2620},"src/index.ts":{"bytesInOutput":0},"src/Graph.ts":{"bytesInOutput":1691},"src/GraphModel.ts":{"bytesInOutput":9582}},"bytes":14246}}}
|