@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/window.js CHANGED
@@ -245,6 +245,7 @@ function LayoutIconButton({
245
245
  }
246
246
 
247
247
  // src/window/useWindowPanel.ts
248
+ import { globalSlot as globalSlot2 } from "@ai-matrx/kit/global-slot";
248
249
  import { useEffect, useRef, useCallback, useId, useState } from "react";
249
250
  import { useSummonDispatch, useSummonSelector, useSummonStore } from "@ai-matrx/summon/react";
250
251
  import {
@@ -431,10 +432,11 @@ function nextCascadeStep() {
431
432
  return seen % CASCADE_WRAP * CASCADE_STEP;
432
433
  }
433
434
  var NARROW_VIEWPORT = 768;
434
- var autoDocked = /* @__PURE__ */ new Set();
435
- var autoOrder = /* @__PURE__ */ new Map();
436
- var autoOrderNext = 0;
437
- var earlierDocked = (id) => (other) => other.id !== id && other.state === "windowed" && autoDocked.has(other.id) && (autoOrder.get(other.id) ?? 0) < (autoOrder.get(id) ?? 0);
435
+ var autoPlacement = () => globalSlot2("ai-matrx.summon.window.autoPlacement", () => ({ docked: /* @__PURE__ */ new Set(), order: /* @__PURE__ */ new Map(), next: 0 }));
436
+ var earlierDocked = (id) => (other) => {
437
+ const { docked, order } = autoPlacement();
438
+ return other.id !== id && other.state === "windowed" && docked.has(other.id) && (order.get(other.id) ?? 0) < (order.get(id) ?? 0);
439
+ };
438
440
  var AUTO_REPLACE_TICKS = 40;
439
441
  function shellHeaderClearance() {
440
442
  const GAP2 = 12;
@@ -495,7 +497,10 @@ function useWindowPanel(opts = {}) {
495
497
  const { vw, vh } = safeViewportDims();
496
498
  let autoPlaced = null;
497
499
  if (opts.autoOpened && vw >= NARROW_VIEWPORT) {
498
- if (!autoOrder.has(id)) autoOrder.set(id, autoOrderNext++);
500
+ {
501
+ const ap = autoPlacement();
502
+ if (!ap.order.has(id)) ap.order.set(id, ap.next++);
503
+ }
499
504
  const siblings = Object.values(store.getState().windowManager.windows).filter(earlierDocked(id)).map((win) => win.windowed);
500
505
  autoPlaced = resolveAutoOpenPlacement({
501
506
  width: w,
@@ -506,7 +511,7 @@ function useWindowPanel(opts = {}) {
506
511
  viewport: { vw, vh },
507
512
  siblings
508
513
  });
509
- if (!autoPlaced.minimized) autoDocked.add(id);
514
+ if (!autoPlaced.minimized) autoPlacement().docked.add(id);
510
515
  else if (opts.onAutoNoRoom) window.setTimeout(() => opts.onAutoNoRoom?.(), 0);
511
516
  }
512
517
  const pos = autoPlaced ? { x: autoPlaced.rect.x, y: autoPlaced.rect.y } : opts.initialRect?.x !== void 0 || opts.initialRect?.y !== void 0 ? {
@@ -535,8 +540,8 @@ function useWindowPanel(opts = {}) {
535
540
  }, 0) : null;
536
541
  return () => {
537
542
  if (confirmationTimer !== null) window.clearTimeout(confirmationTimer);
538
- autoDocked.delete(id);
539
- autoOrder.delete(id);
543
+ autoPlacement().docked.delete(id);
544
+ autoPlacement().order.delete(id);
540
545
  dispatch(unregisterWindow(id));
541
546
  };
542
547
  }, [id]);
@@ -575,7 +580,7 @@ function useWindowPanel(opts = {}) {
575
580
  siblings
576
581
  });
577
582
  if (next.minimized) {
578
- autoDocked.delete(id);
583
+ autoPlacement().docked.delete(id);
579
584
  if (opts.onAutoNoRoom) {
580
585
  window.clearInterval(timer);
581
586
  opts.onAutoNoRoom();
@@ -587,7 +592,7 @@ function useWindowPanel(opts = {}) {
587
592
  lastMinimized = true;
588
593
  return;
589
594
  }
590
- autoDocked.add(id);
595
+ autoPlacement().docked.add(id);
591
596
  if (isMin) dispatch(restoreWindow(id));
592
597
  const cur = store.getState().windowManager.windows[id]?.windowed;
593
598
  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) {
@@ -1374,8 +1379,8 @@ import {
1374
1379
 
1375
1380
  // src/window/popout/popoutWindowMap.ts
1376
1381
  import { useSyncExternalStore as useSyncExternalStore3 } from "react";
1377
- import { globalSlot as globalSlot2 } from "@ai-matrx/kit/global-slot";
1378
- var slot = () => globalSlot2("ai-matrx.summon.window.popoutWindows", () => ({ map: /* @__PURE__ */ new Map(), listeners: /* @__PURE__ */ new Set() }));
1382
+ import { globalSlot as globalSlot3 } from "@ai-matrx/kit/global-slot";
1383
+ var slot = () => globalSlot3("ai-matrx.summon.window.popoutWindows", () => ({ map: /* @__PURE__ */ new Map(), listeners: /* @__PURE__ */ new Set() }));
1379
1384
  function notify() {
1380
1385
  for (const fn of slot().listeners) fn();
1381
1386
  }
@@ -1794,8 +1799,8 @@ import {
1794
1799
  dockWindow as dockWindow2
1795
1800
  } from "@ai-matrx/summon";
1796
1801
  import { buildDockWindowPayload as buildDockWindowPayload2 } from "@ai-matrx/summon";
1797
- import { globalSlot as globalSlot3 } from "@ai-matrx/kit/global-slot";
1798
- var openers = () => globalSlot3("ai-matrx.summon.window.popoutOpeners", () => /* @__PURE__ */ new Map());
1802
+ import { globalSlot as globalSlot4 } from "@ai-matrx/kit/global-slot";
1803
+ var openers = () => globalSlot4("ai-matrx.summon.window.popoutOpeners", () => /* @__PURE__ */ new Map());
1799
1804
  function registerPopoutOpener(windowId, fn) {
1800
1805
  openers().set(windowId, fn);
1801
1806
  return () => {
@@ -1890,9 +1895,9 @@ function PopoutPortal({ windowId, children }) {
1890
1895
  }
1891
1896
 
1892
1897
  // src/window/tray/traySnapshotMap.ts
1893
- import { globalSlot as globalSlot4 } from "@ai-matrx/kit/global-slot";
1898
+ import { globalSlot as globalSlot5 } from "@ai-matrx/kit/global-slot";
1894
1899
  var MAX_SNAPSHOTS = 16;
1895
- var state = () => globalSlot4("ai-matrx.summon.window.traySnapshots", () => ({ map: /* @__PURE__ */ new Map(), listeners: /* @__PURE__ */ new Set() }));
1900
+ var state = () => globalSlot5("ai-matrx.summon.window.traySnapshots", () => ({ map: /* @__PURE__ */ new Map(), listeners: /* @__PURE__ */ new Set() }));
1896
1901
  function notify2() {
1897
1902
  for (const fn of state().listeners) fn();
1898
1903
  }
@@ -3899,8 +3904,8 @@ function mayRaiseUnbidden(overlayId, pathname) {
3899
3904
  }
3900
3905
 
3901
3906
  // src/window/utils/lazy-bundle-guard.ts
3902
- import { globalSlot as globalSlot5 } from "@ai-matrx/kit/global-slot";
3903
- var guard = () => globalSlot5("ai-matrx.summon.lazyBundleGuard", () => {
3907
+ import { globalSlot as globalSlot6 } from "@ai-matrx/kit/global-slot";
3908
+ var guard = () => globalSlot6("ai-matrx.summon.lazyBundleGuard", () => {
3904
3909
  const state2 = { bootInProgress: typeof window !== "undefined", reported: /* @__PURE__ */ new Set() };
3905
3910
  if (state2.bootInProgress) {
3906
3911
  setTimeout(() => {