@cngx/common 0.1.0-rc.8 → 0.1.0-rc.9

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 (52) hide show
  1. package/command/README.md +29 -0
  2. package/data/README.md +5 -2
  3. package/fesm2022/cngx-common-a11y.mjs +403 -84
  4. package/fesm2022/cngx-common-a11y.mjs.map +1 -1
  5. package/fesm2022/cngx-common-audio.mjs +16 -13
  6. package/fesm2022/cngx-common-audio.mjs.map +1 -1
  7. package/fesm2022/cngx-common-card.mjs +4 -3
  8. package/fesm2022/cngx-common-card.mjs.map +1 -1
  9. package/fesm2022/cngx-common-chart.mjs +55 -36
  10. package/fesm2022/cngx-common-chart.mjs.map +1 -1
  11. package/fesm2022/cngx-common-command.mjs +60 -6
  12. package/fesm2022/cngx-common-command.mjs.map +1 -1
  13. package/fesm2022/cngx-common-data.mjs +185 -37
  14. package/fesm2022/cngx-common-data.mjs.map +1 -1
  15. package/fesm2022/cngx-common-dialog.mjs +86 -48
  16. package/fesm2022/cngx-common-dialog.mjs.map +1 -1
  17. package/fesm2022/cngx-common-display.mjs +27 -23
  18. package/fesm2022/cngx-common-display.mjs.map +1 -1
  19. package/fesm2022/cngx-common-interactive.mjs +324 -122
  20. package/fesm2022/cngx-common-interactive.mjs.map +1 -1
  21. package/fesm2022/cngx-common-layout.mjs +129 -26
  22. package/fesm2022/cngx-common-layout.mjs.map +1 -1
  23. package/fesm2022/cngx-common-popover.mjs +947 -33
  24. package/fesm2022/cngx-common-popover.mjs.map +1 -1
  25. package/fesm2022/cngx-common-stepper.mjs +300 -166
  26. package/fesm2022/cngx-common-stepper.mjs.map +1 -1
  27. package/fesm2022/cngx-common-tabs.mjs +251 -80
  28. package/fesm2022/cngx-common-tabs.mjs.map +1 -1
  29. package/fesm2022/cngx-common-timeline.mjs +16 -10
  30. package/fesm2022/cngx-common-timeline.mjs.map +1 -1
  31. package/fesm2022/cngx-common.mjs +1 -1
  32. package/layout/README.md +16 -0
  33. package/package.json +20 -7
  34. package/popover/README.md +40 -0
  35. package/schematics/collection.json +9 -0
  36. package/schematics/ng-add/index.js +9 -0
  37. package/schematics/ng-add/schema.json +91 -0
  38. package/schematics/package.json +3 -0
  39. package/stepper/README.md +5 -4
  40. package/theming/components/cngx-popover-sheet.css +402 -0
  41. package/theming/components/cngx-popover.css +10 -6
  42. package/types/cngx-common-a11y.d.ts +167 -14
  43. package/types/cngx-common-chart.d.ts +8 -7
  44. package/types/cngx-common-command.d.ts +19 -2
  45. package/types/cngx-common-data.d.ts +164 -26
  46. package/types/cngx-common-dialog.d.ts +3 -7
  47. package/types/cngx-common-interactive.d.ts +52 -17
  48. package/types/cngx-common-layout.d.ts +37 -5
  49. package/types/cngx-common-popover.d.ts +353 -13
  50. package/types/cngx-common-stepper.d.ts +168 -129
  51. package/types/cngx-common-tabs.d.ts +149 -30
  52. package/types/cngx-common-timeline.d.ts +27 -7
@@ -1,16 +1,29 @@
1
- import { InjectionToken, inject, computed } from '@angular/core';
1
+ import { InjectionToken, inject, EnvironmentInjector, computed } from '@angular/core';
2
2
  import { foldForMatching, injectLocale } from '@cngx/core/utils';
3
3
 
4
4
  /**
5
5
  * Multi-token every `provideCommands` call contributes to. App parts register
6
6
  * command sets against it without a central list, mirroring `provideCngxMenu`.
7
7
  * The generic is the collected array (as with Angular's `HTTP_INTERCEPTORS`),
8
- * so `inject(CNGX_COMMAND_SOURCE)` returns every contributed source.
8
+ * so `inject(CNGX_COMMAND_SOURCE)` returns the sources of the nearest level
9
+ * that provides it.
10
+ *
11
+ * This is the low-level form. Register through `provideCommands`, which also
12
+ * carries a level's sources into every scope below it. A raw multi-provider on
13
+ * this token is carried down only from a level that also calls
14
+ * `provideCommands`; on any other level it is read only when that level is the
15
+ * one `injectCommands` resolves as nearest.
9
16
  *
10
17
  * @category common/command
11
18
  * @since 0.1.0
12
19
  */
13
20
  const CNGX_COMMAND_SOURCE = new InjectionToken('CNGX_COMMAND_SOURCE');
21
+ /**
22
+ * @internal Per-level registry: the sources of every `provideCommands` level
23
+ * above, plus this level's own. Resolved once per injector by the factory in
24
+ * `provideCommands`; not part of the public API.
25
+ */
26
+ const CNGX_COMMAND_REGISTRY = new InjectionToken('CNGX_COMMAND_REGISTRY');
14
27
  /**
15
28
  * Registers one or more command sources. Each source becomes a `multi` entry
16
29
  * on {@link CNGX_COMMAND_SOURCE}; call `provideCommands` from several app parts
@@ -21,9 +34,18 @@ const CNGX_COMMAND_SOURCE = new InjectionToken('CNGX_COMMAND_SOURCE');
21
34
  * `viewProviders` - letting a route or component contribute a scoped command
22
35
  * set without reaching for the raw {@link CNGX_COMMAND_SOURCE} multi-provider.
23
36
  *
37
+ * A scoped call adds to the sets above it and never hides them, across route
38
+ * and component scopes: root and route scopes come first (outer to inner), then
39
+ * component scopes outer to inner. The same source reference registered at two
40
+ * levels is listed once. Command ids are unique in the merged list: a command
41
+ * whose `id` is already registered further out replaces that command in place,
42
+ * so a scope can swap a global command for its own version.
43
+ *
24
44
  * ```ts
25
45
  * // app root
26
46
  * bootstrapApplication(AppComponent, { providers: [provideCommands(fileCommands)] });
47
+ * // a lazy route adds its set; its pages see fileCommands + reportCommands
48
+ * { path: 'reports', providers: [provideCommands(reportCommands)], component: Reports }
27
49
  * // or component scope
28
50
  * @Component({ viewProviders: [provideCommands(editorCommands)] })
29
51
  * ```
@@ -32,10 +54,23 @@ const CNGX_COMMAND_SOURCE = new InjectionToken('CNGX_COMMAND_SOURCE');
32
54
  * @since 0.1.0
33
55
  */
34
56
  function provideCommands(...sources) {
35
- return sources.map((source) => ({ provide: CNGX_COMMAND_SOURCE, useValue: source, multi: true }));
57
+ // Empty call: the parent registry flows through untouched.
58
+ if (sources.length === 0) {
59
+ return [];
60
+ }
61
+ return [
62
+ ...sources.map((source) => ({ provide: CNGX_COMMAND_SOURCE, useValue: source, multi: true })),
63
+ {
64
+ provide: CNGX_COMMAND_REGISTRY,
65
+ // The nearest CNGX_COMMAND_SOURCE is this level's own multi list, so the
66
+ // same factory works for environment, providers and viewProviders scopes.
67
+ useFactory: () => mergeSources(inject(CNGX_COMMAND_REGISTRY, { skipSelf: true, optional: true }) ?? [], inject(CNGX_COMMAND_SOURCE, { optional: true }) ?? []),
68
+ },
69
+ ];
36
70
  }
37
71
  /**
38
- * Merges every registered {@link CNGX_COMMAND_SOURCE} into one reactive
72
+ * Merges the command sources registered at this injector level and every level
73
+ * above it - route and component scopes alike - into one reactive
39
74
  * `Signal<readonly CngxCommand[]>`. The merge carries an explicit `equal`
40
75
  * (length + per-command identity) so re-emitting an identical set - the same
41
76
  * command references in the same order - does not produce a fresh array and
@@ -47,8 +82,27 @@ function provideCommands(...sources) {
47
82
  * @since 0.1.0
48
83
  */
