@destyler/popper 0.0.6 → 0.1.0

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.
@@ -1,451 +0,0 @@
1
- import { defineComponent, ref, watch, h, computed, watchEffect, mergeProps } from 'vue';
2
- import { createContext, computedEager } from '@destyler/shared';
3
- import { primitiveProps, Primitive } from '@destyler/primitive';
4
- import { useForwardExpose, useSize } from '@destyler/composition';
5
- import { offset, shift, limitShift, flip, size, arrow, hide, useFloating, autoUpdate } from '@floating-ui/vue';
6
- import { Arrow } from '@destyler/arrow';
7
- import { arrowProps } from '@destyler/arrow/component';
8
-
9
- const [injectPopperRootContext, providePopperRootContext] = createContext("DestylerPopperRoot");
10
- const PopperRoot = defineComponent({
11
- name: "PopperRoot",
12
- setup() {
13
- const anchor = ref();
14
- providePopperRootContext({
15
- anchor,
16
- onAnchorChange: (element) => anchor.value = element
17
- });
18
- },
19
- render() {
20
- return this.$slots.default?.();
21
- }
22
- });
23
-
24
- const popperAnchorProps = {
25
- ...primitiveProps,
26
- element: {
27
- type: Object,
28
- required: false
29
- }
30
- };
31
- const PopperAnchor = defineComponent({
32
- name: "DestylerPopperAnchor",
33
- props: popperAnchorProps,
34
- setup(props) {
35
- const { forwardRef, currentElement } = useForwardExpose();
36
- const rootContext = injectPopperRootContext();
37
- watch(currentElement, () => {
38
- rootContext.onAnchorChange(props.element ?? currentElement.value);
39
- });
40
- return {
41
- forwardRef
42
- };
43
- },
44
- render() {
45
- return h(Primitive, {
46
- as: this.$props.as,
47
- asChild: this.$props.asChild,
48
- ref: (el) => this.forwardRef(el)
49
- }, () => this.$slots.default?.());
50
- }
51
- });
52
-
53
- function isNotNull(value) {
54
- return value !== null;
55
- }
56
- function transformOrigin(options) {
57
- return {
58
- name: "transformOrigin",
59
- options,
60
- fn(data) {
61
- const { placement, rects, middlewareData } = data;
62
- const cannotCenterArrow = middlewareData.arrow?.centerOffset !== 0;
63
- const isArrowHidden = cannotCenterArrow;
64
- const arrowWidth = isArrowHidden ? 0 : options.arrowWidth;
65
- const arrowHeight = isArrowHidden ? 0 : options.arrowHeight;
66
- const [placedSide, placedAlign] = getSideAndAlignFromPlacement(placement);
67
- const noArrowAlign = { start: "0%", center: "50%", end: "100%" }[placedAlign];
68
- const arrowXCenter = (middlewareData.arrow?.x ?? 0) + arrowWidth / 2;
69
- const arrowYCenter = (middlewareData.arrow?.y ?? 0) + arrowHeight / 2;
70
- let x = "";
71
- let y = "";
72
- if (placedSide === "bottom") {
73
- x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`;
74
- y = `${-arrowHeight}px`;
75
- } else if (placedSide === "top") {
76
- x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`;
77
- y = `${rects.floating.height + arrowHeight}px`;
78
- } else if (placedSide === "right") {
79
- x = `${-arrowHeight}px`;
80
- y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`;
81
- } else if (placedSide === "left") {
82
- x = `${rects.floating.width + arrowHeight}px`;
83
- y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`;
84
- }
85
- return { data: { x, y } };
86
- }
87
- };
88
- }
89
- function getSideAndAlignFromPlacement(placement) {
90
- const [side, align = "center"] = placement.split("-");
91
- return [side, align];
92
- }
93
-
94
- const [injectPopperContentContext, providePopperContentContext] = createContext("DestylerPopperContent");
95
- const popperContentProps = {
96
- ...primitiveProps,
97
- /**
98
- * The preferred side of the trigger to render against when open.
99
- * Will be reversed when collisions occur and avoidCollisions
100
- * is enabled.
101
- *
102
- * @default bottom
103
- */
104
- side: {
105
- type: String,
106
- required: false,
107
- default: "bottom"
108
- },
109
- /**
110
- * The distance in pixels from the trigger.
111
- *
112
- * @default 0
113
- */
114
- sideOffset: {
115
- type: Number,
116
- required: false,
117
- default: 0
118
- },
119
- /**
120
- * The preferred alignment against the trigger.
121
- * May change when collisions occur.
122
- *
123
- * @default center
124
- */
125
- align: {
126
- type: String,
127
- required: false,
128
- default: "center"
129
- },
130
- /**
131
- * An offset in pixels from the `start` or `end` alignment options.
132
- *
133
- * @default 0
134
- */
135
- alignOffset: {
136
- type: Number,
137
- required: false,
138
- default: 0
139
- },
140
- /**
141
- * When `true`, overrides the side andalign preferences
142
- * to prevent collisions with boundary edges.
143
- *
144
- * @default true
145
- */
146
- avoidCollisions: {
147
- type: Boolean,
148
- required: false,
149
- default: true
150
- },
151
- /**
152
- * The element used as the collision boundary. By default
153
- * this is the viewport, though you can provide additional
154
- * element(s) to be included in this check.
155
- *
156
- * @default () => []
157
- */
158
- collisionBoundary: {
159
- type: [Object, Array, null],
160
- required: false,
161
- default: () => []
162
- },
163
- /**
164
- * The distance in pixels from the boundary edges where collision
165
- * detection should occur. Accepts a number (same for all sides),
166
- * or a partial padding object, for example: { top: 20, left: 20 }.
167
- *
168
- * @default 0
169
- */
170
- collisionPadding: {
171
- type: [Number, Object],
172
- required: false,
173
- default: 0
174
- },
175
- /**
176
- * The distance in pixels from the boundary edges where collision
177
- * detection should occur. Accepts a number (same for all sides),
178
- * or a partial padding object, for example: { top: 20, left: 20 }.
179
- *
180
- * @default 0
181
- */
182
- arrowPadding: {
183
- type: Number,
184
- required: false,
185
- default: 0
186
- },
187
- /**
188
- * The sticky behavior on the align axis. `partial` will keep the
189
- * content in the boundary as long as the trigger is at least partially
190
- * in the boundary whilst "always" will keep the content in the boundary
191
- * regardless.
192
- *
193
- * @default partial
194
- */
195
- sticky: {
196
- type: String,
197
- required: false,
198
- default: "partial"
199
- },
200
- /**
201
- * Whether to hide the content when the trigger becomes fully occluded.
202
- *
203
- * @default false
204
- */
205
- hideWhenDetached: {
206
- type: Boolean,
207
- required: false,
208
- default: false
209
- },
210
- /**
211
- * Strategy to update the position of the floating element on every animation frame.
212
- *
213
- * @default optimized
214
- */
215
- updatePositionStrategy: {
216
- type: String,
217
- required: false,
218
- default: "optimized"
219
- },
220
- /**
221
- * Force content to be position within the viewport.
222
- *
223
- * Might overlap the reference element, which may not be desired.
224
- *
225
- * @default false
226
- */
227
- prioritizePosition: {
228
- type: Boolean,
229
- required: false,
230
- default: false
231
- }
232
- };
233
- const popperContentEmits = {
234
- placed: () => true
235
- };
236
- const PopperContent = defineComponent({
237
- name: "DestylerPopperContent",
238
- inheritAttrs: false,
239
- props: popperContentProps,
240
- emits: popperContentEmits,
241
- setup(props, { attrs, emit }) {
242
- const rootContext = injectPopperRootContext();
243
- const { forwardRef, currentElement: contentElement } = useForwardExpose();
244
- const floatingRef = ref();
245
- const arrow$1 = ref();
246
- const { width: arrowWidth, height: arrowHeight } = useSize(arrow$1);
247
- const desiredPlacement = computed(() => props.side + (props.align !== "center" ? `-${props.align}` : ""));
248
- const collisionPadding = computed(() => {
249
- return typeof props.collisionPadding === "number" ? props.collisionPadding : { top: 0, right: 0, bottom: 0, left: 0, ...props.collisionPadding };
250
- });
251
- const boundary = computed(() => {
252
- return Array.isArray(props.collisionBoundary) ? props.collisionBoundary : [props.collisionBoundary];
253
- });
254
- const detectOverflowOptions = computed(() => {
255
- return {
256
- padding: collisionPadding.value,
257
- boundary: boundary.value.filter(isNotNull),
258
- // with `strategy: 'fixed'`, this is the only way to get it to respect boundaries
259
- altBoundary: boundary.value.length > 0
260
- };
261
- });
262
- const computedMiddleware = computedEager(() => {
263
- return [
264
- offset({
265
- mainAxis: props.sideOffset + arrowHeight.value,
266
- alignmentAxis: props.alignOffset
267
- }),
268
- props.avoidCollisions && shift({
269
- mainAxis: true,
270
- crossAxis: !!props.prioritizePosition,
271
- limiter: props.sticky === "partial" ? limitShift() : void 0,
272
- ...detectOverflowOptions.value
273
- }),
274
- !props.prioritizePosition && props.avoidCollisions && flip({
275
- ...detectOverflowOptions.value
276
- }),
277
- size({
278
- ...detectOverflowOptions.value,
279
- apply: ({ elements, rects, availableWidth, availableHeight }) => {
280
- const { width: anchorWidth, height: anchorHeight } = rects.reference;
281
- const contentStyle = elements.floating.style;
282
- Object.assign(elements.floating.style, {
283
- maxWidth: `${availableWidth}px`,
284
- maxHeight: `${availableHeight}px`
285
- });
286
- contentStyle.setProperty(
287
- "--destyler-popper-available-width",
288
- `${availableWidth}px`
289
- );
290
- contentStyle.setProperty(
291
- "--destyler-popper-available-height",
292
- `${availableHeight}px`
293
- );
294
- contentStyle.setProperty(
295
- "--destyler-popper-anchor-width",
296
- `${anchorWidth}px`
297
- );
298
- contentStyle.setProperty(
299
- "--destyler-popper-anchor-height",
300
- `${anchorHeight}px`
301
- );
302
- }
303
- }),
304
- arrow$1.value && arrow({ element: arrow$1.value, padding: props.arrowPadding }),
305
- transformOrigin({
306
- arrowWidth: arrowWidth.value,
307
- arrowHeight: arrowHeight.value
308
- }),
309
- props.hideWhenDetached && hide({ strategy: "referenceHidden", ...detectOverflowOptions.value })
310
- ];
311
- });
312
- const { floatingStyles, placement, isPositioned, middlewareData } = useFloating(
313
- rootContext.anchor,
314
- floatingRef,
315
- {
316
- strategy: "fixed",
317
- placement: desiredPlacement,
318
- whileElementsMounted: (...args) => {
319
- const cleanup = autoUpdate(...args, {
320
- animationFrame: props.updatePositionStrategy === "always"
321
- });
322
- return cleanup;
323
- },
324
- middleware: computedMiddleware
325
- }
326
- );
327
- const placedSide = computed(() => getSideAndAlignFromPlacement(placement.value)[0]);
328
- const placedAlign = computed(() => getSideAndAlignFromPlacement(placement.value)[1]);
329
- watchEffect(() => {
330
- if (isPositioned.value)
331
- emit("placed");
332
- });
333
- const cannotCenterArrow = computed(
334
- () => middlewareData.value.arrow?.centerOffset !== 0
335
- );
336
- const contentZIndex = ref("");
337
- watchEffect(() => {
338
- if (contentElement.value)
339
- contentZIndex.value = window.getComputedStyle(contentElement.value).zIndex;
340
- });
341
- const arrowX = computed(() => middlewareData.value.arrow?.x ?? 0);
342
- const arrowY = computed(() => middlewareData.value.arrow?.y ?? 0);
343
- providePopperContentContext({
344
- placedSide,
345
- onArrowChange: (element) => arrow$1.value = element,
346
- arrowX,
347
- arrowY,
348
- shouldHideArrow: cannotCenterArrow
349
- });
350
- return {
351
- floatingRef,
352
- floatingStyles,
353
- isPositioned,
354
- contentZIndex,
355
- middlewareData,
356
- forwardRef,
357
- placedSide,
358
- placedAlign,
359
- attrStyle: attrs.style
360
- };
361
- },
362
- render() {
363
- return h("div", {
364
- "data-destyler-popper-content-wrapper": "",
365
- "ref": "floatingRef",
366
- "style": {
367
- ...this.floatingStyles,
368
- transform: this.isPositioned ? this.floatingStyles.transform : "translate(0, -200%)",
369
- minWidth: "max-content",
370
- zIndex: this.contentZIndex,
371
- ["--destyler-popper-transform-origin"]: [
372
- this.middlewareData.transformOrigin?.x,
373
- this.middlewareData.transformOrigin?.y
374
- ].join(" "),
375
- ...this.middlewareData.hide?.referenceHidden && {
376
- visibility: "hidden",
377
- pointerEvents: "none"
378
- }
379
- }
380
- }, h(Primitive, mergeProps(this.$attrs, {
381
- "ref": (el) => this.forwardRef(el),
382
- "as": this.$props.as,
383
- "asChild": this.$props.asChild,
384
- "data-side": this.placedSide,
385
- "data-align": this.placedAlign,
386
- "style": {
387
- animation: !this.isPositioned ? "none" : void 0
388
- }
389
- }), () => this.$slots.default?.()));
390
- }
391
- });
392
-
393
- const OPPOSITE_SIDE = {
394
- top: "bottom",
395
- right: "left",
396
- bottom: "top",
397
- left: "right"
398
- };
399
- const popperArrowProps = {
400
- ...arrowProps
401
- };
402
- const PopperArrow = defineComponent({
403
- name: "DestylerPopperArrow",
404
- inheritAttrs: false,
405
- props: popperArrowProps,
406
- setup() {
407
- const contentContext = injectPopperContentContext();
408
- const baseSide = computed(() => OPPOSITE_SIDE[contentContext.placedSide.value]);
409
- return {
410
- contentContext,
411
- baseSide
412
- };
413
- },
414
- render() {
415
- return h("span", {
416
- ref: (el) => {
417
- this.contentContext.onArrowChange(el);
418
- return void 0;
419
- },
420
- style: {
421
- position: "absolute",
422
- left: this.contentContext.arrowX?.value ? `${this.contentContext.arrowX?.value}px` : void 0,
423
- top: this.contentContext.arrowY?.value ? `${this.contentContext.arrowY?.value}px` : void 0,
424
- [this.baseSide]: 0,
425
- transformOrigin: {
426
- top: "",
427
- right: "0 0",
428
- bottom: "center 0",
429
- left: "100% 0"
430
- }[this.contentContext.placedSide.value],
431
- transform: {
432
- top: "translateY(100%)",
433
- right: "translateY(50%) rotate(90deg) translateX(-50%)",
434
- bottom: `rotate(180deg)`,
435
- left: "translateY(50%) rotate(-90deg) translateX(50%)"
436
- }[this.contentContext.placedSide.value],
437
- visibility: this.contentContext.shouldHideArrow.value ? "hidden" : void 0
438
- }
439
- }, () => h(Arrow, mergeProps(this.$attrs, {
440
- as: this.$props.as,
441
- asChild: this.$props.asChild,
442
- width: this.$props.width,
443
- height: this.$props.height,
444
- style: {
445
- display: "block"
446
- }
447
- }), () => this.$slots.default?.()));
448
- }
449
- });
450
-
451
- export { PopperAnchor, PopperArrow, PopperContent, PopperRoot, popperAnchorProps, popperArrowProps, popperContentEmits, popperContentProps };
package/dist/index.cjs DELETED
@@ -1,20 +0,0 @@
1
- 'use strict';
2
-
3
- const index = require('./component.cjs');
4
- require('vue');
5
- require('@destyler/shared');
6
- require('@destyler/primitive');
7
- require('@destyler/composition');
8
- require('@floating-ui/vue');
9
- require('@destyler/arrow');
10
- require('@destyler/arrow/component');
11
-
12
-
13
-
14
- exports.PopperAnchor = index.PopperAnchor;
15
- exports.PopperArrow = index.PopperArrow;
16
- exports.PopperContent = index.PopperContent;
17
- exports.PopperRoot = index.PopperRoot;
18
- exports.popperAnchorProps = index.popperAnchorProps;
19
- exports.popperArrowProps = index.popperArrowProps;
20
- exports.popperContentProps = index.popperContentProps;
package/dist/index.d.cts DELETED
@@ -1,5 +0,0 @@
1
- export { PopperAnchor, PopperAnchorProps, PopperArrow, PopperArrowProps, PopperContent, PopperContentProps, PopperRoot, popperAnchorProps, popperArrowProps, popperContentProps } from './component.cjs';
2
- import 'vue';
3
- import '@destyler/primitive';
4
- import '@destyler/shared';
5
- import '@floating-ui/vue';
package/dist/index.d.mts DELETED
@@ -1,5 +0,0 @@
1
- export { PopperAnchor, PopperAnchorProps, PopperArrow, PopperArrowProps, PopperContent, PopperContentProps, PopperRoot, popperAnchorProps, popperArrowProps, popperContentProps } from './component.mjs';
2
- import 'vue';
3
- import '@destyler/primitive';
4
- import '@destyler/shared';
5
- import '@floating-ui/vue';
package/dist/index.mjs DELETED
@@ -1,8 +0,0 @@
1
- export { PopperAnchor, PopperArrow, PopperContent, PopperRoot, popperAnchorProps, popperArrowProps, popperContentProps } from './component.mjs';
2
- import 'vue';
3
- import '@destyler/shared';
4
- import '@destyler/primitive';
5
- import '@destyler/composition';
6
- import '@floating-ui/vue';
7
- import '@destyler/arrow';
8
- import '@destyler/arrow/component';
package/dist/resolver.cjs DELETED
@@ -1,23 +0,0 @@
1
- 'use strict';
2
-
3
- const name = "@destyler/popper";
4
-
5
- const packageName = name;
6
- const popperComponentName = [
7
- "PopperRoot",
8
- "PopperAnchor",
9
- "PopperContent",
10
- "PopperArrow"
11
- ];
12
- function PopperResolver() {
13
- return {
14
- type: "component",
15
- resolve: (name2) => {
16
- if (popperComponentName.includes(name2))
17
- return { name: name2, from: packageName };
18
- }
19
- };
20
- }
21
-
22
- exports.PopperResolver = PopperResolver;
23
- exports.popperComponentName = popperComponentName;
@@ -1,6 +0,0 @@
1
- import { ComponentResolver } from 'unplugin-vue-components';
2
-
3
- declare const popperComponentName: string[];
4
- declare function PopperResolver(): ComponentResolver;
5
-
6
- export { PopperResolver, popperComponentName };
@@ -1,6 +0,0 @@
1
- import { ComponentResolver } from 'unplugin-vue-components';
2
-
3
- declare const popperComponentName: string[];
4
- declare function PopperResolver(): ComponentResolver;
5
-
6
- export { PopperResolver, popperComponentName };
@@ -1,6 +0,0 @@
1
- import { ComponentResolver } from 'unplugin-vue-components';
2
-
3
- declare const popperComponentName: string[];
4
- declare function PopperResolver(): ComponentResolver;
5
-
6
- export { PopperResolver, popperComponentName };
package/dist/resolver.mjs DELETED
@@ -1,20 +0,0 @@
1
- const name = "@destyler/popper";
2
-
3
- const packageName = name;
4
- const popperComponentName = [
5
- "PopperRoot",
6
- "PopperAnchor",
7
- "PopperContent",
8
- "PopperArrow"
9
- ];
10
- function PopperResolver() {
11
- return {
12
- type: "component",
13
- resolve: (name2) => {
14
- if (popperComponentName.includes(name2))
15
- return { name: name2, from: packageName };
16
- }
17
- };
18
- }
19
-
20
- export { PopperResolver, popperComponentName };