mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-27 14:59:27 +08:00
[BREAKING CHANGE] change the default document type to doc
This commit is contained in:
parent
a885669929
commit
62f42a229f
@ -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',
|
||||
|
@ -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: [
|
||||
|
@ -14,7 +14,7 @@ export default {
|
||||
return {
|
||||
output: '',
|
||||
json: {
|
||||
type: 'document',
|
||||
type: 'doc',
|
||||
content: [
|
||||
{
|
||||
type: 'paragraph',
|
||||
|
@ -14,7 +14,7 @@ context('/demos/Nodes/Document', () => {
|
||||
const json = editor.getJSON()
|
||||
|
||||
expect(json).to.deep.equal({
|
||||
type: 'document',
|
||||
type: 'doc',
|
||||
content: [
|
||||
{
|
||||
type: 'paragraph',
|
||||
|
@ -24,7 +24,7 @@ const MenuBar = () => {
|
||||
|
||||
export default () => {
|
||||
const [value, setValue] = useState({
|
||||
type: 'document',
|
||||
type: 'doc',
|
||||
content: [
|
||||
{
|
||||
type: 'paragraph',
|
||||
|
@ -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+',
|
||||
})
|
||||
|
@ -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 |
|
||||
| --------------------- | ---------------------- |
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { Node } from '@tiptap/core'
|
||||
|
||||
export const Document = Node.create({
|
||||
name: 'document',
|
||||
name: 'doc',
|
||||
topNode: true,
|
||||
content: 'block+',
|
||||
})
|
||||
|
@ -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: {
|
||||
|
@ -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: [{
|
||||
|
Loading…
Reference in New Issue
Block a user