@dosgato/templating 0.0.80 → 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.
- package/dist/component.d.ts +16 -0
- package/dist/component.js +17 -1
- package/package.json +1 -1
package/dist/component.d.ts
CHANGED
|
@@ -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
|