@m3ui-vue/m3ui-vue 1.6.0 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/dist/API.md +940 -33
  2. package/dist/{MButton-CPghlKb0.js → MButton-OQ4wIERQ.js} +2 -2
  3. package/dist/{MButton-CPghlKb0.js.map → MButton-OQ4wIERQ.js.map} +1 -1
  4. package/dist/MColorPickerModal-NtkihoK6.js +577 -0
  5. package/dist/MColorPickerModal-NtkihoK6.js.map +1 -0
  6. package/dist/{MDialog-X50At1Gk.js → MDialog-DYMnaBlt.js} +3 -3
  7. package/dist/{MDialog-X50At1Gk.js.map → MDialog-DYMnaBlt.js.map} +1 -1
  8. package/dist/{MListItem-DVi1j1QI.js → MListItem-D2cNUyzP.js} +211 -168
  9. package/dist/MListItem-D2cNUyzP.js.map +1 -0
  10. package/dist/{MLoadingIndicator-vooA3110.js → MLoadingIndicator-DWUj0BAB.js} +2 -2
  11. package/dist/{MLoadingIndicator-vooA3110.js.map → MLoadingIndicator-DWUj0BAB.js.map} +1 -1
  12. package/dist/{MMenuItem-CRNZkVVr.js → MMenuItem-BuxYoASE.js} +133 -151
  13. package/dist/MMenuItem-BuxYoASE.js.map +1 -0
  14. package/dist/{MSeekBar-BL2W5_rD.js → MSeekBar-C4cn9RIF.js} +2 -2
  15. package/dist/{MSeekBar-BL2W5_rD.js.map → MSeekBar-C4cn9RIF.js.map} +1 -1
  16. package/dist/{MSlider-B9NcKTmZ.js → MSlider-BIkA6DiE.js} +2 -2
  17. package/dist/{MSlider-B9NcKTmZ.js.map → MSlider-BIkA6DiE.js.map} +1 -1
  18. package/dist/{MSpinner-_XpTRkAg.js → MSpinner-DZkXZJpc.js} +2 -2
  19. package/dist/{MSpinner-_XpTRkAg.js.map → MSpinner-DZkXZJpc.js.map} +1 -1
  20. package/dist/{MTextField-DpcPmR5B.js → MTextField-CNH-byir.js} +2 -2
  21. package/dist/{MTextField-DpcPmR5B.js.map → MTextField-CNH-byir.js.map} +1 -1
  22. package/dist/MTooltip-CK39Zon4.js +183 -0
  23. package/dist/MTooltip-CK39Zon4.js.map +1 -0
  24. package/dist/{_useEscapeStack-C5-BYr8y.js → _popupPosition-nL8SVKPK.js} +20 -2
  25. package/dist/_popupPosition-nL8SVKPK.js.map +1 -0
  26. package/dist/api.json +1 -1
  27. package/dist/code-editor.js +1 -1
  28. package/dist/components/MAddressField.vue.d.ts +54 -0
  29. package/dist/components/MAudioPlayer.vue.d.ts +1 -1
  30. package/dist/components/MAudioRecorder.vue.d.ts +51 -0
  31. package/dist/components/MAvailabilityCalendar.vue.d.ts +1 -1
  32. package/dist/components/MCameraCapture.vue.d.ts +51 -0
  33. package/dist/components/MCollapse.vue.d.ts +32 -0
  34. package/dist/components/MCountrySelect.vue.d.ts +41 -0
  35. package/dist/components/MCronField.vue.d.ts +26 -0
  36. package/dist/components/MDashboardGrid.vue.d.ts +65 -0
  37. package/dist/components/MDiffViewer.vue.d.ts +56 -0
  38. package/dist/components/MExpansionPanel.vue.d.ts +26 -3
  39. package/dist/components/MFilterBuilder.vue.d.ts +22 -0
  40. package/dist/components/MFlex.vue.d.ts +1 -1
  41. package/dist/components/MMapCluster.vue.d.ts +80 -0
  42. package/dist/components/MMapDraw.vue.d.ts +79 -0
  43. package/dist/components/MMentionField.vue.d.ts +102 -0
  44. package/dist/components/MNotificationCenter.vue.d.ts +57 -0
  45. package/dist/components/MQRScanner.vue.d.ts +52 -0
  46. package/dist/components/MQuiz.vue.d.ts +1 -1
  47. package/dist/components/MSimpleCarousel.vue.d.ts +1 -1
  48. package/dist/components/MStack.vue.d.ts +1 -1
  49. package/dist/components/MTimezoneSelect.vue.d.ts +39 -0
  50. package/dist/components/MToolbar.vue.d.ts +1 -1
  51. package/dist/components/MVideoPlayer.vue.d.ts +1 -1
  52. package/dist/components/_MFilterGroup.vue.d.ts +17 -0
  53. package/dist/composables/_caretPosition.d.ts +6 -0
  54. package/dist/composables/_useCamera.d.ts +16 -0
  55. package/dist/composables/_useFollowAnchor.d.ts +15 -0
  56. package/dist/composables/cron.d.ts +29 -0
  57. package/dist/composables/dashboardLayout.d.ts +28 -0
  58. package/dist/composables/filterBuilder.d.ts +55 -0
  59. package/dist/composables/mapAdapters.d.ts +6 -1
  60. package/dist/composables/mapSearch.d.ts +1 -0
  61. package/dist/composables/textDiff.d.ts +24 -0
  62. package/dist/composables/useLocale.d.ts +108 -0
  63. package/dist/draw.js +28 -27
  64. package/dist/draw.js.map +1 -1
  65. package/dist/flow.js +1 -1
  66. package/dist/gantt.js +1 -1
  67. package/dist/index.d.ts +25 -0
  68. package/dist/locales/index.js +749 -0
  69. package/dist/locales/index.js.map +1 -1
  70. package/dist/m3ui-vue.css +1 -1
  71. package/dist/m3ui.js +10444 -7495
  72. package/dist/m3ui.js.map +1 -1
  73. package/dist/map.d.ts +5 -0
  74. package/dist/map.js +1509 -617
  75. package/dist/map.js.map +1 -1
  76. package/dist/media.js +5 -5
  77. package/dist/pdf.js +5 -5
  78. package/dist/rich-text-editor.js +5 -5
  79. package/dist/styles.css +1 -1
  80. package/dist/{useLocale-COav9m8C.js → useLocale-DaVSTdm0.js} +108 -1
  81. package/dist/useLocale-DaVSTdm0.js.map +1 -0
  82. package/package.json +1 -1
  83. package/src/__tests__/MAddressField.test.ts +149 -0
  84. package/src/__tests__/MAudioRecorder.test.ts +125 -0
  85. package/src/__tests__/MCameraCapture.test.ts +154 -0
  86. package/src/__tests__/MCountrySelect.test.ts +67 -0
  87. package/src/__tests__/MCronField.test.ts +100 -0
  88. package/src/__tests__/MDashboardGrid.test.ts +122 -0
  89. package/src/__tests__/MDiffViewer.test.ts +68 -0
  90. package/src/__tests__/MExpansionPanel.test.ts +107 -0
  91. package/src/__tests__/MFilterBuilder.test.ts +130 -0
  92. package/src/__tests__/MMapCluster.test.ts +127 -0
  93. package/src/__tests__/MMapDraw.test.ts +188 -0
  94. package/src/__tests__/MMapLayers.test.ts +56 -0
  95. package/src/__tests__/MMentionField.test.ts +163 -0
  96. package/src/__tests__/MNotificationCenter.test.ts +94 -0
  97. package/src/__tests__/_fakeMaplibre.ts +14 -3
  98. package/src/__tests__/attrsFallthrough.test.ts +4 -0
  99. package/src/__tests__/cron.test.ts +68 -0
  100. package/src/__tests__/dashboardLayout.test.ts +45 -0
  101. package/src/__tests__/filterBuilder.test.ts +91 -0
  102. package/src/__tests__/followAnchor.test.ts +162 -0
  103. package/src/__tests__/ssr.test.ts +3 -0
  104. package/src/__tests__/textDiff.test.ts +37 -0
  105. package/src/components/MAddressField.vue +301 -0
  106. package/src/components/MAudioRecorder.vue +334 -0
  107. package/src/components/MAutocomplete.vue +3 -7
  108. package/src/components/MCameraCapture.vue +156 -0
  109. package/src/components/MCollapse.vue +91 -0
  110. package/src/components/MColorPicker.vue +4 -8
  111. package/src/components/MCountrySelect.vue +89 -0
  112. package/src/components/MCronField.vue +251 -0
  113. package/src/components/MDashboardGrid.vue +382 -0
  114. package/src/components/MDatePicker.vue +10 -7
  115. package/src/components/MDateRangePicker.vue +10 -7
  116. package/src/components/MDiffViewer.vue +234 -0
  117. package/src/components/MExpansionPanel.vue +56 -48
  118. package/src/components/MFilterBuilder.vue +47 -0
  119. package/src/components/MMapBaseLayers.vue +29 -28
  120. package/src/components/MMapCluster.vue +295 -0
  121. package/src/components/MMapDraw.vue +601 -0
  122. package/src/components/MMapMeasure.vue +1 -1
  123. package/src/components/MMapSearch.vue +1 -9
  124. package/src/components/MMentionField.vue +373 -0
  125. package/src/components/MMultiAutocomplete.vue +3 -7
  126. package/src/components/MMultiSelect.vue +3 -7
  127. package/src/components/MNotificationCenter.vue +252 -0
  128. package/src/components/MPhoneInput.vue +3 -10
  129. package/src/components/MQRScanner.vue +177 -0
  130. package/src/components/MSelect.vue +3 -7
  131. package/src/components/MTimePicker.vue +10 -7
  132. package/src/components/MTimezoneSelect.vue +116 -0
  133. package/src/components/_MFilterGroup.vue +210 -0
  134. package/src/composables/_caretPosition.ts +44 -0
  135. package/src/composables/_useCamera.ts +66 -0
  136. package/src/composables/_useFollowAnchor.ts +109 -0
  137. package/src/composables/cron.ts +179 -0
  138. package/src/composables/dashboardLayout.ts +94 -0
  139. package/src/composables/filterBuilder.ts +195 -0
  140. package/src/composables/mapAdapters.ts +29 -15
  141. package/src/composables/mapSearch.ts +10 -0
  142. package/src/composables/textDiff.ts +106 -0
  143. package/src/composables/useLocale.ts +215 -0
  144. package/src/index.ts +25 -0
  145. package/src/locales/de.ts +107 -0
  146. package/src/locales/es.ts +107 -0
  147. package/src/locales/fr.ts +107 -0
  148. package/src/locales/ja.ts +107 -0
  149. package/src/locales/ko.ts +107 -0
  150. package/src/locales/pt.ts +107 -0
  151. package/src/locales/zh.ts +107 -0
  152. package/src/map.ts +5 -0
  153. package/dist/MListItem-DVi1j1QI.js.map +0 -1
  154. package/dist/MMenuItem-CRNZkVVr.js.map +0 -1
  155. package/dist/MTooltip-BL3jPYPT.js +0 -754
  156. package/dist/MTooltip-BL3jPYPT.js.map +0 -1
  157. package/dist/_useEscapeStack-C5-BYr8y.js.map +0 -1
  158. package/dist/useLocale-COav9m8C.js.map +0 -1
