@surdeddd/wmkit 0.6.1 → 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.
Files changed (41) hide show
  1. package/README.md +1 -1
  2. package/README.ru.md +1 -1
  3. package/dist/angular.cjs +3 -3
  4. package/dist/angular.d.cts +2 -2
  5. package/dist/angular.d.ts +2 -2
  6. package/dist/angular.js +1 -1
  7. package/dist/{binder-CkmOoo1U.d.ts → binder-DvQFmO3K.d.ts} +1 -1
  8. package/dist/{binder-CQzQJdVj.d.cts → binder-_L3Iww0u.d.cts} +1 -1
  9. package/dist/{chunk-DYZQY3BE.cjs → chunk-2VRCYMKH.cjs} +70 -24
  10. package/dist/chunk-2VRCYMKH.cjs.map +1 -0
  11. package/dist/{chunk-3HLKVOSI.js → chunk-WOCAQEM6.js} +70 -24
  12. package/dist/chunk-WOCAQEM6.js.map +1 -0
  13. package/dist/index.cjs +18 -18
  14. package/dist/index.d.cts +4 -4
  15. package/dist/index.d.ts +4 -4
  16. package/dist/index.js +1 -1
  17. package/dist/persist.d.cts +1 -1
  18. package/dist/persist.d.ts +1 -1
  19. package/dist/popout.d.cts +1 -1
  20. package/dist/popout.d.ts +1 -1
  21. package/dist/react.cjs +3 -3
  22. package/dist/react.d.cts +2 -2
  23. package/dist/react.d.ts +2 -2
  24. package/dist/react.js +1 -1
  25. package/dist/solid.cjs +3 -3
  26. package/dist/solid.d.cts +2 -2
  27. package/dist/solid.d.ts +2 -2
  28. package/dist/solid.js +1 -1
  29. package/dist/svelte.cjs +3 -3
  30. package/dist/svelte.d.cts +2 -2
  31. package/dist/svelte.d.ts +2 -2
  32. package/dist/svelte.js +1 -1
  33. package/dist/{types-LP7Inhxx.d.cts → types-jG2lHGcA.d.cts} +2 -0
  34. package/dist/{types-LP7Inhxx.d.ts → types-jG2lHGcA.d.ts} +2 -0
  35. package/dist/vue.cjs +3 -3
  36. package/dist/vue.d.cts +2 -2
  37. package/dist/vue.d.ts +2 -2
  38. package/dist/vue.js +1 -1
  39. package/package.json +1 -1
  40. package/dist/chunk-3HLKVOSI.js.map +0 -1
  41. package/dist/chunk-DYZQY3BE.cjs.map +0 -1
@@ -283,8 +283,7 @@ function createWindowManager(options = {}) {
283
283
  }
284
284
  function blockOf(id) {
285
285
  const win = windows[id];
286
- if (win.groupId === null) return [id];
287
- return [...membersOf(win.groupId).filter((entry) => entry !== id), id];
286
+ return win.groupId === null ? [id] : membersOf(win.groupId);
288
287
  }
289
288
  function raise(id) {
290
289
  const win = windows[id];
@@ -893,6 +892,37 @@ function createWindowManager(options = {}) {
893
892
  commit();
894
893
  return true;
895
894
  }
895
+ function moveTab(id, index) {
896
+ const win = windows[id];
897
+ if (!win?.groupId || !Number.isFinite(index)) return false;
898
+ const members = membersOf(win.groupId);
899
+ const from = members.indexOf(id);
900
+ const target = Math.max(0, Math.min(members.length - 1, Math.trunc(index)));
901
+ if (from === -1 || from === target) return false;
902
+ const reordered = [...members];
903
+ reordered.splice(from, 1);
904
+ reordered.splice(target, 0, id);
905
+ const next = [...order];
906
+ let cursor = 0;
907
+ for (let i = 0; i < next.length; i += 1) {
908
+ if (!members.includes(next[i])) continue;
909
+ next[i] = reordered[cursor++];
910
+ }
911
+ order = next;
912
+ emitGroup(win.groupId, null);
913
+ queueEvent(() => emitter.emit("order", { order }));
914
+ commit();
915
+ return true;
916
+ }
917
+ function cycleTab(direction = 1) {
918
+ const win = focusedId ? windows[focusedId] : void 0;
919
+ if (!win?.groupId) return null;
920
+ const members = membersOf(win.groupId);
921
+ const current = members.indexOf(activeTabs[win.groupId]);
922
+ const index = (current + direction + members.length) % members.length;
923
+ const next = members[index];
924
+ return activateTab(next) ? next : null;
925
+ }
896
926
  function groupMembers(groupId) {
897
927
  return membersOf(groupId).map((id) => windows[id]);
898
928
  }
@@ -995,6 +1025,7 @@ function createWindowManager(options = {}) {
995
1025
  }
996
1026
  }
