@dosgato/templating 0.0.14 → 0.0.17

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
@@ -109,6 +110,62 @@ class Component extends provider_1.ResourceProvider {
109
110
  jsBlocks() {
110
111
  return Array.from(this.constructor.jsBlocks.keys());
111
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);
168
+ }
112
169
  }
113
170
  exports.Component = Component;
114
171
  class Page extends Component {
@@ -0,0 +1,11 @@
1
+ export interface EditBarOpts {
2
+ extraClass?: string;
3
+ label?: string;
4
+ editMode?: boolean;
5
+ }
6
+ export declare function editBar(path: string, opts: EditBarOpts & {
7
+ label: string;
8
+ }): string;
9
+ export declare function newBar(path: string, opts: EditBarOpts & {
10
+ label: string;
11
+ }): string;
@@ -0,0 +1,30 @@
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
+ if (!opts.editMode)
8
+ return '';
9
+ const id = (0, txstate_utils_1.randomid)();
10
+ return `
11
+ <div class="dg-edit-bar ${(_a = opts.extraClass) !== null && _a !== void 0 ? _a : ''}" data-path="${(0, txstate_utils_1.htmlEncode)(path)}" draggable="true" ondragstart="window.dgEditing.drag(event)" ondragover="window.dgEditing.over(event)" ondragend="window.dgEditing.drop(event)">
12
+ <span id="${id}" class="dg-edit-bar-label">${(0, txstate_utils_1.htmlEncode)(opts.label)}</span>
13
+ <button onclick="window.dgEditing.edit(event)" aria-describedby="${id}">Edit</button>
14
+ <button onclick="window.dgEditing.move(event)" aria-describedby="${id}">Move</button>
15
+ <button onclick="window.dgEditing.del(event)" aria-describedby="${id}">Trash</button>
16
+ </div>
17
+ `.trim();
18
+ }
19
+ exports.editBar = editBar;
20
+ function newBar(path, opts) {
21
+ var _a;
22
+ if (!opts.editMode)
23
+ return '';
24
+ return `
25
+ <div role="button" onclick="window.dgEditing.create(event)" class="dg-new-bar ${(_a = opts.extraClass) !== null && _a !== void 0 ? _a : ''}" data-path="${(0, txstate_utils_1.htmlEncode)(path)}">
26
+ ${(0, txstate_utils_1.htmlEncode)(opts.label)}
27
+ </div>
28
+ `.trim();
29
+ }
30
+ 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.14",
3
+ "version": "0.0.17",
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",