@w5-ui/wc 0.8.0 → 0.8.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.js CHANGED
@@ -11783,6 +11783,18 @@ function Pill($$anchor, $$props) {
11783
11783
  });
11784
11784
  append($$anchor, span);
11785
11785
  }
11786
+ function along(pointer, size, viewport, margin) {
11787
+ const far = viewport - margin;
11788
+ if (pointer + size <= far) return Math.max(margin, pointer);
11789
+ if (pointer - size >= margin) return pointer - size;
11790
+ return Math.max(margin, Math.min(pointer, far - size));
11791
+ }
11792
+ function computeMenuPosition(input) {
11793
+ return {
11794
+ left: along(input.x, input.menuWidth, input.viewportWidth, input.margin),
11795
+ top: along(input.y, input.menuHeight, input.viewportHeight, input.margin)
11796
+ };
11797
+ }
11786
11798
  var root$2r = /* @__PURE__ */ from_html(`<li role="separator" class="my-1 h-px bg-row-active"></li>`);
11787
11799
  var root_1$1N = /* @__PURE__ */ from_html(` <!> `, 1);
11788
11800
  var root_2$1u = /* @__PURE__ */ from_html(`<li role="menuitem" class="flex cursor-pointer items-center whitespace-nowrap rounded-[5px] px-3 py-1.5 text-13 text-text-2 outline-none hover:bg-row-active hover:text-text-1 data-[active=true]:bg-row-active data-[active=true]:text-text-1 data-[danger=true]:text-status-danger data-[danger=true]:hover:bg-status-danger/10 data-[warning=true]:text-status-warning data-[warning=true]:hover:bg-status-warning/10 data-[success=true]:text-status-success data-[success=true]:hover:bg-status-success/10 aria-disabled:cursor-not-allowed aria-disabled:opacity-40"><!></li>`);
@@ -11809,10 +11821,25 @@ function ContextMenu($$anchor, $$props) {
11809
11821
  },
11810
11822
  []
11811
11823
  ));
11812
- const menuW = 168;
11813
- let menuH = /* @__PURE__ */ user_derived(() => items().length * 30 + 8);
11814
- let cx = /* @__PURE__ */ user_derived(() => Math.min(x(), (typeof window !== "undefined" ? window.innerWidth : 1200) - menuW - 8));
11815
- let cy = /* @__PURE__ */ user_derived(() => Math.min(y(), (typeof window !== "undefined" ? window.innerHeight : 800) - get(menuH) - 8));
11824
+ const MENU_MARGIN = 8;
11825
+ let cx = /* @__PURE__ */ state(0);
11826
+ let cy = /* @__PURE__ */ state(0);
11827
+ user_effect(() => {
11828
+ void items();
11829
+ if (!open() || get(menuEl) === void 0) return;
11830
+ const { width, height } = get(menuEl).getBoundingClientRect();
11831
+ const placed = computeMenuPosition({
11832
+ x: x(),
11833
+ y: y(),
11834
+ menuWidth: width,
11835
+ menuHeight: height,
11836
+ viewportWidth: window.innerWidth,
11837
+ viewportHeight: window.innerHeight,
11838
+ margin: MENU_MARGIN
11839
+ });
11840
+ set(cx, placed.left, true);
11841
+ set(cy, placed.top, true);
11842
+ });
11816
11843
  function activate(id) {
11817
11844
  $$props.onaction?.(id);
11818
11845
  $$props.onclose?.();