@cocreate/render
Advanced tools
Comparing version 1.41.5 to 1.42.0
{ | ||
"name": "@cocreate/render", | ||
"version": "1.41.5", | ||
"version": "1.42.0", | ||
"description": "A simple render component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -286,2 +286,9 @@ /******************************************************************************** | ||
let renderReverse | ||
if (templateData.source && templateData.source.element) { | ||
renderReverse = templateData.source.element.getAttribute('render-reverse'); | ||
if (!renderReverse) | ||
renderReverse = template.element.getAttribute('render-reverse'); | ||
} | ||
if (key && !Array.isArray(renderData) || renderType === "object") { | ||
@@ -360,3 +367,3 @@ if (renderType && Array.isArray(renderData) && renderData.length === 1) | ||
await renderValues(clone.element, object, key, renderAs, null, null, index); | ||
insertElement(template, clone.element, index); | ||
insertElement(template, clone.element, index, '', data, renderReverse); | ||
} | ||
@@ -405,3 +412,3 @@ } | ||
function insertElement(template, element, index, currentIndex) { | ||
function insertElement(template, element, index, currentIndex, data, renderReverse) { | ||
let eid = element.getAttribute('eid') | ||
@@ -416,18 +423,50 @@ if (!eid) { | ||
template = template.template | ||
// const clones = Array.from(template.clones); | ||
let item | ||
if (!currentIndex && currentIndex !== 0) { | ||
if (template.clones.has(eid)) | ||
return | ||
item = [eid, element]; | ||
} | ||
const clones = Array.from(template.clones); | ||
let item | ||
if (currentIndex) { | ||
if (currentIndex || currentIndex === 0) { | ||
item = clones.splice(currentIndex, 1)[0]; | ||
} | ||
if (data.$filter && data.$filter.startingIndex) | ||
index += data.$filter.startingIndex | ||
clones.splice(index, 0, item); // Insert item into clones at the specified index | ||
if (renderReverse) { | ||
// Chat-specific logic: reverse rendering but still inserting based on sorting | ||
// If we're rendering in reverse order, we want to respect the insertion index | ||
if (clones[index + 1] && clones[index + 1][1] !== element) { | ||
// Insert before the next element (reverse order means newer items come before older ones) | ||
clones[index + 1][1].insertAdjacentElement('afterend', element); | ||
} else if (clones[index] && clones[index][1] !== element) { | ||
// Insert after the current element if there's no next element | ||
clones[index][1].insertAdjacentElement('beforeend', element); | ||
} else { | ||
// Fallback: insert before the template if clones are empty or undefined | ||
template.element.insertAdjacentElement('afterend', element); | ||
} | ||
} else { | ||
item = [eid, element]; | ||
// Non-chat logic: handle ascending or descending order as usual | ||
if (clones[index + 1] && clones[index + 1][1] !== element) { | ||
// Insert before the next element | ||
clones[index + 1][1].insertAdjacentElement('beforebegin', element); | ||
} else if (clones[index] && clones[index][1] !== element) { | ||
// Insert after the current element if there's no next element | ||
clones[index][1].insertAdjacentElement('afterend', element); | ||
} else { | ||
// Fallback: insert before the template if clones are empty or undefined | ||
template.element.insertAdjacentElement('beforebegin', element); | ||
} | ||
} | ||
clones.splice(index, 0, item); | ||
if (clones[index + 1] && clones[index][1] !== element) | ||
clones[index][1].insertAdjacentElement('beforebegin', element); | ||
else if (clones[index] && clones[index][1] !== element) | ||
clones[index][1].insertAdjacentElement('afterend', element); | ||
else | ||
template.element.insertAdjacentElement('beforebegin', element); | ||
template.clones = new Map(clones); | ||
@@ -434,0 +473,0 @@ } else { |
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
214153
936