Socket
Socket
Sign inDemoInstall

@contentstack/utils

Package Overview
Dependencies
Maintainers
12
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contentstack/utils - npm Package Compare versions

Comparing version 1.3.0 to 1.3.1

173

dist/index.es.js

@@ -8,7 +8,7 @@ 'use strict';

text: attribute['#text'],
itemUid: attribute["data-sys-entry-uid"] || attribute["data-sys-asset-uid"],
itemUid: attribute['data-sys-entry-uid'] || attribute['data-sys-asset-uid'],
itemType: attribute.type,
styleType: attribute["sys-style-type"],
styleType: attribute['sys-style-type'],
attributes: attribute,
contentTypeUid: attribute["data-sys-content-type-uid"],
contentTypeUid: attribute['data-sys-content-type-uid'],
};

@@ -19,7 +19,7 @@ }

text: textNode.text,
itemUid: attribute["entry-uid"] || attribute["asset-uid"],
itemUid: attribute['entry-uid'] || attribute['asset-uid'],
itemType: attribute.type,
styleType: attribute["display-type"],
styleType: attribute['display-type'],
attributes: attribute,
contentTypeUid: attribute["content-type-uid"],
contentTypeUid: attribute['content-type-uid'],
};

@@ -360,2 +360,3 @@ }

MarkType["UNDERLINE"] = "underline";
MarkType["CLASSNAME_OR_ID"] = "classnameOrId";
MarkType["STRIKE_THROUGH"] = "strikethrough";

@@ -401,42 +402,42 @@ MarkType["INLINE_CODE"] = "inlineCode";

_a[NodeType$1.PARAGRAPH] = function (node, next) {
return "<p>".concat(next(node.children), "</p>");
return "<p".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</p>");
},
_a[NodeType$1.LINK] = function (node, next) {
if (node.attrs.target) {
return "<a href=\"".concat(node.attrs.href || node.attrs.url, "\" target=\"").concat(node.attrs.target, "\">").concat(next(node.children), "</a>");
return "<a".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " href=\"").concat(node.attrs.href || node.attrs.url, "\" target=\"").concat(node.attrs.target, "\">").concat(next(node.children), "</a>");
}
return "<a href=\"".concat(node.attrs.href || node.attrs.url, "\">").concat(next(node.children), "</a>");
return "<a".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " href=\"").concat(node.attrs.href || node.attrs.url, "\">").concat(next(node.children), "</a>");
},
_a[NodeType$1.IMAGE] = function (node, next) {
return "<img src=\"".concat(node.attrs.src || node.attrs.url, "\" />").concat(next(node.children));
return "<img".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " src=\"").concat(node.attrs.src || node.attrs.url, "\" />").concat(next(node.children));
},
_a[NodeType$1.EMBED] = function (node, next) {
return "<iframe src=\"".concat(node.attrs.src || node.attrs.url, "\">").concat(next(node.children), "</iframe>");
return "<iframe".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " src=\"").concat(node.attrs.src || node.attrs.url, "\">").concat(next(node.children), "</iframe>");
},
_a[NodeType$1.HEADING_1] = function (node, next) {
return "<h1>".concat(next(node.children), "</h1>");
return "<h1".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</h1>");
},
_a[NodeType$1.HEADING_2] = function (node, next) {
return "<h2>".concat(next(node.children), "</h2>");
return "<h2".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</h2>");
},
_a[NodeType$1.HEADING_3] = function (node, next) {
return "<h3>".concat(next(node.children), "</h3>");
return "<h3".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</h3>");
},
_a[NodeType$1.HEADING_4] = function (node, next) {
return "<h4>".concat(next(node.children), "</h4>");
return "<h4".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</h4>");
},
_a[NodeType$1.HEADING_5] = function (node, next) {
return "<h5>".concat(next(node.children), "</h5>");
return "<h5".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</h5>");
},
_a[NodeType$1.HEADING_6] = function (node, next) {
return "<h6>".concat(next(node.children), "</h6>");
return "<h6".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</h6>");
},
_a[NodeType$1.ORDER_LIST] = function (node, next) {
return "<ol>".concat(next(node.children), "</ol>");
return "<ol".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</ol>");
},
_a[NodeType$1.UNORDER_LIST] = function (node, next) {
return "<ul>".concat(next(node.children), "</ul>");
return "<ul".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</ul>");
},
_a[NodeType$1.LIST_ITEM] = function (node, next) {
return "<li>".concat(next(node.children), "</li>");
return "<li".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</li>");
},