49
84
  function injectCommands() {
50
- const sources = inject(CNGX_COMMAND_SOURCE, { optional: true }) ?? [];
51
- return computed(() => sources.flatMap(readSource), { equal: commandsEqual });
85
+ // A node resolves its element chain before its environment chain, so a
86
+ // routed component under a shell registry never reaches the route's
87
+ // registry. Read both trees once and join them: environment scopes first.
88
+ const sources = mergeSources(inject(EnvironmentInjector).get(CNGX_COMMAND_REGISTRY, null) ?? [], inject(CNGX_COMMAND_REGISTRY, { optional: true }) ?? [], inject(CNGX_COMMAND_SOURCE, { optional: true }) ?? []);
89
+ return computed(() => dedupeById(sources.flatMap(readSource)), { equal: commandsEqual });
90
+ }
91
+ /**
92
+ * @internal Keeps one command per `id`: the last registration (the innermost
93
+ * scope) wins, at the position of the first. A Map keeps a key's insertion slot
94
+ * when its value is replaced.
95
+ */
96
+ function dedupeById(commands) {
97
+ const byId = new Map();
98
+ for (const command of commands) {
99
+ byId.set(command.id, command);
100
+ }
101
+ return byId.size === commands.length ? commands : [...byId.values()];
102
+ }
103
+ /** @internal Concatenates in argument order and drops repeated source references. */
104
+ function mergeSources(...lists) {
105
+ return [...new Set(lists.flat())];
52
106
  }
53
107
  /** @internal Reads a source, unwrapping a signal or passing an array through. */
