@dosgato/templating 0.0.69 → 0.0.71
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 +89 -15
- package/dist/component.js +25 -14
- package/package.json +1 -1
package/dist/component.d.ts
CHANGED
|
@@ -112,24 +112,21 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
|
|
|
112
112
|
renderVariation(extension: string): string;
|
|
113
113
|
/**
|
|
114
114
|
* helper function to print an area's component list, but you can also override this if you
|
|
115
|
-
* need to do something advanced
|
|
115
|
+
* need to do something advanced
|
|
116
116
|
*/
|
|
117
|
-
renderComponents(components?: RenderedComponent[] | string, opts?:
|
|
118
|
-
hideInheritBars?: boolean;
|
|
119
|
-
editBarOpts?: RenderAreaEditBarOpts;
|
|
120
|
-
}): string;
|
|
117
|
+
renderComponents(components?: RenderedComponent[] | string, opts?: RenderComponentsOpts): string;
|
|
121
118
|
/**
|
|
122
119
|
* helper function to print an area and set a minimum or maximum number of components
|
|
120
|
+
*
|
|
121
|
+
* In some cases you might be rendering the edit bars in a separate div instead of placing
|
|
122
|
+
* them above each component. For instance, a slider that only shows one slide at a time may
|
|
123
|
+
* prefer not to put bars with slides because that would mean only one bar is visible at a time
|
|
124
|
+
* and then there's no way to re-order slides.
|
|
125
|
+
*
|
|
126
|
+
* In that case you would call this.renderArea('areaname', { ..., skipEditBars: true }) first
|
|
127
|
+
* and then this.renderArea('areaname', { ..., skipContent: true }) in another place.
|
|
123
128
|
*/
|
|
124
|
-
renderArea(areaName: string, opts?:
|
|
125
|
-
min?: number;
|
|
126
|
-
max?: number;
|
|
127
|
-
hideMaxWarning?: boolean;
|
|
128
|
-
maxWarning?: string;
|
|
129
|
-
hideInheritBars?: boolean;
|
|
130
|
-
newBarOpts?: NewBarOpts;
|
|
131
|
-
editBarOpts?: RenderAreaEditBarOpts;
|
|
132
|
-
}): string;
|
|
129
|
+
renderArea(areaName: string, opts?: RenderAreaOpts): string;
|
|
133
130
|
/**
|
|
134
131
|
* During rendering, each component should determine the CSS blocks that it needs. This may
|
|
135
132
|
* change depending on the data. For instance, if you need some CSS to style up an image, but
|
|
@@ -230,7 +227,7 @@ export interface PageRecord<DataType extends PageData = PageData> {
|
|
|
230
227
|
linkId: string;
|
|
231
228
|
createdAt: Date;
|
|
232
229
|
modifiedAt: Date;
|
|
233
|
-
publishedAt
|
|
230
|
+
publishedAt?: Date;
|
|
234
231
|
path: string;
|
|
235
232
|
data: DataType;
|
|
236
233
|
site: SiteInfo;
|
|
@@ -273,12 +270,89 @@ export interface EditBarOpts extends BarOpts {
|
|
|
273
270
|
hideEdit?: boolean;
|
|
274
271
|
}
|
|
275
272
|
export interface RenderAreaEditBarOpts extends Omit<Omit<EditBarOpts, 'label'>, 'extraClass'> {
|
|
273
|
+
/**
|
|
274
|
+
* Since renderArea and renderComponents render a whole list of components,
|
|
275
|
+
* they accept functions for editBarOpts.label and editBarOpts.extraClass
|
|
276
|
+
*
|
|
277
|
+
* This way you can have labels and classes depend on the data of the component.
|
|
278
|
+
*/
|
|
276
279
|
label?: string | ((c: Component) => string);
|
|
280
|
+
/**
|
|
281
|
+
* Since renderArea and renderComponents render a whole list of components,
|
|
282
|
+
* they accept functions for editBarOpts.label and editBarOpts.extraClass
|
|
283
|
+
*
|
|
284
|
+
* This way you can have labels and classes depend on the data of the component.
|
|
285
|
+
*/
|
|
277
286
|
extraClass?: string | ((c: Component) => string);
|
|
278
287
|
}
|
|
279
288
|
export interface NewBarOpts extends BarOpts {
|
|
280
289
|
disabled?: boolean;
|
|
281
290
|
}
|
|
291
|
+
export interface RenderComponentsOpts {
|
|
292
|
+
/**
|
|
293
|
+
* Hide bars entiredly for inherited items instead of allowing the user
|
|
294
|
+
* to link back to the creating page. Useful for headers and footers where it's
|
|
295
|
+
* obvious the entire site shares the data from the root page.
|
|
296
|
+
*/
|
|
297
|
+
hideInheritBars?: boolean;
|
|
298
|
+
/**
|
|
299
|
+
* Do not print edit or new bars. Useful for components that have view-one-at-a-time
|
|
300
|
+
* subcomponents. If you don't move your editbars somewhere else, you'll be unable to
|
|
301
|
+
* re-order them easily.
|
|
302
|
+
*/
|
|
303
|
+
skipBars?: boolean;
|
|
304
|
+
/**
|
|
305
|
+
* Do not print the content, only print edit and new bars. This is the other half
|
|
306
|
+
* of skipBars. You'd print bars in one place and content in another.
|
|
307
|
+
*/
|
|
308
|
+
skipContent?: boolean;
|
|
309
|
+
/**
|
|
310
|
+
* Provide a function that wraps each component, e.g.
|
|
311
|
+
* (c: RenderedComponent) => `<li>${c.output}</li>`
|
|
312
|
+
*/
|
|
313
|
+
wrap?: (c: RenderedComponent) => string;
|
|
314
|
+
/**
|
|
315
|
+
* Options for each edit bar; also accepts functions for label and extraClass
|
|
316
|
+
*/
|
|
317
|
+
editBarOpts?: RenderAreaEditBarOpts;
|
|
318
|
+
}
|
|
319
|
+
export interface RenderAreaOpts extends RenderComponentsOpts {
|
|
320
|
+
/**
|
|
321
|
+
* Set a minimum number of components for the area.
|
|
322
|
+
*
|
|
323
|
+
* Enforcement of the minimum components is UI-only. It's possible for a
|
|
324
|
+
* page to be imported or updated via API with less than the minimum.
|
|
325
|
+
*/
|
|
326
|
+
min?: number;
|
|
327
|
+
/**
|
|
328
|
+
* Set a maximum number of components for the area.
|
|
329
|
+
*
|
|
330
|
+
* Enforcement of the maximum components is UI-only. It's possible for a
|
|
331
|
+
* page to be imported or updated via API with more than the maximum.
|
|
332
|
+
*/
|
|
333
|
+
max?: number;
|
|
334
|
+
/**
|
|
335
|
+
* Remove new bar when max is reached
|
|
336
|
+
*
|
|
337
|
+
* If you've set a max, the new bar will change to disabled and change its
|
|
338
|
+
* label when the max has been reached or exceeded. Set this true to completely
|
|
339
|
+
* remove the new bar instead.
|
|
340
|
+
*/
|
|
341
|
+
hideMaxWarning?: boolean;
|
|
342
|
+
/**
|
|
343
|
+
* Set the maximum reached warning label
|
|
344
|
+
*
|
|
345
|
+
* If you've set a max, the new bar will change to disabled and change its
|
|
346
|
+
* label when the max has been reached or exceeded. Set this to adjust the
|
|
347
|
+
* wording of the maximum reached warning, when applicable.
|
|
348
|
+
*/
|
|
349
|
+
maxWarning?: string;
|
|
350
|
+
/**
|
|
351
|
+
* Options to pass into the new bar. Note that some like 'disabled' will
|
|
352
|
+
* be overridden if you have set a max.
|
|
353
|
+
*/
|
|
354
|
+
newBarOpts?: NewBarOpts;
|
|
355
|
+
}
|
|
282
356
|
export interface RenderedComponent<C extends Component = Component> {
|
|
283
357
|
component: C;
|
|
284
358
|
output: string;
|
package/dist/component.js
CHANGED
|
@@ -90,35 +90,46 @@ export class Component extends ResourceProvider {
|
|
|
90
90
|
}
|
|
91
91
|
/**
|
|
92
92
|
* helper function to print an area's component list, but you can also override this if you
|
|
93
|
-
* need to do something advanced
|
|
93
|
+
* need to do something advanced
|
|
94
94
|
*/
|
|
95
95
|
renderComponents(components = [], opts) {
|
|
96
96
|
if (!Array.isArray(components))
|
|
97
97
|
components = this.renderedAreas.get(components) ?? [];
|
|
98
|
+
if (opts?.skipBars)
|
|
99
|
+
return components.map(c => opts.wrap?.(c) ?? c.output).join('');
|
|
98
100
|
return components
|
|
99
|
-
.flatMap(c => c.component.inheritedFrom &&
|
|
100
|
-
opts?.
|
|
101
|
-
? [c.output]
|
|
101
|
+
.flatMap(c => c.component.inheritedFrom && opts?.hideInheritBars
|
|
102
|
+
? [opts.skipContent ? '' : opts.wrap?.(c) ?? c.output]
|
|
102
103
|
: [c.component.editBar({
|
|
103
104
|
...opts?.editBarOpts,
|
|
104
105
|
label: typeof opts?.editBarOpts?.label === 'function' ? opts.editBarOpts.label(c.component) : opts?.editBarOpts?.label,
|
|
105
106
|
extraClass: typeof opts?.editBarOpts?.extraClass === 'function' ? opts.editBarOpts.extraClass(c.component) : opts?.editBarOpts?.extraClass
|
|
106
|
-
}), c.output]).join('');
|
|
107
|
+
}), opts?.skipContent ? '' : opts?.wrap?.(c) ?? c.output]).join('');
|
|
107
108
|
}
|
|
108
109
|
/**
|
|
109
110
|
* helper function to print an area and set a minimum or maximum number of components
|
|
111
|
+
*
|
|
112
|
+
* In some cases you might be rendering the edit bars in a separate div instead of placing
|
|
113
|
+
* them above each component. For instance, a slider that only shows one slide at a time may
|
|
114
|
+
* prefer not to put bars with slides because that would mean only one bar is visible at a time
|
|
115
|
+
* and then there's no way to re-order slides.
|
|
116
|
+
*
|
|
117
|
+
* In that case you would call this.renderArea('areaname', { ..., skipEditBars: true }) first
|
|
118
|
+
* and then this.renderArea('areaname', { ..., skipContent: true }) in another place.
|
|
110
119
|
*/
|
|
111
120
|
renderArea(areaName, opts) {
|
|
112
121
|
const components = this.renderedAreas.get(areaName) ?? [];
|
|
113
122
|
const ownedComponentCount = components.filter(c => !c.component.inheritedFrom).length;
|
|
114
123
|
const full = !!(opts?.max && ownedComponentCount >= opts.max);
|
|
115
|
-
let output = this.renderComponents(components, {
|
|
116
|
-
if (
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
124
|
+
let output = this.renderComponents(components, { ...opts, editBarOpts: { ...opts?.editBarOpts, disableDelete: ownedComponentCount <= (opts?.min ?? 0), disableDrop: full } });
|
|
125
|
+
if (!opts?.skipBars) {
|
|
126
|
+
if (full) {
|
|
127
|
+
if (!opts.hideMaxWarning)
|
|
128
|
+
output += this.newBar(areaName, { ...opts.newBarOpts, label: opts.maxWarning ?? 'Maximum Reached', disabled: true });
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
output += this.newBar(areaName, opts?.newBarOpts);
|
|
132
|
+
}
|
|
122
133
|
}
|
|
123
134
|
return output;
|
|
124
135
|
}
|
|
@@ -175,7 +186,7 @@ export class Component extends ResourceProvider {
|
|
|
175
186
|
editBar(opts = {}) {
|
|
176
187
|
const options = { ...opts };
|
|
177
188
|
options.label ?? (options.label = this.editLabel() ?? this.autoLabel);
|
|
178
|
-
options.extraClass
|
|
189
|
+
options.extraClass = [options.extraClass, this.editClass()].filter(isNotBlank).join(' ');
|
|
179
190
|
options.editMode ?? (options.editMode = this.editMode);
|
|
180
191
|
options.inheritedFrom ?? (options.inheritedFrom = this.inheritedFrom);
|
|
181
192
|
options.hideEdit = this.noData || options.hideEdit;
|
|
@@ -189,7 +200,7 @@ export class Component extends ResourceProvider {
|
|
|
189
200
|
newBar(areaName, opts = {}) {
|
|
190
201
|
const options = { ...opts };
|
|
191
202
|
options.label ?? (options.label = this.newLabel(areaName) ?? (this.areas.size > 1 ? `Add ${areaName} Content` : `Add ${this.autoLabel} Content`));
|
|
192
|
-
options.extraClass
|
|
203
|
+
options.extraClass = [options.extraClass, this.newClass(areaName)].filter(isNotBlank).join(' ');
|
|
193
204
|
options.editMode ?? (options.editMode = this.editMode);
|
|
194
205
|
return Component.newBar([this.path, 'areas', areaName].filter(isNotBlank).join('.'), options);
|
|
195
206
|
}
|