@dosgato/templating 0.0.86 → 0.0.88

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.
@@ -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 = any> extends ResourceProvider {
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;
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, 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;
@@ -492,7 +502,7 @@ export interface RenderedComponent<C extends Component = Component> {
492
502
  component: C;
493
503
  output: string;
494
504
  }
495
- export declare abstract class Page<DataType extends PageData = any, FetchedType = any, RenderContextType extends ContextBase = any> extends Component<DataType, FetchedType, RenderContextType> {
505
+ export declare abstract class Page<DataType extends PageData = any, FetchedType = any, RenderContextType extends ContextBase = ContextBase> extends Component<DataType, FetchedType, RenderContextType> {
496
506
  /**
497
507
  * The page id in case you need to pass it to the API, e.g. this.api.getRootPage(this.id)
498
508
  * in a page template or this.api.getRootPage(this.page.id) in a component template.
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 = (ctx.headerLevel ?? 0) + 1;
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 ?? 0) + 1;
15
+ ctx.headerLevel = (ctx.headerLevel ?? 1) + 1;
16
16
  return ctx;
17
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dosgato/templating",
3
- "version": "0.0.86",
3
+ "version": "0.0.88",
4
4
  "description": "A library to support building templates for dosgato CMS.",
5
5
  "type": "module",
6
6
  "exports": {