@bendyline/squisq-editor-react 1.2.1 → 1.3.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 (105) hide show
  1. package/dist/EditorContext.d.ts +65 -1
  2. package/dist/EditorContext.d.ts.map +1 -1
  3. package/dist/EditorContext.js +31 -4
  4. package/dist/EditorContext.js.map +1 -1
  5. package/dist/EditorShell.d.ts +101 -2
  6. package/dist/EditorShell.d.ts.map +1 -1
  7. package/dist/EditorShell.js +20 -8
  8. package/dist/EditorShell.js.map +1 -1
  9. package/dist/ImageNodeView.d.ts.map +1 -1
  10. package/dist/ImageNodeView.js +12 -2
  11. package/dist/ImageNodeView.js.map +1 -1
  12. package/dist/MediaBin.d.ts.map +1 -1
  13. package/dist/MediaBin.js +16 -1
  14. package/dist/MediaBin.js.map +1 -1
  15. package/dist/MentionExtension.d.ts +22 -0
  16. package/dist/MentionExtension.d.ts.map +1 -0
  17. package/dist/MentionExtension.js +242 -0
  18. package/dist/MentionExtension.js.map +1 -0
  19. package/dist/PreviewPanel.d.ts +3 -8
  20. package/dist/PreviewPanel.d.ts.map +1 -1
  21. package/dist/PreviewPanel.js +4 -282
  22. package/dist/PreviewPanel.js.map +1 -1
  23. package/dist/RawEditor.d.ts +8 -1
  24. package/dist/RawEditor.d.ts.map +1 -1
  25. package/dist/RawEditor.js +167 -30
  26. package/dist/RawEditor.js.map +1 -1
  27. package/dist/TemplateAnnotation.d.ts.map +1 -1
  28. package/dist/TemplateAnnotation.js +4 -2
  29. package/dist/TemplateAnnotation.js.map +1 -1
  30. package/dist/Toolbar.d.ts +7 -1
  31. package/dist/Toolbar.d.ts.map +1 -1
  32. package/dist/Toolbar.js +57 -18
  33. package/dist/Toolbar.js.map +1 -1
  34. package/dist/Tooltip.d.ts +10 -0
  35. package/dist/Tooltip.d.ts.map +1 -0
  36. package/dist/Tooltip.js +104 -0
  37. package/dist/Tooltip.js.map +1 -0
  38. package/dist/ViewSwitcher.d.ts +1 -1
  39. package/dist/ViewSwitcher.d.ts.map +1 -1
  40. package/dist/ViewSwitcher.js +10 -4
  41. package/dist/ViewSwitcher.js.map +1 -1
  42. package/dist/WysiwygEditor.d.ts +13 -2
  43. package/dist/WysiwygEditor.d.ts.map +1 -1
  44. package/dist/WysiwygEditor.js +239 -4
  45. package/dist/WysiwygEditor.js.map +1 -1
  46. package/dist/__tests__/detectMarkdown.test.d.ts +2 -0
  47. package/dist/__tests__/detectMarkdown.test.d.ts.map +1 -0
  48. package/dist/__tests__/detectMarkdown.test.js +69 -0
  49. package/dist/__tests__/detectMarkdown.test.js.map +1 -0
  50. package/dist/__tests__/fileKind.test.d.ts +2 -0
  51. package/dist/__tests__/fileKind.test.d.ts.map +1 -0
  52. package/dist/__tests__/fileKind.test.js +81 -0
  53. package/dist/__tests__/fileKind.test.js.map +1 -0
  54. package/dist/__tests__/tiptapBridge.test.js +36 -0
  55. package/dist/__tests__/tiptapBridge.test.js.map +1 -1
  56. package/dist/buildPreviewDoc.d.ts +22 -0
  57. package/dist/buildPreviewDoc.d.ts.map +1 -0
  58. package/dist/buildPreviewDoc.js +212 -0
  59. package/dist/buildPreviewDoc.js.map +1 -0
  60. package/dist/detectMarkdown.d.ts +20 -0
  61. package/dist/detectMarkdown.d.ts.map +1 -0
  62. package/dist/detectMarkdown.js +61 -0
  63. package/dist/detectMarkdown.js.map +1 -0
  64. package/dist/fileKind.d.ts +30 -0
  65. package/dist/fileKind.d.ts.map +1 -0
  66. package/dist/fileKind.js +123 -0
  67. package/dist/fileKind.js.map +1 -0
  68. package/dist/hooks/useFileDrop.d.ts.map +1 -1
  69. package/dist/hooks/useFileDrop.js +9 -7
  70. package/dist/hooks/useFileDrop.js.map +1 -1
  71. package/dist/index.d.ts +5 -1
  72. package/dist/index.d.ts.map +1 -1
  73. package/dist/index.js +6 -0
  74. package/dist/index.js.map +1 -1
  75. package/dist/mediaDragMime.d.ts +17 -0
  76. package/dist/mediaDragMime.d.ts.map +1 -0
  77. package/dist/mediaDragMime.js +22 -0
  78. package/dist/mediaDragMime.js.map +1 -0
  79. package/dist/tiptapBridge.d.ts.map +1 -1
  80. package/dist/tiptapBridge.js +58 -2
  81. package/dist/tiptapBridge.js.map +1 -1
  82. package/package.json +9 -7
  83. package/src/EditorContext.tsx +106 -3
  84. package/src/EditorShell.tsx +195 -15
  85. package/src/ImageNodeView.tsx +15 -2
  86. package/src/MediaBin.tsx +23 -1
  87. package/src/MentionExtension.tsx +258 -0
  88. package/src/PreviewPanel.tsx +5 -333
  89. package/src/RawEditor.tsx +193 -37
  90. package/src/TemplateAnnotation.ts +4 -2
  91. package/src/Toolbar.tsx +111 -48
  92. package/src/Tooltip.tsx +124 -0
  93. package/src/ViewSwitcher.tsx +15 -5
  94. package/src/WysiwygEditor.tsx +270 -5
  95. package/src/__tests__/detectMarkdown.test.ts +88 -0
  96. package/src/__tests__/fileKind.test.ts +96 -0
  97. package/src/__tests__/tiptapBridge.test.ts +44 -0
  98. package/src/buildPreviewDoc.ts +254 -0
  99. package/src/detectMarkdown.ts +62 -0
  100. package/src/fileKind.ts +134 -0
  101. package/src/hooks/useFileDrop.ts +10 -6
  102. package/src/index.ts +14 -0
  103. package/src/mediaDragMime.ts +32 -0
  104. package/src/styles/editor.css +214 -8
  105. package/src/tiptapBridge.ts +66 -2
