@bagelink/vue 1.18.3 → 1.19.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/vue",
3
3
  "type": "module",
4
- "version": "1.18.3",
4
+ "version": "1.19.1",
5
5
  "description": "Bagel core sdk packages",
6
6
  "author": {
7
7
  "name": "Bagel Studio",
@@ -335,7 +335,7 @@ onMounted(() => {
335
335
  <template #trigger>
336
336
  <div ref="datePickerRef" class="date-picker-container">
337
337
  <TextInput
338
- v-model="inputValue" iconStart="calendar"
338
+ v-model="inputValue" iconStart="calendar_month"
339
339
  :placeholder="underlined ? ' ' : (resolveI18n(placeholder) || defaultPlaceholder)"
340
340
  :required="underlined ? false : required" :disabled="!isEditable"
341
341
  :error="!isValid ? $t('date.invalidFormat') : error"
@@ -329,7 +329,7 @@ flex-shrink: 0;
329
329
  box-sizing: border-box;
330
330
  min-height: var(--bgl-app-header-h, 60px);
331
331
  gap: 0.5rem 0.75rem;
332
- padding-inline: calc(var(--bgl-content-padding, 1rem) + 0.05rem);
332
+ padding-inline: var(--bgl-content-padding, 1rem);
333
333
  padding-block: 0.5rem;
334
334
  flex-wrap: wrap;
335
335
  }
@@ -0,0 +1,37 @@
1
+ // @bun
2
+ import { afterEach, describe, expect, it, vi } from 'vitest'
3
+ import { mount } from '@vue/test-utils'
4
+ import { nextTick } from 'vue'
5
+ import { createI18n } from '../../i18n'
6
+ import AssetPreview from './AssetPreview.vue'
7
+
8
+ createI18n()
9
+
10
+ afterEach(() => {
11
+ vi.restoreAllMocks()
12
+ })
13
+
14
+ describe('AssetPreview protected delivery', () => {
15
+ it('uses the provided authenticated loader and revokes its object URL', async () => {
16
+ const createObjectURL = vi.fn(() => 'blob:protected')
17
+ const revokeObjectURL = vi.fn()
18
+ Object.defineProperties(URL, {
19
+ createObjectURL: { configurable: true, value: createObjectURL },
20
+ revokeObjectURL: { configurable: true, value: revokeObjectURL },
21
+ })
22
+ const load = vi.fn(async () => new Blob(['protected']))
23
+ const wrapper = mount(AssetPreview, {
24
+ props: { asset: { asset_id: 'asset-1' }, type: 'file', load },
25
+ global: { stubs: { BglBtn: { props: ['href'], template: '<a :href="href"><slot /></a>' } } },
26
+ })
27
+ await nextTick()
28
+ await nextTick()
29
+
30
+ expect(load).toHaveBeenCalledWith({ asset_id: 'asset-1' })
31
+ expect(createObjectURL).toHaveBeenCalledOnce()
32
+ expect(wrapper.get('a').attributes('href')).toBe('blob:protected')
33
+
34
+ wrapper.unmount()
35
+ expect(revokeObjectURL).toHaveBeenCalledWith('blob:protected')
36
+ })
37
+ })
@@ -1,13 +1,54 @@
1
1
  <script setup lang="ts">
2
2
  import { useAssetDelivery, type AssetReference } from '../../assets'
3
3
  import { Btn, Image } from '../../index'
4
- const props = defineProps<{ asset: AssetReference, type: string, name?: string }>()
5
- const { url, error, onError } = useAssetDelivery(() => props.asset)
4
+ import { computed, onUnmounted, ref, watch } from 'vue'
5
+
6
+ const props = defineProps<{
7
+ asset: AssetReference
8
+ type: string
9
+ name?: string
10
+ /** Authenticated byte loader for protected assets. Public assets omit it. */
11
+ load?: (asset: AssetReference) => Promise<Blob>
12
+ }>()
13
+ const publicDelivery = useAssetDelivery(() => props.load ? undefined : props.asset)
14
+ const protectedUrl = ref<string>()
15
+ const protectedError = ref(false)
16
+ let generation = 0
17
+
18
+ function clearProtectedUrl() {
19
+ if (protectedUrl.value) URL.revokeObjectURL(protectedUrl.value)
20
+ protectedUrl.value = undefined
21
+ }
22
+
23
+ watch(() => [props.asset.asset_id, props.load] as const, async () => {
24
+ const current = ++generation
25
+ clearProtectedUrl()
26
+ protectedError.value = false
27
+ if (!props.load) return
28
+ try {
29
+ const blob = await props.load(props.asset)
30
+ if (current === generation) protectedUrl.value = URL.createObjectURL(blob)
31
+ } catch {
32
+ if (current === generation) protectedError.value = true
33
+ }
34
+ }, { immediate: true })
35
+
36
+ onUnmounted(() => {
37
+ generation++
38
+ clearProtectedUrl()
39
+ })
40
+
41
+ const url = computed(() => protectedUrl.value ?? publicDelivery.url.value)
42
+ const error = computed(() => protectedError.value || publicDelivery.error.value)
43
+ const onError = () => {
44
+ if (props.load) protectedError.value = true
45
+ else publicDelivery.onError()
46
+ }
6
47
  </script>
7
48
 
8
49
  <template>
9
50
  <div class="flex column gap-1">
10
- <Image v-if="type === 'image'" :src="asset" />
51
+ <Image v-if="type === 'image' && (!load || url)" :src="load ? url : asset" @error="onError" />
11
52
  <video v-else-if="type === 'video' && url" :src="url" controls @error="onError" />
12
53
  <iframe v-else-if="type === 'pdf' && url" :src="url" :title="name || 'PDF preview'" referrerpolicy="no-referrer" />
13
54
  <Btn v-if="url" :href="url" target="_blank" rel="noopener noreferrer" value="Open / download" />