@bendyline/squisq-editor-react 2.1.0 → 2.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 (415) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE.md +40 -0
  3. package/dist/chunk-54UGTQBO.js +862 -0
  4. package/dist/chunk-5JMHFAVW.js +2408 -0
  5. package/dist/chunk-5Q4JN4I5.js +132 -0
  6. package/dist/chunk-6VDYKI3L.js +49 -0
  7. package/dist/chunk-GS7QWYFT.js +9 -0
  8. package/dist/chunk-MJJK7YQB.js +949 -0
  9. package/dist/chunk-NITZVAXL.js +986 -0
  10. package/dist/chunk-TRCKHRBS.js +35234 -0
  11. package/dist/chunk-V44VP242.js +3256 -0
  12. package/dist/image-editor/index.d.ts +223 -0
  13. package/dist/image-editor/index.js +15 -0
  14. package/dist/index.d.ts +2060 -4040
  15. package/dist/index.js +496 -40014
  16. package/dist/json-editor/index.d.ts +27 -0
  17. package/dist/json-editor/index.js +7 -0
  18. package/dist/monaco.d.ts +1 -1
  19. package/dist/monaco.js +1 -2
  20. package/dist/recorder/index.d.ts +407 -0
  21. package/dist/recorder/index.js +43 -0
  22. package/dist/shell/index.d.ts +9 -0
  23. package/dist/shell/index.js +22 -0
  24. package/dist/shell-BxSCBm4H.d.ts +1064 -0
  25. package/dist/styles/index.css +598 -161
  26. package/dist/teleprompter/index.d.ts +497 -0
  27. package/dist/teleprompter/index.js +57 -0
  28. package/package.json +34 -8
  29. package/dist/index.js.map +0 -1
  30. package/dist/monaco.js.map +0 -1
  31. package/src/BlockCardView.tsx +0 -121
  32. package/src/BlockPreviewPanel.tsx +0 -69
  33. package/src/BlockPropertiesPopover.tsx +0 -222
  34. package/src/DocumentSettingsDialog.tsx +0 -272
  35. package/src/DropZoneOverlay.tsx +0 -137
  36. package/src/EditorContext.tsx +0 -1274
  37. package/src/EditorShell.tsx +0 -1358
  38. package/src/EmojiPicker.tsx +0 -332
  39. package/src/FolderView.tsx +0 -131
  40. package/src/Icon.tsx +0 -26
  41. package/src/ImageEditor.tsx +0 -395
  42. package/src/ImageNodeView.tsx +0 -284
  43. package/src/ImageViewer.tsx +0 -221
  44. package/src/InlineIcon.ts +0 -84
  45. package/src/InlinePreviewGutter.tsx +0 -590
  46. package/src/LinkDialog.tsx +0 -276
  47. package/src/MediaBin.tsx +0 -500
  48. package/src/MentionExtension.tsx +0 -261
  49. package/src/OutlinePanel.tsx +0 -547
  50. package/src/PlainHtmlPreview.tsx +0 -277
  51. package/src/PreviewControls.tsx +0 -1265
  52. package/src/PreviewPanel.tsx +0 -426
  53. package/src/RawEditor.tsx +0 -743
  54. package/src/RecorderEntry.tsx +0 -162
  55. package/src/StatusBar.tsx +0 -51
  56. package/src/TemplateAnnotation.ts +0 -167
  57. package/src/TemplateContentPreview.tsx +0 -56
  58. package/src/TemplatePicker.tsx +0 -1314
  59. package/src/ThemeCustomizerPanel.tsx +0 -304
  60. package/src/ThemePicker.tsx +0 -433
  61. package/src/TimelineBlockPreview.tsx +0 -37
  62. package/src/TimelineTrack.tsx +0 -671
  63. package/src/Toolbar.tsx +0 -2885
  64. package/src/Tooltip.tsx +0 -142
  65. package/src/TransitionPicker.tsx +0 -390
  66. package/src/VersionHistoryPanel.tsx +0 -359
  67. package/src/ViewMenuPanel.tsx +0 -189
  68. package/src/ViewSwitcher.tsx +0 -56
  69. package/src/WysiwygEditor.tsx +0 -806
  70. package/src/__tests__/blockProperties.test.ts +0 -92
  71. package/src/__tests__/blockPropertiesPopoverTheme.test.tsx +0 -33
  72. package/src/__tests__/blockRange.test.ts +0 -105
  73. package/src/__tests__/blockTagActivity.test.ts +0 -183
  74. package/src/__tests__/buildDocumentPreviewMarkdown.test.ts +0 -75
  75. package/src/__tests__/buildPreviewDocContent.test.ts +0 -65
  76. package/src/__tests__/buildPreviewDocTransition.test.ts +0 -92
  77. package/src/__tests__/canvasSurfaceTextEditing.test.tsx +0 -60
  78. package/src/__tests__/codeContextSectionView.test.tsx +0 -97
  79. package/src/__tests__/codeContextZoneManager.test.ts +0 -127
  80. package/src/__tests__/createShapeLayer.test.ts +0 -46
  81. package/src/__tests__/customLayoutManagerTheme.test.tsx +0 -34
  82. package/src/__tests__/detectMarkdown.test.ts +0 -73
  83. package/src/__tests__/diffContextSections.test.ts +0 -39
  84. package/src/__tests__/documentSettingsDialog.test.tsx +0 -197
  85. package/src/__tests__/drawingShapeRoundTrip.test.ts +0 -49
  86. package/src/__tests__/editorScrollHandoff.test.tsx +0 -102
  87. package/src/__tests__/editorScrollSync.test.ts +0 -65
  88. package/src/__tests__/editorShellCodeContext.test.tsx +0 -86
  89. package/src/__tests__/editorShellProps.test.tsx +0 -550
  90. package/src/__tests__/embeddedMedia.test.ts +0 -48
  91. package/src/__tests__/emojiPicker.test.tsx +0 -93
  92. package/src/__tests__/fileKind.test.ts +0 -112
  93. package/src/__tests__/findMode.test.tsx +0 -104
  94. package/src/__tests__/findModel.test.ts +0 -55
  95. package/src/__tests__/headingTransition.test.ts +0 -176
  96. package/src/__tests__/imageEditAffordance.test.tsx +0 -272
  97. package/src/__tests__/imageEditModalContract.test.tsx +0 -119
  98. package/src/__tests__/imageEditorShell.test.tsx +0 -94
  99. package/src/__tests__/imageEditorState.test.ts +0 -171
  100. package/src/__tests__/inlinePreviewGutter.test.tsx +0 -62
  101. package/src/__tests__/inlinePreviewGutterAllBlocks.test.tsx +0 -103
  102. package/src/__tests__/jsonEditor.test.tsx +0 -223
  103. package/src/__tests__/layersPanel.test.tsx +0 -167
  104. package/src/__tests__/layoutChildRoundTrip.test.ts +0 -71
  105. package/src/__tests__/linkDialogDocPicker.test.tsx +0 -137
  106. package/src/__tests__/majorApiTypes.test.ts +0 -26
  107. package/src/__tests__/markdownCodeFence.test.ts +0 -45
  108. package/src/__tests__/mediaAttachmentFlow.test.ts +0 -110
  109. package/src/__tests__/mediaBinDrop.test.tsx +0 -90
  110. package/src/__tests__/mediaReferences.test.ts +0 -97
  111. package/src/__tests__/narrationSave.test.ts +0 -148
  112. package/src/__tests__/outlinePanel.test.tsx +0 -169
  113. package/src/__tests__/outlineSource.test.ts +0 -217
  114. package/src/__tests__/plainHtmlPreview.test.tsx +0 -125
  115. package/src/__tests__/presentationMode.test.tsx +0 -290
  116. package/src/__tests__/previewControls.test.tsx +0 -571
  117. package/src/__tests__/previewPanelAudioFailure.test.tsx +0 -46
  118. package/src/__tests__/previewPanelPresentation.test.tsx +0 -126
  119. package/src/__tests__/previewPanelTransforms.test.tsx +0 -117
  120. package/src/__tests__/propertiesPanel.test.tsx +0 -69
  121. package/src/__tests__/rawEditorModelIsolation.test.ts +0 -19
  122. package/src/__tests__/recorderFormats.test.ts +0 -146
  123. package/src/__tests__/recorderMediaInsert.test.ts +0 -86
  124. package/src/__tests__/recorderTheme.test.tsx +0 -42
  125. package/src/__tests__/recorderTimingJson.test.ts +0 -41
  126. package/src/__tests__/resolveBlockVisual.test.ts +0 -43
  127. package/src/__tests__/selectionConversions.test.ts +0 -80
  128. package/src/__tests__/statusBar.test.tsx +0 -27
  129. package/src/__tests__/teleprompter.test.tsx +0 -190
  130. package/src/__tests__/templateAnnotationRoundTrip.test.ts +0 -99
  131. package/src/__tests__/templateContentPreview.test.ts +0 -101
  132. package/src/__tests__/templatePickerMetadata.test.ts +0 -32
  133. package/src/__tests__/templatePickerPortal.test.tsx +0 -62
  134. package/src/__tests__/timelineSource.test.ts +0 -134
  135. package/src/__tests__/tiptapBridge.test.ts +0 -575
  136. package/src/__tests__/tiptapBridgeConformance.test.ts +0 -47
  137. package/src/__tests__/tiptapCodeBlockRoundTrip.test.ts +0 -109
  138. package/src/__tests__/tiptapImageRoundTrip.test.ts +0 -73
  139. package/src/__tests__/toolbarSelectionConversion.test.tsx +0 -190
  140. package/src/__tests__/tooltip.test.tsx +0 -72
  141. package/src/__tests__/transformStyleId.test.ts +0 -13
  142. package/src/__tests__/transitionCatalog.test.ts +0 -64
  143. package/src/__tests__/useBlockNavigator.test.tsx +0 -67
  144. package/src/__tests__/useImageEditor.test.tsx +0 -226
  145. package/src/__tests__/useJsonEditorTokens.test.ts +0 -59
  146. package/src/__tests__/useMediaRecorder.test.ts +0 -302
  147. package/src/__tests__/useTimelineClock.test.ts +0 -21
  148. package/src/__tests__/versionHistory.test.tsx +0 -197
  149. package/src/__tests__/viewMenuPanel.test.tsx +0 -130
  150. package/src/__tests__/writeCanvasSettings.test.ts +0 -15
  151. package/src/__tests__/wysiwygImageUpload.test.ts +0 -69
  152. package/src/__tests__/wysiwygTemplateBadgeFocus.test.tsx +0 -56
  153. package/src/asciiDiagram/AsciiDiagramExtension.ts +0 -343
  154. package/src/asciiDiagram/AsciiDiagramWidget.tsx +0 -254
  155. package/src/asciiDiagram/RepairableDiagramExtension.ts +0 -200
  156. package/src/asciiDiagram/__tests__/AsciiDiagramExtension.test.ts +0 -164
  157. package/src/asciiDiagram/__tests__/RepairableDiagramExtension.test.ts +0 -159
  158. package/src/asciiDiagram/__tests__/asciiDiagramCommands.test.ts +0 -284
  159. package/src/asciiDiagram/__tests__/asciiDiagramOps.test.ts +0 -114
  160. package/src/asciiDiagram/__tests__/asciiPaste.test.ts +0 -43
  161. package/src/asciiDiagram/asciiDiagramCommands.ts +0 -174
  162. package/src/asciiDiagram/asciiDiagramData.ts +0 -149
  163. package/src/asciiDiagram/asciiDiagramOps.ts +0 -238
  164. package/src/asciiDiagram/asciiPaste.ts +0 -19
  165. package/src/blockProperties.ts +0 -88
  166. package/src/blockRange.ts +0 -132
  167. package/src/blockSlice.ts +0 -75
  168. package/src/blockTagActivity.ts +0 -233
  169. package/src/buildDocumentPreviewMarkdown.ts +0 -168
  170. package/src/buildPreviewDoc.ts +0 -407
  171. package/src/codeContext/CodeContextSectionView.tsx +0 -124
  172. package/src/codeContext/CodeContextZoneManager.ts +0 -149
  173. package/src/codeContext/CodeContextZones.tsx +0 -121
  174. package/src/codeContext/diffContextSections.ts +0 -38
  175. package/src/codeContext/types.ts +0 -75
  176. package/src/codeSnippet/CodeSnippetExtension.ts +0 -205
  177. package/src/codeSnippet/CodeSnippetWidget.tsx +0 -109
  178. package/src/codeSnippet/__tests__/CodeSnippetExtension.test.ts +0 -95
  179. package/src/codeSnippet/__tests__/codeSnippetLanguages.test.ts +0 -50
  180. package/src/codeSnippet/codeSnippetCommands.ts +0 -21
  181. package/src/codeSnippet/codeSnippetData.ts +0 -43
  182. package/src/codeSnippet/codeSnippetLanguages.ts +0 -216
  183. package/src/customTemplates/AddBin.tsx +0 -126
  184. package/src/customTemplates/CustomLayoutManager.tsx +0 -234
  185. package/src/customTemplates/CustomTemplateContext.tsx +0 -188
  186. package/src/customTemplates/LayerToolbar.tsx +0 -580
  187. package/src/customTemplates/ShapeGlyph.tsx +0 -47
  188. package/src/customTemplates/TemplateDesigner.tsx +0 -433
  189. package/src/customTemplates/__tests__/library.test.ts +0 -96
  190. package/src/customTemplates/__tests__/normalizePositions.test.ts +0 -109
  191. package/src/customTemplates/__tests__/shapeDefs.test.ts +0 -49
  192. package/src/customTemplates/__tests__/useMemoryLayerAdapter.test.ts +0 -108
  193. package/src/customTemplates/designer.css +0 -732
  194. package/src/customTemplates/index.ts +0 -31
  195. package/src/customTemplates/library.ts +0 -110
  196. package/src/customTemplates/normalizePositions.ts +0 -75
  197. package/src/customTemplates/shapeDefs.ts +0 -131
  198. package/src/customTemplates/thumbnail.tsx +0 -63
  199. package/src/customTemplates/tokenDefs.ts +0 -60
  200. package/src/customTemplates/useDocCustomTemplates.ts +0 -52
  201. package/src/customTemplates/useMemoryLayerAdapter.ts +0 -129
  202. package/src/customThemes/CustomThemeContext.tsx +0 -185
  203. package/src/customThemes/CustomThemeDialog.tsx +0 -316
  204. package/src/customThemes/ImportThemeSection.tsx +0 -178
  205. package/src/customThemes/__tests__/CustomThemeContext.test.tsx +0 -64
  206. package/src/customThemes/__tests__/CustomThemeDialog.test.tsx +0 -47
  207. package/src/customThemes/__tests__/customThemeLibrary.test.ts +0 -60
  208. package/src/customThemes/__tests__/importThemeSection.test.tsx +0 -192
  209. package/src/customThemes/customThemeLibrary.ts +0 -100
  210. package/src/customThemes/index.ts +0 -37
  211. package/src/customThemes/themeControls.tsx +0 -229
  212. package/src/customThemes/themeDraft.ts +0 -288
  213. package/src/customThemes/useDocCustomThemes.ts +0 -49
  214. package/src/detectMarkdown.ts +0 -62
  215. package/src/diagram/DiagramCanvas.tsx +0 -260
  216. package/src/diagram/DiagramMaximizedOverlay.tsx +0 -46
  217. package/src/diagram/diagramCommands.ts +0 -604
  218. package/src/diagram/diagramConstants.ts +0 -17
  219. package/src/diagram/types.ts +0 -35
  220. package/src/editorScrollSync.ts +0 -73
  221. package/src/embeddedMedia.ts +0 -78
  222. package/src/emojiData.ts +0 -1317
  223. package/src/fileKind.ts +0 -158
  224. package/src/find/FindHighlightExtension.ts +0 -81
  225. package/src/find/FindToolbar.tsx +0 -314
  226. package/src/find/findModel.ts +0 -77
  227. package/src/frontmatter.ts +0 -29
  228. package/src/frontmatterSettings.ts +0 -23
  229. package/src/headingTransition.ts +0 -291
  230. package/src/hooks/useFileDrop.ts +0 -266
  231. package/src/imageEditor/CanvasSurface.tsx +0 -703
  232. package/src/imageEditor/ImageVersionHistoryDropdown.tsx +0 -396
  233. package/src/imageEditor/LayersPanel.tsx +0 -218
  234. package/src/imageEditor/PropertiesPanel.tsx +0 -474
  235. package/src/imageEditor/Toolbar.tsx +0 -459
  236. package/src/imageEditor/createShapeLayer.ts +0 -280
  237. package/src/imageEditor/icons.tsx +0 -68
  238. package/src/imageEditor/image-editor.css +0 -574
  239. package/src/imageEditor/layers/EditorImageLayer.tsx +0 -45
  240. package/src/imageEditor/layers/EditorShapeLayer.tsx +0 -62
  241. package/src/imageEditor/layers/EditorTextLayer.tsx +0 -45
  242. package/src/imageEditor/layers/SelectionHandles.tsx +0 -86
  243. package/src/imageEditor/state.ts +0 -173
  244. package/src/imageEditor/useImageEditor.ts +0 -385
  245. package/src/imageEditor/useImageEditorTokens.ts +0 -70
  246. package/src/index.ts +0 -559
  247. package/src/jsonEditor/EmbeddedRichTextField.tsx +0 -81
  248. package/src/jsonEditor/JsonEditor.tsx +0 -81
  249. package/src/jsonEditor/JsonEditorContext.tsx +0 -81
  250. package/src/jsonEditor/RenderNode.tsx +0 -87
  251. package/src/jsonEditor/editors.tsx +0 -745
  252. package/src/jsonEditor/index.ts +0 -2
  253. package/src/jsonEditor/json-editor.css +0 -463
  254. package/src/jsonEditor/useJsonEditorTokens.ts +0 -33
  255. package/src/markdownCodeFence.ts +0 -72
  256. package/src/mediaDragMime.ts +0 -32
  257. package/src/mediaEntries.ts +0 -12
  258. package/src/mediaReferences.ts +0 -301
  259. package/src/mermaid/MermaidDiagramCanvas.tsx +0 -693
  260. package/src/mermaid/MermaidDiagramExtension.ts +0 -243
  261. package/src/mermaid/MermaidDiagramTypeThumbnail.tsx +0 -184
  262. package/src/mermaid/MermaidDiagramWidget.tsx +0 -653
  263. package/src/mermaid/MermaidShapePalette.tsx +0 -245
  264. package/src/mermaid/__tests__/MermaidDiagramExtension.test.ts +0 -361
  265. package/src/mermaid/__tests__/mermaidDiagramTypes.test.ts +0 -35
  266. package/src/mermaid/__tests__/mermaidRenderer.test.ts +0 -49
  267. package/src/mermaid/__tests__/mermaidSourceOps.test.ts +0 -213
  268. package/src/mermaid/__tests__/mermaidSyntax.test.ts +0 -71
  269. package/src/mermaid/mermaidCommands.ts +0 -34
  270. package/src/mermaid/mermaidData.ts +0 -31
  271. package/src/mermaid/mermaidDiagramTypes.ts +0 -325
  272. package/src/mermaid/mermaidModel.ts +0 -31
  273. package/src/mermaid/mermaidRenderer.ts +0 -181
  274. package/src/mermaid/mermaidShapes.ts +0 -113
  275. package/src/mermaid/mermaidSourceOps.ts +0 -454
  276. package/src/monaco.ts +0 -35
  277. package/src/monacoWorkers.ts +0 -89
  278. package/src/outlineSource.ts +0 -171
  279. package/src/presentation/PresentationMode.tsx +0 -596
  280. package/src/rawEditorIsolation.ts +0 -18
  281. package/src/recorder/RecorderButton.tsx +0 -80
  282. package/src/recorder/RecorderModal.tsx +0 -706
  283. package/src/recorder/RecorderPanel.tsx +0 -77
  284. package/src/recorder/formats.ts +0 -159
  285. package/src/recorder/hooks/useMediaRecorder.ts +0 -436
  286. package/src/recorder/hooks/useStreamPreview.ts +0 -47
  287. package/src/recorder/insertMediaBlock.ts +0 -30
  288. package/src/recorder/sources/cameraStream.ts +0 -32
  289. package/src/recorder/sources/micStream.ts +0 -25
  290. package/src/recorder/sources/screenStream.ts +0 -162
  291. package/src/recorder/timingJson.ts +0 -66
  292. package/src/resolveBlockVisual.ts +0 -39
  293. package/src/scene/Scene.tsx +0 -647
  294. package/src/scene/SceneBlockExtension.ts +0 -205
  295. package/src/scene/SceneBlockToolbar.tsx +0 -216
  296. package/src/scene/SceneBlockWidget.tsx +0 -441
  297. package/src/scene/ScenePropsBar.tsx +0 -85
  298. package/src/scene/SceneSelection.tsx +0 -111
  299. package/src/scene/SceneSideToolbar.tsx +0 -89
  300. package/src/scene/SceneViewControls.tsx +0 -43
  301. package/src/scene/SceneViewport.tsx +0 -106
  302. package/src/scene/ShapePalette.tsx +0 -196
  303. package/src/scene/__tests__/DiagramAdapter.test.ts +0 -142
  304. package/src/scene/__tests__/SceneBlockExtension.test.ts +0 -33
  305. package/src/scene/__tests__/bezierEdit.test.ts +0 -85
  306. package/src/scene/__tests__/blockLayers.test.ts +0 -57
  307. package/src/scene/__tests__/fitScale.test.ts +0 -19
  308. package/src/scene/__tests__/sceneIsolation.test.tsx +0 -119
  309. package/src/scene/__tests__/shapeLayers.test.ts +0 -106
  310. package/src/scene/__tests__/useSceneHitTest.test.ts +0 -90
  311. package/src/scene/__tests__/useScenePanZoom.test.ts +0 -130
  312. package/src/scene/adapters/DiagramAdapter.ts +0 -79
  313. package/src/scene/adapters/DrawingAdapter.ts +0 -420
  314. package/src/scene/adapters/LayoutAdapter.ts +0 -313
  315. package/src/scene/adapters/blockLayers.ts +0 -159
  316. package/src/scene/commands/SceneCommand.ts +0 -84
  317. package/src/scene/commands/drawingCommands.ts +0 -318
  318. package/src/scene/commands/layoutCommands.ts +0 -301
  319. package/src/scene/fitScale.ts +0 -17
  320. package/src/scene/hooks/useSceneHitTest.ts +0 -105
  321. package/src/scene/hooks/useScenePanZoom.ts +0 -154
  322. package/src/scene/hooks/useSceneSelection.ts +0 -62
  323. package/src/scene/index.ts +0 -90
  324. package/src/scene/layers/DiagramEdges.tsx +0 -142
  325. package/src/scene/layers/edgeGeometry.ts +0 -104
  326. package/src/scene/layers/nodeCard.tsx +0 -164
  327. package/src/scene/layers/renderLayer.tsx +0 -70
  328. package/src/scene/layers/shapeLayers.ts +0 -201
  329. package/src/scene/paths/bezierEdit.ts +0 -208
  330. package/src/scene/scene.css +0 -874
  331. package/src/scene/text/SceneTextOverlay.tsx +0 -161
  332. package/src/scene/text/sceneTextChannel.ts +0 -46
  333. package/src/scene/text/sceneTextConfig.ts +0 -31
  334. package/src/scene/text/sceneTiptap.ts +0 -36
  335. package/src/scene/text/useSceneTextEditing.ts +0 -39
  336. package/src/scene/tools/ConnectTool.ts +0 -209
  337. package/src/scene/tools/DrawingConnectTool.ts +0 -231
  338. package/src/scene/tools/PathTool.ts +0 -158
  339. package/src/scene/tools/PlaceTool.ts +0 -47
  340. package/src/scene/tools/SceneTool.ts +0 -85
  341. package/src/scene/tools/SelectTool.ts +0 -300
  342. package/src/scene/tools/ShapeTool.ts +0 -143
  343. package/src/scene/tools/TextTool.ts +0 -72
  344. package/src/scene/tools/TokenTool.ts +0 -95
  345. package/src/scene/tools/createDrawShapeTool.ts +0 -82
  346. package/src/selectionConversions.ts +0 -155
  347. package/src/styles/ascii-diagram.css +0 -79
  348. package/src/styles/ascii-timeline.css +0 -596
  349. package/src/styles/code-context.css +0 -155
  350. package/src/styles/code-snippet.css +0 -76
  351. package/src/styles/diagram.css +0 -183
  352. package/src/styles/editor.css +0 -7131
  353. package/src/styles/folder-view.css +0 -210
  354. package/src/styles/image-edit-affordance.css +0 -201
  355. package/src/styles/index.css +0 -20
  356. package/src/styles/mermaid-diagram.css +0 -487
  357. package/src/styles/tree-view.css +0 -189
  358. package/src/teleprompter/TeleprompterControls.tsx +0 -218
  359. package/src/teleprompter/TeleprompterSelfView.tsx +0 -22
  360. package/src/teleprompter/TeleprompterSurface.tsx +0 -267
  361. package/src/teleprompter/TeleprompterView.tsx +0 -338
  362. package/src/teleprompter/canvasRenderer.ts +0 -161
  363. package/src/teleprompter/floatingWindow.ts +0 -352
  364. package/src/teleprompter/index.ts +0 -61
  365. package/src/teleprompter/pcmWorklet.ts +0 -62
  366. package/src/teleprompter/recording/insertPreamble.ts +0 -80
  367. package/src/teleprompter/recording/narrationSave.ts +0 -134
  368. package/src/teleprompter/recording/useNarrationRecorder.ts +0 -367
  369. package/src/teleprompter/scrollModel.ts +0 -85
  370. package/src/teleprompter/teleprompterTheme.ts +0 -303
  371. package/src/teleprompter/types.ts +0 -38
  372. package/src/teleprompter/useFloatingWindow.ts +0 -74
  373. package/src/teleprompter/useMicAnalysis.ts +0 -211
  374. package/src/teleprompter/useTeleprompter.ts +0 -421
  375. package/src/templateContentPreviewResolver.ts +0 -360
  376. package/src/timeline/TimelineEditorWidget.tsx +0 -861
  377. package/src/timeline/TimelineViewExtension.ts +0 -252
  378. package/src/timeline/__tests__/TimelineEditorWidget.test.tsx +0 -414
  379. package/src/timeline/__tests__/TimelineViewExtension.test.ts +0 -163
  380. package/src/timeline/__tests__/timelineCommands.test.ts +0 -359
  381. package/src/timeline/__tests__/timelineOps.test.ts +0 -277
  382. package/src/timeline/__tests__/timelinePaste.test.ts +0 -34
  383. package/src/timeline/timelineCommands.ts +0 -421
  384. package/src/timeline/timelineData.ts +0 -54
  385. package/src/timeline/timelineOps.ts +0 -381
  386. package/src/timeline/timelinePaste.ts +0 -8
  387. package/src/timelineSource.ts +0 -244
  388. package/src/tiptap/TiptapAudio.tsx +0 -86
  389. package/src/tiptap/TiptapVideo.tsx +0 -119
  390. package/src/tiptap/useResolvedMediaSrc.ts +0 -47
  391. package/src/tiptapBridge.ts +0 -986
  392. package/src/tooltipPlacement.ts +0 -13
  393. package/src/transformStyleId.ts +0 -17
  394. package/src/transitionCatalog.ts +0 -159
  395. package/src/treeview/TreeOutlineWidget.tsx +0 -390
  396. package/src/treeview/TreeViewExtension.ts +0 -250
  397. package/src/treeview/__tests__/TreeOutlineWidget.test.tsx +0 -156
  398. package/src/treeview/__tests__/TreeViewExtension.test.ts +0 -122
  399. package/src/treeview/__tests__/treeOps.test.ts +0 -177
  400. package/src/treeview/__tests__/treePaste.test.ts +0 -40
  401. package/src/treeview/__tests__/treeViewCommands.test.ts +0 -179
  402. package/src/treeview/treeOps.ts +0 -231
  403. package/src/treeview/treePaste.ts +0 -13
  404. package/src/treeview/treeViewCommands.ts +0 -99
  405. package/src/treeview/treeViewData.ts +0 -41
  406. package/src/types/monaco-shims.d.ts +0 -10
  407. package/src/useBlockNavigator.ts +0 -153
  408. package/src/useHeadingLayout.ts +0 -294
  409. package/src/useMonacoLoader.ts +0 -82
  410. package/src/useTimelineClock.ts +0 -76
  411. package/src/utils/collectInlineFontAwesomeCss.ts +0 -69
  412. package/src/utils/dropUtils.ts +0 -136
  413. package/src/utils/normalizeMalformedAssetUrl.ts +0 -22
  414. package/src/writeCanvasSettings.ts +0 -30
  415. package/src/wysiwygImageUpload.ts +0 -113
