@dosgato/templating 0.0.62 → 0.0.63

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.
@@ -116,7 +116,7 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
116
116
  */
117
117
  renderComponents(components?: RenderedComponent[] | string, opts?: {
118
118
  hideInheritBars?: boolean;
119
- editBarOpts?: EditBarOpts;
119
+ editBarOpts?: RenderAreaEditBarOpts;
120
120
  }): string;
121
121
  /**
122
122
  * helper function to print an area and set a minimum or maximum number of components
@@ -128,8 +128,8 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
128
128
  maxWarning?: string;
129
129
  hideInheritBars?: boolean;
130
130
  newBarOpts: NewBarOpts;
131
- editBarOpts: EditBarOpts;
132
- }): void;
131
+ editBarOpts: RenderAreaEditBarOpts;
132
+ }): string;
133
133
  /**
134
134
  * During rendering, each component should determine the CSS blocks that it needs. This may
135
135
  * change depending on the data. For instance, if you need some CSS to style up an image, but
@@ -256,16 +256,18 @@ export interface ContextBase {
256
256
  }
257
257
  interface BarOpts {
258
258
  editMode?: boolean;
259
+ label?: string;
260
+ extraClass?: string;
259
261
  }
260
262
  export interface EditBarOpts extends BarOpts {
261
- label?: string | ((c: Component) => string);
262
- extraClass?: string | ((c: Component) => string);
263
263
  inheritedFrom?: string;
264
264
  disableDelete?: boolean;
265
265
  }
266
+ export interface RenderAreaEditBarOpts extends Omit<Omit<EditBarOpts, 'label'>, 'extraClass'> {
267
+ label?: string | ((c: Component) => string);
268
+ extraClass?: string | ((c: Component) => string);
269
+ }
266
270
  export interface NewBarOpts extends BarOpts {
267
- label?: string;
268
- extraClass?: string;
269
271
  disabled?: boolean;
270
272
  }
271
273
  export interface RenderedComponent<C extends Component = Component> {
package/dist/component.js CHANGED
@@ -89,7 +89,15 @@ export class Component extends ResourceProvider {
89
89
  renderComponents(components = [], opts) {
90
90
  if (!Array.isArray(components))
91
91
  components = this.renderedAreas.get(components) ?? [];
92
- return components.flatMap(c => c.component.inheritedFrom && opts?.hideInheritBars ? [c.output] : [c.component.editBar(opts?.editBarOpts), c.output]).join('');
92
+ return components
93
+ .flatMap(c => c.component.inheritedFrom &&
94
+ opts?.hideInheritBars
95
+ ? [c.output]
96
+ : [c.component.editBar({
97
+ ...opts?.editBarOpts,
98
+ label: typeof opts?.editBarOpts?.label === 'function' ? opts.editBarOpts.label(c.component) : opts?.editBarOpts?.label,
99
+ extraClass: typeof opts?.editBarOpts?.extraClass === 'function' ? opts.editBarOpts.extraClass(c.component) : opts?.editBarOpts?.extraClass
100
+ }), c.output]).join('');
93
101
  }
94
102
  /**
95
103
  * helper function to print an area and set a minimum or maximum number of components
@@ -105,6 +113,7 @@ export class Component extends ResourceProvider {
105
113
  else {
106
114
  output += this.newBar(areaName, opts?.newBarOpts);
107
115
  }
116
+ return output;
108
117
  }
109
118
  /**
110
119
  * During rendering, each component should determine the CSS blocks that it needs. This may
@@ -157,11 +166,12 @@ export class Component extends ResourceProvider {
157
166
  * Generally should not be overridden - override editLabel and editClass instead
158
167
  */
159
168
  editBar(opts = {}) {
160
- opts.label ?? (opts.label = this.editLabel() ?? this.autoLabel);
161
- opts.extraClass ?? (opts.extraClass = this.editClass());
162
- opts.editMode ?? (opts.editMode = this.editMode);
163
- opts.inheritedFrom ?? (opts.inheritedFrom = this.inheritedFrom);
164
- return Component.editBar(this.path, opts);
169
+ const options = { ...opts };
170
+ options.label ?? (options.label = this.editLabel() ?? this.autoLabel);
171
+ options.extraClass ?? (options.extraClass = this.editClass());
172
+ options.editMode ?? (options.editMode = this.editMode);
173
+ options.inheritedFrom ?? (options.inheritedFrom = this.inheritedFrom);
174
+ return Component.editBar(this.path, options);
165
175
  }
166
176
  /**
167
177
  * Components may override this function to provide a custom new bar
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dosgato/templating",
3
- "version": "0.0.62",
3
+ "version": "0.0.63",
4
4
  "description": "A library to support building templates for dosgato CMS.",
5
5
  "type": "module",
6
6
  "exports": {