node_modules ignore

This commit is contained in:
2025-05-08 23:43:47 +02:00
parent e19d52f172
commit 4574544c9f
65041 changed files with 10593536 additions and 0 deletions

View File

@@ -0,0 +1,124 @@
'use strict';
var React = require('react');
var strapiAdmin = require('@strapi/admin/strapi-admin');
var designSystem = require('@strapi/design-system');
var reactIntl = require('react-intl');
var reactQuery = require('react-query');
var pluginId = require('../pluginId.js');
function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
const useAssets = ({ skipWhen = false, query = {} } = {})=>{
const { formatMessage } = reactIntl.useIntl();
const { toggleNotification } = strapiAdmin.useNotification();
const { notifyStatus } = designSystem.useNotifyAT();
const { get } = strapiAdmin.useFetchClient();
const { folderPath, _q, ...paramsExceptFolderAndQ } = query;
let params;
if (_q) {
params = {
...paramsExceptFolderAndQ,
_q: encodeURIComponent(_q)
};
} else {
params = {
...paramsExceptFolderAndQ,
filters: {
$and: [
...paramsExceptFolderAndQ?.filters?.$and ?? [],
{
folderPath: {
$eq: folderPath ?? '/'
}
}
]
}
};
}
const { data, error, isLoading } = reactQuery.useQuery([
pluginId.pluginId,
'assets',
params
], async ()=>{
const { data } = await get('/upload/files', {
params
});
return data;
}, {
enabled: !skipWhen,
staleTime: 0,
cacheTime: 0,
select (data) {
if (data?.results && Array.isArray(data.results)) {
return {
...data,
results: data.results/**
* Filter out assets that don't have a name.
* So we don't try to render them as assets
* and get errors.
*/ .filter((asset)=>asset.name).map((asset)=>({
...asset,
/**
* Mime and ext cannot be null in the front-end because
* we expect them to be strings and use the `includes` method.
*/ mime: asset.mime ?? '',
ext: asset.ext ?? ''
}))
};
}
return data;
}
});
React__namespace.useEffect(()=>{
if (data) {
notifyStatus(formatMessage({
id: 'list.asset.at.finished',
defaultMessage: 'The assets have finished loading.'
}));
}
}, [
data,
formatMessage,
notifyStatus
]);
React__namespace.useEffect(()=>{
if (error) {
toggleNotification({
type: 'danger',
message: formatMessage({
id: 'notification.error'
})
});
}
}, [
error,
formatMessage,
toggleNotification
]);
return {
data,
error,
isLoading
};
};
exports.useAssets = useAssets;
//# sourceMappingURL=useAssets.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,103 @@
import * as React from 'react';
import { useNotification, useFetchClient } from '@strapi/admin/strapi-admin';
import { useNotifyAT } from '@strapi/design-system';
import { useIntl } from 'react-intl';
import { useQuery } from 'react-query';
import { pluginId } from '../pluginId.mjs';
const useAssets = ({ skipWhen = false, query = {} } = {})=>{
const { formatMessage } = useIntl();
const { toggleNotification } = useNotification();
const { notifyStatus } = useNotifyAT();
const { get } = useFetchClient();
const { folderPath, _q, ...paramsExceptFolderAndQ } = query;
let params;
if (_q) {
params = {
...paramsExceptFolderAndQ,
_q: encodeURIComponent(_q)
};
} else {
params = {
...paramsExceptFolderAndQ,
filters: {
$and: [
...paramsExceptFolderAndQ?.filters?.$and ?? [],
{
folderPath: {
$eq: folderPath ?? '/'
}
}
]
}
};
}
const { data, error, isLoading } = useQuery([
pluginId,
'assets',
params
], async ()=>{
const { data } = await get('/upload/files', {
params
});
return data;
}, {
enabled: !skipWhen,
staleTime: 0,
cacheTime: 0,
select (data) {
if (data?.results && Array.isArray(data.results)) {
return {
...data,
results: data.results/**
* Filter out assets that don't have a name.
* So we don't try to render them as assets
* and get errors.
*/ .filter((asset)=>asset.name).map((asset)=>({
...asset,
/**
* Mime and ext cannot be null in the front-end because
* we expect them to be strings and use the `includes` method.
*/ mime: asset.mime ?? '',
ext: asset.ext ?? ''
}))
};
}
return data;
}
});
React.useEffect(()=>{
if (data) {
notifyStatus(formatMessage({
id: 'list.asset.at.finished',
defaultMessage: 'The assets have finished loading.'
}));
}
}, [
data,
formatMessage,
notifyStatus
]);
React.useEffect(()=>{
if (error) {
toggleNotification({
type: 'danger',
message: formatMessage({
id: 'notification.error'
})
});
}
}, [
error,
formatMessage,
toggleNotification
]);
return {
data,
error,
isLoading
};
};
export { useAssets };
//# sourceMappingURL=useAssets.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,79 @@
'use strict';
var strapiAdmin = require('@strapi/admin/strapi-admin');
var reactIntl = require('react-intl');
var reactQuery = require('react-query');
var pluginId = require('../pluginId.js');
require('byte-size');
require('date-fns');
var getTrad = require('../utils/getTrad.js');
require('qs');
require('../constants.js');
require('../utils/urlYupSchema.js');
const useBulkMove = ()=>{
const { formatMessage } = reactIntl.useIntl();
const { toggleNotification } = strapiAdmin.useNotification();
const queryClient = reactQuery.useQueryClient();
const { post } = strapiAdmin.useFetchClient();
const bulkMoveQuery = ({ destinationFolderId, filesAndFolders })=>{
const payload = filesAndFolders.reduce((acc, selected)=>{
const { id, type } = selected;
const key = type === 'asset' ? 'fileIds' : 'folderIds';
if (!acc[key]) {
acc[key] = [];
}
acc[key].push(id);
return acc;
}, {});
return post('/upload/actions/bulk-move', {
...payload,
destinationFolderId
});
};
const mutation = reactQuery.useMutation(bulkMoveQuery, {
onSuccess (res) {
const { data: { data } } = res;
if (data?.files?.length > 0) {
queryClient.refetchQueries([
pluginId.pluginId,
'assets'
], {
active: true
});
queryClient.refetchQueries([
pluginId.pluginId,
'asset-count'
], {
active: true
});
}
// folders need to be re-fetched in any case, because assets might have been
// moved into a sub-folder and therefore the count needs to be updated
queryClient.refetchQueries([
pluginId.pluginId,
'folders'
], {
active: true
});
toggleNotification({
type: 'success',
message: formatMessage({
id: getTrad.getTrad('modal.move.success-label'),
defaultMessage: 'Elements have been moved successfully.'
})
});
}
});
const move = (destinationFolderId, filesAndFolders)=>mutation.mutateAsync({
destinationFolderId,
filesAndFolders
});
return {
...mutation,
move
};
};
exports.useBulkMove = useBulkMove;
//# sourceMappingURL=useBulkMove.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useBulkMove.js","sources":["../../../admin/src/hooks/useBulkMove.ts"],"sourcesContent":["import { useNotification, useFetchClient } from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useMutation, useQueryClient } from 'react-query';\n\nimport { File, BulkMoveFiles } from '../../../shared/contracts/files';\nimport { Folder, BulkMoveFolders } from '../../../shared/contracts/folders';\nimport { pluginId } from '../pluginId';\nimport { getTrad } from '../utils';\n\nexport interface FolderWithType extends Folder {\n type: string;\n}\n\nexport interface FileWithType extends File {\n type: string;\n}\n\ninterface BulkMoveParams {\n destinationFolderId: number | string;\n filesAndFolders: Array<FolderWithType | FileWithType>;\n}\n\n// Define the shape of the accumulator object\ntype Payload = {\n fileIds?: number[];\n folderIds?: number[];\n};\n\nexport const useBulkMove = () => {\n const { formatMessage } = useIntl();\n const { toggleNotification } = useNotification();\n const queryClient = useQueryClient();\n const { post } = useFetchClient();\n\n const bulkMoveQuery = ({ destinationFolderId, filesAndFolders }: BulkMoveParams) => {\n const payload = filesAndFolders.reduce<Payload>((acc, selected) => {\n const { id, type } = selected;\n const key = type === 'asset' ? 'fileIds' : 'folderIds';\n\n if (!acc[key]) {\n acc[key] = [];\n }\n\n acc[key]!.push(id);\n\n return acc;\n }, {});\n\n return post('/upload/actions/bulk-move', { ...payload, destinationFolderId });\n };\n\n const mutation = useMutation<\n BulkMoveFolders.Response | BulkMoveFiles.Response,\n BulkMoveFolders.Response['error'] | BulkMoveFiles.Response['error'],\n BulkMoveParams\n >(bulkMoveQuery, {\n onSuccess(res) {\n const {\n data: { data },\n } = res;\n\n if (data?.files?.length > 0) {\n queryClient.refetchQueries([pluginId, 'assets'], { active: true });\n queryClient.refetchQueries([pluginId, 'asset-count'], { active: true });\n }\n\n // folders need to be re-fetched in any case, because assets might have been\n // moved into a sub-folder and therefore the count needs to be updated\n queryClient.refetchQueries([pluginId, 'folders'], { active: true });\n\n toggleNotification({\n type: 'success',\n message: formatMessage({\n id: getTrad('modal.move.success-label'),\n defaultMessage: 'Elements have been moved successfully.',\n }),\n });\n },\n });\n\n const move = (\n destinationFolderId: number | string,\n filesAndFolders: Array<FolderWithType | FileWithType>\n ) => mutation.mutateAsync({ destinationFolderId, filesAndFolders });\n\n return { ...mutation, move };\n};\n"],"names":["useBulkMove","formatMessage","useIntl","toggleNotification","useNotification","queryClient","useQueryClient","post","useFetchClient","bulkMoveQuery","destinationFolderId","filesAndFolders","payload","reduce","acc","selected","id","type","key","push","mutation","useMutation","onSuccess","res","data","files","length","refetchQueries","pluginId","active","message","getTrad","defaultMessage","move","mutateAsync"],"mappings":";;;;;;;;;;;;;MA4BaA,WAAc,GAAA,IAAA;IACzB,MAAM,EAAEC,aAAa,EAAE,GAAGC,iBAAAA,EAAAA;IAC1B,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,2BAAAA,EAAAA;AAC/B,IAAA,MAAMC,WAAcC,GAAAA,yBAAAA,EAAAA;IACpB,MAAM,EAAEC,IAAI,EAAE,GAAGC,0BAAAA,EAAAA;AAEjB,IAAA,MAAMC,gBAAgB,CAAC,EAAEC,mBAAmB,EAAEC,eAAe,EAAkB,GAAA;AAC7E,QAAA,MAAMC,OAAUD,GAAAA,eAAAA,CAAgBE,MAAM,CAAU,CAACC,GAAKC,EAAAA,QAAAA,GAAAA;AACpD,YAAA,MAAM,EAAEC,EAAE,EAAEC,IAAI,EAAE,GAAGF,QAAAA;YACrB,MAAMG,GAAAA,GAAMD,IAAS,KAAA,OAAA,GAAU,SAAY,GAAA,WAAA;AAE3C,YAAA,IAAI,CAACH,GAAG,CAACI,GAAAA,CAAI,EAAE;gBACbJ,GAAG,CAACI,GAAI,CAAA,GAAG,EAAE;AACf;AAEAJ,YAAAA,GAAG,CAACI,GAAAA,CAAI,CAAEC,IAAI,CAACH,EAAAA,CAAAA;YAEf,OAAOF,GAAAA;AACT,SAAA,EAAG,EAAC,CAAA;AAEJ,QAAA,OAAOP,KAAK,2BAA6B,EAAA;AAAE,YAAA,GAAGK,OAAO;AAAEF,YAAAA;AAAoB,SAAA,CAAA;AAC7E,KAAA;IAEA,MAAMU,QAAAA,GAAWC,uBAIfZ,aAAe,EAAA;AACfa,QAAAA,SAAAA,CAAAA,CAAUC,GAAG,EAAA;AACX,YAAA,MAAM,EACJC,IAAM,EAAA,EAAEA,IAAI,EAAE,EACf,GAAGD,GAAAA;YAEJ,IAAIC,IAAAA,EAAMC,KAAOC,EAAAA,MAAAA,GAAS,CAAG,EAAA;AAC3BrB,gBAAAA,WAAAA,CAAYsB,cAAc,CAAC;AAACC,oBAAAA,iBAAAA;AAAU,oBAAA;iBAAS,EAAE;oBAAEC,MAAQ,EAAA;AAAK,iBAAA,CAAA;AAChExB,gBAAAA,WAAAA,CAAYsB,cAAc,CAAC;AAACC,oBAAAA,iBAAAA;AAAU,oBAAA;iBAAc,EAAE;oBAAEC,MAAQ,EAAA;AAAK,iBAAA,CAAA;AACvE;;;AAIAxB,YAAAA,WAAAA,CAAYsB,cAAc,CAAC;AAACC,gBAAAA,iBAAAA;AAAU,gBAAA;aAAU,EAAE;gBAAEC,MAAQ,EAAA;AAAK,aAAA,CAAA;YAEjE1B,kBAAmB,CAAA;gBACjBc,IAAM,EAAA,SAAA;AACNa,gBAAAA,OAAAA,EAAS7B,aAAc,CAAA;AACrBe,oBAAAA,EAAAA,EAAIe,eAAQ,CAAA,0BAAA,CAAA;oBACZC,cAAgB,EAAA;AAClB,iBAAA;AACF,aAAA,CAAA;AACF;AACF,KAAA,CAAA;AAEA,IAAA,MAAMC,OAAO,CACXvB,mBAAAA,EACAC,eACGS,GAAAA,QAAAA,CAASc,WAAW,CAAC;AAAExB,YAAAA,mBAAAA;AAAqBC,YAAAA;AAAgB,SAAA,CAAA;IAEjE,OAAO;AAAE,QAAA,GAAGS,QAAQ;AAAEa,QAAAA;AAAK,KAAA;AAC7B;;;;"}

View File

@@ -0,0 +1,77 @@
import { useNotification, useFetchClient } from '@strapi/admin/strapi-admin';
import { useIntl } from 'react-intl';
import { useQueryClient, useMutation } from 'react-query';
import { pluginId } from '../pluginId.mjs';
import 'byte-size';
import 'date-fns';
import { getTrad } from '../utils/getTrad.mjs';
import 'qs';
import '../constants.mjs';
import '../utils/urlYupSchema.mjs';
const useBulkMove = ()=>{
const { formatMessage } = useIntl();
const { toggleNotification } = useNotification();
const queryClient = useQueryClient();
const { post } = useFetchClient();
const bulkMoveQuery = ({ destinationFolderId, filesAndFolders })=>{
const payload = filesAndFolders.reduce((acc, selected)=>{
const { id, type } = selected;
const key = type === 'asset' ? 'fileIds' : 'folderIds';
if (!acc[key]) {
acc[key] = [];
}
acc[key].push(id);
return acc;
}, {});
return post('/upload/actions/bulk-move', {
...payload,
destinationFolderId
});
};
const mutation = useMutation(bulkMoveQuery, {
onSuccess (res) {
const { data: { data } } = res;
if (data?.files?.length > 0) {
queryClient.refetchQueries([
pluginId,
'assets'
], {
active: true
});
queryClient.refetchQueries([
pluginId,
'asset-count'
], {
active: true
});
}
// folders need to be re-fetched in any case, because assets might have been
// moved into a sub-folder and therefore the count needs to be updated
queryClient.refetchQueries([
pluginId,
'folders'
], {
active: true
});
toggleNotification({
type: 'success',
message: formatMessage({
id: getTrad('modal.move.success-label'),
defaultMessage: 'Elements have been moved successfully.'
})
});
}
});
const move = (destinationFolderId, filesAndFolders)=>mutation.mutateAsync({
destinationFolderId,
filesAndFolders
});
return {
...mutation,
move
};
};
export { useBulkMove };
//# sourceMappingURL=useBulkMove.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useBulkMove.mjs","sources":["../../../admin/src/hooks/useBulkMove.ts"],"sourcesContent":["import { useNotification, useFetchClient } from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useMutation, useQueryClient } from 'react-query';\n\nimport { File, BulkMoveFiles } from '../../../shared/contracts/files';\nimport { Folder, BulkMoveFolders } from '../../../shared/contracts/folders';\nimport { pluginId } from '../pluginId';\nimport { getTrad } from '../utils';\n\nexport interface FolderWithType extends Folder {\n type: string;\n}\n\nexport interface FileWithType extends File {\n type: string;\n}\n\ninterface BulkMoveParams {\n destinationFolderId: number | string;\n filesAndFolders: Array<FolderWithType | FileWithType>;\n}\n\n// Define the shape of the accumulator object\ntype Payload = {\n fileIds?: number[];\n folderIds?: number[];\n};\n\nexport const useBulkMove = () => {\n const { formatMessage } = useIntl();\n const { toggleNotification } = useNotification();\n const queryClient = useQueryClient();\n const { post } = useFetchClient();\n\n const bulkMoveQuery = ({ destinationFolderId, filesAndFolders }: BulkMoveParams) => {\n const payload = filesAndFolders.reduce<Payload>((acc, selected) => {\n const { id, type } = selected;\n const key = type === 'asset' ? 'fileIds' : 'folderIds';\n\n if (!acc[key]) {\n acc[key] = [];\n }\n\n acc[key]!.push(id);\n\n return acc;\n }, {});\n\n return post('/upload/actions/bulk-move', { ...payload, destinationFolderId });\n };\n\n const mutation = useMutation<\n BulkMoveFolders.Response | BulkMoveFiles.Response,\n BulkMoveFolders.Response['error'] | BulkMoveFiles.Response['error'],\n BulkMoveParams\n >(bulkMoveQuery, {\n onSuccess(res) {\n const {\n data: { data },\n } = res;\n\n if (data?.files?.length > 0) {\n queryClient.refetchQueries([pluginId, 'assets'], { active: true });\n queryClient.refetchQueries([pluginId, 'asset-count'], { active: true });\n }\n\n // folders need to be re-fetched in any case, because assets might have been\n // moved into a sub-folder and therefore the count needs to be updated\n queryClient.refetchQueries([pluginId, 'folders'], { active: true });\n\n toggleNotification({\n type: 'success',\n message: formatMessage({\n id: getTrad('modal.move.success-label'),\n defaultMessage: 'Elements have been moved successfully.',\n }),\n });\n },\n });\n\n const move = (\n destinationFolderId: number | string,\n filesAndFolders: Array<FolderWithType | FileWithType>\n ) => mutation.mutateAsync({ destinationFolderId, filesAndFolders });\n\n return { ...mutation, move };\n};\n"],"names":["useBulkMove","formatMessage","useIntl","toggleNotification","useNotification","queryClient","useQueryClient","post","useFetchClient","bulkMoveQuery","destinationFolderId","filesAndFolders","payload","reduce","acc","selected","id","type","key","push","mutation","useMutation","onSuccess","res","data","files","length","refetchQueries","pluginId","active","message","getTrad","defaultMessage","move","mutateAsync"],"mappings":";;;;;;;;;;;MA4BaA,WAAc,GAAA,IAAA;IACzB,MAAM,EAAEC,aAAa,EAAE,GAAGC,OAAAA,EAAAA;IAC1B,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,eAAAA,EAAAA;AAC/B,IAAA,MAAMC,WAAcC,GAAAA,cAAAA,EAAAA;IACpB,MAAM,EAAEC,IAAI,EAAE,GAAGC,cAAAA,EAAAA;AAEjB,IAAA,MAAMC,gBAAgB,CAAC,EAAEC,mBAAmB,EAAEC,eAAe,EAAkB,GAAA;AAC7E,QAAA,MAAMC,OAAUD,GAAAA,eAAAA,CAAgBE,MAAM,CAAU,CAACC,GAAKC,EAAAA,QAAAA,GAAAA;AACpD,YAAA,MAAM,EAAEC,EAAE,EAAEC,IAAI,EAAE,GAAGF,QAAAA;YACrB,MAAMG,GAAAA,GAAMD,IAAS,KAAA,OAAA,GAAU,SAAY,GAAA,WAAA;AAE3C,YAAA,IAAI,CAACH,GAAG,CAACI,GAAAA,CAAI,EAAE;gBACbJ,GAAG,CAACI,GAAI,CAAA,GAAG,EAAE;AACf;AAEAJ,YAAAA,GAAG,CAACI,GAAAA,CAAI,CAAEC,IAAI,CAACH,EAAAA,CAAAA;YAEf,OAAOF,GAAAA;AACT,SAAA,EAAG,EAAC,CAAA;AAEJ,QAAA,OAAOP,KAAK,2BAA6B,EAAA;AAAE,YAAA,GAAGK,OAAO;AAAEF,YAAAA;AAAoB,SAAA,CAAA;AAC7E,KAAA;IAEA,MAAMU,QAAAA,GAAWC,YAIfZ,aAAe,EAAA;AACfa,QAAAA,SAAAA,CAAAA,CAAUC,GAAG,EAAA;AACX,YAAA,MAAM,EACJC,IAAM,EAAA,EAAEA,IAAI,EAAE,EACf,GAAGD,GAAAA;YAEJ,IAAIC,IAAAA,EAAMC,KAAOC,EAAAA,MAAAA,GAAS,CAAG,EAAA;AAC3BrB,gBAAAA,WAAAA,CAAYsB,cAAc,CAAC;AAACC,oBAAAA,QAAAA;AAAU,oBAAA;iBAAS,EAAE;oBAAEC,MAAQ,EAAA;AAAK,iBAAA,CAAA;AAChExB,gBAAAA,WAAAA,CAAYsB,cAAc,CAAC;AAACC,oBAAAA,QAAAA;AAAU,oBAAA;iBAAc,EAAE;oBAAEC,MAAQ,EAAA;AAAK,iBAAA,CAAA;AACvE;;;AAIAxB,YAAAA,WAAAA,CAAYsB,cAAc,CAAC;AAACC,gBAAAA,QAAAA;AAAU,gBAAA;aAAU,EAAE;gBAAEC,MAAQ,EAAA;AAAK,aAAA,CAAA;YAEjE1B,kBAAmB,CAAA;gBACjBc,IAAM,EAAA,SAAA;AACNa,gBAAAA,OAAAA,EAAS7B,aAAc,CAAA;AACrBe,oBAAAA,EAAAA,EAAIe,OAAQ,CAAA,0BAAA,CAAA;oBACZC,cAAgB,EAAA;AAClB,iBAAA;AACF,aAAA,CAAA;AACF;AACF,KAAA,CAAA;AAEA,IAAA,MAAMC,OAAO,CACXvB,mBAAAA,EACAC,eACGS,GAAAA,QAAAA,CAASc,WAAW,CAAC;AAAExB,YAAAA,mBAAAA;AAAqBC,YAAAA;AAAgB,SAAA,CAAA;IAEjE,OAAO;AAAE,QAAA,GAAGS,QAAQ;AAAEa,QAAAA;AAAK,KAAA;AAC7B;;;;"}

