@antelopejs/dms-media 0.3.0 → 0.4.0

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.
Files changed (57) hide show
  1. package/README.md +5 -1
  2. package/dist/index.d.ts +3 -0
  3. package/dist/index.js +8 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/pages/uploads.js +2 -1
  6. package/dist/pages/uploads.js.map +1 -1
  7. package/dist/test/antelope.test.js +3 -2
  8. package/dist/test/antelope.test.js.map +1 -1
  9. package/dist/test/helpers/pages.js +3 -2
  10. package/dist/test/helpers/pages.js.map +1 -1
  11. package/dist/test/integration/frontend-module.test.d.ts +1 -0
  12. package/dist/test/integration/frontend-module.test.js +13 -0
  13. package/dist/test/integration/frontend-module.test.js.map +1 -0
  14. package/dist/test/unit/config.test.js +0 -4
  15. package/dist/test/unit/config.test.js.map +1 -1
  16. package/frontend-vue/app/components/FileProperties.vue +9 -3
  17. package/frontend-vue/app/components/FirstRun.vue +1 -1
  18. package/frontend-vue/app/components/ImageEditor.vue +43 -26
  19. package/frontend-vue/app/components/PresetCards.vue +3 -11
  20. package/frontend-vue/app/components/RecentFiles.vue +6 -14
  21. package/frontend-vue/app/components/UploadQueue.vue +1 -1
  22. package/frontend-vue/app/components/UploadStrip.vue +1 -1
  23. package/frontend-vue/app/components/dialogs/DestinationDialog.vue +1 -2
  24. package/frontend-vue/app/components/explorer/ExplorerInspector.vue +17 -16
  25. package/frontend-vue/app/components/explorer/ExplorerShell.vue +11 -3
  26. package/frontend-vue/app/components/explorer/ExplorerToolbar.vue +2 -1
  27. package/frontend-vue/app/components/field/AssetValue.vue +12 -13
  28. package/frontend-vue/app/components/file/FileViewer.vue +1 -14
  29. package/frontend-vue/app/composables/library/useLibraryListing.ts +180 -79
  30. package/frontend-vue/app/composables/library/useLibraryTree.ts +31 -15
  31. package/frontend-vue/app/composables/library/useMediaLibrary.ts +17 -7
  32. package/frontend-vue/app/composables/uploadLimits.ts +25 -0
  33. package/frontend-vue/app/composables/useAssetContent.ts +20 -0
  34. package/frontend-vue/app/composables/useCurrentFile.ts +10 -8
  35. package/frontend-vue/app/composables/useFieldFolders.ts +19 -18
  36. package/frontend-vue/app/composables/useFileDetails.ts +117 -90
  37. package/frontend-vue/app/composables/useMediaApi.ts +18 -24
  38. package/frontend-vue/i18n/locales/media-en-GB.json +1 -0
  39. package/frontend-vue/i18n/locales/media-fr-FR.json +1 -0
  40. package/frontend-vue/package.json +2 -1
  41. package/frontend-vue/pnpm-lock.yaml +17 -2
  42. package/frontend-vue/tests/engines.test.ts +20 -0
  43. package/frontend-vue/tests/fixtures/inertia.ts +8 -0
  44. package/frontend-vue/tests/fixtures/serverRender.ts +200 -0
  45. package/frontend-vue/tests/fixtures/unhead.ts +3 -0
  46. package/frontend-vue/tests/fixtures/vueI18n.ts +4 -0
  47. package/frontend-vue/tests/libraryListing.test.ts +120 -0
  48. package/frontend-vue/tests/serverRender.test.ts +215 -0
  49. package/frontend-vue/vitest.config.ts +21 -0
  50. package/package.json +16 -10
  51. package/src/index.ts +19 -2
  52. package/src/pages/uploads.ts +2 -1
  53. package/src/test/antelope.test.ts +3 -2
  54. package/src/test/helpers/pages.ts +3 -2
  55. package/src/test/integration/frontend-module.test.ts +13 -0
  56. package/src/test/unit/config.test.ts +0 -5
  57. package/frontend-vue/app/composables/useSharedTree.ts +0 -73
