@dosgato/templating 0.0.86 → 0.0.87
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 +13 -3
- package/dist/render.js +2 -2
- package/package.json +1 -1
package/dist/component.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { APIClient } from './render.js';
|
|
|
11
11
|
* During rendering, it will be "hydrated" - placed into a full page structure with its
|
|
12
12
|
* parent and child components linked.
|
|
13
13
|
*/
|
|
14
|
-
export declare abstract class Component<DataType extends ComponentData = any, FetchedType = any, RenderContextType extends ContextBase =
|
|
14
|
+
export declare abstract class Component<DataType extends ComponentData = any, FetchedType = any, RenderContextType extends ContextBase = ContextBase> extends ResourceProvider {
|
|
15
15
|
/**
|
|
16
16
|
* Provide this when you create a template to identify what you are defining.
|
|
17
17
|
*/
|
|
@@ -156,10 +156,19 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
|
|
|
156
156
|
* if the user skipped a header level (a WCAG violation) that situation will be repaired as well
|
|
157
157
|
* as possible.
|
|
158
158
|
*
|
|
159
|
-
* If you do not provide a headerLevel, the one from `this.renderCtx` will be used.
|
|
159
|
+
* If you do not provide a headerLevel, the one from `this.renderCtx` will be used. However, if you
|
|
160
|
+
* provide a non-blank value for `advanceHeader`, the headerLevel from `this.renderCtx` + 1 will be used.
|
|
161
|
+
*
|
|
162
|
+
* This way you can easily render a piece of rich text in a component that has an optional title:
|
|
163
|
+
*
|
|
164
|
+
* this.renderRichText(this.data.richtext, { advanceHeader: this.data.title })
|
|
165
|
+
*
|
|
166
|
+
* If this.data.title is non-blank, the rich text will be balanced below it, but if it is blank,
|
|
167
|
+
* it will be balanced at the level the title would have had.
|
|
160
168
|
*/
|
|
161
169
|
renderRichText: (html: string, opts?: {
|
|
162
170
|
headerLevel?: number;
|
|
171
|
+
advanceHeader?: string | undefined | null;
|
|
163
172
|
}) => string;
|
|
164
173
|
/**
|
|
165
174
|
* The final phase of rendering a component is the render phase. This step is BOTTOM-UP -
|
|
@@ -264,7 +273,7 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
|
|
|
264
273
|
static editBar: (path: string, opts: EditBarOpts) => string;
|
|
265
274
|
static newBar: (path: string, opts: NewBarOpts) => string;
|
|
266
275
|
constructor(data: DataType, path: string, parent: Component | undefined, editMode: boolean);
|
|
267
|
-
areas: Map<string, Component<any, any,
|
|
276
|
+
areas: Map<string, Component<any, any, ContextBase>[]>;
|
|
268
277
|
data: Omit<DataType, 'areas'>;
|
|
269
278
|
fetched: FetchedType;
|
|
270
279
|
renderCtx: RenderContextType;
|
|
@@ -331,6 +340,7 @@ export interface ContextBase {
|
|
|
331
340
|
* This way every page will have a perfect header tree and avoid complaints from WAVE.
|
|
332
341
|
*/
|
|
333
342
|
headerLevel: number;
|
|
343
|
+
[keys: string]: any;
|
|
334
344
|
}
|
|
335
345
|
interface BarOpts {
|
|
336
346
|
editMode?: boolean;
|
package/dist/render.js
CHANGED
|
@@ -2,7 +2,7 @@ import { htmlEncode, isBlank, isNotEmpty } from 'txstate-utils';
|
|
|
2
2
|
export function printHeader(ctx, content, attributes) {
|
|
3
3
|
if (isBlank(content))
|
|
4
4
|
return '';
|
|
5
|
-
const level =
|
|
5
|
+
const level = ctx.headerLevel ?? 1;
|
|
6
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>`;
|
|
@@ -12,6 +12,6 @@ export function printHeader(ctx, content, attributes) {
|
|
|
12
12
|
}
|
|
13
13
|
export function advanceHeader(ctx, content) {
|
|
14
14
|
if (!isBlank(content))
|
|
15
|
-
ctx.headerLevel = (ctx.headerLevel ??
|
|
15
|
+
ctx.headerLevel = (ctx.headerLevel ?? 1) + 1;
|
|
16
16
|
return ctx;
|
|
17
17
|
}
|