@conloca/mdx 0.1.15 → 0.2.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 (86) hide show
  1. package/README.md +62 -18
  2. package/dist/code-block-frame.d.ts +41 -0
  3. package/dist/code-block-frame.d.ts.map +1 -0
  4. package/dist/code-block-frame.js +187 -0
  5. package/dist/code-block-frame.js.map +1 -0
  6. package/dist/editor-core.d.ts +56 -0
  7. package/dist/editor-core.d.ts.map +1 -0
  8. package/dist/editor-core.js +225 -0
  9. package/dist/editor-core.js.map +1 -0
  10. package/dist/esm-passthrough.d.ts +36 -0
  11. package/dist/esm-passthrough.d.ts.map +1 -0
  12. package/dist/esm-passthrough.js +237 -0
  13. package/dist/esm-passthrough.js.map +1 -0
  14. package/dist/fragments.d.ts +37 -0
  15. package/dist/fragments.d.ts.map +1 -0
  16. package/dist/fragments.js +53 -0
  17. package/dist/fragments.js.map +1 -0
  18. package/dist/index.d.ts +6 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +4 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/markdown-options.d.ts +3 -0
  23. package/dist/markdown-options.d.ts.map +1 -0
  24. package/dist/markdown-options.js +20 -0
  25. package/dist/markdown-options.js.map +1 -0
  26. package/dist/mdx/compile-request.d.ts +5 -0
  27. package/dist/mdx/compile-request.d.ts.map +1 -0
  28. package/dist/mdx/compile-request.js +40 -0
  29. package/dist/mdx/compile-request.js.map +1 -0
  30. package/dist/mdx/compile.d.ts +3 -0
  31. package/dist/mdx/compile.d.ts.map +1 -0
  32. package/dist/mdx/compile.js +47 -0
  33. package/dist/mdx/compile.js.map +1 -0
  34. package/dist/mdx/evaluate.d.ts +39 -0
  35. package/dist/mdx/evaluate.d.ts.map +1 -0
  36. package/dist/mdx/evaluate.js +131 -0
  37. package/dist/mdx/evaluate.js.map +1 -0
  38. package/dist/mdx/heading-outline.d.ts +46 -0
  39. package/dist/mdx/heading-outline.d.ts.map +1 -0
  40. package/dist/mdx/heading-outline.js +114 -0
  41. package/dist/mdx/heading-outline.js.map +1 -0
  42. package/dist/mdx/restrict-expressions.d.ts +43 -0
  43. package/dist/mdx/restrict-expressions.d.ts.map +1 -0
  44. package/dist/mdx/restrict-expressions.js +160 -0
  45. package/dist/mdx/restrict-expressions.js.map +1 -0
  46. package/dist/mdx-editor.d.ts +7 -0
  47. package/dist/mdx-editor.d.ts.map +1 -0
  48. package/dist/mdx-editor.js +8 -0
  49. package/dist/mdx-editor.js.map +1 -0
  50. package/dist/node.d.ts +18 -0
  51. package/dist/node.d.ts.map +1 -0
  52. package/dist/node.js +18 -0
  53. package/dist/node.js.map +1 -0
  54. package/dist/sandbox-frame.d.ts +114 -0
  55. package/dist/sandbox-frame.d.ts.map +1 -0
  56. package/dist/sandbox-frame.js +234 -0
  57. package/dist/sandbox-frame.js.map +1 -0
  58. package/dist/types.d.ts +19 -0
  59. package/dist/types.d.ts.map +1 -0
  60. package/dist/types.js +2 -0
  61. package/dist/types.js.map +1 -0
  62. package/package.json +82 -26
  63. package/src/code-block-frame.tsx +262 -0
  64. package/src/editor-core.tsx +403 -0
  65. package/src/editor-styles.css +282 -0
  66. package/src/esm-passthrough.ts +269 -0
  67. package/src/fragments.ts +91 -0
  68. package/src/index.ts +5 -0
  69. package/src/markdown-options.ts +21 -0
  70. package/src/mdx/compile-request.ts +53 -0
  71. package/src/mdx/compile.ts +51 -0
  72. package/src/mdx/evaluate.ts +144 -0
  73. package/src/mdx/heading-outline.ts +153 -0
  74. package/src/mdx/restrict-expressions.ts +173 -0
  75. package/src/mdx-editor.tsx +15 -0
  76. package/src/node.ts +25 -0
  77. package/src/sandbox-frame.ts +277 -0
  78. package/src/types.ts +23 -0
  79. package/dist/index.d.mts +0 -96
  80. package/dist/index.d.mts.map +0 -1
  81. package/dist/index.mjs +0 -425
  82. package/dist/index.mjs.map +0 -1
  83. package/dist/node.d.mts +0 -107
  84. package/dist/node.d.mts.map +0 -1
  85. package/dist/node.mjs +0 -125
  86. package/dist/node.mjs.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"node.d.mts","names":[],"sources":["../src/types.ts","../src/blocks.ts","../src/mdx/compile.ts","../src/mdx/evaluate.ts"],"mappings":";;;;UAIiB,iBAAA;EACf,EAAA;EACA,EAAA;EACA,KAAA;EACA,SAAA,EAAW,aAAA;AAAA;AAAA,UAGI,wBAAA;EACf,EAAA;EACA,EAAA;EACA,KAAA;EACA,KAAA,EAAO,KAAA;AAAA;AAAA,KAGG,wBAAA,GAA2B,iBAAA,GAAoB,wBAAA;;;UCfjD,kBAAA;EACR,IAAA;IACE,KAAA;EAAA;EAEF,IAAA;AAAA;AAAA,UAGQ,aAAA;EACR,EAAA;EACA,OAAA,EAAS,MAAA,SAAe,kBAAA;AAAA;AAAA,UAGhB,mBAAA;EACR,SAAA;IACE,IAAA;MACE,KAAA;IAAA;IAEF,IAAA;IACA,OAAA;MACE,GAAA;IAAA;EAAA;AAAA;AAAA,UAKI,QAAA;EACR,cAAA,CAAe,OAAA;IAAW,IAAA;EAAA,IAAkB,QAAA,CAAS,aAAA;EACrD,YAAA,CAAa,EAAA,UAAY,MAAA,WAAiB,OAAA,CAAQ,mBAAA;AAAA;;;;;;;iBAS9B,iBAAA,CAAkB,GAAA,EAAK,QAAA,EAAU,MAAA,WAAiB,OAAA,CAAQ,wBAAA;;;;;;ADlChF;iBEGsB,UAAA,CAAW,OAAA,WAAkB,OAAA,CAAQ,gBAAA;;;;;;AFH3D;;;;;;;;;;;AAOA;;;;;;;;;;;AAOA;;;;;;;;ACjB2D;;;iBE0CrC,sBAAA,CACpB,UAAA,UACA,OAAA;EAAY,WAAA;AAAA,IACX,OAAA;EAAU,SAAA,EAAW,aAAA;EAAsB,KAAA,GAAQ,KAAA;AAAA"}