54
108
  function readSource(source) {
@@ -1 +1 @@
1
- {"version":3,"file":"cngx-common-command.mjs","sources":["../../../projects/common/command/provide-commands.ts","../../../projects/common/command/match.ts","../../../projects/common/command/match-strategy.token.ts","../../../projects/common/command/cngx-common-command.ts"],"sourcesContent":["import {\n computed,\n inject,\n InjectionToken,\n type Provider,\n type Signal,\n} from '@angular/core';\n\nimport type { CngxCommand } from './command';\n\n/**\n * A command contribution. Either a static list or a reactive `Signal` of\n * commands - a signal source lets a contributor add or remove commands (or\n * flip a command's `disabled`) live, and `injectCommands` tracks it.\n *\n * @category common/command\n * @since 0.1.0\n */\nexport type CngxCommandSource = Signal<readonly CngxCommand[]> | readonly CngxCommand[];\n\n/**\n * Multi-token every `provideCommands` call contributes to. App parts register\n * command sets against it without a central list, mirroring `provideCngxMenu`.\n * The generic is the collected array (as with Angular's `HTTP_INTERCEPTORS`),\n * so `inject(CNGX_COMMAND_SOURCE)` returns every contributed source.\n *\n * @category common/command\n * @since 0.1.0\n */\nexport const CNGX_COMMAND_SOURCE = new InjectionToken<readonly CngxCommandSource[]>(\n 'CNGX_COMMAND_SOURCE',\n);\n\n/**\n * Registers one or more command sources. Each source becomes a `multi` entry\n * on {@link CNGX_COMMAND_SOURCE}; call `provideCommands` from several app parts\n * and `injectCommands` merges all of them.\n *\n * Returns `Provider[]` (not `EnvironmentProviders`), so it registers at any\n * injector scope - app root, a lazy route, or a component's `providers` /\n * `viewProviders` - letting a route or component contribute a scoped command\n * set without reaching for the raw {@link CNGX_COMMAND_SOURCE} multi-provider.\n *\n * ```ts\n * // app root\n * bootstrapApplication(AppComponent, { providers: [provideCommands(fileCommands)] });\n * // or component scope\n * @Component({ viewProviders: [provideCommands(editorCommands)] })\n * ```\n *\n * @category common/command\n * @since 0.1.0\n */\nexport function provideCommands(...sources: CngxCommandSource[]): Provider[] {\n return sources.map((source) => ({ provide: CNGX_COMMAND_SOURCE, useValue: source, multi: true }));\n}\n\n/**\n * Merges every registered {@link CNGX_COMMAND_SOURCE} into one reactive\n * `Signal<readonly CngxCommand[]>`. The merge carries an explicit `equal`\n * (length + per-command identity) so re-emitting an identical set - the same\n * command references in the same order - does not produce a fresh array and\n * cascade the downstream match `computed()`.\n *\n * Must run in an injection context.\n *\n * @category common/command\n * @since 0.1.0\n */\nexport function injectCommands(): Signal<readonly CngxCommand[]> {\n const sources = inject(CNGX_COMMAND_SOURCE, { optional: true }) ?? [];\n return computed(() => sources.flatMap(readSource), { equal: commandsEqual });\n}\n\n/** @internal Reads a source, unwrapping a signal or passing an array through. */\nfunction readSource(source: CngxCommandSource): readonly CngxCommand[] {\n return typeof source === 'function' ? source() : source;\n}\n\n/**\n * @internal Length + per-command identity. Identity subsumes id equality, so a\n * re-provided set of the same references short-circuits without re-emitting.\n */\nfunction commandsEqual(a: readonly CngxCommand[], b: readonly CngxCommand[]): boolean {\n if (a === b) {\n return true;\n }\n if (a.length !== b.length) {\n return false;\n }\n return a.every((command, i) => command === b[i]);\n}\n","import type { Signal } from '@angular/core';\nimport { foldForMatching } from '@cngx/core/utils';\n\nimport type { CngxCommand } from './command';\n\n/**\n * A command paired with its match score for a given query. Higher scores rank\n * first. The palette renders these in order; the row slot reads `command` and\n * the term to highlight.\n *\n * @category common/command\n * @since 0.1.0\n */\nexport interface CngxRankedCommand {\n /** The matched command. */\n readonly command: CngxCommand;\n /** Relevance score for the query; higher ranks first. `0` for an empty query. */\n readonly score: number;\n}\n\n/**\n * @deprecated Use {@link CngxRankedCommand}. Published under the unprefixed\n * name by mistake; the alias remains for compatibility and will be removed in\n * a future major.\n * @category common/command\n * @since 0.1.0\n */\nexport type RankedCommand = CngxRankedCommand;\n\n/**\n * Ranks and filters a command set against a query and optional scope. Swappable\n * via {@link CNGX_COMMAND_MATCH_FACTORY} - a consumer drops in Levenshtein or a\n * fuzzy engine without touching the panel.\n *\n * @category common/command\n * @since 0.1.0\n */\nexport type CngxCommandMatcher = (\n commands: readonly CngxCommand[],\n term: string,\n scope?: string,\n) => readonly CngxRankedCommand[];\n\n/**\n * Builds the default matcher: a pure label/keyword ranker. An empty query\n * returns every (scoped) command at score `0` in registration order; a\n * non-empty query keeps only commands that match label or keyword, ranked\n * label-exact > label-prefix > label-substring > keyword. The optional scope\n * filters to commands whose `group` equals it.\n *\n * Query, labels and keywords are compared case- and accent-tolerant\n * ({@link foldForMatching}): `uber` finds `Über`. Pass the app locale (the\n * default `CNGX_COMMAND_MATCH_FACTORY` passes `injectLocale()`) so case folds\n * by its rules, e.g. Turkish `I` / `ı`; read inside a `computed()`, a locale\n * switch re-ranks.\n *\n * @category common/command\n * @since 0.1.0\n */\nexport function createDefaultCommandMatcher(locale?: Signal<string>): CngxCommandMatcher {\n // Folded label and keywords per command, re-folded only when the label, the\n // keywords array or the locale changes - not on every keystroke.\n const folded = new WeakMap<CngxCommand, FoldedCommand>();\n const foldedFor = (command: CngxCommand, activeLocale: string | undefined): FoldedCommand => {\n const hit = folded.get(command);\n if (\n hit !== undefined &&\n hit.locale === activeLocale &&\n hit.sourceLabel === command.label &&\n hit.sourceKeywords === command.keywords\n ) {\n return hit;\n }\n const entry: FoldedCommand = {\n locale: activeLocale,\n sourceLabel: command.label,\n sourceKeywords: command.keywords,\n label: foldForMatching(command.label, activeLocale),\n keywords: (command.keywords ?? []).map((keyword) => foldForMatching(keyword, activeLocale)),\n };\n folded.set(command, entry);\n return entry;\n };\n\n return (commands, term, scope) => {\n const scoped = scope ? commands.filter((command) => command.group === scope) : commands;\n const activeLocale = locale?.();\n const query = foldForMatching(term.trim(), activeLocale);\n if (query.length === 0) {\n return scoped.map((command) => ({ command, score: 0 }));\n }\n\n const ranked: CngxRankedCommand[] = [];\n for (const command of scoped) {\n const score = scoreCommand(foldedFor(command, activeLocale), query);\n if (score > 0) {\n ranked.push({ command, score });\n }\n }\n // Stable within equal scores: the sort is stable in V8, so registration\n // order breaks ties.\n ranked.sort((a, b) => b.score - a.score);\n return ranked;\n };\n}\n\n/** @internal A command's label and keywords, folded for one locale. */\ninterface FoldedCommand {\n readonly locale: string | undefined;\n readonly sourceLabel: string;\n readonly sourceKeywords: CngxCommand['keywords'];\n readonly label: string;\n readonly keywords: readonly string[];\n}\n\n/** @internal Scores one folded command against a folded query; `0` means no match. */\nfunction scoreCommand({ label, keywords }: FoldedCommand, query: string): number {\n if (label === query) {\n return 100;\n }\n if (label.startsWith(query)) {\n return 80;\n }\n if (label.includes(query)) {\n return 60;\n }\n for (const value of keywords) {\n if (value === query) {\n return 50;\n }\n if (value.startsWith(query)) {\n return 40;\n }\n if (value.includes(query)) {\n return 20;\n }\n }\n return 0;\n}\n","import { InjectionToken } from '@angular/core';\nimport { injectLocale } from '@cngx/core/utils';\n\nimport { createDefaultCommandMatcher, type CngxCommandMatcher } from './match';\n\n/**\n * Factory producing a {@link CngxCommandMatcher}. The exact signature is\n * captured so an override matches it precisely. The panel calls it in an\n * injection context, so a factory may `inject()` what its matcher needs.\n *\n * @category common/command\n * @since 0.1.0\n */\nexport type CngxCommandMatchFactory = () => CngxCommandMatcher;\n\n/**\n * Swappable match-strategy seam. Defaults to {@link createDefaultCommandMatcher}\n * (pure label/keyword ranking, case- and accent-tolerant in the app locale). Override it - app-wide via `providers` or\n * per-component via `viewProviders` - to drop in a fuzzy/Levenshtein ranker\n * without touching the panel. The fuzzy engine stays a consumer swap; the\n * default bundle ships only the pure ranker.\n *\n * @category common/command\n * @since 0.1.0\n */\nexport const CNGX_COMMAND_MATCH_FACTORY = new InjectionToken<CngxCommandMatchFactory>(\n 'CNGX_COMMAND_MATCH_FACTORY',\n { providedIn: 'root', factory: () => () => createDefaultCommandMatcher(injectLocale()) },\n);\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;AAoBA;;;;;;;;AAQG;MACU,mBAAmB,GAAG,IAAI,cAAc,CACnD,qBAAqB;AAGvB;;;;;;;;;;;;;;;;;;;AAmBG;AACG,SAAU,eAAe,CAAC,GAAG,OAA4B,EAAA;IAC7D,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,MAAM,EAAE,OAAO,EA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AAO,EAAE,KAAK,EAAE,CAAC;YACjC;QACF;;;AAGA,QAAA,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;AACxC,QAAA,OAAO,MAAM;AACf,IAAA,CAAC;AACH;AAWA;AACA,SAAS,YAAY,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAiB,EAAE,KAAa,EAAA;AACrE,IAAA,IAAI,KAAK,KAAK,KAAK,EAAE;AACnB,QAAA,OAAO,GAAG;IACZ;AACA,IAAA,IAAI,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;AAC3B,QAAA,OAAO,EAAE;IACX;AACA,IAAA,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;AACzB,QAAA,OAAO,EAAE;IACX;AACA,IAAA,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE;AAC5B,QAAA,IAAI,KAAK,KAAK,KAAK,EAAE;AACnB,YAAA,OAAO,EAAE;QACX;AACA,QAAA,IAAI,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;AAC3B,YAAA,OAAO,EAAE;QACX;AACA,QAAA,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;AACzB,YAAA,OAAO,EAAE;QACX;IACF;AACA,IAAA,OAAO,CAAC;AACV;;AC3HA;;;;;;;;;AASG;AACI,MAAM,0BAA0B,GAAG,IAAI,cAAc,CAC1D,4BAA4B,EAC5B,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,MAAM,2BAA2B,CAAC,YAAY,EAAE,CAAC,EAAE;;AC3B1F;;AAEG;;;;"}
1
+ {"version":3,"file":"cngx-common-command.mjs","sources":["../../../projects/common/command/provide-commands.ts","../../../projects/common/command/match.ts","../../../projects/common/command/match-strategy.token.ts","../../../projects/common/command/cngx-common-command.ts"],"sourcesContent":["import {\n computed,\n EnvironmentInjector,\n inject,\n InjectionToken,\n type Provider,\n type Signal,\n} from '@angular/core';\n\nimport type { CngxCommand } from './command';\n\n/**\n * A command contribution. Either a static list or a reactive `Signal` of\n * commands - a signal source lets a contributor add or remove commands (or\n * flip a command's `disabled`) live, and `injectCommands` tracks it.\n *\n * @category common/command\n * @since 0.1.0\n */\nexport type CngxCommandSource = Signal<readonly CngxCommand[]> | readonly CngxCommand[];\n\n/**\n * Multi-token every `provideCommands` call contributes to. App parts register\n * command sets against it without a central list, mirroring `provideCngxMenu`.\n * The generic is the collected array (as with Angular's `HTTP_INTERCEPTORS`),\n * so `inject(CNGX_COMMAND_SOURCE)` returns the sources of the nearest level\n * that provides it.\n *\n * This is the low-level form. Register through `provideCommands`, which also\n * carries a level's sources into every scope below it. A raw multi-provider on\n * this token is carried down only from a level that also calls\n * `provideCommands`; on any other level it is read only when that level is the\n * one `injectCommands` resolves as nearest.\n *\n * @category common/command\n * @since 0.1.0\n */\nexport const CNGX_COMMAND_SOURCE = new InjectionToken<readonly CngxCommandSource[]>(\n 'CNGX_COMMAND_SOURCE',\n);\n\n/**\n * @internal Per-level registry: the sources of every `provideCommands` level\n * above, plus this level's own. Resolved once per injector by the factory in\n * `provideCommands`; not part of the public API.\n */\nconst CNGX_COMMAND_REGISTRY = new InjectionToken<readonly CngxCommandSource[]>(\n 'CNGX_COMMAND_REGISTRY',\n);\n\n/**\n * Registers one or more command sources. Each source becomes a `multi` entry\n * on {@link CNGX_COMMAND_SOURCE}; call `provideCommands` from several app parts\n * and `injectCommands` merges all of them.\n *\n * Returns `Provider[]` (not `EnvironmentProviders`), so it registers at any\n * injector scope - app root, a lazy route, or a component's `providers` /\n * `viewProviders` - letting a route or component contribute a scoped command\n * set without reaching for the raw {@link CNGX_COMMAND_SOURCE} multi-provider.\n *\n * A scoped call adds to the sets above it and never hides them, across route\n * and component scopes: root and route scopes come first (outer to inner), then\n * component scopes outer to inner. The same source reference registered at two\n * levels is listed once. Command ids are unique in the merged list: a command\n * whose `id` is already registered further out replaces that command in place,\n * so a scope can swap a global command for its own version.\n *\n * ```ts\n * // app root\n * bootstrapApplication(AppComponent, { providers: [provideCommands(fileCommands)] });\n * // a lazy route adds its set; its pages see fileCommands + reportCommands\n * { path: 'reports', providers: [provideCommands(reportCommands)], component: Reports }\n * // or component scope\n * @Component({ viewProviders: [provideCommands(editorCommands)] })\n * ```\n *\n * @category common/command\n * @since 0.1.0\n */\nexport function provideCommands(...sources: CngxCommandSource[]): Provider[] {\n // Empty call: the parent registry flows through untouched.\n if (sources.length === 0) {\n return [];\n }\n return [\n ...sources.map((source) => ({ provide: CNGX_COMMAND_SOURCE, useValue: source, multi: true })),\n {\n provide: CNGX_COMMAND_REGISTRY,\n // The nearest CNGX_COMMAND_SOURCE is this level's own multi list, so the\n // same factory works for environment, providers and viewProviders scopes.\n useFactory: () =>\n mergeSources(\n inject(CNGX_COMMAND_REGISTRY, { skipSelf: true, optional: true }) ?? [],\n inject(CNGX_COMMAND_SOURCE, { optional: true }) ?? [],\n ),\n },\n ];\n}\n\n/**\n * Merges the command sources registered at this injector level and every level\n * above it - route and component scopes alike - into one reactive\n * `Signal<readonly CngxCommand[]>`. The merge carries an explicit `equal`\n * (length + per-command identity) so re-emitting an identical set - the same\n * command references in the same order - does not produce a fresh array and\n * cascade the downstream match `computed()`.\n *\n * Must run in an injection context.\n *\n * @category common/command\n * @since 0.1.0\n */\nexport function injectCommands(): Signal<readonly CngxCommand[]> {\n // A node resolves its element chain before its environment chain, so a\n // routed component under a shell registry never reaches the route's\n // registry. Read both trees once and join them: environment scopes first.\n const sources = mergeSources(\n inject(EnvironmentInjector).get(CNGX_COMMAND_REGISTRY, null) ?? [],\n inject(CNGX_COMMAND_REGISTRY, { optional: true }) ?? [],\n inject(CNGX_COMMAND_SOURCE, { optional: true }) ?? [],\n );\n return computed(() => dedupeById(sources.flatMap(readSource)), { equal: commandsEqual });\n}\n\n/**\n * @internal Keeps one command per `id`: the last registration (the innermost\n * scope) wins, at the position of the first. A Map keeps a key's insertion slot\n * when its value is replaced.\n */\nfunction dedupeById(commands: readonly CngxCommand[]): readonly CngxCommand[] {\n const byId = new Map<string, CngxCommand>();\n for (const command of commands) {\n byId.set(command.id, command);\n }\n return byId.size === commands.length ? commands : [...byId.values()];\n}\n\n/** @internal Concatenates in argument order and drops repeated source references. */\nfunction mergeSources(...lists: (readonly CngxCommandSource[])[]): readonly CngxCommandSource[] {\n return [...new Set(lists.flat())];\n}\n\n/** @internal Reads a source, unwrapping a signal or passing an array through. */\nfunction readSource(source: CngxCommandSource): readonly CngxCommand[] {\n return typeof source === 'function' ? source() : source;\n}\n\n/**\n * @internal Length + per-command identity. Identity subsumes id equality, so a\n * re-provided set of the same references short-circuits without re-emitting.\n */\nfunction commandsEqual(a: readonly CngxCommand[], b: readonly CngxCommand[]): boolean {\n if (a === b) {\n return true;\n }\n if (a.length !== b.length) {\n return false;\n }\n return a.every((command, i) => command === b[i]);\n}\n","import type { Signal } from '@angular/core';\nimport { foldForMatching } from '@cngx/core/utils';\n\nimport type { CngxCommand } from './command';\n\n/**\n * A command paired with its match score for a given query. Higher scores rank\n * first. The palette renders these in order; the row slot reads `command` and\n * the term to highlight.\n *\n * @category common/command\n * @since 0.1.0\n */\nexport interface CngxRankedCommand {\n /** The matched command. */\n readonly command: CngxCommand;\n /** Relevance score for the query; higher ranks first. `0` for an empty query. */\n readonly score: number;\n}\n\n/**\n * @deprecated Use {@link CngxRankedCommand}. Published under the unprefixed\n * name by mistake; the alias remains for compatibility and will be removed in\n * a future major.\n * @category common/command\n * @since 0.1.0\n */\nexport type RankedCommand = CngxRankedCommand;\n\n/**\n * Ranks and filters a command set against a query and optional scope. Swappable\n * via {@link CNGX_COMMAND_MATCH_FACTORY} - a consumer drops in Levenshtein or a\n * fuzzy engine without touching the panel.\n *\n * @category common/command\n * @since 0.1.0\n */\nexport type CngxCommandMatcher = (\n commands: readonly CngxCommand[],\n term: string,\n scope?: string,\n) => readonly CngxRankedCommand[];\n\n/**\n * Builds the default matcher: a pure label/keyword ranker. An empty query\n * returns every (scoped) command at score `0` in registration order; a\n * non-empty query keeps only commands that match label or keyword, ranked\n * label-exact > label-prefix > label-substring > keyword. The optional scope\n * filters to commands whose `group` equals it.\n *\n * Query, labels and keywords are compared case- and accent-tolerant\n * ({@link foldForMatching}): `uber` finds `Über`. Pass the app locale (the\n * default `CNGX_COMMAND_MATCH_FACTORY` passes `injectLocale()`) so case folds\n * by its rules, e.g. Turkish `I` / `ı`; read inside a `computed()`, a locale\n * switch re-ranks.\n *\n * @category common/command\n * @since 0.1.0\n */\nexport function createDefaultCommandMatcher(locale?: Signal<string>): CngxCommandMatcher {\n // Folded label and keywords per command, re-folded only when the label, the\n // keywords array or the locale changes - not on every keystroke.\n const folded = new WeakMap<CngxCommand, FoldedCommand>();\n const foldedFor = (command: CngxCommand, activeLocale: string | undefined): FoldedCommand => {\n const hit = folded.get(command);\n if (\n hit !== undefined &&\n hit.locale === activeLocale &&\n hit.sourceLabel === command.label &&\n hit.sourceKeywords === command.keywords\n ) {\n return hit;\n }\n const entry: FoldedCommand = {\n locale: activeLocale,\n sourceLabel: command.label,\n sourceKeywords: command.keywords,\n label: foldForMatching(command.label, activeLocale),\n keywords: (command.keywords ?? []).map((keyword) => foldForMatching(keyword, activeLocale)),\n };\n folded.set(command, entry);\n return entry;\n };\n\n return (commands, term, scope) => {\n const scoped = scope ? commands.filter((command) => command.group === scope) : commands;\n const activeLocale = locale?.();\n const query = foldForMatching(term.trim(), activeLocale);\n if (query.length === 0) {\n return scoped.map((command) => ({ command, score: 0 }));\n }\n\n const ranked: CngxRankedCommand[] = [];\n for (const command of scoped) {\n const score = scoreCommand(foldedFor(command, activeLocale), query);\n if (score > 0) {\n ranked.push({ command, score });\n }\n }\n // Stable within equal scores: the sort is stable in V8, so registration\n // order breaks ties.\n ranked.sort((a, b) => b.score - a.score);\n return ranked;\n };\n}\n\n/** @internal A command's label and keywords, folded for one locale. */\ninterface FoldedCommand {\n readonly locale: string | undefined;\n readonly sourceLabel: string;\n readonly sourceKeywords: CngxCommand['keywords'];\n readonly label: string;\n readonly keywords: readonly string[];\n}\n\n/** @internal Scores one folded command against a folded query; `0` means no match. */\nfunction scoreCommand({ label, keywords }: FoldedCommand, query: string): number {\n if (label === query) {\n return 100;\n }\n if (label.startsWith(query)) {\n return 80;\n }\n if (label.includes(query)) {\n return 60;\n }\n for (const value of keywords) {\n if (value === query) {\n return 50;\n }\n if (value.startsWith(query)) {\n return 40;\n }\n if (value.includes(query)) {\n return 20;\n }\n }\n return 0;\n}\n","import { InjectionToken } from '@angular/core';\nimport { injectLocale } from '@cngx/core/utils';\n\nimport { createDefaultCommandMatcher, type CngxCommandMatcher } from './match';\n\n/**\n * Factory producing a {@link CngxCommandMatcher}. The exact signature is\n * captured so an override matches it precisely. The panel calls it in an\n * injection context, so a factory may `inject()` what its matcher needs.\n *\n * @category common/command\n * @since 0.1.0\n */\nexport type CngxCommandMatchFactory = () => CngxCommandMatcher;\n\n/**\n * Swappable match-strategy seam. Defaults to {@link createDefaultCommandMatcher}\n * (pure label/keyword ranking, case- and accent-tolerant in the app locale). Override it - app-wide via `providers` or\n * per-component via `viewProviders` - to drop in a fuzzy/Levenshtein ranker\n * without touching the panel. The fuzzy engine stays a consumer swap; the\n * default bundle ships only the pure ranker.\n *\n * @category common/command\n * @since 0.1.0\n */\nexport const CNGX_COMMAND_MATCH_FACTORY = new InjectionToken<CngxCommandMatchFactory>(\n 'CNGX_COMMAND_MATCH_FACTORY',\n { providedIn: 'root', factory: () => () => createDefaultCommandMatcher(injectLocale()) },\n);\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;AAqBA;;;;;;;;;;;;;;;AAeG;MACU,mBAAmB,GAAG,IAAI,cAAc,CACnD,qBAAqB;AAGvB;;;;AAIG;AACH,MAAM,qBAAqB,GAAG,IAAI,cAAc,CAC9C,uBAAuB,CACxB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BG;AACG,S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M,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;AACxC,QAAA,OAAO,MAAM;AACf,IAAA,CAAC;AACH;AAWA;AACA,SAAS,YAAY,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAiB,EAAE,KAAa,EAAA;AACrE,IAAA,IAAI,KAAK,KAAK,KAAK,EAAE;AACnB,QAAA,OAAO,GAAG;IACZ;AACA,IAAA,IAAI,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;AAC3B,QAAA,OAAO,EAAE;IACX;AACA,IAAA,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;AACzB,QAAA,OAAO,EAAE;IACX;AACA,IAAA,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE;AAC5B,QAAA,IAAI,KAAK,KAAK,KAAK,EAAE;AACnB,YAAA,OAAO,EAAE;QACX;AACA,QAAA,IAAI,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;AAC3B,YAAA,OAAO,EAAE;QACX;AACA,QAAA,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;AACzB,YAAA,OAAO,EAAE;QACX;IACF;AACA,IAAA,OAAO,CAAC;AACV;;AC3HA;;;;;;;;;AASG;AACI,MAAM,0BAA0B,GAAG,IAAI,cAAc,CAC1D,4BAA4B,EAC5B,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,MAAM,2BAA2B,CAAC,YAAY,EAAE,CAAC,EAAE;;AC3B1F;;AAEG;;;;"}
@@ -1,13 +1,13 @@
1
1
  import * as i0 from '@angular/core';
2
- import { input, signal, afterNextRender, computed, output, Directive, inject, TemplateRef, model, contentChild, effect, untracked, ChangeDetectionStrategy, Component, DestroyRef, InjectionToken, Injector, Injectable, makeEnvironmentProviders, ViewContainerRef, ViewEncapsulation, isDevMode, isSignal, ElementRef, Renderer2, runInInjectionContext } from '@angular/core';
2
+ import { input, signal, afterNextRender, computed, output, Directive, inject, TemplateRef, model, contentChild, effect, untracked, ChangeDetectionStrategy, Component, DestroyRef, InjectionToken, Injector, Injectable, makeEnvironmentProviders, ViewContainerRef, ViewEncapsulation, isSignal, ElementRef, Renderer2, runInInjectionContext } from '@angular/core';
3
3
  import { NgTemplateOutlet, DOCUMENT } from '@angular/common';
4
4
  import { CngxChip } from '@cngx/common/display';
5
5
  import { CngxMultiChipGroup, CngxChipInGroup, CngxSearch } from '@cngx/common/interactive';
6
+ import { CngxRuntimeError, cngxDevWarn, arrayEqual, cngxDevError, clamp } from '@cngx/utils';
6
7
  import { takeUntilDestroyed, toObservable } from '@angular/core/rxjs-interop';
7
8
  import { Router, ActivatedRoute } from '@angular/router';
8
9
  import { DataSource } from '@angular/cdk/collections';
9
- import { foldForMatching, memoize, injectLocale, buildAsyncStateView, nextUid, createAggregateAsyncState, CNGX_STATEFUL, createLatencyProbe, numberFormatterFor, createOverrideMerge, createVisibilityGate, createTransitionTracker, createMediaQuerySignal } from '@cngx/core/utils';
10
- import { arrayEqual, clamp } from '@cngx/utils';
10
+ import { foldForMatching, memoize, injectLocale, buildAsyncStateView, CNGX_DEV_DESCRIPTORS, nextUid, createAggregateAsyncState, CNGX_STATEFUL, createLatencyProbe, numberFormatterFor, createOverrideMerge, createVisibilityGate, createTransitionTracker, createMediaQuerySignal, createAnnouncementPhrase } from '@cngx/core/utils';
11
11
  import { isObservable, firstValueFrom, defer, tap, finalize, filter, map } from 'rxjs';
12
12
  import { HttpContextToken, HttpContext, HttpEventType, provideHttpClient, withInterceptors } from '@angular/common/http';
13
13
  import { formatMessage, createLanguageSection, createSectionBundle } from '@cngx/core/i18n';
@@ -564,6 +564,15 @@ class CngxFilterChips {
564
564
  optionLabel = input.required(...(ngDevMode ? [{ debugName: "optionLabel" }] : /* istanbul ignore next */ []));
565
565
  optionValue = input.required(...(ngDevMode ? [{ debugName: "optionValue" }] : /* istanbul ignore next */ []));
566
566
  filterRef = input.required(...(ngDevMode ? [{ debugName: "filterRef" }] : /* istanbul ignore next */ []));
567
+ /**
568
+ * Extracts the comparable value from a filtered list item, when the list
569
+ * is shaped unlike the chip options: role options `{ id, label }` filtering
570
+ * an employee list by `employee.roleId`. Return an array for an item that
571
+ * carries several values (`employee.tags`); it matches when any of them is
572
+ * selected. Unbound, the predicate applies `optionValue` to the list items,
573
+ * which fits a list shaped like the options.
574
+ */
575
+ itemValue = input(undefined, ...(ngDevMode ? [{ debugName: "itemValue" }] : /* istanbul ignore next */ []));
567
576
  filterKey = input.required(...(ngDevMode ? [{ debugName: "filterKey" }] : /* istanbul ignore next */ []));
568
577
  state = input(undefined, ...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
569
578
  /**
@@ -600,14 +609,14 @@ class CngxFilterChips {
600
609
  /**
601
610
  * Build the slot context for a given chip option. `optionValue` is
602
611
  * invoked here per option for the chip rendering pass; the predicate
603
- * closure invokes it again per LIST item for membership filtering.
604
- * Both invocations are necessary because option items (the chip
605
- * pool) and filtered list items (the consumer's filtered data) are
606
- * separate data paths - they happen to share a shape under the
607
- * Phase-5 single-shape limitation, but the bridge cannot memoise
608
- * across the two paths without conflating them. Consumers should
609
- * keep `optionValue` cheap (typically a property lookup); a future
610
- * `[itemValue]` input will separate the two extractors.
612
+ * closure invokes it again per LIST item for membership filtering
613
+ * while `[itemValue]` is unbound. Both invocations are necessary
614
+ * because option items (the chip pool) and filtered list items (the
615
+ * consumer's filtered data) are separate data paths - they share a
616
+ * shape only when `[itemValue]` is unbound, and the bridge cannot
617
+ * memoise across the two paths without conflating them. Consumers
618
+ * should keep `optionValue` cheap (typically a property lookup); bind
619
+ * `[itemValue]` when the list is shaped unlike the options.
611
620
  */
612
621
  chipContext = (option) => {
613
622
  const value = this.optionValue()(option);
@@ -633,8 +642,11 @@ class CngxFilterChips {
633
642
  return true;
634
643
  }
635
644
  const extract = this.keyFn();
636
- const key = extract(this.optionValue()(item));
637
- return values.some((v) => Object.is(extract(v), key));
645
+ const keys = this.itemKeys(item, extract);
646
+ return values.some((v) => {
647
+ const selected = extract(v);
648
+ return keys.some((key) => Object.is(selected, key));
649
+ });
638
650
  };
639
651
  // Binding effect: tracks only filterRef/filterKey, so a rebind moves the
640
652
  // registration. Cleanup is identity-guarded - it removes the key only
@@ -674,8 +686,21 @@ class CngxFilterChips {
674
686
  }
675
687
  });
676
688
  }
689
+ itemKeys(item, extract) {
690
+ const itemValue = this.itemValue();
691
+ if (!itemValue) {
692
+ // Without [itemValue] the list is shaped like the options (the
693
+ // `TListItem = TItem` default), and an array-valued option stays one value.
694
+ const optionValue = this.optionValue();
695
+ return [extract(optionValue(item))];
696
+ }
697
+ const values = itemValue(item);
698
+ return Array.isArray(values)
699
+ ? values.map(extract)
700
+ : [extract(values)];
701
+ }
677
702
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxFilterChips, deps: [], target: i0.ɵɵFactoryTarget.Component });
678
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.4", type: CngxFilterChips, isStandalone: true, selector: "cngx-filter-chips", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: true, transformFunction: null }, options: { classPropertyName: "options", publicName: "options", isSignal: true, isRequired: true, transformFunction: null }, optionLabel: { classPropertyName: "optionLabel", publicName: "optionLabel", isSignal: true, isRequired: true, transformFunction: null }, optionValue: { classPropertyName: "optionValue", publicName: "optionValue", isSignal: true, isRequired: true, transformFunction: null }, filterRef: { classPropertyName: "filterRef", publicName: "filterRef", isSignal: true, isRequired: true, transformFunction: null }, filterKey: { classPropertyName: "filterKey", publicName: "filterKey", isSignal: true, isRequired: true, transformFunction: null }, state: { classPropertyName: "state", publicName: "state", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, invalid: { classPropertyName: "invalid", publicName: "invalid", isSignal: true, isRequired: false, transformFunction: null }, errorMessageId: { classPropertyName: "errorMessageId", publicName: "errorMessageId", isSignal: true, isRequired: false, transformFunction: null }, orientation: { classPropertyName: "orientation", publicName: "orientation", isSignal: true, isRequired: false, transformFunction: null }, keyFn: { classPropertyName: "keyFn", publicName: "keyFn", isSignal: true, isRequired: false, transformFunction: null }, selectedValues: { classPropertyName: "selectedValues", publicName: "selectedValues", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { disabled: "disabledChange", required: "requiredChange", invalid: "invalidChange", selectedValues: "selectedValuesChange" }, host: { properties: { "class.cngx-filter-chips--vertical": "orientation() === \"vertical\"" }, classAttribute: "cngx-filter-chips" }, queries: [{ propertyName: "chipTemplate", first: true, predicate: (CngxFilterChip), descendants: true, isSignal: true }], exportAs: ["cngxFilterChips"], ngImport: i0, template: `
703
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.4", type: CngxFilterChips, isStandalone: true, selector: "cngx-filter-chips", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: true, transformFunction: null }, options: { classPropertyName: "options", publicName: "options", isSignal: true, isRequired: true, transformFunction: null }, optionLabel: { classPropertyName: "optionLabel", publicName: "optionLabel", isSignal: true, isRequired: true, transformFunction: null }, optionValue: { classPropertyName: "optionValue", publicName: "optionValue", isSignal: true, isRequired: true, transformFunction: null }, filterRef: { classPropertyName: "filterRef", publicName: "filterRef", isSignal: true, isRequired: true, transformFunction: null }, itemValue: { classPropertyName: "itemValue", publicName: "itemValue", isSignal: true, isRequired: false, transformFunction: null }, filterKey: { classPropertyName: "filterKey", publicName: "filterKey", isSignal: true, isRequired: true, transformFunction: null }, state: { classPropertyName: "state", publicName: "state", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, invalid: { classPropertyName: "invalid", publicName: "invalid", isSignal: true, isRequired: false, transformFunction: null }, errorMessageId: { classPropertyName: "errorMessageId", publicName: "errorMessageId", isSignal: true, isRequired: false, transformFunction: null }, orientation: { classPropertyName: "orientation", publicName: "orientation", isSignal: true, isRequired: false, transformFunction: null }, keyFn: { classPropertyName: "keyFn", publicName: "keyFn", isSignal: true, isRequired: false, transformFunction: null }, selectedValues: { classPropertyName: "selectedValues", publicName: "selectedValues", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { disabled: "disabledChange", required: "requiredChange", invalid: "invalidChange", selectedValues: "selectedValuesChange" }, host: { properties: { "class.cngx-filter-chips--vertical": "orientation() === \"vertical\"" }, classAttribute: "cngx-filter-chips" }, queries: [{ propertyName: "chipTemplate", first: true, predicate: (CngxFilterChip), descendants: true, isSignal: true }], exportAs: ["cngxFilterChips"], ngImport: i0, template: `
679
704
  <span class="cngx-filter-chips__label" aria-hidden="true">{{ label() }}</span>
