@dosgato/templating 0.0.107 → 0.0.108

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.
@@ -1,6 +1,6 @@
1
1
  import { ComponentData, DataData, PageData } from './component.js';
2
2
  import { LinkDefinition } from './links.js';
3
- export declare type APITemplateType = 'page' | 'component' | 'data';
3
+ export type APITemplateType = 'page' | 'component' | 'data';
4
4
  export declare enum ValidationMessageType {
5
5
  ERROR = "error",
6
6
  WARNING = "warning",
@@ -147,7 +147,7 @@ export interface APIDataTemplate<DataType extends DataData = any> extends APITem
147
147
  validate?: (data: DataType, extras: DataExtras) => Promise<ValidationFeedback[]>;
148
148
  migrations?: DataMigration<DataType>[];
149
149
  }
150
- export declare type APIAnyTemplate = APIComponentTemplate | APIPageTemplate | APIDataTemplate;
150
+ export type APIAnyTemplate = APIComponentTemplate | APIPageTemplate | APIDataTemplate;
151
151
  /**
152
152
  * In dosgato CMS, the data in the database is not altered except during user activity. This
153
153
  * means that older records could have been saved when the schema expected by component
@@ -181,13 +181,13 @@ export interface Migration<DataType, ExtraType> {
181
181
  up: (data: DataType, extras: ExtraType) => DataType | Promise<DataType>;
182
182
  down: (data: DataType, extras: ExtraType) => DataType | Promise<DataType>;
183
183
  }
184
- export declare type ComponentMigration<DataType extends ComponentData = ComponentData> = Migration<DataType, ComponentExtras>;
185
- export declare type PageMigration<DataType extends PageData = PageData> = Migration<DataType, PageExtras>;
186
- export declare type DataMigration<DataType extends DataData = DataData> = Migration<DataType, DataExtras>;
187
- export declare type AnyMigration = ComponentMigration | PageMigration | DataMigration;
188
- export declare type LinkGatheringFn<DataType> = (data: DataType) => (LinkDefinition | string | undefined)[];
189
- export declare type FulltextGatheringFn<DataType> = (data: DataType) => (string | undefined)[];
190
- export declare type GraphQLQueryFn = <T>(query: string, variables?: any) => Promise<T>;
184
+ export type ComponentMigration<DataType extends ComponentData = ComponentData> = Migration<DataType, ComponentExtras>;
185
+ export type PageMigration<DataType extends PageData = PageData> = Migration<DataType, PageExtras>;
186
+ export type DataMigration<DataType extends DataData = DataData> = Migration<DataType, DataExtras>;
187
+ export type AnyMigration = ComponentMigration | PageMigration | DataMigration;
188
+ export type LinkGatheringFn<DataType> = (data: DataType) => (LinkDefinition | string | undefined)[];
189
+ export type FulltextGatheringFn<DataType> = (data: DataType) => (string | undefined)[];
190
+ export type GraphQLQueryFn = <T>(query: string, variables?: any) => Promise<T>;
191
191
  /**
192
192
  * This function is used by API template definitions to help them identify all the searchable
193
193
  * words in a large block of text and return them for indexing.
package/dist/component.js CHANGED
@@ -9,33 +9,6 @@ function defaultWrap(info) { return info.output; }
9
9
  * parent and child components linked.
10
10
  */