@@ -0,0 +1,45 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { clampItem, compactLayout, layoutRows, moveItem, normalizeLayout, type DashboardItem } from '../composables/dashboardLayout'
3
+
4
+ const L = (...items: [string, number, number, number, number, Partial<DashboardItem>?][]): DashboardItem[] =>
5
+ items.map(([id, x, y, w, h, more]) => ({ id, x, y, w, h, ...more }))
6
+ const pos = (layout: DashboardItem[]) => Object.fromEntries(layout.map((i) => [i.id, [i.x, i.y, i.w, i.h]]))
7
+
8
+ describe('dashboardLayout', () => {
9
+ it('clamps to the columns and size limits', () => {
10
+ expect(clampItem({ id: 'a', x: 10, y: -2, w: 5, h: 0 }, 12)).toMatchObject({ x: 7, y: 0, w: 5, h: 1 })
11
+ expect(clampItem({ id: 'a', x: 0, y: 0, w: 1, h: 9, minW: 3, maxH: 4 }, 12)).toMatchObject({ w: 3, h: 4 })
12
+ expect(clampItem({ id: 'a', x: 0, y: 0, w: 20, h: 1 }, 12).w).toBe(12)
13
+ })
14
+
15
+ it('compacts items upward, leaving static ones in place', () => {
16
+ expect(pos(compactLayout(L(['a', 0, 3, 4, 2], ['b', 4, 5, 4, 2])))).toEqual({ a: [0, 0, 4, 2], b: [4, 0, 4, 2] })
17
+ expect(pos(compactLayout(L(['s', 0, 2, 6, 1, { static: true }], ['a', 0, 5, 4, 2])))).toEqual({ s: [0, 2, 6, 1], a: [0, 0, 4, 2] })
18
+ expect(pos(compactLayout(L(['s', 0, 1, 6, 1, { static: true }], ['a', 0, 5, 4, 2])))).toEqual({ s: [0, 1, 6, 1], a: [0, 2, 4, 2] })
19
+ })
20
+
21
+ it('pushes what an item lands on below it, then compacts', () => {
22
+ // a over b's column: b goes below a
23
+ const moved = moveItem(L(['a', 0, 0, 6, 2], ['b', 6, 0, 6, 2]), 'a', { x: 6 }, 12)
24
+ expect(pos(moved)).toEqual({ a: [6, 0, 6, 2], b: [6, 2, 6, 2] })
25
+ // Order of the array is kept
26
+ expect(moved.map((i) => i.id)).toEqual(['a', 'b'])
27
+ })
28
+
29
+ it('resizes, pushing neighbors below', () => {
30
+ const out = moveItem(L(['a', 0, 0, 6, 2], ['b', 6, 0, 6, 2], ['c', 0, 2, 12, 1]), 'a', { w: 12 }, 12)
31
+ expect(pos(out)).toEqual({ a: [0, 0, 12, 2], b: [6, 2, 6, 2], c: [0, 4, 12, 1] })
32
+ })
33
+
34
+ it('never moves a static item, and keeps others off it', () => {
35
+ const base = L(['s', 0, 0, 12, 1, { static: true }], ['a', 0, 1, 6, 2])
36
+ expect(pos(moveItem(base, 's', { y: 3 }, 12))).toEqual({ s: [0, 0, 12, 1], a: [0, 1, 6, 2] })
37
+ expect(pos(moveItem(base, 'a', { y: 0 }, 12))).toEqual({ s: [0, 0, 12, 1], a: [0, 1, 6, 2] })
38
+ })
39
+
40
+ it('normalizes overlapping or out-of-range input', () => {
41
+ const out = normalizeLayout(L(['a', 0, 0, 6, 2], ['b', 2, 0, 6, 2], ['c', 11, 0, 4, 1]), 12)
42
+ expect(pos(out)).toEqual({ a: [0, 0, 6, 2], b: [2, 2, 6, 2], c: [8, 0, 4, 1] })
43
+ expect(layoutRows(out)).toBe(4)
44
+ })
45
+ })
@@ -0,0 +1,91 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import {
3
+ countRules, createFilter, filterRows, matchesFilter, operatorsFor,
4
+ type FilterField, type FilterGroup,
5
+ } from '../composables/filterBuilder'
6
+
7
+ const fields: FilterField[] = [
8
+ { key: 'name', label: 'Name' },
9
+ { key: 'price', label: 'Price', type: 'number' },
10
+ { key: 'due', label: 'Due', type: 'date' },
11
+ { key: 'status', label: 'Status', type: 'select', options: [{ label: 'Open', value: 'open' }, { label: 'Done', value: 'done' }] },
12
+ { key: 'urgent', label: 'Urgent', type: 'boolean' },
13
+ { key: 'address.city', label: 'City' },
14
+ { key: 'tags', label: 'Tags', type: 'select' },
15
+ ]
16
+ const rows = [
17
+ { id: 1, name: 'Fix login', price: 120, due: '2026-11-20', status: 'open', urgent: true, address: { city: 'Córdoba' }, tags: ['web', 'auth'] },
18
+ { id: 2, name: 'Write docs', price: 40, due: '2026-12-02T10:00:00Z', status: 'done', urgent: false, address: { city: 'Rosario' }, tags: ['docs'] },
19
+ { id: 3, name: 'Deploy', price: null, due: null, status: 'open', urgent: false, address: { city: 'córdoba' }, tags: [] },
20
+ ]
21
+ const ids = (filter: FilterGroup) => filterRows(rows, filter, fields).map((r) => r.id)
22
+ const one = (field: string, operator: string, value?: unknown) => createFilter([{ field, operator: operator as never, value }])
23
+
24
+ describe('filterBuilder', () => {
25
+ it('compares text case-insensitively, through dotted paths', () => {
26
+ expect(ids(one('name', 'contains', 'DO'))).toEqual([2])
27
+ expect(ids(one('name', 'notContains', 'login'))).toEqual([2, 3])
28
+ expect(ids(one('name', 'startsWith', 'fix'))).toEqual([1])
29
+ expect(ids(one('name', 'endsWith', 'docs'))).toEqual([2])
30
+ expect(ids(one('address.city', 'equals', 'CÓRDOBA'))).toEqual([1, 3])
31
+ expect(ids(one('address.city', 'notEquals', 'córdoba'))).toEqual([2])
32
+ })
33
+
34
+ it('compares numbers, ranges and emptiness', () => {
35
+ expect(ids(one('price', 'gt', 50))).toEqual([1])
36
+ expect(ids(one('price', 'lte', 40))).toEqual([2])
37
+ expect(ids(one('price', 'between', [30, 100]))).toEqual([2])
38
+ expect(ids(one('price', 'between', [50, null]))).toEqual([1])
39
+ expect(ids(one('price', 'isEmpty'))).toEqual([3])
40
+ expect(ids(one('price', 'isNotEmpty'))).toEqual([1, 2])
41
+ })
42
+
43
+ it('compares dates by day, whatever their form', () => {
44
+ expect(ids(one('due', 'equals', '2026-12-02'))).toEqual([2])
45
+ expect(ids(one('due', 'lt', '2026-12-01'))).toEqual([1])
46
+ expect(ids(one('due', 'between', ['2026-11-01', '2026-11-30']))).toEqual([1])
47
+ })
48
+
49
+ it('matches select values and lists, and booleans', () => {
50
+ expect(ids(one('status', 'in', ['open']))).toEqual([1, 3])
51
+ expect(ids(one('status', 'notIn', ['open']))).toEqual([2])
52
+ expect(ids(one('tags', 'in', ['docs', 'auth']))).toEqual([1, 2])
53
+ expect(ids(one('urgent', 'isTrue'))).toEqual([1])
54
+ expect(ids(one('urgent', 'isFalse'))).toEqual([2, 3])
55
+ })
56
+
57
+ it('combines with and / or, and nests groups', () => {
58
+ const filter: FilterGroup = {
59
+ id: 'g', combinator: 'and',
60
+ rules: [
61
+ { id: 'r1', field: 'status', operator: 'in', value: ['open'] },
62
+ { id: 'g2', combinator: 'or', rules: [
63
+ { id: 'r2', field: 'urgent', operator: 'isTrue' },
64
+ { id: 'r3', field: 'price', operator: 'isEmpty' },
65
+ ] },
66
+ ],
67
+ }
68
+ expect(ids(filter)).toEqual([1, 3])
69
+ expect(ids({ ...filter, combinator: 'or' })).toEqual([1, 3])
70
+ expect(countRules(filter)).toBe(3)
71
+ })
72
+
73
+ it('lets incomplete rules and empty groups match everything', () => {
74
+ expect(ids(one('name', 'contains', ''))).toEqual([1, 2, 3])
75
+ expect(ids(one('price', 'between', [null, null]))).toEqual([1, 2, 3])
76
+ expect(ids({ id: 'g', combinator: 'and', rules: [{ id: 'e', combinator: 'or', rules: [] }] })).toEqual([1, 2, 3])
77
+ expect(matchesFilter(rows[0]!, null)).toBe(true)
78
+ expect(countRules(one('name', 'contains', ''))).toBe(0)
79
+ })
80
+
81
+ it('offers each type its operators, or the field\'s own', () => {
82
+ expect(operatorsFor({ key: 'x', label: 'X' })[0]).toBe('contains')
83
+ expect(operatorsFor({ key: 'x', label: 'X', type: 'boolean' })).toEqual(['isTrue', 'isFalse'])
84
+ expect(operatorsFor({ key: 'x', label: 'X', operators: ['equals'] })).toEqual(['equals'])
85
+ })
86
+
87
+ it('reads through an accessor', () => {
88
+ const f: FilterField[] = [{ key: 'total', label: 'Total', type: 'number', accessor: (r) => (r.price as number ?? 0) * 2 }]
89
+ expect(filterRows(rows, one('total', 'gte', 200), f).map((r) => r.id)).toEqual([1])
90
+ })
91
+ })
@@ -0,0 +1,162 @@
1
+ import { describe, it, expect, afterEach } from 'vitest'
2
+ import { mount, type VueWrapper } from '@vue/test-utils'
3
+ import { nextTick } from 'vue'
4
+ import MSelect from '../components/MSelect.vue'
5
+ import MDatePicker from '../components/MDatePicker.vue'
6
+ import MPhoneInput from '../components/MPhoneInput.vue'
7
+ import { isAnchorHidden } from '../composables/_useFollowAnchor'
8
+
9
+ let wrapper: VueWrapper | undefined
10
+ afterEach(() => {
11
+ wrapper?.unmount()
12
+ wrapper = undefined
13
+ document.body.innerHTML = ''
14
+ })
15
+
16
+ function setRect(el: Element, r: { left: number; top: number; width: number; height: number }) {
17
+ el.getBoundingClientRect = () =>
18
+ ({ ...r, right: r.left + r.width, bottom: r.top + r.height, x: r.left, y: r.top, toJSON: () => ({}) }) as DOMRect
19
+ }
20
+ const frame = () => new Promise((r) => requestAnimationFrame(() => r(null)))
21
+
22
+ describe('isAnchorHidden', () => {
23
+ it('is false inside the window and true once outside it', () => {
24
+ const el = document.createElement('div')
25
+ document.body.appendChild(el)
26
+ setRect(el, { left: 10, top: 10, width: 100, height: 40 })
27
+ expect(isAnchorHidden(el)).toBe(false)
28
+ setRect(el, { left: 10, top: -60, width: 100, height: 40 })
29
+ expect(isAnchorHidden(el)).toBe(true)
30
+ })
31
+
32
+ it('is true when a scroll container around it cuts it away', () => {
33
+ const box = document.createElement('div')
34
+ box.style.overflow = 'auto'
35
+ const el = document.createElement('div')
36
+ box.appendChild(el)
37
+ document.body.appendChild(box)
38
+ setRect(box, { left: 0, top: 100, width: 300, height: 200 })
39
+ setRect(el, { left: 10, top: 150, width: 100, height: 40 })
40
+ expect(isAnchorHidden(el)).toBe(false)
41
+ setRect(el, { left: 10, top: 40, width: 100, height: 40 }) // above the box's top edge
42
+ expect(isAnchorHidden(el)).toBe(true)
43
+ })
44
+
45
+ it('is true for a detached element', () => {
46
+ expect(isAnchorHidden(document.createElement('div'))).toBe(true)
47
+ })
48
+ })
49
+
50
+ const options = [
51
+ { label: 'One', value: 1 },
52
+ { label: 'Two', value: 2 },
53
+ ]
54
+
55
+ async function openSelect() {
56
+ wrapper = mount(MSelect, { props: { modelValue: null, options, label: 'Pick' }, attachTo: document.body })
57
+ const fieldEl = wrapper.element.querySelector('[class*="relative"]')!
58
+ setRect(fieldEl, { left: 20, top: 100, width: 200, height: 56 })
59
+ await wrapper.find('[aria-haspopup], [role="combobox"]').trigger('click')
60
+ await nextTick()
61
+ return fieldEl
62
+ }
63
+
64
+ describe('MSelect dropdown follows its field', () => {
65
+ it('moves with the page scroll instead of closing', async () => {
66
+ const fieldEl = await openSelect()
67
+ const list = document.body.querySelector<HTMLElement>('[role="listbox"]')!
68
+ expect(list.style.top).toBe('160px')
69
+ setRect(fieldEl, { left: 20, top: 40, width: 200, height: 56 })
70
+ window.dispatchEvent(new Event('scroll'))
71
+ await frame()
72
+ await nextTick()
73
+ expect(document.body.querySelector('[role="listbox"]')).not.toBeNull()
74
+ expect(list.style.top).toBe('100px')
75
+ })
76
+
77
+ it('follows a window resize (browser zoom)', async () => {
78
+ const fieldEl = await openSelect()
79
+ const list = document.body.querySelector<HTMLElement>('[role="listbox"]')!
80
+ setRect(fieldEl, { left: 60, top: 100, width: 150, height: 56 })
81
+ window.dispatchEvent(new Event('resize'))
82
+ await frame()
83
+ await nextTick()
84
+ expect(list.style.left).toBe('60px')
85
+ expect(list.style.width).toBe('150px')
86
+ })
87
+
88
+ it('closes once the field is scrolled out of sight', async () => {
89
+ const fieldEl = await openSelect()
90
+ setRect(fieldEl, { left: 20, top: -200, width: 200, height: 56 })
91
+ window.dispatchEvent(new Event('scroll'))
92
+ await frame()
93
+ await nextTick()
94
+ expect(wrapper!.find('[aria-expanded="true"]').exists()).toBe(false)
95
+ })
96
+
97
+ it('also drops focus then, so the field stops looking open', async () => {
98
+ const fieldEl = await openSelect()
99
+ const trigger = wrapper!.find<HTMLElement>('[aria-haspopup], [role="combobox"]').element
100
+ trigger.focus()
101
+ await nextTick()
102
+ const label = () => wrapper!.find('label').exists() ? wrapper!.find('label').classes().join(' ') : ''
103
+ const focusedLabel = label()
104
+ setRect(fieldEl, { left: 20, top: -200, width: 200, height: 56 })
105
+ window.dispatchEvent(new Event('scroll'))
106
+ await frame()
107
+ await nextTick()
108
+ expect(document.activeElement).not.toBe(trigger)
109
+ expect(label()).not.toBe(focusedLabel)
110
+ })
111
+
112
+ it('ignores scrolls inside the list', async () => {
113
+ const fieldEl = await openSelect()
114
+ const list = document.body.querySelector<HTMLElement>('[role="listbox"]')!
115
+ setRect(fieldEl, { left: 20, top: -200, width: 200, height: 56 })
116
+ list.dispatchEvent(new Event('scroll', { bubbles: false }))
117
+ await frame()
118
+ await nextTick()
119
+ expect(document.body.querySelector('[role="listbox"]')).not.toBeNull()
120
+ })
121
+ })
122
+
123
+ describe('MDatePicker panel follows its field', () => {
124
+ it('moves with a container scroll instead of closing', async () => {
125
+ wrapper = mount(MDatePicker, { props: { modelValue: null, label: 'Date' }, attachTo: document.body })
126
+ const trigger = wrapper.element.querySelector('.relative.mt-2')!
127
+ setRect(trigger, { left: 20, top: 100, width: 200, height: 56 })
128
+ await wrapper.find('.relative.mt-2 button').trigger('click')
129
+ await nextTick()
130
+ await nextTick()
131
+ const panel = document.body.querySelector<HTMLElement>('.fixed.z-500')
132
+ expect(panel).toBeTruthy()
133
+ setRect(trigger, { left: 20, top: 50, width: 200, height: 56 })
134
+ document.body.dispatchEvent(new Event('scroll'))
135
+ window.dispatchEvent(new Event('scroll'))
136
+ await frame()
137
+ await nextTick()
138
+ expect(document.body.contains(panel!)).toBe(true)
139
+ expect(panel!.style.top).toBe('110px')
140
+ })
141
+ })
142
+
143
+ describe('MPhoneInput list', () => {
144
+ it('closes once its field is scrolled out of sight', async () => {
145
+ wrapper = mount(MPhoneInput, { props: { modelValue: '', label: 'Phone' }, attachTo: document.body })
146
+ const btn = wrapper.find('button[aria-haspopup]')
147
+ await btn.trigger('click')
148
+ await nextTick()
149
+ await nextTick()
150
+ expect(btn.attributes('aria-expanded')).toBe('true')
151
+ // Every box around the button reports itself off-screen, whichever one is the field
152
+ let el: Element | null = btn.element
153
+ while (el) {
154
+ setRect(el, { left: 0, top: -300, width: 200, height: 56 })
155
+ el = el.parentElement === document.body ? null : el.parentElement
156
+ }
157
+ window.dispatchEvent(new Event('scroll'))
158
+ await frame()
159
+ await nextTick()
160
+ expect(btn.attributes('aria-expanded')).toBe('false')
161
+ })
162
+ })
@@ -48,6 +48,9 @@ const props: Record<string, Record<string, unknown>> = {
48
48
  MShape: { shape: 'Circle' },
49
49
  MSparkline: { data: [3, 1, 4, 1, 5] },
50
50
  MTour: { steps: [{ target: '#x', title: 't' }] },
51
+ MDiffViewer: { original: 'a\nb\nc', modified: 'a\nB\nc\nd' },
52
+ MDashboardGrid: { modelValue: [{ id: 'a', x: 0, y: 0, w: 6, h: 2 }] },
53
+ MFilterBuilder: { fields: [{ key: 'name', label: 'Name' }, { key: 'n', label: 'N', type: 'number' }], modelValue: { id: 'g', combinator: 'and', rules: [{ id: 'r', field: 'n', operator: 'between', value: [1, 2] }] } },
51
54
  }
