@plexui/vue 0.29.1 → 0.31.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/Dialog/Dialog.js +125 -16
- package/dist/es/components/Dialog/Dialog.js.map +1 -1
- package/dist/es/components/Dialog/index.js.map +1 -1
- package/dist/es/components/Page/Page.js +1 -1
- package/dist/es/components/Page/Page.js.map +1 -1
- package/dist/es/components/RadioGroup/RadioGroup.js +3 -1
- package/dist/es/components/RadioGroup/RadioGroup.js.map +1 -1
- package/dist/es/components/Toolbar/Toolbar.js +15 -8
- package/dist/es/components/Toolbar/Toolbar.js.map +1 -1
- package/dist/types/components/Dialog/Dialog.d.ts +12 -4
- package/dist/types/components/Dialog/index.d.ts +1 -1
- package/dist/types/components/FloatingLabelInput/FloatingLabelInput.d.ts +1 -1
- package/dist/types/components/MarkdownEditor/MarkdownEditor.d.ts +2 -2
- package/dist/types/components/Page/Page.d.ts +7 -0
- package/dist/types/components/Textarea/Textarea.d.ts +1 -1
- package/dist/types/components/Toolbar/Toolbar.d.ts +5 -0
- package/package.json +2 -2
|
@@ -15,6 +15,7 @@ import { provideFloatingBoundaryScope, useFloatingBoundaryRegistration } from ".
|
|
|
15
15
|
import { Button } from "../Button/Button.js";
|
|
16
16
|
import { NavigationButton } from "../Button/NavigationButton.js";
|
|
17
17
|
import { Popover, PopoverAnchor, PopoverContent } from "../Popover/Popover.js";
|
|
18
|
+
import { followTitleRows } from "../Page/Page.js";
|
|
18
19
|
import { barBackground, TOOLBAR_HOST, Toolbar, ToolbarLeading, ToolbarTrailing } from "../Toolbar/Toolbar.js";
|
|
19
20
|
import { observeScrollEdges } from "../../lib/scrollEdges.js";
|
|
20
21
|
import s from "@plexui/styles/components/Dialog/Dialog.module.css";
|
|
@@ -191,7 +192,7 @@ export const DialogContent = defineComponent({
|
|
|
191
192
|
* and a phone sheet pulled down all ask first. Pass it while there are changes and leave it out (or `false`) when
|
|
192
193
|
* there are none. Setting `open` to false yourself, such as after Save, closes at once.
|
|
193
194
|
*/
|
|
194
|
-
confirmClose: { type: [Object, Boolean], default: undefined },
|
|
195
|
+
confirmClose: { type: [Object, Boolean, Function], default: undefined },
|
|
195
196
|
/** Stack order of the overlay and the dialog. @default 50 */
|
|
196
197
|
zIndex: Number,
|
|
197
198
|
/** Class, style and data attributes for the fixed layer that holds the panel. Data attributes of DialogContent land here too. */
|
|
@@ -209,9 +210,58 @@ export const DialogContent = defineComponent({
|
|
|
209
210
|
const phoneLayout = computed(() => !!outerPhoneLayout?.phone.value || props.layout === "phone");
|
|
210
211
|
const portalTarget = computed(() => outerPhoneLayout?.container.value ?? null);
|
|
211
212
|
provide(PHONE_LAYOUT_SCOPE, { container: outerPhoneLayout?.container ?? shallowRef(null), phone: phoneLayout });
|
|
212
|
-
|
|
213
|
+
// DialogBody tells the bars that follow the scroll, as a large title does, the body's scroll offset. A large Toolbar
|
|
214
|
+
// title lives at the top of DialogBody, where it scrolls with the body and goes under the bar, which then shows it
|
|
215
|
+
// inline, as on a page; the body keeps a place for it while a title asks for one.
|
|
216
|
+
const scrollListeners = new Set();
|
|
217
|
+
const largeTitleRequests = ref(0);
|
|
218
|
+
const largeTitle = computed(() => largeTitleRequests.value > 0);
|
|
219
|
+
const largeTitleSlot = shallowRef(null);
|
|
220
|
+
const largeTitleRowSlot = shallowRef(null);
|
|
221
|
+
const titleRowsPinned = ref(false);
|
|
222
|
+
const titleRowsHeight = ref(0);
|
|
223
|
+
const bodies = ref(0);
|
|
224
|
+
const scroll = {
|
|
225
|
+
scrolled: ref(false),
|
|
226
|
+
contentBelow: ref(false),
|
|
227
|
+
notifyScroll: (scrollTop) => scrollListeners.forEach((listener) => listener(scrollTop)),
|
|
228
|
+
largeTitle,
|
|
229
|
+
largeTitleSlot,
|
|
230
|
+
largeTitleRowSlot,
|
|
231
|
+
titleRowsPinned,
|
|
232
|
+
titleRowsHeight,
|
|
233
|
+
bodies,
|
|
234
|
+
};
|
|
213
235
|
provide(DIALOG_SCROLL, scroll);
|
|
214
|
-
|
|
236
|
+
const requestLargeTitleSlot = () => {
|
|
237
|
+
largeTitleRequests.value++;
|
|
238
|
+
let released = false;
|
|
239
|
+
return () => { if (!released) {
|
|
240
|
+
released = true;
|
|
241
|
+
largeTitleRequests.value--;
|
|
242
|
+
} };
|
|
243
|
+
};
|
|
244
|
+
// The heights the bars report themselves: a Toolbar inside content of the app's own (a form) is not the panel's child.
|
|
245
|
+
const barHeights = {};
|
|
246
|
+
let measureBars = () => { };
|
|
247
|
+
provide(TOOLBAR_HOST, {
|
|
248
|
+
kind: "dialog",
|
|
249
|
+
setHeight: (placement, height) => { barHeights[placement] = height; measureBars(); },
|
|
250
|
+
scrolled: scroll.scrolled,
|
|
251
|
+
contentBelow: scroll.contentBelow,
|
|
252
|
+
subscribeScroll: (listener) => {
|
|
253
|
+
scrollListeners.add(listener);
|
|
254
|
+
return () => { scrollListeners.delete(listener); };
|
|
255
|
+
},
|
|
256
|
+
// The request stays the same, so with a body the rows mount once, in their place (Codex #68)
|
|
257
|
+
requestLargeTitleSlot,
|
|
258
|
+
// Until the panel has mounted the body may not have told the dialog yet (it comes after the bar): the rows wait
|
|
259
|
+
// for their place rather than mount in the bar first (Codex #69)
|
|
260
|
+
holdsLargeTitle: computed(() => bodies.value > 0 || !panelNode.value),
|
|
261
|
+
largeTitleSlot: computed(() => (largeTitle.value ? largeTitleSlot.value : null)),
|
|
262
|
+
largeTitleRowSlot: computed(() => (largeTitle.value ? largeTitleRowSlot.value : null)),
|
|
263
|
+
rowsPinned: computed(() => largeTitle.value && titleRowsPinned.value),
|
|
264
|
+
});
|
|
215
265
|
// A phone has no other modal view than the sheet and the alert (owner 12.11: «нет такого в iOS»): a centered
|
|
216
266
|
// dialog is an alert, any other a sheet, at the bottom or over the whole screen.
|
|
217
267
|
const mobileVariant = computed(() => props.mobileVariant ?? (props.mobilePlacement === "center" ? "alert" : "sheet"));
|
|
@@ -230,17 +280,34 @@ export const DialogContent = defineComponent({
|
|
|
230
280
|
const closeButton = shallowRef(null);
|
|
231
281
|
// Where focus returns when the question is dismissed: the field or button that asked to close
|
|
232
282
|
let returnFocus = null;
|
|
283
|
+
// The question a function `confirmClose` returned at the last close attempt
|
|
284
|
+
const asked = shallowRef(null);
|
|
285
|
+
// Whether the dialog closed at once (no question to ask)
|
|
233
286
|
const requestClose = () => {
|
|
234
287
|
// A press on a dialog that is already leaving asks nothing
|
|
235
288
|
if (!open.value)
|
|
236
|
-
return;
|
|
237
|
-
|
|
238
|
-
|
|
289
|
+
return false;
|
|
290
|
+
const confirm = props.confirmClose;
|
|
291
|
+
if (!confirm) {
|
|
292
|
+
setOpen(false);
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
239
295
|
if (confirming.value || performance.now() - confirmClosedAt < DOUBLE_CLICK)
|
|
240
|
-
return;
|
|
296
|
+
return false;
|
|
297
|
+
// A function decides at the attempt: the owner commits what is typed, then compares
|
|
298
|
+
if (typeof confirm === "function") {
|
|
299
|
+
const question = confirm();
|
|
300
|
+
if (!question) {
|
|
301
|
+
setOpen(false);
|
|
302
|
+
return true;
|
|
303
|
+
}
|
|
304
|
+
asked.value = question;
|
|
305
|
+
}
|
|
241
306
|
returnFocus = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
242
307
|
setConfirming(true);
|
|
308
|
+
return false;
|
|
243
309
|
};
|
|
310
|
+
const question = () => (typeof props.confirmClose === "function" ? asked.value : props.confirmClose || null);
|
|
244
311
|
const setCloseButton = (button) => { closeButton.value = button; };
|
|
245
312
|
// The answer that discards: the question leaves first, then the dialog, as iOS dismisses the confirmation before
|
|
246
313
|
// the sheet; together, the question would stand still over the sheet as it leaves.
|
|
@@ -269,6 +336,15 @@ export const DialogContent = defineComponent({
|
|
|
269
336
|
rootContext.contentId ||= useId(undefined, "reka-dialog-content");
|
|
270
337
|
// Reka replaces the root's content ref as it mounts, so the layer is found from the panel once it is in place
|
|
271
338
|
const panelNode = shallowRef(null);
|
|
339
|
+
// The bar's background reaches under the pinned rows by their height, as on a page
|
|
340
|
+
watch([panelNode, titleRowsHeight], ([panel, height]) => {
|
|
341
|
+
if (!panel)
|
|
342
|
+
return;
|
|
343
|
+
if (height > 0)
|
|
344
|
+
panel.style.setProperty("--page-toolbar-rows-height", `${height}px`);
|
|
345
|
+
else
|
|
346
|
+
panel.style.removeProperty("--page-toolbar-rows-height");
|
|
347
|
+
}, { flush: "post" });
|
|
272
348
|
let stopViewport;
|
|
273
349
|
watch([panelNode, portalTarget], ([panel, box]) => {
|
|
274
350
|
stopViewport?.();
|
|
@@ -373,10 +449,8 @@ export const DialogContent = defineComponent({
|
|
|
373
449
|
const request = new CustomEvent("dialog.sheetDrag", { cancelable: true, detail: { originalEvent } });
|
|
374
450
|
if (ownerKeepsOpen(request))
|
|
375
451
|
return false;
|
|
376
|
-
if (props.confirmClose)
|
|
377
|
-
requestClose();
|
|
378
|
-
return false;
|
|
379
|
-
}
|
|
452
|
+
if (props.confirmClose)
|
|
453
|
+
return requestClose();
|
|
380
454
|
setOpen(false);
|
|
381
455
|
return true;
|
|
382
456
|
};
|
|
@@ -402,6 +476,7 @@ export const DialogContent = defineComponent({
|
|
|
402
476
|
detachDrag?.();
|
|
403
477
|
barObserver?.disconnect();
|
|
404
478
|
barChildren?.disconnect();
|
|
479
|
+
measureBars = () => { };
|
|
405
480
|
detachDrag = undefined;
|
|
406
481
|
panelElement = element;
|
|
407
482
|
panelNode.value = element ?? null;
|
|
@@ -415,9 +490,10 @@ export const DialogContent = defineComponent({
|
|
|
415
490
|
?? element.querySelector(`:scope > ${TOP_TOOLBAR}`)
|
|
416
491
|
?? element.querySelector(`:scope > .${s.Header}`);
|
|
417
492
|
const footer = element.querySelector(`:scope > ${BOTTOM_TOOLBAR}`) ?? element.querySelector(`:scope > .${s.Footer}`);
|
|
418
|
-
element.style.setProperty("--dialog-header-height", `${header?.offsetHeight ?? 0}px`);
|
|
419
|
-
element.style.setProperty("--dialog-footer-height", `${footer?.offsetHeight ?? 0}px`);
|
|
493
|
+
element.style.setProperty("--dialog-header-height", `${header?.offsetHeight ?? barHeights.top ?? 0}px`);
|
|
494
|
+
element.style.setProperty("--dialog-footer-height", `${footer?.offsetHeight ?? barHeights.bottom ?? 0}px`);
|
|
420
495
|
};
|
|
496
|
+
measureBars = update;
|
|
421
497
|
barObserver = typeof ResizeObserver !== "undefined" ? new ResizeObserver(update) : undefined;
|
|
422
498
|
const observeBars = () => {
|
|
423
499
|
barObserver?.disconnect();
|
|
@@ -508,7 +584,7 @@ export const DialogContent = defineComponent({
|
|
|
508
584
|
slots.default?.(),
|
|
509
585
|
props.confirmClose
|
|
510
586
|
? h(ConfirmClose, {
|
|
511
|
-
...
|
|
587
|
+
...(question() ?? { message: null }),
|
|
512
588
|
open: confirming.value,
|
|
513
589
|
anchor: (phoneWindow.value || phoneLayout.value) && mobileVariant.value === "sheet" ? closeButton.value : null,
|
|
514
590
|
returnFocus: () => returnFocus,
|
|
@@ -665,7 +741,34 @@ export const DialogBody = defineComponent({
|
|
|
665
741
|
scroll.contentBelow.value = false;
|
|
666
742
|
}
|
|
667
743
|
});
|
|
668
|
-
|
|
744
|
+
const setLargeTitleSlot = (slot) => {
|
|
745
|
+
if (scroll)
|
|
746
|
+
scroll.largeTitleSlot.value = slot instanceof HTMLElement ? slot : null;
|
|
747
|
+
};
|
|
748
|
+
const setLargeTitleRowSlot = (slot) => {
|
|
749
|
+
if (scroll)
|
|
750
|
+
scroll.largeTitleRowSlot.value = slot instanceof HTMLElement ? slot : null;
|
|
751
|
+
};
|
|
752
|
+
// The dialog moves a large title here only while a body is there
|
|
753
|
+
if (scroll)
|
|
754
|
+
scroll.bodies.value++;
|
|
755
|
+
onBeforeUnmount(() => { if (scroll)
|
|
756
|
+
scroll.bodies.value--; });
|
|
757
|
+
// The rows of a large title's bar pin under it once scrolled up to it, as on a page
|
|
758
|
+
let stopRows;
|
|
759
|
+
if (scroll) {
|
|
760
|
+
watch([element, scroll.largeTitleRowSlot], ([body, rows]) => {
|
|
761
|
+
stopRows?.();
|
|
762
|
+
stopRows = body && rows
|
|
763
|
+
? followTitleRows(body, rows, (pinned, height) => { scroll.titleRowsPinned.value = pinned; scroll.titleRowsHeight.value = height; })
|
|
764
|
+
: undefined;
|
|
765
|
+
}, { flush: "post" });
|
|
766
|
+
}
|
|
767
|
+
onBeforeUnmount(() => { stopRows?.(); stopRows = undefined; });
|
|
768
|
+
return () => h("div", { ref: element, class: [s.Body, attrs.class], onScroll: scroll ? (event) => scroll.notifyScroll(event.currentTarget.scrollTop) : undefined }, [
|
|
769
|
+
// A large Toolbar title starts the body and scrolls with it; the description comes under it
|
|
770
|
+
scroll?.largeTitle.value ? h("div", { ref: setLargeTitleSlot, class: s.LargeTitle }) : null,
|
|
771
|
+
scroll?.largeTitle.value ? h("div", { ref: setLargeTitleRowSlot, class: s.LargeTitleRows }) : null,
|
|
669
772
|
sheet?.value && phone.value ? h("div", { ref: setDescriptionSlot, class: s.SheetDescriptionSlot }) : null,
|
|
670
773
|
slots.default?.(),
|
|
671
774
|
]);
|
|
@@ -779,6 +882,7 @@ const ConfirmClose = defineComponent({
|
|
|
779
882
|
name: "DialogConfirmClose",
|
|
780
883
|
props: {
|
|
781
884
|
message: { type: null, required: true },
|
|
885
|
+
detail: { type: null, default: undefined },
|
|
782
886
|
confirmLabel: { type: null, default: "Discard Changes" },
|
|
783
887
|
cancelLabel: { type: null, default: "Keep Editing" },
|
|
784
888
|
open: { type: Boolean, default: false },
|
|
@@ -796,6 +900,7 @@ const ConfirmClose = defineComponent({
|
|
|
796
900
|
const setOpen = (next) => emit("update:open", next);
|
|
797
901
|
const confirm = () => emit("confirm");
|
|
798
902
|
const messageId = useId(undefined, "plex-confirm-close");
|
|
903
|
+
const hasDetail = () => props.detail != null && props.detail !== false;
|
|
799
904
|
return () => {
|
|
800
905
|
const anchor = props.anchor;
|
|
801
906
|
if (anchor) {
|
|
@@ -816,6 +921,7 @@ const ConfirmClose = defineComponent({
|
|
|
816
921
|
"data-dialog-confirm-close": "",
|
|
817
922
|
}, () => [
|
|
818
923
|
h("p", { id: messageId, class: s.ConfirmCloseMessage }, [props.message]),
|
|
924
|
+
hasDetail() ? h("p", { class: s.ConfirmCloseDetail }, [props.detail]) : null,
|
|
819
925
|
h(Button, { block: true, pill: true, color: "danger", variant: "soft", class: s.ConfirmCloseAction, onClick: confirm }, () => props.confirmLabel),
|
|
820
926
|
]),
|
|
821
927
|
]);
|
|
@@ -837,7 +943,10 @@ const ConfirmClose = defineComponent({
|
|
|
837
943
|
},
|
|
838
944
|
}, () => [
|
|
839
945
|
// The question names the alert, as an alert's title does
|
|
840
|
-
h(DialogHeader, null, () => [
|
|
946
|
+
h(DialogHeader, null, () => [
|
|
947
|
+
h(DialogTitle, null, () => props.message),
|
|
948
|
+
hasDetail() ? h(DialogDescription, null, () => props.detail) : null,
|
|
949
|
+
]),
|
|
841
950
|
h(DialogFooter, null, () => [
|
|
842
951
|
h(DialogClose, null, () => [h(Button, { color: "secondary", variant: "soft" }, () => props.cancelLabel)]),
|
|
843
952
|
h(Button, { color: "danger", onClick: confirm }, () => props.confirmLabel),
|