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