akar 1.18.0 → 1.20.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/autocomplete/autocomplete-input.js +122 -0
- package/dist/autocomplete/autocomplete-input.js.map +1 -0
- package/dist/autocomplete/autocomplete-root.js +253 -0
- package/dist/autocomplete/autocomplete-root.js.map +1 -0
- package/dist/checkbox/checkbox-group-root.js +1 -1
- package/dist/checkbox/checkbox-root.js +1 -1
- package/dist/combobox/combobox-content-impl.js +9 -2
- package/dist/combobox/combobox-content-impl.js.map +1 -1
- package/dist/combobox/combobox-content.js +4 -0
- package/dist/combobox/combobox-content.js.map +1 -1
- package/dist/combobox/combobox-root.js +1 -1
- package/dist/composables/use-window-splitter-panel-group-behavior.js +13 -9
- package/dist/composables/use-window-splitter-panel-group-behavior.js.map +1 -1
- package/dist/constant/components.js +18 -0
- package/dist/constant/components.js.map +1 -1
- package/dist/constant.d.ts +1 -0
- package/dist/constant.d.ts.map +1 -1
- package/dist/date/use-date-field.js +1 -1
- package/dist/date/use-date-field.js.map +1 -1
- package/dist/date-field/date-field-root.js +1 -1
- package/dist/date-range-field/date-range-field-root.js +1 -1
- package/dist/dialog/dialog-content-impl.js +1 -1
- package/dist/hover-card/hover-card-content-impl.js +1 -1
- package/dist/index.d.ts +1752 -1622
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +50 -47
- package/dist/listbox/listbox-root.js +1 -1
- package/dist/listbox/listbox-virtualizer.js +1 -1
- package/dist/menu/menu-content-impl.js +1 -1
- package/dist/menu/menu-item-impl.js +1 -1
- package/dist/namespaced/index.cjs +19 -0
- package/dist/namespaced/index.d.cts +20 -2
- package/dist/namespaced/index.d.mts +20 -2
- package/dist/namespaced/index.mjs +20 -2
- package/dist/popover/popover-content-impl.js +1 -1
- package/dist/radio-group/radio-group-root.js +1 -1
- package/dist/range-calendar/range-calendar-cell-trigger.js +3 -1
- package/dist/range-calendar/range-calendar-cell-trigger.js.map +1 -1
- package/dist/range-calendar/range-calendar-grid.js +2 -1
- package/dist/range-calendar/range-calendar-grid.js.map +1 -1
- package/dist/range-calendar/range-calendar-root.js +17 -9
- package/dist/range-calendar/range-calendar-root.js.map +1 -1
- package/dist/range-calendar/use-range-calendar.js +16 -6
- package/dist/range-calendar/use-range-calendar.js.map +1 -1
- package/dist/select/select-content-impl.js +1 -1
- package/dist/select/select-root.js +1 -1
- package/dist/select/select-trigger.js +1 -1
- package/dist/shared/use-id.js +7 -4
- package/dist/shared/use-id.js.map +1 -1
- package/dist/splitter/splitter-group.js +143 -30
- package/dist/splitter/splitter-group.js.map +1 -1
- package/dist/splitter/splitter-panel.js +7 -2
- package/dist/splitter/splitter-panel.js.map +1 -1
- package/dist/time-field/time-field-root.js +1 -1
- package/dist/toast/toast-announce.js +4 -1
- package/dist/toast/toast-announce.js.map +1 -1
- package/dist/toggle-group/toggle-group-root.js +1 -1
- package/dist/tooltip/tooltip-content-impl.js +26 -19
- package/dist/tooltip/tooltip-content-impl.js.map +1 -1
- package/dist/tooltip/tooltip-content.js +1 -2
- package/dist/tooltip/tooltip-content.js.map +1 -1
- package/dist/tooltip/tooltip-provider.js +7 -2
- package/dist/tooltip/tooltip-provider.js.map +1 -1
- package/dist/utils/storage.js +7 -1
- package/dist/utils/storage.js.map +1 -1
- package/dist/utils/units.js +82 -0
- package/dist/utils/units.js.map +1 -0
- package/package.json +1 -1
- package/src/autocomplete/autocomplete-input.vue +124 -0
- package/src/autocomplete/autocomplete-root.vue +292 -0
- package/src/autocomplete/index.ts +74 -0
- package/src/combobox/combobox-content-impl.vue +13 -1
- package/src/index.ts +1 -0
- package/src/range-calendar/range-calendar-cell-trigger.vue +4 -2
- package/src/range-calendar/range-calendar-grid.vue +1 -0
- package/src/range-calendar/range-calendar-root.vue +27 -22
- package/src/range-calendar/use-range-calendar.ts +10 -12
- package/src/shared/date/use-date-field.ts +7 -3
- package/src/shared/use-id.ts +6 -8
- package/src/splitter/splitter-group.vue +249 -54
- package/src/splitter/splitter-panel.vue +12 -7
- package/src/splitter/utils/composables/use-window-splitter-panel-group-behavior.ts +18 -7
- package/src/splitter/utils/storage.ts +14 -0
- package/src/splitter/utils/units.ts +166 -0
- package/src/splitter/utils/validation.ts +3 -2
- package/src/toast/toast-announce.vue +4 -1
- package/src/tooltip/tooltip-content-impl.vue +18 -10
- package/src/tooltip/tooltip-content.vue +1 -3
- package/src/tooltip/tooltip-provider.vue +20 -3
|
@@ -12,13 +12,13 @@ import {
|
|
|
12
12
|
|
|
13
13
|
export interface ASplitterGroupProps extends APrimitiveProps {
|
|
14
14
|
/** Group id; falls back to `useId` when not provided. */
|
|
15
|
-
id?:
|
|
15
|
+
id?: string | null;
|
|
16
16
|
/** Unique id used to auto-save group arrangement via `localStorage`. */
|
|
17
|
-
autoSaveId?:
|
|
17
|
+
autoSaveId?: string | null;
|
|
18
18
|
/** The group orientation of splitter. */
|
|
19
19
|
direction: Direction;
|
|
20
20
|
/** Step size when arrow key was pressed. */
|
|
21
|
-
keyboardResizeBy?:
|
|
21
|
+
keyboardResizeBy?: number | null;
|
|
22
22
|
/** Custom storage API; defaults to localStorage */
|
|
23
23
|
storage?: PanelGroupStorage;
|
|
24
24
|
}
|
|
@@ -31,7 +31,7 @@ export type ASplitterGroupEmits = {
|
|
|
31
31
|
const LOCAL_STORAGE_DEBOUNCE_INTERVAL = 100;
|
|
32
32
|
|
|
33
33
|
export type PanelGroupStorage = {
|
|
34
|
-
getItem: (name: string) =>
|
|
34
|
+
getItem: (name: string) => string | null;
|
|
35
35
|
setItem: (name: string, value: string) => void;
|
|
36
36
|
};
|
|
37
37
|
|
|
@@ -57,7 +57,7 @@ export type PanelGroupContext = {
|
|
|
57
57
|
startDragging: (dragHandleId: string, event: ResizeEvent) => void;
|
|
58
58
|
stopDragging: () => void;
|
|
59
59
|
unregisterPanel: (panelData: PanelData) => void;
|
|
60
|
-
panelGroupElement: Ref<
|
|
60
|
+
panelGroupElement: Ref<ParentNode | null>;
|
|
61
61
|
|
|
62
62
|
// Exposed function for child component
|
|
63
63
|
collapsePanel: (panelData: PanelData) => void;
|
|
@@ -73,12 +73,12 @@ export const [injectPanelGroupContext, providePanelGroupContext] = createContext
|
|
|
73
73
|
|
|
74
74
|
<script setup lang="ts">
|
|
75
75
|
import type { PanelConstraints, PanelData } from './splitter-panel.vue';
|
|
76
|
-
|
|
77
76
|
import type { Direction, DragState, ResizeEvent, ResizeHandler } from './utils/types';
|
|
78
77
|
import { APrimitive } from '../primitive';
|
|
79
78
|
import { assert } from './utils/assert';
|
|
80
79
|
import { calculateDeltaPercentage, calculateUnsafeDefaultLayout } from './utils/calculate';
|
|
81
80
|
import { callPanelCallbacks } from './utils/call-panel-callbacks';
|
|
81
|
+
import { fuzzyCompareNumbers } from './utils/compare';
|
|
82
82
|
import debounce from './utils/debounce';
|
|
83
83
|
import { getResizeHandleElement } from './utils/dom';
|
|
84
84
|
import { getResizeEventCursorPosition, isKeyDown, isMouseEvent, isTouchEvent } from './utils/events';
|
|
@@ -92,6 +92,7 @@ import {
|
|
|
92
92
|
reportConstraintsViolation,
|
|
93
93
|
} from './utils/registry';
|
|
94
94
|
import { computePanelFlexBoxStyle } from './utils/style';
|
|
95
|
+
import { convertPanelConstraintsToPercent, hasPixelSizedPanel, recalculateLayoutForPixelPanels } from './utils/units';
|
|
95
96
|
import { validatePanelGroupLayout } from './utils/validation';
|
|
96
97
|
|
|
97
98
|
const props = withDefaults(defineProps<ASplitterGroupProps>(), {
|
|
@@ -113,11 +114,12 @@ const debounceMap: {
|
|
|
113
114
|
} = {};
|
|
114
115
|
|
|
115
116
|
const { direction } = toRefs(props);
|
|
116
|
-
const groupId = useId(props.id, '
|
|
117
|
+
const groupId = useId(props.id, 'reka-splitter-group');
|
|
117
118
|
const dir = useDirection();
|
|
118
119
|
const { forwardRef, currentElement: panelGroupElementRef } = useForwardExpose();
|
|
119
120
|
|
|
120
121
|
const dragState = ref<DragState | null>(null);
|
|
122
|
+
const groupSizeInPixels = ref<number | null>(null);
|
|
121
123
|
const layout = ref<Array<number>>([]);
|
|
122
124
|
const panelIdToLastNotifiedSizeMapRef = ref<Record<string, number>>({});
|
|
123
125
|
const panelSizeBeforeCollapseRef = ref<Map<string, number>>(new Map());
|
|
@@ -131,11 +133,11 @@ const committedValuesRef = computed(() => ({
|
|
|
131
133
|
keyboardResizeBy: props.keyboardResizeBy,
|
|
132
134
|
storage: props.storage,
|
|
133
135
|
}) satisfies {
|
|
134
|
-
autoSaveId:
|
|
136
|
+
autoSaveId: string | null;
|
|
135
137
|
direction: Direction;
|
|
136
138
|
dragState: DragState | null;
|
|
137
139
|
id: string;
|
|
138
|
-
keyboardResizeBy:
|
|
140
|
+
keyboardResizeBy: number | null;
|
|
139
141
|
storage: PanelGroupStorage;
|
|
140
142
|
});
|
|
141
143
|
|
|
@@ -149,6 +151,47 @@ const eagerValuesRef = ref<{
|
|
|
149
151
|
panelDataArrayChanged: false,
|
|
150
152
|
});
|
|
151
153
|
|
|
154
|
+
function getGroupSizeInPixels(): number | null {
|
|
155
|
+
if (groupSizeInPixels.value != null) {
|
|
156
|
+
return groupSizeInPixels.value;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const element = panelGroupElementRef.value;
|
|
160
|
+
if (element && element instanceof HTMLElement) {
|
|
161
|
+
const rect = element.getBoundingClientRect();
|
|
162
|
+
const size = direction.value === 'horizontal' ? rect.width : rect.height;
|
|
163
|
+
|
|
164
|
+
if (!Number.isNaN(size)) {
|
|
165
|
+
groupSizeInPixels.value = size;
|
|
166
|
+
return size;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function getPanelConstraintsInPercent(groupSizeOverride?: number | null) {
|
|
174
|
+
const groupSize = groupSizeOverride ?? getGroupSizeInPixels();
|
|
175
|
+
|
|
176
|
+
return convertPanelConstraintsToPercent({
|
|
177
|
+
panelDataArray: eagerValuesRef.value.panelDataArray,
|
|
178
|
+
groupSizeInPixels: groupSize,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function getPanelDataWithPercentConstraints(groupSizeOverride?: number | null) {
|
|
183
|
+
const percentConstraints = getPanelConstraintsInPercent(groupSizeOverride);
|
|
184
|
+
|
|
185
|
+
if (!percentConstraints) {
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return eagerValuesRef.value.panelDataArray.map((panelData, index) => ({
|
|
190
|
+
...panelData,
|
|
191
|
+
constraints: percentConstraints[index],
|
|
192
|
+
}));
|
|
193
|
+
}
|
|
194
|
+
|
|
152
195
|
function setLayout(val: Array<number>) {
|
|
153
196
|
layout.value = val;
|
|
154
197
|
}
|
|
@@ -160,6 +203,38 @@ useWindowSplitterPanelGroupBehavior({
|
|
|
160
203
|
panelDataArray: eagerValuesRef.value.panelDataArray,
|
|
161
204
|
setLayout,
|
|
162
205
|
panelGroupElement: panelGroupElementRef,
|
|
206
|
+
getPanelDataWithPercentConstraints,
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
watchEffect((onCleanup) => {
|
|
210
|
+
const element = panelGroupElementRef.value;
|
|
211
|
+
if (!element) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (typeof ResizeObserver !== 'function') {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const resizeObserver = new ResizeObserver((entries) => {
|
|
220
|
+
const entry = entries[0];
|
|
221
|
+
if (!entry) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const { height, width } = entry.contentRect;
|
|
226
|
+
const nextSize = direction.value === 'horizontal' ? width : height;
|
|
227
|
+
|
|
228
|
+
if (!Number.isNaN(nextSize)) {
|
|
229
|
+
groupSizeInPixels.value = nextSize;
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
if (element instanceof HTMLElement) {
|
|
234
|
+
resizeObserver.observe(element);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
onCleanup(() => resizeObserver.disconnect());
|
|
163
238
|
});
|
|
164
239
|
|
|
165
240
|
watchEffect(() => {
|
|
@@ -258,18 +333,26 @@ watch(() => eagerValuesRef.value.panelDataArrayChanged, () => {
|
|
|
258
333
|
}
|
|
259
334
|
|
|
260
335
|
if (unsafeLayout === null) {
|
|
336
|
+
const panelDataArrayWithPercentConstraints = getPanelDataWithPercentConstraints();
|
|
337
|
+
if (!panelDataArrayWithPercentConstraints) {
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
|
|
261
341
|
unsafeLayout = calculateUnsafeDefaultLayout({
|
|
262
|
-
panelDataArray,
|
|
342
|
+
panelDataArray: panelDataArrayWithPercentConstraints,
|
|
263
343
|
});
|
|
264
344
|
}
|
|
265
345
|
|
|
346
|
+
const panelConstraints = getPanelConstraintsInPercent();
|
|
347
|
+
if (!panelConstraints) {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
|
|
266
351
|
// Validate even saved layouts in case something has changed since last render
|
|
267
352
|
// e.g. for pixel groups, this could be the size of the window
|
|
268
353
|
const nextLayout = validatePanelGroupLayout({
|
|
269
354
|
layout: unsafeLayout,
|
|
270
|
-
panelConstraints
|
|
271
|
-
(panelData) => panelData.constraints,
|
|
272
|
-
),
|
|
355
|
+
panelConstraints,
|
|
273
356
|
});
|
|
274
357
|
|
|
275
358
|
if (!areArrayEqual(prevLayout, nextLayout)) {
|
|
@@ -287,6 +370,54 @@ watch(() => eagerValuesRef.value.panelDataArrayChanged, () => {
|
|
|
287
370
|
}
|
|
288
371
|
});
|
|
289
372
|
|
|
373
|
+
watch(groupSizeInPixels, (nextSize, prevSize) => {
|
|
374
|
+
if (prevSize == null || nextSize == null) {
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const { layout: prevLayout, panelDataArray } = eagerValuesRef.value;
|
|
379
|
+
if (prevLayout.length === 0) {
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
if (!hasPixelSizedPanel(panelDataArray)) {
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
const recalculatedLayout = recalculateLayoutForPixelPanels({
|
|
387
|
+
layout: prevLayout,
|
|
388
|
+
panelDataArray,
|
|
389
|
+
prevGroupSize: prevSize,
|
|
390
|
+
nextGroupSize: nextSize,
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
if (!recalculatedLayout) {
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
const panelConstraints = getPanelConstraintsInPercent(nextSize);
|
|
398
|
+
if (!panelConstraints) {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
const nextLayout = validatePanelGroupLayout({
|
|
403
|
+
layout: recalculatedLayout,
|
|
404
|
+
panelConstraints,
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
408
|
+
setLayout(nextLayout);
|
|
409
|
+
|
|
410
|
+
eagerValuesRef.value.layout = nextLayout;
|
|
411
|
+
emits('layout', nextLayout);
|
|
412
|
+
|
|
413
|
+
callPanelCallbacks(
|
|
414
|
+
panelDataArray,
|
|
415
|
+
nextLayout,
|
|
416
|
+
panelIdToLastNotifiedSizeMapRef.value,
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
|
|
290
421
|
function registerResizeHandle(dragHandleId: string) {
|
|
291
422
|
return function resizeHandler(event: ResizeEvent) {
|
|
292
423
|
event.preventDefault();
|
|
@@ -324,7 +455,10 @@ function registerResizeHandle(dragHandleId: string) {
|
|
|
324
455
|
delta = -delta;
|
|
325
456
|
}
|
|
326
457
|
|
|
327
|
-
const panelConstraints =
|
|
458
|
+
const panelConstraints = getPanelConstraintsInPercent();
|
|
459
|
+
if (!panelConstraints) {
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
328
462
|
|
|
329
463
|
const nextLayout = adjustLayoutByDelta({
|
|
330
464
|
delta,
|
|
@@ -383,20 +517,36 @@ function registerResizeHandle(dragHandleId: string) {
|
|
|
383
517
|
function resizePanel(panelData: PanelData, unsafePanelSize: number) {
|
|
384
518
|
const { layout: prevLayout, panelDataArray } = eagerValuesRef.value;
|
|
385
519
|
|
|
386
|
-
const panelConstraintsArray =
|
|
520
|
+
const panelConstraintsArray = getPanelConstraintsInPercent();
|
|
521
|
+
if (!panelConstraintsArray) {
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
const panelIndex = findPanelDataIndex(panelDataArray, panelData);
|
|
526
|
+
const panelUnit = panelData.constraints.sizeUnit ?? '%';
|
|
527
|
+
|
|
528
|
+
// Convert px to percent if needed for internal calculation
|
|
529
|
+
let sizeInPercent = unsafePanelSize;
|
|
530
|
+
if (panelUnit === 'px') {
|
|
531
|
+
const groupSize = getGroupSizeInPixels();
|
|
532
|
+
if (groupSize != null) {
|
|
533
|
+
sizeInPercent = (unsafePanelSize / groupSize) * 100;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
387
536
|
|
|
388
537
|
const { panelSize, pivotIndices } = panelDataHelper(
|
|
389
538
|
panelDataArray,
|
|
390
539
|
panelData,
|
|
391
540
|
prevLayout,
|
|
541
|
+
panelConstraintsArray,
|
|
392
542
|
);
|
|
393
543
|
|
|
394
544
|
assert(panelSize != null);
|
|
395
545
|
|
|
396
|
-
const isLastPanel =
|
|
546
|
+
const isLastPanel = panelIndex === panelDataArray.length - 1;
|
|
397
547
|
const delta = isLastPanel
|
|
398
|
-
? panelSize -
|
|
399
|
-
:
|
|
548
|
+
? panelSize - sizeInPercent
|
|
549
|
+
: sizeInPercent - panelSize;
|
|
400
550
|
|
|
401
551
|
const nextLayout = adjustLayoutByDelta({
|
|
402
552
|
delta,
|
|
@@ -425,37 +575,31 @@ function reevaluatePanelConstraints(panelData: PanelData, prevConstraints: Panel
|
|
|
425
575
|
const index = findPanelDataIndex(panelDataArray, panelData);
|
|
426
576
|
panelDataArray[index] = panelData;
|
|
427
577
|
eagerValuesRef.value.panelDataArrayChanged = true;
|
|
428
|
-
const {
|
|
429
|
-
collapsedSize: prevCollapsedSize = 0,
|
|
430
|
-
collapsible: prevCollapsible,
|
|
431
|
-
} = prevConstraints;
|
|
432
578
|
|
|
433
|
-
const
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
minSize: nextMinSize = 0,
|
|
438
|
-
} = panelData.constraints;
|
|
579
|
+
const panelConstraintsArray = getPanelConstraintsInPercent();
|
|
580
|
+
if (!panelConstraintsArray) {
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
439
583
|
|
|
584
|
+
const nextConstraints = panelConstraintsArray[index];
|
|
440
585
|
const { panelSize: prevPanelSize } = panelDataHelper(
|
|
441
586
|
panelDataArray,
|
|
442
587
|
panelData,
|
|
443
588
|
layout,
|
|
589
|
+
panelConstraintsArray,
|
|
444
590
|
);
|
|
591
|
+
|
|
445
592
|
if (prevPanelSize === null) {
|
|
446
|
-
// It's possible that the panels in this group have changed since the last render
|
|
447
593
|
return;
|
|
448
594
|
}
|
|
449
595
|
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
) {
|
|
455
|
-
if (
|
|
596
|
+
const nextCollapsedSize = nextConstraints?.collapsedSize ?? 0;
|
|
597
|
+
const nextMaxSize = nextConstraints?.maxSize ?? 100;
|
|
598
|
+
const nextMinSize = nextConstraints?.minSize ?? 0;
|
|
599
|
+
|
|
600
|
+
if (nextConstraints?.collapsible && isPanelCollapsed(panelData)) {
|
|
601
|
+
if (prevPanelSize !== nextCollapsedSize) {
|
|
456
602
|
resizePanel(panelData, nextCollapsedSize);
|
|
457
|
-
} else {
|
|
458
|
-
// Stay collapsed
|
|
459
603
|
}
|
|
460
604
|
} else if (prevPanelSize < nextMinSize) {
|
|
461
605
|
resizePanel(panelData, nextMinSize);
|
|
@@ -515,15 +659,16 @@ function collapsePanel(panelData: PanelData) {
|
|
|
515
659
|
const { layout: prevLayout, panelDataArray } = eagerValuesRef.value;
|
|
516
660
|
|
|
517
661
|
if (panelData.constraints.collapsible) {
|
|
518
|
-
const panelConstraintsArray =
|
|
519
|
-
|
|
520
|
-
|
|
662
|
+
const panelConstraintsArray = getPanelConstraintsInPercent();
|
|
663
|
+
if (!panelConstraintsArray) {
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
521
666
|
|
|
522
667
|
const {
|
|
523
668
|
collapsedSize = 0,
|
|
524
669
|
panelSize,
|
|
525
670
|
pivotIndices,
|
|
526
|
-
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
671
|
+
} = panelDataHelper(panelDataArray, panelData, prevLayout, panelConstraintsArray);
|
|
527
672
|
|
|
528
673
|
assert(
|
|
529
674
|
panelSize != null,
|
|
@@ -533,7 +678,13 @@ function collapsePanel(panelData: PanelData) {
|
|
|
533
678
|
if (panelSize !== collapsedSize) {
|
|
534
679
|
// Store size before collapse;
|
|
535
680
|
// This is the size that gets restored if the expand() API is used.
|
|
536
|
-
|
|
681
|
+
const sizeUnit = panelData.constraints.sizeUnit ?? '%';
|
|
682
|
+
const groupSize = groupSizeInPixels.value ?? getGroupSizeInPixels();
|
|
683
|
+
const sizeBeforeCollapse = sizeUnit === 'px' && groupSize
|
|
684
|
+
? (panelSize / 100) * groupSize
|
|
685
|
+
: panelSize;
|
|
686
|
+
|
|
687
|
+
panelSizeBeforeCollapseRef.value.set(panelData.id, sizeBeforeCollapse);
|
|
537
688
|
|
|
538
689
|
const isLastPanel
|
|
539
690
|
= findPanelDataIndex(panelDataArray, panelData)
|
|
@@ -571,26 +722,41 @@ function expandPanel(panelData: PanelData) {
|
|
|
571
722
|
const { layout: prevLayout, panelDataArray } = eagerValuesRef.value;
|
|
572
723
|
|
|
573
724
|
if (panelData.constraints.collapsible) {
|
|
574
|
-
const panelConstraintsArray =
|
|
575
|
-
|
|
576
|
-
|
|
725
|
+
const panelConstraintsArray = getPanelConstraintsInPercent();
|
|
726
|
+
if (!panelConstraintsArray) {
|
|
727
|
+
return;
|
|
728
|
+
}
|
|
577
729
|
|
|
578
730
|
const {
|
|
579
731
|
collapsedSize = 0,
|
|
580
|
-
panelSize,
|
|
732
|
+
panelSize = 0,
|
|
581
733
|
minSize = 0,
|
|
582
734
|
pivotIndices,
|
|
583
|
-
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
735
|
+
} = panelDataHelper(panelDataArray, panelData, prevLayout, panelConstraintsArray);
|
|
584
736
|
|
|
585
|
-
if (panelSize
|
|
737
|
+
if (fuzzyCompareNumbers(panelSize, collapsedSize) <= 0) {
|
|
586
738
|
// Restore this panel to the size it was before it was collapsed, if possible.
|
|
587
739
|
const prevPanelSize = panelSizeBeforeCollapseRef.value.get(
|
|
588
740
|
panelData.id,
|
|
589
741
|
);
|
|
742
|
+
const sizeUnit = panelData.constraints.sizeUnit ?? '%';
|
|
743
|
+
const groupSize = groupSizeInPixels.value ?? getGroupSizeInPixels();
|
|
744
|
+
|
|
745
|
+
let restoredSize: number | null | undefined;
|
|
746
|
+
|
|
747
|
+
if (sizeUnit === 'px' && groupSize) {
|
|
748
|
+
if (prevPanelSize != null) {
|
|
749
|
+
restoredSize = (prevPanelSize / groupSize) * 100;
|
|
750
|
+
} else {
|
|
751
|
+
restoredSize = null;
|
|
752
|
+
}
|
|
753
|
+
} else {
|
|
754
|
+
restoredSize = prevPanelSize;
|
|
755
|
+
}
|
|
590
756
|
|
|
591
757
|
const baseSize
|
|
592
|
-
=
|
|
593
|
-
?
|
|
758
|
+
= restoredSize != null && restoredSize >= minSize
|
|
759
|
+
? restoredSize
|
|
594
760
|
: minSize;
|
|
595
761
|
|
|
596
762
|
const isLastPanel
|
|
@@ -633,17 +799,33 @@ function getPanelSize(panelData: PanelData) {
|
|
|
633
799
|
`Panel size not found for panel "${panelData.id}"`,
|
|
634
800
|
);
|
|
635
801
|
|
|
802
|
+
// If the panel uses px units, convert from percent back to px
|
|
803
|
+
const panelUnit = panelData.constraints.sizeUnit ?? '%';
|
|
804
|
+
if (panelUnit === 'px') {
|
|
805
|
+
const groupSize = getGroupSizeInPixels();
|
|
806
|
+
if (groupSize != null) {
|
|
807
|
+
return (panelSize / 100) * groupSize;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
|
|
636
811
|
return panelSize;
|
|
637
812
|
}
|
|
638
813
|
|
|
639
814
|
function isPanelCollapsed(panelData: PanelData) {
|
|
640
815
|
const { layout, panelDataArray } = eagerValuesRef.value;
|
|
641
816
|
|
|
817
|
+
const panelConstraintsArray = getPanelConstraintsInPercent();
|
|
818
|
+
|
|
642
819
|
const {
|
|
643
820
|
collapsedSize = 0,
|
|
644
821
|
collapsible,
|
|
645
822
|
panelSize,
|
|
646
|
-
} = panelDataHelper(
|
|
823
|
+
} = panelDataHelper(
|
|
824
|
+
panelDataArray,
|
|
825
|
+
panelData,
|
|
826
|
+
layout,
|
|
827
|
+
panelConstraintsArray ?? undefined,
|
|
828
|
+
);
|
|
647
829
|
|
|
648
830
|
if (!collapsible) {
|
|
649
831
|
return false;
|
|
@@ -651,7 +833,9 @@ function isPanelCollapsed(panelData: PanelData) {
|
|
|
651
833
|
|
|
652
834
|
// panelSize is undefined during ssr due to vue ssr reactivity limitation.
|
|
653
835
|
if (panelSize === undefined) {
|
|
654
|
-
|
|
836
|
+
const panelIndex = findPanelDataIndex(panelDataArray, panelData);
|
|
837
|
+
const constraints = panelConstraintsArray?.[panelIndex] ?? panelData.constraints;
|
|
838
|
+
return constraints.defaultSize === constraints.collapsedSize;
|
|
655
839
|
} else {
|
|
656
840
|
return panelSize === collapsedSize;
|
|
657
841
|
}
|
|
@@ -660,11 +844,18 @@ function isPanelCollapsed(panelData: PanelData) {
|
|
|
660
844
|
function isPanelExpanded(panelData: PanelData) {
|
|
661
845
|
const { layout, panelDataArray } = eagerValuesRef.value;
|
|
662
846
|
|
|
847
|
+
const panelConstraintsArray = getPanelConstraintsInPercent();
|
|
848
|
+
|
|
663
849
|
const {
|
|
664
850
|
collapsedSize = 0,
|
|
665
851
|
collapsible,
|
|
666
852
|
panelSize,
|
|
667
|
-
} = panelDataHelper(
|
|
853
|
+
} = panelDataHelper(
|
|
854
|
+
panelDataArray,
|
|
855
|
+
panelData,
|
|
856
|
+
layout,
|
|
857
|
+
panelConstraintsArray ?? undefined,
|
|
858
|
+
);
|
|
668
859
|
|
|
669
860
|
assert(
|
|
670
861
|
panelSize != null,
|
|
@@ -706,6 +897,7 @@ function panelDataHelper(
|
|
|
706
897
|
panelDataArray: Array<PanelData>,
|
|
707
898
|
panelData: PanelData,
|
|
708
899
|
layout: Array<number>,
|
|
900
|
+
panelConstraints?: Array<PanelConstraints> | null,
|
|
709
901
|
) {
|
|
710
902
|
const panelIndex = findPanelDataIndex(panelDataArray, panelData);
|
|
711
903
|
|
|
@@ -714,10 +906,13 @@ function panelDataHelper(
|
|
|
714
906
|
? [panelIndex - 1, panelIndex]
|
|
715
907
|
: [panelIndex, panelIndex + 1];
|
|
716
908
|
|
|
909
|
+
const constraints = panelConstraints ?? getPanelConstraintsInPercent();
|
|
910
|
+
const panelConstraintsFromGroup = constraints?.[panelIndex];
|
|
911
|
+
|
|
717
912
|
const panelSize = layout[panelIndex];
|
|
718
913
|
|
|
719
914
|
return {
|
|
720
|
-
...panelData.constraints,
|
|
915
|
+
...(panelConstraintsFromGroup ?? panelData.constraints),
|
|
721
916
|
panelSize,
|
|
722
917
|
pivotIndices,
|
|
723
918
|
};
|
|
@@ -4,20 +4,22 @@ import { useId } from '../shared';
|
|
|
4
4
|
import { PRECISION } from './utils/constants';
|
|
5
5
|
|
|
6
6
|
export interface ASplitterPanelProps extends APrimitiveProps {
|
|
7
|
-
/** The size of panel when it is collapsed
|
|
7
|
+
/** The size of panel when it is collapsed; interpreted using `sizeUnit`. */
|
|
8
8
|
collapsedSize?: number;
|
|
9
9
|
/** Should panel collapse when resized beyond its `minSize`. When `true`, it will be collapsed to `collapsedSize`. */
|
|
10
10
|
collapsible?: boolean;
|
|
11
|
-
/** Initial size of panel (
|
|
11
|
+
/** Initial size of panel, interpreted using `sizeUnit` (percent by default). */
|
|
12
12
|
defaultSize?: number;
|
|
13
13
|
/** Panel id (unique within group); falls back to `useId` when not provided */
|
|
14
14
|
id?: string;
|
|
15
|
-
/** The maximum allowable size of panel
|
|
15
|
+
/** The maximum allowable size of panel, interpreted using `sizeUnit`; defaults to `100` (percent). */
|
|
16
16
|
maxSize?: number;
|
|
17
|
-
/** The minimum allowable size of panel
|
|
17
|
+
/** The minimum allowable size of panel, interpreted using `sizeUnit`; defaults to `10` (percent). */
|
|
18
18
|
minSize?: number;
|
|
19
19
|
/** The order of panel within group; required for groups with conditionally rendered panels */
|
|
20
20
|
order?: number;
|
|
21
|
+
/** Unit used for sizing values; `%` by default, or `px` for fixed sizing. */
|
|
22
|
+
sizeUnit?: '%' | 'px';
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
export type ASplitterPanelEmits = {
|
|
@@ -33,7 +35,7 @@ export type PanelOnCollapse = () => void;
|
|
|
33
35
|
export type PanelOnExpand = () => void;
|
|
34
36
|
export type PanelOnResize = (
|
|
35
37
|
size: number,
|
|
36
|
-
prevSize: number | undefined
|
|
38
|
+
prevSize: number | undefined,
|
|
37
39
|
) => void;
|
|
38
40
|
|
|
39
41
|
export type PanelCallbacks = {
|
|
@@ -49,6 +51,7 @@ export type PanelConstraints = {
|
|
|
49
51
|
/** Panel id (unique within group); falls back to useId when not provided */
|
|
50
52
|
maxSize?: number | undefined;
|
|
51
53
|
minSize?: number | undefined;
|
|
54
|
+
sizeUnit?: '%' | 'px' | undefined;
|
|
52
55
|
};
|
|
53
56
|
|
|
54
57
|
export type PanelData = {
|
|
@@ -107,6 +110,7 @@ const panelDataRef = computed(() => ({
|
|
|
107
110
|
/** Panel id (unique within group); falls back to useId when not provided */
|
|
108
111
|
maxSize: props.maxSize,
|
|
109
112
|
minSize: props.minSize,
|
|
113
|
+
sizeUnit: props.sizeUnit ?? '%',
|
|
110
114
|
},
|
|
111
115
|
id: panelId,
|
|
112
116
|
idIsFromProps: props.id !== undefined,
|
|
@@ -121,6 +125,7 @@ watch(() => panelDataRef.value.constraints, (constraints, prevConstraints) => {
|
|
|
121
125
|
|| prevConstraints.collapsible !== constraints.collapsible
|
|
122
126
|
|| prevConstraints.maxSize !== constraints.maxSize
|
|
123
127
|
|| prevConstraints.minSize !== constraints.minSize
|
|
128
|
+
|| prevConstraints.sizeUnit !== constraints.sizeUnit
|
|
124
129
|
) {
|
|
125
130
|
reevaluatePanelConstraints(panelDataRef.value, prevConstraints);
|
|
126
131
|
}
|
|
@@ -157,11 +162,11 @@ defineExpose({
|
|
|
157
162
|
collapse,
|
|
158
163
|
/** If panel is currently collapsed, expand it to its most recent size. */
|
|
159
164
|
expand,
|
|
160
|
-
/** Gets the current size of the panel
|
|
165
|
+
/** Gets the current size of the panel (in the panel's sizeUnit: percentage for '%', pixels for 'px'). */
|
|
161
166
|
getSize() {
|
|
162
167
|
return getPanelSize(panelDataRef.value);
|
|
163
168
|
},
|
|
164
|
-
/** Resize panel to the specified
|
|
169
|
+
/** Resize panel to the specified size (in the panel's sizeUnit: percentage for '%', pixels for 'px'). */
|
|
165
170
|
resize,
|
|
166
171
|
/** Returns `true` if the panel is currently collapsed */
|
|
167
172
|
isCollapsed,
|
|
@@ -16,9 +16,9 @@ export function useWindowSplitterPanelGroupBehavior({
|
|
|
16
16
|
eagerValuesRef,
|
|
17
17
|
groupId,
|
|
18
18
|
layout,
|
|
19
|
-
panelDataArray,
|
|
20
19
|
panelGroupElement,
|
|
21
20
|
setLayout,
|
|
21
|
+
getPanelDataWithPercentConstraints,
|
|
22
22
|
}: {
|
|
23
23
|
eagerValuesRef: Ref<{
|
|
24
24
|
panelDataArray: Array<PanelData>;
|
|
@@ -28,6 +28,7 @@ export function useWindowSplitterPanelGroupBehavior({
|
|
|
28
28
|
panelDataArray: Array<PanelData>;
|
|
29
29
|
panelGroupElement: Ref<ParentNode | null>;
|
|
30
30
|
setLayout: (sizes: Array<number>) => void;
|
|
31
|
+
getPanelDataWithPercentConstraints: (groupSizeOverride?: number | null) => Array<PanelData> | null;
|
|
31
32
|
}): void {
|
|
32
33
|
watchEffect((onCleanup) => {
|
|
33
34
|
const _panelGroupElement = panelGroupElement.value;
|
|
@@ -35,15 +36,20 @@ export function useWindowSplitterPanelGroupBehavior({
|
|
|
35
36
|
return;
|
|
36
37
|
}
|
|
37
38
|
|
|
39
|
+
const panelDataArrayWithPercentConstraints = getPanelDataWithPercentConstraints();
|
|
40
|
+
if (!panelDataArrayWithPercentConstraints) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
38
44
|
const resizeHandleElements = getResizeHandleElementsForGroup(
|
|
39
45
|
groupId,
|
|
40
46
|
_panelGroupElement,
|
|
41
47
|
);
|
|
42
48
|
|
|
43
|
-
for (let index = 0; index <
|
|
49
|
+
for (let index = 0; index < panelDataArrayWithPercentConstraints.length - 1; index++) {
|
|
44
50
|
const { valueMax, valueMin, valueNow } = calculateAriaValues({
|
|
45
51
|
layout: layout.value,
|
|
46
|
-
panelsArray:
|
|
52
|
+
panelsArray: panelDataArrayWithPercentConstraints,
|
|
47
53
|
pivotIndices: [index, index + 1],
|
|
48
54
|
});
|
|
49
55
|
|
|
@@ -53,7 +59,7 @@ export function useWindowSplitterPanelGroupBehavior({
|
|
|
53
59
|
console.warn(`WARNING: Missing resize handle for PanelGroup "${groupId}"`);
|
|
54
60
|
}
|
|
55
61
|
} else {
|
|
56
|
-
const panelData =
|
|
62
|
+
const panelData = panelDataArrayWithPercentConstraints[index];
|
|
57
63
|
assert(panelData);
|
|
58
64
|
|
|
59
65
|
resizeHandleElement.setAttribute('aria-controls', panelData.id);
|
|
@@ -91,6 +97,11 @@ export function useWindowSplitterPanelGroupBehavior({
|
|
|
91
97
|
const eagerValues = eagerValuesRef.value;
|
|
92
98
|
assert(eagerValues);
|
|
93
99
|
|
|
100
|
+
const panelDataArrayWithPercentConstraints = getPanelDataWithPercentConstraints();
|
|
101
|
+
if (!panelDataArrayWithPercentConstraints) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
94
105
|
const { panelDataArray } = eagerValues;
|
|
95
106
|
const groupElement = getPanelGroupElement(groupId, _panelGroupElement);
|
|
96
107
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
@@ -122,11 +133,11 @@ export function useWindowSplitterPanelGroupBehavior({
|
|
|
122
133
|
case KEY_CODES.ENTER: {
|
|
123
134
|
event.preventDefault();
|
|
124
135
|
|
|
125
|
-
const index =
|
|
136
|
+
const index = panelDataArrayWithPercentConstraints.findIndex(
|
|
126
137
|
(panelData) => panelData.id === idBefore,
|
|
127
138
|
);
|
|
128
139
|
if (index >= 0) {
|
|
129
|
-
const panelData =
|
|
140
|
+
const panelData = panelDataArrayWithPercentConstraints[index];
|
|
130
141
|
assert(panelData);
|
|
131
142
|
|
|
132
143
|
const size = layout.value[index];
|
|
@@ -143,7 +154,7 @@ export function useWindowSplitterPanelGroupBehavior({
|
|
|
143
154
|
? minSize - collapsedSize
|
|
144
155
|
: collapsedSize - size,
|
|
145
156
|
layout: layout.value,
|
|
146
|
-
panelConstraints:
|
|
157
|
+
panelConstraints: panelDataArrayWithPercentConstraints.map(
|
|
147
158
|
(panelData) => panelData.constraints,
|
|
148
159
|
),
|
|
149
160
|
pivotIndices: determinePivotIndices(
|