@zag-js/popper 0.0.0-dev-20220627213436 → 0.0.0-dev-20220703125047
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/auto-update.d.ts +1 -1
- package/dist/get-placement.d.ts +2 -2
- package/dist/index.js +53 -51
- package/dist/index.mjs +53 -51
- package/dist/types.d.ts +5 -3
- package/package.json +2 -2
package/dist/auto-update.d.ts
CHANGED
|
@@ -5,4 +5,4 @@ export declare type AutoUpdateOptions = {
|
|
|
5
5
|
ancestorResize?: boolean;
|
|
6
6
|
referenceResize?: boolean;
|
|
7
7
|
};
|
|
8
|
-
export declare function autoUpdate(reference: ReferenceElement, floating: HTMLElement, update: () => void, options?: boolean | AutoUpdateOptions): (
|
|
8
|
+
export declare function autoUpdate(reference: ReferenceElement, floating: HTMLElement, update: () => void, options?: boolean | AutoUpdateOptions): () => void;
|
package/dist/get-placement.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { VirtualElement } from "@floating-ui/dom";
|
|
2
|
-
import { PositioningOptions } from "./types";
|
|
3
|
-
export declare function getPlacement(reference: HTMLElement | VirtualElement | null, floating: HTMLElement | null,
|
|
2
|
+
import type { PositioningOptions } from "./types";
|
|
3
|
+
export declare function getPlacement(reference: HTMLElement | VirtualElement | null, floating: HTMLElement | null, opts?: PositioningOptions): () => void;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
7
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
@@ -17,6 +19,7 @@ var __spreadValues = (a, b) => {
|
|
|
17
19
|
}
|
|
18
20
|
return a;
|
|
19
21
|
};
|
|
22
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
23
|
var __export = (target, all) => {
|
|
21
24
|
for (var name in all)
|
|
22
25
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -44,14 +47,19 @@ var import_dom2 = require("@floating-ui/dom");
|
|
|
44
47
|
|
|
45
48
|
// ../core/dist/index.mjs
|
|
46
49
|
var isBoolean = (v) => v === true || v === false;
|
|
47
|
-
var
|
|
50
|
+
var callAll = (...fns) => (...a) => {
|
|
51
|
+
fns.forEach(function(fn) {
|
|
52
|
+
fn == null ? void 0 : fn(...a);
|
|
53
|
+
});
|
|
48
54
|
};
|
|
49
|
-
var pipe = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
|
|
50
55
|
|
|
51
56
|
// src/auto-update.ts
|
|
52
57
|
var import_dom = require("@floating-ui/dom");
|
|
53
58
|
|
|
54
59
|
// ../dom/dist/index.mjs
|
|
60
|
+
function isHTMLElement(v) {
|
|
61
|
+
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
|
|
62
|
+
}
|
|
55
63
|
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
56
64
|
var runIfFn = (v, ...a) => {
|
|
57
65
|
const res = typeof v === "function" ? v(...a) : v;
|
|
@@ -65,9 +73,6 @@ function addDomEvent(target, eventName, handler, options) {
|
|
|
65
73
|
node == null ? void 0 : node.removeEventListener(eventName, handler, options);
|
|
66
74
|
};
|
|
67
75
|
}
|
|
68
|
-
function isHTMLElement(v) {
|
|
69
|
-
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
|
|
70
|
-
}
|
|
71
76
|
function getObservedElements() {
|
|
72
77
|
;
|
|
73
78
|
globalThis.__rectObserverMap__ = globalThis.__rectObserverMap__ || /* @__PURE__ */ new Map();
|
|
@@ -143,13 +148,13 @@ function autoUpdate(reference, floating, update, options = false) {
|
|
|
143
148
|
if (referenceResize && isHTMLElement(reference)) {
|
|
144
149
|
cleanups.push(observeElementRect(reference, update));
|
|
145
150
|
}
|
|
146
|
-
cleanups.push(
|
|
151
|
+
cleanups.push(callAll(...ancestors.map((el) => addDomEvent(el, "resize", update))));
|
|
147
152
|
return () => cleanups.forEach((fn) => fn());
|
|
148
153
|
}
|
|
149
154
|
function addScrollListeners() {
|
|
150
|
-
return
|
|
155
|
+
return callAll(...ancestors.map((el) => addDomEvent(el, "scroll", update, { passive: true })));
|
|
151
156
|
}
|
|
152
|
-
return
|
|
157
|
+
return callAll(addResizeListeners(), addScrollListeners());
|
|
153
158
|
}
|
|
154
159
|
|
|
155
160
|
// src/middleware.ts
|
|
@@ -190,20 +195,16 @@ var transformOrigin = {
|
|
|
190
195
|
var shiftArrow = (opts) => ({
|
|
191
196
|
name: "shiftArrow",
|
|
192
197
|
fn({ placement, middlewareData }) {
|
|
193
|
-
var _a;
|
|
194
198
|
const { element: arrow2 } = opts;
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
left: `${x}px`,
|
|
205
|
-
[dir]: cssVars.arrowOffset.reference
|
|
206
|
-
});
|
|
199
|
+
if (middlewareData.arrow) {
|
|
200
|
+
const { x, y } = middlewareData.arrow;
|
|
201
|
+
const dir = placement.split("-")[0];
|
|
202
|
+
Object.assign(arrow2.style, {
|
|
203
|
+
left: x != null ? `${x}px` : "",
|
|
204
|
+
top: y != null ? `${y}px` : "",
|
|
205
|
+
[dir]: `calc(100% + ${cssVars.arrowOffset.reference})`
|
|
206
|
+
});
|
|
207
|
+
}
|
|
207
208
|
return {};
|
|
208
209
|
}
|
|
209
210
|
});
|
|
@@ -218,11 +219,10 @@ var defaultOptions = {
|
|
|
218
219
|
sameWidth: false,
|
|
219
220
|
overflowPadding: 8
|
|
220
221
|
};
|
|
221
|
-
function getPlacement(reference, floating,
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
options = Object.assign({}, defaultOptions, options);
|
|
222
|
+
function getPlacement(reference, floating, opts = {}) {
|
|
223
|
+
if (!floating || !reference)
|
|
224
|
+
return;
|
|
225
|
+
const options = Object.assign({}, defaultOptions, opts);
|
|
226
226
|
const arrowEl = floating.querySelector("[data-part=arrow]");
|
|
227
227
|
const middleware = [];
|
|
228
228
|
if (options.flip) {
|
|
@@ -247,34 +247,36 @@ function getPlacement(reference, floating, options = {}) {
|
|
|
247
247
|
middleware.push((0, import_dom2.arrow)({ element: arrowEl, padding: 8 }), shiftArrow({ element: arrowEl }));
|
|
248
248
|
}
|
|
249
249
|
middleware.push(transformOrigin);
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
maxWidth: `${data.availableWidth}px`,
|
|
263
|
-
maxHeight: `${data.availableHeight}px`
|
|
264
|
-
});
|
|
265
|
-
}
|
|
250
|
+
middleware.push((0, import_dom2.size)({
|
|
251
|
+
padding: options.overflowPadding,
|
|
252
|
+
apply({ rects, availableHeight, availableWidth }) {
|
|
253
|
+
const referenceWidth = Math.round(rects.reference.width);
|
|
254
|
+
floating.style.setProperty("--reference-width", `${referenceWidth}px`);
|
|
255
|
+
floating.style.setProperty("--available-width", `${availableWidth}px`);
|
|
256
|
+
floating.style.setProperty("--available-height", `${availableHeight}px`);
|
|
257
|
+
if (options.sameWidth) {
|
|
258
|
+
Object.assign(floating.style, {
|
|
259
|
+
width: `${referenceWidth}px`,
|
|
260
|
+
minWidth: "unset"
|
|
261
|
+
});
|
|
266
262
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
263
|
+
if (options.fitViewport) {
|
|
264
|
+
Object.assign(floating.style, {
|
|
265
|
+
maxWidth: `${availableWidth}px`,
|
|
266
|
+
maxHeight: `${availableHeight}px`
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}));
|
|
271
|
+
function compute(config = {}) {
|
|
272
|
+
if (!reference || !floating)
|
|
271
273
|
return;
|
|
272
274
|
const { placement, strategy } = options;
|
|
273
|
-
(0, import_dom2.computePosition)(reference, floating, {
|
|
275
|
+
(0, import_dom2.computePosition)(reference, floating, __spreadValues({
|
|
274
276
|
placement,
|
|
275
277
|
middleware,
|
|
276
278
|
strategy
|
|
277
|
-
}).then((data) => {
|
|
279
|
+
}, config)).then((data) => {
|
|
278
280
|
const x = Math.round(data.x);
|
|
279
281
|
const y = Math.round(data.y);
|
|
280
282
|
Object.assign(floating.style, {
|
|
@@ -285,12 +287,12 @@ function getPlacement(reference, floating, options = {}) {
|
|
|
285
287
|
});
|
|
286
288
|
return data;
|
|
287
289
|
}).then((data) => {
|
|
288
|
-
var
|
|
289
|
-
(
|
|
290
|
+
var _a;
|
|
291
|
+
(_a = options.onComplete) == null ? void 0 : _a.call(options, __spreadProps(__spreadValues({}, data), { compute }));
|
|
290
292
|
});
|
|
291
293
|
}
|
|
292
294
|
compute();
|
|
293
|
-
return
|
|
295
|
+
return callAll(options.listeners ? autoUpdate(reference, floating, compute, options.listeners) : void 0, options.onCleanup);
|
|
294
296
|
}
|
|
295
297
|
|
|
296
298
|
// src/get-styles.ts
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
3
5
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
@@ -15,20 +17,26 @@ var __spreadValues = (a, b) => {
|
|
|
15
17
|
}
|
|
16
18
|
return a;
|
|
17
19
|
};
|
|
20
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
18
21
|
|
|
19
22
|
// src/get-placement.ts
|
|
20
23
|
import { arrow, computePosition, flip, offset, shift, size } from "@floating-ui/dom";
|
|
21
24
|
|
|
22
25
|
// ../core/dist/index.mjs
|
|
23
26
|
var isBoolean = (v) => v === true || v === false;
|
|
24
|
-
var
|
|
27
|
+
var callAll = (...fns) => (...a) => {
|
|
28
|
+
fns.forEach(function(fn) {
|
|
29
|
+
fn == null ? void 0 : fn(...a);
|
|
30
|
+
});
|
|
25
31
|
};
|
|
26
|
-
var pipe = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
|
|
27
32
|
|
|
28
33
|
// src/auto-update.ts
|
|
29
34
|
import { getOverflowAncestors } from "@floating-ui/dom";
|
|
30
35
|
|
|
31
36
|
// ../dom/dist/index.mjs
|
|
37
|
+
function isHTMLElement(v) {
|
|
38
|
+
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
|
|
39
|
+
}
|
|
32
40
|
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
33
41
|
var runIfFn = (v, ...a) => {
|
|
34
42
|
const res = typeof v === "function" ? v(...a) : v;
|
|
@@ -42,9 +50,6 @@ function addDomEvent(target, eventName, handler, options) {
|
|
|
42
50
|
node == null ? void 0 : node.removeEventListener(eventName, handler, options);
|
|
43
51
|
};
|
|
44
52
|
}
|
|
45
|
-
function isHTMLElement(v) {
|
|
46
|
-
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
|
|
47
|
-
}
|
|
48
53
|
function getObservedElements() {
|
|
49
54
|
;
|
|
50
55
|
globalThis.__rectObserverMap__ = globalThis.__rectObserverMap__ || /* @__PURE__ */ new Map();
|
|
@@ -120,13 +125,13 @@ function autoUpdate(reference, floating, update, options = false) {
|
|
|
120
125
|
if (referenceResize && isHTMLElement(reference)) {
|
|
121
126
|
cleanups.push(observeElementRect(reference, update));
|
|
122
127
|
}
|
|
123
|
-
cleanups.push(
|
|
128
|
+
cleanups.push(callAll(...ancestors.map((el) => addDomEvent(el, "resize", update))));
|
|
124
129
|
return () => cleanups.forEach((fn) => fn());
|
|
125
130
|
}
|
|
126
131
|
function addScrollListeners() {
|
|
127
|
-
return
|
|
132
|
+
return callAll(...ancestors.map((el) => addDomEvent(el, "scroll", update, { passive: true })));
|
|
128
133
|
}
|
|
129
|
-
return
|
|
134
|
+
return callAll(addResizeListeners(), addScrollListeners());
|
|
130
135
|
}
|
|
131
136
|
|
|
132
137
|
// src/middleware.ts
|
|
@@ -167,20 +172,16 @@ var transformOrigin = {
|
|
|
167
172
|
var shiftArrow = (opts) => ({
|
|
168
173
|
name: "shiftArrow",
|
|
169
174
|
fn({ placement, middlewareData }) {
|
|
170
|
-
var _a;
|
|
171
175
|
const { element: arrow2 } = opts;
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
left: `${x}px`,
|
|
182
|
-
[dir]: cssVars.arrowOffset.reference
|
|
183
|
-
});
|
|
176
|
+
if (middlewareData.arrow) {
|
|
177
|
+
const { x, y } = middlewareData.arrow;
|
|
178
|
+
const dir = placement.split("-")[0];
|
|
179
|
+
Object.assign(arrow2.style, {
|
|
180
|
+
left: x != null ? `${x}px` : "",
|
|
181
|
+
top: y != null ? `${y}px` : "",
|
|
182
|
+
[dir]: `calc(100% + ${cssVars.arrowOffset.reference})`
|
|
183
|
+
});
|
|
184
|
+
}
|
|
184
185
|
return {};
|
|
185
186
|
}
|
|
186
187
|
});
|
|
@@ -195,11 +196,10 @@ var defaultOptions = {
|
|
|
195
196
|
sameWidth: false,
|
|
196
197
|
overflowPadding: 8
|
|
197
198
|
};
|
|
198
|
-
function getPlacement(reference, floating,
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
options = Object.assign({}, defaultOptions, options);
|
|
199
|
+
function getPlacement(reference, floating, opts = {}) {
|
|
200
|
+
if (!floating || !reference)
|
|
201
|
+
return;
|
|
202
|
+
const options = Object.assign({}, defaultOptions, opts);
|
|
203
203
|
const arrowEl = floating.querySelector("[data-part=arrow]");
|
|
204
204
|
const middleware = [];
|
|
205
205
|
if (options.flip) {
|
|
@@ -224,34 +224,36 @@ function getPlacement(reference, floating, options = {}) {
|
|
|
224
224
|
middleware.push(arrow({ element: arrowEl, padding: 8 }), shiftArrow({ element: arrowEl }));
|
|
225
225
|
}
|
|
226
226
|
middleware.push(transformOrigin);
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
maxWidth: `${data.availableWidth}px`,
|
|
240
|
-
maxHeight: `${data.availableHeight}px`
|
|
241
|
-
});
|
|
242
|
-
}
|
|
227
|
+
middleware.push(size({
|
|
228
|
+
padding: options.overflowPadding,
|
|
229
|
+
apply({ rects, availableHeight, availableWidth }) {
|
|
230
|
+
const referenceWidth = Math.round(rects.reference.width);
|
|
231
|
+
floating.style.setProperty("--reference-width", `${referenceWidth}px`);
|
|
232
|
+
floating.style.setProperty("--available-width", `${availableWidth}px`);
|
|
233
|
+
floating.style.setProperty("--available-height", `${availableHeight}px`);
|
|
234
|
+
if (options.sameWidth) {
|
|
235
|
+
Object.assign(floating.style, {
|
|
236
|
+
width: `${referenceWidth}px`,
|
|
237
|
+
minWidth: "unset"
|
|
238
|
+
});
|
|
243
239
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
240
|
+
if (options.fitViewport) {
|
|
241
|
+
Object.assign(floating.style, {
|
|
242
|
+
maxWidth: `${availableWidth}px`,
|
|
243
|
+
maxHeight: `${availableHeight}px`
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}));
|
|
248
|
+
function compute(config = {}) {
|
|
249
|
+
if (!reference || !floating)
|
|
248
250
|
return;
|
|
249
251
|
const { placement, strategy } = options;
|
|
250
|
-
computePosition(reference, floating, {
|
|
252
|
+
computePosition(reference, floating, __spreadValues({
|
|
251
253
|
placement,
|
|
252
254
|
middleware,
|
|
253
255
|
strategy
|
|
254
|
-
}).then((data) => {
|
|
256
|
+
}, config)).then((data) => {
|
|
255
257
|
const x = Math.round(data.x);
|
|
256
258
|
const y = Math.round(data.y);
|
|
257
259
|
Object.assign(floating.style, {
|
|
@@ -262,12 +264,12 @@ function getPlacement(reference, floating, options = {}) {
|
|
|
262
264
|
});
|
|
263
265
|
return data;
|
|
264
266
|
}).then((data) => {
|
|
265
|
-
var
|
|
266
|
-
(
|
|
267
|
+
var _a;
|
|
268
|
+
(_a = options.onComplete) == null ? void 0 : _a.call(options, __spreadProps(__spreadValues({}, data), { compute }));
|
|
267
269
|
});
|
|
268
270
|
}
|
|
269
271
|
compute();
|
|
270
|
-
return
|
|
272
|
+
return callAll(options.listeners ? autoUpdate(reference, floating, compute, options.listeners) : void 0, options.onCleanup);
|
|
271
273
|
}
|
|
272
274
|
|
|
273
275
|
// src/get-styles.ts
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Boundary, Placement, ComputePositionReturn } from "@floating-ui/dom";
|
|
2
|
-
import { AutoUpdateOptions } from "./auto-update";
|
|
1
|
+
import type { Boundary, Placement, ComputePositionReturn, ComputePositionConfig } from "@floating-ui/dom";
|
|
2
|
+
import type { AutoUpdateOptions } from "./auto-update";
|
|
3
3
|
export type { Placement };
|
|
4
4
|
export declare type PositioningOptions = {
|
|
5
5
|
/**
|
|
@@ -53,7 +53,9 @@ export declare type PositioningOptions = {
|
|
|
53
53
|
/**
|
|
54
54
|
* Function called when the placement is computed
|
|
55
55
|
*/
|
|
56
|
-
onComplete?(data: ComputePositionReturn
|
|
56
|
+
onComplete?(data: ComputePositionReturn & {
|
|
57
|
+
compute: (config?: Omit<ComputePositionConfig, "platform">) => void;
|
|
58
|
+
}): void;
|
|
57
59
|
/**
|
|
58
60
|
* Function called on cleanup of all listeners
|
|
59
61
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/popper",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20220703125047",
|
|
4
4
|
"description": "Dynamic positioning logic for ui machines",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@floating-ui/dom": "0.5.0",
|
|
29
|
-
"@zag-js/dom-utils": "0.0.0-dev-
|
|
29
|
+
"@zag-js/dom-utils": "0.0.0-dev-20220703125047",
|
|
30
30
|
"@zag-js/utils": "0.1.2"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|