@conloca/mdx 0.1.16 → 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 +50 -16
  2. package/dist/code-block-frame.js +1 -0
  3. package/dist/code-block-frame.js.map +1 -0
  4. package/dist/editor-core.d.ts +0 -2
  5. package/dist/editor-core.d.ts.map +1 -1
  6. package/dist/editor-core.js +50 -6
  7. package/dist/editor-core.js.map +1 -0
  8. package/dist/esm-passthrough.d.ts +36 -0
  9. package/dist/esm-passthrough.d.ts.map +1 -0
  10. package/dist/esm-passthrough.js +237 -0
  11. package/dist/esm-passthrough.js.map +1 -0
  12. package/dist/fragments.d.ts +37 -0
  13. package/dist/fragments.d.ts.map +1 -0
  14. package/dist/fragments.js +53 -0
  15. package/dist/fragments.js.map +1 -0
  16. package/dist/index.d.ts +0 -2
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +1 -1
  19. package/dist/index.js.map +1 -0
  20. package/dist/markdown-options.js +1 -0
  21. package/dist/markdown-options.js.map +1 -0
  22. package/dist/mdx/compile-request.d.ts +5 -0
  23. package/dist/mdx/compile-request.d.ts.map +1 -0
  24. package/dist/mdx/compile-request.js +40 -0
  25. package/dist/mdx/compile-request.js.map +1 -0
  26. package/dist/mdx/compile.d.ts.map +1 -1
  27. package/dist/mdx/compile.js +21 -1
  28. package/dist/mdx/compile.js.map +1 -0
  29. package/dist/mdx/evaluate.d.ts +18 -23
  30. package/dist/mdx/evaluate.d.ts.map +1 -1
  31. package/dist/mdx/evaluate.js +103 -29
  32. package/dist/mdx/evaluate.js.map +1 -0
  33. package/dist/mdx/heading-outline.d.ts +46 -0
  34. package/dist/mdx/heading-outline.d.ts.map +1 -0
  35. package/dist/mdx/heading-outline.js +114 -0
  36. package/dist/mdx/heading-outline.js.map +1 -0
  37. package/dist/mdx/restrict-expressions.d.ts +43 -0
  38. package/dist/mdx/restrict-expressions.d.ts.map +1 -0
  39. package/dist/mdx/restrict-expressions.js +160 -0
  40. package/dist/mdx/restrict-expressions.js.map +1 -0
  41. package/dist/mdx-editor.js +1 -0
  42. package/dist/mdx-editor.js.map +1 -0
  43. package/dist/node.d.ts +3 -2
  44. package/dist/node.d.ts.map +1 -1
  45. package/dist/node.js +3 -1
  46. package/dist/node.js.map +1 -0
  47. package/dist/sandbox-frame.d.ts +114 -0
  48. package/dist/sandbox-frame.d.ts.map +1 -0
  49. package/dist/sandbox-frame.js +234 -0
  50. package/dist/sandbox-frame.js.map +1 -0
  51. package/dist/types.d.ts +7 -4
  52. package/dist/types.d.ts.map +1 -1
  53. package/dist/types.js +1 -0
  54. package/dist/types.js.map +1 -0
  55. package/package.json +58 -41
  56. package/src/code-block-frame.tsx +262 -0
  57. package/src/editor-core.tsx +403 -0
  58. package/src/editor-styles.css +282 -0
  59. package/src/esm-passthrough.ts +269 -0
  60. package/src/fragments.ts +91 -0
  61. package/src/index.ts +5 -0
  62. package/src/markdown-options.ts +21 -0
  63. package/src/mdx/compile-request.ts +53 -0
  64. package/src/mdx/compile.ts +51 -0
  65. package/src/mdx/evaluate.ts +144 -0
  66. package/src/mdx/heading-outline.ts +153 -0
  67. package/src/mdx/restrict-expressions.ts +173 -0
  68. package/src/mdx-editor.tsx +15 -0
  69. package/src/node.ts +25 -0
  70. package/src/sandbox-frame.ts +277 -0
  71. package/src/types.ts +23 -0
  72. package/dist/blocks.d.ts +0 -37
  73. package/dist/blocks.d.ts.map +0 -1
  74. package/dist/blocks.js +0 -51
  75. package/dist/hooks/useMDXEvaluation.d.ts +0 -28
  76. package/dist/hooks/useMDXEvaluation.d.ts.map +0 -1
  77. package/dist/hooks/useMDXEvaluation.js +0 -117
  78. package/dist/index.d.mts +0 -127
  79. package/dist/index.d.mts.map +0 -1
  80. package/dist/index.mjs +0 -516
  81. package/dist/index.mjs.map +0 -1
  82. package/dist/node.d.mts +0 -102
  83. package/dist/node.d.mts.map +0 -1
  84. package/dist/node.mjs +0 -140
  85. package/dist/node.mjs.map +0 -1
  86. package/dist/style.css +0 -88
