@bendyline/squisq-editor-react 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (394) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE.md +40 -0
  3. package/dist/index.d.ts +188 -55
  4. package/dist/index.js +5094 -2948
  5. package/dist/monaco.js +0 -1
  6. package/dist/styles/index.css +234 -145
  7. package/package.json +9 -6
  8. package/dist/index.js.map +0 -1
  9. package/dist/monaco.js.map +0 -1
  10. package/src/BlockCardView.tsx +0 -121
  11. package/src/BlockPreviewPanel.tsx +0 -69
  12. package/src/BlockPropertiesPopover.tsx +0 -222
  13. package/src/DocumentSettingsDialog.tsx +0 -272
  14. package/src/DropZoneOverlay.tsx +0 -137
  15. package/src/EditorContext.tsx +0 -1274
  16. package/src/EditorShell.tsx +0 -1358
  17. package/src/EmojiPicker.tsx +0 -332
  18. package/src/FolderView.tsx +0 -131
  19. package/src/Icon.tsx +0 -26
  20. package/src/ImageEditor.tsx +0 -395
  21. package/src/ImageNodeView.tsx +0 -284
  22. package/src/ImageViewer.tsx +0 -221
  23. package/src/InlineIcon.ts +0 -84
  24. package/src/InlinePreviewGutter.tsx +0 -590
  25. package/src/LinkDialog.tsx +0 -276
  26. package/src/MediaBin.tsx +0 -500
  27. package/src/MentionExtension.tsx +0 -261
  28. package/src/OutlinePanel.tsx +0 -547
  29. package/src/PlainHtmlPreview.tsx +0 -277
  30. package/src/PreviewControls.tsx +0 -1265
  31. package/src/PreviewPanel.tsx +0 -426
  32. package/src/RawEditor.tsx +0 -743
  33. package/src/RecorderEntry.tsx +0 -162
  34. package/src/StatusBar.tsx +0 -51
  35. package/src/TemplateAnnotation.ts +0 -167
  36. package/src/TemplateContentPreview.tsx +0 -56
  37. package/src/TemplatePicker.tsx +0 -1314
  38. package/src/ThemeCustomizerPanel.tsx +0 -304
  39. package/src/ThemePicker.tsx +0 -433
  40. package/src/TimelineBlockPreview.tsx +0 -37
  41. package/src/TimelineTrack.tsx +0 -671
  42. package/src/Toolbar.tsx +0 -2885
  43. package/src/Tooltip.tsx +0 -142
  44. package/src/TransitionPicker.tsx +0 -390
  45. package/src/VersionHistoryPanel.tsx +0 -359
  46. package/src/ViewMenuPanel.tsx +0 -189
  47. package/src/ViewSwitcher.tsx +0 -56
  48. package/src/WysiwygEditor.tsx +0 -806
  49. package/src/__tests__/blockProperties.test.ts +0 -92
  50. package/src/__tests__/blockPropertiesPopoverTheme.test.tsx +0 -33
  51. package/src/__tests__/blockRange.test.ts +0 -105
  52. package/src/__tests__/blockTagActivity.test.ts +0 -183
  53. package/src/__tests__/buildDocumentPreviewMarkdown.test.ts +0 -75
  54. package/src/__tests__/buildPreviewDocContent.test.ts +0 -65
  55. package/src/__tests__/buildPreviewDocTransition.test.ts +0 -92
  56. package/src/__tests__/canvasSurfaceTextEditing.test.tsx +0 -60
  57. package/src/__tests__/codeContextSectionView.test.tsx +0 -97
  58. package/src/__tests__/codeContextZoneManager.test.ts +0 -127
  59. package/src/__tests__/createShapeLayer.test.ts +0 -46
  60. package/src/__tests__/customLayoutManagerTheme.test.tsx +0 -34
  61. package/src/__tests__/detectMarkdown.test.ts +0 -73
  62. package/src/__tests__/diffContextSections.test.ts +0 -39
  63. package/src/__tests__/documentSettingsDialog.test.tsx +0 -197
  64. package/src/__tests__/drawingShapeRoundTrip.test.ts +0 -49
  65. package/src/__tests__/editorScrollHandoff.test.tsx +0 -102
  66. package/src/__tests__/editorScrollSync.test.ts +0 -65
  67. package/src/__tests__/editorShellCodeContext.test.tsx +0 -86
  68. package/src/__tests__/editorShellProps.test.tsx +0 -550
  69. package/src/__tests__/embeddedMedia.test.ts +0 -48
  70. package/src/__tests__/emojiPicker.test.tsx +0 -93
  71. package/src/__tests__/fileKind.test.ts +0 -112
  72. package/src/__tests__/findMode.test.tsx +0 -104
  73. package/src/__tests__/findModel.test.ts +0 -55
  74. package/src/__tests__/headingTransition.test.ts +0 -176
  75. package/src/__tests__/imageEditAffordance.test.tsx +0 -272
  76. package/src/__tests__/imageEditModalContract.test.tsx +0 -119
  77. package/src/__tests__/imageEditorShell.test.tsx +0 -94
  78. package/src/__tests__/imageEditorState.test.ts +0 -171
  79. package/src/__tests__/inlinePreviewGutter.test.tsx +0 -62
  80. package/src/__tests__/inlinePreviewGutterAllBlocks.test.tsx +0 -103
  81. package/src/__tests__/jsonEditor.test.tsx +0 -223
  82. package/src/__tests__/layersPanel.test.tsx +0 -167
  83. package/src/__tests__/layoutChildRoundTrip.test.ts +0 -71
  84. package/src/__tests__/linkDialogDocPicker.test.tsx +0 -137
  85. package/src/__tests__/majorApiTypes.test.ts +0 -26
  86. package/src/__tests__/markdownCodeFence.test.ts +0 -45
  87. package/src/__tests__/mediaAttachmentFlow.test.ts +0 -110
  88. package/src/__tests__/mediaBinDrop.test.tsx +0 -90
  89. package/src/__tests__/mediaReferences.test.ts +0 -97
  90. package/src/__tests__/narrationSave.test.ts +0 -148
  91. package/src/__tests__/outlinePanel.test.tsx +0 -169
  92. package/src/__tests__/outlineSource.test.ts +0 -217
  93. package/src/__tests__/plainHtmlPreview.test.tsx +0 -125
  94. package/src/__tests__/presentationMode.test.tsx +0 -290
  95. package/src/__tests__/previewControls.test.tsx +0 -571
  96. package/src/__tests__/previewPanelAudioFailure.test.tsx +0 -46
  97. package/src/__tests__/previewPanelPresentation.test.tsx +0 -126
  98. package/src/__tests__/previewPanelTransforms.test.tsx +0 -117
  99. package/src/__tests__/propertiesPanel.test.tsx +0 -69
  100. package/src/__tests__/rawEditorModelIsolation.test.ts +0 -19
  101. package/src/__tests__/recorderFormats.test.ts +0 -146
  102. package/src/__tests__/recorderMediaInsert.test.ts +0 -86
  103. package/src/__tests__/recorderTheme.test.tsx +0 -42
  104. package/src/__tests__/recorderTimingJson.test.ts +0 -41
  105. package/src/__tests__/resolveBlockVisual.test.ts +0 -43
  106. package/src/__tests__/selectionConversions.test.ts +0 -80
  107. package/src/__tests__/statusBar.test.tsx +0 -27
  108. package/src/__tests__/teleprompter.test.tsx +0 -190
  109. package/src/__tests__/templateAnnotationRoundTrip.test.ts +0 -99
  110. package/src/__tests__/templateContentPreview.test.ts +0 -101
  111. package/src/__tests__/templatePickerMetadata.test.ts +0 -32
  112. package/src/__tests__/templatePickerPortal.test.tsx +0 -62
  113. package/src/__tests__/timelineSource.test.ts +0 -134
  114. package/src/__tests__/tiptapBridge.test.ts +0 -575
  115. package/src/__tests__/tiptapBridgeConformance.test.ts +0 -47
  116. package/src/__tests__/tiptapCodeBlockRoundTrip.test.ts +0 -109
  117. package/src/__tests__/tiptapImageRoundTrip.test.ts +0 -73
  118. package/src/__tests__/toolbarSelectionConversion.test.tsx +0 -190
  119. package/src/__tests__/tooltip.test.tsx +0 -72
  120. package/src/__tests__/transformStyleId.test.ts +0 -13
  121. package/src/__tests__/transitionCatalog.test.ts +0 -64
  122. package/src/__tests__/useBlockNavigator.test.tsx +0 -67
  123. package/src/__tests__/useImageEditor.test.tsx +0 -226
  124. package/src/__tests__/useJsonEditorTokens.test.ts +0 -59
  125. package/src/__tests__/useMediaRecorder.test.ts +0 -302
  126. package/src/__tests__/useTimelineClock.test.ts +0 -21
  127. package/src/__tests__/versionHistory.test.tsx +0 -197
  128. package/src/__tests__/viewMenuPanel.test.tsx +0 -130
  129. package/src/__tests__/writeCanvasSettings.test.ts +0 -15
  130. package/src/__tests__/wysiwygImageUpload.test.ts +0 -69
  131. package/src/__tests__/wysiwygTemplateBadgeFocus.test.tsx +0 -56
  132. package/src/asciiDiagram/AsciiDiagramExtension.ts +0 -343
  133. package/src/asciiDiagram/AsciiDiagramWidget.tsx +0 -254
  134. package/src/asciiDiagram/RepairableDiagramExtension.ts +0 -200
  135. package/src/asciiDiagram/__tests__/AsciiDiagramExtension.test.ts +0 -164
  136. package/src/asciiDiagram/__tests__/RepairableDiagramExtension.test.ts +0 -159
  137. package/src/asciiDiagram/__tests__/asciiDiagramCommands.test.ts +0 -284
  138. package/src/asciiDiagram/__tests__/asciiDiagramOps.test.ts +0 -114
  139. package/src/asciiDiagram/__tests__/asciiPaste.test.ts +0 -43
  140. package/src/asciiDiagram/asciiDiagramCommands.ts +0 -174
  141. package/src/asciiDiagram/asciiDiagramData.ts +0 -149
  142. package/src/asciiDiagram/asciiDiagramOps.ts +0 -238
  143. package/src/asciiDiagram/asciiPaste.ts +0 -19
  144. package/src/blockProperties.ts +0 -88
  145. package/src/blockRange.ts +0 -132
  146. package/src/blockSlice.ts +0 -75
  147. package/src/blockTagActivity.ts +0 -233
  148. package/src/buildDocumentPreviewMarkdown.ts +0 -168
  149. package/src/buildPreviewDoc.ts +0 -407
  150. package/src/codeContext/CodeContextSectionView.tsx +0 -124
  151. package/src/codeContext/CodeContextZoneManager.ts +0 -149
  152. package/src/codeContext/CodeContextZones.tsx +0 -121
  153. package/src/codeContext/diffContextSections.ts +0 -38
  154. package/src/codeContext/types.ts +0 -75
  155. package/src/codeSnippet/CodeSnippetExtension.ts +0 -205
  156. package/src/codeSnippet/CodeSnippetWidget.tsx +0 -109
  157. package/src/codeSnippet/__tests__/CodeSnippetExtension.test.ts +0 -95
  158. package/src/codeSnippet/__tests__/codeSnippetLanguages.test.ts +0 -50
  159. package/src/codeSnippet/codeSnippetCommands.ts +0 -21
  160. package/src/codeSnippet/codeSnippetData.ts +0 -43
  161. package/src/codeSnippet/codeSnippetLanguages.ts +0 -216
  162. package/src/customTemplates/AddBin.tsx +0 -126
  163. package/src/customTemplates/CustomLayoutManager.tsx +0 -234
  164. package/src/customTemplates/CustomTemplateContext.tsx +0 -188
  165. package/src/customTemplates/LayerToolbar.tsx +0 -580
  166. package/src/customTemplates/ShapeGlyph.tsx +0 -47
  167. package/src/customTemplates/TemplateDesigner.tsx +0 -433
  168. package/src/customTemplates/__tests__/library.test.ts +0 -96
  169. package/src/customTemplates/__tests__/normalizePositions.test.ts +0 -109
  170. package/src/customTemplates/__tests__/shapeDefs.test.ts +0 -49
  171. package/src/customTemplates/__tests__/useMemoryLayerAdapter.test.ts +0 -108
  172. package/src/customTemplates/designer.css +0 -732
  173. package/src/customTemplates/index.ts +0 -31
  174. package/src/customTemplates/library.ts +0 -110
  175. package/src/customTemplates/normalizePositions.ts +0 -75
  176. package/src/customTemplates/shapeDefs.ts +0 -131
  177. package/src/customTemplates/thumbnail.tsx +0 -63
  178. package/src/customTemplates/tokenDefs.ts +0 -60
  179. package/src/customTemplates/useDocCustomTemplates.ts +0 -52
  180. package/src/customTemplates/useMemoryLayerAdapter.ts +0 -129
  181. package/src/customThemes/CustomThemeContext.tsx +0 -185
  182. package/src/customThemes/CustomThemeDialog.tsx +0 -316
  183. package/src/customThemes/ImportThemeSection.tsx +0 -178
  184. package/src/customThemes/__tests__/CustomThemeContext.test.tsx +0 -64
  185. package/src/customThemes/__tests__/CustomThemeDialog.test.tsx +0 -47
  186. package/src/customThemes/__tests__/customThemeLibrary.test.ts +0 -60
  187. package/src/customThemes/__tests__/importThemeSection.test.tsx +0 -192
  188. package/src/customThemes/customThemeLibrary.ts +0 -100
  189. package/src/customThemes/index.ts +0 -37
  190. package/src/customThemes/themeControls.tsx +0 -229
  191. package/src/customThemes/themeDraft.ts +0 -288
  192. package/src/customThemes/useDocCustomThemes.ts +0 -49
  193. package/src/detectMarkdown.ts +0 -62
  194. package/src/diagram/DiagramCanvas.tsx +0 -260
  195. package/src/diagram/DiagramMaximizedOverlay.tsx +0 -46
  196. package/src/diagram/diagramCommands.ts +0 -604
  197. package/src/diagram/diagramConstants.ts +0 -17
  198. package/src/diagram/types.ts +0 -35
  199. package/src/editorScrollSync.ts +0 -73
  200. package/src/embeddedMedia.ts +0 -78
  201. package/src/emojiData.ts +0 -1317
  202. package/src/fileKind.ts +0 -158
  203. package/src/find/FindHighlightExtension.ts +0 -81
  204. package/src/find/FindToolbar.tsx +0 -314
  205. package/src/find/findModel.ts +0 -77
  206. package/src/frontmatter.ts +0 -29
  207. package/src/frontmatterSettings.ts +0 -23
  208. package/src/headingTransition.ts +0 -291
  209. package/src/hooks/useFileDrop.ts +0 -266
  210. package/src/imageEditor/CanvasSurface.tsx +0 -703
  211. package/src/imageEditor/ImageVersionHistoryDropdown.tsx +0 -396
  212. package/src/imageEditor/LayersPanel.tsx +0 -218
  213. package/src/imageEditor/PropertiesPanel.tsx +0 -474
  214. package/src/imageEditor/Toolbar.tsx +0 -459
  215. package/src/imageEditor/createShapeLayer.ts +0 -280
  216. package/src/imageEditor/icons.tsx +0 -68
  217. package/src/imageEditor/image-editor.css +0 -574
  218. package/src/imageEditor/layers/EditorImageLayer.tsx +0 -45
  219. package/src/imageEditor/layers/EditorShapeLayer.tsx +0 -62
  220. package/src/imageEditor/layers/EditorTextLayer.tsx +0 -45
  221. package/src/imageEditor/layers/SelectionHandles.tsx +0 -86
  222. package/src/imageEditor/state.ts +0 -173
  223. package/src/imageEditor/useImageEditor.ts +0 -385
  224. package/src/imageEditor/useImageEditorTokens.ts +0 -70
  225. package/src/index.ts +0 -559
  226. package/src/jsonEditor/EmbeddedRichTextField.tsx +0 -81
  227. package/src/jsonEditor/JsonEditor.tsx +0 -81
  228. package/src/jsonEditor/JsonEditorContext.tsx +0 -81
  229. package/src/jsonEditor/RenderNode.tsx +0 -87
  230. package/src/jsonEditor/editors.tsx +0 -745
  231. package/src/jsonEditor/index.ts +0 -2
  232. package/src/jsonEditor/json-editor.css +0 -463
  233. package/src/jsonEditor/useJsonEditorTokens.ts +0 -33
  234. package/src/markdownCodeFence.ts +0 -72
  235. package/src/mediaDragMime.ts +0 -32
  236. package/src/mediaEntries.ts +0 -12
  237. package/src/mediaReferences.ts +0 -301
  238. package/src/mermaid/MermaidDiagramCanvas.tsx +0 -693
  239. package/src/mermaid/MermaidDiagramExtension.ts +0 -243
  240. package/src/mermaid/MermaidDiagramTypeThumbnail.tsx +0 -184
  241. package/src/mermaid/MermaidDiagramWidget.tsx +0 -653
  242. package/src/mermaid/MermaidShapePalette.tsx +0 -245
  243. package/src/mermaid/__tests__/MermaidDiagramExtension.test.ts +0 -361
  244. package/src/mermaid/__tests__/mermaidDiagramTypes.test.ts +0 -35
  245. package/src/mermaid/__tests__/mermaidRenderer.test.ts +0 -49
  246. package/src/mermaid/__tests__/mermaidSourceOps.test.ts +0 -213
  247. package/src/mermaid/__tests__/mermaidSyntax.test.ts +0 -71
  248. package/src/mermaid/mermaidCommands.ts +0 -34
  249. package/src/mermaid/mermaidData.ts +0 -31
  250. package/src/mermaid/mermaidDiagramTypes.ts +0 -325
  251. package/src/mermaid/mermaidModel.ts +0 -31
  252. package/src/mermaid/mermaidRenderer.ts +0 -181
  253. package/src/mermaid/mermaidShapes.ts +0 -113
  254. package/src/mermaid/mermaidSourceOps.ts +0 -454
  255. package/src/monaco.ts +0 -35
  256. package/src/monacoWorkers.ts +0 -89
  257. package/src/outlineSource.ts +0 -171
  258. package/src/presentation/PresentationMode.tsx +0 -596
  259. package/src/rawEditorIsolation.ts +0 -18
  260. package/src/recorder/RecorderButton.tsx +0 -80
  261. package/src/recorder/RecorderModal.tsx +0 -706
  262. package/src/recorder/RecorderPanel.tsx +0 -77
  263. package/src/recorder/formats.ts +0 -159
  264. package/src/recorder/hooks/useMediaRecorder.ts +0 -436
  265. package/src/recorder/hooks/useStreamPreview.ts +0 -47
  266. package/src/recorder/insertMediaBlock.ts +0 -30
  267. package/src/recorder/sources/cameraStream.ts +0 -32
  268. package/src/recorder/sources/micStream.ts +0 -25
  269. package/src/recorder/sources/screenStream.ts +0 -162
  270. package/src/recorder/timingJson.ts +0 -66
  271. package/src/resolveBlockVisual.ts +0 -39
  272. package/src/scene/Scene.tsx +0 -647
  273. package/src/scene/SceneBlockExtension.ts +0 -205
  274. package/src/scene/SceneBlockToolbar.tsx +0 -216
  275. package/src/scene/SceneBlockWidget.tsx +0 -441
  276. package/src/scene/ScenePropsBar.tsx +0 -85
  277. package/src/scene/SceneSelection.tsx +0 -111
  278. package/src/scene/SceneSideToolbar.tsx +0 -89
  279. package/src/scene/SceneViewControls.tsx +0 -43
  280. package/src/scene/SceneViewport.tsx +0 -106
  281. package/src/scene/ShapePalette.tsx +0 -196
  282. package/src/scene/__tests__/DiagramAdapter.test.ts +0 -142
  283. package/src/scene/__tests__/SceneBlockExtension.test.ts +0 -33
  284. package/src/scene/__tests__/bezierEdit.test.ts +0 -85
  285. package/src/scene/__tests__/blockLayers.test.ts +0 -57
  286. package/src/scene/__tests__/fitScale.test.ts +0 -19
  287. package/src/scene/__tests__/sceneIsolation.test.tsx +0 -119
  288. package/src/scene/__tests__/shapeLayers.test.ts +0 -106
  289. package/src/scene/__tests__/useSceneHitTest.test.ts +0 -90
  290. package/src/scene/__tests__/useScenePanZoom.test.ts +0 -130
  291. package/src/scene/adapters/DiagramAdapter.ts +0 -79
  292. package/src/scene/adapters/DrawingAdapter.ts +0 -420
  293. package/src/scene/adapters/LayoutAdapter.ts +0 -313
  294. package/src/scene/adapters/blockLayers.ts +0 -159
  295. package/src/scene/commands/SceneCommand.ts +0 -84
  296. package/src/scene/commands/drawingCommands.ts +0 -318
  297. package/src/scene/commands/layoutCommands.ts +0 -301
  298. package/src/scene/fitScale.ts +0 -17
  299. package/src/scene/hooks/useSceneHitTest.ts +0 -105
  300. package/src/scene/hooks/useScenePanZoom.ts +0 -154
  301. package/src/scene/hooks/useSceneSelection.ts +0 -62
  302. package/src/scene/index.ts +0 -90
  303. package/src/scene/layers/DiagramEdges.tsx +0 -142
  304. package/src/scene/layers/edgeGeometry.ts +0 -104
  305. package/src/scene/layers/nodeCard.tsx +0 -164
  306. package/src/scene/layers/renderLayer.tsx +0 -70
  307. package/src/scene/layers/shapeLayers.ts +0 -201
  308. package/src/scene/paths/bezierEdit.ts +0 -208
  309. package/src/scene/scene.css +0 -874
  310. package/src/scene/text/SceneTextOverlay.tsx +0 -161
  311. package/src/scene/text/sceneTextChannel.ts +0 -46
  312. package/src/scene/text/sceneTextConfig.ts +0 -31
  313. package/src/scene/text/sceneTiptap.ts +0 -36
  314. package/src/scene/text/useSceneTextEditing.ts +0 -39
  315. package/src/scene/tools/ConnectTool.ts +0 -209
  316. package/src/scene/tools/DrawingConnectTool.ts +0 -231
  317. package/src/scene/tools/PathTool.ts +0 -158
  318. package/src/scene/tools/PlaceTool.ts +0 -47
  319. package/src/scene/tools/SceneTool.ts +0 -85
  320. package/src/scene/tools/SelectTool.ts +0 -300
  321. package/src/scene/tools/ShapeTool.ts +0 -143
  322. package/src/scene/tools/TextTool.ts +0 -72
  323. package/src/scene/tools/TokenTool.ts +0 -95
  324. package/src/scene/tools/createDrawShapeTool.ts +0 -82
  325. package/src/selectionConversions.ts +0 -155
  326. package/src/styles/ascii-diagram.css +0 -79
  327. package/src/styles/ascii-timeline.css +0 -596
  328. package/src/styles/code-context.css +0 -155
  329. package/src/styles/code-snippet.css +0 -76
  330. package/src/styles/diagram.css +0 -183
  331. package/src/styles/editor.css +0 -7131
  332. package/src/styles/folder-view.css +0 -210
  333. package/src/styles/image-edit-affordance.css +0 -201
  334. package/src/styles/index.css +0 -20
  335. package/src/styles/mermaid-diagram.css +0 -487
  336. package/src/styles/tree-view.css +0 -189
  337. package/src/teleprompter/TeleprompterControls.tsx +0 -218
  338. package/src/teleprompter/TeleprompterSelfView.tsx +0 -22
  339. package/src/teleprompter/TeleprompterSurface.tsx +0 -267
  340. package/src/teleprompter/TeleprompterView.tsx +0 -338
  341. package/src/teleprompter/canvasRenderer.ts +0 -161
  342. package/src/teleprompter/floatingWindow.ts +0 -352
  343. package/src/teleprompter/index.ts +0 -61
  344. package/src/teleprompter/pcmWorklet.ts +0 -62
  345. package/src/teleprompter/recording/insertPreamble.ts +0 -80
  346. package/src/teleprompter/recording/narrationSave.ts +0 -134
  347. package/src/teleprompter/recording/useNarrationRecorder.ts +0 -367
  348. package/src/teleprompter/scrollModel.ts +0 -85
  349. package/src/teleprompter/teleprompterTheme.ts +0 -303
  350. package/src/teleprompter/types.ts +0 -38
  351. package/src/teleprompter/useFloatingWindow.ts +0 -74
  352. package/src/teleprompter/useMicAnalysis.ts +0 -211
  353. package/src/teleprompter/useTeleprompter.ts +0 -421
  354. package/src/templateContentPreviewResolver.ts +0 -360
  355. package/src/timeline/TimelineEditorWidget.tsx +0 -861
  356. package/src/timeline/TimelineViewExtension.ts +0 -252
  357. package/src/timeline/__tests__/TimelineEditorWidget.test.tsx +0 -414
  358. package/src/timeline/__tests__/TimelineViewExtension.test.ts +0 -163
  359. package/src/timeline/__tests__/timelineCommands.test.ts +0 -359
  360. package/src/timeline/__tests__/timelineOps.test.ts +0 -277
  361. package/src/timeline/__tests__/timelinePaste.test.ts +0 -34
  362. package/src/timeline/timelineCommands.ts +0 -421
  363. package/src/timeline/timelineData.ts +0 -54
  364. package/src/timeline/timelineOps.ts +0 -381
  365. package/src/timeline/timelinePaste.ts +0 -8
  366. package/src/timelineSource.ts +0 -244
  367. package/src/tiptap/TiptapAudio.tsx +0 -86
  368. package/src/tiptap/TiptapVideo.tsx +0 -119
  369. package/src/tiptap/useResolvedMediaSrc.ts +0 -47
  370. package/src/tiptapBridge.ts +0 -986
  371. package/src/tooltipPlacement.ts +0 -13
  372. package/src/transformStyleId.ts +0 -17
  373. package/src/transitionCatalog.ts +0 -159
  374. package/src/treeview/TreeOutlineWidget.tsx +0 -390
  375. package/src/treeview/TreeViewExtension.ts +0 -250
  376. package/src/treeview/__tests__/TreeOutlineWidget.test.tsx +0 -156
  377. package/src/treeview/__tests__/TreeViewExtension.test.ts +0 -122
  378. package/src/treeview/__tests__/treeOps.test.ts +0 -177
  379. package/src/treeview/__tests__/treePaste.test.ts +0 -40
  380. package/src/treeview/__tests__/treeViewCommands.test.ts +0 -179
  381. package/src/treeview/treeOps.ts +0 -231
  382. package/src/treeview/treePaste.ts +0 -13
  383. package/src/treeview/treeViewCommands.ts +0 -99
  384. package/src/treeview/treeViewData.ts +0 -41
  385. package/src/types/monaco-shims.d.ts +0 -10
  386. package/src/useBlockNavigator.ts +0 -153
  387. package/src/useHeadingLayout.ts +0 -294
  388. package/src/useMonacoLoader.ts +0 -82
  389. package/src/useTimelineClock.ts +0 -76
  390. package/src/utils/collectInlineFontAwesomeCss.ts +0 -69
  391. package/src/utils/dropUtils.ts +0 -136
  392. package/src/utils/normalizeMalformedAssetUrl.ts +0 -22
  393. package/src/writeCanvasSettings.ts +0 -30
  394. package/src/wysiwygImageUpload.ts +0 -113
