@dosgato/templating 1.0.7 → 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.
- package/dist/component.d.ts +26 -0
- package/dist/component.js +5 -4
- package/dist/uitemplate.d.ts +22 -0
- package/package.json +1 -1
package/dist/component.d.ts
CHANGED
|
@@ -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
|
|
@@ -439,6 +449,7 @@ export interface RenderAreaEditBarOpts extends Omit<Omit<EditBarOpts, 'label'>,
|
|
|
439
449
|
}
|
|
440
450
|
export interface NewBarOpts extends BarOpts {
|
|
441
451
|
disabled?: boolean;
|
|
452
|
+
disableAddToTop?: boolean;
|
|
442
453
|
}
|
|
443
454
|
export interface RenderComponentsWrapParams {
|
|
444
455
|
/**
|
|
@@ -483,6 +494,21 @@ export interface RenderComponentsWrapParams {
|
|
|
483
494
|
* Will be undefined for the new bar, so check that it is not null.
|
|
484
495
|
*/
|
|
485
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[];
|
|
486
512
|
}
|
|
487
513
|
export interface RenderComponentsOpts {
|
|
488
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/dist/uitemplate.d.ts
CHANGED
|
@@ -108,6 +108,28 @@ export interface UITemplate extends UITemplateBase {
|
|
|
108
108
|
*/
|
|
109
109
|
shouldAppear?: (data: PageData, path: string) => boolean;
|
|
110
110
|
}[];
|
|
111
|
+
/**
|
|
112
|
+
* Customize the device preview dropdown. Only applies to page templates. Default is to show
|
|
113
|
+
* Mobile and Desktop in preview mode only.
|
|
114
|
+
*/
|
|
115
|
+
devicePreview?: {
|
|
116
|
+
/**
|
|
117
|
+
* Set this to an object to customize the sizes available on the preview device dropdown.
|
|
118
|
+
* Leave width undefined to use all available space. The first entry marked default will be
|
|
119
|
+
* active on first page load. If none are default, the largest is default.
|
|
120
|
+
* Example: [{ label: 'Mobile', width: 400 }, { label: 'Desktop', default: true }]
|
|
121
|
+
*/
|
|
122
|
+
sizes?: {
|
|
123
|
+
label: string;
|
|
124
|
+
width?: number;
|
|
125
|
+
default?: boolean;
|
|
126
|
+
}[];
|
|
127
|
+
/**
|
|
128
|
+
* If your template is heavily mobile focused, you may want editors to have the device
|
|
129
|
+
* dropdown while editing, in addition to previewing. Set this true to enable that.
|
|
130
|
+
*/
|
|
131
|
+
showWhileEditing?: boolean;
|
|
132
|
+
};
|
|
111
133
|
}
|
|
112
134
|
export interface ExtraDataColumn {
|
|
113
135
|
/**
|