@@ -0,0 +1,200 @@
1
+ /**
2
+ * Server renders of the module's blocks on the renderer's real data layer
3
+ * (`#dms/frontend-module`) and the DMS's real `useApiData`, as the generated
4
+ * application runs them: what each render reads from the backend, and what it
5
+ * hands the browser with the page.
6
+ */
7
+ import * as vue from 'vue'
8
+ import { createSSRApp, h, type Component } from 'vue'
9
+ import { renderToString } from 'vue/server-renderer'
10
+ import { vi } from 'vitest'
11
+ import type { DmsPayload } from '#dms/frontend-module'
12
+
13
+ const engine = await import('#dms/frontend-module')
14
+
15
+ /** A backend request a render made. */
16
+ export interface BackendRead {
17
+ url: string
18
+ method: string
19
+ query: Record<string, unknown>
20
+ }
21
+
22
+ export type Backend = (read: BackendRead) => unknown
23
+
24
+ let backend: Backend = () => ({})
25
+ const reads: BackendRead[] = []
26
+
27
+ /** The query a request was given, as the renderer keys its response: none when it had none. */
28
+ const givenQueries = new WeakMap<BackendRead, Record<string, unknown> | undefined>()
29
+
30
+ const $authFetch = async (url: string, options: { method?: string; query?: Record<string, unknown> } = {}) => {
31
+ const read = { url, method: (options.method ?? 'GET').toUpperCase(), query: options.query ?? {} }
32
+ givenQueries.set(read, options.query)
33
+ reads.push(read)
34
+ return backend(read)
35
+ }
36
+
37
+ const noop = () => undefined
38
+
39
+ /** The auto-imports, which templates reach through the application's global properties. */
40
+ const autoImports: Record<string, unknown> = {}
41
+ function provideGlobal(name: string, value: unknown): void {
42
+ autoImports[name] = value
43
+ vi.stubGlobal(name, value)
44
+ }
45
+
46
+ // The application's auto-imports: Vue's API, the renderer's, the DMS layers'
47
+ // the module calls, and the module's own composables and utilities.
48
+ for (const [name, value] of Object.entries(vue)) if (/^[a-z]/.test(name)) vi.stubGlobal(name, value)
49
+ for (const name of ['useDmsFetch', 'useDmsAsyncData', 'useDmsPagedData', 'useDmsState', 'useDmsRoute', 'useDmsRouter'] as const)
50
+ provideGlobal(name, engine[name])
51
+ const { useApiData, useApiPagedData } = await import('#dms-core/app/composables/auth/useApiData')
52
+ provideGlobal('useApiData', useApiData)
53
+ provideGlobal('useApiPagedData', useApiPagedData)
54
+ provideGlobal('useAuthFetch', () => ({ $authFetch }))
55
+ provideGlobal('useI18n', () => ({
56
+ t: (key: string, params?: Record<string, unknown>) => (params ? `${key} ${Object.values(params).join(' ')}` : key),
57
+ te: () => false,
58
+ locale: vue.ref('en'),
59
+ }))
60
+ provideGlobal('useRegionalFormat', () => ({ formatNumber: (value: number) => String(value) }))
61
+ provideGlobal('useToast', () => ({ add: noop }))
62
+ provideGlobal('useConfirm', () => ({ confirm: async () => false }))
63
+ provideGlobal('useOverlay', () => ({ create: () => ({ open: async () => undefined }) }))
64
+ provideGlobal('useApiError', noop)
65
+ provideGlobal('useUnsavedChanges', noop)
66
+ provideGlobal('usePageLiveRefresh', noop)
67
+ provideGlobal('defineShortcuts', noop)
68
+ const keyboard = await import('#dms-ui/app/composables/global/keyboardPlatform')
69
+ // The labels a server render prints before the browser names its platform.
70
+ provideGlobal('useKeyboardPlatform', () => ({
71
+ keyLabel: (key: string) => keyboard.keyboardKeyLabel(key, keyboard.DEFAULT_KEYBOARD_PLATFORM),
72
+ formatShortcut: (keys: readonly string[]) => keyboard.formatKeyboardShortcut(keys, keyboard.DEFAULT_KEYBOARD_PLATFORM),
73
+ }))
74
+ provideGlobal('navigateDms', noop)
75
+ for (const util of [await import('#dms-core/app/utils/http-status'), await import('#dms-core/app/composables/useFieldErrors')])
76
+ for (const [name, value] of Object.entries(util)) provideGlobal(name, value)
77
+ const own = import.meta.glob<Record<string, unknown>>(['../../app/composables/**/*.ts', '../../app/utils/**/*.ts'])
78
+ for (const load of Object.values(own))
79
+ for (const [name, value] of Object.entries(await load())) provideGlobal(name, value)
80
+
81
+ // The DMS's and Nuxt UI's components the module's templates use: each renders
82
+ // its default slot, its props as attributes.
83
+ const UI_COMPONENTS = [
84
+ 'DmsCard',
85
+ 'DmsCopyButton',
86
+ 'DmsEmptyState',
87
+ 'DmsEyebrow',
88
+ 'DmsFieldRow',
89
+ 'DmsIconWell',
90
+ 'DmsSaveStatus',
91
+ 'DmsTextarea',
92
+ 'UBadge',
93
+ 'UButton',
94
+ 'UFormField',
95
+ 'UIcon',
96
+ 'UInput',
97
+ 'UKbd',
98
+ 'ULink',
99
+ 'USkeleton',
100
+ 'UTooltip',
101
+ ]
102
+
103
+ const uiStub = (name: string): Component =>
104
+ vue.defineComponent({
105
+ name,
106
+ inheritAttrs: false,
107
+ setup:
108
+ (_, { slots, attrs }) =>
109
+ () =>
110
+ h(
111
+ 'div',
112
+ {
113
+ 'data-stub': name,
114
+ ...Object.fromEntries(
115
+ Object.entries(attrs).filter(([, value]) => ['string', 'number', 'boolean'].includes(typeof value)),
116
+ ),
117
+ },
118
+ // Every slot, named ones included: a field's trailing hint renders with it.
119
+ Object.values(slots).flatMap((slot) => slot?.() ?? []),
120
+ ),
121
+ })
122
+
123
+ export interface ServerRender {
124
+ html: string
125
+ payload: DmsPayload
126
+ /** Every backend request the render made, as `METHOD url?query`. */
127
+ reads: string[]
128
+ /**
129
+ * What the payload hands the browser, by key: a `useApiData(url)` read as
130
+ * `METHOD url?query`, a handler's read by its own key.
131
+ */
132
+ handed: string[]
133
+ }
134
+
135
+ const describeRead = (method: string, url: string, query: Record<string, unknown> | null) => {
136
+ const sent = Object.entries(query ?? {}).filter(([, value]) => value !== undefined)
137
+ const search = new URLSearchParams(sent.map(([name, value]) => [name, String(value)])).toString()
138
+ return `${method} ${url}${search ? `?${search}` : ''}`
139
+ }
140
+
141
+ /** The payload key a `useApiData(url)` read's response is handed over under. */
142
+ const fetchKey = (read: BackendRead) => engine.dmsRequestKey(read.url, { method: read.method, query: givenQueries.get(read) })
143
+
144
+ /** A payload key, as `describeRead` writes the request it answers for `$dmsfetch` keys. */
145
+ function handedKey(key: string, made: BackendRead[]): string {
146
+ const read = made.find((candidate) => fetchKey(candidate) === key)
147
+ return read ? describeRead(read.method, read.url, read.query) : key
148
+ }
149
+
150
+ /**
151
+ * Renders `component` with `props` as a server renders the page `url`,
152
+ * answering each backend request with `respond`.
153
+ */
154
+ export async function serverRender(
155
+ component: Component,
156
+ props: Record<string, unknown> = {},
157
+ options: { url?: string; respond?: Backend } = {},
158
+ ): Promise<ServerRender> {
159
+ backend = options.respond ?? (() => ({}))
160
+ reads.length = 0
161
+ const runtime = engine.createDmsFrontendRuntime(undefined, {}, true)
162
+ runtime.route.fullPath = options.url ?? '/'
163
+ const app = createSSRApp({ render: () => h(component, props) })
164
+ engine.provideDmsFrontendRuntime(app, runtime)
165
+ for (const name of UI_COMPONENTS) app.component(name, uiStub(name))
166
+ Object.assign(app.config.globalProperties, autoImports)
167
+ app.config.warnHandler = noop
168
+ const html = await renderToString(app)
169
+ const payload = engine.serializeDmsPayload(runtime)
170
+ return {
171
+ html,
172
+ payload,
173
+ reads: reads.map((read) => describeRead(read.method, read.url, read.query)),
174
+ handed: Object.keys({ ...payload.data, ...payload.errors }).map((key) => handedKey(key, reads)),
175
+ }
176
+ }
177
+
178
+ /** What `inBrowserApp` gives back: what `setup` returned, and the backend requests made so far. */
179
+ export interface BrowserApp<T> {
180
+ result: T
181
+ /** Every backend request made so far, as `METHOD url?query`. */
182
+ reads: () => string[]
183
+ }
184
+
185
+ /**
186
+ * Runs `setup` as a browser application runs a call outside any component, on
187
+ * the renderer's real data layer, answering each backend request with
188
+ * `respond`.
189
+ */
190
+ export function inBrowserApp<T>(setup: () => T, respond: Backend = () => ({})): BrowserApp<T> {
191
+ backend = respond
192
+ reads.length = 0
193
+ const runtime = engine.createDmsFrontendRuntime(undefined, {}, false)
194
+ const app = vue.createApp({ render: () => null })
195
+ engine.provideDmsFrontendRuntime(app, runtime)
196
+ return {
197
+ result: app.runWithContext(setup),
198
+ reads: () => reads.map((read) => describeRead(read.method, read.url, read.query)),
199
+ }
200
+ }
@@ -0,0 +1,3 @@
1
+ // The renderer's head tags, which these tests do not look at.
2
+ export const useHead = () => undefined
3
+ export const useSeoMeta = () => undefined
@@ -0,0 +1,4 @@
1
+ // The renderer's `useI18n` wraps vue-i18n's; the tests stub `useI18n` itself.
2
+ export const useI18n = () => {
3
+ throw new Error('vue-i18n is not available in these tests')
4
+ }
@@ -0,0 +1,120 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { inBrowserApp, type BackendRead } from './fixtures/serverRender'
3
+ import { useLibraryListing } from '../app/composables/library/useLibraryListing'
4
+ import type { MediaAsset } from '../app/types/media'
5
+
6
+ // The explorer's listing is one paged read keyed by the location and the
7
+ // filters: "load more" appends a page, a revalidation reads every loaded page
8
+ // again with the sizes they had, and the local patches keep the next page's
9
+ // offset in step with the server.
10
+
11
+ const FOLDER_FILES = 650
12
+ const FOLDER_URL = '/api/media/folders/catalog/assets'
13
+
14
+ const file = (index: number): MediaAsset => ({
15
+ id: `f${index}`,
16
+ folderId: 'catalog',
17
+ name: `file-${String(index).padStart(4, '0')}.pdf`,
18
+ mimetype: 'application/pdf',
19
+ size: 1000,
20
+ alt: '',
21
+ visibility: 'inherit',
22
+ effectiveVisibility: 'private',
23
+ url: `/media/f${index}/file.pdf`,
24
+ hasOriginal: false,
25
+ typeGroup: 'document',
26
+ starred: false,
27
+ createdAt: '2026-10-01T10:00:00.000Z',
28
+ updatedAt: '2026-10-01T10:00:00.000Z',
29
+ })
30
+
31
+ function folderBackend(files: MediaAsset[]) {
32
+ return ({ url, query }: BackendRead): unknown => {
33
+ if (url !== FOLDER_URL) return {}
34
+ const offset = Number(query.offset)
35
+ const limit = Number(query.limit)
36
+ const sorted = query.direction === 'desc' ? [...files].reverse() : files
37
+ return { assets: sorted.slice(offset, offset + limit), total: files.length, facets: {} }
38
+ }
39
+ }
40
+
41
+ function openListing(files = Array.from({ length: FOLDER_FILES }, (_, index) => file(index))) {
42
+ const app = inBrowserApp(() => useLibraryListing(), folderBackend(files))
43
+ const folderReads = () => app.reads().filter((read) => read.includes(FOLDER_URL))
44
+ return { listing: app.result, folderReads, files }
45
+ }
46
+
47
+ describe('the explorer listing', () => {
48
+ it('reads nothing at the root', () => {
49
+ const { listing, folderReads } = openListing()
50
+ expect(listing.assets.value).toEqual([])
51
+ expect(folderReads()).toEqual([])
52
+ })
53
+
54
+ it('reads a folder page by page', async () => {
55
+ const { listing, folderReads } = openListing()
56
+ await listing.setLocation({ kind: 'folder', folderId: 'catalog' })
57
+ expect(listing.assets.value).toHaveLength(120)
58
+ expect(listing.total.value).toBe(FOLDER_FILES)
59
+ expect(listing.hasMore.value).toBe(true)
60
+
61
+ await listing.load(true)
62
+ expect(listing.assets.value).toHaveLength(240)
63
+ expect(listing.assets.value[120]?.id).toBe('f120')
64
+ expect(folderReads()).toEqual([
65
+ `GET ${FOLDER_URL}?offset=0&limit=120&sort=name&direction=asc&visibility=any&modified=any&orientation=any`,
66
+ `GET ${FOLDER_URL}?offset=120&limit=120&sort=name&direction=asc&visibility=any&modified=any&orientation=any`,
67
+ ])
68
+ })
69
+
70
+ it('reads the next page after the files left once some are removed', async () => {
71
+ const { listing, folderReads, files } = openListing()
72
+ await listing.setLocation({ kind: 'folder', folderId: 'catalog' })
73
+ listing.removeAssets(['f0', 'f1'])
74
+ files.splice(0, 2)
75
+ expect(listing.total.value).toBe(FOLDER_FILES - 2)
76
+
77
+ await listing.load(true)
78
+ expect(folderReads().at(-1)).toContain('offset=118&limit=120')
79
+ expect(listing.assets.value.map((asset) => asset.id)).toEqual(files.slice(0, 238).map((asset) => asset.id))
80
+ })
81
+
82
+ it('loads every file in the largest pages, and reads them again with the same sizes', async () => {
83
+ const { listing, folderReads } = openListing()
84
+ await listing.setLocation({ kind: 'folder', folderId: 'catalog' })
85
+ await listing.loadAll()
86
+ expect(listing.assets.value).toHaveLength(FOLDER_FILES)
87
+ expect(listing.hasMore.value).toBe(false)
88
+ const loaded = folderReads().map((read) => read.match(/offset=\d+&limit=\d+/)?.[0])
89
+ expect(loaded).toEqual(['offset=0&limit=120', 'offset=120&limit=500', 'offset=620&limit=500'])
90
+
91
+ await listing.refresh()
92
+ expect(folderReads().slice(loaded.length).map((read) => read.match(/offset=\d+&limit=\d+/)?.[0])).toEqual(loaded)
93
+ expect(listing.assets.value).toHaveLength(FOLDER_FILES)
94
+ })
95
+
96
+ it('starts again from the first page when the filters change, and shows the pages of a previous key at once', async () => {
97
+ const { listing, folderReads } = openListing()
98
+ await listing.setLocation({ kind: 'folder', folderId: 'catalog' })
99
+ await listing.load(true)
100
+ await listing.setFilters({ direction: 'desc' })
101
+ expect(listing.assets.value).toHaveLength(120)
102
+ expect(listing.assets.value[0]?.id).toBe(`f${FOLDER_FILES - 1}`)
103
+ expect(folderReads().at(-1)).toContain('offset=0&limit=120&sort=name&direction=desc')
104
+
105
+ const back = listing.setFilters({ direction: 'asc' })
106
+ await nextTick()
107
+ expect(listing.assets.value).toHaveLength(240)
108
+ await back
109
+ })
110
+
111
+ it('places a new file where the sort puts it and counts one beyond the loaded pages', async () => {
112
+ const { listing } = openListing()
113
+ await listing.setLocation({ kind: 'folder', folderId: 'catalog' })
114
+ listing.insertAsset({ ...file(9000), name: 'file-0000a.pdf' })
115
+ expect(listing.assets.value[1]?.id).toBe('f9000')
116
+ listing.insertAsset({ ...file(9001), name: 'zzz.pdf' })
117
+ expect(listing.assets.value).toHaveLength(121)
118
+ expect(listing.total.value).toBe(FOLDER_FILES + 2)
119
+ })
120
+ })
@@ -0,0 +1,215 @@
1
+ import { defineComponent, h } from 'vue'
2
+ import { describe, expect, it } from 'vitest'
3
+ import { serverRender, type BackendRead } from './fixtures/serverRender'
4
+ import AssetValue from '../app/components/field/AssetValue.vue'
5
+ import Explorer from '../app/components/Explorer.vue'
6
+ import FileHeader from '../app/components/FileHeader.vue'
7
+ import FilePreview from '../app/components/FilePreview.vue'
8
+ import FileProperties from '../app/components/FileProperties.vue'
9
+ import ImageEditor from '../app/components/ImageEditor.vue'
10
+ import PresetCards from '../app/components/PresetCards.vue'
11
+ import RecentFiles from '../app/components/RecentFiles.vue'
12
+ import { useFieldFolders } from '../app/composables/useFieldFolders'
13
+ import type { MediaAsset, MediaFolder } from '../app/types/media'
14
+
15
+ // What a server render of each block reads, and that it hands every read to
16
+ // the browser: a read the page does not hand over is made again by the
17
+ // browser, after a server request for nothing.
18
+
19
+ const RIGHTS = { read: true, write: true, manage: true }
20
+
21
+ const folder = (id: string, name: string): MediaFolder => ({
22
+ id,
23
+ name,
24
+ parentId: null,
25
+ shell: false,
26
+ bound: false,
27
+ binding: null,
28
+ link: null,
29
+ accepts: null,
30
+ visibility: 'private',
31
+ hasOwnAcl: false,
32
+ createdAt: '2026-10-01T10:00:00.000Z',
33
+ updatedAt: '2026-10-01T10:00:00.000Z',
34
+ rights: RIGHTS,
35
+ fileCount: 3,
36
+ size: 3000,
37
+ starred: false,
38
+ })
39
+
40
+ const file = (id: string, name: string, mimetype = 'image/png'): MediaAsset => ({
41
+ id,
42
+ folderId: 'catalog',
43
+ name,
44
+ mimetype,
45
+ size: 1000,
46
+ width: 1200,
47
+ height: 800,
48
+ alt: `${name} alt`,
49
+ visibility: 'inherit',
50
+ effectiveVisibility: 'private',
51
+ url: `/media/${id}/${name}`,
52
+ hasOriginal: false,
53
+ typeGroup: mimetype.startsWith('image/') ? 'image' : 'document',
54
+ starred: false,
55
+ createdAt: '2026-10-01T10:00:00.000Z',
56
+ updatedAt: '2026-10-01T10:00:00.000Z',
57
+ })
58
+
59
+ const FILES = [file('a1', 'harbour.png'), file('a2', 'lighthouse.png'), file('a3', 'dunes.png')]
60
+
61
+ function backend({ url }: BackendRead): unknown {
62
+ const details = url.match(/^\/api\/media\/assets\/([^/]+)\/details$/)
63
+ if (details) {
64
+ const found = FILES.find((entry) => entry.id === details[1])
65
+ if (!found) throw Object.assign(new Error('Not Found'), { statusCode: 404 })
66
+ return { asset: found, folder: folder('catalog', 'Catalog'), path: [], uploadedBy: null }
67
+ }
68
+ const one = url.match(/^\/api\/media\/assets\/([^/]+)$/)
69
+ if (one) return { asset: FILES.find((entry) => entry.id === one[1]) }
70
+ if (/\/read-url$/.test(url)) return { url: `https://storage.test${url}`, expiresAt: 0 }
71
+ switch (url) {
72
+ case '/api/media/tree':
73
+ return {
74
+ folders: [folder('catalog', 'Catalog')],
75
+ root: { write: true, manage: true, fileCount: 3, size: 3000 },
76
+ views: { starred: 0, missingAlt: 0 },
77
+ isOwner: true,
78
+ maxUploadBytes: 1000,
79
+ allowedMimetypes: [],
80
+ quotaBytes: null,
81
+ }
82
+ case '/api/media/stats/recent':
83
+ return { assets: FILES }
84
+ case '/api/media/presets':
85
+ return {
86
+ presets: [{ id: 'thumb', width: 300, height: 300, fit: 'cover', cacheKey: 'thumb.1', rendered: 1, urlPattern: '', exampleUrl: null }],
87
+ cache: { schedule: '', lastSweepAt: null, lastSweepRemoved: null, publicTtlSeconds: 0, privateTtlSeconds: 0 },
88
+ isDefault: true,
89
+ example: null,
90
+ }
91
+ case '/api/media/folders/catalog/assets':
92
+ return { assets: FILES, total: FILES.length, facets: {} }
93
+ case '/api/media/bindings/demo.cover/folder':
94
+ return { folder: { ...folder('covers', 'Demo covers'), bound: true }, maxUploadBytes: 1000, allowedMimetypes: [] }
95
+ default:
96
+ return {}
97
+ }
98
+ }
99
+
100
+ const render = (component: Parameters<typeof serverRender>[0], props: Record<string, unknown> = {}, url = '/') =>
101
+ serverRender(component, props, { url, respond: backend })
102
+
103
+ /** The file page's blocks, as the page lays them out. */
104
+ const FilePage = defineComponent({
105
+ setup: () => () => h('div', [h(FileHeader), h(FilePreview), h(FileProperties)]),
106
+ })
107
+
108
+ describe('server render: the blocks read with the page and hand it over', () => {
109
+ it('recent files: the files and the folder tree', async () => {
110
+ const page = await render(RecentFiles)
111
+ expect(page.reads).toEqual(['GET /api/media/stats/recent', 'GET /api/media/tree'])
112
+ expect(page.handed).toEqual(expect.arrayContaining(page.reads))
113
+ expect(page.html).toContain('lighthouse.png')
114
+ expect(page.html).not.toContain('animate-pulse')
115
+ })
116
+
117
+ it('image sizes: the presets', async () => {
118
+ const page = await render(PresetCards)
119
+ expect(page.reads).toEqual(['GET /api/media/presets'])
120
+ expect(page.handed).toEqual(expect.arrayContaining(page.reads))
121
+ expect(page.html).toContain('thumb')
122
+ })
123
+
124
+ it('file page: one read of the file and its neighbours for the three blocks, and the image read URL', async () => {
125
+ const page = await render(FilePage, {}, '/modules/media/file?asset=a2')
126
+ expect(page.reads.sort()).toEqual(
127
+ [
128
+ 'GET /api/media/tree',
129
+ 'GET /api/media/assets/a2/details',
130
+ 'GET /api/media/folders/catalog/assets?sort=name&offset=0&limit=500',
131
+ 'GET /api/media/assets/a2/read-url?preset=preview',
132
+ ].sort(),
133
+ )
134
+ expect(page.handed).toEqual(
135
+ expect.arrayContaining([
136
+ 'GET /api/media/tree',
137
+ 'dms-media:file:a2:[null,null,null]',
138
+ 'dms-media:content:a2:2026-10-01T10:00:00.000Z',
139
+ ]),
140
+ )
141
+ // The header's name and position, the viewer's image, the name field.
142
+ expect(page.html).toContain('lighthouse.png')
143
+ expect(page.html).toContain('dms_media.lightbox.position 2 3')
144
+ expect(page.html).toContain('https://storage.test/api/media/assets/a2/read-url')
145
+ expect(page.html).toContain('value="lighthouse"')
146
+ })
147
+
148
+ it('file page: a text file is read by the browser alone', async () => {
149
+ FILES.push(file('t1', 'notes.txt', 'text/plain'))
150
+ try {
151
+ const page = await render(FilePage, {}, '/modules/media/file?asset=t1')
152
+ expect(page.reads).not.toContain(expect.stringContaining('read-url'))
153
+ expect(page.html).toContain('notes.txt')
154
+ } finally {
155
+ FILES.pop()
156
+ }
157
+ })
158
+
159
+ it('file page: an unknown file is said so, and the failure handed over', async () => {
160
+ const page = await render(FilePage, {}, '/modules/media/file?asset=gone')
161
+ expect(page.reads).toContain('GET /api/media/assets/gone/details')
162
+ expect(page.payload.errors).toHaveProperty(['dms-media:file:gone:[null,null,null]'])
163
+ expect(page.html).toContain('dms_media.file.not_found')
164
+ })
165
+
166
+ it('library: a link to a folder reads its files with the page', async () => {
167
+ const page = await render(Explorer, {}, '/modules/media/files?folder=catalog&sort=name&direction=desc')
168
+ expect(page.reads).toEqual([
169
+ 'GET /api/media/tree',
170
+ 'GET /api/media/folders/catalog/assets?offset=0&limit=120&sort=name&direction=desc&visibility=any&modified=any&orientation=any',
171
+ ])
172
+ expect(page.handed).toEqual(expect.arrayContaining(['GET /api/media/tree']))
173
+ expect(page.handed.some((key) => key.startsWith('dms-media:listing:'))).toBe(true)
174
+ expect(page.html).toContain('aria-current="location">Catalog')
175
+ expect(page.html).toContain('dms_media.status.items 3')
176
+ })
177
+
178
+ it('library and image editor: the key hints are the platform labels the browser hydrates with', async () => {
179
+ const library = await render(Explorer, {}, '/modules/media/files')
180
+ const editor = await render(ImageEditor, {}, '/modules/media/editor?asset=a1')
181
+ for (const page of [library, editor]) {
182
+ expect(page.html).not.toContain('data-stub="UKbd" value="meta"')
183
+ expect(page.html).toContain('data-stub="UKbd" value="Ctrl"')
184
+ }
185
+ })
186
+
187
+ it('image editor: the details, not the image the browser edits', async () => {
188
+ const page = await render(ImageEditor, {}, '/modules/media/editor?asset=a1')
189
+ expect(page.reads).toEqual(['GET /api/media/assets/a1/details'])
190
+ expect(page.handed).toEqual(expect.arrayContaining(page.reads))
191
+ expect(page.html).toContain('dms_media.editor.heading harbour.png')
192
+ })
193
+
194
+ it('asset cell: the files it names', async () => {
195
+ const page = await render(AssetValue, { value: ['a1', 'a3', 'a2'] })
196
+ expect(page.reads).toEqual(['GET /api/media/assets/a1', 'GET /api/media/assets/a3'])
197
+ expect(page.handed).toEqual(['dms-media:asset-names:a1,a3'])
198
+ expect(page.html).toContain('harbour.png')
199
+ expect(page.html).toContain('dunes.png')
200
+ expect(page.html).toContain('dms_media.field_widget.more 1')
201
+ })
202
+
203
+ it('bound asset field: its folder', async () => {
204
+ const Field = defineComponent({
205
+ setup() {
206
+ const { boundFolder } = useFieldFolders('demo.cover')
207
+ return () => h('p', boundFolder.value?.name ?? 'no folder')
208
+ },
209
+ })
210
+ const page = await render(Field)
211
+ expect(page.reads).toEqual(['GET /api/media/bindings/demo.cover/folder'])
212
+ expect(page.handed).toEqual(page.reads)
213
+ expect(page.html).toContain('Demo covers')
214
+ })
215
+ })
@@ -1,5 +1,26 @@
1
+ import { resolve } from 'node:path'
2
+ import vue from '@vitejs/plugin-vue'
1
3
  import { defineConfig } from 'vitest/config'
