@dosgato/templating 0.0.69 → 0.0.70

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,10 +116,20 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
116
116
  */
117
117
  renderComponents(components?: RenderedComponent[] | string, opts?: {
118
118
  hideInheritBars?: boolean;
119
+ skipBars?: boolean;
120
+ skipContent?: boolean;
119
121
  editBarOpts?: RenderAreaEditBarOpts;
120
122
  }): string;
121
123
  /**
122
124
  * helper function to print an area and set a minimum or maximum number of components
125
+ *
126
+ * In some cases you might be rendering the edit bars in a separate div instead of placing
127
+ * them above each component. For instance, a slider that only shows one slide at a time may
128
+ * prefer not to put bars with slides because that would mean only one bar is visible at a time
129
+ * and then there's no way to re-order slides.
130
+ *
131
+ * In that case you would call this.renderArea('areaname', { ..., skipEditBars: true }) first
132
+ * and then this.renderArea('areaname', { ..., skipContent: true }) in another place.
123
133
  */
124
134
  renderArea(areaName: string, opts?: {
125
135
  min?: number;
@@ -127,6 +137,8 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
127
137
  hideMaxWarning?: boolean;
128
138
  maxWarning?: string;
129
139
  hideInheritBars?: boolean;
140
+ skipBars?: boolean;
141
+ skipContent?: boolean;
130
142
  newBarOpts?: NewBarOpts;
131
143
  editBarOpts?: RenderAreaEditBarOpts;
132
144
  }): string;
@@ -230,7 +242,7 @@ export interface PageRecord<DataType extends PageData = PageData> {
230
242
  linkId: string;
231
243
  createdAt: Date;
232
244
  modifiedAt: Date;
233
- publishedAt: Date | null;
245
+ publishedAt?: Date;
234
246
  path: string;
235
247
  data: DataType;
236
248
  site: SiteInfo;
package/dist/component.js CHANGED
@@ -95,30 +95,41 @@ export class Component extends ResourceProvider {
95
95
  renderComponents(components = [], opts) {
96
96
  if (!Array.isArray(components))
97
97
  components = this.renderedAreas.get(components) ?? [];
98
+ if (opts?.skipBars)
99
+ return components.map(c => c.output).join('');
98
100
  return components
99
- .flatMap(c => c.component.inheritedFrom &&
100
- opts?.hideInheritBars
101
- ? [c.output]
101
+ .flatMap(c => c.component.inheritedFrom && opts?.hideInheritBars
102
+ ? [opts.skipContent ? '' : c.output]
102
103
  : [c.component.editBar({
103
104
  ...opts?.editBarOpts,
104
105
  label: typeof opts?.editBarOpts?.label === 'function' ? opts.editBarOpts.label(c.component) : opts?.editBarOpts?.label,
105
106
  extraClass: typeof opts?.editBarOpts?.extraClass === 'function' ? opts.editBarOpts.extraClass(c.component) : opts?.editBarOpts?.extraClass
106
- }), c.output]).join('');
107
+ }), opts?.skipContent ? '' : c.output]).join('');
107
108
  }
108
109
  /**
109
110
  * helper function to print an area and set a minimum or maximum number of components
111
+ *
112
+ * In some cases you might be rendering the edit bars in a separate div instead of placing
113
+ * them above each component. For instance, a slider that only shows one slide at a time may
114
+ * prefer not to put bars with slides because that would mean only one bar is visible at a time
115
+ * and then there's no way to re-order slides.
116
+ *
117
+ * In that case you would call this.renderArea('areaname', { ..., skipEditBars: true }) first
118
+ * and then this.renderArea('areaname', { ..., skipContent: true }) in another place.
110
119
  */
111
120
  renderArea(areaName, opts) {
112
121
  const components = this.renderedAreas.get(areaName) ?? [];
113
122
  const ownedComponentCount = components.filter(c => !c.component.inheritedFrom).length;
114
123
  const full = !!(opts?.max && ownedComponentCount >= opts.max);
115
- let output = this.renderComponents(components, { hideInheritBars: opts?.hideInheritBars, editBarOpts: { ...opts?.editBarOpts, disableDelete: ownedComponentCount <= (opts?.min ?? 0), disableDrop: full } });
116
- if (full) {
117
- if (!opts.hideMaxWarning)
118
- output += this.newBar(areaName, { ...opts.newBarOpts, label: opts.maxWarning ?? 'Maximum Reached', disabled: true });
119
- }
120
- else {
121
- output += this.newBar(areaName, opts?.newBarOpts);
124
+ let output = this.renderComponents(components, { hideInheritBars: opts?.hideInheritBars, skipBars: opts?.skipBars, skipContent: opts?.skipContent, editBarOpts: { ...opts?.editBarOpts, disableDelete: ownedComponentCount <= (opts?.min ?? 0), disableDrop: full } });
125
+ if (!opts?.skipBars) {
126
+ if (full) {
127
+ if (!opts.hideMaxWarning)
128
+ output += this.newBar(areaName, { ...opts.newBarOpts, label: opts.maxWarning ?? 'Maximum Reached', disabled: true });
129
+ }
130
+ else {
131
+ output += this.newBar(areaName, opts?.newBarOpts);
132
+ }
122
133
  }
123
134
  return output;
124
135
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dosgato/templating",
3
- "version": "0.0.69",
3
+ "version": "0.0.70",
4
4
  "description": "A library to support building templates for dosgato CMS.",
5
5
  "type": "module",
6
6
  "exports": {