@getcortexlabs/mavis-core 0.1.0-rc.14 → 0.1.0-rc.16

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 (100) hide show
  1. package/README.md +2 -2
  2. package/dist/avatar.d.ts +5 -0
  3. package/dist/avatar.d.ts.map +1 -1
  4. package/dist/capabilities.d.ts +454 -1777
  5. package/dist/capabilities.d.ts.map +1 -1
  6. package/dist/capabilities.js +143 -82
  7. package/dist/capabilities.js.map +1 -1
  8. package/dist/contracts.d.ts +4 -4
  9. package/dist/experimental-regions.d.ts +5 -2
  10. package/dist/experimental-regions.d.ts.map +1 -1
  11. package/dist/experimental-regions.js +3 -0
  12. package/dist/experimental-regions.js.map +1 -1
  13. package/dist/index.d.ts +2 -2
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +1 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/vue/advanced-collections.d.ts +16 -16
  18. package/dist/vue/animated-text.d.ts +4 -4
  19. package/dist/vue/chart.d.ts +5 -5
  20. package/dist/vue/command-palette.d.ts +4 -4
  21. package/dist/vue/component-props.d.ts +92 -22
  22. package/dist/vue/component-props.d.ts.map +1 -1
  23. package/dist/vue/component-props.js +4 -0
  24. package/dist/vue/component-props.js.map +1 -1
  25. package/dist/vue/composer.d.ts +11 -9
  26. package/dist/vue/composer.d.ts.map +1 -1
  27. package/dist/vue/composer.js +12 -16
  28. package/dist/vue/composer.js.map +1 -1
  29. package/dist/vue/configurator.d.ts +16 -16
  30. package/dist/vue/creative-controls.d.ts +11 -11
  31. package/dist/vue/dashboard-charts.d.ts +6 -6
  32. package/dist/vue/dashboard-effects.d.ts +7 -7
  33. package/dist/vue/date-picker.d.ts +52 -52
  34. package/dist/vue/discovery-controls.d.ts +8 -8
  35. package/dist/vue/editor-controls.d.ts +223 -0
  36. package/dist/vue/editor-controls.d.ts.map +1 -0
  37. package/dist/vue/editor-controls.js +323 -0
  38. package/dist/vue/editor-controls.js.map +1 -0
  39. package/dist/vue/global-components.d.ts +22 -1
  40. package/dist/vue/global-components.d.ts.map +1 -1
  41. package/dist/vue/image-cropper.d.ts +8 -8
  42. package/dist/vue/image-cropper.d.ts.map +1 -1
  43. package/dist/vue/index.d.ts +3 -2
  44. package/dist/vue/index.d.ts.map +1 -1
  45. package/dist/vue/index.js +1 -0
  46. package/dist/vue/index.js.map +1 -1
  47. package/dist/vue/kanban.d.ts +2 -2
  48. package/dist/vue/marquee.d.ts +4 -4
  49. package/dist/vue/menu.d.ts +4 -4
  50. package/dist/vue/number-flow.d.ts +3 -3
  51. package/dist/vue/platform.d.ts +1 -2
  52. package/dist/vue/platform.d.ts.map +1 -1
  53. package/dist/vue/platform.js.map +1 -1
  54. package/dist/vue/props.d.ts +44 -44
  55. package/dist/vue/reveal-state.d.ts +1 -1
  56. package/dist/vue/scheduler.d.ts +10 -10
  57. package/dist/vue/screen-component-props.d.ts +10 -0
  58. package/dist/vue/screen-component-props.d.ts.map +1 -1
  59. package/dist/vue/screen-component-props.js +6 -0
  60. package/dist/vue/screen-component-props.js.map +1 -1
  61. package/dist/vue/scroll-frame.d.ts +29 -6
  62. package/dist/vue/scroll-frame.d.ts.map +1 -1
  63. package/dist/vue/scroll-frame.js +106 -43
  64. package/dist/vue/scroll-frame.js.map +1 -1
  65. package/dist/vue/speed-dial.d.ts +3 -3
  66. package/dist/vue/swipe-actions.d.ts +3 -3
  67. package/dist/vue/swipe-deck.d.ts +3 -3
  68. package/dist/vue/theme-provider.d.ts +17 -2
  69. package/dist/vue/theme-provider.d.ts.map +1 -1
  70. package/dist/vue/theme-provider.js +7 -1
  71. package/dist/vue/theme-provider.js.map +1 -1
  72. package/dist/vue/theme.d.ts +7 -0
  73. package/dist/vue/theme.d.ts.map +1 -1
  74. package/dist/vue/theme.js +23 -19
  75. package/dist/vue/theme.js.map +1 -1
  76. package/dist/vue/time-picker.d.ts +20 -20
  77. package/dist/vue/tour.d.ts +3 -3
  78. package/dist/vue/tree-view.d.ts +3 -3
  79. package/dist/vue/wayfinding-controls.d.ts +1 -1
  80. package/dist/vue/workflows.d.ts +3 -3
  81. package/package.json +1 -1
  82. package/src/avatar.ts +6 -0
  83. package/src/capabilities.ts +148 -82
  84. package/src/experimental-regions.ts +10 -2
  85. package/src/index.ts +2 -7
  86. package/src/vue/component-props.ts +4 -0
  87. package/src/vue/composer.ts +22 -16
  88. package/src/vue/editor-controls.ts +370 -0
  89. package/src/vue/global-components.ts +21 -1
  90. package/src/vue/index.ts +3 -1
  91. package/src/vue/platform.ts +1 -2
  92. package/src/vue/screen-component-props.ts +6 -0
  93. package/src/vue/scroll-frame.ts +140 -54
  94. package/src/vue/theme-provider.ts +14 -1
  95. package/src/vue/theme.ts +31 -18
  96. package/dist/macos-capabilities.generated.d.ts +0 -1738
  97. package/dist/macos-capabilities.generated.d.ts.map +0 -1
  98. package/dist/macos-capabilities.generated.js +0 -4191
  99. package/dist/macos-capabilities.generated.js.map +0 -1
  100. package/src/macos-capabilities.generated.ts +0 -4190
