@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,241 @@
|
|
|
1
|
+
import { fontFamily } from '@getcortexlabs/mavis-core'
|
|
2
|
+
import {
|
|
3
|
+
defineComponent,
|
|
4
|
+
h,
|
|
5
|
+
onBeforeUnmount,
|
|
6
|
+
onActivated,
|
|
7
|
+
onDeactivated,
|
|
8
|
+
onMounted,
|
|
9
|
+
ref,
|
|
10
|
+
Teleport,
|
|
11
|
+
Transition,
|
|
12
|
+
watch,
|
|
13
|
+
} from 'vue'
|
|
14
|
+
import {
|
|
15
|
+
useButtonAction,
|
|
16
|
+
toastProps,
|
|
17
|
+
useMavisTheme,
|
|
18
|
+
useToastHost,
|
|
19
|
+
} from '@getcortexlabs/mavis-core/vue'
|
|
20
|
+
import type { IconName, ToastTone } from '@getcortexlabs/mavis-core'
|
|
21
|
+
import { MIcon } from './MIcon.js'
|
|
22
|
+
|
|
23
|
+
const icons: Record<ToastTone, IconName> = {
|
|
24
|
+
success: 'circle-check',
|
|
25
|
+
error: 'circle-alert',
|
|
26
|
+
warning: 'triangle-alert',
|
|
27
|
+
info: 'info',
|
|
28
|
+
}
|
|
29
|
+
const tones = { success: 'success', error: 'danger', warning: 'warning', info: 'accent' } as const
|
|
30
|
+
|
|
31
|
+
export const MToast = defineComponent({
|
|
32
|
+
name: 'MToast',
|
|
33
|
+
inheritAttrs: false,
|
|
34
|
+
props: toastProps,
|
|
35
|
+
setup(props) {
|
|
36
|
+
useButtonAction()
|
|
37
|
+
const { theme } = useMavisTheme()
|
|
38
|
+
const host = useToastHost(() => props.controller)
|
|
39
|
+
const mounted = ref(false)
|
|
40
|
+
const covered = ref(false)
|
|
41
|
+
const top = ref(0)
|
|
42
|
+
const announcement = ref('')
|
|
43
|
+
let enteredId: number | undefined
|
|
44
|
+
function announce() {
|
|
45
|
+
const item = host.snapshot.value.message
|
|
46
|
+
if (!covered.value && item && item.id === enteredId)
|
|
47
|
+
announcement.value = [item.title, item.message].filter(Boolean).join('. ')
|
|
48
|
+
}
|
|
49
|
+
watch(covered, announce)
|
|
50
|
+
let opener: HTMLElement | undefined
|
|
51
|
+
let observer: MutationObserver | undefined
|
|
52
|
+
let viewport: VisualViewport | null = null
|
|
53
|
+
function updateVisibility() {
|
|
54
|
+
host.pause('background', document.hidden)
|
|
55
|
+
}
|
|
56
|
+
function updateModal() {
|
|
57
|
+
covered.value = Boolean(document.querySelector('dialog:modal'))
|
|
58
|
+
host.pause('modal', covered.value)
|
|
59
|
+
}
|
|
60
|
+
function updateViewport() {
|
|
61
|
+
top.value = viewport?.scale === 1 ? viewport.offsetTop : 0
|
|
62
|
+
}
|
|
63
|
+
function restoreFocus(element: Element) {
|
|
64
|
+
if (element.contains(document.activeElement) && opener?.isConnected)
|
|
65
|
+
opener.focus({ preventScroll: true })
|
|
66
|
+
}
|
|
67
|
+
let listening = false
|
|
68
|
+
const start = () => {
|
|
69
|
+
if (listening) return
|
|
70
|
+
listening = true
|
|
71
|
+
if (typeof document === 'undefined') return
|
|
72
|
+
mounted.value = true
|
|
73
|
+
updateVisibility()
|
|
74
|
+
updateModal()
|
|
75
|
+
document.addEventListener('visibilitychange', updateVisibility)
|
|
76
|
+
observer = new MutationObserver(updateModal)
|
|
77
|
+
observer.observe(document.body, {
|
|
78
|
+
subtree: true,
|
|
79
|
+
childList: true,
|
|
80
|
+
attributes: true,
|
|
81
|
+
attributeFilter: ['open'],
|
|
82
|
+
})
|
|
83
|
+
viewport = window.visualViewport
|
|
84
|
+
viewport?.addEventListener('resize', updateViewport)
|
|
85
|
+
viewport?.addEventListener('scroll', updateViewport)
|
|
86
|
+
updateViewport()
|
|
87
|
+
host.activate()
|
|
88
|
+
}
|
|
89
|
+
const stop = () => {
|
|
90
|
+
listening = false
|
|
91
|
+
mounted.value = false
|
|
92
|
+
observer?.disconnect()
|
|
93
|
+
if (typeof document !== 'undefined')
|
|
94
|
+
document.removeEventListener('visibilitychange', updateVisibility)
|
|
95
|
+
viewport?.removeEventListener('resize', updateViewport)
|
|
96
|
+
viewport?.removeEventListener('scroll', updateViewport)
|
|
97
|
+
host.deactivate()
|
|
98
|
+
}
|
|
99
|
+
onMounted(start)
|
|
100
|
+
onActivated(start)
|
|
101
|
+
onDeactivated(stop)
|
|
102
|
+
onBeforeUnmount(stop)
|
|
103
|
+
return () => {
|
|
104
|
+
if (!mounted.value) return null
|
|
105
|
+
const { colors, typography, radius } = theme.value
|
|
106
|
+
const { message, visible } = host.snapshot.value
|
|
107
|
+
const tone = message ? tones[message.tone] : 'accent'
|
|
108
|
+
return h(Teleport, { to: 'body' }, [
|
|
109
|
+
h(
|
|
110
|
+
'div',
|
|
111
|
+
{
|
|
112
|
+
class: 'm-toast-host',
|
|
113
|
+
hidden: covered.value,
|
|
114
|
+
style: {
|
|
115
|
+
top: `calc(${top.value + 16}px + env(safe-area-inset-top, 0px))`,
|
|
116
|
+
'--m-focus': colors.primary,
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
[
|
|
120
|
+
// Keep the live region mounted before its text changes. The close control stays outside it.
|
|
121
|
+
h(
|
|
122
|
+
'span',
|
|
123
|
+
{
|
|
124
|
+
class: 'm-toast-announcement',
|
|
125
|
+
role: 'status',
|
|
126
|
+
'aria-live': 'polite',
|
|
127
|
+
'aria-atomic': 'true',
|
|
128
|
+
},
|
|
129
|
+
announcement.value,
|
|
130
|
+
),
|
|
131
|
+
h(
|
|
132
|
+
Transition,
|
|
133
|
+
{
|
|
134
|
+
name: 'm-toast',
|
|
135
|
+
appear: true,
|
|
136
|
+
onBeforeEnter: () => {
|
|
137
|
+
if (!message) return
|
|
138
|
+
host.begin(message.id)
|
|
139
|
+
opener =
|
|
140
|
+
document.activeElement instanceof HTMLElement
|
|
141
|
+
? document.activeElement
|
|
142
|
+
: undefined
|
|
143
|
+
enteredId = undefined
|
|
144
|
+
announcement.value = ''
|
|
145
|
+
},
|
|
146
|
+
onAfterEnter: () => {
|
|
147
|
+
if (!message) return
|
|
148
|
+
enteredId = message.id
|
|
149
|
+
announce()
|
|
150
|
+
host.entered(message.id)
|
|
151
|
+
},
|
|
152
|
+
onBeforeLeave: (element: Element) => {
|
|
153
|
+
restoreFocus(element)
|
|
154
|
+
element.setAttribute('inert', '')
|
|
155
|
+
element.setAttribute('aria-hidden', 'true')
|
|
156
|
+
announcement.value = ''
|
|
157
|
+
host.pause('hover', false)
|
|
158
|
+
host.pause('focus', false)
|
|
159
|
+
},
|
|
160
|
+
onAfterLeave: () => {
|
|
161
|
+
if (message) host.left(message.id)
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
default: () =>
|
|
166
|
+
message && visible
|
|
167
|
+
? h(
|
|
168
|
+
'div',
|
|
169
|
+
{
|
|
170
|
+
key: message.id,
|
|
171
|
+
class: 'm-toast',
|
|
172
|
+
'data-tone': message.tone,
|
|
173
|
+
style: {
|
|
174
|
+
backgroundColor: colors.surface,
|
|
175
|
+
color: colors.text,
|
|
176
|
+
borderColor: colors.border,
|
|
177
|
+
borderRadius: `${radius.lg}px`,
|
|
178
|
+
fontFamily: fontFamily(theme.value.typography.body.fontFamily, 'web'),
|
|
179
|
+
fontSize: `${typography.body.fontSize}px`,
|
|
180
|
+
lineHeight: typography.body.lineHeight,
|
|
181
|
+
},
|
|
182
|
+
onPointerenter: () => host.pause('hover', true),
|
|
183
|
+
onPointerleave: () => host.pause('hover', false),
|
|
184
|
+
onFocusin: () => host.pause('focus', true),
|
|
185
|
+
onFocusout: (event: FocusEvent) => {
|
|
186
|
+
if (
|
|
187
|
+
!(event.currentTarget as Element).contains(
|
|
188
|
+
event.relatedTarget as Node | null,
|
|
189
|
+
)
|
|
190
|
+
)
|
|
191
|
+
host.pause('focus', false)
|
|
192
|
+
},
|
|
193
|
+
onKeydown: (event: KeyboardEvent) => {
|
|
194
|
+
if (event.key === 'Escape') {
|
|
195
|
+
event.preventDefault()
|
|
196
|
+
event.stopPropagation()
|
|
197
|
+
props.controller.dismiss(message.id)
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
[
|
|
202
|
+
h(
|
|
203
|
+
'div',
|
|
204
|
+
{ class: 'm-toast-icon', style: { backgroundColor: colors.elevated } },
|
|
205
|
+
[h(MIcon, { name: icons[message.tone], tone })],
|
|
206
|
+
),
|
|
207
|
+
h('div', { class: 'm-toast-copy' }, [
|
|
208
|
+
message.title
|
|
209
|
+
? h('p', { class: 'm-toast-title' }, message.title)
|
|
210
|
+
: null,
|
|
211
|
+
h(
|
|
212
|
+
'p',
|
|
213
|
+
{
|
|
214
|
+
class: 'm-toast-message',
|
|
215
|
+
style: { color: message.title ? colors.muted : colors.text },
|
|
216
|
+
},
|
|
217
|
+
message.message,
|
|
218
|
+
),
|
|
219
|
+
]),
|
|
220
|
+
h(
|
|
221
|
+
'button',
|
|
222
|
+
{
|
|
223
|
+
type: 'button',
|
|
224
|
+
class: 'm-toast-close',
|
|
225
|
+
'aria-label': props.closeLabel,
|
|
226
|
+
style: { color: colors.muted },
|
|
227
|
+
onClick: () => props.controller.dismiss(message.id),
|
|
228
|
+
},
|
|
229
|
+
[h(MIcon, { name: 'x', tone: 'muted' })],
|
|
230
|
+
),
|
|
231
|
+
],
|
|
232
|
+
)
|
|
233
|
+
: null,
|
|
234
|
+
},
|
|
235
|
+
),
|
|
236
|
+
],
|
|
237
|
+
),
|
|
238
|
+
])
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
})
|
package/src/components/layout.ts
CHANGED
|
@@ -5,11 +5,12 @@ import {
|
|
|
5
5
|
useMavisTheme,
|
|
6
6
|
layoutDirection,
|
|
7
7
|
useDefaultShrink,
|
|
8
|
-
|
|
8
|
+
motionBoxProps,
|
|
9
9
|
} from '@getcortexlabs/mavis-core/vue'
|
|
10
10
|
import { defineComponent, h, mergeProps, provide } from 'vue'
|
|
11
11
|
import { resolveSpace } from '@getcortexlabs/mavis-core'
|
|
12
12
|
import { boxStyle, webAttrs } from '../style.js'
|
|
13
|
+
import { useMotionRegion } from '../motion-region.js'
|
|
13
14
|
|
|
14
15
|
export type { Align, Justify } from '@getcortexlabs/mavis-core/vue'
|
|
15
16
|
|
|
@@ -64,8 +65,9 @@ export const MColumn = createLayout('MColumn', 'column')
|
|
|
64
65
|
export const MBox = defineComponent({
|
|
65
66
|
name: 'MBox',
|
|
66
67
|
inheritAttrs: false,
|
|
67
|
-
props:
|
|
68
|
+
props: motionBoxProps,
|
|
68
69
|
setup(props, { attrs, slots }) {
|
|
70
|
+
const region = useMotionRegion(() => props.motionRegion)
|
|
69
71
|
const { theme } = useMavisTheme()
|
|
70
72
|
const shrink = useDefaultShrink()
|
|
71
73
|
return () =>
|
|
@@ -77,6 +79,7 @@ export const MBox = defineComponent({
|
|
|
77
79
|
style: { ...boxStyle(theme.value, props, shrink), display: 'grid' },
|
|
78
80
|
},
|
|
79
81
|
webAttrs({ ...attrs, ...viewAttrs(props) }),
|
|
82
|
+
region,
|
|
80
83
|
),
|
|
81
84
|
slots.default?.(),
|
|
82
85
|
)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createWorkflows } from '@getcortexlabs/mavis-core/vue'
|
|
2
|
+
import { MColumn, MRow } from './layout.js'
|
|
3
|
+
import { MText } from './MText.js'
|
|
4
|
+
import { MButton } from './MButton.js'
|
|
5
|
+
|
|
6
|
+
/** Restore only a focus lost because pagination removed/disabled its own action. */
|
|
7
|
+
function preserveFocus(root: unknown, currentId: string) {
|
|
8
|
+
const element = (root as { $el?: HTMLElement } | undefined)?.$el
|
|
9
|
+
const previous = element?.ownerDocument.activeElement as HTMLButtonElement | null
|
|
10
|
+
if (!element || !previous || !element.contains(previous)) return () => {}
|
|
11
|
+
return () => {
|
|
12
|
+
const document = element.ownerDocument
|
|
13
|
+
if (
|
|
14
|
+
element.isConnected &&
|
|
15
|
+
(document.activeElement === document.body || document.activeElement === previous) &&
|
|
16
|
+
(!previous.isConnected || previous.disabled)
|
|
17
|
+
) {
|
|
18
|
+
const target = document.getElementById(currentId)
|
|
19
|
+
if (target && element.contains(target)) target.focus({ preventScroll: true })
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const { MFormGroup, MFormErrors, MSteps, MPagination } = createWorkflows(
|
|
25
|
+
{ Column: MColumn, Row: MRow, Text: MText, Button: MButton, preserveFocus },
|
|
26
|
+
'web',
|
|
27
|
+
)
|
package/src/files.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { FileHandle, FilePickerAdapter, SelectedFile } from '@getcortexlabs/mavis-core'
|
|
2
|
+
|
|
3
|
+
const handles = new WeakMap<FileHandle, File>()
|
|
4
|
+
|
|
5
|
+
/** The host may read/send the File while the selection owns its resource. */
|
|
6
|
+
export function getWebFile(handle: FileHandle): File {
|
|
7
|
+
const file = handles.get(handle)
|
|
8
|
+
if (!file) throw new Error('This Web file handle is unavailable or has been released')
|
|
9
|
+
return file
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function resource(file: File): SelectedFile {
|
|
13
|
+
const handle = Object.freeze({}) as FileHandle
|
|
14
|
+
handles.set(handle, file)
|
|
15
|
+
let source: string | undefined
|
|
16
|
+
let released = false
|
|
17
|
+
return {
|
|
18
|
+
name: file.name,
|
|
19
|
+
size: file.size,
|
|
20
|
+
type: file.type || undefined,
|
|
21
|
+
handle,
|
|
22
|
+
async preview() {
|
|
23
|
+
if (released || !file.type.startsWith('image/')) return
|
|
24
|
+
source ??= URL.createObjectURL(file)
|
|
25
|
+
return source
|
|
26
|
+
},
|
|
27
|
+
release() {
|
|
28
|
+
if (released) return
|
|
29
|
+
released = true
|
|
30
|
+
if (source) URL.revokeObjectURL(source)
|
|
31
|
+
handles.delete(handle)
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Creating the adapter is SSR-safe. The input exists only during user-triggered selection. */
|
|
37
|
+
export function createWebFilePicker(): FilePickerAdapter {
|
|
38
|
+
return {
|
|
39
|
+
pick(request, cancellation) {
|
|
40
|
+
if (typeof document === 'undefined')
|
|
41
|
+
return Promise.reject(new Error('File selection requires a mounted browser'))
|
|
42
|
+
if (cancellation.cancelled) return Promise.resolve(null)
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
const input = document.createElement('input')
|
|
45
|
+
input.type = 'file'
|
|
46
|
+
input.multiple = request.multiple
|
|
47
|
+
input.accept = request.accept.join(',')
|
|
48
|
+
input.tabIndex = -1
|
|
49
|
+
input.setAttribute('aria-hidden', 'true')
|
|
50
|
+
input.style.display = 'none'
|
|
51
|
+
let done = false
|
|
52
|
+
let unsubscribe = () => {}
|
|
53
|
+
const finish = (files: readonly SelectedFile[] | null, error?: unknown) => {
|
|
54
|
+
if (done) return
|
|
55
|
+
done = true
|
|
56
|
+
unsubscribe()
|
|
57
|
+
input.removeEventListener('change', change)
|
|
58
|
+
input.removeEventListener('cancel', cancel)
|
|
59
|
+
input.remove()
|
|
60
|
+
if (error) reject(error)
|
|
61
|
+
else resolve(files)
|
|
62
|
+
}
|
|
63
|
+
const change = () => finish(Array.from(input.files ?? []).map(resource))
|
|
64
|
+
const cancel = () => finish(null)
|
|
65
|
+
input.addEventListener('change', change)
|
|
66
|
+
input.addEventListener('cancel', cancel)
|
|
67
|
+
document.body.append(input)
|
|
68
|
+
unsubscribe = cancellation.onCancel(cancel)
|
|
69
|
+
try {
|
|
70
|
+
input.click()
|
|
71
|
+
} catch (error) {
|
|
72
|
+
finish(null, error)
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
},
|
|
76
|
+
}
|
|
77
|
+
}
|
package/src/hydration.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getCurrentInstance, onBeforeMount, onMounted, shallowRef } from 'vue'
|
|
2
|
+
|
|
3
|
+
/** Read only this component's existing server root, before Vue patches editor values. */
|
|
4
|
+
export function useHydrationEdit<T>(
|
|
5
|
+
read: (root: Element) => T | undefined,
|
|
6
|
+
adopt: (value: T) => void,
|
|
7
|
+
) {
|
|
8
|
+
const instance = getCurrentInstance()!
|
|
9
|
+
let edit: T | undefined
|
|
10
|
+
const mounted = shallowRef(false)
|
|
11
|
+
onBeforeMount(() => {
|
|
12
|
+
const root = instance.vnode.el
|
|
13
|
+
if (root?.nodeType === 1) edit = read(root as Element)
|
|
14
|
+
})
|
|
15
|
+
onMounted(() => {
|
|
16
|
+
if (edit !== undefined) adopt(edit)
|
|
17
|
+
// A rerender also restores controlled values when the parent rejects the edit.
|
|
18
|
+
mounted.value = true
|
|
19
|
+
})
|
|
20
|
+
return () => (mounted.value ? undefined : edit)
|
|
21
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
import { MDatePicker, MDateRangePicker } from './components/MDatePicker.js'
|
|
2
|
+
import { MCombobox } from './components/MCombobox.js'
|
|
3
|
+
import { MFilePicker } from './components/MFilePicker.js'
|
|
4
|
+
import { MFormGroup, MFormErrors, MSteps, MPagination } from './components/workflows.js'
|
|
5
|
+
import { MChip } from './components/MChip.js'
|
|
6
|
+
import { MEmptyState } from './components/MEmptyState.js'
|
|
1
7
|
import type { App } from 'vue'
|
|
2
8
|
import {
|
|
9
|
+
MThemeProvider,
|
|
10
|
+
MSpan,
|
|
3
11
|
createThemeContext,
|
|
12
|
+
installAppToast,
|
|
4
13
|
themeKey,
|
|
5
14
|
type ThemeContextOptions,
|
|
6
15
|
} from '@getcortexlabs/mavis-core/vue'
|
|
@@ -10,6 +19,22 @@ import { MBox, MRow, MColumn } from './components/layout.js'
|
|
|
10
19
|
import { MCard } from './components/MCard.js'
|
|
11
20
|
import { MText } from './components/MText.js'
|
|
12
21
|
import { MButton } from './components/MButton.js'
|
|
22
|
+
import { MToast } from './components/MToast.js'
|
|
23
|
+
import { MDialog } from './components/MDialog.js'
|
|
24
|
+
import { MListItem } from './components/MListItem.js'
|
|
25
|
+
import { MSeparator } from './components/MSeparator.js'
|
|
26
|
+
import { MAvatar } from './components/MAvatar.js'
|
|
27
|
+
import { MBadge } from './components/MBadge.js'
|
|
28
|
+
import { MSkeleton } from './components/MSkeleton.js'
|
|
29
|
+
import { MProgress } from './components/MProgress.js'
|
|
30
|
+
import { MAccordion } from './components/MAccordion.js'
|
|
31
|
+
import { MSegmentedControl } from './components/MSegmentedControl.js'
|
|
32
|
+
import { MAlert } from './components/MAlert.js'
|
|
33
|
+
import { MTabs } from './components/MTabs.js'
|
|
34
|
+
import { MSelect } from './components/MSelect.js'
|
|
35
|
+
import { MRadioGroup } from './components/MRadioGroup.js'
|
|
36
|
+
import { MCheckbox } from './components/MCheckbox.js'
|
|
37
|
+
import { MSwitch } from './components/MSwitch.js'
|
|
13
38
|
import { MSlider } from './components/MSlider.js'
|
|
14
39
|
import { MInput } from './components/MInput.js'
|
|
15
40
|
import { MIcon } from './components/MIcon.js'
|
|
@@ -17,6 +42,8 @@ import { MReveal } from './components/MReveal.js'
|
|
|
17
42
|
import { MSheet } from './components/MSheet.js'
|
|
18
43
|
|
|
19
44
|
export {
|
|
45
|
+
MThemeProvider,
|
|
46
|
+
MSpan,
|
|
20
47
|
MScreen,
|
|
21
48
|
MBox,
|
|
22
49
|
MRow,
|
|
@@ -25,12 +52,44 @@ export {
|
|
|
25
52
|
MText,
|
|
26
53
|
MButton,
|
|
27
54
|
MSlider,
|
|
55
|
+
MSwitch,
|
|
56
|
+
MCheckbox,
|
|
57
|
+
MRadioGroup,
|
|
58
|
+
MSelect,
|
|
59
|
+
MToast,
|
|
60
|
+
MDialog,
|
|
61
|
+
MTabs,
|
|
62
|
+
MSkeleton,
|
|
63
|
+
MChip,
|
|
64
|
+
MEmptyState,
|
|
65
|
+
MProgress,
|
|
66
|
+
MAccordion,
|
|
67
|
+
MSegmentedControl,
|
|
68
|
+
MAlert,
|
|
69
|
+
MListItem,
|
|
70
|
+
MSeparator,
|
|
71
|
+
MAvatar,
|
|
72
|
+
MBadge,
|
|
28
73
|
MInput,
|
|
29
74
|
MIcon,
|
|
30
75
|
MReveal,
|
|
31
76
|
MSheet,
|
|
77
|
+
MDatePicker,
|
|
78
|
+
MDateRangePicker,
|
|
79
|
+
MCombobox,
|
|
80
|
+
MFilePicker,
|
|
81
|
+
MFormGroup,
|
|
82
|
+
MFormErrors,
|
|
83
|
+
MSteps,
|
|
84
|
+
MPagination,
|
|
32
85
|
}
|
|
33
|
-
export {
|
|
86
|
+
export {
|
|
87
|
+
useMavisTheme,
|
|
88
|
+
useToast,
|
|
89
|
+
useFormController,
|
|
90
|
+
useFormField,
|
|
91
|
+
useFileSelection,
|
|
92
|
+
} from '@getcortexlabs/mavis-core/vue'
|
|
34
93
|
export type {
|
|
35
94
|
MavisThemeContext,
|
|
36
95
|
Appearance,
|
|
@@ -40,16 +99,20 @@ export type {
|
|
|
40
99
|
export type { Align, Justify } from './components/layout.js'
|
|
41
100
|
export * from '@getcortexlabs/mavis-core'
|
|
42
101
|
|
|
43
|
-
export type MavisOptions = Omit<ThemeContextOptions, 'source'>
|
|
102
|
+
export type MavisOptions = Omit<ThemeContextOptions, 'source'> & { toast?: { closeLabel?: string } }
|
|
44
103
|
|
|
45
104
|
/** Create one plugin per application; `system` appearance follows `prefers-color-scheme`. */
|
|
46
105
|
export function createMavis(options: MavisOptions = {}) {
|
|
47
106
|
return {
|
|
48
107
|
install(app: App) {
|
|
49
|
-
|
|
108
|
+
installAppToast(app, options.toast)
|
|
109
|
+
const { toast: _toast, ...theme } = options
|
|
110
|
+
const context = createThemeContext({ ...theme, source: systemAppearance() })
|
|
50
111
|
app.provide(themeKey, context)
|
|
51
112
|
app.onUnmount(() => context.dispose())
|
|
52
113
|
for (const [name, component] of Object.entries({
|
|
114
|
+
MThemeProvider,
|
|
115
|
+
MSpan,
|
|
53
116
|
MScreen,
|
|
54
117
|
MBox,
|
|
55
118
|
MRow,
|
|
@@ -58,13 +121,41 @@ export function createMavis(options: MavisOptions = {}) {
|
|
|
58
121
|
MText,
|
|
59
122
|
MButton,
|
|
60
123
|
MSlider,
|
|
124
|
+
MSwitch,
|
|
125
|
+
MCheckbox,
|
|
126
|
+
MRadioGroup,
|
|
127
|
+
MSelect,
|
|
128
|
+
MToast,
|
|
129
|
+
MDialog,
|
|
130
|
+
MTabs,
|
|
131
|
+
MSkeleton,
|
|
132
|
+
MChip,
|
|
133
|
+
MEmptyState,
|
|
134
|
+
MProgress,
|
|
135
|
+
MAccordion,
|
|
136
|
+
MSegmentedControl,
|
|
137
|
+
MAlert,
|
|
138
|
+
MListItem,
|
|
139
|
+
MSeparator,
|
|
140
|
+
MAvatar,
|
|
141
|
+
MBadge,
|
|
61
142
|
MInput,
|
|
62
143
|
MIcon,
|
|
63
144
|
MReveal,
|
|
64
145
|
MSheet,
|
|
146
|
+
MDatePicker,
|
|
147
|
+
MDateRangePicker,
|
|
148
|
+
MCombobox,
|
|
149
|
+
MFilePicker,
|
|
150
|
+
MFormGroup,
|
|
151
|
+
MFormErrors,
|
|
152
|
+
MSteps,
|
|
153
|
+
MPagination,
|
|
65
154
|
})) {
|
|
66
155
|
app.component(name, component)
|
|
67
156
|
}
|
|
68
157
|
},
|
|
69
158
|
}
|
|
70
159
|
}
|
|
160
|
+
|
|
161
|
+
export * from './files.js'
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { AriaAttributes, HTMLAttributes } from 'vue'
|
|
2
|
+
|
|
3
|
+
type EditorEvents = Pick<
|
|
4
|
+
HTMLAttributes,
|
|
5
|
+
| 'onBeforeinput'
|
|
6
|
+
| 'onInput'
|
|
7
|
+
| 'onChange'
|
|
8
|
+
| 'onInvalid'
|
|
9
|
+
| 'onKeydown'
|
|
10
|
+
| 'onKeyup'
|
|
11
|
+
| 'onKeypress'
|
|
12
|
+
| 'onCompositionstart'
|
|
13
|
+
| 'onCompositionupdate'
|
|
14
|
+
| 'onCompositionend'
|
|
15
|
+
>
|
|
16
|
+
|
|
17
|
+
export interface InputEditorAttributes extends AriaAttributes, EditorEvents {}
|
|
18
|
+
|
|
19
|
+
declare module '@getcortexlabs/mavis-core/vue' {
|
|
20
|
+
interface InputPlatformAttributes extends InputEditorAttributes {}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Editing events belong to the editor; layout and other attributes stay on its wrapper. */
|
|
24
|
+
const editorEvent =
|
|
25
|
+
/^on(?:Beforeinput|Input|Change|Invalid|Keydown|Keyup|Keypress|Compositionstart|Compositionupdate|Compositionend)(?:Once|Capture|Passive)*$/
|
|
26
|
+
|
|
27
|
+
export function inputAttrs(attrs: Record<string, unknown>) {
|
|
28
|
+
const editor: Record<string, unknown> = {}
|
|
29
|
+
const wrapper: Record<string, unknown> = {}
|
|
30
|
+
for (const [name, value] of Object.entries(attrs)) {
|
|
31
|
+
const target = name.startsWith('aria-') || editorEvent.test(name) ? editor : wrapper
|
|
32
|
+
target[name] = value
|
|
33
|
+
}
|
|
34
|
+
return { editor, wrapper }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function describedBy(value: unknown, message: string | undefined) {
|
|
38
|
+
const ids = typeof value === 'string' ? value.trim().split(/\s+/).filter(Boolean) : []
|
|
39
|
+
if (message) ids.push(message)
|
|
40
|
+
return [...new Set(ids)].join(' ') || undefined
|
|
41
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { inject, type InjectionKey } from 'vue'
|
|
2
|
+
import { createWebRuntime, type WebRuntime } from '@rafaelaugusto/jolt/web'
|
|
3
|
+
|
|
4
|
+
export interface WebMotionContext {
|
|
5
|
+
acquire(document: Document): { runtime: WebRuntime; release(): void }
|
|
6
|
+
}
|
|
7
|
+
export const motionContextKey: InjectionKey<WebMotionContext> = Symbol('mavis-motion-context')
|
|
8
|
+
|
|
9
|
+
/** A context belongs to a declared region, never to a process or an SSR request singleton. */
|
|
10
|
+
export function createMotionContext(): WebMotionContext {
|
|
11
|
+
let current: { document: Document; runtime: WebRuntime; users: number } | undefined
|
|
12
|
+
return {
|
|
13
|
+
acquire(document) {
|
|
14
|
+
if (current && current.document !== document)
|
|
15
|
+
throw new Error('A motion region cannot span documents.')
|
|
16
|
+
const context = (current ??= { document, runtime: createWebRuntime(document), users: 0 })
|
|
17
|
+
context.users++
|
|
18
|
+
let released = false
|
|
19
|
+
return {
|
|
20
|
+
runtime: context.runtime,
|
|
21
|
+
release() {
|
|
22
|
+
if (released) return
|
|
23
|
+
released = true
|
|
24
|
+
if (--context.users === 0) {
|
|
25
|
+
if (current === context) current = undefined
|
|
26
|
+
context.runtime.dispose()
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function useMotionContext() {
|
|
34
|
+
return inject(motionContextKey, undefined) ?? createMotionContext()
|
|
35
|
+
}
|