@terrafirmagreg-team/mdx 1.2.5 → 1.2.6

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terrafirmagreg-team/mdx",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
4
4
  "type": "module",
5
5
  "description": "MDX/markdown pipeline",
6
6
  "license": "LGPL-3.0-only",
@@ -16,13 +16,14 @@
16
16
  "./src/components/*/index.ts"
17
17
  ],
18
18
  "./types/*": "./src/types/*.ts",
19
- "./types": "./src/types/index.ts"
19
+ "./types": "./src/types/index.ts",
20
+ "./lib/markdown": "./src/lib/markdown/index.ts"
20
21
  },
21
22
  "dependencies": {
22
23
  "@fumadocs/story": "^1.5.3",
23
24
  "@fumari/stf": "^1.1.2",
24
- "@terrafirmagreg-team/translate": "^1.2.6",
25
- "@terrafirmagreg-team/ui": "^1.2.7",
25
+ "@terrafirmagreg-team/translate": "^1.2.7",
26
+ "@terrafirmagreg-team/ui": "^1.2.8",
26
27
  "@types/turndown": "^5.0.6",
27
28
  "fumadocs-core": "16.17.10",
28
29
  "fumadocs-docgen": "^3.2.0",
@@ -38,6 +38,7 @@ import { Mermaid } from '@terrafirmagreg-team/ui/components/mdx/mermaid';
38
38
  import { Callout, CalloutContainer } from '@terrafirmagreg-team/ui/components/mdx/callout';
39
39
  import { Input, Output, Preview } from '@terrafirmagreg-team/ui/components/mdx/preview';
40
40
  import { DocsImage } from './docs-image';
41
+ import { MdxStory } from './mdx-story';
41
42
  import { Multiblock } from '@terrafirmagreg-team/ui/components/mdx/multiblock';
42
43
  import { Icon } from '@terrafirmagreg-team/ui/components/mdx/icon';
43
44
  import { Video } from '@terrafirmagreg-team/ui/components/mdx/video';
@@ -86,6 +87,7 @@ export function getMDXComponents(components?: MDXComponents) {
86
87
  Input,
87
88
  Output,
88
89
  DocsImage,
90
+ Story: MdxStory,
89
91
  Multiblock,
90
92
  Icon,
91
93
  Video,
@@ -0,0 +1,8 @@
1
+ 'use client';
2
+
3
+ import { storyFor } from '../lib/story';
4
+
5
+ export function MdxStory({ name }: { name?: string }) {
6
+ const entry = name ? storyFor(name) : undefined;
7
+ return entry ? <entry.WithControl /> : null;
8
+ }
@@ -3,6 +3,7 @@ type MdastNode = {
3
3
  value?: string;
4
4
  url?: string;
5
5
  children?: MdastNode[];
6
+ data?: { hProperties?: Record<string, unknown> };
6
7
  };
7
8
 
8
9
  const ISSUE_REF = /^#\d+$/;
@@ -18,15 +19,21 @@ const SKIP = new Set([
18
19
  'html',
19
20
  ]);
20
21
 
21
- const DEFAULT_PATH = /[/\\]changelog[/\\]([^/\\]+)[/\\]/;
22
+ const DEFAULT_PATHS = [
23
+ /[/\\]changelog[/\\]([^/\\]+)[/\\]/,
24
+ /[/\\]docs[/\\]([^/\\]+)[/\\][^/\\]+[/\\]major-changelogs[/\\]/,
25
+ ];
22
26
 
23
27
  export function remarkGithubAutolinks(options: {
24
28
  datasetConfig?: Record<string, { repo?: string }>;
25
- path?: RegExp;
29
+ paths?: RegExp[];
26
30
  } = {}) {
27
- const { datasetConfig = {}, path = DEFAULT_PATH } = options;
31
+ const { datasetConfig = {}, paths = DEFAULT_PATHS } = options;
28
32
  return (tree: MdastNode, file: { path?: string }) => {
29
- const pack = path.exec(file.path ?? '')?.[1];
33
+ const filePath = file.path ?? '';
34
+ const pack = paths
35
+ .map((pattern) => pattern.exec(filePath)?.[1])
36
+ .find(Boolean);
30
37
  const repo = pack ? datasetConfig[pack]?.repo : undefined;
31
38
  if (!repo) return;
32
39
  const repoUrl = `https://github.com/${repo}`;
@@ -43,12 +50,14 @@ export function remarkGithubAutolinks(options: {
43
50
  type: 'link',
44
51
  url: `${repoUrl}/issues/${part.slice(1)}`,
45
52
  children: [{ type: 'text', value: part }],
53
+ data: { hProperties: { className: 'gh-issue' } },
46
54
  }
47
55
  : USER_REF.test(part)
48
56
  ? {
49
57
  type: 'link',
50
58
  url: `https://github.com/${part.slice(1)}`,
51
59
  children: [{ type: 'text', value: part }],
60
+ data: { hProperties: { className: 'gh-mention' } },
52
61
  }
53
62
  : { type: 'text', value: part },
54
63
  );
package/src/lib/story.ts CHANGED
@@ -1,11 +1,32 @@
1
1
  'use client';
2
2
 
3
3
  import { defineStoryFactory } from '@fumadocs/story/next/client';
4
+ import type {
5
+ Story,
6
+ StoryOptions,
7
+ } from '@fumadocs/story/next/client';
4
8
  import { DocsWithControl } from '../components/story-panel';
9
+ import type { ComponentType } from 'react';
5
10
 
6
11
  export { md } from './md';
7
12
 
8
- export const { defineStory } = defineStoryFactory({
13
+ const factory = defineStoryFactory({
9
14
  WithControl: DocsWithControl,
10
15
  });
11
16
 
17
+ const registry = ((globalThis as Record<symbol, unknown>)[
18
+ Symbol.for('terrafirmagreg.mdx.stories')
19
+ ] ??= {}) as Record<string, Story>;
20
+
21
+ export function defineStory<C extends ComponentType<any>>(
22
+ options: StoryOptions<C>,
23
+ ): Story<C> {
24
+ const story = factory.defineStory(options);
25
+ if (options.displayName)
26
+ registry[options.displayName] = story as Story;
27
+ return story;
28
+ }
29
+
30
+ export function storyFor(name: string): Story | undefined {
31
+ return registry[name];
32
+ }