@@ -0,0 +1,370 @@
1
+ import { defineComponent, h, nextTick, ref, type Component, type PropType } from '@vue/runtime-core'
2
+ import type { InputHandle } from '../input.js'
3
+ import { avatarSizes, type AvatarMember } from '../avatar.js'
4
+ import { avatarProps } from './props.js'
5
+ import { useMavisTheme } from './theme.js'
6
+
7
+ const editorProps = {
8
+ id: String,
9
+ label: { type: String, required: true as const },
10
+ placeholder: String,
11
+ disabled: Boolean,
12
+ }
13
+ export const searchBarProps = {
14
+ ...editorProps,
15
+ modelValue: { type: String, default: '' },
16
+ clearLabel: { type: String, default: 'Clear search' },
17
+ cancelLabel: { type: String, default: 'Cancel' },
18
+ showCancel: Boolean,
19
+ }
20
+ export const tagInputProps = {
21
+ ...editorProps,
22
+ modelValue: { type: Array as PropType<readonly string[]>, default: () => [] },
23
+ addLabel: { type: String, default: 'Add tag' },
24
+ removeLabel: { type: String, default: 'Remove' },
25
+ maxTags: Number,
26
+ }
27
+ export const avatarGroupProps = {
28
+ id: String,
29
+ members: { type: Array as PropType<readonly AvatarMember[]>, required: true as const },
30
+ maxVisible: { type: Number, default: 4 },
31
+ size: avatarProps.size,
32
+ }
33
+
34
+ export function createEditorControls(
35
+ ui: {
36
+ Row: Component
37
+ Column: Component
38
+ Input: Component
39
+ Chip: Component
40
+ Button: Component
41
+ Avatar: Component
42
+ },
43
+ platform: 'web' | 'native',
44
+ ) {
45
+ const web = platform === 'web'
46
+ const MSearchBar = defineComponent({
47
+ name: 'MSearchBar',
48
+ props: searchBarProps,
49
+ emits: {
50
+ 'update:modelValue': (_v: string) => true,
51
+ submit: (_v: string) => true,
52
+ clear: () => true,
53
+ cancel: () => true,
54
+ },
55
+ setup(props, { emit, expose }) {
56
+ const editor = ref<InputHandle>()
57
+ const focus = () => editor.value?.focus()
58
+ const blur = () => editor.value?.blur()
59
+ expose({ focus, blur })
60
+ return () =>
61
+ h(
62
+ ui.Row,
63
+ { gap: 'sm', align: 'center' },
64
+ {
65
+ default: () => [
66
+ h(ui.Input, {
67
+ ref: editor,
68
+ id: props.id,
69
+ label: props.label,
70
+ placeholder: props.placeholder,
71
+ width: 0,
72
+ grow: 1,
73
+ modelValue: props.modelValue,
74
+ disabled: props.disabled,
75
+ icon: 'search',
76
+ inputmode: 'search',
77
+ returnKey: 'search',
78
+ trailingAction: props.modelValue
79
+ ? { icon: 'x', label: props.clearLabel }
80
+ : undefined,
81
+ 'onUpdate:modelValue': (value: string) => {
82
+ if (!props.disabled) emit('update:modelValue', value)
83
+ },
84
+ onSubmit: (value: string) => {
85
+ if (!props.disabled) emit('submit', value)
86
+ },
87
+ onAction: () => {
88
+ if (props.disabled || !props.modelValue) return
89
+ emit('update:modelValue', '')
90
+ emit('clear')
91
+ void nextTick(focus)
92
+ },
93
+ }),
94
+ props.showCancel
95
+ ? h(ui.Button, {
96
+ text: props.cancelLabel,
97
+ variant: 'ghost',
98
+ disabled: props.disabled,
99
+ onClick: () => {
100
+ if (!props.disabled) {
101
+ blur()
102
+ emit('cancel')
103
+ }
104
+ },
105
+ })
106
+ : null,
107
+ ],
108
+ },
109
+ )
110
+ },
111
+ })
112
+ const MTagInput = defineComponent({
113
+ name: 'MTagInput',
114
+ props: tagInputProps,
115
+ emits: { 'update:modelValue': (_v: string[]) => true },
116
+ setup(props, { emit, expose }) {
117
+ const draft = ref('')
118
+ const editor = ref<InputHandle>()
119
+ let composing = false
120
+ let editVersion = 0
121
+ const focus = () => editor.value?.focus()
122
+ expose({ focus, blur: () => editor.value?.blur() })
123
+ function add(value: string, finish: boolean, fromEditor = false) {
124
+ if (props.disabled) return
125
+ const parts = value.split(/[,\r\n]+/)
126
+ const tail = finish ? '' : (parts.pop() ?? '')
127
+ const result = [...props.modelValue]
128
+ const seen = new Set(result.map((tag) => tag.trim().toLowerCase()))
129
+ const remaining: string[] = []
130
+ for (const part of parts) {
131
+ const tag = part.trim()
132
+ const key = tag.toLowerCase()
133
+ if (!tag || seen.has(key)) continue
134
+ seen.add(key)
135
+ if (result.length < (props.maxTags ?? Infinity)) result.push(tag)
136
+ else remaining.push(tag)
137
+ }
138
+ const nextDraft = [...remaining, tail].filter(Boolean).join(', ')
139
+ const version = ++editVersion
140
+ // A native paste can add whole tags to an already-empty editor. Give the
141
+ // controlled field the input echo before clearing it, even if the final draft is unchanged.
142
+ if (fromEditor && nextDraft !== value) {
143
+ draft.value = value
144
+ void nextTick(() => {
145
+ if (version === editVersion) draft.value = nextDraft
146
+ })
147
+ } else draft.value = nextDraft
148
+ if (result.length !== props.modelValue.length) emit('update:modelValue', result)
149
+ }
150
+ function remove(index: number) {
151
+ if (!props.disabled && index >= 0)
152
+ emit(
153
+ 'update:modelValue',
154
+ props.modelValue.filter((_, i) => i !== index),
155
+ )
156
+ }
157
+ return () => {
158
+ if (props.maxTags !== undefined && (!Number.isInteger(props.maxTags) || props.maxTags < 0))
159
+ throw new RangeError('maxTags must be a nonnegative integer.')
160
+ const webEvents = web
161
+ ? {
162
+ onCompositionstart: () => {
163
+ composing = true
164
+ },
165
+ onCompositionend: (e: CompositionEvent) => {
166
+ composing = false
167
+ add((e.target as HTMLInputElement).value, false)
168
+ },
169
+ onKeydown: (e: KeyboardEvent) => {
170
+ if (
171
+ e.key === 'Backspace' &&
172
+ !e.repeat &&
173
+ !composing &&
174
+ !e.isComposing &&
175
+ !draft.value &&
176
+ (e.target as HTMLElement).tagName === 'INPUT' &&
177
+ props.modelValue.length &&
178
+ !props.disabled
179
+ ) {
180
+ e.preventDefault()
181
+ remove(props.modelValue.length - 1)
182
+ }
183
+ },
184
+ onPaste: (e: ClipboardEvent) => {
185
+ const field = e.target as HTMLInputElement
186
+ const text = e.clipboardData?.getData('text/plain')
187
+ if (
188
+ field.tagName !== 'INPUT' ||
189
+ !text ||
190
+ !/[,\r\n]/.test(text) ||
191
+ props.disabled ||
192
+ composing
193
+ )
194
+ return
195
+ e.preventDefault()
196
+ add(
197
+ field.value.slice(0, field.selectionStart ?? 0) +
198
+ text +
199
+ field.value.slice(field.selectionEnd ?? field.value.length),
200
+ true,
201
+ )
202
+ },
203
+ }
204
+ : {}
205
+ return h(
206
+ ui.Column,
207
+ { gap: 'sm', ...webEvents },
208
+ {
209
+ default: () => [
210
+ h(ui.Input, {
211
+ ref: editor,
212
+ id: props.id,
213
+ label: props.label,
214
+ placeholder: props.placeholder,
215
+ modelValue: draft.value,
216
+ disabled: props.disabled,
217
+ returnKey: 'done',
218
+ trailingAction: draft.value.trim()
219
+ ? { icon: 'plus', label: props.addLabel }
220
+ : undefined,
221
+ 'onUpdate:modelValue': (text: string) => {
222
+ if (composing) {
223
+ editVersion++
224
+ draft.value = text
225
+ } else
226
+ add(
227
+ text,
228
+ !web && /[,\r\n]/.test(text) && text.length > draft.value.length + 1,
229
+ true,
230
+ )
231
+ },
232
+ onSubmit: (text: string) => add(text, true),
233
+ onAction: () => {
234
+ add(draft.value, true)
235
+ void nextTick(focus)
236
+ },
237
+ }),
238
+ props.modelValue.length
239
+ ? h(
240
+ ui.Row,
241
+ { wrap: true, gap: 'xs' },
242
+ {
243
+ default: () =>
244
+ props.modelValue.map((tag, i) =>
245
+ h(ui.Chip, {
246
+ key: tag,
247
+ label: tag,
248
+ removable: true,
249
+ removeLabel: props.removeLabel + ' ' + tag,
250
+ disabled: props.disabled,
251
+ onRemove: () => remove(i),
252
+ }),
253
+ ),
254
+ },
255
+ )
256
+ : null,
257
+ ],
258
+ },
259
+ )
260
+ }
261
+ },
262
+ })
263
+ const MAvatarGroup = defineComponent({
264
+ name: 'MAvatarGroup',
265
+ props: avatarGroupProps,
266
+ setup(props) {
267
+ const { theme } = useMavisTheme()
268
+ return () => {
269
+ if (!Number.isInteger(props.maxVisible) || props.maxVisible < 1)
270
+ throw new RangeError('maxVisible must be a positive integer.')
271
+ const seen = new Set<string>()
272
+ for (const person of props.members) {
273
+ if (!person.id || seen.has(person.id))
274
+ throw new TypeError('Avatar members require unique ids.')
275
+ seen.add(person.id)
276
+ }
277
+ const visible = props.members.slice(0, props.maxVisible)
278
+ const extra = props.members.length - visible.length
279
+ const size = avatarSizes[props.size]
280
+ const stride = Math.ceil(size * 0.82)
281
+ const count = visible.length + Number(extra > 0)
282
+ const width = count ? size + (count - 1) * stride : 0
283
+ const colors = theme.value.colors
284
+ const cell = (index: number) =>
285
+ web
286
+ ? {
287
+ position: 'absolute',
288
+ left: index * stride + 'px',
289
+ top: 0,
290
+ width: size + 'px',
291
+ height: size + 'px',
292
+ borderRadius: '50%',
293
+ boxShadow: '0 0 0 2px ' + colors.surface,
294
+ }
295
+ : {
296
+ width: size,
297
+ height: size,
298
+ borderRadius: size / 2,
299
+ borderWidth: 2,
300
+ borderColor: colors.surface,
301
+ backgroundColor: colors.surface,
302
+ clipToBounds: true,
303
+ }
304
+ const cells = visible.map((person, i) =>
305
+ h(
306
+ web ? 'span' : 'GridLayout',
307
+ {
308
+ key: 'member:' + person.id,
309
+ ...(!web ? { left: i * stride, top: 0 } : {}),
310
+ style: cell(i),
311
+ },
312
+ [h(ui.Avatar, { name: person.name, src: person.src, size: props.size })],
313
+ ),
314
+ )
315
+ if (extra)
316
+ cells.push(
317
+ h(
318
+ web ? 'span' : 'Label',
319
+ {
320
+ key: 'overflow',
321
+ ...(web
322
+ ? {}
323
+ : {
324
+ left: visible.length * stride,
325
+ top: 0,
326
+ text: '+' + extra,
327
+ textAlignment: 'center',
328
+ verticalTextAlignment: 'middle',
329
+ }),
330
+ style: {
331
+ ...cell(visible.length),
332
+ ...(web
333
+ ? {
334
+ display: 'grid',
335
+ placeItems: 'center',
336
+ fontSize: Math.round(size * 0.32) + 'px',
337
+ }
338
+ : { fontSize: Math.round(size * 0.32) }),
339
+ fontWeight: '600',
340
+ color: colors.onPrimary,
341
+ backgroundColor: colors.primary,
342
+ },
343
+ },
344
+ web ? '+' + extra : undefined,
345
+ ),
346
+ )
347
+ return h(
348
+ web ? 'span' : 'AbsoluteLayout',
349
+ {
350
+ id: props.id,
351
+ ...(web
352
+ ? {
353
+ class: 'm-avatar-group',
354
+ style: {
355
+ position: 'relative',
356
+ display: 'inline-block',
357
+ width: width + 'px',
358
+ height: size + 'px',
359
+ alignSelf: 'flex-start',
360
+ },
361
+ }
362
+ : { width, height: size, horizontalAlignment: 'left' }),
363
+ },
364
+ cells,
365
+ )
366
+ }
367
+ },
368
+ })
369
+ return { MTagInput, MSearchBar, MAvatarGroup }
370
+ }
@@ -20,6 +20,9 @@ type InputEvents = {
20
20
 
21
21
  /** Additional input attributes supplied by a renderer, without DOM dependencies in core. */
22
22
  export interface InputPlatformAttributes {}
23
+
24
+ /** Action attributes supplied by the card renderer. */
25
+ export interface CardPlatformAttributes {}
23
26
  type SheetEvents = {
24
27
  'onUpdate:open'?: (value: boolean) => void
25
28
  onClose?: (reason: SheetCloseReason) => void
@@ -147,6 +150,19 @@ declare module '@vue/runtime-core' {
147
150
  onClose?: (reason: string) => void
148
151
  }
149
152
  >
153
+ MAvatarGroup: DefineComponent<ComponentProps['MAvatarGroup']>
154
+ MSearchBar: DefineComponent<
155
+ ComponentProps['MSearchBar'] &
156
+ Pick<InputEvents, 'onUpdate:modelValue' | 'onSubmit'> & {
157
+ onClear?: () => void
158
+ onCancel?: () => void
159
+ },
160
+ InputHandle
161
+ >
162
+ MTagInput: DefineComponent<
163
+ ComponentProps['MTagInput'] & { 'onUpdate:modelValue'?: (tags: string[]) => void },
164
+ InputHandle
165
+ >
150
166
  MComposer: DefineComponent<
151
167
  ComponentProps['MComposer'] &
152
168
  Omit<InputEvents, 'onSubmit'> & {
@@ -163,7 +179,9 @@ declare module '@vue/runtime-core' {
163
179
  > & {
164
180
  new (): {
165
181
  scrollToTop(animated?: boolean): void
182
+ preserveAnchor(change: () => void | Promise<void>): Promise<void>
166
183
  $slots: {
184
+ item?: (scope: { itemKey: string; index: number }) => unknown
167
185
  default?: () => unknown
168
186
  artwork?: () => unknown
169
187
  leading?: () => unknown
@@ -181,7 +199,9 @@ declare module '@vue/runtime-core' {
181
199
  new (): {
182
200
  refresh(): Promise<boolean>
183
201
  cancel(): void
202
+ preserveAnchor(change: () => void | Promise<void>): Promise<void>
184
203
  $slots: {
204
+ item?: (scope: { itemKey: string; index: number }) => unknown
185
205
  default?: (scope: {
186
206
  state: import('../screen-components.js').RefreshState
187
207
  refresh(): Promise<boolean>
@@ -380,7 +400,7 @@ declare module '@vue/runtime-core' {
380
400
  ComponentProps['MLink'] & Action & { onError?: (error: unknown) => void }
381
401
  >
382
402
  MBox: DefineComponent<ComponentProps['MBox']>
383
- MCard: DefineComponent<ComponentProps['MCard'] & Action>
403
+ MCard: DefineComponent<ComponentProps['MCard'] & Action & CardPlatformAttributes>
384
404
  MText: DefineComponent<ComponentProps['MText']>
385
405
  MButton: DefineComponent<ComponentProps['MButton'] & Action> & {
386
406
  new (): {
package/src/vue/index.ts CHANGED
@@ -21,11 +21,12 @@ export type {
21
21
  AppearanceMode,
22
22
  AppearanceSource,
23
23
  ThemeContextOptions,
24
+ ThemePair,
24
25
  } from './theme.js'
25
26
  export { layoutDirection, useDefaultShrink, useLayoutShrink } from './layout-context.js'
26
27
  export { textContent } from './text-content.js'
27
28
  export type {} from './global-components.js'
28
- export type { InputPlatformAttributes } from './global-components.js'
29
+ export type { CardPlatformAttributes, InputPlatformAttributes } from './global-components.js'
29
30
  export {
30
31
  boxProps,
31
32
  motionBoxProps,
@@ -135,6 +136,7 @@ export * from './screen-component-props.js'
135
136
  export * from './scroll-frame.js'
136
137
  export * from './animated-text.js'
137
138
  export * from './composer.js'
139
+ export * from './editor-controls.js'
138
140
  export * from './speed-dial.js'
139
141
  export * from './pin-input.js'
140
142
 
@@ -7,8 +7,7 @@ import {
7
7
  } from '@vue/runtime-core'
8
8
 
9
9
  /**
10
- * `macos` is the SwiftUI app generated from shared screens. No Vue renderer runs there, so the
11
- * Web and NativeScript renderers never report it: the Mac generator answers for it instead.
10
+ * The web and mobile renderers supply their own platform explicitly.
12
11
  */
13
12
  export type MavisPlatform = 'web' | 'ios' | 'android' | 'macos'
14
13
  export type MavisPlatformTarget = MavisPlatform | 'native'
@@ -62,7 +62,12 @@ export const speedDialProps = {
62
62
  closeLabel: { type: String, default: 'Close actions' },
63
63
  direction: { type: String as PropType<'up' | 'down'>, default: 'up' },
64
64
  }
65
+ const scrollRows = {
66
+ itemKeys: { type: Array as PropType<readonly string[]>, default: () => [] },
67
+ sourceKey: [String, Number],
68
+ }
65
69
  export const refreshControlProps = {
70
+ ...scrollRows,
66
71
  id: String,
67
72
  label,
68
73
  refresh: { type: Function as PropType<RefreshAction>, required: true as const },
@@ -77,6 +82,7 @@ export const refreshControlProps = {
77
82
  cancelLabel: { type: String, default: 'Cancel refresh' },
78
83
  }
79
84
  export const collapsibleHeaderProps = {
85
+ ...scrollRows,
80
86
  id: String,
81
87
  title: label,
82
88
  subtitle: String,