@@ -447,31 +448,31 @@ _a[NodeType$1.HR] = function (node, next) {

_a[NodeType$1.TABLE] = function (node, next) {
return "<table>".concat(next(node.children), "</table>");
return "<table".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</table>");
},
_a[NodeType$1.TABLE_HEADER] = function (node, next) {
return "<thead>".concat(next(node.children), "</thead>");
return "<thead".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</thead>");
},
_a[NodeType$1.TABLE_BODY] = function (node, next) {
return "<tbody>".concat(next(node.children), "</tbody>");
return "<tbody".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</tbody>");
},
_a[NodeType$1.TABLE_FOOTER] = function (node, next) {
return "<tfoot>".concat(next(node.children), "</tfoot>");
return "<tfoot".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</tfoot>");
},
_a[NodeType$1.TABLE_ROW] = function (node, next) {
return "<tr>".concat(next(node.children), "</tr>");
return "<tr".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</tr>");
},
_a[NodeType$1.TABLE_HEAD] = function (node, next) {
return "<th>".concat(next(node.children), "</th>");
return "<th".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</th>");
},
_a[NodeType$1.TABLE_DATA] = function (node, next) {
return "<td>".concat(next(node.children), "</td>");
return "<td".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</td>");
},
_a[NodeType$1.BLOCK_QUOTE] = function (node, next) {
return "<blockquote>".concat(next(node.children), "</blockquote>");
return "<blockquote".concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</blockquote>");
},
_a[NodeType$1.CODE] = function (node, next) {
return "<code>".concat(next(node.children), "</code>");
return "<code".concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</code>");
},
_a['reference'] = function (node, next) {
if (node.attrs.type === 'asset') {
return "<img src=\"".concat(node.attrs['asset-link'], "\" />");
return "<img".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " src=\"").concat(node.attrs['asset-link'], "\" />");
}

@@ -507,2 +508,5 @@ return "";

},
_a[MarkType$1.CLASSNAME_OR_ID] = function (text, classname, id) {
return "<span".concat(classname ? " class=\"".concat(classname, "\"") : "").concat(id ? " id=\"".concat(id, "\"") : "", ">").concat(text, "</span>");
},
_a);

@@ -532,2 +536,5 @@

var text = node.text;
if (node.classname || node.id) {
text = renderOption[MarkType$1.CLASSNAME_OR_ID](text, node.classname, node.id);
}
if (node.break) {

@@ -569,3 +576,3 @@ text = renderOption[MarkType$1.BREAK](text);

}
var metadata = nodeToMetadata(node.attrs, ((node.children && node.children.length > 0) ? node.children[0] : {}));
var metadata = nodeToMetadata(node.attrs, (node.children && node.children.length > 0 ? node.children[0] : {}));
var item = renderEmbed(metadata);