680
705
  <cngx-multi-chip-group
681
706
  [label]="label()"
@@ -729,7 +754,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
729
754
  }
730
755
  </cngx-multi-chip-group>
731
756
  `, styles: [":host{display:flex;flex-direction:row;align-items:center;--cngx-filter-chips-gap: var(--cngx-space-sm, 8px);gap:var(--cngx-filter-chips-gap, 8px)}:host(.cngx-filter-chips--vertical){flex-direction:column;align-items:flex-start}.cngx-filter-chips__label{color:var(--cngx-filter-chips-label-color, inherit);font-size:var(--cngx-filter-chips-label-font-size, .8125rem);font-weight:var(--cngx-filter-chips-label-font-weight, 600)}\n"] }]
732
- }], ctorParameters: () => [], propDecorators: { label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: true }] }], options: [{ type: i0.Input, args: [{ isSignal: true, alias: "options", required: true }] }], optionLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "optionLabel", required: true }] }], optionValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "optionValue", required: true }] }], filterRef: [{ type: i0.Input, args: [{ isSignal: true, alias: "filterRef", required: true }] }], filterKey: [{ type: i0.Input, args: [{ isSignal: true, alias: "filterKey", required: true }] }], state: [{ type: i0.Input, args: [{ isSignal: true, alias: "state", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }, { type: i0.Output, args: ["disabledChange"] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }, { type: i0.Output, args: ["requiredChange"] }], invalid: [{ type: i0.Input, args: [{ isSignal: true, alias: "invalid", required: false }] }, { type: i0.Output, args: ["invalidChange"] }], errorMessageId: [{ type: i0.Input, args: [{ isSignal: true, alias: "errorMessageId", required: false }] }], orientation: [{ type: i0.Input, args: [{ isSignal: true, alias: "orientation", required: false }] }], keyFn: [{ type: i0.Input, args: [{ isSignal: true, alias: "keyFn", required: false }] }], chipTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => CngxFilterChip), { isSignal: true }] }], selectedValues: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectedValues", required: false }] }, { type: i0.Output, args: ["selectedValuesChange"] }] } });
757
+ }], ctorParameters: () => [], propDecorators: { label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: true }] }], options: [{ type: i0.Input, args: [{ isSignal: true, alias: "options", required: true }] }], optionLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "optionLabel", required: true }] }], optionValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "optionValue", required: true }] }], filterRef: [{ type: i0.Input, args: [{ isSignal: true, alias: "filterRef", required: true }] }], itemValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "itemValue", required: false }] }], filterKey: [{ type: i0.Input, args: [{ isSignal: true, alias: "filterKey", required: true }] }], state: [{ type: i0.Input, args: [{ isSignal: true, alias: "state", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }, { type: i0.Output, args: ["disabledChange"] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }, { type: i0.Output, args: ["requiredChange"] }], invalid: [{ type: i0.Input, args: [{ isSignal: true, alias: "invalid", required: false }] }, { type: i0.Output, args: ["invalidChange"] }], errorMessageId: [{ type: i0.Input, args: [{ isSignal: true, alias: "errorMessageId", required: false }] }], orientation: [{ type: i0.Input, args: [{ isSignal: true, alias: "orientation", required: false }] }], keyFn: [{ type: i0.Input, args: [{ isSignal: true, alias: "keyFn", required: false }] }], chipTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => CngxFilterChip), { isSignal: true }] }], selectedValues: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectedValues", required: false }] }, { type: i0.Output, args: ["selectedValuesChange"] }] } });
733
758
 
734
759
  /**
735
760
  * Atom directive that tracks pagination state (current page index and page size).
@@ -892,6 +917,24 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
892
917
  }]
893
918
  }], propDecorators: { pageIndexInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxPageIndex", required: false }] }], pageSizeInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxPageSize", required: false }] }], total: [{ type: i0.Input, args: [{ isSignal: true, alias: "total", required: false }] }], state: [{ type: i0.Input, args: [{ isSignal: true, alias: "state", required: false }] }], pageChange: [{ type: i0.Output, args: ["pageChange"] }], pageSizeChange: [{ type: i0.Output, args: ["pageSizeChange"] }] } });
894
919
 
920
+ /**
921
+ * Inject the surrounding {@link CngxPaginate} from a paginate add-on
922
+ * directive. Throws a `CngxRuntimeError` with code `CNGX1063` when no
923
+ * `[cngxPaginate]` is on the element or above it, in development and
924
+ * production alike. `selector` names the add-on in the development message.
925
+ *
926
+ * @internal
927
+ */
928
+ function injectPaginate(selector) {
929
+ const paginate = inject(CngxPaginate, { optional: true });
930
+ if (!paginate) {
931
+ throw new CngxRuntimeError('CNGX1063', typeof ngDevMode !== 'undefined' &&
932
+ ngDevMode &&
933
+ `[${selector}] must be placed on or inside an element with [cngxPaginate], such as <cngx-paginator>.`);
934
+ }
935
+ return paginate;
936
+ }
937
+
895
938
  /**
896
939
  * Wires the reset-on-change behaviour onto a {@link CngxPaginate} brain: when
897
940
  * `key()` changes (after the initial run) the paginator jumps to the first
@@ -945,7 +988,7 @@ function connectPaginateResetOn(paginate, key) {
945
988
  * @relatedTo CngxPaginate, CngxPaginator, CngxMatPaginator
946
989
  */
947
990
  class CngxPaginateResetOn {
948
- paginate = inject(CngxPaginate);
991
+ paginate = injectPaginate('cngxPaginateResetOn');
949
992
  /** The reset key. A change (after mount) jumps the paginator to page 0. */
950
993
  key = input(undefined, { ...(ngDevMode ? { debugName: "key" } : /* istanbul ignore next */ {}), alias: 'cngxPaginateResetOn' });
951
994
  constructor() {
@@ -1072,7 +1115,7 @@ function connectPaginateEmit(paginate, handlers) {
1072
1115
  * <example-url>http://localhost:4200/#/ui/paginator/paginator-behaviors/url-synced-paging</example-url>
1073
1116
  */
1074
1117
  class CngxPaginateRouting {
1075
- paginate = inject(CngxPaginate);
1118
+ paginate = injectPaginate('cngxPaginateRouting');
1076
1119
  router = inject(Router, { optional: true });
1077
1120
  route = inject(ActivatedRoute, { optional: true });
1078
1121
  destroyRef = inject(DestroyRef);
@@ -1097,7 +1140,7 @@ class CngxPaginateRouting {
1097
1140
  const route = this.route;
1098
1141
  if (!router || !route) {
1099
1142
  if (typeof ngDevMode !== 'undefined' && ngDevMode) {
1100
- console.warn('[cngxPaginateRouting]: no Router available - directive is a no-op. ' +
1143
+ cngxDevWarn('CNGX1031', '[cngxPaginateRouting] no Router / ActivatedRoute available - the URL sync is a no-op. ' +
1101
1144
  'Provide @angular/router via provideRouter(...) to enable URL-synced pagination.');
1102
1145
  }
1103
1146
  return;
@@ -1640,10 +1683,12 @@ function createManualState() {
1640
1683
  data: dataState.asReadonly(),
1641
1684
  error: errorState.asReadonly(),
1642
1685
  progress: progressState.asReadonly(),
1643
- isFirstLoad: computed(() => !hadSuccess()),
1686
+ isFirstLoad: computed(() => !hadSuccess(), typeof ngDevMode !== 'undefined' && ngDevMode
1687
+ ? { debugName: 'manualState.isFirstLoad' }
1688
+ : undefined),
1644
1689
  lastUpdated: lastUpdatedState.asReadonly(),
1645
1690
  });
1646
- return {
1691
+ const state = {
1647
1692
  ...view,
1648
1693
  set(newStatus) {
1649
1694
  statusState.set(newStatus);
@@ -1669,6 +1714,11 @@ function createManualState() {
1669
1714
  progressState.set(undefined);
1670
1715
  statusState.set('error');
1671
1716
  },
1717
+ setIdle() {
1718
+ errorState.set(undefined);
1719
+ progressState.set(undefined);
1720
+ statusState.set('idle');
1721
+ },
1672
1722
  setProgress(value) {
1673
1723
  progressState.set(value);
1674
1724
  },
@@ -1681,6 +1731,14 @@ function createManualState() {
1681
1731
  hadSuccess.set(false);
1682
1732
  },
1683
1733
  };
1734
+ if (typeof ngDevMode !== 'undefined' && ngDevMode) {
1735
+ CNGX_DEV_DESCRIPTORS.tag(state, {
1736
+ kind: 'cngx-dev:factory',
1737
+ factory: 'createManualState',
1738
+ inputs: {},
1739
+ });
1740
+ }
1741
+ return state;
1684
1742
  }
1685
1743
 
1686
1744
  /** @internal Length-then-key-set equality for the operations Map signal. */
@@ -1853,7 +1911,7 @@ function createAsyncState(options) {
1853
1911
  destroyRef.onDestroy(() => registry.unregister(operationId));
1854
1912
  }
1855
1913
  }
1856
- return {
1914
+ const mutation = {
1857
1915
  status: state.status,
1858
1916
  data: state.data,
1859
1917
  error: state.error,
@@ -1902,6 +1960,17 @@ function createAsyncState(options) {
1902
1960
  state.reset();
1903
1961
  },
1904
1962
  };
1963
+ if (typeof ngDevMode !== 'undefined' && ngDevMode) {
1964
+ CNGX_DEV_DESCRIPTORS.tag(mutation, {
1965
+ kind: 'cngx-dev:factory',
1966
+ factory: 'createAsyncState',
1967
+ // The inner manual state carries its own tag; listing it here is the
1968
+ // only way an inspector reaches it, since the mutation exposes its
1969
+ // signals, not the state object.
1970
+ inputs: { options, state },
1971
+ });
1972
+ }
1973
+ return mutation;
1905
1974
  }
1906
1975
 
1907
1976
  /**
@@ -2278,7 +2347,10 @@ function fromResource(ref) {
2278
2347
  * Bridge that projects an Angular `httpResource()` ref onto `CngxAsyncState<T>`.
2279
2348
  *
2280
2349
  * Identical to `fromResource` but additionally maps the HTTP progress
2281
- * signal to `CngxAsyncState.progress` (0–100 scale).
2350
+ * signal to `CngxAsyncState.progress` (0-100 scale): `loaded / total`,
2351
+ * rounded and clamped. With an unknown or zero `total` the progress is
2352
+ * `undefined` (indeterminate). Angular only emits progress events when the
2353
+ * request sets `reportProgress: true`.
2282
2354
  *
2283
2355
  * Must be called in an injection context.
2284
2356
  *
@@ -2286,23 +2358,24 @@ function fromResource(ref) {
2286
2358
  * private readonly res = httpResource<Item[]>(() => ({
2287
2359
  * url: '/api/items',
2288
2360
  * params: { q: this.filter() },
2361
+ * reportProgress: true,
2289
2362
  * }));
2290
2363
  *
2291
2364
  * readonly items = fromHttpResource(this.res);
2292
- * // items.progress() tracks upload/download progress
2365
+ * // items.progress() tracks download progress 0-100
2293
2366
  * // <cngx-progress [state]="items"> - auto-wired progress bar
2294
2367
  * ```
