@tstdl/base 0.91.41 → 0.91.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/examples/orm/user.model.d.ts +1 -3
  2. package/examples/orm/user.model.js +0 -10
  3. package/orm/index.d.ts +1 -0
  4. package/orm/index.js +1 -0
  5. package/orm/types.d.ts +2 -2
  6. package/orm/types.js +2 -2
  7. package/package.json +1 -1
  8. package/form/abstract-control.d.ts +0 -72
  9. package/form/abstract-control.js +0 -82
  10. package/form/controls/checkbox.control.d.ts +0 -10
  11. package/form/controls/checkbox.control.js +0 -19
  12. package/form/controls/chip-select.control.d.ts +0 -36
  13. package/form/controls/chip-select.control.js +0 -56
  14. package/form/controls/date.control.d.ts +0 -26
  15. package/form/controls/date.control.js +0 -64
  16. package/form/controls/hidden.control.d.ts +0 -11
  17. package/form/controls/hidden.control.js +0 -22
  18. package/form/controls/index.d.ts +0 -10
  19. package/form/controls/index.js +0 -10
  20. package/form/controls/items.control.d.ts +0 -38
  21. package/form/controls/items.control.js +0 -41
  22. package/form/controls/number.control.d.ts +0 -33
  23. package/form/controls/number.control.js +0 -73
  24. package/form/controls/radio-group.control.d.ts +0 -22
  25. package/form/controls/radio-group.control.js +0 -28
  26. package/form/controls/select.control.d.ts +0 -17
  27. package/form/controls/select.control.js +0 -26
  28. package/form/controls/text.control.d.ts +0 -47
  29. package/form/controls/text.control.js +0 -94
  30. package/form/controls/time.control.d.ts +0 -24
  31. package/form/controls/time.control.js +0 -44
  32. package/form/form-array.d.ts +0 -71
  33. package/form/form-array.js +0 -188
  34. package/form/form-button.d.ts +0 -41
  35. package/form/form-button.js +0 -49
  36. package/form/form-container.d.ts +0 -24
  37. package/form/form-container.js +0 -33
  38. package/form/form-control.d.ts +0 -45
  39. package/form/form-control.js +0 -92
  40. package/form/form-dialog.d.ts +0 -22
  41. package/form/form-dialog.js +0 -24
  42. package/form/form-element.d.ts +0 -7
  43. package/form/form-element.js +0 -6
  44. package/form/form-group.d.ts +0 -70
  45. package/form/form-group.js +0 -134
  46. package/form/form-header-footer-element.d.ts +0 -14
  47. package/form/form-header-footer-element.js +0 -20
  48. package/form/form-portal.d.ts +0 -10
  49. package/form/form-portal.js +0 -13
  50. package/form/form-text.d.ts +0 -13
  51. package/form/form-text.js +0 -15
  52. package/form/form-wrapper.d.ts +0 -40
  53. package/form/form-wrapper.js +0 -64
  54. package/form/index.d.ts +0 -15
  55. package/form/index.js +0 -15
  56. package/form/localization.d.ts +0 -49
  57. package/form/localization.js +0 -56
  58. package/form/types.d.ts +0 -11
  59. package/form/types.js +0 -1
  60. package/form/utils.d.ts +0 -38
  61. package/form/utils.js +0 -47
  62. package/form/validators/boolean.validator.d.ts +0 -3
  63. package/form/validators/boolean.validator.js +0 -15
  64. package/form/validators/date.validator.d.ts +0 -4
  65. package/form/validators/date.validator.js +0 -26
  66. package/form/validators/form.validator.d.ts +0 -10
  67. package/form/validators/form.validator.js +0 -3
  68. package/form/validators/index.d.ts +0 -9
  69. package/form/validators/index.js +0 -9
  70. package/form/validators/max-length.validator.d.ts +0 -3
  71. package/form/validators/max-length.validator.js +0 -17
  72. package/form/validators/number.validator.d.ts +0 -4
  73. package/form/validators/number.validator.js +0 -22
  74. package/form/validators/pattern.validator.d.ts +0 -3
  75. package/form/validators/pattern.validator.js +0 -16
  76. package/form/validators/required.validator.d.ts +0 -3
  77. package/form/validators/required.validator.js +0 -16
  78. package/form/validators/time.validator.d.ts +0 -4
  79. package/form/validators/time.validator.js +0 -22
  80. package/form/validators/unique.validator.d.ts +0 -5
  81. package/form/validators/unique.validator.js +0 -22
