corpushub-design-system 0.0.2 → 0.0.3
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/dist/common/AppDropzone/AppDropzoneBody.js +2 -1
- package/dist/common/AppDropzone/UploadedFile.d.ts +2 -0
- package/dist/common/AppDropzone/index.d.ts +2 -0
- package/dist/common/AppDropzone/index.js +1 -0
- package/dist/common/AppDropzone/toMediaDisplayUrl.d.ts +10 -0
- package/dist/common/AppDropzone/toMediaDisplayUrl.js +27 -0
- package/dist/common/index.d.ts +1 -1
- package/dist/common/index.js +1 -1
- package/dist/configs/types/CorpusImage.d.ts +3 -0
- package/package.json +1 -1
|
@@ -10,6 +10,7 @@ import { useMessageUtils } from '../../configs/useMessageUtils';
|
|
|
10
10
|
import AppModalConfirm from '../AppModal/AppModalConfirm';
|
|
11
11
|
import { DropzoneShell, useDropzoneMessages, } from '../AppDropzoneShell';
|
|
12
12
|
import UploadService from './UploadService';
|
|
13
|
+
import { withMediaDisplayUrl } from './toMediaDisplayUrl';
|
|
13
14
|
function isFileAlreadyExistsError(err) {
|
|
14
15
|
return (err?.response?.status === 409 &&
|
|
15
16
|
err?.response?.data?.description === 'upload.file.already.exists');
|
|
@@ -56,7 +57,7 @@ function AppDropzoneBodyInner({ folder, onSuccess, onError, accept, messages, on
|
|
|
56
57
|
};
|
|
57
58
|
const executeUpload = async (currentFile, replace) => {
|
|
58
59
|
const response = await UploadService.execute(buildUploadFormData(currentFile, replace));
|
|
59
|
-
onSuccess(response.data);
|
|
60
|
+
onSuccess(withMediaDisplayUrl(response.data));
|
|
60
61
|
};
|
|
61
62
|
const upload = async (replace = false) => {
|
|
62
63
|
const currentFile = fileRef.current;
|
|
@@ -2,3 +2,5 @@ import AppDropzone from './AppDropzone';
|
|
|
2
2
|
import AppDropzoneBody, { type AppDropzoneBodyProps, type AppDropzoneBodyRef } from './AppDropzoneBody';
|
|
3
3
|
export default AppDropzone;
|
|
4
4
|
export { AppDropzoneBody, type AppDropzoneBodyProps, type AppDropzoneBodyRef };
|
|
5
|
+
export { toMediaDisplayUrl, withMediaDisplayUrl } from './toMediaDisplayUrl';
|
|
6
|
+
export type { UploadedFile } from './UploadedFile';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { UploadedFile } from './UploadedFile';
|
|
2
|
+
/**
|
|
3
|
+
* Builds a browser-usable media URL from an upload response.
|
|
4
|
+
* Prefer httpPrefix + path (relative key); fall back to url when prefix is absent.
|
|
5
|
+
*/
|
|
6
|
+
export declare function toMediaDisplayUrl(file: Pick<UploadedFile, 'path' | 'url' | 'httpPrefix'>): string;
|
|
7
|
+
/**
|
|
8
|
+
* Keeps path as the relative persistence key and sets url to the display URL.
|
|
9
|
+
*/
|
|
10
|
+
export declare function withMediaDisplayUrl(file: UploadedFile): UploadedFile;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds a browser-usable media URL from an upload response.
|
|
3
|
+
* Prefer httpPrefix + path (relative key); fall back to url when prefix is absent.
|
|
4
|
+
*/
|
|
5
|
+
export function toMediaDisplayUrl(file) {
|
|
6
|
+
const prefix = file.httpPrefix?.replace(/\/+$/, '');
|
|
7
|
+
const key = file.path || file.url || '';
|
|
8
|
+
if (!prefix) {
|
|
9
|
+
return key;
|
|
10
|
+
}
|
|
11
|
+
if (!key) {
|
|
12
|
+
return prefix;
|
|
13
|
+
}
|
|
14
|
+
const normalizedKey = key.startsWith('/') ? key : `/${key}`;
|
|
15
|
+
return `${prefix}${normalizedKey}`;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Keeps path as the relative persistence key and sets url to the display URL.
|
|
19
|
+
*/
|
|
20
|
+
export function withMediaDisplayUrl(file) {
|
|
21
|
+
return {
|
|
22
|
+
...file,
|
|
23
|
+
path: file.path,
|
|
24
|
+
url: toMediaDisplayUrl(file),
|
|
25
|
+
httpPrefix: file.httpPrefix,
|
|
26
|
+
};
|
|
27
|
+
}
|
package/dist/common/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { default as AppClarity } from './AppClarity';
|
|
|
3
3
|
export { default as AppCard } from './AppCard/AppCard';
|
|
4
4
|
export { default as AppClipboard } from './AppClipboard';
|
|
5
5
|
export { default as AppColorpicker } from './AppColorpicker';
|
|
6
|
-
export { default as AppDropzone, AppDropzoneBody, type AppDropzoneBodyProps, type AppDropzoneBodyRef, } from './AppDropzone';
|
|
6
|
+
export { default as AppDropzone, AppDropzoneBody, type AppDropzoneBodyProps, type AppDropzoneBodyRef, toMediaDisplayUrl, withMediaDisplayUrl, } from './AppDropzone';
|
|
7
7
|
export type { UploadedFile } from './AppDropzone/UploadedFile';
|
|
8
8
|
export { default as AppDropzoneLocal, AppDropzoneBodyLocal, type AppDropzoneBodyLocalProps, type AppDropzoneBodyLocalRef, type UploadedFileLocal, } from './AppDropzoneLocal';
|
|
9
9
|
export { default as AppEditable } from './AppEditable';
|
package/dist/common/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export { default as AppClarity } from './AppClarity';
|
|
|
3
3
|
export { default as AppCard } from './AppCard/AppCard';
|
|
4
4
|
export { default as AppClipboard } from './AppClipboard';
|
|
5
5
|
export { default as AppColorpicker } from './AppColorpicker';
|
|
6
|
-
export { default as AppDropzone, AppDropzoneBody, } from './AppDropzone';
|
|
6
|
+
export { default as AppDropzone, AppDropzoneBody, toMediaDisplayUrl, withMediaDisplayUrl, } from './AppDropzone';
|
|
7
7
|
export { default as AppDropzoneLocal, AppDropzoneBodyLocal, } from './AppDropzoneLocal';
|
|
8
8
|
export { default as AppEditable } from './AppEditable';
|
|
9
9
|
export { validateFormField } from './AppEditable/FormField';
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export type CorpusImage = {
|
|
2
2
|
type?: CorpusImageType;
|
|
3
|
+
/** Relative storage key (or legacy absolute). Prefer url for browser src. */
|
|
3
4
|
path: string;
|
|
5
|
+
/** Absolute HTTP URL when returned from API serializers. */
|
|
6
|
+
url?: string;
|
|
4
7
|
};
|
|
5
8
|
export type CorpusImageType = 'COVER' | 'SLIDESHOW';
|
|
6
9
|
export declare const CorpusImageTypeNames: {
|