@dosgato/templating 1.0.8 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -325,6 +325,16 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
325
325
  reqHeaders: IncomingHttpHeaders;
326
326
  reqQuery: ParsedUrlQuery;
327
327
  indexInArea: number;
328
+ /**
329
+ * the full array of components in the same area as this component, including self
330
+ *
331
+ * empty for page component
332
+ */
333
+ siblings: Component[];
334
+ /** the component before this one inside the area, null if this component is first */
335
+ prevSibling?: Component;
336
+ /** the component after this one inside the area, null if this component is last */
337
+ nextSibling?: Component;
328
338
  /**
329
339
  * For logging errors during rendering without crashing the render. If your fetch, setContext,
330
340
  * render, or renderVariation functions throw, the error will be logged but the page render will
@@ -484,6 +494,21 @@ export interface RenderComponentsWrapParams {
484
494
  * Will be undefined for the new bar, so check that it is not null.
485
495
  */
486
496
  component?: Component;
497
+ /**
498
+ * Contains all the components in the same area as the component being rendered.
499
+ *
500
+ * Use this if you need to wrap multiple components together inside the same
501
+ * box. For instance, if you have several components of the same type in a row,
502
+ * perhaps you want them to automatically appear side by side in a flexbox.
503
+ *
504
+ * Your wrap function could inspect the components before and after the current
505
+ * component, based on indexInArea, and decide to open a div when the preceding is
506
+ * not the right type and the following is, then close the div when the preceding
507
+ * is the right type and the following is not.
508
+ *
509
+ * Will be defined when rendering the new bar.
510
+ */
511
+ siblings: Component[];
487
512
  }
488
513
  export interface RenderComponentsOpts {
489
514
  /**
package/dist/component.js CHANGED
@@ -110,15 +110,16 @@ export class Component extends ResourceProvider {
110
110
  renderComponents(components = [], opts) {
111
111
  if (!Array.isArray(components))
112
112
  components = this.renderedAreas.get(components) ?? [];
113
+ const siblings = components.map(c => c.component);
113
114
  const wrap = opts?.wrap ?? defaultWrap;
114
115
  if (opts?.skipContent && !this.editMode)
115
116
  return '';
116
117
  if (opts?.skipBars || opts?.skipEditBars || !this.editMode)
117
- return components.map((c, indexInArea) => wrap({ ...c, content: c.output, bar: '', indexInArea })).join('');
118
+ return components.map((c, indexInArea) => wrap({ ...c, content: c.output, bar: '', indexInArea, siblings })).join('');
118
119
  return components
119
120
  .map((c, indexInArea) => {
120
121
  if (c.component.inheritedFrom && opts?.hideInheritBars) {
121
- return opts.skipContent ? '' : wrap({ ...c, content: c.output, bar: '', indexInArea });
122
+ return opts.skipContent ? '' : wrap({ ...c, content: c.output, bar: '', indexInArea, siblings });
122
123
  }
123
124
  else {
124
125
  const bar = c.component.editBar({
@@ -127,7 +128,7 @@ export class Component extends ResourceProvider {
127
128
  extraClass: typeof opts?.editBarOpts?.extraClass === 'function' ? opts.editBarOpts.extraClass(c.component) : opts?.editBarOpts?.extraClass
128
129
  });
129
130
  const content = opts?.skipContent ? '' : c.output;
130
- return wrap({ output: bar + content, content, bar, component: c.component, indexInArea });
131
+ return wrap({ output: bar + content, content, bar, component: c.component, indexInArea, siblings });
131
132
  }
132
133
  }).join('');
133
134
  }
@@ -159,7 +160,7 @@ export class Component extends ResourceProvider {
159
160
  bar = this.newBar(areaName, opts?.newBarOpts);
160
161
  }
161
162
  if (bar != null)
162
- output += wrap({ output: bar, content: '', bar, indexInArea: components.length });
163
+ output += wrap({ output: bar, content: '', bar, indexInArea: components.length, siblings: components.map(c => c.component) });
163
164
  }
164
165
  return output;
165
166
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dosgato/templating",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "A library to support building templates for dosgato CMS.",
5
5
  "type": "module",
6
6
  "exports": {