@foundrykit/media-plugin 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,55 @@
1
- # Temporary Holding Version
1
+ # @foundrykit/media-plugin
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Media library additions for Payload CMS 3 (3.84+):
4
+
5
+ - **List / Grid switch** on upload collection lists, next to Columns and Filters. Works on the full
6
+ list page and inside the image picker drawer ("Choose from existing"). The choice is remembered
7
+ per browser. In grid view a **Per row** menu sets how many images sit on each row (Auto, or 2–8).
8
+ - **Folders tab in the image picker.** Payload's picker drawer only shows a flat list; this adds a
9
+ Folders tab so editors can browse into `payload-folders` and pick images from inside folders.
10
+ Respects the field's `hasMany` (multi-select on galleries, single select otherwise) and reopens
11
+ in the folder last browsed.
12
+
13
+ ## Install
14
+
15
+ ```sh
16
+ pnpm add @foundrykit/media-plugin
17
+ ```
18
+
19
+ ```ts
20
+ import { mediaPlugin } from '@foundrykit/media-plugin'
21
+
22
+ export default buildConfig({
23
+ // …
24
+ plugins: [mediaPlugin()],
25
+ })
26
+ ```
27
+
28
+ Then regenerate the import map: `pnpm payload generate:importmap`.
29
+
30
+ The Folders tab needs folders turned on for the collection (`folders: true` on the collection
31
+ config), which adds a folder field and so needs a migration on Postgres.
32
+
33
+ ## Options
34
+
35
+ | Option | Default | What it does |
36
+ | -------------- | -------------------------- | ------------------------------------------------- |
37
+ | `collections` | every upload collection | Slugs of the collections to enhance |
38
+ | `gridView` | `true` | List / Grid switch |
39
+ | `folderPicker` | `true` | Folders tab in the picker drawer |
40
+
41
+ A collection that already sets its own `admin.components.views.list` keeps it; the folder picker is
42
+ then skipped for that collection.
43
+
44
+ ## Development
45
+
46
+ ```sh
47
+ pnpm dev # dev app in dev/ on an in-memory Mongo, seeded with a folder of images
48
+ pnpm test:unit # vitest, src/
49
+ pnpm test:int # vitest against the dev config
50
+ pnpm test:e2e # playwright; starts the dev app itself (E2E_PORT to change the port)
51
+ ```
52
+
53
+ Releases: `pnpm release` on `prod` bumps the version from conventional commits, updates the
54
+ changelog and pushes a `v*` tag; `.github/workflows/publish.yml` publishes it to npm with trusted
55
+ publishing.
@@ -0,0 +1,17 @@
1
+ import type { CollectionSlug } from 'payload';
2
+ import React from 'react';
3
+ import './media-plugin.css';
4
+ /**
5
+ * Folder browsing for the picker drawer.
6
+ *
7
+ * Payload already ships every piece of this (the `get-folder-results-component-and-data`
8
+ * server function, `FolderProvider`, the server-rendered results grid) and wires them up
9
+ * for the Move-to-folder drawer — it just never wires them into the list drawer. This is
10
+ * the same assembly, with `onItemClick` selecting a document instead of moving one.
11
+ */
12
+ export declare function FolderPicker({ allowMultiSelect, collectionSlug, list, }: {
13
+ /** True when the field takes several media items — mirrors the list's `enableRowSelections`. */
14
+ allowMultiSelect?: boolean;
15
+ collectionSlug: CollectionSlug;
16
+ list: React.ReactNode;
17
+ }): string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null | undefined;
@@ -0,0 +1,247 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { Button, FolderProvider, LoadingOverlay, Pill, useConfig, useFolder, useListDrawerContext, useModal, useServerFunctions, useTranslation, XIcon } from '@payloadcms/ui';
4
+ import { FolderBreadcrumbs } from '@payloadcms/ui/elements/FolderView/Breadcrumbs';
5
+ import { ColoredFolderIcon } from '@payloadcms/ui/elements/FolderView/ColoredFolderIcon';
6
+ import React from 'react';
7
+ import './media-plugin.css';
8
+ const baseClass = 'media-folder-picker';
9
+ /**
10
+ * The folder each collection's picker was last browsing, so reopening the drawer lands back
11
+ * where the editor was instead of at the root. Module scope rather than state: the picker
12
+ * unmounts with the drawer every time.
13
+ *
14
+ * ponytail: in-memory, so a page reload resets it. Move to sessionStorage if that matters.
15
+ */ const lastFolderID = new Map();
16
+ /**
17
+ * Folder browsing for the picker drawer.
18
+ *
19
+ * Payload already ships every piece of this (the `get-folder-results-component-and-data`
20
+ * server function, `FolderProvider`, the server-rendered results grid) and wires them up
21
+ * for the Move-to-folder drawer — it just never wires them into the list drawer. This is
22
+ * the same assembly, with `onItemClick` selecting a document instead of moving one.
23
+ */ export function FolderPicker({ allowMultiSelect = false, collectionSlug, list }) {
24
+ const { config } = useConfig();
25
+ const { drawerSlug, onBulkSelect, onSelect } = useListDrawerContext();
26
+ const { getFolderResultsComponentAndData } = useServerFunctions();
27
+ const { t } = useTranslation();
28
+ const folders = config.folders;
29
+ const [browsing, setBrowsing] = React.useState(false);
30
+ const [folderID, setFolderID] = React.useState(null);
31
+ const [results, setResults] = React.useState(null);
32
+ const folderSlug = folders ? folders.slug : undefined;
33
+ const openFolder = React.useCallback(async (id)=>{
34
+ if (!folderSlug) {
35
+ return;
36
+ }
37
+ setResults(null);
38
+ const load = (target)=>getFolderResultsComponentAndData({
39
+ browseByFolder: false,
40
+ collectionsToDisplay: [
41
+ folderSlug,
42
+ collectionSlug
43
+ ],
44
+ displayAs: 'grid',
45
+ folderAssignedCollections: [
46
+ collectionSlug
47
+ ],
48
+ folderID: target ?? undefined,
49
+ sort: 'name'
50
+ });
51
+ // A remembered folder can have been deleted or renamed since; drop back to the root
52
+ // rather than leaving the picker stuck on an error.
53
+ let resolvedID = id;
54
+ let result = await load(id).catch(()=>null);
55
+ if (!result && id !== null) {
56
+ resolvedID = null;
57
+ result = await load(null).catch(()=>null);
58
+ }
59
+ setFolderID(resolvedID);
60
+ lastFolderID.set(collectionSlug, resolvedID);
61
+ setResults({
62
+ breadcrumbs: result?.breadcrumbs || [],
63
+ documents: result?.documents || [],
64
+ FolderResultsComponent: result?.FolderResultsComponent || null,
65
+ subfolders: result?.subfolders || []
66
+ });
67
+ }, [
68
+ collectionSlug,
69
+ folderSlug,
70
+ getFolderResultsComponentAndData
71
+ ]);
72
+ React.useEffect(()=>{
73
+ void openFolder(lastFolderID.get(collectionSlug) ?? null);
74
+ }, [
75
+ openFolder,
76
+ collectionSlug
77
+ ]);
78
+ /**
79
+ * One document goes through `onSelect`; several through `onBulkSelect`, which is what the
80
+ * upload field's own list rows use (it takes a Map of id -> isSelected). Both append rather
81
+ * than replace on a hasMany field, so a double-click still behaves the same either way.
82
+ */ const selectItems = React.useCallback((items)=>{
83
+ if (items.length === 0) {
84
+ return;
85
+ }
86
+ if (items.length > 1 && typeof onBulkSelect === 'function') {
87
+ onBulkSelect(new Map(items.map((item)=>[
88
+ item.value.id,
89
+ true
90
+ ])));
91
+ return;
92
+ }
93
+ const item = items[0];
94
+ if (item && typeof onSelect === 'function') {
95
+ onSelect({
96
+ collectionSlug: item.relationTo,
97
+ doc: item.value,
98
+ docID: String(item.value.id)
99
+ });
100
+ }
101
+ }, [
102
+ onBulkSelect,
103
+ onSelect
104
+ ]);
105
+ // Folders disabled for this collection — nothing to browse, leave the list alone.
106
+ if (!folders || !folderSlug) {
107
+ return list;
108
+ }
109
+ return /*#__PURE__*/ _jsxs("div", {
110
+ className: baseClass,
111
+ children: [
112
+ /*#__PURE__*/ _jsxs("div", {
113
+ className: `${baseClass}__tabs`,
114
+ children: [
115
+ /*#__PURE__*/ _jsxs("div", {
116
+ className: `${baseClass}__tab-group`,
117
+ children: [
118
+ /*#__PURE__*/ _jsx(Pill, {
119
+ onClick: ()=>setBrowsing(false),
120
+ pillStyle: browsing ? 'light' : 'dark',
121
+ children: t('general:all')
122
+ }),
123
+ /*#__PURE__*/ _jsx(Pill, {
124
+ onClick: ()=>setBrowsing(true),
125
+ pillStyle: browsing ? 'dark' : 'light',
126
+ children: t('folder:folders')
127
+ })
128
+ ]
129
+ }),
130
+ browsing && drawerSlug ? /*#__PURE__*/ _jsx(CloseDrawerButton, {
131
+ slug: drawerSlug
132
+ }) : null
133
+ ]
134
+ }),
135
+ /*#__PURE__*/ _jsx("div", {
136
+ hidden: browsing,
137
+ children: list
138
+ }),
139
+ browsing ? !results ? /*#__PURE__*/ _jsx(LoadingOverlay, {}) : /*#__PURE__*/ _jsx(FolderProvider, {
140
+ allCollectionFolderSlugs: [
141
+ folderSlug,
142
+ collectionSlug
143
+ ],
144
+ allowCreateCollectionSlugs: [],
145
+ allowMultiSelection: allowMultiSelect,
146
+ breadcrumbs: results.breadcrumbs,
147
+ documents: results.documents,
148
+ folderFieldName: folders.fieldName,
149
+ folderID: folderID ?? undefined,
150
+ FolderResultsComponent: results.FolderResultsComponent,
151
+ onItemClick: (item)=>{
152
+ if (!item) {
153
+ return;
154
+ }
155
+ if (item.relationTo === folderSlug) {
156
+ void openFolder(item.value.id);
157
+ } else {
158
+ selectItems([
159
+ item
160
+ ]);
161
+ }
162
+ },
163
+ subfolders: results.subfolders,
164
+ children: /*#__PURE__*/ _jsx(Results, {
165
+ folderSlug: folderSlug,
166
+ onNavigate: openFolder,
167
+ onSelect: selectItems
168
+ })
169
+ }, String(folderID)) : null
170
+ ]
171
+ });
172
+ }
173
+ /**
174
+ * Stands in for `@payloadcms/ui/elements/CloseModalButton`. That deep import pulls in its own
175
+ * copy of `@faceless-ui/modal`, whose context has no provider, so `closeModal` is undefined and
176
+ * the click throws. `useModal` from the package root reads the provider the admin renders.
177
+ */ function CloseDrawerButton({ slug }) {
178
+ const { closeModal } = useModal();
179
+ const { t } = useTranslation();
180
+ return /*#__PURE__*/ _jsx("button", {
181
+ "aria-label": t('general:close'),
182
+ className: `close-modal-button ${baseClass}__close`,
183
+ onClick: ()=>closeModal(slug),
184
+ type: "button",
185
+ children: /*#__PURE__*/ _jsx(XIcon, {})
186
+ });
187
+ }
188
+ function Results({ folderSlug, onNavigate, onSelect }) {
189
+ const folder = useFolder();
190
+ const { t } = useTranslation();
191
+ const breadcrumbs = folder.breadcrumbs || [];
192
+ const documents = folder.documents || [];
193
+ const subfolders = folder.subfolders || [];
194
+ // Subfolders can be highlighted alongside documents; only documents are selectable here.
195
+ const selectedDocs = (folder.getSelectedItems?.() || []).filter((item)=>item.relationTo !== folderSlug);
196
+ return /*#__PURE__*/ _jsxs(_Fragment, {
197
+ children: [
198
+ /*#__PURE__*/ _jsxs("div", {
199
+ className: `${baseClass}__toolbar`,
200
+ children: [
201
+ /*#__PURE__*/ _jsx(FolderBreadcrumbs, {
202
+ breadcrumbs: [
203
+ {
204
+ id: null,
205
+ name: /*#__PURE__*/ _jsxs("span", {
206
+ className: `${baseClass}__root-crumb`,
207
+ children: [
208
+ /*#__PURE__*/ _jsx(ColoredFolderIcon, {}),
209
+ t('folder:folders')
210
+ ]
211
+ }),
212
+ onClick: ()=>void onNavigate(null)
213
+ },
214
+ ...breadcrumbs.map((crumb, index)=>({
215
+ id: crumb.id,
216
+ name: crumb.name,
217
+ // The last crumb is where we already are — rendered as plain text.
218
+ onClick: index !== breadcrumbs.length - 1 ? ()=>void onNavigate(crumb.id) : undefined
219
+ }))
220
+ ]
221
+ }),
222
+ /*#__PURE__*/ _jsx(Button, {
223
+ buttonStyle: "primary",
224
+ disabled: selectedDocs.length === 0,
225
+ margin: false,
226
+ onClick: ()=>onSelect(selectedDocs),
227
+ size: "small",
228
+ children: selectedDocs.length > 1 ? `${t('general:select')} (${selectedDocs.length})` : t('general:select')
229
+ })
230
+ ]
231
+ }),
232
+ subfolders.length + documents.length > 0 ? folder.FolderResultsComponent : /*#__PURE__*/ _jsxs("div", {
233
+ className: `${baseClass}__empty`,
234
+ children: [
235
+ /*#__PURE__*/ _jsx("h3", {
236
+ children: t('general:noResultsFound')
237
+ }),
238
+ /*#__PURE__*/ _jsx("p", {
239
+ children: t('general:noResultsDescription')
240
+ })
241
+ ]
242
+ })
243
+ ]
244
+ });
245
+ }
246
+
247
+ //# sourceMappingURL=FolderPicker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/FolderPicker.tsx"],"sourcesContent":["'use client'\n\nimport type { CollectionSlug } from 'payload'\nimport type { FolderBreadcrumb, FolderOrDocument } from 'payload/shared'\n\nimport {\n Button,\n FolderProvider,\n LoadingOverlay,\n Pill,\n useConfig,\n useFolder,\n useListDrawerContext,\n useModal,\n useServerFunctions,\n useTranslation,\n XIcon,\n} from '@payloadcms/ui'\nimport { FolderBreadcrumbs } from '@payloadcms/ui/elements/FolderView/Breadcrumbs'\nimport { ColoredFolderIcon } from '@payloadcms/ui/elements/FolderView/ColoredFolderIcon'\nimport React from 'react'\n\nimport './media-plugin.css'\n\nconst baseClass = 'media-folder-picker'\n\n/**\n * The folder each collection's picker was last browsing, so reopening the drawer lands back\n * where the editor was instead of at the root. Module scope rather than state: the picker\n * unmounts with the drawer every time.\n *\n * ponytail: in-memory, so a page reload resets it. Move to sessionStorage if that matters.\n */\nconst lastFolderID = new Map<string, null | number | string>()\n\ntype Results = {\n breadcrumbs: FolderBreadcrumb[]\n documents: FolderOrDocument[]\n FolderResultsComponent: React.ReactNode\n subfolders: FolderOrDocument[]\n}\n\n/**\n * Folder browsing for the picker drawer.\n *\n * Payload already ships every piece of this (the `get-folder-results-component-and-data`\n * server function, `FolderProvider`, the server-rendered results grid) and wires them up\n * for the Move-to-folder drawer — it just never wires them into the list drawer. This is\n * the same assembly, with `onItemClick` selecting a document instead of moving one.\n */\nexport function FolderPicker({\n allowMultiSelect = false,\n collectionSlug,\n list,\n}: {\n /** True when the field takes several media items — mirrors the list's `enableRowSelections`. */\n allowMultiSelect?: boolean\n collectionSlug: CollectionSlug\n list: React.ReactNode\n}) {\n const { config } = useConfig()\n const { drawerSlug, onBulkSelect, onSelect } = useListDrawerContext()\n const { getFolderResultsComponentAndData } = useServerFunctions()\n const { t } = useTranslation()\n\n const folders = config.folders\n const [browsing, setBrowsing] = React.useState(false)\n const [folderID, setFolderID] = React.useState<null | number | string>(null)\n const [results, setResults] = React.useState<null | Results>(null)\n\n const folderSlug = (folders ? folders.slug : undefined)\n\n const openFolder = React.useCallback(\n async (id: null | number | string) => {\n if (!folderSlug) {\n return\n }\n\n setResults(null)\n\n const load = (target: null | number | string) =>\n getFolderResultsComponentAndData({\n browseByFolder: false,\n collectionsToDisplay: [folderSlug, collectionSlug],\n displayAs: 'grid',\n folderAssignedCollections: [collectionSlug],\n folderID: target ?? undefined,\n sort: 'name',\n })\n\n // A remembered folder can have been deleted or renamed since; drop back to the root\n // rather than leaving the picker stuck on an error.\n let resolvedID = id\n let result = await load(id).catch(() => null)\n if (!result && id !== null) {\n resolvedID = null\n result = await load(null).catch(() => null)\n }\n\n setFolderID(resolvedID)\n lastFolderID.set(collectionSlug, resolvedID)\n setResults({\n breadcrumbs: result?.breadcrumbs || [],\n documents: result?.documents || [],\n FolderResultsComponent: result?.FolderResultsComponent || null,\n subfolders: result?.subfolders || [],\n })\n },\n [collectionSlug, folderSlug, getFolderResultsComponentAndData],\n )\n\n React.useEffect(() => {\n void openFolder(lastFolderID.get(collectionSlug) ?? null)\n }, [openFolder, collectionSlug])\n\n /**\n * One document goes through `onSelect`; several through `onBulkSelect`, which is what the\n * upload field's own list rows use (it takes a Map of id -> isSelected). Both append rather\n * than replace on a hasMany field, so a double-click still behaves the same either way.\n */\n const selectItems = React.useCallback(\n (items: FolderOrDocument[]) => {\n if (items.length === 0) {\n return\n }\n\n if (items.length > 1 && typeof onBulkSelect === 'function') {\n onBulkSelect(new Map(items.map((item) => [item.value.id, true])))\n return\n }\n\n const item = items[0]\n if (item && typeof onSelect === 'function') {\n onSelect({\n collectionSlug: item.relationTo,\n doc: item.value,\n docID: String(item.value.id),\n })\n }\n },\n [onBulkSelect, onSelect],\n )\n\n // Folders disabled for this collection — nothing to browse, leave the list alone.\n if (!folders || !folderSlug) {\n return list\n }\n\n return (\n <div className={baseClass}>\n <div className={`${baseClass}__tabs`}>\n <div className={`${baseClass}__tab-group`}>\n <Pill onClick={() => setBrowsing(false)} pillStyle={browsing ? 'light' : 'dark'}>\n {t('general:all')}\n </Pill>\n <Pill onClick={() => setBrowsing(true)} pillStyle={browsing ? 'dark' : 'light'}>\n {t('folder:folders')}\n </Pill>\n </div>\n {/* The stock list header carries its own close button; ours stands in while it is hidden. */}\n {browsing && drawerSlug ? <CloseDrawerButton slug={drawerSlug} /> : null}\n </div>\n\n <div hidden={browsing}>{list}</div>\n\n {browsing ? (\n !results ? (\n <LoadingOverlay />\n ) : (\n <FolderProvider\n allCollectionFolderSlugs={[folderSlug, collectionSlug]}\n allowCreateCollectionSlugs={[]}\n allowMultiSelection={allowMultiSelect}\n breadcrumbs={results.breadcrumbs}\n documents={results.documents}\n folderFieldName={folders.fieldName}\n folderID={folderID ?? undefined}\n FolderResultsComponent={results.FolderResultsComponent}\n key={String(folderID)}\n onItemClick={(item) => {\n if (!item) {\n return\n }\n if (item.relationTo === folderSlug) {\n void openFolder(item.value.id)\n } else {\n selectItems([item])\n }\n }}\n subfolders={results.subfolders}\n >\n <Results folderSlug={folderSlug} onNavigate={openFolder} onSelect={selectItems} />\n </FolderProvider>\n )\n ) : null}\n </div>\n )\n}\n\n/**\n * Stands in for `@payloadcms/ui/elements/CloseModalButton`. That deep import pulls in its own\n * copy of `@faceless-ui/modal`, whose context has no provider, so `closeModal` is undefined and\n * the click throws. `useModal` from the package root reads the provider the admin renders.\n */\nfunction CloseDrawerButton({ slug }: { slug: string }) {\n const { closeModal } = useModal()\n const { t } = useTranslation()\n\n return (\n <button\n aria-label={t('general:close')}\n className={`close-modal-button ${baseClass}__close`}\n onClick={() => closeModal(slug)}\n type=\"button\"\n >\n <XIcon />\n </button>\n )\n}\n\nfunction Results({\n folderSlug,\n onNavigate,\n onSelect,\n}: {\n folderSlug: CollectionSlug\n onNavigate: (id: null | number | string) => Promise<void>\n onSelect: (items: FolderOrDocument[]) => void\n}) {\n const folder = useFolder()\n const { t } = useTranslation()\n\n const breadcrumbs = folder.breadcrumbs || []\n const documents = folder.documents || []\n const subfolders = folder.subfolders || []\n // Subfolders can be highlighted alongside documents; only documents are selectable here.\n const selectedDocs = (folder.getSelectedItems?.() || []).filter(\n (item) => item.relationTo !== folderSlug,\n )\n\n return (\n <>\n <div className={`${baseClass}__toolbar`}>\n <FolderBreadcrumbs\n breadcrumbs={\n [\n {\n id: null,\n name: (\n <span className={`${baseClass}__root-crumb`}>\n <ColoredFolderIcon />\n {t('folder:folders')}\n </span>\n ),\n onClick: () => void onNavigate(null),\n },\n ...breadcrumbs.map((crumb, index) => ({\n id: crumb.id,\n name: crumb.name,\n // The last crumb is where we already are — rendered as plain text.\n onClick:\n index !== breadcrumbs.length - 1 ? () => void onNavigate(crumb.id) : undefined,\n })),\n // `onClick` is optional at runtime: a crumb without one renders unclickable.\n ] as React.ComponentProps<typeof FolderBreadcrumbs>['breadcrumbs']\n }\n />\n <Button\n buttonStyle=\"primary\"\n disabled={selectedDocs.length === 0}\n margin={false}\n onClick={() => onSelect(selectedDocs)}\n size=\"small\"\n >\n {selectedDocs.length > 1\n ? `${t('general:select')} (${selectedDocs.length})`\n : t('general:select')}\n </Button>\n </div>\n\n {subfolders.length + documents.length > 0 ? (\n folder.FolderResultsComponent\n ) : (\n <div className={`${baseClass}__empty`}>\n <h3>{t('general:noResultsFound')}</h3>\n <p>{t('general:noResultsDescription')}</p>\n </div>\n )}\n </>\n )\n}\n"],"names":["Button","FolderProvider","LoadingOverlay","Pill","useConfig","useFolder","useListDrawerContext","useModal","useServerFunctions","useTranslation","XIcon","FolderBreadcrumbs","ColoredFolderIcon","React","baseClass","lastFolderID","Map","FolderPicker","allowMultiSelect","collectionSlug","list","config","drawerSlug","onBulkSelect","onSelect","getFolderResultsComponentAndData","t","folders","browsing","setBrowsing","useState","folderID","setFolderID","results","setResults","folderSlug","slug","undefined","openFolder","useCallback","id","load","target","browseByFolder","collectionsToDisplay","displayAs","folderAssignedCollections","sort","resolvedID","result","catch","set","breadcrumbs","documents","FolderResultsComponent","subfolders","useEffect","get","selectItems","items","length","map","item","value","relationTo","doc","docID","String","div","className","onClick","pillStyle","CloseDrawerButton","hidden","allCollectionFolderSlugs","allowCreateCollectionSlugs","allowMultiSelection","folderFieldName","fieldName","onItemClick","Results","onNavigate","closeModal","button","aria-label","type","folder","selectedDocs","getSelectedItems","filter","name","span","crumb","index","buttonStyle","disabled","margin","size","h3","p"],"mappings":"AAAA;;AAKA,SACEA,MAAM,EACNC,cAAc,EACdC,cAAc,EACdC,IAAI,EACJC,SAAS,EACTC,SAAS,EACTC,oBAAoB,EACpBC,QAAQ,EACRC,kBAAkB,EAClBC,cAAc,EACdC,KAAK,QACA,iBAAgB;AACvB,SAASC,iBAAiB,QAAQ,iDAAgD;AAClF,SAASC,iBAAiB,QAAQ,uDAAsD;AACxF,OAAOC,WAAW,QAAO;AAEzB,OAAO,qBAAoB;AAE3B,MAAMC,YAAY;AAElB;;;;;;CAMC,GACD,MAAMC,eAAe,IAAIC;AASzB;;;;;;;CAOC,GACD,OAAO,SAASC,aAAa,EAC3BC,mBAAmB,KAAK,EACxBC,cAAc,EACdC,IAAI,EAML;IACC,MAAM,EAAEC,MAAM,EAAE,GAAGjB;IACnB,MAAM,EAAEkB,UAAU,EAAEC,YAAY,EAAEC,QAAQ,EAAE,GAAGlB;IAC/C,MAAM,EAAEmB,gCAAgC,EAAE,GAAGjB;IAC7C,MAAM,EAAEkB,CAAC,EAAE,GAAGjB;IAEd,MAAMkB,UAAUN,OAAOM,OAAO;IAC9B,MAAM,CAACC,UAAUC,YAAY,GAAGhB,MAAMiB,QAAQ,CAAC;IAC/C,MAAM,CAACC,UAAUC,YAAY,GAAGnB,MAAMiB,QAAQ,CAAyB;IACvE,MAAM,CAACG,SAASC,WAAW,GAAGrB,MAAMiB,QAAQ,CAAiB;IAE7D,MAAMK,aAAcR,UAAUA,QAAQS,IAAI,GAAGC;IAE7C,MAAMC,aAAazB,MAAM0B,WAAW,CAClC,OAAOC;QACL,IAAI,CAACL,YAAY;YACf;QACF;QAEAD,WAAW;QAEX,MAAMO,OAAO,CAACC,SACZjB,iCAAiC;gBAC/BkB,gBAAgB;gBAChBC,sBAAsB;oBAACT;oBAA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9C,SAAS+D;wBACxBU,MAAK;kCAEJV,aAAa3B,MAAM,GAAG,IACnB,GAAGlC,EAAE,kBAAkB,EAAE,EAAE6D,aAAa3B,MAAM,CAAC,CAAC,CAAC,GACjDlC,EAAE;;;;YAIT6B,WAAWK,MAAM,GAAGP,UAAUO,MAAM,GAAG,IACtC0B,OAAOhC,sBAAsB,iBAE7B,MAACc;gBAAIC,WAAW,GAAGvD,UAAU,OAAO,CAAC;;kCACnC,KAACoF;kCAAIxE,EAAE;;kCACP,KAACyE;kCAAGzE,EAAE;;;;;;AAKhB"}
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom/vitest';
@@ -0,0 +1,15 @@
1
+ import type { ListViewClientProps } from 'payload';
2
+ /**
3
+ * List view for upload collections.
4
+ *
5
+ * On the full-page list view this is Payload's stock list — it already has its own
6
+ * List/Folders tabs. Inside a drawer (the image picker on every upload field) Payload
7
+ * renders the flat list with no way into the folder tree, so we add a Folders tab that
8
+ * browses `payload-folders` and selects a document straight back into the field.
9
+ *
10
+ * `enableRowSelections` is how the upload field says it takes several items: it is set from
11
+ * the field's own `hasMany` (see ListDrawer in @payloadcms/ui fields/Upload/Input). Passing it
12
+ * through keeps the folder tab in step with the flat list — multi-select on a gallery field,
13
+ * single select everywhere else.
14
+ */
15
+ export declare function MediaListView(props: ListViewClientProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,33 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { DefaultListView, useListDrawerContext } from '@payloadcms/ui';
4
+ import { FolderPicker } from './FolderPicker.js';
5
+ /**
6
+ * List view for upload collections.
7
+ *
8
+ * On the full-page list view this is Payload's stock list — it already has its own
9
+ * List/Folders tabs. Inside a drawer (the image picker on every upload field) Payload
10
+ * renders the flat list with no way into the folder tree, so we add a Folders tab that
11
+ * browses `payload-folders` and selects a document straight back into the field.
12
+ *
13
+ * `enableRowSelections` is how the upload field says it takes several items: it is set from
14
+ * the field's own `hasMany` (see ListDrawer in @payloadcms/ui fields/Upload/Input). Passing it
15
+ * through keeps the folder tab in step with the flat list — multi-select on a gallery field,
16
+ * single select everywhere else.
17
+ */ export function MediaListView(props) {
18
+ const { isInDrawer } = useListDrawerContext();
19
+ if (!isInDrawer) {
20
+ return /*#__PURE__*/ _jsx(DefaultListView, {
21
+ ...props
22
+ });
23
+ }
24
+ return /*#__PURE__*/ _jsx(FolderPicker, {
25
+ allowMultiSelect: props.enableRowSelections === true,
26
+ collectionSlug: props.collectionSlug,
27
+ list: /*#__PURE__*/ _jsx(DefaultListView, {
28
+ ...props
29
+ })
30
+ });
31
+ }
32
+
33
+ //# sourceMappingURL=MediaListView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/MediaListView.tsx"],"sourcesContent":["'use client'\n\nimport type { ListViewClientProps } from 'payload'\n\nimport { DefaultListView, useListDrawerContext } from '@payloadcms/ui'\n\nimport { FolderPicker } from './FolderPicker.js'\n\n/**\n * List view for upload collections.\n *\n * On the full-page list view this is Payload's stock list — it already has its own\n * List/Folders tabs. Inside a drawer (the image picker on every upload field) Payload\n * renders the flat list with no way into the folder tree, so we add a Folders tab that\n * browses `payload-folders` and selects a document straight back into the field.\n *\n * `enableRowSelections` is how the upload field says it takes several items: it is set from\n * the field's own `hasMany` (see ListDrawer in @payloadcms/ui fields/Upload/Input). Passing it\n * through keeps the folder tab in step with the flat list — multi-select on a gallery field,\n * single select everywhere else.\n */\nexport function MediaListView(props: ListViewClientProps) {\n const { isInDrawer } = useListDrawerContext()\n\n if (!isInDrawer) {\n return <DefaultListView {...props} />\n }\n\n return (\n <FolderPicker\n allowMultiSelect={props.enableRowSelections === true}\n collectionSlug={props.collectionSlug}\n list={<DefaultListView {...props} />}\n />\n )\n}\n"],"names":["DefaultListView","useListDrawerContext","FolderPicker","MediaListView","props","isInDrawer","allowMultiSelect","enableRowSelections","collectionSlug","list"],"mappings":"AAAA;;AAIA,SAASA,eAAe,EAAEC,oBAAoB,QAAQ,iBAAgB;AAEtE,SAASC,YAAY,QAAQ,oBAAmB;AAEhD;;;;;;;;;;;;CAYC,GACD,OAAO,SAASC,cAAcC,KAA0B;IACtD,MAAM,EAAEC,UAAU,EAAE,GAAGJ;IAEvB,IAAI,CAACI,YAAY;QACf,qBAAO,KAACL;YAAiB,GAAGI,KAAK;;IACnC;IAEA,qBACE,KAACF;QACCI,kBAAkBF,MAAMG,mBAAmB,KAAK;QAChDC,gBAAgBJ,MAAMI,cAAc;QACpCC,oBAAM,KAACT;YAAiB,GAAGI,KAAK;;;AAGtC"}
@@ -0,0 +1,11 @@
1
+ import './media-plugin.css';
2
+ /**
3
+ * List / Grid beside Columns and Filters on an upload collection's list, on the full page and
4
+ * in the picker drawer. It is Payload's own toggle from the By Folder view, so both views switch
5
+ * the same way. Payload has no slot there, so it is portalled into the search bar of
6
+ * the list this renders in (found from its own position, so a drawer open over the list page
7
+ * gets its own switch). In grid view a "Per row" menu sets how many cards sit on each row. Both
8
+ * choices are remembered per browser and set on the list as `data-media-view` and
9
+ * `--media-grid-columns`; the grid itself is CSS over the same table (media-plugin.css).
10
+ */
11
+ export declare function MediaViews(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,124 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { ChevronIcon, Pill, Popup, PopupList } from '@payloadcms/ui';
4
+ import { ToggleViewButtons } from '@payloadcms/ui/elements/FolderView/ToggleViewButtons';
5
+ import { useEffect, useRef, useState } from 'react';
6
+ import { createPortal } from 'react-dom';
7
+ import './media-plugin.css';
8
+ const KEY = 'foundrykit-media-view';
9
+ const COLUMNS_KEY = 'foundrykit-media-columns';
10
+ /** Cards per row in the grid. 0 is "Auto": as many as fit at the minimum card width. */ const COLUMNS = [
11
+ 0,
12
+ 2,
13
+ 3,
14
+ 4,
15
+ 5,
16
+ 6,
17
+ 8
18
+ ];
19
+ const read = (key)=>{
20
+ try {
21
+ return localStorage.getItem(key);
22
+ } catch {
23
+ // Storage can be blocked (private window); the defaults stand.
24
+ return null;
25
+ }
26
+ };
27
+ const write = (key, value)=>{
28
+ try {
29
+ localStorage.setItem(key, value);
30
+ } catch {
31
+ // As above: the choice just isn't remembered.
32
+ }
33
+ };
34
+ /**
35
+ * List / Grid beside Columns and Filters on an upload collection's list, on the full page and
36
+ * in the picker drawer. It is Payload's own toggle from the By Folder view, so both views switch
37
+ * the same way. Payload has no slot there, so it is portalled into the search bar of
38
+ * the list this renders in (found from its own position, so a drawer open over the list page
39
+ * gets its own switch). In grid view a "Per row" menu sets how many cards sit on each row. Both
40
+ * choices are remembered per browser and set on the list as `data-media-view` and
41
+ * `--media-grid-columns`; the grid itself is CSS over the same table (media-plugin.css).
42
+ */ export function MediaViews() {
43
+ const anchor = useRef(null);
44
+ const [list, setList] = useState(null);
45
+ const [view, setView] = useState('list');
46
+ const [columns, setColumns] = useState(0);
47
+ useEffect(()=>{
48
+ setList(anchor.current?.closest('.collection-list') ?? null);
49
+ if (read(KEY) === 'grid') {
50
+ setView('grid');
51
+ }
52
+ const saved = Number(read(COLUMNS_KEY));
53
+ if (COLUMNS.includes(saved)) {
54
+ setColumns(saved);
55
+ }
56
+ }, []);
57
+ useEffect(()=>{
58
+ if (!list) {
59
+ return;
60
+ }
61
+ list.dataset.mediaView = view;
62
+ if (columns) {
63
+ list.style.setProperty('--media-grid-columns', String(columns));
64
+ } else {
65
+ list.style.removeProperty('--media-grid-columns');
66
+ }
67
+ }, [
68
+ list,
69
+ view,
70
+ columns
71
+ ]);
72
+ const choose = (v)=>{
73
+ setView(v);
74
+ write(KEY, v);
75
+ };
76
+ const chooseColumns = (n)=>{
77
+ setColumns(n);
78
+ write(COLUMNS_KEY, String(n));
79
+ };
80
+ const target = list?.querySelector('.search-bar__actions');
81
+ return /*#__PURE__*/ _jsxs(_Fragment, {
82
+ children: [
83
+ /*#__PURE__*/ _jsx("span", {
84
+ hidden: true,
85
+ ref: anchor
86
+ }),
87
+ target ? /*#__PURE__*/ createPortal(/*#__PURE__*/ _jsxs(_Fragment, {
88
+ children: [
89
+ view === 'grid' ? /*#__PURE__*/ _jsx(Popup, {
90
+ button: /*#__PURE__*/ _jsxs(Pill, {
91
+ icon: /*#__PURE__*/ _jsx(ChevronIcon, {}),
92
+ pillStyle: "light",
93
+ size: "small",
94
+ children: [
95
+ "Per row: ",
96
+ columns || 'Auto'
97
+ ]
98
+ }),
99
+ buttonType: "custom",
100
+ className: "media-views__columns",
101
+ horizontalAlign: "right",
102
+ render: ({ close })=>/*#__PURE__*/ _jsx(PopupList.ButtonGroup, {
103
+ children: COLUMNS.map((n)=>/*#__PURE__*/ _jsx(PopupList.Button, {
104
+ active: n === columns,
105
+ onClick: ()=>{
106
+ chooseColumns(n);
107
+ close();
108
+ },
109
+ children: n || 'Auto'
110
+ }, n))
111
+ }),
112
+ size: "small"
113
+ }) : null,
114
+ /*#__PURE__*/ _jsx(ToggleViewButtons, {
115
+ activeView: view,
116
+ setActiveView: choose
117
+ })
118
+ ]
119
+ }), target) : null
120
+ ]
121
+ });
122
+ }
123
+
124
+ //# sourceMappingURL=MediaViews.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/MediaViews.tsx"],"sourcesContent":["'use client'\n\nimport { ChevronIcon, Pill, Popup, PopupList } from '@payloadcms/ui'\nimport { ToggleViewButtons } from '@payloadcms/ui/elements/FolderView/ToggleViewButtons'\nimport { useEffect, useRef, useState } from 'react'\nimport { createPortal } from 'react-dom'\n\nimport './media-plugin.css'\n\ntype View = 'grid' | 'list'\nconst KEY = 'foundrykit-media-view'\nconst COLUMNS_KEY = 'foundrykit-media-columns'\n/** Cards per row in the grid. 0 is \"Auto\": as many as fit at the minimum card width. */\nconst COLUMNS = [0, 2, 3, 4, 5, 6, 8]\n\nconst read = (key: string) => {\n try {\n return localStorage.getItem(key)\n } catch {\n // Storage can be blocked (private window); the defaults stand.\n return null\n }\n}\nconst write = (key: string, value: string) => {\n try {\n localStorage.setItem(key, value)\n } catch {\n // As above: the choice just isn't remembered.\n }\n}\n\n/**\n * List / Grid beside Columns and Filters on an upload collection's list, on the full page and\n * in the picker drawer. It is Payload's own toggle from the By Folder view, so both views switch\n * the same way. Payload has no slot there, so it is portalled into the search bar of\n * the list this renders in (found from its own position, so a drawer open over the list page\n * gets its own switch). In grid view a \"Per row\" menu sets how many cards sit on each row. Both\n * choices are remembered per browser and set on the list as `data-media-view` and\n * `--media-grid-columns`; the grid itself is CSS over the same table (media-plugin.css).\n */\nexport function MediaViews() {\n const anchor = useRef<HTMLSpanElement>(null)\n const [list, setList] = useState<HTMLElement | null>(null)\n const [view, setView] = useState<View>('list')\n const [columns, setColumns] = useState(0)\n\n useEffect(() => {\n setList(anchor.current?.closest<HTMLElement>('.collection-list') ?? null)\n if (read(KEY) === 'grid') {\n setView('grid')\n }\n const saved = Number(read(COLUMNS_KEY))\n if (COLUMNS.includes(saved)) {\n setColumns(saved)\n }\n }, [])\n\n useEffect(() => {\n if (!list) {\n return\n }\n list.dataset.mediaView = view\n if (columns) {\n list.style.setProperty('--media-grid-columns', String(columns))\n } else {\n list.style.removeProperty('--media-grid-columns')\n }\n }, [list, view, columns])\n\n const choose = (v: View) => {\n setView(v)\n write(KEY, v)\n }\n\n const chooseColumns = (n: number) => {\n setColumns(n)\n write(COLUMNS_KEY, String(n))\n }\n\n const target = list?.querySelector('.search-bar__actions')\n\n return (\n <>\n <span hidden ref={anchor} />\n {target\n ? createPortal(\n <>\n {view === 'grid' ? (\n <Popup\n button={\n <Pill icon={<ChevronIcon />} pillStyle=\"light\" size=\"small\">\n Per row: {columns || 'Auto'}\n </Pill>\n }\n buttonType=\"custom\"\n className=\"media-views__columns\"\n horizontalAlign=\"right\"\n render={({ close }) => (\n <PopupList.ButtonGroup>\n {COLUMNS.map((n) => (\n <PopupList.Button\n active={n === columns}\n key={n}\n onClick={() => {\n chooseColumns(n)\n close()\n }}\n >\n {n || 'Auto'}\n </PopupList.Button>\n ))}\n </PopupList.ButtonGroup>\n )}\n size=\"small\"\n />\n ) : null}\n <ToggleViewButtons activeView={view} setActiveView={choose} />\n </>,\n target,\n )\n : null}\n </>\n )\n}\n"],"names":["ChevronIcon","Pill","Popup","PopupList","ToggleViewButtons","useEffect","useRef","useState","createPortal","KEY","COLUMNS_KEY","COLUMNS","read","key","localStorage","getItem","write","value","setItem","MediaViews","anchor","list","setList","view","setView","columns","setColumns","current","closest","saved","Number","includes","dataset","mediaView","style","setProperty","String","removeProperty","choose","v","chooseColumns","n","target","querySelector","span","hidden","ref","button","icon","pillStyle","size","buttonType","className","horizontalAlign","render","close","ButtonGroup","map","Button","active","onClick","activeView","setActiveView"],"mappings":"AAAA;;AAEA,SAASA,WAAW,EAAEC,IAAI,EAAEC,KAAK,EAAEC,SAAS,QAAQ,iBAAgB;AACpE,SAASC,iBAAiB,QAAQ,uDAAsD;AACxF,SAASC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AACnD,SAASC,YAAY,QAAQ,YAAW;AAExC,OAAO,qBAAoB;AAG3B,MAAMC,MAAM;AACZ,MAAMC,cAAc;AACpB,sFAAsF,GACtF,MAAMC,UAAU;IAAC;IAAG;IAAG;IAAG;IAAG;IAAG;IAAG;CAAE;AAErC,MAAMC,OAAO,CAACC;IACZ,IAAI;QACF,OAAOC,aAAaC,OAAO,CAACF;IAC9B,EAAE,OAAM;QACN,+DAA+D;QAC/D,OAAO;IACT;AACF;AACA,MAAMG,QAAQ,CAACH,KAAaI;IAC1B,IAAI;QACFH,aAAaI,OAAO,CAACL,KAAKI;IAC5B,EAAE,OAAM;IACN,8CAA8C;IAChD;AACF;AAEA;;;;;;;;CAQC,GACD,OAAO,SAASE;IACd,MAAMC,SAASd,OAAwB;IACvC,MAAM,CAACe,MAAMC,QAAQ,GAAGf,SAA6B;IACrD,MAAM,CAACgB,MAAMC,QAAQ,GAAGjB,SAAe;IACvC,MAAM,CAACkB,SAASC,WAAW,GAAGnB,SAAS;IAEvCF,U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UAEF;;;AAGV"}
@@ -0,0 +1,116 @@
1
+ /* Folders tab in the picker drawer (FolderPicker.tsx) */
2
+ .media-folder-picker {
3
+ display: flex;
4
+ flex-direction: column;
5
+ min-height: 0;
6
+ }
7
+ .media-folder-picker__tabs,
8
+ .media-folder-picker__toolbar {
9
+ display: flex;
10
+ align-items: center;
11
+ justify-content: space-between;
12
+ gap: var(--base);
13
+ padding: calc(var(--base) * 0.75) var(--gutter-h);
14
+ }
15
+ .media-folder-picker__tabs {
16
+ border-bottom: 1px solid var(--theme-elevation-100);
17
+ }
18
+ .media-folder-picker__tab-group {
19
+ display: flex;
20
+ align-items: center;
21
+ gap: calc(var(--base) * 0.5);
22
+ }
23
+ /* `.close-modal-button` sets `margin: 0`, so push it over from the flex row instead. */
24
+ .media-folder-picker__tabs .media-folder-picker__close {
25
+ margin-inline-start: auto;
26
+ align-self: center;
27
+ }
28
+ .media-folder-picker__root-crumb {
29
+ display: flex;
30
+ align-items: center;
31
+ gap: calc(var(--base) * 0.25);
32
+ }
33
+ .media-folder-picker__empty {
34
+ padding: calc(var(--base) * 2) var(--gutter-h);
35
+ text-align: center;
36
+ }
37
+ /* The results grid is rendered by Payload and assumes the gutter its own view supplies. */
38
+ .media-folder-picker .item-card-grid,
39
+ .media-folder-picker .item-card-grid__title {
40
+ padding-inline: var(--gutter-h);
41
+ }
42
+
43
+ /* Grid view (MediaViews.tsx), drawn over the same table */
44
+ .collection-list[data-media-view='grid'] .table table,
45
+ .collection-list[data-media-view='grid'] .table tbody {
46
+ display: block;
47
+ }
48
+ .collection-list[data-media-view='grid'] .table thead,
49
+ .collection-list[data-media-view='grid'] .table td:not(.cell-_select, .cell-filename) {
50
+ display: none;
51
+ }
52
+ .collection-list[data-media-view='grid'] .table tbody {
53
+ display: grid;
54
+ grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
55
+ gap: 1rem;
56
+ }
57
+ /* A fixed number per row, chosen from "Per row" (set on the list as a custom property). */
58
+ .collection-list[data-media-view='grid'][style*='--media-grid-columns'] .table tbody {
59
+ grid-template-columns: repeat(var(--media-grid-columns), minmax(0, 1fr));
60
+ }
61
+ .collection-list[data-media-view='grid'] .table tr {
62
+ position: relative;
63
+ display: block;
64
+ overflow: hidden;
65
+ border-radius: 0.75rem;
66
+ background: var(--theme-elevation-50);
67
+ }
68
+ .collection-list[data-media-view='grid'] .table td {
69
+ display: block;
70
+ padding: 0;
71
+ }
72
+ .collection-list[data-media-view='grid'] .cell-_select {
73
+ position: absolute;
74
+ top: 0.5rem;
75
+ left: 0.5rem;
76
+ z-index: 1;
77
+ }
78
+ /* A link on the full page, a button inside the picker drawer. */
79
+ .collection-list[data-media-view='grid'] .cell-filename :is(a, button) {
80
+ display: block;
81
+ width: 100%;
82
+ padding: 0;
83
+ border: 0;
84
+ background: none;
85
+ text-align: start;
86
+ text-decoration: none;
87
+ cursor: pointer;
88
+ }
89
+ .collection-list[data-media-view='grid'] .file {
90
+ display: block;
91
+ }
92
+ .collection-list[data-media-view='grid'] .file__thumbnail {
93
+ width: 100%;
94
+ max-width: none;
95
+ max-height: none;
96
+ height: auto;
97
+ aspect-ratio: 1;
98
+ border-radius: 0;
99
+ }
100
+ .collection-list[data-media-view='grid'] .file__thumbnail img {
101
+ width: 100%;
102
+ height: 100%;
103
+ object-fit: cover;
104
+ }
105
+ .collection-list[data-media-view='grid'] .file__filename {
106
+ display: block;
107
+ margin: 0;
108
+ padding: 0.625rem 0.75rem;
109
+ overflow: hidden;
110
+ font-size: 0.8125rem;
111
+ white-space: nowrap;
112
+ text-overflow: ellipsis;
113
+ }
114
+ .collection-list[data-media-view='grid'] .cell-filename :is(a, button):hover .file__filename {
115
+ text-decoration: underline;
116
+ }
@@ -0,0 +1,3 @@
1
+ export { FolderPicker } from '../components/FolderPicker.js';
2
+ export { MediaListView } from '../components/MediaListView.js';
3
+ export { MediaViews } from '../components/MediaViews.js';
@@ -0,0 +1,5 @@
1
+ export { FolderPicker } from '../components/FolderPicker.js';
2
+ export { MediaListView } from '../components/MediaListView.js';
3
+ export { MediaViews } from '../components/MediaViews.js';
4
+
5
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["export { FolderPicker } from '../components/FolderPicker.js'\nexport { MediaListView } from '../components/MediaListView.js'\nexport { MediaViews } from '../components/MediaViews.js'\n"],"names":["FolderPicker","MediaListView","MediaViews"],"mappings":"AAAA,SAASA,YAAY,QAAQ,gCAA+B;AAC5D,SAASC,aAAa,QAAQ,iCAAgC;AAC9D,SAASC,UAAU,QAAQ,8BAA6B"}
@@ -0,0 +1,15 @@
1
+ import type { Config } from 'payload';
2
+ export type MediaPluginConfig = {
3
+ /** Upload collections to enhance. Defaults to every upload collection. */
4
+ collections?: string[];
5
+ /** Folders tab inside the image picker drawer. Needs `folders: true` on the collection. Default true. */
6
+ folderPicker?: boolean;
7
+ /** List / Grid switch on the list, full page and picker drawer. Default true. */
8
+ gridView?: boolean;
9
+ };
10
+ /**
11
+ * A List / Grid switch on upload collection lists, and a Folders tab in the picker drawer so
12
+ * editors can choose images from inside folders. A collection that already has its own list
13
+ * view keeps it.
14
+ */
15
+ export declare const mediaPlugin: ({ collections, folderPicker, gridView }?: MediaPluginConfig) => (config: Config) => Config;
package/dist/index.js ADDED
@@ -0,0 +1,42 @@
1
+ const LIST_VIEW = '@foundrykit/media-plugin/client#MediaListView';
2
+ const MEDIA_VIEWS = '@foundrykit/media-plugin/client#MediaViews';
3
+ /**
4
+ * A List / Grid switch on upload collection lists, and a Folders tab in the picker drawer so
5
+ * editors can choose images from inside folders. A collection that already has its own list
6
+ * view keeps it.
7
+ */ export const mediaPlugin = ({ collections, folderPicker = true, gridView = true } = {})=>(config)=>({
8
+ ...config,
9
+ collections: config.collections?.map((collection)=>{
10
+ const wanted = collections ? collections.includes(collection.slug) : Boolean(collection.upload);
11
+ return wanted ? enhance(collection, {
12
+ folderPicker,
13
+ gridView
14
+ }) : collection;
15
+ })
16
+ });
17
+ function enhance(collection, { folderPicker, gridView }) {
18
+ const components = collection.admin?.components ?? {};
19
+ const views = components.views ?? {};
20
+ const beforeListTable = components.beforeListTable ?? [];
21
+ return {
22
+ ...collection,
23
+ admin: {
24
+ ...collection.admin,
25
+ components: {
26
+ ...components,
27
+ beforeListTable: gridView ? [
28
+ ...beforeListTable,
29
+ MEDIA_VIEWS
30
+ ] : beforeListTable,
31
+ views: {
32
+ ...views,
33
+ list: folderPicker && !views.list ? {
34
+ Component: LIST_VIEW
35
+ } : views.list
36
+ }
37
+ }
38
+ }
39
+ };
40
+ }
41
+
42
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { CollectionConfig, Config } from 'payload'\n\nexport type MediaPluginConfig = {\n /** Upload collections to enhance. Defaults to every upload collection. */\n collections?: string[]\n /** Folders tab inside the image picker drawer. Needs `folders: true` on the collection. Default true. */\n folderPicker?: boolean\n /** List / Grid switch on the list, full page and picker drawer. Default true. */\n gridView?: boolean\n}\n\nconst LIST_VIEW = '@foundrykit/media-plugin/client#MediaListView'\nconst MEDIA_VIEWS = '@foundrykit/media-plugin/client#MediaViews'\n\n/**\n * A List / Grid switch on upload collection lists, and a Folders tab in the picker drawer so\n * editors can choose images from inside folders. A collection that already has its own list\n * view keeps it.\n */\nexport const mediaPlugin =\n ({ collections, folderPicker = true, gridView = true }: MediaPluginConfig = {}) =>\n (config: Config): Config => ({\n ...config,\n collections: config.collections?.map((collection) => {\n const wanted = collections ? collections.includes(collection.slug) : Boolean(collection.upload)\n return wanted ? enhance(collection, { folderPicker, gridView }) : collection\n }),\n })\n\nfunction enhance(\n collection: CollectionConfig,\n { folderPicker, gridView }: { folderPicker: boolean; gridView: boolean },\n): CollectionConfig {\n const components = collection.admin?.components ?? {}\n const views = components.views ?? {}\n const beforeListTable = components.beforeListTable ?? []\n\n return {\n ...collection,\n admin: {\n ...collection.admin,\n components: {\n ...components,\n beforeListTable: gridView ? [...beforeListTable, MEDIA_VIEWS] : beforeListTable,\n views: {\n ...views,\n list: folderPicker && !views.list ? { Component: LIST_VIEW } : views.list,\n },\n },\n },\n }\n}\n"],"names":["LIST_VIEW","MEDIA_VIEWS","mediaPlugin","collections","folderPicker","gridView","config","map","collection","wanted","includes","slug","Boolean","upload","enhance","components","admin","views","beforeListTable","list","Component"],"mappings":"AAWA,MAAMA,YAAY;AAClB,MAAMC,cAAc;AAEpB;;;;CAIC,GACD,OAAO,MAAMC,cACX,CAAC,EAAEC,WAAW,EAAEC,eAAe,IAAI,EAAEC,WAAW,IAAI,EAAqB,GAAG,CAAC,CAAC,GAC9E,CAACC,SAA4B,CAAA;YAC3B,GAAGA,MAAM;YACTH,aAAaG,OAAOH,WAAW,EAAEI,IAAI,CAACC;gBACpC,MAAMC,SAASN,cAAcA,YAAYO,QAAQ,CAACF,WAAWG,IAAI,IAAIC,QAAQJ,WAAWK,MAAM;gBAC9F,OAAOJ,SAASK,QAAQN,YAAY;oBAAEJ;oBAAcC;gBAAS,KAAKG;YACpE;QACF,CAAA,EAAE;AAEJ,SAASM,QACPN,UAA4B,EAC5B,EAAEJ,YAAY,EAAEC,QAAQ,EAAgD;IAExE,MAAMU,aAAaP,WAAWQ,KAAK,EAAED,cAAc,CAAC;IACpD,MAAME,QAAQF,WAAWE,KAAK,IAAI,CAAC;IACnC,MAAMC,kBAAkBH,WAAWG,eAAe,IAAI,EAAE;IAExD,OAAO;QACL,GAAGV,UAAU;QACbQ,OAAO;YACL,GAAGR,WAAWQ,KAAK;YACnBD,YAAY;gBACV,GAAGA,UAAU;gBACbG,iBAAiBb,WAAW;uBAAIa;oBAAiBjB;iBAAY,GAAGiB;gBAChED,OAAO;oBACL,GAAGA,KAAK;oBACRE,MAAMf,gBAAgB,CAACa,MAAME,IAAI,GAAG;wBAAEC,WAAWpB;oBAAU,IAAIiB,MAAME,IAAI;gBAC3E;YACF;QACF;IACF;AACF"}
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,108 @@
1
1
  {
2
2
  "name": "@foundrykit/media-plugin",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Media library for Payload CMS 3: a List / Grid switch on upload lists and a Folders tab in the image picker",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/umi-labs/media-plugin.git"
9
+ },
10
+ "type": "module",
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index.js"
16
+ },
17
+ "./client": {
18
+ "import": "./dist/exports/client.js",
19
+ "types": "./dist/exports/client.d.ts",
20
+ "default": "./dist/exports/client.js"
21
+ }
22
+ },
23
+ "main": "./dist/index.js",
24
+ "types": "./dist/index.d.ts",
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "scripts": {
29
+ "build": "pnpm copyfiles && pnpm build:types && pnpm build:swc",
30
+ "build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths --ignore \"**/*.test.ts,**/*.test.tsx,**/*.d.ts\"",
31
+ "build:types": "tsc --outDir dist --rootDir ./src",
32
+ "clean": "rimraf {dist,*.tsbuildinfo}",
33
+ "copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
34
+ "dev": "next dev dev --turbo",
35
+ "dev:generate-importmap": "pnpm dev:payload generate:importmap",
36
+ "dev:generate-types": "pnpm dev:payload generate:types",
37
+ "dev:payload": "cross-env PAYLOAD_CONFIG_PATH=./dev/payload.config.ts payload",
38
+ "generate:importmap": "pnpm dev:generate-importmap",
39
+ "generate:types": "pnpm dev:generate-types",
40
+ "lint": "eslint",
41
+ "lint:fix": "eslint ./src --fix",
42
+ "prepublishOnly": "pnpm build && node scripts/verify-pack.mjs",
43
+ "verify:pack": "node scripts/verify-pack.mjs",
44
+ "release": "release-it",
45
+ "release:dry": "release-it --dry-run",
46
+ "test": "pnpm test:unit && pnpm test:int && pnpm test:e2e",
47
+ "test:unit": "vitest run src",
48
+ "test:e2e": "playwright test",
49
+ "test:int": "vitest run dev/int.spec.ts"
50
+ },
51
+ "devDependencies": {
52
+ "@eslint/eslintrc": "^3.2.0",
53
+ "@payloadcms/db-mongodb": "3.84.1",
54
+ "@payloadcms/eslint-config": "3.28.0",
55
+ "@payloadcms/next": "3.84.1",
56
+ "@payloadcms/ui": "3.84.1",
57
+ "@playwright/test": "1.58.2",
58
+ "@release-it/conventional-changelog": "^11.0.0",
59
+ "@swc-node/register": "1.10.9",
60
+ "@swc/cli": "0.6.0",
61
+ "@testing-library/jest-dom": "^6.6.3",
62
+ "@testing-library/react": "^16.3.0",
63
+ "@types/node": "22.19.9",
64
+ "@types/react": "19.2.14",
65
+ "@types/react-dom": "19.2.3",
66
+ "copyfiles": "2.4.1",
67
+ "cross-env": "^7.0.3",
68
+ "eslint": "^9.23.0",
69
+ "eslint-config-next": "16.2.6",
70
+ "graphql": "^16.8.1",
71
+ "jsdom": "^26.1.0",
72
+ "mongodb-memory-server": "10.1.4",
73
+ "next": "16.2.6",
74
+ "payload": "3.84.1",
75
+ "prettier": "^3.4.2",
76
+ "react": "19.2.6",
77
+ "react-dom": "19.2.6",
78
+ "release-it": "^20.0.1",
79
+ "rimraf": "3.0.2",
80
+ "sharp": "0.34.2",
81
+ "typescript": "5.7.3",
82
+ "vite-tsconfig-paths": "6.0.5",
83
+ "vitest": "4.0.18"
84
+ },
85
+ "peerDependencies": {
86
+ "@payloadcms/next": "^3.84.1",
87
+ "@payloadcms/ui": "^3.84.1",
88
+ "next": ">=15",
89
+ "payload": "^3.84.1",
90
+ "react": "^19",
91
+ "react-dom": "^19"
92
+ },
93
+ "engines": {
94
+ "node": "^18.20.2 || >=20.9.0",
95
+ "pnpm": "^9 || ^10"
96
+ },
97
+ "publishConfig": {
98
+ "access": "public"
99
+ },
100
+ "registry": "https://registry.npmjs.org/",
101
+ "pnpm": {
102
+ "onlyBuiltDependencies": [
103
+ "sharp",
104
+ "esbuild",
105
+ "unrs-resolver"
106
+ ]
107
+ }
108
+ }