@m3ui-vue/m3ui-vue 1.7.0 → 1.8.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.
Files changed (88) hide show
  1. package/dist/API.md +578 -3
  2. package/dist/{MColorPickerModal-BKM1CHxr.js → MColorPickerModal-H8nuX0Wu.js} +3 -4
  3. package/dist/{MColorPickerModal-BKM1CHxr.js.map → MColorPickerModal-H8nuX0Wu.js.map} +1 -1
  4. package/dist/MDialog-B42Mhn8W.js +331 -0
  5. package/dist/MDialog-B42Mhn8W.js.map +1 -0
  6. package/dist/{MListItem-BU5KDRCB.js → MListItem-DiOAxaN7.js} +102 -102
  7. package/dist/{MListItem-BU5KDRCB.js.map → MListItem-DiOAxaN7.js.map} +1 -1
  8. package/dist/{MLoadingIndicator-RykOo5tf.js → MLoadingIndicator-CuTZYFFj.js} +2 -2
  9. package/dist/{MLoadingIndicator-RykOo5tf.js.map → MLoadingIndicator-CuTZYFFj.js.map} +1 -1
  10. package/dist/{MSeekBar-B_Y3MpVz.js → MSeekBar-BCDQTx2t.js} +2 -2
  11. package/dist/{MSeekBar-B_Y3MpVz.js.map → MSeekBar-BCDQTx2t.js.map} +1 -1
  12. package/dist/{MSegmentedButton-CiOOY1-N.js → MSegmentedButton-BXzRsg1S.js} +2 -2
  13. package/dist/{MSegmentedButton-CiOOY1-N.js.map → MSegmentedButton-BXzRsg1S.js.map} +1 -1
  14. package/dist/MSignaturePad-BTqGaPXA.js +313 -0
  15. package/dist/MSignaturePad-BTqGaPXA.js.map +1 -0
  16. package/dist/{MSlider-BCeVIxcq.js → MSlider-D_O8J9YH.js} +3 -3
  17. package/dist/{MSlider-BCeVIxcq.js.map → MSlider-D_O8J9YH.js.map} +1 -1
  18. package/dist/{MSpinner-Cs03qoqE.js → MSpinner-UCdtSOHP.js} +2 -2
  19. package/dist/{MSpinner-Cs03qoqE.js.map → MSpinner-UCdtSOHP.js.map} +1 -1
  20. package/dist/{MTextField-NaFbMkjv.js → MTextField-CYk9yFvi.js} +3 -3
  21. package/dist/{MTextField-NaFbMkjv.js.map → MTextField-CYk9yFvi.js.map} +1 -1
  22. package/dist/{_useFieldValidation-Bz34IAQY.js → _useFieldValidation-B0B44M_t.js} +2 -2
  23. package/dist/{_useFieldValidation-Bz34IAQY.js.map → _useFieldValidation-B0B44M_t.js.map} +1 -1
  24. package/dist/api.json +1 -1
  25. package/dist/code-editor.js +2 -2
  26. package/dist/components/MFormBuilder.vue.d.ts +22 -0
  27. package/dist/components/MFormRenderer.vue.d.ts +151 -0
  28. package/dist/components/MMapRoute.vue.d.ts +13 -5
  29. package/dist/components/MPdfSigner.vue.d.ts +499 -0
  30. package/dist/components/MPdfViewer.vue.d.ts +12 -0
  31. package/dist/components/MPosKeypad.vue.d.ts +1 -1
  32. package/dist/components/MSpreadsheet.vue.d.ts +137 -0
  33. package/dist/components/MStack.vue.d.ts +1 -1
  34. package/dist/composables/pdfSign.d.ts +52 -0
  35. package/dist/composables/spreadsheetFormula.d.ts +55 -0
  36. package/dist/composables/useLocale.d.ts +154 -0
  37. package/dist/draw.js +2 -2
  38. package/dist/flow.js +1 -1
  39. package/dist/gantt.js +2 -2
  40. package/dist/index.d.ts +7 -0
  41. package/dist/locales/index.js +539 -0
  42. package/dist/locales/index.js.map +1 -1
  43. package/dist/m3ui-vue.css +1 -1
  44. package/dist/m3ui.js +16988 -15064
  45. package/dist/m3ui.js.map +1 -1
  46. package/dist/map.js +601 -585
  47. package/dist/map.js.map +1 -1
  48. package/dist/media.js +4 -4
  49. package/dist/pdf.d.ts +3 -0
  50. package/dist/pdf.js +1228 -687
  51. package/dist/pdf.js.map +1 -1
  52. package/dist/rich-text-editor.js +12 -13
  53. package/dist/rich-text-editor.js.map +1 -1
  54. package/dist/styles.css +1 -1
  55. package/dist/{useLocale-Dh1xZZ8i.js → useLocale-DL96OFgr.js} +78 -1
  56. package/dist/useLocale-DL96OFgr.js.map +1 -0
  57. package/package.json +5 -1
  58. package/src/__tests__/MFormRenderer.test.ts +157 -0
  59. package/src/__tests__/MMapRoute.test.ts +34 -0
  60. package/src/__tests__/MPdfSigner.test.ts +175 -0
  61. package/src/__tests__/MSpreadsheet.test.ts +223 -0
  62. package/src/__tests__/spreadsheetFormula.test.ts +77 -0
  63. package/src/__tests__/ssr.test.ts +3 -0
  64. package/src/components/MFormBuilder.vue +417 -0
  65. package/src/components/MFormRenderer.vue +324 -0
  66. package/src/components/MMapRoute.vue +64 -11
  67. package/src/components/MPdfSigner.vue +433 -0
  68. package/src/components/MPdfViewer.vue +12 -0
  69. package/src/components/MSpreadsheet.vue +992 -0
  70. package/src/composables/pdfSign.ts +141 -0
  71. package/src/composables/spreadsheetFormula.ts +459 -0
  72. package/src/composables/useLocale.ts +231 -0
  73. package/src/index.ts +7 -0
  74. package/src/locales/de.ts +77 -0
  75. package/src/locales/es.ts +77 -0
  76. package/src/locales/fr.ts +77 -0
  77. package/src/locales/ja.ts +77 -0
  78. package/src/locales/ko.ts +77 -0
  79. package/src/locales/pt.ts +77 -0
  80. package/src/locales/zh.ts +77 -0
  81. package/src/pdf.ts +3 -0
  82. package/dist/MButton-CN3wYwIG.js +0 -171
  83. package/dist/MButton-CN3wYwIG.js.map +0 -1
  84. package/dist/MDialog-1LAk9WAO.js +0 -167
  85. package/dist/MDialog-1LAk9WAO.js.map +0 -1
  86. package/dist/MProgressBar-BWly1UKN.js +0 -179
  87. package/dist/MProgressBar-BWly1UKN.js.map +0 -1
  88. package/dist/useLocale-Dh1xZZ8i.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"_useFieldValidation-Bz34IAQY.js","names":["useLocale","isStandardSchema","rule","issueKey","segment","runRule","issue","value","ctx","result","runRules","rules","message","isEmpty","lengthOf","toNumber","REQUIRED_RULE","required","locale","EMAIL_RE","email","url","u","minLength","min","maxLength","max","pattern","re","sameAs","other","values","FORM_KEY","useFocusLeave","check","open","root","active","onLeave","watch","now","was","useFieldValidation","form","inject","messageId","useId","disabled","computed","opts","ruleList","r","list","empty","own","mark","fieldRequired","ref","shown","pending","deps","token","run","t","read","all","key","target","name","next","k","i","mode","resetting","timer","debounceMs","schedule","ms","dismissed","before","v","onMounted","onBlur","validate","resetValidation","initial","reset","nextTick","external","hasError","unregister","onBeforeUnmount"],"sources":["../src/composables/validation.ts","../src/composables/_useFieldValidation.ts"],"sourcesContent":["import type { M3Locale } from './useLocale'\n\n/**\n * The Standard Schema interface (https://standardschema.dev), implemented by zod (3.24+), valibot (1.0+),\n * arktype, yup (1.7+) and others. A copy of the spec's types, so the lib doesn't depend on any of them:\n * pass a schema straight to a field's `rules` or to `MForm`'s `schema`.\n */\nexport interface StandardSchemaV1<Input = unknown, Output = Input> {\n readonly '~standard': {\n readonly version: 1\n readonly vendor: string\n readonly validate: (value: unknown) => StandardSchemaResult<Output> | Promise<StandardSchemaResult<Output>>\n readonly types?: { readonly input: Input; readonly output: Output }\n }\n}\n\nexport interface StandardSchemaIssue {\n readonly message: string\n readonly path?: ReadonlyArray<PropertyKey | { readonly key: PropertyKey }>\n}\n\nexport type StandardSchemaResult<Output> =\n | { readonly value: Output; readonly issues?: undefined }\n | { readonly issues: ReadonlyArray<StandardSchemaIssue> }\n\n/** What a rule receives besides the value */\nexport interface ValidationContext {\n /** The active locale, for messages */\n locale: M3Locale\n /** The values of every named field of the surrounding `MForm` (empty outside one) */\n values: Record<string, unknown>\n}\n\n/**\n * `true`, `undefined` or `null` = valid; a string = invalid with that message; `false` = invalid with the\n * locale's generic `validationInvalid` message\n */\nexport type ValidationResult = boolean | string | null | undefined\n\n/** A function `(value, ctx) => true | 'message'` (may be async), or a Standard Schema (zod, valibot…) */\nexport type ValidationRule<T = any> =\n | ((value: T, ctx: ValidationContext) => ValidationResult | Promise<ValidationResult>)\n | StandardSchemaV1\n\n/** When a field checks its rules and shows the result */\nexport type ValidateOn = 'blur' | 'input' | 'submit'\n\nexport function isStandardSchema(rule: unknown): rule is StandardSchemaV1 {\n return typeof rule === 'object' && rule !== null && '~standard' in rule\n}\n\n/** The key of a Standard Schema issue path segment */\nexport function issueKey(segment: PropertyKey | { readonly key: PropertyKey }): PropertyKey {\n return typeof segment === 'object' && segment !== null ? segment.key : segment\n}\n\n/** Runs one rule: the error message, or null when it passes */\nexport async function runRule(rule: ValidationRule, value: unknown, ctx: ValidationContext): Promise<string | null> {\n if (isStandardSchema(rule)) {\n const result = await rule['~standard'].validate(value)\n const issue = result.issues?.[0]\n return issue ? issue.message || ctx.locale.validationInvalid : null\n }\n const result = await rule(value, ctx)\n if (result === true || result === undefined || result === null) return null\n if (result === false) return ctx.locale.validationInvalid\n return result || ctx.locale.validationInvalid\n}\n\n/** Runs rules in order and stops at the first that fails */\nexport async function runRules(rules: ValidationRule[], value: unknown, ctx: ValidationContext): Promise<string | null> {\n for (const rule of rules) {\n const message = await runRule(rule, value, ctx)\n if (message) return message\n }\n return null\n}\n\n/** Whether a value counts as \"not filled in\": null/undefined, blank string, empty array, `false` (an unticked checkbox) */\nexport function isEmpty(value: unknown): boolean {\n if (value === null || value === undefined || value === false) return true\n if (typeof value === 'string') return value.trim() === ''\n if (Array.isArray(value)) return value.length === 0\n if (value instanceof Set || value instanceof Map) return value.size === 0\n return false\n}\n\nfunction lengthOf(value: unknown): number {\n if (typeof value === 'string' || Array.isArray(value)) return value.length\n if (value instanceof Set || value instanceof Map) return value.size\n return String(value).length\n}\n\nfunction toNumber(value: unknown): number {\n return typeof value === 'number' ? value : Number(String(value).trim())\n}\n\n// Built-in rules. Every one but `required` passes on an empty value, so an optional field stays optional:\n// `[email()]` accepts '' and `[required(), email()]` doesn't.\n\n/** Marks the rules `required()` makes, so a field's `required` prop doesn't add a second one in front */\nexport const REQUIRED_RULE = Symbol('m3-required-rule')\n\n/**\n * The value must be filled in (see `isEmpty`; a field may define its own \"empty\", e.g. a date range needs both\n * ends). Given in `rules`, it replaces the check the field's `required` prop adds, so its message is the one shown\n */\nexport function required(message?: string): ValidationRule {\n const rule: ValidationRule = (value, { locale }) => !isEmpty(value) || message || locale.validationRequired\n // Its message (or true): a field with its own \"empty\" test rebuilds the check with it\n ;(rule as any)[REQUIRED_RULE] = message ?? true\n return rule\n}\n\n// Same pattern as the browser's own <input type=\"email\"> check (WHATWG), which is what users expect\nconst EMAIL_RE = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/\n\n/** An email address (the browser's own rule, plus a dot in the domain) */\nexport function email(message?: string): ValidationRule {\n return (value, { locale }) => isEmpty(value) || EMAIL_RE.test(String(value).trim()) || message || locale.validationEmail\n}\n\n/** An absolute http(s) URL */\nexport function url(message?: string): ValidationRule {\n return (value, { locale }) => {\n if (isEmpty(value)) return true\n try {\n const u = new URL(String(value).trim())\n if (u.protocol === 'http:' || u.protocol === 'https:') return true\n } catch { /* invalid */ }\n return message || locale.validationUrl\n }\n}\n\n/** At least `min` characters (strings) or items (arrays) */\nexport function minLength(min: number, message?: string): ValidationRule {\n return (value, { locale }) =>\n isEmpty(value) || lengthOf(value) >= min ||\n message || (Array.isArray(value) ? locale.validationMinItems : locale.validationMinLength).replace('{min}', String(min))\n}\n\n/** At most `max` characters (strings) or items (arrays) */\nexport function maxLength(max: number, message?: string): ValidationRule {\n return (value, { locale }) =>\n isEmpty(value) || lengthOf(value) <= max ||\n message || (Array.isArray(value) ? locale.validationMaxItems : locale.validationMaxLength).replace('{max}', String(max))\n}\n\n/** A number (or numeric string) of at least `min` */\nexport function min(min: number, message?: string): ValidationRule {\n return (value, { locale }) => isEmpty(value) || toNumber(value) >= min || message || locale.validationMin.replace('{min}', String(min))\n}\n\n/** A number (or numeric string) of at most `max` */\nexport function max(max: number, message?: string): ValidationRule {\n return (value, { locale }) => isEmpty(value) || toNumber(value) <= max || message || locale.validationMax.replace('{max}', String(max))\n}\n\n/** Matches a regular expression */\nexport function pattern(re: RegExp, message?: string): ValidationRule {\n return (value, { locale }) => {\n if (isEmpty(value)) return true\n re.lastIndex = 0 // a /g or /y regex keeps state between test() calls\n return re.test(String(value)) || message || locale.validationPattern\n }\n}\n\n/**\n * Equals another value: the name of a field in the same `MForm` (e.g. 'password' for a confirmation field),\n * or a getter\n */\nexport function sameAs(other: string | (() => unknown), message?: string): ValidationRule {\n return (value, { locale, values }) => {\n if (isEmpty(value)) return true\n const target = typeof other === 'function' ? other() : values[other]\n return value === target || message || locale.validationSameAs\n }\n}\n","import { computed, inject, nextTick, onBeforeUnmount, onMounted, ref, useId, watch, type InjectionKey } from 'vue'\nimport { useLocale } from './useLocale'\nimport { REQUIRED_RULE, isEmpty, runRules, type ValidateOn, type ValidationRule } from './validation'\n\n/** @internal What a field registers with its `MForm` */\nexport interface FormField {\n name: () => string | undefined\n value: () => unknown\n /** Checks the rules, shows the result, resolves to whether its own rules pass */\n validate: () => Promise<boolean>\n resetValidation: () => void\n reset: () => Promise<void>\n focus: () => void\n el: () => Element | null | undefined\n /** The message on display, if any */\n error: () => string | null\n /** Whether its rules pass right now (checked silently, whether or not it's shown yet) */\n valid: () => boolean\n pending: () => boolean\n}\n\n/** @internal Provided by `MForm` */\nexport interface FormContext {\n register: (field: FormField) => () => void\n /** Every named field's value, by name */\n values: () => Record<string, unknown>\n /** An error given from outside (`MForm`'s `errors` prop) */\n externalError: (name: string) => string | null\n hasSchema: () => boolean\n /** The form schema's first issue for this field */\n schemaError: (name: string) => Promise<string | null>\n validateOn: () => ValidateOn | undefined\n /** Default debounce (ms) for re-checks while the value changes */\n validateDebounce: () => number | undefined\n /** The `errors` object itself: a new one (a new server response) shows its errors again */\n externalErrorsKey: () => unknown\n /** Keep an outside error after its field changes, instead of hiding it */\n keepErrors: () => boolean\n disabled: () => boolean\n}\n\n/** @internal */\nexport const FORM_KEY: InjectionKey<FormContext> = Symbol('m3-form')\n\n/**\n * @internal \"Blur\" for a field made of several focusable parts (stepper buttons, chips, a popup panel): calls\n * `onLeave` once focus has left `root` for good, not while it moves between its parts or while `open` (its\n * teleported panel, which sits outside `root` in the DOM) is showing. Closing the panel with focus outside\n * counts as leaving. Bind the returned handler to the root's `@focusout`.\n */\nexport function useFocusLeave(root: () => Element | null | undefined, onLeave: () => void, open?: () => boolean) {\n function check() {\n if (open?.()) return\n const r = root()\n const active = document.activeElement\n if (r && active && r.contains(active)) return\n onLeave()\n }\n if (open) watch(open, (now, was) => { if (!now && was) setTimeout(check) })\n // Focus lands on its next element after focusout: look once it has\n return () => { setTimeout(check) }\n}\n\nexport interface FieldValidationOptions {\n value: () => unknown\n rules: () => ValidationRule | ValidationRule[] | undefined\n required: () => boolean | undefined\n error: () => boolean | string | undefined\n errorLabel: () => string | undefined\n name: () => string | undefined\n validateOn: () => ValidateOn | undefined\n /** Wait this long (ms) after the value stops changing before re-checking (async rules: one request, not one per key) */\n validateDebounce?: () => number | undefined\n disabled: () => boolean | undefined\n focus: () => void\n el: () => Element | null | undefined\n /** Writes a value back through v-model (used by `MForm`'s `reset()`) */\n setValue?: (value: unknown) => void\n /** What \"not filled in\" means for `required`, when `isEmpty` isn't it (a date range needs both ends) */\n isEmpty?: (value: unknown) => boolean\n /** Called when the field is validated on demand (`validate()`, an `MForm` submit), to reveal sub-parts' own errors */\n onValidate?: () => void\n}\n\n/**\n * @internal The validation every form field shares: its own `rules` (plus `required` inside an `MForm` or\n * next to other rules), errors from outside (the `error` prop, `MForm`'s `errors`, its `schema`), when to show\n * them (`validateOn`), and registration with the surrounding `MForm`.\n *\n * Priority of what's shown: a string `error` → `error: true` with `errorLabel` → `MForm`'s `errors[name]`\n * → the field's own rules.\n */\nexport function useFieldValidation(opts: FieldValidationOptions) {\n const form = inject(FORM_KEY, null)\n const locale = useLocale()\n const messageId = useId()\n\n const disabled = computed(() => !!opts.disabled() || !!form?.disabled())\n\n const ruleList = computed<ValidationRule[]>(() => {\n const r = opts.rules()\n const list = r ? (Array.isArray(r) ? r : [r]) : []\n // `required` only validates where validation is in use, so a plain field keeps today's behavior\n // (just the asterisk and the native attribute)\n const empty = opts.isEmpty ?? isEmpty\n // A `required()` in the rules: use the field's own \"empty\" with its message, instead of a second check\n const own = list.map((r) => {\n const mark = (r as any)?.[REQUIRED_RULE]\n if (mark === undefined || !opts.isEmpty) return r\n const fieldRequired: ValidationRule = (value, { locale }) => !empty(value) || (typeof mark === 'string' ? mark : locale.validationRequired)\n ;(fieldRequired as any)[REQUIRED_RULE] = mark\n return fieldRequired\n })\n if (!(opts.required() && (form || own.length))) return own\n if (own.some((r) => (r as any)?.[REQUIRED_RULE] !== undefined)) return own\n const required: ValidationRule = (value, { locale }) => !empty(value) || locale.validationRequired\n return [required, ...own]\n })\n const active = computed(() => ruleList.value.length > 0 || (!!form && !!opts.name() && form.hasSchema()))\n\n /** The rules' verdict, kept up to date silently; only displayed once `shown` */\n const result = ref<string | null>(null)\n const shown = ref(false)\n const pending = ref(false)\n /** Names of other fields the rules read through `ctx.values` (e.g. `sameAs('password')`) */\n const deps = ref<string[]>([])\n let token = 0\n\n async function run(): Promise<string | null> {\n const t = ++token\n if (disabled.value || !active.value) {\n result.value = null\n pending.value = false\n return null\n }\n pending.value = true\n const read = new Set<string>()\n const all = form?.values() ?? {}\n const values = new Proxy(all, {\n get(target, key) {\n if (typeof key === 'string') read.add(key)\n return Reflect.get(target, key)\n },\n })\n let message: string | null = null\n try {\n message = await runRules(ruleList.value, opts.value(), { locale, values })\n const name = opts.name()\n if (!message && form && name && form.hasSchema()) message = await form.schemaError(name)\n } catch (e) {\n console.error('[m3ui] a validation rule threw:', e)\n }\n if (t === token) {\n result.value = message\n pending.value = false\n const next = [...read]\n // Only a real change: a new array every run would re-trigger the deps watcher below, forever\n if (next.length !== deps.value.length || next.some((k, i) => k !== deps.value[i])) deps.value = next\n }\n return message\n }\n\n const mode = () => opts.validateOn() ?? form?.validateOn() ?? 'blur'\n let resetting = false\n let timer: ReturnType<typeof setTimeout> | undefined\n const debounceMs = () => opts.validateDebounce?.() ?? form?.validateDebounce() ?? 0\n /** Re-checks now, or after the debounce while the value keeps changing (pending meanwhile) */\n function schedule() {\n clearTimeout(timer)\n const ms = debounceMs()\n if (ms <= 0 || !active.value || disabled.value) return run()\n pending.value = true\n token++ // a check already running is stale now\n timer = setTimeout(run, ms)\n }\n onBeforeUnmount(() => clearTimeout(timer))\n\n /** An outside error (MForm `errors`) hides once its field changes, until a new `errors` object comes */\n const dismissed = ref(false)\n if (form) watch(() => form.externalErrorsKey(), () => (dismissed.value = false))\n\n watch(opts.value, () => {\n if (mode() === 'input' && !resetting) shown.value = true\n if (form && !form.keepErrors() && !resetting) dismissed.value = true\n schedule()\n }, { deep: true })\n // Not the rules array itself: an inline `:rules=\"[...]\"` is a new array on every render of the parent, and\n // re-checking then would re-run every field's (async) rules on any keystroke anywhere. Its length changes when\n // rules are really swapped (`:rules=\"company ? [required()] : []\"`); `required` and `disabled` are watched too\n watch([() => ruleList.value.length, () => !!opts.required(), disabled], () => run())\n // Cross-field rules: re-check when a field they read changes, but only once this one is on display\n // (compared value by value: the getter returns a new array whenever any field of the form changes)\n watch(\n () => (form ? deps.value.map((k) => form.values()[k]) : []),\n (now, before) => {\n const changed = now.length !== before.length || now.some((v, i) => !Object.is(v, before[i]))\n if (changed && shown.value) run()\n },\n )\n onMounted(run)\n\n function onBlur() {\n if (mode() !== 'submit') shown.value = true\n }\n\n async function validate(): Promise<boolean> {\n clearTimeout(timer)\n shown.value = true\n opts.onValidate?.()\n return !(await run())\n }\n\n function resetValidation() {\n clearTimeout(timer)\n token++\n shown.value = false\n pending.value = false\n run()\n }\n\n const initial = (() => {\n const v = opts.value()\n return Array.isArray(v) ? [...v] : v\n })()\n\n async function reset() {\n if (opts.setValue) {\n resetting = true\n opts.setValue(Array.isArray(initial) ? [...initial] : initial)\n await nextTick()\n resetting = false\n }\n resetValidation()\n }\n\n const external = computed(() => {\n const name = opts.name()\n return form && name && !dismissed.value ? form.externalError(name) : null\n })\n const own = computed(() => (shown.value ? result.value : null))\n\n /** The message to show under the field (null = none) */\n const message = computed<string | null>(() => {\n const e = opts.error()\n if (typeof e === 'string' && e) return e\n if (e === true) return opts.errorLabel() || own.value || external.value\n return external.value || own.value\n })\n const hasError = computed(() => !!opts.error() || !!external.value || !!own.value)\n\n if (form) {\n let unregister: (() => void) | undefined\n onMounted(() => {\n unregister = form.register({\n name: opts.name,\n value: opts.value,\n validate,\n resetValidation,\n reset,\n focus: opts.focus,\n el: opts.el,\n error: () => (hasError.value ? message.value ?? '' : null),\n valid: () => !result.value && !pending.value,\n pending: () => pending.value,\n })\n })\n onBeforeUnmount(() => unregister?.())\n }\n\n return {\n /** Error state (red border/label) */\n hasError,\n /** Message under the field, or null */\n message,\n /** id for the message element, to point `aria-describedby` at */\n messageId,\n /** Whether async rules are still running */\n pending,\n /** The field's own disabled state merged with its `MForm`'s */\n disabled,\n /** Call from the field's blur */\n onBlur,\n validate,\n resetValidation,\n reset,\n }\n}\n"],"mappings":";;;AA+CA,SAAgBC,EAAiB,GAAyC;CACxE,OAAO,OAAOC,KAAS,cAAYA,KAAiB,eAAeA;AACrE;AAGA,SAAgBC,EAAS,GAAmE;CAC1F,OAAO,OAAOC,KAAY,YAAYA,IAAmBA,EAAQ,MAAMA;AACzE;AAGA,eAAsBC,EAAQ,GAAsB,GAAgB,GAAgD;CAClH,IAAIJ,EAAiBC,CAAI,GAAG;EAE1B,IAAMI,KAAQ,MADOJ,EAAK,YAAY,CAAC,SAASK,CAAK,EAAA,CAChC,SAAS;EAC9B,OAAOD,IAAQA,EAAM,WAAWE,EAAI,OAAO,oBAAoB;CACjE;CACA,IAAMC,IAAS,MAAMP,EAAKK,GAAOC,CAAG;CAGpC,OAFIC,MAAW,MAAQA,KAAmC,OAAa,OACnEA,MAAW,KAAcD,EAAI,OAAO,oBACjCC,KAAUD,EAAI,OAAO;AAC9B;AAGA,eAAsBE,EAAS,GAAyB,GAAgB,GAAgD;CACtH,KAAK,IAAMR,KAAQS,GAAO;EACxB,IAAMC,IAAU,MAAMP,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ACF;AACF"}
