@bison-lab/payload-core 3.32.0 → 3.33.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/dist/admin.mjs CHANGED
@@ -1,14 +1,15 @@
1
1
  "use client";
2
2
  import { a as colorDocFromState, i as SYSTEM_COLOR_KEYS, n as pageEditorLooks, r as pageEditorTokens, s as stateFromColorDoc } from "./looks-BbL309kO.mjs";
3
- import { ArrayField, Button, CheckboxInput, DefaultCell, FieldDescription, FieldError, FieldLabel, Link, Logout, NavGroup, NavToggler, SelectField, fieldBaseClass, useAuth, useConfig, useField, useForm, useFormFields, useNav, useRowLabel, useStepNav } from "@payloadcms/ui";
3
+ import { ArrayField, Button, CheckboxInput, DefaultCell, FieldDescription, FieldError, FieldLabel, Link, Logout, NavGroup, NavToggler, SelectField, fieldBaseClass, useAuth, useBulkUpload, useConfig, useField, useForm, useFormFields, useListQuery, useModal, useNav, useRowLabel, useStepNav } from "@payloadcms/ui";
4
4
  import { GREY_SCALES, SHADE_STEPS, contrastForeground, contrastRatio, createColorScale, deriveDarkPalette, deriveLightPalette, hexToHSL, hslToString, includedShadeSteps, isThemeHex, presetHints, setColorScaleInclude } from "@bison-lab/tokens";
