@m3ui-vue/m3ui-vue 0.5.9 → 0.6.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 (76) hide show
  1. package/README.md +26 -1
  2. package/dist/{MMenuItem-DyY4zhRA.js → MMenuItem-DbbrJhFE.js} +2 -2
  3. package/dist/{MMenuItem-DyY4zhRA.js.map → MMenuItem-DbbrJhFE.js.map} +1 -1
  4. package/dist/barcode.d.ts +1 -0
  5. package/dist/barcode.js +51 -0
  6. package/dist/barcode.js.map +1 -0
  7. package/dist/code-editor.js +1 -1
  8. package/dist/components/MAutocomplete.vue.d.ts +1 -1
  9. package/dist/components/MBarcode.vue.d.ts +35 -0
  10. package/dist/components/MButton.vue.d.ts +1 -1
  11. package/dist/components/MButtonGroup.vue.d.ts +1 -1
  12. package/dist/components/MChatBubble.vue.d.ts +1 -1
  13. package/dist/components/MCircleProgressBar.vue.d.ts +1 -1
  14. package/dist/components/MCopyButton.vue.d.ts +31 -0
  15. package/dist/components/MExportButton.vue.d.ts +43 -0
  16. package/dist/components/MFab.vue.d.ts +1 -1
  17. package/dist/components/MKbd.vue.d.ts +12 -0
  18. package/dist/components/MMultiAutocomplete.vue.d.ts +1 -1
  19. package/dist/components/MMultiSelect.vue.d.ts +1 -1
  20. package/dist/components/MPasswordMeter.vue.d.ts +17 -0
  21. package/dist/components/MPinInput.vue.d.ts +35 -0
  22. package/dist/components/MQRCode.vue.d.ts +35 -0
  23. package/dist/components/MRating.vue.d.ts +1 -1
  24. package/dist/components/MRelativeTime.vue.d.ts +8 -0
  25. package/dist/components/MSelect.vue.d.ts +1 -1
  26. package/dist/components/MShader.vue.d.ts +2 -2
  27. package/dist/components/MSignaturePad.vue.d.ts +37 -0
  28. package/dist/components/MSlider.vue.d.ts +1 -1
  29. package/dist/components/MSplitButton.vue.d.ts +1 -1
  30. package/dist/components/MSubtitle.vue.d.ts +1 -1
  31. package/dist/components/MTerminal.vue.d.ts +2 -2
  32. package/dist/components/MTitle.vue.d.ts +1 -1
  33. package/dist/components/MWindow.vue.d.ts +1 -1
  34. package/dist/composables/useLocale.d.ts +2 -0
  35. package/dist/index.d.ts +7 -0
  36. package/dist/locales/index.js +7 -0
  37. package/dist/locales/index.js.map +1 -1
  38. package/dist/m3ui.js +1194 -724
  39. package/dist/m3ui.js.map +1 -1
  40. package/dist/qrcode.d.ts +1 -0
  41. package/dist/qrcode.js +117 -0
  42. package/dist/qrcode.js.map +1 -0
  43. package/dist/rich-text-editor.js +2 -2
  44. package/dist/{useLocale-QCIVDYWx.js → useLocale-BKsIWNix.js} +2 -1
  45. package/dist/useLocale-BKsIWNix.js.map +1 -0
  46. package/package.json +23 -3
  47. package/src/__tests__/MBarcode.test.ts +40 -0
  48. package/src/__tests__/MCopyButton.test.ts +49 -0
  49. package/src/__tests__/MExportButton.test.ts +64 -0
  50. package/src/__tests__/MKbd.test.ts +33 -0
  51. package/src/__tests__/MPasswordMeter.test.ts +43 -0
  52. package/src/__tests__/MPinInput.test.ts +138 -0
  53. package/src/__tests__/MQRCode.test.ts +58 -0
  54. package/src/__tests__/MRelativeTime.test.ts +43 -0
  55. package/src/__tests__/MSignaturePad.test.ts +62 -0
  56. package/src/barcode.ts +1 -0
  57. package/src/components/MBarcode.vue +61 -0
  58. package/src/components/MCopyButton.vue +62 -0
  59. package/src/components/MExportButton.vue +73 -0
  60. package/src/components/MKbd.vue +36 -0
  61. package/src/components/MPasswordMeter.vue +56 -0
  62. package/src/components/MPinInput.vue +202 -0
  63. package/src/components/MQRCode.vue +131 -0
  64. package/src/components/MRelativeTime.vue +68 -0
  65. package/src/components/MSignaturePad.vue +138 -0
  66. package/src/composables/useLocale.ts +5 -0
  67. package/src/index.ts +7 -0
  68. package/src/locales/de.ts +2 -0
  69. package/src/locales/es.ts +2 -0
  70. package/src/locales/fr.ts +2 -0
  71. package/src/locales/ja.ts +2 -0
  72. package/src/locales/ko.ts +2 -0
  73. package/src/locales/pt.ts +2 -0
  74. package/src/locales/zh.ts +2 -0
  75. package/src/qrcode.ts +1 -0
  76. package/dist/useLocale-QCIVDYWx.js.map +0 -1