2
4
 
5
+ // The renderer and the DMS core layer the server-render tests run on: the
6
+ // ones the module installs (`@antelopejs/dms-frontend`, `@antelopejs/dms`),
7
+ // as `pnpm test:frontend` checks the module against them.
8
+ const root = resolve(__dirname, '..', 'node_modules', '@antelopejs')
9
+
3
10
  export default defineConfig({
11
+ plugins: [vue()],
12
+ resolve: {
13
+ alias: {
14
+ '#dms/frontend-module': resolve(root, 'dms-frontend/templates/vue/frontend-module.ts'),
15
+ '#dms-core': resolve(root, 'dms/frontend-vue/layers/dms-core'),
16
+ '#dms-ui': resolve(root, 'dms/frontend-vue/layers/dms-ui'),
17
+ // One Vue for the renderer and the components.
18
+ vue: resolve(__dirname, 'node_modules/vue'),
19
+ // What the renderer reads of Inertia, vue-i18n and unhead in the browser only.
20
+ '@inertiajs/vue3': resolve(__dirname, 'tests/fixtures/inertia.ts'),
21
+ 'vue-i18n': resolve(__dirname, 'tests/fixtures/vueI18n.ts'),
22
+ '@unhead/vue': resolve(__dirname, 'tests/fixtures/unhead.ts'),
23
+ },
24
+ },
4
25
  test: { environment: 'node', include: ['tests/**/*.test.ts'] },
5
26
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antelopejs/dms-media",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,7 +14,12 @@
14
14
  "src"
15
15
  ],
16
16
  "main": "dist/index.js",
17
+ "types": "dist/index.d.ts",
17
18
  "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "default": "./dist/index.js"
22
+ },
18
23
  "./package.json": "./package.json"
