Skip to content

Commit

Permalink
update tiptap, and move away from starter kit. Add setting for disabl…
Browse files Browse the repository at this point in the history
…ing shorthand for ordered list
  • Loading branch information
Mikkel Holm Jensen committed Oct 19, 2022
1 parent f28dc5f commit 1704023
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 25 deletions.
48 changes: 39 additions & 9 deletions admin/src/components/Wysiwyg/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ import TableHeaderExtension from '@tiptap/extension-table-header'
import TextStyleExtension from '@tiptap/extension-text-style'
import CharacterCountExtension from '@tiptap/extension-character-count'
import YouTubeExtension from '@tiptap/extension-youtube'
import CodeExtension from '@tiptap/extension-code'
import BoldExtension from '@tiptap/extension-bold'
import ItalicExtension from '@tiptap/extension-italic'
import StrikeExtension, {Strike} from '@tiptap/extension-strike'
import OrderedListExtension from "@tiptap/extension-ordered-list"
import BulletListExtension from '@tiptap/extension-bullet-list'
import ListItemExtension from '@tiptap/extension-list-item'
import GapcursorExtension from '@tiptap/extension-gapcursor'
import BlockquoteExtension from '@tiptap/extension-blockquote'
import CodeBlockExtension from '@tiptap/extension-code-block'
import DocumentExtension from '@tiptap/extension-document'
import HardBreakExtension from '@tiptap/extension-hard-break'
import HeadingExtension from '@tiptap/extension-heading'
import HorizontalRuleExtension from '@tiptap/extension-horizontal-rule'
import ParagraphExtension from '@tiptap/extension-paragraph'
import TextExtension from '@tiptap/extension-text'
import { Color as ColorExtension } from '@tiptap/extension-color'
import {mergeDeep} from "../../utils/merge";

Expand Down Expand Up @@ -95,6 +111,11 @@ const CSSColumnsExtension = Extension.create({
}
})

const CustomOrderedList = OrderedListExtension.extend({
addInputRules() {
return []
}
})

