@10x-media/form-builder 0.1.0-beta.0 → 0.1.0-beta.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/CHANGELOG.md +52 -0
- package/README.md +43 -1402
- package/dist/actions/buildActionBlocks.js +19 -0
- package/dist/actions/buildActionBlocks.js.map +1 -0
- package/dist/actions/builtin/confirmation.js +49 -0
- package/dist/actions/builtin/confirmation.js.map +1 -0
- package/dist/actions/builtin/emailTeam.js +46 -0
- package/dist/actions/builtin/emailTeam.js.map +1 -0
- package/dist/actions/builtin/index.d.ts +7 -0
- package/dist/actions/builtin/index.js +13 -0
- package/dist/actions/builtin/index.js.map +1 -0
- package/dist/actions/builtin/signedWebhook.js +49 -0
- package/dist/actions/builtin/signedWebhook.js.map +1 -0
- package/dist/actions/defineAction.d.ts +36 -0
- package/dist/actions/defineAction.js +6 -0
- package/dist/actions/defineAction.js.map +1 -0
- package/dist/actions/dispatch.js +48 -0
- package/dist/actions/dispatch.js.map +1 -0
- package/dist/actions/registry.d.ts +16 -0
- package/dist/actions/registry.js +16 -0
- package/dist/actions/registry.js.map +1 -0
- package/dist/actions/runActions.d.ts +9 -0
- package/dist/actions/runActions.js +34 -0
- package/dist/actions/runActions.js.map +1 -0
- package/dist/actions/sign.d.ts +7 -0
- package/dist/actions/sign.js +9 -0
- package/dist/actions/sign.js.map +1 -0
- package/dist/actions/task.js +82 -0
- package/dist/actions/task.js.map +1 -0
- package/dist/aggregation/aggregateResponses.d.ts +31 -0
- package/dist/aggregation/aggregateResponses.js +86 -0
- package/dist/aggregation/aggregateResponses.js.map +1 -0
- package/dist/aggregation/aggregateRows.d.ts +10 -0
- package/dist/aggregation/aggregateRows.js +64 -0
- package/dist/aggregation/aggregateRows.js.map +1 -0
- package/dist/aggregation/resolveResultsRequest.d.ts +32 -0
- package/dist/aggregation/resolveResultsRequest.js +56 -0
- package/dist/aggregation/resolveResultsRequest.js.map +1 -0
- package/dist/aggregation/types.d.ts +39 -0
- package/dist/calc/computeCalcFields.d.ts +15 -0
- package/dist/calc/computeCalcFields.js +27 -0
- package/dist/calc/computeCalcFields.js.map +1 -0
- package/dist/calc/evaluate.d.ts +8 -0
- package/dist/calc/evaluate.js +59 -0
- package/dist/calc/evaluate.js.map +1 -0
- package/dist/calc/normalizeCalc.d.ts +8 -0
- package/dist/calc/normalizeCalc.js +100 -0
- package/dist/calc/normalizeCalc.js.map +1 -0
- package/dist/calc/types.d.ts +28 -0
- package/dist/client/ConditionBuilder.js +121 -0
- package/dist/client/ConditionBuilder.js.map +1 -0
- package/dist/client/ConditionRow.js +150 -0
- package/dist/client/ConditionRow.js.map +1 -0
- package/dist/client/FlowBuilder.d.ts +15 -0
- package/dist/client/FlowBuilder.js +408 -0
- package/dist/client/FlowBuilder.js.map +1 -0
- package/dist/client/FormConditionField.d.ts +21 -0
- package/dist/client/FormConditionField.js +33 -0
- package/dist/client/FormConditionField.js.map +1 -0
- package/dist/client/synthesizeClientField.js +46 -0
- package/dist/client/synthesizeClientField.js.map +1 -0
- package/dist/collections/formSubmissions.js +138 -0
- package/dist/collections/formSubmissions.js.map +1 -0
- package/dist/collections/forms.js +187 -0
- package/dist/collections/forms.js.map +1 -0
- package/dist/collections/uploads.d.ts +29 -0
- package/dist/collections/uploads.js +46 -0
- package/dist/collections/uploads.js.map +1 -0
- package/dist/conditions/conditionType.js +14 -0
- package/dist/conditions/conditionType.js.map +1 -0
- package/dist/conditions/evaluate.d.ts +17 -0
- package/dist/conditions/evaluate.js +94 -0
- package/dist/conditions/evaluate.js.map +1 -0
- package/dist/conditions/fieldTypes.d.ts +9 -0
- package/dist/{fieldTypes-CzhhJXjg.js → conditions/fieldTypes.js} +2 -2
- package/dist/conditions/fieldTypes.js.map +1 -0
- package/dist/conditions/normalizeConditions.js +47 -0
- package/dist/conditions/normalizeConditions.js.map +1 -0
- package/dist/conditions/types.d.ts +8 -0
- package/dist/consent/buildConsentSourceConfig.js +49 -0
- package/dist/consent/buildConsentSourceConfig.js.map +1 -0
- package/dist/consent/builtin/index.d.ts +7 -0
- package/dist/consent/builtin/index.js +11 -0
- package/dist/consent/builtin/index.js.map +1 -0
- package/dist/consent/builtin/pageReference.js +75 -0
- package/dist/consent/builtin/pageReference.js.map +1 -0
- package/dist/consent/builtin/static.js +44 -0
- package/dist/consent/builtin/static.js.map +1 -0
- package/dist/consent/captureConsent.d.ts +28 -0
- package/dist/consent/captureConsent.js +26 -0
- package/dist/consent/captureConsent.js.map +1 -0
- package/dist/consent/defineConsentSource.d.ts +35 -0
- package/dist/consent/defineConsentSource.js +6 -0
- package/dist/consent/defineConsentSource.js.map +1 -0
- package/dist/consent/registry.d.ts +16 -0
- package/dist/consent/registry.js +16 -0
- package/dist/consent/registry.js.map +1 -0
- package/dist/consent/resolveConsentLinks.d.ts +19 -0
- package/dist/consent/resolveConsentLinks.js +26 -0
- package/dist/consent/resolveConsentLinks.js.map +1 -0
- package/dist/consent/resolvePublishedVersionRef.d.ts +17 -0
- package/dist/consent/resolvePublishedVersionRef.js +27 -0
- package/dist/consent/resolvePublishedVersionRef.js.map +1 -0
- package/dist/events/noopSink.js +6 -0
- package/dist/events/noopSink.js.map +1 -0
- package/dist/events/resolveEventSink.js +8 -0
- package/dist/events/resolveEventSink.js.map +1 -0
- package/dist/events/types.d.ts +31 -0
- package/dist/exports/client.d.ts +3 -21
- package/dist/exports/client.js +3 -319
- package/dist/exports/i18n.d.ts +3 -138
- package/dist/exports/i18n.js +2 -2
- package/dist/exports/react.d.ts +45 -550
- package/dist/exports/react.js +39 -1563
- package/dist/exports/rsc.d.ts +2 -16
- package/dist/exports/rsc.js +1 -54
- package/dist/exports/types.d.ts +27 -5
- package/dist/fields/buildFieldBlocks.js +46 -0
- package/dist/fields/buildFieldBlocks.js.map +1 -0
- package/dist/fields/builtin/calculation.js +24 -0
- package/dist/fields/builtin/calculation.js.map +1 -0
- package/dist/fields/builtin/checkbox.js +13 -0
- package/dist/fields/builtin/checkbox.js.map +1 -0
- package/dist/fields/builtin/consent.js +32 -0
- package/dist/fields/builtin/consent.js.map +1 -0
- package/dist/fields/builtin/email.js +18 -0
- package/dist/fields/builtin/email.js.map +1 -0
- package/dist/fields/builtin/file.js +40 -0
- package/dist/fields/builtin/file.js.map +1 -0
- package/dist/fields/builtin/index.js +25 -0
- package/dist/fields/builtin/index.js.map +1 -0
- package/dist/fields/builtin/number.js +17 -0
- package/dist/fields/builtin/number.js.map +1 -0
- package/dist/fields/builtin/select.js +44 -0
- package/dist/fields/builtin/select.js.map +1 -0
- package/dist/fields/builtin/text.js +13 -0
- package/dist/fields/builtin/text.js.map +1 -0
- package/dist/fields/builtin/textarea.js +13 -0
- package/dist/fields/builtin/textarea.js.map +1 -0
- package/dist/fields/defineFormField.d.ts +13 -0
- package/dist/fields/defineFormField.js +12 -0
- package/dist/fields/defineFormField.js.map +1 -0
- package/dist/fields/registry.d.ts +10 -0
- package/dist/fields/registry.js +24 -0
- package/dist/fields/registry.js.map +1 -0
- package/dist/fields/sharedConfig.js +89 -0
- package/dist/fields/sharedConfig.js.map +1 -0
- package/dist/fields/types.d.ts +88 -0
- package/dist/flow/engine.d.ts +17 -0
- package/dist/flow/engine.js +24 -0
- package/dist/flow/engine.js.map +1 -0
- package/dist/flow/normalizeFlow.js +35 -0
- package/dist/flow/normalizeFlow.js.map +1 -0
- package/dist/{types-DsJ_6kGJ.d.ts → flow/types.d.ts} +2 -2
- package/dist/index.d.ts +74 -4
- package/dist/index.js +40 -1889
- package/dist/index.js.map +1 -1
- package/dist/plugin/access.js +12 -0
- package/dist/plugin/access.js.map +1 -0
- package/dist/plugin/registerCollections.js +40 -0
- package/dist/plugin/registerCollections.js.map +1 -0
- package/dist/plugin/registerTranslations.js +19 -0
- package/dist/plugin/registerTranslations.js.map +1 -0
- package/dist/prefill/valuesFromSearchParams.d.ts +18 -0
- package/dist/prefill/valuesFromSearchParams.js +45 -0
- package/dist/prefill/valuesFromSearchParams.js.map +1 -0
- package/dist/presentations/defaults.d.ts +33 -0
- package/dist/presentations/defaults.js +35 -0
- package/dist/presentations/defaults.js.map +1 -0
- package/dist/presentations/registry.d.ts +15 -0
- package/dist/presentations/registry.js +15 -0
- package/dist/presentations/registry.js.map +1 -0
- package/dist/presentations/types.d.ts +18 -0
- package/dist/react/Form.d.ts +81 -0
- package/dist/react/Form.js +457 -0
- package/dist/react/Form.js.map +1 -0
- package/dist/react/FormContext.d.ts +16 -0
- package/dist/react/FormContext.js +14 -0
- package/dist/react/FormContext.js.map +1 -0
- package/dist/react/FormLayout.d.ts +20 -0
- package/dist/react/FormLayout.js +14 -0
- package/dist/react/FormLayout.js.map +1 -0
- package/dist/react/FormResults.d.ts +25 -0
- package/dist/react/FormResults.js +85 -0
- package/dist/react/FormResults.js.map +1 -0
- package/dist/react/Honeypot.d.ts +22 -0
- package/dist/react/Honeypot.js +38 -0
- package/dist/react/Honeypot.js.map +1 -0
- package/dist/react/Poll.d.ts +32 -0
- package/dist/react/Poll.js +77 -0
- package/dist/react/Poll.js.map +1 -0
- package/dist/react/cn.d.ts +6 -0
- package/dist/react/cn.js +8 -0
- package/dist/react/cn.js.map +1 -0
- package/dist/react/contract.d.ts +32 -0
- package/dist/react/contract.js +7 -0
- package/dist/react/contract.js.map +1 -0
- package/dist/react/events.js +14 -0
- package/dist/react/events.js.map +1 -0
- package/dist/react/fetchResults.d.ts +25 -0
- package/dist/react/fetchResults.js +31 -0
- package/dist/react/fetchResults.js.map +1 -0
- package/dist/react/presentation/Backdrop.d.ts +18 -0
- package/dist/react/presentation/Backdrop.js +14 -0
- package/dist/react/presentation/Backdrop.js.map +1 -0
- package/dist/react/presentation/DialogSurface.d.ts +35 -0
- package/dist/react/presentation/DialogSurface.js +56 -0
- package/dist/react/presentation/DialogSurface.js.map +1 -0
- package/dist/react/presentation/presentations.d.ts +7 -0
- package/dist/react/presentation/presentations.js +32 -0
- package/dist/react/presentation/presentations.js.map +1 -0
- package/dist/react/presentation/registry.d.ts +11 -0
- package/dist/react/presentation/registry.js +12 -0
- package/dist/react/presentation/registry.js.map +1 -0
- package/dist/react/presentation/types.d.ts +19 -0
- package/dist/react/presentation/useDismiss.d.ts +19 -0
- package/dist/react/presentation/useDismiss.js +33 -0
- package/dist/react/presentation/useDismiss.js.map +1 -0
- package/dist/react/presentation/useFocusTrap.d.ts +8 -0
- package/dist/react/presentation/useFocusTrap.js +35 -0
- package/dist/react/presentation/useFocusTrap.js.map +1 -0
- package/dist/react/presentation/useScrollLock.d.ts +6 -0
- package/dist/react/presentation/useScrollLock.js +18 -0
- package/dist/react/presentation/useScrollLock.js.map +1 -0
- package/dist/react/primitives/Checkbox.d.ts +26 -0
- package/dist/react/primitives/Checkbox.js +20 -0
- package/dist/react/primitives/Checkbox.js.map +1 -0
- package/dist/react/primitives/FieldShell.d.ts +31 -0
- package/dist/react/primitives/FieldShell.js +51 -0
- package/dist/react/primitives/FieldShell.js.map +1 -0
- package/dist/react/primitives/Input.d.ts +30 -0
- package/dist/react/primitives/Input.js +21 -0
- package/dist/react/primitives/Input.js.map +1 -0
- package/dist/react/primitives/Select.d.ts +34 -0
- package/dist/react/primitives/Select.js +26 -0
- package/dist/react/primitives/Select.js.map +1 -0
- package/dist/react/primitives/Textarea.d.ts +28 -0
- package/dist/react/primitives/Textarea.js +20 -0
- package/dist/react/primitives/Textarea.js.map +1 -0
- package/dist/react/recall.js +20 -0
- package/dist/react/recall.js.map +1 -0
- package/dist/react/registry.d.ts +16 -0
- package/dist/react/registry.js +16 -0
- package/dist/react/registry.js.map +1 -0
- package/dist/react/renderers/calculation.js +30 -0
- package/dist/react/renderers/calculation.js.map +1 -0
- package/dist/react/renderers/checkbox.js +35 -0
- package/dist/react/renderers/checkbox.js.map +1 -0
- package/dist/react/renderers/consent.js +54 -0
- package/dist/react/renderers/consent.js.map +1 -0
- package/dist/react/renderers/email.js +37 -0
- package/dist/react/renderers/email.js.map +1 -0
- package/dist/react/renderers/file.js +92 -0
- package/dist/react/renderers/file.js.map +1 -0
- package/dist/react/renderers/index.d.ts +8 -0
- package/dist/react/renderers/index.js +26 -0
- package/dist/react/renderers/index.js.map +1 -0
- package/dist/react/renderers/number.js +40 -0
- package/dist/react/renderers/number.js.map +1 -0
- package/dist/react/renderers/select.js +38 -0
- package/dist/react/renderers/select.js.map +1 -0
- package/dist/react/renderers/text.js +37 -0
- package/dist/react/renderers/text.js.map +1 -0
- package/dist/react/renderers/textarea.js +36 -0
- package/dist/react/renderers/textarea.js.map +1 -0
- package/dist/react/resolveForm.js +16 -0
- package/dist/react/resolveForm.js.map +1 -0
- package/dist/react/state.d.ts +15 -0
- package/dist/react/state.js +70 -0
- package/dist/react/state.js.map +1 -0
- package/dist/react/submitForm.d.ts +31 -0
- package/dist/react/submitForm.js +58 -0
- package/dist/react/submitForm.js.map +1 -0
- package/dist/react/toFormDocument.d.ts +24 -0
- package/dist/react/toFormDocument.js +22 -0
- package/dist/react/toFormDocument.js.map +1 -0
- package/dist/react/uploadFile.d.ts +23 -0
- package/dist/react/uploadFile.js +39 -0
- package/dist/react/uploadFile.js.map +1 -0
- package/dist/react/useField.d.ts +14 -0
- package/dist/react/useField.js +49 -0
- package/dist/react/useField.js.map +1 -0
- package/dist/react/useFormState.d.ts +8 -0
- package/dist/react/useFormState.js +9 -0
- package/dist/react/useFormState.js.map +1 -0
- package/dist/react/useFormStep.d.ts +8 -0
- package/dist/react/useFormStep.js +9 -0
- package/dist/react/useFormStep.js.map +1 -0
- package/dist/react/validateField.js +30 -0
- package/dist/react/validateField.js.map +1 -0
- package/dist/recall/interpolate.d.ts +10 -0
- package/dist/recall/interpolate.js +16 -0
- package/dist/recall/interpolate.js.map +1 -0
- package/dist/recall/resolver.d.ts +22 -0
- package/dist/recall/resolver.js +36 -0
- package/dist/recall/resolver.js.map +1 -0
- package/dist/spam/captcha.d.ts +12 -0
- package/dist/spam/captcha.js +11 -0
- package/dist/spam/captcha.js.map +1 -0
- package/dist/spam/constants.d.ts +12 -0
- package/dist/spam/constants.js +15 -0
- package/dist/spam/constants.js.map +1 -0
- package/dist/spam/identify.d.ts +12 -0
- package/dist/spam/identify.js +20 -0
- package/dist/spam/identify.js.map +1 -0
- package/dist/spam/rateLimiter.d.ts +18 -0
- package/dist/spam/rateLimiter.js +41 -0
- package/dist/spam/rateLimiter.js.map +1 -0
- package/dist/spam/reserved.js +30 -0
- package/dist/spam/reserved.js.map +1 -0
- package/dist/spam/resolveSpam.d.ts +12 -0
- package/dist/spam/resolveSpam.js +42 -0
- package/dist/spam/resolveSpam.js.map +1 -0
- package/dist/spam/spamGuard.js +68 -0
- package/dist/spam/spamGuard.js.map +1 -0
- package/dist/spam/types.d.ts +73 -0
- package/dist/spam/uploadHooks.js +33 -0
- package/dist/spam/uploadHooks.js.map +1 -0
- package/dist/submissions/SubmissionAnswers.d.ts +16 -0
- package/dist/submissions/SubmissionAnswers.js +57 -0
- package/dist/submissions/SubmissionAnswers.js.map +1 -0
- package/dist/submissions/runSubmission.js +205 -0
- package/dist/submissions/runSubmission.js.map +1 -0
- package/dist/submissions/types.d.ts +33 -0
- package/dist/submissions/validateSubmission.js +59 -0
- package/dist/submissions/validateSubmission.js.map +1 -0
- package/dist/translations/en.d.ts +12 -0
- package/dist/{translations-edMqq_2e.js → translations/en.js} +3 -22
- package/dist/translations/en.js.map +1 -0
- package/dist/translations/index.d.ts +14 -0
- package/dist/translations/index.js +26 -0
- package/dist/translations/index.js.map +1 -0
- package/dist/translations/keys.d.ts +132 -0
- package/dist/{keys-N5xGiUsh.js → translations/keys.js} +2 -2
- package/dist/translations/keys.js.map +1 -0
- package/dist/translations/makeTranslate.d.ts +11 -0
- package/dist/translations/makeTranslate.js +11 -0
- package/dist/translations/makeTranslate.js.map +1 -0
- package/dist/translations/server.js +25 -0
- package/dist/translations/server.js.map +1 -0
- package/dist/translations/useTranslation.js +12 -0
- package/dist/translations/useTranslation.js.map +1 -0
- package/dist/uploads/captureFileRef.d.ts +27 -0
- package/dist/uploads/captureFileRef.js +34 -0
- package/dist/uploads/captureFileRef.js.map +1 -0
- package/dist/uploads/resolveFileRef.d.ts +26 -0
- package/dist/uploads/resolveFileRef.js +44 -0
- package/dist/uploads/resolveFileRef.js.map +1 -0
- package/dist/uploads/types.d.ts +20 -0
- package/dist/validation/buildRuleBlocks.js +46 -0
- package/dist/validation/buildRuleBlocks.js.map +1 -0
- package/dist/validation/builtin/email.js +19 -0
- package/dist/validation/builtin/email.js.map +1 -0
- package/dist/validation/builtin/index.js +27 -0
- package/dist/validation/builtin/index.js.map +1 -0
- package/dist/validation/builtin/matchesField.js +20 -0
- package/dist/validation/builtin/matchesField.js.map +1 -0
- package/dist/validation/builtin/max.js +21 -0
- package/dist/validation/builtin/max.js.map +1 -0
- package/dist/validation/builtin/maxLength.js +26 -0
- package/dist/validation/builtin/maxLength.js.map +1 -0
- package/dist/validation/builtin/min.js +21 -0
- package/dist/validation/builtin/min.js.map +1 -0
- package/dist/validation/builtin/minLength.js +26 -0
- package/dist/validation/builtin/minLength.js.map +1 -0
- package/dist/validation/builtin/notAlreadySubmitted.js +32 -0
- package/dist/validation/builtin/notAlreadySubmitted.js.map +1 -0
- package/dist/validation/builtin/oneOf.js +34 -0
- package/dist/validation/builtin/oneOf.js.map +1 -0
- package/dist/validation/builtin/pattern.js +41 -0
- package/dist/validation/builtin/pattern.js.map +1 -0
- package/dist/validation/builtin/url.js +22 -0
- package/dist/validation/builtin/url.js.map +1 -0
- package/dist/validation/defineValidationRule.d.ts +12 -0
- package/dist/validation/defineValidationRule.js +11 -0
- package/dist/validation/defineValidationRule.js.map +1 -0
- package/dist/validation/message.js +14 -0
- package/dist/validation/message.js.map +1 -0
- package/dist/validation/registry.d.ts +10 -0
- package/dist/validation/registry.js +20 -0
- package/dist/validation/registry.js.map +1 -0
- package/dist/validation/runValidation.js +111 -0
- package/dist/validation/runValidation.js.map +1 -0
- package/dist/validation/types.d.ts +76 -0
- package/package.json +8 -5
- package/styles/form-builder.css +201 -11
- package/dist/constants-B-BUfetP.d.ts +0 -288
- package/dist/exports/client.js.map +0 -1
- package/dist/exports/react.js.map +0 -1
- package/dist/exports/rsc.js.map +0 -1
- package/dist/fieldTypes-B8jkNRob.d.ts +0 -188
- package/dist/fieldTypes-CzhhJXjg.js.map +0 -1
- package/dist/index-DfFYGbVF.d.ts +0 -481
- package/dist/keys-N5xGiUsh.js.map +0 -1
- package/dist/registry-CoCyhtvB.js +0 -282
- package/dist/registry-CoCyhtvB.js.map +0 -1
- package/dist/resolver-OeQyVH2N.js +0 -665
- package/dist/resolver-OeQyVH2N.js.map +0 -1
- package/dist/translations-edMqq_2e.js.map +0 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { keys } from "../translations/keys.js";
|
|
2
|
+
//#region src/presentations/defaults.ts
|
|
3
|
+
const DEFAULT_PRESENTATION_NAME = "page";
|
|
4
|
+
const defaultPresentationDescriptors = {
|
|
5
|
+
page: {
|
|
6
|
+
name: "page",
|
|
7
|
+
label: keys.presentationPage,
|
|
8
|
+
surface: "page",
|
|
9
|
+
density: "comfortable"
|
|
10
|
+
},
|
|
11
|
+
inline: {
|
|
12
|
+
name: "inline",
|
|
13
|
+
label: keys.presentationInline,
|
|
14
|
+
surface: "inline",
|
|
15
|
+
density: "comfortable"
|
|
16
|
+
},
|
|
17
|
+
modal: {
|
|
18
|
+
name: "modal",
|
|
19
|
+
label: keys.presentationModal,
|
|
20
|
+
surface: "overlay",
|
|
21
|
+
density: "comfortable",
|
|
22
|
+
dismissOnSuccess: true
|
|
23
|
+
},
|
|
24
|
+
drawer: {
|
|
25
|
+
name: "drawer",
|
|
26
|
+
label: keys.presentationDrawer,
|
|
27
|
+
surface: "overlay",
|
|
28
|
+
density: "comfortable",
|
|
29
|
+
dismissOnSuccess: true
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
export { DEFAULT_PRESENTATION_NAME, defaultPresentationDescriptors };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.js","names":[],"sources":["../../src/presentations/defaults.ts"],"sourcesContent":["import { keys } from '../translations/keys'\nimport type { PresentationDescriptor } from './types'\n\nexport const DEFAULT_PRESENTATION_NAME = 'page'\n\nexport const defaultPresentationDescriptors = {\n\tpage: { name: 'page', label: keys.presentationPage, surface: 'page', density: 'comfortable' },\n\tinline: {\n\t\tname: 'inline',\n\t\tlabel: keys.presentationInline,\n\t\tsurface: 'inline',\n\t\tdensity: 'comfortable',\n\t},\n\tmodal: {\n\t\tname: 'modal',\n\t\tlabel: keys.presentationModal,\n\t\tsurface: 'overlay',\n\t\tdensity: 'comfortable',\n\t\tdismissOnSuccess: true,\n\t},\n\tdrawer: {\n\t\tname: 'drawer',\n\t\tlabel: keys.presentationDrawer,\n\t\tsurface: 'overlay',\n\t\tdensity: 'comfortable',\n\t\tdismissOnSuccess: true,\n\t},\n} satisfies Record<string, PresentationDescriptor>\n"],"mappings":";;AAGA,MAAa,4BAA4B;AAEzC,MAAa,iCAAiC;CAC7C,MAAM;EAAE,MAAM;EAAQ,OAAO,KAAK;EAAkB,SAAS;EAAQ,SAAS;CAAc;CAC5F,QAAQ;EACP,MAAM;EACN,OAAO,KAAK;EACZ,SAAS;EACT,SAAS;CACV;CACA,OAAO;EACN,MAAM;EACN,OAAO,KAAK;EACZ,SAAS;EACT,SAAS;EACT,kBAAkB;CACnB;CACA,QAAQ;EACP,MAAM;EACN,OAAO,KAAK;EACZ,SAAS;EACT,SAAS;EACT,kBAAkB;CACnB;AACD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PresentationDescriptor } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/presentations/registry.d.ts
|
|
4
|
+
type PresentationDescriptorRegistry = Map<string, PresentationDescriptor>;
|
|
5
|
+
/** Per-name override: `false` removes, `true` keeps the default, a descriptor adds or replaces one. */
|
|
6
|
+
type PresentationDescriptorOption = boolean | PresentationDescriptor;
|
|
7
|
+
type PresentationsDescriptorConfig = Record<string, PresentationDescriptorOption>;
|
|
8
|
+
/**
|
|
9
|
+
* Resolve the active presentation descriptors from the defaults and a consumer override map.
|
|
10
|
+
* Mirrors the field-type, validation-rule, and renderer registry convention.
|
|
11
|
+
*/
|
|
12
|
+
declare const resolvePresentationDescriptors: (defaults: Record<string, PresentationDescriptor>, config?: PresentationsDescriptorConfig) => PresentationDescriptorRegistry;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { PresentationDescriptorOption, PresentationDescriptorRegistry, PresentationsDescriptorConfig, resolvePresentationDescriptors };
|
|
15
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/presentations/registry.ts
|
|
2
|
+
/**
|
|
3
|
+
* Resolve the active presentation descriptors from the defaults and a consumer override map.
|
|
4
|
+
* Mirrors the field-type, validation-rule, and renderer registry convention.
|
|
5
|
+
*/
|
|
6
|
+
const resolvePresentationDescriptors = (defaults, config = {}) => {
|
|
7
|
+
const registry = new Map(Object.entries(defaults));
|
|
8
|
+
for (const [name, option] of Object.entries(config)) if (option === false) registry.delete(name);
|
|
9
|
+
else if (option === true) {} else registry.set(name, option);
|
|
10
|
+
return registry;
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { resolvePresentationDescriptors };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","names":[],"sources":["../../src/presentations/registry.ts"],"sourcesContent":["import type { PresentationDescriptor } from './types'\n\nexport type PresentationDescriptorRegistry = Map<string, PresentationDescriptor>\n\n/** Per-name override: `false` removes, `true` keeps the default, a descriptor adds or replaces one. */\nexport type PresentationDescriptorOption = boolean | PresentationDescriptor\n\nexport type PresentationsDescriptorConfig = Record<string, PresentationDescriptorOption>\n\n/**\n * Resolve the active presentation descriptors from the defaults and a consumer override map.\n * Mirrors the field-type, validation-rule, and renderer registry convention.\n */\nexport const resolvePresentationDescriptors = (\n\tdefaults: Record<string, PresentationDescriptor>,\n\tconfig: PresentationsDescriptorConfig = {}\n): PresentationDescriptorRegistry => {\n\tconst registry: PresentationDescriptorRegistry = new Map(Object.entries(defaults))\n\tfor (const [name, option] of Object.entries(config)) {\n\t\tif (option === false) {\n\t\t\tregistry.delete(name)\n\t\t} else if (option === true) {\n\t\t\t// keep the default; no-op when no default exists for this name\n\t\t} else {\n\t\t\tregistry.set(name, option)\n\t\t}\n\t}\n\treturn registry\n}\n"],"mappings":";;;;;AAaA,MAAa,kCACZ,UACA,SAAwC,CAAC,MACL;CACpC,MAAM,WAA2C,IAAI,IAAI,OAAO,QAAQ,QAAQ,CAAC;CACjF,KAAK,MAAM,CAAC,MAAM,WAAW,OAAO,QAAQ,MAAM,GACjD,IAAI,WAAW,OACd,SAAS,OAAO,IAAI;MACd,IAAI,WAAW,MAAM,CAE5B,OACC,SAAS,IAAI,MAAM,MAAM;CAG3B,OAAO;AACR"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/presentations/types.d.ts
|
|
2
|
+
/** How a presentation surfaces the form. Drives wrapper selection and CSS. */
|
|
3
|
+
type PresentationSurface = 'inline' | 'page' | 'overlay';
|
|
4
|
+
type PresentationDensity = 'comfortable' | 'compact';
|
|
5
|
+
/**
|
|
6
|
+
* Serializable, framework-agnostic description of a presentation. The admin select and the
|
|
7
|
+
* stored `defaultPresentation` use only this; the React `Wrapper` is added in `./react`. No React here.
|
|
8
|
+
*/
|
|
9
|
+
type PresentationDescriptor = {
|
|
10
|
+
name: string; /** i18n key or literal shown in the admin select. */
|
|
11
|
+
label: string;
|
|
12
|
+
surface: PresentationSurface;
|
|
13
|
+
density: PresentationDensity; /** Overlay surfaces request dismissal after a successful submit. */
|
|
14
|
+
dismissOnSuccess?: boolean;
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
export { PresentationDensity, PresentationDescriptor, PresentationSurface };
|
|
18
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { AnyFormFieldDefinition } from "../fields/types.js";
|
|
2
|
+
import { FormFieldInstance } from "../submissions/types.js";
|
|
3
|
+
import { FormFlow } from "../flow/types.js";
|
|
4
|
+
import { RendererTranslate } from "./contract.js";
|
|
5
|
+
import { FormEventSink } from "../events/types.js";
|
|
6
|
+
import { AnyValidationRuleDefinition } from "../validation/types.js";
|
|
7
|
+
import { FormPresentation } from "./presentation/types.js";
|
|
8
|
+
import { PresentationsConfig } from "./presentation/registry.js";
|
|
9
|
+
import { RenderersConfig } from "./registry.js";
|
|
10
|
+
import { SubmitHandler } from "./submitForm.js";
|
|
11
|
+
import { ReactNode } from "react";
|
|
12
|
+
|
|
13
|
+
//#region src/react/Form.d.ts
|
|
14
|
+
type FormDocument = {
|
|
15
|
+
id: number | string;
|
|
16
|
+
fields: FormFieldInstance[];
|
|
17
|
+
flow?: FormFlow; /** Stored presentation name; overridden by the `presentation` prop. */
|
|
18
|
+
defaultPresentation?: string;
|
|
19
|
+
};
|
|
20
|
+
type FormProps = {
|
|
21
|
+
form: FormDocument;
|
|
22
|
+
fieldTypes?: AnyFormFieldDefinition[];
|
|
23
|
+
rules?: AnyValidationRuleDefinition[];
|
|
24
|
+
renderers?: RenderersConfig;
|
|
25
|
+
apiRoute?: string;
|
|
26
|
+
onSubmit?: SubmitHandler;
|
|
27
|
+
onSuccess?: (submissionId?: string) => void;
|
|
28
|
+
onError?: (message: string) => void;
|
|
29
|
+
events?: FormEventSink;
|
|
30
|
+
t?: RendererTranslate;
|
|
31
|
+
locale?: string;
|
|
32
|
+
layout?: boolean;
|
|
33
|
+
submitLabel?: string;
|
|
34
|
+
nextLabel?: string;
|
|
35
|
+
backLabel?: string; /** Label for the overlay close control (modal/drawer). */
|
|
36
|
+
closeLabel?: string;
|
|
37
|
+
successMessage?: string; /** Active presentation: a name into the registry or an inline presentation. Overrides the form's stored default. */
|
|
38
|
+
presentation?: string | FormPresentation; /** Per-render presentation overrides merged onto the defaults (add, replace, or `false` to remove). */
|
|
39
|
+
presentations?: PresentationsConfig; /** Invoked when an overlay presentation dismisses (close button, Escape, outside click, or `dismissOnSuccess`). */
|
|
40
|
+
onClose?: () => void; /** Accessible name for an overlay surface. */
|
|
41
|
+
title?: string; /** Seed initial field values (e.g. from `valuesFromSearchParams`). Still validated on submit. */
|
|
42
|
+
initialValues?: Record<string, unknown>; /** Honeypot decoy (on by default). `false` removes it; `{ name }` matches a customized server `spam.honeypot.fieldName`. */
|
|
43
|
+
honeypot?: false | {
|
|
44
|
+
name?: string;
|
|
45
|
+
}; /** A token from your captcha widget; verified server-side when a captcha provider is configured. */
|
|
46
|
+
captchaToken?: string; /** Custom layout: render fields with `useField`/`useFormState` instead of the auto-rendered field loop. */
|
|
47
|
+
children?: ReactNode; /** Additional CSS class names applied to the root `<form>` element (and the success node). */
|
|
48
|
+
className?: string;
|
|
49
|
+
};
|
|
50
|
+
/** The headless form controller: state, progressive client validation, conditional visibility, submission, events. */
|
|
51
|
+
declare const Form: ({
|
|
52
|
+
form,
|
|
53
|
+
fieldTypes,
|
|
54
|
+
rules,
|
|
55
|
+
renderers,
|
|
56
|
+
apiRoute,
|
|
57
|
+
onSubmit,
|
|
58
|
+
onSuccess,
|
|
59
|
+
onError,
|
|
60
|
+
events,
|
|
61
|
+
t,
|
|
62
|
+
locale,
|
|
63
|
+
layout,
|
|
64
|
+
submitLabel,
|
|
65
|
+
nextLabel,
|
|
66
|
+
backLabel,
|
|
67
|
+
closeLabel,
|
|
68
|
+
successMessage,
|
|
69
|
+
presentation,
|
|
70
|
+
presentations,
|
|
71
|
+
onClose,
|
|
72
|
+
title,
|
|
73
|
+
initialValues,
|
|
74
|
+
honeypot,
|
|
75
|
+
captchaToken,
|
|
76
|
+
children,
|
|
77
|
+
className
|
|
78
|
+
}: FormProps) => import("react/jsx-runtime").JSX.Element;
|
|
79
|
+
//#endregion
|
|
80
|
+
export { Form, FormDocument, FormProps };
|
|
81
|
+
//# sourceMappingURL=Form.d.ts.map
|
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { interpolate } from "../recall/interpolate.js";
|
|
3
|
+
import { noopEventSink } from "../events/noopSink.js";
|
|
4
|
+
import { CAPTCHA_TOKEN_KEY } from "../spam/constants.js";
|
|
5
|
+
import { defaultPresentationDescriptors } from "../presentations/defaults.js";
|
|
6
|
+
import { calcExpressionOf, computeCalcFields } from "../calc/computeCalcFields.js";
|
|
7
|
+
import { evaluateCondition } from "../conditions/evaluate.js";
|
|
8
|
+
import { en } from "../translations/en.js";
|
|
9
|
+
import { buildRecallResolver } from "../recall/resolver.js";
|
|
10
|
+
import { firstStepId, isTerminalStepId, resolveNextStepId, stepFieldNames } from "../flow/engine.js";
|
|
11
|
+
import { cn } from "./cn.js";
|
|
12
|
+
import { makeTranslate } from "../translations/makeTranslate.js";
|
|
13
|
+
import { emitFormEvent } from "./events.js";
|
|
14
|
+
import { FormContext } from "./FormContext.js";
|
|
15
|
+
import { FormLayout, widthProps } from "./FormLayout.js";
|
|
16
|
+
import { Honeypot } from "./Honeypot.js";
|
|
17
|
+
import { defaultPresentations } from "./presentation/presentations.js";
|
|
18
|
+
import { resolvePresentations } from "./presentation/registry.js";
|
|
19
|
+
import { applyRecall } from "./recall.js";
|
|
20
|
+
import { resolveRenderers } from "./registry.js";
|
|
21
|
+
import { defaultRenderers } from "./renderers/index.js";
|
|
22
|
+
import { buildFieldTypeRegistry, buildValidationRuleRegistry, visibleFields } from "./resolveForm.js";
|
|
23
|
+
import { formReducer, initialFormState } from "./state.js";
|
|
24
|
+
import { submitForm } from "./submitForm.js";
|
|
25
|
+
import { useField } from "./useField.js";
|
|
26
|
+
import { validateFieldValue } from "./validateField.js";
|
|
27
|
+
import { createElement, useCallback, useEffect, useId, useMemo, useReducer, useRef, useState } from "react";
|
|
28
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
29
|
+
//#region src/react/Form.tsx
|
|
30
|
+
const isEmpty = (value) => value == null || value === "" || Array.isArray(value) && value.length === 0;
|
|
31
|
+
const FIELD_WIDTHS = new Set([
|
|
32
|
+
"full",
|
|
33
|
+
"half",
|
|
34
|
+
"third",
|
|
35
|
+
"twoThirds"
|
|
36
|
+
]);
|
|
37
|
+
const FieldHost = ({ field, renderer, locale, t }) => {
|
|
38
|
+
const id = useId();
|
|
39
|
+
const { value, errors, warnings, setValue, onBlur } = useField(field.name);
|
|
40
|
+
return createElement(renderer, {
|
|
41
|
+
field,
|
|
42
|
+
id,
|
|
43
|
+
name: field.name,
|
|
44
|
+
value,
|
|
45
|
+
onChange: setValue,
|
|
46
|
+
onBlur,
|
|
47
|
+
errors,
|
|
48
|
+
warnings,
|
|
49
|
+
required: Boolean(field.required),
|
|
50
|
+
locale,
|
|
51
|
+
t
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
/** Hosts a derived (calc) field: read-only, value supplied from `effectiveValues`, never bound via `useField`. */
|
|
55
|
+
const CalcFieldHost = ({ field, renderer, value, locale, t }) => {
|
|
56
|
+
return createElement(renderer, {
|
|
57
|
+
field,
|
|
58
|
+
id: useId(),
|
|
59
|
+
name: field.name,
|
|
60
|
+
value,
|
|
61
|
+
onChange: () => {},
|
|
62
|
+
onBlur: () => {},
|
|
63
|
+
errors: [],
|
|
64
|
+
warnings: [],
|
|
65
|
+
required: false,
|
|
66
|
+
disabled: true,
|
|
67
|
+
locale,
|
|
68
|
+
t
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
/** The headless form controller: state, progressive client validation, conditional visibility, submission, events. */
|
|
72
|
+
const Form = ({ form, fieldTypes, rules, renderers, apiRoute, onSubmit, onSuccess, onError, events, t, locale = "en", layout, submitLabel = "Submit", nextLabel = "Next", backLabel = "Back", closeLabel = "Close", successMessage = "Thank you.", presentation, presentations, onClose, title, initialValues, honeypot, captchaToken, children, className }) => {
|
|
73
|
+
const honeypotName = honeypot === false ? null : honeypot?.name ?? "website";
|
|
74
|
+
const honeypotRef = useRef(null);
|
|
75
|
+
const registry = useMemo(() => buildFieldTypeRegistry(fieldTypes), [fieldTypes]);
|
|
76
|
+
const ruleRegistry = useMemo(() => buildValidationRuleRegistry(rules), [rules]);
|
|
77
|
+
const rendererRegistry = useMemo(() => resolveRenderers(defaultRenderers, renderers), [renderers]);
|
|
78
|
+
const presentationRegistry = useMemo(() => resolvePresentations(defaultPresentations, presentations), [presentations]);
|
|
79
|
+
const activePresentation = typeof presentation === "object" ? presentation : presentationRegistry.get(presentation ?? form.defaultPresentation ?? "page") ?? presentationRegistry.get("page") ?? defaultPresentationDescriptors.page;
|
|
80
|
+
const fieldsByName = useMemo(() => new Map(form.fields.map((field) => [field.name, field])), [form.fields]);
|
|
81
|
+
const translate = useMemo(() => t ?? makeTranslate(en), [t]);
|
|
82
|
+
const sinkRef = useRef(noopEventSink);
|
|
83
|
+
sinkRef.current = events ?? noopEventSink;
|
|
84
|
+
const formIdRef = useRef("");
|
|
85
|
+
formIdRef.current = String(form.id);
|
|
86
|
+
const [state, rawDispatch] = useReducer(formReducer, form.fields, (fields) => initialFormState({
|
|
87
|
+
...Object.fromEntries(fields.map((field) => [field.name, void 0])),
|
|
88
|
+
...initialValues ?? {}
|
|
89
|
+
}));
|
|
90
|
+
const effectiveValues = useMemo(() => computeCalcFields(form.fields, state.values), [form.fields, state.values]);
|
|
91
|
+
const recall = useMemo(() => buildRecallResolver({
|
|
92
|
+
fields: form.fields,
|
|
93
|
+
values: effectiveValues,
|
|
94
|
+
registry,
|
|
95
|
+
locale,
|
|
96
|
+
t: translate
|
|
97
|
+
}), [
|
|
98
|
+
form.fields,
|
|
99
|
+
effectiveValues,
|
|
100
|
+
registry,
|
|
101
|
+
locale,
|
|
102
|
+
translate
|
|
103
|
+
]);
|
|
104
|
+
const flow = form.flow && form.flow.steps.length >= 2 ? form.flow : void 0;
|
|
105
|
+
const [currentStepId, setCurrentStepId] = useState(() => flow ? firstStepId(flow) : void 0);
|
|
106
|
+
const [history, setHistory] = useState([]);
|
|
107
|
+
const startedRef = useRef(false);
|
|
108
|
+
const submittedRef = useRef(false);
|
|
109
|
+
const submittingRef = useRef(false);
|
|
110
|
+
const flowRef = useRef(flow);
|
|
111
|
+
flowRef.current = flow;
|
|
112
|
+
const dispatch = useCallback((action) => {
|
|
113
|
+
if (action.type === "SET_VALUE" && !startedRef.current) {
|
|
114
|
+
startedRef.current = true;
|
|
115
|
+
emitFormEvent(sinkRef.current, formIdRef.current, { type: "form.started" });
|
|
116
|
+
}
|
|
117
|
+
rawDispatch(action);
|
|
118
|
+
}, []);
|
|
119
|
+
const validateField = useCallback((name, value) => {
|
|
120
|
+
const field = fieldsByName.get(name);
|
|
121
|
+
if (!field) return;
|
|
122
|
+
const answers = {
|
|
123
|
+
...effectiveValues,
|
|
124
|
+
[name]: value
|
|
125
|
+
};
|
|
126
|
+
if (!evaluateCondition(field.validateWhen, answers)) {
|
|
127
|
+
rawDispatch({
|
|
128
|
+
type: "SET_FIELD_ISSUES",
|
|
129
|
+
name,
|
|
130
|
+
errors: [],
|
|
131
|
+
warnings: []
|
|
132
|
+
});
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
validateFieldValue({
|
|
136
|
+
field,
|
|
137
|
+
value,
|
|
138
|
+
registry,
|
|
139
|
+
ruleRegistry,
|
|
140
|
+
answers,
|
|
141
|
+
locale,
|
|
142
|
+
t: translate
|
|
143
|
+
}).then(({ errors, warnings }) => {
|
|
144
|
+
rawDispatch({
|
|
145
|
+
type: "SET_FIELD_ISSUES",
|
|
146
|
+
name,
|
|
147
|
+
errors,
|
|
148
|
+
warnings
|
|
149
|
+
});
|
|
150
|
+
const [firstError] = errors;
|
|
151
|
+
if (firstError !== void 0) emitFormEvent(sinkRef.current, formIdRef.current, {
|
|
152
|
+
type: "field.errored",
|
|
153
|
+
field: name,
|
|
154
|
+
message: firstError
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
}, [
|
|
158
|
+
fieldsByName,
|
|
159
|
+
effectiveValues,
|
|
160
|
+
registry,
|
|
161
|
+
ruleRegistry,
|
|
162
|
+
locale,
|
|
163
|
+
translate
|
|
164
|
+
]);
|
|
165
|
+
const visible = visibleFields(form.fields, effectiveValues);
|
|
166
|
+
const stepVisible = (flow && currentStepId ? stepFieldNames(flow, currentStepId) : []).map((name) => visible.find((field) => field.name === name)).filter((field) => Boolean(field));
|
|
167
|
+
const goNext = async () => {
|
|
168
|
+
if (!flow || !currentStepId) return;
|
|
169
|
+
const results = await Promise.all(stepVisible.filter((field) => !calcExpressionOf(field)).filter((field) => evaluateCondition(field.validateWhen, effectiveValues)).map(async (field) => ({
|
|
170
|
+
field,
|
|
171
|
+
...await validateFieldValue({
|
|
172
|
+
field,
|
|
173
|
+
value: effectiveValues[field.name],
|
|
174
|
+
registry,
|
|
175
|
+
ruleRegistry,
|
|
176
|
+
answers: effectiveValues,
|
|
177
|
+
locale,
|
|
178
|
+
t: translate
|
|
179
|
+
})
|
|
180
|
+
})));
|
|
181
|
+
let hasError = false;
|
|
182
|
+
for (const result of results) {
|
|
183
|
+
rawDispatch({
|
|
184
|
+
type: "TOUCH",
|
|
185
|
+
name: result.field.name
|
|
186
|
+
});
|
|
187
|
+
rawDispatch({
|
|
188
|
+
type: "SET_FIELD_ISSUES",
|
|
189
|
+
name: result.field.name,
|
|
190
|
+
errors: result.errors,
|
|
191
|
+
warnings: result.warnings
|
|
192
|
+
});
|
|
193
|
+
if (result.errors.length > 0) hasError = true;
|
|
194
|
+
}
|
|
195
|
+
if (hasError) return;
|
|
196
|
+
const next = resolveNextStepId(flow, currentStepId, state.values);
|
|
197
|
+
if (!next) return;
|
|
198
|
+
emitFormEvent(sinkRef.current, formIdRef.current, {
|
|
199
|
+
type: "step.completed",
|
|
200
|
+
stepId: currentStepId
|
|
201
|
+
});
|
|
202
|
+
setHistory((prev) => [...prev, currentStepId]);
|
|
203
|
+
setCurrentStepId(next);
|
|
204
|
+
emitFormEvent(sinkRef.current, formIdRef.current, {
|
|
205
|
+
type: "step.viewed",
|
|
206
|
+
stepId: next
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
const goBack = () => {
|
|
210
|
+
const prev = history[history.length - 1];
|
|
211
|
+
if (prev === void 0) return;
|
|
212
|
+
setHistory((entries) => entries.slice(0, -1));
|
|
213
|
+
setCurrentStepId(prev);
|
|
214
|
+
emitFormEvent(sinkRef.current, formIdRef.current, {
|
|
215
|
+
type: "step.viewed",
|
|
216
|
+
stepId: prev
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
useEffect(() => {
|
|
220
|
+
emitFormEvent(sinkRef.current, formIdRef.current, { type: "form.viewed" });
|
|
221
|
+
const mountFlow = flowRef.current;
|
|
222
|
+
if (mountFlow) {
|
|
223
|
+
const first = firstStepId(mountFlow);
|
|
224
|
+
if (first) emitFormEvent(sinkRef.current, formIdRef.current, {
|
|
225
|
+
type: "step.viewed",
|
|
226
|
+
stepId: first
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
return () => {
|
|
230
|
+
if (!submittedRef.current && !submittingRef.current) emitFormEvent(sinkRef.current, formIdRef.current, { type: "form.abandoned" });
|
|
231
|
+
};
|
|
232
|
+
}, []);
|
|
233
|
+
const handleClose = useCallback(() => {
|
|
234
|
+
onClose?.();
|
|
235
|
+
}, [onClose]);
|
|
236
|
+
const handleSubmit = async (event) => {
|
|
237
|
+
event.preventDefault();
|
|
238
|
+
if (submittingRef.current) return;
|
|
239
|
+
submittingRef.current = true;
|
|
240
|
+
const visible = visibleFields(form.fields, effectiveValues);
|
|
241
|
+
const results = await Promise.all(visible.filter((field) => !calcExpressionOf(field)).filter((field) => evaluateCondition(field.validateWhen, effectiveValues)).map(async (field) => ({
|
|
242
|
+
field,
|
|
243
|
+
...await validateFieldValue({
|
|
244
|
+
field,
|
|
245
|
+
value: effectiveValues[field.name],
|
|
246
|
+
registry,
|
|
247
|
+
ruleRegistry,
|
|
248
|
+
answers: effectiveValues,
|
|
249
|
+
locale,
|
|
250
|
+
t: translate
|
|
251
|
+
})
|
|
252
|
+
})));
|
|
253
|
+
const errors = {};
|
|
254
|
+
const warnings = {};
|
|
255
|
+
for (const result of results) {
|
|
256
|
+
if (result.errors.length > 0) {
|
|
257
|
+
errors[result.field.name] = result.errors;
|
|
258
|
+
const [firstError] = result.errors;
|
|
259
|
+
if (firstError !== void 0) emitFormEvent(sinkRef.current, formIdRef.current, {
|
|
260
|
+
type: "field.errored",
|
|
261
|
+
field: result.field.name,
|
|
262
|
+
message: firstError
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
if (result.warnings.length > 0) warnings[result.field.name] = result.warnings;
|
|
266
|
+
}
|
|
267
|
+
rawDispatch({
|
|
268
|
+
type: "SET_ALL_ISSUES",
|
|
269
|
+
errors,
|
|
270
|
+
warnings
|
|
271
|
+
});
|
|
272
|
+
if (Object.keys(errors).length > 0) {
|
|
273
|
+
submittingRef.current = false;
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
rawDispatch({ type: "SUBMIT_START" });
|
|
277
|
+
const values = visible.filter((field) => !isEmpty(effectiveValues[field.name])).map((field) => ({
|
|
278
|
+
field: field.name,
|
|
279
|
+
value: effectiveValues[field.name]
|
|
280
|
+
}));
|
|
281
|
+
if (honeypotName) {
|
|
282
|
+
const decoy = honeypotRef.current?.value ?? "";
|
|
283
|
+
if (decoy !== "") values.push({
|
|
284
|
+
field: honeypotName,
|
|
285
|
+
value: decoy
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
if (captchaToken) values.push({
|
|
289
|
+
field: CAPTCHA_TOKEN_KEY,
|
|
290
|
+
value: captchaToken
|
|
291
|
+
});
|
|
292
|
+
const result = onSubmit ? await onSubmit({
|
|
293
|
+
formId: form.id,
|
|
294
|
+
values
|
|
295
|
+
}) : await submitForm({
|
|
296
|
+
formId: form.id,
|
|
297
|
+
values,
|
|
298
|
+
apiRoute
|
|
299
|
+
});
|
|
300
|
+
submittingRef.current = false;
|
|
301
|
+
if (result.ok) {
|
|
302
|
+
submittedRef.current = true;
|
|
303
|
+
rawDispatch({ type: "SUBMIT_SUCCESS" });
|
|
304
|
+
emitFormEvent(sinkRef.current, formIdRef.current, {
|
|
305
|
+
type: "submission.created",
|
|
306
|
+
submissionId: result.submissionId
|
|
307
|
+
});
|
|
308
|
+
onSuccess?.(result.submissionId);
|
|
309
|
+
if (activePresentation.dismissOnSuccess) handleClose();
|
|
310
|
+
} else {
|
|
311
|
+
if (result.fieldErrors) rawDispatch({
|
|
312
|
+
type: "SET_ALL_ISSUES",
|
|
313
|
+
errors: result.fieldErrors,
|
|
314
|
+
warnings: {}
|
|
315
|
+
});
|
|
316
|
+
const message = result.message ?? "Submission failed";
|
|
317
|
+
rawDispatch({
|
|
318
|
+
type: "SUBMIT_ERROR",
|
|
319
|
+
message
|
|
320
|
+
});
|
|
321
|
+
onError?.(message);
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
const step = flow ? {
|
|
325
|
+
flow,
|
|
326
|
+
currentStepId,
|
|
327
|
+
stepIndex: flow.steps.findIndex((s) => s.id === currentStepId),
|
|
328
|
+
stepCount: flow.steps.length,
|
|
329
|
+
isFirst: history.length === 0,
|
|
330
|
+
isTerminal: currentStepId ? isTerminalStepId(flow, currentStepId, state.values) : true,
|
|
331
|
+
goNext: () => {
|
|
332
|
+
goNext();
|
|
333
|
+
},
|
|
334
|
+
goBack
|
|
335
|
+
} : {
|
|
336
|
+
stepIndex: 0,
|
|
337
|
+
stepCount: 1,
|
|
338
|
+
isFirst: true,
|
|
339
|
+
isTerminal: true,
|
|
340
|
+
goNext: () => {},
|
|
341
|
+
goBack: () => {}
|
|
342
|
+
};
|
|
343
|
+
const contextValue = {
|
|
344
|
+
state,
|
|
345
|
+
dispatch,
|
|
346
|
+
validateField,
|
|
347
|
+
locale,
|
|
348
|
+
step
|
|
349
|
+
};
|
|
350
|
+
const PresentationWrapper = activePresentation.Wrapper;
|
|
351
|
+
const wrap = (content) => PresentationWrapper ? /* @__PURE__ */ jsx(PresentationWrapper, {
|
|
352
|
+
presentation: activePresentation,
|
|
353
|
+
open: true,
|
|
354
|
+
onClose: handleClose,
|
|
355
|
+
title,
|
|
356
|
+
closeLabel,
|
|
357
|
+
children: content
|
|
358
|
+
}) : content;
|
|
359
|
+
if (children !== void 0) return /* @__PURE__ */ jsx(FormContext.Provider, {
|
|
360
|
+
value: contextValue,
|
|
361
|
+
children: wrap(/* @__PURE__ */ jsxs("form", {
|
|
362
|
+
className: cn("fb-form-root", className),
|
|
363
|
+
noValidate: true,
|
|
364
|
+
onSubmit: handleSubmit,
|
|
365
|
+
"data-fb-presentation": activePresentation.name,
|
|
366
|
+
"data-fb-density": activePresentation.density,
|
|
367
|
+
children: [honeypotName ? /* @__PURE__ */ jsx(Honeypot, {
|
|
368
|
+
name: honeypotName,
|
|
369
|
+
inputRef: honeypotRef
|
|
370
|
+
}) : null, children]
|
|
371
|
+
}))
|
|
372
|
+
});
|
|
373
|
+
if (state.submitted) return /* @__PURE__ */ jsx(FormContext.Provider, {
|
|
374
|
+
value: contextValue,
|
|
375
|
+
children: wrap(/* @__PURE__ */ jsx("p", {
|
|
376
|
+
role: "status",
|
|
377
|
+
className: cn("fb-form__success", className),
|
|
378
|
+
"data-fb-presentation": activePresentation.name,
|
|
379
|
+
"data-fb-density": activePresentation.density,
|
|
380
|
+
children: interpolate(successMessage, recall)
|
|
381
|
+
}))
|
|
382
|
+
});
|
|
383
|
+
const rendered = (flow ? stepVisible : visible).filter((field) => field.hidden !== true && field.calcDisplay !== false);
|
|
384
|
+
return /* @__PURE__ */ jsx(FormContext.Provider, {
|
|
385
|
+
value: contextValue,
|
|
386
|
+
children: wrap(/* @__PURE__ */ jsxs("form", {
|
|
387
|
+
className: cn("fb-form-root", className),
|
|
388
|
+
noValidate: true,
|
|
389
|
+
onSubmit: handleSubmit,
|
|
390
|
+
"data-fb-presentation": activePresentation.name,
|
|
391
|
+
"data-fb-density": activePresentation.density,
|
|
392
|
+
children: [
|
|
393
|
+
honeypotName ? /* @__PURE__ */ jsx(Honeypot, {
|
|
394
|
+
name: honeypotName,
|
|
395
|
+
inputRef: honeypotRef
|
|
396
|
+
}) : null,
|
|
397
|
+
/* @__PURE__ */ jsx(FormLayout, {
|
|
398
|
+
enabled: layout !== false,
|
|
399
|
+
children: rendered.map((field) => {
|
|
400
|
+
const renderer = rendererRegistry.get(field.blockType);
|
|
401
|
+
if (!renderer) return null;
|
|
402
|
+
const width = typeof field.width === "string" && FIELD_WIDTHS.has(field.width) ? field.width : void 0;
|
|
403
|
+
const recalledField = applyRecall(field, recall);
|
|
404
|
+
return /* @__PURE__ */ jsx("div", {
|
|
405
|
+
...widthProps(width),
|
|
406
|
+
children: calcExpressionOf(field) ? /* @__PURE__ */ jsx(CalcFieldHost, {
|
|
407
|
+
field: recalledField,
|
|
408
|
+
renderer,
|
|
409
|
+
value: effectiveValues[field.name],
|
|
410
|
+
locale,
|
|
411
|
+
t: translate
|
|
412
|
+
}) : /* @__PURE__ */ jsx(FieldHost, {
|
|
413
|
+
field: recalledField,
|
|
414
|
+
renderer,
|
|
415
|
+
locale,
|
|
416
|
+
t: translate
|
|
417
|
+
})
|
|
418
|
+
}, field.name);
|
|
419
|
+
})
|
|
420
|
+
}),
|
|
421
|
+
state.submitError ? /* @__PURE__ */ jsx("p", {
|
|
422
|
+
role: "alert",
|
|
423
|
+
className: "fb-form__submit-error",
|
|
424
|
+
children: state.submitError
|
|
425
|
+
}) : null,
|
|
426
|
+
flow ? /* @__PURE__ */ jsxs("div", {
|
|
427
|
+
className: "fb-form__controls",
|
|
428
|
+
children: [!step.isFirst ? /* @__PURE__ */ jsx("button", {
|
|
429
|
+
type: "button",
|
|
430
|
+
onClick: goBack,
|
|
431
|
+
disabled: state.submitting,
|
|
432
|
+
children: backLabel
|
|
433
|
+
}) : null, step.isTerminal ? /* @__PURE__ */ jsx("button", {
|
|
434
|
+
type: "submit",
|
|
435
|
+
disabled: state.submitting,
|
|
436
|
+
children: submitLabel
|
|
437
|
+
}) : /* @__PURE__ */ jsx("button", {
|
|
438
|
+
type: "button",
|
|
439
|
+
disabled: state.submitting,
|
|
440
|
+
onClick: () => {
|
|
441
|
+
goNext();
|
|
442
|
+
},
|
|
443
|
+
children: nextLabel
|
|
444
|
+
})]
|
|
445
|
+
}) : /* @__PURE__ */ jsx("button", {
|
|
446
|
+
type: "submit",
|
|
447
|
+
disabled: state.submitting,
|
|
448
|
+
children: submitLabel
|
|
449
|
+
})
|
|
450
|
+
]
|
|
451
|
+
}))
|
|
452
|
+
});
|
|
453
|
+
};
|
|
454
|
+
//#endregion
|
|
455
|
+
export { Form };
|
|
456
|
+
|
|
457
|
+
//# sourceMappingURL=Form.js.map
|