19
24
  },
20
25
  "publishConfig": {
@@ -31,15 +36,16 @@
31
36
  "lint": "oxlint && oxfmt --check . && pnpm --dir frontend-vue lint && antelopejs-check-interface-ranges",
32
37
  "typecheck": "tsc --noEmit",
33
38
  "format": "oxfmt . && pnpm --dir frontend-vue format",
34
- "test": "pnpm run build && ajs module test .",
35
- "test:unit": "pnpm run build && DMS_MEDIA_TEST_DIR=dist/test/unit ajs module test .",
36
- "test:integration": "pnpm run build && DMS_MEDIA_TEST_DIR=dist/test/integration ajs module test .",
37
- "test:reload": "pnpm run build && node --test --test-force-exit tests/hot-reload.test.mjs",
39
+ "test": "[ -n \"$DMS_PREBUILT\" ] || pnpm run build && ajs module test .",
40
+ "test:unit": "[ -n \"$DMS_PREBUILT\" ] || pnpm run build && DMS_MEDIA_TEST_DIR=dist/test/unit ajs module test .",
41
+ "test:integration": "[ -n \"$DMS_PREBUILT\" ] || pnpm run build && DMS_MEDIA_TEST_DIR=dist/test/integration ajs module test .",
42
+ "test:reload": "[ -n \"$DMS_PREBUILT\" ] || pnpm run build && node --test --test-force-exit tests/hot-reload.test.mjs",
38
43
  "test:frontend": "ajs dms verify-source --layer node_modules/@antelopejs/dms/frontend-vue --module frontend-vue",
39
44
  "release": "pnpm --filter @antelopejs/interface-dms-media build && pnpm --dir frontend-vue install --frozen-lockfile && release-it",
40
45
  "prepack": "pnpm run build",
41
46
  "knip": "knip --dependencies",
42
- "knip:all": "knip"
47
+ "knip:all": "knip",
48
+ "test:exports": "node --test tests/package-exports.test.mjs"
43
49
  },
44
50
  "dependencies": {
45
51
  "@antelopejs/interface-api": ">=0.0.14 <1.0.0",
@@ -47,8 +53,8 @@
47
53
  "@antelopejs/interface-core": ">=0.1.1 <1.0.0",
48
54
  "@antelopejs/interface-database": ">=0.1.8 <1.0.0",
49
55
  "@antelopejs/interface-database-decorators": ">=0.1.7 <1.0.0",
50
- "@antelopejs/interface-dms": ">=0.5.12 <1.0.0",
51
- "@antelopejs/interface-dms-media": ">=0.2.0 <0.3.0",
56
+ "@antelopejs/interface-dms": ">=0.7.0 <1.0.0",
57
+ "@antelopejs/interface-dms-media": ">=0.2.1 <0.3.0",
52
58
  "@antelopejs/interface-file-storage": ">=0.1.3 <1.0.0",
53
59
  "node-cron": "^4.2.1",
54
60
  "sharp": "^0.34.4",
@@ -56,8 +62,8 @@
56
62
  },
57
63
  "devDependencies": {
58
64
  "@antelopejs/core": ">=1.13.5 <2",
59
- "@antelopejs/dms": ">=0.7.18 <0.8.0",
60
- "@antelopejs/dms-frontend": "0.5.4",
65
+ "@antelopejs/dms": ">=0.9.0 <1.0.0",
66
+ "@antelopejs/dms-frontend": "0.6.0",
61
67
  "@antelopejs/tooling-configs": ">=0.0.7 <1.0.0",
62
68
  "@types/chai": "^4.3.20",
63
69
  "@types/mocha": "^10",