@@ -0,0 +1 @@
1
+ export { default as MQRCode } from './components/MQRCode.vue';
package/dist/qrcode.js ADDED
@@ -0,0 +1,117 @@
1
+ import { Fragment as e, computed as t, createElementBlock as n, createElementVNode as r, createTextVNode as i, defineComponent as a, normalizeStyle as o, openBlock as s, renderList as c, renderSlot as l, toDisplayString as u } from "vue";
2
+ import d from "qrcode-generator";
3
+ //#region src/components/MQRCode.vue?vue&type=script&setup=true&lang.ts
4
+ var f = [
5
+ "width",
6
+ "height",
7
+ "viewBox",
8
+ "aria-label"
9
+ ], p = [
10
+ "width",
11
+ "height",
12
+ "rx",
13
+ "ry",
14
+ "fill"
15
+ ], m = ["d", "fill"], h = [
16
+ "x",
17
+ "y",
18
+ "width",
19
+ "height",
20
+ "fill"
21
+ ], g = /* @__PURE__ */ a({
22
+ __name: "MQRCode",
23
+ props: {
24
+ value: {},
25
+ size: { default: 200 },
26
+ margin: { default: 4 },
27
+ errorCorrectionLevel: { default: "M" },
28
+ color: { default: "#000000" },
29
+ background: { default: "#ffffff" },
30
+ label: {},
31
+ rounded: {
32
+ type: Boolean,
33
+ default: !0
34
+ },
35
+ moduleStyle: { default: "square" }
36
+ },
37
+ setup(a) {
38
+ let g = a, _ = t(() => {
39
+ try {
40
+ let e = d(0, g.errorCorrectionLevel);
41
+ return e.addData(g.value), e.make(), {
42
+ qr: e,
43
+ error: null
44
+ };
45
+ } catch (e) {
46
+ return {
47
+ qr: null,
48
+ error: typeof e == "string" ? e : e instanceof Error ? e.message : "Failed to generate QR code"
49
+ };
50
+ }
51
+ }), v = t(() => _.value.qr), y = t(() => _.value.error), b = t(() => v.value?.getModuleCount() ?? 0), x = t(() => b.value + g.margin * 2), S = t(() => x.value > 0 ? g.size / x.value : 0), C = t(() => g.rounded ? g.size * .06 : 0);
52
+ function w(e, t, n, r, i, a, o) {
53
+ return `M${e + r},${t} H${e + n - i} A${i},${i} 0 0 1 ${e + n},${t + i} V${t + n - a} A${a},${a} 0 0 1 ${e + n - a},${t + n} H${e + o} A${o},${o} 0 0 1 ${e},${t + n - o} V${t + r} A${r},${r} 0 0 1 ${e + r},${t} Z`;
54
+ }
55
+ let T = t(() => {
56
+ let e = [], t = v.value;
57
+ if (!t) return e;
58
+ let n = b.value, r = S.value, i = (e, r) => e >= 0 && e < n && r >= 0 && r < n && t.isDark(e, r);
59
+ for (let t = 0; t < n; t++) for (let a = 0; a < n; a++) {
60
+ if (!i(t, a)) continue;
61
+ let n = (a + g.margin) * r, o = (t + g.margin) * r;
62
+ if (g.moduleStyle !== "dots") {
63
+ e.push({
64
+ x: n,
65
+ y: o
66
+ });
67
+ continue;
68
+ }
69
+ let s = r / 2, c = i(t - 1, a), l = i(t + 1, a), u = i(t, a - 1), d = i(t, a + 1);
70
+ e.push({
71
+ x: n,
72
+ y: o,
73
+ d: w(n, o, r, c || u ? 0 : s, c || d ? 0 : s, l || d ? 0 : s, l || u ? 0 : s)
74
+ });
75
+ }
76
+ return e;
77
+ });
78
+ return (t, d) => y.value ? (s(), n("div", {
79
+ key: 0,
80
+ class: "flex items-center justify-center text-body-small text-error",
81
+ style: o({
82
+ width: `${a.size}px`,
83
+ height: `${a.size}px`
84
+ })
85
+ }, [l(t.$slots, "error", {}, () => [i(u(y.value), 1)])], 4)) : (s(), n("svg", {
86
+ key: 1,
87
+ width: a.size,
88
+ height: a.size,
89
+ viewBox: `0 0 ${a.size} ${a.size}`,
90
+ role: "img",
91
+ "aria-label": a.label ?? a.value
92
+ }, [r("rect", {
93
+ x: "0",
94
+ y: "0",
95
+ width: a.size,
96
+ height: a.size,
97
+ rx: C.value,
98
+ ry: C.value,
99
+ fill: a.background
100
+ }, null, 8, p), a.moduleStyle === "dots" ? (s(!0), n(e, { key: 0 }, c(T.value, (e, t) => (s(), n("path", {
101
+ key: t,
102
+ d: e.d,
103
+ fill: a.color
104
+ }, null, 8, m))), 128)) : (s(!0), n(e, { key: 1 }, c(T.value, (e, t) => (s(), n("rect", {
105
+ key: t,
106
+ x: e.x,
107
+ y: e.y,
108
+ width: S.value,
109
+ height: S.value,
110
+ fill: a.color
111
+ }, null, 8, h))), 128))], 8, f));
112
+ }
113
+ });
114
+ //#endregion
115
+ export { g as MQRCode };
116
+
117
+ //# sourceMappingURL=qrcode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qrcode.js","names":[],"sources":["../src/components/MQRCode.vue","../src/components/MQRCode.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed } from 'vue'\nimport QRCode from 'qrcode-generator'\n\nconst props = withDefaults(\n defineProps<{\n value: string\n size?: number\n /** Quiet zone around the code, in modules. */\n margin?: number\n errorCorrectionLevel?: 'L' | 'M' | 'Q' | 'H'\n color?: string\n background?: string\n label?: string\n /** Rounds the outer container corners. */\n rounded?: boolean\n /** 'square' is the classic scannable pixel grid. 'dots' rounds each module — still fully scannable, just a softer look. */\n moduleStyle?: 'square' | 'dots'\n }>(),\n {\n size: 200,\n margin: 4,\n errorCorrectionLevel: 'M',\n color: '#000000',\n background: '#ffffff',\n rounded: true,\n moduleStyle: 'square',\n },\n)\n\n// qr and error are derived together in one computed so they can never be\n// read out of sync with each other (e.g. a template `v-if=\"error\"` seeing a\n// stale value from before `qr` — which sets it — was actually evaluated).\nconst result = computed(() => {\n try {\n const instance = QRCode(0, props.errorCorrectionLevel)\n instance.addData(props.value)\n instance.make()\n return { qr: instance, error: null as string | null }\n } catch (err) {\n // qrcode-generator throws plain strings (e.g. \"code length overflow...\")\n const message = typeof err === 'string' ? err : err instanceof Error ? err.message : 'Failed to generate QR code'\n return { qr: null, error: message }\n }\n})\n\nconst qr = computed(() => result.value.qr)\nconst error = computed(() => result.value.error)\n\nconst moduleCount = computed(() => qr.value?.getModuleCount() ?? 0)\nconst totalModules = computed(() => moduleCount.value + props.margin * 2)\nconst moduleSize = computed(() => (totalModules.value > 0 ? props.size / totalModules.value : 0))\nconst containerRadius = computed(() => (props.rounded ? props.size * 0.06 : 0))\n\n// A corner rounds only when neither of its two perpendicular neighbors is\n// also dark — otherwise adjacent modules (e.g. the finder-pattern squares,\n// or any run of touching pixels) would each round independently and leave\n// visible notches instead of merging into one smooth shape.\nfunction roundedRectPath(x: number, y: number, s: number, rTL: number, rTR: number, rBR: number, rBL: number): string {\n return `M${x + rTL},${y} H${x + s - rTR} A${rTR},${rTR} 0 0 1 ${x + s},${y + rTR} V${y + s - rBR} A${rBR},${rBR} 0 0 1 ${x + s - rBR},${y + s} H${x + rBL} A${rBL},${rBL} 0 0 1 ${x},${y + s - rBL} V${y + rTL} A${rTL},${rTL} 0 0 1 ${x + rTL},${y} Z`\n}\n\nconst cells = computed(() => {\n const result: { x: number; y: number; d?: string }[] = []\n const inst = qr.value\n if (!inst) return result\n const count = moduleCount.value\n const s = moduleSize.value\n const isDark = (row: number, col: number) => row >= 0 && row < count && col >= 0 && col < count && inst.isDark(row, col)\n\n for (let row = 0; row < count; row++) {\n for (let col = 0; col < count; col++) {\n if (!isDark(row, col)) continue\n const x = (col + props.margin) * s\n const y = (row + props.margin) * s\n\n if (props.moduleStyle !== 'dots') {\n result.push({ x, y })\n continue\n }\n\n const radius = s / 2\n const up = isDark(row - 1, col)\n const down = isDark(row + 1, col)\n const left = isDark(row, col - 1)\n const right = isDark(row, col + 1)\n result.push({\n x, y,\n d: roundedRectPath(\n x, y, s,\n up || left ? 0 : radius,\n up || right ? 0 : radius,\n down || right ? 0 : radius,\n down || left ? 0 : radius,\n ),\n })\n }\n }\n return result\n})\n</script>\n\n<template>\n <div v-if=\"error\" class=\"flex items-center justify-center text-body-small text-error\" :style=\"{ width: `${size}px`, height: `${size}px` }\">\n <slot name=\"error\">{{ error }}</slot>\n </div>\n <svg\n v-else\n :width=\"size\"\n :height=\"size\"\n :viewBox=\"`0 0 ${size} ${size}`\"\n role=\"img\"\n :aria-label=\"label ?? value\"\n >\n <rect x=\"0\" y=\"0\" :width=\"size\" :height=\"size\" :rx=\"containerRadius\" :ry=\"containerRadius\" :fill=\"background\" />\n <template v-if=\"moduleStyle === 'dots'\">\n <path v-for=\"(cell, i) in cells\" :key=\"i\" :d=\"cell.d\" :fill=\"color\" />\n </template>\n <template v-else>\n <rect\n v-for=\"(cell, i) in cells\"\n :key=\"i\"\n :x=\"cell.x\"\n :y=\"cell.y\"\n :width=\"moduleSize\"\n :height=\"moduleSize\"\n :fill=\"color\"\n />\n </template>\n </svg>\n</template>\n","<script setup lang=\"ts\">\nimport { computed } from 'vue'\nimport QRCode from 'qrcode-generator'\n\nconst props = withDefaults(\n defineProps<{\n value: string\n size?: number\n /** Quiet zone around the code, in modules. */\n margin?: number\n errorCorrectionLevel?: 'L' | 'M' | 'Q' | 'H'\n color?: string\n background?: string\n label?: string\n /** Rounds the outer container corners. */\n rounded?: boolean\n /** 'square' is the classic scannable pixel grid. 'dots' rounds each module — still fully scannable, just a softer look. */\n moduleStyle?: 'square' | 'dots'\n }>(),\n {\n size: 200,\n margin: 4,\n errorCorrectionLevel: 'M',\n color: '#000000',\n background: '#ffffff',\n rounded: true,\n moduleStyle: 'square',\n },\n)\n\n// qr and error are derived together in one computed so they can never be\n// read out of sync with each other (e.g. a template `v-if=\"error\"` seeing a\n// stale value from before `qr` — which sets it — was actually evaluated).\nconst result = computed(() => {\n try {\n const instance = QRCode(0, props.errorCorrectionLevel)\n instance.addData(props.value)\n instance.make()\n return { qr: instance, error: null as string | null }\n } catch (err) {\n // qrcode-generator throws plain strings (e.g. \"code length overflow...\")\n const message = typeof err === 'string' ? err : err instanceof Error ? err.message : 'Failed to generate QR code'\n return { qr: null, error: message }\n }\n})\n\nconst qr = computed(() => result.value.qr)\nconst error = computed(() => result.value.error)\n\nconst moduleCount = computed(() => qr.value?.getModuleCount() ?? 0)\nconst totalModules = computed(() => moduleCount.value + props.margin * 2)\nconst moduleSize = computed(() => (totalModules.value > 0 ? props.size / totalModules.value : 0))\nconst containerRadius = computed(() => (props.rounded ? props.size * 0.06 : 0))\n\n// A corner rounds only when neither of its two perpendicular neighbors is\n// also dark — otherwise adjacent modules (e.g. the finder-pattern squares,\n// or any run of touching pixels) would each round independently and leave\n// visible notches instead of merging into one smooth shape.\nfunction roundedRectPath(x: number, y: number, s: number, rTL: number, rTR: number, rBR: number, rBL: number): string {\n return `M${x + rTL},${y} H${x + s - rTR} A${rTR},${rTR} 0 0 1 ${x + s},${y + rTR} V${y + s - rBR} A${rBR},${rBR} 0 0 1 ${x + s - rBR},${y + s} H${x + rBL} A${rBL},${rBL} 0 0 1 ${x},${y + s - rBL} V${y + rTL} A${rTL},${rTL} 0 0 1 ${x + rTL},${y} Z`\n}\n\nconst cells = computed(() => {\n const result: { x: number; y: number; d?: string }[] = []\n const inst = qr.value\n if (!inst) return result\n const count = moduleCount.value\n const s = moduleSize.value\n const isDark = (row: number, col: number) => row >= 0 && row < count && col >= 0 && col < count && inst.isDark(row, col)\n\n for (let row = 0; row < count; row++) {\n for (let col = 0; col < count; col++) {\n if (!isDark(row, col)) continue\n const x = (col + props.margin) * s\n const y = (row + props.margin) * s\n\n if (props.moduleStyle !== 'dots') {\n result.push({ x, y })\n continue\n }\n\n const radius = s / 2\n const up = isDark(row - 1, col)\n const down = isDark(row + 1, col)\n const left = isDark(row, col - 1)\n const right = isDark(row, col + 1)\n result.push({\n x, y,\n d: roundedRectPath(\n x, y, s,\n up || left ? 0 : radius,\n up || right ? 0 : radius,\n down || right ? 0 : radius,\n down || left ? 0 : radius,\n ),\n })\n }\n }\n return result\n})\n</script>\n\n<template>\n <div v-if=\"error\" class=\"flex items-center justify-center text-body-small text-error\" :style=\"{ width: `${size}px`, height: `${size}px` }\">\n <slot name=\"error\">{{ error }}</slot>\n </div>\n <svg\n v-else\n :width=\"size\"\n :height=\"size\"\n :viewBox=\"`0 0 ${size} ${size}`\"\n role=\"img\"\n :aria-label=\"label ?? value\"\n >\n <rect x=\"0\" y=\"0\" :width=\"size\" :height=\"size\" :rx=\"containerRadius\" :ry=\"containerRadius\" :fill=\"background\" />\n <template v-if=\"moduleStyle === 'dots'\">\n <path v-for=\"(cell, i) in cells\" :key=\"i\" :d=\"cell.d\" :fill=\"color\" />\n </template>\n <template v-else>\n <rect\n v-for=\"(cell, i) in cells\"\n :key=\"i\"\n :x=\"cell.x\"\n :y=\"cell.y\"\n :width=\"moduleSize\"\n :height=\"moduleSize\"\n :fill=\"color\"\n />\n </template>\n </svg>\n</template>\n"],"mappings":"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"}
@@ -1,6 +1,6 @@
1
- import { r as e } from "./useLocale-QCIVDYWx.js";
1
+ import { r as e } from "./useLocale-BKsIWNix.js";
2
2
  import { t } from "./MIcon-CaEooCmZ.js";
