@bendyline/squisq-editor-react 2.0.1 → 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 (357) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE.md +40 -0
  3. package/README.md +10 -2
  4. package/dist/index.d.ts +683 -60
  5. package/dist/index.js +9648 -3750
  6. package/dist/monaco.js +0 -1
  7. package/dist/styles/index.css +1160 -241
  8. package/package.json +10 -6
  9. package/dist/index.js.map +0 -1
  10. package/dist/monaco.js.map +0 -1
  11. package/src/BlockCardView.tsx +0 -121
  12. package/src/BlockPreviewPanel.tsx +0 -69
  13. package/src/BlockPropertiesPopover.tsx +0 -222
  14. package/src/DocumentSettingsDialog.tsx +0 -272
  15. package/src/DropZoneOverlay.tsx +0 -137
  16. package/src/EditorContext.tsx +0 -1247
  17. package/src/EditorShell.tsx +0 -1334
  18. package/src/EmojiPicker.tsx +0 -332
  19. package/src/FolderView.tsx +0 -131
  20. package/src/Icon.tsx +0 -26
  21. package/src/ImageEditor.tsx +0 -395
  22. package/src/ImageNodeView.tsx +0 -284
  23. package/src/ImageViewer.tsx +0 -221
  24. package/src/InlineIcon.ts +0 -84
  25. package/src/InlinePreviewGutter.tsx +0 -590
  26. package/src/LinkDialog.tsx +0 -276
  27. package/src/MediaBin.tsx +0 -500
  28. package/src/MentionExtension.tsx +0 -261
  29. package/src/OutlinePanel.tsx +0 -547
  30. package/src/PlainHtmlPreview.tsx +0 -277
  31. package/src/PreviewControls.tsx +0 -1250
  32. package/src/PreviewPanel.tsx +0 -422
  33. package/src/RawEditor.tsx +0 -731
  34. package/src/RecorderEntry.tsx +0 -159
  35. package/src/StatusBar.tsx +0 -51
  36. package/src/TemplateAnnotation.ts +0 -167
  37. package/src/TemplateContentPreview.tsx +0 -56
  38. package/src/TemplatePicker.tsx +0 -1314
  39. package/src/ThemeCustomizerPanel.tsx +0 -304
  40. package/src/ThemePicker.tsx +0 -433
  41. package/src/TimelineBlockPreview.tsx +0 -37
  42. package/src/TimelineTrack.tsx +0 -671
  43. package/src/Toolbar.tsx +0 -2587
  44. package/src/Tooltip.tsx +0 -142
  45. package/src/TransitionPicker.tsx +0 -390
  46. package/src/VersionHistoryPanel.tsx +0 -359
  47. package/src/ViewMenuPanel.tsx +0 -189
  48. package/src/ViewSwitcher.tsx +0 -56
  49. package/src/WysiwygEditor.tsx +0 -792
  50. package/src/__tests__/blockProperties.test.ts +0 -92
  51. package/src/__tests__/blockPropertiesPopoverTheme.test.tsx +0 -33
  52. package/src/__tests__/blockRange.test.ts +0 -105
  53. package/src/__tests__/blockTagActivity.test.ts +0 -183
  54. package/src/__tests__/buildDocumentPreviewMarkdown.test.ts +0 -75
  55. package/src/__tests__/buildPreviewDocContent.test.ts +0 -48
  56. package/src/__tests__/buildPreviewDocTransition.test.ts +0 -92
  57. package/src/__tests__/canvasSurfaceTextEditing.test.tsx +0 -60
  58. package/src/__tests__/codeContextSectionView.test.tsx +0 -97
  59. package/src/__tests__/codeContextZoneManager.test.ts +0 -127
  60. package/src/__tests__/createShapeLayer.test.ts +0 -46
  61. package/src/__tests__/customLayoutManagerTheme.test.tsx +0 -34
  62. package/src/__tests__/detectMarkdown.test.ts +0 -73
  63. package/src/__tests__/diffContextSections.test.ts +0 -39
  64. package/src/__tests__/documentSettingsDialog.test.tsx +0 -197
  65. package/src/__tests__/drawingShapeRoundTrip.test.ts +0 -49
  66. package/src/__tests__/editorScrollHandoff.test.tsx +0 -102
  67. package/src/__tests__/editorScrollSync.test.ts +0 -65
  68. package/src/__tests__/editorShellCodeContext.test.tsx +0 -86
  69. package/src/__tests__/editorShellProps.test.tsx +0 -485
  70. package/src/__tests__/embeddedMedia.test.ts +0 -48
  71. package/src/__tests__/emojiPicker.test.tsx +0 -93
  72. package/src/__tests__/fileKind.test.ts +0 -112
  73. package/src/__tests__/headingTransition.test.ts +0 -176
  74. package/src/__tests__/imageEditAffordance.test.tsx +0 -272
  75. package/src/__tests__/imageEditModalContract.test.tsx +0 -119
  76. package/src/__tests__/imageEditorShell.test.tsx +0 -94
  77. package/src/__tests__/imageEditorState.test.ts +0 -171
  78. package/src/__tests__/inlinePreviewGutter.test.tsx +0 -62
  79. package/src/__tests__/inlinePreviewGutterAllBlocks.test.tsx +0 -103
  80. package/src/__tests__/jsonEditor.test.tsx +0 -223
  81. package/src/__tests__/layersPanel.test.tsx +0 -167
  82. package/src/__tests__/layoutChildRoundTrip.test.ts +0 -71
  83. package/src/__tests__/linkDialogDocPicker.test.tsx +0 -137
  84. package/src/__tests__/majorApiTypes.test.ts +0 -26
  85. package/src/__tests__/mediaAttachmentFlow.test.ts +0 -110
  86. package/src/__tests__/mediaBinDrop.test.tsx +0 -90
  87. package/src/__tests__/mediaReferences.test.ts +0 -82
  88. package/src/__tests__/narrationSave.test.ts +0 -148
  89. package/src/__tests__/outlinePanel.test.tsx +0 -169
  90. package/src/__tests__/outlineSource.test.ts +0 -217
  91. package/src/__tests__/plainHtmlPreview.test.tsx +0 -125
  92. package/src/__tests__/presentationMode.test.tsx +0 -290
  93. package/src/__tests__/previewControls.test.tsx +0 -540
  94. package/src/__tests__/previewPanelAudioFailure.test.tsx +0 -46
  95. package/src/__tests__/previewPanelPresentation.test.tsx +0 -126
  96. package/src/__tests__/previewPanelTransforms.test.tsx +0 -117
  97. package/src/__tests__/propertiesPanel.test.tsx +0 -69
  98. package/src/__tests__/rawEditorModelIsolation.test.ts +0 -19
  99. package/src/__tests__/recorderFormats.test.ts +0 -146
  100. package/src/__tests__/recorderMediaInsert.test.ts +0 -86
  101. package/src/__tests__/recorderTheme.test.tsx +0 -42
  102. package/src/__tests__/recorderTimingJson.test.ts +0 -41
  103. package/src/__tests__/resolveBlockVisual.test.ts +0 -43
  104. package/src/__tests__/selectionConversions.test.ts +0 -80
  105. package/src/__tests__/statusBar.test.tsx +0 -27
  106. package/src/__tests__/teleprompter.test.tsx +0 -190
  107. package/src/__tests__/templateAnnotationRoundTrip.test.ts +0 -99
  108. package/src/__tests__/templateContentPreview.test.ts +0 -101
  109. package/src/__tests__/templatePickerMetadata.test.ts +0 -32
  110. package/src/__tests__/templatePickerPortal.test.tsx +0 -62
  111. package/src/__tests__/timelineSource.test.ts +0 -134
  112. package/src/__tests__/tiptapBridge.test.ts +0 -566
  113. package/src/__tests__/tiptapBridgeConformance.test.ts +0 -47
  114. package/src/__tests__/tiptapCodeBlockRoundTrip.test.ts +0 -109
  115. package/src/__tests__/tiptapImageRoundTrip.test.ts +0 -73
  116. package/src/__tests__/toolbarSelectionConversion.test.tsx +0 -164
  117. package/src/__tests__/tooltip.test.tsx +0 -72
  118. package/src/__tests__/transformStyleId.test.ts +0 -13
  119. package/src/__tests__/transitionCatalog.test.ts +0 -64
  120. package/src/__tests__/useBlockNavigator.test.tsx +0 -67
  121. package/src/__tests__/useImageEditor.test.tsx +0 -226
  122. package/src/__tests__/useJsonEditorTokens.test.ts +0 -59
  123. package/src/__tests__/useMediaRecorder.test.ts +0 -302
  124. package/src/__tests__/useTimelineClock.test.ts +0 -21
  125. package/src/__tests__/versionHistory.test.tsx +0 -197
  126. package/src/__tests__/viewMenuPanel.test.tsx +0 -130
  127. package/src/__tests__/wysiwygImageUpload.test.ts +0 -69
  128. package/src/__tests__/wysiwygTemplateBadgeFocus.test.tsx +0 -56
  129. package/src/asciiDiagram/AsciiDiagramExtension.ts +0 -343
  130. package/src/asciiDiagram/AsciiDiagramWidget.tsx +0 -254
  131. package/src/asciiDiagram/RepairableDiagramExtension.ts +0 -200
  132. package/src/asciiDiagram/__tests__/AsciiDiagramExtension.test.ts +0 -145
  133. package/src/asciiDiagram/__tests__/RepairableDiagramExtension.test.ts +0 -159
  134. package/src/asciiDiagram/__tests__/asciiDiagramCommands.test.ts +0 -284
  135. package/src/asciiDiagram/__tests__/asciiDiagramOps.test.ts +0 -114
  136. package/src/asciiDiagram/__tests__/asciiPaste.test.ts +0 -43
  137. package/src/asciiDiagram/asciiDiagramCommands.ts +0 -174
  138. package/src/asciiDiagram/asciiDiagramData.ts +0 -149
  139. package/src/asciiDiagram/asciiDiagramOps.ts +0 -238
  140. package/src/asciiDiagram/asciiPaste.ts +0 -19
  141. package/src/blockProperties.ts +0 -88
  142. package/src/blockRange.ts +0 -132
  143. package/src/blockSlice.ts +0 -75
  144. package/src/blockTagActivity.ts +0 -233
  145. package/src/buildDocumentPreviewMarkdown.ts +0 -168
  146. package/src/buildPreviewDoc.ts +0 -405
  147. package/src/codeContext/CodeContextSectionView.tsx +0 -124
  148. package/src/codeContext/CodeContextZoneManager.ts +0 -149
  149. package/src/codeContext/CodeContextZones.tsx +0 -121
  150. package/src/codeContext/diffContextSections.ts +0 -38
  151. package/src/codeContext/types.ts +0 -75
  152. package/src/customTemplates/AddBin.tsx +0 -126
  153. package/src/customTemplates/CustomLayoutManager.tsx +0 -234
  154. package/src/customTemplates/CustomTemplateContext.tsx +0 -188
  155. package/src/customTemplates/LayerToolbar.tsx +0 -580
  156. package/src/customTemplates/ShapeGlyph.tsx +0 -47
  157. package/src/customTemplates/TemplateDesigner.tsx +0 -433
  158. package/src/customTemplates/__tests__/library.test.ts +0 -96
  159. package/src/customTemplates/__tests__/normalizePositions.test.ts +0 -109
  160. package/src/customTemplates/__tests__/shapeDefs.test.ts +0 -49
  161. package/src/customTemplates/__tests__/useMemoryLayerAdapter.test.ts +0 -108
  162. package/src/customTemplates/designer.css +0 -732
  163. package/src/customTemplates/index.ts +0 -31
  164. package/src/customTemplates/library.ts +0 -110
  165. package/src/customTemplates/normalizePositions.ts +0 -75
  166. package/src/customTemplates/shapeDefs.ts +0 -131
  167. package/src/customTemplates/thumbnail.tsx +0 -63
  168. package/src/customTemplates/tokenDefs.ts +0 -60
  169. package/src/customTemplates/useDocCustomTemplates.ts +0 -52
  170. package/src/customTemplates/useMemoryLayerAdapter.ts +0 -129
  171. package/src/customThemes/CustomThemeContext.tsx +0 -185
  172. package/src/customThemes/CustomThemeDialog.tsx +0 -316
  173. package/src/customThemes/ImportThemeSection.tsx +0 -178
  174. package/src/customThemes/__tests__/CustomThemeContext.test.tsx +0 -64
  175. package/src/customThemes/__tests__/CustomThemeDialog.test.tsx +0 -47
  176. package/src/customThemes/__tests__/customThemeLibrary.test.ts +0 -60
  177. package/src/customThemes/__tests__/importThemeSection.test.tsx +0 -192
  178. package/src/customThemes/customThemeLibrary.ts +0 -100
  179. package/src/customThemes/index.ts +0 -37
  180. package/src/customThemes/themeControls.tsx +0 -229
  181. package/src/customThemes/themeDraft.ts +0 -288
  182. package/src/customThemes/useDocCustomThemes.ts +0 -49
  183. package/src/detectMarkdown.ts +0 -62
  184. package/src/diagram/DiagramCanvas.tsx +0 -259
  185. package/src/diagram/DiagramMaximizedOverlay.tsx +0 -46
  186. package/src/diagram/diagramCommands.ts +0 -604
  187. package/src/diagram/diagramConstants.ts +0 -17
  188. package/src/diagram/types.ts +0 -35
  189. package/src/editorScrollSync.ts +0 -73
  190. package/src/embeddedMedia.ts +0 -78
  191. package/src/emojiData.ts +0 -1317
  192. package/src/fileKind.ts +0 -158
  193. package/src/frontmatter.ts +0 -29
  194. package/src/frontmatterSettings.ts +0 -23
  195. package/src/headingTransition.ts +0 -291
  196. package/src/hooks/useFileDrop.ts +0 -266
  197. package/src/imageEditor/CanvasSurface.tsx +0 -703
  198. package/src/imageEditor/ImageVersionHistoryDropdown.tsx +0 -396
  199. package/src/imageEditor/LayersPanel.tsx +0 -218
  200. package/src/imageEditor/PropertiesPanel.tsx +0 -474
  201. package/src/imageEditor/Toolbar.tsx +0 -459
  202. package/src/imageEditor/createShapeLayer.ts +0 -280
  203. package/src/imageEditor/icons.tsx +0 -68
  204. package/src/imageEditor/image-editor.css +0 -574
  205. package/src/imageEditor/layers/EditorImageLayer.tsx +0 -45
  206. package/src/imageEditor/layers/EditorShapeLayer.tsx +0 -62
  207. package/src/imageEditor/layers/EditorTextLayer.tsx +0 -45
  208. package/src/imageEditor/layers/SelectionHandles.tsx +0 -86
  209. package/src/imageEditor/state.ts +0 -173
  210. package/src/imageEditor/useImageEditor.ts +0 -385
  211. package/src/imageEditor/useImageEditorTokens.ts +0 -70
  212. package/src/index.ts +0 -470
  213. package/src/jsonEditor/EmbeddedRichTextField.tsx +0 -81
  214. package/src/jsonEditor/JsonEditor.tsx +0 -81
  215. package/src/jsonEditor/JsonEditorContext.tsx +0 -81
  216. package/src/jsonEditor/RenderNode.tsx +0 -87
  217. package/src/jsonEditor/editors.tsx +0 -745
  218. package/src/jsonEditor/index.ts +0 -2
  219. package/src/jsonEditor/json-editor.css +0 -463
  220. package/src/jsonEditor/useJsonEditorTokens.ts +0 -33
  221. package/src/mediaDragMime.ts +0 -32
  222. package/src/mediaEntries.ts +0 -12
  223. package/src/mediaReferences.ts +0 -299
  224. package/src/monaco.ts +0 -35
  225. package/src/monacoWorkers.ts +0 -89
  226. package/src/outlineSource.ts +0 -171
  227. package/src/presentation/PresentationMode.tsx +0 -596
  228. package/src/rawEditorIsolation.ts +0 -18
  229. package/src/recorder/RecorderButton.tsx +0 -80
  230. package/src/recorder/RecorderModal.tsx +0 -706
  231. package/src/recorder/RecorderPanel.tsx +0 -77
  232. package/src/recorder/formats.ts +0 -159
  233. package/src/recorder/hooks/useMediaRecorder.ts +0 -436
  234. package/src/recorder/hooks/useStreamPreview.ts +0 -47
  235. package/src/recorder/insertMediaBlock.ts +0 -30
  236. package/src/recorder/sources/cameraStream.ts +0 -32
  237. package/src/recorder/sources/micStream.ts +0 -25
  238. package/src/recorder/sources/screenStream.ts +0 -162
  239. package/src/recorder/timingJson.ts +0 -66
  240. package/src/resolveBlockVisual.ts +0 -39
  241. package/src/scene/Scene.tsx +0 -616
  242. package/src/scene/SceneBlockExtension.ts +0 -205
  243. package/src/scene/SceneBlockToolbar.tsx +0 -201
  244. package/src/scene/SceneBlockWidget.tsx +0 -441
  245. package/src/scene/ScenePropsBar.tsx +0 -85
  246. package/src/scene/SceneSelection.tsx +0 -111
  247. package/src/scene/SceneSideToolbar.tsx +0 -89
  248. package/src/scene/SceneViewport.tsx +0 -106
  249. package/src/scene/ShapePalette.tsx +0 -196
  250. package/src/scene/__tests__/DiagramAdapter.test.ts +0 -142
  251. package/src/scene/__tests__/SceneBlockExtension.test.ts +0 -33
  252. package/src/scene/__tests__/bezierEdit.test.ts +0 -85
  253. package/src/scene/__tests__/blockLayers.test.ts +0 -57
  254. package/src/scene/__tests__/sceneIsolation.test.tsx +0 -119
  255. package/src/scene/__tests__/shapeLayers.test.ts +0 -106
  256. package/src/scene/__tests__/useSceneHitTest.test.ts +0 -90
  257. package/src/scene/__tests__/useScenePanZoom.test.ts +0 -103
  258. package/src/scene/adapters/DiagramAdapter.ts +0 -79
  259. package/src/scene/adapters/DrawingAdapter.ts +0 -420
  260. package/src/scene/adapters/LayoutAdapter.ts +0 -313
  261. package/src/scene/adapters/blockLayers.ts +0 -159
  262. package/src/scene/commands/SceneCommand.ts +0 -84
  263. package/src/scene/commands/drawingCommands.ts +0 -318
  264. package/src/scene/commands/layoutCommands.ts +0 -301
  265. package/src/scene/hooks/useSceneHitTest.ts +0 -105
  266. package/src/scene/hooks/useScenePanZoom.ts +0 -147
  267. package/src/scene/hooks/useSceneSelection.ts +0 -62
  268. package/src/scene/index.ts +0 -90
  269. package/src/scene/layers/DiagramEdges.tsx +0 -142
  270. package/src/scene/layers/edgeGeometry.ts +0 -104
  271. package/src/scene/layers/nodeCard.tsx +0 -164
  272. package/src/scene/layers/renderLayer.tsx +0 -70
  273. package/src/scene/layers/shapeLayers.ts +0 -201
  274. package/src/scene/paths/bezierEdit.ts +0 -208
  275. package/src/scene/scene.css +0 -792
  276. package/src/scene/text/SceneTextOverlay.tsx +0 -161
  277. package/src/scene/text/sceneTextChannel.ts +0 -46
  278. package/src/scene/text/sceneTextConfig.ts +0 -31
  279. package/src/scene/text/sceneTiptap.ts +0 -36
  280. package/src/scene/text/useSceneTextEditing.ts +0 -39
  281. package/src/scene/tools/ConnectTool.ts +0 -209
  282. package/src/scene/tools/DrawingConnectTool.ts +0 -231
  283. package/src/scene/tools/PathTool.ts +0 -158
  284. package/src/scene/tools/PlaceTool.ts +0 -47
  285. package/src/scene/tools/SceneTool.ts +0 -85
  286. package/src/scene/tools/SelectTool.ts +0 -300
  287. package/src/scene/tools/ShapeTool.ts +0 -143
  288. package/src/scene/tools/TextTool.ts +0 -72
  289. package/src/scene/tools/TokenTool.ts +0 -95
  290. package/src/scene/tools/createDrawShapeTool.ts +0 -82
  291. package/src/selectionConversions.ts +0 -155
  292. package/src/styles/ascii-diagram.css +0 -79
  293. package/src/styles/ascii-timeline.css +0 -596
  294. package/src/styles/code-context.css +0 -155
  295. package/src/styles/diagram.css +0 -183
  296. package/src/styles/editor.css +0 -6811
  297. package/src/styles/folder-view.css +0 -210
  298. package/src/styles/image-edit-affordance.css +0 -201
  299. package/src/styles/index.css +0 -18
  300. package/src/styles/tree-view.css +0 -189
  301. package/src/teleprompter/TeleprompterControls.tsx +0 -218
  302. package/src/teleprompter/TeleprompterSelfView.tsx +0 -22
  303. package/src/teleprompter/TeleprompterSurface.tsx +0 -267
  304. package/src/teleprompter/TeleprompterView.tsx +0 -338
  305. package/src/teleprompter/canvasRenderer.ts +0 -161
  306. package/src/teleprompter/floatingWindow.ts +0 -352
  307. package/src/teleprompter/index.ts +0 -61
  308. package/src/teleprompter/pcmWorklet.ts +0 -62
  309. package/src/teleprompter/recording/insertPreamble.ts +0 -80
  310. package/src/teleprompter/recording/narrationSave.ts +0 -134
  311. package/src/teleprompter/recording/useNarrationRecorder.ts +0 -367
  312. package/src/teleprompter/scrollModel.ts +0 -85
  313. package/src/teleprompter/teleprompterTheme.ts +0 -303
  314. package/src/teleprompter/types.ts +0 -38
  315. package/src/teleprompter/useFloatingWindow.ts +0 -74
  316. package/src/teleprompter/useMicAnalysis.ts +0 -211
  317. package/src/teleprompter/useTeleprompter.ts +0 -421
  318. package/src/templateContentPreviewResolver.ts +0 -360
  319. package/src/timeline/TimelineEditorWidget.tsx +0 -861
  320. package/src/timeline/TimelineViewExtension.ts +0 -252
  321. package/src/timeline/__tests__/TimelineEditorWidget.test.tsx +0 -414
  322. package/src/timeline/__tests__/TimelineViewExtension.test.ts +0 -163
  323. package/src/timeline/__tests__/timelineCommands.test.ts +0 -359
  324. package/src/timeline/__tests__/timelineOps.test.ts +0 -277
  325. package/src/timeline/__tests__/timelinePaste.test.ts +0 -34
  326. package/src/timeline/timelineCommands.ts +0 -421
  327. package/src/timeline/timelineData.ts +0 -54
  328. package/src/timeline/timelineOps.ts +0 -381
  329. package/src/timeline/timelinePaste.ts +0 -8
  330. package/src/timelineSource.ts +0 -244
  331. package/src/tiptap/TiptapAudio.tsx +0 -86
  332. package/src/tiptap/TiptapVideo.tsx +0 -119
  333. package/src/tiptap/useResolvedMediaSrc.ts +0 -47
  334. package/src/tiptapBridge.ts +0 -986
  335. package/src/tooltipPlacement.ts +0 -13
  336. package/src/transformStyleId.ts +0 -17
  337. package/src/transitionCatalog.ts +0 -159
  338. package/src/treeview/TreeOutlineWidget.tsx +0 -390
  339. package/src/treeview/TreeViewExtension.ts +0 -250
  340. package/src/treeview/__tests__/TreeOutlineWidget.test.tsx +0 -156
  341. package/src/treeview/__tests__/TreeViewExtension.test.ts +0 -122
  342. package/src/treeview/__tests__/treeOps.test.ts +0 -177
  343. package/src/treeview/__tests__/treePaste.test.ts +0 -40
  344. package/src/treeview/__tests__/treeViewCommands.test.ts +0 -179
  345. package/src/treeview/treeOps.ts +0 -231
  346. package/src/treeview/treePaste.ts +0 -13
  347. package/src/treeview/treeViewCommands.ts +0 -99
  348. package/src/treeview/treeViewData.ts +0 -41
  349. package/src/types/monaco-shims.d.ts +0 -10
  350. package/src/useBlockNavigator.ts +0 -153
  351. package/src/useHeadingLayout.ts +0 -294
  352. package/src/useMonacoLoader.ts +0 -82
  353. package/src/useTimelineClock.ts +0 -76
  354. package/src/utils/collectInlineFontAwesomeCss.ts +0 -69
  355. package/src/utils/dropUtils.ts +0 -136
  356. package/src/utils/normalizeMalformedAssetUrl.ts +0 -22
  357. package/src/wysiwygImageUpload.ts +0 -113
