@dosgato/templating 0.0.94 → 0.0.96
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 +2 -2
- package/dist/component.d.ts +41 -7
- package/dist/component.js +30 -4
- package/package.json +1 -1
package/dist/apitemplate.d.ts
CHANGED
|
@@ -185,8 +185,8 @@ export declare type ComponentMigration<DataType extends ComponentData = Componen
|
|
|
185
185
|
export declare type PageMigration<DataType extends PageData = PageData> = Migration<DataType, PageExtras>;
|
|
186
186
|
export declare type DataMigration<DataType extends DataData = DataData> = Migration<DataType, DataExtras>;
|
|
187
187
|
export declare type AnyMigration = ComponentMigration | PageMigration | DataMigration;
|
|
188
|
-
export declare type LinkGatheringFn<DataType> = (data: DataType) => LinkDefinition[];
|
|
189
|
-
export declare type FulltextGatheringFn<DataType> = (data: DataType) => string[];
|
|
188
|
+
export declare type LinkGatheringFn<DataType> = (data: DataType) => (LinkDefinition | string | undefined)[];
|
|
189
|
+
export declare type FulltextGatheringFn<DataType> = (data: DataType) => (string | undefined)[];
|
|
190
190
|
export declare type GraphQLQueryFn = <T>(query: string, variables?: any) => Promise<T>;
|
|
191
191
|
/**
|
|
192
192
|
* This function is used by API template definitions to help them identify all the searchable
|
package/dist/component.d.ts
CHANGED
|
@@ -32,6 +32,12 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
|
|
|
32
32
|
* The editBar and newBar methods will automatically use it to blank out the editing UI.
|
|
33
33
|
*/
|
|
34
34
|
editMode: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* The extension of the variation currently being rendered.
|
|
37
|
+
*
|
|
38
|
+
* See 'renderVariation' and 'variationsToFetch' for more discussion of variations.
|
|
39
|
+
*/
|
|
40
|
+
extension: string;
|
|
35
41
|
/**
|
|
36
42
|
* When hydrating an inherited component, the renderer will set this to the id of the page it
|
|
37
43
|
* came from. You may use this information in any of the phases to alter your behavior if needed.
|
|
@@ -61,8 +67,29 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
|
|
|
61
67
|
* Try to minimize the number of round trips you make here, make use of Promise.all and such;
|
|
62
68
|
* remember that the api functions are mostly dataloaded so calling them simultaneously is
|
|
63
69
|
* advantageous where possible.
|
|
70
|
+
*
|
|
71
|
+
* fetch() may be run while rendering a non-HTML variation of a page. If you need to do different
|
|
72
|
+
* work in those cases, remember this.extension is available.
|
|
64
73
|
*/
|
|
65
74
|
fetch(): Promise<FetchedType>;
|
|
75
|
+
/**
|
|
76
|
+
* Only run fetch for specific variations.
|
|
77
|
+
*
|
|
78
|
+
* Sometimes pages are requested with an alternate extension like .rss or .ics. See 'renderVariation'
|
|
79
|
+
* method for more discussion on this.
|
|
80
|
+
*
|
|
81
|
+
* When rendering variations, many components will not need to fetch anything, because they are not
|
|
82
|
+
* going to render anything. For instance, if we are rendering an '.ics' variation and this component
|
|
83
|
+
* is not an event, it will not be participating and we'd like to avoid doing the work in the fetch().
|
|
84
|
+
*
|
|
85
|
+
* This variable is an array of extensions where we SHOULD run fetch(). The default is only run fetch
|
|
86
|
+
* on 'html'. Components that support other variations should override this method and opt in to more
|
|
87
|
+
* extensions.
|
|
88
|
+
*
|
|
89
|
+
* The extensions listed should NOT include the preceding dot. In the case of an extended extension like
|
|
90
|
+
* '.js.map', you should provide 'js.map'.
|
|
91
|
+
*/
|
|
92
|
+
static variationsToFetch: string[];
|
|
66
93
|
/**
|
|
67
94
|
* Some components may be inheritable to subpages within the same site. For instance, a site's
|
|
68
95
|
* social media links may appear on every page's footer. To accomplish this in your template,
|
|
@@ -141,7 +168,7 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
|
|
|
141
168
|
* method to prepare editor-provided HTML for later rendering. It will do things like find and
|
|
142
169
|
* resolve link definitions in the internal dosgato format.
|
|
143
170
|
*/
|
|
144
|
-
fetchRichText: (
|
|
171
|
+
fetchRichText: (html: string | undefined) => Promise<void>;
|
|
145
172
|
/**
|
|
146
173
|
* This function will be provided by the rendering server and should be used during the render
|
|
147
174
|
* phase to clean up editor-provided HTML. It will do things like clean up tags that were accidentally
|
|
@@ -166,7 +193,7 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
|
|
|
166
193
|
* If this.data.title is non-blank, the rich text will be balanced below it, but if it is blank,
|
|
167
194
|
* it will be balanced at the level the title would have had.
|
|
168
195
|
*/
|
|
169
|
-
renderRichText: (html: string, opts?: {
|
|
196
|
+
renderRichText: (html: string | undefined, opts?: {
|
|
170
197
|
headerLevel?: number;
|
|
171
198
|
advanceHeader?: string;
|
|
172
199
|
}) => string;
|
|
@@ -186,6 +213,9 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
|
|
|
186
213
|
* respond, or return empty string if you want your child components to be silent in all
|
|
187
214
|
* cases.
|
|
188
215
|
*
|
|
216
|
+
* The extension will NOT include the preceding dot. In the case of an extended extension like
|
|
217
|
+
* '.js.map', you will receive 'js.map'.
|
|
218
|
+
*
|
|
189
219
|
* This function will be run after the fetch phase. The context and html rendering phases
|
|
190
220
|
* will be skipped.
|
|
191
221
|
*/
|
|
@@ -272,7 +302,7 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
|
|
|
272
302
|
*/
|
|
273
303
|
static editBar: (path: string, opts: EditBarOpts) => string;
|
|
274
304
|
static newBar: (path: string, opts: NewBarOpts) => string;
|
|
275
|
-
constructor(data: DataType, path: string, parent: Component | undefined, editMode: boolean);
|
|
305
|
+
constructor(data: DataType, path: string, parent: Component | undefined, editMode: boolean, extension: string);
|
|
276
306
|
areas: Map<string, Component<any, any, ContextBase>[]>;
|
|
277
307
|
data: Omit<DataType, 'areas'>;
|
|
278
308
|
fetched: FetchedType;
|
|
@@ -385,6 +415,10 @@ export interface RenderComponentsWrapParams {
|
|
|
385
415
|
*
|
|
386
416
|
* If you use this, make sure to also use the bar parameter or else
|
|
387
417
|
* you'll never print the edit bar and your components will be uneditable.
|
|
418
|
+
*
|
|
419
|
+
* This will be an empty string for new bars and when being rendered with skipContent
|
|
420
|
+
* set to true. If you need to determine whether you're wrapping a new bar,
|
|
421
|
+
* check component == null instead of checking this.
|
|
388
422
|
*/
|
|
389
423
|
content: string;
|
|
390
424
|
/**
|
|
@@ -392,9 +426,9 @@ export interface RenderComponentsWrapParams {
|
|
|
392
426
|
*
|
|
393
427
|
* Use this if you want to wrap the bar separately from the component content.
|
|
394
428
|
*
|
|
395
|
-
* Will be
|
|
396
|
-
* and/or renderComponents call. You probably want to check if it's
|
|
397
|
-
* wrapping or you'll end up with an empty wrapper element.
|
|
429
|
+
* Will be empty string when not in edit mode or when skipBars was set to true on
|
|
430
|
+
* the renderArea and/or renderComponents call. You probably want to check if it's
|
|
431
|
+
* blank before wrapping or you'll end up with an empty wrapper element.
|
|
398
432
|
*/
|
|
399
433
|
bar: string;
|
|
400
434
|
/**
|
|
@@ -540,6 +574,6 @@ export declare abstract class Page<DataType extends PageData = any, FetchedType
|
|
|
540
574
|
*/
|
|
541
575
|
addHeader: (key: string, value: string | undefined) => void;
|
|
542
576
|
protected passError(e: Error, path: string): void;
|
|
543
|
-
constructor(page: PageRecord<DataType>, editMode: boolean);
|
|
577
|
+
constructor(page: PageRecord<DataType>, editMode: boolean, extension: string);
|
|
544
578
|
}
|
|
545
579
|
export {};
|
package/dist/component.js
CHANGED
|
@@ -11,7 +11,7 @@ function defaultWrap(info) { return info.output; }
|
|
|
11
11
|
export class Component extends ResourceProvider {
|
|
12
12
|
// the constructor is part of the recursive hydration mechanism: constructing
|
|
13
13
|
// a Component will also construct/hydrate all its child components
|
|
14
|
-
constructor(data, path, parent, editMode) {
|
|
14
|
+
constructor(data, path, parent, editMode, extension) {
|
|
15
15
|
super();
|
|
16
16
|
/**
|
|
17
17
|
* Override with `true` to indicate that this template never accepts data from editors
|
|
@@ -23,6 +23,7 @@ export class Component extends ResourceProvider {
|
|
|
23
23
|
// building a template, but you can use them in the functions you do provide
|
|
24
24
|
this.areas = new Map(); // a Map of area names and the array of hydrated components in each
|
|
25
25
|
this.editMode = editMode;
|
|
26
|
+
this.extension = extension;
|
|
26
27
|
this.parent = parent;
|
|
27
28
|
const { areas, ...ownData } = data;
|
|
28
29
|
this.data = ownData;
|
|
@@ -52,6 +53,9 @@ export class Component extends ResourceProvider {
|
|
|
52
53
|
* Try to minimize the number of round trips you make here, make use of Promise.all and such;
|
|
53
54
|
* remember that the api functions are mostly dataloaded so calling them simultaneously is
|
|
54
55
|
* advantageous where possible.
|
|
56
|
+
*
|
|
57
|
+
* fetch() may be run while rendering a non-HTML variation of a page. If you need to do different
|
|
58
|
+
* work in those cases, remember this.extension is available.
|
|
55
59
|
*/
|
|
56
60
|
async fetch() {
|
|
57
61
|
return undefined;
|
|
@@ -99,6 +103,9 @@ export class Component extends ResourceProvider {
|
|
|
99
103
|
* respond, or return empty string if you want your child components to be silent in all
|
|
100
104
|
* cases.
|
|
101
105
|
*
|
|
106
|
+
* The extension will NOT include the preceding dot. In the case of an extended extension like
|
|
107
|
+
* '.js.map', you will receive 'js.map'.
|
|
108
|
+
*
|
|
102
109
|
* This function will be run after the fetch phase. The context and html rendering phases
|
|
103
110
|
* will be skipped.
|
|
104
111
|
*/
|
|
@@ -126,7 +133,8 @@ export class Component extends ResourceProvider {
|
|
|
126
133
|
label: typeof opts?.editBarOpts?.label === 'function' ? opts.editBarOpts.label(c.component) : opts?.editBarOpts?.label,
|
|
127
134
|
extraClass: typeof opts?.editBarOpts?.extraClass === 'function' ? opts.editBarOpts.extraClass(c.component) : opts?.editBarOpts?.extraClass
|
|
128
135
|
});
|
|
129
|
-
|
|
136
|
+
const content = opts?.skipContent ? '' : c.output;
|
|
137
|
+
return wrap({ output: bar + content, content, bar, component: c.component, indexInArea });
|
|
130
138
|
}
|
|
131
139
|
}).join('');
|
|
132
140
|
}
|
|
@@ -247,9 +255,27 @@ export class Component extends ResourceProvider {
|
|
|
247
255
|
this.parent?.passError(e, path);
|
|
248
256
|
}
|
|
249
257
|
}
|
|
258
|
+
/**
|
|
259
|
+
* Only run fetch for specific variations.
|
|
260
|
+
*
|
|
261
|
+
* Sometimes pages are requested with an alternate extension like .rss or .ics. See 'renderVariation'
|
|
262
|
+
* method for more discussion on this.
|
|
263
|
+
*
|
|
264
|
+
* When rendering variations, many components will not need to fetch anything, because they are not
|
|
265
|
+
* going to render anything. For instance, if we are rendering an '.ics' variation and this component
|
|
266
|
+
* is not an event, it will not be participating and we'd like to avoid doing the work in the fetch().
|
|
267
|
+
*
|
|
268
|
+
* This variable is an array of extensions where we SHOULD run fetch(). The default is only run fetch
|
|
269
|
+
* on 'html'. Components that support other variations should override this method and opt in to more
|
|
270
|
+
* extensions.
|
|
271
|
+
*
|
|
272
|
+
* The extensions listed should NOT include the preceding dot. In the case of an extended extension like
|
|
273
|
+
* '.js.map', you should provide 'js.map'.
|
|
274
|
+
*/
|
|
275
|
+
Component.variationsToFetch = ['html'];
|
|
250
276
|
export class Page extends Component {
|
|
251
|
-
constructor(page, editMode) {
|
|
252
|
-
super(page.data, '', undefined, editMode);
|
|
277
|
+
constructor(page, editMode, extension) {
|
|
278
|
+
super(page.data, '', undefined, editMode, extension);
|
|
253
279
|
this.id = page.id;
|
|
254
280
|
this.pageInfo = page;
|
|
255
281
|
}
|