lucos_search_component 0.0.9 → 0.0.11

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.
@@ -1 +1 @@
1
- import '../index.js';
1
+ import '../dist/index.js';
@@ -3,16 +3,16 @@
3
3
  <title>Hello World Search Component</title>
4
4
  </head>
5
5
  <body>
6
- <label for="search1">Everything:</label><select is="lucos-search" data-api-key="${KEY_LUCOS_ARACHNE}" id="search1"></select>
7
- <label for="search2">No Tracks:</label><select is="lucos-search" data-api-key="${KEY_LUCOS_ARACHNE}" id="search2" data-exclude_types="Track"></select>
8
- <label for="search3">Only Cites and Rivers:</label><select is="lucos-search" data-api-key="${KEY_LUCOS_ARACHNE}" id="search3" data-types="City,River"></select>
9
- <label for="search4">Load with existing items:</label><select is="lucos-search" data-api-key="${KEY_LUCOS_ARACHNE}" id="search4" multiple>
6
+ <label for="search1">Everything:</label><span is="lucos-search" data-api-key="${KEY_LUCOS_ARACHNE}"><select id="search1"></select></span>
7
+ <label for="search2">No Tracks:</label><span is="lucos-search" data-api-key="${KEY_LUCOS_ARACHNE}" data-exclude_types="Track"><select id="search2"></select></span>
8
+ <label for="search3">Only Cites and Rivers:</label><span is="lucos-search" data-api-key="${KEY_LUCOS_ARACHNE}" data-types="City,River"><select id="search3"></select></span>
9
+ <label for="search4">Load with existing items:</label><span is="lucos-search" data-api-key="${KEY_LUCOS_ARACHNE}"><select id="search4" multiple>
10
10
  <option id="https://contacts.l42.eu/people/2" selected>https://contacts.l42.eu/people/2</option>
11
11
  <option id="https://eolas.l42.eu/metadata/place/2/" selected>https://eolas.l42.eu/metadata/place/2/</option>
12
12
  <option id="https://media-metadata.l42.eu/tracks/13713" selected>https://media-metadata.l42.eu/tracks/13713</option>
13
- </select>
13
+ </select></span>
14
14
  <label for="search5">More than 10:</label>
15
- <select is="lucos-search" id="search5" data-api-key="${KEY_LUCOS_ARACHNE}" data-exclude_types="Track" multiple>
15
+ <span is="lucos-search" data-api-key="${KEY_LUCOS_ARACHNE}" data-exclude_types="Track"><select id="search5" multiple>
16
16
  <option value="https://eolas.l42.eu/metadata/place/125/" selected>https://eolas.l42.eu/metadata/place/125/</option>
17
17
  <option value="https://eolas.l42.eu/metadata/place/126/" selected>https://eolas.l42.eu/metadata/place/126/</option>
18
18
  <option value="https://eolas.l42.eu/metadata/place/28/" selected>https://eolas.l42.eu/metadata/place/28/</option>
@@ -26,7 +26,7 @@
26
26
  <option value="https://eolas.l42.eu/metadata/place/315/" selected>https://eolas.l42.eu/metadata/place/315/</option>
27
27
  <option value="https://eolas.l42.eu/metadata/place/316/" selected>https://eolas.l42.eu/metadata/place/316/</option>
28
28
  <option value="https://eolas.l42.eu/metadata/place/317/" selected>https://eolas.l42.eu/metadata/place/317/</option>
29
- </select>
29
+ </select></span>
30
30
  <script src="./built.js"></script>
31
31
  </body>
32
32
  </html>
@@ -7,13 +7,5 @@ export default {
7
7
  filename: 'built.js',
8
8
  path: new URL('.', import.meta.url).pathname,
9
9
  },
10
- module: {
11
- rules: [
12
- {
13
- test: /\.css$/i,
14
- use: ["css-loader"],
15
- },
16
- ],
17
- },
18
10
  mode: 'development',
19
11
  };
package/index.js CHANGED
@@ -1,13 +1,14 @@
1
1
  import TomSelect from 'tom-select';
