@dosgato/templating 0.0.79 → 0.0.81

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.
@@ -81,7 +81,7 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
81
81
  /**
82
82
  * An array of components to add to the area.
83
83
  */
84
- components: ComponentData[],
84
+ components: ComponentData[] | undefined,
85
85
  /**
86
86
  * The page id of the page these components came from.
87
87
  *
@@ -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
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, 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
package/dist/render.d.ts CHANGED
@@ -131,7 +131,7 @@ export interface APIClient {
131
131
  *
132
132
  * Returns the root page(s). Subpages are inside the `children` property.
133
133
  */
134
- getNavigation: ({ beneath, depth, extra, absolute }: {
134
+ getNavigation: (opts?: {
135
135
  /**
136
136
  * Return pages beneath this path
137
137
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dosgato/templating",
3
- "version": "0.0.79",
3
+ "version": "0.0.81",
4
4
  "description": "A library to support building templates for dosgato CMS.",
5
5
  "type": "module",
6
6
  "exports": {