@terrafirmagreg-team/mdx 1.2.10 → 1.2.12
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/package.json +3 -3
- package/src/components/mdx-story.tsx +17 -3
- package/src/lib/story-registry.ts +28 -0
- package/src/lib/story-remark.ts +1 -1
- package/src/lib/story.ts +2 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terrafirmagreg-team/mdx",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "MDX/markdown pipeline",
|
|
6
6
|
"license": "LGPL-3.0-only",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"./lib/markdown": "./src/lib/markdown/index.ts"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@terrafirmagreg-team/translate": "^1.2.
|
|
24
|
-
"@terrafirmagreg-team/ui": "^1.2.
|
|
23
|
+
"@terrafirmagreg-team/translate": "^1.2.11",
|
|
24
|
+
"@terrafirmagreg-team/ui": "^1.2.16",
|
|
25
25
|
"fumadocs-docgen": "^3.2.0",
|
|
26
26
|
"fumadocs-twoslash": "^4.0.4",
|
|
27
27
|
"fumadocs-typescript": "5.6.0",
|
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
|
+
import { ensureStories, storyFor } from '../lib/story-registry';
|
|
5
|
+
import type { Story } from '@fumadocs/story/next/client';
|
|
4
6
|
|
|
5
7
|
export function MdxStory({ name }: { name?: string }) {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
+
const [story, setStory] = useState<Story | undefined>(() =>
|
|
9
|
+
name ? storyFor(name) : undefined,
|
|
10
|
+
);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (story || !name) return;
|
|
13
|
+
let live = true;
|
|
14
|
+
void ensureStories().then(() => {
|
|
15
|
+
if (live) setStory(storyFor(name));
|
|
16
|
+
});
|
|
17
|
+
return () => {
|
|
18
|
+
live = false;
|
|
19
|
+
};
|
|
20
|
+
}, [name, story]);
|
|
21
|
+
return story ? <story.WithControl /> : null;
|
|
8
22
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Story } from '@fumadocs/story/next/client';
|
|
2
|
+
|
|
3
|
+
const registry = ((globalThis as Record<symbol, unknown>)[
|
|
4
|
+
Symbol.for('terrafirmagreg.mdx.stories')
|
|
5
|
+
] ??= {}) as Record<string, Story>;
|
|
6
|
+
|
|
7
|
+
const state = ((globalThis as Record<symbol, unknown>)[
|
|
8
|
+
Symbol.for('terrafirmagreg.mdx.storyLoader')
|
|
9
|
+
] ??= {}) as {
|
|
10
|
+
load?: () => Promise<unknown>;
|
|
11
|
+
loaded?: Promise<unknown>;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function registerStory(name: string, story: Story): void {
|
|
15
|
+
registry[name] = story;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function storyFor(name: string): Story | undefined {
|
|
19
|
+
return registry[name];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function registerStoryLoader(load: () => Promise<unknown>): void {
|
|
23
|
+
state.load = load;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function ensureStories(): Promise<unknown> {
|
|
27
|
+
return (state.loaded ??= state.load?.() ?? Promise.resolve());
|
|
28
|
+
}
|
package/src/lib/story-remark.ts
CHANGED
|
@@ -402,7 +402,7 @@ const DIRECTIVE_META: Record<string, DirectiveMeta> = {
|
|
|
402
402
|
remark: false,
|
|
403
403
|
props: ['url', 'section', 'dataset', 'slug', 'lang', 'version'],
|
|
404
404
|
descriptions: {
|
|
405
|
-
url: 'Page or image.
|
|
405
|
+
url: 'Page or image.webp URL — overrides the fields below',
|
|
406
406
|
section: 'Site section the page belongs to',
|
|
407
407
|
dataset: 'Dataset id within the section',
|
|
408
408
|
slug: 'Page path inside the dataset, e.g. getting-started/install',
|
package/src/lib/story.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
StoryOptions,
|
|
7
7
|
} from '@fumadocs/story/next/client';
|
|
8
8
|
import { DocsWithControl } from '../components/story-panel';
|
|
9
|
+
import { registerStory } from './story-registry';
|
|
9
10
|
import type { ComponentType } from 'react';
|
|
10
11
|
|
|
11
12
|
export { useStory } from '@fumadocs/story';
|
|
@@ -16,19 +17,10 @@ const factory = defineStoryFactory({
|
|
|
16
17
|
WithControl: DocsWithControl,
|
|
17
18
|
});
|
|
18
19
|
|
|
19
|
-
const registry = ((globalThis as Record<symbol, unknown>)[
|
|
20
|
-
Symbol.for('terrafirmagreg.mdx.stories')
|
|
21
|
-
] ??= {}) as Record<string, Story>;
|
|
22
|
-
|
|
23
20
|
export function defineStory<C extends ComponentType<any>>(
|
|
24
21
|
options: StoryOptions<C>,
|
|
25
22
|
): Story<C> {
|
|
26
23
|
const story = factory.defineStory(options);
|
|
27
|
-
if (options.displayName)
|
|
28
|
-
registry[options.displayName] = story as Story;
|
|
24
|
+
if (options.displayName) registerStory(options.displayName, story as Story);
|
|
29
25
|
return story;
|
|
30
26
|
}
|
|
31
|
-
|
|
32
|
-
export function storyFor(name: string): Story | undefined {
|
|
33
|
-
return registry[name];
|
|
34
|
-
}
|