Expose media files api call
This commit is contained in:
parent
60dc4b09b0
commit
77603a520f
32
packages/netlify-cms-core/index.d.ts
vendored
32
packages/netlify-cms-core/index.d.ts
vendored
@ -528,6 +528,36 @@ declare module 'netlify-cms-core' {
|
||||
fileObj: File;
|
||||
};
|
||||
|
||||
type DisplayURL = { id: string; path: string } | string;
|
||||
|
||||
type EntryField = StaticallyTypedRecord<{
|
||||
field?: EntryField;
|
||||
fields?: List<EntryField>;
|
||||
types?: List<EntryField>;
|
||||
widget: string;
|
||||
name: string;
|
||||
default: string | null | boolean | List<unknown>;
|
||||
media_folder?: string;
|
||||
public_folder?: string;
|
||||
comment?: string;
|
||||
meta?: boolean;
|
||||
i18n: 'translate' | 'duplicate' | 'none';
|
||||
}>;
|
||||
|
||||
interface BackendMediaFile {
|
||||
name: string;
|
||||
id: string;
|
||||
size?: number;
|
||||
displayURL?: DisplayURL;
|
||||
path: string;
|
||||
draft?: boolean;
|
||||
url?: string;
|
||||
file?: File;
|
||||
field?: EntryField;
|
||||
}
|
||||
|
||||
type MediaFile = BackendMediaFile & { key?: string };
|
||||
|
||||
export type PreviewTemplateComponentProps = {
|
||||
entry: Map<string, any>;
|
||||
collection: Map<string, any>;
|
||||
@ -549,6 +579,8 @@ declare module 'netlify-cms-core' {
|
||||
getRemarkPlugins: () => Array<Pluggable>;
|
||||
getLocale: (locale: string) => CmsLocalePhrases | undefined;
|
||||
getMediaLibrary: (name: string) => CmsMediaLibrary | undefined;
|
||||
selectMediaFiles(field?: EntryField | undefined): MediaFile[];
|
||||
resolveWidget: (name: string) => CmsWidget | undefined;
|
||||
getPreviewStyles: () => PreviewStyle[];
|
||||
getPreviewTemplate: (name: string) => ComponentType<PreviewTemplateComponentProps> | undefined;
|
||||
getWidget: (name: string) => CmsWidget | undefined;
|
||||
|
@ -3,6 +3,8 @@ import produce from 'immer';
|
||||
import { oneLine } from 'common-tags';
|
||||
|
||||
import EditorComponent from '../valueObjects/EditorComponent';
|
||||
import { selectMediaFiles as selectMediaFilesSelector } from '../reducers/mediaLibrary';
|
||||
import { store } from '../redux';
|
||||
|
||||
const allowedEvents = [
|
||||
'prePublish',
|
||||
@ -224,6 +226,19 @@ export function getMediaLibrary(name) {
|
||||
return registry.mediaLibraries.find(ml => ml.name === name);
|
||||
}
|
||||
|
||||
export function selectMediaFiles(field) {
|
||||
const state = store.getState();
|
||||
if (state) {
|
||||
return selectMediaFilesSelector(state, field);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
export function getFiles(name) {
|
||||
return registry.mediaLibraries.find(ml => ml.name === name);
|
||||
}
|
||||
|
||||
function validateEventName(name) {
|
||||
if (!allowedEvents.includes(name)) {
|
||||
throw new Error(`Invalid event name '${name}'`);
|
||||
|
Loading…
x
Reference in New Issue
Block a user