@tstdl/base 0.91.40 → 0.91.42

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 (80) hide show
  1. package/examples/orm/test.js +1 -0
  2. package/examples/orm/user.model.d.ts +5 -0
  3. package/examples/orm/user.model.js +8 -2
  4. package/orm/types.d.ts +6 -5
  5. package/orm/types.js +2 -2
  6. package/package.json +3 -2
  7. package/form/abstract-control.d.ts +0 -72
  8. package/form/abstract-control.js +0 -82
  9. package/form/controls/checkbox.control.d.ts +0 -10
  10. package/form/controls/checkbox.control.js +0 -19
  11. package/form/controls/chip-select.control.d.ts +0 -36
  12. package/form/controls/chip-select.control.js +0 -56
  13. package/form/controls/date.control.d.ts +0 -26
  14. package/form/controls/date.control.js +0 -64
  15. package/form/controls/hidden.control.d.ts +0 -11
  16. package/form/controls/hidden.control.js +0 -22
  17. package/form/controls/index.d.ts +0 -10
  18. package/form/controls/index.js +0 -10
  19. package/form/controls/items.control.d.ts +0 -38
  20. package/form/controls/items.control.js +0 -41
  21. package/form/controls/number.control.d.ts +0 -33
  22. package/form/controls/number.control.js +0 -73
  23. package/form/controls/radio-group.control.d.ts +0 -22
  24. package/form/controls/radio-group.control.js +0 -28
  25. package/form/controls/select.control.d.ts +0 -17
  26. package/form/controls/select.control.js +0 -26
  27. package/form/controls/text.control.d.ts +0 -47
  28. package/form/controls/text.control.js +0 -94
  29. package/form/controls/time.control.d.ts +0 -24
  30. package/form/controls/time.control.js +0 -44
  31. package/form/form-array.d.ts +0 -71
  32. package/form/form-array.js +0 -188
  33. package/form/form-button.d.ts +0 -41
  34. package/form/form-button.js +0 -49
  35. package/form/form-container.d.ts +0 -24
  36. package/form/form-container.js +0 -33
  37. package/form/form-control.d.ts +0 -45
  38. package/form/form-control.js +0 -92
  39. package/form/form-dialog.d.ts +0 -22
  40. package/form/form-dialog.js +0 -24
  41. package/form/form-element.d.ts +0 -7
  42. package/form/form-element.js +0 -6
  43. package/form/form-group.d.ts +0 -70
  44. package/form/form-group.js +0 -134
  45. package/form/form-header-footer-element.d.ts +0 -14
  46. package/form/form-header-footer-element.js +0 -20
  47. package/form/form-portal.d.ts +0 -10
  48. package/form/form-portal.js +0 -13
  49. package/form/form-text.d.ts +0 -13
  50. package/form/form-text.js +0 -15
  51. package/form/form-wrapper.d.ts +0 -40
  52. package/form/form-wrapper.js +0 -64
  53. package/form/index.d.ts +0 -15
  54. package/form/index.js +0 -15
  55. package/form/localization.d.ts +0 -49
  56. package/form/localization.js +0 -56
  57. package/form/types.d.ts +0 -11
  58. package/form/types.js +0 -1
  59. package/form/utils.d.ts +0 -38
  60. package/form/utils.js +0 -47
  61. package/form/validators/boolean.validator.d.ts +0 -3
  62. package/form/validators/boolean.validator.js +0 -15
  63. package/form/validators/date.validator.d.ts +0 -4
  64. package/form/validators/date.validator.js +0 -26
  65. package/form/validators/form.validator.d.ts +0 -10
  66. package/form/validators/form.validator.js +0 -3
  67. package/form/validators/index.d.ts +0 -9
  68. package/form/validators/index.js +0 -9
  69. package/form/validators/max-length.validator.d.ts +0 -3
  70. package/form/validators/max-length.validator.js +0 -17
  71. package/form/validators/number.validator.d.ts +0 -4
  72. package/form/validators/number.validator.js +0 -22
  73. package/form/validators/pattern.validator.d.ts +0 -3
  74. package/form/validators/pattern.validator.js +0 -16
  75. package/form/validators/required.validator.d.ts +0 -3
  76. package/form/validators/required.validator.js +0 -16
  77. package/form/validators/time.validator.d.ts +0 -4
  78. package/form/validators/time.validator.js +0 -22
  79. package/form/validators/unique.validator.d.ts +0 -5
  80. package/form/validators/unique.validator.js +0 -22
