@mmstack/form-core 19.0.1 → 19.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -10
- package/fesm2022/mmstack-form-core.mjs +15 -10
- package/fesm2022/mmstack-form-core.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -65,6 +65,11 @@
|
|
|
65
65
|
## Slightly more complex example
|
|
66
66
|
|
|
67
67
|
```typescript
|
|
68
|
+
import { Component, computed, inject, Injectable, isDevMode, linkedSignal, Signal, signal, untracked } from '@angular/core';
|
|
69
|
+
import { FormsModule } from '@angular/forms';
|
|
70
|
+
import { derived, formControl, FormControlSignal, formGroup, FormGroupSignal } from '@mmstack/form-core';
|
|
71
|
+
import { mutationResource, queryResource } from '@mmstack/resource';
|
|
72
|
+
|
|
68
73
|
type Post = {
|
|
69
74
|
id: number;
|
|
70
75
|
title?: string;
|
|
@@ -123,14 +128,15 @@ export class PostsService {
|
|
|
123
128
|
createPost(post: Post) {
|
|
124
129
|
this.createPostResource.mutate({
|
|
125
130
|
body: post,
|
|
126
|
-
});
|
|
131
|
+
}); // send the request
|
|
127
132
|
}
|
|
128
133
|
|
|
129
134
|
updatePost(id: number, post: Partial<Post>) {
|
|
130
135
|
this.createPostResource.mutate({
|
|
131
136
|
body: { id, ...post },
|
|
137
|
+
url: `${this.endpoint}/${id}`,
|
|
132
138
|
method: 'PATCH',
|
|
133
|
-
});
|
|
139
|
+
}); // send the request
|
|
134
140
|
}
|
|
135
141
|
}
|
|
136
142
|
|
|
@@ -163,26 +169,33 @@ function createPostState(post: Post, loading: Signal<boolean>): PostState {
|
|
|
163
169
|
}
|
|
164
170
|
|
|
165
171
|
@Component({
|
|
166
|
-
selector: 'app-
|
|
172
|
+
selector: 'app-post-form',
|
|
167
173
|
imports: [FormsModule],
|
|
168
174
|
template: `
|
|
169
|
-
<label
|
|
170
|
-
|
|
175
|
+
<label
|
|
176
|
+
>{{ formState().children().title.label() }}
|
|
177
|
+
<input [(ngModel)]="formState().children().title.value" [readonly]="formState().children().body.readonly()" [class.error]="formState().children().title.touched() && formState().children().title.error()" />
|
|
178
|
+
</label>
|
|
179
|
+
<br />
|
|
180
|
+
|
|
181
|
+
<label
|
|
182
|
+
>{{ formState().children().body.label() }}
|
|
183
|
+
<textarea [(ngModel)]="formState().children().body.value" [readonly]="formState().children().body.readonly()" [class.error]="formState().children().body.touched() && formState().children().body.error()"></textarea>
|
|
184
|
+
</label>
|
|
171
185
|
|
|
172
|
-
<
|
|
173
|
-
<textarea [(ngModel)]="formState().children().body.value" [class.error]="formState().children().body.touched() && formState().children().body.error()"></textarea>
|
|
186
|
+
<br />
|
|
174
187
|
|
|
175
188
|
<button (click)="submit()" [disabled]="svc.loading()">Submit</button>
|
|
176
189
|
`,
|
|
177
190
|
})
|
|
178
|
-
export class
|
|
191
|
+
export class PostFormComponent {
|
|
179
192
|
protected readonly svc = inject(PostsService);
|
|
180
193
|
|
|
181
194
|
protected readonly formState = linkedSignal<Post, PostState>({
|
|
182
195
|
source: () => this.svc.post.value() ?? { title: '', body: '', id: -1, userId: -1 },
|
|
183
196
|
computation: (source, prev) => {
|
|
184
197
|
if (prev) {
|
|
185
|
-
prev.value.
|
|
198
|
+
prev.value.forceReconcile(source);
|
|
186
199
|
return prev.value;
|
|
187
200
|
}
|
|
188
201
|
|
|
@@ -196,7 +209,7 @@ export class AppComponent {
|
|
|
196
209
|
if (untracked(state.error)) return state.markAllAsTouched();
|
|
197
210
|
const value = untracked(state.value);
|
|
198
211
|
if (value.id === -1) this.svc.createPost(value);
|
|
199
|
-
else this.svc.updatePost(value.id, untracked(state.partialValue));
|
|
212
|
+
else this.svc.updatePost(value.id, untracked(state.partialValue));
|
|
200
213
|
}
|
|
201
214
|
}
|
|
202
215
|
```
|
|
@@ -124,7 +124,7 @@ function formControl(initial, opt) {
|
|
|
124
124
|
const markAsPristine = () => touched.set(false);
|
|
125
125
|
const markAllAsPristine = markAsPristine;
|
|
126
126
|
const label = computed(() => opt?.label?.() ?? '');
|
|
127
|
-
const
|
|
127
|
+
const partialValue = computed(() => (dirty() ? value() : undefined));
|
|
128
128
|
const internalReconcile = (newValue, force = false) => {
|
|
129
129
|
const isDirty = untracked(dirty);
|
|
130
130
|
if (!isDirty || force) {
|
|
@@ -166,7 +166,7 @@ function formControl(initial, opt) {
|
|
|
166
166
|
equal: eq,
|
|
167
167
|
[CONTROL_SYMBOL]: true,
|
|
168
168
|
controlType: (opt?.controlType ?? 'control'),
|
|
169
|
-
partialValue:
|
|
169
|
+
partialValue: partialValue,
|
|
170
170
|
};
|
|
171
171
|
}
|
|
172
172
|
|
|
@@ -247,11 +247,15 @@ function formArray(initial, factory, opt) {
|
|
|
247
247
|
});
|
|
248
248
|
const ownError = computed(() => validator()(ctrl.value()));
|
|
249
249
|
const error = computed(() => {
|
|
250
|
-
|
|
251
|
-
|
|
250
|
+
const own = ownError();
|
|
251
|
+
if (own)
|
|
252
|
+
return own;
|
|
252
253
|
if (!children().length)
|
|
253
254
|
return '';
|
|
254
|
-
return children()
|
|
255
|
+
return children()
|
|
256
|
+
.map((c, idx) => (c.error() ? `${idx}: ${c.error()}` : ''))
|
|
257
|
+
.filter(Boolean)
|
|
258
|
+
.join('\n');
|
|
255
259
|
});
|
|
256
260
|
const dirty = computed(() => {
|
|
257
261
|
if (ctrl.dirty())
|
|
@@ -427,12 +431,12 @@ function formGroup(initial, providedChildren, opt) {
|
|
|
427
431
|
const childrenTouched = computed(() => !!derivationsArray().length &&
|
|
428
432
|
derivationsArray().some((d) => d.touched()));
|
|
429
433
|
const touched = computed(() => ctrl.touched() || childrenTouched());
|
|
430
|
-
const dirty = computed(() => ctrl.dirty() || childrenDirty());
|
|
431
434
|
const childError = computed(() => {
|
|
432
435
|
if (!derivationsArray().length)
|
|
433
436
|
return '';
|
|
434
437
|
return derivationsArray()
|
|
435
|
-
.map((d) => d.error())
|
|
438
|
+
.map((d) => (d.error() ? `${d.label()}: ${d.error()}` : ''))
|
|
439
|
+
.filter(Boolean)
|
|
436
440
|
.join('\n');
|
|
437
441
|
});
|
|
438
442
|
const error = computed(() => {
|
|
@@ -477,8 +481,10 @@ function formGroup(initial, providedChildren, opt) {
|
|
|
477
481
|
? computed(() => createBaseValueFn(ctrl.value()))
|
|
478
482
|
: computed(() => ({}));
|
|
479
483
|
const partialValue = computed(() => {
|
|
480
|
-
const obj =
|
|
481
|
-
|
|
484
|
+
const obj = {
|
|
485
|
+
...basePartialValue(),
|
|
486
|
+
};
|
|
487
|
+
if (!ctrl.dirty())
|
|
482
488
|
return obj;
|
|
483
489
|
for (const [key, ctrl] of entries(children())) {
|
|
484
490
|
const pv = ctrl.partialValue();
|
|
@@ -496,7 +502,6 @@ function formGroup(initial, providedChildren, opt) {
|
|
|
496
502
|
forceReconcile,
|
|
497
503
|
ownError: ctrl.error,
|
|
498
504
|
touched,
|
|
499
|
-
dirty,
|
|
500
505
|
error,
|
|
501
506
|
markAllAsPristine,
|
|
502
507
|
markAllAsTouched,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mmstack-form-core.mjs","sources":["../../../../../packages/form/core/src/lib/derived.ts","../../../../../packages/form/core/src/lib/form-control.ts","../../../../../packages/form/core/src/lib/form-array.ts","../../../../../packages/form/core/src/lib/form-group.ts","../../../../../packages/form/core/src/mmstack-form-core.ts"],"sourcesContent":["import {\n computed,\n CreateSignalOptions,\n signal,\n untracked,\n type WritableSignal,\n} from '@angular/core';\nimport type { UnknownObject } from '@mmstack/object';\nimport { toWritable } from '@mmstack/primitives';\n\n/**\n * Options for creating a derived signal using the full `derived` function signature.\n * @typeParam T - The type of the source signal's value (parent).\n * @typeParam U - The type of the derived signal's value (child).\n */\ntype CreateDerivedOptions<T, U> = CreateSignalOptions<U> & {\n /**\n * A function that extracts the derived value (`U`) from the source signal's value (`T`).\n */\n from: (v: T) => U;\n /**\n * A function that updates the source signal's value (`T`) when the derived signal's value (`U`) changes.\n * This establishes the two-way binding.\n */\n onChange: (newValue: U) => void;\n};\n\n/**\n * A `WritableSignal` that derives its value from another `WritableSignal` (the \"source\" signal).\n * It provides two-way binding: changes to the source signal update the derived signal, and\n * changes to the derived signal update the source signal.\n *\n * @typeParam T - The type of the source signal's value (parent).\n * @typeParam U - The type of the derived signal's value (child).\n */\nexport type DerivedSignal<T, U> = WritableSignal<U> & {\n /**\n * The function used to derive the derived signal's value from the source signal's value.\n * This is primarily for internal use and introspection.\n */\n from: (v: T) => U;\n};\n\n/**\n * Creates a `DerivedSignal` that derives its value from another `WritableSignal` (the source signal).\n * This overload provides the most flexibility, allowing you to specify custom `from` and `onChange` functions.\n *\n * @typeParam T - The type of the source signal's value.\n * @typeParam U - The type of the derived signal's value.\n * @param source - The source `WritableSignal`.\n * @param options - An object containing the `from` and `onChange` functions, and optional signal options.\n * @returns A `DerivedSignal` instance.\n *\n * @example\n * const user = signal({ name: 'John', age: 30 });\n * const name = derived(user, {\n * from: (u) => u.name,\n * onChange: (newName) => user.update((u) => ({ ...u, name: newName })),\n * });\n */\nexport function derived<T, U>(\n source: WritableSignal<T>,\n opt: CreateDerivedOptions<T, U>,\n): DerivedSignal<T, U>;\n\n/**\n * Creates a `DerivedSignal` that derives a property from an object held by the source signal.\n * This overload simplifies creating derived signals for object properties.\n *\n * @typeParam T - The type of the source signal's value (must be an object).\n * @typeParam TKey - The key of the property to derive.\n * @param source - The source `WritableSignal` (holding an object).\n * @param key - The key of the property to derive.\n * @param options - Optional signal options for the derived signal.\n * @returns A `DerivedSignal` instance.\n *\n * @example\n * const user = signal({ name: 'John', age: 30 });\n * const name = derived(user, 'name');\n */\nexport function derived<T extends UnknownObject, TKey extends keyof T>(\n source: WritableSignal<T>,\n key: TKey,\n opt?: CreateSignalOptions<T[TKey]>,\n): DerivedSignal<T, T[TKey]>;\n\n/**\n * Creates a `DerivedSignal` from an array, and derives an element by index.\n *\n * @typeParam T - The type of the source signal's value (must be an array).\n * @param source - The source `WritableSignal` (holding an array).\n * @param index - The index of the element to derive.\n * @param options - Optional signal options for the derived signal.\n * @returns A `DerivedSignal` instance.\n *\n * @example\n * const numbers = signal([1, 2, 3]);\n * const secondNumber = derived(numbers, 1); // secondNumber() === 2\n * secondNumber.set(5); // numbers() === [1, 5, 3]\n */\nexport function derived<T extends any[]>(\n source: WritableSignal<T>,\n index: number,\n opt?: CreateSignalOptions<T[number]>,\n): DerivedSignal<T, T[number]>;\n\nexport function derived<T, U>(\n source: WritableSignal<T>,\n optOrKey: CreateDerivedOptions<T, U> | keyof T,\n opt?: CreateSignalOptions<U>,\n): DerivedSignal<T, U> {\n const from =\n typeof optOrKey === 'object' ? optOrKey.from : (v: T) => v[optOrKey] as U;\n const onChange =\n typeof optOrKey === 'object'\n ? optOrKey.onChange\n : (next: U) => {\n source.update((cur) => ({ ...cur, [optOrKey]: next }));\n };\n\n const rest = typeof optOrKey === 'object' ? optOrKey : opt;\n\n const sig = toWritable<U>(\n computed(() => from(source()), rest),\n (newVal) => onChange(newVal),\n ) as DerivedSignal<T, U>;\n\n sig.from = from;\n\n return sig;\n}\n\n/**\n * Creates a \"fake\" `DerivedSignal` from a simple value. This is useful for creating\n * `FormControlSignal` instances that are not directly derived from another signal.\n * The returned signal's `from` function will always return the initial value.\n *\n * @typeParam T - This type parameter is not used in the implementation but is kept for type compatibility with `DerivedSignal`.\n * @typeParam U - The type of the signal's value.\n * @param initial - The initial value of the signal.\n * @returns A `DerivedSignal` instance.\n * @internal\n */\nexport function toFakeDerivation<T, U>(initial: U): DerivedSignal<T, U> {\n const sig = signal(initial) as DerivedSignal<T, U>;\n sig.from = () => initial;\n\n return sig;\n}\n\n/**\n * Creates a \"fake\" `DerivedSignal` from an existing `WritableSignal`. This is useful\n * for treating a regular `WritableSignal` as a `DerivedSignal` without changing its behavior.\n * The returned signal's `from` function returns the current value of signal, using `untracked`.\n *\n * @typeParam T - This type parameter is not used in the implementation but is kept for type compatibility with `DerivedSignal`.\n * @typeParam U - The type of the signal's value.\n * @param initial - The existing `WritableSignal`.\n * @returns A `DerivedSignal` instance.\n * @internal\n */\nexport function toFakeSignalDerivation<T, U>(\n initial: WritableSignal<U>,\n): DerivedSignal<T, U> {\n const sig = initial as DerivedSignal<T, U>;\n sig.from = () => untracked(initial);\n return sig;\n}\n\n/**\n * Type guard function to check if a given `WritableSignal` is a `DerivedSignal`.\n *\n * @typeParam T - The type of the source signal's value (optional, defaults to `any`).\n * @typeParam U - The type of the derived signal's value (optional, defaults to `any`).\n * @param sig - The `WritableSignal` to check.\n * @returns `true` if the signal is a `DerivedSignal`, `false` otherwise.\n */\nexport function isDerivation<T, U>(\n sig: WritableSignal<U>,\n): sig is DerivedSignal<T, U> {\n return 'from' in sig;\n}\n","import {\n computed,\n isSignal,\n signal,\n untracked,\n type CreateSignalOptions,\n type Signal,\n type ValueEqualityFn,\n type WritableSignal,\n} from '@angular/core';\nimport { v7 } from 'uuid';\nimport { type DerivedSignal } from './derived';\n\n/**\n * A symbol used to identify `FormControlSignal` instances. This is for internal type checking.\n * @internal\n */\nexport const CONTROL_SYMBOL = Symbol.for('INTERNAL_CLIENT_FORM_CONTROL');\n\n/**\n * Represents the type of a form control.\n * - `control`: A single form control (e.g., an input field).\n * - `array`: An array of form controls (like Angular's `FormArray`).\n * - `group`: A group of form controls (like Angular's `FormGroup`).\n */\nexport type ControlType = 'control' | 'array' | 'group';\n\n/**\n * Represents a reactive form control. It holds the value, validation status, and other\n * metadata for a form field. This is the core building block for creating reactive forms\n * with signals.\n *\n * @typeParam T - The type of the form control's value.\n * @typeParam TParent - The type of the parent form control's value (if this control is part of a group or array). Defaults to `undefined`.\n * @typeParam TControlType - The type of the control ('control', 'array', or 'group'). Defaults to 'control'.\n * @typeParam TPartialValue - The type of the partial value, used for patching.\n */\nexport type FormControlSignal<\n T,\n TParent = undefined,\n TControlType extends ControlType = 'control',\n TPartialValue = T | undefined,\n> = {\n /** A unique identifier for the control. Used for tracking in `@for` loops. */\n id: string;\n /** The main value signal for the control. */\n value: WritableSignal<T>;\n /** A signal indicating whether the control's value has been changed. */\n dirty: Signal<boolean>;\n /** A signal indicating whether the control has been interacted with (e.g., blurred). */\n touched: Signal<boolean>;\n /** A signal containing the current validation error message (empty string if valid). */\n error: Signal<string>;\n /** A signal indicating whether the control is disabled. */\n disabled: Signal<boolean>;\n /** A signal indicating whether the control is read-only. */\n readonly: Signal<boolean>;\n /** A signal indicating whether the control is required. */\n required: Signal<boolean>;\n /** A signal containing the label for the control. */\n label: Signal<string>;\n /** A signal containing the hint text for the control. */\n hint: Signal<string>;\n /** Marks the control as touched. */\n markAsTouched: () => void;\n /** Marks the control and all its child controls (if any) as touched. */\n markAllAsTouched: () => void;\n /** Marks the control as pristine (not touched). */\n markAsPristine: () => void;\n /** Marks the control and all its child controls (if any) as pristine. */\n markAllAsPristine: () => void;\n /**\n * Resets the control to a new value and sets a new initial value. This is intended for\n * scenarios where the underlying data is updated externally (e.g., data coming from\n * the server). If the control is not dirty, the value is updated. If the control *is*\n * dirty, the value is *not* updated (preserving user changes).\n */\n reconcile: (newValue: T) => void;\n /**\n * Similar to `reconcile`, but forces the update even if the control is dirty.\n */\n forceReconcile: (newValue: T) => void;\n /** Resets the control's value to its initial value. */\n reset: () => void;\n /** Resets the control's value and initial value. */\n resetWithInitial: (initial: T) => void;\n /**\n * The derivation function used to create this control if it's part of a `formGroup` or `formArray`.\n * @internal\n */\n from?: DerivedSignal<TParent, T>['from'];\n /** The equality function used to compare values. Defaults to `Object.is`. */\n equal: (a: T, b: T) => boolean;\n /** @internal A symbol used for internal type checking.*/\n [CONTROL_SYMBOL]: true;\n /** The type of the control ('control', 'array', or 'group'). */\n controlType: TControlType;\n /**\n * A signal representing the partial value of the control, suitable for patching data on a server.\n * It contains the changed value if `dirty` is `true`.\n */\n partialValue: Signal<TPartialValue>;\n};\n\nexport type CreateFormControlOptions<\n T,\n TControlType extends ControlType = ControlType,\n> = CreateSignalOptions<T> & {\n validator?: () => (value: T) => string;\n onTouched?: () => void;\n disable?: () => boolean;\n readonly?: () => boolean;\n required?: () => boolean;\n label?: () => string;\n id?: () => string;\n hint?: () => string;\n dirtyEquality?: ValueEqualityFn<T>;\n onReset?: () => void;\n controlType?: TControlType;\n overrideValidation?: () => string;\n};\n\n/**\n * Creates a `FormControlSignal`, a reactive form control that holds a value and tracks its\n * validity, dirty state, touched state, and other metadata.\n *\n * @typeParam T - The type of the form control's value.\n * @typeParam TParent - The type of the parent form control's value (if this control is part of a group or array).\n * @typeParam TControlType - The type of the control. Defaults to `'control'`.\n * @typeParam TPartialValue - The type of value when patching\n * @param initial - The initial value of the control, or a `DerivedSignal` if this control is part of a `formGroup` or `formArray`.\n * @param options - Optional configuration options for the control.\n * @returns A `FormControlSignal` instance.\n *\n * @example\n * // Create a simple form control:\n * const name = formControl('Initial Name');\n *\n * // Create a form control with validation:\n * const age = formControl(0, {\n * validator: () => (value) => value >= 18 ? '' : 'Must be at least 18',\n * });\n *\n * // Create a derived form control (equivalent to the above, but more explicit):\n * const user = signal({ name: 'John Doe', age: 30 });\n * const name = formControl(derived(user, {\n * from: (u) => u.name,\n * onChange: (newName) => user.update(u => ({...u, name: newName}))\n * }));\n *\n * // Create a form group with nested controls:\n * const user = signal({ name: 'John Doe', age: 30 });\n * const form = formGroup(user, {\n * name: formControl(derived(user, 'name')),\n * age: formControl(derived(user, 'age')),\n * })\n */\nexport function formControl<\n T,\n TParent = undefined,\n TControlType extends ControlType = 'control',\n TPartialValue = T | undefined,\n>(\n initial: DerivedSignal<TParent, T> | T,\n opt?: CreateFormControlOptions<T, TControlType>,\n): FormControlSignal<T, TParent, TControlType, TPartialValue> {\n const value = isSignal(initial) ? initial : signal(initial, opt);\n const initialValue = signal(untracked(value));\n const eq = opt?.equal ?? Object.is;\n\n const dirtyEq = opt?.dirtyEquality ?? eq;\n\n const disabled = computed(() => opt?.disable?.() ?? false);\n const readonly = computed(() => opt?.readonly?.() ?? false);\n\n const dirty = computed(() => !dirtyEq(value(), initialValue()));\n\n const touched = signal(false);\n\n const validator = computed(() => opt?.validator?.() ?? (() => ''));\n\n const error = computed(() => {\n if (opt?.overrideValidation) return opt.overrideValidation();\n if (disabled() || readonly()) return '';\n return validator()(value());\n });\n\n const markAsTouched = () => {\n touched.set(true);\n opt?.onTouched?.();\n };\n const markAllAsTouched = markAsTouched;\n\n const markAsPristine = () => touched.set(false);\n const markAllAsPristine = markAsPristine;\n\n const label = computed(() => opt?.label?.() ?? '');\n\n const patchValue = computed(() => (dirty() ? value() : undefined));\n\n const internalReconcile = (newValue: T, force = false) => {\n const isDirty = untracked(dirty);\n\n if (!isDirty || force) {\n // very dangerous use of untracked here, don't do this everywhere :)\n // thanks to u/synalx for the idea to use untracked here\n untracked(() => {\n initialValue.set(newValue);\n value.set(newValue);\n });\n }\n };\n\n return {\n id: opt?.id?.() ?? v7(),\n value,\n dirty,\n touched,\n error,\n label,\n required: computed(() => opt?.required?.() ?? false),\n disabled,\n readonly,\n hint: computed(() => opt?.hint?.() ?? ''),\n markAsTouched,\n markAllAsTouched,\n markAsPristine,\n markAllAsPristine,\n from: (isSignal(initial) ? initial.from : undefined) as FormControlSignal<\n T,\n TParent,\n TControlType\n >['from'],\n reconcile: (newValue: T) => internalReconcile(newValue),\n forceReconcile: (newValue: T) => internalReconcile(newValue, true),\n reset: () => {\n opt?.onReset?.();\n value.set(untracked(initialValue));\n },\n resetWithInitial: (initial: T) => {\n opt?.onReset?.();\n initialValue.set(initial);\n value.set(initial);\n },\n equal: eq,\n [CONTROL_SYMBOL]: true,\n controlType: (opt?.controlType ?? 'control') as TControlType,\n partialValue: patchValue as Signal<TPartialValue>,\n };\n}\n","import {\n computed,\n linkedSignal,\n untracked,\n type Signal,\n type WritableSignal,\n} from '@angular/core';\nimport { derived, type DerivedSignal } from './derived';\nimport {\n formControl,\n type CreateFormControlOptions,\n type FormControlSignal,\n} from './form-control';\nimport { type SignalValue } from './signal-value.type';\n\nfunction minArrayLengthMsg(min: number, elementLabel: string) {\n return `Min ${min} ${elementLabel}`;\n}\n\nfunction maxArrayLengthMsg(max: number, elementLabel: string) {\n return `Max ${max} ${elementLabel}`;\n}\n\nfunction minArrayLengthValidator(min: number, elementLabel: string) {\n const msg = minArrayLengthMsg(min, elementLabel);\n return (val: any[]) => (val.length >= min ? '' : msg);\n}\n\nfunction maxArrayLengthValidator(max: number, elementLabel: string) {\n const msg = maxArrayLengthMsg(max, elementLabel);\n return (val: any[]) => (val.length <= max ? '' : msg);\n}\n\nexport type ArrayValidatorOpt = {\n min?: number;\n max?: number;\n elementLabel?: string;\n};\n\nexport function arrayValidator<T extends any[]>(opt: ArrayValidatorOpt = {}) {\n const min = opt.min ?? 0;\n const max = opt.max ?? Number.MAX_SAFE_INTEGER;\n const elementLabel = opt.elementLabel ?? 'items';\n\n const minVal = minArrayLengthValidator(min, elementLabel);\n const maxVal = maxArrayLengthValidator(max, elementLabel);\n\n return (val: T) => minVal(val) || maxVal(val);\n}\n\nexport type FormArraySignal<\n T,\n TIndividualState extends FormControlSignal<\n T,\n any,\n any,\n any\n > = FormControlSignal<T, any, any, any>,\n TParent = undefined,\n> = FormControlSignal<\n T[],\n TParent,\n 'array',\n | Exclude<SignalValue<TIndividualState['partialValue']>, null | undefined>[]\n | undefined\n> & {\n ownError: Signal<string>;\n children: Signal<TIndividualState[]>;\n push: (value: T) => void; // add new control with value\n remove: (index: number) => void; // remove at index\n min: Signal<number>; // for display purposes\n max: Signal<number>; // for display purposes\n canAdd: Signal<boolean>; // disable add button if false\n canRemove: Signal<boolean>; // disable remove buttons if false\n};\n\nexport type CreateFormArraySignalOptions<\n T,\n TIndividualState extends FormControlSignal<T, any, any, any>,\n> = CreateFormControlOptions<T> & {\n min?: () => number;\n max?: () => number;\n elementLabel?: () => string;\n toPartialValue?: (\n v: T,\n ) => Exclude<SignalValue<TIndividualState['partialValue']>, null | undefined>;\n};\n\nfunction createReconcileChildren<\n T,\n TIndividualState extends FormControlSignal<T, any, any, any>,\n>(\n factory: (\n val: DerivedSignal<T[], T>,\n idx: number,\n opt?: CreateFormControlOptions<T>,\n ) => TIndividualState,\n opt?: CreateFormControlOptions<T>,\n) {\n return (\n length: number,\n source: WritableSignal<T[]>,\n prev?: TIndividualState[],\n ): TIndividualState[] => {\n if (!prev) {\n const nextControls = [];\n\n for (let i = 0; i < length; i++) {\n nextControls.push(\n factory(derived(source, i, { equal: opt?.equal }), i, opt),\n );\n }\n\n return nextControls;\n }\n\n const next = [...prev];\n\n if (length < prev.length) {\n next.splice(length);\n } else if (length > prev.length) {\n for (let i = prev.length; i < length; i++) {\n next.push(factory(derived(source, i, { equal: opt?.equal }), i, opt));\n }\n }\n\n return next;\n };\n}\n\nexport function formArray<\n T,\n TIndividualState extends FormControlSignal<\n T,\n any,\n any,\n any\n > = FormControlSignal<T, any, any, any>,\n TParent = undefined,\n>(\n initial: T[] | DerivedSignal<TParent, T[]>,\n factory: (\n val: DerivedSignal<T[], T>,\n idx: number,\n opt?: CreateFormControlOptions<T>,\n ) => TIndividualState,\n opt?: CreateFormArraySignalOptions<T, TIndividualState>,\n): FormArraySignal<T, TIndividualState, TParent> {\n const eq = opt?.equal ?? Object.is;\n\n const arrayEqual = (a: T[], b: T[]) => {\n if (a.length !== b.length) return false;\n if (!a.length) return true;\n\n return a.every((v, i) => eq(v, b[i]));\n };\n\n const min = computed(() => opt?.min?.() ?? 0);\n const max = computed(() => opt?.max?.() ?? Number.MAX_SAFE_INTEGER);\n const elementLabel = computed(() => opt?.elementLabel?.() ?? 'items');\n\n const validator = () =>\n arrayValidator<T[]>({\n min: min(),\n max: max(),\n elementLabel: elementLabel(),\n });\n\n const arrayOptions: CreateFormControlOptions<T[], 'array'> = {\n ...opt,\n equal: arrayEqual,\n validator,\n dirtyEquality: (a, b) => a.length === b.length,\n controlType: 'array',\n };\n\n const ctrl = formControl<T[], TParent, 'array'>(\n initial,\n arrayOptions,\n ) satisfies FormControlSignal<T[], TParent, 'array'>;\n\n const length = computed(() => ctrl.value().length);\n\n const reconcileChildren = createReconcileChildren<T, TIndividualState>(\n factory,\n opt,\n );\n\n // linkedSignal used to re-use previous value so that only length changes are affected and existing controls are kept, but updated\n const children = linkedSignal<number, TIndividualState[]>({\n source: () => length(),\n computation: (len, prev) => reconcileChildren(len, ctrl.value, prev?.value),\n });\n\n const ownError = computed(() => validator()(ctrl.value()));\n\n const error = computed((): string => {\n if (ownError()) return ownError();\n if (!children().length) return '';\n return children().some((c) => c.error()) ? 'INVALID' : '';\n });\n\n const dirty = computed(() => {\n if (ctrl.dirty()) return true;\n if (!children().length) return false;\n return children().some((c) => c.dirty());\n });\n\n const markAllAsTouched = () => {\n ctrl.markAllAsTouched();\n for (const c of untracked(children)) {\n c.markAllAsTouched();\n }\n };\n const markAllAsPristine = () => {\n ctrl.markAllAsPristine();\n for (const c of untracked(children)) {\n c.markAllAsPristine();\n }\n };\n\n const toPartialValue = opt?.toPartialValue ?? ((v: T) => v);\n const partialValue = computed(() => {\n if (!dirty()) return undefined;\n return children().map((c) => {\n const pv = c.partialValue();\n if (pv) return pv;\n if (c.controlType === 'control') return undefined;\n\n // return full value for child objects/arrays as this cannot be partially patched without idx\n return toPartialValue(c.value());\n });\n });\n\n const touched = computed(\n () =>\n ctrl.touched() ||\n !!(children().length && children().some((c) => c.touched())),\n );\n\n const reconcile = (newValue: T[]) => {\n const ctrls = untracked(children);\n\n for (let i = 0; i < newValue.length; i++) {\n ctrls.at(i)?.reconcile(newValue[i]); // reconcile existing controls that are relevant addition/removal will be handled after ctrl.reconcile through linkedSignal\n }\n\n ctrl.reconcile(newValue);\n };\n\n const forceReconcile = (newValue: T[]) => {\n const ctrls = untracked(children);\n\n for (let i = 0; i < newValue.length; i++) {\n ctrls.at(i)?.forceReconcile(newValue[i]);\n }\n\n ctrl.forceReconcile(newValue);\n };\n\n return {\n ...ctrl,\n ownError,\n error,\n touched,\n children,\n dirty,\n markAllAsTouched,\n markAllAsPristine,\n min,\n max,\n partialValue,\n canAdd: computed(\n () => !ctrl.disabled() && !ctrl.readonly() && length() < max(),\n ),\n canRemove: computed(\n () => !ctrl.disabled() && !ctrl.readonly() && length() > min(),\n ),\n reconcile,\n forceReconcile,\n reset: () => {\n for (const c of untracked(children)) {\n c.reset();\n }\n ctrl.reset();\n },\n resetWithInitial: (initial: T[]) => {\n const ctrls = untracked(children);\n for (let i = 0; i < initial.length; i++) {\n ctrls.at(i)?.resetWithInitial(initial[i]);\n }\n ctrl.resetWithInitial(initial);\n },\n push: (next) => ctrl.value.update((cur) => [...cur, next]),\n remove: (idx) =>\n ctrl.value.update((cur) => cur.filter((_, i) => i !== idx)),\n };\n}\n","import {\n computed,\n isSignal,\n signal,\n untracked,\n type Signal,\n type WritableSignal,\n} from '@angular/core';\nimport { entries, values } from '@mmstack/object';\nimport {\n isDerivation,\n toFakeSignalDerivation,\n type DerivedSignal,\n} from './derived';\nimport {\n formControl,\n type CreateFormControlOptions,\n type FormControlSignal,\n} from './form-control';\nimport { type SignalValue } from './signal-value.type';\n\n/**\n * Extracts the partial value types from a record of `FormControlSignal` instances.\n * This is used to construct the `partialValue` type for `FormGroupSignal`.\n * @internal\n */\ntype DerivationPartialValues<\n TDerivations extends Record<string, FormControlSignal<any, any, any, any>>,\n> = {\n [K in keyof TDerivations]: Exclude<\n SignalValue<TDerivations[K]['partialValue']>,\n undefined\n >;\n};\n\n/**\n * Represents a group of form controls, similar to Angular's `FormGroup`. It aggregates\n * the values and states of its child controls into a single object.\n *\n * @typeParam T - The type of the form group's value (an object).\n * @typeParam TDerivations - A record where keys are the names of the child controls and values are the `FormControlSignal` instances.\n * @typeParam TParent - The type of the parent form control's value (if this group is nested).\n */\nexport type FormGroupSignal<\n T,\n TDerivations extends Record<string, FormControlSignal<any, T, any, any>>,\n TParent = undefined,\n> = FormControlSignal<\n T,\n TParent,\n 'group',\n Partial<DerivationPartialValues<TDerivations>>\n> & {\n /**\n * A signal that holds a record of the child form controls. The keys are the names\n * of the controls, and the values are the `FormControlSignal` instances.\n */\n children: Signal<TDerivations>;\n /**\n * A signal that holds the validation error message of the group itself (excluding child errors).\n */\n ownError: Signal<string>;\n};\n\n/**\n * Options for creating a `FormGroupSignal`. Extends `CreateFormControlOptions`.\n */\nexport type CreateFormGroupOptions<\n T,\n TDerivations extends Record<string, FormControlSignal<any, T, any, any>>,\n> = CreateFormControlOptions<T, 'group'> & {\n /**\n * An optional function to create a base object for the `partialValue` signal.\n * This can be used to pre-populate the partial value with default values or\n * to perform custom logic before merging in the partial values from child controls.\n */\n createBasePartialValue?: (\n value: T,\n ) => Partial<DerivationPartialValues<TDerivations>>;\n};\n\n/**\n * Creates a `FormGroupSignal`, which aggregates a set of child form controls into a single object.\n *\n * @typeParam T - The type of the form group's value (an object).\n * @typeParam TDerivations - A record where keys are the names of the child controls and values are the `FormControlSignal` instances.\n * @typeParam TParent - The type of the parent form control's value (if this group is nested within another group or array).\n * @param initial - The initial value of the form group (or a `WritableSignal` or `DerivedSignal` if the group is nested).\n * @param providedChildren - An object containing the child `FormControlSignal` instances, or a function that returns such an object.\n * Using a function allows for dynamic creation of child controls (e.g., in response to changes in other signals).\n * @param options - Optional configuration options for the form group.\n * @returns A `FormGroupSignal` instance.\n *\n * @example\n * // Create a simple form group:\n * const user = signal({ name: 'John Doe', age: 30 });\n * const form = formGroup(user, {\n * name: formControl(derived(user, 'name')),\n * age: formControl(derived(user, 'age')),\n * })\n *\n * // Create a nested form group:\n * const user = signal({ name: 'John', age: 30, address: {street: \"Some street\"} });\n *\n * const address = derived(user, 'address');\n * const userForm = formGroup(user, {\n * name: formControl(derived(user, 'name')),\n * age: formControl(derived(user, 'age')),\n * address: formGroup(address, {\n * street: formControl(derived(address, (address) => address.street), {\n * validator: () => (value) => value ? \"\" : \"required!\"\n * }) // you can create deeply nested structures.\n * })\n * });\n *\n * // Create a form group with dynamically created children replaced rare FormRecord requirements.\n * const showAddress = signal(false);\n * type Characteristic = {\n * valueType: 'string';\n * value: string;\n * } | {\n * valueType: 'number';\n * value: number;\n * }\n * const char = signal<Characteristic>({ valueType: 'string', value: '' });\n * const charForm = formGroup(char, () => {\n * if (char().valueType === 'string) return createStringControl(char);\n * return createNumberControl(char);\n * });\n *\n */\nexport function formGroup<\n T,\n TDerivations extends Record<string, FormControlSignal<any, T, any, any>>,\n TParent = undefined,\n>(\n initial: DerivedSignal<TParent, T> | T | WritableSignal<T>,\n providedChildren: (() => TDerivations) | TDerivations,\n opt?: CreateFormGroupOptions<T, TDerivations>,\n): FormGroupSignal<T, TDerivations, TParent> {\n const valueSignal = isSignal(initial) ? initial : signal(initial);\n // we fake a derivation if not present, so that .from is present on the signal\n const value = isDerivation<TParent, T>(valueSignal)\n ? valueSignal\n : toFakeSignalDerivation<TParent, T>(valueSignal);\n\n // we allow for a function/signal to be passed, this case should only be used if the child controls change dependent upon something, say if a formControl is flipped into a formGroup.\n const children =\n typeof providedChildren === 'function'\n ? computed(() => providedChildren())\n : computed(() => providedChildren);\n\n // array allows for easier handling\n const derivationsArray = computed(() => values(children()));\n\n const childrenDirty = computed(\n () =>\n !!derivationsArray().length && derivationsArray().some((d) => d.dirty()),\n );\n\n // by default dont compare object references, just use childrenDirtySignal\n const baseDirtyEq = opt?.dirtyEquality ?? opt?.equal ?? (() => true);\n\n // function which calls a signal becomes a signal\n const dirtyEquality = (a: T, b: T) => {\n return baseDirtyEq(a, b) && !childrenDirty();\n };\n\n // group control\n const ctrl = formControl<T, TParent, 'group'>(value, {\n ...opt,\n dirtyEquality,\n controlType: 'group',\n readonly: () => {\n // readonly if is readonly or all children are readonly\n if (opt?.readonly?.()) return true;\n return (\n !!derivationsArray().length &&\n derivationsArray().every((d) => d.readonly())\n );\n },\n disable: () => {\n if (opt?.disable?.()) return true;\n return (\n !!derivationsArray().length &&\n derivationsArray().some((d) => d.disabled())\n );\n },\n }) satisfies FormControlSignal<T, TParent, 'group'>;\n\n const childrenTouched = computed(\n () =>\n !!derivationsArray().length &&\n derivationsArray().some((d) => d.touched()),\n );\n\n const touched = computed(() => ctrl.touched() || childrenTouched());\n\n const dirty = computed(() => ctrl.dirty() || childrenDirty());\n\n const childError = computed(() => {\n if (!derivationsArray().length) return '';\n return derivationsArray()\n .map((d) => d.error())\n .join('\\n');\n });\n\n const error = computed(() => {\n const ownError = ctrl.error();\n if (ownError) return ownError;\n return childError() ? 'INVALID' : '';\n });\n\n const markAllAsTouched = () => {\n ctrl.markAllAsTouched();\n for (const ctrl of untracked(derivationsArray)) {\n ctrl.markAllAsTouched();\n }\n };\n\n const markAllAsPristine = () => {\n ctrl.markAllAsPristine();\n for (const ctrl of untracked(derivationsArray)) {\n ctrl.markAllAsPristine();\n }\n };\n\n const reconcile = (newValue: T) => {\n // set the children values based on the derivation of the new value\n for (const ctrl of untracked(derivationsArray)) {\n const from = ctrl.from;\n if (!from) continue;\n ctrl.reconcile(from(newValue));\n }\n ctrl.reconcile(newValue);\n };\n\n const forceReconcile = (newValue: T) => {\n for (const ctrl of untracked(derivationsArray)) {\n const from = ctrl.from;\n if (!from) continue;\n ctrl.forceReconcile(from(newValue));\n }\n ctrl.forceReconcile(newValue);\n };\n\n const createBaseValueFn = opt?.createBasePartialValue;\n\n const basePartialValue: Signal<\n Partial<DerivationPartialValues<TDerivations>>\n > = createBaseValueFn\n ? computed(() => createBaseValueFn(ctrl.value()))\n : computed(() => ({}));\n\n const partialValue = computed(() => {\n const obj: Partial<DerivationPartialValues<TDerivations>> =\n basePartialValue();\n if (!dirty()) return obj;\n\n for (const [key, ctrl] of entries(children())) {\n const pv = ctrl.partialValue();\n if (pv === undefined) continue;\n obj[key] = pv;\n }\n\n return obj;\n });\n\n return {\n ...ctrl,\n children,\n partialValue,\n reconcile,\n forceReconcile,\n ownError: ctrl.error,\n touched,\n dirty,\n error,\n markAllAsPristine,\n markAllAsTouched,\n reset: () => {\n for (const ctrl of untracked(derivationsArray)) {\n ctrl.reset();\n }\n ctrl.reset();\n },\n resetWithInitial: (initial: T) => {\n for (const ctrl of untracked(derivationsArray)) {\n const from = ctrl.from;\n from ? ctrl.resetWithInitial(from(initial)) : ctrl.reset();\n }\n ctrl.resetWithInitial(initial);\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AAO,GAAG;AACZ,KAAC,CAAC;IAEF,OAAO;AACL,QAAA,GAAG,IAAI;QACP,QAAQ;QACR,YAAY;QACZ,SAAS;QACT,cAAc;QACd,QAAQ,EAAE,IAAI,CAAC,KAAK;QACpB,OAAO;QACP,KAAK;QACL,KAAK;QACL,iBAAiB;QACjB,gBAAgB;QAChB,KAAK,EAAE,MAAK;YACV,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,gBAAgB,CAAC,EAAE;gBAC9C,IAAI,CAAC,KAAK,EAAE;;YAEd,IAAI,CAAC,KAAK,EAAE;SACb;AACD,QAAA,gBAAgB,EAAE,CAAC,OAAU,KAAI;YAC/B,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,gBAAgB,CAAC,EAAE;AAC9C,gBAAA,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI;AACtB,gBAAA,IAAI,GAAG,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,EAAE;;AAE5D,YAAA,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC;SAC/B;KACF;AACH;;ACtSA;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"mmstack-form-core.mjs","sources":["../../../../../packages/form/core/src/lib/derived.ts","../../../../../packages/form/core/src/lib/form-control.ts","../../../../../packages/form/core/src/lib/form-array.ts","../../../../../packages/form/core/src/lib/form-group.ts","../../../../../packages/form/core/src/mmstack-form-core.ts"],"sourcesContent":["import {\n computed,\n CreateSignalOptions,\n signal,\n untracked,\n type WritableSignal,\n} from '@angular/core';\nimport type { UnknownObject } from '@mmstack/object';\nimport { toWritable } from '@mmstack/primitives';\n\n/**\n * Options for creating a derived signal using the full `derived` function signature.\n * @typeParam T - The type of the source signal's value (parent).\n * @typeParam U - The type of the derived signal's value (child).\n */\ntype CreateDerivedOptions<T, U> = CreateSignalOptions<U> & {\n /**\n * A function that extracts the derived value (`U`) from the source signal's value (`T`).\n */\n from: (v: T) => U;\n /**\n * A function that updates the source signal's value (`T`) when the derived signal's value (`U`) changes.\n * This establishes the two-way binding.\n */\n onChange: (newValue: U) => void;\n};\n\n/**\n * A `WritableSignal` that derives its value from another `WritableSignal` (the \"source\" signal).\n * It provides two-way binding: changes to the source signal update the derived signal, and\n * changes to the derived signal update the source signal.\n *\n * @typeParam T - The type of the source signal's value (parent).\n * @typeParam U - The type of the derived signal's value (child).\n */\nexport type DerivedSignal<T, U> = WritableSignal<U> & {\n /**\n * The function used to derive the derived signal's value from the source signal's value.\n * This is primarily for internal use and introspection.\n */\n from: (v: T) => U;\n};\n\n/**\n * Creates a `DerivedSignal` that derives its value from another `WritableSignal` (the source signal).\n * This overload provides the most flexibility, allowing you to specify custom `from` and `onChange` functions.\n *\n * @typeParam T - The type of the source signal's value.\n * @typeParam U - The type of the derived signal's value.\n * @param source - The source `WritableSignal`.\n * @param options - An object containing the `from` and `onChange` functions, and optional signal options.\n * @returns A `DerivedSignal` instance.\n *\n * @example\n * const user = signal({ name: 'John', age: 30 });\n * const name = derived(user, {\n * from: (u) => u.name,\n * onChange: (newName) => user.update((u) => ({ ...u, name: newName })),\n * });\n */\nexport function derived<T, U>(\n source: WritableSignal<T>,\n opt: CreateDerivedOptions<T, U>,\n): DerivedSignal<T, U>;\n\n/**\n * Creates a `DerivedSignal` that derives a property from an object held by the source signal.\n * This overload simplifies creating derived signals for object properties.\n *\n * @typeParam T - The type of the source signal's value (must be an object).\n * @typeParam TKey - The key of the property to derive.\n * @param source - The source `WritableSignal` (holding an object).\n * @param key - The key of the property to derive.\n * @param options - Optional signal options for the derived signal.\n * @returns A `DerivedSignal` instance.\n *\n * @example\n * const user = signal({ name: 'John', age: 30 });\n * const name = derived(user, 'name');\n */\nexport function derived<T extends UnknownObject, TKey extends keyof T>(\n source: WritableSignal<T>,\n key: TKey,\n opt?: CreateSignalOptions<T[TKey]>,\n): DerivedSignal<T, T[TKey]>;\n\n/**\n * Creates a `DerivedSignal` from an array, and derives an element by index.\n *\n * @typeParam T - The type of the source signal's value (must be an array).\n * @param source - The source `WritableSignal` (holding an array).\n * @param index - The index of the element to derive.\n * @param options - Optional signal options for the derived signal.\n * @returns A `DerivedSignal` instance.\n *\n * @example\n * const numbers = signal([1, 2, 3]);\n * const secondNumber = derived(numbers, 1); // secondNumber() === 2\n * secondNumber.set(5); // numbers() === [1, 5, 3]\n */\nexport function derived<T extends any[]>(\n source: WritableSignal<T>,\n index: number,\n opt?: CreateSignalOptions<T[number]>,\n): DerivedSignal<T, T[number]>;\n\nexport function derived<T, U>(\n source: WritableSignal<T>,\n optOrKey: CreateDerivedOptions<T, U> | keyof T,\n opt?: CreateSignalOptions<U>,\n): DerivedSignal<T, U> {\n const from =\n typeof optOrKey === 'object' ? optOrKey.from : (v: T) => v[optOrKey] as U;\n const onChange =\n typeof optOrKey === 'object'\n ? optOrKey.onChange\n : (next: U) => {\n source.update((cur) => ({ ...cur, [optOrKey]: next }));\n };\n\n const rest = typeof optOrKey === 'object' ? optOrKey : opt;\n\n const sig = toWritable<U>(\n computed(() => from(source()), rest),\n (newVal) => onChange(newVal),\n ) as DerivedSignal<T, U>;\n\n sig.from = from;\n\n return sig;\n}\n\n/**\n * Creates a \"fake\" `DerivedSignal` from a simple value. This is useful for creating\n * `FormControlSignal` instances that are not directly derived from another signal.\n * The returned signal's `from` function will always return the initial value.\n *\n * @typeParam T - This type parameter is not used in the implementation but is kept for type compatibility with `DerivedSignal`.\n * @typeParam U - The type of the signal's value.\n * @param initial - The initial value of the signal.\n * @returns A `DerivedSignal` instance.\n * @internal\n */\nexport function toFakeDerivation<T, U>(initial: U): DerivedSignal<T, U> {\n const sig = signal(initial) as DerivedSignal<T, U>;\n sig.from = () => initial;\n\n return sig;\n}\n\n/**\n * Creates a \"fake\" `DerivedSignal` from an existing `WritableSignal`. This is useful\n * for treating a regular `WritableSignal` as a `DerivedSignal` without changing its behavior.\n * The returned signal's `from` function returns the current value of signal, using `untracked`.\n *\n * @typeParam T - This type parameter is not used in the implementation but is kept for type compatibility with `DerivedSignal`.\n * @typeParam U - The type of the signal's value.\n * @param initial - The existing `WritableSignal`.\n * @returns A `DerivedSignal` instance.\n * @internal\n */\nexport function toFakeSignalDerivation<T, U>(\n initial: WritableSignal<U>,\n): DerivedSignal<T, U> {\n const sig = initial as DerivedSignal<T, U>;\n sig.from = () => untracked(initial);\n return sig;\n}\n\n/**\n * Type guard function to check if a given `WritableSignal` is a `DerivedSignal`.\n *\n * @typeParam T - The type of the source signal's value (optional, defaults to `any`).\n * @typeParam U - The type of the derived signal's value (optional, defaults to `any`).\n * @param sig - The `WritableSignal` to check.\n * @returns `true` if the signal is a `DerivedSignal`, `false` otherwise.\n */\nexport function isDerivation<T, U>(\n sig: WritableSignal<U>,\n): sig is DerivedSignal<T, U> {\n return 'from' in sig;\n}\n","import {\n computed,\n isSignal,\n signal,\n untracked,\n type CreateSignalOptions,\n type Signal,\n type ValueEqualityFn,\n type WritableSignal,\n} from '@angular/core';\nimport { v7 } from 'uuid';\nimport { type DerivedSignal } from './derived';\n\n/**\n * A symbol used to identify `FormControlSignal` instances. This is for internal type checking.\n * @internal\n */\nexport const CONTROL_SYMBOL = Symbol.for('INTERNAL_CLIENT_FORM_CONTROL');\n\n/**\n * Represents the type of a form control.\n * - `control`: A single form control (e.g., an input field).\n * - `array`: An array of form controls (like Angular's `FormArray`).\n * - `group`: A group of form controls (like Angular's `FormGroup`).\n */\nexport type ControlType = 'control' | 'array' | 'group';\n\n/**\n * Represents a reactive form control. It holds the value, validation status, and other\n * metadata for a form field. This is the core building block for creating reactive forms\n * with signals.\n *\n * @typeParam T - The type of the form control's value.\n * @typeParam TParent - The type of the parent form control's value (if this control is part of a group or array). Defaults to `undefined`.\n * @typeParam TControlType - The type of the control ('control', 'array', or 'group'). Defaults to 'control'.\n * @typeParam TPartialValue - The type of the partial value, used for patching.\n */\nexport type FormControlSignal<\n T,\n TParent = undefined,\n TControlType extends ControlType = 'control',\n TPartialValue = T | undefined,\n> = {\n /** A unique identifier for the control. Used for tracking in `@for` loops. */\n id: string;\n /** The main value signal for the control. */\n value: WritableSignal<T>;\n /** A signal indicating whether the control's value has been changed. */\n dirty: Signal<boolean>;\n /** A signal indicating whether the control has been interacted with (e.g., blurred). */\n touched: Signal<boolean>;\n /** A signal containing the current validation error message (empty string if valid). */\n error: Signal<string>;\n /** A signal indicating whether the control is disabled. */\n disabled: Signal<boolean>;\n /** A signal indicating whether the control is read-only. */\n readonly: Signal<boolean>;\n /** A signal indicating whether the control is required. */\n required: Signal<boolean>;\n /** A signal containing the label for the control. */\n label: Signal<string>;\n /** A signal containing the hint text for the control. */\n hint: Signal<string>;\n /** Marks the control as touched. */\n markAsTouched: () => void;\n /** Marks the control and all its child controls (if any) as touched. */\n markAllAsTouched: () => void;\n /** Marks the control as pristine (not touched). */\n markAsPristine: () => void;\n /** Marks the control and all its child controls (if any) as pristine. */\n markAllAsPristine: () => void;\n /**\n * Resets the control to a new value and sets a new initial value. This is intended for\n * scenarios where the underlying data is updated externally (e.g., data coming from\n * the server). If the control is not dirty, the value is updated. If the control *is*\n * dirty, the value is *not* updated (preserving user changes).\n */\n reconcile: (newValue: T) => void;\n /**\n * Similar to `reconcile`, but forces the update even if the control is dirty.\n */\n forceReconcile: (newValue: T) => void;\n /** Resets the control's value to its initial value. */\n reset: () => void;\n /** Resets the control's value and initial value. */\n resetWithInitial: (initial: T) => void;\n /**\n * The derivation function used to create this control if it's part of a `formGroup` or `formArray`.\n * @internal\n */\n from?: DerivedSignal<TParent, T>['from'];\n /** The equality function used to compare values. Defaults to `Object.is`. */\n equal: (a: T, b: T) => boolean;\n /** @internal A symbol used for internal type checking.*/\n [CONTROL_SYMBOL]: true;\n /** The type of the control ('control', 'array', or 'group'). */\n controlType: TControlType;\n /**\n * A signal representing the partial value of the control, suitable for patching data on a server.\n * It contains the changed value if `dirty` is `true`.\n */\n partialValue: Signal<TPartialValue>;\n};\n\nexport type CreateFormControlOptions<\n T,\n TControlType extends ControlType = ControlType,\n> = CreateSignalOptions<T> & {\n validator?: () => (value: T) => string;\n onTouched?: () => void;\n disable?: () => boolean;\n readonly?: () => boolean;\n required?: () => boolean;\n label?: () => string;\n id?: () => string;\n hint?: () => string;\n dirtyEquality?: ValueEqualityFn<T>;\n onReset?: () => void;\n controlType?: TControlType;\n overrideValidation?: () => string;\n};\n\n/**\n * Creates a `FormControlSignal`, a reactive form control that holds a value and tracks its\n * validity, dirty state, touched state, and other metadata.\n *\n * @typeParam T - The type of the form control's value.\n * @typeParam TParent - The type of the parent form control's value (if this control is part of a group or array).\n * @typeParam TControlType - The type of the control. Defaults to `'control'`.\n * @typeParam TPartialValue - The type of value when patching\n * @param initial - The initial value of the control, or a `DerivedSignal` if this control is part of a `formGroup` or `formArray`.\n * @param options - Optional configuration options for the control.\n * @returns A `FormControlSignal` instance.\n *\n * @example\n * // Create a simple form control:\n * const name = formControl('Initial Name');\n *\n * // Create a form control with validation:\n * const age = formControl(0, {\n * validator: () => (value) => value >= 18 ? '' : 'Must be at least 18',\n * });\n *\n * // Create a derived form control (equivalent to the above, but more explicit):\n * const user = signal({ name: 'John Doe', age: 30 });\n * const name = formControl(derived(user, {\n * from: (u) => u.name,\n * onChange: (newName) => user.update(u => ({...u, name: newName}))\n * }));\n *\n * // Create a form group with nested controls:\n * const user = signal({ name: 'John Doe', age: 30 });\n * const form = formGroup(user, {\n * name: formControl(derived(user, 'name')),\n * age: formControl(derived(user, 'age')),\n * })\n */\nexport function formControl<\n T,\n TParent = undefined,\n TControlType extends ControlType = 'control',\n TPartialValue = T | undefined,\n>(\n initial: DerivedSignal<TParent, T> | T,\n opt?: CreateFormControlOptions<T, TControlType>,\n): FormControlSignal<T, TParent, TControlType, TPartialValue> {\n const value = isSignal(initial) ? initial : signal(initial, opt);\n const initialValue = signal(untracked(value));\n const eq = opt?.equal ?? Object.is;\n\n const dirtyEq = opt?.dirtyEquality ?? eq;\n\n const disabled = computed(() => opt?.disable?.() ?? false);\n const readonly = computed(() => opt?.readonly?.() ?? false);\n\n const dirty = computed(() => !dirtyEq(value(), initialValue()));\n\n const touched = signal(false);\n\n const validator = computed(() => opt?.validator?.() ?? (() => ''));\n\n const error = computed(() => {\n if (opt?.overrideValidation) return opt.overrideValidation();\n if (disabled() || readonly()) return '';\n return validator()(value());\n });\n\n const markAsTouched = () => {\n touched.set(true);\n opt?.onTouched?.();\n };\n const markAllAsTouched = markAsTouched;\n\n const markAsPristine = () => touched.set(false);\n const markAllAsPristine = markAsPristine;\n\n const label = computed(() => opt?.label?.() ?? '');\n\n const partialValue = computed(() => (dirty() ? value() : undefined));\n\n const internalReconcile = (newValue: T, force = false) => {\n const isDirty = untracked(dirty);\n\n if (!isDirty || force) {\n // very dangerous use of untracked here, don't do this everywhere :)\n // thanks to u/synalx for the idea to use untracked here\n\n untracked(() => {\n initialValue.set(newValue);\n value.set(newValue);\n });\n }\n };\n\n return {\n id: opt?.id?.() ?? v7(),\n value,\n dirty,\n touched,\n error,\n label,\n required: computed(() => opt?.required?.() ?? false),\n disabled,\n readonly,\n hint: computed(() => opt?.hint?.() ?? ''),\n markAsTouched,\n markAllAsTouched,\n markAsPristine,\n markAllAsPristine,\n from: (isSignal(initial) ? initial.from : undefined) as FormControlSignal<\n T,\n TParent,\n TControlType\n >['from'],\n reconcile: (newValue: T) => internalReconcile(newValue),\n forceReconcile: (newValue: T) => internalReconcile(newValue, true),\n reset: () => {\n opt?.onReset?.();\n value.set(untracked(initialValue));\n },\n resetWithInitial: (initial: T) => {\n opt?.onReset?.();\n initialValue.set(initial);\n value.set(initial);\n },\n equal: eq,\n [CONTROL_SYMBOL]: true,\n controlType: (opt?.controlType ?? 'control') as TControlType,\n partialValue: partialValue as Signal<TPartialValue>,\n };\n}\n","import {\n computed,\n linkedSignal,\n untracked,\n type Signal,\n type WritableSignal,\n} from '@angular/core';\nimport { derived, type DerivedSignal } from './derived';\nimport {\n formControl,\n type CreateFormControlOptions,\n type FormControlSignal,\n} from './form-control';\nimport { type SignalValue } from './signal-value.type';\n\nfunction minArrayLengthMsg(min: number, elementLabel: string) {\n return `Min ${min} ${elementLabel}`;\n}\n\nfunction maxArrayLengthMsg(max: number, elementLabel: string) {\n return `Max ${max} ${elementLabel}`;\n}\n\nfunction minArrayLengthValidator(min: number, elementLabel: string) {\n const msg = minArrayLengthMsg(min, elementLabel);\n return (val: any[]) => (val.length >= min ? '' : msg);\n}\n\nfunction maxArrayLengthValidator(max: number, elementLabel: string) {\n const msg = maxArrayLengthMsg(max, elementLabel);\n return (val: any[]) => (val.length <= max ? '' : msg);\n}\n\nexport type ArrayValidatorOpt = {\n min?: number;\n max?: number;\n elementLabel?: string;\n};\n\nexport function arrayValidator<T extends any[]>(opt: ArrayValidatorOpt = {}) {\n const min = opt.min ?? 0;\n const max = opt.max ?? Number.MAX_SAFE_INTEGER;\n const elementLabel = opt.elementLabel ?? 'items';\n\n const minVal = minArrayLengthValidator(min, elementLabel);\n const maxVal = maxArrayLengthValidator(max, elementLabel);\n\n return (val: T) => minVal(val) || maxVal(val);\n}\n\nexport type FormArraySignal<\n T,\n TIndividualState extends FormControlSignal<\n T,\n any,\n any,\n any\n > = FormControlSignal<T, any, any, any>,\n TParent = undefined,\n> = FormControlSignal<\n T[],\n TParent,\n 'array',\n | Exclude<SignalValue<TIndividualState['partialValue']>, null | undefined>[]\n | undefined\n> & {\n ownError: Signal<string>;\n children: Signal<TIndividualState[]>;\n push: (value: T) => void; // add new control with value\n remove: (index: number) => void; // remove at index\n min: Signal<number>; // for display purposes\n max: Signal<number>; // for display purposes\n canAdd: Signal<boolean>; // disable add button if false\n canRemove: Signal<boolean>; // disable remove buttons if false\n};\n\nexport type CreateFormArraySignalOptions<\n T,\n TIndividualState extends FormControlSignal<T, any, any, any>,\n> = CreateFormControlOptions<T> & {\n min?: () => number;\n max?: () => number;\n elementLabel?: () => string;\n toPartialValue?: (\n v: T,\n ) => Exclude<SignalValue<TIndividualState['partialValue']>, null | undefined>;\n};\n\nfunction createReconcileChildren<\n T,\n TIndividualState extends FormControlSignal<T, any, any, any>,\n>(\n factory: (\n val: DerivedSignal<T[], T>,\n idx: number,\n opt?: CreateFormControlOptions<T>,\n ) => TIndividualState,\n opt?: CreateFormControlOptions<T>,\n) {\n return (\n length: number,\n source: WritableSignal<T[]>,\n prev?: TIndividualState[],\n ): TIndividualState[] => {\n if (!prev) {\n const nextControls = [];\n\n for (let i = 0; i < length; i++) {\n nextControls.push(\n factory(derived(source, i, { equal: opt?.equal }), i, opt),\n );\n }\n\n return nextControls;\n }\n\n const next = [...prev];\n\n if (length < prev.length) {\n next.splice(length);\n } else if (length > prev.length) {\n for (let i = prev.length; i < length; i++) {\n next.push(factory(derived(source, i, { equal: opt?.equal }), i, opt));\n }\n }\n\n return next;\n };\n}\n\nexport function formArray<\n T,\n TIndividualState extends FormControlSignal<\n T,\n any,\n any,\n any\n > = FormControlSignal<T, any, any, any>,\n TParent = undefined,\n>(\n initial: T[] | DerivedSignal<TParent, T[]>,\n factory: (\n val: DerivedSignal<T[], T>,\n idx: number,\n opt?: CreateFormControlOptions<T>,\n ) => TIndividualState,\n opt?: CreateFormArraySignalOptions<T, TIndividualState>,\n): FormArraySignal<T, TIndividualState, TParent> {\n const eq = opt?.equal ?? Object.is;\n\n const arrayEqual = (a: T[], b: T[]) => {\n if (a.length !== b.length) return false;\n if (!a.length) return true;\n\n return a.every((v, i) => eq(v, b[i]));\n };\n\n const min = computed(() => opt?.min?.() ?? 0);\n const max = computed(() => opt?.max?.() ?? Number.MAX_SAFE_INTEGER);\n const elementLabel = computed(() => opt?.elementLabel?.() ?? 'items');\n\n const validator = () =>\n arrayValidator<T[]>({\n min: min(),\n max: max(),\n elementLabel: elementLabel(),\n });\n\n const arrayOptions: CreateFormControlOptions<T[], 'array'> = {\n ...opt,\n equal: arrayEqual,\n validator,\n dirtyEquality: (a, b) => a.length === b.length,\n controlType: 'array',\n };\n\n const ctrl = formControl<T[], TParent, 'array'>(\n initial,\n arrayOptions,\n ) satisfies FormControlSignal<T[], TParent, 'array'>;\n\n const length = computed(() => ctrl.value().length);\n\n const reconcileChildren = createReconcileChildren<T, TIndividualState>(\n factory,\n opt,\n );\n\n // linkedSignal used to re-use previous value so that only length changes are affected and existing controls are kept, but updated\n const children = linkedSignal<number, TIndividualState[]>({\n source: () => length(),\n computation: (len, prev) => reconcileChildren(len, ctrl.value, prev?.value),\n });\n\n const ownError = computed(() => validator()(ctrl.value()));\n\n const error = computed((): string => {\n const own = ownError();\n if (own) return own;\n if (!children().length) return '';\n return children()\n .map((c, idx) => (c.error() ? `${idx}: ${c.error()}` : ''))\n .filter(Boolean)\n .join('\\n');\n });\n\n const dirty = computed(() => {\n if (ctrl.dirty()) return true;\n if (!children().length) return false;\n return children().some((c) => c.dirty());\n });\n\n const markAllAsTouched = () => {\n ctrl.markAllAsTouched();\n for (const c of untracked(children)) {\n c.markAllAsTouched();\n }\n };\n const markAllAsPristine = () => {\n ctrl.markAllAsPristine();\n for (const c of untracked(children)) {\n c.markAllAsPristine();\n }\n };\n\n const toPartialValue = opt?.toPartialValue ?? ((v: T) => v);\n const partialValue = computed(() => {\n if (!dirty()) return undefined;\n return children().map((c) => {\n const pv = c.partialValue();\n if (pv) return pv;\n if (c.controlType === 'control') return undefined;\n\n // return full value for child objects/arrays as this cannot be partially patched without idx\n return toPartialValue(c.value());\n });\n });\n\n const touched = computed(\n () =>\n ctrl.touched() ||\n !!(children().length && children().some((c) => c.touched())),\n );\n\n const reconcile = (newValue: T[]) => {\n const ctrls = untracked(children);\n\n for (let i = 0; i < newValue.length; i++) {\n ctrls.at(i)?.reconcile(newValue[i]); // reconcile existing controls that are relevant addition/removal will be handled after ctrl.reconcile through linkedSignal\n }\n\n ctrl.reconcile(newValue);\n };\n\n const forceReconcile = (newValue: T[]) => {\n const ctrls = untracked(children);\n\n for (let i = 0; i < newValue.length; i++) {\n ctrls.at(i)?.forceReconcile(newValue[i]);\n }\n\n ctrl.forceReconcile(newValue);\n };\n\n return {\n ...ctrl,\n ownError,\n error,\n touched,\n children,\n dirty,\n markAllAsTouched,\n markAllAsPristine,\n min,\n max,\n partialValue,\n canAdd: computed(\n () => !ctrl.disabled() && !ctrl.readonly() && length() < max(),\n ),\n canRemove: computed(\n () => !ctrl.disabled() && !ctrl.readonly() && length() > min(),\n ),\n reconcile,\n forceReconcile,\n reset: () => {\n for (const c of untracked(children)) {\n c.reset();\n }\n ctrl.reset();\n },\n resetWithInitial: (initial: T[]) => {\n const ctrls = untracked(children);\n for (let i = 0; i < initial.length; i++) {\n ctrls.at(i)?.resetWithInitial(initial[i]);\n }\n ctrl.resetWithInitial(initial);\n },\n push: (next) => ctrl.value.update((cur) => [...cur, next]),\n remove: (idx) =>\n ctrl.value.update((cur) => cur.filter((_, i) => i !== idx)),\n };\n}\n","import {\n computed,\n isSignal,\n signal,\n untracked,\n type Signal,\n type WritableSignal,\n} from '@angular/core';\nimport { entries, values } from '@mmstack/object';\nimport {\n isDerivation,\n toFakeSignalDerivation,\n type DerivedSignal,\n} from './derived';\nimport {\n formControl,\n type CreateFormControlOptions,\n type FormControlSignal,\n} from './form-control';\nimport { type SignalValue } from './signal-value.type';\n\n/**\n * Extracts the partial value types from a record of `FormControlSignal` instances.\n * This is used to construct the `partialValue` type for `FormGroupSignal`.\n * @internal\n */\ntype DerivationPartialValues<\n TDerivations extends Record<string, FormControlSignal<any, any, any, any>>,\n> = {\n [K in keyof TDerivations]: Exclude<\n SignalValue<TDerivations[K]['partialValue']>,\n undefined\n >;\n};\n\n/**\n * Represents a group of form controls, similar to Angular's `FormGroup`. It aggregates\n * the values and states of its child controls into a single object.\n *\n * @typeParam T - The type of the form group's value (an object).\n * @typeParam TDerivations - A record where keys are the names of the child controls and values are the `FormControlSignal` instances.\n * @typeParam TParent - The type of the parent form control's value (if this group is nested).\n */\nexport type FormGroupSignal<\n T,\n TDerivations extends Record<string, FormControlSignal<any, T, any, any>>,\n TParent = undefined,\n> = FormControlSignal<\n T,\n TParent,\n 'group',\n Partial<DerivationPartialValues<TDerivations>>\n> & {\n /**\n * A signal that holds a record of the child form controls. The keys are the names\n * of the controls, and the values are the `FormControlSignal` instances.\n */\n children: Signal<TDerivations>;\n /**\n * A signal that holds the validation error message of the group itself (excluding child errors).\n */\n ownError: Signal<string>;\n};\n\n/**\n * Options for creating a `FormGroupSignal`. Extends `CreateFormControlOptions`.\n */\nexport type CreateFormGroupOptions<\n T,\n TDerivations extends Record<string, FormControlSignal<any, T, any, any>>,\n> = CreateFormControlOptions<T, 'group'> & {\n /**\n * An optional function to create a base object for the `partialValue` signal.\n * This can be used to pre-populate the partial value with default values or\n * to perform custom logic before merging in the partial values from child controls.\n */\n createBasePartialValue?: (\n value: T,\n ) => Partial<DerivationPartialValues<TDerivations>>;\n};\n\n/**\n * Creates a `FormGroupSignal`, which aggregates a set of child form controls into a single object.\n *\n * @typeParam T - The type of the form group's value (an object).\n * @typeParam TDerivations - A record where keys are the names of the child controls and values are the `FormControlSignal` instances.\n * @typeParam TParent - The type of the parent form control's value (if this group is nested within another group or array).\n * @param initial - The initial value of the form group (or a `WritableSignal` or `DerivedSignal` if the group is nested).\n * @param providedChildren - An object containing the child `FormControlSignal` instances, or a function that returns such an object.\n * Using a function allows for dynamic creation of child controls (e.g., in response to changes in other signals).\n * @param options - Optional configuration options for the form group.\n * @returns A `FormGroupSignal` instance.\n *\n * @example\n * // Create a simple form group:\n * const user = signal({ name: 'John Doe', age: 30 });\n * const form = formGroup(user, {\n * name: formControl(derived(user, 'name')),\n * age: formControl(derived(user, 'age')),\n * })\n *\n * // Create a nested form group:\n * const user = signal({ name: 'John', age: 30, address: {street: \"Some street\"} });\n *\n * const address = derived(user, 'address');\n * const userForm = formGroup(user, {\n * name: formControl(derived(user, 'name')),\n * age: formControl(derived(user, 'age')),\n * address: formGroup(address, {\n * street: formControl(derived(address, (address) => address.street), {\n * validator: () => (value) => value ? \"\" : \"required!\"\n * }) // you can create deeply nested structures.\n * })\n * });\n *\n * // Create a form group with dynamically created children replaced rare FormRecord requirements.\n * const showAddress = signal(false);\n * type Characteristic = {\n * valueType: 'string';\n * value: string;\n * } | {\n * valueType: 'number';\n * value: number;\n * }\n * const char = signal<Characteristic>({ valueType: 'string', value: '' });\n * const charForm = formGroup(char, () => {\n * if (char().valueType === 'string) return createStringControl(char);\n * return createNumberControl(char);\n * });\n *\n */\nexport function formGroup<\n T,\n TDerivations extends Record<string, FormControlSignal<any, T, any, any>>,\n TParent = undefined,\n>(\n initial: DerivedSignal<TParent, T> | T | WritableSignal<T>,\n providedChildren: (() => TDerivations) | TDerivations,\n opt?: CreateFormGroupOptions<T, TDerivations>,\n): FormGroupSignal<T, TDerivations, TParent> {\n const valueSignal = isSignal(initial) ? initial : signal(initial);\n // we fake a derivation if not present, so that .from is present on the signal\n const value = isDerivation<TParent, T>(valueSignal)\n ? valueSignal\n : toFakeSignalDerivation<TParent, T>(valueSignal);\n\n // we allow for a function/signal to be passed, this case should only be used if the child controls change dependent upon something, say if a formControl is flipped into a formGroup.\n const children =\n typeof providedChildren === 'function'\n ? computed(() => providedChildren())\n : computed(() => providedChildren);\n\n // array allows for easier handling\n const derivationsArray = computed(() => values(children()));\n\n const childrenDirty = computed(\n () =>\n !!derivationsArray().length && derivationsArray().some((d) => d.dirty()),\n );\n\n // by default dont compare object references, just use childrenDirtySignal\n const baseDirtyEq = opt?.dirtyEquality ?? opt?.equal ?? (() => true);\n\n // function which calls a signal becomes a signal\n const dirtyEquality = (a: T, b: T) => {\n return baseDirtyEq(a, b) && !childrenDirty();\n };\n\n // group control\n const ctrl = formControl<T, TParent, 'group'>(value, {\n ...opt,\n dirtyEquality,\n controlType: 'group',\n readonly: () => {\n // readonly if is readonly or all children are readonly\n if (opt?.readonly?.()) return true;\n return (\n !!derivationsArray().length &&\n derivationsArray().every((d) => d.readonly())\n );\n },\n disable: () => {\n if (opt?.disable?.()) return true;\n return (\n !!derivationsArray().length &&\n derivationsArray().some((d) => d.disabled())\n );\n },\n }) satisfies FormControlSignal<T, TParent, 'group'>;\n\n const childrenTouched = computed(\n () =>\n !!derivationsArray().length &&\n derivationsArray().some((d) => d.touched()),\n );\n\n const touched = computed(() => ctrl.touched() || childrenTouched());\n\n const childError = computed(() => {\n if (!derivationsArray().length) return '';\n return derivationsArray()\n .map((d) => (d.error() ? `${d.label()}: ${d.error()}` : ''))\n .filter(Boolean)\n .join('\\n');\n });\n\n const error = computed(() => {\n const ownError = ctrl.error();\n if (ownError) return ownError;\n return childError() ? 'INVALID' : '';\n });\n\n const markAllAsTouched = () => {\n ctrl.markAllAsTouched();\n for (const ctrl of untracked(derivationsArray)) {\n ctrl.markAllAsTouched();\n }\n };\n\n const markAllAsPristine = () => {\n ctrl.markAllAsPristine();\n for (const ctrl of untracked(derivationsArray)) {\n ctrl.markAllAsPristine();\n }\n };\n\n const reconcile = (newValue: T) => {\n // set the children values based on the derivation of the new value\n for (const ctrl of untracked(derivationsArray)) {\n const from = ctrl.from;\n if (!from) continue;\n ctrl.reconcile(from(newValue));\n }\n ctrl.reconcile(newValue);\n };\n\n const forceReconcile = (newValue: T) => {\n for (const ctrl of untracked(derivationsArray)) {\n const from = ctrl.from;\n if (!from) continue;\n ctrl.forceReconcile(from(newValue));\n }\n ctrl.forceReconcile(newValue);\n };\n\n const createBaseValueFn = opt?.createBasePartialValue;\n\n const basePartialValue: Signal<\n Partial<DerivationPartialValues<TDerivations>>\n > = createBaseValueFn\n ? computed(() => createBaseValueFn(ctrl.value()))\n : computed(() => ({}));\n\n const partialValue = computed(() => {\n const obj: Partial<DerivationPartialValues<TDerivations>> = {\n ...basePartialValue(),\n };\n\n if (!ctrl.dirty()) return obj;\n\n for (const [key, ctrl] of entries(children())) {\n const pv = ctrl.partialValue();\n\n if (pv === undefined) continue;\n obj[key] = pv;\n }\n\n return obj;\n });\n\n return {\n ...ctrl,\n children,\n partialValue,\n reconcile,\n forceReconcile,\n ownError: ctrl.error,\n touched,\n error,\n markAllAsPristine,\n markAllAsTouched,\n reset: () => {\n for (const ctrl of untracked(derivationsArray)) {\n ctrl.reset();\n }\n ctrl.reset();\n },\n resetWithInitial: (initial: T) => {\n for (const ctrl of untracked(derivationsArray)) {\n const from = ctrl.from;\n from ? ctrl.resetWithInitial(from(initial)) : ctrl.reset();\n }\n ctrl.resetWithInitial(initial);\n },\n };\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;SA0GgB,OAAO,CACrB,MAAyB,EACzB,QAA8C,EAC9C,GAA4B,EAAA;IAE5B,MAAM,IAAI,GACR,OAAO,QAAQ,KAAK,QAAQ,GAAG,QAAQ,CAAC,IAAI,GAAG,CAAC,CAAI,KAAK,CAAC,CAAC,QAAQ,CAAM;AAC3E,IAAA,MAAM,QAAQ,GACZ,OAAO,QAAQ,KAAK;UAChB,QAAQ,CAAC;AACX,UAAE,CAAC,IAAO,KAAI;YACV,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,MAAM,EAAE,GAAG,GAAG,EAAE,CAAC,QAAQ,GAAG,IAAI,EAAE,CAAC,CAAC;AACxD,SAAC;AAEP,IAAA,MAAM,IAAI,GAAG,OAAO,QAAQ,KAAK,QAAQ,GAAG,QAAQ,GAAG,GAAG;AAE1D,IAAA,MAAM,GAAG,GAAG,UAAU,CACpB,QAAQ,CAAC,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,IAAI,CAAC,EACpC,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,CAAC,CACN;AAExB,IAAA,GAAG,CAAC,IAAI,GAAG,IAAI;AAEf,IAAA,OAAO,GAAG;AACZ;AAEA;;;;;;;;;;AAUG;AACG,SAAU,gBAAgB,CAAO,OAAU,EAAA;AAC/C,IAAA,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAwB;AAClD,IAAA,GAAG,CAAC,IAAI,GAAG,MAAM,OAAO;AAExB,IAAA,OAAO,GAAG;AACZ;AAEA;;;;;;;;;;AAUG;AACG,SAAU,sBAAsB,CACpC,OAA0B,EAAA;IAE1B,MAAM,GAAG,GAAG,OAA8B;IAC1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