3
- import { a as n, i as r, n as i, r as a, t as o } from "./MMenuItem-DyY4zhRA.js";
3
+ import { a as n, i as r, n as i, r as a, t as o } from "./MMenuItem-DbbrJhFE.js";
4
4
  import { t as s } from "./_plugin-vue_export-helper-B3ysoDQm.js";
5
5
  import { Fragment as c, computed as l, createCommentVNode as u, createElementBlock as d, createElementVNode as f, createTextVNode as p, createVNode as m, defineComponent as h, normalizeClass as g, normalizeStyle as _, onBeforeUnmount as v, onMounted as y, openBlock as b, ref as x, renderList as S, shallowRef as C, toDisplayString as w, watch as T, withCtx as E, withKeys as D } from "vue";
6
6
  //#region src/components/MRichTextEditor.vue?vue&type=script&setup=true&lang.ts
@@ -1,6 +1,7 @@
1
1
  import { inject as e, reactive as t, toValue as n, watchEffect as r } from "vue";
2
2
  //#region src/composables/useLocale.ts
3
3
  var i = {
4
+ lang: "en",
4
5
  search: "Search...",
5
6
  noResults: "No results",
6
7
  close: "Close",
@@ -85,4 +86,4 @@ function o() {
85
86
  //#endregion
86
87
  export { i as n, o as r, a as t };
87
88
 
88
- //# sourceMappingURL=useLocale-QCIVDYWx.js.map
89
+ //# sourceMappingURL=useLocale-BKsIWNix.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLocale-BKsIWNix.js","names":[],"sources":["../src/composables/useLocale.ts"],"sourcesContent":["import { inject, reactive, watchEffect, toValue, type InjectionKey, type MaybeRef } from 'vue'\n\nexport interface M3Locale {\n /** BCP-47 language tag (e.g. 'en', 'es', 'pt') — read by locale-aware components (MRelativeTime) that use Intl formatting. */\n lang: string\n\n // Common\n search: string\n noResults: string\n close: string\n cancel: string\n confirm: string\n loading: string\n\n // Navigation\n previous: string\n next: string\n today: string\n more: string\n\n // Tables\n selectedCount: string\n recordCount: string\n expand: string\n columns: string\n exportCsv: string\n noGroup: string\n\n // Tour\n finish: string\n\n // File upload\n dropText: string\n selectText: string\n maxSizePrefix: string\n remove: string\n\n // Pickers\n selectDate: string\n selectTime: string\n selectRange: string\n pickStart: string\n pickEnd: string\n previousMonth: string\n nextMonth: string\n\n // Scheduler\n dayView: string\n weekView: string\n\n // Transfer list\n available: string\n selected: string\n noItems: string\n moveAllRight: string\n moveRight: string\n moveLeft: string\n moveAllLeft: string\n\n // Command palette / Spotlight\n searchCommand: string\n navigateHint: string\n selectHint: string\n openHint: string\n closeHint: string\n\n // Infinite scroll\n loadingMore: string\n noMoreItems: string\n\n // Rich text editor\n bold: string\n italic: string\n underline: string\n strikethrough: string\n highlight: string\n bulletList: string\n orderedList: string\n blockquote: string\n code: string\n alignLeft: string\n alignCenter: string\n alignRight: string\n undo: string\n redo: string\n link: string\n image: string\n paragraph: string\n heading1: string\n heading2: string\n heading3: string\n insertLink: string\n insertImage: string\n imageUrlLabel: string\n insert: string\n\n // JSON editor\n jsonValid: string\n jsonInvalid: string\n jsonFormat: string\n jsonMinify: string\n\n // JSON viewer\n jsonElements: string\n jsonFields: string\n}\n\nexport const defaultLocale: M3Locale = {\n lang: 'en',\n\n search: 'Search...',\n noResults: 'No results',\n close: 'Close',\n cancel: 'Cancel',\n confirm: 'Confirm',\n loading: 'Loading',\n\n previous: 'Previous',\n next: 'Next',\n today: 'Today',\n more: 'more',\n\n selectedCount: 'selected',\n recordCount: 'record',\n expand: 'Expand',\n columns: 'Columns',\n exportCsv: 'Export CSV',\n noGroup: 'No group',\n\n finish: 'Finish',\n\n dropText: 'Drop files here or',\n selectText: 'browse',\n maxSizePrefix: 'Max.',\n remove: 'Remove',\n\n selectDate: 'Select date',\n selectTime: 'Select time',\n selectRange: 'Select range',\n pickStart: 'Select start',\n pickEnd: 'Select end',\n previousMonth: 'Previous month',\n nextMonth: 'Next month',\n\n dayView: 'Day',\n weekView: 'Week',\n\n available: 'Available',\n selected: 'Selected',\n noItems: 'No items',\n moveAllRight: 'Move all right',\n moveRight: 'Move selected right',\n moveLeft: 'Move selected left',\n moveAllLeft: 'Move all left',\n\n searchCommand: 'Search command...',\n navigateHint: 'navigate',\n selectHint: 'select',\n openHint: 'open',\n closeHint: 'close',\n\n loadingMore: 'Loading...',\n noMoreItems: 'No more items',\n\n bold: 'Bold',\n italic: 'Italic',\n underline: 'Underline',\n strikethrough: 'Strikethrough',\n highlight: 'Highlight',\n bulletList: 'Bullet list',\n orderedList: 'Ordered list',\n blockquote: 'Blockquote',\n code: 'Code',\n alignLeft: 'Align left',\n alignCenter: 'Align center',\n alignRight: 'Align right',\n undo: 'Undo',\n redo: 'Redo',\n link: 'Link',\n image: 'Image',\n paragraph: 'Paragraph',\n heading1: 'Heading 1',\n heading2: 'Heading 2',\n heading3: 'Heading 3',\n insertLink: 'Insert link',\n insertImage: 'Insert image',\n imageUrlLabel: 'Image URL',\n insert: 'Insert',\n\n jsonValid: 'Valid',\n jsonInvalid: 'Invalid',\n jsonFormat: 'Format',\n jsonMinify: 'Minify',\n\n jsonElements: 'elements',\n jsonFields: 'fields',\n}\n\nexport const M3_LOCALE_KEY: InjectionKey<MaybeRef<Partial<M3Locale>>> = Symbol('m3-locale')\n\nexport function useLocale(): M3Locale {\n const provided = inject(M3_LOCALE_KEY, {})\n const locale = reactive({ ...defaultLocale }) as M3Locale\n\n watchEffect(() => {\n Object.assign(locale, defaultLocale, toValue(provided))\n })\n\n return locale\n}\n"],"mappings":";;AA2GA,IAAa,IAA0B;CACrC,MAAM;CAEN,QAAQ;CACR,WAAW;CACX,OAAO;CACP,QAAQ;CACR,SAAS;CACT,SAAS;CAET,UAAU;CACV,MAAM;CACN,OAAO;CACP,MAAM;CAEN,eAAe;CACf,aAAa;CACb,QAAQ;CACR,SAAS;CACT,WAAW;CACX,SAAS;CAET,QAAQ;CAER,UAAU;CACV,YAAY;CACZ,eAAe;CACf,QAAQ;CAER,YAAY;CACZ,YAAY;CACZ,aAAa;CACb,WAAW;CACX,SAAS;CACT,eAAe;CACf,WAAW;CAEX,SAAS;CACT,UAAU;CAEV,WAAW;CACX,UAAU;CACV,SAAS;CACT,cAAc;CACd,WAAW;CACX,UAAU;CACV,aAAa;CAEb,eAAe;CACf,cAAc;CACd,YAAY;CACZ,UAAU;CACV,WAAW;CAEX,aAAa;CACb,aAAa;CAEb,MAAM;CACN,QAAQ;CACR,WAAW;CACX,eAAe;CACf,WAAW;CACX,YAAY;CACZ,aAAa;CACb,YAAY;CACZ,MAAM;CACN,WAAW;CACX,aAAa;CACb,YAAY;CACZ,MAAM;CACN,MAAM;CACN,MAAM;CACN,OAAO;CACP,WAAW;CACX,UAAU;CACV,UAAU;CACV,UAAU;CACV,YAAY;CACZ,aAAa;CACb,eAAe;CACf,QAAQ;CAER,WAAW;CACX,aAAa;CACb,YAAY;CACZ,YAAY;CAEZ,cAAc;CACd,YAAY;AACd,GAEa,IAA2D,OAAO,WAAW;AAE1F,SAAgB,IAAsB;CACpC,IAAM,IAAW,EAAO,GAAe,CAAC,CAAC,GACnC,IAAS,EAAS,EAAE,GAAG,EAAc,CAAC;CAM5C,OAJA,QAAkB;EAChB,OAAO,OAAO,GAAQ,GAAe,EAAQ,CAAQ,CAAC;CACxD,CAAC,GAEM;AACT"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m3ui-vue/m3ui-vue",
3
- "version": "0.5.9",
3
+ "version": "0.6.0",
4
4
  "description": "Material 3 component library for Vue 3 + Tailwind CSS v4",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -47,6 +47,14 @@
47
47
  "types": "./dist/terminal.d.ts",
48
48
  "import": "./dist/terminal.js"
49
49
  },
50
+ "./qrcode": {
51
+ "types": "./dist/qrcode.d.ts",
52
+ "import": "./dist/qrcode.js"
53
+ },
54
+ "./barcode": {
55
+ "types": "./dist/barcode.d.ts",
56
+ "import": "./dist/barcode.js"
57
+ },
50
58
  "./styles": "./dist/styles.css",
51
59
  "./theme": "./src/styles/theme.css",
52
60
  "./palettes": "./src/styles/palettes.css",
@@ -156,6 +164,15 @@
156
164
  },
