@verbb/formie-browser 1.0.0
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 +5 -0
- package/LICENSE.md +40 -0
- package/README.md +34 -0
- package/dist/chunks/address-finder-DfMCiW89.js +47 -0
- package/dist/chunks/api-CbqEMQT5.js +181 -0
- package/dist/chunks/api-DE7LfK-R.js +960 -0
- package/dist/chunks/api-DOfDzYC_.js +538 -0
- package/dist/chunks/async-B3DUf1GZ.js +26 -0
- package/dist/chunks/bpoint-Ciy3yY9Q.js +34 -0
- package/dist/chunks/calculations-CkYAqO_-.js +197 -0
- package/dist/chunks/captcha-eu-DnOWhMwr.js +43 -0
- package/dist/chunks/checkbox-radio-0x7Tc0br.js +197 -0
- package/dist/chunks/chunk-K6L4z4UQ.js +24 -0
- package/dist/chunks/conditions-4fXKhEJS.js +609 -0
- package/dist/chunks/date-picker-B6iZkjHS.js +6204 -0
- package/dist/chunks/debug-KnZeKYBI.js +39 -0
- package/dist/chunks/dist-D09GnXMW.js +2663 -0
- package/dist/chunks/event-names-DamGPtXR.js +51 -0
- package/dist/chunks/eway-DEAYcwT0.js +86 -0
- package/dist/chunks/field-references.keys-BpBZ_quS.js +24 -0
- package/dist/chunks/field-references.resolver-Ba6xhiJC.js +183 -0
- package/dist/chunks/file-upload-Bh63PQSE.js +430 -0
- package/dist/chunks/friendly-captcha-v1-CqO4WVre.js +40 -0
- package/dist/chunks/friendly-captcha-v2-CyykcJcM.js +47 -0
- package/dist/chunks/friendly-challenge-Dg8XkStd.js +1101 -0
- package/dist/chunks/go-cardless-CuND59rR.js +26 -0
- package/dist/chunks/google-address--uR8WDSm.js +208 -0
- package/dist/chunks/hcaptcha-CmaFUesv.js +72 -0
- package/dist/chunks/hidden-CYnZYple.js +36 -0
- package/dist/chunks/http-18nn97DZ.js +29 -0
- package/dist/chunks/i18n-vUh-KGiH.js +55 -0
- package/dist/chunks/loqate-BICNJlVK.js +97 -0
- package/dist/chunks/mollie-DwlsgHZ1.js +26 -0
- package/dist/chunks/moneris-B_IFZFTx.js +159 -0
- package/dist/chunks/opayo-U2x_TOII.js +192 -0
- package/dist/chunks/paddle-BqXFrc79.js +75 -0
- package/dist/chunks/paypal-Cn_DYGDb.js +121 -0
- package/dist/chunks/payway-Rnq796eC.js +75 -0
- package/dist/chunks/phone-country-B6Me4lK0.js +3317 -0
- package/dist/chunks/place-kit-ldUl-u9w.js +56 -0
- package/dist/chunks/placekit-autocomplete.esm-D-lGeaZl.js +1771 -0
- package/dist/chunks/recaptcha-enterprise-DPJNyv1X.js +72 -0
- package/dist/chunks/recaptcha-shared-DTI4qWVR.js +22 -0
- package/dist/chunks/recaptcha-v2-checkbox-zFjpvJ5c.js +49 -0
- package/dist/chunks/recaptcha-v2-invisible-CnYtkNvz.js +62 -0
- package/dist/chunks/recaptcha-v3-EAlWhnkX.js +33 -0
- package/dist/chunks/repeater-CXD1eLSn.js +151 -0
- package/dist/chunks/rich-text-DkmZRhGj.js +442 -0
- package/dist/chunks/scripts-BGD_iU_6.js +41 -0
- package/dist/chunks/sdk-B7u9fTlP.js +2103 -0
- package/dist/chunks/shared-DC6_1u8X.js +85 -0
- package/dist/chunks/signature-E9KyYXS1.js +765 -0
- package/dist/chunks/snaptcha-CCDunGeb.js +8 -0
- package/dist/chunks/square-BLqK51rS.js +61 -0
- package/dist/chunks/stripe-B8gHpZNC.js +273 -0
- package/dist/chunks/styles-BIh6g7V_.js +22 -0
- package/dist/chunks/summary-EcNE0cvg.js +191 -0
- package/dist/chunks/table-yxEDL6kA.js +124 -0
- package/dist/chunks/text-limit-D0H_Ca2c.js +179 -0
- package/dist/chunks/theme-classes-vSHpdCUO.js +59 -0
- package/dist/chunks/turnstile-DP0bdR7T.js +68 -0
- package/dist/chunks/utils-ByrEVYrJ.js +49584 -0
- package/dist/css/formie-base.css +78 -0
- package/dist/css/formie-theme.css +19 -0
- package/dist/css/formie.css +2 -0
- package/dist/css/theme/_buttons.css +249 -0
- package/dist/css/theme/_loading.css +37 -0
- package/dist/css/theme/_messages.css +39 -0
- package/dist/css/theme/_progress.css +62 -0
- package/dist/css/theme/_tokens.css +361 -0
- package/dist/css/theme/_typography.css +70 -0
- package/dist/css/theme/fields/_address.css +17 -0
- package/dist/css/theme/fields/_check-radio.css +108 -0
- package/dist/css/theme/fields/_file.css +58 -0
- package/dist/css/theme/fields/_group.css +13 -0
- package/dist/css/theme/fields/_input.css +48 -0
- package/dist/css/theme/fields/_nested.css +19 -0
- package/dist/css/theme/fields/_repeater.css +69 -0
- package/dist/css/theme/fields/_rich-text.css +201 -0
- package/dist/css/theme/fields/_select.css +37 -0
- package/dist/css/theme/fields/_signature.css +39 -0
- package/dist/css/theme/fields/_summary.css +53 -0
- package/dist/css/theme/fields/_table.css +121 -0
- package/dist/css/theme/fields/_text-limit.css +10 -0
- package/dist/css/theme/forms/_field.css +62 -0
- package/dist/css/theme/forms/_form.css +166 -0
- package/dist/css/theme/integrations/_payment-modal.css +32 -0
- package/dist/css/theme/integrations/_paypal.css +10 -0
- package/dist/css/theme/integrations/_payway.css +10 -0
- package/dist/css/theme/integrations/_stripe.css +24 -0
- package/dist/css/theme/utilities/_accessibility.css +13 -0
- package/dist/css/theme-base/_controls.css +41 -0
- package/dist/css/theme-base/_primitives.css +34 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3206 -0
- package/dist/js/compatibility/dom-adapter.d.ts +12 -0
- package/dist/js/compatibility/dom-adapter.d.ts.map +1 -0
- package/dist/js/compatibility/event-map.d.ts +25 -0
- package/dist/js/compatibility/event-map.d.ts.map +1 -0
- package/dist/js/compatibility/validator-adapter.d.ts +17 -0
- package/dist/js/compatibility/validator-adapter.d.ts.map +1 -0
- package/dist/js/contracts/client.d.ts +40 -0
- package/dist/js/contracts/client.d.ts.map +1 -0
- package/dist/js/contracts/common.d.ts +5 -0
- package/dist/js/contracts/common.d.ts.map +1 -0
- package/dist/js/contracts/modules.d.ts +47 -0
- package/dist/js/contracts/modules.d.ts.map +1 -0
- package/dist/js/contracts/schema.d.ts +79 -0
- package/dist/js/contracts/schema.d.ts.map +1 -0
- package/dist/js/contracts/theme.d.ts +2 -0
- package/dist/js/contracts/theme.d.ts.map +1 -0
- package/dist/js/core/create-formie-client.d.ts +3 -0
- package/dist/js/core/create-formie-client.d.ts.map +1 -0
- package/dist/js/core/dom-events.d.ts +2 -0
- package/dist/js/core/dom-events.d.ts.map +1 -0
- package/dist/js/core/formie.d.ts +27 -0
- package/dist/js/core/formie.d.ts.map +1 -0
- package/dist/js/core/hydrate-modules.d.ts +22 -0
- package/dist/js/core/hydrate-modules.d.ts.map +1 -0
- package/dist/js/core/page-client-event.d.ts +9 -0
- package/dist/js/core/page-client-event.d.ts.map +1 -0
- package/dist/js/core/page-tab-errors.d.ts +2 -0
- package/dist/js/core/page-tab-errors.d.ts.map +1 -0
- package/dist/js/core/submit-flow.d.ts +21 -0
- package/dist/js/core/submit-flow.d.ts.map +1 -0
- package/dist/js/core/submit-result-state.d.ts +8 -0
- package/dist/js/core/submit-result-state.d.ts.map +1 -0
- package/dist/js/core/submit-result-ui.d.ts +10 -0
- package/dist/js/core/submit-result-ui.d.ts.map +1 -0
- package/dist/js/events/event-bus.d.ts +21 -0
- package/dist/js/events/event-bus.d.ts.map +1 -0
- package/dist/js/modules/address/address-finder.d.ts +2 -0
- package/dist/js/modules/address/address-finder.d.ts.map +1 -0
- package/dist/js/modules/address/api.d.ts +8 -0
- package/dist/js/modules/address/api.d.ts.map +1 -0
- package/dist/js/modules/address/constants.d.ts +15 -0
- package/dist/js/modules/address/constants.d.ts.map +1 -0
- package/dist/js/modules/address/factories.d.ts +35 -0
- package/dist/js/modules/address/factories.d.ts.map +1 -0
- package/dist/js/modules/address/google-address.d.ts +2 -0
- package/dist/js/modules/address/google-address.d.ts.map +1 -0
- package/dist/js/modules/address/host.d.ts +30 -0
- package/dist/js/modules/address/host.d.ts.map +1 -0
- package/dist/js/modules/address/index.d.ts +3 -0
- package/dist/js/modules/address/index.d.ts.map +1 -0
- package/dist/js/modules/address/loqate.d.ts +2 -0
- package/dist/js/modules/address/loqate.d.ts.map +1 -0
- package/dist/js/modules/address/place-kit.d.ts +2 -0
- package/dist/js/modules/address/place-kit.d.ts.map +1 -0
- package/dist/js/modules/captchas/api.d.ts +9 -0
- package/dist/js/modules/captchas/api.d.ts.map +1 -0
- package/dist/js/modules/captchas/captcha-eu.d.ts +2 -0
- package/dist/js/modules/captchas/captcha-eu.d.ts.map +1 -0
- package/dist/js/modules/captchas/constants.d.ts +5 -0
- package/dist/js/modules/captchas/constants.d.ts.map +1 -0
- package/dist/js/modules/captchas/factories.d.ts +63 -0
- package/dist/js/modules/captchas/factories.d.ts.map +1 -0
- package/dist/js/modules/captchas/friendly-captcha-v1.d.ts +2 -0
- package/dist/js/modules/captchas/friendly-captcha-v1.d.ts.map +1 -0
- package/dist/js/modules/captchas/friendly-captcha-v2.d.ts +2 -0
- package/dist/js/modules/captchas/friendly-captcha-v2.d.ts.map +1 -0
- package/dist/js/modules/captchas/hcaptcha.d.ts +2 -0
- package/dist/js/modules/captchas/hcaptcha.d.ts.map +1 -0
- package/dist/js/modules/captchas/host.d.ts +78 -0
- package/dist/js/modules/captchas/host.d.ts.map +1 -0
- package/dist/js/modules/captchas/index.d.ts +3 -0
- package/dist/js/modules/captchas/index.d.ts.map +1 -0
- package/dist/js/modules/captchas/recaptcha-enterprise.d.ts +2 -0
- package/dist/js/modules/captchas/recaptcha-enterprise.d.ts.map +1 -0
- package/dist/js/modules/captchas/recaptcha-shared.d.ts +26 -0
- package/dist/js/modules/captchas/recaptcha-shared.d.ts.map +1 -0
- package/dist/js/modules/captchas/recaptcha-v2-checkbox.d.ts +2 -0
- package/dist/js/modules/captchas/recaptcha-v2-checkbox.d.ts.map +1 -0
- package/dist/js/modules/captchas/recaptcha-v2-invisible.d.ts +2 -0
- package/dist/js/modules/captchas/recaptcha-v2-invisible.d.ts.map +1 -0
- package/dist/js/modules/captchas/recaptcha-v3.d.ts +2 -0
- package/dist/js/modules/captchas/recaptcha-v3.d.ts.map +1 -0
- package/dist/js/modules/captchas/snaptcha.d.ts +2 -0
- package/dist/js/modules/captchas/snaptcha.d.ts.map +1 -0
- package/dist/js/modules/captchas/turnstile.d.ts +2 -0
- package/dist/js/modules/captchas/turnstile.d.ts.map +1 -0
- package/dist/js/modules/captchas/utils.d.ts +13 -0
- package/dist/js/modules/captchas/utils.d.ts.map +1 -0
- package/dist/js/modules/fields/calculations.d.ts +3 -0
- package/dist/js/modules/fields/calculations.d.ts.map +1 -0
- package/dist/js/modules/fields/checkbox-radio.d.ts +3 -0
- package/dist/js/modules/fields/checkbox-radio.d.ts.map +1 -0
- package/dist/js/modules/fields/conditions/config.d.ts +5 -0
- package/dist/js/modules/fields/conditions/config.d.ts.map +1 -0
- package/dist/js/modules/fields/conditions/effects.d.ts +2 -0
- package/dist/js/modules/fields/conditions/effects.d.ts.map +1 -0
- package/dist/js/modules/fields/conditions/evaluator.d.ts +6 -0
- package/dist/js/modules/fields/conditions/evaluator.d.ts.map +1 -0
- package/dist/js/modules/fields/conditions/references.d.ts +5 -0
- package/dist/js/modules/fields/conditions/references.d.ts.map +1 -0
- package/dist/js/modules/fields/conditions/transforms.d.ts +3 -0
- package/dist/js/modules/fields/conditions/transforms.d.ts.map +1 -0
- package/dist/js/modules/fields/conditions/types.d.ts +30 -0
- package/dist/js/modules/fields/conditions/types.d.ts.map +1 -0
- package/dist/js/modules/fields/conditions/values.d.ts +5 -0
- package/dist/js/modules/fields/conditions/values.d.ts.map +1 -0
- package/dist/js/modules/fields/conditions.d.ts +3 -0
- package/dist/js/modules/fields/conditions.d.ts.map +1 -0
- package/dist/js/modules/fields/date-picker.d.ts +3 -0
- package/dist/js/modules/fields/date-picker.d.ts.map +1 -0
- package/dist/js/modules/fields/file-upload.d.ts +3 -0
- package/dist/js/modules/fields/file-upload.d.ts.map +1 -0
- package/dist/js/modules/fields/hidden.d.ts +3 -0
- package/dist/js/modules/fields/hidden.d.ts.map +1 -0
- package/dist/js/modules/fields/index.d.ts +3 -0
- package/dist/js/modules/fields/index.d.ts.map +1 -0
- package/dist/js/modules/fields/phone-country.d.ts +3 -0
- package/dist/js/modules/fields/phone-country.d.ts.map +1 -0
- package/dist/js/modules/fields/repeater.d.ts +3 -0
- package/dist/js/modules/fields/repeater.d.ts.map +1 -0
- package/dist/js/modules/fields/rich-text.d.ts +3 -0
- package/dist/js/modules/fields/rich-text.d.ts.map +1 -0
- package/dist/js/modules/fields/shared.d.ts +20 -0
- package/dist/js/modules/fields/shared.d.ts.map +1 -0
- package/dist/js/modules/fields/signature.d.ts +3 -0
- package/dist/js/modules/fields/signature.d.ts.map +1 -0
- package/dist/js/modules/fields/summary.d.ts +3 -0
- package/dist/js/modules/fields/summary.d.ts.map +1 -0
- package/dist/js/modules/fields/table.d.ts +3 -0
- package/dist/js/modules/fields/table.d.ts.map +1 -0
- package/dist/js/modules/fields/text-limit.d.ts +3 -0
- package/dist/js/modules/fields/text-limit.d.ts.map +1 -0
- package/dist/js/modules/loader.d.ts +11 -0
- package/dist/js/modules/loader.d.ts.map +1 -0
- package/dist/js/modules/payments/api.d.ts +8 -0
- package/dist/js/modules/payments/api.d.ts.map +1 -0
- package/dist/js/modules/payments/bpoint.d.ts +2 -0
- package/dist/js/modules/payments/bpoint.d.ts.map +1 -0
- package/dist/js/modules/payments/constants.d.ts +5 -0
- package/dist/js/modules/payments/constants.d.ts.map +1 -0
- package/dist/js/modules/payments/eway.d.ts +9 -0
- package/dist/js/modules/payments/eway.d.ts.map +1 -0
- package/dist/js/modules/payments/factories.d.ts +54 -0
- package/dist/js/modules/payments/factories.d.ts.map +1 -0
- package/dist/js/modules/payments/go-cardless.d.ts +2 -0
- package/dist/js/modules/payments/go-cardless.d.ts.map +1 -0
- package/dist/js/modules/payments/host.d.ts +70 -0
- package/dist/js/modules/payments/host.d.ts.map +1 -0
- package/dist/js/modules/payments/index.d.ts +3 -0
- package/dist/js/modules/payments/index.d.ts.map +1 -0
- package/dist/js/modules/payments/mollie.d.ts +2 -0
- package/dist/js/modules/payments/mollie.d.ts.map +1 -0
- package/dist/js/modules/payments/moneris.d.ts +2 -0
- package/dist/js/modules/payments/moneris.d.ts.map +1 -0
- package/dist/js/modules/payments/opayo.d.ts +25 -0
- package/dist/js/modules/payments/opayo.d.ts.map +1 -0
- package/dist/js/modules/payments/paddle.d.ts +2 -0
- package/dist/js/modules/payments/paddle.d.ts.map +1 -0
- package/dist/js/modules/payments/paypal.d.ts +2 -0
- package/dist/js/modules/payments/paypal.d.ts.map +1 -0
- package/dist/js/modules/payments/payway.d.ts +2 -0
- package/dist/js/modules/payments/payway.d.ts.map +1 -0
- package/dist/js/modules/payments/square.d.ts +2 -0
- package/dist/js/modules/payments/square.d.ts.map +1 -0
- package/dist/js/modules/payments/stripe.d.ts +2 -0
- package/dist/js/modules/payments/stripe.d.ts.map +1 -0
- package/dist/js/modules/payments/utils.d.ts +17 -0
- package/dist/js/modules/payments/utils.d.ts.map +1 -0
- package/dist/js/modules/registry.d.ts +9 -0
- package/dist/js/modules/registry.d.ts.map +1 -0
- package/dist/js/modules/styles.d.ts +2 -0
- package/dist/js/modules/styles.d.ts.map +1 -0
- package/dist/js/submit/pipeline.d.ts +18 -0
- package/dist/js/submit/pipeline.d.ts.map +1 -0
- package/dist/js/theme/theme-classes.d.ts +10 -0
- package/dist/js/theme/theme-classes.d.ts.map +1 -0
- package/dist/js/transport/forms-api.d.ts +11 -0
- package/dist/js/transport/forms-api.d.ts.map +1 -0
- package/dist/js/utils/async.d.ts +8 -0
- package/dist/js/utils/async.d.ts.map +1 -0
- package/dist/js/utils/debug.d.ts +10 -0
- package/dist/js/utils/debug.d.ts.map +1 -0
- package/dist/js/utils/event-names.d.ts +13 -0
- package/dist/js/utils/event-names.d.ts.map +1 -0
- package/dist/js/utils/field-references.d.ts +6 -0
- package/dist/js/utils/field-references.d.ts.map +1 -0
- package/dist/js/utils/field-references.keys.d.ts +4 -0
- package/dist/js/utils/field-references.keys.d.ts.map +1 -0
- package/dist/js/utils/field-references.parser.d.ts +3 -0
- package/dist/js/utils/field-references.parser.d.ts.map +1 -0
- package/dist/js/utils/field-references.registry.d.ts +3 -0
- package/dist/js/utils/field-references.registry.d.ts.map +1 -0
- package/dist/js/utils/field-references.resolver.d.ts +4 -0
- package/dist/js/utils/field-references.resolver.d.ts.map +1 -0
- package/dist/js/utils/field-references.types.d.ts +27 -0
- package/dist/js/utils/field-references.types.d.ts.map +1 -0
- package/dist/js/utils/fields.d.ts +5 -0
- package/dist/js/utils/fields.d.ts.map +1 -0
- package/dist/js/utils/http.d.ts +9 -0
- package/dist/js/utils/http.d.ts.map +1 -0
- package/dist/js/utils/i18n.d.ts +7 -0
- package/dist/js/utils/i18n.d.ts.map +1 -0
- package/dist/js/utils/scripts.d.ts +13 -0
- package/dist/js/utils/scripts.d.ts.map +1 -0
- package/dist/js/utils/unload-warning.d.ts +10 -0
- package/dist/js/utils/unload-warning.d.ts.map +1 -0
- package/dist/js/validation/rules/email.d.ts +4 -0
- package/dist/js/validation/rules/email.d.ts.map +1 -0
- package/dist/js/validation/rules/match.d.ts +4 -0
- package/dist/js/validation/rules/match.d.ts.map +1 -0
- package/dist/js/validation/rules/number.d.ts +4 -0
- package/dist/js/validation/rules/number.d.ts.map +1 -0
- package/dist/js/validation/rules/required.d.ts +4 -0
- package/dist/js/validation/rules/required.d.ts.map +1 -0
- package/dist/js/validation/rules/shared.d.ts +7 -0
- package/dist/js/validation/rules/shared.d.ts.map +1 -0
- package/dist/js/validation/rules/url.d.ts +4 -0
- package/dist/js/validation/rules/url.d.ts.map +1 -0
- package/dist/js/validation/rules.d.ts +10 -0
- package/dist/js/validation/rules.d.ts.map +1 -0
- package/dist/js/validation/types.d.ts +44 -0
- package/dist/js/validation/types.d.ts.map +1 -0
- package/dist/js/validation/validator.d.ts +53 -0
- package/dist/js/validation/validator.d.ts.map +1 -0
- package/package.json +78 -0
- package/src/css/formie-base.css +78 -0
- package/src/css/formie-theme.css +19 -0
- package/src/css/formie.css +2 -0
- package/src/css/theme/_buttons.css +249 -0
- package/src/css/theme/_loading.css +37 -0
- package/src/css/theme/_messages.css +39 -0
- package/src/css/theme/_progress.css +62 -0
- package/src/css/theme/_tokens.css +361 -0
- package/src/css/theme/_typography.css +70 -0
- package/src/css/theme/fields/_address.css +17 -0
- package/src/css/theme/fields/_check-radio.css +108 -0
- package/src/css/theme/fields/_file.css +58 -0
- package/src/css/theme/fields/_group.css +13 -0
- package/src/css/theme/fields/_input.css +48 -0
- package/src/css/theme/fields/_nested.css +19 -0
- package/src/css/theme/fields/_repeater.css +69 -0
- package/src/css/theme/fields/_rich-text.css +201 -0
- package/src/css/theme/fields/_select.css +37 -0
- package/src/css/theme/fields/_signature.css +39 -0
- package/src/css/theme/fields/_summary.css +53 -0
- package/src/css/theme/fields/_table.css +121 -0
- package/src/css/theme/fields/_text-limit.css +10 -0
- package/src/css/theme/forms/_field.css +62 -0
- package/src/css/theme/forms/_form.css +166 -0
- package/src/css/theme/integrations/_payment-modal.css +32 -0
- package/src/css/theme/integrations/_paypal.css +10 -0
- package/src/css/theme/integrations/_payway.css +10 -0
- package/src/css/theme/integrations/_stripe.css +24 -0
- package/src/css/theme/utilities/_accessibility.css +13 -0
- package/src/css/theme-base/_controls.css +41 -0
- package/src/css/theme-base/_primitives.css +34 -0
- package/src/icons/rich-text/aligncenter.svg +6 -0
- package/src/icons/rich-text/alignleft.svg +6 -0
- package/src/icons/rich-text/alignright.svg +6 -0
- package/src/icons/rich-text/bold.svg +4 -0
- package/src/icons/rich-text/clear.svg +6 -0
- package/src/icons/rich-text/code.svg +4 -0
- package/src/icons/rich-text/heading1.svg +3 -0
- package/src/icons/rich-text/heading2.svg +3 -0
- package/src/icons/rich-text/image.svg +6 -0
- package/src/icons/rich-text/italic.svg +5 -0
- package/src/icons/rich-text/line.svg +3 -0
- package/src/icons/rich-text/link.svg +4 -0
- package/src/icons/rich-text/olist.svg +8 -0
- package/src/icons/rich-text/paragraph.svg +3 -0
- package/src/icons/rich-text/quote.svg +4 -0
- package/src/icons/rich-text/strikethrough.svg +4 -0
- package/src/icons/rich-text/ulist.svg +8 -0
- package/src/icons/rich-text/underline.svg +4 -0
- package/src/index.ts +125 -0
- package/src/js/compatibility/dom-adapter.ts +129 -0
- package/src/js/compatibility/event-map.ts +72 -0
- package/src/js/compatibility/validator-adapter.ts +105 -0
- package/src/js/contracts/client.ts +43 -0
- package/src/js/contracts/common.ts +14 -0
- package/src/js/contracts/modules.ts +53 -0
- package/src/js/contracts/schema.ts +83 -0
- package/src/js/contracts/theme.ts +1 -0
- package/src/js/core/create-formie-client.ts +1519 -0
- package/src/js/core/dom-events.ts +8 -0
- package/src/js/core/formie.ts +242 -0
- package/src/js/core/hydrate-modules.ts +102 -0
- package/src/js/core/page-client-event.ts +129 -0
- package/src/js/core/page-tab-errors.ts +37 -0
- package/src/js/core/submit-flow.ts +120 -0
- package/src/js/core/submit-result-state.ts +597 -0
- package/src/js/core/submit-result-ui.ts +448 -0
- package/src/js/events/event-bus.ts +109 -0
- package/src/js/modules/address/address-finder.ts +85 -0
- package/src/js/modules/address/api.ts +22 -0
- package/src/js/modules/address/constants.ts +15 -0
- package/src/js/modules/address/factories.ts +203 -0
- package/src/js/modules/address/google-address.ts +345 -0
- package/src/js/modules/address/host.ts +137 -0
- package/src/js/modules/address/index.ts +10 -0
- package/src/js/modules/address/loqate.ts +128 -0
- package/src/js/modules/address/place-kit.ts +94 -0
- package/src/js/modules/captchas/api.ts +25 -0
- package/src/js/modules/captchas/captcha-eu.ts +86 -0
- package/src/js/modules/captchas/constants.ts +4 -0
- package/src/js/modules/captchas/factories.ts +485 -0
- package/src/js/modules/captchas/friendly-captcha-v1.ts +65 -0
- package/src/js/modules/captchas/friendly-captcha-v2.ts +84 -0
- package/src/js/modules/captchas/hcaptcha.ts +153 -0
- package/src/js/modules/captchas/host.ts +448 -0
- package/src/js/modules/captchas/index.ts +16 -0
- package/src/js/modules/captchas/recaptcha-enterprise.ts +138 -0
- package/src/js/modules/captchas/recaptcha-shared.ts +69 -0
- package/src/js/modules/captchas/recaptcha-v2-checkbox.ts +72 -0
- package/src/js/modules/captchas/recaptcha-v2-invisible.ts +108 -0
- package/src/js/modules/captchas/recaptcha-v3.ts +62 -0
- package/src/js/modules/captchas/snaptcha.ts +10 -0
- package/src/js/modules/captchas/turnstile.ts +131 -0
- package/src/js/modules/captchas/utils.ts +85 -0
- package/src/js/modules/fields/calculations.ts +273 -0
- package/src/js/modules/fields/checkbox-radio.ts +295 -0
- package/src/js/modules/fields/conditions/config.ts +79 -0
- package/src/js/modules/fields/conditions/effects.ts +166 -0
- package/src/js/modules/fields/conditions/evaluator.ts +44 -0
- package/src/js/modules/fields/conditions/references.ts +165 -0
- package/src/js/modules/fields/conditions/transforms.ts +206 -0
- package/src/js/modules/fields/conditions/types.ts +33 -0
- package/src/js/modules/fields/conditions/values.ts +115 -0
- package/src/js/modules/fields/conditions.ts +229 -0
- package/src/js/modules/fields/date-picker.ts +272 -0
- package/src/js/modules/fields/file-upload.ts +628 -0
- package/src/js/modules/fields/hidden.ts +58 -0
- package/src/js/modules/fields/index.ts +19 -0
- package/src/js/modules/fields/phone-country.ts +226 -0
- package/src/js/modules/fields/repeater.ts +231 -0
- package/src/js/modules/fields/rich-text.ts +217 -0
- package/src/js/modules/fields/shared.ts +238 -0
- package/src/js/modules/fields/signature.ts +202 -0
- package/src/js/modules/fields/summary.ts +272 -0
- package/src/js/modules/fields/table.ts +197 -0
- package/src/js/modules/fields/text-limit.ts +280 -0
- package/src/js/modules/loader.ts +331 -0
- package/src/js/modules/payments/api.ts +20 -0
- package/src/js/modules/payments/bpoint.ts +48 -0
- package/src/js/modules/payments/constants.ts +17 -0
- package/src/js/modules/payments/eway.ts +132 -0
- package/src/js/modules/payments/factories.ts +332 -0
- package/src/js/modules/payments/go-cardless.ts +37 -0
- package/src/js/modules/payments/host.ts +459 -0
- package/src/js/modules/payments/index.ts +17 -0
- package/src/js/modules/payments/mollie.ts +38 -0
- package/src/js/modules/payments/moneris.ts +216 -0
- package/src/js/modules/payments/opayo.ts +272 -0
- package/src/js/modules/payments/paddle.ts +111 -0
- package/src/js/modules/payments/payment.ts +183 -0
- package/src/js/modules/payments/paypal.ts +214 -0
- package/src/js/modules/payments/payway.ts +114 -0
- package/src/js/modules/payments/square.ts +106 -0
- package/src/js/modules/payments/stripe.ts +426 -0
- package/src/js/modules/payments/stub-payment-module.ts +87 -0
- package/src/js/modules/payments/utils.ts +60 -0
- package/src/js/modules/registry.ts +38 -0
- package/src/js/modules/styles.ts +29 -0
- package/src/js/submit/pipeline.ts +514 -0
- package/src/js/theme/theme-classes.ts +106 -0
- package/src/js/transport/forms-api.ts +345 -0
- package/src/js/utils/async.ts +81 -0
- package/src/js/utils/debug.ts +59 -0
- package/src/js/utils/event-names.ts +60 -0
- package/src/js/utils/field-references.keys.ts +47 -0
- package/src/js/utils/field-references.parser.ts +121 -0
- package/src/js/utils/field-references.registry.ts +50 -0
- package/src/js/utils/field-references.resolver.ts +115 -0
- package/src/js/utils/field-references.ts +11 -0
- package/src/js/utils/field-references.types.ts +31 -0
- package/src/js/utils/fields.ts +58 -0
- package/src/js/utils/http.ts +51 -0
- package/src/js/utils/i18n.ts +98 -0
- package/src/js/utils/scripts.ts +84 -0
- package/src/js/utils/unload-warning.ts +190 -0
- package/src/js/validation/rules/email.ts +18 -0
- package/src/js/validation/rules/match.ts +26 -0
- package/src/js/validation/rules/minmax.ts +47 -0
- package/src/js/validation/rules/number.ts +55 -0
- package/src/js/validation/rules/pattern.ts +29 -0
- package/src/js/validation/rules/required.ts +30 -0
- package/src/js/validation/rules/shared.ts +47 -0
- package/src/js/validation/rules/url.ts +23 -0
- package/src/js/validation/rules.ts +16 -0
- package/src/js/validation/types.ts +50 -0
- package/src/js/validation/validator.ts +643 -0
- package/src/vendor.d.ts +100 -0
- package/src/vite-env.d.ts +22 -0
- package/vite-dev.mjs +22 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { applyConditionSource } from '#modules/fields/conditions/transforms';
|
|
2
|
+
import type { ConditionInput, ConditionSource } from '#modules/fields/conditions/types';
|
|
3
|
+
|
|
4
|
+
function getInputKey(input: ConditionInput, index: number): string {
|
|
5
|
+
return input.name || `__condition_input_${index}`;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function getInputLabel(input: HTMLInputElement): string {
|
|
9
|
+
const explicitLabel = input.id
|
|
10
|
+
? input.ownerDocument.querySelector(`label[for="${input.id}"]`)?.textContent?.trim()
|
|
11
|
+
: '';
|
|
12
|
+
|
|
13
|
+
if (explicitLabel) {
|
|
14
|
+
return explicitLabel;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return input.closest('label')?.textContent?.trim() || '';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function readInputGroupValues(inputs: ConditionInput[], selector = ''): string[] {
|
|
21
|
+
const firstInput = inputs[0];
|
|
22
|
+
|
|
23
|
+
if (!firstInput) {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (firstInput instanceof HTMLInputElement) {
|
|
28
|
+
if (firstInput.type === 'checkbox') {
|
|
29
|
+
const checkedInputs = inputs.filter((input): input is HTMLInputElement => {
|
|
30
|
+
return input instanceof HTMLInputElement && input.checked;
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
if (selector === 'label') {
|
|
34
|
+
return checkedInputs.map((input) => {
|
|
35
|
+
return getInputLabel(input);
|
|
36
|
+
}).filter(Boolean);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return checkedInputs.map((input) => {
|
|
40
|
+
return input.value;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (firstInput.type === 'radio') {
|
|
45
|
+
const checkedInputs = inputs.filter((input): input is HTMLInputElement => {
|
|
46
|
+
return input instanceof HTMLInputElement && input.checked;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
if (selector === 'label') {
|
|
50
|
+
return checkedInputs.map((input) => {
|
|
51
|
+
return getInputLabel(input);
|
|
52
|
+
}).filter(Boolean);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return checkedInputs.map((input) => {
|
|
56
|
+
return input.value;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (firstInput.type === 'file') {
|
|
61
|
+
return Array.from(firstInput.files || []).map((file) => {
|
|
62
|
+
return file.name;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (firstInput instanceof HTMLSelectElement && firstInput.multiple) {
|
|
68
|
+
if (selector === 'label') {
|
|
69
|
+
return Array.from(firstInput.selectedOptions).map((option) => {
|
|
70
|
+
return option.label || option.text;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return Array.from(firstInput.selectedOptions).map((option) => {
|
|
75
|
+
return option.value;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (firstInput instanceof HTMLSelectElement && selector === 'label') {
|
|
80
|
+
return Array.from(firstInput.selectedOptions).map((option) => {
|
|
81
|
+
return option.label || option.text;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return inputs.map((input) => {
|
|
86
|
+
return input.value;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function getConditionInputEventNames(_input: ConditionInput): string[] {
|
|
91
|
+
return ['input', 'change'];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function readConditionValues(inputs: ConditionInput[], source: ConditionSource | null = null): string[] {
|
|
95
|
+
const groupedInputs = new Map<string, ConditionInput[]>();
|
|
96
|
+
|
|
97
|
+
inputs.forEach((input, index) => {
|
|
98
|
+
const key = getInputKey(input, index);
|
|
99
|
+
const existing = groupedInputs.get(key) || [];
|
|
100
|
+
existing.push(input);
|
|
101
|
+
groupedInputs.set(key, existing);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const rawValues = Array.from(groupedInputs.values()).flatMap((group) => {
|
|
105
|
+
return readInputGroupValues(group, source?.selector || '');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
return applyConditionSource(rawValues, source);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function isConditionValueEmpty(values: string[]): boolean {
|
|
112
|
+
return values.length === 0 || values.every((value) => {
|
|
113
|
+
return value.trim() === '';
|
|
114
|
+
});
|
|
115
|
+
}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import type { FormieModuleDefinition } from '#contracts/modules';
|
|
2
|
+
import { CONDITION_SELECTOR, getConditionNodes, parseConditionSettings } from '#modules/fields/conditions/config';
|
|
3
|
+
import { applyConditionVisibility } from '#modules/fields/conditions/effects';
|
|
4
|
+
import { evaluateConditionSettings } from '#modules/fields/conditions/evaluator';
|
|
5
|
+
import { queryConditionInputs } from '#modules/fields/conditions/references';
|
|
6
|
+
import type { ConditionEntry, ConditionInput } from '#modules/fields/conditions/types';
|
|
7
|
+
import { getConditionInputEventNames } from '#modules/fields/conditions/values';
|
|
8
|
+
import { createDebug } from '#utils/debug';
|
|
9
|
+
|
|
10
|
+
const MAX_EVALUATION_PASSES = 4;
|
|
11
|
+
const debug = createDebug('conditions');
|
|
12
|
+
|
|
13
|
+
function uniqueConditionInputs(inputs: ConditionInput[]): ConditionInput[] {
|
|
14
|
+
const seenInputs = new Set<ConditionInput>();
|
|
15
|
+
|
|
16
|
+
return inputs.filter((input) => {
|
|
17
|
+
if (seenInputs.has(input)) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
seenInputs.add(input);
|
|
22
|
+
return true;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const conditionsModule: FormieModuleDefinition = {
|
|
27
|
+
id: 'conditions',
|
|
28
|
+
kind: 'field',
|
|
29
|
+
match: (ctx) => {
|
|
30
|
+
return ctx.target instanceof HTMLElement && (
|
|
31
|
+
ctx.target.matches(CONDITION_SELECTOR) ||
|
|
32
|
+
!!ctx.target.querySelector(CONDITION_SELECTOR)
|
|
33
|
+
);
|
|
34
|
+
},
|
|
35
|
+
setup: async(ctx) => {
|
|
36
|
+
const scopeRoot = ctx.target instanceof HTMLElement ? ctx.target : ctx.root;
|
|
37
|
+
|
|
38
|
+
if (!getConditionNodes(scopeRoot).length) {
|
|
39
|
+
debug.log('No condition nodes in scope.');
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const sourceUnbinds: Array<() => void> = [];
|
|
44
|
+
let entries: ConditionEntry[] = [];
|
|
45
|
+
let evaluationQueued = false;
|
|
46
|
+
let rebuildQueued = false;
|
|
47
|
+
|
|
48
|
+
const cleanupSourceBindings = (): void => {
|
|
49
|
+
sourceUnbinds.forEach((unbind) => {
|
|
50
|
+
unbind();
|
|
51
|
+
});
|
|
52
|
+
sourceUnbinds.length = 0;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const buildEntries = (): ConditionEntry[] => {
|
|
56
|
+
return getConditionNodes(scopeRoot).flatMap((node) => {
|
|
57
|
+
const settings = parseConditionSettings(node);
|
|
58
|
+
|
|
59
|
+
if (!settings || !settings.conditions.length) {
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const sourceInputs = uniqueConditionInputs(settings.conditions.flatMap((condition) => {
|
|
64
|
+
return queryConditionInputs(scopeRoot, node, condition);
|
|
65
|
+
}));
|
|
66
|
+
|
|
67
|
+
return [{
|
|
68
|
+
node,
|
|
69
|
+
settings,
|
|
70
|
+
sourceInputs,
|
|
71
|
+
}];
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const runEvaluationPass = (): boolean => {
|
|
76
|
+
let hasStateChanges = false;
|
|
77
|
+
|
|
78
|
+
entries.forEach((entry) => {
|
|
79
|
+
const result = evaluateConditionSettings(entry.settings, (condition) => {
|
|
80
|
+
return queryConditionInputs(scopeRoot, entry.node, condition);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const stateChanged = applyConditionVisibility(entry.node, result.shouldHide, entry.settings.clearOnHide);
|
|
84
|
+
hasStateChanges = hasStateChanges || stateChanged;
|
|
85
|
+
debug.log('Condition evaluated.', {
|
|
86
|
+
shouldHide: result.shouldHide,
|
|
87
|
+
finalResult: result.finalResult,
|
|
88
|
+
stateChanged,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
void ctx.emit('formie:conditions:evaluated', {
|
|
92
|
+
node: entry.node,
|
|
93
|
+
shouldHide: result.shouldHide,
|
|
94
|
+
finalResult: result.finalResult,
|
|
95
|
+
clearOnHide: entry.settings.clearOnHide,
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
return hasStateChanges;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const evaluateAll = (): void => {
|
|
103
|
+
for (let pass = 0; pass < MAX_EVALUATION_PASSES; pass += 1) {
|
|
104
|
+
if (!runEvaluationPass()) {
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (pass === MAX_EVALUATION_PASSES - 1) {
|
|
109
|
+
debug.warn('Reached max evaluation passes.', { maxPasses: MAX_EVALUATION_PASSES });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const scheduleEvaluateAll = (): void => {
|
|
115
|
+
if (evaluationQueued) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
evaluationQueued = true;
|
|
120
|
+
|
|
121
|
+
queueMicrotask(() => {
|
|
122
|
+
evaluationQueued = false;
|
|
123
|
+
evaluateAll();
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const bindSourceInputs = (): void => {
|
|
128
|
+
uniqueConditionInputs(entries.flatMap((entry) => {
|
|
129
|
+
return entry.sourceInputs;
|
|
130
|
+
})).forEach((input) => {
|
|
131
|
+
const handler = () => {
|
|
132
|
+
scheduleEvaluateAll();
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
getConditionInputEventNames(input).forEach((eventName) => {
|
|
136
|
+
input.addEventListener(eventName, handler);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
sourceUnbinds.push(() => {
|
|
140
|
+
getConditionInputEventNames(input).forEach((eventName) => {
|
|
141
|
+
input.removeEventListener(eventName, handler);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
if (ctx.form) {
|
|
147
|
+
const resetHandler = () => {
|
|
148
|
+
window.setTimeout(() => {
|
|
149
|
+
scheduleEvaluateAll();
|
|
150
|
+
}, 0);
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
ctx.form.addEventListener('reset', resetHandler);
|
|
154
|
+
sourceUnbinds.push(() => {
|
|
155
|
+
ctx.form?.removeEventListener('reset', resetHandler);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const rebuild = (): void => {
|
|
161
|
+
cleanupSourceBindings();
|
|
162
|
+
entries = buildEntries();
|
|
163
|
+
bindSourceInputs();
|
|
164
|
+
debug.log('Rebuilt condition graph.', {
|
|
165
|
+
entryCount: entries.length,
|
|
166
|
+
});
|
|
167
|
+
scheduleEvaluateAll();
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const scheduleRebuild = (): void => {
|
|
171
|
+
if (rebuildQueued) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
rebuildQueued = true;
|
|
176
|
+
|
|
177
|
+
queueMicrotask(() => {
|
|
178
|
+
rebuildQueued = false;
|
|
179
|
+
rebuild();
|
|
180
|
+
});
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const observer = new MutationObserver((mutations) => {
|
|
184
|
+
const shouldRebuild = mutations.some((mutation) => {
|
|
185
|
+
return mutation.type === 'childList' && (mutation.addedNodes.length > 0 || mutation.removedNodes.length > 0);
|
|
186
|
+
});
|
|
187
|
+
const shouldEvaluate = mutations.some((mutation) => {
|
|
188
|
+
return mutation.type === 'attributes';
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
if (shouldRebuild) {
|
|
192
|
+
scheduleRebuild();
|
|
193
|
+
} else if (shouldEvaluate) {
|
|
194
|
+
scheduleEvaluateAll();
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
observer.observe(scopeRoot, {
|
|
199
|
+
childList: true,
|
|
200
|
+
subtree: true,
|
|
201
|
+
attributes: true,
|
|
202
|
+
attributeFilter: [
|
|
203
|
+
'class',
|
|
204
|
+
'style',
|
|
205
|
+
'hidden',
|
|
206
|
+
'aria-hidden',
|
|
207
|
+
'data-formie-conditionally-hidden',
|
|
208
|
+
'data-formie-page-hidden',
|
|
209
|
+
'data-formie-row-hidden',
|
|
210
|
+
],
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
rebuild();
|
|
214
|
+
|
|
215
|
+
await ctx.emit('formie:module:conditions:init', {
|
|
216
|
+
count: entries.length,
|
|
217
|
+
});
|
|
218
|
+
debug.log('Module setup complete.', { entryCount: entries.length });
|
|
219
|
+
|
|
220
|
+
return {
|
|
221
|
+
destroy: () => {
|
|
222
|
+
cleanupSourceBindings();
|
|
223
|
+
observer.disconnect();
|
|
224
|
+
debug.log('Module destroy.');
|
|
225
|
+
void ctx.emit('formie:module:conditions:destroy', {});
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
},
|
|
229
|
+
};
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import flatpickr from 'flatpickr';
|
|
2
|
+
import * as flatpickrLocales from 'flatpickr/dist/l10n/index.js';
|
|
3
|
+
import flatpickrCss from 'flatpickr/dist/flatpickr.css?inline';
|
|
4
|
+
|
|
5
|
+
import type { FormieModuleDefinition } from '#contracts/modules';
|
|
6
|
+
import { dispatchFieldEvent, getModuleFieldContainers } from '#modules/fields/shared';
|
|
7
|
+
import { ensureModuleStyles } from '#modules/styles';
|
|
8
|
+
import { createDebug } from '#utils/debug';
|
|
9
|
+
|
|
10
|
+
const INPUT_SELECTOR = 'input[data-formie-date-datepicker-input]';
|
|
11
|
+
const MODULE_ID = 'date-picker';
|
|
12
|
+
const debug = createDebug('fields', 'date-picker');
|
|
13
|
+
|
|
14
|
+
ensureModuleStyles(MODULE_ID, [flatpickrCss]);
|
|
15
|
+
|
|
16
|
+
type DatePickerOptions = {
|
|
17
|
+
datePickerOptions?: Array<{ label?: string; value?: unknown }>;
|
|
18
|
+
dateFormat?: string;
|
|
19
|
+
timeFormat?: string;
|
|
20
|
+
getIsDate?: boolean;
|
|
21
|
+
getIsTime?: boolean;
|
|
22
|
+
getIsDateTime?: boolean;
|
|
23
|
+
locale?: string;
|
|
24
|
+
minDate?: string | null;
|
|
25
|
+
maxDate?: string | null;
|
|
26
|
+
availableDaysOfWeek?: string[] | number[] | '*';
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
type FlatpickrInstanceLike = {
|
|
30
|
+
destroy: () => void;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type FlatpickrInput = HTMLInputElement & {
|
|
34
|
+
_formieFlatpickr?: FlatpickrInstanceLike;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
function attributesPlugin() {
|
|
38
|
+
return (instance: { input: HTMLInputElement; altInput?: HTMLInputElement | undefined; loadedPlugins: string[] }) => {
|
|
39
|
+
return {
|
|
40
|
+
onReady: () => {
|
|
41
|
+
if (!instance.altInput) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Flatpickr's alt input becomes the visible control, so copy the
|
|
46
|
+
// original accessibility/data attributes onto it before removing
|
|
47
|
+
// them from the hidden transport input.
|
|
48
|
+
const excludedAttributes = new Set(['type', 'name', 'value']);
|
|
49
|
+
instance.input.getAttributeNames().forEach((attribute) => {
|
|
50
|
+
if (excludedAttributes.has(attribute)) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const value = instance.input.getAttribute(attribute);
|
|
55
|
+
if (value !== null) {
|
|
56
|
+
instance.altInput?.setAttribute(attribute, value);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
instance.input.removeAttribute(attribute);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
instance.loadedPlugins.push('formie-attributes');
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function normalizeOffsetDate(input: string | null | undefined, type: 'min' | 'max'): Date | null {
|
|
69
|
+
if (!input) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!Number.isNaN(Date.parse(input))) {
|
|
74
|
+
return new Date(input);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Form config may express relative min/max bounds like "+2 weeks", which are
|
|
78
|
+
// resolved at runtime against the visitor's current date.
|
|
79
|
+
const match = input.trim().match(/^([+-]?\d+)\s*(day|days|week|weeks|month|months|year|years)$/i);
|
|
80
|
+
if (!match) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const amount = parseInt(match[1] || '0', 10);
|
|
85
|
+
const unit = (match[2] || '').toLowerCase();
|
|
86
|
+
const date = new Date();
|
|
87
|
+
|
|
88
|
+
switch (unit) {
|
|
89
|
+
case 'day':
|
|
90
|
+
case 'days':
|
|
91
|
+
date.setDate(date.getDate() + amount);
|
|
92
|
+
break;
|
|
93
|
+
case 'week':
|
|
94
|
+
case 'weeks':
|
|
95
|
+
date.setDate(date.getDate() + (amount * 7));
|
|
96
|
+
break;
|
|
97
|
+
case 'month':
|
|
98
|
+
case 'months':
|
|
99
|
+
date.setMonth(date.getMonth() + amount);
|
|
100
|
+
break;
|
|
101
|
+
case 'year':
|
|
102
|
+
case 'years':
|
|
103
|
+
date.setFullYear(date.getFullYear() + amount);
|
|
104
|
+
break;
|
|
105
|
+
default:
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (type === 'min') {
|
|
110
|
+
date.setHours(0, 0, 0, 0);
|
|
111
|
+
} else {
|
|
112
|
+
date.setHours(23, 59, 59, 999);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return date;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function prepareFormat(options: DatePickerOptions): string {
|
|
119
|
+
const format = options.getIsDate
|
|
120
|
+
? (options.dateFormat || '')
|
|
121
|
+
: options.getIsTime
|
|
122
|
+
? (options.timeFormat || '')
|
|
123
|
+
: `${options.dateFormat || ''} ${options.timeFormat || ''}`.trim();
|
|
124
|
+
|
|
125
|
+
// Translate Formie/PHP-ish format tokens into the subset flatpickr expects.
|
|
126
|
+
return format
|
|
127
|
+
.replaceAll('A', 'K')
|
|
128
|
+
.replaceAll('a', 'K')
|
|
129
|
+
.replaceAll('s', 'S')
|
|
130
|
+
.replaceAll('g', 'h')
|
|
131
|
+
.replaceAll('h', 'G');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function getLocale(locale: string | undefined): unknown {
|
|
135
|
+
if (!locale || locale === 'en') {
|
|
136
|
+
return 'en';
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const localeMap = flatpickrLocales as Record<string, unknown>;
|
|
140
|
+
return localeMap[locale] ?? localeMap.default ?? 'en';
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function getDisabledWeekdayHandler(availableDaysOfWeek: DatePickerOptions['availableDaysOfWeek']) {
|
|
144
|
+
if (!availableDaysOfWeek || availableDaysOfWeek === '*') {
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const allowedDays = availableDaysOfWeek.map((value) => {
|
|
149
|
+
return Number(value);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
return (date: Date) => {
|
|
153
|
+
return !allowedDays.includes(date.getDay());
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function getCustomOptions(options: DatePickerOptions): Record<string, unknown> {
|
|
158
|
+
const result: Record<string, unknown> = {};
|
|
159
|
+
|
|
160
|
+
(options.datePickerOptions || []).forEach((entry) => {
|
|
161
|
+
if (!entry.label) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
result[entry.label] = entry.value;
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
return result;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function initDatePicker(input: FlatpickrInput, options: DatePickerOptions): () => void {
|
|
172
|
+
input._formieFlatpickr?.destroy();
|
|
173
|
+
|
|
174
|
+
const defaultOptions: Record<string, unknown> = {
|
|
175
|
+
disableMobile: true,
|
|
176
|
+
allowInput: true,
|
|
177
|
+
altInput: true,
|
|
178
|
+
altFormat: prepareFormat(options),
|
|
179
|
+
dateFormat: 'Y-m-d H:i:S',
|
|
180
|
+
hourIncrement: 1,
|
|
181
|
+
minuteIncrement: 1,
|
|
182
|
+
minDate: normalizeOffsetDate(options.minDate, 'min'),
|
|
183
|
+
maxDate: normalizeOffsetDate(options.maxDate, 'max'),
|
|
184
|
+
plugins: [attributesPlugin()],
|
|
185
|
+
locale: getLocale(options.locale),
|
|
186
|
+
onChange: (_selectedDates: unknown, _dateStr: string, instance: { input: HTMLInputElement; altInput?: HTMLInputElement }) => {
|
|
187
|
+
// Mirror changes back through bubbling input events so validation,
|
|
188
|
+
// conditions, and calculations respond to picker-driven updates.
|
|
189
|
+
instance.input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
190
|
+
instance.altInput?.dispatchEvent(new Event('input', { bubbles: true }));
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
const disableWeekdays = getDisabledWeekdayHandler(options.availableDaysOfWeek);
|
|
195
|
+
if (disableWeekdays) {
|
|
196
|
+
defaultOptions.disable = [disableWeekdays];
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (options.getIsTime || options.getIsDateTime) {
|
|
200
|
+
defaultOptions.enableTime = true;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (options.getIsTime) {
|
|
204
|
+
defaultOptions.noCalendar = true;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const mergedOptions = {
|
|
208
|
+
...defaultOptions,
|
|
209
|
+
...getCustomOptions(options),
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
dispatchFieldEvent(input, MODULE_ID, 'before-init', {
|
|
213
|
+
datepicker: input,
|
|
214
|
+
options: mergedOptions,
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
const instance = flatpickr(input, mergedOptions) as FlatpickrInstanceLike;
|
|
218
|
+
input._formieFlatpickr = instance;
|
|
219
|
+
debug.log('Initialized.', {
|
|
220
|
+
inputName: input.name,
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
dispatchFieldEvent(input, MODULE_ID, 'after-init', {
|
|
224
|
+
datepicker: instance,
|
|
225
|
+
options: mergedOptions,
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
return () => {
|
|
229
|
+
instance.destroy();
|
|
230
|
+
delete input._formieFlatpickr;
|
|
231
|
+
debug.log('Destroyed.', {
|
|
232
|
+
inputName: input.name,
|
|
233
|
+
});
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export const datePickerModule: FormieModuleDefinition = {
|
|
238
|
+
id: MODULE_ID,
|
|
239
|
+
kind: 'field',
|
|
240
|
+
match: (ctx) => {
|
|
241
|
+
return !!ctx.target.querySelector(INPUT_SELECTOR);
|
|
242
|
+
},
|
|
243
|
+
setup: async (ctx) => {
|
|
244
|
+
const options = (ctx.options || {}) as DatePickerOptions;
|
|
245
|
+
const fields = getModuleFieldContainers(ctx);
|
|
246
|
+
const cleanups = fields.map((field) => {
|
|
247
|
+
const input = field.querySelector(INPUT_SELECTOR);
|
|
248
|
+
if (!(input instanceof HTMLInputElement)) {
|
|
249
|
+
debug.warn('Field missing date input; skipping.');
|
|
250
|
+
return () => { };
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return initDatePicker(input as FlatpickrInput, options);
|
|
254
|
+
});
|
|
255
|
+
debug.log('Module setup.', { fieldCount: fields.length });
|
|
256
|
+
|
|
257
|
+
await ctx.emit('formie:module:date-picker:init', {
|
|
258
|
+
count: cleanups.length,
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
return {
|
|
262
|
+
destroy: () => {
|
|
263
|
+
cleanups.forEach((cleanup) => {
|
|
264
|
+
cleanup();
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
debug.log('Module destroy.', { fieldCount: fields.length });
|
|
268
|
+
void ctx.emit('formie:module:date-picker:destroy', {});
|
|
269
|
+
},
|
|
270
|
+
};
|
|
271
|
+
},
|
|
272
|
+
};
|