View File

@@ -0,0 +1,79 @@
'use strict';
var strapiAdmin = require('@strapi/admin/strapi-admin');
var reactIntl = require('react-intl');
var reactQuery = require('react-query');
var pluginId = require('../pluginId.js');
require('byte-size');
require('date-fns');
var getTrad = require('../utils/getTrad.js');
require('qs');
require('../constants.js');
require('../utils/urlYupSchema.js');
const useBulkRemove = ()=>{
const { toggleNotification } = strapiAdmin.useNotification();
const { formatMessage } = reactIntl.useIntl();
const queryClient = reactQuery.useQueryClient();
const { post } = strapiAdmin.useFetchClient();
const bulkRemoveQuery = (filesAndFolders)=>{
const payload = filesAndFolders.reduce((acc, selected)=>{
const { id, type } = selected;
const key = type === 'asset' ? 'fileIds' : 'folderIds';
if (!acc[key]) {
acc[key] = [];
}
acc[key].push(id);
return acc;
}, {});
return post('/upload/actions/bulk-delete', payload);
};
const mutation = reactQuery.useMutation(bulkRemoveQuery, {
onSuccess (res) {
const { data: { data } } = res;
if (data?.files?.length > 0) {
queryClient.refetchQueries([
pluginId.pluginId,
'assets'
], {
active: true
});
queryClient.refetchQueries([
pluginId.pluginId,
'asset-count'
], {
active: true
});
}
if (data?.folders?.length > 0) {
queryClient.refetchQueries([
pluginId.pluginId,
'folders'
], {
active: true
});
}
toggleNotification({
type: 'success',
message: formatMessage({
id: getTrad.getTrad('modal.remove.success-label'),
defaultMessage: 'Elements have been successfully deleted.'
})
});
},
onError (error) {
toggleNotification({
type: 'danger',
message: error?.message
});
}
});
const remove = (...args)=>mutation.mutateAsync(...args);
return {
...mutation,
remove
};
};
exports.useBulkRemove = useBulkRemove;
//# sourceMappingURL=useBulkRemove.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useBulkRemove.js","sources":["../../../admin/src/hooks/useBulkRemove.ts"],"sourcesContent":["import { useNotification, useFetchClient } from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useMutation, useQueryClient } from 'react-query';\n\nimport { BulkDeleteFiles, File } from '../../../shared/contracts/files';\nimport { pluginId } from '../pluginId';\nimport { getTrad } from '../utils';\n\nimport type { BulkDeleteFolders, FolderDefinition } from '../../../shared/contracts/folders';\n\nexport interface FileWithType extends File {\n type: string;\n}\n\ntype BulkRemovePayload = Partial<BulkDeleteFiles.Request['body']> &\n Partial<BulkDeleteFolders.Request['body']>;\n\nexport const useBulkRemove = () => {\n const { toggleNotification } = useNotification();\n const { formatMessage } = useIntl();\n const queryClient = useQueryClient();\n const { post } = useFetchClient();\n\n const bulkRemoveQuery = (filesAndFolders: Array<FileWithType | FolderDefinition>) => {\n const payload = filesAndFolders.reduce<BulkRemovePayload>((acc, selected) => {\n const { id, type } = selected;\n const key = type === 'asset' ? 'fileIds' : 'folderIds';\n\n if (!acc[key]) {\n acc[key] = [];\n }\n\n acc[key]!.push(id);\n\n return acc;\n }, {});\n\n return post('/upload/actions/bulk-delete', payload);\n };\n\n const mutation = useMutation<\n BulkDeleteFiles.Response | BulkDeleteFolders.Response,\n BulkDeleteFiles.Response['error'] | BulkDeleteFolders.Response['error'],\n Array<FileWithType | FolderDefinition>\n >(bulkRemoveQuery, {\n onSuccess(res) {\n const {\n data: { data },\n } = res;\n\n if (data?.files?.length > 0) {\n queryClient.refetchQueries([pluginId, 'assets'], { active: true });\n queryClient.refetchQueries([pluginId, 'asset-count'], { active: true });\n }\n\n if (data?.folders?.length > 0) {\n queryClient.refetchQueries([pluginId, 'folders'], { active: true });\n }\n\n toggleNotification({\n type: 'success',\n message: formatMessage({\n id: getTrad('modal.remove.success-label'),\n defaultMessage: 'Elements have been successfully deleted.',\n }),\n });\n },\n onError(error) {\n toggleNotification({ type: 'danger', message: error?.message });\n },\n });\n\n const remove = (...args: Parameters<typeof mutation.mutateAsync>) =>\n mutation.mutateAsync(...args);\n\n return { ...mutation, remove };\n};\n"],"names":["useBulkRemove","toggleNotification","useNotification","formatMessage","useIntl","queryClient","useQueryClient","post","useFetchClient","bulkRemoveQuery","filesAndFolders","payload","reduce","acc","selected","id","type","key","push","mutation","useMutation","onSuccess","res","data","files","length","refetchQueries","pluginId","active","folders","message","getTrad","defaultMessage","onError","error","remove","args","mutateAsync"],"mappings":";;;;;;;;;;;;;MAiBaA,aAAgB,GAAA,IAAA;IAC3B,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,2BAAAA,EAAAA;IAC/B,MAAM,EAAEC,aAAa,EAAE,GAAGC,iBAAAA,EAAAA;AAC1B,IAAA,MAAMC,WAAcC,GAAAA,yBAAAA,EAAAA;IACpB,MAAM,EAAEC,IAAI,EAAE,GAAGC,0BAAAA,EAAAA;AAEjB,IAAA,MAAMC,kBAAkB,CAACC,eAAAA,GAAAA;AACvB,QAAA,MAAMC,OAAUD,GAAAA,eAAAA,CAAgBE,MAAM,CAAoB,CAACC,GAAKC,EAAAA,QAAAA,GAAAA;AAC9D,YAAA,MAAM,EAAEC,EAAE,EAAEC,IAAI,EAAE,GAAGF,QAAAA;YACrB,MAAMG,GAAAA,GAAMD,IAAS,KAAA,OAAA,GAAU,SAAY,GAAA,WAAA;AAE3C,YAAA,IAAI,CAACH,GAAG,CAACI,GAAAA,CAAI,EAAE;gBACbJ,GAAG,CAACI,GAAI,CAAA,GAAG,EAAE;AACf;AAEAJ,YAAAA,GAAG,CAACI,GAAAA,CAAI,CAAEC,IAAI,CAACH,EAAAA,CAAAA;YAEf,OAAOF,GAAAA;AACT,SAAA,EAAG,EAAC,CAAA;AAEJ,QAAA,OAAON,KAAK,6BAA+BI,EAAAA,OAAAA,CAAAA;AAC7C,KAAA;IAEA,MAAMQ,QAAAA,GAAWC,uBAIfX,eAAiB,EAAA;AACjBY,QAAAA,SAAAA,CAAAA,CAAUC,GAAG,EAAA;AACX,YAAA,MAAM,EACJC,IAAM,EAAA,EAAEA,IAAI,EAAE,EACf,GAAGD,GAAAA;YAEJ,IAAIC,IAAAA,EAAMC,KAAOC,EAAAA,MAAAA,GAAS,CAAG,EAAA;AAC3BpB,gBAAAA,WAAAA,CAAYqB,cAAc,CAAC;AAACC,oBAAAA,iBAAAA;AAAU,oBAAA;iBAAS,EAAE;oBAAEC,MAAQ,EAAA;AAAK,iBAAA,CAAA;AAChEvB,gBAAAA,WAAAA,CAAYqB,cAAc,CAAC;AAACC,oBAAAA,iBAAAA;AAAU,oBAAA;iBAAc,EAAE;oBAAEC,MAAQ,EAAA;AAAK,iBAAA,CAAA;AACvE;YAEA,IAAIL,IAAAA,EAAMM,OAASJ,EAAAA,MAAAA,GAAS,CAAG,EAAA;AAC7BpB,gBAAAA,WAAAA,CAAYqB,cAAc,CAAC;AAACC,oBAAAA,iBAAAA;AAAU,oBAAA;iBAAU,EAAE;oBAAEC,MAAQ,EAAA;AAAK,iBAAA,CAAA;AACnE;YAEA3B,kBAAmB,CAAA;gBACjBe,IAAM,EAAA,SAAA;AACNc,gBAAAA,OAAAA,EAAS3B,aAAc,CAAA;AACrBY,oBAAAA,EAAAA,EAAIgB,eAAQ,CAAA,4BAAA,CAAA;oBACZC,cAAgB,EAAA;AAClB,iBAAA;AACF,aAAA,CAAA;AACF,SAAA;AACAC,QAAAA,OAAAA,CAAAA,CAAQC,KAAK,EAAA;YACXjC,kBAAmB,CAAA;gBAAEe,IAAM,EAAA,QAAA;AAAUc,gBAAAA,OAAAA,EAASI,KAAOJ,EAAAA;AAAQ,aAAA,CAAA;AAC/D;AACF,KAAA,CAAA;AAEA,IAAA,MAAMK,SAAS,CAAC,GAAGC,IACjBjB,GAAAA,QAAAA,CAASkB,WAAW,CAAID,GAAAA,IAAAA,CAAAA;IAE1B,OAAO;AAAE,QAAA,GAAGjB,QAAQ;AAAEgB,QAAAA;AAAO,KAAA;AAC/B;;;;"}

View File

@@ -0,0 +1,77 @@
import { useNotification, useFetchClient } from '@strapi/admin/strapi-admin';
import { useIntl } from 'react-intl';
import { useQueryClient, useMutation } from 'react-query';
import { pluginId } from '../pluginId.mjs';
import 'byte-size';
import 'date-fns';
import { getTrad } from '../utils/getTrad.mjs';
import 'qs';
import '../constants.mjs';
import '../utils/urlYupSchema.mjs';
const useBulkRemove = ()=>{
const { toggleNotification } = useNotification();
const { formatMessage } = useIntl();
const queryClient = useQueryClient();
const { post } = useFetchClient();
const bulkRemoveQuery = (filesAndFolders)=>{
const payload = filesAndFolders.reduce((acc, selected)=>{
const { id, type } = selected;
const key = type === 'asset' ? 'fileIds' : 'folderIds';
if (!acc[key]) {
acc[key] = [];
}
acc[key].push(id);
return acc;
}, {});
return post('/upload/actions/bulk-delete', payload);
};
const mutation = useMutation(bulkRemoveQuery, {
onSuccess (res) {
const { data: { data } } = res;
if (data?.files?.length > 0) {
queryClient.refetchQueries([
pluginId,
'assets'
], {
active: true
});
queryClient.refetchQueries([
pluginId,
'asset-count'
], {
active: true
});
}
if (data?.folders?.length > 0) {
queryClient.refetchQueries([
pluginId,
'folders'
], {
active: true
});
}
toggleNotification({
type: 'success',
message: formatMessage({
id: getTrad('modal.remove.success-label'),
defaultMessage: 'Elements have been successfully deleted.'
})
});
},
onError (error) {
toggleNotification({
type: 'danger',
message: error?.message
});
}
});
const remove = (...args)=>mutation.mutateAsync(...args);
return {
...mutation,
remove
};
};
export { useBulkRemove };
//# sourceMappingURL=useBulkRemove.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useBulkRemove.mjs","sources":["../../../admin/src/hooks/useBulkRemove.ts"],"sourcesContent":["import { useNotification, useFetchClient } from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useMutation, useQueryClient } from 'react-query';\n\nimport { BulkDeleteFiles, File } from '../../../shared/contracts/files';\nimport { pluginId } from '../pluginId';\nimport { getTrad } from '../utils';\n\nimport type { BulkDeleteFolders, FolderDefinition } from '../../../shared/contracts/folders';\n\nexport interface FileWithType extends File {\n type: string;\n}\n\ntype BulkRemovePayload = Partial<BulkDeleteFiles.Request['body']> &\n Partial<BulkDeleteFolders.Request['body']>;\n\nexport const useBulkRemove = () => {\n const { toggleNotification } = useNotification();\n const { formatMessage } = useIntl();\n const queryClient = useQueryClient();\n const { post } = useFetchClient();\n\n const bulkRemoveQuery = (filesAndFolders: Array<FileWithType | FolderDefinition>) => {\n const payload = filesAndFolders.reduce<BulkRemovePayload>((acc, selected) => {\n const { id, type } = selected;\n const key = type === 'asset' ? 'fileIds' : 'folderIds';\n\n if (!acc[key]) {\n acc[key] = [];\n }\n\n acc[key]!.push(id);\n\n return acc;\n }, {});\n\n return post('/upload/actions/bulk-delete', payload);\n };\n\n const mutation = useMutation<\n BulkDeleteFiles.Response | BulkDeleteFolders.Response,\n BulkDeleteFiles.Response['error'] | BulkDeleteFolders.Response['error'],\n Array<FileWithType | FolderDefinition>\n >(bulkRemoveQuery, {\n onSuccess(res) {\n const {\n data: { data },\n } = res;\n\n if (data?.files?.length > 0) {\n queryClient.refetchQueries([pluginId, 'assets'], { active: true });\n queryClient.refetchQueries([pluginId, 'asset-count'], { active: true });\n }\n\n if (data?.folders?.length > 0) {\n queryClient.refetchQueries([pluginId, 'folders'], { active: true });\n }\n\n toggleNotification({\n type: 'success',\n message: formatMessage({\n id: getTrad('modal.remove.success-label'),\n defaultMessage: 'Elements have been successfully deleted.',\n }),\n });\n },\n onError(error) {\n toggleNotification({ type: 'danger', message: error?.message });\n },\n });\n\n const remove = (...args: Parameters<typeof mutation.mutateAsync>) =>\n mutation.mutateAsync(...args);\n\n return { ...mutation, remove };\n};\n"],"names":["useBulkRemove","toggleNotification","useNotification","formatMessage","useIntl","queryClient","useQueryClient","post","useFetchClient","bulkRemoveQuery","filesAndFolders","payload","reduce","acc","selected","id","type","key","push","mutation","useMutation","onSuccess","res","data","files","length","refetchQueries","pluginId","active","folders","message","getTrad","defaultMessage","onError","error","remove","args","mutateAsync"],"mappings":";;;;;;;;;;;MAiBaA,aAAgB,GAAA,IAAA;IAC3B,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,eAAAA,EAAAA;IAC/B,MAAM,EAAEC,aAAa,EAAE,GAAGC,OAAAA,EAAAA;AAC1B,IAAA,MAAMC,WAAcC,GAAAA,cAAAA,EAAAA;IACpB,MAAM,EAAEC,IAAI,EAAE,GAAGC,cAAAA,EAAAA;AAEjB,IAAA,MAAMC,kBAAkB,CAACC,eAAAA,GAAAA;AACvB,QAAA,MAAMC,OAAUD,GAAAA,eAAAA,CAAgBE,MAAM,CAAoB,CAACC,GAAKC,EAAAA,QAAAA,GAAAA;AAC9D,YAAA,MAAM,EAAEC,EAAE,EAAEC,IAAI,EAAE,GAAGF,QAAAA;YACrB,MAAMG,GAAAA,GAAMD,IAAS,KAAA,OAAA,GAAU,SAAY,GAAA,WAAA;AAE3C,YAAA,IAAI,CAACH,GAAG,CAACI,GAAAA,CAAI,EAAE;gBACbJ,GAAG,CAACI,GAAI,CAAA,GAAG,EAAE;AACf;AAEAJ,YAAAA,GAAG,CAACI,GAAAA,CAAI,CAAEC,IAAI,CAACH,EAAAA,CAAAA;YAEf,OAAOF,GAAAA;AACT,SAAA,EAAG,EAAC,CAAA;AAEJ,QAAA,OAAON,KAAK,6BAA+BI,EAAAA,OAAAA,CAAAA;AAC7C,KAAA;IAEA,MAAMQ,QAAAA,GAAWC,YAIfX,eAAiB,EAAA;AACjBY,QAAAA,SAAAA,CAAAA,CAAUC,GAAG,EAAA;AACX,YAAA,MAAM,EACJC,IAAM,EAAA,EAAEA,IAAI,EAAE,EACf,GAAGD,GAAAA;YAEJ,IAAIC,IAAAA,EAAMC,KAAOC,EAAAA,MAAAA,GAAS,CAAG,EAAA;AAC3BpB,gBAAAA,WAAAA,CAAYqB,cAAc,CAAC;AAACC,oBAAAA,QAAAA;AAAU,oBAAA;iBAAS,EAAE;oBAAEC,MAAQ,EAAA;AAAK,iBAAA,CAAA;AAChEvB,gBAAAA,WAAAA,CAAYqB,cAAc,CAAC;AAACC,oBAAAA,QAAAA;AAAU,oBAAA;iBAAc,EAAE;oBAAEC,MAAQ,EAAA;AAAK,iBAAA,CAAA;AACvE;YAEA,IAAIL,IAAAA,EAAMM,OAASJ,EAAAA,MAAAA,GAAS,CAAG,EAAA;AAC7BpB,gBAAAA,WAAAA,CAAYqB,cAAc,CAAC;AAACC,oBAAAA,QAAAA;AAAU,oBAAA;iBAAU,EAAE;oBAAEC,MAAQ,EAAA;AAAK,iBAAA,CAAA;AACnE;YAEA3B,kBAAmB,CAAA;gBACjBe,IAAM,EAAA,SAAA;AACNc,gBAAAA,OAAAA,EAAS3B,aAAc,CAAA;AACrBY,oBAAAA,EAAAA,EAAIgB,OAAQ,CAAA,4BAAA,CAAA;oBACZC,cAAgB,EAAA;AAClB,iBAAA;AACF,aAAA,CAAA;AACF,SAAA;AACAC,QAAAA,OAAAA,CAAAA,CAAQC,KAAK,EAAA;YACXjC,kBAAmB,CAAA;gBAAEe,IAAM,EAAA,QAAA;AAAUc,gBAAAA,OAAAA,EAASI,KAAOJ,EAAAA;AAAQ,aAAA,CAAA;AAC/D;AACF,KAAA,CAAA;AAEA,IAAA,MAAMK,SAAS,CAAC,GAAGC,IACjBjB,GAAAA,QAAAA,CAASkB,WAAW,CAAID,GAAAA,IAAAA,CAAAA;IAE1B,OAAO;AAAE,QAAA,GAAGjB,QAAQ;AAAEgB,QAAAA;AAAO,KAAA;AAC/B;;;;"}

View File

