@destyler/dialog 0.0.3 → 0.0.4

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/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # @destyler/dialog
2
+
3
+ [![NPM version](https://img.shields.io/npm/v/@destyler/dialog?color=a1b858&label=)](https://www.npmjs.com/package/@destyler/dialog)
4
+
5
+ > before taking action, please confirm.
6
+
7
+ [GitHub](https://github.com/destyler/destyler) | [Documentation](https://destyler-dev.zeabur.app/)
@@ -1,525 +1,40 @@
1
1
  'use strict';
2
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 { forwardRef, currentElement: contentElement } = composition.useForwardExpose();
126
- vue.onMounted(() => {
127
- rootContext.contentElement = contentElement;
128
- });
129
- return {
130
- rootContext,
131
- forwardRef
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, vue.mergeProps(this.$attrs, {
146
- "ref": (el) => this.forwardRef(el),
147
- "as": this.$props.as,
148
- "asChild": this.$props.asChild,
149
- "role": "dialog",
150
- "aria-describedby": this.rootContext.descriptionId,
151
- "aria-labelledby": this.rootContext.titleId,
152
- "data-state": shared.getOpenState(this.rootContext.open.value),
153
- "isDismissable": true,
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 { forwardRef, currentElement } = composition.useForwardExpose();
183
- composition.useHideOthers(currentElement);
184
- return {
185
- rootContext,
186
- emitsAsProps,
187
- forwardRef
188
- };
189
- },
190
- render() {
191
- return vue.h(DestylerDialogContentImpl, vue.mergeProps(this.$props, this.emitsAsProps, {
192
- "ref": (el) => this.forwardRef(el),
193
- "trap-focus": this.rootContext.open.value,
194
- "disableOutsidePointerEvents": 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
- "disableOutsidePointerEvents": 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
- const { forwardRef } = composition.useForwardExpose();
295
- return {
296
- rootContext,
297
- emitsAsProps,
298
- forwardRef
299
- };
300
- },
301
- render() {
302
- const useVShow = this.rootContext.modal.value;
303
- return vue.h(presence.DestylerPresence, {
304
- present: this.$props.forceMount || this.rootContext.open.value
305
- }, () => [
306
- useVShow ? vue.h(DestylerDialogContentModal, vue.mergeProps(this.$props, this.emitsAsProps, this.$attrs, {
307
- ref: (el) => this.forwardRef(el),
308
- onOpenAutoFocus: (event) => {
309
- this.$emit("openAutoFocus", event);
310
- }
311
- }), () => this.$slots.default?.()) : vue.h(DestylerDialogContentNonModal, vue.mergeProps(this.$props, this.emitsAsProps, this.$attrs, { ref: (el) => this.forwardRef(el) }), () => this.$slots.default?.())
312
- ]);
313
- }
314
- });
315
-
316
- const destylerDialogDescriptionProps = {
317
- asChild: {
318
- type: Boolean,
319
- required: false,
320
- default: false
321
- },
322
- as: {
323
- type: [String, Object],
324
- required: false,
325
- default: "p"
326
- }
327
- };
328
- const DestylerDialogDescription = vue.defineComponent({
329
- name: "DestylerDialogDescription",
330
- props: destylerDialogDescriptionProps,
331
- setup() {
332
- const rootContext = injectDialogRootContext();
333
- return {
334
- rootContext
335
- };
336
- },
337
- render() {
338
- return vue.withDirectives(vue.h(primitive.DestylerPrimitive, {
339
- as: this.$props.as,
340
- asChild: this.$props.asChild
341
- }, () => this.$slots.default?.()), [
342
- [directives.BindOnceDirective, { id: this.rootContext.descriptionId }]
343
- ]);
344
- }
345
- });
346
-
347
- const destylerDialogOverlayImplProps = {
348
- as: {
349
- type: [String, Object],
350
- required: false,
351
- default: "div"
352
- },
353
- asChild: {
354
- type: Boolean,
355
- required: false,
356
- default: false
357
- }
358
- };
359
- const DestylerDialogOverlayImpl = vue.defineComponent({
360
- name: "DestylerDialogOverlayImpl",
361
- props: destylerDialogOverlayImplProps,
362
- setup() {
363
- const rootContext = injectDialogRootContext();
364
- composition.useForwardExpose();
365
- return {
366
- rootContext
367
- };
368
- },
369
- render() {
370
- return vue.h(primitive.DestylerPrimitive, {
371
- "as": this.$props.as,
372
- "asChild": this.$props.asChild,
373
- "data-state": this.rootContext.open.value ? "open" : "closed",
374
- "style": {
375
- "pointer-events": "auto"
376
- }
377
- }, () => this.$slots.default?.());
378
- }
379
- });
380
-
381
- const destylerDialogOverlayProps = {
382
- as: {
383
- type: [String, Object],
384
- required: false,
385
- default: "div"
386
- },
387
- asChild: {
388
- type: Boolean,
389
- required: false,
390
- default: false
391
- },
392
- forceMount: {
393
- type: Boolean,
394
- required: false
395
- }
396
- };
397
- const DestylerDialogOverlay = vue.defineComponent({
398
- name: "DestylerDialogOverlay",
399
- props: destylerDialogOverlayProps,
400
- setup() {
401
- const rootContext = injectDialogRootContext();
402
- const { forwardRef } = composition.useForwardExpose();
403
- return {
404
- rootContext,
405
- forwardRef
406
- };
407
- },
408
- render() {
409
- const useVShow = this.rootContext?.modal.value;
410
- return useVShow ? vue.h(presence.DestylerPresence, {
411
- present: this.$props.forceMount || this.rootContext.open.value
412
- }, () => vue.h(DestylerDialogOverlayImpl, vue.mergeProps(this.$attrs, {
413
- ref: (el) => this.forwardRef(el),
414
- as: this.$props.as,
415
- asChild: this.$props.asChild
416
- }), () => this.$slots.default?.())) : null;
417
- }
418
- });
419
-
420
- const destylerDialogPortalProps = {
421
- as: {
422
- type: [String, Object],
423
- required: false,
424
- default: "div"
425
- },
426
- asChild: {
427
- type: Boolean,
428
- required: false,
429
- default: false
430
- }
431
- };
432
- const DestylerDialogPortal = vue.defineComponent({
433
- name: "DestylerDialogPortal",
434
- props: destylerDialogPortalProps,
435
- render() {
436
- return vue.h(teleport.DestylerTeleport, {}, () => this.$slots.default?.());
437
- }
438
- });
439
-
440
- const destylerDialogTitleProps = {
441
- asChild: {
442
- type: Boolean,
443
- required: false,
444
- default: false
445
- },
446
- as: {
447
- type: [String, Object],
448
- required: false,
449
- default: "h2"
450
- }
451
- };
452
- const DestylerDialogTitle = vue.defineComponent({
453
- name: "DestylerDialogTitle",
454
- props: destylerDialogTitleProps,
455
- setup() {
456
- const rootContext = injectDialogRootContext();
457
- return {
458
- rootContext
459
- };
460
- },
461
- render() {
462
- return vue.withDirectives(vue.h(primitive.DestylerPrimitive, {
463
- as: this.$props.as,
464
- asChild: this.$props.asChild
465
- }, () => this.$slots.default?.()), [
466
- [directives.BindOnceDirective, { id: this.rootContext.titleId }]
467
- ]);
468
- }
469
- });
470
-
471
- const destylerDialogTriggerProps = {
472
- asChild: {
473
- type: Boolean,
474
- required: false,
475
- default: false
476
- },
477
- as: {
478
- type: [String, Object],
479
- required: false,
480
- default: "button"
481
- }
482
- };
483
- const DestylerDialogTrigger = vue.defineComponent({
484
- name: "DestylerDialogTrigger",
485
- props: destylerDialogTriggerProps,
486
- setup() {
487
- const rootContext = injectDialogRootContext();
488
- const { forwardRef, currentElement } = composition.useForwardExpose();
489
- vue.onMounted(() => {
490
- rootContext.triggerElement = currentElement;
491
- });
492
- return {
493
- rootContext,
494
- forwardRef
495
- };
496
- },
497
- render() {
498
- return vue.h(primitive.DestylerPrimitive, vue.mergeProps(this.$attrs, {
499
- "as": this.$props.as,
500
- "asChild": this.$props.asChild,
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.contentId,
506
- "data-state": this.rootContext.open.value ? "open" : "closed",
507
- "onClick": () => {
508
- this.rootContext.onOpenToggle();
509
- }
510
- }), () => this.$slots.default?.());
511
- }
512
- });
513
-
514
- exports.DestylerDialogClose = DestylerDialogClose;
515
- exports.DestylerDialogContent = DestylerDialogContent;
516
- exports.DestylerDialogContentImpl = DestylerDialogContentImpl;
517
- exports.DestylerDialogContentModal = DestylerDialogContentModal;
518
- exports.DestylerDialogContentNonModal = DestylerDialogContentNonModal;
519
- exports.DestylerDialogDescription = DestylerDialogDescription;
520
- exports.DestylerDialogOverlay = DestylerDialogOverlay;
521
- exports.DestylerDialogOverlayImpl = DestylerDialogOverlayImpl;
522
- exports.DestylerDialogPortal = DestylerDialogPortal;
523
- exports.DestylerDialogRoot = DestylerDialogRoot;
524
- exports.DestylerDialogTitle = DestylerDialogTitle;
525
- exports.DestylerDialogTrigger = DestylerDialogTrigger;
3
+ const index = require('./shared/dialog.d09a7a95.cjs');
4
+ require('vue');
5
+ require('@destyler/primitive');
6
+ require('@destyler/composition');
7
+ require('@destyler/shared');
8
+ require('@destyler/presence');
9
+ require('@destyler/focus-scope');
10
+ require('@destyler/dismissable-layer');
11
+ require('@destyler/dismissable-layer/component');
12
+ require('@destyler/directives');
13
+ require('@destyler/teleport');
14
+
15
+
16
+
17
+ exports.DialogClose = index.DialogClose;
18
+ exports.DialogContent = index.DialogContent;
19
+ exports.DialogContentImpl = index.DialogContentImpl;
20
+ exports.DialogContentModal = index.DialogContentModal;
21
+ exports.DialogContentNonModal = index.DialogContentNonModal;
22
+ exports.DialogDescription = index.DialogDescription;
23
+ exports.DialogOverlay = index.DialogOverlay;
24
+ exports.DialogOverlayImpl = index.DialogOverlayImpl;
25
+ exports.DialogPortal = index.DialogPortal;
26
+ exports.DialogRoot = index.DialogRoot;
27
+ exports.DialogTitle = index.DialogTitle;
28
+ exports.DialogTrigger = index.DialogTrigger;
29
+ exports.dialogCloseProps = index.dialogCloseProps;
30
+ exports.dialogContentEmits = index.dialogContentEmits;
31
+ exports.dialogContentImplEmtis = index.dialogContentImplEmtis;
32
+ exports.dialogContentImplProps = index.dialogContentImplProps;
33
+ exports.dialogContentProps = index.dialogContentProps;
34
+ exports.dialogDescriptionProps = index.dialogDescriptionProps;
35
+ exports.dialogOverlayImplProps = index.dialogOverlayImplProps;
36
+ exports.dialogPortalProps = index.dialogPortalProps;
37
+ exports.dialogRootEmits = index.dialogRootEmits;
38
+ exports.dialogRootProps = index.dialogRootProps;
39
+ exports.dialogTitleProps = index.dialogTitleProps;
40
+ exports.dialogTriggerProps = index.dialogTriggerProps;