diff options
author | Max <max@nextcloud.com> | 2022-04-11 10:35:30 +0300 |
---|---|---|
committer | Max <max@nextcloud.com> | 2022-06-07 20:41:56 +0300 |
commit | ef7b0fdfd6d130a073d089c24ac4b7297842417b (patch) | |
tree | 08148b9a76e5e7c986cc26f1dec265ca3fb79b7d /src/extensions | |
parent | c3d4c53a8316a7e3b8f3fe6046463cd928f12611 (diff) |
refactor: use Editor.new directly in ReadOnlyEditor
Introduce a `Plaintext` tiptap extension
that bundles all the extensions used for plain text editing.
This allows calling `Editor.new` directly with just a few extensions.
No need to rely on `createEditor` from the editor factory anymore.
Also prevent error messages about undefined callbacks
because no callbacks were handed to `createEditor` in `ReadOnlyEditor`.
Signed-off-by: Max <max@nextcloud.com>
Diffstat (limited to 'src/extensions')
-rw-r--r-- | src/extensions/PlainText.js | 43 | ||||
-rw-r--r-- | src/extensions/RichText.js | 7 | ||||
-rw-r--r-- | src/extensions/index.js | 2 |
3 files changed, 50 insertions, 2 deletions
diff --git a/src/extensions/PlainText.js b/src/extensions/PlainText.js new file mode 100644 index 000000000..1d3a6ee55 --- /dev/null +++ b/src/extensions/PlainText.js @@ -0,0 +1,43 @@ +/* + * @copyright Copyright (c) 2022 Max <max@nextcloud.com> + * + * @author Max <max@nextcloud.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * +*/ + +import { Extension } from '@tiptap/core' + +/* eslint-disable import/no-named-as-default */ +import CodeBlockLowlight from '@tiptap/extension-code-block-lowlight' +import Text from '@tiptap/extension-text' +/* eslint-enable import/no-named-as-default */ + +import { PlainTextDocument } from './../nodes/index.js' + +export default Extension.create({ + name: 'PlainText', + + addExtensions() { + return [ + PlainTextDocument, + Text, + CodeBlockLowlight, + ] + }, + +}) diff --git a/src/extensions/RichText.js b/src/extensions/RichText.js index b7fd5d030..0356aeec8 100644 --- a/src/extensions/RichText.js +++ b/src/extensions/RichText.js @@ -60,7 +60,7 @@ export default Extension.create({ }, addExtensions() { - return [ + const extensions = [ Document, Text, Paragraph, @@ -69,7 +69,6 @@ export default Extension.create({ Strong, Italic, Strike, - Link.configure({ openOnClick: true }), Blockquote, CodeBlock, BulletList, @@ -91,6 +90,10 @@ export default Extension.create({ }), Dropcursor, ] + if (this.options.link !== false) { + extensions.push(Link.configure({ openOnClick: true })) + } + return extensions }, }) diff --git a/src/extensions/index.js b/src/extensions/index.js index ff26f199b..1c05250ed 100644 --- a/src/extensions/index.js +++ b/src/extensions/index.js @@ -26,6 +26,7 @@ import Keymap from './Keymap.js' import UserColor from './UserColor.js' import Collaboration from './Collaboration.js' import Markdown from './Markdown.js' +import PlainText from './PlainText.js' import RichText from './RichText.js' export { @@ -35,5 +36,6 @@ export { UserColor, Collaboration, Markdown, + PlainText, RichText, } |