@raketa-builder/next-form 1.3.9 → 1.3.11
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/dist/Context.js +6 -0
- package/dist/Fields.js +114 -0
- package/dist/Fieldset.js +56 -0
- package/dist/Form.js +53 -0
- package/dist/FormNavigation.js +26 -0
- package/dist/Submit.js +13 -0
- package/dist/chunk-ORMEWXMH.js +33 -0
- package/dist/index.js +15 -23
- package/dist/utils/slugify.js +6 -0
- package/package.json +9 -8
package/dist/Context.js
ADDED
package/dist/Fields.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { __objRest, __spreadValues, __spreadProps } from './chunk-ORMEWXMH.js';
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { Hint, FormGroup, Label, cn, Stack, Textarea, Select, Input } from '@raketa-builder/ui';
|
|
5
|
+
import Context from './Context';
|
|
6
|
+
|
|
7
|
+
const HiddenInput = ({ value, name }) => {
|
|
8
|
+
if (typeof value === "string") {
|
|
9
|
+
return /* @__PURE__ */ jsx(Input, { type: "hidden", defaultValue: value, name });
|
|
10
|
+
} else {
|
|
11
|
+
return /* @__PURE__ */ jsx(Input, { type: "hidden", defaultValue: JSON.stringify(value), name });
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const CustomField = ({ component, name }) => {
|
|
15
|
+
const { defaultValues, errors } = React.useContext(Context);
|
|
16
|
+
const [value, setValue] = React.useState(defaultValues[name]);
|
|
17
|
+
const Component = component;
|
|
18
|
+
return /* @__PURE__ */ jsxs(React.Fragment, { children: [
|
|
19
|
+
/* @__PURE__ */ jsx(Component, { onChange: (newValue) => setValue(newValue), value }),
|
|
20
|
+
/* @__PURE__ */ jsx(HiddenInput, { name, value }),
|
|
21
|
+
errors[name] && /* @__PURE__ */ jsx(Hint, { type: "error", children: errors[name] })
|
|
22
|
+
] });
|
|
23
|
+
};
|
|
24
|
+
const CheckboxGroup = ({ name, label, hint = "", entities }) => {
|
|
25
|
+
const { defaultValues, errors } = React.useContext(Context);
|
|
26
|
+
let defaultChecked = [];
|
|
27
|
+
if (defaultValues[name]) {
|
|
28
|
+
defaultChecked = Array.isArray(defaultValues[name]) ? defaultValues[name] : [defaultValues[name]];
|
|
29
|
+
}
|
|
30
|
+
return /* @__PURE__ */ jsxs(FormGroup, { children: [
|
|
31
|
+
/* @__PURE__ */ jsx(Label, { htmlFor: name, children: label }),
|
|
32
|
+
entities.map((entity, idx) => /* @__PURE__ */ jsx(
|
|
33
|
+
"label",
|
|
34
|
+
{
|
|
35
|
+
className: cn("r-reset", "r-next-form-checkbox-label"),
|
|
36
|
+
children: /* @__PURE__ */ jsxs("div", { children: [
|
|
37
|
+
/* @__PURE__ */ jsx(
|
|
38
|
+
"input",
|
|
39
|
+
{
|
|
40
|
+
type: "checkbox",
|
|
41
|
+
name,
|
|
42
|
+
value: `${entity.value}`,
|
|
43
|
+
defaultChecked: !!defaultChecked.find((dv) => dv === entity.value)
|
|
44
|
+
}
|
|
45
|
+
),
|
|
46
|
+
"\xA0",
|
|
47
|
+
entity.label
|
|
48
|
+
] })
|
|
49
|
+
},
|
|
50
|
+
`${entity.value}-${idx}`
|
|
51
|
+
)),
|
|
52
|
+
hint && /* @__PURE__ */ jsx(Hint, { children: hint }),
|
|
53
|
+
errors[name] && /* @__PURE__ */ jsx(Hint, { type: "error", children: errors[name] })
|
|
54
|
+
] });
|
|
55
|
+
};
|
|
56
|
+
const Checkbox = (_a) => {
|
|
57
|
+
var _b = _a, { name, label, hint = "" } = _b, rest = __objRest(_b, ["name", "label", "hint"]);
|
|
58
|
+
const { defaultValues, errors } = React.useContext(Context);
|
|
59
|
+
return /* @__PURE__ */ jsxs(FormGroup, { children: [
|
|
60
|
+
/* @__PURE__ */ jsx(Label, { children: /* @__PURE__ */ jsxs(Stack, { className: "r-stack-align-center", children: [
|
|
61
|
+
/* @__PURE__ */ jsx(
|
|
62
|
+
"input",
|
|
63
|
+
__spreadValues({
|
|
64
|
+
type: "checkbox",
|
|
65
|
+
name,
|
|
66
|
+
defaultChecked: defaultValues[name]
|
|
67
|
+
}, rest)
|
|
68
|
+
),
|
|
69
|
+
"\xA0",
|
|
70
|
+
label
|
|
71
|
+
] }) }),
|
|
72
|
+
hint && /* @__PURE__ */ jsx(Hint, { children: hint }),
|
|
73
|
+
errors[name] && /* @__PURE__ */ jsx(Hint, { type: "error", children: errors[name] })
|
|
74
|
+
] });
|
|
75
|
+
};
|
|
76
|
+
const Field = (_c) => {
|
|
77
|
+
var _d = _c, {
|
|
78
|
+
as = "input",
|
|
79
|
+
hint = "",
|
|
80
|
+
name,
|
|
81
|
+
label,
|
|
82
|
+
children
|
|
83
|
+
} = _d, props = __objRest(_d, [
|
|
84
|
+
"as",
|
|
85
|
+
"hint",
|
|
86
|
+
"name",
|
|
87
|
+
"label",
|
|
88
|
+
"children"
|
|
89
|
+
]);
|
|
90
|
+
const { defaultValues, errors } = React.useContext(Context);
|
|
91
|
+
const types = {
|
|
92
|
+
input: Input,
|
|
93
|
+
select: Select,
|
|
94
|
+
textarea: Textarea
|
|
95
|
+
};
|
|
96
|
+
const Component = types[as] || Input;
|
|
97
|
+
return /* @__PURE__ */ jsxs(FormGroup, { children: [
|
|
98
|
+
label && /* @__PURE__ */ jsx(Label, { htmlFor: name, children: label }),
|
|
99
|
+
/* @__PURE__ */ jsx(
|
|
100
|
+
Component,
|
|
101
|
+
__spreadProps(__spreadValues({
|
|
102
|
+
id: name,
|
|
103
|
+
name,
|
|
104
|
+
defaultValue: defaultValues[name]
|
|
105
|
+
}, props), {
|
|
106
|
+
children
|
|
107
|
+
})
|
|
108
|
+
),
|
|
109
|
+
hint && /* @__PURE__ */ jsx(Hint, { children: hint }),
|
|
110
|
+
errors[name] && /* @__PURE__ */ jsx(Hint, { type: "error", children: errors[name] })
|
|
111
|
+
] });
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export { Checkbox, CheckboxGroup, CustomField, Field };
|
package/dist/Fieldset.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { __objRest, __spreadValues } from './chunk-ORMEWXMH.js';
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import 'react';
|
|
4
|
+
import { cn } from '@raketa-builder/ui';
|
|
5
|
+
import slugify from './utils/slugify';
|
|
6
|
+
|
|
7
|
+
const Wrapper = (_a) => {
|
|
8
|
+
var _b = _a, { className } = _b, rest = __objRest(_b, ["className"]);
|
|
9
|
+
return /* @__PURE__ */ jsx(
|
|
10
|
+
"div",
|
|
11
|
+
__spreadValues({
|
|
12
|
+
className: cn("r-reset", "r-next-form-fieldset-wrapper", className)
|
|
13
|
+
}, rest)
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
const LegendWrapper = (_c) => {
|
|
17
|
+
var _d = _c, { className } = _d, rest = __objRest(_d, ["className"]);
|
|
18
|
+
return /* @__PURE__ */ jsx(
|
|
19
|
+
"div",
|
|
20
|
+
__spreadValues({
|
|
21
|
+
className: cn("r-reset", "r-next-form-legend-wrapper", className)
|
|
22
|
+
}, rest)
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
const Legend = (_e) => {
|
|
26
|
+
var _f = _e, { className } = _f, rest = __objRest(_f, ["className"]);
|
|
27
|
+
return /* @__PURE__ */ jsx("div", __spreadValues({ className: cn("r-reset", "r-next-form-legend", className) }, rest));
|
|
28
|
+
};
|
|
29
|
+
const Description = (_g) => {
|
|
30
|
+
var _h = _g, { className } = _h, rest = __objRest(_h, ["className"]);
|
|
31
|
+
return /* @__PURE__ */ jsx(
|
|
32
|
+
"div",
|
|
33
|
+
__spreadValues({
|
|
34
|
+
className: cn("r-reset", "r-next-form-description", className)
|
|
35
|
+
}, rest)
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
const FieldWrapper = (_i) => {
|
|
39
|
+
var _j = _i, { className } = _j, rest = __objRest(_j, ["className"]);
|
|
40
|
+
return /* @__PURE__ */ jsx(
|
|
41
|
+
"div",
|
|
42
|
+
__spreadValues({
|
|
43
|
+
className: cn("r-reset", "r-next-form-field-wrapper", className)
|
|
44
|
+
}, rest)
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
const Fieldset = ({ label, description, children }) => /* @__PURE__ */ jsxs(Wrapper, { id: slugify(label), children: [
|
|
48
|
+
/* @__PURE__ */ jsxs(LegendWrapper, { children: [
|
|
49
|
+
/* @__PURE__ */ jsx(Legend, { children: label }),
|
|
50
|
+
description && /* @__PURE__ */ jsx(Description, { dangerouslySetInnerHTML: { __html: description } })
|
|
51
|
+
] }),
|
|
52
|
+
/* @__PURE__ */ jsx(FieldWrapper, { children })
|
|
53
|
+
] });
|
|
54
|
+
var Fieldset_default = Fieldset;
|
|
55
|
+
|
|
56
|
+
export { Fieldset_default as default };
|
package/dist/Form.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { __objRest, __spreadProps, __spreadValues } from './chunk-ORMEWXMH.js';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import Context from './Context';
|
|
5
|
+
|
|
6
|
+
const Form = (_a) => {
|
|
7
|
+
var _b = _a, { children, defaultValues = {}, onSubmit } = _b, rest = __objRest(_b, ["children", "defaultValues", "onSubmit"]);
|
|
8
|
+
const [state, setState] = React.useState({ submitting: false, errors: {} });
|
|
9
|
+
const setErrors = (errors) => {
|
|
10
|
+
let newErrors = {};
|
|
11
|
+
errors.map((error) => newErrors[error.key] = error.message);
|
|
12
|
+
if (state.submitting) {
|
|
13
|
+
setState({
|
|
14
|
+
submitting: false,
|
|
15
|
+
errors: newErrors
|
|
16
|
+
});
|
|
17
|
+
} else {
|
|
18
|
+
setState({
|
|
19
|
+
submitting: state.submitting,
|
|
20
|
+
errors: newErrors
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
return /* @__PURE__ */ jsx(
|
|
25
|
+
"form",
|
|
26
|
+
__spreadProps(__spreadValues({
|
|
27
|
+
onSubmit: (e) => {
|
|
28
|
+
if (!onSubmit) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
e.preventDefault();
|
|
32
|
+
const formData = new FormData(e.target);
|
|
33
|
+
setState(__spreadProps(__spreadValues({}, state), { submitting: true }));
|
|
34
|
+
onSubmit(formData, setErrors, e.target);
|
|
35
|
+
}
|
|
36
|
+
}, rest), {
|
|
37
|
+
children: /* @__PURE__ */ jsx(
|
|
38
|
+
Context.Provider,
|
|
39
|
+
{
|
|
40
|
+
value: {
|
|
41
|
+
defaultValues,
|
|
42
|
+
errors: state.errors,
|
|
43
|
+
submitting: state.submitting
|
|
44
|
+
},
|
|
45
|
+
children
|
|
46
|
+
}
|
|
47
|
+
)
|
|
48
|
+
})
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
var Form_default = Form;
|
|
52
|
+
|
|
53
|
+
export { Form_default as default };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { __objRest, __spreadValues } from './chunk-ORMEWXMH.js';
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import 'react';
|
|
4
|
+
import { cn } from '@raketa-builder/ui';
|
|
5
|
+
import slugify from './utils/slugify';
|
|
6
|
+
|
|
7
|
+
const Wrapper = (_a) => {
|
|
8
|
+
var _b = _a, { className } = _b, rest = __objRest(_b, ["className"]);
|
|
9
|
+
return /* @__PURE__ */ jsx(
|
|
10
|
+
"div",
|
|
11
|
+
__spreadValues({
|
|
12
|
+
className: cn("r-reset", "r-next-form-nav-wrapper", className)
|
|
13
|
+
}, rest)
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
const Link = (_c) => {
|
|
17
|
+
var _d = _c, { className } = _d, rest = __objRest(_d, ["className"]);
|
|
18
|
+
return /* @__PURE__ */ jsx("a", __spreadValues({ className: cn("r-reset", "r-next-form-nav-link", className) }, rest));
|
|
19
|
+
};
|
|
20
|
+
const FormNavigation = ({ sections, children }) => /* @__PURE__ */ jsxs(Wrapper, { children: [
|
|
21
|
+
sections.map((section, idx) => /* @__PURE__ */ jsx(Link, { href: `#${slugify(section)}`, children: section }, `${section}-${idx}`)),
|
|
22
|
+
children
|
|
23
|
+
] });
|
|
24
|
+
var FormNavigation_default = FormNavigation;
|
|
25
|
+
|
|
26
|
+
export { FormNavigation_default as default };
|
package/dist/Submit.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import './chunk-ORMEWXMH.js';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { Button } from '@raketa-builder/ui';
|
|
5
|
+
import Context from './Context';
|
|
6
|
+
|
|
7
|
+
const Submit = ({ children }) => {
|
|
8
|
+
const { submitting } = React.useContext(Context);
|
|
9
|
+
return /* @__PURE__ */ jsx(Button, { disabled: submitting, type: "submit", variant: "primary", children });
|
|
10
|
+
};
|
|
11
|
+
var Submit_default = Submit;
|
|
12
|
+
|
|
13
|
+
export { Submit_default as default };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export { __objRest, __spreadProps, __spreadValues };
|
package/dist/index.js
CHANGED
|
@@ -1,25 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import './chunk-ORMEWXMH.js';
|
|
2
|
+
import Form from './Form';
|
|
3
|
+
import { Field, CustomField, CheckboxGroup, Checkbox } from './Fields';
|
|
4
|
+
import Submit from './Submit';
|
|
5
|
+
import Fieldset from './Fieldset';
|
|
6
|
+
import FormNavigation from './FormNavigation';
|
|
2
7
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
Form.Field = Field;
|
|
9
|
+
Form.CustomField = CustomField;
|
|
10
|
+
Form.CheckboxGroup = CheckboxGroup;
|
|
11
|
+
Form.Checkbox = Checkbox;
|
|
12
|
+
Form.Submit = Submit;
|
|
13
|
+
Form.Fieldset = Fieldset;
|
|
14
|
+
Form.FormNavigation = FormNavigation;
|
|
15
|
+
var index_default = Form;
|
|
8
16
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var Form__default = /*#__PURE__*/_interopDefault(Form);
|
|
12
|
-
var Submit__default = /*#__PURE__*/_interopDefault(Submit);
|
|
13
|
-
var Fieldset__default = /*#__PURE__*/_interopDefault(Fieldset);
|
|
14
|
-
var FormNavigation__default = /*#__PURE__*/_interopDefault(FormNavigation);
|
|
15
|
-
|
|
16
|
-
Form__default.default.Field = Fields.Field;
|
|
17
|
-
Form__default.default.CustomField = Fields.CustomField;
|
|
18
|
-
Form__default.default.CheckboxGroup = Fields.CheckboxGroup;
|
|
19
|
-
Form__default.default.Checkbox = Fields.Checkbox;
|
|
20
|
-
Form__default.default.Submit = Submit__default.default;
|
|
21
|
-
Form__default.default.Fieldset = Fieldset__default.default;
|
|
22
|
-
Form__default.default.FormNavigation = FormNavigation__default.default;
|
|
23
|
-
var index_default = Form__default.default;
|
|
24
|
-
|
|
25
|
-
module.exports = index_default;
|
|
17
|
+
export { index_default as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raketa-builder/next-form",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -8,19 +8,20 @@
|
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"import":
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
}
|
|
12
15
|
},
|
|
13
|
-
"./*":
|
|
14
|
-
"import": "./dist/*.js"
|
|
15
|
-
}
|
|
16
|
+
"./*": "./*"
|
|
16
17
|
},
|
|
17
18
|
"files": [
|
|
18
19
|
"dist"
|
|
19
20
|
],
|
|
20
21
|
"license": "MIT",
|
|
21
22
|
"scripts": {
|
|
22
|
-
"build": "tsup
|
|
23
|
-
"dev": "tsup
|
|
23
|
+
"build": "tsup",
|
|
24
|
+
"dev": "tsup --watch",
|
|
24
25
|
"format": "prettier --write .",
|
|
25
26
|
"lint": "biome lint --max-diagnostics=5000 ."
|
|
26
27
|
},
|
|
@@ -29,7 +30,7 @@
|
|
|
29
30
|
"react-dom": "19.1.0"
|
|
30
31
|
},
|
|
31
32
|
"dependencies": {
|
|
32
|
-
"@raketa-builder/ui": "1.3.
|
|
33
|
+
"@raketa-builder/ui": "1.3.11"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"@biomejs/biome": "1.9.4",
|