@warp-ds/elements 1.4.0-next.1 → 1.4.0-next.3

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.
@@ -51,6 +51,10 @@ export class WarpAttention extends WarpAttention_base {
51
51
  type: BooleanConstructor;
52
52
  reflect: boolean;
53
53
  };
54
+ crossAxis: {
55
+ type: BooleanConstructor;
56
+ reflect: boolean;
57
+ };
54
58
  fallbackPlacements: {
55
59
  type: ArrayConstructor;
56
60
  reflect: boolean;
@@ -69,6 +73,7 @@ export class WarpAttention extends WarpAttention_base {
69
73
  distance: number;
70
74
  skidding: number;
71
75
  flip: boolean;
76
+ crossAxis: boolean;
72
77
  _initialPlacement: string;
73
78
  set _actualDirection(v: string);
74
79
  get _actualDirection(): string;
@@ -101,6 +106,7 @@ export class WarpAttention extends WarpAttention_base {
101
106
  distance: number;
102
107
  skidding: number;
103
108
  flip: boolean;
109
+ crossAxis: boolean;
104
110
  fallbackPlacements: any;
105
111
  };
106
112
  pointingAtDirection(): string;
@@ -1060,7 +1060,7 @@ function generateRandomId() {
1060
1060
  return `m${Math.random().toString(36).slice(2)}`;
1061
1061
  }
1062
1062
 
1063
- // node_modules/.pnpm/@warp-ds+css@1.9.3/node_modules/@warp-ds/css/component-classes/index.js
1063
+ // node_modules/.pnpm/@warp-ds+css@1.9.6/node_modules/@warp-ds/css/component-classes/index.js
1064
1064
  var box = {
1065
1065
  box: "group block relative break-words last-child:mb-0 p-16 rounded-8",
1066
1066
  // Relative here enables w-clickable
@@ -1345,8 +1345,6 @@ var attention = {
1345
1345
 
1346
1346
  // node_modules/.pnpm/@floating-ui+utils@0.2.1/node_modules/@floating-ui/utils/dist/floating-ui.utils.mjs
1347
1347
  var sides = ["top", "right", "bottom", "left"];
1348
- var alignments = ["start", "end"];
1349
- var placements = /* @__PURE__ */ sides.reduce((acc, side2) => acc.concat(side2, side2 + "-" + alignments[0], side2 + "-" + alignments[1]), []);
1350
1348
  var min = Math.min;
1351
1349
  var max = Math.max;
1352
1350
  var round = Math.round;
@@ -1715,106 +1713,6 @@ var arrow = (options) => ({
1715
1713
  };
1716
1714
  }
1717
1715
  });
1718
- function getPlacementList(alignment, autoAlignment, allowedPlacements) {
1719
- const allowedPlacementsSortedByAlignment = alignment ? [...allowedPlacements.filter((placement) => getAlignment(placement) === alignment), ...allowedPlacements.filter((placement) => getAlignment(placement) !== alignment)] : allowedPlacements.filter((placement) => getSide(placement) === placement);
1720
- return allowedPlacementsSortedByAlignment.filter((placement) => {
1721
- if (alignment) {
1722
- return getAlignment(placement) === alignment || (autoAlignment ? getOppositeAlignmentPlacement(placement) !== placement : false);
1723
- }
1724
- return true;
1725
- });
1726
- }
1727
- var autoPlacement = function(options) {
1728
- if (options === void 0) {
1729
- options = {};
1730
- }
1731
- return {
1732
- name: "autoPlacement",
1733
- options,
1734
- async fn(state) {
1735
- var _middlewareData$autoP, _middlewareData$autoP2, _placementsThatFitOnE;
1736
- const {
1737
- rects,
1738
- middlewareData,
1739
- placement,
1740
- platform: platform2,
1741
- elements
1742
- } = state;
1743
- const _a = evaluate(options, state), {
1744
- crossAxis = false,
1745
- alignment,
1746
- allowedPlacements = placements,
1747
- autoAlignment = true
1748
- } = _a, detectOverflowOptions = __objRest(_a, [
1749
- "crossAxis",
1750
- "alignment",
1751
- "allowedPlacements",
1752
- "autoAlignment"
1753
- ]);
1754
- const placements$1 = alignment !== void 0 || allowedPlacements === placements ? getPlacementList(alignment || null, autoAlignment, allowedPlacements) : allowedPlacements;
1755
- const overflow = await detectOverflow(state, detectOverflowOptions);
1756
- const currentIndex = ((_middlewareData$autoP = middlewareData.autoPlacement) == null ? void 0 : _middlewareData$autoP.index) || 0;
1757
- const currentPlacement = placements$1[currentIndex];
1758
- if (currentPlacement == null) {
1759
- return {};
1760
- }
1761
- const alignmentSides = getAlignmentSides(currentPlacement, rects, await (platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating)));
1762
- if (placement !== currentPlacement) {
1763
- return {
1764
- reset: {
1765
- placement: placements$1[0]
1766
- }
1767
- };
1768
- }
1769
- const currentOverflows = [overflow[getSide(currentPlacement)], overflow[alignmentSides[0]], overflow[alignmentSides[1]]];
1770
- const allOverflows = [...((_middlewareData$autoP2 = middlewareData.autoPlacement) == null ? void 0 : _middlewareData$autoP2.overflows) || [], {
1771
- placement: currentPlacement,
1772
- overflows: currentOverflows
1773
- }];
1774
- const nextPlacement = placements$1[currentIndex + 1];
1775
- if (nextPlacement) {
1776
- return {
1777
- data: {
1778
- index: currentIndex + 1,
1779
- overflows: allOverflows
1780
- },
1781
- reset: {
1782
- placement: nextPlacement
1783
- }
1784
- };
1785
- }
1786
- const placementsSortedByMostSpace = allOverflows.map((d) => {
1787
- const alignment2 = getAlignment(d.placement);
1788
- return [d.placement, alignment2 && crossAxis ? (
1789
- // Check along the mainAxis and main crossAxis side.
1790
- d.overflows.slice(0, 2).reduce((acc, v) => acc + v, 0)
1791
- ) : (
1792
- // Check only the mainAxis.
1793
- d.overflows[0]
1794
- ), d.overflows];
1795
- }).sort((a, b) => a[1] - b[1]);
1796
- const placementsThatFitOnEachSide = placementsSortedByMostSpace.filter((d) => d[2].slice(
1797
- 0,
1798
- // Aligned placements should not check their opposite crossAxis
1799
- // side.
1800
- getAlignment(d[0]) ? 2 : 3
1801
- ).every((v) => v <= 0));
1802
- const resetPlacement = ((_placementsThatFitOnE = placementsThatFitOnEachSide[0]) == null ? void 0 : _placementsThatFitOnE[0]) || placementsSortedByMostSpace[0][0];
1803
- if (resetPlacement !== placement) {
1804
- return {
1805
- data: {
1806
- index: currentIndex + 1,
1807
- overflows: allOverflows
1808
- },
1809
- reset: {
1810
- placement: resetPlacement
1811
- }
1812
- };
1813
- }
1814
- return {};
1815
- }
1816
- };
1817
- };
1818
1716
  var flip = function(options) {
1819
1717
  if (options === void 0) {
1820
1718
  options = {};
@@ -1915,6 +1813,65 @@ var flip = function(options) {
1915
1813
  }
1916
1814
  };
1917
1815
  };
1816
+ function getSideOffsets(overflow, rect) {
1817
+ return {
1818
+ top: overflow.top - rect.height,
1819
+ right: overflow.right - rect.width,
1820
+ bottom: overflow.bottom - rect.height,
1821
+ left: overflow.left - rect.width
1822
+ };
1823
+ }
1824
+ function isAnySideFullyClipped(overflow) {
1825
+ return sides.some((side2) => overflow[side2] >= 0);
1826
+ }
1827
+ var hide = function(options) {
1828
+ if (options === void 0) {
1829
+ options = {};
1830
+ }
1831
+ return {
1832
+ name: "hide",
1833
+ options,
1834
+ async fn(state) {
1835
+ const {
1836
+ rects
1837
+ } = state;
1838
+ const _a = evaluate(options, state), {
1839
+ strategy = "referenceHidden"
1840
+ } = _a, detectOverflowOptions = __objRest(_a, [
1841
+ "strategy"
1842
+ ]);
1843
+ switch (strategy) {
1844
+ case "referenceHidden": {
1845
+ const overflow = await detectOverflow(state, __spreadProps(__spreadValues({}, detectOverflowOptions), {
1846
+ elementContext: "reference"
1847
+ }));
1848
+ const offsets = getSideOffsets(overflow, rects.reference);
1849
+ return {
1850
+ data: {
1851
+ referenceHiddenOffsets: offsets,
1852
+ referenceHidden: isAnySideFullyClipped(offsets)
1853
+ }
1854
+ };
1855
+ }
1856
+ case "escaped": {
1857
+ const overflow = await detectOverflow(state, __spreadProps(__spreadValues({}, detectOverflowOptions), {
1858
+ altBoundary: true
1859
+ }));
1860
+ const offsets = getSideOffsets(overflow, rects.floating);
1861
+ return {
1862
+ data: {
1863
+ escapedOffsets: offsets,
1864
+ escaped: isAnySideFullyClipped(offsets)
1865
+ }
1866
+ };
1867
+ }
1868
+ default: {
1869
+ return {};
1870
+ }
1871
+ }
1872
+ }
1873
+ };
1874
+ };
1918
1875
  async function convertValueToCoords(state, options) {
1919
1876
  const {
1920
1877
  placement,
@@ -1981,75 +1938,6 @@ var offset = function(options) {
1981
1938
  }
1982
1939
  };
1983
1940
  };
1984
- var shift = function(options) {
1985
- if (options === void 0) {
1986
- options = {};
1987
- }
1988
- return {
1989
- name: "shift",
1990
- options,
1991
- async fn(state) {
1992
- const {
1993
- x,
1994
- y,
1995
- placement
1996
- } = state;
1997
- const _a = evaluate(options, state), {
1998
- mainAxis: checkMainAxis = true,
1999
- crossAxis: checkCrossAxis = false,
2000
- limiter = {
2001
- fn: (_ref) => {
2002
- let {
2003
- x: x2,
2004
- y: y2
2005
- } = _ref;
2006
- return {
2007
- x: x2,
2008
- y: y2
2009
- };
2010
- }
2011
- }
2012
- } = _a, detectOverflowOptions = __objRest(_a, [
2013
- "mainAxis",
2014
- "crossAxis",
2015
- "limiter"
2016
- ]);
2017
- const coords = {
2018
- x,
2019
- y
2020
- };
2021
- const overflow = await detectOverflow(state, detectOverflowOptions);
2022
- const crossAxis = getSideAxis(getSide(placement));
2023
- const mainAxis = getOppositeAxis(crossAxis);
2024
- let mainAxisCoord = coords[mainAxis];
2025
- let crossAxisCoord = coords[crossAxis];
2026
- if (checkMainAxis) {
2027
- const minSide = mainAxis === "y" ? "top" : "left";
2028
- const maxSide = mainAxis === "y" ? "bottom" : "right";
2029
- const min2 = mainAxisCoord + overflow[minSide];
2030
- const max2 = mainAxisCoord - overflow[maxSide];
2031
- mainAxisCoord = clamp(min2, mainAxisCoord, max2);
2032
- }
2033
- if (checkCrossAxis) {
2034
- const minSide = crossAxis === "y" ? "top" : "left";
2035
- const maxSide = crossAxis === "y" ? "bottom" : "right";
2036
- const min2 = crossAxisCoord + overflow[minSide];
2037
- const max2 = crossAxisCoord - overflow[maxSide];
2038
- crossAxisCoord = clamp(min2, crossAxisCoord, max2);
2039
- }
2040
- const limitedCoords = limiter.fn(__spreadProps(__spreadValues({}, state), {
2041
- [mainAxis]: mainAxisCoord,
2042
- [crossAxis]: crossAxisCoord
2043
- }));
2044
- return __spreadProps(__spreadValues({}, limitedCoords), {
2045
- data: {
2046
- x: limitedCoords.x - x,
2047
- y: limitedCoords.y - y
2048
- }
2049
- });
2050
- }
2051
- };
2052
- };
2053
1941
 
2054
1942
  // node_modules/.pnpm/@floating-ui+utils@0.2.1/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.mjs
2055
1943
  function getNodeName(node) {
@@ -2567,9 +2455,8 @@ var platform = {
2567
2455
  isElement,
2568
2456
  isRTL
2569
2457
  };
2570
- var autoPlacement2 = autoPlacement;
2571
- var shift2 = shift;
2572
2458
  var flip2 = flip;
2459
+ var hide2 = hide;
2573
2460
  var arrow2 = arrow;
2574
2461
  var computePosition2 = (reference, floating, options) => {
2575
2462
  const cache2 = /* @__PURE__ */ new Map();
@@ -2584,7 +2471,7 @@ var computePosition2 = (reference, floating, options) => {
2584
2471
  }));
2585
2472
  };
