@form-os/react 0.1.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 +21 -0
- package/dist/Field-Bq9-eB99.d.cts +15 -0
- package/dist/Field-Bq9-eB99.d.ts +15 -0
- package/dist/chunk-CYMOPAGJ.cjs +61 -0
- package/dist/chunk-CYMOPAGJ.cjs.map +1 -0
- package/dist/chunk-N346U2SM.js +61 -0
- package/dist/chunk-N346U2SM.js.map +1 -0
- package/dist/fields/index.cjs +272 -0
- package/dist/fields/index.cjs.map +1 -0
- package/dist/fields/index.d.cts +52 -0
- package/dist/fields/index.d.ts +52 -0
- package/dist/fields/index.js +272 -0
- package/dist/fields/index.js.map +1 -0
- package/dist/index.cjs +36 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +90 -0
- package/dist/index.d.ts +90 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Adam Beleko
|
|
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,15 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ComponentType } from 'react';
|
|
3
|
+
import { Control, RegisterOptions } from 'react-hook-form';
|
|
4
|
+
import { FieldConfig } from '@form-os/core';
|
|
5
|
+
|
|
6
|
+
interface FieldProps {
|
|
7
|
+
field: FieldConfig;
|
|
8
|
+
control: Control;
|
|
9
|
+
component?: ComponentType<any>;
|
|
10
|
+
rules?: RegisterOptions;
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
}
|
|
13
|
+
declare function Field({ field, control, component, rules, ...rest }: FieldProps): react.JSX.Element | null;
|
|
14
|
+
|
|
15
|
+
export { type FieldProps as F, Field as a };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ComponentType } from 'react';
|
|
3
|
+
import { Control, RegisterOptions } from 'react-hook-form';
|
|
4
|
+
import { FieldConfig } from '@form-os/core';
|
|
5
|
+
|
|
6
|
+
interface FieldProps {
|
|
7
|
+
field: FieldConfig;
|
|
8
|
+
control: Control;
|
|
9
|
+
component?: ComponentType<any>;
|
|
10
|
+
rules?: RegisterOptions;
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
}
|
|
13
|
+
declare function Field({ field, control, component, rules, ...rest }: FieldProps): react.JSX.Element | null;
|
|
14
|
+
|
|
15
|
+
export { type FieldProps as F, Field as a };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/useField.ts
|
|
2
|
+
var _react = require('react');
|
|
3
|
+
var _reacthookform = require('react-hook-form');
|
|
4
|
+
var _core = require('@form-os/core');
|
|
5
|
+
function useField(field, control, options = {}) {
|
|
6
|
+
const values = _reacthookform.useWatch.call(void 0, { control });
|
|
7
|
+
const state = _react.useMemo.call(void 0,
|
|
8
|
+
() => _core.getFieldState.call(void 0, field, _nullishCoalesce(values, () => ( {}))),
|
|
9
|
+
[field, values]
|
|
10
|
+
);
|
|
11
|
+
const { field: f, fieldState } = _reacthookform.useController.call(void 0, {
|
|
12
|
+
name: field.name,
|
|
13
|
+
control,
|
|
14
|
+
rules: _nullishCoalesce(options.rules, () => ( field.rules)),
|
|
15
|
+
defaultValue: _nullishCoalesce(options.defaultValue, () => ( field.defaultValue)),
|
|
16
|
+
disabled: state.disabled
|
|
17
|
+
});
|
|
18
|
+
return { field: f, fieldState, state };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// src/FormFieldsContext.tsx
|
|
22
|
+
|
|
23
|
+
var _jsxruntime = require('react/jsx-runtime');
|
|
24
|
+
var FormFieldsContext = _react.createContext.call(void 0, {});
|
|
25
|
+
function FormFieldsProvider({ components, children }) {
|
|
26
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, FormFieldsContext.Provider, { value: components, children });
|
|
27
|
+
}
|
|
28
|
+
function useFieldComponents() {
|
|
29
|
+
return _react.useContext.call(void 0, FormFieldsContext);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// src/Field.tsx
|
|
33
|
+
|
|
34
|
+
function Field({ field, control, component, rules, ...rest }) {
|
|
35
|
+
const contextComponents = useFieldComponents();
|
|
36
|
+
const Component = _nullishCoalesce(_nullishCoalesce(component, () => ( contextComponents[field.type])), () => ( contextComponents["text"]));
|
|
37
|
+
const { field: f, fieldState, state } = useField(field, control, { rules });
|
|
38
|
+
if (!state.visible) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
42
|
+
Component,
|
|
43
|
+
{
|
|
44
|
+
formField: f,
|
|
45
|
+
fieldConfig: field,
|
|
46
|
+
fieldState: state,
|
|
47
|
+
error: fieldState.error,
|
|
48
|
+
disabled: state.disabled,
|
|
49
|
+
readonly: state.readonly,
|
|
50
|
+
...rest
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
exports.useField = useField; exports.FormFieldsProvider = FormFieldsProvider; exports.useFieldComponents = useFieldComponents; exports.Field = Field;
|
|
61
|
+
//# sourceMappingURL=chunk-CYMOPAGJ.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/abeleko/Documents/larven/formjs/packages/react/dist/chunk-CYMOPAGJ.cjs","../src/useField.ts","../src/FormFieldsContext.tsx","../src/Field.tsx"],"names":["jsx"],"mappings":"AAAA;ACAA,8BAAwB;AACxB,gDAAwC;AAExC,qCAAgD;AAOzC,SAAS,QAAA,CACd,KAAA,EACA,OAAA,EACA,QAAA,EAA2B,CAAC,CAAA,EAC5B;AACA,EAAA,MAAM,OAAA,EAAS,qCAAA,EAAW,QAAQ,CAAC,CAAA;AAEnC,EAAA,MAAM,MAAA,EAAQ,4BAAA;AAAA,IACZ,CAAA,EAAA,GAAM,iCAAA,KAAc,mBAAO,MAAA,UAAU,CAAC,GAAC,CAAA;AAAA,IACvC,CAAC,KAAA,EAAO,MAAM;AAAA,EAChB,CAAA;AAEA,EAAA,MAAM,EAAE,KAAA,EAAO,CAAA,EAAG,WAAW,EAAA,EAAI,0CAAA;AAAc,IAC7C,IAAA,EAAM,KAAA,CAAM,IAAA;AAAA,IACZ,OAAA;AAAA,IACA,KAAA,mBAAO,OAAA,CAAQ,KAAA,UAAU,KAAA,CAAM,OAAA;AAAA,I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AW,KAAA;AAAA,MAClB,QAAA,EAAU,KAAA,CAAM,QAAA;AAAA,MAChB,QAAA,EAAU,KAAA,CAAM,QAAA;AAAA,MACf,GAAG;AAAA,IAAA;AAAA,EACN,CAAA;AAEJ;AHmBA;AACA;AACE;AACA;AACA;AACA;AACF,qJAAC","file":"/Users/abeleko/Documents/larven/formjs/packages/react/dist/chunk-CYMOPAGJ.cjs","sourcesContent":[null,"import { useMemo } from 'react';\nimport { useController, useWatch } from 'react-hook-form';\nimport type { Control, RegisterOptions } from 'react-hook-form';\nimport { getFieldState, type FieldConfig } from '@form-os/core';\n\nexport interface UseFieldOptions {\n rules?: RegisterOptions;\n defaultValue?: any;\n}\n\nexport function useField(\n field: FieldConfig,\n control: Control,\n options: UseFieldOptions = {}\n) {\n const values = useWatch({ control }) as Record<string, any>;\n\n const state = useMemo(\n () => getFieldState(field, values ?? {}),\n [field, values]\n );\n\n const { field: f, fieldState } = useController({\n name: field.name,\n control,\n rules: options.rules ?? (field.rules as RegisterOptions | undefined),\n defaultValue: options.defaultValue ?? field.defaultValue,\n disabled: state.disabled,\n });\n\n return { field: f, fieldState, state };\n}\n","import { createContext, useContext } from 'react';\nimport type { ComponentType, ReactNode } from 'react';\n\nexport type ComponentsMap = Record<string, ComponentType<any>>;\n\nconst FormFieldsContext = createContext<ComponentsMap>({});\n\nexport interface FormFieldsProviderProps {\n components: ComponentsMap;\n children: ReactNode;\n}\n\nexport function FormFieldsProvider({ components, children }: FormFieldsProviderProps) {\n return (\n <FormFieldsContext.Provider value={components}>\n {children}\n </FormFieldsContext.Provider>\n );\n}\n\nexport function useFieldComponents(): ComponentsMap {\n return useContext(FormFieldsContext);\n}\n","import type { ComponentType } from 'react';\nimport type { Control, RegisterOptions } from 'react-hook-form';\nimport type { FieldConfig } from '@form-os/core';\nimport { useField } from './useField';\nimport { useFieldComponents } from './FormFieldsContext';\n\nexport interface FieldProps {\n field: FieldConfig;\n control: Control;\n component?: ComponentType<any>;\n rules?: RegisterOptions;\n [key: string]: any;\n}\n\nexport function Field({ field, control, component, rules, ...rest }: FieldProps) {\n const contextComponents = useFieldComponents();\n const Component = component ?? contextComponents[field.type] ?? contextComponents['text'];\n const { field: f, fieldState, state } = useField(field, control, { rules });\n\n if (!state.visible) {\n return null;\n }\n\n return (\n <Component\n formField={f}\n fieldConfig={field}\n fieldState={state}\n error={fieldState.error}\n disabled={state.disabled}\n readonly={state.readonly}\n {...rest}\n />\n );\n}\n"]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// src/useField.ts
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { useController, useWatch } from "react-hook-form";
|
|
4
|
+
import { getFieldState } from "@form-os/core";
|
|
5
|
+
function useField(field, control, options = {}) {
|
|
6
|
+
const values = useWatch({ control });
|
|
7
|
+
const state = useMemo(
|
|
8
|
+
() => getFieldState(field, values ?? {}),
|
|
9
|
+
[field, values]
|
|
10
|
+
);
|
|
11
|
+
const { field: f, fieldState } = useController({
|
|
12
|
+
name: field.name,
|
|
13
|
+
control,
|
|
14
|
+
rules: options.rules ?? field.rules,
|
|
15
|
+
defaultValue: options.defaultValue ?? field.defaultValue,
|
|
16
|
+
disabled: state.disabled
|
|
17
|
+
});
|
|
18
|
+
return { field: f, fieldState, state };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// src/FormFieldsContext.tsx
|
|
22
|
+
import { createContext, useContext } from "react";
|
|
23
|
+
import { jsx } from "react/jsx-runtime";
|
|
24
|
+
var FormFieldsContext = createContext({});
|
|
25
|
+
function FormFieldsProvider({ components, children }) {
|
|
26
|
+
return /* @__PURE__ */ jsx(FormFieldsContext.Provider, { value: components, children });
|
|
27
|
+
}
|
|
28
|
+
function useFieldComponents() {
|
|
29
|
+
return useContext(FormFieldsContext);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// src/Field.tsx
|
|
33
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
34
|
+
function Field({ field, control, component, rules, ...rest }) {
|
|
35
|
+
const contextComponents = useFieldComponents();
|
|
36
|
+
const Component = component ?? contextComponents[field.type] ?? contextComponents["text"];
|
|
37
|
+
const { field: f, fieldState, state } = useField(field, control, { rules });
|
|
38
|
+
if (!state.visible) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
return /* @__PURE__ */ jsx2(
|
|
42
|
+
Component,
|
|
43
|
+
{
|
|
44
|
+
formField: f,
|
|
45
|
+
fieldConfig: field,
|
|
46
|
+
fieldState: state,
|
|
47
|
+
error: fieldState.error,
|
|
48
|
+
disabled: state.disabled,
|
|
49
|
+
readonly: state.readonly,
|
|
50
|
+
...rest
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export {
|
|
56
|
+
useField,
|
|
57
|
+
FormFieldsProvider,
|
|
58
|
+
useFieldComponents,
|
|
59
|
+
Field
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=chunk-N346U2SM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/useField.ts","../src/FormFieldsContext.tsx","../src/Field.tsx"],"sourcesContent":["import { useMemo } from 'react';\nimport { useController, useWatch } from 'react-hook-form';\nimport type { Control, RegisterOptions } from 'react-hook-form';\nimport { getFieldState, type FieldConfig } from '@form-os/core';\n\nexport interface UseFieldOptions {\n rules?: RegisterOptions;\n defaultValue?: any;\n}\n\nexport function useField(\n field: FieldConfig,\n control: Control,\n options: UseFieldOptions = {}\n) {\n const values = useWatch({ control }) as Record<string, any>;\n\n const state = useMemo(\n () => getFieldState(field, values ?? {}),\n [field, values]\n );\n\n const { field: f, fieldState } = useController({\n name: field.name,\n control,\n rules: options.rules ?? (field.rules as RegisterOptions | undefined),\n defaultValue: options.defaultValue ?? field.defaultValue,\n disabled: state.disabled,\n });\n\n return { field: f, fieldState, state };\n}\n","import { createContext, useContext } from 'react';\nimport type { ComponentType, ReactNode } from 'react';\n\nexport type ComponentsMap = Record<string, ComponentType<any>>;\n\nconst FormFieldsContext = createContext<ComponentsMap>({});\n\nexport interface FormFieldsProviderProps {\n components: ComponentsMap;\n children: ReactNode;\n}\n\nexport function FormFieldsProvider({ components, children }: FormFieldsProviderProps) {\n return (\n <FormFieldsContext.Provider value={components}>\n {children}\n </FormFieldsContext.Provider>\n );\n}\n\nexport function useFieldComponents(): ComponentsMap {\n return useContext(FormFieldsContext);\n}\n","import type { ComponentType } from 'react';\nimport type { Control, RegisterOptions } from 'react-hook-form';\nimport type { FieldConfig } from '@form-os/core';\nimport { useField } from './useField';\nimport { useFieldComponents } from './FormFieldsContext';\n\nexport interface FieldProps {\n field: FieldConfig;\n control: Control;\n component?: ComponentType<any>;\n rules?: RegisterOptions;\n [key: string]: any;\n}\n\nexport function Field({ field, control, component, rules, ...rest }: FieldProps) {\n const contextComponents = useFieldComponents();\n const Component = component ?? contextComponents[field.type] ?? contextComponents['text'];\n const { field: f, fieldState, state } = useField(field, control, { rules });\n\n if (!state.visible) {\n return null;\n }\n\n return (\n <Component\n formField={f}\n fieldConfig={field}\n fieldState={state}\n error={fieldState.error}\n disabled={state.disabled}\n readonly={state.readonly}\n {...rest}\n />\n );\n}\n"],"mappings":";AAAA,SAAS,eAAe;AACxB,SAAS,eAAe,gBAAgB;AAExC,SAAS,qBAAuC;AAOzC,SAAS,SACd,OACA,SACA,UAA2B,CAAC,GAC5B;AACA,QAAM,SAAS,SAAS,EAAE,QAAQ,CAAC;AAEnC,QAAM,QAAQ;AAAA,IACZ,MAAM,cAAc,OAAO,UAAU,CAAC,CAAC;AAAA,IACvC,CAAC,OAAO,MAAM;AAAA,EAChB;AAEA,QAAM,EAAE,OAAO,GAAG,WAAW,IAAI,cAAc;AAAA,IAC7C,MAAM,MAAM;AAAA,IACZ;AAAA,IACA,OAAO,QAAQ,SAAU,MAAM;AAAA,IAC/B,cAAc,QAAQ,gBAAgB,MAAM;AAAA,IAC5C,UAAU,MAAM;AAAA,EAClB,CAAC;AAED,SAAO,EAAE,OAAO,GAAG,YAAY,MAAM;AACvC;;;AC/BA,SAAS,eAAe,kBAAkB;AActC;AATJ,IAAM,oBAAoB,cAA6B,CAAC,CAAC;AAOlD,SAAS,mBAAmB,EAAE,YAAY,SAAS,GAA4B;AACpF,SACE,oBAAC,kBAAkB,UAAlB,EAA2B,OAAO,YAChC,UACH;AAEJ;AAEO,SAAS,qBAAoC;AAClD,SAAO,WAAW,iBAAiB;AACrC;;;ACEI,gBAAAA,YAAA;AAVG,SAAS,MAAM,EAAE,OAAO,SAAS,WAAW,OAAO,GAAG,KAAK,GAAe;AAC/E,QAAM,oBAAoB,mBAAmB;AAC7C,QAAM,YAAY,aAAa,kBAAkB,MAAM,IAAI,KAAK,kBAAkB,MAAM;AACxF,QAAM,EAAE,OAAO,GAAG,YAAY,MAAM,IAAI,SAAS,OAAO,SAAS,EAAE,MAAM,CAAC;AAE1E,MAAI,CAAC,MAAM,SAAS;AAClB,WAAO;AAAA,EACT;AAEA,SACE,gBAAAA;AAAA,IAAC;AAAA;AAAA,MACC,WAAW;AAAA,MACX,aAAa;AAAA,MACb,YAAY;AAAA,MACZ,OAAO,WAAW;AAAA,MAClB,UAAU,MAAM;AAAA,MAChB,UAAU,MAAM;AAAA,MACf,GAAG;AAAA;AAAA,EACN;AAEJ;","names":["jsx"]}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunkCYMOPAGJcjs = require('../chunk-CYMOPAGJ.cjs');
|
|
4
|
+
|
|
5
|
+
// src/fields/TextField.tsx
|
|
6
|
+
var _jsxruntime = require('react/jsx-runtime');
|
|
7
|
+
function TextField({
|
|
8
|
+
formField,
|
|
9
|
+
fieldConfig,
|
|
10
|
+
className,
|
|
11
|
+
...rest
|
|
12
|
+
}) {
|
|
13
|
+
const { ref, ...field } = formField;
|
|
14
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
15
|
+
"input",
|
|
16
|
+
{
|
|
17
|
+
ref,
|
|
18
|
+
...field,
|
|
19
|
+
type: "text",
|
|
20
|
+
placeholder: fieldConfig.placeholder,
|
|
21
|
+
className,
|
|
22
|
+
...rest
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/fields/NumberField.tsx
|
|
28
|
+
|
|
29
|
+
function NumberField({
|
|
30
|
+
formField,
|
|
31
|
+
fieldConfig,
|
|
32
|
+
className,
|
|
33
|
+
...rest
|
|
34
|
+
}) {
|
|
35
|
+
const { ref, ...field } = formField;
|
|
36
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
37
|
+
"input",
|
|
38
|
+
{
|
|
39
|
+
ref,
|
|
40
|
+
...field,
|
|
41
|
+
type: "number",
|
|
42
|
+
min: _optionalChain([fieldConfig, 'access', _ => _.rules, 'optionalAccess', _2 => _2.min]),
|
|
43
|
+
max: _optionalChain([fieldConfig, 'access', _3 => _3.rules, 'optionalAccess', _4 => _4.max]),
|
|
44
|
+
placeholder: fieldConfig.placeholder,
|
|
45
|
+
className,
|
|
46
|
+
...rest
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/fields/EmailField.tsx
|
|
52
|
+
|
|
53
|
+
function EmailField({
|
|
54
|
+
formField,
|
|
55
|
+
fieldConfig,
|
|
56
|
+
className,
|
|
57
|
+
...rest
|
|
58
|
+
}) {
|
|
59
|
+
const { ref, ...field } = formField;
|
|
60
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
61
|
+
"input",
|
|
62
|
+
{
|
|
63
|
+
ref,
|
|
64
|
+
...field,
|
|
65
|
+
type: "email",
|
|
66
|
+
placeholder: fieldConfig.placeholder,
|
|
67
|
+
className,
|
|
68
|
+
...rest
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/fields/PasswordField.tsx
|
|
74
|
+
|
|
75
|
+
function PasswordField({
|
|
76
|
+
formField,
|
|
77
|
+
fieldConfig,
|
|
78
|
+
className,
|
|
79
|
+
...rest
|
|
80
|
+
}) {
|
|
81
|
+
const { ref, ...field } = formField;
|
|
82
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
83
|
+
"input",
|
|
84
|
+
{
|
|
85
|
+
ref,
|
|
86
|
+
...field,
|
|
87
|
+
type: "password",
|
|
88
|
+
placeholder: fieldConfig.placeholder,
|
|
89
|
+
className,
|
|
90
|
+
...rest
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/fields/TextAreaField.tsx
|
|
96
|
+
|
|
97
|
+
function TextAreaField({
|
|
98
|
+
formField,
|
|
99
|
+
fieldConfig,
|
|
100
|
+
className,
|
|
101
|
+
...rest
|
|
102
|
+
}) {
|
|
103
|
+
const { ref, ...field } = formField;
|
|
104
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
105
|
+
"textarea",
|
|
106
|
+
{
|
|
107
|
+
ref,
|
|
108
|
+
...field,
|
|
109
|
+
rows: _nullishCoalesce(_optionalChain([fieldConfig, 'access', _5 => _5.props, 'optionalAccess', _6 => _6.rows]), () => ( 3)),
|
|
110
|
+
placeholder: fieldConfig.placeholder,
|
|
111
|
+
className,
|
|
112
|
+
...rest
|
|
113
|
+
}
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// src/fields/DateField.tsx
|
|
118
|
+
|
|
119
|
+
function DateField({
|
|
120
|
+
formField,
|
|
121
|
+
fieldConfig,
|
|
122
|
+
className,
|
|
123
|
+
...rest
|
|
124
|
+
}) {
|
|
125
|
+
const { ref, ...field } = formField;
|
|
126
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
127
|
+
"input",
|
|
128
|
+
{
|
|
129
|
+
ref,
|
|
130
|
+
...field,
|
|
131
|
+
type: "date",
|
|
132
|
+
placeholder: fieldConfig.placeholder,
|
|
133
|
+
className,
|
|
134
|
+
...rest
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// src/fields/SelectField.tsx
|
|
140
|
+
|
|
141
|
+
function SelectField({
|
|
142
|
+
formField,
|
|
143
|
+
fieldConfig,
|
|
144
|
+
className,
|
|
145
|
+
...rest
|
|
146
|
+
}) {
|
|
147
|
+
const { ref, ...field } = formField;
|
|
148
|
+
const multiple = !!_optionalChain([fieldConfig, 'access', _7 => _7.props, 'optionalAccess', _8 => _8.multiple]);
|
|
149
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
150
|
+
"select",
|
|
151
|
+
{
|
|
152
|
+
ref,
|
|
153
|
+
...field,
|
|
154
|
+
multiple,
|
|
155
|
+
className,
|
|
156
|
+
...rest,
|
|
157
|
+
children: _optionalChain([fieldConfig, 'access', _9 => _9.options, 'optionalAccess', _10 => _10.map, 'call', _11 => _11((opt) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "option", { value: opt.value, children: opt.label }, opt.value))])
|
|
158
|
+
}
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// src/fields/CheckboxField.tsx
|
|
163
|
+
|
|
164
|
+
function CheckboxField({
|
|
165
|
+
formField,
|
|
166
|
+
fieldConfig,
|
|
167
|
+
className,
|
|
168
|
+
...rest
|
|
169
|
+
}) {
|
|
170
|
+
const { ref, value, ...field } = formField;
|
|
171
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
172
|
+
"input",
|
|
173
|
+
{
|
|
174
|
+
ref,
|
|
175
|
+
type: "checkbox",
|
|
176
|
+
checked: !!value,
|
|
177
|
+
...field,
|
|
178
|
+
onChange: (e) => field.onChange(e.target.checked),
|
|
179
|
+
className,
|
|
180
|
+
...rest
|
|
181
|
+
}
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// src/fields/RadioField.tsx
|
|
186
|
+
|
|
187
|
+
function RadioField({
|
|
188
|
+
formField,
|
|
189
|
+
fieldConfig,
|
|
190
|
+
className,
|
|
191
|
+
...rest
|
|
192
|
+
}) {
|
|
193
|
+
const { ref, onChange, onBlur, name, value } = formField;
|
|
194
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className, ...rest, children: _optionalChain([fieldConfig, 'access', _12 => _12.options, 'optionalAccess', _13 => _13.map, 'call', _14 => _14((opt) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "label", { children: [
|
|
195
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
196
|
+
"input",
|
|
197
|
+
{
|
|
198
|
+
type: "radio",
|
|
199
|
+
name,
|
|
200
|
+
value: opt.value,
|
|
201
|
+
checked: value === opt.value,
|
|
202
|
+
onChange: () => onChange(opt.value),
|
|
203
|
+
onBlur,
|
|
204
|
+
ref: value === opt.value ? ref : void 0
|
|
205
|
+
}
|
|
206
|
+
),
|
|
207
|
+
opt.label
|
|
208
|
+
] }, opt.value))]) });
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// src/fields/SwitchField.tsx
|
|
212
|
+
|
|
213
|
+
function SwitchField({
|
|
214
|
+
formField,
|
|
215
|
+
fieldConfig,
|
|
216
|
+
className,
|
|
217
|
+
...rest
|
|
218
|
+
}) {
|
|
219
|
+
const { ref, value, ...field } = formField;
|
|
220
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
221
|
+
"input",
|
|
222
|
+
{
|
|
223
|
+
ref,
|
|
224
|
+
type: "checkbox",
|
|
225
|
+
role: "switch",
|
|
226
|
+
checked: !!value,
|
|
227
|
+
...field,
|
|
228
|
+
onChange: (e) => field.onChange(e.target.checked),
|
|
229
|
+
className,
|
|
230
|
+
...rest
|
|
231
|
+
}
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// src/fields/defaultComponents.ts
|
|
236
|
+
var defaultComponents = {
|
|
237
|
+
text: TextField,
|
|
238
|
+
number: NumberField,
|
|
239
|
+
email: EmailField,
|
|
240
|
+
password: PasswordField,
|
|
241
|
+
textarea: TextAreaField,
|
|
242
|
+
date: DateField,
|
|
243
|
+
select: SelectField,
|
|
244
|
+
checkbox: CheckboxField,
|
|
245
|
+
radio: RadioField,
|
|
246
|
+
switch: SwitchField
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
// src/fields/DefaultField.tsx
|
|
250
|
+
|
|
251
|
+
function DefaultField({
|
|
252
|
+
field,
|
|
253
|
+
control,
|
|
254
|
+
...rest
|
|
255
|
+
}) {
|
|
256
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkCYMOPAGJcjs.Field, { field, control, components: defaultComponents, ...rest });
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
exports.CheckboxField = CheckboxField; exports.DateField = DateField; exports.DefaultField = DefaultField; exports.EmailField = EmailField; exports.NumberField = NumberField; exports.PasswordField = PasswordField; exports.RadioField = RadioField; exports.SelectField = SelectField; exports.SwitchField = SwitchField; exports.TextAreaField = TextAreaField; exports.TextField = TextField; exports.defaultComponents = defaultComponents;
|
|
272
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/abeleko/Documents/larven/formjs/packages/react/dist/fields/index.cjs","../../src/fields/TextField.tsx","../../src/fields/NumberField.tsx","../../src/fields/EmailField.tsx","../../src/fields/PasswordField.tsx","../../src/fields/TextAreaField.tsx","../../src/fields/DateField.tsx","../../src/fields/SelectField.tsx","../../src/fields/CheckboxField.tsx","../../src/fields/RadioField.tsx","../../src/fields/SwitchField.tsx","../../src/fields/defaultComponents.ts","../../src/fields/DefaultField.tsx"],"names":["jsx"],"mappings":"AAAA;AACE;AACF,yDAA8B;AAC9B;AACA;ACMI,+CAAA;AARG,SAAS,SAAA,CAAU;AAAA,EACxB,SAAA;AAAA,EACA,WAAA;AAAA,EACA,SAAA;AAAA,EACA,GAAG;AACL,CAAA,EAAwB;AACtB,EAAA,MAAM,EAAE,GAAA,EAAK,GAAG,MAAM,EAAA,EAAI,SAAA;AAC1B,EAAA,uBACE,6BAAA;AAAA,IAAC,OAAA;AAAA,IAAA;AAAA,MACC,GAAA;AAAA,MACC,GAAG,KAAA;AAAA,MACJ,IAAA,EAAK,MAAA;AAAA,MACL,WAAA,EAAa,WAAA,CAAY,WAAA;AAAA,MACzB,SAAA;AAAA,MACC,GAAG;AAAA,IAAA;AAAA,EACN,CAAA;AAEJ;ADMA;AACA;AEhBI;AARG,SAAS,WAAA,CAAY;AAAA,EAC1B,SAAA;AAAA,EACA,WAAA;AAAA,EACA,SAAA;AAAA,EACA,GAAG;AACL,CAAA,EAAwB;AACtB,EAAA,MAAM,EAAE,GAAA,EAAK,GAAG,MAAM,EAAA,EAAI,SAAA;AAC1B,EAAA,uBACEA,6BAAAA;AAAA,IAAC,OAAA;AAAA,IAAA;AAAA,MACC,GAAA;AAAA,MACC,GAAG,KAAA;AAAA,MACJ,IAAA,EAAK,QAAA;AAAA,MACL,GAAA,kBAAK,WAAA,mBAAY,KAAA,6BAAO,KAAA;AAAA,MACxB,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AAQ,WAAA;AAAA,EACR,QAAA,EAAU,aAAA;AAAA,EACV,KAAA,EAAO,UAAA;AAAA,EACP,MAAA,EAAQ;AACV,CAAA;AXiOA;AACA;AYhPS;AALF,SAAS,YAAA,CAAa;AAAA,EAC3B,KAAA;AAAA,EACA,OAAA;AAAA,EACA,GAAG;AACL,CAAA,EAAmC;AACjC,EAAA,uBAAOA,6BAAAA,uBAAC,EAAA,EAAM,KAAA,EAAc,OAAA,EAAkB,UAAA,EAAY,iBAAA,EAAoB,GAAG,KAAA,CAAM,CAAA;AACzF;AZwPA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,ibAAC","file":"/Users/abeleko/Documents/larven/formjs/packages/react/dist/fields/index.cjs","sourcesContent":[null,"import type { FieldComponentProps } from './types';\n\nexport function TextField({\n formField,\n fieldConfig,\n className,\n ...rest\n}: FieldComponentProps) {\n const { ref, ...field } = formField;\n return (\n <input\n ref={ref}\n {...field}\n type=\"text\"\n placeholder={fieldConfig.placeholder}\n className={className}\n {...rest}\n />\n );\n}\n","import type { FieldComponentProps } from './types';\n\nexport function NumberField({\n formField,\n fieldConfig,\n className,\n ...rest\n}: FieldComponentProps) {\n const { ref, ...field } = formField;\n return (\n <input\n ref={ref}\n {...field}\n type=\"number\"\n min={fieldConfig.rules?.min}\n max={fieldConfig.rules?.max}\n placeholder={fieldConfig.placeholder}\n className={className}\n {...rest}\n />\n );\n}\n","import type { FieldComponentProps } from './types';\n\nexport function EmailField({\n formField,\n fieldConfig,\n className,\n ...rest\n}: FieldComponentProps) {\n const { ref, ...field } = formField;\n return (\n <input\n ref={ref}\n {...field}\n type=\"email\"\n placeholder={fieldConfig.placeholder}\n className={className}\n {...rest}\n />\n );\n}\n","import type { FieldComponentProps } from './types';\n\nexport function PasswordField({\n formField,\n fieldConfig,\n className,\n ...rest\n}: FieldComponentProps) {\n const { ref, ...field } = formField;\n return (\n <input\n ref={ref}\n {...field}\n type=\"password\"\n placeholder={fieldConfig.placeholder}\n className={className}\n {...rest}\n />\n );\n}\n","import type { FieldComponentProps } from './types';\n\nexport function TextAreaField({\n formField,\n fieldConfig,\n className,\n ...rest\n}: FieldComponentProps) {\n const { ref, ...field } = formField;\n return (\n <textarea\n ref={ref}\n {...field}\n rows={fieldConfig.props?.rows ?? 3}\n placeholder={fieldConfig.placeholder}\n className={className}\n {...rest}\n />\n );\n}\n","import type { FieldComponentProps } from './types';\n\nexport function DateField({\n formField,\n fieldConfig,\n className,\n ...rest\n}: FieldComponentProps) {\n const { ref, ...field } = formField;\n return (\n <input\n ref={ref}\n {...field}\n type=\"date\"\n placeholder={fieldConfig.placeholder}\n className={className}\n {...rest}\n />\n );\n}\n","import type { FieldComponentProps } from './types';\n\nexport function SelectField({\n formField,\n fieldConfig,\n className,\n ...rest\n}: FieldComponentProps) {\n const { ref, ...field } = formField;\n const multiple = !!fieldConfig.props?.multiple;\n\n return (\n <select\n ref={ref}\n {...field}\n multiple={multiple}\n className={className}\n {...rest}\n >\n {fieldConfig.options?.map((opt) => (\n <option key={opt.value} value={opt.value}>\n {opt.label}\n </option>\n ))}\n </select>\n );\n}\n","import type { FieldComponentProps } from './types';\n\nexport function CheckboxField({\n formField,\n fieldConfig,\n className,\n ...rest\n}: FieldComponentProps) {\n const { ref, value, ...field } = formField;\n return (\n <input\n ref={ref}\n type=\"checkbox\"\n checked={!!value}\n {...field}\n onChange={(e) => field.onChange(e.target.checked)}\n className={className}\n {...rest}\n />\n );\n}\n","import type { FieldComponentProps } from './types';\n\nexport function RadioField({\n formField,\n fieldConfig,\n className,\n ...rest\n}: FieldComponentProps) {\n const { ref, onChange, onBlur, name, value } = formField;\n\n return (\n <div className={className} {...rest}>\n {fieldConfig.options?.map((opt) => (\n <label key={opt.value}>\n <input\n type=\"radio\"\n name={name}\n value={opt.value}\n checked={value === opt.value}\n onChange={() => onChange(opt.value)}\n onBlur={onBlur}\n ref={value === opt.value ? ref : undefined}\n />\n {opt.label}\n </label>\n ))}\n </div>\n );\n}\n","import type { FieldComponentProps } from './types';\n\nexport function SwitchField({\n formField,\n fieldConfig,\n className,\n ...rest\n}: FieldComponentProps) {\n const { ref, value, ...field } = formField;\n return (\n <input\n ref={ref}\n type=\"checkbox\"\n role=\"switch\"\n checked={!!value}\n {...field}\n onChange={(e) => field.onChange(e.target.checked)}\n className={className}\n {...rest}\n />\n );\n}\n","import { TextField } from './TextField';\nimport { NumberField } from './NumberField';\nimport { EmailField } from './EmailField';\nimport { PasswordField } from './PasswordField';\nimport { TextAreaField } from './TextAreaField';\nimport { DateField } from './DateField';\nimport { SelectField } from './SelectField';\nimport { CheckboxField } from './CheckboxField';\nimport { RadioField } from './RadioField';\nimport { SwitchField } from './SwitchField';\n\nexport const defaultComponents = {\n text: TextField,\n number: NumberField,\n email: EmailField,\n password: PasswordField,\n textarea: TextAreaField,\n date: DateField,\n select: SelectField,\n checkbox: CheckboxField,\n radio: RadioField,\n switch: SwitchField,\n};\n","import { Field, type FieldProps } from '../Field';\nimport { defaultComponents } from './defaultComponents';\n\nexport function DefaultField({\n field,\n control,\n ...rest\n}: Omit<FieldProps, 'components'>) {\n return <Field field={field} control={control} components={defaultComponents} {...rest} />;\n}\n"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { FieldConfig, FieldState } from '@form-os/core';
|
|
2
|
+
import { ControllerRenderProps, FieldError } from 'react-hook-form';
|
|
3
|
+
import * as react from 'react';
|
|
4
|
+
import { F as FieldProps } from '../Field-Bq9-eB99.cjs';
|
|
5
|
+
|
|
6
|
+
interface FieldComponentProps {
|
|
7
|
+
formField: ControllerRenderProps;
|
|
8
|
+
fieldConfig: FieldConfig;
|
|
9
|
+
fieldState: FieldState;
|
|
10
|
+
error?: FieldError;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
readonly?: boolean;
|
|
13
|
+
className?: string;
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare function TextField({ formField, fieldConfig, className, ...rest }: FieldComponentProps): react.JSX.Element;
|
|
18
|
+
|
|
19
|
+
declare function NumberField({ formField, fieldConfig, className, ...rest }: FieldComponentProps): react.JSX.Element;
|
|
20
|
+
|
|
21
|
+
declare function EmailField({ formField, fieldConfig, className, ...rest }: FieldComponentProps): react.JSX.Element;
|
|
22
|
+
|
|
23
|
+
declare function PasswordField({ formField, fieldConfig, className, ...rest }: FieldComponentProps): react.JSX.Element;
|
|
24
|
+
|
|
25
|
+
declare function TextAreaField({ formField, fieldConfig, className, ...rest }: FieldComponentProps): react.JSX.Element;
|
|
26
|
+
|
|
27
|
+
declare function DateField({ formField, fieldConfig, className, ...rest }: FieldComponentProps): react.JSX.Element;
|
|
28
|
+
|
|
29
|
+
declare function SelectField({ formField, fieldConfig, className, ...rest }: FieldComponentProps): react.JSX.Element;
|
|
30
|
+
|
|
31
|
+
declare function CheckboxField({ formField, fieldConfig, className, ...rest }: FieldComponentProps): react.JSX.Element;
|
|
32
|
+
|
|
33
|
+
declare function RadioField({ formField, fieldConfig, className, ...rest }: FieldComponentProps): react.JSX.Element;
|
|
34
|
+
|
|
35
|
+
declare function SwitchField({ formField, fieldConfig, className, ...rest }: FieldComponentProps): react.JSX.Element;
|
|
36
|
+
|
|
37
|
+
declare const defaultComponents: {
|
|
38
|
+
text: typeof TextField;
|
|
39
|
+
number: typeof NumberField;
|
|
40
|
+
email: typeof EmailField;
|
|
41
|
+
password: typeof PasswordField;
|
|
42
|
+
textarea: typeof TextAreaField;
|
|
43
|
+
date: typeof DateField;
|
|
44
|
+
select: typeof SelectField;
|
|
45
|
+
checkbox: typeof CheckboxField;
|
|
46
|
+
radio: typeof RadioField;
|
|
47
|
+
switch: typeof SwitchField;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
declare function DefaultField({ field, control, ...rest }: Omit<FieldProps, 'components'>): react.JSX.Element;
|
|
51
|
+
|
|
52
|
+
export { CheckboxField, DateField, DefaultField, EmailField, type FieldComponentProps, NumberField, PasswordField, RadioField, SelectField, SwitchField, TextAreaField, TextField, defaultComponents };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { FieldConfig, FieldState } from '@form-os/core';
|
|
2
|
+
import { ControllerRenderProps, FieldError } from 'react-hook-form';
|
|
3
|
+
import * as react from 'react';
|
|
4
|
+
import { F as FieldProps } from '../Field-Bq9-eB99.js';
|
|
5
|
+
|
|
6
|
+
interface FieldComponentProps {
|
|
7
|
+
formField: ControllerRenderProps;
|
|
8
|
+
fieldConfig: FieldConfig;
|
|
9
|
+
fieldState: FieldState;
|
|
10
|
+
error?: FieldError;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
readonly?: boolean;
|
|
13
|
+
className?: string;
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare function TextField({ formField, fieldConfig, className, ...rest }: FieldComponentProps): react.JSX.Element;
|
|
18
|
+
|
|
19
|
+
declare function NumberField({ formField, fieldConfig, className, ...rest }: FieldComponentProps): react.JSX.Element;
|
|
20
|
+
|
|
21
|
+
declare function EmailField({ formField, fieldConfig, className, ...rest }: FieldComponentProps): react.JSX.Element;
|
|
22
|
+
|
|
23
|
+
declare function PasswordField({ formField, fieldConfig, className, ...rest }: FieldComponentProps): react.JSX.Element;
|
|
24
|
+
|
|
25
|
+
declare function TextAreaField({ formField, fieldConfig, className, ...rest }: FieldComponentProps): react.JSX.Element;
|
|
26
|
+
|
|
27
|
+
declare function DateField({ formField, fieldConfig, className, ...rest }: FieldComponentProps): react.JSX.Element;
|
|
28
|
+
|
|
29
|
+
declare function SelectField({ formField, fieldConfig, className, ...rest }: FieldComponentProps): react.JSX.Element;
|
|
30
|
+
|
|
31
|
+
declare function CheckboxField({ formField, fieldConfig, className, ...rest }: FieldComponentProps): react.JSX.Element;
|
|
32
|
+
|
|
33
|
+
declare function RadioField({ formField, fieldConfig, className, ...rest }: FieldComponentProps): react.JSX.Element;
|
|
34
|
+
|
|
35
|
+
declare function SwitchField({ formField, fieldConfig, className, ...rest }: FieldComponentProps): react.JSX.Element;
|
|
36
|
+
|
|
37
|
+
declare const defaultComponents: {
|
|
38
|
+
text: typeof TextField;
|
|
39
|
+
number: typeof NumberField;
|
|
40
|
+
email: typeof EmailField;
|
|
41
|
+
password: typeof PasswordField;
|
|
42
|
+
textarea: typeof TextAreaField;
|
|
43
|
+
date: typeof DateField;
|
|
44
|
+
select: typeof SelectField;
|
|
45
|
+
checkbox: typeof CheckboxField;
|
|
46
|
+
radio: typeof RadioField;
|
|
47
|
+
switch: typeof SwitchField;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
declare function DefaultField({ field, control, ...rest }: Omit<FieldProps, 'components'>): react.JSX.Element;
|
|
51
|
+
|
|
52
|
+
export { CheckboxField, DateField, DefaultField, EmailField, type FieldComponentProps, NumberField, PasswordField, RadioField, SelectField, SwitchField, TextAreaField, TextField, defaultComponents };
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Field
|
|
3
|
+
} from "../chunk-N346U2SM.js";
|
|
4
|
+
|
|
5
|
+
// src/fields/TextField.tsx
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
function TextField({
|
|
8
|
+
formField,
|
|
9
|
+
fieldConfig,
|
|
10
|
+
className,
|
|
11
|
+
...rest
|
|
12
|
+
}) {
|
|
13
|
+
const { ref, ...field } = formField;
|
|
14
|
+
return /* @__PURE__ */ jsx(
|
|
15
|
+
"input",
|
|
16
|
+
{
|
|
17
|
+
ref,
|
|
18
|
+
...field,
|
|
19
|
+
type: "text",
|
|
20
|
+
placeholder: fieldConfig.placeholder,
|
|
21
|
+
className,
|
|
22
|
+
...rest
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/fields/NumberField.tsx
|
|
28
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
29
|
+
function NumberField({
|
|
30
|
+
formField,
|
|
31
|
+
fieldConfig,
|
|
32
|
+
className,
|
|
33
|
+
...rest
|
|
34
|
+
}) {
|
|
35
|
+
const { ref, ...field } = formField;
|
|
36
|
+
return /* @__PURE__ */ jsx2(
|
|
37
|
+
"input",
|
|
38
|
+
{
|
|
39
|
+
ref,
|
|
40
|
+
...field,
|
|
41
|
+
type: "number",
|
|
42
|
+
min: fieldConfig.rules?.min,
|
|
43
|
+
max: fieldConfig.rules?.max,
|
|
44
|
+
placeholder: fieldConfig.placeholder,
|
|
45
|
+
className,
|
|
46
|
+
...rest
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/fields/EmailField.tsx
|
|
52
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
53
|
+
function EmailField({
|
|
54
|
+
formField,
|
|
55
|
+
fieldConfig,
|
|
56
|
+
className,
|
|
57
|
+
...rest
|
|
58
|
+
}) {
|
|
59
|
+
const { ref, ...field } = formField;
|
|
60
|
+
return /* @__PURE__ */ jsx3(
|
|
61
|
+
"input",
|
|
62
|
+
{
|
|
63
|
+
ref,
|
|
64
|
+
...field,
|
|
65
|
+
type: "email",
|
|
66
|
+
placeholder: fieldConfig.placeholder,
|
|
67
|
+
className,
|
|
68
|
+
...rest
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/fields/PasswordField.tsx
|
|
74
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
75
|
+
function PasswordField({
|
|
76
|
+
formField,
|
|
77
|
+
fieldConfig,
|
|
78
|
+
className,
|
|
79
|
+
...rest
|
|
80
|
+
}) {
|
|
81
|
+
const { ref, ...field } = formField;
|
|
82
|
+
return /* @__PURE__ */ jsx4(
|
|
83
|
+
"input",
|
|
84
|
+
{
|
|
85
|
+
ref,
|
|
86
|
+
...field,
|
|
87
|
+
type: "password",
|
|
88
|
+
placeholder: fieldConfig.placeholder,
|
|
89
|
+
className,
|
|
90
|
+
...rest
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/fields/TextAreaField.tsx
|
|
96
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
97
|
+
function TextAreaField({
|
|
98
|
+
formField,
|
|
99
|
+
fieldConfig,
|
|
100
|
+
className,
|
|
101
|
+
...rest
|
|
102
|
+
}) {
|
|
103
|
+
const { ref, ...field } = formField;
|
|
104
|
+
return /* @__PURE__ */ jsx5(
|
|
105
|
+
"textarea",
|
|
106
|
+
{
|
|
107
|
+
ref,
|
|
108
|
+
...field,
|
|
109
|
+
rows: fieldConfig.props?.rows ?? 3,
|
|
110
|
+
placeholder: fieldConfig.placeholder,
|
|
111
|
+
className,
|
|
112
|
+
...rest
|
|
113
|
+
}
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// src/fields/DateField.tsx
|
|
118
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
119
|
+
function DateField({
|
|
120
|
+
formField,
|
|
121
|
+
fieldConfig,
|
|
122
|
+
className,
|
|
123
|
+
...rest
|
|
124
|
+
}) {
|
|
125
|
+
const { ref, ...field } = formField;
|
|
126
|
+
return /* @__PURE__ */ jsx6(
|
|
127
|
+
"input",
|
|
128
|
+
{
|
|
129
|
+
ref,
|
|
130
|
+
...field,
|
|
131
|
+
type: "date",
|
|
132
|
+
placeholder: fieldConfig.placeholder,
|
|
133
|
+
className,
|
|
134
|
+
...rest
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// src/fields/SelectField.tsx
|
|
140
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
141
|
+
function SelectField({
|
|
142
|
+
formField,
|
|
143
|
+
fieldConfig,
|
|
144
|
+
className,
|
|
145
|
+
...rest
|
|
146
|
+
}) {
|
|
147
|
+
const { ref, ...field } = formField;
|
|
148
|
+
const multiple = !!fieldConfig.props?.multiple;
|
|
149
|
+
return /* @__PURE__ */ jsx7(
|
|
150
|
+
"select",
|
|
151
|
+
{
|
|
152
|
+
ref,
|
|
153
|
+
...field,
|
|
154
|
+
multiple,
|
|
155
|
+
className,
|
|
156
|
+
...rest,
|
|
157
|
+
children: fieldConfig.options?.map((opt) => /* @__PURE__ */ jsx7("option", { value: opt.value, children: opt.label }, opt.value))
|
|
158
|
+
}
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// src/fields/CheckboxField.tsx
|
|
163
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
164
|
+
function CheckboxField({
|
|
165
|
+
formField,
|
|
166
|
+
fieldConfig,
|
|
167
|
+
className,
|
|
168
|
+
...rest
|
|
169
|
+
}) {
|
|
170
|
+
const { ref, value, ...field } = formField;
|
|
171
|
+
return /* @__PURE__ */ jsx8(
|
|
172
|
+
"input",
|
|
173
|
+
{
|
|
174
|
+
ref,
|
|
175
|
+
type: "checkbox",
|
|
176
|
+
checked: !!value,
|
|
177
|
+
...field,
|
|
178
|
+
onChange: (e) => field.onChange(e.target.checked),
|
|
179
|
+
className,
|
|
180
|
+
...rest
|
|
181
|
+
}
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// src/fields/RadioField.tsx
|
|
186
|
+
import { jsx as jsx9, jsxs } from "react/jsx-runtime";
|
|
187
|
+
function RadioField({
|
|
188
|
+
formField,
|
|
189
|
+
fieldConfig,
|
|
190
|
+
className,
|
|
191
|
+
...rest
|
|
192
|
+
}) {
|
|
193
|
+
const { ref, onChange, onBlur, name, value } = formField;
|
|
194
|
+
return /* @__PURE__ */ jsx9("div", { className, ...rest, children: fieldConfig.options?.map((opt) => /* @__PURE__ */ jsxs("label", { children: [
|
|
195
|
+
/* @__PURE__ */ jsx9(
|
|
196
|
+
"input",
|
|
197
|
+
{
|
|
198
|
+
type: "radio",
|
|
199
|
+
name,
|
|
200
|
+
value: opt.value,
|
|
201
|
+
checked: value === opt.value,
|
|
202
|
+
onChange: () => onChange(opt.value),
|
|
203
|
+
onBlur,
|
|
204
|
+
ref: value === opt.value ? ref : void 0
|
|
205
|
+
}
|
|
206
|
+
),
|
|
207
|
+
opt.label
|
|
208
|
+
] }, opt.value)) });
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// src/fields/SwitchField.tsx
|
|
212
|
+
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
213
|
+
function SwitchField({
|
|
214
|
+
formField,
|
|
215
|
+
fieldConfig,
|
|
216
|
+
className,
|
|
217
|
+
...rest
|
|
218
|
+
}) {
|
|
219
|
+
const { ref, value, ...field } = formField;
|
|
220
|
+
return /* @__PURE__ */ jsx10(
|
|
221
|
+
"input",
|
|
222
|
+
{
|
|
223
|
+
ref,
|
|
224
|
+
type: "checkbox",
|
|
225
|
+
role: "switch",
|
|
226
|
+
checked: !!value,
|
|
227
|
+
...field,
|
|
228
|
+
onChange: (e) => field.onChange(e.target.checked),
|
|
229
|
+
className,
|
|
230
|
+
...rest
|
|
231
|
+
}
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// src/fields/defaultComponents.ts
|
|
236
|
+
var defaultComponents = {
|
|
237
|
+
text: TextField,
|
|
238
|
+
number: NumberField,
|
|
239
|
+
email: EmailField,
|
|
240
|
+
password: PasswordField,
|
|
241
|
+
textarea: TextAreaField,
|
|
242
|
+
date: DateField,
|
|
243
|
+
select: SelectField,
|
|
244
|
+
checkbox: CheckboxField,
|
|
245
|
+
radio: RadioField,
|
|
246
|
+
switch: SwitchField
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
// src/fields/DefaultField.tsx
|
|
250
|
+
import { jsx as jsx11 } from "react/jsx-runtime";
|
|
251
|
+
function DefaultField({
|
|
252
|
+
field,
|
|
253
|
+
control,
|
|
254
|
+
...rest
|
|
255
|
+
}) {
|
|
256
|
+
return /* @__PURE__ */ jsx11(Field, { field, control, components: defaultComponents, ...rest });
|
|
257
|
+
}
|
|
258
|
+
export {
|
|
259
|
+
CheckboxField,
|
|
260
|
+
DateField,
|
|
261
|
+
DefaultField,
|
|
262
|
+
EmailField,
|
|
263
|
+
NumberField,
|
|
264
|
+
PasswordField,
|
|
265
|
+
RadioField,
|
|
266
|
+
SelectField,
|
|
267
|
+
SwitchField,
|
|
268
|
+
TextAreaField,
|
|
269
|
+
TextField,
|
|
270
|
+
defaultComponents
|
|
271
|
+
};
|
|
272
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/fields/TextField.tsx","../../src/fields/NumberField.tsx","../../src/fields/EmailField.tsx","../../src/fields/PasswordField.tsx","../../src/fields/TextAreaField.tsx","../../src/fields/DateField.tsx","../../src/fields/SelectField.tsx","../../src/fields/CheckboxField.tsx","../../src/fields/RadioField.tsx","../../src/fields/SwitchField.tsx","../../src/fields/defaultComponents.ts","../../src/fields/DefaultField.tsx"],"sourcesContent":["import type { FieldComponentProps } from './types';\n\nexport function TextField({\n formField,\n fieldConfig,\n className,\n ...rest\n}: FieldComponentProps) {\n const { ref, ...field } = formField;\n return (\n <input\n ref={ref}\n {...field}\n type=\"text\"\n placeholder={fieldConfig.placeholder}\n className={className}\n {...rest}\n />\n );\n}\n","import type { FieldComponentProps } from './types';\n\nexport function NumberField({\n formField,\n fieldConfig,\n className,\n ...rest\n}: FieldComponentProps) {\n const { ref, ...field } = formField;\n return (\n <input\n ref={ref}\n {...field}\n type=\"number\"\n min={fieldConfig.rules?.min}\n max={fieldConfig.rules?.max}\n placeholder={fieldConfig.placeholder}\n className={className}\n {...rest}\n />\n );\n}\n","import type { FieldComponentProps } from './types';\n\nexport function EmailField({\n formField,\n fieldConfig,\n className,\n ...rest\n}: FieldComponentProps) {\n const { ref, ...field } = formField;\n return (\n <input\n ref={ref}\n {...field}\n type=\"email\"\n placeholder={fieldConfig.placeholder}\n className={className}\n {...rest}\n />\n );\n}\n","import type { FieldComponentProps } from './types';\n\nexport function PasswordField({\n formField,\n fieldConfig,\n className,\n ...rest\n}: FieldComponentProps) {\n const { ref, ...field } = formField;\n return (\n <input\n ref={ref}\n {...field}\n type=\"password\"\n placeholder={fieldConfig.placeholder}\n className={className}\n {...rest}\n />\n );\n}\n","import type { FieldComponentProps } from './types';\n\nexport function TextAreaField({\n formField,\n fieldConfig,\n className,\n ...rest\n}: FieldComponentProps) {\n const { ref, ...field } = formField;\n return (\n <textarea\n ref={ref}\n {...field}\n rows={fieldConfig.props?.rows ?? 3}\n placeholder={fieldConfig.placeholder}\n className={className}\n {...rest}\n />\n );\n}\n","import type { FieldComponentProps } from './types';\n\nexport function DateField({\n formField,\n fieldConfig,\n className,\n ...rest\n}: FieldComponentProps) {\n const { ref, ...field } = formField;\n return (\n <input\n ref={ref}\n {...field}\n type=\"date\"\n placeholder={fieldConfig.placeholder}\n className={className}\n {...rest}\n />\n );\n}\n","import type { FieldComponentProps } from './types';\n\nexport function SelectField({\n formField,\n fieldConfig,\n className,\n ...rest\n}: FieldComponentProps) {\n const { ref, ...field } = formField;\n const multiple = !!fieldConfig.props?.multiple;\n\n return (\n <select\n ref={ref}\n {...field}\n multiple={multiple}\n className={className}\n {...rest}\n >\n {fieldConfig.options?.map((opt) => (\n <option key={opt.value} value={opt.value}>\n {opt.label}\n </option>\n ))}\n </select>\n );\n}\n","import type { FieldComponentProps } from './types';\n\nexport function CheckboxField({\n formField,\n fieldConfig,\n className,\n ...rest\n}: FieldComponentProps) {\n const { ref, value, ...field } = formField;\n return (\n <input\n ref={ref}\n type=\"checkbox\"\n checked={!!value}\n {...field}\n onChange={(e) => field.onChange(e.target.checked)}\n className={className}\n {...rest}\n />\n );\n}\n","import type { FieldComponentProps } from './types';\n\nexport function RadioField({\n formField,\n fieldConfig,\n className,\n ...rest\n}: FieldComponentProps) {\n const { ref, onChange, onBlur, name, value } = formField;\n\n return (\n <div className={className} {...rest}>\n {fieldConfig.options?.map((opt) => (\n <label key={opt.value}>\n <input\n type=\"radio\"\n name={name}\n value={opt.value}\n checked={value === opt.value}\n onChange={() => onChange(opt.value)}\n onBlur={onBlur}\n ref={value === opt.value ? ref : undefined}\n />\n {opt.label}\n </label>\n ))}\n </div>\n );\n}\n","import type { FieldComponentProps } from './types';\n\nexport function SwitchField({\n formField,\n fieldConfig,\n className,\n ...rest\n}: FieldComponentProps) {\n const { ref, value, ...field } = formField;\n return (\n <input\n ref={ref}\n type=\"checkbox\"\n role=\"switch\"\n checked={!!value}\n {...field}\n onChange={(e) => field.onChange(e.target.checked)}\n className={className}\n {...rest}\n />\n );\n}\n","import { TextField } from './TextField';\nimport { NumberField } from './NumberField';\nimport { EmailField } from './EmailField';\nimport { PasswordField } from './PasswordField';\nimport { TextAreaField } from './TextAreaField';\nimport { DateField } from './DateField';\nimport { SelectField } from './SelectField';\nimport { CheckboxField } from './CheckboxField';\nimport { RadioField } from './RadioField';\nimport { SwitchField } from './SwitchField';\n\nexport const defaultComponents = {\n text: TextField,\n number: NumberField,\n email: EmailField,\n password: PasswordField,\n textarea: TextAreaField,\n date: DateField,\n select: SelectField,\n checkbox: CheckboxField,\n radio: RadioField,\n switch: SwitchField,\n};\n","import { Field, type FieldProps } from '../Field';\nimport { defaultComponents } from './defaultComponents';\n\nexport function DefaultField({\n field,\n control,\n ...rest\n}: Omit<FieldProps, 'components'>) {\n return <Field field={field} control={control} components={defaultComponents} {...rest} />;\n}\n"],"mappings":";;;;;AAUI;AARG,SAAS,UAAU;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAwB;AACtB,QAAM,EAAE,KAAK,GAAG,MAAM,IAAI;AAC1B,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACC,GAAG;AAAA,MACJ,MAAK;AAAA,MACL,aAAa,YAAY;AAAA,MACzB;AAAA,MACC,GAAG;AAAA;AAAA,EACN;AAEJ;;;ACTI,gBAAAA,YAAA;AARG,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;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ist/index.cjs
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkCYMOPAGJcjs = require('./chunk-CYMOPAGJ.cjs');
|
|
7
|
+
|
|
8
|
+
// src/useFormConfig.ts
|
|
9
|
+
var _react = require('react');
|
|
10
|
+
var _reacthookform = require('react-hook-form');
|
|
11
|
+
var _core = require('@form-os/core');
|
|
12
|
+
function useFormConfig(config) {
|
|
13
|
+
const normalized = _react.useMemo.call(void 0, () => _core.normalizeConfig.call(void 0, config), [config]);
|
|
14
|
+
const defaultValues = _react.useMemo.call(void 0,
|
|
15
|
+
() => Object.fromEntries(
|
|
16
|
+
normalized.fields.filter((f) => f.defaultValue !== void 0).map((f) => [f.name, f.defaultValue])
|
|
17
|
+
),
|
|
18
|
+
[normalized.fields]
|
|
19
|
+
);
|
|
20
|
+
const form = _reacthookform.useForm.call(void 0, { defaultValues });
|
|
21
|
+
return { ...form, fields: normalized.fields };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// src/index.ts
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
exports.Field = _chunkCYMOPAGJcjs.Field; exports.FormFieldsProvider = _chunkCYMOPAGJcjs.FormFieldsProvider; exports.FormProvider = _reacthookform.FormProvider; exports.useField = _chunkCYMOPAGJcjs.useField; exports.useFieldComponents = _chunkCYMOPAGJcjs.useFieldComponents; exports.useForm = _reacthookform.useForm; exports.useFormConfig = useFormConfig; exports.useFormContext = _reacthookform.useFormContext;
|
|
36
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/abeleko/Documents/larven/formjs/packages/react/dist/index.cjs","../src/useFormConfig.ts","../src/index.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACPA,8BAAwB;AACxB,gDAAwB;AACxB,qCAAmE;AAE5D,SAAS,aAAA,CAAc,MAAA,EAAoC;AAChE,EAAA,MAAM,WAAA,EAAa,4BAAA,CAAQ,EAAA,GAAM,mCAAA,MAAsB,CAAA,EAAG,CAAC,MAAM,CAAC,CAAA;AAElE,EAAA,MAAM,cAAA,EAAgB,4BAAA;AAAA,IACpB,CAAA,EAAA,GACE,MAAA,CAAO,WAAA;AAAA,MACL,UAAA,CAAW,MAAA,CACR,MAAA,CAAO,CAAC,CAAA,EAAA,GAAM,CAAA,CAAE,aAAA,IAAiB,KAAA,CAAS,CAAA,CAC1C,GAAA,CAAI,CAAC,CAAA,EAAA,GAAM,CAAC,CAAA,CAAE,IAAA,EAAM,CAAA,CAAE,YAAY,CAAC;AAAA,IACxC,CAAA;AAAA,IACF,CAAC,UAAA,CAAW,MAAM;AAAA,EACpB,CAAA;AAEA,EAAA,MAAM,KAAA,EAAO,oCAAA,EAAU,cAAc,CAAC,CAAA;AAEtC,EAAA,OAAO,EAAE,GAAG,IAAA,EAAM,MAAA,EAAQ,UAAA,CAAW,OAAO,CAAA;AAC9C;ADEA;AACA;AEhBA;AFkBA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,0ZAAC","file":"/Users/abeleko/Documents/larven/formjs/packages/react/dist/index.cjs","sourcesContent":[null,"import { useMemo } from 'react';\nimport { useForm } from 'react-hook-form';\nimport { normalizeConfig, type FieldConfig, type FormConfig } from '@form-os/core';\n\nexport function useFormConfig(config: FieldConfig[] | FormConfig) {\n const normalized = useMemo(() => normalizeConfig(config), [config]);\n\n const defaultValues = useMemo(\n () =>\n Object.fromEntries(\n normalized.fields\n .filter((f) => f.defaultValue !== undefined)\n .map((f) => [f.name, f.defaultValue])\n ),\n [normalized.fields]\n );\n\n const form = useForm({ defaultValues });\n\n return { ...form, fields: normalized.fields };\n}\n","export { useFormConfig } from './useFormConfig';\nexport { Field } from './Field';\nexport type { FieldProps } from './Field';\nexport { useField } from './useField';\nexport type { UseFieldOptions } from './useField';\nexport { FormFieldsProvider, useFieldComponents } from './FormFieldsContext';\nexport type { ComponentsMap, FormFieldsProviderProps } from './FormFieldsContext';\nexport { FormProvider, useFormContext, useForm } from 'react-hook-form';\nexport type { Control, RegisterOptions, UseFormProps } from 'react-hook-form';\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import * as react_hook_form from 'react-hook-form';
|
|
2
|
+
import { RegisterOptions, Control } from 'react-hook-form';
|
|
3
|
+
export { Control, FormProvider, RegisterOptions, UseFormProps, useForm, useFormContext } from 'react-hook-form';
|
|
4
|
+
import * as _form_os_core from '@form-os/core';
|
|
5
|
+
import { FieldConfig, FormConfig } from '@form-os/core';
|
|
6
|
+
export { a as Field, F as FieldProps } from './Field-Bq9-eB99.cjs';
|
|
7
|
+
import * as react from 'react';
|
|
8
|
+
import { ComponentType, ReactNode } from 'react';
|
|
9
|
+
|
|
10
|
+
declare function useFormConfig(config: FieldConfig[] | FormConfig): {
|
|
11
|
+
fields: FieldConfig[];
|
|
12
|
+
watch: react_hook_form.UseFormWatch<{
|
|
13
|
+
[k: string]: any;
|
|
14
|
+
}>;
|
|
15
|
+
getValues: react_hook_form.UseFormGetValues<{
|
|
16
|
+
[k: string]: any;
|
|
17
|
+
}>;
|
|
18
|
+
getFieldState: react_hook_form.UseFormGetFieldState<{
|
|
19
|
+
[k: string]: any;
|
|
20
|
+
}>;
|
|
21
|
+
setError: react_hook_form.UseFormSetError<{
|
|
22
|
+
[k: string]: any;
|
|
23
|
+
}>;
|
|
24
|
+
clearErrors: react_hook_form.UseFormClearErrors<{
|
|
25
|
+
[k: string]: any;
|
|
26
|
+
}>;
|
|
27
|
+
setValue: react_hook_form.UseFormSetValue<{
|
|
28
|
+
[k: string]: any;
|
|
29
|
+
}>;
|
|
30
|
+
setValues: react_hook_form.UseFormSetValues<{
|
|
31
|
+
[k: string]: any;
|
|
32
|
+
}>;
|
|
33
|
+
trigger: react_hook_form.UseFormTrigger<{
|
|
34
|
+
[k: string]: any;
|
|
35
|
+
}>;
|
|
36
|
+
formState: react_hook_form.FormState<{
|
|
37
|
+
[k: string]: any;
|
|
38
|
+
}>;
|
|
39
|
+
resetField: react_hook_form.UseFormResetField<{
|
|
40
|
+
[k: string]: any;
|
|
41
|
+
}>;
|
|
42
|
+
reset: react_hook_form.UseFormReset<{
|
|
43
|
+
[k: string]: any;
|
|
44
|
+
}>;
|
|
45
|
+
resetDefaultValues: react_hook_form.UseFormResetDefaultValues<{
|
|
46
|
+
[k: string]: any;
|
|
47
|
+
}>;
|
|
48
|
+
handleSubmit: react_hook_form.UseFormHandleSubmit<{
|
|
49
|
+
[k: string]: any;
|
|
50
|
+
}, {
|
|
51
|
+
[k: string]: any;
|
|
52
|
+
}>;
|
|
53
|
+
unregister: react_hook_form.UseFormUnregister<{
|
|
54
|
+
[k: string]: any;
|
|
55
|
+
}>;
|
|
56
|
+
control: react_hook_form.Control<{
|
|
57
|
+
[k: string]: any;
|
|
58
|
+
}, any, {
|
|
59
|
+
[k: string]: any;
|
|
60
|
+
}>;
|
|
61
|
+
register: react_hook_form.UseFormRegister<{
|
|
62
|
+
[k: string]: any;
|
|
63
|
+
}>;
|
|
64
|
+
setFocus: react_hook_form.UseFormSetFocus<{
|
|
65
|
+
[k: string]: any;
|
|
66
|
+
}>;
|
|
67
|
+
subscribe: react_hook_form.UseFormSubscribe<{
|
|
68
|
+
[k: string]: any;
|
|
69
|
+
}>;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
interface UseFieldOptions {
|
|
73
|
+
rules?: RegisterOptions;
|
|
74
|
+
defaultValue?: any;
|
|
75
|
+
}
|
|
76
|
+
declare function useField(field: FieldConfig, control: Control, options?: UseFieldOptions): {
|
|
77
|
+
field: react_hook_form.ControllerRenderProps<react_hook_form.FieldValues, string>;
|
|
78
|
+
fieldState: react_hook_form.ControllerFieldState;
|
|
79
|
+
state: _form_os_core.FieldState;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
type ComponentsMap = Record<string, ComponentType<any>>;
|
|
83
|
+
interface FormFieldsProviderProps {
|
|
84
|
+
components: ComponentsMap;
|
|
85
|
+
children: ReactNode;
|
|
86
|
+
}
|
|
87
|
+
declare function FormFieldsProvider({ components, children }: FormFieldsProviderProps): react.JSX.Element;
|
|
88
|
+
declare function useFieldComponents(): ComponentsMap;
|
|
89
|
+
|
|
90
|
+
export { type ComponentsMap, FormFieldsProvider, type FormFieldsProviderProps, type UseFieldOptions, useField, useFieldComponents, useFormConfig };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import * as react_hook_form from 'react-hook-form';
|
|
2
|
+
import { RegisterOptions, Control } from 'react-hook-form';
|
|
3
|
+
export { Control, FormProvider, RegisterOptions, UseFormProps, useForm, useFormContext } from 'react-hook-form';
|
|
4
|
+
import * as _form_os_core from '@form-os/core';
|
|
5
|
+
import { FieldConfig, FormConfig } from '@form-os/core';
|
|
6
|
+
export { a as Field, F as FieldProps } from './Field-Bq9-eB99.js';
|
|
7
|
+
import * as react from 'react';
|
|
8
|
+
import { ComponentType, ReactNode } from 'react';
|
|
9
|
+
|
|
10
|
+
declare function useFormConfig(config: FieldConfig[] | FormConfig): {
|
|
11
|
+
fields: FieldConfig[];
|
|
12
|
+
watch: react_hook_form.UseFormWatch<{
|
|
13
|
+
[k: string]: any;
|
|
14
|
+
}>;
|
|
15
|
+
getValues: react_hook_form.UseFormGetValues<{
|
|
16
|
+
[k: string]: any;
|
|
17
|
+
}>;
|
|
18
|
+
getFieldState: react_hook_form.UseFormGetFieldState<{
|
|
19
|
+
[k: string]: any;
|
|
20
|
+
}>;
|
|
21
|
+
setError: react_hook_form.UseFormSetError<{
|
|
22
|
+
[k: string]: any;
|
|
23
|
+
}>;
|
|
24
|
+
clearErrors: react_hook_form.UseFormClearErrors<{
|
|
25
|
+
[k: string]: any;
|
|
26
|
+
}>;
|
|
27
|
+
setValue: react_hook_form.UseFormSetValue<{
|
|
28
|
+
[k: string]: any;
|
|
29
|
+
}>;
|
|
30
|
+
setValues: react_hook_form.UseFormSetValues<{
|
|
31
|
+
[k: string]: any;
|
|
32
|
+
}>;
|
|
33
|
+
trigger: react_hook_form.UseFormTrigger<{
|
|
34
|
+
[k: string]: any;
|
|
35
|
+
}>;
|
|
36
|
+
formState: react_hook_form.FormState<{
|
|
37
|
+
[k: string]: any;
|
|
38
|
+
}>;
|
|
39
|
+
resetField: react_hook_form.UseFormResetField<{
|
|
40
|
+
[k: string]: any;
|
|
41
|
+
}>;
|
|
42
|
+
reset: react_hook_form.UseFormReset<{
|
|
43
|
+
[k: string]: any;
|
|
44
|
+
}>;
|
|
45
|
+
resetDefaultValues: react_hook_form.UseFormResetDefaultValues<{
|
|
46
|
+
[k: string]: any;
|
|
47
|
+
}>;
|
|
48
|
+
handleSubmit: react_hook_form.UseFormHandleSubmit<{
|
|
49
|
+
[k: string]: any;
|
|
50
|
+
}, {
|
|
51
|
+
[k: string]: any;
|
|
52
|
+
}>;
|
|
53
|
+
unregister: react_hook_form.UseFormUnregister<{
|
|
54
|
+
[k: string]: any;
|
|
55
|
+
}>;
|
|
56
|
+
control: react_hook_form.Control<{
|
|
57
|
+
[k: string]: any;
|
|
58
|
+
}, any, {
|
|
59
|
+
[k: string]: any;
|
|
60
|
+
}>;
|
|
61
|
+
register: react_hook_form.UseFormRegister<{
|
|
62
|
+
[k: string]: any;
|
|
63
|
+
}>;
|
|
64
|
+
setFocus: react_hook_form.UseFormSetFocus<{
|
|
65
|
+
[k: string]: any;
|
|
66
|
+
}>;
|
|
67
|
+
subscribe: react_hook_form.UseFormSubscribe<{
|
|
68
|
+
[k: string]: any;
|
|
69
|
+
}>;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
interface UseFieldOptions {
|
|
73
|
+
rules?: RegisterOptions;
|
|
74
|
+
defaultValue?: any;
|
|
75
|
+
}
|
|
76
|
+
declare function useField(field: FieldConfig, control: Control, options?: UseFieldOptions): {
|
|
77
|
+
field: react_hook_form.ControllerRenderProps<react_hook_form.FieldValues, string>;
|
|
78
|
+
fieldState: react_hook_form.ControllerFieldState;
|
|
79
|
+
state: _form_os_core.FieldState;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
type ComponentsMap = Record<string, ComponentType<any>>;
|
|
83
|
+
interface FormFieldsProviderProps {
|
|
84
|
+
components: ComponentsMap;
|
|
85
|
+
children: ReactNode;
|
|
86
|
+
}
|
|
87
|
+
declare function FormFieldsProvider({ components, children }: FormFieldsProviderProps): react.JSX.Element;
|
|
88
|
+
declare function useFieldComponents(): ComponentsMap;
|
|
89
|
+
|
|
90
|
+
export { type ComponentsMap, FormFieldsProvider, type FormFieldsProviderProps, type UseFieldOptions, useField, useFieldComponents, useFormConfig };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Field,
|
|
3
|
+
FormFieldsProvider,
|
|
4
|
+
useField,
|
|
5
|
+
useFieldComponents
|
|
6
|
+
} from "./chunk-N346U2SM.js";
|
|
7
|
+
|
|
8
|
+
// src/useFormConfig.ts
|
|
9
|
+
import { useMemo } from "react";
|
|
10
|
+
import { useForm } from "react-hook-form";
|
|
11
|
+
import { normalizeConfig } from "@form-os/core";
|
|
12
|
+
function useFormConfig(config) {
|
|
13
|
+
const normalized = useMemo(() => normalizeConfig(config), [config]);
|
|
14
|
+
const defaultValues = useMemo(
|
|
15
|
+
() => Object.fromEntries(
|
|
16
|
+
normalized.fields.filter((f) => f.defaultValue !== void 0).map((f) => [f.name, f.defaultValue])
|
|
17
|
+
),
|
|
18
|
+
[normalized.fields]
|
|
19
|
+
);
|
|
20
|
+
const form = useForm({ defaultValues });
|
|
21
|
+
return { ...form, fields: normalized.fields };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// src/index.ts
|
|
25
|
+
import { FormProvider, useFormContext, useForm as useForm2 } from "react-hook-form";
|
|
26
|
+
export {
|
|
27
|
+
Field,
|
|
28
|
+
FormFieldsProvider,
|
|
29
|
+
FormProvider,
|
|
30
|
+
useField,
|
|
31
|
+
useFieldComponents,
|
|
32
|
+
useForm2 as useForm,
|
|
33
|
+
useFormConfig,
|
|
34
|
+
useFormContext
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/useFormConfig.ts","../src/index.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport { useForm } from 'react-hook-form';\nimport { normalizeConfig, type FieldConfig, type FormConfig } from '@form-os/core';\n\nexport function useFormConfig(config: FieldConfig[] | FormConfig) {\n const normalized = useMemo(() => normalizeConfig(config), [config]);\n\n const defaultValues = useMemo(\n () =>\n Object.fromEntries(\n normalized.fields\n .filter((f) => f.defaultValue !== undefined)\n .map((f) => [f.name, f.defaultValue])\n ),\n [normalized.fields]\n );\n\n const form = useForm({ defaultValues });\n\n return { ...form, fields: normalized.fields };\n}\n","export { useFormConfig } from './useFormConfig';\nexport { Field } from './Field';\nexport type { FieldProps } from './Field';\nexport { useField } from './useField';\nexport type { UseFieldOptions } from './useField';\nexport { FormFieldsProvider, useFieldComponents } from './FormFieldsContext';\nexport type { ComponentsMap, FormFieldsProviderProps } from './FormFieldsContext';\nexport { FormProvider, useFormContext, useForm } from 'react-hook-form';\nexport type { Control, RegisterOptions, UseFormProps } from 'react-hook-form';\n"],"mappings":";;;;;;;;AAAA,SAAS,eAAe;AACxB,SAAS,eAAe;AACxB,SAAS,uBAA0D;AAE5D,SAAS,cAAc,QAAoC;AAChE,QAAM,aAAa,QAAQ,MAAM,gBAAgB,MAAM,GAAG,CAAC,MAAM,CAAC;AAElE,QAAM,gBAAgB;AAAA,IACpB,MACE,OAAO;AAAA,MACL,WAAW,OACR,OAAO,CAAC,MAAM,EAAE,iBAAiB,MAAS,EAC1C,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC;AAAA,IACxC;AAAA,IACF,CAAC,WAAW,MAAM;AAAA,EACpB;AAEA,QAAM,OAAO,QAAQ,EAAE,cAAc,CAAC;AAEtC,SAAO,EAAE,GAAG,MAAM,QAAQ,WAAW,OAAO;AAC9C;;;ACbA,SAAS,cAAc,gBAAgB,WAAAA,gBAAe;","names":["useForm"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@form-os/react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./fields": {
|
|
16
|
+
"types": "./dist/fields/index.d.ts",
|
|
17
|
+
"import": "./dist/fields/index.js",
|
|
18
|
+
"require": "./dist/fields/index.cjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"react": ">=18.0.0",
|
|
29
|
+
"react-dom": ">=18.0.0",
|
|
30
|
+
"react-hook-form": ">=7.0.0"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@form-os/core": "0.1.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/react": "^18.2.0",
|
|
37
|
+
"@types/react-dom": "^18.2.0",
|
|
38
|
+
"react": "^18.2.0",
|
|
39
|
+
"react-dom": "^18.2.0",
|
|
40
|
+
"react-hook-form": "^7.51.0",
|
|
41
|
+
"tsup": "^8.0.2",
|
|
42
|
+
"typescript": "^5.4.5"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsup"
|
|
46
|
+
}
|
|
47
|
+
}
|