Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@contentstack/utils

Package Overview
Dependencies
Maintainers
14
Versions
23
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.10 to 1.3.11

51

dist/index.es.js

@@ -628,8 +628,13 @@ 'use strict';

function referenceToHTML(node, renderOption, renderEmbed) {
if (node.attrs.type === 'entry' && node.attrs['display-type'] === 'link') {
if ((node.attrs.type === 'entry' || node.attrs.type === 'asset') && node.attrs['display-type'] === 'link') {
var entryText = node.children ? nodeChildrenToHTML(node.children, renderOption, renderEmbed) : '';
var aTagAttrs = "".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs['class-name'] ? " class=\"".concat(node.attrs['class-name'], "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " href=\"").concat(node.attrs.href || node.attrs.url, "\"");
if (node.attrs.target) {
return "<a".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs['class-name'] ? " class=\"".concat(node.attrs['class-name'], "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " href=\"").concat(node.attrs.href || node.attrs.url, "\" target=\"").concat(node.attrs.target, "\">").concat(entryText, "</a>");
aTagAttrs += " target=\"".concat(node.attrs.target, "\"");
}
return "<a".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs['class-name'] ? " class=\"".concat(node.attrs['class-name'], "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " href=\"").concat(node.attrs.href || node.attrs.url, "\">").concat(entryText, "</a>");
if (node.attrs.type == 'asset') {
aTagAttrs += " type=\"asset\" content-type-uid=\"sys_assets\" ".concat(node.attrs['asset-uid'] ? "data-sys-asset-uid=\"".concat(node.attrs['asset-uid'], "\"") : "", " sys-style-type=\"download\"");
}
var aTag = "<a".concat(aTagAttrs, ">").concat(entryText, "</a>");
return aTag;
}

@@ -752,7 +757,10 @@ function sendToRenderOption(referenceNode) {

if (locale === void 0) { locale = 'en-us'; }
if (entry)
entry.$ = getTag(entry, "".concat(contentTypeUid, ".").concat(entry.uid, ".").concat(locale), tagsAsObject, locale);
if (entry) {
var appliedVariants = entry._applied_variants || null;
entry.$ = getTag(entry, "".concat(contentTypeUid, ".").concat(entry.uid, ".").concat(locale), tagsAsObject, locale, { _applied_variants: appliedVariants, shouldApplyVariant: !!appliedVariants, metaKey: '' });
}
}
function getTag(content, prefix, tagsAsObject, locale) {
function getTag(content, prefix, tagsAsObject, locale, appliedVariants) {
var tags = {};
appliedVariants.metaKey; var shouldApplyVariant = appliedVariants.shouldApplyVariant, _applied_variants = appliedVariants._applied_variants;
Object.entries(content).forEach(function (_a) {

@@ -762,2 +770,6 @@ var key = _a[0], value = _a[1];

return;
var metaUID = value && typeof value === 'object' && value._metadata && value._metadata.uid ? value._metadata.uid : '';
var updatedMetakey = appliedVariants.shouldApplyVariant ? "".concat(appliedVariants.metaKey ? appliedVariants.metaKey + '.' : '').concat(key) : '';
if (metaUID && updatedMetakey)
updatedMetakey = updatedMetakey + '.' + metaUID;
switch (typeof value) {

@@ -769,2 +781,6 @@ case "object":

var parentKey = "".concat(key, "__parent");
metaUID = value && typeof value === 'object' && obj._metadata && obj._metadata.uid ? obj._metadata.uid : '';
updatedMetakey = appliedVariants.shouldApplyVariant ? "".concat(appliedVariants.metaKey ? appliedVariants.metaKey + '.' : '').concat(key) : '';
if (metaUID && updatedMetakey)
updatedMetakey = updatedMetakey + '.' + metaUID;
/**

@@ -781,3 +797,3 @@ * Indexes of array are handled here

*/
tags[childKey] = getTagsValue("".concat(prefix, ".").concat(key, ".").concat(index), tagsAsObject);
tags[childKey] = getTagsValue("".concat(prefix, ".").concat(key, ".").concat(index), tagsAsObject, { _applied_variants: _applied_variants, shouldApplyVariant: shouldApplyVariant, metaKey: updatedMetakey });
tags[parentKey] = getParentTagsValue("".concat(prefix, ".").concat(key), tagsAsObject);

@@ -796,3 +812,5 @@ if (typeof obj !== 'undefined' && obj !== null && obj._content_type_uid !== undefined && obj.uid !== undefined) {

*/
value[index].$ = getTag(obj, "".concat(obj._content_type_uid, ".").concat(obj.uid, ".").concat(obj.locale || locale), tagsAsObject, locale);
var newAppliedVariants = obj._applied_variants || _applied_variants;
var newShouldApplyVariant = !!newAppliedVariants;
value[index].$ = getTag(obj, "".concat(obj._content_type_uid, ".").concat(obj.uid, ".").concat(obj.locale || locale), tagsAsObject, locale, { _applied_variants: newAppliedVariants, shouldApplyVariant: newShouldApplyVariant, metaKey: "" });
}

@@ -809,3 +827,3 @@ else if (typeof obj === "object") {

*/
obj.$ = getTag(obj, "".concat(prefix, ".").concat(key, ".").concat(index), tagsAsObject, locale);
obj.$ = getTag(obj, "".concat(prefix, ".").concat(key, ".").concat(index), tagsAsObject, locale, { _applied_variants: _applied_variants, shouldApplyVariant: shouldApplyVariant, metaKey: updatedMetakey });
}

@@ -827,3 +845,3 @@ });

*/
value.$ = getTag(value, "".concat(prefix, ".").concat(key), tagsAsObject, locale);
value.$ = getTag(value, "".concat(prefix, ".").concat(key), tagsAsObject, locale, { _applied_variants: _applied_variants, shouldApplyVariant: shouldApplyVariant, metaKey: updatedMetakey });
}

@@ -843,3 +861,3 @@ }

*/
tags[key] = getTagsValue("".concat(prefix, ".").concat(key), tagsAsObject);
tags[key] = getTagsValue("".concat(prefix, ".").concat(key), tagsAsObject, { _applied_variants: _applied_variants, shouldApplyVariant: shouldApplyVariant, metaKey: updatedMetakey });
break;

@@ -854,3 +872,3 @@ default:

*/
tags[key] = getTagsValue("".concat(prefix, ".").concat(key), tagsAsObject);
tags[key] = getTagsValue("".concat(prefix, ".").concat(key), tagsAsObject, { _applied_variants: _applied_variants, shouldApplyVariant: shouldApplyVariant, metaKey: updatedMetakey });
}

@@ -860,3 +878,10 @@ });

}
function getTagsValue(dataValue, tagsAsObject) {
function getTagsValue(dataValue, tagsAsObject, appliedVariants) {
if (appliedVariants.shouldApplyVariant && appliedVariants._applied_variants && appliedVariants._applied_variants[appliedVariants.metaKey]) {
var variant = appliedVariants._applied_variants[appliedVariants.metaKey];
// Adding v2 prefix to the cslp tag. New cslp tags are in v2 format. ex: v2:content_type_uid.entry_uid.locale.title
var newDataValueArray = ('v2:' + dataValue).split('.');
newDataValueArray[1] = newDataValueArray[1] + '_' + variant;
dataValue = newDataValueArray.join('.');
}
if (tagsAsObject) {

@@ -863,0 +888,0 @@ return { "data-cslp": dataValue };

export function addTags(entry, contentTypeUid, tagsAsObject, locale) {
if (locale === void 0) { locale = 'en-us'; }
if (entry)
entry.$ = getTag(entry, "".concat(contentTypeUid, ".").concat(entry.uid, ".").concat(locale), tagsAsObject, locale);
if (entry) {
var appliedVariants = entry._applied_variants || null;
entry.$ = getTag(entry, "".concat(contentTypeUid, ".").concat(entry.uid, ".").concat(locale), tagsAsObject, locale, { _applied_variants: appliedVariants, shouldApplyVariant: !!appliedVariants, metaKey: '' });
}
}
function getTag(content, prefix, tagsAsObject, locale) {
function getTag(content, prefix, tagsAsObject, locale, appliedVariants) {
var tags = {};
var metaKey = appliedVariants.metaKey, shouldApplyVariant = appliedVariants.shouldApplyVariant, _applied_variants = appliedVariants._applied_variants;
Object.entries(content).forEach(function (_a) {

@@ -12,2 +15,6 @@ var key = _a[0], value = _a[1];

return;
var metaUID = value && typeof value === 'object' && value._metadata && value._metadata.uid ? value._metadata.uid : '';
var updatedMetakey = appliedVariants.shouldApplyVariant ? "".concat(appliedVariants.metaKey ? appliedVariants.metaKey + '.' : '').concat(key) : '';
if (metaUID && updatedMetakey)
updatedMetakey = updatedMetakey + '.' + metaUID;
switch (typeof value) {

@@ -19,2 +26,6 @@ case "object":

var parentKey = "".concat(key, "__parent");
metaUID = value && typeof value === 'object' && obj._metadata && obj._metadata.uid ? obj._metadata.uid : '';
updatedMetakey = appliedVariants.shouldApplyVariant ? "".concat(appliedVariants.metaKey ? appliedVariants.metaKey + '.' : '').concat(key) : '';
if (metaUID && updatedMetakey)
updatedMetakey = updatedMetakey + '.' + metaUID;
/**

@@ -31,3 +42,3 @@ * Indexes of array are handled here

*/
tags[childKey] = getTagsValue("".concat(prefix, ".").concat(key, ".").concat(index), tagsAsObject);
tags[childKey] = getTagsValue("".concat(prefix, ".").concat(key, ".").concat(index), tagsAsObject, { _applied_variants: _applied_variants, shouldApplyVariant: shouldApplyVariant, metaKey: updatedMetakey });
tags[parentKey] = getParentTagsValue("".concat(prefix, ".").concat(key), tagsAsObject);

@@ -46,3 +57,5 @@ if (typeof obj !== 'undefined' && obj !== null && obj._content_type_uid !== undefined && obj.uid !== undefined) {

*/
value[index].$ = getTag(obj, "".concat(obj._content_type_uid, ".").concat(obj.uid, ".").concat(obj.locale || locale), tagsAsObject, locale);
var newAppliedVariants = obj._applied_variants || _applied_variants;
var newShouldApplyVariant = !!newAppliedVariants;
value[index].$ = getTag(obj, "".concat(obj._content_type_uid, ".").concat(obj.uid, ".").concat(obj.locale || locale), tagsAsObject, locale, { _applied_variants: newAppliedVariants, shouldApplyVariant: newShouldApplyVariant, metaKey: "" });
}

@@ -59,3 +72,3 @@ else if (typeof obj === "object") {

*/
obj.$ = getTag(obj, "".concat(prefix, ".").concat(key, ".").concat(index), tagsAsObject, locale);
obj.$ = getTag(obj, "".concat(prefix, ".").concat(key, ".").concat(index), tagsAsObject, locale, { _applied_variants: _applied_variants, shouldApplyVariant: shouldApplyVariant, metaKey: updatedMetakey });
}

@@ -77,3 +90,3 @@ });

*/
value.$ = getTag(value, "".concat(prefix, ".").concat(key), tagsAsObject, locale);
value.$ = getTag(value, "".concat(prefix, ".").concat(key), tagsAsObject, locale, { _applied_variants: _applied_variants, shouldApplyVariant: shouldApplyVariant, metaKey: updatedMetakey });
}

@@ -93,3 +106,3 @@ }

*/
tags[key] = getTagsValue("".concat(prefix, ".").concat(key), tagsAsObject);
tags[key] = getTagsValue("".concat(prefix, ".").concat(key), tagsAsObject, { _applied_variants: _applied_variants, shouldApplyVariant: shouldApplyVariant, metaKey: updatedMetakey });
break;

@@ -104,3 +117,3 @@ default:

*/
tags[key] = getTagsValue("".concat(prefix, ".").concat(key), tagsAsObject);
tags[key] = getTagsValue("".concat(prefix, ".").concat(key), tagsAsObject, { _applied_variants: _applied_variants, shouldApplyVariant: shouldApplyVariant, metaKey: updatedMetakey });
}

@@ -110,3 +123,10 @@ });

}
function getTagsValue(dataValue, tagsAsObject) {
function getTagsValue(dataValue, tagsAsObject, appliedVariants) {
if (appliedVariants.shouldApplyVariant && appliedVariants._applied_variants && appliedVariants._applied_variants[appliedVariants.metaKey]) {
var variant = appliedVariants._applied_variants[appliedVariants.metaKey];
// Adding v2 prefix to the cslp tag. New cslp tags are in v2 format. ex: v2:content_type_uid.entry_uid.locale.title
var newDataValueArray = ('v2:' + dataValue).split('.');
newDataValueArray[1] = newDataValueArray[1] + '_' + variant;
dataValue = newDataValueArray.join('.');
}
if (tagsAsObject) {

@@ -113,0 +133,0 @@ return { "data-cslp": dataValue };

@@ -68,8 +68,13 @@ var __assign = (this && this.__assign) || function () {

export function referenceToHTML(node, renderOption, renderEmbed) {
if (node.attrs.type === 'entry' && node.attrs['display-type'] === 'link') {
if ((node.attrs.type === 'entry' || node.attrs.type === 'asset') && node.attrs['display-type'] === 'link') {
var entryText = node.children ? nodeChildrenToHTML(node.children, renderOption, renderEmbed) : '';
var aTagAttrs = "".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs['class-name'] ? " class=\"".concat(node.attrs['class-name'], "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " href=\"").concat(node.attrs.href || node.attrs.url, "\"");
if (node.attrs.target) {
return "<a".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs['class-name'] ? " class=\"".concat(node.attrs['class-name'], "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " href=\"").concat(node.attrs.href || node.attrs.url, "\" target=\"").concat(node.attrs.target, "\">").concat(entryText, "</a>");
aTagAttrs += " target=\"".concat(node.attrs.target, "\"");
}
return "<a".concat(node.attrs.style ? " style=\"".concat(node.attrs.style, "\"") : "").concat(node.attrs['class-name'] ? " class=\"".concat(node.attrs['class-name'], "\"") : "").concat(node.attrs.id ? " id=\"".concat(node.attrs.id, "\"") : "", " href=\"").concat(node.attrs.href || node.attrs.url, "\">").concat(entryText, "</a>");
if (node.attrs.type == 'asset') {
aTagAttrs += " type=\"asset\" content-type-uid=\"sys_assets\" ".concat(node.attrs['asset-uid'] ? "data-sys-asset-uid=\"".concat(node.attrs['asset-uid'], "\"") : "", " sys-style-type=\"download\"");
}
var aTag = "<a".concat(aTagAttrs, ">").concat(entryText, "</a>");
return aTag;
}

@@ -76,0 +81,0 @@ function sendToRenderOption(referenceNode) {

{
"name": "@contentstack/utils",
"version": "1.3.10",
"version": "1.3.11",
"description": "Contentstack utilities for Javascript",

@@ -5,0 +5,0 @@ "main": "dist/index.es.js",

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