@dosgato/templating 0.0.20 → 0.0.21

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,5 +1,5 @@
1
- import { PageWithAncestors, ComponentData } from './component';
2
- import { LinkDefinition } from './links';
1
+ import { PageWithAncestors, ComponentData } from './component.js';
2
+ import { LinkDefinition } from './links.js';
3
3
  export declare type APITemplateType = 'page' | 'component' | 'data';
4
4
  /**
5
5
  * This interface lays out the structure the API needs for each template in the system.
@@ -1,26 +1,21 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getKeywords = exports.extractLinksFromText = void 0;
4
- const stopwords_1 = require("./stopwords");
1
+ import { stopwords } from './stopwords.js';
5
2
  /**
6
3
  * This function is used by API template definitions to help them identify links inside large blocks
7
4
  * of text and return them for indexing.
8
5
  */
9
- function extractLinksFromText(text) {
6
+ export function extractLinksFromText(text) {
10
7
  const matches = text.matchAll(/{.*"type"\s?:\s+"\w+".*?}/gi);
11
8
  return Array.from(matches).map(m => JSON.parse(m[0]));
12
9
  }
13
- exports.extractLinksFromText = extractLinksFromText;
14
10
  /**
15
11
  * This function is used by API template definitions to help them identify all the searchable
16
12
  * words in a large block of text and return them for indexing.
17
13
  */
18
- function getKeywords(text, options) {
14
+ export function getKeywords(text, options) {
19
15
  return Array.from(new Set(text
20
16
  .toLocaleLowerCase()
21
17
  .normalize('NFD').replace(/\p{Diacritic}/gu, '')
22
18
  .split(/[^\w-]+/)
23
19
  .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)))));
20
+ .filter(word => word.length > 2 && (options?.stopwords === false || !stopwords[word]) && isNaN(Number(word)))));
25
21
  }
26
- exports.getKeywords = getKeywords;
@@ -1,6 +1,6 @@
1
- import { EditBarOpts } from './editbar';
2
- import { LinkDefinition } from './links';
3
- import { ResourceProvider } from './provider';
1
+ import { EditBarOpts } from './editbar.js';
2
+ import { LinkDefinition } from './links.js';
3
+ import { ResourceProvider } from './provider.js';
4
4
  /**
5
5
  * This is the primary templating class to build your templates. Subclass it and provide
6
6
  * at least a render function.
package/dist/component.js CHANGED
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Page = exports.Component = void 0;
4
- const editbar_1 = require("./editbar");
5
- const provider_1 = require("./provider");
1
+ import { editBar, newBar } from './editbar.js';
2
+ import { ResourceProvider } from './provider.js';
6
3
  /**
7
4
  * This is the primary templating class to build your templates. Subclass it and provide
8
5
  * at least a render function.
@@ -10,7 +7,7 @@ const provider_1 = require("./provider");
10
7
  * During rendering, it will be "hydrated" - placed into a full page structure with its
11
8
  * parent and child components linked.
12
9
  */
