From 62f42a229f9846940e3249aacfbcecefe22006e5 Mon Sep 17 00:00:00 2001 From: Hans Pagel Date: Thu, 28 Jan 2021 11:58:10 +0100 Subject: [PATCH] [BREAKING CHANGE] change the default document type to `doc` --- docs/src/demos/Guide/Content/ExportJSON/index.spec.js | 2 +- docs/src/demos/Guide/Content/ExportJSON/index.vue | 2 +- docs/src/demos/Guide/Content/GenerateHTML/index.vue | 2 +- docs/src/demos/Nodes/Document/index.spec.js | 2 +- docs/src/demos/React/index.jsx | 2 +- docs/src/docPages/api/schema.md | 4 ++-- docs/src/docPages/overview/upgrade-guide.md | 4 +--- packages/extension-document/src/document.ts | 2 +- packages/html/src/example.js | 2 +- tests/cypress/integration/core/generateHTML.spec.ts | 2 +- 10 files changed, 11 insertions(+), 13 deletions(-) diff --git a/docs/src/demos/Guide/Content/ExportJSON/index.spec.js b/docs/src/demos/Guide/Content/ExportJSON/index.spec.js index 5c75fe73..22bb446e 100644 --- a/docs/src/demos/Guide/Content/ExportJSON/index.spec.js +++ b/docs/src/demos/Guide/Content/ExportJSON/index.spec.js @@ -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', diff --git a/docs/src/demos/Guide/Content/ExportJSON/index.vue b/docs/src/demos/Guide/Content/ExportJSON/index.vue index 63ccecb5..e51532bf 100644 --- a/docs/src/demos/Guide/Content/ExportJSON/index.vue +++ b/docs/src/demos/Guide/Content/ExportJSON/index.vue @@ -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: [ diff --git a/docs/src/demos/Guide/Content/GenerateHTML/index.vue b/docs/src/demos/Guide/Content/GenerateHTML/index.vue index 9e4f3171..3f04d5d9 100644 --- a/docs/src/demos/Guide/Content/GenerateHTML/index.vue +++ b/docs/src/demos/Guide/Content/GenerateHTML/index.vue @@ -14,7 +14,7 @@ export default { return { output: '', json: { - type: 'document', + type: 'doc', content: [ { type: 'paragraph', diff --git a/docs/src/demos/Nodes/Document/index.spec.js b/docs/src/demos/Nodes/Document/index.spec.js index d8d8845e..6f7a5abe 100644 --- a/docs/src/demos/Nodes/Document/index.spec.js +++ b/docs/src/demos/Nodes/Document/index.spec.js @@ -14,7 +14,7 @@ context('/demos/Nodes/Document', () => { const json = editor.getJSON() expect(json).to.deep.equal({ - type: 'document', + type: 'doc', content: [ { type: 'paragraph', diff --git a/docs/src/demos/React/index.jsx b/docs/src/demos/React/index.jsx index c8a4fd02..021ac371 100644 --- a/docs/src/demos/React/index.jsx +++ b/docs/src/demos/React/index.jsx @@ -24,7 +24,7 @@ const MenuBar = () => { export default () => { const [value, setValue] = useState({ - type: 'document', + type: 'doc', content: [ { type: 'paragraph', diff --git a/docs/src/docPages/api/schema.md b/docs/src/docPages/api/schema.md index ff974210..1e0a26df 100644 --- a/docs/src/docPages/api/schema.md +++ b/docs/src/docPages/api/schema.md @@ -32,7 +32,7 @@ When you’ll work with the provided extensions only, you don’t 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+', }) diff --git a/docs/src/docPages/overview/upgrade-guide.md b/docs/src/docPages/overview/upgrade-guide.md index a493a28a..acc0c661 100644 --- a/docs/src/docPages/overview/upgrade-guide.md +++ b/docs/src/docPages/overview/upgrade-guide.md @@ -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 don’t 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 there’s 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 there’s 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 | | --------------------- | ---------------------- | diff --git a/packages/extension-document/src/document.ts b/packages/extension-document/src/document.ts index b87567b5..bd9c69c1 100644 --- a/packages/extension-document/src/document.ts +++ b/packages/extension-document/src/document.ts @@ -1,7 +1,7 @@ import { Node } from '@tiptap/core' export const Document = Node.create({ - name: 'document', + name: 'doc', topNode: true, content: 'block+', }) diff --git a/packages/html/src/example.js b/packages/html/src/example.js index 058b0580..80ac7078 100644 --- a/packages/html/src/example.js +++ b/packages/html/src/example.js @@ -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: { diff --git a/tests/cypress/integration/core/generateHTML.spec.ts b/tests/cypress/integration/core/generateHTML.spec.ts index 39bfacd2..1cf1a467 100644 --- a/tests/cypress/integration/core/generateHTML.spec.ts +++ b/tests/cypress/integration/core/generateHTML.spec.ts @@ -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: [{