@bendyline/squisq-editor-react 1.3.0 → 1.5.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 (461) hide show
  1. package/dist/DocumentSettingsDialog.d.ts +26 -0
  2. package/dist/DocumentSettingsDialog.d.ts.map +1 -0
  3. package/dist/DocumentSettingsDialog.js +115 -0
  4. package/dist/DocumentSettingsDialog.js.map +1 -0
  5. package/dist/EditorContext.d.ts +248 -4
  6. package/dist/EditorContext.d.ts.map +1 -1
  7. package/dist/EditorContext.js +248 -10
  8. package/dist/EditorContext.js.map +1 -1
  9. package/dist/EditorShell.d.ts +184 -4
  10. package/dist/EditorShell.d.ts.map +1 -1
  11. package/dist/EditorShell.js +184 -12
  12. package/dist/EditorShell.js.map +1 -1
  13. package/dist/EmojiPicker.d.ts +50 -0
  14. package/dist/EmojiPicker.d.ts.map +1 -0
  15. package/dist/EmojiPicker.js +182 -0
  16. package/dist/EmojiPicker.js.map +1 -0
  17. package/dist/ImageEditor.d.ts +68 -0
  18. package/dist/ImageEditor.d.ts.map +1 -0
  19. package/dist/ImageEditor.js +166 -0
  20. package/dist/ImageEditor.js.map +1 -0
  21. package/dist/ImageNodeView.d.ts +13 -1
  22. package/dist/ImageNodeView.d.ts.map +1 -1
  23. package/dist/ImageNodeView.js +172 -19
  24. package/dist/ImageNodeView.js.map +1 -1
  25. package/dist/ImageViewer.d.ts +26 -0
  26. package/dist/ImageViewer.d.ts.map +1 -0
  27. package/dist/ImageViewer.js +119 -0
  28. package/dist/ImageViewer.js.map +1 -0
  29. package/dist/InlineIcon.d.ts +17 -0
  30. package/dist/InlineIcon.d.ts.map +1 -0
  31. package/dist/InlineIcon.js +72 -0
  32. package/dist/InlineIcon.js.map +1 -0
  33. package/dist/InlinePreviewGutter.d.ts +52 -0
  34. package/dist/InlinePreviewGutter.d.ts.map +1 -0
  35. package/dist/InlinePreviewGutter.js +397 -0
  36. package/dist/InlinePreviewGutter.js.map +1 -0
  37. package/dist/LinkDialog.d.ts +43 -0
  38. package/dist/LinkDialog.d.ts.map +1 -0
  39. package/dist/LinkDialog.js +102 -0
  40. package/dist/LinkDialog.js.map +1 -0
  41. package/dist/MediaBin.d.ts +12 -1
  42. package/dist/MediaBin.d.ts.map +1 -1
  43. package/dist/MediaBin.js +13 -3
  44. package/dist/MediaBin.js.map +1 -1
  45. package/dist/MentionExtension.js +10 -7
  46. package/dist/MentionExtension.js.map +1 -1
  47. package/dist/OutlinePanel.d.ts +17 -0
  48. package/dist/OutlinePanel.d.ts.map +1 -0
  49. package/dist/OutlinePanel.js +167 -0
  50. package/dist/OutlinePanel.js.map +1 -0
  51. package/dist/PlainHtmlPreview.d.ts +50 -0
  52. package/dist/PlainHtmlPreview.d.ts.map +1 -0
  53. package/dist/PlainHtmlPreview.js +155 -0
  54. package/dist/PlainHtmlPreview.js.map +1 -0
  55. package/dist/PreviewControls.d.ts +15 -1
  56. package/dist/PreviewControls.d.ts.map +1 -1
  57. package/dist/PreviewControls.js +75 -18
  58. package/dist/PreviewControls.js.map +1 -1
  59. package/dist/PreviewPanel.d.ts +11 -10
  60. package/dist/PreviewPanel.d.ts.map +1 -1
  61. package/dist/PreviewPanel.js +20 -17
  62. package/dist/PreviewPanel.js.map +1 -1
  63. package/dist/RawEditor.d.ts.map +1 -1
  64. package/dist/RawEditor.js +198 -4
  65. package/dist/RawEditor.js.map +1 -1
  66. package/dist/RecorderEntry.d.ts +24 -0
  67. package/dist/RecorderEntry.d.ts.map +1 -0
  68. package/dist/RecorderEntry.js +139 -0
  69. package/dist/RecorderEntry.js.map +1 -0
  70. package/dist/TemplateAnnotation.d.ts.map +1 -1
  71. package/dist/TemplateAnnotation.js +32 -6
  72. package/dist/TemplateAnnotation.js.map +1 -1
  73. package/dist/TemplatePicker.d.ts +53 -0
  74. package/dist/TemplatePicker.d.ts.map +1 -0
  75. package/dist/TemplatePicker.js +388 -0
  76. package/dist/TemplatePicker.js.map +1 -0
  77. package/dist/ThemeCustomizerPanel.d.ts +32 -0
  78. package/dist/ThemeCustomizerPanel.d.ts.map +1 -0
  79. package/dist/ThemeCustomizerPanel.js +256 -0
  80. package/dist/ThemeCustomizerPanel.js.map +1 -0
  81. package/dist/ThemePicker.d.ts +33 -0
  82. package/dist/ThemePicker.d.ts.map +1 -0
  83. package/dist/ThemePicker.js +148 -0
  84. package/dist/ThemePicker.js.map +1 -0
  85. package/dist/Toolbar.d.ts.map +1 -1
  86. package/dist/Toolbar.js +508 -33
  87. package/dist/Toolbar.js.map +1 -1
  88. package/dist/VersionHistoryPanel.d.ts +14 -0
  89. package/dist/VersionHistoryPanel.d.ts.map +1 -0
  90. package/dist/VersionHistoryPanel.js +147 -0
  91. package/dist/VersionHistoryPanel.js.map +1 -0
  92. package/dist/ViewMenuPanel.d.ts +13 -0
  93. package/dist/ViewMenuPanel.d.ts.map +1 -0
  94. package/dist/ViewMenuPanel.js +58 -0
  95. package/dist/ViewMenuPanel.js.map +1 -0
  96. package/dist/WysiwygEditor.d.ts.map +1 -1
  97. package/dist/WysiwygEditor.js +198 -9
  98. package/dist/WysiwygEditor.js.map +1 -1
  99. package/dist/__tests__/detectMarkdown.test.js +0 -14
  100. package/dist/__tests__/detectMarkdown.test.js.map +1 -1
  101. package/dist/__tests__/documentSettingsDialog.test.d.ts +2 -0
  102. package/dist/__tests__/documentSettingsDialog.test.d.ts.map +1 -0
  103. package/dist/__tests__/documentSettingsDialog.test.js +132 -0
  104. package/dist/__tests__/documentSettingsDialog.test.js.map +1 -0
  105. package/dist/__tests__/emojiPicker.test.d.ts +2 -0
  106. package/dist/__tests__/emojiPicker.test.d.ts.map +1 -0
  107. package/dist/__tests__/emojiPicker.test.js +111 -0
  108. package/dist/__tests__/emojiPicker.test.js.map +1 -0
  109. package/dist/__tests__/fileKind.test.js +13 -0
  110. package/dist/__tests__/fileKind.test.js.map +1 -1
  111. package/dist/__tests__/imageEditAffordance.test.d.ts +2 -0
  112. package/dist/__tests__/imageEditAffordance.test.d.ts.map +1 -0
  113. package/dist/__tests__/imageEditAffordance.test.js +188 -0
  114. package/dist/__tests__/imageEditAffordance.test.js.map +1 -0
  115. package/dist/__tests__/imageEditorShell.test.d.ts +2 -0
  116. package/dist/__tests__/imageEditorShell.test.d.ts.map +1 -0
  117. package/dist/__tests__/imageEditorShell.test.js +52 -0
  118. package/dist/__tests__/imageEditorShell.test.js.map +1 -0
  119. package/dist/__tests__/imageEditorState.test.d.ts +3 -0
  120. package/dist/__tests__/imageEditorState.test.d.ts.map +1 -0
  121. package/dist/__tests__/imageEditorState.test.js +148 -0
  122. package/dist/__tests__/imageEditorState.test.js.map +1 -0
  123. package/dist/__tests__/inlinePreviewGutter.test.d.ts +2 -0
  124. package/dist/__tests__/inlinePreviewGutter.test.d.ts.map +1 -0
  125. package/dist/__tests__/inlinePreviewGutter.test.js +51 -0
  126. package/dist/__tests__/inlinePreviewGutter.test.js.map +1 -0
  127. package/dist/__tests__/inlinePreviewGutterAllBlocks.test.d.ts +2 -0
  128. package/dist/__tests__/inlinePreviewGutterAllBlocks.test.d.ts.map +1 -0
  129. package/dist/__tests__/inlinePreviewGutterAllBlocks.test.js +63 -0
  130. package/dist/__tests__/inlinePreviewGutterAllBlocks.test.js.map +1 -0
  131. package/dist/__tests__/jsonEditor.test.d.ts +2 -0
  132. package/dist/__tests__/jsonEditor.test.d.ts.map +1 -0
  133. package/dist/__tests__/jsonEditor.test.js +134 -0
  134. package/dist/__tests__/jsonEditor.test.js.map +1 -0
  135. package/dist/__tests__/layersPanel.test.d.ts +2 -0
  136. package/dist/__tests__/layersPanel.test.d.ts.map +1 -0
  137. package/dist/__tests__/layersPanel.test.js +84 -0
  138. package/dist/__tests__/layersPanel.test.js.map +1 -0
  139. package/dist/__tests__/linkDialogDocPicker.test.d.ts +7 -0
  140. package/dist/__tests__/linkDialogDocPicker.test.d.ts.map +1 -0
  141. package/dist/__tests__/linkDialogDocPicker.test.js +75 -0
  142. package/dist/__tests__/linkDialogDocPicker.test.js.map +1 -0
  143. package/dist/__tests__/mediaAttachmentFlow.test.d.ts +2 -0
  144. package/dist/__tests__/mediaAttachmentFlow.test.d.ts.map +1 -0
  145. package/dist/__tests__/mediaAttachmentFlow.test.js +99 -0
  146. package/dist/__tests__/mediaAttachmentFlow.test.js.map +1 -0
  147. package/dist/__tests__/outlinePanel.test.d.ts +2 -0
  148. package/dist/__tests__/outlinePanel.test.d.ts.map +1 -0
  149. package/dist/__tests__/outlinePanel.test.js +68 -0
  150. package/dist/__tests__/outlinePanel.test.js.map +1 -0
  151. package/dist/__tests__/plainHtmlPreview.test.d.ts +2 -0
  152. package/dist/__tests__/plainHtmlPreview.test.d.ts.map +1 -0
  153. package/dist/__tests__/plainHtmlPreview.test.js +87 -0
  154. package/dist/__tests__/plainHtmlPreview.test.js.map +1 -0
  155. package/dist/__tests__/propertiesPanel.test.d.ts +2 -0
  156. package/dist/__tests__/propertiesPanel.test.d.ts.map +1 -0
  157. package/dist/__tests__/propertiesPanel.test.js +64 -0
  158. package/dist/__tests__/propertiesPanel.test.js.map +1 -0
  159. package/dist/__tests__/recorderFormats.test.d.ts +2 -0
  160. package/dist/__tests__/recorderFormats.test.d.ts.map +1 -0
  161. package/dist/__tests__/recorderFormats.test.js +121 -0
  162. package/dist/__tests__/recorderFormats.test.js.map +1 -0
  163. package/dist/__tests__/recorderTimingJson.test.d.ts +2 -0
  164. package/dist/__tests__/recorderTimingJson.test.d.ts.map +1 -0
  165. package/dist/__tests__/recorderTimingJson.test.js +37 -0
  166. package/dist/__tests__/recorderTimingJson.test.js.map +1 -0
  167. package/dist/__tests__/templateAnnotationRoundTrip.test.d.ts +2 -0
  168. package/dist/__tests__/templateAnnotationRoundTrip.test.d.ts.map +1 -0
  169. package/dist/__tests__/templateAnnotationRoundTrip.test.js +31 -0
  170. package/dist/__tests__/templateAnnotationRoundTrip.test.js.map +1 -0
  171. package/dist/__tests__/tiptapBridge.test.js +26 -0
  172. package/dist/__tests__/tiptapBridge.test.js.map +1 -1
  173. package/dist/__tests__/tiptapImageRoundTrip.test.d.ts +2 -0
  174. package/dist/__tests__/tiptapImageRoundTrip.test.d.ts.map +1 -0
  175. package/dist/__tests__/tiptapImageRoundTrip.test.js +68 -0
  176. package/dist/__tests__/tiptapImageRoundTrip.test.js.map +1 -0
  177. package/dist/__tests__/useImageEditor.test.d.ts +2 -0
  178. package/dist/__tests__/useImageEditor.test.d.ts.map +1 -0
  179. package/dist/__tests__/useImageEditor.test.js +131 -0
  180. package/dist/__tests__/useImageEditor.test.js.map +1 -0
  181. package/dist/__tests__/useMediaRecorder.test.d.ts +2 -0
  182. package/dist/__tests__/useMediaRecorder.test.d.ts.map +1 -0
  183. package/dist/__tests__/useMediaRecorder.test.js +153 -0
  184. package/dist/__tests__/useMediaRecorder.test.js.map +1 -0
  185. package/dist/__tests__/versionHistory.test.d.ts +2 -0
  186. package/dist/__tests__/versionHistory.test.d.ts.map +1 -0
  187. package/dist/__tests__/versionHistory.test.js +124 -0
  188. package/dist/__tests__/versionHistory.test.js.map +1 -0
  189. package/dist/blockSlice.d.ts +24 -0
  190. package/dist/blockSlice.d.ts.map +1 -0
  191. package/dist/blockSlice.js +63 -0
  192. package/dist/blockSlice.js.map +1 -0
  193. package/dist/buildPreviewDoc.d.ts.map +1 -1
  194. package/dist/buildPreviewDoc.js +52 -2
  195. package/dist/buildPreviewDoc.js.map +1 -1
  196. package/dist/emojiData.d.ts +81 -0
  197. package/dist/emojiData.d.ts.map +1 -0
  198. package/dist/emojiData.js +1283 -0
  199. package/dist/emojiData.js.map +1 -0
  200. package/dist/fileKind.d.ts +6 -2
  201. package/dist/fileKind.d.ts.map +1 -1
  202. package/dist/fileKind.js +25 -4
  203. package/dist/fileKind.js.map +1 -1
  204. package/dist/hooks/useFileDrop.d.ts.map +1 -1
  205. package/dist/hooks/useFileDrop.js +40 -4
  206. package/dist/hooks/useFileDrop.js.map +1 -1
  207. package/dist/imageEditor/CanvasSurface.d.ts +31 -0
  208. package/dist/imageEditor/CanvasSurface.d.ts.map +1 -0
  209. package/dist/imageEditor/CanvasSurface.js +264 -0
  210. package/dist/imageEditor/CanvasSurface.js.map +1 -0
  211. package/dist/imageEditor/ImageVersionHistoryDropdown.d.ts +39 -0
  212. package/dist/imageEditor/ImageVersionHistoryDropdown.d.ts.map +1 -0
  213. package/dist/imageEditor/ImageVersionHistoryDropdown.js +283 -0
  214. package/dist/imageEditor/ImageVersionHistoryDropdown.js.map +1 -0
  215. package/dist/imageEditor/LayersPanel.d.ts +14 -0
  216. package/dist/imageEditor/LayersPanel.d.ts.map +1 -0
  217. package/dist/imageEditor/LayersPanel.js +43 -0
  218. package/dist/imageEditor/LayersPanel.js.map +1 -0
  219. package/dist/imageEditor/PropertiesPanel.d.ts +14 -0
  220. package/dist/imageEditor/PropertiesPanel.d.ts.map +1 -0
  221. package/dist/imageEditor/PropertiesPanel.js +97 -0
  222. package/dist/imageEditor/PropertiesPanel.js.map +1 -0
  223. package/dist/imageEditor/Toolbar.d.ts +30 -0
  224. package/dist/imageEditor/Toolbar.d.ts.map +1 -0
  225. package/dist/imageEditor/Toolbar.js +108 -0
  226. package/dist/imageEditor/Toolbar.js.map +1 -0
  227. package/dist/imageEditor/icons.d.ts +24 -0
  228. package/dist/imageEditor/icons.d.ts.map +1 -0
  229. package/dist/imageEditor/icons.js +45 -0
  230. package/dist/imageEditor/icons.js.map +1 -0
  231. package/dist/imageEditor/layers/EditorImageLayer.d.ts +16 -0
  232. package/dist/imageEditor/layers/EditorImageLayer.d.ts.map +1 -0
  233. package/dist/imageEditor/layers/EditorImageLayer.js +37 -0
  234. package/dist/imageEditor/layers/EditorImageLayer.js.map +1 -0
  235. package/dist/imageEditor/layers/EditorShapeLayer.d.ts +15 -0
  236. package/dist/imageEditor/layers/EditorShapeLayer.d.ts.map +1 -0
  237. package/dist/imageEditor/layers/EditorShapeLayer.js +20 -0
  238. package/dist/imageEditor/layers/EditorShapeLayer.js.map +1 -0
  239. package/dist/imageEditor/layers/EditorTextLayer.d.ts +18 -0
  240. package/dist/imageEditor/layers/EditorTextLayer.d.ts.map +1 -0
  241. package/dist/imageEditor/layers/EditorTextLayer.js +13 -0
  242. package/dist/imageEditor/layers/EditorTextLayer.js.map +1 -0
  243. package/dist/imageEditor/layers/SelectionHandles.d.ts +17 -0
  244. package/dist/imageEditor/layers/SelectionHandles.d.ts.map +1 -0
  245. package/dist/imageEditor/layers/SelectionHandles.js +19 -0
  246. package/dist/imageEditor/layers/SelectionHandles.js.map +1 -0
  247. package/dist/imageEditor/state.d.ts +76 -0
  248. package/dist/imageEditor/state.d.ts.map +1 -0
  249. package/dist/imageEditor/state.js +87 -0
  250. package/dist/imageEditor/state.js.map +1 -0
  251. package/dist/imageEditor/useImageEditor.d.ts +53 -0
  252. package/dist/imageEditor/useImageEditor.d.ts.map +1 -0
  253. package/dist/imageEditor/useImageEditor.js +244 -0
  254. package/dist/imageEditor/useImageEditor.js.map +1 -0
  255. package/dist/imageEditor/useImageEditorTokens.d.ts +16 -0
  256. package/dist/imageEditor/useImageEditorTokens.d.ts.map +1 -0
  257. package/dist/imageEditor/useImageEditorTokens.js +45 -0
  258. package/dist/imageEditor/useImageEditorTokens.js.map +1 -0
  259. package/dist/index.d.ts +48 -1
  260. package/dist/index.d.ts.map +1 -1
  261. package/dist/index.js +36 -0
  262. package/dist/index.js.map +1 -1
  263. package/dist/jsonEditor/EmbeddedRichTextField.d.ts +15 -0
  264. package/dist/jsonEditor/EmbeddedRichTextField.d.ts.map +1 -0
  265. package/dist/jsonEditor/EmbeddedRichTextField.js +74 -0
  266. package/dist/jsonEditor/EmbeddedRichTextField.js.map +1 -0
  267. package/dist/jsonEditor/JsonEditor.d.ts +36 -0
  268. package/dist/jsonEditor/JsonEditor.d.ts.map +1 -0
  269. package/dist/jsonEditor/JsonEditor.js +15 -0
  270. package/dist/jsonEditor/JsonEditor.js.map +1 -0
  271. package/dist/jsonEditor/JsonEditorContext.d.ts +28 -0
  272. package/dist/jsonEditor/JsonEditorContext.d.ts.map +1 -0
  273. package/dist/jsonEditor/JsonEditorContext.js +41 -0
  274. package/dist/jsonEditor/JsonEditorContext.js.map +1 -0
  275. package/dist/jsonEditor/RenderNode.d.ts +16 -0
  276. package/dist/jsonEditor/RenderNode.d.ts.map +1 -0
  277. package/dist/jsonEditor/RenderNode.js +32 -0
  278. package/dist/jsonEditor/RenderNode.js.map +1 -0
  279. package/dist/jsonEditor/editors.d.ts +36 -0
  280. package/dist/jsonEditor/editors.d.ts.map +1 -0
  281. package/dist/jsonEditor/editors.js +347 -0
  282. package/dist/jsonEditor/editors.js.map +1 -0
  283. package/dist/jsonEditor/index.d.ts +3 -0
  284. package/dist/jsonEditor/index.d.ts.map +1 -0
  285. package/dist/jsonEditor/index.js +2 -0
  286. package/dist/jsonEditor/index.js.map +1 -0
  287. package/dist/jsonEditor/useJsonEditorTokens.d.ts +13 -0
  288. package/dist/jsonEditor/useJsonEditorTokens.d.ts.map +1 -0
  289. package/dist/jsonEditor/useJsonEditorTokens.js +38 -0
  290. package/dist/jsonEditor/useJsonEditorTokens.js.map +1 -0
  291. package/dist/recorder/RecorderButton.d.ts +31 -0
  292. package/dist/recorder/RecorderButton.d.ts.map +1 -0
  293. package/dist/recorder/RecorderButton.js +24 -0
  294. package/dist/recorder/RecorderButton.js.map +1 -0
  295. package/dist/recorder/RecorderModal.d.ts +59 -0
  296. package/dist/recorder/RecorderModal.d.ts.map +1 -0
  297. package/dist/recorder/RecorderModal.js +333 -0
  298. package/dist/recorder/RecorderModal.js.map +1 -0
  299. package/dist/recorder/RecorderPanel.d.ts +25 -0
  300. package/dist/recorder/RecorderPanel.d.ts.map +1 -0
  301. package/dist/recorder/RecorderPanel.js +30 -0
  302. package/dist/recorder/RecorderPanel.js.map +1 -0
  303. package/dist/recorder/formats.d.ts +51 -0
  304. package/dist/recorder/formats.d.ts.map +1 -0
  305. package/dist/recorder/formats.js +144 -0
  306. package/dist/recorder/formats.js.map +1 -0
  307. package/dist/recorder/hooks/useMediaRecorder.d.ts +90 -0
  308. package/dist/recorder/hooks/useMediaRecorder.d.ts.map +1 -0
  309. package/dist/recorder/hooks/useMediaRecorder.js +277 -0
  310. package/dist/recorder/hooks/useMediaRecorder.js.map +1 -0
  311. package/dist/recorder/hooks/useStreamPreview.d.ts +22 -0
  312. package/dist/recorder/hooks/useStreamPreview.d.ts.map +1 -0
  313. package/dist/recorder/hooks/useStreamPreview.js +44 -0
  314. package/dist/recorder/hooks/useStreamPreview.js.map +1 -0
  315. package/dist/recorder/sources/cameraStream.d.ts +22 -0
  316. package/dist/recorder/sources/cameraStream.d.ts.map +1 -0
  317. package/dist/recorder/sources/cameraStream.js +24 -0
  318. package/dist/recorder/sources/cameraStream.js.map +1 -0
  319. package/dist/recorder/sources/micStream.d.ts +15 -0
  320. package/dist/recorder/sources/micStream.d.ts.map +1 -0
  321. package/dist/recorder/sources/micStream.js +24 -0
  322. package/dist/recorder/sources/micStream.js.map +1 -0
  323. package/dist/recorder/sources/screenStream.d.ts +53 -0
  324. package/dist/recorder/sources/screenStream.d.ts.map +1 -0
  325. package/dist/recorder/sources/screenStream.js +114 -0
  326. package/dist/recorder/sources/screenStream.js.map +1 -0
  327. package/dist/recorder/timingJson.d.ts +51 -0
  328. package/dist/recorder/timingJson.d.ts.map +1 -0
  329. package/dist/recorder/timingJson.js +42 -0
  330. package/dist/recorder/timingJson.js.map +1 -0
  331. package/dist/tiptap/TiptapAudio.d.ts +26 -0
  332. package/dist/tiptap/TiptapAudio.d.ts.map +1 -0
  333. package/dist/tiptap/TiptapAudio.js +58 -0
  334. package/dist/tiptap/TiptapAudio.js.map +1 -0
  335. package/dist/tiptap/TiptapVideo.d.ts +30 -0
  336. package/dist/tiptap/TiptapVideo.d.ts.map +1 -0
  337. package/dist/tiptap/TiptapVideo.js +66 -0
  338. package/dist/tiptap/TiptapVideo.js.map +1 -0
  339. package/dist/tiptap/useResolvedMediaSrc.d.ts +2 -0
  340. package/dist/tiptap/useResolvedMediaSrc.d.ts.map +1 -0
  341. package/dist/tiptap/useResolvedMediaSrc.js +42 -0
  342. package/dist/tiptap/useResolvedMediaSrc.js.map +1 -0
  343. package/dist/tiptapBridge.d.ts.map +1 -1
  344. package/dist/tiptapBridge.js +210 -16
  345. package/dist/tiptapBridge.js.map +1 -1
  346. package/dist/useHeadingLayout.d.ts +54 -0
  347. package/dist/useHeadingLayout.d.ts.map +1 -0
  348. package/dist/useHeadingLayout.js +260 -0
  349. package/dist/useHeadingLayout.js.map +1 -0
  350. package/dist/utils/collectInlineFontAwesomeCss.d.ts +21 -0
  351. package/dist/utils/collectInlineFontAwesomeCss.d.ts.map +1 -0
  352. package/dist/utils/collectInlineFontAwesomeCss.js +68 -0
  353. package/dist/utils/collectInlineFontAwesomeCss.js.map +1 -0
  354. package/dist/utils/dropUtils.d.ts +21 -2
  355. package/dist/utils/dropUtils.d.ts.map +1 -1
  356. package/dist/utils/dropUtils.js +43 -4
  357. package/dist/utils/dropUtils.js.map +1 -1
  358. package/dist/utils/normalizeMalformedAssetUrl.d.ts +15 -0
  359. package/dist/utils/normalizeMalformedAssetUrl.d.ts.map +1 -0
  360. package/dist/utils/normalizeMalformedAssetUrl.js +27 -0
  361. package/dist/utils/normalizeMalformedAssetUrl.js.map +1 -0
  362. package/package.json +8 -5
  363. package/src/DocumentSettingsDialog.tsx +266 -0
  364. package/src/EditorContext.tsx +534 -10
  365. package/src/EditorShell.tsx +691 -63
  366. package/src/EmojiPicker.tsx +332 -0
  367. package/src/ImageEditor.tsx +327 -0
  368. package/src/ImageNodeView.tsx +222 -21
  369. package/src/ImageViewer.tsx +221 -0
  370. package/src/InlineIcon.ts +84 -0
  371. package/src/InlinePreviewGutter.tsx +582 -0
  372. package/src/LinkDialog.tsx +276 -0
  373. package/src/MediaBin.tsx +22 -3
  374. package/src/MentionExtension.tsx +10 -7
  375. package/src/OutlinePanel.tsx +295 -0
  376. package/src/PlainHtmlPreview.tsx +211 -0
  377. package/src/PreviewControls.tsx +130 -24
  378. package/src/PreviewPanel.tsx +38 -21
  379. package/src/RawEditor.tsx +215 -4
  380. package/src/RecorderEntry.tsx +164 -0
  381. package/src/TemplateAnnotation.ts +32 -6
  382. package/src/TemplatePicker.tsx +818 -0
  383. package/src/ThemeCustomizerPanel.tsx +595 -0
  384. package/src/ThemePicker.tsx +319 -0
  385. package/src/Toolbar.tsx +708 -111
  386. package/src/VersionHistoryPanel.tsx +329 -0
  387. package/src/ViewMenuPanel.tsx +188 -0
  388. package/src/WysiwygEditor.tsx +229 -9
  389. package/src/__tests__/detectMarkdown.test.ts +0 -15
  390. package/src/__tests__/documentSettingsDialog.test.tsx +147 -0
  391. package/src/__tests__/emojiPicker.test.tsx +133 -0
  392. package/src/__tests__/fileKind.test.ts +16 -0
  393. package/src/__tests__/imageEditAffordance.test.tsx +268 -0
  394. package/src/__tests__/imageEditorShell.test.tsx +57 -0
  395. package/src/__tests__/imageEditorState.test.ts +171 -0
  396. package/src/__tests__/inlinePreviewGutter.test.tsx +62 -0
  397. package/src/__tests__/inlinePreviewGutterAllBlocks.test.tsx +103 -0
  398. package/src/__tests__/jsonEditor.test.tsx +168 -0
  399. package/src/__tests__/layersPanel.test.tsx +97 -0
  400. package/src/__tests__/linkDialogDocPicker.test.tsx +137 -0
  401. package/src/__tests__/mediaAttachmentFlow.test.ts +110 -0
  402. package/src/__tests__/outlinePanel.test.tsx +79 -0
  403. package/src/__tests__/plainHtmlPreview.test.tsx +107 -0
  404. package/src/__tests__/propertiesPanel.test.tsx +69 -0
  405. package/src/__tests__/recorderFormats.test.ts +146 -0
  406. package/src/__tests__/recorderTimingJson.test.ts +41 -0
  407. package/src/__tests__/templateAnnotationRoundTrip.test.ts +34 -0
  408. package/src/__tests__/tiptapBridge.test.ts +29 -0
  409. package/src/__tests__/tiptapImageRoundTrip.test.ts +73 -0
  410. package/src/__tests__/useImageEditor.test.tsx +159 -0
  411. package/src/__tests__/useMediaRecorder.test.ts +186 -0
  412. package/src/__tests__/versionHistory.test.tsx +197 -0
  413. package/src/blockSlice.ts +75 -0
  414. package/src/buildPreviewDoc.ts +61 -6
  415. package/src/emojiData.ts +1337 -0
  416. package/src/fileKind.ts +30 -6
  417. package/src/hooks/useFileDrop.ts +40 -4
  418. package/src/imageEditor/CanvasSurface.tsx +402 -0
  419. package/src/imageEditor/ImageVersionHistoryDropdown.tsx +396 -0
  420. package/src/imageEditor/LayersPanel.tsx +143 -0
  421. package/src/imageEditor/PropertiesPanel.tsx +428 -0
  422. package/src/imageEditor/Toolbar.tsx +242 -0
  423. package/src/imageEditor/icons.tsx +144 -0
  424. package/src/imageEditor/image-editor.css +450 -0
  425. package/src/imageEditor/layers/EditorImageLayer.tsx +45 -0
  426. package/src/imageEditor/layers/EditorShapeLayer.tsx +62 -0
  427. package/src/imageEditor/layers/EditorTextLayer.tsx +45 -0
  428. package/src/imageEditor/layers/SelectionHandles.tsx +86 -0
  429. package/src/imageEditor/state.ts +153 -0
  430. package/src/imageEditor/useImageEditor.ts +328 -0
  431. package/src/imageEditor/useImageEditorTokens.ts +70 -0
  432. package/src/index.ts +82 -0
  433. package/src/jsonEditor/EmbeddedRichTextField.tsx +81 -0
  434. package/src/jsonEditor/JsonEditor.tsx +81 -0
  435. package/src/jsonEditor/JsonEditorContext.tsx +75 -0
  436. package/src/jsonEditor/RenderNode.tsx +66 -0
  437. package/src/jsonEditor/editors.tsx +678 -0
  438. package/src/jsonEditor/index.ts +2 -0
  439. package/src/jsonEditor/json-editor.css +463 -0
  440. package/src/jsonEditor/useJsonEditorTokens.ts +63 -0
  441. package/src/recorder/RecorderButton.tsx +72 -0
  442. package/src/recorder/RecorderModal.tsx +596 -0
  443. package/src/recorder/RecorderPanel.tsx +93 -0
  444. package/src/recorder/formats.ts +159 -0
  445. package/src/recorder/hooks/useMediaRecorder.ts +378 -0
  446. package/src/recorder/hooks/useStreamPreview.ts +47 -0
  447. package/src/recorder/sources/cameraStream.ts +32 -0
  448. package/src/recorder/sources/micStream.ts +25 -0
  449. package/src/recorder/sources/screenStream.ts +162 -0
  450. package/src/recorder/timingJson.ts +66 -0
  451. package/src/styles/editor.css +2490 -51
  452. package/src/styles/image-edit-affordance.css +201 -0
  453. package/src/styles/index.css +10 -0
  454. package/src/tiptap/TiptapAudio.tsx +86 -0
  455. package/src/tiptap/TiptapVideo.tsx +119 -0
  456. package/src/tiptap/useResolvedMediaSrc.ts +47 -0
  457. package/src/tiptapBridge.ts +227 -22
  458. package/src/useHeadingLayout.ts +294 -0
  459. package/src/utils/collectInlineFontAwesomeCss.ts +69 -0
  460. package/src/utils/dropUtils.ts +54 -6
  461. package/src/utils/normalizeMalformedAssetUrl.ts +22 -0
