@teipublisher/pb-components 1.28.0 → 1.30.0

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.
@@ -9743,6 +9743,11 @@
9743
9743
  "type": "boolean",
9744
9744
  "default": "false"
9745
9745
  },
9746
+ {
9747
+ "name": "before-update-event",
9748
+ "description": "If set to the name of an event, the content of the pb-view will not be replaced\nimmediately upon updates. Instead, an event is emitted, which contains the new content\nin property `root`. An event handler intercepting the event can thus modify the content.\nOnce it is done, it should pass the modified content to the callback function provided\nin the event detail under the name `render`. See the demo for an example.",
9749
+ "type": "string"
9750
+ },
9746
9751
  {
9747
9752
  "name": "subscribe",
9748
9753
  "description": "The name of the channel to subscribe to. Only events on a channel corresponding\nto this property are listened to.",
@@ -9932,6 +9937,12 @@
9932
9937
  "type": "boolean",
9933
9938
  "default": "false"
9934
9939
  },
9940
+ {
9941
+ "name": "beforeUpdate",
9942
+ "attribute": "before-update-event",
9943
+ "description": "If set to the name of an event, the content of the pb-view will not be replaced\nimmediately upon updates. Instead, an event is emitted, which contains the new content\nin property `root`. An event handler intercepting the event can thus modify the content.\nOnce it is done, it should pass the modified content to the callback function provided\nin the event detail under the name `render`. See the demo for an example.",
9944
+ "type": "string"
9945
+ },
9935
9946
  {
9936
9947
  "name": "subscribe",
9937
9948
  "attribute": "subscribe",
@@ -10183,6 +10194,11 @@
10183
10194
  "type": "boolean",
10184
10195
  "default": "false"
10185
10196
  },
10197
+ {
10198
+ "name": "before-update-event",
10199
+ "description": "If set to the name of an event, the content of the pb-view will not be replaced\nimmediately upon updates. Instead, an event is emitted, which contains the new content\nin property `root`. An event handler intercepting the event can thus modify the content.\nOnce it is done, it should pass the modified content to the callback function provided\nin the event detail under the name `render`. See the demo for an example.",
10200
+ "type": "string"
10201
+ },
10186
10202
  {
10187
10203
  "name": "subscribe",
10188
10204
  "description": "The name of the channel to subscribe to. Only events on a channel corresponding\nto this property are listened to.",
@@ -10355,6 +10371,12 @@
10355
10371
  "type": "boolean",
10356
10372
  "default": "false"
10357
10373
  },
10374
+ {
10375
+ "name": "beforeUpdate",
10376
+ "attribute": "before-update-event",
10377
+ "description": "If set to the name of an event, the content of the pb-view will not be replaced\nimmediately upon updates. Instead, an event is emitted, which contains the new content\nin property `root`. An event handler intercepting the event can thus modify the content.\nOnce it is done, it should pass the modified content to the callback function provided\nin the event detail under the name `render`. See the demo for an example.",
10378
+ "type": "string"
10379
+ },
10358
10380
  {
10359
10381
  "name": "subscribe",
10360
10382
  "attribute": "subscribe",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teipublisher/pb-components",
3
- "version": "1.28.0",
3
+ "version": "1.30.0",
4
4
  "description": "Collection of webcomponents underlying TEI Publisher",
5
5
  "repository": "https://github.com/eeditiones/tei-publisher-components.git",
6
6
  "main": "index.html",
package/pb-elements.json CHANGED
@@ -9743,6 +9743,11 @@
9743
9743
  "type": "boolean",
9744
9744
  "default": "false"
9745
9745
  },
9746
+ {
9747
+ "name": "before-update-event",
9748
+ "description": "If set to the name of an event, the content of the pb-view will not be replaced\nimmediately upon updates. Instead, an event is emitted, which contains the new content\nin property `root`. An event handler intercepting the event can thus modify the content.\nOnce it is done, it should pass the modified content to the callback function provided\nin the event detail under the name `render`. See the demo for an example.",
9749
+ "type": "string"
9750
+ },
9746
9751
  {
9747
9752
  "name": "subscribe",
9748
9753
  "description": "The name of the channel to subscribe to. Only events on a channel corresponding\nto this property are listened to.",
@@ -9932,6 +9937,12 @@
9932
9937
  "type": "boolean",
9933
9938
  "default": "false"
9934
9939
  },
