@dosgato/templating 0.0.73 → 0.0.74
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 +54 -3
- package/dist/component.js +21 -11
- package/package.json +1 -1
package/dist/component.d.ts
CHANGED
|
@@ -288,6 +288,40 @@ export interface RenderAreaEditBarOpts extends Omit<Omit<EditBarOpts, 'label'>,
|
|
|
288
288
|
export interface NewBarOpts extends BarOpts {
|
|
289
289
|
disabled?: boolean;
|
|
290
290
|
}
|
|
291
|
+
export interface RenderComponentsWrapParams {
|
|
292
|
+
/**
|
|
293
|
+
* Contains both the regular component content and the edit bar (or the new bar).
|
|
294
|
+
*
|
|
295
|
+
* Use this if you want to wrap content and edit bar together.
|
|
296
|
+
*/
|
|
297
|
+
output: string;
|
|
298
|
+
/**
|
|
299
|
+
* Contains only the regular component content and not the edit bar.
|
|
300
|
+
*
|
|
301
|
+
* If you use this, make sure to also use the bar parameter or else
|
|
302
|
+
* you'll never print the edit bar and your components will be uneditable.
|
|
303
|
+
*/
|
|
304
|
+
content: string;
|
|
305
|
+
/**
|
|
306
|
+
* Contains the edit bar or new bar, depending on the situation.
|
|
307
|
+
*
|
|
308
|
+
* Use this if you want to wrap the bar separately from the component content.
|
|
309
|
+
*
|
|
310
|
+
* Will be blank in edit mode or when skipBars was set to true on the renderArea
|
|
311
|
+
* and/or renderComponents call. You probably want to check if it's blank before
|
|
312
|
+
* wrapping or you'll end up with an empty wrapper element.
|
|
313
|
+
*/
|
|
314
|
+
bar: string;
|
|
315
|
+
/**
|
|
316
|
+
* Contains the full component being wrapped.
|
|
317
|
+
*
|
|
318
|
+
* Use this if you need to check the component's data to alter your
|
|
319
|
+
* wrapping behavior.
|
|
320
|
+
*
|
|
321
|
+
* Will be undefined for the new bar, so check that it is not null.
|
|
322
|
+
*/
|
|
323
|
+
component?: Component;
|
|
324
|
+
}
|
|
291
325
|
export interface RenderComponentsOpts {
|
|
292
326
|
/**
|
|
293
327
|
* Hide bars entiredly for inherited items instead of allowing the user
|
|
@@ -301,20 +335,37 @@ export interface RenderComponentsOpts {
|
|
|
301
335
|
* re-order them easily.
|
|
302
336
|
*/
|
|
303
337
|
skipBars?: boolean;
|
|
338
|
+
/**
|
|
339
|
+
* Only skip edit bars, but print the new bar normally.
|
|
340
|
+
*
|
|
341
|
+
* If skipBars is also true, the new bar will not print normally, obviously.
|
|
342
|
+
*/
|
|
343
|
+
skipEditBars?: boolean;
|
|
344
|
+
/**
|
|
345
|
+
* Only skip the new bar, but print the edit bars normally.
|
|
346
|
+
*
|
|
347
|
+
* If skipBars is also true, the edit bars will not print normally, obviously.
|
|
348
|
+
*/
|
|
349
|
+
skipNewBar?: boolean;
|
|
304
350
|
/**
|
|
305
351
|
* Do not print the content, only print edit and new bars. This is the other half
|
|
306
352
|
* of skipBars. You'd print bars in one place and content in another.
|
|
353
|
+
*
|
|
354
|
+
* If you only want to print the new bar, you need to set BOTH skipContent
|
|
355
|
+
* and skipEditBars.
|
|
307
356
|
*/
|
|
308
357
|
skipContent?: boolean;
|
|
309
358
|
/**
|
|
310
359
|
* Provide a function that wraps each component, e.g.
|
|
311
|
-
* (output
|
|
360
|
+
* ({ output }) => `<li>${output}</li>`
|
|
312
361
|
*
|
|
313
|
-
*
|
|
362
|
+
* Wrap receives a lot of optional paramaters so that you can customize the behavior. For
|
|
363
|
+
* instance, you may want to wrap the content but not the edit bar, or vice versa. See
|
|
364
|
+
* the comments on each parameter for more info.
|
|
314
365
|
*
|
|
315
366
|
* If you need it (unlikely), the full component object is provided as a second parameter.
|
|
316
367
|
*/
|
|
317
|
-
wrap?: (
|
|
368
|
+
wrap?: (info: RenderComponentsWrapParams) => string;
|
|
318
369
|
/**
|
|
319
370
|
* Options for each edit bar; also accepts functions for label and extraClass
|
|
320
371
|
*/
|
package/dist/component.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isNotBlank } from 'txstate-utils';
|
|
2
2
|
import { ResourceProvider } from './provider.js';
|
|
3
|
-
function defaultWrap(
|
|
3
|
+
function defaultWrap(info) { return info.output; }
|
|
4
4
|
/**
|
|
5
5
|
* This is the primary templating class to build your templates. Subclass it and provide
|
|
6
6
|
* at least a render function.
|
|
@@ -97,16 +97,22 @@ export class Component extends ResourceProvider {
|
|
|
97
97
|
if (!Array.isArray(components))
|
|
98
98
|
components = this.renderedAreas.get(components) ?? [];
|
|
99
99
|
const wrap = opts?.wrap ?? defaultWrap;
|
|
100
|
-
if (opts?.skipBars)
|
|
101
|
-
return components.map(c => wrap(c.output,
|
|
100
|
+
if (opts?.skipBars || opts?.skipEditBars)
|
|
101
|
+
return components.map(c => wrap({ ...c, content: c.output, bar: '' })).join('');
|
|
102
102
|
return components
|
|
103
|
-
.map(c =>
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
.map(c => {
|
|
104
|
+
if (c.component.inheritedFrom && opts?.hideInheritBars) {
|
|
105
|
+
return opts.skipContent ? '' : wrap({ ...c, content: c.output, bar: '' });
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
const bar = c.component.editBar({
|
|
106
109
|
...opts?.editBarOpts,
|
|
107
110
|
label: typeof opts?.editBarOpts?.label === 'function' ? opts.editBarOpts.label(c.component) : opts?.editBarOpts?.label,
|
|
108
111
|
extraClass: typeof opts?.editBarOpts?.extraClass === 'function' ? opts.editBarOpts.extraClass(c.component) : opts?.editBarOpts?.extraClass
|
|
109
|
-
})
|
|
112
|
+
});
|
|
113
|
+
return wrap({ output: bar + c.output, content: c.output, bar, component: c.component });
|
|
114
|
+
}
|
|
115
|
+
}).join('');
|
|
110
116
|
}
|
|
111
117
|
/**
|
|
112
118
|
* helper function to print an area and set a minimum or maximum number of components
|
|
@@ -125,14 +131,18 @@ export class Component extends ResourceProvider {
|
|
|
125
131
|
const full = !!(opts?.max && ownedComponentCount >= opts.max);
|
|
126
132
|
const wrap = opts?.wrap ?? defaultWrap;
|
|
127
133
|
let output = this.renderComponents(components, { ...opts, editBarOpts: { ...opts?.editBarOpts, disableDelete: ownedComponentCount <= (opts?.min ?? 0), disableDrop: full } });
|
|
128
|
-
if (!opts?.skipBars) {
|
|
134
|
+
if (!opts?.skipBars && !opts?.skipNewBar) {
|
|
135
|
+
let bar;
|
|
129
136
|
if (full) {
|
|
130
|
-
if (!opts.hideMaxWarning)
|
|
131
|
-
|
|
137
|
+
if (!opts.hideMaxWarning) {
|
|
138
|
+
bar = this.newBar(areaName, { ...opts.newBarOpts, label: opts.maxWarning ?? 'Maximum Reached', disabled: true });
|
|
139
|
+
}
|
|
132
140
|
}
|
|
133
141
|
else {
|
|
134
|
-
|
|
142
|
+
bar = this.newBar(areaName, opts?.newBarOpts);
|
|
135
143
|
}
|
|
144
|
+
if (bar != null)
|
|
145
|
+
output += wrap({ output: bar, content: '', bar });
|
|
136
146
|
}
|
|
137
147
|
return output;
|
|
138
148
|
}
|