@destyler/popover 0.0.1-beta.8 → 0.0.1

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