@destyler/dialog 0.0.6 → 0.0.7-beta.2

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.
@@ -1,514 +0,0 @@
1
- import { defineComponent, ref, toRefs, h, mergeProps, onMounted, withDirectives } from 'vue';
2
- import { primitiveProps, Primitive } from '@destyler/primitive';
3
- import { useVModel, useForwardExpose, useId, useEmitAsProps, useHideOthers } from '@destyler/composition';
4
- import { createContext, getOpenState } from '@destyler/shared';
5
- import { Presence } from '@destyler/presence';
6
- import { FocusScope } from '@destyler/focus-scope';
7
- import { DismissableLayer } from '@destyler/dismissable-layer';
8
- import { dismissableLayerProps, dismissableLayerEmits } from '@destyler/dismissable-layer/component';
9
- import { BindOnceDirective } from '@destyler/directives';
10
- import { teleportPrimitiveProps, TeleportPrimitive } from '@destyler/teleport';
11
-
12
- const dialogRootProps = {
13
- /**
14
- * The controlled open state of the dialog. Can be binded as `v-model:open`.
15
- *
16
- * @default undefined
17
- */
18
- open: {
19
- type: Boolean,
20
- required: false,
21
- default: void 0
22
- },
23
- /**
24
- * The open state of the dialog when it is initially rendered.
25
- * Use when you do not need to control its open state.
26
- *
27
- * @default false
28
- */
29
- defaultOpen: {
30
- type: Boolean,
31
- required: false,
32
- default: false
33
- },
34
- /**
35
- * The modality of the dialog When set to true,
36
- * interaction with outside elements will be
37
- * disabled and only dialog content will
38
- * be visible to screen readers.
39
- *
40
- * @default true
41
- */
42
- modal: {
43
- type: Boolean,
44
- required: false,
45
- default: true
46
- }
47
- };
48
- const [injectDialogRootContext, provideDialogRootContext] = createContext("DestylerDialogRoot");
49
- const dialogRootEmits = {
50
- /**
51
- * Event handler called when the open state of the dialog changes.
52
- */
53
- "update:open": (_value) => true
54
- };
55
- const DialogRoot = defineComponent({
56
- name: "DestylerDialogRoot",
57
- props: dialogRootProps,
58
- emits: dialogRootEmits,
59
- setup(props, { emit }) {
60
- const open = useVModel(props, "open", emit, {
61
- defaultValue: props.defaultOpen,
62
- passive: props.open === void 0
63
- });
64
- const triggerElement = ref();
65
- const contentElement = ref();
66
- const { modal } = toRefs(props);
67
- provideDialogRootContext({
68
- open,
69
- modal,
70
- openModal: () => {
71
- open.value = true;
72
- },
73
- onOpenChange: (value) => {
74
- open.value = value;
75
- },
76
- onOpenToggle: () => {
77
- open.value = !open.value;
78
- },
79
- contentId: "",
80
- titleId: "",
81
- descriptionId: "",
82
- triggerElement,
83
- contentElement
84
- });
85
- },
86
- render() {
87
- return this.$slots.default?.();
88
- }
89
- });
90
-
91
- const dialogCloseProps = {
92
- ...primitiveProps,
93
- /**
94
- * @default button
95
- */
96
- as: {
97
- ...primitiveProps.as,
98
- default: "button"
99
- }
100
- };
101
- const DialogClose = defineComponent({
102
- name: "DestylerDialogClose",
103
- props: dialogCloseProps,
104
- setup() {
105
- const rootContext = injectDialogRootContext();
106
- useForwardExpose();
107
- return {
108
- rootContext
109
- };
110
- },
111
- render() {
112
- return h(Primitive, mergeProps(this.$props, {
113
- type: this.$props.as === "button" ? "button" : void 0,
114
- onClick: () => {
115
- this.rootContext.onOpenChange(false);
116
- }
117
- }), () => this.$slots.default?.());
118
- }
119
- });
120
-
121
- const dialogContentImplProps = {
122
- ...dismissableLayerProps,
123
- /**
124
- * Used to force mounting when more control is needed.
125
- * Useful when controlling animation with Vue animation libraries.
126
- *
127
- * @default false
128
- */
129
- forceMount: {
130
- type: Boolean,
131
- required: false
132
- },
133
- /**
134
- * When `true`, focus cannot escape the Content via keyboard,
135
- * pointer, or a programmatic focus.
136
- *
137
- * @default false
138
- */
139
- trapFocus: {
140
- type: Boolean,
141
- required: false,
142
- default: false
143
- }
144
- };
145
- const dialogContentImplEmtis = {
146
- ...dismissableLayerEmits,
147
- /**
148
- * Event handler called when auto-focusing on open. Can be prevented.
149
- */
150
- openAutoFocus: (_event) => true,
151
- /**
152
- * Event handler called when the a `pointerdown` event happens
153
- * outside of the `DismissableLayer`. Can be prevented.
154
- */
155
- closeAutoFocus: (_event) => true
156
- };
157
- const DialogContentImpl = defineComponent({
158
- name: "DestylerDialogContentImpl",
159
- props: dialogContentImplProps,
160
- emits: dialogContentImplEmtis,
161
- setup() {
162
- const rootContext = injectDialogRootContext();
163
- const { forwardRef, currentElement: contentElement } = useForwardExpose();
164
- rootContext.titleId || (rootContext.titleId = useId(void 0, "destyler-dialog-title"));
165
- rootContext.descriptionId || (rootContext.descriptionId = useId(void 0, "destyler-dialog-description"));
166
- onMounted(() => {
167
- rootContext.contentElement = contentElement;
168
- });
169
- return {
170
- rootContext,
171
- forwardRef
172
- };
173
- },
174
- render() {
175
- return h(FocusScope, {
176
- asChild: true,
177
- loop: true,
178
- trapped: this.$props.trapFocus,
179
- onMountAutoFocus: (event) => {
180
- this.$emit("openAutoFocus", event);
181
- },
182
- onUnmountAutoFocus: (event) => {
183
- this.$emit("closeAutoFocus", event);
184
- }
185
- }, () => withDirectives(h(DismissableLayer, mergeProps(this.$attrs, {
186
- "ref": (el) => this.forwardRef(el),
187
- "as": this.$props.as,
188
- "asChild": this.$props.asChild,
189
- "disableOutsidePointerEvents": this.$props.disableOutsidePointerEvents,
190
- "role": "dialog",
191
- "aria-describedby": this.rootContext.descriptionId,
192
- "aria-labelledby": this.rootContext.titleId,
193
- "data-state": getOpenState(this.rootContext.open.value),
194
- "isDismissable": true,
195
- "onDismiss": () => {
196
- this.rootContext.onOpenChange(false);
197
- },
198
- "onEscapeKeyDown": (event) => {
199
- this.$emit("escapeKeyDown", event);
200
- },
201
- "onFocusOutside": (event) => {
202
- this.$emit("focusOutside", event);
203
- },
204
- "onInteractOutside": (event) => {
205
- this.$emit("interactOutside", event);
206
- },
207
- "onPointerDownOutside": (event) => {
208
- this.$emit("pointerDownOutside", event);
209
- }
210
- }), () => this.$slots.default?.()), [
211
- [BindOnceDirective, { id: this.rootContext.contentId }]
212
- ]));
213
- }
214
- });
215
-
216
- const DialogContentModal = defineComponent({
217
- name: "DestylerDialogContentModal",
218
- props: dialogContentImplProps,
219
- emits: dialogContentImplEmtis,
220
- setup(_, { emit }) {
221
- const rootContext = injectDialogRootContext();
222
- const emitsAsProps = useEmitAsProps(emit);
223
- const { forwardRef, currentElement } = useForwardExpose();
224
- useHideOthers(currentElement);
225
- return {
226
- rootContext,
227
- emitsAsProps,
228
- forwardRef
229
- };
230
- },
231
- render() {
232
- return h(DialogContentImpl, mergeProps(this.$props, this.emitsAsProps, {
233
- "ref": (el) => this.forwardRef(el),
234
- "trap-focus": this.rootContext.open.value,
235
- "disableOutsidePointerEvents": true,
236
- "onCloseAutoFocus": (event) => {
237
- this.$emit("closeAutoFocus", event);
238
- if (!event.defaultPrevented) {
239
- event.preventDefault();
240
- this.rootContext.triggerElement.value?.focus();
241
- }
242
- },
243
- "onPointerDownOutside": (event) => {
244
- const originalEvent = event.detail.originalEvent;
245
- const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
246
- const isRightClick = originalEvent.button === 2 || ctrlLeftClick;
247
- if (isRightClick)
248
- event.preventDefault();
249
- },
250
- "onFocusOutside": (event) => {
251
- event.preventDefault();
252
- },
253
- "onOpenAutoFocus": (event) => {
254
- this.$emit("openAutoFocus", event);
255
- }
256
- }), () => this.$slots.default?.());
257
- }
258
- });
259
-
260
- const DialogContentNonModal = defineComponent({
261
- name: "DestylerDialogContentNonModal",
262
- props: dialogContentImplProps,
263
- emits: dialogContentImplEmtis,
264
- setup(_, { emit }) {
265
- const rootContext = injectDialogRootContext();
266
- const hasInteractedOutsideRef = ref(false);
267
- const hasPointerDownOutsideRef = ref(false);
268
- const emitsAsProps = useEmitAsProps(emit);
269
- return {
270
- rootContext,
271
- hasInteractedOutsideRef,
272
- hasPointerDownOutsideRef,
273
- emitsAsProps
274
- };
275
- },
276
- render() {
277
- return h(DialogContentImpl, mergeProps(this.$props, this.emitsAsProps, {
278
- "trap-focus": false,
279
- "disableOutsidePointerEvents": false,
280
- "onCloseAutoFocus": (event) => {
281
- this.$emit("closeAutoFocus", event);
282
- if (!event.defaultPrevented) {
283
- if (!this.hasInteractedOutsideRef)
284
- this.rootContext.triggerElement.value?.focus();
285
- event.preventDefault();
286
- }
287
- this.hasInteractedOutsideRef = false;
288
- this.hasPointerDownOutsideRef = false;
289
- },
290
- "onInteractOutside": (event) => {
291
- if (!event.defaultPrevented) {
292
- this.hasInteractedOutsideRef = true;
293
- if (event.detail.originalEvent.type === "pointerdown")
294
- this.hasPointerDownOutsideRef = true;
295
- }
296
- const target = event.target;
297
- const targetIsTrigger = this.rootContext.triggerElement.value?.contains(target);
298
- if (targetIsTrigger)
299
- event.preventDefault();
300
- if (event.detail.originalEvent.type === "focusin" && this.hasPointerDownOutsideRef)
301
- event.preventDefault();
302
- }
303
- }), () => this.$slots.default?.());
304
- }
305
- });
306
-
307
- const dialogContentProps = {
308
- ...dialogContentImplProps
309
- };
310
- const dialogContentEmits = {
311
- ...dialogContentImplEmtis
312
- };
313
- const DialogContent = defineComponent({
314
- name: "DestylerDialogContent",
315
- props: dialogContentProps,
316
- emits: dialogContentEmits,
317
- setup(_, { emit }) {
318
- const rootContext = injectDialogRootContext();
319
- const emitsAsProps = useEmitAsProps(emit);
320
- const { forwardRef } = useForwardExpose();
321
- return {
322
- rootContext,
323
- emitsAsProps,
324
- forwardRef
325
- };
326
- },
327
- render() {
328
- const useVShow = this.$props.forceMount || this.rootContext.modal.value;
329
- return h(Presence, {
330
- present: this.$props.forceMount || this.rootContext.open.value
331
- }, () => [
332
- useVShow ? h(DialogContentModal, mergeProps(this.$props, this.emitsAsProps, this.$attrs, {
333
- ref: (el) => this.forwardRef(el),
334
- onOpenAutoFocus: (event) => {
335
- this.$emit("openAutoFocus", event);
336
- }
337
- }), () => this.$slots.default?.()) : h(DialogContentNonModal, mergeProps(this.$props, this.emitsAsProps, this.$attrs, {
338
- ref: (el) => this.forwardRef(el)
339
- }), () => this.$slots.default?.())
340
- ]);
341
- }
342
- });
343
-
344
- const dialogDescriptionProps = {
345
- ...primitiveProps,
346
- /**
347
- * @default p
348
- */
349
- as: {
350
- ...primitiveProps.as,
351
- default: "p"
352
- }
353
- };
354
- const DialogDescription = defineComponent({
355
- name: "DestylerDialogDescription",
356
- props: dialogDescriptionProps,
357
- setup() {
358
- const rootContext = injectDialogRootContext();
359
- useForwardExpose();
360
- return {
361
- rootContext
362
- };
363
- },
364
- render() {
365
- return withDirectives(h(Primitive, {
366
- as: this.$props.as,
367
- asChild: this.$props.asChild
368
- }, () => this.$slots.default?.()), [
369
- [BindOnceDirective, { id: this.rootContext.descriptionId }]
370
- ]);
371
- }
372
- });
373
-
374
- const dialogOverlayImplProps = {
375
- ...primitiveProps
376
- };
377
- const DialogOverlayImpl = defineComponent({
378
- name: "DestylerDialogOverlayImpl",
379
- props: dialogOverlayImplProps,
380
- setup() {
381
- const rootContext = injectDialogRootContext();
382
- useForwardExpose();
383
- return {
384
- rootContext
385
- };
386
- },
387
- render() {
388
- return h(Primitive, {
389
- "as": this.$props.as,
390
- "asChild": this.$props.asChild,
391
- "data-state": this.rootContext.open.value ? "open" : "closed",
392
- "style": {
393
- "pointer-events": "auto"
394
- }
395
- }, () => this.$slots.default?.());
396
- }
397
- });
398
-
399
- const dialogOverlayProps = {
400
- ...primitiveProps,
401
- /**
402
- * Used to force mounting when more control is needed.
403
- * Useful when controlling animation with Vue animation libraries.
404
- */
405
- forceMount: {
406
- type: Boolean,
407
- required: false
408
- }
409
- };
410
- const DialogOverlay = defineComponent({
411
- name: "DestylerDialogOverlay",
412
- props: dialogOverlayProps,
413
- setup() {
414
- const rootContext = injectDialogRootContext();
415
- const { forwardRef } = useForwardExpose();
416
- return {
417
- rootContext,
418
- forwardRef
419
- };
420
- },
421
- render() {
422
- const useVShow = this.rootContext?.modal.value;
423
- return useVShow ? h(Presence, {
424
- present: this.$props.forceMount || this.rootContext.open.value
425
- }, () => h(DialogOverlayImpl, mergeProps(this.$attrs, {
426
- ref: (el) => this.forwardRef(el),
427
- as: this.$props.as,
428
- asChild: this.$props.asChild
429
- }), () => this.$slots.default?.())) : null;
430
- }
431
- });
432
-
433
- const dialogPortalProps = {
434
- ...teleportPrimitiveProps
435
- };
436
- const DialogPortal = defineComponent({
437
- name: "DestylerDialogPortal",
438
- props: dialogPortalProps,
439
- render() {
440
- return h(TeleportPrimitive, mergeProps(this.$props), () => this.$slots.default?.());
441
- }
442
- });
443
-
444
- const dialogTitleProps = {
445
- ...primitiveProps,
446
- /**
447
- * @default h2
448
- */
449
- as: {
450
- ...primitiveProps.as,
451
- default: "h2"
452
- }
453
- };
454
- const DialogTitle = defineComponent({
455
- name: "DestylerDialogTitle",
456
- props: dialogTitleProps,
457
- setup() {
458
- useForwardExpose();
459
- const rootContext = injectDialogRootContext();
460
- return {
461
- rootContext
462
- };
463
- },
464
- render() {
465
- return withDirectives(h(Primitive, {
466
- as: this.$props.as,
467
- asChild: this.$props.asChild
468
- }, () => this.$slots.default?.()), [
469
- [BindOnceDirective, { id: this.rootContext.titleId }]
470
- ]);
471
- }
472
- });
473
-
474
- const dialogTriggerProps = {
475
- ...primitiveProps,
476
- /**
477
- * @default button
478
- */
479
- as: {
480
- ...primitiveProps.as,
481
- default: "button"
482
- }
483
- };
484
- const DialogTrigger = defineComponent({
485
- name: "DestylerDialogTrigger",
486
- props: dialogTriggerProps,
487
- setup() {
488
- const rootContext = injectDialogRootContext();
489
- const { forwardRef, currentElement } = useForwardExpose();
490
- rootContext.contentId || (rootContext.contentId = useId(void 0, "destyler-dialog-content"));
491
- onMounted(() => {
492
- rootContext.triggerElement = currentElement;
493
- });
494
- return {
495
- rootContext,
496
- forwardRef
497
- };
498
- },
499
- render() {
500
- return h(Primitive, mergeProps(this.$attrs, this.$props, {
501
- "ref": (el) => this.forwardRef(el),
502
- "type": this.$props.as === "button" ? "button" : void 0,
503
- "aria-haspopup": "dialog",
504
- "aria-expanded": this.rootContext.open.value || false,
505
- "aria-controls": this.rootContext.open.value ? this.rootContext.contentId : void 0,
506
- "data-state": this.rootContext.open.value ? "open" : "closed",
507
- "onClick": () => {
508
- this.rootContext.onOpenToggle();
509
- }
510
- }), () => this.$slots.default?.());
511
- }
512
- });
513
-
514
- export { DialogClose as D, DialogContent as a, dialogContentProps as b, DialogDescription as c, dialogCloseProps as d, dialogDescriptionProps as e, DialogOverlay as f, dialogOverlayProps as g, DialogPortal as h, dialogPortalProps as i, DialogRoot as j, dialogRootProps as k, DialogTitle as l, dialogTitleProps as m, DialogTrigger as n, dialogTriggerProps as o, dialogContentEmits as p, DialogContentImpl as q, dialogContentImplEmtis as r, dialogContentImplProps as s, DialogContentModal as t, DialogContentNonModal as u, DialogOverlayImpl as v, dialogOverlayImplProps as w, dialogRootEmits as x };