157
165
  "vue-chartjs": {
158
166
  "optional": true
167
+ },
168
+ "material-symbols": {
169
+ "optional": true
170
+ },
171
+ "qrcode-generator": {
172
+ "optional": true
173
+ },
174
+ "jsbarcode": {
175
+ "optional": true
159
176
  }
160
177
  },
161
178
  "devDependencies": {
@@ -181,6 +198,7 @@
181
198
  "@tiptap/extension-underline": "^3.26.1",
182
199
  "@tiptap/starter-kit": "^3.26.1",
183
200
  "@tiptap/vue-3": "^3.26.1",
201
+ "@types/jsbarcode": "^3.11.4",
184
202
  "@types/markdown-it": "^14.1.2",
185
203
  "@vitejs/plugin-vue": "^6.0.7",
186
204
  "@vue/test-utils": "^2.4.11",
@@ -192,13 +210,15 @@
192
210
  "codemirror": "^6.0.2",
193
211
  "happy-dom": "^20.10.6",
194
212
  "highlight.js": "^11.11.1",
213
+ "jsbarcode": "^3.12.3",
195
214
  "markdown-it": "^14.2.0",
215
+ "qrcode-generator": "^2.0.4",
196
216
  "typescript": "~6.0.3",
197
217
  "vite": "^8.0.16",
198
218
  "vitest": "^4.1.9",
199
- "vue": "^3.5.38",
219
+ "vue": "^3.5.42",
200
220
  "vue-chartjs": "^5.3.3",
201
- "vue-tsc": "^3.3.5"
221
+ "vue-tsc": "^3.3.11"
202
222
  },