@@ -0,0 +1,332 @@
1
+ /**
2
+ * EmojiPicker
3
+ *
4
+ * Toolbar-anchored popover for inserting emoji. The user picks a
5
+ * category from a row of tabs along the top, sees a scrollable grid
6
+ * for that category, and can type into a search box to narrow across
7
+ * all categories at once. Click → `onSelect(char)` → caller is
8
+ * responsible for routing the character into the active editor.
9
+ *
10
+ * Keeps the data flat and the rendering simple: there's no fuzzy
11
+ * search, no recently-used persistence, no skin-tone modifiers — just
12
+ * a fast, predictable picker. We can layer those on later without
13
+ * changing the public surface.
14
+ */
15
+
16
+ import { useEffect, useMemo, useRef, useState } from 'react';
17
+ import type { CSSProperties } from 'react';
18
+ import { PICKER_CATEGORIES, searchPickerEntries } from './emojiData';
19
+ import type { PickerEntry } from './emojiData';
20
+
21
+ export interface EmojiPickerProps {
22
+ /** Whether the picker is visible. */
23
+ open: boolean;
24
+ /**
25
+ * Fired when the user picks an entry. Carries either an emoji glyph
26
+ * or a FontAwesome icon descriptor — the caller dispatches on
27
+ * `kind` to insert it into the active editor. The caller is also
28
+ * responsible for closing the popover.
29
+ */
30
+ onSelect: (entry: PickerEntry) => void;
31
+ /** Fired on Escape, click-outside, or selection so the caller can close. */
32
+ onClose: () => void;
33
+ /** Optional anchor element — used for click-outside detection. When the
34
+ * popover is rendered inside the same container as the trigger, pointer
35
+ * events on the trigger don't fire the outside handler. */
36
+ anchorRef?: React.RefObject<HTMLElement>;
37
+ /** Optional CSS class for the popover root. */
38
+ className?: string;
39
+ /** Optional inline style for the popover root (e.g. positioning). */
40
+ style?: CSSProperties;
41
+ /**
42
+ * Editor theme — `'light'` or `'dark'`. Drives the picker's color
43
+ * palette. Required for the picker to render correctly when portaled
44
+ * outside the editor shell, since CSS custom properties defined on
45
+ * the shell don't cascade to portal targets. Defaults to `'light'`.
46
+ */
47
+ theme?: 'light' | 'dark';
48
+ }
49
+
50
+ interface PickerPalette {
51
+ bg: string;
52
+ border: string;
53
+ inputBg: string;
54
+ text: string;
55
+ textMuted: string;
56
+ accent: string;
57
+ accentSoft: string;
58
+ }
59
+
60
+ const LIGHT_PALETTE: PickerPalette = {
61
+ bg: '#fff',
62
+ border: '#d4cdb5',
63
+ inputBg: '#fff',
64
+ text: '#1f2937',
65
+ textMuted: '#8a7a5a',
66
+ accent: '#8B6914',
67
+ accentSoft: '#f3eedb',
68
+ };
69
+
70
+ const DARK_PALETTE: PickerPalette = {
71
+ bg: '#1f2937',
72
+ border: '#4b5563',
73
+ inputBg: '#374151',
74
+ text: '#e5e7eb',
75
+ textMuted: '#9ca3af',
76
+ accent: '#fbbf24',
77
+ accentSoft: '#374151',
78
+ };
79
+
80
+ /** Default popover dimensions. The Toolbar reads these to position the
81
+ * popover with viewport-aware clamping so it never gets clipped. */
82
+ export const EMOJI_PICKER_WIDTH = 480;
83
+ export const EMOJI_PICKER_MAX_HEIGHT = 560;
84
+
85
+ function buildPopoverStyle(palette: PickerPalette): CSSProperties {
86
+ return {
87
+ position: 'absolute',
88
+ zIndex: 100,
89
+ background: palette.bg,
90
+ border: `1px solid ${palette.border}`,
91
+ borderRadius: 6,
92
+ // Dark mode needs a deeper shadow than the light palette uses,
93
+ // because the popover sits on a dark surface where a soft 15%
94
+ // shadow effectively disappears.
95
+ boxShadow:
96
+ palette === DARK_PALETTE ? '0 8px 32px rgba(0, 0, 0, 0.5)' : '0 6px 24px rgba(0, 0, 0, 0.15)',
97
+ color: palette.text,
98
+ width: EMOJI_PICKER_WIDTH,
99
+ maxWidth: '95vw',
100
+ maxHeight: EMOJI_PICKER_MAX_HEIGHT,
101
+ display: 'flex',
102
+ flexDirection: 'column',
103
+ overflow: 'hidden',
104
+ };
105
+ }
106
+
107
+ export function EmojiPicker({
108
+ open,
109
+ onSelect,
110
+ onClose,
111
+ anchorRef,
112
+ className,
113
+ style,
114
+ theme = 'light',
115
+ }: EmojiPickerProps) {
116
+ const palette = theme === 'dark' ? DARK_PALETTE : LIGHT_PALETTE;
117
+ const [activeCategory, setActiveCategory] = useState<string>(PICKER_CATEGORIES[0].id);
118
+ const [query, setQuery] = useState('');
119
+ const popoverRef = useRef<HTMLDivElement>(null);
120
+ const searchInputRef = useRef<HTMLInputElement>(null);
121
+
122
+ // Focus the search box when the popover opens; reset query when it
123
+ // closes so the next open starts fresh.
124
+ useEffect(() => {
125
+ if (open) {
126
+ // Defer so the input is mounted.
127
+ const t = setTimeout(() => searchInputRef.current?.focus(), 0);
128
+ return () => clearTimeout(t);
129
+ }
130
+ setQuery('');
131
+ setActiveCategory(PICKER_CATEGORIES[0].id);
132
+ return undefined;
133
+ }, [open]);
134
+
135
+ // Close on outside click and Escape.
136
+ useEffect(() => {
137
+ if (!open) return;
138
+ const onPointerDown = (e: MouseEvent) => {
139
+ const target = e.target as Node | null;
140
+ if (!target) return;
141
+ if (popoverRef.current?.contains(target)) return;
142
+ if (anchorRef?.current?.contains(target)) return;
143
+ onClose();
144
+ };
145
+ const onKey = (e: KeyboardEvent) => {
146
+ if (e.key === 'Escape') onClose();
147
+ };
148
+ document.addEventListener('mousedown', onPointerDown);
149
+ document.addEventListener('keydown', onKey);
150
+ return () => {
151
+ document.removeEventListener('mousedown', onPointerDown);
152
+ document.removeEventListener('keydown', onKey);
153
+ };
154
+ }, [open, onClose, anchorRef]);
155
+
156
+ const visibleEntries = useMemo<PickerEntry[]>(() => {
157
+ if (query.trim()) return searchPickerEntries(query);
158
+ const cat = PICKER_CATEGORIES.find((c) => c.id === activeCategory);
159
+ return cat ? cat.entries : [];
160
+ }, [query, activeCategory]);
161
+
162
+ if (!open) return null;
163
+
164
+ return (
165
+ <div
166
+ ref={popoverRef}
167
+ className={`squisq-emoji-picker ${className ?? ''}`}
168
+ data-theme={theme}
169
+ style={{ ...buildPopoverStyle(palette), ...style }}
170
+ role="dialog"
171
+ aria-label="Insert emoji"
172
+ data-testid="emoji-picker"
173
+ >
174
+ {/* Search */}
175
+ <div
176
+ style={{
177
+ padding: '8px 10px',
178
+ borderBottom: `1px solid ${palette.border}`,
179
+ }}
180
+ >
181
+ <input
182
+ ref={searchInputRef}
183
+ type="text"
184
+ value={query}
185
+ onChange={(e) => setQuery(e.target.value)}
186
+ placeholder="Search emoji & icons…"
187
+ aria-label="Search emoji & icons"
188
+ style={{
189
+ width: '100%',
190
+ padding: '6px 8px',
191
+ fontSize: 13,
192
+ fontFamily: 'inherit',
193
+ border: `1px solid ${palette.border}`,
194
+ borderRadius: 4,
195
+ background: palette.inputBg,
196
+ color: palette.text,
197
+ boxSizing: 'border-box',
198
+ }}
199
+ />
200
+ </div>
201
+
202
+ {/* Category tabs — hidden when a search is active because the grid
203
+ collapses across categories.
204
+
205
+ Two-row grid layout: with 9 emoji buckets + 3 FA families we'd
206
+ otherwise need a horizontal scrollbar to fit them all in the
207
+ 480px-wide picker, and the scrollbar visually obscures the
208
+ tabs themselves. A 6-column grid gives exactly two even rows
209
+ that always fit without scrolling. */}
210
+ {!query.trim() && (
211
+ <div
212
+ role="tablist"
213
+ aria-label="Emoji & icon categories"
214
+ style={{
215
+ display: 'grid',
216
+ gridTemplateColumns: 'repeat(6, 1fr)',
217
+ gap: 2,
218
+ padding: '4px 6px',
219
+ borderBottom: `1px solid ${palette.border}`,
220
+ }}
221
+ >
222
+ {PICKER_CATEGORIES.map((cat) => {
223
+ const active = cat.id === activeCategory;
224
+ return (
225
+ <button
226
+ key={cat.id}
227
+ type="button"
228
+ role="tab"
229
+ aria-selected={active}
230
+ aria-label={cat.label}
231
+ title={cat.label}
232
+ onClick={() => setActiveCategory(cat.id)}
233
+ style={{
234
+ fontSize: 18,
235
+ lineHeight: 1,
236
+ padding: '6px 0',
237
+ cursor: 'pointer',
238
+ background: active ? palette.accentSoft : 'transparent',
239
+ border: '1px solid transparent',
240
+ borderBottom: active ? `2px solid ${palette.accent}` : '2px solid transparent',
241
+ borderRadius: 4,
242
+ color: palette.text,
243
+ display: 'flex',
244
+ alignItems: 'center',
245
+ justifyContent: 'center',
246
+ }}
247
+ >
248
+ {cat.tab.kind === 'emoji' ? (
249
+ cat.tab.char
250
+ ) : (
251
+ <i className={`fa-${cat.tab.family} fa-${cat.tab.name}`} aria-hidden="true" />
252
+ )}
253
+ </button>
254
+ );
255
+ })}
256
+ </div>
257
+ )}
258
+
259
+ {/* Grid — grows to fill the picker. The wrapper's `maxHeight`
260
+ caps the popover overall (set on the root element above), so
261
+ the grid scrolls only when the content doesn't fit. With the
262
+ default sizing (480 wide × 560 tall, 10 columns) the common
263
+ categories fit without a scrollbar at all. */}
264
+ <div
265
+ style={{
266
+ padding: 6,
267
+ flex: 1,
268
+ minHeight: 0,
269
+ overflowY: 'auto',
270
+ display: 'grid',
271
+ gridTemplateColumns: 'repeat(10, 1fr)',
272
+ gap: 2,
273
+ }}
274
+ >
275
+ {visibleEntries.length === 0 ? (
276
+ <div
277
+ style={{
278
+ gridColumn: '1 / -1',
279
+ padding: '20px 8px',
280
+ textAlign: 'center',
281
+ color: palette.textMuted,
282
+ fontSize: 13,
283
+ }}
284
+ >
285
+ {query.trim() ? `No matches for "${query.trim()}"` : 'No entries'}
286
+ </div>
287
+ ) : (
288
+ visibleEntries.map((entry, idx) => {
289
+ const tooltip = entry.kind === 'emoji' ? entry.name : entry.label;
290
+ const key =
291
+ entry.kind === 'emoji' ? `e-${entry.char}-${idx}` : `i-${entry.token}-${idx}`;
292
+ return (
293
+ <button
294
+ key={key}
295
+ type="button"
296
+ title={tooltip}
297
+ aria-label={tooltip}
298
+ data-picker-kind={entry.kind}
299
+ onClick={() => onSelect(entry)}
300
+ style={{
301
+ fontSize: 22,
302
+ lineHeight: 1,
303
+ padding: 4,
304
+ background: 'transparent',
305
+ border: '1px solid transparent',
306
+ borderRadius: 4,
307
+ cursor: 'pointer',
308
+ color: palette.text,
309
+ display: 'flex',
310
+ alignItems: 'center',
311
+ justifyContent: 'center',
312
+ }}
313
+ onMouseEnter={(e) => {
314
+ e.currentTarget.style.background = palette.accentSoft;
315
+ }}
316
+ onMouseLeave={(e) => {
317
+ e.currentTarget.style.background = 'transparent';
318
+ }}
319
+ >
320
+ {entry.kind === 'emoji' ? (
321
+ entry.char
322
+ ) : (
323
+ <i className={`fa-${entry.family} fa-${entry.name}`} aria-hidden="true" />
324
+ )}
325
+ </button>
326
+ );
327
+ })
328
+ )}
329
+ </div>
330
+ </div>
331
+ );
332
+ }
@@ -0,0 +1,327 @@
1
+ /**
2
+ * ImageEditor — top-level shell that wires together the toolbar,
3
+ * canvas surface, layers panel, and properties panel against an
4
+ * `ImageEditDoc` persisted in a sidecar `ContentContainer`.
5
+ *
6
+ * Hosts pass an already-scoped container (typically built with
7
+ * `scopeContainer(parent, basename + '_files')`). On first mount, if
8
+ * the sidecar has no `state.json`, the editor seeds it from
9
+ * `initialSrc` — the source bytes are copied to `assets/source.<ext>`
10
+ * so the doc is portable and round-trips through ZIP serialization.
11
+ *
12
+ * The export pipeline is `state.json` → SVG → raster blob via
13
+ * `exportImageEditDoc` from `@bendyline/squisq/imageEdit`.
14
+ */
15
+
16
+ import { useCallback, useState } from 'react';
17
+ import type { ContentContainer } from '@bendyline/squisq/storage';
18
+ import { exportImageEditDoc, type ImageEditExportFormat } from '@bendyline/squisq/imageEdit';
19
+ import type { SurfaceScheme, Theme } from '@bendyline/squisq/schemas';
20
+ import { CanvasSurface } from './imageEditor/CanvasSurface.js';
21
+ import { ImageVersionHistoryDropdown } from './imageEditor/ImageVersionHistoryDropdown.js';
22
+ import { LayersPanel } from './imageEditor/LayersPanel.js';
23
+ import { PropertiesPanel } from './imageEditor/PropertiesPanel.js';
24
+ import { Toolbar } from './imageEditor/Toolbar.js';
25
+ import { useImageEditor } from './imageEditor/useImageEditor.js';
26
+ import { useImageEditorTokens } from './imageEditor/useImageEditorTokens.js';
27
+
28
+ export interface ImageEditorProps {
29
+ /**
30
+ * Scoped sidecar container for this image — typically
31
+ * `scopeContainer(parent, basename + '_files')`.
32
+ */
33
+ filesContainer: ContentContainer;
34
+ /**
35
+ * Source URL used to seed `assets/source.<ext>` and layer 0 the
36
+ * first time the sidecar is opened. Ignored once `state.json` exists.
37
+ */
38
+ initialSrc?: string;
39
+ /** Override the state filename. Default: `state.json`. */
40
+ stateFilename?: string;
41
+ /** Enable version-history snapshots in `.versions/`. Default: `false`. */
42
+ allowVersioning?: boolean;
43
+ /** Auto-save idle delay (ms) for version snapshots. Default: `5000`. */
44
+ versioningAutoSaveIdleMs?: number;
45
+ /** Called after the user clicks Export and the blob is produced. */
46
+ onExport?: (blob: Blob, format: ImageEditExportFormat) => void;
47
+ /**
48
+ * What the toolbar's Save button does:
49
+ * - `'flush'` (default): write `state.json` to the sidecar.
50
+ * - `'export'`: rasterize the canvas in `saveFormat` and fire
51
+ * {@link onExport} — the same code path the Export menu uses.
52
+ * Hosts that want one-click "save and close" semantics use this.
53
+ */
54
+ saveBehavior?: 'flush' | 'export';
55
+ /** Format used when `saveBehavior === 'export'`. Default: `'png'`. */
56
+ saveFormat?: ImageEditExportFormat;
57
+ /** Override the Save button label. Default: `'Save'`. */
58
+ saveLabel?: string;
59
+ /** Override the Save button tooltip. */
60
+ saveTitle?: string;
61
+ /**
62
+ * Squisq Theme to color the editor chrome (toolbar, panels, controls).
63
+ * Defaults to `DEFAULT_THEME`. Combined with {@link surface} the same
64
+ * way `<JsonView>` and `<LinearDocView>` do.
65
+ */
66
+ theme?: Theme;
67
+ /**
68
+ * Surface scheme — `LIGHT_SURFACE`, `DARK_SURFACE`, an explicit
69
+ * `SurfaceScheme` object, or `'auto'` to track the user's OS
70
+ * `prefers-color-scheme`. When omitted, the theme's own background is
71
+ * used as-is.
72
+ */
73
+ surface?: SurfaceScheme | 'auto';
74
+ /** Optional className for the root element. */
75
+ className?: string;
76
+ }
77
+
78
+ export function ImageEditor(props: ImageEditorProps) {
79
+ const {
80
+ filesContainer,
81
+ initialSrc,
82
+ stateFilename,
83
+ allowVersioning,
84
+ versioningAutoSaveIdleMs,
85
+ onExport,
86
+ saveBehavior = 'flush',
87
+ saveFormat = 'png',
88
+ saveLabel,
89
+ saveTitle,
90
+ theme,
91
+ surface,
92
+ className,
93
+ } = props;
94
+
95
+ const tokens = useImageEditorTokens(theme, surface);
96
+
97
+ const { state, dispatch, flush, resolveAssetUrl, uploadAsset, versioning, ready, error } =
98
+ useImageEditor({
99
+ container: filesContainer,
100
+ initialSrc,
101
+ stateFilename,
102
+ allowVersioning,
103
+ versioningAutoSaveIdleMs,
104
+ });
105
+
106
+ // Bumped after every save/version write so the history popover
107
+ // re-lists without polling.
108
+ const [historyRefreshKey, setHistoryRefreshKey] = useState(0);
109
+
110
+ const handleExport = useCallback(
111
+ async (format: ImageEditExportFormat) => {
112
+ if (!state) return;
113
+ try {
114
+ const blob = await exportImageEditDoc(state.doc, filesContainer, { format });
115
+ if (onExport) {
116
+ onExport(blob, format);
117
+ } else {
118
+ // Default behavior: trigger a browser download.
119
+ const url = URL.createObjectURL(blob);
120
+ const a = document.createElement('a');
121
+ a.href = url;
122
+ a.download = `image.${format === 'jpeg' ? 'jpg' : format}`;
123
+ document.body.appendChild(a);
124
+ a.click();
125
+ document.body.removeChild(a);
126
+ URL.revokeObjectURL(url);
127
+ }
128
+ } catch (err: unknown) {
129
+ console.warn(
130
+ '[squisq-editor] image export failed:',
131
+ err instanceof Error ? err.message : err,
132
+ );
133
+ }
134
+ },
135
+ [state, filesContainer, onExport],
136
+ );
137
+
138
+ /**
139
+ * Save-and-close pipeline. Critical: we must `await flush()` *before*
140
+ * triggering the export, otherwise the parent modal may close (via the
141
+ * `onExport` chain) before the debounced state.json write fires —
142
+ * losing any layer/edit changes since the last debounce. We also save
143
+ * a version snapshot so the history dropdown captures the moment of
144
+ * save and the user can revert later.
145
+ */
146
+ const handleSaveAndClose = useCallback(async () => {
147
+ try {
148
+ await flush();
149
+ if (versioning) {
150
+ try {
151
+ await versioning.saveVersion();
152
+ setHistoryRefreshKey((k) => k + 1);
153
+ } catch (err: unknown) {
154
+ console.warn(
155
+ '[squisq-editor] image-edit save-version failed:',
156
+ err instanceof Error ? err.message : err,
157
+ );
158
+ }
159
+ }
160
+ await handleExport(saveFormat);
161
+ } catch (err: unknown) {
162
+ console.warn(
163
+ '[squisq-editor] image-edit save-and-close failed:',
164
+ err instanceof Error ? err.message : err,
165
+ );
166
+ }
167
+ }, [flush, versioning, handleExport, saveFormat]);
168
+
169
+ /**
170
+ * Revert `state.json` (and the in-memory editor state) to a prior
171
+ * snapshot. We delegate to `versioning.revertToVersion` so the
172
+ * sidecar write happens through the same code path as direct API
173
+ * use, including a snapshot of the *current* state before overwrite
174
+ * — that way the user can undo a revert via the same dropdown.
175
+ */
176
+ const handleRevertToVersion = useCallback(
177
+ async (version: import('@bendyline/squisq/versions').Version) => {
178
+ if (!versioning) return;
179
+ // Cancel any pending debounced write so it can't clobber the
180
+ // reverted state.json after we replace it.
181
+ try {
182
+ await flush();
183
+ } catch {
184
+ /* swallow — best effort */
185
+ }
186
+ const result = await versioning.revertToVersion(version);
187
+ if (!result.reverted) return;
188
+ const doc = await versioning.readVersion(version);
189
+ if (doc) {
190
+ dispatch({ type: 'load', doc });
191
+ // Bump the history list so the just-saved \"pre-revert\"
192
+ // snapshot shows up in the dropdown.
193
+ setHistoryRefreshKey((k) => k + 1);
194
+ }
195
+ },
196
+ [dispatch, flush, versioning],
197
+ );
198
+
199
+ const handleCreateTextAt = useCallback(
200
+ (x: number, y: number) => {
201
+ dispatch({
202
+ type: 'add-layer',
203
+ layer: {
204
+ type: 'text',
205
+ name: 'Text',
206
+ position: { x: Math.round(x), y: Math.round(y), width: 240, height: 48 },
207
+ content: {
208
+ text: 'New text',
209
+ style: { fontSize: 32, color: '#111111', fontFamily: 'sans-serif' },
210
+ },
211
+ },
212
+ });
213
+ dispatch({ type: 'set-tool', tool: 'select' });
214
+ },
215
+ [dispatch],
216
+ );
217
+
218
+ const handleCreateShapeAt = useCallback(
219
+ (x: number, y: number) => {
220
+ dispatch({
221
+ type: 'add-layer',
222
+ layer: {
223
+ type: 'shape',
224
+ name: 'Rectangle',
225
+ position: {
226
+ x: Math.round(x - 60),
227
+ y: Math.round(y - 40),
228
+ width: 120,
229
+ height: 80,
230
+ },
231
+ content: {
232
+ shape: 'rect',
233
+ fill: '#3399ff',
234
+ stroke: '#1a4d80',
235
+ strokeWidth: 2,
236
+ borderRadius: 8,
237
+ },
238
+ },
239
+ });
240
+ dispatch({ type: 'set-tool', tool: 'select' });
241
+ },
242
+ [dispatch],
243
+ );
244
+
245
+ if (error) {
246
+ return (
247
+ <div
248
+ className={['squisq-image-editor', className].filter(Boolean).join(' ')}
249
+ style={tokens.style}
250
+ >
251
+ <div className="squisq-image-editor-error">
252
+ Failed to load image editor: {error.message}
253
+ </div>
254
+ </div>
255
+ );
256
+ }
257
+
258
+ if (!ready || !state) {
259
+ return (
260
+ <div
261
+ className={['squisq-image-editor', className].filter(Boolean).join(' ')}
262
+ style={tokens.style}
263
+ >
264
+ <div className="squisq-image-editor-loading">Loading image editor…</div>
265
+ </div>
266
+ );
267
+ }
268
+
269
+ return (
270
+ <div
271
+ className={['squisq-image-editor', className].filter(Boolean).join(' ')}
272
+ style={tokens.style}
273
+ data-testid="image-editor"
274
+ >
275
+ <Toolbar
276
+ doc={state.doc}
277
+ tool={state.tool}
278
+ dispatch={dispatch}
279
+ uploadAsset={uploadAsset}
280
+ onExport={handleExport}
281
+ onSave={saveBehavior === 'export' ? handleSaveAndClose : flush}
282
+ saveLabel={saveLabel ?? (saveBehavior === 'export' ? 'Save and close' : 'Save')}
283
+ saveTitle={
284
+ saveTitle ??
285
+ (saveBehavior === 'export'
286
+ ? `Rasterize and save as ${saveFormat.toUpperCase()}`
287
+ : 'Save state.json')
288
+ }
289
+ extraTools={
290
+ versioning ? (
291
+ <ImageVersionHistoryDropdown
292
+ versioning={versioning}
293
+ container={filesContainer}
294
+ onRevert={handleRevertToVersion}
295
+ refreshKey={historyRefreshKey}
296
+ />
297
+ ) : null
298
+ }
299
+ />
300
+ <div className="squisq-image-editor-body">
301
+ <div className="squisq-image-editor-center">
302
+ <CanvasSurface
303
+ doc={state.doc}
304
+ selectedLayerId={state.selectedLayerId}
305
+ tool={state.tool}
306
+ resolveAssetUrl={resolveAssetUrl}
307
+ dispatch={dispatch}
308
+ onCreateTextAt={handleCreateTextAt}
309
+ onCreateShapeAt={handleCreateShapeAt}
310
+ />
311
+ </div>
312
+ <div className="squisq-image-editor-side">
313
+ <LayersPanel
314
+ doc={state.doc}
315
+ selectedLayerId={state.selectedLayerId}
316
+ dispatch={dispatch}
317
+ />
318
+ <PropertiesPanel
319
+ doc={state.doc}
320
+ selectedLayerId={state.selectedLayerId}
321
+ dispatch={dispatch}
322
+ />
323
+ </div>
324
+ </div>
325
+ </div>
326
+ );
327
+ }