@@ -0,0 +1,57 @@
'use strict';
var strapiAdmin = require('@strapi/admin/strapi-admin');
var reactIntl = require('react-intl');
var reactQuery = require('react-query');
var pluginId = require('../pluginId.js');
const endpoint = `/${pluginId.pluginId}/configuration`;
const queryKey = [
pluginId.pluginId,
'configuration'
];
const useConfig = ()=>{
const { trackUsage } = strapiAdmin.useTracking();
const { formatMessage } = reactIntl.useIntl();
const { toggleNotification } = strapiAdmin.useNotification();
const { get, put } = strapiAdmin.useFetchClient();
const config = reactQuery.useQuery(queryKey, async ()=>{
const res = await get(endpoint);
return res.data.data;
}, {
onError () {
return toggleNotification({
type: 'danger',
message: formatMessage({
id: 'notification.error'
})
});
},
/**
* We're cementing that we always expect an object to be returned.
*/ select: (data)=>data || {}
});
const putMutation = reactQuery.useMutation(async (body)=>{
await put(endpoint, body);
}, {
onSuccess () {
trackUsage('didEditMediaLibraryConfig');
config.refetch();
},
onError () {
return toggleNotification({
type: 'danger',
message: formatMessage({
id: 'notification.error'
})
});
}
});
return {
config,
mutateConfig: putMutation
};
};
exports.useConfig = useConfig;
//# sourceMappingURL=useConfig.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useConfig.js","sources":["../../../admin/src/hooks/useConfig.ts"],"sourcesContent":["import { useTracking, useNotification, useFetchClient } from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useMutation, useQuery, UseMutationResult, UseQueryResult } from 'react-query';\n\nimport { GetConfiguration, UpdateConfiguration } from '../../../shared/contracts/configuration';\nimport { pluginId } from '../pluginId';\n\nconst endpoint = `/${pluginId}/configuration`;\nconst queryKey = [pluginId, 'configuration'];\n\nexport const useConfig = () => {\n const { trackUsage } = useTracking();\n const { formatMessage } = useIntl();\n const { toggleNotification } = useNotification();\n const { get, put } = useFetchClient();\n\n const config: UseQueryResult<\n GetConfiguration.Response['data']['data'] | GetConfiguration.Response['error']\n > = useQuery(\n queryKey,\n async () => {\n const res: GetConfiguration.Response = await get(endpoint);\n\n return res.data.data;\n },\n {\n onError() {\n return toggleNotification({\n type: 'danger',\n message: formatMessage({ id: 'notification.error' }),\n });\n },\n /**\n * We're cementing that we always expect an object to be returned.\n */\n select: (data) => data || {},\n }\n );\n\n const putMutation: UseMutationResult<\n void,\n UpdateConfiguration.Response['error'],\n UpdateConfiguration.Request['body']\n > = useMutation(\n async (body) => {\n await put<UpdateConfiguration.Response>(endpoint, body);\n },\n {\n onSuccess() {\n trackUsage('didEditMediaLibraryConfig');\n config.refetch();\n },\n onError() {\n return toggleNotification({\n type: 'danger',\n message: formatMessage({ id: 'notification.error' }),\n });\n },\n }\n );\n\n return {\n config,\n mutateConfig: putMutation,\n };\n};\n"],"names":["endpoint","pluginId","queryKey","useConfig","trackUsage","useTracking","formatMessage","useIntl","toggleNotification","useNotification","get","put","useFetchClient","config","useQuery","res","data","onError","type","message","id","select","putMutation","useMutation","body","onSuccess","refetch","mutateConfig"],"mappings":";;;;;;;AAOA,MAAMA,WAAW,CAAC,CAAC,EAAEC,iBAAAA,CAAS,cAAc,CAAC;AAC7C,MAAMC,QAAW,GAAA;AAACD,IAAAA,iBAAAA;AAAU,IAAA;AAAgB,CAAA;MAE/BE,SAAY,GAAA,IAAA;IACvB,MAAM,EAAEC,UAAU,EAAE,GAAGC,uBAAAA,EAAAA;IACvB,MAAM,EAAEC,aAAa,EAAE,GAAGC,iBAAAA,EAAAA;IAC1B,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,2BAAAA,EAAAA;AAC/B,IAAA,MAAM,EAAEC,GAAG,EAAEC,GAAG,EAAE,GAAGC,0BAAAA,EAAAA;IAErB,MAAMC,MAAAA,GAEFC,oBACFZ,QACA,EAAA,UAAA;QACE,MAAMa,GAAAA,GAAiC,MAAML,GAAIV,CAAAA,QAAAA,CAAAA;QAEjD,OAAOe,GAAAA,CAAIC,IAAI,CAACA,IAAI;KAEtB,EAAA;AACEC,QAAAA,OAAAA,CAAAA,GAAAA;AACE,YAAA,OAAOT,kBAAmB,CAAA;gBACxBU,IAAM,EAAA,QAAA;AACNC,gBAAAA,OAAAA,EAASb,aAAc,CAAA;oBAAEc,EAAI,EAAA;AAAqB,iBAAA;AACpD,aAAA,CAAA;AACF,SAAA;AACA;;AAEC,UACDC,MAAQ,EAAA,CAACL,IAASA,GAAAA,IAAAA,IAAQ;AAC5B,KAAA,CAAA;IAGF,MAAMM,WAAAA,GAIFC,uBACF,OAAOC,IAAAA,GAAAA;AACL,QAAA,MAAMb,IAAkCX,QAAUwB,EAAAA,IAAAA,CAAAA;KAEpD,EAAA;AACEC,QAAAA,SAAAA,CAAAA,GAAAA;YACErB,UAAW,CAAA,2BAAA,CAAA;AACXS,YAAAA,MAAAA,CAAOa,OAAO,EAAA;AAChB,SAAA;AACAT,QAAAA,OAAAA,CAAAA,GAAAA;AACE,YAAA,OAAOT,kBAAmB,CAAA;gBACxBU,IAAM,EAAA,QAAA;AACNC,gBAAAA,OAAAA,EAASb,aAAc,CAAA;oBAAEc,EAAI,EAAA;AAAqB,iBAAA;AACpD,aAAA,CAAA;AACF;AACF,KAAA,CAAA;IAGF,OAAO;AACLP,QAAAA,MAAAA;QACAc,YAAcL,EAAAA;AAChB,KAAA;AACF;;;;"}

View File

@@ -0,0 +1,55 @@
import { useTracking, useNotification, useFetchClient } from '@strapi/admin/strapi-admin';
import { useIntl } from 'react-intl';
import { useQuery, useMutation } from 'react-query';
import { pluginId } from '../pluginId.mjs';
const endpoint = `/${pluginId}/configuration`;
const queryKey = [
pluginId,
'configuration'
];
const useConfig = ()=>{
const { trackUsage } = useTracking();
const { formatMessage } = useIntl();
const { toggleNotification } = useNotification();
const { get, put } = useFetchClient();
const config = useQuery(queryKey, async ()=>{
const res = await get(endpoint);
return res.data.data;
}, {
onError () {
return toggleNotification({
type: 'danger',
message: formatMessage({
id: 'notification.error'
})
});
},
/**
* We're cementing that we always expect an object to be returned.
*/ select: (data)=>data || {}
});
const putMutation = useMutation(async (body)=>{
await put(endpoint, body);
}, {
onSuccess () {
trackUsage('didEditMediaLibraryConfig');
config.refetch();
},
onError () {
return toggleNotification({
type: 'danger',
message: formatMessage({
id: 'notification.error'
})
});
}
});
return {
config,
mutateConfig: putMutation
};
};
export { useConfig };
//# sourceMappingURL=useConfig.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useConfig.mjs","sources":["../../../admin/src/hooks/useConfig.ts"],"sourcesContent":["import { useTracking, useNotification, useFetchClient } from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useMutation, useQuery, UseMutationResult, UseQueryResult } from 'react-query';\n\nimport { GetConfiguration, UpdateConfiguration } from '../../../shared/contracts/configuration';\nimport { pluginId } from '../pluginId';\n\nconst endpoint = `/${pluginId}/configuration`;\nconst queryKey = [pluginId, 'configuration'];\n\nexport const useConfig = () => {\n const { trackUsage } = useTracking();\n const { formatMessage } = useIntl();\n const { toggleNotification } = useNotification();\n const { get, put } = useFetchClient();\n\n const config: UseQueryResult<\n GetConfiguration.Response['data']['data'] | GetConfiguration.Response['error']\n > = useQuery(\n queryKey,\n async () => {\n const res: GetConfiguration.Response = await get(endpoint);\n\n return res.data.data;\n },\n {\n onError() {\n return toggleNotification({\n type: 'danger',\n message: formatMessage({ id: 'notification.error' }),\n });\n },\n /**\n * We're cementing that we always expect an object to be returned.\n */\n select: (data) => data || {},\n }\n );\n\n const putMutation: UseMutationResult<\n void,\n UpdateConfiguration.Response['error'],\n UpdateConfiguration.Request['body']\n > = useMutation(\n async (body) => {\n await put<UpdateConfiguration.Response>(endpoint, body);\n },\n {\n onSuccess() {\n trackUsage('didEditMediaLibraryConfig');\n config.refetch();\n },\n onError() {\n return toggleNotification({\n type: 'danger',\n message: formatMessage({ id: 'notification.error' }),\n });\n },\n }\n );\n\n return {\n config,\n mutateConfig: putMutation,\n };\n};\n"],"names":["endpoint","pluginId","queryKey","useConfig","trackUsage","useTracking","formatMessage","useIntl","toggleNotification","useNotification","get","put","useFetchClient","config","useQuery","res","data","onError","type","message","id","select","putMutation","useMutation","body","onSuccess","refetch","mutateConfig"],"mappings":";;;;;AAOA,MAAMA,WAAW,CAAC,CAAC,EAAEC,QAAAA,CAAS,cAAc,CAAC;AAC7C,MAAMC,QAAW,GAAA;AAACD,IAAAA,QAAAA;AAAU,IAAA;AAAgB,CAAA;MAE/BE,SAAY,GAAA,IAAA;IACvB,MAAM,EAAEC,UAAU,EAAE,GAAGC,WAAAA,EAAAA;IACvB,MAAM,EAAEC,aAAa,EAAE,GAAGC,OAAAA,EAAAA;IAC1B,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,eAAAA,EAAAA;AAC/B,IAAA,MAAM,EAAEC,GAAG,EAAEC,GAAG,EAAE,GAAGC,cAAAA,EAAAA;IAErB,MAAMC,MAAAA,GAEFC,SACFZ,QACA,EAAA,UAAA;QACE,MAAMa,GAAAA,GAAiC,MAAML,GAAIV,CAAAA,QAAAA,CAAAA;QAEjD,OAAOe,GAAAA,CAAIC,IAAI,CAACA,IAAI;KAEtB,EAAA;AACEC,QAAAA,OAAAA,CAAAA,GAAAA;AACE,YAAA,OAAOT,kBAAmB,CAAA;gBACxBU,IAAM,EAAA,QAAA;AACNC,gBAAAA,OAAAA,EAASb,aAAc,CAAA;oBAAEc,EAAI,EAAA;AAAqB,iBAAA;AACpD,aAAA,CAAA;AACF,SAAA;AACA;;AAEC,UACDC,MAAQ,EAAA,CAACL,IAASA,GAAAA,IAAAA,IAAQ;AAC5B,KAAA,CAAA;IAGF,MAAMM,WAAAA,GAIFC,YACF,OAAOC,IAAAA,GAAAA;AACL,QAAA,MAAMb,IAAkCX,QAAUwB,EAAAA,IAAAA,CAAAA;KAEpD,EAAA;AACEC,QAAAA,SAAAA,CAAAA,GAAAA;YACErB,UAAW,CAAA,2BAAA,CAAA;AACXS,YAAAA,MAAAA,CAAOa,OAAO,EAAA;AAChB,SAAA;AACAT,QAAAA,OAAAA,CAAAA,GAAAA;AACE,YAAA,OAAOT,kBAAmB,CAAA;gBACxBU,IAAM,EAAA,QAAA;AACNC,gBAAAA,OAAAA,EAASb,aAAc,CAAA;oBAAEc,EAAI,EAAA;AAAqB,iBAAA;AACpD,aAAA,CAAA;AACF;AACF,KAAA,CAAA;IAGF,OAAO;AACLP,QAAAA,MAAAA;QACAc,YAAcL,EAAAA;AAChB,KAAA;AACF;;;;"}

View File

@@ -0,0 +1,96 @@
'use strict';
var React = require('react');
var Cropper = require('cropperjs');
function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
const QUALITY = 1;
const useCropImg = ()=>{
const cropperRef = React__namespace.useRef();
const [isCropping, setIsCropping] = React__namespace.useState(false);
const [size, setSize] = React__namespace.useState({
width: undefined,
height: undefined
});
React__namespace.useEffect(()=>{
return ()=>{
if (cropperRef.current) {
cropperRef.current.destroy();
}
};
}, []);
const handleResize = ({ detail: { height, width } })=>{
const roundedDataWidth = Math.round(width);
const roundedDataHeight = Math.round(height);
setSize({
width: roundedDataWidth,
height: roundedDataHeight
});
};
const crop = (image)=>{
if (!cropperRef.current) {
cropperRef.current = new Cropper(image, {
modal: true,
initialAspectRatio: 16 / 9,
movable: true,
zoomable: false,
cropBoxResizable: true,
background: false,
checkCrossOrigin: false,
crop: handleResize
});
setIsCropping(true);
}
};
const stopCropping = ()=>{
if (cropperRef.current) {
cropperRef.current.destroy();
cropperRef.current = undefined;
setIsCropping(false);
}
};
const produceFile = (name, mimeType, lastModifiedDate)=>new Promise((resolve, reject)=>{
if (!cropperRef.current) {
reject(new Error('The cropper has not been instantiated: make sure to call the crop() function before calling produceFile().'));
} else {
const canvas = cropperRef.current.getCroppedCanvas();
canvas.toBlob((blob)=>{
resolve(new File([
blob
], name, {
type: mimeType,
lastModified: new Date(lastModifiedDate).getTime()
}));
}, mimeType, QUALITY);
}
});
return {
crop,
produceFile,
stopCropping,
isCropping,
isCropperReady: Boolean(cropperRef.current),
...size
};
};
exports.useCropImg = useCropImg;
//# sourceMappingURL=useCropImg.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,75 @@
import * as React from 'react';
import Cropper from 'cropperjs';
const QUALITY = 1;
const useCropImg = ()=>{
const cropperRef = React.useRef();
const [isCropping, setIsCropping] = React.useState(false);
const [size, setSize] = React.useState({
width: undefined,
height: undefined
});
React.useEffect(()=>{
return ()=>{
if (cropperRef.current) {
cropperRef.current.destroy();
}
};
}, []);
const handleResize = ({ detail: { height, width } })=>{
const roundedDataWidth = Math.round(width);
const roundedDataHeight = Math.round(height);
setSize({
width: roundedDataWidth,
height: roundedDataHeight
});
};
const crop = (image)=>{
if (!cropperRef.current) {
cropperRef.current = new Cropper(image, {
modal: true,
initialAspectRatio: 16 / 9,
movable: true,
zoomable: false,
cropBoxResizable: true,
background: false,
checkCrossOrigin: false,
crop: handleResize
});
setIsCropping(true);
}
};
const stopCropping = ()=>{
if (cropperRef.current) {
cropperRef.current.destroy();
cropperRef.current = undefined;
setIsCropping(false);
}
};
const produceFile = (name, mimeType, lastModifiedDate)=>new Promise((resolve, reject)=>{
if (!cropperRef.current) {
reject(new Error('The cropper has not been instantiated: make sure to call the crop() function before calling produceFile().'));
} else {
const canvas = cropperRef.current.getCroppedCanvas();
canvas.toBlob((blob)=>{
resolve(new File([
blob
], name, {
type: mimeType,
lastModified: new Date(lastModifiedDate).getTime()
}));
}, mimeType, QUALITY);
}
});
return {
crop,
produceFile,
stopCropping,
isCropping,
isCropperReady: Boolean(cropperRef.current),
...size
};
};
export { useCropImg };
//# sourceMappingURL=useCropImg.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,114 @@
'use strict';
var React = require('react');
var strapiAdmin = require('@strapi/admin/strapi-admin');
var reactIntl = require('react-intl');
var reactQuery = require('react-query');
var pluginId = require('../pluginId.js');
require('byte-size');
require('date-fns');
var getTrad = require('../utils/getTrad.js');
require('qs');
require('../constants.js');
require('../utils/urlYupSchema.js');
function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
const editAssetRequest = (asset, file, signal, onProgress, post)=>{
const endpoint = `/${pluginId.pluginId}?id=${asset.id}`;
const formData = new FormData();
if (file) {
formData.append('files', file);
}
formData.append('fileInfo', JSON.stringify({
alternativeText: asset.alternativeText,
caption: asset.caption,
folder: asset.folder,
name: asset.name
}));
/**
* onProgress is not possible using native fetch
* need to look into an alternative to make it work
* perhaps using xhr like Axios does
*/ return post(endpoint, formData, {
signal
}).then((res)=>res.data);
};
const useEditAsset = ()=>{
const [progress, setProgress] = React__namespace.useState(0);
const { formatMessage } = reactIntl.useIntl();
const { toggleNotification } = strapiAdmin.useNotification();
const queryClient = reactQuery.useQueryClient();
const abortController = new AbortController();
const signal = abortController.signal;
const { post } = strapiAdmin.useFetchClient();
const mutation = reactQuery.useMutation(({ asset, file })=>editAssetRequest(asset, file, signal, setProgress, post), {
onSuccess () {
queryClient.refetchQueries([
pluginId.pluginId,
'assets'
], {
active: true
});
queryClient.refetchQueries([
pluginId.pluginId,
'asset-count'
], {
active: true
});
queryClient.refetchQueries([
pluginId.pluginId,
'folders'
], {
active: true
});
},
onError (reason) {
if (reason?.response?.status === 403) {
toggleNotification({
type: 'info',
message: formatMessage({
id: getTrad.getTrad('permissions.not-allowed.update')
})
});
} else {
toggleNotification({
type: 'danger',
message: reason?.message
});
}
}
});
const editAsset = (asset, file)=>mutation.mutateAsync({
asset,
file
});
const cancel = ()=>abortController.abort();
return {
...mutation,
cancel,
editAsset,
progress,
status: mutation.status
};
};
exports.useEditAsset = useEditAsset;
//# sourceMappingURL=useEditAsset.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,93 @@
import * as React from 'react';
import { useNotification, useFetchClient } from '@strapi/admin/strapi-admin';
import { useIntl } from 'react-intl';
import { useQueryClient, useMutation } from 'react-query';
import { pluginId } from '../pluginId.mjs';
import 'byte-size';
import 'date-fns';
import { getTrad } from '../utils/getTrad.mjs';
import 'qs';
import '../constants.mjs';
import '../utils/urlYupSchema.mjs';
const editAssetRequest = (asset, file, signal, onProgress, post)=>{
const endpoint = `/${pluginId}?id=${asset.id}`;
const formData = new FormData();
if (file) {
formData.append('files', file);
}
formData.append('fileInfo', JSON.stringify({
alternativeText: asset.alternativeText,
caption: asset.caption,
folder: asset.folder,
name: asset.name
}));
/**
* onProgress is not possible using native fetch
* need to look into an alternative to make it work
* perhaps using xhr like Axios does
*/ return post(endpoint, formData, {
signal
}).then((res)=>res.data);
};
const useEditAsset = ()=>{
const [progress, setProgress] = React.useState(0);
const { formatMessage } = useIntl();
const { toggleNotification } = useNotification();
const queryClient = useQueryClient();
const abortController = new AbortController();
const signal = abortController.signal;
const { post } = useFetchClient();
const mutation = useMutation(({ asset, file })=>editAssetRequest(asset, file, signal, setProgress, post), {
onSuccess () {
queryClient.refetchQueries([
pluginId,
'assets'
], {
active: true
});
queryClient.refetchQueries([
pluginId,
'asset-count'
], {
active: true
});
queryClient.refetchQueries([
pluginId,
'folders'
], {
active: true
});
},
onError (reason) {
if (reason?.response?.status === 403) {
toggleNotification({
type: 'info',
message: formatMessage({
id: getTrad('permissions.not-allowed.update')
})
});
} else {
toggleNotification({
type: 'danger',
message: reason?.message
});
}
}
});
const editAsset = (asset, file)=>mutation.mutateAsync({
asset,
file
});
const cancel = ()=>abortController.abort();
return {
...mutation,
cancel,
editAsset,
progress,
status: mutation.status
};
};
export { useEditAsset };
//# sourceMappingURL=useEditAsset.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,44 @@
'use strict';
var strapiAdmin = require('@strapi/admin/strapi-admin');
var reactQuery = require('react-query');
var pluginId = require('../pluginId.js');
const editFolderRequest = (put, post, { attrs, id })=>{
const isEditing = !!id;
const method = isEditing ? put : post;
return method(`/upload/folders/${id ?? ''}`, attrs).then((res)=>res.data);
};
const useEditFolder = ()=>{
const queryClient = reactQuery.useQueryClient();
const { put, post } = strapiAdmin.useFetchClient();
const mutation = reactQuery.useMutation((...args)=>editFolderRequest(put, post, ...args), {
async onSuccess () {
await queryClient.refetchQueries([
pluginId.pluginId,
'folders'
], {
active: true
});
await queryClient.refetchQueries([
pluginId.pluginId,
'folder',
'structure'
], {
active: true
});
}
});
const editFolder = (attrs, id)=>mutation.mutateAsync({
attrs,
id
});
return {
...mutation,
editFolder,
status: mutation.status
};
};
exports.useEditFolder = useEditFolder;
//# sourceMappingURL=useEditFolder.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useEditFolder.js","sources":["../../../admin/src/hooks/useEditFolder.ts"],"sourcesContent":["import { useFetchClient, FetchClient } from '@strapi/admin/strapi-admin';\nimport { useMutation, useQueryClient } from 'react-query';\n\nimport { CreateFolders, UpdateFolder } from '../../../shared/contracts/folders';\nimport { pluginId } from '../pluginId';\n\ninterface EditFolderRequestParams {\n attrs: CreateFolders.Request['body'] | UpdateFolder.Request['body'];\n id?: UpdateFolder.Request['params']['id'];\n}\n\nconst editFolderRequest = (\n put: FetchClient['put'],\n post: FetchClient['post'],\n { attrs, id }: EditFolderRequestParams\n): Promise<UpdateFolder.Response['data'] | CreateFolders.Response['data']> => {\n const isEditing = !!id;\n const method = isEditing ? put : post;\n\n return method(`/upload/folders/${id ?? ''}`, attrs).then((res) => res.data);\n};\n\nexport const useEditFolder = () => {\n const queryClient = useQueryClient();\n const { put, post } = useFetchClient();\n\n const mutation = useMutation<\n UpdateFolder.Response['data'] | CreateFolders.Response['data'],\n UpdateFolder.Response['error'] | CreateFolders.Response['error'],\n EditFolderRequestParams\n >((...args) => editFolderRequest(put, post, ...args), {\n async onSuccess() {\n await queryClient.refetchQueries([pluginId, 'folders'], { active: true });\n await queryClient.refetchQueries([pluginId, 'folder', 'structure'], { active: true });\n },\n });\n\n const editFolder = (\n attrs: EditFolderRequestParams['attrs'],\n id?: EditFolderRequestParams['id']\n ) => mutation.mutateAsync({ attrs, id });\n\n return { ...mutation, editFolder, status: mutation.status };\n};\n"],"names":["editFolderRequest","put","post","attrs","id","isEditing","method","then","res","data","useEditFolder","queryClient","useQueryClient","useFetchClient","mutation","useMutation","args","onSuccess","refetchQueries","pluginId","active","editFolder","mutateAsync","status"],"mappings":";;;;;;AAWA,MAAMA,iBAAAA,GAAoB,CACxBC,GACAC,EAAAA,IAAAA,EACA,EAAEC,KAAK,EAAEC,EAAE,EAA2B,GAAA;IAEtC,MAAMC,SAAAA,GAAY,CAAC,CAACD,EAAAA;IACpB,MAAME,MAAAA,GAASD,YAAYJ,GAAMC,GAAAA,IAAAA;AAEjC,IAAA,OAAOI,MAAO,CAAA,CAAC,gBAAgB,EAAEF,MAAM,EAAG,CAAA,CAAC,EAAED,KAAAA,CAAAA,CAAOI,IAAI,CAAC,CAACC,GAAAA,GAAQA,IAAIC,IAAI,CAAA;AAC5E,CAAA;MAEaC,aAAgB,GAAA,IAAA;AAC3B,IAAA,MAAMC,WAAcC,GAAAA,yBAAAA,EAAAA;AACpB,IAAA,MAAM,EAAEX,GAAG,EAAEC,IAAI,EAAE,GAAGW,0BAAAA,EAAAA;IAEtB,MAAMC,QAAAA,GAAWC,uBAIf,CAAC,GAAGC,OAAShB,iBAAkBC,CAAAA,GAAAA,EAAKC,SAASc,IAAO,CAAA,EAAA;QACpD,MAAMC,SAAAA,CAAAA,GAAAA;YACJ,MAAMN,WAAAA,CAAYO,cAAc,CAAC;AAACC,gBAAAA,iBAAAA;AAAU,gBAAA;aAAU,EAAE;gBAAEC,MAAQ,EAAA;AAAK,aAAA,CAAA;YACvE,MAAMT,WAAAA,CAAYO,cAAc,CAAC;AAACC,gBAAAA,iBAAAA;AAAU,gBAAA,QAAA;AAAU,gBAAA;aAAY,EAAE;gBAAEC,MAAQ,EAAA;AAAK,aAAA,CAAA;AACrF;AACF,KAAA,CAAA;AAEA,IAAA,MAAMC,aAAa,CACjBlB,KAAAA,EACAC,EACGU,GAAAA,QAAAA,CAASQ,WAAW,CAAC;AAAEnB,YAAAA,KAAAA;AAAOC,YAAAA;AAAG,SAAA,CAAA;IAEtC,OAAO;AAAE,QAAA,GAAGU,QAAQ;AAAEO,QAAAA,UAAAA;AAAYE,QAAAA,MAAAA,EAAQT,SAASS;AAAO,KAAA;AAC5D;;;;"}

