@matir-js/react 0.1.3 → 0.1.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/dist/index.d.mts +2 -0
- package/dist/index.mjs +4 -0
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -16,6 +16,7 @@ type CurrentRole = {
|
|
|
16
16
|
value: string | null;
|
|
17
17
|
description: string | null;
|
|
18
18
|
} | null;
|
|
19
|
+
type CurrentPermissions = Record<string, string[]> | null;
|
|
19
20
|
declare function MatirProvider({
|
|
20
21
|
children,
|
|
21
22
|
schema,
|
|
@@ -27,6 +28,7 @@ declare function MatirProvider({
|
|
|
27
28
|
}): react_jsx_runtime0.JSX.Element;
|
|
28
29
|
declare function useCurrent(): {
|
|
29
30
|
role: CurrentRole;
|
|
31
|
+
permissions: CurrentPermissions;
|
|
30
32
|
setRole: (role: string) => void;
|
|
31
33
|
setPermissions: (permissions: Record<string, string[]>) => void;
|
|
32
34
|
clearAll: () => void;
|
package/dist/index.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { Fragment, jsx } from "react/jsx-runtime";
|
|
|
5
5
|
const MatirContext = createContext(null);
|
|
6
6
|
function MatirProvider({ children, schema, current: initialCurrent }) {
|
|
7
7
|
const [role, setRole] = useState(null);
|
|
8
|
+
const [permissions, setPermissions] = useState(null);
|
|
8
9
|
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
9
10
|
const { ability, current } = useMemo(() => {
|
|
10
11
|
const instance = matir$1.createSchema(schema);
|
|
@@ -18,6 +19,7 @@ function MatirProvider({ children, schema, current: initialCurrent }) {
|
|
|
18
19
|
}, [current]);
|
|
19
20
|
const setCurrentPermissions = useCallback((permissions) => {
|
|
20
21
|
current.permissions(permissions);
|
|
22
|
+
setPermissions(permissions);
|
|
21
23
|
forceUpdate();
|
|
22
24
|
}, [current]);
|
|
23
25
|
const clearAll = useCallback(() => {
|
|
@@ -27,6 +29,7 @@ function MatirProvider({ children, schema, current: initialCurrent }) {
|
|
|
27
29
|
return /* @__PURE__ */ jsx(MatirContext.Provider, {
|
|
28
30
|
value: {
|
|
29
31
|
role,
|
|
32
|
+
permissions,
|
|
30
33
|
ability,
|
|
31
34
|
setCurrentRole,
|
|
32
35
|
setCurrentPermissions,
|
|
@@ -40,6 +43,7 @@ function useCurrent() {
|
|
|
40
43
|
if (!ctx) throw new Error("useAbility must be used within <MatirProvider />");
|
|
41
44
|
return {
|
|
42
45
|
role: ctx.role,
|
|
46
|
+
permissions: ctx.permissions,
|
|
43
47
|
setRole: ctx.setCurrentRole,
|
|
44
48
|
setPermissions: ctx.setCurrentPermissions,
|
|
45
49
|
clearAll: ctx.clearAll
|