@@ -1,1358 +0,0 @@
1
- /**
2
- * EditorShell
3
- *
4
- * Top-level shell component that composes the Toolbar, ViewSwitcher, editor
5
- * views, and StatusBar into a complete editing experience. Wraps everything
6
- * in an EditorProvider for shared state.
7
- */
8
-
9
- import { useEffect, useRef, useState, useCallback, useMemo } from 'react';
10
- import {
11
- EditorProvider,
12
- useEditorContext,
13
- type EditorView,
14
- type ImageDisplayMode,
15
- type MentionProvider,
16
- type DocumentLinkProvider,
17
- type ViewPreferences,
18
- type ThemeInheritance,
19
- type BlockTagVisibility,
20
- } from './EditorContext';
21
- import { Toolbar } from './Toolbar';
22
- import { StatusBar } from './StatusBar';
23
- import { RawEditor } from './RawEditor';
24
- import { WysiwygEditor } from './WysiwygEditor';
25
- import { InlinePreviewGutter } from './InlinePreviewGutter';
26
- import { BlockPreviewPanel } from './BlockPreviewPanel';
27
- import { OutlinePanel, OUTLINE_RESPONSIVE_WIDTH } from './OutlinePanel';
28
- import { CodeContextZones } from './codeContext/CodeContextZones';
29
- import type { CodeContext } from './codeContext/types';
30
- import { BlockCardView } from './BlockCardView';
31
- import { TimelineTrack } from './TimelineTrack';
32
- import { PreviewPanel } from './PreviewPanel';
33
- import { ImageViewer } from './ImageViewer';
34
- import { ImageEditor } from './ImageEditor';
35
- import {
36
- PreviewSettingsProvider,
37
- PreviewToolbarControls,
38
- ThemeDesignerDock,
39
- } from './PreviewControls';
40
- import { PresentationModeControl, PresentationModeProvider } from './presentation/PresentationMode';
41
- import { CustomThemeProvider, useDocCustomThemes } from './customThemes';
42
- import { MediaBin } from './MediaBin';
43
- import { DropZoneOverlay } from './DropZoneOverlay';
44
- import { TooltipLayer } from './Tooltip';
45
- import { useFileDrop, type DropTarget } from './hooks/useFileDrop';
46
- import {
47
- partitionFiles,
48
- processMediaFiles,
49
- processTextFile,
50
- processTextFiles,
51
- } from './utils/dropUtils';
52
- import {
53
- collectMediaReferencesFromMarkdown,
54
- removeMediaReferencesFromMarkdown,
55
- } from './mediaReferences';
56
- import { filterVisibleMediaEntries } from './mediaEntries';
57
- import type { MediaProvider, Theme } from '@bendyline/squisq/schemas';
58
- import { DARK_SURFACE, LIGHT_SURFACE } from '@bendyline/squisq/schemas';
59
- import type { ContentContainer } from '@bendyline/squisq/storage';
60
- import {
61
- MemoryContentContainer,
62
- scopeContainer,
63
- createMediaProviderFromContainer,
64
- } from '@bendyline/squisq/storage';
65
- import type { PrunePolicy, SaveVersionResult } from '@bendyline/squisq/versions';
66
- import type { CSSProperties, KeyboardEvent as ReactKeyboardEvent, ReactNode } from 'react';
67
- import { MediaContext } from '@bendyline/squisq-react';
68
- import { writeCanvasSettingsStyle, type WriteCanvasSettings } from './writeCanvasSettings';
69
-
70
- export type { EditorColorScheme } from './EditorContext';
71
-
72
- export interface EditorShellProps {
73
- /** Initial markdown content */
74
- initialMarkdown?: string;
75
- /** Initial active view */
76
- /** Initial active view (default: 'wysiwyg') */
77
- initialView?: EditorView;
78
- /** Article ID for Doc generation */
79
- articleId?: string;
80
- /** Base path for media URLs in preview */
81
- basePath?: string;
82
- /** Called when markdown source changes */
83
- onChange?: (source: string) => void;
84
- /**
85
- * Light/dark chrome color scheme for the editor shell — toolbar, tabs,
86
- * status bar, and side panes (default: `'light'`). This is the editor's
87
- * UI mode, **not** a Squisq `Theme` object; the rendered document's
88
- * styling is controlled separately via `themeOverride` / `Doc.themeId`.
89
- */
90
- colorScheme?: 'light' | 'dark';
91
- /** Additional class name */
92
- className?: string;
93
- /** CSS height for the shell container (default: '100vh') */
94
- height?: string;
95
- /**
96
- * Minimum CSS height for the shell. When either `minHeight` or
97
- * `maxHeight` is set, the shell switches to **auto-grow mode**:
98
- * `height` is ignored, the root becomes `height: auto` between the
99
- * bounds, and the content area scrolls internally when content
100
- * exceeds `maxHeight`. Useful for chat composers that should grow
101
- * with content up to some cap.
102
- */
103
- minHeight?: string;
104
- /** See `minHeight`. Upper bound of the auto-grow range. */
105
- maxHeight?: string;
106
- /** Optional MediaProvider for the Files panel. When set (even to null), a Files toggle appears in the toolbar. */
107
- mediaProvider?: MediaProvider | null;
108
- /**
109
- * The workspace-scoped `ContentContainer` for this document — the
110
- * folder that contains the doc, its `_files/` sidecar, sibling
111
- * documents, and any version snapshots. Used for:
112
- * - audio mapping (MP3 discovery + timing.json reading);
113
- * - version history snapshots (when `allowVersioning` is true);
114
- * - reading sibling `.md` files for the recursive HTML export;
115
- * - resolving per-document scoped views (e.g. the image-edit
116
- * sidecar derived via `scopeContainer`).
117
- * Doc-scoped concerns (per-doc media URLs, per-doc asset writes)
118
- * flow through `mediaProvider` instead — typically derived from
119
- * this container via `createMediaProviderFromContainer`.
120
- */
121
- workspaceContainer?: ContentContainer | null;
122
- /**
123
- * Enable version history. Snapshots are stored at
124
- * `.versions/<basename>.<timestamp>.md` inside the same
125
- * `workspaceContainer`, so they ride along with the document when
126
- * the host serializes.
127
- *
128
- * Snapshots fire on idle (controlled by `versioningAutoSaveIdleMs`)
129
- * and can also be triggered host-side via the manager exposed in the
130
- * context (`useEditorContext().versioning`). Has no effect without a
131
- * `workspaceContainer` — a `console.warn` flags the misconfiguration
132
- * in dev.
133
- */
134
- allowVersioning?: boolean;
135
- /**
136
- * Override the document basename used in version filenames. Defaults
137
- * to the basename of the container's primary document path.
138
- */
139
- versionBasename?: string;
140
- /**
141
- * Prune policy applied after each successful save. Defaults to
142
- * `{ type: 'keep-last-n', n: 50 }` so the snapshot count stays bounded.
143
- */
144
- versioningPrunePolicy?: PrunePolicy;
145
- /**
146
- * Idle delay (ms) before the editor auto-saves a version. `0` disables
147
- * auto-save entirely (snapshots are then only saved when the host
148
- * calls `versioning.saveVersion()` from the context). Default: 5000.
149
- */
150
- versioningAutoSaveIdleMs?: number;
151
- /**
152
- * Notified after each `saveVersion` attempt. Fires for both successful
153
- * saves (`reason: 'saved'`) and skips (`'unchanged'`, `'no-document'`,
154
- * `'empty'`). Useful for hosts that want a "Last saved" indicator.
155
- */
156
- onSaveVersion?: (result: SaveVersionResult) => void;
157
- /** Show the Files toggle in the toolbar. Defaults to true when mediaProvider is passed. */
158
- showFilesToggle?: boolean;
159
- /** Content rendered at the left edge of the toolbar, before the view tabs. */
160
- toolbarSlotLeft?: ReactNode;
161
- /** Content rendered after the formatting controls (in the middle area of the toolbar). */
162
- toolbarSlotAfterActions?: ReactNode;
163
- /** Content rendered at the rightmost end of the toolbar, after all other elements. */
164
- toolbarSlotRight?: ReactNode;
165
- /**
166
- * Whether to show the "Play" (preview) tab in the toolbar. When false, the
167
- * tab and its preview panel are hidden, and ⌘3 becomes a no-op. Use this
168
- * when embedding the editor somewhere the slideshow preview doesn't make
169
- * sense (e.g. editing free-form prompt documents). Defaults to true.
170
- */
171
- showPlayTab?: boolean;
172
- /**
173
- * Optional "submit on Enter" callback. When provided, a plain Enter
174
- * keypress fires this callback instead of inserting a newline, and
175
- * Cmd/Ctrl+Enter inserts a newline instead. Matches chat-composer UX
176
- * (Slack, Discord). When omitted, the editor behaves normally.
177
- */
178
- submitOnEnter?: () => void;
179
- /**
180
- * Host-supplied context dictionary rendered inside the Monaco (raw / code)
181
- * surface: collapsible markdown sections injected above anchor lines, plus
182
- * an optional file-top summary. See {@link CodeContext}. Ignored in
183
- * WYSIWYG / preview / image surfaces.
184
- */
185
- codeContext?: CodeContext;
186
- /**
187
- * Let the WYSIWYG editing surface fill its container instead of rendering
188
- * as a centered 800px "page" column. Useful when embedding in chat
189
- * composers, side panels, or any layout where the page metaphor doesn't
190
- * fit. Defaults to false (page mode).
191
- */
192
- fullWidth?: boolean;
193
- /**
194
- * Font-family stack applied to the editor **chrome** — toolbar buttons,
195
- * tabs, status bar, and control surfaces. The actual editing areas
196
- * (Tiptap / Monaco) keep their own fonts so document editing isn't
197
- * affected. Use this when the editor is embedded in a larger product
198
- * that has its own UX type system and you want the controls to blend in.
199
- *
200
- * @example
201
- * ```tsx
202
- * <EditorShell uxFont="'Hanken Grotesk', system-ui, sans-serif" ... />
203
- * ```
204
- */
205
- uxFont?: string;
206
- /**
207
- * Drop the editor's generous page-style padding in favor of a tight
208
- * layout that hugs its container. The default WYSIWYG surface uses
209
- * 16×24px padding suitable for editing long-form documents; chat
210
- * composers want much less. Applies to the editing area only — the
211
- * toolbar, tabs, and status bar keep their normal sizing.
212
- */
213
- thinMargins?: boolean;
214
- /**
215
- * Host-controlled typography for the markdown Write canvas. `textSize` is
216
- * measured in CSS pixels and `lineSpacing` is a unitless line-height
217
- * multiplier. This is presentation-only and does not modify the markdown.
218
- */
219
- writeCanvasSettings?: WriteCanvasSettings;
220
- /**
221
- * Render the bottom status bar (word / character / line / block counts
222
- * and parse-state indicator). Defaults to `true`. Set to `false` in
223
- * embedded surfaces — chat composers and other short-form inputs —
224
- * where the stats are noise.
225
- */
226
- showStatusBar?: boolean;
227
- /**
228
- * How images should be displayed in the WYSIWYG view. `'inline'`
229
- * (default) flows them at natural size up to the container width;
230
- * `'thumbnail'` constrains each image to a 100×100 box with
231
- * aspect-preserving containment — useful for chat composers and other
232
- * dense surfaces where a full-resolution paste would dominate the
233
- * layout. Storage bytes are unchanged either way.
234
- */
235
- imageDisplayMode?: ImageDisplayMode;
236
- /**
237
- * File name (e.g. `foo.ts`) or bare extension that the content
238
- * represents. When set to a non-markdown/text extension, the shell
239
- * enters **code mode**: Monaco picks the right language based on the
240
- * extension, the WYSIWYG and Preview tabs disappear, and the toolbar
241
- * drops its markdown-specific formatting buttons. Markdown-ish
242
- * extensions (`.md`, `.markdown`, `.mdown`, `.txt`) keep the full
243
- * experience. Omit to get today's markdown behavior unchanged.
244
- */
245
- fileName?: string;
246
- /**
247
- * Explicit Monaco language ID override (e.g. `'typescript'`,
248
- * `'python'`, `'json'`). Wins over the language derived from
249
- * `fileName`. Anything other than `'markdown'` or `'plaintext'`
250
- * switches the shell into code mode.
251
- */
252
- language?: string;
253
- /**
254
- * Controlled Find-mode state. Find has no built-in trigger button; hosts
255
- * opt in by setting this prop (or by calling `setFindMode` from a toolbar
256
- * slot rendered inside the editor context).
257
- */
258
- findMode?: boolean;
259
- /** Called when Find mode requests a state change, including its X button. */
260
- onFindModeChange?: (active: boolean) => void;
261
- /**
262
- * Optional async provider for `@`-mention suggestions. When supplied,
263
- * typing `@` inside the editor opens a popover of candidates; selecting
264
- * one inserts a `@[Label](scheme:id)` mention token. Used by chat
265
- * composers and any other surface that wants to address named entities
266
- * inline. Omit to disable mentions entirely.
267
- */
268
- mentionProvider?: MentionProvider | null;
269
- /**
270
- * Optional async provider for sibling-document suggestions in the
271
- * link insert dialog. When supplied, the dialog gains a "Browse
272
- * documents" picker so authors can pick a neighbor `.md` by name and
273
- * insert a relative-path link without typing the URL by hand. Hosts
274
- * that organize docs in a workspace (file-system, IndexedDB slot,
275
- * remote API, …) implement this; the editor stays agnostic.
276
- */
277
- documentLinkProvider?: DocumentLinkProvider | null;
278
- /**
279
- * Whether the in-editor media recorder is surfaced in the toolbar.
280
- * Defaults to true — when a `mediaProvider` is wired, a record
281
- * button appears next to the version history. Pass `false` to
282
- * suppress it (read-only embeds, surfaces where camera/screen
283
- * permission prompts would be jarring). Without a `mediaProvider`,
284
- * the button is hidden regardless of this prop.
285
- */
286
- allowRecording?: boolean;
287
- /**
288
- * Whether the Narrate (teleprompter) display mode is offered under the
289
- * Use tab. Defaults to true. Orthogonal to `allowRecording` — the
290
- * prompter is useful without capture (reading for external recording
291
- * software), and the in-mode Record affordance additionally requires
292
- * `allowRecording` + a `mediaProvider`.
293
- */
294
- allowNarrate?: boolean;
295
- /**
296
- * Placeholder text shown in the WYSIWYG editor while the document is
297
- * empty. When omitted, the editor rotates through its own generic
298
- * "start typing…" prompts; pass a value here to override with copy
299
- * that fits the embedding surface (e.g. a chat composer knows who
300
- * the message is going to and can say so).
301
- */
302
- placeholder?: string;
303
- /**
304
- * When true, both editing surfaces become non-editable: Monaco runs in
305
- * `readOnly` mode and Tiptap is set to `editable: false`. The toolbar
306
- * still renders — hide it from the host side if you want a pure preview.
307
- * Useful for reference panels that show file content without inviting
308
- * accidental edits.
309
- */
310
- readOnly?: boolean;
311
- /**
312
- * Image source URL used when the resolved file mode is `image` (PNG,
313
- * JPEG, GIF, WebP, BMP, ICO, AVIF). When this prop is set, the shell
314
- * replaces its text-editing surfaces with a dedicated `ImageViewer`.
315
- *
316
- * Lifecycle of the URL is the caller's responsibility — when fed a
317
- * `blob:` URL, the host should `URL.revokeObjectURL` on unmount or
318
- * src change.
319
- */
320
- imageSrc?: string;
321
- /** Alt text passed through to the underlying ImageViewer. */
322
- imageAlt?: string;
323
- /**
324
- * Whether the image surface should render as a read-only viewer
325
- * (`'view'`, default) or as the editable {@link ImageEditor}
326
- * (`'edit'`). Editing requires {@link EditorShellProps.imageEditorContainer}
327
- * — without it the shell falls back to view mode and logs a warning.
328
- */
329
- imageMode?: 'view' | 'edit';
330
- /**
331
- * Sidecar `ContentContainer` for the image being edited. Conventionally
332
- * scoped to `<basename>_files/` via
333
- * `scopeContainer(parentContainer, basename + '_files')`. The image
334
- * editor persists `state.json`, layer assets in `assets/`, and (when
335
- * `allowVersioning` is true) snapshots in `.versions/` inside it.
336
- */
337
- imageEditorContainer?: ContentContainer;
338
- /**
339
- * Called after the user clicks Export in the image editor and the
340
- * raster blob is produced. When omitted, the editor triggers a
341
- * default browser download.
342
- */
343
- onImageExport?: (blob: Blob, format: 'png' | 'jpeg' | 'webp') => void;
344
- /**
345
- * Show an inline preview gutter to the right of the WYSIWYG editor.
346
- * The gutter renders one small SVG card per template-annotated block in
347
- * the document, letting authors see their rendered output without
348
- * leaving Edit mode. Auto-hidden via container query when the editor
349
- * body is narrower than ~720px. Defaults to `false`.
350
- */
351
- inlinePreview?: boolean;
352
- /**
353
- * Width in pixels for the inline preview gutter. Defaults to 320.
354
- * Only takes effect when {@link EditorShellProps.inlinePreview} is true.
355
- */
356
- inlinePreviewWidth?: number;
357
- /**
358
- * Show an outline pane on the left of the WYSIWYG editor — a
359
- * hierarchical tree of the document's headings (h1 → h2 → h3) with
360
- * click-to-scroll. Auto-hidden via container query on narrow editors.
361
- * Defaults to `false`. The toolbar's View menu can toggle this at
362
- * runtime regardless of the initial value.
363
- */
364
- outline?: boolean;
365
- /**
366
- * Fixed width in pixels for the outline pane. When omitted, the pane sizes
367
- * responsively — never narrower than 260px, growing with the window and
368
- * capped at 460px — so it stretches out when there's horizontal space to
369
- * spare. Only takes effect when {@link EditorShellProps.outline} is true (or
370
- * the View menu has toggled it on).
371
- */
372
- outlineWidth?: number;
373
- /**
374
- * Legacy initial visibility of inline block-template tags on headings.
375
- * `true` maps to always visible and `false` maps to hidden. When omitted,
376
- * {@link blockTagVisibility} defaults to `'active'`.
377
- */
378
- blockTags?: boolean;
379
- /**
380
- * Initial block-tag visibility mode. Takes precedence over `blockTags`.
381
- * Defaults to `'active'` (selected/hovered block only).
382
- */
383
- blockTagVisibility?: BlockTagVisibility;
384
- /**
385
- * How much of the active Squisq theme the WYSIWYG editing surface
386
- * mirrors. Defaults to `'fonts'` — the historical behavior of
387
- * inheriting body / heading fonts only. The View menu can change it
388
- * at runtime.
389
- */
390
- themeInheritance?: ThemeInheritance;
391
- /**
392
- * Bundled view preferences — a serializable JSON blob covering the
393
- * runtime-toggleable view options surfaced in the View menu. When
394
- * provided, fields here override the corresponding individual props
395
- * (`outline`, `inlinePreview`, `showStatusBar`, `blockTagVisibility`,
396
- * `blockTags`). Pair with
397
- * {@link onViewPreferencesChange} to externalize storage of these
398
- * preferences in the host.
399
- */
400
- viewPreferences?: ViewPreferences;
401
- /**
402
- * Notified after each user-driven toggle in the View menu. The
403
- * argument is a full snapshot of all view preferences — hosts can
404
- * persist it as-is. Not called when {@link viewPreferences} is
405
- * changed externally.
406
- */
407
- onViewPreferencesChange?: (prefs: ViewPreferences) => void;
408
- /**
409
- * Override the preview theme with an explicit `Theme` object. When set,
410
- * `Doc.themeId` and the user's theme dropdown selection are ignored for
411
- * the preview surface. Used by the theme customizer to live-preview an
412
- * in-progress theme without mutating the document.
413
- */
414
- themeOverride?: Theme | null;
415
- }
416
-
417
- /**
418
- * Complete markdown editor shell with toolbar, view switcher, and three
419
- * editing modes: Raw (Monaco), WYSIWYG (Tiptap), and Preview.
420
- */
421
- export function EditorShell({
422
- initialMarkdown = '',
423
- initialView = 'wysiwyg',
424
- articleId = 'untitled',
425
- basePath = '/',
426
- onChange,
427
- colorScheme = 'light',
428
- className,
429
- height = '100vh',
430
- minHeight,
431
- maxHeight,
432
- mediaProvider,
433
- workspaceContainer,
434
- allowVersioning = false,
435
- versionBasename,
436
- versioningPrunePolicy,
437
- versioningAutoSaveIdleMs,
438
- onSaveVersion,
439
- showFilesToggle,
440
- toolbarSlotLeft,
441
- toolbarSlotAfterActions,
442
- toolbarSlotRight,
443
- showPlayTab = true,
444
- submitOnEnter,
445
- codeContext,
446
- fullWidth = false,
447
- uxFont,
448
- thinMargins = false,
449
- writeCanvasSettings,
450
- showStatusBar = true,
451
- imageDisplayMode = 'inline',
452
- fileName,
453
- language,
454
- findMode,
455
- onFindModeChange,
456
- mentionProvider,
457
- documentLinkProvider,
458
- allowRecording = true,
459
- allowNarrate = true,
460
- placeholder,
461
- readOnly = false,
462
- imageSrc,
463
- imageAlt,
464
- imageMode = 'view',
465
- imageEditorContainer,
466
- onImageExport,
467
- inlinePreview = false,
468
- inlinePreviewWidth = 320,
469
- outline = false,
470
- outlineWidth,
471
- blockTags,
472
- blockTagVisibility,
473
- themeInheritance = 'fonts',
474
- viewPreferences,
475
- onViewPreferencesChange,
476
- themeOverride = null,
477
- }: EditorShellProps) {
478
- const effectiveContainer = workspaceContainer ?? null;
479
-
480
- // If the host gave us a `workspaceContainer` but no explicit `mediaProvider`,
481
- // derive one automatically. Without this, drag-and-drop of an image
482
- // into the editor silently failed (no provider \u2192 nothing to upload to)
483
- // even though we had a perfectly good ContentContainer to write into.
484
- const effectiveMediaProvider = useMemo<MediaProvider | null | undefined>(() => {
485
- if (mediaProvider !== undefined) return mediaProvider;
486
- if (effectiveContainer) return createMediaProviderFromContainer(effectiveContainer);
487
- return undefined;
488
- }, [mediaProvider, effectiveContainer]);
489
-
490
- // Show the toggle when explicitly opted in, or when mediaProvider prop was passed at all
491
- const filesToggleEnabled = showFilesToggle ?? effectiveMediaProvider !== undefined;
492
-
493
- // If the host hides the Play tab but asked for it as the initial view,
494
- // fall back to wysiwyg so we don't boot into a tab the user can't leave.
495
- const effectiveInitialView: EditorView =
496
- !showPlayTab && initialView === 'preview' ? 'wysiwyg' : initialView;
497
-
498
- return (
499
- <MediaContext.Provider value={effectiveMediaProvider ?? null}>
500
- <EditorProvider
501
- initialMarkdown={initialMarkdown}
502
- initialView={effectiveInitialView}
503
- articleId={articleId}
504
- colorScheme={colorScheme}
505
- workspaceContainer={effectiveContainer}
506
- allowVersioning={allowVersioning}
507
- versionBasename={versionBasename}
508
- versioningPrunePolicy={versioningPrunePolicy}
509
- versioningAutoSaveIdleMs={versioningAutoSaveIdleMs}
510
- onSaveVersion={onSaveVersion}
511
- mediaProvider={effectiveMediaProvider}
512
- imageDisplayMode={imageDisplayMode}
513
- mentionProvider={mentionProvider}
514
- documentLinkProvider={documentLinkProvider}
515
- allowRecording={allowRecording}
516
- allowNarrate={allowNarrate}
517
- fileName={fileName}
518
- language={language}
519
- findMode={findMode}
520
- onFindModeChange={onFindModeChange}
521
- inlinePreview={inlinePreview}
522
- showStatusBar={showStatusBar}
523
- outline={outline}
524
- blockTags={blockTags}
525
- blockTagVisibility={blockTagVisibility}
526
- themeInheritance={themeInheritance}
527
- viewPreferences={viewPreferences}
528
- onViewPreferencesChange={onViewPreferencesChange}
529
- >
530
- <EditorShellInner
531
- basePath={basePath}
532
- onChange={onChange}
533
- className={className}
534
- height={height}
535
- minHeight={minHeight}
536
- maxHeight={maxHeight}
537
- placeholder={placeholder}
538
- mediaProvider={effectiveMediaProvider ?? null}
539
- workspaceContainer={effectiveContainer}
540
- filesToggleEnabled={filesToggleEnabled}
541
- toolbarSlotLeft={toolbarSlotLeft}
542
- toolbarSlotAfterActions={toolbarSlotAfterActions}
543
- toolbarSlotRight={toolbarSlotRight}
544
- showPlayTab={showPlayTab}
545
- submitOnEnter={submitOnEnter}
546
- codeContext={codeContext}
547
- fullWidth={fullWidth}
548
- uxFont={uxFont}
549
- thinMargins={thinMargins}
550
- writeCanvasSettings={writeCanvasSettings}
551
- readOnly={readOnly}
552
- imageSrc={imageSrc}
553
- imageAlt={imageAlt}
554
- imageMode={imageMode}
555
- imageEditorContainer={imageEditorContainer}
556
- onImageExport={onImageExport}
557
- allowVersioning={allowVersioning}
558
- versioningAutoSaveIdleMs={versioningAutoSaveIdleMs}
559
- inlinePreviewWidth={inlinePreviewWidth}
560
- outlineWidth={outlineWidth}
561
- themeOverride={themeOverride}
562
- />
563
- </EditorProvider>
564
- </MediaContext.Provider>
565
- );
566
- }
567
-
568
- interface EditorShellInnerProps {
569
- basePath: string;
570
- onChange?: (source: string) => void;
571
- className?: string;
572
- height: string;
573
- minHeight?: string;
574
- maxHeight?: string;
575
- placeholder?: string;
576
- mediaProvider: MediaProvider | null;
577
- workspaceContainer?: ContentContainer | null;
578
- filesToggleEnabled: boolean;
579
- toolbarSlotLeft?: ReactNode;
580
- toolbarSlotAfterActions?: ReactNode;
581
- toolbarSlotRight?: ReactNode;
582
- showPlayTab: boolean;
583
- submitOnEnter?: () => void;
584
- codeContext?: CodeContext;
585
- fullWidth: boolean;
586
- uxFont?: string;
587
- thinMargins: boolean;
588
- writeCanvasSettings?: WriteCanvasSettings;
589
- readOnly: boolean;
590
- imageSrc?: string;
591
- imageAlt?: string;
592
- imageMode: 'view' | 'edit';
593
- imageEditorContainer?: ContentContainer;
594
- onImageExport?: (blob: Blob, format: 'png' | 'jpeg' | 'webp') => void;
595
- allowVersioning: boolean;
596
- versioningAutoSaveIdleMs?: number;
597
- inlinePreviewWidth: number;
598
- outlineWidth?: number;
599
- themeOverride: Theme | null;
600
- }
601
-
602
- function EditorShellInner({
603
- basePath,
604
- onChange,
605
- className,
606
- height,
607
- minHeight,
608
- maxHeight,
609
- placeholder,
610
- mediaProvider,
611
- workspaceContainer,
612
- filesToggleEnabled,
613
- toolbarSlotLeft,
614
- toolbarSlotAfterActions,
615
- toolbarSlotRight,
616
- showPlayTab,
617
- submitOnEnter,
618
- codeContext,
619
- fullWidth,
620
- uxFont,
621
- thinMargins,
622
- writeCanvasSettings,
623
- readOnly,
624
- imageSrc,
625
- imageAlt,
626
- imageMode,
627
- imageEditorContainer,
628
- onImageExport,
629
- allowVersioning,
630
- versioningAutoSaveIdleMs,
631
- inlinePreviewWidth,
632
- outlineWidth,
633
- themeOverride,
634
- }: EditorShellInnerProps) {
635
- const shellRef = useRef<HTMLDivElement>(null);
636
- const {
637
- activeView,
638
- markdownSource,
639
- doc,
640
- colorScheme,
641
- editorMode,
642
- insertAtCursor,
643
- replaceAll,
644
- tiptapEditor,
645
- monacoEditor,
646
- setMarkdownSource,
647
- inlinePreviewVisible,
648
- statusBarVisible,
649
- outlineVisible,
650
- layoutMode,
651
- blockCount,
652
- activeBlockKey,
653
- prevBlock,
654
- nextBlock,
655
- addBlock,
656
- imageEditTarget,
657
- closeImageEdit,
658
- bumpMediaRevision,
659
- mediaRevision,
660
- } = useEditorContext();
661
- // Dual-catalog custom themes (doc + browser library), mirroring how
662
- // CustomTemplateProvider is fed. Wraps the preview subtree so the theme
663
- // picker + designer can read/write both pools.
664
- const { docThemes, onDocThemesChange } = useDocCustomThemes();
665
- const isPreview = activeView === 'preview';
666
- const isCodeMode = editorMode === 'code';
667
- const isImageMode = editorMode === 'image';
668
- const isMarkdownMode = editorMode === 'markdown';
669
- // The block card (one block at a time) applies to the editing surfaces (raw /
670
- // wysiwyg) in markdown mode — never to preview, code, or image. Both the
671
- // block-at-a-time and timeline layouts scope the editor to a single block.
672
- const isCardMode =
673
- isMarkdownMode && (layoutMode === 'block' || layoutMode === 'timeline') && !isPreview;
674
- // Timeline mode additionally shows the horizontal timeline track below.
675
- const isTimelineMode = isMarkdownMode && layoutMode === 'timeline' && !isPreview;
676
- const [showFiles, setShowFiles] = useState(false);
677
- const [mediaRefreshKey, setMediaRefreshKey] = useState(0);
678
- const [mediaCount, setMediaCount] = useState(0);
679
- const mediaListRefreshKey = mediaRefreshKey + mediaRevision;
680
- const usedMediaPaths = useMemo(
681
- () => collectMediaReferencesFromMarkdown(markdownSource),
682
- [markdownSource],
683
- );
684
- // Persistent fallback container for image-edit sidecars when the host
685
- // didn't supply one. Lifted to shell scope so opening the same image
686
- // multiple times sees the same `.imageEdits/<sanitized>/.versions/...`
687
- // snapshots — otherwise each modal mount would start from an empty
688
- // in-memory container and history would vanish on close.
689
- const imageEditFallbackContainerRef = useRef<MemoryContentContainer | null>(null);
690
- if (imageEditFallbackContainerRef.current === null) {
691
- imageEditFallbackContainerRef.current = new MemoryContentContainer();
692
- }
693
- const imageEditFallbackContainer = imageEditFallbackContainerRef.current;
694
- const isDark = colorScheme === 'dark';
695
-
696
- useEffect(() => {
697
- if (!mediaProvider) {
698
- setMediaCount(0);
699
- return;
700
- }
701
-
702
- let cancelled = false;
703
- mediaProvider.listMedia().then(
704
- (entries) => {
705
- if (!cancelled) setMediaCount(filterVisibleMediaEntries(entries).length);
706
- },
707
- (err: unknown) => {
708
- if (!cancelled) {
709
- setMediaCount(0);
710
- console.warn(
711
- '[squisq-editor] Failed to read media list:',
712
- err instanceof Error ? err.message : err,
713
- );
714
- }
715
- },
716
- );
717
-
718
- return () => {
719
- cancelled = true;
720
- };
721
- }, [mediaProvider, mediaListRefreshKey]);
722
-
723
- const handleToggleFiles = useCallback(() => {
724
- setShowFiles((prev) => !prev);
725
- }, []);
726
-
727
- // ── Drag-and-drop file handling ──
728
-
729
- /**
730
- * Insert an uploaded media file at the editor's current cursor.
731
- *
732
- * - In **WYSIWYG** mode, insert an actual tiptap image node via
733
- * `setImage({src, alt})` (images) or a link mark (non-images).
734
- * Going through `setImage` directly mirrors the Toolbar's image
735
- * button and avoids the round-trip through `markdownToTiptap`
736
- * that historically lost `<img>` tags to tag-strip passes.
737
- * - In **raw (Monaco)** or **preview** mode, fall back to
738
- * `insertAtCursor` which emits the markdown snippet.
739
- *
740
- * Without this, upload-via-MediaBin and upload-via-drop both
741
- * added the file to the bin and nowhere else — the composer sent
742
- * an empty body and the downstream consumer reported "nothing came
743
- * through."
744
- */
745
- const insertMediaRef = useCallback(
746
- (relativePath: string, name: string, mimeType: string) => {
747
- const alt = name.replace(/\.[^.]+$/, '').replace(/[-_]/g, ' ');
748
- const isImage = mimeType.startsWith('image/');
749
- const snippet = isImage ? `![${alt}](${relativePath})` : `[${alt}](${relativePath})`;
750
-
751
- if (activeView === 'wysiwyg' && tiptapEditor) {
752
- if (isImage) {
753
- tiptapEditor.chain().focus().setImage({ src: relativePath, alt }).run();
754
- } else {
755
- tiptapEditor
756
- .chain()
757
- .focus()
758
- .insertContent([
759
- {
760
- type: 'text',
761
- marks: [{ type: 'link', attrs: { href: relativePath } }],
762
- text: alt,
763
- },
764
- ])
765
- .run();
766
- }
767
- return;
768
- }
769
- if (activeView === 'raw' && monacoEditor) {
770
- insertAtCursor(snippet);
771
- return;
772
- }
773
- // Preview mode — no interactive editor to insert into. Append
774
- // to markdown source so the ref is still in the buffer.
775
- setMarkdownSource(markdownSource ? `${markdownSource}\n\n${snippet}` : snippet);
776
- },
777
- [activeView, tiptapEditor, monacoEditor, insertAtCursor, markdownSource, setMarkdownSource],
778
- );
779
-
780
- const handleMediaUploaded = useCallback(
781
- (relativePath: string, name: string, mimeType: string) => {
782
- insertMediaRef(relativePath, name, mimeType);
783
- setMediaRefreshKey((k) => k + 1);
784
- },
785
- [insertMediaRef],
786
- );
787
-
788
- const handleMediaRemoved = useCallback(
789
- (relativePath: string) => {
790
- const nextSource = removeMediaReferencesFromMarkdown(markdownSource, relativePath);
791
- if (nextSource !== markdownSource) replaceAll(nextSource);
792
- setMediaRefreshKey((k) => k + 1);
793
- bumpMediaRevision();
794
- },
795
- [bumpMediaRevision, markdownSource, replaceAll],
796
- );
797
-
798
- const handleFileDrop = useCallback(
799
- async (files: File[], target: DropTarget) => {
800
- try {
801
- const { media, text } = partitionFiles(files);
802
-
803
- // Process media files
804
- if (media.length > 0 && mediaProvider) {
805
- const paths = await processMediaFiles(media, mediaProvider);
806
- setMediaRefreshKey((k) => k + 1);
807
- // Auto-open the media bin so the user sees the new files
808
- if (!showFiles) setShowFiles(true);
809
- // Insert each uploaded file as a markdown ref at the cursor so
810
- // the body actually contains the attachment. Without this the
811
- // bin holds the file but the serialized markdown stays empty,
812
- // and anything downstream (chat send, document save) sees no
813
- // reference to the upload.
814
- for (let i = 0; i < media.length; i++) {
815
- const file = media[i];
816
- const path = paths[i];
817
- if (!file || !path) continue;
818
- insertMediaRef(path, file.name, file.type || 'application/octet-stream');
819
- }
820
- }
821
-
822
- // Process text files
823
- if (text.length > 0) {
824
- if (target === 'replace') {
825
- // Replace with first text file
826
- const content = await processTextFile(text[0]);
827
- replaceAll(content);
828
- } else {
829
- // Insert all text files concatenated
830
- const content = await processTextFiles(text);
831
- insertAtCursor(content);
832
- }
833
- }
834
- } catch (err: unknown) {
835
- console.error('Failed to process dropped files:', err instanceof Error ? err.message : err);
836
- }
837
- },
838
- [mediaProvider, showFiles, replaceAll, insertAtCursor, insertMediaRef],
839
- );
840
-
841
- const { isDragging, dragContentType, containerProps, zoneProps } = useFileDrop({
842
- onDrop: handleFileDrop,
843
- enabled: !readOnly,
844
- });
845
-
846
- // Notify parent of changes
847
- useEffect(() => {
848
- onChange?.(markdownSource);
849
- }, [markdownSource, onChange]);
850
-
851
- // View shortcuts bubble only through the editor that currently owns focus.
852
- const handleShellKeyDown = useCallback(
853
- (e: ReactKeyboardEvent<HTMLDivElement>) => {
854
- if (!e.ctrlKey && !e.metaKey) return;
855
- const view =
856
- e.key === '1' ? 'wysiwyg' : e.key === '2' ? 'raw' : e.key === '3' ? 'preview' : null;
857
- if (!view || (view === 'preview' && !showPlayTab)) return;
858
- const button = shellRef.current?.querySelector<HTMLButtonElement>(`[data-view="${view}"]`);
859
- if (!button) return;
860
- e.preventDefault();
861
- e.stopPropagation();
862
- button.click();
863
- },
864
- [showPlayTab],
865
- );
866
-
867
- const autoGrow = minHeight !== undefined || maxHeight !== undefined;
868
-
869
- return (
870
- <div
871
- ref={shellRef}
872
- onKeyDown={handleShellKeyDown}
873
- className={`squisq-editor-shell ${className || ''}`}
874
- data-theme={colorScheme}
875
- data-full-width={fullWidth ? 'true' : undefined}
876
- data-thin-margins={thinMargins ? 'true' : undefined}
877
- data-outline-visible={isMarkdownMode && outlineVisible ? 'true' : undefined}
878
- style={{
879
- display: 'flex',
880
- flexDirection: 'column',
881
- overflow: 'hidden',
882
- ...(autoGrow ? { minHeight, maxHeight } : { height }),
883
- // When a consumer supplies a UX font stack, expose it to the
884
- // editor CSS via this custom property. Chrome elements (toolbar,
885
- // tabs, status bar) consume `--squisq-ux-font` as their
886
- // `font-family`, falling back to the system stack when unset.
887
- ...(uxFont ? ({ '--squisq-ux-font': uxFont } as CSSProperties) : {}),
888
- ...writeCanvasSettingsStyle(writeCanvasSettings),
889
- // Exposed so the toolbar's view-tabs section AND the outline pane read
890
- // one shared width, lining up the view-tabs' right-edge separator with
891
- // the outline's right edge. A fixed `outlineWidth` pins it to px;
892
- // otherwise it's the responsive clamp so the pane stretches when
893
- // there's room. The `data-outline-visible` gate above keeps the
894
- // toolbar override scoped to the case where alignment matters.
895
- ...({
896
- '--squisq-outline-width':
897
- outlineWidth != null ? `${outlineWidth}px` : OUTLINE_RESPONSIVE_WIDTH,
898
- } as CSSProperties),
899
- }}
900
- {...containerProps}
901
- >
902
- <CustomThemeProvider docThemes={docThemes} onDocThemesChange={onDocThemesChange}>
903
- <PreviewSettingsProvider doc={doc} themeOverride={themeOverride}>
904
- <PresentationModeProvider rootRef={shellRef}>
905
- {/* Header. In image mode the full markdown/code Toolbar is replaced
906
- with a minimal slot bar — view tabs, formatting, and preview
907
- controls don't apply to a binary asset. */}
908
- {isImageMode ? (
909
- (toolbarSlotLeft || toolbarSlotRight) && (
910
- <div className="squisq-editor-header squisq-editor-header--image">
911
- {toolbarSlotLeft}
912
- <div style={{ flex: 1 }} />
913
- {toolbarSlotRight}
914
- </div>
915
- )
916
- ) : (
917
- <div className="squisq-editor-header">
918
- <Toolbar
919
- showFiles={showFiles}
920
- fileCount={mediaCount}
921
- onToggleFiles={!isCodeMode && filesToggleEnabled ? handleToggleFiles : undefined}
922
- slotLeft={toolbarSlotLeft}
923
- slotAfterTabs={
924
- !isCodeMode &&
925
- isPreview && (
926
- <>
927
- <PreviewToolbarControls />
928
- <PresentationModeControl />
929
- </>
930
- )
931
- }
932
- slotAfterActions={toolbarSlotAfterActions}
933
- slotRight={toolbarSlotRight}
934
- showPlayTab={showPlayTab}
935
- />
936
- </div>
937
- )}
938
-
939
- {/* Main content area */}
940
- <div
941
- className="squisq-editor-content"
942
- style={{
943
- flex: autoGrow ? '1 1 auto' : 1,
944
- overflowY: autoGrow ? 'auto' : 'hidden',
945
- overflowX: 'hidden',
946
- minHeight: 0,
947
- position: 'relative',
948
- display: 'flex',
949
- }}
950
- >
951
- <div
952
- style={{
953
- flex: autoGrow ? '1 1 auto' : 1,
954
- overflow: autoGrow ? 'visible' : 'hidden',
955
- minHeight: 0,
956
- position: 'relative',
957
- }}
958
- >
959
- {isImageMode &&
960
- imageSrc &&
961
- (imageMode === 'edit' && imageEditorContainer ? (
962
- <ImageEditor
963
- filesContainer={imageEditorContainer}
964
- initialSrc={imageSrc}
965
- allowVersioning={allowVersioning}
966
- versioningAutoSaveIdleMs={versioningAutoSaveIdleMs}
967
- onExport={onImageExport}
968
- surface={colorScheme === 'dark' ? DARK_SURFACE : LIGHT_SURFACE}
969
- />
970
- ) : (
971
- <ImageViewer src={imageSrc} alt={imageAlt} theme={colorScheme} />
972
- ))}
973
- {/* Raw (Monaco) view. Always wrapped in `.squisq-editor-with-gutter`
974
- so toggling a pane on/off doesn't change the editor's tree
975
- position — Monaco stays mounted and `monacoEditor` in
976
- context stays stable, which is what `useHeadingLayout` needs
977
- to compute positions. */}
978
- {!isImageMode && activeView === 'raw' && (
979
- <div className="squisq-editor-with-gutter" key="raw-shell">
980
- {isMarkdownMode && outlineVisible && (
981
- <OutlinePanel key="outline" width={outlineWidth} readOnly={readOnly} />
982
- )}
983
- {isCardMode ? (
984
- <BlockCardView
985
- key="raw-card"
986
- blockCount={blockCount}
987
- activeBlockKey={activeBlockKey}
988
- onPrev={prevBlock}
989
- onNext={nextBlock}
990
- onAdd={addBlock}
991
- >
992
- <div key="raw-editor" className="squisq-raw-editor-container">
993
- <RawEditor
994
- monacoTheme={colorScheme === 'dark' ? 'vs-dark' : 'vs'}
995
- submitOnEnter={submitOnEnter}
996
- readOnly={readOnly}
997
- />
998
- </div>
999
- </BlockCardView>
1000
- ) : (
1001
- <div key="raw-editor" className="squisq-raw-editor-container">
1002
- <RawEditor
1003
- monacoTheme={colorScheme === 'dark' ? 'vs-dark' : 'vs'}
1004
- submitOnEnter={submitOnEnter}
1005
- readOnly={readOnly}
1006
- />
1007
- </div>
1008
- )}
1009
- {/* Renders nothing in normal flow — portals context
1010
- sections into Monaco view zones via the context's
1011
- monacoEditor. Code mode only. */}
1012
- {isCodeMode && codeContext && (
1013
- <CodeContextZones key="code-context" options={codeContext} />
1014
- )}
1015
- {isMarkdownMode && isCardMode && inlinePreviewVisible && (
1016
- <BlockPreviewPanel key="block-preview" basePath={basePath} />
1017
- )}
1018
- {isMarkdownMode && !isCardMode && inlinePreviewVisible && (
1019
- <InlinePreviewGutter
1020
- key="inline"
1021
- width={inlinePreviewWidth}
1022
- basePath={basePath}
1023
- mediaProvider={mediaProvider}
1024
- />
1025
- )}
1026
- </div>
1027
- )}
1028
- {/* WYSIWYG + Preview are markdown-only surfaces — skip them
1029
- entirely in code or image mode so Tiptap never initializes
1030
- and the preview pipeline stays idle. Same always-wrapped
1031
- pattern as the Raw branch above so pane toggles don't
1032
- remount Tiptap. */}
1033
- {isMarkdownMode && activeView === 'wysiwyg' && (
1034
- <div className="squisq-editor-with-gutter" key="wysiwyg-shell">
1035
- {outlineVisible && (
1036
- <OutlinePanel key="outline" width={outlineWidth} readOnly={readOnly} />
1037
- )}
1038
- {isCardMode ? (
1039
- <BlockCardView
1040
- key="wysiwyg-card"
1041
- blockCount={blockCount}
1042
- activeBlockKey={activeBlockKey}
1043
- onPrev={prevBlock}
1044
- onNext={nextBlock}
1045
- onAdd={addBlock}
1046
- >
1047
- <WysiwygEditor
1048
- key="wysiwyg-editor"
1049
- submitOnEnter={submitOnEnter}
1050
- placeholder={placeholder}
1051
- readOnly={readOnly}
1052
- />
1053
- </BlockCardView>
1054
- ) : (
1055
- <WysiwygEditor
1056
- key="wysiwyg-editor"
1057
- submitOnEnter={submitOnEnter}
1058
- placeholder={placeholder}
1059
- readOnly={readOnly}
1060
- />
1061
- )}
1062
- {isCardMode && inlinePreviewVisible && (
1063
- <BlockPreviewPanel key="block-preview" basePath={basePath} />
1064
- )}
1065
- {!isCardMode && inlinePreviewVisible && (
1066
- <InlinePreviewGutter
1067
- key="inline"
1068
- width={inlinePreviewWidth}
1069
- basePath={basePath}
1070
- mediaProvider={mediaProvider}
1071
- />
1072
- )}
1073
- </div>
1074
- )}
1075
- {isMarkdownMode && isPreview && (
1076
- <PreviewPanel basePath={basePath} workspaceContainer={workspaceContainer} />
1077
- )}
1078
- </div>
1079
-
1080
- {isMarkdownMode && showFiles && (
1081
- <MediaBin
1082
- mediaProvider={mediaProvider}
1083
- isDark={isDark}
1084
- refreshKey={mediaListRefreshKey}
1085
- usedMediaPaths={usedMediaPaths}
1086
- onMediaUploaded={handleMediaUploaded}
1087
- onMediaRemoved={handleMediaRemoved}
1088
- onCountChange={setMediaCount}
1089
- />
1090
- )}
1091
-
1092
- {/* Docked custom-theme designer — a flex sibling of the preview, so
1093
- opening it reflows the preview narrower. Renders nothing when the
1094
- designer is closed. */}
1095
- {isMarkdownMode && <ThemeDesignerDock />}
1096
-
1097
- {/* Drop zone overlay — image / text drop UX is markdown-specific.
1098
- In WYSIWYG, image drops are handled directly by Tiptap's
1099
- `handleDrop` (uploads to the MediaProvider and inserts an
1100
- image node at the mouse position). The overlay would sit on
1101
- top with z-index: 50 and intercept the drop, so we skip it
1102
- when the dragged content is media-only on the WYSIWYG view —
1103
- the user gets a one-step "drop where you want it" flow
1104
- instead of a two-step "drop in bin, then insert" flow. */}
1105
- {isMarkdownMode &&
1106
- isDragging &&
1107
- !(activeView === 'wysiwyg' && dragContentType === 'media') && (
1108
- <DropZoneOverlay
1109
- dragContentType={dragContentType}
1110
- zoneProps={zoneProps}
1111
- hasMediaProvider={mediaProvider !== null}
1112
- />
1113
- )}
1114
- </div>
1115
-
1116
- {/* Timeline track — horizontal strip of block + media bars shown
1117
- below the editor in Timeline view. The card editor above (driven by
1118
- the block navigator) shows whichever block is selected here. */}
1119
- {isTimelineMode && <TimelineTrack />}
1120
-
1121
- {/* Status bar — word / char / line / block counts. Host can
1122
- suppress via `showStatusBar={false}` for embedded chat-style
1123
- composers where the stats are noise. The image viewer has its
1124
- own dimension/zoom status row, so suppress here too. */}
1125
- {statusBarVisible && !isImageMode && <StatusBar />}
1126
- </PresentationModeProvider>
1127
- </PreviewSettingsProvider>
1128
- </CustomThemeProvider>
1129
- <TooltipLayer />
1130
- {imageEditTarget !== null && mediaProvider && (
1131
- <ImageEditModal
1132
- relativePath={imageEditTarget}
1133
- container={workspaceContainer ?? imageEditFallbackContainer}
1134
- mediaProvider={mediaProvider}
1135
- onClose={closeImageEdit}
1136
- onSaved={() => {
1137
- bumpMediaRevision();
1138
- closeImageEdit();
1139
- }}
1140
- allowVersioning={allowVersioning}
1141
- versioningAutoSaveIdleMs={versioningAutoSaveIdleMs}
1142
- shellTheme={colorScheme}
1143
- />
1144
- )}
1145
- </div>
1146
- );
1147
- }
1148
-
1149
- // ─── ImageEditModal ────────────────────────────────────────
1150
-
1151
- interface ImageEditModalProps {
1152
- relativePath: string;
1153
- /**
1154
- * Host's `ContentContainer`. When non-null the editor's per-image
1155
- * sidecar is scoped underneath it as `.imageEdits/<sanitized>/` so
1156
- * version snapshots travel with the doc. When null (host wired only a
1157
- * `mediaProvider`) the modal creates a fresh in-memory container for
1158
- * the edit session — export still writes the result back through
1159
- * `mediaProvider`.
1160
- */
1161
- container: ContentContainer | null;
1162
- mediaProvider: MediaProvider;
1163
- onClose: () => void;
1164
- onSaved: () => void;
1165
- allowVersioning: boolean;
1166
- versioningAutoSaveIdleMs?: number;
1167
- /** EditorShell's `colorScheme` prop — 'light' or 'dark'. Threaded through
1168
- * so the image editor chrome matches the host shell. */
1169
- shellTheme?: 'light' | 'dark';
1170
- }
1171
-
1172
- /**
1173
- * Modal overlay that mounts a full `<ImageEditor>` against a sidecar
1174
- * container scoped under `.imageEdits/<sanitized-path>/` of the document's
1175
- * `ContentContainer`. Opens when a user clicks the "Edit" affordance on an
1176
- * image in the WYSIWYG view; on Export, rewrites the original image bytes
1177
- * via `mediaProvider.addMedia(relativePath, blob, mime)` and bumps
1178
- * `mediaRevision` so live `<img>` nodes pick up the new content.
1179
- */
1180
- function ImageEditModal({
1181
- relativePath,
1182
- container,
1183
- mediaProvider,
1184
- onClose,
1185
- onSaved,
1186
- allowVersioning,
1187
- versioningAutoSaveIdleMs,
1188
- shellTheme,
1189
- }: ImageEditModalProps) {
1190
- const modalRef = useRef<HTMLDivElement>(null);
1191
- const surfaceRef = useRef<HTMLDivElement>(null);
1192
- const onCloseRef = useRef(onClose);
1193
- onCloseRef.current = onClose;
1194
- const extension = relativePath.split(/[?#]/, 1)[0]?.split('.').pop()?.toLowerCase();
1195
- const saveFormat: 'png' | 'jpeg' | 'webp' | null =
1196
- extension === 'png'
1197
- ? 'png'
1198
- : extension === 'jpg' || extension === 'jpeg'
1199
- ? 'jpeg'
1200
- : extension === 'webp'
1201
- ? 'webp'
1202
- : null;
1203
- // Each unique image path gets its own sidecar so multiple images in the
1204
- // same doc can be edited independently without colliding state. When the
1205
- // host didn't supply a `container`, fall back to a fresh in-memory one
1206
- // — the edit session is transient anyway and the final raster is what
1207
- // gets written back through `mediaProvider`.
1208
- const sidecar = useMemo(() => {
1209
- const sanitized = relativePath.replace(/[^a-zA-Z0-9._-]+/g, '_');
1210
- let hash = 2166136261;
1211
- for (let i = 0; i < relativePath.length; i++) {
1212
- hash ^= relativePath.charCodeAt(i);
1213
- hash = Math.imul(hash, 16777619);
1214
- }
1215
- const scopedName = `${sanitized}-${(hash >>> 0).toString(36)}`;
1216
- const parent: ContentContainer = container ?? new MemoryContentContainer();
1217
- return scopeContainer(parent, `.imageEdits/${scopedName}`);
1218
- }, [container, relativePath]);
1219
-
1220
- const [initialSrc, setInitialSrc] = useState<string | null>(null);
1221
- const [resolveError, setResolveError] = useState<string | null>(null);
1222
- useEffect(() => {
1223
- let cancelled = false;
1224
- setInitialSrc(null);
1225
- setResolveError(null);
1226
- mediaProvider.resolveUrl(relativePath).then(
1227
- (url) => {
1228
- if (!cancelled) setInitialSrc(url);
1229
- },
1230
- (err: unknown) => {
1231
- if (!cancelled) {
1232
- setResolveError(err instanceof Error ? err.message : String(err));
1233
- }
1234
- },
1235
- );
1236
- return () => {
1237
- cancelled = true;
1238
- };
1239
- }, [mediaProvider, relativePath]);
1240
-
1241
- const handleExport = useCallback(
1242
- (blob: Blob, format: 'png' | 'jpeg' | 'webp') => {
1243
- const mime = `image/${format}`;
1244
- mediaProvider.addMedia(relativePath, blob, mime).then(
1245
- () => onSaved(),
1246
- (err: unknown) => {
1247
- console.error('Failed to write image back:', err instanceof Error ? err.message : err);
1248
- },
1249
- );
1250
- },
1251
- [mediaProvider, relativePath, onSaved],
1252
- );
1253
-
1254
- // Close on Escape — global listener so it works regardless of focus.
1255
- useEffect(() => {
1256
- const previousFocus = document.activeElement as HTMLElement | null;
1257
- const shell = modalRef.current?.closest('.squisq-editor-shell');
1258
- const inertSiblings = shell
1259
- ? Array.from(shell.children).filter((element) => !element.contains(modalRef.current))
1260
- : [];
1261
- inertSiblings.forEach((element) => {
1262
- (element as HTMLElement).inert = true;
1263
- });
1264
- surfaceRef.current
1265
- ?.querySelector<HTMLElement>(
1266
- 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])',
1267
- )
1268
- ?.focus();
1269
- const handler = (e: KeyboardEvent) => {
1270
- if (e.key === 'Escape') {
1271
- e.preventDefault();
1272
- onCloseRef.current();
1273
- return;
1274
- }
1275
- if (e.key !== 'Tab' || !surfaceRef.current) return;
1276
- const focusable = Array.from(
1277
- surfaceRef.current.querySelectorAll<HTMLElement>(
1278
- 'button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])',
1279
- ),
1280
- );
1281
- if (focusable.length === 0) return;
1282
- const first = focusable[0];
1283
- const last = focusable[focusable.length - 1];
1284
- if (e.shiftKey && document.activeElement === first) {
1285
- e.preventDefault();
1286
- last.focus();
1287
- } else if (!e.shiftKey && document.activeElement === last) {
1288
- e.preventDefault();
1289
- first.focus();
1290
- }
1291
- };
1292
- window.addEventListener('keydown', handler);
1293
- return () => {
1294
- window.removeEventListener('keydown', handler);
1295
- inertSiblings.forEach((element) => {
1296
- (element as HTMLElement).inert = false;
1297
- });
1298
- previousFocus?.focus();
1299
- };
1300
- }, []);
1301
-
1302
- return (
1303
- <div
1304
- ref={modalRef}
1305
- className="squisq-image-edit-modal"
1306
- data-testid="image-edit-modal"
1307
- role="dialog"
1308
- aria-modal="true"
1309
- aria-label={`Edit ${relativePath}`}
1310
- onClick={(e) => {
1311
- // Click on the dim backdrop (but not on the surface) → close.
1312
- if (e.target === e.currentTarget) onClose();
1313
- }}
1314
- >
1315
- <div ref={surfaceRef} className="squisq-image-edit-modal__surface">
1316
- <header className="squisq-image-edit-modal__header">
1317
- <span className="squisq-image-edit-modal__title">Edit image</span>
1318
- <span className="squisq-image-edit-modal__path">{relativePath}</span>
1319
- <button
1320
- type="button"
1321
- className="squisq-image-edit-modal__close"
1322
- data-testid="image-edit-modal-close"
1323
- onClick={onClose}
1324
- aria-label="Close image editor"
1325
- >
1326
- ×
1327
- </button>
1328
- </header>
1329
- <div className="squisq-image-edit-modal__body">
1330
- {resolveError ? (
1331
- <div className="squisq-image-edit-modal__error">
1332
- Failed to load image: {resolveError}
1333
- </div>
1334
- ) : !saveFormat ? (
1335
- <div className="squisq-image-edit-modal__error">
1336
- Editing supports PNG, JPEG, and WebP images without changing the asset type.
1337
- </div>
1338
- ) : !initialSrc ? (
1339
- <div className="squisq-image-edit-modal__loading">Loading image…</div>
1340
- ) : (
1341
- <ImageEditor
1342
- filesContainer={sidecar}
1343
- initialSrc={initialSrc}
1344
- allowVersioning={allowVersioning}
1345
- versioningAutoSaveIdleMs={versioningAutoSaveIdleMs}
1346
- onExport={handleExport}
1347
- saveBehavior="export"
1348
- saveFormat={saveFormat}
1349
- saveLabel="Save and close"
1350
- saveTitle="Save changes back to the image and close"
1351
- surface={shellTheme === 'dark' ? DARK_SURFACE : LIGHT_SURFACE}
1352
- />
1353
- )}
1354
- </div>
1355
- </div>
1356
- </div>
1357
- );
1358
- }