@destyler/popover 0.0.1-beta.5 → 0.0.1-beta.7
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 +328 -1080
- package/dist/index.d.cts +1343 -89
- package/dist/index.d.mts +1343 -89
- package/dist/index.d.ts +1343 -89
- package/dist/index.mjs +310 -1080
- package/package.json +11 -5
package/dist/index.cjs
CHANGED
|
@@ -1,1144 +1,374 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const vue = require('vue');
|
|
4
|
+
const popper = require('@destyler/popper');
|
|
4
5
|
const shared = require('@destyler/shared');
|
|
5
|
-
const directives = require('@destyler/directives');
|
|
6
6
|
const composition = require('@destyler/composition');
|
|
7
|
+
const primitive = require('@destyler/primitive');
|
|
8
|
+
const presence = require('@destyler/presence');
|
|
9
|
+
const dismissableLayer = require('@destyler/dismissable-layer');
|
|
10
|
+
const focusScope = require('@destyler/focus-scope');
|
|
11
|
+
const directives = require('@destyler/directives');
|
|
12
|
+
const teleport = require('@destyler/teleport');
|
|
7
13
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (node === null)
|
|
15
|
-
return null;
|
|
16
|
-
const parentNode = getParentNode(node);
|
|
17
|
-
if (parentNode === null)
|
|
18
|
-
return null;
|
|
19
|
-
if (parentNode.nodeType === 9)
|
|
20
|
-
return document;
|
|
21
|
-
if (parentNode.nodeType === 1) {
|
|
22
|
-
const { overflow, overflowX, overflowY } = getComputedStyle(
|
|
23
|
-
parentNode
|
|
24
|
-
);
|
|
25
|
-
if (/(auto|scroll|overlay)/.test(overflow + overflowY + overflowX))
|
|
26
|
-
return parentNode;
|
|
27
|
-
}
|
|
28
|
-
return getScrollParent(parentNode);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const DestylerBinder = vue.defineComponent({
|
|
32
|
-
name: "DestylerBinder",
|
|
33
|
-
props: {
|
|
34
|
-
syncTargetWithParent: {
|
|
35
|
-
type: Boolean
|
|
36
|
-
},
|
|
37
|
-
syncTarget: {
|
|
38
|
-
type: Boolean,
|
|
39
|
-
default: true
|
|
40
|
-
}
|
|
14
|
+
const [injectPopoverRootContext, providePopoverRootContext] = shared.createContext("DestylerPopoverRoot");
|
|
15
|
+
const destylerPopoverRootProps = {
|
|
16
|
+
defaultOpen: {
|
|
17
|
+
type: Boolean,
|
|
18
|
+
required: false,
|
|
19
|
+
default: false
|
|
41
20
|
},
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (followerScrollListeners.size === 0)
|
|
81
|
-
ensureScrollListener();
|
|
82
|
-
if (!followerScrollListeners.has(listener))
|
|
83
|
-
followerScrollListeners.add(listener);
|
|
84
|
-
};
|
|
85
|
-
const removeScrollListener = (listener) => {
|
|
86
|
-
if (followerScrollListeners.has(listener))
|
|
87
|
-
followerScrollListeners.delete(listener);
|
|
88
|
-
if (followerScrollListeners.size === 0)
|
|
89
|
-
removeScrollListeners();
|
|
90
|
-
};
|
|
91
|
-
const addResizeListener = (listener) => {
|
|
92
|
-
if (followerResizeListeners.size === 0)
|
|
93
|
-
shared.on("resize", window, onResize);
|
|
94
|
-
if (!followerResizeListeners.has(listener))
|
|
95
|
-
followerResizeListeners.add(listener);
|
|
96
|
-
};
|
|
97
|
-
const removeResizeListener = (listener) => {
|
|
98
|
-
if (followerResizeListeners.has(listener))
|
|
99
|
-
followerResizeListeners.delete(listener);
|
|
100
|
-
if (followerResizeListeners.size === 0)
|
|
101
|
-
shared.off("resize", window, onResize);
|
|
102
|
-
};
|
|
103
|
-
vue.onBeforeUnmount(() => {
|
|
104
|
-
shared.off("resize", window, onResize);
|
|
105
|
-
removeScrollListeners();
|
|
21
|
+
open: {
|
|
22
|
+
type: Boolean,
|
|
23
|
+
required: false,
|
|
24
|
+
default: void 0
|
|
25
|
+
},
|
|
26
|
+
modal: {
|
|
27
|
+
type: Boolean,
|
|
28
|
+
required: false,
|
|
29
|
+
default: false
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const DestylerPopoverRoot = vue.defineComponent({
|
|
33
|
+
name: "DestylerPopoverRoot",
|
|
34
|
+
props: destylerPopoverRootProps,
|
|
35
|
+
emits: ["update:open"],
|
|
36
|
+
setup(props, { emit }) {
|
|
37
|
+
const modalRef = vue.toRef(props.modal);
|
|
38
|
+
const openRef = composition.useVModel(props, "open", emit, {
|
|
39
|
+
defaultValue: props.defaultOpen,
|
|
40
|
+
passive: props.open === void 0
|
|
41
|
+
});
|
|
42
|
+
const triggerElement = vue.ref();
|
|
43
|
+
const hasCustomAnchor = vue.ref(false);
|
|
44
|
+
function handleUpdateOpen(value) {
|
|
45
|
+
openRef.value = value;
|
|
46
|
+
}
|
|
47
|
+
providePopoverRootContext({
|
|
48
|
+
contentId: composition.useId(),
|
|
49
|
+
modal: modalRef,
|
|
50
|
+
open: openRef,
|
|
51
|
+
onOpenChange: (value) => {
|
|
52
|
+
handleUpdateOpen(value);
|
|
53
|
+
},
|
|
54
|
+
onOpenToggle: () => {
|
|
55
|
+
handleUpdateOpen(!openRef.value);
|
|
56
|
+
},
|
|
57
|
+
triggerElement,
|
|
58
|
+
hasCustomAnchor
|
|
106
59
|
});
|
|
107
60
|
return {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
addResizeListener,
|
|
113
|
-
removeResizeListener
|
|
61
|
+
openRef,
|
|
62
|
+
modalRef,
|
|
63
|
+
triggerElement,
|
|
64
|
+
hasCustomAnchor
|
|
114
65
|
};
|
|
115
66
|
},
|
|
116
67
|
render() {
|
|
117
|
-
return
|
|
68
|
+
return vue.h(popper.DestylerPopperRoot, this.$slots.default?.());
|
|
118
69
|
}
|
|
119
70
|
});
|
|
120
71
|
|
|
121
|
-
const
|
|
122
|
-
|
|
72
|
+
const destylerPopoverAnchorProps = {
|
|
73
|
+
...popper.destylerPopperArrowProps
|
|
74
|
+
};
|
|
75
|
+
const DestylerPopoverAnchor = vue.defineComponent({
|
|
76
|
+
name: "DestylerPopoverAnchor",
|
|
77
|
+
props: destylerPopoverAnchorProps,
|
|
123
78
|
setup() {
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
79
|
+
const rootContext = injectPopoverRootContext();
|
|
80
|
+
vue.onBeforeMount(() => {
|
|
81
|
+
rootContext.hasCustomAnchor.value = true;
|
|
82
|
+
});
|
|
83
|
+
vue.onUnmounted(() => {
|
|
84
|
+
rootContext.hasCustomAnchor.value = false;
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
render() {
|
|
88
|
+
return vue.h(popper.DestylerPopperAnchor, vue.mergeProps(this.$props, {}), this.$slots.default?.());
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const destylerPopoverArrowProps = {
|
|
93
|
+
...popper.destylerPopperArrowProps
|
|
94
|
+
};
|
|
95
|
+
const DestylerPopoverArrow = vue.defineComponent({
|
|
96
|
+
name: "DestylerPopoverArrow",
|
|
97
|
+
props: destylerPopoverArrowProps,
|
|
98
|
+
render() {
|
|
99
|
+
return vue.h(popper.DestylerPopperArrow, vue.mergeProps(this.$props, {}), this.$slots.default?.());
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const destylerPopoverCloseProps = {
|
|
104
|
+
...primitive.destylerPrimitiveProp,
|
|
105
|
+
as: {
|
|
106
|
+
type: [String, Object],
|
|
107
|
+
required: false,
|
|
108
|
+
default: "button"
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
const DestylerPopoverClose = vue.defineComponent({
|
|
112
|
+
name: "DestylerPopoverClose",
|
|
113
|
+
props: destylerPopoverCloseProps,
|
|
114
|
+
setup() {
|
|
115
|
+
const rootContext = injectPopoverRootContext();
|
|
133
116
|
return {
|
|
134
|
-
|
|
135
|
-
setTargetDirective
|
|
117
|
+
rootContext
|
|
136
118
|
};
|
|
137
119
|
},
|
|
138
120
|
render() {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
121
|
+
return vue.h(primitive.DestylerPrimitive, {
|
|
122
|
+
as: this.$props.as,
|
|
123
|
+
asChild: this.$props.asChild,
|
|
124
|
+
type: this.$props.as === "button" ? "button" : void 0,
|
|
125
|
+
onClick: () => {
|
|
126
|
+
this.rootContext.onOpenChange(false);
|
|
127
|
+
}
|
|
128
|
+
}, this.$slots.default?.());
|
|
146
129
|
}
|
|
147
130
|
});
|
|
148
131
|
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
},
|
|
132
|
+
const destylerPopoverContentImplProps = {
|
|
133
|
+
...popper.destylerPopperContentProps,
|
|
134
|
+
...dismissableLayer.destylerDismissableLayerProps,
|
|
135
|
+
trapFocus: {
|
|
136
|
+
type: Boolean,
|
|
137
|
+
required: false,
|
|
138
|
+
default: false
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
const destylerPopoverContentImplEmits = ["escapeKeyDown", "pointerDownOutside", "focusOutside", "interactOutside", "dismiss", "openAutoFocus", "closeAutoFocus"];
|
|
142
|
+
const DestylerPopoverContentImpl = vue.defineComponent({
|
|
143
|
+
name: "DestylerPopoverContentImpl",
|
|
144
|
+
props: destylerPopoverContentImplProps,
|
|
145
|
+
emits: destylerPopoverContentImplEmits,
|
|
164
146
|
setup(props) {
|
|
147
|
+
const forwarded = composition.useForwardProps(props);
|
|
148
|
+
const rootContext = injectPopoverRootContext();
|
|
149
|
+
composition.useFocusGuards();
|
|
165
150
|
return {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const { to } = props;
|
|
169
|
-
return to ?? "body";
|
|
170
|
-
})
|
|
151
|
+
rootContext,
|
|
152
|
+
forwarded
|
|
171
153
|
};
|
|
172
154
|
},
|
|
173
155
|
render() {
|
|
174
|
-
return
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
156
|
+
return vue.h(focusScope.DestylerFocusScope, {
|
|
157
|
+
asChild: this.$props.asChild,
|
|
158
|
+
loop: true,
|
|
159
|
+
trapped: this.$props.trapFocus,
|
|
160
|
+
onMountAutoFocus: (event) => {
|
|
161
|
+
this.$emit("openAutoFocus", event);
|
|
162
|
+
},
|
|
163
|
+
onUnmountAutoFocus: (event) => {
|
|
164
|
+
this.$emit("closeAutoFocus", event);
|
|
165
|
+
}
|
|
166
|
+
}, vue.h(dismissableLayer.DestylerDismissableLayer, {
|
|
167
|
+
asChild: this.$props.asChild,
|
|
168
|
+
disableOutsidePointerEvents: this.$props.disableOutsidePointerEvents,
|
|
169
|
+
onPointerDownOutside: (event) => {
|
|
170
|
+
this.$emit("pointerDownOutside", event);
|
|
171
|
+
},
|
|
172
|
+
onInteractOutside: (event) => {
|
|
173
|
+
this.$emit("interactOutside", event);
|
|
179
174
|
},
|
|
180
|
-
|
|
181
|
-
|
|
175
|
+
onEscapeKeyDown: (event) => {
|
|
176
|
+
this.$emit("escapeKeyDown", event);
|
|
177
|
+
},
|
|
178
|
+
onFocusOutside: (event) => {
|
|
179
|
+
this.$emit("focusOutside", event);
|
|
180
|
+
},
|
|
181
|
+
onDismiss: () => {
|
|
182
|
+
this.rootContext.onOpenChange(false);
|
|
183
|
+
}
|
|
184
|
+
}, vue.withDirectives(vue.h(popper.DestylerPopperContent, vue.mergeProps(this.forwarded, {
|
|
185
|
+
"data-state": this.rootContext.open.value ? "open" : "closed",
|
|
186
|
+
"role": "dialog",
|
|
187
|
+
"style": {
|
|
188
|
+
"--destyler_popover_content_transform_origin": "var(--destyler_popper_transform_origin)",
|
|
189
|
+
"--destyler_popover_content_available_width": "var(--destyler_popper_available_width)",
|
|
190
|
+
"--destyler_popover_content_available_height": "var(--destyler_popper_available_height)",
|
|
191
|
+
"--destyler_popover_trigger_width": "var(--destyler_popper_anchor_width)",
|
|
192
|
+
"--destyler_popover_trigger_height": "var(--destyler_popper_anchor_height)"
|
|
193
|
+
}
|
|
194
|
+
}), this.$slots.default?.()), [
|
|
195
|
+
[directives.BindOnceDirective, { id: this.rootContext.contentId }]
|
|
196
|
+
])));
|
|
182
197
|
}
|
|
183
198
|
});
|
|
184
199
|
|
|
185
|
-
const
|
|
186
|
-
name: "
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
default: void 0
|
|
196
|
-
},
|
|
197
|
-
to: {
|
|
198
|
-
type: [String, Object],
|
|
199
|
-
default: "body"
|
|
200
|
-
},
|
|
201
|
-
flip: {
|
|
202
|
-
type: Boolean,
|
|
203
|
-
default: true
|
|
204
|
-
},
|
|
205
|
-
internalShift: {
|
|
206
|
-
type: Boolean
|
|
207
|
-
},
|
|
208
|
-
x: {
|
|
209
|
-
type: Number
|
|
210
|
-
},
|
|
211
|
-
y: {
|
|
212
|
-
type: Number
|
|
213
|
-
},
|
|
214
|
-
width: {
|
|
215
|
-
type: String
|
|
216
|
-
},
|
|
217
|
-
minWidth: {
|
|
218
|
-
type: String
|
|
219
|
-
},
|
|
220
|
-
containerClass: {
|
|
221
|
-
type: String
|
|
222
|
-
},
|
|
223
|
-
teleportDisabled: {
|
|
224
|
-
type: Boolean
|
|
225
|
-
},
|
|
226
|
-
zindexable: {
|
|
227
|
-
type: Boolean,
|
|
228
|
-
default: true
|
|
229
|
-
},
|
|
230
|
-
zIndex: {
|
|
231
|
-
type: Number
|
|
232
|
-
},
|
|
233
|
-
overlap: {
|
|
234
|
-
type: Boolean
|
|
235
|
-
}
|
|
236
|
-
},
|
|
237
|
-
setup(props) {
|
|
238
|
-
const DestylerBinder = vue.inject("DestylerBinder");
|
|
239
|
-
const mergedEnabled = composition.useMemo(() => {
|
|
240
|
-
return props.enabled !== void 0 ? props.enabled : props.show;
|
|
241
|
-
});
|
|
242
|
-
const follower = vue.ref(null);
|
|
243
|
-
const offsetContainer = vue.ref(null);
|
|
244
|
-
const isMounted = composition.useIsMounted();
|
|
245
|
-
const mergedTo = composition.useMemo(
|
|
246
|
-
() => {
|
|
247
|
-
const { to } = props;
|
|
248
|
-
if (to !== void 0)
|
|
249
|
-
return to;
|
|
250
|
-
if (isMounted.value) {
|
|
251
|
-
return void 0;
|
|
252
|
-
}
|
|
253
|
-
return void 0;
|
|
254
|
-
}
|
|
255
|
-
);
|
|
256
|
-
function getElementBounding() {
|
|
257
|
-
if (DestylerBinder.targetRef === null) {
|
|
258
|
-
return {
|
|
259
|
-
x: 0,
|
|
260
|
-
y: 0,
|
|
261
|
-
width: 0,
|
|
262
|
-
height: 0
|
|
263
|
-
};
|
|
264
|
-
} else {
|
|
265
|
-
const rect = DestylerBinder.targetRef.getBoundingClientRect();
|
|
266
|
-
return {
|
|
267
|
-
x: rect.x,
|
|
268
|
-
y: rect.y,
|
|
269
|
-
width: rect.width,
|
|
270
|
-
height: rect.height
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
}
|
|
200
|
+
const DestylerPopoverContentModal = vue.defineComponent({
|
|
201
|
+
name: "DestylerPopoverContentModal",
|
|
202
|
+
props: destylerPopoverContentImplProps,
|
|
203
|
+
emits: destylerPopoverContentImplEmits,
|
|
204
|
+
setup(props, { emit }) {
|
|
205
|
+
const rootContext = injectPopoverRootContext();
|
|
206
|
+
const isRightClickOutsideRef = vue.ref(false);
|
|
207
|
+
const forwarded = composition.useForwardPropsEmits(props, emit);
|
|
208
|
+
const { customElement, currentElement } = composition.useCustomElement();
|
|
209
|
+
composition.useHideOthers(currentElement);
|
|
274
210
|
return {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
getElementBounding
|
|
211
|
+
rootContext,
|
|
212
|
+
forwarded,
|
|
213
|
+
isRightClickOutsideRef,
|
|
214
|
+
customElement
|
|
280
215
|
};
|
|
281
216
|
},
|
|
282
217
|
render() {
|
|
283
|
-
return vue.h(
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
--destyler-follower-width:${this.getElementBounding().width}px;
|
|
300
|
-
--destyler-follower-height:${this.getElementBounding().height}px;
|
|
301
|
-
`
|
|
302
|
-
}, this.$slots.default?.())
|
|
303
|
-
]);
|
|
304
|
-
if (this.$props.zindexable) {
|
|
305
|
-
return vue.withDirectives(vNode, [
|
|
306
|
-
[
|
|
307
|
-
directives.zindexable,
|
|
308
|
-
{
|
|
309
|
-
enabled: this.mergedEnabled,
|
|
310
|
-
zIndex: this.$props.zIndex
|
|
311
|
-
}
|
|
312
|
-
]
|
|
313
|
-
]);
|
|
314
|
-
}
|
|
315
|
-
return vNode;
|
|
218
|
+
return vue.h(DestylerPopoverContentImpl, {
|
|
219
|
+
"ref": "customElement",
|
|
220
|
+
...vue.mergeProps(this.forwarded),
|
|
221
|
+
"trapFocus": this.rootContext.open.value,
|
|
222
|
+
"disable-outside-pointer-events": "",
|
|
223
|
+
"onCloseAutoFocusPrevent": (event) => {
|
|
224
|
+
this.$emit("closeAutoFocus", event);
|
|
225
|
+
if (!this.isRightClickOutsideRef)
|
|
226
|
+
this.rootContext.triggerElement.value?.focus();
|
|
227
|
+
},
|
|
228
|
+
"onPointerDownOutside": (event) => {
|
|
229
|
+
this.$emit("pointerDownOutside", event);
|
|
230
|
+
const originalEvent = event.detail.originalEvent;
|
|
231
|
+
const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
|
|
232
|
+
const isRightClick = originalEvent.button === 2 || ctrlLeftClick;
|
|
233
|
+
this.isRightClickOutsideRef = isRightClick;
|
|
316
234
|
}
|
|
317
|
-
});
|
|
235
|
+
}, this.$slots.default?.());
|
|
318
236
|
}
|
|
319
237
|
});
|
|
320
238
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
return false;
|
|
333
|
-
}
|
|
334
|
-
function focusLastDescendant(element) {
|
|
335
|
-
for (let i = element.childNodes.length - 1; i >= 0; i--) {
|
|
336
|
-
const child = element.childNodes[i];
|
|
337
|
-
if (isHTMLElement(child)) {
|
|
338
|
-
if (attemptFocus(child) || focusLastDescendant(child))
|
|
339
|
-
return true;
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
return false;
|
|
343
|
-
}
|
|
344
|
-
function attemptFocus(element) {
|
|
345
|
-
if (!isFocusable(element))
|
|
346
|
-
return false;
|
|
347
|
-
try {
|
|
348
|
-
element.focus({ preventScroll: true });
|
|
349
|
-
} catch (e) {
|
|
350
|
-
}
|
|
351
|
-
return document.activeElement === element;
|
|
352
|
-
}
|
|
353
|
-
function isFocusable(element) {
|
|
354
|
-
if (element.tabIndex > 0 || element.tabIndex === 0 && element.getAttribute("tabIndex") !== null)
|
|
355
|
-
return true;
|
|
356
|
-
if (element.getAttribute("disabled"))
|
|
357
|
-
return false;
|
|
358
|
-
switch (element.nodeName) {
|
|
359
|
-
case "A":
|
|
360
|
-
return !!element.href && element.rel !== "ignore";
|
|
361
|
-
case "INPUT":
|
|
362
|
-
return element.type !== "hidden" && element.type !== "file";
|
|
363
|
-
case "BUTTON":
|
|
364
|
-
case "SELECT":
|
|
365
|
-
case "TEXTAREA":
|
|
366
|
-
return true;
|
|
367
|
-
default:
|
|
368
|
-
return false;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
let stack = [];
|
|
373
|
-
const DestylerFocusTrap = vue.defineComponent({
|
|
374
|
-
name: "DestylerFocusTrap",
|
|
375
|
-
props: {
|
|
376
|
-
disabled: {
|
|
377
|
-
type: Boolean
|
|
378
|
-
},
|
|
379
|
-
active: {
|
|
380
|
-
type: Boolean
|
|
381
|
-
},
|
|
382
|
-
autoFocus: {
|
|
383
|
-
type: Boolean,
|
|
384
|
-
default: true
|
|
385
|
-
},
|
|
386
|
-
onEsc: {
|
|
387
|
-
type: Function
|
|
388
|
-
},
|
|
389
|
-
initialFocusTo: {
|
|
390
|
-
type: String
|
|
391
|
-
},
|
|
392
|
-
finalFocusTo: {
|
|
393
|
-
type: String
|
|
394
|
-
},
|
|
395
|
-
returnFocusOnDeactivated: {
|
|
396
|
-
type: Boolean,
|
|
397
|
-
default: true
|
|
398
|
-
}
|
|
399
|
-
},
|
|
400
|
-
setup(props) {
|
|
401
|
-
const id = shared.createId();
|
|
402
|
-
const focusableStartRef = vue.ref(null);
|
|
403
|
-
const focusableEndRef = vue.ref(null);
|
|
404
|
-
let activated = false;
|
|
405
|
-
let ignoreInternalFocusChange = false;
|
|
406
|
-
const lastFocusedElement = typeof document === "undefined" ? null : document.activeElement;
|
|
407
|
-
function isCurrentActive() {
|
|
408
|
-
const currentActiveId = stack[stack.length - 1];
|
|
409
|
-
return currentActiveId === id;
|
|
410
|
-
}
|
|
411
|
-
function handleDocumentKeydown(e) {
|
|
412
|
-
if (e.code === "Escape") {
|
|
413
|
-
if (isCurrentActive())
|
|
414
|
-
props.onEsc?.(e);
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
vue.onMounted(() => {
|
|
418
|
-
vue.watch(
|
|
419
|
-
() => props.active,
|
|
420
|
-
(value) => {
|
|
421
|
-
if (value) {
|
|
422
|
-
activate();
|
|
423
|
-
shared.on("keydown", document, handleDocumentKeydown);
|
|
424
|
-
} else {
|
|
425
|
-
shared.off("keydown", document, handleDocumentKeydown);
|
|
426
|
-
if (activated)
|
|
427
|
-
deactivate();
|
|
428
|
-
}
|
|
429
|
-
},
|
|
430
|
-
{
|
|
431
|
-
immediate: true
|
|
432
|
-
}
|
|
433
|
-
);
|
|
434
|
-
});
|
|
435
|
-
vue.onBeforeUnmount(() => {
|
|
436
|
-
shared.off("keydown", document, handleDocumentKeydown);
|
|
437
|
-
if (activated)
|
|
438
|
-
deactivate();
|
|
439
|
-
});
|
|
440
|
-
function handleDocumentFocus(e) {
|
|
441
|
-
if (ignoreInternalFocusChange)
|
|
442
|
-
return;
|
|
443
|
-
if (isCurrentActive()) {
|
|
444
|
-
const mainEl = getMainEl();
|
|
445
|
-
if (mainEl === null)
|
|
446
|
-
return;
|
|
447
|
-
if (mainEl.contains(shared.getPreciseEventTarget(e)))
|
|
448
|
-
return;
|
|
449
|
-
resetFocusTo("first");
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
function getMainEl() {
|
|
453
|
-
const focusableStartEl = focusableStartRef.value;
|
|
454
|
-
if (focusableStartEl === null)
|
|
455
|
-
return null;
|
|
456
|
-
let mainEl = focusableStartEl;
|
|
457
|
-
while (true) {
|
|
458
|
-
mainEl = mainEl.nextSibling;
|
|
459
|
-
if (mainEl === null)
|
|
460
|
-
break;
|
|
461
|
-
if (mainEl instanceof Element && mainEl.tagName === "DIV")
|
|
462
|
-
break;
|
|
463
|
-
}
|
|
464
|
-
return mainEl;
|
|
465
|
-
}
|
|
466
|
-
function activate() {
|
|
467
|
-
if (props.disabled)
|
|
468
|
-
return;
|
|
469
|
-
stack.push(id);
|
|
470
|
-
if (props.autoFocus) {
|
|
471
|
-
const { initialFocusTo } = props;
|
|
472
|
-
if (initialFocusTo === void 0)
|
|
473
|
-
resetFocusTo("first");
|
|
474
|
-
else
|
|
475
|
-
shared.resolveTo(initialFocusTo)?.focus({ preventScroll: true });
|
|
476
|
-
}
|
|
477
|
-
activated = true;
|
|
478
|
-
document.addEventListener("focus", handleDocumentFocus, true);
|
|
479
|
-
}
|
|
480
|
-
function deactivate() {
|
|
481
|
-
if (props.disabled)
|
|
482
|
-
return;
|
|
483
|
-
document.removeEventListener("focus", handleDocumentFocus, true);
|
|
484
|
-
stack = stack.filter((idInStack) => idInStack !== id);
|
|
485
|
-
if (isCurrentActive())
|
|
486
|
-
return;
|
|
487
|
-
const { finalFocusTo } = props;
|
|
488
|
-
if (finalFocusTo !== void 0) {
|
|
489
|
-
shared.resolveTo(finalFocusTo)?.focus({ preventScroll: true });
|
|
490
|
-
} else if (props.returnFocusOnDeactivated) {
|
|
491
|
-
if (lastFocusedElement instanceof HTMLElement) {
|
|
492
|
-
ignoreInternalFocusChange = true;
|
|
493
|
-
lastFocusedElement.focus({ preventScroll: true });
|
|
494
|
-
ignoreInternalFocusChange = false;
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
function resetFocusTo(target) {
|
|
499
|
-
if (!isCurrentActive())
|
|
500
|
-
return;
|
|
501
|
-
if (props.active) {
|
|
502
|
-
const focusableStartEl = focusableStartRef.value;
|
|
503
|
-
const focusableEndEl = focusableEndRef.value;
|
|
504
|
-
if (focusableStartEl !== null && focusableEndEl !== null) {
|
|
505
|
-
const mainEl = getMainEl();
|
|
506
|
-
if (mainEl == null || mainEl === focusableEndEl) {
|
|
507
|
-
ignoreInternalFocusChange = true;
|
|
508
|
-
focusableStartEl.focus({ preventScroll: true });
|
|
509
|
-
ignoreInternalFocusChange = false;
|
|
510
|
-
return;
|
|
511
|
-
}
|
|
512
|
-
ignoreInternalFocusChange = true;
|
|
513
|
-
const focused = target === "first" ? focusFirstDescendant(mainEl) : focusLastDescendant(mainEl);
|
|
514
|
-
ignoreInternalFocusChange = false;
|
|
515
|
-
if (!focused) {
|
|
516
|
-
ignoreInternalFocusChange = true;
|
|
517
|
-
focusableStartEl.focus({ preventScroll: true });
|
|
518
|
-
ignoreInternalFocusChange = false;
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
function handleStartFocus(e) {
|
|
524
|
-
if (ignoreInternalFocusChange)
|
|
525
|
-
return;
|
|
526
|
-
const mainEl = getMainEl();
|
|
527
|
-
if (mainEl === null)
|
|
528
|
-
return;
|
|
529
|
-
if (e.relatedTarget !== null && mainEl.contains(e.relatedTarget)) {
|
|
530
|
-
resetFocusTo("last");
|
|
531
|
-
} else {
|
|
532
|
-
resetFocusTo("first");
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
function handleEndFocus(e) {
|
|
536
|
-
if (ignoreInternalFocusChange)
|
|
537
|
-
return;
|
|
538
|
-
if (e.relatedTarget !== null && e.relatedTarget === focusableStartRef.value) {
|
|
539
|
-
resetFocusTo("last");
|
|
540
|
-
} else {
|
|
541
|
-
resetFocusTo("first");
|
|
542
|
-
}
|
|
543
|
-
}
|
|
239
|
+
const DestylerPopoverContentNonModal = vue.defineComponent({
|
|
240
|
+
name: "DestylerPopoverContentNonModal",
|
|
241
|
+
props: destylerPopoverContentImplProps,
|
|
242
|
+
emits: destylerPopoverContentImplEmits,
|
|
243
|
+
setup(props, { emit }) {
|
|
244
|
+
const rootContext = injectPopoverRootContext();
|
|
245
|
+
const hasInteractedOutsideRef = vue.ref(false);
|
|
246
|
+
const hasPointerDownOutsideRef = vue.ref(false);
|
|
247
|
+
const forwarded = composition.useForwardPropsEmits(props, emit);
|
|
544
248
|
return {
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
handleEndFocus
|
|
249
|
+
forwarded,
|
|
250
|
+
rootContext,
|
|
251
|
+
hasInteractedOutsideRef,
|
|
252
|
+
hasPointerDownOutsideRef
|
|
550
253
|
};
|
|
551
254
|
},
|
|
552
255
|
render() {
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
256
|
+
return vue.h(DestylerPopoverContentImpl, {
|
|
257
|
+
...vue.mergeProps(this.forwarded),
|
|
258
|
+
trapFocus: false,
|
|
259
|
+
disableOutsidePointerEvents: false,
|
|
260
|
+
onCloseAutoFocus: (event) => {
|
|
261
|
+
this.$emit("closeAutoFocus", event);
|
|
262
|
+
if (!event.defaultPrevented) {
|
|
263
|
+
if (!this.hasInteractedOutsideRef)
|
|
264
|
+
this.rootContext.triggerElement.value?.focus();
|
|
265
|
+
event.preventDefault();
|
|
266
|
+
}
|
|
267
|
+
this.hasInteractedOutsideRef = false;
|
|
268
|
+
this.hasPointerDownOutsideRef = false;
|
|
269
|
+
},
|
|
270
|
+
onInteractOutside: async (event) => {
|
|
271
|
+
this.$emit("interactOutside", event);
|
|
272
|
+
if (!event.defaultPrevented) {
|
|
273
|
+
this.hasInteractedOutsideRef = true;
|
|
274
|
+
if (event.detail.originalEvent.type === "pointerdown")
|
|
275
|
+
this.hasPointerDownOutsideRef = true;
|
|
276
|
+
}
|
|
277
|
+
const target = event.target;
|
|
278
|
+
const targetIsTrigger = this.rootContext.triggerElement.value?.contains(target);
|
|
279
|
+
if (targetIsTrigger)
|
|
280
|
+
event.preventDefault();
|
|
281
|
+
if (event.detail.originalEvent.type === "focusin" && this.hasPointerDownOutsideRef)
|
|
282
|
+
event.preventDefault();
|
|
283
|
+
}
|
|
284
|
+
}, this.$slots.default?.());
|
|
580
285
|
}
|
|
581
286
|
});
|
|
582
287
|
|
|
583
|
-
const
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
},
|
|
590
|
-
delay: {
|
|
591
|
-
type: Number
|
|
592
|
-
},
|
|
593
|
-
duration: {
|
|
594
|
-
type: Number
|
|
595
|
-
},
|
|
596
|
-
displayDirective: {
|
|
597
|
-
type: String
|
|
598
|
-
},
|
|
599
|
-
x: {
|
|
600
|
-
type: Number
|
|
601
|
-
},
|
|
602
|
-
y: {
|
|
603
|
-
type: Number
|
|
604
|
-
},
|
|
605
|
-
flip: {
|
|
606
|
-
type: Boolean
|
|
607
|
-
},
|
|
608
|
-
internalTrapFocus: {
|
|
609
|
-
type: Boolean
|
|
610
|
-
},
|
|
611
|
-
overlap: {
|
|
612
|
-
type: Boolean
|
|
613
|
-
},
|
|
614
|
-
keepAliveOnHover: {
|
|
615
|
-
type: Boolean
|
|
616
|
-
},
|
|
617
|
-
scrollable: {
|
|
618
|
-
type: Boolean
|
|
619
|
-
},
|
|
620
|
-
internalDeactivateImmediately: {
|
|
621
|
-
type: Boolean
|
|
622
|
-
},
|
|
623
|
-
onClickoutside: {
|
|
624
|
-
type: Function
|
|
288
|
+
const destylerPopoverContentProps = {
|
|
289
|
+
...destylerPopoverContentImplProps,
|
|
290
|
+
forceMount: {
|
|
291
|
+
type: Boolean,
|
|
292
|
+
required: false,
|
|
293
|
+
default: false
|
|
625
294
|
}
|
|
626
295
|
};
|
|
627
|
-
const
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
const
|
|
634
|
-
const
|
|
635
|
-
const displayed = vue.ref(false);
|
|
636
|
-
vue.watchEffect(() => {
|
|
637
|
-
const { show } = props;
|
|
638
|
-
if (show && !shared.isJsdom() && !props.internalDeactivateImmediately)
|
|
639
|
-
displayed.value = true;
|
|
640
|
-
else
|
|
641
|
-
displayed.value = false;
|
|
642
|
-
});
|
|
643
|
-
vue.onBeforeUnmount(() => {
|
|
644
|
-
DestylerPopover.setBodyInstance(null);
|
|
645
|
-
});
|
|
646
|
-
vue.watch(vue.toRef(props, "show"), (value) => {
|
|
647
|
-
if (value)
|
|
648
|
-
followerEnabled.value = true;
|
|
649
|
-
else
|
|
650
|
-
followerEnabled.value = false;
|
|
651
|
-
});
|
|
652
|
-
function syncPosition() {
|
|
653
|
-
follower.value?.syncPosition();
|
|
654
|
-
}
|
|
655
|
-
DestylerPopover.setBodyInstance({
|
|
656
|
-
syncPosition
|
|
657
|
-
});
|
|
658
|
-
function handleMouseEnter(e) {
|
|
659
|
-
if (props.trigger === "hover" && props.keepAliveOnHover && props.show)
|
|
660
|
-
DestylerPopover.handleMouseEnter(e);
|
|
661
|
-
}
|
|
662
|
-
function handleMouseLeave(e) {
|
|
663
|
-
if (props.trigger === "hover" && props.keepAliveOnHover)
|
|
664
|
-
DestylerPopover.handleMouseLeave(e);
|
|
665
|
-
}
|
|
666
|
-
function handleMouseMoveOutside(e) {
|
|
667
|
-
if (props.trigger === "hover" && !getTriggerElement().contains(shared.getPreciseEventTarget(e)))
|
|
668
|
-
DestylerPopover.handleMouseMoveOutside(e);
|
|
669
|
-
}
|
|
670
|
-
function getTriggerElement() {
|
|
671
|
-
return DestylerPopover.getTriggerElement();
|
|
672
|
-
}
|
|
673
|
-
function handleClickOutside(e) {
|
|
674
|
-
if (props.trigger === "click" && !getTriggerElement().contains(
|
|
675
|
-
shared.getPreciseEventTarget(e)
|
|
676
|
-
) || props.onClickoutside)
|
|
677
|
-
DestylerPopover.handleClickOutside(e);
|
|
678
|
-
}
|
|
679
|
-
const directives$1 = vue.computed(() => {
|
|
680
|
-
const { trigger, onClickoutside } = props;
|
|
681
|
-
const directives2 = [];
|
|
682
|
-
const {
|
|
683
|
-
positionManually: { value: positionManually }
|
|
684
|
-
} = DestylerPopover;
|
|
685
|
-
if (!positionManually) {
|
|
686
|
-
if (trigger === "click" && !onClickoutside) {
|
|
687
|
-
directives2.push([
|
|
688
|
-
directives.clickoutside,
|
|
689
|
-
handleClickOutside,
|
|
690
|
-
void 0,
|
|
691
|
-
{ capture: true }
|
|
692
|
-
]);
|
|
693
|
-
}
|
|
694
|
-
if (trigger === "hover")
|
|
695
|
-
directives2.push([directives.mousemoveoutside, handleMouseMoveOutside]);
|
|
696
|
-
}
|
|
697
|
-
if (onClickoutside) {
|
|
698
|
-
directives2.push([
|
|
699
|
-
directives.clickoutside,
|
|
700
|
-
handleClickOutside,
|
|
701
|
-
void 0,
|
|
702
|
-
{ capture: true }
|
|
703
|
-
]);
|
|
704
|
-
}
|
|
705
|
-
if (props.displayDirective === "show" || displayed.value)
|
|
706
|
-
directives2.push([vue.vShow, props.show]);
|
|
707
|
-
return directives2;
|
|
708
|
-
});
|
|
709
|
-
function renderContentNode() {
|
|
710
|
-
const shouldRenderDom = props.displayDirective === "show" || props.show || displayed.value;
|
|
711
|
-
if (!shouldRenderDom)
|
|
712
|
-
return null;
|
|
713
|
-
let contentNode;
|
|
714
|
-
const renderBody = DestylerPopover.internalRenderBody.value;
|
|
715
|
-
if (!renderBody) {
|
|
716
|
-
const { internalTrapFocus } = props;
|
|
717
|
-
const hasHeaderOrFooter = !shared.isSlotEmpty(slots.header) || !shared.isSlotEmpty(slots.footer);
|
|
718
|
-
const renderContentInnerNode = () => {
|
|
719
|
-
const body2 = hasHeaderOrFooter ? [
|
|
720
|
-
shared.resolveWrappedSlot(slots.header, (children) => {
|
|
721
|
-
return children ? vue.h("div", null, children) : null;
|
|
722
|
-
}),
|
|
723
|
-
shared.resolveWrappedSlot(slots.default, (children) => {
|
|
724
|
-
return children ? vue.h("div", null, children) : null;
|
|
725
|
-
}),
|
|
726
|
-
shared.resolveWrappedSlot(slots.footer, (children) => {
|
|
727
|
-
return children ? vue.h("div", null, children) : null;
|
|
728
|
-
})
|
|
729
|
-
] : vue.h("div", {
|
|
730
|
-
destyler: "popover-body-content"
|
|
731
|
-
}, slots);
|
|
732
|
-
return [body2];
|
|
733
|
-
};
|
|
734
|
-
contentNode = vue.h("div", vue.mergeProps({
|
|
735
|
-
ref: body,
|
|
736
|
-
destyler: "popover-body-toggle",
|
|
737
|
-
onMouseenter: handleMouseEnter,
|
|
738
|
-
onMouseleave: handleMouseLeave
|
|
739
|
-
}, attrs), internalTrapFocus ? vue.h(DestylerFocusTrap, {
|
|
740
|
-
active: props.show,
|
|
741
|
-
autoFocus: true
|
|
742
|
-
}, renderContentInnerNode) : renderContentInnerNode());
|
|
743
|
-
} else {
|
|
744
|
-
contentNode = renderBody(body, handleMouseEnter, handleMouseLeave);
|
|
745
|
-
}
|
|
746
|
-
return vue.withDirectives(contentNode, directives$1.value);
|
|
747
|
-
}
|
|
296
|
+
const destylerPopoverContentEmits = [...destylerPopoverContentImplEmits];
|
|
297
|
+
const DestylerPopoverContent = vue.defineComponent({
|
|
298
|
+
name: "DestylerPopoverContent",
|
|
299
|
+
props: destylerPopoverContentProps,
|
|
300
|
+
emits: destylerPopoverContentEmits,
|
|
301
|
+
setup(props, { emit }) {
|
|
302
|
+
const rootContext = injectPopoverRootContext();
|
|
303
|
+
const forwarded = composition.useForwardPropsEmits(props, emit);
|
|
748
304
|
return {
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
zIndex: DestylerPopover.zIndex,
|
|
752
|
-
follower,
|
|
753
|
-
followerEnabled,
|
|
754
|
-
renderContentNode
|
|
305
|
+
rootContext,
|
|
306
|
+
forwarded
|
|
755
307
|
};
|
|
756
308
|
},
|
|
757
309
|
render() {
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
}, () => this.renderContentNode());
|
|
310
|
+
const useVShow = this.rootContext.modal.value;
|
|
311
|
+
return vue.h(presence.DestylerPresence, {
|
|
312
|
+
present: this.forceMount || this.rootContext.open.value
|
|
313
|
+
}, useVShow ? vue.h(DestylerPopoverContentModal, {
|
|
314
|
+
...this.forwarded,
|
|
315
|
+
...vue.mergeProps(this.$attrs)
|
|
316
|
+
}, this.$slots.default?.()) : vue.h(DestylerPopoverContentNonModal, {
|
|
317
|
+
...this.forwarded,
|
|
318
|
+
...vue.mergeProps(this.$attrs)
|
|
319
|
+
}, this.$slots.default?.()));
|
|
769
320
|
}
|
|
770
321
|
});
|
|
771
322
|
|
|
772
|
-
const
|
|
773
|
-
|
|
774
|
-
focus: ["onFocus", "onBlur"],
|
|
775
|
-
click: ["onClick"],
|
|
776
|
-
hover: ["onMouseenter", "onMouseleave"],
|
|
777
|
-
manual: [],
|
|
778
|
-
nested: ["onFocus", "onBlur", "onMouseenter", "onMouseleave", "onClick"]
|
|
323
|
+
const destylerPopoverPortalProps = {
|
|
324
|
+
...teleport.destylerTeleportProps
|
|
779
325
|
};
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
};
|
|
795
|
-
}
|
|
796
|
-
});
|
|
797
|
-
}
|
|
798
|
-
const destylerPopoverProps = {
|
|
799
|
-
"show": {
|
|
800
|
-
type: Boolean,
|
|
801
|
-
default: void 0
|
|
802
|
-
},
|
|
803
|
-
"defaultShow": {
|
|
804
|
-
type: Boolean
|
|
805
|
-
},
|
|
806
|
-
"trigger": {
|
|
807
|
-
type: String,
|
|
808
|
-
default: "hover"
|
|
809
|
-
},
|
|
810
|
-
"delay": {
|
|
811
|
-
type: Number,
|
|
812
|
-
default: 100
|
|
813
|
-
},
|
|
814
|
-
"duration": {
|
|
815
|
-
type: Number,
|
|
816
|
-
default: 100
|
|
817
|
-
},
|
|
818
|
-
"x": {
|
|
819
|
-
type: Number
|
|
820
|
-
},
|
|
821
|
-
"y": {
|
|
822
|
-
type: Number
|
|
823
|
-
},
|
|
824
|
-
"disabled": {
|
|
825
|
-
type: Boolean
|
|
826
|
-
},
|
|
827
|
-
"getDisabled": {
|
|
828
|
-
type: Function
|
|
829
|
-
},
|
|
830
|
-
"displayDirective": {
|
|
831
|
-
type: String,
|
|
832
|
-
default: "if"
|
|
833
|
-
},
|
|
834
|
-
"zIndex": {
|
|
835
|
-
type: Number
|
|
836
|
-
},
|
|
837
|
-
"internalSyncTargetWithParent": {
|
|
838
|
-
type: Boolean
|
|
839
|
-
},
|
|
840
|
-
"internalInheritedEventHandlers": {
|
|
841
|
-
type: Array,
|
|
842
|
-
default: () => []
|
|
843
|
-
},
|
|
844
|
-
"internalTrapFocus": {
|
|
845
|
-
type: Boolean
|
|
846
|
-
},
|
|
847
|
-
"onClickoutside": {
|
|
848
|
-
type: Function
|
|
849
|
-
},
|
|
850
|
-
"onUpdate:show": {
|
|
851
|
-
type: [Function, Array]
|
|
852
|
-
},
|
|
853
|
-
"onUpdateShow": {
|
|
854
|
-
type: [Function, Array]
|
|
855
|
-
},
|
|
856
|
-
"onShow": {
|
|
857
|
-
type: [Function, Array]
|
|
858
|
-
},
|
|
859
|
-
"onHide": {
|
|
860
|
-
type: [Function, Array]
|
|
861
|
-
},
|
|
862
|
-
"internalRenderBody": {
|
|
863
|
-
type: Function
|
|
326
|
+
const DestylerPopoverPortal = vue.defineComponent({
|
|
327
|
+
name: "DestylerPopoverPortal",
|
|
328
|
+
props: destylerPopoverPortalProps,
|
|
329
|
+
render() {
|
|
330
|
+
return vue.h(teleport.DestylerTeleport, vue.mergeProps(this.$props), this.$slots.default?.());
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
const destylerPopoverTriggerProps = {
|
|
335
|
+
...primitive.destylerPrimitiveProp,
|
|
336
|
+
as: {
|
|
337
|
+
type: [String, Object],
|
|
338
|
+
required: false,
|
|
339
|
+
default: "button"
|
|
864
340
|
}
|
|
865
341
|
};
|
|
866
|
-
const
|
|
867
|
-
name: "
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
const controlledShow = vue.computed(() => props.show);
|
|
875
|
-
const uncontrolledShow = vue.ref(props.defaultShow);
|
|
876
|
-
const mergedShowWithoutDisabled = composition.useMergedState(
|
|
877
|
-
controlledShow,
|
|
878
|
-
uncontrolledShow
|
|
879
|
-
);
|
|
880
|
-
const mergedShowConsideringDisabledProp = composition.useMemo(() => {
|
|
881
|
-
if (props.disabled)
|
|
882
|
-
return false;
|
|
883
|
-
return mergedShowWithoutDisabled.value;
|
|
884
|
-
});
|
|
885
|
-
const getMergedDisabled = () => {
|
|
886
|
-
if (props.disabled)
|
|
887
|
-
return true;
|
|
888
|
-
const { getDisabled } = props;
|
|
889
|
-
if (getDisabled?.())
|
|
890
|
-
return true;
|
|
891
|
-
return false;
|
|
892
|
-
};
|
|
893
|
-
const getMergedShow = () => {
|
|
894
|
-
if (getMergedDisabled())
|
|
895
|
-
return false;
|
|
896
|
-
return mergedShowWithoutDisabled.value;
|
|
897
|
-
};
|
|
898
|
-
const showTimerId = vue.ref(null);
|
|
899
|
-
const hideTimerId = vue.ref(null);
|
|
900
|
-
const positionManually = composition.useMemo(() => {
|
|
901
|
-
return props.x !== void 0 && props.y !== void 0;
|
|
902
|
-
});
|
|
903
|
-
function doUpdateShow(value) {
|
|
904
|
-
const {
|
|
905
|
-
"onUpdate:show": _onUpdateShow,
|
|
906
|
-
onUpdateShow,
|
|
907
|
-
onShow,
|
|
908
|
-
onHide
|
|
909
|
-
} = props;
|
|
910
|
-
uncontrolledShow.value = value;
|
|
911
|
-
if (_onUpdateShow)
|
|
912
|
-
shared.call(_onUpdateShow, value);
|
|
913
|
-
if (onUpdateShow)
|
|
914
|
-
shared.call(onUpdateShow, value);
|
|
915
|
-
if (value && onShow)
|
|
916
|
-
shared.call(onShow, true);
|
|
917
|
-
if (value && onHide)
|
|
918
|
-
shared.call(onHide, false);
|
|
919
|
-
}
|
|
920
|
-
function clearShowTimer() {
|
|
921
|
-
if (showTimerId.value) {
|
|
922
|
-
window.clearTimeout(showTimerId.value);
|
|
923
|
-
showTimerId.value = null;
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
function clearHideTimer() {
|
|
927
|
-
if (hideTimerId.value) {
|
|
928
|
-
window.clearTimeout(hideTimerId.value);
|
|
929
|
-
hideTimerId.value = null;
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
function handleFocus() {
|
|
933
|
-
const mergedDisabled = getMergedDisabled();
|
|
934
|
-
if (props.trigger === "focus" && !mergedDisabled) {
|
|
935
|
-
if (getMergedShow())
|
|
936
|
-
return;
|
|
937
|
-
doUpdateShow(true);
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
function handleBlur() {
|
|
941
|
-
const mergedDisabled = getMergedDisabled();
|
|
942
|
-
if (props.trigger === "focus" && !mergedDisabled) {
|
|
943
|
-
if (!getMergedShow())
|
|
944
|
-
return;
|
|
945
|
-
doUpdateShow(false);
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
function handleMouseEnter() {
|
|
949
|
-
const mergedDisabled = getMergedDisabled();
|
|
950
|
-
if (props.trigger === "hover" && !mergedDisabled) {
|
|
951
|
-
clearHideTimer();
|
|
952
|
-
if (showTimerId.value !== null)
|
|
953
|
-
return;
|
|
954
|
-
if (getMergedShow())
|
|
955
|
-
return;
|
|
956
|
-
const delayCallback = () => {
|
|
957
|
-
doUpdateShow(true);
|
|
958
|
-
showTimerId.value = null;
|
|
959
|
-
};
|
|
960
|
-
const { delay } = props;
|
|
961
|
-
if (delay === 0)
|
|
962
|
-
delayCallback();
|
|
963
|
-
else
|
|
964
|
-
showTimerId.value = window.setTimeout(delayCallback, delay);
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
function handleMouseLeave() {
|
|
968
|
-
const mergedDisabled = getMergedDisabled();
|
|
969
|
-
if (props.trigger === "hover" && !mergedDisabled) {
|
|
970
|
-
clearShowTimer();
|
|
971
|
-
if (hideTimerId.value !== null)
|
|
972
|
-
return;
|
|
973
|
-
if (!getMergedShow())
|
|
974
|
-
return;
|
|
975
|
-
const delayedCallback = () => {
|
|
976
|
-
doUpdateShow(false);
|
|
977
|
-
hideTimerId.value = null;
|
|
978
|
-
};
|
|
979
|
-
const { duration } = props;
|
|
980
|
-
if (duration === 0)
|
|
981
|
-
delayedCallback();
|
|
982
|
-
else
|
|
983
|
-
hideTimerId.value = window.setTimeout(delayedCallback, duration);
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
function handleMouseMoveOutside() {
|
|
987
|
-
handleMouseLeave();
|
|
988
|
-
}
|
|
989
|
-
function handleClickOutside(e) {
|
|
990
|
-
if (!getMergedShow())
|
|
991
|
-
return;
|
|
992
|
-
if (props.trigger === "click") {
|
|
993
|
-
clearShowTimer();
|
|
994
|
-
clearHideTimer();
|
|
995
|
-
doUpdateShow(false);
|
|
996
|
-
}
|
|
997
|
-
props.onClickoutside?.(e);
|
|
998
|
-
}
|
|
999
|
-
function handleClick() {
|
|
1000
|
-
if (props.trigger === "click" && !getMergedDisabled()) {
|
|
1001
|
-
clearShowTimer();
|
|
1002
|
-
clearHideTimer();
|
|
1003
|
-
const nextShow = !getMergedShow();
|
|
1004
|
-
doUpdateShow(nextShow);
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
function getTriggerElement() {
|
|
1008
|
-
return binderInst.value?.targetRef;
|
|
1009
|
-
}
|
|
1010
|
-
function setBodyInstance(value) {
|
|
1011
|
-
}
|
|
1012
|
-
vue.provide("DestylerPopover", {
|
|
1013
|
-
getTriggerElement,
|
|
1014
|
-
handleMouseEnter,
|
|
1015
|
-
handleMouseLeave,
|
|
1016
|
-
handleClickOutside,
|
|
1017
|
-
handleMouseMoveOutside,
|
|
1018
|
-
setBodyInstance,
|
|
1019
|
-
positionManually,
|
|
1020
|
-
isMounted,
|
|
1021
|
-
zIndex: vue.toRef(props, "zIndex"),
|
|
1022
|
-
internalRenderBody: vue.toRef(props, "internalRenderBody")
|
|
1023
|
-
});
|
|
1024
|
-
vue.watchEffect(() => {
|
|
1025
|
-
if (mergedShowWithoutDisabled.value && getMergedDisabled())
|
|
1026
|
-
doUpdateShow(false);
|
|
342
|
+
const DestylerPopoverTrigger = vue.defineComponent({
|
|
343
|
+
name: "DestylerPopoverTrigger",
|
|
344
|
+
props: destylerPopoverTriggerProps,
|
|
345
|
+
setup() {
|
|
346
|
+
const rootContext = injectPopoverRootContext();
|
|
347
|
+
const { customElement, currentElement: triggerElement } = composition.useCustomElement();
|
|
348
|
+
vue.onMounted(() => {
|
|
349
|
+
rootContext.triggerElement.value = triggerElement.value;
|
|
1027
350
|
});
|
|
1028
|
-
function setShow(value) {
|
|
1029
|
-
uncontrolledShow.value = value;
|
|
1030
|
-
}
|
|
1031
351
|
return {
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
mergedShowConsideringDisabledProp,
|
|
1035
|
-
// if to show popover body
|
|
1036
|
-
uncontrolledShow,
|
|
1037
|
-
setShow,
|
|
1038
|
-
getMergedShow,
|
|
1039
|
-
handleClick,
|
|
1040
|
-
handleMouseEnter,
|
|
1041
|
-
handleMouseLeave,
|
|
1042
|
-
handleFocus,
|
|
1043
|
-
handleBlur
|
|
352
|
+
rootContext,
|
|
353
|
+
customElement
|
|
1044
354
|
};
|
|
1045
355
|
},
|
|
1046
356
|
render() {
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
onMouseleave: this.handleMouseLeave,
|
|
1061
|
-
onFocus: this.handleFocus,
|
|
1062
|
-
onBlur: this.handleBlur
|
|
1063
|
-
};
|
|
1064
|
-
if (triggerVNode.type?.__popover__) {
|
|
1065
|
-
popoverInside = true;
|
|
1066
|
-
if (!triggerVNode.props) {
|
|
1067
|
-
triggerVNode.props = {
|
|
1068
|
-
internalSyncTargetWithParent: true,
|
|
1069
|
-
internalInheritedEventHandlers: []
|
|
1070
|
-
};
|
|
1071
|
-
}
|
|
1072
|
-
triggerVNode.props.internalSyncTargetWithParent = true;
|
|
1073
|
-
if (!triggerVNode.props.internalInheritedEventHandlers) {
|
|
1074
|
-
triggerVNode.props.internalInheritedEventHandlers = [handlers];
|
|
1075
|
-
} else {
|
|
1076
|
-
triggerVNode.props.internalInheritedEventHandlers = [
|
|
1077
|
-
handlers,
|
|
1078
|
-
...triggerVNode.props.internalInheritedEventHandlers
|
|
1079
|
-
];
|
|
1080
|
-
}
|
|
1081
|
-
} else {
|
|
1082
|
-
const { internalInheritedEventHandlers } = this.$props;
|
|
1083
|
-
const ascendantAndCurrentHandlers = [
|
|
1084
|
-
handlers,
|
|
1085
|
-
...internalInheritedEventHandlers
|
|
1086
|
-
];
|
|
1087
|
-
const mergedHandlers = {
|
|
1088
|
-
onBlur: (e) => {
|
|
1089
|
-
ascendantAndCurrentHandlers.forEach((_handlers) => {
|
|
1090
|
-
_handlers.onBlur(e);
|
|
1091
|
-
});
|
|
1092
|
-
},
|
|
1093
|
-
onFocus: (e) => {
|
|
1094
|
-
ascendantAndCurrentHandlers.forEach((_handlers) => {
|
|
1095
|
-
_handlers.onFocus(e);
|
|
1096
|
-
});
|
|
1097
|
-
},
|
|
1098
|
-
onClick: (e) => {
|
|
1099
|
-
ascendantAndCurrentHandlers.forEach((_handlers) => {
|
|
1100
|
-
_handlers.onClick(e);
|
|
1101
|
-
});
|
|
1102
|
-
},
|
|
1103
|
-
onMouseenter: (e) => {
|
|
1104
|
-
ascendantAndCurrentHandlers.forEach((_handlers) => {
|
|
1105
|
-
_handlers.onMouseenter(e);
|
|
1106
|
-
});
|
|
1107
|
-
},
|
|
1108
|
-
onMouseleave: (e) => {
|
|
1109
|
-
ascendantAndCurrentHandlers.forEach((_handlers) => {
|
|
1110
|
-
_handlers.onMouseleave(e);
|
|
1111
|
-
});
|
|
1112
|
-
}
|
|
1113
|
-
};
|
|
1114
|
-
appendEvents(
|
|
1115
|
-
triggerVNode,
|
|
1116
|
-
internalInheritedEventHandlers ? "nested" : this.positionManually ? "manual" : this.$props.trigger,
|
|
1117
|
-
mergedHandlers
|
|
1118
|
-
);
|
|
1119
|
-
}
|
|
357
|
+
return vue.h(this.rootContext.hasCustomAnchor.value ? primitive.DestylerPrimitive : popper.DestylerPopperAnchor, {
|
|
358
|
+
asChild: true
|
|
359
|
+
}, vue.h(primitive.DestylerPrimitive, {
|
|
360
|
+
"ref": "customElement",
|
|
361
|
+
"type": this.$props.as === "button" ? "button" : void 0,
|
|
362
|
+
"as": this.$props.as,
|
|
363
|
+
"aria-haspopup": "dialog",
|
|
364
|
+
"asChild": this.$props.asChild,
|
|
365
|
+
"aria-expanded": this.rootContext.open.value,
|
|
366
|
+
"aria-controls": this.rootContext.contentId,
|
|
367
|
+
"data-state": this.rootContext.open.value ? "open" : "closed",
|
|
368
|
+
"onClick": () => {
|
|
369
|
+
this.rootContext.onOpenToggle();
|
|
1120
370
|
}
|
|
1121
|
-
}
|
|
1122
|
-
return vue.h(DestylerBinder, {
|
|
1123
|
-
ref: "binderInst",
|
|
1124
|
-
syncTarget: !popoverInside,
|
|
1125
|
-
syncTargetWithParent: this.$props.internalSyncTargetWithParent
|
|
1126
|
-
}, () => {
|
|
1127
|
-
return [
|
|
1128
|
-
this.$props.internalTrapFocus && this.getMergedShow() ? vue.withDirectives(vue.h("div"), [[directives.zindexable, { enabled: this.getMergedShow(), zIndex: this.$props.zIndex }]]) : null,
|
|
1129
|
-
this.positionManually ? null : vue.h(DestylerTarget, null, {
|
|
1130
|
-
default: () => triggerVNode
|
|
1131
|
-
}),
|
|
1132
|
-
vue.h(DestylerPopoverBody, shared.keep(this.$props, bodyPropKeys, {
|
|
1133
|
-
...this.$attrs,
|
|
1134
|
-
show: this.getMergedShow()
|
|
1135
|
-
}), {
|
|
1136
|
-
default: () => this.$slots.default?.(),
|
|
1137
|
-
header: () => this.$slots.header?.(),
|
|
1138
|
-
footer: () => this.$slots.footer?.()
|
|
1139
|
-
})
|
|
1140
|
-
];
|
|
1141
|
-
});
|
|
371
|
+
}, this.$slots.default?.()));
|
|
1142
372
|
}
|
|
1143
373
|
});
|
|
1144
374
|
|
|
@@ -1155,8 +385,26 @@ function DestylerPopoverResolver() {
|
|
|
1155
385
|
};
|
|
1156
386
|
}
|
|
1157
387
|
|
|
1158
|
-
exports.
|
|
1159
|
-
exports.
|
|
388
|
+
exports.DestylerPopoverAnchor = DestylerPopoverAnchor;
|
|
389
|
+
exports.DestylerPopoverArrow = DestylerPopoverArrow;
|
|
390
|
+
exports.DestylerPopoverClose = DestylerPopoverClose;
|
|
391
|
+
exports.DestylerPopoverContent = DestylerPopoverContent;
|
|
392
|
+
exports.DestylerPopoverContentImpl = DestylerPopoverContentImpl;
|
|
393
|
+
exports.DestylerPopoverContentModal = DestylerPopoverContentModal;
|
|
394
|
+
exports.DestylerPopoverContentNonModal = DestylerPopoverContentNonModal;
|
|
395
|
+
exports.DestylerPopoverPortal = DestylerPopoverPortal;
|
|
1160
396
|
exports.DestylerPopoverResolver = DestylerPopoverResolver;
|
|
1161
|
-
exports.
|
|
1162
|
-
exports.
|
|
397
|
+
exports.DestylerPopoverRoot = DestylerPopoverRoot;
|
|
398
|
+
exports.DestylerPopoverTrigger = DestylerPopoverTrigger;
|
|
399
|
+
exports.destylerPopoverAnchorProps = destylerPopoverAnchorProps;
|
|
400
|
+
exports.destylerPopoverArrowProps = destylerPopoverArrowProps;
|
|
401
|
+
exports.destylerPopoverCloseProps = destylerPopoverCloseProps;
|
|
402
|
+
exports.destylerPopoverContentEmits = destylerPopoverContentEmits;
|
|
403
|
+
exports.destylerPopoverContentImplEmits = destylerPopoverContentImplEmits;
|
|
404
|
+
exports.destylerPopoverContentImplProps = destylerPopoverContentImplProps;
|
|
405
|
+
exports.destylerPopoverContentProps = destylerPopoverContentProps;
|
|
406
|
+
exports.destylerPopoverPortalProps = destylerPopoverPortalProps;
|
|
407
|
+
exports.destylerPopoverRootProps = destylerPopoverRootProps;
|
|
408
|
+
exports.destylerPopoverTriggerProps = destylerPopoverTriggerProps;
|
|
409
|
+
exports.injectPopoverRootContext = injectPopoverRootContext;
|
|
410
|
+
exports.providePopoverRootContext = providePopoverRootContext;
|