View File

@@ -0,0 +1,42 @@
import { useFetchClient } from '@strapi/admin/strapi-admin';
import { useQueryClient, useMutation } from 'react-query';
import { pluginId } from '../pluginId.mjs';
const editFolderRequest = (put, post, { attrs, id })=>{
const isEditing = !!id;
const method = isEditing ? put : post;
return method(`/upload/folders/${id ?? ''}`, attrs).then((res)=>res.data);
};
const useEditFolder = ()=>{
const queryClient = useQueryClient();
const { put, post } = useFetchClient();
const mutation = useMutation((...args)=>editFolderRequest(put, post, ...args), {
async onSuccess () {
await queryClient.refetchQueries([
pluginId,
'folders'
], {
active: true
});
await queryClient.refetchQueries([
pluginId,
'folder',
'structure'
], {
active: true
});
}
});
const editFolder = (attrs, id)=>mutation.mutateAsync({
attrs,
id
});
return {
...mutation,
editFolder,
status: mutation.status
};
};
export { useEditFolder };
//# sourceMappingURL=useEditFolder.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useEditFolder.mjs","sources":["../../../admin/src/hooks/useEditFolder.ts"],"sourcesContent":["import { useFetchClient, FetchClient } from '@strapi/admin/strapi-admin';\nimport { useMutation, useQueryClient } from 'react-query';\n\nimport { CreateFolders, UpdateFolder } from '../../../shared/contracts/folders';\nimport { pluginId } from '../pluginId';\n\ninterface EditFolderRequestParams {\n attrs: CreateFolders.Request['body'] | UpdateFolder.Request['body'];\n id?: UpdateFolder.Request['params']['id'];\n}\n\nconst editFolderRequest = (\n put: FetchClient['put'],\n post: FetchClient['post'],\n { attrs, id }: EditFolderRequestParams\n): Promise<UpdateFolder.Response['data'] | CreateFolders.Response['data']> => {\n const isEditing = !!id;\n const method = isEditing ? put : post;\n\n return method(`/upload/folders/${id ?? ''}`, attrs).then((res) => res.data);\n};\n\nexport const useEditFolder = () => {\n const queryClient = useQueryClient();\n const { put, post } = useFetchClient();\n\n const mutation = useMutation<\n UpdateFolder.Response['data'] | CreateFolders.Response['data'],\n UpdateFolder.Response['error'] | CreateFolders.Response['error'],\n EditFolderRequestParams\n >((...args) => editFolderRequest(put, post, ...args), {\n async onSuccess() {\n await queryClient.refetchQueries([pluginId, 'folders'], { active: true });\n await queryClient.refetchQueries([pluginId, 'folder', 'structure'], { active: true });\n },\n });\n\n const editFolder = (\n attrs: EditFolderRequestParams['attrs'],\n id?: EditFolderRequestParams['id']\n ) => mutation.mutateAsync({ attrs, id });\n\n return { ...mutation, editFolder, status: mutation.status };\n};\n"],"names":["editFolderRequest","put","post","attrs","id","isEditing","method","then","res","data","useEditFolder","queryClient","useQueryClient","useFetchClient","mutation","useMutation","args","onSuccess","refetchQueries","pluginId","active","editFolder","mutateAsync","status"],"mappings":";;;;AAWA,MAAMA,iBAAAA,GAAoB,CACxBC,GACAC,EAAAA,IAAAA,EACA,EAAEC,KAAK,EAAEC,EAAE,EAA2B,GAAA;IAEtC,MAAMC,SAAAA,GAAY,CAAC,CAACD,EAAAA;IACpB,MAAME,MAAAA,GAASD,YAAYJ,GAAMC,GAAAA,IAAAA;AAEjC,IAAA,OAAOI,MAAO,CAAA,CAAC,gBAAgB,EAAEF,MAAM,EAAG,CAAA,CAAC,EAAED,KAAAA,CAAAA,CAAOI,IAAI,CAAC,CAACC,GAAAA,GAAQA,IAAIC,IAAI,CAAA;AAC5E,CAAA;MAEaC,aAAgB,GAAA,IAAA;AAC3B,IAAA,MAAMC,WAAcC,GAAAA,cAAAA,EAAAA;AACpB,IAAA,MAAM,EAAEX,GAAG,EAAEC,IAAI,EAAE,GAAGW,cAAAA,EAAAA;IAEtB,MAAMC,QAAAA,GAAWC,YAIf,CAAC,GAAGC,OAAShB,iBAAkBC,CAAAA,GAAAA,EAAKC,SAASc,IAAO,CAAA,EAAA;QACpD,MAAMC,SAAAA,CAAAA,GAAAA;YACJ,MAAMN,WAAAA,CAAYO,cAAc,CAAC;AAACC,gBAAAA,QAAAA;AAAU,gBAAA;aAAU,EAAE;gBAAEC,MAAQ,EAAA;AAAK,aAAA,CAAA;YACvE,MAAMT,WAAAA,CAAYO,cAAc,CAAC;AAACC,gBAAAA,QAAAA;AAAU,gBAAA,QAAA;AAAU,gBAAA;aAAY,EAAE;gBAAEC,MAAQ,EAAA;AAAK,aAAA,CAAA;AACrF;AACF,KAAA,CAAA;AAEA,IAAA,MAAMC,aAAa,CACjBlB,KAAAA,EACAC,EACGU,GAAAA,QAAAA,CAASQ,WAAW,CAAC;AAAEnB,YAAAA,KAAAA;AAAOC,YAAAA;AAAG,SAAA,CAAA;IAEtC,OAAO;AAAE,QAAA,GAAGU,QAAQ;AAAEO,QAAAA,UAAAA;AAAYE,QAAAA,MAAAA,EAAQT,SAASS;AAAO,KAAA;AAC5D;;;;"}

View File

@@ -0,0 +1,58 @@
'use strict';
var strapiAdmin = require('@strapi/admin/strapi-admin');
var reactIntl = require('react-intl');
var reactQuery = require('react-query');
var pluginId = require('../pluginId.js');
require('byte-size');
require('date-fns');
var getTrad = require('../utils/getTrad.js');
require('qs');
require('../constants.js');
require('../utils/urlYupSchema.js');
const useFolder = (id, { enabled = true } = {})=>{
const { toggleNotification } = strapiAdmin.useNotification();
const { get } = strapiAdmin.useFetchClient();
const { formatMessage } = reactIntl.useIntl();
const { data, error, isLoading } = reactQuery.useQuery([
pluginId.pluginId,
'folder',
id
], async ()=>{
const { data: { data } } = await get(`/upload/folders/${id}`, {
params: {
populate: {
parent: {
populate: {
parent: '*'
}
}
}
}
});
return data;
}, {
retry: false,
enabled,
staleTime: 0,
cacheTime: 0,
onError () {
toggleNotification({
type: 'danger',
message: formatMessage({
id: getTrad.getTrad('notification.warning.404'),
defaultMessage: 'Not found'
})
});
}
});
return {
data,
error,
isLoading
};
};
exports.useFolder = useFolder;
//# sourceMappingURL=useFolder.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useFolder.js","sources":["../../../admin/src/hooks/useFolder.ts"],"sourcesContent":["import { useNotification, useFetchClient } from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useQuery } from 'react-query';\n\nimport { GetFolder } from '../../../shared/contracts/folders';\nimport { pluginId } from '../pluginId';\nimport { getTrad } from '../utils';\n\nexport const useFolder = (id: number | null | undefined, { enabled = true } = {}) => {\n const { toggleNotification } = useNotification();\n const { get } = useFetchClient();\n const { formatMessage } = useIntl();\n\n const { data, error, isLoading } = useQuery<\n GetFolder.Response['data'],\n GetFolder.Response['error']\n >(\n [pluginId, 'folder', id],\n async () => {\n const {\n data: { data },\n } = await get(`/upload/folders/${id}`, {\n params: {\n populate: {\n parent: {\n populate: {\n parent: '*',\n },\n },\n },\n },\n });\n\n return data;\n },\n {\n retry: false,\n enabled,\n staleTime: 0,\n cacheTime: 0,\n onError() {\n toggleNotification({\n type: 'danger',\n message: formatMessage({\n id: getTrad('notification.warning.404'),\n defaultMessage: 'Not found',\n }),\n });\n },\n }\n );\n\n return { data, error, isLoading };\n};\n"],"names":["useFolder","id","enabled","toggleNotification","useNotification","get","useFetchClient","formatMessage","useIntl","data","error","isLoading","useQuery","pluginId","params","populate","parent","retry","staleTime","cacheTime","onError","type","message","getTrad","defaultMessage"],"mappings":";;;;;;;;;;;;;AAQO,MAAMA,SAAY,GAAA,CAACC,EAA+B,EAAA,EAAEC,UAAU,IAAI,EAAE,GAAG,EAAE,GAAA;IAC9E,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,2BAAAA,EAAAA;IAC/B,MAAM,EAAEC,GAAG,EAAE,GAAGC,0BAAAA,EAAAA;IAChB,MAAM,EAAEC,aAAa,EAAE,GAAGC,iBAAAA,EAAAA;IAE1B,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAEC,SAAS,EAAE,GAAGC,mBAIjC,CAAA;AAACC,QAAAA,iBAAAA;AAAU,QAAA,QAAA;AAAUZ,QAAAA;KAAG,EACxB,UAAA;AACE,QAAA,MAAM,EACJQ,IAAAA,EAAM,EAAEA,IAAI,EAAE,EACf,GAAG,MAAMJ,GAAAA,CAAI,CAAC,gBAAgB,EAAEJ,EAAAA,CAAG,CAAC,EAAE;YACrCa,MAAQ,EAAA;gBACNC,QAAU,EAAA;oBACRC,MAAQ,EAAA;wBACND,QAAU,EAAA;4BACRC,MAAQ,EAAA;AACV;AACF;AACF;AACF;AACF,SAAA,CAAA;QAEA,OAAOP,IAAAA;KAET,EAAA;QACEQ,KAAO,EAAA,KAAA;AACPf,QAAAA,OAAAA;QACAgB,SAAW,EAAA,CAAA;QACXC,SAAW,EAAA,CAAA;AACXC,QAAAA,OAAAA,CAAAA,GAAAA;YACEjB,kBAAmB,CAAA;gBACjBkB,IAAM,EAAA,QAAA;AACNC,gBAAAA,OAAAA,EAASf,aAAc,CAAA;AACrBN,oBAAAA,EAAAA,EAAIsB,eAAQ,CAAA,0BAAA,CAAA;oBACZC,cAAgB,EAAA;AAClB,iBAAA;AACF,aAAA,CAAA;AACF;AACF,KAAA,CAAA;IAGF,OAAO;AAAEf,QAAAA,IAAAA;AAAMC,QAAAA,KAAAA;AAAOC,QAAAA;AAAU,KAAA;AAClC;;;;"}

View File

@@ -0,0 +1,56 @@
import { useNotification, useFetchClient } from '@strapi/admin/strapi-admin';
import { useIntl } from 'react-intl';
import { useQuery } from 'react-query';
import { pluginId } from '../pluginId.mjs';
import 'byte-size';
import 'date-fns';
import { getTrad } from '../utils/getTrad.mjs';
import 'qs';
import '../constants.mjs';
import '../utils/urlYupSchema.mjs';
const useFolder = (id, { enabled = true } = {})=>{
const { toggleNotification } = useNotification();
const { get } = useFetchClient();
const { formatMessage } = useIntl();
const { data, error, isLoading } = useQuery([
pluginId,
'folder',
id
], async ()=>{
const { data: { data } } = await get(`/upload/folders/${id}`, {
params: {
populate: {
parent: {
populate: {
parent: '*'
}
}
}
}
});
return data;
}, {
retry: false,
enabled,
staleTime: 0,
cacheTime: 0,
onError () {
toggleNotification({
type: 'danger',
message: formatMessage({
id: getTrad('notification.warning.404'),
defaultMessage: 'Not found'
})
});
}
});
return {
data,
error,
isLoading
};
};
export { useFolder };
//# sourceMappingURL=useFolder.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useFolder.mjs","sources":["../../../admin/src/hooks/useFolder.ts"],"sourcesContent":["import { useNotification, useFetchClient } from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useQuery } from 'react-query';\n\nimport { GetFolder } from '../../../shared/contracts/folders';\nimport { pluginId } from '../pluginId';\nimport { getTrad } from '../utils';\n\nexport const useFolder = (id: number | null | undefined, { enabled = true } = {}) => {\n const { toggleNotification } = useNotification();\n const { get } = useFetchClient();\n const { formatMessage } = useIntl();\n\n const { data, error, isLoading } = useQuery<\n GetFolder.Response['data'],\n GetFolder.Response['error']\n >(\n [pluginId, 'folder', id],\n async () => {\n const {\n data: { data },\n } = await get(`/upload/folders/${id}`, {\n params: {\n populate: {\n parent: {\n populate: {\n parent: '*',\n },\n },\n },\n },\n });\n\n return data;\n },\n {\n retry: false,\n enabled,\n staleTime: 0,\n cacheTime: 0,\n onError() {\n toggleNotification({\n type: 'danger',\n message: formatMessage({\n id: getTrad('notification.warning.404'),\n defaultMessage: 'Not found',\n }),\n });\n },\n }\n );\n\n return { data, error, isLoading };\n};\n"],"names":["useFolder","id","enabled","toggleNotification","useNotification","get","useFetchClient","formatMessage","useIntl","data","error","isLoading","useQuery","pluginId","params","populate","parent","retry","staleTime","cacheTime","onError","type","message","getTrad","defaultMessage"],"mappings":";;;;;;;;;;;AAQO,MAAMA,SAAY,GAAA,CAACC,EAA+B,EAAA,EAAEC,UAAU,IAAI,EAAE,GAAG,EAAE,GAAA;IAC9E,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,eAAAA,EAAAA;IAC/B,MAAM,EAAEC,GAAG,EAAE,GAAGC,cAAAA,EAAAA;IAChB,MAAM,EAAEC,aAAa,EAAE,GAAGC,OAAAA,EAAAA;IAE1B,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAEC,SAAS,EAAE,GAAGC,QAIjC,CAAA;AAACC,QAAAA,QAAAA;AAAU,QAAA,QAAA;AAAUZ,QAAAA;KAAG,EACxB,UAAA;AACE,QAAA,MAAM,EACJQ,IAAAA,EAAM,EAAEA,IAAI,EAAE,EACf,GAAG,MAAMJ,GAAAA,CAAI,CAAC,gBAAgB,EAAEJ,EAAAA,CAAG,CAAC,EAAE;YACrCa,MAAQ,EAAA;gBACNC,QAAU,EAAA;oBACRC,MAAQ,EAAA;wBACND,QAAU,EAAA;4BACRC,MAAQ,EAAA;AACV;AACF;AACF;AACF;AACF,SAAA,CAAA;QAEA,OAAOP,IAAAA;KAET,EAAA;QACEQ,KAAO,EAAA,KAAA;AACPf,QAAAA,OAAAA;QACAgB,SAAW,EAAA,CAAA;QACXC,SAAW,EAAA,CAAA;AACXC,QAAAA,OAAAA,CAAAA,GAAAA;YACEjB,kBAAmB,CAAA;gBACjBkB,IAAM,EAAA,QAAA;AACNC,gBAAAA,OAAAA,EAASf,aAAc,CAAA;AACrBN,oBAAAA,EAAAA,EAAIsB,OAAQ,CAAA,0BAAA,CAAA;oBACZC,cAAgB,EAAA;AAClB,iBAAA;AACF,aAAA,CAAA;AACF;AACF,KAAA,CAAA;IAGF,OAAO;AAAEf,QAAAA,IAAAA;AAAMC,QAAAA,KAAAA;AAAOC,QAAAA;AAAU,KAAA;AAClC;;;;"}

View File

@@ -0,0 +1,53 @@
'use strict';
var strapiAdmin = require('@strapi/admin/strapi-admin');
var reactIntl = require('react-intl');
var reactQuery = require('react-query');
var pluginId = require('../pluginId.js');
require('byte-size');
require('date-fns');
var getTrad = require('../utils/getTrad.js');
require('qs');
require('../constants.js');
require('../utils/urlYupSchema.js');
var renameKeys = require('./utils/renameKeys.js');
const FIELD_MAPPING = {
name: 'label',
id: 'value'
};
const useFolderStructure = ({ enabled = true } = {})=>{
const { formatMessage } = reactIntl.useIntl();
const { get } = strapiAdmin.useFetchClient();
const fetchFolderStructure = async ()=>{
const { data: { data } } = await get('/upload/folder-structure');
const children = data.map((f)=>renameKeys.recursiveRenameKeys(f, (key)=>FIELD_MAPPING?.[key] ?? key));
return [
{
value: null,
label: formatMessage({
id: getTrad.getTrad('form.input.label.folder-location-default-label'),
defaultMessage: 'Media Library'
}),
children
}
];
};
const { data, error, isLoading } = reactQuery.useQuery([
pluginId.pluginId,
'folder',
'structure'
], fetchFolderStructure, {
enabled,
staleTime: 0,
cacheTime: 0
});
return {
data,
error,
isLoading
};
};
exports.useFolderStructure = useFolderStructure;
//# sourceMappingURL=useFolderStructure.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useFolderStructure.js","sources":["../../../admin/src/hooks/useFolderStructure.ts"],"sourcesContent":["import { useFetchClient } from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useQuery } from 'react-query';\n\nimport { FolderNode, GetFolderStructure } from '../../../shared/contracts/folders';\nimport { pluginId } from '../pluginId';\nimport { getTrad } from '../utils';\n\nimport { recursiveRenameKeys } from './utils/renameKeys';\n\nconst FIELD_MAPPING: Record<string, string> = {\n name: 'label',\n id: 'value',\n};\n\ninterface FolderNodeWithChildren extends Omit<FolderNode, 'children'> {\n children: FolderNodeWithChildren[];\n label?: string;\n value: string | number | null;\n}\n\nexport const useFolderStructure = ({ enabled = true } = {}) => {\n const { formatMessage } = useIntl();\n const { get } = useFetchClient();\n\n const fetchFolderStructure = async () => {\n const {\n data: { data },\n } = await get<GetFolderStructure.Response['data']>('/upload/folder-structure');\n const children = data.map((f: FolderNodeWithChildren) =>\n recursiveRenameKeys(f, (key) => FIELD_MAPPING?.[key] ?? key)\n );\n\n return [\n {\n value: null,\n label: formatMessage({\n id: getTrad('form.input.label.folder-location-default-label'),\n defaultMessage: 'Media Library',\n }),\n children,\n },\n ];\n };\n\n const { data, error, isLoading } = useQuery(\n [pluginId, 'folder', 'structure'],\n fetchFolderStructure,\n {\n enabled,\n staleTime: 0,\n cacheTime: 0,\n }\n );\n\n return { data, error, isLoading };\n};\n"],"names":["FIELD_MAPPING","name","id","useFolderStructure","enabled","formatMessage","useIntl","get","useFetchClient","fetchFolderStructure","data","children","map","f","recursiveRenameKeys","key","value","label","getTrad","defaultMessage","error","isLoading","useQuery","pluginId","staleTime","cacheTime"],"mappings":";;;;;;;;;;;;;;AAUA,MAAMA,aAAwC,GAAA;IAC5CC,IAAM,EAAA,OAAA;IACNC,EAAI,EAAA;AACN,CAAA;AAQO,MAAMC,qBAAqB,CAAC,EAAEC,UAAU,IAAI,EAAE,GAAG,EAAE,GAAA;IACxD,MAAM,EAAEC,aAAa,EAAE,GAAGC,iBAAAA,EAAAA;IAC1B,MAAM,EAAEC,GAAG,EAAE,GAAGC,0BAAAA,EAAAA;AAEhB,IAAA,MAAMC,oBAAuB,GAAA,UAAA;QAC3B,MAAM,EACJC,MAAM,EAAEA,IAAI,EAAE,EACf,GAAG,MAAMH,GAAyC,CAAA,0BAAA,CAAA;AACnD,QAAA,MAAMI,QAAWD,GAAAA,IAAAA,CAAKE,GAAG,CAAC,CAACC,CAAAA,GACzBC,8BAAoBD,CAAAA,CAAAA,EAAG,CAACE,GAAAA,GAAQf,aAAe,GAACe,IAAI,IAAIA,GAAAA,CAAAA,CAAAA;QAG1D,OAAO;AACL,YAAA;gBACEC,KAAO,EAAA,IAAA;AACPC,gBAAAA,KAAAA,EAAOZ,aAAc,CAAA;AACnBH,oBAAAA,EAAAA,EAAIgB,eAAQ,CAAA,gDAAA,CAAA;oBACZC,cAAgB,EAAA;AAClB,iBAAA,CAAA;AACAR,gBAAAA;AACF;AACD,SAAA;AACH,KAAA;IAEA,MAAM,EAAED,IAAI,EAAEU,KAAK,EAAEC,SAAS,EAAE,GAAGC,mBACjC,CAAA;AAACC,QAAAA,iBAAAA;AAAU,QAAA,QAAA;AAAU,QAAA;AAAY,KAAA,EACjCd,oBACA,EAAA;AACEL,QAAAA,OAAAA;QACAoB,SAAW,EAAA,CAAA;QACXC,SAAW,EAAA;AACb,KAAA,CAAA;IAGF,OAAO;AAAEf,QAAAA,IAAAA;AAAMU,QAAAA,KAAAA;AAAOC,QAAAA;AAAU,KAAA;AAClC;;;;"}