13
- class Component extends provider_1.ResourceProvider {
10
+ export class Component extends ResourceProvider {
14
11
  // the constructor is part of the recursive hydration mechanism: constructing
15
12
  // a Component will also construct/hydrate all its child components
16
13
  constructor(data, path, parent) {
@@ -150,7 +147,7 @@ class Component extends provider_1.ResourceProvider {
150
147
  editBar(opts = {}) {
151
148
  opts.label ?? (opts.label = this.editLabel());
152
149
  opts.extraClass ?? (opts.extraClass = this.editClass());
153
- return (0, editbar_1.editBar)(this.path, opts);
150
+ return editBar(this.path, opts);
154
151
  }
155
152
  /**
156
153
  * Components may override this function to provide a custom new bar
@@ -160,11 +157,10 @@ class Component extends provider_1.ResourceProvider {
160
157
  newBar(areaName, opts = {}) {
161
158
  opts.label ?? (opts.label = this.newLabel(areaName));
162
159
  opts.extraClass ?? (opts.extraClass = this.newClass(areaName));
163
- return (0, editbar_1.newBar)(this.path + '.' + areaName, opts);
160
+ return newBar(this.path + '.' + areaName, opts);
164
161
  }
165
162
  }
166
- exports.Component = Component;
167
- class Page extends Component {
163
+ export class Page extends Component {
168
164
  constructor(page) {
169
165
  super(page.data, '/', undefined);
170
166
  this.pagePath = page.path;
@@ -174,4 +170,3 @@ class Page extends Component {
174
170
  console.warn(`Recoverable issue occured during render of ${this.pagePath}. Component at ${path} threw the following error:`, e);
175
171
  }
176
172
  }
177
- exports.Page = Page;
package/dist/editbar.js CHANGED
@@ -1,28 +1,23 @@
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) {
1
+ import { htmlEncode, randomid } from 'txstate-utils';
2
+ export function editBar(path, opts) {
6
3
  if (!opts.editMode)
7
4
  return '';
8
- const id = (0, txstate_utils_1.randomid)();
5
+ const id = randomid();
9
6
  return `
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)">
11
- <span id="${id}" class="dg-edit-bar-label">${(0, txstate_utils_1.htmlEncode)(opts.label)}</span>
7
+ <div class="dg-edit-bar ${opts.extraClass ?? ''}" data-path="${htmlEncode(path)}" draggable="true" ondragstart="window.dgEditing.drag(event)" ondragover="window.dgEditing.over(event)" ondragend="window.dgEditing.drop(event)">
8
+ <span id="${id}" class="dg-edit-bar-label">${htmlEncode(opts.label)}</span>
12
9
  <button onclick="window.dgEditing.edit(event)" aria-describedby="${id}">Edit</button>
13
10
  <button onclick="window.dgEditing.move(event)" aria-describedby="${id}">Move</button>
14
11
  <button onclick="window.dgEditing.del(event)" aria-describedby="${id}">Trash</button>
15
12
  </div>
16
13
  `.trim();
17
14
  }
18
- exports.editBar = editBar;
19
- function newBar(path, opts) {
15
+ export function newBar(path, opts) {
20
16
  if (!opts.editMode)
21
17
  return '';
22
18
  return `
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)}
19
+ <div role="button" onclick="window.dgEditing.create(event)" class="dg-new-bar ${opts.extraClass ?? ''}" data-path="${htmlEncode(path)}">
20
+ ${htmlEncode(opts.label)}
25
21
  </div>
26
22
  `.trim();
27
23
  }
28
- exports.newBar = newBar;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export * from './apitemplate';
2
- export * from './component';
3
- export * from './links';
4
- export * from './provider';
5
- export * from './uitemplate';
1
+ export * from './apitemplate.js';
2
+ export * from './component.js';
3
+ export * from './links.js';
4
+ export * from './provider.js';
5
+ export * from './uitemplate.js';
package/dist/index.js CHANGED
@@ -1,21 +1,5 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./apitemplate"), exports);
18
- __exportStar(require("./component"), exports);
19
- __exportStar(require("./links"), exports);
20
- __exportStar(require("./provider"), exports);
21
- __exportStar(require("./uitemplate"), exports);
1
+ export * from './apitemplate.js';
2
+ export * from './component.js';
3
+ export * from './links.js';
4
+ export * from './provider.js';
5
+ export * from './uitemplate.js';
package/dist/links.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/dist/provider.js CHANGED
@@ -1,7 +1,4 @@
1
- "use strict";
2
1
  /* eslint-disable @typescript-eslint/no-extraneous-class */
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.ResourceProvider = void 0;
5
2
  /**
6
3
  * This class is a parent class for Component, but it can also be used as a standalone
7
4
  * if you are creating a set of templates with shared resources. This will be fairly
@@ -11,10 +8,9 @@ exports.ResourceProvider = void 0;
11
8
  *
12
9
  * If you do this, don't forget to register the provider along with your templates!
13
10
  */
14
- class ResourceProvider {
11
+ export class ResourceProvider {
15
12
  static webpath(name) { return this.webpaths.get(name); }
16
13
  }
17
- exports.ResourceProvider = ResourceProvider;
18
14
  /**
19
15
  * Each template should provide a map of CSS blocks where the map key is the unique name for
20
16
  * the CSS and the value is the CSS itself. For instance, if a template needs CSS from a
package/dist/render.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ContextBase } from './component';
1
+ import { ContextBase } from './component.js';
2
2
  export declare function printHeader(ctx: ContextBase, content: string): string;
3
3
  export declare function advanceHeader(ctx: ContextBase, content?: string): {
4
4
  headerLevel: number;
package/dist/render.js CHANGED
@@ -1,9 +1,6 @@
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))
1
+ import { isBlank } from 'txstate-utils';
2
+ export function printHeader(ctx, content) {
3
+ if (isBlank(content))
7
4
  return '';
8
5
  const level = (ctx.headerLevel ?? 0) + 1;
9
6
  if (level < 1)
@@ -12,11 +9,9 @@ function printHeader(ctx, content) {
12
9
  return `<h6>${content}</h1>`;
13
10
  return `<h${level}>${content}</h${level}>`;
14
11
  }
15
- exports.printHeader = printHeader;
16
- function advanceHeader(ctx, content) {
12
+ export function advanceHeader(ctx, content) {
17
13
  const ret = { ...ctx };
18
- if (!(0, txstate_utils_1.isBlank)(content))
14
+ if (!isBlank(content))
19
15
  ret.headerLevel = (ret.headerLevel ?? 0) + 1;
20
16
  return ret;
21
17
  }
22
- exports.advanceHeader = advanceHeader;
package/dist/stopwords.js CHANGED
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stopwords = void 0;
4
- exports.stopwords = {
1
+ export const stopwords = {
5
2
  myself: true,
6
3
  our: true,
7
4
  ours: true,
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@dosgato/templating",
3
- "version": "0.0.20",
3
+ "version": "0.0.21",
4
4
  "description": "A library to support building templates for dosgato CMS.",
5
+ "type": "module",
5
6
  "exports": {
6
- "require": "./dist/index.js",
7
- "import": "./dist-esm/index.js"
7
+ ".": "./dist/index.js",
8
+ "./package.json": "./package.json"
8
9
  },
9
10
  "types": "dist/index.d.ts",
10
11
  "scripts": {
@@ -36,6 +37,6 @@
36
37
  },
37
38
  "homepage": "https://github.com/txstate-etc/dosgato-templating#readme",
38
39
  "files": [
39
- "dist", "dist-esm"
40
+ "dist"
40
41
  ]
41
42
  }
package/dist-esm/index.js DELETED
@@ -1,7 +0,0 @@
1
- import all from '../dist/index.js'
2
-
3
- export const ResourceProvider = all.ResourceProvider
4
- export const Component = all.Component
5
- export const Page = all.Page
6
- export const extractLinksFromText = all.extractLinksFromText
7
- export const getKeywords = all.getKeywords
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }