@zag-js/splitter 1.40.0 → 1.41.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/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/splitter.connect.js +61 -29
- package/dist/splitter.connect.mjs +61 -29
- package/dist/splitter.dom.d.mts +4 -3
- package/dist/splitter.dom.d.ts +4 -3
- package/dist/splitter.dom.js +31 -2
- package/dist/splitter.dom.mjs +31 -3
- package/dist/splitter.machine.js +168 -59
- package/dist/splitter.machine.mjs +169 -61
- package/dist/splitter.types.d.mts +27 -8
- package/dist/splitter.types.d.ts +27 -8
- package/dist/utils/aria.d.mts +9 -3
- package/dist/utils/aria.d.ts +9 -3
- package/dist/utils/aria.js +9 -0
- package/dist/utils/aria.mjs +9 -0
- package/dist/utils/panel.d.mts +13 -12
- package/dist/utils/panel.d.ts +13 -12
- package/dist/utils/panel.js +41 -7
- package/dist/utils/panel.mjs +41 -7
- package/dist/utils/preserve-fixed-panel-sizes.d.mts +18 -0
- package/dist/utils/preserve-fixed-panel-sizes.d.ts +18 -0
- package/dist/utils/preserve-fixed-panel-sizes.js +91 -0
- package/dist/utils/preserve-fixed-panel-sizes.mjs +68 -0
- package/dist/utils/registry.js +1 -1
- package/dist/utils/registry.mjs +2 -2
- package/dist/utils/resize-by-delta.d.mts +2 -2
- package/dist/utils/resize-by-delta.d.ts +2 -2
- package/dist/utils/resize-panel.d.mts +2 -2
- package/dist/utils/resize-panel.d.ts +2 -2
- package/dist/utils/size.d.mts +17 -0
- package/dist/utils/size.d.ts +17 -0
- package/dist/utils/size.js +138 -0
- package/dist/utils/size.mjs +111 -0
- package/dist/utils/validate-sizes.d.mts +2 -2
- package/dist/utils/validate-sizes.d.ts +2 -2
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ export { anatomy } from './splitter.anatomy.mjs';
|
|
|
2
2
|
export { connect } from './splitter.connect.mjs';
|
|
3
3
|
export { machine } from './splitter.machine.mjs';
|
|
4
4
|
export { panelProps, props, resizeTriggerProps, splitPanelProps, splitProps, splitResizeTriggerProps } from './splitter.props.mjs';
|
|
5
|
-
export { SplitterApi as Api, CursorState, DragState, ElementIds, ExpandCollapseDetails, SplitterItem as Item, KeyboardState, SplitterMachine as Machine, PanelData, PanelId, PanelItem, PanelProps, SplitterProps as Props, ResizeDetails, ResizeEndDetails, ResizeEvent, ResizeTriggerId, ResizeTriggerItem, ResizeTriggerProps, ResizeTriggerState, SplitterService as Service } from './splitter.types.mjs';
|
|
5
|
+
export { SplitterApi as Api, CursorState, DragState, ElementIds, ExpandCollapseDetails, SplitterItem as Item, KeyboardState, SplitterMachine as Machine, PanelData, PanelId, PanelItem, PanelProps, PanelResizeBehavior, PanelSize, SplitterProps as Props, ResizeDetails, ResizeEndDetails, ResizeEvent, ResizeTriggerId, ResizeTriggerItem, ResizeTriggerProps, ResizeTriggerState, SplitterService as Service } from './splitter.types.mjs';
|
|
6
6
|
export { getPanelLayout as layout } from './utils/panel.mjs';
|
|
7
7
|
export { HitAreaMargins, SplitterRegistry, SplitterRegistryOptions, registry } from './utils/registry.mjs';
|
|
8
8
|
import '@zag-js/anatomy';
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { anatomy } from './splitter.anatomy.js';
|
|
|
2
2
|
export { connect } from './splitter.connect.js';
|
|
3
3
|
export { machine } from './splitter.machine.js';
|
|
4
4
|
export { panelProps, props, resizeTriggerProps, splitPanelProps, splitProps, splitResizeTriggerProps } from './splitter.props.js';
|
|
5
|
-
export { SplitterApi as Api, CursorState, DragState, ElementIds, ExpandCollapseDetails, SplitterItem as Item, KeyboardState, SplitterMachine as Machine, PanelData, PanelId, PanelItem, PanelProps, SplitterProps as Props, ResizeDetails, ResizeEndDetails, ResizeEvent, ResizeTriggerId, ResizeTriggerItem, ResizeTriggerProps, ResizeTriggerState, SplitterService as Service } from './splitter.types.js';
|
|
5
|
+
export { SplitterApi as Api, CursorState, DragState, ElementIds, ExpandCollapseDetails, SplitterItem as Item, KeyboardState, SplitterMachine as Machine, PanelData, PanelId, PanelItem, PanelProps, PanelResizeBehavior, PanelSize, SplitterProps as Props, ResizeDetails, ResizeEndDetails, ResizeEvent, ResizeTriggerId, ResizeTriggerItem, ResizeTriggerProps, ResizeTriggerState, SplitterService as Service } from './splitter.types.js';
|
|
6
6
|
export { getPanelLayout as layout } from './utils/panel.js';
|
|
7
7
|
export { HitAreaMargins, SplitterRegistry, SplitterRegistryOptions, registry } from './utils/registry.js';
|
|
8
8
|
import '@zag-js/anatomy';
|
package/dist/splitter.connect.js
CHANGED
|
@@ -40,29 +40,59 @@ var dom = __toESM(require("./splitter.dom.js"));
|
|
|
40
40
|
var import_aria = require("./utils/aria.js");
|
|
41
41
|
var import_fuzzy = require("./utils/fuzzy.js");
|
|
42
42
|
var import_panel = require("./utils/panel.js");
|
|
43
|
+
var import_size = require("./utils/size.js");
|
|
43
44
|
function connect(service, normalize) {
|
|
44
45
|
const { state, send, prop, computed, context, scope } = service;
|
|
45
46
|
const horizontal = computed("horizontal");
|
|
46
47
|
const dragging = state.matches("dragging");
|
|
47
48
|
const registry = prop("registry");
|
|
48
49
|
const orientation = prop("orientation");
|
|
50
|
+
const rawPanels = prop("panels");
|
|
51
|
+
const panels = context.get("panels");
|
|
52
|
+
const getResolvedSizes = () => {
|
|
53
|
+
const sizes = context.get("size");
|
|
54
|
+
if (sizes.length > 0) return sizes;
|
|
55
|
+
return (0, import_size.resolvePanelSizes)({
|
|
56
|
+
sizes: prop("size") ?? prop("defaultSize"),
|
|
57
|
+
panels: rawPanels,
|
|
58
|
+
rootEl: null,
|
|
59
|
+
orientation
|
|
60
|
+
});
|
|
61
|
+
};
|
|
49
62
|
const getPanelStyle = (id) => {
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
const defaultSize =
|
|
63
|
+
const panelIndex = rawPanels.findIndex((panel) => panel.id === id);
|
|
64
|
+
const size = prop("size")?.[panelIndex];
|
|
65
|
+
const defaultSize = prop("defaultSize")?.[panelIndex];
|
|
53
66
|
const dragState = context.get("dragState");
|
|
54
67
|
return (0, import_panel.getPanelFlexBoxStyle)({
|
|
68
|
+
size,
|
|
55
69
|
defaultSize,
|
|
56
70
|
dragState,
|
|
57
|
-
|
|
58
|
-
panels,
|
|
59
|
-
panelIndex
|
|
71
|
+
resolvedSizes: context.get("size"),
|
|
72
|
+
panels: rawPanels,
|
|
73
|
+
panelIndex,
|
|
74
|
+
horizontal
|
|
60
75
|
});
|
|
61
76
|
};
|
|
77
|
+
const resolveResizeTriggerId = (id) => {
|
|
78
|
+
const [beforeId, afterId] = id.split(":");
|
|
79
|
+
if (beforeId && afterId) return id;
|
|
80
|
+
if (beforeId) {
|
|
81
|
+
const index = rawPanels.findIndex((panel) => panel.id === beforeId);
|
|
82
|
+
const nextPanel = rawPanels[index + 1];
|
|
83
|
+
return nextPanel ? `${beforeId}:${nextPanel.id}` : id;
|
|
84
|
+
}
|
|
85
|
+
if (afterId) {
|
|
86
|
+
const index = rawPanels.findIndex((panel) => panel.id === afterId);
|
|
87
|
+
const prevPanel = rawPanels[index - 1];
|
|
88
|
+
return prevPanel ? `${prevPanel.id}:${afterId}` : id;
|
|
89
|
+
}
|
|
90
|
+
return id;
|
|
91
|
+
};
|
|
62
92
|
const getResizeTriggerState = (props) => {
|
|
63
93
|
const { id, disabled } = props;
|
|
64
94
|
const dragging2 = context.get("dragState")?.resizeTriggerId === id;
|
|
65
|
-
const focused = dragging2 || context.get("keyboardState")?.resizeTriggerId === id;
|
|
95
|
+
const focused = dragging2 || state.matches("focused") && context.get("keyboardState")?.resizeTriggerId === id;
|
|
66
96
|
return {
|
|
67
97
|
dragging: dragging2,
|
|
68
98
|
focused,
|
|
@@ -73,13 +103,13 @@ function connect(service, normalize) {
|
|
|
73
103
|
dragging,
|
|
74
104
|
orientation,
|
|
75
105
|
getPanels() {
|
|
76
|
-
return
|
|
106
|
+
return rawPanels;
|
|
77
107
|
},
|
|
78
108
|
getPanelById(id) {
|
|
79
|
-
return (0, import_panel.getPanelById)(
|
|
109
|
+
return (0, import_panel.getPanelById)(rawPanels, id);
|
|
80
110
|
},
|
|
81
111
|
getItems() {
|
|
82
|
-
return
|
|
112
|
+
return rawPanels.flatMap((panel, index, arr) => {
|
|
83
113
|
const nextPanel = arr[index + 1];
|
|
84
114
|
if (panel && nextPanel) {
|
|
85
115
|
return [
|
|
@@ -91,13 +121,13 @@ function connect(service, normalize) {
|
|
|
91
121
|
});
|
|
92
122
|
},
|
|
93
123
|
getSizes() {
|
|
94
|
-
return
|
|
124
|
+
return getResolvedSizes();
|
|
95
125
|
},
|
|
96
126
|
setSizes(size) {
|
|
97
127
|
send({ type: "SIZE.SET", size });
|
|
98
128
|
},
|
|
99
129
|
resetSizes() {
|
|
100
|
-
send({ type: "SIZE.
|
|
130
|
+
send({ type: "SIZE.RESET" });
|
|
101
131
|
},
|
|
102
132
|
collapsePanel(id) {
|
|
103
133
|
send({ type: "PANEL.COLLAPSE", id });
|
|
@@ -109,27 +139,27 @@ function connect(service, normalize) {
|
|
|
109
139
|
send({ type: "PANEL.RESIZE", id, size: unsafePanelSize });
|
|
110
140
|
},
|
|
111
141
|
getPanelSize(id) {
|
|
112
|
-
const
|
|
113
|
-
const size =
|
|
114
|
-
const panelData = (0, import_panel.getPanelById)(
|
|
115
|
-
const { panelSize } = (0, import_panel.panelDataHelper)(
|
|
116
|
-
(0, import_utils.ensure)(panelSize, () => `Panel size not found for panel "${panelData.id}"`);
|
|
142
|
+
const panels2 = context.get("panels");
|
|
143
|
+
const size = getResolvedSizes();
|
|
144
|
+
const panelData = (0, import_panel.getPanelById)(panels2, id);
|
|
145
|
+
const { panelSize } = (0, import_panel.panelDataHelper)(panels2, panelData, size);
|
|
146
|
+
(0, import_utils.ensure)(panelSize != null, () => `Panel size not found for panel "${panelData.id}"`);
|
|
117
147
|
return panelSize;
|
|
118
148
|
},
|
|
119
149
|
isPanelCollapsed(id) {
|
|
120
|
-
const
|
|
121
|
-
const size =
|
|
122
|
-
const panelData = (0, import_panel.getPanelById)(
|
|
123
|
-
const { collapsedSize = 0, collapsible, panelSize } = (0, import_panel.panelDataHelper)(
|
|
124
|
-
(0, import_utils.ensure)(panelSize, () => `Panel size not found for panel "${panelData.id}"`);
|
|
150
|
+
const panels2 = context.get("panels");
|
|
151
|
+
const size = getResolvedSizes();
|
|
152
|
+
const panelData = (0, import_panel.getPanelById)(panels2, id);
|
|
153
|
+
const { collapsedSize = 0, collapsible, panelSize } = (0, import_panel.panelDataHelper)(panels2, panelData, size);
|
|
154
|
+
(0, import_utils.ensure)(panelSize != null, () => `Panel size not found for panel "${panelData.id}"`);
|
|
125
155
|
return collapsible === true && (0, import_fuzzy.fuzzyNumbersEqual)(panelSize, collapsedSize);
|
|
126
156
|
},
|
|
127
157
|
isPanelExpanded(id) {
|
|
128
|
-
const
|
|
129
|
-
const size =
|
|
130
|
-
const panelData = (0, import_panel.getPanelById)(
|
|
131
|
-
const { collapsedSize = 0, collapsible, panelSize } = (0, import_panel.panelDataHelper)(
|
|
132
|
-
(0, import_utils.ensure)(panelSize, () => `Panel size not found for panel "${panelData.id}"`);
|
|
158
|
+
const panels2 = context.get("panels");
|
|
159
|
+
const size = getResolvedSizes();
|
|
160
|
+
const panelData = (0, import_panel.getPanelById)(panels2, id);
|
|
161
|
+
const { collapsedSize = 0, collapsible, panelSize } = (0, import_panel.panelDataHelper)(panels2, panelData, size);
|
|
162
|
+
(0, import_utils.ensure)(panelSize != null, () => `Panel size not found for panel "${panelData.id}"`);
|
|
133
163
|
return !collapsible || (0, import_fuzzy.fuzzyCompareNumbers)(panelSize, collapsedSize) > 0;
|
|
134
164
|
},
|
|
135
165
|
getLayout() {
|
|
@@ -180,7 +210,8 @@ function connect(service, normalize) {
|
|
|
180
210
|
getResizeTriggerProps(props) {
|
|
181
211
|
const { id } = props;
|
|
182
212
|
const triggerState = getResizeTriggerState(props);
|
|
183
|
-
const
|
|
213
|
+
const resolvedId = resolveResizeTriggerId(id);
|
|
214
|
+
const aria = (0, import_aria.getAriaValue)(getResolvedSizes(), panels, resolvedId);
|
|
184
215
|
return normalize.element({
|
|
185
216
|
...import_splitter.parts.resizeTrigger.attrs,
|
|
186
217
|
dir: prop("dir"),
|
|
@@ -194,7 +225,7 @@ function connect(service, normalize) {
|
|
|
194
225
|
"aria-valuemax": aria.valueMax,
|
|
195
226
|
"data-orientation": orientation,
|
|
196
227
|
"aria-orientation": orientation,
|
|
197
|
-
"aria-controls": `${dom.getPanelId(scope, aria.beforeId)} ${dom.getPanelId(scope, aria.afterId)}
|
|
228
|
+
"aria-controls": aria.beforeId && aria.afterId ? `${dom.getPanelId(scope, aria.beforeId)} ${dom.getPanelId(scope, aria.afterId)}` : void 0,
|
|
198
229
|
"data-focus": (0, import_dom_query.dataAttr)(triggerState.focused),
|
|
199
230
|
"data-dragging": (0, import_dom_query.dataAttr)(triggerState.dragging),
|
|
200
231
|
"data-disabled": (0, import_dom_query.dataAttr)(triggerState.disabled),
|
|
@@ -213,6 +244,7 @@ function connect(service, normalize) {
|
|
|
213
244
|
event.preventDefault();
|
|
214
245
|
return;
|
|
215
246
|
}
|
|
247
|
+
event.currentTarget.focus({ preventScroll: true });
|
|
216
248
|
if (registry) {
|
|
217
249
|
return;
|
|
218
250
|
}
|
|
@@ -8,29 +8,59 @@ import * as dom from "./splitter.dom.mjs";
|
|
|
8
8
|
import { getAriaValue } from "./utils/aria.mjs";
|
|
9
9
|
import { fuzzyCompareNumbers, fuzzyNumbersEqual } from "./utils/fuzzy.mjs";
|
|
10
10
|
import { findPanelIndex, getPanelById, getPanelFlexBoxStyle, getPanelLayout, panelDataHelper } from "./utils/panel.mjs";
|
|
11
|
+
import { resolvePanelSizes } from "./utils/size.mjs";
|
|
11
12
|
function connect(service, normalize) {
|
|
12
13
|
const { state, send, prop, computed, context, scope } = service;
|
|
13
14
|
const horizontal = computed("horizontal");
|
|
14
15
|
const dragging = state.matches("dragging");
|
|
15
16
|
const registry = prop("registry");
|
|
16
17
|
const orientation = prop("orientation");
|
|
18
|
+
const rawPanels = prop("panels");
|
|
19
|
+
const panels = context.get("panels");
|
|
20
|
+
const getResolvedSizes = () => {
|
|
21
|
+
const sizes = context.get("size");
|
|
22
|
+
if (sizes.length > 0) return sizes;
|
|
23
|
+
return resolvePanelSizes({
|
|
24
|
+
sizes: prop("size") ?? prop("defaultSize"),
|
|
25
|
+
panels: rawPanels,
|
|
26
|
+
rootEl: null,
|
|
27
|
+
orientation
|
|
28
|
+
});
|
|
29
|
+
};
|
|
17
30
|
const getPanelStyle = (id) => {
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const defaultSize =
|
|
31
|
+
const panelIndex = rawPanels.findIndex((panel) => panel.id === id);
|
|
32
|
+
const size = prop("size")?.[panelIndex];
|
|
33
|
+
const defaultSize = prop("defaultSize")?.[panelIndex];
|
|
21
34
|
const dragState = context.get("dragState");
|
|
22
35
|
return getPanelFlexBoxStyle({
|
|
36
|
+
size,
|
|
23
37
|
defaultSize,
|
|
24
38
|
dragState,
|
|
25
|
-
|
|
26
|
-
panels,
|
|
27
|
-
panelIndex
|
|
39
|
+
resolvedSizes: context.get("size"),
|
|
40
|
+
panels: rawPanels,
|
|
41
|
+
panelIndex,
|
|
42
|
+
horizontal
|
|
28
43
|
});
|
|
29
44
|
};
|
|
45
|
+
const resolveResizeTriggerId = (id) => {
|
|
46
|
+
const [beforeId, afterId] = id.split(":");
|
|
47
|
+
if (beforeId && afterId) return id;
|
|
48
|
+
if (beforeId) {
|
|
49
|
+
const index = rawPanels.findIndex((panel) => panel.id === beforeId);
|
|
50
|
+
const nextPanel = rawPanels[index + 1];
|
|
51
|
+
return nextPanel ? `${beforeId}:${nextPanel.id}` : id;
|
|
52
|
+
}
|
|
53
|
+
if (afterId) {
|
|
54
|
+
const index = rawPanels.findIndex((panel) => panel.id === afterId);
|
|
55
|
+
const prevPanel = rawPanels[index - 1];
|
|
56
|
+
return prevPanel ? `${prevPanel.id}:${afterId}` : id;
|
|
57
|
+
}
|
|
58
|
+
return id;
|
|
59
|
+
};
|
|
30
60
|
const getResizeTriggerState = (props) => {
|
|
31
61
|
const { id, disabled } = props;
|
|
32
62
|
const dragging2 = context.get("dragState")?.resizeTriggerId === id;
|
|
33
|
-
const focused = dragging2 || context.get("keyboardState")?.resizeTriggerId === id;
|
|
63
|
+
const focused = dragging2 || state.matches("focused") && context.get("keyboardState")?.resizeTriggerId === id;
|
|
34
64
|
return {
|
|
35
65
|
dragging: dragging2,
|
|
36
66
|
focused,
|
|
@@ -41,13 +71,13 @@ function connect(service, normalize) {
|
|
|
41
71
|
dragging,
|
|
42
72
|
orientation,
|
|
43
73
|
getPanels() {
|
|
44
|
-
return
|
|
74
|
+
return rawPanels;
|
|
45
75
|
},
|
|
46
76
|
getPanelById(id) {
|
|
47
|
-
return getPanelById(
|
|
77
|
+
return getPanelById(rawPanels, id);
|
|
48
78
|
},
|
|
49
79
|
getItems() {
|
|
50
|
-
return
|
|
80
|
+
return rawPanels.flatMap((panel, index, arr) => {
|
|
51
81
|
const nextPanel = arr[index + 1];
|
|
52
82
|
if (panel && nextPanel) {
|
|
53
83
|
return [
|
|
@@ -59,13 +89,13 @@ function connect(service, normalize) {
|
|
|
59
89
|
});
|
|
60
90
|
},
|
|
61
91
|
getSizes() {
|
|
62
|
-
return
|
|
92
|
+
return getResolvedSizes();
|
|
63
93
|
},
|
|
64
94
|
setSizes(size) {
|
|
65
95
|
send({ type: "SIZE.SET", size });
|
|
66
96
|
},
|
|
67
97
|
resetSizes() {
|
|
68
|
-
send({ type: "SIZE.
|
|
98
|
+
send({ type: "SIZE.RESET" });
|
|
69
99
|
},
|
|
70
100
|
collapsePanel(id) {
|
|
71
101
|
send({ type: "PANEL.COLLAPSE", id });
|
|
@@ -77,27 +107,27 @@ function connect(service, normalize) {
|
|
|
77
107
|
send({ type: "PANEL.RESIZE", id, size: unsafePanelSize });
|
|
78
108
|
},
|
|
79
109
|
getPanelSize(id) {
|
|
80
|
-
const
|
|
81
|
-
const size =
|
|
82
|
-
const panelData = getPanelById(
|
|
83
|
-
const { panelSize } = panelDataHelper(
|
|
84
|
-
ensure(panelSize, () => `Panel size not found for panel "${panelData.id}"`);
|
|
110
|
+
const panels2 = context.get("panels");
|
|
111
|
+
const size = getResolvedSizes();
|
|
112
|
+
const panelData = getPanelById(panels2, id);
|
|
113
|
+
const { panelSize } = panelDataHelper(panels2, panelData, size);
|
|
114
|
+
ensure(panelSize != null, () => `Panel size not found for panel "${panelData.id}"`);
|
|
85
115
|
return panelSize;
|
|
86
116
|
},
|
|
87
117
|
isPanelCollapsed(id) {
|
|
88
|
-
const
|
|
89
|
-
const size =
|
|
90
|
-
const panelData = getPanelById(
|
|
91
|
-
const { collapsedSize = 0, collapsible, panelSize } = panelDataHelper(
|
|
92
|
-
ensure(panelSize, () => `Panel size not found for panel "${panelData.id}"`);
|
|
118
|
+
const panels2 = context.get("panels");
|
|
119
|
+
const size = getResolvedSizes();
|
|
120
|
+
const panelData = getPanelById(panels2, id);
|
|
121
|
+
const { collapsedSize = 0, collapsible, panelSize } = panelDataHelper(panels2, panelData, size);
|
|
122
|
+
ensure(panelSize != null, () => `Panel size not found for panel "${panelData.id}"`);
|
|
93
123
|
return collapsible === true && fuzzyNumbersEqual(panelSize, collapsedSize);
|
|
94
124
|
},
|
|
95
125
|
isPanelExpanded(id) {
|
|
96
|
-
const
|
|
97
|
-
const size =
|
|
98
|
-
const panelData = getPanelById(
|
|
99
|
-
const { collapsedSize = 0, collapsible, panelSize } = panelDataHelper(
|
|
100
|
-
ensure(panelSize, () => `Panel size not found for panel "${panelData.id}"`);
|
|
126
|
+
const panels2 = context.get("panels");
|
|
127
|
+
const size = getResolvedSizes();
|
|
128
|
+
const panelData = getPanelById(panels2, id);
|
|
129
|
+
const { collapsedSize = 0, collapsible, panelSize } = panelDataHelper(panels2, panelData, size);
|
|
130
|
+
ensure(panelSize != null, () => `Panel size not found for panel "${panelData.id}"`);
|
|
101
131
|
return !collapsible || fuzzyCompareNumbers(panelSize, collapsedSize) > 0;
|
|
102
132
|
},
|
|
103
133
|
getLayout() {
|
|
@@ -148,7 +178,8 @@ function connect(service, normalize) {
|
|
|
148
178
|
getResizeTriggerProps(props) {
|
|
149
179
|
const { id } = props;
|
|
150
180
|
const triggerState = getResizeTriggerState(props);
|
|
151
|
-
const
|
|
181
|
+
const resolvedId = resolveResizeTriggerId(id);
|
|
182
|
+
const aria = getAriaValue(getResolvedSizes(), panels, resolvedId);
|
|
152
183
|
return normalize.element({
|
|
153
184
|
...parts.resizeTrigger.attrs,
|
|
154
185
|
dir: prop("dir"),
|
|
@@ -162,7 +193,7 @@ function connect(service, normalize) {
|
|
|
162
193
|
"aria-valuemax": aria.valueMax,
|
|
163
194
|
"data-orientation": orientation,
|
|
164
195
|
"aria-orientation": orientation,
|
|
165
|
-
"aria-controls": `${dom.getPanelId(scope, aria.beforeId)} ${dom.getPanelId(scope, aria.afterId)}
|
|
196
|
+
"aria-controls": aria.beforeId && aria.afterId ? `${dom.getPanelId(scope, aria.beforeId)} ${dom.getPanelId(scope, aria.afterId)}` : void 0,
|
|
166
197
|
"data-focus": dataAttr(triggerState.focused),
|
|
167
198
|
"data-dragging": dataAttr(triggerState.dragging),
|
|
168
199
|
"data-disabled": dataAttr(triggerState.disabled),
|
|
@@ -181,6 +212,7 @@ function connect(service, normalize) {
|
|
|
181
212
|
event.preventDefault();
|
|
182
213
|
return;
|
|
183
214
|
}
|
|
215
|
+
event.currentTarget.focus({ preventScroll: true });
|
|
184
216
|
if (registry) {
|
|
185
217
|
return;
|
|
186
218
|
}
|
package/dist/splitter.dom.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Scope } from '@zag-js/core';
|
|
2
|
-
import { CursorState } from './splitter.types.mjs';
|
|
2
|
+
import { CursorState, ResizeTriggerId } from './splitter.types.mjs';
|
|
3
3
|
import '@zag-js/types';
|
|
4
4
|
import './utils/registry.mjs';
|
|
5
5
|
|
|
@@ -10,12 +10,13 @@ declare const getPanelId: (ctx: Scope, id: string | number) => any;
|
|
|
10
10
|
declare const getPanelEls: (ctx: Scope) => HTMLElement[];
|
|
11
11
|
declare const getGlobalCursorId: (ctx: Scope) => string;
|
|
12
12
|
declare const getRootEl: (ctx: Scope) => HTMLElement | null;
|
|
13
|
-
declare const getResizeTriggerEl: (ctx: Scope, id: string) => HTMLElement | null;
|
|
13
|
+
declare const getResizeTriggerEl: (ctx: Scope, id: string | null | undefined) => HTMLElement | null;
|
|
14
14
|
declare const getPanelEl: (ctx: Scope, id: string | number) => HTMLElement | null;
|
|
15
|
+
declare const resolveResizeTriggerId: (ctx: Scope, id: ResizeTriggerId) => `${string}:${string}` | null;
|
|
15
16
|
declare const getCursor: (state: CursorState, x: boolean) => (string & {}) | "col-resize" | "e-resize" | "n-resize" | "row-resize" | "s-resize" | "w-resize";
|
|
16
17
|
declare const getResizeTriggerEls: (ctx: Scope) => HTMLElement[];
|
|
17
18
|
declare const getGlobalCursorEl: (ctx: Scope) => HTMLElement | null;
|
|
18
19
|
declare const setupGlobalCursor: (ctx: Scope, state: CursorState, x: boolean, nonce?: string) => void;
|
|
19
20
|
declare const removeGlobalCursor: (ctx: Scope) => void;
|
|
20
21
|
|
|
21
|
-
export { getCursor, getGlobalCursorEl, getGlobalCursorId, getLabelId, getPanelEl, getPanelEls, getPanelId, getResizeTriggerEl, getResizeTriggerEls, getResizeTriggerId, getRootEl, getRootId, removeGlobalCursor, setupGlobalCursor };
|
|
22
|
+
export { getCursor, getGlobalCursorEl, getGlobalCursorId, getLabelId, getPanelEl, getPanelEls, getPanelId, getResizeTriggerEl, getResizeTriggerEls, getResizeTriggerId, getRootEl, getRootId, removeGlobalCursor, resolveResizeTriggerId, setupGlobalCursor };
|
package/dist/splitter.dom.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Scope } from '@zag-js/core';
|
|
2
|
-
import { CursorState } from './splitter.types.js';
|
|
2
|
+
import { CursorState, ResizeTriggerId } from './splitter.types.js';
|
|
3
3
|
import '@zag-js/types';
|
|
4
4
|
import './utils/registry.js';
|
|
5
5
|
|
|
@@ -10,12 +10,13 @@ declare const getPanelId: (ctx: Scope, id: string | number) => any;
|
|
|
10
10
|
declare const getPanelEls: (ctx: Scope) => HTMLElement[];
|
|
11
11
|
declare const getGlobalCursorId: (ctx: Scope) => string;
|
|
12
12
|
declare const getRootEl: (ctx: Scope) => HTMLElement | null;
|
|
13
|
-
declare const getResizeTriggerEl: (ctx: Scope, id: string) => HTMLElement | null;
|
|
13
|
+
declare const getResizeTriggerEl: (ctx: Scope, id: string | null | undefined) => HTMLElement | null;
|
|
14
14
|
declare const getPanelEl: (ctx: Scope, id: string | number) => HTMLElement | null;
|
|
15
|
+
declare const resolveResizeTriggerId: (ctx: Scope, id: ResizeTriggerId) => `${string}:${string}` | null;
|
|
15
16
|
declare const getCursor: (state: CursorState, x: boolean) => (string & {}) | "col-resize" | "e-resize" | "n-resize" | "row-resize" | "s-resize" | "w-resize";
|
|
16
17
|
declare const getResizeTriggerEls: (ctx: Scope) => HTMLElement[];
|
|
17
18
|
declare const getGlobalCursorEl: (ctx: Scope) => HTMLElement | null;
|
|
18
19
|
declare const setupGlobalCursor: (ctx: Scope, state: CursorState, x: boolean, nonce?: string) => void;
|
|
19
20
|
declare const removeGlobalCursor: (ctx: Scope) => void;
|
|
20
21
|
|
|
21
|
-
export { getCursor, getGlobalCursorEl, getGlobalCursorId, getLabelId, getPanelEl, getPanelEls, getPanelId, getResizeTriggerEl, getResizeTriggerEls, getResizeTriggerId, getRootEl, getRootId, removeGlobalCursor, setupGlobalCursor };
|
|
22
|
+
export { getCursor, getGlobalCursorEl, getGlobalCursorId, getLabelId, getPanelEl, getPanelEls, getPanelId, getResizeTriggerEl, getResizeTriggerEls, getResizeTriggerId, getRootEl, getRootId, removeGlobalCursor, resolveResizeTriggerId, setupGlobalCursor };
|
package/dist/splitter.dom.js
CHANGED
|
@@ -33,6 +33,7 @@ __export(splitter_dom_exports, {
|
|
|
33
33
|
getRootEl: () => getRootEl,
|
|
34
34
|
getRootId: () => getRootId,
|
|
35
35
|
removeGlobalCursor: () => removeGlobalCursor,
|
|
36
|
+
resolveResizeTriggerId: () => resolveResizeTriggerId,
|
|
36
37
|
setupGlobalCursor: () => setupGlobalCursor
|
|
37
38
|
});
|
|
38
39
|
module.exports = __toCommonJS(splitter_dom_exports);
|
|
@@ -41,11 +42,38 @@ var getRootId = (ctx) => ctx.ids?.root ?? `splitter:${ctx.id}`;
|
|
|
41
42
|
var getResizeTriggerId = (ctx, id) => ctx.ids?.resizeTrigger?.(id) ?? `splitter:${ctx.id}:splitter:${id}`;
|
|
42
43
|
var getLabelId = (ctx) => ctx.ids?.label ?? `splitter:${ctx.id}:label`;
|
|
43
44
|
var getPanelId = (ctx, id) => ctx.ids?.panel?.(id) ?? `splitter:${ctx.id}:panel:${id}`;
|
|
44
|
-
var getPanelEls = (ctx) => (0, import_dom_query.queryAll)(getRootEl(ctx), `[data-part=panel][data-ownedby
|
|
45
|
+
var getPanelEls = (ctx) => (0, import_dom_query.queryAll)(getRootEl(ctx), `[data-part=panel][data-ownedby='${CSS.escape(getRootId(ctx))}']`);
|
|
45
46
|
var getGlobalCursorId = (ctx) => `splitter:${ctx.id}:global-cursor`;
|
|
46
47
|
var getRootEl = (ctx) => ctx.getById(getRootId(ctx));
|
|
47
|
-
var getResizeTriggerEl = (ctx, id) => ctx.getById(getResizeTriggerId(ctx, id));
|
|
48
|
+
var getResizeTriggerEl = (ctx, id) => id != null ? ctx.getById(getResizeTriggerId(ctx, id)) : null;
|
|
48
49
|
var getPanelEl = (ctx, id) => ctx.getById(getPanelId(ctx, id));
|
|
50
|
+
var getPanelIdFromEl = (el) => {
|
|
51
|
+
return (0, import_dom_query.isHTMLElement)(el) && el.dataset.part === "panel" ? el.dataset.id : void 0;
|
|
52
|
+
};
|
|
53
|
+
var getPrevPanelId = (el) => {
|
|
54
|
+
let prev = el?.previousElementSibling ?? null;
|
|
55
|
+
while (prev) {
|
|
56
|
+
const id = getPanelIdFromEl(prev);
|
|
57
|
+
if (id) return id;
|
|
58
|
+
prev = prev.previousElementSibling;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var getNextPanelId = (el) => {
|
|
62
|
+
let next = el?.nextElementSibling ?? null;
|
|
63
|
+
while (next) {
|
|
64
|
+
const id = getPanelIdFromEl(next);
|
|
65
|
+
if (id) return id;
|
|
66
|
+
next = next.nextElementSibling;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
var resolveResizeTriggerId = (ctx, id) => {
|
|
70
|
+
const [beforeId, afterId] = id.split(":");
|
|
71
|
+
if (beforeId && afterId) return id;
|
|
72
|
+
const triggerEl = getResizeTriggerEl(ctx, id);
|
|
73
|
+
const resolvedBeforeId = beforeId || getPrevPanelId(triggerEl);
|
|
74
|
+
const resolvedAfterId = afterId || getNextPanelId(triggerEl);
|
|
75
|
+
return resolvedBeforeId && resolvedAfterId ? `${resolvedBeforeId}:${resolvedAfterId}` : null;
|
|
76
|
+
};
|
|
49
77
|
var getCursor = (state, x) => {
|
|
50
78
|
let cursor = x ? "col-resize" : "row-resize";
|
|
51
79
|
if (state.isAtMin) cursor = x ? "e-resize" : "s-resize";
|
|
@@ -90,5 +118,6 @@ var removeGlobalCursor = (ctx) => {
|
|
|
90
118
|
getRootEl,
|
|
91
119
|
getRootId,
|
|
92
120
|
removeGlobalCursor,
|
|
121
|
+
resolveResizeTriggerId,
|
|
93
122
|
setupGlobalCursor
|
|
94
123
|
});
|
package/dist/splitter.dom.mjs
CHANGED
|
@@ -1,16 +1,43 @@
|
|
|
1
1
|
import "./chunk-QZ7TP4HQ.mjs";
|
|
2
2
|
|
|
3
3
|
// src/splitter.dom.ts
|
|
4
|
-
import { queryAll } from "@zag-js/dom-query";
|
|
4
|
+
import { isHTMLElement, queryAll } from "@zag-js/dom-query";
|
|
5
5
|
var getRootId = (ctx) => ctx.ids?.root ?? `splitter:${ctx.id}`;
|
|
6
6
|
var getResizeTriggerId = (ctx, id) => ctx.ids?.resizeTrigger?.(id) ?? `splitter:${ctx.id}:splitter:${id}`;
|
|
7
7
|
var getLabelId = (ctx) => ctx.ids?.label ?? `splitter:${ctx.id}:label`;
|
|
8
8
|
var getPanelId = (ctx, id) => ctx.ids?.panel?.(id) ?? `splitter:${ctx.id}:panel:${id}`;
|
|
9
|
-
var getPanelEls = (ctx) => queryAll(getRootEl(ctx), `[data-part=panel][data-ownedby
|
|
9
|
+
var getPanelEls = (ctx) => queryAll(getRootEl(ctx), `[data-part=panel][data-ownedby='${CSS.escape(getRootId(ctx))}']`);
|
|
10
10
|
var getGlobalCursorId = (ctx) => `splitter:${ctx.id}:global-cursor`;
|
|
11
11
|
var getRootEl = (ctx) => ctx.getById(getRootId(ctx));
|
|
12
|
-
var getResizeTriggerEl = (ctx, id) => ctx.getById(getResizeTriggerId(ctx, id));
|
|
12
|
+
var getResizeTriggerEl = (ctx, id) => id != null ? ctx.getById(getResizeTriggerId(ctx, id)) : null;
|
|
13
13
|
var getPanelEl = (ctx, id) => ctx.getById(getPanelId(ctx, id));
|
|
14
|
+
var getPanelIdFromEl = (el) => {
|
|
15
|
+
return isHTMLElement(el) && el.dataset.part === "panel" ? el.dataset.id : void 0;
|
|
16
|
+
};
|
|
17
|
+
var getPrevPanelId = (el) => {
|
|
18
|
+
let prev = el?.previousElementSibling ?? null;
|
|
19
|
+
while (prev) {
|
|
20
|
+
const id = getPanelIdFromEl(prev);
|
|
21
|
+
if (id) return id;
|
|
22
|
+
prev = prev.previousElementSibling;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
var getNextPanelId = (el) => {
|
|
26
|
+
let next = el?.nextElementSibling ?? null;
|
|
27
|
+
while (next) {
|
|
28
|
+
const id = getPanelIdFromEl(next);
|
|
29
|
+
if (id) return id;
|
|
30
|
+
next = next.nextElementSibling;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var resolveResizeTriggerId = (ctx, id) => {
|
|
34
|
+
const [beforeId, afterId] = id.split(":");
|
|
35
|
+
if (beforeId && afterId) return id;
|
|
36
|
+
const triggerEl = getResizeTriggerEl(ctx, id);
|
|
37
|
+
const resolvedBeforeId = beforeId || getPrevPanelId(triggerEl);
|
|
38
|
+
const resolvedAfterId = afterId || getNextPanelId(triggerEl);
|
|
39
|
+
return resolvedBeforeId && resolvedAfterId ? `${resolvedBeforeId}:${resolvedAfterId}` : null;
|
|
40
|
+
};
|
|
14
41
|
var getCursor = (state, x) => {
|
|
15
42
|
let cursor = x ? "col-resize" : "row-resize";
|
|
16
43
|
if (state.isAtMin) cursor = x ? "e-resize" : "s-resize";
|
|
@@ -54,5 +81,6 @@ export {
|
|
|
54
81
|
getRootEl,
|
|
55
82
|
getRootId,
|
|
56
83
|
removeGlobalCursor,
|
|
84
|
+
resolveResizeTriggerId,
|
|
57
85
|
setupGlobalCursor
|
|
58
86
|
};
|