forty-cdk 0.45.0 → 0.45.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.
@@ -29,6 +29,7 @@ function afterNextRenderCancellable(fn) {
29
29
  ref.destroy();
30
30
  });
31
31
  }
32
+ const MIN_HANDLES_FOR_SIBLING_WALK = 16;
32
33
  function sameSequence(a, b) {
33
34
  if (a === b) return true;
34
35
  if (a.length !== b.length) return false;
@@ -95,6 +96,28 @@ var Collection = class {
95
96
  }
96
97
  #sortByDomOrder(handles) {
97
98
  if (handles.length < 2) return handles;
99
+ return this.#sortBySiblingRank(handles) ?? this.#sortByComparison(handles);
100
+ }
101
+ #sortBySiblingRank(handles) {
102
+ if (handles.length < MIN_HANDLES_FOR_SIBLING_WALK) return null;
103
+ let parent = null;
104
+ const pending = /* @__PURE__ */ new Set();
105
+ for (const handle of handles) {
106
+ const host = handle.host;
107
+ if (!host.isConnected) continue;
108
+ const hostParent = host.parentNode;
109
+ if (hostParent === null || parent !== null && hostParent !== parent) return null;
110
+ parent = hostParent;
111
+ pending.add(host);
112
+ }
113
+ if (parent === null) return null;
114
+ const rank = /* @__PURE__ */ new Map();
115
+ for (let node = parent.firstChild; node !== null && pending.size > 0; node = node.nextSibling) if (pending.delete(node)) rank.set(node, rank.size);
116
+ if (pending.size > 0) return null;
117
+ const detachedRank = rank.size;
118
+ return handles.sort((a, b) => (rank.get(a.host) ?? detachedRank) - (rank.get(b.host) ?? detachedRank));
119
+ }
120
+ #sortByComparison(handles) {
98
121
  const position = new Map(handles.map((h, i) => [h, i]));
99
122
  const indexOrder = (a, b) => position.get(a) - position.get(b);
100
123
  return handles.sort((a, b) => {
@@ -571,9 +594,8 @@ function hostId(prefix) {
571
594
  const host = inject(ElementRef).nativeElement;
572
595
  return signal(resolveHostId(host, prefix)).asReadonly();
573
596
  }
574
- function registerHandle(target, register, unregister, scheduling = "sync") {
575
- if (scheduling === "afterNextRender") afterNextRender(() => register(target));
576
- else register(target);
597
+ function registerHandle(target, register, unregister) {
598
+ register(target);
577
599
  inject(DestroyRef).onDestroy(() => unregister(target));
578
600
  }
579
601
  function registerA11yName(owner, prefix) {
@@ -1774,10 +1796,12 @@ var ForDateTimeSegmentBase = class ForDateTimeSegmentBase {
1774
1796
  return this.ctx.delegate.isFirstSegmentType(this.segment()) ? 0 : -1;
1775
1797
  }, ...ngDevMode ? [{ debugName: "tabindex" }] : /* istanbul ignore next */ []);
1776
1798
  registerSegment() {
1777
- registerHandle({
1799
+ const handle = {
1778
1800
  host: this.host.nativeElement,
1779
1801
  type: this.segment
1780
- }, (h) => this.ctx.delegate.registerSegment(h), (h) => this.ctx.delegate.unregisterSegment(h), "afterNextRender");
1802
+ };
1803
+ afterNextRender(() => this.ctx.delegate.registerSegment(handle));
1804
+ inject(DestroyRef).onDestroy(() => this.ctx.delegate.unregisterSegment(handle));
1781
1805
  }
1782
1806
  onFocus() {
1783
1807
  this.ctx.delegate.focusSegment(this.segment());
@@ -4914,12 +4938,12 @@ function injectPointerMove(handler) {
4914
4938
  const host = inject(ElementRef).nativeElement;
4915
4939
  const moves = inject(StationaryPointerMoves);
4916
4940
  const release = moves.acquire();
4917
- const controller = new AbortController();
4918
- host.addEventListener("pointermove", (event) => {
4941
+ const listener = (event) => {
4919
4942
  if (!moves.isStationary(event)) handler(event);
4920
- }, { signal: controller.signal });
4943
+ };
4944
+ host.addEventListener("pointermove", listener);
4921
4945
  inject(DestroyRef).onDestroy(() => {
4922
- controller.abort();
4946
+ host.removeEventListener("pointermove", listener);
4923
4947
  release();
4924
4948
  });
4925
4949
  }