@bison-lab/payload-core 3.39.0 → 3.42.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 -35
- package/dist/admin.d.mts +3 -3
- package/dist/admin.d.mts.map +1 -1
- package/dist/admin.mjs +117 -105
- package/dist/admin.mjs.map +1 -1
- package/dist/identity-DOGDpCgK.mjs.map +1 -1
- package/dist/index.d.mts +22 -18
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +140 -151
- package/dist/index.mjs.map +1 -1
- package/dist/looks-BbL309kO.mjs.map +1 -1
- package/dist/{preview-B2u9AkFF.d.mts → preview-DtBDy2kv.d.mts} +7 -6
- package/dist/{preview-B2u9AkFF.d.mts.map → preview-DtBDy2kv.d.mts.map} +1 -1
- package/dist/theme.d.mts +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -12,9 +12,9 @@ pnpm add @bison-lab/payload-core @payloadcms/plugin-seo @payloadcms/plugin-redir
|
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
Peers: `payload`, `@payloadcms/plugin-seo`, and `@payloadcms/plugin-redirects` are required. `@bison-lab/tokens`
|
|
15
|
-
and `@bison-lab/fonts` are
|
|
16
|
-
and `react` are needed for
|
|
17
|
-
`@payloadcms/live-preview-react` are
|
|
15
|
+
and `@bison-lab/fonts` are required because Theme is required. `@payloadcms/ui`
|
|
16
|
+
and `react` are needed for admin fields; `@bison-lab/ui` and
|
|
17
|
+
`@payloadcms/live-preview-react` are peers of the legacy `./react` entry.
|
|
18
18
|
Pin the plugin to the same version as `payload`; Payload releases them in
|
|
19
19
|
lockstep.
|
|
20
20
|
|
|
@@ -125,9 +125,9 @@ carry through Next's metadata merge.
|
|
|
125
125
|
|
|
126
126
|
The sitemap is the site's: filter `meta.noIndex` out of it.
|
|
127
127
|
|
|
128
|
-
##
|
|
128
|
+
## Theme
|
|
129
129
|
|
|
130
|
-
Theme
|
|
130
|
+
Theme is required. The admin nav shows one Global (`theme`) in `admin.group: "Theme"`.
|
|
131
131
|
Colors, Typography, Appearance, and Identity are field tabs on that
|
|
132
132
|
document, not custom views and not extra Globals. Save is Payload's Save
|
|
133
133
|
on the whole form — every tab is hydrated from the live row, so an
|
|
@@ -143,34 +143,28 @@ Changing a brand hex or **This color is** leaves the chips as they were;
|
|
|
143
143
|
Success and Destructive family banners use the same scale steps as the
|
|
144
144
|
visitor Alert.
|
|
145
145
|
|
|
146
|
-
**1. Register the Global.**
|
|
147
|
-
|
|
148
|
-
|
|
146
|
+
**1. Register the Global.** `update` defaults to `canUseFeature("theme")`
|
|
147
|
+
(Designer in the seed). Pass `access.read` to tighten who can read the
|
|
148
|
+
document. Omitting `access` still registers the Global. Features does
|
|
149
|
+
not install or remove it.
|
|
149
150
|
|
|
150
151
|
```ts
|
|
151
152
|
// payload.config.ts
|
|
152
153
|
import {
|
|
153
154
|
BRAND_ASSETS_SLUG,
|
|
154
155
|
createBrandAssets,
|
|
155
|
-
canUseFeature,
|
|
156
156
|
createFeatures,
|
|
157
157
|
createRoles,
|
|
158
158
|
createTheme,
|
|
159
|
-
isAuthenticated,
|
|
160
159
|
} from "@bison-lab/payload-core";
|
|
161
160
|
import bisonConfig from "../bison.config.json";
|
|
162
161
|
|
|
163
162
|
export default buildConfig({
|
|
164
|
-
collections: [
|
|
165
|
-
createBrandAssets({
|
|
166
|
-
access: { read: () => true, update: canUseFeature("brand-assets") },
|
|
167
|
-
}),
|
|
168
|
-
],
|
|
163
|
+
collections: [createBrandAssets()],
|
|
169
164
|
globals: [
|
|
170
165
|
createRoles(),
|
|
171
166
|
createFeatures(),
|
|
172
167
|
...createTheme({
|
|
173
|
-
access: { read: isAuthenticated, update: canUseFeature("theme") },
|
|
174
168
|
seed: bisonConfig,
|
|
175
169
|
logo: { collection: BRAND_ASSETS_SLUG },
|
|
176
170
|
identity: {
|
|
@@ -253,10 +247,10 @@ fallback the site passed into `createTheme`. There is no Theme preview pane.
|
|
|
253
247
|
|
|
254
248
|
Logo, favicon, and mobile-menu mark live in a locked cupboard, not in
|
|
255
249
|
ordinary Media. Call `createBrandAssets` and point Theme at
|
|
256
|
-
`BRAND_ASSETS_SLUG`. Access
|
|
257
|
-
|
|
258
|
-
`canUseFeature("
|
|
259
|
-
|
|
250
|
+
`BRAND_ASSETS_SLUG`. Access matches `createTheme`: `read` defaults to
|
|
251
|
+
public so the live site can load the file; `update` defaults to
|
|
252
|
+
`canUseFeature("theme")` and covers create, update, delete, and version
|
|
253
|
+
history.
|
|
260
254
|
SVG preferred, PNG and ICO allowed; an SVG is sanitized on upload.
|
|
261
255
|
Versions stay on so a replaced file can be rolled back.
|
|
262
256
|
|
|
@@ -269,9 +263,8 @@ Settings → Roles is an Admin-editable array. Rank is drag-to-reorder.
|
|
|
269
263
|
Ticks are the catalogue rows released on Features. Developer is
|
|
270
264
|
implicit — every catalogue feature, including ones not released. That
|
|
271
265
|
row is visible only to a Developer, with every tick on and locked.
|
|
272
|
-
Defaults ship in the package (Theme
|
|
273
|
-
|
|
274
|
-
both store). An Admin may remove Admin, Designer, or Author after first
|
|
266
|
+
Defaults ship in the package (the Theme grant on Designer; Designer also
|
|
267
|
+
has Users and Roles; Admin + Designer both store). An Admin may remove Admin, Designer, or Author after first
|
|
275
268
|
run; only Developer stays. A site may pass `extras` into `createRoles` —
|
|
276
269
|
each extra is a slug, a display label, and default `grants` — and an
|
|
277
270
|
Admin can add further custom rows and edit any row’s name. Remaining
|
|
@@ -291,8 +284,9 @@ createRoles({
|
|
|
291
284
|
Settings → Features is a Developer-only release valve: one switch per
|
|
292
285
|
catalogue row. Off hides the tick on Roles; Developer still has the
|
|
293
286
|
feature. The catalogue is code, grouped for the UI: Pages (Content,
|
|
294
|
-
Publish), Media,
|
|
295
|
-
|
|
287
|
+
Publish), Media, and Users (Users, Roles). Theme is not a row. Features
|
|
288
|
+
does not install or remove the Theme Global. Features itself is not a
|
|
289
|
+
row. The
|
|
296
290
|
document API tab and Better Editor overlay settings are not rows either
|
|
297
291
|
— they stay code-locked to Developer (`adminOnlyApiTab`,
|
|
298
292
|
`developerOnlyAccess` / `hideUnlessDeveloper`). A site may pass `extras`
|
|
@@ -309,16 +303,19 @@ createFeatures({
|
|
|
309
303
|
```
|
|
310
304
|
|
|
311
305
|
`canUseFeature(slug)` is true when the row is released and a held role
|
|
312
|
-
is granted it, or when the login is Developer.
|
|
313
|
-
|
|
314
|
-
true when any child is.
|
|
315
|
-
`canUseFeature` for create and update
|
|
316
|
-
|
|
317
|
-
`
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
306
|
+
is granted it, or when the login is Developer. `canUseFeature("theme")`
|
|
307
|
+
is the Roles grant only. An empty Global falls back to the catalogue
|
|
308
|
+
defaults. The group slug `pages` is true when any child is.
|
|
309
|
+
`createPages` / `createMedia` use `canUseFeature` for create and update
|
|
310
|
+
(and `admin.hidden`). `createTheme` and `createBrandAssets` default
|
|
311
|
+
`update` to `canUseFeature("theme")`. That grant opens the Theme
|
|
312
|
+
document and brand-assets. A site may pass `access.read` to tighten
|
|
313
|
+
read. `admin.hidden` is presentation; Access Control is enforcement.
|
|
314
|
+
`hideUnlessFeature("theme")` hides Theme in the nav for a role with no
|
|
315
|
+
grant. `getPublishedTheme` and `themeHead` still return the saved
|
|
316
|
+
document. Nav hiding follows `user.allowedFeatures` on the JWT
|
|
317
|
+
(computed at user read from the live Features and Roles Globals) so
|
|
318
|
+
Payload's `admin.hidden({ user })` matches the API.
|
|
322
319
|
|
|
323
320
|
## Pages, users, and media
|
|
324
321
|
|
package/dist/admin.d.mts
CHANGED
|
@@ -160,9 +160,9 @@ declare const RolesField: SelectFieldClientComponent;
|
|
|
160
160
|
//#endregion
|
|
161
161
|
//#region src/admin/roles-grants-field.d.ts
|
|
162
162
|
/**
|
|
163
|
-
* Released catalogue rows as ticks
|
|
164
|
-
*
|
|
165
|
-
*
|
|
163
|
+
* Released catalogue rows as ticks, plus the Theme grant. Unreleased
|
|
164
|
+
* features do not appear. Theme always does — Features cannot hide it.
|
|
165
|
+
* On Developer every row is shown granted and locked.
|
|
166
166
|
*/
|
|
167
167
|
declare const RolesGrantsField: JSONFieldClientComponent;
|
|
168
168
|
//#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/role-name-field.tsx","../src/admin/roles-field.tsx","../src/admin/roles-grants-field.tsx","../src/admin/features-matrix-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;;;;;;;;;cC2Bf,SAAA,EAAW,wBAAA;;;;;;;iBC1BR,aAAA,CAAc,KAAA,EAAO,yBAAA,GAAyB,kBAAA,CAAA,GAAA,CAAA,OAAA;;;;;;;cCAjD,aAAA,EAAe,wBAAA;;;;;;;;cC8Cf,UAAA,EAAY,0BAAA;;;;;;;;
|
|
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/role-name-field.tsx","../src/admin/roles-field.tsx","../src/admin/roles-grants-field.tsx","../src/admin/features-matrix-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;;;;;;;;;cC2Bf,SAAA,EAAW,wBAAA;;;;;;;iBC1BR,aAAA,CAAc,KAAA,EAAO,yBAAA,GAAyB,kBAAA,CAAA,GAAA,CAAA,OAAA;;;;;;;cCAjD,aAAA,EAAe,wBAAA;;;;;;;;cC8Cf,UAAA,EAAY,0BAAA;;;;;;;;cCpBZ,gBAAA,EAAkB,wBAAA;;;;;;;;;ArBxB/B;;csB2Ca,mBAAA,EAAqB,yBAAA;;;iBChBlB,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;;;A1BGpB;;;iB0B6CgB,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;;;;;;;;A7BClC;U8BFiB,cAAA;;EAEf,MAAA;E9ByED;E8BvEC,IAAA;;EAEA,KAAA;E7BmBW;E6BjBX,MAAA;AAAA;AAAA,UAGe,eAAA;E7BiEhB;E6B/DC,IAAA;;EAEA,KAAA;E5BgBW;E4BdX,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
|
@@ -2648,7 +2648,9 @@ const FEATURE_GROUP_LABELS = {
|
|
|
2648
2648
|
};
|
|
2649
2649
|
/**
|
|
2650
2650
|
* Package catalogue. Features itself is not a row — that screen is
|
|
2651
|
-
* Developer-only in code.
|
|
2651
|
+
* Developer-only in code. Theme is not a row either: every site has the
|
|
2652
|
+
* Theme Global, and who may edit it is the Roles grant `theme`. Empty
|
|
2653
|
+
* Global falls back to these defaults.
|
|
2652
2654
|
*/
|
|
2653
2655
|
const PACKAGE_FEATURES = [
|
|
2654
2656
|
{
|
|
@@ -2669,36 +2671,6 @@ const PACKAGE_FEATURES = [
|
|
|
2669
2671
|
group: "media",
|
|
2670
2672
|
defaultReleased: true
|
|
2671
2673
|
},
|
|
2672
|
-
{
|
|
2673
|
-
slug: "theme-colors",
|
|
2674
|
-
label: "Colors",
|
|
2675
|
-
group: "theme",
|
|
2676
|
-
defaultReleased: true
|
|
2677
|
-
},
|
|
2678
|
-
{
|
|
2679
|
-
slug: "theme-typography",
|
|
2680
|
-
label: "Typography",
|
|
2681
|
-
group: "theme",
|
|
2682
|
-
defaultReleased: true
|
|
2683
|
-
},
|
|
2684
|
-
{
|
|
2685
|
-
slug: "theme-appearance",
|
|
2686
|
-
label: "Appearance",
|
|
2687
|
-
group: "theme",
|
|
2688
|
-
defaultReleased: true
|
|
2689
|
-
},
|
|
2690
|
-
{
|
|
2691
|
-
slug: "theme-identity",
|
|
2692
|
-
label: "Identity",
|
|
2693
|
-
group: "theme",
|
|
2694
|
-
defaultReleased: true
|
|
2695
|
-
},
|
|
2696
|
-
{
|
|
2697
|
-
slug: "brand-assets",
|
|
2698
|
-
label: "Brand assets",
|
|
2699
|
-
group: "theme",
|
|
2700
|
-
defaultReleased: true
|
|
2701
|
-
},
|
|
2702
2674
|
{
|
|
2703
2675
|
slug: "users",
|
|
2704
2676
|
label: "Users",
|
|
@@ -2719,66 +2691,6 @@ function isFeatureSlug(value) {
|
|
|
2719
2691
|
return typeof value === "string" && /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/.test(value);
|
|
2720
2692
|
}
|
|
2721
2693
|
//#endregion
|
|
2722
|
-
//#region src/features/matrix.ts
|
|
2723
|
-
const MISSING_PACKAGE_FEATURES_MESSAGE = "Features must include Content, Publish, Media, Theme screens, Brand assets, Users, and Roles.";
|
|
2724
|
-
function featureCatalogue(extras = []) {
|
|
2725
|
-
return [...PACKAGE_FEATURES.map((feature) => ({ ...feature })), ...extras.map((extra) => ({
|
|
2726
|
-
slug: extra.slug,
|
|
2727
|
-
label: extra.label,
|
|
2728
|
-
group: extra.group ?? "users",
|
|
2729
|
-
defaultReleased: extra.defaultReleased ?? false
|
|
2730
|
-
}))];
|
|
2731
|
-
}
|
|
2732
|
-
function defaultFeaturesFieldValue(extras = []) {
|
|
2733
|
-
return featureCatalogue(extras).map((feature) => ({
|
|
2734
|
-
id: feature.slug,
|
|
2735
|
-
slug: feature.slug,
|
|
2736
|
-
label: feature.label,
|
|
2737
|
-
group: feature.group,
|
|
2738
|
-
released: feature.defaultReleased
|
|
2739
|
-
}));
|
|
2740
|
-
}
|
|
2741
|
-
function parseFeaturesMatrix(value) {
|
|
2742
|
-
if (!Array.isArray(value) || value.length === 0) return {
|
|
2743
|
-
ok: false,
|
|
2744
|
-
message: MISSING_PACKAGE_FEATURES_MESSAGE
|
|
2745
|
-
};
|
|
2746
|
-
const rows = [];
|
|
2747
|
-
const seen = /* @__PURE__ */ new Set();
|
|
2748
|
-
for (const item of value) {
|
|
2749
|
-
if (!item || typeof item !== "object") continue;
|
|
2750
|
-
const slug = "slug" in item ? item.slug : void 0;
|
|
2751
|
-
if (!isFeatureSlug(slug) || seen.has(slug)) continue;
|
|
2752
|
-
seen.add(slug);
|
|
2753
|
-
const pack = PACKAGE_FEATURES.find((feature) => feature.slug === slug);
|
|
2754
|
-
const label = "label" in item && typeof item.label === "string" ? item.label : pack?.label ?? slug;
|
|
2755
|
-
const group = "group" in item && isFeatureGroupId(item.group) ? item.group : pack?.group ?? "users";
|
|
2756
|
-
rows.push({
|
|
2757
|
-
id: slug,
|
|
2758
|
-
slug,
|
|
2759
|
-
label,
|
|
2760
|
-
group,
|
|
2761
|
-
released: Boolean("released" in item && item.released)
|
|
2762
|
-
});
|
|
2763
|
-
}
|
|
2764
|
-
if (PACKAGE_FEATURES.some((feature) => !seen.has(feature.slug))) return {
|
|
2765
|
-
ok: false,
|
|
2766
|
-
message: MISSING_PACKAGE_FEATURES_MESSAGE
|
|
2767
|
-
};
|
|
2768
|
-
return {
|
|
2769
|
-
ok: true,
|
|
2770
|
-
rows
|
|
2771
|
-
};
|
|
2772
|
-
}
|
|
2773
|
-
function featureGroupLabel(group) {
|
|
2774
|
-
return isFeatureGroupId(group) ? FEATURE_GROUP_LABELS[group] : group;
|
|
2775
|
-
}
|
|
2776
|
-
function packageFeatureLabel(slug, extras = []) {
|
|
2777
|
-
const pack = PACKAGE_FEATURES.find((feature) => feature.slug === slug);
|
|
2778
|
-
if (pack) return pack.label;
|
|
2779
|
-
return extras.find((feature) => feature.slug === slug)?.label ?? slug;
|
|
2780
|
-
}
|
|
2781
|
-
//#endregion
|
|
2782
2694
|
//#region src/roles/types.ts
|
|
2783
2695
|
/**
|
|
2784
2696
|
* The Roles Global a site's generated types will describe. Optional and
|
|
@@ -2797,7 +2709,13 @@ const ROLE_LABELS = {
|
|
|
2797
2709
|
designer: "Designer",
|
|
2798
2710
|
author: "Author"
|
|
2799
2711
|
};
|
|
2800
|
-
|
|
2712
|
+
/** One Roles grant. Opens the Theme document and brand-assets. Not a Features row. */
|
|
2713
|
+
const THEME_FEATURE_SLUGS = ["theme"];
|
|
2714
|
+
/**
|
|
2715
|
+
* Grants stored before Theme was one row. Reading any of them is the
|
|
2716
|
+
* Theme grant, so a Designer who already had Colors keeps Theme.
|
|
2717
|
+
*/
|
|
2718
|
+
const LEGACY_THEME_FEATURE_SLUGS = [
|
|
2801
2719
|
"theme-colors",
|
|
2802
2720
|
"theme-typography",
|
|
2803
2721
|
"theme-appearance",
|
|
@@ -2843,11 +2761,72 @@ function defaultGrantsForRole(role, extraGrants) {
|
|
|
2843
2761
|
return extraGrants ? [...extraGrants] : [];
|
|
2844
2762
|
}
|
|
2845
2763
|
//#endregion
|
|
2764
|
+
//#region src/features/matrix.ts
|
|
2765
|
+
const MISSING_PACKAGE_FEATURES_MESSAGE = "Features must include Content, Publish, Media, Users, and Roles.";
|
|
2766
|
+
function featureCatalogue(extras = []) {
|
|
2767
|
+
return [...PACKAGE_FEATURES.map((feature) => ({ ...feature })), ...extras.map((extra) => ({
|
|
2768
|
+
slug: extra.slug,
|
|
2769
|
+
label: extra.label,
|
|
2770
|
+
group: extra.group ?? "users",
|
|
2771
|
+
defaultReleased: extra.defaultReleased ?? false
|
|
2772
|
+
}))];
|
|
2773
|
+
}
|
|
2774
|
+
function defaultFeaturesFieldValue(extras = []) {
|
|
2775
|
+
return featureCatalogue(extras).map((feature) => ({
|
|
2776
|
+
id: feature.slug,
|
|
2777
|
+
slug: feature.slug,
|
|
2778
|
+
label: feature.label,
|
|
2779
|
+
group: feature.group,
|
|
2780
|
+
released: feature.defaultReleased
|
|
2781
|
+
}));
|
|
2782
|
+
}
|
|
2783
|
+
function parseFeaturesMatrix(value) {
|
|
2784
|
+
if (!Array.isArray(value) || value.length === 0) return {
|
|
2785
|
+
ok: false,
|
|
2786
|
+
message: MISSING_PACKAGE_FEATURES_MESSAGE
|
|
2787
|
+
};
|
|
2788
|
+
const rows = [];
|
|
2789
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2790
|
+
for (const item of value) {
|
|
2791
|
+
if (!item || typeof item !== "object") continue;
|
|
2792
|
+
const slug = "slug" in item ? item.slug : void 0;
|
|
2793
|
+
if (!isFeatureSlug(slug) || seen.has(slug)) continue;
|
|
2794
|
+
seen.add(slug);
|
|
2795
|
+
const pack = PACKAGE_FEATURES.find((feature) => feature.slug === slug);
|
|
2796
|
+
const label = "label" in item && typeof item.label === "string" ? item.label : pack?.label ?? slug;
|
|
2797
|
+
const group = "group" in item && isFeatureGroupId(item.group) ? item.group : pack?.group ?? "users";
|
|
2798
|
+
rows.push({
|
|
2799
|
+
id: slug,
|
|
2800
|
+
slug,
|
|
2801
|
+
label,
|
|
2802
|
+
group,
|
|
2803
|
+
released: Boolean("released" in item && item.released)
|
|
2804
|
+
});
|
|
2805
|
+
}
|
|
2806
|
+
if (PACKAGE_FEATURES.some((feature) => !seen.has(feature.slug))) return {
|
|
2807
|
+
ok: false,
|
|
2808
|
+
message: MISSING_PACKAGE_FEATURES_MESSAGE
|
|
2809
|
+
};
|
|
2810
|
+
return {
|
|
2811
|
+
ok: true,
|
|
2812
|
+
rows
|
|
2813
|
+
};
|
|
2814
|
+
}
|
|
2815
|
+
function featureGroupLabel(group) {
|
|
2816
|
+
return isFeatureGroupId(group) ? FEATURE_GROUP_LABELS[group] : group;
|
|
2817
|
+
}
|
|
2818
|
+
function packageFeatureLabel(slug, extras = []) {
|
|
2819
|
+
if (slug === "theme") return "Theme";
|
|
2820
|
+
const pack = PACKAGE_FEATURES.find((feature) => feature.slug === slug);
|
|
2821
|
+
if (pack) return pack.label;
|
|
2822
|
+
return extras.find((feature) => feature.slug === slug)?.label ?? slug;
|
|
2823
|
+
}
|
|
2824
|
+
//#endregion
|
|
2846
2825
|
//#region src/roles/matrix.ts
|
|
2847
2826
|
const ROLES_SLUG = "roles";
|
|
2848
2827
|
/**
|
|
2849
|
-
* Default rank and grants. Developer is implicit (empty grants).
|
|
2850
|
-
*
|
|
2828
|
+
* Default rank and grants. Developer is implicit (empty grants). The
|
|
2829
|
+
* Theme grant defaults to Designer.
|
|
2851
2830
|
*/
|
|
2852
2831
|
const DEFAULT_ROLE_MATRIX = ROLES.map((role) => ({
|
|
2853
2832
|
role,
|
|
@@ -2856,20 +2835,35 @@ const DEFAULT_ROLE_MATRIX = ROLES.map((role) => ({
|
|
|
2856
2835
|
const DEVELOPER_DESCRIPTION = "Everything, including features not released for assignment.";
|
|
2857
2836
|
const MISSING_SEED_ROLES_MESSAGE = "Roles must include Developer.";
|
|
2858
2837
|
const DUPLICATE_ROLE_SLUG_MESSAGE = "Each role needs a unique slug.";
|
|
2838
|
+
const LEGACY_THEME_GRANTS$1 = new Set(LEGACY_THEME_FEATURE_SLUGS);
|
|
2859
2839
|
function uniqueSlugs(values) {
|
|
2860
2840
|
const slugs = [];
|
|
2861
2841
|
for (const value of values) if (typeof value === "string" && isFeatureSlug(value) && !slugs.includes(value)) slugs.push(value);
|
|
2862
2842
|
return slugs;
|
|
2863
2843
|
}
|
|
2844
|
+
/** One Theme grant. A stored Colors or brand-assets tick is that grant. */
|
|
2845
|
+
function collapseThemeGrant(slugs) {
|
|
2846
|
+
let theme = false;
|
|
2847
|
+
const next = [];
|
|
2848
|
+
for (const slug of slugs) {
|
|
2849
|
+
if (slug === "theme" || LEGACY_THEME_GRANTS$1.has(slug)) {
|
|
2850
|
+
theme = true;
|
|
2851
|
+
continue;
|
|
2852
|
+
}
|
|
2853
|
+
next.push(slug);
|
|
2854
|
+
}
|
|
2855
|
+
if (theme) next.push("theme");
|
|
2856
|
+
return next;
|
|
2857
|
+
}
|
|
2864
2858
|
/** Read stored grants, or rebuild them from the old capability ticks. */
|
|
2865
2859
|
function grantsFromStoredRole(item) {
|
|
2866
|
-
if ("grants" in item && Array.isArray(item.grants)) return uniqueSlugs(item.grants);
|
|
2860
|
+
if ("grants" in item && Array.isArray(item.grants)) return collapseThemeGrant(uniqueSlugs(item.grants));
|
|
2867
2861
|
const grants = [];
|
|
2868
2862
|
if ("content" in item && item.content) grants.push("content", "media");
|
|
2869
2863
|
if ("publish" in item && item.publish) grants.push("publish");
|
|
2870
2864
|
if ("users" in item && item.users) grants.push("users", "roles");
|
|
2871
|
-
if ("brand" in item && item.brand) grants.push(
|
|
2872
|
-
return uniqueSlugs(grants);
|
|
2865
|
+
if ("brand" in item && item.brand) grants.push("theme");
|
|
2866
|
+
return collapseThemeGrant(uniqueSlugs(grants));
|
|
2873
2867
|
}
|
|
2874
2868
|
function seedRoleRows(extras = []) {
|
|
2875
2869
|
return [...DEFAULT_ROLE_MATRIX.map((row) => ({
|
|
@@ -3594,19 +3588,29 @@ function asGrants(value) {
|
|
|
3594
3588
|
if (!Array.isArray(value)) return [];
|
|
3595
3589
|
return value.filter((entry) => typeof entry === "string");
|
|
3596
3590
|
}
|
|
3591
|
+
const LEGACY_THEME_GRANTS = new Set(LEGACY_THEME_FEATURE_SLUGS);
|
|
3592
|
+
/** Theme is one tick Features cannot hide. Legacy theme rows are not ticks. */
|
|
3593
|
+
function withThemeGrant(rows) {
|
|
3594
|
+
return [{
|
|
3595
|
+
slug: "theme",
|
|
3596
|
+
label: "Theme",
|
|
3597
|
+
group: "theme",
|
|
3598
|
+
released: true
|
|
3599
|
+
}, ...rows.filter((row) => row.slug !== "theme" && !LEGACY_THEME_GRANTS.has(row.slug))];
|
|
3600
|
+
}
|
|
3597
3601
|
function rolePathFromGrants(path) {
|
|
3598
3602
|
return path.replace(/\.grants$/, ".role");
|
|
3599
3603
|
}
|
|
3600
3604
|
/**
|
|
3601
|
-
* Released catalogue rows as ticks
|
|
3602
|
-
*
|
|
3603
|
-
*
|
|
3605
|
+
* Released catalogue rows as ticks, plus the Theme grant. Unreleased
|
|
3606
|
+
* features do not appear. Theme always does — Features cannot hide it.
|
|
3607
|
+
* On Developer every row is shown granted and locked.
|
|
3604
3608
|
*/
|
|
3605
3609
|
const RolesGrantsField = (props) => {
|
|
3606
3610
|
const { setValue, value } = useField({ path: props.path });
|
|
3607
3611
|
const { value: role } = useField({ path: rolePathFromGrants(props.path) });
|
|
3608
3612
|
const { config } = useConfig();
|
|
3609
|
-
const [catalogue, setCatalogue] = useState(defaultFeaturesFieldValue());
|
|
3613
|
+
const [catalogue, setCatalogue] = useState(withThemeGrant(defaultFeaturesFieldValue()));
|
|
3610
3614
|
const api = config?.routes?.api;
|
|
3611
3615
|
const serverURL = config?.serverURL ?? "";
|
|
3612
3616
|
const implicitAll = role === "developer";
|
|
@@ -3616,7 +3620,7 @@ const RolesGrantsField = (props) => {
|
|
|
3616
3620
|
fetch(`${serverURL}${api}/globals/${FEATURES_SLUG}?depth=0`, { credentials: "include" }).then((response) => response.ok ? response.json() : null).then((doc) => {
|
|
3617
3621
|
if (cancelled || !doc) return;
|
|
3618
3622
|
const parsed = parseFeaturesMatrix(doc.features);
|
|
3619
|
-
if (parsed.ok) setCatalogue(parsed.rows);
|
|
3623
|
+
if (parsed.ok) setCatalogue(withThemeGrant(parsed.rows));
|
|
3620
3624
|
}).catch(() => void 0);
|
|
3621
3625
|
return () => {
|
|
3622
3626
|
cancelled = true;
|
|
@@ -3624,10 +3628,18 @@ const RolesGrantsField = (props) => {
|
|
|
3624
3628
|
}, [api, serverURL]);
|
|
3625
3629
|
const grants = asGrants(value);
|
|
3626
3630
|
const shown = implicitAll ? catalogue : catalogue.filter((row) => row.released);
|
|
3631
|
+
function holds(slug) {
|
|
3632
|
+
if (slug === "theme") return grants.some((entry) => entry === "theme" || LEGACY_THEME_GRANTS.has(entry));
|
|
3633
|
+
return grants.includes(slug);
|
|
3634
|
+
}
|
|
3627
3635
|
function toggle(slug, checked) {
|
|
3628
3636
|
if (implicitAll) return;
|
|
3629
3637
|
const next = new Set(grants);
|
|
3630
|
-
if (
|
|
3638
|
+
if (slug === "theme") {
|
|
3639
|
+
for (const legacy of LEGACY_THEME_GRANTS) next.delete(legacy);
|
|
3640
|
+
if (checked) next.add("theme");
|
|
3641
|
+
else next.delete("theme");
|
|
3642
|
+
} else if (checked) next.add(slug);
|
|
3631
3643
|
else next.delete(slug);
|
|
3632
3644
|
setValue([...next]);
|
|
3633
3645
|
}
|
|
@@ -3656,7 +3668,7 @@ const RolesGrantsField = (props) => {
|
|
|
3656
3668
|
children: [/* @__PURE__ */ jsx("input", {
|
|
3657
3669
|
type: "checkbox",
|
|
3658
3670
|
"aria-label": `${row.label || row.slug}`,
|
|
3659
|
-
checked: implicitAll ||
|
|
3671
|
+
checked: implicitAll || holds(row.slug),
|
|
3660
3672
|
disabled: implicitAll,
|
|
3661
3673
|
onChange: (event) => toggle(row.slug, event.target.checked)
|
|
3662
3674
|
}), /* @__PURE__ */ jsx("span", { children: row.label || row.slug })]
|
|
@@ -3732,7 +3744,7 @@ const FeaturesMatrixField = (props) => {
|
|
|
3732
3744
|
const members = rows.map((row, index) => ({
|
|
3733
3745
|
row,
|
|
3734
3746
|
index
|
|
3735
|
-
})).filter(({ row }) => (row.group ?? "users") === group);
|
|
3747
|
+
})).filter(({ row }) => (row.group ?? "users") === group && row.slug !== "theme" && !LEGACY_THEME_FEATURE_SLUGS.includes(row.slug));
|
|
3736
3748
|
if (members.length === 0) return null;
|
|
3737
3749
|
return /* @__PURE__ */ jsxs("div", {
|
|
3738
3750
|
className: "bl-features__group",
|