@trismegisto/angular 3.3.9 → 3.3.11
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.
- package/fesm2022/trismegisto-angular-agent.mjs +458 -73
- package/fesm2022/trismegisto-angular-agent.mjs.map +1 -1
- package/fesm2022/trismegisto-angular-api-exchange.mjs +1 -1
- package/fesm2022/trismegisto-angular-api-exchange.mjs.map +1 -1
- package/fesm2022/trismegisto-angular-attachment.mjs +6 -2
- package/fesm2022/trismegisto-angular-attachment.mjs.map +1 -1
- package/fesm2022/trismegisto-angular-bubble.mjs.map +1 -1
- package/fesm2022/trismegisto-angular-code-viewer.mjs +78 -5
- package/fesm2022/trismegisto-angular-code-viewer.mjs.map +1 -1
- package/fesm2022/trismegisto-angular-data-grid.mjs +51 -7
- package/fesm2022/trismegisto-angular-data-grid.mjs.map +1 -1
- package/fesm2022/trismegisto-angular-icon.mjs +2 -1
- package/fesm2022/trismegisto-angular-icon.mjs.map +1 -1
- package/fesm2022/trismegisto-angular-message-divider.mjs +14 -6
- package/fesm2022/trismegisto-angular-message-divider.mjs.map +1 -1
- package/fesm2022/trismegisto-angular-message-scroller.mjs +14 -0
- package/fesm2022/trismegisto-angular-message-scroller.mjs.map +1 -1
- package/fesm2022/trismegisto-angular-prompt-input.mjs +251 -0
- package/fesm2022/trismegisto-angular-prompt-input.mjs.map +1 -0
- package/fesm2022/trismegisto-angular-prompt-suggestions.mjs +10 -3
- package/fesm2022/trismegisto-angular-prompt-suggestions.mjs.map +1 -1
- package/fesm2022/trismegisto-angular-questionnaire.mjs +420 -0
- package/fesm2022/trismegisto-angular-questionnaire.mjs.map +1 -0
- package/fesm2022/trismegisto-angular-trace.mjs +38 -9
- package/fesm2022/trismegisto-angular-trace.mjs.map +1 -1
- package/fesm2022/trismegisto-angular-webhook.mjs +1 -1
- package/fesm2022/trismegisto-angular-webhook.mjs.map +1 -1
- package/fesm2022/trismegisto-angular.mjs +4 -2
- package/fesm2022/trismegisto-angular.mjs.map +1 -1
- package/package.json +13 -5
- package/types/trismegisto-angular-agent.d.ts +103 -4
- package/types/trismegisto-angular-agent.d.ts.map +1 -1
- package/types/trismegisto-angular-attachment.d.ts +5 -2
- package/types/trismegisto-angular-attachment.d.ts.map +1 -1
- package/types/trismegisto-angular-bubble.d.ts +1 -1
- package/types/trismegisto-angular-code-viewer.d.ts +40 -3
- package/types/trismegisto-angular-code-viewer.d.ts.map +1 -1
- package/types/trismegisto-angular-data-grid.d.ts +27 -2
- package/types/trismegisto-angular-data-grid.d.ts.map +1 -1
- package/types/trismegisto-angular-icon.d.ts +2 -1
- package/types/trismegisto-angular-icon.d.ts.map +1 -1
- package/types/trismegisto-angular-message-divider.d.ts +4 -2
- package/types/trismegisto-angular-message-divider.d.ts.map +1 -1
- package/types/trismegisto-angular-message-scroller.d.ts +5 -0
- package/types/trismegisto-angular-message-scroller.d.ts.map +1 -1
- package/types/trismegisto-angular-prompt-input.d.ts +100 -0
- package/types/trismegisto-angular-prompt-input.d.ts.map +1 -0
- package/types/trismegisto-angular-prompt-suggestions.d.ts +3 -1
- package/types/trismegisto-angular-prompt-suggestions.d.ts.map +1 -1
- package/types/trismegisto-angular-questionnaire.d.ts +97 -0
- package/types/trismegisto-angular-questionnaire.d.ts.map +1 -0
- package/types/trismegisto-angular-trace.d.ts +11 -4
- package/types/trismegisto-angular-trace.d.ts.map +1 -1
- package/types/trismegisto-angular.d.ts +5 -3
- package/types/trismegisto-angular.d.ts.map +1 -1
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { input, model, booleanAttribute, output, inject, Injector, viewChild, computed, signal, afterNextRender, ChangeDetectionStrategy, Component } from '@angular/core';
|
|
3
|
+
import { ButtonComponent } from '@trismegisto/angular/button';
|
|
4
|
+
import { HermesI18nService } from '@trismegisto/angular/i18n';
|
|
5
|
+
import { ProgressComponent } from '@trismegisto/angular/progress';
|
|
6
|
+
import { formatMessage } from '@trismegisto/primitives/i18n';
|
|
7
|
+
import { enabledQuestions, questionnaireProgress, questionnaireAnswer, questionnaireStatus, questionnaireShortcut, toggleQuestionnaireOption, setQuestionnaireText, skipQuestionnaireAnswer, firstIncompleteQuestion, questionnaireResult, canLeaveQuestion, questionnaireShortcutIndex, adjacentQuestion } from '@trismegisto/primitives/questionnaire';
|
|
8
|
+
|
|
9
|
+
// Textos do hm-questionnaire (pt-BR/en/es). Ficam na pasta, fora do HERMES_MESSAGES compartilhado, para não pesar no
|
|
10
|
+
// bundle de quem não usa a peça. O componente escolhe pelo idioma ativo do `HermesI18nService` (`pick`) e aceita
|
|
11
|
+
// sobrescrita parcial pelo input `texts`.
|
|
12
|
+
const QUESTIONNAIRE_MESSAGES_PT_BR = {
|
|
13
|
+
label: 'Perguntas',
|
|
14
|
+
progress: 'Pergunta {current} de {total}',
|
|
15
|
+
previous: 'Anterior',
|
|
16
|
+
next: 'Próxima',
|
|
17
|
+
skip: 'Pular',
|
|
18
|
+
submit: 'Enviar respostas',
|
|
19
|
+
required: 'Responda para continuar.',
|
|
20
|
+
freeform: 'Outra resposta',
|
|
21
|
+
shortcutHint: 'Tecla {key}',
|
|
22
|
+
};
|
|
23
|
+
const QUESTIONNAIRE_MESSAGES_EN = {
|
|
24
|
+
label: 'Questions',
|
|
25
|
+
progress: 'Question {current} of {total}',
|
|
26
|
+
previous: 'Previous',
|
|
27
|
+
next: 'Next',
|
|
28
|
+
skip: 'Skip',
|
|
29
|
+
submit: 'Submit answers',
|
|
30
|
+
required: 'Answer to continue.',
|
|
31
|
+
freeform: 'Other answer',
|
|
32
|
+
shortcutHint: 'Key {key}',
|
|
33
|
+
};
|
|
34
|
+
const QUESTIONNAIRE_MESSAGES_ES = {
|
|
35
|
+
label: 'Preguntas',
|
|
36
|
+
progress: 'Pregunta {current} de {total}',
|
|
37
|
+
previous: 'Anterior',
|
|
38
|
+
next: 'Siguiente',
|
|
39
|
+
skip: 'Omitir',
|
|
40
|
+
submit: 'Enviar respuestas',
|
|
41
|
+
required: 'Responda para continuar.',
|
|
42
|
+
freeform: 'Otra respuesta',
|
|
43
|
+
shortcutHint: 'Tecla {key}',
|
|
44
|
+
};
|
|
45
|
+
/** Catálogos por idioma, para `HermesI18nService.pick`. */
|
|
46
|
+
const QUESTIONNAIRE_MESSAGES = {
|
|
47
|
+
'pt-BR': QUESTIONNAIRE_MESSAGES_PT_BR,
|
|
48
|
+
en: QUESTIONNAIRE_MESSAGES_EN,
|
|
49
|
+
es: QUESTIONNAIRE_MESSAGES_ES,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
let sequence = 0;
|
|
53
|
+
/**
|
|
54
|
+
* Perguntas em sequência para a pessoa esclarecer o pedido antes de o agente seguir: uma por vez, com respostas
|
|
55
|
+
* prontas (uma ou várias), resposta livre, pular nas opcionais, atalhos de teclado e progresso. Pergunta com
|
|
56
|
+
* `disabled` (valor ou função das respostas) sai da sequência. O app recebe as respostas em `submitted` e decide o
|
|
57
|
+
* resto: onde o questionário fica (cartão, diálogo), guardar, enviar, cancelar.
|
|
58
|
+
*
|
|
59
|
+
* `[(answers)]` e `[(active)]` deixam o app retomar de onde a pessoa parou ou voltar a uma pergunta inválida.
|
|
60
|
+
*
|
|
61
|
+
* Teclado: setas e espaço nas opções (nativo); com `shortcuts`, a letra ou o número marca a opção; Enter numa opção
|
|
62
|
+
* única ou na resposta livre segue; Ctrl/Cmd+Enter segue de qualquer ponto (ou envia, na última); fora de um campo,
|
|
63
|
+
* seta para a esquerda volta e para a direita segue.
|
|
64
|
+
*/
|
|
65
|
+
class QuestionnaireComponent {
|
|
66
|
+
questions = input.required(...(ngDevMode ? [{ debugName: "questions" }] : /* istanbul ignore next */ []));
|
|
67
|
+
/** Respostas por id da pergunta. O app pode trazer as de uma sessão anterior. */
|
|
68
|
+
answers = model({}, ...(ngDevMode ? [{ debugName: "answers" }] : /* istanbul ignore next */ []));
|
|
69
|
+
/** Id da pergunta à vista. Vazio: a primeira que vale. */
|
|
70
|
+
active = model('', ...(ngDevMode ? [{ debugName: "active" }] : /* istanbul ignore next */ []));
|
|
71
|
+
/** Atalho por letra ou número em cada opção. */
|
|
72
|
+
shortcuts = input(null, ...(ngDevMode ? [{ debugName: "shortcuts" }] : /* istanbul ignore next */ []));
|
|
73
|
+
/** Validação do app, além de exigir resposta nas obrigatórias. */
|
|
74
|
+
validate = input(null, ...(ngDevMode ? [{ debugName: "validate" }] : /* istanbul ignore next */ []));
|
|
75
|
+
showProgress = input(true, { ...(ngDevMode ? { debugName: "showProgress" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
76
|
+
/** Enquanto o app envia: trava os campos e mostra o andamento no botão. */
|
|
77
|
+
busy = input(false, { ...(ngDevMode ? { debugName: "busy" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
78
|
+
/** Nome acessível do grupo. Padrão: "Perguntas". */
|
|
79
|
+
label = input('', ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
|
|
80
|
+
/** Texto do botão final. Padrão: "Enviar respostas". */
|
|
81
|
+
submitLabel = input('', ...(ngDevMode ? [{ debugName: "submitLabel" }] : /* istanbul ignore next */ []));
|
|
82
|
+
texts = input({}, ...(ngDevMode ? [{ debugName: "texts" }] : /* istanbul ignore next */ []));
|
|
83
|
+
/** As respostas das perguntas que valem, depois de todas passarem pela validação. */
|
|
84
|
+
submitted = output();
|
|
85
|
+
#i18n = inject(HermesI18nService);
|
|
86
|
+
#injector = inject(Injector);
|
|
87
|
+
title = viewChild('title', ...(ngDevMode ? [{ debugName: "title" }] : /* istanbul ignore next */ []));
|
|
88
|
+
text = computed(() => ({
|
|
89
|
+
...this.#i18n.pick(QUESTIONNAIRE_MESSAGES, QUESTIONNAIRE_MESSAGES_PT_BR),
|
|
90
|
+
...this.texts(),
|
|
91
|
+
}), ...(ngDevMode ? [{ debugName: "text" }] : /* istanbul ignore next */ []));
|
|
92
|
+
groupName = `hm-questionnaire-${++sequence}`;
|
|
93
|
+
descriptionId = `${this.groupName}-description`;
|
|
94
|
+
errorId = `${this.groupName}-error`;
|
|
95
|
+
/** Erro da pergunta à vista; some quando a resposta muda ou a pergunta troca. */
|
|
96
|
+
error = signal('', ...(ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []));
|
|
97
|
+
enabled = computed(() => enabledQuestions(this.questions(), this.answers()), ...(ngDevMode ? [{ debugName: "enabled" }] : /* istanbul ignore next */ []));
|
|
98
|
+
question = computed(() => {
|
|
99
|
+
const enabled = this.enabled();
|
|
100
|
+
return enabled.find((question) => question.id === this.active()) ?? enabled[0] ?? null;
|
|
101
|
+
}, ...(ngDevMode ? [{ debugName: "question" }] : /* istanbul ignore next */ []));
|
|
102
|
+
progress = computed(() => questionnaireProgress(this.questions(), this.answers(), this.question()?.id ?? ''), ...(ngDevMode ? [{ debugName: "progress" }] : /* istanbul ignore next */ []));
|
|
103
|
+
progressText = computed(() => formatMessage(this.text().progress, { current: this.progress().current, total: this.progress().total }), ...(ngDevMode ? [{ debugName: "progressText" }] : /* istanbul ignore next */ []));
|
|
104
|
+
hasPrevious = computed(() => !!this.neighbour(-1), ...(ngDevMode ? [{ debugName: "hasPrevious" }] : /* istanbul ignore next */ []));
|
|
105
|
+
hasNext = computed(() => !!this.neighbour(1), ...(ngDevMode ? [{ debugName: "hasNext" }] : /* istanbul ignore next */ []));
|
|
106
|
+
answerOf(question) {
|
|
107
|
+
return questionnaireAnswer(this.answers(), question.id);
|
|
108
|
+
}
|
|
109
|
+
status(question) {
|
|
110
|
+
return questionnaireStatus(this.answers(), question.id);
|
|
111
|
+
}
|
|
112
|
+
isChecked(question, optionId) {
|
|
113
|
+
return this.answerOf(question).options.includes(optionId);
|
|
114
|
+
}
|
|
115
|
+
shortcutOf(index) {
|
|
116
|
+
const mode = this.shortcuts();
|
|
117
|
+
return mode ? questionnaireShortcut(index, mode) : '';
|
|
118
|
+
}
|
|
119
|
+
describedBy(question) {
|
|
120
|
+
return [question.description ? this.descriptionId : '', this.error() ? this.errorId : ''].filter(Boolean).join(' ') || null;
|
|
121
|
+
}
|
|
122
|
+
toggle(question, optionId) {
|
|
123
|
+
this.update(question, toggleQuestionnaireOption(question, this.answerOf(question), optionId));
|
|
124
|
+
}
|
|
125
|
+
write(question, value) {
|
|
126
|
+
this.update(question, setQuestionnaireText(question, this.answerOf(question), value));
|
|
127
|
+
}
|
|
128
|
+
/** Pula a pergunta opcional e segue. */
|
|
129
|
+
skip() {
|
|
130
|
+
const question = this.question();
|
|
131
|
+
if (!question?.optional)
|
|
132
|
+
return;
|
|
133
|
+
this.update(question, skipQuestionnaireAnswer());
|
|
134
|
+
if (this.hasNext())
|
|
135
|
+
this.next();
|
|
136
|
+
}
|
|
137
|
+
previous() {
|
|
138
|
+
const target = this.neighbour(-1);
|
|
139
|
+
if (target)
|
|
140
|
+
this.goTo(target.id);
|
|
141
|
+
}
|
|
142
|
+
/** Segue para a próxima pergunta, se a atual estiver em ordem. Na última, envia. */
|
|
143
|
+
next() {
|
|
144
|
+
const question = this.question();
|
|
145
|
+
if (!question || !this.check(question))
|
|
146
|
+
return;
|
|
147
|
+
const target = this.neighbour(1);
|
|
148
|
+
if (target)
|
|
149
|
+
this.goTo(target.id);
|
|
150
|
+
else
|
|
151
|
+
this.submit();
|
|
152
|
+
}
|
|
153
|
+
/** Confere tudo o que vale; com algo faltando, volta para a primeira pergunta pendente e mostra o motivo. */
|
|
154
|
+
submit() {
|
|
155
|
+
if (this.busy())
|
|
156
|
+
return;
|
|
157
|
+
const current = this.question();
|
|
158
|
+
if (current && !this.check(current))
|
|
159
|
+
return;
|
|
160
|
+
const pending = firstIncompleteQuestion(this.questions(), this.answers());
|
|
161
|
+
if (pending) {
|
|
162
|
+
this.goTo(pending.id);
|
|
163
|
+
this.check(pending);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
for (const question of this.enabled()) {
|
|
167
|
+
const message = this.validate()?.(question, this.answerOf(question), this.answers());
|
|
168
|
+
if (message) {
|
|
169
|
+
this.goTo(question.id);
|
|
170
|
+
this.error.set(message);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
this.submitted.emit(questionnaireResult(this.questions(), this.answers()));
|
|
175
|
+
}
|
|
176
|
+
onKeydown(event) {
|
|
177
|
+
const question = this.question();
|
|
178
|
+
if (!question || this.busy())
|
|
179
|
+
return;
|
|
180
|
+
const target = event.target;
|
|
181
|
+
const typing = target instanceof HTMLInputElement && target.type === 'text';
|
|
182
|
+
const choice = target instanceof HTMLInputElement && (target.type === 'radio' || target.type === 'checkbox');
|
|
183
|
+
if (event.key === 'Enter' && (event.ctrlKey || event.metaKey)) {
|
|
184
|
+
event.preventDefault();
|
|
185
|
+
this.next();
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (event.key === 'Enter' && (typing || (choice && !question.multiple))) {
|
|
189
|
+
event.preventDefault();
|
|
190
|
+
this.next();
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (typing || event.ctrlKey || event.metaKey || event.altKey)
|
|
194
|
+
return;
|
|
195
|
+
if (!choice && event.key === 'ArrowLeft') {
|
|
196
|
+
event.preventDefault();
|
|
197
|
+
this.previous();
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (!choice && event.key === 'ArrowRight') {
|
|
201
|
+
event.preventDefault();
|
|
202
|
+
if (canLeaveQuestion(question, this.answers()))
|
|
203
|
+
this.next();
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const mode = this.shortcuts();
|
|
207
|
+
const options = question.options ?? [];
|
|
208
|
+
if (!mode || !options.length)
|
|
209
|
+
return;
|
|
210
|
+
const index = questionnaireShortcutIndex(event.key, mode, options.length);
|
|
211
|
+
if (index === -1)
|
|
212
|
+
return;
|
|
213
|
+
event.preventDefault();
|
|
214
|
+
this.toggle(question, options[index].id);
|
|
215
|
+
const host = this.title()?.nativeElement.closest('fieldset');
|
|
216
|
+
host?.querySelectorAll('.hm-questionnaire__control')[index]?.focus();
|
|
217
|
+
}
|
|
218
|
+
neighbour(step) {
|
|
219
|
+
const question = this.question();
|
|
220
|
+
return question ? adjacentQuestion(this.questions(), this.answers(), question.id, step) : null;
|
|
221
|
+
}
|
|
222
|
+
update(question, answer) {
|
|
223
|
+
this.answers.set({ ...this.answers(), [question.id]: answer });
|
|
224
|
+
this.error.set('');
|
|
225
|
+
}
|
|
226
|
+
/** Pode sair da pergunta: responder (ou pular, se opcional) e passar pela validação do app. */
|
|
227
|
+
check(question) {
|
|
228
|
+
if (!canLeaveQuestion(question, this.answers()) && !question.optional) {
|
|
229
|
+
this.error.set(this.text().required);
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
const message = this.validate()?.(question, this.answerOf(question), this.answers()) ?? null;
|
|
233
|
+
this.error.set(message ?? '');
|
|
234
|
+
return !message;
|
|
235
|
+
}
|
|
236
|
+
/** Troca de pergunta e leva o foco ao título, para quem usa leitor de tela saber onde está. */
|
|
237
|
+
goTo(id) {
|
|
238
|
+
if (id !== this.question()?.id)
|
|
239
|
+
this.error.set('');
|
|
240
|
+
this.active.set(id);
|
|
241
|
+
afterNextRender(() => this.title()?.nativeElement.focus(), { injector: this.#injector });
|
|
242
|
+
}
|
|
243
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.24", ngImport: i0, type: QuestionnaireComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
244
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.24", type: QuestionnaireComponent, isStandalone: true, selector: "hm-questionnaire", inputs: { questions: { classPropertyName: "questions", publicName: "questions", isSignal: true, isRequired: true, transformFunction: null }, answers: { classPropertyName: "answers", publicName: "answers", isSignal: true, isRequired: false, transformFunction: null }, active: { classPropertyName: "active", publicName: "active", isSignal: true, isRequired: false, transformFunction: null }, shortcuts: { classPropertyName: "shortcuts", publicName: "shortcuts", isSignal: true, isRequired: false, transformFunction: null }, validate: { classPropertyName: "validate", publicName: "validate", isSignal: true, isRequired: false, transformFunction: null }, showProgress: { classPropertyName: "showProgress", publicName: "showProgress", isSignal: true, isRequired: false, transformFunction: null }, busy: { classPropertyName: "busy", publicName: "busy", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, submitLabel: { classPropertyName: "submitLabel", publicName: "submitLabel", isSignal: true, isRequired: false, transformFunction: null }, texts: { classPropertyName: "texts", publicName: "texts", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { answers: "answersChange", active: "activeChange", submitted: "submitted" }, host: { attributes: { "role": "group" }, listeners: { "keydown": "onKeydown($event)" }, properties: { "attr.aria-label": "label() || text().label", "attr.data-shortcuts": "shortcuts()" }, classAttribute: "hm-questionnaire" }, viewQueries: [{ propertyName: "title", first: true, predicate: ["title"], descendants: true, isSignal: true }], ngImport: i0, template: `
|
|
245
|
+
@if (question(); as q) {
|
|
246
|
+
@if (showProgress() && progress().total > 1) {
|
|
247
|
+
<div class="hm-questionnaire__progress">
|
|
248
|
+
<hm-progress size="small" [value]="progress().completed" [max]="progress().total" [label]="progressText()" />
|
|
249
|
+
</div>
|
|
250
|
+
}
|
|
251
|
+
<fieldset
|
|
252
|
+
class="hm-questionnaire__item"
|
|
253
|
+
[attr.data-status]="status(q)"
|
|
254
|
+
[attr.data-invalid]="error() ? '' : null"
|
|
255
|
+
[attr.aria-describedby]="describedBy(q)"
|
|
256
|
+
[disabled]="busy()"
|
|
257
|
+
>
|
|
258
|
+
<legend class="hm-questionnaire__title" tabindex="-1" #title>{{ q.title }}</legend>
|
|
259
|
+
@if (q.description) {
|
|
260
|
+
<p class="hm-questionnaire__description" [id]="descriptionId">{{ q.description }}</p>
|
|
261
|
+
}
|
|
262
|
+
@if (q.options?.length) {
|
|
263
|
+
<div class="hm-questionnaire__choices">
|
|
264
|
+
@for (option of q.options; track option.id; let index = $index) {
|
|
265
|
+
<label class="hm-questionnaire__choice" [class.hm-questionnaire__choice--checked]="isChecked(q, option.id)">
|
|
266
|
+
<input
|
|
267
|
+
class="hm-questionnaire__control"
|
|
268
|
+
[type]="q.multiple ? 'checkbox' : 'radio'"
|
|
269
|
+
[name]="groupName"
|
|
270
|
+
[value]="option.id"
|
|
271
|
+
[checked]="isChecked(q, option.id)"
|
|
272
|
+
[attr.aria-keyshortcuts]="shortcutOf(index) || null"
|
|
273
|
+
(change)="toggle(q, option.id)"
|
|
274
|
+
/>
|
|
275
|
+
<span class="hm-questionnaire__choice-text">
|
|
276
|
+
<span class="hm-questionnaire__choice-label">{{ option.label }}</span>
|
|
277
|
+
@if (option.description) {
|
|
278
|
+
<span class="hm-questionnaire__choice-description">{{ option.description }}</span>
|
|
279
|
+
}
|
|
280
|
+
</span>
|
|
281
|
+
@if (shortcutOf(index); as key) {
|
|
282
|
+
<kbd class="hm-questionnaire__key" aria-hidden="true">{{ key }}</kbd>
|
|
283
|
+
}
|
|
284
|
+
</label>
|
|
285
|
+
}
|
|
286
|
+
</div>
|
|
287
|
+
}
|
|
288
|
+
@if (q.freeform) {
|
|
289
|
+
<label class="hm-questionnaire__freeform">
|
|
290
|
+
<span class="hm-questionnaire__freeform-label">{{ q.freeformLabel || text().freeform }}</span>
|
|
291
|
+
<input
|
|
292
|
+
class="hm-questionnaire__input"
|
|
293
|
+
type="text"
|
|
294
|
+
[value]="answerOf(q).text"
|
|
295
|
+
[attr.aria-invalid]="error() ? 'true' : null"
|
|
296
|
+
(input)="write(q, $any($event.target).value)"
|
|
297
|
+
/>
|
|
298
|
+
</label>
|
|
299
|
+
}
|
|
300
|
+
@if (error()) {
|
|
301
|
+
<p class="hm-questionnaire__error" [id]="errorId" role="alert">{{ error() }}</p>
|
|
302
|
+
}
|
|
303
|
+
</fieldset>
|
|
304
|
+
<div class="hm-questionnaire__actions">
|
|
305
|
+
@if (hasPrevious()) {
|
|
306
|
+
<hm-button emphasis="minimal" size="small" [disabled]="busy()" (clicked)="previous()">{{ text().previous }}</hm-button>
|
|
307
|
+
}
|
|
308
|
+
<span class="hm-questionnaire__spacer"></span>
|
|
309
|
+
@if (q.optional && status(q) === 'unanswered') {
|
|
310
|
+
<hm-button emphasis="medium" size="small" [disabled]="busy()" (clicked)="skip()">{{ text().skip }}</hm-button>
|
|
311
|
+
}
|
|
312
|
+
@if (hasNext()) {
|
|
313
|
+
<hm-button emphasis="high" size="small" [disabled]="busy()" (clicked)="next()">{{ text().next }}</hm-button>
|
|
314
|
+
} @else {
|
|
315
|
+
<hm-button emphasis="high" size="small" [loading]="busy()" (clicked)="submit()">{{ submitLabel() || text().submit }}</hm-button>
|
|
316
|
+
}
|
|
317
|
+
</div>
|
|
318
|
+
}
|
|
319
|
+
`, isInline: true, dependencies: [{ kind: "component", type: ButtonComponent, selector: "hm-button", inputs: ["emphasis", "intent", "size", "type", "icon", "iconDirection", "iconEnd", "disabled", "loading", "loadingState", "block", "link", "newTab", "caret", "inMenu", "toggle", "pressed"], outputs: ["loadingStateChange", "pressedChange", "clicked"] }, { kind: "component", type: ProgressComponent, selector: "hm-progress", inputs: ["value", "max", "label", "labelHidden", "showValue", "indeterminate", "intent", "size", "hint", "shape"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
320
|
+
}
|
|
321
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.24", ngImport: i0, type: QuestionnaireComponent, decorators: [{
|
|
322
|
+
type: Component,
|
|
323
|
+
args: [{
|
|
324
|
+
selector: 'hm-questionnaire',
|
|
325
|
+
imports: [ButtonComponent, ProgressComponent],
|
|
326
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
327
|
+
host: {
|
|
328
|
+
class: 'hm-questionnaire',
|
|
329
|
+
role: 'group',
|
|
330
|
+
'[attr.aria-label]': 'label() || text().label',
|
|
331
|
+
'[attr.data-shortcuts]': 'shortcuts()',
|
|
332
|
+
'(keydown)': 'onKeydown($event)',
|
|
333
|
+
},
|
|
334
|
+
template: `
|
|
335
|
+
@if (question(); as q) {
|
|
336
|
+
@if (showProgress() && progress().total > 1) {
|
|
337
|
+
<div class="hm-questionnaire__progress">
|
|
338
|
+
<hm-progress size="small" [value]="progress().completed" [max]="progress().total" [label]="progressText()" />
|
|
339
|
+
</div>
|
|
340
|
+
}
|
|
341
|
+
<fieldset
|
|
342
|
+
class="hm-questionnaire__item"
|
|
343
|
+
[attr.data-status]="status(q)"
|
|
344
|
+
[attr.data-invalid]="error() ? '' : null"
|
|
345
|
+
[attr.aria-describedby]="describedBy(q)"
|
|
346
|
+
[disabled]="busy()"
|
|
347
|
+
>
|
|
348
|
+
<legend class="hm-questionnaire__title" tabindex="-1" #title>{{ q.title }}</legend>
|
|
349
|
+
@if (q.description) {
|
|
350
|
+
<p class="hm-questionnaire__description" [id]="descriptionId">{{ q.description }}</p>
|
|
351
|
+
}
|
|
352
|
+
@if (q.options?.length) {
|
|
353
|
+
<div class="hm-questionnaire__choices">
|
|
354
|
+
@for (option of q.options; track option.id; let index = $index) {
|
|
355
|
+
<label class="hm-questionnaire__choice" [class.hm-questionnaire__choice--checked]="isChecked(q, option.id)">
|
|
356
|
+
<input
|
|
357
|
+
class="hm-questionnaire__control"
|
|
358
|
+
[type]="q.multiple ? 'checkbox' : 'radio'"
|
|
359
|
+
[name]="groupName"
|
|
360
|
+
[value]="option.id"
|
|
361
|
+
[checked]="isChecked(q, option.id)"
|
|
362
|
+
[attr.aria-keyshortcuts]="shortcutOf(index) || null"
|
|
363
|
+
(change)="toggle(q, option.id)"
|
|
364
|
+
/>
|
|
365
|
+
<span class="hm-questionnaire__choice-text">
|
|
366
|
+
<span class="hm-questionnaire__choice-label">{{ option.label }}</span>
|
|
367
|
+
@if (option.description) {
|
|
368
|
+
<span class="hm-questionnaire__choice-description">{{ option.description }}</span>
|
|
369
|
+
}
|
|
370
|
+
</span>
|
|
371
|
+
@if (shortcutOf(index); as key) {
|
|
372
|
+
<kbd class="hm-questionnaire__key" aria-hidden="true">{{ key }}</kbd>
|
|
373
|
+
}
|
|
374
|
+
</label>
|
|
375
|
+
}
|
|
376
|
+
</div>
|
|
377
|
+
}
|
|
378
|
+
@if (q.freeform) {
|
|
379
|
+
<label class="hm-questionnaire__freeform">
|
|
380
|
+
<span class="hm-questionnaire__freeform-label">{{ q.freeformLabel || text().freeform }}</span>
|
|
381
|
+
<input
|
|
382
|
+
class="hm-questionnaire__input"
|
|
383
|
+
type="text"
|
|
384
|
+
[value]="answerOf(q).text"
|
|
385
|
+
[attr.aria-invalid]="error() ? 'true' : null"
|
|
386
|
+
(input)="write(q, $any($event.target).value)"
|
|
387
|
+
/>
|
|
388
|
+
</label>
|
|
389
|
+
}
|
|
390
|
+
@if (error()) {
|
|
391
|
+
<p class="hm-questionnaire__error" [id]="errorId" role="alert">{{ error() }}</p>
|
|
392
|
+
}
|
|
393
|
+
</fieldset>
|
|
394
|
+
<div class="hm-questionnaire__actions">
|
|
395
|
+
@if (hasPrevious()) {
|
|
396
|
+
<hm-button emphasis="minimal" size="small" [disabled]="busy()" (clicked)="previous()">{{ text().previous }}</hm-button>
|
|
397
|
+
}
|
|
398
|
+
<span class="hm-questionnaire__spacer"></span>
|
|
399
|
+
@if (q.optional && status(q) === 'unanswered') {
|
|
400
|
+
<hm-button emphasis="medium" size="small" [disabled]="busy()" (clicked)="skip()">{{ text().skip }}</hm-button>
|
|
401
|
+
}
|
|
402
|
+
@if (hasNext()) {
|
|
403
|
+
<hm-button emphasis="high" size="small" [disabled]="busy()" (clicked)="next()">{{ text().next }}</hm-button>
|
|
404
|
+
} @else {
|
|
405
|
+
<hm-button emphasis="high" size="small" [loading]="busy()" (clicked)="submit()">{{ submitLabel() || text().submit }}</hm-button>
|
|
406
|
+
}
|
|
407
|
+
</div>
|
|
408
|
+
}
|
|
409
|
+
`,
|
|
410
|
+
}]
|
|
411
|
+
}], propDecorators: { questions: [{ type: i0.Input, args: [{ isSignal: true, alias: "questions", required: true }] }], answers: [{ type: i0.Input, args: [{ isSignal: true, alias: "answers", required: false }] }, { type: i0.Output, args: ["answersChange"] }], active: [{ type: i0.Input, args: [{ isSignal: true, alias: "active", required: false }] }, { type: i0.Output, args: ["activeChange"] }], shortcuts: [{ type: i0.Input, args: [{ isSignal: true, alias: "shortcuts", required: false }] }], validate: [{ type: i0.Input, args: [{ isSignal: true, alias: "validate", required: false }] }], showProgress: [{ type: i0.Input, args: [{ isSignal: true, alias: "showProgress", required: false }] }], busy: [{ type: i0.Input, args: [{ isSignal: true, alias: "busy", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], submitLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "submitLabel", required: false }] }], texts: [{ type: i0.Input, args: [{ isSignal: true, alias: "texts", required: false }] }], submitted: [{ type: i0.Output, args: ["submitted"] }], title: [{ type: i0.ViewChild, args: ['title', { isSignal: true }] }] } });
|
|
412
|
+
|
|
413
|
+
// Ponto de import `@trismegisto/angular/questionnaire` (secundário do ng-packagr): o que o público usa sai daqui.
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Generated bundle index. Do not edit.
|
|
417
|
+
*/
|
|
418
|
+
|
|
419
|
+
export { QUESTIONNAIRE_MESSAGES, QUESTIONNAIRE_MESSAGES_EN, QUESTIONNAIRE_MESSAGES_ES, QUESTIONNAIRE_MESSAGES_PT_BR, QuestionnaireComponent };
|
|
420
|
+
//# sourceMappingURL=trismegisto-angular-questionnaire.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trismegisto-angular-questionnaire.mjs","sources":["../../src/questionnaire/questionnaire-messages.ts","../../src/questionnaire/questionnaire.component.ts","../../src/questionnaire/index.ts","../../src/questionnaire/trismegisto-angular-questionnaire.ts"],"sourcesContent":["// Textos do hm-questionnaire (pt-BR/en/es). Ficam na pasta, fora do HERMES_MESSAGES compartilhado, para não pesar no\n// bundle de quem não usa a peça. O componente escolhe pelo idioma ativo do `HermesI18nService` (`pick`) e aceita\n// sobrescrita parcial pelo input `texts`.\n\nexport interface QuestionnaireMessages {\n label: string;\n progress: string;\n previous: string;\n next: string;\n skip: string;\n submit: string;\n required: string;\n freeform: string;\n shortcutHint: string;\n}\n\nexport const QUESTIONNAIRE_MESSAGES_PT_BR: QuestionnaireMessages = {\n label: 'Perguntas',\n progress: 'Pergunta {current} de {total}',\n previous: 'Anterior',\n next: 'Próxima',\n skip: 'Pular',\n submit: 'Enviar respostas',\n required: 'Responda para continuar.',\n freeform: 'Outra resposta',\n shortcutHint: 'Tecla {key}',\n};\n\nexport const QUESTIONNAIRE_MESSAGES_EN: QuestionnaireMessages = {\n label: 'Questions',\n progress: 'Question {current} of {total}',\n previous: 'Previous',\n next: 'Next',\n skip: 'Skip',\n submit: 'Submit answers',\n required: 'Answer to continue.',\n freeform: 'Other answer',\n shortcutHint: 'Key {key}',\n};\n\nexport const QUESTIONNAIRE_MESSAGES_ES: QuestionnaireMessages = {\n label: 'Preguntas',\n progress: 'Pregunta {current} de {total}',\n previous: 'Anterior',\n next: 'Siguiente',\n skip: 'Omitir',\n submit: 'Enviar respuestas',\n required: 'Responda para continuar.',\n freeform: 'Otra respuesta',\n shortcutHint: 'Tecla {key}',\n};\n\n/** Catálogos por idioma, para `HermesI18nService.pick`. */\nexport const QUESTIONNAIRE_MESSAGES: Readonly<Record<string, QuestionnaireMessages>> = {\n 'pt-BR': QUESTIONNAIRE_MESSAGES_PT_BR,\n en: QUESTIONNAIRE_MESSAGES_EN,\n es: QUESTIONNAIRE_MESSAGES_ES,\n};\n","import {\n ChangeDetectionStrategy,\n Component,\n ElementRef,\n Injector,\n afterNextRender,\n booleanAttribute,\n computed,\n inject,\n input,\n model,\n output,\n signal,\n viewChild,\n} from '@angular/core';\nimport { ButtonComponent } from '@trismegisto/angular/button';\nimport { HermesI18nService } from '@trismegisto/angular/i18n';\nimport { ProgressComponent } from '@trismegisto/angular/progress';\nimport { formatMessage } from '@trismegisto/primitives/i18n';\nimport {\n adjacentQuestion,\n canLeaveQuestion,\n enabledQuestions,\n firstIncompleteQuestion,\n questionnaireAnswer,\n questionnaireProgress,\n questionnaireResult,\n questionnaireShortcut,\n questionnaireShortcutIndex,\n questionnaireStatus,\n setQuestionnaireText,\n skipQuestionnaireAnswer,\n toggleQuestionnaireOption,\n type QuestionnaireAnswer,\n type QuestionnaireAnswers,\n type QuestionnaireQuestion,\n type QuestionnaireShortcuts,\n} from '@trismegisto/primitives/questionnaire';\nimport { QUESTIONNAIRE_MESSAGES, QUESTIONNAIRE_MESSAGES_PT_BR, type QuestionnaireMessages } from './questionnaire-messages';\n\n/** Validação do app, além de \"responder antes de seguir\": devolve o erro (texto pronto) ou `null`. */\nexport type QuestionnaireValidator = (\n question: QuestionnaireQuestion,\n answer: QuestionnaireAnswer,\n answers: QuestionnaireAnswers,\n) => string | null;\n\nlet sequence = 0;\n\n/**\n * Perguntas em sequência para a pessoa esclarecer o pedido antes de o agente seguir: uma por vez, com respostas\n * prontas (uma ou várias), resposta livre, pular nas opcionais, atalhos de teclado e progresso. Pergunta com\n * `disabled` (valor ou função das respostas) sai da sequência. O app recebe as respostas em `submitted` e decide o\n * resto: onde o questionário fica (cartão, diálogo), guardar, enviar, cancelar.\n *\n * `[(answers)]` e `[(active)]` deixam o app retomar de onde a pessoa parou ou voltar a uma pergunta inválida.\n *\n * Teclado: setas e espaço nas opções (nativo); com `shortcuts`, a letra ou o número marca a opção; Enter numa opção\n * única ou na resposta livre segue; Ctrl/Cmd+Enter segue de qualquer ponto (ou envia, na última); fora de um campo,\n * seta para a esquerda volta e para a direita segue.\n */\n@Component({\n selector: 'hm-questionnaire',\n imports: [ButtonComponent, ProgressComponent],\n changeDetection: ChangeDetectionStrategy.OnPush,\n host: {\n class: 'hm-questionnaire',\n role: 'group',\n '[attr.aria-label]': 'label() || text().label',\n '[attr.data-shortcuts]': 'shortcuts()',\n '(keydown)': 'onKeydown($event)',\n },\n template: `\n @if (question(); as q) {\n @if (showProgress() && progress().total > 1) {\n <div class=\"hm-questionnaire__progress\">\n <hm-progress size=\"small\" [value]=\"progress().completed\" [max]=\"progress().total\" [label]=\"progressText()\" />\n </div>\n }\n <fieldset\n class=\"hm-questionnaire__item\"\n [attr.data-status]=\"status(q)\"\n [attr.data-invalid]=\"error() ? '' : null\"\n [attr.aria-describedby]=\"describedBy(q)\"\n [disabled]=\"busy()\"\n >\n <legend class=\"hm-questionnaire__title\" tabindex=\"-1\" #title>{{ q.title }}</legend>\n @if (q.description) {\n <p class=\"hm-questionnaire__description\" [id]=\"descriptionId\">{{ q.description }}</p>\n }\n @if (q.options?.length) {\n <div class=\"hm-questionnaire__choices\">\n @for (option of q.options; track option.id; let index = $index) {\n <label class=\"hm-questionnaire__choice\" [class.hm-questionnaire__choice--checked]=\"isChecked(q, option.id)\">\n <input\n class=\"hm-questionnaire__control\"\n [type]=\"q.multiple ? 'checkbox' : 'radio'\"\n [name]=\"groupName\"\n [value]=\"option.id\"\n [checked]=\"isChecked(q, option.id)\"\n [attr.aria-keyshortcuts]=\"shortcutOf(index) || null\"\n (change)=\"toggle(q, option.id)\"\n />\n <span class=\"hm-questionnaire__choice-text\">\n <span class=\"hm-questionnaire__choice-label\">{{ option.label }}</span>\n @if (option.description) {\n <span class=\"hm-questionnaire__choice-description\">{{ option.description }}</span>\n }\n </span>\n @if (shortcutOf(index); as key) {\n <kbd class=\"hm-questionnaire__key\" aria-hidden=\"true\">{{ key }}</kbd>\n }\n </label>\n }\n </div>\n }\n @if (q.freeform) {\n <label class=\"hm-questionnaire__freeform\">\n <span class=\"hm-questionnaire__freeform-label\">{{ q.freeformLabel || text().freeform }}</span>\n <input\n class=\"hm-questionnaire__input\"\n type=\"text\"\n [value]=\"answerOf(q).text\"\n [attr.aria-invalid]=\"error() ? 'true' : null\"\n (input)=\"write(q, $any($event.target).value)\"\n />\n </label>\n }\n @if (error()) {\n <p class=\"hm-questionnaire__error\" [id]=\"errorId\" role=\"alert\">{{ error() }}</p>\n }\n </fieldset>\n <div class=\"hm-questionnaire__actions\">\n @if (hasPrevious()) {\n <hm-button emphasis=\"minimal\" size=\"small\" [disabled]=\"busy()\" (clicked)=\"previous()\">{{ text().previous }}</hm-button>\n }\n <span class=\"hm-questionnaire__spacer\"></span>\n @if (q.optional && status(q) === 'unanswered') {\n <hm-button emphasis=\"medium\" size=\"small\" [disabled]=\"busy()\" (clicked)=\"skip()\">{{ text().skip }}</hm-button>\n }\n @if (hasNext()) {\n <hm-button emphasis=\"high\" size=\"small\" [disabled]=\"busy()\" (clicked)=\"next()\">{{ text().next }}</hm-button>\n } @else {\n <hm-button emphasis=\"high\" size=\"small\" [loading]=\"busy()\" (clicked)=\"submit()\">{{ submitLabel() || text().submit }}</hm-button>\n }\n </div>\n }\n `,\n})\nexport class QuestionnaireComponent {\n readonly questions = input.required<readonly QuestionnaireQuestion[]>();\n /** Respostas por id da pergunta. O app pode trazer as de uma sessão anterior. */\n readonly answers = model<QuestionnaireAnswers>({});\n /** Id da pergunta à vista. Vazio: a primeira que vale. */\n readonly active = model('');\n /** Atalho por letra ou número em cada opção. */\n readonly shortcuts = input<QuestionnaireShortcuts | null>(null);\n /** Validação do app, além de exigir resposta nas obrigatórias. */\n readonly validate = input<QuestionnaireValidator | null>(null);\n readonly showProgress = input(true, { transform: booleanAttribute });\n /** Enquanto o app envia: trava os campos e mostra o andamento no botão. */\n readonly busy = input(false, { transform: booleanAttribute });\n /** Nome acessível do grupo. Padrão: \"Perguntas\". */\n readonly label = input('');\n /** Texto do botão final. Padrão: \"Enviar respostas\". */\n readonly submitLabel = input('');\n readonly texts = input<Partial<QuestionnaireMessages>>({});\n /** As respostas das perguntas que valem, depois de todas passarem pela validação. */\n readonly submitted = output<QuestionnaireAnswers>();\n\n readonly #i18n = inject(HermesI18nService);\n readonly #injector = inject(Injector);\n private readonly title = viewChild<ElementRef<HTMLElement>>('title');\n\n protected readonly text = computed<QuestionnaireMessages>(() => ({\n ...this.#i18n.pick(QUESTIONNAIRE_MESSAGES, QUESTIONNAIRE_MESSAGES_PT_BR),\n ...this.texts(),\n }));\n protected readonly groupName = `hm-questionnaire-${++sequence}`;\n protected readonly descriptionId = `${this.groupName}-description`;\n protected readonly errorId = `${this.groupName}-error`;\n /** Erro da pergunta à vista; some quando a resposta muda ou a pergunta troca. */\n protected readonly error = signal('');\n\n private readonly enabled = computed(() => enabledQuestions(this.questions(), this.answers()));\n protected readonly question = computed<QuestionnaireQuestion | null>(() => {\n const enabled = this.enabled();\n return enabled.find((question) => question.id === this.active()) ?? enabled[0] ?? null;\n });\n protected readonly progress = computed(() => questionnaireProgress(this.questions(), this.answers(), this.question()?.id ?? ''));\n protected readonly progressText = computed(() =>\n formatMessage(this.text().progress, { current: this.progress().current, total: this.progress().total }),\n );\n protected readonly hasPrevious = computed(() => !!this.neighbour(-1));\n protected readonly hasNext = computed(() => !!this.neighbour(1));\n\n protected answerOf(question: QuestionnaireQuestion): QuestionnaireAnswer {\n return questionnaireAnswer(this.answers(), question.id);\n }\n\n protected status(question: QuestionnaireQuestion) {\n return questionnaireStatus(this.answers(), question.id);\n }\n\n protected isChecked(question: QuestionnaireQuestion, optionId: string): boolean {\n return this.answerOf(question).options.includes(optionId);\n }\n\n protected shortcutOf(index: number): string {\n const mode = this.shortcuts();\n return mode ? questionnaireShortcut(index, mode) : '';\n }\n\n protected describedBy(question: QuestionnaireQuestion): string | null {\n return [question.description ? this.descriptionId : '', this.error() ? this.errorId : ''].filter(Boolean).join(' ') || null;\n }\n\n protected toggle(question: QuestionnaireQuestion, optionId: string): void {\n this.update(question, toggleQuestionnaireOption(question, this.answerOf(question), optionId));\n }\n\n protected write(question: QuestionnaireQuestion, value: string): void {\n this.update(question, setQuestionnaireText(question, this.answerOf(question), value));\n }\n\n /** Pula a pergunta opcional e segue. */\n skip(): void {\n const question = this.question();\n if (!question?.optional) return;\n this.update(question, skipQuestionnaireAnswer());\n if (this.hasNext()) this.next();\n }\n\n previous(): void {\n const target = this.neighbour(-1);\n if (target) this.goTo(target.id);\n }\n\n /** Segue para a próxima pergunta, se a atual estiver em ordem. Na última, envia. */\n next(): void {\n const question = this.question();\n if (!question || !this.check(question)) return;\n const target = this.neighbour(1);\n if (target) this.goTo(target.id);\n else this.submit();\n }\n\n /** Confere tudo o que vale; com algo faltando, volta para a primeira pergunta pendente e mostra o motivo. */\n submit(): void {\n if (this.busy()) return;\n const current = this.question();\n if (current && !this.check(current)) return;\n const pending = firstIncompleteQuestion(this.questions(), this.answers());\n if (pending) {\n this.goTo(pending.id);\n this.check(pending);\n return;\n }\n for (const question of this.enabled()) {\n const message = this.validate()?.(question, this.answerOf(question), this.answers());\n if (message) {\n this.goTo(question.id);\n this.error.set(message);\n return;\n }\n }\n this.submitted.emit(questionnaireResult(this.questions(), this.answers()));\n }\n\n protected onKeydown(event: KeyboardEvent): void {\n const question = this.question();\n if (!question || this.busy()) return;\n const target = event.target as HTMLElement | null;\n const typing = target instanceof HTMLInputElement && target.type === 'text';\n const choice = target instanceof HTMLInputElement && (target.type === 'radio' || target.type === 'checkbox');\n\n if (event.key === 'Enter' && (event.ctrlKey || event.metaKey)) {\n event.preventDefault();\n this.next();\n return;\n }\n if (event.key === 'Enter' && (typing || (choice && !question.multiple))) {\n event.preventDefault();\n this.next();\n return;\n }\n if (typing || event.ctrlKey || event.metaKey || event.altKey) return;\n if (!choice && event.key === 'ArrowLeft') {\n event.preventDefault();\n this.previous();\n return;\n }\n if (!choice && event.key === 'ArrowRight') {\n event.preventDefault();\n if (canLeaveQuestion(question, this.answers())) this.next();\n return;\n }\n const mode = this.shortcuts();\n const options = question.options ?? [];\n if (!mode || !options.length) return;\n const index = questionnaireShortcutIndex(event.key, mode, options.length);\n if (index === -1) return;\n event.preventDefault();\n this.toggle(question, options[index].id);\n const host = this.title()?.nativeElement.closest('fieldset');\n host?.querySelectorAll<HTMLInputElement>('.hm-questionnaire__control')[index]?.focus();\n }\n\n private neighbour(step: 1 | -1): QuestionnaireQuestion | null {\n const question = this.question();\n return question ? adjacentQuestion(this.questions(), this.answers(), question.id, step) : null;\n }\n\n private update(question: QuestionnaireQuestion, answer: QuestionnaireAnswer): void {\n this.answers.set({ ...this.answers(), [question.id]: answer });\n this.error.set('');\n }\n\n /** Pode sair da pergunta: responder (ou pular, se opcional) e passar pela validação do app. */\n private check(question: QuestionnaireQuestion): boolean {\n if (!canLeaveQuestion(question, this.answers()) && !question.optional) {\n this.error.set(this.text().required);\n return false;\n }\n const message = this.validate()?.(question, this.answerOf(question), this.answers()) ?? null;\n this.error.set(message ?? '');\n return !message;\n }\n\n /** Troca de pergunta e leva o foco ao título, para quem usa leitor de tela saber onde está. */\n private goTo(id: string): void {\n if (id !== this.question()?.id) this.error.set('');\n this.active.set(id);\n afterNextRender(() => this.title()?.nativeElement.focus(), { injector: this.#injector });\n }\n}\n","// Ponto de import `@trismegisto/angular/questionnaire` (secundário do ng-packagr): o que o público usa sai daqui.\nexport * from './questionnaire.component';\nexport * from './questionnaire-messages';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;AAAA;AACA;AACA;AAcO,MAAM,4BAA4B,GAA0B;AACjE,IAAA,KAAK,EAAE,WAAW;AAClB,IAAA,QAAQ,EAAE,+BAA+B;AACzC,IAAA,QAAQ,EAAE,UAAU;AACpB,IAAA,IAAI,EAAE,SAAS;AACf,IAAA,IAAI,EAAE,OAAO;AACb,IAAA,MAAM,EAAE,kBAAkB;AAC1B,IAAA,QAAQ,EAAE,0BAA0B;AACpC,IAAA,QAAQ,EAAE,gBAAgB;AAC1B,IAAA,YAAY,EAAE,aAAa;;AAGtB,MAAM,yBAAyB,GAA0B;AAC9D,IAAA,KAAK,EAAE,WAAW;AAClB,IAAA,QAAQ,EAAE,+BAA+B;AACzC,IAAA,QAAQ,EAAE,UAAU;AACpB,IAAA,IAAI,EAAE,MAAM;AACZ,IAAA,IAAI,EAAE,MAAM;AACZ,IAAA,MAAM,EAAE,gBAAgB;AACxB,IAAA,QAAQ,EAAE,qBAAqB;AAC/B,IAAA,QAAQ,EAAE,cAAc;AACxB,IAAA,YA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2ET,EAAA,CAAA;AACF,iBAAA;4oCAwB6D,OAAO,EAAA,EAAA,QAAA,EAAA,IAAA,EAAA,CAAA,EAAA,CAAA,EAAA,EAAA,CAAA;;AC5KrE;;ACAA;;AAEG;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { input, ChangeDetectionStrategy, Component, booleanAttribute,
|
|
2
|
+
import { input, ChangeDetectionStrategy, Component, booleanAttribute, model, inject, computed } from '@angular/core';
|
|
3
3
|
import { NgTemplateOutlet } from '@angular/common';
|
|
4
4
|
import { HermesI18nService } from '@trismegisto/angular/i18n';
|
|
5
5
|
import { ICON_ANGLE, ICON_CHECK_CIRCLE, ICON_CIRCLE, ICON_LIST, ICON_TIMES_CIRCLE, useHermesIcons, IconComponent } from '@trismegisto/angular/icon';
|
|
@@ -14,18 +14,21 @@ const TRACE_MESSAGES_PT_BR = {
|
|
|
14
14
|
running: 'Em andamento',
|
|
15
15
|
done: 'Concluído',
|
|
16
16
|
error: 'Falhou',
|
|
17
|
+
opensInNewTab: '(abre em nova aba)',
|
|
17
18
|
};
|
|
18
19
|
const TRACE_MESSAGES_EN = {
|
|
19
20
|
pending: 'Waiting',
|
|
20
21
|
running: 'In progress',
|
|
21
22
|
done: 'Done',
|
|
22
23
|
error: 'Failed',
|
|
24
|
+
opensInNewTab: '(opens in a new tab)',
|
|
23
25
|
};
|
|
24
26
|
const TRACE_MESSAGES_ES = {
|
|
25
27
|
pending: 'En espera',
|
|
26
28
|
running: 'En curso',
|
|
27
29
|
done: 'Completado',
|
|
28
30
|
error: 'Falló',
|
|
31
|
+
opensInNewTab: '(se abre en una pestaña nueva)',
|
|
29
32
|
};
|
|
30
33
|
/** Catálogos por idioma, para `HermesI18nService.pick`. */
|
|
31
34
|
const TRACE_MESSAGES = {
|
|
@@ -65,7 +68,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.24", ngImpo
|
|
|
65
68
|
}], propDecorators: { label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }] } });
|
|
66
69
|
/**
|
|
67
70
|
* Uma etapa do `hm-trace`. O estado aparece no desenho e, para leitor de tela, em texto. Com `expandable`, a linha vira
|
|
68
|
-
* um botão que mostra o conteúdo projetado (a saída de uma ferramenta, por exemplo)
|
|
71
|
+
* um botão que mostra o conteúdo projetado (a saída de uma ferramenta, por exemplo), que pode trazer outro `hm-trace`.
|
|
72
|
+
* Com `href`, a linha vira um link (um passo que aponta para outra tela ou para um arquivo).
|
|
69
73
|
*/
|
|
70
74
|
class TraceItemComponent {
|
|
71
75
|
#icons = useHermesIcons(TRACE_ICONS);
|
|
@@ -75,17 +79,22 @@ class TraceItemComponent {
|
|
|
75
79
|
status = input('pending', ...(ngDevMode ? [{ debugName: "status" }] : /* istanbul ignore next */ []));
|
|
76
80
|
/** A linha abre o conteúdo projetado. */
|
|
77
81
|
expandable = input(false, { ...(ngDevMode ? { debugName: "expandable" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
82
|
+
/** Com `expandable`, se o conteúdo está aberto. */
|
|
83
|
+
open = model(false, ...(ngDevMode ? [{ debugName: "open" }] : /* istanbul ignore next */ []));
|
|
84
|
+
/** Destino da linha (ignorado com `expandable`, que já é um botão). */
|
|
85
|
+
href = input('', ...(ngDevMode ? [{ debugName: "href" }] : /* istanbul ignore next */ []));
|
|
86
|
+
/** Com `href`: abre em nova aba. */
|
|
87
|
+
external = input(false, { ...(ngDevMode ? { debugName: "external" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
78
88
|
/** Sobrescrita parcial dos textos de estado. */
|
|
79
89
|
texts = input({}, ...(ngDevMode ? [{ debugName: "texts" }] : /* istanbul ignore next */ []));
|
|
80
|
-
open = signal(false, ...(ngDevMode ? [{ debugName: "open" }] : /* istanbul ignore next */ []));
|
|
81
90
|
panelId = `hm-trace-item-${++sequence}`;
|
|
82
91
|
#i18n = inject(HermesI18nService);
|
|
83
|
-
|
|
92
|
+
messages = computed(() => ({
|
|
84
93
|
...this.#i18n.pick(TRACE_MESSAGES, TRACE_MESSAGES_PT_BR),
|
|
85
94
|
...this.texts(),
|
|
86
|
-
})
|
|
95
|
+
}), ...(ngDevMode ? [{ debugName: "messages" }] : /* istanbul ignore next */ []));
|
|
87
96
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.24", ngImport: i0, type: TraceItemComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
88
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.24", type: TraceItemComponent, isStandalone: true, selector: "hm-trace-item", inputs: { heading: { classPropertyName: "heading", publicName: "heading", isSignal: true, isRequired: true, transformFunction: null }, detail: { classPropertyName: "detail", publicName: "detail", isSignal: true, isRequired: false, transformFunction: null }, status: { classPropertyName: "status", publicName: "status", isSignal: true, isRequired: false, transformFunction: null }, expandable: { classPropertyName: "expandable", publicName: "expandable", isSignal: true, isRequired: false, transformFunction: null }, texts: { classPropertyName: "texts", publicName: "texts", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "role": "listitem" }, properties: { "attr.data-status": "status()" }, classAttribute: "hm-trace-item" }, ngImport: i0, template: `
|
|
97
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.24", type: TraceItemComponent, isStandalone: true, selector: "hm-trace-item", inputs: { heading: { classPropertyName: "heading", publicName: "heading", isSignal: true, isRequired: true, transformFunction: null }, detail: { classPropertyName: "detail", publicName: "detail", isSignal: true, isRequired: false, transformFunction: null }, status: { classPropertyName: "status", publicName: "status", isSignal: true, isRequired: false, transformFunction: null }, expandable: { classPropertyName: "expandable", publicName: "expandable", isSignal: true, isRequired: false, transformFunction: null }, open: { classPropertyName: "open", publicName: "open", isSignal: true, isRequired: false, transformFunction: null }, href: { classPropertyName: "href", publicName: "href", isSignal: true, isRequired: false, transformFunction: null }, external: { classPropertyName: "external", publicName: "external", isSignal: true, isRequired: false, transformFunction: null }, texts: { classPropertyName: "texts", publicName: "texts", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { open: "openChange" }, host: { attributes: { "role": "listitem" }, properties: { "attr.data-status": "status()" }, classAttribute: "hm-trace-item" }, ngImport: i0, template: `
|
|
89
98
|
<ng-template #line>
|
|
90
99
|
<span class="hm-trace-item__mark" aria-hidden="true">
|
|
91
100
|
@switch (status()) {
|
|
@@ -98,7 +107,7 @@ class TraceItemComponent {
|
|
|
98
107
|
<span class="hm-trace-item__text">
|
|
99
108
|
<span class="hm-trace-item__heading">{{ heading() }}</span>
|
|
100
109
|
@if (detail()) { <span class="hm-trace-item__detail">{{ detail() }}</span> }
|
|
101
|
-
<span class="hm-trace-item__status">{{
|
|
110
|
+
<span class="hm-trace-item__status">{{ messages()[status()] }}</span>
|
|
102
111
|
</span>
|
|
103
112
|
@if (expandable()) {
|
|
104
113
|
<hm-icon class="hm-trace-item__chevron" shape="angle" aria-hidden="true" />
|
|
@@ -116,6 +125,16 @@ class TraceItemComponent {
|
|
|
116
125
|
<ng-container *ngTemplateOutlet="line" />
|
|
117
126
|
</button>
|
|
118
127
|
<div class="hm-trace-item__panel" [id]="panelId" [hidden]="!open()"><ng-content /></div>
|
|
128
|
+
} @else if (href()) {
|
|
129
|
+
<a
|
|
130
|
+
class="hm-trace-item__line hm-trace-item__line--link"
|
|
131
|
+
[href]="href()"
|
|
132
|
+
[attr.target]="external() ? '_blank' : null"
|
|
133
|
+
[attr.rel]="external() ? 'noopener noreferrer' : null"
|
|
134
|
+
>
|
|
135
|
+
<ng-container *ngTemplateOutlet="line" />
|
|
136
|
+
@if (external()) { <span class="hm-trace-item__status">{{ messages().opensInNewTab }}</span> }
|
|
137
|
+
</a>
|
|
119
138
|
} @else {
|
|
120
139
|
<div class="hm-trace-item__line"><ng-container *ngTemplateOutlet="line" /></div>
|
|
121
140
|
}
|
|
@@ -141,7 +160,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.24", ngImpo
|
|
|
141
160
|
<span class="hm-trace-item__text">
|
|
142
161
|
<span class="hm-trace-item__heading">{{ heading() }}</span>
|
|
143
162
|
@if (detail()) { <span class="hm-trace-item__detail">{{ detail() }}</span> }
|
|
144
|
-
<span class="hm-trace-item__status">{{
|
|
163
|
+
<span class="hm-trace-item__status">{{ messages()[status()] }}</span>
|
|
145
164
|
</span>
|
|
146
165
|
@if (expandable()) {
|
|
147
166
|
<hm-icon class="hm-trace-item__chevron" shape="angle" aria-hidden="true" />
|
|
@@ -159,12 +178,22 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.24", ngImpo
|
|
|
159
178
|
<ng-container *ngTemplateOutlet="line" />
|
|
160
179
|
</button>
|
|
161
180
|
<div class="hm-trace-item__panel" [id]="panelId" [hidden]="!open()"><ng-content /></div>
|
|
181
|
+
} @else if (href()) {
|
|
182
|
+
<a
|
|
183
|
+
class="hm-trace-item__line hm-trace-item__line--link"
|
|
184
|
+
[href]="href()"
|
|
185
|
+
[attr.target]="external() ? '_blank' : null"
|
|
186
|
+
[attr.rel]="external() ? 'noopener noreferrer' : null"
|
|
187
|
+
>
|
|
188
|
+
<ng-container *ngTemplateOutlet="line" />
|
|
189
|
+
@if (external()) { <span class="hm-trace-item__status">{{ messages().opensInNewTab }}</span> }
|
|
190
|
+
</a>
|
|
162
191
|
} @else {
|
|
163
192
|
<div class="hm-trace-item__line"><ng-container *ngTemplateOutlet="line" /></div>
|
|
164
193
|
}
|
|
165
194
|
`,
|
|
166
195
|
}]
|
|
167
|
-
}], propDecorators: { heading: [{ type: i0.Input, args: [{ isSignal: true, alias: "heading", required: true }] }], detail: [{ type: i0.Input, args: [{ isSignal: true, alias: "detail", required: false }] }], status: [{ type: i0.Input, args: [{ isSignal: true, alias: "status", required: false }] }], expandable: [{ type: i0.Input, args: [{ isSignal: true, alias: "expandable", required: false }] }], texts: [{ type: i0.Input, args: [{ isSignal: true, alias: "texts", required: false }] }] } });
|
|
196
|
+
}], propDecorators: { heading: [{ type: i0.Input, args: [{ isSignal: true, alias: "heading", required: true }] }], detail: [{ type: i0.Input, args: [{ isSignal: true, alias: "detail", required: false }] }], status: [{ type: i0.Input, args: [{ isSignal: true, alias: "status", required: false }] }], expandable: [{ type: i0.Input, args: [{ isSignal: true, alias: "expandable", required: false }] }], open: [{ type: i0.Input, args: [{ isSignal: true, alias: "open", required: false }] }, { type: i0.Output, args: ["openChange"] }], href: [{ type: i0.Input, args: [{ isSignal: true, alias: "href", required: false }] }], external: [{ type: i0.Input, args: [{ isSignal: true, alias: "external", required: false }] }], texts: [{ type: i0.Input, args: [{ isSignal: true, alias: "texts", required: false }] }] } });
|
|
168
197
|
|
|
169
198
|
// Ponto de import `@trismegisto/angular/trace` (secundário do ng-packagr): o que o public-api e as outras pastas usam
|
|
170
199
|
// daqui. Ao criar arquivo público novo na pasta, acrescente a linha.
|