@dosgato/templating 0.0.83 → 0.0.85

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.
package/dist/render.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ContextBase, DataData, PageData, PageRecord, PageRecordOptionalData } from './component.js';
2
2
  import { AssetLink, DataFolderLink, DataLink, LinkDefinition, PageLink } from './links.js';
3
- export declare function printHeader(ctx: ContextBase, content: string): string;
4
- export declare function advanceHeader(ctx: ContextBase, content?: string): {
3
+ export declare function printHeader(ctx: ContextBase, content: string | undefined | null, attributes?: Record<string, string>): string;
4
+ export declare function advanceHeader(ctx: ContextBase, content: string | undefined | null): {
5
5
  headerLevel: number;
6
6
  };
7
7
  export interface PictureResize {
package/dist/render.js CHANGED
@@ -1,13 +1,14 @@
1
- import { isBlank } from 'txstate-utils';
2
- export function printHeader(ctx, content) {
1
+ import { htmlEncode, isBlank } from 'txstate-utils';
2
+ export function printHeader(ctx, content, attributes) {
3
3
  if (isBlank(content))
4
4
  return '';
5
5
  const level = (ctx.headerLevel ?? 0) + 1;
6
+ const attr = attributes ? ' ' + Object.entries(attributes).map(([key, val]) => `${key}="${htmlEncode(val)}"`).join(' ') : '';
6
7
  if (level < 1)
7
- return `<h1>${content}</h1>`;
8
+ return `<h1${attr}>${content}</h1>`;
8
9
  if (level > 6)
9
- return `<h6>${content}</h1>`;
10
- return `<h${level}>${content}</h${level}>`;
10
+ return `<h6${attr}>${content}</h6>`;
11
+ return `<h${level}${attr}>${content}</h${level}>`;
11
12
  }
12
13
  export function advanceHeader(ctx, content) {
13
14
  const ret = { ...ctx };
@@ -1,4 +1,4 @@
1
- import { ComponentData } from './component.js';
1
+ import { ComponentData, PageData } from './component.js';
2
2
  interface IconifyIcon {
3
3
  body: string;
4
4
  rotate?: number;
@@ -26,9 +26,16 @@ export interface UITemplate {
26
26
  * - creating: boolean, true when creating component for the first time, false when editing
27
27
  * - data: ComponentData, the current data on the page, should not be mutated during editing,
28
28
  * undefined when creating
29
+ * - page: DialogPageProp, the current page so that you can reference the full page data or
30
+ * make a further graphql query based on its id/path. Component dialogs only, page and data
31
+ * dialogs do not receive this prop
29
32
  * - templateProperties: the template properties for the current page template, so you can make
30
- * things like color pickers that visually match the colors of the current page template
33
+ * things like color pickers that visually match the colors of the current page template.
34
+ * Data dialogs do not receive this.
31
35
  * - environmentConfig: base URLs in case you need to generate a link to the API or something
36
+ *
37
+ * In addition to the props, you may import the `dialogQuery` function (see below) to send
38
+ * requests to the API.
32
39
  */
33
40
  dialog?: new (...args: any[]) => any;
34
41
  /**
@@ -60,4 +67,18 @@ export interface UITemplate {
60
67
  */
61
68
  icon?: IconOrSVG;
62
69
  }
70
+ /**
71
+ * This is a type for the data that will be passed to dialog Svelte components as
72
+ * the `page` prop. Note that page template dialogs do NOT receive this prop.
73
+ */
74
+ export interface DialogPageProp {
75
+ id: string;
76
+ path: string;
77
+ data: PageData;
78
+ }
79
+ /**
80
+ * A function you may use in your dialogs to make an authenticated graphql request to the DosGato
81
+ * API.
82
+ */
83
+ export declare function dialogQuery<T = any>(query: string, variables: any): Promise<T>;
63
84
  export {};
@@ -1 +1,7 @@
1
- export {};
1
+ /**
2
+ * A function you may use in your dialogs to make an authenticated graphql request to the DosGato
3
+ * API.
4
+ */
5
+ export async function dialogQuery(query, variables) {
6
+ return await window.api.query(query, variables);
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dosgato/templating",
3
- "version": "0.0.83",
3
+ "version": "0.0.85",
4
4
  "description": "A library to support building templates for dosgato CMS.",
5
5
  "type": "module",
6
6
  "exports": {