@plexui/vue 0.10.0 → 0.11.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/es/components/ButtonGroup/ButtonGroup.js +7 -0
- package/dist/es/components/ButtonGroup/ButtonGroup.js.map +1 -1
- package/dist/es/components/ButtonGroup/index.js.map +1 -1
- package/dist/es/components/ContextMenu/shared.js +3 -2
- package/dist/es/components/ContextMenu/shared.js.map +1 -1
- package/dist/es/components/Dialog/Dialog.js +135 -18
- package/dist/es/components/Dialog/Dialog.js.map +1 -1
- package/dist/es/components/Dialog/dialogSteps.js +85 -0
- package/dist/es/components/Dialog/dialogSteps.js.map +1 -0
- package/dist/es/components/Dialog/dialogViewport.js +74 -0
- package/dist/es/components/Dialog/dialogViewport.js.map +1 -0
- package/dist/es/components/Dialog/index.js +1 -1
- package/dist/es/components/Dialog/index.js.map +1 -1
- package/dist/es/components/Dialog/sheetDrag.js +2 -1
- package/dist/es/components/Dialog/sheetDrag.js.map +1 -1
- package/dist/es/components/IndexBar/IndexBar.js +215 -0
- package/dist/es/components/IndexBar/IndexBar.js.map +1 -0
- package/dist/es/components/IndexBar/index.js +2 -0
- package/dist/es/components/IndexBar/index.js.map +1 -0
- package/dist/es/components/MarkdownEditor/MarkdownEditor.js +149 -1
- package/dist/es/components/MarkdownEditor/MarkdownEditor.js.map +1 -1
- package/dist/es/components/Menu/Menu.js +10 -6
- package/dist/es/components/Menu/Menu.js.map +1 -1
- package/dist/es/components/Page/Page.js +2 -2
- package/dist/es/components/Page/Page.js.map +1 -1
- package/dist/es/components/PhoneLayout/PhoneLayout.js +50 -0
- package/dist/es/components/PhoneLayout/PhoneLayout.js.map +1 -0
- package/dist/es/components/PhoneLayout/index.js +2 -0
- package/dist/es/components/PhoneLayout/index.js.map +1 -0
- package/dist/es/components/Popover/Popover.js +1 -1
- package/dist/es/components/Popover/Popover.js.map +1 -1
- package/dist/es/components/Popover/deferredPointerDownOutside.js +59 -4
- package/dist/es/components/Popover/deferredPointerDownOutside.js.map +1 -1
- package/dist/es/components/Select/Select.js +2 -2
- package/dist/es/components/Select/Select.js.map +1 -1
- package/dist/es/components/Slider/Slider.js +34 -3
- package/dist/es/components/Slider/Slider.js.map +1 -1
- package/dist/es/components/SwipeActions/SwipeActions.js +374 -0
- package/dist/es/components/SwipeActions/SwipeActions.js.map +1 -0
- package/dist/es/components/SwipeActions/index.js +2 -0
- package/dist/es/components/SwipeActions/index.js.map +1 -0
- package/dist/es/components/Switch/Switch.js +3 -1
- package/dist/es/components/Switch/Switch.js.map +1 -1
- package/dist/es/components/TabBar/TabBar.js +23 -8
- package/dist/es/components/TabBar/TabBar.js.map +1 -1
- package/dist/es/components/TabBar/index.js.map +1 -1
- package/dist/es/components/Tabs/Tabs.js +1 -0
- package/dist/es/components/Tabs/Tabs.js.map +1 -1
- package/dist/es/components/TagInput/TagInput.js +3 -46
- package/dist/es/components/TagInput/TagInput.js.map +1 -1
- package/dist/es/components/Textarea/Textarea.js +1 -0
- package/dist/es/components/Textarea/Textarea.js.map +1 -1
- package/dist/es/components/Tip/Tip.js +276 -0
- package/dist/es/components/Tip/Tip.js.map +1 -0
- package/dist/es/components/Tip/index.js +2 -0
- package/dist/es/components/Tip/index.js.map +1 -0
- package/dist/es/components/Toast/ToastRenderer.js +30 -13
- package/dist/es/components/Toast/ToastRenderer.js.map +1 -1
- package/dist/es/components/Toast/Toaster.js +17 -6
- package/dist/es/components/Toast/Toaster.js.map +1 -1
- package/dist/es/components/Toast/toastLifecycle.js +113 -1
- package/dist/es/components/Toast/toastLifecycle.js.map +1 -1
- package/dist/es/components/Toolbar/Toolbar.js +3 -3
- package/dist/es/components/Toolbar/Toolbar.js.map +1 -1
- package/dist/es/composables/useEscCloseStack.js +8 -4
- package/dist/es/composables/useEscCloseStack.js.map +1 -1
- package/dist/es/lib/floatingBoundary.js +3 -1
- package/dist/es/lib/floatingBoundary.js.map +1 -1
- package/dist/es/lib/helpers.js +21 -0
- package/dist/es/lib/helpers.js.map +1 -1
- package/dist/es/lib/phoneLayout.js +16 -0
- package/dist/es/lib/phoneLayout.js.map +1 -0
- package/dist/es/lib/toastRegion.js +6 -0
- package/dist/es/lib/toastRegion.js.map +1 -0
- package/dist/types/components/ButtonGroup/ButtonGroup.d.ts +13 -0
- package/dist/types/components/ButtonGroup/index.d.ts +1 -1
- package/dist/types/components/ContextMenu/shared.d.ts +3 -2
- package/dist/types/components/Dialog/Dialog.d.ts +93 -3
- package/dist/types/components/Dialog/dialogSteps.d.ts +10 -0
- package/dist/types/components/Dialog/dialogViewport.d.ts +1 -0
- package/dist/types/components/Dialog/index.d.ts +1 -1
- package/dist/types/components/IndexBar/IndexBar.d.ts +112 -0
- package/dist/types/components/IndexBar/index.d.ts +1 -0
- package/dist/types/components/Menu/Menu.d.ts +14 -15
- package/dist/types/components/Page/Page.d.ts +2 -2
- package/dist/types/components/PhoneLayout/PhoneLayout.d.ts +21 -0
- package/dist/types/components/PhoneLayout/index.d.ts +1 -0
- package/dist/types/components/Popover/deferredPointerDownOutside.d.ts +1 -1
- package/dist/types/components/SwipeActions/SwipeActions.d.ts +135 -0
- package/dist/types/components/SwipeActions/index.d.ts +1 -0
- package/dist/types/components/TabBar/TabBar.d.ts +55 -6
- package/dist/types/components/TabBar/index.d.ts +1 -1
- package/dist/types/components/Tip/Tip.d.ts +146 -0
- package/dist/types/components/Tip/index.d.ts +1 -0
- package/dist/types/components/Toast/toastLifecycle.d.ts +34 -0
- package/dist/types/components/Toolbar/Toolbar.d.ts +9 -7
- package/dist/types/composables/useEscCloseStack.d.ts +2 -2
- package/dist/types/lib/helpers.d.ts +6 -0
- package/dist/types/lib/phoneLayout.d.ts +11 -0
- package/dist/types/lib/toastRegion.d.ts +5 -0
- package/package.json +2 -2
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import { computed, defineComponent, h, onBeforeUnmount, onMounted, onUpdated, ref, watch } from "vue";
|
|
2
|
+
import s from "@plexui/styles/components/SwipeActions/SwipeActions.module.css";
|
|
3
|
+
/** A finger has to travel this far, and farther across than down, before the row follows it. */
|
|
4
|
+
const SLOP = 10;
|
|
5
|
+
/** The width an open row moves by is the border box of its actions, edge and content gaps included. */
|
|
6
|
+
const BORDER_BOX = { box: "border-box" };
|
|
7
|
+
/** Controls that take a horizontal drag themselves. */
|
|
8
|
+
const OWN_DRAG = 'input, textarea, select, [contenteditable]:not([contenteditable="false"]), [role="slider"]';
|
|
9
|
+
/** The open row: opening another one closes it, as a list keeps one row open. */
|
|
10
|
+
let closeOpenRow = null;
|
|
11
|
+
/** The row keeps the finger past its edges; a pointer that is no longer active (it lifted between events) cannot be held. */
|
|
12
|
+
const capture = (element, pointerId) => {
|
|
13
|
+
try {
|
|
14
|
+
element.setPointerCapture?.(pointerId);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
// The swipe goes on with the events the row still gets.
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const sideOf = (offset) => offset > 0 ? "leading" : offset < 0 ? "trailing" : undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Where the content goes for a swipe of `raw` px toward the trailing edge (negative: toward the leading edge), and
|
|
23
|
+
* whether that is a full swipe. A side without actions stays shut. Past its actions the content follows the finger
|
|
24
|
+
* where a full swipe is allowed, and a third as fast where it is not; past the middle between the open actions and
|
|
25
|
+
* the far edge of the row the swipe is full.
|
|
26
|
+
*/
|
|
27
|
+
export const swipeActionsOffset = (raw, widths, rowWidth, fullSwipe) => {
|
|
28
|
+
const side = sideOf(raw);
|
|
29
|
+
const width = side ? widths[side] : 0;
|
|
30
|
+
if (!side || !(width > 0))
|
|
31
|
+
return { offset: 0, full: false };
|
|
32
|
+
const sign = Math.sign(raw);
|
|
33
|
+
const distance = Math.abs(raw);
|
|
34
|
+
if (distance <= width)
|
|
35
|
+
return { offset: raw, full: false };
|
|
36
|
+
if (!fullSwipe)
|
|
37
|
+
return { offset: sign * (width + (distance - width) / 3), full: false };
|
|
38
|
+
const travel = Math.min(distance, Math.max(width, rowWidth));
|
|
39
|
+
return { offset: sign * travel, full: travel >= (width + rowWidth) / 2 };
|
|
40
|
+
};
|
|
41
|
+
const SwipeActionsComponent = defineComponent({
|
|
42
|
+
name: "SwipeActions",
|
|
43
|
+
inheritAttrs: false,
|
|
44
|
+
props: {
|
|
45
|
+
/** Actions revealed by a swipe toward the trailing edge, the first one at the leading edge */
|
|
46
|
+
leading: { type: Array, default: () => [] },
|
|
47
|
+
/** Actions revealed by a swipe toward the leading edge, the first one at the trailing edge */
|
|
48
|
+
trailing: { type: Array, default: () => [] },
|
|
49
|
+
/** Where the actions show their labels: `"hidden"` (symbols only), `"inside"` the capsule, or `"below"` it (for rows of 68px and taller). @default "hidden" */
|
|
50
|
+
labelPlacement: { type: String, default: "hidden" },
|
|
51
|
+
/** A swipe past the middle between the open actions and the far edge runs the first action of that side. @default true */
|
|
52
|
+
fullSwipe: { type: Boolean, default: true },
|
|
53
|
+
},
|
|
54
|
+
setup(props, { attrs, slots }) {
|
|
55
|
+
const offset = ref(0);
|
|
56
|
+
const full = ref(false);
|
|
57
|
+
const swiping = ref(false);
|
|
58
|
+
const rtl = ref(false);
|
|
59
|
+
const root = ref(null);
|
|
60
|
+
const sides = { leading: null, trailing: null };
|
|
61
|
+
let gesture = null;
|
|
62
|
+
let suppressClick = false;
|
|
63
|
+
let observer = null;
|
|
64
|
+
const revealed = computed(() => sideOf(offset.value));
|
|
65
|
+
const widthOf = (side) => sides[side]?.getBoundingClientRect().width ?? 0;
|
|
66
|
+
const isRtl = () => !!root.value && getComputedStyle(root.value).direction === "rtl";
|
|
67
|
+
const move = (next, nextFull = false) => {
|
|
68
|
+
offset.value = next;
|
|
69
|
+
full.value = nextFull;
|
|
70
|
+
};
|
|
71
|
+
/** Lets go of the gesture: the listeners for its end go, and the row no longer follows the finger. */
|
|
72
|
+
const release = () => {
|
|
73
|
+
const state = gesture;
|
|
74
|
+
gesture = null;
|
|
75
|
+
state?.detach();
|
|
76
|
+
return state;
|
|
77
|
+
};
|
|
78
|
+
const close = () => {
|
|
79
|
+
if (closeOpenRow === closer)
|
|
80
|
+
closeOpenRow = null;
|
|
81
|
+
move(0);
|
|
82
|
+
};
|
|
83
|
+
/** One function for the life of the row, so the list knows which row is open; another row that opens ends this one's gesture too. */
|
|
84
|
+
const closer = () => {
|
|
85
|
+
const state = release();
|
|
86
|
+
if (state) {
|
|
87
|
+
swiping.value = false;
|
|
88
|
+
// The finger of the ended swipe still lifts over this row: its click is not a click on the content.
|
|
89
|
+
if (state.swiping)
|
|
90
|
+
suppressClick = true;
|
|
91
|
+
}
|
|
92
|
+
close();
|
|
93
|
+
};
|
|
94
|
+
/** This row takes the place of the open one. */
|
|
95
|
+
const claim = () => {
|
|
96
|
+
if (closeOpenRow && closeOpenRow !== closer)
|
|
97
|
+
closeOpenRow();
|
|
98
|
+
closeOpenRow = closer;
|
|
99
|
+
};
|
|
100
|
+
/** Shows a side as wide as its actions (`width` when known), or closes the row when that side has none (any more). */
|
|
101
|
+
const open = (side, width = widthOf(side)) => {
|
|
102
|
+
if (!(width > 0))
|
|
103
|
+
return close();
|
|
104
|
+
claim();
|
|
105
|
+
rtl.value = isRtl();
|
|
106
|
+
move(side === "leading" ? width : -width);
|
|
107
|
+
};
|
|
108
|
+
/** An open row follows its actions: more of them, other labels or another width move it to their new width. */
|
|
109
|
+
const sync = () => {
|
|
110
|
+
const side = sideOf(offset.value);
|
|
111
|
+
if (!side || gesture?.swiping || full.value)
|
|
112
|
+
return;
|
|
113
|
+
const width = widthOf(side);
|
|
114
|
+
if (!(width > 0))
|
|
115
|
+
return close();
|
|
116
|
+
const target = side === "leading" ? width : -width;
|
|
117
|
+
if (target !== offset.value)
|
|
118
|
+
move(target);
|
|
119
|
+
};
|
|
120
|
+
// After each render, and whenever the actions change size, an open row takes their width.
|
|
121
|
+
const observeSides = () => {
|
|
122
|
+
for (const element of [sides.leading, sides.trailing])
|
|
123
|
+
if (element)
|
|
124
|
+
observer?.observe(element, BORDER_BOX);
|
|
125
|
+
};
|
|
126
|
+
onMounted(() => {
|
|
127
|
+
if (typeof ResizeObserver !== "undefined")
|
|
128
|
+
observer = new ResizeObserver(sync);
|
|
129
|
+
observeSides();
|
|
130
|
+
});
|
|
131
|
+
onUpdated(() => {
|
|
132
|
+
sync();
|
|
133
|
+
observeSides();
|
|
134
|
+
});
|
|
135
|
+
// A press anywhere outside the open row closes it.
|
|
136
|
+
const handleOutsidePointerDown = (event) => {
|
|
137
|
+
if (event.target instanceof Node && root.value?.contains(event.target))
|
|
138
|
+
return;
|
|
139
|
+
close();
|
|
140
|
+
};
|
|
141
|
+
watch([revealed, swiping], ([side, moving]) => {
|
|
142
|
+
document.removeEventListener("pointerdown", handleOutsidePointerDown, true);
|
|
143
|
+
if (side && !moving)
|
|
144
|
+
document.addEventListener("pointerdown", handleOutsidePointerDown, true);
|
|
145
|
+
});
|
|
146
|
+
// The open row lets go of the list, and of the finger, when it goes away.
|
|
147
|
+
onBeforeUnmount(() => {
|
|
148
|
+
document.removeEventListener("pointerdown", handleOutsidePointerDown, true);
|
|
149
|
+
observer?.disconnect();
|
|
150
|
+
observer = null;
|
|
151
|
+
release();
|
|
152
|
+
if (closeOpenRow === closer)
|
|
153
|
+
closeOpenRow = null;
|
|
154
|
+
});
|
|
155
|
+
const settle = (state) => {
|
|
156
|
+
const side = sideOf(offset.value);
|
|
157
|
+
if (!side)
|
|
158
|
+
return close();
|
|
159
|
+
if (full.value) {
|
|
160
|
+
(side === "leading" ? props.leading : props.trailing)[0]?.onSelect?.();
|
|
161
|
+
return close();
|
|
162
|
+
}
|
|
163
|
+
// The widths from the start of the swipe: a full swipe may have stretched the actions since.
|
|
164
|
+
if (Math.abs(offset.value) >= state.widths[side] / 2)
|
|
165
|
+
open(side, state.widths[side]);
|
|
166
|
+
else
|
|
167
|
+
close();
|
|
168
|
+
};
|
|
169
|
+
/** The finger lifted (anywhere): a swipe settles, a press on an open row closes it. */
|
|
170
|
+
const finish = () => {
|
|
171
|
+
const state = release();
|
|
172
|
+
if (!state)
|
|
173
|
+
return;
|
|
174
|
+
if (state.swiping) {
|
|
175
|
+
suppressClick = true;
|
|
176
|
+
swiping.value = false;
|
|
177
|
+
settle(state);
|
|
178
|
+
}
|
|
179
|
+
else if (state.start !== 0) {
|
|
180
|
+
if (state.swiping === undefined)
|
|
181
|
+
suppressClick = true;
|
|
182
|
+
close();
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
/** The browser took the gesture (a scroll) or the row lost the finger: the row goes back to where it was. */
|
|
186
|
+
const cancel = () => {
|
|
187
|
+
const state = release();
|
|
188
|
+
if (!state)
|
|
189
|
+
return;
|
|
190
|
+
swiping.value = false;
|
|
191
|
+
const side = sideOf(state.start);
|
|
192
|
+
if (state.swiping && side)
|
|
193
|
+
open(side, state.widths[side]);
|
|
194
|
+
else
|
|
195
|
+
close();
|
|
196
|
+
};
|
|
197
|
+
const handlePointerDown = (event) => {
|
|
198
|
+
if (event.button !== 0 || gesture)
|
|
199
|
+
return;
|
|
200
|
+
// A new press of the primary pointer starts clean: a swipe that another row ended and that was then cancelled leaves
|
|
201
|
+
// no click to swallow. Another finger's press keeps it, as only the primary pointer clicks.
|
|
202
|
+
if (event.isPrimary)
|
|
203
|
+
suppressClick = false;
|
|
204
|
+
if (props.leading.length < 1 && props.trailing.length < 1)
|
|
205
|
+
return;
|
|
206
|
+
// A drag in a text field or along a slider belongs to that control.
|
|
207
|
+
if (event.target instanceof Element && event.target.closest(OWN_DRAG))
|
|
208
|
+
return;
|
|
209
|
+
const pointerId = event.pointerId;
|
|
210
|
+
// The end of the gesture is heard wherever the finger lifts, inside the row or not.
|
|
211
|
+
const handleUp = (end) => {
|
|
212
|
+
if (end.pointerId === pointerId)
|
|
213
|
+
finish();
|
|
214
|
+
};
|
|
215
|
+
const handleCancel = (end) => {
|
|
216
|
+
if (end.pointerId === pointerId)
|
|
217
|
+
cancel();
|
|
218
|
+
};
|
|
219
|
+
window.addEventListener("pointerup", handleUp, true);
|
|
220
|
+
window.addEventListener("pointercancel", handleCancel, true);
|
|
221
|
+
gesture = {
|
|
222
|
+
pointerId,
|
|
223
|
+
x: event.clientX,
|
|
224
|
+
y: event.clientY,
|
|
225
|
+
start: offset.value,
|
|
226
|
+
swiping: undefined,
|
|
227
|
+
rtl: isRtl(),
|
|
228
|
+
widths: { leading: widthOf("leading"), trailing: widthOf("trailing") },
|
|
229
|
+
rowWidth: root.value?.clientWidth ?? 0,
|
|
230
|
+
detach: () => {
|
|
231
|
+
window.removeEventListener("pointerup", handleUp, true);
|
|
232
|
+
window.removeEventListener("pointercancel", handleCancel, true);
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
const handlePointerMove = (event) => {
|
|
237
|
+
const state = gesture;
|
|
238
|
+
if (!state || state.pointerId !== event.pointerId || state.swiping === false)
|
|
239
|
+
return;
|
|
240
|
+
const across = (event.clientX - state.x) * (state.rtl ? -1 : 1);
|
|
241
|
+
const down = event.clientY - state.y;
|
|
242
|
+
if (state.swiping === undefined) {
|
|
243
|
+
if (Math.abs(across) < SLOP && Math.abs(down) < SLOP)
|
|
244
|
+
return;
|
|
245
|
+
if (Math.abs(across) <= Math.abs(down)) {
|
|
246
|
+
state.swiping = false;
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
state.swiping = true;
|
|
250
|
+
const target = event.currentTarget;
|
|
251
|
+
if (target instanceof Element)
|
|
252
|
+
capture(target, event.pointerId);
|
|
253
|
+
window.getSelection?.()?.removeAllRanges();
|
|
254
|
+
claim();
|
|
255
|
+
rtl.value = state.rtl;
|
|
256
|
+
swiping.value = true;
|
|
257
|
+
}
|
|
258
|
+
const next = swipeActionsOffset(state.start + across, state.widths, state.rowWidth, props.fullSwipe);
|
|
259
|
+
move(next.offset, next.full);
|
|
260
|
+
};
|
|
261
|
+
/** The content lost the finger it held. A child that loses the finger to the content (as a touch moves its implicit capture) ends nothing. */
|
|
262
|
+
const handleLostPointerCapture = (event) => {
|
|
263
|
+
if (event.target === event.currentTarget && gesture?.pointerId === event.pointerId)
|
|
264
|
+
cancel();
|
|
265
|
+
};
|
|
266
|
+
/** A swipe or a press that closed the row is not a click on the content; a click from the keys still is. */
|
|
267
|
+
const handleClickCapture = (event) => {
|
|
268
|
+
if (!suppressClick || event.detail === 0)
|
|
269
|
+
return;
|
|
270
|
+
suppressClick = false;
|
|
271
|
+
event.preventDefault();
|
|
272
|
+
event.stopPropagation();
|
|
273
|
+
};
|
|
274
|
+
/** The focus on an action shows its side; on the content it closes the row. */
|
|
275
|
+
const handleFocusIn = (event) => {
|
|
276
|
+
if (gesture?.swiping)
|
|
277
|
+
return;
|
|
278
|
+
const target = event.target;
|
|
279
|
+
const side = ["leading", "trailing"].find((name) => target instanceof Node && !!sides[name]?.contains(target));
|
|
280
|
+
if (side) {
|
|
281
|
+
if (sideOf(offset.value) !== side)
|
|
282
|
+
open(side);
|
|
283
|
+
}
|
|
284
|
+
else if (offset.value !== 0) {
|
|
285
|
+
close();
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
const handleFocusOut = (event) => {
|
|
289
|
+
if (gesture?.swiping)
|
|
290
|
+
return;
|
|
291
|
+
if (event.relatedTarget instanceof Node && root.value?.contains(event.relatedTarget))
|
|
292
|
+
return;
|
|
293
|
+
if (offset.value !== 0)
|
|
294
|
+
close();
|
|
295
|
+
};
|
|
296
|
+
const select = (action, event) => {
|
|
297
|
+
action.onSelect?.();
|
|
298
|
+
// A press closes the row, as iOS does. From the keys the action keeps the focus, so its side stays open until
|
|
299
|
+
// the focus leaves the row.
|
|
300
|
+
if (event.detail === 0)
|
|
301
|
+
return;
|
|
302
|
+
const target = event.currentTarget;
|
|
303
|
+
if (target instanceof HTMLElement)
|
|
304
|
+
target.blur();
|
|
305
|
+
close();
|
|
306
|
+
};
|
|
307
|
+
const renderSide = (side, actions) => {
|
|
308
|
+
if (actions.length < 1)
|
|
309
|
+
return null;
|
|
310
|
+
const shown = side === "leading" ? actions : [...actions].reverse();
|
|
311
|
+
const isFull = full.value && revealed.value === side;
|
|
312
|
+
return h("div", {
|
|
313
|
+
"ref": (element) => {
|
|
314
|
+
sides[side] = element instanceof HTMLElement ? element : null;
|
|
315
|
+
},
|
|
316
|
+
"class": s.Actions,
|
|
317
|
+
"data-side": side,
|
|
318
|
+
"data-full": isFull ? "" : undefined,
|
|
319
|
+
"style": isFull ? { width: `${Math.abs(offset.value)}px` } : undefined,
|
|
320
|
+
}, shown.map((action) => {
|
|
321
|
+
const color = action.color ?? "secondary";
|
|
322
|
+
const labelInside = props.labelPlacement === "inside" || !action.Icon;
|
|
323
|
+
const labelBelow = props.labelPlacement === "below" && !!action.Icon;
|
|
324
|
+
return h("button", {
|
|
325
|
+
"key": action.id,
|
|
326
|
+
"type": "button",
|
|
327
|
+
"class": s.Action,
|
|
328
|
+
"data-color": color,
|
|
329
|
+
"data-first": action === actions[0] ? "" : undefined,
|
|
330
|
+
"aria-label": labelInside || labelBelow ? undefined : action.label,
|
|
331
|
+
"onClick": (event) => select(action, event),
|
|
332
|
+
}, [
|
|
333
|
+
h("span", { class: s.Capsule }, [
|
|
334
|
+
action.Icon ? h(action.Icon, { "class": s.Icon, "aria-hidden": "true" }) : null,
|
|
335
|
+
labelInside ? h("span", { class: s.Label }, action.label) : null,
|
|
336
|
+
]),
|
|
337
|
+
labelBelow ? h("span", { class: s.Caption }, action.label) : null,
|
|
338
|
+
]);
|
|
339
|
+
}));
|
|
340
|
+
};
|
|
341
|
+
return () => h("div", {
|
|
342
|
+
...attrs,
|
|
343
|
+
"ref": root,
|
|
344
|
+
"class": [s.SwipeActions, attrs.class],
|
|
345
|
+
"data-row": "",
|
|
346
|
+
"data-swipe-actions": "",
|
|
347
|
+
"data-label-placement": props.labelPlacement,
|
|
348
|
+
"data-revealed": revealed.value,
|
|
349
|
+
"data-swiping": swiping.value ? "" : undefined,
|
|
350
|
+
"onFocusin": handleFocusIn,
|
|
351
|
+
"onFocusout": handleFocusOut,
|
|
352
|
+
}, [
|
|
353
|
+
renderSide("leading", props.leading),
|
|
354
|
+
h("div", {
|
|
355
|
+
"class": s.Content,
|
|
356
|
+
"data-swipe-content": "",
|
|
357
|
+
"style": offset.value !== 0 ? { "--swipe-actions-offset": `${rtl.value ? -offset.value : offset.value}px` } : undefined,
|
|
358
|
+
"onPointerdown": handlePointerDown,
|
|
359
|
+
"onPointermove": handlePointerMove,
|
|
360
|
+
"onLostpointercapture": handleLostPointerCapture,
|
|
361
|
+
"onClickCapture": handleClickCapture,
|
|
362
|
+
}, slots.default?.()),
|
|
363
|
+
renderSide("trailing", props.trailing),
|
|
364
|
+
]);
|
|
365
|
+
},
|
|
366
|
+
});
|
|
367
|
+
/**
|
|
368
|
+
* Actions behind a row of a list, as the swipe actions of an iOS list: a swipe toward the leading edge reveals the
|
|
369
|
+
* trailing actions, a swipe toward the trailing edge the leading ones, and a full swipe runs the first action of
|
|
370
|
+
* that side. The row is a `data-row` of a FieldGroup. Each action is also a button in the order of the screen, and
|
|
371
|
+
* the focus on one shows its side.
|
|
372
|
+
*/
|
|
373
|
+
export const SwipeActions = SwipeActionsComponent;
|
|
374
|
+
//# sourceMappingURL=SwipeActions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SwipeActions.js","sourceRoot":"","sources":["../../../../src/components/SwipeActions/SwipeActions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC,EAAE,eAAe,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,EAAiC,MAAM,KAAK,CAAA;AACpI,OAAO,CAAC,MAAM,gEAAgE,CAAA;AA8B9E,gGAAgG;AAChG,MAAM,IAAI,GAAG,EAAE,CAAA;AAEf,uGAAuG;AACvG,MAAM,UAAU,GAA0B,EAAE,GAAG,EAAE,YAAY,EAAE,CAAA;AAE/D,uDAAuD;AACvD,MAAM,QAAQ,GAAG,4FAA4F,CAAA;AAgB7G,iFAAiF;AACjF,IAA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AE;YACpB,GAAG,KAAK;YACR,KAAK,EAAE,IAAI;YACX,OAAO,EAAE,CAAC,CAAC,CAAC,YAAY,EAAE,KAAK,CAAC,KAAK,CAAC;YACtC,UAAU,EAAE,EAAE;YACd,oBAAoB,EAAE,EAAE;YACxB,sBAAsB,EAAE,KAAK,CAAC,cAAc;YAC5C,eAAe,EAAE,QAAQ,CAAC,KAAK;YAC/B,cAAc,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS;YAC9C,WAAW,EAAE,aAAa;YAC1B,YAAY,EAAE,cAAc;SAC7B,EAAE;YACD,UAAU,CAAC,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC;YACpC,CAAC,CAAC,KAAK,EAAE;gBACP,OAAO,EAAE,CAAC,CAAC,OAAO;gBAClB,oBAAoB,EAAE,EAAE;gBACxB,OAAO,EAAE,MAAM,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,wBAAwB,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS;gBACvH,eAAe,EAAE,iBAAiB;gBAClC,eAAe,EAAE,iBAAiB;gBAClC,sBAAsB,EAAE,wBAAwB;gBAChD,gBAAgB,EAAE,kBAAkB;aACrC,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;YACrB,UAAU,CAAC,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC;SACvC,CAAC,CAAA;IACJ,CAAC;CACF,CAAC,CAAA;AAOF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,qBAAqB,CAAA","sourcesContent":["import { computed, defineComponent, h, onBeforeUnmount, onMounted, onUpdated, ref, watch, type Component, type PropType } from \"vue\"\nimport s from \"@plexui/styles/components/SwipeActions/SwipeActions.module.css\"\n\n// Vue port of packages/ui/src/components/SwipeActions/SwipeActions.tsx: the same row, sides, gesture, full swipe,\n// keys and focus. The content of the row is the default slot; an action's `Icon` is a component, as in Select.\n\nexport type SwipeActionColor =\n | \"primary\"\n | \"secondary\"\n | \"danger\"\n | \"success\"\n | \"info\"\n | \"discovery\"\n | \"caution\"\n | \"warning\"\n\nexport type SwipeAction = {\n /** Unique ID of the action within its side */\n id: string\n /** Name of the action: shown with `labelPlacement` `\"inside\"` or `\"below\"` (and on an action without an icon), and its accessible name always */\n label: string\n /** Icon of the action */\n Icon?: Component\n /** Solid color of the action. @default \"secondary\" */\n color?: SwipeActionColor\n /** Called when the action is pressed, or by a full swipe when it is the first action of its side */\n onSelect?: () => void\n}\n\nexport type SwipeActionsSide = \"leading\" | \"trailing\"\n\n/** A finger has to travel this far, and farther across than down, before the row follows it. */\nconst SLOP = 10\n\n/** The width an open row moves by is the border box of its actions, edge and content gaps included. */\nconst BORDER_BOX: ResizeObserverOptions = { box: \"border-box\" }\n\n/** Controls that take a horizontal drag themselves. */\nconst OWN_DRAG = 'input, textarea, select, [contenteditable]:not([contenteditable=\"false\"]), [role=\"slider\"]'\n\ntype Gesture = {\n pointerId: number\n x: number\n y: number\n start: number\n /** Undecided while within the slop, then a swipe (true) or a scroll (false). */\n swiping: boolean | undefined\n rtl: boolean\n widths: Record<SwipeActionsSide, number>\n rowWidth: number\n /** Removes the listeners for the end of the gesture. */\n detach: () => void\n}\n\n/** The open row: opening another one closes it, as a list keeps one row open. */\nlet closeOpenRow: (() => void) | null = null\n\n/** The row keeps the finger past its edges; a pointer that is no longer active (it lifted between events) cannot be held. */\nconst capture = (element: Element, pointerId: number) => {\n try {\n element.setPointerCapture?.(pointerId)\n } catch {\n // The swipe goes on with the events the row still gets.\n }\n}\n\nconst sideOf = (offset: number): SwipeActionsSide | undefined =>\n offset > 0 ? \"leading\" : offset < 0 ? \"trailing\" : undefined\n\n/**\n * Where the content goes for a swipe of `raw` px toward the trailing edge (negative: toward the leading edge), and\n * whether that is a full swipe. A side without actions stays shut. Past its actions the content follows the finger\n * where a full swipe is allowed, and a third as fast where it is not; past the middle between the open actions and\n * the far edge of the row the swipe is full.\n */\nexport const swipeActionsOffset = (\n raw: number,\n widths: Record<SwipeActionsSide, number>,\n rowWidth: number,\n fullSwipe: boolean,\n): { offset: number; full: boolean } => {\n const side = sideOf(raw)\n const width = side ? widths[side] : 0\n if (!side || !(width > 0)) return { offset: 0, full: false }\n const sign = Math.sign(raw)\n const distance = Math.abs(raw)\n if (distance <= width) return { offset: raw, full: false }\n if (!fullSwipe) return { offset: sign * (width + (distance - width) / 3), full: false }\n const travel = Math.min(distance, Math.max(width, rowWidth))\n return { offset: sign * travel, full: travel >= (width + rowWidth) / 2 }\n}\n\nconst SwipeActionsComponent = defineComponent({\n name: \"SwipeActions\",\n inheritAttrs: false,\n props: {\n /** Actions revealed by a swipe toward the trailing edge, the first one at the leading edge */\n leading: { type: Array as PropType<SwipeAction[]>, default: () => [] },\n /** Actions revealed by a swipe toward the leading edge, the first one at the trailing edge */\n trailing: { type: Array as PropType<SwipeAction[]>, default: () => [] },\n /** Where the actions show their labels: `\"hidden\"` (symbols only), `\"inside\"` the capsule, or `\"below\"` it (for rows of 68px and taller). @default \"hidden\" */\n labelPlacement: { type: String as PropType<\"hidden\" | \"inside\" | \"below\">, default: \"hidden\" },\n /** A swipe past the middle between the open actions and the far edge runs the first action of that side. @default true */\n fullSwipe: { type: Boolean, default: true },\n },\n setup(props, { attrs, slots }) {\n const offset = ref(0)\n const full = ref(false)\n const swiping = ref(false)\n const rtl = ref(false)\n const root = ref<HTMLElement | null>(null)\n const sides: Record<SwipeActionsSide, HTMLElement | null> = { leading: null, trailing: null }\n let gesture: Gesture | null = null\n let suppressClick = false\n let observer: ResizeObserver | null = null\n const revealed = computed(() => sideOf(offset.value))\n\n const widthOf = (side: SwipeActionsSide) => sides[side]?.getBoundingClientRect().width ?? 0\n\n const isRtl = () => !!root.value && getComputedStyle(root.value).direction === \"rtl\"\n\n const move = (next: number, nextFull = false) => {\n offset.value = next\n full.value = nextFull\n }\n\n /** Lets go of the gesture: the listeners for its end go, and the row no longer follows the finger. */\n const release = () => {\n const state = gesture\n gesture = null\n state?.detach()\n return state\n }\n\n const close = () => {\n if (closeOpenRow === closer) closeOpenRow = null\n move(0)\n }\n\n /** One function for the life of the row, so the list knows which row is open; another row that opens ends this one's gesture too. */\n const closer = () => {\n const state = release()\n if (state) {\n swiping.value = false\n // The finger of the ended swipe still lifts over this row: its click is not a click on the content.\n if (state.swiping) suppressClick = true\n }\n close()\n }\n\n /** This row takes the place of the open one. */\n const claim = () => {\n if (closeOpenRow && closeOpenRow !== closer) closeOpenRow()\n closeOpenRow = closer\n }\n\n /** Shows a side as wide as its actions (`width` when known), or closes the row when that side has none (any more). */\n const open = (side: SwipeActionsSide, width = widthOf(side)) => {\n if (!(width > 0)) return close()\n claim()\n rtl.value = isRtl()\n move(side === \"leading\" ? width : -width)\n }\n\n /** An open row follows its actions: more of them, other labels or another width move it to their new width. */\n const sync = () => {\n const side = sideOf(offset.value)\n if (!side || gesture?.swiping || full.value) return\n const width = widthOf(side)\n if (!(width > 0)) return close()\n const target = side === \"leading\" ? width : -width\n if (target !== offset.value) move(target)\n }\n\n // After each render, and whenever the actions change size, an open row takes their width.\n const observeSides = () => {\n for (const element of [sides.leading, sides.trailing]) if (element) observer?.observe(element, BORDER_BOX)\n }\n onMounted(() => {\n if (typeof ResizeObserver !== \"undefined\") observer = new ResizeObserver(sync)\n observeSides()\n })\n onUpdated(() => {\n sync()\n observeSides()\n })\n\n // A press anywhere outside the open row closes it.\n const handleOutsidePointerDown = (event: PointerEvent) => {\n if (event.target instanceof Node && root.value?.contains(event.target)) return\n close()\n }\n watch([revealed, swiping], ([side, moving]) => {\n document.removeEventListener(\"pointerdown\", handleOutsidePointerDown, true)\n if (side && !moving) document.addEventListener(\"pointerdown\", handleOutsidePointerDown, true)\n })\n\n // The open row lets go of the list, and of the finger, when it goes away.\n onBeforeUnmount(() => {\n document.removeEventListener(\"pointerdown\", handleOutsidePointerDown, true)\n observer?.disconnect()\n observer = null\n release()\n if (closeOpenRow === closer) closeOpenRow = null\n })\n\n const settle = (state: Gesture) => {\n const side = sideOf(offset.value)\n if (!side) return close()\n if (full.value) {\n (side === \"leading\" ? props.leading : props.trailing)[0]?.onSelect?.()\n return close()\n }\n // The widths from the start of the swipe: a full swipe may have stretched the actions since.\n if (Math.abs(offset.value) >= state.widths[side] / 2) open(side, state.widths[side])\n else close()\n }\n\n /** The finger lifted (anywhere): a swipe settles, a press on an open row closes it. */\n const finish = () => {\n const state = release()\n if (!state) return\n if (state.swiping) {\n suppressClick = true\n swiping.value = false\n settle(state)\n } else if (state.start !== 0) {\n if (state.swiping === undefined) suppressClick = true\n close()\n }\n }\n\n /** The browser took the gesture (a scroll) or the row lost the finger: the row goes back to where it was. */\n const cancel = () => {\n const state = release()\n if (!state) return\n swiping.value = false\n const side = sideOf(state.start)\n if (state.swiping && side) open(side, state.widths[side])\n else close()\n }\n\n const handlePointerDown = (event: PointerEvent) => {\n if (event.button !== 0 || gesture) return\n // A new press of the primary pointer starts clean: a swipe that another row ended and that was then cancelled leaves\n // no click to swallow. Another finger's press keeps it, as only the primary pointer clicks.\n if (event.isPrimary) suppressClick = false\n if (props.leading.length < 1 && props.trailing.length < 1) return\n // A drag in a text field or along a slider belongs to that control.\n if (event.target instanceof Element && event.target.closest(OWN_DRAG)) return\n const pointerId = event.pointerId\n // The end of the gesture is heard wherever the finger lifts, inside the row or not.\n const handleUp = (end: PointerEvent) => {\n if (end.pointerId === pointerId) finish()\n }\n const handleCancel = (end: PointerEvent) => {\n if (end.pointerId === pointerId) cancel()\n }\n window.addEventListener(\"pointerup\", handleUp, true)\n window.addEventListener(\"pointercancel\", handleCancel, true)\n gesture = {\n pointerId,\n x: event.clientX,\n y: event.clientY,\n start: offset.value,\n swiping: undefined,\n rtl: isRtl(),\n widths: { leading: widthOf(\"leading\"), trailing: widthOf(\"trailing\") },\n rowWidth: root.value?.clientWidth ?? 0,\n detach: () => {\n window.removeEventListener(\"pointerup\", handleUp, true)\n window.removeEventListener(\"pointercancel\", handleCancel, true)\n },\n }\n }\n\n const handlePointerMove = (event: PointerEvent) => {\n const state = gesture\n if (!state || state.pointerId !== event.pointerId || state.swiping === false) return\n const across = (event.clientX - state.x) * (state.rtl ? -1 : 1)\n const down = event.clientY - state.y\n if (state.swiping === undefined) {\n if (Math.abs(across) < SLOP && Math.abs(down) < SLOP) return\n if (Math.abs(across) <= Math.abs(down)) {\n state.swiping = false\n return\n }\n state.swiping = true\n const target = event.currentTarget\n if (target instanceof Element) capture(target, event.pointerId)\n window.getSelection?.()?.removeAllRanges()\n claim()\n rtl.value = state.rtl\n swiping.value = true\n }\n const next = swipeActionsOffset(state.start + across, state.widths, state.rowWidth, props.fullSwipe)\n move(next.offset, next.full)\n }\n\n /** The content lost the finger it held. A child that loses the finger to the content (as a touch moves its implicit capture) ends nothing. */\n const handleLostPointerCapture = (event: PointerEvent) => {\n if (event.target === event.currentTarget && gesture?.pointerId === event.pointerId) cancel()\n }\n\n /** A swipe or a press that closed the row is not a click on the content; a click from the keys still is. */\n const handleClickCapture = (event: MouseEvent) => {\n if (!suppressClick || event.detail === 0) return\n suppressClick = false\n event.preventDefault()\n event.stopPropagation()\n }\n\n /** The focus on an action shows its side; on the content it closes the row. */\n const handleFocusIn = (event: FocusEvent) => {\n if (gesture?.swiping) return\n const target = event.target\n const side = ([\"leading\", \"trailing\"] as const).find((name) => target instanceof Node && !!sides[name]?.contains(target))\n if (side) {\n if (sideOf(offset.value) !== side) open(side)\n } else if (offset.value !== 0) {\n close()\n }\n }\n\n const handleFocusOut = (event: FocusEvent) => {\n if (gesture?.swiping) return\n if (event.relatedTarget instanceof Node && root.value?.contains(event.relatedTarget)) return\n if (offset.value !== 0) close()\n }\n\n const select = (action: SwipeAction, event: MouseEvent) => {\n action.onSelect?.()\n // A press closes the row, as iOS does. From the keys the action keeps the focus, so its side stays open until\n // the focus leaves the row.\n if (event.detail === 0) return\n const target = event.currentTarget\n if (target instanceof HTMLElement) target.blur()\n close()\n }\n\n const renderSide = (side: SwipeActionsSide, actions: SwipeAction[]) => {\n if (actions.length < 1) return null\n const shown = side === \"leading\" ? actions : [...actions].reverse()\n const isFull = full.value && revealed.value === side\n return h(\"div\", {\n \"ref\": (element: unknown) => {\n sides[side] = element instanceof HTMLElement ? element : null\n },\n \"class\": s.Actions,\n \"data-side\": side,\n \"data-full\": isFull ? \"\" : undefined,\n \"style\": isFull ? { width: `${Math.abs(offset.value)}px` } : undefined,\n }, shown.map((action) => {\n const color = action.color ?? \"secondary\"\n const labelInside = props.labelPlacement === \"inside\" || !action.Icon\n const labelBelow = props.labelPlacement === \"below\" && !!action.Icon\n return h(\"button\", {\n \"key\": action.id,\n \"type\": \"button\",\n \"class\": s.Action,\n \"data-color\": color,\n \"data-first\": action === actions[0] ? \"\" : undefined,\n \"aria-label\": labelInside || labelBelow ? undefined : action.label,\n \"onClick\": (event: MouseEvent) => select(action, event),\n }, [\n h(\"span\", { class: s.Capsule }, [\n action.Icon ? h(action.Icon, { \"class\": s.Icon, \"aria-hidden\": \"true\" }) : null,\n labelInside ? h(\"span\", { class: s.Label }, action.label) : null,\n ]),\n labelBelow ? h(\"span\", { class: s.Caption }, action.label) : null,\n ])\n }))\n }\n\n return () => h(\"div\", {\n ...attrs,\n \"ref\": root,\n \"class\": [s.SwipeActions, attrs.class],\n \"data-row\": \"\",\n \"data-swipe-actions\": \"\",\n \"data-label-placement\": props.labelPlacement,\n \"data-revealed\": revealed.value,\n \"data-swiping\": swiping.value ? \"\" : undefined,\n \"onFocusin\": handleFocusIn,\n \"onFocusout\": handleFocusOut,\n }, [\n renderSide(\"leading\", props.leading),\n h(\"div\", {\n \"class\": s.Content,\n \"data-swipe-content\": \"\",\n \"style\": offset.value !== 0 ? { \"--swipe-actions-offset\": `${rtl.value ? -offset.value : offset.value}px` } : undefined,\n \"onPointerdown\": handlePointerDown,\n \"onPointermove\": handlePointerMove,\n \"onLostpointercapture\": handleLostPointerCapture,\n \"onClickCapture\": handleClickCapture,\n }, slots.default?.()),\n renderSide(\"trailing\", props.trailing),\n ])\n },\n})\n\ntype SwipeActionsOwnProps = InstanceType<typeof SwipeActionsComponent>[\"$props\"]\n\n/** SwipeActions props. */\nexport type SwipeActionsProps = SwipeActionsOwnProps\n\n/**\n * Actions behind a row of a list, as the swipe actions of an iOS list: a swipe toward the leading edge reveals the\n * trailing actions, a swipe toward the trailing edge the leading ones, and a full swipe runs the first action of\n * that side. The row is a `data-row` of a FieldGroup. Each action is also a button in the order of the screen, and\n * the focus on one shows its side.\n */\nexport const SwipeActions = SwipeActionsComponent\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/SwipeActions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,kBAAkB,GAKnB,MAAM,mBAAmB,CAAA","sourcesContent":["export {\n SwipeActions,\n swipeActionsOffset,\n type SwipeAction,\n type SwipeActionColor,\n type SwipeActionsProps,\n type SwipeActionsSide,\n} from \"./SwipeActions.js\"\n"]}
|
|
@@ -127,7 +127,9 @@ const SwitchComponent = defineComponent({
|
|
|
127
127
|
}, {
|
|
128
128
|
default: () => h(ControlButton, {
|
|
129
129
|
"listeners": listeners,
|
|
130
|
-
|
|
130
|
+
// A touch listener lets iOS Safari apply :active, which draws the pressed knob of a phone
|
|
131
|
+
// (Switch.module.css). React listens for touchstart at its root already.
|
|
132
|
+
"after": { onClick: afterClick, onTouchstartPassive: () => { } },
|
|
131
133
|
"drop": ["onKeydown"],
|
|
132
134
|
"id": id,
|
|
133
135
|
"class": s.Track,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Switch.js","sourceRoot":"","sources":["../../../../src/components/Switch/Switch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC,EAAE,SAAS,EAAE,GAAG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AAC,CAAC,KAAK,EAAE;oBACX,CAAC,CAAC,IAAI;aACT,CACF,CAAA;QACH,CAAC,CAAA;IACH,CAAC;CACF,CAAC,CAAA;AAMF,MAAM,CAAC,MAAM,MAAM,GAAG,eAAe,CAAA","sourcesContent":["import { computed, defineComponent, h, onMounted, ref, useId, watch, type PropType } from \"vue\"\nimport { SwitchRoot as RekaSwitchRoot, SwitchThumb as RekaSwitchThumb } from \"reka-ui\"\nimport { bubbleInputStyle, useBubbleInputEffect, useCheckedTracker, useIsFormControl, useSize } from \"../Checkbox/bubbleInput.js\"\nimport { ControlButton, isListener, type Listeners } from \"../Checkbox/ControlButton.js\"\nimport s from \"@plexui/styles/components/Switch/Switch.module.css\"\n\n// Vue port of packages/ui/src/components/Switch/Switch.tsx on Reka UI's\n// Switch (state, role, aria-checked, thumb). Where Reka's DOM differs from\n// Radix's, Radix's is rendered (see the parity tests): no `aria-label`\n// copied from the label text, the hidden form input is Radix's BubbleInput,\n// the consumer's handlers run before the toggle and can cancel it, Enter\n// is left to the browser (a native click), as Radix does, instead of Reka's\n// own Enter toggle, and a form reset restores the initial state.\n\nconst SwitchComponent = defineComponent({\n name: \"Switch\",\n inheritAttrs: false,\n props: {\n /** The `id` of the switch. */\n id: String,\n /** The state of the switch when it is initially rendered. Use when you do not need to control its state. */\n defaultChecked: { type: Boolean, default: undefined },\n /** The controlled state of the switch. Bind with `v-model:checked`. */\n checked: { type: Boolean, default: undefined },\n /** Checked track color. The accent option uses the platform toggle green. @default primary */\n color: { type: String as PropType<\"primary\" | \"accent\">, default: \"primary\" },\n /** Optional accessible label rendered next to the switch. The `label` slot takes rich content. */\n label: String,\n /** Optional description rendered below the label, linked via `aria-describedby`. The `description` slot takes rich content. */\n description: String,\n /** When `true`, prevents the user from interacting with the switch. */\n disabled: { type: Boolean, default: false },\n /** When `true`, indicates that the user must check the switch before the owning form can be submitted. */\n required: { type: Boolean, default: undefined },\n /** The name of the switch. Submitted with its owning form as part of a name/value pair. */\n name: String,\n /** The value given as data when submitted with a `name`. @default \"on\" */\n value: String,\n /** The position of the label relative to the switch. @default \"end\" */\n labelPosition: { type: String as PropType<\"start\" | \"end\">, default: \"end\" },\n },\n emits: {\n /** The state of the switch changed */\n \"update:checked\": (checked: boolean) => typeof checked === \"boolean\",\n /** The switch gained focus */\n focus: (event: FocusEvent) => event.type === \"focus\",\n /** The switch lost focus */\n blur: (event: FocusEvent) => event.type === \"blur\",\n },\n setup(props, { attrs, slots, emit }) {\n const generatedId = useId()\n const container = ref<HTMLDivElement | null>(null)\n const control = ref<HTMLButtonElement | null>(null)\n const bubbleInput = ref<HTMLInputElement | null>(null)\n useCheckedTracker(bubbleInput)\n\n // Radix's useControllableState: controlled while `checked` is set, and\n // only actual changes are reported\n const internalChecked = ref(props.defaultChecked ?? false)\n const checked = computed(() => props.checked ?? internalChecked.value)\n const setChecked = (next: boolean) => {\n if (next === checked.value) return\n if (props.checked === undefined) internalChecked.value = next\n emit(\"update:checked\", next)\n }\n\n const initialChecked = checked.value\n const isFormControl = useIsFormControl(control, () => attrs.form)\n const controlSize = useSize(() => (isFormControl.value ? control.value : null))\n const onUserClick = useBubbleInputEffect(bubbleInput, () => checked.value, false)\n\n onMounted(() => {\n control.value = (container.value?.firstElementChild as HTMLButtonElement | null) ?? null\n })\n\n // radix-ui 1.8: a reset of the switch's form restores the initial state\n watch(control, (button, _, onCleanup) => {\n const formId = attrs.form\n const form = typeof formId === \"string\" ? button?.ownerDocument.getElementById(formId) : button?.form\n if (!(form instanceof HTMLFormElement)) return\n const reset = () => setChecked(initialChecked)\n form.addEventListener(\"reset\", reset)\n onCleanup(() => form.removeEventListener(\"reset\", reset))\n })\n\n // In a form, the button's click stops here; the input's click bubbles instead\n const afterClick = (event: Event) => {\n const hasConsumerStoppedPropagation = event.cancelBubble\n onUserClick({ requestedChecked: !checked.value, hasConsumerStoppedPropagation })\n if (bubbleInput.value && isFormControl.value && !hasConsumerStoppedPropagation) event.stopPropagation()\n }\n\n return () => {\n const { class: className, form, ...rest } = attrs\n const id = props.id ?? generatedId\n const hasLabel = Boolean(slots.label || props.label)\n const hasDescription = Boolean(slots.description || props.description)\n // The description only renders next to a label; it comes before any ids\n // the caller (a Field, say) passes\n const descriptionId = hasLabel && hasDescription ? `${id}-label-description` : undefined\n\n // The consumer's listeners compose with Reka's; other attributes land\n // on the button after the component's own, as `{...restProps}` does\n const listeners: Listeners = {\n onFocus: (event: FocusEvent) => emit(\"focus\", event),\n onBlur: (event: FocusEvent) => emit(\"blur\", event),\n }\n const buttonAttrs: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(rest)) {\n if (isListener(key)) listeners[key] = value\n else buttonAttrs[key] = value\n }\n const ariaDescribedBy =\n [descriptionId, buttonAttrs[\"aria-describedby\"] as string | undefined].filter(Boolean).join(\" \") || undefined\n\n const label = () =>\n h(\"label\", { for: id, class: s.Label }, slots.label ? slots.label() : props.label)\n\n return h(\n \"div\",\n {\n \"ref\": container,\n \"class\": [s.Container, className],\n \"data-color\": props.color,\n \"data-disabled\": props.disabled ? \"\" : undefined,\n \"data-has-label\": hasLabel ? \"\" : undefined,\n \"data-label-position\": props.labelPosition,\n },\n [\n h(\n RekaSwitchRoot as never,\n {\n \"asChild\": true,\n \"modelValue\": checked.value,\n \"onUpdate:modelValue\": setChecked,\n \"disabled\": props.disabled,\n // Passed even when unset, so Reka renders no aria-required=\"false\"\n \"required\": props.required,\n },\n {\n default: () =>\n h(\n ControlButton,\n {\n \"listeners\": listeners,\n \"after\": { onClick: afterClick },\n \"drop\": [\"onKeydown\"],\n \"id\": id,\n \"class\": s.Track,\n \"value\": props.value ?? \"on\",\n ...buttonAttrs,\n \"aria-describedby\": ariaDescribedBy,\n },\n { default: () => h(RekaSwitchThumb, { class: s.Thumb }) },\n ),\n },\n ),\n isFormControl.value\n ? h(\"input\", {\n \"ref\": bubbleInput,\n \"type\": \"checkbox\",\n \"aria-hidden\": \"true\",\n // React's `defaultChecked`: the prop, else the first state\n \"^checked\": (props.defaultChecked ?? initialChecked) ? \"\" : undefined,\n \"name\": props.name,\n \"^value\": props.value ?? \"on\",\n \"required\": props.required,\n \"disabled\": props.disabled,\n \"form\": form,\n \"tabindex\": -1,\n \"style\": bubbleInputStyle(controlSize.value, { transform: \"translateX(-100%)\" }),\n })\n : null,\n hasLabel\n ? hasDescription\n ? h(\"div\", { class: s.LabelGroup }, [\n label(),\n h(\n \"span\",\n { id: descriptionId, class: s.Description },\n slots.description ? slots.description() : props.description,\n ),\n ])\n : label()\n : null,\n ],\n )\n }\n },\n})\n\ntype SwitchOwnProps = InstanceType<typeof SwitchComponent>[\"$props\"]\n\nexport type SwitchProps = SwitchOwnProps\n\nexport const Switch = SwitchComponent\n"]}
|
|
1
|
+
{"version":3,"file":"Switch.js","sourceRoot":"","sources":["../../../../src/components/Switch/Switch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAiB,MAAM,KAAK,CAAA;AAC/F,OAAO,EAAE,UAAU,IAAI,cAAc,EAAE,WAAW,IAAI,eAAe,EAAE,MAAM,SAAS,CAAA;AACtF,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACjI,OAAO,EAAE,aAAa,EAAE,UAAU,EAAkB,MAAM,8BAA8B,CAAA;AACxF,OAAO,CAAC,MAAM,oDAAoD,CAAA;AAElE,wEAAwE;AACxE,2EAA2E;AAC3E,uEAAuE;AACvE,4EAA4E;AAC5E,yEAAyE;AACzE,4EAA4E;AAC5E,iEAAiE;AAEjE,MAAM,eAAe,GAAG,eAAe,CAAC;IACtC,IAAI,EAAE,QAAQ;IACd,YAAY,EAAE,KAAK;IACnB,KAAK,EAAE;QACL,8BAA8B;QAC9B,EAAE,EAAE,MAAM;QACV,4GAA4G;QAC5G,cAAc,EAAE,EAAE,IAAI,E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AAK,CAAC,KAAK,IAAI,IAAI;wBAC7B,UAAU,EAAE,KAAK,CAAC,QAAQ;wBAC1B,UAAU,EAAE,KAAK,CAAC,QAAQ;wBAC1B,MAAM,EAAE,IAAI;wBACZ,UAAU,EAAE,CAAC,CAAC;wBACd,OAAO,EAAE,gBAAgB,CAAC,WAAW,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,mBAAmB,EAAE,CAAC;qBACjF,CAAC;oBACJ,CAAC,CAAC,IAAI;gBACR,QAAQ;oBACN,CAAC,CAAC,cAAc;wBACd,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,UAAU,EAAE,EAAE;4BAChC,KAAK,EAAE;4BACP,CAAC,CACC,MAAM,EACN,EAAE,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,CAAC,WAAW,EAAE,EAC3C,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAC5D;yBACF,CAAC;wBACJ,CAAC,CAAC,KAAK,EAAE;oBACX,CAAC,CAAC,IAAI;aACT,CACF,CAAA;QACH,CAAC,CAAA;IACH,CAAC;CACF,CAAC,CAAA;AAMF,MAAM,CAAC,MAAM,MAAM,GAAG,eAAe,CAAA","sourcesContent":["import { computed, defineComponent, h, onMounted, ref, useId, watch, type PropType } from \"vue\"\nimport { SwitchRoot as RekaSwitchRoot, SwitchThumb as RekaSwitchThumb } from \"reka-ui\"\nimport { bubbleInputStyle, useBubbleInputEffect, useCheckedTracker, useIsFormControl, useSize } from \"../Checkbox/bubbleInput.js\"\nimport { ControlButton, isListener, type Listeners } from \"../Checkbox/ControlButton.js\"\nimport s from \"@plexui/styles/components/Switch/Switch.module.css\"\n\n// Vue port of packages/ui/src/components/Switch/Switch.tsx on Reka UI's\n// Switch (state, role, aria-checked, thumb). Where Reka's DOM differs from\n// Radix's, Radix's is rendered (see the parity tests): no `aria-label`\n// copied from the label text, the hidden form input is Radix's BubbleInput,\n// the consumer's handlers run before the toggle and can cancel it, Enter\n// is left to the browser (a native click), as Radix does, instead of Reka's\n// own Enter toggle, and a form reset restores the initial state.\n\nconst SwitchComponent = defineComponent({\n name: \"Switch\",\n inheritAttrs: false,\n props: {\n /** The `id` of the switch. */\n id: String,\n /** The state of the switch when it is initially rendered. Use when you do not need to control its state. */\n defaultChecked: { type: Boolean, default: undefined },\n /** The controlled state of the switch. Bind with `v-model:checked`. */\n checked: { type: Boolean, default: undefined },\n /** Checked track color. The accent option uses the platform toggle green. @default primary */\n color: { type: String as PropType<\"primary\" | \"accent\">, default: \"primary\" },\n /** Optional accessible label rendered next to the switch. The `label` slot takes rich content. */\n label: String,\n /** Optional description rendered below the label, linked via `aria-describedby`. The `description` slot takes rich content. */\n description: String,\n /** When `true`, prevents the user from interacting with the switch. */\n disabled: { type: Boolean, default: false },\n /** When `true`, indicates that the user must check the switch before the owning form can be submitted. */\n required: { type: Boolean, default: undefined },\n /** The name of the switch. Submitted with its owning form as part of a name/value pair. */\n name: String,\n /** The value given as data when submitted with a `name`. @default \"on\" */\n value: String,\n /** The position of the label relative to the switch. @default \"end\" */\n labelPosition: { type: String as PropType<\"start\" | \"end\">, default: \"end\" },\n },\n emits: {\n /** The state of the switch changed */\n \"update:checked\": (checked: boolean) => typeof checked === \"boolean\",\n /** The switch gained focus */\n focus: (event: FocusEvent) => event.type === \"focus\",\n /** The switch lost focus */\n blur: (event: FocusEvent) => event.type === \"blur\",\n },\n setup(props, { attrs, slots, emit }) {\n const generatedId = useId()\n const container = ref<HTMLDivElement | null>(null)\n const control = ref<HTMLButtonElement | null>(null)\n const bubbleInput = ref<HTMLInputElement | null>(null)\n useCheckedTracker(bubbleInput)\n\n // Radix's useControllableState: controlled while `checked` is set, and\n // only actual changes are reported\n const internalChecked = ref(props.defaultChecked ?? false)\n const checked = computed(() => props.checked ?? internalChecked.value)\n const setChecked = (next: boolean) => {\n if (next === checked.value) return\n if (props.checked === undefined) internalChecked.value = next\n emit(\"update:checked\", next)\n }\n\n const initialChecked = checked.value\n const isFormControl = useIsFormControl(control, () => attrs.form)\n const controlSize = useSize(() => (isFormControl.value ? control.value : null))\n const onUserClick = useBubbleInputEffect(bubbleInput, () => checked.value, false)\n\n onMounted(() => {\n control.value = (container.value?.firstElementChild as HTMLButtonElement | null) ?? null\n })\n\n // radix-ui 1.8: a reset of the switch's form restores the initial state\n watch(control, (button, _, onCleanup) => {\n const formId = attrs.form\n const form = typeof formId === \"string\" ? button?.ownerDocument.getElementById(formId) : button?.form\n if (!(form instanceof HTMLFormElement)) return\n const reset = () => setChecked(initialChecked)\n form.addEventListener(\"reset\", reset)\n onCleanup(() => form.removeEventListener(\"reset\", reset))\n })\n\n // In a form, the button's click stops here; the input's click bubbles instead\n const afterClick = (event: Event) => {\n const hasConsumerStoppedPropagation = event.cancelBubble\n onUserClick({ requestedChecked: !checked.value, hasConsumerStoppedPropagation })\n if (bubbleInput.value && isFormControl.value && !hasConsumerStoppedPropagation) event.stopPropagation()\n }\n\n return () => {\n const { class: className, form, ...rest } = attrs\n const id = props.id ?? generatedId\n const hasLabel = Boolean(slots.label || props.label)\n const hasDescription = Boolean(slots.description || props.description)\n // The description only renders next to a label; it comes before any ids\n // the caller (a Field, say) passes\n const descriptionId = hasLabel && hasDescription ? `${id}-label-description` : undefined\n\n // The consumer's listeners compose with Reka's; other attributes land\n // on the button after the component's own, as `{...restProps}` does\n const listeners: Listeners = {\n onFocus: (event: FocusEvent) => emit(\"focus\", event),\n onBlur: (event: FocusEvent) => emit(\"blur\", event),\n }\n const buttonAttrs: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(rest)) {\n if (isListener(key)) listeners[key] = value\n else buttonAttrs[key] = value\n }\n const ariaDescribedBy =\n [descriptionId, buttonAttrs[\"aria-describedby\"] as string | undefined].filter(Boolean).join(\" \") || undefined\n\n const label = () =>\n h(\"label\", { for: id, class: s.Label }, slots.label ? slots.label() : props.label)\n\n return h(\n \"div\",\n {\n \"ref\": container,\n \"class\": [s.Container, className],\n \"data-color\": props.color,\n \"data-disabled\": props.disabled ? \"\" : undefined,\n \"data-has-label\": hasLabel ? \"\" : undefined,\n \"data-label-position\": props.labelPosition,\n },\n [\n h(\n RekaSwitchRoot as never,\n {\n \"asChild\": true,\n \"modelValue\": checked.value,\n \"onUpdate:modelValue\": setChecked,\n \"disabled\": props.disabled,\n // Passed even when unset, so Reka renders no aria-required=\"false\"\n \"required\": props.required,\n },\n {\n default: () =>\n h(\n ControlButton,\n {\n \"listeners\": listeners,\n // A touch listener lets iOS Safari apply :active, which draws the pressed knob of a phone\n // (Switch.module.css). React listens for touchstart at its root already.\n \"after\": { onClick: afterClick, onTouchstartPassive: () => {} },\n \"drop\": [\"onKeydown\"],\n \"id\": id,\n \"class\": s.Track,\n \"value\": props.value ?? \"on\",\n ...buttonAttrs,\n \"aria-describedby\": ariaDescribedBy,\n },\n { default: () => h(RekaSwitchThumb, { class: s.Thumb }) },\n ),\n },\n ),\n isFormControl.value\n ? h(\"input\", {\n \"ref\": bubbleInput,\n \"type\": \"checkbox\",\n \"aria-hidden\": \"true\",\n // React's `defaultChecked`: the prop, else the first state\n \"^checked\": (props.defaultChecked ?? initialChecked) ? \"\" : undefined,\n \"name\": props.name,\n \"^value\": props.value ?? \"on\",\n \"required\": props.required,\n \"disabled\": props.disabled,\n \"form\": form,\n \"tabindex\": -1,\n \"style\": bubbleInputStyle(controlSize.value, { transform: \"translateX(-100%)\" }),\n })\n : null,\n hasLabel\n ? hasDescription\n ? h(\"div\", { class: s.LabelGroup }, [\n label(),\n h(\n \"span\",\n { id: descriptionId, class: s.Description },\n slots.description ? slots.description() : props.description,\n ),\n ])\n : label()\n : null,\n ],\n )\n }\n },\n})\n\ntype SwitchOwnProps = InstanceType<typeof SwitchComponent>[\"$props\"]\n\nexport type SwitchProps = SwitchOwnProps\n\nexport const Switch = SwitchComponent\n"]}
|
|
@@ -20,7 +20,7 @@ const TabBarItemComponent = defineComponent({
|
|
|
20
20
|
href: String,
|
|
21
21
|
/** When `true`, the tab cannot be selected. */
|
|
22
22
|
disabled: { type: Boolean, default: false },
|
|
23
|
-
/** @internal The search tab
|
|
23
|
+
/** @internal The search and the prominent tab show their symbol only. */
|
|
24
24
|
hideLabel: { type: Boolean, default: false },
|
|
25
25
|
},
|
|
26
26
|
emits: {
|
|
@@ -77,6 +77,13 @@ const TabBarComponent = defineComponent({
|
|
|
77
77
|
defaultValue: { type: String, default: undefined },
|
|
78
78
|
/** A search tab in a glass circle of its own at the trailing end, as the iOS 26 separate search tab. */
|
|
79
79
|
search: { type: Object, default: undefined },
|
|
80
|
+
/**
|
|
81
|
+
* The one destination the app lifts out of the capsule, a cart or a library, in a glass circle of its own at
|
|
82
|
+
* the trailing end, as the iOS 27 prominent tab role; its symbol is the `prominent-icon` slot. It takes the
|
|
83
|
+
* circle of the search tab: with both, search is the last tab of the capsule, as iOS gives search that place
|
|
84
|
+
* only when no other tab is prominent.
|
|
85
|
+
*/
|
|
86
|
+
prominent: { type: Object, default: undefined },
|
|
80
87
|
/**
|
|
81
88
|
* `onScrollDown` minimizes the bar to the selected tab while the content of the `Page` scrolls down and
|
|
82
89
|
* expands it when the content scrolls back up; a tap on the minimized tab expands it too. @default "never"
|
|
@@ -171,20 +178,28 @@ const TabBarComponent = defineComponent({
|
|
|
171
178
|
"data-background": props.background,
|
|
172
179
|
"data-content-below": host?.contentBelow?.value ? "" : undefined,
|
|
173
180
|
"data-minimized": minimized.value ? "" : undefined,
|
|
174
|
-
"data-search": props.search ? "" : undefined,
|
|
181
|
+
"data-search": props.search && !props.prominent ? "" : undefined,
|
|
182
|
+
"data-prominent": props.prominent ? "" : undefined,
|
|
175
183
|
}, [
|
|
176
|
-
h("div", { class: s.Tabs },
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
184
|
+
h("div", { class: s.Tabs }, [
|
|
185
|
+
slots.default?.(),
|
|
186
|
+
props.search && props.prominent
|
|
187
|
+
? h(TabBarItem, { value: props.search.value, label: props.search.label ?? "Search" }, { icon: () => h(SearchIcon) })
|
|
188
|
+
: null,
|
|
189
|
+
]),
|
|
190
|
+
props.prominent
|
|
191
|
+
? h(TabBarItem, { class: s.Prominent, value: props.prominent.value, label: props.prominent.label, hideLabel: true }, { icon: () => slots["prominent-icon"]?.() })
|
|
192
|
+
: props.search
|
|
193
|
+
? h(TabBarItem, { class: s.Search, value: props.search.value, label: props.search.label ?? "Search", hideLabel: true }, { icon: () => h(SearchIcon) })
|
|
194
|
+
: null,
|
|
180
195
|
]);
|
|
181
196
|
},
|
|
182
197
|
});
|
|
183
198
|
/**
|
|
184
199
|
* The tab bar of a phone screen after the iOS 26 kit Tab Bar - iPhone (507:24689): two to five tabs, each a
|
|
185
200
|
* symbol over a label, in a floating glass capsule at the bottom, the selected tab on a pill, and an optional
|
|
186
|
-
* search tab in a circle of its own. It minimizes to the selected tab while the content scrolls
|
|
187
|
-
* layout navigates with a Sidebar or Tabs, so the bar never renders from 768px up.
|
|
201
|
+
* search or prominent tab in a circle of its own. It minimizes to the selected tab while the content scrolls
|
|
202
|
+
* down. A desktop layout navigates with a Sidebar or Tabs, so the bar never renders from 768px up.
|
|
188
203
|
*/
|
|
189
204
|
export const TabBar = TabBarComponent;
|
|
190
205
|
//# sourceMappingURL=TabBar.js.map
|