@andrewcyuan/focusgrid 0.1.0 → 0.2.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.
@@ -1,175 +1,8 @@
1
+ import { ComputedLayout, DomController, FocusGridController, FocusGridControllerProps, PaneEventHandlers, PaneId, Rect } from "@andrewcyuan/focusgrid/core";
2
+ import { FocusGridDomController } from "@andrewcyuan/focusgrid/dom";
1
3
  import { ReactNode } from "react";
2
4
  import { ShortcutBinding } from "@andrewcyuan/shortcut-engine";
3
5
 
4
- //#region core/src/layout/types.d.ts
5
- type PaneId = string;
6
- type NodeId = string;
7
- type Orientation = "horizontal" | "vertical";
8
- declare const cardinalDirections: readonly ["left", "right", "up", "down"];
9
- type CardinalDirection = (typeof cardinalDirections)[number];
10
- declare enum PaneCommandCapability {
11
- ResizeX = "canResizeX",
12
- ResizeY = "canResizeY",
13
- Remove = "canRemove",
14
- SplitHorizontal = "canSplitHorizontal",
15
- SplitVertical = "canSplitVertical",
16
- SwapX = "canSwapX",
17
- SwapY = "canSwapY",
18
- Focus = "canFocus"
19
- }
20
- type PaneCommandCapabilityInput = Partial<Record<PaneCommandCapability, boolean>>;
21
- type PaneNode = {
22
- kind: "pane";
23
- id: NodeId;
24
- paneId: PaneId;
25
- } & PaneCommandCapabilityInput;
26
- type SplitNode = {
27
- kind: "split";
28
- id: NodeId;
29
- orientation: Orientation;
30
- children: LayoutNode[];
31
- sizes: number[];
32
- lastFocusedChildId?: NodeId;
33
- };
34
- type LayoutNode = PaneNode | SplitNode;
35
- type Rect = {
36
- x: number;
37
- y: number;
38
- width: number;
39
- height: number;
40
- };
41
- type ComputedPane = {
42
- paneId: PaneId;
43
- nodeId: NodeId;
44
- rect: Rect;
45
- active: boolean;
46
- };
47
- type ComputedHandle = {
48
- id: string;
49
- splitId: NodeId;
50
- index: number;
51
- rect: Rect;
52
- direction: Orientation;
53
- };
54
- type ComputedNode = {
55
- kind: "pane";
56
- pane: ComputedPane;
57
- } | {
58
- kind: "split";
59
- orientation: Orientation;
60
- children: ComputedNode[];
61
- handles: ComputedHandle[];
62
- };
63
- type ComputedLayout = {
64
- root: ComputedNode;
65
- rectByNodeId: Map<NodeId, Rect>;
66
- panes: ComputedPane[];
67
- handles: ComputedHandle[];
68
- };
69
- type FocusGridControllerState = {
70
- root: LayoutNode;
71
- activePaneId: PaneId | null;
72
- container: {
73
- width: number;
74
- height: number;
75
- };
76
- };
77
- //#endregion
78
- //#region core/src/controller.d.ts
79
- interface DomController {
80
- focus(paneId: PaneId): boolean;
81
- }
82
- type Listener = (next: FocusGridControllerState, previous: FocusGridControllerState) => void;
83
- type PaneLayoutChangeEvent = {
84
- pane: ComputedPane;
85
- previousPane: ComputedPane;
86
- controller: FocusGridController;
87
- };
88
- type PaneCloseEvent = {
89
- paneId: PaneId;
90
- previousPane: ComputedPane;
91
- controller: FocusGridController;
92
- };
93
- type PaneEventHandlers = {
94
- onPaneLayoutChange?: (event: PaneLayoutChangeEvent) => void;
95
- onPaneClose?: (event: PaneCloseEvent) => void;
96
- };
97
- type PaneDefaults = PaneCommandCapabilityInput;
98
- type FocusGridControllerProps = FocusGridControllerState & {
99
- paneDefaults?: PaneDefaults;
100
- minWidth?: number;
101
- minHeight?: number;
102
- directionalFocusOverflow?: boolean;
103
- };
104
- type SplitPaneOptions = Partial<Omit<PaneNode, "kind" | "id" | "paneId">> & {
105
- side: CardinalDirection;
106
- newPaneId?: PaneId;
107
- newPaneNodeId?: NodeId;
108
- splitId?: NodeId;
109
- preserveActivePane?: boolean;
110
- };
111
- type ResizePaneOptions = {
112
- direction: CardinalDirection;
113
- deltaPx: number;
114
- };
115
- type ResizeHandleOptions = {
116
- index: number;
117
- deltaPx: number;
118
- snapshotSizes?: number[];
119
- };
120
- declare class FocusGridController {
121
- private readonly domController;
122
- readonly minWidth: number;
123
- readonly minHeight: number;
124
- readonly directionalFocusOverflow: boolean;
125
- private currentState;
126
- private cachedLayout;
127
- private readonly paneDefaults;
128
- private readonly listeners;
129
- constructor({
130
- paneDefaults,
131
- minWidth,
132
- minHeight,
133
- directionalFocusOverflow,
134
- ...state
135
- }: FocusGridControllerProps, domController: DomController);
136
- /** Computed render data; stable until the next committed change. */
137
- getLayout(): ComputedLayout;
138
- getPane(paneId: PaneId): PaneNode | null;
139
- getContainerSize(): {
140
- width: number;
141
- height: number;
142
- };
143
- getSplitSizes(splitId: NodeId): number[] | null;
144
- splitActive(side: CardinalDirection): PaneId | null;
145
- removeActive(): boolean;
146
- focusAdjacent(direction: CardinalDirection): boolean;
147
- swapAdjacent(direction: CardinalDirection): boolean;
148
- resizeActive(direction: CardinalDirection, deltaPx: number): boolean;
149
- split(paneNodeId: NodeId, props: SplitPaneOptions): PaneId | null;
150
- remove(paneId: PaneId): boolean;
151
- swap(firstPaneId: PaneId, secondPaneId: PaneId): boolean;
152
- resize(paneId: PaneId, props: ResizePaneOptions): boolean;
153
- resizeHandle(splitId: NodeId, props: ResizeHandleOptions): boolean;
154
- focus(paneId: PaneId): boolean;
155
- updatePane(paneId: PaneId, patch: Partial<Omit<PaneNode, "kind" | "id" | "paneId">>): boolean;
156
- setContainerSize(width: number, height: number): boolean;
157
- private commit;
158
- subscribePaneEvents({
159
- onPaneLayoutChange,
160
- onPaneClose
161
- }: PaneEventHandlers): () => void;
162
- subscribe(listener: Listener): () => void;
163
- }
164
- //#endregion
165
- //#region dom/src/controller.d.ts
166
- /** Attach the renderer root; pane elements are resolved only when focus is requested. */
167
- declare class FocusGridDomController implements DomController {
168
- private root;
169
- setRoot(root: HTMLElement | null): void;
170
- focus(paneId: PaneId): boolean;
171
- }
172
- //#endregion
173
6
  //#region react/src/FocusgridController.d.ts
