@dosgato/templating 0.0.38 → 0.0.39

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.
@@ -19,6 +19,12 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
19
19
  parent?: Component;
20
20
  page?: Page;
21
21
  hadError: boolean;
22
+ /**
23
+ * This property will be set during page render and you may refer to it at any time to
24
+ * determine whether you are doing your work in edit mode or regular rendering mode.
25
+ * The editBar and newBar methods will automatically use it to blank out the editing UI.
26
+ */
27
+ editMode: boolean;
22
28
  /**
23
29
  * The rendering server will provide an instance of the APIClient interface so that
24
30
  * you can run any API GraphQL query you like in your `fetch` function. There are also
@@ -63,7 +69,7 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
63
69
  * you may add them to your this.areas map, e.g.
64
70
  * `this.areas.get('myarea').push(new Component(inheritedData, this.path + '/myarea/inherit1', this))`
65
71
  */
66
- fetch(editMode: boolean): Promise<FetchedType>;
72
+ fetch(): Promise<FetchedType>;
67
73
  /**
68
74
  * The second phase of rendering a component is the context phase. This step is TOP-DOWN and
69
75
  * NON-MUTATING. Each component will receive the parent component's context and then pass a
@@ -79,14 +85,14 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
79
85
  * the context received from the parent, but use it sparingly since it will stall the process.
80
86
  * Try to do all asynchronous work in the fetch phase.
81
87
  */
82
- setContext(renderCtxFromParent: RenderContextType, editMode: boolean): RenderContextType | Promise<RenderContextType>;
88
+ setContext(renderCtxFromParent: RenderContextType): RenderContextType | Promise<RenderContextType>;
83
89
  /**
84
90
  * The final phase of rendering a component is the render phase. This step is BOTTOM-UP -
85
91
  * components at the bottom of the hierarchy will be rendered first, and the result of the
86
92
  * render will be passed to parent components so that the HTML can be included during the
87
93
  * render of the parent component.
88
94
  */
89
- abstract render(renderedAreas: Map<string, string[]>, editMode: boolean): string;
95
+ abstract render(renderedAreas: Map<string, string[]>): string;
90
96
  /**
91
97
  * Sometimes pages are requested with an alternate extension like .rss or .ics. In these
92
98
  * situations, each component should consider whether it should output anything. For
@@ -100,7 +106,7 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
100
106
  * will be skipped.
101
107
  */
102
108
  renderVariation(extension: string, renderedAreas: Map<string, string>): string;
103
- constructor(data: DataType, path: string, parent: Component | undefined);
109
+ constructor(data: DataType, path: string, parent: Component | undefined, editMode: boolean);
104
110
  /**
105
111
  * For logging errors during rendering without crashing the render. If your fetch, setContext,
106
112
  * render, or renderVariation functions throw, the error will be logged but the page render will
@@ -198,5 +204,5 @@ export declare abstract class Page<DataType extends PageData = any, FetchedType
198
204
  */
199
205
  headContent: string;
200
206
  protected passError(e: Error, path: string): void;
201
- constructor(page: PageRecord<DataType>);
207
+ constructor(page: PageRecord<DataType>, editMode: boolean);
202
208
  }
package/dist/component.js CHANGED
@@ -11,11 +11,12 @@ import { ResourceProvider } from './provider.js';
11
11
  export class Component extends ResourceProvider {
12
12
  // the constructor is part of the recursive hydration mechanism: constructing
13
13
  // a Component will also construct/hydrate all its child components
14
- constructor(data, path, parent) {
14
+ constructor(data, path, parent, editMode) {
15
15
  super();
16
16
  // properties for use during hydration, you do not have to provide these when
17
17
  // building a template, but you can use them in the functions you do provide
18
18
  this.areas = new Map();
19
+ this.editMode = editMode;
19
20
  this.parent = parent;
20
21
  const { areas, ...ownData } = data;
21
22
  this.data = ownData;
@@ -42,7 +43,7 @@ export class Component extends ResourceProvider {
42
43
  * you may add them to your this.areas map, e.g.
43
44
  * `this.areas.get('myarea').push(new Component(inheritedData, this.path + '/myarea/inherit1', this))`
44
45
  */
45
- async fetch(editMode) {
46
+ async fetch() {
46
47
  return undefined;
47
48
  }
48
49
  /**
@@ -60,7 +61,7 @@ export class Component extends ResourceProvider {
60
61
  * the context received from the parent, but use it sparingly since it will stall the process.
61
62
  * Try to do all asynchronous work in the fetch phase.
62
63
  */
63
- setContext(renderCtxFromParent, editMode) {
64
+ setContext(renderCtxFromParent) {
64
65
  return renderCtxFromParent;
65
66
  }
66
67
  /**
@@ -151,6 +152,7 @@ export class Component extends ResourceProvider {
151
152
  editBar(opts = {}) {
152
153
  opts.label ?? (opts.label = this.editLabel());
153
154
  opts.extraClass ?? (opts.extraClass = this.editClass());
155
+ opts.editMode = this.editMode;
154
156
  return editBar(this.path, opts);
155
157
  }
156
158
  /**
@@ -161,12 +163,13 @@ export class Component extends ResourceProvider {
161
163
  newBar(areaName, opts = {}) {
162
164
  opts.label ?? (opts.label = this.newLabel(areaName));
163
165
  opts.extraClass ?? (opts.extraClass = this.newClass(areaName));
166
+ opts.editMode = this.editMode;
164
167
  return newBar([this.path, 'areas', areaName].filter(isNotBlank).join('.'), opts);
165
168
  }
166
169
  }
167
170
  export class Page extends Component {
168
- constructor(page) {
169
- super(page.data, '', undefined);
171
+ constructor(page, editMode) {
172
+ super(page.data, '', undefined, editMode);
170
173
  this.pagePath = page.path;
171
174
  }
172
175
  passError(e, path) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dosgato/templating",
3
- "version": "0.0.38",
3
+ "version": "0.0.39",
4
4
  "description": "A library to support building templates for dosgato CMS.",
5
5
  "type": "module",
6
6
  "exports": {