@fluixi/forms-core 0.2.0 → 0.2.1-alpha.1
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 +13 -0
- package/dist/array.d.ts +1 -1
- package/dist/array.js +6 -0
- package/dist/types.d.ts +11 -1
- package/package.json +2 -1
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# @fluixi/forms-core
|
|
2
|
+
|
|
3
|
+
The core reactive engine — `createField`/`createGroup`/`createForm`/`createFormArray`, validators, and the sync+async validation engine. Every field is an independent reactive cell (no RxJS, no central store, no proxies).
|
|
4
|
+
|
|
5
|
+
Part of [`@fluixi/forms`](https://www.npmjs.com/package/@fluixi/forms) — reactive forms for fine-grained signal frameworks.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @fluixi/forms-core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
See the [`@fluixi/forms`](https://www.npmjs.com/package/@fluixi/forms) package for the full guide.
|
package/dist/array.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { ArrayControl, ArrayOptions, Control } from './types.js';
|
|
2
2
|
/** Stable key for a control (for keyed list rendering). */
|
|
3
3
|
export declare const keyOf: (control: object) => number;
|
|
4
|
-
export declare function createFormArray<TItem, TCtrl extends Control<TItem> = Control<TItem>>(initial?: TCtrl[], options?: ArrayOptions<TItem>): ArrayControl<TItem, TCtrl>;
|
|
4
|
+
export declare function createFormArray<TItem, TCtrl extends Control<TItem> = Control<TItem>>(initial?: TCtrl[], options?: ArrayOptions<TItem, TCtrl>): ArrayControl<TItem, TCtrl>;
|
package/dist/array.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* exposed via `keyOf` for keyed rendering. Aggregate state is derived with memos.
|
|
8
8
|
*/
|
|
9
9
|
import { createSignal, createMemo, untrack, batch } from '@fluixi/reactive/signal';
|
|
10
|
+
import { createField } from './field.js';
|
|
10
11
|
let _key = 0;
|
|
11
12
|
const keys = new WeakMap();
|
|
12
13
|
/** Stable key for a control (for keyed list rendering). */
|
|
@@ -18,6 +19,9 @@ export const keyOf = (control) => {
|
|
|
18
19
|
};
|
|
19
20
|
export function createFormArray(initial = [], options = {}) {
|
|
20
21
|
const [list, setList] = createSignal([...initial]);
|
|
22
|
+
// Wrap a plain value into a child control for pushValue/insertValue. Defaults to
|
|
23
|
+
// a field; a `control` factory builds groups/nested arrays for structured rows.
|
|
24
|
+
const makeControl = options.control ?? ((v) => createField(v));
|
|
21
25
|
const [disabled, setDisabledSig] = createSignal(!!options.disabled);
|
|
22
26
|
const [submitCount] = createSignal(0);
|
|
23
27
|
const syncValidators = options.validators ?? [];
|
|
@@ -84,6 +88,8 @@ export function createFormArray(initial = [], options = {}) {
|
|
|
84
88
|
wire(c);
|
|
85
89
|
mutate((arr) => (arr.splice(i, 0, c), arr));
|
|
86
90
|
},
|
|
91
|
+
pushValue: (v) => self.push(makeControl(v)),
|
|
92
|
+
insertValue: (i, v) => self.insert(i, makeControl(v)),
|
|
87
93
|
removeAt: (i) => mutate((arr) => (arr.splice(i, 1), arr)),
|
|
88
94
|
move: (from, to) => mutate((arr) => {
|
|
89
95
|
const [c] = arr.splice(from, 1);
|
package/dist/types.d.ts
CHANGED
|
@@ -115,10 +115,16 @@ export interface GroupControl<C extends ControlsRecord> extends Control<GroupVal
|
|
|
115
115
|
/** Remove a control at runtime. */
|
|
116
116
|
removeControl(key: keyof C): void;
|
|
117
117
|
}
|
|
118
|
-
export interface ArrayOptions<T> {
|
|
118
|
+
export interface ArrayOptions<T, TCtrl extends Control<T> = Control<T>> {
|
|
119
119
|
validators?: Validator<T[]>[];
|
|
120
120
|
asyncValidators?: AsyncValidator<T[]>[];
|
|
121
121
|
disabled?: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* How to wrap a plain value into a child control for `pushValue`/`insertValue`.
|
|
124
|
+
* Defaults to `createField(value)`; supply this to build groups/nested arrays
|
|
125
|
+
* for structured rows.
|
|
126
|
+
*/
|
|
127
|
+
control?: (value: T) => TCtrl;
|
|
122
128
|
}
|
|
123
129
|
export interface ArrayControl<TItem, TCtrl extends Control<TItem> = Control<TItem>> extends Control<TItem[]> {
|
|
124
130
|
readonly kind: 'array';
|
|
@@ -128,6 +134,10 @@ export interface ArrayControl<TItem, TCtrl extends Control<TItem> = Control<TIte
|
|
|
128
134
|
at(index: number): TCtrl | undefined;
|
|
129
135
|
push(control: TCtrl): void;
|
|
130
136
|
insert(index: number, control: TCtrl): void;
|
|
137
|
+
/** Wrap a plain value into a child control (see {@link ArrayOptions.control}) and append it. */
|
|
138
|
+
pushValue(value: TItem): void;
|
|
139
|
+
/** Wrap a plain value into a child control and insert it at `index`. */
|
|
140
|
+
insertValue(index: number, value: TItem): void;
|
|
131
141
|
removeAt(index: number): void;
|
|
132
142
|
move(from: number, to: number): void;
|
|
133
143
|
clear(): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluixi/forms-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1-alpha.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Reactive forms core (FormControl/FormGroup/FormArray) for fine-grained signal frameworks.",
|
|
6
6
|
"type": "module",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
|
+
"README.md",
|
|
16
17
|
"dist",
|
|
17
18
|
"LICENSE"
|
|
18
19
|
],
|