@getcortexlabs/mavis-core 0.1.0-alpha.3 → 0.1.0-alpha.5

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 (242) hide show
  1. package/README.md +2 -2
  2. package/dist/accordion.d.ts +17 -0
  3. package/dist/accordion.d.ts.map +1 -0
  4. package/dist/accordion.js +42 -0
  5. package/dist/accordion.js.map +1 -0
  6. package/dist/alert.d.ts +21 -0
  7. package/dist/alert.d.ts.map +1 -0
  8. package/dist/alert.js +13 -0
  9. package/dist/alert.js.map +1 -0
  10. package/dist/avatar.d.ts +10 -0
  11. package/dist/avatar.d.ts.map +1 -0
  12. package/dist/avatar.js +11 -0
  13. package/dist/avatar.js.map +1 -0
  14. package/dist/badge.d.ts +7 -0
  15. package/dist/badge.d.ts.map +1 -0
  16. package/dist/badge.js +11 -0
  17. package/dist/badge.js.map +1 -0
  18. package/dist/capabilities.d.ts +119 -0
  19. package/dist/capabilities.d.ts.map +1 -0
  20. package/dist/capabilities.js +142 -0
  21. package/dist/capabilities.js.map +1 -0
  22. package/dist/chip.d.ts +9 -0
  23. package/dist/chip.d.ts.map +1 -0
  24. package/dist/chip.js +16 -0
  25. package/dist/chip.js.map +1 -0
  26. package/dist/choice.d.ts +15 -0
  27. package/dist/choice.d.ts.map +1 -0
  28. package/dist/choice.js +27 -0
  29. package/dist/choice.js.map +1 -0
  30. package/dist/combobox.d.ts +42 -0
  31. package/dist/combobox.d.ts.map +1 -0
  32. package/dist/combobox.js +159 -0
  33. package/dist/combobox.js.map +1 -0
  34. package/dist/contracts.d.ts +1201 -0
  35. package/dist/contracts.d.ts.map +1 -0
  36. package/dist/contracts.js +242 -0
  37. package/dist/contracts.js.map +1 -0
  38. package/dist/date.d.ts +96 -0
  39. package/dist/date.d.ts.map +1 -0
  40. package/dist/date.js +235 -0
  41. package/dist/date.js.map +1 -0
  42. package/dist/dialog.d.ts +4 -0
  43. package/dist/dialog.d.ts.map +1 -0
  44. package/dist/dialog.js +20 -0
  45. package/dist/dialog.js.map +1 -0
  46. package/dist/empty-state.d.ts +2 -0
  47. package/dist/empty-state.d.ts.map +1 -0
  48. package/dist/empty-state.js +5 -0
  49. package/dist/empty-state.js.map +1 -0
  50. package/dist/experimental-regions.d.ts +142 -0
  51. package/dist/experimental-regions.d.ts.map +1 -0
  52. package/dist/experimental-regions.js +315 -0
  53. package/dist/experimental-regions.js.map +1 -0
  54. package/dist/experimental.d.ts +134 -0
  55. package/dist/experimental.d.ts.map +1 -0
  56. package/dist/experimental.js +502 -0
  57. package/dist/experimental.js.map +1 -0
  58. package/dist/files.d.ts +87 -0
  59. package/dist/files.d.ts.map +1 -0
  60. package/dist/files.js +328 -0
  61. package/dist/files.js.map +1 -0
  62. package/dist/form.d.ts +39 -0
  63. package/dist/form.d.ts.map +1 -0
  64. package/dist/form.js +170 -0
  65. package/dist/form.js.map +1 -0
  66. package/dist/index.d.ts +38 -4
  67. package/dist/index.d.ts.map +1 -1
  68. package/dist/index.js +23 -1
  69. package/dist/index.js.map +1 -1
  70. package/dist/input.d.ts +10 -0
  71. package/dist/input.d.ts.map +1 -1
  72. package/dist/input.js +12 -0
  73. package/dist/input.js.map +1 -1
  74. package/dist/list-item.d.ts +3 -0
  75. package/dist/list-item.d.ts.map +1 -0
  76. package/dist/list-item.js +7 -0
  77. package/dist/list-item.js.map +1 -0
  78. package/dist/motion.d.ts +33 -0
  79. package/dist/motion.d.ts.map +1 -0
  80. package/dist/motion.js +21 -0
  81. package/dist/motion.js.map +1 -0
  82. package/dist/navigation.d.ts +22 -0
  83. package/dist/navigation.d.ts.map +1 -0
  84. package/dist/navigation.js +54 -0
  85. package/dist/navigation.js.map +1 -0
  86. package/dist/progress.d.ts +19 -0
  87. package/dist/progress.d.ts.map +1 -0
  88. package/dist/progress.js +19 -0
  89. package/dist/progress.js.map +1 -0
  90. package/dist/segmented.d.ts +11 -0
  91. package/dist/segmented.d.ts.map +1 -0
  92. package/dist/segmented.js +30 -0
  93. package/dist/segmented.js.map +1 -0
  94. package/dist/sheet.d.ts +8 -1
  95. package/dist/sheet.d.ts.map +1 -1
  96. package/dist/sheet.js +4 -3
  97. package/dist/sheet.js.map +1 -1
  98. package/dist/tabs.d.ts +11 -0
  99. package/dist/tabs.d.ts.map +1 -0
  100. package/dist/tabs.js +28 -0
  101. package/dist/tabs.js.map +1 -0
  102. package/dist/theme/themes.d.ts.map +1 -1
  103. package/dist/theme/themes.js +84 -11
  104. package/dist/theme/themes.js.map +1 -1
  105. package/dist/theme/types.d.ts +52 -1
  106. package/dist/theme/types.d.ts.map +1 -1
  107. package/dist/theme/typography.d.ts +10 -0
  108. package/dist/theme/typography.d.ts.map +1 -0
  109. package/dist/theme/typography.js +90 -0
  110. package/dist/theme/typography.js.map +1 -0
  111. package/dist/toast.d.ts +43 -0
  112. package/dist/toast.d.ts.map +1 -0
  113. package/dist/toast.js +228 -0
  114. package/dist/toast.js.map +1 -0
  115. package/dist/vue/button-content.d.ts +10 -0
  116. package/dist/vue/button-content.d.ts.map +1 -0
  117. package/dist/vue/button-content.js +54 -0
  118. package/dist/vue/button-content.js.map +1 -0
  119. package/dist/vue/cached-activity.d.ts +3 -0
  120. package/dist/vue/cached-activity.d.ts.map +1 -0
  121. package/dist/vue/cached-activity.js +13 -0
  122. package/dist/vue/cached-activity.js.map +1 -0
  123. package/dist/vue/combobox.d.ts +155 -0
  124. package/dist/vue/combobox.d.ts.map +1 -0
  125. package/dist/vue/combobox.js +195 -0
  126. package/dist/vue/combobox.js.map +1 -0
  127. package/dist/vue/component-props.d.ts +1989 -0
  128. package/dist/vue/component-props.d.ts.map +1 -0
  129. package/dist/vue/component-props.js +18 -0
  130. package/dist/vue/component-props.js.map +1 -0
  131. package/dist/vue/contracts.d.ts +18 -0
  132. package/dist/vue/contracts.d.ts.map +1 -0
  133. package/dist/vue/contracts.js +18 -0
  134. package/dist/vue/contracts.js.map +1 -0
  135. package/dist/vue/date-calendar.d.ts +64 -0
  136. package/dist/vue/date-calendar.d.ts.map +1 -0
  137. package/dist/vue/date-calendar.js +65 -0
  138. package/dist/vue/date-calendar.js.map +1 -0
  139. package/dist/vue/date-picker.d.ts +927 -0
  140. package/dist/vue/date-picker.d.ts.map +1 -0
  141. package/dist/vue/date-picker.js +319 -0
  142. package/dist/vue/date-picker.js.map +1 -0
  143. package/dist/vue/date-props.d.ts +254 -0
  144. package/dist/vue/date-props.d.ts.map +1 -0
  145. package/dist/vue/date-props.js +74 -0
  146. package/dist/vue/date-props.js.map +1 -0
  147. package/dist/vue/dialog.d.ts +21 -0
  148. package/dist/vue/dialog.d.ts.map +1 -0
  149. package/dist/vue/dialog.js +58 -0
  150. package/dist/vue/dialog.js.map +1 -0
  151. package/dist/vue/files.d.ts +53 -0
  152. package/dist/vue/files.d.ts.map +1 -0
  153. package/dist/vue/files.js +40 -0
  154. package/dist/vue/files.js.map +1 -0
  155. package/dist/vue/forms.d.ts +4 -0
  156. package/dist/vue/forms.d.ts.map +1 -0
  157. package/dist/vue/forms.js +15 -0
  158. package/dist/vue/forms.js.map +1 -0
  159. package/dist/vue/global-components.d.ts +129 -3
  160. package/dist/vue/global-components.d.ts.map +1 -1
  161. package/dist/vue/index.d.ts +28 -2
  162. package/dist/vue/index.d.ts.map +1 -1
  163. package/dist/vue/index.js +24 -1
  164. package/dist/vue/index.js.map +1 -1
  165. package/dist/vue/inline-content.d.ts +54 -0
  166. package/dist/vue/inline-content.d.ts.map +1 -0
  167. package/dist/vue/inline-content.js +64 -0
  168. package/dist/vue/inline-content.js.map +1 -0
  169. package/dist/vue/props.d.ts +2654 -637
  170. package/dist/vue/props.d.ts.map +1 -1
  171. package/dist/vue/props.js +228 -86
  172. package/dist/vue/props.js.map +1 -1
  173. package/dist/vue/theme-provider.d.ts +58 -0
  174. package/dist/vue/theme-provider.d.ts.map +1 -0
  175. package/dist/vue/theme-provider.js +69 -0
  176. package/dist/vue/theme-provider.js.map +1 -0
  177. package/dist/vue/theme.d.ts +962 -12
  178. package/dist/vue/theme.d.ts.map +1 -1
  179. package/dist/vue/theme.js +17 -7
  180. package/dist/vue/theme.js.map +1 -1
  181. package/dist/vue/toast.d.ts +29 -0
  182. package/dist/vue/toast.d.ts.map +1 -0
  183. package/dist/vue/toast.js +79 -0
  184. package/dist/vue/toast.js.map +1 -0
  185. package/dist/vue/workflow-props.d.ts +110 -0
  186. package/dist/vue/workflow-props.d.ts.map +1 -0
  187. package/dist/vue/workflow-props.js +37 -0
  188. package/dist/vue/workflow-props.js.map +1 -0
  189. package/dist/vue/workflows.d.ts +267 -0
  190. package/dist/vue/workflows.d.ts.map +1 -0
  191. package/dist/vue/workflows.js +200 -0
  192. package/dist/vue/workflows.js.map +1 -0
  193. package/package.json +5 -1
  194. package/src/accordion.ts +66 -0
  195. package/src/alert.ts +16 -0
  196. package/src/avatar.ts +11 -0
  197. package/src/badge.ts +11 -0
  198. package/src/capabilities.ts +145 -0
  199. package/src/chip.ts +20 -0
  200. package/src/choice.ts +41 -0
  201. package/src/combobox.ts +198 -0
  202. package/src/contracts.ts +295 -0
  203. package/src/date.ts +280 -0
  204. package/src/dialog.ts +20 -0
  205. package/src/empty-state.ts +4 -0
  206. package/src/experimental-regions.ts +463 -0
  207. package/src/experimental.ts +643 -0
  208. package/src/files.ts +408 -0
  209. package/src/form.ts +190 -0
  210. package/src/index.ts +64 -3
  211. package/src/input.ts +22 -0
  212. package/src/list-item.ts +5 -0
  213. package/src/motion.ts +22 -0
  214. package/src/navigation.ts +61 -0
  215. package/src/progress.ts +22 -0
  216. package/src/segmented.ts +39 -0
  217. package/src/sheet.ts +6 -3
  218. package/src/tabs.ts +35 -0
  219. package/src/theme/themes.ts +88 -11
  220. package/src/theme/types.ts +42 -1
  221. package/src/theme/typography.ts +84 -0
  222. package/src/toast.ts +249 -0
  223. package/src/vue/button-content.ts +60 -0
  224. package/src/vue/cached-activity.ts +13 -0
  225. package/src/vue/combobox.ts +238 -0
  226. package/src/vue/component-props.ts +24 -0
  227. package/src/vue/contracts.ts +33 -0
  228. package/src/vue/date-calendar.ts +76 -0
  229. package/src/vue/date-picker.ts +387 -0
  230. package/src/vue/date-props.ts +81 -0
  231. package/src/vue/dialog.ts +63 -0
  232. package/src/vue/files.ts +53 -0
  233. package/src/vue/forms.ts +20 -0
  234. package/src/vue/global-components.ts +120 -3
  235. package/src/vue/index.ts +46 -2
  236. package/src/vue/inline-content.ts +71 -0
  237. package/src/vue/props.ts +258 -95
  238. package/src/vue/theme-provider.ts +74 -0
  239. package/src/vue/theme.ts +17 -6
  240. package/src/vue/toast.ts +99 -0
  241. package/src/vue/workflow-props.ts +41 -0
  242. package/src/vue/workflows.ts +257 -0
