diff --git a/packages/netlify-cms-core/index.d.ts b/packages/netlify-cms-core/index.d.ts index be4a3835..f0fdefa4 100644 --- a/packages/netlify-cms-core/index.d.ts +++ b/packages/netlify-cms-core/index.d.ts @@ -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; + types?: List; + widget: string; + name: string; + default: string | null | boolean | List; + 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; collection: Map; @@ -549,6 +579,8 @@ declare module 'netlify-cms-core' { getRemarkPlugins: () => Array; 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 | undefined; getWidget: (name: string) => CmsWidget | undefined; diff --git a/packages/netlify-cms-core/src/lib/registry.js b/packages/netlify-cms-core/src/lib/registry.js index 534ccf50..23f07be8 100644 --- a/packages/netlify-cms-core/src/lib/registry.js +++ b/packages/netlify-cms-core/src/lib/registry.js @@ -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}'`);