@destyler/popover 0.0.1-beta.8 → 0.0.1

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.mjs CHANGED
@@ -1,386 +1,11 @@
1
- import { defineComponent, toRef, ref, h, onBeforeMount, onUnmounted, mergeProps, withDirectives, onMounted } from 'vue';
2
- import { DestylerPopperRoot, destylerPopperArrowProps, DestylerPopperAnchor, DestylerPopperArrow, destylerPopperContentProps, DestylerPopperContent } from '@destyler/popper';
3
- import { createContext } from '@destyler/shared';
4
- import { useVModel, useId, useForwardProps, useFocusGuards, useForwardPropsEmits, useCustomElement, useHideOthers } from '@destyler/composition';
5
- import { destylerPrimitiveProp, DestylerPrimitive } from '@destyler/primitive';
6
- import { DestylerPresence } from '@destyler/presence';
7
- import { destylerDismissableLayerProps, DestylerDismissableLayer } from '@destyler/dismissable-layer';
8
- import { DestylerFocusScope } from '@destyler/focus-scope';
9
- import { BindOnceDirective } from '@destyler/directives';
10
- import { destylerTeleportProps, DestylerTeleport } from '@destyler/teleport';
11
-
12
- const [injectPopoverRootContext, providePopoverRootContext] = createContext("DestylerPopoverRoot");
13
- const destylerPopoverRootProps = {
14
- defaultOpen: {
15
- type: Boolean,
16
- required: false,
17
- default: false
18
- },
19
- open: {
20
- type: Boolean,
21
- required: false,
22
- default: void 0
23
- },
24
- modal: {
25
- type: Boolean,
26
- required: false,
27
- default: false
28
- }
29
- };
30
- const DestylerPopoverRoot = defineComponent({
31
- name: "DestylerPopoverRoot",
32
- props: destylerPopoverRootProps,
33
- emits: ["update:open"],
34
- setup(props, { emit }) {
35
- const modalRef = toRef(props.modal);
36
- const openRef = useVModel(props, "open", emit, {
37
- defaultValue: props.defaultOpen,
38
- passive: props.open === void 0
39
- });
40
- const triggerElement = ref();
41
- const hasCustomAnchor = ref(false);
42
- function handleUpdateOpen(value) {
43
- openRef.value = value;
44
- }
45
- providePopoverRootContext({
46
- contentId: useId(),
47
- modal: modalRef,
48
- open: openRef,
49
- onOpenChange: (value) => {
50
- handleUpdateOpen(value);
51
- },
52
- onOpenToggle: () => {
53
- handleUpdateOpen(!openRef.value);
54
- },
55
- triggerElement,
56
- hasCustomAnchor
57
- });
58
- return {
59
- openRef,
60
- modalRef,
61
- triggerElement,
62
- hasCustomAnchor
63
- };
64
- },
65
- render() {
66
- return h(DestylerPopperRoot, this.$slots.default?.());
67
- }
68
- });
69
-
70
- const destylerPopoverAnchorProps = {
71
- ...destylerPopperArrowProps
72
- };
73
- const DestylerPopoverAnchor = defineComponent({
74
- name: "DestylerPopoverAnchor",
75
- props: destylerPopoverAnchorProps,
76
- setup() {
77
- const rootContext = injectPopoverRootContext();
78
- onBeforeMount(() => {
79
- rootContext.hasCustomAnchor.value = true;
80
- });
81
- onUnmounted(() => {
82
- rootContext.hasCustomAnchor.value = false;
83
- });
84
- },
85
- render() {
86
- return h(DestylerPopperAnchor, mergeProps(this.$props, {}), this.$slots.default?.());
87
- }
88
- });
89
-
90
- const destylerPopoverArrowProps = {
91
- ...destylerPopperArrowProps
92
- };
93
- const DestylerPopoverArrow = defineComponent({
94
- name: "DestylerPopoverArrow",
95
- props: destylerPopoverArrowProps,
96
- render() {
97
- return h(DestylerPopperArrow, mergeProps(this.$props, {}), this.$slots.default?.());
98
- }
99
- });
100
-
101
- const destylerPopoverCloseProps = {
102
- ...destylerPrimitiveProp,
103
- as: {
104
- type: [String, Object],
105
- required: false,
106
- default: "button"
107
- }
108
- };
109
- const DestylerPopoverClose = defineComponent({
110
- name: "DestylerPopoverClose",
111
- props: destylerPopoverCloseProps,
112
- setup() {
113
- const rootContext = injectPopoverRootContext();
114
- return {
115
- rootContext
116
- };
117
- },
118
- render() {
119
- return h(DestylerPrimitive, {
120
- as: this.$props.as,
121
- asChild: this.$props.asChild,
122
- type: this.$props.as === "button" ? "button" : void 0,
123
- onClick: () => {
124
- this.rootContext.onOpenChange(false);
125
- }
126
- }, this.$slots.default?.());
127
- }
128
- });
129
-
130
- const destylerPopoverContentImplProps = {
131
- ...destylerPopperContentProps,
132
- ...destylerDismissableLayerProps,
133
- trapFocus: {
134
- type: Boolean,
135
- required: false,
136
- default: false
137
- }
138
- };
139
- const destylerPopoverContentImplEmits = ["escapeKeyDown", "pointerDownOutside", "focusOutside", "interactOutside", "dismiss", "openAutoFocus", "closeAutoFocus"];
140
- const DestylerPopoverContentImpl = defineComponent({
141
- name: "DestylerPopoverContentImpl",
142
- props: destylerPopoverContentImplProps,
143
- emits: destylerPopoverContentImplEmits,
144
- setup(props) {
145
- const forwarded = useForwardProps(props);
146
- const rootContext = injectPopoverRootContext();
147
- useFocusGuards();
148
- return {
149
- rootContext,
150
- forwarded
151
- };
152
- },
153
- render() {
154
- return h(DestylerFocusScope, {
155
- asChild: this.$props.asChild,
156
- loop: true,
157
- trapped: this.$props.trapFocus,
158
- onMountAutoFocus: (event) => {
159
- this.$emit("openAutoFocus", event);
160
- },
161
- onUnmountAutoFocus: (event) => {
162
- this.$emit("closeAutoFocus", event);
163
- }
164
- }, h(DestylerDismissableLayer, {
165
- asChild: this.$props.asChild,
166
- disableOutsidePointerEvents: this.$props.disableOutsidePointerEvents,
167
- onPointerDownOutside: (event) => {
168
- this.$emit("pointerDownOutside", event);
169
- },
170
- onInteractOutside: (event) => {
171
- this.$emit("interactOutside", event);
172
- },
173
- onEscapeKeyDown: (event) => {
174
- this.$emit("escapeKeyDown", event);
175
- },
176
- onFocusOutside: (event) => {
177
- this.$emit("focusOutside", event);
178
- },
179
- onDismiss: () => {
180
- this.rootContext.onOpenChange(false);
181
- }
182
- }, withDirectives(h(DestylerPopperContent, mergeProps(this.forwarded, {
183
- "data-state": this.rootContext.open.value ? "open" : "closed",
184
- "role": "dialog",
185
- "style": {
186
- "--destyler_popover_content_transform_origin": "var(--destyler_popper_transform_origin)",
187
- "--destyler_popover_content_available_width": "var(--destyler_popper_available_width)",
188
- "--destyler_popover_content_available_height": "var(--destyler_popper_available_height)",
189
- "--destyler_popover_trigger_width": "var(--destyler_popper_anchor_width)",
190
- "--destyler_popover_trigger_height": "var(--destyler_popper_anchor_height)"
191
- }
192
- }), this.$slots.default?.()), [
193
- [BindOnceDirective, { id: this.rootContext.contentId }]
194
- ])));
195
- }
196
- });
197
-
198
- const DestylerPopoverContentModal = defineComponent({
199
- name: "DestylerPopoverContentModal",
200
- props: destylerPopoverContentImplProps,
201
- emits: destylerPopoverContentImplEmits,
202
- setup(props, { emit }) {
203
- const rootContext = injectPopoverRootContext();
204
- const isRightClickOutsideRef = ref(false);
205
- const forwarded = useForwardPropsEmits(props, emit);
206
- const { customElement, currentElement } = useCustomElement();
207
- useHideOthers(currentElement);
208
- return {
209
- rootContext,
210
- forwarded,
211
- isRightClickOutsideRef,
212
- customElement
213
- };
214
- },
215
- render() {
216
- return h(DestylerPopoverContentImpl, {
217
- "ref": "customElement",
218
- ...mergeProps(this.forwarded),
219
- "trapFocus": this.rootContext.open.value,
220
- "disable-outside-pointer-events": "",
221
- "onCloseAutoFocusPrevent": (event) => {
222
- this.$emit("closeAutoFocus", event);
223
- if (!this.isRightClickOutsideRef)
224
- this.rootContext.triggerElement.value?.focus();
225
- },
226
- "onPointerDownOutside": (event) => {
227
- this.$emit("pointerDownOutside", event);
228
- const originalEvent = event.detail.originalEvent;
229
- const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
230
- const isRightClick = originalEvent.button === 2 || ctrlLeftClick;
231
- this.isRightClickOutsideRef = isRightClick;
232
- }
233
- }, this.$slots.default?.());
234
- }
235
- });
236
-
237
- const DestylerPopoverContentNonModal = defineComponent({
238
- name: "DestylerPopoverContentNonModal",
239
- props: destylerPopoverContentImplProps,
240
- emits: destylerPopoverContentImplEmits,
241
- setup(props, { emit }) {
242
- const rootContext = injectPopoverRootContext();
243
- const hasInteractedOutsideRef = ref(false);
244
- const hasPointerDownOutsideRef = ref(false);
245
- const forwarded = useForwardPropsEmits(props, emit);
246
- return {
247
- forwarded,
248
- rootContext,
249
- hasInteractedOutsideRef,
250
- hasPointerDownOutsideRef
251
- };
252
- },
253
- render() {
254
- return h(DestylerPopoverContentImpl, {
255
- ...mergeProps(this.forwarded),
256
- trapFocus: false,
257
- disableOutsidePointerEvents: false,
258
- onCloseAutoFocus: (event) => {
259
- this.$emit("closeAutoFocus", event);
260
- if (!event.defaultPrevented) {
261
- if (!this.hasInteractedOutsideRef)
262
- this.rootContext.triggerElement.value?.focus();
263
- event.preventDefault();
264
- }
265
- this.hasInteractedOutsideRef = false;
266
- this.hasPointerDownOutsideRef = false;
267
- },
268
- onInteractOutside: async (event) => {
269
- this.$emit("interactOutside", event);
270
- if (!event.defaultPrevented) {
271
- this.hasInteractedOutsideRef = true;
272
- if (event.detail.originalEvent.type === "pointerdown")
273
- this.hasPointerDownOutsideRef = true;
274
- }
275
- const target = event.target;
276
- const targetIsTrigger = this.rootContext.triggerElement.value?.contains(target);
277
- if (targetIsTrigger)
278
- event.preventDefault();
279
- if (event.detail.originalEvent.type === "focusin" && this.hasPointerDownOutsideRef)
280
- event.preventDefault();
281
- }
282
- }, this.$slots.default?.());
283
- }
284
- });
285
-
286
- const destylerPopoverContentProps = {
287
- ...destylerPopoverContentImplProps,
288
- forceMount: {
289
- type: Boolean,
290
- required: false,
291
- default: false
292
- }
293
- };
294
- const destylerPopoverContentEmits = [...destylerPopoverContentImplEmits];
295
- const DestylerPopoverContent = defineComponent({
296
- name: "DestylerPopoverContent",
297
- props: destylerPopoverContentProps,
298
- emits: destylerPopoverContentEmits,
299
- setup(props, { emit }) {
300
- const rootContext = injectPopoverRootContext();
301
- const forwarded = useForwardPropsEmits(props, emit);
302
- return {
303
- rootContext,
304
- forwarded
305
- };
306
- },
307
- render() {
308
- const useVShow = this.rootContext.modal.value;
309
- return h(DestylerPresence, {
310
- present: this.forceMount || this.rootContext.open.value
311
- }, useVShow ? h(DestylerPopoverContentModal, {
312
- ...this.forwarded,
313
- ...mergeProps(this.$attrs)
314
- }, this.$slots.default?.()) : h(DestylerPopoverContentNonModal, {
315
- ...this.forwarded,
316
- ...mergeProps(this.$attrs)
317
- }, this.$slots.default?.()));
318
- }
319
- });
320
-
321
- const destylerPopoverPortalProps = {
322
- ...destylerTeleportProps
323
- };
324
- const DestylerPopoverPortal = defineComponent({
325
- name: "DestylerPopoverPortal",
326
- props: destylerPopoverPortalProps,
327
- render() {
328
- return h(DestylerTeleport, mergeProps(this.$props), this.$slots.default?.());
329
- }
330
- });
331
-
332
- const destylerPopoverTriggerProps = {
333
- ...destylerPrimitiveProp,
334
- as: {
335
- type: [String, Object],
336
- required: false,
337
- default: "button"
338
- }
339
- };
340
- const DestylerPopoverTrigger = defineComponent({
341
- name: "DestylerPopoverTrigger",
342
- props: destylerPopoverTriggerProps,
343
- setup() {
344
- const rootContext = injectPopoverRootContext();
345
- const { customElement, currentElement: triggerElement } = useCustomElement();
346
- onMounted(() => {
347
- rootContext.triggerElement.value = triggerElement.value;
348
- });
349
- return {
350
- rootContext,
351
- customElement
352
- };
353
- },
354
- render() {
355
- return h(this.rootContext.hasCustomAnchor.value ? DestylerPrimitive : DestylerPopperAnchor, {
356
- asChild: true
357
- }, h(DestylerPrimitive, {
358
- "ref": "customElement",
359
- "type": this.$props.as === "button" ? "button" : void 0,
360
- "as": this.$props.as,
361
- "aria-haspopup": "dialog",
362
- "asChild": this.$props.asChild,
363
- "aria-expanded": this.rootContext.open.value,
364
- "aria-controls": this.rootContext.contentId,
365
- "data-state": this.rootContext.open.value ? "open" : "closed",
366
- "onClick": () => {
367
- this.rootContext.onOpenToggle();
368
- }
369
- }, this.$slots.default?.()));
370
- }
371
- });
372
-
373
- const name = "@destyler/popover";
374
-
375
- const packageName = name;
376
- function DestylerPopoverResolver() {
377
- return {
378
- type: "component",
379
- resolve: (name2) => {
380
- if (name2 === "DestylerPopover")
381
- return { name: name2, from: packageName };
382
- }
383
- };
384
- }
385
-
386
- export { DestylerPopoverAnchor, DestylerPopoverArrow, DestylerPopoverClose, DestylerPopoverContent, DestylerPopoverContentImpl, DestylerPopoverContentModal, DestylerPopoverContentNonModal, DestylerPopoverPortal, DestylerPopoverResolver, DestylerPopoverRoot, DestylerPopoverTrigger, destylerPopoverAnchorProps, destylerPopoverArrowProps, destylerPopoverCloseProps, destylerPopoverContentEmits, destylerPopoverContentImplEmits, destylerPopoverContentImplProps, destylerPopoverContentProps, destylerPopoverPortalProps, destylerPopoverRootProps, destylerPopoverTriggerProps, injectPopoverRootContext, providePopoverRootContext };
1
+ export { D as DestylerPopoverArrow, a as DestylerPopoverClose, b as DestylerPopoverContent, f as DestylerPopoverPortal, g as DestylerPopoverRoot, h as DestylerPopoverTrigger } from './shared/popover.a25f925c.mjs';
2
+ import 'vue';
3
+ import '@destyler/popper';
4
+ import '@destyler/primitive';
5
+ import '@destyler/shared';
6
+ import '@destyler/composition';
7
+ import '@destyler/presence';
8
+ import '@destyler/dismissable-layer';
9
+ import '@destyler/focus-scope';
10
+ import '@destyler/directives';
11
+ import '@destyler/teleport';
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ const name = "@destyler/popover";
4
+
5
+ const packageName = name;
6
+ const popoverComponentName = [
7
+ "DestylerPopoverArrow",
8
+ "DestylerPopoverClose",
9
+ "DestylerPopoverContent",
10
+ "DestylerPopoverPortal",
11
+ "DestylerPopoverRoot",
12
+ "DestylerPopoverTrigger"
13
+ ];
14
+ function DestylerPopoverResolver() {
15
+ return {
16
+ type: "component",
17
+ resolve: (name2) => {
18
+ if (popoverComponentName.includes(name2))
19
+ return { name: name2, from: packageName };
20
+ }
21
+ };
22
+ }
23
+
24
+ exports.DestylerPopoverResolver = DestylerPopoverResolver;
25
+ exports.popoverComponentName = popoverComponentName;
@@ -0,0 +1,6 @@
1
+ import { ComponentResolver } from 'unplugin-vue-components';
2
+
3
+ declare const popoverComponentName: string[];
4
+ declare function DestylerPopoverResolver(): ComponentResolver;
5
+
6
+ export { DestylerPopoverResolver, popoverComponentName };
@@ -0,0 +1,6 @@
1
+ import { ComponentResolver } from 'unplugin-vue-components';
2
+
3
+ declare const popoverComponentName: string[];
4
+ declare function DestylerPopoverResolver(): ComponentResolver;
5
+
6
+ export { DestylerPopoverResolver, popoverComponentName };
@@ -0,0 +1,6 @@
1
+ import { ComponentResolver } from 'unplugin-vue-components';
2
+
3
+ declare const popoverComponentName: string[];
4
+ declare function DestylerPopoverResolver(): ComponentResolver;
5
+
6
+ export { DestylerPopoverResolver, popoverComponentName };
@@ -0,0 +1,22 @@
1
+ const name = "@destyler/popover";
2
+
3
+ const packageName = name;
4
+ const popoverComponentName = [
5
+ "DestylerPopoverArrow",
6
+ "DestylerPopoverClose",
7
+ "DestylerPopoverContent",
8
+ "DestylerPopoverPortal",
9
+ "DestylerPopoverRoot",
10
+ "DestylerPopoverTrigger"
11
+ ];
12
+ function DestylerPopoverResolver() {
13
+ return {
14
+ type: "component",
15
+ resolve: (name2) => {
16
+ if (popoverComponentName.includes(name2))
17
+ return { name: name2, from: packageName };
18
+ }
19
+ };
20
+ }
21
+
22
+ export { DestylerPopoverResolver, popoverComponentName };