@@ -580,3 +587,22 @@ if (!item && renderOption[node.type] !== undefined) {

}
function styleObjectToString(styleObj) {
if (!styleObj)
return '';
if (typeof styleObj === 'string') {
return styleObj;
}
var styleString = '';
for (var key in styleObj) {
if (styleObj.hasOwnProperty(key)) {
var value = styleObj[key];
styleString += "".concat(key, ":").concat(value, ";");
}
}
return styleString;
}
function nodeToHTML(node, renderOption, renderEmbed) {
var _a;
if ((_a = node === null || node === void 0 ? void 0 : node.attrs) === null || _a === void 0 ? void 0 : _a.style) {
node.attrs.style = styleObjectToString(node.attrs.style);
}
if (!node.type) {

@@ -666,2 +692,4 @@ return textNodeToHTML(node, renderOption);

var key = _a[0], value = _a[1];
if (key === '$')
return;
switch (typeof value) {

@@ -671,12 +699,42 @@ case "object":

value.forEach(function (obj, index) {
var childKey = "".concat(key, "__").concat(index);
var parentKey = "".concat(key, "__parent");
/**
* Indexes of array are handled here
* {
* "array": ["hello", "world"],
* "$": {
* "array": {"data-cslp": "content_type_uid.entry_uid.locale.array"}
* "array__0": {"data-cslp": "content_type_uid.entry_uid.locale.array.0"}
* "array__1": {"data-cslp": "content_type_uid.entry_uid.locale.array.1"}
* }
* }
*/
tags[childKey] = getTagsValue("".concat(prefix, ".").concat(key, ".").concat(index), tagsAsObject);
tags[parentKey] = getParentTagsValue("".concat(prefix, ".").concat(key), tagsAsObject);
if (typeof obj !== 'undefined' && obj !== null && obj._content_type_uid !== undefined && obj.uid !== undefined) {
/**
* References are handled here
* {
* "reference": [{
* "title": "title",
* "uid": "ref_uid",
* "_content_type_uid": "ref_content_type_uid",
* "$": {"title": {"data-cslp": "ref_content_type_uid.ref_uid.locale.title"}}
* }]
* }
*/
value[index].$ = getTag(obj, "".concat(obj._content_type_uid, ".").concat(obj.uid, ".").concat(obj.locale || locale), tagsAsObject, locale);
}
else {
if (typeof obj === "object") {
obj.$ = getTag(obj, "".concat(prefix, ".").concat(key, ".").concat(index), tagsAsObject, locale);
}
else {
tags[key] = getTagsValue("".concat(prefix, ".").concat(key), tagsAsObject);
}
else if (typeof obj === "object") {
/**
* Objects inside Array like modular blocks are handled here
* {
* "array": [{
* "title": "title",
* "$": {"title": {"data-cslp": "content_type_uid.entry_uid.locale.array.0.title"}}
* }]
* }
*/
obj.$ = getTag(obj, "".concat(prefix, ".").concat(key, ".").concat(index), tagsAsObject, locale);
}

@@ -687,7 +745,38 @@ });

if (value) {
/**
* Objects are handled here
* {
* "object": {
* "title": "title",
* "$": {
* "title": {"data-cslp": "content_type_uid.entry_uid.locale.object.title"}
* }
* },
* }
*/
value.$ = getTag(value, "".concat(prefix, ".").concat(key), tagsAsObject, locale);
}
}
/**
* {
* "object": {
* "title": "title",
* },
* "array": ["hello", "world"]
* "$": {
* "object": {"data-cslp": "content_type_uid.entry_uid.locale.object"},
* "array": {"data-cslp": "content_type_uid.entry_uid.locale.array"}
* }
* }
*/
tags[key] = getTagsValue("".concat(prefix, ".").concat(key), tagsAsObject);
break;
default:
/**
* All primitive values are handled here
* {
* "title": "title",
* "$": {title: {"data-cslp": "content_type_uid.entry_uid.locale.title"}}
* }
*/
tags[key] = getTagsValue("".concat(prefix, ".").concat(key), tagsAsObject);

@@ -706,2 +795,10 @@ }

}
function getParentTagsValue(dataValue, tagsAsObject) {
if (tagsAsObject) {
return { "data-cslp-parent-field": dataValue };
}
else {
return "data-cslp-parent-field=".concat(dataValue);
}
}

@@ -708,0 +805,0 @@ exports.Document = Document;

@@ -10,2 +10,4 @@ export function addTags(entry, contentTypeUid, tagsAsObject, locale) {

var key = _a[0], value = _a[1];
if (key === '$')
return;
switch (typeof value) {

@@ -15,12 +17,42 @@ case "object":

value.forEach(function (obj, index) {
var childKey = "".concat(key, "__").concat(index);
var parentKey = "".concat(key, "__parent");
/**
* Indexes of array are handled here
* {
* "array": ["hello", "world"],
* "$": {
* "array": {"data-cslp": "content_type_uid.entry_uid.locale.array"}
* "array__0": {"data-cslp": "content_type_uid.entry_uid.locale.array.0"}
* "array__1": {"data-cslp": "content_type_uid.entry_uid.locale.array.1"}
* }
* }
*/
tags[childKey] = getTagsValue("".concat(prefix, ".").concat(key, ".").concat(index), tagsAsObject);
tags[parentKey] = getParentTagsValue("".concat(prefix, ".").concat(key), tagsAsObject);
if (typeof obj !== 'undefined' && obj !== null && obj._content_type_uid !== undefined && obj.uid !== undefined) {
/**
* References are handled here
* {
* "reference": [{
* "title": "title",
* "uid": "ref_uid",
* "_content_type_uid": "ref_content_type_uid",
* "$": {"title": {"data-cslp": "ref_content_type_uid.ref_uid.locale.title"}}
* }]
* }
*/
value[index].$ = getTag(obj, "".concat(obj._content_type_uid, ".").concat(obj.uid, ".").concat(obj.locale || locale), tagsAsObject, locale);
}
else {
if (typeof obj === "object") {
obj.$ = getTag(obj, "".concat(prefix, ".").concat(key, ".").concat(index), tagsAsObject, locale);
}
else {
tags[key] = getTagsValue("".concat(prefix, ".").concat(key), tagsAsObject);
}
else if (typeof obj === "object") {
/**
* Objects inside Array like modular blocks are handled here
* {
* "array": [{
* "title": "title",
* "$": {"title": {"data-cslp": "content_type_uid.entry_uid.locale.array.0.title"}}
* }]
* }
*/
obj.$ = getTag(obj, "".concat(prefix, ".").concat(key, ".").concat(index), tagsAsObject, locale);
}

@@ -31,7 +63,38 @@ });

if (value) {
/**
* Objects are handled here
* {
* "object": {
* "title": "title",
* "$": {
* "title": {"data-cslp": "content_type_uid.entry_uid.locale.object.title"}
* }
* },
* }
*/
value.$ = getTag(value, "".concat(prefix, ".").concat(key), tagsAsObject, locale);
}
}
/**
* {
* "object": {
* "title": "title",
* },
* "array": ["hello", "world"]
* "$": {
* "object": {"data-cslp": "content_type_uid.entry_uid.locale.object"},
* "array": {"data-cslp": "content_type_uid.entry_uid.locale.array"}
* }
* }
*/
tags[key] = getTagsValue("".concat(prefix, ".").concat(key), tagsAsObject);
break;
default:
/**
* All primitive values are handled here
* {
* "title": "title",
* "$": {title: {"data-cslp": "content_type_uid.entry_uid.locale.title"}}
* }
*/
tags[key] = getTagsValue("".concat(prefix, ".").concat(key), tagsAsObject);

@@ -50,2 +113,10 @@ }

}
function getParentTagsValue(dataValue, tagsAsObject) {
if (tagsAsObject) {
return { "data-cslp-parent-field": dataValue };
}
else {
return "data-cslp-parent-field=".concat(dataValue);
}
}
//# sourceMappingURL=entry-editable.js.map

@@ -12,6 +12,6 @@ var __assign = (this && this.__assign) || function () {

};
import { nodeToMetadata } from "../Models/metadata-model";
import MarkType from "../nodes/mark-type";
import { defaultNodeOption } from "../options/default-node-options";
import { findRenderString } from "./find-embeded-object";
import { nodeToMetadata } from '../Models/metadata-model';
import MarkType from '../nodes/mark-type';
import { defaultNodeOption } from '../options/default-node-options';
import { findRenderString } from './find-embeded-object';
export function enumerate(entries, process) {

@@ -39,2 +39,5 @@ for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {

var text = node.text;
if (node.classname || node.id) {
text = renderOption[MarkType.CLASSNAME_OR_ID](text, node.classname, node.id);
}
if (node.break) {

@@ -76,3 +79,3 @@ text = renderOption[MarkType.BREAK](text);

}
var metadata = nodeToMetadata(node.attrs, ((node.children && node.children.length > 0) ? node.children[0] : {}));
var metadata = nodeToMetadata(node.attrs, (node.children && node.children.length > 0 ? node.children[0] : {}));
var item = renderEmbed(metadata);

@@ -87,3 +90,22 @@ if (!item && renderOption[node.type] !== undefined) {

}
function styleObjectToString(styleObj) {
if (!styleObj)
return '';
if (typeof styleObj === 'string') {
return styleObj;
}
var styleString = '';
for (var key in styleObj) {
if (styleObj.hasOwnProperty(key)) {
var value = styleObj[key];
styleString += "".concat(key, ":").concat(value, ";");
}
}
return styleString;
}
function nodeToHTML(node, renderOption, renderEmbed) {
var _a;
if ((_a = node === null || node === void 0 ? void 0 : node.attrs) === null || _a === void 0 ? void 0 : _a.style) {
node.attrs.style = styleObjectToString(node.attrs.style);
}
if (!node.type) {

@@ -90,0 +112,0 @@ return textNodeToHTML(node, renderOption);

export function createMetadata(attribute) {
return {
text: attribute['#text'],
itemUid: attribute["data-sys-entry-uid"] || attribute["data-sys-asset-uid"],
itemUid: attribute['data-sys-entry-uid'] || attribute['data-sys-asset-uid'],
itemType: attribute.type,
styleType: attribute["sys-style-type"],
styleType: attribute['sys-style-type'],
attributes: attribute,
contentTypeUid: attribute["data-sys-content-type-uid"],
contentTypeUid: attribute['data-sys-content-type-uid'],
};

@@ -14,7 +14,7 @@ }

text: textNode.text,
itemUid: attribute["entry-uid"] || attribute["asset-uid"],
itemUid: attribute['entry-uid'] || attribute['asset-uid'],
itemType: attribute.type,
styleType: attribute["display-type"],
styleType: attribute['display-type'],
attributes: attribute,
contentTypeUid: attribute["content-type-uid"],
contentTypeUid: attribute['content-type-uid'],
};

@@ -21,0 +21,0 @@ }

@@ -6,2 +6,3 @@ var MarkType;

MarkType["UNDERLINE"] = "underline";
MarkType["CLASSNAME_OR_ID"] = "classnameOrId";
MarkType["STRIKE_THROUGH"] = "strikethrough";

@@ -8,0 +9,0 @@ MarkType["INLINE_CODE"] = "inlineCode";

@@ -9,42 +9,42 @@ var _a;

_a[NodeType.PARAGRAPH] = function (node, next) {
return "<p>".concat(next(node.children), "</p>");
return "<p".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</p>");
},
_a[NodeType.LINK] = function (node, next) {
if (node.attrs.target) {
return "<a href=\"".concat(node.attrs.href || node.attrs.url, "\" target=\"").concat(node.attrs.target, "\">").concat(next(node.children), "</a>");
return "<a".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " href=\"").concat(node.attrs.href || node.attrs.url, "\" target=\"").concat(node.attrs.target, "\">").concat(next(node.children), "</a>");
}
return "<a href=\"".concat(node.attrs.href || node.attrs.url, "\">").concat(next(node.children), "</a>");
return "<a".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " href=\"").concat(node.attrs.href || node.attrs.url, "\">").concat(next(node.children), "</a>");
},
_a[NodeType.IMAGE] = function (node, next) {
return "<img src=\"".concat(node.attrs.src || node.attrs.url, "\" />").concat(next(node.children));
return "<img".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " src=\"").concat(node.attrs.src || node.attrs.url, "\" />").concat(next(node.children));
},
_a[NodeType.EMBED] = function (node, next) {
return "<iframe src=\"".concat(node.attrs.src || node.attrs.url, "\">").concat(next(node.children), "</iframe>");
return "<iframe".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " src=\"").concat(node.attrs.src || node.attrs.url, "\">").concat(next(node.children), "</iframe>");
},
_a[NodeType.HEADING_1] = function (node, next) {
return "<h1>".concat(next(node.children), "</h1>");
return "<h1".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</h1>");
},
_a[NodeType.HEADING_2] = function (node, next) {
return "<h2>".concat(next(node.children), "</h2>");
return "<h2".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</h2>");
},
_a[NodeType.HEADING_3] = function (node, next) {
return "<h3>".concat(next(node.children), "</h3>");
return "<h3".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</h3>");
},
_a[NodeType.HEADING_4] = function (node, next) {
return "<h4>".concat(next(node.children), "</h4>");
return "<h4".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</h4>");
},
_a[NodeType.HEADING_5] = function (node, next) {
return "<h5>".concat(next(node.children), "</h5>");
return "<h5".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</h5>");
},
_a[NodeType.HEADING_6] = function (node, next) {
return "<h6>".concat(next(node.children), "</h6>");
return "<h6".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</h6>");
},
_a[NodeType.ORDER_LIST] = function (node, next) {
return "<ol>".concat(next(node.children), "</ol>");
return "<ol".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</ol>");
},
_a[NodeType.UNORDER_LIST] = function (node, next) {
return "<ul>".concat(next(node.children), "</ul>");
return "<ul".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</ul>");
},
_a[NodeType.LIST_ITEM] = function (node, next) {
return "<li>".concat(next(node.children), "</li>");
return "<li".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</li>");
},