View File

@@ -0,0 +1,51 @@
import { useFetchClient } from '@strapi/admin/strapi-admin';
import { useIntl } from 'react-intl';
import { useQuery } from 'react-query';
import { pluginId } from '../pluginId.mjs';
import 'byte-size';
import 'date-fns';
import { getTrad } from '../utils/getTrad.mjs';
import 'qs';
import '../constants.mjs';
import '../utils/urlYupSchema.mjs';
import { recursiveRenameKeys } from './utils/renameKeys.mjs';
const FIELD_MAPPING = {
name: 'label',
id: 'value'
};
const useFolderStructure = ({ enabled = true } = {})=>{
const { formatMessage } = useIntl();
const { get } = useFetchClient();
const fetchFolderStructure = async ()=>{
const { data: { data } } = await get('/upload/folder-structure');
const children = data.map((f)=>recursiveRenameKeys(f, (key)=>FIELD_MAPPING?.[key] ?? key));
return [
{
value: null,
label: formatMessage({
id: getTrad('form.input.label.folder-location-default-label'),
defaultMessage: 'Media Library'
}),
children
}
];
};
const { data, error, isLoading } = useQuery([
pluginId,
'folder',
'structure'
], fetchFolderStructure, {
enabled,
staleTime: 0,
cacheTime: 0
});
return {
data,
error,
isLoading
};
};
export { useFolderStructure };
//# sourceMappingURL=useFolderStructure.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useFolderStructure.mjs","sources":["../../../admin/src/hooks/useFolderStructure.ts"],"sourcesContent":["import { useFetchClient } from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useQuery } from 'react-query';\n\nimport { FolderNode, GetFolderStructure } from '../../../shared/contracts/folders';\nimport { pluginId } from '../pluginId';\nimport { getTrad } from '../utils';\n\nimport { recursiveRenameKeys } from './utils/renameKeys';\n\nconst FIELD_MAPPING: Record<string, string> = {\n name: 'label',\n id: 'value',\n};\n\ninterface FolderNodeWithChildren extends Omit<FolderNode, 'children'> {\n children: FolderNodeWithChildren[];\n label?: string;\n value: string | number | null;\n}\n\nexport const useFolderStructure = ({ enabled = true } = {}) => {\n const { formatMessage } = useIntl();\n const { get } = useFetchClient();\n\n const fetchFolderStructure = async () => {\n const {\n data: { data },\n } = await get<GetFolderStructure.Response['data']>('/upload/folder-structure');\n const children = data.map((f: FolderNodeWithChildren) =>\n recursiveRenameKeys(f, (key) => FIELD_MAPPING?.[key] ?? key)\n );\n\n return [\n {\n value: null,\n label: formatMessage({\n id: getTrad('form.input.label.folder-location-default-label'),\n defaultMessage: 'Media Library',\n }),\n children,\n },\n ];\n };\n\n const { data, error, isLoading } = useQuery(\n [pluginId, 'folder', 'structure'],\n fetchFolderStructure,\n {\n enabled,\n staleTime: 0,\n cacheTime: 0,\n }\n );\n\n return { data, error, isLoading };\n};\n"],"names":["FIELD_MAPPING","name","id","useFolderStructure","enabled","formatMessage","useIntl","get","useFetchClient","fetchFolderStructure","data","children","map","f","recursiveRenameKeys","key","value","label","getTrad","defaultMessage","error","isLoading","useQuery","pluginId","staleTime","cacheTime"],"mappings":";;;;;;;;;;;;AAUA,MAAMA,aAAwC,GAAA;IAC5CC,IAAM,EAAA,OAAA;IACNC,EAAI,EAAA;AACN,CAAA;AAQO,MAAMC,qBAAqB,CAAC,EAAEC,UAAU,IAAI,EAAE,GAAG,EAAE,GAAA;IACxD,MAAM,EAAEC,aAAa,EAAE,GAAGC,OAAAA,EAAAA;IAC1B,MAAM,EAAEC,GAAG,EAAE,GAAGC,cAAAA,EAAAA;AAEhB,IAAA,MAAMC,oBAAuB,GAAA,UAAA;QAC3B,MAAM,EACJC,MAAM,EAAEA,IAAI,EAAE,EACf,GAAG,MAAMH,GAAyC,CAAA,0BAAA,CAAA;AACnD,QAAA,MAAMI,QAAWD,GAAAA,IAAAA,CAAKE,GAAG,CAAC,CAACC,CAAAA,GACzBC,mBAAoBD,CAAAA,CAAAA,EAAG,CAACE,GAAAA,GAAQf,aAAe,GAACe,IAAI,IAAIA,GAAAA,CAAAA,CAAAA;QAG1D,OAAO;AACL,YAAA;gBACEC,KAAO,EAAA,IAAA;AACPC,gBAAAA,KAAAA,EAAOZ,aAAc,CAAA;AACnBH,oBAAAA,EAAAA,EAAIgB,OAAQ,CAAA,gDAAA,CAAA;oBACZC,cAAgB,EAAA;AAClB,iBAAA,CAAA;AACAR,gBAAAA;AACF;AACD,SAAA;AACH,KAAA;IAEA,MAAM,EAAED,IAAI,EAAEU,KAAK,EAAEC,SAAS,EAAE,GAAGC,QACjC,CAAA;AAACC,QAAAA,QAAAA;AAAU,QAAA,QAAA;AAAU,QAAA;AAAY,KAAA,EACjCd,oBACA,EAAA;AACEL,QAAAA,OAAAA;QACAoB,SAAW,EAAA,CAAA;QACXC,SAAW,EAAA;AACb,KAAA,CAAA;IAGF,OAAO;AAAEf,QAAAA,IAAAA;AAAMU,QAAAA,KAAAA;AAAOC,QAAAA;AAAU,KAAA;AAClC;;;;"}

View File

@@ -0,0 +1,107 @@
'use strict';
var React = require('react');
var strapiAdmin = require('@strapi/admin/strapi-admin');
var designSystem = require('@strapi/design-system');
var qs = require('qs');
var reactIntl = require('react-intl');
var reactQuery = require('react-query');
var pluginId = require('../pluginId.js');
function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
const useFolders = ({ enabled = true, query = {} } = {})=>{
const { formatMessage } = reactIntl.useIntl();
const { toggleNotification } = strapiAdmin.useNotification();
const { notifyStatus } = designSystem.useNotifyAT();
const { folder, _q, ...paramsExceptFolderAndQ } = query;
const { get } = strapiAdmin.useFetchClient();
let params;
if (_q) {
params = {
...paramsExceptFolderAndQ,
pagination: {
pageSize: -1
},
_q
};
} else {
params = {
...paramsExceptFolderAndQ,
pagination: {
pageSize: -1
},
filters: {
$and: [
...paramsExceptFolderAndQ?.filters?.$and ?? [],
{
parent: {
id: folder ?? {
$null: true
}
}
}
]
}
};
}
const { data, error, isLoading } = reactQuery.useQuery([
pluginId.pluginId,
'folders',
qs.stringify(params)
], async ()=>{
const { data: { data } } = await get('/upload/folders', {
params
});
return data;
}, {
enabled,
staleTime: 0,
cacheTime: 0,
onError () {
toggleNotification({
type: 'danger',
message: formatMessage({
id: 'notification.error'
})
});
}
});
React__namespace.useEffect(()=>{
if (data) {
notifyStatus(formatMessage({
id: 'list.asset.at.finished',
defaultMessage: 'The folders have finished loading.'
}));
}
}, [
data,
formatMessage,
notifyStatus
]);
return {
data,
error,
isLoading
};
};
exports.useFolders = useFolders;
//# sourceMappingURL=useFolders.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useFolders.js","sources":["../../../admin/src/hooks/useFolders.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { useNotification, useFetchClient } from '@strapi/admin/strapi-admin';\nimport { useNotifyAT } from '@strapi/design-system';\nimport { stringify } from 'qs';\nimport { useIntl } from 'react-intl';\nimport { useQuery } from 'react-query';\n\nimport { GetFolders } from '../../../shared/contracts/folders';\nimport { pluginId } from '../pluginId';\n\nimport type { Query } from '../../../shared/contracts/files';\n\ninterface UseFoldersOptions {\n enabled?: boolean;\n query?: Query;\n}\n\nexport const useFolders = ({ enabled = true, query = {} }: UseFoldersOptions = {}) => {\n const { formatMessage } = useIntl();\n const { toggleNotification } = useNotification();\n const { notifyStatus } = useNotifyAT();\n const { folder, _q, ...paramsExceptFolderAndQ } = query;\n const { get } = useFetchClient();\n\n let params: Query;\n\n if (_q) {\n params = {\n ...paramsExceptFolderAndQ,\n pagination: {\n pageSize: -1,\n },\n _q,\n };\n } else {\n params = {\n ...paramsExceptFolderAndQ,\n pagination: {\n pageSize: -1,\n },\n filters: {\n $and: [\n ...(paramsExceptFolderAndQ?.filters?.$and ?? []),\n {\n parent: {\n id: folder ?? {\n $null: true,\n },\n },\n },\n ],\n },\n };\n }\n\n const { data, error, isLoading } = useQuery<\n GetFolders.Response['data'],\n GetFolders.Response['error']\n >(\n [pluginId, 'folders', stringify(params)],\n async () => {\n const {\n data: { data },\n } = await get<GetFolders.Response>('/upload/folders', { params });\n\n return data;\n },\n {\n enabled,\n staleTime: 0,\n cacheTime: 0,\n onError() {\n toggleNotification({\n type: 'danger',\n message: formatMessage({ id: 'notification.error' }),\n });\n },\n }\n );\n\n React.useEffect(() => {\n if (data) {\n notifyStatus(\n formatMessage({\n id: 'list.asset.at.finished',\n defaultMessage: 'The folders have finished loading.',\n })\n );\n }\n }, [data, formatMessage, notifyStatus]);\n\n return { data, error, isLoading };\n};\n"],"names":["useFolders","enabled","query","formatMessage","useIntl","toggleNotification","useNotification","notifyStatus","useNotifyAT","folder","_q","paramsExceptFolderAndQ","get","useFetchClient","params","pagination","pageSize","filters","$and","parent","id","$null","data","error","isLoading","useQuery","pluginId","stringify","staleTime","cacheTime","onError","type","message","React","useEffect","defaultMessage"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBaA,MAAAA,UAAAA,GAAa,CAAC,EAAEC,OAAU,GAAA,IAAI,EAAEC,KAAAA,GAAQ,EAAE,EAAqB,GAAG,EAAE,GAAA;IAC/E,MAAM,EAAEC,aAAa,EAAE,GAAGC,iBAAAA,EAAAA;IAC1B,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,2BAAAA,EAAAA;IAC/B,MAAM,EAAEC,YAAY,EAAE,GAAGC,wBAAAA,EAAAA;AACzB,IAAA,MAAM,EAAEC,MAAM,EAAEC,EAAE,EAAE,GAAGC,wBAAwB,GAAGT,KAAAA;IAClD,MAAM,EAAEU,GAAG,EAAE,GAAGC,0BAAAA,EAAAA;IAEhB,IAAIC,MAAAA;AAEJ,IAAA,IAAIJ,EAAI,EAAA;QACNI,MAAS,GAAA;AACP,YAAA,GAAGH,sBAAsB;YACzBI,UAAY,EAAA;AACVC,gBAAAA,QAAAA,EAAU,CAAC;AACb,aAAA;AACAN,YAAAA;AACF,SAAA;KACK,MAAA;QACLI,MAAS,GAAA;AACP,YAAA,GAAGH,sBAAsB;YACzBI,UAAY,EAAA;AACVC,gBAAAA,QAAAA,EAAU,CAAC;AACb,aAAA;YACAC,OAAS,EAAA;gBACPC,IAAM,EAAA;uBACAP,sBAAwBM,EAAAA,OAAAA,EAASC,QAAQ,EAAE;AAC/C,oBAAA;wBACEC,MAAQ,EAAA;AACNC,4BAAAA,EAAAA,EAAIX,MAAU,IAAA;gCACZY,KAAO,EAAA;AACT;AACF;AACF;AACD;AACH;AACF,SAAA;AACF;IAEA,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAEC,SAAS,EAAE,GAAGC,mBAIjC,CAAA;AAACC,QAAAA,iBAAAA;AAAU,QAAA,SAAA;QAAWC,YAAUb,CAAAA,MAAAA;KAAQ,EACxC,UAAA;QACE,MAAM,EACJQ,MAAM,EAAEA,IAAI,EAAE,EACf,GAAG,MAAMV,GAAAA,CAAyB,iBAAmB,EAAA;AAAEE,YAAAA;AAAO,SAAA,CAAA;QAE/D,OAAOQ,IAAAA;KAET,EAAA;AACErB,QAAAA,OAAAA;QACA2B,SAAW,EAAA,CAAA;QACXC,SAAW,EAAA,CAAA;AACXC,QAAAA,OAAAA,CAAAA,GAAAA;YACEzB,kBAAmB,CAAA;gBACjB0B,IAAM,EAAA,QAAA;AACNC,gBAAAA,OAAAA,EAAS7B,aAAc,CAAA;oBAAEiB,EAAI,EAAA;AAAqB,iBAAA;AACpD,aAAA,CAAA;AACF;AACF,KAAA,CAAA;AAGFa,IAAAA,gBAAAA,CAAMC,SAAS,CAAC,IAAA;AACd,QAAA,IAAIZ,IAAM,EAAA;AACRf,YAAAA,YAAAA,CACEJ,aAAc,CAAA;gBACZiB,EAAI,EAAA,wBAAA;gBACJe,cAAgB,EAAA;AAClB,aAAA,CAAA,CAAA;AAEJ;KACC,EAAA;AAACb,QAAAA,IAAAA;AAAMnB,QAAAA,aAAAA;AAAeI,QAAAA;AAAa,KAAA,CAAA;IAEtC,OAAO;AAAEe,QAAAA,IAAAA;AAAMC,QAAAA,KAAAA;AAAOC,QAAAA;AAAU,KAAA;AAClC;;;;"}

View File

@@ -0,0 +1,86 @@
import * as React from 'react';
import { useNotification, useFetchClient } from '@strapi/admin/strapi-admin';
import { useNotifyAT } from '@strapi/design-system';
import { stringify } from 'qs';
import { useIntl } from 'react-intl';
import { useQuery } from 'react-query';
import { pluginId } from '../pluginId.mjs';
const useFolders = ({ enabled = true, query = {} } = {})=>{
const { formatMessage } = useIntl();
const { toggleNotification } = useNotification();
const { notifyStatus } = useNotifyAT();
const { folder, _q, ...paramsExceptFolderAndQ } = query;
const { get } = useFetchClient();
let params;
if (_q) {
params = {
...paramsExceptFolderAndQ,
pagination: {
pageSize: -1
},
_q
};
} else {
params = {
...paramsExceptFolderAndQ,
pagination: {
pageSize: -1
},
filters: {
$and: [
...paramsExceptFolderAndQ?.filters?.$and ?? [],
{
parent: {
id: folder ?? {
$null: true
}
}
}
]
}
};
}
const { data, error, isLoading } = useQuery([
pluginId,
'folders',
stringify(params)
], async ()=>{
const { data: { data } } = await get('/upload/folders', {
params
});
return data;
}, {
enabled,
staleTime: 0,
cacheTime: 0,
onError () {
toggleNotification({
type: 'danger',
message: formatMessage({
id: 'notification.error'
})
});
}
});
React.useEffect(()=>{
if (data) {
notifyStatus(formatMessage({
id: 'list.asset.at.finished',
defaultMessage: 'The folders have finished loading.'
}));
}
}, [
data,
formatMessage,
notifyStatus
]);
return {
data,
error,
isLoading
};
};
export { useFolders };
//# sourceMappingURL=useFolders.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useFolders.mjs","sources":["../../../admin/src/hooks/useFolders.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { useNotification, useFetchClient } from '@strapi/admin/strapi-admin';\nimport { useNotifyAT } from '@strapi/design-system';\nimport { stringify } from 'qs';\nimport { useIntl } from 'react-intl';\nimport { useQuery } from 'react-query';\n\nimport { GetFolders } from '../../../shared/contracts/folders';\nimport { pluginId } from '../pluginId';\n\nimport type { Query } from '../../../shared/contracts/files';\n\ninterface UseFoldersOptions {\n enabled?: boolean;\n query?: Query;\n}\n\nexport const useFolders = ({ enabled = true, query = {} }: UseFoldersOptions = {}) => {\n const { formatMessage } = useIntl();\n const { toggleNotification } = useNotification();\n const { notifyStatus } = useNotifyAT();\n const { folder, _q, ...paramsExceptFolderAndQ } = query;\n const { get } = useFetchClient();\n\n let params: Query;\n\n if (_q) {\n params = {\n ...paramsExceptFolderAndQ,\n pagination: {\n pageSize: -1,\n },\n _q,\n };\n } else {\n params = {\n ...paramsExceptFolderAndQ,\n pagination: {\n pageSize: -1,\n },\n filters: {\n $and: [\n ...(paramsExceptFolderAndQ?.filters?.$and ?? []),\n {\n parent: {\n id: folder ?? {\n $null: true,\n },\n },\n },\n ],\n },\n };\n }\n\n const { data, error, isLoading } = useQuery<\n GetFolders.Response['data'],\n GetFolders.Response['error']\n >(\n [pluginId, 'folders', stringify(params)],\n async () => {\n const {\n data: { data },\n } = await get<GetFolders.Response>('/upload/folders', { params });\n\n return data;\n },\n {\n enabled,\n staleTime: 0,\n cacheTime: 0,\n onError() {\n toggleNotification({\n type: 'danger',\n message: formatMessage({ id: 'notification.error' }),\n });\n },\n }\n );\n\n React.useEffect(() => {\n if (data) {\n notifyStatus(\n formatMessage({\n id: 'list.asset.at.finished',\n defaultMessage: 'The folders have finished loading.',\n })\n );\n }\n }, [data, formatMessage, notifyStatus]);\n\n return { data, error, isLoading };\n};\n"],"names":["useFolders","enabled","query","formatMessage","useIntl","toggleNotification","useNotification","notifyStatus","useNotifyAT","folder","_q","paramsExceptFolderAndQ","get","useFetchClient","params","pagination","pageSize","filters","$and","parent","id","$null","data","error","isLoading","useQuery","pluginId","stringify","staleTime","cacheTime","onError","type","message","React","useEffect","defaultMessage"],"mappings":";;;;;;;;AAkBaA,MAAAA,UAAAA,GAAa,CAAC,EAAEC,OAAU,GAAA,IAAI,EAAEC,KAAAA,GAAQ,EAAE,EAAqB,GAAG,EAAE,GAAA;IAC/E,MAAM,EAAEC,aAAa,EAAE,GAAGC,OAAAA,EAAAA;IAC1B,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,eAAAA,EAAAA;IAC/B,MAAM,EAAEC,YAAY,EAAE,GAAGC,WAAAA,EAAAA;AACzB,IAAA,MAAM,EAAEC,MAAM,EAAEC,EAAE,EAAE,GAAGC,wBAAwB,GAAGT,KAAAA;IAClD,MAAM,EAAEU,GAAG,EAAE,GAAGC,cAAAA,EAAAA;IAEhB,IAAIC,MAAAA;AAEJ,IAAA,IAAIJ,EAAI,EAAA;QACNI,MAAS,GAAA;AACP,YAAA,GAAGH,sBAAsB;YACzBI,UAAY,EAAA;AACVC,gBAAAA,QAAAA,EAAU,CAAC;AACb,aAAA;AACAN,YAAAA;AACF,SAAA;KACK,MAAA;QACLI,MAAS,GAAA;AACP,YAAA,GAAGH,sBAAsB;YACzBI,UAAY,EAAA;AACVC,gBAAAA,QAAAA,EAAU,CAAC;AACb,aAAA;YACAC,OAAS,EAAA;gBACPC,IAAM,EAAA;uBACAP,sBAAwBM,EAAAA,OAAAA,EAASC,QAAQ,EAAE;AAC/C,oBAAA;wBACEC,MAAQ,EAAA;AACNC,4BAAAA,EAAAA,EAAIX,MAAU,IAAA;gCACZY,KAAO,EAAA;AACT;AACF;AACF;AACD;AACH;AACF,SAAA;AACF;IAEA,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAEC,SAAS,EAAE,GAAGC,QAIjC,CAAA;AAACC,QAAAA,QAAAA;AAAU,QAAA,SAAA;QAAWC,SAAUb,CAAAA,MAAAA;KAAQ,EACxC,UAAA;QACE,MAAM,EACJQ,MAAM,EAAEA,IAAI,EAAE,EACf,GAAG,MAAMV,GAAAA,CAAyB,iBAAmB,EAAA;AAAEE,YAAAA;AAAO,SAAA,CAAA;QAE/D,OAAOQ,IAAAA;KAET,EAAA;AACErB,QAAAA,OAAAA;QACA2B,SAAW,EAAA,CAAA;QACXC,SAAW,EAAA,CAAA;AACXC,QAAAA,OAAAA,CAAAA,GAAAA;YACEzB,kBAAmB,CAAA;gBACjB0B,IAAM,EAAA,QAAA;AACNC,gBAAAA,OAAAA,EAAS7B,aAAc,CAAA;oBAAEiB,EAAI,EAAA;AAAqB,iBAAA;AACpD,aAAA,CAAA;AACF;AACF,KAAA,CAAA;AAGFa,IAAAA,KAAAA,CAAMC,SAAS,CAAC,IAAA;AACd,QAAA,IAAIZ,IAAM,EAAA;AACRf,YAAAA,YAAAA,CACEJ,aAAc,CAAA;gBACZiB,EAAI,EAAA,wBAAA;gBACJe,cAAgB,EAAA;AAClB,aAAA,CAAA,CAAA;AAEJ;KACC,EAAA;AAACb,QAAAA,IAAAA;AAAMnB,QAAAA,aAAAA;AAAeI,QAAAA;AAAa,KAAA,CAAA;IAEtC,OAAO;AAAEe,QAAAA,IAAAA;AAAMC,QAAAA,KAAAA;AAAOC,QAAAA;AAAU,KAAA;AAClC;;;;"}