@@ -1,986 +0,0 @@
1
- /**
2
- * Tiptap Bridge
3
- *
4
- * Conversion utilities between raw markdown source and Tiptap's JSON/HTML
5
- * content format. Uses a lightweight HTML-based approach: we convert markdown
6
- * to a simple HTML representation that Tiptap can consume, and parse
7
- * Tiptap's HTML output back to markdown.
8
- *
9
- * This bridge preserves markdown semantics much better than going through
10
- * Tiptap's native markdown extension, since we control the conversion
11
- * using squisq's own parser.
12
- */
13
-
14
- import { resolveIcon } from '@bendyline/squisq/icons';
15
- import {
16
- matchTrailingTemplateAnnotation,
17
- matchTrailingPandocAttr,
18
- tokenizeAttrTokens,
19
- } from '@bendyline/squisq/markdown';
20
-
21
- // Hoisted regex patterns for inline markdown ↔ HTML conversion
22
- const RE_BOLD_STAR = /\*\*(.+?)\*\*/g;
23
- const RE_BOLD_UNDER = /__(.+?)__/g;
24
- const RE_ITALIC_STAR = /\*(.+?)\*/g;
25
- const RE_ITALIC_UNDER = /_(.+?)_/g;
26
- const RE_STRIKETHROUGH = /~~(.+?)~~/g;
27
- const RE_INLINE_CODE = /`(.+?)`/g;
28
- const RE_LINK = /\[(.+?)\]\((.+?)\)/g;
29
- // `*?` on the alt — an empty alt (`![](foo.png)`) is valid markdown and
30
- // the most common shape for pasted/uploaded images that don't yet have
31
- // a human-picked caption. Previously required at least one alt char,
32
- // which dropped those images on the floor during markdown→HTML.
33
- const RE_IMAGE = /!\[(.*?)\]\((.+?)\)/g;
34
- // Mentions: `@[Display](scheme:id)` — scheme-part must start with a letter
35
- // so plain `$100` or price-style parentheticals don't accidentally match.
36
- // remark-stringify may round-trip the colon as `\:` — tolerate either.
37
- const RE_MENTION = /@\[([^\]]+?)\]\(([a-z][a-z0-9+.-]*)\\?:([^)\s]+)\)/gi;
38
- const RE_MENTION_TAG = /<span\b[^>]*?\bdata-mention\b[^>]*?>(?:<[^>]+>)*([^<]*)<\/span>/gi;
39
-
40
- // Inline FontAwesome icon. Markdown form: `{[github]}` (bare) or
41
- // `{[fa-solid:user]}` (qualified). HTML form (produced by the
42
- // `InlineIcon` Tiptap node and consumed back by `htmlToInline`):
43
- // `<i data-icon="github" data-family="brands" data-name="github"
44
- // class="fa-brands fa-github" contenteditable="false"></i>`.
45
- const RE_ICON_MD = /\{\[([a-zA-Z0-9_:-]+)\]\}/g;
46
- const RE_ICON_TAG = /<i\b[^>]*?\bdata-icon="([^"]*)"[^>]*?><\/i>/gi;
47
- const RE_STRONG_TAG = /<strong>(.*?)<\/strong>/g;
48
- const RE_B_TAG = /<b>(.*?)<\/b>/g;
49
- const RE_EM_TAG = /<em>(.*?)<\/em>/g;
50
- const RE_I_TAG = /<i>(.*?)<\/i>/g;
51
- const RE_S_TAG = /<s>(.*?)<\/s>/g;
52
- const RE_DEL_TAG = /<del>(.*?)<\/del>/g;
53
- const RE_CODE_TAG = /<code>(.*?)<\/code>/g;
54
- const RE_A_TAG = /<a[^>]+href="([^"]*)"[^>]*>(.*?)<\/a>/g;
55
- // Matches any `<img>` tag and captures its `src` + `alt` regardless of
56
- // attribute order. TipTap's Image extension renders `<img src="..."
57
- // alt="...">` (src first), while some other producers — including our
58
- // own `markdownToTiptap` conversion — emit alt-first. The previous
59
- // regex required alt-before-src and silently dropped every src-first
60
- // image; `RE_STRIP_TAGS` below would then delete the unmatched tag,
61
- // so the outgoing markdown had no image reference at all.
62
- const RE_IMG_TAG = /<img\b([^>]*)>/g;
63
- const RE_STRIP_TAGS = /<[^>]+>/g;
64
-
65
- /**
66
- * Convert raw markdown source to Tiptap-consumable HTML content.
67
- * Uses a simple markdown-to-HTML conversion that maps cleanly to
68
- * Tiptap's ProseMirror schema.
69
- */
70
- export function markdownToTiptap(markdown: string): string {
71
- if (!markdown.trim()) return '<p></p>';
72
-
73
- // Normalize line endings — content from zip archives may use \r\n
74
- const html = markdown.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
75
-
76
- // Process blocks line by line for accurate conversion
77
- const lines = html.split('\n');
78
- const outputBlocks: string[] = [];
79
- let inCodeBlock = false;
80
- let codeBlockLang = '';
81
- let codeBlockLines: string[] = [];
82
- let inList = false;
83
- let listItems: string[] = [];
84
- let listType: 'ul' | 'ol' | 'task' = 'ul';
85
- let inTable = false;
86
- let tableLines: string[] = [];
87
- let pendingBlankLines = 0;
88
-
89
- const flushPendingBlankParagraphs = () => {
90
- if (pendingBlankLines === 0) return;
91
- const emptyParagraphs =
92
- outputBlocks.length === 0 ? pendingBlankLines : Math.max(0, pendingBlankLines - 1);
93
- for (let i = 0; i < emptyParagraphs; i++) {
94
- outputBlocks.push('<p></p>');
95
- }
96
- pendingBlankLines = 0;
97
- };
98
-
99
- const pushBlock = (block: string) => {
100
- flushPendingBlankParagraphs();
101
- outputBlocks.push(block);
102
- };
103
-
104
- const flushList = () => {
105
- if (inList && listItems.length > 0) {
106
- const tag = listType === 'ol' ? 'ol' : 'ul';
107
- const attr = listType === 'task' ? ' data-type="taskList"' : '';
108
- pushBlock(`<${tag}${attr}>${listItems.join('')}</${tag}>`);
109
- listItems = [];
110
- inList = false;
111
- }
112
- };
113
-
114
- const flushTable = () => {
115
- if (!inTable || tableLines.length === 0) {
116
- inTable = false;
117
- tableLines = [];
118
- return;
119
- }
120
-
121
- // Validate: need at least 2 lines and second must be a separator
122
- const separatorCells = tableLines.length >= 2 ? parseTableCells(tableLines[1]) : [];
123
- const isSeparator =
124
- separatorCells.length > 0 && separatorCells.every((cell) => /^:?-+:?$/.test(cell.trim()));
125
-
126
- if (tableLines.length < 2 || !isSeparator) {
127
- // Not a valid table — render accumulated lines as paragraphs
128
- for (const tl of tableLines) {
129
- pushBlock(`<p>${inlineToHtml(tl)}</p>`);
130
- }
131
- inTable = false;
132
- tableLines = [];
133
- return;
134
- }
135
-
136
- const alignments = parseAlignments(tableLines[1]);
137
- const headerCells = parseTableCells(tableLines[0]);
138
-
139
- // Build header row
140
- const thHtml = headerCells
141
- .map((cell, i) => {
142
- const align = alignments[i];
143
- const style = align ? ` style="text-align: ${align}"` : '';
144
- return `<th${style}>${inlineToHtml(cell)}</th>`;
145
- })
146
- .join('');
147
-
148
- // Build body rows
149
- const bodyHtml = tableLines
150
- .slice(2)
151
- .map((rowLine) => {
152
- const cells = parseTableCells(rowLine);
153
- const tdHtml = cells
154
- .map((cell, i) => {
155
- const align = alignments[i];
156
- const style = align ? ` style="text-align: ${align}"` : '';
157
- return `<td${style}>${inlineToHtml(cell)}</td>`;
158
- })
159
- .join('');
160
- return `<tr>${tdHtml}</tr>`;
161
- })
162
- .join('');
163
-
164
- pushBlock(`<table><thead><tr>${thHtml}</tr></thead><tbody>${bodyHtml}</tbody></table>`);
165
-
166
- inTable = false;
167
- tableLines = [];
168
- };
169
-
170
- for (let i = 0; i < lines.length; i++) {
171
- const line = lines[i];
172
-
173
- // Code fence handling
174
- if (line.startsWith('```')) {
175
- if (!inCodeBlock) {
176
- flushList();
177
- flushPendingBlankParagraphs();
178
- inCodeBlock = true;
179
- codeBlockLang = line.slice(3).trim();
180
- codeBlockLines = [];
181
- continue;
182
- } else {
183
- const langAttr = codeBlockLang ? ` class="language-${escapeHtml(codeBlockLang)}"` : '';
184
- pushBlock(`<pre><code${langAttr}>${escapeHtml(codeBlockLines.join('\n'))}</code></pre>`);
185
- inCodeBlock = false;
186
- codeBlockLang = '';
187
- codeBlockLines = [];
188
- continue;
189
- }
190
- }
191
-
192
- if (inCodeBlock) {
193
- codeBlockLines.push(line);
194
- continue;
195
- }
196
-
197
- // If in table and current line is not a table row, flush
198
- if (inTable && !/^\|.*\|$/.test(line.trim())) {
199
- flushTable();
200
- }
201
-
202
- // Blank line flushes list
203
- if (line.trim() === '') {
204
- flushList();
205
- pendingBlankLines++;
206
- continue;
207
- }
208
-
209
- flushPendingBlankParagraphs();
210
-
211
- // Headings
212
- const headingMatch = line.match(/^(#{1,6})\s+(.+)$/);
213
- if (headingMatch) {
214
- flushList();
215
- const level = headingMatch[1].length;
216
- let text = headingMatch[2];
217
- let attrs = '';
218
-
219
- // Peel off trailing brace-blocks in any order: the squisq-native
220
- // `{[template …]}` annotation and the Pandoc `{#id .class key=value}`
221
- // attribute block may both appear at the end of the heading line.
222
- // Loop until neither matches. The matchers are imported from core so
223
- // this stays in sync with packages/core/src/markdown/convert.ts.
224
- let templateInner: string | null = null;
225
- let pandocInner: string | null = null;
226
- for (let pass = 0; pass < 4; pass++) {
227
- let matched = false;
228
- if (templateInner == null) {
229
- const m = matchTrailingTemplateAnnotation(text);
230
- if (m) {
231
- templateInner = m.inner.trim();
232
- text = text.slice(0, m.index).trimEnd();
233
- matched = true;
234
- }
235
- }
236
- if (pandocInner == null) {
237
- const m = matchTrailingPandocAttr(text);
238
- if (m) {
239
- pandocInner = m.inner.trim();
240
- text = text.slice(0, m.index).trimEnd();
241
- matched = true;
242
- }
243
- }
244
- if (!matched) break;
245
- }
246
-
247
- if (templateInner != null) {
248
- // Quote-aware tokenization (shared with the core parser) keeps a
249
- // quoted value like caption="Beach at sunset" as one token. The
250
- // tokens are stored raw — quotes included — so tiptapToMarkdown
251
- // can re-join them into the annotation verbatim.
252
- const tokens = tokenizeAttrTokens(templateInner);
253
- if (tokens.length === 0) {
254
- // Preserve an authored `{[]}` through the editable Tiptap document
255
- // while keeping the raw marker out of the visible heading text.
256
- attrs += ' data-template-empty="true"';
257
- }
258
- const firstIsParam = tokens.length > 0 && tokens[0].indexOf('=') > 0;
259
- if (!firstIsParam && tokens[0]) {
260
- attrs += ` data-template="${escapeHtml(tokens[0])}"`;
261
- }
262
- const params = tokens.slice(firstIsParam ? 0 : 1).filter((t) => t.includes('='));
263
- if (params.length > 0) {
264
- attrs += ` data-template-params="${escapeHtml(params.join(' '))}"`;
265
- }
266
- }
267
- if (pandocInner != null) {
268
- attrs += ` data-block-attrs="${escapeHtml(pandocInner)}"`;
269
- }
270
-
271
- pushBlock(`<h${level}${attrs}>${inlineToHtml(text)}</h${level}>`);
272
- continue;
273
- }
274
-
275
- // Thematic break
276
- if (/^(---|\*\*\*|___)(\s*)$/.test(line.trim())) {
277
- flushList();
278
- pushBlock('<hr>');
279
- continue;
280
- }
281
-
282
- // Blockquote
283
- if (line.startsWith('> ')) {
284
- flushList();
285
- const quoteLines = [line.slice(2)];
286
- while (i + 1 < lines.length && lines[i + 1].startsWith('> ')) {
287
- i++;
288
- quoteLines.push(lines[i].slice(2));
289
- }
290
- pushBlock(
291
- `<blockquote>${quoteLines.map((quoteLine) => `<p>${inlineToHtml(quoteLine)}</p>`).join('')}</blockquote>`,
292
- );
293
- continue;
294
- }
295
-
296
- // Task list item. Text is optional so freshly-typed, still-empty tasks
297
- // survive a round-trip. The checkbox itself is drawn by TaskItem's node
298
- // view from the data-checked attribute, so we only emit the text content
299
- // (in a paragraph, matching Tiptap's own node structure).
300
- const taskMatch = line.match(/^[-*+]\s+\[([xX ])\]\s*(.*)$/);
301
- if (taskMatch) {
302
- if (!inList || listType !== 'task') {
303
- flushList();
304
- inList = true;
305
- listType = 'task';
306
- }
307
- const checkedAttr = taskMatch[1].toLowerCase() === 'x' ? ' data-checked="true"' : '';
308
- listItems.push(
309
- `<li data-type="taskItem"${checkedAttr}><p>${inlineToHtml(taskMatch[2])}</p></li>`,
310
- );
311
- continue;
312
- }
313
-
314
- // Unordered list item
315
- const ulMatch = line.match(/^[-*+]\s+(.+)$/);
316
- if (ulMatch) {
317
- if (!inList || listType !== 'ul') {
318
- flushList();
319
- inList = true;
320
- listType = 'ul';
321
- }
322
- listItems.push(`<li><p>${inlineToHtml(ulMatch[1])}</p></li>`);
323
- continue;
324
- }
325
-
326
- // Ordered list item
327
- const olMatch = line.match(/^\d+\.\s+(.+)$/);
328
- if (olMatch) {
329
- if (!inList || listType !== 'ol') {
330
- flushList();
331
- inList = true;
332
- listType = 'ol';
333
- }
334
- listItems.push(`<li><p>${inlineToHtml(olMatch[1])}</p></li>`);
335
- continue;
336
- }
337
-
338
- // Table row
339
- if (/^\|.*\|$/.test(line.trim())) {
340
- if (!inTable) {
341
- flushList();
342
- inTable = true;
343
- tableLines = [];
344
- }
345
- tableLines.push(line);
346
- continue;
347
- }
348
-
349
- // Standalone image — emit as a top-level block `<img>` instead of
350
- // wrapping in `<p>`. The Tiptap Image extension is configured with
351
- // `inline: false`, so `<p><img></p>` parses to an empty paragraph
352
- // (the block image can't live inside the paragraph). That bug
353
- // manifested as a broken-image glyph after a markdown → WYSIWYG
354
- // round-trip for any dropped/pasted image.
355
- const standaloneImageMatch = line.trim().match(/^!\[(.*?)\]\((.+?)\)$/);
356
- if (standaloneImageMatch) {
357
- flushList();
358
- const alt = escapeHtml(standaloneImageMatch[1] ?? '');
359
- const src = escapeHtml(standaloneImageMatch[2] ?? '');
360
- pushBlock(`<img alt="${alt}" src="${src}">`);
361
- continue;
362
- }
363
-
364
- // Standalone raw HTML `<img>` line — emitted by `tiptapToMarkdown`
365
- // when the user has resized an image (width/height attrs are
366
- // serialized as HTML rather than markdown shorthand so the
367
- // dimensions survive round-trip). Pass the tag through unchanged
368
- // so Tiptap's Image extension parses width/height attributes.
369
- const trimmed = line.trim();
370
- if (/^<img\b[^>]*>$/i.test(trimmed)) {
371
- flushList();
372
- pushBlock(trimmed);
373
- continue;
374
- }
375
-
376
- // Standalone `<video>` / `<audio>` line — emitted by the recorder
377
- // (RecorderEntry) when it saves a clip, and by `tiptapToMarkdown`
378
- // when the WYSIWYG editor's TiptapVideo/TiptapAudio nodes serialize
379
- // back to markdown. Pass through unchanged so the editor's parseHTML
380
- // picks up the tag attributes (`src`, `controls`, …).
381
- if (/^<(?:video|audio)\b[^>]*>(?:[\s\S]*?<\/(?:video|audio)>)?$/i.test(trimmed)) {
382
- flushList();
383
- pushBlock(trimmed);
384
- continue;
385
- }
386
-
387
- // Regular paragraph
388
- flushList();
389
- pushBlock(`<p>${inlineToHtml(line)}</p>`);
390
- }
391
-
392
- // Close any remaining open blocks
393
- if (inCodeBlock) {
394
- const langAttr = codeBlockLang ? ` class="language-${escapeHtml(codeBlockLang)}"` : '';
395
- pushBlock(`<pre><code${langAttr}>${escapeHtml(codeBlockLines.join('\n'))}</code></pre>`);
396
- }
397
- flushList();
398
- flushTable();
399
- flushPendingBlankParagraphs();
400
-
401
- return outputBlocks.join('') || '<p></p>';
402
- }
403
-
404
- /**
405
- * Convert Tiptap HTML output back to markdown source.
406
- * Extracts semantic structure from HTML and produces clean markdown.
407
- */
408
- export function tiptapToMarkdown(html: string): string {
409
- if (!html || html === '<p></p>') return '';
410
-
411
- const lines: string[] = [];
412
-
413
- // Simple regex-based HTML to markdown conversion
414
- // This works because Tiptap produces clean, predictable HTML
415
- let remaining = html;
416
-
417
- while (remaining.length > 0) {
418
- // Headings
419
- const headingMatch = remaining.match(/^<h([1-6])([^>]*)>(.*?)<\/h\1>/s);
420
- if (headingMatch) {
421
- const level = parseInt(headingMatch[1], 10);
422
- const attrs = headingMatch[2];
423
- const headingHtml = headingMatch[3];
424
- // Template/property badges are editor chrome, not heading content. Strip
425
- // them structurally before converting the inline HTML. Older builds
426
- // briefly rendered the template label as real badge text; using the
427
- // markup boundary preserves that cleanup without mistaking a legitimate
428
- // heading suffix (for example "A Famous Quote") for the badge label.
429
- const chromeStart = headingHtml.search(
430
- /<span\b[^>]*\bclass="[^"]*\bsquisq-(?:template|props)-badge\b[^"]*"[^>]*>/i,
431
- );
432
- let text = htmlToInline(chromeStart >= 0 ? headingHtml.slice(0, chromeStart) : headingHtml);
433
-
434
- // Re-inject heading annotations from data attributes. Canonical
435
- // emit order: Pandoc `{#…}` first, then squisq `{[…]}` annotation
436
- // (matches blockToMdast in core/markdown/convert.ts).
437
- const blockAttrsMatch = attrs.match(/data-block-attrs="([^"]*)"/);
438
- const tmplMatch = attrs.match(/data-template="([^"]+)"/);
439
- const paramsMatch = attrs.match(/data-template-params="([^"]+)"/);
440
- const hasEmptyTemplateAnnotation = /\sdata-template-empty(?:="[^"]*")?/.test(attrs);
441
- if (blockAttrsMatch) {
442
- const inner = unescapeHtml(blockAttrsMatch[1]);
443
- text += ` {${inner}}`;
444
- }
445
- if (tmplMatch || paramsMatch) {
446
- let annotation = tmplMatch ? tmplMatch[1] : '';
447
- if (paramsMatch) {
448
- annotation += (annotation ? ' ' : '') + unescapeHtml(paramsMatch[1]);
449
- }
450
- text += ` {[${annotation}]}`;
451
- } else if (hasEmptyTemplateAnnotation) {
452
- text += ' {[]}';
453
- }
454
-
455
- lines.push('#'.repeat(level) + ' ' + text);
456
- lines.push('');
457
- remaining = remaining.slice(headingMatch[0].length);
458
- continue;
459
- }
460
-
461
- // Code blocks — tolerate attributes on <pre> and <code>: real
462
- // editor.getHTML() output carries class="squisq-code-block" on the
463
- // <pre> (StarterKit codeBlock HTMLAttributes), which a bare
464
- // `<pre><code` anchor never matches, silently dropping the fence.
465
- const codeMatch = remaining.match(/^<pre\b[^>]*><code\b([^>]*)>(.*?)<\/code><\/pre>/s);
466
- if (codeMatch) {
467
- const lang = /\bclass="language-([^"]*)"/.exec(codeMatch[1] ?? '')?.[1] ?? '';
468
- const code = unescapeHtml(codeMatch[2]);
469
- lines.push('```' + lang);
470
- lines.push(code);
471
- lines.push('```');
472
- lines.push('');
473
- remaining = remaining.slice(codeMatch[0].length);
474
- continue;
475
- }
476
-
477
- // Blockquote
478
- const bqMatch = remaining.match(/^<blockquote>(.*?)<\/blockquote>/s);
479
- if (bqMatch) {
480
- const paragraphs = bqMatch[1]
481
- .split(/<\/p>\s*<p[^>]*>/i)
482
- .map((paragraph) => paragraph.replace(/^<p[^>]*>/i, '').replace(/<\/p>\s*$/i, ''));
483
- for (const paragraph of paragraphs) {
484
- for (const quoteLine of htmlToInline(paragraph).split('\n')) {
485
- lines.push('> ' + quoteLine);
486
- }
487
- }
488
- const next = remaining.slice(bqMatch[0].length);
489
- // Older bridge output and direct Tiptap edits can still leave adjacent
490
- // blockquote nodes. Keep those nodes adjacent when serializing;
491
- // inserting the normal block separator here turns one quote into two
492
- // paragraphs every time the document passes through WYSIWYG mode.
493
- if (!/^\s*<blockquote>/.test(next)) lines.push('');
494
- remaining = next;
495
- continue;
496
- }
497
-
498
- // Horizontal rule
499
- if (
500
- remaining.startsWith('<hr>') ||
501
- remaining.startsWith('<hr/>') ||
502
- remaining.startsWith('<hr />')
503
- ) {
504
- const hrMatch = remaining.match(/^<hr\s*\/?>/);
505
- lines.push('---');
506
- lines.push('');
507
- remaining = remaining.slice(hrMatch![0].length);
508
- continue;
509
- }
510
-
511
- // Table (with optional Tiptap tableWrapper div; table tag may have style attrs)
512
- const tableMatch =
513
- remaining.match(
514
- /^<div[^>]*class="[^"]*tableWrapper[^"]*"[^>]*><table[^>]*>(.*?)<\/table>\s*<\/div>/s,
515
- ) || remaining.match(/^<table[^>]*>(.*?)<\/table>/s);
516
- if (tableMatch) {
517
- const tableContent = tableMatch[1];
518
-
519
- // Extract all rows with their cells
520
- const rows: { content: string; align: string | null; isHeader: boolean }[][] = [];
521
- const rowRegex = /<tr[^>]*>(.*?)<\/tr>/gs;
522
- let rowExec;
523
- while ((rowExec = rowRegex.exec(tableContent)) !== null) {
524
- const rowHtml = rowExec[1];
525
- const cells: { content: string; align: string | null; isHeader: boolean }[] = [];
526
- const cellRegex = /<(th|td)([^>]*)>(.*?)<\/\1>/gs;
527
- let cellExec;
528
- while ((cellExec = cellRegex.exec(rowHtml)) !== null) {
529
- const tag = cellExec[1];
530
- const attrs = cellExec[2];
531
- const content = htmlToInline(cellExec[3].replace(/<\/?p>/g, ''));
532
- const alignExec = attrs.match(/text-align:\s*(left|center|right)/);
533
- cells.push({
534
- content,
535
- align: alignExec ? alignExec[1] : null,
536
- isHeader: tag === 'th',
537
- });
538
- }
539
- if (cells.length > 0) {
540
- rows.push(cells);
541
- }
542
- }
543
-
544
- if (rows.length > 0) {
545
- // Header row = first row with th cells, or just the first row
546
- const headerIdx = rows.findIndex((r) => r.some((c) => c.isHeader));
547
- const hIdx = headerIdx >= 0 ? headerIdx : 0;
548
- const headerRow = rows[hIdx];
549
- const dataRows = rows.filter((_, i) => i !== hIdx);
550
-
551
- const aligns = headerRow.map((c) => c.align);
552
- lines.push('| ' + headerRow.map((c) => c.content || ' ').join(' | ') + ' |');
553
- lines.push(
554
- '| ' +
555
- aligns
556
- .map((a) => {
557
- if (a === 'center') return ':---:';
558
- if (a === 'right') return '---:';
559
- return '---';
560
- })
561
- .join(' | ') +
562
- ' |',
563
- );
564
- for (const row of dataRows) {
565
- lines.push('| ' + row.map((c) => c.content || ' ').join(' | ') + ' |');
566
- }
567
- lines.push('');
568
- }
569
-
570
- remaining = remaining.slice(tableMatch[0].length);
571
- continue;
572
- }
573
-
574
- // Task list
575
- const taskListMatch = remaining.match(/^<ul[^>]*data-type="taskList"[^>]*>(.*?)<\/ul>/s);
576
- if (taskListMatch) {
577
- const items = taskListMatch[1].matchAll(/<li[^>]*data-type="taskItem"[^>]*>.*?<\/li>/gs);
578
- for (const item of items) {
579
- // Read checked state from the attribute value only — a bare
580
- // includes('checked') matches the substring in data-checked="false".
581
- const checked = /data-checked="true"/.test(item[0]);
582
- // Drop the checkbox chrome (<label>…</label>) before reading text;
583
- // Tiptap puts the task text in the trailing content node, not the label.
584
- const body = item[0].replace(/<label\b[^>]*>.*?<\/label>/s, '');
585
- const text = htmlToInline(body.replace(/<[^>]+>/g, '').trim());
586
- lines.push(`- [${checked ? 'x' : ' '}] ${text}`.trimEnd());
587
- }
588
- lines.push('');
589
- remaining = remaining.slice(taskListMatch[0].length);
590
- continue;
591
- }
592
-
593
- // Unordered list
594
- const ulMatch = remaining.match(/^<ul>(.*?)<\/ul>/s);
595
- if (ulMatch) {
596
- const items = ulMatch[1].matchAll(/<li>(.*?)<\/li>/gs);
597
- for (const item of items) {
598
- lines.push(...renderListItem('- ', item[1]));
599
- }
600
- lines.push('');
601
- remaining = remaining.slice(ulMatch[0].length);
602
- continue;
603
- }
604
-
605
- // Ordered list
606
- const olMatch = remaining.match(/^<ol[^>]*>(.*?)<\/ol>/s);
607
- if (olMatch) {
608
- const items = [...olMatch[1].matchAll(/<li>(.*?)<\/li>/gs)];
609
- items.forEach((item, idx) => {
610
- lines.push(...renderListItem(`${idx + 1}. `, item[1]));
611
- });
612
- lines.push('');
613
- remaining = remaining.slice(olMatch[0].length);
614
- continue;
615
- }
616
-
617
- // Paragraph
618
- const pMatch = remaining.match(/^<p>(.*?)<\/p>/s);
619
- if (pMatch) {
620
- const text = htmlToInline(pMatch[1]);
621
- if (text.trim()) {
622
- lines.push(text);
623
- lines.push('');
624
- } else {
625
- lines.push('');
626
- }
627
- remaining = remaining.slice(pMatch[0].length);
628
- continue;
629
- }
630
-
631
- // Block-level image. TipTap's Image extension with `inline: false`
632
- // emits `<img src alt>` as a bare top-level element (no wrapping
633
- // `<p>`). Without this handler the skip-unknown-tags catch-all
634
- // below silently drops the image from the outgoing markdown —
635
- // the bug that made the chat composer ship image-less messages
636
- // even though the editor showed the picture. Handled here,
637
- // before the inline walker ever sees it.
638
- const imgMatch = remaining.match(/^<img\b([^>]*)>/);
639
- if (imgMatch) {
640
- const attrs = imgMatch[1] ?? '';
641
- const src = /\bsrc="([^"]*)"/i.exec(attrs)?.[1];
642
- if (src) {
643
- const alt = /\balt="([^"]*)"/i.exec(attrs)?.[1] ?? '';
644
- lines.push(serializeImage(src, alt, attrs));
645
- lines.push('');
646
- }
647
- remaining = remaining.slice(imgMatch[0].length);
648
- continue;
649
- }
650
-
651
- // Block-level `<video>` / `<audio>` — emitted by our TiptapVideo /
652
- // TiptapAudio atom nodes (block group). Serialize the whole tag
653
- // (opening + closing) back to markdown unchanged; CommonMark allows
654
- // inline HTML, and our renderer plus the InlinePreviewGutter both
655
- // know how to parse the htmlElement back out.
656
- const mediaMatch = remaining.match(/^<(video|audio)\b([^>]*)>(?:[\s\S]*?<\/\1>)?/);
657
- if (mediaMatch) {
658
- const tag = mediaMatch[1] === 'video' ? 'video' : 'audio';
659
- lines.push(serializeMediaTag(tag, mediaMatch[2] ?? ''));
660
- lines.push('');
661
- remaining = remaining.slice(mediaMatch[0].length);
662
- continue;
663
- }
664
-
665
- // Skip unknown tags or whitespace
666
- const skipMatch = remaining.match(/^(<[^>]+>|\s+)/);
667
- if (skipMatch) {
668
- remaining = remaining.slice(skipMatch[0].length);
669
- continue;
670
- }
671
-
672
- // Plain text (shouldn't happen in well-formed Tiptap output)
673
- const textMatch = remaining.match(/^([^<]+)/);
674
- if (textMatch) {
675
- lines.push(unescapeHtml(textMatch[1]));
676
- remaining = remaining.slice(textMatch[0].length);
677
- continue;
678
- }
679
-
680
- // Safety: skip one character to avoid infinite loop
681
- remaining = remaining.slice(1);
682
- }
683
-
684
- return lines.join('\n');
685
- }
686
-
687
- /**
688
- * Render a list item's HTML content as one or more markdown lines.
689
- * Handles `<p>` paragraph breaks (blank line) and `<br>` hard breaks
690
- * (two trailing spaces). Continuation lines are indented to keep them
691
- * inside the list item.
692
- */
693
- function renderListItem(prefix: string, html: string): string[] {
694
- const indent = ' '.repeat(prefix.length);
695
-
696
- // Pull out any block-level media nested in the item (e.g. a recording
697
- // dropped onto a list bullet, or a clip dragged into one). The inline
698
- // paragraph walk below ignores `<video>` / `<audio>` tags, so without
699
- // this they'd be silently dropped on serialize and lost from the
700
- // markdown source. We collect them and re-emit each as an indented
701
- // continuation line so they stay inside the list item and round-trip
702
- // through the markdown parser's block-media handler.
703
- const media: string[] = [];
704
- const htmlWithoutMedia = html.replace(
705
- /<(video|audio)\b([^>]*)>(?:[\s\S]*?<\/\1>)?/gi,
706
- (_full, tag: string, attrs: string) => {
707
- media.push(serializeMediaTag(tag.toLowerCase() === 'video' ? 'video' : 'audio', attrs ?? ''));
708
- return '';
709
- },
710
- );
711
-
712
- // Split on </p><p> to detect paragraph breaks within the item
713
- const paragraphs = htmlWithoutMedia
714
- .split(/<\/p>\s*<p[^>]*>/i)
715
- .map((p) => p.replace(/^<p[^>]*>/i, '').replace(/<\/p>\s*$/i, ''));
716
-
717
- const textLines: string[] = [];
718
- paragraphs.forEach((paragraph, pIdx) => {
719
- const inline = htmlToInline(paragraph).trim();
720
- if (!inline) return;
721
-
722
- // Each <br> already became " \n" in htmlToInline; split on it now.
723
- const subLines = inline.split('\n');
724
- subLines.forEach((sub, sIdx) => {
725
- if (pIdx === 0 && sIdx === 0) {
726
- textLines.push(prefix + sub);
727
- } else {
728
- // Blank line separator between paragraphs (sIdx === 0 means new paragraph)
729
- if (sIdx === 0) textLines.push('');
730
- textLines.push(indent + sub);
731
- }
732
- });
733
- });
734
-
735
- if (textLines.length === 0 && media.length === 0) return [prefix];
736
-
737
- // Text first (its first line carries the bullet marker), then each media
738
- // tag as its own indented continuation block. If the item is media-only,
739
- // the first tag takes the bullet so the item isn't emitted empty.
740
- const result: string[] = [];
741
- if (textLines.length > 0) {
742
- result.push(...textLines);
743
- for (const tag of media) {
744
- result.push('');
745
- result.push(indent + tag);
746
- }
747
- } else {
748
- result.push(prefix + media[0]);
749
- for (const tag of media.slice(1)) {
750
- result.push('');
751
- result.push(indent + tag);
752
- }
753
- }
754
- return result;
755
- }
756
-
757
- // ─── Table helpers ───────────────────────────────────────
758
-
759
- /** Split a GFM table row into trimmed cell strings (strips outer pipes). */
760
- function parseTableCells(line: string): string[] {
761
- let inner = line.trim();
762
- if (inner.startsWith('|')) inner = inner.slice(1);
763
- if (inner.endsWith('|')) inner = inner.slice(0, -1);
764
- return inner.split('|').map((cell) => cell.trim());
765
- }
766
-
767
- /** Parse a GFM separator line into column alignments. */
768
- function parseAlignments(separatorLine: string): (string | null)[] {
769
- return parseTableCells(separatorLine).map((cell) => {
770
- const s = cell.replace(/\s/g, '');
771
- if (s.startsWith(':') && s.endsWith(':')) return 'center';
772
- if (s.endsWith(':')) return 'right';
773
- if (s.startsWith(':')) return 'left';
774
- return null;
775
- });
776
- }
777
-
778
- // ─── Helpers ─────────────────────────────────────────────
779
-
780
- /**
781
- * Serialize a parsed `<img>` tag back to markdown. When the tag carries
782
- * an explicit `width` and/or `height` we emit a raw HTML `<img>` (the
783
- * markdown shorthand `![alt](src)` has no syntax for dimensions);
784
- * otherwise the friendlier shorthand is used. Markdown allows inline
785
- * HTML, so the HTML form parses and renders identically in any
786
- * CommonMark/GFM viewer.
787
- */
788
- /**
789
- * Serialize a `<video>` or `<audio>` tag (from the Tiptap atom node's
790
- * `renderHTML`) back to markdown. We re-emit only the attributes the
791
- * recorder + the renderer care about, in a stable order, so the
792
- * round-tripped markdown stays deterministic regardless of how Tiptap
793
- * decided to order them on its output.
794
- */
795
- function serializeMediaTag(tag: 'video' | 'audio', attrs: string): string {
796
- const src = /\bsrc="([^"]*)"/i.exec(attrs)?.[1] ?? '';
797
- const controls = /\bcontrols\b/i.test(attrs);
798
- const width = /\bwidth="([^"]*)"/i.exec(attrs)?.[1];
799
- const height = /\bheight="([^"]*)"/i.exec(attrs)?.[1];
800
- const poster = tag === 'video' ? /\bposter="([^"]*)"/i.exec(attrs)?.[1] : undefined;
801
- const parts = [`<${tag} src="${src}"`];
802
- if (controls) parts.push(' controls');
803
- if (width) parts.push(` width="${width}"`);
804
- if (height) parts.push(` height="${height}"`);
805
- if (poster) parts.push(` poster="${poster}"`);
806
- parts.push(`></${tag}>`);
807
- return parts.join('');
808
- }
809
-
810
- function serializeImage(src: string, alt: string, attrs: string): string {
811
- const width = /\bwidth="([^"]*)"/i.exec(attrs)?.[1];
812
- const height = /\bheight="([^"]*)"/i.exec(attrs)?.[1];
813
- const title = /\btitle="([^"]*)"/i.exec(attrs)?.[1];
814
- if (!width && !height) {
815
- return `![${alt}](${src})`;
816
- }
817
- const parts = [`<img alt="${alt}" src="${src}"`];
818
- if (width) parts.push(` width="${width}"`);
819
- if (height) parts.push(` height="${height}"`);
820
- if (title) parts.push(` title="${title}"`);
821
- parts.push('>');
822
- return parts.join('');
823
- }
824
-
825
- function escapeHtml(text: string): string {
826
- return text
827
- .replace(/&/g, '&amp;')
828
- .replace(/</g, '&lt;')
829
- .replace(/>/g, '&gt;')
830
- .replace(/"/g, '&quot;');
831
- }
832
-
833
- function unescapeHtml(text: string): string {
834
- return text
835
- .replace(/&lt;/g, '<')
836
- .replace(/&gt;/g, '>')
837
- .replace(/&quot;/g, '"')
838
- .replace(/&nbsp;|&#160;|&#xA0;/gi, '\u00a0')
839
- .replace(/&amp;/g, '&');
840
- }
841
-
842
- /** Convert inline markdown to HTML for Tiptap consumption */
843
- function inlineToHtml(text: string): string {
844
- // Extract images/mentions/links to opaque placeholders BEFORE running
845
- // any inline-formatting regexes. Otherwise `_` characters inside a URL
846
- // (e.g. `mikehome_files/IMG_6829.JPEG`) get turned into `<em>` tags by
847
- // the underscore-italic rule, mangling the src so the image renders
848
- // broken after a markdown ↔ WYSIWYG round-trip.
849
- const placeholders: string[] = [];
850
- const stash = (html: string): string => {
851
- const token = `\u0000PH${placeholders.length}\u0000`;
852
- placeholders.push(html);
853
- return token;
854
- };
855
-
856
- // We run extraction on the RAW text (before escapeHtml) so the
857
- // captured groups are the literal markdown contents; then we
858
- // selectively escape the parts of each placeholder that need it.
859
-
860
- // Images first: ![alt](src) — must be before links so the `!` prefix is consumed
861
- let staged = text.replace(RE_IMAGE, (_m, alt, src) =>
862
- stash(`<img alt="${escapeHtml(alt)}" src="${escapeHtml(src)}">`),
863
- );
864
-
865
- // Mentions: @[Display](scheme:id) — must run before links so the
866
- // bracket+paren isn't consumed as a regular link.
867
- staged = staged.replace(RE_MENTION, (_m, label, kind, id) =>
868
- stash(
869
- `<span data-mention="true" data-kind="${escapeHtml(kind)}" data-id="${escapeHtml(id)}" data-label="${escapeHtml(label)}" class="mention">@${escapeHtml(label)}</span>`,
870
- ),
871
- );
872
-
873
- // FontAwesome inline icons: {[github]} / {[fa-solid:user]} — resolve
874
- // against the FA catalog so unknown / ambiguous tokens stay as
875
- // literal text (preserved through escapeHtml later). Stashing here
876
- // alongside images/mentions keeps the `_` and other punctuation in
877
- // the class attribute from being mangled by the underscore-italic
878
- // regex below.
879
- staged = staged.replace(RE_ICON_MD, (full, token) => {
880
- const icon = resolveIcon(token);
881
- if (!icon) return full; // leave literal text — author may have meant it
882
- return stash(
883
- `<i class="fa-${icon.family} fa-${icon.name}" data-icon="${escapeHtml(token)}" data-family="${icon.family}" data-name="${icon.name}" contenteditable="false"></i>`,
884
- );
885
- });
886
-
887
- // Links: [text](url) — stash but keep the link text available to
888
- // inline formatting by recursing.
889
- staged = staged.replace(RE_LINK, (_m, linkText, href) =>
890
- stash(`<a href="${escapeHtml(href)}">${inlineToHtml(linkText)}</a>`),
891
- );
892
-
893
- let result = escapeHtml(staged);
894
-
895
- // Bold: **text** or __text__
896
- result = result.replace(RE_BOLD_STAR, '<strong>$1</strong>');
897
- result = result.replace(RE_BOLD_UNDER, '<strong>$1</strong>');
898
-
899
- // Italic: *text* or _text_
900
- result = result.replace(RE_ITALIC_STAR, '<em>$1</em>');
901
- result = result.replace(RE_ITALIC_UNDER, '<em>$1</em>');
902
-
903
- // Strikethrough: ~~text~~
904
- result = result.replace(RE_STRIKETHROUGH, '<s>$1</s>');
905
-
906
- // Inline code: `text`
907
- result = result.replace(RE_INLINE_CODE, '<code>$1</code>');
908
-
909
- // Restore placeholders. escapeHtml turned each `\u0000PHn\u0000` into
910
- // the same string (the NULs and digits are escape-safe), so the
911
- // restoration regex still matches.
912
- // eslint-disable-next-line no-control-regex
913
- result = result.replace(/\u0000PH(\d+)\u0000/g, (_m, idx) => placeholders[Number(idx)] ?? '');
914
-
915
- return preserveLeadingSpaces(result);
916
- }
917
-
918
- /** Convert inline HTML back to markdown */
919
- function htmlToInline(html: string): string {
920
- let result = html;
921
-
922
- // Soft line breaks — convert <br> to GFM hard-break syntax (two trailing
923
- // spaces + newline) before stripping tags so the newline survives.
924
- result = result.replace(/<br\s*\/?>/gi, ' \n');
925
-
926
- // FontAwesome inline icons — emit the original token. Must run before
927
- // RE_I_TAG (which matches a bare `<i>` and would otherwise eat icon
928
- // tags too). The token captured via data-icon already carries the
929
- // qualified form when needed, so source round-trips exactly.
930
- result = result.replace(RE_ICON_TAG, (_m, token) => `{[${token}]}`);
931
-
932
- // Strong
933
- result = result.replace(RE_STRONG_TAG, '**$1**');
934
- result = result.replace(RE_B_TAG, '**$1**');
935
-
936
- // Em
937
- result = result.replace(RE_EM_TAG, '*$1*');
938
- result = result.replace(RE_I_TAG, '*$1*');
939
-
940
- // Strikethrough
941
- result = result.replace(RE_S_TAG, '~~$1~~');
942
- result = result.replace(RE_DEL_TAG, '~~$1~~');
943
-
944
- // Code
945
- result = result.replace(RE_CODE_TAG, '`$1`');
946
-
947
- // Mentions — match before the link handler so the span isn't stripped
948
- // out as an unknown tag. Pull kind + id out of the data attributes.
949
- result = result.replace(RE_MENTION_TAG, (match, _inner) => {
950
- const kind = /data-kind="([^"]*)"/i.exec(match)?.[1] ?? '';
951
- const id = /data-id="([^"]*)"/i.exec(match)?.[1] ?? '';
952
- const label = /data-label="([^"]*)"/i.exec(match)?.[1] ?? '';
953
- if (!kind || !id || !label) return match;
954
- return `@[${label}](${kind}:${id})`;
955
- });
956
-
957
- // Links
958
- result = result.replace(RE_A_TAG, '[$2]($1)');
959
-
960
- // Images — order-agnostic attribute parsing (tiptap emits src-first,
961
- // our markdown-to-html emits alt-first; either must serialize back).
962
- // When a width/height is present we serialize as raw HTML `<img>` so
963
- // the dimensions survive the round-trip; otherwise the markdown
964
- // shorthand `![alt](src)` is used.
965
- result = result.replace(RE_IMG_TAG, (match, attrs: string) => {
966
- const src = /\bsrc="([^"]*)"/i.exec(attrs)?.[1];
967
- if (!src) return match;
968
- const alt = /\balt="([^"]*)"/i.exec(attrs)?.[1] ?? '';
969
- return serializeImage(src, alt, attrs);
970
- });
971
-
972
- // Strip remaining tags
973
- result = result.replace(RE_STRIP_TAGS, '');
974
-
975
- return restoreLeadingSpaces(unescapeHtml(result));
976
- }
977
-
978
- function preserveLeadingSpaces(html: string): string {
979
- return html.replace(/^ +/, (spaces) => '&nbsp;'.repeat(spaces.length));
980
- }
981
-
982
- function restoreLeadingSpaces(text: string): string {
983
- return text.replace(/(^|\n)(\u00a0+)/g, (_match, prefix: string, spaces: string) => {
984
- return prefix + ' '.repeat(spaces.length);
985
- });
986
- }