@ai-matrx/summon 0.1.1 → 0.1.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.
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(() => {