@dosgato/templating 0.0.80 → 0.0.82

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.
@@ -104,6 +104,22 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
104
104
  * Default is 'top'.
105
105
  */
106
106
  mode?: 'top' | 'bottom' | 'replace') => void;
107
+ /**
108
+ * Inherit components from another page with matching area
109
+ *
110
+ * This is a convenience function for when you are inheriting components from
111
+ * the exact same area on another page. It will not cover all inheritance use
112
+ * cases, but it covers enough that having this as a shorthand is helpful.
113
+ *
114
+ * Call it in your fetch() method just like you would with registerInherited.
115
+ *
116
+ * Note that you can still provide `mode` and you can provide a `filter` function
117
+ * to reduce the number of components that get inherited.
118
+ */
119
+ inheritArea<T extends ComponentData>(page: PageRecord, areaName: string, opts?: {
120
+ mode?: 'top' | 'bottom' | 'replace';
121
+ filter?: (c: T) => boolean;
122
+ }): void;
107
123
  /**
108
124
  * The second phase of rendering a component is the context phase. This step is TOP-DOWN and
109
125
  * NON-MUTATING. Each component will receive the parent component's context and then pass a
@@ -268,6 +284,7 @@ export interface PageRecordOptionalData<DataType extends PageData = PageData> ex
268
284
  export interface ComponentData {
269
285
  templateKey: string;
270
286
  areas?: Record<string, ComponentData[]>;
287
+ [keys: string]: any;
271
288
  }
272
289
  export interface PageData extends ComponentData {
273
290
  savedAtVersion: string;
@@ -275,6 +292,7 @@ export interface PageData extends ComponentData {
275
292
  export interface DataData {
276
293
  templateKey: string;
277
294
  savedAtVersion: string;
295
+ [keys: string]: any;
278
296
  }
279
297
  export interface ContextBase {
280
298
  /**
package/dist/component.js CHANGED
@@ -1,4 +1,4 @@
1
- import { isNotBlank } from 'txstate-utils';
1
+ import { get, isNotBlank } from 'txstate-utils';
2
2
  import { ResourceProvider } from './provider.js';
3
3
  function defaultWrap(info) { return info.output; }
4
4
  /**
@@ -56,6 +56,22 @@ export class Component extends ResourceProvider {
56
56
  async fetch() {
57
57
  return undefined;
58
58
  }
59
+ /**
60
+ * Inherit components from another page with matching area
61
+ *
62
+ * This is a convenience function for when you are inheriting components from
63
+ * the exact same area on another page. It will not cover all inheritance use
64
+ * cases, but it covers enough that having this as a shorthand is helpful.
65
+ *
66
+ * Call it in your fetch() method just like you would with registerInherited.
67
+ *
68
+ * Note that you can still provide `mode` and you can provide a `filter` function
69
+ * to reduce the number of components that get inherited.
70
+ */
71
+ inheritArea(page, areaName, opts) {
72
+ const components = get(page.data, `areas.${areaName}`).filter(opts?.filter ?? (() => true));
73
+ this.registerInherited(areaName, components, page.id, opts?.mode);
74
+ }
59
75
  /**
60
76
  * The second phase of rendering a component is the context phase. This step is TOP-DOWN and
61
77
  * NON-MUTATING. Each component will receive the parent component's context and then pass a
@@ -37,6 +37,13 @@ export interface UITemplate {
37
37
  *
38
38
  * You can place that introductory content here and it will be automatically placed into
39
39
  * components with this template upon creation (and never again).
40
+ *
41
+ * Whatever you put here will be added beneath the component's `areas` property, so it would
42
+ * be structured like:
43
+ * {
44
+ * someArea: [componentData1, componentData2],
45
+ * anotherArea: [componentData3]
46
+ * }
40
47
  */
41
48
  defaultContent?: Record<string, ComponentData[]>;
42
49
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dosgato/templating",
3
- "version": "0.0.80",
3
+ "version": "0.0.82",
4
4
  "description": "A library to support building templates for dosgato CMS.",
5
5
  "type": "module",
6
6
  "exports": {