174
7
  declare const FocusgridController: import("react").Context<{
175
8
  controller: FocusGridController;
@@ -1,175 +1,8 @@
1
1
  import { ReactNode } from "react";
2
+ import { FocusGridDomController } from "@andrewcyuan/focusgrid/dom";
2
3
  import { ShortcutBinding } from "@andrewcyuan/shortcut-engine";
4
+ import { ComputedLayout, DomController, FocusGridController, FocusGridControllerProps, PaneEventHandlers, PaneId, Rect } from "@andrewcyuan/focusgrid/core";
3
5
 
4
- //#region core/src/layout/types.d.ts
5
- type PaneId = string;
6
- type NodeId = string;
7
- type Orientation = "horizontal" | "vertical";
8
- declare const cardinalDirections: readonly ["left", "right", "up", "down"];
9
- type CardinalDirection = (typeof cardinalDirections)[number];
10
- declare enum PaneCommandCapability {
11
- ResizeX = "canResizeX",
12
- ResizeY = "canResizeY",
13
- Remove = "canRemove",
14
- SplitHorizontal = "canSplitHorizontal",
15
- SplitVertical = "canSplitVertical",
16
- SwapX = "canSwapX",
17
- SwapY = "canSwapY",
18
- Focus = "canFocus"
19
- }
20
- type PaneCommandCapabilityInput = Partial<Record<PaneCommandCapability, boolean>>;
21
- type PaneNode = {
22
- kind: "pane";
23
- id: NodeId;
24
- paneId: PaneId;
25
- } & PaneCommandCapabilityInput;
26
- type SplitNode = {
27
- kind: "split";
28
- id: NodeId;
29
- orientation: Orientation;
30
- children: LayoutNode[];
31
- sizes: number[];
32
- lastFocusedChildId?: NodeId;
33
- };
34
- type LayoutNode = PaneNode | SplitNode;
35
- type Rect = {
36
- x: number;
37
- y: number;
38
- width: number;
39
- height: number;
40
- };
41
- type ComputedPane = {
42
- paneId: PaneId;
43
- nodeId: NodeId;
44
- rect: Rect;
45
- active: boolean;
46
- };
47
- type ComputedHandle = {
48
- id: string;
49
- splitId: NodeId;
50
- index: number;
51
- rect: Rect;
52
- direction: Orientation;
53
- };
54
- type ComputedNode = {
55
- kind: "pane";
56
- pane: ComputedPane;
57
- } | {
58
- kind: "split";
59
- orientation: Orientation;
60
- children: ComputedNode[];
61
- handles: ComputedHandle[];
62
- };
63
- type ComputedLayout = {
64
- root: ComputedNode;
65
- rectByNodeId: Map<NodeId, Rect>;
66
- panes: ComputedPane[];
67
- handles: ComputedHandle[];
68
- };
69
- type FocusGridControllerState = {
70
- root: LayoutNode;
71
- activePaneId: PaneId | null;
72
- container: {
73
- width: number;
74
- height: number;
75
- };
76
- };
77
- //#endregion
78
- //#region core/src/controller.d.ts
79
- interface DomController {
80
- focus(paneId: PaneId): boolean;
81
- }
82
- type Listener = (next: FocusGridControllerState, previous: FocusGridControllerState) => void;
83
- type PaneLayoutChangeEvent = {
84
- pane: ComputedPane;
85
- previousPane: ComputedPane;
86
- controller: FocusGridController;
87
- };
88
- type PaneCloseEvent = {
89
- paneId: PaneId;
90
- previousPane: ComputedPane;
91
- controller: FocusGridController;
92
- };
93
- type PaneEventHandlers = {
94
- onPaneLayoutChange?: (event: PaneLayoutChangeEvent) => void;
95
- onPaneClose?: (event: PaneCloseEvent) => void;
96
- };
97
- type PaneDefaults = PaneCommandCapabilityInput;
98
- type FocusGridControllerProps = FocusGridControllerState & {
99
- paneDefaults?: PaneDefaults;
100
- minWidth?: number;
101
- minHeight?: number;
102
- directionalFocusOverflow?: boolean;
103
- };
104
- type SplitPaneOptions = Partial<Omit<PaneNode, "kind" | "id" | "paneId">> & {
105
- side: CardinalDirection;
106
- newPaneId?: PaneId;
107
- newPaneNodeId?: NodeId;
108
- splitId?: NodeId;
109
- preserveActivePane?: boolean;
110
- };
111
- type ResizePaneOptions = {
112
- direction: CardinalDirection;
113
- deltaPx: number;
114
- };
115
- type ResizeHandleOptions = {
116
- index: number;
117
- deltaPx: number;
118
- snapshotSizes?: number[];
119
- };
120
- declare class FocusGridController {
121
- private readonly domController;
122
- readonly minWidth: number;
123
- readonly minHeight: number;
124
- readonly directionalFocusOverflow: boolean;
125
- private currentState;
126
- private cachedLayout;
127
- private readonly paneDefaults;
128
- private readonly listeners;
129
- constructor({
130
- paneDefaults,
131
- minWidth,
132
- minHeight,
133
- directionalFocusOverflow,
134
- ...state
135
- }: FocusGridControllerProps, domController: DomController);
136
- /** Computed render data; stable until the next committed change. */
137
- getLayout(): ComputedLayout;
138
- getPane(paneId: PaneId): PaneNode | null;
139
- getContainerSize(): {
140
- width: number;
141
- height: number;
142
- };
143
- getSplitSizes(splitId: NodeId): number[] | null;
144
- splitActive(side: CardinalDirection): PaneId | null;
145
- removeActive(): boolean;
146
- focusAdjacent(direction: CardinalDirection): boolean;
147
- swapAdjacent(direction: CardinalDirection): boolean;
148
- resizeActive(direction: CardinalDirection, deltaPx: number): boolean;
149
- split(paneNodeId: NodeId, props: SplitPaneOptions): PaneId | null;
150
- remove(paneId: PaneId): boolean;
151
- swap(firstPaneId: PaneId, secondPaneId: PaneId): boolean;
152
- resize(paneId: PaneId, props: ResizePaneOptions): boolean;
153
- resizeHandle(splitId: NodeId, props: ResizeHandleOptions): boolean;
154
- focus(paneId: PaneId): boolean;
155
- updatePane(paneId: PaneId, patch: Partial<Omit<PaneNode, "kind" | "id" | "paneId">>): boolean;
156
- setContainerSize(width: number, height: number): boolean;
157
- private commit;
158
- subscribePaneEvents({
159
- onPaneLayoutChange,
160
- onPaneClose
161
- }: PaneEventHandlers): () => void;
162
- subscribe(listener: Listener): () => void;
163
- }
164
- //#endregion
165
- //#region dom/src/controller.d.ts
166
- /** Attach the renderer root; pane elements are resolved only when focus is requested. */
167
- declare class FocusGridDomController implements DomController {
168
- private root;
169
- setRoot(root: HTMLElement | null): void;
170
- focus(paneId: PaneId): boolean;
171
- }
172
- //#endregion
173
6
  //#region react/src/FocusgridController.d.ts
174
7
  declare const FocusgridController: import("react").Context<{
175
8
  controller: FocusGridController;