@dosgato/templating 0.0.22 → 0.0.25
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 +26 -10
- package/dist/apitemplate.js +6 -0
- package/dist/component.d.ts +39 -19
- package/dist/component.js +7 -5
- package/dist/render.d.ts +79 -1
- package/package.json +1 -1
package/dist/apitemplate.d.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PageRecord, ComponentData, PageData } from './component.js';
|
|
2
2
|
import { LinkDefinition } from './links.js';
|
|
3
3
|
export declare type APITemplateType = 'page' | 'component' | 'data';
|
|
4
|
+
declare enum MessageType {
|
|
5
|
+
ERROR = "error",
|
|
6
|
+
WARNING = "warning",
|
|
7
|
+
SUCCESS = "success"
|
|
8
|
+
}
|
|
9
|
+
interface Feedback {
|
|
10
|
+
type: `${MessageType}`;
|
|
11
|
+
path?: string;
|
|
12
|
+
message: string;
|
|
13
|
+
}
|
|
4
14
|
/**
|
|
5
15
|
* This interface lays out the structure the API needs for each template in the system.
|
|
6
16
|
*/
|
|
@@ -41,17 +51,22 @@ export interface APITemplate {
|
|
|
41
51
|
getFulltext: FulltextGatheringFn;
|
|
42
52
|
/**
|
|
43
53
|
* Each template must provide a validation function so that the API can enforce its data is
|
|
44
|
-
* shaped properly.
|
|
45
|
-
*
|
|
46
|
-
*
|
|
54
|
+
* shaped properly.
|
|
55
|
+
*
|
|
56
|
+
* Each entry in the return array can have a type of error, warning, or success. Errors
|
|
57
|
+
* represent a validation failure and mean that saving will not succeed. Warnings are shown
|
|
58
|
+
* to the editor but do not prevent saving. Success messages postively affirm valid input - for
|
|
59
|
+
* instance, a name they chose is available.
|
|
47
60
|
*
|
|
48
|
-
*
|
|
49
|
-
* { name:
|
|
61
|
+
* As an example, if name is required and the user didn't provide one, you would return:
|
|
62
|
+
* [{ type: 'error', path: 'name', message: 'A name is required.' }]
|
|
50
63
|
*
|
|
51
64
|
* This method is async so that you can do things like look in the database for conflicting
|
|
52
|
-
* names.
|
|
65
|
+
* names. The full page data, the path to this component, and a GraphQL query executor are
|
|
66
|
+
* available as parameters in case you need them. Keep in mind that the current editor MUST
|
|
67
|
+
* have access to any data you attempt to query in GraphQL.
|
|
53
68
|
*/
|
|
54
|
-
validate: (data: any) => Promise<
|
|
69
|
+
validate: (data: ComponentData, query: <T>(query: string, variables?: any) => Promise<T>, page: PageData, path: string) => Promise<Feedback[]>;
|
|
55
70
|
/**
|
|
56
71
|
* Hard-coded properties that may be set on page templates to influence the rendering of
|
|
57
72
|
* components on the page. For instance, a set of color choices that are customized for
|
|
@@ -85,8 +100,8 @@ export interface APITemplate {
|
|
|
85
100
|
*/
|
|
86
101
|
export interface Migration {
|
|
87
102
|
createdAt: Date;
|
|
88
|
-
up: (data: ComponentData, page:
|
|
89
|
-
down: (data: ComponentData, page:
|
|
103
|
+
up: (data: ComponentData, page: PageRecord) => ComponentData | Promise<ComponentData>;
|
|
104
|
+
down: (data: ComponentData, page: PageRecord) => ComponentData | Promise<ComponentData>;
|
|
90
105
|
}
|
|
91
106
|
export declare type LinkGatheringFn = (data: any) => LinkDefinition[];
|
|
92
107
|
export declare type FulltextGatheringFn = (data: any) => string[];
|
|
@@ -102,3 +117,4 @@ export declare function extractLinksFromText(text: string): LinkDefinition[];
|
|
|
102
117
|
export declare function getKeywords(text: string, options?: {
|
|
103
118
|
stopwords?: boolean;
|
|
104
119
|
}): string[];
|
|
120
|
+
export {};
|
package/dist/apitemplate.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { stopwords } from './stopwords.js';
|
|
2
|
+
var MessageType;
|
|
3
|
+
(function (MessageType) {
|
|
4
|
+
MessageType["ERROR"] = "error";
|
|
5
|
+
MessageType["WARNING"] = "warning";
|
|
6
|
+
MessageType["SUCCESS"] = "success";
|
|
7
|
+
})(MessageType || (MessageType = {}));
|
|
2
8
|
/**
|
|
3
9
|
* This function is used by API template definitions to help them identify links inside large blocks
|
|
4
10
|
* of text and return them for indexing.
|
package/dist/component.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EditBarOpts } from './editbar.js';
|
|
2
|
-
import { LinkDefinition } from './links.js';
|
|
3
2
|
import { ResourceProvider } from './provider.js';
|
|
3
|
+
import { APIClient } from './render.js';
|
|
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.
|
|
@@ -20,28 +20,48 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
|
|
|
20
20
|
page?: Page;
|
|
21
21
|
hadError: boolean;
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
23
|
+
* The rendering server will provide an instance of the APIClient interface so that
|
|
24
|
+
* you can run any API GraphQL query you like in your `fetch` function. There are also
|
|
25
|
+
* some useful methods there like processRich to help you convert links in rich text
|
|
26
|
+
* strings.
|
|
27
|
+
*
|
|
28
|
+
* Do NOT mutate data received from the API as it may be cached and given to other
|
|
29
|
+
* Component instances that run the same type of query.
|
|
30
|
+
*/
|
|
31
|
+
api: APIClient;
|
|
32
|
+
/**
|
|
33
|
+
* Retrieve the data for the root page of the page this component is on. Useful for
|
|
34
|
+
* implementing inheritance schemes.
|
|
35
|
+
*
|
|
36
|
+
* This function will be provided by the rendering service.
|
|
37
|
+
*
|
|
38
|
+
* Do NOT mutate the data returned by this function, as it may be cached and given to
|
|
39
|
+
* other Component instances.
|
|
26
40
|
*/
|
|
27
|
-
|
|
41
|
+
getRootPageData: () => Promise<PageData>;
|
|
28
42
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
43
|
+
* Retrieve the data for all ancestor pages of the page this component is on. Useful
|
|
44
|
+
* for implementing inheritance schemes.
|
|
45
|
+
*
|
|
46
|
+
* This function will be provided by the rendering service.
|
|
47
|
+
*
|
|
48
|
+
* Do NOT mutate the data returned by this function, as it may be cached and given to
|
|
49
|
+
* other Component instances.
|
|
33
50
|
*/
|
|
34
|
-
|
|
51
|
+
getAncestorPageData: () => Promise<PageData[]>;
|
|
35
52
|
/**
|
|
36
53
|
* The first phase of rendering a component is the fetch phase. Each component may
|
|
37
54
|
* provide a fetch method that looks up data it needs from external sources. This step
|
|
38
55
|
* is FLAT - it will be executed concurrently for all the components on the page for
|
|
39
56
|
* maximum speed.
|
|
40
57
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
58
|
+
* Place any needed data into the return object, and it will be available to you as `this.fetched`
|
|
59
|
+
* during the rendering phase.
|
|
60
|
+
*
|
|
61
|
+
* Note that this.page will be available, and getRootPageData and getAncestorPageData are
|
|
62
|
+
* available in case there is a need for inheritance. If you need to inherit entire components,
|
|
63
|
+
* you may add them to your this.areas map, e.g.
|
|
64
|
+
* `this.areas.get('myarea').push(new Component(inheritedData, this.path + '/myarea/inherit1', this))`
|
|
45
65
|
*/
|
|
46
66
|
fetch(editMode: boolean): Promise<FetchedType>;
|
|
47
67
|
/**
|
|
@@ -146,9 +166,6 @@ export interface PageRecord<DataType extends PageData = PageData> {
|
|
|
146
166
|
path: string;
|
|
147
167
|
data: DataType;
|
|
148
168
|
}
|
|
149
|
-
export interface PageWithAncestors<DataType extends PageData = PageData> extends PageRecord<DataType> {
|
|
150
|
-
ancestors: PageRecord<PageData>[];
|
|
151
|
-
}
|
|
152
169
|
export interface ComponentData {
|
|
153
170
|
templateKey: string;
|
|
154
171
|
areas?: Record<string, ComponentData[]>;
|
|
@@ -156,6 +173,10 @@ export interface ComponentData {
|
|
|
156
173
|
export interface PageData extends ComponentData {
|
|
157
174
|
savedAtVersion: Date;
|
|
158
175
|
}
|
|
176
|
+
export interface DataData {
|
|
177
|
+
templateKey: string;
|
|
178
|
+
savedAtVersion: Date;
|
|
179
|
+
}
|
|
159
180
|
export interface ContextBase {
|
|
160
181
|
/**
|
|
161
182
|
* For accessibility, every component should consider whether it is creating headers
|
|
@@ -170,7 +191,6 @@ export interface ContextBase {
|
|
|
170
191
|
}
|
|
171
192
|
export declare abstract class Page<DataType extends PageData = any, FetchedType = any, RenderContextType extends ContextBase = any> extends Component<DataType, FetchedType, RenderContextType> {
|
|
172
193
|
pagePath: string;
|
|
173
|
-
ancestors: PageRecord[];
|
|
174
194
|
/**
|
|
175
195
|
* we will fill this before rendering, stuff that dosgato knows needs to be added to
|
|
176
196
|
* the <head> element
|
|
@@ -178,5 +198,5 @@ export declare abstract class Page<DataType extends PageData = any, FetchedType
|
|
|
178
198
|
*/
|
|
179
199
|
headContent: string;
|
|
180
200
|
protected passError(e: Error, path: string): void;
|
|
181
|
-
constructor(page:
|
|
201
|
+
constructor(page: PageRecord<DataType>);
|
|
182
202
|
}
|
package/dist/component.js
CHANGED
|
@@ -33,10 +33,13 @@ export class Component extends ResourceProvider {
|
|
|
33
33
|
* is FLAT - it will be executed concurrently for all the components on the page for
|
|
34
34
|
* maximum speed.
|
|
35
35
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
36
|
+
* Place any needed data into the return object, and it will be available to you as `this.fetched`
|
|
37
|
+
* during the rendering phase.
|
|
38
|
+
*
|
|
39
|
+
* Note that this.page will be available, and getRootPageData and getAncestorPageData are
|
|
40
|
+
* available in case there is a need for inheritance. If you need to inherit entire components,
|
|
41
|
+
* you may add them to your this.areas map, e.g.
|
|
42
|
+
* `this.areas.get('myarea').push(new Component(inheritedData, this.path + '/myarea/inherit1', this))`
|
|
40
43
|
*/
|
|
41
44
|
async fetch(editMode) {
|
|
42
45
|
return undefined;
|
|
@@ -164,7 +167,6 @@ export class Page extends Component {
|
|
|
164
167
|
constructor(page) {
|
|
165
168
|
super(page.data, '/', undefined);
|
|
166
169
|
this.pagePath = page.path;
|
|
167
|
-
this.ancestors = page.ancestors;
|
|
168
170
|
}
|
|
169
171
|
passError(e, path) {
|
|
170
172
|
console.warn(`Recoverable issue occured during render of ${this.pagePath}. Component at ${path} threw the following error:`, e);
|
package/dist/render.d.ts
CHANGED
|
@@ -1,5 +1,83 @@
|
|
|
1
|
-
import { ContextBase } from './component.js';
|
|
1
|
+
import { ContextBase, DataData, PageData } from './component.js';
|
|
2
|
+
import { AssetLink, DataFolderLink, DataLink, LinkDefinition } from './links.js';
|
|
2
3
|
export declare function printHeader(ctx: ContextBase, content: string): string;
|
|
3
4
|
export declare function advanceHeader(ctx: ContextBase, content?: string): {
|
|
4
5
|
headerLevel: number;
|
|
5
6
|
};
|
|
7
|
+
export interface PictureResize {
|
|
8
|
+
/** the width of this particular resize */
|
|
9
|
+
width: number;
|
|
10
|
+
/** the URL to this particular resize, relative or absolute depends on options used */
|
|
11
|
+
src: string;
|
|
12
|
+
}
|
|
13
|
+
export interface PictureAttributes {
|
|
14
|
+
/** string appropriate for the src attribute of the default <img> tag */
|
|
15
|
+
src: string;
|
|
16
|
+
/** string appropriate for the srcset attribute of the default <img> tag, or use widths array to reconstruct */
|
|
17
|
+
srcset: string;
|
|
18
|
+
/** a list of available widths in case you want to filter some out and recreate the srcset */
|
|
19
|
+
widths: PictureResize[];
|
|
20
|
+
/** alternative text stored with the image in its asset repository, may be overridden by local alt text */
|
|
21
|
+
alt?: string;
|
|
22
|
+
/** the original intrinsic width of the image uploaded by the editor */
|
|
23
|
+
width: number;
|
|
24
|
+
/** the original intrinsic height of the image uploaded by the editor */
|
|
25
|
+
height: number;
|
|
26
|
+
/** a list of alternate formats like AVIF or WEBP and their resizes, useful for creating <source> tags */
|
|
27
|
+
alternates: {
|
|
28
|
+
/** the mime type of this alternate source, useful for the type attribute on a <source> tag */
|
|
29
|
+
mime: string;
|
|
30
|
+
/** the full srcset for the <source> tag, or use widths array to reconstruct */
|
|
31
|
+
srcset: string;
|
|
32
|
+
/** a list of available widths in case you want to filter some out and recreate the srcset */
|
|
33
|
+
widths: PictureResize[];
|
|
34
|
+
}[];
|
|
35
|
+
}
|
|
36
|
+
export interface APIClient {
|
|
37
|
+
/**
|
|
38
|
+
* Run any query against the API.
|
|
39
|
+
*
|
|
40
|
+
* Will be authenticated as appropriate - anonymous during published renders, as the editor
|
|
41
|
+
* during preview renders.
|
|
42
|
+
*/
|
|
43
|
+
query: <T = any>(query: string, variables?: any) => Promise<T>;
|
|
44
|
+
/**
|
|
45
|
+
* This function will be provided by the rendering server and should be used inside your fetch,
|
|
46
|
+
* method to convert a link, as input by a user, into a URL suitable for an href, or optionally
|
|
47
|
+
* an absolute URL suitable for a backend http request or non-HTML document like an RSS feed.
|
|
48
|
+
*/
|
|
49
|
+
resolveLink: (link: string | LinkDefinition, absolute?: boolean) => Promise<string>;
|
|
50
|
+
/**
|
|
51
|
+
* This function will be provided by the rendering server and should be used inside your fetch
|
|
52
|
+
* method to prepare editor-provided HTML for rendering. It will do things like find and resolve
|
|
53
|
+
* link definitions in the internal dosgato format and clean up tags that were accidentally left
|
|
54
|
+
* open to protect overall page integrity.
|
|
55
|
+
*/
|
|
56
|
+
processRich: (text: string) => Promise<string>;
|
|
57
|
+
/**
|
|
58
|
+
* This function will retrieve information about an image to help you construct responsive HTML
|
|
59
|
+
* for a <picture> element including the <img> and all <source> tags.
|
|
60
|
+
*
|
|
61
|
+
* The alt text it returns will be the default alternative text from the asset repository. Alt
|
|
62
|
+
* text gathered from a template's dialog should generally take precedence (though the dialog may
|
|
63
|
+
* preload the alt text field with the asset repository default).
|
|
64
|
+
*/
|
|
65
|
+
getImgAttributes: (link: string | AssetLink, absolute?: boolean) => Promise<PictureAttributes>;
|
|
66
|
+
/** Get the data for a specific page. Will be dataloaded. */
|
|
67
|
+
getPageData: ({ id, path }: {
|
|
68
|
+
id?: string;
|
|
69
|
+
path?: string;
|
|
70
|
+
}) => Promise<PageData>;
|
|
71
|
+
/**
|
|
72
|
+
* Get data items
|
|
73
|
+
*
|
|
74
|
+
* Returns an array in case link is a DataFolderLink. If link is a DataLink, will return an
|
|
75
|
+
* array with length <= 1.
|
|
76
|
+
*/
|
|
77
|
+
getDataByLink: (link: string | DataLink | DataFolderLink) => Promise<DataData[]>;
|
|
78
|
+
/**
|
|
79
|
+
* Get data by full path including site. Use '/global' for global data. If path refers
|
|
80
|
+
* to a specific data item, will return an array with length <= 1.
|
|
81
|
+
*/
|
|
82
|
+
getDataByPath: (templateKey: string, path: string) => Promise<DataData[]>;
|
|
83
|
+
}
|