@ai-matrx/summon 0.1.1 → 0.1.2

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/sheet.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/sheet/OverlaySheets.tsx","../src/dialog/closeBinding.ts"],"sourcesContent":["\"use client\";\n\nimport type { ComponentProps } from \"react\";\nimport { BottomSheet, Drawer, Sheet } from \"@ai-matrx/design-system\";\nimport { useOverlaySurfaceClose, type OverlaySurfaceCloseBinding } from \"../dialog/closeBinding\";\n\nfunction bindingOf(props: OverlaySurfaceCloseBinding): OverlaySurfaceCloseBinding {\n return (props.boundToOverlay ? { boundToOverlay: true, onClose: props.onClose } : { onClose: props.onClose, open: props.open }) as OverlaySurfaceCloseBinding;\n}\n\nexport type OverlaySheetProps = Omit<ComponentProps<typeof Sheet>, \"open\" | \"onOpenChange\" | \"defaultOpen\"> & OverlaySurfaceCloseBinding;\n\n/** The design-system Sheet (side panel), close-bound. Compose with `SheetContent` etc. */\nexport function OverlaySheet({ onClose, boundToOverlay, open, children, ...rest }: OverlaySheetProps) {\n const resolved = useOverlaySurfaceClose(bindingOf({ onClose, boundToOverlay, open } as OverlaySurfaceCloseBinding), \"OverlaySheet\");\n return (\n <Sheet {...rest} open={resolved.open} onOpenChange={resolved.onOpenChange}>\n {children}\n </Sheet>\n );\n}\n\ntype DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;\n\nexport type OverlayDrawerProps = DistributiveOmit<ComponentProps<typeof Drawer>, \"open\" | \"onOpenChange\" | \"defaultOpen\"> & OverlaySurfaceCloseBinding;\n\n/** The design-system Drawer (vaul), close-bound. Compose with `DrawerContent` etc. */\nexport function OverlayDrawer({ onClose, boundToOverlay, open, children, ...rest }: OverlayDrawerProps) {\n const resolved = useOverlaySurfaceClose(bindingOf({ onClose, boundToOverlay, open } as OverlaySurfaceCloseBinding), \"OverlayDrawer\");\n return (\n <Drawer {...(rest as ComponentProps<typeof Drawer>)} open={resolved.open} onOpenChange={resolved.onOpenChange}>\n {children}\n </Drawer>\n );\n}\n\nexport type OverlayBottomSheetProps = Omit<ComponentProps<typeof BottomSheet>, \"open\" | \"onOpenChange\"> & OverlaySurfaceCloseBinding;\n\n/** The design-system BottomSheet (phone sheet with header/body/footer), close-bound. */\nexport function OverlayBottomSheet({ onClose, boundToOverlay, open, children, ...rest }: OverlayBottomSheetProps) {\n const resolved = useOverlaySurfaceClose(bindingOf({ onClose, boundToOverlay, open } as OverlaySurfaceCloseBinding), \"OverlayBottomSheet\");\n return (\n <BottomSheet {...rest} open={resolved.open} onOpenChange={resolved.onOpenChange}>\n {children}\n </BottomSheet>\n );\n}\n","\"use client\";\n\n/**\n * The close binding every close-bound surface (dialog, sheet, drawer, bottom sheet) shares.\n *\n * Exactly one of two shapes, enforced by the type system (passing neither is a compile error):\n * - page-local: `onClose` (and usually `open`) — the page owns whether it is shown;\n * - instance-bound: `boundToOverlay` — rendered by an SummonHost; open while the instance is\n * shown (a `keepAlive: \"hidden\"` instance closes it), and closing closes the instance.\n */\nimport { useCallback } from \"react\";\nimport { useOptionalOverlayInstance, useOptionalSummonPorts } from \"@ai-matrx/summon/react\";\n\nexport type OverlaySurfaceCloseBinding =\n | {\n /** Page-local: called when the surface asks to close (Escape, scrim, close button). */\n onClose: () => void;\n boundToOverlay?: never;\n /** Page-local open state. Default true (render it only while open, or pass it). */\n open?: boolean | undefined;\n }\n | {\n /** Close through the enclosing SummonHost instance. */\n boundToOverlay: true;\n /** Optional extra hook run before the instance closes. */\n onClose?: (() => void) | undefined;\n open?: never;\n };\n\nexport interface ResolvedSurfaceClose {\n readonly open: boolean;\n readonly onOpenChange: (open: boolean) => void;\n}\n\nexport function useOverlaySurfaceClose(binding: OverlaySurfaceCloseBinding, surface: string): ResolvedSurfaceClose {\n const instance = useOptionalOverlayInstance();\n const ports = useOptionalSummonPorts();\n const { onClose, boundToOverlay } = binding;\n const open = boundToOverlay ? (instance ? !instance.hidden : false) : (binding.open ?? true);\n const onOpenChange = useCallback(\n (next: boolean) => {\n if (next) return;\n onClose?.();\n if (!boundToOverlay) return;\n if (instance) instance.close();\n else ports.errors.capture(new Error(`[summon] ${surface} boundToOverlay rendered outside an overlay instance`), { surface });\n },\n [boundToOverlay, instance, onClose, ports, surface],\n );\n return { open, onOpenChange };\n}\n"],"mappings":";;;AAGA,SAAS,aAAa,QAAQ,aAAa;;;ACO3C,SAAS,mBAAmB;AAC5B,SAAS,4BAA4B,8BAA8B;AAuB5D,SAAS,uBAAuB,SAAqC,SAAuC;AACjH,QAAM,WAAW,2BAA2B;AAC5C,QAAM,QAAQ,uBAAuB;AACrC,QAAM,EAAE,SAAS,eAAe,IAAI;AACpC,QAAM,OAAO,iBAAkB,WAAW,CAAC,SAAS,SAAS,QAAU,QAAQ,QAAQ;AACvF,QAAM,eAAe;AAAA,IACnB,CAAC,SAAkB;AACjB,UAAI,KAAM;AACV,gBAAU;AACV,UAAI,CAAC,eAAgB;AACrB,UAAI,SAAU,UAAS,MAAM;AAAA,UACxB,OAAM,OAAO,QAAQ,IAAI,MAAM,YAAY,OAAO,sDAAsD,GAAG,EAAE,QAAQ,CAAC;AAAA,IAC7H;AAAA,IACA,CAAC,gBAAgB,UAAU,SAAS,OAAO,OAAO;AAAA,EACpD;AACA,SAAO,EAAE,MAAM,aAAa;AAC9B;;;ADlCI;AAVJ,SAAS,UAAU,OAA+D;AAChF,SAAQ,MAAM,iBAAiB,EAAE,gBAAgB,MAAM,SAAS,MAAM,QAAQ,IAAI,EAAE,SAAS,MAAM,SAAS,MAAM,MAAM,KAAK;AAC/H;AAKO,SAAS,aAAa,EAAE,SAAS,gBAAgB,MAAM,UAAU,GAAG,KAAK,GAAsB;AACpG,QAAM,WAAW,uBAAuB,UAAU,EAAE,SAAS,gBAAgB,KAAK,CAA+B,GAAG,cAAc;AAClI,SACE,oBAAC,SAAO,GAAG,MAAM,MAAM,SAAS,MAAM,cAAc,SAAS,cAC1D,UACH;AAEJ;AAOO,SAAS,cAAc,EAAE,SAAS,gBAAgB,MAAM,UAAU,GAAG,KAAK,GAAuB;AACtG,QAAM,WAAW,uBAAuB,UAAU,EAAE,SAAS,gBAAgB,KAAK,CAA+B,GAAG,eAAe;AACnI,SACE,oBAAC,UAAQ,GAAI,MAAwC,MAAM,SAAS,MAAM,cAAc,SAAS,cAC9F,UACH;AAEJ;AAKO,SAAS,mBAAmB,EAAE,SAAS,gBAAgB,MAAM,UAAU,GAAG,KAAK,GAA4B;AAChH,QAAM,WAAW,uBAAuB,UAAU,EAAE,SAAS,gBAAgB,KAAK,CAA+B,GAAG,oBAAoB;AACxI,SACE,oBAAC,eAAa,GAAG,MAAM,MAAM,SAAS,MAAM,cAAc,SAAS,cAChE,UACH;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../src/sheet/OverlaySheets.tsx"],"sourcesContent":["\"use client\";\n\nimport type { ComponentProps } from \"react\";\nimport { BottomSheet, Drawer, Sheet } from \"@ai-matrx/design-system\";\nimport { useOverlaySurfaceClose, type OverlaySurfaceCloseBinding } from \"@ai-matrx/summon/dialog\";\n\nfunction bindingOf(props: OverlaySurfaceCloseBinding): OverlaySurfaceCloseBinding {\n return (props.boundToOverlay ? { boundToOverlay: true, onClose: props.onClose } : { onClose: props.onClose, open: props.open }) as OverlaySurfaceCloseBinding;\n}\n\nexport type OverlaySheetProps = Omit<ComponentProps<typeof Sheet>, \"open\" | \"onOpenChange\" | \"defaultOpen\"> & OverlaySurfaceCloseBinding;\n\n/** The design-system Sheet (side panel), close-bound. Compose with `SheetContent` etc. */\nexport function OverlaySheet({ onClose, boundToOverlay, open, children, ...rest }: OverlaySheetProps) {\n const resolved = useOverlaySurfaceClose(bindingOf({ onClose, boundToOverlay, open } as OverlaySurfaceCloseBinding), \"OverlaySheet\");\n return (\n <Sheet {...rest} open={resolved.open} onOpenChange={resolved.onOpenChange}>\n {children}\n </Sheet>\n );\n}\n\ntype DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;\n\nexport type OverlayDrawerProps = DistributiveOmit<ComponentProps<typeof Drawer>, \"open\" | \"onOpenChange\" | \"defaultOpen\"> & OverlaySurfaceCloseBinding;\n\n/** The design-system Drawer (vaul), close-bound. Compose with `DrawerContent` etc. */\nexport function OverlayDrawer({ onClose, boundToOverlay, open, children, ...rest }: OverlayDrawerProps) {\n const resolved = useOverlaySurfaceClose(bindingOf({ onClose, boundToOverlay, open } as OverlaySurfaceCloseBinding), \"OverlayDrawer\");\n return (\n <Drawer {...(rest as ComponentProps<typeof Drawer>)} open={resolved.open} onOpenChange={resolved.onOpenChange}>\n {children}\n </Drawer>\n );\n}\n\nexport type OverlayBottomSheetProps = Omit<ComponentProps<typeof BottomSheet>, \"open\" | \"onOpenChange\"> & OverlaySurfaceCloseBinding;\n\n/** The design-system BottomSheet (phone sheet with header/body/footer), close-bound. */\nexport function OverlayBottomSheet({ onClose, boundToOverlay, open, children, ...rest }: OverlayBottomSheetProps) {\n const resolved = useOverlaySurfaceClose(bindingOf({ onClose, boundToOverlay, open } as OverlaySurfaceCloseBinding), \"OverlayBottomSheet\");\n return (\n <BottomSheet {...rest} open={resolved.open} onOpenChange={resolved.onOpenChange}>\n {children}\n </BottomSheet>\n );\n}\n"],"mappings":";;;AAGA,SAAS,aAAa,QAAQ,aAAa;AAC3C,SAAS,8BAA+D;AAYpE;AAVJ,SAAS,UAAU,OAA+D;AAChF,SAAQ,MAAM,iBAAiB,EAAE,gBAAgB,MAAM,SAAS,MAAM,QAAQ,IAAI,EAAE,SAAS,MAAM,SAAS,MAAM,MAAM,KAAK;AAC/H;AAKO,SAAS,aAAa,EAAE,SAAS,gBAAgB,MAAM,UAAU,GAAG,KAAK,GAAsB;AACpG,QAAM,WAAW,uBAAuB,UAAU,EAAE,SAAS,gBAAgB,KAAK,CAA+B,GAAG,cAAc;AAClI,SACE,oBAAC,SAAO,GAAG,MAAM,MAAM,SAAS,MAAM,cAAc,SAAS,cAC1D,UACH;AAEJ;AAOO,SAAS,cAAc,EAAE,SAAS,gBAAgB,MAAM,UAAU,GAAG,KAAK,GAAuB;AACtG,QAAM,WAAW,uBAAuB,UAAU,EAAE,SAAS,gBAAgB,KAAK,CAA+B,GAAG,eAAe;AACnI,SACE,oBAAC,UAAQ,GAAI,MAAwC,MAAM,SAAS,MAAM,cAAc,SAAS,cAC9F,UACH;AAEJ;AAKO,SAAS,mBAAmB,EAAE,SAAS,gBAAgB,MAAM,UAAU,GAAG,KAAK,GAA4B;AAChH,QAAM,WAAW,uBAAuB,UAAU,EAAE,SAAS,gBAAgB,KAAK,CAA+B,GAAG,oBAAoB;AACxI,SACE,oBAAC,eAAa,GAAG,MAAM,MAAM,SAAS,MAAM,cAAc,SAAS,cAChE,UACH;AAEJ;","names":[]}
package/dist/window.cjs CHANGED
@@ -325,6 +325,7 @@ function LayoutIconButton({
325
325
  }
326
326
 
327
327
  // src/window/useWindowPanel.ts
328
+ var import_global_slot2 = require("@ai-matrx/kit/global-slot");
328
329
  var import_react = require("react");
329
330
  var import_react2 = require("@ai-matrx/summon/react");
330
331
  var import_summon = require("@ai-matrx/summon");
@@ -497,10 +498,11 @@ function nextCascadeStep() {
497
498
  return seen % CASCADE_WRAP * CASCADE_STEP;
498
499
  }
499
500
  var NARROW_VIEWPORT = 768;
500
- var autoDocked = /* @__PURE__ */ new Set();
501
- var autoOrder = /* @__PURE__ */ new Map();
502
- var autoOrderNext = 0;
503
- var earlierDocked = (id) => (other) => other.id !== id && other.state === "windowed" && autoDocked.has(other.id) && (autoOrder.get(other.id) ?? 0) < (autoOrder.get(id) ?? 0);
501
+ var autoPlacement = () => (0, import_global_slot2.globalSlot)("ai-matrx.summon.window.autoPlacement", () => ({ docked: /* @__PURE__ */ new Set(), order: /* @__PURE__ */ new Map(), next: 0 }));
502
+ var earlierDocked = (id) => (other) => {
503
+ const { docked, order } = autoPlacement();
504
+ return other.id !== id && other.state === "windowed" && docked.has(other.id) && (order.get(other.id) ?? 0) < (order.get(id) ?? 0);
505
+ };
504
506
  var AUTO_REPLACE_TICKS = 40;
505
507
  function shellHeaderClearance() {
506
508
  const GAP2 = 12;
@@ -561,7 +563,10 @@ function useWindowPanel(opts = {}) {
561
563
  const { vw, vh } = (0, import_summon2.safeViewportDims)();
562
564
  let autoPlaced = null;
563
565
  if (opts.autoOpened && vw >= NARROW_VIEWPORT) {
564
- if (!autoOrder.has(id)) autoOrder.set(id, autoOrderNext++);
566
+ {
567
+ const ap = autoPlacement();
568
+ if (!ap.order.has(id)) ap.order.set(id, ap.next++);
569
+ }
565
570
  const siblings = Object.values(store.getState().windowManager.windows).filter(earlierDocked(id)).map((win) => win.windowed);
566
571
  autoPlaced = resolveAutoOpenPlacement({
567
572
  width: w,
@@ -572,7 +577,7 @@ function useWindowPanel(opts = {}) {
572
577
  viewport: { vw, vh },
573
578
  siblings
574
579
  });
575
- if (!autoPlaced.minimized) autoDocked.add(id);
580
+ if (!autoPlaced.minimized) autoPlacement().docked.add(id);
576
581
  else if (opts.onAutoNoRoom) window.setTimeout(() => opts.onAutoNoRoom?.(), 0);
577
582
  }
578
583
  const pos = autoPlaced ? { x: autoPlaced.rect.x, y: autoPlaced.rect.y } : opts.initialRect?.x !== void 0 || opts.initialRect?.y !== void 0 ? {
@@ -601,8 +606,8 @@ function useWindowPanel(opts = {}) {
601
606
  }, 0) : null;
602
607
  return () => {
603
608
  if (confirmationTimer !== null) window.clearTimeout(confirmationTimer);
604
- autoDocked.delete(id);
605
- autoOrder.delete(id);
609
+ autoPlacement().docked.delete(id);
610
+ autoPlacement().order.delete(id);
606
611
  dispatch((0, import_summon.unregisterWindow)(id));
607
612
  };
608
613
  }, [id]);
@@ -641,7 +646,7 @@ function useWindowPanel(opts = {}) {
641
646
  siblings
642
647
  });
643
648
  if (next.minimized) {
644
- autoDocked.delete(id);
649
+ autoPlacement().docked.delete(id);
645
650
  if (opts.onAutoNoRoom) {
646
651
  window.clearInterval(timer);
647
652
  opts.onAutoNoRoom();
@@ -653,7 +658,7 @@ function useWindowPanel(opts = {}) {
653
658
  lastMinimized = true;
654
659
  return;
655
660
  }
656
- autoDocked.add(id);
661
+ autoPlacement().docked.add(id);
657
662
  if (isMin) dispatch((0, import_summon.restoreWindow)(id));
658
663
  const cur = store.getState().windowManager.windows[id]?.windowed;
659
664
  if (!cur || Math.abs(cur.x - next.rect.x) > 4 || Math.abs(cur.y - next.rect.y) > 4 || Math.abs(cur.width - next.rect.width) > 4 || Math.abs(cur.height - next.rect.height) > 4) {
@@ -1429,8 +1434,8 @@ var import_summon3 = require("@ai-matrx/summon");
1429
1434
 
1430
1435
  // src/window/popout/popoutWindowMap.ts
1431
1436
  var import_react9 = require("react");
1432
- var import_global_slot2 = require("@ai-matrx/kit/global-slot");
1433
- var slot = () => (0, import_global_slot2.globalSlot)("ai-matrx.summon.window.popoutWindows", () => ({ map: /* @__PURE__ */ new Map(), listeners: /* @__PURE__ */ new Set() }));
1437
+ var import_global_slot3 = require("@ai-matrx/kit/global-slot");
1438
+ var slot = () => (0, import_global_slot3.globalSlot)("ai-matrx.summon.window.popoutWindows", () => ({ map: /* @__PURE__ */ new Map(), listeners: /* @__PURE__ */ new Set() }));
1434
1439
  function notify() {
1435
1440
  for (const fn of slot().listeners) fn();
1436
1441
  }
@@ -1847,8 +1852,8 @@ var import_react12 = require("react");
1847
1852
  var import_react13 = require("@ai-matrx/summon/react");
1848
1853
  var import_summon5 = require("@ai-matrx/summon");
1849
1854
  var import_summon6 = require("@ai-matrx/summon");
1850
- var import_global_slot3 = require("@ai-matrx/kit/global-slot");
1851
- var openers = () => (0, import_global_slot3.globalSlot)("ai-matrx.summon.window.popoutOpeners", () => /* @__PURE__ */ new Map());
1855
+ var import_global_slot4 = require("@ai-matrx/kit/global-slot");
1856
+ var openers = () => (0, import_global_slot4.globalSlot)("ai-matrx.summon.window.popoutOpeners", () => /* @__PURE__ */ new Map());
1852
1857
  function registerPopoutOpener(windowId, fn) {
1853
1858
  openers().set(windowId, fn);
1854
1859
  return () => {
@@ -1943,9 +1948,9 @@ function PopoutPortal({ windowId, children }) {
1943
1948
  }
1944
1949
 
1945
1950
  // src/window/tray/traySnapshotMap.ts
1946
- var import_global_slot4 = require("@ai-matrx/kit/global-slot");
1951
+ var import_global_slot5 = require("@ai-matrx/kit/global-slot");
1947
1952
  var MAX_SNAPSHOTS = 16;
1948
- var state = () => (0, import_global_slot4.globalSlot)("ai-matrx.summon.window.traySnapshots", () => ({ map: /* @__PURE__ */ new Map(), listeners: /* @__PURE__ */ new Set() }));
1953
+ var state = () => (0, import_global_slot5.globalSlot)("ai-matrx.summon.window.traySnapshots", () => ({ map: /* @__PURE__ */ new Map(), listeners: /* @__PURE__ */ new Set() }));
1949
1954
  function notify2() {
1950
1955
  for (const fn of state().listeners) fn();
1951
1956
  }
@@ -3941,8 +3946,8 @@ function mayRaiseUnbidden(overlayId, pathname) {
3941
3946
  }
3942
3947
 
3943
3948
  // src/window/utils/lazy-bundle-guard.ts
3944
- var import_global_slot5 = require("@ai-matrx/kit/global-slot");
3945
- var guard = () => (0, import_global_slot5.globalSlot)("ai-matrx.summon.lazyBundleGuard", () => {
3949
+ var import_global_slot6 = require("@ai-matrx/kit/global-slot");
3950
+ var guard = () => (0, import_global_slot6.globalSlot)("ai-matrx.summon.lazyBundleGuard", () => {
3946
3951
  const state2 = { bootInProgress: typeof window !== "undefined", reported: /* @__PURE__ */ new Set() };
3947
3952
  if (state2.bootInProgress) {
3948
3953
  setTimeout(() => {