@bison-lab/payload-core 4.12.3 → 4.12.4
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 +8 -0
- package/dist/admin.d.mts +13 -1
- package/dist/admin.d.mts.map +1 -1
- package/dist/admin.mjs +67 -22
- package/dist/admin.mjs.map +1 -1
- package/dist/index.d.mts +18 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +119 -32
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -276,6 +276,14 @@ seed slugs stay read-only.
|
|
|
276
276
|
back to that seed (plus extras). The package never writes `developer`
|
|
277
277
|
onto a user row.
|
|
278
278
|
|
|
279
|
+
Removing a row removes that slug from every user in the same save, so a
|
|
280
|
+
later row saved under the same slug cannot hand it back. A user whose
|
|
281
|
+
only role it was is left with none. A save that would leave no user
|
|
282
|
+
holding Developer or a role with the Users tick is refused
|
|
283
|
+
(`ROLES_LOCKOUT_MESSAGE`), whether by deleting the row or unticking
|
|
284
|
+
Users. `pruneUserRoles(req)` strips every slug not on the saved Global;
|
|
285
|
+
call it once from a migration to clean users saved before this rule.
|
|
286
|
+
|
|
279
287
|
```ts
|
|
280
288
|
createRoles({
|
|
281
289
|
extras: [{ role: "editor", label: "Editor", grants: ["content"] }],
|
package/dist/admin.d.mts
CHANGED
|
@@ -107,6 +107,18 @@ declare const IdentityFallback: UIFieldClientComponent;
|
|
|
107
107
|
*/
|
|
108
108
|
declare const LookField: TextFieldClientComponent;
|
|
109
109
|
//#endregion
|
|
110
|
+
//#region src/admin/roles-cell.d.ts
|
|
111
|
+
/**
|
|
112
|
+
* Users list Roles column. Labels come from the saved Roles Global, the
|
|
113
|
+
* same list the edit field offers, so a renamed role reads its new name
|
|
114
|
+
* and a slug whose row was deleted is not shown at all. Until that loads
|
|
115
|
+
* (or when this login cannot read Roles), the field's seed options stand in.
|
|
116
|
+
*/
|
|
117
|
+
declare function RolesCell({
|
|
118
|
+
cellData,
|
|
119
|
+
field
|
|
120
|
+
}: DefaultCellComponentProps): react_jsx_runtime0.JSX.Element;
|
|
121
|
+
//#endregion
|
|
110
122
|
//#region src/admin/roles-matrix-field.d.ts
|
|
111
123
|
/**
|
|
112
124
|
* Payload's array field: drag rank stays, add is for custom rows.
|
|
@@ -343,5 +355,5 @@ declare function MediaAltAutofill({
|
|
|
343
355
|
//#region src/admin/media-list-view.d.ts
|
|
344
356
|
declare function MediaListView(props: ListViewClientProps): react_jsx_runtime0.JSX.Element;
|
|
345
357
|
//#endregion
|
|
346
|
-
export { AdminNav, AdminNavEntityField, AdminNavItemRowLabel, AdminNavRowLabel, AppearanceField, BlockLibraryField, ColorField, ColorScaleField, ContrastReport, DocumentCreateNew, DocumentTitleActions, FeaturesMatrixField, FontField, GreyScaleField, HiddenSaveButton, IdentityFallback, LibraryField, ListAlignStyles, LookField, MediaAltAutofill, MediaListView, PageSlugCell, PageTitleCell, PairingField, PublishChild, QuestionsList, RequiredPageCell, RequiredPageField, RoleNameField, RoleSlugField, RolesField, RolesGrantsField, RolesMatrixField, RolesRowLabel, SectionHeading, SlugField, ThemeDocumentControls, ThemeSaveButton, setThemePreviewMode };
|
|
358
|
+
export { AdminNav, AdminNavEntityField, AdminNavItemRowLabel, AdminNavRowLabel, AppearanceField, BlockLibraryField, ColorField, ColorScaleField, ContrastReport, DocumentCreateNew, DocumentTitleActions, FeaturesMatrixField, FontField, GreyScaleField, HiddenSaveButton, IdentityFallback, LibraryField, ListAlignStyles, LookField, MediaAltAutofill, MediaListView, PageSlugCell, PageTitleCell, PairingField, PublishChild, QuestionsList, RequiredPageCell, RequiredPageField, RoleNameField, RoleSlugField, RolesCell, RolesField, RolesGrantsField, RolesMatrixField, RolesRowLabel, SectionHeading, SlugField, ThemeDocumentControls, ThemeSaveButton, setThemePreviewMode };
|
|
347
359
|
//# sourceMappingURL=admin.d.mts.map
|
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/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;;;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;;;;;;;;
|
|
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-cell.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,EA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;EAAU,IAAA;AAAA;;;iBCmH7B,aAAA,CAAc,KAAA,EAAO,mBAAA,GAAmB,kBAAA,CAAA,GAAA,CAAA,OAAA"}
|
package/dist/admin.mjs
CHANGED
|
@@ -2951,6 +2951,69 @@ function resetRolesMatrix(current) {
|
|
|
2951
2951
|
return [...defaultRolesFieldValue(), ...extras];
|
|
2952
2952
|
}
|
|
2953
2953
|
//#endregion
|
|
2954
|
+
//#region src/admin/use-live-roles.ts
|
|
2955
|
+
const inFlight = /* @__PURE__ */ new Map();
|
|
2956
|
+
function fetchLiveRoles(url) {
|
|
2957
|
+
const pending = inFlight.get(url);
|
|
2958
|
+
if (pending) return pending;
|
|
2959
|
+
const request = fetch(url, { credentials: "include" }).then((response) => response.ok ? response.json() : null).then((doc) => {
|
|
2960
|
+
if (!doc) return null;
|
|
2961
|
+
const parsed = parseRolesMatrix(doc.roles);
|
|
2962
|
+
return parsed.ok ? roleSelectOptions(parsed.rows) : null;
|
|
2963
|
+
}).catch(() => null).finally(() => {
|
|
2964
|
+
setTimeout(() => inFlight.delete(url), 0);
|
|
2965
|
+
});
|
|
2966
|
+
inFlight.set(url, request);
|
|
2967
|
+
return request;
|
|
2968
|
+
}
|
|
2969
|
+
/**
|
|
2970
|
+
* The saved Roles Global as options, or `null` until it has loaded (or
|
|
2971
|
+
* when this login cannot read it).
|
|
2972
|
+
*/
|
|
2973
|
+
function useLiveRoles() {
|
|
2974
|
+
const { config } = useConfig();
|
|
2975
|
+
const [live, setLive] = useState(null);
|
|
2976
|
+
const api = config?.routes?.api;
|
|
2977
|
+
const serverURL = config?.serverURL ?? "";
|
|
2978
|
+
useEffect(() => {
|
|
2979
|
+
if (!api) return;
|
|
2980
|
+
let cancelled = false;
|
|
2981
|
+
fetchLiveRoles(`${serverURL}${api}/globals/${ROLES_SLUG}?depth=0`).then((options) => {
|
|
2982
|
+
if (!cancelled && options) setLive(options);
|
|
2983
|
+
});
|
|
2984
|
+
return () => {
|
|
2985
|
+
cancelled = true;
|
|
2986
|
+
};
|
|
2987
|
+
}, [api, serverURL]);
|
|
2988
|
+
return live;
|
|
2989
|
+
}
|
|
2990
|
+
//#endregion
|
|
2991
|
+
//#region src/admin/roles-cell.tsx
|
|
2992
|
+
function staticOptions(field) {
|
|
2993
|
+
return ("options" in field && Array.isArray(field.options) ? field.options : []).map((option) => typeof option === "string" ? {
|
|
2994
|
+
value: option,
|
|
2995
|
+
label: option
|
|
2996
|
+
} : {
|
|
2997
|
+
value: String(option.value),
|
|
2998
|
+
label: typeof option.label === "string" ? option.label : String(option.value)
|
|
2999
|
+
});
|
|
3000
|
+
}
|
|
3001
|
+
/**
|
|
3002
|
+
* Users list Roles column. Labels come from the saved Roles Global, the
|
|
3003
|
+
* same list the edit field offers, so a renamed role reads its new name
|
|
3004
|
+
* and a slug whose row was deleted is not shown at all. Until that loads
|
|
3005
|
+
* (or when this login cannot read Roles), the field's seed options stand in.
|
|
3006
|
+
*/
|
|
3007
|
+
function RolesCell({ cellData, field }) {
|
|
3008
|
+
const live = useLiveRoles();
|
|
3009
|
+
const roles = Array.isArray(cellData) ? cellData.filter((role) => typeof role === "string") : [];
|
|
3010
|
+
const options = live ?? staticOptions(field);
|
|
3011
|
+
return /* @__PURE__ */ jsx("span", { children: roles.flatMap((role) => {
|
|
3012
|
+
const option = options.find((entry) => entry.value === role);
|
|
3013
|
+
return option ? [option.label] : [];
|
|
3014
|
+
}).join(", ") });
|
|
3015
|
+
}
|
|
3016
|
+
//#endregion
|
|
2954
3017
|
//#region src/admin/roles-matrix-field.tsx
|
|
2955
3018
|
const HIDE_ROW_CHROME = `.bl-roles-matrix .array-actions__add,.bl-roles-matrix .array-actions__duplicate,.bl-roles-matrix .array-actions__copy{display:none}.bl-roles-matrix .array-field__add-row{display:none}.bl-roles-matrix--hide-developer .array-field__row:has([data-role-seed="developer"]),.bl-roles-matrix--hide-developer .collapsible:has([data-role-seed="developer"]){display:none}.bl-roles-matrix__toolbar{display:flex;justify-content:flex-end;gap:.5rem;margin-block-end:.75rem}.bl-roles-matrix__reset{min-height:2.25rem;padding:.35rem .9rem;border:1px solid var(--theme-elevation-150,#e2e8f0);border-radius:8px;background:transparent;color:inherit;font:inherit;cursor:pointer}body.bl-roles-matrix-seed-menu .array-actions__remove{display:none}`;
|
|
2956
3019
|
function seedRoleFromTrigger(trigger) {
|
|
@@ -3496,25 +3559,6 @@ function optionValue(option) {
|
|
|
3496
3559
|
function optionLabel(option) {
|
|
3497
3560
|
return typeof option === "string" ? option : String(option.label);
|
|
3498
3561
|
}
|
|
3499
|
-
function useOfferedRoles(fallback) {
|
|
3500
|
-
const { config } = useConfig();
|
|
3501
|
-
const [live, setLive] = useState(null);
|
|
3502
|
-
const api = config?.routes?.api;
|
|
3503
|
-
const serverURL = config?.serverURL ?? "";
|
|
3504
|
-
useEffect(() => {
|
|
3505
|
-
if (!api) return;
|
|
3506
|
-
let cancelled = false;
|
|
3507
|
-
fetch(`${serverURL}${api}/globals/${ROLES_SLUG}?depth=0`, { credentials: "include" }).then((response) => response.ok ? response.json() : null).then((doc) => {
|
|
3508
|
-
if (cancelled || !doc) return;
|
|
3509
|
-
const parsed = parseRolesMatrix(doc.roles);
|
|
3510
|
-
if (parsed.ok) setLive(roleSelectOptions(parsed.rows));
|
|
3511
|
-
}).catch(() => void 0);
|
|
3512
|
-
return () => {
|
|
3513
|
-
cancelled = true;
|
|
3514
|
-
};
|
|
3515
|
-
}, [api, serverURL]);
|
|
3516
|
-
return live ?? fallback;
|
|
3517
|
-
}
|
|
3518
3562
|
/**
|
|
3519
3563
|
* Users Roles checklist. Order and labels come from the field options (the
|
|
3520
3564
|
* Roles Global, or the seed plus extras). Copy is `roleDescription`.
|
|
@@ -3522,10 +3566,11 @@ function useOfferedRoles(fallback) {
|
|
|
3522
3566
|
*/
|
|
3523
3567
|
const RolesField = ({ field, path: pathFromProps, readOnly, validate }) => {
|
|
3524
3568
|
const { admin: { description } = {}, label, localized, options = [], required } = field;
|
|
3525
|
-
const
|
|
3569
|
+
const fallback = (options.length ? options : roleSelectOptions()).map((option) => ({
|
|
3526
3570
|
value: optionValue(option),
|
|
3527
3571
|
label: optionLabel(option)
|
|
3528
|
-
}))
|
|
3572
|
+
}));
|
|
3573
|
+
const offered = useLiveRoles() ?? fallback;
|
|
3529
3574
|
const { disabled, errorMessage, path, setValue, showError, value } = useField({
|
|
3530
3575
|
potentiallyStalePath: pathFromProps,
|
|
3531
3576
|
validate: useCallback((value, validationOptions) => {
|
|
@@ -6670,6 +6715,6 @@ function ChevronMark() {
|
|
|
6670
6715
|
});
|
|
6671
6716
|
}
|
|
6672
6717
|
//#endregion
|
|
6673
|
-
export { AdminNav, AdminNavEntityField, AdminNavItemRowLabel, AdminNavRowLabel, AppearanceField, BlockLibraryField, ColorField, ColorScaleField, ContrastReport, DocumentCreateNew, DocumentTitleActions, FeaturesMatrixField, FontField, GreyScaleField, HiddenSaveButton, IdentityFallback, LibraryField, ListAlignStyles, LookField, MediaAltAutofill, MediaListView, PageSlugCell, PageTitleCell, PairingField, PublishChild, QuestionsList, RequiredPageCell, RequiredPageField, RoleNameField, RoleSlugField, RolesField, RolesGrantsField, RolesMatrixField, RolesRowLabel, SectionHeading, SlugField, ThemeDocumentControls, ThemeSaveButton, setThemePreviewMode };
|
|
6718
|
+
export { AdminNav, AdminNavEntityField, AdminNavItemRowLabel, AdminNavRowLabel, AppearanceField, BlockLibraryField, ColorField, ColorScaleField, ContrastReport, DocumentCreateNew, DocumentTitleActions, FeaturesMatrixField, FontField, GreyScaleField, HiddenSaveButton, IdentityFallback, LibraryField, ListAlignStyles, LookField, MediaAltAutofill, MediaListView, PageSlugCell, PageTitleCell, PairingField, PublishChild, QuestionsList, RequiredPageCell, RequiredPageField, RoleNameField, RoleSlugField, RolesCell, RolesField, RolesGrantsField, RolesMatrixField, RolesRowLabel, SectionHeading, SlugField, ThemeDocumentControls, ThemeSaveButton, setThemePreviewMode };
|
|
6674
6719
|
|
|
6675
6720
|
//# sourceMappingURL=admin.mjs.map
|