Skip to content

Commit 326b2c3

Browse files
committed
refactor: remove dependency for optimized bundle
1 parent 2beda0d commit 326b2c3

File tree

6 files changed

+93
-9
lines changed

6 files changed

+93
-9
lines changed

package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,6 @@
113113
},
114114
"dependencies": {
115115
"@tiptap/core": "^2.5.8",
116-
"@tiptap/extension-document": "^2.5.8",
117-
"@tiptap/extension-paragraph": "^2.5.8",
118-
"@tiptap/extension-placeholder": "^2.5.8",
119-
"@tiptap/extension-text": "^2.5.8",
120116
"@tiptap/react": "^2.5.8"
121117
}
122118
}

src/MixInput.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import React, { type ForwardedRef, forwardRef, useEffect, useImperativeHandle, u
44

55
import { editorValueToMixInputValue, mixInputValueToEditorValue } from './utils'
66
import { EditorContent, useEditor } from '@tiptap/react'
7-
import Document from '@tiptap/extension-document'
8-
import Paragraph from '@tiptap/extension-paragraph'
9-
import Text from '@tiptap/extension-text'
7+
import Document from './extension-document'
8+
import Paragraph from './extension-paragraph'
9+
import Text from './extension-text'
1010
import Placeholder from '@tiptap/extension-placeholder'
11-
import TagExtension from './TagExtension'
11+
import Tag from './extension-tag'
1212
import { type MixInputProps, type MixInputRef, type MixInputValue } from './MixInputType'
1313

1414
const DEFAULT_TAG_ATTRS = {
@@ -49,11 +49,12 @@ const MixInput = forwardRef((props: MixInputProps, ref?: ForwardedRef<MixInputRe
4949
}),
5050
Text,
5151
Placeholder.configure({ placeholder }),
52-
TagExtension.configure({
52+
Tag.configure({
5353
tagClassName,
5454
attrs: { ...DEFAULT_TAG_ATTRS, ...tagAttrs },
5555
tagView,
5656
}),
57+
5758
],
5859
onUpdate: ({ editor }) => {
5960
if (disabled) return

src/extension-document.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Node } from '@tiptap/core'
2+
3+
/**
4+
* The default document node which represents the top level node of the editor.
5+
* @see https://tiptap.dev/api/nodes/document
6+
*/
7+
export default Node.create({
8+
name: 'doc',
9+
topNode: true,
10+
content: 'block+',
11+
})

src/extension-paragraph.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { mergeAttributes, Node } from '@tiptap/core'
2+
3+
export interface ParagraphOptions {
4+
/**
5+
* The HTML attributes for a paragraph node.
6+
* @default {}
7+
* @example { class: 'foo' }
8+
*/
9+
HTMLAttributes: Record<string, any>,
10+
}
11+
12+
declare module '@tiptap/core' {
13+
interface Commands<ReturnType> {
14+
paragraph: {
15+
/**
16+
* Toggle a paragraph
17+
* @example editor.commands.toggleParagraph()
18+
*/
19+
setParagraph: () => ReturnType,
20+
}
21+
}
22+
}
23+
24+
/**
25+
* This extension allows you to create paragraphs.
26+
* @see https://www.tiptap.dev/api/nodes/paragraph
27+
*/
28+
export default Node.create<ParagraphOptions>({
29+
name: 'paragraph',
30+
31+
priority: 1000,
32+
33+
addOptions() {
34+
return {
35+
HTMLAttributes: {},
36+
}
37+
},
38+
39+
group: 'block',
40+
41+
content: 'inline*',
42+
43+
parseHTML() {
44+
return [
45+
{ tag: 'p' },
46+
]
47+
},
48+
49+
renderHTML({ HTMLAttributes }) {
50+
return ['p', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
51+
},
52+
53+
addCommands() {
54+
return {
55+
setParagraph: () => ({ commands }) => {
56+
return commands.setNode(this.name)
57+
},
58+
}
59+
},
60+
61+
addKeyboardShortcuts() {
62+
return {
63+
'Mod-Alt-0': () => this.editor.commands.setParagraph(),
64+
}
65+
},
66+
})
File renamed without changes.

src/extension-text.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Node } from '@tiptap/core'
2+
3+
/**
4+
* This extension allows you to create text nodes.
5+
* @see https://www.tiptap.dev/api/nodes/text
6+
*/
7+
export default Node.create({
8+
name: 'text',
9+
group: 'inline',
10+
})

0 commit comments

Comments
 (0)