@getcortexlabs/mavis-core 0.1.0-rc.11.1 → 0.1.0-rc.12.1

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 (167) hide show
  1. package/README.md +2 -2
  2. package/dist/advanced-collections.d.ts +74 -0
  3. package/dist/advanced-collections.d.ts.map +1 -0
  4. package/dist/advanced-collections.js +129 -0
  5. package/dist/advanced-collections.js.map +1 -0
  6. package/dist/capabilities.d.ts +7 -7
  7. package/dist/capabilities.d.ts.map +1 -1
  8. package/dist/capabilities.js +29 -4
  9. package/dist/capabilities.js.map +1 -1
  10. package/dist/creative-controls.d.ts +47 -0
  11. package/dist/creative-controls.d.ts.map +1 -0
  12. package/dist/creative-controls.js +112 -0
  13. package/dist/creative-controls.js.map +1 -0
  14. package/dist/dashboard.d.ts +72 -0
  15. package/dist/dashboard.d.ts.map +1 -0
  16. package/dist/dashboard.js +115 -0
  17. package/dist/dashboard.js.map +1 -0
  18. package/dist/image-crop.d.ts +49 -0
  19. package/dist/image-crop.d.ts.map +1 -0
  20. package/dist/image-crop.js +71 -0
  21. package/dist/image-crop.js.map +1 -0
  22. package/dist/index.d.ts +6 -0
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +6 -0
  25. package/dist/index.js.map +1 -1
  26. package/dist/scheduler.d.ts +45 -0
  27. package/dist/scheduler.d.ts.map +1 -0
  28. package/dist/scheduler.js +142 -0
  29. package/dist/scheduler.js.map +1 -0
  30. package/dist/screen-components.d.ts +45 -0
  31. package/dist/screen-components.d.ts.map +1 -0
  32. package/dist/screen-components.js +23 -0
  33. package/dist/screen-components.js.map +1 -0
  34. package/dist/vue/advanced-collections.d.ts +486 -0
  35. package/dist/vue/advanced-collections.d.ts.map +1 -0
  36. package/dist/vue/advanced-collections.js +476 -0
  37. package/dist/vue/advanced-collections.js.map +1 -0
  38. package/dist/vue/advanced-props.d.ts +398 -0
  39. package/dist/vue/advanced-props.d.ts.map +1 -0
  40. package/dist/vue/advanced-props.js +128 -0
  41. package/dist/vue/advanced-props.js.map +1 -0
  42. package/dist/vue/animated-text.d.ts +101 -0
  43. package/dist/vue/animated-text.d.ts.map +1 -0
  44. package/dist/vue/animated-text.js +56 -0
  45. package/dist/vue/animated-text.js.map +1 -0
  46. package/dist/vue/chart.d.ts +1 -1
  47. package/dist/vue/command-palette.d.ts +3 -3
  48. package/dist/vue/component-props.d.ts +1045 -0
  49. package/dist/vue/component-props.d.ts.map +1 -1
  50. package/dist/vue/component-props.js +29 -0
  51. package/dist/vue/component-props.js.map +1 -1
  52. package/dist/vue/composer.d.ts +159 -0
  53. package/dist/vue/composer.d.ts.map +1 -0
  54. package/dist/vue/composer.js +142 -0
  55. package/dist/vue/composer.js.map +1 -0
  56. package/dist/vue/configurator.d.ts +5 -5
  57. package/dist/vue/creative-controls.d.ts +328 -0
  58. package/dist/vue/creative-controls.d.ts.map +1 -0
  59. package/dist/vue/creative-controls.js +396 -0
  60. package/dist/vue/creative-controls.js.map +1 -0
  61. package/dist/vue/creative-props.d.ts +260 -0
  62. package/dist/vue/creative-props.d.ts.map +1 -0
  63. package/dist/vue/creative-props.js +92 -0
  64. package/dist/vue/creative-props.js.map +1 -0
  65. package/dist/vue/dashboard-charts.d.ts +240 -0
  66. package/dist/vue/dashboard-charts.d.ts.map +1 -0
  67. package/dist/vue/dashboard-charts.js +263 -0
  68. package/dist/vue/dashboard-charts.js.map +1 -0
  69. package/dist/vue/dashboard-effects.d.ts +211 -0
  70. package/dist/vue/dashboard-effects.d.ts.map +1 -0
  71. package/dist/vue/dashboard-effects.js +235 -0
  72. package/dist/vue/dashboard-effects.js.map +1 -0
  73. package/dist/vue/dashboard-props.d.ts +244 -0
  74. package/dist/vue/dashboard-props.d.ts.map +1 -0
  75. package/dist/vue/dashboard-props.js +94 -0
  76. package/dist/vue/dashboard-props.js.map +1 -0
  77. package/dist/vue/date-picker.d.ts +8 -8
  78. package/dist/vue/discovery-controls.d.ts +2 -2
  79. package/dist/vue/global-components.d.ts +152 -0
  80. package/dist/vue/global-components.d.ts.map +1 -1
  81. package/dist/vue/image-cropper.d.ts +187 -0
  82. package/dist/vue/image-cropper.d.ts.map +1 -0
  83. package/dist/vue/image-cropper.js +310 -0
  84. package/dist/vue/image-cropper.js.map +1 -0
  85. package/dist/vue/index.d.ts +20 -0
  86. package/dist/vue/index.d.ts.map +1 -1
  87. package/dist/vue/index.js +20 -0
  88. package/dist/vue/index.js.map +1 -1
  89. package/dist/vue/kanban.d.ts +150 -0
  90. package/dist/vue/kanban.d.ts.map +1 -0
  91. package/dist/vue/kanban.js +267 -0
  92. package/dist/vue/kanban.js.map +1 -0
  93. package/dist/vue/marquee.d.ts +96 -0
  94. package/dist/vue/marquee.d.ts.map +1 -0
  95. package/dist/vue/marquee.js +186 -0
  96. package/dist/vue/marquee.js.map +1 -0
  97. package/dist/vue/menu.d.ts +2 -2
  98. package/dist/vue/navigation-controls.d.ts +1 -1
  99. package/dist/vue/pin-cell.d.ts +14 -0
  100. package/dist/vue/pin-cell.d.ts.map +1 -0
  101. package/dist/vue/pin-cell.js +19 -0
  102. package/dist/vue/pin-cell.js.map +1 -0
  103. package/dist/vue/pin-input.d.ts +14 -0
  104. package/dist/vue/pin-input.d.ts.map +1 -0
  105. package/dist/vue/pin-input.js +23 -0
  106. package/dist/vue/pin-input.js.map +1 -0
  107. package/dist/vue/scheduler.d.ts +229 -0
  108. package/dist/vue/scheduler.d.ts.map +1 -0
  109. package/dist/vue/scheduler.js +363 -0
  110. package/dist/vue/scheduler.js.map +1 -0
  111. package/dist/vue/screen-component-props.d.ts +236 -0
  112. package/dist/vue/screen-component-props.d.ts.map +1 -0
  113. package/dist/vue/screen-component-props.js +90 -0
  114. package/dist/vue/screen-component-props.js.map +1 -0
  115. package/dist/vue/scroll-frame.d.ts +223 -0
  116. package/dist/vue/scroll-frame.d.ts.map +1 -0
  117. package/dist/vue/scroll-frame.js +346 -0
  118. package/dist/vue/scroll-frame.js.map +1 -0
  119. package/dist/vue/speed-dial.d.ts +73 -0
  120. package/dist/vue/speed-dial.d.ts.map +1 -0
  121. package/dist/vue/speed-dial.js +78 -0
  122. package/dist/vue/speed-dial.js.map +1 -0
  123. package/dist/vue/swipe-actions.d.ts +1 -1
  124. package/dist/vue/swipe-deck.d.ts +120 -0
  125. package/dist/vue/swipe-deck.d.ts.map +1 -0
  126. package/dist/vue/swipe-deck.js +229 -0
  127. package/dist/vue/swipe-deck.js.map +1 -0
  128. package/dist/vue/time-picker.d.ts +6 -6
  129. package/dist/vue/tour.d.ts +120 -0
  130. package/dist/vue/tour.d.ts.map +1 -0
  131. package/dist/vue/tour.js +165 -0
  132. package/dist/vue/tour.js.map +1 -0
  133. package/dist/vue/tree-view.d.ts +1 -1
  134. package/dist/vue/wayfinding-controls.d.ts +2 -2
  135. package/dist/vue/workflows.d.ts +3 -3
  136. package/package.json +1 -1
  137. package/src/advanced-collections.ts +199 -0
  138. package/src/capabilities.ts +30 -4
  139. package/src/creative-controls.ts +169 -0
  140. package/src/dashboard.ts +164 -0
  141. package/src/image-crop.ts +125 -0
  142. package/src/index.ts +11 -0
  143. package/src/scheduler.ts +194 -0
  144. package/src/screen-components.ts +59 -0
  145. package/src/vue/advanced-collections.ts +679 -0
  146. package/src/vue/advanced-props.ts +144 -0
  147. package/src/vue/animated-text.ts +72 -0
  148. package/src/vue/component-props.ts +61 -0
  149. package/src/vue/composer.ts +192 -0
  150. package/src/vue/creative-controls.ts +524 -0
  151. package/src/vue/creative-props.ts +94 -0
  152. package/src/vue/dashboard-charts.ts +346 -0
  153. package/src/vue/dashboard-effects.ts +304 -0
  154. package/src/vue/dashboard-props.ts +95 -0
  155. package/src/vue/global-components.ts +162 -0
  156. package/src/vue/image-cropper.ts +413 -0
  157. package/src/vue/index.ts +28 -0
  158. package/src/vue/kanban.ts +360 -0
  159. package/src/vue/marquee.ts +248 -0
  160. package/src/vue/pin-cell.ts +26 -0
  161. package/src/vue/pin-input.ts +31 -0
  162. package/src/vue/scheduler.ts +505 -0
  163. package/src/vue/screen-component-props.ts +92 -0
  164. package/src/vue/scroll-frame.ts +429 -0
  165. package/src/vue/speed-dial.ts +108 -0
  166. package/src/vue/swipe-deck.ts +277 -0
  167. package/src/vue/tour.ts +239 -0
