@dosgato/templating 0.0.84 → 0.0.86
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 +30 -5
- package/dist/component.js +5 -5
- package/dist/render.d.ts +2 -11
- package/dist/render.js +8 -8
- package/dist/uitemplate.d.ts +8 -3
- package/package.json +1 -1
package/dist/component.d.ts
CHANGED
|
@@ -121,21 +121,46 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
|
|
|
121
121
|
filter?: (c: T) => boolean;
|
|
122
122
|
}): void;
|
|
123
123
|
/**
|
|
124
|
-
* The second phase of rendering a component is the context phase. This step is TOP-DOWN
|
|
125
|
-
*
|
|
126
|
-
*
|
|
124
|
+
* The second phase of rendering a component is the context phase. This step is TOP-DOWN.
|
|
125
|
+
* Each component will receive context from the parent component and then pass a new context
|
|
126
|
+
* object to its own children.
|
|
127
127
|
*
|
|
128
128
|
* This is useful for rendering logic that is sensitive to where the component exists in
|
|
129
129
|
* the hierarchy of the page. For instance, if a parent component has used an h2 header
|
|
130
130
|
* already, it will want to inform its children so that they can use h3 next, and they inform
|
|
131
131
|
* their children that h4 is next, and so on. (Header level tracking is supported by default in
|
|
132
|
-
* dosgato CMS
|
|
132
|
+
* dosgato CMS - see printHeader() and advanceHeader())
|
|
133
133
|
*
|
|
134
134
|
* This function may return a promise in case you need to do something asynchronous based on
|
|
135
135
|
* the context received from the parent, but use it sparingly since it will stall the process.
|
|
136
136
|
* Try to do all asynchronous work in the fetch phase.
|
|
137
137
|
*/
|
|
138
|
-
setContext(renderCtxFromParent: RenderContextType): RenderContextType | Promise<RenderContextType>;
|
|
138
|
+
setContext(renderCtxFromParent: RenderContextType, areaName: string): RenderContextType | Promise<RenderContextType>;
|
|
139
|
+
/**
|
|
140
|
+
* This function will be provided by the rendering server and should be used inside your fetch
|
|
141
|
+
* method to prepare editor-provided HTML for later rendering. It will do things like find and
|
|
142
|
+
* resolve link definitions in the internal dosgato format.
|
|
143
|
+
*/
|
|
144
|
+
fetchRichText: (text: string) => Promise<void>;
|
|
145
|
+
/**
|
|
146
|
+
* This function will be provided by the rendering server and should be used during the render
|
|
147
|
+
* phase to clean up editor-provided HTML. It will do things like clean up tags that were accidentally
|
|
148
|
+
* left open to protect overall page integrity, and fix header levels for accessibility.
|
|
149
|
+
*
|
|
150
|
+
* For instance, an editor supplies a title to be placed above some rich editor content. The
|
|
151
|
+
* title uses an <h2>, so the headers inside the rich editor content should start at <h3> and
|
|
152
|
+
* should not use <h1> or <h2>.
|
|
153
|
+
*
|
|
154
|
+
* Setting headerLevel: 3 instructs the renderRichText function to analyze and rebalance the header
|
|
155
|
+
* structure of the content so that if it had an h2, it woud be replaced with an h3. Additionally,
|
|
156
|
+
* if the user skipped a header level (a WCAG violation) that situation will be repaired as well
|
|
157
|
+
* as possible.
|
|
158
|
+
*
|
|
159
|
+
* If you do not provide a headerLevel, the one from `this.renderCtx` will be used.
|
|
160
|
+
*/
|
|
161
|
+
renderRichText: (html: string, opts?: {
|
|
162
|
+
headerLevel?: number;
|
|
163
|
+
}) => string;
|
|
139
164
|
/**
|
|
140
165
|
* The final phase of rendering a component is the render phase. This step is BOTTOM-UP -
|
|
141
166
|
* components at the bottom of the hierarchy will be rendered first, and the result of the
|
package/dist/component.js
CHANGED
|
@@ -73,21 +73,21 @@ export class Component extends ResourceProvider {
|
|
|
73
73
|
this.registerInherited(areaName, components, page.id, opts?.mode);
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
76
|
-
* The second phase of rendering a component is the context phase. This step is TOP-DOWN
|
|
77
|
-
*
|
|
78
|
-
*
|
|
76
|
+
* The second phase of rendering a component is the context phase. This step is TOP-DOWN.
|
|
77
|
+
* Each component will receive context from the parent component and then pass a new context
|
|
78
|
+
* object to its own children.
|
|
79
79
|
*
|
|
80
80
|
* This is useful for rendering logic that is sensitive to where the component exists in
|
|
81
81
|
* the hierarchy of the page. For instance, if a parent component has used an h2 header
|
|
82
82
|
* already, it will want to inform its children so that they can use h3 next, and they inform
|
|
83
83
|
* their children that h4 is next, and so on. (Header level tracking is supported by default in
|
|
84
|
-
* dosgato CMS
|
|
84
|
+
* dosgato CMS - see printHeader() and advanceHeader())
|
|
85
85
|
*
|
|
86
86
|
* This function may return a promise in case you need to do something asynchronous based on
|
|
87
87
|
* the context received from the parent, but use it sparingly since it will stall the process.
|
|
88
88
|
* Try to do all asynchronous work in the fetch phase.
|
|
89
89
|
*/
|
|
90
|
-
setContext(renderCtxFromParent) {
|
|
90
|
+
setContext(renderCtxFromParent, areaName) {
|
|
91
91
|
return renderCtxFromParent;
|
|
92
92
|
}
|
|
93
93
|
/**
|
package/dist/render.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { ContextBase, DataData, PageData, PageRecord, PageRecordOptionalData } from './component.js';
|
|
2
2
|
import { AssetLink, DataFolderLink, DataLink, LinkDefinition, PageLink } from './links.js';
|
|
3
|
-
export declare function printHeader(ctx: ContextBase, content: string): string;
|
|
4
|
-
export declare function advanceHeader(ctx:
|
|
5
|
-
headerLevel: number;
|
|
6
|
-
};
|
|
3
|
+
export declare function printHeader(ctx: ContextBase, content: string | undefined | null, attributes?: Record<string, string>): string;
|
|
4
|
+
export declare function advanceHeader<T extends ContextBase>(ctx: T, content: string | undefined | null): T;
|
|
7
5
|
export interface PictureResize {
|
|
8
6
|
/** the width of this particular resize */
|
|
9
7
|
width: number;
|
|
@@ -88,13 +86,6 @@ export interface APIClient {
|
|
|
88
86
|
absolute?: boolean;
|
|
89
87
|
extension?: string;
|
|
90
88
|
}) => string;
|
|
91
|
-
/**
|
|
92
|
-
* This function will be provided by the rendering server and should be used inside your fetch
|
|
93
|
-
* method to prepare editor-provided HTML for rendering. It will do things like find and resolve
|
|
94
|
-
* link definitions in the internal dosgato format and clean up tags that were accidentally left
|
|
95
|
-
* open to protect overall page integrity.
|
|
96
|
-
*/
|
|
97
|
-
processRich: (text: string) => Promise<string>;
|
|
98
89
|
/**
|
|
99
90
|
* This function will retrieve information about an image to help you construct responsive HTML
|
|
100
91
|
* for a <picture> element including the <img> and all <source> tags.
|
package/dist/render.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { isBlank } from 'txstate-utils';
|
|
2
|
-
export function printHeader(ctx, content) {
|
|
1
|
+
import { htmlEncode, isBlank, isNotEmpty } from 'txstate-utils';
|
|
2
|
+
export function printHeader(ctx, content, attributes) {
|
|
3
3
|
if (isBlank(content))
|
|
4
4
|
return '';
|
|
5
5
|
const level = (ctx.headerLevel ?? 0) + 1;
|
|
6
|
+
const attr = isNotEmpty(attributes) ? ' ' + Object.entries(attributes).map(([key, val]) => `${key}="${htmlEncode(val)}"`).join(' ') : '';
|
|
6
7
|
if (level < 1)
|
|
7
|
-
return `<h1>${content}</h1>`;
|
|
8
|
+
return `<h1${attr}>${content}</h1>`;
|
|
8
9
|
if (level > 6)
|
|
9
|
-
return `<h6>${content}</h6>`;
|
|
10
|
-
return `<h${level}>${content}</h${level}>`;
|
|
10
|
+
return `<h6${attr}>${content}</h6>`;
|
|
11
|
+
return `<h${level}${attr}>${content}</h${level}>`;
|
|
11
12
|
}
|
|
12
13
|
export function advanceHeader(ctx, content) {
|
|
13
|
-
const ret = { ...ctx };
|
|
14
14
|
if (!isBlank(content))
|
|
15
|
-
|
|
16
|
-
return
|
|
15
|
+
ctx.headerLevel = (ctx.headerLevel ?? 0) + 1;
|
|
16
|
+
return ctx;
|
|
17
17
|
}
|
package/dist/uitemplate.d.ts
CHANGED
|
@@ -27,10 +27,15 @@ export interface UITemplate {
|
|
|
27
27
|
* - data: ComponentData, the current data on the page, should not be mutated during editing,
|
|
28
28
|
* undefined when creating
|
|
29
29
|
* - page: DialogPageProp, the current page so that you can reference the full page data or
|
|
30
|
-
* make a further graphql query based on its id/path.
|
|
30
|
+
* make a further graphql query based on its id/path. Component dialogs only, page and data
|
|
31
|
+
* dialogs do not receive this prop
|
|
31
32
|
* - templateProperties: the template properties for the current page template, so you can make
|
|
32
|
-
* things like color pickers that visually match the colors of the current page template
|
|
33
|
+
* things like color pickers that visually match the colors of the current page template.
|
|
34
|
+
* Data dialogs do not receive this.
|
|
33
35
|
* - environmentConfig: base URLs in case you need to generate a link to the API or something
|
|
36
|
+
*
|
|
37
|
+
* In addition to the props, you may import the `dialogQuery` function (see below) to send
|
|
38
|
+
* requests to the API.
|
|
34
39
|
*/
|
|
35
40
|
dialog?: new (...args: any[]) => any;
|
|
36
41
|
/**
|
|
@@ -64,7 +69,7 @@ export interface UITemplate {
|
|
|
64
69
|
}
|
|
65
70
|
/**
|
|
66
71
|
* This is a type for the data that will be passed to dialog Svelte components as
|
|
67
|
-
* the `page` prop.
|
|
72
|
+
* the `page` prop. Note that page template dialogs do NOT receive this prop.
|
|
68
73
|
*/
|
|
69
74
|
export interface DialogPageProp {
|
|
70
75
|
id: string;
|