feat: Allow exporting multiple Super notes and select what format to export them to (#2191)
This commit is contained in:
@@ -41,6 +41,7 @@ import ReadonlyPlugin from './Plugins/ReadonlyPlugin/ReadonlyPlugin'
|
||||
import { SuperSearchContextProvider } from './Plugins/SearchPlugin/Context'
|
||||
import { SearchPlugin } from './Plugins/SearchPlugin/SearchPlugin'
|
||||
import ModalOverlay from '@/Components/Modal/ModalOverlay'
|
||||
import { SuperEditorNodes } from './SuperEditorNodes'
|
||||
|
||||
const NotePreviewCharLimit = 160
|
||||
|
||||
@@ -170,7 +171,7 @@ export const SuperEditor: FunctionComponent<Props> = ({
|
||||
<BlocksEditorComposer
|
||||
readonly={note.current.locked}
|
||||
initialValue={note.current.text}
|
||||
nodes={[FileNode, BubbleNode]}
|
||||
nodes={SuperEditorNodes}
|
||||
>
|
||||
<BlocksEditor
|
||||
onChange={handleChange}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
import { FileNode } from './Plugins/EncryptedFilePlugin/Nodes/FileNode'
|
||||
import { BubbleNode } from './Plugins/ItemBubblePlugin/Nodes/BubbleNode'
|
||||
|
||||
export const SuperEditorNodes = [FileNode, BubbleNode]
|
||||
@@ -0,0 +1,46 @@
|
||||
import { createHeadlessEditor } from '@lexical/headless'
|
||||
import { $convertToMarkdownString } from '@lexical/markdown'
|
||||
import { MarkdownTransformers } from '@standardnotes/blocks-editor'
|
||||
import { $generateHtmlFromNodes } from '@lexical/html'
|
||||
import { BlockEditorNodes } from '@standardnotes/blocks-editor/src/Lexical/Nodes/AllNodes'
|
||||
import BlocksEditorTheme from '@standardnotes/blocks-editor/src/Lexical/Theme/Theme'
|
||||
import { SNNote } from '@standardnotes/models'
|
||||
import { SuperEditorNodes } from './SuperEditorNodes'
|
||||
|
||||
export const exportSuperNote = (note: SNNote, format: 'txt' | 'md' | 'html' | 'json') => {
|
||||
const headlessEditor = createHeadlessEditor({
|
||||
namespace: 'BlocksEditor',
|
||||
theme: BlocksEditorTheme,
|
||||
editable: false,
|
||||
onError: (error: Error) => console.error(error),
|
||||
nodes: [...SuperEditorNodes, ...BlockEditorNodes],
|
||||
})
|
||||
|
||||
headlessEditor.setEditorState(headlessEditor.parseEditorState(note.text))
|
||||
|
||||
let content: string | undefined
|
||||
|
||||
headlessEditor.update(() => {
|
||||
switch (format) {
|
||||
case 'md':
|
||||
content = $convertToMarkdownString(MarkdownTransformers)
|
||||
break
|
||||
case 'html':
|
||||
content = $generateHtmlFromNodes(headlessEditor)
|
||||
break
|
||||
case 'json':
|
||||
content = JSON.stringify(headlessEditor.toJSON())
|
||||
break
|
||||
case 'txt':
|
||||
default:
|
||||
content = note.text
|
||||
break
|
||||
}
|
||||
})
|
||||
|
||||
if (!content) {
|
||||
throw new Error('Could not export note')
|
||||
}
|
||||
|
||||
return content
|
||||
}
|
||||
Reference in New Issue
Block a user