@bendyline/squisq-editor-react 1.4.0 → 1.5.1
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.
- package/dist/DocumentSettingsDialog.d.ts +26 -0
- package/dist/DocumentSettingsDialog.d.ts.map +1 -0
- package/dist/DocumentSettingsDialog.js +115 -0
- package/dist/DocumentSettingsDialog.js.map +1 -0
- package/dist/EditorContext.d.ts +248 -4
- package/dist/EditorContext.d.ts.map +1 -1
- package/dist/EditorContext.js +248 -10
- package/dist/EditorContext.js.map +1 -1
- package/dist/EditorShell.d.ts +173 -4
- package/dist/EditorShell.d.ts.map +1 -1
- package/dist/EditorShell.js +110 -10
- package/dist/EditorShell.js.map +1 -1
- package/dist/EmojiPicker.d.ts +50 -0
- package/dist/EmojiPicker.d.ts.map +1 -0
- package/dist/EmojiPicker.js +182 -0
- package/dist/EmojiPicker.js.map +1 -0
- package/dist/ImageEditor.d.ts +68 -0
- package/dist/ImageEditor.d.ts.map +1 -0
- package/dist/ImageEditor.js +166 -0
- package/dist/ImageEditor.js.map +1 -0
- package/dist/ImageNodeView.d.ts +13 -1
- package/dist/ImageNodeView.d.ts.map +1 -1
- package/dist/ImageNodeView.js +172 -19
- package/dist/ImageNodeView.js.map +1 -1
- package/dist/ImageViewer.d.ts +26 -0
- package/dist/ImageViewer.d.ts.map +1 -0
- package/dist/ImageViewer.js +119 -0
- package/dist/ImageViewer.js.map +1 -0
- package/dist/InlineIcon.d.ts +17 -0
- package/dist/InlineIcon.d.ts.map +1 -0
- package/dist/InlineIcon.js +72 -0
- package/dist/InlineIcon.js.map +1 -0
- package/dist/InlinePreviewGutter.d.ts +52 -0
- package/dist/InlinePreviewGutter.d.ts.map +1 -0
- package/dist/InlinePreviewGutter.js +397 -0
- package/dist/InlinePreviewGutter.js.map +1 -0
- package/dist/LinkDialog.d.ts +43 -0
- package/dist/LinkDialog.d.ts.map +1 -0
- package/dist/LinkDialog.js +102 -0
- package/dist/LinkDialog.js.map +1 -0
- package/dist/MentionExtension.js +10 -7
- package/dist/MentionExtension.js.map +1 -1
- package/dist/OutlinePanel.d.ts +17 -0
- package/dist/OutlinePanel.d.ts.map +1 -0
- package/dist/OutlinePanel.js +167 -0
- package/dist/OutlinePanel.js.map +1 -0
- package/dist/PlainHtmlPreview.d.ts +50 -0
- package/dist/PlainHtmlPreview.d.ts.map +1 -0
- package/dist/PlainHtmlPreview.js +155 -0
- package/dist/PlainHtmlPreview.js.map +1 -0
- package/dist/PreviewControls.d.ts +15 -1
- package/dist/PreviewControls.d.ts.map +1 -1
- package/dist/PreviewControls.js +75 -18
- package/dist/PreviewControls.js.map +1 -1
- package/dist/PreviewPanel.d.ts +11 -10
- package/dist/PreviewPanel.d.ts.map +1 -1
- package/dist/PreviewPanel.js +20 -17
- package/dist/PreviewPanel.js.map +1 -1
- package/dist/RawEditor.d.ts.map +1 -1
- package/dist/RawEditor.js +198 -4
- package/dist/RawEditor.js.map +1 -1
- package/dist/RecorderEntry.d.ts +24 -0
- package/dist/RecorderEntry.d.ts.map +1 -0
- package/dist/RecorderEntry.js +139 -0
- package/dist/RecorderEntry.js.map +1 -0
- package/dist/TemplateAnnotation.d.ts.map +1 -1
- package/dist/TemplateAnnotation.js +32 -6
- package/dist/TemplateAnnotation.js.map +1 -1
- package/dist/TemplatePicker.d.ts +53 -0
- package/dist/TemplatePicker.d.ts.map +1 -0
- package/dist/TemplatePicker.js +388 -0
- package/dist/TemplatePicker.js.map +1 -0
- package/dist/ThemeCustomizerPanel.d.ts +32 -0
- package/dist/ThemeCustomizerPanel.d.ts.map +1 -0
- package/dist/ThemeCustomizerPanel.js +256 -0
- package/dist/ThemeCustomizerPanel.js.map +1 -0
- package/dist/ThemePicker.d.ts +33 -0
- package/dist/ThemePicker.d.ts.map +1 -0
- package/dist/ThemePicker.js +148 -0
- package/dist/ThemePicker.js.map +1 -0
- package/dist/Toolbar.d.ts.map +1 -1
- package/dist/Toolbar.js +508 -33
- package/dist/Toolbar.js.map +1 -1
- package/dist/VersionHistoryPanel.d.ts +14 -0
- package/dist/VersionHistoryPanel.d.ts.map +1 -0
- package/dist/VersionHistoryPanel.js +147 -0
- package/dist/VersionHistoryPanel.js.map +1 -0
- package/dist/ViewMenuPanel.d.ts +13 -0
- package/dist/ViewMenuPanel.d.ts.map +1 -0
- package/dist/ViewMenuPanel.js +58 -0
- package/dist/ViewMenuPanel.js.map +1 -0
- package/dist/WysiwygEditor.d.ts.map +1 -1
- package/dist/WysiwygEditor.js +198 -9
- package/dist/WysiwygEditor.js.map +1 -1
- package/dist/__tests__/detectMarkdown.test.js +0 -14
- package/dist/__tests__/detectMarkdown.test.js.map +1 -1
- package/dist/__tests__/documentSettingsDialog.test.d.ts +2 -0
- package/dist/__tests__/documentSettingsDialog.test.d.ts.map +1 -0
- package/dist/__tests__/documentSettingsDialog.test.js +132 -0
- package/dist/__tests__/documentSettingsDialog.test.js.map +1 -0
- package/dist/__tests__/emojiPicker.test.d.ts +2 -0
- package/dist/__tests__/emojiPicker.test.d.ts.map +1 -0
- package/dist/__tests__/emojiPicker.test.js +111 -0
- package/dist/__tests__/emojiPicker.test.js.map +1 -0
- package/dist/__tests__/fileKind.test.js +13 -0
- package/dist/__tests__/fileKind.test.js.map +1 -1
- package/dist/__tests__/imageEditAffordance.test.d.ts +2 -0
- package/dist/__tests__/imageEditAffordance.test.d.ts.map +1 -0
- package/dist/__tests__/imageEditAffordance.test.js +188 -0
- package/dist/__tests__/imageEditAffordance.test.js.map +1 -0
- package/dist/__tests__/imageEditorShell.test.d.ts +2 -0
- package/dist/__tests__/imageEditorShell.test.d.ts.map +1 -0
- package/dist/__tests__/imageEditorShell.test.js +52 -0
- package/dist/__tests__/imageEditorShell.test.js.map +1 -0
- package/dist/__tests__/imageEditorState.test.d.ts +3 -0
- package/dist/__tests__/imageEditorState.test.d.ts.map +1 -0
- package/dist/__tests__/imageEditorState.test.js +148 -0
- package/dist/__tests__/imageEditorState.test.js.map +1 -0
- package/dist/__tests__/inlinePreviewGutter.test.d.ts +2 -0
- package/dist/__tests__/inlinePreviewGutter.test.d.ts.map +1 -0
- package/dist/__tests__/inlinePreviewGutter.test.js +51 -0
- package/dist/__tests__/inlinePreviewGutter.test.js.map +1 -0
- package/dist/__tests__/inlinePreviewGutterAllBlocks.test.d.ts +2 -0
- package/dist/__tests__/inlinePreviewGutterAllBlocks.test.d.ts.map +1 -0
- package/dist/__tests__/inlinePreviewGutterAllBlocks.test.js +63 -0
- package/dist/__tests__/inlinePreviewGutterAllBlocks.test.js.map +1 -0
- package/dist/__tests__/jsonEditor.test.d.ts +2 -0
- package/dist/__tests__/jsonEditor.test.d.ts.map +1 -0
- package/dist/__tests__/jsonEditor.test.js +134 -0
- package/dist/__tests__/jsonEditor.test.js.map +1 -0
- package/dist/__tests__/layersPanel.test.d.ts +2 -0
- package/dist/__tests__/layersPanel.test.d.ts.map +1 -0
- package/dist/__tests__/layersPanel.test.js +84 -0
- package/dist/__tests__/layersPanel.test.js.map +1 -0
- package/dist/__tests__/linkDialogDocPicker.test.d.ts +7 -0
- package/dist/__tests__/linkDialogDocPicker.test.d.ts.map +1 -0
- package/dist/__tests__/linkDialogDocPicker.test.js +75 -0
- package/dist/__tests__/linkDialogDocPicker.test.js.map +1 -0
- package/dist/__tests__/outlinePanel.test.d.ts +2 -0
- package/dist/__tests__/outlinePanel.test.d.ts.map +1 -0
- package/dist/__tests__/outlinePanel.test.js +68 -0
- package/dist/__tests__/outlinePanel.test.js.map +1 -0
- package/dist/__tests__/plainHtmlPreview.test.d.ts +2 -0
- package/dist/__tests__/plainHtmlPreview.test.d.ts.map +1 -0
- package/dist/__tests__/plainHtmlPreview.test.js +87 -0
- package/dist/__tests__/plainHtmlPreview.test.js.map +1 -0
- package/dist/__tests__/propertiesPanel.test.d.ts +2 -0
- package/dist/__tests__/propertiesPanel.test.d.ts.map +1 -0
- package/dist/__tests__/propertiesPanel.test.js +64 -0
- package/dist/__tests__/propertiesPanel.test.js.map +1 -0
- package/dist/__tests__/recorderFormats.test.d.ts +2 -0
- package/dist/__tests__/recorderFormats.test.d.ts.map +1 -0
- package/dist/__tests__/recorderFormats.test.js +121 -0
- package/dist/__tests__/recorderFormats.test.js.map +1 -0
- package/dist/__tests__/recorderTimingJson.test.d.ts +2 -0
- package/dist/__tests__/recorderTimingJson.test.d.ts.map +1 -0
- package/dist/__tests__/recorderTimingJson.test.js +37 -0
- package/dist/__tests__/recorderTimingJson.test.js.map +1 -0
- package/dist/__tests__/templateAnnotationRoundTrip.test.d.ts +2 -0
- package/dist/__tests__/templateAnnotationRoundTrip.test.d.ts.map +1 -0
- package/dist/__tests__/templateAnnotationRoundTrip.test.js +31 -0
- package/dist/__tests__/templateAnnotationRoundTrip.test.js.map +1 -0
- package/dist/__tests__/tiptapBridge.test.js +13 -0
- package/dist/__tests__/tiptapBridge.test.js.map +1 -1
- package/dist/__tests__/useImageEditor.test.d.ts +2 -0
- package/dist/__tests__/useImageEditor.test.d.ts.map +1 -0
- package/dist/__tests__/useImageEditor.test.js +131 -0
- package/dist/__tests__/useImageEditor.test.js.map +1 -0
- package/dist/__tests__/useMediaRecorder.test.d.ts +2 -0
- package/dist/__tests__/useMediaRecorder.test.d.ts.map +1 -0
- package/dist/__tests__/useMediaRecorder.test.js +153 -0
- package/dist/__tests__/useMediaRecorder.test.js.map +1 -0
- package/dist/__tests__/versionHistory.test.d.ts +2 -0
- package/dist/__tests__/versionHistory.test.d.ts.map +1 -0
- package/dist/__tests__/versionHistory.test.js +124 -0
- package/dist/__tests__/versionHistory.test.js.map +1 -0
- package/dist/blockSlice.d.ts +24 -0
- package/dist/blockSlice.d.ts.map +1 -0
- package/dist/blockSlice.js +63 -0
- package/dist/blockSlice.js.map +1 -0
- package/dist/buildPreviewDoc.d.ts.map +1 -1
- package/dist/buildPreviewDoc.js +52 -2
- package/dist/buildPreviewDoc.js.map +1 -1
- package/dist/emojiData.d.ts +81 -0
- package/dist/emojiData.d.ts.map +1 -0
- package/dist/emojiData.js +1283 -0
- package/dist/emojiData.js.map +1 -0
- package/dist/fileKind.d.ts +6 -2
- package/dist/fileKind.d.ts.map +1 -1
- package/dist/fileKind.js +25 -4
- package/dist/fileKind.js.map +1 -1
- package/dist/hooks/useFileDrop.d.ts.map +1 -1
- package/dist/hooks/useFileDrop.js +40 -4
- package/dist/hooks/useFileDrop.js.map +1 -1
- package/dist/imageEditor/CanvasSurface.d.ts +31 -0
- package/dist/imageEditor/CanvasSurface.d.ts.map +1 -0
- package/dist/imageEditor/CanvasSurface.js +264 -0
- package/dist/imageEditor/CanvasSurface.js.map +1 -0
- package/dist/imageEditor/ImageVersionHistoryDropdown.d.ts +39 -0
- package/dist/imageEditor/ImageVersionHistoryDropdown.d.ts.map +1 -0
- package/dist/imageEditor/ImageVersionHistoryDropdown.js +283 -0
- package/dist/imageEditor/ImageVersionHistoryDropdown.js.map +1 -0
- package/dist/imageEditor/LayersPanel.d.ts +14 -0
- package/dist/imageEditor/LayersPanel.d.ts.map +1 -0
- package/dist/imageEditor/LayersPanel.js +43 -0
- package/dist/imageEditor/LayersPanel.js.map +1 -0
- package/dist/imageEditor/PropertiesPanel.d.ts +14 -0
- package/dist/imageEditor/PropertiesPanel.d.ts.map +1 -0
- package/dist/imageEditor/PropertiesPanel.js +97 -0
- package/dist/imageEditor/PropertiesPanel.js.map +1 -0
- package/dist/imageEditor/Toolbar.d.ts +30 -0
- package/dist/imageEditor/Toolbar.d.ts.map +1 -0
- package/dist/imageEditor/Toolbar.js +108 -0
- package/dist/imageEditor/Toolbar.js.map +1 -0
- package/dist/imageEditor/icons.d.ts +24 -0
- package/dist/imageEditor/icons.d.ts.map +1 -0
- package/dist/imageEditor/icons.js +45 -0
- package/dist/imageEditor/icons.js.map +1 -0
- package/dist/imageEditor/layers/EditorImageLayer.d.ts +16 -0
- package/dist/imageEditor/layers/EditorImageLayer.d.ts.map +1 -0
- package/dist/imageEditor/layers/EditorImageLayer.js +37 -0
- package/dist/imageEditor/layers/EditorImageLayer.js.map +1 -0
- package/dist/imageEditor/layers/EditorShapeLayer.d.ts +15 -0
- package/dist/imageEditor/layers/EditorShapeLayer.d.ts.map +1 -0
- package/dist/imageEditor/layers/EditorShapeLayer.js +20 -0
- package/dist/imageEditor/layers/EditorShapeLayer.js.map +1 -0
- package/dist/imageEditor/layers/EditorTextLayer.d.ts +18 -0
- package/dist/imageEditor/layers/EditorTextLayer.d.ts.map +1 -0
- package/dist/imageEditor/layers/EditorTextLayer.js +13 -0
- package/dist/imageEditor/layers/EditorTextLayer.js.map +1 -0
- package/dist/imageEditor/layers/SelectionHandles.d.ts +17 -0
- package/dist/imageEditor/layers/SelectionHandles.d.ts.map +1 -0
- package/dist/imageEditor/layers/SelectionHandles.js +19 -0
- package/dist/imageEditor/layers/SelectionHandles.js.map +1 -0
- package/dist/imageEditor/state.d.ts +76 -0
- package/dist/imageEditor/state.d.ts.map +1 -0
- package/dist/imageEditor/state.js +87 -0
- package/dist/imageEditor/state.js.map +1 -0
- package/dist/imageEditor/useImageEditor.d.ts +53 -0
- package/dist/imageEditor/useImageEditor.d.ts.map +1 -0
- package/dist/imageEditor/useImageEditor.js +244 -0
- package/dist/imageEditor/useImageEditor.js.map +1 -0
- package/dist/imageEditor/useImageEditorTokens.d.ts +16 -0
- package/dist/imageEditor/useImageEditorTokens.d.ts.map +1 -0
- package/dist/imageEditor/useImageEditorTokens.js +45 -0
- package/dist/imageEditor/useImageEditorTokens.js.map +1 -0
- package/dist/index.d.ts +48 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -1
- package/dist/jsonEditor/EmbeddedRichTextField.d.ts +15 -0
- package/dist/jsonEditor/EmbeddedRichTextField.d.ts.map +1 -0
- package/dist/jsonEditor/EmbeddedRichTextField.js +74 -0
- package/dist/jsonEditor/EmbeddedRichTextField.js.map +1 -0
- package/dist/jsonEditor/JsonEditor.d.ts +36 -0
- package/dist/jsonEditor/JsonEditor.d.ts.map +1 -0
- package/dist/jsonEditor/JsonEditor.js +15 -0
- package/dist/jsonEditor/JsonEditor.js.map +1 -0
- package/dist/jsonEditor/JsonEditorContext.d.ts +28 -0
- package/dist/jsonEditor/JsonEditorContext.d.ts.map +1 -0
- package/dist/jsonEditor/JsonEditorContext.js +41 -0
- package/dist/jsonEditor/JsonEditorContext.js.map +1 -0
- package/dist/jsonEditor/RenderNode.d.ts +16 -0
- package/dist/jsonEditor/RenderNode.d.ts.map +1 -0
- package/dist/jsonEditor/RenderNode.js +32 -0
- package/dist/jsonEditor/RenderNode.js.map +1 -0
- package/dist/jsonEditor/editors.d.ts +36 -0
- package/dist/jsonEditor/editors.d.ts.map +1 -0
- package/dist/jsonEditor/editors.js +347 -0
- package/dist/jsonEditor/editors.js.map +1 -0
- package/dist/jsonEditor/index.d.ts +3 -0
- package/dist/jsonEditor/index.d.ts.map +1 -0
- package/dist/jsonEditor/index.js +2 -0
- package/dist/jsonEditor/index.js.map +1 -0
- package/dist/jsonEditor/useJsonEditorTokens.d.ts +13 -0
- package/dist/jsonEditor/useJsonEditorTokens.d.ts.map +1 -0
- package/dist/jsonEditor/useJsonEditorTokens.js +38 -0
- package/dist/jsonEditor/useJsonEditorTokens.js.map +1 -0
- package/dist/recorder/RecorderButton.d.ts +31 -0
- package/dist/recorder/RecorderButton.d.ts.map +1 -0
- package/dist/recorder/RecorderButton.js +24 -0
- package/dist/recorder/RecorderButton.js.map +1 -0
- package/dist/recorder/RecorderModal.d.ts +59 -0
- package/dist/recorder/RecorderModal.d.ts.map +1 -0
- package/dist/recorder/RecorderModal.js +333 -0
- package/dist/recorder/RecorderModal.js.map +1 -0
- package/dist/recorder/RecorderPanel.d.ts +25 -0
- package/dist/recorder/RecorderPanel.d.ts.map +1 -0
- package/dist/recorder/RecorderPanel.js +30 -0
- package/dist/recorder/RecorderPanel.js.map +1 -0
- package/dist/recorder/formats.d.ts +51 -0
- package/dist/recorder/formats.d.ts.map +1 -0
- package/dist/recorder/formats.js +144 -0
- package/dist/recorder/formats.js.map +1 -0
- package/dist/recorder/hooks/useMediaRecorder.d.ts +90 -0
- package/dist/recorder/hooks/useMediaRecorder.d.ts.map +1 -0
- package/dist/recorder/hooks/useMediaRecorder.js +277 -0
- package/dist/recorder/hooks/useMediaRecorder.js.map +1 -0
- package/dist/recorder/hooks/useStreamPreview.d.ts +22 -0
- package/dist/recorder/hooks/useStreamPreview.d.ts.map +1 -0
- package/dist/recorder/hooks/useStreamPreview.js +44 -0
- package/dist/recorder/hooks/useStreamPreview.js.map +1 -0
- package/dist/recorder/sources/cameraStream.d.ts +22 -0
- package/dist/recorder/sources/cameraStream.d.ts.map +1 -0
- package/dist/recorder/sources/cameraStream.js +24 -0
- package/dist/recorder/sources/cameraStream.js.map +1 -0
- package/dist/recorder/sources/micStream.d.ts +15 -0
- package/dist/recorder/sources/micStream.d.ts.map +1 -0
- package/dist/recorder/sources/micStream.js +24 -0
- package/dist/recorder/sources/micStream.js.map +1 -0
- package/dist/recorder/sources/screenStream.d.ts +53 -0
- package/dist/recorder/sources/screenStream.d.ts.map +1 -0
- package/dist/recorder/sources/screenStream.js +114 -0
- package/dist/recorder/sources/screenStream.js.map +1 -0
- package/dist/recorder/timingJson.d.ts +51 -0
- package/dist/recorder/timingJson.d.ts.map +1 -0
- package/dist/recorder/timingJson.js +42 -0
- package/dist/recorder/timingJson.js.map +1 -0
- package/dist/tiptap/TiptapAudio.d.ts +26 -0
- package/dist/tiptap/TiptapAudio.d.ts.map +1 -0
- package/dist/tiptap/TiptapAudio.js +58 -0
- package/dist/tiptap/TiptapAudio.js.map +1 -0
- package/dist/tiptap/TiptapVideo.d.ts +30 -0
- package/dist/tiptap/TiptapVideo.d.ts.map +1 -0
- package/dist/tiptap/TiptapVideo.js +66 -0
- package/dist/tiptap/TiptapVideo.js.map +1 -0
- package/dist/tiptap/useResolvedMediaSrc.d.ts +2 -0
- package/dist/tiptap/useResolvedMediaSrc.d.ts.map +1 -0
- package/dist/tiptap/useResolvedMediaSrc.js +42 -0
- package/dist/tiptap/useResolvedMediaSrc.js.map +1 -0
- package/dist/tiptapBridge.d.ts.map +1 -1
- package/dist/tiptapBridge.js +171 -14
- package/dist/tiptapBridge.js.map +1 -1
- package/dist/useHeadingLayout.d.ts +54 -0
- package/dist/useHeadingLayout.d.ts.map +1 -0
- package/dist/useHeadingLayout.js +260 -0
- package/dist/useHeadingLayout.js.map +1 -0
- package/dist/utils/collectInlineFontAwesomeCss.d.ts +21 -0
- package/dist/utils/collectInlineFontAwesomeCss.d.ts.map +1 -0
- package/dist/utils/collectInlineFontAwesomeCss.js +68 -0
- package/dist/utils/collectInlineFontAwesomeCss.js.map +1 -0
- package/dist/utils/dropUtils.d.ts +21 -2
- package/dist/utils/dropUtils.d.ts.map +1 -1
- package/dist/utils/dropUtils.js +43 -4
- package/dist/utils/dropUtils.js.map +1 -1
- package/dist/utils/normalizeMalformedAssetUrl.d.ts +15 -0
- package/dist/utils/normalizeMalformedAssetUrl.d.ts.map +1 -0
- package/dist/utils/normalizeMalformedAssetUrl.js +27 -0
- package/dist/utils/normalizeMalformedAssetUrl.js.map +1 -0
- package/package.json +8 -5
- package/src/DocumentSettingsDialog.tsx +266 -0
- package/src/EditorContext.tsx +534 -10
- package/src/EditorShell.tsx +571 -55
- package/src/EmojiPicker.tsx +332 -0
- package/src/ImageEditor.tsx +327 -0
- package/src/ImageNodeView.tsx +222 -21
- package/src/ImageViewer.tsx +221 -0
- package/src/InlineIcon.ts +84 -0
- package/src/InlinePreviewGutter.tsx +582 -0
- package/src/LinkDialog.tsx +276 -0
- package/src/MentionExtension.tsx +10 -7
- package/src/OutlinePanel.tsx +295 -0
- package/src/PlainHtmlPreview.tsx +211 -0
- package/src/PreviewControls.tsx +130 -24
- package/src/PreviewPanel.tsx +38 -21
- package/src/RawEditor.tsx +215 -4
- package/src/RecorderEntry.tsx +164 -0
- package/src/TemplateAnnotation.ts +32 -6
- package/src/TemplatePicker.tsx +818 -0
- package/src/ThemeCustomizerPanel.tsx +595 -0
- package/src/ThemePicker.tsx +319 -0
- package/src/Toolbar.tsx +708 -111
- package/src/VersionHistoryPanel.tsx +329 -0
- package/src/ViewMenuPanel.tsx +188 -0
- package/src/WysiwygEditor.tsx +229 -9
- package/src/__tests__/detectMarkdown.test.ts +0 -15
- package/src/__tests__/documentSettingsDialog.test.tsx +147 -0
- package/src/__tests__/emojiPicker.test.tsx +133 -0
- package/src/__tests__/fileKind.test.ts +16 -0
- package/src/__tests__/imageEditAffordance.test.tsx +268 -0
- package/src/__tests__/imageEditorShell.test.tsx +57 -0
- package/src/__tests__/imageEditorState.test.ts +171 -0
- package/src/__tests__/inlinePreviewGutter.test.tsx +62 -0
- package/src/__tests__/inlinePreviewGutterAllBlocks.test.tsx +103 -0
- package/src/__tests__/jsonEditor.test.tsx +168 -0
- package/src/__tests__/layersPanel.test.tsx +97 -0
- package/src/__tests__/linkDialogDocPicker.test.tsx +137 -0
- package/src/__tests__/outlinePanel.test.tsx +79 -0
- package/src/__tests__/plainHtmlPreview.test.tsx +107 -0
- package/src/__tests__/propertiesPanel.test.tsx +69 -0
- package/src/__tests__/recorderFormats.test.ts +146 -0
- package/src/__tests__/recorderTimingJson.test.ts +41 -0
- package/src/__tests__/templateAnnotationRoundTrip.test.ts +34 -0
- package/src/__tests__/tiptapBridge.test.ts +15 -0
- package/src/__tests__/useImageEditor.test.tsx +159 -0
- package/src/__tests__/useMediaRecorder.test.ts +186 -0
- package/src/__tests__/versionHistory.test.tsx +197 -0
- package/src/blockSlice.ts +75 -0
- package/src/buildPreviewDoc.ts +61 -6
- package/src/emojiData.ts +1337 -0
- package/src/fileKind.ts +30 -6
- package/src/hooks/useFileDrop.ts +40 -4
- package/src/imageEditor/CanvasSurface.tsx +402 -0
- package/src/imageEditor/ImageVersionHistoryDropdown.tsx +396 -0
- package/src/imageEditor/LayersPanel.tsx +143 -0
- package/src/imageEditor/PropertiesPanel.tsx +428 -0
- package/src/imageEditor/Toolbar.tsx +242 -0
- package/src/imageEditor/icons.tsx +144 -0
- package/src/imageEditor/image-editor.css +450 -0
- package/src/imageEditor/layers/EditorImageLayer.tsx +45 -0
- package/src/imageEditor/layers/EditorShapeLayer.tsx +62 -0
- package/src/imageEditor/layers/EditorTextLayer.tsx +45 -0
- package/src/imageEditor/layers/SelectionHandles.tsx +86 -0
- package/src/imageEditor/state.ts +153 -0
- package/src/imageEditor/useImageEditor.ts +328 -0
- package/src/imageEditor/useImageEditorTokens.ts +70 -0
- package/src/index.ts +82 -0
- package/src/jsonEditor/EmbeddedRichTextField.tsx +81 -0
- package/src/jsonEditor/JsonEditor.tsx +81 -0
- package/src/jsonEditor/JsonEditorContext.tsx +75 -0
- package/src/jsonEditor/RenderNode.tsx +66 -0
- package/src/jsonEditor/editors.tsx +678 -0
- package/src/jsonEditor/index.ts +2 -0
- package/src/jsonEditor/json-editor.css +463 -0
- package/src/jsonEditor/useJsonEditorTokens.ts +63 -0
- package/src/recorder/RecorderButton.tsx +72 -0
- package/src/recorder/RecorderModal.tsx +596 -0
- package/src/recorder/RecorderPanel.tsx +93 -0
- package/src/recorder/formats.ts +159 -0
- package/src/recorder/hooks/useMediaRecorder.ts +378 -0
- package/src/recorder/hooks/useStreamPreview.ts +47 -0
- package/src/recorder/sources/cameraStream.ts +32 -0
- package/src/recorder/sources/micStream.ts +25 -0
- package/src/recorder/sources/screenStream.ts +162 -0
- package/src/recorder/timingJson.ts +66 -0
- package/src/styles/editor.css +2490 -51
- package/src/styles/image-edit-affordance.css +201 -0
- package/src/styles/index.css +10 -0
- package/src/tiptap/TiptapAudio.tsx +86 -0
- package/src/tiptap/TiptapVideo.tsx +119 -0
- package/src/tiptap/useResolvedMediaSrc.ts +47 -0
- package/src/tiptapBridge.ts +188 -20
- package/src/useHeadingLayout.ts +294 -0
- package/src/utils/collectInlineFontAwesomeCss.ts +69 -0
- package/src/utils/dropUtils.ts +54 -6
- package/src/utils/normalizeMalformedAssetUrl.ts +22 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SVG renderer for an `ImageEditLayer` of kind `text` inside the editor.
|
|
3
|
+
*
|
|
4
|
+
* Multi-line text is laid out as a `<text>` element with one `<tspan>`
|
|
5
|
+
* per line. The first line sits at `y + fontSize` so the visible top
|
|
6
|
+
* of the glyph block aligns with the layer's `y` coordinate (matches
|
|
7
|
+
* what users expect from a top-anchored bounding box).
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { ImageEditCanvas, ImageEditLayer } from '@bendyline/squisq/schemas';
|
|
11
|
+
|
|
12
|
+
interface Props {
|
|
13
|
+
layer: ImageEditLayer & { type: 'text' };
|
|
14
|
+
canvas: ImageEditCanvas;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function EditorTextLayer({ layer, canvas: _canvas }: Props) {
|
|
18
|
+
const p = layer.position;
|
|
19
|
+
const x = typeof p.x === 'number' ? p.x : 0;
|
|
20
|
+
const y = typeof p.y === 'number' ? p.y : 0;
|
|
21
|
+
const { text, style } = layer.content;
|
|
22
|
+
const lineHeight = style.lineHeight ?? 1.4;
|
|
23
|
+
const lineHeightPx = style.fontSize * lineHeight;
|
|
24
|
+
const lines = (text ?? '').split('\n');
|
|
25
|
+
const textAnchor =
|
|
26
|
+
style.textAlign === 'center' ? 'middle' : style.textAlign === 'right' ? 'end' : 'start';
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<text
|
|
30
|
+
x={x}
|
|
31
|
+
y={y + style.fontSize}
|
|
32
|
+
fontFamily={style.fontFamily ?? 'sans-serif'}
|
|
33
|
+
fontSize={style.fontSize}
|
|
34
|
+
fontWeight={style.fontWeight ?? 'normal'}
|
|
35
|
+
fill={style.color}
|
|
36
|
+
textAnchor={textAnchor}
|
|
37
|
+
>
|
|
38
|
+
{lines.map((line, i) => (
|
|
39
|
+
<tspan key={i} x={x} dy={i === 0 ? 0 : lineHeightPx}>
|
|
40
|
+
{line || '\u00A0'}
|
|
41
|
+
</tspan>
|
|
42
|
+
))}
|
|
43
|
+
</text>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SelectionHandles
|
|
3
|
+
*
|
|
4
|
+
* Renders the dashed selection rectangle plus eight resize handles around
|
|
5
|
+
* the currently-selected layer's bounding box. Pointer events on each
|
|
6
|
+
* handle bubble back through `onHandlePointerDown` so the surrounding
|
|
7
|
+
* `<CanvasSurface>` can run its drag loop with the right resize semantics.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { CanvasRect } from '../state.js';
|
|
11
|
+
|
|
12
|
+
export type Handle = 'nw' | 'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w';
|
|
13
|
+
|
|
14
|
+
const HANDLE_SIZE = 10; // canvas-pixel size of each square handle
|
|
15
|
+
|
|
16
|
+
interface Props {
|
|
17
|
+
box: CanvasRect;
|
|
18
|
+
onHandlePointerDown: (e: React.PointerEvent<SVGRectElement>, handle: Handle) => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function SelectionHandles({ box, onHandlePointerDown }: Props) {
|
|
22
|
+
const half = HANDLE_SIZE / 2;
|
|
23
|
+
const cx = box.x + box.width / 2;
|
|
24
|
+
const cy = box.y + box.height / 2;
|
|
25
|
+
|
|
26
|
+
const handles: Array<{ id: Handle; x: number; y: number; cursor: string }> = [
|
|
27
|
+
{ id: 'nw', x: box.x, y: box.y, cursor: 'nwse-resize' },
|
|
28
|
+
{ id: 'n', x: cx, y: box.y, cursor: 'ns-resize' },
|
|
29
|
+
{ id: 'ne', x: box.x + box.width, y: box.y, cursor: 'nesw-resize' },
|
|
30
|
+
{ id: 'e', x: box.x + box.width, y: cy, cursor: 'ew-resize' },
|
|
31
|
+
{ id: 'se', x: box.x + box.width, y: box.y + box.height, cursor: 'nwse-resize' },
|
|
32
|
+
{ id: 's', x: cx, y: box.y + box.height, cursor: 'ns-resize' },
|
|
33
|
+
{ id: 'sw', x: box.x, y: box.y + box.height, cursor: 'nesw-resize' },
|
|
34
|
+
{ id: 'w', x: box.x, y: cy, cursor: 'ew-resize' },
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<g pointerEvents="none">
|
|
39
|
+
{/*
|
|
40
|
+
* Outline: rendered as two stacked rectangles so the selection
|
|
41
|
+
* stays visible over both light and dark imagery. The white
|
|
42
|
+
* "halo" goes underneath; the blue dashed line on top. Both use
|
|
43
|
+
* `vector-effect: non-scaling-stroke` so the stroke width stays
|
|
44
|
+
* crisp at any zoom level (the SVG viewBox is the canvas size,
|
|
45
|
+
* which can be much larger than the rendered element).
|
|
46
|
+
*/}
|
|
47
|
+
<rect
|
|
48
|
+
x={box.x}
|
|
49
|
+
y={box.y}
|
|
50
|
+
width={box.width}
|
|
51
|
+
height={box.height}
|
|
52
|
+
fill="none"
|
|
53
|
+
stroke="#ffffff"
|
|
54
|
+
strokeOpacity={0.9}
|
|
55
|
+
strokeWidth={4}
|
|
56
|
+
vectorEffect="non-scaling-stroke"
|
|
57
|
+
/>
|
|
58
|
+
<rect
|
|
59
|
+
x={box.x}
|
|
60
|
+
y={box.y}
|
|
61
|
+
width={box.width}
|
|
62
|
+
height={box.height}
|
|
63
|
+
fill="none"
|
|
64
|
+
stroke="#39f"
|
|
65
|
+
strokeWidth={2}
|
|
66
|
+
strokeDasharray="6 4"
|
|
67
|
+
vectorEffect="non-scaling-stroke"
|
|
68
|
+
/>
|
|
69
|
+
{handles.map((h) => (
|
|
70
|
+
<rect
|
|
71
|
+
key={h.id}
|
|
72
|
+
x={h.x - half}
|
|
73
|
+
y={h.y - half}
|
|
74
|
+
width={HANDLE_SIZE}
|
|
75
|
+
height={HANDLE_SIZE}
|
|
76
|
+
fill="#fff"
|
|
77
|
+
stroke="#39f"
|
|
78
|
+
strokeWidth={2}
|
|
79
|
+
vectorEffect="non-scaling-stroke"
|
|
80
|
+
style={{ cursor: h.cursor, pointerEvents: 'all' }}
|
|
81
|
+
onPointerDown={(e) => onHandlePointerDown(e, h.id)}
|
|
82
|
+
/>
|
|
83
|
+
))}
|
|
84
|
+
</g>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure state + reducer for the `<ImageEditor>` component.
|
|
3
|
+
*
|
|
4
|
+
* Kept React-free so it's easy to unit-test in isolation. The actual
|
|
5
|
+
* React hook that wires this to a {@link ContentContainer} (and the
|
|
6
|
+
* version manager) lives in `useImageEditor.ts`.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { ImageEditDoc, ImageEditLayer } from '@bendyline/squisq/schemas';
|
|
10
|
+
import {
|
|
11
|
+
addLayer,
|
|
12
|
+
removeLayer,
|
|
13
|
+
reorderLayer,
|
|
14
|
+
setCanvas,
|
|
15
|
+
updateLayer,
|
|
16
|
+
touch,
|
|
17
|
+
} from '@bendyline/squisq/imageEdit';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Layer payload accepted by the `add-layer` action — the `id` field is
|
|
21
|
+
* optional and will be assigned by the underlying `addLayer` helper if
|
|
22
|
+
* the caller doesn't supply one.
|
|
23
|
+
*/
|
|
24
|
+
export type ImageEditLayerInput = ImageEditLayer | (Omit<ImageEditLayer, 'id'> & { id?: string });
|
|
25
|
+
|
|
26
|
+
/** The currently active interaction tool. */
|
|
27
|
+
export type ImageEditorTool = 'select' | 'text' | 'shape' | 'image' | 'crop';
|
|
28
|
+
|
|
29
|
+
/** A pixel-space rectangle in canvas coordinates. */
|
|
30
|
+
export interface CanvasRect {
|
|
31
|
+
x: number;
|
|
32
|
+
y: number;
|
|
33
|
+
width: number;
|
|
34
|
+
height: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface ImageEditorState {
|
|
38
|
+
/** The persisted document. */
|
|
39
|
+
doc: ImageEditDoc;
|
|
40
|
+
/** Selected layer id, or `null` when nothing is selected. */
|
|
41
|
+
selectedLayerId: string | null;
|
|
42
|
+
/** Active tool. */
|
|
43
|
+
tool: ImageEditorTool;
|
|
44
|
+
/**
|
|
45
|
+
* Dirty flag — true when the in-memory doc has unsaved changes
|
|
46
|
+
* relative to the last `markClean()` call. The hook uses this to
|
|
47
|
+
* debounce writes back to `state.json`.
|
|
48
|
+
*/
|
|
49
|
+
dirty: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type ImageEditorAction =
|
|
53
|
+
| { type: 'load'; doc: ImageEditDoc }
|
|
54
|
+
| { type: 'mark-clean' }
|
|
55
|
+
| { type: 'set-tool'; tool: ImageEditorTool }
|
|
56
|
+
| { type: 'select'; layerId: string | null }
|
|
57
|
+
| { type: 'set-canvas'; canvas: ImageEditDoc['canvas'] }
|
|
58
|
+
| { type: 'add-layer'; layer: ImageEditLayerInput; select?: boolean }
|
|
59
|
+
| { type: 'remove-layer'; layerId: string }
|
|
60
|
+
| { type: 'update-layer'; layerId: string; patch: Partial<ImageEditLayer> }
|
|
61
|
+
| { type: 'reorder-layer'; layerId: string; toIndex: number }
|
|
62
|
+
| { type: 'crop'; rect: CanvasRect };
|
|
63
|
+
|
|
64
|
+
/** Build the initial state from a freshly-loaded doc. */
|
|
65
|
+
export function initialImageEditorState(doc: ImageEditDoc): ImageEditorState {
|
|
66
|
+
return {
|
|
67
|
+
doc,
|
|
68
|
+
selectedLayerId: null,
|
|
69
|
+
tool: 'select',
|
|
70
|
+
dirty: false,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function imageEditorReducer(
|
|
75
|
+
state: ImageEditorState,
|
|
76
|
+
action: ImageEditorAction,
|
|
77
|
+
): ImageEditorState {
|
|
78
|
+
switch (action.type) {
|
|
79
|
+
case 'load':
|
|
80
|
+
return { doc: action.doc, selectedLayerId: null, tool: 'select', dirty: false };
|
|
81
|
+
|
|
82
|
+
case 'mark-clean':
|
|
83
|
+
return state.dirty ? { ...state, dirty: false } : state;
|
|
84
|
+
|
|
85
|
+
case 'set-tool':
|
|
86
|
+
return state.tool === action.tool ? state : { ...state, tool: action.tool };
|
|
87
|
+
|
|
88
|
+
case 'select':
|
|
89
|
+
return state.selectedLayerId === action.layerId
|
|
90
|
+
? state
|
|
91
|
+
: { ...state, selectedLayerId: action.layerId };
|
|
92
|
+
|
|
93
|
+
case 'set-canvas': {
|
|
94
|
+
const next = setCanvas(state.doc, action.canvas);
|
|
95
|
+
return next === state.doc ? state : { ...state, doc: next, dirty: true };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
case 'add-layer': {
|
|
99
|
+
// `addLayer` from core assigns an id when missing; cast through
|
|
100
|
+
// `ImageEditLayer` for the existing helper signature.
|
|
101
|
+
const next = addLayer(state.doc, action.layer as ImageEditLayer);
|
|
102
|
+
// Pick up the assigned id (last layer)
|
|
103
|
+
const newId = next.layers[next.layers.length - 1]!.id;
|
|
104
|
+
return {
|
|
105
|
+
...state,
|
|
106
|
+
doc: next,
|
|
107
|
+
dirty: true,
|
|
108
|
+
selectedLayerId: action.select === false ? state.selectedLayerId : newId,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
case 'remove-layer': {
|
|
113
|
+
const next = removeLayer(state.doc, action.layerId);
|
|
114
|
+
if (next === state.doc) return state;
|
|
115
|
+
return {
|
|
116
|
+
...state,
|
|
117
|
+
doc: next,
|
|
118
|
+
dirty: true,
|
|
119
|
+
selectedLayerId: state.selectedLayerId === action.layerId ? null : state.selectedLayerId,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
case 'update-layer': {
|
|
124
|
+
const next = updateLayer(state.doc, action.layerId, action.patch);
|
|
125
|
+
return next === state.doc ? state : { ...state, doc: next, dirty: true };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
case 'reorder-layer': {
|
|
129
|
+
const next = reorderLayer(state.doc, action.layerId, action.toIndex);
|
|
130
|
+
return next === state.doc ? state : { ...state, doc: next, dirty: true };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
case 'crop': {
|
|
134
|
+
const { rect } = action;
|
|
135
|
+
const newCanvas = {
|
|
136
|
+
...state.doc.canvas,
|
|
137
|
+
width: Math.max(1, Math.round(rect.width)),
|
|
138
|
+
height: Math.max(1, Math.round(rect.height)),
|
|
139
|
+
};
|
|
140
|
+
// Translate every layer by (-rect.x, -rect.y). Only handles numeric
|
|
141
|
+
// positions; percentage strings are left alone (rare for image-edit
|
|
142
|
+
// layers, which the editor produces with numeric coords).
|
|
143
|
+
const translated: ImageEditLayer[] = state.doc.layers.map((layer) => {
|
|
144
|
+
const { position } = layer;
|
|
145
|
+
const x = typeof position.x === 'number' ? position.x - rect.x : position.x;
|
|
146
|
+
const y = typeof position.y === 'number' ? position.y - rect.y : position.y;
|
|
147
|
+
return { ...layer, position: { ...position, x, y } } as ImageEditLayer;
|
|
148
|
+
});
|
|
149
|
+
const next = touch({ ...state.doc, canvas: newCanvas, layers: translated });
|
|
150
|
+
return { ...state, doc: next, dirty: true };
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React hook that bundles the image-editor reducer with sidecar
|
|
3
|
+
* persistence, versioning, and an object-URL cache for asset bytes.
|
|
4
|
+
*
|
|
5
|
+
* Hosts pass an already-scoped {@link ContentContainer} (typically built
|
|
6
|
+
* with `scopeContainer(parent, basename + '_files')`); the hook never
|
|
7
|
+
* looks above that root.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { useCallback, useEffect, useMemo, useReducer, useRef, useState } from 'react';
|
|
11
|
+
import type { ContentContainer } from '@bendyline/squisq/storage';
|
|
12
|
+
import type { ImageEditDoc, ImageEditLayer } from '@bendyline/squisq/schemas';
|
|
13
|
+
import {
|
|
14
|
+
IMAGE_EDIT_ASSETS_PREFIX,
|
|
15
|
+
IMAGE_EDIT_STATE_FILENAME,
|
|
16
|
+
ImageEditVersionManager,
|
|
17
|
+
createEmptyImageEditDoc,
|
|
18
|
+
readImageEditDoc,
|
|
19
|
+
writeImageEditDoc,
|
|
20
|
+
} from '@bendyline/squisq/imageEdit';
|
|
21
|
+
import {
|
|
22
|
+
imageEditorReducer,
|
|
23
|
+
initialImageEditorState,
|
|
24
|
+
type ImageEditorAction,
|
|
25
|
+
type ImageEditorState,
|
|
26
|
+
} from './state.js';
|
|
27
|
+
|
|
28
|
+
export interface UseImageEditorOptions {
|
|
29
|
+
/** Sidecar container for the image being edited. */
|
|
30
|
+
container: ContentContainer;
|
|
31
|
+
/**
|
|
32
|
+
* Initial source image URL — used to seed layer 0 when the sidecar has
|
|
33
|
+
* no `state.json` yet. Bytes are fetched and copied into
|
|
34
|
+
* `assets/source.<ext>` so the doc is portable.
|
|
35
|
+
*/
|
|
36
|
+
initialSrc?: string;
|
|
37
|
+
/** Override the state filename. Defaults to `state.json`. */
|
|
38
|
+
stateFilename?: string;
|
|
39
|
+
/** Enable version history. Default: `false`. */
|
|
40
|
+
allowVersioning?: boolean;
|
|
41
|
+
/** Auto-save idle delay (ms). `0` disables. Default: `5000`. */
|
|
42
|
+
versioningAutoSaveIdleMs?: number;
|
|
43
|
+
/** Debounced write delay for state.json (ms). Default: `500`. */
|
|
44
|
+
persistDebounceMs?: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface UseImageEditorReturn {
|
|
48
|
+
/** Current reducer state (or `null` while still loading the initial doc). */
|
|
49
|
+
state: ImageEditorState | null;
|
|
50
|
+
/** Dispatch a reducer action. No-op while loading. */
|
|
51
|
+
dispatch: (action: ImageEditorAction) => void;
|
|
52
|
+
/** Manually trigger a synchronous write of `state.json`. */
|
|
53
|
+
flush: () => Promise<void>;
|
|
54
|
+
/** Resolve an asset path inside the sidecar to a blob URL (cached). */
|
|
55
|
+
resolveAssetUrl: (path: string) => Promise<string>;
|
|
56
|
+
/**
|
|
57
|
+
* Write a new asset (raster image) into `assets/` and return the
|
|
58
|
+
* sidecar-relative path. The caller is then expected to push a layer
|
|
59
|
+
* referencing that path.
|
|
60
|
+
*/
|
|
61
|
+
uploadAsset: (file: Blob, suggestedName?: string) => Promise<string>;
|
|
62
|
+
/** Versioning handle. `null` when `allowVersioning` is false or no container. */
|
|
63
|
+
versioning: ImageEditVersionManager | null;
|
|
64
|
+
/** True after the initial load completes (either an existing doc or seeded). */
|
|
65
|
+
ready: boolean;
|
|
66
|
+
/** Last load / persistence error, if any. */
|
|
67
|
+
error: Error | null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function useImageEditor(options: UseImageEditorOptions): UseImageEditorReturn {
|
|
71
|
+
const {
|
|
72
|
+
container,
|
|
73
|
+
initialSrc,
|
|
74
|
+
stateFilename = IMAGE_EDIT_STATE_FILENAME,
|
|
75
|
+
allowVersioning = false,
|
|
76
|
+
versioningAutoSaveIdleMs = 5000,
|
|
77
|
+
persistDebounceMs = 500,
|
|
78
|
+
} = options;
|
|
79
|
+
|
|
80
|
+
const [state, dispatch] = useReducer(
|
|
81
|
+
(s: ImageEditorState | null, a: ImageEditorAction): ImageEditorState | null => {
|
|
82
|
+
if (s === null) return a.type === 'load' ? initialImageEditorState(a.doc) : null;
|
|
83
|
+
return imageEditorReducer(s, a);
|
|
84
|
+
},
|
|
85
|
+
null,
|
|
86
|
+
);
|
|
87
|
+
const [ready, setReady] = useState(false);
|
|
88
|
+
const [error, setError] = useState<Error | null>(null);
|
|
89
|
+
// Set to true inside the initial-load effect when we just seeded the
|
|
90
|
+
// sidecar (no prior `state.json`). The versioning effect below reads
|
|
91
|
+
// this flag to write an "original" snapshot once the manager exists.
|
|
92
|
+
const seededOnLoadRef = useRef(false);
|
|
93
|
+
|
|
94
|
+
// ── Initial load (or seed from initialSrc) ────────────────────────────
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
let cancelled = false;
|
|
97
|
+
setReady(false);
|
|
98
|
+
setError(null);
|
|
99
|
+
|
|
100
|
+
(async () => {
|
|
101
|
+
try {
|
|
102
|
+
const existing = await readImageEditDoc(container, stateFilename);
|
|
103
|
+
if (cancelled) return;
|
|
104
|
+
if (existing) {
|
|
105
|
+
dispatch({ type: 'load', doc: existing });
|
|
106
|
+
setReady(true);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
// No existing state — seed.
|
|
110
|
+
const seeded = await seedFromSource(container, initialSrc);
|
|
111
|
+
if (cancelled) return;
|
|
112
|
+
await writeImageEditDoc(container, seeded, stateFilename);
|
|
113
|
+
dispatch({ type: 'load', doc: seeded });
|
|
114
|
+
setReady(true);
|
|
115
|
+
// Capture an initial snapshot of the freshly-seeded state so the
|
|
116
|
+
// version history always has an "original" entry the user can
|
|
117
|
+
// revert to after their first edit.
|
|
118
|
+
seededOnLoadRef.current = true;
|
|
119
|
+
} catch (err: unknown) {
|
|
120
|
+
if (cancelled) return;
|
|
121
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
122
|
+
setReady(true);
|
|
123
|
+
}
|
|
124
|
+
})();
|
|
125
|
+
|
|
126
|
+
return () => {
|
|
127
|
+
cancelled = true;
|
|
128
|
+
};
|
|
129
|
+
}, [container, stateFilename, initialSrc]);
|
|
130
|
+
|
|
131
|
+
// ── Debounced persistence of state.json ────────────────────────────────
|
|
132
|
+
const persistTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
133
|
+
const docRef = useRef<ImageEditDoc | null>(null);
|
|
134
|
+
docRef.current = state?.doc ?? null;
|
|
135
|
+
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
if (!state?.dirty) return;
|
|
138
|
+
if (persistTimerRef.current) clearTimeout(persistTimerRef.current);
|
|
139
|
+
persistTimerRef.current = setTimeout(() => {
|
|
140
|
+
const doc = docRef.current;
|
|
141
|
+
if (!doc) return;
|
|
142
|
+
writeImageEditDoc(container, doc, stateFilename)
|
|
143
|
+
.then(() => dispatch({ type: 'mark-clean' }))
|
|
144
|
+
.catch((err: unknown) => {
|
|
145
|
+
console.warn(
|
|
146
|
+
'[squisq-editor] image-edit state persist failed:',
|
|
147
|
+
err instanceof Error ? err.message : err,
|
|
148
|
+
);
|
|
149
|
+
});
|
|
150
|
+
}, persistDebounceMs);
|
|
151
|
+
return () => {
|
|
152
|
+
if (persistTimerRef.current) clearTimeout(persistTimerRef.current);
|
|
153
|
+
};
|
|
154
|
+
}, [state?.dirty, state?.doc, container, stateFilename, persistDebounceMs]);
|
|
155
|
+
|
|
156
|
+
const flush = useCallback(async () => {
|
|
157
|
+
const doc = docRef.current;
|
|
158
|
+
if (!doc) return;
|
|
159
|
+
if (persistTimerRef.current) {
|
|
160
|
+
clearTimeout(persistTimerRef.current);
|
|
161
|
+
persistTimerRef.current = null;
|
|
162
|
+
}
|
|
163
|
+
await writeImageEditDoc(container, doc, stateFilename);
|
|
164
|
+
dispatch({ type: 'mark-clean' });
|
|
165
|
+
}, [container, stateFilename]);
|
|
166
|
+
|
|
167
|
+
// ── Versioning ─────────────────────────────────────────────────────────
|
|
168
|
+
const versioning = useMemo(
|
|
169
|
+
() => (allowVersioning ? new ImageEditVersionManager(container, { stateFilename }) : null),
|
|
170
|
+
[allowVersioning, container, stateFilename],
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
// Drop the "original" snapshot once versioning is wired and we just
|
|
174
|
+
// seeded a fresh sidecar. Guarded by `seededOnLoadRef` so we never
|
|
175
|
+
// duplicate-snapshot on subsequent renders. Uses `force: true` so the
|
|
176
|
+
// initial entry always lands even though no diff has occurred yet.
|
|
177
|
+
useEffect(() => {
|
|
178
|
+
if (!versioning) return;
|
|
179
|
+
if (!ready) return;
|
|
180
|
+
if (!seededOnLoadRef.current) return;
|
|
181
|
+
seededOnLoadRef.current = false;
|
|
182
|
+
versioning.saveVersion({ force: true }).catch((err: unknown) => {
|
|
183
|
+
console.warn(
|
|
184
|
+
'[squisq-editor] image-edit initial snapshot failed:',
|
|
185
|
+
err instanceof Error ? err.message : err,
|
|
186
|
+
);
|
|
187
|
+
});
|
|
188
|
+
}, [versioning, ready]);
|
|
189
|
+
|
|
190
|
+
useEffect(() => {
|
|
191
|
+
if (!versioning) return;
|
|
192
|
+
if (versioningAutoSaveIdleMs <= 0) return;
|
|
193
|
+
if (!state?.doc) return;
|
|
194
|
+
const timer = setTimeout(() => {
|
|
195
|
+
versioning.saveVersion({ doc: docRef.current ?? undefined }).catch((err: unknown) => {
|
|
196
|
+
console.warn(
|
|
197
|
+
'[squisq-editor] image-edit auto-save version failed:',
|
|
198
|
+
err instanceof Error ? err.message : err,
|
|
199
|
+
);
|
|
200
|
+
});
|
|
201
|
+
}, versioningAutoSaveIdleMs);
|
|
202
|
+
return () => clearTimeout(timer);
|
|
203
|
+
}, [versioning, versioningAutoSaveIdleMs, state?.doc]);
|
|
204
|
+
|
|
205
|
+
// ── Asset URL cache ────────────────────────────────────────────────────
|
|
206
|
+
const urlCacheRef = useRef<Map<string, string>>(new Map());
|
|
207
|
+
|
|
208
|
+
const resolveAssetUrl = useCallback(
|
|
209
|
+
async (path: string): Promise<string> => {
|
|
210
|
+
const cache = urlCacheRef.current;
|
|
211
|
+
const cached = cache.get(path);
|
|
212
|
+
if (cached) return cached;
|
|
213
|
+
const data = await container.readFile(path);
|
|
214
|
+
if (!data) throw new Error(`useImageEditor: missing asset "${path}"`);
|
|
215
|
+
const list = await container.listFiles(path);
|
|
216
|
+
const mime = list.find((e) => e.path === path)?.mimeType ?? 'application/octet-stream';
|
|
217
|
+
const url = URL.createObjectURL(new Blob([data], { type: mime }));
|
|
218
|
+
cache.set(path, url);
|
|
219
|
+
return url;
|
|
220
|
+
},
|
|
221
|
+
[container],
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
// Revoke all cached object URLs on unmount / container swap
|
|
225
|
+
useEffect(() => {
|
|
226
|
+
const cache = urlCacheRef.current;
|
|
227
|
+
return () => {
|
|
228
|
+
for (const url of cache.values()) URL.revokeObjectURL(url);
|
|
229
|
+
cache.clear();
|
|
230
|
+
};
|
|
231
|
+
}, [container]);
|
|
232
|
+
|
|
233
|
+
const uploadAsset = useCallback(
|
|
234
|
+
async (file: Blob, suggestedName?: string): Promise<string> => {
|
|
235
|
+
const ext = guessExtensionFromMime(file.type) ?? extensionFromName(suggestedName) ?? 'bin';
|
|
236
|
+
const id = randomId();
|
|
237
|
+
const path = `${IMAGE_EDIT_ASSETS_PREFIX}${id}.${ext}`;
|
|
238
|
+
const buf = await file.arrayBuffer();
|
|
239
|
+
await container.writeFile(path, buf, file.type || undefined);
|
|
240
|
+
return path;
|
|
241
|
+
},
|
|
242
|
+
[container],
|
|
243
|
+
);
|
|
244
|
+
|
|
245
|
+
return {
|
|
246
|
+
state,
|
|
247
|
+
dispatch,
|
|
248
|
+
flush,
|
|
249
|
+
resolveAssetUrl,
|
|
250
|
+
uploadAsset,
|
|
251
|
+
versioning,
|
|
252
|
+
ready,
|
|
253
|
+
error,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// ============================================
|
|
258
|
+
// Helpers
|
|
259
|
+
// ============================================
|
|
260
|
+
|
|
261
|
+
async function seedFromSource(
|
|
262
|
+
container: ContentContainer,
|
|
263
|
+
initialSrc: string | undefined,
|
|
264
|
+
): Promise<ImageEditDoc> {
|
|
265
|
+
if (!initialSrc) {
|
|
266
|
+
return createEmptyImageEditDoc(800, 600);
|
|
267
|
+
}
|
|
268
|
+
// Fetch the source bytes (works for blob:, data:, http(s):, and same-origin
|
|
269
|
+
// relative URLs).
|
|
270
|
+
const resp = await fetch(initialSrc);
|
|
271
|
+
if (!resp.ok) throw new Error(`useImageEditor: failed to fetch initialSrc (${resp.status})`);
|
|
272
|
+
const blob = await resp.blob();
|
|
273
|
+
const ext = guessExtensionFromMime(blob.type) ?? 'png';
|
|
274
|
+
const assetPath = `${IMAGE_EDIT_ASSETS_PREFIX}source.${ext}`;
|
|
275
|
+
await container.writeFile(assetPath, await blob.arrayBuffer(), blob.type || undefined);
|
|
276
|
+
|
|
277
|
+
// Probe natural dimensions by loading into an Image.
|
|
278
|
+
const dims = await probeImageDimensions(initialSrc);
|
|
279
|
+
const w = dims?.width ?? 800;
|
|
280
|
+
const h = dims?.height ?? 600;
|
|
281
|
+
|
|
282
|
+
const layer: ImageEditLayer = {
|
|
283
|
+
id: 'base',
|
|
284
|
+
type: 'image',
|
|
285
|
+
name: 'Background',
|
|
286
|
+
position: { x: 0, y: 0, width: w, height: h },
|
|
287
|
+
content: { src: assetPath, alt: '', fit: 'fill' },
|
|
288
|
+
};
|
|
289
|
+
return {
|
|
290
|
+
version: 1,
|
|
291
|
+
canvas: { width: w, height: h, background: 'transparent' },
|
|
292
|
+
layers: [layer],
|
|
293
|
+
meta: {
|
|
294
|
+
sourcePath: assetPath,
|
|
295
|
+
createdAt: new Date().toISOString(),
|
|
296
|
+
updatedAt: new Date().toISOString(),
|
|
297
|
+
},
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function probeImageDimensions(src: string): Promise<{ width: number; height: number } | null> {
|
|
302
|
+
return new Promise((resolve) => {
|
|
303
|
+
const img = new Image();
|
|
304
|
+
img.onload = () => resolve({ width: img.naturalWidth, height: img.naturalHeight });
|
|
305
|
+
img.onerror = () => resolve(null);
|
|
306
|
+
img.src = src;
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function guessExtensionFromMime(mime: string | undefined): string | null {
|
|
311
|
+
if (!mime) return null;
|
|
312
|
+
if (mime.includes('png')) return 'png';
|
|
313
|
+
if (mime.includes('jpeg') || mime.includes('jpg')) return 'jpg';
|
|
314
|
+
if (mime.includes('webp')) return 'webp';
|
|
315
|
+
if (mime.includes('gif')) return 'gif';
|
|
316
|
+
if (mime.includes('svg')) return 'svg';
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function extensionFromName(name: string | undefined): string | null {
|
|
321
|
+
if (!name) return null;
|
|
322
|
+
const dot = name.lastIndexOf('.');
|
|
323
|
+
return dot >= 0 ? name.slice(dot + 1).toLowerCase() : null;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function randomId(): string {
|
|
327
|
+
return Math.random().toString(36).slice(2, 10);
|
|
328
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Derive `--squisq-image-editor-*` CSS custom properties from a Theme +
|
|
3
|
+
* SurfaceScheme, mirroring `useJsonViewTokens` in squisq-react. Lets the
|
|
4
|
+
* ImageEditor re-theme consistently with the rest of Squisq (light/dark
|
|
5
|
+
* surface, theme palette, font family overrides).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { useMemo, type CSSProperties } from 'react';
|
|
9
|
+
import {
|
|
10
|
+
applySurface,
|
|
11
|
+
resolveFontFamily,
|
|
12
|
+
type SurfaceScheme,
|
|
13
|
+
type Theme,
|
|
14
|
+
} from '@bendyline/squisq/schemas';
|
|
15
|
+
import { DEFAULT_THEME } from '@bendyline/squisq/doc';
|
|
16
|
+
import { useAutoSurface } from '@bendyline/squisq-react';
|
|
17
|
+
|
|
18
|
+
export interface ImageEditorTokens {
|
|
19
|
+
/** Inline style object to spread onto the root `.squisq-image-editor`. */
|
|
20
|
+
style: CSSProperties;
|
|
21
|
+
/** The effective theme (after surface application). */
|
|
22
|
+
theme: Theme;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function useImageEditorTokens(
|
|
26
|
+
theme: Theme | undefined,
|
|
27
|
+
surface: SurfaceScheme | 'auto' | undefined,
|
|
28
|
+
): ImageEditorTokens {
|
|
29
|
+
const auto = useAutoSurface(surface === 'auto');
|
|
30
|
+
const effectiveSurface = surface === 'auto' ? auto : (surface ?? undefined);
|
|
31
|
+
|
|
32
|
+
return useMemo(() => {
|
|
33
|
+
const baseTheme = theme ?? DEFAULT_THEME;
|
|
34
|
+
const finalTheme = effectiveSurface ? applySurface(baseTheme, effectiveSurface) : baseTheme;
|
|
35
|
+
|
|
36
|
+
const bg = finalTheme.colors.background;
|
|
37
|
+
const text = finalTheme.colors.text;
|
|
38
|
+
const muted = finalTheme.colors.textMuted;
|
|
39
|
+
const accent = finalTheme.colors.primary;
|
|
40
|
+
|
|
41
|
+
// Panel / control surfaces are derived by mixing toward the opposite
|
|
42
|
+
// pole (text color), so the same recipe works for both light and dark
|
|
43
|
+
// surfaces without conditional branches.
|
|
44
|
+
const panelBg = `color-mix(in srgb, ${bg} 92%, ${text} 8%)`;
|
|
45
|
+
const panelBorder = `color-mix(in srgb, ${bg} 80%, ${text} 20%)`;
|
|
46
|
+
const controlBg = `color-mix(in srgb, ${bg} 86%, ${text} 14%)`;
|
|
47
|
+
const controlBorder = `color-mix(in srgb, ${bg} 72%, ${text} 28%)`;
|
|
48
|
+
const workspaceBg = `color-mix(in srgb, ${bg} 95%, ${text} 5%)`;
|
|
49
|
+
|
|
50
|
+
const bodyFont = resolveFontFamily(
|
|
51
|
+
finalTheme.typography.bodyFont,
|
|
52
|
+
'system-ui, -apple-system, sans-serif',
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const style: CSSProperties = {
|
|
56
|
+
['--squisq-image-editor-bg' as string]: bg,
|
|
57
|
+
['--squisq-image-editor-panel-bg' as string]: panelBg,
|
|
58
|
+
['--squisq-image-editor-panel-border' as string]: panelBorder,
|
|
59
|
+
['--squisq-image-editor-text' as string]: text,
|
|
60
|
+
['--squisq-image-editor-text-muted' as string]: muted,
|
|
61
|
+
['--squisq-image-editor-accent' as string]: accent,
|
|
62
|
+
['--squisq-image-editor-control-bg' as string]: controlBg,
|
|
63
|
+
['--squisq-image-editor-control-border' as string]: controlBorder,
|
|
64
|
+
['--squisq-image-editor-workspace-bg' as string]: workspaceBg,
|
|
65
|
+
['--squisq-image-editor-body-font' as string]: bodyFont,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
return { style, theme: finalTheme };
|
|
69
|
+
}, [theme, effectiveSurface]);
|
|
70
|
+
}
|