@contentful/contentful-slatejs-adapter
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -88,7 +88,7 @@ 'use strict'; | ||
function convertText(node) { | ||
return node.leaves.map(function (leave) { return ({ | ||
return node.leaves.map(function (leaf) { return ({ | ||
nodeClass: 'text', | ||
nodeType: 'text', | ||
value: leave.text, | ||
marks: leave.marks, | ||
value: leaf.text, | ||
marks: leaf.marks || [], | ||
data: node.data, | ||
@@ -95,0 +95,0 @@ }); }); |
@@ -19,6 +19,16 @@ "use strict"; | ||
testFactory('empty document', contentful.document(), slate.document()); | ||
testFactory('document with paragraph', contentful.document(contentful.block('paragraph', contentful.text(''))), slate.document(slate.block('paragraph', slate.text(slate.leaf(''))))); | ||
testFactory('document with block', contentful.document(contentful.block('paragraph', contentful.text(''))), slate.document(slate.block('paragraph', slate.text(slate.leaf(''))))); | ||
testFactory('paragraph with inline', contentful.document(contentful.block('paragraph', contentful.inline('hyperlink'))), slate.document(slate.block('paragraph', slate.inline('hyperlink')))); | ||
testFactory('paragraph with text', contentful.document(contentful.block('paragraph', contentful.text('hi'))), slate.document(slate.block('paragraph', slate.text(slate.leaf('hi'))))); | ||
testFactory('text with mark', contentful.document(contentful.block('paragraph', contentful.text('this'), contentful.text('is', contentful.mark('bold')))), slate.document(slate.block('paragraph', slate.text(slate.leaf('this')), slate.text(slate.leaf('is', contentful.mark('bold')))))); | ||
testFactory('text with marks', contentful.document(contentful.block('paragraph', contentful.text('this'), contentful.text('is', contentful.mark('bold')))), slate.document(slate.block('paragraph', slate.text(slate.leaf('this')), slate.text(slate.leaf('is', contentful.mark('bold')))))); | ||
it('adds a default value to marks if undefined', function () { | ||
var slateDoc = slate.document(slate.block('paragraph', slate.text({ marks: undefined, object: 'leaf', text: 'Hi' }))); | ||
var ctflDoc = slatejs_to_contentful_adapter_1.default(slateDoc); | ||
expect(ctflDoc).toEqual(contentful.document(contentful.block('paragraph', { | ||
nodeType: 'text', | ||
nodeClass: 'text', | ||
marks: [], | ||
value: 'Hi', | ||
}))); | ||
}); | ||
testFactory('text with multiple marks', contentful.document(contentful.block('paragraph', contentful.text('this'), contentful.text('is', contentful.mark('bold')), contentful.text('huge', contentful.mark('bold'), contentful.mark('italic')))), slate.document(slate.block('paragraph', slate.text(slate.leaf('this')), slate.text(slate.leaf('is', slate.mark('bold'))), slate.text(slate.leaf('huge', slate.mark('bold'), slate.mark('italic')))))); | ||
@@ -25,0 +35,0 @@ testFactory('document with nested blocks', contentful.document(contentful.block('paragraph', contentful.text('this is a test', contentful.mark('bold')), contentful.text('paragraph', contentful.mark('underline'))), contentful.block('block', contentful.block('block', contentful.text('this is it')))), slate.document(slate.block('paragraph', slate.text(slate.leaf('this is a test', slate.mark('bold'))), slate.text(slate.leaf('paragraph', slate.mark('underline')))), slate.block('block', slate.block('block', slate.text(slate.leaf('this is it')))))); |
@@ -38,7 +38,7 @@ "use strict"; | ||
function convertText(node) { | ||
return node.leaves.map(function (leave) { return ({ | ||
return node.leaves.map(function (leaf) { return ({ | ||
nodeClass: 'text', | ||
nodeType: 'text', | ||
value: leave.text, | ||
marks: leave.marks, | ||
value: leaf.text, | ||
marks: leaf.marks || [], | ||
data: node.data, | ||
@@ -45,0 +45,0 @@ }); }); |
export declare function document(...nodes: Slate.Block[]): Slate.Document; | ||
export declare function block(type: string, ...nodes: Array<Slate.Block | Slate.Inline | Slate.Text>): Slate.Block; | ||
export declare function inline(type: string, ...nodes: Array<Slate.Inline | Slate.Text>): Slate.Inline; | ||
export declare function text(...leaves: Slate.TextLeave[]): Slate.Text; | ||
export declare function leaf(value: string, ...marks: Slate.Mark[]): Slate.TextLeave; | ||
export declare function text(...leaves: Slate.TextLeaf[]): Slate.Text; | ||
export declare function leaf(value: string, ...marks: Slate.Mark[]): Slate.TextLeaf; | ||
export declare function mark(type: string): Slate.Mark; |
@@ -21,3 +21,3 @@ declare namespace Slate { | ||
object: 'text'; | ||
leaves: TextLeave[]; | ||
leaves: TextLeaf[]; | ||
} | ||
@@ -27,7 +27,7 @@ interface Mark { | ||
} | ||
interface TextLeave { | ||
interface TextLeaf { | ||
object: 'leaf'; | ||
text: string; | ||
marks: Mark[]; | ||
marks?: Mark[]; | ||
} | ||
} |
{ | ||
"name": "@contentful/contentful-slatejs-adapter", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "", | ||
@@ -32,2 +32,3 @@ "keywords": [], | ||
"travis-deploy-once": "travis-deploy-once --pro", | ||
"commitmsg": "validate-commit-msg", | ||
"precommit": "lint-staged" | ||
@@ -34,0 +35,0 @@ }, |
contentful-slatejs-adapter | ||
===== | ||
The library provides an adapter to convert Slate's Document to Contentful Document and vice-versa. | ||
```json | ||
@@ -101,1 +103,9 @@ { | ||
``` | ||
## Releases flow (Atomatic Releases) | ||
Automatic releases are possible thanks to [semantic release](https://github.com/semantic-release/semantic-release), which publishes the code automatically on npm and generates a changelog. | ||
We follow [angular commit format](https://gist.github.com/stephenparish/9941e89d80e2bc58a153#allowed-type) to generate a changelog. | ||
You'll need to use `npm run commit`, to create conventional commits. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
42868
537
111