package/src/RawEditor.tsx DELETED
@@ -1,731 +0,0 @@
1
- /**
2
- * RawEditor
3
- *
4
- * Monaco-based raw markdown editor. Provides full VS Code-like editing
5
- * experience with syntax highlighting, minimap, and bracket matching.
6
- * Syncs changes back to EditorContext on every keystroke (debounced).
7
- */
8
-
9
- import { useRef, useCallback, useEffect } from 'react';
10
- import Editor, { type OnMount, type OnChange, type BeforeMount } from '@monaco-editor/react';
11
- import type * as monaco from 'monaco-editor';
12
- import { useEditorContext } from './EditorContext';
13
- import { getAvailableTemplates } from '@bendyline/squisq/doc';
14
- import { suggestIcons, resolveIcon, iconGlyph } from '@bendyline/squisq/icons';
15
- import { BLOCK_META_KEY_DESCRIPTORS, tokenizeAttrTokens } from '@bendyline/squisq/markdown';
16
- import { SQUISQ_MEDIA_MIME, parseSquisqMediaPayload } from './mediaDragMime';
17
- import { canHandleSquisqMediaDrop, ownsMonacoModel } from './rawEditorIsolation';
18
- import { useMonacoLoader } from './useMonacoLoader';
19
-
20
- // Monaco is loaded lazily through `useMonacoLoader` (see the hook for the
21
- // rationale). The type-only `import type * as monaco from 'monaco-editor'`
22
- // above gives us `monaco.editor.IStandaloneCodeEditor`, `monaco.Range`,
23
- // etc. for typing without pulling the package into the static module
24
- // graph — which is the whole point: a consumer importing `JsonEditor` or
25
- // a type from the package barrel no longer drags ~9MB of language
26
- // services into the resolver.
27
- //
28
- // Consumers that *do* want the raw editor can still slim the bundle by
29
- // aliasing `monaco-editor` to a custom entry in their bundler config.
30
- // For example with Vite:
31
- //
32
- // resolve: { alias: [{ find: /^monaco-editor$/, replacement: './monaco-slim.ts' }] }
33
- //
34
- // Where monaco-slim.ts re-exports 'monaco-editor/esm/vs/editor/editor.api'
35
- // plus only the language contributions actually needed
36
- // (`basic-languages/monaco.contribution` for the broad TM grammars,
37
- // and any of `language/{css,html,json,typescript}/monaco.contribution`
38
- // for the rich language services). Skipping the language contributions
39
- // entirely means `defaultLanguage` becomes inert — no tokenizer
40
- // registered, so every file renders as plain foreground text.
41
-
42
- // Squisq Monaco themes: same syntax highlighting as vs / vs-dark, but with
43
- // Monaco's internal gutter (line numbers + folding margin) and overview
44
- // ruler tinted to match the side-pane "desk" colors so the canvas's
45
- // internal furniture blends with its surroundings. The seam color is the
46
- // 1px line Monaco draws between the white canvas and the overview ruler;
47
- // matches the `::after` border on `.margin` so both sides of the canvas
48
- // frame look the same.
49
- const SQUISQ_LIGHT_GUTTER = '#dcd8d0';
50
- const SQUISQ_DARK_GUTTER = '#0f1219';
51
- const SQUISQ_LIGHT_SEAM = '#b0a99a';
52
- const SQUISQ_DARK_SEAM = '#2a3144';
53
-
54
- const SQUISQ_THEMES: Record<string, string> = {
55
- vs: 'squisq-light',
56
- 'vs-dark': 'squisq-dark',
57
- };
58
-
59
- export interface RawEditorProps {
60
- /**
61
- * Monaco editor theme name (default: `'vs'`). Accepts Monaco's built-in
62
- * theme ids (`'vs'`, `'vs-dark'`, `'hc-black'`) — which are transparently
63
- * mapped to the Squisq-tinted variants — or any custom theme registered
64
- * via `monaco.editor.defineTheme`. This is the *code editor* color
65
- * theme, distinct from the shell's light/dark `colorScheme`.
66
- */
67
- monacoTheme?: string;
68
- /** Show minimap (default: false) */
69
- minimap?: boolean;
70
- /** Font size in pixels (default: 14) */
71
- fontSize?: number;
72
- /** Word wrap setting (default: 'on') */
73
- wordWrap?: 'on' | 'off' | 'wordWrapColumn' | 'bounded';
74
- /** Additional class name for the container */
75
- className?: string;
76
- /**
77
- * Chat-composer mode: Enter fires this callback (submit) and Cmd/Ctrl+Enter
78
- * inserts a newline. When undefined, behaves normally.
79
- */
80
- submitOnEnter?: () => void;
81
- /** Make Monaco read-only (no edits, no cursor blink). */
82
- readOnly?: boolean;
83
- }
84
-
85
- /**
86
- * Raw markdown editor using Monaco Editor.
87
- * Binds to the shared EditorContext for source synchronization.
88
- */
89
- export function RawEditor({
90
- monacoTheme = 'vs',
91
- minimap = false,
92
- fontSize = 14,
93
- wordWrap = 'on',
94
- className,
95
- submitOnEnter,
96
- readOnly = false,
97
- }: RawEditorProps) {
98
- const { editorSource, setEditorSource, setMonacoEditor, language, mentionProvider, doc } =
99
- useEditorContext();
100
- const { monaco: monacoNs, ready: monacoReady } = useMonacoLoader();
101
- const editorRef = useRef<monaco.editor.IStandaloneCodeEditor | null>(null);
102
- const isExternalUpdate = useRef(false);
103
- const completionDisposable = useRef<monaco.IDisposable | null>(null);
104
- const mentionCompletionDisposable = useRef<monaco.IDisposable | null>(null);
105
- const iconCompletionDisposable = useRef<monaco.IDisposable | null>(null);
106
- const attrCompletionDisposable = useRef<monaco.IDisposable | null>(null);
107
- const iconGlyphDecorations = useRef<monaco.editor.IEditorDecorationsCollection | null>(null);
108
- const dropCleanupRef = useRef<(() => void) | null>(null);
109
- const keyDisposable = useRef<monaco.IDisposable | null>(null);
110
- // Ref so the keydown handler always sees the latest callback.
111
- const submitOnEnterRef = useRef(submitOnEnter);
112
- const readOnlyRef = useRef(readOnly);
113
- useEffect(() => {
114
- submitOnEnterRef.current = submitOnEnter;
115
- }, [submitOnEnter]);
116
- useEffect(() => {
117
- readOnlyRef.current = readOnly;
118
- }, [readOnly]);
119
- // Ref so the completion provider — registered once at mount — always
120
- // sees the latest mentionProvider without needing to unregister.
121
- const mentionProviderRef = useRef(mentionProvider);
122
- useEffect(() => {
123
- mentionProviderRef.current = mentionProvider;
124
- }, [mentionProvider]);
125
-
126
- // Template completion list: built-in registry names plus any custom
127
- // templates inlined in the active doc's frontmatter (`doc.customTemplates`
128
- // — the same set that actually renders via `{[name]}`). Held in a ref
129
- // (like mentionProvider above) so the once-registered provider always
130
- // reads the latest set — custom templates created after mount must show
131
- // up without re-mounting Monaco.
132
- const docCustomTemplates = doc?.customTemplates;
133
- const templateEntriesRef = useRef<{ name: string; detail: string }[] | null>(null);
134
- if (templateEntriesRef.current === null) {
135
- templateEntriesRef.current = getAvailableTemplates().map((name) => ({
136
- name,
137
- detail: 'Block template',
138
- }));
139
- }
140
- useEffect(() => {
141
- const builtIns = getAvailableTemplates().map((name) => ({
142
- name,
143
- detail: 'Block template',
144
- }));
145
- const seen = new Set(builtIns.map((b) => b.name));
146
- const custom = (docCustomTemplates ?? [])
147
- .filter((t) => !seen.has(t.name))
148
- .map((t) => ({
149
- name: t.name,
150
- detail: t.label ? `Custom — ${t.label}` : 'Custom template',
151
- }));
152
- templateEntriesRef.current = [...builtIns, ...custom];
153
- }, [docCustomTemplates]);
154
-
155
- const handleBeforeMount: BeforeMount = useCallback((monaco) => {
156
- monaco.editor.defineTheme('squisq-light', {
157
- base: 'vs',
158
- inherit: true,
159
- rules: [],
160
- colors: {
161
- 'editorGutter.background': SQUISQ_LIGHT_GUTTER,
162
- 'editorOverviewRuler.background': SQUISQ_LIGHT_GUTTER,
163
- 'editorOverviewRuler.border': SQUISQ_LIGHT_SEAM,
164
- 'minimap.background': SQUISQ_LIGHT_GUTTER,
165
- },
166
- });
167
- monaco.editor.defineTheme('squisq-dark', {
168
- base: 'vs-dark',
169
- inherit: true,
170
- rules: [],
171
- colors: {
172
- 'editorGutter.background': SQUISQ_DARK_GUTTER,
173
- 'editorOverviewRuler.background': SQUISQ_DARK_GUTTER,
174
- 'editorOverviewRuler.border': SQUISQ_DARK_SEAM,
175
- 'minimap.background': SQUISQ_DARK_GUTTER,
176
- },
177
- });
178
- }, []);
179
-
180
- const handleMount: OnMount = useCallback(
181
- (editor, monaco) => {
182
- editorRef.current = editor;
183
- setMonacoEditor(editor);
184
- editor.focus();
185
-
186
- // Dispose any previous completion provider (from a prior mount)
187
- completionDisposable.current?.dispose();
188
- completionDisposable.current = null;
189
- mentionCompletionDisposable.current?.dispose();
190
- mentionCompletionDisposable.current = null;
191
- iconCompletionDisposable.current?.dispose();
192
- iconCompletionDisposable.current = null;
193
- attrCompletionDisposable.current?.dispose();
194
- attrCompletionDisposable.current = null;
195
-
196
- // Register the `{[template]}` completion provider only for markdown
197
- // files — it's meaningless for TypeScript, JSON, Python, etc.
198
- if (language === 'markdown') {
199
- completionDisposable.current = monaco.languages.registerCompletionItemProvider('markdown', {
200
- triggerCharacters: ['['],
201
- provideCompletionItems(model: monaco.editor.ITextModel, position: monaco.Position) {
202
- if (!ownsMonacoModel(editor, model)) return { suggestions: [] };
203
- const lineContent = model.getLineContent(position.lineNumber);
204
-
205
- // Only trigger inside a heading line that has {[ before the cursor
206
- if (!/^#{1,6}\s/.test(lineContent)) return { suggestions: [] };
207
-
208
- const textBeforeCursor = lineContent.substring(0, position.column - 1);
209
- const textAfterCursor = lineContent.substring(position.column - 1);
210
- const bracketIdx = textBeforeCursor.lastIndexOf('{[');
211
- if (bracketIdx === -1) return { suggestions: [] };
212
-
213
- // Template names are the FIRST token after `{[`. Once a space
214
- // follows the name we're in the `key=value` attribute region —
215
- // the attribute provider handles that, so bail here to avoid
216
- // offering template names mid-attribute.
217
- if (/\s/.test(textBeforeCursor.slice(bracketIdx + 2))) return { suggestions: [] };
218
-
219
- // When Monaco's bracket auto-pair has already produced the
220
- // closing `]}` we just leave it in place and skip the
221
- // suffix — otherwise accepting `sectionHeader` on
222
- // `{[gi]}` would yield `{[sectionHeader]}]}`.
223
- const closingMatch = textAfterCursor.match(/^\]\}/);
224
- const suffix = closingMatch ? '' : ']}';
225
-
226
- const startCol = bracketIdx + 3; // after {[
227
- const range = new monaco.Range(
228
- position.lineNumber,
229
- startCol,
230
- position.lineNumber,
231
- position.column,
232
- );
233
-
234
- const suggestions = (templateEntriesRef.current ?? []).map(({ name, detail }) => ({
235
- label: name,
236
- filterText: name,
237
- kind: monaco.languages.CompletionItemKind.Value,
238
- insertText: name + suffix,
239
- range,
240
- detail,
241
- sortText: name,
242
- }));
243
-
244
- return { suggestions };
245
- },
246
- });
247
-
248
- // `@mention` completion — queries the shared MentionProvider. Keep
249
- // this in its own registration so we can dispose it independently
250
- // of the template provider, and so the trigger character is just
251
- // `@` (not `[`).
252
- mentionCompletionDisposable.current = monaco.languages.registerCompletionItemProvider(
253
- 'markdown',
254
- {
255
- triggerCharacters: ['@'],
256
- async provideCompletionItems(model, position) {
257
- if (!ownsMonacoModel(editor, model)) return { suggestions: [] };
258
- const provider = mentionProviderRef.current;
259
- if (!provider) return { suggestions: [] };
260
- const lineContent = model.getLineContent(position.lineNumber);
261
- const textBeforeCursor = lineContent.substring(0, position.column - 1);
262
- const atIdx = textBeforeCursor.lastIndexOf('@');
263
- if (atIdx === -1) return { suggestions: [] };
264
- // `@` must be at line start or preceded by whitespace/punct —
265
- // skip e.g. email addresses like `foo@bar`.
266
- if (atIdx > 0) {
267
- const prevChar = textBeforeCursor[atIdx - 1];
268
- if (!/[\s\p{P}]/u.test(prevChar)) return { suggestions: [] };
269
- }
270
- const query = textBeforeCursor.slice(atIdx + 1);
271
- // Only fire for short queries — once the user has typed
272
- // a full word, the popover gets noisy.
273
- if (query.length > 40) return { suggestions: [] };
274
- if (/\s/.test(query)) return { suggestions: [] };
275
-
276
- let candidates;
277
- try {
278
- candidates = await provider(query);
279
- } catch {
280
- return { suggestions: [] };
281
- }
282
-
283
- const range = new monaco.Range(
284
- position.lineNumber,
285
- atIdx + 1,
286
- position.lineNumber,
287
- position.column,
288
- );
289
-
290
- return {
291
- suggestions: candidates.map((c) => ({
292
- label: `@${c.label}`,
293
- kind: monaco.languages.CompletionItemKind.User,
294
- insertText: `@[${c.label}](${c.scheme}:${c.id}) `,
295
- range,
296
- ...(c.description ? { detail: c.description } : {}),
297
- sortText: c.label,
298
- })),
299
- };
300
- },
301
- },
302
- );
303
-
304
- // FontAwesome icon completion. Fires inside any `{[…]}` opener
305
- // anywhere in the doc (not just headings — icons are inline).
306
- // Suggestions cover the whole FA Free catalog filtered by the
307
- // partial token; we cap at 50 to keep the popup readable. The
308
- // template provider above still handles heading lines, so on
309
- // a `## Title {[…]}` the user sees both template names AND
310
- // icons interleaved by the regular Monaco filter.
311
- iconCompletionDisposable.current = monaco.languages.registerCompletionItemProvider(
312
- 'markdown',
313
- {
314
- triggerCharacters: ['['],
315
- provideCompletionItems(model, position) {
316
- if (!ownsMonacoModel(editor, model)) return { suggestions: [] };
317
- const lineContent = model.getLineContent(position.lineNumber);
318
- const textBeforeCursor = lineContent.substring(0, position.column - 1);
319
- const textAfterCursor = lineContent.substring(position.column - 1);
320
- const bracketIdx = textBeforeCursor.lastIndexOf('{[');
321
- if (bracketIdx === -1) return { suggestions: [] };
322
- // Bail if any `]` already closes this annotation between
323
- // `{[` and the cursor — we'd be past the token, not in it.
324
- const between = textBeforeCursor.slice(bracketIdx + 2);
325
- if (between.includes(']')) return { suggestions: [] };
326
- // Tokens are alphanumeric + `-_:`; anything else means
327
- // we're not inside an icon (probably a code/link bracket).
328
- if (between && !/^[a-zA-Z0-9_:-]*$/.test(between)) {
329
- return { suggestions: [] };
330
- }
331
- const query = between.toLowerCase();
332
-
333
- // When Monaco's bracket auto-pair has already produced a
334
- // closing `]}` we don't want to insert another — but we
335
- // also don't want to consume the existing one, since
336
- // then we'd have to re-emit it and the round-trip is
337
- // brittle. Leave the closing in place and just insert
338
- // the bare token; if no closing exists yet, append it.
339
- const closingMatch = textAfterCursor.match(/^\]\}/);
340
- const suffix = closingMatch ? '' : ']}';
341
-
342
- const range = new monaco.Range(
343
- position.lineNumber,
344
- bracketIdx + 3, // after `{[`
345
- position.lineNumber,
346
- position.column,
347
- );
348
-
349
- const top = suggestIcons(query, 50);
350
- return {
351
- suggestions: top.map((m, i) => ({
352
- // Embed the FA codepoint as the first character of
353
- // the label. CSS targets the suggest widget with
354
- // FontAwesome as a font fallback, so the codepoint
355
- // renders as the glyph and the name renders in the
356
- // editor's normal font.
357
- label: {
358
- label: `${iconGlyph(m.entry)} ${m.token}`,
359
- description: `fa-${m.entry.family}`,
360
- },
361
- // `filterText` excludes the glyph + spacing so Monaco
362
- // filters against the actual icon name only.
363
- filterText: m.token,
364
- kind: monaco.languages.CompletionItemKind.Constant,
365
- insertText: `${m.token}${suffix}`,
366
- range,
367
- detail: m.entry.label,
368
- // Documentation pane (rendered when Monaco's
369
- // suggestion preview is expanded) shows a large
370
- // version of the glyph alongside the canonical token.
371
- documentation: {
372
- value: `<i class="fa-${m.entry.family} fa-${m.entry.name}" style="font-size: 2em; display: inline-block; margin-right: 8px; vertical-align: middle"></i> **${m.token}** *(${m.entry.label})*`,
373
- isTrusted: true,
374
- supportHtml: true,
375
- },
376
- // Sort key: 1-digit score prefix keeps "starts with"
377
- // matches above "contains" / keyword matches.
378
- sortText: `${m.score}${String(i).padStart(4, '0')}`,
379
- })),
380
- };
381
- },
382
- },
383
- );
384
-
385
- // `{[name key=value]}` block-meta attribute completion. Fires on
386
- // heading lines once the cursor is past the template name (the
387
- // first token), where attributes like `transition=` apply to the
388
- // block. Two modes:
389
- // - bare token → suggest attribute KEYS (insert `key=`)
390
- // - after `key=` → suggest that key's VALUES, when it has a
391
- // closed set (e.g. transition / transitionDirection)
392
- // The descriptor list comes from core so keys and value enums stay
393
- // in lockstep with what `coerceAnnotationValues` actually accepts.
394
- attrCompletionDisposable.current = monaco.languages.registerCompletionItemProvider(
395
- 'markdown',
396
- {
397
- triggerCharacters: ['=', ' '],
398
- provideCompletionItems(model, position) {
399
- if (!ownsMonacoModel(editor, model)) return { suggestions: [] };
400
- const lineContent = model.getLineContent(position.lineNumber);
401
- // Block-meta attributes only mean something on a heading's
402
- // template annotation — same gate as the template provider.
403
- if (!/^#{1,6}\s/.test(lineContent)) return { suggestions: [] };
404
-
405
- const textBeforeCursor = lineContent.substring(0, position.column - 1);
406
- const bracketIdx = textBeforeCursor.lastIndexOf('{[');
407
- if (bracketIdx === -1) return { suggestions: [] };
408
-
409
- // Bail if a `]` already closed the annotation before the
410
- // cursor — we'd be past it, not inside the attribute list.
411
- const innerBefore = textBeforeCursor.slice(bracketIdx + 2);
412
- if (innerBefore.includes(']')) return { suggestions: [] };
413
- // The first token is the template name; attributes only begin
414
- // after a whitespace separator. No space yet → still the name.
415
- if (!/\s/.test(innerBefore)) return { suggestions: [] };
416
-
417
- // Current token = run of non-whitespace ending at the cursor.
418
- const lastWsMatch = innerBefore.match(/\s(\S*)$/);
419
- const currentToken = lastWsMatch ? lastWsMatch[1] : '';
420
- const tokenStartCol = position.column - currentToken.length;
421
-
422
- const eqIdx = currentToken.indexOf('=');
423
- if (eqIdx >= 0) {
424
- // ── Value mode: `key=<partial>` ──
425
- const key = currentToken.slice(0, eqIdx);
426
- const descriptor = BLOCK_META_KEY_DESCRIPTORS.find((d) => d.key === key);
427
- if (!descriptor?.values) return { suggestions: [] };
428
- const range = new monaco.Range(
429
- position.lineNumber,
430
- tokenStartCol + eqIdx + 1, // after `=`
431
- position.lineNumber,
432
- position.column,
433
- );
434
- return {
435
- suggestions: descriptor.values.map((value, i) => ({
436
- label: value,
437
- filterText: value,
438
- kind: monaco.languages.CompletionItemKind.EnumMember,
439
- insertText: value,
440
- range,
441
- detail: descriptor.description,
442
- sortText: String(i).padStart(4, '0'),
443
- })),
444
- };
445
- }
446
-
447
- // ── Key mode: suggest attribute names not already present ──
448
- // Collect keys already set anywhere in the annotation so we
449
- // don't re-offer them; keep the key under the cursor eligible
450
- // so re-editing an existing `key=` still suggests it.
451
- const afterBracket = lineContent.slice(bracketIdx + 2);
452
- const closeIdx = afterBracket.indexOf(']}');
453
- const fullInner = closeIdx === -1 ? afterBracket : afterBracket.slice(0, closeIdx);
454
- const present = new Set(
455
- tokenizeAttrTokens(fullInner)
456
- .map((t) => {
457
- const i = t.indexOf('=');
458
- return i > 0 ? t.slice(0, i) : null;
459
- })
460
- .filter((k): k is string => k != null),
461
- );
462
- present.delete(currentToken);
463
-
464
- const range = new monaco.Range(
465
- position.lineNumber,
466
- tokenStartCol,
467
- position.lineNumber,
468
- position.column,
469
- );
470
- const suggestions = BLOCK_META_KEY_DESCRIPTORS.filter((d) => !present.has(d.key)).map(
471
- (d, i) => ({
472
- label: d.key,
473
- filterText: d.key,
474
- kind: monaco.languages.CompletionItemKind.Property,
475
- insertText: `${d.key}=`,
476
- range,
477
- detail: d.values ? d.description : `${d.description} — ${d.valueHint}`,
478
- sortText: String(i).padStart(4, '0'),
479
- // Closed-set keys chain straight into their value list.
480
- ...(d.values
481
- ? { command: { id: 'editor.action.triggerSuggest', title: '' } }
482
- : {}),
483
- }),
484
- );
485
- return { suggestions };
486
- },
487
- },
488
- );
489
- }
490
-
491
- // Chat-composer mode: intercept Enter before Monaco inserts a newline.
492
- // Cmd/Ctrl+Enter falls through so the native newline still works.
493
- keyDisposable.current?.dispose();
494
- keyDisposable.current = editor.onKeyDown((e) => {
495
- if (e.keyCode !== monaco.KeyCode.Enter) return;
496
- if (!submitOnEnterRef.current) return;
497
- if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
498
- e.preventDefault();
499
- e.stopPropagation();
500
- submitOnEnterRef.current();
501
- });
502
-
503
- // Attach native drop listeners for in-app MediaBin drags. Monaco's own
504
- // drop handling doesn't know about our custom MIME type, so we insert
505
- // markdown image syntax explicitly in the capture phase.
506
- dropCleanupRef.current?.();
507
- const domNode = editor.getDomNode();
508
- if (domNode) {
509
- const onDragOver = (e: DragEvent) => {
510
- const dt = e.dataTransfer;
511
- if (canHandleSquisqMediaDrop(readOnlyRef.current, dt)) {
512
- e.preventDefault();
513
- dt!.dropEffect = 'copy';
514
- }
515
- };
516
- const onDrop = (e: DragEvent) => {
517
- if (!canHandleSquisqMediaDrop(readOnlyRef.current, e.dataTransfer)) return;
518
- const dt = e.dataTransfer;
519
- if (!dt) return;
520
- const raw = dt.getData(SQUISQ_MEDIA_MIME);
521
- if (!raw) return;
522
- const payload = parseSquisqMediaPayload(raw);
523
- if (!payload || !payload.mimeType.startsWith('image/')) return;
524
-
525
- e.preventDefault();
526
- e.stopPropagation();
527
-
528
- const target = editor.getTargetAtClientPoint(e.clientX, e.clientY);
529
- const position = target?.position ?? editor.getPosition();
530
- if (!position) return;
531
-
532
- const markdown = `![${payload.alt}](${payload.name})`;
533
- editor.executeEdits('squisq-media-drop', [
534
- {
535
- range: new monaco.Range(
536
- position.lineNumber,
537
- position.column,
538
- position.lineNumber,
539
- position.column,
540
- ),
541
- text: markdown,
542
- forceMoveMarkers: true,
543
- },
544
- ]);
545
- editor.focus();
546
- };
547
- domNode.addEventListener('dragover', onDragOver, true);
548
- domNode.addEventListener('drop', onDrop, true);
549
- dropCleanupRef.current = () => {
550
- domNode.removeEventListener('dragover', onDragOver, true);
551
- domNode.removeEventListener('drop', onDrop, true);
552
- };
553
- }
554
- },
555
- [setMonacoEditor, language],
556
- );
557
-
558
- // Unregister on unmount
559
- useEffect(() => {
560
- return () => {
561
- setMonacoEditor(null);
562
- completionDisposable.current?.dispose();
563
- completionDisposable.current = null;
564
- mentionCompletionDisposable.current?.dispose();
565
- mentionCompletionDisposable.current = null;
566
- iconCompletionDisposable.current?.dispose();
567
- iconCompletionDisposable.current = null;
568
- attrCompletionDisposable.current?.dispose();
569
- attrCompletionDisposable.current = null;
570
- iconGlyphDecorations.current?.clear();
571
- iconGlyphDecorations.current = null;
572
- dropCleanupRef.current?.();
573
- dropCleanupRef.current = null;
574
- keyDisposable.current?.dispose();
575
- keyDisposable.current = null;
576
- };
577
- }, [setMonacoEditor]);
578
-
579
- const handleChange: OnChange = useCallback(
580
- (value) => {
581
- if (isExternalUpdate.current) return;
582
- if (value !== undefined) {
583
- setEditorSource(value);
584
- }
585
- },
586
- [setEditorSource],
587
- );
588
-
589
- // When external changes happen (e.g. from WYSIWYG, or navigating to another
590
- // block in block-at-a-time mode), update Monaco. In block mode `editorSource`
591
- // is the active block's slice, so this swaps Monaco's content on navigation.
592
- useEffect(() => {
593
- const editor = editorRef.current;
594
- if (editor) {
595
- const currentValue = editor.getValue();
596
- // Ignore trailing-whitespace-only differences from block-mode splice
597
- // normalization — calling setValue for those resets the Monaco cursor.
598
- if (
599
- currentValue !== editorSource &&
600
- currentValue.replace(/\s+$/, '') !== editorSource.replace(/\s+$/, '')
601
- ) {
602
- isExternalUpdate.current = true;
603
- editor.setValue(editorSource);
604
- isExternalUpdate.current = false;
605
- }
606
- }
607
- }, [editorSource]);
608
-
609
- // ── Inline FontAwesome glyph decorations ────────────
610
- // Walk the markdown source on every change, find each resolvable
611
- // `{[icon-name]}` span, and overlay the actual glyph (via Monaco's
612
- // `before:` content decoration) just before the brackets. The CSS
613
- // classes `.fa-glyph-decoration-<family>` set the per-family font
614
- // and weight; the codepoint character is the decoration's content.
615
- useEffect(() => {
616
- const editor = editorRef.current;
617
- // `monacoNs` is read from the lazy loader's state rather than a
618
- // top-level import. Re-run when it transitions from null → loaded
619
- // so decorations show up the moment monaco is in hand.
620
- if (!editor || !monacoNs) return;
621
- if (language !== 'markdown') return;
622
- const model = editor.getModel();
623
- if (!model) return;
624
-
625
- const decorations: monaco.editor.IModelDeltaDecoration[] = [];
626
- const lines = model.getLineCount();
627
- const re = /\{\[([a-zA-Z0-9_:-]+)\]\}/g;
628
- for (let line = 1; line <= lines; line++) {
629
- const text = model.getLineContent(line);
630
- re.lastIndex = 0;
631
- let match: RegExpExecArray | null;
632
- while ((match = re.exec(text)) !== null) {
633
- const icon = resolveIcon(match[1]);
634
- if (!icon) continue;
635
- const glyph = iconGlyph(icon);
636
- if (!glyph) continue;
637
- // Position the decoration as a zero-width range at the `{`
638
- // of the matched token. `before.contentText` renders the
639
- // glyph as content prepended visually to that position.
640
- const col = match.index + 1; // Monaco columns are 1-based
641
- decorations.push({
642
- range: new monacoNs.Range(line, col, line, col),
643
- options: {
644
- before: {
645
- content: glyph,
646
- inlineClassName: `fa-glyph-decoration-${icon.family}`,
647
- },
648
- },
649
- });
650
- }
651
- }
652
-
653
- if (!iconGlyphDecorations.current) {
654
- iconGlyphDecorations.current = editor.createDecorationsCollection(decorations);
655
- } else {
656
- iconGlyphDecorations.current.set(decorations);
657
- }
658
- }, [editorSource, language, monacoNs]);
659
-
660
- const effectiveTheme = SQUISQ_THEMES[monacoTheme] ?? monacoTheme;
661
-
662
- // Wait for the lazy monaco namespace + `loader.config()` to settle
663
- // before mounting `<Editor>`. Without this gate, the @monaco-editor/
664
- // react singleton loader would fall back to its built-in CDN fetch
665
- // for any consumer that hasn't aliased monaco-editor — which is the
666
- // exact regression the lazy-loading move is meant to avoid.
667
- if (!monacoReady) {
668
- return (
669
- <div
670
- className={className}
671
- style={{
672
- width: '100%',
673
- height: '100%',
674
- display: 'flex',
675
- alignItems: 'center',
676
- justifyContent: 'center',
677
- color: 'var(--squisq-editor-muted-foreground, #6a6258)',
678
- fontSize: 13,
679
- }}
680
- data-testid="raw-editor"
681
- data-monaco-loading
682
- >
683
- Loading editor…
684
- </div>
685
- );
686
- }
687
-
688
- return (
689
- <div className={className} style={{ width: '100%', height: '100%' }} data-testid="raw-editor">
690
- <Editor
691
- defaultLanguage={language}
692
- value={editorSource}
693
- theme={effectiveTheme}
694
- beforeMount={handleBeforeMount}
695
- onMount={handleMount}
696
- onChange={handleChange}
697
- options={{
698
- fontSize,
699
- wordWrap,
700
- minimap: { enabled: minimap },
701
- lineNumbers: 'on',
702
- scrollBeyondLastLine: false,
703
- automaticLayout: true,
704
- tabSize: 2,
705
- renderWhitespace: 'selection',
706
- bracketPairColorization: { enabled: true },
707
- guides: { indentation: true },
708
- padding: { top: 12, bottom: 12 },
709
- // Markdown's tokenizer classifies most body text as "string"
710
- // or "comment" context, which suppresses `quickSuggestions`
711
- // by default. Enable in all three so our `{[icon]}` and
712
- // `@mention` typeaheads keep firing as the user types past
713
- // the trigger character.
714
- quickSuggestions: { other: true, comments: true, strings: true },
715
- suggestOnTriggerCharacters: true,
716
- // Breathing room between the gutter and the first character.
717
- // Done via Monaco's own option so cursor + hit-testing stay in
718
- // sync — CSS-padding `.view-lines` shifts the text but not the
719
- // cursors layer, which causes the cursor to drift left of the
720
- // model column. Monaco's default is 10. We set 22 (12 extra),
721
- // and CSS paints the rightmost 12px of the gutter as canvas
722
- // color so the breathing room looks like it sits *inside* the
723
- // canvas rather than widening the gutter.
724
- lineDecorationsWidth: 22,
725
- readOnly,
726
- domReadOnly: readOnly,
727
- }}
728
- />
729
- </div>
730
- );
731
- }