@10x-media/form-builder 0.1.0-beta.2 → 0.1.0-beta.21
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 +360 -0
- package/README.md +7 -5
- package/dist/actions/assertNoBlockCollision.js +18 -0
- package/dist/actions/assertNoBlockCollision.js.map +1 -0
- package/dist/actions/body/converters.d.ts +20 -0
- package/dist/actions/body/converters.js +57 -0
- package/dist/actions/body/converters.js.map +1 -0
- package/dist/actions/body/escapeHtml.d.ts +6 -0
- package/dist/actions/body/escapeHtml.js +14 -0
- package/dist/actions/body/escapeHtml.js.map +1 -0
- package/dist/actions/body/serializeBody.d.ts +55 -0
- package/dist/actions/body/serializeBody.js +78 -0
- package/dist/actions/body/serializeBody.js.map +1 -0
- package/dist/actions/body/serializeSlate.js +31 -0
- package/dist/actions/body/serializeSlate.js.map +1 -0
- package/dist/actions/body/textOfBody.d.ts +13 -0
- package/dist/actions/body/textOfBody.js +35 -0
- package/dist/actions/body/textOfBody.js.map +1 -0
- package/dist/actions/body/wildcards.d.ts +10 -0
- package/dist/actions/body/wildcards.js +33 -0
- package/dist/actions/body/wildcards.js.map +1 -0
- package/dist/actions/buildActionBlocks.js +12 -9
- package/dist/actions/buildActionBlocks.js.map +1 -1
- package/dist/actions/builtin/confirmation.js +47 -43
- package/dist/actions/builtin/confirmation.js.map +1 -1
- package/dist/actions/builtin/emailAction.d.ts +20 -0
- package/dist/actions/builtin/emailAction.js +120 -0
- package/dist/actions/builtin/emailAction.js.map +1 -0
- package/dist/actions/builtin/emailTeam.js +20 -38
- package/dist/actions/builtin/emailTeam.js.map +1 -1
- package/dist/actions/builtin/index.d.ts +16 -1
- package/dist/actions/builtin/index.js +21 -7
- package/dist/actions/builtin/index.js.map +1 -1
- package/dist/actions/builtin/signedWebhook.js +6 -2
- package/dist/actions/builtin/signedWebhook.js.map +1 -1
- package/dist/actions/defineAction.d.ts +17 -5
- package/dist/actions/defineAction.js.map +1 -1
- package/dist/actions/dispatch.js +51 -6
- package/dist/actions/dispatch.js.map +1 -1
- package/dist/actions/dispatchContext.js +13 -0
- package/dist/actions/dispatchContext.js.map +1 -0
- package/dist/actions/emailRecipients.d.ts +12 -0
- package/dist/actions/emailRecipients.js +146 -0
- package/dist/actions/emailRecipients.js.map +1 -0
- package/dist/actions/fromAddresses.d.ts +37 -0
- package/dist/actions/fromAddresses.js +131 -0
- package/dist/actions/fromAddresses.js.map +1 -0
- package/dist/actions/recipientSources.d.ts +34 -0
- package/dist/actions/recipientSources.js +11 -0
- package/dist/actions/recipientSources.js.map +1 -0
- package/dist/actions/registry.d.ts +2 -1
- package/dist/actions/registry.js +5 -7
- package/dist/actions/registry.js.map +1 -1
- package/dist/actions/runActions.js +10 -1
- package/dist/actions/runActions.js.map +1 -1
- package/dist/actions/task.js +47 -16
- package/dist/actions/task.js.map +1 -1
- package/dist/aggregation/aggregateResponses.d.ts +9 -0
- package/dist/aggregation/aggregateResponses.js +8 -14
- package/dist/aggregation/aggregateResponses.js.map +1 -1
- package/dist/aggregation/resolveResultsRequest.d.ts +41 -6
- package/dist/aggregation/resolveResultsRequest.js +97 -11
- package/dist/aggregation/resolveResultsRequest.js.map +1 -1
- package/dist/calc/computeCalcFields.d.ts +5 -3
- package/dist/calc/computeCalcFields.js +6 -4
- package/dist/calc/computeCalcFields.js.map +1 -1
- package/dist/calc/evaluate.d.ts +26 -3
- package/dist/calc/evaluate.js +34 -13
- package/dist/calc/evaluate.js.map +1 -1
- package/dist/calc/formatCalc.d.ts +11 -0
- package/dist/calc/formatCalc.js +35 -0
- package/dist/calc/formatCalc.js.map +1 -0
- package/dist/calc/formatCalcValue.d.ts +17 -0
- package/dist/calc/formatCalcValue.js +17 -0
- package/dist/calc/formatCalcValue.js.map +1 -0
- package/dist/calc/normalizeCalc.d.ts +17 -3
- package/dist/calc/normalizeCalc.js +42 -33
- package/dist/calc/normalizeCalc.js.map +1 -1
- package/dist/calc/registry.d.ts +43 -0
- package/dist/calc/registry.js +27 -0
- package/dist/calc/registry.js.map +1 -0
- package/dist/calc/resolveCalcContext.d.ts +36 -0
- package/dist/calc/resolveCalcContext.js +87 -0
- package/dist/calc/resolveCalcContext.js.map +1 -0
- package/dist/calc/types.d.ts +25 -4
- package/dist/calc/types.js +23 -0
- package/dist/calc/types.js.map +1 -0
- package/dist/client/ByteSizeField.d.ts +29 -0
- package/dist/client/ByteSizeField.js +58 -0
- package/dist/client/ByteSizeField.js.map +1 -0
- package/dist/client/CalcExpressionBuilder.d.ts +20 -0
- package/dist/client/CalcExpressionBuilder.js +890 -0
- package/dist/client/CalcExpressionBuilder.js.map +1 -0
- package/dist/client/ClosePollButton.d.ts +15 -0
- package/dist/client/ClosePollButton.js +80 -0
- package/dist/client/ClosePollButton.js.map +1 -0
- package/dist/client/CondensedArray.d.ts +15 -0
- package/dist/client/CondensedArray.js +97 -0
- package/dist/client/CondensedArray.js.map +1 -0
- package/dist/client/ConditionBuilder.js +2 -1
- package/dist/client/ConditionBuilder.js.map +1 -1
- package/dist/client/ConsentBlockLabel.d.ts +15 -0
- package/dist/client/ConsentBlockLabel.js +71 -0
- package/dist/client/ConsentBlockLabel.js.map +1 -0
- package/dist/client/ConsentSourceRowLabel.d.ts +9 -0
- package/dist/client/ConsentSourceRowLabel.js +21 -0
- package/dist/client/ConsentSourceRowLabel.js.map +1 -0
- package/dist/client/EndpointOptionsSelect.d.ts +55 -0
- package/dist/client/EndpointOptionsSelect.js +112 -0
- package/dist/client/EndpointOptionsSelect.js.map +1 -0
- package/dist/client/FieldBlockLabel.d.ts +18 -0
- package/dist/client/FieldBlockLabel.js +34 -0
- package/dist/client/FieldBlockLabel.js.map +1 -0
- package/dist/client/FieldNameSelect.d.ts +37 -0
- package/dist/client/FieldNameSelect.js +72 -0
- package/dist/client/FieldNameSelect.js.map +1 -0
- package/dist/client/FlowBuilder.d.ts +2 -2
- package/dist/client/FlowBuilder.js +137 -88
- package/dist/client/FlowBuilder.js.map +1 -1
- package/dist/client/FormConditionField.js +1 -4
- package/dist/client/FormConditionField.js.map +1 -1
- package/dist/client/RecipientsSelect.d.ts +37 -0
- package/dist/client/RecipientsSelect.js +197 -0
- package/dist/client/RecipientsSelect.js.map +1 -0
- package/dist/client/RuleDescription.d.ts +21 -0
- package/dist/client/RuleDescription.js +19 -0
- package/dist/client/RuleDescription.js.map +1 -0
- package/dist/client/admin.css +557 -0
- package/dist/client/endpointOptions.d.ts +11 -0
- package/dist/client/endpointOptions.js +38 -0
- package/dist/client/endpointOptions.js.map +1 -0
- package/dist/client/flowAuthoring.js +142 -0
- package/dist/client/flowAuthoring.js.map +1 -0
- package/dist/client/synthesizeClientField.js +21 -10
- package/dist/client/synthesizeClientField.js.map +1 -1
- package/dist/client/toStaticLabel.js +13 -0
- package/dist/client/toStaticLabel.js.map +1 -0
- package/dist/collections/buttonFields.d.ts +34 -0
- package/dist/collections/buttonFields.js +35 -0
- package/dist/collections/buttonFields.js.map +1 -0
- package/dist/collections/cells/FieldCountCell.d.ts +15 -0
- package/dist/collections/cells/FieldCountCell.js +18 -0
- package/dist/collections/cells/FieldCountCell.js.map +1 -0
- package/dist/collections/cells/FlowStepsCell.d.ts +14 -0
- package/dist/collections/cells/FlowStepsCell.js +17 -0
- package/dist/collections/cells/FlowStepsCell.js.map +1 -0
- package/dist/collections/formSubmissions.js +114 -28
- package/dist/collections/formSubmissions.js.map +1 -1
- package/dist/collections/forms.js +449 -112
- package/dist/collections/forms.js.map +1 -1
- package/dist/collections/formsEndpoints.js +106 -0
- package/dist/collections/formsEndpoints.js.map +1 -0
- package/dist/collections/redirectFields.d.ts +29 -0
- package/dist/collections/settingsFields.d.ts +31 -0
- package/dist/collections/settingsFields.js +45 -0
- package/dist/collections/settingsFields.js.map +1 -0
- package/dist/conditions/conditionType.js +9 -2
- package/dist/conditions/conditionType.js.map +1 -1
- package/dist/conditions/evaluate.js +1 -1
- package/dist/conditions/evaluate.js.map +1 -1
- package/dist/conditions/fieldTypes.d.ts +3 -1
- package/dist/conditions/fieldTypes.js +4 -1
- package/dist/conditions/fieldTypes.js.map +1 -1
- package/dist/conditions/normalizeConditions.js +20 -6
- package/dist/conditions/normalizeConditions.js.map +1 -1
- package/dist/consent/applyConsentStatements.d.ts +14 -0
- package/dist/consent/applyConsentStatements.js +17 -0
- package/dist/consent/applyConsentStatements.js.map +1 -0
- package/dist/consent/captureConsent.d.ts +39 -11
- package/dist/consent/captureConsent.js +63 -13
- package/dist/consent/captureConsent.js.map +1 -1
- package/dist/consent/consentSourcesField.d.ts +66 -0
- package/dist/consent/consentSourcesField.js +98 -0
- package/dist/consent/consentSourcesField.js.map +1 -0
- package/dist/consent/effectiveStatement.js +16 -0
- package/dist/consent/effectiveStatement.js.map +1 -0
- package/dist/consent/resolveConsentEntries.d.ts +24 -0
- package/dist/consent/resolveConsentEntries.js +40 -0
- package/dist/consent/resolveConsentEntries.js.map +1 -0
- package/dist/consent/resolveConsentSourcesRequest.d.ts +37 -0
- package/dist/consent/resolveConsentSourcesRequest.js +54 -0
- package/dist/consent/resolveConsentSourcesRequest.js.map +1 -0
- package/dist/consent/resolveConsentStatements.d.ts +45 -0
- package/dist/consent/resolveConsentStatements.js +46 -0
- package/dist/consent/resolveConsentStatements.js.map +1 -0
- package/dist/consent/resolvePublishedVersionRef.d.ts +17 -11
- package/dist/consent/resolvePublishedVersionRef.js +13 -10
- package/dist/consent/resolvePublishedVersionRef.js.map +1 -1
- package/dist/consent/types.d.ts +69 -0
- package/dist/context/formContext.d.ts +30 -0
- package/dist/context/formContext.js +54 -0
- package/dist/context/formContext.js.map +1 -0
- package/dist/email/departments.d.ts +59 -0
- package/dist/email/departments.js +87 -0
- package/dist/email/departments.js.map +1 -0
- package/dist/email/departmentsField.d.ts +53 -0
- package/dist/email/departmentsField.js +73 -0
- package/dist/email/departmentsField.js.map +1 -0
- package/dist/exports/client.d.ts +14 -1
- package/dist/exports/client.js +14 -1
- package/dist/exports/i18n.d.ts +5 -2
- package/dist/exports/i18n.js +5 -2
- package/dist/exports/react.d.ts +34 -10
- package/dist/exports/react.js +24 -4
- package/dist/exports/rsc.d.ts +10 -1
- package/dist/exports/rsc.js +10 -1
- package/dist/exports/types.d.ts +20 -12
- package/dist/fields/buildFieldBlocks.js +46 -25
- package/dist/fields/buildFieldBlocks.js.map +1 -1
- package/dist/fields/builtin/calculation.d.ts +17 -0
- package/dist/fields/builtin/calculation.js +193 -18
- package/dist/fields/builtin/calculation.js.map +1 -1
- package/dist/fields/builtin/checkbox.js +23 -0
- package/dist/fields/builtin/checkbox.js.map +1 -1
- package/dist/fields/builtin/consent.js +49 -14
- package/dist/fields/builtin/consent.js.map +1 -1
- package/dist/fields/builtin/country.d.ts +13 -0
- package/dist/fields/builtin/country.js +30 -0
- package/dist/fields/builtin/country.js.map +1 -0
- package/dist/fields/builtin/date.js +31 -0
- package/dist/fields/builtin/date.js.map +1 -0
- package/dist/fields/builtin/email.js +8 -1
- package/dist/fields/builtin/email.js.map +1 -1
- package/dist/fields/builtin/file.d.ts +15 -0
- package/dist/fields/builtin/file.js +95 -8
- package/dist/fields/builtin/file.js.map +1 -1
- package/dist/fields/builtin/index.d.ts +30 -0
- package/dist/fields/builtin/index.js +37 -10
- package/dist/fields/builtin/index.js.map +1 -1
- package/dist/fields/builtin/message.js +30 -0
- package/dist/fields/builtin/message.js.map +1 -0
- package/dist/fields/builtin/repeater.js +8 -3
- package/dist/fields/builtin/repeater.js.map +1 -1
- package/dist/fields/builtin/select.js +28 -4
- package/dist/fields/builtin/select.js.map +1 -1
- package/dist/fields/builtin/state.d.ts +13 -0
- package/dist/fields/builtin/state.js +30 -0
- package/dist/fields/builtin/state.js.map +1 -0
- package/dist/fields/builtin/text.js +7 -0
- package/dist/fields/builtin/text.js.map +1 -1
- package/dist/fields/data/regions.d.ts +21 -0
- package/dist/fields/data/regions.js +1238 -0
- package/dist/fields/data/regions.js.map +1 -0
- package/dist/fields/fieldKey.d.ts +15 -0
- package/dist/fields/fieldKey.js +16 -0
- package/dist/fields/fieldKey.js.map +1 -0
- package/dist/fields/fieldNamesOfType.js +30 -0
- package/dist/fields/fieldNamesOfType.js.map +1 -0
- package/dist/fields/instanceOptions.js +20 -0
- package/dist/fields/instanceOptions.js.map +1 -0
- package/dist/fields/localizedIf.d.ts +13 -0
- package/dist/fields/localizedIf.js +12 -0
- package/dist/fields/localizedIf.js.map +1 -0
- package/dist/fields/registry.d.ts +3 -1
- package/dist/fields/registry.js +23 -8
- package/dist/fields/registry.js.map +1 -1
- package/dist/fields/sharedConfig.js +125 -59
- package/dist/fields/sharedConfig.js.map +1 -1
- package/dist/fields/types.d.ts +78 -9
- package/dist/flow/engine.d.ts +6 -4
- package/dist/flow/engine.js +11 -6
- package/dist/flow/engine.js.map +1 -1
- package/dist/flow/normalizeFlow.js +28 -9
- package/dist/flow/normalizeFlow.js.map +1 -1
- package/dist/flow/stepLabel.js +15 -0
- package/dist/flow/stepLabel.js.map +1 -0
- package/dist/flow/types.d.ts +12 -3
- package/dist/flow/types.js +11 -0
- package/dist/flow/types.js.map +1 -0
- package/dist/form/pollState.d.ts +23 -0
- package/dist/form/pollState.js +17 -0
- package/dist/form/pollState.js.map +1 -0
- package/dist/form/toFormDocument.d.ts +110 -0
- package/dist/form/toFormDocument.js +89 -0
- package/dist/form/toFormDocument.js.map +1 -0
- package/dist/form/types.d.ts +73 -0
- package/dist/index.d.ts +67 -61
- package/dist/index.js +120 -25
- package/dist/index.js.map +1 -1
- package/dist/options.d.ts +281 -0
- package/dist/plugin/applyRegistryConfig.d.ts +11 -0
- package/dist/plugin/applyRegistryConfig.js +20 -0
- package/dist/plugin/applyRegistryConfig.js.map +1 -0
- package/dist/plugin/customState.js +26 -0
- package/dist/plugin/customState.js.map +1 -0
- package/dist/plugin/registerCollections.js +43 -40
- package/dist/plugin/registerCollections.js.map +1 -1
- package/dist/plugin/uploadsCollection.d.ts +16 -0
- package/dist/plugin/uploadsCollection.js +53 -0
- package/dist/plugin/uploadsCollection.js.map +1 -0
- package/dist/poll/applyPollOptions.js +18 -0
- package/dist/poll/applyPollOptions.js.map +1 -0
- package/dist/poll/buildPollOptionSourceFields.js +50 -0
- package/dist/poll/buildPollOptionSourceFields.js.map +1 -0
- package/dist/poll/closeJob.d.ts +53 -0
- package/dist/poll/closeJob.js +121 -0
- package/dist/poll/closeJob.js.map +1 -0
- package/dist/poll/definePollOptionSource.d.ts +44 -0
- package/dist/poll/definePollOptionSource.js +6 -0
- package/dist/poll/definePollOptionSource.js.map +1 -0
- package/dist/poll/definePollType.d.ts +34 -0
- package/dist/poll/definePollType.js +6 -0
- package/dist/poll/definePollType.js.map +1 -0
- package/dist/poll/effectivePollOptions.d.ts +38 -0
- package/dist/poll/effectivePollOptions.js +64 -0
- package/dist/poll/effectivePollOptions.js.map +1 -0
- package/dist/poll/mostVoted.d.ts +21 -0
- package/dist/poll/mostVoted.js +32 -0
- package/dist/poll/mostVoted.js.map +1 -0
- package/dist/poll/outcomeBeforeChange.js +91 -0
- package/dist/poll/outcomeBeforeChange.js.map +1 -0
- package/dist/poll/outcomeFields.d.ts +38 -0
- package/dist/poll/outcomeFields.js +52 -0
- package/dist/poll/outcomeFields.js.map +1 -0
- package/dist/poll/pollTypeRegistry.d.ts +34 -0
- package/dist/poll/pollTypeRegistry.js +69 -0
- package/dist/poll/pollTypeRegistry.js.map +1 -0
- package/dist/poll/registry.d.ts +17 -0
- package/dist/poll/registry.js +12 -0
- package/dist/poll/registry.js.map +1 -0
- package/dist/poll/resolvePollCloseRequest.js +106 -0
- package/dist/poll/resolvePollCloseRequest.js.map +1 -0
- package/dist/poll/resolvePollOptions.d.ts +29 -0
- package/dist/poll/resolvePollOptions.js +52 -0
- package/dist/poll/resolvePollOptions.js.map +1 -0
- package/dist/poll/resolvePollOptionsRequest.js +50 -0
- package/dist/poll/resolvePollOptionsRequest.js.map +1 -0
- package/dist/poll/resolvePollOutcome.d.ts +40 -0
- package/dist/poll/resolvePollOutcome.js +90 -0
- package/dist/poll/resolvePollOutcome.js.map +1 -0
- package/dist/poll/resultsField.js +21 -0
- package/dist/poll/resultsField.js.map +1 -0
- package/dist/poll/votes/aggregateFromVotes.d.ts +27 -0
- package/dist/poll/votes/aggregateFromVotes.js +54 -0
- package/dist/poll/votes/aggregateFromVotes.js.map +1 -0
- package/dist/poll/votes/answerValues.js +16 -0
- package/dist/poll/votes/answerValues.js.map +1 -0
- package/dist/poll/votes/bumpPollVote.js +88 -0
- package/dist/poll/votes/bumpPollVote.js.map +1 -0
- package/dist/poll/votes/recountPollVotes.d.ts +20 -0
- package/dist/poll/votes/recountPollVotes.js +63 -0
- package/dist/poll/votes/recountPollVotes.js.map +1 -0
- package/dist/poll/votes/voteTallyHook.js +76 -0
- package/dist/poll/votes/voteTallyHook.js.map +1 -0
- package/dist/poll/votes/votesCollection.d.ts +19 -0
- package/dist/poll/votes/votesCollection.js +89 -0
- package/dist/poll/votes/votesCollection.js.map +1 -0
- package/dist/prefill/valuesFromSearchParams.js +5 -9
- package/dist/prefill/valuesFromSearchParams.js.map +1 -1
- package/dist/presentations/types.d.ts +3 -2
- package/dist/react/Form.d.ts +77 -35
- package/dist/react/Form.js +368 -222
- package/dist/react/Form.js.map +1 -1
- package/dist/react/FormContext.d.ts +51 -1
- package/dist/react/FormContext.js.map +1 -1
- package/dist/react/FormControls.d.ts +55 -0
- package/dist/react/FormControls.js +56 -0
- package/dist/react/FormControls.js.map +1 -0
- package/dist/react/FormFields.d.ts +18 -0
- package/dist/react/FormFields.js +114 -0
- package/dist/react/FormFields.js.map +1 -0
- package/dist/react/FormLayout.d.ts +4 -2
- package/dist/react/FormLayout.js +3 -2
- package/dist/react/FormLayout.js.map +1 -1
- package/dist/react/FormResults.d.ts +8 -3
- package/dist/react/FormResults.js +50 -29
- package/dist/react/FormResults.js.map +1 -1
- package/dist/react/FormSteps.d.ts +17 -0
- package/dist/react/FormSteps.js +35 -0
- package/dist/react/FormSteps.js.map +1 -0
- package/dist/react/Poll.d.ts +40 -6
- package/dist/react/Poll.js +137 -33
- package/dist/react/Poll.js.map +1 -1
- package/dist/react/adapters.d.ts +35 -0
- package/dist/react/adapters.js +11 -0
- package/dist/react/adapters.js.map +1 -0
- package/dist/react/captcha/HcaptchaCaptcha.d.ts +31 -0
- package/dist/react/captcha/HcaptchaCaptcha.js +53 -0
- package/dist/react/captcha/HcaptchaCaptcha.js.map +1 -0
- package/dist/react/captcha/RecaptchaCaptcha.d.ts +44 -0
- package/dist/react/captcha/RecaptchaCaptcha.js +93 -0
- package/dist/react/captcha/RecaptchaCaptcha.js.map +1 -0
- package/dist/react/captcha/TurnstileCaptcha.d.ts +31 -0
- package/dist/react/captcha/TurnstileCaptcha.js +53 -0
- package/dist/react/captcha/TurnstileCaptcha.js.map +1 -0
- package/dist/react/captcha/types.d.ts +8 -0
- package/dist/react/captcha/useCaptchaScript.js +63 -0
- package/dist/react/captcha/useCaptchaScript.js.map +1 -0
- package/dist/react/captcha/vendors.js +8 -0
- package/dist/react/captcha/vendors.js.map +1 -0
- package/dist/react/contract.d.ts +2 -3
- package/dist/react/contract.js.map +1 -1
- package/dist/react/fetchResults.d.ts +1 -1
- package/dist/react/fetchResults.js +1 -1
- package/dist/react/fetchResults.js.map +1 -1
- package/dist/react/presentation/DialogSurface.js +1 -4
- package/dist/react/presentation/DialogSurface.js.map +1 -1
- package/dist/react/primitives/Checkbox.d.ts +6 -2
- package/dist/react/primitives/Checkbox.js +4 -2
- package/dist/react/primitives/Checkbox.js.map +1 -1
- package/dist/react/primitives/ChoiceGroup.d.ts +40 -0
- package/dist/react/primitives/ChoiceGroup.js +33 -0
- package/dist/react/primitives/ChoiceGroup.js.map +1 -0
- package/dist/react/primitives/FieldShell.d.ts +13 -5
- package/dist/react/primitives/FieldShell.js +35 -32
- package/dist/react/primitives/FieldShell.js.map +1 -1
- package/dist/react/primitives/Input.d.ts +4 -2
- package/dist/react/primitives/Input.js +2 -1
- package/dist/react/primitives/Input.js.map +1 -1
- package/dist/react/renderers/calculation.js +7 -5
- package/dist/react/renderers/calculation.js.map +1 -1
- package/dist/react/renderers/checkbox.js +3 -5
- package/dist/react/renderers/checkbox.js.map +1 -1
- package/dist/react/renderers/consent.js +84 -36
- package/dist/react/renderers/consent.js.map +1 -1
- package/dist/react/renderers/date.js +33 -0
- package/dist/react/renderers/date.js.map +1 -0
- package/dist/react/renderers/email.js +4 -5
- package/dist/react/renderers/email.js.map +1 -1
- package/dist/react/renderers/file.js +29 -14
- package/dist/react/renderers/file.js.map +1 -1
- package/dist/react/renderers/index.js +7 -0
- package/dist/react/renderers/index.js.map +1 -1
- package/dist/react/renderers/message.js +41 -0
- package/dist/react/renderers/message.js.map +1 -0
- package/dist/react/renderers/number.js +1 -4
- package/dist/react/renderers/number.js.map +1 -1
- package/dist/react/renderers/region.js +43 -0
- package/dist/react/renderers/region.js.map +1 -0
- package/dist/react/renderers/repeater.js +32 -14
- package/dist/react/renderers/repeater.js.map +1 -1
- package/dist/react/renderers/select.js +21 -6
- package/dist/react/renderers/select.js.map +1 -1
- package/dist/react/renderers/text.js +4 -5
- package/dist/react/renderers/text.js.map +1 -1
- package/dist/react/renderers/textarea.js +1 -4
- package/dist/react/renderers/textarea.js.map +1 -1
- package/dist/react/state.d.ts +46 -3
- package/dist/react/state.js +73 -10
- package/dist/react/state.js.map +1 -1
- package/dist/react/submitForm.js +1 -1
- package/dist/react/submitForm.js.map +1 -1
- package/dist/react/uploadFile.d.ts +2 -2
- package/dist/react/uploadFile.js +1 -1
- package/dist/react/uploadFile.js.map +1 -1
- package/dist/react/useCalcValues.d.ts +10 -0
- package/dist/react/useCalcValues.js +13 -0
- package/dist/react/useCalcValues.js.map +1 -0
- package/dist/react/useField.d.ts +0 -1
- package/dist/react/useField.js +7 -6
- package/dist/react/useField.js.map +1 -1
- package/dist/react/useFormState.d.ts +1 -1
- package/dist/react/useFormState.js +1 -1
- package/dist/react/useFormState.js.map +1 -1
- package/dist/react/validateField.js +3 -6
- package/dist/react/validateField.js.map +1 -1
- package/dist/recall/interpolate.d.ts +4 -3
- package/dist/recall/interpolate.js +5 -4
- package/dist/recall/interpolate.js.map +1 -1
- package/dist/recall/resolver.d.ts +1 -1
- package/dist/recall/resolver.js +15 -3
- package/dist/recall/resolver.js.map +1 -1
- package/dist/spam/captcha.d.ts +4 -3
- package/dist/spam/captcha.js +4 -3
- package/dist/spam/captcha.js.map +1 -1
- package/dist/spam/clientIp.js +9 -0
- package/dist/spam/clientIp.js.map +1 -0
- package/dist/spam/constants.js +13 -1
- package/dist/spam/constants.js.map +1 -1
- package/dist/spam/identify.js +3 -6
- package/dist/spam/identify.js.map +1 -1
- package/dist/spam/providers/hcaptcha.d.ts +17 -0
- package/dist/spam/providers/hcaptcha.js +18 -0
- package/dist/spam/providers/hcaptcha.js.map +1 -0
- package/dist/spam/providers/recaptcha.d.ts +23 -0
- package/dist/spam/providers/recaptcha.js +23 -0
- package/dist/spam/providers/recaptcha.js.map +1 -0
- package/dist/spam/providers/siteverify.js +34 -0
- package/dist/spam/providers/siteverify.js.map +1 -0
- package/dist/spam/providers/turnstile.d.ts +17 -0
- package/dist/spam/providers/turnstile.js +18 -0
- package/dist/spam/providers/turnstile.js.map +1 -0
- package/dist/spam/resolveSpam.js +2 -1
- package/dist/spam/resolveSpam.js.map +1 -1
- package/dist/spam/spamGuard.js +25 -11
- package/dist/spam/spamGuard.js.map +1 -1
- package/dist/spam/types.d.ts +19 -4
- package/dist/submissions/SubmissionAnswers.js +6 -2
- package/dist/submissions/SubmissionAnswers.js.map +1 -1
- package/dist/submissions/SubmissionAnswersClient.js +100 -64
- package/dist/submissions/SubmissionAnswersClient.js.map +1 -1
- package/dist/submissions/coerceBoolean.js +14 -0
- package/dist/submissions/coerceBoolean.js.map +1 -0
- package/dist/submissions/createSubmission.d.ts +36 -0
- package/dist/submissions/createSubmission.js +26 -0
- package/dist/submissions/createSubmission.js.map +1 -0
- package/dist/submissions/formIdOf.js +13 -0
- package/dist/submissions/formIdOf.js.map +1 -0
- package/dist/submissions/resolveVotedSubmission.d.ts +27 -0
- package/dist/submissions/resolveVotedSubmission.js +51 -0
- package/dist/submissions/resolveVotedSubmission.js.map +1 -0
- package/dist/submissions/runSubmission.d.ts +10 -0
- package/dist/submissions/runSubmission.js +104 -54
- package/dist/submissions/runSubmission.js.map +1 -1
- package/dist/submissions/types.d.ts +11 -4
- package/dist/submissions/validateSubmission.js +99 -13
- package/dist/submissions/validateSubmission.js.map +1 -1
- package/dist/submissions/verifyContext.js +35 -0
- package/dist/submissions/verifyContext.js.map +1 -0
- package/dist/submissions/voteChangeEndpoint.js +105 -0
- package/dist/submissions/voteChangeEndpoint.js.map +1 -0
- package/dist/submissions/votedCookie.d.ts +15 -0
- package/dist/submissions/votedCookie.js +74 -0
- package/dist/submissions/votedCookie.js.map +1 -0
- package/dist/translations/clientRuntimeKeys.d.ts +17 -0
- package/dist/translations/clientRuntimeKeys.js +48 -0
- package/dist/translations/clientRuntimeKeys.js.map +1 -0
- package/dist/translations/de.d.ts +12 -0
- package/dist/translations/de.js +380 -0
- package/dist/translations/de.js.map +1 -0
- package/dist/translations/en.js +250 -28
- package/dist/translations/en.js.map +1 -1
- package/dist/translations/index.d.ts +14 -5
- package/dist/translations/index.js +14 -3
- package/dist/translations/index.js.map +1 -1
- package/dist/translations/keys.d.ts +245 -23
- package/dist/translations/keys.js +246 -24
- package/dist/translations/keys.js.map +1 -1
- package/dist/translations/makeTranslate.d.ts +7 -3
- package/dist/translations/makeTranslate.js +12 -3
- package/dist/translations/makeTranslate.js.map +1 -1
- package/dist/translations/server.js +8 -1
- package/dist/translations/server.js.map +1 -1
- package/dist/uploads/captureFileRef.d.ts +10 -3
- package/dist/uploads/captureFileRef.js +18 -9
- package/dist/uploads/captureFileRef.js.map +1 -1
- package/dist/uploads/formatBytes.d.ts +9 -0
- package/dist/uploads/formatBytes.js +25 -0
- package/dist/uploads/formatBytes.js.map +1 -0
- package/dist/uploads/resolveFileRef.js +3 -2
- package/dist/uploads/resolveFileRef.js.map +1 -1
- package/dist/uploads/types.d.ts +1 -2
- package/dist/validation/buildRuleBlocks.js +18 -17
- package/dist/validation/buildRuleBlocks.js.map +1 -1
- package/dist/validation/builtin/email.js +2 -1
- package/dist/validation/builtin/email.js.map +1 -1
- package/dist/validation/builtin/index.d.ts +14 -0
- package/dist/validation/builtin/index.js +14 -1
- package/dist/validation/builtin/index.js.map +1 -1
- package/dist/validation/builtin/integer.js +15 -0
- package/dist/validation/builtin/integer.js.map +1 -0
- package/dist/validation/builtin/matchesField.js +3 -7
- package/dist/validation/builtin/matchesField.js.map +1 -1
- package/dist/validation/builtin/max.js +1 -0
- package/dist/validation/builtin/max.js.map +1 -1
- package/dist/validation/builtin/maxDate.js +24 -0
- package/dist/validation/builtin/maxDate.js.map +1 -0
- package/dist/validation/builtin/maxLength.js +1 -0
- package/dist/validation/builtin/maxLength.js.map +1 -1
- package/dist/validation/builtin/min.js +1 -0
- package/dist/validation/builtin/min.js.map +1 -1
- package/dist/validation/builtin/minDate.js +24 -0
- package/dist/validation/builtin/minDate.js.map +1 -0
- package/dist/validation/builtin/minLength.js +1 -0
- package/dist/validation/builtin/minLength.js.map +1 -1
- package/dist/validation/builtin/notAlreadySubmitted.js +5 -1
- package/dist/validation/builtin/notAlreadySubmitted.js.map +1 -1
- package/dist/validation/builtin/oneOf.js +1 -0
- package/dist/validation/builtin/oneOf.js.map +1 -1
- package/dist/validation/builtin/pattern.js +11 -2
- package/dist/validation/builtin/pattern.js.map +1 -1
- package/dist/validation/builtin/url.js +1 -0
- package/dist/validation/builtin/url.js.map +1 -1
- package/dist/validation/builtin/validateDateBound.js +18 -0
- package/dist/validation/builtin/validateDateBound.js.map +1 -0
- package/dist/validation/builtin/validateRegexParams.js +44 -0
- package/dist/validation/builtin/validateRegexParams.js.map +1 -0
- package/dist/validation/emailPattern.js +10 -0
- package/dist/validation/emailPattern.js.map +1 -0
- package/dist/validation/fieldTargetParam.d.ts +22 -0
- package/dist/validation/fieldTargetParam.js +38 -0
- package/dist/validation/fieldTargetParam.js.map +1 -0
- package/dist/validation/registry.d.ts +2 -1
- package/dist/validation/registry.js +2 -9
- package/dist/validation/registry.js.map +1 -1
- package/dist/validation/runValidation.js +8 -29
- package/dist/validation/runValidation.js.map +1 -1
- package/dist/validation/types.d.ts +5 -11
- package/dist/validation/validateUrl.js +22 -0
- package/dist/validation/validateUrl.js.map +1 -0
- package/package.json +14 -6
- package/styles/form-builder.css +94 -190
- package/dist/collections/uploads.d.ts +0 -30
- package/dist/collections/uploads.js +0 -55
- package/dist/collections/uploads.js.map +0 -1
- package/dist/consent/buildConsentSourceConfig.js +0 -49
- package/dist/consent/buildConsentSourceConfig.js.map +0 -1
- package/dist/consent/builtin/index.d.ts +0 -7
- package/dist/consent/builtin/index.js +0 -11
- package/dist/consent/builtin/index.js.map +0 -1
- package/dist/consent/builtin/pageReference.js +0 -75
- package/dist/consent/builtin/pageReference.js.map +0 -1
- package/dist/consent/builtin/static.js +0 -44
- package/dist/consent/builtin/static.js.map +0 -1
- package/dist/consent/defineConsentSource.d.ts +0 -35
- package/dist/consent/defineConsentSource.js +0 -6
- package/dist/consent/defineConsentSource.js.map +0 -1
- package/dist/consent/registry.d.ts +0 -16
- package/dist/consent/registry.js +0 -16
- package/dist/consent/registry.js.map +0 -1
- package/dist/consent/resolveConsentLinks.d.ts +0 -19
- package/dist/consent/resolveConsentLinks.js +0 -26
- package/dist/consent/resolveConsentLinks.js.map +0 -1
- package/dist/presentations/registry.d.ts +0 -15
- package/dist/presentations/registry.js +0 -15
- package/dist/presentations/registry.js.map +0 -1
- package/dist/react/toFormDocument.d.ts +0 -24
- package/dist/react/toFormDocument.js +0 -22
- package/dist/react/toFormDocument.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"forms.js","names":[],"sources":["../../src/collections/forms.ts"],"sourcesContent":["import {\n\ttype CollectionBeforeValidateHook,\n\ttype CollectionConfig,\n\ttype Field,\n\ttype PayloadRequest,\n\tValidationError,\n} from 'payload'\nimport { buildActionBlocks } from '../actions/buildActionBlocks'\nimport type { ActionRegistry } from '../actions/registry'\nimport { resolveFormResultsRequest } from '../aggregation/resolveResultsRequest'\nimport { normalizeCalc } from '../calc/normalizeCalc'\nimport { buildConditionTypeMap } from '../conditions/conditionType'\nimport { type FieldRow, normalizeFormConditions } from '../conditions/normalizeConditions'\nimport type { ConsentSourceRegistry } from '../consent/registry'\nimport { buildFieldBlocks } from '../fields/buildFieldBlocks'\nimport type { FieldTypeRegistry } from '../fields/registry'\nimport { normalizeFlow } from '../flow/normalizeFlow'\nimport { isLoggedIn } from '../plugin/access'\nimport type { CollectionOverrides } from '../plugin/collectionOverrides'\nimport {\n\tDEFAULT_PRESENTATION_NAME,\n\tdefaultPresentationDescriptors,\n} from '../presentations/defaults'\nimport type { PresentationDescriptorRegistry } from '../presentations/registry'\nimport { keys } from '../translations/keys'\nimport { labelFor, labelForKey } from '../translations/server'\nimport type { ValidationRuleRegistry } from '../validation/registry'\n\nexport const FORMS_SLUG = 'forms'\n\nconst validateFlow = (raw: unknown): string | true => {\n\tif (raw === null || raw === undefined) return true\n\tconst r = raw as Record<string, unknown>\n\tif (!Array.isArray(r.steps)) return true\n\tconst steps = r.steps as Array<Record<string, unknown>>\n\tconst emptyIdStep = steps.find((s) => typeof s?.id !== 'string' || s.id.length === 0)\n\tif (emptyIdStep) return 'Flow: every step must have a non-empty ID'\n\tconst ids = steps.map((s) => s.id as string)\n\tif (new Set(ids).size !== ids.length) {\n\t\treturn 'Flow: duplicate step IDs found'\n\t}\n\tconst idSet = new Set(ids)\n\tfor (const step of steps) {\n\t\tconst id = step.id as string\n\t\tif (typeof step.next === 'string' && step.next.length > 0 && !idSet.has(step.next)) {\n\t\t\treturn `Flow: step \"${id}\" references unknown next step \"${step.next}\"`\n\t\t}\n\t\tif (Array.isArray(step.transitions)) {\n\t\t\tfor (const t of step.transitions as Array<Record<string, unknown>>) {\n\t\t\t\tif (typeof t?.to === 'string' && t.to.length > 0 && !idSet.has(t.to)) {\n\t\t\t\t\treturn `Flow: step \"${id}\" has a transition to unknown step \"${t.to}\"`\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn true\n}\n\n/** How many steps the caller actually submitted, before normalization strips/collapses the flow. */\nconst providedFlowStepCount = (raw: unknown): number => {\n\tif (raw === null || typeof raw !== 'object') return 0\n\tconst steps = (raw as { steps?: unknown }).steps\n\treturn Array.isArray(steps) ? steps.length : 0\n}\n\ntype BuildFormsCollectionArgs = {\n\tregistry: FieldTypeRegistry\n\truleRegistry: ValidationRuleRegistry\n\tconsentRegistry?: ConsentSourceRegistry\n\tpresentationRegistry?: PresentationDescriptorRegistry\n\tactionRegistry?: ActionRegistry\n\toverrides?: CollectionOverrides\n}\n\nexport const buildFormsCollection = ({\n\toverrides,\n\tregistry,\n\truleRegistry,\n\tconsentRegistry,\n\tpresentationRegistry = new Map(Object.entries(defaultPresentationDescriptors)),\n\tactionRegistry = new Map(),\n}: BuildFormsCollectionArgs): CollectionConfig => {\n\tconst conditionTypes = buildConditionTypeMap(registry)\n\tconst FLOW_BUILDER_REF = '@10x-media/form-builder/client#FlowBuilder'\n\n\tconst beforeValidate: CollectionBeforeValidateHook = ({ data, req }) => {\n\t\tif (\n\t\t\tdata &&\n\t\t\ttypeof data.defaultPresentation === 'string' &&\n\t\t\t!presentationRegistry.has(data.defaultPresentation)\n\t\t) {\n\t\t\tdata.defaultPresentation = DEFAULT_PRESENTATION_NAME\n\t\t}\n\t\tif (data && Array.isArray(data.fields)) {\n\t\t\tconst normalized: FieldRow[] = normalizeFormConditions(\n\t\t\t\tdata.fields as FieldRow[],\n\t\t\t\tconditionTypes\n\t\t\t)\n\t\t\tfor (const field of normalized) {\n\t\t\t\tif ('expression' in field) {\n\t\t\t\t\tfield.expression = normalizeCalc(field.expression)\n\t\t\t\t}\n\t\t\t}\n\t\t\tdata.fields = normalized\n\t\t\tconst fieldNames = normalized\n\t\t\t\t.map((field: FieldRow) => (typeof field.name === 'string' ? field.name : undefined))\n\t\t\t\t.filter((name): name is string => name !== undefined)\n\t\t\tconst normalizedFlow = normalizeFlow(data.flow, fieldNames)\n\t\t\t// A flow the author built but that collapses to fewer than two valid steps would\n\t\t\t// otherwise vanish silently. Surface it instead of discarding their work.\n\t\t\tif (providedFlowStepCount(data.flow) > 0 && normalizedFlow === undefined) {\n\t\t\t\tthrow new ValidationError(\n\t\t\t\t\t{\n\t\t\t\t\t\tcollection: FORMS_SLUG,\n\t\t\t\t\t\terrors: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tpath: 'flow',\n\t\t\t\t\t\t\t\tmessage:\n\t\t\t\t\t\t\t\t\t'A flow needs at least two steps with unique, non-empty IDs. Add another step or remove the flow.',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t\treq.t\n\t\t\t\t)\n\t\t\t}\n\t\t\tdata.flow = normalizedFlow\n\t\t}\n\t\treturn data\n\t}\n\n\tconst defaultFields: Field[] = [\n\t\t{ name: 'title', type: 'text', required: true, label: labelForKey(keys.fieldTitle) },\n\t\t{\n\t\t\tname: 'fields',\n\t\t\ttype: 'blocks',\n\t\t\tblocks: buildFieldBlocks(registry, ruleRegistry, consentRegistry),\n\t\t},\n\t\t{\n\t\t\tname: 'flow',\n\t\t\ttype: 'json',\n\t\t\tvalidate: validateFlow,\n\t\t\tadmin: {\n\t\t\t\tcomponents: {\n\t\t\t\t\tField: { path: FLOW_BUILDER_REF, clientProps: { conditionTypes } },\n\t\t\t\t},\n\t\t\t},\n\t\t\t// Narrows the generated TypeScript type from opaque JSON to FormFlow so callers\n\t\t\t// don't need a cast. Keep this in sync with src/flow/types.ts.\n\t\t\ttypescriptSchema: [\n\t\t\t\t() => ({\n\t\t\t\t\ttype: 'object' as const,\n\t\t\t\t\trequired: ['steps'],\n\t\t\t\t\tadditionalProperties: false,\n\t\t\t\t\tproperties: {\n\t\t\t\t\t\tsteps: {\n\t\t\t\t\t\t\ttype: 'array' as const,\n\t\t\t\t\t\t\titems: {\n\t\t\t\t\t\t\t\ttype: 'object' as const,\n\t\t\t\t\t\t\t\trequired: ['id'],\n\t\t\t\t\t\t\t\tadditionalProperties: true,\n\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\tid: { type: 'string' as const },\n\t\t\t\t\t\t\t\t\ttitle: { type: 'string' as const },\n\t\t\t\t\t\t\t\t\tfields: { type: 'array' as const, items: { type: 'string' as const } },\n\t\t\t\t\t\t\t\t\tnext: { type: 'string' as const },\n\t\t\t\t\t\t\t\t\ttransitions: {\n\t\t\t\t\t\t\t\t\t\ttype: 'array' as const,\n\t\t\t\t\t\t\t\t\t\titems: {\n\t\t\t\t\t\t\t\t\t\t\ttype: 'object' as const,\n\t\t\t\t\t\t\t\t\t\t\trequired: ['to'],\n\t\t\t\t\t\t\t\t\t\t\tadditionalProperties: true,\n\t\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\t\tto: { type: 'string' as const },\n\t\t\t\t\t\t\t\t\t\t\t\twhen: { type: 'object' as const, additionalProperties: true },\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t],\n\t\t},\n\t\t{\n\t\t\tname: 'actions',\n\t\t\ttype: 'blocks',\n\t\t\tblocks: buildActionBlocks(actionRegistry),\n\t\t\tlabel: labelForKey(keys.configActions),\n\t\t\t// Action config can contain secrets (e.g. signedWebhook.secret). The collection\n\t\t\t// itself is publicly readable so forms can be rendered by anonymous clients, but\n\t\t\t// action config must never be exposed to anonymous callers.\n\t\t\taccess: { read: isLoggedIn },\n\t\t},\n\t\t{\n\t\t\tname: 'defaultPresentation',\n\t\t\ttype: 'select',\n\t\t\tdefaultValue: DEFAULT_PRESENTATION_NAME,\n\t\t\toptions: [...presentationRegistry.values()].map((descriptor) => ({\n\t\t\t\tlabel: labelFor(descriptor.label),\n\t\t\t\tvalue: descriptor.name,\n\t\t\t})),\n\t\t\tlabel: labelForKey(keys.configDefaultPresentation),\n\t\t\tadmin: { position: 'sidebar' },\n\t\t},\n\t\t{\n\t\t\tname: 'showResults',\n\t\t\ttype: 'checkbox',\n\t\t\tdefaultValue: false,\n\t\t\tlabel: labelForKey(keys.configShowResults),\n\t\t\tadmin: { position: 'sidebar' },\n\t\t},\n\t\t{\n\t\t\tname: 'resultsField',\n\t\t\ttype: 'text',\n\t\t\tlabel: labelForKey(keys.configResultsField),\n\t\t\tadmin: {\n\t\t\t\tposition: 'sidebar',\n\t\t\t\tdescription:\n\t\t\t\t\t'Field whose aggregate results are public when \"Show results publicly\" is on. Use a choice field, never a free-text or PII field.',\n\t\t\t\tcondition: (data) => Boolean(data?.showResults),\n\t\t\t},\n\t\t},\n\t]\n\n\tconst defaultEndpoints: CollectionConfig['endpoints'] = [\n\t\t{\n\t\t\tpath: '/:id/results',\n\t\t\tmethod: 'get',\n\t\t\thandler: async (req: PayloadRequest) => {\n\t\t\t\tconst field = typeof req.query?.field === 'string' ? req.query.field : undefined\n\t\t\t\tconst { status, body } = await resolveFormResultsRequest({\n\t\t\t\t\tpayload: req.payload,\n\t\t\t\t\tformId: req.routeParams?.id as number | string | undefined,\n\t\t\t\t\tfield,\n\t\t\t\t\tisAuthed: Boolean(req.user),\n\t\t\t\t\treq,\n\t\t\t\t})\n\t\t\t\treturn Response.json(body, { status })\n\t\t\t},\n\t\t},\n\t]\n\n\treturn {\n\t\t...(overrides ?? {}),\n\t\tslug: FORMS_SLUG,\n\t\tlabels: {\n\t\t\tsingular: labelForKey(keys.collectionFormSingular),\n\t\t\tplural: labelForKey(keys.collectionFormPlural),\n\t\t\t...(overrides?.labels ?? {}),\n\t\t},\n\t\tadmin: { group: 'Forms', useAsTitle: 'title', ...(overrides?.admin ?? {}) },\n\t\taccess: { read: () => true, ...(overrides?.access ?? {}) },\n\t\thooks: {\n\t\t\t...(overrides?.hooks ?? {}),\n\t\t\t// beforeValidate normalizes conditions and flow; consumer hooks run after\n\t\t\tbeforeValidate: [beforeValidate, ...(overrides?.hooks?.beforeValidate ?? [])],\n\t\t},\n\t\tendpoints: [\n\t\t\t...defaultEndpoints,\n\t\t\t...(Array.isArray(overrides?.endpoints) ? overrides.endpoints : []),\n\t\t],\n\t\tfields: overrides?.fields ? overrides.fields({ defaultFields }) : defaultFields,\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;AA4BA,MAAa,aAAa;AAE1B,MAAM,gBAAgB,QAAgC;CACrD,IAAI,QAAQ,QAAQ,QAAQ,KAAA,GAAW,OAAO;CAC9C,MAAM,IAAI;CACV,IAAI,CAAC,MAAM,QAAQ,EAAE,KAAK,GAAG,OAAO;CACpC,MAAM,QAAQ,EAAE;CAEhB,IADoB,MAAM,MAAM,MAAM,OAAO,GAAG,OAAO,YAAY,EAAE,GAAG,WAAW,CACrE,GAAG,OAAO;CACxB,MAAM,MAAM,MAAM,KAAK,MAAM,EAAE,EAAY;CAC3C,IAAI,IAAI,IAAI,GAAG,EAAE,SAAS,IAAI,QAC7B,OAAO;CAER,MAAM,QAAQ,IAAI,IAAI,GAAG;CACzB,KAAK,MAAM,QAAQ,OAAO;EACzB,MAAM,KAAK,KAAK;EAChB,IAAI,OAAO,KAAK,SAAS,YAAY,KAAK,KAAK,SAAS,KAAK,CAAC,MAAM,IAAI,KAAK,IAAI,GAChF,OAAO,eAAe,GAAG,kCAAkC,KAAK,KAAK;EAEtE,IAAI,MAAM,QAAQ,KAAK,WAAW;QAC5B,MAAM,KAAK,KAAK,aACpB,IAAI,OAAO,GAAG,OAAO,YAAY,EAAE,GAAG,SAAS,KAAK,CAAC,MAAM,IAAI,EAAE,EAAE,GAClE,OAAO,eAAe,GAAG,sCAAsC,EAAE,GAAG;EAAA;CAIxE;CACA,OAAO;AACR;;AAGA,MAAM,yBAAyB,QAAyB;CACvD,IAAI,QAAQ,QAAQ,OAAO,QAAQ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AAM;EACN,QAAQ;EACR,SAAS,OAAO,QAAwB;GACvC,MAAM,QAAQ,OAAO,IAAI,OAAO,UAAU,WAAW,IAAI,MAAM,QAAQ,KAAA;GACvE,MAAM,EAAE,QAAQ,SAAS,MAAM,0BAA0B;IACxD,SAAS,IAAI;IACb,QAAQ,IAAI,aAAa;IACzB;IACA,UAAU,QAAQ,IAAI,IAAI;IAC1B;GACD,CAAC;GACD,OAAO,SAAS,KAAK,MAAM,EAAE,OAAO,CAAC;EACtC;CACD,CACD;CAEA,OAAO;EACN,GAAI,aAAa,CAAC;EAClB,MAAM;EACN,QAAQ;GACP,UAAU,YAAY,KAAK,sBAAsB;GACjD,QAAQ,YAAY,KAAK,oBAAoB;GAC7C,GAAI,WAAW,UAAU,CAAC;EAC3B;EACA,OAAO;GAAE,OAAO;GAAS,YAAY;GAAS,GAAI,WAAW,SAAS,CAAC;EAAG;EAC1E,QAAQ;GAAE,YAAY;GAAM,GAAI,WAAW,UAAU,CAAC;EAAG;EACzD,OAAO;GACN,GAAI,WAAW,SAAS,CAAC;GAEzB,gBAAgB,CAAC,gBAAgB,GAAI,WAAW,OAAO,kBAAkB,CAAC,CAAE;EAC7E;EACA,WAAW,CACV,GAAG,kBACH,GAAI,MAAM,QAAQ,WAAW,SAAS,IAAI,UAAU,YAAY,CAAC,CAClE;EACA,QAAQ,WAAW,SAAS,UAAU,OAAO,EAAE,cAAc,CAAC,IAAI;CACnE;AACD"}
|
|
1
|
+
{"version":3,"file":"forms.js","names":[],"sources":["../../src/collections/forms.ts"],"sourcesContent":["import {\n\ttype CollectionAfterChangeHook,\n\ttype CollectionAfterReadHook,\n\ttype CollectionBeforeValidateHook,\n\ttype CollectionConfig,\n\ttype CollectionSlug,\n\ttype Field,\n\ttype PayloadRequest,\n\ttype TextFieldSingleValidation,\n\tValidationError,\n} from 'payload'\nimport type { RichTextBodyOption } from '../actions/body/serializeBody'\nimport { buildActionBlocks } from '../actions/buildActionBlocks'\nimport type { FromAddressesResolver, FromAddressSourceRegistry } from '../actions/fromAddresses'\nimport type { ActionRegistry } from '../actions/registry'\nimport type { FormResultsAccess } from '../aggregation/resolveResultsRequest'\nimport { type CalcAllowed, normalizeCalc } from '../calc/normalizeCalc'\nimport type { CalcSource } from '../calc/registry'\nimport { calcUsesSources, resolveCalcContext } from '../calc/resolveCalcContext'\nimport { buildConditionTypeMap } from '../conditions/conditionType'\nimport {\n\tbuildOperandTypes,\n\ttype FieldRow,\n\tnormalizeFormConditions,\n\tnormalizeWhere,\n} from '../conditions/normalizeConditions'\nimport { resolveConsentStatements } from '../consent/resolveConsentStatements'\nimport type { ConsentSourcesResolver } from '../consent/types'\nimport type { DepartmentEmailsResolver } from '../email/departments'\nimport { buildFieldBlocks } from '../fields/buildFieldBlocks'\nimport { fieldNamesOfType } from '../fields/fieldNamesOfType'\nimport { localizedIf } from '../fields/localizedIf'\nimport type { FieldTypeRegistry } from '../fields/registry'\nimport { normalizeFlow } from '../flow/normalizeFlow'\nimport { END_OF_FORM } from '../flow/types'\nimport { pollConfigOf } from '../form/pollState'\nimport { isLoggedIn } from '../plugin/access'\nimport type { CollectionOverrides } from '../plugin/collectionOverrides'\nimport { buildPollOptionSourceFields } from '../poll/buildPollOptionSourceFields'\nimport { enqueuePollClose } from '../poll/closeJob'\nimport { pollOutcomeBeforeChange } from '../poll/outcomeBeforeChange'\nimport { buildDefaultOutcomeFields, type OutcomeFieldsOverride } from '../poll/outcomeFields'\nimport { type PollTypeRegistry, resolvePollTypes } from '../poll/pollTypeRegistry'\nimport type { PollOptionSourceRegistry } from '../poll/registry'\nimport { buildValidateResultsField, pollEligibleTypes } from '../poll/resultsField'\nimport type { FormFieldInstance } from '../submissions/types'\nimport { keys } from '../translations/keys'\nimport { asTranslate, labelForKey, resolveDefinitionLabel } from '../translations/server'\nimport type { ValidationRuleRegistry } from '../validation/registry'\nimport { validateUrl } from '../validation/validateUrl'\nimport { type ButtonsOption, buildDefaultButtonFields } from './buttonFields'\nimport { buildFormsEndpoints } from './formsEndpoints'\nimport type { ResponseOption } from './redirectFields'\nimport { composeSettingsFields, type SettingsOption } from './settingsFields'\n\nexport const FORMS_SLUG = 'forms'\n\n/** `req.context` key under which `consentAfterRead` tracks the form ids it is currently resolving, to break re-entrant reads. */\nconst CONSENT_AFTER_READ_GUARD = 'formBuilderConsentAfterReadInFlight'\n\n/** `req.context` key under which `calcAfterRead` tracks the form ids it is currently resolving, to break re-entrant reads. */\nconst CALC_AFTER_READ_GUARD = 'formBuilderCalcAfterReadInFlight'\n\n/**\n * Require the title in the default locale (and on hosts without localization), but let it be empty in\n * other locales so a localized form falls back to the default-locale title rather than forcing a\n * translation for every locale. Payload's field-level `required` cannot express this: it enforces per\n * write-locale, which would make a title mandatory in every locale and break the documented fallback.\n */\nconst validateFormTitle: TextFieldSingleValidation = (value, { req }) => {\n\tconst localization = req.payload.config.localization\n\tconst defaultLocale = localization ? localization.defaultLocale : undefined\n\tconst enforced =\n\t\tdefaultLocale === undefined || req.locale === undefined || req.locale === defaultLocale\n\tif (enforced && (typeof value !== 'string' || value.trim().length === 0)) {\n\t\treturn req.t('validation:required')\n\t}\n\treturn true\n}\n\n/**\n * Field-level validation for the raw flow JSON: step ids must be non-empty, unique, and not the\n * reserved `END_OF_FORM` sentinel, and every explicit step-id reference (a string `next`, a\n * transition `to`) must resolve to a known step. `next: null` (explicit end of form) and an\n * absent `next` (fall through to the next step in array order) are always valid. On full-document\n * saves the beforeValidate pass has already run `normalizeFlow` and laundered dangling\n * references, so the unknown-target checks mainly protect partial API updates that send `flow`\n * without `fields`.\n */\nconst validateFlow = (\n\traw: unknown,\n\t{ req }: { data?: unknown; req: PayloadRequest }\n): string | true => {\n\tif (raw === null || raw === undefined) return true\n\tconst r = raw as Record<string, unknown>\n\tif (!Array.isArray(r.steps)) return true\n\tconst steps = r.steps as Array<Record<string, unknown>>\n\tconst t = asTranslate(req.t)\n\tconst emptyIdStep = steps.find((s) => typeof s?.id !== 'string' || s.id.length === 0)\n\tif (emptyIdStep) return t(keys.flowStepIdEmpty)\n\tif (steps.some((s) => s.id === END_OF_FORM)) {\n\t\treturn t(keys.flowStepIdReserved).replace('{id}', END_OF_FORM)\n\t}\n\tconst ids = steps.map((s) => s.id as string)\n\tif (new Set(ids).size !== ids.length) {\n\t\treturn t(keys.flowDuplicateStepIds)\n\t}\n\tconst idSet = new Set(ids)\n\tfor (const step of steps) {\n\t\tconst id = step.id as string\n\t\tif (typeof step.next === 'string' && step.next.length > 0 && !idSet.has(step.next)) {\n\t\t\treturn t(keys.flowUnknownNext).replace('{id}', id).replace('{next}', step.next)\n\t\t}\n\t\tif (Array.isArray(step.transitions)) {\n\t\t\tfor (const trans of step.transitions as Array<Record<string, unknown>>) {\n\t\t\t\tif (typeof trans?.to === 'string' && trans.to.length > 0 && !idSet.has(trans.to)) {\n\t\t\t\t\treturn t(keys.flowUnknownTransition).replace('{id}', id).replace('{to}', trans.to)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn true\n}\n\n/** How many steps the caller actually submitted, before normalization strips/collapses the flow. */\nconst providedFlowStepCount = (raw: unknown): number => {\n\tif (raw === null || typeof raw !== 'object') return 0\n\tconst steps = (raw as { steps?: unknown }).steps\n\treturn Array.isArray(steps) ? steps.length : 0\n}\n\n/**\n * Stamp the configured uploads collection slug onto every `file` block (including repeater\n * sub-fields) on each save. The block carries a hidden `uploadsCollection` field so the slug\n * reaches the client renderer through the form document; the server always overwrites it from\n * plugin config, so the stored value is never author- or client-controlled.\n */\nconst stampFileCollections = (rows: FieldRow[], slug: string): void => {\n\tfor (const row of rows) {\n\t\tif (row.blockType === 'file') {\n\t\t\t;(row as { uploadsCollection?: string }).uploadsCollection = slug\n\t\t}\n\t\tconst subFields = (row as { subFields?: unknown }).subFields\n\t\tif (Array.isArray(subFields)) {\n\t\t\tstampFileCollections(subFields as FieldRow[], slug)\n\t\t}\n\t}\n}\n\ntype BuildFormsCollectionArgs = {\n\tregistry: FieldTypeRegistry\n\truleRegistry: ValidationRuleRegistry\n\t/** Registered calc extension names; expressions referencing anything else are dropped on save. */\n\tcalcAllowed?: CalcAllowed\n\t/** Registered calc sources; when a form's expressions use any, an afterRead hook stamps `doc.calcResolved`. */\n\tcalcSources?: Record<string, CalcSource>\n\t/**\n\t * The plugin `consent.sources` option. Present: the `/:id/consent-sources` endpoint backing the\n\t * consent field's source select is registered. Absent: neither it nor the consent field type exists.\n\t */\n\tconsentSources?: ConsentSourcesResolver\n\t/** Plugin `consent.resolveOnRead` (default true); `false` skips the per-read consent afterRead hook. */\n\tconsentResolveOnRead?: boolean\n\tactionRegistry?: ActionRegistry\n\tlocalizeContent?: boolean\n\t/** The plugin `richText` option; `responseEditor ?? editor` sets the response message field's editor. */\n\trichText?: RichTextBodyOption\n\t/** The host-owned uploads collection slug from plugin config; absent when uploads are disabled. */\n\tuploadsCollectionSlug?: string\n\t/** Host seam gating anonymous results reads (plugin option `results.access`). */\n\tresultsAccess?: FormResultsAccess\n\t/**\n\t * Whether the hidden tally store is registered (`poll.votes !== false`). Threads into the poll\n\t * endpoints (tally-backed reads) and, when false, forbids poll forms from disabling\n\t * `persistSubmissions`: with neither store nor submissions there would be nothing to count.\n\t */\n\tpollVotesEnabled?: boolean\n\t/** Registered poll option sources (plugin option `poll.sources`); empty registry means no source fields. */\n\tpollSourceRegistry?: PollOptionSourceRegistry\n\t/** Registered poll outcome strategies (`poll.types`); drives the poll `type` select options. Defaults to the built-ins. */\n\tpollTypeRegistry?: PollTypeRegistry\n\t/** The plugin `poll.outcomeFields` seam; composes the outcome group from the two default fields. */\n\toutcomeFields?: OutcomeFieldsOverride\n\t/** The plugin `buttons` option; `fields` composes the `{ submit, prev, next }` labels from the localized defaults. */\n\tbuttons?: ButtonsOption\n\t/** The plugin `settings` option; `fields` composes the sidebar flag checkboxes from the defaults. */\n\tsettings?: SettingsOption\n\t/** The plugin `response` option; `redirect.fields` composes the `response.redirect` group from its default fields. */\n\tresponse?: ResponseOption\n\t/**\n\t * The plugin `email.fromAddresses` option. Either this or `fromSources` present: both email\n\t * actions gain a `from` select and the `/:id/from-addresses` endpoint is registered. Both\n\t * absent: neither exists.\n\t */\n\tfromAddresses?: FromAddressesResolver\n\t/** The plugin `email.fromSources` option: send-time-resolved senders served ahead of the literals. */\n\tfromSources?: FromAddressSourceRegistry\n\t/**\n\t * The plugin `email.departments` option. Present: the `emailTeam` `to` becomes a department select\n\t * and the `/:id/departments` endpoint backing it is registered. Absent: `to` stays a plain field.\n\t */\n\tdepartments?: DepartmentEmailsResolver\n\t/**\n\t * The plugin `redirectRelationships` option. Non-empty: `response.redirect` gains a polymorphic\n\t * `reference` relationship field so an author can redirect to an internal document instead of\n\t * (or alongside) a URL. Absent or empty: no `reference` field exists, matching today's URL-only\n\t * redirect.\n\t */\n\tredirectRelationships?: CollectionSlug[]\n\toverrides?: CollectionOverrides\n}\n\nexport const buildFormsCollection = ({\n\toverrides,\n\tregistry,\n\truleRegistry,\n\tcalcAllowed,\n\tcalcSources,\n\tconsentSources,\n\tconsentResolveOnRead,\n\tactionRegistry = new Map(),\n\tlocalizeContent = true,\n\trichText,\n\tuploadsCollectionSlug,\n\tresultsAccess,\n\tpollVotesEnabled = false,\n\tpollSourceRegistry,\n\tpollTypeRegistry,\n\toutcomeFields,\n\tbuttons,\n\tsettings,\n\tresponse,\n\tfromAddresses,\n\tfromSources,\n\tdepartments,\n\tredirectRelationships,\n}: BuildFormsCollectionArgs): CollectionConfig => {\n\tconst conditionTypes = buildConditionTypeMap(registry)\n\tconst pollTypes = pollTypeRegistry ?? resolvePollTypes()\n\tconst pollResultsTypes = pollEligibleTypes(registry)\n\tconst bareTypes = new Set(\n\t\t[...registry.values()].filter((d) => d.bare === true).map((d) => d.type)\n\t)\n\t// Handed to the FlowBuilder so it can list bare (nameless) blocks in the step picker: slug ->\n\t// label (an i18n key or literal, resolved client-side).\n\tconst bareTypeLabels = Object.fromEntries(\n\t\t[...registry.values()].filter((d) => d.bare === true).map((d) => [d.type, d.label])\n\t)\n\t// The success `response` message field's editor: `richText.responseEditor` overrides the plugin-wide\n\t// `richText.editor` for this field alone (mirroring `bodyEditor` for action bodies).\n\tconst responseEditor = richText?.responseEditor ?? richText?.editor\n\tconst FLOW_BUILDER_REF = '@10x-media/form-builder/client#FlowBuilder'\n\tconst FIELD_NAME_SELECT_REF = '@10x-media/form-builder/client#FieldNameSelect'\n\tconst FLOW_STEPS_CELL_REF = '@10x-media/form-builder/client#FlowStepsCell'\n\tconst FIELD_COUNT_CELL_REF = '@10x-media/form-builder/client#FieldCountCell'\n\tconst CLOSE_POLL_BUTTON_REF = '@10x-media/form-builder/client#ClosePollButton'\n\t// The `source` outcome strategy delegates to the poll's option source, so it is useless without one:\n\t// offer it in the author-facing select only when option sources are registered. The strategy stays in\n\t// the registry regardless, so `resolvePollOutcome` and host code can still address it.\n\tconst hasOptionSources = (pollSourceRegistry?.size ?? 0) > 0\n\t// `mostVoted` leads the author-facing select because it is the default: an enabled poll works\n\t// immediately, with no winner to hand-pick. Only the select order changes; the registry keeps its\n\t// own order (host strategies stay after the built-ins).\n\tconst orderedPollTypes = [\n\t\t...[...pollTypes.values()].filter((strategy) => strategy.type === 'mostVoted'),\n\t\t...[...pollTypes.values()].filter((strategy) => strategy.type !== 'mostVoted'),\n\t]\n\n\tconst beforeValidate: CollectionBeforeValidateHook = ({ data, originalDoc, req }) => {\n\t\t// Without the tally store, pruned submissions would erase every vote: a poll form may only\n\t\t// turn `persistSubmissions` off while the store is registered to carry the counts. Evaluated\n\t\t// on the incoming partial merged over the stored doc (outcomeBeforeChange precedent), so a\n\t\t// PATCH flipping either flag alone cannot slip past the guard.\n\t\tif (!pollVotesEnabled) {\n\t\t\tconst pollOn = (data?.pollEnabled ?? originalDoc?.pollEnabled) === true\n\t\t\tconst persistOff = (data?.persistSubmissions ?? originalDoc?.persistSubmissions) === false\n\t\t\tif (pollOn && persistOff) {\n\t\t\t\tthrow new ValidationError(\n\t\t\t\t\t{\n\t\t\t\t\t\tcollection: FORMS_SLUG,\n\t\t\t\t\t\terrors: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tpath: 'persistSubmissions',\n\t\t\t\t\t\t\t\tmessage: asTranslate(req.t)(keys.pollNeedsPersistedSubmissions),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t\treq.t\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\t{\n\t\t\t// Changeable votes update the voter's stored submission in place, so `allowChange` cannot\n\t\t\t// coexist with pruning: a pruned row would make the next \"change\" a second, double-counted\n\t\t\t// vote. Same merged-partial evaluation as the guard above.\n\t\t\tconst pollOn = (data?.pollEnabled ?? originalDoc?.pollEnabled) === true\n\t\t\tconst persistOff = (data?.persistSubmissions ?? originalDoc?.persistSubmissions) === false\n\t\t\tconst allowChangeOn =\n\t\t\t\t(pollConfigOf(data?.poll)?.allowChange ?? pollConfigOf(originalDoc?.poll)?.allowChange) ===\n\t\t\t\ttrue\n\t\t\tif (pollOn && persistOff && allowChangeOn) {\n\t\t\t\tthrow new ValidationError(\n\t\t\t\t\t{\n\t\t\t\t\t\tcollection: FORMS_SLUG,\n\t\t\t\t\t\terrors: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tpath: 'persistSubmissions',\n\t\t\t\t\t\t\t\tmessage: asTranslate(req.t)(keys.pollAllowChangeNeedsPersistedSubmissions),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t\treq.t\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\tif (data && Array.isArray(data.fields)) {\n\t\t\tconst normalized: FieldRow[] = normalizeFormConditions(\n\t\t\t\tdata.fields as FieldRow[],\n\t\t\t\tconditionTypes\n\t\t\t)\n\t\t\tfor (const field of normalized) {\n\t\t\t\tif ('expression' in field) {\n\t\t\t\t\tfield.expression = normalizeCalc(field.expression, calcAllowed)\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (uploadsCollectionSlug) {\n\t\t\t\tstampFileCollections(normalized, uploadsCollectionSlug)\n\t\t\t}\n\t\t\tdata.fields = normalized\n\t\t\t// Flow step assignments store field keys: machine names for named fields, block row ids\n\t\t\t// for bare (nameless) blocks. Mirrors `fieldKey` over the raw rows.\n\t\t\tconst fieldKeys = normalized\n\t\t\t\t.map((field: FieldRow) => {\n\t\t\t\t\tif (typeof field.name === 'string' && field.name.length > 0) {\n\t\t\t\t\t\treturn field.name\n\t\t\t\t\t}\n\t\t\t\t\treturn bareTypes.has(field.blockType) && field.id != null ? String(field.id) : undefined\n\t\t\t\t})\n\t\t\t\t.filter((key): key is string => key !== undefined)\n\t\t\t// Launder flow transition `when` clauses with the same operand-type rules as field conditions,\n\t\t\t// so a transition referencing a deleted field is dropped, not left as a route that always\n\t\t\t// matches at navigation time and force-routes the visitor.\n\t\t\tconst operandTypes = buildOperandTypes(normalized, conditionTypes)\n\t\t\tconst normalizedFlow = normalizeFlow(data.flow, fieldKeys, (w) =>\n\t\t\t\tnormalizeWhere(w, operandTypes)\n\t\t\t)\n\t\t\t// A flow the author built but that collapses to fewer than two valid steps would\n\t\t\t// otherwise vanish silently. Surface it instead of discarding their work.\n\t\t\tif (providedFlowStepCount(data.flow) > 0 && normalizedFlow === undefined) {\n\t\t\t\tthrow new ValidationError(\n\t\t\t\t\t{\n\t\t\t\t\t\tcollection: FORMS_SLUG,\n\t\t\t\t\t\terrors: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tpath: 'flow',\n\t\t\t\t\t\t\t\tmessage: asTranslate(req.t)(keys.flowNeedsTwoSteps),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t\treq.t\n\t\t\t\t)\n\t\t\t}\n\t\t\tdata.flow = normalizedFlow\n\t\t\t// A poll needs a field whose answers are the votes. With the poll enabled and no vote field\n\t\t\t// chosen (and the outcome not coming from an option source), bind one: auto-fill the sole\n\t\t\t// eligible field for a one-choice form, otherwise surface a clear error rather than storing a\n\t\t\t// poll that can never aggregate. The optionSource/`source` exemption preserves domain-driven\n\t\t\t// polls that have no on-form vote field. `buildValidateResultsField` still checks a set value;\n\t\t\t// this is the enforcer for enabled polls.\n\t\t\tif (data.pollEnabled === true) {\n\t\t\t\tconst poll =\n\t\t\t\t\tdata.poll != null && typeof data.poll === 'object'\n\t\t\t\t\t\t? (data.poll as Record<string, unknown>)\n\t\t\t\t\t\t: {}\n\t\t\t\tconst resultsField = typeof poll.resultsField === 'string' ? poll.resultsField.trim() : ''\n\t\t\t\tconst optionSource = typeof poll.optionSource === 'string' ? poll.optionSource.trim() : ''\n\t\t\t\tconst sourceDriven = optionSource.length > 0 || poll.type === 'source'\n\t\t\t\tif (resultsField.length === 0 && !sourceDriven) {\n\t\t\t\t\tconst eligible = fieldNamesOfType(data.fields, pollResultsTypes)\n\t\t\t\t\tif (eligible.length === 1) {\n\t\t\t\t\t\tdata.poll = { ...poll, resultsField: eligible[0] }\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst messageKey =\n\t\t\t\t\t\t\teligible.length > 1 ? keys.pollVoteFieldChoose : keys.pollVoteFieldMissing\n\t\t\t\t\t\tthrow new ValidationError(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcollection: FORMS_SLUG,\n\t\t\t\t\t\t\t\terrors: [{ path: 'poll.resultsField', message: asTranslate(req.t)(messageKey) }],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\treq.t\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn data\n\t}\n\n\t// After every save, (re)schedule the poll's auto-close job when it applies (enabled + closesAt +\n\t// unresolved + non-manual strategy + a job runner present). Best-effort and non-throwing, so it\n\t// never affects the save; without a runner the resolve-on-read fallback in the results endpoint\n\t// heals the outcome instead.\n\tconst pollCloseAfterChange: CollectionAfterChangeHook = async ({ doc, req }) => {\n\t\tawait enqueuePollClose({ payload: req.payload, form: doc, req })\n\t\treturn doc\n\t}\n\n\tconst fieldsField: Field = {\n\t\tname: 'fields',\n\t\ttype: 'blocks',\n\t\tblocks: buildFieldBlocks({ registry, ruleRegistry, localize: localizeContent }),\n\t\tadmin: { components: { Cell: FIELD_COUNT_CELL_REF } },\n\t}\n\n\tconst flowField: Field = {\n\t\tname: 'flow',\n\t\ttype: 'json',\n\t\tvalidate: validateFlow,\n\t\tadmin: {\n\t\t\tcomponents: {\n\t\t\t\tCell: FLOW_STEPS_CELL_REF,\n\t\t\t\tField: { path: FLOW_BUILDER_REF, clientProps: { conditionTypes, bareTypeLabels } },\n\t\t\t},\n\t\t},\n\t\t// Narrows the generated TypeScript type from opaque JSON to FormFlow so callers\n\t\t// don't need a cast. Keep this in sync with src/flow/types.ts.\n\t\ttypescriptSchema: [\n\t\t\t() => ({\n\t\t\t\ttype: 'object' as const,\n\t\t\t\trequired: ['steps'],\n\t\t\t\tadditionalProperties: false,\n\t\t\t\tproperties: {\n\t\t\t\t\tsteps: {\n\t\t\t\t\t\ttype: 'array' as const,\n\t\t\t\t\t\titems: {\n\t\t\t\t\t\t\ttype: 'object' as const,\n\t\t\t\t\t\t\trequired: ['id'],\n\t\t\t\t\t\t\tadditionalProperties: true,\n\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\tid: { type: 'string' as const },\n\t\t\t\t\t\t\t\ttitle: { type: 'string' as const },\n\t\t\t\t\t\t\t\tfields: { type: 'array' as const, items: { type: 'string' as const } },\n\t\t\t\t\t\t\t\tnext: { type: ['string', 'null'] as ('string' | 'null')[] },\n\t\t\t\t\t\t\t\ttransitions: {\n\t\t\t\t\t\t\t\t\ttype: 'array' as const,\n\t\t\t\t\t\t\t\t\titems: {\n\t\t\t\t\t\t\t\t\t\ttype: 'object' as const,\n\t\t\t\t\t\t\t\t\t\trequired: ['to'],\n\t\t\t\t\t\t\t\t\t\tadditionalProperties: true,\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tto: { type: 'string' as const },\n\t\t\t\t\t\t\t\t\t\t\twhen: { type: 'object' as const, additionalProperties: true },\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t],\n\t}\n\n\tconst actionsField: Field = {\n\t\tname: 'actions',\n\t\ttype: 'blocks',\n\t\tblocks: buildActionBlocks(actionRegistry),\n\t\tlabel: labelForKey(keys.configActions),\n\t\t// Action config can contain secrets (e.g. signedWebhook.secret). The collection\n\t\t// itself is publicly readable so forms can be rendered by anonymous clients, but\n\t\t// action config must never be exposed to anonymous callers.\n\t\taccess: { read: isLoggedIn },\n\t}\n\n\t// Optional polymorphic reference to an internal document, for `response.redirect` to point at\n\t// instead of (or alongside) a URL. Absent unless `redirectRelationships` is a non-empty array:\n\t// always polymorphic even for one slug (the consent `page` field's precedent), so a host adding\n\t// a second collection later never changes the stored shape. The plugin never resolves this to a\n\t// URL itself; `toFormDocument` passes the raw `{ relationTo, value }` through for the host to\n\t// resolve, since only the host knows its own routing.\n\tconst redirectReferenceField: Field[] =\n\t\tredirectRelationships && redirectRelationships.length > 0\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'reference',\n\t\t\t\t\t\ttype: 'relationship',\n\t\t\t\t\t\trelationTo: redirectRelationships,\n\t\t\t\t\t\tlabel: labelForKey(keys.responseRedirectReference),\n\t\t\t\t\t\tadmin: { description: labelForKey(keys.responseRedirectReferenceDescription) },\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t: []\n\n\t// The redirect group's fields: the `url` text field plus the optional polymorphic `reference`.\n\t// The `response.redirect.fields` seam composes them (mirroring `buttons.fields`), so a host can\n\t// prepend a custom link field, swap `url` for their own picker, or filter; the default (no\n\t// override) is the same `[url, ...reference]` as before. Built-in redirect handling still reads\n\t// `redirect.url`/`redirect.reference`, so a host replacing `url` owns resolving their field to a\n\t// destination in their frontend.\n\tconst urlField: Field = {\n\t\tname: 'url',\n\t\ttype: 'text',\n\t\tlabel: labelForKey(keys.responseUrl),\n\t\tvalidate: validateUrl,\n\t}\n\tconst defaultRedirectFields: Field[] = [urlField, ...redirectReferenceField]\n\tconst redirectFields = response?.redirect?.fields\n\t\t? response.redirect.fields({ defaultFields: defaultRedirectFields })\n\t\t: defaultRedirectFields\n\n\t// What the visitor sees after a successful submit. Publicly readable (unlike actions): the\n\t// client renderer needs message/redirect. `type`/`url` are behavior, never localized;\n\t// `message` is visitor-facing content and follows `localizeContent`.\n\t// `type` is defaulted and not clearable rather than `required`: a required member would make\n\t// the whole group required in generated types, breaking typed `payload.create` calls that\n\t// omit `response`. Consumers treat a missing type as 'message'.\n\tconst responseField: Field = {\n\t\tname: 'response',\n\t\ttype: 'group',\n\t\tfields: [\n\t\t\t{\n\t\t\t\tname: 'type',\n\t\t\t\ttype: 'select',\n\t\t\t\tdefaultValue: 'message',\n\t\t\t\tlabel: labelForKey(keys.responseType),\n\t\t\t\tadmin: { isClearable: false },\n\t\t\t\toptions: [\n\t\t\t\t\t{ label: labelForKey(keys.responseTypeMessage), value: 'message' },\n\t\t\t\t\t{ label: labelForKey(keys.responseTypeRedirect), value: 'redirect' },\n\t\t\t\t],\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'message',\n\t\t\t\ttype: 'richText',\n\t\t\t\tlabel: labelForKey(keys.responseMessage),\n\t\t\t\t// Unset type (docs predating this field) means 'message', matching the client fallback.\n\t\t\t\tadmin: { condition: (_data, siblingData) => siblingData?.type !== 'redirect' },\n\t\t\t\t...(responseEditor ? { editor: responseEditor } : {}),\n\t\t\t\t...localizedIf(localizeContent),\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'redirect',\n\t\t\t\ttype: 'group',\n\t\t\t\tlabel: labelForKey(keys.responseRedirect),\n\t\t\t\tadmin: {\n\t\t\t\t\tcondition: (_data, siblingData) => siblingData?.type === 'redirect',\n\t\t\t\t\thideGutter: true,\n\t\t\t\t},\n\t\t\t\tfields: redirectFields,\n\t\t\t},\n\t\t],\n\t}\n\n\tconst defaultOutcomeFields = buildDefaultOutcomeFields()\n\tconst defaultButtonFields = buildDefaultButtonFields(localizeContent)\n\t// Half-width copy of a default field for the prev/next row; merges width into whatever admin the\n\t// field already carries (a host's `buttons.fields` override may add its own) rather than replacing\n\t// it. The cast is safe: `width` is a valid admin option on every field variant, but spreading a\n\t// `Field`-typed value's `admin` back into a union-typed object literal loses the discriminant TS\n\t// needs to check it structurally.\n\tconst halfWidth = (field: Field): Field =>\n\t\t({ ...field, admin: { ...field.admin, width: '50%' } }) as Field\n\t// The three button-label fields sit at the document root now (no `buttons` group): `submit` at\n\t// the bottom of the Fields tab, `prev`/`next` in a row on the Flow tab. The `buttons.fields` seam\n\t// composes each slot from the already-localized defaults, so a host can wrap a default in a row\n\t// with its own field (e.g. an icon select) or replace it; `toFormDocument` reassembles the three\n\t// labels into `FormDocument.buttons` for the client.\n\tconst composedButtons = buttons?.fields\n\t\t? buttons.fields({ defaultFields: defaultButtonFields })\n\t\t: defaultButtonFields\n\tconst submitField = composedButtons.submit\n\tconst prevNextRow: Field = {\n\t\ttype: 'row',\n\t\t// The prev/next labels only matter once the flow has a step; the Flow tab itself is gated on\n\t\t// `multistep`. `data` (1st arg) is the whole document, so `flow.steps` reads the stored flow.\n\t\tadmin: {\n\t\t\tcondition: (data) => {\n\t\t\t\tconst steps = (data as { flow?: { steps?: unknown } })?.flow?.steps\n\t\t\t\treturn Array.isArray(steps) && steps.length >= 1\n\t\t\t},\n\t\t},\n\t\tfields: [halfWidth(composedButtons.prev), halfWidth(composedButtons.next)],\n\t}\n\n\t// Poll lifecycle config; identifiers and behavior, never localized. Lives inside the conditional\n\t// Poll tab (gated on the top-level `pollEnabled` flag), so the per-field enabled conditions are\n\t// gone; `label: false` suppresses the group header the tab label already provides.\n\t// `resultsVisibility` is defaulted and not clearable rather than `required` for the same\n\t// generated-types reason as `response.type`.\n\tconst pollGroupField: Field = {\n\t\tname: 'poll',\n\t\ttype: 'group',\n\t\tlabel: false,\n\t\tfields: [\n\t\t\t// Authored by picking from the form's poll-eligible fields; the stored value stays a plain\n\t\t\t// text field name. Select options and server validate share `pollResultsTypes`, so they\n\t\t\t// cannot drift.\n\t\t\t{\n\t\t\t\tname: 'resultsField',\n\t\t\t\ttype: 'text',\n\t\t\t\tlabel: labelForKey(keys.pollResultsField),\n\t\t\t\tvalidate: buildValidateResultsField(pollResultsTypes),\n\t\t\t\tadmin: {\n\t\t\t\t\tcomponents: {\n\t\t\t\t\t\tField: {\n\t\t\t\t\t\t\tpath: FIELD_NAME_SELECT_REF,\n\t\t\t\t\t\t\tclientProps: {\n\t\t\t\t\t\t\t\ttypes: pollResultsTypes,\n\t\t\t\t\t\t\t\tdescriptionKey: keys.pollResultsFieldDescription,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t// How the winning value(s) get decided. `mostVoted` (default) and `source` auto-resolve on close\n\t\t\t// (via the scheduled job or the results-read fallback); `manual` leaves it to an admin. Options\n\t\t\t// come from the registered `poll.types` strategies, so a host strategy appears here too, with\n\t\t\t// `mostVoted` first so an enabled poll works with no winner to hand-pick.\n\t\t\t{\n\t\t\t\tname: 'type',\n\t\t\t\ttype: 'select',\n\t\t\t\tdefaultValue: 'mostVoted',\n\t\t\t\tlabel: labelForKey(keys.pollType),\n\t\t\t\tadmin: { isClearable: false, description: labelForKey(keys.pollTypeDescription) },\n\t\t\t\toptions: orderedPollTypes\n\t\t\t\t\t.filter((strategy) => strategy.type !== 'source' || hasOptionSources)\n\t\t\t\t\t.map((strategy) => ({\n\t\t\t\t\t\tlabel: resolveDefinitionLabel(strategy.label),\n\t\t\t\t\t\tvalue: strategy.type,\n\t\t\t\t\t})),\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'resultsVisibility',\n\t\t\t\ttype: 'select',\n\t\t\t\tdefaultValue: 'afterVote',\n\t\t\t\tlabel: labelForKey(keys.pollResultsVisibility),\n\t\t\t\tadmin: { isClearable: false },\n\t\t\t\toptions: [\n\t\t\t\t\t{ label: labelForKey(keys.pollVisibilityAfterVote), value: 'afterVote' },\n\t\t\t\t\t{ label: labelForKey(keys.pollVisibilityAfterClose), value: 'afterClose' },\n\t\t\t\t],\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'allowChange',\n\t\t\t\ttype: 'checkbox',\n\t\t\t\tdefaultValue: false,\n\t\t\t\tlabel: labelForKey(keys.pollAllowChange),\n\t\t\t\tadmin: { description: labelForKey(keys.pollAllowChangeDescription) },\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'closesAt',\n\t\t\t\ttype: 'date',\n\t\t\t\tlabel: labelForKey(keys.pollClosesAt),\n\t\t\t\tadmin: { date: { pickerAppearance: 'dayAndTime' } },\n\t\t\t},\n\t\t\t// Close / reopen the poll from the admin. The button toggles on the live `closesAt` and saves the\n\t\t\t// whole document (persisting an unsaved winner alongside `closesAt`) rather than calling the close\n\t\t\t// endpoint, so there is no DB-vs-form-state mismatch. Always mounted inside the (pollEnabled-gated)\n\t\t\t// Poll tab now; the button owns both states, so it carries no `admin.condition` of its own.\n\t\t\t{\n\t\t\t\tname: 'closePoll',\n\t\t\t\ttype: 'ui',\n\t\t\t\tadmin: {\n\t\t\t\t\tcomponents: { Field: CLOSE_POLL_BUTTON_REF },\n\t\t\t\t},\n\t\t\t},\n\t\t\t...buildPollOptionSourceFields(pollSourceRegistry ?? new Map()),\n\t\t\t// `winningValues` is recorded either by an admin picking from the poll's effective options\n\t\t\t// (served by `/:id/poll-options`) or by `resolvePollOutcome` (host domain logic); more than\n\t\t\t// one value records a tie. The `pollOutcomeBeforeChange` hook validates both paths and owns\n\t\t\t// the `resolvedAt` stamp. `resolvedAt` itself stays fully locked: field-level create/update\n\t\t\t// access blocks every non-override caller write (Payload silently drops the denied value\n\t\t\t// rather than erroring) while the hook's stamp, applied after access filtering, still\n\t\t\t// persists. The `poll.outcomeFields` seam receives both defaults and its return becomes the\n\t\t\t// group's fields verbatim, so a host can swap `winningValues` for its own component; the hook\n\t\t\t// still validates every stored value against the effective options, so no swap bypasses it.\n\t\t\t// `hideGutter` stays: outcome is still a group nested inside the poll group.\n\t\t\t{\n\t\t\t\tname: 'outcome',\n\t\t\t\ttype: 'group',\n\t\t\t\tlabel: labelForKey(keys.pollOutcome),\n\t\t\t\tadmin: { hideGutter: true },\n\t\t\t\tfields: outcomeFields\n\t\t\t\t\t? outcomeFields({ defaultFields: defaultOutcomeFields })\n\t\t\t\t\t: [defaultOutcomeFields.winningValues, defaultOutcomeFields.resolvedAt],\n\t\t\t},\n\t\t],\n\t}\n\n\tconst defaultFields: Field[] = [\n\t\t// The document title is the only visitor-facing text the collection renders itself: it is\n\t\t// always required (drives `useAsTitle` in the admin list/relationship views) and is passed\n\t\t// through `toFormDocument` as `FormDocument.title`. Whether and how a host renders it above\n\t\t// the fields is entirely the host's call; the plugin does not gate or duplicate it.\n\t\t{\n\t\t\tname: 'title',\n\t\t\ttype: 'text',\n\t\t\tlabel: labelForKey(keys.fieldTitle),\n\t\t\t// Visitor-facing content, so it follows `localizeContent` like the response message and\n\t\t\t// consent statement: hosts with localization get a per-locale title (and a locale-aware\n\t\t\t// `useAsTitle`), hosts without it are unaffected since Payload strips the flag. `validate`\n\t\t\t// (not `required`) keeps it mandatory only in the default locale so other locales fall back.\n\t\t\t...localizedIf(localizeContent),\n\t\t\tvalidate: validateFormTitle,\n\t\t},\n\t\t// The three form-level flags: behavior, never localized, sidebar checkboxes by default.\n\t\t// `multistep` gates the Flow tab and the client's step navigation; `pollEnabled` gates the\n\t\t// Poll tab and marks the form a poll; `persistSubmissions` (default checked) tells the plugin\n\t\t// whether to keep a submission's row after its actions run, or prune it. The `settings.fields`\n\t\t// seam composes them from the defaults, mirroring `buttons.fields`.\n\t\t...composeSettingsFields(settings),\n\t\t// Unnamed tabs are presentational: their fields stay at the document root. An unnamed tab's\n\t\t// `admin.condition` receives the whole document as its 2nd arg, so the Flow and Poll tabs gate\n\t\t// on the root-level flags. The poll group nests its config under `form.poll` as before.\n\t\t{\n\t\t\ttype: 'tabs',\n\t\t\ttabs: [\n\t\t\t\t{ label: labelForKey(keys.tabFields), fields: [fieldsField, submitField] },\n\t\t\t\t{\n\t\t\t\t\tlabel: labelForKey(keys.tabFlow),\n\t\t\t\t\tadmin: { condition: (_data, siblingData) => siblingData?.multistep === true },\n\t\t\t\t\tfields: [flowField, prevNextRow],\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tlabel: labelForKey(keys.pollGroup),\n\t\t\t\t\tadmin: { condition: (_data, siblingData) => siblingData?.pollEnabled === true },\n\t\t\t\t\tfields: [pollGroupField],\n\t\t\t\t},\n\t\t\t\t{ label: labelForKey(keys.tabActions), fields: [actionsField] },\n\t\t\t\t{ label: labelForKey(keys.tabResponse), fields: [responseField] },\n\t\t\t],\n\t\t},\n\t]\n\n\t// When `consent.sources` is set, resolve the visitor-facing consent statements onto every read of\n\t// a form doc (REST, local API, relationship population), so a client/modal fetch renders consent,\n\t// not only the RSC path that calls `resolveConsentStatements` itself. Fails open: a resolver outage\n\t// must never break form/admin/relationship reads, and the renderer already tolerates a missing\n\t// statement. `resolveConsentStatements` returns `{}` without calling the resolver when the form has\n\t// no consent fields, and entries are cached per request+form, so the cost stays bounded.\n\tconst consentAfterRead: CollectionAfterReadHook | undefined =\n\t\tconsentSources && consentResolveOnRead !== false\n\t\t\t? async ({ doc, req }) => {\n\t\t\t\t\tconst id = (doc as { id?: unknown }).id\n\t\t\t\t\tconst key = id == null ? undefined : String(id)\n\t\t\t\t\t// Re-entrance guard: a host resolver that reads this same form back (threading req) would\n\t\t\t\t\t// otherwise re-enter this hook and recurse. Payload runs collection afterRead concurrently\n\t\t\t\t\t// across list docs on one shared req.context, so this must be a per-id Set (a boolean would\n\t\t\t\t\t// make sibling docs skip), mutated in place and never reassigned after fan-out. Mirrors\n\t\t\t\t\t// @payloadcms/plugin-search's syncDocAsSearchIndex guard.\n\t\t\t\t\tif (key !== undefined && req.context) {\n\t\t\t\t\t\tconst inFlight =\n\t\t\t\t\t\t\t(req.context[CONSENT_AFTER_READ_GUARD] as Set<string> | undefined) ??\n\t\t\t\t\t\t\tnew Set<string>()\n\t\t\t\t\t\tif (inFlight.has(key)) {\n\t\t\t\t\t\t\treturn doc\n\t\t\t\t\t\t}\n\t\t\t\t\t\tinFlight.add(key)\n\t\t\t\t\t\treq.context[CONSENT_AFTER_READ_GUARD] = inFlight\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst statements = await resolveConsentStatements({\n\t\t\t\t\t\t\tpayload: req.payload,\n\t\t\t\t\t\t\treq,\n\t\t\t\t\t\t\tform: doc,\n\t\t\t\t\t\t\tsources: consentSources,\n\t\t\t\t\t\t})\n\t\t\t\t\t\tif (Object.keys(statements).length > 0) {\n\t\t\t\t\t\t\t;(doc as Record<string, unknown>).consentStatements = statements\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\treq.payload.logger?.warn(`form-builder consent afterRead: ${String(error)}`)\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tif (key !== undefined && req.context) {\n\t\t\t\t\t\t\t;(req.context[CONSENT_AFTER_READ_GUARD] as Set<string> | undefined)?.delete(key)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn doc\n\t\t\t\t}\n\t\t\t: undefined\n\n\t// When calc sources are registered, resolve the values a form's expressions reference onto every\n\t// read of its doc, stamped as `doc.calcResolved` (`toFormDocument` passes it through), so the\n\t// client's live preview computes with real values. Fails open: a resolver outage must never break\n\t// form/admin/relationship reads; the preview degrades to 0 and submit re-resolves loudly.\n\tconst calcAfterRead: CollectionAfterReadHook | undefined =\n\t\tcalcSources && Object.keys(calcSources).length > 0\n\t\t\t? async ({ doc, req }) => {\n\t\t\t\t\tconst fields = Array.isArray((doc as { fields?: unknown }).fields)\n\t\t\t\t\t\t? ((doc as { fields: unknown[] }).fields as FormFieldInstance[])\n\t\t\t\t\t\t: []\n\t\t\t\t\tif (!calcUsesSources(fields)) {\n\t\t\t\t\t\treturn doc\n\t\t\t\t\t}\n\t\t\t\t\tconst id = (doc as { id?: unknown }).id\n\t\t\t\t\tconst key = id == null ? undefined : String(id)\n\t\t\t\t\t// Re-entrance guard: a host resolver that reads this same form back (threading req) would\n\t\t\t\t\t// otherwise re-enter this hook and recurse. Per-id Set, mutated in place, exactly like\n\t\t\t\t\t// `consentAfterRead` above (afterRead fans out concurrently over one shared req.context).\n\t\t\t\t\tif (key !== undefined && req.context) {\n\t\t\t\t\t\tconst inFlight =\n\t\t\t\t\t\t\t(req.context[CALC_AFTER_READ_GUARD] as Set<string> | undefined) ?? new Set<string>()\n\t\t\t\t\t\tif (inFlight.has(key)) {\n\t\t\t\t\t\t\treturn doc\n\t\t\t\t\t\t}\n\t\t\t\t\t\tinFlight.add(key)\n\t\t\t\t\t\treq.context[CALC_AFTER_READ_GUARD] = inFlight\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst resolved = await resolveCalcContext({\n\t\t\t\t\t\t\tfields,\n\t\t\t\t\t\t\tsources: calcSources,\n\t\t\t\t\t\t\tform: doc as { id: number | string } & Record<string, unknown>,\n\t\t\t\t\t\t\tpayload: req.payload,\n\t\t\t\t\t\t\treq,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t;(doc as Record<string, unknown>).calcResolved = resolved\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\treq.payload.logger?.warn(`form-builder calc afterRead: ${String(error)}`)\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tif (key !== undefined && req.context) {\n\t\t\t\t\t\t\t;(req.context[CALC_AFTER_READ_GUARD] as Set<string> | undefined)?.delete(key)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn doc\n\t\t\t\t}\n\t\t\t: undefined\n\n\tconst defaultEndpoints = buildFormsEndpoints({\n\t\tresultsAccess,\n\t\tpollResultsTypes,\n\t\tpollVotesEnabled,\n\t\tconsentSources,\n\t\tfromAddresses,\n\t\tfromSources,\n\t\tdepartments,\n\t})\n\n\treturn {\n\t\t...(overrides ?? {}),\n\t\tslug: FORMS_SLUG,\n\t\tlabels: {\n\t\t\tsingular: labelForKey(keys.collectionFormSingular),\n\t\t\tplural: labelForKey(keys.collectionFormPlural),\n\t\t\t...(overrides?.labels ?? {}),\n\t\t},\n\t\tadmin: {\n\t\t\tgroup: 'Forms',\n\t\t\tuseAsTitle: 'title',\n\t\t\tdefaultColumns: ['title', 'fields', 'flow', 'pollEnabled', 'updatedAt'],\n\t\t\t...(overrides?.admin ?? {}),\n\t\t},\n\t\taccess: { read: () => true, ...(overrides?.access ?? {}) },\n\t\thooks: {\n\t\t\t...(overrides?.hooks ?? {}),\n\t\t\t// beforeValidate normalizes conditions and flow; consumer hooks run after\n\t\t\tbeforeValidate: [beforeValidate, ...(overrides?.hooks?.beforeValidate ?? [])],\n\t\t\tbeforeChange: [pollOutcomeBeforeChange, ...(overrides?.hooks?.beforeChange ?? [])],\n\t\t\tafterChange: [pollCloseAfterChange, ...(overrides?.hooks?.afterChange ?? [])],\n\t\t\tafterRead: [\n\t\t\t\t...(consentAfterRead ? [consentAfterRead] : []),\n\t\t\t\t...(calcAfterRead ? [calcAfterRead] : []),\n\t\t\t\t...(overrides?.hooks?.afterRead ?? []),\n\t\t\t],\n\t\t},\n\t\tendpoints: [\n\t\t\t...defaultEndpoints,\n\t\t\t...(Array.isArray(overrides?.endpoints) ? overrides.endpoints : []),\n\t\t],\n\t\tfields: overrides?.fields ? overrides.fields({ defaultFields }) : defaultFields,\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,MAAa,aAAa;;AAG1B,MAAM,2BAA2B;;AAGjC,MAAM,wBAAwB;;;;;;;AAQ9B,MAAM,qBAAgD,OAAO,EAAE,UAAU;CAC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,KAAA;CAEJ,MAAM,mBAAmB,oBAAoB;EAC5C;EACA;EACA;EACA;EACA;EACA;EACA;CACD,CAAC;CAED,OAAO;EACN,GAAI,aAAa,CAAC;EAClB,MAAM;EACN,QAAQ;GACP,UAAU,YAAY,KAAK,sBAAsB;GACjD,QAAQ,YAAY,KAAK,oBAAoB;GAC7C,GAAI,WAAW,UAAU,CAAC;EAC3B;EACA,OAAO;GACN,OAAO;GACP,YAAY;GACZ,gBAAgB;IAAC;IAAS;IAAU;IAAQ;IAAe;GAAW;GACtE,GAAI,WAAW,SAAS,CAAC;EAC1B;EACA,QAAQ;GAAE,YAAY;GAAM,GAAI,WAAW,UAAU,CAAC;EAAG;EACzD,OAAO;GACN,GAAI,WAAW,SAAS,CAAC;GAEzB,gBAAgB,CAAC,gBAAgB,GAAI,WAAW,OAAO,kBAAkB,CAAC,CAAE;GAC5E,cAAc,CAAC,yBAAyB,GAAI,WAAW,OAAO,gBAAgB,CAAC,CAAE;GACjF,aAAa,CAAC,sBAAsB,GAAI,WAAW,OAAO,eAAe,CAAC,CAAE;GAC5E,WAAW;IACV,GAAI,mBAAmB,CAAC,gBAAgB,IAAI,CAAC;IAC7C,GAAI,gBAAgB,CAAC,aAAa,IAAI,CAAC;IACvC,GAAI,WAAW,OAAO,aAAa,CAAC;GACrC;EACD;EACA,WAAW,CACV,GAAG,kBACH,GAAI,MAAM,QAAQ,WAAW,SAAS,IAAI,UAAU,YAAY,CAAC,CAClE;EACA,QAAQ,WAAW,SAAS,UAAU,OAAO,EAAE,cAAc,CAAC,IAAI;CACnE;AACD"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { resolveFromAddressesRequest } from "../actions/fromAddresses.js";
|
|
2
|
+
import { resolveFormResultsRequest } from "../aggregation/resolveResultsRequest.js";
|
|
3
|
+
import { resolveConsentSourcesRequest } from "../consent/resolveConsentSourcesRequest.js";
|
|
4
|
+
import { resolveDepartmentsRequest } from "../email/departments.js";
|
|
5
|
+
import { resolvePollCloseRequest } from "../poll/resolvePollCloseRequest.js";
|
|
6
|
+
import { resolvePollOptionsRequest } from "../poll/resolvePollOptionsRequest.js";
|
|
7
|
+
//#region src/collections/formsEndpoints.ts
|
|
8
|
+
/**
|
|
9
|
+
* The forms collection's built-in endpoints: poll results/options/close, plus the optional
|
|
10
|
+
* consent-sources, from-addresses, and departments option endpoints that only exist when the
|
|
11
|
+
* matching plugin option is set. Each delegates to its request helper, which owns the auth check
|
|
12
|
+
* (anonymous callers get a 403 from the helper, not here). Extracted from `buildFormsCollection`
|
|
13
|
+
* so the collection builder stays focused on field and hook composition.
|
|
14
|
+
*/
|
|
15
|
+
/** A request-scoped GET route at its id-less path plus the legacy doc-scoped path, one handler. */
|
|
16
|
+
const requestScopedRoutes = (name, handler) => [{
|
|
17
|
+
path: `/${name}`,
|
|
18
|
+
method: "get",
|
|
19
|
+
handler
|
|
20
|
+
}, {
|
|
21
|
+
path: `/:id/${name}`,
|
|
22
|
+
method: "get",
|
|
23
|
+
handler
|
|
24
|
+
}];
|
|
25
|
+
const buildFormsEndpoints = ({ resultsAccess, pollResultsTypes, pollVotesEnabled, consentSources, fromAddresses, fromSources, departments }) => [
|
|
26
|
+
{
|
|
27
|
+
path: "/:id/results",
|
|
28
|
+
method: "get",
|
|
29
|
+
handler: async (req) => {
|
|
30
|
+
const field = typeof req.query?.field === "string" ? req.query.field : void 0;
|
|
31
|
+
const { status, body } = await resolveFormResultsRequest({
|
|
32
|
+
payload: req.payload,
|
|
33
|
+
formId: req.routeParams?.id,
|
|
34
|
+
field,
|
|
35
|
+
isAuthed: Boolean(req.user),
|
|
36
|
+
req,
|
|
37
|
+
access: resultsAccess,
|
|
38
|
+
eligibleTypes: pollResultsTypes,
|
|
39
|
+
pollVotesEnabled
|
|
40
|
+
});
|
|
41
|
+
return Response.json(body, { status });
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
path: "/:id/poll-options",
|
|
46
|
+
method: "get",
|
|
47
|
+
handler: async (req) => {
|
|
48
|
+
const { status, body } = await resolvePollOptionsRequest({
|
|
49
|
+
payload: req.payload,
|
|
50
|
+
formId: req.routeParams?.id,
|
|
51
|
+
isAuthed: Boolean(req.user),
|
|
52
|
+
req
|
|
53
|
+
});
|
|
54
|
+
return Response.json(body, { status });
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
path: "/:id/close",
|
|
59
|
+
method: "post",
|
|
60
|
+
handler: async (req) => {
|
|
61
|
+
const { status, body } = await resolvePollCloseRequest({
|
|
62
|
+
payload: req.payload,
|
|
63
|
+
formId: req.routeParams?.id,
|
|
64
|
+
isAuthed: Boolean(req.user),
|
|
65
|
+
pollVotesEnabled,
|
|
66
|
+
req
|
|
67
|
+
});
|
|
68
|
+
return Response.json(body, { status });
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
...consentSources ? [{
|
|
72
|
+
path: "/:id/consent-sources",
|
|
73
|
+
method: "get",
|
|
74
|
+
handler: async (req) => {
|
|
75
|
+
const { status, body } = await resolveConsentSourcesRequest({
|
|
76
|
+
payload: req.payload,
|
|
77
|
+
formId: req.routeParams?.id,
|
|
78
|
+
isAuthed: Boolean(req.user),
|
|
79
|
+
req,
|
|
80
|
+
resolver: consentSources
|
|
81
|
+
});
|
|
82
|
+
return Response.json(body, { status });
|
|
83
|
+
}
|
|
84
|
+
}] : [],
|
|
85
|
+
...fromAddresses || fromSources ? requestScopedRoutes("from-addresses", async (req) => {
|
|
86
|
+
const { status, body } = await resolveFromAddressesRequest({
|
|
87
|
+
isAuthed: Boolean(req.user),
|
|
88
|
+
req,
|
|
89
|
+
resolver: fromAddresses,
|
|
90
|
+
sources: fromSources
|
|
91
|
+
});
|
|
92
|
+
return Response.json(body, { status });
|
|
93
|
+
}) : [],
|
|
94
|
+
...departments ? requestScopedRoutes("departments", async (req) => {
|
|
95
|
+
const { status, body } = await resolveDepartmentsRequest({
|
|
96
|
+
isAuthed: Boolean(req.user),
|
|
97
|
+
req,
|
|
98
|
+
resolver: departments
|
|
99
|
+
});
|
|
100
|
+
return Response.json(body, { status });
|
|
101
|
+
}) : []
|
|
102
|
+
];
|
|
103
|
+
//#endregion
|
|
104
|
+
export { buildFormsEndpoints };
|
|
105
|
+
|
|
106
|
+
//# sourceMappingURL=formsEndpoints.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formsEndpoints.js","names":[],"sources":["../../src/collections/formsEndpoints.ts"],"sourcesContent":["import type { CollectionConfig, PayloadRequest } from 'payload'\nimport {\n\ttype FromAddressesResolver,\n\ttype FromAddressSourceRegistry,\n\tresolveFromAddressesRequest,\n} from '../actions/fromAddresses'\nimport {\n\ttype FormResultsAccess,\n\tresolveFormResultsRequest,\n} from '../aggregation/resolveResultsRequest'\nimport { resolveConsentSourcesRequest } from '../consent/resolveConsentSourcesRequest'\nimport type { ConsentSourcesResolver } from '../consent/types'\nimport { type DepartmentEmailsResolver, resolveDepartmentsRequest } from '../email/departments'\nimport { resolvePollCloseRequest } from '../poll/resolvePollCloseRequest'\nimport { resolvePollOptionsRequest } from '../poll/resolvePollOptionsRequest'\n\ntype FormsEndpointDeps = {\n\t/** Host seam gating anonymous results reads (plugin option `results.access`). */\n\tresultsAccess?: FormResultsAccess\n\t/** The poll-eligible field-type names; the `/:id/results` endpoint restricts reads to these. */\n\tpollResultsTypes: string[]\n\t/** Whether the hidden tally store backs poll reads and the close endpoint's outcome aggregation. */\n\tpollVotesEnabled: boolean\n\t/** The plugin `consent.sources` option; present registers the `/:id/consent-sources` endpoint. */\n\tconsentSources?: ConsentSourcesResolver\n\t/** The plugin `email.fromAddresses` option; this or `fromSources` present registers the `/:id/from-addresses` endpoint. */\n\tfromAddresses?: FromAddressesResolver\n\t/** The plugin `email.fromSources` option; served ahead of the resolver's literals. */\n\tfromSources?: FromAddressSourceRegistry\n\t/** The plugin `email.departments` option; present registers the `/:id/departments` endpoint. */\n\tdepartments?: DepartmentEmailsResolver\n}\n\n/**\n * The forms collection's built-in endpoints: poll results/options/close, plus the optional\n * consent-sources, from-addresses, and departments option endpoints that only exist when the\n * matching plugin option is set. Each delegates to its request helper, which owns the auth check\n * (anonymous callers get a 403 from the helper, not here). Extracted from `buildFormsCollection`\n * so the collection builder stays focused on field and hook composition.\n */\n/** A request-scoped GET route at its id-less path plus the legacy doc-scoped path, one handler. */\nconst requestScopedRoutes = (\n\tname: string,\n\thandler: (req: PayloadRequest) => Promise<Response>\n): Exclude<CollectionConfig['endpoints'], false | undefined> => [\n\t{ path: `/${name}`, method: 'get', handler },\n\t{ path: `/:id/${name}`, method: 'get', handler },\n]\n\nexport const buildFormsEndpoints = ({\n\tresultsAccess,\n\tpollResultsTypes,\n\tpollVotesEnabled,\n\tconsentSources,\n\tfromAddresses,\n\tfromSources,\n\tdepartments,\n}: FormsEndpointDeps): Exclude<CollectionConfig['endpoints'], false | undefined> => [\n\t{\n\t\tpath: '/:id/results',\n\t\tmethod: 'get',\n\t\thandler: async (req: PayloadRequest) => {\n\t\t\tconst field = typeof req.query?.field === 'string' ? req.query.field : undefined\n\t\t\tconst { status, body } = await resolveFormResultsRequest({\n\t\t\t\tpayload: req.payload,\n\t\t\t\tformId: req.routeParams?.id as number | string | undefined,\n\t\t\t\tfield,\n\t\t\t\tisAuthed: Boolean(req.user),\n\t\t\t\treq,\n\t\t\t\taccess: resultsAccess,\n\t\t\t\teligibleTypes: pollResultsTypes,\n\t\t\t\tpollVotesEnabled,\n\t\t\t})\n\t\t\treturn Response.json(body, { status })\n\t\t},\n\t},\n\t{\n\t\tpath: '/:id/poll-options',\n\t\tmethod: 'get',\n\t\thandler: async (req: PayloadRequest) => {\n\t\t\tconst { status, body } = await resolvePollOptionsRequest({\n\t\t\t\tpayload: req.payload,\n\t\t\t\tformId: req.routeParams?.id as number | string | undefined,\n\t\t\t\tisAuthed: Boolean(req.user),\n\t\t\t\treq,\n\t\t\t})\n\t\t\treturn Response.json(body, { status })\n\t\t},\n\t},\n\t// Trusted admin action (authenticated only): close a poll now and resolve its outcome. A POST\n\t// because it mutates; auth is `Boolean(req.user)` so an anonymous caller gets 403 from the helper.\n\t{\n\t\tpath: '/:id/close',\n\t\tmethod: 'post',\n\t\thandler: async (req: PayloadRequest) => {\n\t\t\tconst { status, body } = await resolvePollCloseRequest({\n\t\t\t\tpayload: req.payload,\n\t\t\t\tformId: req.routeParams?.id as number | string | undefined,\n\t\t\t\tisAuthed: Boolean(req.user),\n\t\t\t\tpollVotesEnabled,\n\t\t\t\treq,\n\t\t\t})\n\t\t\treturn Response.json(body, { status })\n\t\t},\n\t},\n\t...(consentSources\n\t\t? [\n\t\t\t\t{\n\t\t\t\t\tpath: '/:id/consent-sources',\n\t\t\t\t\tmethod: 'get' as const,\n\t\t\t\t\thandler: async (req: PayloadRequest) => {\n\t\t\t\t\t\tconst { status, body } = await resolveConsentSourcesRequest({\n\t\t\t\t\t\t\tpayload: req.payload,\n\t\t\t\t\t\t\tformId: req.routeParams?.id as number | string | undefined,\n\t\t\t\t\t\t\tisAuthed: Boolean(req.user),\n\t\t\t\t\t\t\treq,\n\t\t\t\t\t\t\tresolver: consentSources,\n\t\t\t\t\t\t})\n\t\t\t\t\t\treturn Response.json(body, { status })\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t]\n\t\t: []),\n\t// The from-addresses and departments sets are request-scoped (e.g. per tenant), never per-form.\n\t// Each lives at the id-less path the selects call (which is what lets their options load while\n\t// a form is still being created), with the legacy `/:id/` route kept on the same handler for\n\t// integrators that hardcoded it.\n\t...(fromAddresses || fromSources\n\t\t? requestScopedRoutes('from-addresses', async (req: PayloadRequest) => {\n\t\t\t\tconst { status, body } = await resolveFromAddressesRequest({\n\t\t\t\t\tisAuthed: Boolean(req.user),\n\t\t\t\t\treq,\n\t\t\t\t\tresolver: fromAddresses,\n\t\t\t\t\tsources: fromSources,\n\t\t\t\t})\n\t\t\t\treturn Response.json(body, { status })\n\t\t\t})\n\t\t: []),\n\t...(departments\n\t\t? requestScopedRoutes('departments', async (req: PayloadRequest) => {\n\t\t\t\tconst { status, body } = await resolveDepartmentsRequest({\n\t\t\t\t\tisAuthed: Boolean(req.user),\n\t\t\t\t\treq,\n\t\t\t\t\tresolver: departments,\n\t\t\t\t})\n\t\t\t\treturn Response.json(body, { status })\n\t\t\t})\n\t\t: []),\n]\n"],"mappings":";;;;;;;;;;;;;;;AAyCA,MAAM,uBACL,MACA,YAC+D,CAC/D;CAAE,MAAM,IAAI;CAAQ,QAAQ;CAAO;AAAQ,GAC3C;CAAE,MAAM,QAAQ;CAAQ,QAAQ;CAAO;AAAQ,CAChD;AAEA,MAAa,uBAAuB,EACnC,eACA,kBACA,kBACA,gBACA,eACA,aACA,kBACmF;CACnF;EACC,MAAM;EACN,QAAQ;EACR,SAAS,OAAO,QAAwB;GACvC,MAAM,QAAQ,OAAO,IAAI,OAAO,UAAU,WAAW,IAAI,MAAM,QAAQ,KAAA;GACvE,MAAM,EAAE,QAAQ,SAAS,MAAM,0BAA0B;IACxD,SAAS,IAAI;IACb,QAAQ,IAAI,aAAa;IACzB;IACA,UAAU,QAAQ,IAAI,IAAI;IAC1B;IACA,QAAQ;IACR,eAAe;IACf;GACD,CAAC;GACD,OAAO,SAAS,KAAK,MAAM,EAAE,OAAO,CAAC;EACtC;CACD;CACA;EACC,MAAM;EACN,QAAQ;EACR,SAAS,OAAO,QAAwB;GACvC,MAAM,EAAE,QAAQ,SAAS,MAAM,0BAA0B;IACxD,SAAS,IAAI;IACb,QAAQ,IAAI,aAAa;IACzB,UAAU,QAAQ,IAAI,IAAI;IAC1B;GACD,CAAC;GACD,OAAO,SAAS,KAAK,MAAM,EAAE,OAAO,CAAC;EACtC;CACD;CAGA;EACC,MAAM;EACN,QAAQ;EACR,SAAS,OAAO,QAAwB;GACvC,MAAM,EAAE,QAAQ,SAAS,MAAM,wBAAwB;IACtD,SAAS,IAAI;IACb,QAAQ,IAAI,aAAa;IACzB,UAAU,QAAQ,IAAI,IAAI;IAC1B;IACA;GACD,CAAC;GACD,OAAO,SAAS,KAAK,MAAM,EAAE,OAAO,CAAC;EACtC;CACD;CACA,GAAI,iBACD,CACA;EACC,MAAM;EACN,QAAQ;EACR,SAAS,OAAO,QAAwB;GACvC,MAAM,EAAE,QAAQ,SAAS,MAAM,6BAA6B;IAC3D,SAAS,IAAI;IACb,QAAQ,IAAI,aAAa;IACzB,UAAU,QAAQ,IAAI,IAAI;IAC1B;IACA,UAAU;GACX,CAAC;GACD,OAAO,SAAS,KAAK,MAAM,EAAE,OAAO,CAAC;EACtC;CACD,CACD,IACC,CAAC;CAKJ,GAAI,iBAAiB,cAClB,oBAAoB,kBAAkB,OAAO,QAAwB;EACrE,MAAM,EAAE,QAAQ,SAAS,MAAM,4BAA4B;GAC1D,UAAU,QAAQ,IAAI,IAAI;GAC1B;GACA,UAAU;GACV,SAAS;EACV,CAAC;EACD,OAAO,SAAS,KAAK,MAAM,EAAE,OAAO,CAAC;CACtC,CAAC,IACA,CAAC;CACJ,GAAI,cACD,oBAAoB,eAAe,OAAO,QAAwB;EAClE,MAAM,EAAE,QAAQ,SAAS,MAAM,0BAA0B;GACxD,UAAU,QAAQ,IAAI,IAAI;GAC1B;GACA,UAAU;EACX,CAAC;EACD,OAAO,SAAS,KAAK,MAAM,EAAE,OAAO,CAAC;CACtC,CAAC,IACA,CAAC;AACL"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Field } from "payload";
|
|
2
|
+
|
|
3
|
+
//#region src/collections/redirectFields.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Composes the fields inside the forms `response.redirect` group. Receives the default fields (the
|
|
6
|
+
* `url` text field, plus the polymorphic `reference` relationship when `redirectRelationships` is
|
|
7
|
+
* set) and returns the group's final field array verbatim, so a host can prepend a custom link
|
|
8
|
+
* field, swap `url` for their own picker, reorder, or filter. Mirrors `buttons.fields` and
|
|
9
|
+
* `poll.outcomeFields`.
|
|
10
|
+
*
|
|
11
|
+
* The plugin's built-in redirect handling reads `redirect.url` (and `redirect.reference` when
|
|
12
|
+
* configured); `toFormDocument` passes the whole `response` group through, so a host that replaces
|
|
13
|
+
* `url` with their own link field owns resolving it to a destination in their frontend, the same as
|
|
14
|
+
* the internal-reference case.
|
|
15
|
+
*/
|
|
16
|
+
type RedirectFieldsOverride = (args: {
|
|
17
|
+
defaultFields: Field[];
|
|
18
|
+
}) => Field[];
|
|
19
|
+
/** The forms `response.redirect` group options: its fields composition seam. */
|
|
20
|
+
type RedirectOption = {
|
|
21
|
+
fields?: RedirectFieldsOverride;
|
|
22
|
+
};
|
|
23
|
+
/** The plugin `response` option: currently the `redirect` group's composition seam. */
|
|
24
|
+
type ResponseOption = {
|
|
25
|
+
redirect?: RedirectOption;
|
|
26
|
+
};
|
|
27
|
+
//#endregion
|
|
28
|
+
export { RedirectFieldsOverride, RedirectOption, ResponseOption };
|
|
29
|
+
//# sourceMappingURL=redirectFields.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Field } from "payload";
|
|
2
|
+
|
|
3
|
+
//#region src/collections/settingsFields.d.ts
|
|
4
|
+
/** The default form-level flag fields, keyed by flag. What the `settings.fields` seam receives. */
|
|
5
|
+
type DefaultSettingsFields = {
|
|
6
|
+
multistep: Field;
|
|
7
|
+
pollEnabled: Field;
|
|
8
|
+
persistSubmissions: Field;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Composes the three form-level flag fields. Receives the defaults and returns the final field
|
|
12
|
+
* array placed verbatim at the forms collection root, so a host can relocate a flag (strip
|
|
13
|
+
* `admin.position`), wrap them in a row, append its own, or drop one.
|
|
14
|
+
*/
|
|
15
|
+
type SettingsFieldsOverride = (args: {
|
|
16
|
+
defaultFields: DefaultSettingsFields;
|
|
17
|
+
}) => Field[];
|
|
18
|
+
/** The plugin `settings` option: the three form-level flags and their composition seam. */
|
|
19
|
+
type SettingsOption = {
|
|
20
|
+
fields?: SettingsFieldsOverride;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* The three flags: behavior, never localized, sidebar checkboxes by default. `multistep` gates the
|
|
24
|
+
* Flow tab and the client's step navigation; `pollEnabled` gates the Poll tab and marks the form a
|
|
25
|
+
* poll; `persistSubmissions` (default checked) tells the plugin whether to keep a submission's row
|
|
26
|
+
* after its actions run, or prune it (a pure signup form's opt-out).
|
|
27
|
+
*/
|
|
28
|
+
declare const buildDefaultSettingsFields: () => DefaultSettingsFields;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { DefaultSettingsFields, SettingsFieldsOverride, SettingsOption, buildDefaultSettingsFields };
|
|
31
|
+
//# sourceMappingURL=settingsFields.d.ts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { keys } from "../translations/keys.js";
|
|
2
|
+
import { labelForKey } from "../translations/server.js";
|
|
3
|
+
//#region src/collections/settingsFields.ts
|
|
4
|
+
/**
|
|
5
|
+
* The three flags: behavior, never localized, sidebar checkboxes by default. `multistep` gates the
|
|
6
|
+
* Flow tab and the client's step navigation; `pollEnabled` gates the Poll tab and marks the form a
|
|
7
|
+
* poll; `persistSubmissions` (default checked) tells the plugin whether to keep a submission's row
|
|
8
|
+
* after its actions run, or prune it (a pure signup form's opt-out).
|
|
9
|
+
*/
|
|
10
|
+
const buildDefaultSettingsFields = () => ({
|
|
11
|
+
multistep: {
|
|
12
|
+
name: "multistep",
|
|
13
|
+
type: "checkbox",
|
|
14
|
+
defaultValue: false,
|
|
15
|
+
label: labelForKey(keys.formMultistep),
|
|
16
|
+
admin: { position: "sidebar" }
|
|
17
|
+
},
|
|
18
|
+
pollEnabled: {
|
|
19
|
+
name: "pollEnabled",
|
|
20
|
+
type: "checkbox",
|
|
21
|
+
defaultValue: false,
|
|
22
|
+
label: labelForKey(keys.formPollEnabled),
|
|
23
|
+
admin: { position: "sidebar" }
|
|
24
|
+
},
|
|
25
|
+
persistSubmissions: {
|
|
26
|
+
name: "persistSubmissions",
|
|
27
|
+
type: "checkbox",
|
|
28
|
+
defaultValue: true,
|
|
29
|
+
label: labelForKey(keys.formPersistSubmissions),
|
|
30
|
+
admin: { position: "sidebar" }
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
const composeSettingsFields = (settings) => {
|
|
34
|
+
const defaultFields = buildDefaultSettingsFields();
|
|
35
|
+
if (settings?.fields) return settings.fields({ defaultFields });
|
|
36
|
+
return [
|
|
37
|
+
defaultFields.multistep,
|
|
38
|
+
defaultFields.pollEnabled,
|
|
39
|
+
defaultFields.persistSubmissions
|
|
40
|
+
];
|
|
41
|
+
};
|
|
42
|
+
//#endregion
|
|
43
|
+
export { buildDefaultSettingsFields, composeSettingsFields };
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=settingsFields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settingsFields.js","names":[],"sources":["../../src/collections/settingsFields.ts"],"sourcesContent":["import type { Field } from 'payload'\nimport { keys } from '../translations/keys'\nimport { labelForKey } from '../translations/server'\n\n/** The default form-level flag fields, keyed by flag. What the `settings.fields` seam receives. */\nexport type DefaultSettingsFields = {\n\tmultistep: Field\n\tpollEnabled: Field\n\tpersistSubmissions: Field\n}\n\n/**\n * Composes the three form-level flag fields. Receives the defaults and returns the final field\n * array placed verbatim at the forms collection root, so a host can relocate a flag (strip\n * `admin.position`), wrap them in a row, append its own, or drop one.\n */\nexport type SettingsFieldsOverride = (args: { defaultFields: DefaultSettingsFields }) => Field[]\n\n/** The plugin `settings` option: the three form-level flags and their composition seam. */\nexport type SettingsOption = {\n\tfields?: SettingsFieldsOverride\n}\n\n/**\n * The three flags: behavior, never localized, sidebar checkboxes by default. `multistep` gates the\n * Flow tab and the client's step navigation; `pollEnabled` gates the Poll tab and marks the form a\n * poll; `persistSubmissions` (default checked) tells the plugin whether to keep a submission's row\n * after its actions run, or prune it (a pure signup form's opt-out).\n */\nexport const buildDefaultSettingsFields = (): DefaultSettingsFields => ({\n\tmultistep: {\n\t\tname: 'multistep',\n\t\ttype: 'checkbox',\n\t\tdefaultValue: false,\n\t\tlabel: labelForKey(keys.formMultistep),\n\t\tadmin: { position: 'sidebar' },\n\t},\n\tpollEnabled: {\n\t\tname: 'pollEnabled',\n\t\ttype: 'checkbox',\n\t\tdefaultValue: false,\n\t\tlabel: labelForKey(keys.formPollEnabled),\n\t\tadmin: { position: 'sidebar' },\n\t},\n\tpersistSubmissions: {\n\t\tname: 'persistSubmissions',\n\t\ttype: 'checkbox',\n\t\tdefaultValue: true,\n\t\tlabel: labelForKey(keys.formPersistSubmissions),\n\t\tadmin: { position: 'sidebar' },\n\t},\n})\n\nexport const composeSettingsFields = (settings: SettingsOption | undefined): Field[] => {\n\tconst defaultFields = buildDefaultSettingsFields()\n\tif (settings?.fields) {\n\t\treturn settings.fields({ defaultFields })\n\t}\n\treturn [defaultFields.multistep, defaultFields.pollEnabled, defaultFields.persistSubmissions]\n}\n"],"mappings":";;;;;;;;;AA6BA,MAAa,oCAA2D;CACvE,WAAW;EACV,MAAM;EACN,MAAM;EACN,cAAc;EACd,OAAO,YAAY,KAAK,aAAa;EACrC,OAAO,EAAE,UAAU,UAAU;CAC9B;CACA,aAAa;EACZ,MAAM;EACN,MAAM;EACN,cAAc;EACd,OAAO,YAAY,KAAK,eAAe;EACvC,OAAO,EAAE,UAAU,UAAU;CAC9B;CACA,oBAAoB;EACnB,MAAM;EACN,MAAM;EACN,cAAc;EACd,OAAO,YAAY,KAAK,sBAAsB;EAC9C,OAAO,EAAE,UAAU,UAAU;CAC9B;AACD;AAEA,MAAa,yBAAyB,aAAkD;CACvF,MAAM,gBAAgB,2BAA2B;CACjD,IAAI,UAAU,QACb,OAAO,SAAS,OAAO,EAAE,cAAc,CAAC;CAEzC,OAAO;EAAC,cAAc;EAAW,cAAc;EAAa,cAAc;CAAkB;AAC7F"}
|
|
@@ -2,10 +2,17 @@ import { defaultConditionType } from "./fieldTypes.js";
|
|
|
2
2
|
//#region src/conditions/conditionType.ts
|
|
3
3
|
/** The condition input a field type uses in the builder: its declared `conditionType` or the value-kind default. */
|
|
4
4
|
const conditionTypeForDefinition = (definition) => definition.conditionType ?? defaultConditionType(definition.value);
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* A serializable slug -> condition type map for every conditionable field type, handed to the client
|
|
7
|
+
* builder. Valueless ('none' kind, display-only) types are left out so they never appear as operands;
|
|
8
|
+
* consumers treat a missing entry as "not conditionable". An explicit `conditionType` opts back in.
|
|
9
|
+
*/
|
|
6
10
|
const buildConditionTypeMap = (registry) => {
|
|
7
11
|
const map = {};
|
|
8
|
-
for (const definition of registry.values())
|
|
12
|
+
for (const definition of registry.values()) {
|
|
13
|
+
if (definition.value === "none" && definition.conditionType == null) continue;
|
|
14
|
+
map[definition.type] = conditionTypeForDefinition(definition);
|
|
15
|
+
}
|
|
9
16
|
return map;
|
|
10
17
|
};
|
|
11
18
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditionType.js","names":[],"sources":["../../src/conditions/conditionType.ts"],"sourcesContent":["import type { AnyFormFieldDefinition } from '../fields/types'\nimport { type ConditionFieldType, defaultConditionType } from './fieldTypes'\n\n/** The condition input a field type uses in the builder: its declared `conditionType` or the value-kind default. */\nexport const conditionTypeForDefinition = (\n\tdefinition: Pick<AnyFormFieldDefinition, 'value' | 'conditionType'>\n): ConditionFieldType => definition.conditionType ?? defaultConditionType(definition.value)\n\n
|
|
1
|
+
{"version":3,"file":"conditionType.js","names":[],"sources":["../../src/conditions/conditionType.ts"],"sourcesContent":["import type { AnyFormFieldDefinition } from '../fields/types'\nimport { type ConditionFieldType, defaultConditionType } from './fieldTypes'\n\n/** The condition input a field type uses in the builder: its declared `conditionType` or the value-kind default. */\nexport const conditionTypeForDefinition = (\n\tdefinition: Pick<AnyFormFieldDefinition, 'value' | 'conditionType'>\n): ConditionFieldType => definition.conditionType ?? defaultConditionType(definition.value)\n\n/**\n * A serializable slug -> condition type map for every conditionable field type, handed to the client\n * builder. Valueless ('none' kind, display-only) types are left out so they never appear as operands;\n * consumers treat a missing entry as \"not conditionable\". An explicit `conditionType` opts back in.\n */\nexport const buildConditionTypeMap = (\n\tregistry: Map<string, AnyFormFieldDefinition>\n): Record<string, ConditionFieldType> => {\n\tconst map: Record<string, ConditionFieldType> = {}\n\tfor (const definition of registry.values()) {\n\t\tif (definition.value === 'none' && definition.conditionType == null) {\n\t\t\tcontinue\n\t\t}\n\t\tmap[definition.type] = conditionTypeForDefinition(definition)\n\t}\n\treturn map\n}\n"],"mappings":";;;AAIA,MAAa,8BACZ,eACwB,WAAW,iBAAiB,qBAAqB,WAAW,KAAK;;;;;;AAO1F,MAAa,yBACZ,aACwC;CACxC,MAAM,MAA0C,CAAC;CACjD,KAAK,MAAM,cAAc,SAAS,OAAO,GAAG;EAC3C,IAAI,WAAW,UAAU,UAAU,WAAW,iBAAiB,MAC9D;EAED,IAAI,WAAW,QAAQ,2BAA2B,UAAU;CAC7D;CACA,OAAO;AACR"}
|
|
@@ -47,7 +47,7 @@ const evaluateOperator = (operator, answer, value) => {
|
|
|
47
47
|
case "in": return toList(value).some((entry) => valuesEqual(answer, entry));
|
|
48
48
|
case "not_in": return isNil(answer) || !toList(value).some((entry) => valuesEqual(answer, entry));
|
|
49
49
|
case "exists": {
|
|
50
|
-
const present = !isNil(answer) && answer !== "";
|
|
50
|
+
const present = !isNil(answer) && answer !== "" && !(Array.isArray(answer) && answer.length === 0);
|
|
51
51
|
return value === true || value === "true" ? present : !present;
|
|
52
52
|
}
|
|
53
53
|
case "greater_than": return ordered(answer, value, (a, b) => a > b);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluate.js","names":[],"sources":["../../src/conditions/evaluate.ts"],"sourcesContent":["import type { Operator, Where } from 'payload'\nimport { transformWhereQuery } from 'payload/shared'\n\nconst isNil = (value: unknown): boolean => value === null || value === undefined\n\nconst toNumber = (value: unknown): number | undefined => {\n\tif (typeof value === 'number') {\n\t\treturn Number.isFinite(value) ? value : undefined\n\t}\n\tif (typeof value === 'string' && value.trim() !== '') {\n\t\tconst next = Number(value)\n\t\treturn Number.isNaN(next) ? undefined : next\n\t}\n\treturn undefined\n}\n\nconst toTime = (value: unknown): number | undefined => {\n\tif (value instanceof Date) {\n\t\treturn value.getTime()\n\t}\n\tif (typeof value === 'string' && value.trim() !== '') {\n\t\tconst time = Date.parse(value)\n\t\treturn Number.isNaN(time) ? undefined : time\n\t}\n\treturn undefined\n}\n\n/** Strict, then numeric, then string equality, mirroring Payload's coerce-by-type-then-compare. */\nconst valuesEqual = (answer: unknown, value: unknown): boolean => {\n\tif (answer === value) {\n\t\treturn true\n\t}\n\tif (isNil(answer) || isNil(value)) {\n\t\treturn false\n\t}\n\tconst a = toNumber(answer)\n\tconst b = toNumber(value)\n\tif (a !== undefined && b !== undefined) {\n\t\treturn a === b\n\t}\n\treturn String(answer) === String(value)\n}\n\nconst toList = (value: unknown): unknown[] => {\n\tif (Array.isArray(value)) {\n\t\treturn value\n\t}\n\tif (typeof value === 'string') {\n\t\treturn value.split(',').map((entry) => entry.trim())\n\t}\n\treturn [value]\n}\n\nconst ordered = (\n\tanswer: unknown,\n\tvalue: unknown,\n\tcompare: (a: number, b: number) => boolean\n): boolean => {\n\tconst a = toNumber(answer) ?? toTime(answer)\n\tconst b = toNumber(value) ?? toTime(value)\n\tif (a === undefined || b === undefined) {\n\t\treturn false\n\t}\n\treturn compare(a, b)\n}\n\n/** Case-insensitive: every space-separated word in `value` is a substring of `answer` (Payload `like`). */\nconst everyWord = (answer: unknown, value: unknown): boolean => {\n\tconst haystack = String(answer).toLowerCase()\n\treturn String(value)\n\t\t.toLowerCase()\n\t\t.split(' ')\n\t\t.filter((word) => word.length > 0)\n\t\t.every((word) => haystack.includes(word))\n}\n\nconst evaluateOperator = (operator: Operator, answer: unknown, value: unknown): boolean => {\n\tswitch (operator) {\n\t\tcase 'equals':\n\t\t\treturn isNil(value) ? isNil(answer) : valuesEqual(answer, value)\n\t\tcase 'not_equals':\n\t\t\treturn isNil(value) ? !isNil(answer) : isNil(answer) || !valuesEqual(answer, value)\n\t\tcase 'in':\n\t\t\treturn toList(value).some((entry) => valuesEqual(answer, entry))\n\t\tcase 'not_in':\n\t\t\treturn isNil(answer) || !toList(value).some((entry) => valuesEqual(answer, entry))\n\t\tcase 'exists': {\n\t\t\tconst present
|
|
1
|
+
{"version":3,"file":"evaluate.js","names":[],"sources":["../../src/conditions/evaluate.ts"],"sourcesContent":["import type { Operator, Where } from 'payload'\nimport { transformWhereQuery } from 'payload/shared'\n\nconst isNil = (value: unknown): boolean => value === null || value === undefined\n\nconst toNumber = (value: unknown): number | undefined => {\n\tif (typeof value === 'number') {\n\t\treturn Number.isFinite(value) ? value : undefined\n\t}\n\tif (typeof value === 'string' && value.trim() !== '') {\n\t\tconst next = Number(value)\n\t\treturn Number.isNaN(next) ? undefined : next\n\t}\n\treturn undefined\n}\n\nconst toTime = (value: unknown): number | undefined => {\n\tif (value instanceof Date) {\n\t\treturn value.getTime()\n\t}\n\tif (typeof value === 'string' && value.trim() !== '') {\n\t\tconst time = Date.parse(value)\n\t\treturn Number.isNaN(time) ? undefined : time\n\t}\n\treturn undefined\n}\n\n/** Strict, then numeric, then string equality, mirroring Payload's coerce-by-type-then-compare. */\nconst valuesEqual = (answer: unknown, value: unknown): boolean => {\n\tif (answer === value) {\n\t\treturn true\n\t}\n\tif (isNil(answer) || isNil(value)) {\n\t\treturn false\n\t}\n\tconst a = toNumber(answer)\n\tconst b = toNumber(value)\n\tif (a !== undefined && b !== undefined) {\n\t\treturn a === b\n\t}\n\treturn String(answer) === String(value)\n}\n\nconst toList = (value: unknown): unknown[] => {\n\tif (Array.isArray(value)) {\n\t\treturn value\n\t}\n\tif (typeof value === 'string') {\n\t\treturn value.split(',').map((entry) => entry.trim())\n\t}\n\treturn [value]\n}\n\nconst ordered = (\n\tanswer: unknown,\n\tvalue: unknown,\n\tcompare: (a: number, b: number) => boolean\n): boolean => {\n\tconst a = toNumber(answer) ?? toTime(answer)\n\tconst b = toNumber(value) ?? toTime(value)\n\tif (a === undefined || b === undefined) {\n\t\treturn false\n\t}\n\treturn compare(a, b)\n}\n\n/** Case-insensitive: every space-separated word in `value` is a substring of `answer` (Payload `like`). */\nconst everyWord = (answer: unknown, value: unknown): boolean => {\n\tconst haystack = String(answer).toLowerCase()\n\treturn String(value)\n\t\t.toLowerCase()\n\t\t.split(' ')\n\t\t.filter((word) => word.length > 0)\n\t\t.every((word) => haystack.includes(word))\n}\n\nconst evaluateOperator = (operator: Operator, answer: unknown, value: unknown): boolean => {\n\tswitch (operator) {\n\t\tcase 'equals':\n\t\t\treturn isNil(value) ? isNil(answer) : valuesEqual(answer, value)\n\t\tcase 'not_equals':\n\t\t\treturn isNil(value) ? !isNil(answer) : isNil(answer) || !valuesEqual(answer, value)\n\t\tcase 'in':\n\t\t\treturn toList(value).some((entry) => valuesEqual(answer, entry))\n\t\tcase 'not_in':\n\t\t\treturn isNil(answer) || !toList(value).some((entry) => valuesEqual(answer, entry))\n\t\tcase 'exists': {\n\t\t\t// Empty string and empty array both count as absent, so a repeater with no rows and an\n\t\t\t// unfilled text field are treated the same by a presence check.\n\t\t\tconst present =\n\t\t\t\t!isNil(answer) && answer !== '' && !(Array.isArray(answer) && answer.length === 0)\n\t\t\treturn value === true || value === 'true' ? present : !present\n\t\t}\n\t\tcase 'greater_than':\n\t\t\treturn ordered(answer, value, (a, b) => a > b)\n\t\tcase 'greater_than_equal':\n\t\t\treturn ordered(answer, value, (a, b) => a >= b)\n\t\tcase 'less_than':\n\t\t\treturn ordered(answer, value, (a, b) => a < b)\n\t\tcase 'less_than_equal':\n\t\t\treturn ordered(answer, value, (a, b) => a <= b)\n\t\tcase 'like':\n\t\t\treturn isNil(answer) ? false : everyWord(answer, value)\n\t\tcase 'not_like':\n\t\t\treturn isNil(answer) ? true : !everyWord(answer, value)\n\t\tcase 'contains':\n\t\t\treturn isNil(answer)\n\t\t\t\t? false\n\t\t\t\t: String(answer).toLowerCase().includes(String(value).toLowerCase())\n\t\tdefault:\n\t\t\treturn false\n\t}\n}\n\n/**\n * Evaluate one `Where` node: every top-level key is ANDed. `or` is a disjunction of sub-conditions\n * (an empty `or` matches), `and` is a conjunction, and any other key is a field path whose\n * `{ operator: value }` constraints are ANDed. Recurses, so nested `or`/`and` groups are supported.\n */\nconst evaluateWhere = (where: Where, answers: Record<string, unknown>): boolean =>\n\tObject.entries(where).every(([key, constraint]) => {\n\t\tif (key === 'or') {\n\t\t\tconst groups = (Array.isArray(constraint) ? constraint : []) as Where[]\n\t\t\treturn groups.length === 0 || groups.some((group) => evaluateWhere(group, answers))\n\t\t}\n\t\tif (key === 'and') {\n\t\t\tconst groups = (Array.isArray(constraint) ? constraint : []) as Where[]\n\t\t\treturn groups.every((group) => evaluateWhere(group, answers))\n\t\t}\n\t\tif (constraint == null || typeof constraint !== 'object' || Array.isArray(constraint)) {\n\t\t\treturn false\n\t\t}\n\t\treturn Object.entries(constraint as Record<string, unknown>).every(([operator, value]) =>\n\t\t\tevaluateOperator(operator as Operator, answers[key], value)\n\t\t)\n\t})\n\n/**\n * Evaluate a serializable `Where`-shaped condition against a flat map of (already coerced) form answers.\n * An absent or empty condition matches (returns true). Operator semantics mirror Payload's query\n * adapters: coerce then compare; `not_equals`/`not_in` are null-inclusive; `exists` treats `''`/absent\n * as not-existing; `like` is case-insensitive and space-splits (every word must be a substring), and\n * `not_like` is its logical negation (at least one word absent); `contains` is a single case-insensitive\n * substring; comma-delimited `in`/`not_in` string values are split and trimmed. Geo (`near`/`within`/\n * `intersects`) and `all` are out of scope and evaluate to false. Isomorphic: no `req`/DB access, so the\n * renderer reuses it client-side.\n */\nexport const evaluateCondition = (\n\twhere: Where | null | undefined,\n\tanswers: Record<string, unknown>\n): boolean => {\n\tif (!where || Object.keys(where).length === 0) {\n\t\treturn true\n\t}\n\treturn evaluateWhere(transformWhereQuery(where), answers)\n}\n"],"mappings":";;AAGA,MAAM,SAAS,UAA4B,UAAU,QAAQ,UAAU,KAAA;AAEvE,MAAM,YAAY,UAAuC;CACxD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O,KAAK,EAAE,YAAY,CAAC;EACrE,SACC,OAAO;CACT;AACD;;;;;;AAOA,MAAM,iBAAiB,OAAc,YACpC,OAAO,QAAQ,KAAK,EAAE,OAAO,CAAC,KAAK,gBAAgB;CAClD,IAAI,QAAQ,MAAM;EACjB,MAAM,SAAU,MAAM,QAAQ,UAAU,IAAI,aAAa,CAAC;EAC1D,OAAO,OAAO,WAAW,KAAK,OAAO,MAAM,UAAU,cAAc,OAAO,OAAO,CAAC;CACnF;CACA,IAAI,QAAQ,OAEX,QADgB,MAAM,QAAQ,UAAU,IAAI,aAAa,CAAC,GAC5C,OAAO,UAAU,cAAc,OAAO,OAAO,CAAC;CAE7D,IAAI,cAAc,QAAQ,OAAO,eAAe,YAAY,MAAM,QAAQ,UAAU,GACnF,OAAO;CAER,OAAO,OAAO,QAAQ,UAAqC,EAAE,OAAO,CAAC,UAAU,WAC9E,iBAAiB,UAAsB,QAAQ,MAAM,KAAK,CAC3D;AACD,CAAC;;;;;;;;;;;AAYF,MAAa,qBACZ,OACA,YACa;CACb,IAAI,CAAC,SAAS,OAAO,KAAK,KAAK,EAAE,WAAW,GAC3C,OAAO;CAER,OAAO,cAAc,oBAAoB,KAAK,GAAG,OAAO;AACzD"}
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* The condition input families the builder supports. A deliberate subset of Payload's field-condition
|
|
4
4
|
* types, restricted to the operators `evaluateCondition` implements (no geo/relationship in v1).
|
|
5
|
+
* `presence` is for values that only support an existence check (a file upload, a repeater), never a
|
|
6
|
+
* scalar comparison.
|
|
5
7
|
*/
|
|
6
|
-
type ConditionFieldType = 'text' | 'number' | 'select' | 'checkbox' | 'date';
|
|
8
|
+
type ConditionFieldType = 'text' | 'number' | 'select' | 'checkbox' | 'date' | 'presence';
|
|
7
9
|
//#endregion
|
|
8
10
|
export { ConditionFieldType };
|
|
9
11
|
//# sourceMappingURL=fieldTypes.d.ts.map
|
|
@@ -37,7 +37,8 @@ const conditionOperators = {
|
|
|
37
37
|
...EQUALITY,
|
|
38
38
|
...ORDER,
|
|
39
39
|
...EXISTS
|
|
40
|
-
]
|
|
40
|
+
],
|
|
41
|
+
presence: [...EXISTS]
|
|
41
42
|
};
|
|
42
43
|
/** Default condition input for a stored value kind; a field type may override via its `conditionType`. */
|
|
43
44
|
const defaultConditionType = (value) => {
|
|
@@ -46,6 +47,8 @@ const defaultConditionType = (value) => {
|
|
|
46
47
|
case "boolean": return "checkbox";
|
|
47
48
|
case "date": return "date";
|
|
48
49
|
case "text[]": return "select";
|
|
50
|
+
case "file":
|
|
51
|
+
case "repeater": return "presence";
|
|
49
52
|
default: return "text";
|
|
50
53
|
}
|
|
51
54
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fieldTypes.js","names":[],"sources":["../../src/conditions/fieldTypes.ts"],"sourcesContent":["import type { Operator } from 'payload'\nimport type { FormFieldValueKind } from '../fields/types'\n\n/**\n * The condition input families the builder supports. A deliberate subset of Payload's field-condition\n * types, restricted to the operators `evaluateCondition` implements (no geo/relationship in v1).\n */\nexport type ConditionFieldType = 'text' | 'number' | 'select' | 'checkbox' | 'date'\n\nconst EQUALITY: Operator[] = ['equals', 'not_equals']\nconst MEMBERSHIP: Operator[] = ['in', 'not_in']\nconst ORDER: Operator[] = ['greater_than', 'greater_than_equal', 'less_than', 'less_than_equal']\nconst TEXT_MATCH: Operator[] = ['like', 'not_like', 'contains']\nconst EXISTS: Operator[] = ['exists']\n\n/** Operators offered per condition type. Each is implemented by `evaluateCondition`. */\nexport const conditionOperators: Record<ConditionFieldType, Operator[]> = {\n\ttext: [...EQUALITY, ...MEMBERSHIP, ...TEXT_MATCH, ...EXISTS],\n\tnumber: [...EQUALITY, ...MEMBERSHIP, ...ORDER, ...EXISTS],\n\tselect: [...EQUALITY, ...MEMBERSHIP, ...EXISTS],\n\tcheckbox: [...EQUALITY, ...EXISTS],\n\tdate: [...EQUALITY, ...ORDER, ...EXISTS],\n}\n\n/** Default condition input for a stored value kind; a field type may override via its `conditionType`. */\nexport const defaultConditionType = (value: FormFieldValueKind): ConditionFieldType => {\n\tswitch (value) {\n\t\tcase 'number':\n\t\t\treturn 'number'\n\t\tcase 'boolean':\n\t\t\treturn 'checkbox'\n\t\tcase 'date':\n\t\t\treturn 'date'\n\t\tcase 'text[]':\n\t\t\treturn 'select'\n\t\tdefault:\n\t\t\treturn 'text'\n\t}\n}\n\n/**\n * The Payload `operators:*` i18n keys the builder uses for operator labels. A local literal union (not\n * imported from `@payloadcms/translations`, which this package never depends on); each member is a real\n * client translation key, so a value of this type is accepted by Payload's `i18n.t`.\n */\nexport type OperatorLabelKey =\n\t| 'operators:contains'\n\t| 'operators:equals'\n\t| 'operators:exists'\n\t| 'operators:isGreaterThan'\n\t| 'operators:isGreaterThanOrEqualTo'\n\t| 'operators:isIn'\n\t| 'operators:isLessThan'\n\t| 'operators:isLessThanOrEqualTo'\n\t| 'operators:isLike'\n\t| 'operators:isNotEqualTo'\n\t| 'operators:isNotIn'\n\t| 'operators:isNotLike'\n\nconst OPERATOR_LABEL_KEYS: Partial<Record<Operator, OperatorLabelKey>> = {\n\tequals: 'operators:equals',\n\tnot_equals: 'operators:isNotEqualTo',\n\tin: 'operators:isIn',\n\tnot_in: 'operators:isNotIn',\n\texists: 'operators:exists',\n\tgreater_than: 'operators:isGreaterThan',\n\tgreater_than_equal: 'operators:isGreaterThanOrEqualTo',\n\tless_than: 'operators:isLessThan',\n\tless_than_equal: 'operators:isLessThanOrEqualTo',\n\tlike: 'operators:isLike',\n\tnot_like: 'operators:isNotLike',\n\tcontains: 'operators:contains',\n}\n\n/**\n * The i18n key for an operator's label, in Payload's own `operators:*` namespace (always present in the\n * admin), so the builder reads native, localized operator labels without duplicating them in our i18n.\n * Keys mirror Payload's `WhereBuilder/field-types.tsx` operator labels. Every operator surfaced by\n * `conditionOperators` is mapped; the `operators:equals` fallback is unreachable for the offered\n * catalogs (no geo/`all` operator is ever presented) and exists only to keep the return type total.\n */\nexport const operatorLabelKey = (operator: Operator): OperatorLabelKey =>\n\tOPERATOR_LABEL_KEYS[operator] ?? 'operators:equals'\n\n/**\n * The first (default) operator a condition type offers. Every catalog leads with `equals`, so the\n * fallback is unreachable; it exists only to keep the return non-optional under `noUncheckedIndexedAccess`.\n */\nexport const firstOperatorFor = (type: ConditionFieldType): Operator =>\n\tconditionOperators[type][0] ?? 'equals'\n\n/** The value control an operator needs: a boolean toggle (`exists`), a list (`in`/`not_in`), or a scalar. */\nexport const operatorValueShape = (operator: Operator): 'boolean' | 'array' | 'scalar' => {\n\tif (operator === 'exists') {\n\t\treturn 'boolean'\n\t}\n\tif (operator === 'in' || operator === 'not_in') {\n\t\treturn 'array'\n\t}\n\treturn 'scalar'\n}\n"],"mappings":";
|
|
1
|
+
{"version":3,"file":"fieldTypes.js","names":[],"sources":["../../src/conditions/fieldTypes.ts"],"sourcesContent":["import type { Operator } from 'payload'\nimport type { FormFieldValueKind } from '../fields/types'\n\n/**\n * The condition input families the builder supports. A deliberate subset of Payload's field-condition\n * types, restricted to the operators `evaluateCondition` implements (no geo/relationship in v1).\n * `presence` is for values that only support an existence check (a file upload, a repeater), never a\n * scalar comparison.\n */\nexport type ConditionFieldType = 'text' | 'number' | 'select' | 'checkbox' | 'date' | 'presence'\n\nconst EQUALITY: Operator[] = ['equals', 'not_equals']\nconst MEMBERSHIP: Operator[] = ['in', 'not_in']\nconst ORDER: Operator[] = ['greater_than', 'greater_than_equal', 'less_than', 'less_than_equal']\nconst TEXT_MATCH: Operator[] = ['like', 'not_like', 'contains']\nconst EXISTS: Operator[] = ['exists']\n\n/** Operators offered per condition type. Each is implemented by `evaluateCondition`. */\nexport const conditionOperators: Record<ConditionFieldType, Operator[]> = {\n\ttext: [...EQUALITY, ...MEMBERSHIP, ...TEXT_MATCH, ...EXISTS],\n\tnumber: [...EQUALITY, ...MEMBERSHIP, ...ORDER, ...EXISTS],\n\tselect: [...EQUALITY, ...MEMBERSHIP, ...EXISTS],\n\tcheckbox: [...EQUALITY, ...EXISTS],\n\tdate: [...EQUALITY, ...ORDER, ...EXISTS],\n\tpresence: [...EXISTS],\n}\n\n/** Default condition input for a stored value kind; a field type may override via its `conditionType`. */\nexport const defaultConditionType = (value: FormFieldValueKind): ConditionFieldType => {\n\tswitch (value) {\n\t\tcase 'number':\n\t\t\treturn 'number'\n\t\tcase 'boolean':\n\t\t\treturn 'checkbox'\n\t\tcase 'date':\n\t\t\treturn 'date'\n\t\tcase 'text[]':\n\t\t\treturn 'select'\n\t\tcase 'file':\n\t\tcase 'repeater':\n\t\t\t// Non-scalar values: a FileRef object or a row array cannot be compared with text/select\n\t\t\t// operators (they only stringify), so offer presence-only checks.\n\t\t\treturn 'presence'\n\t\tdefault:\n\t\t\treturn 'text'\n\t}\n}\n\n/**\n * The Payload `operators:*` i18n keys the builder uses for operator labels. A local literal union (not\n * imported from `@payloadcms/translations`, which this package never depends on); each member is a real\n * client translation key, so a value of this type is accepted by Payload's `i18n.t`.\n */\nexport type OperatorLabelKey =\n\t| 'operators:contains'\n\t| 'operators:equals'\n\t| 'operators:exists'\n\t| 'operators:isGreaterThan'\n\t| 'operators:isGreaterThanOrEqualTo'\n\t| 'operators:isIn'\n\t| 'operators:isLessThan'\n\t| 'operators:isLessThanOrEqualTo'\n\t| 'operators:isLike'\n\t| 'operators:isNotEqualTo'\n\t| 'operators:isNotIn'\n\t| 'operators:isNotLike'\n\nconst OPERATOR_LABEL_KEYS: Partial<Record<Operator, OperatorLabelKey>> = {\n\tequals: 'operators:equals',\n\tnot_equals: 'operators:isNotEqualTo',\n\tin: 'operators:isIn',\n\tnot_in: 'operators:isNotIn',\n\texists: 'operators:exists',\n\tgreater_than: 'operators:isGreaterThan',\n\tgreater_than_equal: 'operators:isGreaterThanOrEqualTo',\n\tless_than: 'operators:isLessThan',\n\tless_than_equal: 'operators:isLessThanOrEqualTo',\n\tlike: 'operators:isLike',\n\tnot_like: 'operators:isNotLike',\n\tcontains: 'operators:contains',\n}\n\n/**\n * The i18n key for an operator's label, in Payload's own `operators:*` namespace (always present in the\n * admin), so the builder reads native, localized operator labels without duplicating them in our i18n.\n * Keys mirror Payload's `WhereBuilder/field-types.tsx` operator labels. Every operator surfaced by\n * `conditionOperators` is mapped; the `operators:equals` fallback is unreachable for the offered\n * catalogs (no geo/`all` operator is ever presented) and exists only to keep the return type total.\n */\nexport const operatorLabelKey = (operator: Operator): OperatorLabelKey =>\n\tOPERATOR_LABEL_KEYS[operator] ?? 'operators:equals'\n\n/**\n * The first (default) operator a condition type offers. Every catalog leads with `equals`, so the\n * fallback is unreachable; it exists only to keep the return non-optional under `noUncheckedIndexedAccess`.\n */\nexport const firstOperatorFor = (type: ConditionFieldType): Operator =>\n\tconditionOperators[type][0] ?? 'equals'\n\n/** The value control an operator needs: a boolean toggle (`exists`), a list (`in`/`not_in`), or a scalar. */\nexport const operatorValueShape = (operator: Operator): 'boolean' | 'array' | 'scalar' => {\n\tif (operator === 'exists') {\n\t\treturn 'boolean'\n\t}\n\tif (operator === 'in' || operator === 'not_in') {\n\t\treturn 'array'\n\t}\n\treturn 'scalar'\n}\n"],"mappings":";AAWA,MAAM,WAAuB,CAAC,UAAU,YAAY;AACpD,MAAM,aAAyB,CAAC,MAAM,QAAQ;AAC9C,MAAM,QAAoB;CAAC;CAAgB;CAAsB;CAAa;AAAiB;AAC/F,MAAM,aAAyB;CAAC;CAAQ;CAAY;AAAU;AAC9D,MAAM,SAAqB,CAAC,QAAQ;;AAGpC,MAAa,qBAA6D;CACzE,MAAM;EAAC,GAAG;EAAU,GAAG;EAAY,GAAG;EAAY,GAAG;CAAM;CAC3D,QAAQ;EAAC,GAAG;EAAU,GAAG;EAAY,GAAG;EAAO,GAAG;CAAM;CACxD,QAAQ;EAAC,GAAG;EAAU,GAAG;EAAY,GAAG;CAAM;CAC9C,UAAU,CAAC,GAAG,UAAU,GAAG,MAAM;CACjC,MAAM;EAAC,GAAG;EAAU,GAAG;EAAO,GAAG;CAAM;CACvC,UAAU,CAAC,GAAG,MAAM;AACrB;;AAGA,MAAa,wBAAwB,UAAkD;CACtF,QAAQ,OAAR;EACC,KAAK,UACJ,OAAO;EACR,KAAK,WACJ,OAAO;EACR,KAAK,QACJ,OAAO;EACR,KAAK,UACJ,OAAO;EACR,KAAK;EACL,KAAK,YAGJ,OAAO;EACR,SACC,OAAO;CACT;AACD;AAqBA,MAAM,sBAAmE;CACxE,QAAQ;CACR,YAAY;CACZ,IAAI;CACJ,QAAQ;CACR,QAAQ;CACR,cAAc;CACd,oBAAoB;CACpB,WAAW;CACX,iBAAiB;CACjB,MAAM;CACN,UAAU;CACV,UAAU;AACX;;;;;;;;AASA,MAAa,oBAAoB,aAChC,oBAAoB,aAAa;;;;;AAMlC,MAAa,oBAAoB,SAChC,mBAAmB,MAAM,MAAM;;AAGhC,MAAa,sBAAsB,aAAuD;CACzF,IAAI,aAAa,UAChB,OAAO;CAER,IAAI,aAAa,QAAQ,aAAa,UACrC,OAAO;CAER,OAAO;AACR"}
|
|
@@ -12,7 +12,11 @@ const isValidConstraint = (constraint, operandTypes) => {
|
|
|
12
12
|
const operator = Object.keys(ops)[0];
|
|
13
13
|
return Boolean(operator && conditionOperators[type].includes(operator));
|
|
14
14
|
};
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Canonicalize a `Where` to OR-of-ANDs and strip constraints whose operand field is unknown or whose
|
|
17
|
+
* operator is invalid for that field's condition type. Returns undefined when nothing valid remains.
|
|
18
|
+
*/
|
|
19
|
+
const normalizeWhere = (raw, operandTypes) => {
|
|
16
20
|
if (raw == null || typeof raw !== "object" || Object.keys(raw).length === 0) return;
|
|
17
21
|
const canonical = transformWhereQuery(raw);
|
|
18
22
|
const groups = (Array.isArray(canonical.or) ? canonical.or : Array.isArray(canonical.and) ? [{ and: canonical.and }] : []).map((group) => {
|
|
@@ -25,15 +29,25 @@ const normalizeOne = (raw, operandTypes) => {
|
|
|
25
29
|
* to OR-of-ANDs and strips constraints whose operand field is missing or whose operator is invalid for
|
|
26
30
|
* that field's condition type, so stored conditions always match what `evaluateCondition` can run.
|
|
27
31
|
*/
|
|
28
|
-
|
|
32
|
+
/**
|
|
33
|
+
* The operand-name -> condition-type map for a form's fields. A field is a valid condition operand
|
|
34
|
+
* only when it has a name and its block type has a condition type (display-only types are excluded),
|
|
35
|
+
* so a constraint referencing anything else is stripped, matching the client operand list.
|
|
36
|
+
*/
|
|
37
|
+
const buildOperandTypes = (fields, conditionTypes) => {
|
|
29
38
|
const operandTypes = /* @__PURE__ */ new Map();
|
|
30
39
|
for (const row of fields) {
|
|
31
40
|
const name = typeof row.name === "string" ? row.name.trim() : "";
|
|
32
|
-
|
|
41
|
+
const conditionType = conditionTypes[row.blockType];
|
|
42
|
+
if (name.length > 0 && conditionType) operandTypes.set(name, conditionType);
|
|
33
43
|
}
|
|
44
|
+
return operandTypes;
|
|
45
|
+
};
|
|
46
|
+
const normalizeFormConditions = (fields, conditionTypes) => {
|
|
47
|
+
const operandTypes = buildOperandTypes(fields, conditionTypes);
|
|
34
48
|
return fields.map((row) => {
|
|
35
|
-
const visibleWhen =
|
|
36
|
-
const validateWhen =
|
|
49
|
+
const visibleWhen = normalizeWhere(row.visibleWhen, operandTypes);
|
|
50
|
+
const validateWhen = normalizeWhere(row.validateWhen, operandTypes);
|
|
37
51
|
return {
|
|
38
52
|
...row,
|
|
39
53
|
visibleWhen,
|
|
@@ -42,6 +56,6 @@ const normalizeFormConditions = (fields, conditionTypes) => {
|
|
|
42
56
|
});
|
|
43
57
|
};
|
|
44
58
|
//#endregion
|
|
45
|
-
export { normalizeFormConditions };
|
|
59
|
+
export { buildOperandTypes, normalizeFormConditions, normalizeWhere };
|
|
46
60
|
|
|
47
61
|
//# sourceMappingURL=normalizeConditions.js.map
|