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