@@ -0,0 +1,403 @@
1
+ import {
2
+ BlockTypeSelect,
3
+ BoldItalicUnderlineToggles,
4
+ ButtonWithTooltip,
5
+ ChangeCodeMirrorLanguage,
6
+ ConditionalContents,
7
+ CreateLink,
8
+ codeBlockPlugin,
9
+ codeMirrorPlugin,
10
+ DiffSourceToggleWrapper,
11
+ diffSourcePlugin,
12
+ GenericJsxEditor,
13
+ HighlightToggle,
14
+ headingsPlugin,
15
+ InsertCodeBlock,
16
+ InsertImage,
17
+ InsertTable,
18
+ InsertThematicBreak,
19
+ imagePlugin,
20
+ type JsxComponentDescriptor,
21
+ jsxPlugin,
22
+ ListsToggle,
23
+ linkDialogPlugin,
24
+ linkPlugin,
25
+ listsPlugin,
26
+ MDXEditor as MDXEditorLib,
27
+ type MDXEditorMethods,
28
+ markdownShortcutPlugin,
29
+ quotePlugin,
30
+ type RealmPlugin,
31
+ Separator,
32
+ StrikeThroughSupSubToggles,
33
+ tablePlugin,
34
+ thematicBreakPlugin,
35
+ toolbarPlugin,
36
+ UndoRedo,
37
+ } from '@mdxeditor/editor';
38
+ import { Maximize2, Minimize2 } from 'lucide-react';
39
+ import React, { useCallback, useEffect, useImperativeHandle, useRef, useSyncExternalStore } from 'react';
40
+ import { conlocaCodeBlockDescriptor } from './code-block-frame.js';
41
+ import { joinEsm, type PreservedEsm, splitEsm } from './esm-passthrough.js';
42
+ import { TO_MARKDOWN_OPTIONS } from './markdown-options.js';
43
+
44
+ const FOCUS_MODE_STORAGE_KEY = 'conloca.mdxeditor.focusMode';
45
+ const FOCUS_MODE_BODY_CLASS = 'mdxeditor-focus-mode';
46
+
47
+ /**
48
+ * Toggle focus-mode by writing the class on `document.body`. Direct DOM
49
+ * mutation (vs. piping a boolean through React state into the editor's
50
+ * `className` prop) avoids re-rendering Lexical on every toggle — the
51
+ * editor's prop is the only entry point and changing it forces a parse
52
+ * round-trip. Persisted in localStorage so the preference survives reloads.
53
+ */
54
+ function readFocusMode(): boolean {
55
+ if (typeof document === 'undefined') return false;
56
+ return document.body.classList.contains(FOCUS_MODE_BODY_CLASS);
57
+ }
58
+
59
+ function subscribeFocusMode(callback: () => void): () => void {
60
+ if (typeof window === 'undefined') return () => {};
61
+ const handler = () => callback();
62
+ window.addEventListener('conloca:focusModeChange', handler);
63
+ return () => window.removeEventListener('conloca:focusModeChange', handler);
64
+ }
65
+
66
+ function setFocusMode(next: boolean): void {
67
+ if (typeof document === 'undefined') return;
68
+ document.body.classList.toggle(FOCUS_MODE_BODY_CLASS, next);
69
+ try {
70
+ if (next) {
71
+ window.localStorage.setItem(FOCUS_MODE_STORAGE_KEY, '1');
72
+ } else {
73
+ window.localStorage.removeItem(FOCUS_MODE_STORAGE_KEY);
74
+ }
75
+ } catch {
76
+ // localStorage may be unavailable (private mode, SSR) — ignore.
77
+ }
78
+ window.dispatchEvent(new Event('conloca:focusModeChange'));
79
+ }
80
+
81
+ function FocusModeToggle() {
82
+ const focusMode = useSyncExternalStore(subscribeFocusMode, readFocusMode, () => false);
83
+ const onClick = useCallback(() => setFocusMode(!focusMode), [focusMode]);
84
+ const Icon = focusMode ? Minimize2 : Maximize2;
85
+ return (
86
+ <ButtonWithTooltip
87
+ title={focusMode ? 'Exit focus mode (wider column)' : 'Enter focus mode (narrow column)'}
88
+ onClick={onClick}
89
+ >
90
+ <Icon size={16} aria-hidden />
91
+ </ButtonWithTooltip>
92
+ );
93
+ }
94
+
95
+ export interface BaseMDXEditorProps {
96
+ value: string;
97
+ /**
98
+ * Called whenever the editor content changes. The second argument is `true`
99
+ * the first time the library normalizes the parsed markdown back to its
100
+ * canonical form (bullet style, trailing newline, etc.) — consumers tracking
101
+ * dirty state should treat that call as a re-baseline rather than a user
102
+ * edit, otherwise the editor looks dirty the moment the page loads.
103
+ */
104
+ onChange: (value: string, initialMarkdownNormalize?: boolean) => void;
105
+ onSave?: (value: string) => void;
106
+ readOnly?: boolean;
107
+ imageDialog?: React.FC | null;
108
+ disableImageSettingsButton?: boolean;
109
+ onImageShortcut?: () => void;
110
+ imageButtonRef?: React.Ref<HTMLButtonElement>;
111
+ /**
112
+ * Upload handler for images pasted or dropped directly into the editor. When
113
+ * provided, the underlying imagePlugin will route those events through this
114
+ * function and insert the returned URL as the image src. Independent of the
115
+ * library/picker `imageDialog` flow — both can be active simultaneously.
116
+ */
117
+ imageUploadHandler?: (file: File) => Promise<string>;
118
+ jsxComponentDescriptors?: JsxComponentDescriptor[];
119
+ /**
120
+ * Additional @mdxeditor/editor RealmPlugins appended to the built-in
121
+ * plugin list. Used by the SPA shell to register the MDX components
122
+ * registry-driven slash menu without coupling @conloca/mdx to
123
+ * @conloca/cms-spa.
124
+ */
125
+ extraPlugins?: RealmPlugin[];
126
+ /**
127
+ * Extra toolbar buttons inserted between `<InsertAdmonition />` and the
128
+ * separator preceding focus mode. Pass `null` (default) to keep the
129
+ * stock toolbar.
130
+ */
131
+ extraToolbarItems?: React.ReactNode;
132
+ /**
133
+ * Class applied to the MDXEditor root element (library forwards it to the
134
+ * toolbar and portaled popups too). Pass `"dark-theme"` to activate the
135
+ * library's built-in Radix dark palette.
136
+ * See https://mdxeditor.dev/editor/docs/theming
137
+ */
138
+ className?: string;
139
+ /** Placeholder shown when the editor is empty. Forwarded to MDXEditorLib. */
140
+ placeholder?: React.ReactNode;
141
+ /** Auto-focus the editor on mount. Forwarded to MDXEditorLib. */
142
+ autoFocus?: boolean | { defaultSelection?: 'rootStart' | 'rootEnd'; preventScroll?: boolean };
143
+ }
144
+
145
+ // The empty-string entry is the documented escape hatch for code blocks
146
+ // authored without a language hint. Without it, fences like ```\nfoo\n``` (which
147
+ // the parser tags as language `null` / meta `'N/A'`) trip a hard error in
148
+ // older versions and emit a noisy warning even on v3.55+. See mdx-editor/editor
149
+ // issues #370, #423, #463, #885, #886, #901.
150
+ const codeBlockLanguages: Record<string, string> = {
151
+ '': 'Plain text',
152
+ text: 'Plain Text',
153
+ js: 'JavaScript',
154
+ jsx: 'JavaScript (React)',
155
+ ts: 'TypeScript',
156
+ tsx: 'TypeScript (React)',
157
+ css: 'CSS',
158
+ html: 'HTML',
159
+ json: 'JSON',
160
+ md: 'Markdown',
161
+ mdx: 'MDX',
162
+ bash: 'Bash',
163
+ python: 'Python',
164
+ };
165
+
166
+ /**
167
+ * Wildcard fallback so any unknown JSX tag round-trips through GenericJsxEditor
168
+ * instead of crashing the importer with "Parsing of the following markdown
169
+ * structure failed". Two entries because the upstream visitor dispatches by
170
+ * `kind` (block vs inline JSX) — without the inline one, an inline `<Badge>`
171
+ * mid-paragraph would be matched by the flow wildcard and lifted out of its
172
+ * paragraph in Lexical. Consumers passing typed descriptors win via the
173
+ * exact-name match in the visitor; the wildcard only handles the leftovers.
174
+ */
175
+ const wildcardJsxDescriptors: JsxComponentDescriptor[] = [
176
+ { name: '*', kind: 'flow', props: [], hasChildren: true, Editor: GenericJsxEditor },
177
+ { name: '*', kind: 'text', props: [], hasChildren: true, Editor: GenericJsxEditor },
178
+ ];
179
+
180
+ function renderInsertImageButton(imageButtonRef?: React.Ref<HTMLButtonElement>) {
181
+ if (!imageButtonRef) {
182
+ return <InsertImage />;
183
+ }
184
+
185
+ return React.createElement(InsertImage as unknown as React.FC<{ ref: React.Ref<HTMLButtonElement> }>, {
186
+ ref: imageButtonRef,
187
+ });
188
+ }
189
+
190
+ /**
191
+ * Restore the persisted focus-mode preference on first import. Runs once at
192
+ * module load so the class is in place before any editor mounts — avoids a
193
+ * flash of wide column when the user previously selected focus mode.
194
+ */
195
+ if (typeof window !== 'undefined') {
196
+ try {
197
+ if (window.localStorage.getItem(FOCUS_MODE_STORAGE_KEY) === '1') {
198
+ document.body.classList.add(FOCUS_MODE_BODY_CLASS);
199
+ }
200
+ } catch {
201
+ // ignore
202
+ }
203
+ }
204
+
205
+ export const BaseMDXEditor = React.forwardRef<MDXEditorMethods, BaseMDXEditorProps>(
206
+ (
207
+ {
208
+ value,
209
+ onChange,
210
+ onSave,
211
+ readOnly = false,
212
+ imageDialog,
213
+ disableImageSettingsButton = false,
214
+ onImageShortcut,
215
+ imageButtonRef,
216
+ imageUploadHandler,
217
+ jsxComponentDescriptors,
218
+ extraPlugins,
219
+ extraToolbarItems,
220
+ className,
221
+ placeholder,
222
+ autoFocus,
223
+ },
224
+ ref,
225
+ ) => {
226
+ // The library reads `markdown` once, as `initialMarkdown`, and consumers
227
+ // swap documents by remounting (see the `key=` on MdxPageEditor's and
228
+ // FragmentEditor's editors). So the ESM lifted off the document belongs to
229
+ // whatever the editor was *seeded* with — re-deriving it from `value` would
230
+ // parse the whole document on every keystroke and would be wrong if the
231
+ // prop ever changed without a remount.
232
+ const seededRef = useRef<PreservedEsm | null>(null);
233
+ seededRef.current ??= splitEsm(value);
234
+ // Known consequence: the editor is seeded with the stripped body, so the
235
+ // Source and Diff views (diffSourcePlugin, below) show a document without
236
+ // the import block even though the committed file has it. Data is safe —
237
+ // retyping an import there is reconciled by `joinEsm` against the preserved
238
+ // bindings rather than declared twice — but the raw view is not a faithful
239
+ // picture of the file on disk. Fixing that needs the library to render ESM
240
+ // it cannot represent in rich-text mode.
241
+
242
+ const innerRef = useRef<MDXEditorMethods>(null);
243
+
244
+ // Everything leaving the editor gets the author's import/export block put
245
+ // back verbatim. `onChange` is the save path; the imperative handle is
246
+ // intercepted too so `getMarkdown()` never reports a document that is
247
+ // missing statements the file on disk has.
248
+ const handleChange = useCallback(
249
+ (markdown: string, initialMarkdownNormalize?: boolean) => {
250
+ const preserved = seededRef.current;
251
+ onChange(preserved === null ? markdown : joinEsm(preserved, markdown), initialMarkdownNormalize);
252
+ },
253
+ [onChange],
254
+ );
255
+
256
+ useImperativeHandle(
257
+ ref,
258
+ () => ({
259
+ getMarkdown: () => {
260
+ const markdown = innerRef.current?.getMarkdown() ?? '';
261
+ const preserved = seededRef.current;
262
+ return preserved === null ? markdown : joinEsm(preserved, markdown);
263
+ },
264
+ // Replaces the whole document, so its ESM becomes the preserved block.
265
+ setMarkdown: (markdown: string) => {
266
+ const split = splitEsm(markdown);
267
+ seededRef.current = split;
268
+ innerRef.current?.setMarkdown(split.body);
269
+ },
270
+ // Inserts at the cursor rather than reseeding, so the preserved block is
271
+ // unaffected. ESM in inserted markdown is dropped by the library, as
272
+ // before — the editor has never been able to author new imports.
273
+ insertMarkdown: (markdown: string) => innerRef.current?.insertMarkdown(markdown),
274
+ focus: (
275
+ callbackFn?: () => void,
276
+ opts?: { defaultSelection?: 'rootStart' | 'rootEnd'; preventScroll?: boolean },
277
+ ) => innerRef.current?.focus(callbackFn, opts),
278
+ getContentEditableHTML: () => innerRef.current?.getContentEditableHTML() ?? '',
279
+ getSelectionMarkdown: () => innerRef.current?.getSelectionMarkdown() ?? '',
280
+ }),
281
+ [],
282
+ );
283
+
284
+ useEffect(() => {
285
+ const handleKeyDown = (event: KeyboardEvent) => {
286
+ if ((event.ctrlKey || event.metaKey) && event.key === 's') {
287
+ event.preventDefault();
288
+ onSave?.(value);
289
+ }
290
+
291
+ if ((event.ctrlKey || event.metaKey) && event.shiftKey && event.key.toLowerCase() === 'i') {
292
+ if (!onImageShortcut) {
293
+ return;
294
+ }
295
+
296
+ event.preventDefault();
297
+ onImageShortcut();
298
+ }
299
+ };
300
+
301
+ document.addEventListener('keydown', handleKeyDown);
302
+ return () => document.removeEventListener('keydown', handleKeyDown);
303
+ }, [onImageShortcut, onSave, value]);
304
+
305
+ return (
306
+ <MDXEditorLib
307
+ ref={innerRef}
308
+ markdown={seededRef.current.body}
309
+ toMarkdownOptions={TO_MARKDOWN_OPTIONS}
310
+ onChange={handleChange}
311
+ onError={({ error, source }) => {
312
+ // Library invokes this synchronously inside a gurx signal, so don't
313
+ // setState here — that triggers a render-phase warning (#872).
314
+ // Logging only is enough; the React error boundary still catches
315
+ // anything that escapes from rendering.
316
+ console.error('[MDXEditor] parse error:', error, '\nsource:', source);
317
+ }}
318
+ readOnly={readOnly}
319
+ className={className}
320
+ placeholder={placeholder}
321
+ autoFocus={autoFocus}
322
+ contentEditableClassName="conloca-prose conloca-prose--editor"
323
+ plugins={[
324
+ headingsPlugin(),
325
+ listsPlugin(),
326
+ quotePlugin(),
327
+ linkPlugin(),
328
+ linkDialogPlugin(),
329
+ tablePlugin(),
330
+ thematicBreakPlugin(),
331
+ // frontmatterPlugin intentionally omitted: metadata (title,
332
+ // description, id, created, modified) is server-owned and stripped
333
+ // from `content.mdx` on load. Re-introducing the plugin would let
334
+ // the editor round-trip a YAML block as body text, corrupting the
335
+ // file when content is inserted above it.
336
+ codeBlockPlugin({
337
+ defaultCodeBlockLanguage: 'ts',
338
+ codeBlockEditorDescriptors: [conlocaCodeBlockDescriptor],
339
+ }),
340
+ codeMirrorPlugin({ codeBlockLanguages }),
341
+ diffSourcePlugin({ viewMode: 'rich-text' }),
342
+ markdownShortcutPlugin(),
343
+ jsxPlugin({
344
+ jsxComponentDescriptors: [...(jsxComponentDescriptors ?? []), ...wildcardJsxDescriptors],
345
+ }),
346
+ imagePlugin({
347
+ ...(imageDialog ? { ImageDialog: imageDialog, disableImageSettingsButton } : {}),
348
+ ...(imageUploadHandler ? { imageUploadHandler } : {}),
349
+ }),
350
+ ...(extraPlugins ?? []),
351
+ toolbarPlugin({
352
+ // flex-wrap so the toolbar reflows on narrow viewports instead of
353
+ // overflowing horizontally — workaround documented in
354
+ // mdx-editor/editor#908.
355
+ toolbarClassName: 'mdxeditor-toolbar-wrap',
356
+ toolbarContents: () => (
357
+ <DiffSourceToggleWrapper>
358
+ <ConditionalContents
359
+ options={[
360
+ {
361
+ // When the user clicks into a code block, swap most of
362
+ // the rich-text toolbar for the language picker — those
363
+ // controls are no-ops inside CodeMirror anyway.
364
+ when: (editor) => editor?.editorType === 'codeblock',
365
+ contents: () => <ChangeCodeMirrorLanguage />,
366
+ },
367
+ {
368
+ fallback: () => (
369
+ <>
370
+ <UndoRedo />
371
+ <Separator />
372
+ <BoldItalicUnderlineToggles />
373
+ <StrikeThroughSupSubToggles />
374
+ <HighlightToggle />
375
+ <Separator />
376
+ <ListsToggle />
377
+ <Separator />
378
+ <BlockTypeSelect />
379
+ <Separator />
380
+ <CreateLink />
381
+ {renderInsertImageButton(imageButtonRef)}
382
+ <InsertTable />
383
+ <InsertThematicBreak />
384
+ <Separator />
385
+ <InsertCodeBlock />
386
+ {extraToolbarItems}
387
+ <Separator />
388
+ <FocusModeToggle />
389
+ </>
390
+ ),
391
+ },
392
+ ]}
393
+ />
394
+ </DiffSourceToggleWrapper>
395
+ ),
396
+ }),
397
+ ]}
398
+ />
399
+ );
400
+ },
401
+ );
402
+
403
+ BaseMDXEditor.displayName = 'BaseMDXEditor';
@@ -0,0 +1,282 @@
1
+ /* MDXEditor's own stylesheet comes in here, so a host imports this one
2
+ file and never has to know the editor sits on MDXEditor. Order between
3
+ the two is irrelevant: MDXEditor injects its CSS-module rules at mount
4
+ time, so the rules below win on specificity, never on position. */
5
+ @import "@mdxeditor/editor/style.css";
6
+
7
+ /* L0 Conloca prose baseline — used when host probe vars are unset.
8
+ Never fall through to admin chrome body font via bare `inherit`.
9
+ Host match (--conloca-host-*) and consumer editorCSS still override. */
10
+ :root {
11
+ --conloca-prose-font-family:
12
+ ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
13
+ --conloca-prose-font-size: 1rem;
14
+ --conloca-prose-font-weight: 400;
15
+ --conloca-prose-font-style: normal;
16
+ --conloca-prose-line-height: 1.7;
17
+ --conloca-prose-letter-spacing: normal;
18
+ --conloca-prose-color: #181818;
19
+ }
20
+ .dark,
21
+ :root[data-theme="dark"] {
22
+ --conloca-prose-color: #fafafa;
23
+ }
24
+
25
+ /* L0 heading scale. Tailwind preflight sets `h1..h6 { font-size: inherit;
26
+ font-weight: inherit }`, so BlockType → Heading looks identical to a
27
+ paragraph unless something restores real sizes. Use :where() so specificity
28
+ stays (0,0,1) and later host-probe rules (also unlayered, same specificity)
29
+ can override when auto-match lands. */
30
+ :where(.conloca-prose--editor) h1 {
31
+ font-size: 2.25em;
32
+ font-weight: 700;
33
+ line-height: 1.2;
34
+ }
35
+ :where(.conloca-prose--editor) h2 {
36
+ font-size: 1.75em;
37
+ font-weight: 700;
38
+ line-height: 1.25;
39
+ }
40
+ :where(.conloca-prose--editor) h3 {
41
+ font-size: 1.375em;
42
+ font-weight: 600;
43
+ line-height: 1.3;
44
+ }
45
+ :where(.conloca-prose--editor) h4 {
46
+ font-size: 1.125em;
47
+ font-weight: 600;
48
+ line-height: 1.35;
49
+ }
50
+ :where(.conloca-prose--editor) h5 {
51
+ font-size: 1em;
52
+ font-weight: 600;
53
+ line-height: 1.4;
54
+ }
55
+ :where(.conloca-prose--editor) h6 {
56
+ font-size: 0.875em;
57
+ font-weight: 600;
58
+ line-height: 1.4;
59
+ }
60
+
61
+ /* Editor chrome styles only. Prose typography is intentionally NOT
62
+ shipped from this package — the host's own prose CSS (Starlight's
63
+ `.sl-markdown-content`, Tailwind Typography's `.prose`, etc.) reaches
64
+ the editor's content via the cascade, because the host-wrapper plugin
65
+ wraps the contenteditable in a clone of the host's content-root
66
+ element. Shipping our own typography here was a drift source — every
67
+ Starlight update misaligned the mirror. Removed.
68
+
69
+ Code-block chrome (borders, backgrounds, header bar styling, CodeMirror
70
+ surface overrides, design tokens, font sizing) is ALSO intentionally
71
+ NOT shipped from this package. Same reason: the host's code-block CSS
72
+ reaches the editor's `.conloca-code-block` element via the wrapper
73
+ auto-copy (which adds `expressive-code frame has-title not-content`
74
+ classes from the discovered host wrapper). Conloca shipping a parallel
75
+ chrome was a hand-maintained mirror that drifted on every host update.
76
+
77
+ The only rules retained here are layout primitives MDXEditor itself
78
+ needs to function inside a flex-column shell: toolbar wrap behavior,
79
+ flex layout on the editor root, the diff/source wrapper's scroll
80
+ container, and the responsive breakpoint adjustments. Nothing visual,
81
+ nothing decorative, nothing host-mirrored. */
82
+
83
+ /* Workaround for mdx-editor/editor#908: the toolbar root is flex-row by
84
+ default and overflows horizontally on narrow viewports. Wrapping is the
85
+ library author's recommended workaround until the upstream offers a
86
+ responsive primitive — applied via `toolbarClassName` in editor-core.tsx. */
87
+ .mdxeditor-toolbar-wrap {
88
+ flex-wrap: wrap;
89
+ row-gap: 4px;
90
+ /* Pin to top inside the flex-column layout below; the content area
91
+ absorbs the remaining height. Without this the toolbar can shrink
92
+ when the editor is mounted in a constrained-height column. */
93
+ flex-shrink: 0;
94
+ }
95
+
96
+ /* Editor layout for page-route mounts (CMS `/pages/:id`, `/fragments/:id`).
97
+ MDXEditor's root defaults to `display: block`, so when the consumer
98
+ parks it in a fixed-height column, the toolbar floats on top and the
99
+ tall content has no scroll container. Turn the root into a flex
100
+ column so the toolbar pins to the top and the rich-text body scrolls
101
+ inside its allotted slice. */
102
+ .mdxeditor {
103
+ display: flex;
104
+ flex-direction: column;
105
+ height: 100%;
106
+ min-height: 0;
107
+ }
108
+
109
+ .mdxeditor-diff-source-wrapper {
110
+ flex: 1;
111
+ /* `min-height: 0` lets this flex child shrink past its content height
112
+ so overflow-y has something to actually scroll past. */
113
+ min-height: 0;
114
+ overflow-y: auto;
115
+ }
116
+
117
+ /* @mdxeditor/editor's BlockTypeSelect renders an empty label when the
118
+ cursor sits inside a custom JSX block (currentBlockType$ stays "" until
119
+ selection moves back into a paragraph/heading). Surface a visible
120
+ placeholder so the control isn't a bare caret. */
121
+ .mdxeditor-toolbar-wrap [aria-label="Block type"] > span:first-child:empty::before {
122
+ content: "Block";
123
+ opacity: 0.6;
124
+ }
125
+
126
+ /* Compress the toolbar on narrow viewports so all controls remain reachable
127
+ instead of wrapping below the visible row. Targets sm breakpoint. */
128
+ @media (max-width: 640px) {
129
+ .mdxeditor-toolbar-wrap {
130
+ gap: 2px;
131
+ row-gap: 2px;
132
+ }
133
+ .mdxeditor-toolbar-wrap button {
134
+ padding-inline: 4px;
135
+ }
136
+ /* Hide visual group separators on narrow screens; wrap rows still convey grouping. */
137
+ .mdxeditor-toolbar-wrap [data-orientation="vertical"] {
138
+ display: none;
139
+ }
140
+ /* @mdxeditor/editor groups the formatting controls inside a flex-nowrap
141
+ row that overflows past the viewport on phones, clipping ~17 buttons
142
+ (Block, link, image, table, hr, code-block, …). Force that inner row
143
+ to wrap so every control stays tappable without horizontal scroll. */
144
+ .mdxeditor-toolbar-wrap > div:first-child {
145
+ flex-wrap: wrap;
146
+ row-gap: 2px;
147
+ }
148
+ }
149
+
150
+ /* Library neutralization — purely transparency / zero overrides for
151
+ bundled third-party libraries (MDXEditor, CodeMirror) so they don't
152
+ visually fight the host's cascade. No colors, no borders, no fonts,
153
+ no opinions shipped from Conloca — these rules ONLY silence library
154
+ defaults that would otherwise leak through.
155
+
156
+ A developer integrating Conloca expects the editor to be a transparent
157
+ shell: the host's CSS flows in via the wrapper auto-copy, and library
158
+ internals (which the developer can't easily reach) don't paint over
159
+ it. Without these neutralizations, MDXEditor's bundled gray border
160
+ and CodeMirror's white background end up looking like Conloca's
161
+ opinions about how a code block should appear. They aren't — they're
162
+ the third-party libraries asserting themselves.
163
+
164
+ These selectors are scoped to `.conloca-code-block` so they only
165
+ touch the editor's code-block frame, not unrelated CodeMirror or
166
+ MDXEditor instances elsewhere on the page. */
167
+
168
+ /* MDXEditor's `._editorRoot_*` rule sets `font-family: var(--font-body)`
169
+ and `color: var(--baseText)`; its `._contentEditable_*` rule sets
170
+ `color: var(--baseTextContrast)`. Both inherit / apply through the
171
+ host-wrapper auto-copy and override what would otherwise inherit
172
+ from the host's body typography. Wire the host's actual typography
173
+ (computed by the iframe probe in cms-spa, published as
174
+ `--conloca-host-*` custom properties on `:root`) into MDXEditor's
175
+ contenteditable so the editing surface matches the published page.
176
+
177
+ Fallback chain (L1 host → L0 Conloca prose baseline → last-ditch
178
+ system stack). Do NOT fall back to bare `inherit` — that silently
179
+ picks up the admin shell body font (`--puck-font-family`), which is
180
+ product chrome, not content typography.
181
+
182
+ This sheet pulls `@mdxeditor/editor/style.css` in ahead of its own
183
+ rules, BUT MDXEditor injects its CSS-module styles dynamically at mount
184
+ time, placing them later in the document. Source-order tiebreaks give
185
+ MDXEditor the win on equal-specificity rules. Chain with
186
+ `.conloca-prose` (the static base class we apply alongside
187
+ `conloca-prose--editor`) to push our specificity to (0,2,0), beating
188
+ MDXEditor's bare `._contentEditable_*` (0,1,0). */
189
+ [class*="_contentEditable_"].conloca-prose {
190
+ font-family: var(--conloca-host-font-family, var(--conloca-prose-font-family, ui-sans-serif, system-ui, sans-serif));
191
+ font-size: var(--conloca-host-font-size, var(--conloca-prose-font-size, 1rem));
192
+ font-weight: var(--conloca-host-font-weight, var(--conloca-prose-font-weight, 400));
193
+ font-style: var(--conloca-host-font-style, var(--conloca-prose-font-style, normal));
194
+ line-height: var(--conloca-host-line-height, var(--conloca-prose-line-height, 1.7));
195
+ letter-spacing: var(--conloca-host-letter-spacing, var(--conloca-prose-letter-spacing, normal));
196
+ color: var(--conloca-host-color, var(--conloca-prose-color, CanvasText));
197
+ }
198
+
199
+ /* MDXEditor's `._listitem_*` rule adds `margin: 8px 0` to every list
200
+ item it generates inside the contenteditable. Hosts (Starlight,
201
+ Tailwind Typography, etc.) typically collapse list-item margins to 0
202
+ and rely on the parent `<ul>`/`<ol>` for vertical rhythm. The 8px
203
+ gap pushes editor lists out of parity with the published page.
204
+ Zero it out under `.conloca-prose` so the host's list spacing rules
205
+ (or the editor's probe-emitted li defaults) reach the element
206
+ unobstructed. Specificity (0,2,0) beats MDXEditor's bare `._listitem_*`
207
+ (0,1,0) so we win regardless of source order (MDXEditor's CSS
208
+ module is injected at component-mount time, AFTER editor-styles.css). */
209
+ .conloca-prose [class*="_listitem_"] {
210
+ margin-block: 0;
211
+ }
212
+
213
+ /* MDXEditor wraps CodeMirror in a hash-suffixed `_codeMirrorWrapper_*`
214
+ div that ships with `margin`, `padding`, `border`, `border-radius`,
215
+ `background`, AND `position: relative` of its own. Attribute selector
216
+ covers hash rotations across library upgrades.
217
+ `position: static` is the key piece for toolbar placement: MDXEditor
218
+ absolutely-positions its `_codeMirrorToolbar_*` (language combobox +
219
+ delete button) at `top:0; right:0` relative to its nearest positioned
220
+ ancestor. With the wrapper relative, that ancestor IS the wrapper —
221
+ so the toolbar lands ON TOP OF the first line of code. Making the
222
+ wrapper static promotes the toolbar's containing block to the next
223
+ positioned ancestor (our `.conloca-code-block` figure, see rule
224
+ below), where it sits in the title-bar region instead. */
225
+ .conloca-code-block [class*="codeMirrorWrapper"] {
226
+ margin: 0;
227
+ padding: 0;
228
+ border: 0;
229
+ border-radius: 0;
230
+ background: transparent;
231
+ position: static;
232
+ }
233
+
234
+ /* The frame element (figure) becomes the containing block for
235
+ MDXEditor's absolutely-positioned code-block toolbar. Paired with the
236
+ `position: static` override above so the toolbar lands at the
237
+ figure's top-right (alongside the editable filename) instead of
238
+ overlapping code. */
239
+ .conloca-code-block {
240
+ position: relative;
241
+ }
242
+
243
+ /* The filename slot sits inside `<span class="title">`, so the host's
244
+ `.frame .title` styling (expressive-code's tab background, padding,
245
+ font) paints the SPAN. The `<input>` we render inside must visually
246
+ disappear into that styled span — otherwise its UA chrome (border,
247
+ background, padding, monospace fallback) leaves a smaller-looking
248
+ field nested inside the larger tab.
249
+ `all: unset` neutralizes the UA defaults; then we set just the
250
+ typography handoff (`inherit` font/color from the span) and a width
251
+ so it spans the tab's editable area. `min-width: 0` prevents
252
+ intrinsic width from forcing the tab wider than the host expects on
253
+ long filenames. */
254
+ .conloca-code-block__filename {
255
+ all: unset;
256
+ font: inherit;
257
+ color: inherit;
258
+ width: 100%;
259
+ min-width: 0;
260
+ cursor: text;
261
+ box-sizing: border-box;
262
+ }
263
+ /* Subtle focus indicator so the input is discoverable as editable —
264
+ the published page renders a static span, so we don't have prior
265
+ art here. A 1px underline matches the rhythm of the title tab and
266
+ doesn't add chrome the host wasn't expecting. */
267
+ .conloca-code-block__filename:focus {
268
+ outline: 1px dashed currentColor;
269
+ outline-offset: 2px;
270
+ }
271
+
272
+ /* CodeMirror's default theme paints the editor surface white. Override
273
+ to transparent so the host's parent background flows through — which
274
+ matches the published page where every code-block wrapper is also
275
+ transparent and the body bg supplies the visible color. */
276
+ .conloca-code-block .cm-editor,
277
+ .conloca-code-block .cm-editor .cm-scroller,
278
+ .conloca-code-block .cm-editor .cm-gutters,
279
+ .conloca-code-block .cm-editor .cm-content,
280
+ .conloca-code-block .cm-editor .cm-line {
281
+ background: transparent;
282
+ }