forty-cdk 0.44.0 → 0.45.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.
@@ -1,6 +1,6 @@
1
1
  import * as i0 from "@angular/core";
2
2
  import { Directive, ElementRef, InjectionToken, booleanAttribute, computed, inject, input, model, signal } from "@angular/core";
3
- import { IdGenerator, adoptHostId, hostButtonType, orphanContextError, reflectDisabled } from "forty-cdk/core";
3
+ import { HIDDEN_UNTIL_FOUND, IdGenerator, adoptHostId, assertRootContext, hostButtonType, keepHiddenUntilFound, orphanContextError, reflectDisabled, registerHandle } from "forty-cdk/core";
4
4
  const FOR_DISCLOSURE_CONTEXT = new InjectionToken("FOR_DISCLOSURE_CONTEXT");
5
5
  function injectDisclosureContext(piece) {
6
6
  const ctx = inject(FOR_DISCLOSURE_CONTEXT, { optional: true });
@@ -10,6 +10,13 @@ function injectDisclosureContext(piece) {
10
10
  root: "[forDisclosure]",
11
11
  token: "FOR_DISCLOSURE_CONTEXT"
12
12
  });
13
+ assertRootContext({
14
+ entryPoint: "disclosure",
15
+ token: "FOR_DISCLOSURE_CONTEXT",
16
+ root: "[forDisclosure]",
17
+ piece,
18
+ probe: () => ctx.registerContent
19
+ });
13
20
  return ctx;
14
21
  }
