@bison-lab/payload-core 4.4.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 +106 -5
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +244 -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/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as documentTitle, r as titleTemplate, t as SHARE_IMAGE_SIZE } from "./share-image-C4ILz4p2.mjs";
|
|
2
2
|
import { A as THEME_DOCUMENT_CONTROLS, C as validateSourceIncluded, D as THEME_COLOR_FIELD, E as THEME_APPEARANCE_FIELD, F as THEME_PAIRING_FIELD, I as THEME_PUBLISH_FIELD, L as THEME_SAVE_BUTTON, M as THEME_GREY_SCALE_FIELD, N as THEME_IDENTITY_FALLBACK, O as THEME_COLOR_SCALE_FIELD, P as THEME_LIBRARY_FIELD, R as THEME_SECTION_HEADING, S as themeConfigFromDoc, T as LOOK_FIELD, _ as THEME_IDENTITY_SLUG, a as PAGE_EDITOR_SYSTEM_KEYS, b as docFromConfig, c as themeLibraryFromDoc, d as deleteLibraryColor, f as rewriteColorToken, g as THEME_COLORS_SLUG, h as THEME_APPEARANCE_SLUG, i as lookField, j as THEME_FONT_FIELD, k as THEME_CONTRAST_REPORT, l as findColorTokens, m as SYSTEM_COLOR_KEYS, n as THEME_PREVIEW_BREAKPOINTS, o as pageEditorLooks, p as themeColorKeys, r as colorTokenField, s as pageEditorTokens, t as resolveThemeIdentity, u as rewriteColorTokens, v as THEME_SLUG, w as validateThemeHex, y as THEME_TYPOGRAPHY_SLUG, z as headingSelectValue } from "./identity-DOGDpCgK.mjs";
|
|
3
|
-
import { C as
|
|
3
|
+
import { C as NAVIGATION_SLUG, S as NAVIGATION_FOOTER_SLUG, _ as validateExternalHref, a as FOOTER_MAX_LINK_COLUMNS, b as NAVIGATION_FEATURE, c as footerDesktopTracks, d as validateFooterColumns, f as validateFooterSocialUrl, g as linkField, h as isValidExternalHref, i as FOOTER_MAX_COLUMNS, l as footerFields, m as headerCtaEnabled, n as FOOTER_COLUMNS_FIELD, o as FOOTER_SOCIALS, p as EXTERNAL_HREF_MESSAGE, r as FOOTER_COLUMN_WIDTHS, s as FOOTER_TWELFTHS, t as getNavigation, u as normalizeFooterDesktop, v as validateHeaderCta, x as NAVIGATION_FOOTER_DB_NAME, y as NAVIGATION_DB_NAME } from "./published-BvTPQqAF.mjs";
|
|
4
4
|
import { seoPlugin as seoPlugin$1 } from "@payloadcms/plugin-seo";
|
|
5
5
|
import { catalog } from "@bison-lab/fonts";
|
|
6
6
|
import { DESTRUCTIVE_SCALE_HEX, SHADE_STEPS, SUCCESS_SCALE_HEX, presetHints } from "@bison-lab/tokens";
|
|
@@ -183,7 +183,7 @@ async function findColorUsages(payload, scopes, key) {
|
|
|
183
183
|
token: hit.token
|
|
184
184
|
});
|
|
185
185
|
for (const slug of globals) {
|
|
186
|
-
const doc = await readGlobal$
|
|
186
|
+
const doc = await readGlobal$2(payload, slug);
|
|
187
187
|
if (!doc) continue;
|
|
188
188
|
for (const hit of findColorTokens(doc, key)) usages.push({
|
|
189
189
|
global: slug,
|
|
@@ -209,7 +209,7 @@ async function rewriteColorUsages(payload, scopes, fromKey, toKey) {
|
|
|
209
209
|
});
|
|
210
210
|
}
|
|
211
211
|
for (const slug of globals) {
|
|
212
|
-
const doc = await readGlobal$
|
|
212
|
+
const doc = await readGlobal$2(payload, slug);
|
|
213
213
|
if (!doc || findColorTokens(doc, fromKey).length === 0) continue;
|
|
214
214
|
await payload.updateGlobal({
|
|
215
215
|
slug,
|
|
@@ -244,7 +244,7 @@ function slugsOf$2(value) {
|
|
|
244
244
|
if (value && typeof value === "object") return Object.keys(value);
|
|
245
245
|
return [];
|
|
246
246
|
}
|
|
247
|
-
async function readGlobal$
|
|
247
|
+
async function readGlobal$2(payload, slug) {
|
|
248
248
|
try {
|
|
249
249
|
return await payload.findGlobal({
|
|
250
250
|
slug,
|
|
@@ -1674,11 +1674,12 @@ const BLOCK_LIBRARY_CATEGORIES = [
|
|
|
1674
1674
|
/**
|
|
1675
1675
|
* Package catalogue. `megaMenu` and `navLink` are header item blocks, not
|
|
1676
1676
|
* cards. Navigation's card is `floatingNav`. CTA is a category for a site
|
|
1677
|
-
* extra; the package ships no CTA slug.
|
|
1678
|
-
* route is SPI-53.
|
|
1677
|
+
* extra; the package ships no CTA slug. The preview route is SPI-53.
|
|
1679
1678
|
*/
|
|
1680
1679
|
const PACKAGE_BLOCK_SLUGS = [
|
|
1681
1680
|
"hero",
|
|
1681
|
+
"heroSweep",
|
|
1682
|
+
"heroCompact",
|
|
1682
1683
|
"showcasePanels",
|
|
1683
1684
|
"processSteps",
|
|
1684
1685
|
"faqColumns",
|
|
@@ -1698,6 +1699,18 @@ const PACKAGE_BLOCKS = [
|
|
|
1698
1699
|
category: "hero",
|
|
1699
1700
|
kind: "hero"
|
|
1700
1701
|
},
|
|
1702
|
+
{
|
|
1703
|
+
slug: "heroSweep",
|
|
1704
|
+
label: "Sweep hero",
|
|
1705
|
+
category: "hero",
|
|
1706
|
+
kind: "hero"
|
|
1707
|
+
},
|
|
1708
|
+
{
|
|
1709
|
+
slug: "heroCompact",
|
|
1710
|
+
label: "Compact hero",
|
|
1711
|
+
category: "hero",
|
|
1712
|
+
kind: "hero"
|
|
1713
|
+
},
|
|
1701
1714
|
{
|
|
1702
1715
|
slug: "showcasePanels",
|
|
1703
1716
|
label: "Showcase panels",
|
|
@@ -1787,7 +1800,9 @@ function holderLabel(holder) {
|
|
|
1787
1800
|
return slug ? `${title} (${slug})` : title;
|
|
1788
1801
|
}
|
|
1789
1802
|
/**
|
|
1790
|
-
* Refuses a disable
|
|
1803
|
+
* Refuses a disable: the last hero, the last navbar, or a slug a published
|
|
1804
|
+
* document holds. Drafts alone never refuse; the Save that turns the slug
|
|
1805
|
+
* off strips them (`stripDrafts`). Pure — writes nothing.
|
|
1791
1806
|
*/
|
|
1792
1807
|
async function validateBlockLibrary(value, options, check = {}) {
|
|
1793
1808
|
const next = stampBlockLibrary(value, options);
|
|
@@ -1801,7 +1816,9 @@ async function validateBlockLibrary(value, options, check = {}) {
|
|
|
1801
1816
|
const holders = check.holders ?? [];
|
|
1802
1817
|
if (holders.length > 0) {
|
|
1803
1818
|
const names = holders.map(holderLabel).join(", ");
|
|
1804
|
-
|
|
1819
|
+
const slugs = turningOff.map((row) => row.label).join(", ");
|
|
1820
|
+
const drafts = check.drafts ?? [];
|
|
1821
|
+
return `Cannot disable ${slugs}. Still published on: ${names}. Remove it from those first.${drafts.length > 0 ? ` Drafts also use it and were left as they are: ${drafts.map(holderLabel).join(", ")}.` : ""}`;
|
|
1805
1822
|
}
|
|
1806
1823
|
return true;
|
|
1807
1824
|
}
|
|
@@ -1810,6 +1827,14 @@ async function validateBlockLibrary(value, options, check = {}) {
|
|
|
1810
1827
|
const BLOCK_LIBRARY_FIELD = "@bison-lab/payload-core/admin#BlockLibraryField";
|
|
1811
1828
|
//#endregion
|
|
1812
1829
|
//#region src/block-library/holders.ts
|
|
1830
|
+
/** Payload's bookkeeping, never block rows. */
|
|
1831
|
+
const NOT_CONTENT = new Set([
|
|
1832
|
+
"id",
|
|
1833
|
+
"_status",
|
|
1834
|
+
"createdAt",
|
|
1835
|
+
"updatedAt",
|
|
1836
|
+
"globalType"
|
|
1837
|
+
]);
|
|
1813
1838
|
function slugsOf$1(value) {
|
|
1814
1839
|
return (value ?? []).map((item) => item.slug).filter((slug) => Boolean(slug));
|
|
1815
1840
|
}
|
|
@@ -1820,66 +1845,202 @@ function holdsSlug(value, slug) {
|
|
|
1820
1845
|
if (record.blockType === slug) return true;
|
|
1821
1846
|
return Object.values(record).some((child) => holdsSlug(child, slug));
|
|
1822
1847
|
}
|
|
1823
|
-
|
|
1848
|
+
/**
|
|
1849
|
+
* A block row of one of `slugs`: an array row (`blockType`) or a Lexical
|
|
1850
|
+
* block node embedding one (`fields.blockType`), so a strip removes every
|
|
1851
|
+
* use `holdsSlug` counts.
|
|
1852
|
+
*/
|
|
1853
|
+
function isRowOf(item, slugs) {
|
|
1854
|
+
if (!item || typeof item !== "object") return false;
|
|
1855
|
+
const record = item;
|
|
1856
|
+
const blockType = record.blockType ?? (record.fields && typeof record.fields === "object" ? record.fields.blockType : void 0);
|
|
1857
|
+
return typeof blockType === "string" && slugs.has(blockType);
|
|
1858
|
+
}
|
|
1859
|
+
/** `value` with every block row of any of `slugs` removed, at any depth. */
|
|
1860
|
+
function withoutSlugs(value, slugs) {
|
|
1861
|
+
if (!value || typeof value !== "object") return value;
|
|
1862
|
+
if (Array.isArray(value)) return value.filter((item) => !isRowOf(item, slugs)).map((item) => withoutSlugs(item, slugs));
|
|
1863
|
+
return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, withoutSlugs(child, slugs)]));
|
|
1864
|
+
}
|
|
1865
|
+
/** The top-level fields of `doc` that hold any of `slugs`, with those rows removed. */
|
|
1866
|
+
function strippedFields(doc, slugs) {
|
|
1867
|
+
const data = {};
|
|
1868
|
+
for (const [key, value] of Object.entries(doc)) {
|
|
1869
|
+
if (NOT_CONTENT.has(key) || ![...slugs].some((slug) => holdsSlug(value, slug))) continue;
|
|
1870
|
+
data[key] = withoutSlugs(value, slugs);
|
|
1871
|
+
}
|
|
1872
|
+
return data;
|
|
1873
|
+
}
|
|
1874
|
+
function asHolder(doc, fallback) {
|
|
1824
1875
|
return {
|
|
1825
|
-
title: typeof doc.title === "string" ? doc.title : null,
|
|
1876
|
+
title: typeof doc.title === "string" ? doc.title : fallback ?? null,
|
|
1826
1877
|
slug: typeof doc.slug === "string" ? doc.slug : null
|
|
1827
1878
|
};
|
|
1828
1879
|
}
|
|
1880
|
+
/** Payload's draft flag. A document without versions is always live. */
|
|
1881
|
+
function isDraft(doc) {
|
|
1882
|
+
return doc._status === "draft";
|
|
1883
|
+
}
|
|
1884
|
+
function globalLabel(slug) {
|
|
1885
|
+
return slug === "navigation" ? "Header" : slug;
|
|
1886
|
+
}
|
|
1887
|
+
/** The navbar slug a Header document uses: `header.navbar`, else `fallback`. */
|
|
1888
|
+
function activeNavbar(doc, fallback) {
|
|
1889
|
+
const header = doc?.header;
|
|
1890
|
+
if (header && typeof header === "object") {
|
|
1891
|
+
const navbar = header.navbar;
|
|
1892
|
+
if (typeof navbar === "string" && navbar) return navbar;
|
|
1893
|
+
}
|
|
1894
|
+
return fallback;
|
|
1895
|
+
}
|
|
1896
|
+
async function findAll(payload, collection, draft, req) {
|
|
1897
|
+
const docs = [];
|
|
1898
|
+
let page = 1;
|
|
1899
|
+
for (;;) {
|
|
1900
|
+
const result = await payload.find({
|
|
1901
|
+
collection,
|
|
1902
|
+
draft,
|
|
1903
|
+
depth: 0,
|
|
1904
|
+
limit: 100,
|
|
1905
|
+
page,
|
|
1906
|
+
overrideAccess: true,
|
|
1907
|
+
...req ? { req } : {}
|
|
1908
|
+
});
|
|
1909
|
+
docs.push(...result.docs);
|
|
1910
|
+
const totalPages = result.totalPages ?? (result.docs.length < 100 ? page : page + 1);
|
|
1911
|
+
if (page >= totalPages || result.docs.length === 0) break;
|
|
1912
|
+
page += 1;
|
|
1913
|
+
}
|
|
1914
|
+
return docs;
|
|
1915
|
+
}
|
|
1916
|
+
async function readGlobal$1(payload, slug, draft, req) {
|
|
1917
|
+
if (!payload.findGlobal) return null;
|
|
1918
|
+
return payload.findGlobal({
|
|
1919
|
+
slug,
|
|
1920
|
+
draft,
|
|
1921
|
+
depth: 0,
|
|
1922
|
+
overrideAccess: true,
|
|
1923
|
+
...req ? { req } : {}
|
|
1924
|
+
});
|
|
1925
|
+
}
|
|
1829
1926
|
/**
|
|
1830
|
-
*
|
|
1831
|
-
*
|
|
1927
|
+
* Where `slug` is used, split the way a disable decides. Reads only.
|
|
1928
|
+
*
|
|
1929
|
+
* `published`: live documents that hold the slug (Payload's main row is the
|
|
1930
|
+
* published version), and the published Header when the slug is its navbar.
|
|
1931
|
+
* Any of these refuses the disable.
|
|
1932
|
+
*
|
|
1933
|
+
* `drafts`: documents whose newest version is a draft that holds the slug.
|
|
1934
|
+
* A page can be in both lists.
|
|
1832
1935
|
*/
|
|
1833
|
-
async function
|
|
1936
|
+
async function blockUsage(payload, slug, options = {}) {
|
|
1834
1937
|
const collections = slugsOf$1(payload.config?.collections).filter((name) => !name.startsWith("payload-") && name !== "block-library");
|
|
1835
1938
|
const globals = slugsOf$1(payload.config?.globals).filter((name) => name !== BLOCK_LIBRARY_SLUG);
|
|
1836
|
-
const
|
|
1837
|
-
const
|
|
1838
|
-
const
|
|
1839
|
-
|
|
1840
|
-
const
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1939
|
+
const published = [];
|
|
1940
|
+
const drafts = [];
|
|
1941
|
+
for (const collection of collections) {
|
|
1942
|
+
const live = /* @__PURE__ */ new Set();
|
|
1943
|
+
for (const doc of await findAll(payload, collection, false, options.req)) {
|
|
1944
|
+
if (isDraft(doc) || !holdsSlug(doc, slug) || live.has(String(doc.id))) continue;
|
|
1945
|
+
live.add(String(doc.id));
|
|
1946
|
+
published.push(asHolder(doc));
|
|
1947
|
+
}
|
|
1948
|
+
const draft = /* @__PURE__ */ new Set();
|
|
1949
|
+
for (const doc of await findAll(payload, collection, true, options.req)) {
|
|
1950
|
+
if (doc.id == null || !isDraft(doc) || !holdsSlug(doc, slug) || draft.has(String(doc.id))) continue;
|
|
1951
|
+
draft.add(String(doc.id));
|
|
1952
|
+
drafts.push({
|
|
1953
|
+
...asHolder(doc),
|
|
1954
|
+
collection,
|
|
1955
|
+
id: doc.id
|
|
1956
|
+
});
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1959
|
+
for (const global of globals) {
|
|
1960
|
+
const live = await readGlobal$1(payload, global, false, options.req);
|
|
1961
|
+
const navbarHere = options.navbar === true && global === "navigation" && activeNavbar(live, options.defaultNavbar ?? "") === slug;
|
|
1962
|
+
if (live && !isDraft(live) && (holdsSlug(live, slug) || navbarHere)) published.push(asHolder(live, globalLabel(global)));
|
|
1963
|
+
const latest = await readGlobal$1(payload, global, true, options.req);
|
|
1964
|
+
if (latest && isDraft(latest) && holdsSlug(latest, slug)) drafts.push({
|
|
1965
|
+
...asHolder(latest, globalLabel(global)),
|
|
1966
|
+
global
|
|
1967
|
+
});
|
|
1968
|
+
}
|
|
1969
|
+
return {
|
|
1970
|
+
published,
|
|
1971
|
+
drafts
|
|
1972
|
+
};
|
|
1973
|
+
}
|
|
1974
|
+
/**
|
|
1975
|
+
* Removes every row of `slugs` from each draft and saves it as one new
|
|
1976
|
+
* draft version per document, inside `req`'s transaction. All slugs go in
|
|
1977
|
+
* one write so a second slug cannot write back a row the first removed.
|
|
1978
|
+
* Reads go through `req` too, so each starts from the newest version the
|
|
1979
|
+
* transaction can see. Published versions are untouched; only the fields
|
|
1980
|
+
* that held a slug are written.
|
|
1981
|
+
*/
|
|
1982
|
+
async function stripDrafts(payload, slugs, drafts, req) {
|
|
1983
|
+
const remove = new Set(slugs);
|
|
1984
|
+
if (remove.size === 0) return;
|
|
1985
|
+
const byCollection = /* @__PURE__ */ new Map();
|
|
1986
|
+
const globals = /* @__PURE__ */ new Set();
|
|
1987
|
+
for (const draft of drafts) {
|
|
1988
|
+
if (draft.global) globals.add(draft.global);
|
|
1989
|
+
if (!draft.collection || draft.id == null) continue;
|
|
1990
|
+
const ids = byCollection.get(draft.collection) ?? /* @__PURE__ */ new Set();
|
|
1991
|
+
ids.add(String(draft.id));
|
|
1992
|
+
byCollection.set(draft.collection, ids);
|
|
1993
|
+
}
|
|
1994
|
+
for (const [collection, ids] of byCollection) {
|
|
1995
|
+
if (!payload.update) throw new Error("Cannot remove blocks from drafts: Payload has no update.");
|
|
1996
|
+
for (const doc of await findAll(payload, collection, true, req)) {
|
|
1997
|
+
if (!ids.has(String(doc.id)) || !isDraft(doc)) continue;
|
|
1998
|
+
const data = strippedFields(doc, remove);
|
|
1999
|
+
if (Object.keys(data).length === 0) continue;
|
|
2000
|
+
await payload.update({
|
|
2001
|
+
collection,
|
|
2002
|
+
id: doc.id,
|
|
2003
|
+
data,
|
|
2004
|
+
draft: true,
|
|
2005
|
+
depth: 0,
|
|
2006
|
+
overrideAccess: true,
|
|
2007
|
+
req
|
|
2008
|
+
});
|
|
1865
2009
|
}
|
|
1866
2010
|
}
|
|
1867
|
-
|
|
1868
|
-
|
|
2011
|
+
for (const global of globals) {
|
|
2012
|
+
if (!payload.updateGlobal) throw new Error("Cannot remove blocks from drafts: Payload has no updateGlobal.");
|
|
2013
|
+
const doc = await readGlobal$1(payload, global, true, req);
|
|
2014
|
+
if (!doc || !isDraft(doc)) continue;
|
|
2015
|
+
const data = strippedFields(doc, remove);
|
|
2016
|
+
if (Object.keys(data).length === 0) continue;
|
|
2017
|
+
await payload.updateGlobal({
|
|
1869
2018
|
slug: global,
|
|
1870
|
-
|
|
2019
|
+
data,
|
|
2020
|
+
draft: true,
|
|
1871
2021
|
depth: 0,
|
|
1872
|
-
overrideAccess: true
|
|
2022
|
+
overrideAccess: true,
|
|
2023
|
+
req
|
|
1873
2024
|
});
|
|
1874
|
-
|
|
1875
|
-
} catch {}
|
|
1876
|
-
return holders;
|
|
2025
|
+
}
|
|
1877
2026
|
}
|
|
1878
2027
|
//#endregion
|
|
1879
2028
|
//#region src/block-library/global.ts
|
|
2029
|
+
/** A navbar can be held by the published Header; the package navbar is its default. */
|
|
2030
|
+
function usageOptions(row, rows) {
|
|
2031
|
+
return {
|
|
2032
|
+
navbar: row.kind === "navbar",
|
|
2033
|
+
defaultNavbar: rows.find((entry) => entry.kind === "navbar")?.slug
|
|
2034
|
+
};
|
|
2035
|
+
}
|
|
1880
2036
|
/**
|
|
1881
2037
|
* Settings → Block library. One card per installed option. Off is editorial
|
|
1882
2038
|
* availability. The preview route that fills each island is SPI-53.
|
|
2039
|
+
*
|
|
2040
|
+
* Turning a slug off is refused while a published page or the published
|
|
2041
|
+
* Header holds it. Otherwise the Save that turns it off deletes its rows
|
|
2042
|
+
* from every draft that still holds it (the admin confirms first, using
|
|
2043
|
+
* `GET /api/globals/block-library/usage?slug=…`).
|
|
1883
2044
|
*/
|
|
1884
2045
|
function createBlockLibrary({ access, blocks = [], previewPath }) {
|
|
1885
2046
|
const options = {
|
|
@@ -1906,13 +2067,29 @@ function createBlockLibrary({ access, blocks = [], previewPath }) {
|
|
|
1906
2067
|
const turningOff = stamped.filter((row) => {
|
|
1907
2068
|
return originals.find((entry) => entry.slug === row.slug)?.enabled !== false && row.enabled === false;
|
|
1908
2069
|
});
|
|
2070
|
+
if (turningOff.length === 0) return stamped;
|
|
2071
|
+
const counted = await validateBlockLibrary(stamped, options, { originals });
|
|
2072
|
+
if (counted !== true) throw new APIError(counted, 400);
|
|
2073
|
+
const payload = req?.payload;
|
|
2074
|
+
if (!payload) return stamped;
|
|
2075
|
+
const drafts = [];
|
|
1909
2076
|
for (const row of turningOff) {
|
|
1910
|
-
const
|
|
2077
|
+
const usage = await blockUsage(payload, row.slug, {
|
|
2078
|
+
...usageOptions(row, stamped),
|
|
2079
|
+
req
|
|
2080
|
+
});
|
|
2081
|
+
const message = await validateBlockLibrary(originals.map((entry) => entry.slug === row.slug ? {
|
|
2082
|
+
...entry,
|
|
2083
|
+
enabled: false
|
|
2084
|
+
} : entry), options, {
|
|
1911
2085
|
originals,
|
|
1912
|
-
holders:
|
|
2086
|
+
holders: usage.published,
|
|
2087
|
+
drafts: usage.drafts
|
|
1913
2088
|
});
|
|
1914
|
-
if (message !== true) throw new
|
|
2089
|
+
if (message !== true) throw new APIError(message, 400);
|
|
2090
|
+
drafts.push(...usage.drafts);
|
|
1915
2091
|
}
|
|
2092
|
+
if (drafts.length > 0) await stripDrafts(payload, turningOff.map((row) => row.slug), drafts, req);
|
|
1916
2093
|
return stamped;
|
|
1917
2094
|
}] },
|
|
1918
2095
|
admin: {
|
|
@@ -1953,6 +2130,7 @@ function createBlockLibrary({ access, blocks = [], previewPath }) {
|
|
|
1953
2130
|
}
|
|
1954
2131
|
]
|
|
1955
2132
|
};
|
|
2133
|
+
const update = access?.update ?? isAdmin;
|
|
1956
2134
|
return {
|
|
1957
2135
|
slug: BLOCK_LIBRARY_SLUG,
|
|
1958
2136
|
label: "Block library",
|
|
@@ -1962,8 +2140,20 @@ function createBlockLibrary({ access, blocks = [], previewPath }) {
|
|
|
1962
2140
|
},
|
|
1963
2141
|
access: {
|
|
1964
2142
|
read: access?.read ?? isAuthenticated,
|
|
1965
|
-
update
|
|
2143
|
+
update
|
|
1966
2144
|
},
|
|
2145
|
+
endpoints: [{
|
|
2146
|
+
path: "/usage",
|
|
2147
|
+
method: "get",
|
|
2148
|
+
handler: async (req) => {
|
|
2149
|
+
if (!await Promise.resolve(update({ req }))) return Response.json({ error: "Forbidden" }, { status: 403 });
|
|
2150
|
+
const slug = req.searchParams?.get("slug") ?? "";
|
|
2151
|
+
const row = defaultBlockLibraryValue(options).find((entry) => entry.slug === slug);
|
|
2152
|
+
if (!row) return Response.json({ error: `Unknown block: ${slug}` }, { status: 400 });
|
|
2153
|
+
const usage = await blockUsage(req.payload, slug, usageOptions(row, defaultBlockLibraryValue(options)));
|
|
2154
|
+
return Response.json(usage);
|
|
2155
|
+
}
|
|
2156
|
+
}],
|
|
1967
2157
|
fields: [blocksField]
|
|
1968
2158
|
};
|
|
1969
2159
|
}
|
|
@@ -3739,6 +3929,6 @@ const documentTitleActions = definePlugin({
|
|
|
3739
3929
|
plugin: ({ config }) => withTitleActions(config)
|
|
3740
3930
|
});
|
|
3741
3931
|
//#endregion
|
|
3742
|
-
export { ADMIN_NAV, ADMIN_NAV_ENTITY_FIELD, ADMIN_NAV_ITEM_ROW_LABEL, ADMIN_NAV_ROW_LABEL, ADMIN_NAV_SLUG, BLOCK_LIBRARY_CATEGORIES, BLOCK_LIBRARY_FIELD, BLOCK_LIBRARY_SLUG, BRAND_ASSETS_MIME_TYPES, BRAND_ASSETS_SLUG, CAPABILITIES, CAPABILITY_FEATURES, DEFAULT_ROLE_GRANTS, DEFAULT_ROLE_MATRIX, DESCRIPTION_LENGTH, DEVELOPER_DESCRIPTION, DOCUMENT_CREATE_NEW, DOCUMENT_TITLE_ACTIONS, DUPLICATE_ROLE_NAME_MESSAGE, DUPLICATE_ROLE_SLUG_MESSAGE, EXISTING_PARENT_MESSAGE, EXTERNAL_HREF_MESSAGE, FEATURES_MATRIX_FIELD, FEATURES_SLUG, FEATURE_GROUPS, FEATURE_GROUP_LABELS, FOOTER_COLUMNS_FIELD, FOOTER_COLUMN_WIDTHS, FOOTER_MAX_COLUMNS, FOOTER_MAX_LINK_COLUMNS, FOOTER_SOCIALS, FOOTER_TWELFTHS, INVALID_ROLE_NAME_MESSAGE, LAST_ADMIN_DELETE_MESSAGE, LAST_ADMIN_DEMOTE_MESSAGE, LAST_USERS_TICK_MESSAGE, LAYOUT_DESCRIPTION, LAYOUT_REQUIRED_LABEL, LAYOUT_REQUIRED_MESSAGE, LOOK_FIELD, MEDIA_ALT_AUTOFILL, MEDIA_IN_USE_PATH, MEDIA_LIST, MISSING_PACKAGE_FEATURES_MESSAGE, MISSING_SEED_ROLES_MESSAGE, NAVIGATION_DB_NAME, NAVIGATION_FEATURE, NAVIGATION_FOOTER_DB_NAME, NAVIGATION_FOOTER_SLUG, NAVIGATION_SLUG, NEW_FOLDER_PARENT, PACKAGE_BLOCK_SLUGS, PACKAGE_FEATURES, PACKAGE_FEATURE_SLUGS, PAGE_EDITOR_SYSTEM_KEYS, PAGE_SLUG_CELL, PAGE_TITLE_CELL, QUESTIONS_FEATURE, QUESTIONS_LIST, QUESTIONS_SLUG, REDIRECTS_SLUG, REQUIRED_PAGE_CELL, REQUIRED_PAGE_DELETE_MESSAGE, REQUIRED_PAGE_FIELD, REQUIRED_PAGE_UNPUBLISH_MESSAGE, ROLES, ROLES_FIELD, ROLES_FIELD_DESCRIPTION, ROLES_GLOBAL_DESCRIPTION, ROLES_GRANTS_FIELD, ROLES_MATRIX_FIELD, ROLES_ROW_LABEL, ROLES_SLUG, ROLE_LABELS, ROLE_NAME_FIELD, ROLE_SLUG_FIELD, ROOT_PAGE_KEY, ROOT_PAGE_SLUG, SHARE_IMAGE_SIZE, SLUG_FIELD, SLUG_UNLOCK_WARNING, SYSTEM_COLOR_KEYS, THEME_APPEARANCE_FIELD, THEME_APPEARANCE_SLUG, THEME_COLORS_SLUG, THEME_COLOR_FIELD, THEME_COLOR_SCALE_FIELD, THEME_CONTRAST_REPORT, THEME_DOCUMENT_CONTROLS, THEME_FEATURE_SLUGS, THEME_FONT_FIELD, THEME_GREY_SCALE_FIELD, THEME_IDENTITY_FALLBACK, THEME_IDENTITY_SLUG, THEME_LIBRARY_FIELD, THEME_PAIRING_FIELD, THEME_PREVIEW_BREAKPOINTS, THEME_PUBLISH_FIELD, THEME_SAVE_BUTTON, THEME_SECTION_HEADING, THEME_SLUG, THEME_TYPOGRAPHY_SLUG, adminNav, adminOnlyApiTab, allowedFeaturesForUser, altFromFilename, applyRoleSlugsFromNames, authenticatedOrPublished, blockLibraryCatalogue, canManageBrand, canManageContent, canPublish, canUseFeature, colorTokenField, composeSlug, createAdminNav, createBlockLibrary, createBrandAssets, createFeatures, createMedia, createNavigation, createPages, createQuestions, createRedirects, createRoles, createTaxonomy, createTheme, createUsers, defaultBlockLibraryValue, defaultFeaturesFieldValue, defaultRolesFieldValue, deleteLibraryColor, developerOnlyAccess, documentCreateNew, documentTitle, documentTitleActions, ensureRootPage, featureCatalogue, featureGroupLabel, fillBlankAltFromFilename, findColorTokens, findColorUsages, firstImageIn, footerDesktopTracks, getFeaturesMatrix, getNavigation, getRolesMatrix, hasCapability, hasFeature, hasGrant, hasRole, headerCtaEnabled, hideUnlessDeveloper, hideUnlessFeature, inferredFolders, isAdmin, isAdminOrSelf, isAuthenticated, isDeveloper, isDeveloperTab, isFeatureGroupId, isFeatureSlug, isLockedFeature, isPackageFeatureSlug, isPrivilegedRole, isRole, isRoleName, isRoleSlug, isRootPageKey, isValidExternalHref, lexicalPlainText, lockSlugOnPublish, lookField, noIndexField, normalizeFooterDesktop, normalizeSlug, normalizeStoredRoles, pageEditorLooks, pageEditorTokens, parentPrefix, parseFeaturesMatrix, parseRolesMatrix, persistThemeChild, publishThemeChild, recordPublishedSlugRedirect, redirectPath, replaceClientOriginalWithResizedFile, requireLayoutOnPublish, resetRolesMatrix, resolveAdminNav, resolveThemeIdentity, rewriteColorToken, rewriteColorTokens, rewriteColorUsages, roleDescription, roleLabel, roleSelectOptions, sanitizeRoleNameInput, sanitizeSvg, seedFeatures, seedRoleRows, seedRoles, seedTheme, seoPlugin, slugDepth, slugField, slugLeaf, slugifyRoleName, stampBlockLibrary, stampFeatureCatalogue, storedRoles, syncAnswerText, themeColorKeys, themeLibraryFromDoc, titleTemplate, truncateAtWord, validateBlockLibrary, validateExternalHref, validateFeaturesMatrix, validateFooterColumns, validateFooterSocialUrl, validateHeaderCta, validateRolesMatrix, writePublishedSlugRedirect };
|
|
3932
|
+
export { ADMIN_NAV, ADMIN_NAV_ENTITY_FIELD, ADMIN_NAV_ITEM_ROW_LABEL, ADMIN_NAV_ROW_LABEL, ADMIN_NAV_SLUG, BLOCK_LIBRARY_CATEGORIES, BLOCK_LIBRARY_FIELD, BLOCK_LIBRARY_SLUG, BRAND_ASSETS_MIME_TYPES, BRAND_ASSETS_SLUG, CAPABILITIES, CAPABILITY_FEATURES, DEFAULT_ROLE_GRANTS, DEFAULT_ROLE_MATRIX, DESCRIPTION_LENGTH, DEVELOPER_DESCRIPTION, DOCUMENT_CREATE_NEW, DOCUMENT_TITLE_ACTIONS, DUPLICATE_ROLE_NAME_MESSAGE, DUPLICATE_ROLE_SLUG_MESSAGE, EXISTING_PARENT_MESSAGE, EXTERNAL_HREF_MESSAGE, FEATURES_MATRIX_FIELD, FEATURES_SLUG, FEATURE_GROUPS, FEATURE_GROUP_LABELS, FOOTER_COLUMNS_FIELD, FOOTER_COLUMN_WIDTHS, FOOTER_MAX_COLUMNS, FOOTER_MAX_LINK_COLUMNS, FOOTER_SOCIALS, FOOTER_TWELFTHS, INVALID_ROLE_NAME_MESSAGE, LAST_ADMIN_DELETE_MESSAGE, LAST_ADMIN_DEMOTE_MESSAGE, LAST_USERS_TICK_MESSAGE, LAYOUT_DESCRIPTION, LAYOUT_REQUIRED_LABEL, LAYOUT_REQUIRED_MESSAGE, LOOK_FIELD, MEDIA_ALT_AUTOFILL, MEDIA_IN_USE_PATH, MEDIA_LIST, MISSING_PACKAGE_FEATURES_MESSAGE, MISSING_SEED_ROLES_MESSAGE, NAVIGATION_DB_NAME, NAVIGATION_FEATURE, NAVIGATION_FOOTER_DB_NAME, NAVIGATION_FOOTER_SLUG, NAVIGATION_SLUG, NEW_FOLDER_PARENT, PACKAGE_BLOCK_SLUGS, PACKAGE_FEATURES, PACKAGE_FEATURE_SLUGS, PAGE_EDITOR_SYSTEM_KEYS, PAGE_SLUG_CELL, PAGE_TITLE_CELL, QUESTIONS_FEATURE, QUESTIONS_LIST, QUESTIONS_SLUG, REDIRECTS_SLUG, REQUIRED_PAGE_CELL, REQUIRED_PAGE_DELETE_MESSAGE, REQUIRED_PAGE_FIELD, REQUIRED_PAGE_UNPUBLISH_MESSAGE, ROLES, ROLES_FIELD, ROLES_FIELD_DESCRIPTION, ROLES_GLOBAL_DESCRIPTION, ROLES_GRANTS_FIELD, ROLES_MATRIX_FIELD, ROLES_ROW_LABEL, ROLES_SLUG, ROLE_LABELS, ROLE_NAME_FIELD, ROLE_SLUG_FIELD, ROOT_PAGE_KEY, ROOT_PAGE_SLUG, SHARE_IMAGE_SIZE, SLUG_FIELD, SLUG_UNLOCK_WARNING, SYSTEM_COLOR_KEYS, THEME_APPEARANCE_FIELD, THEME_APPEARANCE_SLUG, THEME_COLORS_SLUG, THEME_COLOR_FIELD, THEME_COLOR_SCALE_FIELD, THEME_CONTRAST_REPORT, THEME_DOCUMENT_CONTROLS, THEME_FEATURE_SLUGS, THEME_FONT_FIELD, THEME_GREY_SCALE_FIELD, THEME_IDENTITY_FALLBACK, THEME_IDENTITY_SLUG, THEME_LIBRARY_FIELD, THEME_PAIRING_FIELD, THEME_PREVIEW_BREAKPOINTS, THEME_PUBLISH_FIELD, THEME_SAVE_BUTTON, THEME_SECTION_HEADING, THEME_SLUG, THEME_TYPOGRAPHY_SLUG, adminNav, adminOnlyApiTab, allowedFeaturesForUser, altFromFilename, applyRoleSlugsFromNames, authenticatedOrPublished, blockLibraryCatalogue, blockUsage, canManageBrand, canManageContent, canPublish, canUseFeature, colorTokenField, composeSlug, createAdminNav, createBlockLibrary, createBrandAssets, createFeatures, createMedia, createNavigation, createPages, createQuestions, createRedirects, createRoles, createTaxonomy, createTheme, createUsers, defaultBlockLibraryValue, defaultFeaturesFieldValue, defaultRolesFieldValue, deleteLibraryColor, developerOnlyAccess, documentCreateNew, documentTitle, documentTitleActions, ensureRootPage, featureCatalogue, featureGroupLabel, fillBlankAltFromFilename, findColorTokens, findColorUsages, firstImageIn, footerDesktopTracks, getFeaturesMatrix, getNavigation, getRolesMatrix, hasCapability, hasFeature, hasGrant, hasRole, headerCtaEnabled, hideUnlessDeveloper, hideUnlessFeature, inferredFolders, isAdmin, isAdminOrSelf, isAuthenticated, isDeveloper, isDeveloperTab, isFeatureGroupId, isFeatureSlug, isLockedFeature, isPackageFeatureSlug, isPrivilegedRole, isRole, isRoleName, isRoleSlug, isRootPageKey, isValidExternalHref, lexicalPlainText, lockSlugOnPublish, lookField, noIndexField, normalizeFooterDesktop, normalizeSlug, normalizeStoredRoles, pageEditorLooks, pageEditorTokens, parentPrefix, parseFeaturesMatrix, parseRolesMatrix, persistThemeChild, publishThemeChild, recordPublishedSlugRedirect, redirectPath, replaceClientOriginalWithResizedFile, requireLayoutOnPublish, resetRolesMatrix, resolveAdminNav, resolveThemeIdentity, rewriteColorToken, rewriteColorTokens, rewriteColorUsages, roleDescription, roleLabel, roleSelectOptions, sanitizeRoleNameInput, sanitizeSvg, seedFeatures, seedRoleRows, seedRoles, seedTheme, seoPlugin, slugDepth, slugField, slugLeaf, slugifyRoleName, stampBlockLibrary, stampFeatureCatalogue, storedRoles, stripDrafts, syncAnswerText, themeColorKeys, themeLibraryFromDoc, titleTemplate, truncateAtWord, validateBlockLibrary, validateExternalHref, validateFeaturesMatrix, validateFooterColumns, validateFooterSocialUrl, validateHeaderCta, validateRolesMatrix, writePublishedSlugRedirect };
|
|
3743
3933
|
|
|
3744
3934
|
//# sourceMappingURL=index.mjs.map
|