@wix/headless-forms 0.0.1
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/cjs/dist/react/Form.d.ts +632 -0
- package/cjs/dist/react/Form.js +652 -0
- package/cjs/dist/react/constants/calling-country-codes.d.ts +242 -0
- package/cjs/dist/react/constants/calling-country-codes.js +242 -0
- package/cjs/dist/react/core/Form.d.ts +215 -0
- package/cjs/dist/react/core/Form.js +196 -0
- package/cjs/dist/react/index.d.ts +2 -0
- package/cjs/dist/react/index.js +41 -0
- package/cjs/dist/react/types.d.ts +1251 -0
- package/cjs/dist/react/types.js +2 -0
- package/cjs/dist/services/form-service.d.ts +189 -0
- package/cjs/dist/services/form-service.js +141 -0
- package/cjs/dist/services/index.d.ts +1 -0
- package/cjs/dist/services/index.js +17 -0
- package/cjs/package.json +3 -0
- package/dist/react/Form.d.ts +632 -0
- package/dist/react/Form.js +613 -0
- package/dist/react/constants/calling-country-codes.d.ts +242 -0
- package/dist/react/constants/calling-country-codes.js +241 -0
- package/dist/react/core/Form.d.ts +215 -0
- package/dist/react/core/Form.js +189 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.js +2 -0
- package/dist/react/types.d.ts +1251 -0
- package/dist/react/types.js +1 -0
- package/dist/services/form-service.d.ts +189 -0
- package/dist/services/form-service.js +137 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/package.json +49 -0
- package/react/package.json +4 -0
- package/services/package.json +4 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Root = Root;
|
|
4
|
+
exports.Loading = Loading;
|
|
5
|
+
exports.LoadingError = LoadingError;
|
|
6
|
+
exports.Error = Error;
|
|
7
|
+
exports.Submitted = Submitted;
|
|
8
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
|
+
const services_manager_react_1 = require("@wix/services-manager-react");
|
|
10
|
+
const form_service_js_1 = require("../../services/form-service.js");
|
|
11
|
+
const services_manager_1 = require("@wix/services-manager");
|
|
12
|
+
const DEFAULT_SUCCESS_MESSAGE = 'Your form has been submitted successfully.';
|
|
13
|
+
/**
|
|
14
|
+
* Root component that provides the Form service context to its children.
|
|
15
|
+
* This component sets up the necessary services for rendering and managing form data.
|
|
16
|
+
*
|
|
17
|
+
* @order 1
|
|
18
|
+
* @component
|
|
19
|
+
* @param {React.ReactNode} children - Child components that will have access to form context
|
|
20
|
+
* @param {FormServiceConfig} formServiceConfig - Configuration object containing form data
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* import { Form } from '@wix/headless-forms/react';
|
|
24
|
+
* import { loadFormServiceConfig } from '@wix/headless-forms/services';
|
|
25
|
+
*
|
|
26
|
+
* // Pattern 1: Pre-loaded form data (SSR/SSG)
|
|
27
|
+
* function FormPage({ formServiceConfig }) {
|
|
28
|
+
* return (
|
|
29
|
+
* <Form.Root formServiceConfig={formServiceConfig}>
|
|
30
|
+
* <Form.Loading>
|
|
31
|
+
* {({ isLoading }) => isLoading ? <div>Loading form...</div> : null}
|
|
32
|
+
* </Form.Loading>
|
|
33
|
+
* <Form.LoadingError>
|
|
34
|
+
* {({ error, hasError }) => hasError ? <div>{error}</div> : null}
|
|
35
|
+
* </Form.LoadingError>
|
|
36
|
+
* <Form.Fields fieldMap={FIELD_MAP} />
|
|
37
|
+
* </Form.Root>
|
|
38
|
+
* );
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* // Pattern 2: Lazy loading with formId (Client-side)
|
|
42
|
+
* function DynamicFormPage({ formId }) {
|
|
43
|
+
* return (
|
|
44
|
+
* <Form.Root formServiceConfig={{ formId }}>
|
|
45
|
+
* <Form.Loading>
|
|
46
|
+
* {({ isLoading }) => isLoading ? <div>Loading form...</div> : null}
|
|
47
|
+
* </Form.Loading>
|
|
48
|
+
* <Form.LoadingError>
|
|
49
|
+
* {({ error, hasError }) => hasError ? <div>{error}</div> : null}
|
|
50
|
+
* </Form.LoadingError>
|
|
51
|
+
* <Form.Fields fieldMap={FIELD_MAP} />
|
|
52
|
+
* </Form.Root>
|
|
53
|
+
* );
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
function Root(props) {
|
|
58
|
+
return ((0, jsx_runtime_1.jsx)(services_manager_react_1.WixServices, { servicesMap: (0, services_manager_1.createServicesMap)().addService(form_service_js_1.FormServiceDefinition, form_service_js_1.FormService, props.formServiceConfig), children: props.children }));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Headless component for form loading state access
|
|
62
|
+
*
|
|
63
|
+
* @component
|
|
64
|
+
* @param {FormLoadingProps} props - Component props
|
|
65
|
+
* @param {FormLoadingProps['children']} props.children - Render prop function that receives loading state
|
|
66
|
+
* @example
|
|
67
|
+
* ```tsx
|
|
68
|
+
* import { Form } from '@wix/headless-forms/react';
|
|
69
|
+
*
|
|
70
|
+
* function FormLoadingIndicator() {
|
|
71
|
+
* return (
|
|
72
|
+
* <Form.Loading>
|
|
73
|
+
* {({ isLoading }) => (
|
|
74
|
+
* isLoading ? (
|
|
75
|
+
* <div>Loading form...</div>
|
|
76
|
+
* ) : null
|
|
77
|
+
* )}
|
|
78
|
+
* </Form.Loading>
|
|
79
|
+
* );
|
|
80
|
+
* }
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
function Loading(props) {
|
|
84
|
+
const service = (0, services_manager_react_1.useService)(form_service_js_1.FormServiceDefinition);
|
|
85
|
+
const isLoading = service.isLoading?.get() || false;
|
|
86
|
+
return props.children({
|
|
87
|
+
isLoading,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Headless component for form error state access
|
|
92
|
+
*
|
|
93
|
+
* @component
|
|
94
|
+
* @param {FormErrorProps} props - Component props
|
|
95
|
+
* @param {FormErrorProps['children']} props.children - Render prop function that receives error state
|
|
96
|
+
* @example
|
|
97
|
+
* ```tsx
|
|
98
|
+
* import { Form } from '@wix/headless-forms/react';
|
|
99
|
+
*
|
|
100
|
+
* function FormErrorDisplay() {
|
|
101
|
+
* return (
|
|
102
|
+
* <Form.LoadingError>
|
|
103
|
+
* {({ error, hasError }) => (
|
|
104
|
+
* hasError ? (
|
|
105
|
+
* <div className="error-message">
|
|
106
|
+
* {error}
|
|
107
|
+
* </div>
|
|
108
|
+
* ) : null
|
|
109
|
+
* )}
|
|
110
|
+
* </Form.LoadingError>
|
|
111
|
+
* );
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
function LoadingError(props) {
|
|
116
|
+
const service = (0, services_manager_react_1.useService)(form_service_js_1.FormServiceDefinition);
|
|
117
|
+
const error = service.error?.get() || null;
|
|
118
|
+
const hasError = !!error;
|
|
119
|
+
return props.children({
|
|
120
|
+
error,
|
|
121
|
+
hasError,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Headless component for form submit error state access
|
|
126
|
+
*
|
|
127
|
+
* @component
|
|
128
|
+
* @param {FormSubmitErrorProps} props - Component props
|
|
129
|
+
* @param {FormSubmitErrorProps['children']} props.children - Render prop function that receives submit error state
|
|
130
|
+
* @example
|
|
131
|
+
* ```tsx
|
|
132
|
+
* import { Form } from '@wix/headless-forms/react';
|
|
133
|
+
*
|
|
134
|
+
* function FormSubmitErrorDisplay() {
|
|
135
|
+
* return (
|
|
136
|
+
* <Form.Error>
|
|
137
|
+
* {({ error, hasError }) => (
|
|
138
|
+
* hasError ? (
|
|
139
|
+
* <div className="error-message">
|
|
140
|
+
* {error}
|
|
141
|
+
* </div>
|
|
142
|
+
* ) : null
|
|
143
|
+
* )}
|
|
144
|
+
* </Form.Error>
|
|
145
|
+
* );
|
|
146
|
+
* }
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
function Error(props) {
|
|
150
|
+
const service = (0, services_manager_react_1.useService)(form_service_js_1.FormServiceDefinition);
|
|
151
|
+
const submitResponse = service.submitResponse?.get() || { type: 'idle' };
|
|
152
|
+
const error = submitResponse.type === 'error' ? submitResponse.message : null;
|
|
153
|
+
const hasError = submitResponse.type === 'error';
|
|
154
|
+
return props.children({
|
|
155
|
+
error,
|
|
156
|
+
hasError,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Headless component for form submission state access
|
|
161
|
+
*
|
|
162
|
+
* @component
|
|
163
|
+
* @param {FormSubmittedProps} props - Component props
|
|
164
|
+
* @param {FormSubmittedProps['children']} props.children - Render prop function that receives submission state
|
|
165
|
+
* @example
|
|
166
|
+
* ```tsx
|
|
167
|
+
* import { Form } from '@wix/headless-forms/react';
|
|
168
|
+
*
|
|
169
|
+
* function FormSubmittedDisplay() {
|
|
170
|
+
* return (
|
|
171
|
+
* <Form.Submitted>
|
|
172
|
+
* {({ isSubmitted, message }) => (
|
|
173
|
+
* isSubmitted ? (
|
|
174
|
+
* <div className="success-message">
|
|
175
|
+
* <h2>Thank You!</h2>
|
|
176
|
+
* <p>{message}</p>
|
|
177
|
+
* </div>
|
|
178
|
+
* ) : null
|
|
179
|
+
* )}
|
|
180
|
+
* </Form.Submitted>
|
|
181
|
+
* );
|
|
182
|
+
* }
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
function Submitted(props) {
|
|
186
|
+
const service = (0, services_manager_react_1.useService)(form_service_js_1.FormServiceDefinition);
|
|
187
|
+
const submitResponse = service.submitResponse?.get() || { type: 'idle' };
|
|
188
|
+
const isSubmitted = submitResponse.type === 'success';
|
|
189
|
+
const message = submitResponse.type === 'success'
|
|
190
|
+
? submitResponse.message || DEFAULT_SUCCESS_MESSAGE
|
|
191
|
+
: DEFAULT_SUCCESS_MESSAGE;
|
|
192
|
+
return props.children({
|
|
193
|
+
isSubmitted,
|
|
194
|
+
message,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
36
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.Form = void 0;
|
|
40
|
+
exports.Form = __importStar(require("./Form.js"));
|
|
41
|
+
__exportStar(require("./types.js"), exports);
|