@cocreate/render
Advanced tools
Comparing version 1.40.4 to 1.41.0
{ | ||
"name": "@cocreate/render", | ||
"version": "1.40.4", | ||
"version": "1.41.0", | ||
"description": "A simple render component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -272,3 +272,10 @@ /******************************************************************************** | ||
if (key && !Array.isArray(renderData)) { | ||
let renderType | ||
if (templateData.source && templateData.source.element) | ||
renderType = templateData.source.element.getAttribute('render-type'); | ||
if (key && !Array.isArray(renderData) || renderType === "object") { | ||
if (renderType && Array.isArray(renderData) && renderData.length === 1) | ||
renderData = renderData[0] | ||
let exclude = template.element.getAttribute('render-exclude') || '' | ||
@@ -339,3 +346,6 @@ if (exclude) { | ||
await renderValues(clone.element, object, key, renderAs); | ||
let index | ||
if (key !== 'data') | ||
index = i | ||
await renderValues(clone.element, object, key, renderAs, null, null, index); | ||
insertElement(template, clone.element, index); | ||
@@ -418,3 +428,3 @@ } | ||
async function renderValues(node, data, key, renderAs, keyPath, parent) { | ||
async function renderValues(node, data, key, renderAs, keyPath, parent, index) { | ||
if (!data) return; | ||
@@ -492,4 +502,4 @@ | ||
name = await renderValue(attr, data, namePlaceholder, renderAs, renderedAttribute); | ||
value = await renderValue(attr, data, valuePlaceholder, renderAs, renderedAttribute); | ||
name = await renderValue(attr, data, namePlaceholder, renderAs, renderedAttribute, index); | ||
value = await renderValue(attr, data, valuePlaceholder, renderAs, renderedAttribute, index); | ||
if (namePlaceholder.includes('{{') && name) { | ||
@@ -533,3 +543,3 @@ const attributes = name.match(/([^\s]+="[^"]*"|[^\s]+)/g) || []; | ||
for (let childNode of node.childNodes) { | ||
await renderValues(childNode, data, key, renderAs, keyPath, parent); | ||
await renderValues(childNode, data, key, renderAs, keyPath, parent, index); | ||
} | ||
@@ -552,3 +562,3 @@ // }); | ||
text = await renderValue(node, data, textContent, renderAs, renderedNode); | ||
text = await renderValue(node, data, textContent, renderAs, renderedNode, index); | ||
@@ -582,3 +592,3 @@ if (text || text == "") { | ||
for (let childNode of node.childNodes) { | ||
await renderValues(childNode, data, key, renderAs, keyPath, parent); | ||
await renderValues(childNode, data, key, renderAs, keyPath, parent, index); | ||
} | ||
@@ -592,4 +602,5 @@ // }); | ||
async function renderValue(node, data, placeholder, renderAs, renderedNode) { | ||
async function renderValue(node, data, placeholder, renderAs, renderedNode, index) { | ||
let output = placeholder; | ||
let regex = /\{([^{}]+)\}/ | ||
@@ -604,3 +615,6 @@ let omitted = {} | ||
try { | ||
if (match[1].startsWith('[') && match[1].endsWith(']')) { // {[]} - Dot-notation | ||
if (match[1] === 'index' && index >= 0) { // {[]} - Dot-notation | ||
value = index | ||
} else if (match[1].startsWith('[') && match[1].endsWith(']')) { // {[]} - Dot-notation | ||
match[1] = match[1].slice(1, -1); | ||
@@ -644,3 +658,3 @@ value = getRenderValue(node, data, match[1], renderAs); | ||
if (value || value === "") { | ||
if (value || value === "" || value >= 0) { | ||
if (typeof value === "object") { | ||
@@ -647,0 +661,0 @@ value = JSON.stringify(value, null, 2); |
Sorry, the diff of this file is too big to display
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
210624
878