lucos_search_component 4.0.1 → 4.0.2

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.
package/CLAUDE.md ADDED
@@ -0,0 +1,7 @@
1
+ # lucos_search_component
2
+
3
+ ## Public interface changes
4
+
5
+ Any change to the public interface of this component (new attributes, modified attribute behaviour, removed attributes) must be accompanied by a new or updated example in `example/index.html`.
6
+
7
+ For **breaking changes** (removing or renaming an attribute, changing the expected format of an existing attribute), also review all existing examples in `example/index.html` to check whether any need updating or removing entirely.
package/dist/index.js CHANGED
@@ -5696,12 +5696,13 @@ var categoryColoursCSS = "/* Generated by scripts/generate-colours.js — do not
5696
5696
  /**
5697
5697
  * Builds a Typesense filter_by expression from the search component's filter attributes.
5698
5698
  *
5699
- * @param {string|null} types - Value of data-types attribute (e.g. "Person,Place")
5700
- * @param {string|null} excludeTypes - Value of data-exclude-types attribute (e.g. "Language")
5701
- * @param {string|null} isContact - Value of data-is-contact attribute ("true" or "false")
5699
+ * @param {string|null} types - Value of data-types attribute (e.g. "Person,Place")
5700
+ * @param {string|null} excludeTypes - Value of data-exclude-types attribute (e.g. "Language")
5701
+ * @param {string|null} isContact - Value of data-is-contact attribute ("true" or "false")
5702
+ * @param {string|null} allowedOrigins - Value of data-allowed-origins attribute (e.g. "https://eolas.l42.eu")
5702
5703
  * @returns {string|null} filter expression, or null if no filters apply
5703
5704
  */
