@edhspace/api 0.0.0-stage → 0.1.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.
- package/LICENSE +14 -0
- package/README.md +36 -2
- package/dist/chunk-HL56LR6P.cjs +311 -0
- package/dist/chunk-LBLXK5J2.js +311 -0
- package/dist/client-CSAi6AFj.d.ts +136 -0
- package/dist/client-DKX6ZfiJ.d.cts +136 -0
- package/dist/contracts-r8d4RACz.d.cts +474 -0
- package/dist/contracts-r8d4RACz.d.ts +474 -0
- package/dist/host.cjs +356 -0
- package/dist/host.d.cts +57 -0
- package/dist/host.d.ts +57 -0
- package/dist/host.js +356 -0
- package/dist/index.cjs +234 -0
- package/dist/index.d.cts +148 -0
- package/dist/index.d.ts +148 -0
- package/dist/index.js +234 -0
- package/dist/math.cjs +107 -0
- package/dist/math.d.cts +70 -0
- package/dist/math.d.ts +70 -0
- package/dist/math.js +107 -0
- package/dist/react.cjs +69 -0
- package/dist/react.d.cts +177 -0
- package/dist/react.d.ts +177 -0
- package/dist/react.js +69 -0
- package/package.json +76 -5
package/dist/react.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// src/react.tsx
|
|
2
|
+
import {
|
|
3
|
+
createContext,
|
|
4
|
+
useContext,
|
|
5
|
+
useEffect,
|
|
6
|
+
useCallback,
|
|
7
|
+
useRef,
|
|
8
|
+
useState
|
|
9
|
+
} from "react";
|
|
10
|
+
import { jsx } from "react/jsx-runtime";
|
|
11
|
+
var Context = createContext(void 0);
|
|
12
|
+
function ExtensionProvider({
|
|
13
|
+
api,
|
|
14
|
+
revision,
|
|
15
|
+
children
|
|
16
|
+
}) {
|
|
17
|
+
return /* @__PURE__ */ jsx(Context.Provider, { value: { api, revision }, children });
|
|
18
|
+
}
|
|
19
|
+
function useContextValue() {
|
|
20
|
+
const context = useContext(Context);
|
|
21
|
+
if (!context) throw new Error("Render this extension inside an EDHspace ExtensionProvider.");
|
|
22
|
+
return context;
|
|
23
|
+
}
|
|
24
|
+
function useExtension() {
|
|
25
|
+
return useContextValue().api;
|
|
26
|
+
}
|
|
27
|
+
function useResource(load, revision) {
|
|
28
|
+
const generation = useRef(0);
|
|
29
|
+
const [data, setData] = useState();
|
|
30
|
+
const [error, setError] = useState();
|
|
31
|
+
const [loading, setLoading] = useState(true);
|
|
32
|
+
const refresh = useCallback(async () => {
|
|
33
|
+
const current = ++generation.current;
|
|
34
|
+
setLoading(true);
|
|
35
|
+
setError(void 0);
|
|
36
|
+
try {
|
|
37
|
+
const result = await load();
|
|
38
|
+
if (generation.current === current) setData(result);
|
|
39
|
+
} catch (error2) {
|
|
40
|
+
if (generation.current === current)
|
|
41
|
+
setError(
|
|
42
|
+
error2 instanceof Error ? error2 : new Error("Extension data could not be read.")
|
|
43
|
+
);
|
|
44
|
+
} finally {
|
|
45
|
+
if (generation.current === current) setLoading(false);
|
|
46
|
+
}
|
|
47
|
+
}, [load]);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
void refresh();
|
|
50
|
+
return () => {
|
|
51
|
+
generation.current++;
|
|
52
|
+
};
|
|
53
|
+
}, [refresh, revision]);
|
|
54
|
+
return { data, error, loading, refresh };
|
|
55
|
+
}
|
|
56
|
+
function useActiveDeck() {
|
|
57
|
+
const { api, revision } = useContextValue();
|
|
58
|
+
return useResource(api.deck.read, revision);
|
|
59
|
+
}
|
|
60
|
+
function useSelectedCards() {
|
|
61
|
+
const { api, revision } = useContextValue();
|
|
62
|
+
return useResource(api.selection.read, revision);
|
|
63
|
+
}
|
|
64
|
+
export {
|
|
65
|
+
ExtensionProvider,
|
|
66
|
+
useActiveDeck,
|
|
67
|
+
useExtension,
|
|
68
|
+
useSelectedCards
|
|
69
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,77 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@edhspace/api",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"description": "Typed capability API for curated native EDHspace extensions",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/EDHspace/extensions.git",
|
|
11
|
+
"directory": "packages/api"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/EDHspace/extensions/tree/main/packages/api#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/EDHspace/extensions/issues"
|
|
16
|
+
},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public",
|
|
19
|
+
"registry": "https://registry.npmjs.org/"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"exports": {
|
|
26
|
+
"./math": {
|
|
27
|
+
"types": "./dist/math.d.ts",
|
|
28
|
+
"import": "./dist/math.js",
|
|
29
|
+
"require": "./dist/math.cjs"
|
|
30
|
+
},
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"import": "./dist/index.js",
|
|
34
|
+
"require": "./dist/index.cjs"
|
|
35
|
+
},
|
|
36
|
+
"./host": {
|
|
37
|
+
"types": "./dist/host.d.ts",
|
|
38
|
+
"import": "./dist/host.js",
|
|
39
|
+
"require": "./dist/host.cjs"
|
|
40
|
+
},
|
|
41
|
+
"./react": {
|
|
42
|
+
"types": "./dist/react.d.ts",
|
|
43
|
+
"import": "./dist/react.js",
|
|
44
|
+
"require": "./dist/react.cjs"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsup",
|
|
49
|
+
"typecheck": "tsc --noEmit",
|
|
50
|
+
"test": "npm run build && vitest run"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"zod": "^4.6.5"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"react": "^19.0.0"
|
|
57
|
+
},
|
|
58
|
+
"peerDependenciesMeta": {
|
|
59
|
+
"react": {
|
|
60
|
+
"optional": true
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@edhspace/ui": "^0.1.0",
|
|
65
|
+
"@types/node": "^20.10.0",
|
|
66
|
+
"@types/react": "^19.2.18",
|
|
67
|
+
"@types/react-dom": "^19.2.4",
|
|
68
|
+
"react": "^19.2.8",
|
|
69
|
+
"react-dom": "^19.2.8",
|
|
70
|
+
"tsup": "^8.0.0",
|
|
71
|
+
"typescript": "^5.3.3",
|
|
72
|
+
"vitest": "3.2.7"
|
|
73
|
+
},
|
|
74
|
+
"engines": {
|
|
75
|
+
"node": ">=22.12.0"
|
|
76
|
+
}
|
|
77
|
+
}
|