@dosgato/templating 1.0.8 → 1.1.0
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/apitemplate.d.ts +15 -3
- package/dist/component.d.ts +31 -3
- package/dist/component.js +17 -9
- package/package.json +1 -1
package/dist/apitemplate.d.ts
CHANGED
|
@@ -34,15 +34,27 @@ export interface PageExtras {
|
|
|
34
34
|
linkId?: string;
|
|
35
35
|
/** The name the page has or will have. NOTE: looking the page up by name will not work during page creation. */
|
|
36
36
|
name: string;
|
|
37
|
+
/**
|
|
38
|
+
* The full page data before the validation/migration in case validating depends on the previous
|
|
39
|
+
* state of the page.
|
|
40
|
+
*
|
|
41
|
+
* Will be undefined during page creations, and equal to the data already being passed to a migration.
|
|
42
|
+
*/
|
|
43
|
+
page?: PageData;
|
|
37
44
|
}
|
|
38
45
|
export interface ComponentExtras extends PageExtras {
|
|
46
|
+
/** The path within the page data to the component currently being evaluated. */
|
|
47
|
+
path: string;
|
|
39
48
|
/**
|
|
40
|
-
* The full page data in case validating
|
|
49
|
+
* The full page data before the validation/migration in case validating depends on state
|
|
41
50
|
* elsewhere in the page.
|
|
42
51
|
*/
|
|
43
52
|
page: PageData;
|
|
44
|
-
/**
|
|
45
|
-
|
|
53
|
+
/**
|
|
54
|
+
* The component data before validation. Will be present during migration but equal to the
|
|
55
|
+
* data already being passed to the migration.
|
|
56
|
+
*/
|
|
57
|
+
currentData: ComponentData;
|
|
46
58
|
}
|
|
47
59
|
export interface DataExtras {
|
|
48
60
|
/** A function for executing a graphql query to acquire more information than is already at hand. */
|
package/dist/component.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
1
|
import type { IncomingHttpHeaders } from 'http';
|
|
4
2
|
import type { ParsedUrlQuery } from 'querystring';
|
|
5
3
|
import { ResourceProvider } from './provider.js';
|
|
@@ -89,7 +87,7 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
|
|
|
89
87
|
* The extension will NOT include the preceding dot. In the case of an extended extension like
|
|
90
88
|
* '.js.map', you should receive 'js.map'.
|
|
91
89
|
*/
|
|
92
|
-
shouldFetchVariation(extension: string):
|
|
90
|
+
shouldFetchVariation(extension: string): extension is "html";
|
|
93
91
|
/**
|
|
94
92
|
* Some components may be inheritable to subpages within the same site. For instance, a site's
|
|
95
93
|
* social media links may appear on every page's footer. To accomplish this in your template,
|
|
@@ -280,6 +278,11 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
|
|
|
280
278
|
* Its edit bar will not have a pencil icon.
|
|
281
279
|
*/
|
|
282
280
|
noData: boolean;
|
|
281
|
+
/**
|
|
282
|
+
* Override with `true` to indicate that this template renders its own edit bar
|
|
283
|
+
* so that the parent component will avoid rendering it
|
|
284
|
+
*/
|
|
285
|
+
renderIncludesEditBar: boolean;
|
|
283
286
|
/**
|
|
284
287
|
* Components may override this function to give their new bars a custom
|
|
285
288
|
* label
|
|
@@ -325,6 +328,16 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
|
|
|
325
328
|
reqHeaders: IncomingHttpHeaders;
|
|
326
329
|
reqQuery: ParsedUrlQuery;
|
|
327
330
|
indexInArea: number;
|
|
331
|
+
/**
|
|
332
|
+
* the full array of components in the same area as this component, including self
|
|
333
|
+
*
|
|
334
|
+
* empty for page component
|
|
335
|
+
*/
|
|
336
|
+
siblings: Component[];
|
|
337
|
+
/** the component before this one inside the area, null if this component is first */
|
|
338
|
+
prevSibling?: Component;
|
|
339
|
+
/** the component after this one inside the area, null if this component is last */
|
|
340
|
+
nextSibling?: Component;
|
|
328
341
|
/**
|
|
329
342
|
* For logging errors during rendering without crashing the render. If your fetch, setContext,
|
|
330
343
|
* render, or renderVariation functions throw, the error will be logged but the page render will
|
|
@@ -484,6 +497,21 @@ export interface RenderComponentsWrapParams {
|
|
|
484
497
|
* Will be undefined for the new bar, so check that it is not null.
|
|
485
498
|
*/
|
|
486
499
|
component?: Component;
|
|
500
|
+
/**
|
|
501
|
+
* Contains all the components in the same area as the component being rendered.
|
|
502
|
+
*
|
|
503
|
+
* Use this if you need to wrap multiple components together inside the same
|
|
504
|
+
* box. For instance, if you have several components of the same type in a row,
|
|
505
|
+
* perhaps you want them to automatically appear side by side in a flexbox.
|
|
506
|
+
*
|
|
507
|
+
* Your wrap function could inspect the components before and after the current
|
|
508
|
+
* component, based on indexInArea, and decide to open a div when the preceding is
|
|
509
|
+
* not the right type and the following is, then close the div when the preceding
|
|
510
|
+
* is the right type and the following is not.
|
|
511
|
+
*
|
|
512
|
+
* Will be defined when rendering the new bar.
|
|
513
|
+
*/
|
|
514
|
+
siblings: Component[];
|
|
487
515
|
}
|
|
488
516
|
export interface RenderComponentsOpts {
|
|
489
517
|
/**
|
package/dist/component.js
CHANGED
|
@@ -110,24 +110,27 @@ 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
|
-
const bar = c.component.
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
125
|
+
const bar = c.component.renderIncludesEditBar
|
|
126
|
+
? ''
|
|
127
|
+
: c.component.editBar({
|
|
128
|
+
...opts?.editBarOpts,
|
|
129
|
+
label: typeof opts?.editBarOpts?.label === 'function' ? opts.editBarOpts.label(c.component) : opts?.editBarOpts?.label,
|
|
130
|
+
extraClass: typeof opts?.editBarOpts?.extraClass === 'function' ? opts.editBarOpts.extraClass(c.component) : opts?.editBarOpts?.extraClass
|
|
131
|
+
});
|
|
129
132
|
const content = opts?.skipContent ? '' : c.output;
|
|
130
|
-
return wrap({ output: bar + content, content, bar, component: c.component, indexInArea });
|
|
133
|
+
return wrap({ output: bar + content, content, bar, component: c.component, indexInArea, siblings });
|
|
131
134
|
}
|
|
132
135
|
}).join('');
|
|
133
136
|
}
|
|
@@ -159,7 +162,7 @@ export class Component extends ResourceProvider {
|
|
|
159
162
|
bar = this.newBar(areaName, opts?.newBarOpts);
|
|
160
163
|
}
|
|
161
164
|
if (bar != null)
|
|
162
|
-
output += wrap({ output: bar, content: '', bar, indexInArea: components.length });
|
|
165
|
+
output += wrap({ output: bar, content: '', bar, indexInArea: components.length, siblings: components.map(c => c.component) });
|
|
163
166
|
}
|
|
164
167
|
return output;
|
|
165
168
|
}
|
|
@@ -244,6 +247,11 @@ export class Component extends ResourceProvider {
|
|
|
244
247
|
* Its edit bar will not have a pencil icon.
|
|
245
248
|
*/
|
|
246
249
|
this.noData = false;
|
|
250
|
+
/**
|
|
251
|
+
* Override with `true` to indicate that this template renders its own edit bar
|
|
252
|
+
* so that the parent component will avoid rendering it
|
|
253
|
+
*/
|
|
254
|
+
this.renderIncludesEditBar = false;
|
|
247
255
|
// Properties provided during the rendering process. You do not have to provide these when
|
|
248
256
|
// building a template, but you can use them in the functions you do provide
|
|
249
257
|
this.areas = new Map(); // a Map of area names and the array of hydrated components in each
|