@surdeddd/wmkit 0.5.0 → 0.5.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 chunkRXAMUBUJ_cjs = require('./chunk-RXAMUBUJ.cjs');
3
+ var chunkC2UHNBSA_cjs = require('./chunk-C2UHNBSA.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 = chunkRXAMUBUJ_cjs.createWindowManager(options);
16
+ const wm = chunkC2UHNBSA_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 = chunkRXAMUBUJ_cjs.createDesktopBinder(wm, options);
31
+ const binder = chunkC2UHNBSA_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-L43XBN44.js';
1
+ import { createWindowManager, createDesktopBinder } from './chunk-2WQHHYYR.js';
2
2
  import { signal, computed, inject, DestroyRef } from '@angular/core';
3
3
 
4
4
  function onDestroy(dispose) {
@@ -252,16 +252,22 @@ function createWindowManager(options = {}) {
252
252
  function sortByLayer(ids) {
253
253
  return ids.map((id, index) => ({ id, index, rank: layerRankOf(id) })).sort((a, b) => a.rank !== b.rank ? a.rank - b.rank : a.index - b.index).map((entry) => entry.id);
254
254
  }
255
+ function blockOf(id) {
256
+ const win = windows[id];
257
+ if (win.groupId === null) return [id];
258
+ return [...membersOf(win.groupId).filter((entry) => entry !== id), id];
259
+ }
255
260
  function raise(id) {
256
261
  const win = windows[id];
257
- const without = order.filter((entry) => entry !== id);
262
+ const block = blockOf(id);
263
+ const without = order.filter((entry) => !block.includes(entry));
258
264
  const rank = LAYER_RANK[win.layer];
259
265
  let insertAt = without.length;
260
266
  for (let i = without.length - 1; i >= 0; i -= 1) {
261
267
  if (layerRankOf(without[i]) > rank) insertAt = i;
262
268
  else break;
263
269
  }
264
- const next = [...without.slice(0, insertAt), id, ...without.slice(insertAt)];
270
+ const next = [...without.slice(0, insertAt), ...block, ...without.slice(insertAt)];
265
271
  const changed = next.length !== order.length || next.some((entry, i) => entry !== order[i]);
266
272
  order = next;
267
273
  return changed;
@@ -276,7 +282,7 @@ function createWindowManager(options = {}) {
276
282
  return win.groupId === null || activeTabs[win.groupId] === win.id;
277
283
  }
278
284
  function buildGroups() {
279
- const result = {};
285
+ const result = /* @__PURE__ */ Object.create(null);
280
286
  for (const [groupId, activeId] of Object.entries(activeTabs)) {
281
287
  result[groupId] = { id: groupId, activeId, members: membersOf(groupId) };
282
288
  }
@@ -333,6 +339,14 @@ function createWindowManager(options = {}) {
333
339
  const targets = focusTargets();
334
340
  focusedId = targets.length > 0 ? targets[targets.length - 1] : null;
335
341
  }
342
+ function reconcileFocus() {
343
+ if (focusedId === null) return;
344
+ const win = windows[focusedId];
345
+ if (win && win.stage !== "minimized" && onActiveWorkspace(win) && isVisibleTab(win)) return;
346
+ const previous = focusedId;
347
+ focusTop();
348
+ if (focusedId) emitFocus(windows[focusedId], previous);
349
+ }
336
350
  function emitFocus(win, previous) {
337
351
  queueEvent(() => emitter.emit("focus", { window: win, previous }));
338
352
  }
@@ -454,7 +468,6 @@ function createWindowManager(options = {}) {
454
468
  const win = windows[id];
455
469
  if (!win) return false;
456
470
  if (!onActiveWorkspace(win)) setWorkspace(win.workspace);
457
- if (!isVisibleTab(win)) activateTab(id);
458
471
  const modal = topModalId();
459
472
  if (modal && modal !== id && win.layer !== "modal") {
460
473
  const modalWin = windows[modal];
@@ -462,6 +475,7 @@ function createWindowManager(options = {}) {
462
475
  commitQuiet();
463
476
  return false;
464
477
  }
478
+ if (!isVisibleTab(win)) activateTab(id);
465
479
  if (win.stage === "minimized") {
466
480
  restore(id);
467
481
  return focusedId === id;
@@ -516,6 +530,7 @@ function createWindowManager(options = {}) {
516
530
  setWindow(next);
517
531
  syncGroup(next);
518
532
  queueEvent(() => emitter.emit("stage", { window: next, previous: win.stage }));
533
+ if (next.groupId !== null) reconcileFocus();
519
534
  commit();
520
535
  return true;
521
536
  }
@@ -720,6 +735,8 @@ function createWindowManager(options = {}) {
720
735
  if (!onActiveWorkspace(updated) && focusedId === id) {
721
736
  focusTop();
722
737
  if (focusedId) emitFocus(windows[focusedId], id);
738
+ } else if (updated.groupId !== null && !onActiveWorkspace(updated)) {
739
+ reconcileFocus();
723
740
  } else if (onActiveWorkspace(updated) && topModalId() === id && focusedId !== id) {
724
741
  const previous = focusedId;
725
742
  focusedId = id;
@@ -745,7 +762,16 @@ function createWindowManager(options = {}) {
745
762
  for (const entry of siblings) if (!expanded.includes(entry)) expanded.push(entry);
746
763
  }
747
764
  if (expanded.length < 2) return null;
748
- const groupId = `${idPrefix}-group-${++groupCounter}`;
765
+ let groupId = `${idPrefix}-group-${++groupCounter}`;
766
+ while (activeTabs[groupId]) groupId = `${idPrefix}-group-${++groupCounter}`;
767
+ const shared = expanded.reduce(
768
+ (size, id) => {
769
+ const fit = normalizeSize(size, windows[id]);
770
+ return { width: Math.max(size.width, fit.width), height: Math.max(size.height, fit.height) };
771
+ },
772
+ { width: host.bounds.width, height: host.bounds.height }
773
+ );
774
+ const bounds = { x: host.bounds.x, y: host.bounds.y, ...shared };
749
775
  const retired = /* @__PURE__ */ new Set();
750
776
  for (const id of expanded) {
751
777
  const win = windows[id];
@@ -753,7 +779,7 @@ function createWindowManager(options = {}) {
753
779
  setWindow({
754
780
  ...win,
755
781
  groupId,
756
- bounds: host.bounds,
782
+ bounds,
757
783
  stage: host.stage,
758
784
  snapZone: host.snapZone,
759
785
  restoreBounds: host.restoreBounds,
@@ -768,8 +794,10 @@ function createWindowManager(options = {}) {
768
794
  raise(host.id);
769
795
  emitGroup(groupId, null);
770
796
  queueEvent(() => emitter.emit("order", { order }));
797
+ const hostVisible = onActiveWorkspace(host) && host.stage !== "minimized";
798
+ if (!hostVisible) reconcileFocus();
771
799
  commit();
772
- if (onActiveWorkspace(host) && host.stage !== "minimized") focus(host.id);
800
+ if (hostVisible) focus(host.id);
773
801
  return groupId;
774
802
  }
775
803
  function ungroup(id) {
@@ -783,7 +811,7 @@ function createWindowManager(options = {}) {
783
811
  dissolveIfOrphaned(groupId);
784
812
  if (membersOf(groupId).length >= 2) emitGroup(groupId, wasActive ? id : null);
785
813
  commit();
786
- focus(id);
814
+ if (onActiveWorkspace(win) && win.stage !== "minimized") focus(id);
787
815
  return true;
788
816
  }
789
817
  function activateTab(id) {
@@ -793,6 +821,10 @@ function createWindowManager(options = {}) {
793
821
  const previous = activeTabs[groupId];
794
822
  if (previous === id) return false;
795
823
  activeTabs = { ...activeTabs, [groupId]: id };
824
+ if (focusedId === previous) {
825
+ focusedId = id;
826
+ emitFocus(win, previous);
827
+ }
796
828
  emitGroup(groupId, previous);
797
829
  commit();
798
830
  return true;
@@ -803,14 +835,15 @@ function createWindowManager(options = {}) {
803
835
  function sendToBack(id) {
804
836
  const win = windows[id];
805
837
  if (!win) return false;
806
- const without = order.filter((entry) => entry !== id);
838
+ const block = blockOf(id);
839
+ const without = order.filter((entry) => !block.includes(entry));
807
840
  const rank = LAYER_RANK[win.layer];
808
841
  let insertAt = 0;
809
842
  for (const entry of without) {
810
843
  if (layerRankOf(entry) < rank) insertAt += 1;
811
844
  else break;
812
845
  }
813
- const next = [...without.slice(0, insertAt), id, ...without.slice(insertAt)];
846
+ const next = [...without.slice(0, insertAt), ...block, ...without.slice(insertAt)];
814
847
  if (next.every((entry, i) => entry === order[i])) return false;
815
848
  order = next;
816
849
  queueEvent(() => emitter.emit("order", { order }));
@@ -874,19 +907,23 @@ function createWindowManager(options = {}) {
874
907
  function reflowViewport() {
875
908
  for (const id of order) {
876
909
  const win = windows[id];
910
+ if (!isVisibleTab(win)) continue;
877
911
  if (win.stage === "maximized") {
878
912
  const updated = { ...win, bounds: fullBounds() };
879
913
  setWindow(updated);
914
+ syncGroup(updated);
880
915
  queueEvent(() => emitter.emit("resize", { window: updated }));
881
916
  } else if (win.stage === "snapped" && win.snapZone) {
882
917
  const updated = { ...win, bounds: snapBounds(win, win.snapZone) };
883
918
  setWindow(updated);
919
+ syncGroup(updated);
884
920
  queueEvent(() => emitter.emit("resize", { window: updated }));
885
921
  } else if (win.stage === "normal" && keepInViewport) {
886
922
  const bounds = clampToViewport(win.bounds, viewport, minVisible);
887
923
  if (!boundsEqual(bounds, win.bounds)) {
888
924
  const updated = { ...win, bounds };
889
925
  setWindow(updated);
926
+ syncGroup(updated);
890
927
  queueEvent(() => emitter.emit("move", { window: updated }));
891
928
  }
892
929
  }
@@ -973,7 +1010,7 @@ function createWindowManager(options = {}) {
973
1010
  function arrange(mode) {
974
1011
  const ids = order.filter((id) => {
975
1012
  const win = windows[id];
976
- return win.stage !== "minimized" && onActiveWorkspace(win);
1013
+ return win.stage !== "minimized" && onActiveWorkspace(win) && isVisibleTab(win);
977
1014
  });
978
1015
  if (ids.length === 0) return;
979
1016
  if (mode === "cascade") {
@@ -1005,7 +1042,8 @@ function createWindowManager(options = {}) {
1005
1042
  }
1006
1043
  function minimizeAll() {
1007
1044
  for (const id of [...order]) {
1008
- if (onActiveWorkspace(windows[id])) minimize(id);
1045
+ const win = windows[id];
1046
+ if (onActiveWorkspace(win) && isVisibleTab(win)) minimize(id);
1009
1047
  }
1010
1048
  }
1011
1049
  function restoreAll() {
@@ -1125,7 +1163,7 @@ function createWindowManager(options = {}) {
1125
1163
  if (focusedCandidate && (focusedCandidate.stage === "minimized" || !onActiveWorkspace(focusedCandidate))) {
1126
1164
  focusedId = null;
1127
1165
  }
1128
- const restoredTabs = {};
1166
+ const restoredTabs = /* @__PURE__ */ Object.create(null);
1129
1167
  const rawTabs = data.activeTabs;
1130
1168
  for (const id of order) {
1131
1169
  const groupId = windows[id].groupId;
@@ -1398,6 +1436,8 @@ function createDragStarter(ctx) {
1398
1436
  const el = ctx.windowElement(id);
1399
1437
  function armGroup(target2) {
1400
1438
  session.groupTarget = target2;
1439
+ session.zone = null;
1440
+ ctx.hidePreview();
1401
1441
  ctx.markGroupTarget(target2);
1402
1442
  }
1403
1443
  function clearHover() {
@@ -1442,9 +1482,9 @@ function createDragStarter(ctx) {
1442
1482
  for (const otherId of state.order) {
1443
1483
  if (otherId === id) continue;
1444
1484
  const other = state.windows[otherId];
1445
- if (other && other.stage !== "minimized" && other.workspace === state.workspace) {
1446
- targets.push(other.bounds);
1447
- }
1485
+ if (!other || other.stage === "minimized" || other.workspace !== state.workspace) continue;
1486
+ if (other.groupId !== null && state.groups[other.groupId]?.activeId !== otherId) continue;
1487
+ targets.push(other.bounds);
1448
1488
  }
1449
1489
  const magnet = magnetize(
1450
1490
  { x: nextX, y: nextY, width: current.bounds.width, height: current.bounds.height },
@@ -1755,6 +1795,7 @@ function attachDesktop(wm, element, options = {}) {
1755
1795
  let lastFocused = null;
1756
1796
  let drag = null;
1757
1797
  let groupTargetId = null;
1798
+ let groupTargetEl = null;
1758
1799
  let cachedRect = null;
1759
1800
  let rectUsers = 0;
1760
1801
  let announcer = null;
@@ -1833,21 +1874,16 @@ function attachDesktop(wm, element, options = {}) {
1833
1874
  const handle = node.closest?.("[data-wm-drag]");
1834
1875
  const host = handle?.closest("[data-wm-window]");
1835
1876
  const id = host?.dataset.wmWindow;
1836
- if (id && id !== selfId && registry.has(id)) return id;
1877
+ if (id && id !== selfId && registry.get(id)?.element === host) return id;
1837
1878
  }
1838
1879
  return null;
1839
1880
  },
1840
1881
  markGroupTarget(id) {
1841
1882
  if (groupTargetId === id) return;
1842
- if (groupTargetId) {
1843
- const previous = registry.get(groupTargetId);
1844
- if (previous) delete previous.element.dataset.wmTabTarget;
1845
- }
1883
+ if (groupTargetEl) delete groupTargetEl.dataset.wmTabTarget;
1846
1884
  groupTargetId = id;
1847
- if (id) {
1848
- const next = registry.get(id);
1849
- if (next) next.element.dataset.wmTabTarget = "";
1850
- }
1885
+ groupTargetEl = id ? registry.get(id)?.element ?? null : null;
1886
+ if (groupTargetEl) groupTargetEl.dataset.wmTabTarget = "";
1851
1887
  },
1852
1888
  currentDrag: () => drag,
1853
1889
  claimDrag(session) {
@@ -2249,5 +2285,5 @@ function createDesktopBinder(wm, options = {}) {
2249
2285
  }
2250
2286
 
2251
2287
  export { applyAspect, attachDesktop, boundsEqual, clamp, clampSize, clampToViewport, createAnnouncer, createDesktopBinder, createEmitter, createWindowManager, defaultMessages, detectSnapZone, flipFromTarget, flipToTarget, magnetize, prefersReducedMotion, zoneBounds };
2252
- //# sourceMappingURL=chunk-L43XBN44.js.map
2253
- //# sourceMappingURL=chunk-L43XBN44.js.map
2288
+ //# sourceMappingURL=chunk-2WQHHYYR.js.map
2289
+ //# sourceMappingURL=chunk-2WQHHYYR.js.map