@@ -1,188 +0,0 @@
1
- import { computed, signal, untracked } from '../signals/api.js';
2
- import { switchAll } from '../signals/index.js';
3
- import { createArray } from '../utils/array/array.js';
4
- import { fromEntries } from '../utils/object/object.js';
5
- import { deferThrow } from '../utils/throw.js';
6
- import { isDefined, isNotNull } from '../utils/type-guards.js';
7
- import { ignoreFormValue } from './abstract-control.js';
8
- import { FormContainer } from './form-container.js';
9
- import { bindReactiveOption } from './utils.js';
10
- export class FormArray extends FormContainer {
11
- #children = signal([]);
12
- #selfTouched = signal(false);
13
- #selfDirty = signal(false);
14
- #displayType = signal('tabs');
15
- #allowRemove = signal(true);
16
- #allowRemoveAll = signal(true);
17
- #removedChildren = signal(new Set());
18
- internalValidators = null;
19
- children = this.#children.asReadonly();
20
- enabledChildren = computed(() => this.#children().filter((child) => child.enabled()));
21
- size = computed(() => this.children().length);
22
- displayType = this.#displayType.asReadonly();
23
- allowRemove = this.#allowRemove.asReadonly();
24
- allowRemoveAll = this.#allowRemoveAll.asReadonly();
25
- removedChildren = computed(() => [...this.#removedChildren()]);
26
- removeHandler;
27
- builder;
28
- /** Raw values of all children whether disabled or not */
29
- rawValue = computed(() => this.#children().map((child) => child.rawValue()));
30
- /** Values of all enabled children */
31
- value = computed(() => this.enabledChildren().map((child) => child.value()));
32
- dirty = computed(() => this.#selfDirty() || this.children().some((child) => child.dirty()));
33
- touched = computed(() => this.#selfTouched() || this.children().some((child) => child.touched()));
34
- localErrors = switchAll(() => {
35
- const validations = this.validators().map((validator) => validator(this));
36
- return computed(() => validations.map((validation) => validation()).filter(isNotNull));
37
- });
38
- childrenErrors = computed(() => this.children().flatMap((child) => child.errors()));
39
- errors = computed(() => [
40
- ...this.localErrors(),
41
- ...this.childrenErrors()
42
- ]);
43
- errorDebug = computed(() => this.valid()
44
- ? null
45
- : ({
46
- _self: this.localErrors(),
47
- ...fromEntries(this.children().map((child, index) => [index, child.errorDebug()]).filter(([, errorDebug]) => isNotNull(errorDebug)))
48
- }));
49
- constructor(options = {}) {
50
- super(options);
51
- this.builder = options.builder ?? deferThrow(() => new Error('Builder required to add children by value'));
52
- this.removeHandler = options.removeHandler ?? (() => true);
53
- if (isDefined(options.children)) {
54
- this.add(...options.children);
55
- }
56
- bindReactiveOption(options.displayType, this.#displayType);
57
- bindReactiveOption(options.allowRemove, this.#allowRemove);
58
- bindReactiveOption(options.allowRemoveAll, this.#allowRemoveAll);
59
- }
60
- get(index) {
61
- return this.children()[index];
62
- }
63
- getValue(index) {
64
- return this.get(index)?.value();
65
- }
66
- getRawValue(index) {
67
- return this.get(index)?.rawValue();
68
- }
69
- reset() {
70
- for (const child of untracked(this.#children)) {
71
- child.reset();
72
- }
73
- this.#removedChildren.set(new Set());
74
- }
75
- indexOf(child) {
76
- const index = untracked(this.children).indexOf(child);
77
- return (index == -1) ? null : index;
78
- }
79
- add(...children) {
80
- this.#children.set([...untracked(this.children), ...children]);
81
- for (const child of children) {
82
- child.setParent(this);
83
- }
84
- }
85
- addValue(...values) {
86
- const children = values.map((value) => this.builder(value));
87
- this.add(...children);
88
- }
89
- removeAll() {
90
- const newlyRemovedChildren = [];
91
- for (const child of untracked(this.children)) {
92
- if (untracked(child.parent) == this) {
93
- child.setParent(null);
94
- }
95
- newlyRemovedChildren.push(child);
96
- }
97
- this.#removedChildren.update((removedChildren) => new Set([...removedChildren, ...newlyRemovedChildren]));
98
- this.#children.set([]);
99
- }
100
- remove(child) {
101
- const index = this.indexOf(child);
102
- if (isNotNull(index)) {
103
- this.removeAt(index);
104
- }
105
- }
106
- removeAt(index, count = 1) {
107
- const children = untracked(this.children);
108
- const newlyRemovedChildren = [];
109
- const end = Math.min(index + count, children.length);
110
- if (end <= index) {
111
- return;
112
- }
113
- for (let i = index; i < end; i++) {
114
- const child = children[i];
115
- child.setParent(null);
116
- newlyRemovedChildren.push(child);
117
- }
118
- const spliced = children.toSpliced(index, 1);
119
- this.#removedChildren.update((removedChildren) => new Set([...removedChildren, ...newlyRemovedChildren]));
120
- this.#children.set(spliced);
121
- }
122
- setValue(values) {
123
- if (values == ignoreFormValue) {
124
- return;
125
- }
126
- let children = untracked(this.#children);
127
- const newlyRemovedChildren = [];
128
- if (values.length < children.length) {
129
- for (let i = values.length; i < children.length - 1; i++) {
130
- const child = children[i];
131
- child.setParent(null);
132
- newlyRemovedChildren.push(child);
133
- }
134
- children = children.slice(0, values.length);
135
- }
136
- else if (values.length > children.length) {
137
- const newChildren = createArray(values.length - children.length, (index) => this.builder(values[children.length + index]));
138
- children = [...children, ...newChildren];
139
- }
140
- for (let i = 0; i < values.length; i++) {
141
- children[i].setValue(values[i]);
142
- }
143
- this.#removedChildren.update((removedChildren) => new Set([...removedChildren, ...newlyRemovedChildren]));
144
- this.#children.set(children);
145
- }
146
- markAsDirty({ onlySelf = false } = {}) {
147
- this.#selfDirty.set(true);
148
- if (onlySelf) {
149
- return;
150
- }
151
- for (const child of untracked(this.children)) {
152
- child.markAsDirty();
153
- }
154
- }
155
- markAsTouched({ onlySelf = false } = {}) {
156
- this.#selfTouched.set(true);
157
- if (onlySelf) {
158
- return;
159
- }
160
- for (const child of untracked(this.children)) {
161
- child.markAsTouched();
162
- }
163
- }
164
- setParent(parent, force) {
165
- super.setParent(parent, force);
166
- this.updateParents(true);
167
- }
168
- *[Symbol.iterator]() {
169
- yield* untracked(this.children);
170
- }
171
- getChildPath(child) {
172
- return computed(() => {
173
- const key = this.#children().indexOf(child);
174
- return this.path().add((key >= 0) ? key : 'CHILD_NOT_FOUND');
175
- });
176
- }
177
- updateParents(force) {
178
- for (const child of untracked(this.#children)) {
179
- child.setParent(this, force);
180
- }
181
- }
182
- }
183
- export function formArray(options) {
184
- return new FormArray(options); // eslint-disable-line @typescript-eslint/no-unsafe-return
185
- }
186
- export function isFormArray(value) {
187
- return (value instanceof FormArray);
188
- }
@@ -1,41 +0,0 @@
1
- import type { PartialProperty, ReactiveValue, TypedOmit } from '../types.js';
2
- import type { FormDialog } from './form-dialog.js';
3
- import { FormHeaderFooterElement, type FormHeaderFooterElementOptions } from './form-header-footer-element.js';
4
- import type { DynamicTextOption } from './types.js';
5
- export type FormButtonSize = 'normal' | 'small';
6
- export type FormButtonColor = 'transparent' | 'white' | 'accent' | 'neutral' | 'stone' | 'red' | 'orange' | 'amber' | 'yellow' | 'lime' | 'green' | 'emerald' | 'teal' | 'cyan' | 'sky' | 'blue' | 'indigo' | 'violet' | 'purple' | 'fuchsia' | 'pink' | 'rose';
7
- export type FormButtonType = 'button' | 'submit' | 'reset';
8
- export type FormButtonDesign = 'flat' | 'outline' | 'icon' | 'icon-outline' | 'none';
9
- export type IconLocation = 'before' | 'after';
10
- export type IconSize = 'small' | 'normal';
11
- export type FormButtonHandler = () => any;
12
- export type FormButtonOptions = FormHeaderFooterElementOptions & {
13
- handler: FormButtonHandler;
14
- label?: ReactiveValue<DynamicTextOption>;
15
- type?: ReactiveValue<FormButtonType | null>;
16
- disabled?: ReactiveValue<boolean | null>;
17
- design?: ReactiveValue<FormButtonDesign | null>;
18
- color?: ReactiveValue<FormButtonColor | null>;
19
- icon?: ReactiveValue<string | null>;
20
- iconLocation?: ReactiveValue<IconLocation | null>;
21
- iconSize?: ReactiveValue<IconSize | null>;
22
- };
23
- export declare class FormButton extends FormHeaderFooterElement {
24
- #private;
25
- readonly handler: FormButtonHandler;
26
- readonly label: import("../signals/api.js").Signal<DynamicTextOption>;
27
- readonly type: import("../signals/api.js").Signal<FormButtonType>;
28
- readonly disabled: import("../signals/api.js").Signal<boolean>;
29
- readonly style: import("../signals/api.js").Signal<FormButtonDesign>;
30
- readonly color: import("../signals/api.js").Signal<FormButtonColor>;
31
- readonly icon: import("../signals/api.js").Signal<string | null>;
32
- readonly iconLocation: import("../signals/api.js").Signal<IconLocation>;
33
- readonly iconSize: import("../signals/api.js").Signal<IconSize>;
34
- constructor(options: FormButtonOptions);
35
- }
36
- export declare function formButton(options: FormButtonOptions): FormButton;
37
- export declare function dialogFormButton(options: {
38
- dialog: FormDialog;
39
- showErrors?: boolean;
40
- } & TypedOmit<PartialProperty<FormButtonOptions, 'handler'>, 'icon' | 'color'>): FormButton;
41
- export declare function isFormButton(value: any): value is FormButton;
@@ -1,49 +0,0 @@
1
- import { computed, signal } from '../signals/api.js';
2
- import { FormHeaderFooterElement } from './form-header-footer-element.js';
3
- import { bindReactiveOption } from './utils.js';
4
- export class FormButton extends FormHeaderFooterElement {
5
- #label = signal(null);
6
- #type = signal('button');
7
- #disabled = signal(false);
8
- #design = signal('flat');
9
- #color = signal('accent');
10
- #icon = signal(null);
11
- #iconLocation = signal('before');
12
- #iconSize = signal('normal');
13
- handler;
14
- label = this.#label.asReadonly();
15
- type = this.#type.asReadonly();
16
- disabled = this.#disabled.asReadonly();
17
- style = this.#design.asReadonly();
18
- color = this.#color.asReadonly();
19
- icon = this.#icon.asReadonly();
20
- iconLocation = this.#iconLocation.asReadonly();
21
- iconSize = this.#iconSize.asReadonly();
22
- constructor(options) {
23
- super(options);
24
- this.handler = options.handler;
25
- bindReactiveOption(options.label, this.#label, { defaultValue: null });
26
- bindReactiveOption(options.type, this.#type, { defaultValue: 'button' });
27
- bindReactiveOption(options.disabled, this.#disabled, { defaultValue: false });
28
- bindReactiveOption(options.design, this.#design, { defaultValue: 'flat' });
29
- bindReactiveOption(options.color, this.#color, { defaultValue: 'accent' });
30
- bindReactiveOption(options.icon, this.#icon, { defaultValue: null });
31
- bindReactiveOption(options.iconLocation, this.#iconLocation, { defaultValue: 'before' });
32
- bindReactiveOption(options.iconSize, this.#iconSize, { defaultValue: 'normal' });
33
- }
34
- }
35
- export function formButton(options) {
36
- return new FormButton(options);
37
- }
38
- export function dialogFormButton(options) {
39
- const showError = computed(() => ((options.showErrors ?? true) ? options.dialog.touched() ? options.dialog.invalid() : false : false));
40
- return formButton({
41
- handler: () => options.dialog.openDialog(),
42
- ...options,
43
- icon: computed(() => (showError() ? 'warning' : null)),
44
- color: computed(() => (showError() ? 'red' : null))
45
- });
46
- }
47
- export function isFormButton(value) {
48
- return (value instanceof FormButton);
49
- }
@@ -1,24 +0,0 @@
1
- import type { OneOrMany, ReactiveValue } from '../types.js';
2
- import { AbstractControl, type AbstractControlOptions } from './abstract-control.js';
3
- import type { FormHeaderFooterElement } from './form-header-footer-element.js';
4
- import type { ClassesOption, ClassesOptions } from './types.js';
5
- export type FormContainerOptions<T> = AbstractControlOptions<T> & ClassesOptions & {
6
- displayLabel?: ReactiveValue<boolean>;
7
- displayLine?: ReactiveValue<boolean>;
8
- headerContainerClasses?: ReactiveValue<ClassesOption>;
9
- footerContainerClasses?: ReactiveValue<ClassesOption>;
10
- headerElements?: ReactiveValue<OneOrMany<FormHeaderFooterElement>>;
11
- footerElements?: ReactiveValue<OneOrMany<FormHeaderFooterElement>>;
12
- };
13
- export declare abstract class FormContainer<T, TRaw> extends AbstractControl<T, TRaw> {
14
- #private;
15
- readonly displayLabel: import("../signals/api.js").Signal<boolean>;
16
- readonly displayLine: import("../signals/api.js").Signal<boolean>;
17
- readonly headerElements: import("../signals/api.js").Signal<readonly FormHeaderFooterElement[]>;
18
- readonly footerElements: import("../signals/api.js").Signal<readonly FormHeaderFooterElement[]>;
19
- readonly headerContainerClasses: import("../signals/api.js").Signal<readonly string[]>;
20
- readonly footerContainerClasses: import("../signals/api.js").Signal<readonly string[]>;
21
- readonly classes: import("../signals/api.js").Signal<readonly string[]>;
22
- constructor(options: FormContainerOptions<T>);
23
- }
24
- export declare function isFormContainer(value: any): value is FormContainer<any, any>;
@@ -1,33 +0,0 @@
1
- import { signal } from '../signals/api.js';
2
- import { toArray } from '../utils/array/array.js';
3
- import { AbstractControl } from './abstract-control.js';
4
- import { bindReactiveOption, normalizeClassesOption } from './utils.js';
5
- export class FormContainer extends AbstractControl {
6
- #displayLabel = signal(true);
7
- #displayLine = signal(false);
8
- #headerElements = signal([]);
9
- #footerElements = signal([]);
10
- #headerContainerClasses = signal([]);
11
- #footerContainerClasses = signal([]);
12
- #classes = signal([]);
13
- displayLabel = this.#displayLabel.asReadonly();
14
- displayLine = this.#displayLine.asReadonly();
15
- headerElements = this.#headerElements.asReadonly();
16
- footerElements = this.#footerElements.asReadonly();
17
- headerContainerClasses = this.#headerContainerClasses.asReadonly();
18
- footerContainerClasses = this.#footerContainerClasses.asReadonly();
19
- classes = this.#classes.asReadonly();
20
- constructor(options) {
21
- super(options);
22
- bindReactiveOption(options.displayLabel, this.#displayLabel, { defaultValue: true });
23
- bindReactiveOption(options.displayLine, this.#displayLine, { defaultValue: false });
24
- bindReactiveOption(options.headerElements, (elements) => this.#headerElements.set(toArray(elements)), { defaultValue: [] });
25
- bindReactiveOption(options.footerElements, (elements) => this.#footerElements.set(toArray(elements)), { defaultValue: [] });
26
- bindReactiveOption(options.headerContainerClasses, (classes) => this.#headerContainerClasses.set(normalizeClassesOption(classes)));
27
- bindReactiveOption(options.footerContainerClasses, (classes) => this.#footerContainerClasses.set(normalizeClassesOption(classes)));
28
- bindReactiveOption(options.classes, (classes) => this.#classes.set(normalizeClassesOption(classes)));
29
- }
30
- }
31
- export function isFormContainer(value) {
32
- return (value instanceof FormContainer);
33
- }
@@ -1,45 +0,0 @@
1
- import { type Signal } from '../signals/api.js';
2
- import type { ReactiveValue } from '../types.js';
3
- import { AbstractControl, type AbstractControlOptions } from './abstract-control.js';
4
- import type { ClassesOptions, DynamicTextOption } from './types.js';
5
- import { type FormValidatorError } from './validators/index.js';
6
- export type InitialValue<T> = T | null;
7
- export type InitialValueOption<T> = {
8
- initialValue: T;
9
- };
10
- export type FormControlOptions<T = any> = AbstractControlOptions<T> & ClassesOptions & {
11
- initialValue?: ReactiveValue<T>;
12
- required?: ReactiveValue<boolean | null>;
13
- suffix?: ReactiveValue<DynamicTextOption>;
14
- hint?: ReactiveValue<DynamicTextOption>;
15
- };
16
- export type FormControlValueType<T extends FormControl<any>> = T extends FormControl<infer U> ? U : never;
17
- export declare abstract class FormControl<T, U = any> extends AbstractControl<T, T> {
18
- #private;
19
- readonly initialValue: Signal<T>;
20
- readonly rawValue: Signal<T>;
21
- /** Value for rendering including formatting etc. */
22
- readonly inputValue: Signal<U | null>;
23
- /** Same as {@link rawValue} for simple controls */
24
- readonly value: Signal<T>;
25
- readonly dirty: Signal<boolean>;
26
- readonly touched: Signal<boolean>;
27
- readonly required: Signal<boolean>;
28
- readonly suffix: Signal<DynamicTextOption>;
29
- readonly hint: Signal<DynamicTextOption>;
30
- readonly classes: Signal<string[]>;
31
- readonly errors: Signal<FormValidatorError[]>;
32
- readonly errorDebug: Signal<FormValidatorError[] | null>;
33
- constructor(initialValue: T, options: FormControlOptions<T>);
34
- setInitialValue(value: T): void;
35
- setInputValue(value: U | null): void;
36
- setValue(value: T | null): void;
37
- reset(): void;
38
- markAsDirty(): void;
39
- markAsTouched(): void;
40
- formatInputValue(): void;
41
- parseRawValue?(value: T | null): T | null;
42
- abstract parseInputValue(value: U | null): T | null;
43
- abstract formatRawValue(value: T | null): U;
44
- }
45
- export declare function isFormControl(value: any): value is FormControl<any>;
@@ -1,92 +0,0 @@
1
- import { computed, signal, untracked } from '../signals/api.js';
2
- import { switchAll } from '../signals/index.js';
3
- import { isDefined, isNotNull } from '../utils/type-guards.js';
4
- import { AbstractControl, computedInternalValidators, ignoreFormValue } from './abstract-control.js';
5
- import { bindReactiveOption, normalizeClassesOption } from './utils.js';
6
- import { requiredValidator } from './validators/index.js';
7
- export class FormControl extends AbstractControl {
8
- #initialValue = signal(null);
9
- #rawValue = signal(null);
10
- #inputValue = signal(null);
11
- #dirty = signal(false);
12
- #touched = signal(false);
13
- #required = signal(false);
14
- #suffix = signal(null);
15
- #hint = signal(null);
16
- #classes = signal([]);
17
- initialValue = this.#initialValue.asReadonly();
18
- rawValue = computed(() => this.#rawValue() ?? this.initialValue());
19
- /** Value for rendering including formatting etc. */
20
- inputValue = this.#inputValue.asReadonly();
21
- /** Same as {@link rawValue} for simple controls */
22
- value = this.rawValue;
23
- dirty = this.#dirty.asReadonly();
24
- touched = this.#touched.asReadonly();
25
- required = this.#required.asReadonly();
26
- suffix = this.#suffix.asReadonly();
27
- hint = this.#hint.asReadonly();
28
- classes = this.#classes.asReadonly();
29
- errors = switchAll(() => {
30
- const validations = this.validators().map((validator) => validator(this));
31
- return computed(() => validations.map((validation) => validation()).filter(isNotNull));
32
- });
33
- errorDebug = computed(() => this.valid() ? null : this.errors());
34
- constructor(initialValue, options) {
35
- super(options);
36
- this.#initialValue.set(initialValue);
37
- this.setValue(initialValue);
38
- bindReactiveOption(options.initialValue ?? initialValue, (value) => this.setInitialValue(value));
39
- bindReactiveOption(options.required, this.#required, { defaultValue: false });
40
- bindReactiveOption(options.suffix, this.#suffix, { defaultValue: null });
41
- bindReactiveOption(options.hint, this.#hint, { defaultValue: null });
42
- bindReactiveOption(options.classes, (value) => this.#classes.set(normalizeClassesOption(value)));
43
- this.registerValidators(computedInternalValidators(() => [
44
- this.required() ? requiredValidator() : null
45
- ]));
46
- }
47
- setInitialValue(value) {
48
- const updateInputValue = untracked(this.value) == untracked(this.initialValue);
49
- this.#initialValue.set(value);
50
- if (updateInputValue) {
51
- this.#inputValue.set(this.formatRawValue(value));
52
- }
53
- }
54
- setInputValue(value) {
55
- if (value == untracked(this.#inputValue)) {
56
- return;
57
- }
58
- const parsed = this.parseInputValue(value);
59
- this.#inputValue.set(value);
60
- this.#rawValue.set(parsed);
61
- }
62
- setValue(value) {
63
- if (value == ignoreFormValue) {
64
- return;
65
- }
66
- const newRawValue = (value == this.initialValue()) ? null : value;
67
- if (newRawValue === untracked(this.#rawValue)) {
68
- return;
69
- }
70
- const parsed = isDefined(this.parseRawValue) ? this.parseRawValue(newRawValue) : newRawValue; // eslint-disable-line @typescript-eslint/unbound-method
71
- this.#rawValue.set(parsed);
72
- this.formatInputValue();
73
- }
74
- reset() {
75
- this.setValue(null);
76
- this.#dirty.set(false);
77
- this.#touched.set(false);
78
- }
79
- markAsDirty() {
80
- this.#dirty.set(true);
81
- }
82
- markAsTouched() {
83
- this.#touched.set(true);
84
- }
85
- formatInputValue() {
86
- const formatted = this.formatRawValue(untracked(this.value));
87
- this.#inputValue.set(formatted);
88
- }
89
- }
90
- export function isFormControl(value) {
91
- return (value instanceof FormControl);
92
- }
@@ -1,22 +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 { FormWrapper, type FormWrapperOptions } from './form-wrapper.js';
5
- import type { DynamicTextOption } from './types.js';
6
- export type FormDialogOptions<T, C extends AbstractControl<T>> = FormWrapperOptions<T, C> & {
7
- header?: ReactiveValue<DynamicTextOption>;
8
- displayType?: ReactiveValue<FormDialogDisplayType>;
9
- };
10
- export type FormDialogDisplayType = 'none' | 'button';
11
- export type FormDialogByControl<C extends AbstractControl> = FormDialog<AbstractControlValueType<C>, AbstractControlRawValueType<C>, C>;
12
- export declare class FormDialog<T = any, TRaw = any, C extends AbstractControl<T, TRaw> = AbstractControl<T, TRaw>, DialogHandle = any> extends FormWrapper<T, TRaw, C> {
13
- #private;
14
- readonly displayType: Signal<FormDialogDisplayType>;
15
- readonly header: Signal<DynamicTextOption>;
16
- readonly openDialog$: import("rxjs").Observable<void>;
17
- dialogHandle: DialogHandle | null;
18
- constructor(options: FormDialogOptions<T, C>);
19
- openDialog(): void;
20
- }
21
- export declare function formDialog<C extends AbstractControl>(options: FormDialogOptions<AbstractControlRawValueType<C>, C>): FormDialog<AbstractControlValueType<C>, AbstractControlRawValueType<C>, C>;
22
- export declare function isFormDialog(value: any): value is FormDialog;
@@ -1,24 +0,0 @@
1
- import { Subject } from 'rxjs';
2
- import { FormWrapper } from './form-wrapper.js';
3
- import { reactiveOptionToSignal } from './utils.js';
4
- export class FormDialog extends FormWrapper {
5
- #openDialogSubject = new Subject();
6
- displayType;
7
- header;
8
- openDialog$ = this.#openDialogSubject.asObservable();
9
- dialogHandle = null;
10
- constructor(options) {
11
- super(options);
12
- this.displayType = reactiveOptionToSignal(options.displayType ?? 'none', { initialValue: 'none' });
13
- this.header = reactiveOptionToSignal(options.header ?? null, { initialValue: null });
14
- }
15
- openDialog() {
16
- this.#openDialogSubject.next();
17
- }
18
- }
19
- export function formDialog(options) {
20
- return new FormDialog(options);
21
- }
22
- export function isFormDialog(value) {
23
- return (value instanceof FormDialog);
24
- }
@@ -1,7 +0,0 @@
1
- export type FormElementOptions = {
2
- id?: string;
3
- };
4
- export declare abstract class FormElement {
5
- readonly id: string;
6
- constructor(options?: FormElementOptions);
7
- }
@@ -1,6 +0,0 @@
1
- export class FormElement {
2
- id;
3
- constructor(options) {
4
- this.id = options?.id ?? crypto.randomUUID();
5
- }
6
- }
@@ -1,70 +0,0 @@
1
- import type { JsonPath } from '../json-path/json-path.js';
2
- import { type Signal } from '../signals/index.js';
3
- import type { ReactiveValue, Record } from '../types.js';
4
- import { type AbstractControl, type AbstractControlParent, type AbstractControlRawValueType, type AbstractControlValueType, type MarkOptions } from './abstract-control.js';
5
- import { FormContainer, type FormContainerOptions } from './form-container.js';
6
- import type { FormValue, RawFormValue } from './types.js';
7
- import type { FormValidatorError } from './validators/form.validator.js';
8
- type FormGroupDisplayType = 'simple' | 'block' | 'stepper' | 'tabs';
9
- type FormGroupStepperOrientiation = 'horizontal' | 'vertical';
10
- export type FromGroupControls<T extends Record> = {
11
- [P in keyof T]: AbstractControl<T[P]>;
12
- };
13
- export type FormGroupOptions<T extends Record = Record, C extends FromGroupControls<T> = FromGroupControls<T>> = FormContainerOptions<Partial<T>> & {
14
- displayType?: ReactiveValue<FormGroupDisplayType>;
15
- stepperOrientation?: ReactiveValue<FormGroupStepperOrientiation>;
16
- children: C;
17
- };
18
- export type FormGroupChildren<T extends FormGroup> = T extends FormGroup<any, infer C> ? C : never;
19
- export type FormGroupChild<T extends FormGroup, K extends keyof FormGroupChildren<T>> = FormGroupChildren<T>[K];
20
- export type FormGroupChildValue<T extends FormGroup, K extends keyof AbstractControlRawValueType<T>> = AbstractControlValueType<T>[K];
21
- export type FormGroupChildRawValue<T extends FormGroup, K extends keyof AbstractControlRawValueType<T>> = AbstractControlRawValueType<T>[K];
22
- export type FormGroupRawValueType<C extends FromGroupControls<Record>> = {
23
- [P in keyof C]: AbstractControlRawValueType<C[P]>;
24
- };
25
- export type FormGroupByControls<C extends FromGroupControls<Record> = FromGroupControls<Record>> = FormGroup<FormGroupRawValueType<C>, C>;
26
- export declare class FormGroup<T extends Record = Record, C extends FromGroupControls<T> = FromGroupControls<T>> extends FormContainer<Partial<T>, T> implements Iterable<[keyof C, C[keyof C]]> {
27
- #private;
28
- protected readonly internalValidators: null;
29
- readonly displayType: Signal<FormGroupDisplayType>;
30
- readonly stepperOrientation: Signal<FormGroupStepperOrientiation>;
31
- readonly children: Signal<Readonly<C>>;
32
- readonly childrenEntries: Signal<[keyof C, Readonly<C>[keyof C]][]>;
33
- readonly childrenValues: Signal<Readonly<C>[keyof C][]>;
34
- readonly enabledChildrenEntries: Signal<[keyof C, Readonly<C>[keyof C]][]>;
35
- readonly enabledChildrenValues: Signal<Readonly<C>[keyof C][]>;
36
- /**
37
- * Raw values of all children whether disabled or not
38
- */
39
- readonly rawValue: Signal<T>;
40
- /**
41
- * If enabled: values of all enabled children
42
- * if disabled: values of all children whether disabled or not (same as {@link rawValue})
43
- */
44
- readonly value: Signal<Partial<T>>;
45
- readonly dirty: Signal<boolean>;
46
- readonly touched: Signal<boolean>;
47
- readonly localErrors: Signal<readonly FormValidatorError[]>;
48
- readonly childrenErrors: Signal<FormValidatorError[]>;
49
- readonly errors: Signal<FormValidatorError[]>;
50
- readonly errorDebug: Signal<({
51
- _self: readonly FormValidatorError[];
52
- } & { [K in import("../types.js").Cast<keyof C, PropertyKey>]: import("../types.js").Fallback<Extract<readonly [keyof C, any], readonly [K, any]>[1], any>; }) | null>;
53
- constructor(options: FormGroupOptions<T, C>);
54
- setParent(parent: AbstractControlParent, force?: boolean): void;
55
- setParent(parent: null): void;
56
- getChildPath(child: AbstractControl): Signal<JsonPath>;
57
- reset(): void;
58
- get<K extends keyof C>(key: K): C[K];
59
- getValue<K extends keyof C>(key: K): FormValue<C[K]>;
60
- getRawValue<K extends keyof C>(key: K): RawFormValue<C[K]>;
61
- patchValue(values: Partial<T>): void;
62
- setValue(values: Partial<T>): void;
63
- markAsDirty({ onlySelf }?: MarkOptions): void;
64
- markAsTouched({ onlySelf }?: MarkOptions): void;
65
- [Symbol.iterator](): Iterator<[keyof C, C[keyof C]]>;
66
- private updateParents;
67
- }
68
- export declare function formGroup<C extends FromGroupControls<Record> = FromGroupControls<Record>>(options: FormGroupOptions<FormGroupRawValueType<C>, C>): FormGroup<FormGroupRawValueType<C>, C>;
69
- export declare function isFormGroup(value: any): value is FormGroup;
70
- export {};