-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
567 additions
and
62 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { useEditor } from '@tiptap/react' | ||
import type { EditorOptions } from '@tiptap/react' | ||
import { | ||
makeEditArticleEditorExtensions, | ||
MakeArticleEditorExtensionsProps, | ||
} from './extensions' | ||
|
||
type UseEditArticleEditorProps = { | ||
content: string | ||
} & MakeArticleEditorExtensionsProps & | ||
Partial<EditorOptions> | ||
|
||
export const useEditArticleEdtor = ({ | ||
content, | ||
placeholder, | ||
mentionSuggestion, | ||
...editorProps | ||
}: UseEditArticleEditorProps) => { | ||
const { extensions, ...restProps } = editorProps | ||
const editor = useEditor({ | ||
extensions: [ | ||
...makeEditArticleEditorExtensions({ placeholder, mentionSuggestion }), | ||
...(extensions || []), | ||
], | ||
content, | ||
...restProps, | ||
}) | ||
|
||
return editor | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { Node } from '@tiptap/core' | ||
|
||
/** | ||
* ReadyOnlyFigureAudio extension is similar to FigureAudio extension, | ||
* but it is read-only for article revision. | ||
*/ | ||
|
||
const pluginName = 'readOnlyFigureAudio' | ||
|
||
export const ReadOnlyFigureAudio = Node.create({ | ||
name: pluginName, | ||
group: 'block', | ||
content: 'text*', | ||
draggable: true, | ||
isolating: true, | ||
|
||
// read-only | ||
atom: true, | ||
|
||
// disallows all marks for figcaption | ||
marks: '', | ||
|
||
addAttributes() { | ||
return { | ||
src: { | ||
default: null, | ||
parseHTML: (element) => | ||
element.querySelector('source')?.getAttribute('src'), | ||
}, | ||
title: { | ||
default: '', | ||
parseHTML: (element) => element.querySelector('.title')?.textContent, | ||
}, | ||
} | ||
}, | ||
|
||
parseHTML() { | ||
return [ | ||
{ | ||
tag: 'figure[class="audio"]', | ||
contentElement: 'figcaption', | ||
}, | ||
] | ||
}, | ||
|
||
renderHTML({ HTMLAttributes }) { | ||
return [ | ||
'figure', | ||
{ class: 'audio' }, | ||
[ | ||
'audio', | ||
{ | ||
controls: true, | ||
// for backward compatibility | ||
// can be removed when fully switch to new editor | ||
'data-file-name': HTMLAttributes.title, | ||
}, | ||
[ | ||
'source', | ||
{ | ||
src: HTMLAttributes.src, | ||
type: 'audio/mp3', | ||
draggable: false, | ||
contenteditable: false, | ||
}, | ||
], | ||
], | ||
[ | ||
'div', | ||
{ class: 'player' }, | ||
[ | ||
'header', | ||
[ | ||
'div', | ||
{ class: 'meta' }, | ||
['h4', { class: 'title' }, HTMLAttributes.title], | ||
[ | ||
'div', | ||
{ class: 'time' }, | ||
['span', { class: 'current', 'data-time': '00:00' }], | ||
['span', { class: 'duration', 'data-time': '--:--' }], | ||
], | ||
], | ||
['span', { class: 'play' }], | ||
], | ||
['footer', ['div', { class: 'progress-bar' }, ['span', {}]]], | ||
], | ||
['figcaption', 0], | ||
] | ||
}, | ||
}) |
Oops, something went wrong.