2586
2473
 
2587
- // node_modules/.pnpm/@warp-ds+core@1.1.0_@floating-ui+dom@1.6.3/node_modules/@warp-ds/core/dist/attention/utils/helpers.js
2474
+ // node_modules/.pnpm/@warp-ds+core@1.1.1_@floating-ui+dom@1.6.3/node_modules/@warp-ds/core/dist/attention/utils/helpers.js
2588
2475
  var TOP_START = "top-start";
2589
2476
  var TOP = "top";
2590
2477
  var TOP_END = "top-end";
@@ -2692,12 +2579,12 @@ async function useRecompute(state) {
2692
2579
  middleware: [
2693
2580
  offset({ mainAxis: (_b = state == null ? void 0 : state.distance) != null ? _b : 8, crossAxis: (_c = state == null ? void 0 : state.skidding) != null ? _c : 0 }),
2694
2581
  (state == null ? void 0 : state.flip) && flip2({
2695
- fallbackAxisSideDirection: "start",
2582
+ crossAxis: state == null ? void 0 : state.crossAxis,
2696
2583
  fallbackPlacements: state == null ? void 0 : state.fallbackPlacements
2697
2584
  }),
2698
- !(state == null ? void 0 : state.flip) && autoPlacement2(),
2699
- shift2({ padding: 16 }),
2700
- !(state == null ? void 0 : state.noArrow) && (state == null ? void 0 : state.arrowEl) && arrow2({ element: state == null ? void 0 : state.arrowEl })
2585
+ !(state == null ? void 0 : state.noArrow) && (state == null ? void 0 : state.arrowEl) && arrow2({ element: state == null ? void 0 : state.arrowEl }),
2586
+ hide2()
2587
+ //will hide the attentionEl when it appears detached from the targetEl. Can be called multiple times in the middleware-array if you want to use several strategies. Default strategy is 'referenceHidden'.
2701
2588
  ]
2702
2589
  }).then(({ x, y, middlewareData, placement }) => {
2703
2590
  state.actualDirection = placement;
@@ -2705,6 +2592,12 @@ async function useRecompute(state) {
2705
2592
  left: `${x}px`,
2706
2593
  top: `${y}px`
2707
2594
  });
2595
+ if ((middlewareData == null ? void 0 : middlewareData.hide) && !(state == null ? void 0 : state.isCallout)) {
2596
+ const { referenceHidden } = middlewareData == null ? void 0 : middlewareData.hide;
2597
+ Object.assign(attentionEl == null ? void 0 : attentionEl.style, {
2598
+ visibility: referenceHidden ? "hidden" : ""
2599
+ });
2600
+ }
2708
2601
  const isRtl = window.getComputedStyle(attentionEl).direction === "rtl";
2709
2602
  const arrowPlacement = arrowDirection(placement).split("-")[1];
2710
2603
  if ((middlewareData == null ? void 0 : middlewareData.arrow) && (state == null ? void 0 : state.arrowEl)) {
@@ -3254,6 +3147,7 @@ var WarpAttention = class extends kebabCaseAttributes(WarpElement) {
3254
3147
  this.distance = 8;
3255
3148
  this.skidding = 0;
3256
3149
  this.flip = false;
3150
+ this.crossAxis = false;
3257
3151
  this._initialPlacement = this.placement;
3258
3152
  this._actualDirection = this.placement;
3259
3153
  }
@@ -3338,7 +3232,8 @@ ${JSON.stringify(directions)}`);
3338
3232
  return this.renderRoot.querySelector("#attention");
3339
3233
  }
3340
3234
  get _targetEl() {
3341
- const targetSlot = this.renderRoot.querySelector("slot[name='target']");
3235
+ var _a;
3236
+ const targetSlot = (_a = this.renderRoot) == null ? void 0 : _a.querySelector("slot[name='target']");
3342
3237
  return targetSlot ? targetSlot.assignedNodes()[0] : null;
3343
3238
  }
3344
3239
  get _messageEl() {
@@ -3384,6 +3279,7 @@ ${JSON.stringify(directions)}`);
3384
3279
  distance: this.distance,
3385
3280
  skidding: this.skidding,
3386
3281
  flip: this.flip,
3282
+ crossAxis: this.crossAxis,
3387
3283
  fallbackPlacements: this.fallbackPlacements
3388
3284
  };
3389
3285
  useRecompute(this.attentionState);
@@ -3488,6 +3384,8 @@ ${JSON.stringify(directions)}`);
3488
3384
  }
3489
3385
  }
3490
3386
  render() {
3387
+ if (!this.callout && this._targetEl === void 0)
3388
+ return html2``;
3491
3389
  return html2`
3492
3390
  <div class=${ifDefined(this.className ? this.className : void 0)}>
3493
3391
  ${this.placement === "right-start" || this.placement === "right" || this.placement === "right-end" || this.placement === "bottom-start" || this.placement === "bottom" || this.placement === "bottom-end" ? html2`
@@ -3533,6 +3431,8 @@ __publicField(WarpAttention, "properties", {
3533
3431
  skidding: { type: Number, reflect: true },
3534
3432
  // Whether Attention element should flip its placement in order to keep it in view
3535
3433
  flip: { type: Boolean, reflect: true },
3434
+ // Whether Attention element should ignore cross axis overflow when flip is enabled
3435
+ crossAxis: { type: Boolean, reflect: true },
3536
3436
  // Choose which preferred placements the Attention element should flip to
3537
3437
  fallbackPlacements: { type: Array, reflect: true }
3538
3438
  });