View File

@@ -0,0 +1,16 @@
'use strict';
var strapiAdmin = require('@strapi/admin/strapi-admin');
var constants = require('../constants.js');
const { main: _main, ...restPermissions } = constants.PERMISSIONS;
const useMediaLibraryPermissions = ()=>{
const { allowedActions, isLoading } = strapiAdmin.useRBAC(restPermissions);
return {
...allowedActions,
isLoading
};
};
exports.useMediaLibraryPermissions = useMediaLibraryPermissions;
//# sourceMappingURL=useMediaLibraryPermissions.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useMediaLibraryPermissions.js","sources":["../../../admin/src/hooks/useMediaLibraryPermissions.ts"],"sourcesContent":["import { useRBAC, type AllowedActions } from '@strapi/admin/strapi-admin';\n\nimport { PERMISSIONS } from '../constants';\n\nconst { main: _main, ...restPermissions } = PERMISSIONS;\n\nexport const useMediaLibraryPermissions = (): AllowedActions & { isLoading: boolean } => {\n const { allowedActions, isLoading } = useRBAC(restPermissions);\n\n return { ...allowedActions, isLoading };\n};\n"],"names":["main","_main","restPermissions","PERMISSIONS","useMediaLibraryPermissions","allowedActions","isLoading","useRBAC"],"mappings":";;;;;AAIA,MAAM,EAAEA,IAAMC,EAAAA,KAAK,EAAE,GAAGC,iBAAiB,GAAGC,qBAAAA;MAE/BC,0BAA6B,GAAA,IAAA;AACxC,IAAA,MAAM,EAAEC,cAAc,EAAEC,SAAS,EAAE,GAAGC,mBAAQL,CAAAA,eAAAA,CAAAA;IAE9C,OAAO;AAAE,QAAA,GAAGG,cAAc;AAAEC,QAAAA;AAAU,KAAA;AACxC;;;;"}

View File

@@ -0,0 +1,14 @@
import { useRBAC } from '@strapi/admin/strapi-admin';
import { PERMISSIONS } from '../constants.mjs';
const { main: _main, ...restPermissions } = PERMISSIONS;
const useMediaLibraryPermissions = ()=>{
const { allowedActions, isLoading } = useRBAC(restPermissions);
return {
...allowedActions,
isLoading
};
};
export { useMediaLibraryPermissions };
//# sourceMappingURL=useMediaLibraryPermissions.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useMediaLibraryPermissions.mjs","sources":["../../../admin/src/hooks/useMediaLibraryPermissions.ts"],"sourcesContent":["import { useRBAC, type AllowedActions } from '@strapi/admin/strapi-admin';\n\nimport { PERMISSIONS } from '../constants';\n\nconst { main: _main, ...restPermissions } = PERMISSIONS;\n\nexport const useMediaLibraryPermissions = (): AllowedActions & { isLoading: boolean } => {\n const { allowedActions, isLoading } = useRBAC(restPermissions);\n\n return { ...allowedActions, isLoading };\n};\n"],"names":["main","_main","restPermissions","PERMISSIONS","useMediaLibraryPermissions","allowedActions","isLoading","useRBAC"],"mappings":";;;AAIA,MAAM,EAAEA,IAAMC,EAAAA,KAAK,EAAE,GAAGC,iBAAiB,GAAGC,WAAAA;MAE/BC,0BAA6B,GAAA,IAAA;AACxC,IAAA,MAAM,EAAEC,cAAc,EAAEC,SAAS,EAAE,GAAGC,OAAQL,CAAAA,eAAAA,CAAAA;IAE9C,OAAO;AAAE,QAAA,GAAGG,cAAc;AAAEC,QAAAA;AAAU,KAAA;AACxC;;;;"}

View File

@@ -0,0 +1,138 @@
'use strict';
var React = require('react');
var strapiAdmin = require('@strapi/admin/strapi-admin');
var qs = require('qs');
var useConfig = require('./useConfig.js');
function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
const useModalQueryParams = (initialState)=>{
const { trackUsage } = strapiAdmin.useTracking();
const { config: { data: config } } = useConfig.useConfig();
const [queryObject, setQueryObject] = React__namespace.useState({
page: 1,
sort: 'updatedAt:DESC',
pageSize: 10,
filters: {
$and: []
},
...initialState
});
React__namespace.useEffect(()=>{
if (config && 'sort' in config && 'pageSize' in config) {
setQueryObject((prevQuery)=>({
...prevQuery,
sort: config.sort,
pageSize: config.pageSize
}));
}
}, [
config
]);
const handleChangeFilters = (nextFilters)=>{
if (nextFilters) {
trackUsage('didFilterMediaLibraryElements', {
location: 'content-manager',
filter: Object.keys(nextFilters[nextFilters.length - 1])[0]
});
setQueryObject((prev)=>({
...prev,
page: 1,
filters: {
$and: nextFilters
}
}));
}
};
const handleChangePageSize = (pageSize)=>{
setQueryObject((prev)=>({
...prev,
pageSize: typeof pageSize === 'string' ? parseInt(pageSize, 10) : pageSize,
page: 1
}));
};
const handeChangePage = (page)=>{
setQueryObject((prev)=>({
...prev,
page
}));
};
const handleChangeSort = (sort)=>{
if (sort) {
trackUsage('didSortMediaLibraryElements', {
location: 'content-manager',
sort
});
setQueryObject((prev)=>({
...prev,
sort
}));
}
};
const handleChangeSearch = (_q)=>{
if (_q) {
setQueryObject((prev)=>({
...prev,
_q,
page: 1
}));
} else {
const newState = {
page: 1
};
Object.keys(queryObject).forEach((key)=>{
if (![
'page',
'_q'
].includes(key)) {
newState[key] = queryObject[key];
}
});
setQueryObject(newState);
}
};
const handleChangeFolder = (folder, folderPath)=>{
setQueryObject((prev)=>({
...prev,
folder: folder ?? null,
folderPath
}));
};
return [
{
queryObject,
rawQuery: qs.stringify(queryObject, {
encode: false
})
},
{
onChangeFilters: handleChangeFilters,
onChangeFolder: handleChangeFolder,
onChangePage: handeChangePage,
onChangePageSize: handleChangePageSize,
onChangeSort: handleChangeSort,
onChangeSearch: handleChangeSearch
}
];
};
exports.useModalQueryParams = useModalQueryParams;
//# sourceMappingURL=useModalQueryParams.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,117 @@
import * as React from 'react';
import { useTracking } from '@strapi/admin/strapi-admin';
import { stringify } from 'qs';
import { useConfig } from './useConfig.mjs';
const useModalQueryParams = (initialState)=>{
const { trackUsage } = useTracking();
const { config: { data: config } } = useConfig();
const [queryObject, setQueryObject] = React.useState({
page: 1,
sort: 'updatedAt:DESC',
pageSize: 10,
filters: {
$and: []
},
...initialState
});
React.useEffect(()=>{
if (config && 'sort' in config && 'pageSize' in config) {
setQueryObject((prevQuery)=>({
...prevQuery,
sort: config.sort,
pageSize: config.pageSize
}));
}
}, [
config
]);
const handleChangeFilters = (nextFilters)=>{
if (nextFilters) {
trackUsage('didFilterMediaLibraryElements', {
location: 'content-manager',
filter: Object.keys(nextFilters[nextFilters.length - 1])[0]
});
setQueryObject((prev)=>({
...prev,
page: 1,
filters: {
$and: nextFilters
}
}));
}
};
const handleChangePageSize = (pageSize)=>{
setQueryObject((prev)=>({
...prev,
pageSize: typeof pageSize === 'string' ? parseInt(pageSize, 10) : pageSize,
page: 1
}));
};
const handeChangePage = (page)=>{
setQueryObject((prev)=>({
...prev,
page
}));
};
const handleChangeSort = (sort)=>{
if (sort) {
trackUsage('didSortMediaLibraryElements', {
location: 'content-manager',
sort
});
setQueryObject((prev)=>({
...prev,
sort
}));
}
};
const handleChangeSearch = (_q)=>{
if (_q) {
setQueryObject((prev)=>({
...prev,
_q,
page: 1
}));
} else {
const newState = {
page: 1
};
Object.keys(queryObject).forEach((key)=>{
if (![
'page',
'_q'
].includes(key)) {
newState[key] = queryObject[key];
}
});
setQueryObject(newState);
}
};
const handleChangeFolder = (folder, folderPath)=>{
setQueryObject((prev)=>({
...prev,
folder: folder ?? null,
folderPath
}));
};
return [
{
queryObject,
rawQuery: stringify(queryObject, {
encode: false
})
},
{
onChangeFilters: handleChangeFilters,
onChangeFolder: handleChangeFolder,
onChangePage: handeChangePage,
onChangePageSize: handleChangePageSize,
onChangeSort: handleChangeSort,
onChangeSearch: handleChangeSearch
}
];
};
export { useModalQueryParams };
//# sourceMappingURL=useModalQueryParams.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,31 @@
'use strict';
var React = require('react');
const usePersistentState = (key, defaultValue)=>{
const [value, setValue] = React.useState(()=>{
const stickyValue = window.localStorage.getItem(key);
if (stickyValue !== null) {
try {
return JSON.parse(stickyValue);
} catch {
// JSON.parse fails when the stored value is a primitive
return stickyValue;
}
}
return defaultValue;
});
React.useEffect(()=>{
window.localStorage.setItem(key, JSON.stringify(value));
}, [
key,
value
]);
return [
value,
setValue
];
};
exports.usePersistentState = usePersistentState;
//# sourceMappingURL=usePersistentState.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"usePersistentState.js","sources":["../../../admin/src/hooks/usePersistentState.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nconst usePersistentState = <T>(key: string, defaultValue: T) => {\n const [value, setValue] = useState<T>(() => {\n const stickyValue = window.localStorage.getItem(key);\n\n if (stickyValue !== null) {\n try {\n return JSON.parse(stickyValue);\n } catch {\n // JSON.parse fails when the stored value is a primitive\n return stickyValue;\n }\n }\n\n return defaultValue;\n });\n\n useEffect(() => {\n window.localStorage.setItem(key, JSON.stringify(value));\n }, [key, value]);\n\n return [value, setValue] as const;\n};\n\nexport { usePersistentState };\n"],"names":["usePersistentState","key","defaultValue","value","setValue","useState","stickyValue","window","localStorage","getItem","JSON","parse","useEffect","setItem","stringify"],"mappings":";;;;AAEMA,MAAAA,kBAAAA,GAAqB,CAAIC,GAAaC,EAAAA,YAAAA,GAAAA;AAC1C,IAAA,MAAM,CAACC,KAAAA,EAAOC,QAAS,CAAA,GAAGC,cAAY,CAAA,IAAA;AACpC,QAAA,MAAMC,WAAcC,GAAAA,MAAAA,CAAOC,YAAY,CAACC,OAAO,CAACR,GAAAA,CAAAA;AAEhD,QAAA,IAAIK,gBAAgB,IAAM,EAAA;YACxB,IAAI;gBACF,OAAOI,IAAAA,CAAKC,KAAK,CAACL,WAAAA,CAAAA;AACpB,aAAA,CAAE,OAAM;;gBAEN,OAAOA,WAAAA;AACT;AACF;QAEA,OAAOJ,YAAAA;AACT,KAAA,CAAA;IAEAU,eAAU,CAAA,IAAA;AACRL,QAAAA,MAAAA,CAAOC,YAAY,CAACK,OAAO,CAACZ,GAAKS,EAAAA,IAAAA,CAAKI,SAAS,CAACX,KAAAA,CAAAA,CAAAA;KAC/C,EAAA;AAACF,QAAAA,GAAAA;AAAKE,QAAAA;AAAM,KAAA,CAAA;IAEf,OAAO;AAACA,QAAAA,KAAAA;AAAOC,QAAAA;AAAS,KAAA;AAC1B;;;;"}

View File

@@ -0,0 +1,29 @@
import { useState, useEffect } from 'react';
const usePersistentState = (key, defaultValue)=>{
const [value, setValue] = useState(()=>{
const stickyValue = window.localStorage.getItem(key);
if (stickyValue !== null) {
try {
return JSON.parse(stickyValue);
} catch {
// JSON.parse fails when the stored value is a primitive
return stickyValue;
}
}
return defaultValue;
});
useEffect(()=>{
window.localStorage.setItem(key, JSON.stringify(value));
}, [
key,
value
]);
return [
value,
setValue
];
};
export { usePersistentState };
//# sourceMappingURL=usePersistentState.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"usePersistentState.mjs","sources":["../../../admin/src/hooks/usePersistentState.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nconst usePersistentState = <T>(key: string, defaultValue: T) => {\n const [value, setValue] = useState<T>(() => {\n const stickyValue = window.localStorage.getItem(key);\n\n if (stickyValue !== null) {\n try {\n return JSON.parse(stickyValue);\n } catch {\n // JSON.parse fails when the stored value is a primitive\n return stickyValue;\n }\n }\n\n return defaultValue;\n });\n\n useEffect(() => {\n window.localStorage.setItem(key, JSON.stringify(value));\n }, [key, value]);\n\n return [value, setValue] as const;\n};\n\nexport { usePersistentState };\n"],"names":["usePersistentState","key","defaultValue","value","setValue","useState","stickyValue","window","localStorage","getItem","JSON","parse","useEffect","setItem","stringify"],"mappings":";;AAEMA,MAAAA,kBAAAA,GAAqB,CAAIC,GAAaC,EAAAA,YAAAA,GAAAA;AAC1C,IAAA,MAAM,CAACC,KAAAA,EAAOC,QAAS,CAAA,GAAGC,QAAY,CAAA,IAAA;AACpC,QAAA,MAAMC,WAAcC,GAAAA,MAAAA,CAAOC,YAAY,CAACC,OAAO,CAACR,GAAAA,CAAAA;AAEhD,QAAA,IAAIK,gBAAgB,IAAM,EAAA;YACxB,IAAI;gBACF,OAAOI,IAAAA,CAAKC,KAAK,CAACL,WAAAA,CAAAA;AACpB,aAAA,CAAE,OAAM;;gBAEN,OAAOA,WAAAA;AACT;AACF;QAEA,OAAOJ,YAAAA;AACT,KAAA,CAAA;IAEAU,SAAU,CAAA,IAAA;AACRL,QAAAA,MAAAA,CAAOC,YAAY,CAACK,OAAO,CAACZ,GAAKS,EAAAA,IAAAA,CAAKI,SAAS,CAACX,KAAAA,CAAAA,CAAAA;KAC/C,EAAA;AAACF,QAAAA,GAAAA;AAAKE,QAAAA;AAAM,KAAA,CAAA;IAEf,OAAO;AAACA,QAAAA,KAAAA;AAAOC,QAAAA;AAAS,KAAA;AAC1B;;;;"}

View File

@@ -0,0 +1,53 @@
'use strict';
var strapiAdmin = require('@strapi/admin/strapi-admin');
var reactIntl = require('react-intl');
var reactQuery = require('react-query');
var pluginId = require('../pluginId.js');
const useRemoveAsset = (onSuccess)=>{
const { toggleNotification } = strapiAdmin.useNotification();
const { formatMessage } = reactIntl.useIntl();
const queryClient = reactQuery.useQueryClient();
const { del } = strapiAdmin.useFetchClient();
const mutation = reactQuery.useMutation((assetId)=>del(`/upload/files/${assetId}`), {
onSuccess () {
queryClient.refetchQueries([
pluginId.pluginId,
'assets'
], {
active: true
});
queryClient.refetchQueries([
pluginId.pluginId,
'asset-count'
], {
active: true
});
toggleNotification({
type: 'success',
message: formatMessage({
id: 'modal.remove.success-label',
defaultMessage: 'Elements have been successfully deleted.'
})
});
onSuccess();
},
onError (error) {
toggleNotification({
type: 'danger',
message: error.message
});
}
});
const removeAsset = async (assetId)=>{
await mutation.mutateAsync(assetId);
};
return {
...mutation,
removeAsset
};
};
exports.useRemoveAsset = useRemoveAsset;
//# sourceMappingURL=useRemoveAsset.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useRemoveAsset.js","sources":["../../../admin/src/hooks/useRemoveAsset.ts"],"sourcesContent":["import { useNotification, useFetchClient, FetchResponse } from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useMutation, useQueryClient, UseMutationResult } from 'react-query';\n\nimport { pluginId } from '../pluginId';\n\nimport type { DeleteFile } from '../../../shared/contracts/files';\n\ntype UseRemoveAsset = {\n removeAsset: (assetId: number) => Promise<void>;\n} & UseMutationResult<FetchResponse<DeleteFile.Response>, Error, number>;\n\nexport const useRemoveAsset = (onSuccess: () => void): UseRemoveAsset => {\n const { toggleNotification } = useNotification();\n const { formatMessage } = useIntl();\n const queryClient = useQueryClient();\n const { del } = useFetchClient();\n\n const mutation = useMutation(\n (assetId: number) => del<DeleteFile.Response>(`/upload/files/${assetId}`),\n {\n onSuccess() {\n queryClient.refetchQueries([pluginId, 'assets'], { active: true });\n queryClient.refetchQueries([pluginId, 'asset-count'], { active: true });\n\n toggleNotification({\n type: 'success',\n message: formatMessage({\n id: 'modal.remove.success-label',\n defaultMessage: 'Elements have been successfully deleted.',\n }),\n });\n\n onSuccess();\n },\n onError(error: Error) {\n toggleNotification({ type: 'danger', message: error.message });\n },\n }\n );\n\n const removeAsset = async (assetId: number) => {\n await mutation.mutateAsync(assetId);\n };\n\n return { ...mutation, removeAsset };\n};\n"],"names":["useRemoveAsset","onSuccess","toggleNotification","useNotification","formatMessage","useIntl","queryClient","useQueryClient","del","useFetchClient","mutation","useMutation","assetId","refetchQueries","pluginId","active","type","message","id","defaultMessage","onError","error","removeAsset","mutateAsync"],"mappings":";;;;;;;AAYO,MAAMA,iBAAiB,CAACC,SAAAA,GAAAA;IAC7B,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,2BAAAA,EAAAA;IAC/B,MAAM,EAAEC,aAAa,EAAE,GAAGC,iBAAAA,EAAAA;AAC1B,IAAA,MAAMC,WAAcC,GAAAA,yBAAAA,EAAAA;IACpB,MAAM,EAAEC,GAAG,EAAE,GAAGC,0BAAAA,EAAAA;IAEhB,MAAMC,QAAAA,GAAWC,sBACf,CAAA,CAACC,OAAoBJ,GAAAA,GAAAA,CAAyB,CAAC,cAAc,EAAEI,OAAQ,CAAA,CAAC,CACxE,EAAA;AACEX,QAAAA,SAAAA,CAAAA,GAAAA;AACEK,YAAAA,WAAAA,CAAYO,cAAc,CAAC;AAACC,gBAAAA,iBAAAA;AAAU,gBAAA;aAAS,EAAE;gBAAEC,MAAQ,EAAA;AAAK,aAAA,CAAA;AAChET,YAAAA,WAAAA,CAAYO,cAAc,CAAC;AAACC,gBAAAA,iBAAAA;AAAU,gBAAA;aAAc,EAAE;gBAAEC,MAAQ,EAAA;AAAK,aAAA,CAAA;YAErEb,kBAAmB,CAAA;gBACjBc,IAAM,EAAA,SAAA;AACNC,gBAAAA,OAAAA,EAASb,aAAc,CAAA;oBACrBc,EAAI,EAAA,4BAAA;oBACJC,cAAgB,EAAA;AAClB,iBAAA;AACF,aAAA,CAAA;AAEAlB,YAAAA,SAAAA,EAAAA;AACF,SAAA;AACAmB,QAAAA,OAAAA,CAAAA,CAAQC,KAAY,EAAA;YAClBnB,kBAAmB,CAAA;gBAAEc,IAAM,EAAA,QAAA;AAAUC,gBAAAA,OAAAA,EAASI,MAAMJ;AAAQ,aAAA,CAAA;AAC9D;AACF,KAAA,CAAA;AAGF,IAAA,MAAMK,cAAc,OAAOV,OAAAA,GAAAA;QACzB,MAAMF,QAAAA,CAASa,WAAW,CAACX,OAAAA,CAAAA;AAC7B,KAAA;IAEA,OAAO;AAAE,QAAA,GAAGF,QAAQ;AAAEY,QAAAA;AAAY,KAAA;AACpC;;;;"}

View File

