@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,188 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
2
+ import { flushPromises, mount } from '@vue/test-utils'
3
+ import { defineComponent, h, nextTick, ref } from 'vue'
4
+ import { created, type FakeMap } from './_fakeMaplibre'
5
+
6
+ vi.mock('maplibre-gl', async () => (await import('./_fakeMaplibre')).fakeModule)
7
+
8
+ const { MMap, MMapDraw, MMapIdentify, orvianAdapter } = await import('../map')
9
+ type Collection = { type: 'FeatureCollection'; features: { id?: string | number; geometry: { type: string; coordinates: unknown }; properties: Record<string, unknown> | null }[] }
10
+
11
+ beforeEach(() => {
12
+ created.maps = []
13
+ created.markers = []
14
+ created.popups = []
15
+ document.documentElement.lang = 'en'
16
+ document.documentElement.style.setProperty('--color-primary', '#6750a4')
17
+ document.documentElement.style.setProperty('--color-surface', '#fef7ff')
18
+ })
19
+ afterEach(() => { document.body.innerHTML = '' })
20
+
21
+ /** An MMap with an MMapDraw bound to a ref (v-model), like a consumer. */
22
+ async function mountDraw(initial?: Collection, extra: Record<string, unknown> = {}, more?: () => unknown) {
23
+ const shapes = ref<Collection | undefined>(initial)
24
+ const onSelect = vi.fn()
25
+ const Host = defineComponent({
26
+ setup: () => () => h(MMap, { mapStyle: 's', ...(more ? { adapter: orvianAdapter() } : {}) }, () => [
27
+ h(MMapDraw, { modelValue: shapes.value as never, 'onUpdate:modelValue': (v: Collection) => (shapes.value = v), onSelect, ...extra }),
28
+ more?.(),
29
+ ]),
30
+ })
31
+ const wrapper = mount(Host, { attachTo: document.body })
32
+ await flushPromises()
33
+ const map = created.maps.at(-1)! as FakeMap
34
+ map.load()
35
+ await nextTick()
36
+ await nextTick()
37
+ return { wrapper, map, shapes, onSelect }
38
+ }
39
+
40
+ const button = (label: string) => document.querySelector<HTMLButtonElement>(`button[aria-label="${label}"]`)!
41
+ const press = async (label: string) => { button(label).click(); await nextTick() }
42
+ const click = (map: FakeMap, lng: number, lat: number) =>
43
+ map.fire('click', { target: map, lngLat: { lng, lat }, point: map.project([lng, lat]) })
44
+ const key = (k: string) => document.dispatchEvent(new KeyboardEvent('keydown', { key: k, cancelable: true }))
45
+ const sourceData = (map: FakeMap, suffix: string) =>
46
+ [...map.sources.entries()].find(([id]) => id.endsWith(suffix))![1].data as { features: { geometry: { type: string }; properties: Record<string, unknown> }[] }
47
+ /** Pretend the pointer is over this shape (what queryRenderedFeatures finds) */
48
+ const hover = (map: FakeMap, id: string) => {
49
+ const layer = map.layers.find((l) => l.id.endsWith('-shapes-line'))!.id
50
+ map.rendered = [{ layer: { id: layer }, properties: { __draw_id: id } }]
51
+ }
52
+
53
+ describe('MMapDraw', () => {
54
+ it('draws a point with one click', async () => {
55
+ const { map, shapes, onSelect } = await mountDraw()
56
+ await press('Draw a point')
57
+ expect(map.canvas.style.cursor).toBe('crosshair')
58
+ click(map, -64.19, -31.42)
59
+ await nextTick()
60
+ expect(shapes.value!.features).toHaveLength(1)
61
+ expect(shapes.value!.features[0]).toMatchObject({ type: 'Feature', id: 'shape-1', geometry: { type: 'Point', coordinates: [-64.19, -31.42] }, properties: {} })
62
+ expect(map.canvas.style.cursor).toBe('')
63
+ expect(onSelect).toHaveBeenLastCalledWith(expect.objectContaining({ id: 'shape-1' }))
64
+ })
65
+
66
+ it('draws a line, finished with Enter, with Backspace taking back a point', async () => {
67
+ const { map, shapes } = await mountDraw()
68
+ await press('Draw a line')
69
+ click(map, 0, 0)
70
+ click(map, 1, 1)
71
+ click(map, 2, 2)
72
+ key('Backspace')
73
+ key('Enter')
74
+ await nextTick()
75
+ expect(shapes.value!.features[0]!.geometry).toEqual({ type: 'LineString', coordinates: [[0, 0], [1, 1]] })
76
+ })
77
+
78
+ it('closes a polygon by clicking its first point, and drops one with too few points', async () => {
79
+ const { map, shapes } = await mountDraw()
80
+ await press('Draw a polygon')
81
+ click(map, 0, 0)
82
+ click(map, 0.1, 0)
83
+ click(map, 0.1, 0.1)
84
+ click(map, 0.0001, 0.0001) // within 20px of the first point
85
+ await nextTick()
86
+ expect(shapes.value!.features[0]!.geometry).toEqual({ type: 'Polygon', coordinates: [[[0, 0], [0.1, 0], [0.1, 0.1], [0, 0]]] })
87
+ await press('Draw a polygon')
88
+ click(map, 1, 1)
89
+ click(map, 1.1, 1)
90
+ key('Escape')
91
+ await nextTick()
92
+ expect(shapes.value!.features).toHaveLength(1)
93
+ })
94
+
95
+ it('selects a shape on click, deletes it with Delete, and keeps others\' ids and properties', async () => {
96
+ const initial: Collection = {
97
+ type: 'FeatureCollection',
98
+ features: [
99
+ { id: 7, geometry: { type: 'LineString', coordinates: [[0, 0], [1, 1]] }, properties: { name: 'Road' } },
100
+ { geometry: { type: 'Point', coordinates: [2, 2] }, properties: { name: 'Stop' } },
101
+ ],
102
+ }
103
+ const { map, shapes, onSelect } = await mountDraw(initial)
104
+ hover(map, '7')
105
+ click(map, 0.5, 0.5)
106
+ await nextTick()
107
+ expect(onSelect).toHaveBeenLastCalledWith(expect.objectContaining({ id: 7, properties: { name: 'Road' } }))
108
+ expect(sourceData(map, '-shapes').features[0]!.properties).toMatchObject({ name: 'Road', __draw_selected: true })
109
+ // Its handles: two vertices and a midpoint
110
+ expect(sourceData(map, '-handles').features.map((f) => f.properties.handle)).toEqual(['vertex', 'vertex', 'midpoint'])
111
+ expect(button('Delete the selected shape').disabled).toBe(false)
112
+ key('Delete')
113
+ await nextTick()
114
+ expect(shapes.value!.features).toHaveLength(1)
115
+ expect(shapes.value!.features[0]).toMatchObject({ id: 'shape-1', properties: { name: 'Stop' } })
116
+ expect(onSelect).toHaveBeenLastCalledWith(null)
117
+ })
118
+
119
+ it('clears the selection on a click on empty map', async () => {
120
+ const { map, onSelect } = await mountDraw({ type: 'FeatureCollection', features: [{ id: 'a', geometry: { type: 'Point', coordinates: [0, 0] }, properties: {} }] })
121
+ hover(map, 'a')
122
+ click(map, 0, 0)
123
+ map.rendered = []
124
+ click(map, 5, 5)
125
+ expect(onSelect).toHaveBeenLastCalledWith(null)
126
+ })
127
+
128
+ it('drags a vertex, adds one from a midpoint and removes one with a double click', async () => {
129
+ const { map, shapes } = await mountDraw({ type: 'FeatureCollection', features: [{ id: 'l', geometry: { type: 'LineString', coordinates: [[0, 0], [2, 0]] }, properties: {} }] })
130
+ hover(map, 'l')
131
+ click(map, 1, 0)
132
+ const vertex = map.layers.find((l) => l.id.endsWith('-handles-vertex'))!.id
133
+ const mid = map.layers.find((l) => l.id.endsWith('-handles-midpoint'))!.id
134
+ const down = (layer: string, properties: Record<string, unknown>, lng: number, lat: number) =>
135
+ map.fire(`mousedown:${layer}`, { type: 'mousedown', features: [{ properties }], lngLat: { lng, lat }, preventDefault() {} })
136
+ // Move the second vertex
137
+ down(vertex, { handle: 'vertex', v: 1 }, 2, 0)
138
+ map.fire('mousemove', { lngLat: { lng: 3, lat: 1 } })
139
+ map.fire('mouseup')
140
+ expect(shapes.value!.features[0]!.geometry.coordinates).toEqual([[0, 0], [3, 1]])
141
+ // Pull the midpoint out: a new vertex in between
142
+ down(mid, { handle: 'midpoint', after: 0 }, 1.5, 0.5)
143
+ map.fire('mousemove', { lngLat: { lng: 1.5, lat: 2 } })
144
+ map.fire('mouseup')
145
+ expect(shapes.value!.features[0]!.geometry.coordinates).toEqual([[0, 0], [1.5, 2], [3, 1]])
146
+ // Double-click the new vertex away; a line keeps at least two
147
+ map.fire(`dblclick:${vertex}`, { features: [{ properties: { handle: 'vertex', v: 1 } }], preventDefault() {} })
148
+ expect(shapes.value!.features[0]!.geometry.coordinates).toEqual([[0, 0], [3, 1]])
149
+ map.fire(`dblclick:${vertex}`, { features: [{ properties: { handle: 'vertex', v: 1 } }], preventDefault() {} })
150
+ expect(shapes.value!.features[0]!.geometry.coordinates).toEqual([[0, 0], [3, 1]])
151
+ })
152
+
153
+ it('reloads when the v-model changes from outside', async () => {
154
+ const { map, shapes } = await mountDraw()
155
+ shapes.value = { type: 'FeatureCollection', features: [{ id: 'x', geometry: { type: 'Point', coordinates: [4, 4] }, properties: {} }] }
156
+ await nextTick()
157
+ expect(sourceData(map, '-shapes').features).toHaveLength(1)
158
+ })
159
+
160
+ it('keeps MMapIdentify quiet while drawing', async () => {
161
+ const onIdentify = vi.fn()
162
+ const { map } = await mountDraw(undefined, {}, () => h(MMapIdentify, { onIdentify }))
163
+ await press('Draw a line')
164
+ click(map, 1, 1)
165
+ expect(onIdentify).not.toHaveBeenCalled()
166
+ key('Escape')
167
+ click(map, 1, 1)
168
+ expect(onIdentify).toHaveBeenCalledTimes(1)
169
+ })
170
+
171
+ it('draws only with editable false, and starts from v-model:mode', async () => {
172
+ const onMode = vi.fn()
173
+ const { map, onSelect } = await mountDraw(undefined, { editable: false, mode: 'point', 'onUpdate:mode': onMode })
174
+ expect(document.querySelector('button[aria-label="Delete the selected shape"]')).toBeNull()
175
+ click(map, 1, 1)
176
+ await nextTick()
177
+ expect(onMode).toHaveBeenLastCalledWith(null)
178
+ expect(onSelect).not.toHaveBeenCalled()
179
+ })
180
+
181
+ it('cleans up its layers and sources on unmount', async () => {
182
+ const { wrapper, map } = await mountDraw()
183
+ expect(map.sources.size).toBe(3)
184
+ wrapper.unmount()
185
+ expect(map.sources.size).toBe(0)
186
+ expect(map.layers).toEqual([])
187
+ })
188
+ })
@@ -90,6 +90,62 @@ describe('genericAdapter', () => {
90
90
  const model = genericAdapter(orvianStyle() as unknown as StyleSpecification, {})
91
91
  expect(model.layers.find((l) => l.id === 'roads')).toMatchObject({ title: 'roads', listed: true, identify: { format: {}, exclude: [] }, hover: false })
92
92
  expect(model.layers.find((l) => l.id === 'osm')!.identify).toBe(false)
93
+ // Orvian's own keys mean nothing here
94
+ expect(model.layers.find((l) => l.id === 'osm')).toMatchObject({ listed: true, base: undefined })
95
+ })
96
+
97
+ it('reads base layers, thumbnails, children and listed from neutral metadata', () => {
98
+ const style = {
99
+ version: 8,
100
+ sources: {},
101
+ layers: [
102
+ { id: 'osm', type: 'raster', metadata: { base: true, image: 'osm.png', title: 'Streets' } },
103
+ { id: 'sat', type: 'raster', metadata: { base: { image: 'sat.png' } } },
104
+ { id: 'vector-base', type: 'fill', metadata: { base: true, children: ['vb-roads', 'vb-labels'] } },
105
+ { id: 'vb-roads', type: 'line' },
106
+ { id: 'vb-labels', type: 'symbol' },
107
+ { id: 'parcels', type: 'fill', metadata: { children: ['parcels-line'] } },
108
+ { id: 'parcels-line', type: 'line', metadata: { listed: false } },
109
+ ],
110
+ }
111
+ const model = genericAdapter(style as unknown as StyleSpecification, {})
112
+ const layer = (id: string) => model.layers.find((l) => l.id === id)!
113
+ expect(layer('osm')).toMatchObject({ title: 'Streets', listed: false, base: { image: 'osm.png' }, identify: false })
114
+ expect(layer('sat')).toMatchObject({ listed: false, base: { image: 'sat.png' } })
115
+ expect(layer('vector-base')).toMatchObject({ listed: false, base: { image: undefined }, children: ['vb-roads', 'vb-labels'], identify: false })
116
+ expect(layer('vb-roads')).toMatchObject({ listed: false, identify: false, base: undefined })
117
+ expect(layer('parcels')).toMatchObject({ listed: true, children: ['parcels-line'] })
118
+ expect(layer('parcels-line').listed).toBe(false)
119
+ })
120
+
121
+ it('drives MMapBaseLayers without the Orvian conventions', async () => {
122
+ const style = {
123
+ version: 8,
124
+ sources: {},
125
+ layers: [
126
+ { id: 'osm', type: 'raster', metadata: { base: true, image: 'osm.png', title: 'Streets' } },
127
+ { id: 'sat', type: 'raster', layout: { visibility: 'none' }, metadata: { base: true, image: 'sat.png', title: 'Satellite' } },
128
+ ],
129
+ }
130
+ const wrapper = mount(MMap, {
131
+ props: { mapStyle: 'https://x.test/style.json', adapter: genericAdapter },
132
+ slots: { default: () => h(MMapBaseLayers, { imageBase: '/img/' }) },
133
+ attachTo: document.body,
134
+ })
135
+ await flushPromises()
136
+ const map = created.maps.at(-1)! as FakeMap
137
+ map.style = style as never
138
+ map.load()
139
+ await nextTick()
140
+ await nextTick()
141
+ const radios = wrapper.findAll('[role="radio"]')
142
+ expect(radios.length).toBe(3) // two base layers + none
143
+ expect(radios[0]!.find('img').attributes('src')).toBe('/img/osm.png')
144
+ expect(radios[0]!.attributes('aria-checked')).toBe('true')
145
+ await radios[1]!.trigger('click')
146
+ expect(radios[1]!.attributes('aria-checked')).toBe('true')
147
+ expect(map.getLayoutProperty('osm', 'visibility')).toBe('none')
148
+ wrapper.unmount()
93
149
  })
