@voyantjs/react 0.2.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/README.md +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/provider.d.ts +15 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +19 -0
- package/package.json +54 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
React runtime foundation for Voyant frontend packages. Provides a single shared `VoyantReactProvider` for API configuration used by `@voyantjs/*-react` packages.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,KAAK,aAAa,EAClB,KAAK,uBAAuB,EAC5B,mBAAmB,EACnB,KAAK,wBAAwB,GAC9B,MAAM,eAAe,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { defaultFetcher, useVoyantReactContext, VoyantReactProvider, } from "./provider.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export type VoyantFetcher = (url: string, init?: RequestInit) => Promise<Response>;
|
|
3
|
+
export declare const defaultFetcher: VoyantFetcher;
|
|
4
|
+
export interface VoyantReactContextValue {
|
|
5
|
+
baseUrl: string;
|
|
6
|
+
fetcher: VoyantFetcher;
|
|
7
|
+
}
|
|
8
|
+
export interface VoyantReactProviderProps {
|
|
9
|
+
baseUrl: string;
|
|
10
|
+
fetcher?: VoyantFetcher;
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
}
|
|
13
|
+
export declare function VoyantReactProvider({ baseUrl, fetcher, children }: VoyantReactProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export declare function useVoyantReactContext(): VoyantReactContextValue;
|
|
15
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAiB,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAA;AAE1E,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;AAElF,eAAO,MAAM,cAAc,EAAE,aAIzB,CAAA;AAEJ,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,aAAa,CAAA;CACvB;AAID,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,aAAa,CAAA;IACvB,QAAQ,EAAE,SAAS,CAAA;CACpB;AAED,wBAAgB,mBAAmB,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,wBAAwB,2CAO3F;AAED,wBAAgB,qBAAqB,IAAI,uBAAuB,CAS/D"}
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useContext, useMemo } from "react";
|
|
4
|
+
export const defaultFetcher = (url, init) => fetch(url, {
|
|
5
|
+
credentials: "include",
|
|
6
|
+
...init,
|
|
7
|
+
});
|
|
8
|
+
const VoyantReactContext = createContext(null);
|
|
9
|
+
export function VoyantReactProvider({ baseUrl, fetcher, children }) {
|
|
10
|
+
const value = useMemo(() => ({ baseUrl, fetcher: fetcher ?? defaultFetcher }), [baseUrl, fetcher]);
|
|
11
|
+
return _jsx(VoyantReactContext.Provider, { value: value, children: children });
|
|
12
|
+
}
|
|
13
|
+
export function useVoyantReactContext() {
|
|
14
|
+
const context = useContext(VoyantReactContext);
|
|
15
|
+
if (!context) {
|
|
16
|
+
throw new Error('useVoyantReactContext must be used inside <VoyantReactProvider>. Wrap your app with <VoyantReactProvider baseUrl="/api" />.');
|
|
17
|
+
}
|
|
18
|
+
return context;
|
|
19
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@voyantjs/react",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"license": "FSL-1.1-Apache-2.0",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/voyantjs/voyant.git",
|
|
8
|
+
"directory": "packages/react"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": "./src/index.ts",
|
|
13
|
+
"./provider": "./src/provider.tsx"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc -p tsconfig.json",
|
|
17
|
+
"clean": "rm -rf dist",
|
|
18
|
+
"prepack": "pnpm run build",
|
|
19
|
+
"typecheck": "tsc --noEmit",
|
|
20
|
+
"lint": "biome check src/",
|
|
21
|
+
"test": "vitest run --passWithNoTests"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"react": "^19.0.0",
|
|
25
|
+
"react-dom": "^19.0.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/react": "^19.2.14",
|
|
29
|
+
"@types/react-dom": "^19.2.3",
|
|
30
|
+
"@voyantjs/voyant-typescript-config": "workspace:*",
|
|
31
|
+
"react": "^19.2.4",
|
|
32
|
+
"react-dom": "^19.2.4",
|
|
33
|
+
"typescript": "^6.0.2",
|
|
34
|
+
"vitest": "^4.1.2"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist"
|
|
38
|
+
],
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public",
|
|
41
|
+
"exports": {
|
|
42
|
+
".": {
|
|
43
|
+
"types": "./dist/index.d.ts",
|
|
44
|
+
"import": "./dist/index.js"
|
|
45
|
+
},
|
|
46
|
+
"./provider": {
|
|
47
|
+
"types": "./dist/provider.d.ts",
|
|
48
|
+
"import": "./dist/provider.js"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"main": "./dist/index.js",
|
|
52
|
+
"types": "./dist/index.d.ts"
|
|
53
|
+
}
|
|
54
|
+
}
|