@@ -0,0 +1,51 @@
import { useNotification, useFetchClient } from '@strapi/admin/strapi-admin';
import { useIntl } from 'react-intl';
import { useQueryClient, useMutation } from 'react-query';
import { pluginId } from '../pluginId.mjs';
const useRemoveAsset = (onSuccess)=>{
const { toggleNotification } = useNotification();
const { formatMessage } = useIntl();
const queryClient = useQueryClient();
const { del } = useFetchClient();
const mutation = useMutation((assetId)=>del(`/upload/files/${assetId}`), {
onSuccess () {
queryClient.refetchQueries([
pluginId,
'assets'
], {
active: true
});
queryClient.refetchQueries([
pluginId,
'asset-count'
], {
active: true
});
toggleNotification({
type: 'success',
message: formatMessage({
id: 'modal.remove.success-label',
defaultMessage: 'Elements have been successfully deleted.'
})
});
onSuccess();
},
onError (error) {
toggleNotification({
type: 'danger',
message: error.message
});
}
});
const removeAsset = async (assetId)=>{
await mutation.mutateAsync(assetId);
};
return {
...mutation,
removeAsset
};
};
export { useRemoveAsset };
//# sourceMappingURL=useRemoveAsset.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useRemoveAsset.mjs","sources":["../../../admin/src/hooks/useRemoveAsset.ts"],"sourcesContent":["import { useNotification, useFetchClient, FetchResponse } from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useMutation, useQueryClient, UseMutationResult } from 'react-query';\n\nimport { pluginId } from '../pluginId';\n\nimport type { DeleteFile } from '../../../shared/contracts/files';\n\ntype UseRemoveAsset = {\n removeAsset: (assetId: number) => Promise<void>;\n} & UseMutationResult<FetchResponse<DeleteFile.Response>, Error, number>;\n\nexport const useRemoveAsset = (onSuccess: () => void): UseRemoveAsset => {\n const { toggleNotification } = useNotification();\n const { formatMessage } = useIntl();\n const queryClient = useQueryClient();\n const { del } = useFetchClient();\n\n const mutation = useMutation(\n (assetId: number) => del<DeleteFile.Response>(`/upload/files/${assetId}`),\n {\n onSuccess() {\n queryClient.refetchQueries([pluginId, 'assets'], { active: true });\n queryClient.refetchQueries([pluginId, 'asset-count'], { active: true });\n\n toggleNotification({\n type: 'success',\n message: formatMessage({\n id: 'modal.remove.success-label',\n defaultMessage: 'Elements have been successfully deleted.',\n }),\n });\n\n onSuccess();\n },\n onError(error: Error) {\n toggleNotification({ type: 'danger', message: error.message });\n },\n }\n );\n\n const removeAsset = async (assetId: number) => {\n await mutation.mutateAsync(assetId);\n };\n\n return { ...mutation, removeAsset };\n};\n"],"names":["useRemoveAsset","onSuccess","toggleNotification","useNotification","formatMessage","useIntl","queryClient","useQueryClient","del","useFetchClient","mutation","useMutation","assetId","refetchQueries","pluginId","active","type","message","id","defaultMessage","onError","error","removeAsset","mutateAsync"],"mappings":";;;;;AAYO,MAAMA,iBAAiB,CAACC,SAAAA,GAAAA;IAC7B,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,eAAAA,EAAAA;IAC/B,MAAM,EAAEC,aAAa,EAAE,GAAGC,OAAAA,EAAAA;AAC1B,IAAA,MAAMC,WAAcC,GAAAA,cAAAA,EAAAA;IACpB,MAAM,EAAEC,GAAG,EAAE,GAAGC,cAAAA,EAAAA;IAEhB,MAAMC,QAAAA,GAAWC,WACf,CAAA,CAACC,OAAoBJ,GAAAA,GAAAA,CAAyB,CAAC,cAAc,EAAEI,OAAQ,CAAA,CAAC,CACxE,EAAA;AACEX,QAAAA,SAAAA,CAAAA,GAAAA;AACEK,YAAAA,WAAAA,CAAYO,cAAc,CAAC;AAACC,gBAAAA,QAAAA;AAAU,gBAAA;aAAS,EAAE;gBAAEC,MAAQ,EAAA;AAAK,aAAA,CAAA;AAChET,YAAAA,WAAAA,CAAYO,cAAc,CAAC;AAACC,gBAAAA,QAAAA;AAAU,gBAAA;aAAc,EAAE;gBAAEC,MAAQ,EAAA;AAAK,aAAA,CAAA;YAErEb,kBAAmB,CAAA;gBACjBc,IAAM,EAAA,SAAA;AACNC,gBAAAA,OAAAA,EAASb,aAAc,CAAA;oBACrBc,EAAI,EAAA,4BAAA;oBACJC,cAAgB,EAAA;AAClB,iBAAA;AACF,aAAA,CAAA;AAEAlB,YAAAA,SAAAA,EAAAA;AACF,SAAA;AACAmB,QAAAA,OAAAA,CAAAA,CAAQC,KAAY,EAAA;YAClBnB,kBAAmB,CAAA;gBAAEc,IAAM,EAAA,QAAA;AAAUC,gBAAAA,OAAAA,EAASI,MAAMJ;AAAQ,aAAA,CAAA;AAC9D;AACF,KAAA,CAAA;AAGF,IAAA,MAAMK,cAAc,OAAOV,OAAAA,GAAAA;QACzB,MAAMF,QAAAA,CAASa,WAAW,CAACX,OAAAA,CAAAA;AAC7B,KAAA;IAEA,OAAO;AAAE,QAAA,GAAGF,QAAQ;AAAEY,QAAAA;AAAY,KAAA;AACpC;;;;"}

View File

@@ -0,0 +1,85 @@
'use strict';
var React = require('react');
function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
const useSelectionState = (keys, initialValue)=>{
const [selections, setSelections] = React__namespace.useState(initialValue);
const selectOne = (selection)=>{
const index = selections.findIndex((currentSelection)=>keys.every((key)=>currentSelection[key] === selection[key]));
if (index > -1) {
setSelections((prevSelected)=>[
...prevSelected.slice(0, index),
...prevSelected.slice(index + 1)
]);
} else {
setSelections((prevSelected)=>[
...prevSelected,
selection
]);
}
};
const selectAll = (nextSelections)=>{
if (selections.length > 0) {
setSelections([]);
} else {
setSelections(nextSelections);
}
};
const selectOnly = (nextSelection)=>{
const index = selections.findIndex((currentSelection)=>keys.every((key)=>currentSelection[key] === nextSelection[key]));
if (index > -1) {
setSelections([]);
} else {
setSelections([
nextSelection
]);
}
};
const selectMultiple = (nextSelections)=>{
setSelections((currSelections)=>[
// already selected items
...currSelections,
// filter out already selected items from nextSelections
...nextSelections.filter((nextSelection)=>currSelections.findIndex((currentSelection)=>keys.every((key)=>currentSelection[key] === nextSelection[key])) === -1)
]);
};
const deselectMultiple = (nextSelections)=>{
setSelections((currSelections)=>[
// filter out items in currSelections that are in nextSelections
...currSelections.filter((currentSelection)=>nextSelections.findIndex((nextSelection)=>keys.every((key)=>currentSelection[key] === nextSelection[key])) === -1)
]);
};
return [
selections,
{
selectOne,
selectAll,
selectOnly,
selectMultiple,
deselectMultiple,
setSelections
}
];
};
exports.useSelectionState = useSelectionState;
//# sourceMappingURL=useSelectionState.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useSelectionState.js","sources":["../../../admin/src/hooks/useSelectionState.ts"],"sourcesContent":["import * as React from 'react';\n\nexport const useSelectionState = <TValues extends object>(\n keys: Array<keyof TValues>,\n initialValue: TValues[]\n) => {\n const [selections, setSelections] = React.useState(initialValue);\n\n const selectOne = (selection: TValues) => {\n const index = selections.findIndex((currentSelection) =>\n keys.every((key) => currentSelection[key] === selection[key])\n );\n\n if (index > -1) {\n setSelections((prevSelected) => [\n ...prevSelected.slice(0, index),\n ...prevSelected.slice(index + 1),\n ]);\n } else {\n setSelections((prevSelected) => [...prevSelected, selection]);\n }\n };\n\n const selectAll = (nextSelections?: TValues[]) => {\n if (selections.length > 0) {\n setSelections([]);\n } else {\n setSelections(nextSelections!);\n }\n };\n\n const selectOnly = (nextSelection: TValues) => {\n const index = selections.findIndex((currentSelection) =>\n keys.every((key) => currentSelection[key] === nextSelection[key])\n );\n\n if (index > -1) {\n setSelections([]);\n } else {\n setSelections([nextSelection]);\n }\n };\n\n const selectMultiple = (nextSelections: TValues[]) => {\n setSelections((currSelections) => [\n // already selected items\n ...currSelections,\n // filter out already selected items from nextSelections\n ...nextSelections.filter(\n (nextSelection) =>\n currSelections.findIndex((currentSelection) =>\n keys.every((key) => currentSelection[key] === nextSelection[key])\n ) === -1\n ),\n ]);\n };\n\n const deselectMultiple = (nextSelections: TValues[]) => {\n setSelections((currSelections) => [\n // filter out items in currSelections that are in nextSelections\n ...currSelections.filter(\n (currentSelection) =>\n nextSelections.findIndex((nextSelection) =>\n keys.every((key) => currentSelection[key] === nextSelection[key])\n ) === -1\n ),\n ]);\n };\n\n return [\n selections,\n { selectOne, selectAll, selectOnly, selectMultiple, deselectMultiple, setSelections },\n ] as const;\n};\n"],"names":["useSelectionState","keys","initialValue","selections","setSelections","React","useState","selectOne","selection","index","findIndex","currentSelection","every","key","prevSelected","slice","selectAll","nextSelections","length","selectOnly","nextSelection","selectMultiple","currSelections","filter","deselectMultiple"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAEO,MAAMA,iBAAoB,GAAA,CAC/BC,IACAC,EAAAA,YAAAA,GAAAA;AAEA,IAAA,MAAM,CAACC,UAAYC,EAAAA,aAAAA,CAAc,GAAGC,gBAAAA,CAAMC,QAAQ,CAACJ,YAAAA,CAAAA;AAEnD,IAAA,MAAMK,YAAY,CAACC,SAAAA,GAAAA;AACjB,QAAA,MAAMC,QAAQN,UAAWO,CAAAA,SAAS,CAAC,CAACC,mBAClCV,IAAKW,CAAAA,KAAK,CAAC,CAACC,MAAQF,gBAAgB,CAACE,IAAI,KAAKL,SAAS,CAACK,GAAI,CAAA,CAAA,CAAA;QAG9D,IAAIJ,KAAAA,GAAQ,CAAC,CAAG,EAAA;AACdL,YAAAA,aAAAA,CAAc,CAACU,YAAiB,GAAA;uBAC3BA,YAAaC,CAAAA,KAAK,CAAC,CAAGN,EAAAA,KAAAA,CAAAA;uBACtBK,YAAaC,CAAAA,KAAK,CAACN,KAAQ,GAAA,CAAA;AAC/B,iBAAA,CAAA;SACI,MAAA;AACLL,YAAAA,aAAAA,CAAc,CAACU,YAAiB,GAAA;AAAIA,oBAAAA,GAAAA,YAAAA;AAAcN,oBAAAA;AAAU,iBAAA,CAAA;AAC9D;AACF,KAAA;AAEA,IAAA,MAAMQ,YAAY,CAACC,cAAAA,GAAAA;QACjB,IAAId,UAAAA,CAAWe,MAAM,GAAG,CAAG,EAAA;AACzBd,YAAAA,aAAAA,CAAc,EAAE,CAAA;SACX,MAAA;YACLA,aAAca,CAAAA,cAAAA,CAAAA;AAChB;AACF,KAAA;AAEA,IAAA,MAAME,aAAa,CAACC,aAAAA,GAAAA;AAClB,QAAA,MAAMX,QAAQN,UAAWO,CAAAA,SAAS,CAAC,CAACC,mBAClCV,IAAKW,CAAAA,KAAK,CAAC,CAACC,MAAQF,gBAAgB,CAACE,IAAI,KAAKO,aAAa,CAACP,GAAI,CAAA,CAAA,CAAA;QAGlE,IAAIJ,KAAAA,GAAQ,CAAC,CAAG,EAAA;AACdL,YAAAA,aAAAA,CAAc,EAAE,CAAA;SACX,MAAA;YACLA,aAAc,CAAA;AAACgB,gBAAAA;AAAc,aAAA,CAAA;AAC/B;AACF,KAAA;AAEA,IAAA,MAAMC,iBAAiB,CAACJ,cAAAA,GAAAA;AACtBb,QAAAA,aAAAA,CAAc,CAACkB,cAAmB,GAAA;;AAE7BA,gBAAAA,GAAAA,cAAAA;;mBAEAL,cAAeM,CAAAA,MAAM,CACtB,CAACH,aAAAA,GACCE,eAAeZ,SAAS,CAAC,CAACC,gBAAAA,GACxBV,IAAKW,CAAAA,KAAK,CAAC,CAACC,GAAAA,GAAQF,gBAAgB,CAACE,GAAAA,CAAI,KAAKO,aAAa,CAACP,GAAI,CAAA,CAAA,CAAA,KAC5D,CAAC,CAAA;AAEZ,aAAA,CAAA;AACH,KAAA;AAEA,IAAA,MAAMW,mBAAmB,CAACP,cAAAA,GAAAA;AACxBb,QAAAA,aAAAA,CAAc,CAACkB,cAAmB,GAAA;;mBAE7BA,cAAeC,CAAAA,MAAM,CACtB,CAACZ,gBAAAA,GACCM,eAAeP,SAAS,CAAC,CAACU,aAAAA,GACxBnB,IAAKW,CAAAA,KAAK,CAAC,CAACC,GAAAA,GAAQF,gBAAgB,CAACE,GAAAA,CAAI,KAAKO,aAAa,CAACP,GAAI,CAAA,CAAA,CAAA,KAC5D,CAAC,CAAA;AAEZ,aAAA,CAAA;AACH,KAAA;IAEA,OAAO;AACLV,QAAAA,UAAAA;AACA,QAAA;AAAEI,YAAAA,SAAAA;AAAWS,YAAAA,SAAAA;AAAWG,YAAAA,UAAAA;AAAYE,YAAAA,cAAAA;AAAgBG,YAAAA,gBAAAA;AAAkBpB,YAAAA;AAAc;AACrF,KAAA;AACH;;;;"}

View File

@@ -0,0 +1,64 @@
import * as React from 'react';
const useSelectionState = (keys, initialValue)=>{
const [selections, setSelections] = React.useState(initialValue);
const selectOne = (selection)=>{
const index = selections.findIndex((currentSelection)=>keys.every((key)=>currentSelection[key] === selection[key]));
if (index > -1) {
setSelections((prevSelected)=>[
...prevSelected.slice(0, index),
...prevSelected.slice(index + 1)
]);
} else {
setSelections((prevSelected)=>[
...prevSelected,
selection
]);
}
};
const selectAll = (nextSelections)=>{
if (selections.length > 0) {
setSelections([]);
} else {
setSelections(nextSelections);
}
};
const selectOnly = (nextSelection)=>{
const index = selections.findIndex((currentSelection)=>keys.every((key)=>currentSelection[key] === nextSelection[key]));
if (index > -1) {
setSelections([]);
} else {
setSelections([
nextSelection
]);
}
};
const selectMultiple = (nextSelections)=>{
setSelections((currSelections)=>[
// already selected items
...currSelections,
// filter out already selected items from nextSelections
...nextSelections.filter((nextSelection)=>currSelections.findIndex((currentSelection)=>keys.every((key)=>currentSelection[key] === nextSelection[key])) === -1)
]);
};
const deselectMultiple = (nextSelections)=>{
setSelections((currSelections)=>[
// filter out items in currSelections that are in nextSelections
...currSelections.filter((currentSelection)=>nextSelections.findIndex((nextSelection)=>keys.every((key)=>currentSelection[key] === nextSelection[key])) === -1)
]);
};
return [
selections,
{
selectOne,
selectAll,
selectOnly,
selectMultiple,
deselectMultiple,
setSelections
}
];
};
export { useSelectionState };
//# sourceMappingURL=useSelectionState.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useSelectionState.mjs","sources":["../../../admin/src/hooks/useSelectionState.ts"],"sourcesContent":["import * as React from 'react';\n\nexport const useSelectionState = <TValues extends object>(\n keys: Array<keyof TValues>,\n initialValue: TValues[]\n) => {\n const [selections, setSelections] = React.useState(initialValue);\n\n const selectOne = (selection: TValues) => {\n const index = selections.findIndex((currentSelection) =>\n keys.every((key) => currentSelection[key] === selection[key])\n );\n\n if (index > -1) {\n setSelections((prevSelected) => [\n ...prevSelected.slice(0, index),\n ...prevSelected.slice(index + 1),\n ]);\n } else {\n setSelections((prevSelected) => [...prevSelected, selection]);\n }\n };\n\n const selectAll = (nextSelections?: TValues[]) => {\n if (selections.length > 0) {\n setSelections([]);\n } else {\n setSelections(nextSelections!);\n }\n };\n\n const selectOnly = (nextSelection: TValues) => {\n const index = selections.findIndex((currentSelection) =>\n keys.every((key) => currentSelection[key] === nextSelection[key])\n );\n\n if (index > -1) {\n setSelections([]);\n } else {\n setSelections([nextSelection]);\n }\n };\n\n const selectMultiple = (nextSelections: TValues[]) => {\n setSelections((currSelections) => [\n // already selected items\n ...currSelections,\n // filter out already selected items from nextSelections\n ...nextSelections.filter(\n (nextSelection) =>\n currSelections.findIndex((currentSelection) =>\n keys.every((key) => currentSelection[key] === nextSelection[key])\n ) === -1\n ),\n ]);\n };\n\n const deselectMultiple = (nextSelections: TValues[]) => {\n setSelections((currSelections) => [\n // filter out items in currSelections that are in nextSelections\n ...currSelections.filter(\n (currentSelection) =>\n nextSelections.findIndex((nextSelection) =>\n keys.every((key) => currentSelection[key] === nextSelection[key])\n ) === -1\n ),\n ]);\n };\n\n return [\n selections,\n { selectOne, selectAll, selectOnly, selectMultiple, deselectMultiple, setSelections },\n ] as const;\n};\n"],"names":["useSelectionState","keys","initialValue","selections","setSelections","React","useState","selectOne","selection","index","findIndex","currentSelection","every","key","prevSelected","slice","selectAll","nextSelections","length","selectOnly","nextSelection","selectMultiple","currSelections","filter","deselectMultiple"],"mappings":";;AAEO,MAAMA,iBAAoB,GAAA,CAC/BC,IACAC,EAAAA,YAAAA,GAAAA;AAEA,IAAA,MAAM,CAACC,UAAYC,EAAAA,aAAAA,CAAc,GAAGC,KAAAA,CAAMC,QAAQ,CAACJ,YAAAA,CAAAA;AAEnD,IAAA,MAAMK,YAAY,CAACC,SAAAA,GAAAA;AACjB,QAAA,MAAMC,QAAQN,UAAWO,CAAAA,SAAS,CAAC,CAACC,mBAClCV,IAAKW,CAAAA,KAAK,CAAC,CAACC,MAAQF,gBAAgB,CAACE,IAAI,KAAKL,SAAS,CAACK,GAAI,CAAA,CAAA,CAAA;QAG9D,IAAIJ,KAAAA,GAAQ,CAAC,CAAG,EAAA;AACdL,YAAAA,aAAAA,CAAc,CAACU,YAAiB,GAAA;uBAC3BA,YAAaC,CAAAA,KAAK,CAAC,CAAGN,EAAAA,KAAAA,CAAAA;uBACtBK,YAAaC,CAAAA,KAAK,CAACN,KAAQ,GAAA,CAAA;AAC/B,iBAAA,CAAA;SACI,MAAA;AACLL,YAAAA,aAAAA,CAAc,CAACU,YAAiB,GAAA;AAAIA,oBAAAA,GAAAA,YAAAA;AAAcN,oBAAAA;AAAU,iBAAA,CAAA;AAC9D;AACF,KAAA;AAEA,IAAA,MAAMQ,YAAY,CAACC,cAAAA,GAAAA;QACjB,IAAId,UAAAA,CAAWe,MAAM,GAAG,CAAG,EAAA;AACzBd,YAAAA,aAAAA,CAAc,EAAE,CAAA;SACX,MAAA;YACLA,aAAca,CAAAA,cAAAA,CAAAA;AAChB;AACF,KAAA;AAEA,IAAA,MAAME,aAAa,CAACC,aAAAA,GAAAA;AAClB,QAAA,MAAMX,QAAQN,UAAWO,CAAAA,SAAS,CAAC,CAACC,mBAClCV,IAAKW,CAAAA,KAAK,CAAC,CAACC,MAAQF,gBAAgB,CAACE,IAAI,KAAKO,aAAa,CAACP,GAAI,CAAA,CAAA,CAAA;QAGlE,IAAIJ,KAAAA,GAAQ,CAAC,CAAG,EAAA;AACdL,YAAAA,aAAAA,CAAc,EAAE,CAAA;SACX,MAAA;YACLA,aAAc,CAAA;AAACgB,gBAAAA;AAAc,aAAA,CAAA;AAC/B;AACF,KAAA;AAEA,IAAA,MAAMC,iBAAiB,CAACJ,cAAAA,GAAAA;AACtBb,QAAAA,aAAAA,CAAc,CAACkB,cAAmB,GAAA;;AAE7BA,gBAAAA,GAAAA,cAAAA;;mBAEAL,cAAeM,CAAAA,MAAM,CACtB,CAACH,aAAAA,GACCE,eAAeZ,SAAS,CAAC,CAACC,gBAAAA,GACxBV,IAAKW,CAAAA,KAAK,CAAC,CAACC,GAAAA,GAAQF,gBAAgB,CAACE,GAAAA,CAAI,KAAKO,aAAa,CAACP,GAAI,CAAA,CAAA,CAAA,KAC5D,CAAC,CAAA;AAEZ,aAAA,CAAA;AACH,KAAA;AAEA,IAAA,MAAMW,mBAAmB,CAACP,cAAAA,GAAAA;AACxBb,QAAAA,aAAAA,CAAc,CAACkB,cAAmB,GAAA;;mBAE7BA,cAAeC,CAAAA,MAAM,CACtB,CAACZ,gBAAAA,GACCM,eAAeP,SAAS,CAAC,CAACU,aAAAA,GACxBnB,IAAKW,CAAAA,KAAK,CAAC,CAACC,GAAAA,GAAQF,gBAAgB,CAACE,GAAAA,CAAI,KAAKO,aAAa,CAACP,GAAI,CAAA,CAAA,CAAA,KAC5D,CAAC,CAAA;AAEZ,aAAA,CAAA;AACH,KAAA;IAEA,OAAO;AACLV,QAAAA,UAAAA;AACA,QAAA;AAAEI,YAAAA,SAAAA;AAAWS,YAAAA,SAAAA;AAAWG,YAAAA,UAAAA;AAAYE,YAAAA,cAAAA;AAAgBG,YAAAA,gBAAAA;AAAkBpB,YAAAA;AAAc;AACrF,KAAA;AACH;;;;"}