@@ -55,31 +55,31 @@ _a[NodeType.HR] = function (node, next) {

_a[NodeType.TABLE] = function (node, next) {
return "<table>".concat(next(node.children), "</table>");
return "<table".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</table>");
},
_a[NodeType.TABLE_HEADER] = function (node, next) {
return "<thead>".concat(next(node.children), "</thead>");
return "<thead".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</thead>");
},
_a[NodeType.TABLE_BODY] = function (node, next) {
return "<tbody>".concat(next(node.children), "</tbody>");
return "<tbody".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</tbody>");
},
_a[NodeType.TABLE_FOOTER] = function (node, next) {
return "<tfoot>".concat(next(node.children), "</tfoot>");
return "<tfoot".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</tfoot>");
},
_a[NodeType.TABLE_ROW] = function (node, next) {
return "<tr>".concat(next(node.children), "</tr>");
return "<tr".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</tr>");
},
_a[NodeType.TABLE_HEAD] = function (node, next) {
return "<th>".concat(next(node.children), "</th>");
return "<th".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</th>");
},
_a[NodeType.TABLE_DATA] = function (node, next) {
return "<td>".concat(next(node.children), "</td>");
return "<td".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</td>");
},
_a[NodeType.BLOCK_QUOTE] = function (node, next) {
return "<blockquote>".concat(next(node.children), "</blockquote>");
return "<blockquote".concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</blockquote>");
},
_a[NodeType.CODE] = function (node, next) {
return "<code>".concat(next(node.children), "</code>");
return "<code".concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", ">").concat(next(node.children), "</code>");
},
_a['reference'] = function (node, next) {
if (node.attrs.type === 'asset') {
return "<img src=\"".concat(node.attrs['asset-link'], "\" />");
return "<img".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs.class ? " class=\"".concat(node.attrs.class, "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " src=\"").concat(node.attrs['asset-link'], "\" />");
}

@@ -115,3 +115,6 @@ return "";

},
_a[MarkType.CLASSNAME_OR_ID] = function (text, classname, id) {
return "<span".concat(classname ? " class=\"".concat(classname, "\"") : "").concat(id ? " id=\"".concat(id, "\"") : "", ">").concat(text, "</span>");
},
_a);
//# sourceMappingURL=default-node-options.js.map

