@antelopejs/dms-media 0.3.1 → 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 (48) 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/test/antelope.test.js +1 -1
  6. package/dist/test/helpers/pages.js +3 -2
  7. package/dist/test/helpers/pages.js.map +1 -1
  8. package/dist/test/integration/frontend-module.test.d.ts +1 -0
  9. package/dist/test/integration/frontend-module.test.js +13 -0
  10. package/dist/test/integration/frontend-module.test.js.map +1 -0
  11. package/frontend-vue/app/components/FileProperties.vue +9 -3
  12. package/frontend-vue/app/components/FirstRun.vue +1 -1
  13. package/frontend-vue/app/components/ImageEditor.vue +43 -26
  14. package/frontend-vue/app/components/PresetCards.vue +3 -11
  15. package/frontend-vue/app/components/RecentFiles.vue +6 -14
  16. package/frontend-vue/app/components/UploadQueue.vue +1 -1
  17. package/frontend-vue/app/components/UploadStrip.vue +1 -1
  18. package/frontend-vue/app/components/dialogs/DestinationDialog.vue +1 -2
  19. package/frontend-vue/app/components/explorer/ExplorerInspector.vue +17 -16
  20. package/frontend-vue/app/components/explorer/ExplorerShell.vue +11 -3
  21. package/frontend-vue/app/components/explorer/ExplorerToolbar.vue +2 -1
  22. package/frontend-vue/app/components/field/AssetValue.vue +12 -13
  23. package/frontend-vue/app/components/file/FileViewer.vue +1 -14
  24. package/frontend-vue/app/composables/library/useLibraryListing.ts +180 -79
  25. package/frontend-vue/app/composables/library/useLibraryTree.ts +31 -15
  26. package/frontend-vue/app/composables/library/useMediaLibrary.ts +17 -7
  27. package/frontend-vue/app/composables/uploadLimits.ts +25 -0
  28. package/frontend-vue/app/composables/useAssetContent.ts +20 -0
  29. package/frontend-vue/app/composables/useCurrentFile.ts +10 -8
  30. package/frontend-vue/app/composables/useFieldFolders.ts +19 -18
  31. package/frontend-vue/app/composables/useFileDetails.ts +117 -90
  32. package/frontend-vue/app/composables/useMediaApi.ts +18 -24
  33. package/frontend-vue/package.json +2 -1
  34. package/frontend-vue/pnpm-lock.yaml +17 -2
  35. package/frontend-vue/tests/engines.test.ts +20 -0
  36. package/frontend-vue/tests/fixtures/inertia.ts +8 -0
  37. package/frontend-vue/tests/fixtures/serverRender.ts +200 -0
  38. package/frontend-vue/tests/fixtures/unhead.ts +3 -0
  39. package/frontend-vue/tests/fixtures/vueI18n.ts +4 -0
  40. package/frontend-vue/tests/libraryListing.test.ts +120 -0
  41. package/frontend-vue/tests/serverRender.test.ts +215 -0
  42. package/frontend-vue/vitest.config.ts +21 -0
  43. package/package.json +11 -5
  44. package/src/index.ts +19 -2
  45. package/src/test/antelope.test.ts +1 -1
  46. package/src/test/helpers/pages.ts +3 -2
  47. package/src/test/integration/frontend-module.test.ts +13 -0
  48. package/frontend-vue/app/composables/useSharedTree.ts +0 -73
package/README.md CHANGED
@@ -202,7 +202,11 @@ The playground connects to MongoDB at `mongodb://localhost:27017` by default. Se
202
202
 
203
203
  The frontend entry is `frontend-vue/dms.frontend.ts`. It declares `componentPrefix: "DmsMedia"` and registers the blocks of `app/components/*.vue` by file name (`Explorer` is served as `DmsMediaExplorer`); the parts in subfolders are imported by path. `dms.frontend.build.ts` auto-imports `app/composables` and `app/utils`. Use relative imports for module-local files because the Inertia adapter copies the frontend separately from the backend. The adapter discovers locale files and `app/config/shortcuts-registry.ts`; no Nuxt installation is required.
204
204
 
