@teipublisher/pb-components 3.5.0 → 3.6.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.
@@ -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.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
@@ -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
  */