@dosgato/templating 0.0.42 → 0.0.45

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.
@@ -92,7 +92,7 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
92
92
  * render will be passed to parent components so that the HTML can be included during the
93
93
  * render of the parent component.
94
94
  */
95
- abstract render(renderedAreas: Map<string, RenderedComponent[]>): string;
95
+ abstract render(): string;
96
96
  /**
97
97
  * Sometimes pages are requested with an alternate extension like .rss or .ics. In these
98
98
  * situations, each component should consider whether it should output anything. For
@@ -105,8 +105,8 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
105
105
  * This function will be run after the fetch phase. The context and html rendering phases
106
106
  * will be skipped.
107
107
  */
108
- renderVariation(extension: string, renderedAreas: Map<string, string>): string;
109
- renderComponents(components?: RenderedComponent[], opts?: {
108
+ renderVariation(extension: string): string;
109
+ renderComponents(components?: RenderedComponent[] | string, opts?: {
110
110
  hideInheritBars?: boolean;
111
111
  }): string;
112
112
  /**
@@ -131,12 +131,12 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
131
131
  *
132
132
  * For instance, you could return this.data.title
133
133
  */
134
- editLabel(): undefined;
134
+ editLabel(): string | undefined;
135
135
  /**
136
136
  * Components may override this function to give their edit bars a custom
137
137
  * CSS class
138
138
  */
139
- editClass(): undefined;
139
+ editClass(): string | undefined;
140
140
  /**
141
141
  * Components may override this function to give their new bars a custom
142
142
  * label
@@ -144,12 +144,12 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
144
144
  * For instance, an area that only accepts 'layout' components could
145
145
  * return "Add Layout"
146
146
  */
147
- newLabel(areaName: string): undefined;
147
+ newLabel(areaName: string): string | undefined;
148
148
  /**
149
149
  * Components may override this function to give their new bars a custom
150
150
  * CSS class
151
151
  */
152
- newClass(areaName: string): undefined;
152
+ newClass(areaName: string): string | undefined;
153
153
  /**
154
154
  * Components may override this function to provide a custom edit bar
155
155
  *
@@ -177,9 +177,9 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
177
177
  path: string;
178
178
  parent?: Component;
179
179
  page?: Page;
180
+ renderedAreas: Map<string, RenderedComponent[]>;
180
181
  hadError: boolean;
181
182
  autoLabel: string;
182
- autoNewLabel: string;
183
183
  /**
184
184
  * For logging errors during rendering without crashing the render. If your fetch, setContext,
185
185
  * render, or renderVariation functions throw, the error will be logged but the page render will
@@ -225,7 +225,7 @@ export interface EditBarOpts {
225
225
  }
226
226
  export interface RenderedComponent<C extends Component = Component> {
227
227
  component: C;
228
- html: string;
228
+ output: string;
229
229
  }
230
230
  export declare abstract class Page<DataType extends PageData = any, FetchedType = any, RenderContextType extends ContextBase = any> extends Component<DataType, FetchedType, RenderContextType> {
231
231
  pagePath: string;
package/dist/component.js CHANGED
@@ -79,13 +79,15 @@ export class Component extends ResourceProvider {
79
79
  * This function will be run after the fetch phase. The context and html rendering phases
80
80
  * will be skipped.
81
81
  */
82
- renderVariation(extension, renderedAreas) {
83
- return Array.from(renderedAreas.values()).join('');
82
+ renderVariation(extension) {
83
+ return Array.from(this.renderedAreas.values()).flatMap(ras => ras.map(ra => ra.output)).join('');
84
84
  }
85
85
  // helper function to help you print an area, but you can also override this if you
86
86
  // need to do something advanced like wrap each component in a div
87
87
  renderComponents(components = [], opts) {
88
- return components.flatMap(c => c.component.inheritedFrom && opts?.hideInheritBars ? [c.html] : [c.component.editBar(), c.html]).join('');
88
+ if (!Array.isArray(components))
89
+ components = this.renderedAreas.get(components) ?? [];
90
+ return components.flatMap(c => c.component.inheritedFrom && opts?.hideInheritBars ? [c.output] : [c.component.editBar(), c.output]).join('');
89
91
  }
90
92
  /**
91
93
  * During rendering, each component should determine the CSS blocks that it needs. This may
@@ -150,7 +152,7 @@ export class Component extends ResourceProvider {
150
152
  * Generally should not be overridden - override newLabel and newClass instead
151
153
  */
152
154
  newBar(areaName, opts = {}) {
153
- opts.label ?? (opts.label = this.newLabel(areaName) ?? this.autoNewLabel);
155
+ opts.label ?? (opts.label = this.newLabel(areaName) ?? (this.areas.size > 1 ? `Add ${areaName} Content` : `Add ${this.autoLabel} Content`));
154
156
  opts.extraClass ?? (opts.extraClass = this.newClass(areaName));
155
157
  opts.editMode ?? (opts.editMode = this.editMode);
156
158
  opts.inheritedFrom ?? (opts.inheritedFrom = this.inheritedFrom);
package/dist/render.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ContextBase, DataData, PageData, PageRecord } from './component.js';
2
- import { AssetLink, DataFolderLink, DataLink, LinkDefinition } from './links.js';
2
+ import { AssetLink, DataFolderLink, DataLink, LinkDefinition, PageLink } from './links.js';
3
3
  export declare function printHeader(ctx: ContextBase, content: string): string;
4
4
  export declare function advanceHeader(ctx: ContextBase, content?: string): {
5
5
  headerLevel: number;
@@ -69,20 +69,21 @@ export interface APIClient {
69
69
  *
70
70
  * Will be dataloaded.
71
71
  */
72
- getPageData: ({ id, path }: {
72
+ getPage: ({ id, path, link }: {
73
73
  id?: string;
74
74
  path?: string;
75
- }) => Promise<PageData>;
75
+ link?: string | PageLink;
76
+ }) => Promise<PageRecord<PageData>>;
76
77
  /** Get all ancestor pages of a specific page. First array element will be the pagetree root page. */
77
78
  getAncestors: ({ id, path }: {
78
79
  id?: string;
79
80
  path?: string;
80
- }) => Promise<PageRecord[]>;
81
+ }) => Promise<PageRecord<PageData>[]>;
81
82
  /** Get the pagetree root page from which the specified page descends. */
82
- getRootPageData: ({ id, path }: {
83
+ getRootPage: ({ id, path }: {
83
84
  id?: string;
84
85
  path?: string;
85
- }) => Promise<PageData>;
86
+ }) => Promise<PageRecord<PageData>>;
86
87
  /**
87
88
  * Get data entries by link or folder link
88
89
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dosgato/templating",
3
- "version": "0.0.42",
3
+ "version": "0.0.45",
4
4
  "description": "A library to support building templates for dosgato CMS.",
5
5
  "type": "module",
6
6
  "exports": {