package/src/toast.ts ADDED
@@ -0,0 +1,249 @@
1
+ export type ToastTone = 'success' | 'error' | 'warning' | 'info'
2
+
3
+ export interface ToastOptions {
4
+ message: string
5
+ title?: string
6
+ tone?: ToastTone
7
+ /** Milliseconds after entry. Zero keeps the notification until dismissed. */
8
+ duration?: number
9
+ }
10
+ export interface ToastMessage {
11
+ readonly id: number
12
+ readonly title?: string
13
+ readonly message: string
14
+ readonly tone: ToastTone
15
+ readonly duration: number
16
+ }
17
+ export interface ToastController {
18
+ /** Returns undefined after disposal, or after a local host has left. */
19
+ show(options: ToastOptions): number | undefined
20
+ dismiss(id?: number): void
21
+ clear(): void
22
+ }
23
+ export interface ToastSnapshot {
24
+ readonly message?: ToastMessage
25
+ readonly visible: boolean
26
+ }
27
+ export interface ToastConnection {
28
+ activate(): void
29
+ deactivate(): void
30
+ pause(reason: string, paused: boolean): void
31
+ begin(id: number): void
32
+ entered(id: number): void
33
+ left(id: number): void
34
+ dispose(): void
35
+ }
36
+
37
+ const queues = new WeakMap<ToastController, ToastQueue>()
38
+ let nextId = 0
39
+
40
+ function notification(options: ToastOptions): ToastMessage {
41
+ if (!options || typeof options.message !== 'string' || !options.message.trim())
42
+ throw new TypeError('Toast message must be a non-empty string')
43
+ if (options.title !== undefined && (typeof options.title !== 'string' || !options.title.trim()))
44
+ throw new TypeError('Toast title must be a non-empty string when supplied')
45
+ const tone = options.tone ?? 'info'
46
+ if (!['success', 'error', 'warning', 'info'].includes(tone))
47
+ throw new RangeError(`Unknown Toast tone: ${String(tone)}`)
48
+ const duration = options.duration ?? 5000
49
+ if (!Number.isFinite(duration) || duration < 0 || duration > 2_147_483_647)
50
+ throw new RangeError('Toast duration must be between 0 and 2147483647 milliseconds')
51
+ return Object.freeze({
52
+ id: ++nextId,
53
+ title: options.title,
54
+ message: options.message,
55
+ tone,
56
+ duration,
57
+ })
58
+ }
59
+
60
+ class ToastQueue {
61
+ items: ToastMessage[] = []
62
+ listener?: (snapshot: ToastSnapshot) => void
63
+ bound = 0
64
+ owner?: object
65
+
66
+ constructor(readonly persistent = false) {}
67
+ active = false
68
+ accepting = true
69
+ disposed = false
70
+ presenting = false
71
+ entered = false
72
+ closing = false
73
+ remaining = 0
74
+ started = 0
75
+ timer?: ReturnType<typeof setTimeout>
76
+ pauses = new Set<string>()
77
+
78
+ publish() {
79
+ this.listener?.({ message: this.items[0], visible: this.active && !this.closing })
80
+ }
81
+ stop() {
82
+ if (this.timer === undefined) return
83
+ clearTimeout(this.timer)
84
+ this.timer = undefined
85
+ this.remaining = Math.max(0, this.remaining - Math.max(0, Date.now() - this.started))
86
+ }
87
+ run() {
88
+ const item = this.items[0]
89
+ if (
90
+ !item ||
91
+ !item.duration ||
92
+ !this.active ||
93
+ !this.entered ||
94
+ this.closing ||
95
+ this.pauses.size
96
+ )
97
+ return
98
+ if (this.timer !== undefined) return
99
+ this.started = Date.now()
100
+ this.timer = setTimeout(() => {
101
+ this.timer = undefined
102
+ if (this.items[0]?.id === item.id) this.dismiss(item.id)
103
+ }, this.remaining)
104
+ }
105
+ advance() {
106
+ this.stop()
107
+ this.presenting = this.entered = this.closing = false
108
+ this.remaining = this.items[0]?.duration ?? 0
109
+ this.publish()
110
+ }
111
+ show(options: ToastOptions) {
112
+ const item = notification(options)
113
+ if (!this.accepting || this.disposed) return undefined
114
+ this.items.push(item)
115
+ if (this.items.length === 1) this.advance()
116
+ return item.id
117
+ }
118
+ dismiss(id = this.items[0]?.id) {
119
+ const index = this.items.findIndex((item) => item.id === id)
120
+ if (index < 0) return
121
+ if (index > 0) {
122
+ this.items.splice(index, 1)
123
+ return
124
+ }
125
+ if (this.closing) return
126
+ this.stop()
127
+ if (!this.presenting || !this.active) {
128
+ this.items.shift()
129
+ this.advance()
130
+ } else {
131
+ this.closing = true
132
+ this.publish()
133
+ }
134
+ }
135
+ clear() {
136
+ this.items.splice(1)
137
+ this.dismiss()
138
+ }
139
+ deactivate() {
140
+ this.stop()
141
+ this.active = false
142
+ this.pauses.clear()
143
+ if (this.persistent && !this.disposed) {
144
+ if (this.closing) {
145
+ this.items.shift()
146
+ this.remaining = this.items[0]?.duration ?? 0
147
+ }
148
+ this.presenting = this.entered = this.closing = false
149
+ this.publish()
150
+ } else {
151
+ this.accepting = false
152
+ this.items = []
153
+ this.advance()
154
+ }
155
+ }
156
+ }
157
+
158
+ /** Hosts own presentation; a persistent queue survives host replacement until disposed. */
159
+ export function createToastController(options: { persistent?: boolean } = {}): ToastController {
160
+ const queue = new ToastQueue(options.persistent)
161
+ const controller: ToastController = Object.freeze({
162
+ show: (options: ToastOptions) => queue.show(options),
163
+ dismiss: (id?: number) => queue.dismiss(id),
164
+ clear: () => queue.clear(),
165
+ })
166
+ queues.set(controller, queue)
167
+ return controller
168
+ }
169
+
170
+ /** @internal Local queues have one host; persistent queues hand off to the latest active host. */
171
+ export function connectToast(
172
+ controller: ToastController,
173
+ listener: (snapshot: ToastSnapshot) => void,
174
+ ): ToastConnection {
175
+ const queue = queues.get(controller)
176
+ if (!queue || queue.disposed) throw new Error('MToast needs an active Mavis Toast controller')
177
+ if (queue.bound && !queue.persistent)
178
+ throw new Error('A Toast controller can only have one MToast host')
179
+ queue.bound++
180
+ const owner = {}
181
+ const pauses = new Set<string>()
182
+ let released = false
183
+ const owns = () => !released && !queue.disposed && queue.owner === owner
184
+ const current = (id: number) => owns() && queue.items[0]?.id === id
185
+ const detach = () => {
186
+ if (queue.owner !== owner) return
187
+ queue.deactivate()
188
+ listener({ visible: false })
189
+ queue.owner = queue.listener = undefined
190
+ }
191
+ listener({ visible: false })
192
+ return {
193
+ activate() {
194
+ if (released || queue.disposed || owns()) return
195
+ if (queue.owner) {
196
+ queue.deactivate()
197
+ queue.listener?.({ visible: false })
198
+ }
199
+ queue.owner = owner
200
+ queue.listener = listener
201
+ queue.pauses = new Set(pauses)
202
+ queue.active = queue.accepting = true
203
+ queue.publish()
204
+ queue.run()
205
+ },
206
+ deactivate() {
207
+ if (released) return
208
+ detach()
209
+ pauses.clear()
210
+ },
211
+ pause(reason, paused) {
212
+ if (released) return
213
+ if (paused) pauses.add(reason)
214
+ else pauses.delete(reason)
215
+ if (!owns()) return
216
+ if (paused) queue.stop()
217
+ queue.pauses = new Set(pauses)
218
+ queue.run()
219
+ },
220
+ begin(id) {
221
+ if (current(id)) queue.presenting = true
222
+ },
223
+ entered(id) {
224
+ if (!current(id) || queue.closing) return
225
+ queue.entered = true
226
+ queue.run()
227
+ },
228
+ left(id) {
229
+ if (!current(id) || !queue.closing) return
230
+ queue.items.shift()
231
+ queue.advance()
232
+ },
233
+ dispose() {
234
+ if (released) return
235
+ detach()
236
+ released = true
237
+ queue.bound--
238
+ pauses.clear()
239
+ },
240
+ }
241
+ }
242
+
243
+ /** @internal Vue scope cleanup also rejects late asynchronous notifications. */
244
+ export function disposeToast(controller: ToastController) {
245
+ const queue = queues.get(controller)
246
+ if (!queue) return
247
+ queue.disposed = true
248
+ queue.deactivate()
249
+ }
@@ -0,0 +1,60 @@
1
+ import { defineComponent, inject, provide, watchEffect } from '@vue/runtime-core'
2
+ import { Comment, Fragment, isVNode, type VNode, type VNodeChild } from '@vue/runtime-core'
3
+
4
+ /** Adornments are decorative. Put any meaning in the button label, never another action. */
5
+ export function buttonContent(content: VNodeChild[] | undefined): VNodeChild[] {
6
+ const visit = (node: VNodeChild): void => {
7
+ if (Array.isArray(node)) {
8
+ node.forEach(visit)
9
+ return
10
+ }
11
+ if (!isVNode(node) || node.type === Comment) return
12
+ const name =
13
+ typeof node.type === 'string'
14
+ ? node.type
15
+ : typeof node.type === 'object'
16
+ ? 'name' in node.type
17
+ ? String(node.type.name)
18
+ : ''
19
+ : ''
20
+ const props = node.props ?? {}
21
+ if (
22
+ /^(button|input|textarea|select|a|Button|TextField|TextView|Switch|Slider|WebView|MButton|MInput|MSwitch|MCheckbox|MRadioGroup|MSelect|MSlider|MTabs|MChip|MAccordion|MSegmentedControl|MSheet|MDialog|MToast)$/i.test(
23
+ name,
24
+ ) ||
25
+ props.interactive ||
26
+ props.contenteditable ||
27
+ props.contentEditable ||
28
+ props.tabindex !== undefined ||
29
+ props.tabIndex !== undefined ||
30
+ Object.keys(props).some((key) => /^on(Click|Tap|Touch|Pointer|Key|Focus|LongPress)/.test(key))
31
+ ) {
32
+ throw new TypeError(
33
+ 'Button leading/trailing content must be decorative, without nested controls or interaction handlers.',
34
+ )
35
+ }
36
+ if (Array.isArray(node.children)) node.children.forEach((child) => visit(child as VNode))
37
+ else if (node.type === Fragment && node.children) visit(node.children as VNodeChild)
38
+ }
39
+ content?.forEach(visit)
40
+ return content ?? []
41
+ }
42
+
43
+ const decorationKey = Symbol('mavis.buttonDecoration')
44
+
45
+ /** @internal Also guards Mavis controls rendered inside custom decorative components. */
46
+ export const ButtonAdornment = defineComponent({
47
+ setup(_props, { slots }) {
48
+ provide(decorationKey, true)
49
+ return () => slots.default?.()
50
+ },
51
+ })
52
+
53
+ /** @internal Stateful controls cannot become descendants of a decorative button slot. */
54
+ export function useButtonAction(interactive: () => boolean = () => true) {
55
+ if (!inject(decorationKey, false)) return
56
+ watchEffect(() => {
57
+ if (interactive())
58
+ throw new TypeError('Button adornments cannot contain interactive Mavis components.')
59
+ })
60
+ }
@@ -0,0 +1,13 @@
1
+ import { onActivated, onDeactivated, ref } from '@vue/runtime-core'
2
+
3
+ /** @internal Vue caches instances, but application observers still need an explicit pause. */
4
+ export function useCachedActivity() {
5
+ const active = ref(true)
6
+ onActivated(() => {
7
+ active.value = true
8
+ })
9
+ onDeactivated(() => {
10
+ active.value = false
11
+ })
12
+ return active
13
+ }
@@ -0,0 +1,238 @@
1
+ import {
2
+ computed,
3
+ onBeforeUnmount,
4
+ ref,
5
+ shallowRef,
6
+ watch,
7
+ type ExtractPropTypes,
8
+ type PropType,
9
+ } from '@vue/runtime-core'
10
+ import { dimensionProperty, flexContract, viewContract } from '../contracts.js'
11
+ import { vueProperty, vueProps } from './contracts.js'
12
+ import { useCachedActivity } from './cached-activity.js'
13
+ import {
14
+ choiceKey,
15
+ isChoiceValue,
16
+ validateChoices,
17
+ type ChoiceOption,
18
+ type ChoiceValue,
19
+ } from '../choice.js'
20
+ import {
21
+ comboboxHighlight,
22
+ comboboxMove,
23
+ comboboxSelected,
24
+ createComboboxSearch,
25
+ type ComboboxSearch,
26
+ type ComboboxSnapshot,
27
+ } from '../combobox.js'
28
+
29
+ export const comboboxProps = {
30
+ ...vueProps(viewContract),
31
+ ...vueProps(flexContract),
32
+ width: vueProperty(dimensionProperty),
33
+ modelValue: { type: [String, Number] as PropType<ChoiceValue | null>, default: null },
34
+ query: { type: String, required: true as const },
35
+ selectedOption: { type: Object as PropType<ChoiceOption | null>, default: null },
36
+ search: { type: Function as PropType<ComboboxSearch>, required: true as const },
37
+ initialResults: { type: Object as PropType<ComboboxSnapshot>, default: undefined },
38
+ debounce: { type: Number, default: 200 },
39
+ minQueryLength: { type: Number, default: 1 },
40
+ maxResults: { type: Number, default: 50 },
41
+ label: { type: String, required: true as const },
42
+ placeholder: { type: String, default: 'Search options' },
43
+ helperText: { type: String, default: '' },
44
+ error: { type: String, default: '' },
45
+ disabled: Boolean,
46
+ clearable: { type: Boolean, default: true },
47
+ clearLabel: { type: String, default: 'Clear selection' },
48
+ closeLabel: { type: String, default: 'Close results' },
49
+ loadingText: { type: String, default: 'Searching…' },
50
+ emptyText: { type: String, default: 'No results' },
51
+ searchErrorText: { type: String, default: 'Could not load results.' },
52
+ retryLabel: { type: String, default: 'Try again' },
53
+ idleText: { type: String, default: 'Type to search.' },
54
+ limitedText: { type: String, default: 'Refine your search to see more results.' },
55
+ }
56
+ export const comboboxEmits = {
57
+ 'update:modelValue': (value: ChoiceValue | null) => value === null || isChoiceValue(value),
58
+ 'update:query': (value: string) => typeof value === 'string',
59
+ select: (option: ChoiceOption | null) => option === null || isChoiceValue(option.value),
60
+ focus: () => true,
61
+ blur: () => true,
62
+ }
63
+ type Props = Readonly<ExtractPropTypes<typeof comboboxProps>>
64
+ type Emit = {
65
+ (event: 'update:modelValue', value: ChoiceValue | null): void
66
+ (event: 'update:query', value: string): void
67
+ (event: 'select', value: ChoiceOption | null): void
68
+ }
69
+
70
+ /** @internal Shared request ownership and controlled selection for the two Vue renderers. */
71
+ export function useCombobox(props: Props, emit: Emit) {
72
+ watch(
73
+ () => props.label,
74
+ (label) => {
75
+ if (!label.trim()) throw new RangeError('Combobox needs a nonempty label.')
76
+ },
77
+ { immediate: true },
78
+ )
79
+ const open = ref(false)
80
+ const revision = ref(0)
81
+ const composing = ref(false)
82
+ const active = ref<string>()
83
+ const retained = shallowRef<ChoiceOption | null>(props.selectedOption)
84
+ const pendingSelection = shallowRef<ChoiceOption>()
85
+ const activity = useCachedActivity()
86
+ const makeSearch = () =>
87
+ createComboboxSearch({
88
+ search: (query, context) => props.search(query, context),
89
+ debounce: props.debounce,
90
+ minQueryLength: props.minQueryLength,
91
+ maxResults: props.maxResults,
92
+ initialResults: props.initialResults,
93
+ onChange(value) {
94
+ state.value = value
95
+ active.value = comboboxHighlight(value.options, active.value)
96
+ },
97
+ })
98
+ let search = makeSearch()
99
+ const state = shallowRef(search.state)
100
+ const selected = computed(() =>
101
+ comboboxSelected(
102
+ props.modelValue,
103
+ state.value.options,
104
+ props.selectedOption?.value === props.modelValue
105
+ ? props.selectedOption
106
+ : pendingSelection.value?.value === props.modelValue
107
+ ? pendingSelection.value
108
+ : retained.value,
109
+ ),
110
+ )
111
+ watch(
112
+ selected,
113
+ (option) => {
114
+ if (option) retained.value = option
115
+ },
116
+ { immediate: true },
117
+ )
118
+ watch(
119
+ () => [props.modelValue, props.selectedOption] as const,
120
+ () => {
121
+ validateChoices(props.selectedOption ? [props.selectedOption] : [], props.modelValue)
122
+ if (props.modelValue === null) {
123
+ retained.value = null
124
+ pendingSelection.value = undefined
125
+ }
126
+ },
127
+ { immediate: true, deep: true },
128
+ )
129
+ watch(
130
+ () => props.query,
131
+ () => {
132
+ if (open.value && !composing.value) search.request(props.query)
133
+ else search.cancel()
134
+ },
135
+ { flush: 'sync' },
136
+ )
137
+ watch(
138
+ () => [props.search, props.debounce, props.minQueryLength, props.maxResults],
139
+ () => {
140
+ search.dispose()
141
+ search = makeSearch()
142
+ state.value = search.state
143
+ if (open.value && !composing.value) search.request(props.query)
144
+ },
145
+ )
146
+ watch(
147
+ () => props.disabled || !activity.value,
148
+ (blocked) => {
149
+ if (blocked) close()
150
+ },
151
+ )
152
+ onBeforeUnmount(() => search.dispose())
153
+ function show() {
154
+ if (props.disabled || !activity.value) return
155
+ open.value = true
156
+ if (!composing.value) search.request(props.query)
157
+ }
158
+ function close() {
159
+ open.value = false
160
+ active.value = undefined
161
+ composing.value = false
162
+ search.cancel()
163
+ }
164
+ function edit(query: string) {
165
+ if (props.disabled) return
166
+ revision.value++
167
+ // Browsers may send a final input event after compositionend. It is the same
168
+ // accepted query, not a second request (including when debounce is zero).
169
+ if (
170
+ query === props.query &&
171
+ !composing.value &&
172
+ open.value &&
173
+ state.value.query === query &&
174
+ state.value.status !== 'idle'
175
+ )
176
+ return
177
+ search.cancel()
178
+ active.value = undefined
179
+ open.value = true
180
+ emit('update:query', query)
181
+ if (props.query === query && !composing.value) search.request(query)
182
+ // Only the accepted controlled query starts a request (the synchronous watch owns it).
183
+ }
184
+ function choose(option: ChoiceOption) {
185
+ const current = state.value.options.find((item) => item.value === option.value)
186
+ if (!open.value || props.disabled || composing.value || !current || current.disabled) return
187
+ pendingSelection.value = current
188
+ if (props.modelValue !== current.value) emit('update:modelValue', current.value)
189
+ emit('update:query', current.label)
190
+ emit('select', current)
191
+ close()
192
+ }
193
+ function clear() {
194
+ if (props.disabled) return
195
+ close()
196
+ emit('update:modelValue', null)
197
+ emit('update:query', '')
198
+ emit('select', null)
199
+ }
200
+ function cancel() {
201
+ close()
202
+ emit('update:query', selected.value?.label ?? '')
203
+ }
204
+ return {
205
+ open,
206
+ composing,
207
+ active,
208
+ state,
209
+ selected,
210
+ revision,
211
+ show,
212
+ close,
213
+ edit,
214
+ choose,
215
+ clear,
216
+ cancel,
217
+ startComposition() {
218
+ composing.value = true
219
+ search.cancel()
220
+ active.value = undefined
221
+ },
222
+ endComposition(query: string) {
223
+ composing.value = false
224
+ edit(query)
225
+ },
226
+ move(direction: 1 | -1) {
227
+ if (!open.value) show()
228
+ active.value = comboboxMove(state.value.options, active.value, direction)
229
+ },
230
+ commit() {
231
+ const option = state.value.options.find((item) => choiceKey(item.value) === active.value)
232
+ if (option) choose(option)
233
+ },
234
+ retry() {
235
+ if (!props.disabled && open.value && !composing.value) search.request(props.query, true)
236
+ },
237
+ }
238
+ }
@@ -0,0 +1,24 @@
1
+ import type { ExtractPublicPropTypes } from '@vue/runtime-core'
2
+ import type { SheetName } from '../sheet.js'
3
+ import { componentProps as foundationProps } from './props.js'
4
+ import { datePickerProps, dateRangePickerProps } from './date-props.js'
5
+ import { comboboxProps } from './combobox.js'
6
+ import { filePickerProps } from './files.js'
7
+ import { formGroupProps, formErrorsProps, stepsProps, paginationProps } from './workflow-props.js'
8
+
9
+ /** Complete registry, kept separate from the primitives used to compose controls. */
10
+ export const componentProps = {
11
+ ...foundationProps,
12
+ MDatePicker: datePickerProps,
13
+ MDateRangePicker: dateRangePickerProps,
14
+ MCombobox: comboboxProps,
15
+ MFilePicker: filePickerProps,
16
+ MFormGroup: formGroupProps,
17
+ MFormErrors: formErrorsProps,
18
+ MSteps: stepsProps,
19
+ MPagination: paginationProps,
20
+ }
21
+ export type ComponentProps = {
22
+ [Name in keyof typeof componentProps]: ExtractPublicPropTypes<(typeof componentProps)[Name]> &
23
+ (Name extends 'MSheet' ? SheetName : unknown)
24
+ }
@@ -0,0 +1,33 @@
1
+ import type { PropType } from '@vue/runtime-core'
2
+ import type { Property, PropertyValue } from '../contracts.js'
3
+
4
+ type VueProperty<P extends Property> = { type: PropType<PropertyValue<P>> } & (P extends {
5
+ default: infer D
6
+ }
7
+ ? { default: D extends undefined ? undefined : PropertyValue<P> }
8
+ : unknown) &
9
+ (P extends { required: true } ? { required: true } : unknown)
10
+
11
+ const constructors = { string: String, number: Number, boolean: Boolean, object: Object }
12
+
13
+ /** Vue owns coercion and warnings; portable metadata owns names, defaults and allowed values. */
14
+ export function vueProperty<P extends Property>(definition: P): VueProperty<P> {
15
+ const kinds = Array.isArray(definition.kind) ? definition.kind : [definition.kind]
16
+ const types = kinds.map((kind: keyof typeof constructors) => constructors[kind])
17
+ return {
18
+ type: types.length === 1 ? types[0] : types,
19
+ ...('default' in definition ? { default: definition.default } : {}),
20
+ ...(definition.required ? { required: true } : {}),
21
+ ...(definition.values
22
+ ? { validator: (value: unknown) => definition.values!.includes(value) }
23
+ : {}),
24
+ } as VueProperty<P>
25
+ }
26
+
27
+ export function vueProps<P extends Record<string, Property>>(properties: P) {
28
+ return Object.fromEntries(
29
+ Object.entries(properties).map(([key, value]) => [key, vueProperty(value)]),
30
+ ) as {
31
+ [K in keyof P]: VueProperty<P[K]>
32
+ }
33
+ }
@@ -0,0 +1,76 @@
1
+ import { computed, watch, type ExtractPropTypes } from '@vue/runtime-core'
2
+ import {
3
+ addCivilDays,
4
+ addCivilMonths,
5
+ calendarMonth,
6
+ civilWeekday,
7
+ dateAvailability,
8
+ dateLocales,
9
+ parseCivilDate,
10
+ type CivilDate,
11
+ } from '../date.js'
12
+ import { dateCalendarProps } from './date-props.js'
13
+
14
+ /** @internal Calendar arithmetic and live bounds shared by Web and native presentations. */
15
+ export function useDateCalendar(
16
+ props: ExtractPropTypes<typeof dateCalendarProps>,
17
+ change: (value: CivilDate) => void,
18
+ ) {
19
+ const words = computed(() => dateLocales[props.locale])
20
+ const firstDay = computed(() => props.firstDayOfWeek ?? words.value.firstDayOfWeek)
21
+ const cells = computed(() => calendarMonth(props.activeDate, firstDay.value))
22
+ const title = computed(() => {
23
+ const parts = parseCivilDate(props.activeDate)!
24
+ return `${words.value.months[parts.month - 1]} ${String(parts.year).padStart(4, '0')}`
25
+ })
26
+ const weekdays = computed(() =>
27
+ Array.from({ length: 7 }, (_, index) => (index + firstDay.value) % 7),
28
+ )
29
+ const available = (date: CivilDate) => dateAvailability(date, props) === null
30
+ function clamp(value: CivilDate) {
31
+ if (props.min && value < props.min) return props.min
32
+ if (props.max && value > props.max) return props.max
33
+ return value
34
+ }
35
+ function move(value: CivilDate) {
36
+ change(clamp(value))
37
+ }
38
+ function canPage(amount: number) {
39
+ const next = addCivilMonths(props.activeDate, amount)
40
+ return (
41
+ next.slice(0, 7) !== props.activeDate.slice(0, 7) &&
42
+ (!props.min || next.slice(0, 7) >= props.min.slice(0, 7)) &&
43
+ (!props.max || next.slice(0, 7) <= props.max.slice(0, 7))
44
+ )
45
+ }
46
+ function page(amount: number) {
47
+ if (canPage(amount)) move(addCivilMonths(props.activeDate, amount))
48
+ }
49
+ function key(key: string, shift = false, rtl = false): boolean {
50
+ const active = props.activeDate
51
+ if (key === 'ArrowLeft') move(addCivilDays(active, rtl ? 1 : -1))
52
+ else if (key === 'ArrowRight') move(addCivilDays(active, rtl ? -1 : 1))
53
+ else if (key === 'ArrowUp') move(addCivilDays(active, -7))
54
+ else if (key === 'ArrowDown') move(addCivilDays(active, 7))
55
+ else if (key === 'Home')
56
+ move(addCivilDays(active, -((civilWeekday(active) - firstDay.value + 7) % 7)))
57
+ else if (key === 'End')
58
+ move(addCivilDays(active, 6 - ((civilWeekday(active) - firstDay.value + 7) % 7)))
59
+ else if (key === 'PageUp') move(addCivilMonths(active, shift ? -12 : -1))
60
+ else if (key === 'PageDown') move(addCivilMonths(active, shift ? 12 : 1))
61
+ else return false
62
+ return true
63
+ }
64
+ watch(
65
+ () => [props.min, props.max, props.activeDate],
66
+ () => {
67
+ const value = clamp(props.activeDate)
68
+ if (value !== props.activeDate) change(value)
69
+ },
70
+ )
71
+ const inRange = (date: CivilDate) =>
72
+ Boolean(
73
+ props.rangeStart && props.rangeEnd && date >= props.rangeStart && date <= props.rangeEnd,
74
+ )
75
+ return { words, title, firstDay, cells, weekdays, available, move, canPage, page, key, inRange }
76
+ }