@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.
package/dist/angular.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkE47Q36LM_cjs = require('./chunk-E47Q36LM.cjs');
3
+ var chunk2VRCYMKH_cjs = require('./chunk-2VRCYMKH.cjs');
4
4
  var core = require('@angular/core');
5
5
 
6
6
  function onDestroy(dispose) {
@@ -13,7 +13,7 @@ function onDestroy(dispose) {
13
13
  destroyRef?.onDestroy(dispose);
14
14
  }
15
15
  function useWindowManager(options) {
16
- const wm = chunkE47Q36LM_cjs.createWindowManager(options);
16
+ const wm = chunk2VRCYMKH_cjs.createWindowManager(options);
17
17
  onDestroy(() => wm.destroy());
18
18
  return wm;
19
19
  }
@@ -28,7 +28,7 @@ function useWmWindow(wm, id) {
28
28
  return core.computed(() => state().windows[id]);
29
29
  }
30
30
  function createDesktop(wm, options) {
31
- const binder = chunkE47Q36LM_cjs.createDesktopBinder(wm, options);
31
+ const binder = chunk2VRCYMKH_cjs.createDesktopBinder(wm, options);
32
32
  onDestroy(() => binder.destroy());
33
33
  return {
34
34
  binder,
package/dist/angular.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createWindowManager, createDesktopBinder } from './chunk-VQ3TLK3N.js';
1
+ import { createWindowManager, createDesktopBinder } from './chunk-WOCAQEM6.js';
2
2
  import { signal, computed, inject, DestroyRef } from '@angular/core';
3
3
 
4
4
  function onDestroy(dispose) {
@@ -1027,6 +1027,7 @@ function createWindowManager(options = {}) {
1027
1027
  }
1028
1028
  }
1029
1029
  function applyEntry(entry) {
1030
+ const previousWindows = windows;
1030
1031
  windows = entry.windows;
1031
1032
  order = [...entry.order];
1032
1033
  modalCount = countModals();
@@ -1038,6 +1039,16 @@ function createWindowManager(options = {}) {
1038
1039
  if (workspace !== previousWorkspace) {
1039
1040
  queueEvent(() => emitter.emit("workspace", { workspace, previous: previousWorkspace }));
1040
1041
  }
1042
+ for (const id of Object.keys(previousWindows)) {
1043
+ if (windows[id]) continue;
1044
+ const closed = previousWindows[id];
1045
+ queueEvent(() => emitter.emit("close", { window: closed }));
1046
+ }
1047
+ for (const id of order) {
1048
+ if (previousWindows[id]) continue;
1049
+ const opened = windows[id];
1050
+ queueEvent(() => emitter.emit("open", { window: opened }));
1051
+ }
1041
1052
  reflowViewport();
1042
1053
  commit();
1043
1054
  }
@@ -1988,7 +1999,7 @@ function attachDesktop(wm, element, options = {}) {
1988
1999
  const registry = /* @__PURE__ */ new Map();
1989
2000
  const cleanup = [];
1990
2001
  let lastOrder = null;
1991
- let lastFocused = null;
2002
+ let focusedEl = null;
1992
2003
  let drag = null;
1993
2004
  let groupTargetId = null;
1994
2005
  let groupTargetEl = null;
@@ -2175,16 +2186,11 @@ function attachDesktop(wm, element, options = {}) {
2175
2186
  }
2176
2187
  }
2177
2188
  if (orderChanged) applyStacking(state.order);
2178
- if (state.focusedId !== lastFocused) {
2179
- if (lastFocused) {
2180
- const prev = registry.get(lastFocused);
2181
- if (prev) delete prev.element.dataset.wmFocused;
2182
- }
2183
- if (state.focusedId) {
2184
- const next = registry.get(state.focusedId);
2185
- if (next) next.element.dataset.wmFocused = "";
2186
- }
2187
- lastFocused = state.focusedId;
2189
+ const wanted = state.focusedId ? registry.get(state.focusedId)?.element ?? null : null;
2190
+ if (wanted !== focusedEl) {
2191
+ if (focusedEl) delete focusedEl.dataset.wmFocused;
2192
+ focusedEl = wanted;
2193
+ if (focusedEl) focusedEl.dataset.wmFocused = "";
2188
2194
  }
2189
2195
  lastOrder = state.order;
2190
2196
  }
@@ -2414,23 +2420,31 @@ function attachDesktop(wm, element, options = {}) {
2414
2420
  };
2415
2421
  windowElement.addEventListener("keydown", onModalTrap);
2416
2422
  attached.cleanup.push(() => windowElement.removeEventListener("keydown", onModalTrap));
2423
+ let detached = false;
2417
2424
  const detach = () => {
2425
+ if (detached) return;
2426
+ detached = true;
2418
2427
  if (drag?.id === id) endDrag(true);
2419
2428
  for (const dispose of attached.cleanup) dispose();
2420
2429
  for (const resizeHandle of attached.handles) resizeHandle.remove();
2421
2430
  registry.delete(id);
2431
+ if (registry.get(id)?.element !== windowElement) delete windowElement.dataset.wmWindow;
2432
+ delete windowElement.dataset.wmFocused;
2433
+ delete windowElement.dataset.wmTabTarget;
2434
+ if (focusedEl === windowElement) focusedEl = null;
2435
+ if (groupTargetEl === windowElement) {
2436
+ groupTargetId = null;
2437
+ groupTargetEl = null;
2438
+ }
2422
2439
  };
2423
- if (windowOptions.removeOnClose) {
2424
- const stopOnClose = wm.on("close", ({ window: closed }) => {
2425
- if (closed.id !== id) return;
2426
- detach();
2427
- windowElement.remove();
2428
- });
2429
- attached.cleanup.push(stopOnClose);
2430
- }
2440
+ const stopOnClose = wm.on("close", ({ window: closed }) => {
2441
+ if (closed.id !== id) return;
2442
+ detach();
2443
+ if (windowOptions.removeOnClose) windowElement.remove();
2444
+ });
2445
+ attached.cleanup.push(stopOnClose);
2431
2446
  registry.set(id, attached);
2432
2447
  lastOrder = null;
2433
- lastFocused = null;
2434
2448
  syncAll();
2435
2449
  if (wm.getState().focusedId === id && !windowElement.contains(doc.activeElement)) {
2436
2450
  windowElement.focus({ preventScroll: true });
@@ -2520,5 +2534,5 @@ exports.flipToTarget = flipToTarget;
2520
2534
  exports.magnetize = magnetize;
2521
2535
  exports.prefersReducedMotion = prefersReducedMotion;
2522
2536
  exports.zoneBounds = zoneBounds;
2523
- //# sourceMappingURL=chunk-E47Q36LM.cjs.map
2524
- //# sourceMappingURL=chunk-E47Q36LM.cjs.map
2537
+ //# sourceMappingURL=chunk-2VRCYMKH.cjs.map
2538
+ //# sourceMappingURL=chunk-2VRCYMKH.cjs.map