formo-react 0.0.0-stage → 0.3.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.
Files changed (87) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +21 -2
  3. package/dist/components/FormoBlueprint.d.ts +5 -0
  4. package/dist/components/FormoBlueprint.js +30 -0
  5. package/dist/components/FormoButton.d.ts +6 -0
  6. package/dist/components/FormoButton.js +23 -0
  7. package/dist/components/FormoCheckbox.d.ts +7 -0
  8. package/dist/components/FormoCheckbox.js +10 -0
  9. package/dist/components/FormoChecklist.d.ts +5 -0
  10. package/dist/components/FormoChecklist.js +15 -0
  11. package/dist/components/FormoChoices.d.ts +8 -0
  12. package/dist/components/FormoChoices.js +33 -0
  13. package/dist/components/FormoContext.d.ts +27 -0
  14. package/dist/components/FormoContext.js +69 -0
  15. package/dist/components/FormoErrors.d.ts +5 -0
  16. package/dist/components/FormoErrors.js +14 -0
  17. package/dist/components/FormoField.d.ts +17 -0
  18. package/dist/components/FormoField.js +148 -0
  19. package/dist/components/FormoForm.d.ts +15 -0
  20. package/dist/components/FormoForm.js +76 -0
  21. package/dist/components/FormoGroup.d.ts +5 -0
  22. package/dist/components/FormoGroup.js +15 -0
  23. package/dist/components/FormoHelp.d.ts +6 -0
  24. package/dist/components/FormoHelp.js +9 -0
  25. package/dist/components/FormoInput.d.ts +6 -0
  26. package/dist/components/FormoInput.js +24 -0
  27. package/dist/components/FormoLabel.d.ts +6 -0
  28. package/dist/components/FormoLabel.js +9 -0
  29. package/dist/components/FormoProvider.d.ts +11 -0
  30. package/dist/components/FormoProvider.js +13 -0
  31. package/dist/components/FormoRest.d.ts +6 -0
  32. package/dist/components/FormoRest.js +23 -0
  33. package/dist/components/FormoSelect.d.ts +6 -0
  34. package/dist/components/FormoSelect.js +36 -0
  35. package/dist/components/FormoUneditable.d.ts +6 -0
  36. package/dist/components/FormoUneditable.js +12 -0
  37. package/dist/core/builder.d.ts +42 -0
  38. package/dist/core/builder.js +166 -0
  39. package/dist/core/controls.d.ts +27 -0
  40. package/dist/core/controls.js +24 -0
  41. package/dist/core/fields.d.ts +63 -0
  42. package/dist/core/fields.js +177 -0
  43. package/dist/core/messages.d.ts +35 -0
  44. package/dist/core/messages.js +69 -0
  45. package/dist/core/normalize.d.ts +35 -0
  46. package/dist/core/normalize.js +234 -0
  47. package/dist/core/options.d.ts +44 -0
  48. package/dist/core/options.js +146 -0
  49. package/dist/core/rules.d.ts +41 -0
  50. package/dist/core/rules.js +230 -0
  51. package/dist/core/store.d.ts +155 -0
  52. package/dist/core/store.js +830 -0
  53. package/dist/core/theme.d.ts +20 -0
  54. package/dist/core/theme.js +21 -0
  55. package/dist/core/tree.d.ts +74 -0
  56. package/dist/core/tree.js +119 -0
  57. package/dist/core/utils.d.ts +35 -0
  58. package/dist/core/utils.js +206 -0
  59. package/dist/hooks/subscriptions.d.ts +38 -0
  60. package/dist/hooks/subscriptions.js +65 -0
  61. package/dist/hooks/useFormo.d.ts +18 -0
  62. package/dist/hooks/useFormo.js +25 -0
  63. package/dist/index.d.ts +28 -0
  64. package/dist/index.js +27 -0
  65. package/dist/schema/form.d.ts +92 -0
  66. package/dist/schema/form.js +304 -0
  67. package/dist/schema/index.d.ts +22 -0
  68. package/dist/schema/index.js +21 -0
  69. package/dist/schema/ir.d.ts +189 -0
  70. package/dist/schema/ir.js +130 -0
  71. package/dist/schema/json-schema.d.ts +25 -0
  72. package/dist/schema/json-schema.js +351 -0
  73. package/dist/schema/laravel.d.ts +57 -0
  74. package/dist/schema/laravel.js +555 -0
  75. package/dist/schema/openapi.d.ts +24 -0
  76. package/dist/schema/openapi.js +67 -0
  77. package/dist/schema/policy.d.ts +60 -0
  78. package/dist/schema/policy.js +315 -0
  79. package/dist/schema/spec.d.ts +75 -0
  80. package/dist/schema/spec.js +1 -0
  81. package/dist/schema/values.d.ts +35 -0
  82. package/dist/schema/values.js +151 -0
  83. package/dist/schema/zod.d.ts +79 -0
  84. package/dist/schema/zod.js +236 -0
  85. package/dist/types.d.ts +400 -0
  86. package/dist/types.js +1 -0
  87. package/package.json +70 -4