2295
2368
  *
2296
2369
  * @category common/data/async-state
2297
2370
  */
2298
2371
  function fromHttpResource(ref) {
2299
- // Map HTTP progress (0-1 float) to 0-100 integer, clamped.
2372
+ // Map loaded/total bytes to a 0-100 integer, clamped; no total = indeterminate.
2300
2373
  const progress = computed(() => {
2301
- const p = ref.progress();
2302
- if (p == null) {
2374
+ const event = ref.progress();
2375
+ if (event?.total == null || event.total <= 0) {
2303
2376
  return undefined;
2304
2377
  }
2305
- return Math.round(Math.min(p, 1) * 100);
2378
+ return Math.round(Math.min(event.loaded / event.total, 1) * 100);
2306
2379
  }, ...(ngDevMode ? [{ debugName: "progress" }] : /* istanbul ignore next */ []));
2307
2380
  return buildResourceBridge(ref, progress);
2308
2381
  }
@@ -2405,7 +2478,8 @@ function tapAsyncProgress(state) {
2405
2478
  * 5. Call `setError(err)` on error
2406
2479
  *
2407
2480
  * The output Observable emits the **response body** (not HttpEvents).
2408
- * Throws if the response body is `null`.
2481
+ * Throws a `CngxRuntimeError` with code `CNGX1054` if the response body is
2482
+ * `null`; the sink receives it through `setError(err)`.
2409
2483
  *
2410
2484
  * ```typescript
2411
2485
  * readonly upload = createManualState<UploadResult>();
@@ -2432,7 +2506,9 @@ function tapHttpAsyncState(state, options) {
2432
2506
  return event.type === RESPONSE;
2433
2507
  }), map((response) => {
2434
2508
  if (response.body == null) {
2435
- throw new Error('tapHttpAsyncState: response body is null');
2509
+ throw new CngxRuntimeError('CNGX1054', typeof ngDevMode !== 'undefined' &&
2510
+ ngDevMode &&
2511
+ 'tapHttpAsyncState(): response body is null');
2436
2512
  }
2437
2513
  return response.body;
2438
2514
  }), tap({
@@ -3782,8 +3858,12 @@ function createScrollObserver(elementRef, destroyRef) {
3782
3858
  if (typeof elementRef !== 'string' || typeof MutationObserver === 'undefined') {
3783
3859
  return;
3784
3860
  }
3785
- if (isDevMode()) {
3786
- console.warn(`recycler scrollElement '${elementRef}' not found on first render; ` +
3861
+ // Mounted between the first effect run and now: the bump above attaches it.
3862
+ if (resolveElement(elementRef, doc) != null) {
3863
+ return;
3864
+ }
3865
+ if (typeof ngDevMode !== 'undefined' && ngDevMode) {
3866
+ cngxDevWarn('CNGX1013', `injectRecycler(): scrollElement '${elementRef}' not found on first render; ` +
3787
3867
  'it will attach automatically once it mounts. If it never does, check the selector.');
3788
3868
  }
3789
3869
  mutationObserver = new MutationObserver(() => {
@@ -3960,8 +4040,8 @@ function injectRecycler(config) {
3960
4040
  const i18n = recyclerBundle.resolve(inject(CNGX_RECYCLER_I18N));
3961
4041
  const overscan = config.overscan ?? 5;
3962
4042
  const isGrid = (config.layout ?? 'list') === 'grid';
3963
- if (isGrid && config.columns == null && isDevMode()) {
3964
- console.error('[CngxRecycler] layout: "grid" requires explicit `columns`. Falling back to columns=1.');
4043
+ if (typeof ngDevMode !== 'undefined' && ngDevMode && isGrid && config.columns == null) {
4044
+ cngxDevError('CNGX1011', 'injectRecycler(): layout: "grid" requires explicit `columns`. Falling back to columns=1.');
3965
4045
  }
3966
4046
  // Reactive columns - reactive only if the function reads a Signal internally
3967
4047
  const columns = computed(() => {
@@ -3974,10 +4054,13 @@ function injectRecycler(config) {
3974
4054
  // per-index measurement - it carries no O(n) per-frame cost, so exclude it
3975
4055
  // from the variable-height warning (a reactive scalar estimate is a
3976
4056
  // sanctioned pattern; see the resolveSize note below).
3977
- if (typeof config.estimateSize === 'function' && !isSignal(config.estimateSize) && isDevMode()) {
4057
+ if (typeof ngDevMode !== 'undefined' &&
4058
+ ngDevMode &&
4059
+ typeof config.estimateSize === 'function' &&
4060
+ !isSignal(config.estimateSize)) {
3978
4061
  const count = config.totalCount();
3979
4062
  if (count > 10_000) {
3980
- console.warn(`[CngxRecycler] estimateSize as a function with ${count} items has O(n) ` +
4063
+ cngxDevWarn('CNGX1012', `injectRecycler(): estimateSize as a function with ${count} items has O(n) ` +
3981
4064
  `per-frame cost. Consider using a fixed estimateSize for large datasets.`);
3982
4065
  }
3983
4066
  }
@@ -5041,7 +5124,9 @@ function createCommitController() {
5041
5124
  const intendedState = signal(undefined, ...(ngDevMode ? [{ debugName: "intendedState" }] : /* istanbul ignore next */ []));
5042
5125
  return {
5043
5126
  state: slot,
5044
- isCommitting: computed(() => slot.isPending()),
5127
+ isCommitting: computed(() => slot.isPending(), typeof ngDevMode !== 'undefined' && ngDevMode
5128
+ ? { debugName: 'commitController.isCommitting' }
5129
+ : undefined),
5045
5130
  intendedValue: intendedState.asReadonly(),
5046
5131
  begin(runner, intended, previous, handlers) {
5047
5132
  // bump commitId BEFORE tearing down the previous runner: a runner that
@@ -5075,6 +5160,16 @@ function createCommitController() {
5075
5160
  active = null;
5076
5161
  handlers.onError(err, previous);
5077
5162
  },
5163
+ onRefused: () => {
5164
+ if (id !== commitId) {
5165
+ return;
5166
+ }
5167
+ settled = true;
5168
+ slot.setIdle();
5169
+ intendedState.set(undefined);
5170
+ active = null;
5171
+ handlers.onRefused?.(previous);
5172
+ },
5078
5173
  });
5079
5174
  active = settled ? null : handle;
5080
5175
  },
@@ -5094,6 +5189,59 @@ function createCommitController() {
5094
5189
  };
5095
5190
  }
5096
5191
 
5192
+ /**
5193
+ * Live-region phrase for a refused commit-gated transition (a step
5194
+ * change or tab switch whose `commitAction` answered `false`).
5195
+ *
5196
+ * A refusal settles the commit status back to `'idle'`, so no status
5197
+ * edge can voice it. This phrase arms on each new refused outcome (a new
5198
+ * `sequence`) and is spent by the next commit status change, an
5199
+ * active-index move, a cleared outcome or, when given, a changed
5200
+ * `extraSpend` value. A failed outcome never arms it. Arm wins over
5201
+ * spend in the same flush, so an optimistic rollback that moves the
5202
+ * active index still voices the refusal.
5203
+ *
5204
+ * Built on {@link createAnnouncementPhrase}: fully derived, no `effect`.
5205
+ * The same eager-read caveat applies - read the phrase before branching
5206
+ * on another arm of the live announcement, otherwise a spend transition
5207
+ * can be skipped.
5208
+ *
5209
+ * ```ts
5210
+ * const refusedPhrase = createRefusedPhrase({
5211
+ * outcome: () => presenter.lastOutcome(),
5212
+ * status: () => presenter.commitTransition.current(),
5213
+ * activeIndex: () => presenter.activeIndex(),
5214
+ * copy: () => i18n().commitRefusedGeneric,
5215
+ * });
5216
+ * ```
5217
+ *
5218
+ * @category common/data/commit
5219
+ * @wcag AA
5220
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/data/commit/refused-phrase.ts
5221
+ * @since 0.1.0
5222
+ * @relatedTo CngxTransitionOutcome, createAnnouncementPhrase
5223
+ */
5224
+ function createRefusedPhrase(options) {
5225
+ const { outcome, status, activeIndex, copy, extraSpend } = options;
5226
+ return createAnnouncementPhrase({
5227
+ source: () => {
5228
+ const current = outcome();
5229
+ return {
5230
+ sequence: current?.sequence,
5231
+ kind: current?.kind,
5232
+ status: status(),
5233
+ activeIndex: activeIndex(),
5234
+ extra: extraSpend?.(),
5235
+ };
5236
+ },
5237
+ arm: (curr, prev) => curr.kind === 'refused' && curr.sequence !== prev.sequence ? untracked(copy) : null,
5238
+ spend: (curr, prev) => curr.status !== prev.status ||
5239
+ curr.activeIndex !== prev.activeIndex ||
5240
+ curr.sequence === undefined ||
5241
+ curr.extra !== prev.extra,
5242
+ });
5243
+ }
5244
+
5097
5245
  /**
5098
5246
  * DI token carrying the factory that every cngx feature uses to
5099
5247
  * allocate its commit controller. Default `providedIn: 'root'`
@@ -5245,5 +5393,5 @@ function createMaterialBidirectionalSync(opts) {
5245
5393
  * Generated bundle index. Do not edit.
5246
5394
  */
5247
5395
 
5248
- export { CNGX_ASYNC_LABEL, CNGX_ASYNC_SKIP, CNGX_BUCKET_PAGINATE_HOST, CNGX_COMMIT_CONTROLLER_FACTORY, CNGX_KPI_I18N, CNGX_KPI_LANGUAGE_EN, CNGX_RECYCLER_I18N, CNGX_RECYCLER_LANGUAGE_EN, CNGX_RECYCLER_PLACEHOLDER_ROW, CNGX_STAT, CngxAsync, CngxAsyncBoundary, CngxAsyncRegistry, CngxBucketPaginate, CngxDataSource, CngxDelta, CngxFilter, CngxFilterChip, CngxFilterChips, CngxGoal, CngxMeasure, CngxMetric, CngxPaginate, CngxPaginateResetOn, CngxPaginateRouting, CngxRecyclerAnnouncer, CngxRecyclerPlaceholder, CngxRecyclerRow, CngxSmartDataSource, CngxSort, CngxSortHeader, CngxStat, CngxStatCaption, CngxStatCoordinator, CngxStatDelta, CngxStatLabel, CngxStatValue, CngxTrend, CngxVirtualItem, cngxAsyncInterceptor, connectPaginateEmit, connectPaginateResetOn, connectRecyclerToActiveDescendant, connectRecyclerToRoving, createAsyncState, createCommitController, createForwardedAsyncState, createManualState, createMaterialBidirectionalSync, createSortHeaderState, fromHttpResource, fromResource, injectAsyncRegistry, injectAsyncState, injectDataSource, injectKpiI18n, injectLatencyProbe, injectRecycler, injectSmartDataSource, provideAsyncHttpObservability, provideAsyncRegistry, provideKpiI18n, provideRecyclerI18n, provideRecyclerPlaceholderRow, resolveAsyncView, tapAsyncProgress, tapAsyncState, tapHttpAsyncState, withAsyncLabel, withAsyncSkip, withKpiI18nLabels, withRecyclerI18nLabels };
5396
+ export { CNGX_ASYNC_LABEL, CNGX_ASYNC_SKIP, CNGX_BUCKET_PAGINATE_HOST, CNGX_COMMIT_CONTROLLER_FACTORY, CNGX_KPI_I18N, CNGX_KPI_LANGUAGE_EN, CNGX_RECYCLER_I18N, CNGX_RECYCLER_LANGUAGE_EN, CNGX_RECYCLER_PLACEHOLDER_ROW, CNGX_STAT, CngxAsync, CngxAsyncBoundary, CngxAsyncRegistry, CngxBucketPaginate, CngxDataSource, CngxDelta, CngxFilter, CngxFilterChip, CngxFilterChips, CngxGoal, CngxMeasure, CngxMetric, CngxPaginate, CngxPaginateResetOn, CngxPaginateRouting, CngxRecyclerAnnouncer, CngxRecyclerPlaceholder, CngxRecyclerRow, CngxSmartDataSource, CngxSort, CngxSortHeader, CngxStat, CngxStatCaption, CngxStatCoordinator, CngxStatDelta, CngxStatLabel, CngxStatValue, CngxTrend, CngxVirtualItem, cngxAsyncInterceptor, connectPaginateEmit, connectPaginateResetOn, connectRecyclerToActiveDescendant, connectRecyclerToRoving, createAsyncState, createCommitController, createForwardedAsyncState, createManualState, createMaterialBidirectionalSync, createRefusedPhrase, createSortHeaderState, fromHttpResource, fromResource, injectAsyncRegistry, injectAsyncState, injectDataSource, injectKpiI18n, injectLatencyProbe, injectRecycler, injectSmartDataSource, provideAsyncHttpObservability, provideAsyncRegistry, provideKpiI18n, provideRecyclerI18n, provideRecyclerPlaceholderRow, resolveAsyncView, tapAsyncProgress, tapAsyncState, tapHttpAsyncState, withAsyncLabel, withAsyncSkip, withKpiI18nLabels, withRecyclerI18nLabels };
5249
5397
  //# sourceMappingURL=cngx-common-data.mjs.map