@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,94 @@
1
+ /*
2
+ * The layout behind MDashboardGrid, as pure functions: items on a grid of `columns`, in whole cells. Moving or
3
+ * resizing one pushes whatever it lands on downward, then everything floats up to fill gaps (vertical compaction).
4
+ * Static items never move and others flow around them. Usable on their own (server-side layouts, tests).
5
+ */
6
+
7
+ /** A widget's place on the grid, in cells. */
8
+ export interface DashboardItem {
9
+ id: string | number
10
+ /** Column, from 0 */
11
+ x: number
12
+ /** Row, from 0 */
13
+ y: number
14
+ /** Width in columns */
15
+ w: number
16
+ /** Height in rows */
17
+ h: number
18
+ minW?: number
19
+ minH?: number
20
+ maxW?: number
21
+ maxH?: number
22
+ /** Never moves or resizes, and others flow around it */
23
+ static?: boolean
24
+ }
25
+
26
+ const overlaps = (a: DashboardItem, b: DashboardItem) =>
27
+ a.id !== b.id && a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h
28
+
29
+ const clone = (layout: DashboardItem[]) => layout.map((i) => ({ ...i }))
30
+
31
+ /** Keeps an item inside the columns and its size limits. */
32
+ export function clampItem(item: DashboardItem, columns: number): DashboardItem {
33
+ const w = Math.max(item.minW ?? 1, Math.min(item.maxW ?? columns, columns, Math.round(item.w)))
34
+ const h = Math.max(item.minH ?? 1, Math.min(item.maxH ?? Infinity, Math.round(item.h)))
35
+ return { ...item, w, h, x: Math.max(0, Math.min(columns - w, Math.round(item.x))), y: Math.max(0, Math.round(item.y)) }
36
+ }
37
+
38
+ /** Floats every movable item up as far as it goes, top to bottom (static ones stay). */
39
+ export function compactLayout(layout: DashboardItem[]): DashboardItem[] {
40
+ const out = clone(layout)
41
+ const placed: DashboardItem[] = out.filter((i) => i.static)
42
+ const order = out.filter((i) => !i.static).sort((a, b) => a.y - b.y || a.x - b.x)
43
+ for (const item of order) {
44
+ item.y = 0
45
+ // Down until it fits
46
+ while (placed.some((p) => overlaps(item, p))) item.y++
47
+ placed.push(item)
48
+ }
49
+ return out
50
+ }
51
+
52
+ /** Pushes items overlapping `moved` down below it, recursively (the moved one keeps its place). */
53
+ function pushDown(layout: DashboardItem[], moved: DashboardItem) {
54
+ for (const other of layout) {
55
+ if (other.id === moved.id || !overlaps(moved, other)) continue
56
+ if (other.static) {
57
+ // A static item can't move: the moved one goes below it instead
58
+ moved.y = other.y + other.h
59
+ pushDown(layout, moved)
60
+ return
61
+ }
62
+ other.y = moved.y + moved.h
63
+ pushDown(layout, other)
64
+ }
65
+ }
66
+
67
+ /** The layout with one item moved and/or resized, the rest pushed out of the way and compacted. */
68
+ export function moveItem(layout: DashboardItem[], id: DashboardItem['id'], next: Partial<Pick<DashboardItem, 'x' | 'y' | 'w' | 'h'>>, columns: number): DashboardItem[] {
69
+ const out = clone(layout)
70
+ const item = out.find((i) => i.id === id)
71
+ if (!item || item.static) return compactLayout(out)
72
+ Object.assign(item, clampItem({ ...item, ...next }, columns))
73
+ // Others in its way go below it, in reading order so the result is stable
74
+ out.sort((a, b) => a.y - b.y || a.x - b.x)
75
+ pushDown(out, item)
76
+ // Compact, but keep the moved item where it was dropped if nothing is above it to fill
77
+ const compacted = compactLayout(out)
78
+ return layout.map((orig) => compacted.find((i) => i.id === orig.id)!)
79
+ }
80
+
81
+ /** A layout made valid: clamped to the columns, no overlaps, compacted. */
82
+ export function normalizeLayout(layout: DashboardItem[], columns: number): DashboardItem[] {
83
+ let out = layout.map((i) => clampItem(i, columns))
84
+ for (const item of [...out].sort((a, b) => a.y - b.y || a.x - b.x)) {
85
+ out = out.map((i) => (i.id === item.id ? item : i))
86
+ const current = out.find((i) => i.id === item.id)!
87
+ const fixed = out.filter((i) => i.id !== item.id)
88
+ while (fixed.some((o) => overlaps(current, o) && (o.y < current.y || (o.y === current.y && o.x < current.x) || o.static))) current.y++
89
+ }
90
+ return layout.map((orig) => compactLayout(out).find((i) => i.id === orig.id)!)
91
+ }
92
+
93
+ /** How many rows the layout takes. */
94
+ export const layoutRows = (layout: DashboardItem[]) => layout.reduce((n, i) => Math.max(n, i.y + i.h), 0)
@@ -0,0 +1,195 @@
1
+ /*
2
+ * The model and the evaluation behind MFilterBuilder, usable on their own: a filter is a JSON tree of groups (all /
3
+ * any of their rules) and rules (field · operator · value). `filterRows(rows, filter, fields)` applies it to an array
4
+ * (a table's rows), `matchesFilter(row, filter, fields)` to one row. Rules that aren't complete yet (no value) match
5
+ * everything, so a half-built filter never empties the table.
6
+ */
7
+
8
+ /** How a field's values are compared, and which input `MFilterBuilder` shows for them. */
9
+ export type FilterFieldType = 'text' | 'number' | 'date' | 'select' | 'boolean'
10
+
11
+ export type FilterOperator =
12
+ | 'contains' | 'notContains' | 'equals' | 'notEquals' | 'startsWith' | 'endsWith'
13
+ | 'gt' | 'gte' | 'lt' | 'lte' | 'between'
14
+ | 'in' | 'notIn'
15
+ | 'isTrue' | 'isFalse'
16
+ | 'isEmpty' | 'isNotEmpty'
17
+
18
+ /** A field that can be filtered on. */
19
+ export interface FilterField {
20
+ /** The row property (a dotted path reaches into nested objects: `address.city`) */
21
+ key: string
22
+ /** Its name in the UI */
23
+ label: string
24
+ /** Text by default */
25
+ type?: FilterFieldType
26
+ /** For `select`: the values to choose from */
27
+ options?: { label: string; value: unknown }[]
28
+ /** The operators offered, instead of the type's own */
29
+ operators?: FilterOperator[]
30
+ /** Reads the value from a row, instead of `key` */
31
+ accessor?: (row: Record<string, unknown>) => unknown
32
+ }
33
+
34
+ /** One condition: field · operator · value (`[min, max]` for `between`, a list for `in` / `notIn`). */
35
+ export interface FilterRule {
36
+ id: string
37
+ field: string
38
+ operator: FilterOperator
39
+ value?: unknown
40
+ }
41
+
42
+ /** All (`and`) or any (`or`) of its rules and nested groups. */
43
+ export interface FilterGroup {
44
+ id: string
45
+ combinator: 'and' | 'or'
46
+ rules: (FilterRule | FilterGroup)[]
47
+ }
48
+
49
+ /** The operators each type offers, in order (the first is the default for a new rule). */
50
+ export const FILTER_OPERATORS: Record<FilterFieldType, FilterOperator[]> = {
51
+ text: ['contains', 'notContains', 'equals', 'notEquals', 'startsWith', 'endsWith', 'isEmpty', 'isNotEmpty'],
52
+ number: ['equals', 'notEquals', 'gt', 'gte', 'lt', 'lte', 'between', 'isEmpty', 'isNotEmpty'],
53
+ date: ['equals', 'gt', 'lt', 'between', 'isEmpty', 'isNotEmpty'],
54
+ select: ['in', 'notIn', 'isEmpty', 'isNotEmpty'],
55
+ boolean: ['isTrue', 'isFalse'],
56
+ }
57
+
58
+ /** Operators that take no value. */
59
+ export const VALUELESS: FilterOperator[] = ['isTrue', 'isFalse', 'isEmpty', 'isNotEmpty']
60
+
61
+ export const isGroup = (r: FilterRule | FilterGroup): r is FilterGroup => 'rules' in r
62
+
63
+ let seq = 0
64
+ const newId = () => `f${Date.now().toString(36)}${(seq++).toString(36)}`
65
+
66
+ /** An empty filter (a group matching every row), or one with these rules. */
67
+ export function createFilter(rules: Omit<FilterRule, 'id'>[] = [], combinator: 'and' | 'or' = 'and'): FilterGroup {
68
+ return { id: newId(), combinator, rules: rules.map((r) => ({ ...r, id: newId() })) }
69
+ }
70
+
71
+ /** A new rule on a field, with its type's first operator. */
72
+ export function createRule(field: FilterField): FilterRule {
73
+ return { id: newId(), field: field.key, operator: operatorsFor(field)[0]! }
74
+ }
75
+
76
+ /** A new nested group. */
77
+ export function createGroup(combinator: 'and' | 'or' = 'and'): FilterGroup {
78
+ return { id: newId(), combinator, rules: [] }
79
+ }
80
+
81
+ /** The operators a field offers. */
82
+ export function operatorsFor(field: FilterField): FilterOperator[] {
83
+ return field.operators ?? FILTER_OPERATORS[field.type ?? 'text']
84
+ }
85
+
86
+ const empty = (v: unknown) => v === undefined || v === null || v === '' || (Array.isArray(v) && v.length === 0)
87
+
88
+ /** Whether a rule has what it needs to filter (an operator that takes no value, or a value). */
89
+ export function isComplete(rule: FilterRule): boolean {
90
+ if (VALUELESS.includes(rule.operator)) return true
91
+ if (rule.operator === 'between') {
92
+ const [a, b] = Array.isArray(rule.value) ? rule.value : []
93
+ return !empty(a) || !empty(b)
94
+ }
95
+ return !empty(rule.value)
96
+ }
97
+
98
+ function read(row: Record<string, unknown>, field: FilterField | undefined, key: string): unknown {
99
+ if (field?.accessor) return field.accessor(row)
100
+ if (key in row) return row[key]
101
+ return key.split('.').reduce<unknown>((v, k) => (v && typeof v === 'object' ? (v as Record<string, unknown>)[k] : undefined), row)
102
+ }
103
+
104
+ /** A date (a Date, an ISO string, a timestamp) as `YYYY-MM-DD`, or null. */
105
+ function day(v: unknown): string | null {
106
+ if (empty(v)) return null
107
+ if (typeof v === 'string' && /^\d{4}-\d{2}-\d{2}/.test(v)) return v.slice(0, 10)
108
+ const d = v instanceof Date ? v : new Date(v as string | number)
109
+ if (Number.isNaN(d.getTime())) return null
110
+ const p = (n: number) => String(n).padStart(2, '0')
111
+ return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}`
112
+ }
113
+
114
+ const same = (a: unknown, b: unknown) => a === b || (typeof a === 'object' && a !== null && JSON.stringify(a) === JSON.stringify(b))
115
+
116
+ function test(rule: FilterRule, raw: unknown, type: FilterFieldType): boolean {
117
+ const op = rule.operator
118
+ if (op === 'isEmpty') return empty(raw)
119
+ if (op === 'isNotEmpty') return !empty(raw)
120
+ if (op === 'isTrue') return !!raw
121
+ if (op === 'isFalse') return !raw
122
+
123
+ if (type === 'select' || op === 'in' || op === 'notIn') {
124
+ const wanted = Array.isArray(rule.value) ? rule.value : [rule.value]
125
+ const values = Array.isArray(raw) ? raw : [raw]
126
+ const hit = values.some((v) => wanted.some((w) => same(v, w)))
127
+ if (op === 'notIn') return !hit
128
+ if (op === 'in') return hit
129
+ }
130
+
131
+ if (type === 'number' || type === 'date') {
132
+ const val = type === 'date' ? day(raw) : empty(raw) ? null : Number(raw)
133
+ const conv = (x: unknown) => (type === 'date' ? day(x) : empty(x) ? null : Number(x))
134
+ if (val === null || (typeof val === 'number' && Number.isNaN(val))) return op === 'notEquals'
135
+ if (op === 'between') {
136
+ const [a, b] = (Array.isArray(rule.value) ? rule.value : []).map(conv)
137
+ return (a === null || a === undefined || val >= a) && (b === null || b === undefined || val <= b)
138
+ }
139
+ const ref = conv(rule.value)
140
+ if (ref === null) return true
141
+ switch (op) {
142
+ case 'equals': return val === ref
143
+ case 'notEquals': return val !== ref
144
+ case 'gt': return val > ref
145
+ case 'gte': return val >= ref
146
+ case 'lt': return val < ref
147
+ case 'lte': return val <= ref
148
+ }
149
+ }
150
+
151
+ const s = empty(raw) ? '' : String(raw).toLocaleLowerCase()
152
+ const q = String(rule.value).toLocaleLowerCase()
153
+ switch (op) {
154
+ case 'contains': return s.includes(q)
155
+ case 'notContains': return !s.includes(q)
156
+ case 'equals': return s === q
157
+ case 'notEquals': return s !== q
158
+ case 'startsWith': return s.startsWith(q)
159
+ case 'endsWith': return s.endsWith(q)
160
+ }
161
+ return true
162
+ }
163
+
164
+ /** Whether a row passes the filter. Incomplete rules, and groups with none complete, match everything. */
165
+ export function matchesFilter(row: Record<string, unknown>, filter: FilterGroup | null | undefined, fields: FilterField[] = []): boolean {
166
+ if (!filter) return true
167
+ const byKey = new Map(fields.map((f) => [f.key, f]))
168
+ const check = (group: FilterGroup): boolean | null => {
169
+ const results: boolean[] = []
170
+ for (const r of group.rules) {
171
+ if (isGroup(r)) {
172
+ const sub = check(r)
173
+ if (sub !== null) results.push(sub)
174
+ } else if (isComplete(r)) {
175
+ const field = byKey.get(r.field)
176
+ results.push(test(r, read(row, field, r.field), field?.type ?? 'text'))
177
+ }
178
+ }
179
+ if (!results.length) return null
180
+ return group.combinator === 'or' ? results.some(Boolean) : results.every(Boolean)
181
+ }
182
+ return check(filter) ?? true
183
+ }
184
+
185
+ /** The rows that pass the filter. */
186
+ export function filterRows<T extends Record<string, unknown>>(rows: T[], filter: FilterGroup | null | undefined, fields: FilterField[] = []): T[] {
187
+ if (!filter || !filter.rules.length) return rows
188
+ return rows.filter((row) => matchesFilter(row, filter, fields))
189
+ }
190
+
191
+ /** How many complete rules the filter has (for a "Filters (3)" button). */
192
+ export function countRules(filter: FilterGroup | null | undefined): number {
193
+ if (!filter) return 0
194
+ return filter.rules.reduce((n, r) => n + (isGroup(r) ? countRules(r) : isComplete(r) ? 1 : 0), 0)
195
+ }
@@ -64,22 +64,36 @@ const VECTOR = new Set(['fill', 'line', 'circle', 'symbol', 'fill-extrusion', 'h
64
64
 
65
65
  /**
66
66
  * Any style: every layer but the background is listed under its id (or `metadata.title`), vector layers identify all
67
- * their properties, and nothing is a base layer or shows on hover.
67
+ * their properties, and nothing shows on hover. A few neutral keys in a layer's `metadata` refine it:
68
+ * - `base: true` (or `base: { image }`) makes it a base layer for `MMapBaseLayers`, with `image` (here or in
69
+ * `metadata.image`) as its thumbnail; base layers aren't listed in `MMapLayers`
70
+ * - `children`: layer ids shown, hidden and faded along with it (a vector base map's many layers under one entry);
71
+ * the children of a base layer aren't listed either
72
+ * - `listed: false` leaves it out of `MMapLayers`
68
73
  */
69
- export const genericAdapter: MapAdapter = (style) => ({
70
- title: style.name,
71
- groups: [],
72
- layers: style.layers
73
- .filter((l) => l.type !== 'background')
74
- .map((l) => ({
75
- id: l.id,
76
- title: (meta(l)?.title as string | undefined) ?? l.id,
77
- listed: true,
78
- children: [],
79
- identify: VECTOR.has(l.type) ? { format: {}, exclude: [] } : false,
80
- hover: false,
81
- })),
82
- })
74
+ export const genericAdapter: MapAdapter = (style) => {
75
+ const layers = style.layers.filter((l) => l.type !== 'background')
76
+ const baseOf = (m: Metadata) => (m?.base === true || (typeof m?.base === 'object' && m.base !== null) ? m : undefined)
77
+ const childrenOf = (m: Metadata) => (Array.isArray(m?.children) ? (m!.children as string[]) : [])
78
+ const underBase = new Set(layers.flatMap((l) => (baseOf(meta(l)) ? childrenOf(meta(l)) : [])))
79
+ return {
80
+ title: style.name,
81
+ groups: [],
82
+ layers: layers.map((l) => {
83
+ const m = meta(l)
84
+ const base = baseOf(m)
85
+ return {
86
+ id: l.id,
87
+ title: (m?.title as string | undefined) ?? l.id,
88
+ listed: !base && !underBase.has(l.id) && m?.listed !== false,
89
+ base: base ? { image: ((m!.base as { image?: string }).image ?? m!.image) as string | undefined } : undefined,
90
+ children: childrenOf(m),
91
+ identify: VECTOR.has(l.type) && !base && !underBase.has(l.id) ? { format: {}, exclude: [] } : false,
92
+ hover: false,
93
+ }
94
+ }),
95
+ }
96
+ }
83
97
 
84
98
  export interface OrvianAdapterOptions {
85
99
  /**
@@ -54,3 +54,13 @@ export function nominatimProvider(options: NominatimOptions = {}): MapSearchProv
54
54
  })
55
55
  }
56
56
  }
57
+
58
+ // Internal (not exported from the entry): the icon for a result's `type`, shared by MMapSearch and MAddressField
59
+ const ICONS: Record<string, string> = {
60
+ city: 'location_city', town: 'location_city', village: 'holiday_village', hamlet: 'cottage', suburb: 'apartment',
61
+ neighbourhood: 'maps_home_work', road: 'road', residential: 'home', house: 'home', building: 'domain',
62
+ shop: 'storefront', park: 'park', water: 'water', river: 'water', lake: 'water', school: 'school',
63
+ university: 'school', hospital: 'local_hospital', restaurant: 'restaurant', cafe: 'local_cafe', hotel: 'hotel',
64
+ station: 'train', bus_stop: 'directions_bus', administrative: 'map', country: 'public', state: 'map',
65
+ }
66
+ export const placeIcon = (type?: string) => (type && ICONS[type]) || 'location_on'
@@ -0,0 +1,106 @@
1
+ /*
2
+ * Line and word diffs (Myers' O(ND) algorithm) behind MDiffViewer, usable on their own. `diffLines(a, b)` gives
3
+ * every line as equal, removed or added with its line numbers; `diffWords(a, b)` splits two versions of one line
4
+ * into the parts that stayed and changed, for highlighting inside a changed line.
5
+ */
6
+
7
+ export type DiffOp = 'equal' | 'remove' | 'add'
8
+
9
+ /** One line of a diff. */
10
+ export interface DiffLine {
11
+ op: DiffOp
12
+ text: string
13
+ /** Its number in the original (equal and removed lines) */
14
+ oldLine?: number
15
+ /** Its number in the modified version (equal and added lines) */
16
+ newLine?: number
17
+ }
18
+
19
+ /** A run of a word diff. */
20
+ export interface DiffPart {
21
+ op: DiffOp
22
+ text: string
23
+ }
24
+
25
+ /** The edit script between two sequences: Myers' greedy diff, with the shortest middle snake left out (simple, O(ND)). */
26
+ function myers<T>(a: T[], b: T[]): DiffOp[] {
27
+ const n = a.length
28
+ const m = b.length
29
+ const max = n + m
30
+ const v = new Map<number, number>([[1, 0]])
31
+ const trace: Map<number, number>[] = []
32
+ outer: for (let d = 0; d <= max; d++) {
33
+ trace.push(new Map(v))
34
+ for (let k = -d; k <= d; k += 2) {
35
+ let x = k === -d || (k !== d && (v.get(k - 1) ?? -1) < (v.get(k + 1) ?? -1)) ? v.get(k + 1) ?? 0 : (v.get(k - 1) ?? 0) + 1
36
+ let y = x - k
37
+ while (x < n && y < m && a[x] === b[y]) { x++; y++ }
38
+ v.set(k, x)
39
+ if (x >= n && y >= m) break outer
40
+ }
41
+ }
42
+ // Walk back through the trace
43
+ const ops: DiffOp[] = []
44
+ let x = n
45
+ let y = m
46
+ for (let d = trace.length - 1; d >= 0 && (x > 0 || y > 0); d--) {
47
+ const vd = trace[d]!
48
+ const k = x - y
49
+ const down = k === -d || (k !== d && (vd.get(k - 1) ?? -1) < (vd.get(k + 1) ?? -1))
50
+ const prevK = down ? k + 1 : k - 1
51
+ const prevX = vd.get(prevK) ?? 0
52
+ const prevY = prevX - prevK
53
+ while (x > prevX && y > prevY) { ops.push('equal'); x--; y-- }
54
+ if (d > 0) {
55
+ if (down) { ops.push('add'); y-- } else { ops.push('remove'); x-- }
56
+ }
57
+ }
58
+ while (x > 0 && y > 0) { ops.push('equal'); x--; y-- }
59
+ return ops.reverse()
60
+ }
61
+
62
+ const lines = (s: string) => (s === '' ? [] : s.replace(/\r\n?/g, '\n').split('\n'))
63
+
64
+ /** Every line of `a` → `b` as equal, removed or added, with its line numbers. Removals come before additions. */
65
+ export function diffLines(a: string, b: string): DiffLine[] {
66
+ const A = lines(a)
67
+ const B = lines(b)
68
+ const out: DiffLine[] = []
69
+ let i = 0
70
+ let j = 0
71
+ let removes: DiffLine[] = []
72
+ let adds: DiffLine[] = []
73
+ const flush = () => { out.push(...removes, ...adds); removes = []; adds = [] }
74
+ for (const op of myers(A, B)) {
75
+ if (op === 'equal') {
76
+ flush()
77
+ out.push({ op, text: A[i]!, oldLine: ++i, newLine: ++j })
78
+ } else if (op === 'remove') removes.push({ op, text: A[i]!, oldLine: ++i })
79
+ else adds.push({ op, text: B[j]!, newLine: ++j })
80
+ }
81
+ flush()
82
+ return out
83
+ }
84
+
85
+ /** Two versions of a line split into words, spaces and punctuation, marked as kept, removed or added. */
86
+ export function diffWords(a: string, b: string): DiffPart[] {
87
+ const split = (s: string) => s.match(/\w+|\s+|[^\w\s]/gu) ?? []
88
+ const A = split(a)
89
+ const B = split(b)
90
+ const out: DiffPart[] = []
91
+ let i = 0
92
+ let j = 0
93
+ for (const op of myers(A, B)) {
94
+ const text = op === 'add' ? B[j++]! : A[i++]!
95
+ if (op === 'equal') j++
96
+ const lastPart = out[out.length - 1]
97
+ if (lastPart && lastPart.op === op) lastPart.text += text
98
+ else out.push({ op, text })
99
+ }
100
+ return out
101
+ }
102
+
103
+ /** How many lines were added and removed. */
104
+ export function diffStats(diff: DiffLine[]) {
105
+ return { added: diff.filter((l) => l.op === 'add').length, removed: diff.filter((l) => l.op === 'remove').length }
106
+ }