@10x-media/form-builder 0.1.0-beta.9 → 4.0.0-alpha.2
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 +185 -0
- package/README.md +12 -4
- package/dist/actions/assertNoBlockCollision.js +18 -0
- package/dist/actions/assertNoBlockCollision.js.map +1 -0
- package/dist/actions/body/serializeBody.d.ts +16 -14
- package/dist/actions/body/serializeBody.js +5 -8
- package/dist/actions/body/serializeBody.js.map +1 -1
- package/dist/actions/builtin/confirmation.js +2 -1
- package/dist/actions/builtin/confirmation.js.map +1 -1
- package/dist/actions/builtin/emailAction.d.ts +15 -3
- package/dist/actions/builtin/emailAction.js +72 -20
- package/dist/actions/builtin/emailAction.js.map +1 -1
- package/dist/actions/builtin/emailTeam.js +11 -5
- package/dist/actions/builtin/emailTeam.js.map +1 -1
- package/dist/actions/defineAction.d.ts +37 -6
- package/dist/actions/defineAction.js +14 -1
- package/dist/actions/defineAction.js.map +1 -1
- package/dist/actions/dispatch.d.ts +12 -0
- package/dist/actions/dispatch.js +103 -30
- package/dist/actions/dispatch.js.map +1 -1
- package/dist/actions/dispatchContext.js +19 -0
- package/dist/actions/dispatchContext.js.map +1 -0
- package/dist/actions/emailRecipients.js +38 -8
- package/dist/actions/emailRecipients.js.map +1 -1
- package/dist/actions/emailRender.d.ts +27 -0
- package/dist/actions/fromAddresses.d.ts +19 -1
- package/dist/actions/fromAddresses.js +66 -9
- package/dist/actions/fromAddresses.js.map +1 -1
- package/dist/actions/recipientSources.d.ts +23 -0
- package/dist/actions/recipientSources.js +11 -0
- package/dist/actions/recipientSources.js.map +1 -0
- package/dist/actions/registry.js +3 -1
- package/dist/actions/registry.js.map +1 -1
- package/dist/actions/runActions.d.ts +2 -0
- package/dist/actions/runActions.js +13 -8
- package/dist/actions/runActions.js.map +1 -1
- package/dist/actions/sign.js.map +1 -1
- package/dist/actions/submissionContext.d.ts +34 -0
- package/dist/actions/task.js +43 -16
- package/dist/actions/task.js.map +1 -1
- package/dist/aggregation/aggregateResponses.js +3 -4
- package/dist/aggregation/aggregateResponses.js.map +1 -1
- package/dist/aggregation/resolveResultsRequest.d.ts +6 -0
- package/dist/aggregation/resolveResultsRequest.js +69 -26
- package/dist/aggregation/resolveResultsRequest.js.map +1 -1
- package/dist/calc/computeCalcFields.d.ts +5 -3
- package/dist/calc/computeCalcFields.js +4 -3
- package/dist/calc/computeCalcFields.js.map +1 -1
- package/dist/calc/evaluate.d.ts +26 -3
- package/dist/calc/evaluate.js +33 -11
- 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 +39 -17
- 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 +19 -4
- package/dist/calc/types.js +3 -2
- package/dist/calc/types.js.map +1 -1
- package/dist/client/ByteSizeField.js +11 -8
- package/dist/client/ByteSizeField.js.map +1 -1
- package/dist/client/CalcExpressionBuilder.d.ts +20 -0
- package/dist/client/CalcExpressionBuilder.js +888 -0
- package/dist/client/CalcExpressionBuilder.js.map +1 -0
- package/dist/client/ClosePollButton.js +3 -3
- package/dist/client/ClosePollButton.js.map +1 -1
- package/dist/client/CondensedArray.d.ts +2 -2
- package/dist/client/CondensedArray.js +5 -7
- package/dist/client/CondensedArray.js.map +1 -1
- package/dist/client/ConditionBuilder.js +5 -7
- package/dist/client/ConditionBuilder.js.map +1 -1
- package/dist/client/ConditionRow.js +3 -3
- package/dist/client/ConditionRow.js.map +1 -1
- package/dist/client/ConsentBlockLabel.js +2 -2
- package/dist/client/ConsentBlockLabel.js.map +1 -1
- package/dist/client/ConsentRetentionNotice.d.ts +11 -0
- package/dist/client/ConsentRetentionNotice.js +23 -0
- package/dist/client/ConsentRetentionNotice.js.map +1 -0
- package/dist/client/EndpointOptionsSelect.d.ts +17 -7
- package/dist/client/EndpointOptionsSelect.js +18 -14
- package/dist/client/EndpointOptionsSelect.js.map +1 -1
- package/dist/client/FieldBlockLabel.js +2 -2
- package/dist/client/FieldBlockLabel.js.map +1 -1
- package/dist/client/FieldNameSelect.d.ts +1 -0
- package/dist/client/FieldNameSelect.js +2 -4
- package/dist/client/FieldNameSelect.js.map +1 -1
- package/dist/client/FlowBuilder.js +31 -23
- package/dist/client/FlowBuilder.js.map +1 -1
- package/dist/client/FormConditionField.js +0 -1
- package/dist/client/FormConditionField.js.map +1 -1
- package/dist/client/RecipientsSelect.d.ts +9 -2
- package/dist/client/RecipientsSelect.js +31 -10
- package/dist/client/RecipientsSelect.js.map +1 -1
- package/dist/client/admin.css +345 -72
- package/dist/client/endpointOptions.d.ts +11 -0
- package/dist/client/endpointOptions.js +17 -8
- package/dist/client/endpointOptions.js.map +1 -1
- package/dist/collections/formSubmissions.js +145 -51
- package/dist/collections/formSubmissions.js.map +1 -1
- package/dist/collections/forms.js +170 -65
- package/dist/collections/forms.js.map +1 -1
- package/dist/collections/formsEndpoints.js +31 -26
- package/dist/collections/formsEndpoints.js.map +1 -1
- package/dist/collections/settingsFields.d.ts +32 -0
- package/dist/collections/settingsFields.js +55 -0
- package/dist/collections/settingsFields.js.map +1 -0
- package/dist/consent/captureConsent.d.ts +2 -1
- package/dist/consent/captureConsent.js +4 -1
- package/dist/consent/captureConsent.js.map +1 -1
- package/dist/consent/consentSourcesField.d.ts +7 -1
- package/dist/consent/consentSourcesField.js +15 -1
- package/dist/consent/consentSourcesField.js.map +1 -1
- package/dist/consent/effectiveStatement.js +16 -0
- package/dist/consent/effectiveStatement.js.map +1 -0
- package/dist/consent/resolveConsentSourcesRequest.js +2 -2
- package/dist/consent/resolveConsentSourcesRequest.js.map +1 -1
- package/dist/consent/resolveConsentStatements.js +3 -1
- package/dist/consent/resolveConsentStatements.js.map +1 -1
- package/dist/consent/resolvePublishedVersionRef.js +1 -0
- package/dist/consent/resolvePublishedVersionRef.js.map +1 -1
- package/dist/consent/types.d.ts +8 -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/departmentsField.d.ts +6 -1
- package/dist/email/departmentsField.js +6 -1
- package/dist/email/departmentsField.js.map +1 -1
- package/dist/exports/client.d.ts +3 -1
- package/dist/exports/client.js +3 -1
- package/dist/exports/i18n.d.ts +14 -2
- package/dist/exports/i18n.js +14 -2
- package/dist/exports/react.d.ts +23 -5
- package/dist/exports/react.js +17 -1
- package/dist/exports/rsc.d.ts +4 -1
- package/dist/exports/rsc.js +7 -4
- package/dist/exports/shared.d.ts +21 -0
- package/dist/exports/shared.js +18 -0
- package/dist/exports/types.d.ts +4 -3
- package/dist/fields/buildFieldBlocks.js +2 -1
- package/dist/fields/buildFieldBlocks.js.map +1 -1
- package/dist/fields/builtin/calculation.d.ts +17 -0
- package/dist/fields/builtin/calculation.js +70 -127
- package/dist/fields/builtin/calculation.js.map +1 -1
- package/dist/fields/builtin/checkbox.js +15 -0
- package/dist/fields/builtin/checkbox.js.map +1 -1
- package/dist/fields/builtin/consent.js +21 -1
- package/dist/fields/builtin/consent.js.map +1 -1
- package/dist/fields/builtin/email.js +7 -0
- package/dist/fields/builtin/email.js.map +1 -1
- package/dist/fields/builtin/index.d.ts +6 -2
- package/dist/fields/builtin/index.js +9 -4
- package/dist/fields/builtin/index.js.map +1 -1
- package/dist/fields/builtin/select.js +20 -1
- package/dist/fields/builtin/select.js.map +1 -1
- package/dist/fields/builtin/text.js +7 -0
- package/dist/fields/builtin/text.js.map +1 -1
- package/dist/fields/instanceOptions.js +1 -1
- package/dist/fields/instanceOptions.js.map +1 -1
- package/dist/fields/sharedConfig.js +15 -11
- package/dist/fields/sharedConfig.js.map +1 -1
- package/dist/fields/types.d.ts +8 -2
- package/dist/form/findFormAtLocale.d.ts +30 -0
- package/dist/form/findFormAtLocale.js +88 -0
- package/dist/form/findFormAtLocale.js.map +1 -0
- package/dist/form/pollState.d.ts +2 -1
- package/dist/form/pollState.js.map +1 -1
- package/dist/form/toFormDocument.d.ts +18 -6
- package/dist/form/toFormDocument.js +3 -1
- package/dist/form/toFormDocument.js.map +1 -1
- package/dist/form/types.d.ts +9 -1
- package/dist/index.d.ts +29 -7
- package/dist/index.js +74 -18
- package/dist/index.js.map +1 -1
- package/dist/options.d.ts +119 -4
- package/dist/plugin/collectionSlugs.d.ts +28 -0
- package/dist/plugin/collectionSlugs.js +65 -0
- package/dist/plugin/collectionSlugs.js.map +1 -0
- package/dist/plugin/customState.js +1 -1
- package/dist/plugin/customState.js.map +1 -1
- package/dist/plugin/registerCollections.js +38 -21
- package/dist/plugin/registerCollections.js.map +1 -1
- package/dist/poll/closeJob.d.ts +4 -3
- package/dist/poll/closeJob.js +13 -10
- package/dist/poll/closeJob.js.map +1 -1
- package/dist/poll/outcomeBeforeChange.js +2 -2
- package/dist/poll/outcomeBeforeChange.js.map +1 -1
- package/dist/poll/pollTypeRegistry.js +1 -1
- package/dist/poll/resolvePollCloseRequest.js +5 -4
- package/dist/poll/resolvePollCloseRequest.js.map +1 -1
- package/dist/poll/resolvePollOptionsRequest.js +2 -2
- package/dist/poll/resolvePollOptionsRequest.js.map +1 -1
- package/dist/poll/resolvePollOutcome.d.ts +6 -0
- package/dist/poll/resolvePollOutcome.js +20 -6
- package/dist/poll/resolvePollOutcome.js.map +1 -1
- package/dist/poll/votes/aggregateFromVotes.d.ts +27 -0
- package/dist/poll/votes/aggregateFromVotes.js +55 -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 +91 -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 +23 -0
- package/dist/poll/votes/votesCollection.js +96 -0
- package/dist/poll/votes/votesCollection.js.map +1 -0
- package/dist/react/Form.d.ts +49 -7
- package/dist/react/Form.js +48 -13
- package/dist/react/Form.js.map +1 -1
- package/dist/react/FormContext.d.ts +8 -1
- package/dist/react/FormContext.js.map +1 -1
- package/dist/react/FormResults.d.ts +4 -2
- package/dist/react/FormResults.js +21 -8
- package/dist/react/FormResults.js.map +1 -1
- package/dist/react/Poll.d.ts +25 -2
- package/dist/react/Poll.js +76 -25
- 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 +4 -1
- package/dist/react/captcha/HcaptchaCaptcha.js +2 -2
- package/dist/react/captcha/HcaptchaCaptcha.js.map +1 -1
- package/dist/react/captcha/RecaptchaCaptcha.d.ts +4 -1
- package/dist/react/captcha/RecaptchaCaptcha.js +2 -2
- package/dist/react/captcha/RecaptchaCaptcha.js.map +1 -1
- package/dist/react/captcha/TurnstileCaptcha.d.ts +4 -1
- package/dist/react/captcha/TurnstileCaptcha.js +2 -2
- package/dist/react/captcha/TurnstileCaptcha.js.map +1 -1
- package/dist/react/captcha/useCaptchaScript.js +23 -5
- package/dist/react/captcha/useCaptchaScript.js.map +1 -1
- package/dist/react/fetchResults.d.ts +6 -3
- package/dist/react/fetchResults.js +10 -5
- package/dist/react/fetchResults.js.map +1 -1
- package/dist/react/primitives/Checkbox.d.ts +4 -2
- package/dist/react/primitives/Checkbox.js +3 -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 +11 -1
- package/dist/react/primitives/FieldShell.js +43 -33
- package/dist/react/primitives/FieldShell.js.map +1 -1
- package/dist/react/primitives/Input.d.ts +3 -1
- package/dist/react/primitives/Input.js +2 -1
- package/dist/react/primitives/Input.js.map +1 -1
- package/dist/react/renderers/calculation.js +6 -1
- package/dist/react/renderers/calculation.js.map +1 -1
- package/dist/react/renderers/checkbox.js +2 -1
- package/dist/react/renderers/checkbox.js.map +1 -1
- package/dist/react/renderers/consent.js +8 -3
- package/dist/react/renderers/consent.js.map +1 -1
- package/dist/react/renderers/email.js +3 -1
- package/dist/react/renderers/email.js.map +1 -1
- package/dist/react/renderers/repeater.js +5 -0
- package/dist/react/renderers/repeater.js.map +1 -1
- package/dist/react/renderers/select.js +20 -2
- package/dist/react/renderers/select.js.map +1 -1
- package/dist/react/renderers/text.js +3 -1
- package/dist/react/renderers/text.js.map +1 -1
- package/dist/react/state.d.ts +10 -0
- package/dist/react/state.js +45 -1
- package/dist/react/state.js.map +1 -1
- package/dist/react/submitForm.d.ts +20 -3
- package/dist/react/submitForm.js +8 -4
- package/dist/react/submitForm.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.js +2 -1
- package/dist/react/useField.js.map +1 -1
- package/dist/recall/resolver.js +1 -1
- package/dist/recall/resolver.js.map +1 -1
- package/dist/spam/constants.js +7 -1
- package/dist/spam/constants.js.map +1 -1
- package/dist/spam/spamGuard.js +2 -1
- package/dist/spam/spamGuard.js.map +1 -1
- package/dist/submissions/SubmissionAnswersClient.js +14 -14
- package/dist/submissions/SubmissionAnswersClient.js.map +1 -1
- package/dist/submissions/createSubmission.d.ts +7 -1
- package/dist/submissions/createSubmission.js +10 -5
- package/dist/submissions/createSubmission.js.map +1 -1
- 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.js +6 -5
- package/dist/submissions/runSubmission.js.map +1 -1
- package/dist/submissions/submissionLocale.js +39 -0
- package/dist/submissions/submissionLocale.js.map +1 -0
- package/dist/submissions/validateSubmission.js +125 -79
- 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/voteChange.js +21 -0
- package/dist/submissions/voteChange.js.map +1 -0
- package/dist/submissions/voteChangeEndpoint.js +110 -0
- package/dist/submissions/voteChangeEndpoint.js.map +1 -0
- package/dist/submissions/votedCookie.d.ts +10 -4
- package/dist/submissions/votedCookie.js +49 -11
- package/dist/submissions/votedCookie.js.map +1 -1
- package/dist/translations/ar.d.ts +7 -0
- package/dist/translations/ar.js +379 -0
- package/dist/translations/ar.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 +78 -3
- package/dist/translations/de.js.map +1 -1
- package/dist/translations/en.js +78 -3
- package/dist/translations/en.js.map +1 -1
- package/dist/translations/es.d.ts +7 -0
- package/dist/translations/es.js +379 -0
- package/dist/translations/es.js.map +1 -0
- package/dist/translations/fr.d.ts +7 -0
- package/dist/translations/fr.js +379 -0
- package/dist/translations/fr.js.map +1 -0
- package/dist/translations/id.d.ts +7 -0
- package/dist/translations/id.js +379 -0
- package/dist/translations/id.js.map +1 -0
- package/dist/translations/index.d.ts +23 -6
- package/dist/translations/index.js +31 -6
- package/dist/translations/index.js.map +1 -1
- package/dist/translations/keys.d.ts +76 -1
- package/dist/translations/keys.js +76 -1
- package/dist/translations/keys.js.map +1 -1
- package/dist/translations/ko.d.ts +7 -0
- package/dist/translations/ko.js +379 -0
- package/dist/translations/ko.js.map +1 -0
- 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/pt.d.ts +7 -0
- package/dist/translations/pt.js +379 -0
- package/dist/translations/pt.js.map +1 -0
- package/dist/translations/ru.d.ts +7 -0
- package/dist/translations/ru.js +379 -0
- package/dist/translations/ru.js.map +1 -0
- package/dist/translations/uk.d.ts +7 -0
- package/dist/translations/uk.js +379 -0
- package/dist/translations/uk.js.map +1 -0
- package/dist/translations/zh.d.ts +7 -0
- package/dist/translations/zh.js +379 -0
- package/dist/translations/zh.js.map +1 -0
- package/dist/validation/builtin/index.js +2 -0
- 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/notAlreadySubmitted.js +5 -3
- package/dist/validation/builtin/notAlreadySubmitted.js.map +1 -1
- package/package.json +29 -16
- package/styles/form-builder.css +84 -0
|
@@ -1,144 +1,87 @@
|
|
|
1
1
|
import { keys } from "../../translations/keys.js";
|
|
2
2
|
import { asTranslate, labelFor } from "../../translations/server.js";
|
|
3
|
-
import {
|
|
3
|
+
import { localizedIf } from "../localizedIf.js";
|
|
4
|
+
import { formatCalcValue } from "../../calc/formatCalcValue.js";
|
|
4
5
|
import { normalizeCalc } from "../../calc/normalizeCalc.js";
|
|
5
6
|
import { defineFormField } from "../defineFormField.js";
|
|
6
7
|
//#region src/fields/builtin/calculation.ts
|
|
8
|
+
const CALC_SCHEMA_URI = "https://10xmedia.de/schemas/form-builder/calc-expression.json";
|
|
7
9
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* `validateExpression`/`normalizeCalc`; this schema is a convenience, not the source of truth.
|
|
10
|
+
* Validates the calculation field's `expression` against the registered extension names: unset/empty
|
|
11
|
+
* is fine, otherwise it must normalize into a well-formed `CalcExpression` tree.
|
|
11
12
|
*/
|
|
12
|
-
const
|
|
13
|
-
uri: "https://10xmedia.de/schemas/form-builder/calc-expression.json",
|
|
14
|
-
fileMatch: ["https://10xmedia.de/schemas/form-builder/calc-expression.json"],
|
|
15
|
-
schema: {
|
|
16
|
-
$ref: "#/definitions/expr",
|
|
17
|
-
definitions: {
|
|
18
|
-
expr: { oneOf: [
|
|
19
|
-
{ $ref: "#/definitions/lit" },
|
|
20
|
-
{ $ref: "#/definitions/ref" },
|
|
21
|
-
{ $ref: "#/definitions/op" },
|
|
22
|
-
{ $ref: "#/definitions/neg" },
|
|
23
|
-
{ $ref: "#/definitions/fn" },
|
|
24
|
-
{ $ref: "#/definitions/weight" }
|
|
25
|
-
] },
|
|
26
|
-
lit: {
|
|
27
|
-
type: "object",
|
|
28
|
-
properties: {
|
|
29
|
-
type: { enum: ["lit"] },
|
|
30
|
-
value: { type: "number" }
|
|
31
|
-
},
|
|
32
|
-
required: ["type", "value"],
|
|
33
|
-
additionalProperties: false
|
|
34
|
-
},
|
|
35
|
-
ref: {
|
|
36
|
-
type: "object",
|
|
37
|
-
properties: {
|
|
38
|
-
type: { enum: ["ref"] },
|
|
39
|
-
field: { type: "string" }
|
|
40
|
-
},
|
|
41
|
-
required: ["type", "field"],
|
|
42
|
-
additionalProperties: false
|
|
43
|
-
},
|
|
44
|
-
op: {
|
|
45
|
-
type: "object",
|
|
46
|
-
properties: {
|
|
47
|
-
type: { enum: ["op"] },
|
|
48
|
-
op: { enum: [...CALC_OPS] },
|
|
49
|
-
left: { $ref: "#/definitions/expr" },
|
|
50
|
-
right: { $ref: "#/definitions/expr" }
|
|
51
|
-
},
|
|
52
|
-
required: [
|
|
53
|
-
"type",
|
|
54
|
-
"op",
|
|
55
|
-
"left",
|
|
56
|
-
"right"
|
|
57
|
-
],
|
|
58
|
-
additionalProperties: false
|
|
59
|
-
},
|
|
60
|
-
neg: {
|
|
61
|
-
type: "object",
|
|
62
|
-
properties: {
|
|
63
|
-
type: { enum: ["neg"] },
|
|
64
|
-
operand: { $ref: "#/definitions/expr" }
|
|
65
|
-
},
|
|
66
|
-
required: ["type", "operand"],
|
|
67
|
-
additionalProperties: false
|
|
68
|
-
},
|
|
69
|
-
fn: {
|
|
70
|
-
type: "object",
|
|
71
|
-
properties: {
|
|
72
|
-
type: { enum: ["fn"] },
|
|
73
|
-
fn: { enum: [...CALC_FNS] },
|
|
74
|
-
args: {
|
|
75
|
-
type: "array",
|
|
76
|
-
items: { $ref: "#/definitions/expr" }
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
required: [
|
|
80
|
-
"type",
|
|
81
|
-
"fn",
|
|
82
|
-
"args"
|
|
83
|
-
],
|
|
84
|
-
additionalProperties: false
|
|
85
|
-
},
|
|
86
|
-
weight: {
|
|
87
|
-
type: "object",
|
|
88
|
-
properties: {
|
|
89
|
-
type: { enum: ["weight"] },
|
|
90
|
-
field: { type: "string" },
|
|
91
|
-
weights: {
|
|
92
|
-
type: "object",
|
|
93
|
-
additionalProperties: { type: "number" }
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
required: [
|
|
97
|
-
"type",
|
|
98
|
-
"field",
|
|
99
|
-
"weights"
|
|
100
|
-
],
|
|
101
|
-
additionalProperties: false
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
/**
|
|
107
|
-
* Validates the calculation field's `expression`: unset/empty is fine, otherwise it must
|
|
108
|
-
* normalize into a well-formed `CalcExpression` tree. Exported for unit testing.
|
|
109
|
-
*/
|
|
110
|
-
const validateExpression = (value, { req }) => {
|
|
13
|
+
const buildValidateExpression = (allowed) => (value, { req }) => {
|
|
111
14
|
if (value == null || value === "") return true;
|
|
112
|
-
return normalizeCalc(value) !== void 0 ? true : asTranslate(req.t)(keys.validationCalcExpressionInvalid);
|
|
15
|
+
return normalizeCalc(value, allowed) !== void 0 ? true : asTranslate(req.t)(keys.validationCalcExpressionInvalid);
|
|
113
16
|
};
|
|
114
17
|
/**
|
|
115
18
|
* A calculation is derived and read-only: it renders disabled with no text affordance (no
|
|
116
19
|
* `placeholder`), and it is never validated (`runSubmission` stores its computed value and skips
|
|
117
20
|
* `runValidation` entirely), so an authored `required` could never fire. Both are omitted rather
|
|
118
|
-
* than offered as settings that do nothing.
|
|
21
|
+
* than offered as settings that do nothing. `allowed` threads the registered calc extension names
|
|
22
|
+
* (plugin option `calc`) into the expression validate; `extras.sources`
|
|
23
|
+
* carries serializable source metadata to the builder component as clientProps (custom function
|
|
24
|
+
* names travel too, so the client-side normalize accepts every expression the server accepts).
|
|
119
25
|
*/
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
26
|
+
const buildCalculationField = (allowed, extras) => {
|
|
27
|
+
const sources = extras?.sources ?? [];
|
|
28
|
+
const functions = [...allowed?.functions ?? []];
|
|
29
|
+
const builderRef = "@10x-media/form-builder/client#CalcExpressionBuilder";
|
|
30
|
+
return defineFormField({
|
|
31
|
+
type: "calculation",
|
|
32
|
+
label: keys.fieldTypeCalculation,
|
|
33
|
+
value: "number",
|
|
34
|
+
omitShared: ["placeholder", "required"],
|
|
35
|
+
config: [
|
|
36
|
+
{
|
|
37
|
+
name: "expression",
|
|
38
|
+
type: "json",
|
|
39
|
+
label: labelFor(keys.configExpression),
|
|
40
|
+
admin: { components: { Field: sources.length > 0 || functions.length > 0 ? {
|
|
41
|
+
path: builderRef,
|
|
42
|
+
clientProps: {
|
|
43
|
+
sources,
|
|
44
|
+
functions
|
|
45
|
+
}
|
|
46
|
+
} : builderRef } },
|
|
47
|
+
jsonSchema: {
|
|
48
|
+
uri: CALC_SCHEMA_URI,
|
|
49
|
+
fileMatch: [CALC_SCHEMA_URI],
|
|
50
|
+
schema: { type: "object" }
|
|
51
|
+
},
|
|
52
|
+
validate: buildValidateExpression(allowed)
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: "calcDisplay",
|
|
56
|
+
type: "checkbox",
|
|
57
|
+
defaultValue: true,
|
|
58
|
+
label: labelFor(keys.configCalcDisplay)
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: "decimals",
|
|
62
|
+
type: "number",
|
|
63
|
+
min: 0,
|
|
64
|
+
max: 6,
|
|
65
|
+
label: labelFor(keys.calcConfigDecimals)
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: "prefix",
|
|
69
|
+
type: "text",
|
|
70
|
+
label: labelFor(keys.calcConfigPrefix),
|
|
71
|
+
...localizedIf(extras?.localize === true)
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: "suffix",
|
|
75
|
+
type: "text",
|
|
76
|
+
label: labelFor(keys.calcConfigSuffix),
|
|
77
|
+
...localizedIf(extras?.localize === true)
|
|
78
|
+
}
|
|
79
|
+
],
|
|
80
|
+
format: ({ value, config }) => value == null ? "" : formatCalcValue(value, config)
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
buildCalculationField();
|
|
141
84
|
//#endregion
|
|
142
|
-
export {
|
|
85
|
+
export { buildCalculationField };
|
|
143
86
|
|
|
144
87
|
//# sourceMappingURL=calculation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculation.js","names":[],"sources":["../../../src/fields/builtin/calculation.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"calculation.js","names":[],"sources":["../../../src/fields/builtin/calculation.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\nimport { formatCalcValue } from '../../calc/formatCalcValue'\nimport { type CalcAllowed, normalizeCalc } from '../../calc/normalizeCalc'\nimport { keys } from '../../translations/keys'\nimport { asTranslate, labelFor } from '../../translations/server'\nimport { defineFormField } from '../defineFormField'\nimport { localizedIf } from '../localizedIf'\n\n/**\n * Serializable calc-source metadata for the admin builder (threaded as clientProps): key, display\n * label, and which modes the source implements (`scalar` = has `resolve`, `weights` = has\n * `resolveWeights`). Derived where the registry is resolved; resolver functions never serialize.\n */\nexport type CalcSourceClientMeta = {\n\tkey: string\n\tlabel: string | Record<string, string>\n\tscalar: boolean\n\tweights: boolean\n}\n\ntype BuildCalculationFieldExtras = {\n\t/** Whether content-bearing display config (`prefix`, `suffix`) is localized. */\n\tlocalize?: boolean\n\t/** Registered calc-source metadata for the builder UI. */\n\tsources?: CalcSourceClientMeta[]\n}\n\n/** The calculation field's own config values (display settings; `expression` is handled separately). */\ntype CalculationConfig = {\n\tdecimals?: number\n\tprefix?: string\n\tsuffix?: string\n}\n\nconst CALC_SCHEMA_URI = 'https://10xmedia.de/schemas/form-builder/calc-expression.json'\n\n/**\n * Validates the calculation field's `expression` against the registered extension names: unset/empty\n * is fine, otherwise it must normalize into a well-formed `CalcExpression` tree.\n */\nexport const buildValidateExpression =\n\t(allowed?: CalcAllowed) =>\n\t(value: unknown, { req }: { data?: unknown; req: PayloadRequest }): string | true => {\n\t\tif (value == null || value === '') {\n\t\t\treturn true\n\t\t}\n\t\treturn normalizeCalc(value, allowed) !== undefined\n\t\t\t? true\n\t\t\t: asTranslate(req.t)(keys.validationCalcExpressionInvalid)\n\t}\n\n/** The no-extensions validate (built-in grammar only). Exported for unit testing and spread consumers. */\nexport const validateExpression = buildValidateExpression()\n\n/**\n * A calculation is derived and read-only: it renders disabled with no text affordance (no\n * `placeholder`), and it is never validated (`runSubmission` stores its computed value and skips\n * `runValidation` entirely), so an authored `required` could never fire. Both are omitted rather\n * than offered as settings that do nothing. `allowed` threads the registered calc extension names\n * (plugin option `calc`) into the expression validate; `extras.sources`\n * carries serializable source metadata to the builder component as clientProps (custom function\n * names travel too, so the client-side normalize accepts every expression the server accepts).\n */\nexport const buildCalculationField = (\n\tallowed?: CalcAllowed,\n\textras?: BuildCalculationFieldExtras\n) => {\n\tconst sources = extras?.sources ?? []\n\tconst functions = [...(allowed?.functions ?? [])]\n\tconst builderRef = '@10x-media/form-builder/client#CalcExpressionBuilder'\n\treturn defineFormField<'number', CalculationConfig>({\n\t\ttype: 'calculation',\n\t\tlabel: keys.fieldTypeCalculation,\n\t\tvalue: 'number',\n\t\tomitShared: ['placeholder', 'required'],\n\t\tconfig: [\n\t\t\t{\n\t\t\t\tname: 'expression',\n\t\t\t\ttype: 'json',\n\t\t\t\tlabel: labelFor(keys.configExpression),\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\tsources.length > 0 || functions.length > 0\n\t\t\t\t\t\t\t\t? { path: builderRef, clientProps: { sources, functions } }\n\t\t\t\t\t\t\t\t: builderRef,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t// Type generation reads jsonSchema.schema as the field's type (Payload 4 has no transform\n\t\t\t\t// for json fields), and the visual builder replaces the JSON editor, so a flat object is\n\t\t\t\t// all it carries. The real gate is the validate below.\n\t\t\t\tjsonSchema: {\n\t\t\t\t\turi: CALC_SCHEMA_URI,\n\t\t\t\t\tfileMatch: [CALC_SCHEMA_URI],\n\t\t\t\t\tschema: { type: 'object' },\n\t\t\t\t},\n\t\t\t\tvalidate: buildValidateExpression(allowed),\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'calcDisplay',\n\t\t\t\ttype: 'checkbox',\n\t\t\t\tdefaultValue: true,\n\t\t\t\tlabel: labelFor(keys.configCalcDisplay),\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'decimals',\n\t\t\t\ttype: 'number',\n\t\t\t\tmin: 0,\n\t\t\t\tmax: 6,\n\t\t\t\tlabel: labelFor(keys.calcConfigDecimals),\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'prefix',\n\t\t\t\ttype: 'text',\n\t\t\t\tlabel: labelFor(keys.calcConfigPrefix),\n\t\t\t\t...localizedIf(extras?.localize === true),\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'suffix',\n\t\t\t\ttype: 'text',\n\t\t\t\tlabel: labelFor(keys.calcConfigSuffix),\n\t\t\t\t...localizedIf(extras?.localize === true),\n\t\t\t},\n\t\t],\n\t\tformat: ({ value, config }) => (value == null ? '' : formatCalcValue(value, config)),\n\t})\n}\n\n/** The no-extensions definition, for definition-spread consumers (the `buildSelectField`/`selectField` precedent). */\nexport const calculationField = buildCalculationField()\n"],"mappings":";;;;;;;AAkCA,MAAM,kBAAkB;;;;;AAMxB,MAAa,2BACX,aACA,OAAgB,EAAE,UAAkE;CACpF,IAAI,SAAS,QAAQ,UAAU,IAC9B,OAAO;CAER,OAAO,cAAc,OAAO,OAAO,MAAM,KAAA,IACtC,OACA,YAAY,IAAI,CAAC,EAAE,KAAK,+BAA+B;AAC3D;;;;;;;;;;AAcD,MAAa,yBACZ,SACA,WACI;CACJ,MAAM,UAAU,QAAQ,WAAW,CAAC;CACpC,MAAM,YAAY,CAAC,GAAI,SAAS,aAAa,CAAC,CAAE;CAChD,MAAM,aAAa;CACnB,OAAO,gBAA6C;EACnD,MAAM;EACN,OAAO,KAAK;EACZ,OAAO;EACP,YAAY,CAAC,eAAe,UAAU;EACtC,QAAQ;GACP;IACC,MAAM;IACN,MAAM;IACN,OAAO,SAAS,KAAK,gBAAgB;IACrC,OAAO,EACN,YAAY,EACX,OACC,QAAQ,SAAS,KAAK,UAAU,SAAS,IACtC;KAAE,MAAM;KAAY,aAAa;MAAE;MAAS;KAAU;IAAE,IACxD,WACL,EACD;IAIA,YAAY;KACX,KAAK;KACL,WAAW,CAAC,eAAe;KAC3B,QAAQ,EAAE,MAAM,SAAS;IAC1B;IACA,UAAU,wBAAwB,OAAO;GAC1C;GACA;IACC,MAAM;IACN,MAAM;IACN,cAAc;IACd,OAAO,SAAS,KAAK,iBAAiB;GACvC;GACA;IACC,MAAM;IACN,MAAM;IACN,KAAK;IACL,KAAK;IACL,OAAO,SAAS,KAAK,kBAAkB;GACxC;GACA;IACC,MAAM;IACN,MAAM;IACN,OAAO,SAAS,KAAK,gBAAgB;IACrC,GAAG,YAAY,QAAQ,aAAa,IAAI;GACzC;GACA;IACC,MAAM;IACN,MAAM;IACN,OAAO,SAAS,KAAK,gBAAgB;IACrC,GAAG,YAAY,QAAQ,aAAa,IAAI;GACzC;EACD;EACA,SAAS,EAAE,OAAO,aAAc,SAAS,OAAO,KAAK,gBAAgB,OAAO,MAAM;CACnF,CAAC;AACF;AAGgC,sBAAsB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { keys } from "../../translations/keys.js";
|
|
2
|
+
import { labelFor } from "../../translations/server.js";
|
|
2
3
|
import { defineFormField } from "../defineFormField.js";
|
|
3
4
|
//#region src/fields/builtin/checkbox.ts
|
|
4
5
|
/**
|
|
@@ -12,6 +13,20 @@ const checkboxField = defineFormField({
|
|
|
12
13
|
label: keys.fieldTypeCheckbox,
|
|
13
14
|
value: "boolean",
|
|
14
15
|
omitShared: ["placeholder"],
|
|
16
|
+
config: [{
|
|
17
|
+
name: "display",
|
|
18
|
+
type: "select",
|
|
19
|
+
defaultValue: "checkbox",
|
|
20
|
+
label: labelFor(keys.configCheckboxDisplay),
|
|
21
|
+
admin: { isClearable: false },
|
|
22
|
+
options: [{
|
|
23
|
+
label: labelFor(keys.checkboxDisplayCheckbox),
|
|
24
|
+
value: "checkbox"
|
|
25
|
+
}, {
|
|
26
|
+
label: labelFor(keys.checkboxDisplaySwitch),
|
|
27
|
+
value: "switch"
|
|
28
|
+
}]
|
|
29
|
+
}],
|
|
15
30
|
validate: ({ value, config, t }) => config.required === true && value !== true ? t(keys.validationRequired) : true,
|
|
16
31
|
format: ({ value, t }) => value ? t(keys.formatYes) : t(keys.formatNo)
|
|
17
32
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkbox.js","names":[],"sources":["../../../src/fields/builtin/checkbox.ts"],"sourcesContent":["import { keys } from '../../translations/keys'\nimport { defineFormField } from '../defineFormField'\n\ntype CheckboxConfig = { required?: boolean }\n\n/**\n * A checkbox renders as a lone box with no free-text affordance, so `placeholder` is never read.\n * The intrinsic validator owns `required`: the engine's shared required guard only fires on an\n * empty value, and `false` (checked, then unchecked) is a present one, so without this a required\n * checkbox would accept an explicit refusal.\n */\nexport const checkboxField = defineFormField<'boolean', CheckboxConfig>({\n\ttype: 'checkbox',\n\tlabel: keys.fieldTypeCheckbox,\n\tvalue: 'boolean',\n\tomitShared: ['placeholder'],\n\tvalidate: ({ value, config, t }) =>\n\t\tconfig.required === true && value !== true ? t(keys.validationRequired) : true,\n\tformat: ({ value, t }) => (value ? t(keys.formatYes) : t(keys.formatNo)),\n})\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"checkbox.js","names":[],"sources":["../../../src/fields/builtin/checkbox.ts"],"sourcesContent":["import { keys } from '../../translations/keys'\nimport { labelFor } from '../../translations/server'\nimport { defineFormField } from '../defineFormField'\n\ntype CheckboxConfig = { required?: boolean; display?: 'checkbox' | 'switch' }\n\n/**\n * A checkbox renders as a lone box with no free-text affordance, so `placeholder` is never read.\n * The intrinsic validator owns `required`: the engine's shared required guard only fires on an\n * empty value, and `false` (checked, then unchecked) is a present one, so without this a required\n * checkbox would accept an explicit refusal.\n */\nexport const checkboxField = defineFormField<'boolean', CheckboxConfig>({\n\ttype: 'checkbox',\n\tlabel: keys.fieldTypeCheckbox,\n\tvalue: 'boolean',\n\tomitShared: ['placeholder'],\n\tconfig: [\n\t\t{\n\t\t\tname: 'display',\n\t\t\ttype: 'select',\n\t\t\tdefaultValue: 'checkbox',\n\t\t\tlabel: labelFor(keys.configCheckboxDisplay),\n\t\t\tadmin: { isClearable: false },\n\t\t\toptions: [\n\t\t\t\t{ label: labelFor(keys.checkboxDisplayCheckbox), value: 'checkbox' },\n\t\t\t\t{ label: labelFor(keys.checkboxDisplaySwitch), value: 'switch' },\n\t\t\t],\n\t\t},\n\t],\n\tvalidate: ({ value, config, t }) =>\n\t\tconfig.required === true && value !== true ? t(keys.validationRequired) : true,\n\tformat: ({ value, t }) => (value ? t(keys.formatYes) : t(keys.formatNo)),\n})\n"],"mappings":";;;;;;;;;;AAYA,MAAa,gBAAgB,gBAA2C;CACvE,MAAM;CACN,OAAO,KAAK;CACZ,OAAO;CACP,YAAY,CAAC,aAAa;CAC1B,QAAQ,CACP;EACC,MAAM;EACN,MAAM;EACN,cAAc;EACd,OAAO,SAAS,KAAK,qBAAqB;EAC1C,OAAO,EAAE,aAAa,MAAM;EAC5B,SAAS,CACR;GAAE,OAAO,SAAS,KAAK,uBAAuB;GAAG,OAAO;EAAW,GACnE;GAAE,OAAO,SAAS,KAAK,qBAAqB;GAAG,OAAO;EAAS,CAChE;CACD,CACD;CACA,WAAW,EAAE,OAAO,QAAQ,QAC3B,OAAO,aAAa,QAAQ,UAAU,OAAO,EAAE,KAAK,kBAAkB,IAAI;CAC3E,SAAS,EAAE,OAAO,QAAS,QAAQ,EAAE,KAAK,SAAS,IAAI,EAAE,KAAK,QAAQ;AACvE,CAAC"}
|
|
@@ -14,6 +14,10 @@ import { defineFormField } from "../defineFormField.js";
|
|
|
14
14
|
* The intrinsic validator owns `required`: the engine's shared required guard only fires on an
|
|
15
15
|
* empty value, and `false` (the coerced state of both an unchecked box and an absent answer) is a
|
|
16
16
|
* present one, so without this a required consent would accept an explicit refusal.
|
|
17
|
+
*
|
|
18
|
+
* `display: 'notice'` renders the statement as prose with no control: the submit itself is the
|
|
19
|
+
* consent, so there is no value for `required` to gate and validation always passes; the server
|
|
20
|
+
* records `agreed: true` on the proof regardless of what the client sent.
|
|
17
21
|
*/
|
|
18
22
|
const consentField = defineFormField({
|
|
19
23
|
type: "consent",
|
|
@@ -37,8 +41,24 @@ const consentField = defineFormField({
|
|
|
37
41
|
isClearable: false
|
|
38
42
|
}
|
|
39
43
|
} } }
|
|
44
|
+
}, {
|
|
45
|
+
name: "display",
|
|
46
|
+
type: "select",
|
|
47
|
+
defaultValue: "checkbox",
|
|
48
|
+
label: labelForKey(keys.consentConfigDisplay),
|
|
49
|
+
admin: {
|
|
50
|
+
isClearable: false,
|
|
51
|
+
description: labelForKey(keys.consentConfigDisplayDescription)
|
|
52
|
+
},
|
|
53
|
+
options: [{
|
|
54
|
+
label: labelForKey(keys.consentDisplayCheckbox),
|
|
55
|
+
value: "checkbox"
|
|
56
|
+
}, {
|
|
57
|
+
label: labelForKey(keys.consentDisplayNotice),
|
|
58
|
+
value: "notice"
|
|
59
|
+
}]
|
|
40
60
|
}],
|
|
41
|
-
validate: ({ value, config, t }) => config.required === true && value !== true ? t(keys.validationRequired) : true,
|
|
61
|
+
validate: ({ value, config, t }) => config.display !== "notice" && config.required === true && value !== true ? t(keys.validationRequired) : true,
|
|
42
62
|
format: ({ value, t }) => t(value === true ? keys.formatYes : keys.formatNo)
|
|
43
63
|
});
|
|
44
64
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consent.js","names":[],"sources":["../../../src/fields/builtin/consent.ts"],"sourcesContent":["import { keys } from '../../translations/keys'\nimport { labelForKey } from '../../translations/server'\nimport { defineFormField } from '../defineFormField'\n\ntype ConsentConfig = { source?: string; required?: boolean }\n\nconst SOURCE_FIELD_REF = '@10x-media/form-builder/client#EndpointOptionsSelect'\n\n/**\n * Consent is a reference, so the field is a reference: the author picks a source and nothing else.\n * The statement, the policy page, and its version all live with the source (see\n * `consentSourcesField`), so there is no wording to copy per form, no URL to paste, and no version\n * to type; correcting a statement corrects every form pointing at it. `label` and `placeholder` are\n * dropped for the same reason: the statement is the visible text and the checkbox's accessible name.\n *\n * Registered only when the plugin's `consent.sources` resolver is set, since a consent field with\n * no source to reference has nothing to say and nothing to prove.\n *\n * The intrinsic validator owns `required`: the engine's shared required guard only fires on an\n * empty value, and `false` (the coerced state of both an unchecked box and an absent answer) is a\n * present one, so without this a required consent would accept an explicit refusal.\n */\nexport const consentField = defineFormField<'boolean', ConsentConfig>({\n\ttype: 'consent',\n\tlabel: keys.fieldTypeConsent,\n\tvalue: 'boolean',\n\tomitShared: ['label', 'placeholder', 'description'],\n\tblockLabel: '@10x-media/form-builder/client#ConsentBlockLabel',\n\tconfig: [\n\t\t{\n\t\t\tname: 'source',\n\t\t\ttype: 'text',\n\t\t\tlabel: labelForKey(keys.consentConfigSource),\n\t\t\tadmin: {\n\t\t\t\tcomponents: {\n\t\t\t\t\tField: {\n\t\t\t\t\t\tpath: SOURCE_FIELD_REF,\n\t\t\t\t\t\tclientProps: {\n\t\t\t\t\t\t\tendpoint: 'consent-sources',\n\t\t\t\t\t\t\tdescriptionKey: keys.consentConfigSourceDescription,\n\t\t\t\t\t\t\tisClearable: false,\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\tvalidate: ({ value, config, t }) =>\n\t\tconfig.required === true && value !== true
|
|
1
|
+
{"version":3,"file":"consent.js","names":[],"sources":["../../../src/fields/builtin/consent.ts"],"sourcesContent":["import type { ConsentDisplay } from '../../consent/effectiveStatement'\nimport { keys } from '../../translations/keys'\nimport { labelForKey } from '../../translations/server'\nimport { defineFormField } from '../defineFormField'\n\ntype ConsentConfig = { source?: string; required?: boolean; display?: ConsentDisplay }\n\nconst SOURCE_FIELD_REF = '@10x-media/form-builder/client#EndpointOptionsSelect'\n\n/**\n * Consent is a reference, so the field is a reference: the author picks a source and nothing else.\n * The statement, the policy page, and its version all live with the source (see\n * `consentSourcesField`), so there is no wording to copy per form, no URL to paste, and no version\n * to type; correcting a statement corrects every form pointing at it. `label` and `placeholder` are\n * dropped for the same reason: the statement is the visible text and the checkbox's accessible name.\n *\n * Registered only when the plugin's `consent.sources` resolver is set, since a consent field with\n * no source to reference has nothing to say and nothing to prove.\n *\n * The intrinsic validator owns `required`: the engine's shared required guard only fires on an\n * empty value, and `false` (the coerced state of both an unchecked box and an absent answer) is a\n * present one, so without this a required consent would accept an explicit refusal.\n *\n * `display: 'notice'` renders the statement as prose with no control: the submit itself is the\n * consent, so there is no value for `required` to gate and validation always passes; the server\n * records `agreed: true` on the proof regardless of what the client sent.\n */\nexport const consentField = defineFormField<'boolean', ConsentConfig>({\n\ttype: 'consent',\n\tlabel: keys.fieldTypeConsent,\n\tvalue: 'boolean',\n\tomitShared: ['label', 'placeholder', 'description'],\n\tblockLabel: '@10x-media/form-builder/client#ConsentBlockLabel',\n\tconfig: [\n\t\t{\n\t\t\tname: 'source',\n\t\t\ttype: 'text',\n\t\t\tlabel: labelForKey(keys.consentConfigSource),\n\t\t\tadmin: {\n\t\t\t\tcomponents: {\n\t\t\t\t\tField: {\n\t\t\t\t\t\tpath: SOURCE_FIELD_REF,\n\t\t\t\t\t\tclientProps: {\n\t\t\t\t\t\t\tendpoint: 'consent-sources',\n\t\t\t\t\t\t\tdescriptionKey: keys.consentConfigSourceDescription,\n\t\t\t\t\t\t\tisClearable: false,\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: 'display',\n\t\t\ttype: 'select',\n\t\t\tdefaultValue: 'checkbox',\n\t\t\tlabel: labelForKey(keys.consentConfigDisplay),\n\t\t\tadmin: { isClearable: false, description: labelForKey(keys.consentConfigDisplayDescription) },\n\t\t\toptions: [\n\t\t\t\t{ label: labelForKey(keys.consentDisplayCheckbox), value: 'checkbox' },\n\t\t\t\t{ label: labelForKey(keys.consentDisplayNotice), value: 'notice' },\n\t\t\t],\n\t\t},\n\t],\n\tvalidate: ({ value, config, t }) =>\n\t\tconfig.display !== 'notice' && config.required === true && value !== true\n\t\t\t? t(keys.validationRequired)\n\t\t\t: true,\n\tformat: ({ value, t }) => t(value === true ? keys.formatYes : keys.formatNo),\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA2BA,MAAa,eAAe,gBAA0C;CACrE,MAAM;CACN,OAAO,KAAK;CACZ,OAAO;CACP,YAAY;EAAC;EAAS;EAAe;CAAa;CAClD,YAAY;CACZ,QAAQ,CACP;EACC,MAAM;EACN,MAAM;EACN,OAAO,YAAY,KAAK,mBAAmB;EAC3C,OAAO,EACN,YAAY,EACX,OAAO;GACN,MAAM;GACN,aAAa;IACZ,UAAU;IACV,gBAAgB,KAAK;IACrB,aAAa;GACd;EACD,EACD,EACD;CACD,GACA;EACC,MAAM;EACN,MAAM;EACN,cAAc;EACd,OAAO,YAAY,KAAK,oBAAoB;EAC5C,OAAO;GAAE,aAAa;GAAO,aAAa,YAAY,KAAK,+BAA+B;EAAE;EAC5F,SAAS,CACR;GAAE,OAAO,YAAY,KAAK,sBAAsB;GAAG,OAAO;EAAW,GACrE;GAAE,OAAO,YAAY,KAAK,oBAAoB;GAAG,OAAO;EAAS,CAClE;CACD,CACD;CACA,WAAW,EAAE,OAAO,QAAQ,QAC3B,OAAO,YAAY,YAAY,OAAO,aAAa,QAAQ,UAAU,OAClE,EAAE,KAAK,kBAAkB,IACzB;CACJ,SAAS,EAAE,OAAO,QAAQ,EAAE,UAAU,OAAO,KAAK,YAAY,KAAK,QAAQ;AAC5E,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { keys } from "../../translations/keys.js";
|
|
2
|
+
import { labelFor } from "../../translations/server.js";
|
|
2
3
|
import { defineFormField } from "../defineFormField.js";
|
|
3
4
|
import { EMAIL_PATTERN } from "../../validation/emailPattern.js";
|
|
4
5
|
//#region src/fields/builtin/email.ts
|
|
@@ -6,6 +7,12 @@ const emailField = defineFormField({
|
|
|
6
7
|
type: "email",
|
|
7
8
|
label: keys.fieldTypeEmail,
|
|
8
9
|
value: "text",
|
|
10
|
+
advancedConfig: [{
|
|
11
|
+
name: "autocomplete",
|
|
12
|
+
type: "text",
|
|
13
|
+
label: labelFor(keys.configAutocomplete),
|
|
14
|
+
admin: { description: labelFor(keys.configAutocompleteDescription) }
|
|
15
|
+
}],
|
|
9
16
|
validate: ({ value, t }) => {
|
|
10
17
|
if (value == null || value === "") return true;
|
|
11
18
|
return EMAIL_PATTERN.test(value) ? true : t(keys.validationEmail);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email.js","names":[],"sources":["../../../src/fields/builtin/email.ts"],"sourcesContent":["import { keys } from '../../translations/keys'\nimport { EMAIL_PATTERN } from '../../validation/emailPattern'\nimport { defineFormField } from '../defineFormField'\n\nexport const emailField = defineFormField<'text'>({\n\ttype: 'email',\n\tlabel: keys.fieldTypeEmail,\n\tvalue: 'text',\n\tvalidate: ({ value, t }) => {\n\t\tif (value == null || value === '') {\n\t\t\treturn true\n\t\t}\n\t\treturn EMAIL_PATTERN.test(value) ? true : t(keys.validationEmail)\n\t},\n\tformat: ({ value }) => (value == null ? '' : String(value)),\n})\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"email.js","names":[],"sources":["../../../src/fields/builtin/email.ts"],"sourcesContent":["import { keys } from '../../translations/keys'\nimport { labelFor } from '../../translations/server'\nimport { EMAIL_PATTERN } from '../../validation/emailPattern'\nimport { defineFormField } from '../defineFormField'\n\nexport const emailField = defineFormField<'text'>({\n\ttype: 'email',\n\tlabel: keys.fieldTypeEmail,\n\tvalue: 'text',\n\tadvancedConfig: [\n\t\t{\n\t\t\tname: 'autocomplete',\n\t\t\ttype: 'text',\n\t\t\tlabel: labelFor(keys.configAutocomplete),\n\t\t\tadmin: { description: labelFor(keys.configAutocompleteDescription) },\n\t\t},\n\t],\n\tvalidate: ({ value, t }) => {\n\t\tif (value == null || value === '') {\n\t\t\treturn true\n\t\t}\n\t\treturn EMAIL_PATTERN.test(value) ? true : t(keys.validationEmail)\n\t},\n\tformat: ({ value }) => (value == null ? '' : String(value)),\n})\n"],"mappings":";;;;;AAKA,MAAa,aAAa,gBAAwB;CACjD,MAAM;CACN,OAAO,KAAK;CACZ,OAAO;CACP,gBAAgB,CACf;EACC,MAAM;EACN,MAAM;EACN,OAAO,SAAS,KAAK,kBAAkB;EACvC,OAAO,EAAE,aAAa,SAAS,KAAK,6BAA6B,EAAE;CACpE,CACD;CACA,WAAW,EAAE,OAAO,QAAQ;EAC3B,IAAI,SAAS,QAAQ,UAAU,IAC9B,OAAO;EAER,OAAO,cAAc,KAAK,KAAK,IAAI,OAAO,EAAE,KAAK,eAAe;CACjE;CACA,SAAS,EAAE,YAAa,SAAS,OAAO,KAAK,OAAO,KAAK;AAC1D,CAAC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { AnyFormFieldDefinition } from "../types.js";
|
|
2
|
+
import { CalcAllowed } from "../../calc/normalizeCalc.js";
|
|
3
|
+
import { CalcSourceClientMeta } from "./calculation.js";
|
|
2
4
|
import { RichTextField } from "payload";
|
|
3
5
|
|
|
4
6
|
//#region src/fields/builtin/index.d.ts
|
|
@@ -8,9 +10,11 @@ import { RichTextField } from "payload";
|
|
|
8
10
|
* richText editor on the message content field (from the plugin's `richText.editor` option). Field
|
|
9
11
|
* types without content config are shared static definitions. Definitions are authored with precise
|
|
10
12
|
* value/config generics; the registry stores them erased (config is re-narrowed per matched type at
|
|
11
|
-
* execution), hence one cast per built-in, no `any`.
|
|
13
|
+
* execution), hence one cast per built-in, no `any`. `calcAllowed` threads the registered calc
|
|
14
|
+
* extension names into the calculation field's expression validate and editor schema;
|
|
15
|
+
* `calcSources` carries the serializable source metadata the builder UI renders from.
|
|
12
16
|
*/
|
|
13
|
-
declare const buildDefaultFieldDefinitions: (localize: boolean, editor?: RichTextField["editor"], uploadMimeTypes?: string[]) => AnyFormFieldDefinition[];
|
|
17
|
+
declare const buildDefaultFieldDefinitions: (localize: boolean, editor?: RichTextField["editor"], uploadMimeTypes?: string[], calcAllowed?: CalcAllowed, calcSources?: CalcSourceClientMeta[]) => AnyFormFieldDefinition[];
|
|
14
18
|
declare const defaultFieldDefinitions: AnyFormFieldDefinition[];
|
|
15
19
|
/**
|
|
16
20
|
* `defaultFieldDefinitions` indexed by `type`, so a single built-in can be spread and tweaked
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { buildCalculationField } from "./calculation.js";
|
|
2
2
|
import { checkboxField } from "./checkbox.js";
|
|
3
3
|
import { consentField } from "./consent.js";
|
|
4
4
|
import { dateField } from "./date.js";
|
|
@@ -17,16 +17,21 @@ import { textareaField } from "./textarea.js";
|
|
|
17
17
|
* richText editor on the message content field (from the plugin's `richText.editor` option). Field
|
|
18
18
|
* types without content config are shared static definitions. Definitions are authored with precise
|
|
19
19
|
* value/config generics; the registry stores them erased (config is re-narrowed per matched type at
|
|
20
|
-
* execution), hence one cast per built-in, no `any`.
|
|
20
|
+
* execution), hence one cast per built-in, no `any`. `calcAllowed` threads the registered calc
|
|
21
|
+
* extension names into the calculation field's expression validate and editor schema;
|
|
22
|
+
* `calcSources` carries the serializable source metadata the builder UI renders from.
|
|
21
23
|
*/
|
|
22
|
-
const buildDefaultFieldDefinitions = (localize, editor, uploadMimeTypes) => [
|
|
24
|
+
const buildDefaultFieldDefinitions = (localize, editor, uploadMimeTypes, calcAllowed, calcSources) => [
|
|
23
25
|
textField,
|
|
24
26
|
textareaField,
|
|
25
27
|
emailField,
|
|
26
28
|
numberField,
|
|
27
29
|
buildSelectField(localize),
|
|
28
30
|
checkboxField,
|
|
29
|
-
|
|
31
|
+
buildCalculationField(calcAllowed, {
|
|
32
|
+
localize,
|
|
33
|
+
sources: calcSources
|
|
34
|
+
}),
|
|
30
35
|
consentField,
|
|
31
36
|
buildFileField(uploadMimeTypes),
|
|
32
37
|
buildRepeaterField(localize),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/fields/builtin/index.ts"],"sourcesContent":["import type { RichTextField } from 'payload'\nimport type { AnyFormFieldDefinition } from '../types'\nimport {
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/fields/builtin/index.ts"],"sourcesContent":["import type { RichTextField } from 'payload'\nimport type { CalcAllowed } from '../../calc/normalizeCalc'\nimport type { AnyFormFieldDefinition } from '../types'\nimport { buildCalculationField, type CalcSourceClientMeta } from './calculation'\nimport { checkboxField } from './checkbox'\nimport { consentField } from './consent'\nimport { dateField } from './date'\nimport { emailField } from './email'\nimport { buildFileField } from './file'\nimport { buildMessageField } from './message'\nimport { numberField } from './number'\nimport { buildRepeaterField } from './repeater'\nimport { buildSelectField } from './select'\nimport { textField } from './text'\nimport { textareaField } from './textarea'\n\n/**\n * Built-in field definitions with content-bearing config fields (select option labels, repeater add\n * label) carrying `localized: true` when `localize` is true. `editor`, when given, overrides the\n * richText editor on the message content field (from the plugin's `richText.editor` option). Field\n * types without content config are shared static definitions. Definitions are authored with precise\n * value/config generics; the registry stores them erased (config is re-narrowed per matched type at\n * execution), hence one cast per built-in, no `any`. `calcAllowed` threads the registered calc\n * extension names into the calculation field's expression validate and editor schema;\n * `calcSources` carries the serializable source metadata the builder UI renders from.\n */\n// biome-ignore lint/complexity/useMaxParams: the documented positional surface (localize, editor, uploadMimeTypes) plus the calc allowed sets and source metadata; an options object would break existing callers\nexport const buildDefaultFieldDefinitions = (\n\tlocalize: boolean,\n\teditor?: RichTextField['editor'],\n\tuploadMimeTypes?: string[],\n\tcalcAllowed?: CalcAllowed,\n\tcalcSources?: CalcSourceClientMeta[]\n): AnyFormFieldDefinition[] => [\n\ttextField as AnyFormFieldDefinition,\n\ttextareaField as AnyFormFieldDefinition,\n\temailField as AnyFormFieldDefinition,\n\tnumberField as AnyFormFieldDefinition,\n\tbuildSelectField(localize) as AnyFormFieldDefinition,\n\tcheckboxField as AnyFormFieldDefinition,\n\tbuildCalculationField(calcAllowed, { localize, sources: calcSources }) as AnyFormFieldDefinition,\n\tconsentField as AnyFormFieldDefinition,\n\tbuildFileField(uploadMimeTypes) as AnyFormFieldDefinition,\n\tbuildRepeaterField(localize) as AnyFormFieldDefinition,\n\tdateField as AnyFormFieldDefinition,\n\tbuildMessageField(localize, editor) as AnyFormFieldDefinition,\n]\n\nexport const defaultFieldDefinitions: AnyFormFieldDefinition[] = buildDefaultFieldDefinitions(true)\n\n/**\n * `defaultFieldDefinitions` indexed by `type`, so a single built-in can be spread and tweaked\n * without hand-rolling a `.find()`, e.g.\n * `fields: { text: { ...defaultFieldDefinitionsByType.text, validate: myValidate } }`. The\n * `fields` plugin option replaces a built-in of the same `type`; `false` removes it, `true` keeps it.\n * Prebuilt with content localization on; with `localizeContent: false`, derive overrides from\n * `buildDefaultFieldDefinitions(false)` instead so the spread does not reintroduce `localized`.\n */\nexport const defaultFieldDefinitionsByType: Record<string, AnyFormFieldDefinition> =\n\tObject.fromEntries(defaultFieldDefinitions.map((definition) => [definition.type, definition]))\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAa,gCACZ,UACA,QACA,iBACA,aACA,gBAC8B;CAC9B;CACA;CACA;CACA;CACA,iBAAiB,QAAQ;CACzB;CACA,sBAAsB,aAAa;EAAE;EAAU,SAAS;CAAY,CAAC;CACrE;CACA,eAAe,eAAe;CAC9B,mBAAmB,QAAQ;CAC3B;CACA,kBAAkB,UAAU,MAAM;AACnC;AAEA,MAAa,0BAAoD,6BAA6B,IAAI;;;;;;;;;AAUlG,MAAa,gCACZ,OAAO,YAAY,wBAAwB,KAAK,eAAe,CAAC,WAAW,MAAM,UAAU,CAAC,CAAC"}
|
|
@@ -21,7 +21,6 @@ const buildSelectField = (localize) => defineFormField({
|
|
|
21
21
|
fields: [{
|
|
22
22
|
name: "label",
|
|
23
23
|
type: "text",
|
|
24
|
-
required: true,
|
|
25
24
|
label: labelFor(keys.configOptionLabel),
|
|
26
25
|
...localizedIf(localize)
|
|
27
26
|
}, {
|
|
@@ -30,6 +29,26 @@ const buildSelectField = (localize) => defineFormField({
|
|
|
30
29
|
required: true,
|
|
31
30
|
label: labelFor(keys.configOptionValue)
|
|
32
31
|
}]
|
|
32
|
+
}, {
|
|
33
|
+
name: "display",
|
|
34
|
+
type: "select",
|
|
35
|
+
defaultValue: "dropdown",
|
|
36
|
+
label: labelFor(keys.configSelectDisplay),
|
|
37
|
+
admin: { isClearable: false },
|
|
38
|
+
options: [
|
|
39
|
+
{
|
|
40
|
+
label: labelFor(keys.selectDisplayDropdown),
|
|
41
|
+
value: "dropdown"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
label: labelFor(keys.selectDisplayRadio),
|
|
45
|
+
value: "radio"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
label: labelFor(keys.selectDisplayButtons),
|
|
49
|
+
value: "buttons"
|
|
50
|
+
}
|
|
51
|
+
]
|
|
33
52
|
}],
|
|
34
53
|
validate: ({ value, config, t }) => {
|
|
35
54
|
if (value == null || value === "") return true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select.js","names":[],"sources":["../../../src/fields/builtin/select.ts"],"sourcesContent":["import { keys } from '../../translations/keys'\nimport { labelFor } from '../../translations/server'\nimport { defineFormField } from '../defineFormField'\nimport { localizedIf } from '../localizedIf'\n\ntype SelectOption = { label
|
|
1
|
+
{"version":3,"file":"select.js","names":[],"sources":["../../../src/fields/builtin/select.ts"],"sourcesContent":["import { keys } from '../../translations/keys'\nimport { labelFor } from '../../translations/server'\nimport { defineFormField } from '../defineFormField'\nimport { localizedIf } from '../localizedIf'\n\ntype SelectOption = { label?: string; value: string }\ntype SelectConfig = { options?: SelectOption[]; display?: 'dropdown' | 'radio' | 'buttons' }\n\n/** Option `label` is author-facing content and follows `localize`; `value` is an identifier and never does. */\nexport const buildSelectField = (localize: boolean) =>\n\tdefineFormField<'text', SelectConfig>({\n\t\ttype: 'select',\n\t\tlabel: keys.fieldTypeSelect,\n\t\tvalue: 'text',\n\t\tconditionType: 'select',\n\t\tpollEligible: true,\n\t\tconfig: [\n\t\t\t{\n\t\t\t\tname: 'options',\n\t\t\t\ttype: 'array',\n\t\t\t\tlabel: labelFor(keys.configOptions),\n\t\t\t\tlabels: { singular: labelFor(keys.configOption), plural: labelFor(keys.configOptions) },\n\t\t\t\tfields: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'label',\n\t\t\t\t\t\ttype: 'text',\n\t\t\t\t\t\tlabel: labelFor(keys.configOptionLabel),\n\t\t\t\t\t\t...localizedIf(localize),\n\t\t\t\t\t},\n\t\t\t\t\t{ name: 'value', type: 'text', required: true, label: labelFor(keys.configOptionValue) },\n\t\t\t\t],\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'display',\n\t\t\t\ttype: 'select',\n\t\t\t\tdefaultValue: 'dropdown',\n\t\t\t\tlabel: labelFor(keys.configSelectDisplay),\n\t\t\t\tadmin: { isClearable: false },\n\t\t\t\toptions: [\n\t\t\t\t\t{ label: labelFor(keys.selectDisplayDropdown), value: 'dropdown' },\n\t\t\t\t\t{ label: labelFor(keys.selectDisplayRadio), value: 'radio' },\n\t\t\t\t\t{ label: labelFor(keys.selectDisplayButtons), value: 'buttons' },\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t\tvalidate: ({ value, config, t }) => {\n\t\t\tif (value == null || value === '') {\n\t\t\t\treturn true\n\t\t\t}\n\t\t\tconst options = config.options ?? []\n\t\t\tif (options.length === 0) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t\treturn options.some((option) => option.value === value) ? true : t(keys.validationSelect)\n\t\t},\n\t\tformat: ({ value, optionLabels }) => {\n\t\t\tif (value == null || value === '') {\n\t\t\t\treturn ''\n\t\t\t}\n\t\t\treturn optionLabels?.[value] ?? String(value)\n\t\t},\n\t})\n\nexport const selectField = buildSelectField(true)\n"],"mappings":";;;;;;AASA,MAAa,oBAAoB,aAChC,gBAAsC;CACrC,MAAM;CACN,OAAO,KAAK;CACZ,OAAO;CACP,eAAe;CACf,cAAc;CACd,QAAQ,CACP;EACC,MAAM;EACN,MAAM;EACN,OAAO,SAAS,KAAK,aAAa;EAClC,QAAQ;GAAE,UAAU,SAAS,KAAK,YAAY;GAAG,QAAQ,SAAS,KAAK,aAAa;EAAE;EACtF,QAAQ,CACP;GACC,MAAM;GACN,MAAM;GACN,OAAO,SAAS,KAAK,iBAAiB;GACtC,GAAG,YAAY,QAAQ;EACxB,GACA;GAAE,MAAM;GAAS,MAAM;GAAQ,UAAU;GAAM,OAAO,SAAS,KAAK,iBAAiB;EAAE,CACxF;CACD,GACA;EACC,MAAM;EACN,MAAM;EACN,cAAc;EACd,OAAO,SAAS,KAAK,mBAAmB;EACxC,OAAO,EAAE,aAAa,MAAM;EAC5B,SAAS;GACR;IAAE,OAAO,SAAS,KAAK,qBAAqB;IAAG,OAAO;GAAW;GACjE;IAAE,OAAO,SAAS,KAAK,kBAAkB;IAAG,OAAO;GAAQ;GAC3D;IAAE,OAAO,SAAS,KAAK,oBAAoB;IAAG,OAAO;GAAU;EAChE;CACD,CACD;CACA,WAAW,EAAE,OAAO,QAAQ,QAAQ;EACnC,IAAI,SAAS,QAAQ,UAAU,IAC9B,OAAO;EAER,MAAM,UAAU,OAAO,WAAW,CAAC;EACnC,IAAI,QAAQ,WAAW,GACtB,OAAO;EAER,OAAO,QAAQ,MAAM,WAAW,OAAO,UAAU,KAAK,IAAI,OAAO,EAAE,KAAK,gBAAgB;CACzF;CACA,SAAS,EAAE,OAAO,mBAAmB;EACpC,IAAI,SAAS,QAAQ,UAAU,IAC9B,OAAO;EAER,OAAO,eAAe,UAAU,OAAO,KAAK;CAC7C;AACD,CAAC;AAEyB,iBAAiB,IAAI"}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import { keys } from "../../translations/keys.js";
|
|
2
|
+
import { labelFor } from "../../translations/server.js";
|
|
2
3
|
import { defineFormField } from "../defineFormField.js";
|
|
3
4
|
//#region src/fields/builtin/text.ts
|
|
4
5
|
const textField = defineFormField({
|
|
5
6
|
type: "text",
|
|
6
7
|
label: keys.fieldTypeText,
|
|
7
8
|
value: "text",
|
|
9
|
+
advancedConfig: [{
|
|
10
|
+
name: "autocomplete",
|
|
11
|
+
type: "text",
|
|
12
|
+
label: labelFor(keys.configAutocomplete),
|
|
13
|
+
admin: { description: labelFor(keys.configAutocompleteDescription) }
|
|
14
|
+
}],
|
|
8
15
|
format: ({ value }) => value == null ? "" : String(value)
|
|
9
16
|
});
|
|
10
17
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","names":[],"sources":["../../../src/fields/builtin/text.ts"],"sourcesContent":["import { keys } from '../../translations/keys'\nimport { defineFormField } from '../defineFormField'\n\nexport const textField = defineFormField<'text'>({\n\ttype: 'text',\n\tlabel: keys.fieldTypeText,\n\tvalue: 'text',\n\tformat: ({ value }) => (value == null ? '' : String(value)),\n})\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"text.js","names":[],"sources":["../../../src/fields/builtin/text.ts"],"sourcesContent":["import { keys } from '../../translations/keys'\nimport { labelFor } from '../../translations/server'\nimport { defineFormField } from '../defineFormField'\n\nexport const textField = defineFormField<'text'>({\n\ttype: 'text',\n\tlabel: keys.fieldTypeText,\n\tvalue: 'text',\n\tadvancedConfig: [\n\t\t{\n\t\t\tname: 'autocomplete',\n\t\t\ttype: 'text',\n\t\t\tlabel: labelFor(keys.configAutocomplete),\n\t\t\tadmin: { description: labelFor(keys.configAutocompleteDescription) },\n\t\t},\n\t],\n\tformat: ({ value }) => (value == null ? '' : String(value)),\n})\n"],"mappings":";;;;AAIA,MAAa,YAAY,gBAAwB;CAChD,MAAM;CACN,OAAO,KAAK;CACZ,OAAO;CACP,gBAAgB,CACf;EACC,MAAM;EACN,MAAM;EACN,OAAO,SAAS,KAAK,kBAAkB;EACvC,OAAO,EAAE,aAAa,SAAS,KAAK,6BAA6B,EAAE;CACpE,CACD;CACA,SAAS,EAAE,YAAa,SAAS,OAAO,KAAK,OAAO,KAAK;AAC1D,CAAC"}
|
|
@@ -10,7 +10,7 @@ const instanceOptionsOf = (field) => {
|
|
|
10
10
|
if (!Array.isArray(field.options)) return;
|
|
11
11
|
const options = field.options.filter((option) => typeof option?.value === "string").map((option) => ({
|
|
12
12
|
value: String(option.value),
|
|
13
|
-
label: option.label
|
|
13
|
+
label: option.label?.trim() ? option.label : String(option.value)
|
|
14
14
|
}));
|
|
15
15
|
return options.length > 0 ? options : void 0;
|
|
16
16
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instanceOptions.js","names":[],"sources":["../../src/fields/instanceOptions.ts"],"sourcesContent":["import type { FormFieldInstance } from '../submissions/types'\n\n/**\n * Normalize a field instance's authored options to `{ value, label }` pairs, dropping entries\n * without a string value and falling back to the value as label. Returns `undefined` when the\n * instance declares no usable options, so callers can distinguish \"not a choice field\" from an\n * empty choice set. Shared by response aggregation and poll outcome resolution so both read the\n * same choice set from a form document.\n */\nexport const instanceOptionsOf = (\n\tfield: FormFieldInstance\n): { value: string; label: string }[] | undefined => {\n\tif (!Array.isArray(field.options)) {\n\t\treturn undefined\n\t}\n\tconst options = (field.options as Array<{ label?: string; value?: string }>)\n\t\t.filter((option) => typeof option?.value === 'string')\n\t\t.map((option) => ({
|
|
1
|
+
{"version":3,"file":"instanceOptions.js","names":[],"sources":["../../src/fields/instanceOptions.ts"],"sourcesContent":["import type { FormFieldInstance } from '../submissions/types'\n\n/**\n * Normalize a field instance's authored options to `{ value, label }` pairs, dropping entries\n * without a string value and falling back to the value as label. Returns `undefined` when the\n * instance declares no usable options, so callers can distinguish \"not a choice field\" from an\n * empty choice set. Shared by response aggregation and poll outcome resolution so both read the\n * same choice set from a form document.\n */\nexport const instanceOptionsOf = (\n\tfield: FormFieldInstance\n): { value: string; label: string }[] | undefined => {\n\tif (!Array.isArray(field.options)) {\n\t\treturn undefined\n\t}\n\tconst options = (field.options as Array<{ label?: string; value?: string }>)\n\t\t.filter((option) => typeof option?.value === 'string')\n\t\t.map((option) => ({\n\t\t\tvalue: String(option.value),\n\t\t\tlabel: option.label?.trim() ? option.label : String(option.value),\n\t\t}))\n\treturn options.length > 0 ? options : undefined\n}\n"],"mappings":";;;;;;;;AASA,MAAa,qBACZ,UACoD;CACpD,IAAI,CAAC,MAAM,QAAQ,MAAM,OAAO,GAC/B;CAED,MAAM,UAAW,MAAM,QACrB,QAAQ,WAAW,OAAO,QAAQ,UAAU,QAAQ,EACpD,KAAK,YAAY;EACjB,OAAO,OAAO,OAAO,KAAK;EAC1B,OAAO,OAAO,OAAO,KAAK,IAAI,OAAO,QAAQ,OAAO,OAAO,KAAK;CACjE,EAAE;CACH,OAAO,QAAQ,SAAS,IAAI,UAAU,KAAA;AACvC"}
|
|
@@ -65,7 +65,6 @@ const baseSharedFieldConfig = (localize) => [
|
|
|
65
65
|
fields: [{
|
|
66
66
|
name: "width",
|
|
67
67
|
type: "select",
|
|
68
|
-
required: true,
|
|
69
68
|
defaultValue: "full",
|
|
70
69
|
label: labelFor(keys.configWidth),
|
|
71
70
|
admin: {
|
|
@@ -74,19 +73,19 @@ const baseSharedFieldConfig = (localize) => [
|
|
|
74
73
|
},
|
|
75
74
|
options: [
|
|
76
75
|
{
|
|
77
|
-
label:
|
|
76
|
+
label: labelFor(keys.widthFull),
|
|
78
77
|
value: "full"
|
|
79
78
|
},
|
|
80
79
|
{
|
|
81
|
-
label:
|
|
80
|
+
label: labelFor(keys.widthHalf),
|
|
82
81
|
value: "half"
|
|
83
82
|
},
|
|
84
83
|
{
|
|
85
|
-
label:
|
|
84
|
+
label: labelFor(keys.widthThird),
|
|
86
85
|
value: "third"
|
|
87
86
|
},
|
|
88
87
|
{
|
|
89
|
-
label:
|
|
88
|
+
label: labelFor(keys.widthTwoThirds),
|
|
90
89
|
value: "twoThirds"
|
|
91
90
|
}
|
|
92
91
|
]
|
|
@@ -124,7 +123,7 @@ const sharedFieldConfig = (localize = true, omitShared = []) => {
|
|
|
124
123
|
omit.delete("name");
|
|
125
124
|
return applyOmissions(baseSharedFieldConfig(localize), omit);
|
|
126
125
|
};
|
|
127
|
-
const fieldBlockTabs = ({ conditionTypes, typeConfig, validations, localize = true, omitShared }) => ({
|
|
126
|
+
const fieldBlockTabs = ({ conditionTypes, typeConfig, validations, localize = true, omitShared, advancedConfig }) => ({
|
|
128
127
|
type: "tabs",
|
|
129
128
|
tabs: [
|
|
130
129
|
{
|
|
@@ -137,11 +136,16 @@ const fieldBlockTabs = ({ conditionTypes, typeConfig, validations, localize = tr
|
|
|
137
136
|
},
|
|
138
137
|
{
|
|
139
138
|
label: labelFor(keys.tabAdvanced),
|
|
140
|
-
fields: [
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
139
|
+
fields: [
|
|
140
|
+
conditionField("visibleWhen", keys.configVisibleWhen, conditionTypes),
|
|
141
|
+
{
|
|
142
|
+
name: "hidden",
|
|
143
|
+
type: "checkbox",
|
|
144
|
+
label: labelFor(keys.configHidden),
|
|
145
|
+
admin: { description: labelFor(keys.configHiddenDescription) }
|
|
146
|
+
},
|
|
147
|
+
...advancedConfig ?? []
|
|
148
|
+
]
|
|
145
149
|
}
|
|
146
150
|
]
|
|
147
151
|
});
|