@@ -0,0 +1,144 @@
1
+ import type { PropType } from '@vue/runtime-core'
2
+ import type {
3
+ TreeSelectNode,
4
+ MasonryItem,
5
+ HeatmapValue,
6
+ MavisNotification,
7
+ } from '../advanced-collections.js'
8
+ import type { ImageCrop, CropExportOptions } from '../image-crop.js'
9
+ import type { CivilDate } from '../date.js'
10
+ import type { SchedulerEvent, SchedulerDisambiguation } from '../scheduler.js'
11
+ import { spacingProp } from './props.js'
12
+ const label = { type: String, required: true as const },
13
+ animated = { type: Boolean, default: true }
14
+ export const treeSelectProps = {
15
+ id: String,
16
+ label,
17
+ nodes: { type: Array as PropType<readonly TreeSelectNode[]>, required: true as const },
18
+ modelValue: { type: Array as PropType<readonly string[]>, default: () => [] },
19
+ expanded: { type: Array as PropType<readonly string[]>, default: () => [] },
20
+ multiple: Boolean,
21
+ disabled: Boolean,
22
+ animated,
23
+ placeholder: { type: String, default: 'Choose items' },
24
+ searchLabel: { type: String, default: 'Search' },
25
+ clearLabel: { type: String, default: 'Clear selection' },
26
+ emptyLabel: { type: String, default: 'No matches' },
27
+ expandLabel: { type: String, default: 'Expand' },
28
+ collapseLabel: { type: String, default: 'Collapse' },
29
+ }
30
+ export const masonryProps = {
31
+ id: String,
32
+ label,
33
+ items: { type: Array as PropType<readonly MasonryItem[]>, required: true as const },
34
+ minColumnWidth: { type: Number, default: 220 },
35
+ columns: { type: Number, default: 4 },
36
+ gap: { ...spacingProp, default: 'md' },
37
+ animated,
38
+ emptyLabel: { type: String, default: 'No items' },
39
+ }
40
+ export const heatmapProps = {
41
+ id: String,
42
+ label,
43
+ start: { type: String as PropType<CivilDate>, required: true as const },
44
+ end: { type: String as PropType<CivilDate>, required: true as const },
45
+ values: { type: Array as PropType<readonly HeatmapValue[]>, required: true as const },
46
+ modelValue: { type: String as PropType<CivilDate | null>, default: null },
47
+ colors: {
48
+ type: Array as PropType<readonly string[]>,
49
+ default: () => ['#E6E4EB', '#C6ABCD', '#9B6AA9', '#704080', '#4C245C'],
50
+ },
51
+ cellSize: { type: Number, default: 40 },
52
+ weekStartsOn: { type: Number as PropType<0 | 1>, default: 1 },
53
+ animated,
54
+ disabled: Boolean,
55
+ missingLabel: { type: String, default: 'No data' },
56
+ dataLabel: { type: String, default: 'View data' },
57
+ lessLabel: { type: String, default: 'Less' },
58
+ moreLabel: { type: String, default: 'More' },
59
+ formatValue: Function as PropType<(value: number) => string>,
60
+ }
61
+ export const notificationCenterProps = {
62
+ id: String,
63
+ label,
64
+ modelValue: { type: Array as PropType<readonly MavisNotification[]>, required: true as const },
65
+ disabled: Boolean,
66
+ animated,
67
+ filter: { type: String as PropType<'all' | 'unread'>, default: 'all' },
68
+ allLabel: { type: String, default: 'All' },
69
+ unreadLabel: { type: String, default: 'Unread' },
70
+ readLabel: { type: String, default: 'Mark as read' },
71
+ unreadActionLabel: { type: String, default: 'Mark as unread' },
72
+ readAllLabel: { type: String, default: 'Mark all as read' },
73
+ dismissLabel: { type: String, default: 'Dismiss' },
74
+ emptyLabel: { type: String, default: 'You are all caught up' },
75
+ ungroupedLabel: { type: String, default: 'Notifications' },
76
+ }
77
+ export const imageCropperProps = {
78
+ id: String,
79
+ label,
80
+ src: { type: String, required: true as const },
81
+ modelValue: { type: Object as PropType<ImageCrop | null>, default: null },
82
+ aspectRatio: { type: Number, default: 1 },
83
+ animated,
84
+ disabled: Boolean,
85
+ output: {
86
+ type: Object as PropType<CropExportOptions>,
87
+ default: () => ({ mimeType: 'image/png', quality: 0.92 }),
88
+ },
89
+ zoomLabel: { type: String, default: 'Zoom' },
90
+ rotateLabel: { type: String, default: 'Rotate clockwise' },
91
+ resetLabel: { type: String, default: 'Reset' },
92
+ exportLabel: { type: String, default: 'Export image' },
93
+ loadingLabel: { type: String, default: 'Loading image' },
94
+ moveLabel: { type: String, default: 'Move image' },
95
+ leftLabel: { type: String, default: 'Move left' },
96
+ rightLabel: { type: String, default: 'Move right' },
97
+ upLabel: { type: String, default: 'Move up' },
98
+ downLabel: { type: String, default: 'Move down' },
99
+ }
100
+ export const schedulerProps = {
101
+ id: String,
102
+ label,
103
+ modelValue: { type: Array as PropType<readonly SchedulerEvent[]>, required: true as const },
104
+ date: { type: String as PropType<CivilDate>, required: true as const },
105
+ timeZone: { type: String, required: true as const },
106
+ days: { type: Number as PropType<1 | 7>, default: 7 },
107
+ startHour: { type: Number, default: 8 },
108
+ endHour: { type: Number, default: 19 },
109
+ slotMinutes: { type: Number, default: 15 },
110
+ hourHeight: { type: Number, default: 80 },
111
+ dayWidth: { type: Number, default: 180 },
112
+ animated,
113
+ disabled: Boolean,
114
+ disambiguation: { type: String as PropType<SchedulerDisambiguation>, default: 'reject' },
115
+ previousLabel: { type: String, default: 'Previous' },
116
+ nextLabel: { type: String, default: 'Next' },
117
+ moveLabel: { type: String, default: 'Move event' },
118
+ resizeLabel: { type: String, default: 'Resize event' },
119
+ earlierLabel: { type: String, default: 'Earlier' },
120
+ laterLabel: { type: String, default: 'Later' },
121
+ previousDayLabel: { type: String, default: 'Previous day' },
122
+ nextDayLabel: { type: String, default: 'Next day' },
123
+ shorterLabel: { type: String, default: 'Shorter' },
124
+ longerLabel: { type: String, default: 'Longer' },
125
+ emptyLabel: { type: String, default: 'No events' },
126
+ }
127
+ export const advancedCellProps = {
128
+ x: { type: Number, default: 0 },
129
+ y: { type: Number, default: 0 },
130
+ width: { type: Number, required: true as const },
131
+ height: Number,
132
+ measure: Boolean,
133
+ }
134
+ export const advancedCanvasProps = {
135
+ height: { type: Number, required: true as const },
136
+ width: Number,
137
+ }
138
+ export const advancedGestureProps = { label, disabled: Boolean }
139
+ export interface AdvancedGesture {
140
+ phase: 'start' | 'move' | 'end' | 'cancel'
141
+ x: number
142
+ y: number
143
+ scale: number
144
+ }
@@ -0,0 +1,72 @@
1
+ import {
2
+ defineComponent,
3
+ h,
4
+ markRaw,
5
+ mergeProps,
6
+ onScopeDispose,
7
+ watch,
8
+ type Component,
9
+ } from '@vue/runtime-core'
10
+ import { createMotionSurface, type MotionPlayback } from '../experimental.js'
11
+ import { animatedTextProps } from './screen-component-props.js'
12
+
13
+ export function createAnimatedText(Text: Component) {
14
+ return defineComponent({
15
+ name: 'MAnimatedText',
16
+ inheritAttrs: false,
17
+ props: animatedTextProps,
18
+ setup(props, { attrs, expose }) {
19
+ const surface = markRaw(createMotionSurface())
20
+ let playback: MotionPlayback | undefined
21
+ const validate = () => {
22
+ if (
23
+ !Number.isFinite(props.duration) ||
24
+ props.duration <= 0 ||
25
+ !Number.isFinite(props.stagger) ||
26
+ props.stagger < 0 ||
27
+ !Number.isFinite(props.distance) ||
28
+ !['word', 'letter'].includes(props.by)
29
+ )
30
+ throw new RangeError(
31
+ 'MAnimatedText requires a positive duration, nonnegative stagger and finite distance.',
32
+ )
33
+ }
34
+ function play() {
35
+ validate()
36
+ playback?.stop()
37
+ if (surface.available && props.animated && props.text)
38
+ playback = surface.animateText({
39
+ by: props.by,
40
+ duration: props.duration,
41
+ stagger: props.stagger,
42
+ y: props.distance,
43
+ })
44
+ }
45
+ onScopeDispose(
46
+ surface.use(() => {
47
+ if (props.appear) play()
48
+ return () => {
49
+ playback?.stop()
50
+ playback = undefined
51
+ }
52
+ }),
53
+ )
54
+ watch(() => [props.text, props.replayKey, props.by, props.animated], play, { flush: 'post' })
55
+ onScopeDispose(() => playback?.stop())
56
+ expose({ replay: play })
57
+ return () => {
58
+ validate()
59
+ return h(
60
+ Text,
61
+ mergeProps(attrs, {
62
+ id: props.id,
63
+ text: props.text,
64
+ variant: props.variant,
65
+ tone: props.tone,
66
+ motionSurface: surface,
67
+ }),
68
+ )
69
+ }
70
+ },
71
+ })
72
+ }
@@ -1,3 +1,36 @@
1
+ import {
2
+ treeSelectProps,
3
+ masonryProps,
4
+ heatmapProps,
5
+ imageCropperProps,
6
+ schedulerProps,
7
+ notificationCenterProps,
8
+ } from './advanced-props.js'
9
+ import {
10
+ kanbanProps,
11
+ donutChartProps,
12
+ sparklineProps,
13
+ gradientBackgroundProps,
14
+ particleFieldProps,
15
+ confettiProps,
16
+ } from './dashboard-props.js'
17
+ import {
18
+ colorPickerProps,
19
+ swipeDeckProps,
20
+ gaugeProps,
21
+ tourProps,
22
+ tourTargetProps,
23
+ transferListProps,
24
+ marqueeProps,
25
+ } from './creative-props.js'
26
+ import {
27
+ collapsibleHeaderProps,
28
+ refreshControlProps,
29
+ composerProps,
30
+ speedDialProps,
31
+ pinInputProps,
32
+ animatedTextProps,
33
+ } from './screen-component-props.js'
1
34
  import {
2
35
  sortableListProps,
3
36
  swipeActionsProps,
@@ -42,6 +75,34 @@ import { formGroupProps, formErrorsProps, stepsProps, paginationProps } from './
42
75
  /** Complete registry, kept separate from the primitives used to compose controls. */
43
76
  export const componentProps = {
44
77
  ...foundationProps,
78
+ MTreeSelect: treeSelectProps,
79
+ MMasonry: masonryProps,
80
+ MHeatmap: heatmapProps,
81
+ MImageCropper: imageCropperProps,
82
+ MScheduler: schedulerProps,
83
+ MNotificationCenter: notificationCenterProps,
84
+ MKanban: kanbanProps,
85
+ MDonutChart: donutChartProps,
86
+ MSparkline: sparklineProps,
87
+ MGradientBackground: gradientBackgroundProps,
88
+ MParticleField: particleFieldProps,
89
+ MConfetti: confettiProps,
90
+
91
+ MColorPicker: colorPickerProps,
92
+ MSwipeDeck: swipeDeckProps,
93
+ MGauge: gaugeProps,
94
+ MTour: tourProps,
95
+ MTourTarget: tourTargetProps,
96
+ MTransferList: transferListProps,
97
+ MMarquee: marqueeProps,
98
+
99
+ MCollapsibleHeader: collapsibleHeaderProps,
100
+ MRefreshControl: refreshControlProps,
101
+ MComposer: composerProps,
102
+ MSpeedDial: speedDialProps,
103
+ MPinInput: pinInputProps,
104
+ MAnimatedText: animatedTextProps,
105
+
45
106
  MSortableList: sortableListProps,
46
107
  MSwipeActions: swipeActionsProps,
47
108
  MNumberFlow: numberFlowProps,
@@ -0,0 +1,192 @@
1
+ import {
2
+ computed,
3
+ defineComponent,
4
+ h,
5
+ markRaw,
6
+ mergeProps,
7
+ onScopeDispose,
8
+ ref,
9
+ watch,
10
+ type Component,
11
+ } from '@vue/runtime-core'
12
+ import { createMotionSurface, type MotionBinding } from '../experimental.js'
13
+ import type { ComposerMessage } from '../screen-components.js'
14
+ import { composerProps } from './screen-component-props.js'
15
+ import { useComponentLayout } from './component-motion.js'
16
+
17
+ export function createComposer(
18
+ ui: {
19
+ Box: Component
20
+ Card: Component
21
+ Row: Component
22
+ Column: Component
23
+ Input: Component
24
+ Button: Component
25
+ Chip: Component
26
+ Text: Component
27
+ },
28
+ platform: 'web' | 'native',
29
+ ) {
30
+ return defineComponent({
31
+ name: 'MComposer',
32
+ inheritAttrs: false,
33
+ props: composerProps,
34
+ emits: {
35
+ 'update:modelValue': (_v: string) => true,
36
+ 'update:attachments': (_v: unknown[]) => true,
37
+ submit: (_message: ComposerMessage) => true,
38
+ attach: () => true,
39
+ focus: () => true,
40
+ blur: () => true,
41
+ },
42
+ setup(props, { attrs, emit, expose, slots }) {
43
+ const editor = ref<{ focus(): void; blur(): void }>()
44
+ const surface = markRaw(createMotionSurface())
45
+ const layout = useComponentLayout(() => props.attachments.map((a) => a.id))
46
+ const blocked = computed(() => props.disabled || props.readonly || props.loading)
47
+ const canSend = computed(
48
+ () => !blocked.value && Boolean(props.modelValue.trim() || props.attachments.length),
49
+ )
50
+ let follow: MotionBinding | undefined
51
+ function followKeyboard() {
52
+ follow?.dispose()
53
+ follow = undefined
54
+ if (props.followKeyboard && surface.available)
55
+ follow = surface.followKeyboard({ offset: props.keyboardOffset })
56
+ }
57
+ onScopeDispose(
58
+ surface.use(() => {
59
+ followKeyboard()
60
+ return () => {
61
+ follow?.dispose()
62
+ follow = undefined
63
+ }
64
+ }),
65
+ )
66
+ watch(() => [props.followKeyboard, props.keyboardOffset], followKeyboard, { flush: 'post' })
67
+ const submit = () => {
68
+ if (canSend.value)
69
+ emit('submit', {
70
+ text: props.modelValue,
71
+ attachments: props.attachments.map((a) => ({ ...a })),
72
+ })
73
+ }
74
+ expose({ focus: () => editor.value?.focus(), blur: () => editor.value?.blur() })
75
+ return () => {
76
+ const ids = new Set(props.attachments.map((a) => a.id))
77
+ if (ids.size !== props.attachments.length)
78
+ throw new TypeError('Composer attachments require unique ids.')
79
+ return h(
80
+ ui.Box,
81
+ mergeProps(attrs, {
82
+ motionSurface: surface,
83
+ ...(platform === 'web'
84
+ ? {
85
+ class: 'm-composer',
86
+ role: 'group',
87
+ 'aria-label': props.label,
88
+ onKeydown: (e: KeyboardEvent) => {
89
+ if (
90
+ props.shortcut &&
91
+ e.key === 'Enter' &&
92
+ (e.ctrlKey || e.metaKey) &&
93
+ !e.isComposing &&
94
+ e.keyCode !== 229 &&
95
+ !e.defaultPrevented
96
+ ) {
97
+ e.preventDefault()
98
+ submit()
99
+ }
100
+ },
101
+ }
102
+ : {}),
103
+ }),
104
+ {
105
+ default: () =>
106
+ h(
107
+ ui.Card,
108
+ { padding: 'md', gap: 'sm', motionRegion: layout },
109
+ {
110
+ default: () => [
111
+ h(ui.Input, {
112
+ ref: editor,
113
+ id: props.id,
114
+ label: props.label,
115
+ modelValue: props.modelValue,
116
+ multiline: true,
117
+ rows: props.rows,
118
+ maxLength: props.maxLength,
119
+ placeholder: props.placeholder,
120
+ error: props.error,
121
+ disabled: props.disabled,
122
+ readonly: props.readonly || props.loading,
123
+ 'onUpdate:modelValue': (value: string) => {
124
+ if (!blocked.value) emit('update:modelValue', value)
125
+ },
126
+ onFocus: () => emit('focus'),
127
+ onBlur: () => emit('blur'),
128
+ }),
129
+ props.attachments.length
130
+ ? h(
131
+ ui.Row,
132
+ { gap: 'xs', wrap: true },
133
+ {
134
+ default: () =>
135
+ props.attachments.map((a) =>
136
+ h(ui.Chip, {
137
+ key: a.id,
138
+ label: a.name,
139
+ removable: true,
140
+ removeLabel: `${props.removeLabel}: ${a.name}`,
141
+ disabled: blocked.value,
142
+ onRemove: () => {
143
+ if (!blocked.value)
144
+ emit(
145
+ 'update:attachments',
146
+ props.attachments.filter((item) => item.id !== a.id),
147
+ )
148
+ },
149
+ }),
150
+ ),
151
+ },
152
+ )
153
+ : null,
154
+ slots.default?.(),
155
+ h(
156
+ ui.Row,
157
+ { gap: 'sm', align: 'center', justify: 'between', wrap: true },
158
+ {
159
+ default: () => [
160
+ props.attachable
161
+ ? h(ui.Button, {
162
+ text: props.attachLabel,
163
+ icon: 'paperclip',
164
+ variant: 'ghost',
165
+ size: 'sm',
166
+ disabled: blocked.value,
167
+ onClick: () => {
168
+ if (!blocked.value) emit('attach')
169
+ },
170
+ })
171
+ : null,
172
+ h(ui.Button, {
173
+ text: props.sendLabel,
174
+ icon: 'arrow-up',
175
+ size: 'sm',
176
+ disabled: !canSend.value && !props.loading,
177
+ loading: props.loading,
178
+ loadingText: props.sendingLabel,
179
+ onClick: submit,
180
+ }),
181
+ ],
182
+ },
183
+ ),
184
+ ],
185
+ },
186
+ ),
187
+ },
188
+ )
189
+ }
190
+ },
191
+ })
192
+ }