ui-core-abv 0.11.3 → 0.11.4

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.
@@ -2,6 +2,7 @@ import { NgZone, OnDestroy } from '@angular/core';
2
2
  import { AbstractControl, FormArray, FormGroup } from '@angular/forms';
3
3
  import { Observable } from 'rxjs';
4
4
  import { ButtonColor } from '../../button/button.component';
5
+ import { AppSelectOption } from '../../inputs/select/select.component';
5
6
  import { FormField, FormIconMode, SelectOptionsResolver } from '../form.models';
6
7
  import * as i0 from "@angular/core";
7
8
  interface DynamicFieldState {
@@ -50,6 +51,14 @@ export declare class UicDynamicFormComponent implements OnDestroy {
50
51
  listeningField: string | null;
51
52
  readonly fieldStates: import("@angular/core").Signal<DynamicFieldState[]>;
52
53
  readonly visibleFieldStates: import("@angular/core").Signal<DynamicFieldState[]>;
54
+ readonly otherTextMaxLength = 500;
55
+ private readonly otherOptionsCache;
56
+ /** Texto "especifica" visible de cada pregunta (por nombre de la pregunta). */
57
+ private readonly visibleOtherStates;
58
+ /** Opciones de la pregunta, con "Otros" al final si la tiene. Cacheado para no recrear el array en cada ciclo. */
59
+ optionsFor(field: FormField): AppSelectOption[];
60
+ /** Estado del texto "especifica" de una pregunta, si está visible (eligió "Otros"). */
61
+ otherStateFor(field: FormField): DynamicFieldState | null;
53
62
  private readonly formSyncEffect;
54
63
  private readonly fieldStateSyncEffect;
55
64
  readonly colorToIcon: Record<string, string>;
@@ -24,6 +24,7 @@ export interface UicOptionsSourceError {
24
24
  export declare class UicFormEngine implements OnDestroy {
25
25
  private readonly fb;
26
26
  private readonly formState;
27
+ private readonly i18n;
27
28
  schema?: FormSchema;
28
29
  fields: FormField[];
29
30
  cols: number;
@@ -161,6 +162,11 @@ export declare class UicFormEngine implements OnDestroy {
161
162
  private toNestedValues;
162
163
  private setNestedValue;
163
164
  syncEffectiveSchema(): void;
165
+ /**
166
+ * Agrega el campo de texto de cada pregunta con "Otros" (ver other-option.ts).
167
+ * Sin preguntas con "Otros" devuelve el mismo esquema, sin copiarlo.
168
+ */
169
+ private expandOtherOptionFields;
164
170
  static ɵfac: i0.ɵɵFactoryDeclaration<UicFormEngine, never>;
165
171
  static ɵprov: i0.ɵɵInjectableDeclaration<UicFormEngine>;
166
172
  }
@@ -8,3 +8,15 @@ import { FormField } from './form.models';
8
8
  export declare function uicSelectionCountValidator(min?: number | null, max?: number | null): ValidatorFn;
9
9
  /** Validadores de selección que corresponden al campo (vacío si no aplica). */
10
10
  export declare function uicSelectionValidatorsFor(field: FormField): ValidatorFn[];
11
+ /** Total que debe sumar una pregunta de distribución porcentual. */
12
+ export declare const UIC_DISTRIBUTION_TOTAL = 100;
13
+ /** Suma de los porcentajes de un valor de distribución (ignora ítems inválidos). */
14
+ export declare function uicDistributionSum(value: unknown): number;
15
+ /**
16
+ * Distribución porcentual: si hay respuesta, debe sumar exactamente 100.
17
+ * Un valor vacío (null o todo en 0) no falla: para exigir respuesta se usa `required`.
18
+ * Error: { distributionTotal: { total, expected } }.
19
+ */
20
+ export declare function uicDistributionTotalValidator(expected?: number): ValidatorFn;
21
+ /** Validadores de distribución que corresponden al campo (vacío si no aplica). */
22
+ export declare function uicDistributionValidatorsFor(field: FormField): ValidatorFn[];
@@ -132,6 +132,13 @@ export interface FormField {
132
132
  searchIsEnabledFn?: (item: any) => boolean;
133
133
  pattern?: RegExp;
134
134
  visibilityRules?: FieldVisibilityRule[] | null;
135
+ /**
136
+ * Opción "Otros (especifica)" (radio, select, multyselect): agrega la opción "Otros" y un texto que se
137
+ * guarda en `<name>__other`. El valor de la pregunta no cambia (sigue siendo el id o la lista de ids).
138
+ */
139
+ otherOption?: UicOtherOptionConfig | null;
140
+ /** Interno: este campo es el texto "especifica" de la opción Otros de la pregunta `otherFor`. */
141
+ otherFor?: string;
135
142
  /**
136
143
  * Opción A (declarativa/serializable): define la clave y dependencias del campo calculado.
137
144
  * El wrapper llama a `computedFieldResolver` cuando algún campo de `dependsOn` cambia.
@@ -152,6 +159,15 @@ export interface FormField {
152
159
  repeaterRemoveLabel?: string;
153
160
  repeaterItemTitle?: string;
154
161
  }
162
+ /** Configuración de la opción "Otros". */
163
+ export interface UicOtherOptionConfig {
164
+ /** Texto de la opción. Por defecto: "Otros". */
165
+ label?: string;
166
+ /** Placeholder del texto. Por defecto: "Especifica...". */
167
+ placeholder?: string;
168
+ /** Si al elegir "Otros" el texto es obligatorio. Por defecto: true. */
169
+ required?: boolean;
170
+ }
155
171
  export interface FieldVisibilityRule {
156
172
  fieldName: string;
157
173
  fieldLabel?: string;
@@ -176,7 +192,15 @@ export declare const VISIBILITY_OPERATOR_OPTIONS: {
176
192
  text: string;
177
193
  }[];
178
194
  export declare const FIELDS_CONFIG: FieldConfig[];
179
- export type FieldType = 'text' | 'number' | 'phone' | 'date' | 'time' | 'select' | 'radio' | 'checkbox' | 'switch' | 'textarea' | 'pool' | 'file' | 'multyselect' | 'searcher' | 'multisearcher' | 'slider' | 'repeater' | 'computed' | 'scale';
195
+ export type FieldType = 'text' | 'number' | 'phone' | 'date' | 'time' | 'select' | 'radio' | 'checkbox' | 'switch' | 'textarea' | 'pool' | 'file' | 'multyselect' | 'searcher' | 'multisearcher' | 'slider' | 'repeater' | 'computed' | 'scale' | 'distribution';
196
+ /**
197
+ * Valor de una pregunta de distribución porcentual: un ítem por opción, en el orden de las opciones,
198
+ * con el porcentaje asignado (enteros 0–100 que suman 100). Sin respuesta, el valor es null.
199
+ */
200
+ export type UicDistributionValue = {
201
+ id: string | number;
202
+ value: number;
203
+ }[];
180
204
  export interface FormResult {
181
205
  result: boolean;
182
206
  form: uicFormValuesRecord | null;
@@ -0,0 +1,34 @@
1
+ import { AppSelectOption } from '../inputs/select/select.component';
2
+ import { FieldType, FormField } from './form.models';
3
+ /**
4
+ * Opción "Otros (especifica)".
5
+ *
6
+ * Una pregunta con `otherOption` suma la opción "Otros" (id UIC_OTHER_OPTION_ID) y un texto
7
+ * acompañante que se guarda en `<name>__other`. El valor de la pregunta no cambia (sigue siendo
8
+ * el id elegido, o la lista de ids), así que reglas, reportes y consumidores existentes no se afectan.
9
+ *
10
+ * El texto es un campo más del formulario, generado a partir del esquema: se muestra solo cuando
11
+ * se elige "Otros" (regla de visibilidad automática), se limpia al dejar de elegirlo y se valida,
12
+ * guarda y reanuda como cualquier otro campo.
13
+ */
14
+ export declare const UIC_OTHER_OPTION_ID = "__other__";
15
+ export declare const UIC_OTHER_FIELD_SUFFIX = "__other";
16
+ /** Tipos que admiten "Otros": su valor es un id o una lista de ids. */
17
+ export declare const UIC_OTHER_OPTION_TYPES: readonly FieldType[];
18
+ export declare const UIC_OTHER_TEXT_MAX_LENGTH = 500;
19
+ /** Nombre del campo que guarda el texto de "Otros" de una pregunta. */
20
+ export declare function uicOtherFieldName(name: string): string;
21
+ export declare function uicSupportsOtherOption(field: Pick<FormField, 'type'>): boolean;
22
+ /** true si la pregunta muestra la opción "Otros". */
23
+ export declare function uicHasOtherOption(field: FormField): boolean;
24
+ /** Opciones de la pregunta con "Otros" al final (si corresponde y no está ya). */
25
+ export declare function uicOptionsWithOther(options: AppSelectOption[] | undefined, field: FormField, label: string): AppSelectOption[];
26
+ /** Campo de texto acompañante de una pregunta con "Otros". */
27
+ export declare function uicBuildOtherField(field: FormField, otherLabel: string, placeholder: string): FormField;
28
+ /** true si algún campo (o sub-campo de repetidor) usa "Otros". */
29
+ export declare function uicContainsOtherOption(fields: FormField[] | undefined): boolean;
30
+ /**
31
+ * Inserta, después de cada pregunta con "Otros", su campo de texto acompañante.
32
+ * Si ningún campo usa "Otros" devuelve el mismo array (no copia el esquema).
33
+ */
34
+ export declare function uicExpandOtherFields(fields: FormField[], otherLabel: string, placeholder: string): FormField[];
@@ -0,0 +1,55 @@
1
+ import { ButtonColor } from '../../button/button.component';
2
+ import { AppSelectOption } from '../select/select.component';
3
+ import { UicDistributionValue } from '../../dynamic-form/form.models';
4
+ import * as i0 from "@angular/core";
5
+ declare const base: abstract new () => {
6
+ value: UicDistributionValue | null;
7
+ valueChange: import("@angular/core").EventEmitter<UicDistributionValue | null>;
8
+ onChange: (value: UicDistributionValue | null) => void;
9
+ onTouched: () => void;
10
+ writeValue(obj: UicDistributionValue | null): void;
11
+ registerOnChange(fn: any): void;
12
+ registerOnTouched(fn: any): void;
13
+ setDisabledState?(isDisabled: boolean): void;
14
+ notifyChange(value: UicDistributionValue | null): void;
15
+ };
16
+ /**
17
+ * Distribución porcentual: el usuario reparte el 100% entre las opciones.
18
+ * Valor: [{ id, value }] con un ítem por opción (en su orden), o null si no asignó nada.
19
+ * Los porcentajes son enteros entre 0 y 100; la validación de que sumen 100 está en el formulario
20
+ * (uicDistributionTotalValidator), este componente solo muestra el total y cuánto falta o sobra.
21
+ */
22
+ export declare class UicDistributionComponent extends base {
23
+ private readonly host;
24
+ readonly uid: string;
25
+ readonly expected = 100;
26
+ icon: string;
27
+ iconColor: ButtonColor;
28
+ label: string;
29
+ error: string;
30
+ tip: string;
31
+ disabled: boolean;
32
+ options: AppSelectOption[];
33
+ /** Opciones con id utilizable (una opción sin id no se puede guardar en el valor). */
34
+ get validOptions(): (AppSelectOption & {
35
+ id: string | number;
36
+ })[];
37
+ get total(): number;
38
+ /** Lo que falta para llegar a 100 (negativo si se pasó). */
39
+ get remaining(): number;
40
+ amountOf(option: AppSelectOption): number;
41
+ onInput(option: AppSelectOption, event: Event): void;
42
+ /** Asigna a esta opción todo lo que falta para llegar a 100. */
43
+ fillRemaining(option: AppSelectOption): void;
44
+ clear(): void;
45
+ /** Foco dentro del grupo: mientras se reparte, el total ya indica cuánto falta y no se muestra el error. */
46
+ hasFocus: boolean;
47
+ get displayedError(): string;
48
+ onFocusIn(): void;
49
+ onFocusOut(event: FocusEvent): void;
50
+ inputId(index: number): string;
51
+ private setAmount;
52
+ static ɵfac: i0.ɵɵFactoryDeclaration<UicDistributionComponent, never>;
53
+ static ɵcmp: i0.ɵɵComponentDeclaration<UicDistributionComponent, "ui-distribution", never, { "icon": { "alias": "icon"; "required": false; }; "iconColor": { "alias": "iconColor"; "required": false; }; "label": { "alias": "label"; "required": false; }; "error": { "alias": "error"; "required": false; }; "tip": { "alias": "tip"; "required": false; }; "disabled": { "alias": "disabled"; "required": false; }; "options": { "alias": "options"; "required": false; }; }, {}, never, never, true, never>;
54
+ }
55
+ export {};
@@ -145,6 +145,7 @@ export declare class UicSurveyComponent implements OnInit, OnChanges, OnDestroy
145
145
  private validatePage;
146
146
  private findFirstInvalidPage;
147
147
  private focusActivePage;
148
+ /** Campos de una página de una sola pregunta: la pregunta y, si tiene "Otros", su texto acompañante. */
148
149
  private fieldsForSingleFieldPage;
149
150
  private onFormBuilt;
150
151
  private scheduleImmediateSaves;
@@ -1,4 +1,4 @@
1
- import { FieldVisibilityRule, FormField, uicFormValuesRecord } from '../../../dynamic-form/form.models';
1
+ import { FieldVisibilityRule, FormField, UicOtherOptionConfig, uicFormValuesRecord } from '../../../dynamic-form/form.models';
2
2
  import { AppSelectOption } from '../../../inputs/select/select.component';
3
3
  import { EditableField } from '../../user-formbuilder.component';
4
4
  import * as i0 from "@angular/core";
@@ -34,6 +34,8 @@ export declare class FieldEditorComponent {
34
34
  /** Sección "Estilo". */
35
35
  styleEnabled: import("@angular/core").InputSignal<boolean>;
36
36
  showDependencySection: import("@angular/core").Signal<boolean>;
37
+ /** Tipos con opciones que no admiten origen externo (el motor solo lo resuelve para selectores, pool y radio). */
38
+ private readonly manualOptionsOnly;
37
39
  showOptionsSourceConfig: import("@angular/core").Signal<boolean>;
38
40
  showExternalValidation: import("@angular/core").Signal<boolean>;
39
41
  options: import("@angular/core").InputSignal<Record<string, AppSelectOption[]>>;
@@ -65,6 +67,10 @@ export declare class FieldEditorComponent {
65
67
  updateFieldValues(fr: uicFormValuesRecord): void;
66
68
  /** Leyendas de la escala: el código es el valor numérico. */
67
69
  updateScaleLabels(labels: AppSelectOption[]): void;
70
+ supportsOtherOption: import("@angular/core").Signal<boolean>;
71
+ toggleOtherOption(enabled: boolean): void;
72
+ updateOtherOption(patch: Partial<UicOtherOptionConfig>): void;
73
+ private patchField;
68
74
  updateOptions(options: AppSelectOption[]): void;
69
75
  private getDependencyFieldLabel;
70
76
  isSectionHidden(section: string): boolean;
@@ -235,6 +235,13 @@ export declare const DICTIONARY_EN: {
235
235
  readonly visibility_summary: "Visible if {{field}} {{operator}} {{value}}";
236
236
  readonly yes: "Yes";
237
237
  readonly no: "No";
238
+ readonly other_option: {
239
+ readonly enable: "Include an \"Other\" (please specify) option";
240
+ readonly enable_tip: "Adds an Other option with a text to specify. The text is saved as <identifier>__other.";
241
+ readonly label: "Option text";
242
+ readonly placeholder: "Field placeholder";
243
+ readonly required: "Specifying is required when Other is chosen";
244
+ };
238
245
  readonly limits: {
239
246
  readonly fields_reached: "The form already has the maximum of {{max}} fields";
240
247
  readonly blocks_reached: "The maximum of {{max}} blocks has been reached";
@@ -476,6 +483,19 @@ export declare const DICTIONARY_EN: {
476
483
  readonly subtitle_margin: "Subtitle margin";
477
484
  };
478
485
  };
486
+ readonly other_option: {
487
+ readonly label: "Other";
488
+ readonly placeholder: "Please specify...";
489
+ };
490
+ readonly distribution: {
491
+ readonly total: "Total";
492
+ readonly complete: "Complete";
493
+ readonly missing: "{{amount}}% left";
494
+ readonly over: "{{amount}}% over";
495
+ readonly clear: "Clear";
496
+ readonly fill_remaining: "Assign the remaining {{remaining}}% to {{option}}";
497
+ readonly no_options: "This question has no options yet.";
498
+ };
479
499
  readonly validation: {
480
500
  readonly invalid: "{{field}} is invalid.";
481
501
  readonly required: "{{field}} is required.";
@@ -487,6 +507,7 @@ export declare const DICTIONARY_EN: {
487
507
  readonly external_invalid: "{{field}} is not valid.";
488
508
  readonly min_selections: "{{field}}: choose at least {{min}} options.";
489
509
  readonly max_selections: "{{field}}: choose at most {{max}} options.";
510
+ readonly distribution_total: "{{field}} must add up to {{expected}}% (currently {{total}}%).";
490
511
  };
491
512
  readonly clipboard: {
492
513
  readonly copy_error: "Could not copy:";
@@ -235,6 +235,13 @@ export declare const DICTIONARY_ES: {
235
235
  readonly visibility_summary: "Visible si {{field}} {{operator}} {{value}}";
236
236
  readonly yes: "Sí";
237
237
  readonly no: "No";
238
+ readonly other_option: {
239
+ readonly enable: "Incluir opción «Otros» (especifica)";
240
+ readonly enable_tip: "Agrega la opción Otros con un texto para especificar. El texto se guarda en <identificador>__other.";
241
+ readonly label: "Texto de la opción";
242
+ readonly placeholder: "Texto de ayuda del campo";
243
+ readonly required: "Especificar es obligatorio al elegir Otros";
244
+ };
238
245
  readonly limits: {
239
246
  readonly fields_reached: "Se alcanzó el máximo de {{max}} campos del formulario";
240
247
  readonly blocks_reached: "Se alcanzó el máximo de {{max}} bloques";
@@ -476,6 +483,19 @@ export declare const DICTIONARY_ES: {
476
483
  readonly subtitle_margin: "Margen subtítulo";
477
484
  };
478
485
  };
486
+ readonly other_option: {
487
+ readonly label: "Otros";
488
+ readonly placeholder: "Especifica...";
489
+ };
490
+ readonly distribution: {
491
+ readonly total: "Total";
492
+ readonly complete: "Completo";
493
+ readonly missing: "Faltan {{amount}}%";
494
+ readonly over: "Sobran {{amount}}%";
495
+ readonly clear: "Limpiar";
496
+ readonly fill_remaining: "Asignar el {{remaining}}% restante a {{option}}";
497
+ readonly no_options: "Esta pregunta aún no tiene opciones.";
498
+ };
479
499
  readonly validation: {
480
500
  readonly invalid: "{{field}} es invalido.";
481
501
  readonly required: "{{field}} es obligatorio.";
@@ -487,6 +507,7 @@ export declare const DICTIONARY_ES: {
487
507
  readonly external_invalid: "{{field}} no es válido.";
488
508
  readonly min_selections: "{{field}}: elige al menos {{min}} opciones.";
489
509
  readonly max_selections: "{{field}}: elige como máximo {{max}} opciones.";
510
+ readonly distribution_total: "{{field}} debe sumar {{expected}}% (ahora suma {{total}}%).";
490
511
  };
491
512
  readonly clipboard: {
492
513
  readonly copy_error: "No se pudo copiar:";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ui-core-abv",
3
- "version": "0.11.3",
3
+ "version": "0.11.4",
4
4
  "peerDependencies": {
5
5
  "@angular/common": ">=19.2.0 <22.0.0",
6
6
  "@angular/core": ">=19.2.0 <22.0.0",
package/public-api.d.ts CHANGED
@@ -24,6 +24,7 @@ export * from './lib/components/skeleton-cards/skeleton-cards.component';
24
24
  export * from './lib/components/push-alerts/alert-container/alert-container.component';
25
25
  export * from './lib/components/inputs/ui-slider/ui-slider.component';
26
26
  export * from './lib/components/inputs/ui-scale/ui-scale.component';
27
+ export * from './lib/components/inputs/ui-distribution/ui-distribution.component';
27
28
  export * from './lib/components/uic-action-button/uic-action-button.component';
28
29
  export * from './lib/components/signature-pad/signature-pad.component';
29
30
  export * from './lib/components/dropdown-container/dropdown-container.component';
@@ -67,5 +68,6 @@ export * from './lib/components/survey/survey-templates.directive';
67
68
  export * from './lib/components/dynamic-form/form-engine.service';
68
69
  export * from './lib/components/dynamic-form/form-state.service';
69
70
  export * from './lib/components/dynamic-form/form-validators';
71
+ export * from './lib/components/dynamic-form/other-option';
70
72
  export * from './lib/theme/theme-scope';
71
73
  export * from './lib/theme/colors';