@@ -0,0 +1,148 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { memo } from 'react';
3
+ import { isControl } from '../core/controls';
4
+ import { isHidden } from '../core/normalize';
5
+ import { useFormoField } from '../hooks/subscriptions';
6
+ import { FormoBlueprint } from './FormoBlueprint';
7
+ import { FormoButton } from './FormoButton';
8
+ import { FormoCheckbox } from './FormoCheckbox';
9
+ import { FormoChecklist } from './FormoChecklist';
10
+ import { FormoCheckboxes, FormoRadios } from './FormoChoices';
11
+ import { FormoFieldContext, useClaimField, useFieldProp, useFormoOptions } from './FormoContext';
12
+ import { FormoErrors } from './FormoErrors';
13
+ import { FormoGroup } from './FormoGroup';
14
+ import { FormoHelp } from './FormoHelp';
15
+ import { FormoInput } from './FormoInput';
16
+ import { FormoLabel } from './FormoLabel';
17
+ import { FormoSelect } from './FormoSelect';
18
+ import { FormoUneditable, readOnlyText } from './FormoUneditable';
19
+ const isButton = (driver) => driver === 'button' || driver === 'submit';
20
+ function resolveRef(ref, components) {
21
+ if (!ref)
22
+ return undefined;
23
+ if (typeof ref === 'string')
24
+ return resolveRef(components[ref], components);
25
+ if (isControl(ref)) {
26
+ const inner = typeof ref.component === 'string' ? resolveRef(ref.component, components) : ref.component;
27
+ if (!inner || isControl(inner))
28
+ return inner;
29
+ return { ...ref, component: inner };
30
+ }
31
+ return ref;
32
+ }
33
+ function renderSlot(slot, field, fallback) {
34
+ if (slot === undefined)
35
+ return fallback;
36
+ return typeof slot === 'function' ? slot(field) : slot;
37
+ }
38
+ export function FormoReadOnly({ field: propField }) {
39
+ const field = useFieldProp(propField);
40
+ const options = useFormoOptions();
41
+ const resolved = resolveRef(field.node.component, options.components);
42
+ const comp = isControl(resolved)
43
+ ? typeof resolved.component === 'function'
44
+ ? resolved.component
45
+ : undefined
46
+ : resolved;
47
+ const ReadOnly = comp?.readOnly;
48
+ if (ReadOnly)
49
+ return _jsx(ReadOnly, { field: field, text: readOnlyText(field) });
50
+ return _jsx(FormoUneditable, { field: field });
51
+ }
52
+ export function FormoFieldControl({ field: propField }) {
53
+ const field = useFieldProp(propField);
54
+ const { node } = field;
55
+ const options = useFormoOptions();
56
+ if (!field.editable)
57
+ return _jsx(FormoReadOnly, { field: field });
58
+ const ref = node.component ??
59
+ (node.type ? options.components[`${node.driver}|${node.type}`] : undefined) ??
60
+ options.components[node.driver];
61
+ const resolved = resolveRef(ref, options.components);
62
+ if (resolved) {
63
+ if (isControl(resolved)) {
64
+ const Comp = resolved.component;
65
+ const propName = resolved.model?.prop ?? 'value';
66
+ const eventName = resolved.model?.event ?? 'onChange';
67
+ const modelVal = resolved.model?.get ? resolved.model.get(field.value) : field.value;
68
+ const dynamicProps = resolved.props ? resolved.props(field) : {};
69
+ const extraProps = {
70
+ field,
71
+ ...dynamicProps,
72
+ ...(node.props ?? {}),
73
+ [propName]: modelVal,
74
+ [eventName]: (next) => {
75
+ field.setValue(resolved.model?.set ? resolved.model.set(next) : next);
76
+ },
77
+ onBlur: field.setBlur,
78
+ };
79
+ return _jsx(Comp, { ...extraProps });
80
+ }
81
+ const Custom = resolved;
82
+ return (_jsx(Custom, { field: field, value: field.value, onChange: (next) => field.setValue(next), onBlur: field.setBlur, editable: field.editable, disabled: field.disabled, invalid: field.invalid, ...(node.props ?? {}) }));
83
+ }
84
+ switch (node.driver) {
85
+ case 'button':
86
+ case 'submit':
87
+ return _jsx(FormoButton, { field: field });
88
+ case 'checkbox':
89
+ case 'switch':
90
+ return _jsx(FormoCheckbox, { field: field });
91
+ case 'select':
92
+ case 'multiple':
93
+ return _jsx(FormoSelect, { field: field });
94
+ case 'radios':
95
+ return _jsx(FormoRadios, { field: field });
96
+ case 'checkboxes':
97
+ case 'set':
98
+ return _jsx(FormoCheckboxes, { field: field });
99
+ default:
100
+ return _jsx(FormoInput, { field: field });
101
+ }
102
+ }
103
+ function FormoFieldInner({ field: handle, slots: propSlots, view: propView, children }) {
104
+ useClaimField(handle.path, true);
105
+ const options = useFormoOptions();
106
+ const formSlot = options.slots[handle.path];
107
+ const formDefaultSlot = typeof formSlot === 'function' ? formSlot : undefined;
108
+ const formRegionSlots = formSlot && typeof formSlot === 'object' ? formSlot : undefined;
109
+ const activeDefaultSlot = children ?? formDefaultSlot;
110
+ const field = useFormoField(handle, { withValue: handle.kind === 'field' || !!activeDefaultSlot });
111
+ if (!field.node.render)
112
+ return null;
113
+ if (activeDefaultSlot) {
114
+ return _jsx(FormoFieldContext.Provider, { value: field, children: activeDefaultSlot(field) });
115
+ }
116
+ if (field.kind === 'group')
117
+ return _jsx(FormoGroup, { group: handle });
118
+ if (field.kind === 'blueprint')
119
+ return _jsx(FormoBlueprint, { blueprint: handle });
120
+ if (isHidden(field.node))
121
+ return null;
122
+ const { node } = field;
123
+ const inlineLabel = (node.driver === 'checkbox' || node.driver === 'switch') && field.editable && !node.component;
124
+ const showLabel = !isButton(node.driver) && !inlineLabel && !!node.label;
125
+ const mergedSlots = {
126
+ ...formRegionSlots,
127
+ ...propSlots,
128
+ ...(options.slots[`${handle.path}.label`] ? { label: options.slots[`${handle.path}.label`] } : {}),
129
+ ...(options.slots[`${handle.path}.input`] ? { input: options.slots[`${handle.path}.input`] } : {}),
130
+ ...(options.slots[`${handle.path}.help`] ? { help: options.slots[`${handle.path}.help`] } : {}),
131
+ ...(options.slots[`${handle.path}.checklist`] ? { checklist: options.slots[`${handle.path}.checklist`] } : {}),
132
+ ...(options.slots[`${handle.path}.errors`] ? { errors: options.slots[`${handle.path}.errors`] } : {}),
133
+ };
134
+ const LabelComp = options.views.label ?? FormoLabel;
135
+ const HelpComp = options.views.help ?? FormoHelp;
136
+ const ChecklistComp = options.views.checklist ?? FormoChecklist;
137
+ const ErrorsComp = options.views.errors ?? FormoErrors;
138
+ const rendered = {
139
+ label: renderSlot(mergedSlots.label, field, showLabel ? _jsx(LabelComp, { field: field }) : null),
140
+ input: renderSlot(mergedSlots.input, field, _jsx(FormoFieldControl, { field: field })),
141
+ help: renderSlot(mergedSlots.help, field, node.message ? _jsx(HelpComp, { field: field }) : null),
142
+ checklist: renderSlot(mergedSlots.checklist, field, field.editable ? _jsx(ChecklistComp, { field: field }) : null),
143
+ errors: renderSlot(mergedSlots.errors, field, _jsx(ErrorsComp, { field: field })),
144
+ };
145
+ const FieldView = propView ?? (typeof node.view === 'function' ? node.view : undefined) ?? options.views.field;
146
+ return (_jsx(FormoFieldContext.Provider, { value: field, children: FieldView ? (_jsx(FieldView, { formo: field, slots: rendered })) : (_jsxs("div", { style: { marginBottom: 14 }, children: [rendered.label, rendered.input, rendered.help, rendered.checklist, rendered.errors] })) }));
147
+ }
148
+ export const FormoField = memo(FormoFieldInner);
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import type { ComponentRef, FormoConfig, FormoController, FormoDefinition, FormoFieldHandle, FormoFieldSlots, FormoTheme, FormoViews } from '../types';
3
+ import { type UseFormoOptions } from '../hooks/useFormo';
4
+ export interface FormoFormProps extends Omit<React.FormHTMLAttributes<HTMLFormElement>, 'onSubmit'> {
5
+ form: FormoDefinition | FormoController;
6
+ options?: UseFormoOptions;
7
+ config?: FormoConfig;
8
+ theme?: FormoTheme;
9
+ components?: Record<string, ComponentRef>;
10
+ views?: FormoViews;
11
+ slots?: Record<string, FormoFieldSlots | ((field: FormoFieldHandle) => React.ReactNode)>;
12
+ classes?: Record<string, string>;
13
+ children?: React.ReactNode;
14
+ }
15
+ export declare function FormoForm({ form, options, config, theme, components, views, slots, classes, children, ...rest }: FormoFormProps): React.JSX.Element;
@@ -0,0 +1,76 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useMemo, useRef } from 'react';
3
+ import { useFormo } from '../hooks/useFormo';
4
+ import { useFormoFields, useFormoState } from '../hooks/subscriptions';
5
+ import { FormoClaimedContext, FormoContext, FormoOptionsContext, useFormoOptions, useStableLayerOptions, } from './FormoContext';
6
+ import { FormoField } from './FormoField';
7
+ function isController(value) {
8
+ return typeof value?.validate === 'function' && typeof value?.submit === 'function';
9
+ }
10
+ function FormoFormBody({ controller, children }) {
11
+ const formError = useFormoState(controller, (s) => s.errors['']);
12
+ const fields = useFormoFields(controller);
13
+ return (_jsxs(_Fragment, { children: [formError ? (_jsx("p", { role: "alert", style: {
14
+ fontSize: 14,
15
+ color: '#dc2626',
16
+ border: '1px solid #fecaca',
17
+ backgroundColor: '#fef2f2',
18
+ borderRadius: 6,
19
+ padding: '8px 12px',
20
+ margin: '0 0 14px',
21
+ }, children: formError })) : null, children ?? Object.values(fields).map((field) => _jsx(FormoField, { field: field }, field.path))] }));
22
+ }
23
+ function FormoFormProviders({ controller, theme, components, views, slots, classes, children, ...rest }) {
24
+ const parentOptions = useFormoOptions();
25
+ const mergedOptions = useStableLayerOptions(useMemo(() => ({
26
+ components: { ...parentOptions.components, ...theme?.components, ...components },
27
+ views: { ...parentOptions.views, ...theme?.views, ...views },
28
+ slots: { ...parentOptions.slots, ...slots },
29
+ classes: { ...parentOptions.classes, ...theme?.classes, ...classes },
30
+ }), [parentOptions, theme, components, views, slots, classes]));
31
+ const trackerRef = useRef(null);
32
+ if (!trackerRef.current) {
33
+ const claimed = new Set();
34
+ const listeners = new Set();
35
+ let version = 0;
36
+ const notify = () => {
37
+ version++;
38
+ for (const l of listeners)
39
+ l();
40
+ };
41
+ trackerRef.current = {
42
+ claimed,
43
+ version,
44
+ listeners,
45
+ claim: (path) => {
46
+ if (!claimed.has(path)) {
47
+ claimed.add(path);
48
+ notify();
49
+ }
50
+ return () => {
51
+ if (claimed.delete(path))
52
+ notify();
53
+ };
54
+ },
55
+ subscribe: (listener) => {
56
+ listeners.add(listener);
57
+ return () => listeners.delete(listener);
58
+ },
59
+ getSnapshot: () => version,
60
+ };
61
+ }
62
+ return (_jsx(FormoOptionsContext.Provider, { value: mergedOptions, children: _jsx(FormoClaimedContext.Provider, { value: trackerRef.current, children: _jsx(FormoContext.Provider, { value: controller, children: _jsx("form", { noValidate: true, onSubmit: (e) => {
63
+ e.preventDefault();
64
+ void controller.submit();
65
+ }, ...rest, children: _jsx(FormoFormBody, { controller: controller, children: children }) }) }) }) }));
66
+ }
67
+ function FormoFormWithDef({ definition, options, theme, components, views, slots, classes, children, ...rest }) {
68
+ const controller = useFormo(definition, options);
69
+ return (_jsx(FormoFormProviders, { controller: controller, theme: theme, components: components, views: views, slots: slots, classes: classes, ...rest, children: children }));
70
+ }
71
+ export function FormoForm({ form, options, config, theme, components, views, slots, classes, children, ...rest }) {
72
+ if (!isController(form)) {
73
+ return (_jsx(FormoFormWithDef, { definition: form, options: config ? { ...options, config: { ...config, ...options?.config } } : options, theme: theme, components: components, views: views, slots: slots, classes: classes, ...rest, children: children }));
74
+ }
75
+ return (_jsx(FormoFormProviders, { controller: form, theme: theme, components: components, views: views, slots: slots, classes: classes, ...rest, children: children }));
76
+ }
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import type { FormoGroupHandle } from '../types';
3
+ export declare function FormoGroup({ group }: {
4
+ group: FormoGroupHandle;
5
+ }): React.JSX.Element | null;
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useFormoField } from '../hooks/subscriptions';
3
+ import { FormoErrors } from './FormoErrors';
4
+ import { FormoField } from './FormoField';
5
+ export function FormoGroup({ group }) {
6
+ const live = useFormoField(group);
7
+ if (!live.node.render)
8
+ return null;
9
+ return (_jsxs("fieldset", { style: {
10
+ border: '1px solid #e5e7eb',
11
+ borderRadius: 8,
12
+ padding: 16,
13
+ margin: '0 0 16px',
14
+ }, children: [live.node.label ? (_jsx("legend", { style: { fontSize: 14, fontWeight: 600, padding: '0 6px', color: '#111827' }, children: live.node.label })) : null, _jsx("div", { style: { display: 'flex', flexDirection: 'column', gap: 12 }, children: Object.values(group.fields).map((child) => (_jsx(FormoField, { field: child }, child.path))) }), _jsx(FormoErrors, { field: live })] }));
15
+ }
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import type { FormoFieldHandle } from '../types';
3
+ export interface FormoHelpProps extends React.HTMLAttributes<HTMLParagraphElement> {
4
+ field?: FormoFieldHandle;
5
+ }
6
+ export declare function FormoHelp({ field: propField, style, children, ...rest }: FormoHelpProps): React.JSX.Element | null;
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useFormoField } from '../hooks/subscriptions';
3
+ import { useFieldProp } from './FormoContext';
4
+ export function FormoHelp({ field: propField, style, children, ...rest }) {
5
+ const field = useFormoField(useFieldProp(propField));
6
+ if (!field.node.message && !children)
7
+ return null;
8
+ return (_jsx("p", { style: { margin: '4px 0 0', fontSize: 12, color: '#6b7280', ...style }, ...rest, children: children ?? field.node.message }));
9
+ }
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import type { FormoFieldHandle } from '../types';
3
+ export interface FormoInputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'value' | 'onChange' | 'onBlur'> {
4
+ field?: FormoFieldHandle;
5
+ }
6
+ export declare function FormoInput({ field: propField, id, className, style, ...rest }: FormoInputProps): React.JSX.Element;
@@ -0,0 +1,24 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useFormoField } from '../hooks/subscriptions';
3
+ import { useClaimField, useFieldProp } from './FormoContext';
4
+ export function FormoInput({ field: propField, id, className, style, ...rest }) {
5
+ const resolved = useFieldProp(propField);
6
+ useClaimField(resolved.path, !!propField);
7
+ const field = useFormoField(resolved);
8
+ const { node } = field;
9
+ const value = field.value == null ? '' : String(field.value);
10
+ const sharedStyle = {
11
+ display: 'block',
12
+ width: '100%',
13
+ padding: '8px 12px',
14
+ borderRadius: 6,
15
+ border: `1px solid ${field.invalid ? '#ef4444' : '#d1d5db'}`,
16
+ fontSize: 14,
17
+ boxSizing: 'border-box',
18
+ ...style,
19
+ };
20
+ if (node.driver === 'textarea') {
21
+ return (_jsx("textarea", { id: id ?? field.path, name: field.path, value: value, onChange: (e) => field.setValue(e.target.value), onBlur: () => field.setBlur(), disabled: field.disabled, readOnly: !field.editable, placeholder: node.placeholder, "aria-invalid": field.invalid || undefined, className: className, style: { minHeight: 90, resize: 'vertical', ...sharedStyle } }));
22
+ }
23
+ return (_jsx("input", { id: id ?? field.path, name: field.path, type: node.type || 'text', value: value, onChange: (e) => field.setValue(e.target.value), onBlur: () => field.setBlur(), disabled: field.disabled, readOnly: !field.editable, placeholder: node.placeholder, "aria-invalid": field.invalid || undefined, className: className, style: sharedStyle, ...rest }));
24
+ }
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import type { FormoFieldHandle } from '../types';
3
+ export interface FormoLabelProps extends React.LabelHTMLAttributes<HTMLLabelElement> {
4
+ field?: FormoFieldHandle;
5
+ }
6
+ export declare function FormoLabel({ field: propField, htmlFor, style, children, ...rest }: FormoLabelProps): React.JSX.Element | null;
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useFormoField } from '../hooks/subscriptions';
3
+ import { useFieldProp } from './FormoContext';
4
+ export function FormoLabel({ field: propField, htmlFor, style, children, ...rest }) {
5
+ const field = useFormoField(useFieldProp(propField));
6
+ if (!field.node.label && !children)
7
+ return null;
8
+ return (_jsx("label", { htmlFor: htmlFor ?? field.path, style: { display: 'block', fontSize: 14, fontWeight: 500, marginBottom: 6, color: '#111827', ...style }, ...rest, children: children ?? (_jsxs(_Fragment, { children: [field.node.label, field.required && field.editable ? _jsx("span", { style: { color: '#ef4444' }, children: " *" }) : null] })) }));
9
+ }
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import type { ComponentRef, FormoFieldHandle, FormoFieldSlots, FormoTheme, FormoViews } from '../types';
3
+ export interface FormoProviderProps {
4
+ theme?: FormoTheme;
5
+ components?: Record<string, ComponentRef>;
6
+ views?: FormoViews;
7
+ slots?: Record<string, FormoFieldSlots | ((field: FormoFieldHandle) => React.ReactNode)>;
8
+ classes?: Record<string, string>;
9
+ children: React.ReactNode;
10
+ }
11
+ export declare function FormoProvider({ theme, components, views, slots, classes, children }: FormoProviderProps): React.JSX.Element;
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useMemo } from 'react';
3
+ import { FormoOptionsContext, useFormoOptions, useStableLayerOptions } from './FormoContext';
4
+ export function FormoProvider({ theme, components, views, slots, classes, children }) {
5
+ const parent = useFormoOptions();
6
+ const merged = useStableLayerOptions(useMemo(() => ({
7
+ components: { ...parent.components, ...theme?.components, ...components },
8
+ views: { ...parent.views, ...theme?.views, ...views },
9
+ slots: { ...parent.slots, ...slots },
10
+ classes: { ...parent.classes, ...theme?.classes, ...classes },
11
+ }), [parent, theme, components, views, slots, classes]));
12
+ return _jsx(FormoOptionsContext.Provider, { value: merged, children: children });
13
+ }
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import type { FormoGroupHandle } from '../types';
3
+ export interface FormoRestProps {
4
+ group?: FormoGroupHandle;
5
+ }
6
+ export declare function FormoRest({ group }: FormoRestProps): React.JSX.Element;
@@ -0,0 +1,23 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useContext, useSyncExternalStore } from 'react';
3
+ import { useFormoFields } from '../hooks/subscriptions';
4
+ import { FormoClaimedContext, FormoInsideRestContext, useFormoContext } from './FormoContext';
5
+ import { FormoField } from './FormoField';
6
+ const noopSubscribe = () => () => { };
7
+ const zeroSnapshot = () => 0;
8
+ export function FormoRest({ group }) {
9
+ const form = useFormoContext();
10
+ const tracker = useContext(FormoClaimedContext);
11
+ useSyncExternalStore(tracker?.subscribe ?? noopSubscribe, tracker?.getSnapshot ?? zeroSnapshot, tracker?.getSnapshot ?? zeroSnapshot);
12
+ const topFields = useFormoFields(form);
13
+ const fields = group ? group.fields : topFields;
14
+ const claimed = tracker?.claimed ?? new Set();
15
+ return (_jsx(FormoInsideRestContext.Provider, { value: true, children: Object.values(fields).map((field) => {
16
+ if (claimed.has(field.path))
17
+ return null;
18
+ if (field.kind === 'blueprint' && [...claimed].some((p) => p.startsWith(`${field.path}[`))) {
19
+ return null;
20
+ }
21
+ return _jsx(FormoField, { field: field }, field.path);
22
+ }) }));
23
+ }
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import type { FormoFieldHandle } from '../types';
3
+ export interface FormoSelectProps extends Omit<React.SelectHTMLAttributes<HTMLSelectElement>, 'value' | 'onChange' | 'onBlur'> {
4
+ field?: FormoFieldHandle;
5
+ }
6
+ export declare function FormoSelect({ field: propField, id, className, style, ...rest }: FormoSelectProps): React.JSX.Element;
@@ -0,0 +1,36 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { isOptionGroup } from '../core/options';
3
+ import { useFormoField } from '../hooks/subscriptions';
4
+ import { useClaimField, useFieldProp } from './FormoContext';
5
+ export function FormoSelect({ field: propField, id, className, style, ...rest }) {
6
+ const resolved = useFieldProp(propField);
7
+ useClaimField(resolved.path, !!propField);
8
+ const field = useFormoField(resolved);
9
+ const multiple = field.node.driver === 'multiple' || Boolean(field.node.attr?.multiple);
10
+ const items = field.node.options;
11
+ const value = multiple
12
+ ? Array.isArray(field.value)
13
+ ? field.value.map(String)
14
+ : []
15
+ : field.value == null
16
+ ? ''
17
+ : String(field.value);
18
+ return (_jsxs("select", { id: id ?? field.path, name: field.path, multiple: multiple, value: value, disabled: field.disabled || !field.editable, "aria-invalid": field.invalid || undefined, onChange: (e) => {
19
+ if (multiple) {
20
+ const selected = Array.from(e.target.selectedOptions).map((o) => o.value);
21
+ field.setValue(selected);
22
+ }
23
+ else {
24
+ field.setValue(e.target.value);
25
+ }
26
+ }, onBlur: () => field.setBlur(), className: className, style: {
27
+ display: 'block',
28
+ width: '100%',
29
+ padding: '8px 12px',
30
+ borderRadius: 6,
31
+ border: `1px solid ${field.invalid ? '#ef4444' : '#d1d5db'}`,
32
+ fontSize: 14,
33
+ boxSizing: 'border-box',
34
+ ...style,
35
+ }, ...rest, children: [!multiple && field.node.blank !== false && (_jsx("option", { value: "", children: typeof field.node.blank === 'string' ? field.node.blank : 'Select...' })), items.map((item, idx) => isOptionGroup(item) ? (_jsx("optgroup", { label: item.label, children: item.options.map((opt) => (_jsx("option", { value: String(opt.value), disabled: opt.disabled, children: opt.label }, String(opt.value)))) }, `${item.label}-${idx}`)) : (_jsx("option", { value: String(item.value), disabled: item.disabled, children: item.label }, String(item.value))))] }));
36
+ }
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import type { FormoFieldHandle } from '../types';
3
+ export declare function readOnlyText(field: FormoFieldHandle): string;
4
+ export declare function FormoUneditable({ field: propField }: {
5
+ field?: FormoFieldHandle;
6
+ }): React.JSX.Element;
@@ -0,0 +1,12 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { displayValue } from '../core/options';
3
+ import { uiStrings } from '../core/messages';
4
+ import { useFormoField } from '../hooks/subscriptions';
5
+ import { useFieldProp } from './FormoContext';
6
+ export function readOnlyText(field) {
7
+ return displayValue(field.node, field.value) || uiStrings.empty;
8
+ }
9
+ export function FormoUneditable({ field: propField }) {
10
+ const field = useFormoField(useFieldProp(propField));
11
+ return _jsx("p", { style: { margin: '4px 0', fontSize: 14, color: '#374151' }, children: readOnlyText(field) });
12
+ }
@@ -0,0 +1,42 @@
1
+ import type { FieldDef } from '../types';
2
+ import { type FormFromModelOptions } from '../schema/form';
3
+ import type { FormoModel } from '../schema/ir';
4
+ /**
5
+ * Minimal React Native port of Formo's fluent form builder.
6
+ * Pure TypeScript — no React or React Native imports.
7
+ */
8
+ export declare class Formo {
9
+ #private;
10
+ static form(def?: FieldDef | string): Formo;
11
+ static group(alias?: string | FieldDef, def?: FieldDef): Formo;
12
+ static fromModel(model: FormoModel, options?: FormFromModelOptions): Formo;
13
+ constructor(def?: FieldDef | string);
14
+ alias(): string | number | undefined;
15
+ /**
16
+ * Add a field or subform (formo-vue's signatures):
17
+ *
18
+ * add('username')
19
+ * add('notes', 'textarea', 'My notes')
20
+ * add('email', 'input|email', { required: true }) // 3rd arg object = options
21
+ * add('hobbies', 'checkboxes', ['run'], { opts }) // alias, driver, val, opts
22
+ * add('notes', { driver: 'textarea', val: 'My notes' })
23
+ * add('address', Formo.form().add('street')) // subform (a form added to a form is a group)
24
+ * add(Formo.group('phones').add('number').padBlueprint(1)) // repeatable rows
25
+ */
26
+ add(aliasOrField: string | number | FieldDef | Formo, driver?: string | FieldDef | Formo, valOrOpts?: unknown, opts?: FieldDef | Formo): this;
27
+ /**
28
+ * Fields that rely on options (select, radios, checkboxes):
29
+ * addGroup('hobby', 'select', { run: 'Running' }, 'run', { label: 'Hobby' })
30
+ */
31
+ addGroup(alias: string, driver: string, opts: FieldDef['opts'], val?: unknown, settings?: FieldDef): this;
32
+ /**
33
+ * Blueprints: make this group repeatable, optionally pre-filled:
34
+ * Formo.group('phones').add('number').padBlueprint(2)
35
+ * Formo.group('phones').add('number').padBlueprint([{ number: '555-1234' }])
36
+ */
37
+ padBlueprint(countOrRows?: number | Array<Record<string, unknown>>): this;
38
+ find(alias: string): Formo | undefined;
39
+ remove(alias: string): this;
40
+ set(key: string, value: unknown): this;
41
+ toSchema(): FieldDef;
42
+ }