94
150
  })
95
151
 
@@ -0,0 +1,163 @@
1
+ import { afterEach, describe, expect, it, vi } from 'vitest'
2
+ import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
3
+ import { defineComponent, h, nextTick, ref } from 'vue'
4
+ import MMentionField from '../components/MMentionField.vue'
5
+ import type { MentionItem, MentionRef, MentionSource } from '../components/MMentionField.vue'
6
+
7
+ const PEOPLE: MentionItem[] = [
8
+ { id: 1, label: 'Ana López', description: 'Design' },
9
+ { id: 2, label: 'Bruno Díaz', description: 'Backend' },
10
+ { id: 3, label: 'Mariana Paz', avatar: 'https://img.test/m.png' },
11
+ ]
12
+ const TAGS: MentionItem[] = [{ id: 'bug', label: 'bug', icon: 'bug_report' }, { id: 'ux', label: 'ux' }]
13
+
14
+ let wrapper: VueWrapper | undefined
15
+ afterEach(() => {
16
+ wrapper?.unmount()
17
+ wrapper = undefined
18
+ document.body.innerHTML = ''
19
+ vi.useRealTimers()
20
+ })
21
+
22
+ function mountField(sources: MentionSource[] = [{ trigger: '@', items: PEOPLE }, { trigger: '#', items: TAGS }], slots = {}) {
23
+ const text = ref('')
24
+ const mentions = ref<MentionRef[]>([])
25
+ const onMention = vi.fn()
26
+ const Host = defineComponent({
27
+ setup: () => () => h(MMentionField, {
28
+ modelValue: text.value, 'onUpdate:modelValue': (v: string) => (text.value = v),
29
+ mentions: mentions.value, 'onUpdate:mentions': (v: MentionRef[]) => (mentions.value = v),
30
+ onMention, sources, label: 'Message',
31
+ }, slots),
32
+ })
33
+ wrapper = mount(Host, { attachTo: document.body })
34
+ const el = wrapper.find('textarea').element as HTMLTextAreaElement
35
+ /** Types the whole text with the caret at its end (or at `caret`) */
36
+ const type = async (value: string, caret = value.length) => {
37
+ el.value = value
38
+ el.setSelectionRange(caret, caret)
39
+ el.dispatchEvent(new Event('input'))
40
+ await nextTick()
41
+ await nextTick()
42
+ }
43
+ const key = async (k: string, opts: KeyboardEventInit = {}) => {
44
+ el.dispatchEvent(new KeyboardEvent('keydown', { key: k, bubbles: true, cancelable: true, ...opts }))
45
+ await nextTick()
46
+ }
47
+ return { text, mentions, onMention, el, type, key }
48
+ }
49
+
50
+ const options = () => [...document.body.querySelectorAll<HTMLElement>('[role="option"]')]
51
+ const list = () => document.body.querySelector('[role="listbox"]')
52
+
53
+ describe('MMentionField', () => {
54
+ it('opens on a trigger at the start of a word, filtered without accents or case', async () => {
55
+ const { type, el } = mountField()
56
+ await type('Hi @')
57
+ expect(options().map((o) => o.querySelector('.text-body-large')!.textContent)).toEqual(['Ana López', 'Bruno Díaz', 'Mariana Paz'])
58
+ await type('Hi @ana')
59
+ // "Ana López" starts with it, "Mariana Paz" only contains it
60
+ expect(options().map((o) => o.querySelector('.text-body-large')!.textContent)).toEqual(['Ana López', 'Mariana Paz'])
61
+ await type('Hi @diaz')
62
+ expect(options()).toHaveLength(1)
63
+ expect(el.getAttribute('aria-expanded')).toBe('true')
64
+ // Inside a word (an email) it's not a mention
65
+ await type('mail me at ana@ex')
66
+ expect(list()).toBeNull()
67
+ // A space ends the query
68
+ await type('Hi @ana ')
69
+ expect(list()).toBeNull()
70
+ })
71
+
72
+ it('picks with the keyboard, writing the label and keeping the mention with its id', async () => {
73
+ const { type, key, text, mentions, onMention, el } = mountField()
74
+ await type('Hi @an')
75
+ await key('ArrowDown')
76
+ expect(el.getAttribute('aria-activedescendant')).toBe(options()[1]!.id)
77
+ await key('Enter')
78
+ expect(text.value).toBe('Hi @Mariana Paz ')
79
+ expect(mentions.value).toEqual([{ trigger: '@', id: 3, label: 'Mariana Paz' }])
80
+ expect(onMention).toHaveBeenCalledWith(PEOPLE[2], '@')
81
+ expect(list()).toBeNull()
82
+ })
83
+
84
+ it('picks with the pointer, mid-text, and handles a second trigger', async () => {
85
+ const { type, text, mentions } = mountField()
86
+ await type('Fixed #b today', 'Fixed #b'.length)
87
+ expect(options()).toHaveLength(1)
88
+ options()[0]!.dispatchEvent(new MouseEvent('mousedown', { bubbles: true, cancelable: true }))
89
+ await nextTick()
90
+ expect(text.value).toBe('Fixed #bug today')
91
+ expect(mentions.value).toEqual([{ trigger: '#', id: 'bug', label: 'bug' }])
92
+ // Its icon instead of initials
93
+ await type('#u')
94
+ expect(options()[0]!.textContent).toContain('ux')
95
+ })
96
+
97
+ it('drops a mention once its text is gone', async () => {
98
+ const { type, key, mentions } = mountField()
99
+ await type('@br')
100
+ await key('Enter')
101
+ expect(mentions.value).toHaveLength(1)
102
+ await type('@Bruno Dí')
103
+ expect(mentions.value).toEqual([])
104
+ })
105
+
106
+ it('closes on Escape, and Enter then types as usual', async () => {
107
+ const { type, key } = mountField()
108
+ await type('@a')
109
+ expect(list()).not.toBeNull()
110
+ await key('Escape')
111
+ expect(list()).toBeNull()
112
+ const enter = new KeyboardEvent('keydown', { key: 'Enter', bubbles: true, cancelable: true })
113
+ wrapper!.find('textarea').element.dispatchEvent(enter)
114
+ expect(enter.defaultPrevented).toBe(false)
115
+ })
116
+
117
+ it('looks items up through search, debounced, aborting a replaced query', async () => {
118
+ vi.useFakeTimers()
119
+ const search = vi.fn(async (q: string) => PEOPLE.filter((p) => p.label.toLowerCase().startsWith(q)))
120
+ const { type } = mountField([{ trigger: '@', search }])
121
+ await type('@a')
122
+ await type('@an')
123
+ expect(document.body.textContent).toContain('Loading')
124
+ // A key that types nothing while the search is on its way doesn't make its answer look stale
125
+ wrapper!.find('textarea').element.dispatchEvent(new KeyboardEvent('keyup', { key: 'Shift', bubbles: true }))
126
+ await vi.advanceTimersByTimeAsync(200)
127
+ await flushPromises()
128
+ expect(search).toHaveBeenCalledTimes(1)
129
+ expect(search.mock.calls[0]![0]).toBe('an')
130
+ expect(options()).toHaveLength(1)
131
+ })
132
+
133
+ it('marks the Enter it picks with, before the consumer\'s own @keydown sees it', async () => {
134
+ const seen: boolean[] = []
135
+ const text = ref('')
136
+ const Host = defineComponent({
137
+ setup: () => () => h(MMentionField, {
138
+ modelValue: text.value, 'onUpdate:modelValue': (v: string) => (text.value = v),
139
+ sources: [{ trigger: '@', items: PEOPLE }], label: 'Message',
140
+ onKeydown: (e: KeyboardEvent) => seen.push(e.defaultPrevented),
141
+ }),
142
+ })
143
+ wrapper = mount(Host, { attachTo: document.body })
144
+ const el = wrapper.find('textarea').element as HTMLTextAreaElement
145
+ el.value = '@bru'
146
+ el.setSelectionRange(4, 4)
147
+ el.dispatchEvent(new Event('input'))
148
+ await nextTick()
149
+ await nextTick()
150
+ el.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true, cancelable: true }))
151
+ await nextTick()
152
+ el.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true, cancelable: true }))
153
+ // The first Enter picked (prevented), the second is the consumer's to use
154
+ expect(seen).toEqual([true, false])
155
+ expect(text.value).toBe('@Bruno Díaz ')
156
+ })
157
+
158
+ it('takes an #item slot', async () => {
159
+ const { type } = mountField(undefined, { item: ({ item, active }: { item: MentionItem; active: boolean }) => h('b', `${item.label}${active ? '*' : ''}`) })
160
+ await type('@bru')
161
+ expect(options()[0]!.textContent).toBe('Bruno Díaz*')
162
+ })
163
+ })
@@ -0,0 +1,94 @@
1
+ import { afterEach, describe, expect, it } from 'vitest'
2
+ import { mount, type VueWrapper } from '@vue/test-utils'
3
+ import { defineComponent, h, nextTick, ref } from 'vue'
4
+ import MNotificationCenter from '../components/MNotificationCenter.vue'
5
+ import MChip from '../components/MChip.vue'
6
+ import type { InboxNotification } from '../components/MNotificationCenter.vue'
7
+
8
+ let wrapper: VueWrapper | undefined
9
+ afterEach(() => {
10
+ wrapper?.unmount()
11
+ wrapper = undefined
12
+ })
13
+
14
+ const now = Date.now()
15
+ const items = (): InboxNotification[] => [
16
+ { id: 1, title: 'New order', body: '3 items from Ana', time: now - 5 * 60e3, icon: 'shopping_bag', color: 'primary' },
17
+ { id: 2, title: 'Payment received', time: now - 2 * 3600e3, read: true, color: 'success' },
18
+ { id: 3, title: 'Weekly report', time: now - 26 * 3600e3 },
19
+ { id: 4, title: 'Server restarted', time: now - 5 * 24 * 3600e3, read: true },
20
+ ]
21
+
22
+ function mountCenter(props: Record<string, unknown> = {}) {
23
+ const list = ref(items())
24
+ const opened: InboxNotification[] = []
25
+ const dismissed: InboxNotification[] = []
26
+ const Host = defineComponent({
27
+ setup: () => () => h(MNotificationCenter, {
28
+ modelValue: list.value, 'onUpdate:modelValue': (v: InboxNotification[]) => (list.value = v),
29
+ onOpen: (n: InboxNotification) => opened.push(n), onDismiss: (n: InboxNotification) => dismissed.push(n), ...props,
30
+ }),
31
+ })
32
+ wrapper = mount(Host, { attachTo: document.body })
33
+ return { list, opened, dismissed }
34
+ }
35
+
36
+ const rows = () => wrapper!.findAll('li')
37
+ const row = (title: string) => rows().find((r) => r.text().includes(title))!
38
+
39
+ describe('MNotificationCenter', () => {
40
+ it('groups by day, newest first, with relative times and the unread count', () => {
41
+ mountCenter()
42
+ expect(wrapper!.findAll('h3').map((h) => h.text()).slice(0, 2)).toEqual(['Today', 'Yesterday'])
43
+ expect(rows().map((r) => r.find('.text-body-large').text())).toEqual(['New order', 'Payment received', 'Weekly report', 'Server restarted'])
44
+ expect(row('New order').text()).toContain('5 min. ago')
45
+ expect(wrapper!.text()).toContain('Mark all as read')
46
+ expect(wrapper!.find('h2').text()).toBe('Notifications')
47
+ })
48
+
49
+ it('opens one on click, marking it read', async () => {
50
+ const { list, opened } = mountCenter()
51
+ await row('New order').trigger('click')
52
+ expect(list.value.find((n) => n.id === 1)!.read).toBe(true)
53
+ expect(opened[0]!.id).toBe(1)
54
+ })
55
+
56
+ it('marks all read, and filters to unread', async () => {
57
+ const { list } = mountCenter()
58
+ const chips = wrapper!.findAllComponents(MChip)
59
+ await chips[1]!.find('button').trigger('click')
60
+ expect(rows().map((r) => r.find('.text-body-large').text())).toEqual(['New order', 'Weekly report'])
61
+ await wrapper!.findAll('button').find((b) => b.text() === 'Mark all as read')!.trigger('click')
62
+ expect(list.value.every((n) => n.read)).toBe(true)
63
+ await nextTick()
64
+ expect(wrapper!.text()).toContain("You're all caught up")
65
+ })
66
+
67
+ it('dismisses from its button and with Delete', async () => {
68
+ const { list, dismissed } = mountCenter()
69
+ await row('Weekly report').find('button[aria-label="Dismiss"]').trigger('click')
70
+ expect(list.value.map((n) => n.id)).toEqual([1, 2, 4])
71
+ expect(dismissed[0]!.id).toBe(3)
72
+ await row('Payment received').trigger('keydown', { key: 'Delete' })
73
+ expect(list.value.map((n) => n.id)).toEqual([1, 4])
74
+ })
75
+
76
+ it('dismisses with a swipe, and not with a short one', async () => {
77
+ const { list } = mountCenter()
78
+ const el = row('New order').element as HTMLElement
79
+ Object.defineProperty(el, 'offsetWidth', { value: 300 })
80
+ el.dispatchEvent(new PointerEvent('pointerdown', { clientX: 100, clientY: 10, button: 0, bubbles: true }))
81
+ window.dispatchEvent(new PointerEvent('pointermove', { clientX: 140, clientY: 10 }))
82
+ window.dispatchEvent(new PointerEvent('pointerup', {}))
83
+ expect(list.value).toHaveLength(4)
84
+ el.dispatchEvent(new PointerEvent('pointerdown', { clientX: 100, clientY: 10, button: 0, bubbles: true }))
85
+ window.dispatchEvent(new PointerEvent('pointermove', { clientX: 130, clientY: 10 }))
86
+ window.dispatchEvent(new PointerEvent('pointermove', { clientX: 260, clientY: 10 }))
87
+ window.dispatchEvent(new PointerEvent('pointerup', {}))
88
+ // happy-dom's timeline doesn't run by itself
89
+ el.getAnimations().forEach((a) => a.finish())
90
+ await new Promise((r) => setTimeout(r, 0))
91
+ await nextTick()
92
+ expect(list.value.map((n) => n.id)).toEqual([2, 3, 4])
93
+ })
94
+ })
@@ -28,7 +28,7 @@ export class FakeMap extends Evented {
28
28
  bearing = 0
29
29
  pitch = 0
30
30
  controls: { control: { onAdd?: (m: unknown) => HTMLElement }; position: string }[] = []
31
- sources = new Map<string, { data: unknown; setData: (d: unknown) => void }>()
31
+ sources = new Map<string, { spec: unknown; data: unknown; setData: (d: unknown) => void; expansionZoom: number; leaves: unknown[]; getClusterExpansionZoom: (id: number) => Promise<number>; getClusterLeaves: (id: number, limit: number) => Promise<unknown[]> }>()
32
32
  layers: { id: string; [k: string]: unknown }[] = []
33
33
  canvas = document.createElement('canvas')
34
34
  styles: unknown[] = []
@@ -64,7 +64,16 @@ export class FakeMap extends Evented {
64
64
  this.layers = []
65
65
  }
66
66
  addSource(id: string, spec: { data: unknown }) {
67
- const source = { data: spec.data, setData: (d: unknown) => { source.data = d } }
67
+ const source = {
68
+ spec,
69
+ data: spec.data,
70
+ setData: (d: unknown) => { source.data = d },
71
+ // Clustered sources: a fixed expansion zoom and leaves, set by tests
72
+ expansionZoom: 9,
73
+ leaves: [] as unknown[],
74
+ getClusterExpansionZoom: async () => source.expansionZoom,
75
+ getClusterLeaves: async (_id: number, limit: number) => source.leaves.slice(0, limit),
76
+ }
68
77
  this.sources.set(id, source)
69
78
  }
70
79
  getSource(id: string) {
@@ -98,10 +107,12 @@ export class FakeMap extends Evented {
98
107
  getFilter(id: string) { return this.filters.get(id) ?? (this.styleLayer(id) as { filter?: unknown } | undefined)?.filter }
99
108
  setFilter(id: string, filter: unknown) { this.filters.set(id, filter) }
100
109
  /** A source's loaded features, set by tests */
101
- sourceFeatures: { properties: Record<string, unknown> }[] = []
110
+ sourceFeatures: { properties: Record<string, unknown>; geometry?: unknown }[] = []
102
111
  querySourceFeatures() { return this.sourceFeatures }
103
112
  flights: unknown[] = []
104
113
  flyTo(o: unknown) { this.flights.push(['flyTo', o]) }
114
+ easeTo(o: unknown) { this.flights.push(['easeTo', o]) }
115
+ getMaxZoom() { return 22 }
105
116
  fitBounds(b: unknown, o?: unknown) { this.flights.push(['fitBounds', b, o]) }
106
117
  /** Features "under the pointer", set by tests */
107
118
  rendered: { layer: { id: string }; properties: Record<string, unknown> }[] = []
@@ -18,12 +18,16 @@ import MTransferList from '../components/MTransferList.vue'
18
18
  import MContainerTransform from '../components/MContainerTransform.vue'
19
19
  import MDialog from '../components/MDialog.vue'
20
20
  import MOverlay from '../components/MOverlay.vue'
21
+ import MAddressField from '../components/MAddressField.vue'
22
+ import MMentionField from '../components/MMentionField.vue'
21
23
 
22
24
  // These components render more than one root node (an element plus a Teleport, a v-if/v-show
23
25
  // pair, a comment before the root...), which makes Vue drop a consumer's class/attrs silently.
24
26
  // Each case names the element that should receive them.
25
27
  const cases: [name: string, component: Component, props: Record<string, unknown>, tag: string][] = [
26
28
  ['MMenu', MMenu, {}, 'DIV'],
29
+ ['MAddressField', MAddressField, {}, 'DIV'],
30
+ ['MMentionField', MMentionField, { modelValue: '', label: 'L', sources: [] }, 'DIV'],
27
31
  ['MContextMenu', MContextMenu, {}, 'DIV'],
28
32
  ['MTooltip', MTooltip, { text: 'Tip' }, 'SPAN'],
29
33
  ['MFab', MFab, { icon: 'add' }, 'DIV'],
@@ -0,0 +1,68 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { describeCron, isValidCron, nextCronRuns, parseCron } from '../composables/cron'
3
+ import { defaultLocale } from '../composables/useLocale'
4
+ import { esLocale } from '../locales'
5
+
6
+ const en = { ...defaultLocale, lang: 'en-US' }
7
+ const es = { ...defaultLocale, ...esLocale, lang: 'es' }
8
+
9
+ describe('parseCron', () => {
10
+ it('reads numbers, ranges, steps, lists, names and macros', () => {
11
+ const s = parseCron('*/15 9-17 1,15 JAN-MAR mon-fri')!
12
+ expect(s.minutes).toEqual([0, 15, 30, 45])
13
+ expect(s.hours).toEqual([9, 10, 11, 12, 13, 14, 15, 16, 17])
14
+ expect(s.days).toEqual([1, 15])
15
+ expect(s.months).toEqual([1, 2, 3])
16
+ expect(s.weekdays).toEqual([1, 2, 3, 4, 5])
17
+ expect(parseCron('5/20 * * * *')!.minutes).toEqual([5, 25, 45])
18
+ expect(parseCron('0 0 * * 7')!.weekdays).toEqual([0])
19
+ expect(parseCron('@daily')!.fields).toEqual(['0', '0', '*', '*', '*'])
20
+ expect(parseCron('@weekly')!.weekdays).toEqual([0])
21
+ })
22
+
23
+ it('rejects what crontab would', () => {
24
+ for (const bad of ['', '* * * *', '60 * * * *', '* 24 * * *', '* * 0 * *', '* * * 13 *', '*/0 * * * *', '5-1 * * * *', 'x * * * *', '* * * * 8']) {
25
+ expect(isValidCron(bad), bad).toBe(false)
26
+ }
27
+ })
28
+ })
29
+
30
+ describe('nextCronRuns', () => {
31
+ const from = new Date(2026, 10, 26, 10, 30) // Thursday 26 Nov 2026, 10:30
32
+ it('finds the next times, in local time', () => {
33
+ expect(nextCronRuns('0 9 * * 1-5', 3, from)).toEqual([new Date(2026, 10, 27, 9, 0), new Date(2026, 10, 30, 9, 0), new Date(2026, 11, 1, 9, 0)])
34
+ expect(nextCronRuns('*/20 * * * *', 2, from)).toEqual([new Date(2026, 10, 26, 10, 40), new Date(2026, 10, 26, 11, 0)])
35
+ expect(nextCronRuns('0 0 29 2 *', 1, from)).toEqual([new Date(2028, 1, 29, 0, 0)])
36
+ })
37
+
38
+ it('runs on either day field when both are set (crontab\'s rule)', () => {
39
+ // The 1st, or any Friday
40
+ expect(nextCronRuns('0 12 1 * 5', 3, from)).toEqual([new Date(2026, 10, 27, 12, 0), new Date(2026, 11, 1, 12, 0), new Date(2026, 11, 4, 12, 0)])
41
+ })
42
+
43
+ it('gives nothing for an invalid or impossible expression', () => {
44
+ expect(nextCronRuns('nope')).toEqual([])
45
+ expect(nextCronRuns('0 0 31 2 *', 1, from)).toEqual([])
46
+ })
47
+ })
48
+
49
+ describe('describeCron', () => {
50
+ it('says it in English', () => {
51
+ expect(describeCron('* * * * *', en)).toBe('Every minute')
52
+ expect(describeCron('*/5 * * * *', en)).toBe('Every 5 minutes')
53
+ expect(describeCron('30 * * * *', en)).toBe('At minute 30 of every hour')
54
+ expect(describeCron('0 */2 * * *', en)).toBe('Every 2 hours, at minute 0')
55
+ expect(describeCron('0 9 * * 1-5', en)).toBe('At 9:00 AM, Monday to Friday')
56
+ expect(describeCron('30 8,18 * * 0,6', en)).toBe('At 8:30 AM and 6:30 PM, Sunday and Saturday')
57
+ expect(describeCron('0 0 1 1 *', en)).toBe('At 12:00 AM, on day 1 of the month, in January')
58
+ expect(describeCron('0 12 1 * 5', en)).toBe('At 12:00 PM, on day 1 of the month or Friday')
59
+ expect(describeCron('0,30 9-17 * * *', en)).toBe('At minutes 0 and 30 of hours 9 to 17')
60
+ expect(describeCron('bad', en)).toBeNull()
61
+ })
62
+
63
+ it('says it in the app\'s language', () => {
64
+ expect(describeCron('0 9 * * 1-5', es)).toBe('A las 9:00, lunes a viernes')
65
+ expect(describeCron('*/10 * * * *', es)).toBe('Cada 10 minutos')
66
+ expect(describeCron('0 8 15 * *', es)).toBe('A las 8:00, el día 15 del mes')
67
+ })
68
+ })