@dosgato/templating 0.0.60 → 0.0.62

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.
@@ -110,9 +110,26 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
110
110
  * will be skipped.
111
111
  */
112
112
  renderVariation(extension: string): string;
113
+ /**
114
+ * helper function to print an area's component list, but you can also override this if you
115
+ * need to do something advanced like wrap each component in a div
116
+ */
113
117
  renderComponents(components?: RenderedComponent[] | string, opts?: {
114
118
  hideInheritBars?: boolean;
119
+ editBarOpts?: EditBarOpts;
115
120
  }): string;
121
+ /**
122
+ * helper function to print an area and set a minimum or maximum number of components
123
+ */
124
+ renderArea(areaName: string, opts?: {
125
+ min?: number;
126
+ max?: number;
127
+ hideMaxWarning?: boolean;
128
+ maxWarning?: string;
129
+ hideInheritBars?: boolean;
130
+ newBarOpts: NewBarOpts;
131
+ editBarOpts: EditBarOpts;
132
+ }): void;
116
133
  /**
117
134
  * During rendering, each component should determine the CSS blocks that it needs. This may
118
135
  * change depending on the data. For instance, if you need some CSS to style up an image, but
@@ -165,13 +182,13 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
165
182
  *
166
183
  * Generally should not be overridden - override newLabel and newClass instead
167
184
  */
168
- newBar(areaName: string, opts?: EditBarOpts): string;
185
+ newBar(areaName: string, opts?: NewBarOpts): string;
169
186
  /**
170
187
  * These functions will be provided by the rendering server to assist in the
171
188
  * rendering process.
172
189
  */
173
190
  static editBar: (path: string, opts: EditBarOpts) => string;
174
- static newBar: (path: string, opts: EditBarOpts) => string;
191
+ static newBar: (path: string, opts: NewBarOpts) => string;
175
192
  constructor(data: DataType, path: string, parent: Component | undefined, editMode: boolean);
176
193
  areas: Map<string, Component<any, any, any>[]>;
177
194
  data: Omit<DataType, 'areas'>;
