@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
package/README.md CHANGED
@@ -6,17 +6,34 @@ Universal MDX package for both browser and Node.js environments.
6
6
 
7
7
  ### Browser-safe exports (`@conloca/mdx`)
8
8
 
9
- - **MDXEditorModal** - Full MDX editor component with UI (for admin/CMS use)
10
- - **useMDXEvaluation** - Hook for running pre-compiled MDX code in the browser
9
+ - **MDXEditor** - Embeddable MDX editor component (the page-route editor in the CMS SPA uses this directly)
10
+ - **BaseMDXEditor** - Lower-level editor primitive that accepts the image-dialog hook used by the CMS SPA's
11
+ media-library integration
12
+ - **codeBlockWrapperInfo$** - Editor realm cell a host publishes so the editor's fenced code blocks inherit the host
13
+ site's own code-block classes
11
14
 
12
- If you are building inside `@conloca/cms-spa`, prefer `CMSMDXEditorModal` there for the integrated media-library image
15
+ If you are building inside `@conloca/cms-spa`, prefer `CMSMDXEditor` there for the integrated media-library image
13
16
  picker.
14
17
 
18
+ > **Note:** The legacy `MDXEditorModal` / `BaseMDXEditorModal` exports were removed when the CMS SPA standardized on the
19
+ > page-route editor (`/fragments/:id`, `/pages/:id`). Mount `MDXEditor` directly inside your own layout instead of
20
+ > nesting it in a fullscreen modal.
21
+
15
22
  ### Node.js-only exports (`@conloca/mdx/node`)
16
23
 
17
24
  - **compileMDX** - Compile MDX strings to JavaScript
18
25
  - **evaluateMDXToComponent** - Evaluate MDX strings to React components (server-side)
19
- - **evaluateMDXBlocks** - Fetch and evaluate MDX blocks from a compatible content API
26
+ - **evaluateMDXFragments** - Fetch and evaluate MDX fragments from a compatible content API
27
+ - **handleMDXCompileRequest** - Answer the editor's `POST /mdx/compile` request with the whole compile result
28
+
29
+ ### Sandboxed preview exports (`@conloca/mdx/sandbox-frame`)
30
+
31
+ Compiled MDX is evaluated in an opaque-origin iframe, never in the page that hosts the editor.
32
+
33
+ - **buildSandboxSrcdoc** - Build the preview frame's HTML document, with its runtime inlined
34
+ - **SANDBOX_FRAME_CSP** - The content-security policy that confines the MDX evaluation to that frame
35
+ - **SANDBOX_FRAME_PATH** - The path a host serves the frame document from
36
+ - **SandboxRenderMessage** / **SandboxOutboundMessage** - The messages the host and the frame exchange
20
37
 
21
38
  ## Usage
22
39
 
@@ -24,26 +41,49 @@ picker.
24
41
 
25
42
  ```typescript
26
43
  // In admin/CMS interface
27
- import { MDXEditorModal } from '@conloca/mdx';
44
+ import { MDXEditor } from '@conloca/mdx';
45
+ import '@conloca/mdx/style.css';
46
+ ```
47
+
48
+ The editor entry ships no stylesheet in its JavaScript; import `@conloca/mdx/style.css` once, alongside it. It pulls
49
+ MDXEditor's own stylesheet in first, so that is the only stylesheet import a host writes.
28
50
 
29
- // For rendering MDX content
30
- import { useMDXEvaluation } from '@conloca/mdx';
51
+ ### Browser (Preview)
52
+
53
+ Serve the frame document at `SANDBOX_FRAME_PATH`, point an iframe at it, and post the compiled MDX to the frame:
54
+
55
+ ```typescript
56
+ import { buildSandboxSrcdoc, SANDBOX_FRAME_CSP, SANDBOX_FRAME_PATH } from '@conloca/mdx/sandbox-frame';
57
+
58
+ // In the host's request handler for SANDBOX_FRAME_PATH
59
+ new Response(buildSandboxSrcdoc(), {
60
+ headers: {
61
+ 'content-type': 'text/html; charset=utf-8',
62
+ 'content-security-policy': `${SANDBOX_FRAME_CSP}; frame-ancestors 'self'`,
63
+ },
64
+ });
65
+
66
+ // In the host page, once the frame has posted `{ kind: 'ready' }`. The frame's
67
+ // origin is opaque, so '*' is the only target origin that reaches it.
68
+ frame.contentWindow?.postMessage({ __conlocaSandbox: true, kind: 'render', mode: 'mdx', payload: compiledMdx }, '*');
31
69
  ```