@@ -1,40 +0,0 @@
1
- import { type Signal } from '../signals/api.js';
2
- import type { ReactiveValue } from '../types.js';
3
- import type { AbstractControl, AbstractControlRawValueType, AbstractControlValueType } from './abstract-control.js';
4
- import { type FormContainerOptions, FormContainer } from './form-container.js';
5
- export type FormWrapperOptions<T, C extends AbstractControl<T>> = FormContainerOptions<T> & {
6
- element: C;
7
- forwardWrites?: ReactiveValue<boolean>;
8
- forwardErrors?: ReactiveValue<boolean>;
9
- };
10
- export type FormWrapperByControl<C extends AbstractControl> = FormWrapper<AbstractControlValueType<C>, AbstractControlRawValueType<C>, C>;
11
- export declare abstract class FormWrapper<T = any, TRaw = any, C extends AbstractControl<T, TRaw> = AbstractControl<T, TRaw>> extends FormContainer<T, TRaw> {
12
- #private;
13
- protected readonly internalValidators: null;
14
- readonly element: Signal<C>;
15
- readonly forwardWrites: Signal<boolean>;
16
- readonly forwardErrors: Signal<boolean>;
17
- errors: Signal<import("./index.js").FormValidatorError[]>;
18
- valid: Signal<boolean>;
19
- invalid: Signal<boolean>;
20
- disabled: Signal<boolean>;
21
- enabled: Signal<boolean>;
22
- untouched: Signal<boolean>;
23
- pristine: Signal<boolean>;
24
- rawValue: Signal<TRaw>;
25
- value: Signal<T>;
26
- dirty: Signal<boolean>;
27
- touched: Signal<boolean>;
28
- errorDebug: Signal<{
29
- wrapped: any;
30
- }>;
31
- constructor(options: FormWrapperOptions<T, C>);
32
- setElement(element: C): void;
33
- setReadonly(readonly: boolean): void;
34
- setDisabled(disabled: boolean): void;
35
- setValue(value: T): void;
36
- reset(): void;
37
- markAsTouched(): void;
38
- markAsDirty(): void;
39
- }
40
- export declare function isFormWrapper(value: any): value is FormWrapper<any, any, any>;
@@ -1,64 +0,0 @@
1
- import { computed, signal, untracked } from '../signals/api.js';
2
- import { FormContainer } from './form-container.js';
3
- import { reactiveOptionToSignal } from './utils.js';
4
- export class FormWrapper extends FormContainer {
5
- #element = signal(null);
6
- internalValidators = null;
7
- element = this.#element.asReadonly();
8
- forwardWrites;
9
- forwardErrors;
10
- errors = computed(() => this.forwardErrors() ? this.element().errors() : []);
11
- valid = computed(() => this.forwardErrors() ? this.element().valid() : true);
12
- invalid = computed(() => this.forwardErrors() ? this.element().invalid() : false);
13
- disabled = computed(() => this.element().disabled());
14
- enabled = computed(() => this.element().enabled());
15
- untouched = computed(() => this.element().untouched());
16
- pristine = computed(() => this.element().pristine());
17
- rawValue = computed(() => this.element().rawValue());
18
- value = computed(() => this.element().value());
19
- dirty = computed(() => this.element().dirty());
20
- touched = computed(() => this.element().touched());
21
- errorDebug = computed(() => ({ wrapped: this.element().errorDebug() }));
22
- constructor(options) {
23
- super(options);
24
- this.forwardWrites = reactiveOptionToSignal(options.forwardWrites ?? true, { requireSync: true });
25
- this.forwardErrors = reactiveOptionToSignal(options.forwardErrors ?? true, { requireSync: true });
26
- this.setElement(options.element);
27
- }
28
- setElement(element) {
29
- this.#element.set(element);
30
- }
31
- setReadonly(readonly) {
32
- if (untracked(this.forwardWrites)) {
33
- untracked(this.element).setReadonly(readonly);
34
- }
35
- }
36
- setDisabled(disabled) {
37
- if (untracked(this.forwardWrites)) {
38
- untracked(this.element).setDisabled(disabled);
39
- }
40
- }
41
- setValue(value) {
42
- if (untracked(this.forwardWrites)) {
43
- untracked(this.element).setValue(value);
44
- }
45
- }
46
- reset() {
47
- if (untracked(this.forwardWrites)) {
48
- untracked(this.element).reset();
49
- }
50
- }
51
- markAsTouched() {
52
- if (untracked(this.forwardWrites)) {
53
- untracked(this.element).markAsTouched();
54
- }
55
- }
56
- markAsDirty() {
57
- if (untracked(this.forwardWrites)) {
58
- untracked(this.element).markAsDirty();
59
- }
60
- }
61
- }
62
- export function isFormWrapper(value) {
63
- return (value instanceof FormWrapper);
64
- }
package/form/index.d.ts DELETED
@@ -1,15 +0,0 @@
1
- export * from './abstract-control.js';
2
- export * from './controls/index.js';
3
- export * from './form-array.js';
4
- export * from './form-button.js';
5
- export * from './form-control.js';
6
- export * from './form-dialog.js';
7
- export * from './form-element.js';
8
- export * from './form-group.js';
9
- export * from './form-header-footer-element.js';
10
- export * from './form-portal.js';
11
- export * from './form-text.js';
12
- export * from './form-wrapper.js';
13
- export * from './types.js';
14
- export * from './utils.js';
15
- export * from './validators/index.js';
package/form/index.js DELETED
@@ -1,15 +0,0 @@
1
- export * from './abstract-control.js';
2
- export * from './controls/index.js';
3
- export * from './form-array.js';
4
- export * from './form-button.js';
5
- export * from './form-control.js';
6
- export * from './form-dialog.js';
7
- export * from './form-element.js';
8
- export * from './form-group.js';
9
- export * from './form-header-footer-element.js';
10
- export * from './form-portal.js';
11
- export * from './form-text.js';
12
- export * from './form-wrapper.js';
13
- export * from './types.js';
14
- export * from './utils.js';
15
- export * from './validators/index.js';
@@ -1,49 +0,0 @@
1
- import { type Localization, type LocalizeItem } from '../text/localization.service.js';
2
- export type TstdlFormLocalization = Localization<{
3
- tstdl: {
4
- validation: {
5
- required: LocalizeItem;
6
- unique: LocalizeItem;
7
- pattern: LocalizeItem;
8
- maxLength: LocalizeItem<{
9
- maxLength: number;
10
- }>;
11
- time: LocalizeItem<{
12
- minimum?: number;
13
- maximum?: number;
14
- }>;
15
- date: LocalizeItem<{
16
- minimum?: Date | number;
17
- maximum?: Date | number;
18
- }>;
19
- number: LocalizeItem<{
20
- minimum?: number;
21
- maximum?: number;
22
- }>;
23
- };
24
- };
25
- }>;
26
- export declare const tstdlFormLocalizationKeys: import("../text/localization.service.js").ProxyLocalizationKeys<{
27
- validation: {
28
- required: LocalizeItem;
29
- unique: LocalizeItem;
30
- pattern: LocalizeItem;
31
- maxLength: LocalizeItem<{
32
- maxLength: number;
33
- }>;
34
- time: LocalizeItem<{
35
- minimum?: number;
36
- maximum?: number;
37
- }>;
38
- date: LocalizeItem<{
39
- minimum?: Date | number;
40
- maximum?: Date | number;
41
- }>;
42
- number: LocalizeItem<{
43
- minimum?: number;
44
- maximum?: number;
45
- }>;
46
- };
47
- }>;
48
- export declare const germanTstdlFormLocalization: TstdlFormLocalization;
49
- export declare const englishTstdlFormLocalization: TstdlFormLocalization;
@@ -1,56 +0,0 @@
1
- import { formatDateShort, formatTimeShort } from '../formats.js';
2
- import { getLocalizationKeys } from '../text/localization.service.js';
3
- import { isDefined } from '../utils/type-guards.js';
4
- export const tstdlFormLocalizationKeys = getLocalizationKeys().tstdl;
5
- export const germanTstdlFormLocalization = {
6
- language: { code: 'de', name: 'Deutsch' },
7
- keys: {
8
- tstdl: {
9
- validation: {
10
- required: 'Angabe erforderlich',
11
- unique: 'Wert darf nur einmal vorkommen',
12
- pattern: 'Ungültiges Format',
13
- maxLength: ({ maxLength }) => `Maximallänge von ${maxLength} überschritten`,
14
- time: ({ minimum, maximum }) => ((isDefined(minimum) && isDefined(maximum)) ? `Uhrzeit muss zwischen ${formatTimeShort(minimum)} und ${formatTimeShort(maximum)} liegen`
15
- : isDefined(minimum) ? `Uhrzeit muss nach ${formatTimeShort(minimum)} liegen`
16
- : isDefined(maximum) ? `Uhrzeit muss vor ${formatTimeShort(maximum)} liegen`
17
- : 'Ungültige Uhrzeit'),
18
- date: ({ minimum, maximum }) => ((isDefined(minimum) && isDefined(maximum)) ? `Datum muss zwischen ${formatDateShort(minimum)} und ${formatDateShort(maximum)} liegen`
19
- : isDefined(minimum) ? `Datum muss nach ${formatDateShort(minimum)} liegen`
20
- : isDefined(maximum) ? `Datum muss vor ${formatDateShort(maximum)} liegen`
21
- : 'Ungültiges Datum'),
22
- number: ({ minimum, maximum }) => ((isDefined(minimum) && isDefined(maximum)) ? `Wert muss zwischen ${minimum} und ${maximum} liegen`
23
- : isDefined(minimum) ? `Wert muss größer/gleich ${minimum} sein`
24
- : isDefined(maximum) ? `Wert muss kleiner/gleich ${maximum} sein`
25
- : 'Ungültiger Wert')
26
- }
27
- }
28
- },
29
- enums: []
30
- };
31
- export const englishTstdlFormLocalization = {
32
- language: { code: 'en', name: 'English' },
33
- keys: {
34
- tstdl: {
35
- validation: {
36
- required: 'Input required',
37
- unique: 'Value must be unique',
38
- pattern: 'Invalid format',
39
- maxLength: ({ maxLength }) => `Maxmimum length of ${maxLength} exceeded`,
40
- time: ({ minimum, maximum }) => ((isDefined(minimum) && isDefined(maximum)) ? `Time must be between ${formatTimeShort(minimum)} and ${formatTimeShort(maximum)}`
41
- : isDefined(minimum) ? `Time must be after ${formatTimeShort(minimum)}`
42
- : isDefined(maximum) ? `Time must be before ${formatTimeShort(maximum)}`
43
- : 'Invalid time'),
44
- date: ({ minimum, maximum }) => ((isDefined(minimum) && isDefined(maximum)) ? `Date must be between ${formatDateShort(minimum)} and ${formatDateShort(maximum)}`
45
- : isDefined(minimum) ? `Date must be after ${formatDateShort(minimum)}`
46
- : isDefined(maximum) ? `Date must be before ${formatDateShort(maximum)}`
47
- : 'Invalid date'),
48
- number: ({ minimum, maximum }) => ((isDefined(minimum) && isDefined(maximum)) ? `Value must be between ${minimum} and ${maximum}`
49
- : isDefined(minimum) ? `Value must be at least ${minimum}`
50
- : isDefined(maximum) ? `Value must be at most ${maximum}`
51
- : 'Invalid value')
52
- }
53
- }
54
- },
55
- enums: []
56
- };
package/form/types.d.ts DELETED
@@ -1,11 +0,0 @@
1
- import type { LocalizableText } from '../text/localizable-text.model.js';
2
- import type { ReactiveValue } from '../types.js';
3
- import type { AbstractControl, AbstractControlRawValueType, AbstractControlValueType } from './abstract-control.js';
4
- export type FormControlRemoveHandler<C extends AbstractControl = AbstractControl> = (control: C) => boolean | Promise<boolean>;
5
- export type FormValue<T extends AbstractControl> = AbstractControlValueType<T>;
6
- export type RawFormValue<T extends AbstractControl> = AbstractControlRawValueType<T>;
7
- export type DynamicTextOption = LocalizableText | null;
8
- export type ClassesOption = string | string[] | null;
9
- export type ClassesOptions = {
10
- classes?: ReactiveValue<ClassesOption>;
11
- };
package/form/types.js DELETED
@@ -1 +0,0 @@
1
- export {};
package/form/utils.d.ts DELETED
@@ -1,38 +0,0 @@
1
- import { type Signal } from '../signals/index.js';
2
- import { LocalizationService } from '../text/localization.service.js';
3
- import type { EnumerationObject, FilledReadonlyArray, ReactiveValue } from '../types.js';
4
- import { type ReactiveValueToSignalOptions } from '../utils/reactive-value-to-signal.js';
5
- export type EnumFormItem<T> = {
6
- label: Signal<string>;
7
- value: T;
8
- };
9
- export type BindReactiveOptionOptions<D> = {
10
- defaultValue?: D;
11
- };
12
- export type BindReactiveOptionTarget<T> = (Signal<T> & {
13
- set: (value: T) => void;
14
- }) | ((value: T) => void);
15
- export declare function enumAsItems<T extends EnumerationObject>(enumeration: T, allowedValues?: FilledReadonlyArray<T[keyof T]>, localizationService?: LocalizationService): EnumFormItem<T[keyof T]>[];
16
- export declare function nullToUndefinedSignal<T>(source: Signal<T | null>): Signal<T | undefined>;
17
- export declare function reactiveOptionToSignal<T>(source: ReactiveValue<T>): Signal<T | undefined>;
18
- export declare function reactiveOptionToSignal<T>(source: ReactiveValue<T>, options: ReactiveValueToSignalOptions<T | undefined> & {
19
- initialValue?: undefined;
20
- requireSync?: false;
21
- }): Signal<T | undefined>;
22
- export declare function reactiveOptionToSignal<T>(source: ReactiveValue<T>, options: ReactiveValueToSignalOptions<T | null> & {
23
- initialValue?: null;
24
- requireSync?: false;
25
- }): Signal<T | null>;
26
- export declare function reactiveOptionToSignal<T>(source: ReactiveValue<T>, options: ReactiveValueToSignalOptions<T> & {
27
- initialValue?: undefined;
28
- requireSync: true;
29
- }): Signal<T>;
30
- export declare function reactiveOptionToSignal<T, const I>(source: ReactiveValue<T>, options: ReactiveValueToSignalOptions<T | I> & {
31
- initialValue: I;
32
- requireSync?: false;
33
- }): Signal<T | I>;
34
- export declare function bindReactiveOption<T>(option: ReactiveValue<T> | undefined, target: BindReactiveOptionTarget<T>): void;
35
- export declare function bindReactiveOption<T>(option: ReactiveValue<T | null | undefined>, target: BindReactiveOptionTarget<T>, options: BindReactiveOptionOptions<T> & {
36
- defaultValue: T;
37
- }): void;
38
- export declare function normalizeClassesOption(classes: string | string[] | null): string[];
package/form/utils.js DELETED
@@ -1,47 +0,0 @@
1
- import { inject } from '../injector/inject.js';
2
- import { computed, effect, isSignal, untracked } from '../signals/index.js';
3
- import { LocalizationService } from '../text/localization.service.js';
4
- import { enumValues } from '../utils/enum.js';
5
- import { hasOwnProperty } from '../utils/object/object.js';
6
- import { reactiveValueToSignal } from '../utils/reactive-value-to-signal.js';
7
- import { isNull, isNullOrUndefined, isString, isUndefined } from '../utils/type-guards.js';
8
- export function enumAsItems(enumeration, allowedValues, localizationService = inject(LocalizationService)) {
9
- return enumValues(enumeration)
10
- .filter((value) => allowedValues?.includes(value) ?? true)
11
- .map((type) => ({ label: localizationService.localizeEnum(enumeration, type), value: type }));
12
- }
13
- export function nullToUndefinedSignal(source) {
14
- return computed(() => source() ?? undefined);
15
- }
16
- export function reactiveOptionToSignal(source, options) {
17
- return untracked(() => reactiveValueToSignal(source, options));
18
- }
19
- export function bindReactiveOption(option, target, options = {}) {
20
- const targetSetValue = isSignal(target)
21
- ? (value) => target.set(value)
22
- : target;
23
- if (isUndefined(option)) {
24
- if (hasOwnProperty(options, 'defaultValue')) {
25
- targetSetValue(options.defaultValue);
26
- }
27
- return;
28
- }
29
- const setValue = (value) => {
30
- const defaultedValue = (isNullOrUndefined(value) && hasOwnProperty(options, 'defaultValue')) ? options.defaultValue : value;
31
- targetSetValue(defaultedValue);
32
- };
33
- const optionSignal = reactiveValueToSignal(option);
34
- untracked(() => effect(() => setValue(optionSignal()), { allowSignalWrites: true }));
35
- }
36
- export function normalizeClassesOption(classes) {
37
- if (isNull(classes)) {
38
- return [];
39
- }
40
- if (isString(classes)) {
41
- return classes
42
- .split(' ')
43
- .map((klass) => klass.trim())
44
- .filter((klass) => klass.length > 0);
45
- }
46
- return classes;
47
- }
@@ -1,3 +0,0 @@
1
- import type { DynamicText } from '../../text/dynamic-text.model.js';
2
- import { type FormValidator } from './form.validator.js';
3
- export declare function booleanValidator(value: boolean, errorMessage: DynamicText): FormValidator<boolean | null>;
@@ -1,15 +0,0 @@
1
- import { computed } from '../../signals/api.js';
2
- import { isNullOrUndefined } from '../../utils/type-guards.js';
3
- import { formValidatorError } from './form.validator.js';
4
- export function booleanValidator(value, errorMessage) {
5
- function booleanValidator(control) {
6
- return computed(() => {
7
- const controlValue = control.value();
8
- if (isNullOrUndefined(controlValue) || (controlValue == value)) {
9
- return null;
10
- }
11
- return formValidatorError(control, errorMessage);
12
- });
13
- }
14
- return booleanValidator;
15
- }
@@ -1,4 +0,0 @@
1
- import type { DynamicText } from '../../text/dynamic-text.model.js';
2
- import type { ReactiveValue } from '../../types.js';
3
- import { type FormValidator } from './form.validator.js';
4
- export declare function dateValidator(minimum: ReactiveValue<Date | number | null | undefined>, maximum: ReactiveValue<Date | number | null | undefined>, errorMessage?: DynamicText): FormValidator<Date | number | null>;
@@ -1,26 +0,0 @@
1
- import { computed } from '../../signals/api.js';
2
- import { localizationData } from '../../text/localization.service.js';
3
- import { dateToNumericDate } from '../../utils/date-time.js';
4
- import { isNullOrUndefined, isNumber } from '../../utils/type-guards.js';
5
- import { tstdlFormLocalizationKeys } from '../localization.js';
6
- import { reactiveOptionToSignal } from '../utils.js';
7
- import { formValidatorError } from './form.validator.js';
8
- export function dateValidator(minimum, maximum, errorMessage) {
9
- const minimumSignal = reactiveOptionToSignal(minimum);
10
- const maximumSignal = reactiveOptionToSignal(maximum);
11
- function dateValidator(control) {
12
- return computed(() => {
13
- const value = control.value();
14
- const min = minimumSignal();
15
- const max = maximumSignal();
16
- const valueNumericDate = isNullOrUndefined(value) ? null : isNumber(value) ? value : dateToNumericDate(value);
17
- const minNumericDate = isNullOrUndefined(min) ? null : isNumber(min) ? min : dateToNumericDate(min); // eslint-disable-line @typescript-eslint/strict-boolean-expressions
18
- const maxNumericDate = isNullOrUndefined(max) ? null : isNumber(max) ? max : dateToNumericDate(max);
19
- if (isNullOrUndefined(valueNumericDate) || ((isNullOrUndefined(minNumericDate) || (valueNumericDate >= minNumericDate)) && (isNullOrUndefined(maxNumericDate) || (valueNumericDate <= maxNumericDate)))) {
20
- return null;
21
- }
22
- return formValidatorError(control, errorMessage ?? localizationData(tstdlFormLocalizationKeys.validation.date, { minimum: min ?? undefined, maximum: max ?? undefined }));
23
- });
24
- }
25
- return dateValidator;
26
- }
@@ -1,10 +0,0 @@
1
- import type { Signal } from '../../signals/api.js';
2
- import type { DynamicText } from '../../text/dynamic-text.model.js';
3
- import type { AbstractControl } from '../abstract-control.js';
4
- export type FormValidator<T> = (control: AbstractControl<T>) => Signal<FormValidatorError | null>;
5
- export type FormValidatorProvider<T> = () => FormValidator<T>;
6
- export type FormValidatorError = {
7
- readonly control: AbstractControl;
8
- readonly errorMessage: DynamicText;
9
- };
10
- export declare function formValidatorError(control: AbstractControl, errorMessage: DynamicText): FormValidatorError;
@@ -1,3 +0,0 @@
1
- export function formValidatorError(control, errorMessage) {
2
- return { control, errorMessage };
3
- }
@@ -1,9 +0,0 @@
1
- export * from './boolean.validator.js';
2
- export * from './date.validator.js';
3
- export * from './form.validator.js';
4
- export * from './max-length.validator.js';
5
- export * from './number.validator.js';
6
- export * from './pattern.validator.js';
7
- export * from './required.validator.js';
8
- export * from './time.validator.js';
9
- export * from './unique.validator.js';
@@ -1,9 +0,0 @@
1
- export * from './boolean.validator.js';
2
- export * from './date.validator.js';
3
- export * from './form.validator.js';
4
- export * from './max-length.validator.js';
5
- export * from './number.validator.js';
6
- export * from './pattern.validator.js';
7
- export * from './required.validator.js';
8
- export * from './time.validator.js';
9
- export * from './unique.validator.js';
@@ -1,3 +0,0 @@
1
- import type { DynamicText } from '../../text/dynamic-text.model.js';
2
- import { type FormValidator } from './form.validator.js';
3
- export declare function maxLengthValidator(maxLength: number, errorMessage?: DynamicText): FormValidator<any[] | string>;
@@ -1,17 +0,0 @@
1
- import { computed } from '../../signals/api.js';
2
- import { localizationData } from '../../text/localization.service.js';
3
- import { isNullOrUndefined } from '../../utils/type-guards.js';
4
- import { tstdlFormLocalizationKeys } from '../localization.js';
5
- import { formValidatorError } from './form.validator.js';
6
- export function maxLengthValidator(maxLength, errorMessage) {
7
- function maxLengthValidator(control) {
8
- return computed(() => {
9
- const value = control.value();
10
- if (isNullOrUndefined(value) || value.length <= maxLength) {
11
- return null;
12
- }
13
- return formValidatorError(control, errorMessage ?? localizationData(tstdlFormLocalizationKeys.validation.maxLength, { maxLength }));
14
- });
15
- }
16
- return maxLengthValidator;
17
- }
@@ -1,4 +0,0 @@
1
- import type { DynamicText } from '../../text/dynamic-text.model.js';
2
- import type { ReactiveValue } from '../../types.js';
3
- import { type FormValidator } from './form.validator.js';
4
- export declare function numberValidator(minimum: ReactiveValue<number | null | undefined>, maximum: ReactiveValue<number | null | undefined>, errorMessage?: DynamicText): FormValidator<number | null>;
@@ -1,22 +0,0 @@
1
- import { computed } from '../../signals/api.js';
2
- import { localizationData } from '../../text/localization.service.js';
3
- import { isNullOrUndefined } from '../../utils/type-guards.js';
4
- import { tstdlFormLocalizationKeys } from '../localization.js';
5
- import { reactiveOptionToSignal } from '../utils.js';
6
- import { formValidatorError } from './form.validator.js';
7
- export function numberValidator(minimum, maximum, errorMessage) {
8
- const minimumSignal = reactiveOptionToSignal(minimum);
9
- const maximumSignal = reactiveOptionToSignal(maximum);
10
- function numberValidator(control) {
11
- return computed(() => {
12
- const value = control.value();
13
- const min = minimumSignal();
14
- const max = maximumSignal();
15
- if (isNullOrUndefined(value) || ((isNullOrUndefined(min) || (value >= min)) && (isNullOrUndefined(max) || (value <= max)))) {
16
- return null;
17
- }
18
- return formValidatorError(control, errorMessage ?? localizationData(tstdlFormLocalizationKeys.validation.number, { minimum: min ?? undefined, maximum: max ?? undefined }));
19
- });
20
- }
21
- return numberValidator;
22
- }
@@ -1,3 +0,0 @@
1
- import type { DynamicText } from '../../text/dynamic-text.model.js';
2
- import { type FormValidator } from './form.validator.js';
3
- export declare function patternValidator(pattern: RegExp, errorMessage?: DynamicText): FormValidator<string | null>;
@@ -1,16 +0,0 @@
1
- import { computed } from '../../signals/api.js';
2
- import { isNullOrUndefined } from '../../utils/type-guards.js';
3
- import { tstdlFormLocalizationKeys } from '../localization.js';
4
- import { formValidatorError } from './form.validator.js';
5
- export function patternValidator(pattern, errorMessage) {
6
- function patternValidator(control) {
7
- return computed(() => {
8
- const value = control.value();
9
- if (isNullOrUndefined(value) || pattern.test(value)) {
10
- return null;
11
- }
12
- return formValidatorError(control, errorMessage ?? tstdlFormLocalizationKeys.validation.pattern);
13
- });
14
- }
15
- return patternValidator;
16
- }
@@ -1,3 +0,0 @@
1
- import type { DynamicText } from '../../text/dynamic-text.model.js';
2
- import { type FormValidator } from './form.validator.js';
3
- export declare function requiredValidator<T>(errorMessage?: DynamicText): FormValidator<T>;
@@ -1,16 +0,0 @@
1
- import { computed } from '../../signals/api.js';
2
- import { isArray, isNullOrUndefined, isString } from '../../utils/type-guards.js';
3
- import { tstdlFormLocalizationKeys } from '../localization.js';
4
- import { formValidatorError } from './form.validator.js';
5
- export function requiredValidator(errorMessage) {
6
- function requiredValidator(control) {
7
- return computed(() => {
8
- const value = control.value();
9
- if (isNullOrUndefined(value) || (isString(value) && (value.trim().length == 0)) || (isArray(value) && value.length == 0)) {
10
- return formValidatorError(control, errorMessage ?? tstdlFormLocalizationKeys.validation.required);
11
- }
12
- return null;
13
- });
14
- }
15
- return requiredValidator;
16
- }
@@ -1,4 +0,0 @@
1
- import type { DynamicText } from '../../text/dynamic-text.model.js';
2
- import type { ReactiveValue } from '../../types.js';
3
- import { type FormValidator } from './form.validator.js';
4
- export declare function timeValidator(minimum: ReactiveValue<number | null | undefined>, maximum: ReactiveValue<number | null | undefined>, errorMessage?: DynamicText): FormValidator<number | null>;
@@ -1,22 +0,0 @@
1
- import { computed } from '../../signals/api.js';
2
- import { localizationData } from '../../text/localization.service.js';
3
- import { isNullOrUndefined } from '../../utils/type-guards.js';
4
- import { tstdlFormLocalizationKeys } from '../localization.js';
5
- import { reactiveOptionToSignal } from '../utils.js';
6
- import { formValidatorError } from './form.validator.js';
7
- export function timeValidator(minimum, maximum, errorMessage) {
8
- const minimumSignal = reactiveOptionToSignal(minimum);
9
- const maximumSignal = reactiveOptionToSignal(maximum);
10
- function timeValidator(control) {
11
- return computed(() => {
12
- const value = control.value();
13
- const min = minimumSignal();
14
- const max = maximumSignal();
15
- if (isNullOrUndefined(value) || ((isNullOrUndefined(min) || (value >= min)) && (isNullOrUndefined(max) || (value <= max)))) {
16
- return null;
17
- }
18
- return formValidatorError(control, errorMessage ?? localizationData(tstdlFormLocalizationKeys.validation.time, { minimum: min ?? undefined, maximum: max ?? undefined }));
19
- });
20
- }
21
- return timeValidator;
22
- }
@@ -1,5 +0,0 @@
1
- import type { DynamicText } from '../../text/dynamic-text.model.js';
2
- import type { ReactiveValue } from '../../types.js';
3
- import type { AbstractControl } from '../abstract-control.js';
4
- import { type FormValidator } from './form.validator.js';
5
- export declare function uniqueValidator<T>(otherControls: ReactiveValue<readonly AbstractControl<T>[]>, errorMessage?: DynamicText): FormValidator<T>;
@@ -1,22 +0,0 @@
1
- import { computed, getCurrentSignalsInjector, runInSignalsInjectionContext } from '../../signals/index.js';
2
- import { reactiveValueToSignal } from '../../utils/reactive-value-to-signal.js';
3
- import { isNotNull } from '../../utils/type-guards.js';
4
- import { tstdlFormLocalizationKeys } from '../localization.js';
5
- import { formValidatorError } from './form.validator.js';
6
- export function uniqueValidator(otherControls, errorMessage) {
7
- const signalsInjector = getCurrentSignalsInjector();
8
- function uniqueValidator(control) {
9
- const otherControlsSignal = runInSignalsInjectionContext(signalsInjector, () => reactiveValueToSignal(otherControls, { initialValue: [] }));
10
- return computed(() => {
11
- const ownValue = control.value();
12
- const otherValues = otherControlsSignal().filter((otherControl) => otherControl != control).map((otherControl) => (otherControl.disabled() ? null : otherControl.value())).filter(isNotNull);
13
- for (const value of otherValues) {
14
- if (ownValue == value) {
15
- return formValidatorError(control, errorMessage ?? tstdlFormLocalizationKeys.validation.unique);
16
- }
17
- }
18
- return null;
19
- });
20
- }
21
- return uniqueValidator;
22
- }