@bison-lab/payload-core 4.11.0 → 4.12.1
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 +16 -2
- package/dist/admin.d.mts +27 -7
- package/dist/admin.d.mts.map +1 -1
- package/dist/admin.mjs +135 -36
- package/dist/admin.mjs.map +1 -1
- package/dist/block-library.d.mts +1 -1
- package/dist/{catalogue-qKbnBeEY.d.mts → catalogue-9MO2jy69.d.mts} +1 -1
- package/dist/{catalogue-qKbnBeEY.d.mts.map → catalogue-9MO2jy69.d.mts.map} +1 -1
- package/dist/facet-field-DHpNdS_u.d.mts +28 -0
- package/dist/facet-field-DHpNdS_u.d.mts.map +1 -0
- package/dist/facet-field-Di1kNyzH.mjs +22 -0
- package/dist/facet-field-Di1kNyzH.mjs.map +1 -0
- package/dist/index.d.mts +12 -12
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3 -8
- package/dist/index.mjs.map +1 -1
- package/dist/metadata.d.mts +1 -1
- package/dist/navigation.d.mts +1 -1
- package/dist/{preview-BafqwipZ.d.mts → preview-D-Psltpf.d.mts} +1 -1
- package/dist/{preview-BafqwipZ.d.mts.map → preview-D-Psltpf.d.mts.map} +1 -1
- package/dist/{published-1JRfuEO4.d.mts → published-DhARD4W8.d.mts} +1 -1
- package/dist/{published-1JRfuEO4.d.mts.map → published-DhARD4W8.d.mts.map} +1 -1
- package/dist/taxonomy.d.mts +2 -0
- package/dist/taxonomy.mjs +2 -0
- package/dist/theme.d.mts +1 -1
- package/dist/{title-DjTfxz6F.d.mts → title-7VASfaFO.d.mts} +1 -1
- package/dist/{title-DjTfxz6F.d.mts.map → title-7VASfaFO.d.mts.map} +1 -1
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -18,15 +18,16 @@ and `react` are needed for admin fields; `@bison-lab/ui` and
|
|
|
18
18
|
Pin the plugin to the same version as `payload`; Payload releases them in
|
|
19
19
|
lockstep.
|
|
20
20
|
|
|
21
|
-
##
|
|
21
|
+
## Eight entry points, and why
|
|
22
22
|
|
|
23
23
|
| Import | Contents | Runs where |
|
|
24
24
|
| ---------------------------------- | ------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------- |
|
|
25
|
-
| `@bison-lab/payload-core` | `seoPlugin`, `createTheme`, `createBrandAssets`, `createRoles`, `createFeatures`, `createBlockLibrary`, `createPages`, `createUsers`, `createMedia`, `createRedirects`, `createQuestions`, `createTaxonomy`, `createAdminNav`, `adminNav`, `createNavigation`, `adminOnlyApiTab`, `documentTitleActions`, `listAlign`, `seedTheme`, `seedRoles`, `seedFeatures`, predicates, `lookField`, `colorTokenField`, import-map strings, title and text helpers, types | Node. What `payload.config.ts` imports; it loads the plugin. |
|
|
25
|
+
| `@bison-lab/payload-core` | `seoPlugin`, `createTheme`, `createBrandAssets`, `createRoles`, `createFeatures`, `createBlockLibrary`, `createPages`, `createUsers`, `createMedia`, `createRedirects`, `createQuestions`, `createTaxonomy`, `facetField`, `createAdminNav`, `adminNav`, `createNavigation`, `adminOnlyApiTab`, `documentTitleActions`, `listAlign`, `seedTheme`, `seedRoles`, `seedFeatures`, predicates, `lookField`, `colorTokenField`, import-map strings, title and text helpers, types | Node. What `payload.config.ts` imports; it loads the plugin. |
|
|
26
26
|
| `@bison-lab/payload-core/metadata` | `pageMetadata`, the title helpers, the same types | Server. What a page route imports; it does not load the plugin. |
|
|
27
27
|
| `@bison-lab/payload-core/theme` | `getPublishedTheme`, `getPublishedIdentity`, `themeConfigFromDoc`, `themeHead`, `themeHeadFromDoc` | Server. What a root layout imports; it does not load the plugin or React. |
|
|
28
28
|
| `@bison-lab/payload-core/navigation` | `getNavigation`, the Header and Footer slugs | Server. What a site header imports; it does not load the plugin or React. |
|
|
29
29
|
| `@bison-lab/payload-core/block-library` | `getSectionControls`, `sectionControlsFromLibrary`, `SectionControls`, the catalogue readers | Server. What a page route and the Block Settings fold import; it does not load the plugin or React. |
|
|
30
|
+
| `@bison-lab/payload-core/taxonomy` | `facetField`, `FacetEntry` | Anywhere. What a block config imports to tag content from a taxonomy; no plugin, no React, so a browser bundle can take it (`@bison-lab/payload-blocks` main entry reaches the docs island and Storybook). |
|
|
30
31
|
| `@bison-lab/payload-core/admin` | Theme fields, the Roles and Features matrices, the Block library field, Admin nav, the Users Roles checklist, and the FAQ Library list | Admin. Referenced by import-map string; `generate:importmap` writes it. |
|
|
31
32
|
| `@bison-lab/payload-core/react` | `ThemePreview` (legacy; Theme has no preview pane) | Client. Kept so an older site import does not break. |
|
|
32
33
|
|
|
@@ -350,6 +351,11 @@ Turning a card off distinguishes published from draft:
|
|
|
350
351
|
transaction. Published versions are never written. Cancel leaves it on.
|
|
351
352
|
- **Unused** — off, no dialog.
|
|
352
353
|
|
|
354
|
+
Save leaves the form clean: the field reads each row from Payload's own
|
|
355
|
+
row fields and writes one column at a time, never the array path and never
|
|
356
|
+
on load, so after a Save the button disables again, leaving the page asks
|
|
357
|
+
nothing, and a switch flipped straight after a Save holds (BIS-135).
|
|
358
|
+
|
|
353
359
|
The server is the authority: the Save hook re-reads usage, refuses while
|
|
354
360
|
anything published holds the slug, and strips drafts otherwise, whether
|
|
355
361
|
the Save came from the admin or the API. The admin asks
|
|
@@ -600,6 +606,14 @@ createQuestions({
|
|
|
600
606
|
});
|
|
601
607
|
```
|
|
602
608
|
|
|
609
|
+
Each `organizeBy` entry's field is `facetField(entry)`: a stock
|
|
610
|
+
`relationship`, `hasMany`, onto `collection`, with Payload's default
|
|
611
|
+
`allowCreate`, so "Add new" shows only to a user with create access on the
|
|
612
|
+
terms collection. It is exported from the main entry and from
|
|
613
|
+
`./taxonomy`; tag any other content from the same taxonomy with it
|
|
614
|
+
(`createResourcesBlock({ facets })` in payload-blocks does). Only `name`,
|
|
615
|
+
`label` and `collection` are read.
|
|
616
|
+
|
|
603
617
|
The list view is `@bison-lab/payload-core/admin#QuestionsList`. It wraps
|
|
604
618
|
`Page` from `@bison-lab/admin-ui` so the column is Payload's `--gutter-h`,
|
|
605
619
|
the same inset Media and Pages use — not a mockup max-width. A later kit
|
package/dist/admin.d.mts
CHANGED
|
@@ -198,6 +198,12 @@ declare const FeaturesMatrixField: ArrayFieldClientComponent;
|
|
|
198
198
|
* `megaMenu` and `navLink` are not cards. Turning a card off is refused
|
|
199
199
|
* while a published document holds it, and asks before a Save that strips
|
|
200
200
|
* it from drafts.
|
|
201
|
+
*
|
|
202
|
+
* Form contract (BIS-135): rows are read from Payload's per-row fields and
|
|
203
|
+
* written one column at a time. The field never writes the array path and
|
|
204
|
+
* never marks the form modified on its own; a catalogue entry the stored
|
|
205
|
+
* rows lack is added to local form state without that mark. So a Save
|
|
206
|
+
* leaves the form clean and the server's post-Save state is what shows.
|
|
201
207
|
*/
|
|
202
208
|
declare const BlockLibraryField: ArrayFieldClientComponent;
|
|
203
209
|
//#endregion
|
|
@@ -271,6 +277,21 @@ declare function AdminNavItemRowLabel(): react_jsx_runtime0.JSX.Element;
|
|
|
271
277
|
*/
|
|
272
278
|
declare const AdminNavEntityField: TextFieldClientComponent;
|
|
273
279
|
//#endregion
|
|
280
|
+
//#region src/taxonomy/facet-field.d.ts
|
|
281
|
+
/**
|
|
282
|
+
* One taxonomy axis a document is tagged on: the field it writes and the
|
|
283
|
+
* terms collection it picks from. A FAQ Library `organizeBy` entry is one,
|
|
284
|
+
* and so is a Resources block facet.
|
|
285
|
+
*/
|
|
286
|
+
interface FacetEntry {
|
|
287
|
+
/** Relationship field name. Must be a valid Payload field name. */
|
|
288
|
+
name: string;
|
|
289
|
+
/** Field label in the admin. */
|
|
290
|
+
label: string;
|
|
291
|
+
/** Terms collection slug. */
|
|
292
|
+
collection: string;
|
|
293
|
+
}
|
|
294
|
+
//#endregion
|
|
274
295
|
//#region src/questions/types.d.ts
|
|
275
296
|
/**
|
|
276
297
|
* Theme family for chips on a linked facet. The list fetches this
|
|
@@ -288,13 +309,12 @@ interface OrganizeByLook {
|
|
|
288
309
|
/** Theme family field. Default `family`. */
|
|
289
310
|
family?: string;
|
|
290
311
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
collection: string;
|
|
312
|
+
/**
|
|
313
|
+
* A facet (`name`, `label`, `collection`; the field is `facetField`) plus
|
|
314
|
+
* what only the FAQ Library list reads. `label` is also the list's filter,
|
|
315
|
+
* table heading, and Manage column.
|
|
316
|
+
*/
|
|
317
|
+
interface OrganizeByEntry extends FacetEntry {
|
|
298
318
|
/**
|
|
299
319
|
* When true, Manage organization can add and delete terms. Default
|
|
300
320
|
* false — linked collections stay read-only here.
|
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/list-align-styles.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":";;;;;;;;;;;cAW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;;;;;;;;;AvBxB/B;;cwB2Ca,mBAAA,EAAqB,yBAAA;;;;;;;;;AxB3ClC
|
|
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/list-align-styles.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/taxonomy/facet-field.ts","../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;;;cC0I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BAAA,CAAA,GAAA,CAAA,OAAA;;;iBCOzE,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;;;A9BGpB;;;iB8B6CgB,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;;;;;;;;;AhCGpC;ciCCa,mBAAA,EAAqB,wBAAA;;;;;;;;UCLjB,UAAA;ElCIJ;EkCFX,IAAA;;EAEA,KAAA;ElCyED;EkCvEC,UAAA;AAAA;;;;;;;AlCFF;;UmCAiB,cAAA;EnCAQ;EmCEvB,MAAA;;EAEA,IAAA;;EAEA,KAAA;ElCoED;EkClEC,MAAA;AAAA;;;;;AjCqBF;UiCbiB,eAAA,SAAwB,UAAA;;;;;EAKvC,MAAA;;EAEA,IAAA,GAAO,cAAA;AAAA;;;iBCwKO,aAAA,CACd,KAAA,EAAO,mBAAA;EAAwB,UAAA,YAAsB,eAAA;AAAA,IAAmB,kBAAA,CAAA,GAAA,CAAA,OAAA;;;;;;;iBChM1D,gBAAA,CAAA;EAAmB;AAAA;EAAU,IAAA;AAAA;;;iBCkH7B,aAAA,CAAc,KAAA,EAAO,mBAAA,GAAmB,kBAAA,CAAA,GAAA,CAAA,OAAA"}
|
package/dist/admin.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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, useBulkUpload, useConfig, useEntityVisibility, useField, useForm, useFormFields, useListDrawerContext, useListQuery, useModal, useNav, useRowLabel, useStepNav } from "@payloadcms/ui";
|
|
3
|
+
import { ArrayField, Button, CheckboxInput, DefaultCell, FieldDescription, FieldError, FieldLabel, Link, Logout, NavGroup, NavToggler, SelectField, fieldBaseClass, useAllFormFields, useAuth, useBulkUpload, useConfig, useEntityVisibility, useField, useForm, useFormFields, useListDrawerContext, 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, regenerateColorScale, setColorScaleInclude, updateColorScale } 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";
|
|
@@ -3928,7 +3928,7 @@ function isUsage(value) {
|
|
|
3928
3928
|
* publish without its hero). A disabled block keeps its ticks; they matter
|
|
3929
3929
|
* again when it is re-enabled.
|
|
3930
3930
|
*/
|
|
3931
|
-
function SectionControlTicks({ row,
|
|
3931
|
+
function SectionControlTicks({ row, write }) {
|
|
3932
3932
|
if (row.kind === "navbar") return null;
|
|
3933
3933
|
const controls = sectionControlsOf(row.sectionControls, defaultSectionControls(row.kind));
|
|
3934
3934
|
const locked = (key) => key === "hidden" && row.kind === "hero";
|
|
@@ -3943,12 +3943,9 @@ function SectionControlTicks({ row, onChange }) {
|
|
|
3943
3943
|
...locked(key) ? { "data-locked": "" } : {},
|
|
3944
3944
|
children: [/* @__PURE__ */ jsx(Checkbox, {
|
|
3945
3945
|
checked: locked(key) ? false : controls[key],
|
|
3946
|
-
disabled: locked(key),
|
|
3946
|
+
disabled: locked(key) || !write,
|
|
3947
3947
|
"aria-label": SECTION_CONTROL_LABELS[key],
|
|
3948
|
-
onCheckedChange: (checked) =>
|
|
3949
|
-
...controls,
|
|
3950
|
-
[key]: checked === true
|
|
3951
|
-
})
|
|
3948
|
+
onCheckedChange: (checked) => write?.(`sectionControls.${key}`, checked === true)
|
|
3952
3949
|
}), /* @__PURE__ */ jsx("span", {
|
|
3953
3950
|
"aria-hidden": true,
|
|
3954
3951
|
children: SECTION_CONTROL_LABELS[key]
|
|
@@ -3956,15 +3953,11 @@ function SectionControlTicks({ row, onChange }) {
|
|
|
3956
3953
|
}, key))]
|
|
3957
3954
|
});
|
|
3958
3955
|
}
|
|
3959
|
-
function LibraryCard({
|
|
3960
|
-
const { setValue: setEnabled } = useField({ path: `${path}.${index}.enabled` });
|
|
3956
|
+
function LibraryCard({ row, write, src, toggle, usageURL }) {
|
|
3961
3957
|
const [refusal, setRefusal] = useState(null);
|
|
3962
3958
|
const [drafts, setDrafts] = useState(null);
|
|
3963
3959
|
const [checking, setChecking] = useState(false);
|
|
3964
|
-
const apply = (enabled) =>
|
|
3965
|
-
setEnabled(enabled);
|
|
3966
|
-
setRow(index, { enabled });
|
|
3967
|
-
};
|
|
3960
|
+
const apply = (enabled) => write?.("enabled", enabled);
|
|
3968
3961
|
/**
|
|
3969
3962
|
* Off asks the server where the slug is used. Published refuses; drafts
|
|
3970
3963
|
* only ask first, because the Save that turns it off deletes those rows.
|
|
@@ -3990,7 +3983,7 @@ function LibraryCard({ path, index, row, setRow, src, toggle, usageURL }) {
|
|
|
3990
3983
|
children: [
|
|
3991
3984
|
/* @__PURE__ */ jsxs("header", { children: [/* @__PURE__ */ jsx("span", { children: row.label }), toggle ? /* @__PURE__ */ jsx(Switch, {
|
|
3992
3985
|
checked: row.enabled !== false,
|
|
3993
|
-
disabled: checking,
|
|
3986
|
+
disabled: checking || !write,
|
|
3994
3987
|
"aria-label": `Enable ${row.label}`,
|
|
3995
3988
|
onCheckedChange: (enabled) => {
|
|
3996
3989
|
if (enabled) {
|
|
@@ -4001,7 +3994,7 @@ function LibraryCard({ path, index, row, setRow, src, toggle, usageURL }) {
|
|
|
4001
3994
|
}) : null] }),
|
|
4002
3995
|
/* @__PURE__ */ jsx(SectionControlTicks, {
|
|
4003
3996
|
row,
|
|
4004
|
-
|
|
3997
|
+
write
|
|
4005
3998
|
}),
|
|
4006
3999
|
refusal ? /* @__PURE__ */ jsx("p", {
|
|
4007
4000
|
className: "bl-block-library__refusal",
|
|
@@ -4035,6 +4028,30 @@ function LibraryCard({ path, index, row, setRow, src, toggle, usageURL }) {
|
|
|
4035
4028
|
]
|
|
4036
4029
|
});
|
|
4037
4030
|
}
|
|
4031
|
+
function rowState(row) {
|
|
4032
|
+
const state = {};
|
|
4033
|
+
const put = (key, value) => {
|
|
4034
|
+
state[key] = {
|
|
4035
|
+
value,
|
|
4036
|
+
initialValue: value,
|
|
4037
|
+
valid: true
|
|
4038
|
+
};
|
|
4039
|
+
};
|
|
4040
|
+
put("id", row.id);
|
|
4041
|
+
put("slug", row.slug);
|
|
4042
|
+
put("label", row.label);
|
|
4043
|
+
put("category", row.category);
|
|
4044
|
+
put("enabled", row.enabled);
|
|
4045
|
+
put("kind", row.kind);
|
|
4046
|
+
for (const key of SECTION_CONTROL_KEYS) put(`sectionControls.${key}`, row.sectionControls[key]);
|
|
4047
|
+
return state;
|
|
4048
|
+
}
|
|
4049
|
+
/** The form index of the row holding `slug`, read off the fields as they are now. */
|
|
4050
|
+
function indexOfSlug(fields, path, slug) {
|
|
4051
|
+
const count = rowCount(fields, path);
|
|
4052
|
+
for (let i = 0; i < count; i += 1) if (fields[`${path}.${i}.slug`]?.value === slug) return i;
|
|
4053
|
+
return -1;
|
|
4054
|
+
}
|
|
4038
4055
|
function asRows(value) {
|
|
4039
4056
|
return Array.isArray(value) ? value : [];
|
|
4040
4057
|
}
|
|
@@ -4049,40 +4066,124 @@ function previewsOf(field) {
|
|
|
4049
4066
|
function seededRows(field) {
|
|
4050
4067
|
return asRows(customOf(field).rows);
|
|
4051
4068
|
}
|
|
4069
|
+
function isKind(value) {
|
|
4070
|
+
return value === "hero" || value === "section" || value === "navbar";
|
|
4071
|
+
}
|
|
4072
|
+
/**
|
|
4073
|
+
* How many rows the form holds. Payload keeps an array field's *count* at
|
|
4074
|
+
* its path (`blocks.value`), never the rows; each row's columns sit at
|
|
4075
|
+
* `blocks.<i>.<name>`. The count is read off `rows` when present, so a row
|
|
4076
|
+
* added client-side counts too.
|
|
4077
|
+
*/
|
|
4078
|
+
function rowCount(fields, path) {
|
|
4079
|
+
const field = fields[path];
|
|
4080
|
+
if (Array.isArray(field?.rows)) return field.rows.length;
|
|
4081
|
+
return typeof field?.value === "number" ? field.value : 0;
|
|
4082
|
+
}
|
|
4083
|
+
/**
|
|
4084
|
+
* The rows as the form holds them, read column by column. A column a
|
|
4085
|
+
* stored row lacks (the ticks, before the migration that added them)
|
|
4086
|
+
* takes the catalogue's seeded value for that slug. Reading never writes:
|
|
4087
|
+
* the stored values stand until an editor changes one.
|
|
4088
|
+
*/
|
|
4089
|
+
function rowsFromFields(fields, path, seeded) {
|
|
4090
|
+
const count = rowCount(fields, path);
|
|
4091
|
+
const rows = [];
|
|
4092
|
+
for (let i = 0; i < count; i += 1) {
|
|
4093
|
+
const read = (name) => fields[`${path}.${i}.${name}`]?.value;
|
|
4094
|
+
const slug = read("slug");
|
|
4095
|
+
if (typeof slug !== "string" || !slug) continue;
|
|
4096
|
+
const seed = seeded.find((entry) => entry.slug === slug);
|
|
4097
|
+
const kind = read("kind");
|
|
4098
|
+
const resolvedKind = isKind(kind) ? kind : seed?.kind ?? "section";
|
|
4099
|
+
const ticks = {};
|
|
4100
|
+
for (const key of SECTION_CONTROL_KEYS) ticks[key] = read(`sectionControls.${key}`);
|
|
4101
|
+
const label = read("label");
|
|
4102
|
+
const category = read("category");
|
|
4103
|
+
const enabled = read("enabled");
|
|
4104
|
+
const id = read("id");
|
|
4105
|
+
rows.push({
|
|
4106
|
+
id: typeof id === "string" ? id : slug,
|
|
4107
|
+
slug,
|
|
4108
|
+
label: typeof label === "string" ? label : seed?.label ?? slug,
|
|
4109
|
+
category: typeof category === "string" ? category : seed?.category ?? "content",
|
|
4110
|
+
enabled: typeof enabled === "boolean" ? enabled : true,
|
|
4111
|
+
kind: resolvedKind,
|
|
4112
|
+
sectionControls: sectionControlsOf(ticks, seed?.sectionControls ?? defaultSectionControls(resolvedKind))
|
|
4113
|
+
});
|
|
4114
|
+
}
|
|
4115
|
+
return rows;
|
|
4116
|
+
}
|
|
4052
4117
|
/**
|
|
4053
4118
|
* Category rail and a gallery of live islands. Each island is the sample
|
|
4054
4119
|
* at `previewPath(slug)` under the published theme (the route is SPI-53).
|
|
4055
4120
|
* `megaMenu` and `navLink` are not cards. Turning a card off is refused
|
|
4056
4121
|
* while a published document holds it, and asks before a Save that strips
|
|
4057
4122
|
* it from drafts.
|
|
4123
|
+
*
|
|
4124
|
+
* Form contract (BIS-135): rows are read from Payload's per-row fields and
|
|
4125
|
+
* written one column at a time. The field never writes the array path and
|
|
4126
|
+
* never marks the form modified on its own; a catalogue entry the stored
|
|
4127
|
+
* rows lack is added to local form state without that mark. So a Save
|
|
4128
|
+
* leaves the form clean and the server's post-Save state is what shows.
|
|
4058
4129
|
*/
|
|
4059
4130
|
const BlockLibraryField = (props) => {
|
|
4060
|
-
const
|
|
4131
|
+
const [fields, dispatch] = useAllFormFields();
|
|
4132
|
+
const { setModified } = useForm();
|
|
4061
4133
|
const { config } = useConfig();
|
|
4062
4134
|
const usageURL = `${config.serverURL ?? ""}${config.routes?.api ?? "/api"}/globals/${BLOCK_LIBRARY_SLUG}/usage`;
|
|
4063
|
-
const loaded = asRows(value);
|
|
4064
4135
|
const seeded = seededRows(props.field);
|
|
4065
|
-
const
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4136
|
+
const loaded = useMemo(() => rowsFromFields(fields, props.path, seeded), [
|
|
4137
|
+
fields,
|
|
4138
|
+
props.path,
|
|
4139
|
+
seeded
|
|
4140
|
+
]);
|
|
4141
|
+
const fieldsRef = useRef(fields);
|
|
4142
|
+
fieldsRef.current = fields;
|
|
4143
|
+
const missing = useMemo(() => seeded.filter((entry) => !loaded.some((row) => row.slug === entry.slug)), [loaded, seeded]);
|
|
4144
|
+
const added = useRef(null);
|
|
4072
4145
|
useEffect(() => {
|
|
4073
|
-
if (
|
|
4146
|
+
if (missing.length === 0) return;
|
|
4147
|
+
const current = fields;
|
|
4148
|
+
const asked = added.current?.fields === current ? added.current.slugs : /* @__PURE__ */ new Set();
|
|
4149
|
+
for (const entry of missing) {
|
|
4150
|
+
if (asked.has(entry.slug)) continue;
|
|
4151
|
+
asked.add(entry.slug);
|
|
4152
|
+
dispatch({
|
|
4153
|
+
type: "ADD_ROW",
|
|
4154
|
+
path: props.path,
|
|
4155
|
+
subFieldState: rowState(entry)
|
|
4156
|
+
});
|
|
4157
|
+
}
|
|
4158
|
+
added.current = {
|
|
4159
|
+
fields: current,
|
|
4160
|
+
slugs: asked
|
|
4161
|
+
};
|
|
4074
4162
|
}, [
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4163
|
+
dispatch,
|
|
4164
|
+
fields,
|
|
4165
|
+
missing,
|
|
4166
|
+
props.path
|
|
4078
4167
|
]);
|
|
4168
|
+
const writeRow = useCallback((slug) => (column, value) => {
|
|
4169
|
+
const index = indexOfSlug(fieldsRef.current, props.path, slug);
|
|
4170
|
+
if (index < 0) return;
|
|
4171
|
+
dispatch({
|
|
4172
|
+
type: "UPDATE",
|
|
4173
|
+
path: `${props.path}.${index}.${column}`,
|
|
4174
|
+
value
|
|
4175
|
+
});
|
|
4176
|
+
setModified(true);
|
|
4177
|
+
}, [
|
|
4178
|
+
dispatch,
|
|
4179
|
+
props.path,
|
|
4180
|
+
setModified
|
|
4181
|
+
]);
|
|
4182
|
+
const rows = [...loaded, ...missing];
|
|
4079
4183
|
const previews = previewsOf(props.field);
|
|
4080
4184
|
const [category, setCategory] = useState("hero");
|
|
4081
4185
|
const navbarCount = rows.filter((row) => row.kind === "navbar").length;
|
|
4082
|
-
const visible = rows.
|
|
4083
|
-
row,
|
|
4084
|
-
index
|
|
4085
|
-
})).filter(({ row }) => row.category === category);
|
|
4186
|
+
const visible = rows.filter((row) => row.category === category);
|
|
4086
4187
|
return /* @__PURE__ */ jsx(KitProvider, { children: /* @__PURE__ */ jsx(Page, { children: /* @__PURE__ */ jsxs("div", {
|
|
4087
4188
|
className: "bl-block-library",
|
|
4088
4189
|
children: [
|
|
@@ -4102,11 +4203,9 @@ const BlockLibraryField = (props) => {
|
|
|
4102
4203
|
children: entry.label
|
|
4103
4204
|
}, entry.id))
|
|
4104
4205
|
}),
|
|
4105
|
-
/* @__PURE__ */ jsx("div", { children: visible.map((
|
|
4106
|
-
path: props.path,
|
|
4107
|
-
index,
|
|
4206
|
+
/* @__PURE__ */ jsx("div", { children: visible.map((row) => /* @__PURE__ */ jsx(LibraryCard, {
|
|
4108
4207
|
row,
|
|
4109
|
-
|
|
4208
|
+
write: loaded.some((entry) => entry.slug === row.slug) ? writeRow(row.slug) : null,
|
|
4110
4209
|
src: previews[row.slug] ?? "",
|
|
4111
4210
|
toggle: row.kind !== "navbar" || navbarCount > 1,
|
|
4112
4211
|
usageURL
|