@strapi/upload 5.35.0 → 5.36.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.
- package/dist/admin/future/App.js +4 -9
- package/dist/admin/future/App.js.map +1 -1
- package/dist/admin/future/App.mjs +4 -9
- package/dist/admin/future/App.mjs.map +1 -1
- package/dist/admin/future/enums.js +12 -0
- package/dist/admin/future/enums.js.map +1 -0
- package/dist/admin/future/enums.mjs +10 -0
- package/dist/admin/future/enums.mjs.map +1 -0
- package/dist/admin/future/pages/Assets/AssetsPage.js +342 -0
- package/dist/admin/future/pages/Assets/AssetsPage.js.map +1 -0
- package/dist/admin/future/pages/Assets/AssetsPage.mjs +321 -0
- package/dist/admin/future/pages/Assets/AssetsPage.mjs.map +1 -0
- package/dist/admin/future/pages/Assets/components/AssetsGrid.js +164 -0
- package/dist/admin/future/pages/Assets/components/AssetsGrid.js.map +1 -0
- package/dist/admin/future/pages/Assets/components/AssetsGrid.mjs +162 -0
- package/dist/admin/future/pages/Assets/components/AssetsGrid.mjs.map +1 -0
- package/dist/admin/future/pages/Assets/components/AssetsTable.js +198 -0
- package/dist/admin/future/pages/Assets/components/AssetsTable.js.map +1 -0
- package/dist/admin/future/pages/Assets/components/AssetsTable.mjs +196 -0
- package/dist/admin/future/pages/Assets/components/AssetsTable.mjs.map +1 -0
- package/dist/admin/future/pages/Assets/components/DropZone/DropZoneWithOverlay.js +33 -0
- package/dist/admin/future/pages/Assets/components/DropZone/DropZoneWithOverlay.js.map +1 -0
- package/dist/admin/future/pages/Assets/components/DropZone/DropZoneWithOverlay.mjs +31 -0
- package/dist/admin/future/pages/Assets/components/DropZone/DropZoneWithOverlay.mjs.map +1 -0
- package/dist/admin/future/pages/Assets/components/DropZone/UploadDropZoneContext.js +107 -0
- package/dist/admin/future/pages/Assets/components/DropZone/UploadDropZoneContext.js.map +1 -0
- package/dist/admin/future/pages/Assets/components/DropZone/UploadDropZoneContext.mjs +104 -0
- package/dist/admin/future/pages/Assets/components/DropZone/UploadDropZoneContext.mjs.map +1 -0
- package/dist/admin/future/pages/Assets/constants.js +54 -0
- package/dist/admin/future/pages/Assets/constants.js.map +1 -0
- package/dist/admin/future/pages/Assets/constants.mjs +50 -0
- package/dist/admin/future/pages/Assets/constants.mjs.map +1 -0
- package/dist/admin/future/services/assets.js +37 -0
- package/dist/admin/future/services/assets.js.map +1 -0
- package/dist/admin/future/services/assets.mjs +35 -0
- package/dist/admin/future/services/assets.mjs.map +1 -0
- package/dist/admin/future/utils/files.js +23 -0
- package/dist/admin/future/utils/files.js.map +1 -0
- package/dist/admin/future/utils/files.mjs +19 -0
- package/dist/admin/future/utils/files.mjs.map +1 -0
- package/dist/admin/future/utils/getAssetIcon.js +28 -0
- package/dist/admin/future/utils/getAssetIcon.js.map +1 -0
- package/dist/admin/future/utils/getAssetIcon.mjs +26 -0
- package/dist/admin/future/utils/getAssetIcon.mjs.map +1 -0
- package/dist/admin/package.json.js +7 -6
- package/dist/admin/package.json.js.map +1 -1
- package/dist/admin/package.json.mjs +7 -6
- package/dist/admin/package.json.mjs.map +1 -1
- package/dist/admin/src/future/enums.d.ts +6 -0
- package/dist/admin/src/future/pages/Assets/AssetsPage.d.ts +1 -0
- package/dist/admin/src/future/pages/Assets/components/AssetsGrid.d.ts +6 -0
- package/dist/admin/src/future/pages/Assets/components/AssetsTable.d.ts +6 -0
- package/dist/admin/src/future/pages/Assets/components/DropZone/DropZoneWithOverlay.d.ts +4 -0
- package/dist/admin/src/future/pages/Assets/components/DropZone/UploadDropZoneContext.d.ts +11 -0
- package/dist/admin/src/future/pages/Assets/constants.d.ts +17 -0
- package/dist/admin/src/future/services/assets.d.ts +13 -0
- package/dist/admin/src/future/utils/files.d.ts +3 -0
- package/dist/admin/src/future/utils/getAssetIcon.d.ts +12 -0
- package/dist/admin/translations/en.json.js +3 -0
- package/dist/admin/translations/en.json.js.map +1 -1
- package/dist/admin/translations/en.json.mjs +3 -0
- package/dist/admin/translations/en.json.mjs.map +1 -1
- package/package.json +7 -6
- package/dist/admin/future/pages/MediaLibraryPage.js +0 -119
- package/dist/admin/future/pages/MediaLibraryPage.js.map +0 -1
- package/dist/admin/future/pages/MediaLibraryPage.mjs +0 -98
- package/dist/admin/future/pages/MediaLibraryPage.mjs.map +0 -1
- package/dist/admin/src/future/pages/MediaLibraryPage.d.ts +0 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var designSystem = require('@strapi/design-system');
|
|
5
|
+
var styledComponents = require('styled-components');
|
|
6
|
+
var UploadDropZoneContext = require('./UploadDropZoneContext.js');
|
|
7
|
+
|
|
8
|
+
const setOpacity = (hex, alpha)=>`${hex}${Math.floor(alpha * 255).toString(16).padStart(2, '0')}`;
|
|
9
|
+
const DropZoneOverlay = styledComponents.styled(designSystem.Box)`
|
|
10
|
+
position: absolute;
|
|
11
|
+
top: 0;
|
|
12
|
+
left: 0;
|
|
13
|
+
right: 0;
|
|
14
|
+
bottom: 0;
|
|
15
|
+
background: ${({ theme })=>setOpacity(theme.colors.primary200, 0.3)};
|
|
16
|
+
border: 1px solid ${({ theme })=>theme.colors.primary700};
|
|
17
|
+
border-radius: ${({ theme })=>theme.borderRadius};
|
|
18
|
+
z-index: 1;
|
|
19
|
+
pointer-events: none;
|
|
20
|
+
`;
|
|
21
|
+
const DropZoneWithOverlay = ({ children })=>{
|
|
22
|
+
const { isDragging } = UploadDropZoneContext.useUploadDropZone();
|
|
23
|
+
return /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Box, {
|
|
24
|
+
position: "relative",
|
|
25
|
+
children: [
|
|
26
|
+
isDragging && /*#__PURE__*/ jsxRuntime.jsx(DropZoneOverlay, {}),
|
|
27
|
+
children
|
|
28
|
+
]
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
exports.DropZoneWithOverlay = DropZoneWithOverlay;
|
|
33
|
+
//# sourceMappingURL=DropZoneWithOverlay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DropZoneWithOverlay.js","sources":["../../../../../../../admin/src/future/pages/Assets/components/DropZone/DropZoneWithOverlay.tsx"],"sourcesContent":["import { Box } from '@strapi/design-system';\nimport { styled } from 'styled-components';\n\nimport { useUploadDropZone } from './UploadDropZoneContext';\n\nconst setOpacity = (hex: string, alpha: number) =>\n `${hex}${Math.floor(alpha * 255)\n .toString(16)\n .padStart(2, '0')}`;\n\nconst DropZoneOverlay = styled(Box)`\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background: ${({ theme }) => setOpacity(theme.colors.primary200, 0.3)};\n border: 1px solid ${({ theme }) => theme.colors.primary700};\n border-radius: ${({ theme }) => theme.borderRadius};\n z-index: 1;\n pointer-events: none;\n`;\n\nconst DropZoneWithOverlay = ({ children }: { children: React.ReactNode }) => {\n const { isDragging } = useUploadDropZone();\n return (\n <Box position=\"relative\">\n {isDragging && <DropZoneOverlay />}\n {children}\n </Box>\n );\n};\n\nexport { DropZoneWithOverlay };\n"],"names":["setOpacity","hex","alpha","Math","floor","toString","padStart","DropZoneOverlay","styled","Box","theme","colors","primary200","primary700","borderRadius","DropZoneWithOverlay","children","isDragging","useUploadDropZone","_jsxs","position","_jsx"],"mappings":";;;;;;;AAKA,MAAMA,aAAa,CAACC,GAAAA,EAAaC,KAC/B,GAAA,CAAA,EAAGD,MAAME,IAAKC,CAAAA,KAAK,CAACF,KAAAA,GAAQ,KACzBG,QAAQ,CAAC,IACTC,QAAQ,CAAC,GAAG,GAAM,CAAA,CAAA,CAAA;AAEvB,MAAMC,eAAAA,GAAkBC,uBAAOC,CAAAA,gBAAAA,CAAI;;;;;;cAMrB,EAAE,CAAC,EAAEC,KAAK,EAAE,GAAKV,UAAWU,CAAAA,KAAAA,CAAMC,MAAM,CAACC,UAAU,EAAE,GAAK,CAAA,CAAA;oBACpD,EAAE,CAAC,EAAEF,KAAK,EAAE,GAAKA,KAAMC,CAAAA,MAAM,CAACE,UAAU,CAAC;AAC5C,iBAAA,EAAE,CAAC,EAAEH,KAAK,EAAE,GAAKA,KAAAA,CAAMI,YAAY,CAAC;;;AAGrD,CAAC;AAED,MAAMC,mBAAsB,GAAA,CAAC,EAAEC,QAAQ,EAAiC,GAAA;IACtE,MAAM,EAAEC,UAAU,EAAE,GAAGC,uCAAAA,EAAAA;AACvB,IAAA,qBACEC,eAACV,CAAAA,gBAAAA,EAAAA;QAAIW,QAAS,EAAA,UAAA;;AACXH,YAAAA,UAAAA,kBAAcI,cAACd,CAAAA,eAAAA,EAAAA,EAAAA,CAAAA;AACfS,YAAAA;;;AAGP;;;;"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { Box } from '@strapi/design-system';
|
|
3
|
+
import { styled } from 'styled-components';
|
|
4
|
+
import { useUploadDropZone } from './UploadDropZoneContext.mjs';
|
|
5
|
+
|
|
6
|
+
const setOpacity = (hex, alpha)=>`${hex}${Math.floor(alpha * 255).toString(16).padStart(2, '0')}`;
|
|
7
|
+
const DropZoneOverlay = styled(Box)`
|
|
8
|
+
position: absolute;
|
|
9
|
+
top: 0;
|
|
10
|
+
left: 0;
|
|
11
|
+
right: 0;
|
|
12
|
+
bottom: 0;
|
|
13
|
+
background: ${({ theme })=>setOpacity(theme.colors.primary200, 0.3)};
|
|
14
|
+
border: 1px solid ${({ theme })=>theme.colors.primary700};
|
|
15
|
+
border-radius: ${({ theme })=>theme.borderRadius};
|
|
16
|
+
z-index: 1;
|
|
17
|
+
pointer-events: none;
|
|
18
|
+
`;
|
|
19
|
+
const DropZoneWithOverlay = ({ children })=>{
|
|
20
|
+
const { isDragging } = useUploadDropZone();
|
|
21
|
+
return /*#__PURE__*/ jsxs(Box, {
|
|
22
|
+
position: "relative",
|
|
23
|
+
children: [
|
|
24
|
+
isDragging && /*#__PURE__*/ jsx(DropZoneOverlay, {}),
|
|
25
|
+
children
|
|
26
|
+
]
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { DropZoneWithOverlay };
|
|
31
|
+
//# sourceMappingURL=DropZoneWithOverlay.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DropZoneWithOverlay.mjs","sources":["../../../../../../../admin/src/future/pages/Assets/components/DropZone/DropZoneWithOverlay.tsx"],"sourcesContent":["import { Box } from '@strapi/design-system';\nimport { styled } from 'styled-components';\n\nimport { useUploadDropZone } from './UploadDropZoneContext';\n\nconst setOpacity = (hex: string, alpha: number) =>\n `${hex}${Math.floor(alpha * 255)\n .toString(16)\n .padStart(2, '0')}`;\n\nconst DropZoneOverlay = styled(Box)`\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background: ${({ theme }) => setOpacity(theme.colors.primary200, 0.3)};\n border: 1px solid ${({ theme }) => theme.colors.primary700};\n border-radius: ${({ theme }) => theme.borderRadius};\n z-index: 1;\n pointer-events: none;\n`;\n\nconst DropZoneWithOverlay = ({ children }: { children: React.ReactNode }) => {\n const { isDragging } = useUploadDropZone();\n return (\n <Box position=\"relative\">\n {isDragging && <DropZoneOverlay />}\n {children}\n </Box>\n );\n};\n\nexport { DropZoneWithOverlay };\n"],"names":["setOpacity","hex","alpha","Math","floor","toString","padStart","DropZoneOverlay","styled","Box","theme","colors","primary200","primary700","borderRadius","DropZoneWithOverlay","children","isDragging","useUploadDropZone","_jsxs","position","_jsx"],"mappings":";;;;;AAKA,MAAMA,aAAa,CAACC,GAAAA,EAAaC,KAC/B,GAAA,CAAA,EAAGD,MAAME,IAAKC,CAAAA,KAAK,CAACF,KAAAA,GAAQ,KACzBG,QAAQ,CAAC,IACTC,QAAQ,CAAC,GAAG,GAAM,CAAA,CAAA,CAAA;AAEvB,MAAMC,eAAAA,GAAkBC,MAAOC,CAAAA,GAAAA,CAAI;;;;;;cAMrB,EAAE,CAAC,EAAEC,KAAK,EAAE,GAAKV,UAAWU,CAAAA,KAAAA,CAAMC,MAAM,CAACC,UAAU,EAAE,GAAK,CAAA,CAAA;oBACpD,EAAE,CAAC,EAAEF,KAAK,EAAE,GAAKA,KAAMC,CAAAA,MAAM,CAACE,UAAU,CAAC;AAC5C,iBAAA,EAAE,CAAC,EAAEH,KAAK,EAAE,GAAKA,KAAAA,CAAMI,YAAY,CAAC;;;AAGrD,CAAC;AAED,MAAMC,mBAAsB,GAAA,CAAC,EAAEC,QAAQ,EAAiC,GAAA;IACtE,MAAM,EAAEC,UAAU,EAAE,GAAGC,iBAAAA,EAAAA;AACvB,IAAA,qBACEC,IAACV,CAAAA,GAAAA,EAAAA;QAAIW,QAAS,EAAA,UAAA;;AACXH,YAAAA,UAAAA,kBAAcI,GAACd,CAAAA,eAAAA,EAAAA,EAAAA,CAAAA;AACfS,YAAAA;;;AAGP;;;;"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var designSystem = require('@strapi/design-system');
|
|
6
|
+
var styledComponents = require('styled-components');
|
|
7
|
+
|
|
8
|
+
/* -------------------------------------------------------------------------------------------------
|
|
9
|
+
* Context
|
|
10
|
+
* -----------------------------------------------------------------------------------------------*/ const UploadDropZoneContext = /*#__PURE__*/ React.createContext(null);
|
|
11
|
+
/* -------------------------------------------------------------------------------------------------
|
|
12
|
+
* Components
|
|
13
|
+
* -----------------------------------------------------------------------------------------------*/ const DropZoneWrapper = styledComponents.styled(designSystem.Box)`
|
|
14
|
+
position: relative;
|
|
15
|
+
display: flex;
|
|
16
|
+
flex-direction: column;
|
|
17
|
+
min-height: 100%;
|
|
18
|
+
`;
|
|
19
|
+
const UploadDropZoneProvider = ({ children, onDrop })=>{
|
|
20
|
+
const [isDragging, setIsDragging] = React.useState(false);
|
|
21
|
+
const dragCounterRef = React.useRef(0);
|
|
22
|
+
const contextValue = {
|
|
23
|
+
isDragging
|
|
24
|
+
};
|
|
25
|
+
React.useEffect(()=>{
|
|
26
|
+
const handleDragEnd = ()=>{
|
|
27
|
+
setIsDragging(false);
|
|
28
|
+
dragCounterRef.current = 0;
|
|
29
|
+
};
|
|
30
|
+
// Handle drag leaving the entire document/window
|
|
31
|
+
const handleDocumentDragLeave = (e)=>{
|
|
32
|
+
// When relatedTarget is null, we're leaving the document entirely
|
|
33
|
+
if (!e.relatedTarget) {
|
|
34
|
+
setIsDragging(false);
|
|
35
|
+
dragCounterRef.current = 0;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
document.addEventListener('dragend', handleDragEnd);
|
|
39
|
+
document.addEventListener('dragleave', handleDocumentDragLeave);
|
|
40
|
+
return ()=>{
|
|
41
|
+
document.removeEventListener('dragend', handleDragEnd);
|
|
42
|
+
document.removeEventListener('dragleave', handleDocumentDragLeave);
|
|
43
|
+
};
|
|
44
|
+
}, []);
|
|
45
|
+
const handleDragEnter = React.useCallback((e)=>{
|
|
46
|
+
e.preventDefault();
|
|
47
|
+
e.stopPropagation();
|
|
48
|
+
dragCounterRef.current += 1;
|
|
49
|
+
if (e.dataTransfer.types.includes('Files')) {
|
|
50
|
+
setIsDragging(true);
|
|
51
|
+
}
|
|
52
|
+
}, []);
|
|
53
|
+
const handleDragLeave = React.useCallback((e)=>{
|
|
54
|
+
e.preventDefault();
|
|
55
|
+
e.stopPropagation();
|
|
56
|
+
dragCounterRef.current -= 1;
|
|
57
|
+
// Only set dragging to false if we've left the dropzone completely
|
|
58
|
+
// (counter reaches 0 or negative)
|
|
59
|
+
if (dragCounterRef.current <= 0) {
|
|
60
|
+
setIsDragging(false);
|
|
61
|
+
dragCounterRef.current = 0;
|
|
62
|
+
}
|
|
63
|
+
}, []);
|
|
64
|
+
const handleDragOver = React.useCallback((e)=>{
|
|
65
|
+
e.preventDefault();
|
|
66
|
+
e.stopPropagation();
|
|
67
|
+
e.dataTransfer.dropEffect = 'copy';
|
|
68
|
+
}, []);
|
|
69
|
+
const handleDrop = React.useCallback((e)=>{
|
|
70
|
+
e.preventDefault();
|
|
71
|
+
e.stopPropagation();
|
|
72
|
+
setIsDragging(false);
|
|
73
|
+
dragCounterRef.current = 0;
|
|
74
|
+
const { files } = e.dataTransfer;
|
|
75
|
+
if (files?.length && onDrop) {
|
|
76
|
+
onDrop(Array.from(files));
|
|
77
|
+
}
|
|
78
|
+
}, [
|
|
79
|
+
onDrop
|
|
80
|
+
]);
|
|
81
|
+
return /*#__PURE__*/ jsxRuntime.jsx(UploadDropZoneContext.Provider, {
|
|
82
|
+
value: contextValue,
|
|
83
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(DropZoneWrapper, {
|
|
84
|
+
"data-testid": "assets-dropzone",
|
|
85
|
+
onDragEnter: handleDragEnter,
|
|
86
|
+
onDragLeave: handleDragLeave,
|
|
87
|
+
onDragOver: handleDragOver,
|
|
88
|
+
onDrop: handleDrop,
|
|
89
|
+
children: children
|
|
90
|
+
})
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
/* -------------------------------------------------------------------------------------------------
|
|
94
|
+
* Hook
|
|
95
|
+
* -----------------------------------------------------------------------------------------------*/ const useUploadDropZone = ()=>{
|
|
96
|
+
const context = React.useContext(UploadDropZoneContext);
|
|
97
|
+
if (!context) {
|
|
98
|
+
throw new Error('useUploadDropZone must be used within UploadDropZone');
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
isDragging: context.isDragging
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
exports.UploadDropZoneProvider = UploadDropZoneProvider;
|
|
106
|
+
exports.useUploadDropZone = useUploadDropZone;
|
|
107
|
+
//# sourceMappingURL=UploadDropZoneContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UploadDropZoneContext.js","sources":["../../../../../../../admin/src/future/pages/Assets/components/DropZone/UploadDropZoneContext.tsx"],"sourcesContent":["import {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useRef,\n useState,\n type DragEvent,\n type ReactNode,\n} from 'react';\n\nimport { Box } from '@strapi/design-system';\nimport { styled } from 'styled-components';\n\n/* -------------------------------------------------------------------------------------------------\n * Types\n * -----------------------------------------------------------------------------------------------*/\n\ntype DropHandler = (files: File[]) => void | Promise<void>;\n\ninterface UploadDropZoneContextValue {\n isDragging: boolean;\n}\n\n/* -------------------------------------------------------------------------------------------------\n * Context\n * -----------------------------------------------------------------------------------------------*/\n\nconst UploadDropZoneContext = createContext<UploadDropZoneContextValue | null>(null);\n\n/* -------------------------------------------------------------------------------------------------\n * Components\n * -----------------------------------------------------------------------------------------------*/\n\nconst DropZoneWrapper = styled(Box)`\n position: relative;\n display: flex;\n flex-direction: column;\n min-height: 100%;\n`;\n\n/* -------------------------------------------------------------------------------------------------\n * Provider\n * -----------------------------------------------------------------------------------------------*/\n\ninterface UploadDropZoneProps {\n children: ReactNode;\n onDrop?: DropHandler;\n}\n\nexport const UploadDropZoneProvider = ({ children, onDrop }: UploadDropZoneProps) => {\n const [isDragging, setIsDragging] = useState(false);\n const dragCounterRef = useRef(0);\n\n const contextValue: UploadDropZoneContextValue = {\n isDragging,\n };\n\n useEffect(() => {\n const handleDragEnd = () => {\n setIsDragging(false);\n dragCounterRef.current = 0;\n };\n\n // Handle drag leaving the entire document/window\n const handleDocumentDragLeave = (e: globalThis.DragEvent) => {\n // When relatedTarget is null, we're leaving the document entirely\n if (!e.relatedTarget) {\n setIsDragging(false);\n dragCounterRef.current = 0;\n }\n };\n\n document.addEventListener('dragend', handleDragEnd);\n document.addEventListener('dragleave', handleDocumentDragLeave);\n\n return () => {\n document.removeEventListener('dragend', handleDragEnd);\n document.removeEventListener('dragleave', handleDocumentDragLeave);\n };\n }, []);\n\n const handleDragEnter = useCallback((e: DragEvent<HTMLElement>) => {\n e.preventDefault();\n e.stopPropagation();\n\n dragCounterRef.current += 1;\n\n if (e.dataTransfer.types.includes('Files')) {\n setIsDragging(true);\n }\n }, []);\n\n const handleDragLeave = useCallback((e: DragEvent<HTMLElement>) => {\n e.preventDefault();\n e.stopPropagation();\n\n dragCounterRef.current -= 1;\n\n // Only set dragging to false if we've left the dropzone completely\n // (counter reaches 0 or negative)\n if (dragCounterRef.current <= 0) {\n setIsDragging(false);\n dragCounterRef.current = 0;\n }\n }, []);\n\n const handleDragOver = useCallback((e: DragEvent<HTMLElement>) => {\n e.preventDefault();\n e.stopPropagation();\n e.dataTransfer.dropEffect = 'copy';\n }, []);\n\n const handleDrop = useCallback(\n (e: DragEvent<HTMLElement>) => {\n e.preventDefault();\n e.stopPropagation();\n setIsDragging(false);\n dragCounterRef.current = 0;\n\n const { files } = e.dataTransfer;\n if (files?.length && onDrop) {\n onDrop(Array.from(files));\n }\n },\n [onDrop]\n );\n\n return (\n <UploadDropZoneContext.Provider value={contextValue}>\n <DropZoneWrapper\n data-testid=\"assets-dropzone\"\n onDragEnter={handleDragEnter}\n onDragLeave={handleDragLeave}\n onDragOver={handleDragOver}\n onDrop={handleDrop}\n >\n {children}\n </DropZoneWrapper>\n </UploadDropZoneContext.Provider>\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * Hook\n * -----------------------------------------------------------------------------------------------*/\n\nexport const useUploadDropZone = () => {\n const context = useContext(UploadDropZoneContext);\n\n if (!context) {\n throw new Error('useUploadDropZone must be used within UploadDropZone');\n }\n\n return {\n isDragging: context.isDragging,\n };\n};\n"],"names":["UploadDropZoneContext","createContext","DropZoneWrapper","styled","Box","UploadDropZoneProvider","children","onDrop","isDragging","setIsDragging","useState","dragCounterRef","useRef","contextValue","useEffect","handleDragEnd","current","handleDocumentDragLeave","e","relatedTarget","document","addEventListener","removeEventListener","handleDragEnter","useCallback","preventDefault","stopPropagation","dataTransfer","types","includes","handleDragLeave","handleDragOver","dropEffect","handleDrop","files","length","Array","from","_jsx","Provider","value","data-testid","onDragEnter","onDragLeave","onDragOver","useUploadDropZone","context","useContext","Error"],"mappings":";;;;;;;A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cAAA,CAACtC,sBAAsBuC,QAAQ,EAAA;QAACC,KAAO3B,EAAAA,YAAAA;AACrC,QAAA,QAAA,gBAAAyB,cAACpC,CAAAA,eAAAA,EAAAA;YACCuC,aAAY,EAAA,iBAAA;YACZC,WAAanB,EAAAA,eAAAA;YACboB,WAAab,EAAAA,eAAAA;YACbc,UAAYb,EAAAA,cAAAA;YACZxB,MAAQ0B,EAAAA,UAAAA;AAEP3B,YAAAA,QAAAA,EAAAA;;;AAIT;AAEA;;2GAIauC,iBAAoB,GAAA,IAAA;AAC/B,IAAA,MAAMC,UAAUC,gBAAW/C,CAAAA,qBAAAA,CAAAA;AAE3B,IAAA,IAAI,CAAC8C,OAAS,EAAA;AACZ,QAAA,MAAM,IAAIE,KAAM,CAAA,sDAAA,CAAA;AAClB;IAEA,OAAO;AACLxC,QAAAA,UAAAA,EAAYsC,QAAQtC;AACtB,KAAA;AACF;;;;;"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useState, useRef, useEffect, useCallback, createContext, useContext } from 'react';
|
|
3
|
+
import { Box } from '@strapi/design-system';
|
|
4
|
+
import { styled } from 'styled-components';
|
|
5
|
+
|
|
6
|
+
/* -------------------------------------------------------------------------------------------------
|
|
7
|
+
* Context
|
|
8
|
+
* -----------------------------------------------------------------------------------------------*/ const UploadDropZoneContext = /*#__PURE__*/ createContext(null);
|
|
9
|
+
/* -------------------------------------------------------------------------------------------------
|
|
10
|
+
* Components
|
|
11
|
+
* -----------------------------------------------------------------------------------------------*/ const DropZoneWrapper = styled(Box)`
|
|
12
|
+
position: relative;
|
|
13
|
+
display: flex;
|
|
14
|
+
flex-direction: column;
|
|
15
|
+
min-height: 100%;
|
|
16
|
+
`;
|
|
17
|
+
const UploadDropZoneProvider = ({ children, onDrop })=>{
|
|
18
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
19
|
+
const dragCounterRef = useRef(0);
|
|
20
|
+
const contextValue = {
|
|
21
|
+
isDragging
|
|
22
|
+
};
|
|
23
|
+
useEffect(()=>{
|
|
24
|
+
const handleDragEnd = ()=>{
|
|
25
|
+
setIsDragging(false);
|
|
26
|
+
dragCounterRef.current = 0;
|
|
27
|
+
};
|
|
28
|
+
// Handle drag leaving the entire document/window
|
|
29
|
+
const handleDocumentDragLeave = (e)=>{
|
|
30
|
+
// When relatedTarget is null, we're leaving the document entirely
|
|
31
|
+
if (!e.relatedTarget) {
|
|
32
|
+
setIsDragging(false);
|
|
33
|
+
dragCounterRef.current = 0;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
document.addEventListener('dragend', handleDragEnd);
|
|
37
|
+
document.addEventListener('dragleave', handleDocumentDragLeave);
|
|
38
|
+
return ()=>{
|
|
39
|
+
document.removeEventListener('dragend', handleDragEnd);
|
|
40
|
+
document.removeEventListener('dragleave', handleDocumentDragLeave);
|
|
41
|
+
};
|
|
42
|
+
}, []);
|
|
43
|
+
const handleDragEnter = useCallback((e)=>{
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
e.stopPropagation();
|
|
46
|
+
dragCounterRef.current += 1;
|
|
47
|
+
if (e.dataTransfer.types.includes('Files')) {
|
|
48
|
+
setIsDragging(true);
|
|
49
|
+
}
|
|
50
|
+
}, []);
|
|
51
|
+
const handleDragLeave = useCallback((e)=>{
|
|
52
|
+
e.preventDefault();
|
|
53
|
+
e.stopPropagation();
|
|
54
|
+
dragCounterRef.current -= 1;
|
|
55
|
+
// Only set dragging to false if we've left the dropzone completely
|
|
56
|
+
// (counter reaches 0 or negative)
|
|
57
|
+
if (dragCounterRef.current <= 0) {
|
|
58
|
+
setIsDragging(false);
|
|
59
|
+
dragCounterRef.current = 0;
|
|
60
|
+
}
|
|
61
|
+
}, []);
|
|
62
|
+
const handleDragOver = useCallback((e)=>{
|
|
63
|
+
e.preventDefault();
|
|
64
|
+
e.stopPropagation();
|
|
65
|
+
e.dataTransfer.dropEffect = 'copy';
|
|
66
|
+
}, []);
|
|
67
|
+
const handleDrop = useCallback((e)=>{
|
|
68
|
+
e.preventDefault();
|
|
69
|
+
e.stopPropagation();
|
|
70
|
+
setIsDragging(false);
|
|
71
|
+
dragCounterRef.current = 0;
|
|
72
|
+
const { files } = e.dataTransfer;
|
|
73
|
+
if (files?.length && onDrop) {
|
|
74
|
+
onDrop(Array.from(files));
|
|
75
|
+
}
|
|
76
|
+
}, [
|
|
77
|
+
onDrop
|
|
78
|
+
]);
|
|
79
|
+
return /*#__PURE__*/ jsx(UploadDropZoneContext.Provider, {
|
|
80
|
+
value: contextValue,
|
|
81
|
+
children: /*#__PURE__*/ jsx(DropZoneWrapper, {
|
|
82
|
+
"data-testid": "assets-dropzone",
|
|
83
|
+
onDragEnter: handleDragEnter,
|
|
84
|
+
onDragLeave: handleDragLeave,
|
|
85
|
+
onDragOver: handleDragOver,
|
|
86
|
+
onDrop: handleDrop,
|
|
87
|
+
children: children
|
|
88
|
+
})
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
/* -------------------------------------------------------------------------------------------------
|
|
92
|
+
* Hook
|
|
93
|
+
* -----------------------------------------------------------------------------------------------*/ const useUploadDropZone = ()=>{
|
|
94
|
+
const context = useContext(UploadDropZoneContext);
|
|
95
|
+
if (!context) {
|
|
96
|
+
throw new Error('useUploadDropZone must be used within UploadDropZone');
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
isDragging: context.isDragging
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export { UploadDropZoneProvider, useUploadDropZone };
|
|
104
|
+
//# sourceMappingURL=UploadDropZoneContext.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UploadDropZoneContext.mjs","sources":["../../../../../../../admin/src/future/pages/Assets/components/DropZone/UploadDropZoneContext.tsx"],"sourcesContent":["import {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useRef,\n useState,\n type DragEvent,\n type ReactNode,\n} from 'react';\n\nimport { Box } from '@strapi/design-system';\nimport { styled } from 'styled-components';\n\n/* -------------------------------------------------------------------------------------------------\n * Types\n * -----------------------------------------------------------------------------------------------*/\n\ntype DropHandler = (files: File[]) => void | Promise<void>;\n\ninterface UploadDropZoneContextValue {\n isDragging: boolean;\n}\n\n/* -------------------------------------------------------------------------------------------------\n * Context\n * -----------------------------------------------------------------------------------------------*/\n\nconst UploadDropZoneContext = createContext<UploadDropZoneContextValue | null>(null);\n\n/* -------------------------------------------------------------------------------------------------\n * Components\n * -----------------------------------------------------------------------------------------------*/\n\nconst DropZoneWrapper = styled(Box)`\n position: relative;\n display: flex;\n flex-direction: column;\n min-height: 100%;\n`;\n\n/* -------------------------------------------------------------------------------------------------\n * Provider\n * -----------------------------------------------------------------------------------------------*/\n\ninterface UploadDropZoneProps {\n children: ReactNode;\n onDrop?: DropHandler;\n}\n\nexport const UploadDropZoneProvider = ({ children, onDrop }: UploadDropZoneProps) => {\n const [isDragging, setIsDragging] = useState(false);\n const dragCounterRef = useRef(0);\n\n const contextValue: UploadDropZoneContextValue = {\n isDragging,\n };\n\n useEffect(() => {\n const handleDragEnd = () => {\n setIsDragging(false);\n dragCounterRef.current = 0;\n };\n\n // Handle drag leaving the entire document/window\n const handleDocumentDragLeave = (e: globalThis.DragEvent) => {\n // When relatedTarget is null, we're leaving the document entirely\n if (!e.relatedTarget) {\n setIsDragging(false);\n dragCounterRef.current = 0;\n }\n };\n\n document.addEventListener('dragend', handleDragEnd);\n document.addEventListener('dragleave', handleDocumentDragLeave);\n\n return () => {\n document.removeEventListener('dragend', handleDragEnd);\n document.removeEventListener('dragleave', handleDocumentDragLeave);\n };\n }, []);\n\n const handleDragEnter = useCallback((e: DragEvent<HTMLElement>) => {\n e.preventDefault();\n e.stopPropagation();\n\n dragCounterRef.current += 1;\n\n if (e.dataTransfer.types.includes('Files')) {\n setIsDragging(true);\n }\n }, []);\n\n const handleDragLeave = useCallback((e: DragEvent<HTMLElement>) => {\n e.preventDefault();\n e.stopPropagation();\n\n dragCounterRef.current -= 1;\n\n // Only set dragging to false if we've left the dropzone completely\n // (counter reaches 0 or negative)\n if (dragCounterRef.current <= 0) {\n setIsDragging(false);\n dragCounterRef.current = 0;\n }\n }, []);\n\n const handleDragOver = useCallback((e: DragEvent<HTMLElement>) => {\n e.preventDefault();\n e.stopPropagation();\n e.dataTransfer.dropEffect = 'copy';\n }, []);\n\n const handleDrop = useCallback(\n (e: DragEvent<HTMLElement>) => {\n e.preventDefault();\n e.stopPropagation();\n setIsDragging(false);\n dragCounterRef.current = 0;\n\n const { files } = e.dataTransfer;\n if (files?.length && onDrop) {\n onDrop(Array.from(files));\n }\n },\n [onDrop]\n );\n\n return (\n <UploadDropZoneContext.Provider value={contextValue}>\n <DropZoneWrapper\n data-testid=\"assets-dropzone\"\n onDragEnter={handleDragEnter}\n onDragLeave={handleDragLeave}\n onDragOver={handleDragOver}\n onDrop={handleDrop}\n >\n {children}\n </DropZoneWrapper>\n </UploadDropZoneContext.Provider>\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * Hook\n * -----------------------------------------------------------------------------------------------*/\n\nexport const useUploadDropZone = () => {\n const context = useContext(UploadDropZoneContext);\n\n if (!context) {\n throw new Error('useUploadDropZone must be used within UploadDropZone');\n }\n\n return {\n isDragging: context.isDragging,\n };\n};\n"],"names":["UploadDropZoneContext","createContext","DropZoneWrapper","styled","Box","UploadDropZoneProvider","children","onDrop","isDragging","setIsDragging","useState","dragCounterRef","useRef","contextValue","useEffect","handleDragEnd","current","handleDocumentDragLeave","e","relatedTarget","document","addEventListener","removeEventListener","handleDragEnter","useCallback","preventDefault","stopPropagation","dataTransfer","types","includes","handleDragLeave","handleDragOver","dropEffect","handleDrop","files","length","Array","from","_jsx","Provider","value","data-testid","onDragEnter","onDragLeave","onDragOver","useUploadDropZone","context","useContext","Error"],"mappings":";;;;;AAwBA;;qGAIA,MAAMA,sCAAwBC,aAAiD,CAAA,IAAA,CAAA;AAE/E;;AAEkG,qGAElG,MAAMC,eAAA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,CAAAA,eAAAA,EAAAA;YACCuC,aAAY,EAAA,iBAAA;YACZC,WAAanB,EAAAA,eAAAA;YACboB,WAAab,EAAAA,eAAAA;YACbc,UAAYb,EAAAA,cAAAA;YACZxB,MAAQ0B,EAAAA,UAAAA;AAEP3B,YAAAA,QAAAA,EAAAA;;;AAIT;AAEA;;2GAIauC,iBAAoB,GAAA,IAAA;AAC/B,IAAA,MAAMC,UAAUC,UAAW/C,CAAAA,qBAAAA,CAAAA;AAE3B,IAAA,IAAI,CAAC8C,OAAS,EAAA;AACZ,QAAA,MAAM,IAAIE,KAAM,CAAA,sDAAA,CAAA;AAClB;IAEA,OAAO;AACLxC,QAAAA,UAAAA,EAAYsC,QAAQtC;AACtB,KAAA;AACF;;;;"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var translations = require('../../utils/translations.js');
|
|
4
|
+
|
|
5
|
+
const localStorageKeys = {
|
|
6
|
+
view: `STRAPI_UPLOAD_LIBRARY_VIEW`
|
|
7
|
+
};
|
|
8
|
+
const viewOptions = {
|
|
9
|
+
GRID: 0,
|
|
10
|
+
TABLE: 1
|
|
11
|
+
};
|
|
12
|
+
const TABLE_HEADERS = [
|
|
13
|
+
{
|
|
14
|
+
name: 'name',
|
|
15
|
+
label: {
|
|
16
|
+
id: translations.getTranslationKey('list.table.header.name'),
|
|
17
|
+
defaultMessage: 'name'
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: 'createdAt',
|
|
22
|
+
label: {
|
|
23
|
+
id: translations.getTranslationKey('list.table.header.creationDate'),
|
|
24
|
+
defaultMessage: 'creation date'
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: 'updatedAt',
|
|
29
|
+
label: {
|
|
30
|
+
id: translations.getTranslationKey('list.table.header.lastModified'),
|
|
31
|
+
defaultMessage: 'last modified'
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'size',
|
|
36
|
+
label: {
|
|
37
|
+
id: translations.getTranslationKey('list.table.header.size'),
|
|
38
|
+
defaultMessage: 'size'
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: 'actions',
|
|
43
|
+
label: {
|
|
44
|
+
id: translations.getTranslationKey('list.table.header.actions'),
|
|
45
|
+
defaultMessage: 'actions'
|
|
46
|
+
},
|
|
47
|
+
isVisuallyHidden: true
|
|
48
|
+
}
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
exports.TABLE_HEADERS = TABLE_HEADERS;
|
|
52
|
+
exports.localStorageKeys = localStorageKeys;
|
|
53
|
+
exports.viewOptions = viewOptions;
|
|
54
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../../../../admin/src/future/pages/Assets/constants.ts"],"sourcesContent":["import { getTranslationKey } from '../../utils/translations';\n\nexport const localStorageKeys = {\n view: `STRAPI_UPLOAD_LIBRARY_VIEW`,\n};\n\nexport const viewOptions = {\n GRID: 0,\n TABLE: 1,\n};\n\ninterface TableHeader {\n name: string;\n label: { id: string; defaultMessage: string };\n isVisuallyHidden?: boolean;\n}\n\nexport const TABLE_HEADERS: TableHeader[] = [\n {\n name: 'name',\n label: { id: getTranslationKey('list.table.header.name'), defaultMessage: 'name' },\n },\n {\n name: 'createdAt',\n label: {\n id: getTranslationKey('list.table.header.creationDate'),\n defaultMessage: 'creation date',\n },\n },\n {\n name: 'updatedAt',\n label: {\n id: getTranslationKey('list.table.header.lastModified'),\n defaultMessage: 'last modified',\n },\n },\n {\n name: 'size',\n label: { id: getTranslationKey('list.table.header.size'), defaultMessage: 'size' },\n },\n {\n name: 'actions',\n label: { id: getTranslationKey('list.table.header.actions'), defaultMessage: 'actions' },\n isVisuallyHidden: true,\n },\n];\n"],"names":["localStorageKeys","view","viewOptions","GRID","TABLE","TABLE_HEADERS","name","label","id","getTranslationKey","defaultMessage","isVisuallyHidden"],"mappings":";;;;MAEaA,gBAAmB,GAAA;IAC9BC,IAAM,EAAA,CAAC,0BAA0B;AACnC;MAEaC,WAAc,GAAA;IACzBC,IAAM,EAAA,CAAA;IACNC,KAAO,EAAA;AACT;MAQaC,aAA+B,GAAA;AAC1C,IAAA;QACEC,IAAM,EAAA,MAAA;QACNC,KAAO,EAAA;AAAEC,YAAAA,EAAAA,EAAIC,8BAAkB,CAAA,wBAAA,CAAA;YAA2BC,cAAgB,EAAA;AAAO;AACnF,KAAA;AACA,IAAA;QACEJ,IAAM,EAAA,WAAA;QACNC,KAAO,EAAA;AACLC,YAAAA,EAAAA,EAAIC,8BAAkB,CAAA,gCAAA,CAAA;YACtBC,cAAgB,EAAA;AAClB;AACF,KAAA;AACA,IAAA;QACEJ,IAAM,EAAA,WAAA;QACNC,KAAO,EAAA;AACLC,YAAAA,EAAAA,EAAIC,8BAAkB,CAAA,gCAAA,CAAA;YACtBC,cAAgB,EAAA;AAClB;AACF,KAAA;AACA,IAAA;QACEJ,IAAM,EAAA,MAAA;QACNC,KAAO,EAAA;AAAEC,YAAAA,EAAAA,EAAIC,8BAAkB,CAAA,wBAAA,CAAA;YAA2BC,cAAgB,EAAA;AAAO;AACnF,KAAA;AACA,IAAA;QACEJ,IAAM,EAAA,SAAA;QACNC,KAAO,EAAA;AAAEC,YAAAA,EAAAA,EAAIC,8BAAkB,CAAA,2BAAA,CAAA;YAA8BC,cAAgB,EAAA;AAAU,SAAA;QACvFC,gBAAkB,EAAA;AACpB;;;;;;;"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { getTranslationKey } from '../../utils/translations.mjs';
|
|
2
|
+
|
|
3
|
+
const localStorageKeys = {
|
|
4
|
+
view: `STRAPI_UPLOAD_LIBRARY_VIEW`
|
|
5
|
+
};
|
|
6
|
+
const viewOptions = {
|
|
7
|
+
GRID: 0,
|
|
8
|
+
TABLE: 1
|
|
9
|
+
};
|
|
10
|
+
const TABLE_HEADERS = [
|
|
11
|
+
{
|
|
12
|
+
name: 'name',
|
|
13
|
+
label: {
|
|
14
|
+
id: getTranslationKey('list.table.header.name'),
|
|
15
|
+
defaultMessage: 'name'
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: 'createdAt',
|
|
20
|
+
label: {
|
|
21
|
+
id: getTranslationKey('list.table.header.creationDate'),
|
|
22
|
+
defaultMessage: 'creation date'
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: 'updatedAt',
|
|
27
|
+
label: {
|
|
28
|
+
id: getTranslationKey('list.table.header.lastModified'),
|
|
29
|
+
defaultMessage: 'last modified'
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: 'size',
|
|
34
|
+
label: {
|
|
35
|
+
id: getTranslationKey('list.table.header.size'),
|
|
36
|
+
defaultMessage: 'size'
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'actions',
|
|
41
|
+
label: {
|
|
42
|
+
id: getTranslationKey('list.table.header.actions'),
|
|
43
|
+
defaultMessage: 'actions'
|
|
44
|
+
},
|
|
45
|
+
isVisuallyHidden: true
|
|
46
|
+
}
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
export { TABLE_HEADERS, localStorageKeys, viewOptions };
|
|
50
|
+
//# sourceMappingURL=constants.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.mjs","sources":["../../../../../admin/src/future/pages/Assets/constants.ts"],"sourcesContent":["import { getTranslationKey } from '../../utils/translations';\n\nexport const localStorageKeys = {\n view: `STRAPI_UPLOAD_LIBRARY_VIEW`,\n};\n\nexport const viewOptions = {\n GRID: 0,\n TABLE: 1,\n};\n\ninterface TableHeader {\n name: string;\n label: { id: string; defaultMessage: string };\n isVisuallyHidden?: boolean;\n}\n\nexport const TABLE_HEADERS: TableHeader[] = [\n {\n name: 'name',\n label: { id: getTranslationKey('list.table.header.name'), defaultMessage: 'name' },\n },\n {\n name: 'createdAt',\n label: {\n id: getTranslationKey('list.table.header.creationDate'),\n defaultMessage: 'creation date',\n },\n },\n {\n name: 'updatedAt',\n label: {\n id: getTranslationKey('list.table.header.lastModified'),\n defaultMessage: 'last modified',\n },\n },\n {\n name: 'size',\n label: { id: getTranslationKey('list.table.header.size'), defaultMessage: 'size' },\n },\n {\n name: 'actions',\n label: { id: getTranslationKey('list.table.header.actions'), defaultMessage: 'actions' },\n isVisuallyHidden: true,\n },\n];\n"],"names":["localStorageKeys","view","viewOptions","GRID","TABLE","TABLE_HEADERS","name","label","id","getTranslationKey","defaultMessage","isVisuallyHidden"],"mappings":";;MAEaA,gBAAmB,GAAA;IAC9BC,IAAM,EAAA,CAAC,0BAA0B;AACnC;MAEaC,WAAc,GAAA;IACzBC,IAAM,EAAA,CAAA;IACNC,KAAO,EAAA;AACT;MAQaC,aAA+B,GAAA;AAC1C,IAAA;QACEC,IAAM,EAAA,MAAA;QACNC,KAAO,EAAA;AAAEC,YAAAA,EAAAA,EAAIC,iBAAkB,CAAA,wBAAA,CAAA;YAA2BC,cAAgB,EAAA;AAAO;AACnF,KAAA;AACA,IAAA;QACEJ,IAAM,EAAA,WAAA;QACNC,KAAO,EAAA;AACLC,YAAAA,EAAAA,EAAIC,iBAAkB,CAAA,gCAAA,CAAA;YACtBC,cAAgB,EAAA;AAClB;AACF,KAAA;AACA,IAAA;QACEJ,IAAM,EAAA,WAAA;QACNC,KAAO,EAAA;AACLC,YAAAA,EAAAA,EAAIC,iBAAkB,CAAA,gCAAA,CAAA;YACtBC,cAAgB,EAAA;AAClB;AACF,KAAA;AACA,IAAA;QACEJ,IAAM,EAAA,MAAA;QACNC,KAAO,EAAA;AAAEC,YAAAA,EAAAA,EAAIC,iBAAkB,CAAA,wBAAA,CAAA;YAA2BC,cAAgB,EAAA;AAAO;AACnF,KAAA;AACA,IAAA;QACEJ,IAAM,EAAA,SAAA;QACNC,KAAO,EAAA;AAAEC,YAAAA,EAAAA,EAAIC,iBAAkB,CAAA,2BAAA,CAAA;YAA8BC,cAAgB,EAAA;AAAU,SAAA;QACvFC,gBAAkB,EAAA;AACpB;;;;;"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var api = require('./api.js');
|
|
4
|
+
|
|
5
|
+
const assetsApi = api.uploadApi.injectEndpoints({
|
|
6
|
+
endpoints: (builder)=>({
|
|
7
|
+
getAssets: builder.query({
|
|
8
|
+
query: (params = {})=>({
|
|
9
|
+
url: '/upload/files',
|
|
10
|
+
method: 'GET',
|
|
11
|
+
config: {
|
|
12
|
+
params
|
|
13
|
+
}
|
|
14
|
+
}),
|
|
15
|
+
transformResponse: (response)=>response,
|
|
16
|
+
providesTags: (result)=>result ? [
|
|
17
|
+
...result.results.map(({ id })=>({
|
|
18
|
+
type: 'Asset',
|
|
19
|
+
id
|
|
20
|
+
})),
|
|
21
|
+
{
|
|
22
|
+
type: 'Asset',
|
|
23
|
+
id: 'LIST'
|
|
24
|
+
}
|
|
25
|
+
] : [
|
|
26
|
+
{
|
|
27
|
+
type: 'Asset',
|
|
28
|
+
id: 'LIST'
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
});
|
|
34
|
+
const { useGetAssetsQuery } = assetsApi;
|
|
35
|
+
|
|
36
|
+
exports.useGetAssetsQuery = useGetAssetsQuery;
|
|
37
|
+
//# sourceMappingURL=assets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets.js","sources":["../../../../admin/src/future/services/assets.ts"],"sourcesContent":["import { uploadApi } from './api';\n\nimport type { GetFiles, File, Pagination } from '../../../../shared/contracts/files';\n\ninterface GetAssetsParams {\n page?: number;\n pageSize?: number;\n folder?: number | null;\n sort?: string;\n}\n\ninterface GetAssetsResponse {\n results: File[];\n pagination: Pagination;\n}\n\nconst assetsApi = uploadApi.injectEndpoints({\n endpoints: (builder) => ({\n getAssets: builder.query<GetAssetsResponse, GetAssetsParams | void>({\n query: (params = {}) => ({\n url: '/upload/files',\n method: 'GET',\n config: { params },\n }),\n transformResponse: (response: GetFiles.Response['data']) => response,\n providesTags: (result) =>\n result\n ? [\n ...result.results.map(({ id }) => ({ type: 'Asset' as const, id })),\n { type: 'Asset', id: 'LIST' },\n ]\n : [{ type: 'Asset', id: 'LIST' }],\n }),\n }),\n});\n\nexport const { useGetAssetsQuery } = assetsApi;\n"],"names":["assetsApi","uploadApi","injectEndpoints","endpoints","builder","getAssets","query","params","url","method","config","transformResponse","response","providesTags","result","results","map","id","type","useGetAssetsQuery"],"mappings":";;;;AAgBA,MAAMA,SAAAA,GAAYC,aAAUC,CAAAA,eAAe,CAAC;IAC1CC,SAAW,EAAA,CAACC,WAAa;YACvBC,SAAWD,EAAAA,OAAAA,CAAQE,KAAK,CAA4C;AAClEA,gBAAAA,KAAAA,EAAO,CAACC,MAAAA,GAAS,EAAE,IAAM;wBACvBC,GAAK,EAAA,eAAA;wBACLC,MAAQ,EAAA,KAAA;wBACRC,MAAQ,EAAA;AAAEH,4BAAAA;AAAO;qBACnB,CAAA;AACAI,gBAAAA,iBAAAA,EAAmB,CAACC,QAAwCA,GAAAA,QAAAA;gBAC5DC,YAAc,EAAA,CAACC,SACbA,MACI,GAAA;2BACKA,MAAOC,CAAAA,OAAO,CAACC,GAAG,CAAC,CAAC,EAAEC,EAAE,EAAE,IAAM;gCAAEC,IAAM,EAAA,OAAA;AAAkBD,gCAAAA;6BAAG,CAAA,CAAA;AAChE,wBAAA;4BAAEC,IAAM,EAAA,OAAA;4BAASD,EAAI,EAAA;AAAO;qBAC7B,GACD;AAAC,wBAAA;4BAAEC,IAAM,EAAA,OAAA;4BAASD,EAAI,EAAA;AAAO;AAAE;AACvC,aAAA;SACF;AACF,CAAA,CAAA;AAEa,MAAA,EAAEE,iBAAiB,EAAE,GAAGnB;;;;"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { uploadApi } from './api.mjs';
|
|
2
|
+
|
|
3
|
+
const assetsApi = uploadApi.injectEndpoints({
|
|
4
|
+
endpoints: (builder)=>({
|
|
5
|
+
getAssets: builder.query({
|
|
6
|
+
query: (params = {})=>({
|
|
7
|
+
url: '/upload/files',
|
|
8
|
+
method: 'GET',
|
|
9
|
+
config: {
|
|
10
|
+
params
|
|
11
|
+
}
|
|
12
|
+
}),
|
|
13
|
+
transformResponse: (response)=>response,
|
|
14
|
+
providesTags: (result)=>result ? [
|
|
15
|
+
...result.results.map(({ id })=>({
|
|
16
|
+
type: 'Asset',
|
|
17
|
+
id
|
|
18
|
+
})),
|
|
19
|
+
{
|
|
20
|
+
type: 'Asset',
|
|
21
|
+
id: 'LIST'
|
|
22
|
+
}
|
|
23
|
+
] : [
|
|
24
|
+
{
|
|
25
|
+
type: 'Asset',
|
|
26
|
+
id: 'LIST'
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
});
|
|
32
|
+
const { useGetAssetsQuery } = assetsApi;
|
|
33
|
+
|
|
34
|
+
export { useGetAssetsQuery };
|
|
35
|
+
//# sourceMappingURL=assets.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets.mjs","sources":["../../../../admin/src/future/services/assets.ts"],"sourcesContent":["import { uploadApi } from './api';\n\nimport type { GetFiles, File, Pagination } from '../../../../shared/contracts/files';\n\ninterface GetAssetsParams {\n page?: number;\n pageSize?: number;\n folder?: number | null;\n sort?: string;\n}\n\ninterface GetAssetsResponse {\n results: File[];\n pagination: Pagination;\n}\n\nconst assetsApi = uploadApi.injectEndpoints({\n endpoints: (builder) => ({\n getAssets: builder.query<GetAssetsResponse, GetAssetsParams | void>({\n query: (params = {}) => ({\n url: '/upload/files',\n method: 'GET',\n config: { params },\n }),\n transformResponse: (response: GetFiles.Response['data']) => response,\n providesTags: (result) =>\n result\n ? [\n ...result.results.map(({ id }) => ({ type: 'Asset' as const, id })),\n { type: 'Asset', id: 'LIST' },\n ]\n : [{ type: 'Asset', id: 'LIST' }],\n }),\n }),\n});\n\nexport const { useGetAssetsQuery } = assetsApi;\n"],"names":["assetsApi","uploadApi","injectEndpoints","endpoints","builder","getAssets","query","params","url","method","config","transformResponse","response","providesTags","result","results","map","id","type","useGetAssetsQuery"],"mappings":";;AAgBA,MAAMA,SAAAA,GAAYC,SAAUC,CAAAA,eAAe,CAAC;IAC1CC,SAAW,EAAA,CAACC,WAAa;YACvBC,SAAWD,EAAAA,OAAAA,CAAQE,KAAK,CAA4C;AAClEA,gBAAAA,KAAAA,EAAO,CAACC,MAAAA,GAAS,EAAE,IAAM;wBACvBC,GAAK,EAAA,eAAA;wBACLC,MAAQ,EAAA,KAAA;wBACRC,MAAQ,EAAA;AAAEH,4BAAAA;AAAO;qBACnB,CAAA;AACAI,gBAAAA,iBAAAA,EAAmB,CAACC,QAAwCA,GAAAA,QAAAA;gBAC5DC,YAAc,EAAA,CAACC,SACbA,MACI,GAAA;2BACKA,MAAOC,CAAAA,OAAO,CAACC,GAAG,CAAC,CAAC,EAAEC,EAAE,EAAE,IAAM;gCAAEC,IAAM,EAAA,OAAA;AAAkBD,gCAAAA;6BAAG,CAAA,CAAA;AAChE,wBAAA;4BAAEC,IAAM,EAAA,OAAA;4BAASD,EAAI,EAAA;AAAO;qBAC7B,GACD;AAAC,wBAAA;4BAAEC,IAAM,EAAA,OAAA;4BAASD,EAAI,EAAA;AAAO;AAAE;AACvC,aAAA;SACF;AACF,CAAA,CAAA;AAEa,MAAA,EAAEE,iBAAiB,EAAE,GAAGnB;;;;"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var byteSize = require('byte-size');
|
|
4
|
+
|
|
5
|
+
function formatBytes(receivedBytes, decimals = 0) {
|
|
6
|
+
const realBytes = typeof receivedBytes === 'string' ? Number(receivedBytes) : receivedBytes;
|
|
7
|
+
const { value, unit } = byteSize(realBytes * 1000, {
|
|
8
|
+
precision: decimals
|
|
9
|
+
});
|
|
10
|
+
if (!unit) {
|
|
11
|
+
return '0B';
|
|
12
|
+
}
|
|
13
|
+
return `${value}${unit.toUpperCase()}`;
|
|
14
|
+
}
|
|
15
|
+
const getFileExtension = (ext)=>ext && ext[0] === '.' ? ext.substring(1) : ext;
|
|
16
|
+
const prefixFileUrlWithBackendUrl = (fileURL)=>{
|
|
17
|
+
return !!fileURL && fileURL.startsWith('/') ? `${window.strapi.backendURL}${fileURL}` : fileURL;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
exports.formatBytes = formatBytes;
|
|
21
|
+
exports.getFileExtension = getFileExtension;
|
|
22
|
+
exports.prefixFileUrlWithBackendUrl = prefixFileUrlWithBackendUrl;
|
|
23
|
+
//# sourceMappingURL=files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.js","sources":["../../../../admin/src/future/utils/files.ts"],"sourcesContent":["import byteSize from 'byte-size';\n\nexport function formatBytes(receivedBytes: number | string, decimals = 0) {\n const realBytes = typeof receivedBytes === 'string' ? Number(receivedBytes) : receivedBytes;\n const { value, unit } = byteSize(realBytes * 1000, { precision: decimals });\n\n if (!unit) {\n return '0B';\n }\n\n return `${value}${unit.toUpperCase()}`;\n}\n\nexport const getFileExtension = (ext?: string | null) =>\n ext && ext[0] === '.' ? ext.substring(1) : ext;\n\nexport const prefixFileUrlWithBackendUrl = (fileURL?: string) => {\n return !!fileURL && fileURL.startsWith('/') ? `${window.strapi.backendURL}${fileURL}` : fileURL;\n};\n"],"names":["formatBytes","receivedBytes","decimals","realBytes","Number","value","unit","byteSize","precision","toUpperCase","getFileExtension","ext","substring","prefixFileUrlWithBackendUrl","fileURL","startsWith","window","strapi","backendURL"],"mappings":";;;;AAEO,SAASA,WAAAA,CAAYC,aAA8B,EAAEC,WAAW,CAAC,EAAA;AACtE,IAAA,MAAMC,SAAY,GAAA,OAAOF,aAAkB,KAAA,QAAA,GAAWG,OAAOH,aAAiBA,CAAAA,GAAAA,aAAAA;IAC9E,MAAM,EAAEI,KAAK,EAAEC,IAAI,EAAE,GAAGC,QAAAA,CAASJ,YAAY,IAAM,EAAA;QAAEK,SAAWN,EAAAA;AAAS,KAAA,CAAA;AAEzE,IAAA,IAAI,CAACI,IAAM,EAAA;QACT,OAAO,IAAA;AACT;AAEA,IAAA,OAAO,CAAGD,EAAAA,KAAAA,CAAAA,EAAQC,IAAKG,CAAAA,WAAW,EAAI,CAAA,CAAA;AACxC;AAEaC,MAAAA,gBAAAA,GAAmB,CAACC,GAAAA,GAC/BA,OAAOA,GAAG,CAAC,CAAE,CAAA,KAAK,GAAMA,GAAAA,GAAAA,CAAIC,SAAS,CAAC,KAAKD;AAEtC,MAAME,8BAA8B,CAACC,OAAAA,GAAAA;AAC1C,IAAA,OAAO,CAAC,CAACA,OAAWA,IAAAA,OAAAA,CAAQC,UAAU,CAAC,GAAA,CAAA,GAAO,CAAGC,EAAAA,MAAAA,CAAOC,MAAM,CAACC,UAAU,CAAA,EAAGJ,SAAS,GAAGA,OAAAA;AAC1F;;;;;;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import byteSize from 'byte-size';
|
|
2
|
+
|
|
3
|
+
function formatBytes(receivedBytes, decimals = 0) {
|
|
4
|
+
const realBytes = typeof receivedBytes === 'string' ? Number(receivedBytes) : receivedBytes;
|
|
5
|
+
const { value, unit } = byteSize(realBytes * 1000, {
|
|
6
|
+
precision: decimals
|
|
7
|
+
});
|
|
8
|
+
if (!unit) {
|
|
9
|
+
return '0B';
|
|
10
|
+
}
|
|
11
|
+
return `${value}${unit.toUpperCase()}`;
|
|
12
|
+
}
|
|
13
|
+
const getFileExtension = (ext)=>ext && ext[0] === '.' ? ext.substring(1) : ext;
|
|
14
|
+
const prefixFileUrlWithBackendUrl = (fileURL)=>{
|
|
15
|
+
return !!fileURL && fileURL.startsWith('/') ? `${window.strapi.backendURL}${fileURL}` : fileURL;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { formatBytes, getFileExtension, prefixFileUrlWithBackendUrl };
|
|
19
|
+
//# sourceMappingURL=files.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.mjs","sources":["../../../../admin/src/future/utils/files.ts"],"sourcesContent":["import byteSize from 'byte-size';\n\nexport function formatBytes(receivedBytes: number | string, decimals = 0) {\n const realBytes = typeof receivedBytes === 'string' ? Number(receivedBytes) : receivedBytes;\n const { value, unit } = byteSize(realBytes * 1000, { precision: decimals });\n\n if (!unit) {\n return '0B';\n }\n\n return `${value}${unit.toUpperCase()}`;\n}\n\nexport const getFileExtension = (ext?: string | null) =>\n ext && ext[0] === '.' ? ext.substring(1) : ext;\n\nexport const prefixFileUrlWithBackendUrl = (fileURL?: string) => {\n return !!fileURL && fileURL.startsWith('/') ? `${window.strapi.backendURL}${fileURL}` : fileURL;\n};\n"],"names":["formatBytes","receivedBytes","decimals","realBytes","Number","value","unit","byteSize","precision","toUpperCase","getFileExtension","ext","substring","prefixFileUrlWithBackendUrl","fileURL","startsWith","window","strapi","backendURL"],"mappings":";;AAEO,SAASA,WAAAA,CAAYC,aAA8B,EAAEC,WAAW,CAAC,EAAA;AACtE,IAAA,MAAMC,SAAY,GAAA,OAAOF,aAAkB,KAAA,QAAA,GAAWG,OAAOH,aAAiBA,CAAAA,GAAAA,aAAAA;IAC9E,MAAM,EAAEI,KAAK,EAAEC,IAAI,EAAE,GAAGC,QAAAA,CAASJ,YAAY,IAAM,EAAA;QAAEK,SAAWN,EAAAA;AAAS,KAAA,CAAA;AAEzE,IAAA,IAAI,CAACI,IAAM,EAAA;QACT,OAAO,IAAA;AACT;AAEA,IAAA,OAAO,CAAGD,EAAAA,KAAAA,CAAAA,EAAQC,IAAKG,CAAAA,WAAW,EAAI,CAAA,CAAA;AACxC;AAEaC,MAAAA,gBAAAA,GAAmB,CAACC,GAAAA,GAC/BA,OAAOA,GAAG,CAAC,CAAE,CAAA,KAAK,GAAMA,GAAAA,GAAAA,CAAIC,SAAS,CAAC,KAAKD;AAEtC,MAAME,8BAA8B,CAACC,OAAAA,GAAAA;AAC1C,IAAA,OAAO,CAAC,CAACA,OAAWA,IAAAA,OAAAA,CAAQC,UAAU,CAAC,GAAA,CAAA,GAAO,CAAGC,EAAAA,MAAAA,CAAOC,MAAM,CAACC,UAAU,CAAA,EAAGJ,SAAS,GAAGA,OAAAA;AAC1F;;;;"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var icons = require('@strapi/icons');
|
|
4
|
+
var enums = require('../enums.js');
|
|
5
|
+
var files = require('./files.js');
|
|
6
|
+
|
|
7
|
+
const DOC_ICON_MAP = {
|
|
8
|
+
pdf: icons.FilePdf,
|
|
9
|
+
csv: icons.FileCsv,
|
|
10
|
+
xls: icons.FileXls,
|
|
11
|
+
zip: icons.FileZip
|
|
12
|
+
};
|
|
13
|
+
const getAssetIcon = (mime, ext)=>{
|
|
14
|
+
const fileExtension = files.getFileExtension(ext);
|
|
15
|
+
if (mime?.includes(enums.AssetType.Image)) {
|
|
16
|
+
return icons.Images;
|
|
17
|
+
}
|
|
18
|
+
if (mime?.includes(enums.AssetType.Video)) {
|
|
19
|
+
return icons.Monitor;
|
|
20
|
+
}
|
|
21
|
+
if (mime?.includes(enums.AssetType.Audio)) {
|
|
22
|
+
return icons.VolumeUp;
|
|
23
|
+
}
|
|
24
|
+
return fileExtension ? DOC_ICON_MAP[fileExtension] || icons.File : icons.File;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
exports.getAssetIcon = getAssetIcon;
|
|
28
|
+
//# sourceMappingURL=getAssetIcon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAssetIcon.js","sources":["../../../../admin/src/future/utils/getAssetIcon.ts"],"sourcesContent":["import { SVGProps } from 'react';\n\nimport {\n File as FileIcon,\n FileCsv,\n FilePdf,\n FileXls,\n FileZip,\n Monitor,\n VolumeUp,\n Images,\n} from '@strapi/icons';\nimport { DefaultTheme } from 'styled-components';\n\nimport { AssetType } from '../enums';\n\nimport { getFileExtension } from './files';\n\n// NOTE: IconProps interface is not exported from our design library package, so we need to redefine it here\ninterface IconProps extends Omit<SVGProps<SVGSVGElement>, 'fill' | 'stroke'> {\n /**\n * @default \"currentColor\"\n */\n fill?: keyof DefaultTheme['colors'] | string;\n stroke?: keyof DefaultTheme['colors'] | string;\n}\n\ntype IconComponent = React.FC<IconProps>;\n\nconst DOC_ICON_MAP: Record<string, IconComponent> = {\n pdf: FilePdf,\n csv: FileCsv,\n xls: FileXls,\n zip: FileZip,\n};\n\nexport const getAssetIcon = (mime: string | undefined, ext: string | undefined): IconComponent => {\n const fileExtension = getFileExtension(ext);\n\n if (mime?.includes(AssetType.Image)) {\n return Images;\n }\n\n if (mime?.includes(AssetType.Video)) {\n return Monitor;\n }\n\n if (mime?.includes(AssetType.Audio)) {\n return VolumeUp;\n }\n\n return fileExtension ? DOC_ICON_MAP[fileExtension] || FileIcon : FileIcon;\n};\n"],"names":["DOC_ICON_MAP","pdf","FilePdf","csv","FileCsv","xls","FileXls","zip","FileZip","getAssetIcon","mime","ext","fileExtension","getFileExtension","includes","AssetType","Image","Images","Video","Monitor","Audio","VolumeUp","FileIcon"],"mappings":";;;;;;AA6BA,MAAMA,YAA8C,GAAA;IAClDC,GAAKC,EAAAA,aAAAA;IACLC,GAAKC,EAAAA,aAAAA;IACLC,GAAKC,EAAAA,aAAAA;IACLC,GAAKC,EAAAA;AACP,CAAA;AAEO,MAAMC,YAAe,GAAA,CAACC,IAA0BC,EAAAA,GAAAA,GAAAA;AACrD,IAAA,MAAMC,gBAAgBC,sBAAiBF,CAAAA,GAAAA,CAAAA;AAEvC,IAAA,IAAID,IAAMI,EAAAA,QAAAA,CAASC,eAAUC,CAAAA,KAAK,CAAG,EAAA;QACnC,OAAOC,YAAAA;AACT;AAEA,IAAA,IAAIP,IAAMI,EAAAA,QAAAA,CAASC,eAAUG,CAAAA,KAAK,CAAG,EAAA;QACnC,OAAOC,aAAAA;AACT;AAEA,IAAA,IAAIT,IAAMI,EAAAA,QAAAA,CAASC,eAAUK,CAAAA,KAAK,CAAG,EAAA;QACnC,OAAOC,cAAAA;AACT;AAEA,IAAA,OAAOT,aAAgBZ,GAAAA,YAAY,CAACY,aAAAA,CAAc,IAAIU,UAAWA,GAAAA,UAAAA;AACnE;;;;"}
|