@dosgato/templating 0.0.71 → 0.0.72

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.
@@ -308,9 +308,13 @@ export interface RenderComponentsOpts {
308
308
  skipContent?: boolean;
309
309
  /**
310
310
  * Provide a function that wraps each component, e.g.
311
- * (c: RenderedComponent) => `<li>${c.output}</li>`
311
+ * (output: string) => `<li>${output}</li>`
312
+ *
313
+ * Note that the wrap will also go around the edit bar.
314
+ *
315
+ * If you need it (unlikely), the full component object is provided as a second parameter.
312
316
  */
313
- wrap?: (c: RenderedComponent) => string;
317
+ wrap?: (output: string, c: Component) => string;
314
318
  /**
315
319
  * Options for each edit bar; also accepts functions for label and extraClass
316
320
  */
package/dist/component.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { isNotBlank } from 'txstate-utils';
2
2
  import { ResourceProvider } from './provider.js';
3
+ function defaultWrap(output) { return output; }
3
4
  /**
4
5
  * This is the primary templating class to build your templates. Subclass it and provide
5
6
  * at least a render function.
@@ -95,16 +96,17 @@ export class Component extends ResourceProvider {
95
96
  renderComponents(components = [], opts) {
96
97
  if (!Array.isArray(components))
97
98
  components = this.renderedAreas.get(components) ?? [];
99
+ const wrap = opts?.wrap ?? defaultWrap;
98
100
  if (opts?.skipBars)
99
- return components.map(c => opts.wrap?.(c) ?? c.output).join('');
101
+ return components.map(c => wrap(c.output, c.component)).join('');
100
102
  return components
101
- .flatMap(c => c.component.inheritedFrom && opts?.hideInheritBars
102
- ? [opts.skipContent ? '' : opts.wrap?.(c) ?? c.output]
103
- : [c.component.editBar({
103
+ .map(c => c.component.inheritedFrom && opts?.hideInheritBars
104
+ ? (opts.skipContent ? '' : wrap(c.output, c.component))
105
+ : wrap([c.component.editBar({
104
106
  ...opts?.editBarOpts,
105
107
  label: typeof opts?.editBarOpts?.label === 'function' ? opts.editBarOpts.label(c.component) : opts?.editBarOpts?.label,
106
108
  extraClass: typeof opts?.editBarOpts?.extraClass === 'function' ? opts.editBarOpts.extraClass(c.component) : opts?.editBarOpts?.extraClass
107
- }), opts?.skipContent ? '' : opts?.wrap?.(c) ?? c.output]).join('');
109
+ }), opts?.skipContent ? '' : c.output].join(''), c.component)).join('');
108
110
  }
109
111
  /**
110
112
  * helper function to print an area and set a minimum or maximum number of components
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dosgato/templating",
3
- "version": "0.0.71",
3
+ "version": "0.0.72",
4
4
  "description": "A library to support building templates for dosgato CMS.",
5
5
  "type": "module",
6
6
  "exports": {