@contentful/contentful-slatejs-adapter
Advanced tools
Comparing version 1.2.0 to 2.0.0
@@ -1,4 +0,10 @@ | ||
import flatmap from 'lodash.flatmap'; | ||
import omit from 'lodash.omit'; | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var flatmap = _interopDefault(require('lodash.flatmap')); | ||
var Contentful = require('@contentful/structured-text-types'); | ||
function toSlatejsDocument(ctfDocument) { | ||
@@ -12,3 +18,3 @@ return { | ||
var nodes = []; | ||
switch (node.category) { | ||
switch (node.nodeClass) { | ||
case 'block': | ||
@@ -18,16 +24,12 @@ case 'inline': | ||
var childNodes = flatmap(contentfulBlock.content, convertNode); | ||
var data = omit(contentfulBlock, ['category', 'type', 'content']); | ||
var slateBlock = { | ||
object: contentfulBlock.category, | ||
type: contentfulBlock.type, | ||
object: contentfulBlock.nodeClass, | ||
type: contentfulBlock.nodeType, | ||
nodes: childNodes, | ||
data: contentfulBlock.data, | ||
}; | ||
if (Object.keys(data).length > 0) { | ||
slateBlock.data = data; | ||
} | ||
nodes.push(slateBlock); | ||
break; | ||
case 'text': | ||
var _a = node, marks = _a.marks, value = _a.value; | ||
var textData = omit(node, ['category', 'type', 'value', 'marks']); | ||
var _a = node, marks = _a.marks, value = _a.value, data = _a.data; | ||
var slateText = { | ||
@@ -42,6 +44,4 @@ object: 'text', | ||
], | ||
data: data, | ||
}; | ||
if (Object.keys(textData).length > 0) { | ||
slateText.data = textData; | ||
} | ||
nodes.push(slateText); | ||
@@ -59,85 +59,6 @@ break; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */ | ||
var __assign = function() { | ||
__assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
function unwrapExports (x) { | ||
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; | ||
} | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
var structuredTextTypes_es5 = createCommonjsModule(function (module, exports) { | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
/** | ||
* Map of all Contentful block types. Blocks contain inline or block nodes. | ||
*/ | ||
var DOCUMENT = 'document'; | ||
// Classic blocks | ||
var PARAGRAPH = 'paragraph'; | ||
// Headings | ||
var HEADING_1 = 'header-one'; | ||
var HEADING_2 = 'header-two'; | ||
var ENTRY_LINK = 'entry-link-block'; | ||
var blocks = /*#__PURE__*/Object.freeze({ | ||
DOCUMENT: DOCUMENT, | ||
PARAGRAPH: PARAGRAPH, | ||
HEADING_1: HEADING_1, | ||
HEADING_2: HEADING_2, | ||
ENTRY_LINK: ENTRY_LINK | ||
}); | ||
var BOLD = 'bold'; | ||
var ITALIC = 'italic'; | ||
var UNDERLINED = 'underlined'; | ||
var marks = /*#__PURE__*/Object.freeze({ | ||
BOLD: BOLD, | ||
ITALIC: ITALIC, | ||
UNDERLINED: UNDERLINED | ||
}); | ||
var BLOCKS = blocks; | ||
var MARKS = marks; | ||
exports.BLOCKS = BLOCKS; | ||
exports.MARKS = MARKS; | ||
}); | ||
unwrapExports(structuredTextTypes_es5); | ||
var structuredTextTypes_es5_1 = structuredTextTypes_es5.BLOCKS; | ||
var structuredTextTypes_es5_2 = structuredTextTypes_es5.MARKS; | ||
function toContentfulDocument(slateDocument) { | ||
return { | ||
category: 'document', | ||
type: structuredTextTypes_es5_1.DOCUMENT, | ||
nodeClass: 'document', | ||
nodeType: Contentful.BLOCKS.DOCUMENT, | ||
content: flatmap(slateDocument.nodes, convertNode$1), | ||
@@ -153,3 +74,8 @@ }; | ||
var content = flatmap(slateBlock.nodes, convertNode$1); | ||
var contentfulBlock = __assign({ category: slateBlock.object, type: slateBlock.type, content: content }, slateBlock.data); | ||
var contentfulBlock = { | ||
nodeClass: slateBlock.object, | ||
nodeType: slateBlock.type, | ||
content: content, | ||
data: slateBlock.data, | ||
}; | ||
nodes.push(contentfulBlock); | ||
@@ -167,3 +93,9 @@ break; | ||
function convertText(node) { | ||
return node.leaves.map(function (leave) { return (__assign({ category: 'text', type: 'text', value: leave.text, marks: leave.marks }, node.data)); }); | ||
return node.leaves.map(function (leave) { return ({ | ||
nodeClass: 'text', | ||
nodeType: 'text', | ||
value: leave.text, | ||
marks: leave.marks, | ||
data: node.data, | ||
}); }); | ||
} | ||
@@ -174,3 +106,4 @@ function assertUnreachable$1(object) { | ||
export { toSlatejsDocument, toContentfulDocument }; | ||
exports.toSlatejsDocument = toSlatejsDocument; | ||
exports.toContentfulDocument = toContentfulDocument; | ||
//# sourceMappingURL=contentful-slatejs-adapter.es5.js.map |
@@ -10,4 +10,4 @@ "use strict"; | ||
return { | ||
category: 'document', | ||
type: Contentful.BLOCKS.DOCUMENT, | ||
nodeClass: 'document', | ||
nodeType: Contentful.BLOCKS.DOCUMENT, | ||
content: content, | ||
@@ -17,3 +17,3 @@ }; | ||
exports.document = document; | ||
function block(type) { | ||
function block(nodeType) { | ||
var content = []; | ||
@@ -24,4 +24,4 @@ for (var _i = 1; _i < arguments.length; _i++) { | ||
return { | ||
category: 'block', | ||
type: type, | ||
nodeClass: 'block', | ||
nodeType: nodeType, | ||
content: content, | ||
@@ -31,3 +31,3 @@ }; | ||
exports.block = block; | ||
function inline(type) { | ||
function inline(nodeType) { | ||
var content = []; | ||
@@ -38,4 +38,4 @@ for (var _i = 1; _i < arguments.length; _i++) { | ||
return { | ||
category: 'inline', | ||
type: type, | ||
nodeClass: 'inline', | ||
nodeType: nodeType, | ||
content: content, | ||
@@ -51,4 +51,4 @@ }; | ||
return { | ||
category: 'text', | ||
type: 'text', | ||
nodeClass: 'text', | ||
nodeType: 'text', | ||
marks: marks, | ||
@@ -55,0 +55,0 @@ value: value, |
@@ -28,10 +28,10 @@ "use strict"; | ||
testFactory('data in block', { | ||
category: 'document', | ||
type: Contentful.BLOCKS.DOCUMENT, | ||
nodeClass: 'document', | ||
nodeType: Contentful.BLOCKS.DOCUMENT, | ||
content: [ | ||
{ | ||
category: 'block', | ||
type: 'paragraph', | ||
a: 1, | ||
nodeClass: 'block', | ||
nodeType: 'paragraph', | ||
content: [], | ||
data: { a: 1 }, | ||
}, | ||
@@ -51,14 +51,14 @@ ], | ||
testFactory('data in inline', { | ||
category: 'document', | ||
type: Contentful.BLOCKS.DOCUMENT, | ||
nodeClass: 'document', | ||
nodeType: Contentful.BLOCKS.DOCUMENT, | ||
content: [ | ||
{ | ||
category: 'block', | ||
type: 'paragraph', | ||
a: 1, | ||
nodeClass: 'block', | ||
nodeType: 'paragraph', | ||
data: { a: 1 }, | ||
content: [ | ||
{ | ||
category: 'inline', | ||
type: 'hyperlink', | ||
a: 2, | ||
nodeClass: 'inline', | ||
nodeType: 'hyperlink', | ||
data: { a: 2 }, | ||
content: [], | ||
@@ -90,21 +90,21 @@ }, | ||
testFactory('data in text', { | ||
category: 'document', | ||
type: Contentful.BLOCKS.DOCUMENT, | ||
nodeClass: 'document', | ||
nodeType: Contentful.BLOCKS.DOCUMENT, | ||
content: [ | ||
{ | ||
category: 'block', | ||
type: 'paragraph', | ||
a: 1, | ||
nodeClass: 'block', | ||
nodeType: 'paragraph', | ||
data: { a: 1 }, | ||
content: [ | ||
{ | ||
category: 'inline', | ||
type: 'hyperlink', | ||
a: 2, | ||
nodeClass: 'inline', | ||
nodeType: 'hyperlink', | ||
data: { a: 2 }, | ||
content: [], | ||
}, | ||
{ | ||
category: 'text', | ||
type: 'text', | ||
nodeClass: 'text', | ||
nodeType: 'text', | ||
marks: [], | ||
a: 3, | ||
data: { a: 3 }, | ||
value: 'YO', | ||
@@ -111,0 +111,0 @@ }, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var lodash_flatmap_1 = require("lodash.flatmap"); | ||
var lodash_omit_1 = require("lodash.omit"); | ||
function toSlatejsDocument(ctfDocument) { | ||
@@ -14,3 +13,3 @@ return { | ||
var nodes = []; | ||
switch (node.category) { | ||
switch (node.nodeClass) { | ||
case 'block': | ||
@@ -20,16 +19,12 @@ case 'inline': | ||
var childNodes = lodash_flatmap_1.default(contentfulBlock.content, convertNode); | ||
var data = lodash_omit_1.default(contentfulBlock, ['category', 'type', 'content']); | ||
var slateBlock = { | ||
object: contentfulBlock.category, | ||
type: contentfulBlock.type, | ||
object: contentfulBlock.nodeClass, | ||
type: contentfulBlock.nodeType, | ||
nodes: childNodes, | ||
data: contentfulBlock.data, | ||
}; | ||
if (Object.keys(data).length > 0) { | ||
slateBlock.data = data; | ||
} | ||
nodes.push(slateBlock); | ||
break; | ||
case 'text': | ||
var _a = node, marks = _a.marks, value = _a.value; | ||
var textData = lodash_omit_1.default(node, ['category', 'type', 'value', 'marks']); | ||
var _a = node, marks = _a.marks, value = _a.value, data = _a.data; | ||
var slateText = { | ||
@@ -44,6 +39,4 @@ object: 'text', | ||
], | ||
data: data, | ||
}; | ||
if (Object.keys(textData).length > 0) { | ||
slateText.data = textData; | ||
} | ||
nodes.push(slateText); | ||
@@ -50,0 +43,0 @@ break; |
"use strict"; | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -15,4 +7,4 @@ var lodash_flatmap_1 = require("lodash.flatmap"); | ||
return { | ||
category: 'document', | ||
type: Contentful.BLOCKS.DOCUMENT, | ||
nodeClass: 'document', | ||
nodeType: Contentful.BLOCKS.DOCUMENT, | ||
content: lodash_flatmap_1.default(slateDocument.nodes, convertNode), | ||
@@ -29,3 +21,8 @@ }; | ||
var content = lodash_flatmap_1.default(slateBlock.nodes, convertNode); | ||
var contentfulBlock = __assign({ category: slateBlock.object, type: slateBlock.type, content: content }, slateBlock.data); | ||
var contentfulBlock = { | ||
nodeClass: slateBlock.object, | ||
nodeType: slateBlock.type, | ||
content: content, | ||
data: slateBlock.data, | ||
}; | ||
nodes.push(contentfulBlock); | ||
@@ -43,3 +40,9 @@ break; | ||
function convertText(node) { | ||
return node.leaves.map(function (leave) { return (__assign({ category: 'text', type: 'text', value: leave.text, marks: leave.marks }, node.data)); }); | ||
return node.leaves.map(function (leave) { return ({ | ||
nodeClass: 'text', | ||
nodeType: 'text', | ||
value: leave.text, | ||
marks: leave.marks, | ||
data: node.data, | ||
}); }); | ||
} | ||
@@ -46,0 +49,0 @@ function assertUnreachable(object) { |
import * as Contentful from '@contentful/structured-text-types'; | ||
export declare function document(...content: Contentful.Block[]): Contentful.Document; | ||
export declare function block(type: string, ...content: Array<Contentful.Block | Contentful.Inline | Contentful.Text>): Contentful.Block; | ||
export declare function inline(type: string, ...content: Array<Contentful.Inline | Contentful.Text>): Contentful.Inline; | ||
export declare function block(nodeType: string, ...content: Array<Contentful.Block | Contentful.Inline | Contentful.Text>): Contentful.Block; | ||
export declare function inline(nodeType: string, ...content: Array<Contentful.Inline | Contentful.Text>): Contentful.Inline; | ||
export declare function text(value: string, ...marks: Contentful.Mark[]): Contentful.Text; | ||
export declare function mark(type: string): Contentful.Mark; |
{ | ||
"name": "@contentful/contentful-slatejs-adapter", | ||
"version": "1.2.0", | ||
"version": "2.0.0", | ||
"description": "", | ||
@@ -59,6 +59,10 @@ "keywords": [], | ||
], | ||
"testPathIgnorePatterns": [ | ||
"/dist/" | ||
], | ||
"coveragePathIgnorePatterns": [ | ||
"/node_modules/", | ||
"/test/", | ||
"/__test__/" | ||
"/__test__/", | ||
"/dist/" | ||
], | ||
@@ -118,3 +122,3 @@ "coverageThreshold": { | ||
"dependencies": { | ||
"@contentful/structured-text-types": "^1.1.0", | ||
"@contentful/structured-text-types": "^2.0.0", | ||
"lodash.flatmap": "^4.5.0", | ||
@@ -121,0 +125,0 @@ "lodash.omit": "^4.5.0" |
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
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
29
0
41275
527
+ Added@contentful/structured-text-types@2.4.0(transitive)
- Removed@contentful/structured-text-types@1.1.0(transitive)