const WysiwygContent = ({ name, onChange, value, intlLabel, labelAction, disabled, error, description, required, settings }) => {
const { formatMessage } = useIntl();
Expand All @@ -103,14 +124,23 @@ const WysiwygContent = ({ name, onChange, value, intlLabel, labelAction, disable
const editor = useEditor({
extensions: [
// Text
StarterKit.configure({
gapcursor: true,
code: settings.code,
codeBlock: settings.code,
blockquote: settings.blockquote,
horizontalRule: settings.horizontal,
hardBreak: settings.hardbreak
}),
DocumentExtension,
ParagraphExtension,
TextExtension,
BoldExtension,
StrikeExtension,
ItalicExtension,
GapcursorExtension,
ListItemExtension,
BulletListExtension,

settings.disableOrderedListShorthand ? CustomOrderedList : OrderedListExtension,
settings.code ? CodeBlockExtension : null,
settings.code ? CodeExtension : null,
settings.blockquote ? BlockquoteExtension : null,
settings.horizontalRule ? HorizontalRuleExtension : null,
settings.hardBreak ? HardBreakExtension : null,

UnderlineExtension,
TextAlignExtension.configure({
types: ['heading', 'paragraph'],
Expand Down Expand Up @@ -175,7 +205,7 @@ const WysiwygContent = ({ name, onChange, value, intlLabel, labelAction, disable
<Box>
<FieldLabel action={labelAction} required={required}> {formatMessage(intlLabel)}</FieldLabel>
</Box>
{editor &&
{editor &&
<Editor
key="editor"
disabled={disabled}
Expand Down
17 changes: 17 additions & 0 deletions admin/src/pages/HomePage/Tabs/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,23 @@ export default ({errors, values, handleChange, isSubmitting}) => {
</Box>
<Box></Box>
<Box></Box>

<Box>
<ToggleInput
label="Disable shorthand for ordered list"
hint="Normally you can type: 1. and after the space it converts it to a ordered list. This can be annoying when typing dates."
size="S"
name="lists"
onLabel="Enabled"
offLabel="Disabled"
checked={values.disableOrderedListShorthand}
onChange={e => handleChange({
target: {
name: 'disableOrderedListShorthand',
value: !values.disableOrderedListShorthand
}
})}/>
</Box>
</GridLayout>
</Fragment>
)
Expand Down
45 changes: 29 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,35 @@
"homepage": "https://github.com/dasmikko/strapi-tiptap-editor#readme",
"dependencies": {
"@strapi/icons": "1.2.1",
"@tiptap/core": "2.0.0-beta.195",
"@tiptap/extension-character-count": "2.0.0-beta.195",
"@tiptap/extension-color": "2.0.0-beta.195",
"@tiptap/extension-gapcursor": "2.0.0-beta.195",
"@tiptap/extension-image": "2.0.0-beta.195",
"@tiptap/extension-link": "2.0.0-beta.195",
"@tiptap/extension-table": "2.0.0-beta.195",
"@tiptap/extension-table-cell": "2.0.0-beta.195",
"@tiptap/extension-table-header": "2.0.0-beta.195",
"@tiptap/extension-table-row": "2.0.0-beta.195",
"@tiptap/extension-text-align": "2.0.0-beta.195",
"@tiptap/extension-text-style": "2.0.0-beta.195",
"@tiptap/extension-underline": "2.0.0-beta.195",
"@tiptap/extension-youtube": "2.0.0-beta.195",
"@tiptap/react": "2.0.0-beta.195",
"@tiptap/starter-kit": "2.0.0-beta.195",
"@tiptap/core": "2.0.0-beta.199",
"@tiptap/extension-blockquote": "2.0.0-beta.199",
"@tiptap/extension-bold": "2.0.0-beta.199",
"@tiptap/extension-bullet-list": "2.0.0-beta.199",
"@tiptap/extension-character-count": "2.0.0-beta.199",
"@tiptap/extension-code": "2.0.0-beta.199",
"@tiptap/extension-code-block": "2.0.0-beta.199",
"@tiptap/extension-color": "2.0.0-beta.199",
"@tiptap/extension-document": "2.0.0-beta.199",
"@tiptap/extension-gapcursor": "2.0.0-beta.199",
"@tiptap/extension-hard-break": "2.0.0-beta.199",
"@tiptap/extension-heading": "2.0.0-beta.199",
"@tiptap/extension-horizontal-rule": "2.0.0-beta.199",
"@tiptap/extension-image": "2.0.0-beta.199",
"@tiptap/extension-italic": "2.0.0-beta.199",
"@tiptap/extension-link": "2.0.0-beta.199",
"@tiptap/extension-list-item": "2.0.0-beta.199",
"@tiptap/extension-ordered-list": "2.0.0-beta.199",
"@tiptap/extension-paragraph": "2.0.0-beta.199",
"@tiptap/extension-strike": "2.0.0-beta.199",
"@tiptap/extension-table": "2.0.0-beta.199",
"@tiptap/extension-table-cell": "2.0.0-beta.199",
"@tiptap/extension-table-header": "2.0.0-beta.199",
"@tiptap/extension-table-row": "2.0.0-beta.199",
"@tiptap/extension-text": "2.0.0-beta.199",
"@tiptap/extension-text-align": "2.0.0-beta.199",
"@tiptap/extension-text-style": "2.0.0-beta.199",
"@tiptap/extension-underline": "2.0.0-beta.199",
"@tiptap/extension-youtube": "2.0.0-beta.199",
"react-icons": "4.4.0"
},
"peerDependencies": {
Expand Down
1 change: 1 addition & 0 deletions utils/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
color: true,
align: ['left', 'center', 'right'],
lists: ['ol', 'ul'],
disableOrderedListShorthand: false,
columns: ['two', 'three'],
table: true,
hardbreak: true,
Expand Down

0 comments on commit 1704023

Please sign in to comment.