@dosgato/templating 0.0.135 → 0.0.137

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.
@@ -179,8 +179,18 @@ export interface APIDataTemplate<DataType extends DataData = any> extends APITem
179
179
  * Data template implementations receive the id of the dataroot the data is/will be inside,
180
180
  * as well as the folder id (if applicable) and their own id. Keep in mind dataId will be
181
181
  * null when it is a creation operation.
182
+ *
183
+ * nameIsTaken will be true when the automatically generated name for the data entry already
184
+ * exists elsewhere in the folder. This fact can be ignored and the generated name will be automatically
185
+ * numerated to be unique. If you would rather present the editor with a validation error and let them resolve
186
+ * the conflict, this parameter gives you an opportunity to do that.
187
+ *
188
+ * Note that numeration can lead to the name changing during unrelated edits, possibly breaking
189
+ * links. For example, on creation the name is set with a "-1" suffix because of a conflict, then
190
+ * the conflicting entry is deleted. Editing this data entry again will remove the "-1" because
191
+ * of the lack of conflict.
182
192
  */
183
- validate?: (data: DataType, extras: DataExtras) => Promise<ValidationFeedback[]>;
193
+ validate?: (data: DataType, extras: DataExtras, nameIsTaken: boolean) => Promise<ValidationFeedback[]>;
184
194
  migrations?: DataMigration<DataType>[];
185
195
  /**
186
196
  * Mark this data type as inappropriate for sites. For example, if you have system-wide configuration
@@ -188,6 +198,27 @@ export interface APIDataTemplate<DataType extends DataData = any> extends APITem
188
198
  * true to avoid showing the site list and stop allowing data of this type to be attached to sites.
189
199
  */
190
200
  global?: boolean;
201
+ /**
202
+ * Mark this data type as inappropriate for global. For example, if you have a data type for site
203
+ * configurations, a global entry might make no sense. Setting this will avoid showing editors
204
+ * the global space in the dataroot list.
205
+ */
206
+ noglobal?: boolean;
207
+ /**
208
+ * Data objects must have names so that they can be linked to at a specific path. However,
209
+ * for an editor, setting an addressable name for a data entry that already has, say, a
210
+ * title, is both tedious and confusing.
211
+ *
212
+ * Instead, it is the data template developer's responsibility to create the name from
213
+ * the data gathered from the editor. If there is a title, that's a great option. Otherwise,
214
+ * the dialog may need to have an explicit `name` field. Either way it's up to the developer
215
+ * of each data template to decide and provide.
216
+ *
217
+ * Whatever is returned from this function will be further processed to fit well in a path -
218
+ * i.e. lower-cased and non-word characters replaced by a dash. If there is a duplicate data
219
+ * entry in the same folder, it will be automatically numerated.
220
+ */
221
+ computeName: (data: DataType) => string;
191
222
  }
192
223
  export type APIAnyTemplate = APIComponentTemplate | APIPageTemplate | APIDataTemplate;
193
224
  /**
@@ -360,6 +360,24 @@ export interface PageRecord<DataType extends PageData = PageData> {
360
360
  export interface PageRecordOptionalData<DataType extends PageData = PageData> extends Omit<PageRecord<DataType>, 'data'> {
361
361
  data?: DataType;
362
362
  }
363
+ export interface DataRecord<DataType extends DataData = DataData> {
364
+ id: string;
365
+ name: string;
366
+ createdAt: Date;
367
+ createdBy: {
368
+ id: string;
369
+ name: string;
370
+ };
371
+ modifiedAt: Date;
372
+ modifiedBy: {
373
+ id: string;
374
+ name: string;
375
+ };
376
+ publishedAt?: Date;
377
+ path: string;
378
+ data: DataType;
379
+ site?: SiteInfo;
380
+ }
363
381
  export interface ComponentData {
364
382
  templateKey: string;
365
383
  areas?: Record<string, ComponentData[]>;
package/dist/render.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ContextBase, DataData, PageData, PageRecord, PageRecordOptionalData } from './component.js';
1
+ import type { ContextBase, DataRecord, PageData, PageRecord, PageRecordOptionalData } from './component.js';
2
2
  import type { AssetFolderLink, AssetLink, DataFolderLink, DataLink, LinkDefinition, PageLink } from './links.js';
3
3
  /**
4
4
  * Safely encapsulates `content` in header tags based on the `ctx` context passed and adds any passed `attributes` to the header tagging.
@@ -52,14 +52,6 @@ export interface AssetRecord {
52
52
  downloadLink: string;
53
53
  image?: PictureAttributes;
54
54
  }
55
- export interface DataRecord {
56
- id: string;
57
- path: string;
58
- name: string;
59
- modifiedAt: Date;
60
- publishedAt?: Date;
61
- data: DataData;
62
- }
63
55
  export interface PageForNavigation {
64
56
  id: string;
65
57
  name: string;
@@ -1,4 +1,4 @@
1
- import type { ComponentData, PageData } from './component.js';
1
+ import type { ComponentData, DataData, PageData, DataRecord } from './component.js';
2
2
  interface IconifyIcon {
3
3
  body: string;
4
4
  rotate?: number;
@@ -12,7 +12,7 @@ interface IconifyIcon {
12
12
  export interface IconOrSVG extends IconifyIcon {
13
13
  raw?: true;
14
14
  }
15
- export interface UITemplate {
15
+ export interface UITemplateBase {
16
16
  templateKey: string;
17
17
  /**
18
18
  * A svelte component that expects to be inside a @dosgato/dialog Form component
@@ -52,6 +52,21 @@ export interface UITemplate {
52
52
  * For example, `randomId: 'id'` means your component data will look like `{ id: 'cym87regpk' }`
53
53
  */