@@ -0,0 +1,254 @@
1
+ /**
2
+ * buildPreviewDoc — Converts a markdown-derived Doc into a player-ready Doc
3
+ * with TemplateBlock slides and interleaved images.
4
+ *
5
+ * Shared between PreviewPanel (live preview) and export flows (HTML/video).
6
+ *
7
+ * Pipeline:
8
+ * 1. Flatten hierarchical blocks into a linear slide sequence
9
+ * 2. Convert each block into a TemplateBlock-compatible object
10
+ * 3. Interleave images as standalone imageWithCaption slides
11
+ * 4. Synthesize a dummy audio segment for timer-based playback
12
+ */
13
+
14
+ import { flattenBlocks, hasTemplate } from '@bendyline/squisq/doc';
15
+ import { extractPlainText } from '@bendyline/squisq/markdown';
16
+ import { getChildren } from '@bendyline/squisq/markdown';
17
+ import type { Block, Doc } from '@bendyline/squisq/schemas';
18
+ import type { MarkdownBlockNode, MarkdownList, MarkdownNode } from '@bendyline/squisq/markdown';
19
+
20
+ // ── Helpers ────────────────────────────────────────────────────────
21
+
22
+ function extractBodyText(contents: MarkdownBlockNode[] | undefined): string {
23
+ if (!contents || contents.length === 0) return '';
24
+ const parts: string[] = [];
25
+ for (const node of contents) {
26
+ parts.push(extractPlainText(node));
27
+ }
28
+ return parts.join('\n').trim();
29
+ }
30
+
31
+ function extractBlockImages(
32
+ contents: MarkdownBlockNode[] | undefined,
33
+ ): Array<{ src: string; alt: string }> {
34
+ if (!contents || contents.length === 0) return [];
35
+ const images: Array<{ src: string; alt: string }> = [];
36
+
37
+ function walk(node: MarkdownNode): void {
38
+ if ('type' in node && node.type === 'image' && 'url' in node) {
39
+ const img = node as { url: string; alt?: string };
40
+ if (img.url) {
41
+ images.push({ src: img.url, alt: img.alt ?? '' });
42
+ }
43
+ }
44
+ for (const child of getChildren(node)) {
45
+ walk(child);
46
+ }
47
+ }
48
+
49
+ for (const node of contents) {
50
+ walk(node);
51
+ }
52
+ return images;
53
+ }
54
+
55
+ function collectAllDocImages(blocks: Block[]): Array<{ src: string; alt: string }> {
56
+ const seen = new Set<string>();
57
+ const images: Array<{ src: string; alt: string }> = [];
58
+
59
+ function walkBlocks(blockList: Block[]): void {
60
+ for (const block of blockList) {
61
+ for (const img of extractBlockImages(block.contents)) {
62
+ if (!seen.has(img.src)) {
63
+ seen.add(img.src);
64
+ images.push(img);
65
+ }
66
+ }
67
+ if (block.children) {
68
+ walkBlocks(block.children);
69
+ }
70
+ }
71
+ }
72
+
73
+ walkBlocks(blocks);
74
+ return images;
75
+ }
76
+
77
+ function extractListItems(contents: MarkdownBlockNode[] | undefined): string[] {
78
+ if (!contents) return [];
79
+ const items: string[] = [];
80
+ for (const node of contents) {
81
+ if (node.type === 'list') {
82
+ for (const item of (node as MarkdownList).children) {
83
+ const text = extractPlainText(item).trim();
84
+ if (text) items.push(text);
85
+ }
86
+ }
87
+ }
88
+ return items;
89
+ }
90
+
91
+ function getTemplateDefaults(
92
+ templateName: string,
93
+ headingText: string,
94
+ block: Block,
95
+ ): Record<string, unknown> {
96
+ const body = extractBodyText(block.contents);
97
+
98
+ switch (templateName) {
99
+ case 'statHighlight':
100
+ return { stat: headingText, description: body || headingText };
101
+ case 'quoteBlock':
102
+ case 'fullBleedQuote':
103
+ case 'pullQuote':
104
+ return { quote: body || headingText };
105
+ case 'factCard':
106
+ return { fact: headingText, explanation: body || headingText };
107
+ case 'comparisonBar':
108
+ return { leftLabel: 'A', leftValue: 60, rightLabel: 'B', rightValue: 40 };
109
+ case 'listBlock': {
110
+ const items = extractListItems(block.contents);
111
+ return { items: items.length > 0 ? items : ['Item 1', 'Item 2', 'Item 3'] };
112
+ }
113
+ case 'definitionCard':
114
+ return { term: headingText, definition: body || headingText };
115
+ case 'dateEvent':
116
+ return { date: headingText, description: body || headingText };
117
+ default:
118
+ return {};
119
+ }
120
+ }
121
+
122
+ function blockToSlide(block: Block, index: number): Record<string, unknown> {
123
+ const headingText = block.sourceHeading
124
+ ? extractPlainText(block.sourceHeading)
125
+ : block.title || block.id || `Slide ${index + 1}`;
126
+
127
+ const requestedTemplate = block.template || 'sectionHeader';
128
+ const template = hasTemplate(requestedTemplate) ? requestedTemplate : 'sectionHeader';
129
+ const defaults = getTemplateDefaults(template, headingText, block);
130
+
131
+ const {
132
+ id: _id,
133
+ startTime: _st,
134
+ duration: _d,
135
+ audioSegment: _as,
136
+ layers: _l,
137
+ transition: _tr,
138
+ template: _t,
139
+ title: _ti,
140
+ children: _c,
141
+ contents: _co,
142
+ sourceHeading: _sh,
143
+ templateOverrides: _to,
144
+ ...extraFields
145
+ } = block as unknown as Record<string, unknown>;
146
+
147
+ return {
148
+ id: block.id,
149
+ template,
150
+ duration: block.duration,
151
+ audioSegment: 0,
152
+ transition: index > 0 ? { type: 'fade', duration: 0.5 } : undefined,
153
+ title: headingText,
154
+ ...defaults,
155
+ ...extraFields,
156
+ ...block.templateOverrides,
157
+ };
158
+ }
159
+
160
+ const IMAGE_MOTIONS: Array<'zoomIn' | 'zoomOut' | 'panLeft' | 'panRight'> = [
161
+ 'zoomIn',
162
+ 'zoomOut',
163
+ 'panLeft',
164
+ 'panRight',
165
+ ];
166
+
167
+ // ── Public API ─────────────────────────────────────────────────────
168
+
169
+ /**
170
+ * Build a player-ready Doc from a markdown-derived Doc.
171
+ *
172
+ * Flattens hierarchical blocks, converts each to a TemplateBlock-compatible
173
+ * slide, interleaves images, recalculates timing, and adds a synthetic
174
+ * audio segment.
175
+ */
176
+ export function buildPreviewDoc(doc: Doc): Doc {
177
+ const flat = flattenBlocks(doc.blocks);
178
+ const allImages = collectAllDocImages(doc.blocks);
179
+ const usedImageSrcs = new Set<string>();
180
+
181
+ const slides: Record<string, unknown>[] = [];
182
+ let motionIndex = 0;
183
+
184
+ for (let i = 0; i < flat.length; i++) {
185
+ const block = flat[i];
186
+ const blockImages = extractBlockImages(block.contents);
187
+ const slide = blockToSlide(block, i);
188
+
189
+ if (blockImages.length > 0 && slide.template === 'sectionHeader') {
190
+ const img = blockImages[0];
191
+ usedImageSrcs.add(img.src);
192
+ slide.template = 'imageWithCaption';
193
+ slide.imageSrc = img.src;
194
+ slide.imageAlt = img.alt;
195
+ slide.caption = slide.title as string;
196
+ slide.captionPosition = 'bottom';
197
+ slide.ambientMotion = IMAGE_MOTIONS[motionIndex++ % IMAGE_MOTIONS.length];
198
+ } else if (blockImages.length > 0) {
199
+ const img = blockImages[0];
200
+ usedImageSrcs.add(img.src);
201
+ if (!slide.accentImage) {
202
+ slide.accentImage = {
203
+ src: img.src,
204
+ alt: img.alt,
205
+ position: 'left-strip',
206
+ ambientMotion: IMAGE_MOTIONS[motionIndex++ % IMAGE_MOTIONS.length],
207
+ };
208
+ }
209
+ }
210
+
211
+ slides.push(slide);
212
+ }
213
+
214
+ // Interleave unused images
215
+ const unusedImages = allImages.filter((img) => !usedImageSrcs.has(img.src));
216
+ if (unusedImages.length > 0 && slides.length > 0) {
217
+ const interval = Math.max(2, Math.floor(slides.length / (unusedImages.length + 1)));
218
+ let insertOffset = 0;
219
+ for (let imgIdx = 0; imgIdx < unusedImages.length; imgIdx++) {
220
+ const insertAt = Math.min((imgIdx + 1) * interval + insertOffset, slides.length);
221
+ const img = unusedImages[imgIdx];
222
+ slides.splice(insertAt, 0, {
223
+ id: `img-interleave-${imgIdx}`,
224
+ template: 'imageWithCaption',
225
+ duration: 5,
226
+ audioSegment: 0,
227
+ imageSrc: img.src,
228
+ imageAlt: img.alt,
229
+ ambientMotion: IMAGE_MOTIONS[motionIndex++ % IMAGE_MOTIONS.length],
230
+ transition: { type: 'fade', duration: 0.5 },
231
+ });
232
+ insertOffset++;
233
+ }
234
+ }
235
+
236
+ // Recalculate timing
237
+ let t = 0;
238
+ for (const slide of slides) {
239
+ slide.startTime = t;
240
+ t += slide.duration as number;
241
+ }
242
+
243
+ return {
244
+ articleId: doc.articleId,
245
+ duration: t,
246
+ blocks: slides as unknown as Block[],
247
+ audio: {
248
+ segments: t > 0 ? [{ src: '', name: 'preview', duration: t, startTime: 0 }] : [],
249
+ },
250
+ ...(doc.captions ? { captions: doc.captions } : {}),
251
+ ...(doc.startBlock ? { startBlock: doc.startBlock } : {}),
252
+ ...(doc.themeId ? { themeId: doc.themeId } : {}),
253
+ };
254
+ }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Markdown detection — heuristic for spotting markdown source in pasted text.
3
+ *
4
+ * Used by the WYSIWYG editor's paste handler to decide whether plain-text
5
+ * paste content should be parsed as markdown rather than inserted literally.
6
+ *
7
+ * The heuristic prefers false negatives (treating markdown as plain text)
8
+ * over false positives (mangling plain text that happens to contain a few
9
+ * special characters).
10
+ */
11
+
12
+ /** Block-level patterns that strongly indicate markdown. Any one is enough. */
13
+ const STRONG_BLOCK_PATTERNS: RegExp[] = [
14
+ /^#{1,6}\s+\S/, // # Heading
15
+ /^[-*+]\s+\S/, // - bullet
16
+ /^\d+\.\s+\S/, // 1. ordered
17
+ /^>\s+\S/, // > blockquote
18
+ /^```/, // ``` code fence
19
+ /^\|.+\|\s*$/, // | table | row |
20
+ /^[-*+]\s+\[[ xX]\]\s+/, // - [ ] task
21
+ ];
22
+
23
+ /** Inline patterns that are weaker indicators on their own. */
24
+ const INLINE_PATTERNS: RegExp[] = [
25
+ /\*\*[^*\n]+\*\*/, // **bold**
26
+ /__[^_\n]+__/, // __bold__
27
+ /`[^`\n]+`/, // `code`
28
+ /\[[^\]\n]+\]\([^)\n]+\)/, // [link](url)
29
+ /!\[[^\]\n]*\]\([^)\n]+\)/, // ![image](url)
30
+ /~~[^~\n]+~~/, // ~~strike~~
31
+ ];
32
+
33
+ /**
34
+ * Returns true if the text looks like markdown source.
35
+ *
36
+ * Detection rules:
37
+ * - Any line matching a strong block pattern → yes
38
+ * - Two or more inline pattern matches anywhere in the text → yes
39
+ * - Otherwise → no
40
+ */
41
+ export function looksLikeMarkdown(text: string): boolean {
42
+ if (!text || text.length < 2) return false;
43
+
44
+ const lines = text.split(/\r?\n/);
45
+ for (const line of lines) {
46
+ const trimmed = line.trim();
47
+ if (!trimmed) continue;
48
+ for (const re of STRONG_BLOCK_PATTERNS) {
49
+ if (re.test(trimmed)) return true;
50
+ }
51
+ }
52
+
53
+ let inlineHits = 0;
54
+ for (const re of INLINE_PATTERNS) {
55
+ if (re.test(text)) {
56
+ inlineHits++;
57
+ if (inlineHits >= 2) return true;
58
+ }
59
+ }
60
+
61
+ return false;
62
+ }
@@ -0,0 +1,134 @@
1
+ /**
2
+ * fileKind
3
+ *
4
+ * Maps a file name (or bare extension) to a Monaco language ID and decides
5
+ * whether the editor shell should operate in markdown mode (full WYSIWYG +
6
+ * Preview experience) or code mode (Monaco-only view with formatting
7
+ * buttons hidden).
8
+ *
9
+ * The mapping favors common web / systems languages that Monaco ships with
10
+ * out of the box. Unknown extensions fall back to markdown mode so the
11
+ * existing UX remains the default for anything we don't recognize.
12
+ */
13
+
14
+ export interface FileKind {
15
+ /** 'markdown' keeps the full editor (WYSIWYG + Preview tabs); 'code' is Monaco-only. */
16
+ mode: 'markdown' | 'code';
17
+ /** Monaco language ID — passed to `<Editor defaultLanguage={...} />`. */
18
+ language: string;
19
+ }
20
+
21
+ /**
22
+ * Extension → Monaco language ID. Keys are lowercase, no leading dot.
23
+ * Extend as needed; unknown extensions fall back to markdown mode.
24
+ */
25
+ const EXT_TO_LANGUAGE: Record<string, string> = {
26
+ md: 'markdown',
27
+ markdown: 'markdown',
28
+ mdown: 'markdown',
29
+ txt: 'plaintext',
30
+ ts: 'typescript',
31
+ tsx: 'typescript',
32
+ js: 'javascript',
33
+ jsx: 'javascript',
34
+ mjs: 'javascript',
35
+ cjs: 'javascript',
36
+ json: 'json',
37
+ jsonc: 'json',
38
+ html: 'html',
39
+ htm: 'html',
40
+ css: 'css',
41
+ scss: 'scss',
42
+ less: 'less',
43
+ py: 'python',
44
+ go: 'go',
45
+ rs: 'rust',
46
+ rb: 'ruby',
47
+ java: 'java',
48
+ c: 'c',
49
+ h: 'c',
50
+ cpp: 'cpp',
51
+ hpp: 'cpp',
52
+ cc: 'cpp',
53
+ cs: 'csharp',
54
+ php: 'php',
55
+ sh: 'shell',
56
+ bash: 'shell',
57
+ zsh: 'shell',
58
+ yml: 'yaml',
59
+ yaml: 'yaml',
60
+ toml: 'ini',
61
+ ini: 'ini',
62
+ xml: 'xml',
63
+ svg: 'xml',
64
+ sql: 'sql',
65
+ lua: 'lua',
66
+ swift: 'swift',
67
+ kt: 'kotlin',
68
+ kts: 'kotlin',
69
+ dockerfile: 'dockerfile',
70
+ };
71
+
72
+ /**
73
+ * Languages that keep the full markdown shell (WYSIWYG + Preview). Anything
74
+ * outside this set is treated as code.
75
+ */
76
+ const MARKDOWN_MODE_LANGUAGES = new Set(['markdown', 'plaintext']);
77
+
78
+ /**
79
+ * Pull the lowercase extension (no leading dot) from a file name or bare
80
+ * extension string. Returns null when none is discernible.
81
+ *
82
+ * Examples:
83
+ * "foo.ts" → "ts"
84
+ * "foo.tar.gz" → "gz"
85
+ * ".ts" → "ts"
86
+ * "ts" → "ts"
87
+ * "Dockerfile" → "dockerfile" (full name match for extensionless files)
88
+ * "" → null
89
+ */
90
+ function extractExtension(fileName: string): string | null {
91
+ const trimmed = fileName.trim();
92
+ if (!trimmed) return null;
93
+
94
+ // Strip any leading path — take only the basename.
95
+ const base = trimmed.replace(/^.*[/\\]/, '');
96
+ if (!base) return null;
97
+
98
+ const dotIdx = base.lastIndexOf('.');
99
+ if (dotIdx === -1) {
100
+ // No dot — could still be a recognized bare name (Dockerfile) or a bare
101
+ // extension passed by a caller like "ts". Lower-case and return.
102
+ return base.toLowerCase();
103
+ }
104
+ if (dotIdx === base.length - 1) return null; // Trailing dot, no extension.
105
+ return base.slice(dotIdx + 1).toLowerCase();
106
+ }
107
+
108
+ /**
109
+ * Detect a Monaco language ID from a file name. Returns null when the
110
+ * extension (or bare name) is not in the mapping.
111
+ */
112
+ export function detectLanguageFromFileName(fileName: string): string | null {
113
+ const ext = extractExtension(fileName);
114
+ if (!ext) return null;
115
+ return EXT_TO_LANGUAGE[ext] ?? null;
116
+ }
117
+
118
+ /**
119
+ * Resolve the editor mode + Monaco language for a given file. The explicit
120
+ * `language` argument, if provided, wins over any detection from
121
+ * `fileName`. When nothing matches, falls back to markdown mode.
122
+ */
123
+ export function resolveFileKind(fileName?: string, language?: string): FileKind {
124
+ const resolvedLanguage = language ?? (fileName ? detectLanguageFromFileName(fileName) : null);
125
+
126
+ if (!resolvedLanguage) {
127
+ return { mode: 'markdown', language: 'markdown' };
128
+ }
129
+
130
+ const mode: FileKind['mode'] = MARKDOWN_MODE_LANGUAGES.has(resolvedLanguage)
131
+ ? 'markdown'
132
+ : 'code';
133
+ return { mode, language: resolvedLanguage };
134
+ }
@@ -137,17 +137,21 @@ export function useFileDrop({ onDrop, enabled = true }: UseFileDropOptions): Use
137
137
  const handleDragEnter = useCallback(
138
138
  (e: React.DragEvent) => {
139
139
  if (!enabled) return;
140
+
141
+ // Only react to OS file drags. In-app drags (e.g. dragging a thumbnail
142
+ // out of the MediaBin) don't carry file-kind items and must pass
143
+ // through to the editors without showing the drop overlay.
144
+ const classification = e.dataTransfer.items
145
+ ? classifyDataTransferItems(e.dataTransfer.items)
146
+ : 'mixed';
147
+ if (!classification) return;
148
+
140
149
  e.preventDefault();
141
150
  dragCounterRef.current++;
142
151
 
143
152
  if (dragCounterRef.current === 1) {
144
153
  setIsDragging(true);
145
- if (e.dataTransfer.items) {
146
- setDragContentType(classifyDataTransferItems(e.dataTransfer.items));
147
- } else {
148
- // Fallback: can't classify, show all zones
149
- setDragContentType('mixed');
150
- }
154
+ setDragContentType(classification);
151
155
  }
152
156
  },
153
157
  [enabled],
package/src/index.ts CHANGED
@@ -25,12 +25,21 @@ export type { EditorShellProps, EditorTheme } from './EditorShell.js';
25
25
  export { EditorProvider, useEditorContext } from './EditorContext.js';
26
26
  export type {
27
27
  EditorView,
28
+ EditorMode,
28
29
  EditorState,
29
30
  EditorActions,
30
31
  EditorContextValue,
31
32
  EditorProviderProps,
33
+ ImageDisplayMode,
34
+ MentionCandidate,
35
+ MentionProvider,
32
36
  } from './EditorContext.js';
33
37
 
38
+ // File-kind detection — useful for hosts that want to pre-decide chrome
39
+ // around the editor based on whether a file is markdown or code.
40
+ export { resolveFileKind, detectLanguageFromFileName } from './fileKind.js';
41
+ export type { FileKind } from './fileKind.js';
42
+
34
43
  // Individual editors (for custom layouts)
35
44
  export { RawEditor } from './RawEditor.js';
36
45
  export type { RawEditorProps } from './RawEditor.js';
@@ -60,6 +69,8 @@ export type { MediaBinProps } from './MediaBin.js';
60
69
  export { StatusBar } from './StatusBar.js';
61
70
  export type { StatusBarProps } from './StatusBar.js';
62
71
 
72
+ export { TooltipLayer } from './Tooltip.js';
73
+
63
74
  // Drag-and-drop
64
75
  export { DropZoneOverlay } from './DropZoneOverlay.js';
65
76
  export type { DropZoneOverlayProps } from './DropZoneOverlay.js';
@@ -83,5 +94,8 @@ export {
83
94
  // Bridge utilities
84
95
  export { markdownToTiptap, tiptapToMarkdown } from './tiptapBridge.js';
85
96
 
97
+ // Slideshow builder (shared between PreviewPanel and export flows)
98
+ export { buildPreviewDoc } from './buildPreviewDoc.js';
99
+
86
100
  // Tiptap extension: Heading with template annotation support
87
101
  export { HeadingWithTemplate } from './TemplateAnnotation.js';
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Shared MIME type used to signal an in-app drag from the MediaBin to either
3
+ * the Raw or WYSIWYG editor. Carries a JSON payload of the form
4
+ * `{ name, mimeType, alt }` so the receiving editor can insert a reference
5
+ * to an existing media entry without re-uploading it.
6
+ */
7
+ export const SQUISQ_MEDIA_MIME = 'application/x-squisq-media';
8
+
9
+ export interface SquisqMediaDragPayload {
10
+ /** Relative path / filename as stored in the MediaProvider. */
11
+ name: string;
12
+ /** MIME type of the entry. */
13
+ mimeType: string;
14
+ /** Default alt text derived from the filename. */
15
+ alt: string;
16
+ }
17
+
18
+ export function parseSquisqMediaPayload(raw: string): SquisqMediaDragPayload | null {
19
+ try {
20
+ const parsed = JSON.parse(raw) as Partial<SquisqMediaDragPayload>;
21
+ if (
22
+ typeof parsed.name === 'string' &&
23
+ typeof parsed.mimeType === 'string' &&
24
+ typeof parsed.alt === 'string'
25
+ ) {
26
+ return parsed as SquisqMediaDragPayload;
27
+ }
28
+ } catch {
29
+ // fall through
30
+ }
31
+ return null;
32
+ }