@buoy-gg/shared-ui 7.0.16 → 7.0.18
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/lib/commonjs/dataViewer/ThemedSplitView.js +622 -0
- package/lib/commonjs/dataViewer/index.js +32 -0
- package/lib/commonjs/dataViewer/objectDiff.js +304 -0
- package/lib/commonjs/hooks/index.js +7 -0
- package/lib/commonjs/hooks/safe-area-impl.js +1 -1
- package/lib/commonjs/hooks/usePersistedState.js +71 -0
- package/lib/commonjs/icons/index.js +14 -0
- package/lib/commonjs/index.js +61 -0
- package/lib/commonjs/storage/devToolsStorageKeys.js +31 -0
- package/lib/commonjs/sync/wireBudget.js +97 -0
- package/lib/commonjs/ui/components/HeaderSearchButton.js +6 -1
- package/lib/commonjs/ui/components/ModalHeader.js +69 -0
- package/lib/commonjs/ui/components/ToolButton.js +90 -0
- package/lib/commonjs/ui/components/index.js +7 -0
- package/lib/commonjs/ui/index.js +8 -0
- package/lib/commonjs/ui/toolTheme.js +96 -0
- package/lib/commonjs/utils/index.js +38 -0
- package/lib/commonjs/utils/persistentStorage.js +6 -3
- package/lib/commonjs/utils/stateSnapshotRegistry.js +71 -0
- package/lib/module/dataViewer/ThemedSplitView.js +617 -0
- package/lib/module/dataViewer/index.js +7 -1
- package/lib/module/dataViewer/objectDiff.js +297 -0
- package/lib/module/hooks/index.js +1 -0
- package/lib/module/hooks/safe-area-impl.js +1 -1
- package/lib/module/hooks/usePersistedState.js +68 -0
- package/lib/module/icons/index.js +1 -0
- package/lib/module/index.js +6 -1
- package/lib/module/storage/devToolsStorageKeys.js +31 -0
- package/lib/module/sync/wireBudget.js +92 -0
- package/lib/module/ui/components/HeaderSearchButton.js +6 -1
- package/lib/module/ui/components/ModalHeader.js +70 -2
- package/lib/module/ui/components/ToolButton.js +86 -0
- package/lib/module/ui/components/index.js +1 -0
- package/lib/module/ui/index.js +3 -0
- package/lib/module/ui/toolTheme.js +93 -0
- package/lib/module/utils/index.js +2 -0
- package/lib/module/utils/persistentStorage.js +6 -3
- package/lib/module/utils/stateSnapshotRegistry.js +64 -0
- package/lib/typescript/commonjs/dataViewer/ThemedSplitView.d.ts +28 -0
- package/lib/typescript/commonjs/dataViewer/ThemedSplitView.d.ts.map +1 -0
- package/lib/typescript/commonjs/dataViewer/index.d.ts +2 -0
- package/lib/typescript/commonjs/dataViewer/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/dataViewer/objectDiff.d.ts +67 -0
- package/lib/typescript/commonjs/dataViewer/objectDiff.d.ts.map +1 -0
- package/lib/typescript/commonjs/hooks/index.d.ts +1 -0
- package/lib/typescript/commonjs/hooks/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/hooks/safe-area-impl.d.ts +1 -1
- package/lib/typescript/commonjs/hooks/usePersistedState.d.ts +16 -0
- package/lib/typescript/commonjs/hooks/usePersistedState.d.ts.map +1 -0
- package/lib/typescript/commonjs/icons/index.d.ts +1 -0
- package/lib/typescript/commonjs/icons/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +3 -2
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/storage/devToolsStorageKeys.d.ts +28 -0
- package/lib/typescript/commonjs/storage/devToolsStorageKeys.d.ts.map +1 -1
- package/lib/typescript/commonjs/sync/wireBudget.d.ts +50 -0
- package/lib/typescript/commonjs/sync/wireBudget.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/components/HeaderSearchButton.d.ts +3 -1
- package/lib/typescript/commonjs/ui/components/HeaderSearchButton.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/ModalHeader.d.ts +13 -1
- package/lib/typescript/commonjs/ui/components/ModalHeader.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/ToolButton.d.ts +24 -0
- package/lib/typescript/commonjs/ui/components/ToolButton.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/components/index.d.ts +4 -0
- package/lib/typescript/commonjs/ui/components/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/index.d.ts +1 -0
- package/lib/typescript/commonjs/ui/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/toolTheme.d.ts +68 -0
- package/lib/typescript/commonjs/ui/toolTheme.d.ts.map +1 -0
- package/lib/typescript/commonjs/utils/index.d.ts +2 -0
- package/lib/typescript/commonjs/utils/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/utils/persistentStorage.d.ts.map +1 -1
- package/lib/typescript/commonjs/utils/stateSnapshotRegistry.d.ts +111 -0
- package/lib/typescript/commonjs/utils/stateSnapshotRegistry.d.ts.map +1 -0
- package/lib/typescript/module/dataViewer/ThemedSplitView.d.ts +28 -0
- package/lib/typescript/module/dataViewer/ThemedSplitView.d.ts.map +1 -0
- package/lib/typescript/module/dataViewer/index.d.ts +2 -0
- package/lib/typescript/module/dataViewer/index.d.ts.map +1 -1
- package/lib/typescript/module/dataViewer/objectDiff.d.ts +67 -0
- package/lib/typescript/module/dataViewer/objectDiff.d.ts.map +1 -0
- package/lib/typescript/module/hooks/index.d.ts +1 -0
- package/lib/typescript/module/hooks/index.d.ts.map +1 -1
- package/lib/typescript/module/hooks/safe-area-impl.d.ts +1 -1
- package/lib/typescript/module/hooks/usePersistedState.d.ts +16 -0
- package/lib/typescript/module/hooks/usePersistedState.d.ts.map +1 -0
- package/lib/typescript/module/icons/index.d.ts +1 -0
- package/lib/typescript/module/icons/index.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +3 -2
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/storage/devToolsStorageKeys.d.ts +28 -0
- package/lib/typescript/module/storage/devToolsStorageKeys.d.ts.map +1 -1
- package/lib/typescript/module/sync/wireBudget.d.ts +50 -0
- package/lib/typescript/module/sync/wireBudget.d.ts.map +1 -0
- package/lib/typescript/module/ui/components/HeaderSearchButton.d.ts +3 -1
- package/lib/typescript/module/ui/components/HeaderSearchButton.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/ModalHeader.d.ts +13 -1
- package/lib/typescript/module/ui/components/ModalHeader.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/ToolButton.d.ts +24 -0
- package/lib/typescript/module/ui/components/ToolButton.d.ts.map +1 -0
- package/lib/typescript/module/ui/components/index.d.ts +4 -0
- package/lib/typescript/module/ui/components/index.d.ts.map +1 -1
- package/lib/typescript/module/ui/index.d.ts +1 -0
- package/lib/typescript/module/ui/index.d.ts.map +1 -1
- package/lib/typescript/module/ui/toolTheme.d.ts +68 -0
- package/lib/typescript/module/ui/toolTheme.d.ts.map +1 -0
- package/lib/typescript/module/utils/index.d.ts +2 -0
- package/lib/typescript/module/utils/index.d.ts.map +1 -1
- package/lib/typescript/module/utils/persistentStorage.d.ts.map +1 -1
- package/lib/typescript/module/utils/stateSnapshotRegistry.d.ts +111 -0
- package/lib/typescript/module/utils/stateSnapshotRegistry.d.ts.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* objectDiff — the bounded, cycle-safe diff KERNEL the dataViewer never had.
|
|
5
|
+
*
|
|
6
|
+
* Every diff consumer so far either hand-rolled a private summary helper or
|
|
7
|
+
* fed whole values into the render-layer viewers (which compute eagerly, have
|
|
8
|
+
* no cycle guards, and mis-compare rich types — TreeDiffViewer treats two
|
|
9
|
+
* different Dates/Maps/Sets as EQUAL because they have zero own keys).
|
|
10
|
+
*
|
|
11
|
+
* This kernel is for VERDICTS and BADGES, not rendering:
|
|
12
|
+
* - correct equality for Date / RegExp / Map / Set / BigInt / NaN /
|
|
13
|
+
* TypedArray / URL / Error, and `undefined`-value vs absent-key
|
|
14
|
+
* - WeakSet cycle guard (a revisited pair reports unequal-safe truncation,
|
|
15
|
+
* never a stack overflow)
|
|
16
|
+
* - hard depth + node budgets with an explicit `truncated` flag; when the
|
|
17
|
+
* budget runs out a subtree is reported as CHANGED (a false "changed" is
|
|
18
|
+
* recoverable — a false "unchanged" hides a real difference, the worst
|
|
19
|
+
* failure mode for a restore preview)
|
|
20
|
+
*
|
|
21
|
+
* `toDiffable` is the companion RENDER normalizer: it converts rich types to
|
|
22
|
+
* plain-JSON stand-ins so the existing viewers (which only handle plain JSON
|
|
23
|
+
* faithfully) never see a Date/Map/Set/BigInt/cycle at all.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
function isPlainObjectLike(v) {
|
|
27
|
+
if (typeof v !== "object" || v === null) return false;
|
|
28
|
+
const proto = Object.getPrototypeOf(v);
|
|
29
|
+
return proto === Object.prototype || proto === null;
|
|
30
|
+
}
|
|
31
|
+
function isTypedArray(v) {
|
|
32
|
+
return ArrayBuffer.isView(v) && !(v instanceof DataView);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Bounded deep equality. Returns false on budget exhaustion (conservative:
|
|
37
|
+
* report changed rather than hide a change) and marks the budget truncated.
|
|
38
|
+
*/
|
|
39
|
+
export function boundedDeepEqual(a, b, options) {
|
|
40
|
+
const budget = {
|
|
41
|
+
nodes: options?.maxNodes ?? 2000,
|
|
42
|
+
truncated: false
|
|
43
|
+
};
|
|
44
|
+
return deepEqual(a, b, options?.maxDepth ?? 8, budget, new WeakSet());
|
|
45
|
+
}
|
|
46
|
+
function deepEqual(a, b, depth, budget, seen) {
|
|
47
|
+
if (budget.nodes-- <= 0) {
|
|
48
|
+
budget.truncated = true;
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
// NaN-equal, -0-distinct — Object.is has the right scalar semantics.
|
|
52
|
+
if (Object.is(a, b)) return true;
|
|
53
|
+
if (typeof a !== typeof b) return false;
|
|
54
|
+
if (typeof a !== "object" || a === null || b === null) {
|
|
55
|
+
// Distinct functions: treated as EQUAL — providers strip/preserve them
|
|
56
|
+
// and reference inequality across a serialization boundary is pure noise.
|
|
57
|
+
return typeof a === "function" && typeof b === "function";
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Rich types the render-layer viewers get wrong:
|
|
61
|
+
if (a instanceof Date || b instanceof Date) {
|
|
62
|
+
return a instanceof Date && b instanceof Date && a.getTime() === b.getTime();
|
|
63
|
+
}
|
|
64
|
+
if (a instanceof RegExp || b instanceof RegExp) {
|
|
65
|
+
return a instanceof RegExp && b instanceof RegExp && a.source === b.source && a.flags === b.flags;
|
|
66
|
+
}
|
|
67
|
+
if (a instanceof Error || b instanceof Error) {
|
|
68
|
+
return a instanceof Error && b instanceof Error && a.name === b.name && a.message === b.message;
|
|
69
|
+
}
|
|
70
|
+
if (typeof URL !== "undefined" && (a instanceof URL || b instanceof URL)) {
|
|
71
|
+
return a instanceof URL && b instanceof URL && a.href === b.href;
|
|
72
|
+
}
|
|
73
|
+
if (isTypedArray(a) || isTypedArray(b)) {
|
|
74
|
+
if (!isTypedArray(a) || !isTypedArray(b)) return false;
|
|
75
|
+
if (a.constructor !== b.constructor || a.byteLength !== b.byteLength) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
const ua = new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
|
|
79
|
+
const ub = new Uint8Array(b.buffer, b.byteOffset, b.byteLength);
|
|
80
|
+
for (let i = 0; i < ua.length; i++) if (ua[i] !== ub[i]) return false;
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
if (depth <= 0) {
|
|
84
|
+
budget.truncated = true;
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
// Cycle guard: a revisited left-side object ends the walk for this branch.
|
|
88
|
+
// Reporting unequal here is the conservative direction.
|
|
89
|
+
if (seen.has(a)) {
|
|
90
|
+
budget.truncated = true;
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
seen.add(a);
|
|
94
|
+
if (a instanceof Map || b instanceof Map) {
|
|
95
|
+
if (!(a instanceof Map) || !(b instanceof Map) || a.size !== b.size) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
// Insertion-order comparison — superjson round-trips preserve it, and
|
|
99
|
+
// order-insensitive matching with object keys is quadratic.
|
|
100
|
+
const ea = Array.from(a.entries());
|
|
101
|
+
const eb = Array.from(b.entries());
|
|
102
|
+
for (let i = 0; i < ea.length; i++) {
|
|
103
|
+
if (!deepEqual(ea[i][0], eb[i][0], depth - 1, budget, seen)) return false;
|
|
104
|
+
if (!deepEqual(ea[i][1], eb[i][1], depth - 1, budget, seen)) return false;
|
|
105
|
+
}
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
if (a instanceof Set || b instanceof Set) {
|
|
109
|
+
if (!(a instanceof Set) || !(b instanceof Set) || a.size !== b.size) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
const va = Array.from(a.values());
|
|
113
|
+
const vb = Array.from(b.values());
|
|
114
|
+
for (let i = 0; i < va.length; i++) {
|
|
115
|
+
if (!deepEqual(va[i], vb[i], depth - 1, budget, seen)) return false;
|
|
116
|
+
}
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
120
|
+
if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
for (let i = 0; i < a.length; i++) {
|
|
124
|
+
if (!deepEqual(a[i], b[i], depth - 1, budget, seen)) return false;
|
|
125
|
+
}
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
const ka = Object.keys(a);
|
|
129
|
+
const kb = Object.keys(b);
|
|
130
|
+
if (ka.length !== kb.length) return false;
|
|
131
|
+
for (const k of ka) {
|
|
132
|
+
if (!Object.prototype.hasOwnProperty.call(b, k)) return false;
|
|
133
|
+
if (!deepEqual(a[k], b[k], depth - 1, budget, seen)) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Top-level key diff of two values with bounded deep equality per key.
|
|
142
|
+
* Non-object inputs degrade to a single implicit "value" comparison.
|
|
143
|
+
*/
|
|
144
|
+
export function objectDiff(oldValue, newValue, options) {
|
|
145
|
+
const maxDepth = options?.maxDepth ?? 8;
|
|
146
|
+
const budget = {
|
|
147
|
+
nodes: options?.maxNodes ?? 2000,
|
|
148
|
+
truncated: false
|
|
149
|
+
};
|
|
150
|
+
const oldIsObj = isPlainObjectLike(oldValue);
|
|
151
|
+
const newIsObj = isPlainObjectLike(newValue);
|
|
152
|
+
if (!oldIsObj || !newIsObj) {
|
|
153
|
+
const equal = deepEqual(oldValue, newValue, maxDepth, budget, new WeakSet());
|
|
154
|
+
return {
|
|
155
|
+
equal,
|
|
156
|
+
addedKeys: [],
|
|
157
|
+
removedKeys: [],
|
|
158
|
+
changedKeys: equal ? [] : ["value"],
|
|
159
|
+
truncated: budget.truncated
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
const addedKeys = [];
|
|
163
|
+
const removedKeys = [];
|
|
164
|
+
const changedKeys = [];
|
|
165
|
+
const oldObj = oldValue;
|
|
166
|
+
const newObj = newValue;
|
|
167
|
+
for (const k of Object.keys(oldObj)) {
|
|
168
|
+
if (!Object.prototype.hasOwnProperty.call(newObj, k)) {
|
|
169
|
+
removedKeys.push(k);
|
|
170
|
+
} else if (!deepEqual(oldObj[k], newObj[k], maxDepth - 1, budget, new WeakSet())) {
|
|
171
|
+
changedKeys.push(k);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
for (const k of Object.keys(newObj)) {
|
|
175
|
+
if (!Object.prototype.hasOwnProperty.call(oldObj, k)) addedKeys.push(k);
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
equal: addedKeys.length === 0 && removedKeys.length === 0 && changedKeys.length === 0,
|
|
179
|
+
addedKeys,
|
|
180
|
+
removedKeys,
|
|
181
|
+
changedKeys,
|
|
182
|
+
truncated: budget.truncated
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// ============================================================================
|
|
187
|
+
// toDiffable — render normalizer
|
|
188
|
+
// ============================================================================
|
|
189
|
+
|
|
190
|
+
const TO_DIFFABLE_MAX_DEPTH = 12;
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Convert a value tree into plain JSON the render-layer diff viewers handle
|
|
194
|
+
* faithfully. Dates → ISO strings, Maps → objects, Sets → arrays,
|
|
195
|
+
* BigInt → "123n", TypedArrays/cycles/depth-overflow → placeholder strings.
|
|
196
|
+
* Functions become "[Function]" (providers have already recorded real ones).
|
|
197
|
+
*/
|
|
198
|
+
export function toDiffable(value) {
|
|
199
|
+
return normalizeForDiff(value, TO_DIFFABLE_MAX_DEPTH, new WeakSet());
|
|
200
|
+
}
|
|
201
|
+
function normalizeForDiff(value, depth, seen) {
|
|
202
|
+
if (value === null || value === undefined) return value;
|
|
203
|
+
const t = typeof value;
|
|
204
|
+
if (t === "string" || t === "boolean") return value;
|
|
205
|
+
if (t === "number") {
|
|
206
|
+
return Number.isFinite(value) ? value : String(value);
|
|
207
|
+
}
|
|
208
|
+
if (t === "bigint") return `${String(value)}n`;
|
|
209
|
+
if (t === "function") return "[Function]";
|
|
210
|
+
if (t === "symbol") return String(value);
|
|
211
|
+
if (t !== "object") return String(value);
|
|
212
|
+
if (value instanceof Date) return value.toISOString();
|
|
213
|
+
if (value instanceof RegExp) return String(value);
|
|
214
|
+
if (value instanceof Error) return `[${value.name}: ${value.message}]`;
|
|
215
|
+
if (typeof URL !== "undefined" && value instanceof URL) return value.href;
|
|
216
|
+
if (isTypedArray(value)) {
|
|
217
|
+
return `<${value.constructor.name} ${value.byteLength} bytes>`;
|
|
218
|
+
}
|
|
219
|
+
if (depth <= 0) return "[Max depth]";
|
|
220
|
+
if (seen.has(value)) return "[Circular]";
|
|
221
|
+
seen.add(value);
|
|
222
|
+
if (value instanceof Map) {
|
|
223
|
+
const out = {};
|
|
224
|
+
for (const [k, v] of value.entries()) {
|
|
225
|
+
const key = typeof k === "string" ? k : JSON.stringify(toDiffable(k));
|
|
226
|
+
out[key] = normalizeForDiff(v, depth - 1, seen);
|
|
227
|
+
}
|
|
228
|
+
return out;
|
|
229
|
+
}
|
|
230
|
+
if (value instanceof Set) {
|
|
231
|
+
return Array.from(value.values()).map(v => normalizeForDiff(v, depth - 1, seen));
|
|
232
|
+
}
|
|
233
|
+
if (Array.isArray(value)) {
|
|
234
|
+
return value.map(v => normalizeForDiff(v, depth - 1, seen));
|
|
235
|
+
}
|
|
236
|
+
const out = {};
|
|
237
|
+
for (const [k, v] of Object.entries(value)) {
|
|
238
|
+
out[k] = normalizeForDiff(v, depth - 1, seen);
|
|
239
|
+
}
|
|
240
|
+
return out;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// ============================================================================
|
|
244
|
+
// Size probe — O(limit) early-bail, cycle-safe
|
|
245
|
+
// ============================================================================
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* True when `value`'s JSON form is likely larger than `limitBytes`. Iterative
|
|
249
|
+
* walk that bails the moment the running estimate crosses the limit, so cost
|
|
250
|
+
* is O(limit) regardless of payload size (the redux store's `jsonLongerThan`
|
|
251
|
+
* lesson: a full stringify per check froze enterprise-scale apps).
|
|
252
|
+
*/
|
|
253
|
+
export function jsonLikelyLargerThan(value, limitBytes) {
|
|
254
|
+
let size = 0;
|
|
255
|
+
const stack = [value];
|
|
256
|
+
const seenObjects = new Set();
|
|
257
|
+
while (stack.length > 0) {
|
|
258
|
+
const v = stack.pop();
|
|
259
|
+
if (v === null || v === undefined) {
|
|
260
|
+
size += 4;
|
|
261
|
+
} else if (typeof v === "string") {
|
|
262
|
+
size += v.length + 2;
|
|
263
|
+
} else if (typeof v === "number" || typeof v === "boolean") {
|
|
264
|
+
size += 8;
|
|
265
|
+
} else if (typeof v === "bigint") {
|
|
266
|
+
size += String(v).length + 1;
|
|
267
|
+
} else if (typeof v === "object") {
|
|
268
|
+
if (seenObjects.has(v)) continue;
|
|
269
|
+
seenObjects.add(v);
|
|
270
|
+
if (v instanceof Date || v instanceof RegExp) {
|
|
271
|
+
size += 32;
|
|
272
|
+
} else if (isTypedArray(v)) {
|
|
273
|
+
size += v.byteLength;
|
|
274
|
+
} else if (v instanceof Map) {
|
|
275
|
+
for (const [k, val] of v.entries()) {
|
|
276
|
+
stack.push(k, val);
|
|
277
|
+
size += 4;
|
|
278
|
+
}
|
|
279
|
+
} else if (v instanceof Set) {
|
|
280
|
+
for (const val of v.values()) {
|
|
281
|
+
stack.push(val);
|
|
282
|
+
size += 2;
|
|
283
|
+
}
|
|
284
|
+
} else if (Array.isArray(v)) {
|
|
285
|
+
for (const item of v) stack.push(item);
|
|
286
|
+
size += 2 * v.length + 2;
|
|
287
|
+
} else {
|
|
288
|
+
for (const [k, val] of Object.entries(v)) {
|
|
289
|
+
size += k.length + 4;
|
|
290
|
+
stack.push(val);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (size > limitBytes) return true;
|
|
295
|
+
}
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
export { useFilterManager } from "./useFilterManager.js";
|
|
4
|
+
export { usePersistedState } from "./usePersistedState.js";
|
|
4
5
|
export { useSafeAreaInsets } from "./useSafeAreaInsets.js";
|
|
5
6
|
export { getSafeAreaInsets } from "./useSafeAreaInsets.js";
|
|
6
7
|
export { useDeviceInfo, getDeviceInfo, logDeviceInfo } from "./useDeviceInfo.js";
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
|
+
import { persistentStorage } from "../utils/persistentStorage.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Per-key cache so remounts (and multiple consumers of the same key) render
|
|
8
|
+
* the last-known value immediately instead of flashing the default while the
|
|
9
|
+
* async backend loads again.
|
|
10
|
+
*/
|
|
11
|
+
const hydratedCache = new Map();
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* `useState` persisted through `persistentStorage` (FileSystem → AsyncStorage
|
|
15
|
+
* → memory). Replaces the load-then-`hasLoaded`-guard `useEffect` pattern
|
|
16
|
+
* every tool used to hand-roll.
|
|
17
|
+
*
|
|
18
|
+
* Values are JSON-serialized; the default is returned until hydration
|
|
19
|
+
* completes (subsequent mounts of the same key hydrate synchronously from an
|
|
20
|
+
* in-memory cache). The third tuple element reports hydration so callers can
|
|
21
|
+
* defer writes that must not clobber a not-yet-loaded value.
|
|
22
|
+
*
|
|
23
|
+
* ```tsx
|
|
24
|
+
* const [tab, setTab, tabHydrated] = usePersistedState("@react_buoy_custom_flags_tab", "flags");
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export function usePersistedState(key, defaultValue) {
|
|
28
|
+
const [value, setValue] = useState(() => hydratedCache.has(key) ? hydratedCache.get(key) : defaultValue);
|
|
29
|
+
const [hydrated, setHydrated] = useState(() => hydratedCache.has(key));
|
|
30
|
+
const keyRef = useRef(key);
|
|
31
|
+
keyRef.current = key;
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (hydratedCache.has(key)) {
|
|
34
|
+
setValue(hydratedCache.get(key));
|
|
35
|
+
setHydrated(true);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
let cancelled = false;
|
|
39
|
+
persistentStorage.getItem(key).then(raw => {
|
|
40
|
+
if (cancelled) return;
|
|
41
|
+
if (raw != null) {
|
|
42
|
+
try {
|
|
43
|
+
const parsed = JSON.parse(raw);
|
|
44
|
+
hydratedCache.set(key, parsed);
|
|
45
|
+
setValue(parsed);
|
|
46
|
+
} catch {
|
|
47
|
+
// Corrupt payload — fall back to the default and let the next
|
|
48
|
+
// write repair it.
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
setHydrated(true);
|
|
52
|
+
}).catch(() => {
|
|
53
|
+
if (!cancelled) setHydrated(true);
|
|
54
|
+
});
|
|
55
|
+
return () => {
|
|
56
|
+
cancelled = true;
|
|
57
|
+
};
|
|
58
|
+
}, [key]);
|
|
59
|
+
const set = useCallback(next => {
|
|
60
|
+
setValue(prev => {
|
|
61
|
+
const resolved = typeof next === "function" ? next(prev) : next;
|
|
62
|
+
hydratedCache.set(keyRef.current, resolved);
|
|
63
|
+
persistentStorage.setItem(keyRef.current, JSON.stringify(resolved)).catch(() => {});
|
|
64
|
+
return resolved;
|
|
65
|
+
});
|
|
66
|
+
}, []);
|
|
67
|
+
return [value, set, hydrated];
|
|
68
|
+
}
|
|
@@ -11,6 +11,7 @@ export { EnvIcon, ENV_ICON_COLOR } from "@buoy-gg/floating-tools-core";
|
|
|
11
11
|
// into core, so these are the same artwork the Flutter build renders. Tool
|
|
12
12
|
// packages re-export from here rather than drawing their own copies.
|
|
13
13
|
export { ConsoleIcon, CONSOLE_ICON_COLOR } from "@buoy-gg/floating-tools-core";
|
|
14
|
+
export { TimeMachineIcon, TIME_MACHINE_ICON_COLOR } from "@buoy-gg/floating-tools-core";
|
|
14
15
|
export { ImagesIcon, IMAGES_ICON_COLOR } from "@buoy-gg/floating-tools-core";
|
|
15
16
|
export { AssetsIcon, ASSETS_ICON_COLOR } from "@buoy-gg/floating-tools-core";
|
|
16
17
|
export { ImpersonateIcon, IMPERSONATE_ICON_COLOR } from "@buoy-gg/floating-tools-core";
|
package/lib/module/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export * from "./ui/index.js";
|
|
|
5
5
|
|
|
6
6
|
// Store base classes
|
|
7
7
|
export * from "./stores/index.js";
|
|
8
|
+
export * from "./sync/wireBudget.js";
|
|
8
9
|
|
|
9
10
|
// Utils exports - selectively export to avoid conflicts
|
|
10
11
|
export {
|
|
@@ -26,6 +27,10 @@ parseValue, formatValue, getTypeColor, truncateText, flattenObject, formatPath,
|
|
|
26
27
|
loadOptionalModule, getCachedOptionalModule,
|
|
27
28
|
// Render-commit capture bridge (provider: highlight-updates, consumer: perf-monitor)
|
|
28
29
|
setRenderCaptureProvider, getRenderCaptureProvider,
|
|
30
|
+
// State snapshot bridge (providers: storage/redux/zustand/jotai/react-query, consumer: time-machine)
|
|
31
|
+
registerStateSnapshotProvider, getStateSnapshotProviders, getStateSnapshotProvider, subscribeToStateSnapshotProviders,
|
|
32
|
+
// Minimal superjson (Date/Map/Set/BigInt-safe round-trip) for snapshot payloads
|
|
33
|
+
superJsonSerialize, superJsonDeserialize,
|
|
29
34
|
// JS-bundle reload (core's `app` adapter + perf-monitor's batch runner)
|
|
30
35
|
reloadApp, scheduleReloadApp, resolveReloadStrategy, REMOTE_RELOAD_DELAY_MS,
|
|
31
36
|
// Subscribable base class for self-managing listeners
|
|
@@ -50,7 +55,7 @@ export * from "./clipboard/index.js";
|
|
|
50
55
|
export * from "./logger/index.js";
|
|
51
56
|
export * from "./settings/index.js";
|
|
52
57
|
export * from "./storage/index.js";
|
|
53
|
-
export { useSafeAreaInsets, useFilterManager, useDeviceInfo, getDeviceInfo, logDeviceInfo } from "./hooks/index.js";
|
|
58
|
+
export { useSafeAreaInsets, useFilterManager, usePersistedState, useDeviceInfo, getDeviceInfo, logDeviceInfo } from "./hooks/index.js";
|
|
54
59
|
|
|
55
60
|
// JsModal
|
|
56
61
|
export { JsModal } from "./JsModal";
|
|
@@ -31,6 +31,28 @@ export const devToolsStorageKeys = {
|
|
|
31
31
|
dimensions: () => `${devToolsStorageKeys.modal.root()}_dimensions`,
|
|
32
32
|
hintAcknowledged: () => `${devToolsStorageKeys.modal.root()}_hint_acknowledged`
|
|
33
33
|
},
|
|
34
|
+
/**
|
|
35
|
+
* Namespace factory for third-party custom tools. Keys share the
|
|
36
|
+
* `@react_buoy` prefix, so `isDevToolsStorageKey` filtering (and the Storage
|
|
37
|
+
* tool's internal-key handling) covers custom-tool persistence for free.
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* const keys = devToolsStorageKeys.custom("feature-flags");
|
|
41
|
+
* keys.modal(); // "@react_buoy_custom_feature-flags_modal"
|
|
42
|
+
* keys.key("overrides"); // "@react_buoy_custom_feature-flags_overrides"
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
custom: toolId => {
|
|
46
|
+
const root = `${devToolsStorageKeys.base}_custom_${toolId}`;
|
|
47
|
+
return {
|
|
48
|
+
root: () => root,
|
|
49
|
+
/** JsModal `persistenceKey` for this tool's window dimensions. */
|
|
50
|
+
modal: () => `${root}_modal`,
|
|
51
|
+
settings: () => `${root}_settings`,
|
|
52
|
+
/** Arbitrary tool-scoped key. */
|
|
53
|
+
key: suffix => `${root}_${suffix}`
|
|
54
|
+
};
|
|
55
|
+
},
|
|
34
56
|
/**
|
|
35
57
|
* Settings-related storage keys
|
|
36
58
|
*/
|
|
@@ -97,6 +119,15 @@ export const devToolsStorageKeys = {
|
|
|
97
119
|
isMonitoring: () => `${devToolsStorageKeys.storage.root()}_is_monitoring`,
|
|
98
120
|
diffViewerMode: () => `${devToolsStorageKeys.storage.root()}_diff_viewer_mode` // 'split' | 'tree'
|
|
99
121
|
},
|
|
122
|
+
/**
|
|
123
|
+
* Time Machine storage keys. NOTE: the snapshot VAULT keys
|
|
124
|
+
* (`@react_buoy_time_machine:index` / `:snap:*`) predate this namespace and
|
|
125
|
+
* stay as-is — only preferences live here.
|
|
126
|
+
*/
|
|
127
|
+
timeMachine: {
|
|
128
|
+
root: () => `${devToolsStorageKeys.base}_time_machine`,
|
|
129
|
+
diffViewerMode: () => `${devToolsStorageKeys.timeMachine.root()}_diff_viewer_mode` // 'split' | 'tree'
|
|
130
|
+
},
|
|
100
131
|
/**
|
|
101
132
|
* React Query-related storage keys
|
|
102
133
|
*/
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Size guards for anything a tool puts on the sync wire.
|
|
5
|
+
*
|
|
6
|
+
* Every adapter faces the same problem: a snapshot is rebuilt and serialized
|
|
7
|
+
* on the device's JS thread ~5x/sec while a dashboard watches, and one fat or
|
|
8
|
+
* unserializable field can either freeze that thread or blow the emit layer's
|
|
9
|
+
* budget — which drops the WHOLE snapshot and leaves the panel stale.
|
|
10
|
+
*
|
|
11
|
+
* Two rules make that safe, and both are easy to get subtly wrong, which is
|
|
12
|
+
* why they live here instead of being copied per adapter:
|
|
13
|
+
*
|
|
14
|
+
* 1. NEVER measure by serializing. `JSON.stringify(value).length` is
|
|
15
|
+
* O(payload) and allocates the whole string — an unbounded cost to
|
|
16
|
+
* enforce a 16KB cap, i.e. the protection becomes the freeze. Walk with
|
|
17
|
+
* an early abort instead: the cost is O(limit) no matter how big the
|
|
18
|
+
* value, and a string costs a length read rather than a scan.
|
|
19
|
+
*
|
|
20
|
+
* 2. Only reach for `JSON.stringify` when the walk saw something that could
|
|
21
|
+
* actually make it throw. A value straight out of `JSON.parse` — which is
|
|
22
|
+
* what a network body or a stored string is — is a finite tree of plain
|
|
23
|
+
* values and can never throw, so the check is pure waste on the common
|
|
24
|
+
* path.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import { isJsonSerializable } from "../utils/typeHelpers.js";
|
|
28
|
+
/**
|
|
29
|
+
* Approximate JSON size, aborting as soon as `limit` is passed — O(limit),
|
|
30
|
+
* never O(payload). Returns the bytes counted so far, so one walk can both
|
|
31
|
+
* threshold ("over the per-field cap?") and accumulate ("how much of the
|
|
32
|
+
* snapshot budget is left?").
|
|
33
|
+
*/
|
|
34
|
+
export function approxJsonSize(value, limit) {
|
|
35
|
+
let bytes = 0;
|
|
36
|
+
let sawRepeat = false;
|
|
37
|
+
let sawBigInt = false;
|
|
38
|
+
const stack = [value];
|
|
39
|
+
const seen = new Set();
|
|
40
|
+
while (stack.length > 0) {
|
|
41
|
+
if (bytes > limit) return {
|
|
42
|
+
bytes,
|
|
43
|
+
sawRepeat,
|
|
44
|
+
sawBigInt
|
|
45
|
+
};
|
|
46
|
+
const v = stack.pop();
|
|
47
|
+
if (v === null || v === undefined) bytes += 4;else if (typeof v === "string") bytes += v.length + 2; // O(1), no scan
|
|
48
|
+
else if (typeof v === "number") bytes += 8;else if (typeof v === "boolean") bytes += 5;else if (typeof v === "object") {
|
|
49
|
+
if (seen.has(v)) {
|
|
50
|
+
sawRepeat = true;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
seen.add(v);
|
|
54
|
+
if (Array.isArray(v)) {
|
|
55
|
+
bytes += 2 + v.length;
|
|
56
|
+
for (let i = 0; i < v.length; i++) stack.push(v[i]);
|
|
57
|
+
} else {
|
|
58
|
+
bytes += 2;
|
|
59
|
+
for (const k in v) {
|
|
60
|
+
bytes += k.length + 4;
|
|
61
|
+
stack.push(v[k]);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
if (typeof v === "bigint") sawBigInt = true;
|
|
66
|
+
bytes += 4;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
bytes,
|
|
71
|
+
sawRepeat,
|
|
72
|
+
sawBigInt
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Should this value be withheld from the wire — too big, or unserializable?
|
|
78
|
+
*
|
|
79
|
+
* The ordering is the point: measure with the early-abort walk, and only pay
|
|
80
|
+
* for `JSON.stringify` when the walk found a reason it might throw.
|
|
81
|
+
*/
|
|
82
|
+
export function isOverWireBudget(value, limit) {
|
|
83
|
+
const walk = approxJsonSize(value, limit);
|
|
84
|
+
if (walk.bytes > limit) return true;
|
|
85
|
+
// A finished walk with no repeated reference and no bigint cannot throw.
|
|
86
|
+
//
|
|
87
|
+
// Not exhaustive even then: a `toJSON`/getter that throws is invisible to
|
|
88
|
+
// the walk, so callers handling hostile payloads should still guard their
|
|
89
|
+
// own conversion. `safeEmit` is the last backstop.
|
|
90
|
+
if (!walk.sawRepeat && !walk.sawBigInt) return false;
|
|
91
|
+
return !isJsonSerializable(value);
|
|
92
|
+
}
|
|
@@ -8,12 +8,17 @@ export function HeaderSearchButton({
|
|
|
8
8
|
onPress,
|
|
9
9
|
size = 14,
|
|
10
10
|
color = gameUIColors.secondary,
|
|
11
|
-
style
|
|
11
|
+
style,
|
|
12
|
+
accessibilityLabel = "Search",
|
|
13
|
+
testID
|
|
12
14
|
}) {
|
|
13
15
|
return /*#__PURE__*/_jsx(TouchableOpacity, {
|
|
14
16
|
onPress: onPress,
|
|
15
17
|
style: [styles.button, style],
|
|
16
18
|
activeOpacity: 0.7,
|
|
19
|
+
accessibilityRole: "button",
|
|
20
|
+
accessibilityLabel: accessibilityLabel,
|
|
21
|
+
testID: testID,
|
|
17
22
|
children: /*#__PURE__*/_jsx(Search, {
|
|
18
23
|
size: size,
|
|
19
24
|
color: color
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { View, Text, TouchableOpacity, StyleSheet } from "react-native";
|
|
4
|
-
import {
|
|
3
|
+
import { View, Text, TextInput, TouchableOpacity, StyleSheet } from "react-native";
|
|
4
|
+
import { useEffect, useRef } from "react";
|
|
5
|
+
import { ChevronLeft, Search as SearchIcon, X } from "../../icons/index.js";
|
|
5
6
|
import { buoyColors } from "../gameUI/constants/gameUIColors.js";
|
|
6
7
|
|
|
7
8
|
// Base ModalHeader container component
|
|
@@ -111,10 +112,51 @@ export function Actions({
|
|
|
111
112
|
}
|
|
112
113
|
Actions.displayName = "ModalHeaderActions";
|
|
113
114
|
|
|
115
|
+
// Expanding search input for the header. Render this IN PLACE OF
|
|
116
|
+
// `ModalHeader.Content` while search is active — it fills the same flex slot.
|
|
117
|
+
// Extracts the idiom env/network/storage each hand-rolled (~50 lines apiece).
|
|
118
|
+
|
|
119
|
+
export function HeaderSearch({
|
|
120
|
+
value,
|
|
121
|
+
onChangeText,
|
|
122
|
+
onCancel,
|
|
123
|
+
placeholder = "Search...",
|
|
124
|
+
autoFocus = true
|
|
125
|
+
}) {
|
|
126
|
+
const inputRef = useRef(null);
|
|
127
|
+
useEffect(() => {
|
|
128
|
+
if (autoFocus) inputRef.current?.focus();
|
|
129
|
+
}, [autoFocus]);
|
|
130
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
131
|
+
style: styles.searchContainer,
|
|
132
|
+
children: [/*#__PURE__*/_jsx(SearchIcon, {
|
|
133
|
+
size: 12,
|
|
134
|
+
color: buoyColors.textSecondary
|
|
135
|
+
}), /*#__PURE__*/_jsx(TextInput, {
|
|
136
|
+
ref: inputRef,
|
|
137
|
+
style: styles.searchInput,
|
|
138
|
+
placeholder: placeholder,
|
|
139
|
+
placeholderTextColor: buoyColors.textMuted,
|
|
140
|
+
value: value,
|
|
141
|
+
onChangeText: onChangeText,
|
|
142
|
+
autoCorrect: false,
|
|
143
|
+
autoCapitalize: "none"
|
|
144
|
+
}), /*#__PURE__*/_jsx(TouchableOpacity, {
|
|
145
|
+
onPress: onCancel,
|
|
146
|
+
style: styles.searchCancelButton,
|
|
147
|
+
children: /*#__PURE__*/_jsx(X, {
|
|
148
|
+
size: 12,
|
|
149
|
+
color: buoyColors.textSecondary
|
|
150
|
+
})
|
|
151
|
+
})]
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
114
155
|
// Attach sub-components to the main component
|
|
115
156
|
ModalHeader.Navigation = Navigation;
|
|
116
157
|
ModalHeader.Content = Content;
|
|
117
158
|
ModalHeader.Actions = Actions;
|
|
159
|
+
ModalHeader.Search = HeaderSearch;
|
|
118
160
|
const styles = StyleSheet.create({
|
|
119
161
|
headerContainer: {
|
|
120
162
|
flexDirection: "row",
|
|
@@ -162,5 +204,31 @@ const styles = StyleSheet.create({
|
|
|
162
204
|
},
|
|
163
205
|
headerContentNoMargin: {
|
|
164
206
|
marginHorizontal: 0
|
|
207
|
+
},
|
|
208
|
+
searchContainer: {
|
|
209
|
+
flexDirection: "row",
|
|
210
|
+
alignItems: "center",
|
|
211
|
+
flex: 1,
|
|
212
|
+
backgroundColor: buoyColors.input,
|
|
213
|
+
borderRadius: 6,
|
|
214
|
+
paddingHorizontal: 10,
|
|
215
|
+
paddingVertical: 4,
|
|
216
|
+
marginHorizontal: 12,
|
|
217
|
+
marginVertical: 4,
|
|
218
|
+
height: 32,
|
|
219
|
+
borderWidth: 1,
|
|
220
|
+
borderColor: buoyColors.border
|
|
221
|
+
},
|
|
222
|
+
searchInput: {
|
|
223
|
+
flex: 1,
|
|
224
|
+
marginLeft: 8,
|
|
225
|
+
fontSize: 13,
|
|
226
|
+
color: buoyColors.text,
|
|
227
|
+
padding: 0,
|
|
228
|
+
height: "100%"
|
|
229
|
+
},
|
|
230
|
+
searchCancelButton: {
|
|
231
|
+
padding: 4,
|
|
232
|
+
marginLeft: 4
|
|
165
233
|
}
|
|
166
234
|
});
|