@matir-js/react 0.1.2 → 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 +5 -3
- package/dist/index.mjs +8 -6
- package/package.json +1 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { MatirCore,
|
|
1
|
+
import { MatirCore, matir, matir as matir$1 } from "@matir-js/core";
|
|
2
2
|
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
3
3
|
|
|
4
4
|
//#region src/matir-context.d.ts
|
|
5
5
|
interface MatirRegister {}
|
|
6
|
-
type Schema = ReturnType<typeof matir.defineSchema>;
|
|
6
|
+
type Schema = ReturnType<typeof matir$1.defineSchema>;
|
|
7
7
|
type RegisteredSchema = MatirRegister extends {
|
|
8
8
|
schema: infer S;
|
|
9
9
|
} ? S extends Schema ? S : Schema : Schema;
|
|
@@ -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;
|
|
@@ -57,5 +59,5 @@ type CanPassThroughProps<S extends CanSubject, A extends CanAction<S>> = CanBase
|
|
|
57
59
|
type CanProps<S extends CanSubject, A extends CanAction<S>> = CanNormalProps<S, A> | CanPassThroughProps<S, A>;
|
|
58
60
|
declare function Can<S extends CanSubject, A extends CanAction<S>>(props: CanProps<S, A>): react_jsx_runtime0.JSX.Element;
|
|
59
61
|
//#endregion
|
|
60
|
-
export { Can, CanRenderProp, MatirCurrentInput, MatirProvider, MatirRegister, RegisteredAbility,
|
|
62
|
+
export { Can, CanRenderProp, MatirCurrentInput, MatirProvider, MatirRegister, RegisteredAbility, matir, useAbility, useCurrent };
|
|
61
63
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { matir, matir as matir$1 } from "@matir-js/core";
|
|
2
2
|
import { createContext, useCallback, useContext, useMemo, useReducer, useState } from "react";
|
|
3
3
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
4
|
-
|
|
5
4
|
//#region src/matir-context.tsx
|
|
6
5
|
const MatirContext = createContext(null);
|
|
7
6
|
function MatirProvider({ children, schema, current: initialCurrent }) {
|
|
8
7
|
const [role, setRole] = useState(null);
|
|
8
|
+
const [permissions, setPermissions] = useState(null);
|
|
9
9
|
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
10
10
|
const { ability, current } = useMemo(() => {
|
|
11
|
-
const instance = matir.createSchema(schema);
|
|
11
|
+
const instance = matir$1.createSchema(schema);
|
|
12
12
|
if (initialCurrent?.role) instance.current.role(initialCurrent.role);
|
|
13
13
|
if (initialCurrent?.permissions) instance.current.permissions(initialCurrent.permissions);
|
|
14
14
|
return instance;
|
|
@@ -19,6 +19,7 @@ function MatirProvider({ children, schema, current: initialCurrent }) {
|
|
|
19
19
|
}, [current]);
|
|
20
20
|
const setCurrentPermissions = useCallback((permissions) => {
|
|
21
21
|
current.permissions(permissions);
|
|
22
|
+
setPermissions(permissions);
|
|
22
23
|
forceUpdate();
|
|
23
24
|
}, [current]);
|
|
24
25
|
const clearAll = useCallback(() => {
|
|
@@ -28,6 +29,7 @@ function MatirProvider({ children, schema, current: initialCurrent }) {
|
|
|
28
29
|
return /* @__PURE__ */ jsx(MatirContext.Provider, {
|
|
29
30
|
value: {
|
|
30
31
|
role,
|
|
32
|
+
permissions,
|
|
31
33
|
ability,
|
|
32
34
|
setCurrentRole,
|
|
33
35
|
setCurrentPermissions,
|
|
@@ -41,6 +43,7 @@ function useCurrent() {
|
|
|
41
43
|
if (!ctx) throw new Error("useAbility must be used within <MatirProvider />");
|
|
42
44
|
return {
|
|
43
45
|
role: ctx.role,
|
|
46
|
+
permissions: ctx.permissions,
|
|
44
47
|
setRole: ctx.setCurrentRole,
|
|
45
48
|
setPermissions: ctx.setCurrentPermissions,
|
|
46
49
|
clearAll: ctx.clearAll
|
|
@@ -51,7 +54,6 @@ function useAbility() {
|
|
|
51
54
|
if (!ctx) throw new Error("useAbility must be used within <MatirProvider />");
|
|
52
55
|
return ctx.ability;
|
|
53
56
|
}
|
|
54
|
-
|
|
55
57
|
//#endregion
|
|
56
58
|
//#region src/can.tsx
|
|
57
59
|
function Can(props) {
|
|
@@ -59,7 +61,7 @@ function Can(props) {
|
|
|
59
61
|
if (props.passThrough) return /* @__PURE__ */ jsx(Fragment, { children: props.children(allowed) });
|
|
60
62
|
return /* @__PURE__ */ jsx(Fragment, { children: allowed ? props.children : props.fallback ?? null });
|
|
61
63
|
}
|
|
62
|
-
|
|
63
64
|
//#endregion
|
|
64
|
-
export { Can, MatirProvider,
|
|
65
|
+
export { Can, MatirProvider, matir, useAbility, useCurrent };
|
|
66
|
+
|
|
65
67
|
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@matir-js/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
@@ -21,8 +21,6 @@
|
|
|
21
21
|
"author": "andrefelipeschulle",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"react": "^19",
|
|
25
|
-
"react-dom": "^19",
|
|
26
24
|
"@matir-js/core": "0.6.0"
|
|
27
25
|
},
|
|
28
26
|
"peerDependencies": {
|