@dosgato/templating 0.0.14 → 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.
- package/dist/component.d.ts +38 -0
- package/dist/component.js +57 -0
- package/dist/editbar.d.ts +10 -0
- package/dist/editbar.js +26 -0
- package/dist/uitemplate.d.ts +6 -3
- package/package.json +3 -2
package/dist/component.d.ts
CHANGED
|
@@ -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,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;
|
package/dist/editbar.js
ADDED
|
@@ -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;
|
package/dist/uitemplate.d.ts
CHANGED
|
@@ -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?:
|
|
7
|
-
icon?:
|
|
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.
|
|
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",
|