32
70
 
71
+ `@conloca/astro-cms` already serves this route; a host that mounts the editor itself has to serve it.
72
+
33
73
  ### Node.js (Server-side)
34
74
 
35
75
  ```typescript
36
76
  // In Astro, Next.js, etc.
37
- import { evaluateMDXBlocks, evaluateMDXToComponent } from '@conloca/mdx/node';
77
+ import { evaluateMDXFragments, evaluateMDXToComponent } from '@conloca/mdx/node';
38
78
  import { createContentAPI } from '@conloca/content-api/node';
39
79
 
40
- // Evaluate all MDX blocks for a locale
80
+ // Evaluate all MDX fragments for a locale
41
81
  const api = await createContentAPI({ contentRoot: './content' });
42
- const mdxComponents = await evaluateMDXBlocks(api, 'en');
82
+ const mdxComponents = await evaluateMDXFragments(api, 'en');
43
83
 
44
- for (const block of mdxComponents) {
45
- if (!block.ok) {
46
- console.error(`Failed to evaluate ${block.id}:`, block.error.message);
84
+ for (const fragment of mdxComponents) {
85
+ if (!fragment.ok) {
86
+ console.error(`Failed to evaluate ${fragment.id}:`, fragment.error.message);
47
87
  }
48
88
  }
49
89
 
@@ -61,22 +101,26 @@ This package was renamed from `@conloca/mdx-client` to `@conloca/mdx` and consol
61
101
  // Before
62
102
  import { MDXEditorModal } from '@conloca/mdx-client';
63
103
 
64
- // After
65
- import { MDXEditorModal } from '@conloca/mdx';
104
+ // After — mount the editor inline (the fullscreen-modal variant was removed
105
+ // when the CMS standardized on page-route editing at `/fragments/:id` / `/pages/:id`).
106
+ import { MDXEditor } from '@conloca/mdx';
66
107
  ```
67
108
 
109
+ The new `MDXEditor` is a component, not a modal — host it inside your own page layout (header, toolbar, save button) and
110
+ pass `value` / `onChange` directly. See the **Browser: MDX Editor** usage example above for the shape.
111
+
68
112
  **Server-side functions moved here:**
69
113
 
70
114
  ```typescript
71
115
  // Before (scattered across packages)
72
116
  import { evaluateMDXToComponent } from '@conloca/content-api/node';
73
- import { evaluateMDXBlocks } from '@conloca/astro-cms/components';
117
+ import { evaluateMDXFragments } from '@conloca/astro-cms/components';
74
118
 
75
119
  // After
76
- import { evaluateMDXBlocks, evaluateMDXToComponent } from '@conloca/mdx/node';
120
+ import { evaluateMDXFragments, evaluateMDXToComponent } from '@conloca/mdx/node';
77
121
 
78
122
  // Also re-exported from Astro helpers when you are already working there
79
- import { evaluateMDXBlocks } from '@conloca/astro-cms/components';
123
+ import { evaluateMDXFragments } from '@conloca/astro-cms/components';
80
124
  ```
81
125
 
82
126
  ## Building