205
- The playground uses the `@antelopejs/dms-frontend` CLI. Run `pnpm --dir frontend-vue install` and `pnpm --dir frontend-vue test` for frontend tests. `pnpm test:frontend` typechecks the layer against the DMS layer (`ajs dms verify-source`), without a running backend; CI runs it.
205
+ The blocks read the data they render with the DMS's `useApiData` (`@antelopejs/dms` 0.9, `@antelopejs/interface-dms` 0.7, `@antelopejs/dms-frontend` 0.6): a server render reads it and hands it to the browser with the page. The explorer's folder tree is the same read, and its file listing one `useApiPagedData` read keyed by the location and the filters ("Load more" appends a page, a library change reads every loaded page again). The reads that follow the library's realtime changes on their own opt out of the page's refreshes. Writes, downloads, and the reads of the asset field's entries, the dialogs and the image editor's canvas, stay `$authFetch` calls in the browser.
206
+
207
+ The file links (`/media/<id>/<name>`) are served by the backend. The module declares `/media/**` as a backend prefix (`backendProxies`, with the session), so that a link on the dashboard's origin reaches the backend and a private file opens for a signed-in member.
208
+
209
+ The playground uses the `@antelopejs/dms-frontend` CLI. Run `pnpm --dir frontend-vue install` and `pnpm --dir frontend-vue test` for frontend tests; `tests/serverRender.test.ts` renders the blocks on the server with the renderer and the DMS layer the package installs. `pnpm test:frontend` typechecks the layer against the DMS layer (`ajs dms verify-source`), without a running backend; CI runs it.
206
210
 
207
211
  ## Known limitations (v1)
208
212
 
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { type FrontendBackendProxy } from "@antelopejs/interface-dms/page";
1
2
  import "./db";
2
3
  import { type DmsMediaConfig } from "./config";
3
4
  export * from "./acl";
@@ -12,6 +13,8 @@ export * from "./presets";
12
13
  export * from "./routes";
13
14
  export * from "./transform";
14
15
  export * from "./types";
16
+ export declare const MEDIA_FRONTEND_MODULE = "@antelopejs/dms-media-frontend-vue";
17
+ export declare const MEDIA_DELIVERY_PROXY: FrontendBackendProxy;
15
18
  export declare function construct(config?: DmsMediaConfig): Promise<void>;
16
19
  export declare function start(): void;
17
20
  export declare function stop(): Promise<void>;
package/dist/index.js CHANGED
@@ -39,6 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.MEDIA_DELIVERY_PROXY = exports.MEDIA_FRONTEND_MODULE = void 0;
42
43
  exports.construct = construct;
43
44
  exports.start = start;
44
45
  exports.stop = stop;
@@ -63,16 +64,22 @@ __exportStar(require("./routes"), exports);
63
64
  __exportStar(require("./transform"), exports);
64
65
  __exportStar(require("./types"), exports);
65
66
  let cronTasks = [];
67
+ exports.MEDIA_FRONTEND_MODULE = "@antelopejs/dms-media-frontend-vue";
68
+ exports.MEDIA_DELIVERY_PROXY = {
69
+ path: "/media/**",
70
+ auth: "session",
71
+ };
66
72
  async function construct(config = {}) {
67
73
  (0, config_1.configureMediaModule)(config);
68
74
  (0, interface_core_1.ImplementInterface)(await Promise.resolve().then(() => __importStar(require("@antelopejs/interface-dms-media"))), await Promise.resolve().then(() => __importStar(require("./implementations/interface-dms-media"))));
69
75
  const sourcePath = node_path_1.default.join(__dirname, "../frontend-vue");
70
76
  await (0, page_1.AddFrontendModule)({
71
- name: "@antelopejs/dms-media-frontend-vue",
77
+ name: exports.MEDIA_FRONTEND_MODULE,
72
78
  sourcePath,
73
79
  renderer: { name: "vue", version: "3" },
74
80
  configKey: "dmsMedia",
75
81
  priority: 0,
82
+ backendProxies: [exports.MEDIA_DELIVERY_PROXY],
76
83
  });
77
84
  }
