[BREAKING CHANGE] change the default document type to doc

This commit is contained in:
Hans Pagel 2021-01-28 11:58:10 +01:00
parent a885669929
commit 62f42a229f
10 changed files with 11 additions and 13 deletions

View File

@ -14,7 +14,7 @@ context('/demos/Guide/Content/ExportJSON', () => {
const json = editor.getJSON()
expect(json).to.deep.equal({
type: 'document',
type: 'doc',
content: [
{
type: 'paragraph',

View File

@ -62,7 +62,7 @@ export default {
setContent() {
// You can pass a JSON document to the editor.
this.editor.commands.setContent({
type: 'document',
type: 'doc',
content: [{
type: 'paragraph',
content: [

View File

@ -14,7 +14,7 @@ export default {
return {
output: '',
json: {
type: 'document',
type: 'doc',
content: [
{
type: 'paragraph',

View File

@ -14,7 +14,7 @@ context('/demos/Nodes/Document', () => {
const json = editor.getJSON()
expect(json).to.deep.equal({
type: 'document',
type: 'doc',
content: [
{
type: 'paragraph',

View File

@ -24,7 +24,7 @@ const MenuBar = () => {
export default () => {
const [value, setValue] = useState({
type: 'document',
type: 'doc',
content: [
{
type: 'paragraph',

View File

@ -32,7 +32,7 @@ When youll work with the provided extensions only, you dont have to care t
}
```
We register three nodes here. `document`, `paragraph` and `text`. `document` is the root node which allows one or more block nodes as children (`content: 'block+'`). Since `paragraph` is in the group of block nodes (`group: 'block'`) our document can only contain paragraphs. Our paragraphs allow zero or more inline nodes as children (`content: 'inline*'`) so there can only be `text` in it. `parseDOM` defines how a node can be parsed from pasted HTML. `toDOM` defines how it will be rendered in the DOM.
We register three nodes here. `doc`, `paragraph` and `text`. `doc` is the root node which allows one or more block nodes as children (`content: 'block+'`). Since `paragraph` is in the group of block nodes (`group: 'block'`) our document can only contain paragraphs. Our paragraphs allow zero or more inline nodes as children (`content: 'inline*'`) so there can only be `text` in it. `parseDOM` defines how a node can be parsed from pasted HTML. `toDOM` defines how it will be rendered in the DOM.
In tiptap every node, mark and extension is living in its own file. This allows us to split the logic. Under the hood the whole schema will be merged together:
@ -41,7 +41,7 @@ In tiptap every node, mark and extension is living in its own file. This allows
import { Node } from '@tiptap/core'
const Document = Node.create({
name: 'document',
name: 'doc',
topNode: true,
content: 'block+',
})

View File

@ -53,9 +53,7 @@ new Editor({
And we removed some settings: `dropCursor`, `enableDropCursor`, and `enableGapCursor`. Those are separate extensions now: [`Dropcursor`](/api/extensions/dropcursor) and [`Gapcursor`](/api/extensions/gapcursor). You probably want to load them, but if you dont just ignore me.
### New names for most extensions
**We renamed the default [`Document`](/api/nodes/document) type from `doc` to `document`.** To keep it like that, use your own implementation of the [`Document`](/api/nodes/document) node or migrate the stored JSON to use the new name.
Also, we switched to lowerCamelCase, so theres a lot that changed. If you stored your content as JSON you need to loop through it and rename a lot of types. Sorry for that one.
We switched to lowerCamelCase, so theres a lot type names that changed. If you stored your content as JSON you need to loop through it and rename them. Sorry for that one.
| Old type | New type |
| --------------------- | ---------------------- |

View File

@ -1,7 +1,7 @@
import { Node } from '@tiptap/core'
export const Document = Node.create({
name: 'document',
name: 'doc',
topNode: true,
content: 'block+',
})

View File

@ -6,7 +6,7 @@ import Text from '@tiptap/extension-text'
// eslint-disable-next-line
const html = generateHTML({
type: 'document',
type: 'doc',
content: [{
type: 'paragraph',
attrs: {

View File

@ -8,7 +8,7 @@ import Text from '@tiptap/extension-text'
describe('generateHTML', () => {
it('generate HTML from JSON without an editor instance', () => {
const json = {
type: 'document',
type: 'doc',
content: [{
type: 'paragraph',
content: [{