refactoring

This commit is contained in:
Philipp Kühn
2021-03-16 22:22:13 +01:00
parent a76de1ab6d
commit 49fcf829f3
9 changed files with 91 additions and 55 deletions

View File

@@ -13,7 +13,7 @@ export class MentionList extends React.Component {
componentDidUpdate(oldProps) {
if (this.props.items !== oldProps.items) {
this.setState({
selectedIndex: 0
selectedIndex: 0,
})
}
}
@@ -39,13 +39,13 @@ export class MentionList extends React.Component {
upHandler() {
this.setState({
selectedIndex: ((this.state.selectedIndex + this.props.items.length) - 1) % this.props.items.length
selectedIndex: ((this.state.selectedIndex + this.props.items.length) - 1) % this.props.items.length,
})
}
downHandler() {
this.setState({
selectedIndex: (this.state.selectedIndex + 1) % this.props.items.length
selectedIndex: (this.state.selectedIndex + 1) % this.props.items.length,
})
}

View File

@@ -66,9 +66,9 @@ export default () => {
reactRenderer.destroy()
},
}
}
},
},
})
}),
],
content: `
<p>
@@ -84,8 +84,8 @@ export default () => {
return (
<div>
<EditorContent editor={editor} />
{editor &&
<div className={`character-count ${editor.getCharacterCount() === limit ? 'character-count--warning' : ''}`}>
{editor
&& <div className={`character-count ${editor.getCharacterCount() === limit ? 'character-count--warning' : ''}`}>
<svg
height="20"
width="20"

View File

@@ -1,6 +1,9 @@
/* eslint-disable */
import React, { useState } from 'react'
import tippy from 'tippy.js'
import { useEditor, EditorContent, ReactRenderer, ReactNodeViewRenderer, NodeViewWrapper, NodeViewContent } from '@tiptap/react'
import {
useEditor, EditorContent, ReactRenderer, ReactNodeViewRenderer, NodeViewWrapper, NodeViewContent,
} from '@tiptap/react'
import { defaultExtensions } from '@tiptap/starter-kit'
import Heading from '@tiptap/extension-heading'
import Paragraph from '@tiptap/extension-paragraph'
@@ -127,13 +130,13 @@ const MenuBar = ({ editor }) => {
)
}
const MentionList = (props) => {
console.log({props})
const MentionList = props => {
console.log({ props })
return (
<div>
mentions
{props.items.map((item) => (
{props.items.map(item => (
<div>
{item}
</div>
@@ -174,7 +177,7 @@ export default () => {
Heading.extend({
draggable: true,
addNodeView() {
return ReactNodeViewRenderer((props) => {
return ReactNodeViewRenderer(props => {
return (
<NodeViewWrapper>
<div className="heading">
@@ -193,7 +196,7 @@ export default () => {
</NodeViewWrapper>
)
})
}
},
}),
Mention.configure({
suggestion: {
@@ -238,45 +241,45 @@ export default () => {
reactRenderer.destroy()
},
}
}
},
},
})
}),
],
content: `
<h1>heading</h1>
<h2>heading</h2>
<p>paragraph</p>
`,
// content: `
// <h2>
// Hi there,
// </h2>
// <p>
// this is a basic <em>basic</em> example of <strong>tiptap</strong>. Sure, there are all kind of basic text styles youd probably expect from a text editor. But wait until you see the lists:
// </p>
// <ul>
// <li>
// Thats a bullet list with one …
// </li>
// <li>
// … or two list items.
// </li>
// </ul>
// <p>
// Isnt that great? And all of that is editable. But wait, theres more. Lets try a code block:
// </p>
// <pre><code class="language-css">body {
// display: none;
// }</code></pre>
// <p>
// I know, I know, this is impressive. Its only the tip of the iceberg though. Give it a try and click a little bit around. Dont forget to check the other examples too.
// </p>
// <blockquote>
// Wow, thats amazing. Good work, boy! 👏
// <br />
// — Mom
// </blockquote>
// `,
// content: `
// <h2>
// Hi there,
// </h2>
// <p>
// this is a basic <em>basic</em> example of <strong>tiptap</strong>. Sure, there are all kind of basic text styles youd probably expect from a text editor. But wait until you see the lists:
// </p>
// <ul>
// <li>
// Thats a bullet list with one …
// </li>
// <li>
// … or two list items.
// </li>
// </ul>
// <p>
// Isnt that great? And all of that is editable. But wait, theres more. Lets try a code block:
// </p>
// <pre><code class="language-css">body {
// display: none;
// }</code></pre>
// <p>
// I know, I know, this is impressive. Its only the tip of the iceberg though. Give it a try and click a little bit around. Dont forget to check the other examples too.
// </p>
// <blockquote>
// Wow, thats amazing. Good work, boy! 👏
// <br />
// — Mom
// </blockquote>
// `,
})
return (