@destyler/popover 0.0.0 → 0.0.1-beta.10

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.
@@ -0,0 +1,480 @@
1
+ 'use strict';
2
+
3
+ const vue = require('vue');
4
+ const popper = require('@destyler/popper');
5
+ const primitive = require('@destyler/primitive');
6
+ const shared = require('@destyler/shared');
7
+ const composition = require('@destyler/composition');
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');
13
+
14
+ const destylerPopoverArrowProps = {
15
+ asChild: {
16
+ type: Boolean,
17
+ required: false,
18
+ default: false
19
+ },
20
+ width: {
21
+ type: Number,
22
+ required: false,
23
+ default: 5
24
+ },
25
+ height: {
26
+ type: Number,
27
+ required: false,
28
+ default: 10
29
+ },
30
+ as: {
31
+ type: [String, Object],
32
+ required: false,
33
+ default: "svg"
34
+ }
35
+ };
36
+ const DestylerPopoverArrow = vue.defineComponent({
37
+ name: "DestylerPopoverArrow",
38
+ props: destylerPopoverArrowProps,
39
+ render() {
40
+ return vue.h(popper.DestylerPopperArrow, vue.mergeProps(this.$props, {}), this.$slots.default?.());
41
+ }
42
+ });
43
+
44
+ const [injectPopoverRootContext, providePopoverRootContext] = shared.createContext("DestylerPopoverRoot");
45
+ const destylerPopoverRootProps = {
46
+ defaultOpen: {
47
+ type: Boolean,
48
+ required: false,
49
+ default: false
50
+ },
51
+ open: {
52
+ type: Boolean,
53
+ required: false,
54
+ default: void 0
55
+ },
56
+ modal: {
57
+ type: Boolean,
58
+ required: false,
59
+ default: false
60
+ }
61
+ };
62
+ const DestylerPopoverRoot = vue.defineComponent({
63
+ name: "DestylerPopoverRoot",
64
+ props: destylerPopoverRootProps,
65
+ emits: ["update:open"],
66
+ setup(props, { emit }) {
67
+ const modalRef = vue.toRef(props.modal);
68
+ const openRef = composition.useVModel(props, "open", emit, {
69
+ defaultValue: props.defaultOpen,
70
+ passive: props.open === void 0
71
+ });
72
+ const triggerElement = vue.ref();
73
+ const hasCustomAnchor = vue.ref(false);
74
+ function handleUpdateOpen(value) {
75
+ openRef.value = value;
76
+ }
77
+ providePopoverRootContext({
78
+ contentId: composition.useId(),
79
+ modal: modalRef,
80
+ open: openRef,
81
+ onOpenChange: (value) => {
82
+ handleUpdateOpen(value);
83
+ },
84
+ onOpenToggle: () => {
85
+ handleUpdateOpen(!openRef.value);
86
+ },
87
+ triggerElement,
88
+ hasCustomAnchor
89
+ });
90
+ return {
91
+ openRef,
92
+ modalRef,
93
+ triggerElement,
94
+ hasCustomAnchor
95
+ };
96
+ },
97
+ render() {
98
+ return vue.h(popper.DestylerPopperRoot, this.$slots.default?.());
99
+ }
100
+ });
101
+
102
+ const destylerPopoverCloseProps = {
103
+ asChild: {
104
+ type: Boolean,
105
+ required: false,
106
+ default: false
107
+ },
108
+ as: {
109
+ type: [String, Object],
110
+ required: false,
111
+ default: "button"
112
+ }
113
+ };
114
+ const DestylerPopoverClose = vue.defineComponent({
115
+ name: "DestylerPopoverClose",
116
+ props: destylerPopoverCloseProps,
117
+ setup() {
118
+ const rootContext = injectPopoverRootContext();
119
+ return {
120
+ rootContext
121
+ };
122
+ },
123
+ render() {
124
+ return vue.h(primitive.DestylerPrimitive, {
125
+ as: this.$props.as,
126
+ asChild: this.$props.asChild,
127
+ type: this.$props.as === "button" ? "button" : void 0,
128
+ onClick: () => {
129
+ this.rootContext.onOpenChange(false);
130
+ }
131
+ }, this.$slots.default?.());
132
+ }
133
+ });
134
+
135
+ const destylerPopoverContentImplProps = {
136
+ side: {
137
+ type: String,
138
+ required: false,
139
+ default: "bottom"
140
+ },
141
+ sideOffset: {
142
+ type: Number,
143
+ required: false,
144
+ default: 0
145
+ },
146
+ align: {
147
+ type: String,
148
+ required: false,
149
+ default: "center"
150
+ },
151
+ alignOffset: {
152
+ type: Number,
153
+ required: false,
154
+ default: 0
155
+ },
156
+ avoidCollisions: {
157
+ type: Boolean,
158
+ required: false,
159
+ default: true
160
+ },
161
+ collisionBoundary: {
162
+ type: [Object, Array, null],
163
+ required: false,
164
+ default: () => []
165
+ },
166
+ collisionPadding: {
167
+ type: [Number, Object],
168
+ required: false,
169
+ default: 0
170
+ },
171
+ arrowPadding: {
172
+ type: Number,
173
+ required: false,
174
+ default: 0
175
+ },
176
+ sticky: {
177
+ type: String,
178
+ required: false,
179
+ default: "partial"
180
+ },
181
+ hideWhenDetached: {
182
+ type: Boolean,
183
+ required: false,
184
+ default: false
185
+ },
186
+ updatePositionStrategy: {
187
+ type: String,
188
+ required: false,
189
+ default: "optimized"
190
+ },
191
+ onPlaced: {
192
+ type: Function,
193
+ required: false
194
+ },
195
+ prioritizePosition: {
196
+ type: Boolean,
197
+ required: false,
198
+ default: false
199
+ },
200
+ as: {
201
+ type: [String, Object],
202
+ required: false,
203
+ default: "div"
204
+ },
205
+ asChild: {
206
+ type: Boolean,
207
+ required: false,
208
+ default: false
209
+ },
210
+ disableOutsidePointerEvents: {
211
+ type: Boolean,
212
+ required: false,
213
+ default: false
214
+ },
215
+ trapFocus: {
216
+ type: Boolean,
217
+ required: false,
218
+ default: false
219
+ }
220
+ };
221
+ const destylerPopoverContentImplEmits = ["escapeKeyDown", "pointerDownOutside", "focusOutside", "interactOutside", "dismiss", "openAutoFocus", "closeAutoFocus"];
222
+ const DestylerPopoverContentImpl = vue.defineComponent({
223
+ name: "DestylerPopoverContentImpl",
224
+ props: destylerPopoverContentImplProps,
225
+ emits: destylerPopoverContentImplEmits,
226
+ setup(props) {
227
+ const forwarded = composition.useForwardProps(props);
228
+ const rootContext = injectPopoverRootContext();
229
+ composition.useFocusGuards();
230
+ return {
231
+ rootContext,
232
+ forwarded
233
+ };
234
+ },
235
+ render() {
236
+ return vue.h(focusScope.DestylerFocusScope, {
237
+ asChild: true,
238
+ loop: true,
239
+ trapped: this.$props.trapFocus,
240
+ onMountAutoFocus: (event) => {
241
+ this.$emit("openAutoFocus", event);
242
+ },
243
+ onUnmountAutoFocus: (event) => {
244
+ this.$emit("closeAutoFocus", event);
245
+ }
246
+ }, vue.h(dismissableLayer.DestylerDismissableLayer, {
247
+ asChild: true,
248
+ disableOutsidePointerEvents: this.$props.disableOutsidePointerEvents,
249
+ onPointerDownOutside: (event) => {
250
+ this.$emit("pointerDownOutside", event);
251
+ },
252
+ onInteractOutside: (event) => {
253
+ this.$emit("interactOutside", event);
254
+ },
255
+ onEscapeKeyDown: (event) => {
256
+ this.$emit("escapeKeyDown", event);
257
+ },
258
+ onFocusOutside: (event) => {
259
+ this.$emit("focusOutside", event);
260
+ },
261
+ onDismiss: () => {
262
+ this.rootContext.onOpenChange(false);
263
+ }
264
+ }, vue.withDirectives(vue.h(popper.DestylerPopperContent, vue.mergeProps(this.forwarded, {
265
+ "data-state": this.rootContext.open.value ? "open" : "closed",
266
+ "role": "dialog",
267
+ "style": {
268
+ "--destyler_popover_content_transform_origin": "var(--destyler_popper_transform_origin)",
269
+ "--destyler_popover_content_available_width": "var(--destyler_popper_available_width)",
270
+ "--destyler_popover_content_available_height": "var(--destyler_popper_available_height)",
271
+ "--destyler_popover_trigger_width": "var(--destyler_popper_anchor_width)",
272
+ "--destyler_popover_trigger_height": "var(--destyler_popper_anchor_height)"
273
+ }
274
+ }), this.$slots.default?.()), [
275
+ [directives.BindOnceDirective, { id: this.rootContext.contentId }]
276
+ ])));
277
+ }
278
+ });
279
+
280
+ const DestylerPopoverContentModal = vue.defineComponent({
281
+ name: "DestylerPopoverContentModal",
282
+ props: destylerPopoverContentImplProps,
283
+ emits: destylerPopoverContentImplEmits,
284
+ setup(props, { emit }) {
285
+ const rootContext = injectPopoverRootContext();
286
+ const isRightClickOutsideRef = vue.ref(false);
287
+ const forwarded = composition.useForwardPropsEmits(props, emit);
288
+ const { customElement, currentElement } = composition.useCustomElement();
289
+ composition.useHideOthers(currentElement);
290
+ return {
291
+ rootContext,
292
+ forwarded,
293
+ isRightClickOutsideRef,
294
+ customElement
295
+ };
296
+ },
297
+ render() {
298
+ return vue.h(DestylerPopoverContentImpl, {
299
+ "ref": "customElement",
300
+ ...vue.mergeProps(this.forwarded),
301
+ "trapFocus": this.rootContext.open.value,
302
+ "disable-outside-pointer-events": "",
303
+ "onCloseAutoFocusPrevent": (event) => {
304
+ this.$emit("closeAutoFocus", event);
305
+ if (!this.isRightClickOutsideRef)
306
+ this.rootContext.triggerElement.value?.focus();
307
+ },
308
+ "onPointerDownOutside": (event) => {
309
+ this.$emit("pointerDownOutside", event);
310
+ const originalEvent = event.detail.originalEvent;
311
+ const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
312
+ const isRightClick = originalEvent.button === 2 || ctrlLeftClick;
313
+ this.isRightClickOutsideRef = isRightClick;
314
+ }
315
+ }, this.$slots.default?.());
316
+ }
317
+ });
318
+
319
+ const DestylerPopoverContentNonModal = vue.defineComponent({
320
+ name: "DestylerPopoverContentNonModal",
321
+ props: destylerPopoverContentImplProps,
322
+ emits: destylerPopoverContentImplEmits,
323
+ setup(props, { emit }) {
324
+ const rootContext = injectPopoverRootContext();
325
+ const hasInteractedOutsideRef = vue.ref(false);
326
+ const hasPointerDownOutsideRef = vue.ref(false);
327
+ const forwarded = composition.useForwardPropsEmits(props, emit);
328
+ return {
329
+ forwarded,
330
+ rootContext,
331
+ hasInteractedOutsideRef,
332
+ hasPointerDownOutsideRef
333
+ };
334
+ },
335
+ render() {
336
+ return vue.h(DestylerPopoverContentImpl, {
337
+ ...this.forwarded,
338
+ trapFocus: false,
339
+ disableOutsidePointerEvents: false,
340
+ onCloseAutoFocus: (event) => {
341
+ this.$emit("closeAutoFocus", event);
342
+ if (!event.defaultPrevented) {
343
+ if (!this.hasInteractedOutsideRef)
344
+ this.rootContext.triggerElement.value?.focus();
345
+ event.preventDefault();
346
+ }
347
+ this.hasInteractedOutsideRef = false;
348
+ this.hasPointerDownOutsideRef = false;
349
+ },
350
+ onInteractOutside: async (event) => {
351
+ this.$emit("interactOutside", event);
352
+ if (!event.defaultPrevented) {
353
+ this.hasInteractedOutsideRef = true;
354
+ if (event.detail.originalEvent.type === "pointerdown")
355
+ this.hasPointerDownOutsideRef = true;
356
+ }
357
+ const target = event.target;
358
+ const targetIsTrigger = this.rootContext.triggerElement.value?.contains(target);
359
+ if (targetIsTrigger)
360
+ event.preventDefault();
361
+ if (event.detail.originalEvent.type === "focusin" && this.hasPointerDownOutsideRef)
362
+ event.preventDefault();
363
+ }
364
+ }, this.$slots.default?.());
365
+ }
366
+ });
367
+
368
+ const destylerPopoverContentProps = {
369
+ ...destylerPopoverContentImplProps,
370
+ forceMount: {
371
+ type: Boolean,
372
+ required: false,
373
+ default: false
374
+ }
375
+ };
376
+ const destylerPopoverContentEmits = [...destylerPopoverContentImplEmits];
377
+ const DestylerPopoverContent = vue.defineComponent({
378
+ name: "DestylerPopoverContent",
379
+ props: destylerPopoverContentProps,
380
+ emits: destylerPopoverContentEmits,
381
+ setup(props, { emit }) {
382
+ const rootContext = injectPopoverRootContext();
383
+ const forwarded = composition.useForwardPropsEmits(props, emit);
384
+ return {
385
+ rootContext,
386
+ forwarded
387
+ };
388
+ },
389
+ render() {
390
+ const useVShow = this.rootContext.modal.value;
391
+ return vue.h(presence.DestylerPresence, {
392
+ present: this.forceMount || this.rootContext.open.value
393
+ }, useVShow ? vue.h(DestylerPopoverContentModal, {
394
+ ...this.forwarded
395
+ }, this.$slots.default?.()) : vue.h(DestylerPopoverContentNonModal, {
396
+ ...this.forwarded
397
+ }, this.$slots.default?.()));
398
+ }
399
+ });
400
+
401
+ const destylerPopoverPortalProps = {
402
+ to: {
403
+ type: [String, Object],
404
+ required: false,
405
+ default: "body"
406
+ },
407
+ disabled: {
408
+ type: Boolean,
409
+ required: false,
410
+ default: false
411
+ },
412
+ forceMount: {
413
+ type: Boolean,
414
+ required: false,
415
+ default: false
416
+ }
417
+ };
418
+ const DestylerPopoverPortal = vue.defineComponent({
419
+ name: "DestylerPopoverPortal",
420
+ props: destylerPopoverPortalProps,
421
+ render() {
422
+ return vue.h(teleport.DestylerTeleport, vue.mergeProps(this.$props), this.$slots.default?.());
423
+ }
424
+ });
425
+
426
+ const destylerPopoverTriggerProps = {
427
+ asChild: {
428
+ type: Boolean,
429
+ required: false,
430
+ default: false
431
+ },
432
+ as: {
433
+ type: [String, Object],
434
+ required: false,
435
+ default: "button"
436
+ }
437
+ };
438
+ const DestylerPopoverTrigger = vue.defineComponent({
439
+ name: "DestylerPopoverTrigger",
440
+ props: destylerPopoverTriggerProps,
441
+ setup() {
442
+ const rootContext = injectPopoverRootContext();
443
+ const { customElement, currentElement: triggerElement } = composition.useCustomElement();
444
+ vue.onMounted(() => {
445
+ rootContext.triggerElement.value = triggerElement.value;
446
+ });
447
+ return {
448
+ rootContext,
449
+ customElement
450
+ };
451
+ },
452
+ render() {
453
+ return vue.h(this.rootContext.hasCustomAnchor.value ? primitive.DestylerPrimitive : popper.DestylerPopperAnchor, {
454
+ asChild: true
455
+ }, vue.h(primitive.DestylerPrimitive, {
456
+ "ref": "customElement",
457
+ "type": this.$props.as === "button" ? "button" : void 0,
458
+ "as": this.$props.as,
459
+ "aria-haspopup": "dialog",
460
+ "asChild": this.$props.asChild,
461
+ "aria-expanded": this.rootContext.open.value,
462
+ "aria-controls": this.rootContext.contentId,
463
+ "data-state": this.rootContext.open.value ? "open" : "closed",
464
+ "onClick": () => {
465
+ this.rootContext.onOpenToggle();
466
+ }
467
+ }, this.$slots.default?.()));
468
+ }
469
+ });
470
+
471
+ exports.DestylerPopoverArrow = DestylerPopoverArrow;
472
+ exports.DestylerPopoverClose = DestylerPopoverClose;
473
+ exports.DestylerPopoverContent = DestylerPopoverContent;
474
+ exports.DestylerPopoverContentImpl = DestylerPopoverContentImpl;
475
+ exports.DestylerPopoverContentModal = DestylerPopoverContentModal;
476
+ exports.DestylerPopoverContentNonModal = DestylerPopoverContentNonModal;
477
+ exports.DestylerPopoverPortal = DestylerPopoverPortal;
478
+ exports.DestylerPopoverRoot = DestylerPopoverRoot;
479
+ exports.DestylerPopoverTrigger = DestylerPopoverTrigger;
480
+ exports.injectPopoverRootContext = injectPopoverRootContext;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@destyler/popover",
3
- "version": "0.0.0",
3
+ "version": "0.0.1-beta.10",
4
4
  "description": "unstyled popover component for vue",
