kizlo 0.23.0 → 0.24.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/dist/package.js +1 -1
- package/dist/react.d.ts +56 -0
- package/dist/react.js +54 -0
- package/package.json +7 -1
package/dist/package.js
CHANGED
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ActiveKizloClient } from "./client.js";
|
|
2
|
+
import * as react0 from "react";
|
|
3
|
+
import { ReactNode } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/react.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* What the context carries. One key today, which is why the hook hands back the object rather than the client itself: a
|
|
9
|
+
* locale, a session or app-wide configuration can join it without changing a signature.
|
|
10
|
+
*/
|
|
11
|
+
type KizloContextValue = {
|
|
12
|
+
/** The app's browser Kizlo client, typed from the procedures that app registered. */
|
|
13
|
+
client: ActiveKizloClient;
|
|
14
|
+
};
|
|
15
|
+
type KizloProviderProps = {
|
|
16
|
+
children: ReactNode;
|
|
17
|
+
/** The app's browser Kizlo client, the callable procedure tree. */
|
|
18
|
+
client: ActiveKizloClient;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Holds the app's browser Kizlo client for the client components below it. Mount it once, above anything that reads it.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* // app/providers.tsx
|
|
26
|
+
* "use client"
|
|
27
|
+
* import { KizloProvider } from "kizlo/react"
|
|
28
|
+
* import { client } from "@/lib/kizlo/client"
|
|
29
|
+
*
|
|
30
|
+
* export function Providers({ children }: { children: React.ReactNode }) {
|
|
31
|
+
* return <KizloProvider client={client}>{children}</KizloProvider>
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare function KizloProvider({
|
|
36
|
+
children,
|
|
37
|
+
client
|
|
38
|
+
}: KizloProviderProps): react0.JSX.Element;
|
|
39
|
+
/**
|
|
40
|
+
* Reads the context, whose `client` is typed from the procedures the app registered, so a call the contract does not
|
|
41
|
+
* carry is a compile error rather than a runtime surprise.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```tsx
|
|
45
|
+
* "use client"
|
|
46
|
+
* import { useKizloContext } from "kizlo/react"
|
|
47
|
+
*
|
|
48
|
+
* function LatestPosts() {
|
|
49
|
+
* const { client } = useKizloContext()
|
|
50
|
+
* // ...
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
declare function useKizloContext(): KizloContextValue;
|
|
55
|
+
//#endregion
|
|
56
|
+
export { KizloContextValue, KizloProvider, KizloProviderProps, useKizloContext };
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { createContext, useContext, useMemo } from "react";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
|
|
7
|
+
//#region src/react.tsx
|
|
8
|
+
const KizloContext = createContext(null);
|
|
9
|
+
/**
|
|
10
|
+
* Holds the app's browser Kizlo client for the client components below it. Mount it once, above anything that reads it.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* // app/providers.tsx
|
|
15
|
+
* "use client"
|
|
16
|
+
* import { KizloProvider } from "kizlo/react"
|
|
17
|
+
* import { client } from "@/lib/kizlo/client"
|
|
18
|
+
*
|
|
19
|
+
* export function Providers({ children }: { children: React.ReactNode }) {
|
|
20
|
+
* return <KizloProvider client={client}>{children}</KizloProvider>
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
function KizloProvider({ children, client }) {
|
|
25
|
+
if (!client) throw new Error("<KizloProvider client={client}> needs the browser client `createKizloClient` returned.");
|
|
26
|
+
const value = useMemo(() => ({ client }), [client]);
|
|
27
|
+
return /* @__PURE__ */ jsx(KizloContext.Provider, {
|
|
28
|
+
value,
|
|
29
|
+
children
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Reads the context, whose `client` is typed from the procedures the app registered, so a call the contract does not
|
|
34
|
+
* carry is a compile error rather than a runtime surprise.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```tsx
|
|
38
|
+
* "use client"
|
|
39
|
+
* import { useKizloContext } from "kizlo/react"
|
|
40
|
+
*
|
|
41
|
+
* function LatestPosts() {
|
|
42
|
+
* const { client } = useKizloContext()
|
|
43
|
+
* // ...
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
function useKizloContext() {
|
|
48
|
+
const value = useContext(KizloContext);
|
|
49
|
+
if (!value) throw new Error("mount <KizloProvider client={client}> from kizlo/react above this component.");
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
export { KizloProvider, useKizloContext };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kizlo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A headless WordPress framework for TypeScript.",
|
|
6
6
|
"keywords": [
|
|
@@ -40,6 +40,12 @@
|
|
|
40
40
|
"default": "./dist/index.js"
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
|
+
"./react": {
|
|
44
|
+
"import": {
|
|
45
|
+
"types": "./dist/react.d.ts",
|
|
46
|
+
"default": "./dist/react.js"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
43
49
|
"./config": {
|
|
44
50
|
"import": {
|
|
45
51
|
"types": "./dist/config.d.ts",
|