11
11
  export class Component extends ResourceProvider {
12
- // the constructor is part of the recursive hydration mechanism: constructing
13
- // a Component will also construct/hydrate all its child components
14
- constructor(data, path, parent, editMode, extension) {
15
- super();
16
- /**
17
- * Override with `true` to indicate that this template never accepts data from editors
18
- *
19
- * Its edit bar will not have a pencil icon.
20
- */
21
- this.noData = false;
22
- // Properties provided during the rendering process. You do not have to provide these when
23
- // building a template, but you can use them in the functions you do provide
24
- this.areas = new Map(); // a Map of area names and the array of hydrated components in each
25
- this.editMode = editMode;
26
- this.extension = extension;
27
- this.parent = parent;
28
- const { areas, ...ownData } = data;
29
- this.data = ownData;
30
- this.path = path;
31
- this.hadError = false;
32
- let tmpParent = this.parent ?? this;
33
- while (!(tmpParent instanceof Page) && tmpParent.parent)
34
- tmpParent = tmpParent.parent;
35
- if (!(tmpParent instanceof Page))
36
- throw new Error('Hydration failed, could not map component back to its page.');
37
- this.page = tmpParent;
38
- }
39
12
  /**
40
13
  * The first phase of rendering a component is the fetch phase. Each component may
41
14
  * provide a fetch method that looks up data it needs from external sources. This step
@@ -259,6 +232,33 @@ export class Component extends ResourceProvider {
259
232
  options.editMode ?? (options.editMode = this.editMode);
260
233
  return Component.newBar([this.path, 'areas', areaName].filter(isNotBlank).join('.'), options);
261
234
  }
235
+ // the constructor is part of the recursive hydration mechanism: constructing
236
+ // a Component will also construct/hydrate all its child components
237
+ constructor(data, path, parent, editMode, extension) {
238
+ super();
239
+ /**
240
+ * Override with `true` to indicate that this template never accepts data from editors
241
+ *
242
+ * Its edit bar will not have a pencil icon.
243
+ */
244
+ this.noData = false;
245
+ // Properties provided during the rendering process. You do not have to provide these when
246
+ // building a template, but you can use them in the functions you do provide
247
+ this.areas = new Map(); // a Map of area names and the array of hydrated components in each
248
+ this.editMode = editMode;
249
+ this.extension = extension;
250
+ this.parent = parent;
251
+ const { areas, ...ownData } = data;
252
+ this.data = ownData;
253
+ this.path = path;
254
+ this.hadError = false;
255
+ let tmpParent = this.parent ?? this;
256
+ while (!(tmpParent instanceof Page) && tmpParent.parent)
257
+ tmpParent = tmpParent.parent;
258
+ if (!(tmpParent instanceof Page))
259
+ throw new Error('Hydration failed, could not map component back to its page.');
260
+ this.page = tmpParent;
261
+ }
262
262
  /**
263
263
  * For logging errors during rendering without crashing the render. If your fetch, setContext,
264
264
  * render, or renderVariation functions throw, the error will be logged but the page render will
@@ -274,11 +274,6 @@ export class Component extends ResourceProvider {
274
274
  }
275
275
  }
276
276
  export class Page extends Component {
277
- constructor(page, editMode, extension) {
278
- super(page.data, '', undefined, editMode, extension);
279
- this.id = page.id;
280
- this.pageInfo = page;
281
- }
282
277
  /**
283
278
  * A convenience to get the page title.
284
279
  *
@@ -296,4 +291,9 @@ export class Page extends Component {
296
291
  passError(e, path) {
297
292
  console.warn(`Recoverable issue occured during render of ${this.pageInfo.path}. Component at ${path} threw the following error:`, e);
298
293
  }
294
+ constructor(page, editMode, extension) {
295
+ super(page.data, '', undefined, editMode, extension);
296
+ this.id = page.id;
297
+ this.pageInfo = page;
298
+ }
299
299
  }
package/dist/links.d.ts CHANGED
@@ -75,7 +75,7 @@ export interface DataFolderLink {
75
75
  siteId?: string;
76
76
  path: string;
77
77
  }
78
- export declare type LinkDefinition = AssetLink | AssetFolderLink | PageLink | WebLink | DataLink | DataFolderLink;
78
+ export type LinkDefinition = AssetLink | AssetFolderLink | PageLink | WebLink | DataLink | DataFolderLink;
79
79
  /**
80
80
  * This function is used by template definitions to help them identify links inside large blocks
81
81
  * of text and return them for indexing, and by render definitions to help replace them with the actual URLs
package/dist/render.d.ts CHANGED
@@ -37,6 +37,7 @@ export interface PageForNavigation {
37
37
  title: string;
38
38
  path: string;
39
39
  href: string;
40
+ publishedAt?: Date;
40
41
  extra: Record<string, any>;
41
42
  children: this[];
42
43
  }
@@ -147,6 +148,16 @@ export interface APIClient {
147
148
  * you the root page and one level of subpages, etc.
148
149
  */
149
150
  depth?: number;
151
+ /**
152
+ * Only return pages that are published. Setting this to true will ensure that the
153
+ * page will appear the same in editing and preview views as it does in published
154
+ * and live views.
155
+ *
156
+ * By default it is false, which means that in editing/preview context it shows
157
+ * all pages, published and unpublished, but in published/live context it only shows
158
+ * other published pages.
159
+ */
160
+ published?: boolean;
150
161
  /**
151
162
  * Get extra data from the page data
152
163
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dosgato/templating",
3
- "version": "0.0.107",
3
+ "version": "0.0.108",
4
4
  "description": "A library to support building templates for dosgato CMS.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "devDependencies": {
20
20
  "@types/node": "^18.7.11",
21
- "eslint-config-standard-with-typescript": "^23.0.0",
21
+ "eslint-config-standard-with-typescript": "^26.0.0",
22
22
  "typescript": "^4.4.2"
23
23
  },
24
24
  "repository": {