2
2
  import tomSelectStylesheet from 'tom-select/dist/css/tom-select.default.css';
3
3
 
4
- class LucosSearchComponent extends HTMLSelectElement {
4
+ class LucosSearchComponent extends HTMLSpanElement {
5
5
  static get observedAttributes() {
6
6
  return ['data-api-key','data-types','data-exclude-types'];
7
7
  }
8
8
  constructor() {
9
9
  super();
10
10
  const component = this;
11
+ const shadow = component.attachShadow({mode: 'open'});
11
12
 
12
13
  const mainStyle = document.createElement('style');
13
14
  mainStyle.textContent = `
@@ -86,18 +87,21 @@ class LucosSearchComponent extends HTMLSelectElement {
86
87
  padding: 2px 6px;
87
88
  }
88
89
  `;
89
- component.appendChild(mainStyle);
90
+ shadow.appendChild(mainStyle);
90
91
 
91
92
  // If webpack is configured with `css-loader` but not `style-loader`, include the tom-select stylesheet here
92
93
  // (If `style-loader` is being used, the tom-select stylesheet will be handled by that)
93
94
  if (tomSelectStylesheet) {
94
95
  const tomStyle = document.createElement('style');
95
- tomStyle.textContent = tomSelectStylesheet[0][1];
96
- component.appendChild(tomStyle);
96
+ tomStyle.textContent = tomSelectStylesheet;
97
+ shadow.appendChild(tomStyle);
97
98
  }
98
99
 
99
- component.setAttribute("multiple", "multiple");
100
- new TomSelect(component, {
100
+ const selector = component.querySelector("select");
101
+ if (!selector) throw new Error("Can't find select element in lucos-search");
102
+ shadow.append(selector);
103
+ selector.setAttribute("multiple", "multiple");
104
+ new TomSelect(selector, {
101
105
  valueField: 'id',
102
106
  labelField: 'pref_label',
103
107
  searchField: [],
@@ -173,4 +177,4 @@ class LucosSearchComponent extends HTMLSelectElement {
173
177
  return results;
174
178
  }
175
179
  }
176
- customElements.define('lucos-search', LucosSearchComponent, { extends: "select" });
180
+ customElements.define('lucos-search', LucosSearchComponent, { extends: "span" });
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "lucos_search_component",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "Web Component for searching lucOS data",
5
5
  "type": "module",
6
- "main": "index.js",
6
+ "main": "dist/index.js",
7
7
  "scripts": {
8
8
  "test": "echo \"Error: no test specified\" && exit 1",
9
- "example": "source .env && KEY_LUCOS_ARACHNE=$KEY_LUCOS_ARACHNE envsubst < example/index.html > example/built.html && webpack -c example/webpack.config.js && open example/built.html"
9
+ "example": "source .env && KEY_LUCOS_ARACHNE=$KEY_LUCOS_ARACHNE envsubst < example/index.html > example/built.html && npm run build && webpack -c example/webpack.config.js && open example/built.html",
10
+ "build": "rollup -c"
10
11
  },
11
12
  "repository": {
12
13
  "type": "git",
@@ -22,10 +23,10 @@
22
23
  },
23
24
  "homepage": "https://github.com/lucas42/lucos_search_component#readme",
24
25
  "devDependencies": {
25
- "webpack-cli": "^6.0.1"
26
- },
27
- "dependencies": {
26
+ "@rollup/plugin-node-resolve": "^16.0.1",
27
+ "rollup": "^4.52.4",
28
+ "rollup-plugin-import-css": "^4.0.2",
28
29
  "tom-select": "^2.4.3",
29
- "css-loader": "^7.1.2"
30
+ "webpack-cli": "^6.0.1"
30
31
  }
31
32
  }
@@ -0,0 +1,14 @@
1
+ import resolve from '@rollup/plugin-node-resolve';
2
+ import css from "rollup-plugin-import-css";
3
+
4
+ export default {
5
+ input: 'index.js',
6
+ output: {
7
+ file: 'dist/index.js',
8
+ format: 'esm'
9
+ },
10
+ plugins: [
11
+ resolve(),
12
+ css(),
13
+ ],
14
+ };