9940
+ {
9941
+ "name": "beforeUpdate",
9942
+ "attribute": "before-update-event",
9943
+ "description": "If set to the name of an event, the content of the pb-view will not be replaced\nimmediately upon updates. Instead, an event is emitted, which contains the new content\nin property `root`. An event handler intercepting the event can thus modify the content.\nOnce it is done, it should pass the modified content to the callback function provided\nin the event detail under the name `render`. See the demo for an example.",
9944
+ "type": "string"
9945
+ },
9935
9946
  {
9936
9947
  "name": "subscribe",
9937
9948
  "attribute": "subscribe",
@@ -10183,6 +10194,11 @@
10183
10194
  "type": "boolean",
10184
10195
  "default": "false"
10185
10196
  },
10197
+ {
10198
+ "name": "before-update-event",
10199
+ "description": "If set to the name of an event, the content of the pb-view will not be replaced\nimmediately upon updates. Instead, an event is emitted, which contains the new content\nin property `root`. An event handler intercepting the event can thus modify the content.\nOnce it is done, it should pass the modified content to the callback function provided\nin the event detail under the name `render`. See the demo for an example.",
10200
+ "type": "string"
10201
+ },
10186
10202
  {
10187
10203
  "name": "subscribe",
10188
10204
  "description": "The name of the channel to subscribe to. Only events on a channel corresponding\nto this property are listened to.",
@@ -10355,6 +10371,12 @@
10355
10371
  "type": "boolean",
10356
10372
  "default": "false"
10357
10373
  },
