@dosgato/templating 0.0.85 → 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 +1 -10
- package/dist/render.js +4 -5
- 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
3
|
export declare function printHeader(ctx: ContextBase, content: string | undefined | null, attributes?: Record<string, string>): string;
|
|
4
|
-
export declare function advanceHeader(ctx:
|
|
5
|
-
headerLevel: number;
|
|
6
|
-
};
|
|
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,9 +1,9 @@
|
|
|
1
|
-
import { htmlEncode, isBlank } from 'txstate-utils';
|
|
1
|
+
import { htmlEncode, isBlank, isNotEmpty } from 'txstate-utils';
|
|
2
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 = attributes ? ' ' + Object.entries(attributes).map(([key, val]) => `${key}="${htmlEncode(val)}"`).join(' ') : '';
|
|
6
|
+
const attr = isNotEmpty(attributes) ? ' ' + Object.entries(attributes).map(([key, val]) => `${key}="${htmlEncode(val)}"`).join(' ') : '';
|
|
7
7
|
if (level < 1)
|
|
8
8
|
return `<h1${attr}>${content}</h1>`;
|
|
9
9
|
if (level > 6)
|
|
@@ -11,8 +11,7 @@ export function printHeader(ctx, content, attributes) {
|
|
|
11
11
|
return `<h${level}${attr}>${content}</h${level}>`;
|
|
12
12
|
}
|
|
13
13
|
export function advanceHeader(ctx, content) {
|
|
14
|
-
const ret = { ...ctx };
|
|
15
14
|
if (!isBlank(content))
|
|
16
|
-
|
|
17
|
-
return
|
|
15
|
+
ctx.headerLevel = (ctx.headerLevel ?? 0) + 1;
|
|
16
|
+
return ctx;
|
|
18
17
|
}
|