@dosgato/templating
Advanced tools
Comparing version 1.0.8 to 1.0.9
@@ -329,2 +329,12 @@ /// <reference types="node" /> | ||
/** | ||
* the full array of components in the same area as this component, including self | ||
* | ||
* empty for page component | ||
*/ | ||
siblings: Component[]; | ||
/** the component before this one inside the area, null if this component is first */ | ||
prevSibling?: Component; | ||
/** the component after this one inside the area, null if this component is last */ | ||
nextSibling?: Component; | ||
/** | ||
* For logging errors during rendering without crashing the render. If your fetch, setContext, | ||
@@ -488,2 +498,17 @@ * render, or renderVariation functions throw, the error will be logged but the page render will | ||
component?: Component; | ||
/** | ||
* Contains all the components in the same area as the component being rendered. | ||
* | ||
* Use this if you need to wrap multiple components together inside the same | ||
* box. For instance, if you have several components of the same type in a row, | ||
* perhaps you want them to automatically appear side by side in a flexbox. | ||
* | ||
* Your wrap function could inspect the components before and after the current | ||
* component, based on indexInArea, and decide to open a div when the preceding is | ||
* not the right type and the following is, then close the div when the preceding | ||
* is the right type and the following is not. | ||
* | ||
* Will be defined when rendering the new bar. | ||
*/ | ||
siblings: Component[]; | ||
} | ||
@@ -490,0 +515,0 @@ export interface RenderComponentsOpts { |
@@ -113,2 +113,3 @@ import { get, isNotBlank, titleCase } from 'txstate-utils'; | ||
components = this.renderedAreas.get(components) ?? []; | ||
const siblings = components.map(c => c.component); | ||
const wrap = opts?.wrap ?? defaultWrap; | ||
@@ -118,7 +119,7 @@ if (opts?.skipContent && !this.editMode) | ||
if (opts?.skipBars || opts?.skipEditBars || !this.editMode) | ||
return components.map((c, indexInArea) => wrap({ ...c, content: c.output, bar: '', indexInArea })).join(''); | ||
return components.map((c, indexInArea) => wrap({ ...c, content: c.output, bar: '', indexInArea, siblings })).join(''); | ||
return components | ||
.map((c, indexInArea) => { | ||
if (c.component.inheritedFrom && opts?.hideInheritBars) { | ||
return opts.skipContent ? '' : wrap({ ...c, content: c.output, bar: '', indexInArea }); | ||
return opts.skipContent ? '' : wrap({ ...c, content: c.output, bar: '', indexInArea, siblings }); | ||
} | ||
@@ -132,3 +133,3 @@ else { | ||
const content = opts?.skipContent ? '' : c.output; | ||
return wrap({ output: bar + content, content, bar, component: c.component, indexInArea }); | ||
return wrap({ output: bar + content, content, bar, component: c.component, indexInArea, siblings }); | ||
} | ||
@@ -165,3 +166,3 @@ }).join(''); | ||
if (bar != null) | ||
output += wrap({ output: bar, content: '', bar, indexInArea: components.length }); | ||
output += wrap({ output: bar, content: '', bar, indexInArea: components.length, siblings: components.map(c => c.component) }); | ||
} | ||
@@ -168,0 +169,0 @@ return output; |
{ | ||
"name": "@dosgato/templating", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"description": "A library to support building templates for dosgato CMS.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
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
120327
2618