@firecms/media_manager 3.1.0-canary.02232f4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +6 -0
- package/dist/MediaManagerProvider.d.ts +14 -0
- package/dist/components/MediaAssetCard.d.ts +13 -0
- package/dist/components/MediaAssetDetails.d.ts +11 -0
- package/dist/components/MediaLibraryCard.d.ts +8 -0
- package/dist/components/MediaLibraryView.d.ts +9 -0
- package/dist/components/MediaUploadDialog.d.ts +13 -0
- package/dist/components/index.d.ts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.es.js +1741 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +1737 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/locales/de.d.ts +45 -0
- package/dist/locales/en.d.ts +45 -0
- package/dist/locales/es.d.ts +45 -0
- package/dist/locales/fr.d.ts +45 -0
- package/dist/locales/hi.d.ts +45 -0
- package/dist/locales/it.d.ts +45 -0
- package/dist/locales/pt.d.ts +45 -0
- package/dist/types/config.d.ts +87 -0
- package/dist/types/controller.d.ts +66 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/media_asset.d.ts +70 -0
- package/dist/useMediaManagerController.d.ts +18 -0
- package/dist/useMediaManagerPlugin.d.ts +23 -0
- package/package.json +58 -0
- package/src/MediaManagerProvider.tsx +34 -0
- package/src/components/MediaAssetCard.tsx +134 -0
- package/src/components/MediaAssetDetails.tsx +353 -0
- package/src/components/MediaLibraryCard.tsx +58 -0
- package/src/components/MediaLibraryView.tsx +196 -0
- package/src/components/MediaUploadDialog.tsx +266 -0
- package/src/components/index.ts +5 -0
- package/src/index.ts +10 -0
- package/src/locales/de.ts +45 -0
- package/src/locales/en.ts +45 -0
- package/src/locales/es.ts +45 -0
- package/src/locales/fr.ts +45 -0
- package/src/locales/hi.ts +45 -0
- package/src/locales/it.ts +45 -0
- package/src/locales/pt.ts +45 -0
- package/src/types/config.ts +100 -0
- package/src/types/controller.ts +79 -0
- package/src/types/index.ts +3 -0
- package/src/types/media_asset.ts +84 -0
- package/src/useMediaManagerController.tsx +387 -0
- package/src/useMediaManagerPlugin.tsx +114 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import React, { useMemo, createContext, useContext, PropsWithChildren } from "react";
|
|
2
|
+
import { FireCMSPlugin, CMSView, useTranslation } from "@firecms/core";
|
|
3
|
+
import { MediaManagerConfig } from "./types";
|
|
4
|
+
import { MediaManagerProvider } from "./MediaManagerProvider";
|
|
5
|
+
import { useMediaManagerController } from "./useMediaManagerController";
|
|
6
|
+
import { MediaLibraryCard } from "./components/MediaLibraryCard";
|
|
7
|
+
import { MediaLibraryView } from "./components/MediaLibraryView";
|
|
8
|
+
import { mediaManagerTranslationsEn } from "./locales/en";
|
|
9
|
+
import { mediaManagerTranslationsEs } from "./locales/es";
|
|
10
|
+
import { mediaManagerTranslationsDe } from "./locales/de";
|
|
11
|
+
import { mediaManagerTranslationsFr } from "./locales/fr";
|
|
12
|
+
import { mediaManagerTranslationsIt } from "./locales/it";
|
|
13
|
+
import { mediaManagerTranslationsHi } from "./locales/hi";
|
|
14
|
+
import { mediaManagerTranslationsPt } from "./locales/pt";
|
|
15
|
+
|
|
16
|
+
const DEFAULT_STORAGE_PATH = "media";
|
|
17
|
+
const DEFAULT_COLLECTION_PATH = "media_assets";
|
|
18
|
+
|
|
19
|
+
export interface MediaManagerPluginProps extends MediaManagerConfig { }
|
|
20
|
+
|
|
21
|
+
// Context to store the config
|
|
22
|
+
const MediaManagerConfigContext = createContext<MediaManagerConfig | null>(null);
|
|
23
|
+
|
|
24
|
+
function useMediaManagerConfig(): MediaManagerConfig {
|
|
25
|
+
const config = useContext(MediaManagerConfigContext);
|
|
26
|
+
if (!config) {
|
|
27
|
+
throw new Error("useMediaManagerConfig must be used within MediaManagerConfigProvider");
|
|
28
|
+
}
|
|
29
|
+
return config;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Internal wrapper that reads config from context
|
|
34
|
+
*/
|
|
35
|
+
function MediaLibraryViewInternal() {
|
|
36
|
+
const config = useMediaManagerConfig();
|
|
37
|
+
const controller = useMediaManagerController({
|
|
38
|
+
storageSource: config.storageSource,
|
|
39
|
+
dataSourceDelegate: config.dataSourceDelegate,
|
|
40
|
+
storagePath: config.storagePath ?? DEFAULT_STORAGE_PATH,
|
|
41
|
+
collectionPath: config.collectionPath ?? DEFAULT_COLLECTION_PATH,
|
|
42
|
+
bucket: config.bucket,
|
|
43
|
+
thumbnailSizes: config.thumbnailSizes,
|
|
44
|
+
thumbnailPath: config.thumbnailPath
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<MediaManagerProvider controller={controller}>
|
|
49
|
+
<MediaLibraryView
|
|
50
|
+
maxFileSize={config.maxFileSize}
|
|
51
|
+
acceptedMimeTypes={config.acceptedMimeTypes}
|
|
52
|
+
/>
|
|
53
|
+
</MediaManagerProvider>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Build the media view - this is a static object that doesn't change
|
|
59
|
+
*/
|
|
60
|
+
function buildMediaView(): CMSView {
|
|
61
|
+
return {
|
|
62
|
+
path: "media",
|
|
63
|
+
name: "Media Library",
|
|
64
|
+
description: "Manage your media files",
|
|
65
|
+
group: "Media",
|
|
66
|
+
icon: "perm_media",
|
|
67
|
+
view: <MediaLibraryViewInternal />
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Removed static MEDIA_VIEW because it depends on translation
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Hook to create the Media Manager plugin for FireCMS.
|
|
75
|
+
*
|
|
76
|
+
* The plugin automatically registers the Media Library view in the navigation.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```tsx
|
|
80
|
+
* const { plugin: mediaManagerPlugin } = useMediaManagerPlugin({
|
|
81
|
+
* storageSource,
|
|
82
|
+
* dataSourceDelegate: firestoreDelegate,
|
|
83
|
+
* storagePath: "media",
|
|
84
|
+
* collectionPath: "media_assets"
|
|
85
|
+
* });
|
|
86
|
+
*
|
|
87
|
+
* // Add plugin to your plugins array - view is auto-registered
|
|
88
|
+
* const plugins = [mediaManagerPlugin, ...otherPlugins];
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export function useMediaManagerPlugin(props: MediaManagerPluginProps): FireCMSPlugin {
|
|
92
|
+
const mediaView = useMemo(() => buildMediaView(), []);
|
|
93
|
+
|
|
94
|
+
return useMemo(() => ({
|
|
95
|
+
key: "media_manager",
|
|
96
|
+
views: [mediaView],
|
|
97
|
+
provider: {
|
|
98
|
+
Component: ({ children }: PropsWithChildren) => (
|
|
99
|
+
<MediaManagerConfigContext.Provider value={props}>
|
|
100
|
+
{children}
|
|
101
|
+
</MediaManagerConfigContext.Provider>
|
|
102
|
+
)
|
|
103
|
+
},
|
|
104
|
+
i18n: {
|
|
105
|
+
en: mediaManagerTranslationsEn,
|
|
106
|
+
es: mediaManagerTranslationsEs,
|
|
107
|
+
de: mediaManagerTranslationsDe,
|
|
108
|
+
fr: mediaManagerTranslationsFr,
|
|
109
|
+
it: mediaManagerTranslationsIt,
|
|
110
|
+
hi: mediaManagerTranslationsHi,
|
|
111
|
+
pt: mediaManagerTranslationsPt
|
|
112
|
+
}
|
|
113
|
+
} satisfies FireCMSPlugin), []);
|
|
114
|
+
}
|