@destyler/dialog 0.0.1-beta.10

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