@bison-lab/payload-core 4.6.0 → 4.7.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 +32 -4
- package/dist/admin.d.mts +3 -1
- package/dist/admin.d.mts.map +1 -1
- package/dist/admin.mjs +97 -20
- package/dist/admin.mjs.map +1 -1
- package/dist/index.d.mts +105 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +230 -54
- package/dist/index.mjs.map +1 -1
- package/dist/navigation.mjs +1 -1
- package/dist/{published-BltDUYZv.mjs → published-BvTPQqAF.mjs} +9 -9
- package/dist/published-BvTPQqAF.mjs.map +1 -0
- package/package.json +3 -3
- package/dist/published-BltDUYZv.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -336,10 +336,38 @@ switches back, so an editor picks which one the site uses. A site extra is appen
|
|
|
336
336
|
only in the category it names. A site may not add `megaMenu` or `navLink`
|
|
337
337
|
as cards.
|
|
338
338
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
339
|
+
Turning a card off distinguishes published from draft:
|
|
340
|
+
|
|
341
|
+
- **The last hero or the last navbar** is refused.
|
|
342
|
+
- **Published** — a live page (or any live document) holds the slug, or
|
|
343
|
+
it is the published Header's navbar: refused. The message names the
|
|
344
|
+
published documents and mentions any drafts; nothing is deleted.
|
|
345
|
+
- **Drafts only** — the switch opens a `ConfirmDialog` that names the
|
|
346
|
+
drafts. Confirm turns the switch off; the **Save** that turns the slug
|
|
347
|
+
off deletes its rows from those drafts, each written as a new draft
|
|
348
|
+
version (`payload.update({ draft: true })`) inside the Save's
|
|
349
|
+
transaction. Published versions are never written. Cancel leaves it on.
|
|
350
|
+
- **Unused** — off, no dialog.
|
|
351
|
+
|
|
352
|
+
The server is the authority: the Save hook re-reads usage, refuses while
|
|
353
|
+
anything published holds the slug, and strips drafts otherwise, whether
|
|
354
|
+
the Save came from the admin or the API. The admin asks
|
|
355
|
+
`GET /api/globals/block-library/usage?slug=…` (same access as `update`)
|
|
356
|
+
before it turns a switch off. `blockUsage` and `stripDrafts` are exported.
|
|
357
|
+
A page whose only section was stripped stays a draft until a section is
|
|
358
|
+
added: publish still hits `LAYOUT_REQUIRED_MESSAGE`. A block embedded in
|
|
359
|
+
rich text (a Lexical block node) is stripped too. A refusal is a public
|
|
360
|
+
400, so the admin shows its message. A read that fails while checking
|
|
361
|
+
usage fails the check (the switch stays on) rather than answering from
|
|
362
|
+
part of the site. An editor who has a stripped draft open still holds the
|
|
363
|
+
row in their form; their next autosave writes it back, so turn a block off
|
|
364
|
+
when nobody is editing the drafts it names.
|
|
365
|
+
|
|
366
|
+
The Header's navbar is `header.navbar` when the Header document carries
|
|
367
|
+
one, otherwise the catalogue's first navbar (`floatingNav`). The package
|
|
368
|
+
Header has no such field yet; the picker arrives with a second navbar
|
|
369
|
+
package (BIS-132), so until then the published Header always holds
|
|
370
|
+
`floatingNav`.
|
|
343
371
|
|
|
344
372
|
```ts
|
|
345
373
|
import { createBlockLibrary } from "@bison-lab/payload-core";
|
package/dist/admin.d.mts
CHANGED
|
@@ -195,7 +195,9 @@ declare const FeaturesMatrixField: ArrayFieldClientComponent;
|
|
|
195
195
|
/**
|
|
196
196
|
* Category rail and a gallery of live islands. Each island is the sample
|
|
197
197
|
* at `previewPath(slug)` under the published theme (the route is SPI-53).
|
|
198
|
-
* `megaMenu` and `navLink` are not cards.
|
|
198
|
+
* `megaMenu` and `navLink` are not cards. Turning a card off is refused
|
|
199
|
+
* while a published document holds it, and asks before a Save that strips
|
|
200
|
+
* it from drafts.
|
|
199
201
|
*/
|
|
200
202
|
declare const BlockLibraryField: ArrayFieldClientComponent;
|
|
201
203
|
//#endregion
|
package/dist/admin.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admin.d.mts","names":[],"sources":["../src/admin/color-field.tsx","../src/admin/color-scale-field.tsx","../src/admin/library-field.tsx","../src/admin/font-field.tsx","../src/admin/pairing-field.tsx","../src/admin/appearance-field.tsx","../src/admin/grey-scale-field.tsx","../src/admin/contrast-report.tsx","../src/admin/section-heading.tsx","../src/admin/publish-child.tsx","../src/admin/save-button.tsx","../src/admin/preview-mode.tsx","../src/admin/identity-fallback.tsx","../src/admin/look-field.tsx","../src/admin/roles-matrix-field.tsx","../src/admin/roles-row-label.tsx","../src/admin/role-slug-field.tsx","../src/admin/slug-field.tsx","../src/admin/page-title-cell.tsx","../src/admin/page-slug-cell.tsx","../src/admin/required-page-cell.tsx","../src/admin/role-name-field.tsx","../src/admin/roles-field.tsx","../src/admin/roles-grants-field.tsx","../src/admin/features-matrix-field.tsx","../src/admin/block-library-field.tsx","../src/admin/document-title-actions.tsx","../src/admin/document-create-new.tsx","../src/admin-nav/types.ts","../src/admin/admin-nav.tsx","../src/admin/admin-nav-row-label.tsx","../src/admin/admin-nav-item-row-label.tsx","../src/admin/admin-nav-entity-field.tsx","../src/questions/types.ts","../src/admin/questions-list.tsx","../src/admin/media-alt-autofill.tsx","../src/admin/media-list-view.tsx"],"mappings":";;;;;;;;;;;cAWa,UAAA,EAAY,wBAAA;;;;;;;;cCuBZ,eAAA,EAAiB,yBAAA;;;;;;;;;cCMjB,YAAA,EAAc,yBAAA;;;;;;;;;cCtBd,SAAA,EAAW,0BAAA;;;;;;;cCNX,YAAA,EAAc,sBAAA;;;;;;;cCCd,eAAA,EAAiB,yBAAA;;;ALF9B;;;;AAAA,cM4Da,cAAA,EAAgB,0BAAA;;;;;;;cCnDhB,cAAA,EAAgB,sBAAA;;;;;;cCbhB,cAAA,EAAgB,sBAAA;;;cC0IhB,YAAA,EAAc,sBAAA;;;;;;;;iBCtIX,qBAAA,CAAA;;AVAhB;;;iBUQgB,eAAA,CAAA,GAAe,kBAAA,CAAA,GAAA,CAAA,OAAA;;iBA0Bf,gBAAA,CAAA,GAAgB,kBAAA,CAAA,GAAA,CAAA,OAAA;;;KCpCpB,gBAAA;AAAA,iBAgDI,mBAAA,CAAoB,IAAA,EAAM,gBAAA;;;;;;;cCjD7B,gBAAA,EAAkB,sBAAA;;;;;;;cCIlB,SAAA,EAAW,wBAAA;;;;;;;;cCqBX,gBAAA,EAAkB,yBAAA;;;;;;iBC1Bf,aAAA,CAAA,GAAa,kBAAA,CAAA,GAAA,CAAA,OAAA;;;;;;cCChB,aAAA,EAAe,wBAAA;;;;;;;;;cC4Bf,SAAA,EAAW,wBAAA;;;;;;;iBC3BR,aAAA,CAAc,KAAA,EAAO,yBAAA,GAAyB,kBAAA,CAAA,GAAA,CAAA,OAAA;;;;iBCJ9C,YAAA,CAAA;EAAe,QAAA;EAAU;AAAA,GAAW,yBAAA,GAAyB,kBAAA,CAAA,GAAA,CAAA,OAAA;;;;cCEhE,iBAAA,EAAmB,wBAAA;AAAA,iBAEhB,gBAAA,CAAA;EAAmB;AAAA,GAAW,yBAAA,GAAyB,kBAAA,CAAA,GAAA,CAAA,OAAA;;;;;;;cCA1D,aAAA,EAAe,wBAAA;;;;;;;;cC8Cf,UAAA,EAAY,0BAAA;;;;;;;;cCpBZ,gBAAA,EAAkB,wBAAA;;;;;;;;;AvBxB/B;;cwB2Ca,mBAAA,EAAqB,yBAAA
|
|
1
|
+
{"version":3,"file":"admin.d.mts","names":[],"sources":["../src/admin/color-field.tsx","../src/admin/color-scale-field.tsx","../src/admin/library-field.tsx","../src/admin/font-field.tsx","../src/admin/pairing-field.tsx","../src/admin/appearance-field.tsx","../src/admin/grey-scale-field.tsx","../src/admin/contrast-report.tsx","../src/admin/section-heading.tsx","../src/admin/publish-child.tsx","../src/admin/save-button.tsx","../src/admin/preview-mode.tsx","../src/admin/identity-fallback.tsx","../src/admin/look-field.tsx","../src/admin/roles-matrix-field.tsx","../src/admin/roles-row-label.tsx","../src/admin/role-slug-field.tsx","../src/admin/slug-field.tsx","../src/admin/page-title-cell.tsx","../src/admin/page-slug-cell.tsx","../src/admin/required-page-cell.tsx","../src/admin/role-name-field.tsx","../src/admin/roles-field.tsx","../src/admin/roles-grants-field.tsx","../src/admin/features-matrix-field.tsx","../src/admin/block-library-field.tsx","../src/admin/document-title-actions.tsx","../src/admin/document-create-new.tsx","../src/admin-nav/types.ts","../src/admin/admin-nav.tsx","../src/admin/admin-nav-row-label.tsx","../src/admin/admin-nav-item-row-label.tsx","../src/admin/admin-nav-entity-field.tsx","../src/questions/types.ts","../src/admin/questions-list.tsx","../src/admin/media-alt-autofill.tsx","../src/admin/media-list-view.tsx"],"mappings":";;;;;;;;;;;cAWa,UAAA,EAAY,wBAAA;;;;;;;;cCuBZ,eAAA,EAAiB,yBAAA;;;;;;;;;cCMjB,YAAA,EAAc,yBAAA;;;;;;;;;cCtBd,SAAA,EAAW,0BAAA;;;;;;;cCNX,YAAA,EAAc,sBAAA;;;;;;;cCCd,eAAA,EAAiB,yBAAA;;;ALF9B;;;;AAAA,cM4Da,cAAA,EAAgB,0BAAA;;;;;;;cCnDhB,cAAA,EAAgB,sBAAA;;;;;;cCbhB,cAAA,EAAgB,sBAAA;;;cC0IhB,YAAA,EAAc,sBAAA;;;;;;;;iBCtIX,qBAAA,CAAA;;AVAhB;;;iBUQgB,eAAA,CAAA,GAAe,kBAAA,CAAA,GAAA,CAAA,OAAA;;iBA0Bf,gBAAA,CAAA,GAAgB,kBAAA,CAAA,GAAA,CAAA,OAAA;;;KCpCpB,gBAAA;AAAA,iBAgDI,mBAAA,CAAoB,IAAA,EAAM,gBAAA;;;;;;;cCjD7B,gBAAA,EAAkB,sBAAA;;;;;;;cCIlB,SAAA,EAAW,wBAAA;;;;;;;;cCqBX,gBAAA,EAAkB,yBAAA;;;;;;iBC1Bf,aAAA,CAAA,GAAa,kBAAA,CAAA,GAAA,CAAA,OAAA;;;;;;cCChB,aAAA,EAAe,wBAAA;;;;;;;;;cC4Bf,SAAA,EAAW,wBAAA;;;;;;;iBC3BR,aAAA,CAAc,KAAA,EAAO,yBAAA,GAAyB,kBAAA,CAAA,GAAA,CAAA,OAAA;;;;iBCJ9C,YAAA,CAAA;EAAe,QAAA;EAAU;AAAA,GAAW,yBAAA,GAAyB,kBAAA,CAAA,GAAA,CAAA,OAAA;;;;cCEhE,iBAAA,EAAmB,wBAAA;AAAA,iBAEhB,gBAAA,CAAA;EAAmB;AAAA,GAAW,yBAAA,GAAyB,kBAAA,CAAA,GAAA,CAAA,OAAA;;;;;;;cCA1D,aAAA,EAAe,wBAAA;;;;;;;;cC8Cf,UAAA,EAAY,0BAAA;;;;;;;;cCpBZ,gBAAA,EAAkB,wBAAA;;;;;;;;;AvBxB/B;;cwB2Ca,mBAAA,EAAqB,yBAAA;;;;;;;;;AxB3ClC;cyBuJa,iBAAA,EAAmB,yBAAA;;;iBC5HhB,oBAAA,CAAA;EAAuB;AAAA;EAAc,QAAA,GAAW,SAAA;AAAA,IAAW,kBAAA,CAAA,GAAA,CAAA,OAAA;;;iBCxB3D,iBAAA,CAAA;EAAoB;AAAA;EAAU,IAAA;AAAA,IAAc,kBAAA,CAAA,GAAA,CAAA,OAAA;;;UCmB3C,uBAAA;EACf,WAAA;EACA,OAAA;AAAA;;;UC5Be,aAAA;EACf,eAAA,GAAkB,uBAAA;AAAA;;;A7BGpB;;;iB6B6CgB,QAAA,CAAA;EAAW;AAAA,GAAmB,aAAA,GAAa,kBAAA,CAAA,GAAA,CAAA,OAAA;;;;;;iBCnD3C,gBAAA,CAAA,GAAgB,kBAAA,CAAA,GAAA,CAAA,OAAA;;;;;;;iBCGhB,oBAAA,CAAA,GAAoB,kBAAA,CAAA,GAAA,CAAA,OAAA;;;;;;;;cCEvB,mBAAA,EAAqB,wBAAA;;;;;;;;AhCClC;UiCFiB,cAAA;;EAEf,MAAA;EjCyED;EiCvEC,IAAA;;EAEA,KAAA;EhCmBW;EgCjBX,MAAA;AAAA;AAAA,UAGe,eAAA;EhCiEhB;EgC/DC,IAAA;;EAEA,KAAA;E/BgBW;E+BdX,UAAA;;;;;EAKA,MAAA;;EAEA,IAAA,GAAO,cAAA;AAAA;;;iBCyKO,aAAA,CACd,KAAA,EAAO,mBAAA;EAAwB,UAAA,YAAsB,eAAA;AAAA,IAAmB,kBAAA,CAAA,GAAA,CAAA,OAAA;;;;;;;iBChM1D,gBAAA,CAAA;EAAmB;AAAA;EAAU,IAAA;AAAA;;;iBC2G7B,aAAA,CAAc,KAAA,EAAO,mBAAA,GAAmB,kBAAA,CAAA,GAAA,CAAA,OAAA"}
|
package/dist/admin.mjs
CHANGED
|
@@ -3803,6 +3803,7 @@ const FeaturesMatrixField = (props) => {
|
|
|
3803
3803
|
};
|
|
3804
3804
|
//#endregion
|
|
3805
3805
|
//#region src/block-library/types.ts
|
|
3806
|
+
const BLOCK_LIBRARY_SLUG = "block-library";
|
|
3806
3807
|
const BLOCK_LIBRARY_CATEGORIES = [
|
|
3807
3808
|
{
|
|
3808
3809
|
id: "hero",
|
|
@@ -3847,25 +3848,91 @@ const BLOCK_LIBRARY_CATEGORIES = [
|
|
|
3847
3848
|
];
|
|
3848
3849
|
//#endregion
|
|
3849
3850
|
//#region src/admin/block-library-field.tsx
|
|
3850
|
-
const LIST_CSS$1 = `.bl-block-library{display:grid;grid-template-columns:12rem 1fr;gap:1.5rem;align-items:start}.bl-block-library__rail{display:flex;flex-direction:column;gap:.25rem}.bl-block-library__rail button{text-align:left;background:transparent;border:0;padding:.4rem .6rem;border-radius:8px;cursor:pointer}.bl-block-library__rail button[aria-current=true]{background:var(--theme-elevation-100,#f1f5f9);font-weight:650}.bl-block-library__card{display:flex;flex-direction:column;gap:.5rem;margin-block-end:1.25rem}.bl-block-library__card header{display:flex;justify-content:space-between;align-items:center;gap:1rem}.bl-block-library iframe{width:100%;height:720px;border:1px solid var(--theme-elevation-150,#e2e8f0);border-radius:12px;background:var(--theme-elevation-0,#fff)}`;
|
|
3851
|
-
function
|
|
3851
|
+
const LIST_CSS$1 = `.bl-block-library{display:grid;grid-template-columns:12rem 1fr;gap:1.5rem;align-items:start}.bl-block-library__rail{display:flex;flex-direction:column;gap:.25rem}.bl-block-library__rail button{text-align:left;background:transparent;border:0;padding:.4rem .6rem;border-radius:8px;cursor:pointer}.bl-block-library__rail button[aria-current=true]{background:var(--theme-elevation-100,#f1f5f9);font-weight:650}.bl-block-library__card{display:flex;flex-direction:column;gap:.5rem;margin-block-end:1.25rem}.bl-block-library__card header{display:flex;justify-content:space-between;align-items:center;gap:1rem}.bl-block-library__refusal{margin:0;color:var(--theme-error-500,#b91c1c)}.bl-block-library__drafts{margin:.5rem 0 0;padding-inline-start:1.25rem}.bl-block-library iframe{width:100%;height:720px;border:1px solid var(--theme-elevation-150,#e2e8f0);border-radius:12px;background:var(--theme-elevation-0,#fff)}`;
|
|
3852
|
+
function holderLabel(holder) {
|
|
3853
|
+
const title = holder.title?.trim() || "Untitled";
|
|
3854
|
+
const slug = holder.slug?.trim();
|
|
3855
|
+
return slug ? `${title} (${slug})` : title;
|
|
3856
|
+
}
|
|
3857
|
+
function refusalOf(label, usage) {
|
|
3858
|
+
return `${label} cannot be turned off. It is published on: ${usage.published.map(holderLabel).join(", ")}. Remove it from those first.${usage.drafts.length > 0 ? ` Drafts also use it: ${usage.drafts.map(holderLabel).join(", ")}.` : ""}`;
|
|
3859
|
+
}
|
|
3860
|
+
function isUsage(value) {
|
|
3861
|
+
return Boolean(value) && typeof value === "object" && Array.isArray(value.published) && Array.isArray(value.drafts);
|
|
3862
|
+
}
|
|
3863
|
+
function LibraryCard({ path, index, row, setRow, src, toggle, usageURL }) {
|
|
3852
3864
|
const { setValue: setEnabled } = useField({ path: `${path}.${index}.enabled` });
|
|
3865
|
+
const [refusal, setRefusal] = useState(null);
|
|
3866
|
+
const [drafts, setDrafts] = useState(null);
|
|
3867
|
+
const [checking, setChecking] = useState(false);
|
|
3868
|
+
const apply = (enabled) => {
|
|
3869
|
+
setEnabled(enabled);
|
|
3870
|
+
setRow(index, enabled);
|
|
3871
|
+
};
|
|
3872
|
+
/**
|
|
3873
|
+
* Off asks the server where the slug is used. Published refuses; drafts
|
|
3874
|
+
* only ask first, because the Save that turns it off deletes those rows.
|
|
3875
|
+
*/
|
|
3876
|
+
const turnOff = async () => {
|
|
3877
|
+
setRefusal(null);
|
|
3878
|
+
setChecking(true);
|
|
3879
|
+
try {
|
|
3880
|
+
const response = await fetch(`${usageURL}?slug=${encodeURIComponent(row.slug)}`, { credentials: "include" });
|
|
3881
|
+
const usage = response.ok ? await response.json() : null;
|
|
3882
|
+
if (!isUsage(usage)) throw new Error("usage");
|
|
3883
|
+
if (usage.published.length > 0) setRefusal(refusalOf(row.label, usage));
|
|
3884
|
+
else if (usage.drafts.length > 0) setDrafts(usage.drafts);
|
|
3885
|
+
else apply(false);
|
|
3886
|
+
} catch {
|
|
3887
|
+
setRefusal(`Could not check where ${row.label} is used. It stays on; try again.`);
|
|
3888
|
+
} finally {
|
|
3889
|
+
setChecking(false);
|
|
3890
|
+
}
|
|
3891
|
+
};
|
|
3853
3892
|
return /* @__PURE__ */ jsxs("article", {
|
|
3854
3893
|
className: "bl-block-library__card",
|
|
3855
|
-
children: [
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3894
|
+
children: [
|
|
3895
|
+
/* @__PURE__ */ jsxs("header", { children: [/* @__PURE__ */ jsx("span", { children: row.label }), toggle ? /* @__PURE__ */ jsx(Switch, {
|
|
3896
|
+
checked: row.enabled !== false,
|
|
3897
|
+
disabled: checking,
|
|
3898
|
+
"aria-label": `Enable ${row.label}`,
|
|
3899
|
+
onCheckedChange: (enabled) => {
|
|
3900
|
+
if (enabled) {
|
|
3901
|
+
setRefusal(null);
|
|
3902
|
+
apply(true);
|
|
3903
|
+
} else turnOff();
|
|
3904
|
+
}
|
|
3905
|
+
}) : null] }),
|
|
3906
|
+
refusal ? /* @__PURE__ */ jsx("p", {
|
|
3907
|
+
className: "bl-block-library__refusal",
|
|
3908
|
+
role: "alert",
|
|
3909
|
+
children: refusal
|
|
3910
|
+
}) : null,
|
|
3911
|
+
/* @__PURE__ */ jsx("iframe", {
|
|
3912
|
+
title: row.label,
|
|
3913
|
+
src
|
|
3914
|
+
}),
|
|
3915
|
+
/* @__PURE__ */ jsxs(ConfirmDialog, {
|
|
3916
|
+
open: drafts !== null,
|
|
3917
|
+
title: `Remove ${row.label} from ${drafts?.length === 1 ? "1 draft" : `${drafts?.length ?? 0} drafts`}?`,
|
|
3918
|
+
cancelLabel: "Cancel",
|
|
3919
|
+
confirmLabel: "Remove from drafts",
|
|
3920
|
+
confirmVariant: "danger",
|
|
3921
|
+
onCancel: () => setDrafts(null),
|
|
3922
|
+
onConfirm: () => {
|
|
3923
|
+
setDrafts(null);
|
|
3924
|
+
apply(false);
|
|
3925
|
+
},
|
|
3926
|
+
children: [/* @__PURE__ */ jsxs("p", { children: [
|
|
3927
|
+
"No published page uses ",
|
|
3928
|
+
row.label,
|
|
3929
|
+
". Saving deletes its rows from these drafts and turns it off. Published pages are not changed."
|
|
3930
|
+
] }), /* @__PURE__ */ jsx("ul", {
|
|
3931
|
+
className: "bl-block-library__drafts",
|
|
3932
|
+
children: (drafts ?? []).map((holder) => /* @__PURE__ */ jsx("li", { children: holderLabel(holder) }, holderLabel(holder)))
|
|
3933
|
+
})]
|
|
3934
|
+
})
|
|
3935
|
+
]
|
|
3869
3936
|
});
|
|
3870
3937
|
}
|
|
3871
3938
|
function asRows(value) {
|
|
@@ -3885,13 +3952,23 @@ function seededRows(field) {
|
|
|
3885
3952
|
/**
|
|
3886
3953
|
* Category rail and a gallery of live islands. Each island is the sample
|
|
3887
3954
|
* at `previewPath(slug)` under the published theme (the route is SPI-53).
|
|
3888
|
-
* `megaMenu` and `navLink` are not cards.
|
|
3955
|
+
* `megaMenu` and `navLink` are not cards. Turning a card off is refused
|
|
3956
|
+
* while a published document holds it, and asks before a Save that strips
|
|
3957
|
+
* it from drafts.
|
|
3889
3958
|
*/
|
|
3890
3959
|
const BlockLibraryField = (props) => {
|
|
3891
3960
|
const { setValue, value } = useField({ path: props.path });
|
|
3961
|
+
const { config } = useConfig();
|
|
3962
|
+
const usageURL = `${config.serverURL ?? ""}${config.routes?.api ?? "/api"}/globals/${BLOCK_LIBRARY_SLUG}/usage`;
|
|
3892
3963
|
const loaded = asRows(value);
|
|
3893
3964
|
const seeded = seededRows(props.field);
|
|
3894
3965
|
const rows = loaded.length > 0 ? loaded : seeded;
|
|
3966
|
+
const rowsRef = useRef(rows);
|
|
3967
|
+
rowsRef.current = rows;
|
|
3968
|
+
const setRow = useCallback((index, enabled) => setValue(rowsRef.current.map((entry, i) => i === index ? {
|
|
3969
|
+
...entry,
|
|
3970
|
+
enabled
|
|
3971
|
+
} : entry)), [setValue]);
|
|
3895
3972
|
useEffect(() => {
|
|
3896
3973
|
if (loaded.length === 0 && seeded.length > 0) setValue(seeded);
|
|
3897
3974
|
}, [
|
|
@@ -3929,10 +4006,10 @@ const BlockLibraryField = (props) => {
|
|
|
3929
4006
|
path: props.path,
|
|
3930
4007
|
index,
|
|
3931
4008
|
row,
|
|
3932
|
-
|
|
3933
|
-
setRows: (next) => setValue(next),
|
|
4009
|
+
setRow,
|
|
3934
4010
|
src: previews[row.slug] ?? "",
|
|
3935
|
-
toggle: row.kind !== "navbar" || navbarCount > 1
|
|
4011
|
+
toggle: row.kind !== "navbar" || navbarCount > 1,
|
|
4012
|
+
usageURL
|
|
3936
4013
|
}, row.slug)) })
|
|
3937
4014
|
]
|
|
3938
4015
|
}) }) });
|