@plexui/vue 0.28.0 → 0.29.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 +178 -5
- package/dist/es/components/Dialog/Dialog.js.map +1 -1
- package/dist/es/components/Dialog/index.js.map +1 -1
- package/dist/es/components/Field/Field.js +2 -0
- package/dist/es/components/Field/Field.js.map +1 -1
- package/dist/es/components/FileUpload/FileUpload.js +13 -3
- package/dist/es/components/FileUpload/FileUpload.js.map +1 -1
- package/dist/es/components/Icon/index.js +2 -0
- package/dist/es/components/Icon/index.js.map +1 -1
- package/dist/es/components/Icon/svg/ZoomIn.js +12 -0
- package/dist/es/components/Icon/svg/ZoomIn.js.map +1 -0
- package/dist/es/components/Icon/svg/ZoomOut.js +11 -0
- package/dist/es/components/Icon/svg/ZoomOut.js.map +1 -0
- package/dist/es/components/Popover/Popover.js +41 -0
- package/dist/es/components/Popover/Popover.js.map +1 -1
- package/dist/es/components/Popover/index.js +1 -1
- package/dist/es/components/Popover/index.js.map +1 -1
- package/dist/es/components/Slider/Slider.js +17 -2
- package/dist/es/components/Slider/Slider.js.map +1 -1
- package/dist/es/components/Sortable/Sortable.js +6 -0
- package/dist/es/components/Sortable/Sortable.js.map +1 -1
- package/dist/es/components/Sortable/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/lib/sortable.js +16 -4
- package/dist/es/lib/sortable.js.map +1 -1
- package/dist/types/components/Dialog/Dialog.d.ts +33 -1
- package/dist/types/components/Dialog/index.d.ts +1 -1
- package/dist/types/components/Field/Field.d.ts +4 -1
- package/dist/types/components/FileUpload/FileUpload.d.ts +42 -0
- package/dist/types/components/Icon/index.d.ts +2 -0
- package/dist/types/components/Icon/svg/ZoomIn.d.ts +3 -0
- package/dist/types/components/Icon/svg/ZoomOut.d.ts +3 -0
- package/dist/types/components/Popover/Popover.d.ts +30 -0
- package/dist/types/components/Popover/index.d.ts +1 -1
- package/dist/types/components/Sortable/Sortable.d.ts +24 -2
- package/dist/types/components/Sortable/index.d.ts +1 -1
- package/dist/types/lib/sortable.d.ts +3 -0
- package/package.json +2 -2
|
@@ -12,7 +12,9 @@ import { enterStep, leaveStep, releaseStepHeight, settleStepHeight, STEP_TIMING
|
|
|
12
12
|
import { PHONE_LAYOUT as PHONE_LAYOUT_SCOPE } from "../PhoneLayout/PhoneLayout.js";
|
|
13
13
|
import { overlayTiming, overlayTimingLarge } from "../Transition/shared.js";
|
|
14
14
|
import { provideFloatingBoundaryScope, useFloatingBoundaryRegistration } from "../../composables/useFloatingBoundary.js";
|
|
15
|
+
import { Button } from "../Button/Button.js";
|
|
15
16
|
import { NavigationButton } from "../Button/NavigationButton.js";
|
|
17
|
+
import { Popover, PopoverAnchor, PopoverContent } from "../Popover/Popover.js";
|
|
16
18
|
import { barBackground, TOOLBAR_HOST, Toolbar, ToolbarLeading, ToolbarTrailing } from "../Toolbar/Toolbar.js";
|
|
17
19
|
import { observeScrollEdges } from "../../lib/scrollEdges.js";
|
|
18
20
|
import s from "@plexui/styles/components/Dialog/Dialog.module.css";
|
|
@@ -22,6 +24,8 @@ const DIALOG_SCROLL = Symbol("DialogScroll");
|
|
|
22
24
|
const DIALOG_SHEET = Symbol("DialogSheet");
|
|
23
25
|
// Inside that bar: the title, the description and the header actions take the Toolbar's parts
|
|
24
26
|
const DIALOG_BAR = Symbol("DialogBar");
|
|
27
|
+
// A close that asks first (`confirmClose`): DialogClose inside the content asks as the Close button does
|
|
28
|
+
const DIALOG_REQUEST_CLOSE = Symbol("DialogRequestClose");
|
|
25
29
|
const DIALOG_DESCRIPTION_SLOT = Symbol("DialogDescriptionSlot");
|
|
26
30
|
// The phone layout of the Dialog style sheet (its rules for the Sheet's bar use the same query). A dialog's content
|
|
27
31
|
// mounts on the client only (its portal waits for the document), so it reads the layout as it mounts, with nothing to
|
|
@@ -182,6 +186,12 @@ export const DialogContent = defineComponent({
|
|
|
182
186
|
* iOS sheet does under `isModalInPresentation`), or for a press on a developer panel over the page.
|
|
183
187
|
*/
|
|
184
188
|
onInteractOutside: Function,
|
|
189
|
+
/**
|
|
190
|
+
* Asks before the dialog closes, as a form with unsaved changes does: Close, DialogClose, Escape, a press outside
|
|
191
|
+
* and a phone sheet pulled down all ask first. Pass it while there are changes and leave it out (or `false`) when
|
|
192
|
+
* there are none. Setting `open` to false yourself, such as after Save, closes at once.
|
|
193
|
+
*/
|
|
194
|
+
confirmClose: { type: [Object, Boolean], default: undefined },
|
|
185
195
|
/** Stack order of the overlay and the dialog. @default 50 */
|
|
186
196
|
zIndex: Number,
|
|
187
197
|
/** Class, style and data attributes for the fixed layer that holds the panel. Data attributes of DialogContent land here too. */
|
|
@@ -206,7 +216,47 @@ export const DialogContent = defineComponent({
|
|
|
206
216
|
// dialog is an alert, any other a sheet, at the bottom or over the whole screen.
|
|
207
217
|
const mobileVariant = computed(() => props.mobileVariant ?? (props.mobilePlacement === "center" ? "alert" : "sheet"));
|
|
208
218
|
const phoneWindow = usePhoneLayout();
|
|
209
|
-
|
|
219
|
+
// A close asked for while there are changes waits for the answer (`confirmClose`). A press that dismisses the
|
|
220
|
+
// question itself does not ask again: one just after the question closed is that press.
|
|
221
|
+
const confirming = ref(false);
|
|
222
|
+
let confirmClosedAt = 0;
|
|
223
|
+
const setConfirming = (next) => {
|
|
224
|
+
if (confirming.value && !next)
|
|
225
|
+
confirmClosedAt = performance.now();
|
|
226
|
+
confirming.value = next;
|
|
227
|
+
};
|
|
228
|
+
watch([open, () => props.confirmClose], ([isOpen, confirm]) => { if (!isOpen || !confirm)
|
|
229
|
+
setConfirming(false); });
|
|
230
|
+
const closeButton = shallowRef(null);
|
|
231
|
+
// Where focus returns when the question is dismissed: the field or button that asked to close
|
|
232
|
+
let returnFocus = null;
|
|
233
|
+
const requestClose = () => {
|
|
234
|
+
// A press on a dialog that is already leaving asks nothing
|
|
235
|
+
if (!open.value)
|
|
236
|
+
return;
|
|
237
|
+
if (!props.confirmClose)
|
|
238
|
+
return setOpen(false);
|
|
239
|
+
if (confirming.value || performance.now() - confirmClosedAt < DOUBLE_CLICK)
|
|
240
|
+
return;
|
|
241
|
+
returnFocus = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
242
|
+
setConfirming(true);
|
|
243
|
+
};
|
|
244
|
+
const setCloseButton = (button) => { closeButton.value = button; };
|
|
245
|
+
// The answer that discards: the question leaves first, then the dialog, as iOS dismisses the confirmation before
|
|
246
|
+
// the sheet; together, the question would stand still over the sheet as it leaves.
|
|
247
|
+
let confirmTimer;
|
|
248
|
+
onBeforeUnmount(() => clearTimeout(confirmTimer));
|
|
249
|
+
// A close from outside, or a new opening, ends a discard that is still waiting for the question to leave
|
|
250
|
+
watch(open, () => clearTimeout(confirmTimer));
|
|
251
|
+
const confirmAndClose = () => {
|
|
252
|
+
setConfirming(false);
|
|
253
|
+
clearTimeout(confirmTimer);
|
|
254
|
+
confirmTimer = setTimeout(() => setOpen(false), overlayTiming.exitDuration);
|
|
255
|
+
};
|
|
256
|
+
provide(DIALOG_REQUEST_CLOSE, computed(() => (props.confirmClose ? requestClose : null)));
|
|
257
|
+
provide(DIALOG_SHEET, computed(() => (mobileVariant.value === "sheet"
|
|
258
|
+
? { showClose: props.showClose, asksToClose: Boolean(props.confirmClose), requestClose, setCloseButton }
|
|
259
|
+
: null)));
|
|
210
260
|
// A dialog opened from a header action is not inside that header's bar
|
|
211
261
|
provide(DIALOG_BAR, computed(() => false));
|
|
212
262
|
provide(DIALOG_DESCRIPTION_SLOT, { body: shallowRef(null), own: shallowRef(null) });
|
|
@@ -257,7 +307,7 @@ export const DialogContent = defineComponent({
|
|
|
257
307
|
if (request.defaultPrevented)
|
|
258
308
|
return;
|
|
259
309
|
}
|
|
260
|
-
|
|
310
|
+
requestClose();
|
|
261
311
|
});
|
|
262
312
|
// The second click of a double click lands on the overlay: it must not undo the first
|
|
263
313
|
let openedAt = 0;
|
|
@@ -273,13 +323,16 @@ export const DialogContent = defineComponent({
|
|
|
273
323
|
if (ownerKeepsOpen(request))
|
|
274
324
|
return;
|
|
275
325
|
if (!originalEvent.ctrlKey && performance.now() - openedAt >= DOUBLE_CLICK)
|
|
276
|
-
|
|
326
|
+
requestClose();
|
|
277
327
|
}, () => rootContext.contentElement.value);
|
|
278
328
|
const handlePointerDownOutside = (event) => {
|
|
279
329
|
// The native modal owner outlives logical open. An exiting layer must not
|
|
280
330
|
// start a deferred dismissal that closes a trigger-driven reopen.
|
|
281
331
|
if (!open.value)
|
|
282
332
|
return event.preventDefault();
|
|
333
|
+
// A press that dismisses the question before a close keeps editing
|
|
334
|
+
if (confirming.value)
|
|
335
|
+
return event.preventDefault();
|
|
283
336
|
// A press in a toast is not outside: the toast region is a layer above the dialog. The Toaster stops it
|
|
284
337
|
// before Reka sees it; this holds when the Toaster mounted after the dialog.
|
|
285
338
|
if (inToastRegion(event.detail.originalEvent.target))
|
|
@@ -288,6 +341,16 @@ export const DialogContent = defineComponent({
|
|
|
288
341
|
const { originalEvent } = event.detail;
|
|
289
342
|
if (originalEvent.button === 0 && originalEvent.pointerType !== "touch")
|
|
290
343
|
return outsidePress.onPointerDownOutside(event);
|
|
344
|
+
// With changes a touch or another button asks too, and Reka does not close on it
|
|
345
|
+
if (props.confirmClose) {
|
|
346
|
+
// The owner's veto first: it reads the event's own defaultPrevented
|
|
347
|
+
const kept = ownerKeepsOpen(event);
|
|
348
|
+
event.preventDefault();
|
|
349
|
+
// A right click (button 2, or Control and a click on a Mac) is not a dismissal, as Reka and React hold (Codex #58)
|
|
350
|
+
if (!kept && !originalEvent.ctrlKey && originalEvent.button !== 2)
|
|
351
|
+
requestClose();
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
291
354
|
if (!ownerKeepsOpen(event))
|
|
292
355
|
outsidePress.onPointerDownOutside(event);
|
|
293
356
|
};
|
|
@@ -298,6 +361,11 @@ export const DialogContent = defineComponent({
|
|
|
298
361
|
outsidePress.onFocusOutside(event);
|
|
299
362
|
if (!event.defaultPrevented)
|
|
300
363
|
props.onInteractOutside?.(event);
|
|
364
|
+
// With changes focus leaving asks, as React's interact-outside does; Reka does not close on it
|
|
365
|
+
if (!event.defaultPrevented && props.confirmClose) {
|
|
366
|
+
event.preventDefault();
|
|
367
|
+
requestClose();
|
|
368
|
+
}
|
|
301
369
|
};
|
|
302
370
|
// A sheet pulled down asks as a press outside does: an owner that keeps the dialog open on one, such as a form
|
|
303
371
|
// with unsaved changes, keeps it on the other, and the sheet returns.
|
|
@@ -305,6 +373,10 @@ export const DialogContent = defineComponent({
|
|
|
305
373
|
const request = new CustomEvent("dialog.sheetDrag", { cancelable: true, detail: { originalEvent } });
|
|
306
374
|
if (ownerKeepsOpen(request))
|
|
307
375
|
return false;
|
|
376
|
+
if (props.confirmClose) {
|
|
377
|
+
requestClose();
|
|
378
|
+
return false;
|
|
379
|
+
}
|
|
308
380
|
setOpen(false);
|
|
309
381
|
return true;
|
|
310
382
|
};
|
|
@@ -434,6 +506,17 @@ export const DialogContent = defineComponent({
|
|
|
434
506
|
})
|
|
435
507
|
: null,
|
|
436
508
|
slots.default?.(),
|
|
509
|
+
props.confirmClose
|
|
510
|
+
? h(ConfirmClose, {
|
|
511
|
+
...props.confirmClose,
|
|
512
|
+
open: confirming.value,
|
|
513
|
+
anchor: (phoneWindow.value || phoneLayout.value) && mobileVariant.value === "sheet" ? closeButton.value : null,
|
|
514
|
+
returnFocus: () => returnFocus,
|
|
515
|
+
"onUpdate:open": setConfirming,
|
|
516
|
+
onConfirm: confirmAndClose,
|
|
517
|
+
zIndex: props.zIndex,
|
|
518
|
+
})
|
|
519
|
+
: null,
|
|
437
520
|
])),
|
|
438
521
|
],
|
|
439
522
|
}),
|
|
@@ -508,7 +591,15 @@ export const DialogHeader = defineComponent({
|
|
|
508
591
|
// A step's Back takes the leading place, as the back button of a screen pushed inside an iOS sheet
|
|
509
592
|
sheet?.value?.showClose && !parts.some(isLeadingAction)
|
|
510
593
|
? h(ToolbarLeading, { class: s.BarClose }, () => [
|
|
511
|
-
|
|
594
|
+
sheet.value?.asksToClose
|
|
595
|
+
? h(NavigationButton, {
|
|
596
|
+
"ref": (instance) => sheet.value?.setCloseButton(elementOf(instance)),
|
|
597
|
+
"action": "close",
|
|
598
|
+
"variant": "ghost",
|
|
599
|
+
"aria-label": "Close dialog",
|
|
600
|
+
"onClick": () => sheet.value?.requestClose(),
|
|
601
|
+
})
|
|
602
|
+
: h(DialogClose, null, { default: () => [h(NavigationButton, { "action": "close", "variant": "ghost", "aria-label": "Close dialog" })] }),
|
|
512
603
|
])
|
|
513
604
|
: null,
|
|
514
605
|
...parts.filter(isLeadingAction),
|
|
@@ -667,13 +758,95 @@ export const DialogClose = defineComponent({
|
|
|
667
758
|
name: "DialogClose",
|
|
668
759
|
setup(_props, { slots }) {
|
|
669
760
|
const rootContext = injectDialogRootContext();
|
|
761
|
+
const requestClose = inject(DIALOG_REQUEST_CLOSE, null);
|
|
670
762
|
const onClick = (event) => {
|
|
671
|
-
if (
|
|
763
|
+
if (event.defaultPrevented)
|
|
764
|
+
return;
|
|
765
|
+
const request = requestClose?.value;
|
|
766
|
+
if (request)
|
|
767
|
+
request();
|
|
768
|
+
else
|
|
672
769
|
rootContext.onOpenChange(false);
|
|
673
770
|
};
|
|
674
771
|
return () => withDialogProps(firstElementChild(slots.default?.()), { type: "button" }, onClick);
|
|
675
772
|
},
|
|
676
773
|
});
|
|
774
|
+
const elementOf = (instance) => instance instanceof HTMLElement ? instance : (instance?.$el instanceof HTMLElement ? instance.$el : null);
|
|
775
|
+
// iOS asks at the button that closes (a confirmation dialog presented from the sheet's Close on iOS 27: a glass
|
|
776
|
+
// popover over it, no dimming, the question in 17 regular over a full-width destructive pill); with no such button,
|
|
777
|
+
// and on a desktop, the question is an alert.
|
|
778
|
+
const ConfirmClose = defineComponent({
|
|
779
|
+
name: "DialogConfirmClose",
|
|
780
|
+
props: {
|
|
781
|
+
message: { type: null, required: true },
|
|
782
|
+
confirmLabel: { type: null, default: "Discard Changes" },
|
|
783
|
+
cancelLabel: { type: null, default: "Keep Editing" },
|
|
784
|
+
open: { type: Boolean, default: false },
|
|
785
|
+
/** The phone Sheet's Close: the question stands at it. Without one it is an alert. */
|
|
786
|
+
anchor: { type: Object, default: null },
|
|
787
|
+
returnFocus: { type: Function, required: true },
|
|
788
|
+
/** The owner dialog's stack order: the question stands over it */
|
|
789
|
+
zIndex: Number,
|
|
790
|
+
},
|
|
791
|
+
emits: {
|
|
792
|
+
"update:open": (open) => typeof open === "boolean",
|
|
793
|
+
confirm: () => true,
|
|
794
|
+
},
|
|
795
|
+
setup(props, { emit }) {
|
|
796
|
+
const setOpen = (next) => emit("update:open", next);
|
|
797
|
+
const confirm = () => emit("confirm");
|
|
798
|
+
const messageId = useId(undefined, "plex-confirm-close");
|
|
799
|
+
return () => {
|
|
800
|
+
const anchor = props.anchor;
|
|
801
|
+
if (anchor) {
|
|
802
|
+
return h(Popover, { "open": props.open, "onUpdate:open": setOpen }, () => [
|
|
803
|
+
h(PopoverAnchor, { element: anchor }),
|
|
804
|
+
// Over the Close, its corner 6 before the button's, as the native confirmation grows out of it
|
|
805
|
+
h(PopoverContent, {
|
|
806
|
+
"side": "bottom",
|
|
807
|
+
"align": "start",
|
|
808
|
+
"sideOffset": -anchor.offsetHeight,
|
|
809
|
+
"alignOffset": -6,
|
|
810
|
+
"collisionPadding": 10,
|
|
811
|
+
"width": 240,
|
|
812
|
+
"minWidth": 240,
|
|
813
|
+
"zIndex": props.zIndex,
|
|
814
|
+
"ariaLabelledby": messageId,
|
|
815
|
+
"class": s.ConfirmClose,
|
|
816
|
+
"data-dialog-confirm-close": "",
|
|
817
|
+
}, () => [
|
|
818
|
+
h("p", { id: messageId, class: s.ConfirmCloseMessage }, [props.message]),
|
|
819
|
+
h(Button, { block: true, pill: true, color: "danger", variant: "soft", class: s.ConfirmCloseAction, onClick: confirm }, () => props.confirmLabel),
|
|
820
|
+
]),
|
|
821
|
+
]);
|
|
822
|
+
}
|
|
823
|
+
return h(Dialog, { "open": props.open, "onUpdate:open": setOpen }, () => [
|
|
824
|
+
h(DialogContent, {
|
|
825
|
+
"mobileVariant": "alert",
|
|
826
|
+
"surface": "plain",
|
|
827
|
+
"width": 360,
|
|
828
|
+
"showClose": false,
|
|
829
|
+
"zIndex": props.zIndex,
|
|
830
|
+
"data-dialog-confirm-close": "",
|
|
831
|
+
"onCloseAutoFocus": (event) => {
|
|
832
|
+
const target = props.returnFocus();
|
|
833
|
+
if (target?.isConnected) {
|
|
834
|
+
event.preventDefault();
|
|
835
|
+
target.focus({ preventScroll: true });
|
|
836
|
+
}
|
|
837
|
+
},
|
|
838
|
+
}, () => [
|
|
839
|
+
// The question names the alert, as an alert's title does
|
|
840
|
+
h(DialogHeader, null, () => [h(DialogTitle, null, () => props.message)]),
|
|
841
|
+
h(DialogFooter, null, () => [
|
|
842
|
+
h(DialogClose, null, () => [h(Button, { color: "secondary", variant: "soft" }, () => props.cancelLabel)]),
|
|
843
|
+
h(Button, { color: "danger", onClick: confirm }, () => props.confirmLabel),
|
|
844
|
+
]),
|
|
845
|
+
]),
|
|
846
|
+
]);
|
|
847
|
+
};
|
|
848
|
+
},
|
|
849
|
+
});
|
|
677
850
|
/** The steps of a flow inside a dialog, such as a sign-in that asks for an email and then a code. */
|
|
678
851
|
export const DialogSteps = defineComponent({
|
|
679
852
|
name: "DialogSteps",
|