@zag-js/popper 1.31.0 → 1.31.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.
package/dist/index.d.mts CHANGED
@@ -90,8 +90,14 @@ interface PositioningOptions {
90
90
  onPositioned?: ((data: {
91
91
  placed: boolean;
92
92
  }) => void) | undefined;
93
+ /**
94
+ * Function that returns the anchor element.
95
+ * Useful when you want to use a different element as the anchor.
96
+ */
97
+ getAnchorElement?: (() => HTMLElement | VirtualElement | null) | undefined;
93
98
  /**
94
99
  * Function that returns the anchor rect
100
+ * @deprecated Use `getAnchorElement` instead
95
101
  */
96
102
  getAnchorRect?: ((element: HTMLElement | VirtualElement | null) => AnchorRect | null) | undefined;
97
103
  /**
package/dist/index.d.ts CHANGED
@@ -90,8 +90,14 @@ interface PositioningOptions {
90
90
  onPositioned?: ((data: {
91
91
  placed: boolean;
92
92
  }) => void) | undefined;
93
+ /**
94
+ * Function that returns the anchor element.
95
+ * Useful when you want to use a different element as the anchor.
96
+ */
97
+ getAnchorElement?: (() => HTMLElement | VirtualElement | null) | undefined;
93
98
  /**
94
99
  * Function that returns the anchor rect
100
+ * @deprecated Use `getAnchorElement` instead
95
101
  */
96
102
  getAnchorRect?: ((element: HTMLElement | VirtualElement | null) => AnchorRect | null) | undefined;
97
103
  /**
package/dist/index.js CHANGED
@@ -28,7 +28,7 @@ function getDOMRect(anchorRect) {
28
28
  }
29
29
  function getAnchorElement(anchorElement, getAnchorRect) {
30
30
  return {
31
- contextElement: domQuery.isHTMLElement(anchorElement) ? anchorElement : void 0,
31
+ contextElement: domQuery.isHTMLElement(anchorElement) ? anchorElement : anchorElement?.contextElement,
32
32
  getBoundingClientRect: () => {
33
33
  const anchor = anchorElement;
34
34
  const anchorRect = getAnchorRect?.(anchor);
@@ -218,7 +218,8 @@ function getAutoUpdateOptions(opts) {
218
218
  return opts;
219
219
  }
220
220
  function getPlacementImpl(referenceOrVirtual, floating, opts = {}) {
221
- const reference = getAnchorElement(referenceOrVirtual, opts.getAnchorRect);
221
+ const anchor = opts.getAnchorElement?.() ?? referenceOrVirtual;
222
+ const reference = getAnchorElement(anchor, opts.getAnchorRect);
222
223
  if (!floating || !reference) return;
223
224
  const options = Object.assign({}, defaultOptions, opts);
224
225
  const arrowEl = floating.querySelector("[data-part=arrow]");
package/dist/index.mjs CHANGED
@@ -26,7 +26,7 @@ function getDOMRect(anchorRect) {
26
26
  }
27
27
  function getAnchorElement(anchorElement, getAnchorRect) {
28
28
  return {
29
- contextElement: isHTMLElement(anchorElement) ? anchorElement : void 0,
29
+ contextElement: isHTMLElement(anchorElement) ? anchorElement : anchorElement?.contextElement,
30
30
  getBoundingClientRect: () => {
31
31
  const anchor = anchorElement;
32
32
  const anchorRect = getAnchorRect?.(anchor);
@@ -216,7 +216,8 @@ function getAutoUpdateOptions(opts) {
216
216
  return opts;
217
217
  }
218
218
  function getPlacementImpl(referenceOrVirtual, floating, opts = {}) {
219
- const reference = getAnchorElement(referenceOrVirtual, opts.getAnchorRect);
219
+ const anchor = opts.getAnchorElement?.() ?? referenceOrVirtual;
220
+ const reference = getAnchorElement(anchor, opts.getAnchorRect);
220
221
  if (!floating || !reference) return;
221
222
  const options = Object.assign({}, defaultOptions, opts);
222
223
  const arrowEl = floating.querySelector("[data-part=arrow]");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/popper",
3
- "version": "1.31.0",
3
+ "version": "1.31.1",
4
4
  "description": "Dynamic positioning logic for ui machines",
5
5
  "keywords": [
6
6
  "js",
@@ -23,8 +23,8 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@floating-ui/dom": "1.7.4",
26
- "@zag-js/dom-query": "1.31.0",
27
- "@zag-js/utils": "1.31.0"
26
+ "@zag-js/dom-query": "1.31.1",
27
+ "@zag-js/utils": "1.31.1"
28
28
  },
29
29
  "devDependencies": {
30
30
  "clean-package": "2.2.0"