package/dist/node.mjs DELETED
@@ -1,125 +0,0 @@
1
- import * as runtime from "react/jsx-runtime";
2
- import { evaluate } from "@mdx-js/mdx";
3
- import remarkFrontmatter from "remark-frontmatter";
4
- import remarkGfm from "remark-gfm";
5
- import remarkMdxFrontmatter from "remark-mdx-frontmatter";
6
- import { compileMDX as compileMDX$1 } from "@conloca/content-api/node";
7
-
8
- //#region src/mdx/evaluate.ts
9
- /**
10
- * Evaluate MDX content string to a React component.
11
- *
12
- * This is a framework-agnostic utility for converting MDX strings into
13
- * executable React components. Works in any Node.js environment (Astro,
14
- * Next.js, Remix, etc.) at build time or server-side.
15
- *
16
- * **When to use:**
17
- * - Building static sites with MDX content
18
- * - Server-side rendering MDX as React components
19
- * - Need React components (not HTML strings)
20
- *
21
- * @param mdxContent - The MDX string to evaluate
22
- * @param options - Optional configuration
23
- * @param options.development - Whether to use development mode (default: false)
24
- * @returns Object containing Component (or null) and optional error
25
- *
26
- * @example
27
- * ```typescript
28
- * import { evaluateMDXToComponent } from '@conloca/mdx/node';
29
- *
30
- * const { Component, error } = await evaluateMDXToComponent('# Hello\n\nThis is **MDX**');
31
- * if (error) {
32
- * console.error('Failed to evaluate:', error);
33
- * } else if (Component) {
34
- * // Render <Component /> in your React app
35
- * }
36
- * ```
37
- *
38
- * @example
39
- * ```typescript
40
- * // In Astro pages
41
- * const { Component } = await evaluateMDXToComponent(mdxContent);
42
- * // Then render in JSX: <Component />
43
- * ```
44
- */
45
- async function evaluateMDXToComponent(mdxContent, options) {
46
- try {
47
- const { default: MDXComponent } = await evaluate(mdxContent, {
48
- ...runtime,
49
- remarkPlugins: [
50
- remarkFrontmatter,
51
- remarkMdxFrontmatter,
52
- remarkGfm
53
- ],
54
- development: options?.development ?? false
55
- });
56
- return { Component: MDXComponent };
57
- } catch (error) {
58
- return {
59
- Component: null,
60
- error: error instanceof Error ? error : /* @__PURE__ */ new Error("MDX evaluation failed")
61
- };
62
- }
63
- }
64
-
65
- //#endregion
66
- //#region src/blocks.ts
67
- /**
68
- * Evaluate all MDX blocks from a compatible content API.
69
- *
70
- * Returns structured success/error results so callers can decide how to
71
- * surface broken blocks instead of hardcoding fallback UI in this package.
72
- */
73
- async function evaluateMDXBlocks(api, locale) {
74
- const blocks = Array.from(api.listAllContent({ kind: "block" }));
75
- return Promise.all(blocks.map(async (block) => {
76
- const locales = Object.keys(block.locales);
77
- const firstLocale = locales.length > 0 ? block.locales[locales[0]] : null;
78
- const manifestTitle = firstLocale?.meta?.title || firstLocale?.name || block.id;
79
- try {
80
- const blockLocalized = await api.getLocalized(block.id, locale);
81
- const blockTitle = blockLocalized?.localized?.meta?.title || blockLocalized?.localized?.name || manifestTitle;
82
- const mdxContent = blockLocalized?.localized?.content?.mdx;
83
- if (!mdxContent) return {
84
- ok: false,
85
- id: block.id,
86
- title: blockTitle,
87
- error: /* @__PURE__ */ new Error(`No MDX content found for block: ${block.id}`)
88
- };
89
- const { Component: EvaluatedComponent, error } = await evaluateMDXToComponent(mdxContent);
90
- if (error || !EvaluatedComponent) return {
91
- ok: false,
92
- id: block.id,
93
- title: blockTitle,
94
- error: error || /* @__PURE__ */ new Error(`MDX evaluation failed for block: ${block.id}`)
95
- };
96
- return {
97
- ok: true,
98
- id: block.id,
99
- title: blockTitle,
100
- Component: EvaluatedComponent
101
- };
102
- } catch (error) {
103
- return {
104
- ok: false,
105
- id: block.id,
106
- title: manifestTitle,
107
- error: error instanceof Error ? error : /* @__PURE__ */ new Error(`Failed to evaluate block: ${block.id}`)
108
- };
109
- }
110
- }));
111
- }
112
-
113
- //#endregion
114
- //#region src/mdx/compile.ts
115
- /**
116
- * Compile MDX content to executable JavaScript.
117
- * Delegates to the shared compiler in @conloca/content-api.
118
- */
119
- async function compileMDX(content) {
120
- return compileMDX$1(content);
121
- }
122
-
123
- //#endregion
124
- export { compileMDX, evaluateMDXBlocks, evaluateMDXToComponent };
125
- //# sourceMappingURL=node.mjs.map
package/dist/node.mjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"node.mjs","names":["compileSharedMDX"],"sources":["../src/mdx/evaluate.ts","../src/blocks.ts","../src/mdx/compile.ts"],"sourcesContent":["import { evaluate } from '@mdx-js/mdx';\nimport type { ComponentType } from 'react';\nimport * as runtime from 'react/jsx-runtime';\nimport remarkFrontmatter from 'remark-frontmatter';\nimport remarkGfm from 'remark-gfm';\nimport remarkMdxFrontmatter from 'remark-mdx-frontmatter';\n\n/**\n * Evaluate MDX content string to a React component.\n *\n * This is a framework-agnostic utility for converting MDX strings into\n * executable React components. Works in any Node.js environment (Astro,\n * Next.js, Remix, etc.) at build time or server-side.\n *\n * **When to use:**\n * - Building static sites with MDX content\n * - Server-side rendering MDX as React components\n * - Need React components (not HTML strings)\n *\n * @param mdxContent - The MDX string to evaluate\n * @param options - Optional configuration\n * @param options.development - Whether to use development mode (default: false)\n * @returns Object containing Component (or null) and optional error\n *\n * @example\n * ```typescript\n * import { evaluateMDXToComponent } from '@conloca/mdx/node';\n *\n * const { Component, error } = await evaluateMDXToComponent('# Hello\\n\\nThis is **MDX**');\n * if (error) {\n * console.error('Failed to evaluate:', error);\n * } else if (Component) {\n * // Render <Component /> in your React app\n * }\n * ```\n *\n * @example\n * ```typescript\n * // In Astro pages\n * const { Component } = await evaluateMDXToComponent(mdxContent);\n * // Then render in JSX: <Component />\n * ```\n */\nexport async function evaluateMDXToComponent(\n mdxContent: string,\n options?: { development?: boolean },\n): Promise<{ Component: ComponentType | null; error?: Error }> {\n try {\n // Use evaluate() to compile and execute MDX in one step\n const { default: MDXComponent } = await evaluate(mdxContent, {\n ...runtime,\n remarkPlugins: [remarkFrontmatter, remarkMdxFrontmatter, remarkGfm],\n development: options?.development ?? false,\n });\n\n return { Component: MDXComponent };\n } catch (error) {\n return {\n Component: null,\n error: error instanceof Error ? error : new Error('MDX evaluation failed'),\n };\n }\n}\n","import { evaluateMDXToComponent } from './mdx/evaluate.js';\nimport type { MDXBlockEvaluationResult } from './types.js';\n\ninterface BlockLocaleSummary {\n meta?: {\n title?: string;\n };\n name?: string;\n}\n\ninterface BlockManifest {\n id: string;\n locales: Record<string, BlockLocaleSummary | undefined>;\n}\n\ninterface BlockLocalizedEntry {\n localized?: {\n meta?: {\n title?: string;\n };\n name?: string;\n content?: {\n mdx?: string;\n };\n };\n}\n\ninterface BlockAPI {\n listAllContent(filters: { kind: 'block' }): Iterable<BlockManifest>;\n getLocalized(id: string, locale: string): Promise<BlockLocalizedEntry | null>;\n}\n\n/**\n * Evaluate all MDX blocks from a compatible content API.\n *\n * Returns structured success/error results so callers can decide how to\n * surface broken blocks instead of hardcoding fallback UI in this package.\n */\nexport async function evaluateMDXBlocks(api: BlockAPI, locale: string): Promise<MDXBlockEvaluationResult[]> {\n const blocks = Array.from(api.listAllContent({ kind: 'block' }));\n\n return Promise.all(\n blocks.map(async (block) => {\n const locales = Object.keys(block.locales);\n const firstLocale = locales.length > 0 ? block.locales[locales[0]] : null;\n const manifestTitle = firstLocale?.meta?.title || firstLocale?.name || block.id;\n\n try {\n const blockLocalized = await api.getLocalized(block.id, locale);\n const blockTitle = blockLocalized?.localized?.meta?.title || blockLocalized?.localized?.name || manifestTitle;\n const mdxContent = blockLocalized?.localized?.content?.mdx;\n\n if (!mdxContent) {\n return {\n ok: false,\n id: block.id,\n title: blockTitle,\n error: new Error(`No MDX content found for block: ${block.id}`),\n };\n }\n\n const { Component: EvaluatedComponent, error } = await evaluateMDXToComponent(mdxContent);\n\n if (error || !EvaluatedComponent) {\n return {\n ok: false,\n id: block.id,\n title: blockTitle,\n error: error || new Error(`MDX evaluation failed for block: ${block.id}`),\n };\n }\n\n return {\n ok: true,\n id: block.id,\n title: blockTitle,\n Component: EvaluatedComponent,\n };\n } catch (error) {\n return {\n ok: false,\n id: block.id,\n title: manifestTitle,\n error: error instanceof Error ? error : new Error(`Failed to evaluate block: ${block.id}`),\n };\n }\n }),\n );\n}\n","import { compileMDX as compileSharedMDX } from '@conloca/content-api/node';\nimport type { MDXCompileResult } from '../types.js';\n\n/**\n * Compile MDX content to executable JavaScript.\n * Delegates to the shared compiler in @conloca/content-api.\n */\nexport async function compileMDX(content: string): Promise<MDXCompileResult> {\n return compileSharedMDX(content);\n}\n"],"mappings":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