View File

@@ -0,0 +1,86 @@
'use strict';
var React = require('react');
var strapiAdmin = require('@strapi/admin/strapi-admin');
var reactQuery = require('react-query');
var pluginId = require('../pluginId.js');
function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
const endpoint = `/${pluginId.pluginId}`;
const uploadAsset = (asset, folderId, signal, onProgress, post)=>{
const { rawFile, caption, name, alternativeText } = asset;
const formData = new FormData();
formData.append('files', rawFile);
formData.append('fileInfo', JSON.stringify({
name,
caption,
alternativeText,
folder: folderId
}));
/**
* onProgress is not possible using native fetch
* need to look into an alternative to make it work
* perhaps using xhr like Axios does
*/ return post(endpoint, formData, {
signal
}).then((res)=>res.data);
};
const useUpload = ()=>{
const [progress, setProgress] = React__namespace.useState(0);
const queryClient = reactQuery.useQueryClient();
const abortController = new AbortController();
const signal = abortController.signal;
const { post } = strapiAdmin.useFetchClient();
const mutation = reactQuery.useMutation(({ asset, folderId })=>{
return uploadAsset(asset, folderId, signal, setProgress, post);
}, {
onSuccess () {
queryClient.refetchQueries([
pluginId.pluginId,
'assets'
], {
active: true
});
queryClient.refetchQueries([
pluginId.pluginId,
'asset-count'
], {
active: true
});
}
});
const upload = (asset, folderId)=>mutation.mutateAsync({
asset,
folderId
});
const cancel = ()=>abortController.abort();
return {
upload,
isLoading: mutation.isLoading,
cancel,
error: mutation.error,
progress,
status: mutation.status
};
};
exports.useUpload = useUpload;
//# sourceMappingURL=useUpload.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useUpload.js","sources":["../../../admin/src/hooks/useUpload.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { useFetchClient, FetchClient } from '@strapi/admin/strapi-admin';\nimport { useMutation, useQueryClient } from 'react-query';\n\nimport { File, RawFile, CreateFile } from '../../../shared/contracts/files';\nimport { pluginId } from '../pluginId';\n\nconst endpoint = `/${pluginId}`;\n\ninterface Asset extends Omit<File, 'id' | 'hash'> {\n rawFile?: RawFile;\n id?: File['id'];\n hash?: File['hash'];\n}\n\nconst uploadAsset = (\n asset: Asset,\n folderId: number | null,\n signal: AbortSignal,\n onProgress: (progress: number) => void,\n post: FetchClient['post']\n) => {\n const { rawFile, caption, name, alternativeText } = asset;\n const formData = new FormData();\n\n formData.append('files', rawFile!);\n\n formData.append(\n 'fileInfo',\n JSON.stringify({\n name,\n caption,\n alternativeText,\n folder: folderId,\n })\n );\n\n /**\n * onProgress is not possible using native fetch\n * need to look into an alternative to make it work\n * perhaps using xhr like Axios does\n */\n return post(endpoint, formData, {\n signal,\n }).then((res) => res.data);\n};\n\nexport const useUpload = () => {\n const [progress, setProgress] = React.useState(0);\n const queryClient = useQueryClient();\n const abortController = new AbortController();\n const signal = abortController.signal;\n const { post } = useFetchClient();\n\n const mutation = useMutation<\n CreateFile.Response['data'],\n CreateFile.Response['error'],\n { asset: Asset; folderId: number | null }\n >(\n ({ asset, folderId }) => {\n return uploadAsset(asset, folderId, signal, setProgress, post);\n },\n {\n onSuccess() {\n queryClient.refetchQueries([pluginId, 'assets'], { active: true });\n queryClient.refetchQueries([pluginId, 'asset-count'], { active: true });\n },\n }\n );\n\n const upload = (asset: Asset, folderId: number | null) =>\n mutation.mutateAsync({ asset, folderId });\n\n const cancel = () => abortController.abort();\n\n return {\n upload,\n isLoading: mutation.isLoading,\n cancel,\n error: mutation.error,\n progress,\n status: mutation.status,\n };\n};\n"],"names":["endpoint","pluginId","uploadAsset","asset","folderId","signal","onProgress","post","rawFile","caption","name","alternativeText","formData","FormData","append","JSON","stringify","folder","then","res","data","useUpload","progress","setProgress","React","useState","queryClient","useQueryClient","abortController","AbortController","useFetchClient","mutation","useMutation","onSuccess","refetchQueries","active","upload","mutateAsync","cancel","abort","isLoading","error","status"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,MAAMA,QAAW,GAAA,CAAC,CAAC,EAAEC,kBAAS,CAAC;AAQ/B,MAAMC,WAAc,GAAA,CAClBC,KACAC,EAAAA,QAAAA,EACAC,QACAC,UACAC,EAAAA,IAAAA,GAAAA;IAEA,MAAM,EAAEC,OAAO,EAAEC,OAAO,EAAEC,IAAI,EAAEC,eAAe,EAAE,GAAGR,KAAAA;AACpD,IAAA,MAAMS,WAAW,IAAIC,QAAAA,EAAAA;IAErBD,QAASE,CAAAA,MAAM,CAAC,OAASN,EAAAA,OAAAA,CAAAA;AAEzBI,IAAAA,QAAAA,CAASE,MAAM,CACb,UACAC,EAAAA,IAAAA,CAAKC,SAAS,CAAC;AACbN,QAAAA,IAAAA;AACAD,QAAAA,OAAAA;AACAE,QAAAA,eAAAA;QACAM,MAAQb,EAAAA;AACV,KAAA,CAAA,CAAA;AAGF;;;;MAKA,OAAOG,IAAKP,CAAAA,QAAAA,EAAUY,QAAU,EAAA;AAC9BP,QAAAA;AACF,KAAA,CAAA,CAAGa,IAAI,CAAC,CAACC,GAAAA,GAAQA,IAAIC,IAAI,CAAA;AAC3B,CAAA;MAEaC,SAAY,GAAA,IAAA;AACvB,IAAA,MAAM,CAACC,QAAUC,EAAAA,WAAAA,CAAY,GAAGC,gBAAAA,CAAMC,QAAQ,CAAC,CAAA,CAAA;AAC/C,IAAA,MAAMC,WAAcC,GAAAA,yBAAAA,EAAAA;AACpB,IAAA,MAAMC,kBAAkB,IAAIC,eAAAA,EAAAA;IAC5B,MAAMxB,MAAAA,GAASuB,gBAAgBvB,MAAM;IACrC,MAAM,EAAEE,IAAI,EAAE,GAAGuB,0BAAAA,EAAAA;AAEjB,IAAA,MAAMC,WAAWC,sBAKf,CAAA,CAAC,EAAE7B,KAAK,EAAEC,QAAQ,EAAE,GAAA;AAClB,QAAA,OAAOF,WAAYC,CAAAA,KAAAA,EAAOC,QAAUC,EAAAA,MAAAA,EAAQkB,WAAahB,EAAAA,IAAAA,CAAAA;KAE3D,EAAA;AACE0B,QAAAA,SAAAA,CAAAA,GAAAA;AACEP,YAAAA,WAAAA,CAAYQ,cAAc,CAAC;AAACjC,gBAAAA,iBAAAA;AAAU,gBAAA;aAAS,EAAE;gBAAEkC,MAAQ,EAAA;AAAK,aAAA,CAAA;AAChET,YAAAA,WAAAA,CAAYQ,cAAc,CAAC;AAACjC,gBAAAA,iBAAAA;AAAU,gBAAA;aAAc,EAAE;gBAAEkC,MAAQ,EAAA;AAAK,aAAA,CAAA;AACvE;AACF,KAAA,CAAA;AAGF,IAAA,MAAMC,SAAS,CAACjC,KAAAA,EAAcC,QAC5B2B,GAAAA,QAAAA,CAASM,WAAW,CAAC;AAAElC,YAAAA,KAAAA;AAAOC,YAAAA;AAAS,SAAA,CAAA;IAEzC,MAAMkC,MAAAA,GAAS,IAAMV,eAAAA,CAAgBW,KAAK,EAAA;IAE1C,OAAO;AACLH,QAAAA,MAAAA;AACAI,QAAAA,SAAAA,EAAWT,SAASS,SAAS;AAC7BF,QAAAA,MAAAA;AACAG,QAAAA,KAAAA,EAAOV,SAASU,KAAK;AACrBnB,QAAAA,QAAAA;AACAoB,QAAAA,MAAAA,EAAQX,SAASW;AACnB,KAAA;AACF;;;;"}

View File

@@ -0,0 +1,65 @@
import * as React from 'react';
import { useFetchClient } from '@strapi/admin/strapi-admin';
import { useQueryClient, useMutation } from 'react-query';
import { pluginId } from '../pluginId.mjs';
const endpoint = `/${pluginId}`;
const uploadAsset = (asset, folderId, signal, onProgress, post)=>{
const { rawFile, caption, name, alternativeText } = asset;
const formData = new FormData();
formData.append('files', rawFile);
formData.append('fileInfo', JSON.stringify({
name,
caption,
alternativeText,
folder: folderId
}));
/**
* onProgress is not possible using native fetch
* need to look into an alternative to make it work
* perhaps using xhr like Axios does
*/ return post(endpoint, formData, {
signal
}).then((res)=>res.data);
};
const useUpload = ()=>{
const [progress, setProgress] = React.useState(0);
const queryClient = useQueryClient();
const abortController = new AbortController();
const signal = abortController.signal;
const { post } = useFetchClient();
const mutation = useMutation(({ asset, folderId })=>{
return uploadAsset(asset, folderId, signal, setProgress, post);
}, {
onSuccess () {
queryClient.refetchQueries([
pluginId,
'assets'
], {
active: true
});
queryClient.refetchQueries([
pluginId,
'asset-count'
], {
active: true
});
}
});
const upload = (asset, folderId)=>mutation.mutateAsync({
asset,
folderId
});
const cancel = ()=>abortController.abort();
return {
upload,
isLoading: mutation.isLoading,
cancel,
error: mutation.error,
progress,
status: mutation.status
};
};
export { useUpload };
//# sourceMappingURL=useUpload.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useUpload.mjs","sources":["../../../admin/src/hooks/useUpload.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { useFetchClient, FetchClient } from '@strapi/admin/strapi-admin';\nimport { useMutation, useQueryClient } from 'react-query';\n\nimport { File, RawFile, CreateFile } from '../../../shared/contracts/files';\nimport { pluginId } from '../pluginId';\n\nconst endpoint = `/${pluginId}`;\n\ninterface Asset extends Omit<File, 'id' | 'hash'> {\n rawFile?: RawFile;\n id?: File['id'];\n hash?: File['hash'];\n}\n\nconst uploadAsset = (\n asset: Asset,\n folderId: number | null,\n signal: AbortSignal,\n onProgress: (progress: number) => void,\n post: FetchClient['post']\n) => {\n const { rawFile, caption, name, alternativeText } = asset;\n const formData = new FormData();\n\n formData.append('files', rawFile!);\n\n formData.append(\n 'fileInfo',\n JSON.stringify({\n name,\n caption,\n alternativeText,\n folder: folderId,\n })\n );\n\n /**\n * onProgress is not possible using native fetch\n * need to look into an alternative to make it work\n * perhaps using xhr like Axios does\n */\n return post(endpoint, formData, {\n signal,\n }).then((res) => res.data);\n};\n\nexport const useUpload = () => {\n const [progress, setProgress] = React.useState(0);\n const queryClient = useQueryClient();\n const abortController = new AbortController();\n const signal = abortController.signal;\n const { post } = useFetchClient();\n\n const mutation = useMutation<\n CreateFile.Response['data'],\n CreateFile.Response['error'],\n { asset: Asset; folderId: number | null }\n >(\n ({ asset, folderId }) => {\n return uploadAsset(asset, folderId, signal, setProgress, post);\n },\n {\n onSuccess() {\n queryClient.refetchQueries([pluginId, 'assets'], { active: true });\n queryClient.refetchQueries([pluginId, 'asset-count'], { active: true });\n },\n }\n );\n\n const upload = (asset: Asset, folderId: number | null) =>\n mutation.mutateAsync({ asset, folderId });\n\n const cancel = () => abortController.abort();\n\n return {\n upload,\n isLoading: mutation.isLoading,\n cancel,\n error: mutation.error,\n progress,\n status: mutation.status,\n };\n};\n"],"names":["endpoint","pluginId","uploadAsset","asset","folderId","signal","onProgress","post","rawFile","caption","name","alternativeText","formData","FormData","append","JSON","stringify","folder","then","res","data","useUpload","progress","setProgress","React","useState","queryClient","useQueryClient","abortController","AbortController","useFetchClient","mutation","useMutation","onSuccess","refetchQueries","active","upload","mutateAsync","cancel","abort","isLoading","error","status"],"mappings":";;;;;AAQA,MAAMA,QAAW,GAAA,CAAC,CAAC,EAAEC,SAAS,CAAC;AAQ/B,MAAMC,WAAc,GAAA,CAClBC,KACAC,EAAAA,QAAAA,EACAC,QACAC,UACAC,EAAAA,IAAAA,GAAAA;IAEA,MAAM,EAAEC,OAAO,EAAEC,OAAO,EAAEC,IAAI,EAAEC,eAAe,EAAE,GAAGR,KAAAA;AACpD,IAAA,MAAMS,WAAW,IAAIC,QAAAA,EAAAA;IAErBD,QAASE,CAAAA,MAAM,CAAC,OAASN,EAAAA,OAAAA,CAAAA;AAEzBI,IAAAA,QAAAA,CAASE,MAAM,CACb,UACAC,EAAAA,IAAAA,CAAKC,SAAS,CAAC;AACbN,QAAAA,IAAAA;AACAD,QAAAA,OAAAA;AACAE,QAAAA,eAAAA;QACAM,MAAQb,EAAAA;AACV,KAAA,CAAA,CAAA;AAGF;;;;MAKA,OAAOG,IAAKP,CAAAA,QAAAA,EAAUY,QAAU,EAAA;AAC9BP,QAAAA;AACF,KAAA,CAAA,CAAGa,IAAI,CAAC,CAACC,GAAAA,GAAQA,IAAIC,IAAI,CAAA;AAC3B,CAAA;MAEaC,SAAY,GAAA,IAAA;AACvB,IAAA,MAAM,CAACC,QAAUC,EAAAA,WAAAA,CAAY,GAAGC,KAAAA,CAAMC,QAAQ,CAAC,CAAA,CAAA;AAC/C,IAAA,MAAMC,WAAcC,GAAAA,cAAAA,EAAAA;AACpB,IAAA,MAAMC,kBAAkB,IAAIC,eAAAA,EAAAA;IAC5B,MAAMxB,MAAAA,GAASuB,gBAAgBvB,MAAM;IACrC,MAAM,EAAEE,IAAI,EAAE,GAAGuB,cAAAA,EAAAA;AAEjB,IAAA,MAAMC,WAAWC,WAKf,CAAA,CAAC,EAAE7B,KAAK,EAAEC,QAAQ,EAAE,GAAA;AAClB,QAAA,OAAOF,WAAYC,CAAAA,KAAAA,EAAOC,QAAUC,EAAAA,MAAAA,EAAQkB,WAAahB,EAAAA,IAAAA,CAAAA;KAE3D,EAAA;AACE0B,QAAAA,SAAAA,CAAAA,GAAAA;AACEP,YAAAA,WAAAA,CAAYQ,cAAc,CAAC;AAACjC,gBAAAA,QAAAA;AAAU,gBAAA;aAAS,EAAE;gBAAEkC,MAAQ,EAAA;AAAK,aAAA,CAAA;AAChET,YAAAA,WAAAA,CAAYQ,cAAc,CAAC;AAACjC,gBAAAA,QAAAA;AAAU,gBAAA;aAAc,EAAE;gBAAEkC,MAAQ,EAAA;AAAK,aAAA,CAAA;AACvE;AACF,KAAA,CAAA;AAGF,IAAA,MAAMC,SAAS,CAACjC,KAAAA,EAAcC,QAC5B2B,GAAAA,QAAAA,CAASM,WAAW,CAAC;AAAElC,YAAAA,KAAAA;AAAOC,YAAAA;AAAS,SAAA,CAAA;IAEzC,MAAMkC,MAAAA,GAAS,IAAMV,eAAAA,CAAgBW,KAAK,EAAA;IAE1C,OAAO;AACLH,QAAAA,MAAAA;AACAI,QAAAA,SAAAA,EAAWT,SAASS,SAAS;AAC7BF,QAAAA,MAAAA;AACAG,QAAAA,KAAAA,EAAOV,SAASU,KAAK;AACrBnB,QAAAA,QAAAA;AACAoB,QAAAA,MAAAA,EAAQX,SAASW;AACnB,KAAA;AACF;;;;"}

View File

@@ -0,0 +1,12 @@
'use strict';
const recursiveRenameKeys = (obj, fn)=>Object.fromEntries(Object.entries(obj).map(([key, value])=>{
const getValue = (v)=>typeof v === 'object' && v !== null ? recursiveRenameKeys(v, fn) : v;
return [
fn(key),
Array.isArray(value) ? value.map((val)=>getValue(val)) : getValue(value)
];
}));
exports.recursiveRenameKeys = recursiveRenameKeys;
//# sourceMappingURL=renameKeys.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"renameKeys.js","sources":["../../../../admin/src/hooks/utils/renameKeys.ts"],"sourcesContent":["type Primitive = string | number | boolean | null | undefined;\n\nexport type DeepRecord<T> = {\n [K in keyof T]: T[K] extends Primitive ? T[K] : DeepRecord<T[K]>;\n};\n\nexport const recursiveRenameKeys = <T extends object>(\n obj: T,\n fn: (key: string) => string\n): DeepRecord<T> =>\n Object.fromEntries(\n Object.entries(obj).map(([key, value]) => {\n const getValue = (v: unknown): unknown =>\n typeof v === 'object' && v !== null ? recursiveRenameKeys(v, fn) : v;\n\n return [fn(key), Array.isArray(value) ? value.map((val) => getValue(val)) : getValue(value)];\n })\n ) as DeepRecord<T>;\n"],"names":["recursiveRenameKeys","obj","fn","Object","fromEntries","entries","map","key","value","getValue","v","Array","isArray","val"],"mappings":";;MAMaA,mBAAsB,GAAA,CACjCC,GACAC,EAAAA,EAAAA,GAEAC,OAAOC,WAAW,CAChBD,MAAOE,CAAAA,OAAO,CAACJ,GAAKK,CAAAA,CAAAA,GAAG,CAAC,CAAC,CAACC,KAAKC,KAAM,CAAA,GAAA;QACnC,MAAMC,QAAAA,GAAW,CAACC,CAAAA,GAChB,OAAOA,CAAAA,KAAM,YAAYA,CAAM,KAAA,IAAA,GAAOV,mBAAoBU,CAAAA,CAAAA,EAAGR,EAAMQ,CAAAA,GAAAA,CAAAA;QAErE,OAAO;YAACR,EAAGK,CAAAA,GAAAA,CAAAA;YAAMI,KAAMC,CAAAA,OAAO,CAACJ,KAAAA,CAAAA,GAASA,KAAMF,CAAAA,GAAG,CAAC,CAACO,GAAAA,GAAQJ,QAASI,CAAAA,GAAAA,CAAAA,CAAAA,GAAQJ,QAASD,CAAAA,KAAAA;AAAO,SAAA;KAE7E,CAAA;;;;"}

View File

@@ -0,0 +1,10 @@
const recursiveRenameKeys = (obj, fn)=>Object.fromEntries(Object.entries(obj).map(([key, value])=>{
const getValue = (v)=>typeof v === 'object' && v !== null ? recursiveRenameKeys(v, fn) : v;
return [
fn(key),
Array.isArray(value) ? value.map((val)=>getValue(val)) : getValue(value)
];
}));
export { recursiveRenameKeys };
//# sourceMappingURL=renameKeys.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"renameKeys.mjs","sources":["../../../../admin/src/hooks/utils/renameKeys.ts"],"sourcesContent":["type Primitive = string | number | boolean | null | undefined;\n\nexport type DeepRecord<T> = {\n [K in keyof T]: T[K] extends Primitive ? T[K] : DeepRecord<T[K]>;\n};\n\nexport const recursiveRenameKeys = <T extends object>(\n obj: T,\n fn: (key: string) => string\n): DeepRecord<T> =>\n Object.fromEntries(\n Object.entries(obj).map(([key, value]) => {\n const getValue = (v: unknown): unknown =>\n typeof v === 'object' && v !== null ? recursiveRenameKeys(v, fn) : v;\n\n return [fn(key), Array.isArray(value) ? value.map((val) => getValue(val)) : getValue(value)];\n })\n ) as DeepRecord<T>;\n"],"names":["recursiveRenameKeys","obj","fn","Object","fromEntries","entries","map","key","value","getValue","v","Array","isArray","val"],"mappings":"MAMaA,mBAAsB,GAAA,CACjCC,GACAC,EAAAA,EAAAA,GAEAC,OAAOC,WAAW,CAChBD,MAAOE,CAAAA,OAAO,CAACJ,GAAKK,CAAAA,CAAAA,GAAG,CAAC,CAAC,CAACC,KAAKC,KAAM,CAAA,GAAA;QACnC,MAAMC,QAAAA,GAAW,CAACC,CAAAA,GAChB,OAAOA,CAAAA,KAAM,YAAYA,CAAM,KAAA,IAAA,GAAOV,mBAAoBU,CAAAA,CAAAA,EAAGR,EAAMQ,CAAAA,GAAAA,CAAAA;QAErE,OAAO;YAACR,EAAGK,CAAAA,GAAAA,CAAAA;YAAMI,KAAMC,CAAAA,OAAO,CAACJ,KAAAA,CAAAA,GAASA,KAAMF,CAAAA,GAAG,CAAC,CAACO,GAAAA,GAAQJ,QAASI,CAAAA,GAAAA,CAAAA,CAAAA,GAAQJ,QAASD,CAAAA,KAAAA;AAAO,SAAA;KAE7E,CAAA;;;;"}