@dosgato/templating 0.0.12 → 0.0.15

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.
@@ -1,3 +1,4 @@
1
+ import { EditBarOpts } from './editbar';
1
2
  import { ResourceProvider } from './provider';
2
3
  /**
3
4
  * This is the primary templating class to build your templates. Subclass it and provide
@@ -87,6 +88,43 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
87
88
  * Same as cssBlocks() but for javascript.
88
89
  */
89
90
  jsBlocks(): string[];
91
+ /**
92
+ * Components may override this function to give their edit bars a custom
93
+ * label instead of using the templateName property
94
+ *
95
+ * For instance, you could return this.data.title
96
+ */
97
+ editLabel(): string;
98
+ /**
99
+ * Components may override this function to give their edit bars a custom
100
+ * CSS class
101
+ */
102
+ editClass(): undefined;
103
+ /**
104
+ * Components may override this function to give their new bars a custom
105
+ * label
106
+ *
107
+ * For instance, an area that only accepts 'layout' components could
108
+ * return "Add Layout"
109
+ */
110
+ newLabel(areaName: string): string;
111
+ /**
112
+ * Components may override this function to give their new bars a custom
113
+ * CSS class
114
+ */
115
+ newClass(areaName: string): undefined;
116
+ /**
117
+ * Components may override this function to provide a custom edit bar
118
+ *
119
+ * Generally should not be overridden - override editLabel and editClass instead
120
+ */
121
+ editBar(opts?: EditBarOpts): string;
122
+ /**
123
+ * Components may override this function to provide a custom new bar
124
+ *
125
+ * Generally should not be overridden - override newLabel and newClass instead
126
+ */
127
+ newBar(areaName: string, opts?: EditBarOpts): string;
90
128
  }
