@spartan-ng/brain 1.3.4 → 1.4.0-beta.2

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.
@@ -0,0 +1,1558 @@
1
+ import * as i0 from '@angular/core';
2
+ import { InjectionToken, inject, ElementRef, input, model, booleanAttribute, signal, computed, afterNextRender, effect, Directive, output, forwardRef, untracked } from '@angular/core';
3
+ import { brnDevMode } from '@spartan-ng/brain/core';
4
+ import { NG_VALUE_ACCESSOR } from '@angular/forms';
5
+
6
+ function hasInputValue(value) {
7
+ if (Array.isArray(value)) {
8
+ return value.some((item) => String(item).trim().length > 0);
9
+ }
10
+ return value !== undefined && value !== null && String(value).trim().length > 0;
11
+ }
12
+ function getShortcutKeys(shortcuts) {
13
+ if (shortcuts === 'letters') {
14
+ return Array.from({ length: 26 }, (_, index) => String.fromCharCode(65 + index));
15
+ }
16
+ if (shortcuts === 'numbers') {
17
+ return Array.from({ length: 9 }, (_, index) => String(index + 1));
18
+ }
19
+ return [];
20
+ }
21
+ function getShortcutFromKey(key, shortcuts) {
22
+ const normalizedKey = shortcuts === 'letters' ? key.toUpperCase() : key;
23
+ return getShortcutKeys(shortcuts).includes(normalizedKey) ? normalizedKey : null;
24
+ }
25
+ function getAnswerKeyShortcuts(shortcut, filled) {
26
+ return [shortcut, filled ? 'Enter' : null].filter(Boolean).join(' ') || undefined;
27
+ }
28
+ function isAnswerFilled(answer) {
29
+ if (answer.type === 'choice') {
30
+ return answer.element.checked;
31
+ }
32
+ return answer.element.hasAttribute('name') && hasInputValue(answer.element.value);
33
+ }
34
+ function isEmptyNavigableInput(answer) {
35
+ return (answer?.type === 'input' &&
36
+ ['email', 'password', 'search', 'tel', 'text', 'url'].includes(answer.element.type) &&
37
+ !hasInputValue(answer.element.value));
38
+ }
39
+ function isTextEntryTarget(element) {
40
+ if (element instanceof HTMLTextAreaElement || element instanceof HTMLSelectElement) {
41
+ return true;
42
+ }
43
+ if (element instanceof HTMLInputElement) {
44
+ return !['button', 'checkbox', 'radio', 'reset', 'submit'].includes(element.type);
45
+ }
46
+ return element instanceof HTMLElement && element.isContentEditable;
47
+ }
48
+ function isRadioTarget(element) {
49
+ return element instanceof HTMLInputElement && element.type === 'radio';
50
+ }
51
+ function compareItemOrder(firstItem, secondItem) {
52
+ if (firstItem.element === secondItem.element) {
53
+ return 0;
54
+ }
55
+ const position = firstItem.element.compareDocumentPosition(secondItem.element);
56
+ if (position & Node.DOCUMENT_POSITION_FOLLOWING) {
57
+ return -1;
58
+ }
59
+ if (position & Node.DOCUMENT_POSITION_PRECEDING) {
60
+ return 1;
61
+ }
62
+ return 0;
63
+ }
64
+ function compareAnswerOrder(firstAnswer, secondAnswer) {
65
+ if (firstAnswer.element === secondAnswer.element) {
66
+ return 0;
67
+ }
68
+ const position = firstAnswer.element.compareDocumentPosition(secondAnswer.element);
69
+ if (position & Node.DOCUMENT_POSITION_FOLLOWING) {
70
+ return -1;
71
+ }
72
+ if (position & Node.DOCUMENT_POSITION_PRECEDING) {
73
+ return 1;
74
+ }
75
+ return 0;
76
+ }
77
+
78
+ function createQuestionnaireCollection(items) {
79
+ if (items === undefined) {
80
+ return null;
81
+ }
82
+ return {
83
+ enabledItems: items.filter((item) => !item.disabled),
84
+ itemByName: new Map(items.map((item) => [item.name, item])),
85
+ items,
86
+ };
87
+ }
88
+ function getInitialItemName(collection, defaultItem) {
89
+ if (!collection) {
90
+ return defaultItem ?? null;
91
+ }
92
+ const defaultDefinition = defaultItem ? collection.itemByName.get(defaultItem) : undefined;
93
+ if (defaultDefinition && !defaultDefinition.disabled) {
94
+ return defaultDefinition.name;
95
+ }
96
+ return collection.enabledItems[0]?.name ?? null;
97
+ }
98
+ function getShortcutByChoiceValue(item, shortcuts) {
99
+ const shortcutByChoiceValue = new Map();
100
+ if (!item || !shortcuts) {
101
+ return shortcutByChoiceValue;
102
+ }
103
+ const keys = getShortcutKeys(shortcuts);
104
+ let shortcutIndex = 0;
105
+ for (const choice of item.choices ?? []) {
106
+ if (choice.disabled) {
107
+ continue;
108
+ }
109
+ const shortcut = keys[shortcutIndex];
110
+ if (!shortcut) {
111
+ break;
112
+ }
113
+ shortcutByChoiceValue.set(choice.value, shortcut);
114
+ shortcutIndex += 1;
115
+ }
116
+ return shortcutByChoiceValue;
117
+ }
118
+ function getCollectionDefinitionWarnings(collection, defaultItem) {
119
+ const warnings = [];
120
+ const itemNames = new Set();
121
+ for (const item of collection.items) {
122
+ if (itemNames.has(item.name)) {
123
+ warnings.push(`Item name "${item.name}" is defined more than once.`);
124
+ }
125
+ itemNames.add(item.name);
126
+ const choiceValues = new Set();
127
+ for (const choice of item.choices ?? []) {
128
+ if (choiceValues.has(choice.value)) {
129
+ warnings.push(`Choice value "${choice.value}" is defined more than once in item "${item.name}".`);
130
+ }
131
+ choiceValues.add(choice.value);
132
+ }
133
+ }
134
+ if (defaultItem) {
135
+ const defaultDefinition = collection.itemByName.get(defaultItem);
136
+ if (!defaultDefinition || defaultDefinition.disabled) {
137
+ warnings.push(`defaultItem "${defaultItem}" does not identify an enabled item. The first enabled item will be used instead.`);
138
+ }
139
+ }
140
+ return warnings;
141
+ }
142
+ function getCollectionRegistrationWarnings(collection, registrations, shortcuts) {
143
+ const warnings = [];
144
+ const registrationByName = new Map(registrations.map((registration) => [registration.name, registration]));
145
+ for (const definition of collection.items) {
146
+ const registration = registrationByName.get(definition.name);
147
+ if (!registration) {
148
+ if (!definition.disabled) {
149
+ warnings.push(`Item "${definition.name}" is defined but has no rendered Questionnaire.Item.`);
150
+ }
151
+ continue;
152
+ }
153
+ if (registration.disabled !== Boolean(definition.disabled)) {
154
+ warnings.push(`Item "${definition.name}" has different disabled values in Root.items and Questionnaire.Item.`);
155
+ }
156
+ if (registration.required !== Boolean(definition.required)) {
157
+ warnings.push(`Item "${definition.name}" has different required values in Root.items and Questionnaire.Item.`);
158
+ }
159
+ const definedChoices = definition.choices ?? [];
160
+ const definedChoiceByValue = new Map(definedChoices.map((choice) => [choice.value, choice]));
161
+ const registeredChoiceByValue = new Map(registration.choices.map((choice) => [choice.value, choice]));
162
+ for (const choice of definedChoices) {
163
+ const registeredChoice = registeredChoiceByValue.get(choice.value);
164
+ if (!registeredChoice) {
165
+ warnings.push(`Choice "${choice.value}" is defined for item "${definition.name}" but has no rendered Questionnaire.Choice.`);
166
+ continue;
167
+ }
168
+ if (registeredChoice.disabled !== Boolean(choice.disabled)) {
169
+ warnings.push(`Choice "${choice.value}" in item "${definition.name}" has different disabled values in Root.items and Questionnaire.Choice.`);
170
+ }
171
+ }
172
+ if (shortcuts) {
173
+ for (const choice of registration.choices) {
174
+ if (!definedChoiceByValue.has(choice.value)) {
175
+ warnings.push(`Rendered choice "${choice.value}" in item "${definition.name}" is missing from Root.items and will not receive a shortcut.`);
176
+ }
177
+ }
178
+ const definedOrder = definedChoices.filter((choice) => !choice.disabled).map((choice) => choice.value);
179
+ const registeredOrder = registration.choices.filter((choice) => !choice.disabled).map((choice) => choice.value);
180
+ const sameChoices = definedOrder.length > 0 &&
181
+ definedOrder.length === registeredOrder.length &&
182
+ definedOrder.every((choiceValue) => registeredOrder.includes(choiceValue));
183
+ if (sameChoices && definedOrder.some((choiceValue, index) => choiceValue !== registeredOrder[index])) {
184
+ warnings.push(`Choice order for item "${definition.name}" differs between Root.items and the rendered Questionnaire.Choice elements.`);
185
+ }
186
+ }
187
+ }
188
+ for (const registration of registrations) {
189
+ if (!registration.disabled && !collection.itemByName.has(registration.name)) {
190
+ warnings.push(`Rendered item "${registration.name}" is missing from Root.items and is excluded from the questionnaire collection.`);
191
+ }
192
+ }
193
+ return warnings;
194
+ }
195
+
196
+ const BrnQuestionnaireToken = new InjectionToken('BrnQuestionnaireToken');
197
+ const BrnQuestionnaireItemToken = new InjectionToken('BrnQuestionnaireItemToken');
198
+ const BrnQuestionnaireChoiceToken = new InjectionToken('BrnQuestionnaireChoiceToken');
199
+ function provideBrnQuestionnaire(directive) {
200
+ return { provide: BrnQuestionnaireToken, useExisting: directive };
201
+ }
202
+ function injectBrnQuestionnaire() {
203
+ const questionnaire = inject(BrnQuestionnaireToken, { optional: true });
204
+ if (!questionnaire) {
205
+ throw new Error('Questionnaire parts must be used within a brnQuestionnaire root.');
206
+ }
207
+ return questionnaire;
208
+ }
209
+ function provideBrnQuestionnaireItem(directive) {
210
+ return { provide: BrnQuestionnaireItemToken, useExisting: directive };
211
+ }
212
+ function injectBrnQuestionnaireItem() {
213
+ const item = inject(BrnQuestionnaireItemToken, { optional: true });
214
+ if (!item) {
215
+ throw new Error('Questionnaire item parts must be used within a brnQuestionnaireItem.');
216
+ }
217
+ return item;
218
+ }
219
+ function provideBrnQuestionnaireChoice(directive) {
220
+ return { provide: BrnQuestionnaireChoiceToken, useExisting: directive };
221
+ }
222
+ function injectBrnQuestionnaireChoice() {
223
+ const choice = inject(BrnQuestionnaireChoiceToken, { optional: true });
224
+ if (!choice) {
225
+ throw new Error('Questionnaire choice parts must be used within a brnQuestionnaireChoice.');
226
+ }
227
+ return choice;
228
+ }
229
+
230
+ class BrnQuestionnaire {
231
+ _elementRef = inject(ElementRef);
232
+ items = input(undefined, ...(ngDevMode ? [{ debugName: "items" }] : /* istanbul ignore next */ []));
233
+ defaultItem = input(undefined, ...(ngDevMode ? [{ debugName: "defaultItem" }] : /* istanbul ignore next */ []));
234
+ item = model(null, ...(ngDevMode ? [{ debugName: "item" }] : /* istanbul ignore next */ []));
235
+ shortcuts = input(null, ...(ngDevMode ? [{ debugName: "shortcuts" }] : /* istanbul ignore next */ []));
236
+ noValidate = input(true, { ...(ngDevMode ? { debugName: "noValidate" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
237
+ _registrations = signal([], ...(ngDevMode ? [{ debugName: "_registrations" }] : /* istanbul ignore next */ []));
238
+ _domVersion = signal(0, ...(ngDevMode ? [{ debugName: "_domVersion" }] : /* istanbul ignore next */ []));
239
+ _pendingFocus = signal(null, ...(ngDevMode ? [{ debugName: "_pendingFocus" }] : /* istanbul ignore next */ []));
240
+ _initialized = signal(false, ...(ngDevMode ? [{ debugName: "_initialized" }] : /* istanbul ignore next */ []));
241
+ _warningsReady = signal(false, ...(ngDevMode ? [{ debugName: "_warningsReady" }] : /* istanbul ignore next */ []));
242
+ _previousActiveItemName = null;
243
+ _activeWarnings = new Set();
244
+ _collection = computed(() => createQuestionnaireCollection(this.items()), ...(ngDevMode ? [{ debugName: "_collection" }] : /* istanbul ignore next */ []));
245
+ _runtimeItems = computed(() => {
246
+ this._domVersion();
247
+ return this._registrations()
248
+ .filter((registration) => !registration.disabled)
249
+ .sort(compareItemOrder);
250
+ }, ...(ngDevMode ? [{ debugName: "_runtimeItems" }] : /* istanbul ignore next */ []));
251
+ _runtimeItemByName = computed(() => new Map(this._runtimeItems().map((runtimeItem) => [runtimeItem.name, runtimeItem])), ...(ngDevMode ? [{ debugName: "_runtimeItemByName" }] : /* istanbul ignore next */ []));
252
+ _logicalItems = computed(() => this._collection()?.enabledItems ?? this._runtimeItems(), ...(ngDevMode ? [{ debugName: "_logicalItems" }] : /* istanbul ignore next */ []));
253
+ _currentIndex = computed(() => this._logicalItems().findIndex((logicalItem) => logicalItem.name === this.item()), ...(ngDevMode ? [{ debugName: "_currentIndex" }] : /* istanbul ignore next */ []));
254
+ activeItem = computed(() => {
255
+ const activeItemName = this.item();
256
+ const currentIndex = this._currentIndex();
257
+ if (currentIndex < 0 || !activeItemName) {
258
+ return null;
259
+ }
260
+ return this._runtimeItemByName().get(activeItemName) ?? null;
261
+ }, ...(ngDevMode ? [{ debugName: "activeItem" }] : /* istanbul ignore next */ []));
262
+ activeItemName = computed(() => this.item(), ...(ngDevMode ? [{ debugName: "activeItemName" }] : /* istanbul ignore next */ []));
263
+ activeItemRequired = computed(() => {
264
+ const currentIndex = this._currentIndex();
265
+ const activeItemName = this.item();
266
+ if (currentIndex < 0) {
267
+ return null;
268
+ }
269
+ const activeDefinition = activeItemName ? this._collection()?.itemByName.get(activeItemName) : undefined;
270
+ if (activeDefinition) {
271
+ return Boolean(activeDefinition.required);
272
+ }
273
+ return this.activeItem()?.required ?? false;
274
+ }, ...(ngDevMode ? [{ debugName: "activeItemRequired" }] : /* istanbul ignore next */ []));
275
+ activeItemStatus = computed(() => {
276
+ const currentIndex = this._currentIndex();
277
+ const activeItemName = this.item();
278
+ if (currentIndex < 0) {
279
+ return null;
280
+ }
281
+ return this.activeItem()?.status ?? (activeItemName ? 'unanswered' : null);
282
+ }, ...(ngDevMode ? [{ debugName: "activeItemStatus" }] : /* istanbul ignore next */ []));
283
+ itemDefinitionByName = computed(() => this._collection()?.itemByName ?? null, ...(ngDevMode ? [{ debugName: "itemDefinitionByName" }] : /* istanbul ignore next */ []));
284
+ nativeValidation = computed(() => this.noValidate() === false, ...(ngDevMode ? [{ debugName: "nativeValidation" }] : /* istanbul ignore next */ []));
285
+ total = computed(() => this._logicalItems().length, ...(ngDevMode ? [{ debugName: "total" }] : /* istanbul ignore next */ []));
286
+ current = computed(() => {
287
+ const currentIndex = this._currentIndex();
288
+ return currentIndex < 0 ? 0 : currentIndex + 1;
289
+ }, ...(ngDevMode ? [{ debugName: "current" }] : /* istanbul ignore next */ []));
290
+ first = computed(() => this.total() > 0 && this._currentIndex() === 0, ...(ngDevMode ? [{ debugName: "first" }] : /* istanbul ignore next */ []));
291
+ last = computed(() => this.total() > 0 && this._currentIndex() === this.total() - 1, ...(ngDevMode ? [{ debugName: "last" }] : /* istanbul ignore next */ []));
292
+ domVersion = this._domVersion.asReadonly();
293
+ _orderedRegistrations = computed(() => {
294
+ const collection = this._collection();
295
+ const runtimeItemByName = this._runtimeItemByName();
296
+ if (collection) {
297
+ return collection.enabledItems.flatMap((definition) => {
298
+ const registration = runtimeItemByName.get(definition.name);
299
+ return registration ? [registration] : [];
300
+ });
301
+ }
302
+ return this._runtimeItems();
303
+ }, ...(ngDevMode ? [{ debugName: "_orderedRegistrations" }] : /* istanbul ignore next */ []));
304
+ constructor() {
305
+ afterNextRender(() => {
306
+ this._warningsReady.set(true);
307
+ });
308
+ effect(() => {
309
+ if (this._initialized()) {
310
+ return;
311
+ }
312
+ const next = getInitialItemName(this._collection(), this.defaultItem());
313
+ if (this.item() === null && next) {
314
+ this.item.set(next);
315
+ }
316
+ this._initialized.set(true);
317
+ });
318
+ effect((onCleanup) => {
319
+ const form = this._elementRef.nativeElement;
320
+ if (typeof MutationObserver === 'undefined') {
321
+ return;
322
+ }
323
+ const observer = new MutationObserver(() => {
324
+ this._domVersion.update((version) => version + 1);
325
+ });
326
+ observer.observe(form, { childList: true, subtree: true });
327
+ onCleanup(() => observer.disconnect());
328
+ });
329
+ effect(() => {
330
+ if (!brnDevMode || !this._warningsReady()) {
331
+ return;
332
+ }
333
+ const collection = this._collection();
334
+ const form = this._elementRef.nativeElement;
335
+ if (!collection || !form) {
336
+ this._activeWarnings.clear();
337
+ return;
338
+ }
339
+ const registrations = this._registrations();
340
+ const shortcuts = this.shortcuts();
341
+ const defaultItem = this.defaultItem();
342
+ queueMicrotask(() => {
343
+ const warnings = [
344
+ ...getCollectionDefinitionWarnings(collection, defaultItem),
345
+ ...getCollectionRegistrationWarnings(collection, registrations, shortcuts),
346
+ ];
347
+ const activeWarnings = new Set(warnings);
348
+ for (const warning of activeWarnings) {
349
+ if (!this._activeWarnings.has(warning)) {
350
+ console.warn(`[Questionnaire] ${warning}`);
351
+ }
352
+ }
353
+ this._activeWarnings.clear();
354
+ for (const warning of activeWarnings) {
355
+ this._activeWarnings.add(warning);
356
+ }
357
+ });
358
+ });
359
+ effect(() => {
360
+ const total = this.total();
361
+ const currentIndex = this._currentIndex();
362
+ const logicalItems = this._logicalItems();
363
+ const activeItemName = this.item();
364
+ const activeItem = this.activeItem();
365
+ if (total === 0) {
366
+ return;
367
+ }
368
+ if (currentIndex < 0) {
369
+ this.setItem(logicalItems[0].name);
370
+ return;
371
+ }
372
+ // An enabled definition without a rendered item leaves navigation inert — recover.
373
+ if (!activeItem) {
374
+ const recoveryName = this.getRecoveryItemName(currentIndex);
375
+ if (recoveryName && recoveryName !== activeItemName) {
376
+ this.setItem(recoveryName);
377
+ }
378
+ return;
379
+ }
380
+ const pendingFocus = this._pendingFocus();
381
+ const activeItemChanged = this._previousActiveItemName !== activeItemName;
382
+ this._previousActiveItemName = activeItemName;
383
+ if (!pendingFocus || pendingFocus.name !== activeItemName) {
384
+ if (activeItemChanged) {
385
+ this._pendingFocus.set(null);
386
+ activeItem.focus();
387
+ }
388
+ return;
389
+ }
390
+ if (pendingFocus.target === 'invalid') {
391
+ activeItem.focusInvalid();
392
+ }
393
+ else {
394
+ activeItem.focus();
395
+ }
396
+ this._pendingFocus.set(null);
397
+ });
398
+ }
399
+ getRecoveryItemName(currentIndex) {
400
+ const ordered = this._orderedRegistrations();
401
+ if (!ordered.length) {
402
+ return null;
403
+ }
404
+ const logicalNames = this._logicalItems().map((logicalItem) => logicalItem.name);
405
+ let recoveryName = ordered[0].name;
406
+ for (const registration of ordered) {
407
+ const registrationIndex = logicalNames.indexOf(registration.name);
408
+ if (registrationIndex < 0) {
409
+ continue;
410
+ }
411
+ recoveryName = registration.name;
412
+ if (registrationIndex >= currentIndex) {
413
+ break;
414
+ }
415
+ }
416
+ return recoveryName;
417
+ }
418
+ registerItem(registration) {
419
+ this._registrations.update((currentRegistrations) => [
420
+ ...currentRegistrations.filter((currentRegistration) => currentRegistration.element !== registration.element && currentRegistration.name !== registration.name),
421
+ registration,
422
+ ]);
423
+ return () => {
424
+ this._registrations.update((currentRegistrations) => currentRegistrations.filter((currentRegistration) => currentRegistration !== registration));
425
+ };
426
+ }
427
+ setItem(nextItem, focusTarget = 'item') {
428
+ if (nextItem === this.item()) {
429
+ return;
430
+ }
431
+ this._pendingFocus.set({ name: nextItem, target: focusTarget });
432
+ this.item.set(nextItem);
433
+ }
434
+ goPrevious() {
435
+ const currentIndex = this._currentIndex();
436
+ if (currentIndex <= 0) {
437
+ return;
438
+ }
439
+ this.setItem(this._logicalItems()[currentIndex - 1].name);
440
+ }
441
+ goNext() {
442
+ const activeItem = this.activeItem();
443
+ const currentIndex = this._currentIndex();
444
+ const total = this.total();
445
+ if (!activeItem || currentIndex >= total - 1) {
446
+ return;
447
+ }
448
+ if (!activeItem.validate()) {
449
+ activeItem.focusInvalid();
450
+ return;
451
+ }
452
+ this.setItem(this._logicalItems()[currentIndex + 1].name);
453
+ }
454
+ confirmCurrent() {
455
+ const activeItem = this.activeItem();
456
+ if (!activeItem) {
457
+ return;
458
+ }
459
+ if (!activeItem.validate()) {
460
+ activeItem.focusInvalid();
461
+ return;
462
+ }
463
+ if (this.last()) {
464
+ this._elementRef.nativeElement.requestSubmit();
465
+ return;
466
+ }
467
+ this.setItem(this._logicalItems()[this._currentIndex() + 1].name);
468
+ }
469
+ skipCurrent() {
470
+ const activeItem = this.activeItem();
471
+ if (!activeItem || activeItem.required) {
472
+ return;
473
+ }
474
+ activeItem.skip();
475
+ if (!this.last()) {
476
+ this.setItem(this._logicalItems()[this._currentIndex() + 1].name);
477
+ return;
478
+ }
479
+ queueMicrotask(() => {
480
+ this._elementRef.nativeElement.requestSubmit();
481
+ });
482
+ }
483
+ onReset(event) {
484
+ if (event.defaultPrevented) {
485
+ return;
486
+ }
487
+ for (const registration of this._registrations()) {
488
+ registration.reset();
489
+ }
490
+ const collection = this._collection();
491
+ const runtimeItems = this._runtimeItems();
492
+ const defaultItem = this.defaultItem();
493
+ const resetItemName = collection
494
+ ? getInitialItemName(collection, defaultItem)
495
+ : (runtimeItems.find((registration) => registration.name === defaultItem)?.name ?? runtimeItems[0]?.name);
496
+ if (resetItemName) {
497
+ this.setItem(resetItemName);
498
+ }
499
+ }
500
+ onSubmit(event) {
501
+ const firstInvalidItem = this._orderedRegistrations().find((registration) => !registration.validate());
502
+ if (!firstInvalidItem) {
503
+ return;
504
+ }
505
+ event.preventDefault();
506
+ this.setItem(firstInvalidItem.name, 'invalid');
507
+ if (firstInvalidItem.name === this.item()) {
508
+ firstInvalidItem.focusInvalid();
509
+ this._pendingFocus.set(null);
510
+ }
511
+ }
512
+ onKeyDown(event) {
513
+ const activeItem = this.activeItem();
514
+ if (event.defaultPrevented ||
515
+ event.isComposing ||
516
+ event.keyCode === 229 ||
517
+ !activeItem ||
518
+ !(event.target instanceof Element)) {
519
+ return;
520
+ }
521
+ if (event.key === 'Enter' && (event.metaKey || event.ctrlKey) && !event.altKey && !event.shiftKey) {
522
+ event.preventDefault();
523
+ if (!event.repeat) {
524
+ this.confirmCurrent();
525
+ }
526
+ return;
527
+ }
528
+ if (event.metaKey || event.ctrlKey || event.altKey) {
529
+ return;
530
+ }
531
+ if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {
532
+ const moved = activeItem.moveAnswerFocus(event.target, event.key === 'ArrowDown' ? 'next' : 'previous');
533
+ if (moved) {
534
+ event.preventDefault();
535
+ return;
536
+ }
537
+ }
538
+ if ((event.key === 'ArrowLeft' || event.key === 'ArrowRight') &&
539
+ !isTextEntryTarget(event.target) &&
540
+ !isRadioTarget(event.target)) {
541
+ event.preventDefault();
542
+ if (event.repeat) {
543
+ return;
544
+ }
545
+ if (event.key === 'ArrowLeft') {
546
+ this.goPrevious();
547
+ }
548
+ else if (activeItem.status !== 'unanswered') {
549
+ this.goNext();
550
+ }
551
+ return;
552
+ }
553
+ if (event.key === 'Enter') {
554
+ const answer = activeItem.getAnswerByElement(event.target);
555
+ if (!answer) {
556
+ return;
557
+ }
558
+ event.preventDefault();
559
+ if (!event.repeat && isAnswerFilled(answer)) {
560
+ this.confirmCurrent();
561
+ }
562
+ return;
563
+ }
564
+ const shortcuts = this.shortcuts();
565
+ if (!shortcuts || isTextEntryTarget(event.target)) {
566
+ return;
567
+ }
568
+ const shortcut = getShortcutFromKey(event.key, shortcuts);
569
+ const answer = shortcut ? activeItem.getAnswerByShortcut(shortcut) : null;
570
+ if (!answer) {
571
+ return;
572
+ }
573
+ event.preventDefault();
574
+ if (event.repeat) {
575
+ return;
576
+ }
577
+ answer.element.focus();
578
+ if (answer.type === 'choice') {
579
+ answer.element.click();
580
+ }
581
+ }
582
+ /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaire, deps: [], target: i0.ɵɵFactoryTarget.Directive });
583
+ /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.16", type: BrnQuestionnaire, isStandalone: true, selector: "form[brnQuestionnaire]", inputs: { items: { classPropertyName: "items", publicName: "items", isSignal: true, isRequired: false, transformFunction: null }, defaultItem: { classPropertyName: "defaultItem", publicName: "defaultItem", isSignal: true, isRequired: false, transformFunction: null }, item: { classPropertyName: "item", publicName: "item", isSignal: true, isRequired: false, transformFunction: null }, shortcuts: { classPropertyName: "shortcuts", publicName: "shortcuts", isSignal: true, isRequired: false, transformFunction: null }, noValidate: { classPropertyName: "noValidate", publicName: "noValidate", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { item: "itemChange" }, host: { listeners: { "keydown": "onKeyDown($event)", "submit": "onSubmit($event)", "reset": "onReset($event)" }, properties: { "attr.data-shortcuts": "shortcuts() ?? null", "attr.tabindex": "shortcuts() ? -1 : null", "attr.novalidate": "noValidate() ? \"\" : null" } }, providers: [provideBrnQuestionnaire(BrnQuestionnaire)], exportAs: ["brnQuestionnaire"], ngImport: i0 });
584
+ }
585
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaire, decorators: [{
586
+ type: Directive,
587
+ args: [{
588
+ selector: 'form[brnQuestionnaire]',
589
+ exportAs: 'brnQuestionnaire',
590
+ providers: [provideBrnQuestionnaire(BrnQuestionnaire)],
591
+ host: {
592
+ '[attr.data-shortcuts]': 'shortcuts() ?? null',
593
+ // When shortcuts are enabled, allow programmatic focus without adding a Tab stop
594
+ // (keydown still bubbles from focused descendants / the focused form).
595
+ '[attr.tabindex]': 'shortcuts() ? -1 : null',
596
+ '[attr.novalidate]': 'noValidate() ? "" : null',
597
+ '(keydown)': 'onKeyDown($event)',
598
+ '(submit)': 'onSubmit($event)',
599
+ '(reset)': 'onReset($event)',
600
+ },
601
+ }]
602
+ }], ctorParameters: () => [], propDecorators: { items: [{ type: i0.Input, args: [{ isSignal: true, alias: "items", required: false }] }], defaultItem: [{ type: i0.Input, args: [{ isSignal: true, alias: "defaultItem", required: false }] }], item: [{ type: i0.Input, args: [{ isSignal: true, alias: "item", required: false }] }, { type: i0.Output, args: ["itemChange"] }], shortcuts: [{ type: i0.Input, args: [{ isSignal: true, alias: "shortcuts", required: false }] }], noValidate: [{ type: i0.Input, args: [{ isSignal: true, alias: "noValidate", required: false }] }] } });
603
+
604
+ let nextChoiceId = 0;
605
+ class BrnQuestionnaireChoice {
606
+ _item = injectBrnQuestionnaireItem();
607
+ _answerId = `brn-questionnaire-choice-${++nextChoiceId}`;
608
+ value = input.required(...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
609
+ disabledInput = input(false, { ...(ngDevMode ? { debugName: "disabledInput" } : /* istanbul ignore next */ {}), alias: 'disabled',
610
+ transform: booleanAttribute });
611
+ defaultChecked = input(false, { ...(ngDevMode ? { debugName: "defaultChecked" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
612
+ checkedInput = input(undefined, { ...(ngDevMode ? { debugName: "checkedInput" } : /* istanbul ignore next */ {}), alias: 'checked' });
613
+ checkedChange = output();
614
+ _inputElement = signal(null, ...(ngDevMode ? [{ debugName: "_inputElement" }] : /* istanbul ignore next */ []));
615
+ disabled = computed(() => this._item.disabled() || this.disabledInput(), ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
616
+ invalid = computed(() => this._item.invalid(), ...(ngDevMode ? [{ debugName: "invalid" }] : /* istanbul ignore next */ []));
617
+ type = computed(() => (this._item.multiple() ? 'checkbox' : 'radio'), ...(ngDevMode ? [{ debugName: "type" }] : /* istanbul ignore next */ []));
618
+ checked = computed(() => {
619
+ const controlledChecked = this.checkedInput();
620
+ const selected = this._item.selectedAnswerIds().includes(this._answerId);
621
+ if (controlledChecked !== undefined) {
622
+ return this._item.status() === 'skipped' ? false : controlledChecked;
623
+ }
624
+ return selected;
625
+ }, ...(ngDevMode ? [{ debugName: "checked" }] : /* istanbul ignore next */ []));
626
+ shortcut = computed(() => this._item.shortcutByChoiceValue()?.get(this.value()) ??
627
+ this._item.shortcutByAnswerId().get(this._answerId) ??
628
+ null, ...(ngDevMode ? [{ debugName: "shortcut" }] : /* istanbul ignore next */ []));
629
+ inputId = computed(() => this._answerId, ...(ngDevMode ? [{ debugName: "inputId" }] : /* istanbul ignore next */ []));
630
+ inputName = computed(() => (this._item.status() === 'skipped' ? undefined : this._item.name()), ...(ngDevMode ? [{ debugName: "inputName" }] : /* istanbul ignore next */ []));
631
+ inputRequired = computed(() => this._item.required() && !this._item.multiple() && !this._item.hasInputAnswer(), ...(ngDevMode ? [{ debugName: "inputRequired" }] : /* istanbul ignore next */ []));
632
+ inputAriaKeyShortcuts = computed(() => getAnswerKeyShortcuts(this.shortcut(), !this.disabled() && this.checked()), ...(ngDevMode ? [{ debugName: "inputAriaKeyShortcuts" }] : /* istanbul ignore next */ []));
633
+ constructor() {
634
+ effect((onCleanup) => {
635
+ onCleanup(this._item.registerBoundAnswerDefault(this._answerId, this.defaultChecked()));
636
+ });
637
+ effect((onCleanup) => {
638
+ const inputElement = this._inputElement();
639
+ if (!inputElement) {
640
+ return;
641
+ }
642
+ onCleanup(this._item.registerAnswerControl({
643
+ disabled: this.disabled(),
644
+ element: inputElement,
645
+ id: this._answerId,
646
+ ownDisabled: this.disabledInput(),
647
+ type: 'choice',
648
+ value: this.value(),
649
+ }));
650
+ });
651
+ effect(() => {
652
+ const controlledChecked = this.checkedInput();
653
+ if (controlledChecked === undefined) {
654
+ return;
655
+ }
656
+ this._item.resetVersion();
657
+ this._item.syncControlledAnswerSelection(this._answerId, controlledChecked);
658
+ });
659
+ effect(() => {
660
+ const inputElement = this._inputElement();
661
+ if (!inputElement) {
662
+ return;
663
+ }
664
+ const controlledChecked = this.checkedInput();
665
+ inputElement.defaultChecked = controlledChecked !== undefined ? controlledChecked : this.defaultChecked();
666
+ if (this._item.resetVersion() > 0) {
667
+ inputElement.checked = this.checked();
668
+ }
669
+ });
670
+ }
671
+ setInputElement(element) {
672
+ this._inputElement.set(element);
673
+ }
674
+ onInputChange(event) {
675
+ this.checkedChange.emit(event);
676
+ if (event.defaultPrevented || !(event.target instanceof HTMLInputElement)) {
677
+ return;
678
+ }
679
+ const controlledChecked = this.checkedInput();
680
+ if (controlledChecked === undefined) {
681
+ this._item.setAnswerSelectionFromInteraction(this._answerId, event.target.checked);
682
+ return;
683
+ }
684
+ if (this._item.status() === 'skipped' && controlledChecked === event.target.checked) {
685
+ this._item.setAnswerSelectionFromInteraction(this._answerId, controlledChecked);
686
+ }
687
+ }
688
+ /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaireChoice, deps: [], target: i0.ɵɵFactoryTarget.Directive });
689
+ /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.16", type: BrnQuestionnaireChoice, isStandalone: true, selector: "label[brnQuestionnaireChoice]", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: true, transformFunction: null }, disabledInput: { classPropertyName: "disabledInput", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, defaultChecked: { classPropertyName: "defaultChecked", publicName: "defaultChecked", isSignal: true, isRequired: false, transformFunction: null }, checkedInput: { classPropertyName: "checkedInput", publicName: "checked", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { checkedChange: "checkedChange" }, host: { properties: { "attr.data-checked": "checked() ? \"\" : null", "attr.data-unchecked": "checked() ? null : \"\"", "attr.data-disabled": "disabled() ? \"\" : null", "attr.data-invalid": "invalid() ? \"\" : null", "attr.data-type": "type()", "attr.data-shortcut": "shortcut() ?? null" } }, providers: [provideBrnQuestionnaireChoice(BrnQuestionnaireChoice)], exportAs: ["brnQuestionnaireChoice"], ngImport: i0 });
690
+ }
691
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaireChoice, decorators: [{
692
+ type: Directive,
693
+ args: [{
694
+ selector: 'label[brnQuestionnaireChoice]',
695
+ exportAs: 'brnQuestionnaireChoice',
696
+ providers: [provideBrnQuestionnaireChoice(BrnQuestionnaireChoice)],
697
+ host: {
698
+ '[attr.data-checked]': 'checked() ? "" : null',
699
+ '[attr.data-unchecked]': 'checked() ? null : ""',
700
+ '[attr.data-disabled]': 'disabled() ? "" : null',
701
+ '[attr.data-invalid]': 'invalid() ? "" : null',
702
+ '[attr.data-type]': 'type()',
703
+ '[attr.data-shortcut]': 'shortcut() ?? null',
704
+ },
705
+ }]
706
+ }], ctorParameters: () => [], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: true }] }], disabledInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], defaultChecked: [{ type: i0.Input, args: [{ isSignal: true, alias: "defaultChecked", required: false }] }], checkedInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "checked", required: false }] }], checkedChange: [{ type: i0.Output, args: ["checkedChange"] }] } });
707
+
708
+ class BrnQuestionnaireChoiceInput {
709
+ _choice = injectBrnQuestionnaireChoice();
710
+ _elementRef = inject(ElementRef);
711
+ constructor() {
712
+ effect(() => {
713
+ this._choice.setInputElement(this._elementRef.nativeElement);
714
+ });
715
+ // Keep the native checked property aligned with questionnaire state.
716
+ // Avoid [checked] template bindings that can fight radio group clicks.
717
+ effect(() => {
718
+ const input = this._elementRef.nativeElement;
719
+ const checked = this._choice.checked();
720
+ if (input.checked !== checked) {
721
+ input.checked = checked;
722
+ }
723
+ });
724
+ }
725
+ /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaireChoiceInput, deps: [], target: i0.ɵɵFactoryTarget.Directive });
726
+ /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.16", type: BrnQuestionnaireChoiceInput, isStandalone: true, selector: "input[brnQuestionnaireChoiceInput]", host: { listeners: { "change": "_choice.onInputChange($event)" }, properties: { "attr.id": "_choice.inputId()", "attr.name": "_choice.inputName() ?? null", "attr.type": "_choice.type()", "attr.value": "_choice.value()", "attr.disabled": "_choice.disabled() || null", "attr.required": "_choice.inputRequired() || null", "attr.aria-invalid": "_choice.invalid() ? \"true\" : null", "attr.aria-keyshortcuts": "_choice.inputAriaKeyShortcuts() ?? null", "attr.data-checked": "_choice.checked() ? \"\" : null", "attr.data-unchecked": "_choice.checked() ? null : \"\"" } }, exportAs: ["brnQuestionnaireChoiceInput"], ngImport: i0 });
727
+ }
728
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaireChoiceInput, decorators: [{
729
+ type: Directive,
730
+ args: [{
731
+ selector: 'input[brnQuestionnaireChoiceInput]',
732
+ exportAs: 'brnQuestionnaireChoiceInput',
733
+ host: {
734
+ '[attr.id]': '_choice.inputId()',
735
+ '[attr.name]': '_choice.inputName() ?? null',
736
+ '[attr.type]': '_choice.type()',
737
+ '[attr.value]': '_choice.value()',
738
+ '[attr.disabled]': '_choice.disabled() || null',
739
+ '[attr.required]': '_choice.inputRequired() || null',
740
+ '[attr.aria-invalid]': '_choice.invalid() ? "true" : null',
741
+ '[attr.aria-keyshortcuts]': '_choice.inputAriaKeyShortcuts() ?? null',
742
+ '[attr.data-checked]': '_choice.checked() ? "" : null',
743
+ '[attr.data-unchecked]': '_choice.checked() ? null : ""',
744
+ '(change)': '_choice.onInputChange($event)',
745
+ },
746
+ }]
747
+ }], ctorParameters: () => [] });
748
+
749
+ class BrnQuestionnaireChoiceLabel {
750
+ constructor() {
751
+ injectBrnQuestionnaireChoice();
752
+ }
753
+ /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaireChoiceLabel, deps: [], target: i0.ɵɵFactoryTarget.Directive });
754
+ /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.16", type: BrnQuestionnaireChoiceLabel, isStandalone: true, selector: "[brnQuestionnaireChoiceLabel]", exportAs: ["brnQuestionnaireChoiceLabel"], ngImport: i0 });
755
+ }
756
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaireChoiceLabel, decorators: [{
757
+ type: Directive,
758
+ args: [{
759
+ selector: '[brnQuestionnaireChoiceLabel]',
760
+ exportAs: 'brnQuestionnaireChoiceLabel',
761
+ }]
762
+ }], ctorParameters: () => [] });
763
+
764
+ class BrnQuestionnaireChoiceShortcut {
765
+ _choice = injectBrnQuestionnaireChoice();
766
+ /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaireChoiceShortcut, deps: [], target: i0.ɵɵFactoryTarget.Directive });
767
+ /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.16", type: BrnQuestionnaireChoiceShortcut, isStandalone: true, selector: "[brnQuestionnaireChoiceShortcut]", host: { properties: { "attr.aria-hidden": "true", "attr.hidden": "_choice.shortcut() === null || null" } }, exportAs: ["brnQuestionnaireChoiceShortcut"], ngImport: i0 });
768
+ }
769
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaireChoiceShortcut, decorators: [{
770
+ type: Directive,
771
+ args: [{
772
+ selector: '[brnQuestionnaireChoiceShortcut]',
773
+ exportAs: 'brnQuestionnaireChoiceShortcut',
774
+ host: {
775
+ '[attr.aria-hidden]': 'true',
776
+ '[attr.hidden]': '_choice.shortcut() === null || null',
777
+ },
778
+ }]
779
+ }] });
780
+
781
+ class BrnQuestionnaireChoices {
782
+ _item = injectBrnQuestionnaireItem();
783
+ shortcuts = this._item.shortcuts;
784
+ /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaireChoices, deps: [], target: i0.ɵɵFactoryTarget.Directive });
785
+ /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.16", type: BrnQuestionnaireChoices, isStandalone: true, selector: "[brnQuestionnaireChoices]", host: { properties: { "attr.data-shortcuts": "_item.shortcuts() ?? null" } }, exportAs: ["brnQuestionnaireChoices"], ngImport: i0 });
786
+ }
787
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaireChoices, decorators: [{
788
+ type: Directive,
789
+ args: [{
790
+ selector: '[brnQuestionnaireChoices]',
791
+ exportAs: 'brnQuestionnaireChoices',
792
+ host: {
793
+ '[attr.data-shortcuts]': '_item.shortcuts() ?? null',
794
+ },
795
+ }]
796
+ }] });
797
+
798
+ let nextDescriptionId = 0;
799
+ class BrnQuestionnaireDescription {
800
+ _item = injectBrnQuestionnaireItem();
801
+ _generatedId = `brn-questionnaire-description-${++nextDescriptionId}`;
802
+ id = input(undefined, ...(ngDevMode ? [{ debugName: "id" }] : /* istanbul ignore next */ []));
803
+ _descriptionId = computed(() => this.id() ?? this._generatedId, ...(ngDevMode ? [{ debugName: "_descriptionId" }] : /* istanbul ignore next */ []));
804
+ constructor() {
805
+ effect((onCleanup) => {
806
+ onCleanup(this._item.registerDescription(this._descriptionId()));
807
+ });
808
+ }
809
+ /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaireDescription, deps: [], target: i0.ɵɵFactoryTarget.Directive });
810
+ /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.16", type: BrnQuestionnaireDescription, isStandalone: true, selector: "[brnQuestionnaireDescription]", inputs: { id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "attr.id": "_descriptionId()" } }, exportAs: ["brnQuestionnaireDescription"], ngImport: i0 });
811
+ }
812
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaireDescription, decorators: [{
813
+ type: Directive,
814
+ args: [{
815
+ selector: '[brnQuestionnaireDescription]',
816
+ exportAs: 'brnQuestionnaireDescription',
817
+ host: {
818
+ '[attr.id]': '_descriptionId()',
819
+ },
820
+ }]
821
+ }], ctorParameters: () => [], propDecorators: { id: [{ type: i0.Input, args: [{ isSignal: true, alias: "id", required: false }] }] } });
822
+
823
+ let nextErrorId = 0;
824
+ class BrnQuestionnaireError {
825
+ _item = injectBrnQuestionnaireItem();
826
+ _generatedId = `brn-questionnaire-error-${++nextErrorId}`;
827
+ id = input(undefined, ...(ngDevMode ? [{ debugName: "id" }] : /* istanbul ignore next */ []));
828
+ _errorId = computed(() => this.id() ?? this._generatedId, ...(ngDevMode ? [{ debugName: "_errorId" }] : /* istanbul ignore next */ []));
829
+ requiredMessage = input('Choose an answer to continue.', ...(ngDevMode ? [{ debugName: "requiredMessage" }] : /* istanbul ignore next */ []));
830
+ optionalMessage = input('Choose an answer or skip this question.', ...(ngDevMode ? [{ debugName: "optionalMessage" }] : /* istanbul ignore next */ []));
831
+ defaultMessage = computed(() => this._item.required() ? this.requiredMessage() : this.optionalMessage(), ...(ngDevMode ? [{ debugName: "defaultMessage" }] : /* istanbul ignore next */ []));
832
+ constructor() {
833
+ effect((onCleanup) => {
834
+ onCleanup(this._item.registerError(this._errorId()));
835
+ });
836
+ }
837
+ /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaireError, deps: [], target: i0.ɵɵFactoryTarget.Directive });
838
+ /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.16", type: BrnQuestionnaireError, isStandalone: true, selector: "[brnQuestionnaireError]", inputs: { id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, requiredMessage: { classPropertyName: "requiredMessage", publicName: "requiredMessage", isSignal: true, isRequired: false, transformFunction: null }, optionalMessage: { classPropertyName: "optionalMessage", publicName: "optionalMessage", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "attr.id": "_errorId()", "attr.hidden": "!_item.invalid() || null", "attr.role": "_item.invalid() ? \"alert\" : null" } }, exportAs: ["brnQuestionnaireError"], ngImport: i0 });
839
+ }
840
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaireError, decorators: [{
841
+ type: Directive,
842
+ args: [{
843
+ selector: '[brnQuestionnaireError]',
844
+ exportAs: 'brnQuestionnaireError',
845
+ host: {
846
+ '[attr.id]': '_errorId()',
847
+ '[attr.hidden]': '!_item.invalid() || null',
848
+ '[attr.role]': '_item.invalid() ? "alert" : null',
849
+ },
850
+ }]
851
+ }], ctorParameters: () => [], propDecorators: { id: [{ type: i0.Input, args: [{ isSignal: true, alias: "id", required: false }] }], requiredMessage: [{ type: i0.Input, args: [{ isSignal: true, alias: "requiredMessage", required: false }] }], optionalMessage: [{ type: i0.Input, args: [{ isSignal: true, alias: "optionalMessage", required: false }] }] } });
852
+
853
+ let nextInputId = 0;
854
+ class BrnQuestionnaireInput {
855
+ _item = injectBrnQuestionnaireItem();
856
+ _elementRef = inject(ElementRef);
857
+ _answerId = `brn-questionnaire-input-${++nextInputId}`;
858
+ type = input('text', ...(ngDevMode ? [{ debugName: "type" }] : /* istanbul ignore next */ []));
859
+ disabledInput = input(false, { ...(ngDevMode ? { debugName: "disabledInput" } : /* istanbul ignore next */ {}), alias: 'disabled',
860
+ transform: booleanAttribute });
861
+ value = input(undefined, ...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
862
+ defaultValue = input(undefined, ...(ngDevMode ? [{ debugName: "defaultValue" }] : /* istanbul ignore next */ []));
863
+ _uncontrolledFilled = signal(hasInputValue(this.defaultValue()), ...(ngDevMode ? [{ debugName: "_uncontrolledFilled" }] : /* istanbul ignore next */ []));
864
+ disabled = computed(() => this._item.disabled() || this.disabledInput(), ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
865
+ invalid = computed(() => this._item.invalid(), ...(ngDevMode ? [{ debugName: "invalid" }] : /* istanbul ignore next */ []));
866
+ filled = computed(() => {
867
+ const controlledValue = this.value();
868
+ return controlledValue !== undefined ? hasInputValue(controlledValue) : this._uncontrolledFilled();
869
+ }, ...(ngDevMode ? [{ debugName: "filled" }] : /* istanbul ignore next */ []));
870
+ _selected = computed(() => this._item.selectedAnswerIds().includes(this._answerId), ...(ngDevMode ? [{ debugName: "_selected" }] : /* istanbul ignore next */ []));
871
+ _ariaKeyShortcuts = computed(() => getAnswerKeyShortcuts(null, !this.disabled() && this.filled() && this._selected()), ...(ngDevMode ? [{ debugName: "_ariaKeyShortcuts" }] : /* istanbul ignore next */ []));
872
+ constructor() {
873
+ effect((onCleanup) => {
874
+ const defaultFilled = hasInputValue(this.defaultValue());
875
+ this._uncontrolledFilled.set(defaultFilled);
876
+ onCleanup(this._item.registerBoundAnswerDefault(this._answerId, defaultFilled));
877
+ });
878
+ effect((onCleanup) => {
879
+ onCleanup(this._item.registerAnswerControl({
880
+ disabled: this.disabled(),
881
+ element: this._elementRef.nativeElement,
882
+ id: this._answerId,
883
+ type: 'input',
884
+ }));
885
+ });
886
+ effect(() => {
887
+ const controlledValue = this.value();
888
+ const resetVersion = this._item.resetVersion();
889
+ const writtenValue = this._item.writtenInputValues()[this._answerId];
890
+ if (controlledValue !== undefined) {
891
+ this._item.syncControlledAnswerSelection(this._answerId, hasInputValue(controlledValue));
892
+ const nextValue = String(controlledValue);
893
+ this._elementRef.nativeElement.defaultValue = nextValue;
894
+ this._elementRef.nativeElement.value = nextValue;
895
+ return;
896
+ }
897
+ if (writtenValue !== undefined) {
898
+ this._uncontrolledFilled.set(hasInputValue(writtenValue));
899
+ this._elementRef.nativeElement.defaultValue = writtenValue;
900
+ if (this._elementRef.nativeElement.value !== writtenValue) {
901
+ this._elementRef.nativeElement.value = writtenValue;
902
+ }
903
+ return;
904
+ }
905
+ if (resetVersion > 0) {
906
+ this._uncontrolledFilled.set(hasInputValue(this.defaultValue()));
907
+ }
908
+ });
909
+ }
910
+ onInput(event) {
911
+ if (!(event.target instanceof HTMLInputElement)) {
912
+ return;
913
+ }
914
+ if (this.value() !== undefined) {
915
+ return;
916
+ }
917
+ const nextFilled = event.target.value.trim().length > 0;
918
+ this._uncontrolledFilled.set(nextFilled);
919
+ this._item.setAnswerSelectionFromInteraction(this._answerId, nextFilled);
920
+ }
921
+ /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaireInput, deps: [], target: i0.ɵɵFactoryTarget.Directive });
922
+ /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.16", type: BrnQuestionnaireInput, isStandalone: true, selector: "input[brnQuestionnaireInput]", inputs: { type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: false, transformFunction: null }, disabledInput: { classPropertyName: "disabledInput", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null }, defaultValue: { classPropertyName: "defaultValue", publicName: "defaultValue", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "input": "onInput($event)", "change": "onInput($event)" }, properties: { "attr.id": "_answerId", "attr.name": "_selected() ? _item.name() : null", "attr.form": "_selected() ? null : \"\"", "attr.type": "type()", "attr.disabled": "disabled() || null", "attr.aria-invalid": "invalid() ? \"true\" : null", "attr.aria-keyshortcuts": "_ariaKeyShortcuts() ?? null", "attr.data-filled": "filled() ? \"\" : null", "attr.data-empty": "filled() ? null : \"\"" } }, exportAs: ["brnQuestionnaireInput"], ngImport: i0 });
923
+ }
924
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaireInput, decorators: [{
925
+ type: Directive,
926
+ args: [{
927
+ selector: 'input[brnQuestionnaireInput]',
928
+ exportAs: 'brnQuestionnaireInput',
929
+ host: {
930
+ '[attr.id]': '_answerId',
931
+ '[attr.name]': '_selected() ? _item.name() : null',
932
+ '[attr.form]': '_selected() ? null : ""',
933
+ '[attr.type]': 'type()',
934
+ '[attr.disabled]': 'disabled() || null',
935
+ '[attr.aria-invalid]': 'invalid() ? "true" : null',
936
+ '[attr.aria-keyshortcuts]': '_ariaKeyShortcuts() ?? null',
937
+ '[attr.data-filled]': 'filled() ? "" : null',
938
+ '[attr.data-empty]': 'filled() ? null : ""',
939
+ '(input)': 'onInput($event)',
940
+ '(change)': 'onInput($event)',
941
+ },
942
+ }]
943
+ }], ctorParameters: () => [], propDecorators: { type: [{ type: i0.Input, args: [{ isSignal: true, alias: "type", required: false }] }], disabledInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }], defaultValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "defaultValue", required: false }] }] } });
944
+
945
+ const BRN_QUESTIONNAIRE_ITEM_VALUE_ACCESSOR = {
946
+ provide: NG_VALUE_ACCESSOR,
947
+ useExisting: forwardRef(() => BrnQuestionnaireItem),
948
+ multi: true,
949
+ };
950
+ class BrnQuestionnaireItem {
951
+ _questionnaire = injectBrnQuestionnaire();
952
+ _elementRef = inject(ElementRef);
953
+ /**
954
+ * `[formField]` overwrites `name` / `required` / `disabled` with field state.
955
+ * Prefer the host attributes so questionnaire identity and flow stay stable.
956
+ */
957
+ nameInput = input.required({ ...(ngDevMode ? { debugName: "nameInput" } : /* istanbul ignore next */ {}), alias: 'name' });
958
+ _hostName = this._elementRef.nativeElement.getAttribute('name');
959
+ name = computed(() => this._hostName || this.nameInput(), ...(ngDevMode ? [{ debugName: "name" }] : /* istanbul ignore next */ []));
960
+ multiple = input(false, { ...(ngDevMode ? { debugName: "multiple" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
961
+ requiredInput = input(false, { ...(ngDevMode ? { debugName: "requiredInput" } : /* istanbul ignore next */ {}), alias: 'required',
962
+ transform: booleanAttribute });
963
+ _hostRequired = this._elementRef.nativeElement.hasAttribute('required');
964
+ required = computed(() => this._hostRequired || this.requiredInput(), ...(ngDevMode ? [{ debugName: "required" }] : /* istanbul ignore next */ []));
965
+ disabledInput = input(false, { ...(ngDevMode ? { debugName: "disabledInput" } : /* istanbul ignore next */ {}), alias: 'disabled',
966
+ transform: booleanAttribute });
967
+ _hostDisabled = this._elementRef.nativeElement.hasAttribute('disabled');
968
+ /**
969
+ * Do not alias this to `invalid` — `[formField]` would bind field.invalid()
970
+ * and mark empty required items invalid before the user interacts.
971
+ */
972
+ externallyInvalid = input(false, { ...(ngDevMode ? { debugName: "externallyInvalid" } : /* istanbul ignore next */ {}), alias: 'itemInvalid',
973
+ transform: booleanAttribute });
974
+ ariaDescribedBy = input(undefined, { ...(ngDevMode ? { debugName: "ariaDescribedBy" } : /* istanbul ignore next */ {}), alias: 'aria-describedby' });
975
+ ariaKeyShortcuts = input(undefined, { ...(ngDevMode ? { debugName: "ariaKeyShortcuts" } : /* istanbul ignore next */ {}), alias: 'aria-keyshortcuts' });
976
+ _cvaDisabled = signal(false, ...(ngDevMode ? [{ debugName: "_cvaDisabled" }] : /* istanbul ignore next */ []));
977
+ disabled = computed(() => this._hostDisabled || this.disabledInput() || this._cvaDisabled(), ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
978
+ onChange = () => undefined;
979
+ onTouched = () => undefined;
980
+ _pendingControlValue = undefined;
981
+ _writtenInputValues = signal({}, ...(ngDevMode ? [{ debugName: "_writtenInputValues" }] : /* istanbul ignore next */ []));
982
+ statusChange = output();
983
+ _answerControlRegistrations = signal([], ...(ngDevMode ? [{ debugName: "_answerControlRegistrations" }] : /* istanbul ignore next */ []));
984
+ _validationAttempted = signal(false, ...(ngDevMode ? [{ debugName: "_validationAttempted" }] : /* istanbul ignore next */ []));
985
+ _selectedAnswerIds = signal([], ...(ngDevMode ? [{ debugName: "_selectedAnswerIds" }] : /* istanbul ignore next */ []));
986
+ _skipped = signal(false, ...(ngDevMode ? [{ debugName: "_skipped" }] : /* istanbul ignore next */ []));
987
+ _resetVersion = signal(0, ...(ngDevMode ? [{ debugName: "_resetVersion" }] : /* istanbul ignore next */ []));
988
+ _descriptionIds = signal([], ...(ngDevMode ? [{ debugName: "_descriptionIds" }] : /* istanbul ignore next */ []));
989
+ _errorIds = signal([], ...(ngDevMode ? [{ debugName: "_errorIds" }] : /* istanbul ignore next */ []));
990
+ _defaultSelectedAnswerIds = signal([], ...(ngDevMode ? [{ debugName: "_defaultSelectedAnswerIds" }] : /* istanbul ignore next */ []));
991
+ _previousStatus = null;
992
+ active = computed(() => !this._hostDisabled && !this.disabledInput() && this._questionnaire.activeItemName() === this.name(), ...(ngDevMode ? [{ debugName: "active" }] : /* istanbul ignore next */ []));
993
+ _answerControls = computed(() => {
994
+ this._questionnaire.domVersion();
995
+ return [...this._answerControlRegistrations()].sort(compareAnswerOrder);
996
+ }, ...(ngDevMode ? [{ debugName: "_answerControls" }] : /* istanbul ignore next */ []));
997
+ _answers = computed(() => this._answerControls().filter((registration) => !registration.disabled), ...(ngDevMode ? [{ debugName: "_answers" }] : /* istanbul ignore next */ []));
998
+ _answered = computed(() => this._answers().some((answer) => this._selectedAnswerIds().includes(answer.id)), ...(ngDevMode ? [{ debugName: "_answered" }] : /* istanbul ignore next */ []));
999
+ status = computed(() => {
1000
+ if (this._skipped()) {
1001
+ return 'skipped';
1002
+ }
1003
+ return this._answered() ? 'answered' : 'unanswered';
1004
+ }, ...(ngDevMode ? [{ debugName: "status" }] : /* istanbul ignore next */ []));
1005
+ _intentionallySkipped = computed(() => this.status() === 'skipped' && !this.required(), ...(ngDevMode ? [{ debugName: "_intentionallySkipped" }] : /* istanbul ignore next */ []));
1006
+ _valid = computed(() => this.disabled() || this._intentionallySkipped() || (!this.externallyInvalid() && this.status() === 'answered'), ...(ngDevMode ? [{ debugName: "_valid" }] : /* istanbul ignore next */ []));
1007
+ invalid = computed(() => !this.disabled() &&
1008
+ !this._intentionallySkipped() &&
1009
+ (this.externallyInvalid() || (this._validationAttempted() && !this._valid())), ...(ngDevMode ? [{ debugName: "invalid" }] : /* istanbul ignore next */ []));
1010
+ hasInputAnswer = computed(() => this._answers().some((answer) => answer.type === 'input'), ...(ngDevMode ? [{ debugName: "hasInputAnswer" }] : /* istanbul ignore next */ []));
1011
+ selectedAnswerIds = this._selectedAnswerIds.asReadonly();
1012
+ resetVersion = this._resetVersion.asReadonly();
1013
+ writtenInputValues = this._writtenInputValues.asReadonly();
1014
+ shortcuts = this._questionnaire.shortcuts;
1015
+ shortcutByChoiceValue = computed(() => {
1016
+ const itemDefinitionByName = this._questionnaire.itemDefinitionByName();
1017
+ if (!itemDefinitionByName) {
1018
+ return null;
1019
+ }
1020
+ return getShortcutByChoiceValue(itemDefinitionByName.get(this.name()), this._questionnaire.shortcuts());
1021
+ }, ...(ngDevMode ? [{ debugName: "shortcutByChoiceValue" }] : /* istanbul ignore next */ []));
1022
+ shortcutByAnswerId = computed(() => {
1023
+ // Prefer definition-based shortcuts only when they actually assigned keys.
1024
+ // An empty Map must fall through so DOM-order shortcuts still work.
1025
+ if ((this.shortcutByChoiceValue()?.size ?? 0) > 0) {
1026
+ return new Map();
1027
+ }
1028
+ const keys = getShortcutKeys(this._questionnaire.shortcuts());
1029
+ const shortcutAnswers = this._answers().filter((answer) => answer.type === 'choice');
1030
+ return new Map(shortcutAnswers.slice(0, keys.length).map((answer, index) => [answer.id, keys[index]]));
1031
+ }, ...(ngDevMode ? [{ debugName: "shortcutByAnswerId" }] : /* istanbul ignore next */ []));
1032
+ _describedBy = computed(() => [...this._descriptionIds(), ...(this.invalid() ? this._errorIds() : []), this.ariaDescribedBy()]
1033
+ .filter(Boolean)
1034
+ .join(' ') || null, ...(ngDevMode ? [{ debugName: "_describedBy" }] : /* istanbul ignore next */ []));
1035
+ _keyShortcuts = computed(() => {
1036
+ const active = this.active();
1037
+ const status = this.status();
1038
+ return ([
1039
+ this.ariaKeyShortcuts(),
1040
+ active ? 'Meta+Enter Control+Enter' : undefined,
1041
+ active && this._answers().length ? 'ArrowUp ArrowDown' : undefined,
1042
+ active && !this._questionnaire.first() ? 'ArrowLeft' : undefined,
1043
+ active && !this._questionnaire.last() && status !== 'unanswered' ? 'ArrowRight' : undefined,
1044
+ ]
1045
+ .filter(Boolean)
1046
+ .join(' ') || null);
1047
+ }, ...(ngDevMode ? [{ debugName: "_keyShortcuts" }] : /* istanbul ignore next */ []));
1048
+ constructor() {
1049
+ effect(() => {
1050
+ const status = this.status();
1051
+ if (this._previousStatus === status) {
1052
+ return;
1053
+ }
1054
+ this._previousStatus = status;
1055
+ this.statusChange.emit(status);
1056
+ });
1057
+ effect((onCleanup) => {
1058
+ const registration = {
1059
+ choices: this._answerControls().flatMap((answer) => answer.type === 'choice' ? [{ disabled: answer.ownDisabled, value: answer.value }] : []),
1060
+ disabled: this._hostDisabled || this.disabledInput(),
1061
+ element: this._elementRef.nativeElement,
1062
+ focus: () => this.focus(),
1063
+ focusInvalid: () => this.focusInvalid(),
1064
+ getAnswerByElement: (element) => this.getAnswerByElement(element),
1065
+ getAnswerByShortcut: (shortcut) => this.getAnswerByShortcut(shortcut),
1066
+ moveAnswerFocus: (element, direction) => this.moveAnswerFocus(element, direction),
1067
+ name: this.name(),
1068
+ required: this.required(),
1069
+ reset: () => this.reset(),
1070
+ skip: () => this.skip(),
1071
+ status: this.status(),
1072
+ validate: () => this.validate(),
1073
+ };
1074
+ onCleanup(this._questionnaire.registerItem(registration));
1075
+ });
1076
+ effect(() => {
1077
+ const multiple = this.multiple();
1078
+ // Collapse multi-selection when switching to single.
1079
+ if (multiple) {
1080
+ return;
1081
+ }
1082
+ this._selectedAnswerIds.update((currentAnswerIds) => {
1083
+ if (currentAnswerIds.length <= 1) {
1084
+ return currentAnswerIds;
1085
+ }
1086
+ const selectedAnswer = this._answers().find((answer) => currentAnswerIds.includes(answer.id));
1087
+ return selectedAnswer ? [selectedAnswer.id] : [];
1088
+ });
1089
+ });
1090
+ effect(() => {
1091
+ this._answers();
1092
+ this.multiple();
1093
+ untracked(() => this.applyPendingControlValue());
1094
+ });
1095
+ }
1096
+ writeValue(value) {
1097
+ this._pendingControlValue = this.normalizeControlValue(value);
1098
+ this.applyPendingControlValue();
1099
+ }
1100
+ registerOnChange(fn) {
1101
+ this.onChange = fn;
1102
+ }
1103
+ registerOnTouched(fn) {
1104
+ this.onTouched = fn;
1105
+ }
1106
+ setDisabledState(isDisabled) {
1107
+ this._cvaDisabled.set(isDisabled);
1108
+ }
1109
+ registerAnswerControl(registration) {
1110
+ this._answerControlRegistrations.update((currentRegistrations) => [
1111
+ ...currentRegistrations.filter((currentRegistration) => currentRegistration.element !== registration.element && currentRegistration.id !== registration.id),
1112
+ registration,
1113
+ ]);
1114
+ return () => {
1115
+ this._answerControlRegistrations.update((currentRegistrations) => currentRegistrations.filter((currentRegistration) => currentRegistration !== registration));
1116
+ };
1117
+ }
1118
+ registerAnswerSelection(answerId, defaultSelected) {
1119
+ if (defaultSelected) {
1120
+ this._defaultSelectedAnswerIds.update((ids) => [...ids.filter((id) => id !== answerId), answerId]);
1121
+ this._selectedAnswerIds.update((currentAnswerIds) => {
1122
+ if (!this.multiple()) {
1123
+ return currentAnswerIds.length ? currentAnswerIds : [answerId];
1124
+ }
1125
+ return currentAnswerIds.includes(answerId) ? currentAnswerIds : [...currentAnswerIds, answerId];
1126
+ });
1127
+ }
1128
+ return () => {
1129
+ this._defaultSelectedAnswerIds.update((ids) => ids.filter((id) => id !== answerId));
1130
+ this._selectedAnswerIds.update((currentAnswerIds) => currentAnswerIds.filter((currentAnswerId) => currentAnswerId !== answerId));
1131
+ };
1132
+ }
1133
+ /**
1134
+ * Registers the bound default for reset and applies the initial-only selection path
1135
+ * in one place so cleanup cannot run before defaults are recorded.
1136
+ */
1137
+ registerBoundAnswerDefault(answerId, defaultSelected) {
1138
+ this.setAnswerDefault(answerId, defaultSelected);
1139
+ return this.registerAnswerSelection(answerId, defaultSelected);
1140
+ }
1141
+ setAnswerDefault(answerId, defaultSelected) {
1142
+ if (defaultSelected) {
1143
+ this._defaultSelectedAnswerIds.update((ids) => (ids.includes(answerId) ? ids : [...ids, answerId]));
1144
+ return;
1145
+ }
1146
+ this._defaultSelectedAnswerIds.update((ids) => ids.filter((id) => id !== answerId));
1147
+ }
1148
+ setAnswerSelectionFromInteraction(answerId, selected) {
1149
+ this._pendingControlValue = undefined;
1150
+ this._skipped.set(false);
1151
+ this.updateAnswerSelected(answerId, selected);
1152
+ this.emitControlValue();
1153
+ }
1154
+ syncControlledAnswerSelection(answerId, selected) {
1155
+ if (selected) {
1156
+ this._skipped.set(false);
1157
+ }
1158
+ this.updateAnswerSelected(answerId, selected);
1159
+ }
1160
+ registerDescription(descriptionId) {
1161
+ this._descriptionIds.update((ids) => (ids.includes(descriptionId) ? ids : [...ids, descriptionId]));
1162
+ return () => this._descriptionIds.update((ids) => ids.filter((id) => id !== descriptionId));
1163
+ }
1164
+ registerError(errorId) {
1165
+ this._errorIds.update((ids) => (ids.includes(errorId) ? ids : [...ids, errorId]));
1166
+ return () => this._errorIds.update((ids) => ids.filter((id) => id !== errorId));
1167
+ }
1168
+ validate() {
1169
+ this._validationAttempted.set(true);
1170
+ if (!this._valid()) {
1171
+ return false;
1172
+ }
1173
+ if (!this._questionnaire.nativeValidation()) {
1174
+ return true;
1175
+ }
1176
+ const invalidAnswer = this._answers().find((answer) => isAnswerFilled(answer) && answer.element.willValidate && !answer.element.validity.valid);
1177
+ if (!invalidAnswer) {
1178
+ return true;
1179
+ }
1180
+ invalidAnswer.element.focus();
1181
+ invalidAnswer.element.reportValidity();
1182
+ return false;
1183
+ }
1184
+ focus() {
1185
+ this._elementRef.nativeElement.focus();
1186
+ }
1187
+ focusInvalid() {
1188
+ const element = this._elementRef.nativeElement;
1189
+ const selectedInput = element.querySelector('input[data-filled][name]:not(:disabled)');
1190
+ const firstControl = element.querySelector('input:not([type=hidden]):not(:disabled), textarea:not(:disabled)');
1191
+ (selectedInput ?? firstControl ?? element).focus();
1192
+ }
1193
+ reset() {
1194
+ this._pendingControlValue = undefined;
1195
+ this._validationAttempted.set(false);
1196
+ this._skipped.set(false);
1197
+ const defaults = this._defaultSelectedAnswerIds();
1198
+ this._selectedAnswerIds.set(this.multiple() ? [...defaults] : defaults.slice(0, 1));
1199
+ this._writtenInputValues.set({});
1200
+ this._resetVersion.update((version) => version + 1);
1201
+ this.emitControlValue();
1202
+ }
1203
+ skip() {
1204
+ if (this.required()) {
1205
+ return;
1206
+ }
1207
+ this._pendingControlValue = undefined;
1208
+ this._selectedAnswerIds.set([]);
1209
+ this._skipped.set(true);
1210
+ this.emitControlValue();
1211
+ }
1212
+ getAnswerByElement(answerElement) {
1213
+ return this._answers().find((answer) => answer.element === answerElement) ?? null;
1214
+ }
1215
+ getAnswerByShortcut(shortcut) {
1216
+ const shortcutByChoiceValue = this.shortcutByChoiceValue();
1217
+ if (shortcutByChoiceValue && shortcutByChoiceValue.size > 0) {
1218
+ const choiceValue = Array.from(shortcutByChoiceValue.entries()).find(([, choiceShortcut]) => choiceShortcut === shortcut)?.[0];
1219
+ return this._answers().find((answer) => answer.type === 'choice' && answer.value === choiceValue) ?? null;
1220
+ }
1221
+ const answerId = Array.from(this.shortcutByAnswerId().entries()).find(([, answerShortcut]) => answerShortcut === shortcut)?.[0];
1222
+ return this._answers().find((answer) => answer.id === answerId) ?? null;
1223
+ }
1224
+ moveAnswerFocus(currentElement, direction) {
1225
+ const answers = this._answers();
1226
+ const element = this._elementRef.nativeElement;
1227
+ const currentIndex = answers.findIndex((answer) => answer.element === currentElement);
1228
+ const currentAnswer = currentIndex < 0 ? null : (answers[currentIndex] ?? null);
1229
+ if (!answers.length ||
1230
+ (isTextEntryTarget(currentElement) && !isEmptyNavigableInput(currentAnswer)) ||
1231
+ (currentIndex < 0 && currentElement !== element)) {
1232
+ return false;
1233
+ }
1234
+ const nextAnswer = currentIndex < 0
1235
+ ? (answers.find(isAnswerFilled) ?? (direction === 'next' ? answers[0] : answers[answers.length - 1]))
1236
+ : answers[(currentIndex + (direction === 'next' ? 1 : -1) + answers.length) % answers.length];
1237
+ if (!nextAnswer || nextAnswer.element === currentElement) {
1238
+ return false;
1239
+ }
1240
+ if (currentIndex >= 0 && isRadioTarget(currentElement) && isRadioTarget(nextAnswer.element)) {
1241
+ return false;
1242
+ }
1243
+ nextAnswer.element.focus();
1244
+ if (nextAnswer.type === 'choice' && isRadioTarget(nextAnswer.element)) {
1245
+ nextAnswer.element.click();
1246
+ }
1247
+ return true;
1248
+ }
1249
+ updateAnswerSelected(answerId, selected) {
1250
+ this._selectedAnswerIds.update((currentAnswerIds) => {
1251
+ if (!selected) {
1252
+ return currentAnswerIds.filter((currentAnswerId) => currentAnswerId !== answerId);
1253
+ }
1254
+ if (!this.multiple()) {
1255
+ return [answerId];
1256
+ }
1257
+ return currentAnswerIds.includes(answerId) ? currentAnswerIds : [...currentAnswerIds, answerId];
1258
+ });
1259
+ }
1260
+ applyPendingControlValue() {
1261
+ if (this._pendingControlValue === undefined) {
1262
+ return;
1263
+ }
1264
+ this.applyControlValue(this._pendingControlValue);
1265
+ }
1266
+ applyControlValue(value) {
1267
+ const answers = this._answers();
1268
+ const selectedValues = new Set(Array.isArray(value) ? value : hasInputValue(value) ? [value] : []);
1269
+ const scalar = Array.isArray(value) ? (value[0] ?? '') : value;
1270
+ const choiceMatch = answers.find((answer) => answer.type === 'choice' && answer.value === scalar);
1271
+ const nextInputValues = {};
1272
+ if (this.multiple()) {
1273
+ for (const answer of answers) {
1274
+ if (answer.type === 'choice') {
1275
+ this.syncControlledAnswerSelection(answer.id, selectedValues.has(answer.value));
1276
+ continue;
1277
+ }
1278
+ nextInputValues[answer.id] = '';
1279
+ this.syncControlledAnswerSelection(answer.id, false);
1280
+ }
1281
+ this._writtenInputValues.set(nextInputValues);
1282
+ return;
1283
+ }
1284
+ for (const answer of answers) {
1285
+ if (answer.type === 'choice') {
1286
+ this.syncControlledAnswerSelection(answer.id, answer.value === scalar);
1287
+ continue;
1288
+ }
1289
+ const text = choiceMatch || !hasInputValue(scalar) ? '' : scalar;
1290
+ nextInputValues[answer.id] = text;
1291
+ this.syncControlledAnswerSelection(answer.id, hasInputValue(text));
1292
+ }
1293
+ this._writtenInputValues.set(nextInputValues);
1294
+ }
1295
+ getControlValue() {
1296
+ if (this._skipped()) {
1297
+ return this.emptyControlValue();
1298
+ }
1299
+ const values = this._answers()
1300
+ .filter((answer) => this._selectedAnswerIds().includes(answer.id))
1301
+ .map((answer) => (answer.type === 'choice' ? answer.value : answer.element.value.trim()))
1302
+ .filter((value) => value.length > 0);
1303
+ if (this.multiple()) {
1304
+ return values;
1305
+ }
1306
+ return values[0] ?? '';
1307
+ }
1308
+ normalizeControlValue(value) {
1309
+ if (this.multiple()) {
1310
+ if (Array.isArray(value)) {
1311
+ return value;
1312
+ }
1313
+ return hasInputValue(value) ? [String(value)] : [];
1314
+ }
1315
+ if (Array.isArray(value)) {
1316
+ return value[0] ?? '';
1317
+ }
1318
+ return value ?? '';
1319
+ }
1320
+ emptyControlValue() {
1321
+ return this.multiple() ? [] : '';
1322
+ }
1323
+ emitControlValue() {
1324
+ this.onChange(this.getControlValue());
1325
+ }
1326
+ /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaireItem, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1327
+ /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.16", type: BrnQuestionnaireItem, isStandalone: true, selector: "fieldset[brnQuestionnaireItem]", inputs: { nameInput: { classPropertyName: "nameInput", publicName: "name", isSignal: true, isRequired: true, transformFunction: null }, multiple: { classPropertyName: "multiple", publicName: "multiple", isSignal: true, isRequired: false, transformFunction: null }, requiredInput: { classPropertyName: "requiredInput", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, disabledInput: { classPropertyName: "disabledInput", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, externallyInvalid: { classPropertyName: "externallyInvalid", publicName: "itemInvalid", isSignal: true, isRequired: false, transformFunction: null }, ariaDescribedBy: { classPropertyName: "ariaDescribedBy", publicName: "aria-describedby", isSignal: true, isRequired: false, transformFunction: null }, ariaKeyShortcuts: { classPropertyName: "ariaKeyShortcuts", publicName: "aria-keyshortcuts", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { statusChange: "statusChange" }, host: { listeners: { "focusout": "onTouched()" }, properties: { "attr.aria-describedby": "_describedBy()", "attr.aria-invalid": "invalid() ? \"true\" : null", "attr.aria-keyshortcuts": "_keyShortcuts()", "attr.data-active": "active() ? \"\" : null", "attr.data-status": "status()", "attr.disabled": "disabled() || null", "attr.hidden": "!active() || null", "attr.inert": "!active() || null", "attr.tabindex": "-1" } }, providers: [BRN_QUESTIONNAIRE_ITEM_VALUE_ACCESSOR, provideBrnQuestionnaireItem(BrnQuestionnaireItem)], exportAs: ["brnQuestionnaireItem"], ngImport: i0 });
1328
+ }
1329
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaireItem, decorators: [{
1330
+ type: Directive,
1331
+ args: [{
1332
+ selector: 'fieldset[brnQuestionnaireItem]',
1333
+ exportAs: 'brnQuestionnaireItem',
1334
+ providers: [BRN_QUESTIONNAIRE_ITEM_VALUE_ACCESSOR, provideBrnQuestionnaireItem(BrnQuestionnaireItem)],
1335
+ host: {
1336
+ '[attr.aria-describedby]': '_describedBy()',
1337
+ '[attr.aria-invalid]': 'invalid() ? "true" : null',
1338
+ '[attr.aria-keyshortcuts]': '_keyShortcuts()',
1339
+ '[attr.data-active]': 'active() ? "" : null',
1340
+ '[attr.data-status]': 'status()',
1341
+ '[attr.disabled]': 'disabled() || null',
1342
+ '[attr.hidden]': '!active() || null',
1343
+ '[attr.inert]': '!active() || null',
1344
+ '[attr.tabindex]': '-1',
1345
+ '(focusout)': 'onTouched()',
1346
+ },
1347
+ }]
1348
+ }], ctorParameters: () => [], propDecorators: { nameInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "name", required: true }] }], multiple: [{ type: i0.Input, args: [{ isSignal: true, alias: "multiple", required: false }] }], requiredInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }], disabledInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], externallyInvalid: [{ type: i0.Input, args: [{ isSignal: true, alias: "itemInvalid", required: false }] }], ariaDescribedBy: [{ type: i0.Input, args: [{ isSignal: true, alias: "aria-describedby", required: false }] }], ariaKeyShortcuts: [{ type: i0.Input, args: [{ isSignal: true, alias: "aria-keyshortcuts", required: false }] }], statusChange: [{ type: i0.Output, args: ["statusChange"] }] } });
1349
+
1350
+ class BrnQuestionnaireNext {
1351
+ _questionnaire = injectBrnQuestionnaire();
1352
+ disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
1353
+ visible = computed(() => this._questionnaire.total() > 1 && !this._questionnaire.last(), ...(ngDevMode ? [{ debugName: "visible" }] : /* istanbul ignore next */ []));
1354
+ status = this._questionnaire.activeItemStatus;
1355
+ shortcut = computed(() => (this.visible() && !this.disabled() ? 'Enter' : null), ...(ngDevMode ? [{ debugName: "shortcut" }] : /* istanbul ignore next */ []));
1356
+ onClick(event) {
1357
+ if (event.defaultPrevented) {
1358
+ return;
1359
+ }
1360
+ this._questionnaire.goNext();
1361
+ }
1362
+ /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaireNext, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1363
+ /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.16", type: BrnQuestionnaireNext, isStandalone: true, selector: "button[brnQuestionnaireNext]", inputs: { disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "type": "button" }, listeners: { "click": "onClick($event)" }, properties: { "attr.aria-hidden": "!visible() || null", "attr.hidden": "!visible() || null", "attr.inert": "!visible() || null", "attr.data-visible": "visible() ? \"\" : null", "attr.data-hidden": "visible() ? null : \"\"", "attr.aria-keyshortcuts": "shortcut() ?? null", "attr.tabindex": "visible() ? null : -1", "attr.disabled": "disabled() || null" } }, exportAs: ["brnQuestionnaireNext"], ngImport: i0 });
1364
+ }
1365
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaireNext, decorators: [{
1366
+ type: Directive,
1367
+ args: [{
1368
+ selector: 'button[brnQuestionnaireNext]',
1369
+ exportAs: 'brnQuestionnaireNext',
1370
+ host: {
1371
+ type: 'button',
1372
+ '[attr.aria-hidden]': '!visible() || null',
1373
+ '[attr.hidden]': '!visible() || null',
1374
+ '[attr.inert]': '!visible() || null',
1375
+ '[attr.data-visible]': 'visible() ? "" : null',
1376
+ '[attr.data-hidden]': 'visible() ? null : ""',
1377
+ '[attr.aria-keyshortcuts]': 'shortcut() ?? null',
1378
+ '[attr.tabindex]': 'visible() ? null : -1',
1379
+ '[attr.disabled]': 'disabled() || null',
1380
+ '(click)': 'onClick($event)',
1381
+ },
1382
+ }]
1383
+ }], propDecorators: { disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }] } });
1384
+
1385
+ class BrnQuestionnairePrevious {
1386
+ _questionnaire = injectBrnQuestionnaire();
1387
+ disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
1388
+ visible = computed(() => this._questionnaire.total() > 1 && !this._questionnaire.first(), ...(ngDevMode ? [{ debugName: "visible" }] : /* istanbul ignore next */ []));
1389
+ status = this._questionnaire.activeItemStatus;
1390
+ onClick(event) {
1391
+ if (event.defaultPrevented) {
1392
+ return;
1393
+ }
1394
+ this._questionnaire.goPrevious();
1395
+ }
1396
+ /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnairePrevious, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1397
+ /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.16", type: BrnQuestionnairePrevious, isStandalone: true, selector: "button[brnQuestionnairePrevious]", inputs: { disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "type": "button" }, listeners: { "click": "onClick($event)" }, properties: { "attr.aria-hidden": "!visible() || null", "attr.hidden": "!visible() || null", "attr.inert": "!visible() || null", "attr.data-visible": "visible() ? \"\" : null", "attr.data-hidden": "visible() ? null : \"\"", "attr.tabindex": "visible() ? null : -1", "attr.disabled": "disabled() || null" } }, exportAs: ["brnQuestionnairePrevious"], ngImport: i0 });
1398
+ }
1399
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnairePrevious, decorators: [{
1400
+ type: Directive,
1401
+ args: [{
1402
+ selector: 'button[brnQuestionnairePrevious]',
1403
+ exportAs: 'brnQuestionnairePrevious',
1404
+ host: {
1405
+ type: 'button',
1406
+ '[attr.aria-hidden]': '!visible() || null',
1407
+ '[attr.hidden]': '!visible() || null',
1408
+ '[attr.inert]': '!visible() || null',
1409
+ '[attr.data-visible]': 'visible() ? "" : null',
1410
+ '[attr.data-hidden]': 'visible() ? null : ""',
1411
+ '[attr.tabindex]': 'visible() ? null : -1',
1412
+ '[attr.disabled]': 'disabled() || null',
1413
+ '(click)': 'onClick($event)',
1414
+ },
1415
+ }]
1416
+ }], propDecorators: { disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }] } });
1417
+
1418
+ class BrnQuestionnaireProgress {
1419
+ _questionnaire = injectBrnQuestionnaire();
1420
+ ariaLabel = input('Questionnaire progress', { ...(ngDevMode ? { debugName: "ariaLabel" } : /* istanbul ignore next */ {}), alias: 'aria-label' });
1421
+ valueText = input('Question %current of %total', ...(ngDevMode ? [{ debugName: "valueText" }] : /* istanbul ignore next */ []));
1422
+ _current = this._questionnaire.current;
1423
+ _total = this._questionnaire.total;
1424
+ first = this._questionnaire.first;
1425
+ last = this._questionnaire.last;
1426
+ current = this._questionnaire.current;
1427
+ total = this._questionnaire.total;
1428
+ _label = computed(() => {
1429
+ const total = this._total();
1430
+ if (!total) {
1431
+ return null;
1432
+ }
1433
+ return this.valueText().replaceAll('%current', String(this._current())).replaceAll('%total', String(total));
1434
+ }, ...(ngDevMode ? [{ debugName: "_label" }] : /* istanbul ignore next */ []));
1435
+ label = this._label;
1436
+ /** Boolean flags marking which segments of the progress bar are filled. */
1437
+ segments = computed(() => Array.from({ length: this._total() }, (_, index) => index < this._current()), ...(ngDevMode ? [{ debugName: "segments" }] : /* istanbul ignore next */ []));
1438
+ /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaireProgress, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1439
+ /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.16", type: BrnQuestionnaireProgress, isStandalone: true, selector: "[brnQuestionnaireProgress]", inputs: { ariaLabel: { classPropertyName: "ariaLabel", publicName: "aria-label", isSignal: true, isRequired: false, transformFunction: null }, valueText: { classPropertyName: "valueText", publicName: "valueText", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "role": "progressbar" }, properties: { "attr.aria-label": "ariaLabel()", "attr.aria-live": "\"polite\"", "attr.aria-valuemax": "_total() || null", "attr.aria-valuemin": "_total() ? 1 : null", "attr.aria-valuenow": "_total() ? _current() : null", "attr.aria-valuetext": "_label()" } }, exportAs: ["brnQuestionnaireProgress"], ngImport: i0 });
1440
+ }
1441
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaireProgress, decorators: [{
1442
+ type: Directive,
1443
+ args: [{
1444
+ selector: '[brnQuestionnaireProgress]',
1445
+ exportAs: 'brnQuestionnaireProgress',
1446
+ host: {
1447
+ role: 'progressbar',
1448
+ '[attr.aria-label]': 'ariaLabel()',
1449
+ '[attr.aria-live]': '"polite"',
1450
+ '[attr.aria-valuemax]': '_total() || null',
1451
+ '[attr.aria-valuemin]': '_total() ? 1 : null',
1452
+ '[attr.aria-valuenow]': '_total() ? _current() : null',
1453
+ '[attr.aria-valuetext]': '_label()',
1454
+ },
1455
+ }]
1456
+ }], propDecorators: { ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "aria-label", required: false }] }], valueText: [{ type: i0.Input, args: [{ isSignal: true, alias: "valueText", required: false }] }] } });
1457
+
1458
+ class BrnQuestionnaireSkip {
1459
+ _questionnaire = injectBrnQuestionnaire();
1460
+ disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
1461
+ visible = computed(() => this._questionnaire.activeItemRequired() === false, ...(ngDevMode ? [{ debugName: "visible" }] : /* istanbul ignore next */ []));
1462
+ status = this._questionnaire.activeItemStatus;
1463
+ onClick(event) {
1464
+ if (event.defaultPrevented) {
1465
+ return;
1466
+ }
1467
+ this._questionnaire.skipCurrent();
1468
+ }
1469
+ /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaireSkip, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1470
+ /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.16", type: BrnQuestionnaireSkip, isStandalone: true, selector: "button[brnQuestionnaireSkip]", inputs: { disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "type": "button" }, listeners: { "click": "onClick($event)" }, properties: { "attr.aria-hidden": "!visible() || null", "attr.hidden": "!visible() || null", "attr.inert": "!visible() || null", "attr.data-visible": "visible() ? \"\" : null", "attr.data-hidden": "visible() ? null : \"\"", "attr.tabindex": "visible() ? null : -1", "attr.disabled": "disabled() || null" } }, exportAs: ["brnQuestionnaireSkip"], ngImport: i0 });
1471
+ }
1472
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaireSkip, decorators: [{
1473
+ type: Directive,
1474
+ args: [{
1475
+ selector: 'button[brnQuestionnaireSkip]',
1476
+ exportAs: 'brnQuestionnaireSkip',
1477
+ host: {
1478
+ type: 'button',
1479
+ '[attr.aria-hidden]': '!visible() || null',
1480
+ '[attr.hidden]': '!visible() || null',
1481
+ '[attr.inert]': '!visible() || null',
1482
+ '[attr.data-visible]': 'visible() ? "" : null',
1483
+ '[attr.data-hidden]': 'visible() ? null : ""',
1484
+ '[attr.tabindex]': 'visible() ? null : -1',
1485
+ '[attr.disabled]': 'disabled() || null',
1486
+ '(click)': 'onClick($event)',
1487
+ },
1488
+ }]
1489
+ }], propDecorators: { disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }] } });
1490
+
1491
+ class BrnQuestionnaireSubmit {
1492
+ _questionnaire = injectBrnQuestionnaire();
1493
+ disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
1494
+ visible = computed(() => this._questionnaire.total() > 0 && this._questionnaire.last(), ...(ngDevMode ? [{ debugName: "visible" }] : /* istanbul ignore next */ []));
1495
+ status = this._questionnaire.activeItemStatus;
1496
+ shortcut = computed(() => (this.visible() && !this.disabled() ? 'Enter' : null), ...(ngDevMode ? [{ debugName: "shortcut" }] : /* istanbul ignore next */ []));
1497
+ /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaireSubmit, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1498
+ /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.16", type: BrnQuestionnaireSubmit, isStandalone: true, selector: "button[brnQuestionnaireSubmit]", inputs: { disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "type": "submit" }, properties: { "attr.aria-hidden": "!visible() || null", "attr.hidden": "!visible() || null", "attr.inert": "!visible() || null", "attr.data-visible": "visible() ? \"\" : null", "attr.data-hidden": "visible() ? null : \"\"", "attr.aria-keyshortcuts": "shortcut() ?? null", "attr.tabindex": "visible() ? null : -1", "attr.disabled": "disabled() || null" } }, exportAs: ["brnQuestionnaireSubmit"], ngImport: i0 });
1499
+ }
1500
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaireSubmit, decorators: [{
1501
+ type: Directive,
1502
+ args: [{
1503
+ selector: 'button[brnQuestionnaireSubmit]',
1504
+ exportAs: 'brnQuestionnaireSubmit',
1505
+ host: {
1506
+ type: 'submit',
1507
+ '[attr.aria-hidden]': '!visible() || null',
1508
+ '[attr.hidden]': '!visible() || null',
1509
+ '[attr.inert]': '!visible() || null',
1510
+ '[attr.data-visible]': 'visible() ? "" : null',
1511
+ '[attr.data-hidden]': 'visible() ? null : ""',
1512
+ '[attr.aria-keyshortcuts]': 'shortcut() ?? null',
1513
+ '[attr.tabindex]': 'visible() ? null : -1',
1514
+ '[attr.disabled]': 'disabled() || null',
1515
+ },
1516
+ }]
1517
+ }], propDecorators: { disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }] } });
1518
+
1519
+ class BrnQuestionnaireTitle {
1520
+ constructor() {
1521
+ injectBrnQuestionnaireItem();
1522
+ }
1523
+ /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaireTitle, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1524
+ /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.16", type: BrnQuestionnaireTitle, isStandalone: true, selector: "legend[brnQuestionnaireTitle]", exportAs: ["brnQuestionnaireTitle"], ngImport: i0 });
1525
+ }
1526
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnQuestionnaireTitle, decorators: [{
1527
+ type: Directive,
1528
+ args: [{
1529
+ selector: 'legend[brnQuestionnaireTitle]',
1530
+ exportAs: 'brnQuestionnaireTitle',
1531
+ }]
1532
+ }], ctorParameters: () => [] });
1533
+
1534
+ const BrnQuestionnaireImports = [
1535
+ BrnQuestionnaire,
1536
+ BrnQuestionnaireProgress,
1537
+ BrnQuestionnaireItem,
1538
+ BrnQuestionnaireTitle,
1539
+ BrnQuestionnaireDescription,
1540
+ BrnQuestionnaireChoices,
1541
+ BrnQuestionnaireChoice,
1542
+ BrnQuestionnaireChoiceInput,
1543
+ BrnQuestionnaireChoiceLabel,
1544
+ BrnQuestionnaireChoiceShortcut,
1545
+ BrnQuestionnaireInput,
1546
+ BrnQuestionnaireError,
1547
+ BrnQuestionnairePrevious,
1548
+ BrnQuestionnaireSkip,
1549
+ BrnQuestionnaireNext,
1550
+ BrnQuestionnaireSubmit,
1551
+ ];
1552
+
1553
+ /**
1554
+ * Generated bundle index. Do not edit.
1555
+ */
1556
+
1557
+ export { BRN_QUESTIONNAIRE_ITEM_VALUE_ACCESSOR, BrnQuestionnaire, BrnQuestionnaireChoice, BrnQuestionnaireChoiceInput, BrnQuestionnaireChoiceLabel, BrnQuestionnaireChoiceShortcut, BrnQuestionnaireChoices, BrnQuestionnaireDescription, BrnQuestionnaireError, BrnQuestionnaireImports, BrnQuestionnaireInput, BrnQuestionnaireItem, BrnQuestionnaireNext, BrnQuestionnairePrevious, BrnQuestionnaireProgress, BrnQuestionnaireSkip, BrnQuestionnaireSubmit, BrnQuestionnaireTitle, compareAnswerOrder, compareItemOrder, createQuestionnaireCollection, getAnswerKeyShortcuts, getCollectionDefinitionWarnings, getCollectionRegistrationWarnings, getInitialItemName, getShortcutByChoiceValue, getShortcutFromKey, getShortcutKeys, hasInputValue, injectBrnQuestionnaire, injectBrnQuestionnaireChoice, injectBrnQuestionnaireItem, isAnswerFilled, isEmptyNavigableInput, isRadioTarget, isTextEntryTarget, provideBrnQuestionnaire, provideBrnQuestionnaireChoice, provideBrnQuestionnaireItem };
1558
+ //# sourceMappingURL=spartan-ng-brain-questionnaire.mjs.map