@dosgato/templating 0.0.17 → 0.0.20
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/apitemplate.d.ts +12 -0
- package/dist/apitemplate.js +24 -0
- package/dist/component.d.ts +18 -4
- package/dist/component.js +10 -14
- package/dist/editbar.js +2 -4
- package/dist/render.d.ts +5 -0
- package/dist/render.js +22 -0
- package/dist/stopwords.d.ts +1 -0
- package/dist/stopwords.js +154 -0
- package/dist-esm/index.js +2 -0
- package/package.json +1 -1
package/dist/apitemplate.d.ts
CHANGED
|
@@ -90,3 +90,15 @@ export interface Migration {
|
|
|
90
90
|
}
|
|
91
91
|
export declare type LinkGatheringFn = (data: any) => LinkDefinition[];
|
|
92
92
|
export declare type FulltextGatheringFn = (data: any) => string[];
|
|
93
|
+
/**
|
|
94
|
+
* This function is used by API template definitions to help them identify links inside large blocks
|
|
95
|
+
* of text and return them for indexing.
|
|
96
|
+
*/
|
|
97
|
+
export declare function extractLinksFromText(text: string): LinkDefinition[];
|
|
98
|
+
/**
|
|
99
|
+
* This function is used by API template definitions to help them identify all the searchable
|
|
100
|
+
* words in a large block of text and return them for indexing.
|
|
101
|
+
*/
|
|
102
|
+
export declare function getKeywords(text: string, options?: {
|
|
103
|
+
stopwords?: boolean;
|
|
104
|
+
}): string[];
|
package/dist/apitemplate.js
CHANGED
|
@@ -1,2 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getKeywords = exports.extractLinksFromText = void 0;
|
|
4
|
+
const stopwords_1 = require("./stopwords");
|
|
5
|
+
/**
|
|
6
|
+
* This function is used by API template definitions to help them identify links inside large blocks
|
|
7
|
+
* of text and return them for indexing.
|
|
8
|
+
*/
|
|
9
|
+
function extractLinksFromText(text) {
|
|
10
|
+
const matches = text.matchAll(/{.*"type"\s?:\s+"\w+".*?}/gi);
|
|
11
|
+
return Array.from(matches).map(m => JSON.parse(m[0]));
|
|
12
|
+
}
|
|
13
|
+
exports.extractLinksFromText = extractLinksFromText;
|
|
14
|
+
/**
|
|
15
|
+
* This function is used by API template definitions to help them identify all the searchable
|
|
16
|
+
* words in a large block of text and return them for indexing.
|
|
17
|
+
*/
|
|
18
|
+
function getKeywords(text, options) {
|
|
19
|
+
return Array.from(new Set(text
|
|
20
|
+
.toLocaleLowerCase()
|
|
21
|
+
.normalize('NFD').replace(/\p{Diacritic}/gu, '')
|
|
22
|
+
.split(/[^\w-]+/)
|
|
23
|
+
.flatMap(word => word.includes('-') ? word.split('-').concat(word.replace('-', '')) : [word])
|
|
24
|
+
.filter(word => word.length > 2 && (options?.stopwords === false || !stopwords_1.stopwords[word]) && isNaN(Number(word)))));
|
|
25
|
+
}
|
|
26
|
+
exports.getKeywords = getKeywords;
|
package/dist/component.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EditBarOpts } from './editbar';
|
|
2
|
+
import { LinkDefinition } from './links';
|
|
2
3
|
import { ResourceProvider } from './provider';
|
|
3
4
|
/**
|
|
4
5
|
* This is the primary templating class to build your templates. Subclass it and provide
|
|
@@ -18,6 +19,19 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
|
|
|
18
19
|
parent?: Component;
|
|
19
20
|
page?: Page;
|
|
20
21
|
hadError: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* This function will be provided by the rendering server and should be used inside your fetch,
|
|
24
|
+
* method to convert a link, as input by a user, into a URL suitable for an href, or optionally
|
|
25
|
+
* an absolute URL suitable for a backend http request or non-HTML document like an RSS feed.
|
|
26
|
+
*/
|
|
27
|
+
resolveLink: (link: string | LinkDefinition, absolute?: boolean) => Promise<string>;
|
|
28
|
+
/**
|
|
29
|
+
* This function will be provided by the rendering server and should be used inside your fetch
|
|
30
|
+
* method to prepare editor-provided HTML for rendering. It will do things like find and resolve
|
|
31
|
+
* link definitions in the internal dosgato format and clean up tags that were accidentally left
|
|
32
|
+
* open to protect overall page integrity.
|
|
33
|
+
*/
|
|
34
|
+
processRich: (text: string) => Promise<string>;
|
|
21
35
|
/**
|
|
22
36
|
* The first phase of rendering a component is the fetch phase. Each component may
|
|
23
37
|
* provide a fetch method that looks up data it needs from external sources. This step
|
|
@@ -31,14 +45,14 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
|
|
|
31
45
|
*/
|
|
32
46
|
fetch(editMode: boolean): Promise<FetchedType>;
|
|
33
47
|
/**
|
|
34
|
-
* The second phase of rendering a component is the context phase. This step is TOP-DOWN
|
|
35
|
-
*
|
|
36
|
-
*
|
|
48
|
+
* The second phase of rendering a component is the context phase. This step is TOP-DOWN and
|
|
49
|
+
* NON-MUTATING. Each component will receive the parent component's context and then pass a
|
|
50
|
+
* NEW context object to its children.
|
|
37
51
|
*
|
|
38
52
|
* This is useful for rendering logic that is sensitive to where the component exists in
|
|
39
53
|
* the hierarchy of the page. For instance, if a parent component has used an h2 header
|
|
40
54
|
* already, it will want to inform its children so that they can use h3 next, and they inform
|
|
41
|
-
* their children that h4 is next, and so on. (Header level tracking is
|
|
55
|
+
* their children that h4 is next, and so on. (Header level tracking is supported by default in
|
|
42
56
|
* dosgato CMS.)
|
|
43
57
|
*
|
|
44
58
|
* This function may return a promise in case you need to do something asynchronous based on
|
package/dist/component.js
CHANGED
|
@@ -14,7 +14,6 @@ class Component extends provider_1.ResourceProvider {
|
|
|
14
14
|
// the constructor is part of the recursive hydration mechanism: constructing
|
|
15
15
|
// a Component will also construct/hydrate all its child components
|
|
16
16
|
constructor(data, path, parent) {
|
|
17
|
-
var _a;
|
|
18
17
|
super();
|
|
19
18
|
// properties for use during hydration, you do not have to provide these when
|
|
20
19
|
// building a template, but you can use them in the functions you do provide
|
|
@@ -24,7 +23,7 @@ class Component extends provider_1.ResourceProvider {
|
|
|
24
23
|
this.data = ownData;
|
|
25
24
|
this.path = path;
|
|
26
25
|
this.hadError = false;
|
|
27
|
-
let tmpParent =
|
|
26
|
+
let tmpParent = this.parent ?? this;
|
|
28
27
|
while (!(tmpParent instanceof Page) && tmpParent.parent)
|
|
29
28
|
tmpParent = tmpParent.parent;
|
|
30
29
|
if (!(tmpParent instanceof Page))
|
|
@@ -46,14 +45,14 @@ class Component extends provider_1.ResourceProvider {
|
|
|
46
45
|
return undefined;
|
|
47
46
|
}
|
|
48
47
|
/**
|
|
49
|
-
* The second phase of rendering a component is the context phase. This step is TOP-DOWN
|
|
50
|
-
*
|
|
51
|
-
*
|
|
48
|
+
* The second phase of rendering a component is the context phase. This step is TOP-DOWN and
|
|
49
|
+
* NON-MUTATING. Each component will receive the parent component's context and then pass a
|
|
50
|
+
* NEW context object to its children.
|
|
52
51
|
*
|
|
53
52
|
* This is useful for rendering logic that is sensitive to where the component exists in
|
|
54
53
|
* the hierarchy of the page. For instance, if a parent component has used an h2 header
|
|
55
54
|
* already, it will want to inform its children so that they can use h3 next, and they inform
|
|
56
|
-
* their children that h4 is next, and so on. (Header level tracking is
|
|
55
|
+
* their children that h4 is next, and so on. (Header level tracking is supported by default in
|
|
57
56
|
* dosgato CMS.)
|
|
58
57
|
*
|
|
59
58
|
* This function may return a promise in case you need to do something asynchronous based on
|
|
@@ -89,8 +88,7 @@ class Component extends provider_1.ResourceProvider {
|
|
|
89
88
|
}
|
|
90
89
|
// helper function for recursively passing the error up until it reaches the page
|
|
91
90
|
passError(e, path) {
|
|
92
|
-
|
|
93
|
-
(_a = this.parent) === null || _a === void 0 ? void 0 : _a.passError(e, path);
|
|
91
|
+
this.parent?.passError(e, path);
|
|
94
92
|
}
|
|
95
93
|
/**
|
|
96
94
|
* During rendering, each component should determine the CSS blocks that it needs. This may
|
|
@@ -150,9 +148,8 @@ class Component extends provider_1.ResourceProvider {
|
|
|
150
148
|
* Generally should not be overridden - override editLabel and editClass instead
|
|
151
149
|
*/
|
|
152
150
|
editBar(opts = {}) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
(_b = opts.extraClass) !== null && _b !== void 0 ? _b : (opts.extraClass = this.editClass());
|
|
151
|
+
opts.label ?? (opts.label = this.editLabel());
|
|
152
|
+
opts.extraClass ?? (opts.extraClass = this.editClass());
|
|
156
153
|
return (0, editbar_1.editBar)(this.path, opts);
|
|
157
154
|
}
|
|
158
155
|
/**
|
|
@@ -161,9 +158,8 @@ class Component extends provider_1.ResourceProvider {
|
|
|
161
158
|
* Generally should not be overridden - override newLabel and newClass instead
|
|
162
159
|
*/
|
|
163
160
|
newBar(areaName, opts = {}) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
(_b = opts.extraClass) !== null && _b !== void 0 ? _b : (opts.extraClass = this.newClass(areaName));
|
|
161
|
+
opts.label ?? (opts.label = this.newLabel(areaName));
|
|
162
|
+
opts.extraClass ?? (opts.extraClass = this.newClass(areaName));
|
|
167
163
|
return (0, editbar_1.newBar)(this.path + '.' + areaName, opts);
|
|
168
164
|
}
|
|
169
165
|
}
|
package/dist/editbar.js
CHANGED
|
@@ -3,12 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.newBar = exports.editBar = void 0;
|
|
4
4
|
const txstate_utils_1 = require("txstate-utils");
|
|
5
5
|
function editBar(path, opts) {
|
|
6
|
-
var _a;
|
|
7
6
|
if (!opts.editMode)
|
|
8
7
|
return '';
|
|
9
8
|
const id = (0, txstate_utils_1.randomid)();
|
|
10
9
|
return `
|
|
11
|
-
<div class="dg-edit-bar ${
|
|
10
|
+
<div class="dg-edit-bar ${opts.extraClass ?? ''}" 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
11
|
<span id="${id}" class="dg-edit-bar-label">${(0, txstate_utils_1.htmlEncode)(opts.label)}</span>
|
|
13
12
|
<button onclick="window.dgEditing.edit(event)" aria-describedby="${id}">Edit</button>
|
|
14
13
|
<button onclick="window.dgEditing.move(event)" aria-describedby="${id}">Move</button>
|
|
@@ -18,11 +17,10 @@ function editBar(path, opts) {
|
|
|
18
17
|
}
|
|
19
18
|
exports.editBar = editBar;
|
|
20
19
|
function newBar(path, opts) {
|
|
21
|
-
var _a;
|
|
22
20
|
if (!opts.editMode)
|
|
23
21
|
return '';
|
|
24
22
|
return `
|
|
25
|
-
<div role="button" onclick="window.dgEditing.create(event)" class="dg-new-bar ${
|
|
23
|
+
<div role="button" onclick="window.dgEditing.create(event)" class="dg-new-bar ${opts.extraClass ?? ''}" data-path="${(0, txstate_utils_1.htmlEncode)(path)}">
|
|
26
24
|
${(0, txstate_utils_1.htmlEncode)(opts.label)}
|
|
27
25
|
</div>
|
|
28
26
|
`.trim();
|
package/dist/render.d.ts
ADDED
package/dist/render.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.advanceHeader = exports.printHeader = void 0;
|
|
4
|
+
const txstate_utils_1 = require("txstate-utils");
|
|
5
|
+
function printHeader(ctx, content) {
|
|
6
|
+
if ((0, txstate_utils_1.isBlank)(content))
|
|
7
|
+
return '';
|
|
8
|
+
const level = (ctx.headerLevel ?? 0) + 1;
|
|
9
|
+
if (level < 1)
|
|
10
|
+
return `<h1>${content}</h1>`;
|
|
11
|
+
if (level > 6)
|
|
12
|
+
return `<h6>${content}</h1>`;
|
|
13
|
+
return `<h${level}>${content}</h${level}>`;
|
|
14
|
+
}
|
|
15
|
+
exports.printHeader = printHeader;
|
|
16
|
+
function advanceHeader(ctx, content) {
|
|
17
|
+
const ret = { ...ctx };
|
|
18
|
+
if (!(0, txstate_utils_1.isBlank)(content))
|
|
19
|
+
ret.headerLevel = (ret.headerLevel ?? 0) + 1;
|
|
20
|
+
return ret;
|
|
21
|
+
}
|
|
22
|
+
exports.advanceHeader = advanceHeader;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const stopwords: Record<string, boolean>;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stopwords = void 0;
|
|
4
|
+
exports.stopwords = {
|
|
5
|
+
myself: true,
|
|
6
|
+
our: true,
|
|
7
|
+
ours: true,
|
|
8
|
+
ourselves: true,
|
|
9
|
+
you: true,
|
|
10
|
+
your: true,
|
|
11
|
+
yours: true,
|
|
12
|
+
yourself: true,
|
|
13
|
+
yourselves: true,
|
|
14
|
+
him: true,
|
|
15
|
+
his: true,
|
|
16
|
+
himself: true,
|
|
17
|
+
she: true,
|
|
18
|
+
her: true,
|
|
19
|
+
hers: true,
|
|
20
|
+
herself: true,
|
|
21
|
+
its: true,
|
|
22
|
+
itself: true,
|
|
23
|
+
they: true,
|
|
24
|
+
them: true,
|
|
25
|
+
their: true,
|
|
26
|
+
theirs: true,
|
|
27
|
+
themselves: true,
|
|
28
|
+
what: true,
|
|
29
|
+
which: true,
|
|
30
|
+
who: true,
|
|
31
|
+
whom: true,
|
|
32
|
+
this: true,
|
|
33
|
+
that: true,
|
|
34
|
+
these: true,
|
|
35
|
+
those: true,
|
|
36
|
+
are: true,
|
|
37
|
+
was: true,
|
|
38
|
+
were: true,
|
|
39
|
+
been: true,
|
|
40
|
+
being: true,
|
|
41
|
+
have: true,
|
|
42
|
+
has: true,
|
|
43
|
+
had: true,
|
|
44
|
+
having: true,
|
|
45
|
+
does: true,
|
|
46
|
+
did: true,
|
|
47
|
+
doing: true,
|
|
48
|
+
the: true,
|
|
49
|
+
and: true,
|
|
50
|
+
but: true,
|
|
51
|
+
because: true,
|
|
52
|
+
until: true,
|
|
53
|
+
while: true,
|
|
54
|
+
for: true,
|
|
55
|
+
with: true,
|
|
56
|
+
about: true,
|
|
57
|
+
against: true,
|
|
58
|
+
between: true,
|
|
59
|
+
into: true,
|
|
60
|
+
through: true,
|
|
61
|
+
during: true,
|
|
62
|
+
before: true,
|
|
63
|
+
after: true,
|
|
64
|
+
above: true,
|
|
65
|
+
below: true,
|
|
66
|
+
from: true,
|
|
67
|
+
down: true,
|
|
68
|
+
out: true,
|
|
69
|
+
off: true,
|
|
70
|
+
over: true,
|
|
71
|
+
under: true,
|
|
72
|
+
again: true,
|
|
73
|
+
further: true,
|
|
74
|
+
then: true,
|
|
75
|
+
once: true,
|
|
76
|
+
here: true,
|
|
77
|
+
there: true,
|
|
78
|
+
when: true,
|
|
79
|
+
where: true,
|
|
80
|
+
why: true,
|
|
81
|
+
how: true,
|
|
82
|
+
all: true,
|
|
83
|
+
any: true,
|
|
84
|
+
both: true,
|
|
85
|
+
each: true,
|
|
86
|
+
few: true,
|
|
87
|
+
more: true,
|
|
88
|
+
most: true,
|
|
89
|
+
other: true,
|
|
90
|
+
some: true,
|
|
91
|
+
such: true,
|
|
92
|
+
nor: true,
|
|
93
|
+
not: true,
|
|
94
|
+
only: true,
|
|
95
|
+
own: true,
|
|
96
|
+
same: true,
|
|
97
|
+
than: true,
|
|
98
|
+
too: true,
|
|
99
|
+
very: true,
|
|
100
|
+
can: true,
|
|
101
|
+
will: true,
|
|
102
|
+
just: true,
|
|
103
|
+
don: true,
|
|
104
|
+
should: true,
|
|
105
|
+
now: true,
|
|
106
|
+
// HTML
|
|
107
|
+
div: true,
|
|
108
|
+
span: true,
|
|
109
|
+
img: true,
|
|
110
|
+
abbr: true,
|
|
111
|
+
area: true,
|
|
112
|
+
main: true,
|
|
113
|
+
aside: true,
|
|
114
|
+
blockquote: true,
|
|
115
|
+
button: true,
|
|
116
|
+
caption: true,
|
|
117
|
+
code: true,
|
|
118
|
+
del: true,
|
|
119
|
+
strong: true,
|
|
120
|
+
font: true,
|
|
121
|
+
embed: true,
|
|
122
|
+
fieldset: true,
|
|
123
|
+
form: true,
|
|
124
|
+
figure: true,
|
|
125
|
+
iframe: true,
|
|
126
|
+
label: true,
|
|
127
|
+
input: true,
|
|
128
|
+
script: true,
|
|
129
|
+
nav: true,
|
|
130
|
+
select: true,
|
|
131
|
+
option: true,
|
|
132
|
+
picture: true,
|
|
133
|
+
pre: true,
|
|
134
|
+
small: true,
|
|
135
|
+
style: true,
|
|
136
|
+
svg: true,
|
|
137
|
+
sub: true,
|
|
138
|
+
table: true,
|
|
139
|
+
tbody: true,
|
|
140
|
+
href: true,
|
|
141
|
+
src: true,
|
|
142
|
+
srcset: true,
|
|
143
|
+
class: true,
|
|
144
|
+
textarea: true,
|
|
145
|
+
title: true,
|
|
146
|
+
onclick: true,
|
|
147
|
+
// LinkDefinition
|
|
148
|
+
siteId: true,
|
|
149
|
+
path: true,
|
|
150
|
+
type: true,
|
|
151
|
+
assetId: true,
|
|
152
|
+
linkId: true,
|
|
153
|
+
url: true
|
|
154
|
+
};
|
package/dist-esm/index.js
CHANGED