203
223
  "publishConfig": {
204
224
  "access": "public"
@@ -0,0 +1,40 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import { nextTick } from 'vue'
4
+ import MBarcode from '../components/MBarcode.vue'
5
+
6
+ // happy-dom's canvas.getContext('2d') returns null, and jsbarcode uses it to
7
+ // measure the text label width — so tests here disable displayValue to avoid
8
+ // that gap (a real browser has no such issue).
9
+ describe('MBarcode', () => {
10
+ it('renders an svg with barcode content for a valid value', () => {
11
+ const wrapper = mount(MBarcode, { props: { value: '123456789012', displayValue: false } })
12
+ const svg = wrapper.find('svg')
13
+ expect(svg.exists()).toBe(true)
14
+ expect(svg.element.childElementCount).toBeGreaterThan(0)
15
+ })
16
+
17
+ it('defaults the aria-label to the encoded value', () => {
18
+ const wrapper = mount(MBarcode, { props: { value: 'ORDER-123', displayValue: false } })
19
+ expect(wrapper.find('svg').attributes('aria-label')).toBe('ORDER-123')
20
+ })
21
+
22
+ it('uses a custom label when provided', () => {
23
+ const wrapper = mount(MBarcode, { props: { value: 'ORDER-123', label: 'Order number', displayValue: false } })
24
+ expect(wrapper.find('svg').attributes('aria-label')).toBe('Order number')
25
+ })
26
+
27
+ it('shows an error slot fallback for a value invalid in the given format', async () => {
28
+ const wrapper = mount(MBarcode, { props: { value: 'not-a-valid-ean', format: 'EAN13', displayValue: false } })
29
+ await nextTick()
30
+ expect(wrapper.find('svg').attributes('style')).toContain('display: none')
31
+ expect(wrapper.text().length).toBeGreaterThan(0)
32
+ })
33
+
34
+ it('re-renders when the value changes', async () => {
35
+ const wrapper = mount(MBarcode, { props: { value: '111111111111', displayValue: false } })
36
+ const first = wrapper.find('svg').html()
37
+ await wrapper.setProps({ value: '222222222222' })
38
+ expect(wrapper.find('svg').html()).not.toBe(first)
39
+ })
40
+ })
@@ -0,0 +1,49 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import MCopyButton from '../components/MCopyButton.vue'
4
+
5
+ describe('MCopyButton', () => {
6
+ beforeEach(() => {
7
+ Object.defineProperty(navigator, 'clipboard', {
8
+ value: { writeText: vi.fn().mockResolvedValue(undefined) },
9
+ configurable: true,
10
+ })
11
+ })
12
+
13
+ it('copies the value to the clipboard on click', async () => {
14
+ const wrapper = mount(MCopyButton, { props: { value: 'hello' } })
15
+ await wrapper.find('button').trigger('click')
16
+ await vi.waitFor(() => expect(navigator.clipboard.writeText).toHaveBeenCalledWith('hello'))
17
+ })
18
+
19
+ it('emits copied with the value', async () => {
20
+ const wrapper = mount(MCopyButton, { props: { value: 'hello' } })
21
+ await wrapper.find('button').trigger('click')
22
+ await vi.waitFor(() => expect(wrapper.emitted('copied')).toEqual([['hello']]))
23
+ })
24
+
25
+ it('swaps the icon to copiedIcon after copying, then reverts after resetDelay', async () => {
26
+ const wrapper = mount(MCopyButton, { props: { value: 'hello', resetDelay: 30 } })
27
+ expect(wrapper.text()).toContain('content_copy')
28
+
29
+ await wrapper.find('button').trigger('click')
30
+ await vi.waitFor(() => expect(wrapper.text()).toContain('check'))
31
+ await vi.waitFor(() => expect(wrapper.text()).toContain('content_copy'))
32
+ })
33
+
34
+ it('emits error when the clipboard write fails', async () => {
35
+ Object.defineProperty(navigator, 'clipboard', {
36
+ value: { writeText: vi.fn().mockRejectedValue(new Error('denied')) },
37
+ configurable: true,
38
+ })
39
+ const wrapper = mount(MCopyButton, { props: { value: 'hello' } })
40
+ await wrapper.find('button').trigger('click')
41
+ await vi.waitFor(() => expect(wrapper.emitted('error')).toHaveLength(1))
42
+ })
43
+
44
+ it('does not copy when disabled', async () => {
45
+ const wrapper = mount(MCopyButton, { props: { value: 'hello', disabled: true } })
46
+ await wrapper.find('button').trigger('click')
47
+ expect(navigator.clipboard.writeText).not.toHaveBeenCalled()
48
+ })
49
+ })
@@ -0,0 +1,64 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import MExportButton from '../components/MExportButton.vue'
4
+
5
+ const sampleData = [
6
+ { name: 'Ada', age: 30 },
7
+ { name: 'Grace, "The Admiral"', age: 45 },
8
+ ]
9
+
10
+ describe('MExportButton', () => {
11
+ let clickSpy: ReturnType<typeof vi.fn>
12
+ let lastBlob: Blob | null
13
+
14
+ beforeEach(() => {
15
+ clickSpy = vi.fn()
16
+ lastBlob = null
17
+ HTMLAnchorElement.prototype.click = clickSpy
18
+ vi.spyOn(URL, 'createObjectURL').mockImplementation((blob: Blob) => {
19
+ lastBlob = blob
20
+ return 'blob:mock'
21
+ })
22
+ vi.spyOn(URL, 'revokeObjectURL').mockImplementation(() => {})
23
+ })
24
+
25
+ it('renders the label', () => {
26
+ const wrapper = mount(MExportButton, { props: { data: sampleData } })
27
+ expect(wrapper.text()).toContain('Export')
28
+ })
29
+
30
+ it('exports CSV by default, escaping commas and quotes', async () => {
31
+ const wrapper = mount(MExportButton, { props: { data: sampleData } })
32
+ await wrapper.find('button').trigger('click')
33
+ const text = await lastBlob!.text()
34
+ expect(text).toBe('name,age\nAda,30\n"Grace, ""The Admiral""",45')
35
+ expect(clickSpy).toHaveBeenCalledOnce()
36
+ })
37
+
38
+ it('exports JSON when format is json', async () => {
39
+ const wrapper = mount(MExportButton, { props: { data: sampleData, format: 'json' } })
40
+ await wrapper.find('button').trigger('click')
41
+ const text = await lastBlob!.text()
42
+ expect(JSON.parse(text)).toEqual(sampleData)
43
+ })
44
+
45
+ it('emits exported with the format and filename', async () => {
46
+ const wrapper = mount(MExportButton, { props: { data: sampleData, filename: 'users' } })
47
+ await wrapper.find('button').trigger('click')
48
+ expect(wrapper.emitted('exported')![0]).toEqual([{ format: 'csv', filename: 'users.csv' }])
49
+ })
50
+
51
+ it('does not export when disabled', async () => {
52
+ const wrapper = mount(MExportButton, { props: { data: sampleData, disabled: true } })
53
+ await wrapper.find('button').trigger('click')
54
+ expect(clickSpy).not.toHaveBeenCalled()
55
+ })
56
+
57
+ it('supports a custom label via the default slot', () => {
58
+ const wrapper = mount(MExportButton, {
59
+ props: { data: sampleData },
60
+ slots: { default: 'Download all' },
61
+ })
62
+ expect(wrapper.text()).toContain('Download all')
63
+ })
64
+ })
@@ -0,0 +1,33 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import MKbd from '../components/MKbd.vue'
4
+
5
+ describe('MKbd', () => {
6
+ it('splits a "+"-delimited string into separate kbd elements', () => {
7
+ const wrapper = mount(MKbd, { props: { keys: 'Ctrl+Shift+K' } })
8
+ const kbds = wrapper.findAll('kbd')
9
+ expect(kbds.map((k) => k.text())).toEqual(['Ctrl', 'Shift', 'K'])
10
+ })
11
+
12
+ it('accepts an array of keys directly', () => {
13
+ const wrapper = mount(MKbd, { props: { keys: ['Cmd', 'K'] } })
14
+ const kbds = wrapper.findAll('kbd')
15
+ expect(kbds.map((k) => k.text())).toEqual(['Cmd', 'K'])
16
+ })
17
+
18
+ it('renders a single key with no separator', () => {
19
+ const wrapper = mount(MKbd, { props: { keys: 'Esc' } })
20
+ expect(wrapper.findAll('kbd')).toHaveLength(1)
21
+ expect(wrapper.text()).toBe('Esc')
22
+ })
23
+
24
+ it('renders the separator between keys, but not trailing', () => {
25
+ const wrapper = mount(MKbd, { props: { keys: 'Ctrl+K' } })
26
+ expect(wrapper.text()).toBe('Ctrl+K')
27
+ })
28
+
29
+ it('supports a custom separator', () => {
30
+ const wrapper = mount(MKbd, { props: { keys: ['Ctrl', 'K'], separator: ' then ' } })
31
+ expect(wrapper.text()).toBe('Ctrl then K')
32
+ })
33
+ })
@@ -0,0 +1,43 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import MPasswordMeter from '../components/MPasswordMeter.vue'
4
+
5
+ describe('MPasswordMeter', () => {
6
+ it('shows no label and no filled segments for an empty value', () => {
7
+ const wrapper = mount(MPasswordMeter, { props: { value: '' } })
8
+ expect(wrapper.find('p').exists()).toBe(false)
9
+ })
10
+
11
+ it('rates a short lowercase-only password as very weak', () => {
12
+ const wrapper = mount(MPasswordMeter, { props: { value: 'abc' } })
13
+ expect(wrapper.text()).toBe('Very weak')
14
+ })
15
+
16
+ it('rates a long, varied password as strong', () => {
17
+ const wrapper = mount(MPasswordMeter, { props: { value: 'Sup3r$ecureLongPass!' } })
18
+ expect(wrapper.text()).toBe('Strong')
19
+ })
20
+
21
+ it('emits score whenever the value changes', async () => {
22
+ const wrapper = mount(MPasswordMeter, { props: { value: '' } })
23
+ expect(wrapper.emitted('score')![0]).toEqual([-1])
24
+
25
+ await wrapper.setProps({ value: 'Sup3r$ecureLongPass!' })
26
+ expect(wrapper.emitted('score')!.at(-1)).toEqual([4])
27
+ })
28
+
29
+ it('supports custom labels', () => {
30
+ const wrapper = mount(MPasswordMeter, {
31
+ props: { value: 'abc', labels: ['Muy débil', 'Débil', 'Regular', 'Buena', 'Fuerte'] },
32
+ })
33
+ expect(wrapper.text()).toBe('Muy débil')
34
+ })
35
+
36
+ it('respects a custom minLength when scoring', () => {
37
+ const short = mount(MPasswordMeter, { props: { value: '1234', minLength: 4 } })
38
+ const shortScore = short.emitted('score')![0]![0]
39
+ const long = mount(MPasswordMeter, { props: { value: '123', minLength: 4 } })
40
+ const longScore = long.emitted('score')![0]![0]
41
+ expect(shortScore).toBeGreaterThan(longScore as number)
42
+ })
43
+ })
@@ -0,0 +1,138 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import MPinInput from '../components/MPinInput.vue'
4
+
5
+ describe('MPinInput', () => {
6
+ it('renders `length` boxes', () => {
7
+ const wrapper = mount(MPinInput, { props: { modelValue: '', length: 4 } })
8
+ expect(wrapper.findAll('input')).toHaveLength(4)
9
+ })
10
+
11
+ it('defaults to 6 boxes', () => {
12
+ const wrapper = mount(MPinInput, { props: { modelValue: '' } })
13
+ expect(wrapper.findAll('input')).toHaveLength(6)
14
+ })
15
+
16
+ it('renders each digit in its own box', () => {
17
+ const wrapper = mount(MPinInput, { props: { modelValue: '12', length: 4 } })
18
+ const inputs = wrapper.findAll('input')
19
+ expect(inputs[0].element.value).toBe('1')
20
+ expect(inputs[1].element.value).toBe('2')
21
+ expect(inputs[2].element.value).toBe('')
22
+ })
23
+
24
+ it('emits update:modelValue and advances focus on digit entry', async () => {
25
+ const wrapper = mount(MPinInput, {
26
+ props: { modelValue: '', length: 4 },
27
+ attachTo: document.body,
28
+ })
29
+ const inputs = wrapper.findAll('input')
30
+ await inputs[0].setValue('5')
31
+ expect(wrapper.emitted('update:modelValue')![0]).toEqual(['5'])
32
+ wrapper.unmount()
33
+ })
34
+
35
+ it('rejects non-numeric input by default', async () => {
36
+ const wrapper = mount(MPinInput, { props: { modelValue: '', length: 4 } })
37
+ const input = wrapper.findAll('input')[0]
38
+ await input.setValue('a')
39
+ expect(wrapper.emitted('update:modelValue')).toBeUndefined()
40
+ })
41
+
42
+ it('allows letters when type is alphanumeric', async () => {
43
+ const wrapper = mount(MPinInput, { props: { modelValue: '', length: 4, type: 'alphanumeric' } })
44
+ const input = wrapper.findAll('input')[0]
45
+ await input.setValue('a')
46
+ expect(wrapper.emitted('update:modelValue')![0]).toEqual(['a'])
47
+ })
48
+
49
+ it('emits complete when all boxes are filled', async () => {
50
+ const wrapper = mount(MPinInput, { props: { modelValue: '123', length: 4 } })
51
+ const input = wrapper.findAll('input')[3]
52
+ await input.setValue('4')
53
+ expect(wrapper.emitted('complete')![0]).toEqual(['1234'])
54
+ })
55
+
56
+ it('moves focus back and clears the previous box on backspace from an empty box', async () => {
57
+ const wrapper = mount(MPinInput, {
58
+ props: { modelValue: '12', length: 4 },
59
+ attachTo: document.body,
60
+ })
61
+ const inputs = wrapper.findAll('input')
62
+ await inputs[2].trigger('keydown', { key: 'Backspace' })
63
+ expect(wrapper.emitted('update:modelValue')![0]).toEqual(['1'])
64
+ wrapper.unmount()
65
+ })
66
+
67
+ it('distributes a pasted code across the remaining boxes', async () => {
68
+ const wrapper = mount(MPinInput, { props: { modelValue: '', length: 4 } })
69
+ const input = wrapper.findAll('input')[0]
70
+ await input.trigger('paste', {
71
+ clipboardData: { getData: () => '1234' },
72
+ })
73
+ expect(wrapper.emitted('update:modelValue')![0]).toEqual(['1234'])
74
+ expect(wrapper.emitted('complete')![0]).toEqual(['1234'])
75
+ })
76
+
77
+ it("keeps a skipped box's position when it's filled in afterwards", async () => {
78
+ // Simulates clicking box 3 directly while boxes 1-2 are still empty,
79
+ // then coming back to fill the gap — the middle boxes must not shift.
80
+ const wrapper = mount(MPinInput, { props: { modelValue: '1', length: 4 } })
81
+
82
+ await wrapper.findAll('input')[3].setValue('4')
83
+ let value = wrapper.emitted('update:modelValue')!.at(-1)![0] as string
84
+ await wrapper.setProps({ modelValue: value })
85
+ let inputs = wrapper.findAll('input')
86
+ expect(inputs[0].element.value).toBe('1')
87
+ expect(inputs[1].element.value).toBe('')
88
+ expect(inputs[2].element.value).toBe('')
89
+ expect(inputs[3].element.value).toBe('4')
90
+
91
+ await inputs[2].setValue('3')
92
+ value = wrapper.emitted('update:modelValue')!.at(-1)![0] as string
93
+ await wrapper.setProps({ modelValue: value })
94
+ inputs = wrapper.findAll('input')
95
+ expect(inputs[2].element.value).toBe('3')
96
+ expect(inputs[3].element.value).toBe('4')
97
+
98
+ await inputs[1].setValue('2')
99
+ expect(wrapper.emitted('complete')!.at(-1)).toEqual(['1234'])
100
+ })
101
+
102
+ it('renders as masked input when masked is true', () => {
103
+ const wrapper = mount(MPinInput, { props: { modelValue: '', length: 4, masked: true } })
104
+ expect(wrapper.findAll('input')[0].attributes('type')).toBe('password')
105
+ })
106
+
107
+ it('derives length from groups and renders a separator at each boundary', () => {
108
+ const wrapper = mount(MPinInput, { props: { modelValue: '', groups: [2, 3, 2] } })
109
+ expect(wrapper.findAll('input')).toHaveLength(7)
110
+ const spans = wrapper.findAll('span')
111
+ expect(spans).toHaveLength(2)
112
+ expect(spans[0].text()).toBe('-')
113
+ expect(spans[1].text()).toBe('-')
114
+ })
115
+
116
+ it('uses a custom separator', () => {
117
+ const wrapper = mount(MPinInput, { props: { modelValue: '', groups: [2, 2], separator: '•' } })
118
+ expect(wrapper.find('span').text()).toBe('•')
119
+ })
120
+
121
+ it('treats grouped boxes as one continuous value for typing and complete', async () => {
122
+ const wrapper = mount(MPinInput, { props: { modelValue: '12', groups: [2, 2] } })
123
+ const inputs = wrapper.findAll('input')
124
+ expect(inputs).toHaveLength(4)
125
+ await inputs[2].setValue('3')
126
+ let value = wrapper.emitted('update:modelValue')!.at(-1)![0] as string
127
+ await wrapper.setProps({ modelValue: value })
128
+ await wrapper.findAll('input')[3].setValue('4')
129
+ expect(wrapper.emitted('complete')!.at(-1)).toEqual(['1234'])
130
+ })
131
+
132
+ it('disables all boxes when disabled', () => {
133
+ const wrapper = mount(MPinInput, { props: { modelValue: '', length: 4, disabled: true } })
134
+ for (const input of wrapper.findAll('input')) {
135
+ expect(input.attributes('disabled')).toBeDefined()
136
+ }
137
+ })
138
+ })