91
129
  export interface PageRecord<DataType extends PageData = PageData> {
92
130
  id: string;
package/dist/component.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Page = exports.Component = void 0;
4
+ const editbar_1 = require("./editbar");
4
5
  const provider_1 = require("./provider");
5
6
  /**
6
7
  * This is the primary templating class to build your templates. Subclass it and provide
@@ -83,9 +84,8 @@ class Component extends provider_1.ResourceProvider {
83
84
  * continue. You generally do not need to use this function, just throw when appropriate.
84
85
  */
85
86
  logError(e) {
86
- var _a;
87
87
  this.hadError = true;
88
- (_a = this.parent) === null || _a === void 0 ? void 0 : _a.passError(e, this.path);
88
+ this.passError(e, this.path);
89
89
  }
90
90
  // helper function for recursively passing the error up until it reaches the page
91
91
  passError(e, path) {
@@ -102,13 +102,69 @@ class Component extends provider_1.ResourceProvider {
102
102
  * need any async data to make this determination, be sure to fetch it during the fetch phase.
103
103
  */
104
104
  cssBlocks() {
105
- return this.constructor.cssBlocks.keys();
105
+ return Array.from(this.constructor.cssBlocks.keys());
106
106
  }
107
107
  /**
108
108
  * Same as cssBlocks() but for javascript.
109
109
  */
110
110
  jsBlocks() {
111
- return this.constructor.jsBlocks.keys();
111
+ return Array.from(this.constructor.jsBlocks.keys());
112
+ }
113
+ /**
114
+ * Components may override this function to give their edit bars a custom
115
+ * label instead of using the templateName property
116
+ *
117
+ * For instance, you could return this.data.title
118
+ */
119
+ editLabel() {
120
+ const This = this.constructor;
121
+ return This.templateName;
122
+ }
123
+ /**
124
+ * Components may override this function to give their edit bars a custom
125
+ * CSS class
126
+ */
127
+ editClass() {
128
+ return undefined;
129
+ }
130
+ /**
131
+ * Components may override this function to give their new bars a custom
132
+ * label
133
+ *
134
+ * For instance, an area that only accepts 'layout' components could
135
+ * return "Add Layout"
136
+ */
137
+ newLabel(areaName) {
138
+ return 'Add Content';
139
+ }
140
+ /**
141
+ * Components may override this function to give their new bars a custom
142
+ * CSS class
143
+ */
144
+ newClass(areaName) {
145
+ return undefined;
146
+ }
147
+ /**
148
+ * Components may override this function to provide a custom edit bar
149
+ *
150
+ * Generally should not be overridden - override editLabel and editClass instead
151
+ */
152
+ editBar(opts = {}) {
153
+ var _a, _b;
154
+ (_a = opts.label) !== null && _a !== void 0 ? _a : (opts.label = this.editLabel());
155
+ (_b = opts.extraClass) !== null && _b !== void 0 ? _b : (opts.extraClass = this.editClass());
156
+ return (0, editbar_1.editBar)(this.path, opts);
157
+ }
158
+ /**
159
+ * Components may override this function to provide a custom new bar
160
+ *
161
+ * Generally should not be overridden - override newLabel and newClass instead
162
+ */
163
+ newBar(areaName, opts = {}) {
164
+ var _a, _b;
165
+ (_a = opts.label) !== null && _a !== void 0 ? _a : (opts.label = this.newLabel(areaName));
166
+ (_b = opts.extraClass) !== null && _b !== void 0 ? _b : (opts.extraClass = this.newClass(areaName));
167
+ return (0, editbar_1.newBar)(this.path + '.' + areaName, opts);
112
168
  }
113
169
  }
114
170
  exports.Component = Component;
@@ -0,0 +1,10 @@
1
+ export interface EditBarOpts {
2
+ extraClass?: string;
3
+ label?: string;
4
+ }
5
+ export declare function editBar(path: string, opts: EditBarOpts & {
6
+ label: string;
7
+ }): string;
8
+ export declare function newBar(path: string, opts: EditBarOpts & {
9
+ label: string;
10
+ }): string;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.newBar = exports.editBar = void 0;
4
+ const txstate_utils_1 = require("txstate-utils");
5
+ function editBar(path, opts) {
6
+ var _a;
7
+ const id = (0, txstate_utils_1.randomid)();
8
+ return `
9
+ <div class="dg-edit-bar ${(_a = opts.extraClass) !== null && _a !== void 0 ? _a : ''}" data-path="${(0, txstate_utils_1.htmlEncode)(path)}">
10
+ <span id="${id}" class="dg-edit-bar-label">${(0, txstate_utils_1.htmlEncode)(opts.label)}</span>
11
+ <button onClick="window.dgEditing.edit" aria-describedby="${id}">Edit</button>
12
+ <button onClick="window.dgEditing.move" aria-describedby="${id}">Move</button>
13
+ <button onClick="window.dgEditing.del" aria-describedby="${id}">Trash</button>
14
+ </div>
15
+ `.trim();
16
+ }
17
+ exports.editBar = editBar;
18
+ function newBar(path, opts) {
19
+ var _a;
20
+ return `
21
+ <div class="dg-new-bar ${(_a = opts.extraClass) !== null && _a !== void 0 ? _a : ''}" data-path="${(0, txstate_utils_1.htmlEncode)(path)}">
22
+ <button>${(0, txstate_utils_1.htmlEncode)(opts.label)}</button>
23
+ </div>
24
+ `.trim();
25
+ }
26
+ exports.newBar = newBar;
@@ -1,8 +1,11 @@
1
1
  import { IconifyIcon } from '@iconify/svelte';
2
2
  import { SvelteComponent } from 'svelte';
3
+ export interface IconOrSVG extends IconifyIcon {
4
+ raw?: true;
5
+ }
3
6
  export interface UITemplate {
4
7
  templateKey: string;
5
- dialog: SvelteComponent;
6
- preview?: IconifyIcon;
7
- icon?: IconifyIcon;
8
+ dialog: typeof SvelteComponent;
9
+ preview?: IconOrSVG;
10
+ icon?: IconOrSVG;
8
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dosgato/templating",
3
- "version": "0.0.12",
3
+ "version": "0.0.15",
4
4
  "description": "A library to support building templates for dosgato CMS.",
5
5
  "exports": {
6
6
  "require": "./dist/index.js",
@@ -13,7 +13,8 @@
13
13
  },
14
14
  "dependencies": {
15
15
  "@iconify/svelte": "^2.2.1",
16
- "svelte": "^3.48.0"
16
+ "svelte": "^3.48.0",
17
+ "txstate-utils": "^1.7.1"
17
18
  },
18
19
  "devDependencies": {
19
20
  "eslint-config-standard-with-typescript": "^21.0.1",