1
+ {"version":3,"file":"_useFieldValidation-B0B44M_t.js","names":["useLocale","isStandardSchema","rule","issueKey","segment","runRule","issue","value","ctx","result","runRules","rules","message","isEmpty","lengthOf","toNumber","REQUIRED_RULE","required","locale","EMAIL_RE","email","url","u","minLength","min","maxLength","max","pattern","re","sameAs","other","values","FORM_KEY","useFocusLeave","check","open","root","active","onLeave","watch","now","was","useFieldValidation","form","inject","messageId","useId","disabled","computed","opts","ruleList","r","list","empty","own","mark","fieldRequired","ref","shown","pending","deps","token","run","t","read","all","key","target","name","next","k","i","mode","resetting","timer","debounceMs","schedule","ms","dismissed","before","v","onMounted","onBlur","validate","resetValidation","initial","reset","nextTick","external","hasError","unregister","onBeforeUnmount"],"sources":["../src/composables/validation.ts","../src/composables/_useFieldValidation.ts"],"sourcesContent":["import type { M3Locale } from './useLocale'\n\n/**\n * The Standard Schema interface (https://standardschema.dev), implemented by zod (3.24+), valibot (1.0+),\n * arktype, yup (1.7+) and others. A copy of the spec's types, so the lib doesn't depend on any of them:\n * pass a schema straight to a field's `rules` or to `MForm`'s `schema`.\n */\nexport interface StandardSchemaV1<Input = unknown, Output = Input> {\n readonly '~standard': {\n readonly version: 1\n readonly vendor: string\n readonly validate: (value: unknown) => StandardSchemaResult<Output> | Promise<StandardSchemaResult<Output>>\n readonly types?: { readonly input: Input; readonly output: Output }\n }\n}\n\nexport interface StandardSchemaIssue {\n readonly message: string\n readonly path?: ReadonlyArray<PropertyKey | { readonly key: PropertyKey }>\n}\n\nexport type StandardSchemaResult<Output> =\n | { readonly value: Output; readonly issues?: undefined }\n | { readonly issues: ReadonlyArray<StandardSchemaIssue> }\n\n/** What a rule receives besides the value */\nexport interface ValidationContext {\n /** The active locale, for messages */\n locale: M3Locale\n /** The values of every named field of the surrounding `MForm` (empty outside one) */\n values: Record<string, unknown>\n}\n\n/**\n * `true`, `undefined` or `null` = valid; a string = invalid with that message; `false` = invalid with the\n * locale's generic `validationInvalid` message\n */\nexport type ValidationResult = boolean | string | null | undefined\n\n/** A function `(value, ctx) => true | 'message'` (may be async), or a Standard Schema (zod, valibot…) */\nexport type ValidationRule<T = any> =\n | ((value: T, ctx: ValidationContext) => ValidationResult | Promise<ValidationResult>)\n | StandardSchemaV1\n\n/** When a field checks its rules and shows the result */\nexport type ValidateOn = 'blur' | 'input' | 'submit'\n\nexport function isStandardSchema(rule: unknown): rule is StandardSchemaV1 {\n return typeof rule === 'object' && rule !== null && '~standard' in rule\n}\n\n/** The key of a Standard Schema issue path segment */\nexport function issueKey(segment: PropertyKey | { readonly key: PropertyKey }): PropertyKey {\n return typeof segment === 'object' && segment !== null ? segment.key : segment\n}\n\n/** Runs one rule: the error message, or null when it passes */\nexport async function runRule(rule: ValidationRule, value: unknown, ctx: ValidationContext): Promise<string | null> {\n if (isStandardSchema(rule)) {\n const result = await rule['~standard'].validate(value)\n const issue = result.issues?.[0]\n return issue ? issue.message || ctx.locale.validationInvalid : null\n }\n const result = await rule(value, ctx)\n if (result === true || result === undefined || result === null) return null\n if (result === false) return ctx.locale.validationInvalid\n return result || ctx.locale.validationInvalid\n}\n\n/** Runs rules in order and stops at the first that fails */\nexport async function runRules(rules: ValidationRule[], value: unknown, ctx: ValidationContext): Promise<string | null> {\n for (const rule of rules) {\n const message = await runRule(rule, value, ctx)\n if (message) return message\n }\n return null\n}\n\n/** Whether a value counts as \"not filled in\": null/undefined, blank string, empty array, `false` (an unticked checkbox) */\nexport function isEmpty(value: unknown): boolean {\n if (value === null || value === undefined || value === false) return true\n if (typeof value === 'string') return value.trim() === ''\n if (Array.isArray(value)) return value.length === 0\n if (value instanceof Set || value instanceof Map) return value.size === 0\n return false\n}\n\nfunction lengthOf(value: unknown): number {\n if (typeof value === 'string' || Array.isArray(value)) return value.length\n if (value instanceof Set || value instanceof Map) return value.size\n return String(value).length\n}\n\nfunction toNumber(value: unknown): number {\n return typeof value === 'number' ? value : Number(String(value).trim())\n}\n\n// Built-in rules. Every one but `required` passes on an empty value, so an optional field stays optional:\n// `[email()]` accepts '' and `[required(), email()]` doesn't.\n\n/** Marks the rules `required()` makes, so a field's `required` prop doesn't add a second one in front */\nexport const REQUIRED_RULE = Symbol('m3-required-rule')\n\n/**\n * The value must be filled in (see `isEmpty`; a field may define its own \"empty\", e.g. a date range needs both\n * ends). Given in `rules`, it replaces the check the field's `required` prop adds, so its message is the one shown\n */\nexport function required(message?: string): ValidationRule {\n const rule: ValidationRule = (value, { locale }) => !isEmpty(value) || message || locale.validationRequired\n // Its message (or true): a field with its own \"empty\" test rebuilds the check with it\n ;(rule as any)[REQUIRED_RULE] = message ?? true\n return rule\n}\n\n// Same pattern as the browser's own <input type=\"email\"> check (WHATWG), which is what users expect\nconst EMAIL_RE = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/\n\n/** An email address (the browser's own rule, plus a dot in the domain) */\nexport function email(message?: string): ValidationRule {\n return (value, { locale }) => isEmpty(value) || EMAIL_RE.test(String(value).trim()) || message || locale.validationEmail\n}\n\n/** An absolute http(s) URL */\nexport function url(message?: string): ValidationRule {\n return (value, { locale }) => {\n if (isEmpty(value)) return true\n try {\n const u = new URL(String(value).trim())\n if (u.protocol === 'http:' || u.protocol === 'https:') return true\n } catch { /* invalid */ }\n return message || locale.validationUrl\n }\n}\n\n/** At least `min` characters (strings) or items (arrays) */\nexport function minLength(min: number, message?: string): ValidationRule {\n return (value, { locale }) =>\n isEmpty(value) || lengthOf(value) >= min ||\n message || (Array.isArray(value) ? locale.validationMinItems : locale.validationMinLength).replace('{min}', String(min))\n}\n\n/** At most `max` characters (strings) or items (arrays) */\nexport function maxLength(max: number, message?: string): ValidationRule {\n return (value, { locale }) =>\n isEmpty(value) || lengthOf(value) <= max ||\n message || (Array.isArray(value) ? locale.validationMaxItems : locale.validationMaxLength).replace('{max}', String(max))\n}\n\n/** A number (or numeric string) of at least `min` */\nexport function min(min: number, message?: string): ValidationRule {\n return (value, { locale }) => isEmpty(value) || toNumber(value) >= min || message || locale.validationMin.replace('{min}', String(min))\n}\n\n/** A number (or numeric string) of at most `max` */\nexport function max(max: number, message?: string): ValidationRule {\n return (value, { locale }) => isEmpty(value) || toNumber(value) <= max || message || locale.validationMax.replace('{max}', String(max))\n}\n\n/** Matches a regular expression */\nexport function pattern(re: RegExp, message?: string): ValidationRule {\n return (value, { locale }) => {\n if (isEmpty(value)) return true\n re.lastIndex = 0 // a /g or /y regex keeps state between test() calls\n return re.test(String(value)) || message || locale.validationPattern\n }\n}\n\n/**\n * Equals another value: the name of a field in the same `MForm` (e.g. 'password' for a confirmation field),\n * or a getter\n */\nexport function sameAs(other: string | (() => unknown), message?: string): ValidationRule {\n return (value, { locale, values }) => {\n if (isEmpty(value)) return true\n const target = typeof other === 'function' ? other() : values[other]\n return value === target || message || locale.validationSameAs\n }\n}\n","import { computed, inject, nextTick, onBeforeUnmount, onMounted, ref, useId, watch, type InjectionKey } from 'vue'\nimport { useLocale } from './useLocale'\nimport { REQUIRED_RULE, isEmpty, runRules, type ValidateOn, type ValidationRule } from './validation'\n\n/** @internal What a field registers with its `MForm` */\nexport interface FormField {\n name: () => string | undefined\n value: () => unknown\n /** Checks the rules, shows the result, resolves to whether its own rules pass */\n validate: () => Promise<boolean>\n resetValidation: () => void\n reset: () => Promise<void>\n focus: () => void\n el: () => Element | null | undefined\n /** The message on display, if any */\n error: () => string | null\n /** Whether its rules pass right now (checked silently, whether or not it's shown yet) */\n valid: () => boolean\n pending: () => boolean\n}\n\n/** @internal Provided by `MForm` */\nexport interface FormContext {\n register: (field: FormField) => () => void\n /** Every named field's value, by name */\n values: () => Record<string, unknown>\n /** An error given from outside (`MForm`'s `errors` prop) */\n externalError: (name: string) => string | null\n hasSchema: () => boolean\n /** The form schema's first issue for this field */\n schemaError: (name: string) => Promise<string | null>\n validateOn: () => ValidateOn | undefined\n /** Default debounce (ms) for re-checks while the value changes */\n validateDebounce: () => number | undefined\n /** The `errors` object itself: a new one (a new server response) shows its errors again */\n externalErrorsKey: () => unknown\n /** Keep an outside error after its field changes, instead of hiding it */\n keepErrors: () => boolean\n disabled: () => boolean\n}\n\n/** @internal */\nexport const FORM_KEY: InjectionKey<FormContext> = Symbol('m3-form')\n\n/**\n * @internal \"Blur\" for a field made of several focusable parts (stepper buttons, chips, a popup panel): calls\n * `onLeave` once focus has left `root` for good, not while it moves between its parts or while `open` (its\n * teleported panel, which sits outside `root` in the DOM) is showing. Closing the panel with focus outside\n * counts as leaving. Bind the returned handler to the root's `@focusout`.\n */\nexport function useFocusLeave(root: () => Element | null | undefined, onLeave: () => void, open?: () => boolean) {\n function check() {\n if (open?.()) return\n const r = root()\n const active = document.activeElement\n if (r && active && r.contains(active)) return\n onLeave()\n }\n if (open) watch(open, (now, was) => { if (!now && was) setTimeout(check) })\n // Focus lands on its next element after focusout: look once it has\n return () => { setTimeout(check) }\n}\n\nexport interface FieldValidationOptions {\n value: () => unknown\n rules: () => ValidationRule | ValidationRule[] | undefined\n required: () => boolean | undefined\n error: () => boolean | string | undefined\n errorLabel: () => string | undefined\n name: () => string | undefined\n validateOn: () => ValidateOn | undefined\n /** Wait this long (ms) after the value stops changing before re-checking (async rules: one request, not one per key) */\n validateDebounce?: () => number | undefined\n disabled: () => boolean | undefined\n focus: () => void\n el: () => Element | null | undefined\n /** Writes a value back through v-model (used by `MForm`'s `reset()`) */\n setValue?: (value: unknown) => void\n /** What \"not filled in\" means for `required`, when `isEmpty` isn't it (a date range needs both ends) */\n isEmpty?: (value: unknown) => boolean\n /** Called when the field is validated on demand (`validate()`, an `MForm` submit), to reveal sub-parts' own errors */\n onValidate?: () => void\n}\n\n/**\n * @internal The validation every form field shares: its own `rules` (plus `required` inside an `MForm` or\n * next to other rules), errors from outside (the `error` prop, `MForm`'s `errors`, its `schema`), when to show\n * them (`validateOn`), and registration with the surrounding `MForm`.\n *\n * Priority of what's shown: a string `error` → `error: true` with `errorLabel` → `MForm`'s `errors[name]`\n * → the field's own rules.\n */\nexport function useFieldValidation(opts: FieldValidationOptions) {\n const form = inject(FORM_KEY, null)\n const locale = useLocale()\n const messageId = useId()\n\n const disabled = computed(() => !!opts.disabled() || !!form?.disabled())\n\n const ruleList = computed<ValidationRule[]>(() => {\n const r = opts.rules()\n const list = r ? (Array.isArray(r) ? r : [r]) : []\n // `required` only validates where validation is in use, so a plain field keeps today's behavior\n // (just the asterisk and the native attribute)\n const empty = opts.isEmpty ?? isEmpty\n // A `required()` in the rules: use the field's own \"empty\" with its message, instead of a second check\n const own = list.map((r) => {\n const mark = (r as any)?.[REQUIRED_RULE]\n if (mark === undefined || !opts.isEmpty) return r\n const fieldRequired: ValidationRule = (value, { locale }) => !empty(value) || (typeof mark === 'string' ? mark : locale.validationRequired)\n ;(fieldRequired as any)[REQUIRED_RULE] = mark\n return fieldRequired\n })\n if (!(opts.required() && (form || own.length))) return own\n if (own.some((r) => (r as any)?.[REQUIRED_RULE] !== undefined)) return own\n const required: ValidationRule = (value, { locale }) => !empty(value) || locale.validationRequired\n return [required, ...own]\n })\n const active = computed(() => ruleList.value.length > 0 || (!!form && !!opts.name() && form.hasSchema()))\n\n /** The rules' verdict, kept up to date silently; only displayed once `shown` */\n const result = ref<string | null>(null)\n const shown = ref(false)\n const pending = ref(false)\n /** Names of other fields the rules read through `ctx.values` (e.g. `sameAs('password')`) */\n const deps = ref<string[]>([])\n let token = 0\n\n async function run(): Promise<string | null> {\n const t = ++token\n if (disabled.value || !active.value) {\n result.value = null\n pending.value = false\n return null\n }\n pending.value = true\n const read = new Set<string>()\n const all = form?.values() ?? {}\n const values = new Proxy(all, {\n get(target, key) {\n if (typeof key === 'string') read.add(key)\n return Reflect.get(target, key)\n },\n })\n let message: string | null = null\n try {\n message = await runRules(ruleList.value, opts.value(), { locale, values })\n const name = opts.name()\n if (!message && form && name && form.hasSchema()) message = await form.schemaError(name)\n } catch (e) {\n console.error('[m3ui] a validation rule threw:', e)\n }\n if (t === token) {\n result.value = message\n pending.value = false\n const next = [...read]\n // Only a real change: a new array every run would re-trigger the deps watcher below, forever\n if (next.length !== deps.value.length || next.some((k, i) => k !== deps.value[i])) deps.value = next\n }\n return message\n }\n\n const mode = () => opts.validateOn() ?? form?.validateOn() ?? 'blur'\n let resetting = false\n let timer: ReturnType<typeof setTimeout> | undefined\n const debounceMs = () => opts.validateDebounce?.() ?? form?.validateDebounce() ?? 0\n /** Re-checks now, or after the debounce while the value keeps changing (pending meanwhile) */\n function schedule() {\n clearTimeout(timer)\n const ms = debounceMs()\n if (ms <= 0 || !active.value || disabled.value) return run()\n pending.value = true\n token++ // a check already running is stale now\n timer = setTimeout(run, ms)\n }\n onBeforeUnmount(() => clearTimeout(timer))\n\n /** An outside error (MForm `errors`) hides once its field changes, until a new `errors` object comes */\n const dismissed = ref(false)\n if (form) watch(() => form.externalErrorsKey(), () => (dismissed.value = false))\n\n watch(opts.value, () => {\n if (mode() === 'input' && !resetting) shown.value = true\n if (form && !form.keepErrors() && !resetting) dismissed.value = true\n schedule()\n }, { deep: true })\n // Not the rules array itself: an inline `:rules=\"[...]\"` is a new array on every render of the parent, and\n // re-checking then would re-run every field's (async) rules on any keystroke anywhere. Its length changes when\n // rules are really swapped (`:rules=\"company ? [required()] : []\"`); `required` and `disabled` are watched too\n watch([() => ruleList.value.length, () => !!opts.required(), disabled], () => run())\n // Cross-field rules: re-check when a field they read changes, but only once this one is on display\n // (compared value by value: the getter returns a new array whenever any field of the form changes)\n watch(\n () => (form ? deps.value.map((k) => form.values()[k]) : []),\n (now, before) => {\n const changed = now.length !== before.length || now.some((v, i) => !Object.is(v, before[i]))\n if (changed && shown.value) run()\n },\n )\n onMounted(run)\n\n function onBlur() {\n if (mode() !== 'submit') shown.value = true\n }\n\n async function validate(): Promise<boolean> {\n clearTimeout(timer)\n shown.value = true\n opts.onValidate?.()\n return !(await run())\n }\n\n function resetValidation() {\n clearTimeout(timer)\n token++\n shown.value = false\n pending.value = false\n run()\n }\n\n const initial = (() => {\n const v = opts.value()\n return Array.isArray(v) ? [...v] : v\n })()\n\n async function reset() {\n if (opts.setValue) {\n resetting = true\n opts.setValue(Array.isArray(initial) ? [...initial] : initial)\n await nextTick()\n resetting = false\n }\n resetValidation()\n }\n\n const external = computed(() => {\n const name = opts.name()\n return form && name && !dismissed.value ? form.externalError(name) : null\n })\n const own = computed(() => (shown.value ? result.value : null))\n\n /** The message to show under the field (null = none) */\n const message = computed<string | null>(() => {\n const e = opts.error()\n if (typeof e === 'string' && e) return e\n if (e === true) return opts.errorLabel() || own.value || external.value\n return external.value || own.value\n })\n const hasError = computed(() => !!opts.error() || !!external.value || !!own.value)\n\n if (form) {\n let unregister: (() => void) | undefined\n onMounted(() => {\n unregister = form.register({\n name: opts.name,\n value: opts.value,\n validate,\n resetValidation,\n reset,\n focus: opts.focus,\n el: opts.el,\n error: () => (hasError.value ? message.value ?? '' : null),\n valid: () => !result.value && !pending.value,\n pending: () => pending.value,\n })\n })\n onBeforeUnmount(() => unregister?.())\n }\n\n return {\n /** Error state (red border/label) */\n hasError,\n /** Message under the field, or null */\n message,\n /** id for the message element, to point `aria-describedby` at */\n messageId,\n /** Whether async rules are still running */\n pending,\n /** The field's own disabled state merged with its `MForm`'s */\n disabled,\n /** Call from the field's blur */\n onBlur,\n validate,\n resetValidation,\n reset,\n }\n}\n"],"mappings":";;;AA+CA,SAAgBC,EAAiB,GAAyC;CACxE,OAAO,OAAOC,KAAS,cAAYA,KAAiB,eAAeA;AACrE;AAGA,SAAgBC,EAAS,GAAmE;CAC1F,OAAO,OAAOC,KAAY,YAAYA,IAAmBA,EAAQ,MAAMA;AACzE;AAGA,eAAsBC,EAAQ,GAAsB,GAAgB,GAAgD;CAClH,IAAIJ,EAAiBC,CAAI,GAAG;EAE1B,IAAMI,KAAQ,MADOJ,EAAK,YAAY,CAAC,SAASK,CAAK,EAAA,CAChC,SAAS;EAC9B,OAAOD,IAAQA,EAAM,WAAWE,E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