78
85
  function start() {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,8BAeC;AAED,sBAEC;AAED,oBAWC;AAzDD,0DAA6B;AAC7B,+DAAgE;AAChE,yDAAmE;AACnE,gEAA6D;AAC7D,gBAAc;AAEd,qCAAqE;AACrE,mCAA6C;AAC7C,iDAAyD;AAEzD,wCAAsB;AACtB,6CAA2B;AAC3B,2CAAyB;AACzB,8CAA4B;AAC5B,0CAAwB;AACxB,uCAAqB;AACrB,gDAA8B;AAC9B,0CAAwB;AACxB,4CAA0B;AAC1B,2CAAyB;AACzB,8CAA4B;AAC5B,0CAAwB;AAExB,IAAI,SAAS,GAAoB,EAAE,CAAC;AAE7B,KAAK,UAAU,SAAS,CAAC,SAAyB,EAAE;IACzD,IAAA,6BAAoB,EAAC,MAAM,CAAC,CAAC;IAC7B,IAAA,mCAAkB,EAChB,wDAAa,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B,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;IACD,SAAS,GAAG,EAAE,CAAC;AACjB,CAAC"}
@@ -99,7 +99,7 @@ exports.default = (0, config_1.defineConfig)({
99
99
  source: {
100
100
  type: "package",
101
101
  package: "@antelopejs/dms",
102
- version: ">=0.8.0 <0.9.0",
102
+ version: ">=0.9.0 <1.0.0",
103
103
  },
104
104
  config: {
105
105
  auth: {
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.readPageAccess = readPageAccess;
4
+ const page_1 = require("@antelopejs/interface-dms/page");
4
5
  const HTTP_OK = 200;
5
- const PAGE_LAYOUT_SUFFIX = "/pagelayout";
6
+ const PAGE_LAYOUT_ROUTE = "/pagelayout";
6
7
  const OMIT_SHARED_PAGE = "false";
7
8
  function countBlocks(components) {
8
9
  if (Array.isArray(components))
@@ -11,7 +12,7 @@ function countBlocks(components) {
11
12
  }
12
13
  async function readPageAccess(client, slug) {
13
14
  const [ownRoute, page, layout] = await Promise.all([
14
- client.get(`${slug}${PAGE_LAYOUT_SUFFIX}`),
15
+ client.get((0, page_1.pageRoutePath)(slug, PAGE_LAYOUT_ROUTE)),
15
16
  client.get("/dms/page", {
16
17
  params: { path: slug, shared: OMIT_SHARED_PAGE },
17
18
  }),
@@ -1 +1 @@
1
- {"version":3,"file":"pages.js","sourceRoot":"","sources":["../../../src/test/helpers/pages.ts"],"names":[],"mappings":";;AAsBA,wCAqBC;AAzCD,MAAM,OAAO,GAAG,GAAG,CAAC;AACpB,MAAM,kBAAkB,GAAG,aAAa,CAAC;AACzC,MAAM,gBAAgB,GAAG,OAAO,CAAC;AAYjC,SAAS,WAAW,CAAC,UAAmB;IACtC,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC;QAAE,OAAO,UAAU,CAAC,MAAM,CAAC;IACxD,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,IAAI,EAAE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AAU,CAAC,MAAM,CAAC;IACxD,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;AAC9C,CAAC;AAGM,KAAK,UAAU,cAAc,CAClC,MAAqB,EACrB,IAAY;IAEZ,MAAM,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACjD,MAAM,CAAC,GAAG,CAAC,IAAA,oBAAa,EAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;QAClD,MAAM,CAAC,GAAG,CAAC,WAAW,EAAE;YACtB,MAAM,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,gBAAgB,EAAE;SACjD,CAAC;QACF,MAAM,CAAC,GAAG,CAAC,iBAAiB,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC;KACpD,CAAC,CAAC;IACH,IAAI,IAAI,CAAC,MAAM,KAAK,OAAO,IAAI,MAAM,CAAC,MAAM,KAAK,OAAO,EAAE,CAAC;QACzD,MAAM,IAAI,KAAK,CACb,QAAQ,IAAI,aAAa,IAAI,CAAC,MAAM,qBAAqB,MAAM,CAAC,MAAM,qBAAqB,CAC5F,CAAC;IACJ,CAAC;IACD,OAAO;QACL,cAAc,EAAE,QAAQ,CAAC,MAAM;QAC/B,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI;QAC9C,YAAY,EAAE,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC;KAClD,CAAC;AACJ,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const page_1 = require("@antelopejs/interface-dms/page");
4
+ const chai_1 = require("chai");
5
+ const index_1 = require("../../index");
6
+ describe("frontend module", () => {
7
+ it("declares the file links as a backend prefix the frontend server proxies with the session", async () => {
8
+ const modules = await (0, page_1.GetFrontendModules)();
9
+ const media = modules.find((module) => module.name === index_1.MEDIA_FRONTEND_MODULE);
10
+ (0, chai_1.expect)(media?.backendProxies).to.deep.equal([index_1.MEDIA_DELIVERY_PROXY]);
11
+ });
12
+ });
13
+ //# sourceMappingURL=frontend-module.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frontend-module.test.js","sourceRoot":"","sources":["../../../src/test/integration/frontend-module.test.ts"],"names":[],"mappings":";;AAAA,yDAAoE;AACpE,+BAA8B;AAC9B,uCAA0E;AAE1E,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,EAAE,CAAC,0FAA0F,EAAE,KAAK,IAAI,EAAE;QACxG,MAAM,OAAO,GAAG,MAAM,IAAA,yBAAkB,GAAE,CAAC;QAC3C,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CACxB,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,6BAAqB,CAClD,CAAC;QACF,IAAA,aAAM,EAAC,KAAK,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,4BAAoB,CAAC,CAAC,CAAC;IACtE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -16,7 +16,14 @@ const assetLink = useAssetLink()
16
16
  const file = useCurrentFile()
17
17
  const asset = computed(() => file.asset.value)
18
18
  const details = computed(() => file.details.value)
19
- const nameDraft = ref('')
19
+ /** What the reader typed in the name field; the file's own name until then, so a server render shows it. */
20
+ const typedName = ref<string | null>(null)
21
+ const nameDraft = computed({
22
+ get: () => typedName.value ?? (asset.value ? baseNameOf(asset.value) : ''),
23
+ set: (value: string) => {
24
+ typedName.value = value
25
+ },
26
+ })
20
27
  const extension = computed(() => (asset.value ? extensionOf(asset.value) : ''))
21
28
  const hasExtension = computed(() => Boolean(asset.value?.name.toLowerCase().endsWith(`.${extension.value}`)))
22
29
  const nameMaxLength = computed(() => NAME_MAX_LENGTH - (hasExtension.value ? extension.value.length + 1 : 0))
@@ -33,9 +40,8 @@ const keepsFormatHint = computed(() =>
33
40
  watch(
34
41
  () => [asset.value?.id, asset.value?.name],
35
42
  () => {
36
- if (asset.value) nameDraft.value = baseNameOf(asset.value)
43
+ typedName.value = null
37
44
  },
38
- { immediate: true },
39
45
  )
40
46
 
41
47
  /** `banner.jpg` typed on a JPG keeps one `.jpg`, rather than saving `banner.jpg.jpg`. */
@@ -17,7 +17,7 @@ const STARTERS: StarterFolder[] = [
17
17
  const api = useMediaApi()
18
18
  const { t } = useI18n()
19
19
  const toast = useToast()
20
- const { tree } = useSharedTree()
20
+ const { tree } = useLibraryTree()
21
21
  const isCreating = ref(false)
22
22
 
23
23
  const isEmpty = computed(
@@ -1,7 +1,8 @@
1
1
  <script setup lang="ts">
2
+ import { useMounted } from '@vueuse/core'
2
3
  import { Cropper, Preview } from 'vue-advanced-cropper'
3
4
  import 'vue-advanced-cropper/dist/style.css'
4
- import type { AssetDetails, DeliveryPreset, MediaAsset } from '../types/media'
5
+ import type { AssetDetails, DeliveryPreset, MediaAsset, PresetsResponse } from '../types/media'
5
6
  import type { TransformOperations } from '../composables/useMediaApi'
6
7
  import { type AspectOption, aspectOptions, FREE_ASPECT_ID, ORIGINAL_ASPECT_ID, type PixelSize, rotatedSize as turnSize } from '../utils/editorAspects'
7
8
 
@@ -85,16 +86,18 @@ const KEY_STEPS: Record<string, KeyStep> = {
85
86
  const route = useDmsRoute()
86
87
  const api = useMediaApi()
87
88
  const { t } = useI18n()
89
+ const { keyLabel } = useKeyboardPlatform()
88
90
  const toast = useToast()
89
91
  const format = useMediaFormat()
90
92
  const { confirm } = useConfirm()
91
93
  const cropper = useTemplateRef<CropperHandle>('cropper')
92
94
  const stage = useTemplateRef<HTMLElement>('stage')
93
95
  const aspectGroup = useTemplateRef<HTMLElement>('aspectGroup')
94
- const details = ref<AssetDetails | null>(null)
95
- const presets = ref<DeliveryPreset[]>([])
96
+ const isMounted = useMounted()
96
97
  const source = ref<string | null>(null)
97
- const loadState = ref<LoadState>('loading')
98
+ const sourceFailed = ref(false)
99
+ /** Counts the retries, so that a retry loads the image again. */
100
+ const attempt = ref(0)
98
101
  const rotation = ref(0)
99
102
  const aspect = ref(FREE_ASPECT_ID)
100
103
  const change = ref<CropperChange | null>(null)
@@ -102,8 +105,20 @@ const isSaving = ref(false)
102
105
  const isCropperReady = ref(false)
103
106
 
104
107
  const assetId = computed(() => (typeof route.query.asset === 'string' ? route.query.asset : undefined))
108
+ /** The file's details, read with the page: a server render shows its name and whether it can be edited. */
109
+ const detailsRead = useApiData<AssetDetails>(() => (assetId.value ? MEDIA_READS.details(assetId.value) : null))
110
+ const details = computed(() => (detailsRead.error.value || detailsRead.placeholder.value ? null : detailsRead.data.value))
105
111
  const asset = computed(() => details.value?.asset)
106
112
  const isEditable = computed(() => Boolean(asset.value && isEditableAsset(asset.value)))
113
+ /** The delivery sizes previewed under the crop, which only the browser draws: read once mounted. */
114
+ const presetsRead = useApiData<PresetsResponse>(() => (isMounted.value && isEditable.value ? MEDIA_READS.presets : null))
115
+ const presets = computed<DeliveryPreset[]>(() => presetsRead.data.value?.presets ?? [])
116
+ const loadState = computed<LoadState>(() => {
117
+ const error = detailsRead.error.value
118
+ if (error && detailsRead.status.value !== 'pending') return isOutOfReachError(error) ? 'missing' : 'error'
119
+ if (sourceFailed.value) return 'error'
120
+ return asset.value ? 'ready' : 'loading'
121
+ })
107
122
  const isEditing = computed(() => loadState.value === 'ready' && isEditable.value)
108
123
 
109
124
  const imageSize = computed<PixelSize | undefined>(() => {
@@ -224,25 +239,18 @@ function resetEdits(): void {
224
239
  isCropperReady.value = false
225
240
  }
226
241
 
227
- async function load(): Promise<void> {
228
- source.value = null
229
- details.value = null
230
- resetEdits()
231
- if (!assetId.value) return
232
- loadState.value = 'loading'
233
- try {
234
- details.value = await api.details(assetId.value)
235
- } catch (error) {
236
- loadState.value = isOutOfReachError(error) ? 'missing' : 'error'
237
- return
238
- }
239
- loadState.value = 'ready'
240
- if (!isEditable.value || !asset.value) return
241
- void api.presets().then((response) => (presets.value = response.presets)).catch(() => undefined)
242
- source.value = await editingSource(asset.value).catch(() => {
243
- loadState.value = 'error'
244
- return null
245
- })
242
+ /** The image the cropper edits, loaded by the browser once the file is known to be editable. */
243
+ async function loadSource(target: MediaAsset): Promise<void> {
244
+ const url = await editingSource(target).catch(() => null)
245
+ if (asset.value?.id !== target.id) return
246
+ if (url) source.value = url
247
+ else sourceFailed.value = true
248
+ }
249
+
250
+ async function retry(): Promise<void> {
251
+ sourceFailed.value = false
252
+ await detailsRead.refresh()
253
+ attempt.value += 1
246
254
  }
247
255
 
248
256
  function onCropperReady(): void {
@@ -395,7 +403,16 @@ const notEditableDescription = computed(() =>
395
403
  asset.value?.mimetype === VECTOR_MIMETYPE ? t('dms_media.editor.not_editable_vector') : t('dms_media.editor.not_editable_formats'),
396
404
  )
397
405
 
398
- watch(assetId, () => void load(), { immediate: true })
406
+ watch(
407
+ () => [isMounted.value && isEditable.value ? asset.value?.id : undefined, attempt.value] as const,
408
+ ([id]) => {
409
+ source.value = null
410
+ sourceFailed.value = false
411
+ resetEdits()
412
+ if (id && asset.value) void loadSource(asset.value)
413
+ },
414
+ { immediate: true },
415
+ )
399
416
  /** A fixed ratio starts as the largest frame of that ratio, centred on the image. */
400
417
  watch(stencilRatio, async (ratio) => {
401
418
  await nextTick()
@@ -436,7 +453,7 @@ definePageShortcuts(() => ({
436
453
  variant="error"
437
454
  :title="t('dms_media.editor.load_failed')"
438
455
  :description="t('dms_media.editor.load_failed_description')"
439
- :actions="[{ label: t('dms_media.actions.retry'), icon: 'i-ph-arrow-clockwise', onClick: load }]"
456
+ :actions="[{ label: t('dms_media.actions.retry'), icon: 'i-ph-arrow-clockwise', onClick: retry }]"
440
457
  />
441
458
  <DmsEmptyState
442
459
  v-else-if="asset && !isEditable"
@@ -572,7 +589,7 @@ definePageShortcuts(() => ({
572
589
  :label="pending.length ? t('dms_media.editor.save', { count: pending.length }, pending.length) : t('dms_media.editor.save_none')"
573
590
  @click="save"
574
591
  >
575
- <template #trailing><UKbd value="meta" size="sm" variant="subtle" /><UKbd value="S" size="sm" variant="subtle" /></template>
592
+ <template #trailing><UKbd :value="keyLabel('meta')" size="sm" variant="subtle" /><UKbd value="S" size="sm" variant="subtle" /></template>
576
593
  </UButton>
577
594
  <div class="grid grid-cols-2 gap-2">
578
595
  <UButton block color="neutral" variant="outline" :label="t('dms_media.editor.discard')" @click="leave" />
@@ -29,25 +29,17 @@ interface PresetFact {
29
29
  hint?: string
30
30
  }
31
31
 
32
- const api = useMediaApi()
33
32
  const format = useMediaFormat()
34
33
  const { t, te } = useI18n()
35
- const data = ref<ImageSizesResponse | null>(null)
36
- const failed = ref(false)
34
+ const presets = useApiData<ImageSizesResponse>(MEDIA_READS.presets)
35
+ const data = presets.data
36
+ const failed = computed(() => Boolean(presets.error.value) && presets.status.value !== 'pending')
37
37
  const brokenExamples = ref(new Set<string>())
38
38
  const BOX_SIZE = 140
39
39
  const MIN_BOX_SIZE = 28
40
40
  const UNBOUNDED_RATIO = 0.62
41
41
  const DEFAULT_FIT = 'cover'
42
42
 
43
- onMounted(async () => {
44
- try {
45
- data.value = (await api.presets()) as ImageSizesResponse
46
- } catch {
47
- failed.value = true
48
- }
49
- })
50
-
51
43
  /** The example's own size, or a landscape stand-in when there is none. */
52
44
  const sourceSize = computed<PixelSize>(() => {
53
45
  const example = data.value?.example
@@ -2,24 +2,16 @@
2
2
  import type { MediaAsset } from '../types/media'
3
3
  import AssetThumb from './shared/AssetThumb.vue'
4
4
 
5
- const api = useMediaApi()
6
5
  const format = useMediaFormat()
7
6
  const { t } = useI18n()
8
- const assets = ref<MediaAsset[]>([])
9
- const { tree } = useSharedTree()
10
- const isLoading = ref(true)
7
+ // Read again on each library change, its own trigger: the page's refreshes leave it alone.
8
+ const recent = useApiData<{ assets: MediaAsset[] }>(MEDIA_READS.recent, { refreshOnPageRefresh: false })
9
+ const assets = computed(() => recent.data.value?.assets ?? [])
10
+ const { tree } = useLibraryTree()
11
+ const isLoading = computed(() => recent.status.value === 'pending' && !recent.data.value)
11
12
  const SKELETONS = 6
12
13
 
13
- async function load(): Promise<void> {
14
- try {
15
- assets.value = (await api.recent()).assets
16
- } finally {
17
- isLoading.value = false
18
- }
19
- }
20
-
21
- onMounted(() => void load())
22
- onLibraryChange(load)
14
+ onLibraryChange(() => recent.refresh())
23
15
 
24
16
  const foldersById = computed(() => new Map((tree.value?.folders ?? []).map((folder) => [folder.id, folder])))
25
17
  </script>
@@ -9,7 +9,7 @@ const format = useMediaFormat()
9
9
  const overlay = useOverlay()
10
10
  const destinationDialog = overlay.create(DestinationDialog)
11
11
  const { prefs, update } = useMediaPrefs()
12
- const { tree, reload } = useSharedTree()
12
+ const { tree, refresh: reload } = useLibraryTree()
13
13
  const toasts = useUploadToasts()
14
14
  const route = useDmsRoute()
15
15
  const router = useDmsRouter()
@@ -6,7 +6,7 @@ const uploads = useUploadQueue()
6
6
  const overlay = useOverlay()
7
7
  const destinationDialog = overlay.create(DestinationDialog)
8
8
  const { prefs, update } = useMediaPrefs()
9
- const { tree, reload } = useSharedTree()
9
+ const { tree, refresh: reload } = useLibraryTree()
10
10
  const { t } = useI18n()
11
11
  const toast = useUploadToasts()
12
12
  const fileInput = useTemplateRef<HTMLInputElement>('fileInput')
@@ -19,7 +19,7 @@ const api = useMediaApi()
19
19
  const toast = useToast()
20
20
  const format = useMediaFormat()
21
21
  const nameDialog = useOverlay().create(NameDialog)
22
- const { tree, reload } = useSharedTree()
22
+ const { tree, refresh: reload } = useLibraryTree()
23
23
  const pickerRoot = useTemplateRef<HTMLElement>('pickerRoot')
24
24
  const isCreating = ref(false)
25
25
 
@@ -87,7 +87,6 @@ const stopFocusing = watch(pickerRoot, (root) => {
87
87
  setTimeout(() => root.querySelector('input')?.focus())
88
88
  })
89
89
 
90
- onMounted(() => void reload())
91
90
  </script>
92
91
 
93
92
  <template>
@@ -1,4 +1,7 @@
1
1
  <script setup lang="ts">
2
+ import type { ApiDataResult } from '#dms-core/app/composables/auth/useApiData'
3
+ import type { ReadUrl } from '../../composables/useMediaApi'
4
+ import type { AssetDetails } from '../../types/media'
2
5
  import AltTextField from '../shared/AltTextField.vue'
3
6
  import AssetThumb from '../shared/AssetThumb.vue'
4
7
  import FolderGlyph from '../shared/FolderGlyph.vue'
@@ -22,25 +25,23 @@ const assetPath = computed(() => folderPathLabel(assetFolder.value, library.tree
22
25
  const canEdit = computed(() => (asset.value ? commands.canWriteAsset(asset.value) : false))
23
26
  const isBrowse = library.mode === 'browse'
24
27
  const PREVIEW_PRESET = 'preview'
25
- const previewUrl = ref<string>()
26
- const uploadedBy = ref<string | null>(null)
28
+ // The preview uncropped, at the file's own ratio, and who added it, for the
29
+ // file in view: read while it is in view, shared with the other blocks
30
+ // reading the same file.
31
+ const assetId = computed(() => asset.value?.id)
32
+ const previewRead = useApiData<ReadUrl>(
33
+ () => (asset.value && isImageAsset(asset.value) ? MEDIA_READS.readUrl(asset.value.id) : null),
34
+ { query: { preset: PREVIEW_PRESET } },
35
+ )
36
+ const detailsRead = useApiData<AssetDetails>(() => (assetId.value ? MEDIA_READS.details(assetId.value) : null))
27
37
 
28
- /** The preview uncropped, at the file's own ratio, and who added it, for the file in view. */
29
- async function loadDetails(assetId: string | undefined): Promise<void> {
30
- previewUrl.value = undefined
31
- uploadedBy.value = null
32
- const target = asset.value
33
- if (!assetId || !target) return
34
- const [read, details] = await Promise.all([
35
- isImageAsset(target) ? library.api.readUrl(assetId, PREVIEW_PRESET).catch(() => undefined) : undefined,
36
- library.api.details(assetId).catch(() => undefined),
37
- ])
38
- if (asset.value?.id !== assetId) return
39
- previewUrl.value = read?.url
40
- uploadedBy.value = details?.uploadedBy ?? null
38
+ /** Nothing of the previous file shows while the next one's reads are under way. */
39
+ function isCurrent<T>(read: ApiDataResult<T>): boolean {
40
+ return !read.placeholder.value && !read.error.value
41
41
  }
42
42
 
43
- watch(() => asset.value?.id, (assetId) => void loadDetails(assetId), { immediate: true })
43
+ const previewUrl = computed(() => (isCurrent(previewRead) ? previewRead.data.value?.url : undefined))
44
+ const uploadedBy = computed(() => (isCurrent(detailsRead) ? (detailsRead.data.value?.uploadedBy ?? null) : null))
44
45
 
45
46
  function saveAlt(alt: string): Promise<boolean> {
46
47
  return asset.value ? library.actions.setAlt(asset.value, alt) : Promise.resolve(false)
@@ -1,6 +1,6 @@
1
1
  <script setup lang="ts">
2
2
  import type { ExplorerHistory } from '../../composables/library/useExplorerLayout'
3
- import type { LibraryLocation, ListingFilters } from '../../composables/library/useLibraryListing'
3
+ import { type LibraryLocation, type ListingFilters, sameLocation } from '../../composables/library/useLibraryListing'
4
4
  import type { MediaAsset, MediaFolder } from '../../types/media'
5
5
  import MediaLightbox from '../shared/MediaLightbox.vue'
6
6
  import BulkBar from './BulkBar.vue'
@@ -37,6 +37,9 @@ const library = provideMediaLibrary({
37
37
  remaining: props.remaining,
38
38
  scopeFolderId: props.scopeFolderId,
39
39
  alreadyPicked: props.alreadyPicked,
40
+ // Started here rather than once mounted, so that a server render reads a link's folder with the page.
41
+ initialLocation: props.initialLocation ?? startLocation(),
42
+ initialFilters: props.initialFilters,
40
43
  })
41
44
  const layout = createExplorerLayout(root, {
42
45
  scopeFolderId: props.scopeFolderId,
@@ -149,8 +152,13 @@ async function navigate(target: LibraryLocation, filters: Partial<ListingFilters
149
152
  }
150
153
 
151
154
  onMounted(async () => {
152
- await library.tree.refresh()
153
- await navigate(props.initialLocation ?? startLocation(), props.initialFilters)
155
+ await library.tree.ready()
156
+ const start = checkedLocation(props.initialLocation ?? startLocation())
157
+ // The listing started there, with its filters: opening it again would only reset them. The
158
+ // page still hears where it starts, as it does after a navigation.
159
+ if (!sameLocation(start, library.listing.location.value)) return navigate(start, props.initialFilters)
160
+ emit('location', library.listing.location.value)
161
+ emit('filters', library.listing.filters.value)
154
162
  })
155
163
 
156
164
  const isBrowse = props.mode === 'browse'
@@ -9,6 +9,7 @@ const { library, commands } = useExplorerContext()
9
9
  const layout = useExplorerLayout()
10
10
  const drop = useExplorerDrop()
11
11
  const { t } = useI18n()
12
+ const { keyLabel } = useKeyboardPlatform()
12
13
  const { prefs, update } = useMediaPrefs()
13
14
  const searchInput = useTemplateRef<{ inputRef?: HTMLInputElement }>('search')
14
15
  const query = ref('')
@@ -195,7 +196,7 @@ defineExpose({ focusSearch: () => searchInput.value?.inputRef?.focus() })
195
196
  @click="clearQuery"
196
197
  />
197
198
  <span v-else class="hidden items-center gap-0.5 sm:inline-flex [@media(pointer:coarse)]:hidden">
198
- <UKbd value="meta" size="sm" />
199
+ <UKbd :value="keyLabel('meta')" size="sm" />
199
200
  <UKbd value="/" size="sm" />
200
201
  </span>
201
202
  </template>
@@ -4,8 +4,6 @@ import AssetThumb from '../shared/AssetThumb.vue'
4
4
 
5
5
  const props = defineProps<{ value: unknown }>()
6
6
  const { t } = useI18n()
7
- const api = useMediaApi()
8
- const assets = ref<(MediaAsset | null)[]>([])
9
7
 
10
8
  const SHOWN_NAMES = 2
11
9
 
@@ -18,21 +16,22 @@ const ids = computed<string[]>(() => {
18
16
  const shownIds = computed(() => ids.value.slice(0, SHOWN_NAMES))
19
17
  const hidden = computed(() => Math.max(ids.value.length - SHOWN_NAMES, 0))
20
18
 
21
- /** Only the files the cell names are read: the others are counted. */
22
- watch(
23
- shownIds,
24
- async (list) => {
25
- assets.value = await Promise.all(
26
- list.map((id) =>
27
- api
28
- .asset(id)
19
+ /**
20
+ * Only the files the cell names are read, with the page: the others are
21
+ * counted. A file the server does not answer for shows as missing.
22
+ */
23
+ const read = useApiData<(MediaAsset | null)[]>(
24
+ () => `dms-media:asset-names:${shownIds.value.join(',')}`,
25
+ ({ $authFetch, signal }) =>
26
+ Promise.all(
27
+ shownIds.value.map((id) =>
28
+ $authFetch<{ asset: MediaAsset }>(MEDIA_READS.asset(id), { signal })
29
29
  .then((response) => response.asset)
30
30
  .catch(() => null),
31
31
  ),
32
- )
33
- },
34
- { immediate: true },
32
+ ),
35
33
  )
34
+ const assets = computed(() => (read.placeholder.value ? [] : (read.data.value ?? [])))
36
35
  </script>
37
36
 
38
37
  <template>
@@ -1,28 +1,15 @@
1
1
  <script setup lang="ts">
2
2
  import type { MediaAsset } from '../../types/media'
3
- import type { AssetContent } from '../../composables/useAssetContent'
4
3
  import AssetThumb from '../shared/AssetThumb.vue'
5
4
 
6
5
  const props = defineProps<{ asset: MediaAsset; siblings: MediaAsset[] }>()
7
6
  const emit = defineEmits<{ open: [string]; fullscreen: [] }>()
8
- const contents = useAssetContent()
9
7
  const assetLink = useAssetLink()
10
8
  const format = useMediaFormat()
11
9
  const { t } = useI18n()
12
- const content = ref<AssetContent>({ kind: 'none' })
10
+ const content = useShownContent(() => props.asset)
13
11
  const filmstrip = useTemplateRef<HTMLElement>('filmstrip')
14
12
 
15
- watch(
16
- () => [props.asset.id, props.asset.updatedAt],
17
- async () => {
18
- const shown = props.asset
19
- content.value = { kind: 'none' }
20
- const loaded = await contents.load(shown)
21
- if (shown.id === props.asset.id) content.value = loaded
22
- },
23
- { immediate: true },
24
- )
25
-
26
13
  watch(
27
14
  () => props.asset.id,
28
15
  async (id) => {