@dosgato/templating 0.0.15 → 0.0.18

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.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 = (_a = this.parent) !== null && _a !== void 0 ? _a : this;
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))
@@ -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
- var _a;
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
- 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());
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
- 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));
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.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export interface EditBarOpts {
2
2
  extraClass?: string;
3
3
  label?: string;
4
+ editMode?: boolean;
4
5
  }
5
6
  export declare function editBar(path: string, opts: EditBarOpts & {
6
7
  label: string;
package/dist/editbar.js CHANGED
@@ -3,23 +3,25 @@ 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;
6
+ if (!opts.editMode)
7
+ return '';
7
8
  const id = (0, txstate_utils_1.randomid)();
8
9
  return `
9
- <div class="dg-edit-bar ${(_a = opts.extraClass) !== null && _a !== void 0 ? _a : ''}" data-path="${(0, txstate_utils_1.htmlEncode)(path)}">
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)">
10
11
  <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>
12
+ <button onclick="window.dgEditing.edit(event)" aria-describedby="${id}">Edit</button>
13
+ <button onclick="window.dgEditing.move(event)" aria-describedby="${id}">Move</button>
14
+ <button onclick="window.dgEditing.del(event)" aria-describedby="${id}">Trash</button>
14
15
  </div>
15
16
  `.trim();
16
17
  }
17
18
  exports.editBar = editBar;
18
19
  function newBar(path, opts) {
19
- var _a;
20
+ if (!opts.editMode)
21
+ return '';
20
22
  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 role="button" onclick="window.dgEditing.create(event)" class="dg-new-bar ${opts.extraClass ?? ''}" data-path="${(0, txstate_utils_1.htmlEncode)(path)}">
24
+ ${(0, txstate_utils_1.htmlEncode)(opts.label)}
23
25
  </div>
24
26
  `.trim();
25
27
  }
package/dist/links.d.ts CHANGED
@@ -63,3 +63,15 @@ export interface DataFolderLink {
63
63
  path: string;
64
64
  }
65
65
  export declare type LinkDefinition = AssetLink | AssetFolderLink | PageLink | WebLink | DataLink | DataFolderLink;
66
+ /**
67
+ * This function is used by API template definitions to help them identify links inside large blocks
68
+ * of text and return them for indexing.
69
+ */
70
+ export declare function extractLinksFromText(text: string): LinkDefinition[];
71
+ /**
72
+ * This function is used by API template definitions to help them identify all the searchable
73
+ * words in a large block of text and return them for indexing.
74
+ */
75
+ export declare function getKeywords(text: string, options?: {
76
+ stopwords?: boolean;
77
+ }): string[];
package/dist/links.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;
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dosgato/templating",
3
- "version": "0.0.15",
3
+ "version": "0.0.18",
4
4
  "description": "A library to support building templates for dosgato CMS.",
5
5
  "exports": {
6
6
  "require": "./dist/index.js",