5
5
  "author": "Elone Hoo <elonehoo@gmail.com>",
6
6
  "license": "MIT",
@@ -10,6 +10,16 @@
10
10
  "import": "./dist/index.mjs",
11
11
  "require": "./dist/index.cjs"
12
12
  },
13
+ "./resolver": {
14
+ "types": "./dist/resolver.d.ts",
15
+ "import": "./dist/resolver.mjs",
16
+ "require": "./dist/resolver.cjs"
17
+ },
18
+ "./component": {
19
+ "types": "./dist/component.d.ts",
20
+ "import": "./dist/component.mjs",
21
+ "require": "./dist/component.cjs"
22
+ },
13
23
  "./*": "./*"
14
24
  },
15
25
  "main": "dist/index.cjs",
@@ -20,12 +30,18 @@
20
30
  "dist"
21
31
  ],
22
32
  "peerDependencies": {
23
- "vue": "^3.3.4"
33
+ "vue": ">=3.3.4"
24
34
  },
25
35
  "dependencies": {
26
- "@destyler/composition": "0.0.1-beta.0",
27
- "@destyler/directives": "0.0.1-beta.0",
28
- "@destyler/shared": "0.0.1-beta.0"
36
+ "@destyler/directives": "0.0.1-beta.10",
37
+ "@destyler/focus-scope": "0.0.1-beta.10",
38
+ "@destyler/popper": "0.0.1-beta.10",
39
+ "@destyler/composition": "0.0.1-beta.10",
40
+ "@destyler/primitive": "0.0.1-beta.10",
41
+ "@destyler/shared": "0.0.1-beta.10",
42
+ "@destyler/teleport": "0.0.1-beta.10",
43
+ "@destyler/presence": "0.0.1-beta.10",
44
+ "@destyler/dismissable-layer": "0.0.1-beta.10"
29
45
  },
30
46
  "scripts": {
31
47
  "clear": "rimraf ./dist",