CETEIcean 1.5.0 → 1.7.1

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.
@@ -0,0 +1,6 @@
1
+ {
2
+ "cSpell.words": [
3
+ "Ordinality",
4
+ "prefixdef"
5
+ ]
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "CETEIcean",
3
- "version": "1.5.0",
3
+ "version": "1.7.1",
4
4
  "description": "JavaScript library to load a TEI XML document and register it as HTML5 custom elements.",
5
5
  "main": "src/CETEI.js",
6
6
  "keywords": [
@@ -18,13 +18,13 @@
18
18
  "devDependencies": {
19
19
  "@babel/core": "^7.15.5",
20
20
  "@babel/preset-env": "7.15.6",
21
+ "@rollup/plugin-babel": "^5.3.0",
21
22
  "babel-preset-env": "^1.7.0",
22
- "http-server": "^0.12.3",
23
+ "http-server": "^14.1.1",
23
24
  "onchange": "^6.1.1",
24
25
  "rollup": "^2.57.0",
25
- "@rollup/plugin-babel": "^5.3.0",
26
- "rollup-plugin-terser": "1.0.1",
27
- "terser": "^3.17.0"
26
+ "rollup-plugin-terser": "^7.0.2",
27
+ "terser": "^5.14.2"
28
28
  },
29
29
  "scripts": {
30
30
  "build": "rollup -c rollup.config.js",
package/src/CETEI.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import defaultBehaviors from './defaultBehaviors';
2
2
  import * as utilities from './utilities';
3
- import {addBehaviors, addBehavior, applyBehaviors, removeBehavior} from './behaviors';
3
+ import {addBehaviors, addBehavior, removeBehavior} from './behaviors';
4
4
  import {learnElementNames, learnCustomElementNames} from './dom';
5
5
 
6
6
  class CETEI {
@@ -10,7 +10,6 @@ class CETEI {
10
10
  // Bind methods
11
11
  this.addBehaviors = addBehaviors.bind(this);
12
12
  this.addBehavior = addBehavior.bind(this);
13
- this.applyBehaviors = applyBehaviors.bind(this);
14
13
  this.removeBehavior = removeBehavior.bind(this);
15
14
 
16
15
  // Bind selected utilities
@@ -304,11 +303,14 @@ childExists(elt, name) {
304
303
  strings or an object with CSS selector keys and either functions
305
304
  or arrays as described above. Returns a closure around a function
306
305
  that can be called in the element constructor or applied to an
307
- individual element.
306
+ individual element. An empty array is considered a no-op.
308
307
 
309
308
  Called by the getHandler() and getFallback() methods
310
309
  */
311
310
  decorator(template) {
311
+ if (Array.isArray(template) && template.length == 0) {
312
+ return function(e) {};
313
+ }
312
314
  if (Array.isArray(template) && !Array.isArray(template[0])) {
313
315
  return this.applyDecorator(template)
314
316
  }
@@ -435,6 +437,15 @@ template(str, elt) {
435
437
  return result;
436
438
  }
437
439
 
440
+ // Define or apply behaviors for the document
441
+ applyBehaviors() {
442
+ if (window.customElements) {
443
+ this.define.call(this, this.els);
444
+ } else {
445
+ this.fallback.call(this, this.els);
446
+ }
447
+ }
448
+
438
449
  /*
439
450
  Registers the list of elements provided with the browser.
440
451
  Called by makeHTML5(), but can be called independently if, for example,
@@ -443,7 +454,7 @@ template(str, elt) {
443
454
  define(names) {
444
455
  for (let name of names) {
445
456
  try {
446
- let fn = this.getHandler(this.behaviors, name);
457
+ const fn = this.getHandler(this.behaviors, name);
447
458
  window.customElements.define(this.tagName(name), class extends HTMLElement {
448
459
  constructor() {
449
460
  super();
@@ -469,7 +480,7 @@ define(names) {
469
480
  // When using the same CETEIcean instance for multiple TEI files, this error becomes very common.
470
481
  // It's muted by default unless the debug option is set.
471
482
  if (this.debug) {
472
- console.log(tagName(name) + " couldn't be registered or is already registered.");
483
+ console.log(this.tagName(name) + " couldn't be registered or is already registered.");
473
484
  console.log(error);
474
485
  }
475
486
  }
package/src/behaviors.js CHANGED
@@ -19,6 +19,11 @@ export function addBehaviors(bhvs) {
19
19
  }
20
20
  }
21
21
  }
22
+ if (bhvs["functions"]) {
23
+ for (let fn of Object.keys(bhvs["functions"])) {
24
+ this.utilities[fn] = bhvs["functions"][fn];
25
+ }
26
+ }
22
27
  if (bhvs["handlers"]) {
23
28
  console.log("Behavior handlers are no longer used.")
24
29
  }
@@ -66,12 +71,3 @@ export function removeBehavior(ns, element) {
66
71
  }
67
72
  delete this.behaviors[`${p}:${element}`];
68
73
  }
69
-
70
- // Define or apply behaviors for the document
71
- export function applyBehaviors() {
72
- if (window.customElements) {
73
- this.define.call(this, this.els);
74
- } else {
75
- this.fallback.call(this, this.els);
76
- }
77
- }
@@ -84,11 +84,6 @@ export default {
84
84
  document.querySelector("head").appendChild(title);
85
85
  }]
86
86
  ],
87
- "cell": [
88
- ["[cols]", function(elt) {
89
- elt.setAttribute("style", "grid-column: " + this.getOrdinality(elt) + " / span " + elt.getAttribute("cols") + ";");
90
- }]
91
- ]
92
87
  },
93
88
  "teieg": {
94
89
  "egXML": function(elt) {
package/src/utilities.js CHANGED
@@ -208,7 +208,6 @@ export function serialize(el, stripElt, ws) {
208
208
  return str;
209
209
  }
210
210
 
211
-
212
211
  export function unEscapeEntities(str) {
213
212
  return str.replace(/>/, ">")
214
213
  .replace(/"/, "\"")
@@ -75,7 +75,6 @@
75
75
  CETEIcean.getHTML5('https://raw.githubusercontent.com/textcreationpartnership/A00689/master/A00689.xml', function(data) {
76
76
  document.getElementById("TEI").innerHTML = "";
77
77
  document.getElementById("TEI").appendChild(data);
78
- CETEIcean.addStyle(document, data);
79
78
  // Fix combining abbreviation marker in Chrome
80
79
  if (!!window.chrome) {
81
80
  var gs = document.getElementsByTagName("tei-g");
@@ -1,31 +0,0 @@
1
- <html>
2
- <head>
3
- <meta charset="utf-8">
4
- <link rel="stylesheet" href="CETEIcean.css" media="screen" charset="utf-8">
5
- </head>
6
- <body>
7
- <div id="TEI"></div>
8
- <script src="../dist/CETEI.js"></script>
9
- <script>
10
-
11
- /* Testing the functions for registering elements. All these should work */
12
-
13
- // Repeated elements should be skipped
14
- var els = ["TEI", "TEI", "teiHeader"];
15
-
16
- var CETEIcean = new CETEI();
17
-
18
- if (document.registerElement) {
19
- CETEIcean.registerAll(els);
20
- if (document.createElement("tei-TEI") instanceof HTMLElement) {
21
- console.log("tei-TEI correctly registered without conflict");
22
- }
23
- }
24
- else {
25
- console.log("HTML CE not supported. Fallback used.")
26
- }
27
-
28
-
29
- </script>
30
- </body>
31
- </html>