@fluixi/forms-framework 0.2.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Fluixi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @fluixi/forms-framework — JSX bindings for @fluixi/forms-core.
3
+ *
4
+ * Fine-grained by construction: `bindField` returns reactive prop accessors. In the
5
+ * Fluixi compiler, `value={field.value}` and `onInput={...}` wire to ONLY that field's
6
+ * signals, so typing in one field never re-runs another.
7
+ */
8
+ import type { FieldControl } from '@fluixi/forms-core';
9
+ export interface FieldBinding<T> {
10
+ /** reactive value accessor — pass as `value={binding.value}` */
11
+ value: () => T;
12
+ /** writes the field + marks touched */
13
+ onInput: (e: {
14
+ currentTarget: {
15
+ value: any;
16
+ };
17
+ } | any) => void;
18
+ onBlur: () => void;
19
+ 'aria-invalid': () => boolean;
20
+ disabled: () => boolean;
21
+ }
22
+ /** Bind a field to a native input. `coerce` turns the DOM string into T (number, etc.). */
23
+ export declare function bindField<T>(field: FieldControl<T>, coerce?: (raw: string) => T): FieldBinding<T>;
24
+ /** Bind a checkbox (boolean field). */
25
+ export declare function bindCheckbox(field: FieldControl<boolean>): {
26
+ checked: import("@fluixi/forms-core").Accessor<boolean>;
27
+ onChange: (e: any) => void;
28
+ onBlur: () => void;
29
+ };
30
+ /**
31
+ * `<Field>` render-prop component. Usage (Fluixi JSX):
32
+ * <Field control={form.get('email')}>
33
+ * {(b, field) => <>
34
+ * <input value={b.value()} onInput={b.onInput} onBlur={b.onBlur} />
35
+ * <Show when={field.touched() && field.error()}>{e => <span>{e().message}</span>}</Show>
36
+ * </>}
37
+ * </Field>
38
+ */
39
+ export declare function Field<T>(props: {
40
+ control: FieldControl<T>;
41
+ children: (binding: FieldBinding<T>, field: FieldControl<T>) => any;
42
+ coerce?: (raw: string) => T;
43
+ }): any;
44
+ /**
45
+ * Directive-style binding for the compiler's `use:` syntax:
46
+ * <input use:model={field} />
47
+ * Wires value + input + blur on the element, with cleanup.
48
+ */
49
+ export declare function model<T>(el: HTMLInputElement, accessor: () => FieldControl<T>): void;
package/dist/index.js ADDED
@@ -0,0 +1,55 @@
1
+ /** Bind a field to a native input. `coerce` turns the DOM string into T (number, etc.). */
2
+ export function bindField(field, coerce) {
3
+ return {
4
+ value: field.value,
5
+ onInput: (e) => {
6
+ const raw = e?.currentTarget?.value ?? e?.target?.value ?? e;
7
+ field.setValue((coerce ? coerce(raw) : raw));
8
+ },
9
+ onBlur: () => field.markTouched(true),
10
+ 'aria-invalid': () => field.invalid() && field.touched(),
11
+ disabled: field.disabled,
12
+ };
13
+ }
14
+ /** Bind a checkbox (boolean field). */
15
+ export function bindCheckbox(field) {
16
+ return {
17
+ checked: field.value,
18
+ onChange: (e) => field.setValue(!!(e?.currentTarget?.checked ?? e?.target?.checked)),
19
+ onBlur: () => field.markTouched(true),
20
+ };
21
+ }
22
+ /**
23
+ * `<Field>` render-prop component. Usage (Fluixi JSX):
24
+ * <Field control={form.get('email')}>
25
+ * {(b, field) => <>
26
+ * <input value={b.value()} onInput={b.onInput} onBlur={b.onBlur} />
27
+ * <Show when={field.touched() && field.error()}>{e => <span>{e().message}</span>}</Show>
28
+ * </>}
29
+ * </Field>
30
+ */
31
+ export function Field(props) {
32
+ return props.children(bindField(props.control, props.coerce), props.control);
33
+ }
34
+ /**
35
+ * Directive-style binding for the compiler's `use:` syntax:
36
+ * <input use:model={field} />
37
+ * Wires value + input + blur on the element, with cleanup.
38
+ */
39
+ export function model(el, accessor) {
40
+ const field = accessor();
41
+ const sync = () => {
42
+ const v = field.value();
43
+ if (el.type === 'checkbox')
44
+ el.checked = !!v;
45
+ else if (el.value !== String(v ?? ''))
46
+ el.value = String(v ?? '');
47
+ };
48
+ // A render-effect would normally be created by the framework around use: directives;
49
+ // here we attach listeners + an initial sync. (The host framework owns the effect.)
50
+ sync();
51
+ const onInput = () => field.setValue((el.type === 'checkbox' ? el.checked : el.value));
52
+ const onBlur = () => field.markTouched(true);
53
+ el.addEventListener('input', onInput);
54
+ el.addEventListener('blur', onBlur);
55
+ }
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@fluixi/forms-framework",
3
+ "version": "0.2.0",
4
+ "license": "MIT",
5
+ "description": "JSX bindings + Field component for @fluixi/forms-core.",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "LICENSE"
18
+ ],
19
+ "dependencies": {
20
+ "@fluixi/forms-core": "0.2.0"
21
+ },
22
+ "publishConfig": {
23
+ "registry": "https://registry.npmjs.org/",
24
+ "access": "public"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/fluixi/forms.git",
29
+ "directory": "packages/forms-framework"
30
+ },
31
+ "scripts": {
32
+ "build": "tsc -p tsconfig.json",
33
+ "test": "vitest run --passWithNoTests"
34
+ }
35
+ }