-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add insertContent() command, deprecate insertText(), insertHTML…
…() and insertNode()
- Loading branch information
1 parent
63acc57
commit b8d9b7d
Showing
21 changed files
with
198 additions
and
113 deletions.
There are no files selected for viewing
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
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,23 @@ | ||
# insertContent | ||
|
||
## Parameters | ||
|
||
## Usage | ||
|
||
```js | ||
this.editor.commands.insertContent('text') | ||
this.editor.commands.insertContent('<p>HTML</p>') | ||
this.editor.commands.insertContent({ | ||
type: 'heading', | ||
attrs: { | ||
level: 2, | ||
}, | ||
content: [ | ||
{ | ||
type: 'text', | ||
text: 'nested nodes', | ||
}, | ||
], | ||
}) | ||
``` | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
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
10 changes: 5 additions & 5 deletions
10
...rc/tests/core/commands/insertHTML.spec.js → ...tests/core/commands/insertContent.spec.js
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,35 @@ | ||
import createNodeFromContent from '../helpers/createNodeFromContent' | ||
import selectionToInsertionEnd from '../helpers/selectionToInsertionEnd' | ||
import { Command, RawCommands, Content } from '../types' | ||
|
||
declare module '@tiptap/core' { | ||
interface Commands { | ||
insertContent: { | ||
/** | ||
* Insert a node or string of HTML at the current position. | ||
*/ | ||
insertContent: (value: Content) => Command, | ||
} | ||
} | ||
} | ||
|
||
export const insertContent: RawCommands['insertContent'] = value => ({ tr, dispatch, editor }) => { | ||
if (dispatch) { | ||
const content = createNodeFromContent(value, editor.schema) | ||
|
||
if (typeof content === 'string') { | ||
tr.insertText(content) | ||
|
||
return true | ||
} | ||
|
||
if (!tr.selection.empty) { | ||
tr.deleteSelection() | ||
} | ||
|
||
tr.insert(tr.selection.anchor, content) | ||
selectionToInsertionEnd(tr, tr.steps.length - 1, -1) | ||
} | ||
|
||
return true | ||
} |
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
Oops, something went wrong.