giggles 0.6.0 → 0.6.1
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.
|
@@ -36,8 +36,13 @@ function useKeybindings(focus, bindings, options) {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
// src/core/input/useKeybindingRegistry.ts
|
|
39
|
+
import { useSyncExternalStore } from "react";
|
|
39
40
|
function useKeybindingRegistry(focus) {
|
|
40
41
|
const store = useStore();
|
|
42
|
+
useSyncExternalStore(
|
|
43
|
+
(cb) => store.subscribe(cb),
|
|
44
|
+
() => store.getVersion()
|
|
45
|
+
);
|
|
41
46
|
const all = store.getAllBindings().filter((b) => b.name != null);
|
|
42
47
|
const branchPath = store.getActiveBranchPath();
|
|
43
48
|
const branchSet = new Set(branchPath);
|
|
@@ -47,15 +52,24 @@ function useKeybindingRegistry(focus) {
|
|
|
47
52
|
const trapIndex = branchPath.indexOf(trapNodeId);
|
|
48
53
|
return trapIndex >= 0 ? new Set(branchPath.slice(0, trapIndex + 1)) : null;
|
|
49
54
|
})();
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
55
|
+
const availableSet = withinTrapSet ?? branchSet;
|
|
56
|
+
const seenKeys = /* @__PURE__ */ new Set();
|
|
57
|
+
const available = [];
|
|
58
|
+
for (const nodeId of branchPath) {
|
|
59
|
+
if (!availableSet.has(nodeId)) continue;
|
|
60
|
+
for (const b of all) {
|
|
61
|
+
if (b.nodeId === nodeId && !seenKeys.has(b.key)) {
|
|
62
|
+
seenKeys.add(b.key);
|
|
63
|
+
available.push(b);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
53
67
|
const local = focus ? all.filter((b) => b.nodeId === focus.id) : [];
|
|
54
68
|
return { all, available, local };
|
|
55
69
|
}
|
|
56
70
|
|
|
57
71
|
// src/core/focus/useFocusNode.ts
|
|
58
|
-
import { useContext as useContext2, useEffect as useEffect2, useId as useId2, useMemo, useSyncExternalStore } from "react";
|
|
72
|
+
import { useContext as useContext2, useEffect as useEffect2, useId as useId2, useMemo, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
59
73
|
function useFocusNode(options) {
|
|
60
74
|
var _a;
|
|
61
75
|
const id = useId2();
|
|
@@ -69,7 +83,7 @@ function useFocusNode(options) {
|
|
|
69
83
|
store.unregisterNode(id);
|
|
70
84
|
};
|
|
71
85
|
}, [id, parentId, store]);
|
|
72
|
-
const hasFocus =
|
|
86
|
+
const hasFocus = useSyncExternalStore2(subscribe, () => store.isFocused(id));
|
|
73
87
|
return { id, hasFocus };
|
|
74
88
|
}
|
|
75
89
|
|
|
@@ -106,7 +120,7 @@ function InputRouter({ children }) {
|
|
|
106
120
|
}
|
|
107
121
|
|
|
108
122
|
// src/core/focus/useFocusScope.ts
|
|
109
|
-
import { useCallback, useContext as useContext3, useEffect as useEffect4, useId as useId3, useMemo as useMemo2, useSyncExternalStore as
|
|
123
|
+
import { useCallback, useContext as useContext3, useEffect as useEffect4, useId as useId3, useMemo as useMemo2, useSyncExternalStore as useSyncExternalStore3 } from "react";
|
|
110
124
|
function useFocusScope(options) {
|
|
111
125
|
var _a;
|
|
112
126
|
const id = useId3();
|
|
@@ -121,8 +135,8 @@ function useFocusScope(options) {
|
|
|
121
135
|
store.unregisterNode(id);
|
|
122
136
|
};
|
|
123
137
|
}, [id, parentId, store]);
|
|
124
|
-
const hasFocus =
|
|
125
|
-
const isPassive =
|
|
138
|
+
const hasFocus = useSyncExternalStore3(subscribe, () => store.isFocused(id));
|
|
139
|
+
const isPassive = useSyncExternalStore3(subscribe, () => store.isPassive(id));
|
|
126
140
|
const next = useCallback(() => store.navigateSibling("next", true, id), [store, id]);
|
|
127
141
|
const prev = useCallback(() => store.navigateSibling("prev", true, id), [store, id]);
|
|
128
142
|
const nextShallow = useCallback(() => store.navigateSibling("next", true, id, true), [store, id]);
|
|
@@ -178,6 +192,7 @@ var FocusStore = class {
|
|
|
178
192
|
pendingFocusFirstChild = /* @__PURE__ */ new Set();
|
|
179
193
|
trapNodeId = null;
|
|
180
194
|
listeners = /* @__PURE__ */ new Set();
|
|
195
|
+
version = 0;
|
|
181
196
|
// nodeId → registrationId → BindingRegistration
|
|
182
197
|
// Keybindings register synchronously during render; nodes register in useEffect.
|
|
183
198
|
// A keybinding may exist for a node that has not yet appeared in the node tree —
|
|
@@ -191,10 +206,14 @@ var FocusStore = class {
|
|
|
191
206
|
return () => this.listeners.delete(listener);
|
|
192
207
|
}
|
|
193
208
|
notify() {
|
|
209
|
+
this.version++;
|
|
194
210
|
for (const listener of this.listeners) {
|
|
195
211
|
listener();
|
|
196
212
|
}
|
|
197
213
|
}
|
|
214
|
+
getVersion() {
|
|
215
|
+
return this.version;
|
|
216
|
+
}
|
|
198
217
|
// ---------------------------------------------------------------------------
|
|
199
218
|
// Registration
|
|
200
219
|
// ---------------------------------------------------------------------------
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useTerminalSize
|
|
3
|
-
} from "./chunk-WNGBTD67.js";
|
|
4
1
|
import {
|
|
5
2
|
FocusScope,
|
|
6
3
|
FocusStore,
|
|
@@ -14,11 +11,14 @@ import {
|
|
|
14
11
|
useKeybindingRegistry,
|
|
15
12
|
useKeybindings,
|
|
16
13
|
useStore
|
|
17
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-A7BRQXWE.js";
|
|
18
15
|
import {
|
|
19
16
|
ThemeProvider,
|
|
20
17
|
useTheme
|
|
21
18
|
} from "./chunk-C77VBSPK.js";
|
|
19
|
+
import {
|
|
20
|
+
useTerminalSize
|
|
21
|
+
} from "./chunk-WNGBTD67.js";
|
|
22
22
|
|
|
23
23
|
// src/core/GigglesProvider.tsx
|
|
24
24
|
import { useRef } from "react";
|
package/dist/ui/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "giggles",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"build": "tsup",
|
|
42
42
|
"build:watch": "nodemon --watch src --ext ts,tsx --exec tsup",
|
|
43
43
|
"play": "tsx --watch",
|
|
44
|
+
"record": "vhs",
|
|
44
45
|
"dev:docs": "pnpm build && concurrently --kill-others \"pnpm build:watch\" \"pnpm --filter documentation dev\"",
|
|
45
46
|
"lint": "prettier --write . && eslint . --fix"
|
|
46
47
|
},
|