forty-cdk 0.43.0 → 0.44.0

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.
@@ -742,8 +742,6 @@ function assertTimeCapable(adapter, piece, options) {
742
742
  });
743
743
  return adapter;
744
744
  }
745
- const AM_TIME = new Date(2e3, 0, 1, 1);
746
- const PM_TIME = new Date(2e3, 0, 1, 13);
747
745
  function resolveHourCycle(locale, override) {
748
746
  if (override !== null) return override;
749
747
  const cycle = new Intl.DateTimeFormat(locale, {
@@ -778,8 +776,8 @@ function dayPeriodNames(locale) {
778
776
  });
779
777
  const read = (date) => fmt.formatToParts(date).find((part) => part.type === "dayPeriod")?.value ?? "";
780
778
  return {
781
- am: read(AM_TIME) || "AM",
782
- pm: read(PM_TIME) || "PM"
779
+ am: read(new Date(2e3, 0, 1, 1)) || "AM",
780
+ pm: read(new Date(2e3, 0, 1, 13)) || "PM"
783
781
  };
784
782
  }
785
783
  function firstDifferingIndex(a, b) {
@@ -1218,15 +1216,19 @@ const DIGITS$1 = {
1218
1216
  second: 2,
1219
1217
  dayPeriod: 0
1220
1218
  };
1221
- const REFERENCE_DATE = new Date(2e3, 1, 1);
1222
- const REFERENCE_DATE_TIME = new Date(2e3, 1, 1, 13, 23, 45);
1219
+ function referenceDate() {
1220
+ return new Date(2e3, 1, 1);
1221
+ }
1222
+ function referenceDateTime() {
1223
+ return new Date(2e3, 1, 1, 13, 23, 45);
1224
+ }
1223
1225
  function buildSegments(locale) {
1224
1226
  const parts = new Intl.DateTimeFormat(locale, {
1225
1227
  calendar: "gregory",
1226
1228
  year: "numeric",
1227
1229
  month: "2-digit",
1228
1230
  day: "2-digit"
1229
- }).formatToParts(REFERENCE_DATE);
1231
+ }).formatToParts(referenceDate());
1230
1232
  const segments = [];
1231
1233
  for (const part of parts) switch (part.type) {
1232
1234
  case "day":
@@ -1257,7 +1259,7 @@ function buildDateTimeSegments(locale, granularity, hourCycle) {
1257
1259
  };
1258
1260
  if (granularity !== "hour") options.minute = "2-digit";
1259
1261
  if (granularity === "second") options.second = "2-digit";
1260
- const parts = new Intl.DateTimeFormat(locale, options).formatToParts(REFERENCE_DATE_TIME);
1262
+ const parts = new Intl.DateTimeFormat(locale, options).formatToParts(referenceDateTime());
1261
1263
  const segments = [];
1262
1264
  for (const part of parts) switch (part.type) {
1263
1265
  case "day":
@@ -1496,21 +1498,66 @@ i0.ɵɵngDeclareClassMetadata({
1496
1498
  }]
1497
1499
  });
1498
1500
  const FOR_PICKER_SOURCE_HOST = new InjectionToken("FOR_PICKER_SOURCE_HOST");
1501
+ var KeyedFlag = class {
1502
+ #slots = /* @__PURE__ */ new WeakMap();
1503
+ #current = null;
1504
+ get current() {
1505
+ return this.#current;
1506
+ }
1507
+ has(key) {
1508
+ return this.#slot(key)();
1509
+ }
1510
+ move(next) {
1511
+ const previous = this.#current;
1512
+ if (previous === next) return;
1513
+ this.#current = next;
1514
+ if (previous !== null) this.#slot(previous).set(false);
1515
+ if (next !== null) this.#slot(next).set(true);
1516
+ }
1517
+ #slot(key) {
1518
+ let slot = this.#slots.get(key);
1519
+ if (slot === void 0) {
1520
+ slot = signal(this.#current === key);
1521
+ this.#slots.set(key, slot);
1522
+ }
1523
+ return slot;
1524
+ }
1525
+ };
1499
1526
  var RovingFocusYield = class {
1500
- #focused = signal(null, ...ngDevMode ? [{ debugName: "#focused" }] : /* istanbul ignore next */ []);
1527
+ #focused = null;
1528
+ #tracksItems = false;
1529
+ #epoch = signal(0, ...ngDevMode ? [{ debugName: "#epoch" }] : /* istanbul ignore next */ []);
1530
+ #items;
1501
1531
  yields;
1502
1532
  constructor(items) {
1533
+ this.#items = items;
1503
1534
  this.yields = computed(() => {
1504
- const focused = this.#focused();
1505
- return focused !== null && items().some((item) => item.host === focused && item.disabled());
1535
+ this.#epoch();
1536
+ if (this.#tracksItems) for (const item of items()) item.disabled();
1537
+ return untracked(() => this.#holdsDisabled());
1506
1538
  }, ...ngDevMode ? [{ debugName: "yields" }] : /* istanbul ignore next */ []);
1507
1539
  }
1508
1540
  noteFocus(el) {
1509
- this.#focused.set(el);
1541
+ untracked(() => {
1542
+ if (this.#focused === el) return;
1543
+ const before = this.yields();
1544
+ this.#focused = el;
1545
+ const subscribes = el !== null && !this.#tracksItems;
1546
+ if (subscribes) this.#tracksItems = true;
1547
+ if (subscribes || this.#holdsDisabled() !== before) this.#epoch.update((epoch) => epoch + 1);
1548
+ });
1549
+ }
1550
+ #holdsDisabled() {
1551
+ const focused = this.#focused;
1552
+ return focused !== null && this.#items().some((item) => item.host === focused && item.disabled());
1510
1553
  }
1511
1554
  };
1512
1555
  var RovingTabindex = class {
1513
1556
  #rawActive = signal(null, ...ngDevMode ? [{ debugName: "#rawActive" }] : /* istanbul ignore next */ []);
1557
+ #raw = new KeyedFlag();
1558
+ #epoch = signal(0, ...ngDevMode ? [{ debugName: "#epoch" }] : /* istanbul ignore next */ []);
1559
+ #tracksItems = false;
1560
+ #settled;
1514
1561
  #keepsDeparted;
1515
1562
  #focusYield;
1516
1563
  #active;
@@ -1538,34 +1585,72 @@ var RovingTabindex = class {
1538
1585
  });
1539
1586
  this.active = this.#active;
1540
1587
  this.#focusYield = items ? new RovingFocusYield(items) : null;
1588
+ this.#settled = computed(() => {
1589
+ this.#epoch();
1590
+ if (items && this.#tracksItems) for (const item of items()) item.disabled();
1591
+ return untracked(() => this.#settle());
1592
+ }, {
1593
+ ...ngDevMode ? { debugName: "#settled" } : /* istanbul ignore next */ {},
1594
+ equal: sameSettled
1595
+ });
1596
+ }
1597
+ isActive(el) {
1598
+ if (this.#raw.has(el)) return this.#active() === el;
1599
+ return this.#settled().promoted === el;
1541
1600
  }
1542
1601
  hasActive() {
1543
1602
  if (this.#focusYield?.yields() === true) return true;
1544
- const el = this.#active();
1603
+ if (!this.#settled().owns) return false;
1604
+ const el = untracked(this.#active);
1545
1605
  return el !== null && !isStale(el);
1546
1606
  }
1607
+ holdsActive() {
1608
+ return this.#settled().present;
1609
+ }
1547
1610
  tabindexFor(el) {
1548
1611
  if (this.#focusYield?.yields() === true) return -1;
1549
- const active = this.#active();
1550
- if (active === null || isStale(active)) return -1;
1551
- return active === el ? 0 : -1;
1612
+ return this.isActive(el) && !isStale(el) ? 0 : -1;
1552
1613
  }
1553
1614
  noteFocus(el) {
1554
1615
  this.#focusYield?.noteFocus(el);
1555
1616
  }
1556
1617
  setActive(el) {
1557
- this.#rawActive.set(el);
1618
+ this.#write(el);
1558
1619
  }
1559
1620
  unregister(el) {
1560
- if (!this.#keepsDeparted && this.#active() === el) this.#rawActive.set(null);
1621
+ if (!this.#keepsDeparted && this.#active() === el) this.#write(null);
1561
1622
  }
1562
1623
  focusActive(el) {
1563
1624
  const target = el ?? this.#active();
1564
1625
  if (!target) return;
1565
- if (target !== this.#active()) this.#rawActive.set(target);
1626
+ if (target !== this.#active()) this.#write(target);
1566
1627
  target.focus();
1567
1628
  }
1629
+ #write(next) {
1630
+ untracked(() => {
1631
+ if (this.#rawActive() === next) return;
1632
+ const before = this.#settled();
1633
+ this.#raw.move(next);
1634
+ this.#rawActive.set(next);
1635
+ const after = this.#settle();
1636
+ const subscribes = next !== null && !this.#tracksItems;
1637
+ if (subscribes) this.#tracksItems = true;
1638
+ if (subscribes || !sameSettled(before, after)) this.#epoch.update((epoch) => epoch + 1);
1639
+ });
1640
+ }
1641
+ #settle() {
1642
+ const raw = this.#rawActive();
1643
+ const active = this.#active();
1644
+ return {
1645
+ present: active !== null,
1646
+ owns: active !== null && !isStale(active),
1647
+ promoted: active === raw ? null : active
1648
+ };
1649
+ }
1568
1650
  };
1651
+ function sameSettled(a, b) {
1652
+ return a.present === b.present && a.owns === b.owns && a.promoted === b.promoted;
1653
+ }
1569
1654
  function nearestUsable(list, order, anchor) {
1570
1655
  const usable = new Set(list.filter((item) => !item.disabled() && item.host.isConnected).map((item) => item.host));
1571
1656
  if (usable.has(anchor)) return anchor;
@@ -1682,7 +1767,7 @@ var ForDateTimeSegmentBase = class ForDateTimeSegmentBase {
1682
1767
  editable = computed(() => !this.ctx.effectiveDisabled() && !this.ctx.readonly(), ...ngDevMode ? [{ debugName: "editable" }] : /* istanbul ignore next */ []);
1683
1768
  inputmode = computed(() => this.editable() && this.segment() !== "dayPeriod" ? "numeric" : null, ...ngDevMode ? [{ debugName: "inputmode" }] : /* istanbul ignore next */ []);
1684
1769
  #restoreContent = null;
1685
- highlighted = computed(() => this.ctx.roving.active() === this.host.nativeElement, ...ngDevMode ? [{ debugName: "highlighted" }] : /* istanbul ignore next */ []);
1770
+ highlighted = computed(() => this.ctx.roving.isActive(this.host.nativeElement), ...ngDevMode ? [{ debugName: "highlighted" }] : /* istanbul ignore next */ []);
1686
1771
  tabindex = computed(() => {
1687
1772
  if (this.ctx.effectiveDisabled()) return -1;
1688
1773
  if (this.ctx.roving.hasActive()) return this.ctx.roving.tabindexFor(this.host.nativeElement);
@@ -1905,7 +1990,9 @@ const DIGITS = {
1905
1990
  second: 2,
1906
1991
  dayPeriod: 0
1907
1992
  };
1908
- const REFERENCE_TIME = new Date(2e3, 0, 1, 13, 23, 45);
1993
+ function referenceTime() {
1994
+ return new Date(2e3, 0, 1, 13, 23, 45);
1995
+ }
1909
1996
  function buildTimeSegments(locale, hourCycle, granularity) {
1910
1997
  const options = {
1911
1998
  calendar: "gregory",
@@ -1914,7 +2001,7 @@ function buildTimeSegments(locale, hourCycle, granularity) {
1914
2001
  };
1915
2002
  if (granularity !== "hour") options.minute = "2-digit";
1916
2003
  if (granularity === "second") options.second = "2-digit";
1917
- const parts = new Intl.DateTimeFormat(locale, options).formatToParts(REFERENCE_TIME);
2004
+ const parts = new Intl.DateTimeFormat(locale, options).formatToParts(referenceTime());
1918
2005
  const segments = [];
1919
2006
  for (const part of parts) switch (part.type) {
1920
2007
  case "hour":
@@ -3220,13 +3307,16 @@ const FOCUSABLE_ATTRIBUTE_CLAUSES = ["[tabindex]:not([tabindex=\"-1\"])", "[cont
3220
3307
  const HIDDEN_ATTRIBUTE = "hidden";
3221
3308
  const INERT_ATTRIBUTE = "inert";
3222
3309
  const OPEN_ATTRIBUTE = "open";
3223
- const FOCUSABLE_SELECTOR = [...Object.entries(FOCUSABLE_LOCAL_NAME_QUALIFIERS).map(([name, qualifier]) => name + qualifier), ...FOCUSABLE_ATTRIBUTE_CLAUSES].join(",");
3224
- const FOCUSABILITY_ATTRIBUTES = [.../* @__PURE__ */ new Set([
3225
- ...[...FOCUSABLE_SELECTOR.matchAll(/\[([\w-]+)/g)].map((match) => match[1]),
3226
- HIDDEN_ATTRIBUTE,
3227
- INERT_ATTRIBUTE,
3228
- OPEN_ATTRIBUTE
3229
- ])];
3310
+ const FOCUSABLE_SELECTOR = /* @__PURE__ */ [...Object.entries(FOCUSABLE_LOCAL_NAME_QUALIFIERS).map(([name, qualifier]) => name + qualifier), ...FOCUSABLE_ATTRIBUTE_CLAUSES].join(",");
3311
+ function focusabilityAttributes(selector) {
3312
+ return [.../* @__PURE__ */ new Set([
3313
+ ...[...selector.matchAll(/\[([\w-]+)/g)].map((match) => match[1]),
3314
+ HIDDEN_ATTRIBUTE,
3315
+ INERT_ATTRIBUTE,
3316
+ OPEN_ATTRIBUTE
3317
+ ])];
3318
+ }
3319
+ const FOCUSABILITY_ATTRIBUTES = /* @__PURE__ */ focusabilityAttributes(FOCUSABLE_SELECTOR);
3230
3320
  function queryFocusableCandidates(container) {
3231
3321
  const found = [];
3232
3322
  if (container.shadowRoot) collectFocusableCandidates(container.shadowRoot, found);
@@ -3313,7 +3403,7 @@ function indexOfInnermostContaining(candidates, from) {
3313
3403
  for (let i = candidates.length - 1; i >= 0; i--) if (composedContains(candidates[i], from)) return i;
3314
3404
  return -1;
3315
3405
  }
3316
- const FOCUSABLE_LOCAL_NAMES = new Set(Object.keys(FOCUSABLE_LOCAL_NAME_QUALIFIERS));
3406
+ const FOCUSABLE_LOCAL_NAMES = /* @__PURE__ */ new Set(/* @__PURE__ */ Object.keys(FOCUSABLE_LOCAL_NAME_QUALIFIERS));
3317
3407
  function mayMatchFocusableSelector(el) {
3318
3408
  if (FOCUSABLE_LOCAL_NAMES.has(el.localName)) return true;
3319
3409
  const tabindex = el.getAttribute("tabindex");
@@ -4803,13 +4893,37 @@ function injectPointerMove(handler) {
4803
4893
  function createPointerHighlight(config) {
4804
4894
  const suppression = createPointerSuppression();
4805
4895
  const host = signal(null, ...ngDevMode ? [{ debugName: "host" }] : /* istanbul ignore next */ []);
4896
+ const pointed = computed(() => {
4897
+ const current = host();
4898
+ if (current === null) return null;
4899
+ const item = config.items().find((candidate) => candidate.host === current);
4900
+ return item && !item.disabled() ? current : null;
4901
+ }, ...ngDevMode ? [{ debugName: "pointed" }] : /* istanbul ignore next */ []);
4902
+ const flag = new KeyedFlag();
4903
+ const epoch = signal(0, ...ngDevMode ? [{ debugName: "epoch" }] : /* istanbul ignore next */ []);
4904
+ let tracksItems = false;
4905
+ const hasPointed = computed(() => {
4906
+ epoch();
4907
+ if (tracksItems) for (const item of config.items()) item.disabled();
4908
+ return untracked(pointed) !== null;
4909
+ }, ...ngDevMode ? [{ debugName: "hasPointed" }] : /* istanbul ignore next */ []);
4910
+ const point = (next) => {
4911
+ untracked(() => {
4912
+ if (host() === next) return;
4913
+ const before = hasPointed();
4914
+ flag.move(next);
4915
+ host.set(next);
4916
+ const subscribes = next !== null && !tracksItems;
4917
+ if (subscribes) tracksItems = true;
4918
+ if (subscribes || pointed() !== null !== before) epoch.update((value) => value + 1);
4919
+ });
4920
+ };
4806
4921
  return {
4807
- pointed: computed(() => {
4808
- const current = host();
4809
- if (current === null) return null;
4810
- const item = config.items().find((candidate) => candidate.host === current);
4811
- return item && !item.disabled() ? current : null;
4812
- }, ...ngDevMode ? [{ debugName: "pointed" }] : /* istanbul ignore next */ []),
4922
+ pointed,
4923
+ hasPointed,
4924
+ isPointed(target) {
4925
+ return flag.has(target) && hasPointed();
4926
+ },
4813
4927
  claim(target, id = target.id) {
4814
4928
  if (suppression.isSuppressed()) return;
4815
4929
  const activeDescendant = config.activeDescendant;
@@ -4817,10 +4931,10 @@ function createPointerHighlight(config) {
4817
4931
  activeDescendant.claim(id);
4818
4932
  return;
4819
4933
  }
4820
- host.set(target);
4934
+ point(target);
4821
4935
  },
4822
4936
  release() {
4823
- host.set(null);
4937
+ point(null);
4824
4938
  },
4825
4939
  suppress() {
4826
4940
  suppression.suppress();