10374
+ {
10375
+ "name": "beforeUpdate",
10376
+ "attribute": "before-update-event",
10377
+ "description": "If set to the name of an event, the content of the pb-view will not be replaced\nimmediately upon updates. Instead, an event is emitted, which contains the new content\nin property `root`. An event handler intercepting the event can thus modify the content.\nOnce it is done, it should pass the modified content to the callback function provided\nin the event detail under the name `render`. See the demo for an example.",
10378
+ "type": "string"
10379
+ },
10358
10380
  {
10359
10381
  "name": "subscribe",
10360
10382
  "attribute": "subscribe",
@@ -154,7 +154,7 @@ export class PbTableGrid extends pbMixin(LitElement) {
154
154
  Object.assign(this._params, form.serializeForm());
155
155
  }
156
156
  this._params.limit = limit;
157
- this._params.start = page * limit;
157
+ this._params.start = page * limit + 1;
158
158
  this.setParameters(this._params);
159
159
  this.pushHistory('grid', this._params);
160
160
 
@@ -112,12 +112,13 @@ function ancestors(node, selector) {
112
112
  * @param {Node} node the current node
113
113
  * @returns next text node or the current node if none is found
114
114
  */
115
- function nextTextNode(node) {
116
- let next = node.nextSibling;
117
- while (next.hasChildNodes()) {
118
- next = next.firstChild;
115
+ function nextTextNode(context, node) {
116
+ const walker = document.createTreeWalker(context, NodeFilter.SHOW_TEXT);
117
+ walker.currentNode = node;
118
+ if (walker.nextNode()) {
119
+ return walker.currentNode;
119
120
  }
120
- return next.nodeType === Node.TEXT_NODE ? next : node;
121
+ return node;
121
122
  }
122
123
 
123
124
  /**
@@ -433,12 +434,16 @@ class PbViewAnnotate extends PbView {
433
434
 
434
435
  console.log('<pb-view-annotate> Range before adjust: %o %o', startPoint, endPoint);
435
436
  if (startPoint[1] === startPoint[0].textContent.length) {
436
- const nextNode = nextTextNode(startPoint[0]);
437
+ // try to find the next text node
438
+ const nextNode = nextTextNode(context, startPoint[0]);
437
439
  // next text node is the endpoint: start there
438
440
  if (nextNode === endPoint[0]) {
439
441
  range.setStart(nextNode, 0);
442
+ // adjust startPoint for check below
443
+ startPoint[0] = nextNode;
444
+ startPoint[1] = 0;
440
445
  } else {
441
- range.setStartBefore(startPoint[0].nextSibling);
446
+ range.setStartBefore(startPoint[0].nextSibling || nextNode);
442
447
  }
443
448
  } else if (startPoint[0] !== endPoint[0] && startPoint[1] === 0) {
444
449
  range.setStartBefore(extendRange(startPoint[0], context));
@@ -980,6 +985,7 @@ class PbViewAnnotate extends PbView {
980
985
  lightness: [30, 60]
981
986
  }));
982
987
  });
988
+ this.emitTo('pb-annotation-colors', { colors: this._annotationColors });
983
989
  }
984
990
 
985
991
  _checkAnnotationColor(type) {
@@ -992,6 +998,7 @@ class PbViewAnnotate extends PbView {
992
998
  lightness: [30, 60]
993
999
  }));
994
1000
  this._annotationStyles();
1001
+ this.emitTo('pb-annotation-colors', { colors: this._annotationColors });
995
1002
  }
996
1003
 
997
1004
  _annotationStyles() {
package/src/pb-view.js CHANGED
@@ -272,6 +272,17 @@ export class PbView extends pbMixin(LitElement) {
272
272
  type: Boolean,
273
273
  attribute: 'disable-history'
274
274
  },
275
+ /**
276
+ * If set to the name of an event, the content of the pb-view will not be replaced
277
+ * immediately upon updates. Instead, an event is emitted, which contains the new content
278
+ * in property `root`. An event handler intercepting the event can thus modify the content.
279
+ * Once it is done, it should pass the modified content to the callback function provided
280
+ * in the event detail under the name `render`. See the demo for an example.
281
+ */
282
+ beforeUpdate: {
283
+ type: String,
284
+ attribute: 'before-update-event'
285
+ },
275
286
  _features: {
276
287
  type: Object
277
288
  },
@@ -312,6 +323,7 @@ export class PbView extends pbMixin(LitElement) {
312
323
  this.highlight = false;
313
324
  this.infiniteScrollMax = 10;
314
325
  this.disableHistory = false;
326
+ this.beforeUpdate = null;
315
327
  this._features = {};
316
328
  this._selector = new Map();
317
329
  this._chunks = [];
@@ -496,6 +508,15 @@ export class PbView extends pbMixin(LitElement) {
496
508
 
497
509
  _refresh(ev) {
498
510
  if (ev && ev.detail) {
511
+ if (ev.detail.hash && !(ev.detail.id || ev.detail.path || ev.detail.odd || ev.detail.view || ev.detail.position)) {
512
+ // if only the scroll target has changed: scroll to the element without reloading
513
+ this._scrollTarget = ev.detail.hash;
514
+ const target = this.shadowRoot.getElementById(this._scrollTarget);
515
+ if (target) {
516
+ setTimeout(() => target.scrollIntoView());
517
+ }
518
+ return;
519
+ }
499
520
  if (ev.detail.path) {
500
521
  const doc = this.getDocument();
501
522
  doc.path = ev.detail.path;
@@ -641,7 +662,7 @@ export class PbView extends pbMixin(LitElement) {
641
662
  if (target) {
642
663
  setTimeout(() => {
643
664
  target.scrollIntoView();
644
- });
665
+ }, 100);
645
666
  }
646
667
  this._scrollTarget = null;
647
668
  });
@@ -687,6 +708,22 @@ export class PbView extends pbMixin(LitElement) {
687
708
  fragment.appendChild(elem);
688
709
  elem.innerHTML = resp.content;
689
710
 
711
+ // if before-update-event is set, we do not replace the content immediately,
712
+ // but emit an event
713
+ if (this.beforeUpdate) {
714
+ this.emitTo(this.beforeUpdate, {
715
+ data: resp,
716
+ root: elem,
717
+ render: (content) => {
718
+ this._doReplaceContent(content, resp, direction);
719
+ }
720
+ });
721
+ } else {
722
+ this._doReplaceContent(elem, resp, direction);
723
+ }
724
+ }
725
+
726
+ _doReplaceContent(elem, resp, direction) {
690
727
  if (this.columnSeparator) {
691
728
  this._replaceColumns(elem);
692
729
  this._loading = false;