@bison-lab/payload-core 3.31.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 } 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, Dialog, Field, Input, KitProvider, Label, Select, SelectContent, SelectItem, SelectTrigger, SelectValue } 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,
@@ -4062,6 +4063,1884 @@ const AdminNavEntityField = ({ field, path, permissions, readOnly, schemaPath })
4062
4063
  });
4063
4064
  };
4064
4065
  //#endregion
4065
- export { AdminNav, AdminNavEntityField, AdminNavItemRowLabel, AdminNavRowLabel, AppearanceField, ColorField, ColorScaleField, ContrastReport, DocumentCreateNew, DocumentTitleActions, FeaturesMatrixField, FontField, GreyScaleField, HiddenSaveButton, IdentityFallback, LibraryField, LookField, PageTitleCell, PairingField, PublishChild, RoleNameField, RoleSlugField, RolesField, RolesGrantsField, RolesMatrixField, RolesRowLabel, SectionHeading, SlugField, ThemeDocumentControls, ThemeSaveButton, setThemePreviewMode };
4066
+ //#region src/admin/questions-list-css.ts
4067
+ /**
4068
+ * List chrome for the FAQ Library kit screen. Width is kit `Page`
4069
+ * (Payload `--gutter-h`). Paint is kit tokens.
4070
+ */
4071
+ const QUESTIONS_LIST_CSS = `
4072
+ .collection-list__header,.list-header{display:none}
4073
+ .bl-faq-library{font:14px/1.45 Inter,ui-sans-serif,system-ui,sans-serif;color:var(--bl-kit-ink)}
4074
+ .bl-faq-library .bl-workspace__main-head{padding:0;margin:0 0 22px;align-items:flex-start}
4075
+ .bl-faq-library .bl-workspace__main-head h1{display:flex;align-items:baseline;gap:.45em;font-size:27px;margin:0 0 5px;font-weight:700;letter-spacing:-.02em}
4076
+ .bl-faq-library .bl-workspace__main-head p{margin:0;color:var(--bl-kit-ink-muted)}
4077
+ .bl-faq-library__count{color:var(--bl-kit-ink-muted);white-space:nowrap;font-size:13px;font-weight:500;letter-spacing:0}
4078
+ .bl-faq-library__toolbar{display:flex;align-items:center;gap:10px;margin:0 0 14px;padding:14px;border:1px solid var(--bl-kit-border);border-radius:var(--bl-kit-radius);background:var(--bl-kit-surface);box-shadow:0 1px 2px rgba(20,25,35,.04),0 8px 28px rgba(20,25,35,.05)}
4079
+ .bl-faq-library__search{position:relative;flex:1;min-width:12rem}
4080
+ .bl-faq-library__search:before{content:"";position:absolute;left:12px;top:50%;transform:translateY(-50%);width:16px;height:16px;background:no-repeat center/16px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' stroke='%23858c96' stroke-width='1.8' viewBox='0 0 24 24'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M20 20l-3.5-3.5' stroke-linecap='round'/%3E%3C/svg%3E");pointer-events:none}
4081
+ .bl-faq-library__search .bl-nav-kit__input{padding-left:34px}
4082
+ .bl-faq-library__filter{width:auto;min-width:150px}
4083
+ .bl-faq-library__table{box-shadow:0 1px 2px rgba(20,25,35,.04),0 8px 28px rgba(20,25,35,.05)}
4084
+ .bl-faq-library__table .bl-nav-kit__table-row{align-items:flex-start;padding:14px}
4085
+ .bl-faq-library__table .bl-nav-kit__table-head{align-items:center;padding:11px 14px}
4086
+ .bl-faq-library__question{font-weight:700;margin:0 0 4px}
4087
+ .bl-faq-library__answer{margin:0;color:var(--bl-kit-ink-muted);max-width:640px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
4088
+ .bl-faq-library__chips{display:flex;flex-wrap:wrap;gap:5px}
4089
+ .bl-faq-library__chip{font-size:12px;font-weight:650;padding:3px 7px}
4090
+ .bl-faq-library__chip--anatomy{background:var(--bl-kit-accent-soft);color:var(--bl-kit-accent,#2563eb)}
4091
+ .bl-faq-library__chip--look{background:hsl(var(--look-tint));color:hsl(var(--look-ink))}
4092
+ [data-theme="dark"] .bl-faq-library__chip--look{background:hsl(var(--look-tint-dark));color:hsl(var(--look-ink-dark))}
4093
+ .bl-faq-library__chip--topic{background:color-mix(in srgb,var(--theme-info-500,#1769aa) 12%,var(--bl-kit-surface));color:var(--theme-info-500,#1769aa)}
4094
+ .bl-faq-library__used{font-size:12px;color:var(--bl-kit-ink-muted)}
4095
+ .bl-faq-library__used strong{color:var(--bl-kit-ink);font-weight:700}
4096
+ .bl-faq-library__empty{display:none;padding:55px;text-align:center;color:var(--bl-kit-ink-muted);border:1px solid var(--bl-kit-border);border-radius:var(--bl-kit-radius);background:var(--bl-kit-surface)}
4097
+ .bl-faq-library__empty.is-visible{display:block}
4098
+ .bl-faq-library__empty.is-visible + .bl-faq-library__table,.bl-faq-library__table:has(+ .bl-faq-library__empty.is-visible){display:none}
4099
+ .bl-faq-library__manage{display:none;margin:14px 0 0;padding:18px;border:1px solid var(--bl-kit-border);border-radius:var(--bl-kit-radius);background:var(--bl-kit-surface);box-shadow:var(--bl-kit-shadow-sm)}
4100
+ .bl-faq-library__manage.is-open{display:block}
4101
+ .bl-faq-library__manage-head{display:flex;justify-content:space-between;align-items:flex-start;gap:16px;margin:0 0 14px}
4102
+ .bl-faq-library__manage-head h3{margin:0;font-size:16px}
4103
+ .bl-faq-library__manage-grid{display:grid;grid-template-columns:1fr 1fr;gap:22px}
4104
+ .bl-faq-library__taxonomy{border:1px solid var(--bl-kit-border);border-radius:var(--bl-kit-radius-sm);overflow:hidden;background:var(--bl-kit-surface)}
4105
+ .bl-faq-library__taxonomy h4{margin:0;padding:11px 13px;background:var(--bl-kit-surface-well);border-bottom:1px solid var(--bl-kit-border);font-size:14px}
4106
+ .bl-faq-library__taxrow{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:10px 13px;border-bottom:1px solid var(--bl-kit-border-divider)}
4107
+ .bl-faq-library__taxrow:last-child{border-bottom:0}
4108
+ .bl-faq-library__taxmeta{color:var(--bl-kit-ink-muted);font-size:12px}
4109
+ .bl-faq-library__taxrow .bl-faq-library__taxmeta{display:inline-flex;align-items:center;gap:14px}
4110
+ .bl-faq-library__addrow{display:flex;gap:7px;padding:10px;border-top:1px solid var(--bl-kit-border);background:var(--bl-kit-surface-well)}
4111
+ .bl-faq-library__addrow .bl-nav-kit__input{flex:1;min-width:0}
4112
+ .bl-faq-library__modal .bl-nav-kit__modal-card,.bl-faq-library__dialog.bl-nav-kit__modal-card{width:min(760px,100%)}
4113
+ .bl-faq-library__modal-card{width:min(760px,calc(100vw - 2rem));max-height:calc(100vh - 48px);overflow:auto;background:var(--bl-kit-surface);border:1px solid var(--bl-kit-border);border-radius:var(--bl-kit-radius-lg);box-shadow:var(--bl-kit-shadow)}
4114
+ .bl-faq-library__modal-head{display:flex;justify-content:space-between;align-items:center;padding:18px 22px;border-bottom:1px solid var(--bl-kit-border);position:sticky;top:0;background:var(--bl-kit-surface);z-index:2}
4115
+ .bl-faq-library__modal-head h2{margin:0;font-size:20px}
4116
+ .bl-faq-library__modal-body{padding:20px 22px}
4117
+ .bl-faq-library__grid{display:grid;grid-template-columns:1fr 1fr;gap:18px}
4118
+ .bl-faq-library__section{font-weight:800;margin:4px 0 12px;padding-top:14px;border-top:1px solid var(--bl-kit-border-divider)}
4119
+ .bl-faq-library__hint{display:block;margin-top:6px;color:var(--bl-kit-ink-muted);font-size:12px}
4120
+ .bl-faq-library__choicebox{border:1px solid var(--bl-kit-border-strong);border-radius:var(--bl-kit-radius-sm);overflow:hidden;background:var(--bl-kit-surface)}
4121
+ .bl-faq-library__choice{display:flex;align-items:center;gap:9px;margin:0;padding:9px 11px;border-bottom:1px solid var(--bl-kit-border-divider);cursor:pointer;font-weight:500}
4122
+ .bl-faq-library__choice:last-child{border-bottom:0}
4123
+ .bl-faq-library__choice:hover{background:var(--bl-kit-surface-well)}
4124
+ .bl-faq-library__addtag{border:0;background:transparent;color:var(--bl-kit-accent,#2563eb);padding:8px 0 0;cursor:pointer;font-weight:650}
4125
+ .bl-faq-library__addtag:hover{text-decoration:underline}
4126
+ .bl-faq-library__inline-add{display:flex;gap:7px;margin-top:8px}
4127
+ .bl-faq-library__notice{padding:11px 12px;border-radius:var(--bl-kit-radius-sm);background:var(--bl-kit-accent-soft);color:var(--bl-kit-accent,#2563eb);font-size:13px}
4128
+ .bl-faq-library__modal-foot{display:flex;justify-content:space-between;align-items:center;gap:12px;padding:16px 22px;border-top:1px solid var(--bl-kit-border);position:sticky;bottom:0;background:var(--bl-kit-surface)}
4129
+ .bl-faq-library__published{display:flex;align-items:center;gap:8px;color:var(--bl-kit-ink-muted);cursor:pointer}
4130
+ .bl-faq-library__foot-actions{display:flex;gap:8px}
4131
+ .bl-faq-library__danger.bl-nav-kit__modal-card{width:min(500px,calc(100vw - 2rem))}
4132
+ .bl-faq-library__danger-body{padding:24px}
4133
+ .bl-faq-library__danger-heading{display:flex;align-items:center;gap:14px;margin:0 0 16px}
4134
+ .bl-faq-library__danger-icon{width:42px;height:42px;flex:none;border-radius:50%;display:grid;place-items:center;background:color-mix(in srgb,hsl(var(--destructive,0 84% 60%)) 12%,var(--bl-kit-surface));color:hsl(var(--destructive,0 84% 60%));font-size:21px;font-weight:800}
4135
+ .bl-faq-library__danger-heading h2{margin:0;font-size:20px}
4136
+ .bl-faq-library__danger-body p{margin:0 0 12px;color:var(--bl-kit-ink-muted)}
4137
+ .bl-faq-library__impact{background:color-mix(in srgb,hsl(var(--destructive,0 84% 60%)) 8%,var(--bl-kit-surface));border:1px solid color-mix(in srgb,hsl(var(--destructive,0 84% 60%)) 28%,var(--bl-kit-border));border-radius:var(--bl-kit-radius-sm);padding:12px;color:hsl(var(--destructive-700,353 100% 26%))}
4138
+ .bl-faq-library__link{border:0;background:transparent;color:var(--bl-kit-accent,#2563eb);padding:0;cursor:pointer;text-decoration:underline;font:inherit}
4139
+ .bl-faq-library__error{margin:0 0 14px;color:hsl(var(--destructive,0 84% 60%))}
4140
+ .bl-faq-library__pages{margin-top:14px}
4141
+ @media(max-width:900px){
4142
+ .bl-faq-library__toolbar{flex-wrap:wrap}
4143
+ .bl-faq-library__search{flex-basis:100%}
4144
+ .bl-faq-library__grid,.bl-faq-library__manage-grid{grid-template-columns:1fr}
4145
+ .bl-faq-library__used-col{display:none}
4146
+ }
4147
+ `;
4148
+ //#endregion
4149
+ //#region src/admin/questions-list.tsx
4150
+ const ALL = "__all__";
4151
+ const PAGE_SIZE = 25;
4152
+ function asId(value) {
4153
+ if (typeof value === "string" || typeof value === "number") return value;
4154
+ if (value && typeof value === "object" && "id" in value) {
4155
+ const id = value.id;
4156
+ if (typeof id === "string" || typeof id === "number") return id;
4157
+ }
4158
+ return null;
4159
+ }
4160
+ function idsFrom(value) {
4161
+ if (!Array.isArray(value)) return [];
4162
+ return value.map(asId).filter((id) => id !== null);
4163
+ }
4164
+ function termName(value) {
4165
+ if (value && typeof value === "object" && "name" in value && typeof value.name === "string") return value.name;
4166
+ return "";
4167
+ }
4168
+ function familyFromDoc(value) {
4169
+ if (!value || typeof value !== "object") return void 0;
4170
+ const rec = value;
4171
+ for (const key of ["family", "look"]) {
4172
+ const raw = rec[key];
4173
+ if (typeof raw === "string" && raw.trim()) return raw.trim();
4174
+ }
4175
+ }
4176
+ function chipsFrom$1(value) {
4177
+ if (!Array.isArray(value)) return [];
4178
+ const chips = [];
4179
+ for (const item of value) {
4180
+ const name = termName(item);
4181
+ if (!name) continue;
4182
+ chips.push({
4183
+ name,
4184
+ family: familyFromDoc(item)
4185
+ });
4186
+ }
4187
+ return chips;
4188
+ }
4189
+ function lookMapsFromGlobal(doc, look) {
4190
+ const path = look.path ?? "areas";
4191
+ const labelKey = look.label ?? "label";
4192
+ const familyKey = look.family ?? "family";
4193
+ const rows = Array.isArray(doc?.[path]) ? doc[path] : [];
4194
+ const map = {};
4195
+ for (const row of rows) {
4196
+ if (!row || typeof row !== "object") continue;
4197
+ const rec = row;
4198
+ const family = typeof rec[familyKey] === "string" ? rec[familyKey].trim() : "";
4199
+ if (!family) continue;
4200
+ const label = typeof rec[labelKey] === "string" ? rec[labelKey].trim() : "";
4201
+ const key = typeof rec.key === "string" ? rec.key.trim() : "";
4202
+ if (label) map[label.toLowerCase()] = family;
4203
+ if (key) map[key.toLowerCase()] = family;
4204
+ }
4205
+ return map;
4206
+ }
4207
+ function resolveFamily(field, name, family, looks) {
4208
+ return family || looks[field]?.[name.toLowerCase()] || void 0;
4209
+ }
4210
+ function useApi() {
4211
+ const { config } = useConfig();
4212
+ const base = `${config.serverURL}${config.routes.api}`;
4213
+ return useCallback(async function request(path, init) {
4214
+ const response = await fetch(`${base}${path}`, {
4215
+ credentials: "include",
4216
+ ...init,
4217
+ headers: {
4218
+ "Content-Type": "application/json",
4219
+ ...init?.headers ?? {}
4220
+ }
4221
+ });
4222
+ const body = await response.json().catch(() => null);
4223
+ if (!response.ok) throw new Error(body?.errors?.[0]?.message ?? body?.message ?? response.statusText);
4224
+ return body;
4225
+ }, [base]);
4226
+ }
4227
+ function useOrganizeBy(collectionSlug, fromProps) {
4228
+ const { config } = useConfig();
4229
+ return useMemo(() => {
4230
+ if (fromProps && fromProps.length > 0) return fromProps;
4231
+ return (config.collections.find((entry) => entry.slug === collectionSlug)?.admin?.custom)?.organizeBy ?? [];
4232
+ }, [
4233
+ collectionSlug,
4234
+ config.collections,
4235
+ fromProps
4236
+ ]);
4237
+ }
4238
+ function QuestionsList(props) {
4239
+ return /* @__PURE__ */ jsx(ThemeKitAccent, { children: /* @__PURE__ */ jsx(QuestionsListPage, { ...props }) });
4240
+ }
4241
+ function QuestionsListPage({ collectionSlug, organizeBy: organizeByProp }) {
4242
+ const { setStepNav } = useStepNav();
4243
+ const organizeBy = useOrganizeBy(collectionSlug, organizeByProp);
4244
+ const request = useApi();
4245
+ useEffect(() => {
4246
+ setStepNav([{ label: "FAQ Library" }]);
4247
+ }, [setStepNav]);
4248
+ const [docs, setDocs] = useState([]);
4249
+ const [total, setTotal] = useState(0);
4250
+ const [page, setPage] = useState(1);
4251
+ const [terms, setTerms] = useState({});
4252
+ const [looks, setLooks] = useState({});
4253
+ const [counts, setCounts] = useState({});
4254
+ const [search, setSearch] = useState("");
4255
+ const [filters, setFilters] = useState({});
4256
+ const [manageOpen, setManageOpen] = useState(false);
4257
+ const [faqOpen, setFaqOpen] = useState(false);
4258
+ const [editing, setEditing] = useState(null);
4259
+ const [draftQuestion, setDraftQuestion] = useState("");
4260
+ const [draftAnswer, setDraftAnswer] = useState("");
4261
+ const [draftFacets, setDraftFacets] = useState({});
4262
+ const [published, setPublished] = useState(true);
4263
+ const [inlineTopic, setInlineTopic] = useState(null);
4264
+ const [newTerm, setNewTerm] = useState({});
4265
+ const [deleteFaq, setDeleteFaq] = useState(null);
4266
+ const [deleteTerm, setDeleteTerm] = useState(null);
4267
+ const [error, setError] = useState(null);
4268
+ const [busy, setBusy] = useState(false);
4269
+ const loadTerms = useCallback(async () => {
4270
+ const next = {};
4271
+ await Promise.all(organizeBy.map(async (entry) => {
4272
+ const data = await request(`/${entry.collection}?limit=200&sort=name&depth=0`);
4273
+ next[entry.name] = (data.docs ?? []).map((doc) => ({
4274
+ id: doc.id,
4275
+ name: typeof doc.name === "string" ? doc.name : String(doc.id),
4276
+ family: familyFromDoc(doc)
4277
+ }));
4278
+ }));
4279
+ setTerms(next);
4280
+ }, [organizeBy, request]);
4281
+ const loadDocs = useCallback(async () => {
4282
+ const where = { and: [] };
4283
+ const and = where.and;
4284
+ const q = search.trim();
4285
+ if (q) and.push({ or: [{ question: { contains: q } }, { answer: { contains: q } }] });
4286
+ for (const [field, value] of Object.entries(filters)) if (value) and.push({ [field]: { equals: value } });
4287
+ const params = new URLSearchParams({
4288
+ depth: "1",
4289
+ draft: "true",
4290
+ limit: String(PAGE_SIZE),
4291
+ page: String(page),
4292
+ sort: "createdAt"
4293
+ });
4294
+ if (and.length > 0) params.set("where", JSON.stringify(where));
4295
+ const data = await request(`/${collectionSlug}?${params.toString()}`);
4296
+ setDocs(data.docs ?? []);
4297
+ setTotal(data.totalDocs ?? data.docs?.length ?? 0);
4298
+ }, [
4299
+ collectionSlug,
4300
+ filters,
4301
+ page,
4302
+ request,
4303
+ search
4304
+ ]);
4305
+ const loadLooks = useCallback(async () => {
4306
+ const next = {};
4307
+ await Promise.all(organizeBy.map(async (entry) => {
4308
+ if (!entry.look?.global) return;
4309
+ try {
4310
+ const doc = await request(`/globals/${entry.look.global}?depth=0`);
4311
+ next[entry.name] = lookMapsFromGlobal(doc, entry.look);
4312
+ } catch {
4313
+ next[entry.name] = {};
4314
+ }
4315
+ }));
4316
+ setLooks(next);
4317
+ }, [organizeBy, request]);
4318
+ const loadCounts = useCallback(async () => {
4319
+ const next = {};
4320
+ await Promise.all(organizeBy.map(async (entry) => {
4321
+ next[entry.name] = {};
4322
+ await Promise.all((terms[entry.name] ?? []).map(async (term) => {
4323
+ const data = await request(`/${collectionSlug}/count?${new URLSearchParams({
4324
+ draft: "true",
4325
+ where: JSON.stringify({ [entry.name]: { equals: term.id } })
4326
+ }).toString()}`);
4327
+ next[entry.name][String(term.id)] = data.totalDocs ?? 0;
4328
+ }));
4329
+ }));
4330
+ setCounts(next);
4331
+ }, [
4332
+ collectionSlug,
4333
+ organizeBy,
4334
+ request,
4335
+ terms
4336
+ ]);
4337
+ useEffect(() => {
4338
+ loadTerms().catch((err) => {
4339
+ setError(err instanceof Error ? err.message : "Could not load terms");
4340
+ });
4341
+ }, [loadTerms]);
4342
+ useEffect(() => {
4343
+ loadLooks().catch(() => void 0);
4344
+ }, [loadLooks]);
4345
+ useEffect(() => {
4346
+ loadDocs().catch((err) => {
4347
+ setError(err instanceof Error ? err.message : "Could not load FAQs");
4348
+ });
4349
+ }, [loadDocs]);
4350
+ useEffect(() => {
4351
+ if (!manageOpen) return;
4352
+ loadCounts().catch(() => void 0);
4353
+ }, [loadCounts, manageOpen]);
4354
+ function openFaq(doc) {
4355
+ setEditing(doc);
4356
+ setDraftQuestion(doc?.question ?? "");
4357
+ setDraftAnswer(doc?.answer ?? "");
4358
+ setPublished(doc ? doc._status !== "draft" : true);
4359
+ const selected = {};
4360
+ for (const entry of organizeBy) selected[entry.name] = doc ? idsFrom(doc[entry.name]) : [];
4361
+ setDraftFacets(selected);
4362
+ setInlineTopic(null);
4363
+ setFaqOpen(true);
4364
+ }
4365
+ function toggleFacet(field, id, on) {
4366
+ setDraftFacets((current) => {
4367
+ const next = new Set(current[field] ?? []);
4368
+ if (on) next.add(id);
4369
+ else next.delete(id);
4370
+ return {
4371
+ ...current,
4372
+ [field]: [...next]
4373
+ };
4374
+ });
4375
+ }
4376
+ async function saveFaq() {
4377
+ const question = draftQuestion.trim();
4378
+ const answer = draftAnswer.trim();
4379
+ if (!question || !answer) {
4380
+ setError("Question and answer are required.");
4381
+ return;
4382
+ }
4383
+ setBusy(true);
4384
+ setError(null);
4385
+ const body = {
4386
+ question,
4387
+ answer,
4388
+ _status: published ? "published" : "draft",
4389
+ ...Object.fromEntries(organizeBy.map((entry) => [entry.name, draftFacets[entry.name] ?? []]))
4390
+ };
4391
+ try {
4392
+ if (editing) await request(`/${collectionSlug}/${editing.id}`, {
4393
+ method: "PATCH",
4394
+ body: JSON.stringify(body)
4395
+ });
4396
+ else await request(`/${collectionSlug}`, {
4397
+ method: "POST",
4398
+ body: JSON.stringify(body)
4399
+ });
4400
+ setFaqOpen(false);
4401
+ await loadDocs();
4402
+ await loadTerms();
4403
+ } catch (err) {
4404
+ setError(err instanceof Error ? err.message : "Save failed");
4405
+ } finally {
4406
+ setBusy(false);
4407
+ }
4408
+ }
4409
+ async function confirmDeleteFaq() {
4410
+ if (!deleteFaq) return;
4411
+ setBusy(true);
4412
+ try {
4413
+ await request(`/${collectionSlug}/${deleteFaq.id}`, { method: "DELETE" });
4414
+ setDeleteFaq(null);
4415
+ await loadDocs();
4416
+ } catch (err) {
4417
+ setError(err instanceof Error ? err.message : "Delete failed");
4418
+ } finally {
4419
+ setBusy(false);
4420
+ }
4421
+ }
4422
+ async function addTerm(entry, name) {
4423
+ const trimmed = name.trim();
4424
+ if (!trimmed) return;
4425
+ setBusy(true);
4426
+ try {
4427
+ const created = await request(`/${entry.collection}`, {
4428
+ method: "POST",
4429
+ body: JSON.stringify({ name: trimmed })
4430
+ });
4431
+ setNewTerm((current) => ({
4432
+ ...current,
4433
+ [entry.name]: ""
4434
+ }));
4435
+ setInlineTopic(null);
4436
+ await loadTerms();
4437
+ toggleFacet(entry.name, created.id, true);
4438
+ } catch (err) {
4439
+ setError(err instanceof Error ? err.message : "Could not add term");
4440
+ } finally {
4441
+ setBusy(false);
4442
+ }
4443
+ }
4444
+ async function confirmDeleteTerm() {
4445
+ if (!deleteTerm) return;
4446
+ setBusy(true);
4447
+ try {
4448
+ await request(`/${deleteTerm.entry.collection}/${deleteTerm.term.id}`, { method: "DELETE" });
4449
+ setDeleteTerm(null);
4450
+ await loadTerms();
4451
+ await loadDocs();
4452
+ await loadCounts();
4453
+ } catch (err) {
4454
+ setError(err instanceof Error ? err.message : "Could not delete term");
4455
+ } finally {
4456
+ setBusy(false);
4457
+ }
4458
+ }
4459
+ const pageCount = Math.max(1, Math.ceil(total / PAGE_SIZE));
4460
+ const columns = [
4461
+ "minmax(0,2.2fr)",
4462
+ ...organizeBy.map(() => "minmax(7rem,1fr)"),
4463
+ "6.5rem",
4464
+ "90px"
4465
+ ].join(" ");
4466
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
4467
+ /* @__PURE__ */ jsx("style", {
4468
+ href: "bl-faq-library",
4469
+ precedence: "high",
4470
+ children: QUESTIONS_LIST_CSS
4471
+ }),
4472
+ /* @__PURE__ */ jsxs(Page, {
4473
+ className: "bl-faq-library",
4474
+ children: [
4475
+ /* @__PURE__ */ jsx(MainHead, {
4476
+ title: /* @__PURE__ */ jsxs(Fragment, { children: ["FAQ Library", /* @__PURE__ */ jsxs("span", {
4477
+ className: "bl-faq-library__count",
4478
+ children: [
4479
+ total,
4480
+ " FAQ",
4481
+ total === 1 ? "" : "s"
4482
+ ]
4483
+ })] }),
4484
+ description: "Create answers once, organize them, and reuse them across the website.",
4485
+ children: /* @__PURE__ */ jsx(Button$1, {
4486
+ onClick: () => openFaq(null),
4487
+ children: "+ New FAQ"
4488
+ })
4489
+ }),
4490
+ error ? /* @__PURE__ */ jsx("p", {
4491
+ className: "bl-faq-library__error",
4492
+ children: error
4493
+ }) : null,
4494
+ /* @__PURE__ */ jsxs("div", {
4495
+ className: "bl-faq-library__toolbar",
4496
+ children: [
4497
+ /* @__PURE__ */ jsx("div", {
4498
+ className: "bl-faq-library__search",
4499
+ children: /* @__PURE__ */ jsx(Input, {
4500
+ value: search,
4501
+ onChange: (event) => {
4502
+ setPage(1);
4503
+ setSearch(event.target.value);
4504
+ },
4505
+ placeholder: "Search questions or answers…",
4506
+ "aria-label": "Search questions or answers"
4507
+ })
4508
+ }),
4509
+ organizeBy.map((entry) => /* @__PURE__ */ jsxs(Select, {
4510
+ value: filters[entry.name] || ALL,
4511
+ onValueChange: (value) => {
4512
+ setPage(1);
4513
+ setFilters((current) => ({
4514
+ ...current,
4515
+ [entry.name]: value === ALL ? "" : value
4516
+ }));
4517
+ },
4518
+ children: [/* @__PURE__ */ jsx(SelectTrigger, {
4519
+ className: "bl-faq-library__filter",
4520
+ "aria-label": entry.label,
4521
+ children: /* @__PURE__ */ jsx(SelectValue, { placeholder: `All ${entry.label.toLowerCase()}` })
4522
+ }), /* @__PURE__ */ jsxs(SelectContent, { children: [/* @__PURE__ */ jsxs(SelectItem, {
4523
+ value: ALL,
4524
+ children: ["All ", entry.label.toLowerCase()]
4525
+ }), (terms[entry.name] ?? []).map((term) => /* @__PURE__ */ jsx(SelectItem, {
4526
+ value: String(term.id),
4527
+ children: term.name
4528
+ }, String(term.id)))] })]
4529
+ }, entry.name)),
4530
+ /* @__PURE__ */ jsx(Button$1, {
4531
+ variant: "outline",
4532
+ onClick: () => setManageOpen((open) => !open),
4533
+ children: "Manage organization"
4534
+ })
4535
+ ]
4536
+ }),
4537
+ /* @__PURE__ */ jsx("p", {
4538
+ className: docs.length ? "bl-faq-library__empty" : "bl-faq-library__empty is-visible",
4539
+ children: "No FAQs match these filters."
4540
+ }),
4541
+ /* @__PURE__ */ jsxs(Table, {
4542
+ className: "bl-faq-library__table",
4543
+ columns,
4544
+ children: [/* @__PURE__ */ jsxs(TableHead, { children: [
4545
+ /* @__PURE__ */ jsx(TableCell, { children: "FAQ" }),
4546
+ organizeBy.map((entry) => /* @__PURE__ */ jsx(TableCell, { children: entry.label }, entry.name)),
4547
+ /* @__PURE__ */ jsx(TableCell, {
4548
+ className: "bl-faq-library__used-col",
4549
+ children: "Used on"
4550
+ }),
4551
+ /* @__PURE__ */ jsx(TableCell, {})
4552
+ ] }), docs.map((doc) => /* @__PURE__ */ jsxs(TableRow, { children: [
4553
+ /* @__PURE__ */ jsxs(TableCell, { children: [/* @__PURE__ */ jsx("div", {
4554
+ className: "bl-faq-library__question",
4555
+ children: doc.question
4556
+ }), /* @__PURE__ */ jsx("p", {
4557
+ className: "bl-faq-library__answer",
4558
+ children: doc.answer
4559
+ })] }),
4560
+ organizeBy.map((entry) => {
4561
+ const chips = chipsFrom$1(doc[entry.name]);
4562
+ const kind = entry.manage ? "topic" : "anatomy";
4563
+ return /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx("div", {
4564
+ className: "bl-faq-library__chips",
4565
+ children: chips.length === 0 && !entry.manage ? /* @__PURE__ */ jsx("span", {
4566
+ className: "bl-faq-library__used",
4567
+ children: "General"
4568
+ }) : chips.map((chip) => {
4569
+ const family = resolveFamily(entry.name, chip.name, chip.family, looks);
4570
+ return /* @__PURE__ */ jsx(Badge, {
4571
+ variant: false,
4572
+ "data-look": family,
4573
+ className: [
4574
+ "bl-faq-library__chip",
4575
+ `bl-faq-library__chip--${kind}`,
4576
+ family ? "bl-faq-library__chip--look" : ""
4577
+ ].filter(Boolean).join(" "),
4578
+ children: chip.name
4579
+ }, chip.name);
4580
+ })
4581
+ }) }, entry.name);
4582
+ }),
4583
+ /* @__PURE__ */ jsx(TableCell, {
4584
+ className: "bl-faq-library__used-col",
4585
+ children: /* @__PURE__ */ jsxs("div", {
4586
+ className: "bl-faq-library__used",
4587
+ children: [/* @__PURE__ */ jsx("strong", { children: "0" }), " pages"]
4588
+ })
4589
+ }),
4590
+ /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsxs(TableActions, { children: [/* @__PURE__ */ jsx(Button$1, {
4591
+ size: "icon",
4592
+ variant: "ghost",
4593
+ "aria-label": "Edit",
4594
+ onClick: () => openFaq(doc),
4595
+ children: /* @__PURE__ */ jsx(EditGlyph, {})
4596
+ }), /* @__PURE__ */ jsx(Button$1, {
4597
+ size: "icon",
4598
+ variant: "ghost",
4599
+ "aria-label": "Delete",
4600
+ onClick: () => setDeleteFaq(doc),
4601
+ children: /* @__PURE__ */ jsx(DeleteGlyph, {})
4602
+ })] }) })
4603
+ ] }, String(doc.id)))]
4604
+ }),
4605
+ total > PAGE_SIZE ? /* @__PURE__ */ jsx(Pagination, {
4606
+ className: "bl-faq-library__pages",
4607
+ page,
4608
+ pageCount,
4609
+ onPageChange: setPage
4610
+ }) : null,
4611
+ /* @__PURE__ */ jsxs("div", {
4612
+ className: manageOpen ? "bl-faq-library__manage is-open" : "bl-faq-library__manage",
4613
+ children: [/* @__PURE__ */ jsxs("div", {
4614
+ className: "bl-faq-library__manage-head",
4615
+ children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h3", { children: "Manage organization" }), /* @__PURE__ */ jsx("div", {
4616
+ className: "bl-faq-library__taxmeta",
4617
+ children: "Anatomy comes from your existing Anatomy collection. Topics are flexible labels created for FAQs."
4618
+ })] }), /* @__PURE__ */ jsx(Button$1, {
4619
+ variant: "outline",
4620
+ onClick: () => setManageOpen(false),
4621
+ children: "Done"
4622
+ })]
4623
+ }), /* @__PURE__ */ jsx("div", {
4624
+ className: "bl-faq-library__manage-grid",
4625
+ children: organizeBy.map((entry) => /* @__PURE__ */ jsxs("div", {
4626
+ className: "bl-faq-library__taxonomy",
4627
+ children: [
4628
+ /* @__PURE__ */ jsxs("h4", { children: [
4629
+ entry.label,
4630
+ " ",
4631
+ /* @__PURE__ */ jsx("span", {
4632
+ className: "bl-faq-library__taxmeta",
4633
+ children: entry.manage ? "FAQ-specific" : "linked collection"
4634
+ })
4635
+ ] }),
4636
+ (terms[entry.name] ?? []).map((term) => /* @__PURE__ */ jsxs("div", {
4637
+ className: "bl-faq-library__taxrow",
4638
+ children: [/* @__PURE__ */ jsx("span", { children: term.name }), /* @__PURE__ */ jsxs("span", {
4639
+ className: "bl-faq-library__taxmeta",
4640
+ children: [
4641
+ counts[entry.name]?.[String(term.id)] ?? 0,
4642
+ " FAQs",
4643
+ entry.manage ? /* @__PURE__ */ jsx(Button$1, {
4644
+ size: "icon",
4645
+ variant: "ghost",
4646
+ "aria-label": `Delete ${term.name}`,
4647
+ onClick: () => setDeleteTerm({
4648
+ entry,
4649
+ term,
4650
+ count: counts[entry.name]?.[String(term.id)] ?? 0
4651
+ }),
4652
+ children: /* @__PURE__ */ jsx(DeleteGlyph, {})
4653
+ }) : null
4654
+ ]
4655
+ })]
4656
+ }, String(term.id))),
4657
+ entry.manage ? /* @__PURE__ */ jsxs("div", {
4658
+ className: "bl-faq-library__addrow",
4659
+ children: [/* @__PURE__ */ jsx(Input, {
4660
+ value: newTerm[entry.name] ?? "",
4661
+ onChange: (event) => setNewTerm((current) => ({
4662
+ ...current,
4663
+ [entry.name]: event.target.value
4664
+ })),
4665
+ placeholder: `New ${entry.label.toLowerCase().replace(/s$/, "")} name`,
4666
+ onKeyDown: (event) => {
4667
+ if (event.key === "Enter") {
4668
+ event.preventDefault();
4669
+ addTerm(entry, newTerm[entry.name] ?? "");
4670
+ }
4671
+ }
4672
+ }), /* @__PURE__ */ jsx(Button$1, {
4673
+ variant: "outline",
4674
+ disabled: busy,
4675
+ onClick: () => void addTerm(entry, newTerm[entry.name] ?? ""),
4676
+ children: "Add"
4677
+ })]
4678
+ }) : null
4679
+ ]
4680
+ }, entry.name))
4681
+ })]
4682
+ })
4683
+ ]
4684
+ }),
4685
+ faqOpen ? /* @__PURE__ */ jsx("div", {
4686
+ className: "bl-nav-kit__modal bl-faq-library__modal",
4687
+ role: "dialog",
4688
+ "aria-modal": "true",
4689
+ "aria-labelledby": "bl-faq-library-title",
4690
+ onClick: () => setFaqOpen(false),
4691
+ children: /* @__PURE__ */ jsxs("div", {
4692
+ className: "bl-faq-library__modal-card",
4693
+ onClick: (event) => event.stopPropagation(),
4694
+ children: [
4695
+ /* @__PURE__ */ jsxs("div", {
4696
+ className: "bl-faq-library__modal-head",
4697
+ children: [/* @__PURE__ */ jsx("h2", {
4698
+ id: "bl-faq-library-title",
4699
+ children: editing ? "Edit FAQ" : "New FAQ"
4700
+ }), /* @__PURE__ */ jsx(Button$1, {
4701
+ size: "icon",
4702
+ variant: "ghost",
4703
+ "aria-label": "Close",
4704
+ onClick: () => setFaqOpen(false),
4705
+ children: "×"
4706
+ })]
4707
+ }),
4708
+ /* @__PURE__ */ jsxs("div", {
4709
+ className: "bl-faq-library__modal-body",
4710
+ children: [
4711
+ /* @__PURE__ */ jsxs(Field, { children: [/* @__PURE__ */ jsx(Label, { children: "Question" }), /* @__PURE__ */ jsx(Input, {
4712
+ value: draftQuestion,
4713
+ onChange: (event) => setDraftQuestion(event.target.value),
4714
+ placeholder: "e.g. How long does recovery usually take?"
4715
+ })] }),
4716
+ /* @__PURE__ */ jsxs(Field, { children: [/* @__PURE__ */ jsx(Label, { children: "Answer" }), /* @__PURE__ */ jsx(Textarea, {
4717
+ value: draftAnswer,
4718
+ onChange: (event) => setDraftAnswer(event.target.value),
4719
+ placeholder: "Write the reusable answer…"
4720
+ })] }),
4721
+ organizeBy.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
4722
+ className: "bl-faq-library__section",
4723
+ children: "Organization"
4724
+ }), /* @__PURE__ */ jsx("div", {
4725
+ className: "bl-faq-library__grid",
4726
+ children: organizeBy.map((entry) => /* @__PURE__ */ jsxs(Field, {
4727
+ as: "div",
4728
+ children: [
4729
+ /* @__PURE__ */ jsx(Label, { children: entry.label }),
4730
+ /* @__PURE__ */ jsx("div", {
4731
+ className: "bl-faq-library__choicebox",
4732
+ children: (terms[entry.name] ?? []).map((term) => {
4733
+ return /* @__PURE__ */ jsxs("label", {
4734
+ className: "bl-faq-library__choice",
4735
+ children: [/* @__PURE__ */ jsx(Checkbox, {
4736
+ checked: (draftFacets[entry.name] ?? []).some((id) => String(id) === String(term.id)),
4737
+ onCheckedChange: (value) => toggleFacet(entry.name, term.id, value === true)
4738
+ }), /* @__PURE__ */ jsx("span", { children: term.name })]
4739
+ }, String(term.id));
4740
+ })
4741
+ }),
4742
+ entry.manage ? inlineTopic?.field === entry.name ? /* @__PURE__ */ jsxs("form", {
4743
+ className: "bl-faq-library__inline-add",
4744
+ onSubmit: (event) => {
4745
+ event.preventDefault();
4746
+ addTerm(entry, inlineTopic.name);
4747
+ },
4748
+ children: [/* @__PURE__ */ jsx(Input, {
4749
+ autoFocus: true,
4750
+ value: inlineTopic.name,
4751
+ onChange: (event) => setInlineTopic({
4752
+ field: entry.name,
4753
+ name: event.target.value
4754
+ }),
4755
+ placeholder: "New topic name"
4756
+ }), /* @__PURE__ */ jsx(Button$1, {
4757
+ type: "submit",
4758
+ variant: "outline",
4759
+ disabled: busy,
4760
+ children: "Add"
4761
+ })]
4762
+ }) : /* @__PURE__ */ jsx("button", {
4763
+ type: "button",
4764
+ className: "bl-faq-library__addtag",
4765
+ onClick: () => setInlineTopic({
4766
+ field: entry.name,
4767
+ name: ""
4768
+ }),
4769
+ children: "+ Create new topic"
4770
+ }) : null,
4771
+ /* @__PURE__ */ jsx("small", {
4772
+ className: "bl-faq-library__hint",
4773
+ children: entry.manage ? "Use topics to group related FAQs across anatomy areas." : "Select every body area this FAQ applies to."
4774
+ })
4775
+ ]
4776
+ }, entry.name))
4777
+ })] }) : null,
4778
+ /* @__PURE__ */ jsx("div", {
4779
+ className: "bl-faq-library__notice",
4780
+ children: "Pages should select FAQs from this library. Editing an FAQ here updates every page that references it."
4781
+ })
4782
+ ]
4783
+ }),
4784
+ /* @__PURE__ */ jsxs("div", {
4785
+ className: "bl-faq-library__modal-foot",
4786
+ children: [/* @__PURE__ */ jsxs("label", {
4787
+ className: "bl-faq-library__published",
4788
+ children: [/* @__PURE__ */ jsx(Switch, {
4789
+ checked: published,
4790
+ onCheckedChange: setPublished
4791
+ }), "Published"]
4792
+ }), /* @__PURE__ */ jsxs("div", {
4793
+ className: "bl-faq-library__foot-actions",
4794
+ children: [/* @__PURE__ */ jsx(Button$1, {
4795
+ variant: "outline",
4796
+ onClick: () => setFaqOpen(false),
4797
+ children: "Cancel"
4798
+ }), /* @__PURE__ */ jsx(Button$1, {
4799
+ disabled: busy,
4800
+ onClick: () => void saveFaq(),
4801
+ children: "Save FAQ"
4802
+ })]
4803
+ })]
4804
+ })
4805
+ ]
4806
+ })
4807
+ }) : null,
4808
+ /* @__PURE__ */ jsx(Dialog, {
4809
+ open: Boolean(deleteFaq),
4810
+ title: "Delete this FAQ?",
4811
+ cancelLabel: "Cancel",
4812
+ confirmLabel: "Delete FAQ",
4813
+ confirmVariant: "danger",
4814
+ confirmDisabled: busy,
4815
+ onCancel: () => setDeleteFaq(null),
4816
+ onConfirm: () => void confirmDeleteFaq(),
4817
+ children: "Pages using it would need another FAQ selected."
4818
+ }),
4819
+ deleteTerm ? /* @__PURE__ */ jsx("div", {
4820
+ className: "bl-nav-kit__modal",
4821
+ role: "dialog",
4822
+ "aria-modal": "true",
4823
+ "aria-labelledby": "bl-faq-term-title",
4824
+ onClick: () => setDeleteTerm(null),
4825
+ children: /* @__PURE__ */ jsxs("div", {
4826
+ className: "bl-faq-library__modal-card bl-faq-library__danger",
4827
+ onClick: (event) => event.stopPropagation(),
4828
+ children: [/* @__PURE__ */ jsxs("div", {
4829
+ className: "bl-faq-library__danger-body",
4830
+ children: [
4831
+ /* @__PURE__ */ jsxs("div", {
4832
+ className: "bl-faq-library__danger-heading",
4833
+ children: [/* @__PURE__ */ jsx("div", {
4834
+ className: "bl-faq-library__danger-icon",
4835
+ children: "!"
4836
+ }), /* @__PURE__ */ jsxs("h2", {
4837
+ id: "bl-faq-term-title",
4838
+ children: [
4839
+ "Delete “",
4840
+ deleteTerm.term.name,
4841
+ "” topic?"
4842
+ ]
4843
+ })]
4844
+ }),
4845
+ deleteTerm.count > 0 ? /* @__PURE__ */ jsxs("p", { children: [
4846
+ "This topic is currently assigned to",
4847
+ " ",
4848
+ /* @__PURE__ */ jsx("button", {
4849
+ type: "button",
4850
+ className: "bl-faq-library__link",
4851
+ onClick: () => {
4852
+ setFilters((current) => ({
4853
+ ...current,
4854
+ [deleteTerm.entry.name]: String(deleteTerm.term.id)
4855
+ }));
4856
+ setManageOpen(false);
4857
+ setDeleteTerm(null);
4858
+ },
4859
+ children: /* @__PURE__ */ jsxs("strong", { children: [
4860
+ deleteTerm.count,
4861
+ " FAQ",
4862
+ deleteTerm.count === 1 ? "" : "s"
4863
+ ] })
4864
+ }),
4865
+ ". Deleting it removes the topic assignment only."
4866
+ ] }) : /* @__PURE__ */ jsx("p", { children: "This topic is not assigned to any FAQs." }),
4867
+ /* @__PURE__ */ jsxs("div", {
4868
+ className: "bl-faq-library__impact",
4869
+ children: [
4870
+ /* @__PURE__ */ jsx("strong", { children: deleteTerm.count > 0 ? `The FAQ${deleteTerm.count === 1 ? " itself" : "s themselves"} will not be deleted.` : "No FAQs will be affected." }),
4871
+ " ",
4872
+ "This action cannot be undone."
4873
+ ]
4874
+ })
4875
+ ]
4876
+ }), /* @__PURE__ */ jsxs("div", {
4877
+ className: "bl-faq-library__modal-foot",
4878
+ children: [/* @__PURE__ */ jsx("span", {}), /* @__PURE__ */ jsxs("div", {
4879
+ className: "bl-faq-library__foot-actions",
4880
+ children: [/* @__PURE__ */ jsx(Button$1, {
4881
+ variant: "outline",
4882
+ onClick: () => setDeleteTerm(null),
4883
+ children: "Cancel"
4884
+ }), /* @__PURE__ */ jsx(Button$1, {
4885
+ variant: "danger",
4886
+ disabled: busy,
4887
+ onClick: () => void confirmDeleteTerm(),
4888
+ children: "Delete topic"
4889
+ })]
4890
+ })]
4891
+ })]
4892
+ })
4893
+ }) : null
4894
+ ] });
4895
+ }
4896
+ //#endregion
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 };
4066
5945
 
4067
5946
  //# sourceMappingURL=admin.mjs.map