@cedarjs/forms 0.0.4

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 (48) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +33 -0
  3. package/dist/CheckboxField.d.ts +7 -0
  4. package/dist/CheckboxField.d.ts.map +1 -0
  5. package/dist/CheckboxField.js +85 -0
  6. package/dist/FieldError.d.ts +43 -0
  7. package/dist/FieldError.d.ts.map +1 -0
  8. package/dist/FieldError.js +56 -0
  9. package/dist/FieldProps.d.ts +26 -0
  10. package/dist/FieldProps.d.ts.map +1 -0
  11. package/dist/FieldProps.js +16 -0
  12. package/dist/Form.d.ts +41 -0
  13. package/dist/Form.d.ts.map +1 -0
  14. package/dist/Form.js +69 -0
  15. package/dist/FormError.d.ts +36 -0
  16. package/dist/FormError.d.ts.map +1 -0
  17. package/dist/FormError.js +90 -0
  18. package/dist/InputComponents.d.ts +30 -0
  19. package/dist/InputComponents.d.ts.map +1 -0
  20. package/dist/InputComponents.js +180 -0
  21. package/dist/Label.d.ts +10 -0
  22. package/dist/Label.d.ts.map +1 -0
  23. package/dist/Label.js +58 -0
  24. package/dist/SelectField.d.ts +7 -0
  25. package/dist/SelectField.d.ts.map +1 -0
  26. package/dist/SelectField.js +76 -0
  27. package/dist/ServerErrorsContext.d.ts +8 -0
  28. package/dist/ServerErrorsContext.d.ts.map +1 -0
  29. package/dist/ServerErrorsContext.js +41 -0
  30. package/dist/Submit.d.ts +16 -0
  31. package/dist/Submit.d.ts.map +1 -0
  32. package/dist/Submit.js +39 -0
  33. package/dist/TextAreaField.d.ts +9 -0
  34. package/dist/TextAreaField.d.ts.map +1 -0
  35. package/dist/TextAreaField.js +76 -0
  36. package/dist/coercion.d.ts +59 -0
  37. package/dist/coercion.d.ts.map +1 -0
  38. package/dist/coercion.js +178 -0
  39. package/dist/index.d.ts +64 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +118 -0
  42. package/dist/useErrorStyles.d.ts +18 -0
  43. package/dist/useErrorStyles.d.ts.map +1 -0
  44. package/dist/useErrorStyles.js +68 -0
  45. package/dist/useRegister.d.ts +32 -0
  46. package/dist/useRegister.d.ts.map +1 -0
  47. package/dist/useRegister.js +69 -0
  48. package/package.json +65 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Cedar
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.
package/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Forms
2
+
3
+ <!-- toc -->
4
+
5
+ - [Purpose and Vision](#Purpose-and-Vision)
6
+ - [Package Lead](#Package-Lead)
7
+ - [Roadmap](#Roadmap)
8
+ - [Contributing](#Contributing)
9
+ - [FAQ](#FAQ)
10
+
11
+ ## Purpose and Vision
12
+
13
+ Summarize the project's values, purpose, and aspirational vision.
14
+
15
+ ## Package Lead
16
+
17
+ Identify the decision maker and/or go-to for questions.
18
+
19
+ ## Roadmap
20
+
21
+ Similar to Purpose and Vision, but more concrete, comprising near-term priorities and long-term goals.
22
+
23
+ ## Contributing
24
+
25
+ Explains how to contribute by addressing the following three points:
26
+
27
+ 1. Core technologies a contributor should be a familiar with.
28
+ 2. How this package fits into the Redwood Framework, if it depends on other Redwood packages, etc.
29
+ 3. The structure of the package and/or an explanation of its contents.
30
+
31
+ ## FAQ
32
+
33
+ Answers to frequently asked questions.
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import type { FieldProps } from './FieldProps';
3
+ export interface CheckboxFieldProps extends Omit<FieldProps<HTMLInputElement>, 'type' | 'emptyAs'>, Omit<React.ComponentPropsWithRef<'input'>, 'name' | 'type'> {
4
+ }
5
+ /** Renders an `<input type="checkbox">` field */
6
+ export declare const CheckboxField: React.ForwardRefExoticComponent<Omit<CheckboxFieldProps, "ref"> & React.RefAttributes<HTMLInputElement>>;
7
+ //# sourceMappingURL=CheckboxField.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CheckboxField.d.ts","sourceRoot":"","sources":["../src/CheckboxField.tsx"],"names":[],"mappings":"AACA,OAAO,KAAqB,MAAM,OAAO,CAAA;AAEzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAI9C,MAAM,WAAW,kBACf,SAAQ,IAAI,CAAC,UAAU,CAAC,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,EAC5D,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAAG;AAElE,iDAAiD;AACjD,eAAO,MAAM,aAAa,0GAkDzB,CAAA"}
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var CheckboxField_exports = {};
30
+ __export(CheckboxField_exports, {
31
+ CheckboxField: () => CheckboxField
32
+ });
33
+ module.exports = __toCommonJS(CheckboxField_exports);
34
+ var import_react = __toESM(require("react"));
35
+ var import_useErrorStyles = require("./useErrorStyles");
36
+ var import_useRegister = require("./useRegister");
37
+ const CheckboxField = (0, import_react.forwardRef)(
38
+ ({
39
+ name,
40
+ id,
41
+ // for useErrorStyles
42
+ errorClassName,
43
+ errorStyle,
44
+ className,
45
+ style,
46
+ // for useRegister
47
+ validation,
48
+ onBlur,
49
+ onChange,
50
+ ...rest
51
+ }, ref) => {
52
+ const styles = (0, import_useErrorStyles.useErrorStyles)({
53
+ name,
54
+ errorClassName,
55
+ errorStyle,
56
+ className,
57
+ style
58
+ });
59
+ const type = "checkbox";
60
+ const useRegisterReturn = (0, import_useRegister.useRegister)(
61
+ {
62
+ name,
63
+ validation,
64
+ onBlur,
65
+ onChange,
66
+ type
67
+ },
68
+ ref
69
+ );
70
+ return /* @__PURE__ */ import_react.default.createElement(
71
+ "input",
72
+ {
73
+ id: id || name,
74
+ ...rest,
75
+ type,
76
+ ...styles,
77
+ ...useRegisterReturn
78
+ }
79
+ );
80
+ }
81
+ );
82
+ // Annotate the CommonJS export names for ESM import in node:
83
+ 0 && (module.exports = {
84
+ CheckboxField
85
+ });
@@ -0,0 +1,43 @@
1
+ import React from 'react';
2
+ export interface FieldErrorProps extends React.ComponentPropsWithoutRef<'span'> {
3
+ /**
4
+ * The name of the field the `<FieldError>`'s associated with.
5
+ */
6
+ name: string;
7
+ }
8
+ /**
9
+ * Renders a `<span>` with an error message if there's a validation error on the corresponding field.
10
+ * If no error message is provided, a default one is used based on the type of validation that caused the error.
11
+ *
12
+ * @example Displaying a validation error message with `<FieldError>`
13
+ *
14
+ * `<FieldError>` doesn't render (i.e. returns `null`) when there's no error on `<TextField>`.
15
+ *
16
+ * ```jsx
17
+ * <Label name="name" errorClassName="error">
18
+ * Name
19
+ * </Label>
20
+ * <TextField
21
+ * name="name"
22
+ * validation={{ required: true }}
23
+ * errorClassName="error"
24
+ * />
25
+ * <FieldError name="name" className="error" />
26
+ * ```
27
+ *
28
+ * @see {@link https://redwoodjs.com/docs/tutorial/chapter3/forms#fielderror}
29
+ *
30
+ * @privateRemarks
31
+ *
32
+ * This is basically a helper for a common pattern you see in `react-hook-form`:
33
+ *
34
+ * ```jsx
35
+ * <form onSubmit={handleSubmit(onSubmit)}>
36
+ * <input {...register("firstName", { required: true })} />
37
+ * {errors.firstName?.type === 'required' && "First name is required"}
38
+ * ```
39
+ *
40
+ * @see {@link https://react-hook-form.com/get-started#Handleerrors}
41
+ */
42
+ export declare const FieldError: ({ name, ...rest }: FieldErrorProps) => React.JSX.Element | null;
43
+ //# sourceMappingURL=FieldError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FieldError.d.ts","sourceRoot":"","sources":["../src/FieldError.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,MAAM,WAAW,eACf,SAAQ,KAAK,CAAC,wBAAwB,CAAC,MAAM,CAAC;IAC9C;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;CACb;AAYD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,UAAU,sBAAuB,eAAe,6BAe5D,CAAA"}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var FieldError_exports = {};
30
+ __export(FieldError_exports, {
31
+ FieldError: () => FieldError
32
+ });
33
+ module.exports = __toCommonJS(FieldError_exports);
34
+ var import_react = __toESM(require("react"));
35
+ var import_react_hook_form = require("react-hook-form");
36
+ const DEFAULT_MESSAGES = {
37
+ required: "is required",
38
+ pattern: "is not formatted correctly",
39
+ minLength: "is too short",
40
+ maxLength: "is too long",
41
+ min: "is too low",
42
+ max: "is too high",
43
+ validate: "is not valid"
44
+ };
45
+ const FieldError = ({ name, ...rest }) => {
46
+ const {
47
+ formState: { errors }
48
+ } = (0, import_react_hook_form.useFormContext)();
49
+ const validationError = (0, import_react_hook_form.get)(errors, name);
50
+ const errorMessage = validationError && (validationError.message || `${name} ${DEFAULT_MESSAGES[validationError.type]}`);
51
+ return validationError ? /* @__PURE__ */ import_react.default.createElement("span", { ...rest }, errorMessage) : null;
52
+ };
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {
55
+ FieldError
56
+ });
@@ -0,0 +1,26 @@
1
+ import type { EmptyAsValue, RedwoodRegisterOptions } from './coercion';
2
+ /**
3
+ * The main interface, just to have some sort of source of truth.
4
+ *
5
+ * @typeParam E - The type of element; we're only ever working with a few HTMLElements.
6
+ *
7
+ * `extends` constrains the generic while `=` provides a default.
8
+ *
9
+ * @see {@link https://www.typescriptlang.org/docs/handbook/2/generics.html#generic-constraints}
10
+ *
11
+ * @internal
12
+ */
13
+ export interface FieldProps<Element extends HTMLTextAreaElement | HTMLSelectElement | HTMLInputElement = HTMLInputElement> {
14
+ name: string;
15
+ id?: string;
16
+ emptyAs?: EmptyAsValue;
17
+ errorClassName?: string;
18
+ errorStyle?: React.CSSProperties;
19
+ className?: string;
20
+ style?: React.CSSProperties;
21
+ validation?: RedwoodRegisterOptions;
22
+ type?: string;
23
+ onBlur?: React.FocusEventHandler<Element>;
24
+ onChange?: React.ChangeEventHandler<Element>;
25
+ }
26
+ //# sourceMappingURL=FieldProps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FieldProps.d.ts","sourceRoot":"","sources":["../src/FieldProps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAEtE;;;;;;;;;;GAUG;AACH,MAAM,WAAW,UAAU,CACzB,OAAO,SACH,mBAAmB,GACnB,iBAAiB,GACjB,gBAAgB,GAAG,gBAAgB;IAEvC,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,OAAO,CAAC,EAAE,YAAY,CAAA;IACtB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,UAAU,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;IAChC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;IAC3B,UAAU,CAAC,EAAE,sBAAsB,CAAA;IACnC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,KAAK,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAA;IACzC,QAAQ,CAAC,EAAE,KAAK,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAA;CAC7C"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var FieldProps_exports = {};
16
+ module.exports = __toCommonJS(FieldProps_exports);
package/dist/Form.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ import React from 'react';
2
+ import type { FieldValues, UseFormReturn, UseFormProps } from 'react-hook-form';
3
+ export interface FormProps<TFieldValues extends FieldValues> extends Omit<React.ComponentPropsWithRef<'form'>, 'onSubmit'> {
4
+ error?: any;
5
+ /**
6
+ * The methods returned by `useForm`.
7
+ * This prop is only necessary if you've called `useForm` yourself to get
8
+ * access to one of its functions, like `reset`.
9
+ *
10
+ * @example
11
+ *
12
+ * ```typescript
13
+ * const formMethods = useForm<FormData>()
14
+ *
15
+ * const onSubmit = (data: FormData) => {
16
+ * sendDataToServer(data)
17
+ * formMethods.reset()
18
+ * }
19
+ *
20
+ * return (
21
+ * <Form formMethods={formMethods} onSubmit={onSubmit}>
22
+ * )
23
+ * ```
24
+ */
25
+ formMethods?: UseFormReturn<TFieldValues>;
26
+ /**
27
+ * Configures how React Hook Form performs validation, among other things.
28
+ *
29
+ * @example
30
+ *
31
+ * ```jsx
32
+ * <Form config={{ mode: 'onBlur' }}>
33
+ * ```
34
+ *
35
+ * @see {@link https://react-hook-form.com/api/useform}
36
+ */
37
+ config?: UseFormProps<TFieldValues>;
38
+ onSubmit?: (value: TFieldValues, event?: React.BaseSyntheticEvent) => void;
39
+ }
40
+ export declare const Form: <TFieldValues extends FieldValues>(props: FormProps<TFieldValues> & React.RefAttributes<HTMLFormElement>) => React.ReactElement | null;
41
+ //# sourceMappingURL=Form.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../src/Form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAqB,MAAM,OAAO,CAAA;AAIzC,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAI/E,MAAM,WAAW,SAAS,CAAC,YAAY,SAAS,WAAW,CACzD,SAAQ,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC;IAC7D,KAAK,CAAC,EAAE,GAAG,CAAA;IACX;;;;;;;;;;;;;;;;;;;OAmBG;IACH,WAAW,CAAC,EAAE,aAAa,CAAC,YAAY,CAAC,CAAA;IACzC;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,YAAY,CAAC,YAAY,CAAC,CAAA;IACnC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,kBAAkB,KAAK,IAAI,CAAA;CAC3E;AAgDD,eAAO,MAAM,IAAI,EAA4B,CAAC,YAAgC,SAAX,WAAW,EAC5E,KAAK,EAAE,SAAS,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,eAAe,CAAC,KAClE,KAAK,CAAC,YAAY,GAAG,IAAI,CAAA"}
package/dist/Form.js ADDED
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var Form_exports = {};
30
+ __export(Form_exports, {
31
+ Form: () => Form
32
+ });
33
+ module.exports = __toCommonJS(Form_exports);
34
+ var import_react = __toESM(require("react"));
35
+ var import_react_hook_form = require("react-hook-form");
36
+ var import_ServerErrorsContext = require("./ServerErrorsContext");
37
+ function FormInner({
38
+ config,
39
+ error: errorProps,
40
+ formMethods: propFormMethods,
41
+ onSubmit,
42
+ children,
43
+ ...rest
44
+ }, ref) {
45
+ const hookFormMethods = (0, import_react_hook_form.useForm)(config);
46
+ const formMethods = propFormMethods || hookFormMethods;
47
+ return /* @__PURE__ */ import_react.default.createElement(
48
+ "form",
49
+ {
50
+ ref,
51
+ ...rest,
52
+ onSubmit: formMethods.handleSubmit(
53
+ (data, event) => onSubmit?.(data, event)
54
+ )
55
+ },
56
+ /* @__PURE__ */ import_react.default.createElement(
57
+ import_ServerErrorsContext.ServerErrorsContext.Provider,
58
+ {
59
+ value: errorProps?.graphQLErrors?.[0]?.extensions?.properties?.messages || {}
60
+ },
61
+ /* @__PURE__ */ import_react.default.createElement(import_react_hook_form.FormProvider, { ...formMethods }, children)
62
+ )
63
+ );
64
+ }
65
+ const Form = (0, import_react.forwardRef)(FormInner);
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ Form
69
+ });
@@ -0,0 +1,36 @@
1
+ import React from 'react';
2
+ import type { GraphQLFormattedError } from 'graphql';
3
+ export interface ServerParseError extends Error {
4
+ response: Response;
5
+ statusCode: number;
6
+ bodyText: string;
7
+ }
8
+ export interface ServerError extends Error {
9
+ response: Response;
10
+ statusCode: number;
11
+ result: Record<string, any>;
12
+ }
13
+ export interface RWGqlError {
14
+ message: string;
15
+ graphQLErrors: readonly GraphQLFormattedError[];
16
+ networkError: Error | ServerParseError | ServerError | null;
17
+ }
18
+ export type RwGqlErrorProperties = Record<string, Record<string, string[]>>;
19
+ interface FormErrorProps {
20
+ error?: RWGqlError;
21
+ wrapperClassName?: string;
22
+ wrapperStyle?: React.CSSProperties;
23
+ titleClassName?: string;
24
+ titleStyle?: React.CSSProperties;
25
+ listClassName?: string;
26
+ listStyle?: React.CSSProperties;
27
+ listItemClassName?: string;
28
+ listItemStyle?: React.CSSProperties;
29
+ }
30
+ /**
31
+ * Big error message at the top of the page explaining everything that's wrong
32
+ * with the form fields in this form
33
+ */
34
+ declare const FormError: ({ error, wrapperClassName, wrapperStyle, titleClassName, titleStyle, listClassName, listStyle, listItemClassName, listItemStyle, }: FormErrorProps) => React.JSX.Element | null;
35
+ export default FormError;
36
+ //# sourceMappingURL=FormError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormError.d.ts","sourceRoot":"","sources":["../src/FormError.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAEpD,MAAM,WAAW,gBAAiB,SAAQ,KAAK;IAC7C,QAAQ,EAAE,QAAQ,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,WAAY,SAAQ,KAAK;IACxC,QAAQ,EAAE,QAAQ,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAC5B;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAA;IACf,aAAa,EAAE,SAAS,qBAAqB,EAAE,CAAA;IAC/C,YAAY,EAAE,KAAK,GAAG,gBAAgB,GAAG,WAAW,GAAG,IAAI,CAAA;CAC5D;AAED,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAA;AAE3E,UAAU,cAAc;IACtB,KAAK,CAAC,EAAE,UAAU,CAAA;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,YAAY,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;IAClC,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,UAAU,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;IAChC,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,SAAS,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;IAC/B,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,aAAa,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;CACpC;AAED;;;GAGG;AACH,QAAA,MAAM,SAAS,uIAUZ,cAAc,6BAyEhB,CAAA;AAED,eAAe,SAAS,CAAA"}
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var FormError_exports = {};
30
+ __export(FormError_exports, {
31
+ default: () => FormError_default
32
+ });
33
+ module.exports = __toCommonJS(FormError_exports);
34
+ var import_react = __toESM(require("react"));
35
+ const FormError = ({
36
+ error,
37
+ wrapperClassName,
38
+ wrapperStyle,
39
+ titleClassName,
40
+ titleStyle,
41
+ listClassName,
42
+ listStyle,
43
+ listItemClassName,
44
+ listItemStyle
45
+ }) => {
46
+ if (!error) {
47
+ return null;
48
+ }
49
+ let rootMessage = error.message;
50
+ const messages = [];
51
+ const hasGraphQLError = !!error.graphQLErrors?.[0];
52
+ const hasNetworkError = !!error.networkError && Object.keys(error.networkError).length > 0;
53
+ if (hasGraphQLError) {
54
+ rootMessage = error.graphQLErrors[0].message ?? "Something went wrong";
55
+ if (error.graphQLErrors[0]?.extensions?.code === "BAD_USER_INPUT") {
56
+ rootMessage = "Errors prevented this form from being saved";
57
+ }
58
+ const properties = error.graphQLErrors[0].extensions?.["properties"];
59
+ const propertyMessages = properties?.["messages"];
60
+ if (propertyMessages) {
61
+ for (const e in propertyMessages) {
62
+ propertyMessages[e].forEach((fieldError) => {
63
+ messages.push(fieldError);
64
+ });
65
+ }
66
+ }
67
+ } else if (hasNetworkError) {
68
+ rootMessage = rootMessage ?? "An error has occurred";
69
+ if (Object.prototype.hasOwnProperty.call(error.networkError, "bodyText")) {
70
+ const netErr = error.networkError;
71
+ messages.push(`${netErr.name}: ${netErr.bodyText}`);
72
+ } else if (Object.prototype.hasOwnProperty.call(error.networkError, "result")) {
73
+ const netErr = error.networkError;
74
+ netErr.result.errors?.forEach((error2) => {
75
+ if (typeof error2.message === "string") {
76
+ if (error2.message.indexOf(";") >= 0) {
77
+ messages.push(error2.message?.split(";")[1]);
78
+ } else {
79
+ messages.push(error2.message);
80
+ }
81
+ }
82
+ });
83
+ }
84
+ }
85
+ if (!rootMessage) {
86
+ return null;
87
+ }
88
+ return /* @__PURE__ */ import_react.default.createElement("div", { className: wrapperClassName, style: wrapperStyle }, /* @__PURE__ */ import_react.default.createElement("p", { className: titleClassName, style: titleStyle }, rootMessage), messages.length > 0 && /* @__PURE__ */ import_react.default.createElement("ul", { className: listClassName, style: listStyle }, messages.map((message, index) => /* @__PURE__ */ import_react.default.createElement("li", { key: index, className: listItemClassName, style: listItemStyle }, message))));
89
+ };
90
+ var FormError_default = FormError;
@@ -0,0 +1,30 @@
1
+ import React from 'react';
2
+ import type { FieldProps } from './FieldProps';
3
+ /**
4
+ * All the types we'll be generating named `<InputFields>` for (which is basically all of them).
5
+ * Note that `'checkbox'` isn't here because we handle it separately above.
6
+ *
7
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#input_types}
8
+ */
9
+ declare const INPUT_TYPES: readonly ["button", "color", "date", "datetime-local", "email", "file", "hidden", "image", "month", "number", "password", "radio", "range", "reset", "search", "submit", "tel", "text", "time", "url", "week"];
10
+ type InputType = (typeof INPUT_TYPES)[number];
11
+ export interface InputFieldProps extends Omit<FieldProps<HTMLInputElement>, 'type'>, Omit<React.ComponentPropsWithRef<'input'>, 'name' | 'type'> {
12
+ /**
13
+ * @privateRemarks
14
+ *
15
+ * With this typing, passing `'checkbox'` to `<InputField>`'s type is an error, which,
16
+ * at face value, feels like it shouldn't be.
17
+ *
18
+ * Even though we provide a separate `<CheckboxField>`, maybe we should reconsider the typing here?
19
+ */
20
+ type?: InputType;
21
+ }
22
+ /**
23
+ * Renders an `<input>` field.
24
+ *
25
+ * @see {@link https://redwoodjs.com/docs/forms#input-fields}
26
+ */
27
+ export declare const InputField: React.ForwardRefExoticComponent<Omit<InputFieldProps, "ref"> & React.RefAttributes<HTMLInputElement>>;
28
+ export declare const ButtonField: React.ForwardRefExoticComponent<Omit<InputFieldProps, "type">>, ColorField: React.ForwardRefExoticComponent<Omit<InputFieldProps, "type">>, DateField: React.ForwardRefExoticComponent<Omit<InputFieldProps, "type">>, DatetimeLocalField: React.ForwardRefExoticComponent<Omit<InputFieldProps, "type">>, EmailField: React.ForwardRefExoticComponent<Omit<InputFieldProps, "type">>, FileField: React.ForwardRefExoticComponent<Omit<InputFieldProps, "type">>, HiddenField: React.ForwardRefExoticComponent<Omit<InputFieldProps, "type">>, ImageField: React.ForwardRefExoticComponent<Omit<InputFieldProps, "type">>, MonthField: React.ForwardRefExoticComponent<Omit<InputFieldProps, "type">>, NumberField: React.ForwardRefExoticComponent<Omit<InputFieldProps, "type">>, PasswordField: React.ForwardRefExoticComponent<Omit<InputFieldProps, "type">>, RadioField: React.ForwardRefExoticComponent<Omit<InputFieldProps, "type">>, RangeField: React.ForwardRefExoticComponent<Omit<InputFieldProps, "type">>, ResetField: React.ForwardRefExoticComponent<Omit<InputFieldProps, "type">>, SearchField: React.ForwardRefExoticComponent<Omit<InputFieldProps, "type">>, SubmitField: React.ForwardRefExoticComponent<Omit<InputFieldProps, "type">>, TelField: React.ForwardRefExoticComponent<Omit<InputFieldProps, "type">>, TextField: React.ForwardRefExoticComponent<Omit<InputFieldProps, "type">>, TimeField: React.ForwardRefExoticComponent<Omit<InputFieldProps, "type">>, UrlField: React.ForwardRefExoticComponent<Omit<InputFieldProps, "type">>, WeekField: React.ForwardRefExoticComponent<Omit<InputFieldProps, "type">>;
29
+ export {};
30
+ //# sourceMappingURL=InputComponents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InputComponents.d.ts","sourceRoot":"","sources":["../src/InputComponents.tsx"],"names":[],"mappings":"AACA,OAAO,KAAqB,MAAM,OAAO,CAAA;AAIzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAI9C;;;;;GAKG;AACH,QAAA,MAAM,WAAW,gNAsBP,CAAA;AAEV,KAAK,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAA;AAE7C,MAAM,WAAW,eACf,SAAQ,IAAI,CAAC,UAAU,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC,EAChD,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7D;;;;;;;OAOG;IACH,IAAI,CAAC,EAAE,SAAS,CAAA;CACjB;AAED;;;;GAIG;AACH,eAAO,MAAM,UAAU,uGAkDtB,CAAA;AA2BD,eAAO,MACL,WAAW,kEACX,UAAU,kEACV,SAAS,kEACT,kBAAkB,kEAClB,UAAU,kEACV,SAAS,kEACT,WAAW,kEACX,UAAU,kEACV,UAAU,kEACV,WAAW,kEACX,aAAa,kEACb,UAAU,kEACV,UAAU,kEACV,UAAU,kEACV,WAAW,kEACX,WAAW,kEACX,QAAQ,kEACR,SAAS,kEACT,SAAS,kEACT,QAAQ,kEACR,SAAS,gEACQ,CAAA"}