@10x-media/form-builder 0.1.0-beta.0 → 0.1.0-beta.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 +68 -0
- package/README.md +45 -1402
- package/dist/actions/buildActionBlocks.js +19 -0
- package/dist/actions/buildActionBlocks.js.map +1 -0
- package/dist/actions/builtin/confirmation.js +49 -0
- package/dist/actions/builtin/confirmation.js.map +1 -0
- package/dist/actions/builtin/emailTeam.js +46 -0
- package/dist/actions/builtin/emailTeam.js.map +1 -0
- package/dist/actions/builtin/index.d.ts +7 -0
- package/dist/actions/builtin/index.js +13 -0
- package/dist/actions/builtin/index.js.map +1 -0
- package/dist/actions/builtin/signedWebhook.js +49 -0
- package/dist/actions/builtin/signedWebhook.js.map +1 -0
- package/dist/actions/defineAction.d.ts +36 -0
- package/dist/actions/defineAction.js +6 -0
- package/dist/actions/defineAction.js.map +1 -0
- package/dist/actions/dispatch.js +48 -0
- package/dist/actions/dispatch.js.map +1 -0
- package/dist/actions/registry.d.ts +16 -0
- package/dist/actions/registry.js +16 -0
- package/dist/actions/registry.js.map +1 -0
- package/dist/actions/runActions.d.ts +9 -0
- package/dist/actions/runActions.js +34 -0
- package/dist/actions/runActions.js.map +1 -0
- package/dist/actions/sign.d.ts +7 -0
- package/dist/actions/sign.js +9 -0
- package/dist/actions/sign.js.map +1 -0
- package/dist/actions/task.js +82 -0
- package/dist/actions/task.js.map +1 -0
- package/dist/aggregation/aggregateResponses.d.ts +31 -0
- package/dist/aggregation/aggregateResponses.js +86 -0
- package/dist/aggregation/aggregateResponses.js.map +1 -0
- package/dist/aggregation/aggregateRows.d.ts +10 -0
- package/dist/aggregation/aggregateRows.js +64 -0
- package/dist/aggregation/aggregateRows.js.map +1 -0
- package/dist/aggregation/resolveResultsRequest.d.ts +32 -0
- package/dist/aggregation/resolveResultsRequest.js +56 -0
- package/dist/aggregation/resolveResultsRequest.js.map +1 -0
- package/dist/aggregation/types.d.ts +39 -0
- package/dist/calc/computeCalcFields.d.ts +15 -0
- package/dist/calc/computeCalcFields.js +27 -0
- package/dist/calc/computeCalcFields.js.map +1 -0
- package/dist/calc/evaluate.d.ts +8 -0
- package/dist/calc/evaluate.js +59 -0
- package/dist/calc/evaluate.js.map +1 -0
- package/dist/calc/normalizeCalc.d.ts +8 -0
- package/dist/calc/normalizeCalc.js +100 -0
- package/dist/calc/normalizeCalc.js.map +1 -0
- package/dist/calc/types.d.ts +28 -0
- package/dist/client/ConditionBuilder.js +121 -0
- package/dist/client/ConditionBuilder.js.map +1 -0
- package/dist/client/ConditionRow.js +150 -0
- package/dist/client/ConditionRow.js.map +1 -0
- package/dist/client/FlowBuilder.d.ts +15 -0
- package/dist/client/FlowBuilder.js +408 -0
- package/dist/client/FlowBuilder.js.map +1 -0
- package/dist/client/FormConditionField.d.ts +21 -0
- package/dist/client/FormConditionField.js +33 -0
- package/dist/client/FormConditionField.js.map +1 -0
- package/dist/client/synthesizeClientField.js +46 -0
- package/dist/client/synthesizeClientField.js.map +1 -0
- package/dist/collections/formSubmissions.js +157 -0
- package/dist/collections/formSubmissions.js.map +1 -0
- package/dist/collections/forms.js +198 -0
- package/dist/collections/forms.js.map +1 -0
- package/dist/collections/uploads.d.ts +30 -0
- package/dist/collections/uploads.js +55 -0
- package/dist/collections/uploads.js.map +1 -0
- package/dist/conditions/conditionType.js +14 -0
- package/dist/conditions/conditionType.js.map +1 -0
- package/dist/conditions/evaluate.d.ts +17 -0
- package/dist/conditions/evaluate.js +94 -0
- package/dist/conditions/evaluate.js.map +1 -0
- package/dist/conditions/fieldTypes.d.ts +9 -0
- package/dist/{fieldTypes-CzhhJXjg.js → conditions/fieldTypes.js} +2 -2
- package/dist/conditions/fieldTypes.js.map +1 -0
- package/dist/conditions/normalizeConditions.js +47 -0
- package/dist/conditions/normalizeConditions.js.map +1 -0
- package/dist/conditions/types.d.ts +8 -0
- package/dist/consent/buildConsentSourceConfig.js +49 -0
- package/dist/consent/buildConsentSourceConfig.js.map +1 -0
- package/dist/consent/builtin/index.d.ts +7 -0
- package/dist/consent/builtin/index.js +11 -0
- package/dist/consent/builtin/index.js.map +1 -0
- package/dist/consent/builtin/pageReference.js +75 -0
- package/dist/consent/builtin/pageReference.js.map +1 -0
- package/dist/consent/builtin/static.js +44 -0
- package/dist/consent/builtin/static.js.map +1 -0
- package/dist/consent/captureConsent.d.ts +28 -0
- package/dist/consent/captureConsent.js +26 -0
- package/dist/consent/captureConsent.js.map +1 -0
- package/dist/consent/defineConsentSource.d.ts +35 -0
- package/dist/consent/defineConsentSource.js +6 -0
- package/dist/consent/defineConsentSource.js.map +1 -0
- package/dist/consent/registry.d.ts +16 -0
- package/dist/consent/registry.js +16 -0
- package/dist/consent/registry.js.map +1 -0
- package/dist/consent/resolveConsentLinks.d.ts +19 -0
- package/dist/consent/resolveConsentLinks.js +26 -0
- package/dist/consent/resolveConsentLinks.js.map +1 -0
- package/dist/consent/resolvePublishedVersionRef.d.ts +17 -0
- package/dist/consent/resolvePublishedVersionRef.js +27 -0
- package/dist/consent/resolvePublishedVersionRef.js.map +1 -0
- package/dist/events/noopSink.js +6 -0
- package/dist/events/noopSink.js.map +1 -0
- package/dist/events/resolveEventSink.js +8 -0
- package/dist/events/resolveEventSink.js.map +1 -0
- package/dist/events/types.d.ts +31 -0
- package/dist/exports/client.d.ts +3 -21
- package/dist/exports/client.js +3 -319
- package/dist/exports/i18n.d.ts +3 -138
- package/dist/exports/i18n.js +2 -2
- package/dist/exports/react.d.ts +45 -550
- package/dist/exports/react.js +39 -1563
- package/dist/exports/rsc.d.ts +2 -16
- package/dist/exports/rsc.js +1 -54
- package/dist/exports/types.d.ts +28 -5
- package/dist/fields/buildFieldBlocks.js +60 -0
- package/dist/fields/buildFieldBlocks.js.map +1 -0
- package/dist/fields/builtin/calculation.js +24 -0
- package/dist/fields/builtin/calculation.js.map +1 -0
- package/dist/fields/builtin/checkbox.js +13 -0
- package/dist/fields/builtin/checkbox.js.map +1 -0
- package/dist/fields/builtin/consent.js +32 -0
- package/dist/fields/builtin/consent.js.map +1 -0
- package/dist/fields/builtin/email.js +18 -0
- package/dist/fields/builtin/email.js.map +1 -0
- package/dist/fields/builtin/file.js +40 -0
- package/dist/fields/builtin/file.js.map +1 -0
- package/dist/fields/builtin/index.js +27 -0
- package/dist/fields/builtin/index.js.map +1 -0
- package/dist/fields/builtin/number.js +17 -0
- package/dist/fields/builtin/number.js.map +1 -0
- package/dist/fields/builtin/repeater.js +44 -0
- package/dist/fields/builtin/repeater.js.map +1 -0
- package/dist/fields/builtin/select.js +44 -0
- package/dist/fields/builtin/select.js.map +1 -0
- package/dist/fields/builtin/text.js +13 -0
- package/dist/fields/builtin/text.js.map +1 -0
- package/dist/fields/builtin/textarea.js +13 -0
- package/dist/fields/builtin/textarea.js.map +1 -0
- package/dist/fields/defineFormField.d.ts +13 -0
- package/dist/fields/defineFormField.js +12 -0
- package/dist/fields/defineFormField.js.map +1 -0
- package/dist/fields/registry.d.ts +10 -0
- package/dist/fields/registry.js +24 -0
- package/dist/fields/registry.js.map +1 -0
- package/dist/fields/sharedConfig.js +89 -0
- package/dist/fields/sharedConfig.js.map +1 -0
- package/dist/fields/types.d.ts +89 -0
- package/dist/flow/engine.d.ts +17 -0
- package/dist/flow/engine.js +24 -0
- package/dist/flow/engine.js.map +1 -0
- package/dist/flow/normalizeFlow.js +35 -0
- package/dist/flow/normalizeFlow.js.map +1 -0
- package/dist/{types-DsJ_6kGJ.d.ts → flow/types.d.ts} +2 -2
- package/dist/index.d.ts +93 -4
- package/dist/index.js +43 -1890
- package/dist/index.js.map +1 -1
- package/dist/plugin/access.js +12 -0
- package/dist/plugin/access.js.map +1 -0
- package/dist/plugin/collectionOverrides.d.ts +22 -0
- package/dist/plugin/registerCollections.js +68 -0
- package/dist/plugin/registerCollections.js.map +1 -0
- package/dist/plugin/registerTranslations.js +19 -0
- package/dist/plugin/registerTranslations.js.map +1 -0
- package/dist/prefill/valuesFromSearchParams.d.ts +18 -0
- package/dist/prefill/valuesFromSearchParams.js +45 -0
- package/dist/prefill/valuesFromSearchParams.js.map +1 -0
- package/dist/presentations/defaults.d.ts +33 -0
- package/dist/presentations/defaults.js +35 -0
- package/dist/presentations/defaults.js.map +1 -0
- package/dist/presentations/registry.d.ts +15 -0
- package/dist/presentations/registry.js +15 -0
- package/dist/presentations/registry.js.map +1 -0
- package/dist/presentations/types.d.ts +18 -0
- package/dist/react/Form.d.ts +110 -0
- package/dist/react/Form.js +499 -0
- package/dist/react/Form.js.map +1 -0
- package/dist/react/FormContext.d.ts +16 -0
- package/dist/react/FormContext.js +14 -0
- package/dist/react/FormContext.js.map +1 -0
- package/dist/react/FormLayout.d.ts +20 -0
- package/dist/react/FormLayout.js +14 -0
- package/dist/react/FormLayout.js.map +1 -0
- package/dist/react/FormResults.d.ts +25 -0
- package/dist/react/FormResults.js +85 -0
- package/dist/react/FormResults.js.map +1 -0
- package/dist/react/Honeypot.d.ts +22 -0
- package/dist/react/Honeypot.js +38 -0
- package/dist/react/Honeypot.js.map +1 -0
- package/dist/react/Poll.d.ts +32 -0
- package/dist/react/Poll.js +77 -0
- package/dist/react/Poll.js.map +1 -0
- package/dist/react/cn.d.ts +6 -0
- package/dist/react/cn.js +8 -0
- package/dist/react/cn.js.map +1 -0
- package/dist/react/contract.d.ts +32 -0
- package/dist/react/contract.js +7 -0
- package/dist/react/contract.js.map +1 -0
- package/dist/react/events.js +14 -0
- package/dist/react/events.js.map +1 -0
- package/dist/react/fetchResults.d.ts +25 -0
- package/dist/react/fetchResults.js +31 -0
- package/dist/react/fetchResults.js.map +1 -0
- package/dist/react/presentation/Backdrop.d.ts +18 -0
- package/dist/react/presentation/Backdrop.js +14 -0
- package/dist/react/presentation/Backdrop.js.map +1 -0
- package/dist/react/presentation/DialogSurface.d.ts +35 -0
- package/dist/react/presentation/DialogSurface.js +56 -0
- package/dist/react/presentation/DialogSurface.js.map +1 -0
- package/dist/react/presentation/presentations.d.ts +7 -0
- package/dist/react/presentation/presentations.js +32 -0
- package/dist/react/presentation/presentations.js.map +1 -0
- package/dist/react/presentation/registry.d.ts +11 -0
- package/dist/react/presentation/registry.js +12 -0
- package/dist/react/presentation/registry.js.map +1 -0
- package/dist/react/presentation/types.d.ts +19 -0
- package/dist/react/presentation/useDismiss.d.ts +19 -0
- package/dist/react/presentation/useDismiss.js +33 -0
- package/dist/react/presentation/useDismiss.js.map +1 -0
- package/dist/react/presentation/useFocusTrap.d.ts +8 -0
- package/dist/react/presentation/useFocusTrap.js +35 -0
- package/dist/react/presentation/useFocusTrap.js.map +1 -0
- package/dist/react/presentation/useScrollLock.d.ts +6 -0
- package/dist/react/presentation/useScrollLock.js +18 -0
- package/dist/react/presentation/useScrollLock.js.map +1 -0
- package/dist/react/primitives/Checkbox.d.ts +26 -0
- package/dist/react/primitives/Checkbox.js +20 -0
- package/dist/react/primitives/Checkbox.js.map +1 -0
- package/dist/react/primitives/FieldShell.d.ts +31 -0
- package/dist/react/primitives/FieldShell.js +51 -0
- package/dist/react/primitives/FieldShell.js.map +1 -0
- package/dist/react/primitives/Input.d.ts +30 -0
- package/dist/react/primitives/Input.js +21 -0
- package/dist/react/primitives/Input.js.map +1 -0
- package/dist/react/primitives/Select.d.ts +34 -0
- package/dist/react/primitives/Select.js +26 -0
- package/dist/react/primitives/Select.js.map +1 -0
- package/dist/react/primitives/Textarea.d.ts +28 -0
- package/dist/react/primitives/Textarea.js +20 -0
- package/dist/react/primitives/Textarea.js.map +1 -0
- package/dist/react/recall.js +20 -0
- package/dist/react/recall.js.map +1 -0
- package/dist/react/registry.d.ts +16 -0
- package/dist/react/registry.js +16 -0
- package/dist/react/registry.js.map +1 -0
- package/dist/react/renderers/calculation.js +30 -0
- package/dist/react/renderers/calculation.js.map +1 -0
- package/dist/react/renderers/checkbox.js +35 -0
- package/dist/react/renderers/checkbox.js.map +1 -0
- package/dist/react/renderers/consent.js +54 -0
- package/dist/react/renderers/consent.js.map +1 -0
- package/dist/react/renderers/email.js +37 -0
- package/dist/react/renderers/email.js.map +1 -0
- package/dist/react/renderers/file.js +92 -0
- package/dist/react/renderers/file.js.map +1 -0
- package/dist/react/renderers/index.d.ts +8 -0
- package/dist/react/renderers/index.js +28 -0
- package/dist/react/renderers/index.js.map +1 -0
- package/dist/react/renderers/number.js +40 -0
- package/dist/react/renderers/number.js.map +1 -0
- package/dist/react/renderers/repeater.js +113 -0
- package/dist/react/renderers/repeater.js.map +1 -0
- package/dist/react/renderers/select.js +38 -0
- package/dist/react/renderers/select.js.map +1 -0
- package/dist/react/renderers/text.js +37 -0
- package/dist/react/renderers/text.js.map +1 -0
- package/dist/react/renderers/textarea.js +36 -0
- package/dist/react/renderers/textarea.js.map +1 -0
- package/dist/react/resolveForm.js +16 -0
- package/dist/react/resolveForm.js.map +1 -0
- package/dist/react/state.d.ts +15 -0
- package/dist/react/state.js +70 -0
- package/dist/react/state.js.map +1 -0
- package/dist/react/submitForm.d.ts +31 -0
- package/dist/react/submitForm.js +58 -0
- package/dist/react/submitForm.js.map +1 -0
- package/dist/react/toFormDocument.d.ts +24 -0
- package/dist/react/toFormDocument.js +22 -0
- package/dist/react/toFormDocument.js.map +1 -0
- package/dist/react/uploadFile.d.ts +23 -0
- package/dist/react/uploadFile.js +39 -0
- package/dist/react/uploadFile.js.map +1 -0
- package/dist/react/useField.d.ts +14 -0
- package/dist/react/useField.js +49 -0
- package/dist/react/useField.js.map +1 -0
- package/dist/react/useFormState.d.ts +8 -0
- package/dist/react/useFormState.js +9 -0
- package/dist/react/useFormState.js.map +1 -0
- package/dist/react/useFormStep.d.ts +8 -0
- package/dist/react/useFormStep.js +9 -0
- package/dist/react/useFormStep.js.map +1 -0
- package/dist/react/validateField.js +30 -0
- package/dist/react/validateField.js.map +1 -0
- package/dist/recall/interpolate.d.ts +10 -0
- package/dist/recall/interpolate.js +16 -0
- package/dist/recall/interpolate.js.map +1 -0
- package/dist/recall/resolver.d.ts +22 -0
- package/dist/recall/resolver.js +36 -0
- package/dist/recall/resolver.js.map +1 -0
- package/dist/spam/captcha.d.ts +12 -0
- package/dist/spam/captcha.js +11 -0
- package/dist/spam/captcha.js.map +1 -0
- package/dist/spam/constants.d.ts +12 -0
- package/dist/spam/constants.js +15 -0
- package/dist/spam/constants.js.map +1 -0
- package/dist/spam/identify.d.ts +12 -0
- package/dist/spam/identify.js +20 -0
- package/dist/spam/identify.js.map +1 -0
- package/dist/spam/rateLimiter.d.ts +18 -0
- package/dist/spam/rateLimiter.js +41 -0
- package/dist/spam/rateLimiter.js.map +1 -0
- package/dist/spam/reserved.js +30 -0
- package/dist/spam/reserved.js.map +1 -0
- package/dist/spam/resolveSpam.d.ts +12 -0
- package/dist/spam/resolveSpam.js +42 -0
- package/dist/spam/resolveSpam.js.map +1 -0
- package/dist/spam/spamGuard.js +68 -0
- package/dist/spam/spamGuard.js.map +1 -0
- package/dist/spam/types.d.ts +73 -0
- package/dist/spam/uploadHooks.js +33 -0
- package/dist/spam/uploadHooks.js.map +1 -0
- package/dist/submissions/SubmissionAnswers.d.ts +14 -0
- package/dist/submissions/SubmissionAnswers.js +133 -0
- package/dist/submissions/SubmissionAnswers.js.map +1 -0
- package/dist/submissions/SubmissionAnswersClient.js +142 -0
- package/dist/submissions/SubmissionAnswersClient.js.map +1 -0
- package/dist/submissions/runSubmission.js +257 -0
- package/dist/submissions/runSubmission.js.map +1 -0
- package/dist/submissions/types.d.ts +34 -0
- package/dist/submissions/validateSubmission.js +59 -0
- package/dist/submissions/validateSubmission.js.map +1 -0
- package/dist/translations/en.d.ts +12 -0
- package/dist/{translations-edMqq_2e.js → translations/en.js} +29 -23
- package/dist/translations/en.js.map +1 -0
- package/dist/translations/index.d.ts +14 -0
- package/dist/translations/index.js +26 -0
- package/dist/translations/index.js.map +1 -0
- package/dist/translations/keys.d.ts +157 -0
- package/dist/{keys-N5xGiUsh.js → translations/keys.js} +28 -3
- package/dist/translations/keys.js.map +1 -0
- package/dist/translations/makeTranslate.d.ts +11 -0
- package/dist/translations/makeTranslate.js +11 -0
- package/dist/translations/makeTranslate.js.map +1 -0
- package/dist/translations/server.js +25 -0
- package/dist/translations/server.js.map +1 -0
- package/dist/translations/useTranslation.js +12 -0
- package/dist/translations/useTranslation.js.map +1 -0
- package/dist/uploads/captureFileRef.d.ts +27 -0
- package/dist/uploads/captureFileRef.js +34 -0
- package/dist/uploads/captureFileRef.js.map +1 -0
- package/dist/uploads/resolveFileRef.d.ts +26 -0
- package/dist/uploads/resolveFileRef.js +44 -0
- package/dist/uploads/resolveFileRef.js.map +1 -0
- package/dist/uploads/types.d.ts +20 -0
- package/dist/validation/buildRuleBlocks.js +46 -0
- package/dist/validation/buildRuleBlocks.js.map +1 -0
- package/dist/validation/builtin/email.js +19 -0
- package/dist/validation/builtin/email.js.map +1 -0
- package/dist/validation/builtin/index.js +27 -0
- package/dist/validation/builtin/index.js.map +1 -0
- package/dist/validation/builtin/matchesField.js +20 -0
- package/dist/validation/builtin/matchesField.js.map +1 -0
- package/dist/validation/builtin/max.js +21 -0
- package/dist/validation/builtin/max.js.map +1 -0
- package/dist/validation/builtin/maxLength.js +26 -0
- package/dist/validation/builtin/maxLength.js.map +1 -0
- package/dist/validation/builtin/min.js +21 -0
- package/dist/validation/builtin/min.js.map +1 -0
- package/dist/validation/builtin/minLength.js +26 -0
- package/dist/validation/builtin/minLength.js.map +1 -0
- package/dist/validation/builtin/notAlreadySubmitted.js +32 -0
- package/dist/validation/builtin/notAlreadySubmitted.js.map +1 -0
- package/dist/validation/builtin/oneOf.js +34 -0
- package/dist/validation/builtin/oneOf.js.map +1 -0
- package/dist/validation/builtin/pattern.js +41 -0
- package/dist/validation/builtin/pattern.js.map +1 -0
- package/dist/validation/builtin/url.js +22 -0
- package/dist/validation/builtin/url.js.map +1 -0
- package/dist/validation/defineValidationRule.d.ts +12 -0
- package/dist/validation/defineValidationRule.js +11 -0
- package/dist/validation/defineValidationRule.js.map +1 -0
- package/dist/validation/message.js +14 -0
- package/dist/validation/message.js.map +1 -0
- package/dist/validation/registry.d.ts +10 -0
- package/dist/validation/registry.js +20 -0
- package/dist/validation/registry.js.map +1 -0
- package/dist/validation/runValidation.js +111 -0
- package/dist/validation/runValidation.js.map +1 -0
- package/dist/validation/types.d.ts +76 -0
- package/package.json +8 -5
- package/styles/form-builder.css +201 -11
- package/dist/constants-B-BUfetP.d.ts +0 -288
- package/dist/exports/client.js.map +0 -1
- package/dist/exports/react.js.map +0 -1
- package/dist/exports/rsc.js.map +0 -1
- package/dist/fieldTypes-B8jkNRob.d.ts +0 -188
- package/dist/fieldTypes-CzhhJXjg.js.map +0 -1
- package/dist/index-DfFYGbVF.d.ts +0 -481
- package/dist/keys-N5xGiUsh.js.map +0 -1
- package/dist/registry-CoCyhtvB.js +0 -282
- package/dist/registry-CoCyhtvB.js.map +0 -1
- package/dist/resolver-OeQyVH2N.js +0 -665
- package/dist/resolver-OeQyVH2N.js.map +0 -1
- package/dist/translations-edMqq_2e.js.map +0 -1
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { keys } from "../translations/keys.js";
|
|
3
|
+
import { firstOperatorFor } from "../conditions/fieldTypes.js";
|
|
4
|
+
import { useTranslation as useTranslation$1 } from "../translations/useTranslation.js";
|
|
5
|
+
import { operandFromRow } from "./synthesizeClientField.js";
|
|
6
|
+
import { ConditionRow } from "./ConditionRow.js";
|
|
7
|
+
import { reduceFieldsToValues, transformWhereQuery } from "payload/shared";
|
|
8
|
+
import { Button, useFormFields } from "@payloadcms/ui";
|
|
9
|
+
import { useMemo } from "react";
|
|
10
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
//#region src/client/ConditionBuilder.tsx
|
|
12
|
+
const toRow = (constraint) => {
|
|
13
|
+
const field = Object.keys(constraint)[0];
|
|
14
|
+
if (!field) return null;
|
|
15
|
+
const ops = constraint[field];
|
|
16
|
+
const operator = Object.keys(ops)[0];
|
|
17
|
+
if (!operator) return null;
|
|
18
|
+
return {
|
|
19
|
+
field,
|
|
20
|
+
operator,
|
|
21
|
+
value: ops[operator]
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
const fromRow = (row) => ({ [row.field]: { [row.operator]: row.value } });
|
|
25
|
+
const readGroups = (value) => {
|
|
26
|
+
if (!value || Object.keys(value).length === 0) return [];
|
|
27
|
+
const canonical = transformWhereQuery(value);
|
|
28
|
+
return (Array.isArray(canonical.or) ? canonical.or : []).map((group) => {
|
|
29
|
+
return (Array.isArray(group.and) ? group.and : []).map((constraint) => toRow(constraint)).filter((row) => row !== null);
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
const writeGroups = (groups) => ({ or: groups.filter((group) => group.length > 0).map((group) => ({ and: group.map(fromRow) })) });
|
|
33
|
+
const operandsFromData = (data, conditionTypes, selfName) => {
|
|
34
|
+
return (Array.isArray(data.fields) ? data.fields : []).map((row) => operandFromRow(row, conditionTypes)).filter((operand) => operand !== null && operand.name !== selfName);
|
|
35
|
+
};
|
|
36
|
+
const ConditionBuilder = ({ value, onChange, conditionTypes, selfName }) => {
|
|
37
|
+
const { t } = useTranslation$1();
|
|
38
|
+
const operandsJson = useFormFields(([fields]) => JSON.stringify(operandsFromData(reduceFieldsToValues(fields, true), conditionTypes, selfName)));
|
|
39
|
+
const operands = useMemo(() => JSON.parse(operandsJson), [operandsJson]);
|
|
40
|
+
const groups = readGroups(value);
|
|
41
|
+
const emit = (next) => onChange(writeGroups(next));
|
|
42
|
+
const addCondition = (groupIndex) => {
|
|
43
|
+
const first = operands[0];
|
|
44
|
+
if (!first) return;
|
|
45
|
+
const row = {
|
|
46
|
+
field: first.name,
|
|
47
|
+
operator: firstOperatorFor(first.conditionType),
|
|
48
|
+
value: void 0
|
|
49
|
+
};
|
|
50
|
+
emit(groups.length === 0 ? [[row]] : groups.map((group, index) => index === groupIndex ? [...group, row] : group));
|
|
51
|
+
};
|
|
52
|
+
const addOrGroup = () => {
|
|
53
|
+
const first = operands[0];
|
|
54
|
+
if (!first) return;
|
|
55
|
+
emit([...groups, [{
|
|
56
|
+
field: first.name,
|
|
57
|
+
operator: firstOperatorFor(first.conditionType),
|
|
58
|
+
value: void 0
|
|
59
|
+
}]]);
|
|
60
|
+
};
|
|
61
|
+
const updateRow = (groupIndex, rowIndex, row) => emit(groups.map((group, index) => index === groupIndex ? group.map((existing, position) => position === rowIndex ? row : existing) : group));
|
|
62
|
+
const removeRow = (groupIndex, rowIndex) => emit(groups.map((group, index) => index === groupIndex ? group.filter((_, position) => position !== rowIndex) : group).filter((group) => group.length > 0));
|
|
63
|
+
if (operands.length === 0) return /* @__PURE__ */ jsx("p", {
|
|
64
|
+
className: "fb-condition-builder__hint",
|
|
65
|
+
children: t(keys.conditionNoFields)
|
|
66
|
+
});
|
|
67
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
68
|
+
className: "fb-condition-builder",
|
|
69
|
+
children: [groups.length === 0 ? /* @__PURE__ */ jsx("p", {
|
|
70
|
+
className: "fb-condition-builder__hint",
|
|
71
|
+
children: t(keys.conditionEmpty)
|
|
72
|
+
}) : groups.map((group, groupIndex) => /* @__PURE__ */ jsxs("div", {
|
|
73
|
+
className: "fb-condition-builder__group",
|
|
74
|
+
children: [
|
|
75
|
+
groupIndex > 0 ? /* @__PURE__ */ jsx("div", {
|
|
76
|
+
className: "fb-condition-builder__or-label",
|
|
77
|
+
children: t(keys.conditionOr)
|
|
78
|
+
}) : null,
|
|
79
|
+
group.map((row, rowIndex) => /* @__PURE__ */ jsxs("div", {
|
|
80
|
+
className: "fb-condition-builder__and-row",
|
|
81
|
+
children: [rowIndex > 0 ? /* @__PURE__ */ jsx("span", {
|
|
82
|
+
className: "fb-condition-builder__and-label",
|
|
83
|
+
children: t(keys.conditionAnd)
|
|
84
|
+
}) : null, /* @__PURE__ */ jsx(ConditionRow, {
|
|
85
|
+
condition: row,
|
|
86
|
+
operands,
|
|
87
|
+
onChange: (next) => updateRow(groupIndex, rowIndex, next),
|
|
88
|
+
onRemove: () => removeRow(groupIndex, rowIndex)
|
|
89
|
+
})]
|
|
90
|
+
}, rowIndex)),
|
|
91
|
+
/* @__PURE__ */ jsx("div", {
|
|
92
|
+
className: "fb-condition-builder__add-condition",
|
|
93
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
94
|
+
buttonStyle: "icon-label",
|
|
95
|
+
icon: "plus",
|
|
96
|
+
iconStyle: "with-border",
|
|
97
|
+
iconPosition: "left",
|
|
98
|
+
onClick: () => addCondition(groupIndex),
|
|
99
|
+
margin: false,
|
|
100
|
+
children: t(keys.conditionAddCondition)
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
]
|
|
104
|
+
}, groupIndex)), /* @__PURE__ */ jsx("div", {
|
|
105
|
+
className: "fb-condition-builder__actions",
|
|
106
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
107
|
+
buttonStyle: "icon-label",
|
|
108
|
+
icon: "plus",
|
|
109
|
+
iconStyle: "with-border",
|
|
110
|
+
iconPosition: "left",
|
|
111
|
+
onClick: () => groups.length === 0 ? addCondition(0) : addOrGroup(),
|
|
112
|
+
margin: false,
|
|
113
|
+
children: groups.length === 0 ? t(keys.conditionAddCondition) : t(keys.conditionAddOr)
|
|
114
|
+
})
|
|
115
|
+
})]
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
//#endregion
|
|
119
|
+
export { ConditionBuilder };
|
|
120
|
+
|
|
121
|
+
//# sourceMappingURL=ConditionBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConditionBuilder.js","names":["useTranslation"],"sources":["../../src/client/ConditionBuilder.tsx"],"sourcesContent":["'use client'\n\nimport { Button, useFormFields } from '@payloadcms/ui'\nimport type { Operator, Where } from 'payload'\nimport { reduceFieldsToValues, transformWhereQuery } from 'payload/shared'\nimport { useMemo } from 'react'\nimport { type ConditionFieldType, firstOperatorFor } from '../conditions/fieldTypes'\nimport { keys } from '../translations/keys'\nimport { useTranslation } from '../translations/useTranslation'\nimport { ConditionRow, type RowCondition } from './ConditionRow'\nimport { type ConditionOperand, type FieldRow, operandFromRow } from './synthesizeClientField'\n\nexport type ConditionBuilderProps = {\n\tvalue?: Where\n\tonChange: (next: Where) => void\n\tconditionTypes: Record<string, ConditionFieldType>\n\t/** This field's own machine name, excluded from the operand list (a field cannot condition on itself). */\n\tselfName?: string\n}\n\nconst toRow = (constraint: Record<string, unknown>): RowCondition | null => {\n\tconst field = Object.keys(constraint)[0]\n\tif (!field) {\n\t\treturn null\n\t}\n\tconst ops = constraint[field] as Record<string, unknown>\n\tconst operator = Object.keys(ops)[0] as Operator | undefined\n\tif (!operator) {\n\t\treturn null\n\t}\n\treturn { field, operator, value: ops[operator] }\n}\n\nconst fromRow = (row: RowCondition): Where => ({ [row.field]: { [row.operator]: row.value } })\n\nconst readGroups = (value: Where | undefined): RowCondition[][] => {\n\tif (!value || Object.keys(value).length === 0) {\n\t\treturn []\n\t}\n\tconst canonical = transformWhereQuery(value)\n\tconst or = Array.isArray(canonical.or) ? canonical.or : []\n\treturn or.map((group) => {\n\t\tconst and = Array.isArray((group as Where).and) ? ((group as Where).and as Where[]) : []\n\t\treturn and\n\t\t\t.map((constraint) => toRow(constraint as Record<string, unknown>))\n\t\t\t.filter((row): row is RowCondition => row !== null)\n\t})\n}\n\nconst writeGroups = (groups: RowCondition[][]): Where => ({\n\tor: groups.filter((group) => group.length > 0).map((group) => ({ and: group.map(fromRow) })),\n})\n\nconst operandsFromData = (\n\tdata: Record<string, unknown>,\n\tconditionTypes: Record<string, ConditionFieldType>,\n\tselfName: string | undefined\n): ConditionOperand[] => {\n\tconst rows = Array.isArray(data.fields) ? (data.fields as FieldRow[]) : []\n\treturn rows\n\t\t.map((row) => operandFromRow(row, conditionTypes))\n\t\t.filter((operand): operand is ConditionOperand => operand !== null && operand.name !== selfName)\n}\n\nexport const ConditionBuilder = ({\n\tvalue,\n\tonChange,\n\tconditionTypes,\n\tselfName,\n}: ConditionBuilderProps) => {\n\tconst { t } = useTranslation()\n\t// Serialize the operand list so the builder re-renders only when operands actually change (a field\n\t// added, renamed, retyped, or its options edited), not on every unrelated form-state update.\n\tconst operandsJson = useFormFields(([fields]) =>\n\t\tJSON.stringify(operandsFromData(reduceFieldsToValues(fields, true), conditionTypes, selfName))\n\t)\n\tconst operands = useMemo(() => JSON.parse(operandsJson) as ConditionOperand[], [operandsJson])\n\n\tconst groups = readGroups(value)\n\tconst emit = (next: RowCondition[][]) => onChange(writeGroups(next))\n\n\tconst addCondition = (groupIndex: number) => {\n\t\tconst first = operands[0]\n\t\tif (!first) {\n\t\t\treturn\n\t\t}\n\t\tconst row: RowCondition = {\n\t\t\tfield: first.name,\n\t\t\toperator: firstOperatorFor(first.conditionType),\n\t\t\tvalue: undefined,\n\t\t}\n\t\temit(\n\t\t\tgroups.length === 0\n\t\t\t\t? [[row]]\n\t\t\t\t: groups.map((group, index) => (index === groupIndex ? [...group, row] : group))\n\t\t)\n\t}\n\n\tconst addOrGroup = () => {\n\t\tconst first = operands[0]\n\t\tif (!first) {\n\t\t\treturn\n\t\t}\n\t\temit([\n\t\t\t...groups,\n\t\t\t[{ field: first.name, operator: firstOperatorFor(first.conditionType), value: undefined }],\n\t\t])\n\t}\n\n\tconst updateRow = (groupIndex: number, rowIndex: number, row: RowCondition) =>\n\t\temit(\n\t\t\tgroups.map((group, index) =>\n\t\t\t\tindex === groupIndex\n\t\t\t\t\t? group.map((existing, position) => (position === rowIndex ? row : existing))\n\t\t\t\t\t: group\n\t\t\t)\n\t\t)\n\n\tconst removeRow = (groupIndex: number, rowIndex: number) =>\n\t\temit(\n\t\t\tgroups\n\t\t\t\t.map((group, index) =>\n\t\t\t\t\tindex === groupIndex ? group.filter((_, position) => position !== rowIndex) : group\n\t\t\t\t)\n\t\t\t\t.filter((group) => group.length > 0)\n\t\t)\n\n\tif (operands.length === 0) {\n\t\treturn <p className=\"fb-condition-builder__hint\">{t(keys.conditionNoFields)}</p>\n\t}\n\n\treturn (\n\t\t<div className=\"fb-condition-builder\">\n\t\t\t{groups.length === 0 ? (\n\t\t\t\t<p className=\"fb-condition-builder__hint\">{t(keys.conditionEmpty)}</p>\n\t\t\t) : (\n\t\t\t\tgroups.map((group, groupIndex) => (\n\t\t\t\t\t// biome-ignore lint/suspicious/noArrayIndexKey: groups are positional and never reordered\n\t\t\t\t\t<div key={groupIndex} className=\"fb-condition-builder__group\">\n\t\t\t\t\t\t{groupIndex > 0 ? (\n\t\t\t\t\t\t\t<div className=\"fb-condition-builder__or-label\">{t(keys.conditionOr)}</div>\n\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t{group.map((row, rowIndex) => (\n\t\t\t\t\t\t\t// biome-ignore lint/suspicious/noArrayIndexKey: rows are positional and never reordered\n\t\t\t\t\t\t\t<div key={rowIndex} className=\"fb-condition-builder__and-row\">\n\t\t\t\t\t\t\t\t{rowIndex > 0 ? (\n\t\t\t\t\t\t\t\t\t<span className=\"fb-condition-builder__and-label\">{t(keys.conditionAnd)}</span>\n\t\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t\t\t<ConditionRow\n\t\t\t\t\t\t\t\t\tcondition={row}\n\t\t\t\t\t\t\t\t\toperands={operands}\n\t\t\t\t\t\t\t\t\tonChange={(next) => updateRow(groupIndex, rowIndex, next)}\n\t\t\t\t\t\t\t\t\tonRemove={() => removeRow(groupIndex, rowIndex)}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t))}\n\t\t\t\t\t\t<div className=\"fb-condition-builder__add-condition\">\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\tbuttonStyle=\"icon-label\"\n\t\t\t\t\t\t\t\ticon=\"plus\"\n\t\t\t\t\t\t\t\ticonStyle=\"with-border\"\n\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\tonClick={() => addCondition(groupIndex)}\n\t\t\t\t\t\t\t\tmargin={false}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{t(keys.conditionAddCondition)}\n\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t))\n\t\t\t)}\n\t\t\t<div className=\"fb-condition-builder__actions\">\n\t\t\t\t<Button\n\t\t\t\t\tbuttonStyle=\"icon-label\"\n\t\t\t\t\ticon=\"plus\"\n\t\t\t\t\ticonStyle=\"with-border\"\n\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\tonClick={() => (groups.length === 0 ? addCondition(0) : addOrGroup())}\n\t\t\t\t\tmargin={false}\n\t\t\t\t>\n\t\t\t\t\t{groups.length === 0 ? t(keys.conditionAddCondition) : t(keys.conditionAddOr)}\n\t\t\t\t</Button>\n\t\t\t</div>\n\t\t</div>\n\t)\n}\n"],"mappings":";;;;;;;;;;;AAoBA,MAAM,SAAS,eAA6D;CAC3E,MAAM,QAAQ,OAAO,KAAK,UAAU,EAAE;CACtC,IAAI,CAAC,OACJ,OAAO;CAER,MAAM,MAAM,WAAW;CACvB,MAAM,WAAW,OAAO,KAAK,GAAG,EAAE;CAClC,IAAI,CAAC,UACJ,OAAO;CAER,OAAO;EAAE;EAAO;EAAU,OAAO,IAAI;CAAU;AAChD;AAEA,MAAM,WAAW,SAA8B,GAAG,IAAI,QAAQ,GAAG,IAAI,WAAW,IAAI,MAAM,EAAE;AAE5F,MAAM,cAAc,UAA+C;CAClE,IAAI,CAAC,SAAS,OAAO,KAAK,KAAK,EAAE,WAAW,GAC3C,OAAO,CAAC;CAET,MAAM,YAAY,oBAAoB,KAAK;CAE3C,QADW,MAAM,QAAQ,UAAU,EAAE,IAAI,UAAU,KAAK,CAAC,GAC/C,KAAK,UAAU;EAExB,QADY,MAAM,QAAS,MAAgB,GAAG,IAAM,MAAgB,MAAkB,CAAC,GAErF,KAAK,eAAe,MAAM,UAAqC,CAAC,EAChE,QAAQ,QAA6B,QAAQ,IAAI;CACpD,CAAC;AACF;AAEA,MAAM,eAAe,YAAqC,EACzD,IAAI,OAAO,QAAQ,UAAU,MAAM,SAAS,CAAC,E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QAAQ;cAEP,OAAO,WAAW,IAAI,EAAE,KAAK,qBAAqB,IAAI,EAAE,KAAK,cAAc;GACrE,CAAA;EACJ,CAAA,CACD;;AAEP"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { keys } from "../translations/keys.js";
|
|
3
|
+
import { conditionOperators, firstOperatorFor, operatorLabelKey, operatorValueShape } from "../conditions/fieldTypes.js";
|
|
4
|
+
import { useTranslation as useTranslation$1 } from "../translations/useTranslation.js";
|
|
5
|
+
import { dateClientField, numberClientField, selectClientField, textClientField } from "./synthesizeClientField.js";
|
|
6
|
+
import { Button, DateCondition, NumberCondition, ReactSelect, SelectCondition, TextCondition } from "@payloadcms/ui";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
//#region src/client/ConditionRow.tsx
|
|
9
|
+
/** ReactSelect's `onChange` hands back `Option | Option[]`; narrow it to the single chosen option. */
|
|
10
|
+
const singleOption = (selected) => Array.isArray(selected) ? selected[0] : selected;
|
|
11
|
+
const ConditionRow = ({ condition, operands, onChange, onRemove }) => {
|
|
12
|
+
const { t, i18n } = useTranslation$1();
|
|
13
|
+
const operand = operands.find((entry) => entry.name === condition.field);
|
|
14
|
+
const conditionType = operand?.conditionType ?? "text";
|
|
15
|
+
const operators = conditionOperators[conditionType];
|
|
16
|
+
const fieldOptions = operands.map((entry) => ({
|
|
17
|
+
label: entry.label,
|
|
18
|
+
value: entry.name
|
|
19
|
+
}));
|
|
20
|
+
const operatorOptions = operators.map((operator) => ({
|
|
21
|
+
label: i18n.t(operatorLabelKey(operator)),
|
|
22
|
+
value: operator
|
|
23
|
+
}));
|
|
24
|
+
const handleFieldChange = (selected) => {
|
|
25
|
+
const chosen = singleOption(selected);
|
|
26
|
+
const next = operands.find((entry) => entry.name === chosen?.value);
|
|
27
|
+
if (!next) return;
|
|
28
|
+
onChange({
|
|
29
|
+
field: next.name,
|
|
30
|
+
operator: firstOperatorFor(next.conditionType),
|
|
31
|
+
value: void 0
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
const handleOperatorChange = (selected) => {
|
|
35
|
+
const chosen = singleOption(selected);
|
|
36
|
+
if (!chosen) return;
|
|
37
|
+
const operator = chosen.value;
|
|
38
|
+
const keepValue = operatorValueShape(condition.operator) === operatorValueShape(operator);
|
|
39
|
+
onChange({
|
|
40
|
+
...condition,
|
|
41
|
+
operator,
|
|
42
|
+
value: keepValue ? condition.value : void 0
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
46
|
+
className: "fb-condition-row",
|
|
47
|
+
children: [
|
|
48
|
+
/* @__PURE__ */ jsx("div", {
|
|
49
|
+
className: "fb-condition-row__field",
|
|
50
|
+
children: /* @__PURE__ */ jsx(ReactSelect, {
|
|
51
|
+
options: fieldOptions,
|
|
52
|
+
value: fieldOptions.find((option) => option.value === condition.field),
|
|
53
|
+
placeholder: t(keys.conditionSelectField),
|
|
54
|
+
isClearable: false,
|
|
55
|
+
onChange: handleFieldChange
|
|
56
|
+
})
|
|
57
|
+
}),
|
|
58
|
+
/* @__PURE__ */ jsx("div", {
|
|
59
|
+
className: "fb-condition-row__operator",
|
|
60
|
+
children: /* @__PURE__ */ jsx(ReactSelect, {
|
|
61
|
+
options: operatorOptions,
|
|
62
|
+
value: operatorOptions.find((option) => option.value === condition.operator),
|
|
63
|
+
disabled: !operand,
|
|
64
|
+
isClearable: false,
|
|
65
|
+
onChange: handleOperatorChange
|
|
66
|
+
})
|
|
67
|
+
}),
|
|
68
|
+
/* @__PURE__ */ jsx("div", {
|
|
69
|
+
className: "fb-condition-row__value",
|
|
70
|
+
children: /* @__PURE__ */ jsx(ConditionValue, {
|
|
71
|
+
conditionType,
|
|
72
|
+
operand,
|
|
73
|
+
operator: condition.operator,
|
|
74
|
+
value: condition.value,
|
|
75
|
+
onChange: (value) => onChange({
|
|
76
|
+
...condition,
|
|
77
|
+
value
|
|
78
|
+
})
|
|
79
|
+
})
|
|
80
|
+
}),
|
|
81
|
+
/* @__PURE__ */ jsx("div", {
|
|
82
|
+
className: "fb-condition-row__remove",
|
|
83
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
84
|
+
buttonStyle: "icon-label",
|
|
85
|
+
icon: "x",
|
|
86
|
+
onClick: onRemove,
|
|
87
|
+
"aria-label": t(keys.conditionRemove),
|
|
88
|
+
margin: false
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
]
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
const ConditionValue = ({ conditionType, operand, operator, value, onChange }) => {
|
|
95
|
+
const { t } = useTranslation$1();
|
|
96
|
+
if (conditionType === "checkbox" || operatorValueShape(operator) === "boolean") {
|
|
97
|
+
const options = [{
|
|
98
|
+
label: t(keys.conditionTrue),
|
|
99
|
+
value: "true"
|
|
100
|
+
}, {
|
|
101
|
+
label: t(keys.conditionFalse),
|
|
102
|
+
value: "false"
|
|
103
|
+
}];
|
|
104
|
+
const handleBooleanChange = (selected) => {
|
|
105
|
+
onChange(singleOption(selected)?.value === "true");
|
|
106
|
+
};
|
|
107
|
+
return /* @__PURE__ */ jsx(ReactSelect, {
|
|
108
|
+
options,
|
|
109
|
+
value: options.find((option) => String(option.value) === String(value)) ?? options[0],
|
|
110
|
+
isClearable: false,
|
|
111
|
+
onChange: handleBooleanChange
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
if (!operand) return null;
|
|
115
|
+
switch (conditionType) {
|
|
116
|
+
case "number": return /* @__PURE__ */ jsx(NumberCondition, {
|
|
117
|
+
disabled: false,
|
|
118
|
+
field: numberClientField(operand),
|
|
119
|
+
operator,
|
|
120
|
+
value,
|
|
121
|
+
onChange: (next) => onChange(next)
|
|
122
|
+
});
|
|
123
|
+
case "date": return /* @__PURE__ */ jsx(DateCondition, {
|
|
124
|
+
disabled: false,
|
|
125
|
+
field: dateClientField(operand),
|
|
126
|
+
operator,
|
|
127
|
+
value,
|
|
128
|
+
onChange: (next) => onChange(next)
|
|
129
|
+
});
|
|
130
|
+
case "select": return /* @__PURE__ */ jsx(SelectCondition, {
|
|
131
|
+
disabled: false,
|
|
132
|
+
field: selectClientField(operand),
|
|
133
|
+
operator,
|
|
134
|
+
options: operand.options ?? [],
|
|
135
|
+
value,
|
|
136
|
+
onChange: (next) => onChange(next)
|
|
137
|
+
});
|
|
138
|
+
default: return /* @__PURE__ */ jsx(TextCondition, {
|
|
139
|
+
disabled: false,
|
|
140
|
+
field: textClientField(operand),
|
|
141
|
+
operator,
|
|
142
|
+
value,
|
|
143
|
+
onChange: (next) => onChange(next)
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
//#endregion
|
|
148
|
+
export { ConditionRow };
|
|
149
|
+
|
|
150
|
+
//# sourceMappingURL=ConditionRow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConditionRow.js","names":["useTranslation"],"sources":["../../src/client/ConditionRow.tsx"],"sourcesContent":["'use client'\n\nimport {\n\tButton,\n\tDateCondition,\n\tNumberCondition,\n\tReactSelect,\n\ttype ReactSelectOption,\n\tSelectCondition,\n\tTextCondition,\n} from '@payloadcms/ui'\nimport type { Operator } from 'payload'\nimport {\n\tconditionOperators,\n\tfirstOperatorFor,\n\toperatorLabelKey,\n\toperatorValueShape,\n} from '../conditions/fieldTypes'\nimport { keys } from '../translations/keys'\nimport { useTranslation } from '../translations/useTranslation'\nimport {\n\ttype ConditionOperand,\n\tdateClientField,\n\tnumberClientField,\n\tselectClientField,\n\ttextClientField,\n} from './synthesizeClientField'\n\nexport type RowCondition = { field: string; operator: Operator; value: unknown }\n\nexport type ConditionRowProps = {\n\tcondition: RowCondition\n\toperands: ConditionOperand[]\n\tonChange: (next: RowCondition) => void\n\tonRemove: () => void\n}\n\n/** ReactSelect's `onChange` hands back `Option | Option[]`; narrow it to the single chosen option. */\nconst singleOption = (\n\tselected: ReactSelectOption | ReactSelectOption[]\n): ReactSelectOption | undefined => (Array.isArray(selected) ? selected[0] : selected)\n\nexport const ConditionRow = ({ condition, operands, onChange, onRemove }: ConditionRowProps) => {\n\tconst { t, i18n } = useTranslation()\n\tconst operand = operands.find((entry) => entry.name === condition.field)\n\tconst conditionType = operand?.conditionType ?? 'text'\n\tconst operators = conditionOperators[conditionType]\n\n\tconst fieldOptions: ReactSelectOption[] = operands.map((entry) => ({\n\t\tlabel: entry.label,\n\t\tvalue: entry.name,\n\t}))\n\tconst operatorOptions: ReactSelectOption[] = operators.map((operator) => ({\n\t\tlabel: i18n.t(operatorLabelKey(operator)),\n\t\tvalue: operator,\n\t}))\n\n\tconst handleFieldChange = (selected: ReactSelectOption | ReactSelectOption[]) => {\n\t\tconst chosen = singleOption(selected)\n\t\tconst next = operands.find((entry) => entry.name === chosen?.value)\n\t\tif (!next) {\n\t\t\treturn\n\t\t}\n\t\tonChange({\n\t\t\tfield: next.name,\n\t\t\toperator: firstOperatorFor(next.conditionType),\n\t\t\tvalue: undefined,\n\t\t})\n\t}\n\n\tconst handleOperatorChange = (selected: ReactSelectOption | ReactSelectOption[]) => {\n\t\tconst chosen = singleOption(selected)\n\t\tif (!chosen) {\n\t\t\treturn\n\t\t}\n\t\tconst operator = chosen.value as Operator\n\t\tconst keepValue = operatorValueShape(condition.operator) === operatorValueShape(operator)\n\t\tonChange({ ...condition, operator, value: keepValue ? condition.value : undefined })\n\t}\n\n\treturn (\n\t\t<div className=\"fb-condition-row\">\n\t\t\t<div className=\"fb-condition-row__field\">\n\t\t\t\t<ReactSelect\n\t\t\t\t\toptions={fieldOptions}\n\t\t\t\t\tvalue={fieldOptions.find((option) => option.value === condition.field)}\n\t\t\t\t\tplaceholder={t(keys.conditionSelectField)}\n\t\t\t\t\tisClearable={false}\n\t\t\t\t\tonChange={handleFieldChange}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t\t<div className=\"fb-condition-row__operator\">\n\t\t\t\t<ReactSelect\n\t\t\t\t\toptions={operatorOptions}\n\t\t\t\t\tvalue={operatorOptions.find((option) => option.value === condition.operator)}\n\t\t\t\t\tdisabled={!operand}\n\t\t\t\t\tisClearable={false}\n\t\t\t\t\tonChange={handleOperatorChange}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t\t<div className=\"fb-condition-row__value\">\n\t\t\t\t<ConditionValue\n\t\t\t\t\tconditionType={conditionType}\n\t\t\t\t\toperand={operand}\n\t\t\t\t\toperator={condition.operator}\n\t\t\t\t\tvalue={condition.value}\n\t\t\t\t\tonChange={(value) => onChange({ ...condition, value })}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t\t<div className=\"fb-condition-row__remove\">\n\t\t\t\t<Button\n\t\t\t\t\tbuttonStyle=\"icon-label\"\n\t\t\t\t\ticon=\"x\"\n\t\t\t\t\tonClick={onRemove}\n\t\t\t\t\taria-label={t(keys.conditionRemove)}\n\t\t\t\t\tmargin={false}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</div>\n\t)\n}\n\ntype ConditionValueProps = {\n\tconditionType: ConditionOperand['conditionType']\n\toperand?: ConditionOperand\n\toperator: Operator\n\tvalue: unknown\n\tonChange: (value: unknown) => void\n}\n\nconst ConditionValue = ({\n\tconditionType,\n\toperand,\n\toperator,\n\tvalue,\n\tonChange,\n}: ConditionValueProps) => {\n\tconst { t } = useTranslation()\n\tif (conditionType === 'checkbox' || operatorValueShape(operator) === 'boolean') {\n\t\tconst options: ReactSelectOption[] = [\n\t\t\t{ label: t(keys.conditionTrue), value: 'true' },\n\t\t\t{ label: t(keys.conditionFalse), value: 'false' },\n\t\t]\n\t\tconst handleBooleanChange = (selected: ReactSelectOption | ReactSelectOption[]) => {\n\t\t\tconst chosen = singleOption(selected)\n\t\t\tonChange(chosen?.value === 'true')\n\t\t}\n\t\treturn (\n\t\t\t<ReactSelect\n\t\t\t\toptions={options}\n\t\t\t\tvalue={options.find((option) => String(option.value) === String(value)) ?? options[0]}\n\t\t\t\tisClearable={false}\n\t\t\t\tonChange={handleBooleanChange}\n\t\t\t/>\n\t\t)\n\t}\n\tif (!operand) {\n\t\treturn null\n\t}\n\tswitch (conditionType) {\n\t\tcase 'number':\n\t\t\treturn (\n\t\t\t\t<NumberCondition\n\t\t\t\t\tdisabled={false}\n\t\t\t\t\tfield={numberClientField(operand)}\n\t\t\t\t\toperator={operator}\n\t\t\t\t\tvalue={value as number | number[]}\n\t\t\t\t\tonChange={(next: string) => onChange(next)}\n\t\t\t\t/>\n\t\t\t)\n\t\tcase 'date':\n\t\t\treturn (\n\t\t\t\t<DateCondition\n\t\t\t\t\tdisabled={false}\n\t\t\t\t\tfield={dateClientField(operand)}\n\t\t\t\t\toperator={operator}\n\t\t\t\t\tvalue={value as Date | string}\n\t\t\t\t\tonChange={(next: Date | string) => onChange(next)}\n\t\t\t\t/>\n\t\t\t)\n\t\tcase 'select':\n\t\t\treturn (\n\t\t\t\t<SelectCondition\n\t\t\t\t\tdisabled={false}\n\t\t\t\t\tfield={selectClientField(operand)}\n\t\t\t\t\toperator={operator}\n\t\t\t\t\toptions={operand.options ?? []}\n\t\t\t\t\tvalue={value as string}\n\t\t\t\t\tonChange={(next: string) => onChange(next)}\n\t\t\t\t/>\n\t\t\t)\n\t\tdefault:\n\t\t\treturn (\n\t\t\t\t<TextCondition\n\t\t\t\t\tdisabled={false}\n\t\t\t\t\tfield={textClientField(operand)}\n\t\t\t\t\toperator={operator}\n\t\t\t\t\tvalue={value as string | string[]}\n\t\t\t\t\tonChange={(next: string) => onChange(next)}\n\t\t\t\t/>\n\t\t\t)\n\t}\n}\n"],"mappings":";;;;;;;;;AAsCA,MAAM,gBACL,aACoC,MAAM,QAAQ,QAAQ,IAAI,SAAS,KAAK;AAE7E,MAAa,gBAAgB,EAAE,WAAW,UAAU,UAAU,eAAkC;CAC/F,MAAM,EAAE,GAAG,SAASA,iBAAe;CACnC,MAAM,UAAU,SAAS,MAAM,UAAU,MAAM,SAAS,UAAU,KAAK;CACvE,MAAM,gBAAgB,SAAS,iBAAiB;CAChD,MAAM,YAAY,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ACP,WAAW,SAAiB,SAAS,IAAI;EACzC,CAAA;CAEJ;AACD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ConditionFieldType } from "../conditions/fieldTypes.js";
|
|
2
|
+
|
|
3
|
+
//#region src/client/FlowBuilder.d.ts
|
|
4
|
+
type FlowBuilderProps = {
|
|
5
|
+
path?: string;
|
|
6
|
+
field?: {
|
|
7
|
+
label?: unknown;
|
|
8
|
+
};
|
|
9
|
+
label?: unknown;
|
|
10
|
+
conditionTypes: Record<string, ConditionFieldType>;
|
|
11
|
+
};
|
|
12
|
+
declare const FlowBuilder: (props: FlowBuilderProps) => import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { FlowBuilder };
|
|
15
|
+
//# sourceMappingURL=FlowBuilder.d.ts.map
|