@pkhex-everywhere/react 0.2.0 → 0.2.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @pkhex-everywhere/react
2
2
 
3
+ ## 0.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 92c350e: Document the public types, so editors and the API reference describe each type and field.
8
+ - 4fe8568: Require `@pkhex-everywhere/engine` from the matching minor as a peer, instead of any version.
9
+ - 92c350e: Link the READMEs and npm pages to the new documentation site.
10
+ - Updated dependencies [92c350e]
11
+ - Updated dependencies [55b1b68]
12
+ - Updated dependencies [92c350e]
13
+ - @pkhex-everywhere/engine@0.2.1
14
+
3
15
  ## 0.2.0
4
16
 
5
17
  ### Minor Changes
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  React hooks for [`@pkhex-everywhere/engine`](https://www.npmjs.com/package/@pkhex-everywhere/engine). Hooks suspend until their data arrives and refetch when a command changes it.
4
4
 
5
+ **[Documentation](https://arley-space--docs.wawesome.app/docs/guides/react/)** · [API reference](https://arley-space--docs.wawesome.app/docs/reference/react/)
6
+
5
7
  ## Install
6
8
 
7
9
  ```sh
@@ -76,17 +78,6 @@ The Suspense fallback shows the runtime download with `useEngineStatus()`. `<Req
76
78
 
77
79
  CI builds this app from the packed packages and runs it.
78
80
 
79
- ## Hooks that need a save
80
-
81
- Most hooks throw `no-save` when no save is loaded, so render them inside `<RequireGame>`. Hover a hook to see what it needs. A hook that runs without a save fails with a message naming the call and the fix, and the error's `code` stays `no-save`. The same goes for `no-draft`.
82
-
83
- These work without a save:
84
-
85
- - `useEngineStatus()`
86
- - `useEngine()`
87
- - `useLoadedGame()`, where `game` is `null` until a save is loaded
88
- - `useQuery` with `game.get`, `game.version`, `game.blankVersions`, `catalog.names` and the `plugins.*` queries
89
-
90
81
  ## License
91
82
 
92
83
  GPL-3.0-or-later.
@@ -6,11 +6,15 @@ interface EngineContextValue {
6
6
  cache: QueryCache;
7
7
  }
8
8
  interface EngineProviderProps {
9
+ /** The engine the hooks below read from, usually created once with `createEngine()`. */
9
10
  engine: Engine;
11
+ /** Called with `EngineError` rejections nothing else handled, for example to show a toast. */
10
12
  onUnhandledError?: (error: EngineError) => void;
11
13
  children?: ReactNode;
12
14
  }
15
+ /** Gives the hooks below it an engine and a query cache that refetches when a command changes the save. */
13
16
  export declare function EngineProvider({ engine, onUnhandledError, children }: EngineProviderProps): import("react").JSX.Element;
14
17
  export declare function useEngineContext(): EngineContextValue;
18
+ /** The engine from the nearest `EngineProvider`, for any call the hooks don't cover. */
15
19
  export declare function useEngine(): Engine;
16
20
  export {};
@@ -1,4 +1,5 @@
1
1
  import type { ReactNode } from 'react';
2
+ /** Renders `fallback` until a save is loaded, then `children`. Wrap hooks that need a save in it. */
2
3
  export declare function RequireGame({ fallback, children }: {
3
4
  fallback?: ReactNode;
4
5
  children?: ReactNode;
package/dist/index.js CHANGED
@@ -56,6 +56,7 @@ var QueryCache = class {
56
56
  //#region src/EngineProvider.tsx
57
57
  var EngineContext = createContext(null);
58
58
  var reported = /* @__PURE__ */ new WeakSet();
59
+ /** Gives the hooks below it an engine and a query cache that refetches when a command changes the save. */
59
60
  function EngineProvider({ engine, onUnhandledError, children }) {
60
61
  const [cache] = useState(() => new QueryCache());
61
62
  useEffect(() => engine.subscribe(["*"], cache.invalidate), [engine, cache]);
@@ -87,6 +88,7 @@ function useEngineContext() {
87
88
  if (!context) throw new Error("Engine hooks must be used inside an EngineProvider.");
88
89
  return context;
89
90
  }
91
+ /** The engine from the nearest `EngineProvider`, for any call the hooks don't cover. */
90
92
  function useEngine() {
91
93
  return useEngineContext().engine;
92
94
  }
@@ -101,6 +103,10 @@ function explain(name, error) {
101
103
  const fix = fixes[error.code];
102
104
  return fix ? new EngineError(error.code, fix(name)) : error;
103
105
  }
106
+ /**
107
+ * Runs a query by name and suspends until it resolves. Refetches when a command changes a topic the query reads,
108
+ * and keeps showing the previous value while it does.
109
+ */
104
110
  function useQuery(name, ...args) {
105
111
  const { engine, cache } = useEngineContext();
106
112
  const key = JSON.stringify([name, args]);
@@ -114,6 +120,7 @@ function useQuery(name, ...args) {
114
120
  }
115
121
  //#endregion
116
122
  //#region src/useEngineStatus.ts
123
+ /** The engine's boot status. Re-renders as the runtime downloads. Works without a save. */
117
124
  function useEngineStatus() {
118
125
  const engine = useEngine();
119
126
  const read = () => engine.status;
@@ -219,12 +226,14 @@ function useTrainer() {
219
226
  }
220
227
  //#endregion
221
228
  //#region src/RequireGame.tsx
229
+ /** Renders `fallback` until a save is loaded, then `children`. Wrap hooks that need a save in it. */
222
230
  function RequireGame({ fallback = null, children }) {
223
231
  const { game } = useLoadedGame();
224
232
  return game ? children : fallback;
225
233
  }
226
234
  //#endregion
227
235
  //#region src/usePokemonDetails.ts
236
+ /** A Pokémon's editable fields and an `update` that applies a patch to it. Requires a loaded save. */
228
237
  function usePokemonDetails(at) {
229
238
  const engine = useEngine();
230
239
  const details = useQuery("pokemon.details", at);
@@ -1,2 +1,3 @@
1
1
  import type { EngineStatus } from '@pkhex-everywhere/engine';
2
+ /** The engine's boot status. Re-renders as the runtime downloads. Works without a save. */
2
3
  export declare function useEngineStatus(): EngineStatus;
@@ -1,4 +1,5 @@
1
1
  import type { PokemonHandle, PokemonPatch } from '@pkhex-everywhere/engine';
2
+ /** A Pokémon's editable fields and an `update` that applies a patch to it. Requires a loaded save. */
2
3
  export declare function usePokemonDetails(at: PokemonHandle): {
3
4
  details: import("@pkhex-everywhere/engine").EditablePokemon;
4
5
  update: (patch: PokemonPatch) => Promise<void>;
@@ -1,7 +1,13 @@
1
1
  import { type CallName, type EngineClient, type QueryName } from '@pkhex-everywhere/engine';
2
2
  type Lookup<T, Path extends string> = Path extends `${infer Head}.${infer Rest}` ? Head extends keyof T ? Lookup<T[Head], Rest> : never : Path extends keyof T ? T[Path] : never;
3
3
  type CallFunction<Name extends CallName> = Extract<Lookup<EngineClient, Name>, (...args: never[]) => Promise<unknown>>;
4
+ /** The arguments of the call `Name`, such as `[at: PokemonHandle]` for `pokemon.details`. */
4
5
  export type CallArgs<Name extends CallName> = Parameters<CallFunction<Name>>;
6
+ /** What the call `Name` resolves to. */
5
7
  export type CallResult<Name extends CallName> = Awaited<ReturnType<CallFunction<Name>>>;
8
+ /**
9
+ * Runs a query by name and suspends until it resolves. Refetches when a command changes a topic the query reads,
10
+ * and keeps showing the previous value while it does.
11
+ */
6
12
  export declare function useQuery<Name extends QueryName>(name: Name, ...args: CallArgs<Name>): CallResult<Name>;
7
13
  export {};
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@pkhex-everywhere/react",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "React hooks for @pkhex-everywhere/engine.",
5
5
  "license": "GPL-3.0-or-later",
6
+ "homepage": "https://arley-space--docs.wawesome.app/docs/",
6
7
  "repository": {
7
8
  "type": "git",
8
9
  "url": "git+https://github.com/arleypadua/PKHeX.Everywhere.git",
@@ -29,7 +30,7 @@
29
30
  "test": "vitest run"
30
31
  },
31
32
  "peerDependencies": {
32
- "@pkhex-everywhere/engine": "*",
33
+ "@pkhex-everywhere/engine": "^0.2.1",
33
34
  "react": "^19.0.0"
34
35
  },
35
36
  "devDependencies": {