@@ -1,8 +0,8 @@

import { EmbeddedItem, EntryEmbedable } from "../Models/embedded-object";
import { Metadata } from "../Models/metadata-model";
import TextNode from "../nodes/text-node";
import { EmbeddedItem, EntryEmbedable } from '../Models/embedded-object';
import { Metadata } from '../Models/metadata-model';
import TextNode from '../nodes/text-node';
import Node from '../nodes/node';
import Document from '../nodes/document';
import { RenderOption } from "../options";
import { EntryNode } from "../Models/json-rte-model";
import { RenderOption } from '../options';
import { EntryNode } from '../Models/json-rte-model';
export declare function enumerate(entries: EntryEmbedable[] | EmbeddedItem[], process: (entry: EntryEmbedable | EmbeddedItem) => void): void;

@@ -9,0 +9,0 @@ export declare function enumerateContents(content: Document | Document[], renderOption?: RenderOption, renderEmbed?: (metadata: Metadata) => EmbeddedItem | EntryNode): string | string[];

@@ -14,5 +14,10 @@ import StyleType from '../embedded-types/style-type';

class?: string;
id?: string;
[key: string]: any;
style?: styleObjType | string;
'sys-style-type'?: string;
}
export type styleObjType = {
[key: string]: any;
};
export interface EntryAttributes extends Attributes {

@@ -19,0 +24,0 @@ 'data-sys-entry-uid': string;

@@ -5,2 +5,3 @@ declare enum MarkType {

UNDERLINE = "underline",
CLASSNAME_OR_ID = "classnameOrId",
STRIKE_THROUGH = "strikethrough",

@@ -7,0 +8,0 @@ INLINE_CODE = "inlineCode",

@@ -11,4 +11,6 @@ import Node from "./node";

break?: boolean;
classname?: string;
id?: string;
text: string;
constructor(text: string);
}

@@ -8,3 +8,3 @@ import { AnyNode } from '../json-to-html';

export type RenderNode = (node: Node, next: Next) => string;
export type RenderMark = (text: string) => string;
export type RenderMark = (text: string, classname?: string, id?: string) => string;
export type RenderItem = (item: EmbeddedItem | EntryNode, metadata: Metadata) => string;

@@ -11,0 +11,0 @@ export interface RenderOption {

{
"name": "@contentstack/utils",
"version": "1.3.0",
"version": "1.3.1",
"description": "Contentstack utilities for Javascript",

@@ -39,21 +39,22 @@ "main": "dist/index.es.js",

"devDependencies": {
"@babel/preset-env": "^7.16.11",
"@commitlint/cli": "^17.4.2",
"@commitlint/config-conventional": "^17.4.2",
"@babel/preset-env": "^7.22.20",
"@commitlint/cli": "^17.7.1",
"@commitlint/config-conventional": "^17.7.0",
"@types/jest": "^26.0.24",
"babel-core": "^6.26.3",
"babel-jest": "^27.5.1",
"babel-core": "^4.7.16",
"babel-jest": "^29.7.0",
"babel-loader": "8.1.0",
"babel-preset-es2015": "^6.24.1",
"commitizen": "^4.3.0",
"eslint": "^8.12.0",
"eslint": "^8.50.0",
"husky": "^8.0.3",
"jest": "^27.5.1",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-coverage-badges": "^1.1.2",
"jest-html-reporters": "^2.1.7",
"jest-junit": "^15.0.0",
"jsdom": "^21.1.0",
"jsdom": "^21.1.2",
"jsdom-global": "^3.0.2",
"prettier": "^2.6.1",
"rollup": "^2.70.1",
"prettier": "^2.8.8",
"rollup": "^2.79.1",
"rollup-plugin-json": "^4.0.0",

@@ -63,9 +64,8 @@ "rollup-plugin-node-resolve": "^5.2.0",

"rollup-plugin-typescript2": "^0.28.0",
"ts-jest": "^27.1.4",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0",
"typescript": "^4.6.3"
"typescript": "^4.9.5"
},
"dependencies": {},
"config": {

@@ -72,0 +72,0 @@ "commitizen": {

@@ -1,6 +0,1 @@

![Coverage statements](./badges/badge-statements.svg?raw=true)
![Coverage branches](./badges/badge-branches.svg)
![Coverage functions](./badges/badge-functions.svg)
![Coverage lines](./badges/badge-lines.svg)
# Contentstack JavaScript Utils SDK:

@@ -30,29 +25,29 @@

```js
const renderOptions = {
const renderOption = {
// to render Supercharged RTE NodeType content like paragraph, link, table, order list, un-order list and more.
p: (node, next) => {
`<p class='class-id'>${next(node.children)}</p>` // you will need to call next function with node children contents
}
return `<p class='class-id'>${next(node.children)}</p>` // you will need to call next function with node children contents
},
h1: (node, next) => {
`<h1 class='class-id'>${next(node.children)}</h1>` // you will need to call next function with node children contents
}
return `<h1 class='class-id'>${next(node.children)}</h1>` // you will need to call next function with node children contents
},
// to render Supercharged RTE MarkType content like bold, italic, underline, strikethrough, inlineCode, subscript, and superscript
bold: (text) => {
`<b>${next(node.children)}</b>`
}
return `<b>${next(node.children)}</b>`
},
// to render block-type embedded items
block: {
'product': (item, metadata) => {
`<div>
<h2 >${item.title}</h2>
<img src=${item.product_image.url} alt=${item.product_image.title}/>
<p>${item.price}</p>
</div>`
return `<div>
<h2 >${item.title}</h2>
<img src=${item.product_image.url} alt=${item.product_image.title}/>
<p>${item.price}</p>
</div>`
},
// to render the default
'$default': (item, metadata) => {
`<div>
<h2>${item.title}</h2>
<p>${item.description}</p>
</div>`
return `<div>
<h2>${item.title}</h2>
<p>${item.description}</p>
</div>`
}

@@ -63,3 +58,3 @@ },

'$default': (item, metadata) => {
`<span><b>${item.title}</b> - ${item.description}</span>`
return `<span><b>${item.title}</b> - ${item.description}</span>`
}

@@ -69,7 +64,7 @@ },

link: (item, metadata) => {
`<a href="${metadata.attributes.href}">${metadata.text}</a>`
return `<a href="${metadata.attributes.href}">${metadata.text}</a>`
},
// to display assets
display: (item, metadata) => {
`<img src=${metadata.attributes.src} alt=${metadata.alt} />`
return `<img src=${metadata.attributes.src} alt=${metadata.alt} />`
}

@@ -110,3 +105,3 @@ }

#### Render Supercharged RTE contents
To get a single entry, you need to provide the stack API key, environment name, delivery token, content type and entry UID. Then, use `Contentstack.Utils.jsonToHtml` function as shown below:
To get a single entry, you need to provide the stack API key, environment name, delivery token, content type and entry UID. Then, use `Contentstack.Utils.jsonToHTML` function as shown below:
```js

@@ -124,3 +119,3 @@ import * as Contentstack from 'contentstack'

.then(entry => {
Contentstack.Utils.jsonToHtml({
Contentstack.Utils.jsonToHTML({
entry,

@@ -163,3 +158,3 @@ path: ["rte_fieldUid", "group.rteFieldUID"],

#### Render Supercharged RTE contents
To get a multiple entries, you need to provide the stack API key, environment name, delivery token, content type and entry UID. Then, use `Contentstack.Utils.jsonToHtml` function as shown below:
To get a multiple entries, you need to provide the stack API key, environment name, delivery token, content type and entry UID. Then, use `Contentstack.Utils.jsonToHTML` function as shown below:
```js

@@ -179,3 +174,3 @@ import * as Contentstack from 'contentstack'

result.forEach(entry => {
Contentstack.Utils.jsonToHtml({
Contentstack.Utils.jsonToHTML({
entry,

@@ -182,0 +177,0 @@ path: ["rte_fieldUid", "group.rteFieldUID"],

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc