@getcortexlabs/mavis-web 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.
- package/README.md +6 -4
- package/dist/components/DateCalendar.d.ts +95 -0
- package/dist/components/DateCalendar.d.ts.map +1 -0
- package/dist/components/DateCalendar.js +157 -0
- package/dist/components/DateCalendar.js.map +1 -0
- package/dist/components/MAccordion.d.ts +119 -0
- package/dist/components/MAccordion.d.ts.map +1 -0
- package/dist/components/MAccordion.js +180 -0
- package/dist/components/MAccordion.js.map +1 -0
- package/dist/components/MAlert.d.ts +109 -0
- package/dist/components/MAlert.d.ts.map +1 -0
- package/dist/components/MAlert.js +88 -0
- package/dist/components/MAlert.js.map +1 -0
- package/dist/components/MAvatar.d.ts +80 -0
- package/dist/components/MAvatar.d.ts.map +1 -0
- package/dist/components/MAvatar.js +88 -0
- package/dist/components/MAvatar.js.map +1 -0
- package/dist/components/MBadge.d.ts +70 -0
- package/dist/components/MBadge.d.ts.map +1 -0
- package/dist/components/MBadge.js +35 -0
- package/dist/components/MBadge.js.map +1 -0
- package/dist/components/MButton.d.ts +126 -32
- package/dist/components/MButton.d.ts.map +1 -1
- package/dist/components/MButton.js +51 -18
- package/dist/components/MButton.js.map +1 -1
- package/dist/components/MCard.d.ts +65 -19
- package/dist/components/MCard.d.ts.map +1 -1
- package/dist/components/MCard.js +28 -6
- package/dist/components/MCard.js.map +1 -1
- package/dist/components/MCheckbox.d.ts +103 -0
- package/dist/components/MCheckbox.d.ts.map +1 -0
- package/dist/components/MCheckbox.js +127 -0
- package/dist/components/MCheckbox.js.map +1 -0
- package/dist/components/MChip.d.ts +117 -0
- package/dist/components/MChip.d.ts.map +1 -0
- package/dist/components/MChip.js +103 -0
- package/dist/components/MChip.js.map +1 -0
- package/dist/components/MCombobox.d.ts +282 -0
- package/dist/components/MCombobox.d.ts.map +1 -0
- package/dist/components/MCombobox.js +440 -0
- package/dist/components/MCombobox.js.map +1 -0
- package/dist/components/MDatePicker.d.ts +1254 -0
- package/dist/components/MDatePicker.d.ts.map +1 -0
- package/dist/components/MDatePicker.js +22 -0
- package/dist/components/MDatePicker.js.map +1 -0
- package/dist/components/MDialog.d.ts +96 -0
- package/dist/components/MDialog.d.ts.map +1 -0
- package/dist/components/MDialog.js +214 -0
- package/dist/components/MDialog.js.map +1 -0
- package/dist/components/MEmptyState.d.ts +117 -0
- package/dist/components/MEmptyState.d.ts.map +1 -0
- package/dist/components/MEmptyState.js +79 -0
- package/dist/components/MEmptyState.js.map +1 -0
- package/dist/components/MFilePicker.d.ts +112 -0
- package/dist/components/MFilePicker.d.ts.map +1 -0
- package/dist/components/MFilePicker.js +193 -0
- package/dist/components/MFilePicker.js.map +1 -0
- package/dist/components/MIcon.d.ts +5 -3
- package/dist/components/MIcon.d.ts.map +1 -1
- package/dist/components/MInput.d.ts +182 -52
- package/dist/components/MInput.d.ts.map +1 -1
- package/dist/components/MInput.js +113 -21
- package/dist/components/MInput.js.map +1 -1
- package/dist/components/MListItem.d.ts +104 -0
- package/dist/components/MListItem.d.ts.map +1 -0
- package/dist/components/MListItem.js +53 -0
- package/dist/components/MListItem.js.map +1 -0
- package/dist/components/MProgress.d.ts +122 -0
- package/dist/components/MProgress.d.ts.map +1 -0
- package/dist/components/MProgress.js +69 -0
- package/dist/components/MProgress.js.map +1 -0
- package/dist/components/MRadioGroup.d.ts +104 -0
- package/dist/components/MRadioGroup.d.ts.map +1 -0
- package/dist/components/MRadioGroup.js +189 -0
- package/dist/components/MRadioGroup.js.map +1 -0
- package/dist/components/MReveal.d.ts +71 -35
- package/dist/components/MReveal.d.ts.map +1 -1
- package/dist/components/MReveal.js +28 -3
- package/dist/components/MReveal.js.map +1 -1
- package/dist/components/MScreen.d.ts +22 -7
- package/dist/components/MScreen.d.ts.map +1 -1
- package/dist/components/MScreen.js +13 -1
- package/dist/components/MScreen.js.map +1 -1
- package/dist/components/MSegmentedControl.d.ts +95 -0
- package/dist/components/MSegmentedControl.d.ts.map +1 -0
- package/dist/components/MSegmentedControl.js +128 -0
- package/dist/components/MSegmentedControl.js.map +1 -0
- package/dist/components/MSelect.d.ts +140 -0
- package/dist/components/MSelect.d.ts.map +1 -0
- package/dist/components/MSelect.js +308 -0
- package/dist/components/MSelect.js.map +1 -0
- package/dist/components/MSeparator.d.ts +56 -0
- package/dist/components/MSeparator.d.ts.map +1 -0
- package/dist/components/MSeparator.js +36 -0
- package/dist/components/MSeparator.js.map +1 -0
- package/dist/components/MSheet.d.ts +27 -15
- package/dist/components/MSheet.d.ts.map +1 -1
- package/dist/components/MSheet.js +82 -55
- package/dist/components/MSheet.js.map +1 -1
- package/dist/components/MSkeleton.d.ts +78 -0
- package/dist/components/MSkeleton.d.ts.map +1 -0
- package/dist/components/MSkeleton.js +43 -0
- package/dist/components/MSkeleton.js.map +1 -0
- package/dist/components/MSlider.d.ts +8 -4
- package/dist/components/MSlider.d.ts.map +1 -1
- package/dist/components/MSlider.js +14 -2
- package/dist/components/MSlider.js.map +1 -1
- package/dist/components/MSwitch.d.ts +89 -0
- package/dist/components/MSwitch.d.ts.map +1 -0
- package/dist/components/MSwitch.js +87 -0
- package/dist/components/MSwitch.js.map +1 -0
- package/dist/components/MTabs.d.ts +101 -0
- package/dist/components/MTabs.d.ts.map +1 -0
- package/dist/components/MTabs.js +228 -0
- package/dist/components/MTabs.js.map +1 -0
- package/dist/components/MText.d.ts +51 -26
- package/dist/components/MText.d.ts.map +1 -1
- package/dist/components/MText.js +26 -7
- package/dist/components/MText.js.map +1 -1
- package/dist/components/MToast.d.ts +24 -0
- package/dist/components/MToast.d.ts.map +1 -0
- package/dist/components/MToast.js +196 -0
- package/dist/components/MToast.js.map +1 -0
- package/dist/components/layout.d.ts +193 -84
- package/dist/components/layout.d.ts.map +1 -1
- package/dist/components/layout.js +5 -3
- package/dist/components/layout.js.map +1 -1
- package/dist/components/workflows.d.ts +251 -0
- package/dist/components/workflows.d.ts.map +1 -0
- package/dist/components/workflows.js +23 -0
- package/dist/components/workflows.js.map +1 -0
- package/dist/files.d.ts +6 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +82 -0
- package/dist/files.js.map +1 -0
- package/dist/hydration.d.ts +3 -0
- package/dist/hydration.d.ts.map +1 -0
- package/dist/hydration.js +20 -0
- package/dist/hydration.js.map +1 -0
- package/dist/index.d.ts +31 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +57 -4
- package/dist/index.js.map +1 -1
- package/dist/input-attrs.d.ts +15 -0
- package/dist/input-attrs.d.ts.map +1 -0
- package/dist/input-attrs.js +18 -0
- package/dist/input-attrs.js.map +1 -0
- package/dist/motion-context.d.ts +13 -0
- package/dist/motion-context.d.ts.map +1 -0
- package/dist/motion-context.js +33 -0
- package/dist/motion-context.js.map +1 -0
- package/dist/motion-region.d.ts +13 -0
- package/dist/motion-region.d.ts.map +1 -0
- package/dist/motion-region.js +134 -0
- package/dist/motion-region.js.map +1 -0
- package/dist/motion-surface.d.ts +12 -0
- package/dist/motion-surface.d.ts.map +1 -0
- package/dist/motion-surface.js +135 -0
- package/dist/motion-surface.js.map +1 -0
- package/dist/motion.d.ts +20 -0
- package/dist/motion.d.ts.map +1 -0
- package/dist/motion.js +263 -0
- package/dist/motion.js.map +1 -0
- package/dist/screen-viewport.d.ts.map +1 -1
- package/dist/screen-viewport.js +8 -0
- package/dist/screen-viewport.js.map +1 -1
- package/dist/scroll-motion.d.ts +5 -0
- package/dist/scroll-motion.d.ts.map +1 -0
- package/dist/scroll-motion.js +69 -0
- package/dist/scroll-motion.js.map +1 -0
- package/dist/sheet-motion.d.ts +8 -0
- package/dist/sheet-motion.d.ts.map +1 -0
- package/dist/sheet-motion.js +182 -0
- package/dist/sheet-motion.js.map +1 -0
- package/package.json +4 -3
- package/src/components/DateCalendar.ts +213 -0
- package/src/components/MAccordion.ts +231 -0
- package/src/components/MAlert.ts +109 -0
- package/src/components/MAvatar.ts +97 -0
- package/src/components/MBadge.ts +40 -0
- package/src/components/MButton.ts +68 -15
- package/src/components/MCard.ts +43 -5
- package/src/components/MCheckbox.ts +149 -0
- package/src/components/MChip.ts +109 -0
- package/src/components/MCombobox.ts +510 -0
- package/src/components/MDatePicker.ts +23 -0
- package/src/components/MDialog.ts +245 -0
- package/src/components/MEmptyState.ts +96 -0
- package/src/components/MFilePicker.ts +233 -0
- package/src/components/MInput.ts +186 -71
- package/src/components/MListItem.ts +66 -0
- package/src/components/MProgress.ts +82 -0
- package/src/components/MRadioGroup.ts +210 -0
- package/src/components/MReveal.ts +40 -3
- package/src/components/MScreen.ts +17 -1
- package/src/components/MSegmentedControl.ts +151 -0
- package/src/components/MSelect.ts +362 -0
- package/src/components/MSeparator.ts +40 -0
- package/src/components/MSheet.ts +101 -52
- package/src/components/MSkeleton.ts +52 -0
- package/src/components/MSlider.ts +25 -2
- package/src/components/MSwitch.ts +108 -0
- package/src/components/MTabs.ts +275 -0
- package/src/components/MText.ts +30 -7
- package/src/components/MToast.ts +241 -0
- package/src/components/layout.ts +5 -2
- package/src/components/workflows.ts +27 -0
- package/src/files.ts +77 -0
- package/src/hydration.ts +21 -0
- package/src/index.ts +94 -3
- package/src/input-attrs.ts +41 -0
- package/src/motion-context.ts +35 -0
- package/src/motion-region.ts +145 -0
- package/src/motion-surface.ts +150 -0
- package/src/motion.ts +311 -0
- package/src/screen-viewport.ts +6 -0
- package/src/scroll-motion.ts +75 -0
- package/src/sheet-motion.ts +181 -0
- package/src/style.css +806 -54
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { defineComponent, h, onBeforeUnmount, onDeactivated, Transition, useId, watch } from 'vue'
|
|
2
|
+
import {
|
|
3
|
+
useButtonAction,
|
|
4
|
+
dialogProps,
|
|
5
|
+
dialogEmits,
|
|
6
|
+
useDialogState,
|
|
7
|
+
useMavisTheme,
|
|
8
|
+
useCachedActivity,
|
|
9
|
+
} from '@getcortexlabs/mavis-core/vue'
|
|
10
|
+
import { checkDialogLabels, fontFamily } from '@getcortexlabs/mavis-core'
|
|
11
|
+
import { MButton } from './MButton.js'
|
|
12
|
+
import { MIcon } from './MIcon.js'
|
|
13
|
+
|
|
14
|
+
export const MDialog = defineComponent({
|
|
15
|
+
name: 'MDialog',
|
|
16
|
+
inheritAttrs: false,
|
|
17
|
+
props: dialogProps,
|
|
18
|
+
emits: dialogEmits,
|
|
19
|
+
setup(props, { emit }) {
|
|
20
|
+
useButtonAction()
|
|
21
|
+
const active = useCachedActivity()
|
|
22
|
+
const state = useDialogState(
|
|
23
|
+
{
|
|
24
|
+
get open() {
|
|
25
|
+
return active.value && props.open
|
|
26
|
+
},
|
|
27
|
+
get loading() {
|
|
28
|
+
return props.loading
|
|
29
|
+
},
|
|
30
|
+
get dismissible() {
|
|
31
|
+
return props.dismissible
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
emit,
|
|
35
|
+
)
|
|
36
|
+
const { theme } = useMavisTheme()
|
|
37
|
+
const titleId = `m-dialog-${useId()}`
|
|
38
|
+
let current: HTMLDialogElement | undefined
|
|
39
|
+
let opener: HTMLElement | undefined
|
|
40
|
+
let overflow: string | undefined
|
|
41
|
+
let outside = false
|
|
42
|
+
function release(element: HTMLDialogElement) {
|
|
43
|
+
if (element.open) element.close()
|
|
44
|
+
if (current !== element || props.open) return
|
|
45
|
+
current = undefined
|
|
46
|
+
if (overflow !== undefined && document.body.style.overflow === 'hidden')
|
|
47
|
+
document.body.style.overflow = overflow
|
|
48
|
+
overflow = undefined
|
|
49
|
+
if (opener?.isConnected) opener.focus({ preventScroll: true })
|
|
50
|
+
opener = undefined
|
|
51
|
+
}
|
|
52
|
+
function enter(element: Element) {
|
|
53
|
+
const dialog = element as HTMLDialogElement
|
|
54
|
+
if (current !== dialog) {
|
|
55
|
+
opener = document.activeElement instanceof HTMLElement ? document.activeElement : undefined
|
|
56
|
+
overflow ??= document.body.style.overflow
|
|
57
|
+
}
|
|
58
|
+
current = dialog
|
|
59
|
+
document.body.style.overflow = 'hidden'
|
|
60
|
+
if (!dialog.open) dialog.showModal()
|
|
61
|
+
const cancel = dialog.querySelector<HTMLButtonElement>('[data-dialog-cancel]')
|
|
62
|
+
const panel = dialog.querySelector<HTMLElement>('.m-dialog-panel')
|
|
63
|
+
;(cancel && !cancel.disabled ? cancel : panel)?.focus({ preventScroll: true })
|
|
64
|
+
}
|
|
65
|
+
function trap(event: KeyboardEvent) {
|
|
66
|
+
if (event.key !== 'Tab' || !current) return
|
|
67
|
+
const controls = [...current.querySelectorAll<HTMLButtonElement>('button:not(:disabled)')]
|
|
68
|
+
const first = controls[0],
|
|
69
|
+
last = controls[controls.length - 1]
|
|
70
|
+
if (!first) {
|
|
71
|
+
event.preventDefault()
|
|
72
|
+
current.querySelector<HTMLElement>('.m-dialog-panel')?.focus()
|
|
73
|
+
} else if (
|
|
74
|
+
event.shiftKey &&
|
|
75
|
+
(document.activeElement === first ||
|
|
76
|
+
!controls.includes(document.activeElement as HTMLButtonElement))
|
|
77
|
+
) {
|
|
78
|
+
event.preventDefault()
|
|
79
|
+
last?.focus()
|
|
80
|
+
} else if (!event.shiftKey && document.activeElement === last) {
|
|
81
|
+
event.preventDefault()
|
|
82
|
+
first.focus()
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
watch(
|
|
86
|
+
() => props.loading,
|
|
87
|
+
(loading) => {
|
|
88
|
+
if (loading)
|
|
89
|
+
current?.querySelector<HTMLElement>('.m-dialog-panel')?.focus({ preventScroll: true })
|
|
90
|
+
},
|
|
91
|
+
)
|
|
92
|
+
const cleanup = () => {
|
|
93
|
+
if (current?.open) current.close()
|
|
94
|
+
if (overflow !== undefined && document.body.style.overflow === 'hidden')
|
|
95
|
+
document.body.style.overflow = overflow
|
|
96
|
+
if (opener?.isConnected) opener.focus({ preventScroll: true })
|
|
97
|
+
current = opener = undefined
|
|
98
|
+
}
|
|
99
|
+
onBeforeUnmount(cleanup)
|
|
100
|
+
onDeactivated(() => {
|
|
101
|
+
state.request('navigation')
|
|
102
|
+
cleanup()
|
|
103
|
+
})
|
|
104
|
+
return () => {
|
|
105
|
+
checkDialogLabels(props.title, props.confirmLabel, props.cancelLabel, props.loadingLabel)
|
|
106
|
+
const { colors, radius, typography } = theme.value
|
|
107
|
+
const danger = props.tone === 'danger'
|
|
108
|
+
return h(
|
|
109
|
+
Transition,
|
|
110
|
+
{
|
|
111
|
+
name: 'm-dialog',
|
|
112
|
+
appear: true,
|
|
113
|
+
onEnter: enter,
|
|
114
|
+
onAfterLeave: (element: Element) => {
|
|
115
|
+
release(element as HTMLDialogElement)
|
|
116
|
+
state.left()
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
default: () =>
|
|
121
|
+
state.visible.value
|
|
122
|
+
? h(
|
|
123
|
+
'dialog',
|
|
124
|
+
{
|
|
125
|
+
id: props.id,
|
|
126
|
+
class: 'm-dialog',
|
|
127
|
+
'aria-labelledby': titleId,
|
|
128
|
+
'aria-describedby': props.description ? `${titleId}-description` : undefined,
|
|
129
|
+
'aria-busy': props.loading ? 'true' : undefined,
|
|
130
|
+
style: {
|
|
131
|
+
color: colors.text,
|
|
132
|
+
colorScheme: theme.value.appearance,
|
|
133
|
+
'--m-focus': colors.primary,
|
|
134
|
+
},
|
|
135
|
+
onCancel: (event: Event) => {
|
|
136
|
+
event.preventDefault()
|
|
137
|
+
state.request('escape')
|
|
138
|
+
},
|
|
139
|
+
onClose: (event: Event) => {
|
|
140
|
+
const element = event.target as HTMLDialogElement
|
|
141
|
+
if (element === current && !element.open && props.open)
|
|
142
|
+
state.request('escape')
|
|
143
|
+
},
|
|
144
|
+
onKeydown: trap,
|
|
145
|
+
onPointerdown: (event: Event) => {
|
|
146
|
+
outside = event.target === event.currentTarget
|
|
147
|
+
},
|
|
148
|
+
onClick: (event: Event) => {
|
|
149
|
+
if (outside && event.target === event.currentTarget) state.request('backdrop')
|
|
150
|
+
outside = false
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
[
|
|
154
|
+
h(
|
|
155
|
+
'div',
|
|
156
|
+
{
|
|
157
|
+
class: 'm-dialog-panel',
|
|
158
|
+
tabindex: -1,
|
|
159
|
+
style: {
|
|
160
|
+
backgroundColor: colors.surface,
|
|
161
|
+
borderColor: colors.border,
|
|
162
|
+
borderRadius: `${radius.lg}px`,
|
|
163
|
+
fontFamily: fontFamily(typography.body.fontFamily, 'web'),
|
|
164
|
+
fontSize: `${typography.body.fontSize}px`,
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
[
|
|
168
|
+
h('div', { class: 'm-dialog-body' }, [
|
|
169
|
+
h(
|
|
170
|
+
'div',
|
|
171
|
+
{
|
|
172
|
+
class: 'm-dialog-symbol',
|
|
173
|
+
style: {
|
|
174
|
+
backgroundColor: danger ? colors.elevated : colors.primarySoft,
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
[
|
|
178
|
+
h(MIcon, {
|
|
179
|
+
name: danger ? 'triangle-alert' : 'circle-check',
|
|
180
|
+
tone: danger ? 'danger' : 'primary',
|
|
181
|
+
size: 'lg',
|
|
182
|
+
}),
|
|
183
|
+
],
|
|
184
|
+
),
|
|
185
|
+
h(
|
|
186
|
+
'h2',
|
|
187
|
+
{
|
|
188
|
+
id: titleId,
|
|
189
|
+
class: 'm-dialog-title',
|
|
190
|
+
style: {
|
|
191
|
+
fontFamily: fontFamily(typography.heading.fontFamily, 'web'),
|
|
192
|
+
fontSize: `${typography.heading.fontSize}px`,
|
|
193
|
+
fontWeight: typography.heading.fontWeight,
|
|
194
|
+
lineHeight: typography.heading.lineHeight,
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
props.title,
|
|
198
|
+
),
|
|
199
|
+
props.description
|
|
200
|
+
? h(
|
|
201
|
+
'p',
|
|
202
|
+
{
|
|
203
|
+
id: `${titleId}-description`,
|
|
204
|
+
class: 'm-dialog-description',
|
|
205
|
+
style: {
|
|
206
|
+
color: colors.muted,
|
|
207
|
+
lineHeight: typography.body.lineHeight,
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
props.description,
|
|
211
|
+
)
|
|
212
|
+
: null,
|
|
213
|
+
]),
|
|
214
|
+
h('div', { class: 'm-dialog-actions' }, [
|
|
215
|
+
h(MButton, {
|
|
216
|
+
'data-dialog-cancel': '',
|
|
217
|
+
grow: 1,
|
|
218
|
+
text: props.cancelLabel,
|
|
219
|
+
variant: 'secondary',
|
|
220
|
+
disabled: props.loading,
|
|
221
|
+
onClick: () => state.request('cancel'),
|
|
222
|
+
}),
|
|
223
|
+
h(MButton, {
|
|
224
|
+
'data-dialog-confirm': '',
|
|
225
|
+
grow: 1,
|
|
226
|
+
text: props.confirmLabel,
|
|
227
|
+
loading: props.loading,
|
|
228
|
+
disabled: props.loading,
|
|
229
|
+
loadingText: props.loadingLabel,
|
|
230
|
+
style: danger
|
|
231
|
+
? { backgroundColor: colors.danger, color: colors.surface }
|
|
232
|
+
: undefined,
|
|
233
|
+
onClick: state.confirm,
|
|
234
|
+
}),
|
|
235
|
+
]),
|
|
236
|
+
],
|
|
237
|
+
),
|
|
238
|
+
],
|
|
239
|
+
)
|
|
240
|
+
: null,
|
|
241
|
+
},
|
|
242
|
+
)
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
})
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { defineComponent, h, mergeProps, type SlotsType, type VNode } from 'vue'
|
|
2
|
+
import { checkEmptyStateTitle } from '@getcortexlabs/mavis-core'
|
|
3
|
+
import { emptyStateProps, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
|
|
4
|
+
import { MColumn, MRow, MBox } from './layout.js'
|
|
5
|
+
import { MText } from './MText.js'
|
|
6
|
+
import { MIcon } from './MIcon.js'
|
|
7
|
+
|
|
8
|
+
export const MEmptyState = defineComponent({
|
|
9
|
+
name: 'MEmptyState',
|
|
10
|
+
inheritAttrs: false,
|
|
11
|
+
props: emptyStateProps,
|
|
12
|
+
slots: Object as SlotsType<{ illustration?: () => VNode[]; actions?: () => VNode[] }>,
|
|
13
|
+
setup(props, { attrs, slots }) {
|
|
14
|
+
const { theme } = useMavisTheme()
|
|
15
|
+
return () => {
|
|
16
|
+
checkEmptyStateTitle(props.title)
|
|
17
|
+
const { colors } = theme.value
|
|
18
|
+
const size = props.compact ? 64 : 88
|
|
19
|
+
const illustration = () =>
|
|
20
|
+
slots.illustration?.() ??
|
|
21
|
+
h(
|
|
22
|
+
MBox,
|
|
23
|
+
{
|
|
24
|
+
width: size,
|
|
25
|
+
height: size,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
default: () => [
|
|
29
|
+
h(MBox, {
|
|
30
|
+
width: size,
|
|
31
|
+
height: size,
|
|
32
|
+
radius: 'full',
|
|
33
|
+
backgroundColor: colors[props.tone === 'primary' ? 'primarySoft' : 'accentSoft'],
|
|
34
|
+
}),
|
|
35
|
+
h(MIcon, {
|
|
36
|
+
name: props.icon,
|
|
37
|
+
size: props.compact ? 28 : 36,
|
|
38
|
+
tone: props.tone,
|
|
39
|
+
style: { justifySelf: 'center', alignSelf: 'center' },
|
|
40
|
+
}),
|
|
41
|
+
h(MBox, {
|
|
42
|
+
width: 18,
|
|
43
|
+
height: 18,
|
|
44
|
+
radius: 'full',
|
|
45
|
+
backgroundColor: colors[props.tone === 'primary' ? 'accent' : 'primary'],
|
|
46
|
+
style: { justifySelf: 'end', alignSelf: 'start' },
|
|
47
|
+
}),
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
)
|
|
51
|
+
return h(
|
|
52
|
+
MColumn,
|
|
53
|
+
mergeProps(attrs, {
|
|
54
|
+
id: props.id,
|
|
55
|
+
width: props.width,
|
|
56
|
+
grow: props.grow,
|
|
57
|
+
shrink: props.shrink,
|
|
58
|
+
accessibilityHidden: props.accessibilityHidden,
|
|
59
|
+
gap: props.compact ? 'md' : 'lg',
|
|
60
|
+
padding: props.compact ? 'lg' : '2xl',
|
|
61
|
+
align: 'stretch',
|
|
62
|
+
class: 'm-empty-state',
|
|
63
|
+
}),
|
|
64
|
+
{
|
|
65
|
+
default: () => [
|
|
66
|
+
h(
|
|
67
|
+
MColumn,
|
|
68
|
+
{ align: 'center', accessibilityHidden: true, inert: true },
|
|
69
|
+
{ default: () => illustration() },
|
|
70
|
+
),
|
|
71
|
+
h(
|
|
72
|
+
MColumn,
|
|
73
|
+
{ gap: 'sm' },
|
|
74
|
+
{
|
|
75
|
+
default: () => [
|
|
76
|
+
h(MText, {
|
|
77
|
+
text: props.title,
|
|
78
|
+
variant: props.compact ? 'heading' : 'title',
|
|
79
|
+
as: props.titleAs,
|
|
80
|
+
align: 'center',
|
|
81
|
+
}),
|
|
82
|
+
props.description
|
|
83
|
+
? h(MText, { text: props.description, tone: 'muted', align: 'center' })
|
|
84
|
+
: null,
|
|
85
|
+
],
|
|
86
|
+
},
|
|
87
|
+
),
|
|
88
|
+
slots.actions
|
|
89
|
+
? h(MRow, { gap: 'sm', wrap: true, justify: 'center' }, { default: slots.actions })
|
|
90
|
+
: null,
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
})
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineComponent,
|
|
3
|
+
h,
|
|
4
|
+
mergeProps,
|
|
5
|
+
nextTick,
|
|
6
|
+
onBeforeUnmount,
|
|
7
|
+
onDeactivated,
|
|
8
|
+
onMounted,
|
|
9
|
+
ref,
|
|
10
|
+
shallowRef,
|
|
11
|
+
watch,
|
|
12
|
+
} from 'vue'
|
|
13
|
+
import { filePickerProps, fileStatusText, useButtonAction } from '@getcortexlabs/mavis-core/vue'
|
|
14
|
+
import type { InputHandle } from '@getcortexlabs/mavis-core'
|
|
15
|
+
import { createWebFilePicker } from '../files.js'
|
|
16
|
+
import { MColumn, MRow } from './layout.js'
|
|
17
|
+
import { MText } from './MText.js'
|
|
18
|
+
import { MButton } from './MButton.js'
|
|
19
|
+
import { MProgress } from './MProgress.js'
|
|
20
|
+
import { MCard } from './MCard.js'
|
|
21
|
+
|
|
22
|
+
const FilePicker = defineComponent({
|
|
23
|
+
name: 'MFilePicker',
|
|
24
|
+
inheritAttrs: false,
|
|
25
|
+
props: filePickerProps,
|
|
26
|
+
setup(props, { attrs, expose }) {
|
|
27
|
+
useButtonAction()
|
|
28
|
+
const root = ref<HTMLElement>()
|
|
29
|
+
const state = shallowRef(props.selection.state)
|
|
30
|
+
const picker = createWebFilePicker()
|
|
31
|
+
let mounted = false
|
|
32
|
+
let unsubscribe = () => {}
|
|
33
|
+
watch(
|
|
34
|
+
() => props.selection,
|
|
35
|
+
(selection, previous) => {
|
|
36
|
+
previous?.pause()
|
|
37
|
+
unsubscribe()
|
|
38
|
+
state.value = selection.state
|
|
39
|
+
unsubscribe = selection.subscribe((value) => {
|
|
40
|
+
state.value = value
|
|
41
|
+
})
|
|
42
|
+
},
|
|
43
|
+
{ immediate: true, flush: 'sync' },
|
|
44
|
+
)
|
|
45
|
+
watch(
|
|
46
|
+
() => props.disabled,
|
|
47
|
+
(disabled) => {
|
|
48
|
+
if (disabled) props.selection.pause()
|
|
49
|
+
},
|
|
50
|
+
)
|
|
51
|
+
onMounted(() => {
|
|
52
|
+
mounted = true
|
|
53
|
+
})
|
|
54
|
+
onDeactivated(() => props.selection.pause())
|
|
55
|
+
onBeforeUnmount(() => {
|
|
56
|
+
mounted = false
|
|
57
|
+
unsubscribe()
|
|
58
|
+
props.selection.pause()
|
|
59
|
+
})
|
|
60
|
+
function focusChoose() {
|
|
61
|
+
if (!mounted || props.disabled || state.value.picking) return
|
|
62
|
+
root.value
|
|
63
|
+
?.querySelector<HTMLButtonElement>('[data-file-choose]')
|
|
64
|
+
?.focus({ preventScroll: true })
|
|
65
|
+
}
|
|
66
|
+
expose({
|
|
67
|
+
focus: focusChoose,
|
|
68
|
+
blur: () => root.value?.querySelector<HTMLButtonElement>('[data-file-choose]')?.blur(),
|
|
69
|
+
} satisfies InputHandle)
|
|
70
|
+
function choose() {
|
|
71
|
+
if (!mounted || props.disabled || state.value.picking) return
|
|
72
|
+
focusChoose()
|
|
73
|
+
const selection = props.selection
|
|
74
|
+
void selection.select(picker).finally(async () => {
|
|
75
|
+
await nextTick()
|
|
76
|
+
if (mounted && props.selection === selection && !props.disabled) focusChoose()
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
return () => {
|
|
80
|
+
if (!props.label.trim()) throw new TypeError('FilePicker needs a non-empty label')
|
|
81
|
+
const selection = props.selection
|
|
82
|
+
return h(
|
|
83
|
+
'div',
|
|
84
|
+
mergeProps(attrs, {
|
|
85
|
+
ref: root,
|
|
86
|
+
role: 'group',
|
|
87
|
+
'aria-label': props.label,
|
|
88
|
+
style: { minWidth: 0 },
|
|
89
|
+
}),
|
|
90
|
+
[
|
|
91
|
+
h(
|
|
92
|
+
MColumn,
|
|
93
|
+
{ gap: 'md' },
|
|
94
|
+
{
|
|
95
|
+
default: () => [
|
|
96
|
+
h(MText, { text: props.label, weight: '600' }),
|
|
97
|
+
h(
|
|
98
|
+
MRow,
|
|
99
|
+
{ gap: 'sm', wrap: true },
|
|
100
|
+
{
|
|
101
|
+
default: () => [
|
|
102
|
+
h(MButton, {
|
|
103
|
+
text: props.chooseLabel,
|
|
104
|
+
variant: 'secondary',
|
|
105
|
+
disabled: props.disabled || state.value.picking,
|
|
106
|
+
'data-file-choose': '',
|
|
107
|
+
onClick: choose,
|
|
108
|
+
}),
|
|
109
|
+
state.value.picking
|
|
110
|
+
? h(MButton, {
|
|
111
|
+
text: props.cancelLabel,
|
|
112
|
+
variant: 'ghost',
|
|
113
|
+
onClick: () => {
|
|
114
|
+
selection.cancelSelection()
|
|
115
|
+
focusChoose()
|
|
116
|
+
},
|
|
117
|
+
})
|
|
118
|
+
: null,
|
|
119
|
+
],
|
|
120
|
+
},
|
|
121
|
+
),
|
|
122
|
+
state.value.error
|
|
123
|
+
? h('div', { role: 'alert' }, [
|
|
124
|
+
h(MText, {
|
|
125
|
+
text:
|
|
126
|
+
props.errorLabels[state.value.error.code] ?? state.value.error.message,
|
|
127
|
+
tone: 'danger',
|
|
128
|
+
}),
|
|
129
|
+
])
|
|
130
|
+
: null,
|
|
131
|
+
!state.value.items.length
|
|
132
|
+
? h(MText, { text: props.emptyLabel, tone: 'muted' })
|
|
133
|
+
: null,
|
|
134
|
+
...state.value.items.map((item) => {
|
|
135
|
+
const preview = selection.preview(item.id)
|
|
136
|
+
const status = fileStatusText(item, props.statusLabels)
|
|
137
|
+
return h(
|
|
138
|
+
MCard,
|
|
139
|
+
{ key: item.id, gap: 'sm' },
|
|
140
|
+
{
|
|
141
|
+
default: () => [
|
|
142
|
+
typeof preview === 'string'
|
|
143
|
+
? h('img', {
|
|
144
|
+
src: preview,
|
|
145
|
+
alt: '',
|
|
146
|
+
width: 80,
|
|
147
|
+
height: 80,
|
|
148
|
+
style: { objectFit: 'contain', borderRadius: '8px' },
|
|
149
|
+
onError: () => selection.discardPreview(item.id),
|
|
150
|
+
})
|
|
151
|
+
: null,
|
|
152
|
+
h(MText, {
|
|
153
|
+
text: item.name,
|
|
154
|
+
weight: '600',
|
|
155
|
+
style: { overflowWrap: 'anywhere' },
|
|
156
|
+
}),
|
|
157
|
+
h(MText, {
|
|
158
|
+
text: `${status}${item.size === undefined ? '' : ` · ${item.size} B`}`,
|
|
159
|
+
variant: 'caption',
|
|
160
|
+
tone:
|
|
161
|
+
item.status === 'failed'
|
|
162
|
+
? 'danger'
|
|
163
|
+
: item.status === 'uploaded'
|
|
164
|
+
? 'success'
|
|
165
|
+
: 'muted',
|
|
166
|
+
'aria-live': 'polite',
|
|
167
|
+
}),
|
|
168
|
+
item.status === 'uploading'
|
|
169
|
+
? h(MProgress, {
|
|
170
|
+
value: (item.progress ?? 0) * 100,
|
|
171
|
+
indeterminate: item.progress === undefined,
|
|
172
|
+
label: `${props.uploadLabel}: ${item.name}`,
|
|
173
|
+
indeterminateLabel: props.pendingLabel,
|
|
174
|
+
})
|
|
175
|
+
: null,
|
|
176
|
+
item.error
|
|
177
|
+
? h(MText, { text: item.error, tone: 'danger', variant: 'caption' })
|
|
178
|
+
: null,
|
|
179
|
+
h(
|
|
180
|
+
MRow,
|
|
181
|
+
{ gap: 'sm', wrap: true },
|
|
182
|
+
{
|
|
183
|
+
default: () => [
|
|
184
|
+
item.status === 'uploading'
|
|
185
|
+
? h(MButton, {
|
|
186
|
+
text: props.cancelLabel,
|
|
187
|
+
accessibilityLabel: `${props.cancelLabel}: ${item.name}`,
|
|
188
|
+
variant: 'secondary',
|
|
189
|
+
disabled: props.disabled,
|
|
190
|
+
onClick: () => selection.cancel(item.id),
|
|
191
|
+
})
|
|
192
|
+
: selection.canUpload && item.status !== 'uploaded'
|
|
193
|
+
? h(MButton, {
|
|
194
|
+
text:
|
|
195
|
+
item.status === 'failed' || item.status === 'cancelled'
|
|
196
|
+
? props.retryLabel
|
|
197
|
+
: props.uploadLabel,
|
|
198
|
+
accessibilityLabel: `${item.status === 'failed' || item.status === 'cancelled' ? props.retryLabel : props.uploadLabel}: ${item.name}`,
|
|
199
|
+
disabled: props.disabled || !selection.hasFile(item.id),
|
|
200
|
+
onClick: () => {
|
|
201
|
+
void selection.upload(item.id)
|
|
202
|
+
},
|
|
203
|
+
})
|
|
204
|
+
: null,
|
|
205
|
+
h(MButton, {
|
|
206
|
+
text: props.removeLabel,
|
|
207
|
+
accessibilityLabel: `${props.removeLabel}: ${item.name}`,
|
|
208
|
+
variant: 'ghost',
|
|
209
|
+
disabled: props.disabled,
|
|
210
|
+
onClick: () => {
|
|
211
|
+
focusChoose()
|
|
212
|
+
selection.remove(item.id)
|
|
213
|
+
},
|
|
214
|
+
}),
|
|
215
|
+
],
|
|
216
|
+
},
|
|
217
|
+
),
|
|
218
|
+
],
|
|
219
|
+
},
|
|
220
|
+
)
|
|
221
|
+
}),
|
|
222
|
+
],
|
|
223
|
+
},
|
|
224
|
+
),
|
|
225
|
+
],
|
|
226
|
+
)
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
export const MFilePicker = FilePicker as typeof FilePicker & {
|
|
232
|
+
new (): InstanceType<typeof FilePicker> & InputHandle
|
|
233
|
+
}
|