54
54
  randomId?: string;
55
+ /**
56
+ * if present this SVG will be used when presenting users with
57
+ * an array of choices of templates to create. Ideally it should look
58
+ * a lot like the template will look on a webpage. It will be presented
59
+ * about 1-2 inches wide
60
+ */
61
+ preview?: IconOrSVG;
62
+ /**
63
+ * if present this icon will be used to represent the template in various
64
+ * UI contexts. It will be presented about 3mm wide. Falls back to the
65
+ * preview image.
66
+ */
67
+ icon?: IconOrSVG;
68
+ }
69
+ export interface UITemplate extends UITemplateBase {
55
70
  /**
56
71
  * Sometimes when you create a component that has areas, you want to automatically fill
57
72
  * one or more areas with some default introductory content.
@@ -67,19 +82,6 @@ export interface UITemplate {
67
82
  * }
68
83
  */
69
84
  defaultContent?: Record<string, ComponentData[]> | ((data: ComponentData) => Record<string, ComponentData[]>);
70
- /**
71
- * if present this SVG will be used when presenting users with
72
- * an array of choices of templates to create. Ideally it should look
73
- * a lot like the template will look on a webpage. It will be presented
74
- * about 1-2 inches wide
75
- */
76
- preview?: IconOrSVG;
77
- /**
78
- * if present this icon will be used to represent the template in various
79
- * UI contexts. It will be presented about 3mm wide. Falls back to the
80
- * preview image.
81
- */
82
- icon?: IconOrSVG;
83
85
  /**
84
86
  * Add buttons to the page bar in the page editing UI when editing pages with this
85
87
  * template. Only applies to page templates.
@@ -107,6 +109,30 @@ export interface UITemplate {
107
109
  shouldAppear?: (data: PageData, path: string) => boolean;
108
110
  }[];
109
111
  }
112
+ export interface UITemplateData extends UITemplateBase {
113
+ /**
114
+ * Without configuration, only data entry names and modified dates are shown
115
+ * in the list view. Use this to configure your own set of columns.
116
+ */
117
+ columns?: {
118
+ /**
119
+ * A title for the column in header row.
120
+ */
121
+ title: string;
122
+ /**
123
+ * If given a string, will be treated as a dot-separated path within DataData and
124
+ * the content at that path will be html-encoded and placed inside the field.
125
+ *
126
+ * If given a function, the result of the function will be placed inside the field
127
+ * without html-encoding, so that you can write your own HTML. Do the encoding yourself.
128
+ */
129
+ get: string | ((data: DataRecord) => string);
130
+ /**
131
+ * An icon for the cell in all regular rows (not the header).
132
+ */
133
+ icon?: (data: DataData) => IconOrSVG;
134
+ }[];
135
+ }
110
136
  /**
111
137
  * This is a type for the data that will be passed to dialog Svelte components as
112
138
  * the `page` prop. Note that page template dialogs do NOT receive this prop.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dosgato/templating",
3
- "version": "0.0.135",
3
+ "version": "0.0.137",
4
4
  "description": "A library to support building templates for dosgato CMS.",
5
5
  "type": "module",
6
6
  "exports": {