@@ -205,10 +222,15 @@ export interface SiteInfo {
205
222
  export interface PageRecord<DataType extends PageData = PageData> {
206
223
  id: string;
207
224
  linkId: string;
225
+ createdAt: Date;
226
+ modifiedAt: Date;
208
227
  path: string;
209
228
  data: DataType;
210
229
  site: SiteInfo;
211
230
  }
231
+ export interface PageRecordOptionalData<DataType extends PageData = PageData> extends Omit<PageRecord<DataType>, 'data'> {
232
+ data?: DataType;
233
+ }
212
234
  export interface ComponentData {
213
235
  templateKey: string;
214
236
  areas?: Record<string, ComponentData[]>;
@@ -232,11 +254,19 @@ export interface ContextBase {
232
254
  */
233
255
  headerLevel: number;
234
256
  }
235
- export interface EditBarOpts {
236
- extraClass?: string;
237
- label?: string;
257
+ interface BarOpts {
238
258
  editMode?: boolean;
259
+ }
260
+ export interface EditBarOpts extends BarOpts {
261
+ label?: string | ((c: Component) => string);
262
+ extraClass?: string | ((c: Component) => string);
239
263
  inheritedFrom?: string;
264
+ disableDelete?: boolean;
265
+ }
266
+ export interface NewBarOpts extends BarOpts {
267
+ label?: string;
268
+ extraClass?: string;
269
+ disabled?: boolean;
240
270
  }
241
271
  export interface RenderedComponent<C extends Component = Component> {
242
272
  component: C;
@@ -275,3 +305,4 @@ export declare abstract class Page<DataType extends PageData = any, FetchedType
275
305
  protected passError(e: Error, path: string): void;
276
306
  constructor(page: PageRecord<DataType>, editMode: boolean);
277
307
  }
308
+ export {};
package/dist/component.js CHANGED
@@ -82,12 +82,29 @@ export class Component extends ResourceProvider {
82
82
  renderVariation(extension) {
83
83
  return Array.from(this.renderedAreas.values()).flatMap(ras => ras.map(ra => ra.output)).join('');
84
84
  }
85
- // helper function to help you print an area, but you can also override this if you
86
- // need to do something advanced like wrap each component in a div
85
+ /**
86
+ * helper function to print an area's component list, but you can also override this if you
87
+ * need to do something advanced like wrap each component in a div
88
+ */
87
89
  renderComponents(components = [], opts) {
88
90
  if (!Array.isArray(components))
89
91
  components = this.renderedAreas.get(components) ?? [];
90
- return components.flatMap(c => c.component.inheritedFrom && opts?.hideInheritBars ? [c.output] : [c.component.editBar(), c.output]).join('');
92
+ return components.flatMap(c => c.component.inheritedFrom && opts?.hideInheritBars ? [c.output] : [c.component.editBar(opts?.editBarOpts), c.output]).join('');
93
+ }
94
+ /**
95
+ * helper function to print an area and set a minimum or maximum number of components
96
+ */
97
+ renderArea(areaName, opts) {
98
+ const components = this.renderedAreas.get(areaName) ?? [];
99
+ const ownedComponentCount = components.filter(c => !c.component.inheritedFrom).length;
100
+ let output = this.renderComponents(components, { hideInheritBars: opts?.hideInheritBars, editBarOpts: { ...opts?.editBarOpts, disableDelete: ownedComponentCount <= (opts?.min ?? 0) } });
101
+ if (opts?.max && ownedComponentCount >= opts.max) {
102
+ if (!opts.hideMaxWarning)
103
+ output += this.newBar(areaName, { ...opts.newBarOpts, label: opts.maxWarning ?? 'Maximum Reached', disabled: true });
104
+ }
105
+ else {
106
+ output += this.newBar(areaName, opts?.newBarOpts);
107
+ }
91
108
  }
92
109
  /**
93
110
  * During rendering, each component should determine the CSS blocks that it needs. This may
@@ -155,7 +172,6 @@ export class Component extends ResourceProvider {
155
172
  opts.label ?? (opts.label = this.newLabel(areaName) ?? (this.areas.size > 1 ? `Add ${areaName} Content` : `Add ${this.autoLabel} Content`));
156
173
  opts.extraClass ?? (opts.extraClass = this.newClass(areaName));
157
174
  opts.editMode ?? (opts.editMode = this.editMode);
158
- opts.inheritedFrom ?? (opts.inheritedFrom = this.inheritedFrom);
159
175
  return Component.newBar([this.path, 'areas', areaName].filter(isNotBlank).join('.'), opts);
160
176
  }
161
177
  /**
package/dist/render.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ContextBase, DataData, PageData, PageRecord } from './component.js';
1
+ import { ContextBase, DataData, PageData, PageRecord, PageRecordOptionalData } from './component.js';
2
2
  import { AssetLink, DataFolderLink, DataLink, LinkDefinition, PageLink } from './links.js';
3
3
  export declare function printHeader(ctx: ContextBase, content: string): string;
4
4
  export declare function advanceHeader(ctx: ContextBase, content?: string): {
@@ -57,7 +57,7 @@ export interface APIClient {
57
57
  * absolute: true to generate a full URL suitable for a backend http request or non-HTML document
58
58
  * like an RSS feed.
59
59
  */
60
- getHref: (page: PageRecord, opts?: {
60
+ getHref: (page: PageRecordOptionalData, opts?: {
61
61
  absolute?: boolean;
62
62
  extension?: string;
63
63
  }) => string;
@@ -1,11 +1,16 @@
1
- import { IconifyIcon } from '@iconify/svelte';
2
- import { SvelteComponent } from 'svelte';
1
+ import type { IconifyIcon } from '@iconify/svelte';
2
+ export interface SvelteComponent {
3
+ $set: (props?: Record<string, any>) => void;
4
+ $on: (event: string, callback: (event: any) => void) => () => void;
5
+ $destroy: () => void;
6
+ [accessor: string]: any;
7
+ }
3
8
  export interface IconOrSVG extends IconifyIcon {
4
9
  raw?: true;
5
10
  }
6
11
  export interface UITemplate {
7
12
  templateKey: string;
8
- dialog: typeof SvelteComponent;
13
+ dialog: SvelteComponent;
9
14
  preview?: IconOrSVG;
10
15
  icon?: IconOrSVG;
11
16
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dosgato/templating",
3
- "version": "0.0.60",
3
+ "version": "0.0.62",
4
4
  "description": "A library to support building templates for dosgato CMS.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -10,16 +10,16 @@
10
10
  "types": "dist/index.d.ts",
11
11
  "scripts": {
12
12
  "prepublishOnly": "npm run build",
13
+ "lint": "eslint --ignore-path .gitignore .",
13
14
  "build": "rm -rf dist && tsc"
14
15
  },
15
16
  "dependencies": {
16
- "@iconify/svelte": "^2.2.1",
17
- "svelte": "^3.48.0",
17
+ "@iconify/svelte": "^3.0.0",
18
18
  "txstate-utils": "^1.7.4"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/node": "^18.7.11",
22
- "eslint-config-standard-with-typescript": "^22.0.0",
22
+ "eslint-config-standard-with-typescript": "^23.0.0",
23
23
  "typescript": "^4.4.2"
24
24
  },
25
25
  "repository": {