@matir-js/react 0.1.0 → 0.1.2
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 +61 -0
- package/dist/index.mjs +2 -1
- package/package.json +8 -2
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { MatirCore, defineSchema, matir } from "@matir-js/core";
|
|
2
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
3
|
+
|
|
4
|
+
//#region src/matir-context.d.ts
|
|
5
|
+
interface MatirRegister {}
|
|
6
|
+
type Schema = ReturnType<typeof matir.defineSchema>;
|
|
7
|
+
type RegisteredSchema = MatirRegister extends {
|
|
8
|
+
schema: infer S;
|
|
9
|
+
} ? S extends Schema ? S : Schema : Schema;
|
|
10
|
+
type MatirCurrentInput = {
|
|
11
|
+
role?: string;
|
|
12
|
+
permissions?: Record<string, string[]>;
|
|
13
|
+
};
|
|
14
|
+
type RegisteredAbility = ReturnType<typeof MatirCore.createSchema<RegisteredSchema["roles"], RegisteredSchema["actions"], RegisteredSchema["rules"]>>["ability"];
|
|
15
|
+
type CurrentRole = {
|
|
16
|
+
value: string | null;
|
|
17
|
+
description: string | null;
|
|
18
|
+
} | null;
|
|
19
|
+
declare function MatirProvider({
|
|
20
|
+
children,
|
|
21
|
+
schema,
|
|
22
|
+
current: initialCurrent
|
|
23
|
+
}: {
|
|
24
|
+
children: React.ReactNode;
|
|
25
|
+
schema: Schema;
|
|
26
|
+
current?: MatirCurrentInput;
|
|
27
|
+
}): react_jsx_runtime0.JSX.Element;
|
|
28
|
+
declare function useCurrent(): {
|
|
29
|
+
role: CurrentRole;
|
|
30
|
+
setRole: (role: string) => void;
|
|
31
|
+
setPermissions: (permissions: Record<string, string[]>) => void;
|
|
32
|
+
clearAll: () => void;
|
|
33
|
+
};
|
|
34
|
+
declare function useAbility(): RegisteredAbility;
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/can.d.ts
|
|
37
|
+
type CanSubject = Parameters<RegisteredAbility["can"]>[0];
|
|
38
|
+
type CanAction<S extends CanSubject> = Parameters<RegisteredAbility["can"] extends ((subject: S, action: infer A, ...args: any[]) => boolean) ? (subject: S, action: A, ...args: any[]) => boolean : never>[1];
|
|
39
|
+
type CanCondition<S extends CanSubject, A extends CanAction<S>> = Parameters<RegisteredAbility["can"] extends ((subject: S, action: A, condition: infer C, ...args: any[]) => boolean) ? (subject: S, action: A, condition: C, ...args: any[]) => boolean : never>[2];
|
|
40
|
+
type CanRenderProp = (allowed: boolean) => React.ReactNode;
|
|
41
|
+
type CanBaseProps<S extends CanSubject, A extends CanAction<S>> = {
|
|
42
|
+
actions?: A;
|
|
43
|
+
subject: S;
|
|
44
|
+
condition?: CanCondition<S, A>;
|
|
45
|
+
context?: unknown;
|
|
46
|
+
};
|
|
47
|
+
type CanNormalProps<S extends CanSubject, A extends CanAction<S>> = CanBaseProps<S, A> & {
|
|
48
|
+
passThrough?: false;
|
|
49
|
+
children: React.ReactNode;
|
|
50
|
+
fallback?: React.ReactNode;
|
|
51
|
+
};
|
|
52
|
+
type CanPassThroughProps<S extends CanSubject, A extends CanAction<S>> = CanBaseProps<S, A> & {
|
|
53
|
+
passThrough: true;
|
|
54
|
+
children: CanRenderProp;
|
|
55
|
+
fallback?: never;
|
|
56
|
+
};
|
|
57
|
+
type CanProps<S extends CanSubject, A extends CanAction<S>> = CanNormalProps<S, A> | CanPassThroughProps<S, A>;
|
|
58
|
+
declare function Can<S extends CanSubject, A extends CanAction<S>>(props: CanProps<S, A>): react_jsx_runtime0.JSX.Element;
|
|
59
|
+
//#endregion
|
|
60
|
+
export { Can, CanRenderProp, MatirCurrentInput, MatirProvider, MatirRegister, RegisteredAbility, defineSchema, useAbility, useCurrent };
|
|
61
|
+
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@matir-js/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
7
7
|
"files": [
|
|
8
|
-
"dist",
|
|
8
|
+
"dist/index.mjs",
|
|
9
|
+
"dist/index.d.mts",
|
|
9
10
|
"LICENSE",
|
|
10
11
|
"package.json"
|
|
11
12
|
],
|
|
@@ -19,6 +20,11 @@
|
|
|
19
20
|
"keywords": [],
|
|
20
21
|
"author": "andrefelipeschulle",
|
|
21
22
|
"license": "MIT",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"react": "^19",
|
|
25
|
+
"react-dom": "^19",
|
|
26
|
+
"@matir-js/core": "0.6.0"
|
|
27
|
+
},
|
|
22
28
|
"peerDependencies": {
|
|
23
29
|
"react": "^19",
|
|
24
30
|
"react-dom": "^19"
|