@meistrari/tela-build 1.77.4 → 1.78.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.
@@ -1,5 +1,6 @@
1
1
  <script setup lang="ts">
2
- import { computed, useAttrs, watch } from 'vue'
2
+ import { computed, reactive, ref, useAttrs, watch } from 'vue'
3
+ import { useResizeObserver } from '@vueuse/core'
3
4
 
4
5
  import {
5
6
  DialogClose,
@@ -12,14 +13,30 @@ import {
12
13
  VisuallyHidden,
13
14
  } from 'radix-vue'
14
15
 
16
+ type SlotProps = { close: () => void }
17
+
15
18
  defineOptions({
16
19
  inheritAttrs: false,
17
20
  })
18
21
 
19
22
  const props = withDefaults(defineProps<{
23
+ /**
24
+ * Opts into the modal layout: built-in header (title, description, close), scrollable body and footer.
25
+ * `sm` 320px, `md` 480px, `lg` 840px. Without it the legacy layout renders, driven by `modalWidth`.
26
+ */
27
+ size?: 'sm' | 'md' | 'lg'
20
28
  title?: string
29
+ /** Supporting text under the title. Requires `size`. */
30
+ description?: string
31
+ /** Blocks Escape, outside clicks and the close button (e.g. while saving). Programmatic closes still work. */
32
+ preventClose?: boolean
33
+ /** Accessible label of the close button. */
34
+ closeLabel?: string
35
+ /** @deprecated Legacy layout only. Use `size`; see the Modal changelog entry. */
21
36
  modalWidth?: 'sm' | 'md' | 'lg' | 'xl'
37
+ /** @deprecated Legacy layout only. Use `size`; see the Modal changelog entry. */
22
38
  compact?: boolean
39
+ /** Hides the hairlines that appear while the body scrolls under the header or footer. */
23
40
  hideDividers?: boolean
24
41
  hideHeader?: boolean
25
42
  overlayClass?: string
@@ -28,11 +45,14 @@ const props = withDefaults(defineProps<{
28
45
  fullscreen?: boolean
29
46
  dialogContentClass?: string
30
47
  isCloseIcon?: boolean
48
+ /** @deprecated Legacy layout only. Use `size`; see the Modal changelog entry. */
31
49
  isCloseIconAbsolute?: boolean
50
+ /** @deprecated Legacy layout only. Use `size`; see the Modal changelog entry. */
32
51
  smallTitle?: boolean
33
52
  titleClass?: string
34
53
  hideEnterAnimation?: boolean
35
54
  }>(), {
55
+ closeLabel: 'Close',
36
56
  modalWidth: 'md',
37
57
  isCloseIcon: true,
38
58
  isCloseIconAbsolute: false,
@@ -43,8 +63,21 @@ const emit = defineEmits<{
43
63
  close: []
44
64
  }>()
45
65
 
66
+ const slots = defineSlots<{
67
+ 'default'?: (props: SlotProps) => unknown
68
+ 'content'?: (props: SlotProps) => unknown
69
+ 'header'?: (props: SlotProps) => unknown
70
+ 'header-leading'?: () => unknown
71
+ 'title'?: (props: SlotProps) => unknown
72
+ 'description'?: (props: SlotProps) => unknown
73
+ 'actions'?: (props: SlotProps) => unknown
74
+ 'footer'?: (props: SlotProps) => unknown
75
+ }>()
76
+
46
77
  const attrs = useAttrs()
47
78
 
79
+ const isLegacy = computed(() => !props.size)
80
+
48
81
  const forwardedAttrs = computed(() => {
49
82
  const { onPointerDownOutside, ...rest } = attrs as Record<string, unknown>
50
83
  return rest
@@ -58,10 +91,92 @@ watch(open, (value) => {
58
91
  }
59
92
  })
60
93
 
94
+ function close() {
95
+ open.value = false
96
+ }
97
+
61
98
  const modalMaxWidth = computed(() => {
62
99
  return props.modalWidth === 'xl' ? 'max-w-1024px' : props.modalWidth === 'lg' ? 'max-w-900px' : props.modalWidth === 'sm' ? 'max-w-300px' : 'max-w-500px'
63
100
  })
64
101
 
102
+ const hasTitle = computed(() => Boolean(props.title || slots.title))
103
+ const hasDescription = computed(() => Boolean(props.description || slots.description))
104
+ const showHeader = computed(() => !props.hideHeader && Boolean(hasTitle.value || hasDescription.value || slots.header || slots.actions || props.isCloseIcon))
105
+ const showHeading = computed(() => showHeader.value && !slots.header)
106
+
107
+ const describedBy = computed(() => {
108
+ if ('aria-describedby' in attrs)
109
+ return {}
110
+
111
+ const rendersDescription = isLegacy.value ? !props.hideHeader : hasDescription.value
112
+ return rendersDescription ? {} : { 'aria-describedby': undefined }
113
+ })
114
+
115
+ const bodyRef = ref<HTMLElement>()
116
+ const bodyViewport = computed(() => bodyRef.value?.closest<HTMLElement>('[data-reka-scroll-area-viewport]') ?? undefined)
117
+ const scrollEdges = reactive({ top: false, bottom: false })
118
+
119
+ function measureScroll() {
120
+ const viewport = bodyViewport.value
121
+ if (!viewport)
122
+ return
123
+
124
+ scrollEdges.top = viewport.scrollTop > 0
125
+ scrollEdges.bottom = Math.ceil(viewport.scrollTop + viewport.clientHeight) < viewport.scrollHeight
126
+ }
127
+
128
+ useResizeObserver(bodyRef, measureScroll)
129
+ useResizeObserver(bodyViewport, measureScroll)
130
+
131
+ const sizedAttrs = computed(() => {
132
+ const { class: _class, ...rest } = forwardedAttrs.value
133
+
134
+ return rest
135
+ })
136
+
137
+ const sizedOverlayClass = computed(() => cn(
138
+ 'fixed inset-0 z-600 flex items-center justify-center p-[16px] bg-#000/48',
139
+ // same timing as the popover-enter-exit content (css/animations.css)
140
+ 'overlay-enter-exit',
141
+ props.fullscreen && 'p-0',
142
+ props.overlayClass,
143
+ ))
144
+
145
+ const sizedContentClass = computed(() => cn(
146
+ 'relative flex flex-col w-full max-h-full overflow-hidden rounded-[20px] bg-background outline-none',
147
+ { sm: 'max-w-[320px]', md: 'max-w-[480px]', lg: 'max-w-[840px]' }[props.size ?? 'md'],
148
+ props.fullscreen && 'max-w-none h-full rounded-none',
149
+ // same enter/exit as popovers, selects and dropdowns (css/animations.css)
150
+ !props.hideEnterAnimation && 'popover-enter-exit',
151
+ props.dialogContentClass,
152
+ attrs.class as string,
153
+ ))
154
+
155
+ const hasBody = computed(() => Boolean(slots.default || slots.content))
156
+
157
+ const sizedHeaderClass = computed(() => cn(
158
+ 'relative flex flex-none items-start gap-8px px-[24px] pt-[20px] pb-[16px]',
159
+ !hasBody.value && !slots.footer && 'pb-[20px]',
160
+ // hairline shown only while the body is scrolled under the header
161
+ 'after:content-empty after:absolute after:inset-x-0 after:bottom-0 after:h-0.5px after:bg-border after:opacity-0 after:pointer-events-none after:transition-opacity after:duration-150',
162
+ !props.hideDividers && scrollEdges.top && 'after:opacity-100',
163
+ props.headerClass,
164
+ ))
165
+
166
+ const sizedBodyClass = computed(() => cn(
167
+ 'px-[24px]',
168
+ !showHeader.value && 'pt-[20px]',
169
+ !slots.footer && 'pb-[20px]',
170
+ props.contentClass,
171
+ ))
172
+
173
+ const sizedFooterClass = computed(() => cn(
174
+ 'relative flex flex-none items-center justify-end gap-8px px-[24px] pt-[16px] pb-[20px]',
175
+ !showHeader.value && 'pt-[20px]',
176
+ 'before:content-empty before:absolute before:inset-x-0 before:top-0 before:h-0.5px before:bg-border before:opacity-0 before:pointer-events-none before:transition-opacity before:duration-150',
177
+ !props.hideDividers && scrollEdges.bottom && 'before:opacity-100',
178
+ ))
179
+
65
180
  function handlePointerDownOutside(event: any) {
66
181
  const target = event?.detail?.originalEvent?.target ?? event?.target
67
182
 
@@ -69,6 +184,9 @@ function handlePointerDownOutside(event: any) {
69
184
  event.preventDefault()
70
185
  }
71
186
 
187
+ if (props.preventClose)
188
+ event.preventDefault()
189
+
72
190
  const listener = (attrs as Record<string, unknown>).onPointerDownOutside
73
191
  if (Array.isArray(listener)) {
74
192
  listener.forEach((handler) => {
@@ -80,23 +198,29 @@ function handlePointerDownOutside(event: any) {
80
198
  listener(event)
81
199
  }
82
200
  }
201
+
202
+ function handleEscapeKeyDown(event: KeyboardEvent) {
203
+ if (props.preventClose)
204
+ event.preventDefault()
205
+ }
83
206
  </script>
84
207
 
85
208
  <template>
86
209
  <DialogRoot v-model:open="open">
87
210
  <DialogPortal>
88
- <DialogOverlay data-tela-escape-layer :class="`DialogOverlay ${overlayClass ?? ''}`" bg="#000/35" z-600 overflow-y-auto flex items-center justify-center :p-16px="!fullscreen">
211
+ <DialogOverlay v-if="isLegacy" data-tela-escape-layer :class="`DialogOverlay overlay-enter-exit ${overlayClass ?? ''}`" bg="#000/35" z-600 overflow-y-auto flex items-center justify-center :p-16px="!fullscreen">
89
212
  <DialogContent
90
213
  :data-animation="hideEnterAnimation"
91
- :class="cn('DialogContent shadow-xl', modalMaxWidth, dialogContentClass)"
214
+ :class="cn('DialogContent shadow-xl', modalMaxWidth, !hideEnterAnimation && 'popover-enter-exit', dialogContentClass)"
92
215
  z-101
93
216
  rounded-16px
94
217
  w-full flex="~ col"
95
218
  min-w-100px
96
219
  bg-white
97
- v-bind="forwardedAttrs"
220
+ v-bind="{ ...forwardedAttrs, ...describedBy }"
98
221
  overflow-y-hidden
99
222
  @pointer-down-outside="handlePointerDownOutside"
223
+ @escape-key-down="handleEscapeKeyDown"
100
224
  >
101
225
  <div
102
226
  v-if="!hideHeader" w-full flex="~" items-center
@@ -121,7 +245,7 @@ function handlePointerDownOutside(event: any) {
121
245
  capitalize
122
246
  break-all
123
247
  >
124
- <slot name="header">
248
+ <slot name="header" :close="close">
125
249
  <div flex="~" items-center justify-between min-h-24px>
126
250
  <slot name="header-leading" />
127
251
  <p :class="$slots['header-leading'] && 'absolute left-1/2 -translate-x-1/2'">
@@ -141,11 +265,13 @@ function handlePointerDownOutside(event: any) {
141
265
  </VisuallyHidden>
142
266
 
143
267
  <div v-if="isCloseIcon" z-1 :right="props.compact ? '12px' : '24px'">
144
- <slot name="actions">
268
+ <slot name="actions" :close="close">
145
269
  <DialogClose as-child>
146
270
  <TelaIconButton
147
271
  icon="i-ph-x" size="sm" color="secondary" button-class="text-gray-400 hover:text-gray-900"
148
272
  :class="cn('p-6px', props.isCloseIconAbsolute && 'absolute right-20px top-20px')"
273
+ :aria-label="closeLabel"
274
+ :disabled="preventClose"
149
275
  />
150
276
  </DialogClose>
151
277
  </slot>
@@ -156,7 +282,7 @@ function handlePointerDownOutside(event: any) {
156
282
  <DialogTitle />
157
283
  </VisuallyHidden>
158
284
 
159
- <slot name="content">
285
+ <slot name="content" :close="close">
160
286
  <div
161
287
  flex w-full items-center justify-center relative h-full
162
288
  class="DialogBody" :class="[
@@ -164,7 +290,7 @@ function handlePointerDownOutside(event: any) {
164
290
  contentClass,
165
291
  ]"
166
292
  >
167
- <slot />
293
+ <slot :close="close" />
168
294
  </div>
169
295
  </slot>
170
296
 
@@ -173,7 +299,81 @@ function handlePointerDownOutside(event: any) {
173
299
  class="DialogFooter" mt-24px :b-t="!props.hideDividers && '0.5px gray-200'"
174
300
  py-24px flex px-32px
175
301
  >
176
- <slot name="footer" />
302
+ <slot name="footer" :close="close" />
303
+ </div>
304
+ </DialogContent>
305
+ </DialogOverlay>
306
+
307
+ <DialogOverlay v-else data-tela-escape-layer :class="sizedOverlayClass">
308
+ <DialogContent
309
+ :class="sizedContentClass"
310
+ v-bind="{ ...sizedAttrs, ...describedBy }"
311
+ @pointer-down-outside="handlePointerDownOutside"
312
+ @escape-key-down="handleEscapeKeyDown"
313
+ >
314
+ <div v-if="showHeader" :class="sizedHeaderClass">
315
+ <div class="flex flex-1 flex-col gap-4px min-w-0">
316
+ <slot name="header" :close="close">
317
+ <DialogTitle
318
+ v-if="hasTitle"
319
+ :class="cn('heading-h4-semibold text-primary text-balance break-words', titleClass)"
320
+ >
321
+ <slot name="title" :close="close">
322
+ {{ title }}
323
+ </slot>
324
+ </DialogTitle>
325
+ <!-- a div, not radix's default <p>: description slots often hold <p>/<div> content -->
326
+ <DialogDescription
327
+ v-if="hasDescription"
328
+ as="div"
329
+ class="body-14-regular text-secondary text-pretty break-words"
330
+ >
331
+ <slot name="description" :close="close">
332
+ {{ description }}
333
+ </slot>
334
+ </DialogDescription>
335
+ </slot>
336
+ </div>
337
+
338
+ <div v-if="$slots.actions || isCloseIcon" class="flex flex-none items-center gap-4px h-20px pt-4px -mr-16px -mt-4px">
339
+ <slot name="actions" :close="close">
340
+ <DialogClose as-child>
341
+ <TelaIconButton
342
+ icon="i-ph-x"
343
+ size="md"
344
+ color="secondary"
345
+ button-class="!p-8px !rounded-12px text-icon"
346
+ :aria-label="closeLabel"
347
+ :disabled="preventClose"
348
+ />
349
+ </DialogClose>
350
+ </slot>
351
+ </div>
352
+ </div>
353
+
354
+ <VisuallyHidden v-if="!showHeading || !hasTitle">
355
+ <DialogTitle>{{ title }}</DialogTitle>
356
+ </VisuallyHidden>
357
+ <VisuallyHidden v-if="description && !showHeading">
358
+ <DialogDescription>{{ description }}</DialogDescription>
359
+ </VisuallyHidden>
360
+
361
+ <!-- custom content scrolls instead of clipping once the modal reaches the viewport height -->
362
+ <div v-if="$slots.content" class="flex flex-auto flex-col min-h-0 overflow-y-auto overscroll-contain">
363
+ <slot name="content" :close="close" />
364
+ </div>
365
+ <TelaScrollArea
366
+ v-else-if="$slots.default"
367
+ class="flex flex-auto flex-col min-h-0 [&>[data-reka-scroll-area-viewport]]:min-h-0 [&>[data-reka-scroll-area-viewport]]:overscroll-contain"
368
+ @scroll.passive="measureScroll"
369
+ >
370
+ <div ref="bodyRef" :class="sizedBodyClass">
371
+ <slot :close="close" />
372
+ </div>
373
+ </TelaScrollArea>
374
+
375
+ <div v-if="$slots.footer" :class="sizedFooterClass">
376
+ <slot name="footer" :close="close" />
177
377
  </div>
178
378
  </DialogContent>
179
379
  </DialogOverlay>
@@ -185,15 +385,6 @@ function handlePointerDownOutside(event: any) {
185
385
  .DialogOverlay {
186
386
  position: fixed;
187
387
  inset: 0;
188
-
189
- &[data-state="open"] {
190
- animation: overlayShow 0.12s ease-out forwards;
191
- }
192
-
193
- &[data-state="closed"] {
194
- animation: overlayHide 0.12s ease-out forwards;
195
- animation-delay: 0s;
196
- }
197
388
  }
198
389
 
199
390
  .DialogContent {
@@ -203,14 +394,8 @@ function handlePointerDownOutside(event: any) {
203
394
  padding: 24px;
204
395
 
205
396
  [data-animation="false"]&[data-state="open"] {
206
- animation: contentShow 0.12s ease-out forwards;
207
397
  overflow: visible;
208
398
  }
209
-
210
- [data-animation="false"]&[data-state="closed"] {
211
- animation: contentHide 0.12s ease-out forwards;
212
- animation-delay: 0s;
213
- }
214
399
  }
215
400
 
216
401
  .DialogContent:focus {
@@ -238,44 +423,4 @@ function handlePointerDownOutside(event: any) {
238
423
  font-size: 15px;
239
424
  line-height: 1.5;
240
425
  }
241
-
242
- @keyframes overlayShow {
243
- from {
244
- opacity: 0;
245
- }
246
- to {
247
- opacity: 1;
248
- }
249
- }
250
-
251
- @keyframes overlayHide {
252
- from {
253
- opacity: 1;
254
- }
255
- to {
256
- opacity: 0;
257
- }
258
- }
259
-
260
- @keyframes contentShow {
261
- from {
262
- opacity: 0;
263
- transform: scale(0.96);
264
- }
265
- to {
266
- opacity: 1;
267
- transform: scale(1);
268
- }
269
- }
270
-
271
- @keyframes contentHide {
272
- from {
273
- opacity: 1;
274
- transform: scale(1);
275
- }
276
- to {
277
- opacity: 0;
278
- transform: scale(0.96);
279
- }
280
- }
281
426
  </style>
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import type { FullWorkspace } from '@meistrari/auth-sdk/utils'
2
+ import type { FullWorkspace } from './types'
3
3
 
4
4
  const props = defineProps<{
5
5
  workspaces: FullWorkspace[]
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import type { FullWorkspace } from '@meistrari/auth-sdk/utils'
2
+ import type { FullWorkspace } from './types'
3
3
 
4
4
  defineProps<{
5
5
  modelValue: boolean
@@ -28,50 +28,23 @@ function onClose() {
28
28
 
29
29
  <template>
30
30
  <TelaModal
31
- class="w-420px!"
32
31
  :model-value="modelValue"
33
- title-class="text-[16px] font-580 leading-[20px] -tracking-[0.01em] !normal-case"
34
- hide-dividers
35
- hide-header
36
- compact
32
+ size="md"
33
+ :title="title"
37
34
  @close="onClose"
38
35
  >
39
- <div flex="~ col" gap-10px w-full>
40
- <div flex="~ row justify-between" items-start>
41
- <h4 heading-h4-semibold text-primary>
42
- {{ title }}
43
- </h4>
44
- <TelaIconButton
45
- icon="i-ph-x"
46
- size="md"
47
- color="secondary"
48
- outline-none
49
- p-8px mt--10px mr--10px
50
- @click="onClose"
51
- />
52
- </div>
53
- <div
54
- w-full
55
- rounded-12px
56
- border-0.5px border
57
- flex="~ col"
58
- max-h-720px
59
- overflow-hidden
60
- >
61
- <div overflow-y-auto no-scrollbar>
62
- <TelaModalSwitchWorkspaceContent
63
- :workspaces="workspaces"
64
- :loading="loading"
65
- :active-workspace-id="activeWorkspaceId"
66
- :member-label="memberLabel"
67
- :members-label="membersLabel"
68
- :project-label="projectLabel"
69
- :projects-label="projectsLabel"
70
- :selected-label="selectedLabel"
71
- @select="emit('select', $event)"
72
- />
73
- </div>
74
- </div>
36
+ <div class="w-full rounded-12px border-0.5px border overflow-hidden">
37
+ <TelaModalSwitchWorkspaceContent
38
+ :workspaces="workspaces"
39
+ :loading="loading"
40
+ :active-workspace-id="activeWorkspaceId"
41
+ :member-label="memberLabel"
42
+ :members-label="membersLabel"
43
+ :project-label="projectLabel"
44
+ :projects-label="projectsLabel"
45
+ :selected-label="selectedLabel"
46
+ @select="emit('select', $event)"
47
+ />
75
48
  </div>
76
49
  </TelaModal>
77
50
  </template>
@@ -0,0 +1,9 @@
1
+ import type { FullOrganization } from '@meistrari/auth-core'
2
+
3
+ export type FullWorkspace = FullOrganization & {
4
+ stats?: {
5
+ projectCount: number
6
+ promptCount: number
7
+ memberCount: number
8
+ }
9
+ }
@@ -312,13 +312,17 @@ By default, the fullscreen button is hidden when the preview is rendered inside
312
312
 
313
313
  ```vue
314
314
  <!-- Fullscreen button will be shown (default) -->
315
- <TelaModal v-model="isOpen">
316
- <TelaPreview :current-file="file" />
315
+ <TelaModal v-model="isOpen" size="lg" hide-header title="Preview">
316
+ <template #content>
317
+ <TelaPreview :current-file="file" />
318
+ </template>
317
319
  </TelaModal>
318
320
 
319
321
  <!-- Fullscreen button will be hidden -->
320
- <TelaModal v-model="isOpen" data-disable-preview-fullscreen>
321
- <TelaPreview :current-file="file" />
322
+ <TelaModal v-model="isOpen" size="lg" hide-header title="Preview" data-disable-preview-fullscreen>
323
+ <template #content>
324
+ <TelaPreview :current-file="file" />
325
+ </template>
322
326
  </TelaModal>
323
327
  ```
324
328
 
@@ -64,35 +64,35 @@ function closeModal() {
64
64
  <template>
65
65
  <TelaModal
66
66
  :model-value="modelValue"
67
- compact
68
- hide-dividers
69
- :is-close-icon="false"
70
- modal-width="lg"
71
- class="overflow-hidden !w-full !p-0"
67
+ size="lg"
68
+ :title="currentFile?.fileName"
69
+ hide-header
72
70
  data-disable-preview-fullscreen
73
71
  @update:model-value="(value: boolean | undefined) => emit('update:modelValue', value ?? false)"
74
72
  @close="closeModal"
75
73
  >
76
- <div v-if="file && currentFile" flex="~ col" w-full h-90vh bg rounded-12px overflow-hidden>
77
- <TelaPreview
78
- :model-value="selectedVariable"
79
- :file-options="fileOptions"
80
- :labels="props.previewLabels"
81
- :select-variable-labels="props.selectVariableLabels"
82
- :current-file="currentFile"
83
- :pdf-loader="props.pdfLoader"
84
- :content-labels="props.contentLabels"
85
- >
86
- <template #header-actions>
87
- <TelaIconButton
88
- icon="i-ph-x"
89
- size="md"
90
- color="secondary"
91
- p-4px!
92
- @click="closeModal"
93
- />
94
- </template>
95
- </TelaPreview>
96
- </div>
74
+ <template #content>
75
+ <div v-if="file && currentFile" class="flex flex-col w-full h-90vh bg overflow-hidden">
76
+ <TelaPreview
77
+ :model-value="selectedVariable"
78
+ :file-options="fileOptions"
79
+ :labels="props.previewLabels"
80
+ :select-variable-labels="props.selectVariableLabels"
81
+ :current-file="currentFile"
82
+ :pdf-loader="props.pdfLoader"
83
+ :content-labels="props.contentLabels"
84
+ >
85
+ <template #header-actions>
86
+ <TelaIconButton
87
+ icon="i-ph-x"
88
+ size="md"
89
+ color="secondary"
90
+ button-class="!p-4px"
91
+ @click="closeModal"
92
+ />
93
+ </template>
94
+ </TelaPreview>
95
+ </div>
96
+ </template>
97
97
  </TelaModal>
98
98
  </template>