5
5
  import { useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
6
6
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
7
- import { Badge, Button as Button$1, Checkbox, DeleteGlyph, Dialog, EditGlyph, Field, Input, KitProvider, Label, MainHead, Page, Pagination, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Switch, Table, TableActions, TableCell, TableHead, TableRow, Textarea } from "@bison-lab/admin-ui";
7
+ import { Badge, Button as Button$1, Checkbox, Chip, ConfirmDialog, DeleteGlyph, Dialog, EditGlyph, Field, Input, KitProvider, Label, MainHead, Page, Pagination, Popover, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Switch, Table, TableActions, TableCell, TableHead, TableRow, Textarea, Thumbnail } from "@bison-lab/admin-ui";
8
8
  import { HexColorPicker } from "react-colorful";
9
9
  import { createPortal } from "react-dom";
10
10
  import { findFont, fontFaceCss, isFontId } from "@bison-lab/fonts";
11
11
  import "payload";
12
+ import { formatAdminURL, formatFilesize } from "payload/shared";
12
13
  //#region src/admin/color-field.tsx
13
14
  const HEX_ERROR = "Enter a six-digit hex colour like #1e3a5f";
14
15
  /**
@@ -3504,7 +3505,7 @@ const RolesField = ({ field, path: pathFromProps, readOnly, validate }) => {
3504
3505
  };
3505
3506
  //#endregion
3506
3507
  //#region src/admin/roles-grants-field.tsx
3507
- const LIST_CSS$1 = `.bl-role-grants{margin-block:.2rem 0;font-size:16px}.bl-role-grants__group{margin-block:.75rem 0}.bl-role-grants__group-title{font-size:13px;letter-spacing:.02em;color:var(--theme-elevation-400,#94a3b8);font-weight:650;margin-block-end:.25rem}.bl-role-grants__row{display:flex;align-items:center;gap:.65rem;padding:.35rem 0}.bl-role-grants__row.is-implicit{opacity:.85}.bl-role-grants input{inline-size:1.15rem;block-size:1.15rem}.bl-role-grants input:disabled{cursor:default}.bl-role-grants__note{margin-block:.35rem 0;font-size:13px;color:var(--theme-elevation-500,#64748b)}`;
3508
+ const LIST_CSS$2 = `.bl-role-grants{margin-block:.2rem 0;font-size:16px}.bl-role-grants__group{margin-block:.75rem 0}.bl-role-grants__group-title{font-size:13px;letter-spacing:.02em;color:var(--theme-elevation-400,#94a3b8);font-weight:650;margin-block-end:.25rem}.bl-role-grants__row{display:flex;align-items:center;gap:.65rem;padding:.35rem 0}.bl-role-grants__row.is-implicit{opacity:.85}.bl-role-grants input{inline-size:1.15rem;block-size:1.15rem}.bl-role-grants input:disabled{cursor:default}.bl-role-grants__note{margin-block:.35rem 0;font-size:13px;color:var(--theme-elevation-500,#64748b)}`;
3508
3509
  function asGrants(value) {
3509
3510
  if (!Array.isArray(value)) return [];
3510
3511
  return value.filter((entry) => typeof entry === "string");
@@ -3552,7 +3553,7 @@ const RolesGrantsField = (props) => {
3552
3553
  /* @__PURE__ */ jsx("style", {
3553
3554
  href: "bl-role-grants",
3554
3555
  precedence: "default",
3555
- children: LIST_CSS$1
3556
+ children: LIST_CSS$2
3556
3557
  }),
3557
3558
  implicitAll ? /* @__PURE__ */ jsx("p", {
3558
3559
  className: "bl-role-grants__note",
@@ -3583,7 +3584,7 @@ const RolesGrantsField = (props) => {
3583
3584
  };
3584
3585
  //#endregion
3585
3586
  //#region src/admin/features-matrix-field.tsx
3586
- const LIST_CSS = `.bl-features{margin-block:.35rem 0;font-size:16px}.bl-features__group{margin-block:1rem 0}.bl-features__group-title{font-size:14px;letter-spacing:.02em;color:var(--theme-elevation-400,#94a3b8);font-weight:650;margin-block-end:.35rem}.bl-features__row{display:flex;align-items:center;justify-content:space-between;gap:1rem;padding:.55rem 0;border-bottom:1px solid var(--theme-elevation-150,#e2e8f0)}.bl-features__row:last-child{border-bottom:0}.bl-features input{inline-size:1.15rem;block-size:1.15rem}`;
3587
+ const LIST_CSS$1 = `.bl-features{margin-block:.35rem 0;font-size:16px}.bl-features__group{margin-block:1rem 0}.bl-features__group-title{font-size:14px;letter-spacing:.02em;color:var(--theme-elevation-400,#94a3b8);font-weight:650;margin-block-end:.35rem}.bl-features__row{display:flex;align-items:center;justify-content:space-between;gap:1rem;padding:.55rem 0;border-bottom:1px solid var(--theme-elevation-150,#e2e8f0)}.bl-features__row:last-child{border-bottom:0}.bl-features input{inline-size:1.15rem;block-size:1.15rem}`;
3587
3588
  function asRows(value) {
3588
3589
  return Array.isArray(value) ? value : [];
3589
3590
  }
@@ -3642,7 +3643,7 @@ const FeaturesMatrixField = (props) => {
3642
3643
  children: [/* @__PURE__ */ jsx("style", {
3643
3644
  href: "bl-features",
3644
3645
  precedence: "default",
3645
- children: LIST_CSS
3646
+ children: LIST_CSS$1
3646
3647
  }), FEATURE_GROUPS.map((group) => {
3647
3648
  const members = rows.map((row, index) => ({
3648
3649
  row,
@@ -4172,7 +4173,7 @@ function familyFromDoc(value) {
4172
4173
  if (typeof raw === "string" && raw.trim()) return raw.trim();
4173
4174
  }
4174
4175
  }
4175
- function chipsFrom(value) {
4176
+ function chipsFrom$1(value) {
4176
4177
  if (!Array.isArray(value)) return [];
4177
4178
  const chips = [];
4178
4179
  for (const item of value) {
@@ -4557,7 +4558,7 @@ function QuestionsListPage({ collectionSlug, organizeBy: organizeByProp }) {
4557
4558
  children: doc.answer
4558
4559
  })] }),
4559
4560
  organizeBy.map((entry) => {
4560
- const chips = chipsFrom(doc[entry.name]);
4561
+ const chips = chipsFrom$1(doc[entry.name]);
4561
4562
  const kind = entry.manage ? "topic" : "anatomy";
4562
4563
  return /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx("div", {
4563
4564
  className: "bl-faq-library__chips",
@@ -4893,6 +4894,1053 @@ function QuestionsListPage({ collectionSlug, organizeBy: organizeByProp }) {
4893
4894
  ] });
4894
4895
  }
4895
4896
  //#endregion
4896
- export { AdminNav, AdminNavEntityField, AdminNavItemRowLabel, AdminNavRowLabel, AppearanceField, ColorField, ColorScaleField, ContrastReport, DocumentCreateNew, DocumentTitleActions, FeaturesMatrixField, FontField, GreyScaleField, HiddenSaveButton, IdentityFallback, LibraryField, LookField, PageTitleCell, PairingField, PublishChild, QuestionsList, RoleNameField, RoleSlugField, RolesField, RolesGrantsField, RolesMatrixField, RolesRowLabel, SectionHeading, SlugField, ThemeDocumentControls, ThemeSaveButton, setThemePreviewMode };
4897
+ //#region src/collections/media-alt.ts
4898
+ /** The name the editor just chose, or the stored filename on an existing row. */
4899
+ function filenameFromUpload(file, filename) {
4900
+ if (typeof File !== "undefined" && file instanceof File) return file.name;
4901
+ if (typeof filename === "string") return filename;
4902
+ return "";
4903
+ }
4904
+ /** Alt text from an upload filename: drop the extension, hyphenate the rest. */
4905
+ function altFromFilename(filename) {
4906
+ if (typeof filename !== "string") return "";
4907
+ return filename.trim().replace(/\.[a-z0-9]{1,5}$/i, "").replace(/[_\s]+/g, "-");
4908
+ }
4909
+ /**
4910
+ * Fill while Alt is empty or still the last auto value. Stop once the editor
4911
+ * types something else.
4912
+ */
4913
+ function shouldFillMediaAlt(existing, generated, lastAuto) {
4914
+ if (!generated) return false;
4915
+ const current = typeof existing === "string" ? existing.trim() : "";
4916
+ if (current === generated) return false;
4917
+ if (!current) return true;
4918
+ return current === lastAuto;
4919
+ }
4920
+ //#endregion
4921
+ //#region src/admin/media-alt-autofill.tsx
4922
+ /**
4923
+ * Writes a hyphenated filename into Alt as the file is chosen. Renders
4924
+ * nothing: the stock text field stays the one the editor types into.
4925
+ */
4926
+ function MediaAltAutofill({ path }) {
4927
+ const { value, setValue } = useField({
4928
+ path,
4929
+ potentiallyStalePath: path
4930
+ });
4931
+ const filename = useFormFields(([fields]) => filenameFromUpload(fields.file?.value, fields.filename?.value));
4932
+ const lastAuto = useRef("");
4933
+ useEffect(() => {
4934
+ const generated = altFromFilename(filename);
4935
+ if (!generated) return;
4936
+ if ((typeof value === "string" ? value.trim() : "") === generated) {
4937
+ lastAuto.current = generated;
4938
+ return;
4939
+ }
4940
+ if (!shouldFillMediaAlt(value, generated, lastAuto.current)) return;
4941
+ lastAuto.current = generated;
4942
+ setValue(generated);
4943
+ }, [
4944
+ filename,
4945
+ setValue,
4946
+ value
4947
+ ]);
4948
+ return null;
4949
+ }
4950
+ //#endregion
4951
+ //#region src/collections/media-list-query.ts
4952
+ const MEDIA_COLUMN_KEYS = [
4953
+ "filename",
4954
+ "alt",
4955
+ "inUse",
4956
+ "updatedAt",
4957
+ "createdAt",
4958
+ "filesize",
4959
+ "dimensions"
4960
+ ];
4961
+ const EMPTY_MEDIA_FILTERS = {
4962
+ alt: "any",
4963
+ date: "any",
4964
+ advField: "filename",
4965
+ advOp: "contains",
4966
+ advValue: ""
4967
+ };
4968
+ function mediaInUseEnabled(config) {
4969
+ return (config?.admin?.custom)?.mediaInUse !== false;
4970
+ }
4971
+ function defaultMediaColumns(inUseEnabled) {
4972
+ return inUseEnabled ? [
4973
+ "filename",
4974
+ "alt",
4975
+ "inUse",
4976
+ "updatedAt",
4977
+ "createdAt"
4978
+ ] : [
4979
+ "filename",
4980
+ "alt",
4981
+ "updatedAt",
4982
+ "createdAt"
4983
+ ];
4984
+ }
4985
+ function normalizeColumns(columns) {
4986
+ if (Array.isArray(columns)) return columns.filter((entry) => typeof entry === "string");
4987
+ if (typeof columns !== "string" || !columns.trim()) return null;
4988
+ try {
4989
+ const parsed = JSON.parse(columns);
4990
+ if (!Array.isArray(parsed)) return null;
4991
+ return parsed.filter((entry) => typeof entry === "string");
4992
+ } catch {
4993
+ return null;
4994
+ }
4995
+ }
4996
+ function columnsFromQuery(columns, inUseEnabled) {
4997
+ const defaultOn = defaultMediaColumns(inUseEnabled);
4998
+ const visible = Object.fromEntries(MEDIA_COLUMN_KEYS.map((key) => [key, defaultOn.includes(key)]));
4999
+ const entries = normalizeColumns(columns);
5000
+ if (!entries) return visible;
5001
+ const named = /* @__PURE__ */ new Set();
5002
+ for (const entry of entries) {
5003
+ if (typeof entry !== "string") continue;
5004
+ const active = entry[0] !== "-";
5005
+ const key = active ? entry : entry.slice(1);
5006
+ if (!MEDIA_COLUMN_KEYS.includes(key)) continue;
5007
+ if (key === "inUse" && !inUseEnabled) continue;
5008
+ visible[key] = active;
5009
+ named.add(key);
5010
+ }
5011
+ if (inUseEnabled && !named.has("inUse")) visible.inUse = true;
5012
+ visible.filename = true;
5013
+ if (!inUseEnabled) visible.inUse = false;
5014
+ return visible;
5015
+ }
5016
+ function columnsToQuery(visible) {
5017
+ return MEDIA_COLUMN_KEYS.map((key) => visible[key] ? key : `-${key}`);
5018
+ }
5019
+ function draftFromWhere(where) {
5020
+ const draft = { ...EMPTY_MEDIA_FILTERS };
5021
+ const clauses = flattenWhere(where);
5022
+ for (const clause of clauses) {
5023
+ if (clause.alt && typeof clause.alt === "object") {
5024
+ const alt = clause.alt;
5025
+ if (alt.equals === "" || alt.exists === false) draft.alt = "missing";
5026
+ else if (alt.exists === true || alt.not_equals === "") draft.alt = "has";
5027
+ else if (typeof alt.equals === "string" && alt.equals !== "") {
5028
+ draft.advField = "alt";
5029
+ draft.advOp = "equals";
5030
+ draft.advValue = alt.equals;
5031
+ }
5032
+ }
5033
+ if (clause.createdAt && typeof clause.createdAt === "object") {
5034
+ const stamp = clause.createdAt.greater_than_equal;
5035
+ if (stamp) {
5036
+ const days = (Date.now() - new Date(stamp).getTime()) / 864e5;
5037
+ draft.date = days <= 1.1 ? "today" : days <= 8 ? "week" : "month";
5038
+ }
5039
+ }
5040
+ for (const field of ["filename", "alt"]) {
5041
+ const value = clause[field];
5042
+ if (!value || typeof value !== "object") continue;
5043
+ const op = value;
5044
+ if (typeof op.contains === "string") {
5045
+ draft.advField = field;
5046
+ draft.advOp = "contains";
5047
+ draft.advValue = op.contains;
5048
+ } else if (typeof op.equals === "string") {
5049
+ draft.advField = field;
5050
+ draft.advOp = "equals";
5051
+ draft.advValue = op.equals;
5052
+ } else if (typeof op.not_like === "string") {
5053
+ draft.advField = field;
5054
+ draft.advOp = "not_contains";
5055
+ draft.advValue = op.not_like;
5056
+ }
5057
+ }
5058
+ }
5059
+ return draft;
5060
+ }
5061
+ function whereFromDraft(draft) {
5062
+ const and = [];
5063
+ if (draft.alt === "has") and.push({ and: [{ alt: { exists: true } }, { alt: { not_equals: "" } }] });
5064
+ if (draft.alt === "missing") and.push({ or: [{ alt: { exists: false } }, { alt: { equals: "" } }] });
5065
+ if (draft.date !== "any") {
5066
+ const start = /* @__PURE__ */ new Date();
5067
+ start.setHours(0, 0, 0, 0);
5068
+ if (draft.date === "week") start.setDate(start.getDate() - 6);
5069
+ if (draft.date === "month") start.setDate(start.getDate() - 29);
5070
+ and.push({ createdAt: { greater_than_equal: start.toISOString() } });
5071
+ }
5072
+ const value = draft.advValue.trim();
5073
+ if (value) if (draft.advOp === "contains") and.push({ [draft.advField]: { contains: value } });
5074
+ else if (draft.advOp === "equals") and.push({ [draft.advField]: { equals: value } });
5075
+ else and.push({ [draft.advField]: { not_like: value } });
5076
+ if (and.length === 0) return {};
5077
+ if (and.length === 1) return and[0];
5078
+ return { and };
5079
+ }
5080
+ function flattenWhere(where) {
5081
+ if (!where || typeof where !== "object") return [];
5082
+ const and = where.and;
5083
+ if (Array.isArray(and)) return and.flatMap((entry) => flattenWhere(entry));
5084
+ const or = where.or;
5085
+ if (Array.isArray(or)) return or.flatMap((entry) => flattenWhere(entry));
5086
+ return [where];
5087
+ }
5088
+ //#endregion
5089
+ //#region src/admin/media-list-view.tsx
5090
+ const COLUMN_KEYS = MEDIA_COLUMN_KEYS;
5091
+ const LOCKED = "filename";
5092
+ const CHECK_COL = "56px";
5093
+ const FILE_COL = "18rem";
5094
+ const ACTIONS_COL = "var(--bl-media-actions-col,max-content)";
5095
+ const FILE_PIN_LEFT = { left: CHECK_COL };
5096
+ const LIST_CSS = `
5097
+ .bl-media-list{font:14px/1.4 Inter,ui-sans-serif,system-ui,sans-serif;color:var(--bl-kit-ink)}
5098
+ .bl-media-list .bl-workspace__main-head{padding:0;margin:0 0 22px;align-items:flex-start}
5099
+ .bl-media-list .bl-workspace__main-head h1{display:flex;align-items:baseline;gap:.45em;font-size:27px;margin:0;font-weight:700;letter-spacing:-.02em}
5100
+ .bl-media-list__count{color:var(--bl-kit-ink-muted);white-space:nowrap;font-size:13px;font-weight:500;letter-spacing:0}
5101
+ .bl-media-list__actions{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
5102
+ .bl-media-list__toolbar{display:flex;align-items:center;gap:8px;margin-bottom:18px}
5103
+ .bl-media-list__search{position:relative;flex:1;min-width:0}
5104
+ .bl-media-list__search .bl-nav-kit__input{padding-left:44px}
5105
+ .bl-media-list__search-icon{position:absolute;left:12px;top:50%;transform:translateY(-50%);color:var(--bl-kit-ink-muted);pointer-events:none;display:grid;place-items:center}
5106
+ .bl-media-list__search-icon svg{display:block;width:20px;height:20px}
5107
+ .bl-media-list__file{display:flex;align-items:center;gap:12px;width:100%;min-width:0;max-width:100%}
5108
+ .bl-media-list .bl-nav-kit__thumb--sm .bl-nav-kit__thumb-frame{width:38px;height:38px;border-radius:5px;flex:none}
5109
+ .bl-media-list__when{white-space:nowrap}
5110
+ .bl-media-list__filename{text-decoration:underline;font-weight:500;color:inherit;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0;flex:1}
5111
+ .bl-media-list__filename:hover{color:var(--bl-kit-accent,#2563eb)}
5112
+ .bl-media-list__sort{display:inline-flex;align-items:center;gap:2px;border:0;background:transparent;padding:0;color:inherit;font:inherit;font-weight:inherit;letter-spacing:inherit;text-transform:inherit;cursor:pointer;min-width:0;max-width:100%}
5113
+ .bl-media-list__sort-mark{display:inline-flex;flex-direction:column;width:12px;height:16px;margin-left:4px;flex:none}
5114
+ .bl-media-list__sort-mark svg{display:block;width:12px;height:9px;stroke:currentColor;fill:none;stroke-width:2.4;stroke-linecap:round;stroke-linejoin:round;opacity:.32}
5115
+ .bl-media-list__sort-mark[data-dir="asc"] svg:first-child,.bl-media-list__sort-mark[data-dir="desc"] svg:last-child{opacity:1;color:var(--bl-kit-accent,#2563eb)}
5116
+ .bl-media-list .bl-nav-kit__table-row:not(.bl-nav-kit__table-head):nth-child(even){--bl-table-row-bg:var(--bl-kit-surface-well);background-color:var(--bl-table-row-bg)}
5117
+ .bl-media-list .bl-nav-kit__table-cell--shade.bl-nav-kit__table-cell--pin-start{min-width:0;overflow:hidden}
5118
+ .bl-media-list .bl-nav-kit__table-cell--pin-end{justify-content:center}
5119
+ .bl-media-list .bl-nav-kit__table-cell--pin-end .bl-nav-kit__table-actions{justify-content:center;width:max-content}
5120
+ .bl-media-list__empty{padding:48px 16px;text-align:center;color:var(--bl-kit-ink-muted)}
5121
+ .bl-media-list__checks{display:flex;flex-direction:column;gap:2px}
5122
+ .bl-media-list__checks label{display:flex;align-items:center;gap:8px;margin:9px 0;font-weight:400;cursor:pointer}
5123
+ .bl-media-list__checks label small{margin-left:auto;color:var(--bl-kit-ink-muted)}
5124
+ .bl-media-list__radios{display:flex;gap:14px;flex-wrap:wrap;margin:8px 0 4px}
5125
+ .bl-media-list__radios label{display:flex;align-items:center;gap:8px;margin:0;font-weight:400;cursor:pointer}
5126
+ .bl-media-list__field{display:block;margin:12px 0}
5127
+ .bl-media-list__field-label{display:block;margin-bottom:6px;font-weight:500}
5128
+ .bl-media-list__advanced{display:none;border-top:1px solid var(--bl-kit-border);padding-top:12px;margin-top:12px}
5129
+ .bl-media-list__advanced.is-open{display:block}
5130
+ .bl-media-list__link{border:0;background:none;color:var(--bl-kit-accent,#2563eb);padding:4px 0;cursor:pointer;font:inherit}
5131
+ .bl-media-list__inuse{display:grid;place-items:center;color:var(--theme-success-500,#3cbf7a)}
5132
+ .bl-media-list__inuse svg{display:block}
5133
+ .bl-media-list .bl-nav-kit__chips{margin:0 0 18px}
5134
+ @media(max-width:700px){
5135
+ .bl-media-list .bl-workspace__main-head{flex-direction:column}
5136
+ .bl-media-list__toolbar{flex-wrap:wrap}
5137
+ .bl-media-list__search{flex-basis:100%}
5138
+ }
5139
+ `;
5140
+ function MediaListView(props) {
5141
+ return /* @__PURE__ */ jsx(ThemeKitAccent, { children: /* @__PURE__ */ jsx(MediaListPage, { ...props }) });
5142
+ }
5143
+ function MediaListPage({ collectionSlug, hasCreatePermission, hasDeletePermission, newDocumentURL }) {
5144
+ const { setStepNav } = useStepNav();
5145
+ const { openModal } = useModal();
5146
+ const { drawerSlug, setCollectionSlug, setOnSuccess } = useBulkUpload();
5147
+ const { config: { routes: { admin: adminRoute, api }, serverURL }, getEntityConfig } = useConfig();
5148
+ const { data, query, handleSearchChange, handlePageChange, handlePerPageChange, handleSortChange, handleWhereChange, refineListData } = useListQuery();
5149
+ const collectionConfig = getEntityConfig({ collectionSlug });
5150
+ const inUseEnabled = mediaInUseEnabled(collectionConfig);
5151
+ const canDelete = hasDeletePermission !== false;
5152
+ const [search, setSearch] = useState(typeof query.search === "string" ? query.search : "");
5153
+ const [visible, setVisible] = useState(() => columnsFromQuery(query.columns, inUseEnabled));
5154
+ const [openPop, setOpenPop] = useState(null);
5155
+ const [draft, setDraft] = useState(() => draftFromWhere(query.where));
5156
+ const [applied, setApplied] = useState(() => draftFromWhere(query.where));
5157
+ const [advancedOpen, setAdvancedOpen] = useState(Boolean(draftFromWhere(query.where).advValue));
5158
+ const [selected, setSelected] = useState(/* @__PURE__ */ new Set());
5159
+ const [selectedLabels, setSelectedLabels] = useState(/* @__PURE__ */ new Map());
5160
+ const [inUse, setInUse] = useState(/* @__PURE__ */ new Set());
5161
+ const [inUseScanFailed, setInUseScanFailed] = useState(false);
5162
+ const [confirm, setConfirm] = useState(null);
5163
+ const rootRef = useRef(null);
5164
+ const docs = data?.docs ?? [];
5165
+ const totalDocs = data?.totalDocs ?? docs.length;
5166
+ const page = data?.page ?? 1;
5167
+ const pageCount = Math.max(1, data?.totalPages ?? 1);
5168
+ const pageSize = data?.limit ?? 10;
5169
+ const sort = typeof query.sort === "string" ? query.sort : void 0;
5170
+ const searchQuery = typeof query.search === "string" ? query.search : "";
5171
+ const pendingSearches = useRef(/* @__PURE__ */ new Set());
5172
+ useEffect(() => {
5173
+ setStepNav([{ label: "Media" }]);
5174
+ }, [setStepNav]);
5175
+ useEffect(() => {
5176
+ const next = typeof query.search === "string" ? query.search : "";
5177
+ if (pendingSearches.current.has(next)) {
5178
+ pendingSearches.current.delete(next);
5179
+ return;
5180
+ }
5181
+ setSearch(next);
5182
+ }, [query.search]);
5183
+ useEffect(() => {
5184
+ setVisible(columnsFromQuery(query.columns, inUseEnabled));
5185
+ }, [query.columns, inUseEnabled]);
5186
+ useEffect(() => {
5187
+ const nextDraft = draftFromWhere(query.where);
5188
+ setApplied(nextDraft);
5189
+ setDraft(nextDraft);
5190
+ setAdvancedOpen(Boolean(nextDraft.advValue));
5191
+ }, [query.where]);
5192
+ useEffect(() => {
5193
+ if (search === searchQuery) return;
5194
+ const handle = window.setTimeout(() => {
5195
+ pendingSearches.current.add(search);
5196
+ if (handleSearchChange) handleSearchChange(search);
5197
+ }, 250);
5198
+ return () => window.clearTimeout(handle);
5199
+ }, [
5200
+ search,
5201
+ searchQuery,
5202
+ handleSearchChange
5203
+ ]);
5204
+ const refreshInUse = useCallback(() => {
5205
+ if (!inUseEnabled) {
5206
+ setInUse(/* @__PURE__ */ new Set());
5207
+ setInUseScanFailed(false);
5208
+ return;
5209
+ }
5210
+ fetch(`${serverURL}${api}/media/in-use`, { credentials: "include" }).then((response) => {
5211
+ if (!response.ok) {
5212
+ setInUseScanFailed(true);
5213
+ setInUse(/* @__PURE__ */ new Set());
5214
+ return;
5215
+ }
5216
+ return response.json();
5217
+ }).then((body) => {
5218
+ if (!body) return;
5219
+ setInUseScanFailed(false);
5220
+ const ids = Array.isArray(body.ids) ? body.ids.map(String) : [];
5221
+ setInUse(new Set(ids));
5222
+ }).catch(() => {
5223
+ setInUseScanFailed(true);
5224
+ setInUse(/* @__PURE__ */ new Set());
5225
+ });
5226
+ }, [
5227
+ api,
5228
+ inUseEnabled,
5229
+ serverURL
5230
+ ]);
5231
+ useEffect(() => {
5232
+ refreshInUse();
5233
+ }, [refreshInUse]);
5234
+ const openBulkUpload = useCallback(() => {
5235
+ setCollectionSlug(collectionSlug);
5236
+ setOnSuccess(() => {
5237
+ refineListData({});
5238
+ });
5239
+ openModal(drawerSlug);
5240
+ }, [
5241
+ collectionSlug,
5242
+ drawerSlug,
5243
+ openModal,
5244
+ refineListData,
5245
+ setCollectionSlug,
5246
+ setOnSuccess
5247
+ ]);
5248
+ const editUrl = (id) => formatAdminURL({
5249
+ adminRoute,
5250
+ path: `/collections/${collectionSlug}/${id}`
5251
+ });
5252
+ const toggleColumn = (key, on) => {
5253
+ if (key === LOCKED) return;
5254
+ const next = {
5255
+ ...visible,
5256
+ [key]: on
5257
+ };
5258
+ setVisible(next);
5259
+ if (refineListData) refineListData({ columns: columnsToQuery(next) });
5260
+ };
5261
+ const applyFilters = () => {
5262
+ setApplied(draft);
5263
+ setOpenPop(null);
5264
+ if (handleWhereChange) handleWhereChange(whereFromDraft(draft));
5265
+ };
5266
+ const clearDraft = () => setDraft(EMPTY_MEDIA_FILTERS);
5267
+ const dismissChip = (key) => {
5268
+ const next = {
5269
+ ...applied,
5270
+ ...key === "alt" ? { alt: "any" } : {},
5271
+ ...key === "date" ? { date: "any" } : {},
5272
+ ...key === "adv" ? { advValue: "" } : {}
5273
+ };
5274
+ setApplied(next);
5275
+ setDraft(next);
5276
+ if (handleWhereChange) handleWhereChange(whereFromDraft(next));
5277
+ };
5278
+ const clearAllFilters = () => {
5279
+ setApplied(EMPTY_MEDIA_FILTERS);
5280
+ setDraft(EMPTY_MEDIA_FILTERS);
5281
+ if (handleWhereChange) handleWhereChange({});
5282
+ };
5283
+ const chips = useMemo(() => chipsFrom(applied), [applied]);
5284
+ const shown = COLUMN_KEYS.filter((key) => visible[key]);
5285
+ const columns = gridColumns(shown);
5286
+ useLayoutEffect(() => {
5287
+ const root = rootRef.current;
5288
+ const table = root?.querySelector(".bl-nav-kit__table");
5289
+ if (!root || !table) return;
5290
+ const measurePins = () => {
5291
+ const actionCells = [...root.querySelectorAll(".bl-nav-kit__table-cell--pin-end")];
5292
+ const actionsCol = Math.ceil(Math.max(0, ...actionCells.map((cell) => pinTrackWidth(cell, ".bl-nav-kit__table-actions"))));
5293
+ if (actionsCol) table.style.setProperty("--bl-media-actions-col", `${actionsCol}px`);
5294
+ };
5295
+ measurePins();
5296
+ const observer = new ResizeObserver(measurePins);
5297
+ observer.observe(table);
5298
+ window.addEventListener("resize", measurePins);
5299
+ return () => {
5300
+ observer.disconnect();
5301
+ window.removeEventListener("resize", measurePins);
5302
+ };
5303
+ }, [
5304
+ columns,
5305
+ docs.length,
5306
+ shown.length
5307
+ ]);
5308
+ const pageIds = docs.map((doc) => String(doc.id));
5309
+ const allPageSelected = pageIds.length > 0 && pageIds.every((id) => selected.has(id));
5310
+ const toggleAll = (on) => {
5311
+ setSelected((current) => {
5312
+ const next = new Set(current);
5313
+ for (const id of pageIds) if (on) next.add(id);
5314
+ else next.delete(id);
5315
+ return next;
5316
+ });
5317
+ setSelectedLabels((current) => {
5318
+ const next = new Map(current);
5319
+ for (const doc of docs) {
5320
+ const id = String(doc.id);
5321
+ if (!pageIds.includes(id)) continue;
5322
+ if (on) next.set(id, doc.filename || id);
5323
+ else next.delete(id);
5324
+ }
5325
+ return next;
5326
+ });
5327
+ };
5328
+ const askDelete = (targets) => {
5329
+ setConfirm({
5330
+ ids: targets.map((doc) => doc.id),
5331
+ names: targets.map((doc) => doc.filename || String(doc.id))
5332
+ });
5333
+ };
5334
+ const runDelete = async () => {
5335
+ if (!confirm) return;
5336
+ const failed = [];
5337
+ for (const id of confirm.ids) if (!(await fetch(`${serverURL}${api}/media/${id}`, {
5338
+ method: "DELETE",
5339
+ credentials: "include"
5340
+ })).ok) failed.push(String(id));
5341
+ if (refineListData) refineListData({});
5342
+ if (failed.length > 0) {
5343
+ setSelected(new Set(failed));
5344
+ setSelectedLabels((current) => new Map([...current].filter(([id]) => failed.includes(id))));
5345
+ setConfirm({
5346
+ ids: failed,
5347
+ names: failed.map((id) => selectedLabels.get(id) ?? id),
5348
+ error: "Some files could not be deleted."
5349
+ });
5350
+ return;
5351
+ }
5352
+ setSelected(/* @__PURE__ */ new Set());
5353
+ setSelectedLabels(/* @__PURE__ */ new Map());
5354
+ setConfirm(null);
5355
+ refreshInUse();
5356
+ };
5357
+ const askDeleteSelected = () => {
5358
+ const ids = [...selected];
5359
+ if (ids.length === 0) return;
5360
+ setConfirm({
5361
+ ids,
5362
+ names: ids.map((id) => selectedLabels.get(id) ?? id)
5363
+ });
5364
+ };
5365
+ const confirmInUse = confirm?.ids.some((id) => inUse.has(String(id))) ?? false;
5366
+ const confirmInUseUnavailable = inUseEnabled && inUseScanFailed;
5367
+ const title = typeof collectionConfig?.labels?.plural === "string" ? collectionConfig.labels.plural : "Media";
5368
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("style", {
5369
+ href: "bl-media-list",
5370
+ precedence: "default",
5371
+ children: LIST_CSS
5372
+ }), /* @__PURE__ */ jsx(Page, {
5373
+ className: "bl-media-list",
5374
+ children: /* @__PURE__ */ jsxs("div", {
5375
+ ref: rootRef,
5376
+ children: [
5377
+ /* @__PURE__ */ jsx(MainHead, {
5378
+ title: /* @__PURE__ */ jsxs(Fragment, { children: [title, /* @__PURE__ */ jsxs("span", {
5379
+ className: "bl-media-list__count",
5380
+ children: [
5381
+ totalDocs,
5382
+ " ",
5383
+ totalDocs === 1 ? "file" : "files"
5384
+ ]
5385
+ })] }),
5386
+ children: /* @__PURE__ */ jsxs("div", {
5387
+ className: "bl-media-list__actions",
5388
+ children: [
5389
+ /* @__PURE__ */ jsx(Button$1, {
5390
+ variant: "primary",
5391
+ disabled: !hasCreatePermission,
5392
+ onClick: () => window.location.assign(newDocumentURL),
5393
+ children: "Create New"
5394
+ }),
5395
+ /* @__PURE__ */ jsx(Button$1, {
5396
+ variant: "outline",
5397
+ onClick: openBulkUpload,
5398
+ children: "Bulk Upload"
5399
+ }),
5400
+ /* @__PURE__ */ jsx(Button$1, {
5401
+ variant: "outline",
5402
+ disabled: !canDelete || selected.size === 0,
5403
+ onClick: askDeleteSelected,
5404
+ children: "Delete"
5405
+ })
5406
+ ]
5407
+ })
5408
+ }),
5409
+ /* @__PURE__ */ jsxs("div", {
5410
+ className: "bl-media-list__toolbar",
5411
+ children: [
5412
+ /* @__PURE__ */ jsxs("label", {
5413
+ className: "bl-media-list__search",
5414
+ children: [/* @__PURE__ */ jsx("span", {
5415
+ className: "bl-media-list__search-icon",
5416
+ "aria-hidden": true,
5417
+ children: /* @__PURE__ */ jsx(SearchMark, {})
5418
+ }), /* @__PURE__ */ jsx(Input, {
5419
+ value: search,
5420
+ onChange: (event) => setSearch(event.target.value),
5421
+ placeholder: "Search by file name",
5422
+ "aria-label": "Search by file name"
5423
+ })]
5424
+ }),
5425
+ /* @__PURE__ */ jsx(Popover, {
5426
+ open: openPop === "columns",
5427
+ onOpenChange: (open) => setOpenPop(open ? "columns" : null),
5428
+ title: "Show columns",
5429
+ size: "sm",
5430
+ trigger: /* @__PURE__ */ jsxs(Button$1, {
5431
+ variant: "outline",
5432
+ onClick: () => setOpenPop(openPop === "columns" ? null : "columns"),
5433
+ children: [
5434
+ /* @__PURE__ */ jsx(ColumnsMark, {}),
5435
+ "Columns",
5436
+ /* @__PURE__ */ jsx(ChevronMark, {})
5437
+ ]
5438
+ }),
5439
+ children: /* @__PURE__ */ jsxs("div", {
5440
+ className: "bl-media-list__checks",
5441
+ children: [COLUMN_KEYS.map((key) => /* @__PURE__ */ jsxs("label", { children: [
5442
+ /* @__PURE__ */ jsx(Checkbox, {
5443
+ checked: visible[key],
5444
+ disabled: key === LOCKED,
5445
+ onCheckedChange: (value) => toggleColumn(key, value === true)
5446
+ }),
5447
+ /* @__PURE__ */ jsx("span", { children: columnLabel(key) }),
5448
+ key === LOCKED ? /* @__PURE__ */ jsx("small", { children: "Required" }) : null
5449
+ ] }, key)), /* @__PURE__ */ jsxs("label", { children: [
5450
+ /* @__PURE__ */ jsx(Checkbox, {
5451
+ checked: true,
5452
+ disabled: true
5453
+ }),
5454
+ /* @__PURE__ */ jsx("span", { children: "Actions" }),
5455
+ /* @__PURE__ */ jsx("small", { children: "Required" })
5456
+ ] })]
5457
+ })
5458
+ }),
5459
+ /* @__PURE__ */ jsxs(Popover, {
5460
+ open: openPop === "filters",
5461
+ onOpenChange: (open) => setOpenPop(open ? "filters" : null),
5462
+ title: "Filters",
5463
+ trigger: /* @__PURE__ */ jsxs(Button$1, {
5464
+ variant: "outline",
5465
+ onClick: () => setOpenPop(openPop === "filters" ? null : "filters"),
5466
+ children: [
5467
+ /* @__PURE__ */ jsx(FiltersMark, {}),
5468
+ chips.length ? `Filters (${chips.length})` : "Filters",
5469
+ /* @__PURE__ */ jsx(ChevronMark, {})
5470
+ ]
5471
+ }),
5472
+ footer: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Button$1, {
5473
+ variant: "ghost",
5474
+ onClick: clearDraft,
5475
+ children: "Clear"
5476
+ }), /* @__PURE__ */ jsx(Button$1, {
5477
+ variant: "primary",
5478
+ onClick: applyFilters,
5479
+ children: "Apply filters"
5480
+ })] }),
5481
+ children: [
5482
+ /* @__PURE__ */ jsxs("div", {
5483
+ className: "bl-media-list__field",
5484
+ children: [/* @__PURE__ */ jsx("span", {
5485
+ className: "bl-media-list__field-label",
5486
+ children: "Alt text"
5487
+ }), /* @__PURE__ */ jsx("div", {
5488
+ className: "bl-media-list__radios",
5489
+ children: [
5490
+ ["any", "Any"],
5491
+ ["has", "Has alt text"],
5492
+ ["missing", "Missing alt text"]
5493
+ ].map(([value, label]) => /* @__PURE__ */ jsxs("label", { children: [/* @__PURE__ */ jsx("input", {
5494
+ type: "radio",
5495
+ name: "media-alt",
5496
+ value,
5497
+ checked: draft.alt === value,
5498
+ onChange: () => setDraft((current) => ({
5499
+ ...current,
5500
+ alt: value
5501
+ }))
5502
+ }), label] }, value))
5503
+ })]
5504
+ }),
5505
+ /* @__PURE__ */ jsxs("label", {
5506
+ className: "bl-media-list__field",
5507
+ children: [/* @__PURE__ */ jsx("span", {
5508
+ className: "bl-media-list__field-label",
5509
+ children: "Uploaded"
5510
+ }), /* @__PURE__ */ jsxs(Select, {
5511
+ value: draft.date,
5512
+ onValueChange: (value) => setDraft((current) => ({
5513
+ ...current,
5514
+ date: value
5515
+ })),
5516
+ children: [/* @__PURE__ */ jsx(SelectTrigger, {
5517
+ "aria-label": "Uploaded",
5518
+ children: /* @__PURE__ */ jsx(SelectValue, {})
5519
+ }), /* @__PURE__ */ jsxs(SelectContent, { children: [
5520
+ /* @__PURE__ */ jsx(SelectItem, {
5521
+ value: "any",
5522
+ children: "Any time"
5523
+ }),
5524
+ /* @__PURE__ */ jsx(SelectItem, {
5525
+ value: "today",
5526
+ children: "Today"
5527
+ }),
5528
+ /* @__PURE__ */ jsx(SelectItem, {
5529
+ value: "week",
5530
+ children: "Past 7 days"
5531
+ }),
5532
+ /* @__PURE__ */ jsx(SelectItem, {
5533
+ value: "month",
5534
+ children: "Past 30 days"
5535
+ })
5536
+ ] })]
5537
+ })]
5538
+ }),
5539
+ /* @__PURE__ */ jsxs("button", {
5540
+ type: "button",
5541
+ className: "bl-media-list__link",
5542
+ onClick: () => setAdvancedOpen((open) => !open),
5543
+ children: ["Advanced filters ", advancedOpen ? "▴" : "▾"]
5544
+ }),
5545
+ /* @__PURE__ */ jsxs("div", {
5546
+ className: ["bl-media-list__advanced", advancedOpen ? "is-open" : void 0].filter(Boolean).join(" "),
5547
+ children: [
5548
+ /* @__PURE__ */ jsxs("label", {
5549
+ className: "bl-media-list__field",
5550
+ children: [/* @__PURE__ */ jsx("span", {
5551
+ className: "bl-media-list__field-label",
5552
+ children: "Field"
5553
+ }), /* @__PURE__ */ jsxs(Select, {
5554
+ value: draft.advField,
5555
+ onValueChange: (value) => setDraft((current) => ({
5556
+ ...current,
5557
+ advField: value
5558
+ })),
5559
+ children: [/* @__PURE__ */ jsx(SelectTrigger, {
5560
+ "aria-label": "Field",
5561
+ children: /* @__PURE__ */ jsx(SelectValue, {})
5562
+ }), /* @__PURE__ */ jsxs(SelectContent, { children: [/* @__PURE__ */ jsx(SelectItem, {
5563
+ value: "filename",
5564
+ children: "File name"
5565
+ }), /* @__PURE__ */ jsx(SelectItem, {
5566
+ value: "alt",
5567
+ children: "Alt text"
5568
+ })] })]
5569
+ })]
5570
+ }),
5571
+ /* @__PURE__ */ jsxs("label", {
5572
+ className: "bl-media-list__field",
5573
+ children: [/* @__PURE__ */ jsx("span", {
5574
+ className: "bl-media-list__field-label",
5575
+ children: "Operator"
5576
+ }), /* @__PURE__ */ jsxs(Select, {
5577
+ value: draft.advOp,
5578
+ onValueChange: (value) => setDraft((current) => ({
5579
+ ...current,
5580
+ advOp: value
5581
+ })),
5582
+ children: [/* @__PURE__ */ jsx(SelectTrigger, {
5583
+ "aria-label": "Operator",
5584
+ children: /* @__PURE__ */ jsx(SelectValue, {})
5585
+ }), /* @__PURE__ */ jsxs(SelectContent, { children: [
5586
+ /* @__PURE__ */ jsx(SelectItem, {
5587
+ value: "contains",
5588
+ children: "contains"
5589
+ }),
5590
+ /* @__PURE__ */ jsx(SelectItem, {
5591
+ value: "equals",
5592
+ children: "equals"
5593
+ }),
5594
+ /* @__PURE__ */ jsx(SelectItem, {
5595
+ value: "not_contains",
5596
+ children: "does not contain"
5597
+ })
5598
+ ] })]
5599
+ })]
5600
+ }),
5601
+ /* @__PURE__ */ jsxs("label", {
5602
+ className: "bl-media-list__field",
5603
+ children: [/* @__PURE__ */ jsx("span", {
5604
+ className: "bl-media-list__field-label",
5605
+ children: "Value"
5606
+ }), /* @__PURE__ */ jsx(Input, {
5607
+ value: draft.advValue,
5608
+ onChange: (event) => setDraft((current) => ({
5609
+ ...current,
5610
+ advValue: event.target.value
5611
+ }))
5612
+ })]
5613
+ })
5614
+ ]
5615
+ })
5616
+ ]
5617
+ })
5618
+ ]
5619
+ }),
5620
+ chips.length > 0 ? /* @__PURE__ */ jsxs("div", {
5621
+ className: "bl-nav-kit__chips",
5622
+ children: [chips.map((chip) => /* @__PURE__ */ jsx(Chip, {
5623
+ onDismiss: () => dismissChip(chip.key),
5624
+ children: chip.label
5625
+ }, chip.key)), /* @__PURE__ */ jsx(Button$1, {
5626
+ variant: "ghost",
5627
+ onClick: clearAllFilters,
5628
+ children: "Clear all"
5629
+ })]
5630
+ }) : null,
5631
+ /* @__PURE__ */ jsxs(Table, {
5632
+ columns,
5633
+ children: [/* @__PURE__ */ jsxs(TableHead, { children: [
5634
+ /* @__PURE__ */ jsx(TableCell, {
5635
+ pin: "start",
5636
+ children: /* @__PURE__ */ jsx(Checkbox, {
5637
+ checked: allPageSelected,
5638
+ onCheckedChange: (value) => toggleAll(value === true),
5639
+ "aria-label": "Select all on this page"
5640
+ })
5641
+ }),
5642
+ shown.map((key) => /* @__PURE__ */ jsx(TableCell, {
5643
+ pin: key === "filename" ? "start" : void 0,
5644
+ shade: key === "filename",
5645
+ style: key === "filename" ? FILE_PIN_LEFT : void 0,
5646
+ children: sortable(key) ? /* @__PURE__ */ jsxs("button", {
5647
+ type: "button",
5648
+ className: "bl-media-list__sort",
5649
+ onClick: () => handleSortChange && void handleSortChange(nextSort(sort, key)),
5650
+ children: [columnLabel(key), /* @__PURE__ */ jsx(SortChevrons, { dir: sortDir(sort, key) })]
5651
+ }) : columnLabel(key)
5652
+ }, key)),
5653
+ /* @__PURE__ */ jsx(TableCell, {
5654
+ pin: "end",
5655
+ shade: true,
5656
+ children: "Actions"
5657
+ })
5658
+ ] }), docs.map((doc) => {
5659
+ const id = String(doc.id);
5660
+ const name = doc.filename || id;
5661
+ return /* @__PURE__ */ jsxs(TableRow, { children: [
5662
+ /* @__PURE__ */ jsx(TableCell, {
5663
+ pin: "start",
5664
+ children: /* @__PURE__ */ jsx(Checkbox, {
5665
+ checked: selected.has(id),
5666
+ onCheckedChange: (value) => {
5667
+ setSelected((current) => {
5668
+ const next = new Set(current);
5669
+ if (value === true) next.add(id);
5670
+ else next.delete(id);
5671
+ return next;
5672
+ });
5673
+ setSelectedLabels((current) => {
5674
+ const next = new Map(current);
5675
+ if (value === true) next.set(id, name);
5676
+ else next.delete(id);
5677
+ return next;
5678
+ });
5679
+ },
5680
+ "aria-label": `Select ${name}`
5681
+ })
5682
+ }),
5683
+ shown.map((key) => /* @__PURE__ */ jsx(TableCell, {
5684
+ pin: key === "filename" ? "start" : void 0,
5685
+ shade: key === "filename",
5686
+ style: key === "filename" ? FILE_PIN_LEFT : void 0,
5687
+ children: key === "filename" ? /* @__PURE__ */ jsxs("div", {
5688
+ className: "bl-media-list__file",
5689
+ children: [/* @__PURE__ */ jsx(Thumbnail, {
5690
+ size: "sm",
5691
+ src: doc.thumbnailURL || doc.url,
5692
+ alt: doc.alt || name
5693
+ }), /* @__PURE__ */ jsx("a", {
5694
+ className: "bl-media-list__filename",
5695
+ href: editUrl(doc.id),
5696
+ children: name
5697
+ })]
5698
+ }) : key === "alt" ? doc.alt || "—" : key === "inUse" ? inUse.has(id) ? /* @__PURE__ */ jsx("span", {
5699
+ className: "bl-media-list__inuse",
5700
+ "aria-label": "In use",
5701
+ children: /* @__PURE__ */ jsx(InUseMark, {})
5702
+ }) : null : key === "updatedAt" ? /* @__PURE__ */ jsx("span", {
5703
+ className: "bl-media-list__when",
5704
+ children: formatWhen(doc.updatedAt)
5705
+ }) : key === "createdAt" ? /* @__PURE__ */ jsx("span", {
5706
+ className: "bl-media-list__when",
5707
+ children: formatWhen(doc.createdAt)
5708
+ }) : key === "filesize" ? doc.filesize != null ? formatFilesize(doc.filesize) : "—" : doc.width && doc.height ? `${doc.width} × ${doc.height}` : "—"
5709
+ }, key)),
5710
+ /* @__PURE__ */ jsx(TableCell, {
5711
+ pin: "end",
5712
+ shade: true,
5713
+ children: /* @__PURE__ */ jsxs(TableActions, { children: [/* @__PURE__ */ jsx(Button$1, {
5714
+ size: "icon",
5715
+ variant: "ghost",
5716
+ "aria-label": `Edit ${name}`,
5717
+ onClick: () => window.location.assign(editUrl(doc.id)),
5718
+ children: /* @__PURE__ */ jsx(EditGlyph, {})
5719
+ }), /* @__PURE__ */ jsx(Button$1, {
5720
+ size: "icon",
5721
+ variant: "danger",
5722
+ "aria-label": `Delete ${name}`,
5723
+ disabled: !canDelete,
5724
+ onClick: () => askDelete([doc]),
5725
+ children: /* @__PURE__ */ jsx(DeleteGlyph, {})
5726
+ })] })
5727
+ })
5728
+ ] }, id);
5729
+ })]
5730
+ }),
5731
+ docs.length === 0 ? /* @__PURE__ */ jsx("div", {
5732
+ className: "bl-media-list__empty",
5733
+ children: "No files match these filters."
5734
+ }) : null,
5735
+ docs.length > 0 ? /* @__PURE__ */ jsx("div", {
5736
+ style: { marginTop: 16 },
5737
+ children: /* @__PURE__ */ jsx(Pagination, {
5738
+ page,
5739
+ pageCount,
5740
+ onPageChange: (next) => handlePageChange && void handlePageChange(next),
5741
+ pageSize,
5742
+ pageSizeOptions: [
5743
+ 10,
5744
+ 25,
5745
+ 50
5746
+ ],
5747
+ onPageSizeChange: (next) => handlePerPageChange && void handlePerPageChange(next)
5748
+ })
5749
+ }) : null,
5750
+ /* @__PURE__ */ jsxs(ConfirmDialog, {
5751
+ open: Boolean(confirm),
5752
+ title: confirm && confirm.names.length === 1 ? `Delete ${confirm.names[0]}?` : `Delete ${confirm?.names.length ?? 0} files?`,
5753
+ cancelLabel: "Cancel",
5754
+ confirmLabel: "Delete",
5755
+ confirmVariant: "danger",
5756
+ onCancel: () => setConfirm(null),
5757
+ onConfirm: () => void runDelete(),
5758
+ children: [confirm?.error ? /* @__PURE__ */ jsx("p", { children: confirm.error }) : null, confirmInUseUnavailable ? "The in-use check is unavailable right now. Deleting may leave a broken picture on a live page." : confirmInUse ? "This cannot be undone. At least one selected file appears on a published document or live global. Deleting it leaves a broken picture." : "This cannot be undone."]
5759
+ })
5760
+ ]
5761
+ })
5762
+ })] });
5763
+ }
5764
+ function columnLabel(key) {
5765
+ switch (key) {
5766
+ case "filename": return "File name";
5767
+ case "alt": return "Alt text";
5768
+ case "inUse": return "In Use";
5769
+ case "updatedAt": return "Updated at";
5770
+ case "createdAt": return "Created at";
5771
+ case "filesize": return "File size";
5772
+ case "dimensions": return "Dimensions";
5773
+ }
5774
+ }
5775
+ function sortable(key) {
5776
+ return key === "filename" || key === "alt" || key === "updatedAt" || key === "createdAt";
5777
+ }
5778
+ function nextSort(current, key) {
5779
+ if (current === key) return `-${key}`;
5780
+ return key;
5781
+ }
5782
+ function sortDir(current, key) {
5783
+ if (current === key) return "asc";
5784
+ if (current === `-${key}`) return "desc";
5785
+ return null;
5786
+ }
5787
+ function pinTrackWidth(cell, innerSelector) {
5788
+ const inner = cell.querySelector(innerSelector);
5789
+ const styles = getComputedStyle(cell);
5790
+ const pad = (Number.parseFloat(styles.paddingLeft) || 0) + (Number.parseFloat(styles.paddingRight) || 0);
5791
+ return (inner ? inner.scrollWidth : Math.max(0, cell.scrollWidth - pad)) + pad;
5792
+ }
5793
+ function gridColumns(shown) {
5794
+ return [
5795
+ CHECK_COL,
5796
+ ...shown.map((key) => key === "filename" ? FILE_COL : key === "inUse" ? "72px" : key === "updatedAt" || key === "createdAt" ? "148px" : "minmax(120px,1fr)"),
5797
+ ACTIONS_COL
5798
+ ].join(" ");
5799
+ }
5800
+ function chipsFrom(applied) {
5801
+ const chips = [];
5802
+ if (applied.alt === "has") chips.push({
5803
+ key: "alt",
5804
+ label: "Has alt text"
5805
+ });
5806
+ if (applied.alt === "missing") chips.push({
5807
+ key: "alt",
5808
+ label: "Missing alt text"
5809
+ });
5810
+ if (applied.date === "today") chips.push({
5811
+ key: "date",
5812
+ label: "Today"
5813
+ });
5814
+ if (applied.date === "week") chips.push({
5815
+ key: "date",
5816
+ label: "Past 7 days"
5817
+ });
5818
+ if (applied.date === "month") chips.push({
5819
+ key: "date",
5820
+ label: "Past 30 days"
5821
+ });
5822
+ if (applied.advValue.trim()) chips.push({
5823
+ key: "adv",
5824
+ label: `Advanced: ${applied.advValue.trim()}`
5825
+ });
5826
+ return chips;
5827
+ }
5828
+ function formatWhen(value) {
5829
+ if (!value) return "—";
5830
+ const date = new Date(value);
5831
+ if (Number.isNaN(date.getTime())) return value;
5832
+ const month = String(date.getMonth() + 1).padStart(2, "0");
5833
+ const day = String(date.getDate()).padStart(2, "0");
5834
+ const year = String(date.getFullYear()).slice(-2);
5835
+ const minute = String(date.getMinutes()).padStart(2, "0");
5836
+ let hour = date.getHours();
5837
+ const meridiem = hour >= 12 ? "PM" : "AM";
5838
+ hour = hour % 12 || 12;
5839
+ return `${month}/${day}/${year} ${String(hour).padStart(2, "0")}:${minute} ${meridiem}`;
5840
+ }
5841
+ function InUseMark() {
5842
+ return /* @__PURE__ */ jsx("svg", {
5843
+ xmlns: "http://www.w3.org/2000/svg",
5844
+ width: "16",
5845
+ height: "16",
5846
+ viewBox: "0 0 24 24",
5847
+ fill: "none",
5848
+ stroke: "currentColor",
5849
+ strokeWidth: "2.2",
5850
+ strokeLinecap: "round",
5851
+ strokeLinejoin: "round",
5852
+ "aria-hidden": true,
5853
+ children: /* @__PURE__ */ jsx("path", { d: "M20 6 9 17l-5-5" })
5854
+ });
5855
+ }
5856
+ function SearchMark() {
5857
+ return /* @__PURE__ */ jsxs("svg", {
5858
+ xmlns: "http://www.w3.org/2000/svg",
5859
+ width: "20",
5860
+ height: "20",
5861
+ viewBox: "0 0 24 24",
5862
+ fill: "none",
5863
+ stroke: "currentColor",
5864
+ strokeWidth: "2",
5865
+ strokeLinecap: "round",
5866
+ strokeLinejoin: "round",
5867
+ "aria-hidden": true,
5868
+ children: [/* @__PURE__ */ jsx("circle", {
5869
+ cx: "11",
5870
+ cy: "11",
5871
+ r: "7"
5872
+ }), /* @__PURE__ */ jsx("path", { d: "m20 20-3.5-3.5" })]
5873
+ });
5874
+ }
5875
+ function SortChevrons({ dir }) {
5876
+ return /* @__PURE__ */ jsxs("span", {
5877
+ className: "bl-media-list__sort-mark",
5878
+ "data-dir": dir ?? "none",
5879
+ children: [/* @__PURE__ */ jsx("svg", {
5880
+ xmlns: "http://www.w3.org/2000/svg",
5881
+ viewBox: "0 0 24 24",
5882
+ "aria-hidden": true,
5883
+ children: /* @__PURE__ */ jsx("path", { d: "m6 15 6-6 6 6" })
5884
+ }), /* @__PURE__ */ jsx("svg", {
5885
+ xmlns: "http://www.w3.org/2000/svg",
5886
+ viewBox: "0 0 24 24",
5887
+ "aria-hidden": true,
5888
+ children: /* @__PURE__ */ jsx("path", { d: "m6 9 6 6 6-6" })
5889
+ })]
5890
+ });
5891
+ }
5892
+ function ColumnsMark() {
5893
+ return /* @__PURE__ */ jsxs("svg", {
5894
+ xmlns: "http://www.w3.org/2000/svg",
5895
+ width: "16",
5896
+ height: "16",
5897
+ viewBox: "0 0 24 24",
5898
+ fill: "none",
5899
+ stroke: "currentColor",
5900
+ strokeWidth: "1.8",
5901
+ strokeLinecap: "round",
5902
+ strokeLinejoin: "round",
5903
+ "aria-hidden": true,
5904
+ children: [/* @__PURE__ */ jsx("rect", {
5905
+ x: "3",
5906
+ y: "4",
5907
+ width: "18",
5908
+ height: "16",
5909
+ rx: "2"
5910
+ }), /* @__PURE__ */ jsx("path", { d: "M9 4v16M15 4v16" })]
5911
+ });
5912
+ }
5913
+ function FiltersMark() {
5914
+ return /* @__PURE__ */ jsx("svg", {
5915
+ xmlns: "http://www.w3.org/2000/svg",
5916
+ width: "16",
5917
+ height: "16",
5918
+ viewBox: "0 0 24 24",
5919
+ fill: "none",
5920
+ stroke: "currentColor",
5921
+ strokeWidth: "1.8",
5922
+ strokeLinecap: "round",
5923
+ strokeLinejoin: "round",
5924
+ "aria-hidden": true,
5925
+ children: /* @__PURE__ */ jsx("path", { d: "M4 6h16M7 12h10M10 18h4" })
5926
+ });
5927
+ }
5928
+ function ChevronMark() {
5929
+ return /* @__PURE__ */ jsx("svg", {
5930
+ xmlns: "http://www.w3.org/2000/svg",
5931
+ width: "12",
5932
+ height: "12",
5933
+ viewBox: "0 0 24 24",
5934
+ fill: "none",
5935
+ stroke: "currentColor",
5936
+ strokeWidth: "2",
5937
+ strokeLinecap: "round",
5938
+ strokeLinejoin: "round",
5939
+ "aria-hidden": true,
5940
+ children: /* @__PURE__ */ jsx("path", { d: "m6 9 6 6 6-6" })
5941
+ });
5942
+ }
5943
+ //#endregion
5944
+ export { AdminNav, AdminNavEntityField, AdminNavItemRowLabel, AdminNavRowLabel, AppearanceField, ColorField, ColorScaleField, ContrastReport, DocumentCreateNew, DocumentTitleActions, FeaturesMatrixField, FontField, GreyScaleField, HiddenSaveButton, IdentityFallback, LibraryField, LookField, MediaAltAutofill, MediaListView, PageTitleCell, PairingField, PublishChild, QuestionsList, RoleNameField, RoleSlugField, RolesField, RolesGrantsField, RolesMatrixField, RolesRowLabel, SectionHeading, SlugField, ThemeDocumentControls, ThemeSaveButton, setThemePreviewMode };
4897
5945
 
4898
5946
  //# sourceMappingURL=admin.mjs.map