997
1027
  function applyEntry(entry) {
1028
+ const previousWindows = windows;
998
1029
  windows = entry.windows;
999
1030
  order = [...entry.order];
1000
1031
  modalCount = countModals();
@@ -1006,6 +1037,16 @@ function createWindowManager(options = {}) {
1006
1037
  if (workspace !== previousWorkspace) {
1007
1038
  queueEvent(() => emitter.emit("workspace", { workspace, previous: previousWorkspace }));
1008
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
+ }
1009
1050
  reflowViewport();
1010
1051
  commit();
1011
1052
  }
@@ -1301,6 +1342,8 @@ function createWindowManager(options = {}) {
1301
1342
  group: (ids) => transact(() => group(ids)),
1302
1343
  ungroup: (id) => transact(() => ungroup(id)),
1303
1344
  activateTab: (id) => transact(() => activateTab(id)),
1345
+ moveTab: (id, index) => transact(() => moveTab(id, index)),
1346
+ cycleTab: (direction) => transact(() => cycleTab(direction)),
1304
1347
  groupMembers,
1305
1348
  batch: (run) => transact(run),
1306
1349
  serialize,
@@ -1954,7 +1997,7 @@ function attachDesktop(wm, element, options = {}) {
1954
1997
  const registry = /* @__PURE__ */ new Map();
1955
1998
  const cleanup = [];
1956
1999
  let lastOrder = null;
1957
- let lastFocused = null;
2000
+ let focusedEl = null;
1958
2001
  let drag = null;
1959
2002
  let groupTargetId = null;
1960
2003
  let groupTargetEl = null;
@@ -2141,16 +2184,11 @@ function attachDesktop(wm, element, options = {}) {
2141
2184
  }
2142
2185
  }
2143
2186
  if (orderChanged) applyStacking(state.order);
2144
- if (state.focusedId !== lastFocused) {
2145
- if (lastFocused) {
2146
- const prev = registry.get(lastFocused);
2147
- if (prev) delete prev.element.dataset.wmFocused;
2148
- }
2149
- if (state.focusedId) {
2150
- const next = registry.get(state.focusedId);
2151
- if (next) next.element.dataset.wmFocused = "";
2152
- }
2153
- 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 = "";
2154
2192
  }
2155
2193
  lastOrder = state.order;
2156
2194
  }
@@ -2380,23 +2418,31 @@ function attachDesktop(wm, element, options = {}) {
2380
2418
  };
2381
2419
  windowElement.addEventListener("keydown", onModalTrap);
2382
2420
  attached.cleanup.push(() => windowElement.removeEventListener("keydown", onModalTrap));
2421
+ let detached = false;
2383
2422
  const detach = () => {
2423
+ if (detached) return;
2424
+ detached = true;
2384
2425
  if (drag?.id === id) endDrag(true);
2385
2426
  for (const dispose of attached.cleanup) dispose();
2386
2427
  for (const resizeHandle of attached.handles) resizeHandle.remove();
2387
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
+ }
2388
2437
  };
2389
- if (windowOptions.removeOnClose) {
2390
- const stopOnClose = wm.on("close", ({ window: closed }) => {
2391
- if (closed.id !== id) return;
2392
- detach();
2393
- windowElement.remove();
2394
- });
2395
- attached.cleanup.push(stopOnClose);
2396
- }
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);
2397
2444
  registry.set(id, attached);
2398
2445
  lastOrder = null;
2399
- lastFocused = null;
2400
2446
  syncAll();
2401
2447
  if (wm.getState().focusedId === id && !windowElement.contains(doc.activeElement)) {
2402
2448
  windowElement.focus({ preventScroll: true });
@@ -2470,5 +2516,5 @@ function createDesktopBinder(wm, options = {}) {
2470
2516
  }
2471
2517
 
2472
2518
  export { applyAspect, attachDesktop, boundsEqual, clamp, clampSize, clampToViewport, createAnnouncer, createDesktopBinder, createEmitter, createWindowManager, defaultMessages, detectSnapZone, flipFromTarget, flipToTarget, magnetize, prefersReducedMotion, zoneBounds };
2473
- //# sourceMappingURL=chunk-3HLKVOSI.js.map
2474
- //# sourceMappingURL=chunk-3HLKVOSI.js.map
2519
+ //# sourceMappingURL=chunk-WOCAQEM6.js.map
2520
+ //# sourceMappingURL=chunk-WOCAQEM6.js.map