@dosgato/templating 0.0.71 → 0.0.73
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.
- package/dist/component.d.ts +6 -2
- package/dist/component.js +10 -7
- package/package.json +1 -1
package/dist/component.d.ts
CHANGED
|
@@ -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
|
-
* (
|
|
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?: (
|
|
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 =>
|
|
101
|
+
return components.map(c => wrap(c.output, c.component)).join('');
|
|
100
102
|
return components
|
|
101
|
-
.
|
|
102
|
-
?
|
|
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 ? '' :
|
|
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
|
|
@@ -121,14 +123,15 @@ export class Component extends ResourceProvider {
|
|
|
121
123
|
const components = this.renderedAreas.get(areaName) ?? [];
|
|
122
124
|
const ownedComponentCount = components.filter(c => !c.component.inheritedFrom).length;
|
|
123
125
|
const full = !!(opts?.max && ownedComponentCount >= opts.max);
|
|
126
|
+
const wrap = opts?.wrap ?? defaultWrap;
|
|
124
127
|
let output = this.renderComponents(components, { ...opts, editBarOpts: { ...opts?.editBarOpts, disableDelete: ownedComponentCount <= (opts?.min ?? 0), disableDrop: full } });
|
|
125
128
|
if (!opts?.skipBars) {
|
|
126
129
|
if (full) {
|
|
127
130
|
if (!opts.hideMaxWarning)
|
|
128
|
-
output += this.newBar(areaName, { ...opts.newBarOpts, label: opts.maxWarning ?? 'Maximum Reached', disabled: true });
|
|
131
|
+
output += wrap(this.newBar(areaName, { ...opts.newBarOpts, label: opts.maxWarning ?? 'Maximum Reached', disabled: true }));
|
|
129
132
|
}
|
|
130
133
|
else {
|
|
131
|
-
output += this.newBar(areaName, opts?.newBarOpts);
|
|
134
|
+
output += wrap(this.newBar(areaName, opts?.newBarOpts));
|
|
132
135
|
}
|
|
133
136
|
}
|
|
134
137
|
return output;
|