@forgebook/react 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.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +40 -2
  3. package/dist/src/StoryErrorBoundary.d.ts +59 -0
  4. package/dist/src/StoryErrorBoundary.d.ts.map +1 -0
  5. package/dist/src/StoryErrorBoundary.js +59 -0
  6. package/dist/src/StoryErrorBoundary.js.map +1 -0
  7. package/dist/src/clock.d.ts +26 -0
  8. package/dist/src/clock.d.ts.map +1 -0
  9. package/dist/src/clock.js +30 -0
  10. package/dist/src/clock.js.map +1 -0
  11. package/dist/src/mountFrame.d.ts +15 -0
  12. package/dist/src/mountFrame.d.ts.map +1 -0
  13. package/dist/src/mountFrame.js +16 -0
  14. package/dist/src/mountFrame.js.map +1 -0
  15. package/dist/src/reactRenderer.d.ts +15 -0
  16. package/dist/src/reactRenderer.d.ts.map +1 -0
  17. package/dist/src/reactRenderer.js +79 -0
  18. package/dist/src/reactRenderer.js.map +1 -0
  19. package/dist/src/stories.d.ts +49 -0
  20. package/dist/src/stories.d.ts.map +1 -0
  21. package/dist/src/stories.js +1 -0
  22. package/dist/src/stories.js.map +1 -0
  23. package/dist/src/storyElement.d.ts +19 -0
  24. package/dist/src/storyElement.d.ts.map +1 -0
  25. package/dist/src/storyElement.js +39 -0
  26. package/dist/src/storyElement.js.map +1 -0
  27. package/dist/src/storyJsx.d.ts +24 -0
  28. package/dist/src/storyJsx.d.ts.map +1 -0
  29. package/dist/src/storyJsx.js +48 -0
  30. package/dist/src/storyJsx.js.map +1 -0
  31. package/dist/src/texts.d.ts +21 -0
  32. package/dist/src/texts.d.ts.map +1 -0
  33. package/dist/src/texts.js +22 -0
  34. package/dist/src/texts.js.map +1 -0
  35. package/dist/src/vite/extractDocs.d.ts +19 -0
  36. package/dist/src/vite/extractDocs.d.ts.map +1 -0
  37. package/dist/src/vite/extractDocs.js +439 -0
  38. package/dist/src/vite/extractDocs.js.map +1 -0
  39. package/dist/src/vite/react.d.ts +10 -0
  40. package/dist/src/vite/react.d.ts.map +1 -0
  41. package/dist/src/vite/react.js +33 -0
  42. package/dist/src/vite/react.js.map +1 -0
  43. package/package.json +82 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ensiria
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,41 @@
1
- # Temporary Holding Version
1
+ # @forgebook/react
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ React for [Forgebook](https://www.npmjs.com/package/forgebook): the story types, the renderer the frame mounts a story
4
+ with, and the adapter that reads a React component's props from its TypeScript types.
5
+
6
+ **Requirements:** React 18.2 or 19 · `forgebook` · Vite 8 · [MIT licence](https://github.com/Ensiria/forgebook/blob/develop/packages/react/LICENSE)
7
+
8
+ ```sh
9
+ npm install --save-dev forgebook @forgebook/react
10
+ ```
11
+
12
+ The catalogue's configuration names it as its framework:
13
+
14
+ ```ts
15
+ // forgebook.config.ts
16
+ import { react } from "@forgebook/react/vite";
17
+ import { defineConfig } from "forgebook";
18
+
19
+ export default defineConfig({ framework: react(), title: "My components", stories: ["src/**/*.stories.tsx"] });
20
+ ```
21
+
22
+ and the stories take their types from it:
23
+
24
+ ```tsx
25
+ import type { Meta, Story } from "@forgebook/react";
26
+
27
+ import { Badge } from "./Badge";
28
+
29
+ export default { title: "Components/Badge", component: Badge } satisfies Meta<typeof Badge>;
30
+
31
+ export const Default: Story<typeof Badge> = { args: { label: "New" } };
32
+ ```
33
+
34
+ | Import | What it is |
35
+ |---|---|
36
+ | `@forgebook/react` | `Meta`, `Story`, `Decorator`, `Preview`: CSF 3 typed for React, the args from the component's props |
37
+ | `@forgebook/react/vite` | `react()`, the framework adapter of `forgebook.config.ts` |
38
+ | `@forgebook/react/texts`, `@forgebook/react/clock` | A story's texts in the catalogue's language, and the story clock, as hooks |
39
+
40
+ The rest of its exports are what the catalogue loads itself. Getting started, the catalogue's features and its
41
+ commands: [Forgebook's README](https://github.com/Ensiria/forgebook/blob/develop/packages/forgebook/README.md).
@@ -0,0 +1,59 @@
1
+ /**
2
+ * The boundary around a story: an error thrown while the story renders goes to the frame, which shows it with its
3
+ * stack and reports it, instead of leaving an empty frame that never says it is ready.
4
+ *
5
+ * @remarks
6
+ * React catches render errors only in a class component (`getDerivedStateFromError`), so this is the package's one
7
+ * class. While the error stands it draws nothing: the frame draws the error, the same for every framework. A new
8
+ * `resetKey` (the story's args, changed by the props panel or Replay) clears the error and renders the story again,
9
+ * so a value that made it throw can be changed back.
10
+ *
11
+ * @module
12
+ */
13
+ import { Component, type ErrorInfo, type ReactNode } from "react";
14
+ /** The boundary's props. */
15
+ export type StoryErrorBoundaryProps = {
16
+ /** The story. */
17
+ readonly children: ReactNode;
18
+ /** Renders the story again after an error when it changes. */
19
+ readonly resetKey: unknown;
20
+ /** Called once with the error when the story fails to render. */
21
+ readonly onError: (error: Error) => void;
22
+ };
23
+ /** Whether the story threw. */
24
+ type StoryErrorBoundaryState = {
25
+ readonly hasError: boolean;
26
+ };
27
+ /** The boundary. */
28
+ export declare class StoryErrorBoundary extends Component<StoryErrorBoundaryProps, StoryErrorBoundaryState> {
29
+ /** No error at first. */
30
+ state: StoryErrorBoundaryState;
31
+ /**
32
+ * Whether the standing error was handed to the frame: React may catch the same failure twice (it renders the tree
33
+ * again before giving up), and the frame hears of each error once.
34
+ */
35
+ private isReported;
36
+ /**
37
+ * Notes the error, so the next render draws nothing.
38
+ *
39
+ * @returns the state with the error.
40
+ */
41
+ static getDerivedStateFromError(): StoryErrorBoundaryState;
42
+ /**
43
+ * Hands the error to the frame.
44
+ *
45
+ * @param error - what the story threw.
46
+ * @param _info - React's component stack, which the error's own stack already covers.
47
+ */
48
+ componentDidCatch(error: unknown, _info: ErrorInfo): void;
49
+ /**
50
+ * Clears the error when the story's args change.
51
+ *
52
+ * @param previous - the props before the change.
53
+ */
54
+ componentDidUpdate(previous: StoryErrorBoundaryProps): void;
55
+ /** The story, or nothing while its error stands. */
56
+ render(): ReactNode;
57
+ }
58
+ export {};
59
+ //# sourceMappingURL=StoryErrorBoundary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StoryErrorBoundary.d.ts","sourceRoot":"","sources":["../../src/StoryErrorBoundary.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,SAAS,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAElE,4BAA4B;AAC5B,MAAM,MAAM,uBAAuB,GAAG;IACpC,iBAAiB;IACjB,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAC7B,8DAA8D;IAC9D,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,iEAAiE;IACjE,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAC1C,CAAC;AAEF,+BAA+B;AAC/B,KAAK,uBAAuB,GAAG;IAAE,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAC;AAE9D,oBAAoB;AACpB,qBAAa,kBAAmB,SAAQ,SAAS,CAAC,uBAAuB,EAAE,uBAAuB,CAAC;IACjG,yBAAyB;IAChB,KAAK,EAAE,uBAAuB,CAAuB;IAE9D;;;OAGG;IACH,OAAO,CAAC,UAAU,CAAS;IAE3B;;;;OAIG;IACH,MAAM,CAAC,wBAAwB,IAAI,uBAAuB;IAI1D;;;;;OAKG;IACM,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI;IAMlE;;;;OAIG;IACM,kBAAkB,CAAC,QAAQ,EAAE,uBAAuB,GAAG,IAAI;IAOpE,oDAAoD;IAC3C,MAAM,IAAI,SAAS;CAG7B"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * The boundary around a story: an error thrown while the story renders goes to the frame, which shows it with its
3
+ * stack and reports it, instead of leaving an empty frame that never says it is ready.
4
+ *
5
+ * @remarks
6
+ * React catches render errors only in a class component (`getDerivedStateFromError`), so this is the package's one
7
+ * class. While the error stands it draws nothing: the frame draws the error, the same for every framework. A new
8
+ * `resetKey` (the story's args, changed by the props panel or Replay) clears the error and renders the story again,
9
+ * so a value that made it throw can be changed back.
10
+ *
11
+ * @module
12
+ */
13
+ import { Component } from "react";
14
+ /** The boundary. */
15
+ export class StoryErrorBoundary extends Component {
16
+ /** No error at first. */
17
+ state = { hasError: false };
18
+ /**
19
+ * Whether the standing error was handed to the frame: React may catch the same failure twice (it renders the tree
20
+ * again before giving up), and the frame hears of each error once.
21
+ */
22
+ isReported = false;
23
+ /**
24
+ * Notes the error, so the next render draws nothing.
25
+ *
26
+ * @returns the state with the error.
27
+ */
28
+ static getDerivedStateFromError() {
29
+ return { hasError: true };
30
+ }
31
+ /**
32
+ * Hands the error to the frame.
33
+ *
34
+ * @param error - what the story threw.
35
+ * @param _info - React's component stack, which the error's own stack already covers.
36
+ */
37
+ componentDidCatch(error, _info) {
38
+ if (this.isReported)
39
+ return;
40
+ this.isReported = true;
41
+ this.props.onError(error instanceof Error ? error : new Error(String(error)));
42
+ }
43
+ /**
44
+ * Clears the error when the story's args change.
45
+ *
46
+ * @param previous - the props before the change.
47
+ */
48
+ componentDidUpdate(previous) {
49
+ if (this.state.hasError && previous.resetKey !== this.props.resetKey) {
50
+ this.isReported = false;
51
+ this.setState({ hasError: false });
52
+ }
53
+ }
54
+ /** The story, or nothing while its error stands. */
55
+ render() {
56
+ return this.state.hasError ? null : this.props.children;
57
+ }
58
+ }
59
+ //# sourceMappingURL=StoryErrorBoundary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StoryErrorBoundary.js","sourceRoot":"","sources":["../../src/StoryErrorBoundary.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,SAAS,EAAkC,MAAM,OAAO,CAAC;AAelE,oBAAoB;AACpB,MAAM,OAAO,kBAAmB,SAAQ,SAA2D;IACjG,yBAAyB;IAChB,KAAK,GAA4B,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;IAE9D;;;OAGG;IACK,UAAU,GAAG,KAAK,CAAC;IAE3B;;;;OAIG;IACH,MAAM,CAAC,wBAAwB;QAC7B,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC5B,CAAC;IAED;;;;;OAKG;IACM,iBAAiB,CAAC,KAAc,EAAE,KAAgB;QACzD,IAAI,IAAI,CAAC,UAAU;YAAE,OAAO;QAC5B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAChF,CAAC;IAED;;;;OAIG;IACM,kBAAkB,CAAC,QAAiC;QAC3D,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,IAAI,QAAQ,CAAC,QAAQ,KAAK,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;YACrE,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;YACxB,IAAI,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;IAED,oDAAoD;IAC3C,MAAM;QACb,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;IAC1D,CAAC;CACF"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The story clock for React components inside a story: the clock the catalogue runs, held at the Unix epoch outside a
3
+ * catalogue (D-504).
4
+ *
5
+ * @remarks
6
+ * The clock itself is the format's (`@forgebook/story-format/clock`); this module is how a React component reads it.
7
+ * The frame's renderer provides it (`reactRenderer.tsx`).
8
+ *
9
+ * @module
10
+ */
11
+ import { type StoryClock } from "@forgebook/story-format/clock";
12
+ /** The story clock of the frame: held at the Unix epoch outside a catalogue. */
13
+ export declare const StoryClockContext: import("react").Context<StoryClock>;
14
+ /**
15
+ * The story's clock, for a component inside a story.
16
+ *
17
+ * @returns the clock the catalogue runs for the story.
18
+ */
19
+ export declare const useStoryClock: () => StoryClock;
20
+ /**
21
+ * The story's current moment, drawn again at each tick of the clock.
22
+ *
23
+ * @returns the moment, in milliseconds since the Unix epoch.
24
+ */
25
+ export declare const useStoryNow: () => number;
26
+ //# sourceMappingURL=clock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clock.d.ts","sourceRoot":"","sources":["../../src/clock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAkB,KAAK,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAGhF,gFAAgF;AAChF,eAAO,MAAM,iBAAiB,qCAA+C,CAAC;AAE9E;;;;GAIG;AACH,eAAO,MAAM,aAAa,QAAO,UAA2C,CAAC;AAE7E;;;;GAIG;AACH,eAAO,MAAM,WAAW,QAAO,MAG9B,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The story clock for React components inside a story: the clock the catalogue runs, held at the Unix epoch outside a
3
+ * catalogue (D-504).
4
+ *
5
+ * @remarks
6
+ * The clock itself is the format's (`@forgebook/story-format/clock`); this module is how a React component reads it.
7
+ * The frame's renderer provides it (`reactRenderer.tsx`).
8
+ *
9
+ * @module
10
+ */
11
+ import { heldStoryClock } from "@forgebook/story-format/clock";
12
+ import { createContext, useContext, useSyncExternalStore } from "react";
13
+ /** The story clock of the frame: held at the Unix epoch outside a catalogue. */
14
+ export const StoryClockContext = createContext(heldStoryClock(0));
15
+ /**
16
+ * The story's clock, for a component inside a story.
17
+ *
18
+ * @returns the clock the catalogue runs for the story.
19
+ */
20
+ export const useStoryClock = () => useContext(StoryClockContext);
21
+ /**
22
+ * The story's current moment, drawn again at each tick of the clock.
23
+ *
24
+ * @returns the moment, in milliseconds since the Unix epoch.
25
+ */
26
+ export const useStoryNow = () => {
27
+ const clock = useStoryClock();
28
+ return useSyncExternalStore(clock.subscribe, clock.now, clock.now);
29
+ };
30
+ //# sourceMappingURL=clock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clock.js","sourceRoot":"","sources":["../../src/clock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,cAAc,EAAmB,MAAM,+BAA+B,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAExE,gFAAgF;AAChF,MAAM,CAAC,MAAM,iBAAiB,GAAG,aAAa,CAAa,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;AAE9E;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,GAAe,EAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC;AAE7E;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,GAAW,EAAE;IACtC,MAAM,KAAK,GAAG,aAAa,EAAE,CAAC;IAC9B,OAAO,oBAAoB,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;AACrE,CAAC,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The frame page of a React catalogue: Forgebook's frame, drawing its stories with React. Called by the page the
3
+ * plugin generates from the catalogue's configuration, not by an app.
4
+ *
5
+ * @module
6
+ */
7
+ import { type FrameConfig } from "forgebook/frame";
8
+ /**
9
+ * Shows the story the address names in the given element, drawn with React.
10
+ *
11
+ * @param container - the element the story renders into.
12
+ * @param config - the sources and the languages, as the shell's configuration gives them.
13
+ */
14
+ export declare const mountFrame: (container: HTMLElement, config: Omit<FrameConfig, "renderer">) => Promise<void>;
15
+ //# sourceMappingURL=mountFrame.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mountFrame.d.ts","sourceRoot":"","sources":["../../src/mountFrame.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,KAAK,WAAW,EAAqC,MAAM,iBAAiB,CAAC;AAItF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,WAAW,WAAW,EAAE,QAAQ,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,KAAG,OAAO,CAAC,IAAI,CAC/B,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The frame page of a React catalogue: Forgebook's frame, drawing its stories with React. Called by the page the
3
+ * plugin generates from the catalogue's configuration, not by an app.
4
+ *
5
+ * @module
6
+ */
7
+ import { mountFrame as mountForgebookFrame } from "forgebook/frame";
8
+ import { reactRenderer } from "./reactRenderer.js";
9
+ /**
10
+ * Shows the story the address names in the given element, drawn with React.
11
+ *
12
+ * @param container - the element the story renders into.
13
+ * @param config - the sources and the languages, as the shell's configuration gives them.
14
+ */
15
+ export const mountFrame = (container, config) => mountForgebookFrame(container, { ...config, renderer: reactRenderer });
16
+ //# sourceMappingURL=mountFrame.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mountFrame.js","sourceRoot":"","sources":["../../src/mountFrame.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAoB,UAAU,IAAI,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtF,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAqB,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,SAAsB,EAAE,MAAqC,EAAiB,EAAE,CACzG,mBAAmB,CAAC,SAAS,EAAE,EAAE,GAAG,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAC,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Forgebook's renderer for React: draws a story in a canvas with a React root of its own, inside the texts' and the
3
+ * clock's providers and the catalogue's decorators, and catches what the story throws.
4
+ *
5
+ * @remarks
6
+ * The frame runs everything else the same for every framework (`forgebook/renderer`): the play function, Replay, the
7
+ * matrix, the error shown in place of the story. Drawing again with other args keeps the story's state; the frame
8
+ * mounts it anew when a story must start over.
9
+ *
10
+ * @module
11
+ */
12
+ import type { StoryRenderer } from "forgebook/renderer";
13
+ /** React as the frame draws with it. */
14
+ export declare const reactRenderer: StoryRenderer;
15
+ //# sourceMappingURL=reactRenderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactRenderer.d.ts","sourceRoot":"","sources":["../../src/reactRenderer.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,KAAK,EAA8B,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAkEpF,wCAAwC;AACxC,eAAO,MAAM,aAAa,EAAE,aAuC3B,CAAC"}
@@ -0,0 +1,79 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { storyTextOf } from "@forgebook/story-format/texts";
3
+ import { untracedStep } from "forgebook/renderer";
4
+ import { useEffect, useRef } from "react";
5
+ import { createRoot } from "react-dom/client";
6
+ import { renderToString } from "react-dom/server";
7
+ import { StoryClockContext } from "./clock.js";
8
+ import { StoryErrorBoundary } from "./StoryErrorBoundary.js";
9
+ import { storyElement } from "./storyElement.js";
10
+ import { StoryTextsContext } from "./texts.js";
11
+ /**
12
+ * The story in the texts' and the clock's providers; the language's provider is a decorator of the catalogue's
13
+ * preview, inside these.
14
+ *
15
+ * @param drawing - the story's texts and clock.
16
+ * @param story - the story's element, to wrap.
17
+ */
18
+ const inProviders = (drawing, story) => (_jsx(StoryTextsContext.Provider, { value: drawing.texts, children: _jsx(StoryClockContext.Provider, { value: drawing.clock, children: story }) }));
19
+ /**
20
+ * What a render and a decorator receive.
21
+ *
22
+ * @param drawing - the story's args, texts, clock and switches' values.
23
+ * @param canvasOf - the element the story is drawn in, read only when a story asks for it: on the server there is
24
+ * none, and a story that reads it there fails as it would in a page rendered on the server.
25
+ */
26
+ const contextOf = (drawing, canvasOf) => ({
27
+ args: drawing.args,
28
+ step: untracedStep,
29
+ text: storyTextOf(drawing.texts),
30
+ clock: drawing.clock,
31
+ globals: drawing.globals,
32
+ loaded: drawing.loaded,
33
+ ...drawing.identity,
34
+ parameters: drawing.story.parameters,
35
+ get canvasElement() {
36
+ return canvasOf();
37
+ }
38
+ });
39
+ /**
40
+ * The story, telling once that it is drawn: its effect runs after React put it in the page, and does not run when the
41
+ * story threw.
42
+ *
43
+ * @param props - the story's element and what to call once it is drawn.
44
+ */
45
+ const Drawn = ({ children, onDrawn }) => {
46
+ const drawnRef = useRef(onDrawn);
47
+ useEffect(() => {
48
+ drawnRef.current();
49
+ }, []);
50
+ return children;
51
+ };
52
+ /** React as the frame draws with it. */
53
+ export const reactRenderer = {
54
+ mount: (canvas, first, onError) => {
55
+ const root = createRoot(canvas);
56
+ let markDrawn = () => undefined;
57
+ const drawn = new Promise((resolve) => {
58
+ markDrawn = resolve;
59
+ });
60
+ let drawing = first;
61
+ const draw = () => {
62
+ root.render(inProviders(drawing, _jsx(StoryErrorBoundary, { resetKey: drawing.args, onError: onError, children: _jsx(Drawn, { onDrawn: markDrawn, children: storyElement(drawing.story, contextOf(drawing, () => canvas), drawing.decorators) }) })));
63
+ };
64
+ draw();
65
+ return {
66
+ drawn,
67
+ update: (next) => {
68
+ drawing = next;
69
+ draw();
70
+ },
71
+ unmount: () => root.unmount()
72
+ };
73
+ },
74
+ renderToString: (drawing) => {
75
+ const context = contextOf(drawing, () => document.body);
76
+ return renderToString(inProviders(drawing, storyElement(drawing.story, context, drawing.decorators)));
77
+ }
78
+ };
79
+ //# sourceMappingURL=reactRenderer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactRenderer.js","sourceRoot":"","sources":["../../src/reactRenderer.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAkB,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAA0B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C;;;;;;GAMG;AACH,MAAM,WAAW,GAAG,CAAC,OAAqB,EAAE,KAAgB,EAAa,EAAE,CAAC,CAC1E,KAAC,iBAAiB,CAAC,QAAQ,IAAC,KAAK,EAAE,OAAO,CAAC,KAAK,YAC9C,KAAC,iBAAiB,CAAC,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B,MAAM,IAAI,GAAG,GAAS,EAAE;YACtB,IAAI,CAAC,MAAM,CACT,WAAW,CACT,OAAO,EAEP,KAAC,kBAAkB,IAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,YAC1D,KAAC,KAAK,IAAC,OAAO,EAAE,SAAS,YACtB,YAAY,CACX,OAAO,CAAC,KAAK,EACb,SAAS,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,EAChC,OAAO,CAAC,UAAU,CACnB,GACK,GACW,CACtB,CACF,CAAC;QACJ,CAAC,CAAC;QACF,IAAI,EAAE,CAAC;QACP,OAAO;YACL,KAAK;YACL,MAAM,EAAE,CAAC,IAAkB,EAAQ,EAAE;gBACnC,OAAO,GAAG,IAAI,CAAC;gBACf,IAAI,EAAE,CAAC;YACT,CAAC;YACD,OAAO,EAAE,GAAS,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE;SACpC,CAAC;IACJ,CAAC;IACD,cAAc,EAAE,CAAC,OAAqB,EAAU,EAAE;QAChD,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACxD,OAAO,cAAc,CAAC,WAAW,CAAC,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IACxG,CAAC;CACF,CAAC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * The story types for React: what a story file of a React library is written with
3
+ * (`import type { Meta, Story } from "@forgebook/react"`).
4
+ *
5
+ * @remarks
6
+ * The format's types (`@forgebook/story-format/csf`) are generic over a framework; these name them for React, so a
7
+ * meta writes `satisfies Meta<typeof Button>` and its stories' args are the component's props, a prop that takes a
8
+ * text also as `storyText("key")`. Types only: a library that writes stories depends on this package, never on the
9
+ * catalogue that shows them (D-438).
10
+ *
11
+ * @module
12
+ */
13
+ import type { Decorator as CsfDecorator, CsfMeta, CsfPreview, CsfStory, WrittenArg } from "@forgebook/story-format/csf";
14
+ import type { ReactNode } from "react";
15
+ /**
16
+ * Any function component (the library writes no class components); the props are what the stories' args fill in.
17
+ * Its parameter is `never` so a component of any props is assignable to it.
18
+ */
19
+ export type AnyComponent = (props: never) => ReactNode;
20
+ /** React, as the format's types read it. */
21
+ export type ReactRenderer = {
22
+ /** A function component. */
23
+ readonly component: AnyComponent;
24
+ /** What a story draws. */
25
+ readonly storyResult: ReactNode;
26
+ };
27
+ /** A component's props, every one optional: what a story's args may set, and what its render receives. */
28
+ export type ArgsOf<TComponent extends AnyComponent> = TComponent extends (props: infer TProps) => ReactNode ? Partial<TProps> : never;
29
+ /**
30
+ * What a story's `args` may write: the component's props, every one optional, a prop that takes a text also as
31
+ * `storyText("key")`. The render and the play function receive `ArgsOf`, the text already in the shown language.
32
+ */
33
+ export type WrittenArgsOf<TComponent extends AnyComponent> = TComponent extends (props: infer TProps) => ReactNode ? {
34
+ [TName in keyof TProps]?: WrittenArg<TProps[TName]>;
35
+ } : never;
36
+ /** A page with no component (a foundations page): no args. */
37
+ export type NoComponent = () => ReactNode;
38
+ /** A React story file's default export: `{ title, component, args… } satisfies Meta<typeof Button>`. */
39
+ export type Meta<TComponent extends AnyComponent = NoComponent> = CsfMeta<ReactRenderer, TComponent, ArgsOf<TComponent>, WrittenArgsOf<TComponent>>;
40
+ /** A React story: a named export of a story file. */
41
+ export type Story<TComponent extends AnyComponent = NoComponent> = CsfStory<ReactRenderer, ArgsOf<TComponent>, WrittenArgsOf<TComponent>>;
42
+ /** Wraps a React story: a provider, a container of a given width. */
43
+ export type Decorator<TArgs> = CsfDecorator<ReactRenderer, TArgs>;
44
+ /**
45
+ * A React catalogue's preview (`forgebook.preview.ts`): decorators around every story (its providers, the language's
46
+ * reading `context.globals.lang`), parameters under every meta's, a setup before any story renders.
47
+ */
48
+ export type Preview = CsfPreview<ReactRenderer>;
49
+ //# sourceMappingURL=stories.d.ts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M,KAAK,CAAC,UAAU,SAAS,YAAY,GAAG,WAAW,IAAI,QAAQ,CACzE,aAAa,EACb,MAAM,CAAC,UAAU,CAAC,EAClB,aAAa,CAAC,UAAU,CAAC,CAC1B,CAAC;AAEF,qEAAqE;AACrE,MAAM,MAAM,SAAS,CAAC,KAAK,IAAI,YAAY,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;AAElE;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=stories.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stories.js","sourceRoot":"","sources":["../../src/stories.ts"],"names":[],"mappings":""}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * A story drawn as React: its render (or the meta's component) inside its decorators, the story's, the meta's and
3
+ * the catalogue's (its preview's), in that order outward. The story's canvas and each cell of its matrix draw it the
4
+ * same way.
5
+ *
6
+ * @module
7
+ */
8
+ import type { StoryContext } from "@forgebook/story-format/csf";
9
+ import type { LoadedArgs, LoadedDecorator, LoadedStory } from "forgebook/story-module";
10
+ import { type ReactNode } from "react";
11
+ /**
12
+ * The story with these args: its render (or the meta's component), inside its decorators.
13
+ *
14
+ * @param loaded - the story.
15
+ * @param context - the args and the canvas its render, play and decorators read.
16
+ * @param outer - the catalogue's decorators, outside the story's and the meta's.
17
+ */
18
+ export declare const storyElement: (loaded: LoadedStory, context: StoryContext<LoadedArgs>, outer: readonly LoadedDecorator[]) => ReactNode;
19
+ //# sourceMappingURL=storyElement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storyElement.d.ts","sourceRoot":"","sources":["../../src/storyElement.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACvF,OAAO,EAAmC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AA0BxE;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,GACvB,QAAQ,WAAW,EACnB,SAAS,YAAY,CAAC,UAAU,CAAC,EACjC,OAAO,SAAS,eAAe,EAAE,KAChC,SAWF,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * A story drawn as React: its render (or the meta's component) inside its decorators, the story's, the meta's and
3
+ * the catalogue's (its preview's), in that order outward. The story's canvas and each cell of its matrix draw it the
4
+ * same way.
5
+ *
6
+ * @module
7
+ */
8
+ import { createElement } from "react";
9
+ /**
10
+ * A loaded story read as React's: the one place React's types meet the story file's module.
11
+ *
12
+ * @remarks
13
+ * The frame reads a story file without its types (`forgebook/story-module`: a function is taken with the signature
14
+ * CSF gives it), so what its functions return is `unknown` there. A React story file is written against
15
+ * `@forgebook/react`'s `Meta` and `Story`, and its catalogue's preview against its `Preview`, whose components,
16
+ * renders and decorators return `ReactNode`: that is what this view takes on trust, as the frame takes the functions'
17
+ * parameters.
18
+ *
19
+ * @param story - the loaded story.
20
+ */
21
+ const asReactStory = (story) => story;
22
+ /**
23
+ * The story with these args: its render (or the meta's component), inside its decorators.
24
+ *
25
+ * @param loaded - the story.
26
+ * @param context - the args and the canvas its render, play and decorators read.
27
+ * @param outer - the catalogue's decorators, outside the story's and the meta's.
28
+ */
29
+ export const storyElement = (loaded, context, outer) => {
30
+ const story = asReactStory({ ...loaded, decorators: [...loaded.decorators, ...outer] });
31
+ const renderStory = () => {
32
+ if (story.render !== undefined)
33
+ return story.render(context.args, context);
34
+ return story.component === undefined ? null : createElement(story.component, context.args);
35
+ };
36
+ const decorated = story.decorators.reduce((inner, decorator) => () => decorator(inner, context), renderStory);
37
+ return decorated();
38
+ };
39
+ //# sourceMappingURL=storyElement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storyElement.js","sourceRoot":"","sources":["../../src/storyElement.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EAAE,aAAa,EAAoC,MAAM,OAAO,CAAC;AAYxE;;;;;;;;;;;GAWG;AACH,MAAM,YAAY,GAAG,CAAC,KAAkB,EAAc,EAAE,CAAC,KAAmB,CAAC;AAE7E;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,MAAmB,EACnB,OAAiC,EACjC,KAAiC,EACtB,EAAE;IACb,MAAM,KAAK,GAAG,YAAY,CAAC,EAAE,GAAG,MAAM,EAAE,UAAU,EAAE,CAAC,GAAG,MAAM,CAAC,UAAU,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC;IACxF,MAAM,WAAW,GAAG,GAAc,EAAE;QAClC,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC3E,OAAO,KAAK,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7F,CAAC,CAAC;IACF,MAAM,SAAS,GAAG,KAAK,CAAC,UAAU,CAAC,MAAM,CACvC,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,CAAC,GAAc,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,EAChE,WAAW,CACZ,CAAC;IACF,OAAO,SAAS,EAAE,CAAC;AACrB,CAAC,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The JSX of a story drawn from its args: the component with the values the story and the props panel set, as a
3
+ * developer would write it, for the Code card.
4
+ *
5
+ * @remarks
6
+ * A text is an attribute in quotes (in braces when it holds a quote), a number or `null` in braces, `true` the bare
7
+ * name, `false` in braces, a named value by its name (`icon={IconFolder}`); `children` goes between the tags. Only the
8
+ * values that cross from the frame are known (texts, numbers, booleans, `null`, named values): a function or an
9
+ * element the story passes is left out. Pure.
10
+ *
11
+ * @module
12
+ */
13
+ import { type PanelArgs } from "forgebook/messages";
14
+ import type { StoryCodeWriter } from "forgebook/renderer";
15
+ /**
16
+ * A component's JSX with these args.
17
+ *
18
+ * @param component - the component's name (`IconTile`).
19
+ * @param args - the values, in the order they are written.
20
+ */
21
+ export declare const storyJsx: (component: string, args: PanelArgs) => string;
22
+ /** The code writer a React catalogue's shell writes a story's code with: the name the generated pages import. */
23
+ export declare const codeOf: StoryCodeWriter;
24
+ //# sourceMappingURL=storyJsx.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storyJsx.d.ts","sourceRoot":"","sources":["../../src/storyJsx.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAA6B,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAe1D;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,GAAI,WAAW,MAAM,EAAE,MAAM,SAAS,KAAG,MAY7D,CAAC;AAEF,iHAAiH;AACjH,eAAO,MAAM,MAAM,EAAE,eAA0B,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * The JSX of a story drawn from its args: the component with the values the story and the props panel set, as a
3
+ * developer would write it, for the Code card.
4
+ *
5
+ * @remarks
6
+ * A text is an attribute in quotes (in braces when it holds a quote), a number or `null` in braces, `true` the bare
7
+ * name, `false` in braces, a named value by its name (`icon={IconFolder}`); `children` goes between the tags. Only the
8
+ * values that cross from the frame are known (texts, numbers, booleans, `null`, named values): a function or an
9
+ * element the story passes is left out. Pure.
10
+ *
11
+ * @module
12
+ */
13
+ import { isNamedArg } from "forgebook/messages";
14
+ /** One attribute as JSX writes it. */
15
+ const attribute = (name, value) => {
16
+ if (value === true)
17
+ return name;
18
+ if (typeof value === "string")
19
+ return value.includes('"') ? `${name}={${JSON.stringify(value)}}` : `${name}="${value}"`;
20
+ // a named value is written by its name, as the source's module exports it (`icon={IconFolder}`)
21
+ if (isNamedArg(value))
22
+ return `${name}={${value.named}}`;
23
+ return `${name}={${String(value)}}`;
24
+ };
25
+ /** The longest line the attributes stay on one line for, in characters. */
26
+ const ONE_LINE = 80;
27
+ /**
28
+ * A component's JSX with these args.
29
+ *
30
+ * @param component - the component's name (`IconTile`).
31
+ * @param args - the values, in the order they are written.
32
+ */
33
+ export const storyJsx = (component, args) => {
34
+ const { children, ...rest } = args;
35
+ const attributes = Object.entries(rest).map(([name, value]) => attribute(name, value));
36
+ const inner = children === undefined || children === null || children === false ? undefined : String(children);
37
+ const oneLine = [component, ...attributes].join(" ");
38
+ const isOneLine = oneLine.length + 2 <= ONE_LINE;
39
+ const opening = isOneLine
40
+ ? `<${oneLine}`
41
+ : `<${component}\n${attributes.map((text) => ` ${text}`).join("\n")}\n`;
42
+ if (inner === undefined)
43
+ return `${opening}${isOneLine ? " " : ""}/>`;
44
+ return `${opening}>${inner}</${component}>`;
45
+ };
46
+ /** The code writer a React catalogue's shell writes a story's code with: the name the generated pages import. */
47
+ export const codeOf = storyJsx;
48
+ //# sourceMappingURL=storyJsx.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storyJsx.js","sourceRoot":"","sources":["../../src/storyJsx.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAiB,UAAU,EAAkB,MAAM,oBAAoB,CAAC;AAG/E,sCAAsC;AACtC,MAAM,SAAS,GAAG,CAAC,IAAY,EAAE,KAAe,EAAU,EAAE;IAC1D,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAChC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAC3B,OAAO,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,KAAK,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,KAAK,KAAK,GAAG,CAAC;IAC3F,gGAAg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