@wix/headless-forms 0.0.16 → 0.0.18
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/README.md +2 -9
- package/cjs/dist/react/Form.js +17 -6
- package/cjs/dist/react/core/Form.d.ts +3 -1
- package/cjs/dist/react/core/Form.js +4 -1
- package/cjs/dist/react/index.d.ts +1 -1
- package/cjs/dist/react/index.js +4 -2
- package/cjs/dist/react/types.d.ts +11 -0
- package/cjs/dist/services/form-service.d.ts +5 -1
- package/cjs/dist/services/form-service.js +14 -8
- package/cjs/dist/services/utils/file-upload-utils.d.ts +2 -0
- package/cjs/dist/services/utils/file-upload-utils.js +39 -0
- package/cjs/dist/services/utils/index.d.ts +1 -0
- package/cjs/dist/services/utils/index.js +6 -0
- package/dist/react/Form.js +17 -6
- package/dist/react/core/Form.d.ts +3 -1
- package/dist/react/core/Form.js +4 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +1 -1
- package/dist/react/types.d.ts +11 -0
- package/dist/services/form-service.d.ts +5 -1
- package/dist/services/form-service.js +14 -8
- package/dist/services/utils/file-upload-utils.d.ts +2 -0
- package/dist/services/utils/file-upload-utils.js +34 -0
- package/dist/services/utils/index.d.ts +1 -0
- package/dist/services/utils/index.js +1 -0
- package/package.json +5 -4
- package/cjs/dist/react/Phone.d.ts +0 -47
- package/cjs/dist/react/Phone.js +0 -56
- package/dist/react/Phone.d.ts +0 -47
- package/dist/react/Phone.js +0 -50
package/README.md
CHANGED
|
@@ -27,16 +27,9 @@ All changes should be documented using `jsdoc` and updating `docs/api/FORM_INTER
|
|
|
27
27
|
## Publishing
|
|
28
28
|
|
|
29
29
|
1. **Update Version**
|
|
30
|
-
|
|
31
|
-
- Create PR and merge to main branch
|
|
30
|
+
The version will be updated automatically by Falcon after merging to master
|
|
32
31
|
|
|
33
|
-
2. **
|
|
34
|
-
- Go to GitHub Actions
|
|
35
|
-
- Run "Publish Package" workflow
|
|
36
|
-
- Enter package name: `forms`
|
|
37
|
-
- Monitor the workflow for successful completion
|
|
38
|
-
|
|
39
|
-
3. **Update SDK Exports**
|
|
32
|
+
2. **Update SDK Exports**
|
|
40
33
|
- Go to Form app in Wix Dev Center
|
|
41
34
|
- Update SDK exports extensions:
|
|
42
35
|
- "Forms SDK Exports Components"
|
package/cjs/dist/react/Form.js
CHANGED
|
@@ -41,6 +41,7 @@ const form_public_1 = require("@wix/form-public");
|
|
|
41
41
|
const Form_js_1 = require("./core/Form.js");
|
|
42
42
|
const FieldContext_js_1 = require("./context/FieldContext.js");
|
|
43
43
|
const FieldLayoutContext_js_1 = require("./context/FieldLayoutContext.js");
|
|
44
|
+
const utils_1 = require("../services/utils");
|
|
44
45
|
var TestIds;
|
|
45
46
|
(function (TestIds) {
|
|
46
47
|
TestIds["formRoot"] = "form-root";
|
|
@@ -523,21 +524,30 @@ exports.Submitted = react_1.default.forwardRef((props, ref) => {
|
|
|
523
524
|
* ```
|
|
524
525
|
*/
|
|
525
526
|
exports.Fields = react_1.default.forwardRef((props, ref) => {
|
|
526
|
-
const [formValues, setFormValues] = (0, react_1.useState)({});
|
|
527
527
|
const [formErrors, setFormErrors] = (0, react_1.useState)([]);
|
|
528
|
-
const handleFormChange = (0, react_1.useCallback)((values) => {
|
|
529
|
-
setFormValues(values);
|
|
530
|
-
}, []);
|
|
531
528
|
const handleFormValidate = (0, react_1.useCallback)((errors) => {
|
|
532
529
|
setFormErrors(errors);
|
|
533
530
|
}, []);
|
|
534
|
-
return ((0, jsx_runtime_1.jsx)(Form_js_1.Fields, { children: ({ form, submitForm }) => {
|
|
531
|
+
return ((0, jsx_runtime_1.jsx)(Form_js_1.Fields, { children: ({ form, formValues, submitForm, handleForm }) => {
|
|
535
532
|
if (!form)
|
|
536
533
|
return null;
|
|
537
|
-
return ((0, jsx_runtime_1.jsx)("div", { ref: ref, children: (0, jsx_runtime_1.jsx)(form_public_1.FormProvider, { currency: 'USD', locale: 'en', children: (0, jsx_runtime_1.jsx)(FieldsWithForm, { form: form, values: formValues, onChange:
|
|
534
|
+
return ((0, jsx_runtime_1.jsx)("div", { ref: ref, children: (0, jsx_runtime_1.jsx)(form_public_1.FormProvider, { currency: 'USD', locale: 'en', children: (0, jsx_runtime_1.jsx)(FieldsWithForm, { form: form, values: formValues, onChange: handleForm, errors: formErrors, onValidate: handleFormValidate, fields: props.fieldMap, submitForm: submitForm, rowGapClassname: props.rowGapClassname, columnGapClassname: props.columnGapClassname }) }) }));
|
|
538
535
|
} }));
|
|
539
536
|
});
|
|
540
537
|
const FieldsWithForm = ({ form, submitForm, values, onChange, errors, onValidate, fields: fieldMap, rowGapClassname, columnGapClassname, }) => {
|
|
538
|
+
const coreUploadFile = async ({ file, formId, }) => {
|
|
539
|
+
const uploadUrl = await (0, utils_1.getUploadUrl)(formId, file);
|
|
540
|
+
if (uploadUrl === undefined) {
|
|
541
|
+
return { isPrivate: false };
|
|
542
|
+
}
|
|
543
|
+
const url = await (0, utils_1.uploadFile)(file, uploadUrl);
|
|
544
|
+
return {
|
|
545
|
+
id: '123123',
|
|
546
|
+
isPrivate: false,
|
|
547
|
+
displayName: file.name,
|
|
548
|
+
url,
|
|
549
|
+
};
|
|
550
|
+
};
|
|
541
551
|
const formData = (0, form_public_1.useForm)({
|
|
542
552
|
form,
|
|
543
553
|
values,
|
|
@@ -545,6 +555,7 @@ const FieldsWithForm = ({ form, submitForm, values, onChange, errors, onValidate
|
|
|
545
555
|
onChange,
|
|
546
556
|
onValidate,
|
|
547
557
|
submitForm,
|
|
558
|
+
uploadFile: coreUploadFile,
|
|
548
559
|
fieldMap,
|
|
549
560
|
});
|
|
550
561
|
if (!formData)
|
|
@@ -225,8 +225,10 @@ export declare function Submitted(props: FormSubmittedProps): import("react").Re
|
|
|
225
225
|
export interface FieldsRenderProps {
|
|
226
226
|
/** The form data, or null if not loaded */
|
|
227
227
|
form: forms.Form | null;
|
|
228
|
+
formValues: FormValues;
|
|
228
229
|
/** Function to submit the form with values */
|
|
229
|
-
submitForm: (
|
|
230
|
+
submitForm: () => Promise<void>;
|
|
231
|
+
handleForm: (formValues: FormValues) => Promise<void>;
|
|
230
232
|
}
|
|
231
233
|
/**
|
|
232
234
|
* Props for Fields headless component
|
|
@@ -230,11 +230,14 @@ function Submitted(props) {
|
|
|
230
230
|
* ```
|
|
231
231
|
*/
|
|
232
232
|
function Fields(props) {
|
|
233
|
-
const { formSignal, submitForm } = (0, services_manager_react_1.useService)(form_service_js_1.FormServiceDefinition);
|
|
233
|
+
const { formSignal, submitForm, handleForm, formValuesSignal } = (0, services_manager_react_1.useService)(form_service_js_1.FormServiceDefinition);
|
|
234
234
|
const form = formSignal.get();
|
|
235
|
+
const formValues = formValuesSignal.get();
|
|
235
236
|
return props.children({
|
|
236
237
|
form,
|
|
238
|
+
formValues,
|
|
237
239
|
submitForm,
|
|
240
|
+
handleForm,
|
|
238
241
|
});
|
|
239
242
|
}
|
|
240
243
|
/**
|
package/cjs/dist/react/index.js
CHANGED
|
@@ -36,7 +36,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
36
36
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.Form = void 0;
|
|
39
|
+
exports.FileUpload = exports.PhoneField = exports.Form = void 0;
|
|
40
40
|
exports.Form = __importStar(require("./Form.js"));
|
|
41
41
|
__exportStar(require("./types.js"), exports);
|
|
42
|
-
|
|
42
|
+
var form_public_1 = require("@wix/form-public");
|
|
43
|
+
Object.defineProperty(exports, "PhoneField", { enumerable: true, get: function () { return form_public_1.PhoneField; } });
|
|
44
|
+
Object.defineProperty(exports, "FileUpload", { enumerable: true, get: function () { return form_public_1.FileUpload; } });
|
|
@@ -1,3 +1,14 @@
|
|
|
1
1
|
import { type CheckboxGroupProps, type CheckboxProps, type PhoneInputProps, type DateInputProps, type DatePickerProps, type DateTimeInputProps, type DropdownProps, type FileUploadProps, type MultilineAddressProps, type NumberInputProps, type RadioGroupProps, type RatingInputProps, type RichTextProps, type SignatureProps, type SubmitButtonProps, type TagsProps, type TextAreaProps, type TextInputProps, type TimeInputProps, type ProductListProps, type FixedPaymentProps, type PaymentInputProps, type DonationProps, type AppointmentProps, type ImageChoiceProps } from '@wix/form-public';
|
|
2
2
|
export type { CheckboxGroupProps, CheckboxProps, PhoneInputProps, DateInputProps, DatePickerProps, DateTimeInputProps, DropdownProps, FileUploadProps, MultilineAddressProps, NumberInputProps, RadioGroupProps, RatingInputProps, RichTextProps, SignatureProps, SubmitButtonProps, TagsProps, TextAreaProps, TextInputProps, TimeInputProps, ProductListProps, FixedPaymentProps, PaymentInputProps, DonationProps, AppointmentProps, ImageChoiceProps, };
|
|
3
3
|
export type FormValues = Record<string, any>;
|
|
4
|
+
export interface UploadFileParams {
|
|
5
|
+
file: File;
|
|
6
|
+
formId: string;
|
|
7
|
+
uploadTarget: string;
|
|
8
|
+
}
|
|
9
|
+
export interface FileDescriptor {
|
|
10
|
+
id?: string;
|
|
11
|
+
displayName?: string;
|
|
12
|
+
url?: string;
|
|
13
|
+
isPrivate: boolean;
|
|
14
|
+
}
|
|
@@ -32,8 +32,12 @@ export interface FormServiceAPI {
|
|
|
32
32
|
errorSignal: ReadOnlySignal<string | null>;
|
|
33
33
|
/** Reactive signal containing submission response state */
|
|
34
34
|
submitResponseSignal: ReadOnlySignal<SubmitResponse>;
|
|
35
|
+
/** Reactive signal that contains all actual formValues */
|
|
36
|
+
formValuesSignal: ReadOnlySignal<FormValues>;
|
|
35
37
|
/** Function to submit form with current values */
|
|
36
|
-
submitForm: (
|
|
38
|
+
submitForm: () => Promise<void>;
|
|
39
|
+
/** Function to handle changed form with new values */
|
|
40
|
+
handleForm: (formValues: FormValues) => Promise<void>;
|
|
37
41
|
}
|
|
38
42
|
/**
|
|
39
43
|
* Service definition for the Form service.
|
|
@@ -47,6 +47,7 @@ exports.FormService = services_definitions_1.implementService.withConfig()(expor
|
|
|
47
47
|
});
|
|
48
48
|
const hasSchema = 'form' in config;
|
|
49
49
|
const formSignal = signalsService.signal(hasSchema ? config.form : null);
|
|
50
|
+
const formValuesSignal = signalsService.signal({});
|
|
50
51
|
if (!hasSchema) {
|
|
51
52
|
loadForm(config.formId, config.namespace, config.additionalMetadata);
|
|
52
53
|
}
|
|
@@ -88,7 +89,7 @@ exports.FormService = services_definitions_1.implementService.withConfig()(expor
|
|
|
88
89
|
* Submits the form with the provided values.
|
|
89
90
|
* Uses custom handler if provided in config, otherwise uses default submission.
|
|
90
91
|
*/
|
|
91
|
-
async function submitForm(
|
|
92
|
+
async function submitForm() {
|
|
92
93
|
const form = formSignal.get();
|
|
93
94
|
if (!form) {
|
|
94
95
|
console.error('Cannot submit: form not loaded');
|
|
@@ -98,8 +99,8 @@ exports.FormService = services_definitions_1.implementService.withConfig()(expor
|
|
|
98
99
|
const formId = form._id ? form._id : form.id;
|
|
99
100
|
submitResponseSignal.set({ type: 'loading' });
|
|
100
101
|
try {
|
|
101
|
-
const handler =
|
|
102
|
-
const response = await handler(formId,
|
|
102
|
+
const handler = await defaultSubmitHandler;
|
|
103
|
+
const response = await handler(formId, formValuesSignal.get());
|
|
103
104
|
submitResponseSignal.set(response);
|
|
104
105
|
}
|
|
105
106
|
catch (error) {
|
|
@@ -110,12 +111,17 @@ exports.FormService = services_definitions_1.implementService.withConfig()(expor
|
|
|
110
111
|
});
|
|
111
112
|
}
|
|
112
113
|
}
|
|
114
|
+
async function handleForm(formValues) {
|
|
115
|
+
formValuesSignal.set(formValues);
|
|
116
|
+
}
|
|
113
117
|
return {
|
|
114
|
-
formSignal
|
|
115
|
-
isLoadingSignal
|
|
116
|
-
errorSignal
|
|
117
|
-
submitResponseSignal
|
|
118
|
-
|
|
118
|
+
formSignal,
|
|
119
|
+
isLoadingSignal,
|
|
120
|
+
errorSignal,
|
|
121
|
+
submitResponseSignal,
|
|
122
|
+
formValuesSignal,
|
|
123
|
+
submitForm,
|
|
124
|
+
handleForm,
|
|
119
125
|
};
|
|
120
126
|
});
|
|
121
127
|
function buildFormFetchQueryParams({ id, namespace, additionalMetadata, }) {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.uploadFile = exports.getUploadUrl = void 0;
|
|
4
|
+
const forms_1 = require("@wix/forms");
|
|
5
|
+
const essentials_1 = require("@wix/essentials");
|
|
6
|
+
const getUploadUrl = async (formId, file) => {
|
|
7
|
+
try {
|
|
8
|
+
const { uploadUrl } = await forms_1.submissions.getMediaUploadUrl(formId, file.name, file.type);
|
|
9
|
+
return uploadUrl;
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
console.error('Cannot get uploadUrl for file upload!');
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
exports.getUploadUrl = getUploadUrl;
|
|
17
|
+
const uploadFile = async (file, uploadUrl) => {
|
|
18
|
+
const headers = {
|
|
19
|
+
'Content-Type': 'application/octet-stream',
|
|
20
|
+
};
|
|
21
|
+
const { withErrorHandler } = essentials_1.errorHandler;
|
|
22
|
+
try {
|
|
23
|
+
const response = await withErrorHandler(() => essentials_1.httpClient.fetchWithAuth(uploadUrl, {
|
|
24
|
+
method: 'PUT',
|
|
25
|
+
body: file,
|
|
26
|
+
headers,
|
|
27
|
+
}), {});
|
|
28
|
+
const data = await response.json();
|
|
29
|
+
if (!data) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
return data.file.url;
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
const resolvedError = essentials_1.errorHandler.getResolvedError(e);
|
|
36
|
+
throw resolvedError;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
exports.uploadFile = uploadFile;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getUploadUrl, uploadFile } from './file-upload-utils';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.uploadFile = exports.getUploadUrl = void 0;
|
|
4
|
+
var file_upload_utils_1 = require("./file-upload-utils");
|
|
5
|
+
Object.defineProperty(exports, "getUploadUrl", { enumerable: true, get: function () { return file_upload_utils_1.getUploadUrl; } });
|
|
6
|
+
Object.defineProperty(exports, "uploadFile", { enumerable: true, get: function () { return file_upload_utils_1.uploadFile; } });
|
package/dist/react/Form.js
CHANGED
|
@@ -5,6 +5,7 @@ import { useForm, FormProvider, } from '@wix/form-public';
|
|
|
5
5
|
import { Root as CoreRoot, Loading as CoreLoading, LoadingError as CoreLoadingError, Error as CoreError, Submitted as CoreSubmitted, Fields as CoreFields, Field as CoreField, } from './core/Form.js';
|
|
6
6
|
import { FieldContext, useFieldContext, } from './context/FieldContext.js';
|
|
7
7
|
import { FieldLayoutProvider, useFieldLayout, } from './context/FieldLayoutContext.js';
|
|
8
|
+
import { getUploadUrl, uploadFile } from '../services/utils';
|
|
8
9
|
var TestIds;
|
|
9
10
|
(function (TestIds) {
|
|
10
11
|
TestIds["formRoot"] = "form-root";
|
|
@@ -487,21 +488,30 @@ export const Submitted = React.forwardRef((props, ref) => {
|
|
|
487
488
|
* ```
|
|
488
489
|
*/
|
|
489
490
|
export const Fields = React.forwardRef((props, ref) => {
|
|
490
|
-
const [formValues, setFormValues] = useState({});
|
|
491
491
|
const [formErrors, setFormErrors] = useState([]);
|
|
492
|
-
const handleFormChange = useCallback((values) => {
|
|
493
|
-
setFormValues(values);
|
|
494
|
-
}, []);
|
|
495
492
|
const handleFormValidate = useCallback((errors) => {
|
|
496
493
|
setFormErrors(errors);
|
|
497
494
|
}, []);
|
|
498
|
-
return (_jsx(CoreFields, { children: ({ form, submitForm }) => {
|
|
495
|
+
return (_jsx(CoreFields, { children: ({ form, formValues, submitForm, handleForm }) => {
|
|
499
496
|
if (!form)
|
|
500
497
|
return null;
|
|
501
|
-
return (_jsx("div", { ref: ref, children: _jsx(FormProvider, { currency: 'USD', locale: 'en', children: _jsx(FieldsWithForm, { form: form, values: formValues, onChange:
|
|
498
|
+
return (_jsx("div", { ref: ref, children: _jsx(FormProvider, { currency: 'USD', locale: 'en', children: _jsx(FieldsWithForm, { form: form, values: formValues, onChange: handleForm, errors: formErrors, onValidate: handleFormValidate, fields: props.fieldMap, submitForm: submitForm, rowGapClassname: props.rowGapClassname, columnGapClassname: props.columnGapClassname }) }) }));
|
|
502
499
|
} }));
|
|
503
500
|
});
|
|
504
501
|
const FieldsWithForm = ({ form, submitForm, values, onChange, errors, onValidate, fields: fieldMap, rowGapClassname, columnGapClassname, }) => {
|
|
502
|
+
const coreUploadFile = async ({ file, formId, }) => {
|
|
503
|
+
const uploadUrl = await getUploadUrl(formId, file);
|
|
504
|
+
if (uploadUrl === undefined) {
|
|
505
|
+
return { isPrivate: false };
|
|
506
|
+
}
|
|
507
|
+
const url = await uploadFile(file, uploadUrl);
|
|
508
|
+
return {
|
|
509
|
+
id: '123123',
|
|
510
|
+
isPrivate: false,
|
|
511
|
+
displayName: file.name,
|
|
512
|
+
url,
|
|
513
|
+
};
|
|
514
|
+
};
|
|
505
515
|
const formData = useForm({
|
|
506
516
|
form,
|
|
507
517
|
values,
|
|
@@ -509,6 +519,7 @@ const FieldsWithForm = ({ form, submitForm, values, onChange, errors, onValidate
|
|
|
509
519
|
onChange,
|
|
510
520
|
onValidate,
|
|
511
521
|
submitForm,
|
|
522
|
+
uploadFile: coreUploadFile,
|
|
512
523
|
fieldMap,
|
|
513
524
|
});
|
|
514
525
|
if (!formData)
|
|
@@ -225,8 +225,10 @@ export declare function Submitted(props: FormSubmittedProps): import("react").Re
|
|
|
225
225
|
export interface FieldsRenderProps {
|
|
226
226
|
/** The form data, or null if not loaded */
|
|
227
227
|
form: forms.Form | null;
|
|
228
|
+
formValues: FormValues;
|
|
228
229
|
/** Function to submit the form with values */
|
|
229
|
-
submitForm: (
|
|
230
|
+
submitForm: () => Promise<void>;
|
|
231
|
+
handleForm: (formValues: FormValues) => Promise<void>;
|
|
230
232
|
}
|
|
231
233
|
/**
|
|
232
234
|
* Props for Fields headless component
|
package/dist/react/core/Form.js
CHANGED
|
@@ -221,11 +221,14 @@ export function Submitted(props) {
|
|
|
221
221
|
* ```
|
|
222
222
|
*/
|
|
223
223
|
export function Fields(props) {
|
|
224
|
-
const { formSignal, submitForm } = useService(FormServiceDefinition);
|
|
224
|
+
const { formSignal, submitForm, handleForm, formValuesSignal } = useService(FormServiceDefinition);
|
|
225
225
|
const form = formSignal.get();
|
|
226
|
+
const formValues = formValuesSignal.get();
|
|
226
227
|
return props.children({
|
|
227
228
|
form,
|
|
229
|
+
formValues,
|
|
228
230
|
submitForm,
|
|
231
|
+
handleForm,
|
|
229
232
|
});
|
|
230
233
|
}
|
|
231
234
|
/**
|
package/dist/react/index.d.ts
CHANGED
package/dist/react/index.js
CHANGED
package/dist/react/types.d.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
1
|
import { type CheckboxGroupProps, type CheckboxProps, type PhoneInputProps, type DateInputProps, type DatePickerProps, type DateTimeInputProps, type DropdownProps, type FileUploadProps, type MultilineAddressProps, type NumberInputProps, type RadioGroupProps, type RatingInputProps, type RichTextProps, type SignatureProps, type SubmitButtonProps, type TagsProps, type TextAreaProps, type TextInputProps, type TimeInputProps, type ProductListProps, type FixedPaymentProps, type PaymentInputProps, type DonationProps, type AppointmentProps, type ImageChoiceProps } from '@wix/form-public';
|
|
2
2
|
export type { CheckboxGroupProps, CheckboxProps, PhoneInputProps, DateInputProps, DatePickerProps, DateTimeInputProps, DropdownProps, FileUploadProps, MultilineAddressProps, NumberInputProps, RadioGroupProps, RatingInputProps, RichTextProps, SignatureProps, SubmitButtonProps, TagsProps, TextAreaProps, TextInputProps, TimeInputProps, ProductListProps, FixedPaymentProps, PaymentInputProps, DonationProps, AppointmentProps, ImageChoiceProps, };
|
|
3
3
|
export type FormValues = Record<string, any>;
|
|
4
|
+
export interface UploadFileParams {
|
|
5
|
+
file: File;
|
|
6
|
+
formId: string;
|
|
7
|
+
uploadTarget: string;
|
|
8
|
+
}
|
|
9
|
+
export interface FileDescriptor {
|
|
10
|
+
id?: string;
|
|
11
|
+
displayName?: string;
|
|
12
|
+
url?: string;
|
|
13
|
+
isPrivate: boolean;
|
|
14
|
+
}
|
|
@@ -32,8 +32,12 @@ export interface FormServiceAPI {
|
|
|
32
32
|
errorSignal: ReadOnlySignal<string | null>;
|
|
33
33
|
/** Reactive signal containing submission response state */
|
|
34
34
|
submitResponseSignal: ReadOnlySignal<SubmitResponse>;
|
|
35
|
+
/** Reactive signal that contains all actual formValues */
|
|
36
|
+
formValuesSignal: ReadOnlySignal<FormValues>;
|
|
35
37
|
/** Function to submit form with current values */
|
|
36
|
-
submitForm: (
|
|
38
|
+
submitForm: () => Promise<void>;
|
|
39
|
+
/** Function to handle changed form with new values */
|
|
40
|
+
handleForm: (formValues: FormValues) => Promise<void>;
|
|
37
41
|
}
|
|
38
42
|
/**
|
|
39
43
|
* Service definition for the Form service.
|
|
@@ -43,6 +43,7 @@ export const FormService = implementService.withConfig()(FormServiceDefinition,
|
|
|
43
43
|
});
|
|
44
44
|
const hasSchema = 'form' in config;
|
|
45
45
|
const formSignal = signalsService.signal(hasSchema ? config.form : null);
|
|
46
|
+
const formValuesSignal = signalsService.signal({});
|
|
46
47
|
if (!hasSchema) {
|
|
47
48
|
loadForm(config.formId, config.namespace, config.additionalMetadata);
|
|
48
49
|
}
|
|
@@ -84,7 +85,7 @@ export const FormService = implementService.withConfig()(FormServiceDefinition,
|
|
|
84
85
|
* Submits the form with the provided values.
|
|
85
86
|
* Uses custom handler if provided in config, otherwise uses default submission.
|
|
86
87
|
*/
|
|
87
|
-
async function submitForm(
|
|
88
|
+
async function submitForm() {
|
|
88
89
|
const form = formSignal.get();
|
|
89
90
|
if (!form) {
|
|
90
91
|
console.error('Cannot submit: form not loaded');
|
|
@@ -94,8 +95,8 @@ export const FormService = implementService.withConfig()(FormServiceDefinition,
|
|
|
94
95
|
const formId = form._id ? form._id : form.id;
|
|
95
96
|
submitResponseSignal.set({ type: 'loading' });
|
|
96
97
|
try {
|
|
97
|
-
const handler =
|
|
98
|
-
const response = await handler(formId,
|
|
98
|
+
const handler = await defaultSubmitHandler;
|
|
99
|
+
const response = await handler(formId, formValuesSignal.get());
|
|
99
100
|
submitResponseSignal.set(response);
|
|
100
101
|
}
|
|
101
102
|
catch (error) {
|
|
@@ -106,12 +107,17 @@ export const FormService = implementService.withConfig()(FormServiceDefinition,
|
|
|
106
107
|
});
|
|
107
108
|
}
|
|
108
109
|
}
|
|
110
|
+
async function handleForm(formValues) {
|
|
111
|
+
formValuesSignal.set(formValues);
|
|
112
|
+
}
|
|
109
113
|
return {
|
|
110
|
-
formSignal
|
|
111
|
-
isLoadingSignal
|
|
112
|
-
errorSignal
|
|
113
|
-
submitResponseSignal
|
|
114
|
-
|
|
114
|
+
formSignal,
|
|
115
|
+
isLoadingSignal,
|
|
116
|
+
errorSignal,
|
|
117
|
+
submitResponseSignal,
|
|
118
|
+
formValuesSignal,
|
|
119
|
+
submitForm,
|
|
120
|
+
handleForm,
|
|
115
121
|
};
|
|
116
122
|
});
|
|
117
123
|
function buildFormFetchQueryParams({ id, namespace, additionalMetadata, }) {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { submissions } from '@wix/forms';
|
|
2
|
+
import { httpClient, errorHandler } from '@wix/essentials';
|
|
3
|
+
export const getUploadUrl = async (formId, file) => {
|
|
4
|
+
try {
|
|
5
|
+
const { uploadUrl } = await submissions.getMediaUploadUrl(formId, file.name, file.type);
|
|
6
|
+
return uploadUrl;
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
console.error('Cannot get uploadUrl for file upload!');
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
export const uploadFile = async (file, uploadUrl) => {
|
|
14
|
+
const headers = {
|
|
15
|
+
'Content-Type': 'application/octet-stream',
|
|
16
|
+
};
|
|
17
|
+
const { withErrorHandler } = errorHandler;
|
|
18
|
+
try {
|
|
19
|
+
const response = await withErrorHandler(() => httpClient.fetchWithAuth(uploadUrl, {
|
|
20
|
+
method: 'PUT',
|
|
21
|
+
body: file,
|
|
22
|
+
headers,
|
|
23
|
+
}), {});
|
|
24
|
+
const data = await response.json();
|
|
25
|
+
if (!data) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
return data.file.url;
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
const resolvedError = errorHandler.getResolvedError(e);
|
|
32
|
+
throw resolvedError;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getUploadUrl, uploadFile } from './file-upload-utils';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getUploadUrl, uploadFile } from './file-upload-utils';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/headless-forms",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -42,11 +42,12 @@
|
|
|
42
42
|
"vitest": "^3.1.4"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@wix/form-public": "^0.
|
|
45
|
+
"@wix/form-public": "^0.68.0",
|
|
46
46
|
"@wix/forms": "^1.0.331",
|
|
47
47
|
"@wix/headless-utils": "0.0.7",
|
|
48
48
|
"@wix/services-definitions": "^0.1.4",
|
|
49
|
-
"@wix/services-manager-react": "^0.1.26"
|
|
49
|
+
"@wix/services-manager-react": "^0.1.26",
|
|
50
|
+
"react-aria-components": "^1.13.0"
|
|
50
51
|
},
|
|
51
52
|
"publishConfig": {
|
|
52
53
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -58,5 +59,5 @@
|
|
|
58
59
|
"groupId": "com.wixpress.headless-components"
|
|
59
60
|
}
|
|
60
61
|
},
|
|
61
|
-
"falconPackageHash": "
|
|
62
|
+
"falconPackageHash": "f3edf9d5732afbeb7ae504e3914dcd5e290272761dec8d784dc0e8f8"
|
|
62
63
|
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
export interface PhoneFieldProps {
|
|
3
|
-
id: string;
|
|
4
|
-
children: React.ReactNode;
|
|
5
|
-
asChild?: boolean;
|
|
6
|
-
className?: string;
|
|
7
|
-
}
|
|
8
|
-
export interface PhoneLabelProps {
|
|
9
|
-
children: React.ReactNode;
|
|
10
|
-
asChild?: boolean;
|
|
11
|
-
className?: string;
|
|
12
|
-
}
|
|
13
|
-
export interface PhoneLabelRequiredProps {
|
|
14
|
-
required?: boolean;
|
|
15
|
-
children?: React.ReactNode;
|
|
16
|
-
asChild?: boolean;
|
|
17
|
-
className?: string;
|
|
18
|
-
}
|
|
19
|
-
export declare const Required: React.ForwardRefExoticComponent<PhoneLabelRequiredProps & React.RefAttributes<HTMLSpanElement>>;
|
|
20
|
-
interface PhoneLabelComponent extends React.ForwardRefExoticComponent<PhoneLabelProps & React.RefAttributes<HTMLDivElement>> {
|
|
21
|
-
Required: typeof Required;
|
|
22
|
-
}
|
|
23
|
-
export declare const Label: PhoneLabelComponent;
|
|
24
|
-
export interface PhoneErrorProps {
|
|
25
|
-
children?: React.ReactNode;
|
|
26
|
-
asChild?: boolean;
|
|
27
|
-
className?: string;
|
|
28
|
-
}
|
|
29
|
-
declare const Error: React.ForwardRefExoticComponent<PhoneErrorProps & React.RefAttributes<HTMLDivElement>>;
|
|
30
|
-
export interface CountryCodeProps {
|
|
31
|
-
asChild?: boolean;
|
|
32
|
-
className?: string;
|
|
33
|
-
}
|
|
34
|
-
declare const CountryCode: React.ForwardRefExoticComponent<CountryCodeProps & React.RefAttributes<HTMLDivElement>>;
|
|
35
|
-
export interface PhoneFieldInputProps {
|
|
36
|
-
asChild?: boolean;
|
|
37
|
-
className?: string;
|
|
38
|
-
}
|
|
39
|
-
declare const Input: React.ForwardRefExoticComponent<PhoneFieldInputProps & React.RefAttributes<HTMLDivElement>>;
|
|
40
|
-
interface PhoneFieldComponent extends React.ForwardRefExoticComponent<PhoneFieldProps & React.RefAttributes<HTMLDivElement>> {
|
|
41
|
-
Label: typeof Label;
|
|
42
|
-
Error: typeof Error;
|
|
43
|
-
Input: typeof Input;
|
|
44
|
-
CountryCode: typeof CountryCode;
|
|
45
|
-
}
|
|
46
|
-
export declare const PhoneField: PhoneFieldComponent;
|
|
47
|
-
export {};
|
package/cjs/dist/react/Phone.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.PhoneField = exports.Label = exports.Required = void 0;
|
|
7
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
-
const react_1 = __importDefault(require("react"));
|
|
9
|
-
const react_2 = require("@wix/headless-forms/react");
|
|
10
|
-
const form_public_1 = require("@wix/form-public");
|
|
11
|
-
const Root = react_1.default.forwardRef((props, ref) => {
|
|
12
|
-
const { id, children, asChild, className } = props;
|
|
13
|
-
const { description } = (0, form_public_1.useFieldProps)();
|
|
14
|
-
return ((0, jsx_runtime_1.jsx)(react_2.Form.Field, { ref: ref, id: id, asChild: asChild, className: className, children: (0, jsx_runtime_1.jsx)(react_2.Form.Field.InputWrapper, { children: (0, jsx_runtime_1.jsx)(react_2.Form.Field.Input, { description: description, children: children }) }) }));
|
|
15
|
-
});
|
|
16
|
-
Root.displayName = 'PhoneField';
|
|
17
|
-
const LabelRoot = react_1.default.forwardRef((props, ref) => {
|
|
18
|
-
const { asChild, className, children } = props;
|
|
19
|
-
const { id, label, showLabel } = (0, form_public_1.useFieldProps)();
|
|
20
|
-
if (!showLabel) {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
return ((0, jsx_runtime_1.jsx)(react_2.Form.Field.Label, { ref: ref, asChild: asChild, className: className, children: (0, jsx_runtime_1.jsxs)("label", { htmlFor: id, children: [label, children] }) }));
|
|
24
|
-
});
|
|
25
|
-
LabelRoot.displayName = 'PhoneField.Label';
|
|
26
|
-
exports.Required = react_1.default.forwardRef((props, ref) => {
|
|
27
|
-
const { required } = (0, form_public_1.useFieldProps)();
|
|
28
|
-
return (0, jsx_runtime_1.jsx)(react_2.Form.Field.Label.Required, { ...props, ref: ref, required: required });
|
|
29
|
-
});
|
|
30
|
-
exports.Required.displayName = 'PhoneField.Label.Required';
|
|
31
|
-
exports.Label = LabelRoot;
|
|
32
|
-
exports.Label.Required = exports.Required;
|
|
33
|
-
const Error = react_1.default.forwardRef((props, ref) => {
|
|
34
|
-
const { children, ...rest } = props;
|
|
35
|
-
const { errorMessage } = (0, form_public_1.useFieldProps)();
|
|
36
|
-
return ((0, jsx_runtime_1.jsx)(react_2.Form.Field.Error, { ref: ref, ...rest, children: errorMessage }));
|
|
37
|
-
});
|
|
38
|
-
Error.displayName = 'PhoneField.Error';
|
|
39
|
-
const CountryCode = react_1.default.forwardRef((props, ref) => {
|
|
40
|
-
const { asChild, className, ...rest } = props;
|
|
41
|
-
const { id, countryCodes, defaultCountryCode, readOnly, onChange, onBlur, onFocus, } = (0, form_public_1.useFieldProps)();
|
|
42
|
-
return ((0, jsx_runtime_1.jsx)(react_2.Form.Field.Input, { ref: ref, asChild: asChild, className: className, ...rest, children: (0, jsx_runtime_1.jsx)("select", { id: `${id}-country`, defaultValue: defaultCountryCode || '', disabled: readOnly, onChange: (e) => onChange?.(e.target.value), onBlur: () => onBlur?.(), onFocus: () => onFocus?.(), children: countryCodes?.map((code) => ((0, jsx_runtime_1.jsx)("option", { value: code, children: code }, code))) }) }));
|
|
43
|
-
});
|
|
44
|
-
CountryCode.displayName = 'PhoneField.CountryCode';
|
|
45
|
-
const Input = react_1.default.forwardRef((props, ref) => {
|
|
46
|
-
const { asChild, className, ...rest } = props;
|
|
47
|
-
const { id, value, required, readOnly, placeholder, onChange, onBlur, onFocus, description, } = (0, form_public_1.useFieldProps)();
|
|
48
|
-
const descriptionId = description ? `${id}-description` : undefined;
|
|
49
|
-
return ((0, jsx_runtime_1.jsx)(react_2.Form.Field.Input, { ref: ref, asChild: asChild, className: className, ...rest, children: (0, jsx_runtime_1.jsx)("input", { id: id, type: "tel", value: value || '', required: required, readOnly: readOnly, placeholder: placeholder, "aria-describedby": descriptionId, "aria-invalid": !!(required && !value), "aria-required": required, onChange: (e) => onChange?.(e.target.value), onBlur: () => onBlur?.(), onFocus: () => onFocus?.() }) }));
|
|
50
|
-
});
|
|
51
|
-
Input.displayName = 'PhoneField.Input';
|
|
52
|
-
exports.PhoneField = Root;
|
|
53
|
-
exports.PhoneField.Label = exports.Label;
|
|
54
|
-
exports.PhoneField.Error = Error;
|
|
55
|
-
exports.PhoneField.Input = Input;
|
|
56
|
-
exports.PhoneField.CountryCode = CountryCode;
|
package/dist/react/Phone.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
export interface PhoneFieldProps {
|
|
3
|
-
id: string;
|
|
4
|
-
children: React.ReactNode;
|
|
5
|
-
asChild?: boolean;
|
|
6
|
-
className?: string;
|
|
7
|
-
}
|
|
8
|
-
export interface PhoneLabelProps {
|
|
9
|
-
children: React.ReactNode;
|
|
10
|
-
asChild?: boolean;
|
|
11
|
-
className?: string;
|
|
12
|
-
}
|
|
13
|
-
export interface PhoneLabelRequiredProps {
|
|
14
|
-
required?: boolean;
|
|
15
|
-
children?: React.ReactNode;
|
|
16
|
-
asChild?: boolean;
|
|
17
|
-
className?: string;
|
|
18
|
-
}
|
|
19
|
-
export declare const Required: React.ForwardRefExoticComponent<PhoneLabelRequiredProps & React.RefAttributes<HTMLSpanElement>>;
|
|
20
|
-
interface PhoneLabelComponent extends React.ForwardRefExoticComponent<PhoneLabelProps & React.RefAttributes<HTMLDivElement>> {
|
|
21
|
-
Required: typeof Required;
|
|
22
|
-
}
|
|
23
|
-
export declare const Label: PhoneLabelComponent;
|
|
24
|
-
export interface PhoneErrorProps {
|
|
25
|
-
children?: React.ReactNode;
|
|
26
|
-
asChild?: boolean;
|
|
27
|
-
className?: string;
|
|
28
|
-
}
|
|
29
|
-
declare const Error: React.ForwardRefExoticComponent<PhoneErrorProps & React.RefAttributes<HTMLDivElement>>;
|
|
30
|
-
export interface CountryCodeProps {
|
|
31
|
-
asChild?: boolean;
|
|
32
|
-
className?: string;
|
|
33
|
-
}
|
|
34
|
-
declare const CountryCode: React.ForwardRefExoticComponent<CountryCodeProps & React.RefAttributes<HTMLDivElement>>;
|
|
35
|
-
export interface PhoneFieldInputProps {
|
|
36
|
-
asChild?: boolean;
|
|
37
|
-
className?: string;
|
|
38
|
-
}
|
|
39
|
-
declare const Input: React.ForwardRefExoticComponent<PhoneFieldInputProps & React.RefAttributes<HTMLDivElement>>;
|
|
40
|
-
interface PhoneFieldComponent extends React.ForwardRefExoticComponent<PhoneFieldProps & React.RefAttributes<HTMLDivElement>> {
|
|
41
|
-
Label: typeof Label;
|
|
42
|
-
Error: typeof Error;
|
|
43
|
-
Input: typeof Input;
|
|
44
|
-
CountryCode: typeof CountryCode;
|
|
45
|
-
}
|
|
46
|
-
export declare const PhoneField: PhoneFieldComponent;
|
|
47
|
-
export {};
|
package/dist/react/Phone.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { Form } from '@wix/headless-forms/react';
|
|
4
|
-
import { useFieldProps } from '@wix/form-public';
|
|
5
|
-
const Root = React.forwardRef((props, ref) => {
|
|
6
|
-
const { id, children, asChild, className } = props;
|
|
7
|
-
const { description } = useFieldProps();
|
|
8
|
-
return (_jsx(Form.Field, { ref: ref, id: id, asChild: asChild, className: className, children: _jsx(Form.Field.InputWrapper, { children: _jsx(Form.Field.Input, { description: description, children: children }) }) }));
|
|
9
|
-
});
|
|
10
|
-
Root.displayName = 'PhoneField';
|
|
11
|
-
const LabelRoot = React.forwardRef((props, ref) => {
|
|
12
|
-
const { asChild, className, children } = props;
|
|
13
|
-
const { id, label, showLabel } = useFieldProps();
|
|
14
|
-
if (!showLabel) {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
return (_jsx(Form.Field.Label, { ref: ref, asChild: asChild, className: className, children: _jsxs("label", { htmlFor: id, children: [label, children] }) }));
|
|
18
|
-
});
|
|
19
|
-
LabelRoot.displayName = 'PhoneField.Label';
|
|
20
|
-
export const Required = React.forwardRef((props, ref) => {
|
|
21
|
-
const { required } = useFieldProps();
|
|
22
|
-
return _jsx(Form.Field.Label.Required, { ...props, ref: ref, required: required });
|
|
23
|
-
});
|
|
24
|
-
Required.displayName = 'PhoneField.Label.Required';
|
|
25
|
-
export const Label = LabelRoot;
|
|
26
|
-
Label.Required = Required;
|
|
27
|
-
const Error = React.forwardRef((props, ref) => {
|
|
28
|
-
const { children, ...rest } = props;
|
|
29
|
-
const { errorMessage } = useFieldProps();
|
|
30
|
-
return (_jsx(Form.Field.Error, { ref: ref, ...rest, children: errorMessage }));
|
|
31
|
-
});
|
|
32
|
-
Error.displayName = 'PhoneField.Error';
|
|
33
|
-
const CountryCode = React.forwardRef((props, ref) => {
|
|
34
|
-
const { asChild, className, ...rest } = props;
|
|
35
|
-
const { id, countryCodes, defaultCountryCode, readOnly, onChange, onBlur, onFocus, } = useFieldProps();
|
|
36
|
-
return (_jsx(Form.Field.Input, { ref: ref, asChild: asChild, className: className, ...rest, children: _jsx("select", { id: `${id}-country`, defaultValue: defaultCountryCode || '', disabled: readOnly, onChange: (e) => onChange?.(e.target.value), onBlur: () => onBlur?.(), onFocus: () => onFocus?.(), children: countryCodes?.map((code) => (_jsx("option", { value: code, children: code }, code))) }) }));
|
|
37
|
-
});
|
|
38
|
-
CountryCode.displayName = 'PhoneField.CountryCode';
|
|
39
|
-
const Input = React.forwardRef((props, ref) => {
|
|
40
|
-
const { asChild, className, ...rest } = props;
|
|
41
|
-
const { id, value, required, readOnly, placeholder, onChange, onBlur, onFocus, description, } = useFieldProps();
|
|
42
|
-
const descriptionId = description ? `${id}-description` : undefined;
|
|
43
|
-
return (_jsx(Form.Field.Input, { ref: ref, asChild: asChild, className: className, ...rest, children: _jsx("input", { id: id, type: "tel", value: value || '', required: required, readOnly: readOnly, placeholder: placeholder, "aria-describedby": descriptionId, "aria-invalid": !!(required && !value), "aria-required": required, onChange: (e) => onChange?.(e.target.value), onBlur: () => onBlur?.(), onFocus: () => onFocus?.() }) }));
|
|
44
|
-
});
|
|
45
|
-
Input.displayName = 'PhoneField.Input';
|
|
46
|
-
export const PhoneField = Root;
|
|
47
|
-
PhoneField.Label = Label;
|
|
48
|
-
PhoneField.Error = Error;
|
|
49
|
-
PhoneField.Input = Input;
|
|
50
|
-
PhoneField.CountryCode = CountryCode;
|