5704
- function buildFilterBy(types, excludeTypes, isContact) {
5705
+ function buildFilterBy(types, excludeTypes, isContact, allowedOrigins) {
5705
5706
  const parts = [];
5706
5707
  if (types) {
5707
5708
  parts.push(`types:=[${types}]`);
@@ -5713,6 +5714,9 @@ function buildFilterBy(types, excludeTypes, isContact) {
5713
5714
  } else if (isContact === 'false') {
5714
5715
  parts.push('is_contact:=false');
5715
5716
  }
5717
+ if (allowedOrigins) {
5718
+ parts.push(`origin:=[${allowedOrigins}]`);
5719
+ }
5716
5720
  return parts.length > 0 ? parts.join(' && ') : null;
5717
5721
  }
5718
5722
 
@@ -5748,7 +5752,7 @@ function buildFormDataEntries(name, values, optionMap) {
5748
5752
 
5749
5753
  class LucosSearchComponent extends HTMLSpanElement {
5750
5754
  static get observedAttributes() {
5751
- return ['data-api-key','data-types','data-exclude_types','data-is-contact','data-label-override-zxx','data-common','data-preload','data-create'];
5755
+ return ['data-api-key','data-types','data-exclude_types','data-is-contact','data-label-override-zxx','data-common','data-preload','data-create','data-allowed-origins'];
5752
5756
  }
5753
5757
  constructor() {
5754
5758
  super();
@@ -5934,6 +5938,7 @@ class LucosSearchComponent extends HTMLSpanElement {
5934
5938
  component.getAttribute("data-types"),
5935
5939
  component.getAttribute("data-exclude_types"),
5936
5940
  component.getAttribute("data-is-contact"),
5941
+ component.getAttribute("data-allowed-origins"),
5937
5942
  );
5938
5943
  if (filterBy) queryParams.set("filter_by", filterBy);
5939
5944
  try {
@@ -6012,6 +6017,7 @@ class LucosSearchComponent extends HTMLSpanElement {
6012
6017
  component.getAttribute("data-types"),
6013
6018
  component.getAttribute("data-exclude_types"),
6014
6019
  component.getAttribute("data-is-contact"),
6020
+ component.getAttribute("data-allowed-origins"),
6015
6021
  );
6016
6022
  // per_page: 250 acts as an upper bound — data-preload is intended for finite datasets
6017
6023
  const preloadParams = new URLSearchParams({ q: '*', per_page: 250 });
@@ -19,6 +19,7 @@
19
19
  <label for="search6">Languages with label override for zxx:</label><span is="lucos-search" data-api-key="${KEY_LUCOS_ARACHNE}" data-types="Language" data-label-override-zxx="No Language"><select id="search6"></select></span>
20
20
  <label for="search7">Languages with zxx pre-selected:</label><span is="lucos-search" data-api-key="${KEY_LUCOS_ARACHNE}" data-types="Language" data-label-override-zxx="No Language"><select id="search7" multiple><option selected>https://eolas.l42.eu/metadata/language/zxx/</option></select></span>
21
21
  <label for="search11">Languages with label override, common and preload:</label><span is="lucos-search" data-api-key="${KEY_LUCOS_ARACHNE}" data-types="Language" data-label-override-zxx="Instrumental / No Language" data-common="https://eolas.l42.eu/metadata/language/en/,https://eolas.l42.eu/metadata/language/ga/,https://eolas.l42.eu/metadata/language/zxx/" data-preload><select id="search11" multiple ></select></span>
22
+ <label for="search_origins">Eolas only (data-allowed-origins):</label><span is="lucos-search" data-api-key="${KEY_LUCOS_ARACHNE}" data-allowed-origins="https://eolas.l42.eu"><select id="search_origins"></select></span>
22
23
  <label for="search5">More than 10:</label>
23
24
  <span is="lucos-search" data-api-key="${KEY_LUCOS_ARACHNE}" data-exclude_types="Track"><select id="search5" multiple>
24
25
  <option selected>https://eolas.l42.eu/metadata/place/125/</option>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lucos_search_component",
3
- "version": "4.0.1",
3
+ "version": "4.0.2",
4
4
  "description": "Web Components for searching lucOS data",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -31,3 +31,23 @@ test('data-exclude-types produces types:!= filter', () => {
31
31
  const result = buildFilterBy(null, 'Track', null);
32
32
  assert.equal(result, 'types:!=[Track]');
33
33
  });
34
+
35
+ test('data-allowed-origins produces origin:= filter', () => {
36
+ const result = buildFilterBy(null, null, null, 'https://eolas.l42.eu');
37
+ assert.equal(result, 'origin:=[https://eolas.l42.eu]');
38
+ });
39
+
40
+ test('data-allowed-origins with multiple comma-separated origins', () => {
41
+ const result = buildFilterBy(null, null, null, 'https://eolas.l42.eu,https://contacts.l42.eu');
42
+ assert.equal(result, 'origin:=[https://eolas.l42.eu,https://contacts.l42.eu]');
43
+ });
44
+
45
+ test('data-allowed-origins combines with data-types', () => {
46
+ const result = buildFilterBy('Person', null, null, 'https://eolas.l42.eu');
47
+ assert.equal(result, 'types:=[Person] && origin:=[https://eolas.l42.eu]');
48
+ });
49
+
50
+ test('absent data-allowed-origins produces no origin filter', () => {
51
+ const result = buildFilterBy('Person', null, null, null);
52
+ assert.equal(result, 'types:=[Person]');
53
+ });
@@ -1,12 +1,13 @@
1
1
  /**
2
2
  * Builds a Typesense filter_by expression from the search component's filter attributes.
3
3
  *
4
- * @param {string|null} types - Value of data-types attribute (e.g. "Person,Place")
5
- * @param {string|null} excludeTypes - Value of data-exclude-types attribute (e.g. "Language")
6
- * @param {string|null} isContact - Value of data-is-contact attribute ("true" or "false")
4
+ * @param {string|null} types - Value of data-types attribute (e.g. "Person,Place")
5
+ * @param {string|null} excludeTypes - Value of data-exclude-types attribute (e.g. "Language")
6
+ * @param {string|null} isContact - Value of data-is-contact attribute ("true" or "false")
7
+ * @param {string|null} allowedOrigins - Value of data-allowed-origins attribute (e.g. "https://eolas.l42.eu")
7
8
  * @returns {string|null} filter expression, or null if no filters apply
8
9
  */
9
- export function buildFilterBy(types, excludeTypes, isContact) {
10
+ export function buildFilterBy(types, excludeTypes, isContact, allowedOrigins) {
10
11
  const parts = [];
11
12
  if (types) {
12
13
  parts.push(`types:=[${types}]`);
@@ -18,5 +19,8 @@ export function buildFilterBy(types, excludeTypes, isContact) {
18
19
  } else if (isContact === 'false') {
19
20
  parts.push('is_contact:=false');
20
21
  }
22
+ if (allowedOrigins) {
23
+ parts.push(`origin:=[${allowedOrigins}]`);
24
+ }
21
25
  return parts.length > 0 ? parts.join(' && ') : null;
22
26
  }
@@ -6,7 +6,7 @@ import { buildFormDataEntries } from './form-serialise.js';
6
6
 
7
7
  class LucosSearchComponent extends HTMLSpanElement {
8
8
  static get observedAttributes() {
9
- return ['data-api-key','data-types','data-exclude_types','data-is-contact','data-label-override-zxx','data-common','data-preload','data-create'];
9
+ return ['data-api-key','data-types','data-exclude_types','data-is-contact','data-label-override-zxx','data-common','data-preload','data-create','data-allowed-origins'];
10
10
  }
11
11
  constructor() {
12
12
  super();
@@ -192,6 +192,7 @@ class LucosSearchComponent extends HTMLSpanElement {
192
192
  component.getAttribute("data-types"),
193
193
  component.getAttribute("data-exclude_types"),
194
194
  component.getAttribute("data-is-contact"),
195
+ component.getAttribute("data-allowed-origins"),
195
196
  );
196
197
  if (filterBy) queryParams.set("filter_by", filterBy);
197
198
  try {
@@ -270,6 +271,7 @@ class LucosSearchComponent extends HTMLSpanElement {
270
271
  component.getAttribute("data-types"),
271
272
  component.getAttribute("data-exclude_types"),
272
273
  component.getAttribute("data-is-contact"),
274
+ component.getAttribute("data-allowed-origins"),
273
275
  );
274
276
  // per_page: 250 acts as an upper bound — data-preload is intended for finite datasets
275
277
  const preloadParams = new URLSearchParams({ q: '*', per_page: 250 });