@andrewcyuan/focusgrid 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -9
- package/dist/core/index.cjs +194 -299
- package/dist/core/index.d.cts +18 -11
- package/dist/core/index.d.ts +18 -11
- package/dist/core/index.js +195 -299
- package/dist/dom/index.cjs +59 -145
- package/dist/dom/index.d.cts +0 -2
- package/dist/dom/index.d.ts +0 -2
- package/dist/dom/index.js +59 -145
- package/dist/react/index.cjs +52 -53
- package/dist/react/index.d.cts +22 -21
- package/dist/react/index.d.ts +22 -21
- package/dist/react/index.js +53 -54
- package/dist/react/styles.css +9 -9
- package/package.json +18 -24
package/dist/react/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createContext, useCallback, useContext, useEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
2
|
-
import { isEditableTarget, mountFocusGrid } from "@andrewcyuan/focusgrid/dom";
|
|
2
|
+
import { FocusGridDomController, isEditableTarget, mountFocusGrid } from "@andrewcyuan/focusgrid/dom";
|
|
3
3
|
import { ShortcutScope, useShortcuts } from "@andrewcyuan/shortcut-engine/react";
|
|
4
4
|
import "@andrewcyuan/shortcut-engine";
|
|
5
5
|
import { FocusGridController } from "@andrewcyuan/focusgrid/core";
|
|
@@ -18,114 +18,120 @@ const defaultPaneShortcutActions = [
|
|
|
18
18
|
id: "split-right",
|
|
19
19
|
label: "Split right",
|
|
20
20
|
action: (controller) => controller.splitActive("right"),
|
|
21
|
-
defaultSequence: "Ctrl-
|
|
21
|
+
defaultSequence: "Ctrl-S |"
|
|
22
22
|
},
|
|
23
23
|
{
|
|
24
24
|
id: "split-down",
|
|
25
25
|
label: "Split down",
|
|
26
26
|
action: (controller) => controller.splitActive("down"),
|
|
27
|
-
defaultSequence: "Ctrl-
|
|
27
|
+
defaultSequence: "Ctrl-S -"
|
|
28
28
|
},
|
|
29
29
|
{
|
|
30
30
|
id: "close",
|
|
31
31
|
label: "Close active",
|
|
32
32
|
action: (controller) => controller.removeActive(),
|
|
33
|
-
defaultSequence: "Ctrl-
|
|
33
|
+
defaultSequence: "Ctrl-S X"
|
|
34
34
|
},
|
|
35
35
|
{
|
|
36
36
|
id: "focus-left",
|
|
37
37
|
label: "Focus left",
|
|
38
38
|
action: (controller) => controller.focusAdjacent("left"),
|
|
39
|
-
defaultSequence: "Ctrl-
|
|
39
|
+
defaultSequence: "Ctrl-H"
|
|
40
40
|
},
|
|
41
41
|
{
|
|
42
42
|
id: "focus-right",
|
|
43
43
|
label: "Focus right",
|
|
44
44
|
action: (controller) => controller.focusAdjacent("right"),
|
|
45
|
-
defaultSequence: "Ctrl-
|
|
45
|
+
defaultSequence: "Ctrl-L"
|
|
46
46
|
},
|
|
47
47
|
{
|
|
48
48
|
id: "focus-up",
|
|
49
49
|
label: "Focus up",
|
|
50
50
|
action: (controller) => controller.focusAdjacent("up"),
|
|
51
|
-
defaultSequence: "Ctrl-
|
|
51
|
+
defaultSequence: "Ctrl-K"
|
|
52
52
|
},
|
|
53
53
|
{
|
|
54
54
|
id: "focus-down",
|
|
55
55
|
label: "Focus down",
|
|
56
56
|
action: (controller) => controller.focusAdjacent("down"),
|
|
57
|
-
defaultSequence: "Ctrl-
|
|
57
|
+
defaultSequence: "Ctrl-J"
|
|
58
58
|
},
|
|
59
59
|
{
|
|
60
60
|
id: "swap-left",
|
|
61
61
|
label: "Swap left",
|
|
62
62
|
action: (controller) => controller.swapAdjacent("left"),
|
|
63
|
-
defaultSequence: "Ctrl-
|
|
63
|
+
defaultSequence: "Ctrl-S Shift-Left"
|
|
64
64
|
},
|
|
65
65
|
{
|
|
66
66
|
id: "swap-right",
|
|
67
67
|
label: "Swap right",
|
|
68
68
|
action: (controller) => controller.swapAdjacent("right"),
|
|
69
|
-
defaultSequence: "Ctrl-
|
|
69
|
+
defaultSequence: "Ctrl-S Shift-Right"
|
|
70
70
|
},
|
|
71
71
|
{
|
|
72
72
|
id: "swap-up",
|
|
73
73
|
label: "Swap up",
|
|
74
74
|
action: (controller) => controller.swapAdjacent("up"),
|
|
75
|
-
defaultSequence: "Ctrl-
|
|
75
|
+
defaultSequence: "Ctrl-S Shift-Up"
|
|
76
76
|
},
|
|
77
77
|
{
|
|
78
78
|
id: "swap-down",
|
|
79
79
|
label: "Swap down",
|
|
80
80
|
action: (controller) => controller.swapAdjacent("down"),
|
|
81
|
-
defaultSequence: "Ctrl-
|
|
81
|
+
defaultSequence: "Ctrl-S Shift-Down"
|
|
82
82
|
},
|
|
83
83
|
{
|
|
84
84
|
id: "resize-left",
|
|
85
85
|
label: "Resize left",
|
|
86
86
|
action: (controller) => controller.resizeActive("left", 48),
|
|
87
|
-
defaultSequence: "Ctrl-
|
|
87
|
+
defaultSequence: "Ctrl-Shift-H",
|
|
88
88
|
repeat: true
|
|
89
89
|
},
|
|
90
90
|
{
|
|
91
91
|
id: "resize-right",
|
|
92
92
|
label: "Resize right",
|
|
93
93
|
action: (controller) => controller.resizeActive("right", 48),
|
|
94
|
-
defaultSequence: "Ctrl-
|
|
94
|
+
defaultSequence: "Ctrl-Shift-L",
|
|
95
95
|
repeat: true
|
|
96
96
|
},
|
|
97
97
|
{
|
|
98
98
|
id: "resize-up",
|
|
99
99
|
label: "Resize up",
|
|
100
100
|
action: (controller) => controller.resizeActive("up", 48),
|
|
101
|
-
defaultSequence: "Ctrl-
|
|
101
|
+
defaultSequence: "Ctrl-Shift-K",
|
|
102
102
|
repeat: true
|
|
103
103
|
},
|
|
104
104
|
{
|
|
105
105
|
id: "resize-down",
|
|
106
106
|
label: "Resize down",
|
|
107
107
|
action: (controller) => controller.resizeActive("down", 48),
|
|
108
|
-
defaultSequence: "Ctrl-
|
|
108
|
+
defaultSequence: "Ctrl-Shift-J",
|
|
109
109
|
repeat: true
|
|
110
110
|
}
|
|
111
111
|
];
|
|
112
112
|
function createDefaultPaneShortcuts() {
|
|
113
113
|
return Object.fromEntries(defaultPaneShortcutActions.map((action) => [action.id, action.defaultSequence]));
|
|
114
114
|
}
|
|
115
|
-
function createDefaultPaneKeymap(controller) {
|
|
115
|
+
function createDefaultPaneKeymap(controller, shortcuts = createDefaultPaneShortcuts()) {
|
|
116
116
|
return defaultPaneShortcutActions.map((definition) => ({
|
|
117
|
-
sequence: definition.
|
|
117
|
+
sequence: shortcuts[definition.id],
|
|
118
118
|
action: () => {
|
|
119
119
|
definition.action(controller);
|
|
120
120
|
},
|
|
121
|
-
repeat: "repeat" in definition
|
|
121
|
+
repeat: "repeat" in definition && definition.repeat
|
|
122
122
|
}));
|
|
123
123
|
}
|
|
124
124
|
//#endregion
|
|
125
125
|
//#region react/src/hooks.ts
|
|
126
|
-
function useFocusGridController(createProps
|
|
127
|
-
const [
|
|
128
|
-
|
|
126
|
+
function useFocusGridController(createProps) {
|
|
127
|
+
const [controllers] = useState(() => {
|
|
128
|
+
const domController = new FocusGridDomController();
|
|
129
|
+
return {
|
|
130
|
+
controller: new FocusGridController(createProps(), domController),
|
|
131
|
+
domController
|
|
132
|
+
};
|
|
133
|
+
});
|
|
134
|
+
return controllers;
|
|
129
135
|
}
|
|
130
136
|
function useControllerLayout(controller) {
|
|
131
137
|
const subscribe = useCallback((notify) => controller.subscribe(notify), [controller]);
|
|
@@ -133,34 +139,25 @@ function useControllerLayout(controller) {
|
|
|
133
139
|
return useSyncExternalStore(subscribe, getLayout, getLayout);
|
|
134
140
|
}
|
|
135
141
|
//#endregion
|
|
136
|
-
//#region react/src/ResizeHandle.tsx
|
|
137
|
-
function ResizeHandle({ handle }) {
|
|
138
|
-
const style = {
|
|
139
|
-
left: handle.rect.x,
|
|
140
|
-
top: handle.rect.y,
|
|
141
|
-
width: handle.rect.width,
|
|
142
|
-
height: handle.rect.height
|
|
143
|
-
};
|
|
144
|
-
return /* @__PURE__ */ jsx("div", {
|
|
145
|
-
className: "FocusgridResizeHandle",
|
|
146
|
-
"data-direction": handle.direction,
|
|
147
|
-
style,
|
|
148
|
-
role: "separator",
|
|
149
|
-
"aria-orientation": handle.direction === "horizontal" ? "vertical" : "horizontal",
|
|
150
|
-
"data-resize-handle": handle.id
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
//#endregion
|
|
154
142
|
//#region react/src/PaneView.tsx
|
|
155
|
-
function PaneView({ node, renderPane }) {
|
|
156
|
-
return renderNode(node, renderPane);
|
|
157
|
-
}
|
|
158
143
|
function renderNode(node, renderPane) {
|
|
159
144
|
if (node.kind === "pane") return [/* @__PURE__ */ jsx(PaneShell, {
|
|
160
145
|
pane: node.pane,
|
|
161
146
|
renderPane
|
|
162
147
|
}, `pane:${node.pane.paneId}`)];
|
|
163
|
-
return node.children.flatMap((child, index) =>
|
|
148
|
+
return node.children.flatMap((child, index) => {
|
|
149
|
+
const elements = renderNode(child, renderPane);
|
|
150
|
+
const handle = node.handles[index];
|
|
151
|
+
return handle ? [...elements, /* @__PURE__ */ jsx(ResizeHandle, { handle }, `handle:${handle.id}`)] : elements;
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
function rectStyle(rect) {
|
|
155
|
+
return {
|
|
156
|
+
left: rect.x,
|
|
157
|
+
top: rect.y,
|
|
158
|
+
width: rect.width,
|
|
159
|
+
height: rect.height
|
|
160
|
+
};
|
|
164
161
|
}
|
|
165
162
|
function PaneShell({ pane, renderPane }) {
|
|
166
163
|
const { controller } = useGridControllers();
|
|
@@ -169,12 +166,7 @@ function PaneShell({ pane, renderPane }) {
|
|
|
169
166
|
"data-active": pane.active,
|
|
170
167
|
"data-pane-id": pane.paneId,
|
|
171
168
|
tabIndex: -1,
|
|
172
|
-
style:
|
|
173
|
-
left: pane.rect.x,
|
|
174
|
-
top: pane.rect.y,
|
|
175
|
-
width: pane.rect.width,
|
|
176
|
-
height: pane.rect.height
|
|
177
|
-
},
|
|
169
|
+
style: rectStyle(pane.rect),
|
|
178
170
|
children: renderPane({
|
|
179
171
|
paneId: pane.paneId,
|
|
180
172
|
rect: pane.rect,
|
|
@@ -183,6 +175,16 @@ function PaneShell({ pane, renderPane }) {
|
|
|
183
175
|
})
|
|
184
176
|
});
|
|
185
177
|
}
|
|
178
|
+
function ResizeHandle({ handle }) {
|
|
179
|
+
return /* @__PURE__ */ jsx("div", {
|
|
180
|
+
className: "FocusgridResizeHandle",
|
|
181
|
+
"data-direction": handle.direction,
|
|
182
|
+
style: rectStyle(handle.rect),
|
|
183
|
+
role: "separator",
|
|
184
|
+
"aria-orientation": handle.direction === "horizontal" ? "vertical" : "horizontal",
|
|
185
|
+
"data-resize-handle": handle.id
|
|
186
|
+
});
|
|
187
|
+
}
|
|
186
188
|
//#endregion
|
|
187
189
|
//#region react/src/FocusGrid.tsx
|
|
188
190
|
function FocusGrid({ className, onPaneLayoutChange, onPaneClose, ...content }) {
|
|
@@ -210,10 +212,7 @@ function GridContent({ keymap, renderPane }) {
|
|
|
210
212
|
const { controller } = useGridControllers();
|
|
211
213
|
const layout = useControllerLayout(controller);
|
|
212
214
|
useShortcuts(keymap ?? createDefaultPaneKeymap(controller));
|
|
213
|
-
return
|
|
214
|
-
node: layout.root,
|
|
215
|
-
renderPane
|
|
216
|
-
});
|
|
215
|
+
return renderNode(layout.root, renderPane);
|
|
217
216
|
}
|
|
218
217
|
//#endregion
|
|
219
218
|
//#region react/src/composite-shortcuts.ts
|
package/dist/react/styles.css
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
.FocusgridFocusGrid {
|
|
1
|
+
:where(.FocusgridFocusGrid) {
|
|
2
2
|
position: relative;
|
|
3
3
|
width: 100%;
|
|
4
4
|
height: 100%;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
outline: none;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
.FocusgridPaneView {
|
|
10
|
+
:where(.FocusgridPaneView) {
|
|
11
11
|
position: absolute;
|
|
12
12
|
box-sizing: border-box;
|
|
13
13
|
overflow: hidden;
|
|
@@ -15,28 +15,28 @@
|
|
|
15
15
|
min-height: 0;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
.FocusgridPaneView[data-active="true"] {
|
|
18
|
+
:where(.FocusgridFocusGrid:focus-within .FocusgridPaneView[data-active="true"]) {
|
|
19
19
|
outline: 1px solid var(--focusgrid-focus-color, #4d8dff);
|
|
20
20
|
outline-offset: -1px;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
.FocusgridResizeHandle {
|
|
23
|
+
:where(.FocusgridResizeHandle) {
|
|
24
24
|
position: absolute;
|
|
25
25
|
box-sizing: border-box;
|
|
26
26
|
z-index: 2;
|
|
27
|
-
background: transparent;
|
|
27
|
+
background: var(--focusgrid-handle-idle-color, transparent);
|
|
28
28
|
touch-action: none;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
.FocusgridResizeHandle[data-direction="horizontal"] {
|
|
31
|
+
:where(.FocusgridResizeHandle[data-direction="horizontal"]) {
|
|
32
32
|
cursor: col-resize;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
.FocusgridResizeHandle[data-direction="vertical"] {
|
|
35
|
+
:where(.FocusgridResizeHandle[data-direction="vertical"]) {
|
|
36
36
|
cursor: row-resize;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
.FocusgridResizeHandle:hover,
|
|
40
|
-
.FocusgridResizeHandle:focus-visible {
|
|
39
|
+
:where(.FocusgridResizeHandle:hover),
|
|
40
|
+
:where(.FocusgridResizeHandle:focus-visible) {
|
|
41
41
|
background: var(--focusgrid-handle-color, rgb(77 141 255 / 35%));
|
|
42
42
|
}
|
package/package.json
CHANGED
|
@@ -1,32 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andrewcyuan/focusgrid",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Keyboard-native pane layouts and deterministic focus management for web applications.",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"keyboard-navigation",
|
|
7
6
|
"focus-management",
|
|
7
|
+
"keyboard-navigation",
|
|
8
8
|
"pane-layout",
|
|
9
9
|
"react",
|
|
10
10
|
"typescript"
|
|
11
11
|
],
|
|
12
|
-
"type": "module",
|
|
13
12
|
"license": "MIT",
|
|
14
|
-
"sideEffects": [
|
|
15
|
-
"./dist/react/styles.css",
|
|
16
|
-
"./react/styles.css"
|
|
17
|
-
],
|
|
18
|
-
"files": [
|
|
19
|
-
"dist",
|
|
20
|
-
"LICENSE"
|
|
21
|
-
],
|
|
22
13
|
"repository": {
|
|
23
14
|
"type": "git",
|
|
24
15
|
"url": "git+https://github.com/andrewcyuan/focusgrid.git",
|
|
25
16
|
"directory": "packages/focusgrid"
|
|
26
17
|
},
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"type": "module",
|
|
23
|
+
"sideEffects": [
|
|
24
|
+
"./dist/react/styles.css",
|
|
25
|
+
"./react/styles.css"
|
|
26
|
+
],
|
|
30
27
|
"exports": {
|
|
31
28
|
"./core": {
|
|
32
29
|
"types": "./dist/core/index.d.ts",
|
|
@@ -45,22 +42,19 @@
|
|
|
45
42
|
},
|
|
46
43
|
"./react/styles.css": "./dist/react/styles.css"
|
|
47
44
|
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "tsdown core/src/index.ts --config buildConfig.mjs --format esm,cjs --out-dir dist/core && tsdown dom/src/index.ts --config buildConfig.mjs --format esm,cjs --out-dir dist/dom --no-clean && tsdown react/src/index.tsx --config buildConfig.mjs --format esm,cjs --out-dir dist/react --no-clean && cp react/src/styles.css dist/react/styles.css",
|
|
50
50
|
"test": "vitest run --config ../../vitest.config.ts",
|
|
51
|
-
"typecheck": "tsc --noEmit"
|
|
52
|
-
|
|
51
|
+
"typecheck": "tsc --noEmit"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@andrewcyuan/shortcut-engine": "0.2.0"
|
|
53
55
|
},
|
|
54
56
|
"peerDependencies": {
|
|
55
57
|
"react": ">=18",
|
|
56
58
|
"react-dom": ">=18"
|
|
57
|
-
},
|
|
58
|
-
"dependencies": {
|
|
59
|
-
"@andrewcyuan/shortcut-engine": "0.1.0"
|
|
60
|
-
},
|
|
61
|
-
"devDependencies": {
|
|
62
|
-
"@types/react": "^18.3.18",
|
|
63
|
-
"@types/react-dom": "^18.3.5",
|
|
64
|
-
"vitest": "^2.1.8"
|
|
65
59
|
}
|
|
66
60
|
}
|