52
55
 
53
56
  // Overlays rendered open, where the open/scroll-lock code runs
@@ -0,0 +1,37 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { diffLines, diffStats, diffWords } from '../composables/textDiff'
3
+
4
+ const compact = (a: string, b: string) => diffLines(a, b).map((l) => `${l.op === 'equal' ? ' ' : l.op === 'add' ? '+' : '-'}${l.text}`)
5
+
6
+ describe('diffLines', () => {
7
+ it('finds equal, removed and added lines with their numbers', () => {
8
+ const d = diffLines('a\nb\nc\nd', 'a\nB\nc\nd\ne')
9
+ expect(d.map((l) => `${l.op === 'equal' ? ' ' : l.op === 'add' ? '+' : '-'}${l.text}`)).toEqual([' a', '-b', '+B', ' c', ' d', '+e'])
10
+ expect(d[1]).toMatchObject({ oldLine: 2 })
11
+ expect(d[2]).toMatchObject({ newLine: 2 })
12
+ expect(d[5]).toMatchObject({ newLine: 5 })
13
+ expect(diffStats(d)).toEqual({ added: 2, removed: 1 })
14
+ })
15
+
16
+ it('handles empty sides, identical texts and line endings', () => {
17
+ expect(compact('', 'x\ny')).toEqual(['+x', '+y'])
18
+ expect(compact('x\ny', '')).toEqual(['-x', '-y'])
19
+ expect(compact('same\ntext', 'same\ntext')).toEqual([' same', ' text'])
20
+ expect(compact('a\r\nb', 'a\nb')).toEqual([' a', ' b'])
21
+ })
22
+
23
+ it('is minimal on a moved block', () => {
24
+ const d = diffLines('1\n2\n3\n4\n5', '1\n4\n5\n2\n3')
25
+ expect(diffStats(d).added + diffStats(d).removed).toBe(4)
26
+ })
27
+ })
28
+
29
+ describe('diffWords', () => {
30
+ it('marks the changed words of a line', () => {
31
+ expect(diffWords('const total = price * qty', 'const total = price * quantity + tax')).toEqual([
32
+ { op: 'equal', text: 'const total = price * ' },
33
+ { op: 'remove', text: 'qty' },
34
+ { op: 'add', text: 'quantity + tax' },
35
+ ])
36
+ })
37
+ })
@@ -0,0 +1,301 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * An address field: a text field that looks places up through a `MapSearchProvider` (OpenStreetMap's Nominatim by
4
+ * default, or your own function) and lists them under it to pick one. The picked place (label, `[lng, lat]`, extent,
5
+ * kind) is the v-model; editing the text afterwards clears it. Enter searches (Nominatim's public server allows no
6
+ * search-as-you-type); with `instant`, it searches while typing, debounced, for providers that allow it. Arrow keys
7
+ * move through the results, Enter picks, Escape closes. Needs no map: put it in any form. Available from the `/map`
8
+ * entry point.
9
+ *
10
+ * @event update:modelValue A place was picked, or the text changed after picking one (null)
11
+ * @event select A place was picked
12
+ */
13
+ import { computed, nextTick, onBeforeUnmount, ref, shallowRef, useId, watch, watchEffect } from 'vue'
14
+ import MIcon from './MIcon.vue'
15
+ import MIconButton from './MIconButton.vue'
16
+ import MSpinner from './MSpinner.vue'
17
+ import MTextField from './MTextField.vue'
18
+ import { useLocale } from '../composables/useLocale'
19
+ import { useEscapeStack } from '../composables/_useEscapeStack'
20
+ import { useFollowAnchor } from '../composables/_useFollowAnchor'
21
+ import { POPUP_MARGIN, fitPopup } from '../composables/_popupPosition'
22
+ import { nominatimProvider, placeIcon, type MapSearchProvider, type MapSearchResult } from '../composables/mapSearch'
23
+
24
+ // The root is the field plus a teleported list: attributes go on the field
25
+ defineOptions({ inheritAttrs: false })
26
+
27
+ const props = withDefaults(
28
+ defineProps<{
29
+ /** The picked place (v-model), or null */
30
+ modelValue?: MapSearchResult | null
31
+ /** Where to search: `nominatimProvider(options)` by default, or your own function */
32
+ provider?: MapSearchProvider
33
+ /** The field's label (the locale's "Address" by default) */
34
+ label?: string
35
+ /** Field style */
36
+ variant?: 'filled' | 'outlined'
37
+ /** Material Symbol on the left */
38
+ leadingIcon?: string
39
+ /** Search while typing (debounced), for providers that allow it; Nominatim's public server doesn't */
40
+ instant?: boolean
41
+ /** The delay before an `instant` search, in ms */
42
+ debounce?: number
43
+ /** Characters needed before searching */
44
+ minLength?: number
45
+ /** Helper text below the field */
46
+ hint?: string
47
+ /** Error state */
48
+ error?: boolean
49
+ /** Error message shown when `error` is true */
50
+ errorLabel?: string
51
+ /** Marks it as required */
52
+ required?: boolean
53
+ /** Disables the field */
54
+ disabled?: boolean
55
+ }>(),
56
+ { modelValue: null, variant: 'filled', leadingIcon: 'location_on', instant: false, debounce: 400, minLength: 3 },
57
+ )
58
+
59
+ const emit = defineEmits<{
60
+ 'update:modelValue': [place: MapSearchResult | null]
61
+ select: [place: MapSearchResult]
62
+ }>()
63
+
64
+ const t = useLocale()
65
+ const uid = useId()
66
+ const listId = `${uid}-list`
67
+ const optionId = (i: number) => `${uid}-opt-${i}`
68
+ const provider = computed(() => props.provider ?? nominatimProvider())
69
+
70
+ const text = ref(props.modelValue?.label ?? '')
71
+ const results = shallowRef<MapSearchResult[]>([])
72
+ const loading = ref(false)
73
+ const searched = ref(false)
74
+ const focused = ref(false)
75
+ const open = ref(false)
76
+ const active = ref(-1)
77
+ let controller: AbortController | undefined
78
+ let timer: ReturnType<typeof setTimeout> | undefined
79
+
80
+ const field = ref<InstanceType<typeof MTextField>>()
81
+ const wrapEl = ref<HTMLElement>()
82
+ const listEl = ref<HTMLElement>()
83
+ // The field's box (MTextField's first child), without its hint
84
+ const anchorEl = computed(() => (wrapEl.value?.firstElementChild?.firstElementChild as HTMLElement | null) ?? null)
85
+ const listPos = ref<Record<string, string>>({})
86
+
87
+ const longEnough = computed(() => text.value.trim().length >= props.minLength)
88
+ /** "Press Enter to search": typed enough, not searched for this text yet, and no search while typing */
89
+ const showHint = computed(() => !props.instant && focused.value && longEnough.value && !searched.value && !loading.value && !props.modelValue)
90
+
91
+ // The picked place shows as the text; a new one from outside replaces it
92
+ watch(() => props.modelValue, (place) => {
93
+ if (place && place.label !== text.value) text.value = place.label
94
+ // Reset from outside (a form cleared): not while the user is typing, which also sets it to null
95
+ else if (!place && !focused.value) text.value = ''
96
+ })
97
+
98
+ async function search() {
99
+ const q = text.value.trim()
100
+ if (q.length < props.minLength) return
101
+ controller?.abort()
102
+ clearTimeout(timer)
103
+ controller = new AbortController()
104
+ const mine = controller
105
+ loading.value = true
106
+ open.value = true
107
+ try {
108
+ results.value = await provider.value(q, mine.signal)
109
+ active.value = results.value.length ? 0 : -1
110
+ } catch {
111
+ if (mine.signal.aborted) return
112
+ results.value = []
113
+ } finally {
114
+ if (controller === mine) {
115
+ loading.value = false
116
+ searched.value = true
117
+ }
118
+ }
119
+ }
120
+
121
+ function onText(value: string | number) {
122
+ text.value = String(value)
123
+ searched.value = false
124
+ results.value = []
125
+ active.value = -1
126
+ if (props.modelValue) emit('update:modelValue', null)
127
+ controller?.abort()
128
+ loading.value = false
129
+ clearTimeout(timer)
130
+ if (!longEnough.value) {
131
+ open.value = false
132
+ return
133
+ }
134
+ open.value = !props.instant // the hint row
135
+ if (props.instant) timer = setTimeout(search, props.debounce)
136
+ }
137
+
138
+ function pick(place: MapSearchResult) {
139
+ text.value = place.label
140
+ open.value = false
141
+ results.value = []
142
+ searched.value = false
143
+ emit('update:modelValue', place)
144
+ emit('select', place)
145
+ }
146
+
147
+ function clear() {
148
+ controller?.abort()
149
+ clearTimeout(timer)
150
+ text.value = ''
151
+ results.value = []
152
+ searched.value = false
153
+ loading.value = false
154
+ open.value = false
155
+ if (props.modelValue) emit('update:modelValue', null)
156
+ field.value?.focus()
157
+ }
158
+
159
+ function onKeydown(e: KeyboardEvent) {
160
+ if (e.key === 'Enter') {
161
+ e.preventDefault()
162
+ const r = results.value[active.value]
163
+ if (open.value && r && searched.value) pick(r)
164
+ else void search()
165
+ } else if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
166
+ if (!open.value || !results.value.length) return
167
+ e.preventDefault()
168
+ const n = results.value.length
169
+ active.value = (active.value + (e.key === 'ArrowDown' ? 1 : -1) + n) % n
170
+ nextTick(() => listEl.value?.querySelector(`#${CSS.escape(optionId(active.value))}`)?.scrollIntoView({ block: 'nearest' }))
171
+ }
172
+ }
173
+
174
+ function onFocusIn() {
175
+ focused.value = true
176
+ if (searched.value && results.value.length && !props.modelValue) open.value = true
177
+ else if (showHint.value) open.value = true
178
+ }
179
+ function onFocusOut(e: FocusEvent) {
180
+ const next = e.relatedTarget as Node | null
181
+ if (next && (wrapEl.value?.contains(next) || listEl.value?.contains(next))) return
182
+ focused.value = false
183
+ open.value = false
184
+ }
185
+
186
+ // Escape closes the list (and only that, inside a dialog)
187
+ useEscapeStack(() => open.value, () => (open.value = false))
188
+
189
+ const visible = computed(() => open.value && (loading.value || searched.value || showHint.value))
190
+
191
+ // The list hangs under the field, as wide as it, or above it when there's no room
192
+ function place() {
193
+ const anchor = anchorEl.value?.getBoundingClientRect()
194
+ const list = listEl.value
195
+ if (!anchor || !list) return
196
+ const h = list.offsetHeight
197
+ const top = fitPopup([anchor.bottom + 4, anchor.top - 4 - h], h, window.innerHeight, POPUP_MARGIN)
198
+ listPos.value = { top: `${top}px`, left: `${anchor.left}px`, width: `${anchor.width}px` }
199
+ }
200
+ watch([visible, results, loading], () => nextTick(place))
201
+ useFollowAnchor({ open: () => visible.value, anchor: anchorEl, popup: listEl, place, close: () => (open.value = false) })
202
+
203
+ // The input as an ARIA combobox pointing at its list and the result the arrows are on
204
+ watchEffect(() => {
205
+ const input = field.value?.inputEl as HTMLInputElement | undefined
206
+ if (!input) return
207
+ input.setAttribute('role', 'combobox')
208
+ input.setAttribute('aria-autocomplete', 'list')
209
+ input.setAttribute('aria-expanded', String(visible.value && results.value.length > 0))
210
+ input.setAttribute('aria-controls', listId)
211
+ input.setAttribute('enterkeyhint', 'search')
212
+ if (visible.value && active.value >= 0 && results.value.length) input.setAttribute('aria-activedescendant', optionId(active.value))
213
+ else input.removeAttribute('aria-activedescendant')
214
+ })
215
+
216
+ onBeforeUnmount(() => {
217
+ controller?.abort()
218
+ clearTimeout(timer)
219
+ })
220
+
221
+ /** A result's first part (the place itself) and the rest (where it is) */
222
+ function parts(label: string) {
223
+ const i = label.indexOf(', ')
224
+ return i < 0 ? [label, ''] : [label.slice(0, i), label.slice(i + 2)]
225
+ }
226
+
227
+ defineExpose({
228
+ /** Searches for the current text now */
229
+ search,
230
+ /** Empties the field */
231
+ clear,
232
+ /** Focuses the field */
233
+ focus: () => field.value?.focus(),
234
+ })
235
+ </script>
236
+
237
+ <template>
238
+ <div ref="wrapEl" v-bind="$attrs" @focusin="onFocusIn" @focusout="onFocusOut" @keydown="onKeydown">
239
+ <MTextField
240
+ ref="field"
241
+ :model-value="text"
242
+ :label="label ?? t.mapAddress"
243
+ :variant="variant"
244
+ :leading-icon="leadingIcon"
245
+ :hint="hint"
246
+ :error="error"
247
+ :error-label="errorLabel"
248
+ :required="required"
249
+ :disabled="disabled"
250
+ autocomplete="street-address"
251
+ @update:model-value="onText"
252
+ >
253
+ <!-- Always passed: MTextField reserves the room for #trailing only when the slot exists from the start -->
254
+ <template #trailing>
255
+ <MSpinner v-if="loading" :size="20" class="m-2" />
256
+ <MIconButton v-else-if="text" icon="close" :label="t.clearSearch" size="sm" :disabled="disabled" @click="clear" />
257
+ </template>
258
+ </MTextField>
259
+ </div>
260
+
261
+ <Teleport to="body">
262
+ <div
263
+ v-if="visible"
264
+ :id="listId"
265
+ ref="listEl"
266
+ role="listbox"
267
+ :aria-label="label ?? t.mapAddress"
268
+ class="fixed z-500 max-h-72 overflow-auto rounded-xs bg-surface-container py-1 shadow-elevation-2"
269
+ :style="listPos"
270
+ >
271
+ <div v-if="loading" class="flex items-center gap-3 px-4 py-3 text-body-medium text-on-surface-variant" role="status">
272
+ <MSpinner :size="20" />{{ t.mapSearching }}
273
+ </div>
274
+ <div v-else-if="showHint" class="flex items-center gap-3 px-4 py-3 text-body-medium text-on-surface-variant">
275
+ <MIcon name="keyboard_return" :size="20" />{{ t.mapPressEnterToSearch }}
276
+ </div>
277
+ <div v-else-if="!results.length" class="flex items-center gap-3 px-4 py-3 text-body-medium text-on-surface-variant" role="status">
278
+ <MIcon name="search_off" :size="20" />{{ t.mapNoPlaces }}
279
+ </div>
280
+ <template v-else>
281
+ <div
282
+ v-for="(r, i) in results"
283
+ :id="optionId(i)"
284
+ :key="i"
285
+ role="option"
286
+ :aria-selected="i === active"
287
+ class="flex cursor-pointer items-center gap-3 px-4 py-2 text-on-surface hover:bg-on-surface/8"
288
+ :class="i === active ? 'bg-on-surface/12' : ''"
289
+ @mousedown.prevent="pick(r)"
290
+ @mousemove="active = i"
291
+ >
292
+ <MIcon :name="placeIcon(r.type)" :size="20" class="shrink-0 text-on-surface-variant" />
293
+ <span class="flex min-w-0 flex-col">
294
+ <span class="truncate text-body-large">{{ parts(r.label)[0] }}</span>
295
+ <span v-if="parts(r.label)[1]" class="truncate text-body-small text-on-surface-variant">{{ parts(r.label)[1] }}</span>
296
+ </span>
297
+ </div>
298
+ </template>
299
+ </div>
300
+ </Teleport>
301
+ </template>