@getcortexlabs/mavis-web 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.
- package/README.md +4 -4
- package/dist/components/DateCalendar.d.ts +1 -1
- package/dist/components/MButton.d.ts +3 -3
- package/dist/components/MCard.d.ts +1 -1
- package/dist/components/MChip.d.ts +1 -1
- package/dist/components/MCombobox.d.ts +4 -4
- package/dist/components/MDatePicker.d.ts +16 -16
- package/dist/components/MDialog.d.ts +3 -3
- package/dist/components/MFilePicker.d.ts +3 -3
- package/dist/components/MGrid.d.ts +1 -1
- package/dist/components/MImageCompare.d.ts +2 -2
- package/dist/components/MImageViewer.d.ts +5 -5
- package/dist/components/MInput.d.ts +2 -2
- package/dist/components/MLink.d.ts +1 -1
- package/dist/components/MListItem.d.ts +1 -1
- package/dist/components/MPinInput.d.ts +57 -0
- package/dist/components/MPinInput.d.ts.map +1 -0
- package/dist/components/MPinInput.js +159 -0
- package/dist/components/MPinInput.js.map +1 -0
- package/dist/components/MPopover.d.ts +1 -1
- package/dist/components/MPopover.d.ts.map +1 -1
- package/dist/components/MPopover.js +29 -19
- package/dist/components/MPopover.js.map +1 -1
- package/dist/components/MProgress.d.ts +1 -1
- package/dist/components/MRangeSlider.d.ts +1 -1
- package/dist/components/MResizablePanels.d.ts +4 -4
- package/dist/components/MSelect.d.ts +2 -2
- package/dist/components/MSeparator.d.ts +1 -1
- package/dist/components/MTimePicker.d.ts +12 -12
- package/dist/components/advanced.d.ts +852 -0
- package/dist/components/advanced.d.ts.map +1 -0
- package/dist/components/advanced.js +331 -0
- package/dist/components/advanced.js.map +1 -0
- package/dist/components/configurator.d.ts +7 -7
- package/dist/components/creative.d.ts +614 -0
- package/dist/components/creative.d.ts.map +1 -0
- package/dist/components/creative.js +191 -0
- package/dist/components/creative.js.map +1 -0
- package/dist/components/dashboard.d.ts +474 -0
- package/dist/components/dashboard.d.ts.map +1 -0
- package/dist/components/dashboard.js +286 -0
- package/dist/components/dashboard.js.map +1 -0
- package/dist/components/discovery.d.ts +3 -3
- package/dist/components/interactive.d.ts +1 -1
- package/dist/components/navigation.d.ts +3 -3
- package/dist/components/screen-components.d.ts +502 -0
- package/dist/components/screen-components.d.ts.map +1 -0
- package/dist/components/screen-components.js +67 -0
- package/dist/components/screen-components.js.map +1 -0
- package/dist/components/wayfinding.d.ts +6 -6
- package/dist/components/workflows.d.ts +3 -3
- package/dist/image-crop.d.ts +3 -0
- package/dist/image-crop.d.ts.map +1 -0
- package/dist/image-crop.js +62 -0
- package/dist/image-crop.js.map +1 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +30 -1
- package/dist/index.js.map +1 -1
- package/dist/use-motion-surface.d.ts.map +1 -1
- package/dist/use-motion-surface.js +27 -8
- package/dist/use-motion-surface.js.map +1 -1
- package/package.json +3 -3
- package/src/components/MPinInput.ts +194 -0
- package/src/components/MPopover.ts +33 -19
- package/src/components/advanced.ts +387 -0
- package/src/components/creative.ts +240 -0
- package/src/components/dashboard.ts +353 -0
- package/src/components/screen-components.ts +86 -0
- package/src/image-crop.ts +57 -0
- package/src/index.ts +84 -0
- package/src/use-motion-surface.ts +40 -15
|
@@ -54,6 +54,15 @@ export const MPopover = defineComponent({
|
|
|
54
54
|
let generation = 0
|
|
55
55
|
let mounted = false
|
|
56
56
|
let reason: PopoverCloseReason = 'program'
|
|
57
|
+
function returnTarget() {
|
|
58
|
+
return (
|
|
59
|
+
trigger.value?.$el ??
|
|
60
|
+
anchor.value?.querySelector<HTMLElement>(
|
|
61
|
+
'button:not(:disabled), [href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex="0"]',
|
|
62
|
+
) ??
|
|
63
|
+
anchor.value
|
|
64
|
+
)
|
|
65
|
+
}
|
|
57
66
|
function owns(target: EventTarget | null) {
|
|
58
67
|
return (
|
|
59
68
|
target instanceof Node && (anchor.value?.contains(target) || panel.value?.contains(target))
|
|
@@ -179,7 +188,7 @@ export const MPopover = defineComponent({
|
|
|
179
188
|
const focused =
|
|
180
189
|
typeof document !== 'undefined' && panel.value?.contains(document.activeElement)
|
|
181
190
|
detach()
|
|
182
|
-
if (focused && reason !== 'outside')
|
|
191
|
+
if (focused && reason !== 'outside') returnTarget()?.focus({ preventScroll: true })
|
|
183
192
|
}
|
|
184
193
|
},
|
|
185
194
|
)
|
|
@@ -227,28 +236,33 @@ export const MPopover = defineComponent({
|
|
|
227
236
|
{
|
|
228
237
|
ref: anchor,
|
|
229
238
|
class: 'm-popover-anchor',
|
|
230
|
-
style: {
|
|
239
|
+
style: {
|
|
240
|
+
display: slots.anchor ? 'block' : 'inline-flex',
|
|
241
|
+
alignSelf: slots.anchor ? 'stretch' : 'flex-start',
|
|
242
|
+
},
|
|
243
|
+
tabindex: slots.anchor ? -1 : undefined,
|
|
231
244
|
},
|
|
232
245
|
attrs,
|
|
233
246
|
),
|
|
234
247
|
[
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
event.
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
248
|
+
slots.anchor?.() ??
|
|
249
|
+
h(MButton, {
|
|
250
|
+
ref: trigger,
|
|
251
|
+
text: props.triggerLabel,
|
|
252
|
+
icon: props.icon,
|
|
253
|
+
variant: props.variant,
|
|
254
|
+
disabled: props.disabled,
|
|
255
|
+
'aria-haspopup': props.role,
|
|
256
|
+
'aria-expanded': props.open,
|
|
257
|
+
'aria-controls': panelId,
|
|
258
|
+
onClick: () => (props.open ? close('trigger') : emit('update:open', true)),
|
|
259
|
+
onKeydown: (event: KeyboardEvent) => {
|
|
260
|
+
if (event.key === 'ArrowDown' && !props.open) {
|
|
261
|
+
event.preventDefault()
|
|
262
|
+
emit('update:open', true)
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
}),
|
|
252
266
|
host.value
|
|
253
267
|
? h(
|
|
254
268
|
Teleport,
|
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineComponent,
|
|
3
|
+
h,
|
|
4
|
+
mergeProps,
|
|
5
|
+
onMounted,
|
|
6
|
+
onBeforeUnmount,
|
|
7
|
+
onActivated,
|
|
8
|
+
onDeactivated,
|
|
9
|
+
ref,
|
|
10
|
+
watch,
|
|
11
|
+
type PropType,
|
|
12
|
+
} from 'vue'
|
|
13
|
+
import {
|
|
14
|
+
createTreeSelect,
|
|
15
|
+
createMasonry,
|
|
16
|
+
createHeatmap,
|
|
17
|
+
createNotificationCenter,
|
|
18
|
+
createImageCropper,
|
|
19
|
+
createScheduler,
|
|
20
|
+
advancedCanvasProps,
|
|
21
|
+
advancedCellProps,
|
|
22
|
+
advancedGestureProps,
|
|
23
|
+
type AdvancedGesture,
|
|
24
|
+
} from '@getcortexlabs/mavis-core/vue'
|
|
25
|
+
import { civilDate, type CropSource, type SchedulerClock } from '@getcortexlabs/mavis-core'
|
|
26
|
+
import type { MotionSurface } from '@getcortexlabs/mavis-core/experimental'
|
|
27
|
+
import { loadCropImage } from '../image-crop.js'
|
|
28
|
+
import { MBox, MColumn, MRow } from './layout.js'
|
|
29
|
+
import { MStack } from './MStack.js'
|
|
30
|
+
import { MCard } from './MCard.js'
|
|
31
|
+
import { MText } from './MText.js'
|
|
32
|
+
import { MButton } from './MButton.js'
|
|
33
|
+
import { MInput } from './MInput.js'
|
|
34
|
+
import { MImage } from './MImage.js'
|
|
35
|
+
import { MCheckbox } from './MCheckbox.js'
|
|
36
|
+
import { MSlider } from './MSlider.js'
|
|
37
|
+
import { MPopover } from './MPopover.js'
|
|
38
|
+
const Host = defineComponent({
|
|
39
|
+
inheritAttrs: false,
|
|
40
|
+
props: { label: String },
|
|
41
|
+
setup(props, { attrs, slots, expose }) {
|
|
42
|
+
const root = ref<HTMLElement>()
|
|
43
|
+
expose({
|
|
44
|
+
focus(id?: string) {
|
|
45
|
+
const el = id ? root.value?.ownerDocument.getElementById(id) : root.value
|
|
46
|
+
if (el && root.value?.contains(el)) el.focus({ preventScroll: true })
|
|
47
|
+
},
|
|
48
|
+
})
|
|
49
|
+
return () =>
|
|
50
|
+
h(
|
|
51
|
+
'section',
|
|
52
|
+
mergeProps(attrs, {
|
|
53
|
+
ref: root,
|
|
54
|
+
'aria-label': props.label,
|
|
55
|
+
tabindex: -1,
|
|
56
|
+
style: { minWidth: 0 },
|
|
57
|
+
}),
|
|
58
|
+
slots.default?.(),
|
|
59
|
+
)
|
|
60
|
+
},
|
|
61
|
+
})
|
|
62
|
+
function measured(cell: boolean) {
|
|
63
|
+
return defineComponent({
|
|
64
|
+
inheritAttrs: false,
|
|
65
|
+
props: { ...advancedCellProps, width: { type: Number, default: 0 } },
|
|
66
|
+
emits: ['width', 'height'],
|
|
67
|
+
setup(props, { attrs, slots, emit }) {
|
|
68
|
+
const root = ref<HTMLElement>()
|
|
69
|
+
let observer: ResizeObserver | undefined,
|
|
70
|
+
last = -1,
|
|
71
|
+
frame = 0
|
|
72
|
+
function measure() {
|
|
73
|
+
const el = root.value
|
|
74
|
+
if (!el) return
|
|
75
|
+
if (cell && !props.measure) return
|
|
76
|
+
const v = cell ? el.offsetHeight : el.clientWidth
|
|
77
|
+
if (Math.abs(v - last) > 0.5) {
|
|
78
|
+
last = v
|
|
79
|
+
emit(cell ? 'height' : 'width', v)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function detach() {
|
|
83
|
+
cancelAnimationFrame(frame)
|
|
84
|
+
frame = 0
|
|
85
|
+
observer?.disconnect()
|
|
86
|
+
observer = undefined
|
|
87
|
+
}
|
|
88
|
+
function schedule() {
|
|
89
|
+
if (!frame)
|
|
90
|
+
frame = requestAnimationFrame(() => {
|
|
91
|
+
frame = 0
|
|
92
|
+
measure()
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
function attach() {
|
|
96
|
+
detach()
|
|
97
|
+
if (!root.value) return
|
|
98
|
+
if (cell && !props.measure) return
|
|
99
|
+
observer = new ResizeObserver(schedule)
|
|
100
|
+
observer.observe(root.value)
|
|
101
|
+
schedule()
|
|
102
|
+
}
|
|
103
|
+
onMounted(attach)
|
|
104
|
+
onActivated(attach)
|
|
105
|
+
onDeactivated(detach)
|
|
106
|
+
onBeforeUnmount(detach)
|
|
107
|
+
return () =>
|
|
108
|
+
cell
|
|
109
|
+
? h(
|
|
110
|
+
'div',
|
|
111
|
+
mergeProps(attrs, {
|
|
112
|
+
style: {
|
|
113
|
+
position: 'absolute',
|
|
114
|
+
left: `${props.x}px`,
|
|
115
|
+
top: `${props.y}px`,
|
|
116
|
+
width: `${props.width}px`,
|
|
117
|
+
height: props.height === undefined ? undefined : `${props.height}px`,
|
|
118
|
+
},
|
|
119
|
+
}),
|
|
120
|
+
h(
|
|
121
|
+
MBox,
|
|
122
|
+
{ width: '100%', height: props.height === undefined ? undefined : '100%' },
|
|
123
|
+
() =>
|
|
124
|
+
h(
|
|
125
|
+
'div',
|
|
126
|
+
{
|
|
127
|
+
ref: root,
|
|
128
|
+
style: {
|
|
129
|
+
display: 'flow-root',
|
|
130
|
+
height: props.height === undefined ? undefined : '100%',
|
|
131
|
+
minWidth: 0,
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
slots.default?.(),
|
|
135
|
+
),
|
|
136
|
+
),
|
|
137
|
+
)
|
|
138
|
+
: h(
|
|
139
|
+
'div',
|
|
140
|
+
mergeProps(attrs, { ref: root, style: { minWidth: 0, width: '100%' } }),
|
|
141
|
+
slots.default?.(),
|
|
142
|
+
)
|
|
143
|
+
},
|
|
144
|
+
})
|
|
145
|
+
}
|
|
146
|
+
const Measure = measured(false),
|
|
147
|
+
Cell = measured(true)
|
|
148
|
+
const Canvas = defineComponent({
|
|
149
|
+
props: advancedCanvasProps,
|
|
150
|
+
setup(props, { slots }) {
|
|
151
|
+
return () =>
|
|
152
|
+
h(
|
|
153
|
+
'div',
|
|
154
|
+
{
|
|
155
|
+
style: {
|
|
156
|
+
position: 'relative',
|
|
157
|
+
height: `${props.height}px`,
|
|
158
|
+
width: props.width === undefined ? '100%' : `${props.width}px`,
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
slots.default?.(),
|
|
162
|
+
)
|
|
163
|
+
},
|
|
164
|
+
})
|
|
165
|
+
const Scroll = defineComponent({
|
|
166
|
+
setup(_, { slots }) {
|
|
167
|
+
return () =>
|
|
168
|
+
h('div', { style: { overflowX: 'auto', minWidth: 0, maxWidth: '100%' } }, slots.default?.())
|
|
169
|
+
},
|
|
170
|
+
})
|
|
171
|
+
const Gesture = defineComponent({
|
|
172
|
+
inheritAttrs: false,
|
|
173
|
+
props: advancedGestureProps,
|
|
174
|
+
emits: ['gesture', 'step'],
|
|
175
|
+
setup(props, { attrs, slots, emit }) {
|
|
176
|
+
const root = ref<HTMLElement>()
|
|
177
|
+
const points = new Map<number, { x: number; y: number }>()
|
|
178
|
+
let origin = { x: 0, y: 0 },
|
|
179
|
+
distance = 0,
|
|
180
|
+
last = { x: 0, y: 0, scale: 1 },
|
|
181
|
+
active = false
|
|
182
|
+
function metrics() {
|
|
183
|
+
const values = [...points.values()]
|
|
184
|
+
return {
|
|
185
|
+
x: values.reduce((a, p) => a + p.x, 0) / values.length,
|
|
186
|
+
y: values.reduce((a, p) => a + p.y, 0) / values.length,
|
|
187
|
+
distance:
|
|
188
|
+
values.length === 2
|
|
189
|
+
? Math.hypot(values[0]!.x - values[1]!.x, values[0]!.y - values[1]!.y)
|
|
190
|
+
: 0,
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function send(phase: AdvancedGesture['phase']) {
|
|
194
|
+
emit('gesture', { phase, ...last })
|
|
195
|
+
}
|
|
196
|
+
function clear(cancel = true) {
|
|
197
|
+
if (active) {
|
|
198
|
+
active = false
|
|
199
|
+
send(cancel ? 'cancel' : 'end')
|
|
200
|
+
}
|
|
201
|
+
for (const id of points.keys()) {
|
|
202
|
+
if (root.value?.hasPointerCapture(id)) root.value.releasePointerCapture(id)
|
|
203
|
+
}
|
|
204
|
+
points.clear()
|
|
205
|
+
distance = 0
|
|
206
|
+
last = { x: 0, y: 0, scale: 1 }
|
|
207
|
+
}
|
|
208
|
+
function down(e: PointerEvent) {
|
|
209
|
+
if (props.disabled || e.button !== 0 || points.size >= 2) return
|
|
210
|
+
e.preventDefault()
|
|
211
|
+
root.value?.focus({ preventScroll: true })
|
|
212
|
+
points.set(e.pointerId, { x: e.clientX, y: e.clientY })
|
|
213
|
+
root.value?.setPointerCapture(e.pointerId)
|
|
214
|
+
const m = metrics()
|
|
215
|
+
origin = { x: m.x - last.x, y: m.y - last.y }
|
|
216
|
+
distance = m.distance / last.scale
|
|
217
|
+
if (!active) {
|
|
218
|
+
active = true
|
|
219
|
+
send('start')
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
function move(e: PointerEvent) {
|
|
223
|
+
if (!points.has(e.pointerId)) return
|
|
224
|
+
points.set(e.pointerId, { x: e.clientX, y: e.clientY })
|
|
225
|
+
const m = metrics()
|
|
226
|
+
last = {
|
|
227
|
+
x: m.x - origin.x,
|
|
228
|
+
y: m.y - origin.y,
|
|
229
|
+
scale: distance && m.distance ? m.distance / distance : last.scale,
|
|
230
|
+
}
|
|
231
|
+
send('move')
|
|
232
|
+
}
|
|
233
|
+
function up(e: PointerEvent) {
|
|
234
|
+
if (!points.has(e.pointerId)) return
|
|
235
|
+
if (points.size === 1) {
|
|
236
|
+
clear(false)
|
|
237
|
+
return
|
|
238
|
+
}
|
|
239
|
+
points.delete(e.pointerId)
|
|
240
|
+
if (root.value?.hasPointerCapture(e.pointerId)) root.value.releasePointerCapture(e.pointerId)
|
|
241
|
+
const m = metrics()
|
|
242
|
+
origin = { x: m.x - last.x, y: m.y - last.y }
|
|
243
|
+
distance = 0
|
|
244
|
+
}
|
|
245
|
+
function cancel() {
|
|
246
|
+
clear()
|
|
247
|
+
}
|
|
248
|
+
function attach() {
|
|
249
|
+
window.addEventListener('resize', cancel)
|
|
250
|
+
window.addEventListener('blur', cancel)
|
|
251
|
+
window.addEventListener('scroll', cancel, true)
|
|
252
|
+
}
|
|
253
|
+
function detach() {
|
|
254
|
+
cancel()
|
|
255
|
+
window.removeEventListener('resize', cancel)
|
|
256
|
+
window.removeEventListener('blur', cancel)
|
|
257
|
+
window.removeEventListener('scroll', cancel, true)
|
|
258
|
+
}
|
|
259
|
+
onMounted(attach)
|
|
260
|
+
onActivated(attach)
|
|
261
|
+
onDeactivated(detach)
|
|
262
|
+
onBeforeUnmount(detach)
|
|
263
|
+
watch(() => props.disabled, cancel)
|
|
264
|
+
return () =>
|
|
265
|
+
h(
|
|
266
|
+
'div',
|
|
267
|
+
mergeProps(attrs, {
|
|
268
|
+
ref: root,
|
|
269
|
+
role: 'group',
|
|
270
|
+
'aria-label': props.label,
|
|
271
|
+
'aria-disabled': props.disabled || undefined,
|
|
272
|
+
tabindex: props.disabled ? -1 : 0,
|
|
273
|
+
style: {
|
|
274
|
+
touchAction: props.disabled ? 'auto' : 'none',
|
|
275
|
+
cursor: props.disabled ? 'default' : 'grab',
|
|
276
|
+
userSelect: 'none',
|
|
277
|
+
},
|
|
278
|
+
onPointerdown: down,
|
|
279
|
+
onPointermove: move,
|
|
280
|
+
onPointerup: up,
|
|
281
|
+
onPointercancel: cancel,
|
|
282
|
+
onLostpointercapture: (e: PointerEvent) => {
|
|
283
|
+
if (points.has(e.pointerId)) cancel()
|
|
284
|
+
},
|
|
285
|
+
onKeydown: (e: KeyboardEvent) => {
|
|
286
|
+
if (e.key === 'Escape') {
|
|
287
|
+
e.preventDefault()
|
|
288
|
+
cancel()
|
|
289
|
+
}
|
|
290
|
+
if (props.disabled) return
|
|
291
|
+
const d: Record<string, [number, number]> = {
|
|
292
|
+
ArrowLeft: [-1, 0],
|
|
293
|
+
ArrowRight: [1, 0],
|
|
294
|
+
ArrowUp: [0, -1],
|
|
295
|
+
ArrowDown: [0, 1],
|
|
296
|
+
}
|
|
297
|
+
if (d[e.key]) {
|
|
298
|
+
e.preventDefault()
|
|
299
|
+
emit('step', { x: d[e.key]![0], y: d[e.key]![1] })
|
|
300
|
+
}
|
|
301
|
+
},
|
|
302
|
+
}),
|
|
303
|
+
slots.default?.(),
|
|
304
|
+
)
|
|
305
|
+
},
|
|
306
|
+
})
|
|
307
|
+
const CropPreview = defineComponent({
|
|
308
|
+
props: {
|
|
309
|
+
source: { type: Object as PropType<CropSource>, required: true },
|
|
310
|
+
width: Number,
|
|
311
|
+
height: Number,
|
|
312
|
+
motionSurface: Object as PropType<MotionSurface>,
|
|
313
|
+
},
|
|
314
|
+
setup(props) {
|
|
315
|
+
return () =>
|
|
316
|
+
h(
|
|
317
|
+
MBox,
|
|
318
|
+
{
|
|
319
|
+
width: props.width,
|
|
320
|
+
height: props.height,
|
|
321
|
+
motionSurface: props.motionSurface,
|
|
322
|
+
style: { position: 'absolute', left: 0, top: 0, pointerEvents: 'none' },
|
|
323
|
+
},
|
|
324
|
+
() =>
|
|
325
|
+
h('img', {
|
|
326
|
+
src: props.source!.preview,
|
|
327
|
+
alt: '',
|
|
328
|
+
draggable: false,
|
|
329
|
+
width: props.width,
|
|
330
|
+
height: props.height,
|
|
331
|
+
style: { display: 'block', maxWidth: 'none', width: '100%', height: '100%' },
|
|
332
|
+
}),
|
|
333
|
+
)
|
|
334
|
+
},
|
|
335
|
+
})
|
|
336
|
+
const formats = new Map<string, Intl.DateTimeFormat>()
|
|
337
|
+
export const schedulerClock: SchedulerClock = {
|
|
338
|
+
parts(instant, timeZone) {
|
|
339
|
+
let format = formats.get(timeZone)
|
|
340
|
+
if (!format) {
|
|
341
|
+
format = new Intl.DateTimeFormat('en-CA', {
|
|
342
|
+
timeZone,
|
|
343
|
+
year: 'numeric',
|
|
344
|
+
month: '2-digit',
|
|
345
|
+
day: '2-digit',
|
|
346
|
+
hour: '2-digit',
|
|
347
|
+
minute: '2-digit',
|
|
348
|
+
hourCycle: 'h23',
|
|
349
|
+
})
|
|
350
|
+
if (formats.size >= 32) formats.clear()
|
|
351
|
+
formats.set(timeZone, format)
|
|
352
|
+
}
|
|
353
|
+
const parts = Object.fromEntries(format.formatToParts(instant).map((p) => [p.type, p.value]))
|
|
354
|
+
return {
|
|
355
|
+
date: civilDate(`${parts.year!.padStart(4, '0')}-${parts.month}-${parts.day}`),
|
|
356
|
+
minute: Number(parts.hour) * 60 + Number(parts.minute),
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
}
|
|
360
|
+
const ui = {
|
|
361
|
+
Box: MBox,
|
|
362
|
+
Column: MColumn,
|
|
363
|
+
Row: MRow,
|
|
364
|
+
Stack: MStack,
|
|
365
|
+
Card: MCard,
|
|
366
|
+
Text: MText,
|
|
367
|
+
Button: MButton,
|
|
368
|
+
Input: MInput,
|
|
369
|
+
Image: MImage,
|
|
370
|
+
Checkbox: MCheckbox,
|
|
371
|
+
Slider: MSlider,
|
|
372
|
+
Popover: MPopover,
|
|
373
|
+
Segmented: MBox,
|
|
374
|
+
Host,
|
|
375
|
+
Measure,
|
|
376
|
+
Cell,
|
|
377
|
+
Canvas,
|
|
378
|
+
Scroll,
|
|
379
|
+
Gesture,
|
|
380
|
+
CropPreview,
|
|
381
|
+
}
|
|
382
|
+
export const MTreeSelect = createTreeSelect(ui, 'web')
|
|
383
|
+
export const MMasonry = createMasonry(ui, 'web')
|
|
384
|
+
export const MHeatmap = createHeatmap(ui, 'web')
|
|
385
|
+
export const MNotificationCenter = createNotificationCenter(ui, 'web')
|
|
386
|
+
export const MImageCropper = createImageCropper(ui, 'web', loadCropImage)
|
|
387
|
+
export const MScheduler = createScheduler(ui, 'web', schedulerClock)
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineComponent,
|
|
3
|
+
h,
|
|
4
|
+
mergeProps,
|
|
5
|
+
nextTick,
|
|
6
|
+
onMounted,
|
|
7
|
+
onBeforeUnmount,
|
|
8
|
+
onActivated,
|
|
9
|
+
onDeactivated,
|
|
10
|
+
ref,
|
|
11
|
+
watch,
|
|
12
|
+
type PropType,
|
|
13
|
+
} from 'vue'
|
|
14
|
+
import {
|
|
15
|
+
createColorPicker,
|
|
16
|
+
createGauge,
|
|
17
|
+
createSwipeDeck,
|
|
18
|
+
createTransferList,
|
|
19
|
+
createTour,
|
|
20
|
+
createMarquee,
|
|
21
|
+
tourHostProps,
|
|
22
|
+
marqueeHostProps,
|
|
23
|
+
} from '@getcortexlabs/mavis-core/vue'
|
|
24
|
+
import type { gaugeGeometry } from '@getcortexlabs/mavis-core'
|
|
25
|
+
import { MBox, MColumn, MRow } from './layout.js'
|
|
26
|
+
import { MStack } from './MStack.js'
|
|
27
|
+
import { MCard } from './MCard.js'
|
|
28
|
+
import { MText } from './MText.js'
|
|
29
|
+
import { MInput } from './MInput.js'
|
|
30
|
+
import { MImage } from './MImage.js'
|
|
31
|
+
import { MButton } from './MButton.js'
|
|
32
|
+
import { MSlider } from './MSlider.js'
|
|
33
|
+
import { MCheckbox } from './MCheckbox.js'
|
|
34
|
+
import { MNumberFlow } from './interactive.js'
|
|
35
|
+
import { MPopover } from './MPopover.js'
|
|
36
|
+
|
|
37
|
+
const GaugeFallback = defineComponent({
|
|
38
|
+
props: {
|
|
39
|
+
geometry: { type: Object as PropType<ReturnType<typeof gaugeGeometry>>, required: true },
|
|
40
|
+
size: Number,
|
|
41
|
+
strokeWidth: Number,
|
|
42
|
+
color: String,
|
|
43
|
+
track: String,
|
|
44
|
+
hidden: Boolean,
|
|
45
|
+
},
|
|
46
|
+
setup(props) {
|
|
47
|
+
return () =>
|
|
48
|
+
h(
|
|
49
|
+
'svg',
|
|
50
|
+
{
|
|
51
|
+
viewBox: props.geometry.viewBox.join(' '),
|
|
52
|
+
width: '100%',
|
|
53
|
+
height: '100%',
|
|
54
|
+
'aria-hidden': true,
|
|
55
|
+
style: { gridArea: '1 / 1', visibility: props.hidden ? 'hidden' : 'visible' },
|
|
56
|
+
},
|
|
57
|
+
[
|
|
58
|
+
h('path', {
|
|
59
|
+
d: props.geometry.path,
|
|
60
|
+
fill: 'none',
|
|
61
|
+
stroke: props.track,
|
|
62
|
+
'stroke-width': props.strokeWidth,
|
|
63
|
+
'stroke-linecap': 'round',
|
|
64
|
+
}),
|
|
65
|
+
h('path', {
|
|
66
|
+
d: props.geometry.path,
|
|
67
|
+
fill: 'none',
|
|
68
|
+
stroke: props.color,
|
|
69
|
+
'stroke-width': props.strokeWidth,
|
|
70
|
+
'stroke-linecap': 'round',
|
|
71
|
+
pathLength: 1,
|
|
72
|
+
'stroke-dasharray': `${props.geometry.ratio} 1`,
|
|
73
|
+
}),
|
|
74
|
+
],
|
|
75
|
+
)
|
|
76
|
+
},
|
|
77
|
+
})
|
|
78
|
+
const TourHost = defineComponent({
|
|
79
|
+
inheritAttrs: false,
|
|
80
|
+
props: tourHostProps,
|
|
81
|
+
setup(props, { attrs, slots }) {
|
|
82
|
+
let saved: HTMLElement | null = null,
|
|
83
|
+
lastFocused: HTMLElement | null = null
|
|
84
|
+
const remember = (event: Event) => {
|
|
85
|
+
if (props.active) return
|
|
86
|
+
const element =
|
|
87
|
+
event.target instanceof Element
|
|
88
|
+
? event.target.closest<HTMLElement>(
|
|
89
|
+
'button, a[href], input, select, textarea, [tabindex]',
|
|
90
|
+
)
|
|
91
|
+
: null
|
|
92
|
+
if (element) lastFocused = element
|
|
93
|
+
}
|
|
94
|
+
onMounted(() => {
|
|
95
|
+
document.addEventListener('focusin', remember, true)
|
|
96
|
+
document.addEventListener('pointerdown', remember, true)
|
|
97
|
+
})
|
|
98
|
+
onBeforeUnmount(() => {
|
|
99
|
+
document.removeEventListener('focusin', remember, true)
|
|
100
|
+
document.removeEventListener('pointerdown', remember, true)
|
|
101
|
+
})
|
|
102
|
+
watch(
|
|
103
|
+
() => props.active,
|
|
104
|
+
(active, wasActive) => {
|
|
105
|
+
if (typeof document === 'undefined') return
|
|
106
|
+
if (active && !wasActive)
|
|
107
|
+
saved =
|
|
108
|
+
document.activeElement instanceof HTMLElement &&
|
|
109
|
+
document.activeElement !== document.body
|
|
110
|
+
? document.activeElement
|
|
111
|
+
: lastFocused
|
|
112
|
+
else if (!active)
|
|
113
|
+
void nextTick(() => {
|
|
114
|
+
if (!props.active && props.restoreFocus && saved?.isConnected)
|
|
115
|
+
saved.focus({ preventScroll: true })
|
|
116
|
+
saved = null
|
|
117
|
+
})
|
|
118
|
+
},
|
|
119
|
+
{ immediate: true, flush: 'pre' },
|
|
120
|
+
)
|
|
121
|
+
return () => h('div', attrs, slots.default?.())
|
|
122
|
+
},
|
|
123
|
+
})
|
|
124
|
+
const TargetHost = defineComponent({
|
|
125
|
+
inheritAttrs: false,
|
|
126
|
+
props: tourHostProps,
|
|
127
|
+
setup(props, { attrs, slots }) {
|
|
128
|
+
const root = ref<HTMLElement>()
|
|
129
|
+
const reveal = () => {
|
|
130
|
+
if (props.active)
|
|
131
|
+
root.value?.scrollIntoView({ block: 'nearest', inline: 'nearest', behavior: 'instant' })
|
|
132
|
+
}
|
|
133
|
+
watch(
|
|
134
|
+
() => props.active,
|
|
135
|
+
() => void nextTick(reveal),
|
|
136
|
+
{ flush: 'post' },
|
|
137
|
+
)
|
|
138
|
+
onMounted(reveal)
|
|
139
|
+
return () => h('div', mergeProps(attrs, { ref: root }), slots.default?.())
|
|
140
|
+
},
|
|
141
|
+
})
|
|
142
|
+
const MarqueeHost = defineComponent({
|
|
143
|
+
inheritAttrs: false,
|
|
144
|
+
props: marqueeHostProps,
|
|
145
|
+
emits: ['environment'],
|
|
146
|
+
setup(_props, { attrs, slots, emit }) {
|
|
147
|
+
const root = ref<HTMLElement>()
|
|
148
|
+
let media: MediaQueryList | undefined,
|
|
149
|
+
resize: ResizeObserver | undefined,
|
|
150
|
+
intersection: IntersectionObserver | undefined
|
|
151
|
+
let hovered = false,
|
|
152
|
+
focused = false,
|
|
153
|
+
visible = true,
|
|
154
|
+
attached = false
|
|
155
|
+
const update = () =>
|
|
156
|
+
emit('environment', {
|
|
157
|
+
reduced: media?.matches ?? true,
|
|
158
|
+
paused: !attached || document.hidden || hovered || focused || !visible,
|
|
159
|
+
width: root.value?.clientWidth ?? 0,
|
|
160
|
+
})
|
|
161
|
+
function attach() {
|
|
162
|
+
if (attached || !root.value) return
|
|
163
|
+
attached = true
|
|
164
|
+
media = matchMedia('(prefers-reduced-motion: reduce)')
|
|
165
|
+
media.addEventListener('change', update)
|
|
166
|
+
resize = new ResizeObserver(update)
|
|
167
|
+
resize.observe(root.value)
|
|
168
|
+
intersection = new IntersectionObserver(([entry]) => {
|
|
169
|
+
visible = entry?.isIntersecting ?? false
|
|
170
|
+
update()
|
|
171
|
+
})
|
|
172
|
+
intersection.observe(root.value)
|
|
173
|
+
document.addEventListener('visibilitychange', update)
|
|
174
|
+
update()
|
|
175
|
+
}
|
|
176
|
+
function detach() {
|
|
177
|
+
attached = false
|
|
178
|
+
media?.removeEventListener('change', update)
|
|
179
|
+
resize?.disconnect()
|
|
180
|
+
intersection?.disconnect()
|
|
181
|
+
document.removeEventListener('visibilitychange', update)
|
|
182
|
+
update()
|
|
183
|
+
}
|
|
184
|
+
onMounted(attach)
|
|
185
|
+
onActivated(attach)
|
|
186
|
+
onDeactivated(detach)
|
|
187
|
+
onBeforeUnmount(detach)
|
|
188
|
+
return () =>
|
|
189
|
+
h(
|
|
190
|
+
'div',
|
|
191
|
+
mergeProps(attrs, {
|
|
192
|
+
ref: root,
|
|
193
|
+
style: { overflow: 'hidden', minWidth: 0, width: '100%' },
|
|
194
|
+
onMouseenter: () => {
|
|
195
|
+
hovered = true
|
|
196
|
+
update()
|
|
197
|
+
},
|
|
198
|
+
onMouseleave: () => {
|
|
199
|
+
hovered = false
|
|
200
|
+
update()
|
|
201
|
+
},
|
|
202
|
+
onFocusin: () => {
|
|
203
|
+
focused = true
|
|
204
|
+
update()
|
|
205
|
+
},
|
|
206
|
+
onFocusout: (event: FocusEvent) => {
|
|
207
|
+
focused =
|
|
208
|
+
event.relatedTarget instanceof Node && !!root.value?.contains(event.relatedTarget)
|
|
209
|
+
update()
|
|
210
|
+
},
|
|
211
|
+
}),
|
|
212
|
+
slots.default?.(),
|
|
213
|
+
)
|
|
214
|
+
},
|
|
215
|
+
})
|
|
216
|
+
const ui = {
|
|
217
|
+
Box: MBox,
|
|
218
|
+
Column: MColumn,
|
|
219
|
+
Row: MRow,
|
|
220
|
+
Stack: MStack,
|
|
221
|
+
Card: MCard,
|
|
222
|
+
Text: MText,
|
|
223
|
+
Input: MInput,
|
|
224
|
+
Image: MImage,
|
|
225
|
+
Button: MButton,
|
|
226
|
+
Slider: MSlider,
|
|
227
|
+
Checkbox: MCheckbox,
|
|
228
|
+
NumberFlow: MNumberFlow,
|
|
229
|
+
GaugeFallback,
|
|
230
|
+
MarqueeHost,
|
|
231
|
+
}
|
|
232
|
+
export const MColorPicker = createColorPicker(ui, 'web')
|
|
233
|
+
export const MGauge = createGauge(ui, 'web')
|
|
234
|
+
export const MSwipeDeck = createSwipeDeck(ui, 'web')
|
|
235
|
+
export const MTransferList = createTransferList(ui, 'web')
|
|
236
|
+
export const MMarquee = createMarquee(ui, 'web')
|
|
237
|
+
export const { MTour, MTourTarget } = createTour(
|
|
238
|
+
{ ...ui, Popover: MPopover, Host: TourHost, TargetHost },
|
|
239
|
+
'web',
|
|
240
|
+
)
|