@surdeddd/wmkit 0.7.0 → 0.7.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.
@@ -1025,6 +1025,7 @@ function createWindowManager(options = {}) {
1025
1025
  }
1026
1026
  }
1027
1027
  function applyEntry(entry) {
1028
+ const previousWindows = windows;
1028
1029
  windows = entry.windows;
1029
1030
  order = [...entry.order];
1030
1031
  modalCount = countModals();
@@ -1036,6 +1037,16 @@ function createWindowManager(options = {}) {
1036
1037
  if (workspace !== previousWorkspace) {
1037
1038
  queueEvent(() => emitter.emit("workspace", { workspace, previous: previousWorkspace }));
1038
1039
  }
1040
+ for (const id of Object.keys(previousWindows)) {
1041
+ if (windows[id]) continue;
1042
+ const closed = previousWindows[id];
1043
+ queueEvent(() => emitter.emit("close", { window: closed }));
1044
+ }
1045
+ for (const id of order) {
1046
+ if (previousWindows[id]) continue;
1047
+ const opened = windows[id];
1048
+ queueEvent(() => emitter.emit("open", { window: opened }));
1049
+ }
1039
1050
  reflowViewport();
1040
1051
  commit();
1041
1052
  }
@@ -1986,7 +1997,7 @@ function attachDesktop(wm, element, options = {}) {
1986
1997
  const registry = /* @__PURE__ */ new Map();
1987
1998
  const cleanup = [];
1988
1999
  let lastOrder = null;
1989
- let lastFocused = null;
2000
+ let focusedEl = null;
1990
2001
  let drag = null;
1991
2002
  let groupTargetId = null;
1992
2003
  let groupTargetEl = null;
@@ -2173,16 +2184,11 @@ function attachDesktop(wm, element, options = {}) {
2173
2184
  }
2174
2185
  }
2175
2186
  if (orderChanged) applyStacking(state.order);
2176
- if (state.focusedId !== lastFocused) {
2177
- if (lastFocused) {
2178
- const prev = registry.get(lastFocused);
2179
- if (prev) delete prev.element.dataset.wmFocused;
2180
- }
2181
- if (state.focusedId) {
2182
- const next = registry.get(state.focusedId);
2183
- if (next) next.element.dataset.wmFocused = "";
2184
- }
2185
- lastFocused = state.focusedId;
2187
+ const wanted = state.focusedId ? registry.get(state.focusedId)?.element ?? null : null;
2188
+ if (wanted !== focusedEl) {
2189
+ if (focusedEl) delete focusedEl.dataset.wmFocused;
2190
+ focusedEl = wanted;
2191
+ if (focusedEl) focusedEl.dataset.wmFocused = "";
2186
2192
  }
2187
2193
  lastOrder = state.order;
2188
2194
  }
@@ -2412,23 +2418,31 @@ function attachDesktop(wm, element, options = {}) {
2412
2418
  };
2413
2419
  windowElement.addEventListener("keydown", onModalTrap);
2414
2420
  attached.cleanup.push(() => windowElement.removeEventListener("keydown", onModalTrap));
2421
+ let detached = false;
2415
2422
  const detach = () => {
2423
+ if (detached) return;
2424
+ detached = true;
2416
2425
  if (drag?.id === id) endDrag(true);
2417
2426
  for (const dispose of attached.cleanup) dispose();
2418
2427
  for (const resizeHandle of attached.handles) resizeHandle.remove();
2419
2428
  registry.delete(id);
2429
+ if (registry.get(id)?.element !== windowElement) delete windowElement.dataset.wmWindow;
2430
+ delete windowElement.dataset.wmFocused;
2431
+ delete windowElement.dataset.wmTabTarget;
2432
+ if (focusedEl === windowElement) focusedEl = null;
2433
+ if (groupTargetEl === windowElement) {
2434
+ groupTargetId = null;
2435
+ groupTargetEl = null;
2436
+ }
2420
2437
  };
2421
- if (windowOptions.removeOnClose) {
2422
- const stopOnClose = wm.on("close", ({ window: closed }) => {
2423
- if (closed.id !== id) return;
2424
- detach();
2425
- windowElement.remove();
2426
- });
2427
- attached.cleanup.push(stopOnClose);
2428
- }
2438
+ const stopOnClose = wm.on("close", ({ window: closed }) => {
2439
+ if (closed.id !== id) return;
2440
+ detach();
2441
+ if (windowOptions.removeOnClose) windowElement.remove();
2442
+ });
2443
+ attached.cleanup.push(stopOnClose);
2429
2444
  registry.set(id, attached);
2430
2445
  lastOrder = null;
2431
- lastFocused = null;
2432
2446
  syncAll();
2433
2447
  if (wm.getState().focusedId === id && !windowElement.contains(doc.activeElement)) {
2434
2448
  windowElement.focus({ preventScroll: true });
@@ -2502,5 +2516,5 @@ function createDesktopBinder(wm, options = {}) {
2502
2516
  }
2503
2517
 
2504
2518
  export { applyAspect, attachDesktop, boundsEqual, clamp, clampSize, clampToViewport, createAnnouncer, createDesktopBinder, createEmitter, createWindowManager, defaultMessages, detectSnapZone, flipFromTarget, flipToTarget, magnetize, prefersReducedMotion, zoneBounds };
2505
- //# sourceMappingURL=chunk-VQ3TLK3N.js.map
2506
- //# sourceMappingURL=chunk-VQ3TLK3N.js.map
2519
+ //# sourceMappingURL=chunk-WOCAQEM6.js.map
2520
+ //# sourceMappingURL=chunk-WOCAQEM6.js.map