@teipublisher/pb-components 3.5.0 → 3.6.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.
@@ -4723,7 +4723,7 @@
4723
4723
  },
4724
4724
  {
4725
4725
  "name": "key",
4726
- "description": "The key to which this element is connected.",
4726
+ "description": "One or more keys (space or comma separated) to which this element is connected.",
4727
4727
  "type": "string"
4728
4728
  },
4729
4729
  {
@@ -4825,7 +4825,7 @@
4825
4825
  {
4826
4826
  "name": "key",
4827
4827
  "attribute": "key",
4828
- "description": "The key to which this element is connected.",
4828
+ "description": "One or more keys (space or comma separated) to which this element is connected.",
4829
4829
  "type": "string"
4830
4830
  },
4831
4831
  {
@@ -5198,11 +5198,11 @@
5198
5198
  {
5199
5199
  "name": "pb-highlight",
5200
5200
  "path": "./src/pb-highlight.js",
5201
- "description": "Link elements to each other: when a trigger action occurs on one element,\nthe others are highlighted by changing their background color. Which elements\nare linked is determined by the `key` property: elements with the same key\nare linked. The trigger action is configured via the `trigger` property and\nsends a `pb-highlight-on` event. Other elements with the same key react to this event.\n\n`pb-highlight` should be output for relevant elements via ODD processing model.",
5201
+ "description": "Link elements to each other: when a trigger action occurs on one element,\nthe others are highlighted by changing their background color. Which elements\nare linked is determined by the `key` property: elements with the same key\nare linked. Multiple keys (space or comma separated) may be specified; in that\ncase the emitted `pb-highlight-on` event passes an array of ids and receivers\nhighlight when any of their keys matches. The trigger action is configured via the `trigger` property and\nsends a `pb-highlight-on` event. Other elements with the same key react to this event.\n\n`pb-highlight` should be output for relevant elements via ODD processing model.",
5202
5202
  "attributes": [
5203
5203
  {
5204
5204
  "name": "key",
5205
- "description": "The key to which this element is connected.",
5205
+ "description": "One or more keys (space or comma separated) to which this element is connected.",
5206
5206
  "type": "string"
5207
5207
  },
5208
5208
  {
@@ -5264,7 +5264,7 @@
5264
5264
  {
5265
5265
  "name": "key",
5266
5266
  "attribute": "key",
5267
- "description": "The key to which this element is connected.",
5267
+ "description": "One or more keys (space or comma separated) to which this element is connected.",
5268
5268
  "type": "string"
5269
5269
  },
5270
5270
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teipublisher/pb-components",
3
- "version": "3.5.0",
3
+ "version": "3.6.1",
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
@@ -4723,7 +4723,7 @@
4723
4723
  },
4724
4724
  {
4725
4725
  "name": "key",
4726
- "description": "The key to which this element is connected.",
4726
+ "description": "One or more keys (space or comma separated) to which this element is connected.",
4727
4727
  "type": "string"
4728
4728
  },
4729
4729
  {
@@ -4825,7 +4825,7 @@
4825
4825
  {
4826
4826
  "name": "key",
4827
4827
  "attribute": "key",
4828
- "description": "The key to which this element is connected.",
4828
+ "description": "One or more keys (space or comma separated) to which this element is connected.",
4829
4829
  "type": "string"
4830
4830
  },
4831
4831
  {
@@ -5198,11 +5198,11 @@
5198
5198
  {
5199
5199
  "name": "pb-highlight",
5200
5200
  "path": "./src/pb-highlight.js",
5201
- "description": "Link elements to each other: when a trigger action occurs on one element,\nthe others are highlighted by changing their background color. Which elements\nare linked is determined by the `key` property: elements with the same key\nare linked. The trigger action is configured via the `trigger` property and\nsends a `pb-highlight-on` event. Other elements with the same key react to this event.\n\n`pb-highlight` should be output for relevant elements via ODD processing model.",
5201
+ "description": "Link elements to each other: when a trigger action occurs on one element,\nthe others are highlighted by changing their background color. Which elements\nare linked is determined by the `key` property: elements with the same key\nare linked. Multiple keys (space or comma separated) may be specified; in that\ncase the emitted `pb-highlight-on` event passes an array of ids and receivers\nhighlight when any of their keys matches. The trigger action is configured via the `trigger` property and\nsends a `pb-highlight-on` event. Other elements with the same key react to this event.\n\n`pb-highlight` should be output for relevant elements via ODD processing model.",
5202
5202
  "attributes": [
5203
5203
  {
5204
5204
  "name": "key",
5205
- "description": "The key to which this element is connected.",
5205
+ "description": "One or more keys (space or comma separated) to which this element is connected.",
5206
5206
  "type": "string"
5207
5207
  },
5208
5208
  {
@@ -5264,7 +5264,7 @@
5264
5264
  {
5265
5265
  "name": "key",
5266
5266
  "attribute": "key",
5267
- "description": "The key to which this element is connected.",
5267
+ "description": "One or more keys (space or comma separated) to which this element is connected.",
5268
5268
  "type": "string"
5269
5269
  },
5270
5270
  {
@@ -5,7 +5,9 @@ import { pbMixin } from './pb-mixin';
5
5
  * Link elements to each other: when a trigger action occurs on one element,
6
6
  * the others are highlighted by changing their background color. Which elements
7
7
  * are linked is determined by the `key` property: elements with the same key
8
- * are linked. The trigger action is configured via the `trigger` property and
8
+ * are linked. Multiple keys (space or comma separated) may be specified; in that
9
+ * case the emitted `pb-highlight-on` event passes an array of ids and receivers
10
+ * highlight when any of their keys matches. The trigger action is configured via the `trigger` property and
9
11
  * sends a `pb-highlight-on` event. Other elements with the same key react to this event.
10
12
  *
11
13
  * `pb-highlight` should be output for relevant elements via ODD processing model.
@@ -16,7 +18,7 @@ import { pbMixin } from './pb-mixin';
16
18
  * @fires pb-highlight-off - Fires removal of all highlights that might have existed before
17
19
  * @fires pb-highlight-on - Fires highlight event with a key passed to which other pb-highlight elements with the same key will react
18
20
  * @fires pb-highlight-off - When received, triggers removal of a highlight that might have been on for this element before
19
- * @fires pb-highlight-on - When received, switches the highlight on if the same key was received as the current element has
21
+ * @fires pb-highlight-on - When received, switches the highlight on if any received key matches one of this element's keys
20
22
  * @prop {"click" | "mouseenter"} trigger - Defines one or more actions (space separated) which should cause
21
23
  * the highlight to show. Default is `mouseenter`. If `click` is among the triggers, matching elements scroll into view.
22
24
  * @cssprop --pb-highlight-color - Background color to highlight an element
@@ -26,7 +28,7 @@ export class PbHighlight extends pbMixin(LitElement) {
26
28
  return {
27
29
  ...super.properties,
28
30
  /**
29
- * The key to which this element is connected.
31
+ * One or more keys (space or comma separated) to which this element is connected.
30
32
  */
31
33
  key: {
32
34
  type: String,
@@ -74,6 +76,26 @@ export class PbHighlight extends pbMixin(LitElement) {
74
76
  return (this.trigger || 'mouseenter').trim().split(/\s+/);
75
77
  }
76
78
 
79
+ _getKeys() {
80
+ return (this.key || '').trim().split(/[\s,]+/).filter(Boolean);
81
+ }
82
+
83
+ _getEventId() {
84
+ const keys = this._getKeys();
85
+ return keys.length > 1 ? keys : keys[0] || null;
86
+ }
87
+
88
+ _matchesKey(eventId) {
89
+ const keys = this._getKeys();
90
+ if (!keys.length || eventId == null) {
91
+ return false;
92
+ }
93
+ if (Array.isArray(eventId)) {
94
+ return keys.some(key => eventId.includes(key));
95
+ }
96
+ return keys.includes(eventId);
97
+ }
98
+
77
99
  _isClickable() {
78
100
  return this._getTriggers().includes('click');
79
101
  }
@@ -95,11 +117,12 @@ export class PbHighlight extends pbMixin(LitElement) {
95
117
  this.emitTo('pb-highlight-off', {
96
118
  source: this,
97
119
  });
120
+ const id = this._getEventId();
98
121
  if (this.highlightSelf) {
99
- this._highlightOn({ detail: { id: this.key } });
122
+ this._highlightOn({ detail: { id } });
100
123
  }
101
124
  this.emitTo('pb-highlight-on', {
102
- id: this.key,
125
+ id,
103
126
  source: this,
104
127
  scroll: this.scroll || this._isClickable(),
105
128
  });
@@ -157,7 +180,7 @@ export class PbHighlight extends pbMixin(LitElement) {
157
180
  }
158
181
 
159
182
  _highlightOn(ev) {
160
- if (ev.detail.source != this && ev.detail.id === this.key) {
183
+ if (ev.detail.source != this && this._matchesKey(ev.detail.id)) {
161
184
  this._className = 'highlight-on';
162
185
  if (ev.detail.scroll && this.disabled == false) {
163
186
  this.scrollIntoView({ block: 'center', behavior: 'smooth' });
@@ -180,7 +203,7 @@ export class PbHighlight extends pbMixin(LitElement) {
180
203
  * Fired when a trigger action occurs on the element
181
204
  *
182
205
  * @event pb-highlight-on
183
- * @param {String} id key
206
+ * @param {String|Array<String>} id key or keys
184
207
  * @param {Object} source this element
185
208
  * @param {Boolean} scroll should target scroll to highlighted position
186
209
  */
package/src/pb-view.js CHANGED
@@ -832,18 +832,31 @@ export class PbView extends themableMixin(pbMixin(LitElement)) {
832
832
  this.emitTo('pb-end-update', null);
833
833
  }
834
834
 
835
+ /**
836
+ * Move markup from a server-rendered light-DOM wrapper into a target container.
837
+ *
838
+ * Re-parses the HTML string (same as the dynamic `innerHTML = resp.content`
839
+ * path) so nested custom elements such as `pb-popover` and `pb-highlight`
840
+ * upgrade when the target is connected to the shadow tree. Moving live nodes
841
+ * with `appendChild` leaves those elements inert: they may have been parsed
842
+ * before the component bundle loaded, or their lifecycle already ran in the
843
+ * wrong document root.
844
+ *
845
+ * @param {HTMLElement} container destination element inside the shadow content
846
+ * @param {HTMLElement} ssrWrapper `[data-pb-ssr]` or `[data-pb-ssr-footnotes]`
847
+ */
848
+ _adoptSsrMarkup(container, ssrWrapper) {
849
+ container.innerHTML = ssrWrapper.innerHTML;
850
+ ssrWrapper.remove();
851
+ }
852
+
835
853
  _replaceContent(resp, direction) {
836
854
  const fragment = document.createDocumentFragment();
837
855
  const elem = document.createElement('div');
838
856
  // elem.style.opacity = 0; //hide it - animation has to make sure to blend it in
839
857
  fragment.appendChild(elem);
840
858
  if (this._ssrContent && (!resp.content || resp.content.length === 0)) {
841
- // Adopt the server-rendered content from light DOM (SSR) rather than
842
- // re-rendering it: move its children into the shadow content container.
843
- while (this._ssrContent.firstChild) {
844
- elem.appendChild(this._ssrContent.firstChild);
845
- }
846
- this._ssrContent.remove();
859
+ this._adoptSsrMarkup(elem, this._ssrContent);
847
860
  this._ssrContent = null;
848
861
  } else {
849
862
  elem.innerHTML = resp.content;
@@ -910,10 +923,7 @@ export class PbView extends themableMixin(pbMixin(LitElement)) {
910
923
  if (this.appendFootnotes) {
911
924
  const footnotes = document.createElement('div');
912
925
  if (this._ssrFootnotes) {
913
- // Adopt the server-rendered footnotes from light DOM (SSR).
914
- while (this._ssrFootnotes.firstChild) {
915
- footnotes.appendChild(this._ssrFootnotes.firstChild);
916
- }
926
+ this._adoptSsrMarkup(footnotes, this._ssrFootnotes);
917
927
  } else if (resp.footnotes) {
918
928
  footnotes.innerHTML = resp.footnotes;
919
929
  }