@@ -0,0 +1,41 @@
1
+ import { type CodeBlockEditorDescriptor } from '@mdxeditor/editor';
2
+ /**
3
+ * Frame chrome around the editor's fenced code blocks — header bar with
4
+ * filename, language tag, and a copy button. The outer wrapper picks up
5
+ * the host's code-block classes (published via `codeBlockWrapperInfo$`
6
+ * by the host-wrapper plugin in cms-spa), so the host's actual code-
7
+ * block CSS (Starlight's expressive-code, Tailwind's pre styling, etc.)
8
+ * reaches the editor's frame through the cascade — no shipped mirror.
9
+ *
10
+ * Host-agnostic: no Shiki / Starlight / ExpressiveCode imports. Class
11
+ * names are discovered at runtime from the host's live HTML.
12
+ */
13
+ /**
14
+ * Realm-published cell carrying the host's code-block wrapper chain,
15
+ * outermost first. For Starlight's expressive-code:
16
+ *
17
+ * [
18
+ * { tagName: 'div', className: 'expressive-code' },
19
+ * { tagName: 'figure', className: 'frame has-title not-content' },
20
+ * ]
21
+ *
22
+ * The cms-spa `hostWrapperPlugin` writes to this whenever the fetched
23
+ * wrapper info changes; the code-block frame reads from it to render
24
+ * each chain link as a nested element with the host's expected tag
25
+ * name. Same publish-pattern as the content-wrapper plugin in cms-spa.
26
+ *
27
+ * Null when the host has no code-block chrome (or the fetch is in
28
+ * flight). The frame then falls back to its base `.conloca-code-block`
29
+ * wrapper with no host inheritance — "looks plain but not broken."
30
+ */
31
+ export declare const codeBlockWrapperInfo$: import("@mdxeditor/editor").NodeRef<{
32
+ tagName: string;
33
+ className: string;
34
+ }[] | null>;
35
+ /**
36
+ * Catch-all descriptor — `priority: 100`, `match: () => true` — registered
37
+ * via `codeBlockPlugin({ codeBlockEditorDescriptors: [conlocaCodeBlockDescriptor] })`.
38
+ * Wraps the upstream `CodeMirrorEditor` with the host-themed frame.
39
+ */
40
+ export declare const conlocaCodeBlockDescriptor: CodeBlockEditorDescriptor;
41
+ //# sourceMappingURL=code-block-frame.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-block-frame.d.ts","sourceRoot":"","sources":["../src/code-block-frame.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,yBAAyB,EAK/B,MAAM,mBAAmB,CAAC;AAI3B;;;;;;;;;;GAUG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,qBAAqB;aAAmB,MAAM;eAAa,MAAM;WAAkB,CAAC;AAmNjG;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,EAAE,yBAIxC,CAAC"}
@@ -0,0 +1,187 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Cell, CodeMirrorEditor, useCellValue, useCodeBlockEditorContext, } from '@mdxeditor/editor';
3
+ import { Check, Copy } from 'lucide-react';
4
+ import { createElement, useCallback, useEffect, useMemo, useState } from 'react';
5
+ /**
6
+ * Frame chrome around the editor's fenced code blocks — header bar with
7
+ * filename, language tag, and a copy button. The outer wrapper picks up
8
+ * the host's code-block classes (published via `codeBlockWrapperInfo$`
9
+ * by the host-wrapper plugin in cms-spa), so the host's actual code-
10
+ * block CSS (Starlight's expressive-code, Tailwind's pre styling, etc.)
11
+ * reaches the editor's frame through the cascade — no shipped mirror.
12
+ *
13
+ * Host-agnostic: no Shiki / Starlight / ExpressiveCode imports. Class
14
+ * names are discovered at runtime from the host's live HTML.
15
+ */
16
+ /**
17
+ * Realm-published cell carrying the host's code-block wrapper chain,
18
+ * outermost first. For Starlight's expressive-code:
19
+ *
20
+ * [
21
+ * { tagName: 'div', className: 'expressive-code' },
22
+ * { tagName: 'figure', className: 'frame has-title not-content' },
23
+ * ]
24
+ *
25
+ * The cms-spa `hostWrapperPlugin` writes to this whenever the fetched
26
+ * wrapper info changes; the code-block frame reads from it to render
27
+ * each chain link as a nested element with the host's expected tag
28
+ * name. Same publish-pattern as the content-wrapper plugin in cms-spa.
29
+ *
30
+ * Null when the host has no code-block chrome (or the fetch is in
31
+ * flight). The frame then falls back to its base `.conloca-code-block`
32
+ * wrapper with no host inheritance — "looks plain but not broken."
33
+ */
34
+ export const codeBlockWrapperInfo$ = Cell(null);
35
+ const TITLE_META_RE = /\btitle=(?:"([^"]*)"|'([^']*)'|(\S+))/;
36
+ // First-line filename comment, the convention ExpressiveCode's frames
37
+ // plugin recognizes when no explicit `title=` is set on the fence —
38
+ // `// foo.ts`, `# foo.py`, `<!-- foo.html -->`, `/* foo.css */`,
39
+ // `; foo.ini`, `-- foo.sql`. Requires a dot-extension so plain prose
40
+ // comments don't get mistaken for filenames.
41
+ const FILENAME_COMMENT_RE = /^\s*(?:\/\/|#|;|--|<!--|\/\*)\s*([\w.\-/@]+\.[\w.-]+)\s*(?:-->|\*\/)?\s*$/;
42
+ function parseMeta(meta) {
43
+ const match = meta.match(TITLE_META_RE);
44
+ if (!match)
45
+ return { title: '', rest: meta.trim() };
46
+ const value = match[1] ?? match[2] ?? match[3] ?? '';
47
+ const rest = (meta.slice(0, match.index) + meta.slice(match.index + match[0].length)).replace(/\s+/g, ' ').trim();
48
+ return { title: value, rest };
49
+ }
50
+ /** Reassemble a meta string with `title` set (or stripped when empty). */
51
+ function buildMeta(title, rest) {
52
+ const trimmedTitle = title.trim();
53
+ const titleFragment = trimmedTitle ? `title="${trimmedTitle.replace(/"/g, '\\"')}"` : '';
54
+ if (titleFragment && rest)
55
+ return `${titleFragment} ${rest}`;
56
+ return titleFragment || rest;
57
+ }
58
+ /**
59
+ * Detect a leading filename comment, the convention EC's frames plugin
60
+ * uses on the published page when no explicit `title=` is set. Returns
61
+ * the filename when line 1 of the code is a single-line comment ending
62
+ * in a dot-extension; empty string otherwise.
63
+ *
64
+ * Used to pre-fill the editor's filename input on legacy fences so
65
+ * authors see the same value the reader sees in the rendered tab. Pure
66
+ * read — the underlying code/comment is never touched.
67
+ */
68
+ function detectFilenameComment(code) {
69
+ const firstLine = code.split('\n', 1)[0] ?? '';
70
+ const match = firstLine.match(FILENAME_COMMENT_RE);
71
+ return match ? (match[1] ?? '') : '';
72
+ }
73
+ function CopyButton({ code }) {
74
+ const [copied, setCopied] = useState(false);
75
+ const onClick = useCallback(() => {
76
+ void navigator.clipboard.writeText(code).then(() => {
77
+ setCopied(true);
78
+ window.setTimeout(() => setCopied(false), 1200);
79
+ });
80
+ }, [code]);
81
+ return (_jsx("button", { type: "button", onClick: onClick, className: "conloca-code-copy", "aria-label": copied ? 'Copied' : 'Copy code', title: copied ? 'Copied' : 'Copy code', children: copied ? _jsx(Check, { size: 14, "aria-hidden": "true" }) : _jsx(Copy, { size: 14, "aria-hidden": "true" }) }));
82
+ }
83
+ /**
84
+ * Editable filename slot. Rewrites the code block's meta string via
85
+ * `setMeta` from `useCodeBlockEditorContext` so authors can author the
86
+ * frame title (`\`\`\`ts title="src/foo.ts"`) directly from the editor —
87
+ * the meta string round-trips through MDXEditor's markdown serializer
88
+ * and ExpressiveCode picks it up as the frame header on the published
89
+ * page. Other meta fragments (ins/del/mark/wrap) are preserved.
90
+ *
91
+ * Legacy fences with a filename comment on line 1 (`// foo.ts`) — EC's
92
+ * pre-meta convention for tab titles — are detected and pre-filled in
93
+ * the input as a read-only display. Opening such a fence does NOT
94
+ * mutate the source. Editing the field is an explicit author intent:
95
+ * the new value is written as `title=` meta AND the original comment
96
+ * line is stripped, so the editor's input becomes the single source of
97
+ * truth without breaking the published render.
98
+ */
99
+ function FilenameInput({ meta, code }) {
100
+ const { setMeta, setCode } = useCodeBlockEditorContext();
101
+ const parsed = useMemo(() => parseMeta(meta), [meta]);
102
+ const detectedFromComment = useMemo(() => (parsed.title ? '' : detectFilenameComment(code)), [parsed.title, code]);
103
+ const displayed = parsed.title || detectedFromComment;
104
+ const [title, setTitle] = useState(displayed);
105
+ const [interacted, setInteracted] = useState(false);
106
+ // External updates (HMR, language change, sibling code edits) reset
107
+ // the local view to the canonical value and clear the "user edited"
108
+ // flag — so the next blur after an external update doesn't write
109
+ // anything until the author actively types again.
110
+ useEffect(() => {
111
+ setTitle(displayed);
112
+ setInteracted(false);
113
+ }, [displayed]);
114
+ const commit = useCallback((next) => {
115
+ if (!interacted)
116
+ return;
117
+ if (next === parsed.title)
118
+ return;
119
+ setMeta(buildMeta(next, parsed.rest));
120
+ // If the pre-fill came from a leading filename comment and the
121
+ // author has now committed an explicit title, strip the comment
122
+ // so EC doesn't render the title twice (once as the tab, once as
123
+ // a stray code comment) on the published page.
124
+ if (detectedFromComment) {
125
+ const lines = code.split('\n');
126
+ if (lines[0] && FILENAME_COMMENT_RE.test(lines[0])) {
127
+ setCode(lines.slice(1).join('\n').replace(/^\n+/, ''));
128
+ }
129
+ }
130
+ }, [interacted, parsed.title, parsed.rest, detectedFromComment, code, setMeta, setCode]);
131
+ const onChange = (e) => {
132
+ setInteracted(true);
133
+ setTitle(e.target.value);
134
+ };
135
+ const onBlur = () => commit(title);
136
+ return (_jsx("input", { type: "text", className: "conloca-code-block__filename", value: title, placeholder: "filename", spellCheck: false, onChange: onChange, onBlur: onBlur, "aria-label": "Code block filename" }));
137
+ }
138
+ function ConlocaCodeBlockEditor(props) {
139
+ // Materialise the host's discovered code-block chain as nested
140
+ // elements. The INNERMOST link in the chain becomes the "frame"
141
+ // element that directly holds the filename header, the code body,
142
+ // and the copy slot — matching ExpressiveCode's authoring shape:
143
+ //
144
+ // <div class="expressive-code"> ← outer link
145
+ // <figure class="frame has-title …"> ← inner link (frame)
146
+ // <figcaption class="header">
147
+ // <span class="title"><FilenameInput /></span>
148
+ // </figcaption>
149
+ // <pre><CodeMirror /></pre>
150
+ // <div class="copy"><CopyButton /></div>
151
+ // </figure>
152
+ // </div>
153
+ //
154
+ // Rendering with the host's expected tags (figure / figcaption / pre)
155
+ // and nesting depth lets descendant CSS selectors land — both single-
156
+ // class (`.frame { ... }`) and descendant (`.expressive-code .frame
157
+ // .header > .title { ... }`) rules paint without us shipping a
158
+ // parallel copy.
159
+ //
160
+ // When chain is null/empty (host has no code-block chrome, or the
161
+ // wrapper fetch hasn't resolved yet) we fall back to a bare
162
+ // `<div class="conloca-code-block">` containing the same inner
163
+ // shape — "looks plain but not broken."
164
+ const chain = useCellValue(codeBlockWrapperInfo$) ?? [];
165
+ const frameLink = chain.length > 0 ? chain[chain.length - 1] : null;
166
+ const outerLinks = frameLink ? chain.slice(0, -1) : [];
167
+ const frameInner = (_jsxs(_Fragment, { children: [_jsx("figcaption", { className: "conloca-code-block__header header", children: _jsx("span", { className: "title", children: _jsx(FilenameInput, { meta: props.meta, code: props.code }) }) }), _jsx("pre", { className: "conloca-code-block__pre", children: _jsx(CodeMirrorEditor, { ...props }) }), _jsx("div", { className: "conloca-code-block__copy copy", children: _jsx(CopyButton, { code: props.code }) })] }));
168
+ // The frame element carries `conloca-code-block` (our own targeting
169
+ // hook) alongside the host's discovered classes. When the host has
170
+ // no chain, we still wrap in a plain `<div>` so the inner shape is
171
+ // consistent for our utility selectors.
172
+ const frame = frameLink ? (createElement(frameLink.tagName, { className: `conloca-code-block ${frameLink.className}` }, frameInner)) : (_jsx("div", { className: "conloca-code-block", children: frameInner }));
173
+ // Wrap outer links from inside out. `reduceRight` so the first
174
+ // chain link ends up as the outermost rendered element.
175
+ return outerLinks.reduceRight((kids, link) => createElement(link.tagName, { className: link.className }, kids), frame);
176
+ }
177
+ /**
178
+ * Catch-all descriptor — `priority: 100`, `match: () => true` — registered
179
+ * via `codeBlockPlugin({ codeBlockEditorDescriptors: [conlocaCodeBlockDescriptor] })`.
180
+ * Wraps the upstream `CodeMirrorEditor` with the host-themed frame.
181
+ */
182
+ export const conlocaCodeBlockDescriptor = {
183
+ priority: 100,
184
+ match: () => true,
185
+ Editor: ConlocaCodeBlockEditor,
186
+ };
187
+ //# sourceMappingURL=code-block-frame.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-block-frame.js","sourceRoot":"","sources":["../src/code-block-frame.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,IAAI,EAGJ,gBAAgB,EAChB,YAAY,EACZ,yBAAyB,GAC1B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAoB,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AS,EAAE,EAAE,EAAE,UAAU,CAAC,CACzG,CAAC,CAAC,CAAC,CACF,cAAK,SAAS,EAAC,oBAAoB,YAAE,UAAU,GAAO,CACvD,CAAC;IAEF,+DAA+D;IAC/D,wDAAwD;IACxD,OAAO,UAAU,CAAC,WAAW,CAC3B,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,EAAE,IAAI,CAAC,EAChF,KAAK,CACN,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAA8B;IACnE,QAAQ,EAAE,GAAG;IACb,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI;IACjB,MAAM,EAAE,sBAAsB;CAC/B,CAAC"}
@@ -0,0 +1,56 @@
1
+ import { type JsxComponentDescriptor, type MDXEditorMethods, type RealmPlugin } from '@mdxeditor/editor';
2
+ import React from 'react';
3
+ export interface BaseMDXEditorProps {
4
+ value: string;
5
+ /**
6
+ * Called whenever the editor content changes. The second argument is `true`
7
+ * the first time the library normalizes the parsed markdown back to its
8
+ * canonical form (bullet style, trailing newline, etc.) — consumers tracking
9
+ * dirty state should treat that call as a re-baseline rather than a user
10
+ * edit, otherwise the editor looks dirty the moment the page loads.
11
+ */
12
+ onChange: (value: string, initialMarkdownNormalize?: boolean) => void;
13
+ onSave?: (value: string) => void;
14
+ readOnly?: boolean;
15
+ imageDialog?: React.FC | null;
16
+ disableImageSettingsButton?: boolean;
17
+ onImageShortcut?: () => void;
18
+ imageButtonRef?: React.Ref<HTMLButtonElement>;
19
+ /**
20
+ * Upload handler for images pasted or dropped directly into the editor. When
21
+ * provided, the underlying imagePlugin will route those events through this
22
+ * function and insert the returned URL as the image src. Independent of the
23
+ * library/picker `imageDialog` flow — both can be active simultaneously.
24
+ */
25
+ imageUploadHandler?: (file: File) => Promise<string>;
26
+ jsxComponentDescriptors?: JsxComponentDescriptor[];
27
+ /**
28
+ * Additional @mdxeditor/editor RealmPlugins appended to the built-in
29
+ * plugin list. Used by the SPA shell to register the MDX components
30
+ * registry-driven slash menu without coupling @conloca/mdx to
31
+ * @conloca/cms-spa.
32
+ */
33
+ extraPlugins?: RealmPlugin[];
34
+ /**
35
+ * Extra toolbar buttons inserted between `<InsertAdmonition />` and the
36
+ * separator preceding focus mode. Pass `null` (default) to keep the
37
+ * stock toolbar.
38
+ */
39
+ extraToolbarItems?: React.ReactNode;
40
+ /**
41
+ * Class applied to the MDXEditor root element (library forwards it to the
42
+ * toolbar and portaled popups too). Pass `"dark-theme"` to activate the
43
+ * library's built-in Radix dark palette.
44
+ * See https://mdxeditor.dev/editor/docs/theming
45
+ */
46
+ className?: string;
47
+ /** Placeholder shown when the editor is empty. Forwarded to MDXEditorLib. */
48
+ placeholder?: React.ReactNode;
49
+ /** Auto-focus the editor on mount. Forwarded to MDXEditorLib. */
50
+ autoFocus?: boolean | {
51
+ defaultSelection?: 'rootStart' | 'rootEnd';
52
+ preventScroll?: boolean;
53
+ };
54
+ }
55
+ export declare const BaseMDXEditor: React.ForwardRefExoticComponent<BaseMDXEditorProps & React.RefAttributes<MDXEditorMethods>>;
56
+ //# sourceMappingURL=editor-core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editor-core.d.ts","sourceRoot":"","sources":["../src/editor-core.tsx"],"names":[],"mappings":"AAAA,OAAO,EAmBL,KAAK,sBAAsB,EAO3B,KAAK,gBAAgB,EAGrB,KAAK,WAAW,EAOjB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAoF,MAAM,OAAO,CAAC;AAwDzG,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd;;;;;;OAMG;IACH,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,wBAAwB,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACtE,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,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