effect-atom-svelte-devtools 0.2.2 → 0.4.0
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/README.md +3 -2
- package/dist/atom-devtools.svelte +151 -40
- package/dist/atom-devtools.svelte.d.ts +2 -1
- package/dist/graph/atom-graph.svelte +37 -9
- package/dist/graph/frame-graph.svelte +45 -37
- package/dist/graph/frame-graph.svelte.d.ts +1 -24
- package/dist/graph/graph-types.d.ts +28 -0
- package/dist/graph/graph-types.js +2 -0
- package/dist/graph/index.d.ts +1 -1
- package/dist/graph/layout.d.ts +5 -2
- package/dist/graph/layout.js +5 -4
- package/dist/internal/format.js +14 -7
- package/dist/internal/graph-view.svelte +23 -16
- package/dist/internal/label.js +40 -17
- package/dist/internal/model.svelte.js +39 -29
- package/dist/internal/names.js +4 -1
- package/dist/internal/settings-view.svelte +35 -8
- package/dist/internal/sheets-view.svelte +112 -36
- package/dist/internal/shortcut.js +6 -5
- package/dist/internal/timeline-view.svelte +71 -23
- package/dist/internal/transform.js +112 -82
- package/dist/vite.js +1 -1
- package/package.json +11 -10
|
@@ -25,6 +25,19 @@ export const componentName = (file) => path
|
|
|
25
25
|
.map((part) => part[0]?.toUpperCase() + part.slice(1))
|
|
26
26
|
.join("") || "Component";
|
|
27
27
|
const parser = Parser.extend(tsPlugin());
|
|
28
|
+
// The parser gives every node a type, a start and an end; a type is what tells one from data.
|
|
29
|
+
const isNode = (value) => typeof value === "object" &&
|
|
30
|
+
value !== null &&
|
|
31
|
+
"type" in value &&
|
|
32
|
+
typeof value.type === "string";
|
|
33
|
+
/** The node a field holds, if it holds one. */
|
|
34
|
+
const child = (value) => isNode(value) ? value : undefined;
|
|
35
|
+
/** The nodes a list field holds. */
|
|
36
|
+
const children = (value) => Array.isArray(value) ? value.filter(isNode) : [];
|
|
37
|
+
/** An identifier's name: `todosAtom`. */
|
|
38
|
+
const identifierName = (node) => node?.type === "Identifier" && typeof node.name === "string"
|
|
39
|
+
? node.name
|
|
40
|
+
: undefined;
|
|
28
41
|
// Type annotations around the call, as in `Atom.make(0) as Atom.Writable<number>`, are looked
|
|
29
42
|
// through: only the call is wrapped.
|
|
30
43
|
const wrappers = new Set([
|
|
@@ -34,41 +47,59 @@ const wrappers = new Set([
|
|
|
34
47
|
"TSTypeAssertion",
|
|
35
48
|
"ParenthesizedExpression",
|
|
36
49
|
]);
|
|
37
|
-
const unwrap = (node) =>
|
|
38
|
-
|
|
39
|
-
|
|
50
|
+
const unwrap = (node) => {
|
|
51
|
+
const inner = wrappers.has(node.type) ? child(node.expression) : undefined;
|
|
52
|
+
return inner === undefined ? node : unwrap(inner);
|
|
53
|
+
};
|
|
54
|
+
/** The node a field holds, with its type annotations looked through. */
|
|
55
|
+
const unwrapped = (value) => {
|
|
56
|
+
const node = child(value);
|
|
57
|
+
return node === undefined ? undefined : unwrap(node);
|
|
58
|
+
};
|
|
59
|
+
/** The next node down a callee chain: a member's object, a call's callee, an annotation's expression. */
|
|
60
|
+
const chainNext = (node) => {
|
|
40
61
|
if (node.type === "MemberExpression") {
|
|
41
|
-
return
|
|
62
|
+
return child(node.object);
|
|
42
63
|
}
|
|
43
64
|
if (node.type === "CallExpression") {
|
|
44
|
-
return
|
|
65
|
+
return child(node.callee);
|
|
45
66
|
}
|
|
46
|
-
return wrappers.has(node.type) ?
|
|
67
|
+
return wrappers.has(node.type) ? child(node.expression) : undefined;
|
|
68
|
+
};
|
|
69
|
+
/** The identifier a callee chain starts from: `Atom` in `Atom.make(...).pipe(...)`. */
|
|
70
|
+
const chainStart = (node) => {
|
|
71
|
+
const next = chainNext(node);
|
|
72
|
+
return next === undefined ? node : chainStart(next);
|
|
47
73
|
};
|
|
48
74
|
/**
|
|
49
75
|
* A call to wrap, or `undefined`. Svelte's runes (`$state(...)`, `$derived.by(...)`) must stay as
|
|
50
76
|
* they are, and hooks (`useAtomValue(...)`) never return an atom, so both are left be.
|
|
51
77
|
*/
|
|
52
78
|
const call = (init) => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
const node = unwrap(init);
|
|
57
|
-
if (node.type !== "CallExpression") {
|
|
79
|
+
const node = unwrapped(init);
|
|
80
|
+
if (node?.type !== "CallExpression") {
|
|
58
81
|
return undefined;
|
|
59
82
|
}
|
|
60
|
-
const start = chainStart(node
|
|
61
|
-
if (start
|
|
62
|
-
/^(?:\$|use[A-Z])/u.test(String(start.name))) {
|
|
83
|
+
const start = identifierName(chainStart(node));
|
|
84
|
+
if (start !== undefined && /^(?:\$|use[A-Z])/u.test(start)) {
|
|
63
85
|
return undefined;
|
|
64
86
|
}
|
|
65
87
|
return node;
|
|
66
88
|
};
|
|
67
89
|
/** Whether the call is `Atom.family(...)` (or a bare `family(...)`), whose members are labelled. */
|
|
68
90
|
const isFamily = (node) => {
|
|
69
|
-
const callee = node.callee;
|
|
70
|
-
const property = callee
|
|
71
|
-
return property
|
|
91
|
+
const callee = child(node.callee);
|
|
92
|
+
const property = callee?.type === "MemberExpression" ? child(callee.property) : callee;
|
|
93
|
+
return identifierName(property) === "family";
|
|
94
|
+
};
|
|
95
|
+
/** The method a member expression takes from `Atom`: `make` in `Atom.make`. */
|
|
96
|
+
const atomMethod = (node) => {
|
|
97
|
+
if (node?.type !== "MemberExpression") {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
return identifierName(child(node.object)) === "Atom"
|
|
101
|
+
? identifierName(child(node.property))
|
|
102
|
+
: undefined;
|
|
72
103
|
};
|
|
73
104
|
// The arguments `Atom.make` takes as a plain value, rather than a function or an effect.
|
|
74
105
|
const plainValues = new Set([
|
|
@@ -95,58 +126,52 @@ const stateKeeping = new Set([
|
|
|
95
126
|
/** Whether `Atom.keepAlive`, `Atom.setIdleTTL(...)` or the like: one of `stateKeeping`. */
|
|
96
127
|
const keepsState = (argument) => {
|
|
97
128
|
const node = unwrap(argument);
|
|
98
|
-
const callee = node.type === "CallExpression" ?
|
|
99
|
-
return (callee.
|
|
100
|
-
!callee.computed &&
|
|
101
|
-
callee.object.type === "Identifier" &&
|
|
102
|
-
callee.object.name === "Atom" &&
|
|
103
|
-
stateKeeping.has(String(callee.property.name)));
|
|
129
|
+
const callee = node.type === "CallExpression" ? unwrapped(node.callee) : node;
|
|
130
|
+
return (callee?.computed !== true && stateKeeping.has(atomMethod(callee) ?? ""));
|
|
104
131
|
};
|
|
105
132
|
/**
|
|
106
133
|
* Whether the call makes a state atom, such as `Atom.make(0)` or `Atom.make([]).pipe(...)`: one
|
|
107
134
|
* that holds what is written to it, which a hot reload can carry over.
|
|
108
135
|
*/
|
|
109
136
|
const isState = (node) => {
|
|
110
|
-
const callee = node.callee;
|
|
111
|
-
if (callee
|
|
137
|
+
const callee = child(node.callee);
|
|
138
|
+
if (callee?.type !== "MemberExpression") {
|
|
112
139
|
return false;
|
|
113
140
|
}
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return (object
|
|
141
|
+
const args = children(node.arguments);
|
|
142
|
+
if (identifierName(child(callee.property)) === "pipe") {
|
|
143
|
+
const object = child(callee.object);
|
|
144
|
+
return (object?.type === "CallExpression" &&
|
|
118
145
|
isState(object) &&
|
|
119
|
-
|
|
146
|
+
args.every(keepsState));
|
|
120
147
|
}
|
|
121
|
-
const [argument] =
|
|
122
|
-
return (
|
|
123
|
-
object.name === "Atom" &&
|
|
124
|
-
property.type === "Identifier" &&
|
|
125
|
-
property.name === "make" &&
|
|
148
|
+
const [argument] = args;
|
|
149
|
+
return (atomMethod(callee) === "make" &&
|
|
126
150
|
argument !== undefined &&
|
|
127
151
|
plainValues.has(unwrap(argument).type));
|
|
128
152
|
};
|
|
129
153
|
/** A property's name, when it is written out: `todosAtom` in `{ todosAtom: ... }`. */
|
|
130
154
|
const propertyName = (property) => {
|
|
131
|
-
|
|
132
|
-
if (property.computed) {
|
|
155
|
+
if (property.computed === true) {
|
|
133
156
|
return undefined;
|
|
134
157
|
}
|
|
135
|
-
|
|
136
|
-
|
|
158
|
+
const key = child(property.key);
|
|
159
|
+
if (key?.type === "Identifier") {
|
|
160
|
+
return identifierName(key);
|
|
137
161
|
}
|
|
138
|
-
return key
|
|
162
|
+
return key?.type === "Literal" && typeof key.value === "string"
|
|
139
163
|
? key.value
|
|
140
164
|
: undefined;
|
|
141
165
|
};
|
|
142
166
|
/** Every node below `node`, depth first. */
|
|
143
167
|
const descendants = (node, found = []) => {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
168
|
+
const values = Object.values(node);
|
|
169
|
+
for (const value of values) {
|
|
170
|
+
const below = Array.isArray(value) ? value : [value];
|
|
171
|
+
for (const item of below) {
|
|
172
|
+
if (isNode(item)) {
|
|
173
|
+
found.push(item);
|
|
174
|
+
descendants(item, found);
|
|
150
175
|
}
|
|
151
176
|
}
|
|
152
177
|
}
|
|
@@ -175,18 +200,19 @@ const sites = (program, base, defaultName, once) => {
|
|
|
175
200
|
});
|
|
176
201
|
};
|
|
177
202
|
const members = (object, prefix) => {
|
|
178
|
-
for (const property of object.properties) {
|
|
179
|
-
const key = property.
|
|
180
|
-
|
|
203
|
+
for (const property of children(object.properties)) {
|
|
204
|
+
const key = child(property.key);
|
|
205
|
+
const name = property.type === "Property" ? propertyName(property) : undefined;
|
|
206
|
+
const value = unwrapped(property.value);
|
|
207
|
+
if (key === undefined || name === undefined || value === undefined) {
|
|
181
208
|
continue;
|
|
182
209
|
}
|
|
183
|
-
const value = unwrap(property.value);
|
|
184
210
|
const node = call(value);
|
|
185
211
|
if (node) {
|
|
186
|
-
add(node, `${prefix}.${
|
|
212
|
+
add(node, `${prefix}.${name}`, key.start);
|
|
187
213
|
}
|
|
188
214
|
else if (value.type === "ObjectExpression") {
|
|
189
|
-
members(value, `${prefix}.${
|
|
215
|
+
members(value, `${prefix}.${name}`);
|
|
190
216
|
}
|
|
191
217
|
}
|
|
192
218
|
};
|
|
@@ -194,25 +220,26 @@ const sites = (program, base, defaultName, once) => {
|
|
|
194
220
|
if (declaration.type !== "VariableDeclaration") {
|
|
195
221
|
return;
|
|
196
222
|
}
|
|
197
|
-
for (const declarator of declaration.declarations) {
|
|
223
|
+
for (const declarator of children(declaration.declarations)) {
|
|
198
224
|
handled.add(declarator);
|
|
199
|
-
const id = declarator.id;
|
|
200
|
-
|
|
225
|
+
const id = child(declarator.id);
|
|
226
|
+
const name = identifierName(id);
|
|
227
|
+
const init = unwrapped(declarator.init);
|
|
228
|
+
if (id === undefined || name === undefined || init === undefined) {
|
|
201
229
|
continue;
|
|
202
230
|
}
|
|
203
|
-
const init = unwrap(declarator.init);
|
|
204
231
|
const node = call(init);
|
|
205
232
|
if (node) {
|
|
206
|
-
add(node,
|
|
233
|
+
add(node, name, id.start);
|
|
207
234
|
}
|
|
208
235
|
else if (init.type === "ObjectExpression") {
|
|
209
|
-
members(init,
|
|
236
|
+
members(init, name);
|
|
210
237
|
}
|
|
211
238
|
}
|
|
212
239
|
};
|
|
213
|
-
for (const statement of program.body) {
|
|
240
|
+
for (const statement of children(program.body)) {
|
|
214
241
|
if (statement.type === "ExportNamedDeclaration") {
|
|
215
|
-
const
|
|
242
|
+
const declaration = child(statement.declaration);
|
|
216
243
|
if (declaration) {
|
|
217
244
|
declare(declaration);
|
|
218
245
|
}
|
|
@@ -231,14 +258,14 @@ const sites = (program, base, defaultName, once) => {
|
|
|
231
258
|
if (node.type !== "VariableDeclarator" || handled.has(node)) {
|
|
232
259
|
continue;
|
|
233
260
|
}
|
|
234
|
-
const id = node.id;
|
|
235
|
-
const
|
|
236
|
-
const
|
|
237
|
-
if (id
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
add(init,
|
|
261
|
+
const id = child(node.id);
|
|
262
|
+
const name = identifierName(id);
|
|
263
|
+
const init = call(node.init);
|
|
264
|
+
if (id !== undefined &&
|
|
265
|
+
name !== undefined &&
|
|
266
|
+
init !== undefined &&
|
|
267
|
+
identifierName(chainStart(init)) === "Atom") {
|
|
268
|
+
add(init, name, id.start, false);
|
|
242
269
|
}
|
|
243
270
|
}
|
|
244
271
|
return found;
|
|
@@ -252,14 +279,14 @@ const factoryName = /^(?!use[A-Z]|is[A-Z])[\w$]+Atom$/u;
|
|
|
252
279
|
* as `mapDraftAtom({"doc":1})`, so a cache that makes a new atom for a key it has seen shows it.
|
|
253
280
|
*/
|
|
254
281
|
const factoryCalls = (program, base) => descendants(program).flatMap((node) => {
|
|
255
|
-
const callee = node.type === "CallExpression" ? node.callee : undefined;
|
|
256
|
-
|
|
257
|
-
|
|
282
|
+
const callee = node.type === "CallExpression" ? child(node.callee) : undefined;
|
|
283
|
+
const name = identifierName(callee);
|
|
284
|
+
return callee !== undefined && name !== undefined && factoryName.test(name)
|
|
258
285
|
? [
|
|
259
286
|
{
|
|
260
287
|
calleeEnd: base + callee.end,
|
|
261
288
|
calleeStart: base + callee.start,
|
|
262
|
-
name
|
|
289
|
+
name,
|
|
263
290
|
},
|
|
264
291
|
]
|
|
265
292
|
: [];
|
|
@@ -319,12 +346,10 @@ const scripts = (source) => {
|
|
|
319
346
|
.map((m) => [m.index, m.index + m[0].length]);
|
|
320
347
|
for (const match of matches) {
|
|
321
348
|
const { attributes, code } = match.groups ?? {};
|
|
322
|
-
|
|
323
|
-
continue;
|
|
324
|
-
}
|
|
325
|
-
if (top
|
|
349
|
+
const nested = top
|
|
326
350
|
? !top.has(match.index)
|
|
327
|
-
: heads.some(([from, to]) => match.index > from && match.index < to)
|
|
351
|
+
: heads.some(([from, to]) => match.index > from && match.index < to);
|
|
352
|
+
if (attributes === undefined || code === undefined || nested) {
|
|
328
353
|
continue;
|
|
329
354
|
}
|
|
330
355
|
found.push({
|
|
@@ -378,12 +403,17 @@ const address = (file, root) => {
|
|
|
378
403
|
/** Wraps each labelled declaration's call in `label(...)`, and each factory's callee in `call(...)`. */
|
|
379
404
|
const wrap = (output, code, found, calls, where) => {
|
|
380
405
|
for (const site of found) {
|
|
381
|
-
const options = {
|
|
382
|
-
|
|
406
|
+
const options = {};
|
|
407
|
+
if (site.family) {
|
|
408
|
+
options.family = true;
|
|
409
|
+
}
|
|
410
|
+
if (site.keep) {
|
|
383
411
|
// The declaration's source, hashed: an edit to it means the old value no longer applies.
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
412
|
+
options.keep = hash(code.slice(site.start, site.end));
|
|
413
|
+
}
|
|
414
|
+
if (site.local) {
|
|
415
|
+
options.local = true;
|
|
416
|
+
}
|
|
387
417
|
const args = [
|
|
388
418
|
JSON.stringify(site.name),
|
|
389
419
|
JSON.stringify(where(site.at)),
|
package/dist/vite.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "effect-atom-svelte-devtools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Developer tools for effect-atom-svelte: atom names from your source, and a live view of the registry",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"devtools",
|
|
@@ -56,19 +56,20 @@
|
|
|
56
56
|
"magic-string": "^0.30.21"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@sveltejs/package": "^3.0.
|
|
60
|
-
"@sveltejs/vite-plugin-svelte": "^7.2
|
|
59
|
+
"@sveltejs/package": "^3.0.3",
|
|
60
|
+
"@sveltejs/vite-plugin-svelte": "^7.3.2",
|
|
61
61
|
"@types/node": "^24",
|
|
62
|
-
"effect": "4.
|
|
62
|
+
"effect": "4.1.7",
|
|
63
63
|
"effect-atom-svelte": "workspace:*",
|
|
64
|
-
"svelte": "^5.
|
|
65
|
-
"svelte-check": "^4.
|
|
66
|
-
"
|
|
67
|
-
"
|
|
64
|
+
"svelte": "^5.59.2",
|
|
65
|
+
"svelte-check": "^4.7.8",
|
|
66
|
+
"typescript": "^6.0.3",
|
|
67
|
+
"vite": "^8.3.4",
|
|
68
|
+
"vitest": "^5.0.5"
|
|
68
69
|
},
|
|
69
70
|
"peerDependencies": {
|
|
70
|
-
"effect": "~4.
|
|
71
|
-
"effect-atom-svelte": "^0.
|
|
71
|
+
"effect": "~4.1.0",
|
|
72
|
+
"effect-atom-svelte": "^0.5.0",
|
|
72
73
|
"svelte": "^5.57.2",
|
|
73
74
|
"vite": ">=5.0.0"
|
|
74
75
|
},
|