@destyler/popover 0.0.1-beta.6 → 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 +326 -1089
- package/dist/index.d.cts +1342 -98
- package/dist/index.d.mts +1342 -98
- package/dist/index.d.ts +1342 -98
- package/dist/index.mjs +308 -1089
- package/package.json +11 -5
package/dist/index.cjs
CHANGED
|
@@ -1,1155 +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);
|
|
179
162
|
},
|
|
180
|
-
|
|
181
|
-
|
|
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);
|
|
174
|
+
},
|
|
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
|
-
|
|
288
|
+
const destylerPopoverContentProps = {
|
|
289
|
+
...destylerPopoverContentImplProps,
|
|
290
|
+
forceMount: {
|
|
291
|
+
type: Boolean,
|
|
586
292
|
required: false,
|
|
587
|
-
default:
|
|
588
|
-
},
|
|
589
|
-
show: {
|
|
590
|
-
type: Boolean
|
|
591
|
-
},
|
|
592
|
-
trigger: {
|
|
593
|
-
type: String
|
|
594
|
-
},
|
|
595
|
-
delay: {
|
|
596
|
-
type: Number
|
|
597
|
-
},
|
|
598
|
-
duration: {
|
|
599
|
-
type: Number
|
|
600
|
-
},
|
|
601
|
-
displayDirective: {
|
|
602
|
-
type: String
|
|
603
|
-
},
|
|
604
|
-
x: {
|
|
605
|
-
type: Number
|
|
606
|
-
},
|
|
607
|
-
y: {
|
|
608
|
-
type: Number
|
|
609
|
-
},
|
|
610
|
-
flip: {
|
|
611
|
-
type: Boolean
|
|
612
|
-
},
|
|
613
|
-
internalTrapFocus: {
|
|
614
|
-
type: Boolean
|
|
615
|
-
},
|
|
616
|
-
overlap: {
|
|
617
|
-
type: Boolean
|
|
618
|
-
},
|
|
619
|
-
keepAliveOnHover: {
|
|
620
|
-
type: Boolean
|
|
621
|
-
},
|
|
622
|
-
scrollable: {
|
|
623
|
-
type: Boolean
|
|
624
|
-
},
|
|
625
|
-
internalDeactivateImmediately: {
|
|
626
|
-
type: Boolean
|
|
627
|
-
},
|
|
628
|
-
onClickoutside: {
|
|
629
|
-
type: Function
|
|
293
|
+
default: false
|
|
630
294
|
}
|
|
631
295
|
};
|
|
632
|
-
const
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
const
|
|
639
|
-
const
|
|
640
|
-
const displayed = vue.ref(false);
|
|
641
|
-
vue.watchEffect(() => {
|
|
642
|
-
const { show } = props;
|
|
643
|
-
if (show && !shared.isJsdom() && !props.internalDeactivateImmediately)
|
|
644
|
-
displayed.value = true;
|
|
645
|
-
else
|
|
646
|
-
displayed.value = false;
|
|
647
|
-
});
|
|
648
|
-
vue.onBeforeUnmount(() => {
|
|
649
|
-
DestylerPopover.setBodyInstance(null);
|
|
650
|
-
});
|
|
651
|
-
vue.watch(vue.toRef(props, "show"), (value) => {
|
|
652
|
-
if (value)
|
|
653
|
-
followerEnabled.value = true;
|
|
654
|
-
else
|
|
655
|
-
followerEnabled.value = false;
|
|
656
|
-
});
|
|
657
|
-
function syncPosition() {
|
|
658
|
-
follower.value?.syncPosition();
|
|
659
|
-
}
|
|
660
|
-
DestylerPopover.setBodyInstance({
|
|
661
|
-
syncPosition
|
|
662
|
-
});
|
|
663
|
-
function handleMouseEnter(e) {
|
|
664
|
-
if (props.trigger === "hover" && props.keepAliveOnHover && props.show)
|
|
665
|
-
DestylerPopover.handleMouseEnter(e);
|
|
666
|
-
}
|
|
667
|
-
function handleMouseLeave(e) {
|
|
668
|
-
if (props.trigger === "hover" && props.keepAliveOnHover)
|
|
669
|
-
DestylerPopover.handleMouseLeave(e);
|
|
670
|
-
}
|
|
671
|
-
function handleMouseMoveOutside(e) {
|
|
672
|
-
if (props.trigger === "hover" && !getTriggerElement().contains(shared.getPreciseEventTarget(e)))
|
|
673
|
-
DestylerPopover.handleMouseMoveOutside(e);
|
|
674
|
-
}
|
|
675
|
-
function getTriggerElement() {
|
|
676
|
-
return DestylerPopover.getTriggerElement();
|
|
677
|
-
}
|
|
678
|
-
function handleClickOutside(e) {
|
|
679
|
-
if (props.trigger === "click" && !getTriggerElement().contains(
|
|
680
|
-
shared.getPreciseEventTarget(e)
|
|
681
|
-
) || props.onClickoutside)
|
|
682
|
-
DestylerPopover.handleClickOutside(e);
|
|
683
|
-
}
|
|
684
|
-
const directives$1 = vue.computed(() => {
|
|
685
|
-
const { trigger, onClickoutside } = props;
|
|
686
|
-
const directives2 = [];
|
|
687
|
-
const {
|
|
688
|
-
positionManually: { value: positionManually }
|
|
689
|
-
} = DestylerPopover;
|
|
690
|
-
if (!positionManually) {
|
|
691
|
-
if (trigger === "click" && !onClickoutside) {
|
|
692
|
-
directives2.push([
|
|
693
|
-
directives.clickoutside,
|
|
694
|
-
handleClickOutside,
|
|
695
|
-
void 0,
|
|
696
|
-
{ capture: true }
|
|
697
|
-
]);
|
|
698
|
-
}
|
|
699
|
-
if (trigger === "hover")
|
|
700
|
-
directives2.push([directives.mousemoveoutside, handleMouseMoveOutside]);
|
|
701
|
-
}
|
|
702
|
-
if (onClickoutside) {
|
|
703
|
-
directives2.push([
|
|
704
|
-
directives.clickoutside,
|
|
705
|
-
handleClickOutside,
|
|
706
|
-
void 0,
|
|
707
|
-
{ capture: true }
|
|
708
|
-
]);
|
|
709
|
-
}
|
|
710
|
-
if (props.displayDirective === "show" || displayed.value)
|
|
711
|
-
directives2.push([vue.vShow, props.show]);
|
|
712
|
-
return directives2;
|
|
713
|
-
});
|
|
714
|
-
function renderContentNode() {
|
|
715
|
-
const shouldRenderDom = props.displayDirective === "show" || props.show || displayed.value;
|
|
716
|
-
if (!shouldRenderDom)
|
|
717
|
-
return null;
|
|
718
|
-
let contentNode;
|
|
719
|
-
const renderBody = DestylerPopover.internalRenderBody.value;
|
|
720
|
-
if (!renderBody) {
|
|
721
|
-
const { internalTrapFocus } = props;
|
|
722
|
-
const hasHeaderOrFooter = !shared.isSlotEmpty(slots.header) || !shared.isSlotEmpty(slots.footer);
|
|
723
|
-
const renderContentInnerNode = () => {
|
|
724
|
-
const body2 = hasHeaderOrFooter ? [
|
|
725
|
-
shared.resolveWrappedSlot(slots.header, (children) => {
|
|
726
|
-
return children ? vue.h("div", null, children) : null;
|
|
727
|
-
}),
|
|
728
|
-
shared.resolveWrappedSlot(slots.default, (children) => {
|
|
729
|
-
return children ? vue.h("div", null, children) : null;
|
|
730
|
-
}),
|
|
731
|
-
shared.resolveWrappedSlot(slots.footer, (children) => {
|
|
732
|
-
return children ? vue.h("div", null, children) : null;
|
|
733
|
-
})
|
|
734
|
-
] : vue.h("div", {
|
|
735
|
-
destyler: `${props.name}-body-content`
|
|
736
|
-
}, slots);
|
|
737
|
-
return [body2];
|
|
738
|
-
};
|
|
739
|
-
contentNode = vue.h("div", vue.mergeProps({
|
|
740
|
-
ref: body,
|
|
741
|
-
destyler: `${props.name}-body-toggle`,
|
|
742
|
-
onMouseenter: handleMouseEnter,
|
|
743
|
-
onMouseleave: handleMouseLeave
|
|
744
|
-
}, attrs), internalTrapFocus ? vue.h(DestylerFocusTrap, {
|
|
745
|
-
active: props.show,
|
|
746
|
-
autoFocus: true
|
|
747
|
-
}, renderContentInnerNode) : renderContentInnerNode());
|
|
748
|
-
} else {
|
|
749
|
-
contentNode = renderBody(body, handleMouseEnter, handleMouseLeave);
|
|
750
|
-
}
|
|
751
|
-
return vue.withDirectives(contentNode, directives$1.value);
|
|
752
|
-
}
|
|
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);
|
|
753
304
|
return {
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
zIndex: DestylerPopover.zIndex,
|
|
757
|
-
follower,
|
|
758
|
-
followerEnabled,
|
|
759
|
-
renderContentNode
|
|
305
|
+
rootContext,
|
|
306
|
+
forwarded
|
|
760
307
|
};
|
|
761
308
|
},
|
|
762
309
|
render() {
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
}, () => 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?.()));
|
|
774
320
|
}
|
|
775
321
|
});
|
|
776
322
|
|
|
777
|
-
const
|
|
778
|
-
|
|
779
|
-
focus: ["onFocus", "onBlur"],
|
|
780
|
-
click: ["onClick"],
|
|
781
|
-
hover: ["onMouseenter", "onMouseleave"],
|
|
782
|
-
manual: [],
|
|
783
|
-
nested: ["onFocus", "onBlur", "onMouseenter", "onMouseleave", "onClick"]
|
|
323
|
+
const destylerPopoverPortalProps = {
|
|
324
|
+
...teleport.destylerTeleportProps
|
|
784
325
|
};
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
originalHandler(...args);
|
|
798
|
-
handler(...args);
|
|
799
|
-
};
|
|
800
|
-
}
|
|
801
|
-
});
|
|
802
|
-
}
|
|
803
|
-
const destylerPopoverProps = {
|
|
804
|
-
"name": {
|
|
805
|
-
type: String,
|
|
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],
|
|
806
338
|
required: false,
|
|
807
|
-
default: "
|
|
808
|
-
},
|
|
809
|
-
"show": {
|
|
810
|
-
type: Boolean,
|
|
811
|
-
default: void 0
|
|
812
|
-
},
|
|
813
|
-
"defaultShow": {
|
|
814
|
-
type: Boolean
|
|
815
|
-
},
|
|
816
|
-
"trigger": {
|
|
817
|
-
type: String,
|
|
818
|
-
default: "hover"
|
|
819
|
-
},
|
|
820
|
-
"delay": {
|
|
821
|
-
type: Number,
|
|
822
|
-
default: 100
|
|
823
|
-
},
|
|
824
|
-
"duration": {
|
|
825
|
-
type: Number,
|
|
826
|
-
default: 100
|
|
827
|
-
},
|
|
828
|
-
"x": {
|
|
829
|
-
type: Number
|
|
830
|
-
},
|
|
831
|
-
"y": {
|
|
832
|
-
type: Number
|
|
833
|
-
},
|
|
834
|
-
"disabled": {
|
|
835
|
-
type: Boolean
|
|
836
|
-
},
|
|
837
|
-
"getDisabled": {
|
|
838
|
-
type: Function
|
|
839
|
-
},
|
|
840
|
-
"displayDirective": {
|
|
841
|
-
type: String,
|
|
842
|
-
default: "if"
|
|
843
|
-
},
|
|
844
|
-
"zIndex": {
|
|
845
|
-
type: Number
|
|
846
|
-
},
|
|
847
|
-
"internalSyncTargetWithParent": {
|
|
848
|
-
type: Boolean
|
|
849
|
-
},
|
|
850
|
-
"internalInheritedEventHandlers": {
|
|
851
|
-
type: Array,
|
|
852
|
-
default: () => []
|
|
853
|
-
},
|
|
854
|
-
"internalTrapFocus": {
|
|
855
|
-
type: Boolean
|
|
856
|
-
},
|
|
857
|
-
"onClickoutside": {
|
|
858
|
-
type: Function
|
|
859
|
-
},
|
|
860
|
-
"onUpdate:show": {
|
|
861
|
-
type: [Function, Array]
|
|
862
|
-
},
|
|
863
|
-
"onUpdateShow": {
|
|
864
|
-
type: [Function, Array]
|
|
865
|
-
},
|
|
866
|
-
"onShow": {
|
|
867
|
-
type: [Function, Array]
|
|
868
|
-
},
|
|
869
|
-
"onHide": {
|
|
870
|
-
type: [Function, Array]
|
|
871
|
-
},
|
|
872
|
-
"internalRenderBody": {
|
|
873
|
-
type: Function
|
|
339
|
+
default: "button"
|
|
874
340
|
}
|
|
875
341
|
};
|
|
876
|
-
const
|
|
877
|
-
name: "
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
const controlledShow = vue.computed(() => props.show);
|
|
885
|
-
const uncontrolledShow = vue.ref(props.defaultShow);
|
|
886
|
-
const mergedShowWithoutDisabled = composition.useMergedState(
|
|
887
|
-
controlledShow,
|
|
888
|
-
uncontrolledShow
|
|
889
|
-
);
|
|
890
|
-
const mergedShowConsideringDisabledProp = composition.useMemo(() => {
|
|
891
|
-
if (props.disabled)
|
|
892
|
-
return false;
|
|
893
|
-
return mergedShowWithoutDisabled.value;
|
|
894
|
-
});
|
|
895
|
-
const getMergedDisabled = () => {
|
|
896
|
-
if (props.disabled)
|
|
897
|
-
return true;
|
|
898
|
-
const { getDisabled } = props;
|
|
899
|
-
if (getDisabled?.())
|
|
900
|
-
return true;
|
|
901
|
-
return false;
|
|
902
|
-
};
|
|
903
|
-
const getMergedShow = () => {
|
|
904
|
-
if (getMergedDisabled())
|
|
905
|
-
return false;
|
|
906
|
-
return mergedShowWithoutDisabled.value;
|
|
907
|
-
};
|
|
908
|
-
const showTimerId = vue.ref(null);
|
|
909
|
-
const hideTimerId = vue.ref(null);
|
|
910
|
-
const positionManually = composition.useMemo(() => {
|
|
911
|
-
return props.x !== void 0 && props.y !== void 0;
|
|
912
|
-
});
|
|
913
|
-
function doUpdateShow(value) {
|
|
914
|
-
const {
|
|
915
|
-
"onUpdate:show": _onUpdateShow,
|
|
916
|
-
onUpdateShow,
|
|
917
|
-
onShow,
|
|
918
|
-
onHide
|
|
919
|
-
} = props;
|
|
920
|
-
uncontrolledShow.value = value;
|
|
921
|
-
if (_onUpdateShow)
|
|
922
|
-
shared.call(_onUpdateShow, value);
|
|
923
|
-
if (onUpdateShow)
|
|
924
|
-
shared.call(onUpdateShow, value);
|
|
925
|
-
if (value && onShow)
|
|
926
|
-
shared.call(onShow, true);
|
|
927
|
-
if (value && onHide)
|
|
928
|
-
shared.call(onHide, false);
|
|
929
|
-
}
|
|
930
|
-
function clearShowTimer() {
|
|
931
|
-
if (showTimerId.value) {
|
|
932
|
-
window.clearTimeout(showTimerId.value);
|
|
933
|
-
showTimerId.value = null;
|
|
934
|
-
}
|
|
935
|
-
}
|
|
936
|
-
function clearHideTimer() {
|
|
937
|
-
if (hideTimerId.value) {
|
|
938
|
-
window.clearTimeout(hideTimerId.value);
|
|
939
|
-
hideTimerId.value = null;
|
|
940
|
-
}
|
|
941
|
-
}
|
|
942
|
-
function handleFocus() {
|
|
943
|
-
const mergedDisabled = getMergedDisabled();
|
|
944
|
-
if (props.trigger === "focus" && !mergedDisabled) {
|
|
945
|
-
if (getMergedShow())
|
|
946
|
-
return;
|
|
947
|
-
doUpdateShow(true);
|
|
948
|
-
}
|
|
949
|
-
}
|
|
950
|
-
function handleBlur() {
|
|
951
|
-
const mergedDisabled = getMergedDisabled();
|
|
952
|
-
if (props.trigger === "focus" && !mergedDisabled) {
|
|
953
|
-
if (!getMergedShow())
|
|
954
|
-
return;
|
|
955
|
-
doUpdateShow(false);
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
function handleMouseEnter() {
|
|
959
|
-
const mergedDisabled = getMergedDisabled();
|
|
960
|
-
if (props.trigger === "hover" && !mergedDisabled) {
|
|
961
|
-
clearHideTimer();
|
|
962
|
-
if (showTimerId.value !== null)
|
|
963
|
-
return;
|
|
964
|
-
if (getMergedShow())
|
|
965
|
-
return;
|
|
966
|
-
const delayCallback = () => {
|
|
967
|
-
doUpdateShow(true);
|
|
968
|
-
showTimerId.value = null;
|
|
969
|
-
};
|
|
970
|
-
const { delay } = props;
|
|
971
|
-
if (delay === 0)
|
|
972
|
-
delayCallback();
|
|
973
|
-
else
|
|
974
|
-
showTimerId.value = window.setTimeout(delayCallback, delay);
|
|
975
|
-
}
|
|
976
|
-
}
|
|
977
|
-
function handleMouseLeave() {
|
|
978
|
-
const mergedDisabled = getMergedDisabled();
|
|
979
|
-
if (props.trigger === "hover" && !mergedDisabled) {
|
|
980
|
-
clearShowTimer();
|
|
981
|
-
if (hideTimerId.value !== null)
|
|
982
|
-
return;
|
|
983
|
-
if (!getMergedShow())
|
|
984
|
-
return;
|
|
985
|
-
const delayedCallback = () => {
|
|
986
|
-
doUpdateShow(false);
|
|
987
|
-
hideTimerId.value = null;
|
|
988
|
-
};
|
|
989
|
-
const { duration } = props;
|
|
990
|
-
if (duration === 0)
|
|
991
|
-
delayedCallback();
|
|
992
|
-
else
|
|
993
|
-
hideTimerId.value = window.setTimeout(delayedCallback, duration);
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
function handleMouseMoveOutside() {
|
|
997
|
-
handleMouseLeave();
|
|
998
|
-
}
|
|
999
|
-
function handleClickOutside(e) {
|
|
1000
|
-
if (!getMergedShow())
|
|
1001
|
-
return;
|
|
1002
|
-
if (props.trigger === "click") {
|
|
1003
|
-
clearShowTimer();
|
|
1004
|
-
clearHideTimer();
|
|
1005
|
-
doUpdateShow(false);
|
|
1006
|
-
}
|
|
1007
|
-
props.onClickoutside?.(e);
|
|
1008
|
-
}
|
|
1009
|
-
function handleClick() {
|
|
1010
|
-
if (props.trigger === "click" && !getMergedDisabled()) {
|
|
1011
|
-
clearShowTimer();
|
|
1012
|
-
clearHideTimer();
|
|
1013
|
-
const nextShow = !getMergedShow();
|
|
1014
|
-
doUpdateShow(nextShow);
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
function getTriggerElement() {
|
|
1018
|
-
return binderInst.value?.targetRef;
|
|
1019
|
-
}
|
|
1020
|
-
function setBodyInstance(value) {
|
|
1021
|
-
}
|
|
1022
|
-
vue.provide("DestylerPopover", {
|
|
1023
|
-
getTriggerElement,
|
|
1024
|
-
handleMouseEnter,
|
|
1025
|
-
handleMouseLeave,
|
|
1026
|
-
handleClickOutside,
|
|
1027
|
-
handleMouseMoveOutside,
|
|
1028
|
-
setBodyInstance,
|
|
1029
|
-
positionManually,
|
|
1030
|
-
isMounted,
|
|
1031
|
-
zIndex: vue.toRef(props, "zIndex"),
|
|
1032
|
-
internalRenderBody: vue.toRef(props, "internalRenderBody")
|
|
1033
|
-
});
|
|
1034
|
-
vue.watchEffect(() => {
|
|
1035
|
-
if (mergedShowWithoutDisabled.value && getMergedDisabled())
|
|
1036
|
-
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;
|
|
1037
350
|
});
|
|
1038
|
-
function setShow(value) {
|
|
1039
|
-
uncontrolledShow.value = value;
|
|
1040
|
-
}
|
|
1041
351
|
return {
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
mergedShowConsideringDisabledProp,
|
|
1045
|
-
// if to show popover body
|
|
1046
|
-
uncontrolledShow,
|
|
1047
|
-
setShow,
|
|
1048
|
-
getMergedShow,
|
|
1049
|
-
handleClick,
|
|
1050
|
-
handleMouseEnter,
|
|
1051
|
-
handleMouseLeave,
|
|
1052
|
-
handleFocus,
|
|
1053
|
-
handleBlur
|
|
352
|
+
rootContext,
|
|
353
|
+
customElement
|
|
1054
354
|
};
|
|
1055
355
|
},
|
|
1056
356
|
render() {
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
onMouseleave: this.handleMouseLeave,
|
|
1071
|
-
onFocus: this.handleFocus,
|
|
1072
|
-
onBlur: this.handleBlur
|
|
1073
|
-
};
|
|
1074
|
-
if (triggerVNode.type?.__popover__) {
|
|
1075
|
-
popoverInside = true;
|
|
1076
|
-
if (!triggerVNode.props) {
|
|
1077
|
-
triggerVNode.props = {
|
|
1078
|
-
internalSyncTargetWithParent: true,
|
|
1079
|
-
internalInheritedEventHandlers: []
|
|
1080
|
-
};
|
|
1081
|
-
}
|
|
1082
|
-
triggerVNode.props.internalSyncTargetWithParent = true;
|
|
1083
|
-
if (!triggerVNode.props.internalInheritedEventHandlers) {
|
|
1084
|
-
triggerVNode.props.internalInheritedEventHandlers = [handlers];
|
|
1085
|
-
} else {
|
|
1086
|
-
triggerVNode.props.internalInheritedEventHandlers = [
|
|
1087
|
-
handlers,
|
|
1088
|
-
...triggerVNode.props.internalInheritedEventHandlers
|
|
1089
|
-
];
|
|
1090
|
-
}
|
|
1091
|
-
} else {
|
|
1092
|
-
const { internalInheritedEventHandlers } = this.$props;
|
|
1093
|
-
const ascendantAndCurrentHandlers = [
|
|
1094
|
-
handlers,
|
|
1095
|
-
...internalInheritedEventHandlers
|
|
1096
|
-
];
|
|
1097
|
-
const mergedHandlers = {
|
|
1098
|
-
onBlur: (e) => {
|
|
1099
|
-
ascendantAndCurrentHandlers.forEach((_handlers) => {
|
|
1100
|
-
_handlers.onBlur(e);
|
|
1101
|
-
});
|
|
1102
|
-
},
|
|
1103
|
-
onFocus: (e) => {
|
|
1104
|
-
ascendantAndCurrentHandlers.forEach((_handlers) => {
|
|
1105
|
-
_handlers.onFocus(e);
|
|
1106
|
-
});
|
|
1107
|
-
},
|
|
1108
|
-
onClick: (e) => {
|
|
1109
|
-
ascendantAndCurrentHandlers.forEach((_handlers) => {
|
|
1110
|
-
_handlers.onClick(e);
|
|
1111
|
-
});
|
|
1112
|
-
},
|
|
1113
|
-
onMouseenter: (e) => {
|
|
1114
|
-
ascendantAndCurrentHandlers.forEach((_handlers) => {
|
|
1115
|
-
_handlers.onMouseenter(e);
|
|
1116
|
-
});
|
|
1117
|
-
},
|
|
1118
|
-
onMouseleave: (e) => {
|
|
1119
|
-
ascendantAndCurrentHandlers.forEach((_handlers) => {
|
|
1120
|
-
_handlers.onMouseleave(e);
|
|
1121
|
-
});
|
|
1122
|
-
}
|
|
1123
|
-
};
|
|
1124
|
-
appendEvents(
|
|
1125
|
-
triggerVNode,
|
|
1126
|
-
internalInheritedEventHandlers ? "nested" : this.positionManually ? "manual" : this.$props.trigger,
|
|
1127
|
-
mergedHandlers
|
|
1128
|
-
);
|
|
1129
|
-
}
|
|
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();
|
|
1130
370
|
}
|
|
1131
|
-
}
|
|
1132
|
-
return vue.h(DestylerBinder, {
|
|
1133
|
-
ref: "binderInst",
|
|
1134
|
-
syncTarget: !popoverInside,
|
|
1135
|
-
syncTargetWithParent: this.$props.internalSyncTargetWithParent
|
|
1136
|
-
}, () => {
|
|
1137
|
-
return [
|
|
1138
|
-
this.$props.internalTrapFocus && this.getMergedShow() ? vue.withDirectives(vue.h("div"), [[directives.zindexable, { enabled: this.getMergedShow(), zIndex: this.$props.zIndex }]]) : null,
|
|
1139
|
-
this.positionManually ? null : vue.h(DestylerTarget, null, {
|
|
1140
|
-
default: () => triggerVNode
|
|
1141
|
-
}),
|
|
1142
|
-
vue.h(DestylerPopoverBody, shared.keep(this.$props, bodyPropKeys, {
|
|
1143
|
-
...this.$attrs,
|
|
1144
|
-
name: this.$props.name,
|
|
1145
|
-
show: this.getMergedShow()
|
|
1146
|
-
}), {
|
|
1147
|
-
default: () => this.$slots.default?.(),
|
|
1148
|
-
header: () => this.$slots.header?.(),
|
|
1149
|
-
footer: () => this.$slots.footer?.()
|
|
1150
|
-
})
|
|
1151
|
-
];
|
|
1152
|
-
});
|
|
371
|
+
}, this.$slots.default?.()));
|
|
1153
372
|
}
|
|
1154
373
|
});
|
|
1155
374
|
|
|
@@ -1166,8 +385,26 @@ function DestylerPopoverResolver() {
|
|
|
1166
385
|
};
|
|
1167
386
|
}
|
|
1168
387
|
|
|
1169
|
-
exports.
|
|
1170
|
-
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;
|
|
1171
396
|
exports.DestylerPopoverResolver = DestylerPopoverResolver;
|
|
1172
|
-
exports.
|
|
1173
|
-
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;
|