@dosgato/templating 0.0.73 → 0.0.75

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.
@@ -30,8 +30,8 @@ export interface PageExtras {
30
30
  pageId?: string;
31
31
  /** The path in the pagetree to the page, or what the path will be. NOTE: looking the page up by path will not work during page creation. */
32
32
  pagePath?: string;
33
- /** The linkId the page has or will have. NOTE: looking the page up by linkId will not work during page creation. */
34
- linkId: string;
33
+ /** The linkId the page has. Null during page creation. */
34
+ linkId?: string;
35
35
  /** The name the page has or will have. NOTE: looking the page up by name will not work during page creation. */
36
36
  name: string;
37
37
  }
@@ -288,6 +288,40 @@ export interface RenderAreaEditBarOpts extends Omit<Omit<EditBarOpts, 'label'>,
288
288
  export interface NewBarOpts extends BarOpts {
289
289
  disabled?: boolean;
290
290
  }
291
+ export interface RenderComponentsWrapParams {
292
+ /**
293
+ * Contains both the regular component content and the edit bar (or the new bar).
294
+ *
295
+ * Use this if you want to wrap content and edit bar together.
296
+ */
297
+ output: string;
298
+ /**
299
+ * Contains only the regular component content and not the edit bar.
300
+ *
301
+ * If you use this, make sure to also use the bar parameter or else
302
+ * you'll never print the edit bar and your components will be uneditable.
303
+ */
304
+ content: string;
305
+ /**
306
+ * Contains the edit bar or new bar, depending on the situation.
307
+ *
308
+ * Use this if you want to wrap the bar separately from the component content.
309
+ *
310
+ * Will be blank in edit mode or when skipBars was set to true on the renderArea
311
+ * and/or renderComponents call. You probably want to check if it's blank before
312
+ * wrapping or you'll end up with an empty wrapper element.
313
+ */
314
+ bar: string;
315
+ /**
316
+ * Contains the full component being wrapped.
317
+ *
318
+ * Use this if you need to check the component's data to alter your
319
+ * wrapping behavior.
320
+ *
321
+ * Will be undefined for the new bar, so check that it is not null.
322
+ */
323
+ component?: Component;
324
+ }
291
325
  export interface RenderComponentsOpts {
292
326
  /**
293
327
  * Hide bars entiredly for inherited items instead of allowing the user
@@ -301,20 +335,37 @@ export interface RenderComponentsOpts {
301
335
  * re-order them easily.
302
336
  */
303
337
  skipBars?: boolean;
338
+ /**
339
+ * Only skip edit bars, but print the new bar normally.
340
+ *
341
+ * If skipBars is also true, the new bar will not print normally, obviously.
342
+ */
343
+ skipEditBars?: boolean;
344
+ /**
345
+ * Only skip the new bar, but print the edit bars normally.
346
+ *
347
+ * If skipBars is also true, the edit bars will not print normally, obviously.
348
+ */
349
+ skipNewBar?: boolean;
304
350
  /**
305
351
  * Do not print the content, only print edit and new bars. This is the other half
306
352
  * of skipBars. You'd print bars in one place and content in another.
353
+ *
354
+ * If you only want to print the new bar, you need to set BOTH skipContent
355
+ * and skipEditBars.
307
356
  */
308
357
  skipContent?: boolean;
309
358
  /**
310
359
  * Provide a function that wraps each component, e.g.
311
- * (output: string) => `<li>${output}</li>`
360
+ * ({ output }) => `<li>${output}</li>`
312
361
  *
313
- * Note that the wrap will also go around the edit bar.
362
+ * Wrap receives a lot of optional paramaters so that you can customize the behavior. For
363
+ * instance, you may want to wrap the content but not the edit bar, or vice versa. See
364
+ * the comments on each parameter for more info.
314
365
  *
315
366
  * If you need it (unlikely), the full component object is provided as a second parameter.
316
367
  */
317
- wrap?: (output: string, c?: Component) => string;
368
+ wrap?: (info: RenderComponentsWrapParams) => string;
318
369
  /**
319
370
  * Options for each edit bar; also accepts functions for label and extraClass
320
371
  */
package/dist/component.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { isNotBlank } from 'txstate-utils';
2
2
  import { ResourceProvider } from './provider.js';
3
- function defaultWrap(output) { return output; }
3
+ function defaultWrap(info) { return info.output; }
4
4
  /**
5
5
  * This is the primary templating class to build your templates. Subclass it and provide
6
6
  * at least a render function.
@@ -97,16 +97,22 @@ export class Component extends ResourceProvider {
97
97
  if (!Array.isArray(components))
98
98
  components = this.renderedAreas.get(components) ?? [];
99
99
  const wrap = opts?.wrap ?? defaultWrap;
100
- if (opts?.skipBars)
101
- return components.map(c => wrap(c.output, c.component)).join('');
100
+ if (opts?.skipBars || opts?.skipEditBars)
101
+ return components.map(c => wrap({ ...c, content: c.output, bar: '' })).join('');
102
102
  return components
103
- .map(c => c.component.inheritedFrom && opts?.hideInheritBars
104
- ? (opts.skipContent ? '' : wrap(c.output, c.component))
105
- : wrap([c.component.editBar({
103
+ .map(c => {
104
+ if (c.component.inheritedFrom && opts?.hideInheritBars) {
105
+ return opts.skipContent ? '' : wrap({ ...c, content: c.output, bar: '' });
106
+ }
107
+ else {
108
+ const bar = c.component.editBar({
106
109
  ...opts?.editBarOpts,
107
110
  label: typeof opts?.editBarOpts?.label === 'function' ? opts.editBarOpts.label(c.component) : opts?.editBarOpts?.label,
108
111
  extraClass: typeof opts?.editBarOpts?.extraClass === 'function' ? opts.editBarOpts.extraClass(c.component) : opts?.editBarOpts?.extraClass
109
- }), opts?.skipContent ? '' : c.output].join(''), c.component)).join('');
112
+ });
113
+ return wrap({ output: bar + c.output, content: c.output, bar, component: c.component });
114
+ }
115
+ }).join('');
110
116
  }
111
117
  /**
112
118
  * helper function to print an area and set a minimum or maximum number of components
@@ -125,14 +131,18 @@ export class Component extends ResourceProvider {
125
131
  const full = !!(opts?.max && ownedComponentCount >= opts.max);
126
132
  const wrap = opts?.wrap ?? defaultWrap;
127
133
  let output = this.renderComponents(components, { ...opts, editBarOpts: { ...opts?.editBarOpts, disableDelete: ownedComponentCount <= (opts?.min ?? 0), disableDrop: full } });
128
- if (!opts?.skipBars) {
134
+ if (!opts?.skipBars && !opts?.skipNewBar) {
135
+ let bar;
129
136
  if (full) {
130
- if (!opts.hideMaxWarning)
131
- output += wrap(this.newBar(areaName, { ...opts.newBarOpts, label: opts.maxWarning ?? 'Maximum Reached', disabled: true }));
137
+ if (!opts.hideMaxWarning) {
138
+ bar = this.newBar(areaName, { ...opts.newBarOpts, label: opts.maxWarning ?? 'Maximum Reached', disabled: true });
139
+ }
132
140
  }
133
141
  else {
134
- output += wrap(this.newBar(areaName, opts?.newBarOpts));
142
+ bar = this.newBar(areaName, opts?.newBarOpts);
135
143
  }
144
+ if (bar != null)
145
+ output += wrap({ output: bar, content: '', bar });
136
146
  }
137
147
  return output;
138
148
  }
package/dist/render.d.ts CHANGED
@@ -34,6 +34,24 @@ export interface PictureAttributes {
34
34
  }[];
35
35
  }
36
36
  export interface APIClient {
37
+ /**
38
+ * Identify whether we are generating the page for live, preview, or editing
39
+ *
40
+ * Useful for things like google analytics where you only want to add it to live pages
41
+ * or else you'd be getting stats from editors and previewers.
42
+ */
43
+ context: 'live' | 'preview' | 'edit';
44
+ /**
45
+ * Identify whether we are generating the published version of a page or not.
46
+ *
47
+ * The methods provided below all take this into account. For instance, if you are
48
+ * generating the published view of a page and ask for its root page, you get
49
+ * the published version of the root page, not the latest unpublished version.
50
+ *
51
+ * If you make your own queries asking for other pages' data, you should make use
52
+ * of this variable to ensure you get the correct version of the data.
53
+ */
54
+ published: boolean;
37
55
  /**
38
56
  * Run any query against the API.
39
57
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dosgato/templating",
3
- "version": "0.0.73",
3
+ "version": "0.0.75",
4
4
  "description": "A library to support building templates for dosgato CMS.",
5
5
  "type": "module",
6
6
  "exports": {