@fluixi/devtools 1.0.0-alpha.108 → 1.0.0-alpha.110
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/callsite.mjs +4 -63
- package/dist/change-view.mjs +6 -106
- package/dist/chunk-235BSS43.mjs +185 -0
- package/dist/chunk-2ACSNLS6.mjs +87 -0
- package/dist/chunk-2VDMQ3VF.mjs +520 -0
- package/dist/chunk-33U2S43X.mjs +121 -0
- package/dist/chunk-B3SAJ7QG.mjs +72 -0
- package/dist/chunk-BTCWJTXR.mjs +216 -0
- package/dist/chunk-CPZWLBCQ.mjs +35 -0
- package/dist/chunk-D25KZZBZ.mjs +212 -0
- package/dist/chunk-EBSROPWJ.mjs +314 -0
- package/dist/chunk-F664XLZL.mjs +743 -0
- package/dist/chunk-FY5K3QVT.mjs +35 -0
- package/dist/chunk-GDQXCOQB.mjs +43 -0
- package/dist/chunk-JLNWT36I.mjs +118 -0
- package/dist/chunk-JTHAZJJZ.mjs +780 -0
- package/dist/chunk-L6XQGNMW.mjs +106 -0
- package/dist/chunk-MN6O673L.mjs +90 -0
- package/dist/chunk-NDUBBBNL.mjs +70 -0
- package/dist/chunk-NT7YMK77.mjs +157 -0
- package/dist/chunk-NVULLJDH.mjs +120 -0
- package/dist/chunk-NWLSDERQ.mjs +68 -0
- package/dist/chunk-OPIGF5XB.mjs +184 -0
- package/dist/chunk-P5I7DWFX.mjs +292 -0
- package/dist/chunk-PSSBFXBD.mjs +155 -0
- package/dist/chunk-PTQ5VCYE.mjs +103 -0
- package/dist/chunk-UAEJ3N7F.mjs +76 -0
- package/dist/chunk-V6DKWEYD.mjs +67 -0
- package/dist/chunk-VO2V7AC5.mjs +80 -0
- package/dist/chunk-WGQH7RUW.mjs +25 -0
- package/dist/chunk-Z6KYHEKY.mjs +64 -0
- package/dist/copy.mjs +3 -39
- package/dist/describe.mjs +3 -31
- package/dist/detail-panel.cjs +2 -1
- package/dist/detail-panel.d.ts.map +1 -1
- package/dist/detail-panel.js +1 -0
- package/dist/detail-panel.mjs +6 -280
- package/dist/diff.mjs +4 -201
- package/dist/dom.mjs +7 -176
- package/dist/export.mjs +6 -207
- package/dist/float.mjs +5 -206
- package/dist/format.mjs +5 -151
- package/dist/graph-view.mjs +9 -875
- package/dist/highlight.mjs +6 -113
- package/dist/history.cjs +14 -2
- package/dist/history.d.ts +8 -1
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +15 -2
- package/dist/history.mjs +4 -70
- package/dist/hook.cjs +26 -1
- package/dist/hook.d.ts +4 -0
- package/dist/hook.d.ts.map +1 -1
- package/dist/hook.js +13 -0
- package/dist/hook.mjs +16 -1719
- package/dist/index.cjs +34 -5
- package/dist/index.mjs +106 -4673
- package/dist/inspector.mjs +11 -677
- package/dist/instrument.mjs +9 -486
- package/dist/kind-filter.mjs +6 -148
- package/dist/menu.mjs +4 -116
- package/dist/observe.cjs +15 -1
- package/dist/observe.d.ts +2 -0
- package/dist/observe.d.ts.map +1 -1
- package/dist/observe.js +3 -0
- package/dist/observe.mjs +14 -1510
- package/dist/palette.mjs +6 -28
- package/dist/path.mjs +3 -21
- package/dist/plugin.mjs +9 -57
- package/dist/plugins/context.mjs +6 -71
- package/dist/plugins/directives.mjs +8 -68
- package/dist/plugins/index.cjs +1 -1
- package/dist/plugins/index.mjs +13 -136
- package/dist/source.mjs +12 -93
- package/dist/timeline.cjs +5 -2
- package/dist/timeline.d.ts.map +1 -1
- package/dist/timeline.js +5 -1
- package/dist/timeline.mjs +7 -323
- package/dist/tree.mjs +11 -558
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/value-pane.mjs +6 -196
- package/dist/wire.cjs +1 -1
- package/dist/wire.mjs +6 -86
- package/package.json +3 -3
|
@@ -0,0 +1,780 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TREE_KINDS
|
|
3
|
+
} from "./chunk-2VDMQ3VF.mjs";
|
|
4
|
+
import {
|
|
5
|
+
createHistory
|
|
6
|
+
} from "./chunk-2ACSNLS6.mjs";
|
|
7
|
+
import {
|
|
8
|
+
devtoolsPlugins
|
|
9
|
+
} from "./chunk-V6DKWEYD.mjs";
|
|
10
|
+
import {
|
|
11
|
+
currentCallSite
|
|
12
|
+
} from "./chunk-NWLSDERQ.mjs";
|
|
13
|
+
import {
|
|
14
|
+
describeNode
|
|
15
|
+
} from "./chunk-CPZWLBCQ.mjs";
|
|
16
|
+
import {
|
|
17
|
+
diffValues
|
|
18
|
+
} from "./chunk-PTQ5VCYE.mjs";
|
|
19
|
+
import {
|
|
20
|
+
describeAll,
|
|
21
|
+
tagDepths
|
|
22
|
+
} from "./chunk-OPIGF5XB.mjs";
|
|
23
|
+
import {
|
|
24
|
+
KIND_OF_BUILTIN
|
|
25
|
+
} from "./chunk-EBSROPWJ.mjs";
|
|
26
|
+
import {
|
|
27
|
+
classSource,
|
|
28
|
+
componentSource,
|
|
29
|
+
dropReactiveSource,
|
|
30
|
+
holeLocation,
|
|
31
|
+
installSourceMarker,
|
|
32
|
+
propsLocations,
|
|
33
|
+
takeReactiveSource
|
|
34
|
+
} from "./chunk-L6XQGNMW.mjs";
|
|
35
|
+
import {
|
|
36
|
+
formatValue,
|
|
37
|
+
shorten
|
|
38
|
+
} from "./chunk-NT7YMK77.mjs";
|
|
39
|
+
|
|
40
|
+
// src/observe.ts
|
|
41
|
+
import {
|
|
42
|
+
createRoot,
|
|
43
|
+
observeReactiveNodes,
|
|
44
|
+
untrack
|
|
45
|
+
} from "@fluixi/reactive/signal";
|
|
46
|
+
function stampDocumentOrder(graph, rendered) {
|
|
47
|
+
const roots = [];
|
|
48
|
+
for (const node of graph.values()) {
|
|
49
|
+
if (!TREE_KINDS.has(node.kind)) continue;
|
|
50
|
+
const element = rendered(node.id)[0];
|
|
51
|
+
if (element?.isConnected) roots.push({ id: node.id, element });
|
|
52
|
+
}
|
|
53
|
+
roots.sort((a, b) => a.element.compareDocumentPosition(b.element) & 4 ? -1 : 1);
|
|
54
|
+
for (const node of graph.values()) node.order = void 0;
|
|
55
|
+
roots.forEach(({ id }, at) => {
|
|
56
|
+
const node = graph.get(id);
|
|
57
|
+
if (node) node.order = at;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
var REMOVED_LOG = 500;
|
|
61
|
+
var KINDS = {
|
|
62
|
+
signal: "state",
|
|
63
|
+
memo: "memo",
|
|
64
|
+
effect: "effect",
|
|
65
|
+
store: "store",
|
|
66
|
+
resource: "resource"
|
|
67
|
+
};
|
|
68
|
+
var HISTORY_VALUE = 80;
|
|
69
|
+
var SET_SITES = 8;
|
|
70
|
+
var PREFIX = {
|
|
71
|
+
state: "s",
|
|
72
|
+
memo: "m",
|
|
73
|
+
effect: "e",
|
|
74
|
+
store: "st",
|
|
75
|
+
resource: "r",
|
|
76
|
+
component: "c",
|
|
77
|
+
// Only the static graph makes these: at runtime control flow is a named memo, and a route
|
|
78
|
+
// handler never reaches a browser.
|
|
79
|
+
control: "x",
|
|
80
|
+
router: "rt",
|
|
81
|
+
handler: "h",
|
|
82
|
+
// Never produced here: these are cards a view draws, not nodes anything creates.
|
|
83
|
+
group: "g",
|
|
84
|
+
binding: "b",
|
|
85
|
+
setter: "w",
|
|
86
|
+
// A plugin's, and it names them itself.
|
|
87
|
+
directive: "d",
|
|
88
|
+
context: "ctx",
|
|
89
|
+
provider: "p",
|
|
90
|
+
// Scopes are always named by what opened them.
|
|
91
|
+
"custom-element": "el",
|
|
92
|
+
module: "mod",
|
|
93
|
+
service: "svc"
|
|
94
|
+
};
|
|
95
|
+
function readProps(props) {
|
|
96
|
+
if (readOnce.has(props)) return readOnce.get(props);
|
|
97
|
+
const at = propsLocations(props);
|
|
98
|
+
const out = [];
|
|
99
|
+
for (const name of Object.keys(props)) {
|
|
100
|
+
if (name === "children") continue;
|
|
101
|
+
const where = at?.[name];
|
|
102
|
+
const report = {
|
|
103
|
+
name,
|
|
104
|
+
...where ? { at: { line: where[0], column: where[1] } } : {}
|
|
105
|
+
};
|
|
106
|
+
try {
|
|
107
|
+
report.value = formatValue(
|
|
108
|
+
createRoot((dispose) => {
|
|
109
|
+
try {
|
|
110
|
+
return untrack(() => props[name]);
|
|
111
|
+
} finally {
|
|
112
|
+
dispose();
|
|
113
|
+
}
|
|
114
|
+
}),
|
|
115
|
+
200
|
|
116
|
+
);
|
|
117
|
+
} catch {
|
|
118
|
+
}
|
|
119
|
+
out.push(report);
|
|
120
|
+
}
|
|
121
|
+
const reports = out.length ? out : void 0;
|
|
122
|
+
readOnce.set(props, reports);
|
|
123
|
+
return reports;
|
|
124
|
+
}
|
|
125
|
+
var readOnce = /* @__PURE__ */ new WeakMap();
|
|
126
|
+
function observeGraph(options = {}) {
|
|
127
|
+
installSourceMarker();
|
|
128
|
+
const origin = options.origin ?? (typeof location === "object" ? location.origin : void 0);
|
|
129
|
+
const graph = /* @__PURE__ */ new Map();
|
|
130
|
+
const claims = (node, value) => {
|
|
131
|
+
for (const dep of node.deps) {
|
|
132
|
+
const other = graph.get(dep);
|
|
133
|
+
if (other?.read && readRaw(other) === value) return false;
|
|
134
|
+
}
|
|
135
|
+
return true;
|
|
136
|
+
};
|
|
137
|
+
const ids = /* @__PURE__ */ new WeakMap();
|
|
138
|
+
const through = /* @__PURE__ */ new WeakMap();
|
|
139
|
+
const internals = /* @__PURE__ */ new Set();
|
|
140
|
+
const targets = /* @__PURE__ */ new WeakMap();
|
|
141
|
+
const handed = /* @__PURE__ */ new Map();
|
|
142
|
+
const bindingSites = /* @__PURE__ */ new WeakMap();
|
|
143
|
+
const boundTo = /* @__PURE__ */ new WeakMap();
|
|
144
|
+
const drivenBy = /* @__PURE__ */ new WeakMap();
|
|
145
|
+
let reaches = /* @__PURE__ */ new Map();
|
|
146
|
+
const SCOPE_KINDS = /* @__PURE__ */ new Set(["custom-element", "module", "service"]);
|
|
147
|
+
const scopeIds = /* @__PURE__ */ new WeakMap();
|
|
148
|
+
const scopeOfTarget = /* @__PURE__ */ new WeakMap();
|
|
149
|
+
const fieldsOf = /* @__PURE__ */ new WeakMap();
|
|
150
|
+
let described = null;
|
|
151
|
+
let descendants = null;
|
|
152
|
+
const rendered = /* @__PURE__ */ new Map();
|
|
153
|
+
const elementsIn = (value) => {
|
|
154
|
+
if (value instanceof Element) return [value];
|
|
155
|
+
if (value instanceof DocumentFragment) return [...value.children];
|
|
156
|
+
if (Array.isArray(value)) return value.flatMap(elementsIn);
|
|
157
|
+
return [];
|
|
158
|
+
};
|
|
159
|
+
const cores = /* @__PURE__ */ new Map();
|
|
160
|
+
const setters = /* @__PURE__ */ new Map();
|
|
161
|
+
const runsAtLastSample = /* @__PURE__ */ new Map();
|
|
162
|
+
const unnamed = /* @__PURE__ */ new Set();
|
|
163
|
+
const recording = (options.history ?? 200) > 0;
|
|
164
|
+
const wantSites = options.bindingSources ?? true;
|
|
165
|
+
const mapped = (location2) => {
|
|
166
|
+
if (!options.mapSource) return location2;
|
|
167
|
+
try {
|
|
168
|
+
const found = options.mapSource(location2);
|
|
169
|
+
return found ? { ...location2, ...found, compiled: { line: location2.line, column: location2.column } } : location2;
|
|
170
|
+
} catch {
|
|
171
|
+
return location2;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
const history = createHistory(options.history ?? 200);
|
|
175
|
+
let seq = 0;
|
|
176
|
+
const raws = /* @__PURE__ */ new Map();
|
|
177
|
+
const readRaw = (node) => {
|
|
178
|
+
if (!node.read) return void 0;
|
|
179
|
+
try {
|
|
180
|
+
return untrack(() => node.read());
|
|
181
|
+
} catch {
|
|
182
|
+
return void 0;
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
const removed = [];
|
|
186
|
+
let revision = 0;
|
|
187
|
+
const revs = /* @__PURE__ */ new Map();
|
|
188
|
+
let drained = 0;
|
|
189
|
+
const onDirective = [];
|
|
190
|
+
const onContext = [];
|
|
191
|
+
const retyped = /* @__PURE__ */ new Map();
|
|
192
|
+
const contextSites = /* @__PURE__ */ new Map();
|
|
193
|
+
const elementExtra = /* @__PURE__ */ new WeakMap();
|
|
194
|
+
const ancestor = (parents) => {
|
|
195
|
+
if (!parents) return void 0;
|
|
196
|
+
for (let i = parents.length - 1; i >= 0; i--) {
|
|
197
|
+
const key = parents[i];
|
|
198
|
+
const found = ids.get(key) ?? through.get(key);
|
|
199
|
+
if (found !== void 0) return found;
|
|
200
|
+
}
|
|
201
|
+
return void 0;
|
|
202
|
+
};
|
|
203
|
+
const stop = (options.observe ?? observeReactiveNodes)({
|
|
204
|
+
created(report) {
|
|
205
|
+
const core = report.node;
|
|
206
|
+
if (!core || typeof core !== "object") return;
|
|
207
|
+
if (report.internal) {
|
|
208
|
+
const owner2 = ancestor(report.parents);
|
|
209
|
+
if (owner2 !== void 0) through.set(core, owner2);
|
|
210
|
+
internals.add(core);
|
|
211
|
+
if (wantSites) {
|
|
212
|
+
const site2 = currentCallSite(origin);
|
|
213
|
+
if (site2) bindingSites.set(core, mapped(site2.location));
|
|
214
|
+
}
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const id = seq++;
|
|
218
|
+
const handle = report.handle;
|
|
219
|
+
const mark = takeReactiveSource();
|
|
220
|
+
const base = KINDS[report.kind];
|
|
221
|
+
const marked = base === "memo" && mark?.name ? KIND_OF_BUILTIN[mark.name] : void 0;
|
|
222
|
+
const kind = (report.name ? KIND_OF_BUILTIN[report.name] : void 0) ?? marked ?? base;
|
|
223
|
+
const named = report.name ?? mark?.name;
|
|
224
|
+
if (!named) unnamed.add(id);
|
|
225
|
+
const site = mark?.location ? void 0 : currentCallSite(origin);
|
|
226
|
+
const node = {
|
|
227
|
+
id,
|
|
228
|
+
label: named ?? `${PREFIX[kind]}${id}`,
|
|
229
|
+
kind,
|
|
230
|
+
// Only a compiler mark means the author wrote this and gave it that name. A name
|
|
231
|
+
// the runtime supplies, such as `Show.when`, `mapArray` or `row index`, describes framework
|
|
232
|
+
// machinery, and so does no name at all.
|
|
233
|
+
authored: mark?.name != null,
|
|
234
|
+
deps: /* @__PURE__ */ new Set(),
|
|
235
|
+
// A write edge needs to know which consumer was running when a setter fired, and
|
|
236
|
+
// nothing observed records that. Reads carry the graph; writes do not.
|
|
237
|
+
writes: /* @__PURE__ */ new Set(),
|
|
238
|
+
runs: 0,
|
|
239
|
+
lastPulse: 0,
|
|
240
|
+
core,
|
|
241
|
+
// The application's line is where it was asked for; a package's is where it was made,
|
|
242
|
+
// and for a node made while that package loaded it is the only thing there is.
|
|
243
|
+
...mark?.location ? { source: mark.location } : {},
|
|
244
|
+
// Mapped, unlike `mark`: these two came off a stack, so they are positions in the
|
|
245
|
+
// compiled file until a host translates them.
|
|
246
|
+
...site && !site.external ? { usedAt: mapped(site.location) } : {},
|
|
247
|
+
// Not inside a scope: an element's prop is made by the package for the element, and
|
|
248
|
+
// the package's line says less than the scope it sits in already does.
|
|
249
|
+
...site && site.external && !mark?.location && !report.scope ? { source: mapped(site.location) } : {}
|
|
250
|
+
};
|
|
251
|
+
const owner = ancestor(report.parents);
|
|
252
|
+
if (owner !== void 0) node.createdIn = owner;
|
|
253
|
+
const originId = report.origin ? ids.get(report.origin) : void 0;
|
|
254
|
+
const from = originId !== void 0 ? graph.get(originId) : void 0;
|
|
255
|
+
if (from) {
|
|
256
|
+
node.createdIn = originId;
|
|
257
|
+
if (from.source) node.source = from.source;
|
|
258
|
+
}
|
|
259
|
+
const scopeId = report.scope ? scopeIds.get(report.scope) : void 0;
|
|
260
|
+
if (scopeId !== void 0) {
|
|
261
|
+
node.scope = scopeId;
|
|
262
|
+
const creator = node.createdIn !== void 0 ? graph.get(node.createdIn) : void 0;
|
|
263
|
+
const insideAlready = node.createdIn === scopeId || creator?.scope === scopeId;
|
|
264
|
+
if (!insideAlready) node.createdIn = scopeId;
|
|
265
|
+
} else if (node.createdIn !== void 0) {
|
|
266
|
+
const creator = graph.get(node.createdIn);
|
|
267
|
+
const inherited = creator && SCOPE_KINDS.has(creator.kind) ? creator.id : creator?.scope;
|
|
268
|
+
if (inherited !== void 0) node.scope = inherited;
|
|
269
|
+
}
|
|
270
|
+
const self = mark?.self;
|
|
271
|
+
if (self) {
|
|
272
|
+
const list = fieldsOf.get(self);
|
|
273
|
+
if (list) list.push(id);
|
|
274
|
+
else fieldsOf.set(self, [id]);
|
|
275
|
+
const open = scopeOfTarget.get(self);
|
|
276
|
+
if (open !== void 0 && graph.has(open)) {
|
|
277
|
+
node.scope = open;
|
|
278
|
+
node.createdIn = open;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if (kind !== "effect" && typeof handle === "function") {
|
|
282
|
+
const read = handle;
|
|
283
|
+
node.read = () => untrack(read);
|
|
284
|
+
}
|
|
285
|
+
ids.set(core, id);
|
|
286
|
+
if (handle && (typeof handle === "object" || typeof handle === "function")) {
|
|
287
|
+
ids.set(handle, id);
|
|
288
|
+
}
|
|
289
|
+
cores.set(id, core);
|
|
290
|
+
if (typeof report.set === "function") setters.set(id, report.set);
|
|
291
|
+
graph.set(id, node);
|
|
292
|
+
history.created(id, node.createdIn, node.label);
|
|
293
|
+
},
|
|
294
|
+
ran(target) {
|
|
295
|
+
const id = ids.get(target);
|
|
296
|
+
if (id !== void 0) {
|
|
297
|
+
const node = graph.get(id);
|
|
298
|
+
if (node) node.runs++;
|
|
299
|
+
history.ran(id);
|
|
300
|
+
}
|
|
301
|
+
},
|
|
302
|
+
wrote(target, by) {
|
|
303
|
+
const writer = by ? ids.get(by) : void 0;
|
|
304
|
+
const written = ids.get(target);
|
|
305
|
+
if (written === void 0) return;
|
|
306
|
+
if (wantSites && writer === void 0) {
|
|
307
|
+
const node = graph.get(written);
|
|
308
|
+
const site = currentCallSite(origin);
|
|
309
|
+
if (node && site) {
|
|
310
|
+
const seen = node.setAt ??= [];
|
|
311
|
+
const at = mapped(site.location);
|
|
312
|
+
if (!seen.some((s) => s.file === at.file && s.line === at.line && s.column === at.column)) {
|
|
313
|
+
if (seen.length >= SET_SITES) seen.shift();
|
|
314
|
+
seen.push(at);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
if (recording) {
|
|
319
|
+
const node = graph.get(written);
|
|
320
|
+
const after = node ? readRaw(node) : void 0;
|
|
321
|
+
const before = raws.get(written);
|
|
322
|
+
if (node) raws.set(written, after);
|
|
323
|
+
const shown = node?.detail ?? node?.value;
|
|
324
|
+
history.wrote(written, writer, {
|
|
325
|
+
from: shown === void 0 ? void 0 : shorten(shown, HISTORY_VALUE),
|
|
326
|
+
to: node ? shorten(formatValue(after, HISTORY_VALUE * 2), HISTORY_VALUE) : void 0,
|
|
327
|
+
// Which row was added is the fact a reader is after.
|
|
328
|
+
change: diffValues(before, after),
|
|
329
|
+
label: node?.label
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
if (writer === void 0 || writer === written) return;
|
|
333
|
+
graph.get(writer)?.writes.add(written);
|
|
334
|
+
},
|
|
335
|
+
directive(node, target, kind, name, accessor) {
|
|
336
|
+
if (!onDirective.length) return;
|
|
337
|
+
const core = node;
|
|
338
|
+
const owner = core && typeof core === "object" ? ids.get(core) : void 0;
|
|
339
|
+
const at = holeLocation(accessor);
|
|
340
|
+
const report = {
|
|
341
|
+
owner: owner !== void 0 ? through.get(core) ?? owner : void 0,
|
|
342
|
+
kind,
|
|
343
|
+
name,
|
|
344
|
+
element: describeNode(target),
|
|
345
|
+
target,
|
|
346
|
+
...at ? { at } : {}
|
|
347
|
+
};
|
|
348
|
+
for (const fn of onDirective) {
|
|
349
|
+
try {
|
|
350
|
+
fn(report);
|
|
351
|
+
} catch {
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
},
|
|
355
|
+
contextCreated(id) {
|
|
356
|
+
if (!onContext.length || contextSites.has(id)) return;
|
|
357
|
+
const site = currentCallSite(origin);
|
|
358
|
+
if (site) contextSites.set(id, mapped(site.location));
|
|
359
|
+
},
|
|
360
|
+
context(node, id, kind, value) {
|
|
361
|
+
if (!onContext.length) return;
|
|
362
|
+
const core = node;
|
|
363
|
+
const owner = core && typeof core === "object" ? ids.get(core) : void 0;
|
|
364
|
+
const report = {
|
|
365
|
+
owner: owner !== void 0 ? through.get(core) ?? owner : void 0,
|
|
366
|
+
id,
|
|
367
|
+
name: id.description || "context",
|
|
368
|
+
...owner !== void 0 ? { ownerLabel: graph.get(owner)?.label } : {},
|
|
369
|
+
// Where the context itself was written. The provider's line is a fallback, and it
|
|
370
|
+
// reads as a lie when two providers share one context.
|
|
371
|
+
...contextSites.get(id) ?? graph.get(owner ?? -1)?.source ? { at: contextSites.get(id) ?? graph.get(owner ?? -1)?.source } : {},
|
|
372
|
+
kind,
|
|
373
|
+
...value === void 0 ? {} : { value: formatValue(value) }
|
|
374
|
+
};
|
|
375
|
+
for (const fn of onContext) {
|
|
376
|
+
try {
|
|
377
|
+
fn(report);
|
|
378
|
+
} catch {
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
},
|
|
382
|
+
props(node, props) {
|
|
383
|
+
const core = node;
|
|
384
|
+
if (!core || typeof core !== "object" || !props) return;
|
|
385
|
+
const id = ids.get(core);
|
|
386
|
+
if (id !== void 0) handed.set(id, props);
|
|
387
|
+
},
|
|
388
|
+
bound(node, target, kind, name, accessor) {
|
|
389
|
+
const core = node;
|
|
390
|
+
if (!core || typeof core !== "object") return;
|
|
391
|
+
const hole = holeLocation(accessor);
|
|
392
|
+
const site = hole ? { ...hole, file: bindingSites.get(core)?.file } : bindingSites.get(core);
|
|
393
|
+
const box = target instanceof Element ? target : target?.parentElement ?? void 0;
|
|
394
|
+
if (box) boundTo.set(core, new WeakRef(box));
|
|
395
|
+
targets.set(core, {
|
|
396
|
+
kind,
|
|
397
|
+
element: describeNode(target),
|
|
398
|
+
...name ? { name } : {},
|
|
399
|
+
...site ? { source: site } : {}
|
|
400
|
+
});
|
|
401
|
+
},
|
|
402
|
+
moved(target, origin2, name) {
|
|
403
|
+
const node = graph.get(ids.get(target) ?? -1);
|
|
404
|
+
if (!node) return;
|
|
405
|
+
const owner = ids.get(origin2);
|
|
406
|
+
if (owner !== void 0 && graph.has(owner)) node.createdIn = owner;
|
|
407
|
+
if (name) {
|
|
408
|
+
node.label = name;
|
|
409
|
+
unnamed.delete(node.id);
|
|
410
|
+
}
|
|
411
|
+
},
|
|
412
|
+
disposed(target) {
|
|
413
|
+
internals.delete(target);
|
|
414
|
+
const id = ids.get(target);
|
|
415
|
+
if (id === void 0) return;
|
|
416
|
+
forget(id);
|
|
417
|
+
},
|
|
418
|
+
scope(scope, info, parent) {
|
|
419
|
+
dropReactiveSource();
|
|
420
|
+
const id = seq++;
|
|
421
|
+
const kind = info.kind === "element" ? "custom-element" : info.kind;
|
|
422
|
+
const parentId = parent ? scopeIds.get(parent) : void 0;
|
|
423
|
+
const found = currentCallSite(origin);
|
|
424
|
+
const site = found && !/\0|__x00__|^virtual:/.test(found.location.file ?? "") ? found : void 0;
|
|
425
|
+
const node = {
|
|
426
|
+
id,
|
|
427
|
+
label: info.name,
|
|
428
|
+
kind,
|
|
429
|
+
// The author named the element, the module and the service; none of them is plumbing.
|
|
430
|
+
authored: true,
|
|
431
|
+
deps: /* @__PURE__ */ new Set(),
|
|
432
|
+
writes: /* @__PURE__ */ new Set(),
|
|
433
|
+
runs: 0,
|
|
434
|
+
lastPulse: 0,
|
|
435
|
+
...info.detail ? { value: info.detail, detail: info.detail } : {},
|
|
436
|
+
...parentId !== void 0 ? { scope: parentId, createdIn: parentId } : {}
|
|
437
|
+
};
|
|
438
|
+
const target = info.target;
|
|
439
|
+
if (kind === "custom-element") {
|
|
440
|
+
const defined = target ? classSource(target.constructor) : void 0;
|
|
441
|
+
if (defined) node.declaredAt = defined;
|
|
442
|
+
} else if (site && !site.external) {
|
|
443
|
+
node.usedAt = mapped(site.location);
|
|
444
|
+
}
|
|
445
|
+
scopeIds.set(scope, id);
|
|
446
|
+
if (target && typeof target === "object" && target.nodeType === 1) {
|
|
447
|
+
rendered.set(id, [new WeakRef(target)]);
|
|
448
|
+
}
|
|
449
|
+
graph.set(id, node);
|
|
450
|
+
history.created(id, node.createdIn, node.label);
|
|
451
|
+
if (target && typeof target === "object") {
|
|
452
|
+
scopeOfTarget.set(target, id);
|
|
453
|
+
for (const field of fieldsOf.get(target) ?? []) {
|
|
454
|
+
const made = graph.get(field);
|
|
455
|
+
if (!made) continue;
|
|
456
|
+
made.scope = id;
|
|
457
|
+
made.createdIn = id;
|
|
458
|
+
revs.set(field, ++revision);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
},
|
|
462
|
+
scopeEnded(scope) {
|
|
463
|
+
const id = scopeIds.get(scope);
|
|
464
|
+
if (id === void 0) return;
|
|
465
|
+
const ended = /* @__PURE__ */ new Set([id]);
|
|
466
|
+
for (let grew = true; grew; ) {
|
|
467
|
+
grew = false;
|
|
468
|
+
for (const [other, node] of graph) {
|
|
469
|
+
if (!ended.has(other) && node.scope !== void 0 && ended.has(node.scope)) {
|
|
470
|
+
ended.add(other);
|
|
471
|
+
grew = true;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
for (const gone of ended) forget(gone);
|
|
476
|
+
},
|
|
477
|
+
scopeAdopted(scope, parent) {
|
|
478
|
+
const node = graph.get(scopeIds.get(scope) ?? -1);
|
|
479
|
+
const parentId = scopeIds.get(parent);
|
|
480
|
+
if (!node || parentId === void 0 || parentId === node.id) return;
|
|
481
|
+
node.scope = parentId;
|
|
482
|
+
node.createdIn = parentId;
|
|
483
|
+
revs.set(node.id, ++revision);
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
function forget(id) {
|
|
487
|
+
removed.push({ id, rev: ++revision });
|
|
488
|
+
revs.delete(id);
|
|
489
|
+
if (removed.length > REMOVED_LOG) removed.splice(0, removed.length - REMOVED_LOG);
|
|
490
|
+
history.disposed(id, graph.get(id)?.label);
|
|
491
|
+
graph.delete(id);
|
|
492
|
+
handed.delete(id);
|
|
493
|
+
raws.delete(id);
|
|
494
|
+
cores.delete(id);
|
|
495
|
+
rendered.delete(id);
|
|
496
|
+
setters.delete(id);
|
|
497
|
+
runsAtLastSample.delete(id);
|
|
498
|
+
unnamed.delete(id);
|
|
499
|
+
}
|
|
500
|
+
const edges = (id, node) => {
|
|
501
|
+
const sources = cores.get(id)?.sources;
|
|
502
|
+
node.deps.clear();
|
|
503
|
+
if (!sources) return;
|
|
504
|
+
for (const source of sources) {
|
|
505
|
+
const dep = ids.get(source);
|
|
506
|
+
if (dep !== void 0 && dep !== id) node.deps.add(dep);
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
const api = {
|
|
510
|
+
graph,
|
|
511
|
+
sample() {
|
|
512
|
+
described = null;
|
|
513
|
+
descendants = null;
|
|
514
|
+
const changed = [];
|
|
515
|
+
const moved = (id) => {
|
|
516
|
+
changed.push(id);
|
|
517
|
+
revs.set(id, ++revision);
|
|
518
|
+
};
|
|
519
|
+
const now = Date.now();
|
|
520
|
+
for (const [id, node] of graph) {
|
|
521
|
+
if (node.kind !== "custom-element" || node.usedAt) continue;
|
|
522
|
+
const element = rendered.get(id)?.[0]?.deref();
|
|
523
|
+
const written = element ? element.__fx_loc : void 0;
|
|
524
|
+
if (!written?.file) continue;
|
|
525
|
+
node.usedAt = { file: written.file, line: written.line, column: written.column };
|
|
526
|
+
revs.set(id, ++revision);
|
|
527
|
+
}
|
|
528
|
+
const bindings = /* @__PURE__ */ new Map();
|
|
529
|
+
const drives = /* @__PURE__ */ new Map();
|
|
530
|
+
const seen = /* @__PURE__ */ new Map();
|
|
531
|
+
for (const internal of internals) {
|
|
532
|
+
const target = targets.get(internal);
|
|
533
|
+
const element = boundTo.get(internal);
|
|
534
|
+
for (const source of internal.sources ?? []) {
|
|
535
|
+
const id = ids.get(source);
|
|
536
|
+
if (id === void 0) continue;
|
|
537
|
+
bindings.set(id, (bindings.get(id) ?? 0) + 1);
|
|
538
|
+
if (element) {
|
|
539
|
+
const found = element.deref();
|
|
540
|
+
if (found && !drivenBy.has(found)) drivenBy.set(found, id);
|
|
541
|
+
const held = seen.get(id);
|
|
542
|
+
if (held) held.push(element);
|
|
543
|
+
else seen.set(id, [element]);
|
|
544
|
+
}
|
|
545
|
+
if (!target) continue;
|
|
546
|
+
const list = drives.get(id);
|
|
547
|
+
if (list) list.push(target);
|
|
548
|
+
else drives.set(id, [target]);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
reaches = seen;
|
|
552
|
+
for (const node of graph.values()) {
|
|
553
|
+
const count = bindings.get(node.id) ?? 0;
|
|
554
|
+
if (node.bindings !== count) node.bindings = count || void 0;
|
|
555
|
+
const list = drives.get(node.id);
|
|
556
|
+
node.targets = list?.length ? list : void 0;
|
|
557
|
+
}
|
|
558
|
+
for (const node of graph.values()) {
|
|
559
|
+
if (!node.read) {
|
|
560
|
+
edges(node.id, node);
|
|
561
|
+
const seen2 = runsAtLastSample.get(node.id);
|
|
562
|
+
if (seen2 === void 0 || node.runs > seen2) {
|
|
563
|
+
node.lastPulse = now;
|
|
564
|
+
moved(node.id);
|
|
565
|
+
}
|
|
566
|
+
runsAtLastSample.set(node.id, node.runs);
|
|
567
|
+
continue;
|
|
568
|
+
}
|
|
569
|
+
const raw = readRaw(node);
|
|
570
|
+
if (recording) raws.set(node.id, raw);
|
|
571
|
+
edges(node.id, node);
|
|
572
|
+
const stamped = raw?.$name;
|
|
573
|
+
if (node.kind === "memo" && typeof stamped === "string" && stamped && claims(node, raw)) {
|
|
574
|
+
node.kind = KIND_OF_BUILTIN[stamped] ?? "component";
|
|
575
|
+
node.declaredAt = componentSource(stamped);
|
|
576
|
+
node.source ??= node.declaredAt;
|
|
577
|
+
if (raw.$lazy) node.lazy = true;
|
|
578
|
+
if (unnamed.has(node.id)) {
|
|
579
|
+
node.label = stamped;
|
|
580
|
+
unnamed.delete(node.id);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
if (TREE_KINDS.has(node.kind)) {
|
|
584
|
+
const found = elementsIn(raw);
|
|
585
|
+
if (found.length) rendered.set(node.id, found.map((el) => new WeakRef(el)));
|
|
586
|
+
const given = handed.get(node.id);
|
|
587
|
+
if (given) node.props = readProps(given);
|
|
588
|
+
}
|
|
589
|
+
const detail = formatValue(raw);
|
|
590
|
+
const next = shorten(detail);
|
|
591
|
+
if (next !== node.value || detail !== node.detail) {
|
|
592
|
+
node.detail = detail;
|
|
593
|
+
node.value = next;
|
|
594
|
+
if (node.kind === "state") node.runs++;
|
|
595
|
+
node.lastPulse = now;
|
|
596
|
+
moved(node.id);
|
|
597
|
+
}
|
|
598
|
+
runsAtLastSample.set(node.id, node.runs);
|
|
599
|
+
}
|
|
600
|
+
for (const [id, kind] of retyped) {
|
|
601
|
+
const node = graph.get(id);
|
|
602
|
+
if (node?.kind === "component" && TREE_KINDS.has(kind)) node.kind = kind;
|
|
603
|
+
}
|
|
604
|
+
const unnumbered = () => {
|
|
605
|
+
for (const node of graph.values()) {
|
|
606
|
+
if (TREE_KINDS.has(node.kind) && node.order === void 0) return true;
|
|
607
|
+
}
|
|
608
|
+
return false;
|
|
609
|
+
};
|
|
610
|
+
if (changed.length || unnumbered()) stampDocumentOrder(graph, (of) => api.renderedFor(of));
|
|
611
|
+
return changed;
|
|
612
|
+
},
|
|
613
|
+
get revision() {
|
|
614
|
+
return revision;
|
|
615
|
+
},
|
|
616
|
+
takeRemoved() {
|
|
617
|
+
const out = removed.filter((entry) => entry.rev > drained).map((entry) => entry.id);
|
|
618
|
+
drained = revision;
|
|
619
|
+
return out;
|
|
620
|
+
},
|
|
621
|
+
changedSince(rev) {
|
|
622
|
+
const out = [];
|
|
623
|
+
for (const [id, at] of revs) if (at > rev) out.push(id);
|
|
624
|
+
return out;
|
|
625
|
+
},
|
|
626
|
+
removedSince(rev) {
|
|
627
|
+
return removed.filter((entry) => entry.rev > rev).map((entry) => entry.id);
|
|
628
|
+
},
|
|
629
|
+
outrun(rev) {
|
|
630
|
+
return removed.length >= REMOVED_LOG && rev < removed[0].rev;
|
|
631
|
+
},
|
|
632
|
+
elementsFor(id) {
|
|
633
|
+
const live = [];
|
|
634
|
+
const collect = (from, where = reaches) => {
|
|
635
|
+
for (const ref of where.get(from) ?? []) {
|
|
636
|
+
const found = ref.deref();
|
|
637
|
+
if (found?.isConnected && !live.includes(found)) live.push(found);
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
collect(id, rendered);
|
|
641
|
+
if (live.length) return live;
|
|
642
|
+
collect(id);
|
|
643
|
+
if (!live.length) {
|
|
644
|
+
descendants ??= descendantsByCreator(graph);
|
|
645
|
+
for (const below of descendants.get(id) ?? []) collect(below);
|
|
646
|
+
}
|
|
647
|
+
return live;
|
|
648
|
+
},
|
|
649
|
+
setValue(id, next) {
|
|
650
|
+
const node = graph.get(id);
|
|
651
|
+
const write = setters.get(id);
|
|
652
|
+
if (!node || node.kind !== "state" || !write) return false;
|
|
653
|
+
write(next);
|
|
654
|
+
return true;
|
|
655
|
+
},
|
|
656
|
+
renderedFor(id) {
|
|
657
|
+
const live = [];
|
|
658
|
+
for (const ref of rendered.get(id) ?? []) {
|
|
659
|
+
const found = ref.deref();
|
|
660
|
+
if (found?.isConnected && !live.includes(found)) live.push(found);
|
|
661
|
+
}
|
|
662
|
+
return live;
|
|
663
|
+
},
|
|
664
|
+
domFor(id) {
|
|
665
|
+
described ??= describeAll(
|
|
666
|
+
graph,
|
|
667
|
+
(of) => api.renderedFor(of),
|
|
668
|
+
(of) => api.elementsFor(of),
|
|
669
|
+
TREE_KINDS,
|
|
670
|
+
(element) => elementExtra.get(element)
|
|
671
|
+
);
|
|
672
|
+
return described.get(id) ?? [];
|
|
673
|
+
},
|
|
674
|
+
nodeAt(element) {
|
|
675
|
+
const depth = tagDepths(graph, TREE_KINDS);
|
|
676
|
+
const rendering = /* @__PURE__ */ new Map();
|
|
677
|
+
for (const node of graph.values()) {
|
|
678
|
+
if (!TREE_KINDS.has(node.kind)) continue;
|
|
679
|
+
for (const found of api.renderedFor(node.id)) {
|
|
680
|
+
const held = rendering.get(found);
|
|
681
|
+
if (held === void 0 || (depth.get(node.id) ?? 0) > (depth.get(held) ?? 0)) {
|
|
682
|
+
rendering.set(found, node.id);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
for (let at = element; at; at = at.parentElement) {
|
|
687
|
+
const owner = rendering.get(at);
|
|
688
|
+
if (owner !== void 0 && graph.has(owner)) return owner;
|
|
689
|
+
}
|
|
690
|
+
for (let at = element; at; at = at.parentElement) {
|
|
691
|
+
const id = drivenBy.get(at);
|
|
692
|
+
if (id !== void 0 && graph.has(id)) return id;
|
|
693
|
+
}
|
|
694
|
+
return void 0;
|
|
695
|
+
},
|
|
696
|
+
takeEvents() {
|
|
697
|
+
return history.take();
|
|
698
|
+
},
|
|
699
|
+
mark(label) {
|
|
700
|
+
history.marked(label);
|
|
701
|
+
},
|
|
702
|
+
detach() {
|
|
703
|
+
stop();
|
|
704
|
+
internals.clear();
|
|
705
|
+
graph.clear();
|
|
706
|
+
cores.clear();
|
|
707
|
+
rendered.clear();
|
|
708
|
+
setters.clear();
|
|
709
|
+
runsAtLastSample.clear();
|
|
710
|
+
unnamed.clear();
|
|
711
|
+
raws.clear();
|
|
712
|
+
history.clear();
|
|
713
|
+
}
|
|
714
|
+
};
|
|
715
|
+
for (const plugin of devtoolsPlugins()) {
|
|
716
|
+
if (!plugin.collect) continue;
|
|
717
|
+
const context = {
|
|
718
|
+
onDirective: (fn) => onDirective.push(fn),
|
|
719
|
+
onContext: (fn) => onContext.push(fn),
|
|
720
|
+
annotate: (id, data) => {
|
|
721
|
+
const node = graph.get(id);
|
|
722
|
+
if (node) (node.extra ??= {})[plugin.name] = data;
|
|
723
|
+
},
|
|
724
|
+
annotation: (id) => graph.get(id)?.extra?.[plugin.name],
|
|
725
|
+
// Remembered, not applied here. A component is still a memo when its context is
|
|
726
|
+
// provided, and the promotion that gives it its name only runs while it is one.
|
|
727
|
+
retype: (id, kind) => retyped.set(id, kind),
|
|
728
|
+
annotateElement: (target, data) => {
|
|
729
|
+
if (!target || typeof target !== "object") return;
|
|
730
|
+
const held = elementExtra.get(target) ?? {};
|
|
731
|
+
held[plugin.name] = data;
|
|
732
|
+
elementExtra.set(target, held);
|
|
733
|
+
},
|
|
734
|
+
elementAnnotation: (target) => target && typeof target === "object" ? elementExtra.get(target)?.[plugin.name] : void 0,
|
|
735
|
+
add: (spec) => {
|
|
736
|
+
const id = seq++;
|
|
737
|
+
graph.set(id, {
|
|
738
|
+
id,
|
|
739
|
+
label: spec.label,
|
|
740
|
+
kind: spec.kind,
|
|
741
|
+
deps: new Set(spec.deps ?? []),
|
|
742
|
+
writes: /* @__PURE__ */ new Set(),
|
|
743
|
+
runs: 0,
|
|
744
|
+
lastPulse: 0,
|
|
745
|
+
authored: spec.authored ?? false,
|
|
746
|
+
...spec.createdIn !== void 0 ? { createdIn: spec.createdIn } : {},
|
|
747
|
+
...spec.value !== void 0 ? { value: spec.value } : {},
|
|
748
|
+
...spec.detail !== void 0 ? { detail: spec.detail } : {},
|
|
749
|
+
...spec.source ? { source: spec.source } : {}
|
|
750
|
+
});
|
|
751
|
+
return id;
|
|
752
|
+
}
|
|
753
|
+
};
|
|
754
|
+
try {
|
|
755
|
+
plugin.collect(context);
|
|
756
|
+
} catch {
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
return api;
|
|
760
|
+
}
|
|
761
|
+
function descendantsByCreator(graph) {
|
|
762
|
+
const out = /* @__PURE__ */ new Map();
|
|
763
|
+
for (const node of graph.values()) {
|
|
764
|
+
const seen = /* @__PURE__ */ new Set();
|
|
765
|
+
let at = node.createdIn;
|
|
766
|
+
while (at !== void 0 && !seen.has(at)) {
|
|
767
|
+
seen.add(at);
|
|
768
|
+
let list = out.get(at);
|
|
769
|
+
if (!list) out.set(at, list = []);
|
|
770
|
+
list.push(node.id);
|
|
771
|
+
at = graph.get(at)?.createdIn;
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
return out;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
export {
|
|
778
|
+
observeGraph,
|
|
779
|
+
descendantsByCreator
|
|
780
|
+
};
|