15
22
  var ForDisclosure = class ForDisclosure {
@@ -23,6 +30,7 @@ var ForDisclosure = class ForDisclosure {
23
30
  #contentId = signal(this.#idGen.next("for-disclosure-content"), ...ngDevMode ? [{ debugName: "#contentId" }] : /* istanbul ignore next */ []);
24
31
  triggerId = this.#triggerId.asReadonly();
25
32
  contentId = this.#contentId.asReadonly();
33
+ #contents = signal([], ...ngDevMode ? [{ debugName: "#contents" }] : /* istanbul ignore next */ []);
26
34
  adoptTriggerId(el) {
27
35
  adoptHostId(el, this.#triggerId);
28
36
  }
@@ -33,6 +41,18 @@ var ForDisclosure = class ForDisclosure {
33
41
  if (this.disabled()) return;
34
42
  this.open.set(!this.open());
35
43
  }
44
+ registerContent(el) {
45
+ this.#contents.update((contents) => [...contents, el]);
46
+ }
47
+ unregisterContent(el) {
48
+ this.#contents.update((contents) => {
49
+ const index = contents.lastIndexOf(el);
50
+ return index < 0 ? contents : [...contents.slice(0, index), ...contents.slice(index + 1)];
51
+ });
52
+ }
53
+ hasContent() {
54
+ return this.#contents().length > 0;
55
+ }
36
56
  static ɵfac = i0.ɵɵngDeclareFactory({
37
57
  minVersion: "12.0.0",
38
58
  version: "22.2.4",
@@ -161,7 +181,7 @@ var ForDisclosureTrigger = class ForDisclosureTrigger {
161
181
  "attr.type": "buttonType()",
162
182
  "id": "ctx.triggerId()",
163
183
  "attr.aria-expanded": "ctx.open() ? \"true\" : \"false\"",
164
- "attr.aria-controls": "ctx.open() ? ctx.contentId() : null",
184
+ "attr.aria-controls": "ctx.open() || ctx.hasContent() ? ctx.contentId() : null",
165
185
  "attr.data-state": "ctx.open() ? \"open\" : \"closed\"",
166
186
  "attr.data-disabled": "effectiveDisabled() ? \"\" : null"
167
187
  }
@@ -184,7 +204,7 @@ i0.ɵɵngDeclareClassMetadata({
184
204
  "[attr.type]": "buttonType()",
185
205
  "[id]": "ctx.triggerId()",
186
206
  "[attr.aria-expanded]": "ctx.open() ? \"true\" : \"false\"",
187
- "[attr.aria-controls]": "ctx.open() ? ctx.contentId() : null",
207
+ "[attr.aria-controls]": "ctx.open() || ctx.hasContent() ? ctx.contentId() : null",
188
208
  "[attr.data-state]": "ctx.open() ? \"open\" : \"closed\"",
189
209
  "[attr.data-disabled]": "effectiveDisabled() ? \"\" : null",
190
210
  "(click)": "onClick()"
@@ -203,8 +223,21 @@ i0.ɵɵngDeclareClassMetadata({
203
223
  });
204
224
  var ForDisclosureContent = class ForDisclosureContent {
205
225
  ctx = injectDisclosureContext("ForDisclosureContent");
226
+ #host = inject(ElementRef).nativeElement;
227
+ hiddenUntilFound = input(false, {
228
+ ...ngDevMode ? { debugName: "hiddenUntilFound" } : /* istanbul ignore next */ {},
229
+ transform: booleanAttribute
230
+ });
231
+ hiddenValue = HIDDEN_UNTIL_FOUND;
232
+ untilFound = computed(() => this.hiddenUntilFound() && !this.ctx.open(), ...ngDevMode ? [{ debugName: "untilFound" }] : /* istanbul ignore next */ []);
206
233
  constructor() {
207
- this.ctx.adoptContentId(inject(ElementRef).nativeElement);
234
+ this.ctx.adoptContentId(this.#host);
235
+ registerHandle(this.#host, (el) => this.ctx.registerContent(el), (el) => this.ctx.unregisterContent(el));
236
+ }
237
+ onBeforeMatch() {
238
+ if (!this.untilFound()) return;
239
+ this.ctx.toggle();
240
+ if (this.untilFound()) keepHiddenUntilFound(this.#host, () => this.untilFound());
208
241
  }
209
242
  static ɵfac = i0.ɵɵngDeclareFactory({
210
243
  minVersion: "12.0.0",
@@ -215,18 +248,29 @@ var ForDisclosureContent = class ForDisclosureContent {
215
248
  target: i0.ɵɵFactoryTarget.Directive
216
249
  });
217
250
  static ɵdir = i0.ɵɵngDeclareDirective({
218
- minVersion: "14.0.0",
251
+ minVersion: "17.1.0",
219
252
  version: "22.2.4",
220
253
  type: ForDisclosureContent,
221
254
  isStandalone: true,
222
255
  selector: "[forDisclosureContent]",
223
- host: { properties: {
224
- "id": "ctx.contentId()",
225
- "attr.aria-hidden": "ctx.open() ? null : \"true\"",
226
- "attr.inert": "ctx.open() ? null : \"\"",
227
- "attr.data-state": "ctx.open() ? \"open\" : \"closed\"",
228
- "attr.data-disabled": "ctx.disabled() ? \"\" : null"
256
+ inputs: { hiddenUntilFound: {
257
+ classPropertyName: "hiddenUntilFound",
258
+ publicName: "hiddenUntilFound",
259
+ isSignal: true,
260
+ isRequired: false,
261
+ transformFunction: null
229
262
  } },
263
+ host: {
264
+ listeners: { "beforematch": "onBeforeMatch()" },
265
+ properties: {
266
+ "id": "ctx.contentId()",
267
+ "attr.hidden": "untilFound() ? hiddenValue : null",
268
+ "attr.aria-hidden": "ctx.open() || hiddenUntilFound() ? null : \"true\"",
269
+ "attr.inert": "ctx.open() || hiddenUntilFound() ? null : \"\"",
270
+ "attr.data-state": "ctx.open() ? \"open\" : \"closed\"",
271
+ "attr.data-disabled": "ctx.disabled() ? \"\" : null"
272
+ }
273
+ },
230
274
  exportAs: ["forDisclosureContent"],
231
275
  ngImport: i0
232
276
  });
@@ -243,14 +287,24 @@ i0.ɵɵngDeclareClassMetadata({
243
287
  exportAs: "forDisclosureContent",
244
288
  host: {
245
289
  "[id]": "ctx.contentId()",
246
- "[attr.aria-hidden]": "ctx.open() ? null : \"true\"",
247
- "[attr.inert]": "ctx.open() ? null : \"\"",
290
+ "[attr.hidden]": "untilFound() ? hiddenValue : null",
291
+ "[attr.aria-hidden]": "ctx.open() || hiddenUntilFound() ? null : \"true\"",
292
+ "[attr.inert]": "ctx.open() || hiddenUntilFound() ? null : \"\"",
248
293
  "[attr.data-state]": "ctx.open() ? \"open\" : \"closed\"",
249
- "[attr.data-disabled]": "ctx.disabled() ? \"\" : null"
294
+ "[attr.data-disabled]": "ctx.disabled() ? \"\" : null",
295
+ "(beforematch)": "onBeforeMatch()"
250
296
  }
251
297
  }]
252
298
  }],
253
- ctorParameters: () => []
299
+ ctorParameters: () => [],
300
+ propDecorators: { hiddenUntilFound: [{
301
+ type: i0.Input,
302
+ args: [{
303
+ isSignal: true,
304
+ alias: "hiddenUntilFound",
305
+ required: false
306
+ }]
307
+ }] }
254
308
  });
255
309
  export { FOR_DISCLOSURE_CONTEXT, ForDisclosure, ForDisclosureContent, ForDisclosureTrigger };
256
310
 
@@ -1 +1 @@
1
- {"version":3,"file":"forty-cdk-disclosure.mjs","names":[],"sources":["../../../projects/forty-cdk/disclosure/src/disclosure-context.ts","../../../projects/forty-cdk/disclosure/src/disclosure.ts","../../../projects/forty-cdk/disclosure/src/disclosure-trigger.ts","../../../projects/forty-cdk/disclosure/src/disclosure-content.ts"],"sourcesContent":["import { inject, InjectionToken, type Signal } from '@angular/core';\n\nimport { orphanContextError } from 'forty-cdk/core';\n\n/**\n * Shared state contract between the pieces of a Disclosure primitive.\n * Provided by `ForDisclosure`, consumed by `ForDisclosureTrigger` and\n * `ForDisclosureContent`.\n */\nexport interface ForDisclosureContext {\n readonly open: Signal<boolean>;\n readonly disabled: Signal<boolean>;\n readonly triggerId: Signal<string>;\n readonly contentId: Signal<string>;\n /** Adopts a consumer-set static `id` on the trigger host into `triggerId`. */\n adoptTriggerId(el: HTMLElement): void;\n /** Adopts a consumer-set static `id` on the content host into `contentId`. */\n adoptContentId(el: HTMLElement): void;\n toggle(): void;\n}\n\nexport const FOR_DISCLOSURE_CONTEXT = new InjectionToken<ForDisclosureContext>(\n 'FOR_DISCLOSURE_CONTEXT',\n);\n\n/**\n * Injects the disclosure context or throws a prefixed, actionable error\n * naming the piece that was used outside `[forDisclosure]`.\n */\nexport function injectDisclosureContext(piece: string): ForDisclosureContext {\n const ctx = inject(FOR_DISCLOSURE_CONTEXT, { optional: true });\n if (!ctx) {\n throw orphanContextError({\n code: 'FORCDK-DISCLOSURE-001',\n piece,\n root: '[forDisclosure]',\n token: 'FOR_DISCLOSURE_CONTEXT',\n });\n }\n return ctx;\n}\n","import { booleanAttribute, Directive, inject, input, model, signal } from '@angular/core';\n\nimport { adoptHostId, IdGenerator } from 'forty-cdk/core';\nimport { FOR_DISCLOSURE_CONTEXT, type ForDisclosureContext } from './disclosure-context';\n\n/**\n * Root of the Disclosure primitive. Holds the open/disabled state and\n * the IDs that wire the trigger to its content.\n *\n * Implements the [WAI-ARIA Disclosure pattern](https://www.w3.org/WAI/ARIA/apg/patterns/disclosure/).\n *\n * Compose it on any wrapper element with `[forDisclosureTrigger]` and\n * `[forDisclosureContent]` as descendants.\n *\n * @example\n * ```html\n * <div forDisclosure [(open)]=\"isOpen\">\n * <button type=\"button\" forDisclosureTrigger>Toggle</button>\n * <div forDisclosureContent>...</div>\n * </div>\n * ```\n */\n@Directive({\n selector: '[forDisclosure]',\n exportAs: 'forDisclosure',\n host: {\n '[attr.data-state]': 'open() ? \"open\" : \"closed\"',\n '[attr.data-disabled]': 'disabled() ? \"\" : null',\n },\n providers: [{ provide: FOR_DISCLOSURE_CONTEXT, useExisting: ForDisclosure }],\n})\nexport class ForDisclosure implements ForDisclosureContext {\n readonly #idGen = inject(IdGenerator);\n\n /**\n * Two-way bindable open state. Use `[(open)]` for both read & write, or\n * `(openChange)` alone to observe transitions when the directive itself\n * toggles state (trigger click). The `model()` change emitter does NOT fire\n * for consumer-driven writes via `[(open)]`, so subscribing to\n * `(openChange)` is safe and only sees internal transitions.\n */\n readonly open = model<boolean>(false);\n\n /** When true, click on the trigger is ignored and `data-disabled` is reflected. */\n readonly disabled = input(false, { transform: booleanAttribute });\n\n readonly #triggerId = signal(this.#idGen.next('for-disclosure-trigger'));\n readonly #contentId = signal(this.#idGen.next('for-disclosure-content'));\n\n readonly triggerId = this.#triggerId.asReadonly();\n readonly contentId = this.#contentId.asReadonly();\n\n /**\n * Adopts a consumer-set static `id` on the `[forDisclosureTrigger]` host into\n * `triggerId` (preserving anchors / external `aria-labelledby` references /\n * label `for`) instead of letting the `[id]` host binding clobber it.\n */\n adoptTriggerId(el: HTMLElement): void {\n adoptHostId(el, this.#triggerId);\n }\n\n /** Adopts a consumer-set static `id` on the content host into `contentId`. */\n adoptContentId(el: HTMLElement): void {\n adoptHostId(el, this.#contentId);\n }\n\n toggle(): void {\n if (this.disabled()) {\n return;\n }\n this.open.set(!this.open());\n }\n}\n","import { booleanAttribute, computed, Directive, ElementRef, inject, input } from '@angular/core';\n\nimport { hostButtonType, reflectDisabled } from 'forty-cdk/core';\nimport { injectDisclosureContext } from './disclosure-context';\n\n/**\n * Trigger button for a `ForDisclosure`. Apply on a `<button>` so Enter/Space\n * toggling come from native button behavior. The directive host-binds\n * `type=\"button\"` so a trigger inside a `<form>` never submits it on toggle.\n *\n * `aria-controls` is emitted only while open — mirroring the overlay triggers'\n * open-only gating — so the reference never dangles at an unmounted panel\n * under the recommended `@if (open())` mount pattern.\n *\n * Disabling: the trigger merges its own `disabled` input OR the root's\n * `disabled` into `effectiveDisabled`, which drives the native `disabled`\n * attribute, `data-disabled`, and the click guard. The native attribute is the\n * single reflection channel — no `aria-disabled` is emitted, because on a real\n * single-purpose `<button>` trigger the native attribute already conveys the\n * state to assistive technology.\n */\n@Directive({\n selector: '[forDisclosureTrigger]',\n exportAs: 'forDisclosureTrigger',\n host: {\n '[attr.type]': 'buttonType()',\n '[id]': 'ctx.triggerId()',\n '[attr.aria-expanded]': 'ctx.open() ? \"true\" : \"false\"',\n '[attr.aria-controls]': 'ctx.open() ? ctx.contentId() : null',\n '[attr.data-state]': 'ctx.open() ? \"open\" : \"closed\"',\n '[attr.data-disabled]': 'effectiveDisabled() ? \"\" : null',\n '(click)': 'onClick()',\n },\n})\nexport class ForDisclosureTrigger {\n private readonly buttonType = hostButtonType();\n\n private readonly ctx = injectDisclosureContext('ForDisclosureTrigger');\n\n /** Disables this trigger only, in addition to the root's `disabled`. */\n readonly disabled = input(false, { transform: booleanAttribute });\n\n /** Whether the trigger is disabled — its own `disabled` input OR the root's. */\n readonly effectiveDisabled = computed(() => this.disabled() || this.ctx.disabled());\n\n constructor() {\n this.ctx.adoptTriggerId(inject<ElementRef<HTMLElement>>(ElementRef).nativeElement);\n reflectDisabled(this.effectiveDisabled);\n }\n\n private onClick(): void {\n if (this.effectiveDisabled()) {\n return;\n }\n this.ctx.toggle();\n }\n}\n","import { Directive, ElementRef, inject } from '@angular/core';\n\nimport { injectDisclosureContext } from './disclosure-context';\n\n/**\n * Disclosed content panel for a `ForDisclosure`. The directive does not\n * manage DOM presence — wrap with `@if (open())` so the panel mounts and\n * unmounts with the disclosure state, and use `animate.enter` /\n * `animate.leave` for transitions if desired. If the consumer prefers to\n * keep the panel mounted (for CSS-only transitions or to preserve internal\n * state), the directive reflects `aria-hidden=\"true\"` and `inert` while\n * closed so the panel is removed from the accessibility tree and focus\n * order automatically.\n */\n@Directive({\n selector: '[forDisclosureContent]',\n exportAs: 'forDisclosureContent',\n host: {\n '[id]': 'ctx.contentId()',\n '[attr.aria-hidden]': 'ctx.open() ? null : \"true\"',\n '[attr.inert]': 'ctx.open() ? null : \"\"',\n '[attr.data-state]': 'ctx.open() ? \"open\" : \"closed\"',\n '[attr.data-disabled]': 'ctx.disabled() ? \"\" : null',\n },\n})\nexport class ForDisclosureContent {\n private readonly ctx = injectDisclosureContext('ForDisclosureContent');\n\n constructor() {\n this.ctx.adoptContentId(inject<ElementRef<HTMLElement>>(ElementRef).nativeElement);\n }\n}\n"],"mappings":";;;AAqBA,MAAa,yBAAyB,IAAI,eACxC,wBAAwB;AAO1B,SAAgB,wBAAwB,OAAa;CACnD,MAAM,MAAM,OAAO,wBAAwB,EAAE,UAAU,KAAI,CAAE;CAC7D,IAAI,CAAC,KACH,MAAM,mBAAmB;EACvB,MAAM;EACN;EACA,MAAM;EACN,OAAO;CACR,CAAA;CAEH,OAAO;AACT;ACTA,IAAa,gBAAb,MAAa,cAAa;CACf,SAAS,OAAO,WAAW;CAS3B,OAAO,MAAe,OAAM,GAAA,YAAA,CAAA,EAAA,WAAA,OAAA,CAAA,+BAAA,CAAA,CAAA;CAG5B,WAAW,MAAM,OAAK;EAAA,GAAA,YAAA,EAAA,WAAA,WAAA,+BAAA,CAAA;EAAI,WAAW;CAAgB,CAAA;CAErD,aAAa,OAAO,KAAK,OAAO,KAAK,wBAAwB,GAAE,GAAA,YAAA,CAAA,EAAA,WAAA,aAAA,CAAA,+BAAA,CAAA,CAAA;CAC/D,aAAa,OAAO,KAAK,OAAO,KAAK,wBAAwB,GAAE,GAAA,YAAA,CAAA,EAAA,WAAA,aAAA,CAAA,+BAAA,CAAA,CAAA;CAE/D,YAAY,KAAK,WAAW,WAAU;CACtC,YAAY,KAAK,WAAW,WAAU;CAO/C,eAAe,IAAe;EAC5B,YAAY,IAAI,KAAK,UAAU;CACjC;CAGA,eAAe,IAAe;EAC5B,YAAY,IAAI,KAAK,UAAU;CACjC;CAEA,SAAM;EACJ,IAAI,KAAK,SAAQ,GACf;EAEF,KAAK,KAAK,IAAI,CAAC,KAAK,KAAI,CAAE;CAC5B;CAxC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AAA;EAAA,SAAA;EAAA,MAAA;EAAoB,cAAA;EAAA,UAAA;EAAA,MAAA,EAAA,YAAA;GAAA,MAAA;GAAA,oBAAA;GAAA,cAAA;GAAA,mBAAA;GAAA,sBAAA;EAAA,EAAA;EAAA,UAAA,CAAA,sBAAA;EAAA,UAAA;CAAA,CAAA;;AAApB,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAoB,YAAA,CAAA;EAXhC,MAAA;EAAU,MAAA,CAAA;GACT,UAAU;GACV,UAAU;GACV,MAAM;IACJ,QAAQ;IACR,sBAAsB;IACtB,gBAAgB;IAChB,qBAAqB;IACrB,wBAAwB;GACzB;EACF,CAAA"}
1
+ {"version":3,"file":"forty-cdk-disclosure.mjs","names":[],"sources":["../../../projects/forty-cdk/disclosure/src/disclosure-context.ts","../../../projects/forty-cdk/disclosure/src/disclosure.ts","../../../projects/forty-cdk/disclosure/src/disclosure-trigger.ts","../../../projects/forty-cdk/disclosure/src/disclosure-content.ts"],"sourcesContent":["import { inject, InjectionToken, type Signal } from '@angular/core';\n\nimport { assertRootContext, orphanContextError } from 'forty-cdk/core';\n\n/**\n * Shared state contract between the pieces of a Disclosure primitive.\n * Provided by `ForDisclosure`, consumed by `ForDisclosureTrigger` and\n * `ForDisclosureContent`.\n */\nexport interface ForDisclosureContext {\n readonly open: Signal<boolean>;\n readonly disabled: Signal<boolean>;\n readonly triggerId: Signal<string>;\n readonly contentId: Signal<string>;\n /** Adopts a consumer-set static `id` on the trigger host into `triggerId`. */\n adoptTriggerId(el: HTMLElement): void;\n /** Adopts a consumer-set static `id` on the content host into `contentId`. */\n adoptContentId(el: HTMLElement): void;\n toggle(): void;\n}\n\n/**\n * DI token for the disclosure's coordination surface, provided by `[forDisclosure]`.\n *\n * Publicly typed as the read surface {@link ForDisclosureContext}, which is the whole of\n * what the token promises a consumer. The pieces read the same token at an internal type\n * that adds the content-registration protocol, so a wrapper re-providing it must alias it\n * to the root: `{ provide: FOR_DISCLOSURE_CONTEXT, useExisting: MyDisclosure }`, where\n * `MyDisclosure` extends `ForDisclosure`. A value that merely satisfies the declared type\n * resolves too, and is rejected in dev mode by the first piece to reach the protocol.\n */\nexport const FOR_DISCLOSURE_CONTEXT = new InjectionToken<ForDisclosureContext>(\n 'FOR_DISCLOSURE_CONTEXT',\n);\n\n/**\n * The disclosure's internal coordination surface: everything\n * {@link ForDisclosureContext} publishes plus the content-registration protocol\n * the trigger's `aria-controls` is derived from.\n *\n * Never exported from `public-api.ts`. `ForDisclosure` declares the protocol\n * members TS-`private`, which keeps them out of the emitted `.d.ts` while\n * `useExisting` still satisfies this contract at runtime.\n */\nexport interface DisclosureContext extends ForDisclosureContext {\n registerContent(el: HTMLElement): void;\n unregisterContent(el: HTMLElement): void;\n /** Whether a `[forDisclosureContent]` is mounted, so the trigger can reference it. */\n hasContent(): boolean;\n}\n\n/**\n * Injects the disclosure context or throws a prefixed, actionable error\n * naming the piece that was used outside `[forDisclosure]`.\n */\nexport function injectDisclosureContext(piece: string): DisclosureContext {\n const ctx = inject(FOR_DISCLOSURE_CONTEXT, { optional: true }) as DisclosureContext | null;\n if (!ctx) {\n throw orphanContextError({\n code: 'FORCDK-DISCLOSURE-001',\n piece,\n root: '[forDisclosure]',\n token: 'FOR_DISCLOSURE_CONTEXT',\n });\n }\n assertRootContext({\n entryPoint: 'disclosure',\n token: 'FOR_DISCLOSURE_CONTEXT',\n root: '[forDisclosure]',\n piece,\n probe: () => ctx.registerContent,\n });\n return ctx;\n}\n","import { booleanAttribute, Directive, inject, input, model, signal } from '@angular/core';\n\nimport { adoptHostId, IdGenerator } from 'forty-cdk/core';\nimport { FOR_DISCLOSURE_CONTEXT, type ForDisclosureContext } from './disclosure-context';\n\n/**\n * Root of the Disclosure primitive. Holds the open/disabled state and\n * the IDs that wire the trigger to its content.\n *\n * Implements the [WAI-ARIA Disclosure pattern](https://www.w3.org/WAI/ARIA/apg/patterns/disclosure/).\n *\n * Compose it on any wrapper element with `[forDisclosureTrigger]` and\n * `[forDisclosureContent]` as descendants.\n *\n * @example\n * ```html\n * <div forDisclosure [(open)]=\"isOpen\">\n * <button type=\"button\" forDisclosureTrigger>Toggle</button>\n * <div forDisclosureContent>...</div>\n * </div>\n * ```\n */\n@Directive({\n selector: '[forDisclosure]',\n exportAs: 'forDisclosure',\n host: {\n '[attr.data-state]': 'open() ? \"open\" : \"closed\"',\n '[attr.data-disabled]': 'disabled() ? \"\" : null',\n },\n providers: [{ provide: FOR_DISCLOSURE_CONTEXT, useExisting: ForDisclosure }],\n})\nexport class ForDisclosure implements ForDisclosureContext {\n readonly #idGen = inject(IdGenerator);\n\n /**\n * Two-way bindable open state. Use `[(open)]` for both read & write, or\n * `(openChange)` alone to observe transitions when the directive itself\n * toggles state (trigger click). The `model()` change emitter does NOT fire\n * for consumer-driven writes via `[(open)]`, so subscribing to\n * `(openChange)` is safe and only sees internal transitions.\n */\n readonly open = model<boolean>(false);\n\n /** When true, click on the trigger is ignored and `data-disabled` is reflected. */\n readonly disabled = input(false, { transform: booleanAttribute });\n\n readonly #triggerId = signal(this.#idGen.next('for-disclosure-trigger'));\n readonly #contentId = signal(this.#idGen.next('for-disclosure-content'));\n\n readonly triggerId = this.#triggerId.asReadonly();\n readonly contentId = this.#contentId.asReadonly();\n\n readonly #contents = signal<readonly HTMLElement[]>([]);\n\n /**\n * Adopts a consumer-set static `id` on the `[forDisclosureTrigger]` host into\n * `triggerId` (preserving anchors / external `aria-labelledby` references /\n * label `for`) instead of letting the `[id]` host binding clobber it.\n */\n adoptTriggerId(el: HTMLElement): void {\n adoptHostId(el, this.#triggerId);\n }\n\n /** Adopts a consumer-set static `id` on the content host into `contentId`. */\n adoptContentId(el: HTMLElement): void {\n adoptHostId(el, this.#contentId);\n }\n\n toggle(): void {\n if (this.disabled()) {\n return;\n }\n this.open.set(!this.open());\n }\n\n private registerContent(el: HTMLElement): void {\n this.#contents.update((contents) => [...contents, el]);\n }\n\n private unregisterContent(el: HTMLElement): void {\n this.#contents.update((contents) => {\n const index = contents.lastIndexOf(el);\n return index < 0 ? contents : [...contents.slice(0, index), ...contents.slice(index + 1)];\n });\n }\n\n private hasContent(): boolean {\n return this.#contents().length > 0;\n }\n}\n","import { booleanAttribute, computed, Directive, ElementRef, inject, input } from '@angular/core';\n\nimport { hostButtonType, reflectDisabled } from 'forty-cdk/core';\nimport { injectDisclosureContext } from './disclosure-context';\n\n/**\n * Trigger button for a `ForDisclosure`. Apply on a `<button>` so Enter/Space\n * toggling come from native button behavior. The directive host-binds\n * `type=\"button\"` so a trigger inside a `<form>` never submits it on toggle.\n *\n * `aria-controls` references the content while open, and while closed with the\n * content kept mounted. A panel unmounted by `@if (open())` is not referenced\n * while closed.\n *\n * Disabling: the trigger merges its own `disabled` input OR the root's\n * `disabled` into `effectiveDisabled`, which drives the native `disabled`\n * attribute, `data-disabled`, and the click guard. The native attribute is the\n * single reflection channel — no `aria-disabled` is emitted, because on a real\n * single-purpose `<button>` trigger the native attribute already conveys the\n * state to assistive technology.\n */\n@Directive({\n selector: '[forDisclosureTrigger]',\n exportAs: 'forDisclosureTrigger',\n host: {\n '[attr.type]': 'buttonType()',\n '[id]': 'ctx.triggerId()',\n '[attr.aria-expanded]': 'ctx.open() ? \"true\" : \"false\"',\n '[attr.aria-controls]': 'ctx.open() || ctx.hasContent() ? ctx.contentId() : null',\n '[attr.data-state]': 'ctx.open() ? \"open\" : \"closed\"',\n '[attr.data-disabled]': 'effectiveDisabled() ? \"\" : null',\n '(click)': 'onClick()',\n },\n})\nexport class ForDisclosureTrigger {\n private readonly buttonType = hostButtonType();\n\n private readonly ctx = injectDisclosureContext('ForDisclosureTrigger');\n\n /** Disables this trigger only, in addition to the root's `disabled`. */\n readonly disabled = input(false, { transform: booleanAttribute });\n\n /** Whether the trigger is disabled — its own `disabled` input OR the root's. */\n readonly effectiveDisabled = computed(() => this.disabled() || this.ctx.disabled());\n\n constructor() {\n this.ctx.adoptTriggerId(inject<ElementRef<HTMLElement>>(ElementRef).nativeElement);\n reflectDisabled(this.effectiveDisabled);\n }\n\n private onClick(): void {\n if (this.effectiveDisabled()) {\n return;\n }\n this.ctx.toggle();\n }\n}\n","import { booleanAttribute, computed, Directive, ElementRef, inject, input } from '@angular/core';\n\nimport { HIDDEN_UNTIL_FOUND, keepHiddenUntilFound, registerHandle } from 'forty-cdk/core';\nimport { injectDisclosureContext } from './disclosure-context';\n\n/**\n * Disclosed content panel for a `ForDisclosure`. The directive does not\n * manage DOM presence — wrap with `@if (open())` so the panel mounts and\n * unmounts with the disclosure state, and use `animate.enter` /\n * `animate.leave` for transitions if desired. If the consumer prefers to\n * keep the panel mounted (for CSS-only transitions or to preserve internal\n * state), the directive reflects `aria-hidden=\"true\"` and `inert` while\n * closed so the panel is removed from the accessibility tree and focus\n * order automatically.\n *\n * Set `hiddenUntilFound` on a mounted panel to hide it with\n * `hidden=\"until-found\"` instead, so find-in-page can reach its text and open it.\n */\n@Directive({\n selector: '[forDisclosureContent]',\n exportAs: 'forDisclosureContent',\n host: {\n '[id]': 'ctx.contentId()',\n '[attr.hidden]': 'untilFound() ? hiddenValue : null',\n '[attr.aria-hidden]': 'ctx.open() || hiddenUntilFound() ? null : \"true\"',\n '[attr.inert]': 'ctx.open() || hiddenUntilFound() ? null : \"\"',\n '[attr.data-state]': 'ctx.open() ? \"open\" : \"closed\"',\n '[attr.data-disabled]': 'ctx.disabled() ? \"\" : null',\n '(beforematch)': 'onBeforeMatch()',\n },\n})\nexport class ForDisclosureContent {\n private readonly ctx = injectDisclosureContext('ForDisclosureContent');\n readonly #host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;\n\n /**\n * When set, a closed panel is hidden with `hidden=\"until-found\"` in place of\n * `aria-hidden` + `inert`, and a find-in-page match or fragment navigation inside it\n * opens the disclosure as a trigger click would. A disabled disclosure stays closed.\n * Closing is instant, so the opt-in rules out an exit animation.\n */\n readonly hiddenUntilFound = input(false, { transform: booleanAttribute });\n\n private readonly hiddenValue = HIDDEN_UNTIL_FOUND;\n\n private readonly untilFound = computed(() => this.hiddenUntilFound() && !this.ctx.open());\n\n constructor() {\n this.ctx.adoptContentId(this.#host);\n registerHandle(\n this.#host,\n (el) => this.ctx.registerContent(el),\n (el) => this.ctx.unregisterContent(el),\n );\n }\n\n private onBeforeMatch(): void {\n if (!this.untilFound()) {\n return;\n }\n this.ctx.toggle();\n if (this.untilFound()) {\n keepHiddenUntilFound(this.#host, () => this.untilFound());\n }\n }\n}\n"],"mappings":";;;AA+BA,MAAa,yBAAyB,IAAI,eACxC,wBAAwB;AAuB1B,SAAgB,wBAAwB,OAAa;CACnD,MAAM,MAAM,OAAO,wBAAwB,EAAE,UAAU,KAAI,CAAE;CAC7D,IAAI,CAAC,KACH,MAAM,mBAAmB;EACvB,MAAM;EACN;EACA,MAAM;EACN,OAAO;CACR,CAAA;CAEH,kBAAkB;EAChB,YAAY;EACZ,OAAO;EACP,MAAM;EACN;EACA,aAAa,IAAI;CAClB,CAAA;CACD,OAAO;AACT;AC1CA,IAAa,gBAAb,MAAa,cAAa;CACf,SAAS,OAAO,WAAW;CAS3B,OAAO,MAAe,OAAM,GAAA,YAAA,CAAA,EAAA,WAAA,OAAA,CAAA,+BAAA,CAAA,CAAA;CAG5B,WAAW,MAAM,OAAK;EAAA,GAAA,YAAA,EAAA,WAAA,WAAA,+BAAA,CAAA;EAAI,WAAW;CAAgB,CAAA;CAErD,aAAa,OAAO,KAAK,OAAO,KAAK,wBAAwB,GAAE,GAAA,YAAA,CAAA,EAAA,WAAA,aAAA,CAAA,+BAAA,CAAA,CAAA;CAC/D,aAAa,OAAO,KAAK,OAAO,KAAK,wBAAwB,GAAE,GAAA,YAAA,CAAA,EAAA,WAAA,aAAA,CAAA,+BAAA,CAAA,CAAA;CAE/D,YAAY,KAAK,WAAW,WAAU;CACtC,YAAY,KAAK,WAAW,WAAU;CAEtC,YAAY,OAA+B,CAAA,GAAG,GAAA,YAAA,CAAA,EAAA,WAAA,YAAA,CAAA,+BAAA,CA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AA,YAAA;GAAA,mBAAA;EAAA,EAAA;EAAA,MAAA;GAAA,WAAA,EAAA,eAAA,kBAAA;GAAA,YAAA;IAAA,MAAA;IAAA,eAAA;IAAA,oBAAA;IAAA,cAAA;IAAA,mBAAA;IAAA,sBAAA;GAAA;EAAA;EAAA,UAAA,CAAA,sBAAA;EAAA,UAAA;CAAA,CAAA;;AAApB,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAoB,YAAA,CAAA;EAbhC,MAAA;EAAU,MAAA,CAAA;GACT,UAAU;GACV,UAAU;GACV,MAAM;IACJ,QAAQ;IACR,iBAAiB;IACjB,sBAAsB;IACtB,gBAAgB;IAChB,qBAAqB;IACrB,wBAAwB;IACxB,iBAAiB;GAClB;EACF,CAAA"}
@@ -1,6 +1,6 @@
1
1
  import * as i0 from "@angular/core";
2
2
  import { ChangeDetectionStrategy, Component, DOCUMENT, DestroyRef, Directive, ElementRef, Injectable, InjectionToken, Injector, PLATFORM_ID, TemplateRef, afterEveryRender, afterNextRender, booleanAttribute, computed, contentChild, effect, inject, input, isSignal, model, numberAttribute, output, signal, viewChildren } from "@angular/core";
3
- import { Collection, DRAG_DEAD_ZONE_PX, DragAnnouncer, EscapeArbiter, LiveAnnouncer, RovingTabindex, TABLE_REGISTRATION_CONTEXT, TABLE_ROW_REGISTRATION_CONTEXT, appendMissing, arbitrateLiftPress, assertInputBound, assertRootContext, boundEntries, clamp, composedContains, consumeUnmappedLiftedKey, createKeyboardDragMediator, createPointerDragSession, createPointerHighlight, dedupeValues, defaultCompareWith, findFirstFocusable, findPressedDragItem, firstEnabledHost, focusWhenMounted, fortyError, hostAriaLabel, hostButtonType, injectElementSize, injectHostCarriesDragItem, injectPointerMove, injectReflectedDirection, injectTextDirection, isDragLiftKey, isHistoryChord, isImeComposing, isUnset, layoutPlaceholderInSlot, membership, moveGridIndex, orphanContextError, registerHandle, resolveGridNavigation, resolveLiftedDragControl, resolvePressedDragItem, resolveTreegridExpandCollapse, resolveWindowedReorder, selectionMembership, stepDragTarget, stepFocusableCycle, translateWindowReorder, unsetInput } from "forty-cdk/core";
3
+ import { Collection, DRAG_DEAD_ZONE_PX, DragAnnouncer, EscapeArbiter, LiveAnnouncer, RovingTabindex, TABLE_REGISTRATION_CONTEXT, TABLE_ROW_REGISTRATION_CONTEXT, appendMissing, arbitrateLiftPress, assertInputBound, assertRootContext, boundEntries, clamp, composedContains, consumeUnmappedLiftedKey, createKeyboardDragMediator, createPointerDragSession, createPointerHighlight, dedupeValues, defaultCompareWith, findFirstFocusable, findPressedDragItem, firstEnabledHost, focusWhenMounted, fortyError, hostAriaLabel, hostButtonType, injectElementSize, injectHostCarriesDragItem, injectPointerMove, injectReflectedDirection, injectRovingFocusRestore, injectTextDirection, isDragLiftKey, isHistoryChord, isImeComposing, isUnset, layoutPlaceholderInSlot, membership, moveGridIndex, orphanContextError, registerHandle, resolveGridNavigation, resolveLiftedDragControl, resolvePressedDragItem, resolveTreegridExpandCollapse, resolveWindowedReorder, selectionMembership, stepDragTarget, stepFocusableCycle, translateWindowReorder, unsetInput } from "forty-cdk/core";
4
4
  import { CssVarNamespacer } from "@angular/platform-browser";
5
5
  import { NgTemplateOutlet, isPlatformBrowser } from "@angular/common";
6
6
  import * as i1 from "forty-cdk/drag-drop";
@@ -464,8 +464,52 @@ var ForTable = class ForTable {
464
464
  const rendered = this.#cols();
465
465
  return rendered === 0 ? UNKNOWN_COUNT : rendered;
466
466
  }, ...ngDevMode ? [{ debugName: "colCountAttr" }] : /* istanbul ignore next */ []);
467
+ #focusedPosition = null;
467
468
  constructor() {
468
469
  this.#registry.registerHeaderCellFocus((column) => this.#focusHeaderCell(column));
470
+ injectRovingFocusRestore({
471
+ active: () => this.#focusRestoreTarget(),
472
+ noteFocus: (el) => this.#noteFocusedPosition(el)
473
+ }, { skip: () => this.#windowed() });
474
+ }
475
+ #gridRows() {
476
+ const body = this.#registry.rows().map((row) => row.cells());
477
+ return this.#headerParticipates() ? [this.#headerCellHosts(), ...body] : body;
478
+ }
479
+ #noteFocusedPosition(el) {
480
+ if (el === null) return;
481
+ this.#focusedPosition = null;
482
+ if (this.mode() === "table") return;
483
+ const rows = this.#gridRows();
484
+ for (let row = 0; row < rows.length; row++) {
485
+ const column = rows[row].findIndex((cell) => cell.host === el || composedContains(cell.host, el));
486
+ if (column >= 0) {
487
+ this.#focusedPosition = {
488
+ row,
489
+ column
490
+ };
491
+ return;
492
+ }
493
+ }
494
+ }
495
+ #focusRestoreTarget() {
496
+ if (this.mode() === "table") return null;
497
+ const current = this.#roving.active();
498
+ if (current !== null && current.isConnected) return current;
499
+ const target = this.#cellNear(this.#focusedPosition) ?? this.#firstEnabledCell();
500
+ if (target !== null) this.#roving.setActive(target);
501
+ return target;
502
+ }
503
+ #cellNear(position) {
504
+ if (position === null) return null;
505
+ const rows = this.#gridRows();
506
+ const cells = rows[Math.min(position.row, rows.length - 1)] ?? [];
507
+ const column = Math.min(position.column, cells.length - 1);
508
+ for (let distance = 0; distance < cells.length; distance++) for (const index of [column - distance, column + distance]) {
509
+ const cell = cells[index];
510
+ if (cell !== void 0 && !cell.disabled()) return cell.host;
511
+ }
512
+ return null;
469
513
  }
470
514
  isRowExpanded(value) {
471
515
  return this.#expansion.isExpanded(value);