@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
package/src/ImageNodeView.tsx
CHANGED
|
@@ -6,35 +6,62 @@
|
|
|
6
6
|
*
|
|
7
7
|
* The ProseMirror node retains the original relative path so markdown roundtrip
|
|
8
8
|
* is preserved — only the rendered DOM uses the resolved URL.
|
|
9
|
+
*
|
|
10
|
+
* When the image is hovered or selected, a small floating "Edit" affordance
|
|
11
|
+
* appears in the top-right corner — clicking it calls `openImageEdit` on the
|
|
12
|
+
* editor context, which `<EditorShell>` consumes to open a modal
|
|
13
|
+
* `<ImageEditor>` on the source path. Only shown for paths that are
|
|
14
|
+
* relative (i.e. live in the document's media container).
|
|
9
15
|
*/
|
|
10
16
|
|
|
11
|
-
import { useEffect, useState } from 'react';
|
|
17
|
+
import { useEffect, useRef, useState } from 'react';
|
|
12
18
|
import { NodeViewWrapper, ReactNodeViewRenderer } from '@tiptap/react';
|
|
13
19
|
import type { NodeViewProps } from '@tiptap/react';
|
|
14
20
|
import Image from '@tiptap/extension-image';
|
|
15
21
|
import { useEditorContext } from './EditorContext';
|
|
22
|
+
import { normalizeMalformedAssetUrl } from './utils/normalizeMalformedAssetUrl';
|
|
16
23
|
|
|
17
|
-
function ImageComponent({ node }: NodeViewProps) {
|
|
18
|
-
const { src, alt, title } = node.attrs as {
|
|
19
|
-
|
|
24
|
+
function ImageComponent({ node, selected, editor, updateAttributes }: NodeViewProps) {
|
|
25
|
+
const { src, alt, title, width } = node.attrs as {
|
|
26
|
+
src: string;
|
|
27
|
+
alt: string;
|
|
28
|
+
title: string;
|
|
29
|
+
width: number | null;
|
|
30
|
+
height: number | null;
|
|
31
|
+
};
|
|
32
|
+
const { mediaProvider, imageDisplayMode, openImageEdit, mediaRevision } = useEditorContext();
|
|
20
33
|
const [resolvedSrc, setResolvedSrc] = useState(src);
|
|
34
|
+
const [hovered, setHovered] = useState(false);
|
|
35
|
+
const imgRef = useRef<HTMLImageElement | null>(null);
|
|
36
|
+
// Live preview width while a resize gesture is in flight. Null means
|
|
37
|
+
// "use the persisted width attr". Committed to node attrs on mouseup.
|
|
38
|
+
const [previewWidth, setPreviewWidth] = useState<number | null>(null);
|
|
21
39
|
const isThumbnail = imageDisplayMode === 'thumbnail';
|
|
40
|
+
const isEditable = editor?.isEditable ?? true;
|
|
22
41
|
|
|
42
|
+
// MS "Save Page As Web Page" / pandoc-style imports sometimes leave
|
|
43
|
+
// image srcs in the shape `http://<doc>_files/<asset>` — the asset
|
|
44
|
+
// folder got URL-parsed as a hostname because no scheme separator was
|
|
45
|
+
// ever there. Detect that shape (bare hostname, no dots/ports, ending
|
|
46
|
+
// in `_files`) and recover the original relative path so the media
|
|
47
|
+
// provider can resolve it from the workspace.
|
|
48
|
+
const normalizedRelativePath = normalizeMalformedAssetUrl(src);
|
|
23
49
|
const isRelative =
|
|
24
50
|
src &&
|
|
25
51
|
!src.startsWith('blob:') &&
|
|
26
52
|
!src.startsWith('http') &&
|
|
27
53
|
!src.startsWith('data:') &&
|
|
28
54
|
!src.startsWith('/');
|
|
55
|
+
const resolveAs = normalizedRelativePath ?? (isRelative ? src : null);
|
|
29
56
|
|
|
30
57
|
useEffect(() => {
|
|
31
|
-
if (!mediaProvider || !
|
|
58
|
+
if (!mediaProvider || !resolveAs) {
|
|
32
59
|
setResolvedSrc(src);
|
|
33
60
|
return;
|
|
34
61
|
}
|
|
35
62
|
|
|
36
63
|
let cancelled = false;
|
|
37
|
-
mediaProvider.resolveUrl(
|
|
64
|
+
mediaProvider.resolveUrl(resolveAs).then(
|
|
38
65
|
(resolved) => {
|
|
39
66
|
if (!cancelled) setResolvedSrc(resolved);
|
|
40
67
|
},
|
|
@@ -46,37 +73,211 @@ function ImageComponent({ node }: NodeViewProps) {
|
|
|
46
73
|
return () => {
|
|
47
74
|
cancelled = true;
|
|
48
75
|
};
|
|
49
|
-
|
|
76
|
+
// `mediaRevision` is bumped after the image editor writes back to the
|
|
77
|
+
// same path — re-resolve so we pick up the fresh blob URL.
|
|
78
|
+
}, [src, resolveAs, mediaProvider, mediaRevision]);
|
|
79
|
+
|
|
80
|
+
// The Edit affordance is only meaningful when:
|
|
81
|
+
// - the editor is editable (read-only previews skip it),
|
|
82
|
+
// - the path is relative (lives in the doc's container, so the editor
|
|
83
|
+
// can read+write it back), and
|
|
84
|
+
// - a media provider is wired (the modal resolves the URL through it).
|
|
85
|
+
const canEdit = isEditable && isRelative && mediaProvider !== null;
|
|
86
|
+
const showAffordance = canEdit && (selected || hovered);
|
|
87
|
+
// Resize handle is shown for any selected image in an editable view —
|
|
88
|
+
// even non-relative ones (external URLs, data URIs) — so authors can
|
|
89
|
+
// size remote pictures the same way as local ones.
|
|
90
|
+
const canResize = isEditable && !isThumbnail;
|
|
91
|
+
const showResize = canResize && (selected || hovered);
|
|
92
|
+
|
|
93
|
+
// Effective render width: live preview while dragging, otherwise the
|
|
94
|
+
// persisted attr. Height is always derived from the natural aspect
|
|
95
|
+
// ratio of the image element so authors can't accidentally squash it.
|
|
96
|
+
const effectiveWidth = previewWidth ?? width ?? null;
|
|
97
|
+
|
|
98
|
+
const beginResize = (event: React.MouseEvent) => {
|
|
99
|
+
if (!canResize) return;
|
|
100
|
+
event.preventDefault();
|
|
101
|
+
event.stopPropagation();
|
|
102
|
+
const imgEl = imgRef.current;
|
|
103
|
+
if (!imgEl) return;
|
|
104
|
+
const startWidth = imgEl.getBoundingClientRect().width;
|
|
105
|
+
const startX = event.clientX;
|
|
106
|
+
// Cap at the image's natural width so dragging out doesn't upscale
|
|
107
|
+
// past the source pixels (which just looks blurry).
|
|
108
|
+
const maxWidth = imgEl.naturalWidth || Infinity;
|
|
109
|
+
const minWidth = 24;
|
|
110
|
+
|
|
111
|
+
const onMove = (e: MouseEvent) => {
|
|
112
|
+
const next = Math.max(minWidth, Math.min(maxWidth, startWidth + (e.clientX - startX)));
|
|
113
|
+
setPreviewWidth(Math.round(next));
|
|
114
|
+
};
|
|
115
|
+
const onUp = (e: MouseEvent) => {
|
|
116
|
+
window.removeEventListener('mousemove', onMove);
|
|
117
|
+
window.removeEventListener('mouseup', onUp);
|
|
118
|
+
const finalWidth = Math.max(minWidth, Math.min(maxWidth, startWidth + (e.clientX - startX)));
|
|
119
|
+
const naturalW = imgEl.naturalWidth;
|
|
120
|
+
const naturalH = imgEl.naturalHeight;
|
|
121
|
+
const w = Math.round(finalWidth);
|
|
122
|
+
const h = naturalW > 0 && naturalH > 0 ? Math.round((w * naturalH) / naturalW) : null;
|
|
123
|
+
setPreviewWidth(null);
|
|
124
|
+
updateAttributes({ width: w, height: h });
|
|
125
|
+
};
|
|
126
|
+
window.addEventListener('mousemove', onMove);
|
|
127
|
+
window.addEventListener('mouseup', onUp);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const resetSize = (event: React.MouseEvent) => {
|
|
131
|
+
if (!canResize) return;
|
|
132
|
+
event.preventDefault();
|
|
133
|
+
event.stopPropagation();
|
|
134
|
+
setPreviewWidth(null);
|
|
135
|
+
updateAttributes({ width: null, height: null });
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const baseStyle: React.CSSProperties = isThumbnail
|
|
139
|
+
? {
|
|
140
|
+
maxWidth: '100px',
|
|
141
|
+
maxHeight: '100px',
|
|
142
|
+
width: 'auto',
|
|
143
|
+
height: 'auto',
|
|
144
|
+
objectFit: 'contain',
|
|
145
|
+
display: 'block',
|
|
146
|
+
}
|
|
147
|
+
: effectiveWidth
|
|
148
|
+
? {
|
|
149
|
+
width: `${effectiveWidth}px`,
|
|
150
|
+
maxWidth: '100%',
|
|
151
|
+
height: 'auto',
|
|
152
|
+
display: 'block',
|
|
153
|
+
}
|
|
154
|
+
: { maxWidth: '100%', height: 'auto', display: 'block' };
|
|
50
155
|
|
|
51
156
|
return (
|
|
52
|
-
<NodeViewWrapper
|
|
157
|
+
<NodeViewWrapper
|
|
158
|
+
as="figure"
|
|
159
|
+
// `data-drag-handle` tells ProseMirror that drags starting on this
|
|
160
|
+
// wrapper are NODE moves (not OS-level image drags). Without it,
|
|
161
|
+
// grabbing the inner `<img>` fires the browser's default image-drag
|
|
162
|
+
// behaviour: the picture is packaged as a virtual file in
|
|
163
|
+
// `dataTransfer.files`, the drop is treated as an external upload,
|
|
164
|
+
// and the source node is never removed — producing a duplicate.
|
|
165
|
+
// Combined with `draggable: true` in the node spec, this gives
|
|
166
|
+
// ProseMirror's default dropHandler a real internal move which
|
|
167
|
+
// preserves the `width`/`height` attrs and deletes the original.
|
|
168
|
+
draggable
|
|
169
|
+
data-drag-handle
|
|
170
|
+
style={{ margin: '0.5em 0', position: 'relative', display: 'inline-block', maxWidth: '100%' }}
|
|
171
|
+
onMouseEnter={() => setHovered(true)}
|
|
172
|
+
onMouseLeave={() => setHovered(false)}
|
|
173
|
+
>
|
|
53
174
|
<img
|
|
175
|
+
ref={imgRef}
|
|
54
176
|
src={resolvedSrc}
|
|
55
177
|
alt={alt || ''}
|
|
56
178
|
title={title || undefined}
|
|
57
179
|
className={isThumbnail ? 'squisq-image squisq-image--thumbnail' : 'squisq-image'}
|
|
58
|
-
style={
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
display: 'block',
|
|
67
|
-
}
|
|
68
|
-
: { maxWidth: '100%', height: 'auto', display: 'block' }
|
|
69
|
-
}
|
|
180
|
+
style={baseStyle}
|
|
181
|
+
// Disable the inner `<img>`'s native HTML5 drag so the gesture is
|
|
182
|
+
// captured by the wrapper's `data-drag-handle` instead. (Without
|
|
183
|
+
// this the browser still emits its own dragstart on the image
|
|
184
|
+
// and ProseMirror sees an external file drop.)
|
|
185
|
+
draggable={false}
|
|
186
|
+
onDragStart={(e) => e.preventDefault()}
|
|
187
|
+
data-selected={selected ? 'true' : undefined}
|
|
70
188
|
/>
|
|
189
|
+
{showAffordance && (
|
|
190
|
+
<button
|
|
191
|
+
type="button"
|
|
192
|
+
className="squisq-image-edit-affordance"
|
|
193
|
+
data-testid="image-edit-affordance"
|
|
194
|
+
// Stop the click from re-selecting the ProseMirror node and from
|
|
195
|
+
// bubbling to host handlers like file-drop overlays.
|
|
196
|
+
onMouseDown={(e) => e.preventDefault()}
|
|
197
|
+
onClick={(e) => {
|
|
198
|
+
e.preventDefault();
|
|
199
|
+
e.stopPropagation();
|
|
200
|
+
openImageEdit(src);
|
|
201
|
+
}}
|
|
202
|
+
title="Edit image"
|
|
203
|
+
aria-label={`Edit image ${alt || src}`}
|
|
204
|
+
>
|
|
205
|
+
<span aria-hidden="true" style={{ fontSize: '0.95em', lineHeight: 1 }}>
|
|
206
|
+
✎
|
|
207
|
+
</span>
|
|
208
|
+
<span>Edit</span>
|
|
209
|
+
</button>
|
|
210
|
+
)}
|
|
211
|
+
{showResize && (
|
|
212
|
+
<>
|
|
213
|
+
<span
|
|
214
|
+
className="squisq-image-resize-handle"
|
|
215
|
+
data-testid="image-resize-handle"
|
|
216
|
+
onMouseDown={beginResize}
|
|
217
|
+
// Double-click clears the persisted width/height so the image
|
|
218
|
+
// returns to its natural rendered size.
|
|
219
|
+
onDoubleClick={resetSize}
|
|
220
|
+
title="Drag to resize · double-click to reset"
|
|
221
|
+
aria-label="Resize image"
|
|
222
|
+
role="separator"
|
|
223
|
+
/>
|
|
224
|
+
{(previewWidth != null || width != null) && (
|
|
225
|
+
<span className="squisq-image-resize-readout" aria-hidden="true">
|
|
226
|
+
{Math.round(effectiveWidth ?? 0)}px
|
|
227
|
+
</span>
|
|
228
|
+
)}
|
|
229
|
+
</>
|
|
230
|
+
)}
|
|
71
231
|
</NodeViewWrapper>
|
|
72
232
|
);
|
|
73
233
|
}
|
|
74
234
|
|
|
75
235
|
/**
|
|
76
236
|
* Image extension with a custom React NodeView that resolves URLs
|
|
77
|
-
* through the EditorContext's MediaProvider
|
|
237
|
+
* through the EditorContext's MediaProvider, plus author-controlled
|
|
238
|
+
* width/height attributes for in-editor resizing.
|
|
239
|
+
*
|
|
240
|
+
* When `width` (and optionally `height`) is set, the markdown serializer
|
|
241
|
+
* (`tiptapToMarkdown` in `tiptapBridge.ts`) emits an HTML `<img>` tag
|
|
242
|
+
* rather than the `` shorthand so dimensions survive a
|
|
243
|
+
* markdown ↔ WYSIWYG round-trip.
|
|
78
244
|
*/
|
|
79
245
|
export const ImageWithMediaProvider = Image.extend({
|
|
246
|
+
// Mark the node draggable so ProseMirror handles drag-to-reposition
|
|
247
|
+
// as an internal node move (preserves `width`/`height` attrs and
|
|
248
|
+
// removes the source node automatically). Combined with the
|
|
249
|
+
// `data-drag-handle` on the NodeViewWrapper, this is what makes the
|
|
250
|
+
// `moved` flag true in `handleDrop` so the editor's file-upload path
|
|
251
|
+
// doesn't fire on a drag-reorder.
|
|
252
|
+
draggable: true,
|
|
253
|
+
addAttributes() {
|
|
254
|
+
const parent = this.parent?.() ?? {};
|
|
255
|
+
return {
|
|
256
|
+
...parent,
|
|
257
|
+
width: {
|
|
258
|
+
default: null,
|
|
259
|
+
parseHTML: (element) => {
|
|
260
|
+
const raw = element.getAttribute('width');
|
|
261
|
+
if (!raw) return null;
|
|
262
|
+
const n = parseInt(raw, 10);
|
|
263
|
+
return Number.isFinite(n) && n > 0 ? n : null;
|
|
264
|
+
},
|
|
265
|
+
renderHTML: (attrs: { width?: number | null }) =>
|
|
266
|
+
attrs.width ? { width: String(attrs.width) } : {},
|
|
267
|
+
},
|
|
268
|
+
height: {
|
|
269
|
+
default: null,
|
|
270
|
+
parseHTML: (element) => {
|
|
271
|
+
const raw = element.getAttribute('height');
|
|
272
|
+
if (!raw) return null;
|
|
273
|
+
const n = parseInt(raw, 10);
|
|
274
|
+
return Number.isFinite(n) && n > 0 ? n : null;
|
|
275
|
+
},
|
|
276
|
+
renderHTML: (attrs: { height?: number | null }) =>
|
|
277
|
+
attrs.height ? { height: String(attrs.height) } : {},
|
|
278
|
+
},
|
|
279
|
+
};
|
|
280
|
+
},
|
|
80
281
|
addNodeView() {
|
|
81
282
|
return ReactNodeViewRenderer(ImageComponent);
|
|
82
283
|
},
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ImageViewer
|
|
3
|
+
*
|
|
4
|
+
* Read-only image viewer used when EditorShell runs in `image` file mode
|
|
5
|
+
* (PNG/JPEG/etc.). Renders a centered image that fits its container with
|
|
6
|
+
* a small overlay toolbar for fit / 100% / zoom in / zoom out, and a
|
|
7
|
+
* status row showing intrinsic dimensions and current zoom.
|
|
8
|
+
*
|
|
9
|
+
* Lifecycle of the `src` URL is the caller's responsibility — when fed a
|
|
10
|
+
* blob URL, the host should `URL.revokeObjectURL` on unmount or src change.
|
|
11
|
+
*
|
|
12
|
+
* Future image-editing actions (rotate, flip, crop) will slot in alongside
|
|
13
|
+
* the existing zoom controls.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
17
|
+
import type { CSSProperties, MouseEvent as ReactMouseEvent } from 'react';
|
|
18
|
+
|
|
19
|
+
export interface ImageViewerProps {
|
|
20
|
+
/** Image source — typically a blob: URL the host owns and revokes. */
|
|
21
|
+
src: string;
|
|
22
|
+
/** Alt text for accessibility. Defaults to empty string (decorative). */
|
|
23
|
+
alt?: string;
|
|
24
|
+
/** Additional class name on the outer container. */
|
|
25
|
+
className?: string;
|
|
26
|
+
/** Color theme for the chrome around the image. */
|
|
27
|
+
theme?: 'light' | 'dark';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const MIN_ZOOM = 0.1;
|
|
31
|
+
const MAX_ZOOM = 16;
|
|
32
|
+
const ZOOM_STEP = 1.25;
|
|
33
|
+
|
|
34
|
+
type FitState = { mode: 'fit' } | { mode: 'manual'; zoom: number };
|
|
35
|
+
|
|
36
|
+
export function ImageViewer({ src, alt = '', className, theme = 'light' }: ImageViewerProps) {
|
|
37
|
+
const imgRef = useRef<HTMLImageElement | null>(null);
|
|
38
|
+
const stageRef = useRef<HTMLDivElement | null>(null);
|
|
39
|
+
|
|
40
|
+
const [naturalSize, setNaturalSize] = useState<{ w: number; h: number } | null>(null);
|
|
41
|
+
const [fitZoom, setFitZoom] = useState<number>(1);
|
|
42
|
+
const [state, setState] = useState<FitState>({ mode: 'fit' });
|
|
43
|
+
const [pan, setPan] = useState<{ x: number; y: number }>({ x: 0, y: 0 });
|
|
44
|
+
const [error, setError] = useState<string | null>(null);
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
setNaturalSize(null);
|
|
48
|
+
setState({ mode: 'fit' });
|
|
49
|
+
setPan({ x: 0, y: 0 });
|
|
50
|
+
setError(null);
|
|
51
|
+
}, [src]);
|
|
52
|
+
|
|
53
|
+
const recomputeFitZoom = useCallback(() => {
|
|
54
|
+
const stage = stageRef.current;
|
|
55
|
+
if (!stage || !naturalSize) return;
|
|
56
|
+
const { clientWidth, clientHeight } = stage;
|
|
57
|
+
if (clientWidth === 0 || clientHeight === 0) return;
|
|
58
|
+
const fit = Math.min(clientWidth / naturalSize.w, clientHeight / naturalSize.h, 1);
|
|
59
|
+
setFitZoom(fit > 0 ? fit : 1);
|
|
60
|
+
}, [naturalSize]);
|
|
61
|
+
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
recomputeFitZoom();
|
|
64
|
+
if (typeof ResizeObserver === 'undefined') return;
|
|
65
|
+
const stage = stageRef.current;
|
|
66
|
+
if (!stage) return;
|
|
67
|
+
const ro = new ResizeObserver(() => recomputeFitZoom());
|
|
68
|
+
ro.observe(stage);
|
|
69
|
+
return () => ro.disconnect();
|
|
70
|
+
}, [recomputeFitZoom]);
|
|
71
|
+
|
|
72
|
+
const handleLoad = useCallback(() => {
|
|
73
|
+
const img = imgRef.current;
|
|
74
|
+
if (!img) return;
|
|
75
|
+
setNaturalSize({ w: img.naturalWidth, h: img.naturalHeight });
|
|
76
|
+
}, []);
|
|
77
|
+
|
|
78
|
+
const handleError = useCallback(() => {
|
|
79
|
+
setError('Failed to load image');
|
|
80
|
+
}, []);
|
|
81
|
+
|
|
82
|
+
const effectiveZoom = state.mode === 'fit' ? fitZoom : state.zoom;
|
|
83
|
+
|
|
84
|
+
const setZoom = useCallback((next: number) => {
|
|
85
|
+
const clamped = Math.max(MIN_ZOOM, Math.min(MAX_ZOOM, next));
|
|
86
|
+
setState({ mode: 'manual', zoom: clamped });
|
|
87
|
+
}, []);
|
|
88
|
+
|
|
89
|
+
const onFit = useCallback(() => {
|
|
90
|
+
setState({ mode: 'fit' });
|
|
91
|
+
setPan({ x: 0, y: 0 });
|
|
92
|
+
}, []);
|
|
93
|
+
const onActual = useCallback(() => {
|
|
94
|
+
setZoom(1);
|
|
95
|
+
setPan({ x: 0, y: 0 });
|
|
96
|
+
}, [setZoom]);
|
|
97
|
+
const onZoomIn = useCallback(() => setZoom(effectiveZoom * ZOOM_STEP), [effectiveZoom, setZoom]);
|
|
98
|
+
const onZoomOut = useCallback(() => setZoom(effectiveZoom / ZOOM_STEP), [effectiveZoom, setZoom]);
|
|
99
|
+
|
|
100
|
+
const dragRef = useRef<{ startX: number; startY: number; panX: number; panY: number } | null>(
|
|
101
|
+
null,
|
|
102
|
+
);
|
|
103
|
+
const onMouseDown = useCallback(
|
|
104
|
+
(e: ReactMouseEvent<HTMLDivElement>) => {
|
|
105
|
+
if (effectiveZoom <= fitZoom) return;
|
|
106
|
+
dragRef.current = { startX: e.clientX, startY: e.clientY, panX: pan.x, panY: pan.y };
|
|
107
|
+
e.preventDefault();
|
|
108
|
+
},
|
|
109
|
+
[effectiveZoom, fitZoom, pan.x, pan.y],
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
const onMove = (e: MouseEvent) => {
|
|
114
|
+
const drag = dragRef.current;
|
|
115
|
+
if (!drag) return;
|
|
116
|
+
setPan({
|
|
117
|
+
x: drag.panX + (e.clientX - drag.startX),
|
|
118
|
+
y: drag.panY + (e.clientY - drag.startY),
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
const onUp = () => {
|
|
122
|
+
dragRef.current = null;
|
|
123
|
+
};
|
|
124
|
+
window.addEventListener('mousemove', onMove);
|
|
125
|
+
window.addEventListener('mouseup', onUp);
|
|
126
|
+
return () => {
|
|
127
|
+
window.removeEventListener('mousemove', onMove);
|
|
128
|
+
window.removeEventListener('mouseup', onUp);
|
|
129
|
+
};
|
|
130
|
+
}, []);
|
|
131
|
+
|
|
132
|
+
const isPannable = effectiveZoom > fitZoom + 1e-6;
|
|
133
|
+
|
|
134
|
+
const imgStyle: CSSProperties = naturalSize
|
|
135
|
+
? {
|
|
136
|
+
width: `${naturalSize.w * effectiveZoom}px`,
|
|
137
|
+
height: `${naturalSize.h * effectiveZoom}px`,
|
|
138
|
+
transform: `translate(${pan.x}px, ${pan.y}px)`,
|
|
139
|
+
}
|
|
140
|
+
: { maxWidth: '100%', maxHeight: '100%' };
|
|
141
|
+
|
|
142
|
+
const containerCls = ['squisq-image-viewer', `squisq-image-viewer--${theme}`, className]
|
|
143
|
+
.filter(Boolean)
|
|
144
|
+
.join(' ');
|
|
145
|
+
|
|
146
|
+
return (
|
|
147
|
+
<div className={containerCls} data-testid="image-viewer">
|
|
148
|
+
<div
|
|
149
|
+
ref={stageRef}
|
|
150
|
+
className="squisq-image-viewer-stage"
|
|
151
|
+
onMouseDown={onMouseDown}
|
|
152
|
+
style={{ cursor: isPannable ? (dragRef.current ? 'grabbing' : 'grab') : 'default' }}
|
|
153
|
+
>
|
|
154
|
+
{/* future: rotate, flip, crop overlays go here */}
|
|
155
|
+
{error ? (
|
|
156
|
+
<div className="squisq-image-viewer-error">{error}</div>
|
|
157
|
+
) : (
|
|
158
|
+
<img
|
|
159
|
+
ref={imgRef}
|
|
160
|
+
src={src}
|
|
161
|
+
alt={alt}
|
|
162
|
+
className="squisq-image-viewer-img"
|
|
163
|
+
style={imgStyle}
|
|
164
|
+
onLoad={handleLoad}
|
|
165
|
+
onError={handleError}
|
|
166
|
+
draggable={false}
|
|
167
|
+
/>
|
|
168
|
+
)}
|
|
169
|
+
<div className="squisq-image-viewer-toolbar">
|
|
170
|
+
<button
|
|
171
|
+
type="button"
|
|
172
|
+
className="squisq-image-viewer-btn"
|
|
173
|
+
onClick={onZoomOut}
|
|
174
|
+
aria-label="Zoom out"
|
|
175
|
+
title="Zoom out"
|
|
176
|
+
>
|
|
177
|
+
−
|
|
178
|
+
</button>
|
|
179
|
+
<button
|
|
180
|
+
type="button"
|
|
181
|
+
className="squisq-image-viewer-btn"
|
|
182
|
+
onClick={onFit}
|
|
183
|
+
aria-pressed={state.mode === 'fit'}
|
|
184
|
+
title="Fit to viewport"
|
|
185
|
+
>
|
|
186
|
+
Fit
|
|
187
|
+
</button>
|
|
188
|
+
<button
|
|
189
|
+
type="button"
|
|
190
|
+
className="squisq-image-viewer-btn"
|
|
191
|
+
onClick={onActual}
|
|
192
|
+
title="Actual size (100%)"
|
|
193
|
+
>
|
|
194
|
+
100%
|
|
195
|
+
</button>
|
|
196
|
+
<button
|
|
197
|
+
type="button"
|
|
198
|
+
className="squisq-image-viewer-btn"
|
|
199
|
+
onClick={onZoomIn}
|
|
200
|
+
aria-label="Zoom in"
|
|
201
|
+
title="Zoom in"
|
|
202
|
+
>
|
|
203
|
+
+
|
|
204
|
+
</button>
|
|
205
|
+
</div>
|
|
206
|
+
</div>
|
|
207
|
+
<div className="squisq-image-viewer-status">
|
|
208
|
+
{naturalSize ? (
|
|
209
|
+
<>
|
|
210
|
+
<span>
|
|
211
|
+
{naturalSize.w} × {naturalSize.h}
|
|
212
|
+
</span>
|
|
213
|
+
<span>{Math.round(effectiveZoom * 100)}%</span>
|
|
214
|
+
</>
|
|
215
|
+
) : (
|
|
216
|
+
<span>Loading…</span>
|
|
217
|
+
)}
|
|
218
|
+
</div>
|
|
219
|
+
</div>
|
|
220
|
+
);
|
|
221
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* InlineIcon — Tiptap Node Extension
|
|
3
|
+
*
|
|
4
|
+
* Atomic inline node that round-trips FontAwesome icons through the
|
|
5
|
+
* WYSIWYG editor. The markdown bridge stashes `{[github]}` source as
|
|
6
|
+
* `<i data-icon="github" data-family="brands" data-name="github"
|
|
7
|
+
* class="fa-brands fa-github"></i>`; this extension lets ProseMirror
|
|
8
|
+
* recognize that markup, persist the attributes through edits, and
|
|
9
|
+
* re-emit it when serializing back to HTML/markdown.
|
|
10
|
+
*
|
|
11
|
+
* Atom / inline / non-selectable means the icon behaves like an emoji:
|
|
12
|
+
* the caret can land before or after it, Backspace deletes it whole,
|
|
13
|
+
* and Tiptap won't try to put content inside it.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { Node, mergeAttributes } from '@tiptap/core';
|
|
17
|
+
|
|
18
|
+
interface InlineIconAttrs {
|
|
19
|
+
/** Token as authored in markdown — e.g. `github`, `fa-solid:user`. */
|
|
20
|
+
token: string;
|
|
21
|
+
family: 'brands' | 'solid' | 'regular';
|
|
22
|
+
name: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const InlineIcon = Node.create({
|
|
26
|
+
name: 'inlineIcon',
|
|
27
|
+
group: 'inline',
|
|
28
|
+
inline: true,
|
|
29
|
+
atom: true,
|
|
30
|
+
selectable: true,
|
|
31
|
+
draggable: false,
|
|
32
|
+
|
|
33
|
+
addAttributes() {
|
|
34
|
+
return {
|
|
35
|
+
token: {
|
|
36
|
+
default: '',
|
|
37
|
+
parseHTML: (el: HTMLElement) => el.getAttribute('data-icon') ?? '',
|
|
38
|
+
renderHTML: (attrs: InlineIconAttrs) => (attrs.token ? { 'data-icon': attrs.token } : {}),
|
|
39
|
+
},
|
|
40
|
+
family: {
|
|
41
|
+
default: 'solid',
|
|
42
|
+
parseHTML: (el: HTMLElement) => el.getAttribute('data-family') ?? 'solid',
|
|
43
|
+
renderHTML: (attrs: InlineIconAttrs) =>
|
|
44
|
+
attrs.family ? { 'data-family': attrs.family } : {},
|
|
45
|
+
},
|
|
46
|
+
name: {
|
|
47
|
+
default: '',
|
|
48
|
+
parseHTML: (el: HTMLElement) => el.getAttribute('data-name') ?? '',
|
|
49
|
+
renderHTML: (attrs: InlineIconAttrs) => (attrs.name ? { 'data-name': attrs.name } : {}),
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
parseHTML() {
|
|
55
|
+
// Tiptap's built-in Italic mark also claims `<i>` tags. We need a
|
|
56
|
+
// higher priority than the default (50) so ProseMirror picks
|
|
57
|
+
// InlineIcon over Italic for `<i data-icon=…>` markup — otherwise
|
|
58
|
+
// the markdown → WYSIWYG round-trip silently drops the icon and
|
|
59
|
+
// produces an empty italic mark instead.
|
|
60
|
+
return [
|
|
61
|
+
{
|
|
62
|
+
tag: 'i[data-icon]',
|
|
63
|
+
priority: 100,
|
|
64
|
+
},
|
|
65
|
+
];
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
renderHTML({ HTMLAttributes }) {
|
|
69
|
+
const family = (HTMLAttributes['data-family'] as string | undefined) ?? 'solid';
|
|
70
|
+
const name = (HTMLAttributes['data-name'] as string | undefined) ?? '';
|
|
71
|
+
// The `<i>` carries `class="fa-brands fa-github"` so the bundled
|
|
72
|
+
// FontAwesome CSS picks it up. We also keep `data-*` mirrors so
|
|
73
|
+
// the bridge regex can round-trip back to markdown without
|
|
74
|
+
// parsing the class string.
|
|
75
|
+
const className = name ? `fa-${family} fa-${name}` : '';
|
|
76
|
+
return [
|
|
77
|
+
'i',
|
|
78
|
+
mergeAttributes(HTMLAttributes, {
|
|
79
|
+
class: className,
|
|
80
|
+
contenteditable: 'false',
|
|
81
|
+
}),
|
|
82
|
+
];
|
|
83
|
+
},
|
|
84
|
+
});
|