@carlonicora/nextjs-jsonapi 1.80.0 → 1.81.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.
@@ -47,7 +47,7 @@ import {
47
47
  TabsList,
48
48
  TabsTrigger,
49
49
  useCurrentUserContext
50
- } from "../chunk-NQV5RDCK.mjs";
50
+ } from "../chunk-FZFJLDJY.mjs";
51
51
  import {
52
52
  getRoleId,
53
53
  getStripePublishableKey
@@ -9199,7 +9199,7 @@ __name(FormCheckbox, "FormCheckbox");
9199
9199
  import dynamic from "next/dynamic";
9200
9200
  import React14 from "react";
9201
9201
  import { jsx as jsx73 } from "react/jsx-runtime";
9202
- var BlockNoteEditor = dynamic(() => import("./BlockNoteEditor-3M5PD3BZ.mjs"), {
9202
+ var BlockNoteEditor = dynamic(() => import("./BlockNoteEditor-DCQA2PNW.mjs"), {
9203
9203
  ssr: false
9204
9204
  });
9205
9205
  var BlockNoteEditorContainer = React14.memo(/* @__PURE__ */ __name(function EditorContainer(props) {
@@ -20874,6 +20874,183 @@ function RbacContainer() {
20874
20874
  }
20875
20875
  __name(RbacContainer, "RbacContainer");
20876
20876
 
20877
+ // src/features/rbac/components/RbacByRoleContainer.tsx
20878
+ import { Loader2Icon as Loader2Icon4 } from "lucide-react";
20879
+ import { useTranslations as useTranslations111 } from "next-intl";
20880
+ import { Fragment as Fragment54, memo as memo3, useCallback as useCallback46, useEffect as useEffect69, useMemo as useMemo34, useRef as useRef34, useState as useState96 } from "react";
20881
+ import { jsx as jsx251, jsxs as jsxs164 } from "react/jsx-runtime";
20882
+ function findToken2(tokens, action) {
20883
+ if (!tokens) return void 0;
20884
+ return tokens.find((t) => t.action === action);
20885
+ }
20886
+ __name(findToken2, "findToken");
20887
+ function cellValue2(tokens, action) {
20888
+ const tok = findToken2(tokens, action);
20889
+ if (!tok) return void 0;
20890
+ return tok.scope;
20891
+ }
20892
+ __name(cellValue2, "cellValue");
20893
+ var CellButton3 = memo3(/* @__PURE__ */ __name(function CellButton4({
20894
+ moduleId,
20895
+ rowKey,
20896
+ action,
20897
+ tokens,
20898
+ isRoleColumn,
20899
+ onOpen
20900
+ }) {
20901
+ const ref = useRef34(null);
20902
+ const value = cellValue2(tokens, action);
20903
+ const handleClick = useCallback46(() => {
20904
+ if (!ref.current) return;
20905
+ onOpen({ moduleId, rowKey, action, isRoleColumn, anchor: ref.current });
20906
+ }, [onOpen, moduleId, rowKey, action, isRoleColumn]);
20907
+ return /* @__PURE__ */ jsx251("div", { ref, children: /* @__PURE__ */ jsx251(RbacPermissionCell, { value, isRoleColumn, onClick: handleClick }) });
20908
+ }, "CellButton"));
20909
+ var ACTION_LABELS2 = {
20910
+ read: "Read",
20911
+ create: "Create",
20912
+ update: "Update",
20913
+ delete: "Delete"
20914
+ };
20915
+ function RbacByRoleContainer() {
20916
+ const t = useTranslations111();
20917
+ const { matrix, modulePaths, loading, error, roleNames, moduleNames, updateCell, clearCell } = useRbacContext();
20918
+ const [selectedRoleId, setSelectedRoleId] = useState96(null);
20919
+ const [activePicker, setActivePicker] = useState96(null);
20920
+ const openPicker = useCallback46((picker) => {
20921
+ setActivePicker(picker);
20922
+ }, []);
20923
+ const closePicker = useCallback46(() => {
20924
+ setActivePicker(null);
20925
+ }, []);
20926
+ const handleSelectRole = useCallback46((id) => {
20927
+ setSelectedRoleId(id);
20928
+ setActivePicker(null);
20929
+ }, []);
20930
+ const sortedRoleIds = useMemo34(() => {
20931
+ if (!roleNames) return [];
20932
+ return Object.keys(roleNames).sort((a, b) => (roleNames[a] ?? a).localeCompare(roleNames[b] ?? b));
20933
+ }, [roleNames]);
20934
+ const sortedModuleIds = useMemo34(() => {
20935
+ if (!matrix) return [];
20936
+ return Object.keys(matrix).sort((a, b) => (moduleNames?.[a] ?? a).localeCompare(moduleNames?.[b] ?? b));
20937
+ }, [matrix, moduleNames]);
20938
+ useEffect69(() => {
20939
+ if (!selectedRoleId && sortedRoleIds.length > 0) {
20940
+ setSelectedRoleId(sortedRoleIds[0]);
20941
+ }
20942
+ }, [selectedRoleId, sortedRoleIds]);
20943
+ const activeValue = useMemo34(() => {
20944
+ if (!activePicker || !matrix) return void 0;
20945
+ const block = matrix[activePicker.moduleId];
20946
+ if (!block) return void 0;
20947
+ const tokens = activePicker.rowKey === "default" ? block.default : block[activePicker.rowKey];
20948
+ return cellValue2(tokens, activePicker.action);
20949
+ }, [activePicker, matrix]);
20950
+ const activeSegments = useMemo34(() => {
20951
+ if (!activePicker) return [];
20952
+ return modulePaths[activePicker.moduleId] ?? [];
20953
+ }, [activePicker, modulePaths]);
20954
+ const handleSetValue = useCallback46(
20955
+ (value) => {
20956
+ if (!activePicker) return;
20957
+ updateCell(activePicker.moduleId, activePicker.rowKey, activePicker.action, value);
20958
+ },
20959
+ [activePicker, updateCell]
20960
+ );
20961
+ const handleClear = useCallback46(() => {
20962
+ if (!activePicker || !activePicker.isRoleColumn) return;
20963
+ clearCell(activePicker.moduleId, activePicker.rowKey, activePicker.action);
20964
+ }, [activePicker, clearCell]);
20965
+ if (loading) {
20966
+ return /* @__PURE__ */ jsx251(RoundPageContainer, { fullWidth: true, children: /* @__PURE__ */ jsx251("div", { className: "flex h-full items-center justify-center", children: /* @__PURE__ */ jsx251(Loader2Icon4, { className: "h-8 w-8 animate-spin text-muted-foreground" }) }) });
20967
+ }
20968
+ if (error) {
20969
+ return /* @__PURE__ */ jsx251(RoundPageContainer, { fullWidth: true, children: /* @__PURE__ */ jsx251("div", { className: "flex h-full items-center justify-center", children: /* @__PURE__ */ jsx251("p", { className: "text-destructive", children: error }) }) });
20970
+ }
20971
+ if (!matrix || !selectedRoleId) return null;
20972
+ return /* @__PURE__ */ jsxs164(RoundPageContainer, { fullWidth: true, forceHeader: true, children: [
20973
+ /* @__PURE__ */ jsxs164("div", { className: "flex h-full w-full", children: [
20974
+ /* @__PURE__ */ jsx251("aside", { className: "w-60 shrink-0 overflow-y-auto border-r bg-muted/20", children: /* @__PURE__ */ jsx251("ul", { className: "py-1", children: sortedRoleIds.map((id) => /* @__PURE__ */ jsx251("li", { children: /* @__PURE__ */ jsx251(
20975
+ "button",
20976
+ {
20977
+ type: "button",
20978
+ onClick: () => handleSelectRole(id),
20979
+ "aria-current": id === selectedRoleId ? "true" : void 0,
20980
+ className: cn(
20981
+ "block w-full px-4 py-1.5 text-left text-sm hover:bg-muted",
20982
+ id === selectedRoleId && "bg-muted font-medium text-foreground",
20983
+ id !== selectedRoleId && "text-muted-foreground"
20984
+ ),
20985
+ children: roleNames?.[id] ?? id
20986
+ }
20987
+ ) }, id)) }) }),
20988
+ /* @__PURE__ */ jsx251("section", { className: "flex-1 overflow-y-auto p-4", children: sortedModuleIds.length > 0 ? /* @__PURE__ */ jsx251("div", { className: "rounded-lg border border-accent bg-card", children: /* @__PURE__ */ jsx251("div", { className: "overflow-x-auto", children: /* @__PURE__ */ jsxs164("table", { className: "w-full text-sm", children: [
20989
+ /* @__PURE__ */ jsx251("thead", { className: "sticky top-0 z-10", children: /* @__PURE__ */ jsxs164("tr", { className: "border-b bg-muted/80 backdrop-blur-sm", children: [
20990
+ /* @__PURE__ */ jsx251("th", { className: "w-40 px-4 py-2 text-left text-xs font-medium text-muted-foreground", children: t("rbac.module") }),
20991
+ ACTION_TYPES.map((action) => /* @__PURE__ */ jsx251(
20992
+ "th",
20993
+ {
20994
+ className: "min-w-28 px-2 py-2 text-center text-xs font-medium text-muted-foreground",
20995
+ children: ACTION_LABELS2[action]
20996
+ },
20997
+ action
20998
+ ))
20999
+ ] }) }),
21000
+ /* @__PURE__ */ jsx251("tbody", { children: sortedModuleIds.map((moduleId) => {
21001
+ const block = matrix[moduleId];
21002
+ if (!block) return null;
21003
+ const defaultTokens = block.default ?? [];
21004
+ const roleTokens = block[selectedRoleId];
21005
+ const moduleLabel = moduleNames?.[moduleId] ?? moduleId;
21006
+ return /* @__PURE__ */ jsxs164(Fragment54, { children: [
21007
+ /* @__PURE__ */ jsx251("tr", { className: "border-b bg-muted/40", children: /* @__PURE__ */ jsx251(
21008
+ "td",
21009
+ {
21010
+ colSpan: ACTION_TYPES.length + 1,
21011
+ className: "px-4 py-1.5 text-xs font-bold text-muted-foreground",
21012
+ children: moduleLabel
21013
+ }
21014
+ ) }),
21015
+ /* @__PURE__ */ jsxs164("tr", { className: "border-b bg-muted/20", children: [
21016
+ /* @__PURE__ */ jsx251("td", { className: "px-4 py-1 text-xs text-muted-foreground", children: t("rbac.defaults") }),
21017
+ ACTION_TYPES.map((action) => /* @__PURE__ */ jsx251("td", { className: "px-2 py-1", children: /* @__PURE__ */ jsx251(RbacPermissionCell, { value: cellValue2(defaultTokens, action) }) }, action))
21018
+ ] }),
21019
+ /* @__PURE__ */ jsxs164("tr", { className: "border-b last:border-b-0", children: [
21020
+ /* @__PURE__ */ jsx251("td", { className: "px-4 py-1 text-xs font-medium text-muted-foreground", children: roleNames?.[selectedRoleId] ?? selectedRoleId }),
21021
+ ACTION_TYPES.map((action) => /* @__PURE__ */ jsx251("td", { className: "px-2 py-1", children: /* @__PURE__ */ jsx251(
21022
+ CellButton3,
21023
+ {
21024
+ moduleId,
21025
+ rowKey: selectedRoleId,
21026
+ action,
21027
+ tokens: roleTokens,
21028
+ isRoleColumn: true,
21029
+ onOpen: openPicker
21030
+ }
21031
+ ) }, action))
21032
+ ] })
21033
+ ] }, moduleId);
21034
+ }) })
21035
+ ] }) }) }) : /* @__PURE__ */ jsx251("p", { className: "text-muted-foreground text-sm", children: t("rbac.select_role_prompt") }) })
21036
+ ] }),
21037
+ /* @__PURE__ */ jsx251(
21038
+ RbacPermissionPicker,
21039
+ {
21040
+ open: !!activePicker,
21041
+ anchor: activePicker?.anchor ?? null,
21042
+ value: activeValue,
21043
+ isRoleColumn: activePicker?.isRoleColumn ?? false,
21044
+ knownSegments: activeSegments,
21045
+ onSetValue: handleSetValue,
21046
+ onClear: activePicker?.isRoleColumn ? handleClear : void 0,
21047
+ onClose: closePicker
21048
+ }
21049
+ )
21050
+ ] });
21051
+ }
21052
+ __name(RbacByRoleContainer, "RbacByRoleContainer");
21053
+
20877
21054
  export {
20878
21055
  JsonApiProvider,
20879
21056
  useJsonApiGet,
@@ -21354,6 +21531,7 @@ export {
21354
21531
  RbacPermissionCell,
21355
21532
  RbacPermissionPicker,
21356
21533
  RbacContainer,
21534
+ RbacByRoleContainer,
21357
21535
  AddUserToRole,
21358
21536
  UserAvatarEditor,
21359
21537
  UserDeleter,
@@ -21379,4 +21557,4 @@ export {
21379
21557
  useOAuthClients,
21380
21558
  useOAuthClient
21381
21559
  };
21382
- //# sourceMappingURL=chunk-NQV5RDCK.mjs.map
21560
+ //# sourceMappingURL=chunk-FZFJLDJY.mjs.map