@nice-code/state 0.4.0 → 0.4.2
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.
|
@@ -191,105 +191,6 @@ var DEVTOOL_JSON_PUNCTUATION = "#475569";
|
|
|
191
191
|
var MONO_FONT = "ui-monospace, 'Cascadia Code', 'Source Code Pro', monospace";
|
|
192
192
|
var SANS_FONT = "ui-sans-serif, system-ui, sans-serif";
|
|
193
193
|
|
|
194
|
-
// src/devtools/browser/devtools_dock.ts
|
|
195
|
-
var GLOBAL_KEY = "__NICE_DEVTOOLS_DOCK__";
|
|
196
|
-
var VERSION = 2;
|
|
197
|
-
function createCoordinator() {
|
|
198
|
-
const panels = new Map;
|
|
199
|
-
const listeners = new Set;
|
|
200
|
-
function toRef(panel) {
|
|
201
|
-
return {
|
|
202
|
-
id: panel.id,
|
|
203
|
-
label: panel.label,
|
|
204
|
-
icon: panel.icon,
|
|
205
|
-
badge: panel.badge,
|
|
206
|
-
onOpen: panel.onOpen
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
function applyBodyMargins() {
|
|
210
|
-
if (typeof document === "undefined")
|
|
211
|
-
return;
|
|
212
|
-
const margins = { top: 0, bottom: 0, left: 0, right: 0 };
|
|
213
|
-
for (const panel of panels.values()) {
|
|
214
|
-
if (panel.open)
|
|
215
|
-
margins[panel.side] += panel.size;
|
|
216
|
-
}
|
|
217
|
-
const sides = ["top", "bottom", "left", "right"];
|
|
218
|
-
for (const side of sides) {
|
|
219
|
-
if (margins[side] > 0) {
|
|
220
|
-
document.body.style.setProperty(`margin-${side}`, `${margins[side]}px`);
|
|
221
|
-
} else {
|
|
222
|
-
document.body.style.removeProperty(`margin-${side}`);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
function notify() {
|
|
227
|
-
applyBodyMargins();
|
|
228
|
-
for (const listener of listeners)
|
|
229
|
-
listener();
|
|
230
|
-
}
|
|
231
|
-
return {
|
|
232
|
-
version: VERSION,
|
|
233
|
-
register(panel) {
|
|
234
|
-
panels.set(panel.id, { ...panel });
|
|
235
|
-
notify();
|
|
236
|
-
return () => {
|
|
237
|
-
panels.delete(panel.id);
|
|
238
|
-
notify();
|
|
239
|
-
};
|
|
240
|
-
},
|
|
241
|
-
update(id, next) {
|
|
242
|
-
const existing = panels.get(id);
|
|
243
|
-
if (existing == null)
|
|
244
|
-
return;
|
|
245
|
-
if (existing.side === next.side && existing.size === next.size && existing.open === next.open && existing.badge === next.badge) {
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
panels.set(id, { ...existing, ...next });
|
|
249
|
-
notify();
|
|
250
|
-
},
|
|
251
|
-
getView(id) {
|
|
252
|
-
const list = [...panels.values()];
|
|
253
|
-
const anyOpen = list.some((p) => p.open);
|
|
254
|
-
const firstId = list.length > 0 ? list[0].id : null;
|
|
255
|
-
let dockOffset = 0;
|
|
256
|
-
const self = panels.get(id);
|
|
257
|
-
if (self != null && self.open) {
|
|
258
|
-
for (const panel of list) {
|
|
259
|
-
if (panel.id === id)
|
|
260
|
-
break;
|
|
261
|
-
if (panel.open && panel.side === self.side)
|
|
262
|
-
dockOffset += panel.size;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
return {
|
|
266
|
-
dockOffset,
|
|
267
|
-
anyOpen,
|
|
268
|
-
isPrimary: id === firstId,
|
|
269
|
-
devtools: list.map(toRef),
|
|
270
|
-
otherClosed: list.filter((p) => !p.open && p.id !== id).map(toRef)
|
|
271
|
-
};
|
|
272
|
-
},
|
|
273
|
-
subscribe(listener) {
|
|
274
|
-
listeners.add(listener);
|
|
275
|
-
return () => {
|
|
276
|
-
listeners.delete(listener);
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
function getDevtoolsDockCoordinator() {
|
|
282
|
-
if (typeof window === "undefined")
|
|
283
|
-
return createCoordinator();
|
|
284
|
-
const host = window;
|
|
285
|
-
const existing = host[GLOBAL_KEY];
|
|
286
|
-
if (existing != null && existing.version === VERSION)
|
|
287
|
-
return existing;
|
|
288
|
-
const created = createCoordinator();
|
|
289
|
-
host[GLOBAL_KEY] = created;
|
|
290
|
-
return created;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
194
|
// src/devtools/browser/components/ChangeDetailPanel.tsx
|
|
294
195
|
import { useState as useState2 } from "react";
|
|
295
196
|
|
|
@@ -571,9 +472,15 @@ import {
|
|
|
571
472
|
import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
|
|
572
473
|
var DOCKED_SIZE_MIN = 160;
|
|
573
474
|
var POSITION_GRID = [
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
475
|
+
{ key: "tl", pos: null },
|
|
476
|
+
{ key: "tc", pos: "dock-top" },
|
|
477
|
+
{ key: "tr", pos: null },
|
|
478
|
+
{ key: "ml", pos: "dock-left" },
|
|
479
|
+
{ key: "mc", pos: null },
|
|
480
|
+
{ key: "mr", pos: "dock-right" },
|
|
481
|
+
{ key: "bl", pos: null },
|
|
482
|
+
{ key: "bc", pos: "dock-bottom" },
|
|
483
|
+
{ key: "br", pos: null }
|
|
577
484
|
];
|
|
578
485
|
function getDockSide(pos) {
|
|
579
486
|
switch (pos) {
|
|
@@ -705,12 +612,11 @@ function PositionPicker({
|
|
|
705
612
|
return /* @__PURE__ */ jsxDEV3("div", {
|
|
706
613
|
title: "Move / dock panel",
|
|
707
614
|
style: { display: "grid", gridTemplateColumns: "repeat(3, 9px)", gap: "2px", padding: "2px" },
|
|
708
|
-
children: POSITION_GRID.
|
|
615
|
+
children: POSITION_GRID.map(({ key, pos }) => {
|
|
709
616
|
if (pos == null)
|
|
710
617
|
return /* @__PURE__ */ jsxDEV3("div", {
|
|
711
618
|
style: { width: "9px", height: "9px" }
|
|
712
|
-
},
|
|
713
|
-
const isDock = pos.startsWith("dock-");
|
|
619
|
+
}, key, false, undefined, this);
|
|
714
620
|
const isTopBottom = pos === "dock-top" || pos === "dock-bottom";
|
|
715
621
|
const isActive = pos === position;
|
|
716
622
|
return /* @__PURE__ */ jsxDEV3("div", {
|
|
@@ -726,13 +632,13 @@ function PositionPicker({
|
|
|
726
632
|
},
|
|
727
633
|
children: /* @__PURE__ */ jsxDEV3("div", {
|
|
728
634
|
style: {
|
|
729
|
-
width:
|
|
730
|
-
height:
|
|
731
|
-
borderRadius:
|
|
635
|
+
width: isTopBottom ? "9px" : "3px",
|
|
636
|
+
height: isTopBottom ? "3px" : "9px",
|
|
637
|
+
borderRadius: "1px",
|
|
732
638
|
background: isActive ? DEVTOOL_COLOR_SEMANTIC_SYSTEM : DEVTOOL_COLOR_TEXT_FAINT
|
|
733
639
|
}
|
|
734
640
|
}, undefined, false, undefined, this)
|
|
735
|
-
},
|
|
641
|
+
}, key, false, undefined, this);
|
|
736
642
|
})
|
|
737
643
|
}, undefined, false, undefined, this);
|
|
738
644
|
}
|
|
@@ -1395,6 +1301,105 @@ function Pill({
|
|
|
1395
1301
|
}, undefined, true, undefined, this);
|
|
1396
1302
|
}
|
|
1397
1303
|
|
|
1304
|
+
// src/devtools/browser/devtools_dock.ts
|
|
1305
|
+
var GLOBAL_KEY = "__NICE_DEVTOOLS_DOCK__";
|
|
1306
|
+
var VERSION = 2;
|
|
1307
|
+
function createCoordinator() {
|
|
1308
|
+
const panels = new Map;
|
|
1309
|
+
const listeners = new Set;
|
|
1310
|
+
function toRef(panel) {
|
|
1311
|
+
return {
|
|
1312
|
+
id: panel.id,
|
|
1313
|
+
label: panel.label,
|
|
1314
|
+
icon: panel.icon,
|
|
1315
|
+
badge: panel.badge,
|
|
1316
|
+
onOpen: panel.onOpen
|
|
1317
|
+
};
|
|
1318
|
+
}
|
|
1319
|
+
function applyBodyMargins() {
|
|
1320
|
+
if (typeof document === "undefined")
|
|
1321
|
+
return;
|
|
1322
|
+
const margins = { top: 0, bottom: 0, left: 0, right: 0 };
|
|
1323
|
+
for (const panel of panels.values()) {
|
|
1324
|
+
if (panel.open)
|
|
1325
|
+
margins[panel.side] += panel.size;
|
|
1326
|
+
}
|
|
1327
|
+
const sides = ["top", "bottom", "left", "right"];
|
|
1328
|
+
for (const side of sides) {
|
|
1329
|
+
if (margins[side] > 0) {
|
|
1330
|
+
document.body.style.setProperty(`margin-${side}`, `${margins[side]}px`);
|
|
1331
|
+
} else {
|
|
1332
|
+
document.body.style.removeProperty(`margin-${side}`);
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
function notify() {
|
|
1337
|
+
applyBodyMargins();
|
|
1338
|
+
for (const listener of listeners)
|
|
1339
|
+
listener();
|
|
1340
|
+
}
|
|
1341
|
+
return {
|
|
1342
|
+
version: VERSION,
|
|
1343
|
+
register(panel) {
|
|
1344
|
+
panels.set(panel.id, { ...panel });
|
|
1345
|
+
notify();
|
|
1346
|
+
return () => {
|
|
1347
|
+
panels.delete(panel.id);
|
|
1348
|
+
notify();
|
|
1349
|
+
};
|
|
1350
|
+
},
|
|
1351
|
+
update(id, next) {
|
|
1352
|
+
const existing = panels.get(id);
|
|
1353
|
+
if (existing == null)
|
|
1354
|
+
return;
|
|
1355
|
+
if (existing.side === next.side && existing.size === next.size && existing.open === next.open && existing.badge === next.badge) {
|
|
1356
|
+
return;
|
|
1357
|
+
}
|
|
1358
|
+
panels.set(id, { ...existing, ...next });
|
|
1359
|
+
notify();
|
|
1360
|
+
},
|
|
1361
|
+
getView(id) {
|
|
1362
|
+
const list = [...panels.values()];
|
|
1363
|
+
const anyOpen = list.some((p) => p.open);
|
|
1364
|
+
const firstId = list.length > 0 ? list[0].id : null;
|
|
1365
|
+
let dockOffset = 0;
|
|
1366
|
+
const self = panels.get(id);
|
|
1367
|
+
if (self != null && self.open) {
|
|
1368
|
+
for (const panel of list) {
|
|
1369
|
+
if (panel.id === id)
|
|
1370
|
+
break;
|
|
1371
|
+
if (panel.open && panel.side === self.side)
|
|
1372
|
+
dockOffset += panel.size;
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
return {
|
|
1376
|
+
dockOffset,
|
|
1377
|
+
anyOpen,
|
|
1378
|
+
isPrimary: id === firstId,
|
|
1379
|
+
devtools: list.map(toRef),
|
|
1380
|
+
otherClosed: list.filter((p) => !p.open && p.id !== id).map(toRef)
|
|
1381
|
+
};
|
|
1382
|
+
},
|
|
1383
|
+
subscribe(listener) {
|
|
1384
|
+
listeners.add(listener);
|
|
1385
|
+
return () => {
|
|
1386
|
+
listeners.delete(listener);
|
|
1387
|
+
};
|
|
1388
|
+
}
|
|
1389
|
+
};
|
|
1390
|
+
}
|
|
1391
|
+
function getDevtoolsDockCoordinator() {
|
|
1392
|
+
if (typeof window === "undefined")
|
|
1393
|
+
return createCoordinator();
|
|
1394
|
+
const host = window;
|
|
1395
|
+
const existing = host[GLOBAL_KEY];
|
|
1396
|
+
if (existing != null && existing.version === VERSION)
|
|
1397
|
+
return existing;
|
|
1398
|
+
const created = createCoordinator();
|
|
1399
|
+
host[GLOBAL_KEY] = created;
|
|
1400
|
+
return created;
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1398
1403
|
// src/devtools/browser/NiceStateDevtools.tsx
|
|
1399
1404
|
import { jsxDEV as jsxDEV9, Fragment } from "react/jsx-dev-runtime";
|
|
1400
1405
|
if (typeof document !== "undefined" && !document.getElementById("__nice-state-devtools-styles")) {
|
|
@@ -1467,12 +1472,12 @@ function NiceStateDevtools_Panel({
|
|
|
1467
1472
|
const [selectedChangeCuid, setSelectedChangeCuid] = useState4(null);
|
|
1468
1473
|
useEffect2(() => core.subscribe(setSnapshot), [core]);
|
|
1469
1474
|
const setPrefs = (update) => {
|
|
1470
|
-
setPrefsRaw((prev) => {
|
|
1471
|
-
const next = { ...prev, ...update };
|
|
1472
|
-
writePrefs(next);
|
|
1473
|
-
return next;
|
|
1474
|
-
});
|
|
1475
|
+
setPrefsRaw((prev) => ({ ...prev, ...update }));
|
|
1475
1476
|
};
|
|
1477
|
+
useEffect2(() => {
|
|
1478
|
+
const timer = setTimeout(() => writePrefs(prefs), 250);
|
|
1479
|
+
return () => clearTimeout(timer);
|
|
1480
|
+
}, [prefs]);
|
|
1476
1481
|
const { stores, changes, paused } = snapshot;
|
|
1477
1482
|
const { position, isOpen, dockedHeight, dockedWidth, detailRatio } = prefs;
|
|
1478
1483
|
const dockSide = getDockSide(position);
|
|
@@ -1529,7 +1534,31 @@ function NiceStateDevtools_Panel({
|
|
|
1529
1534
|
flexDirection: "column",
|
|
1530
1535
|
boxShadow: "0 -4px 24px rgba(0,0,0,0.4)",
|
|
1531
1536
|
overflow: "hidden",
|
|
1532
|
-
...dockSide === "bottom" ? {
|
|
1537
|
+
...dockSide === "bottom" ? {
|
|
1538
|
+
bottom: view.dockOffset,
|
|
1539
|
+
left: 0,
|
|
1540
|
+
right: 0,
|
|
1541
|
+
height: `${dockedSize}px`,
|
|
1542
|
+
borderRadius: "8px 8px 0 0"
|
|
1543
|
+
} : dockSide === "top" ? {
|
|
1544
|
+
top: view.dockOffset,
|
|
1545
|
+
left: 0,
|
|
1546
|
+
right: 0,
|
|
1547
|
+
height: `${dockedSize}px`,
|
|
1548
|
+
borderRadius: "0 0 8px 8px"
|
|
1549
|
+
} : dockSide === "left" ? {
|
|
1550
|
+
top: 0,
|
|
1551
|
+
left: view.dockOffset,
|
|
1552
|
+
bottom: 0,
|
|
1553
|
+
width: `${dockedSize}px`,
|
|
1554
|
+
borderRadius: "0 8px 8px 0"
|
|
1555
|
+
} : {
|
|
1556
|
+
top: 0,
|
|
1557
|
+
right: view.dockOffset,
|
|
1558
|
+
bottom: 0,
|
|
1559
|
+
width: `${dockedSize}px`,
|
|
1560
|
+
borderRadius: "8px 0 0 8px"
|
|
1561
|
+
}
|
|
1533
1562
|
};
|
|
1534
1563
|
return /* @__PURE__ */ jsxDEV9("div", {
|
|
1535
1564
|
id: "__nice-state-devtools-panel",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { StateDevtoolsCore } from "../core/StateDevtoolsCore";
|
|
2
1
|
import type { TDevtoolsPosition } from "../core/StateDevtools.types";
|
|
2
|
+
import type { StateDevtoolsCore } from "../core/StateDevtoolsCore";
|
|
3
3
|
export interface INiceStateDevtoolsProps {
|
|
4
4
|
core: StateDevtoolsCore;
|
|
5
5
|
position?: TDevtoolsPosition;
|
package/package.json
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@nice-code/state",
|
|
3
|
-
"version": "0.4.
|
|
4
|
-
"private": false,
|
|
5
|
-
"type": "module",
|
|
6
|
-
"exports": {
|
|
7
|
-
".": {
|
|
8
|
-
"source": "./src/index.ts",
|
|
9
|
-
"types": "./build/types/index.d.ts",
|
|
10
|
-
"import": "./build/index.js"
|
|
11
|
-
},
|
|
12
|
-
"./react": {
|
|
13
|
-
"source": "./src/react/index.ts",
|
|
14
|
-
"types": "./build/types/react/index.d.ts",
|
|
15
|
-
"import": "./build/react/index.js"
|
|
16
|
-
},
|
|
17
|
-
"./devtools/browser": {
|
|
18
|
-
"source": "./src/devtools/browser/index.ts",
|
|
19
|
-
"types": "./build/types/devtools/browser/index.d.ts",
|
|
20
|
-
"import": "./build/devtools/browser/index.js"
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
"files": [
|
|
24
|
-
"build",
|
|
25
|
-
"package.json",
|
|
26
|
-
"README.md"
|
|
27
|
-
],
|
|
28
|
-
"publishConfig": {
|
|
29
|
-
"access": "public"
|
|
30
|
-
},
|
|
31
|
-
"scripts": {
|
|
32
|
-
"type-check": "bunx tsc --noEmit",
|
|
33
|
-
"type-check-watch": "bunx tsc --noEmit --watch",
|
|
34
|
-
"clean-build": "bunx rimraf build",
|
|
35
|
-
"vitest": "vitest --typecheck",
|
|
36
|
-
"vitest-agent": "vitest --typecheck --reporter=agent",
|
|
37
|
-
"build": "bun run clean-build && bun run build.ts && bun run build-types",
|
|
38
|
-
"build-watch": "bun run clean-build && bun run build.ts --watch && bun run build-types --watch",
|
|
39
|
-
"build-types": "tsc --project tsconfig.build.json"
|
|
40
|
-
},
|
|
41
|
-
"dependencies": {
|
|
42
|
-
"immer": "11.1.8",
|
|
43
|
-
"fast-equals": "6.0.0"
|
|
44
|
-
},
|
|
45
|
-
"devDependencies": {
|
|
46
|
-
"react": "19.2.7"
|
|
47
|
-
},
|
|
48
|
-
"peerDependencies": {
|
|
49
|
-
"react": ">=19"
|
|
50
|
-
},
|
|
51
|
-
"peerDependenciesMeta": {
|
|
52
|
-
"react": {
|
|
53
|
-
"optional": true
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@nice-code/state",
|
|
3
|
+
"version": "0.4.2",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"source": "./src/index.ts",
|
|
9
|
+
"types": "./build/types/index.d.ts",
|
|
10
|
+
"import": "./build/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./react": {
|
|
13
|
+
"source": "./src/react/index.ts",
|
|
14
|
+
"types": "./build/types/react/index.d.ts",
|
|
15
|
+
"import": "./build/react/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./devtools/browser": {
|
|
18
|
+
"source": "./src/devtools/browser/index.ts",
|
|
19
|
+
"types": "./build/types/devtools/browser/index.d.ts",
|
|
20
|
+
"import": "./build/devtools/browser/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"build",
|
|
25
|
+
"package.json",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"type-check": "bunx tsc --noEmit",
|
|
33
|
+
"type-check-watch": "bunx tsc --noEmit --watch",
|
|
34
|
+
"clean-build": "bunx rimraf build",
|
|
35
|
+
"vitest": "vitest --typecheck",
|
|
36
|
+
"vitest-agent": "vitest --typecheck --reporter=agent",
|
|
37
|
+
"build": "bun run clean-build && bun run build.ts && bun run build-types",
|
|
38
|
+
"build-watch": "bun run clean-build && bun run build.ts --watch && bun run build-types --watch",
|
|
39
|
+
"build-types": "tsc --project tsconfig.build.json"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"immer": "11.1.8",
|
|
43
|
+
"fast-equals": "6.0.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"react": "19.2.7"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"react": ">=19"
|
|
50
|
+
},
|
|
51
|
+
"peerDependenciesMeta": {
|
|
52
|
+
"react": {
|
|
53
|
+
"optional": true
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|