lucos_search_component 0.0.12 → 0.0.14
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/dist/index.js +55 -11
- package/index.js +55 -11
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5608,6 +5608,12 @@ class LucosSearchComponent extends HTMLSpanElement {
|
|
|
5608
5608
|
const component = this;
|
|
5609
5609
|
const shadow = component.attachShadow({mode: 'open'});
|
|
5610
5610
|
|
|
5611
|
+
{
|
|
5612
|
+
const tomStyle = document.createElement('style');
|
|
5613
|
+
tomStyle.textContent = tomSelectStylesheet;
|
|
5614
|
+
shadow.appendChild(tomStyle);
|
|
5615
|
+
}
|
|
5616
|
+
|
|
5611
5617
|
const mainStyle = document.createElement('style');
|
|
5612
5618
|
mainStyle.textContent = `
|
|
5613
5619
|
.lozenge {
|
|
@@ -5677,6 +5683,22 @@ class LucosSearchComponent extends HTMLSpanElement {
|
|
|
5677
5683
|
--lozenge-border: #674800;
|
|
5678
5684
|
--lozenge-text: #352005;
|
|
5679
5685
|
}
|
|
5686
|
+
.lozenge[data-type="Historical Event"] {
|
|
5687
|
+
--lozenge-background: #740909;
|
|
5688
|
+
--lozenge-border: #470202;
|
|
5689
|
+
}
|
|
5690
|
+
.lozenge[data-type="Number"] {
|
|
5691
|
+
--lozenge-background: #0000ff;
|
|
5692
|
+
--lozenge-border: #000083;
|
|
5693
|
+
}
|
|
5694
|
+
/** Temporal Types **/
|
|
5695
|
+
.lozenge[data-type="Calendar"], .lozenge[data-type="Festival"], .lozenge[data-type="Month of Year"], .lozenge[data-type="Day of Week"] {
|
|
5696
|
+
--lozenge-background: #fffc33;
|
|
5697
|
+
--lozenge-border: #7f7e00;
|
|
5698
|
+
--lozenge-text: #0f0f00;
|
|
5699
|
+
}
|
|
5700
|
+
|
|
5701
|
+
|
|
5680
5702
|
.lozenge.active {
|
|
5681
5703
|
--lozenge-border: #b00;
|
|
5682
5704
|
}
|
|
@@ -5684,25 +5706,26 @@ class LucosSearchComponent extends HTMLSpanElement {
|
|
|
5684
5706
|
margin: 0 3px;
|
|
5685
5707
|
padding: 2px 6px;
|
|
5686
5708
|
}
|
|
5709
|
+
.ts-dropdown {
|
|
5710
|
+
margin: 0;
|
|
5711
|
+
}
|
|
5712
|
+
.lozenge a {
|
|
5713
|
+
color: inherit;
|
|
5714
|
+
text-decoration: none;
|
|
5715
|
+
}
|
|
5687
5716
|
`;
|
|
5688
5717
|
shadow.appendChild(mainStyle);
|
|
5689
5718
|
|
|
5690
|
-
// If webpack is configured with `css-loader` but not `style-loader`, include the tom-select stylesheet here
|
|
5691
|
-
// (If `style-loader` is being used, the tom-select stylesheet will be handled by that)
|
|
5692
|
-
{
|
|
5693
|
-
const tomStyle = document.createElement('style');
|
|
5694
|
-
tomStyle.textContent = tomSelectStylesheet;
|
|
5695
|
-
shadow.appendChild(tomStyle);
|
|
5696
|
-
}
|
|
5697
5719
|
|
|
5698
5720
|
const selector = component.querySelector("select");
|
|
5699
5721
|
if (!selector) throw new Error("Can't find select element in lucos-search");
|
|
5700
|
-
shadow.append(selector);
|
|
5701
5722
|
selector.setAttribute("multiple", "multiple");
|
|
5702
5723
|
new TomSelect(selector, {
|
|
5703
5724
|
valueField: 'id',
|
|
5704
5725
|
labelField: 'pref_label',
|
|
5705
5726
|
searchField: [],
|
|
5727
|
+
closeAfterSelect: true,
|
|
5728
|
+
highlight: false, // Will use typesense's hightlight (as it can consider other fields)
|
|
5706
5729
|
load: async function(query, callback) {
|
|
5707
5730
|
const queryParams = new URLSearchParams({
|
|
5708
5731
|
q: query,
|
|
@@ -5743,15 +5766,33 @@ class LucosSearchComponent extends HTMLSpanElement {
|
|
|
5743
5766
|
this.updateOption(result.id, result);
|
|
5744
5767
|
});
|
|
5745
5768
|
},
|
|
5769
|
+
onItemSelect: function (item) {
|
|
5770
|
+
// Tom-select prevents clicking on link in an item to work as normal, so force it here
|
|
5771
|
+
window.open(item.dataset.value, '_blank').focus();
|
|
5772
|
+
},
|
|
5746
5773
|
render:{
|
|
5747
5774
|
option: function(data, escape) {
|
|
5748
|
-
|
|
5775
|
+
let label = escape(data.pref_label);
|
|
5776
|
+
let alt_label = "";
|
|
5777
|
+
if (data.highlight.pref_label) {
|
|
5778
|
+
label = data.highlight.pref_label.snippet;
|
|
5779
|
+
} else if (data.highlight.labels) {
|
|
5780
|
+
const matched_label = data.highlight.labels.find(l => l.matched_tokens.length > 0);
|
|
5781
|
+
if (matched_label) {
|
|
5782
|
+
alt_label = ` <span class="alt-label">(${matched_label.snippet})</span>`;
|
|
5783
|
+
}
|
|
5784
|
+
}
|
|
5785
|
+
label = label.replace(` (${data.type})`,""); // No need to include any type disambiguation in label, as types are always shown
|
|
5786
|
+
return `<div>${label}${alt_label}<span class="type lozenge" data-type="${escape(data.type)}">${escape(data.type)}</span></div>`;
|
|
5749
5787
|
},
|
|
5750
5788
|
item: function(data, escape) {
|
|
5751
|
-
return `<div class="lozenge" data-type="${escape(data.type)}">${escape(data.pref_label)}</div>`;
|
|
5789
|
+
return `<div class="lozenge" data-type="${escape(data.type)}"><a href="${data.id}" target="_blank">${escape(data.pref_label)}</a></div>`;
|
|
5752
5790
|
},
|
|
5753
5791
|
},
|
|
5754
5792
|
});
|
|
5793
|
+
if (selector.nextElementSibling) {
|
|
5794
|
+
shadow.append(selector.nextElementSibling);
|
|
5795
|
+
}
|
|
5755
5796
|
}
|
|
5756
5797
|
async searchRequest(searchParams) {
|
|
5757
5798
|
const key = this.getAttribute("data-api-key");
|
|
@@ -5760,7 +5801,10 @@ class LucosSearchComponent extends HTMLSpanElement {
|
|
|
5760
5801
|
searchParams.set('query_by_weights', "10,8,3,1");
|
|
5761
5802
|
searchParams.set('sort_by', "_text_match:desc,pref_label:asc");
|
|
5762
5803
|
searchParams.set('prioritize_num_matching_fields', false);
|
|
5763
|
-
searchParams.set('include_fields', "id,pref_label,type");
|
|
5804
|
+
searchParams.set('include_fields', "id,pref_label,type,labels");
|
|
5805
|
+
searchParams.set('enable_highlight_v1', false);
|
|
5806
|
+
searchParams.set('highlight_start_tag', '<span class="highlight">');
|
|
5807
|
+
searchParams.set('highlight_end_tag', '</span>');
|
|
5764
5808
|
const response = await fetch("https://arachne.l42.eu/search?"+searchParams.toString(), {
|
|
5765
5809
|
headers: { 'X-TYPESENSE-API-KEY': key },
|
|
5766
5810
|
signal: AbortSignal.timeout(900),
|
package/index.js
CHANGED
|
@@ -10,6 +10,12 @@ class LucosSearchComponent extends HTMLSpanElement {
|
|
|
10
10
|
const component = this;
|
|
11
11
|
const shadow = component.attachShadow({mode: 'open'});
|
|
12
12
|
|
|
13
|
+
if (tomSelectStylesheet) {
|
|
14
|
+
const tomStyle = document.createElement('style');
|
|
15
|
+
tomStyle.textContent = tomSelectStylesheet;
|
|
16
|
+
shadow.appendChild(tomStyle);
|
|
17
|
+
}
|
|
18
|
+
|
|
13
19
|
const mainStyle = document.createElement('style');
|
|
14
20
|
mainStyle.textContent = `
|
|
15
21
|
.lozenge {
|
|
@@ -79,6 +85,22 @@ class LucosSearchComponent extends HTMLSpanElement {
|
|
|
79
85
|
--lozenge-border: #674800;
|
|
80
86
|
--lozenge-text: #352005;
|
|
81
87
|
}
|
|
88
|
+
.lozenge[data-type="Historical Event"] {
|
|
89
|
+
--lozenge-background: #740909;
|
|
90
|
+
--lozenge-border: #470202;
|
|
91
|
+
}
|
|
92
|
+
.lozenge[data-type="Number"] {
|
|
93
|
+
--lozenge-background: #0000ff;
|
|
94
|
+
--lozenge-border: #000083;
|
|
95
|
+
}
|
|
96
|
+
/** Temporal Types **/
|
|
97
|
+
.lozenge[data-type="Calendar"], .lozenge[data-type="Festival"], .lozenge[data-type="Month of Year"], .lozenge[data-type="Day of Week"] {
|
|
98
|
+
--lozenge-background: #fffc33;
|
|
99
|
+
--lozenge-border: #7f7e00;
|
|
100
|
+
--lozenge-text: #0f0f00;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
82
104
|
.lozenge.active {
|
|
83
105
|
--lozenge-border: #b00;
|
|
84
106
|
}
|
|
@@ -86,25 +108,26 @@ class LucosSearchComponent extends HTMLSpanElement {
|
|
|
86
108
|
margin: 0 3px;
|
|
87
109
|
padding: 2px 6px;
|
|
88
110
|
}
|
|
111
|
+
.ts-dropdown {
|
|
112
|
+
margin: 0;
|
|
113
|
+
}
|
|
114
|
+
.lozenge a {
|
|
115
|
+
color: inherit;
|
|
116
|
+
text-decoration: none;
|
|
117
|
+
}
|
|
89
118
|
`;
|
|
90
119
|
shadow.appendChild(mainStyle);
|
|
91
120
|
|
|
92
|
-
// If webpack is configured with `css-loader` but not `style-loader`, include the tom-select stylesheet here
|
|
93
|
-
// (If `style-loader` is being used, the tom-select stylesheet will be handled by that)
|
|
94
|
-
if (tomSelectStylesheet) {
|
|
95
|
-
const tomStyle = document.createElement('style');
|
|
96
|
-
tomStyle.textContent = tomSelectStylesheet;
|
|
97
|
-
shadow.appendChild(tomStyle);
|
|
98
|
-
}
|
|
99
121
|
|
|
100
122
|
const selector = component.querySelector("select");
|
|
101
123
|
if (!selector) throw new Error("Can't find select element in lucos-search");
|
|
102
|
-
shadow.append(selector);
|
|
103
124
|
selector.setAttribute("multiple", "multiple");
|
|
104
125
|
new TomSelect(selector, {
|
|
105
126
|
valueField: 'id',
|
|
106
127
|
labelField: 'pref_label',
|
|
107
128
|
searchField: [],
|
|
129
|
+
closeAfterSelect: true,
|
|
130
|
+
highlight: false, // Will use typesense's hightlight (as it can consider other fields)
|
|
108
131
|
load: async function(query, callback) {
|
|
109
132
|
const queryParams = new URLSearchParams({
|
|
110
133
|
q: query,
|
|
@@ -145,15 +168,33 @@ class LucosSearchComponent extends HTMLSpanElement {
|
|
|
145
168
|
this.updateOption(result.id, result);
|
|
146
169
|
});
|
|
147
170
|
},
|
|
171
|
+
onItemSelect: function (item) {
|
|
172
|
+
// Tom-select prevents clicking on link in an item to work as normal, so force it here
|
|
173
|
+
window.open(item.dataset.value, '_blank').focus();
|
|
174
|
+
},
|
|
148
175
|
render:{
|
|
149
176
|
option: function(data, escape) {
|
|
150
|
-
|
|
177
|
+
let label = escape(data.pref_label);
|
|
178
|
+
let alt_label = "";
|
|
179
|
+
if (data.highlight.pref_label) {
|
|
180
|
+
label = data.highlight.pref_label.snippet;
|
|
181
|
+
} else if (data.highlight.labels) {
|
|
182
|
+
const matched_label = data.highlight.labels.find(l => l.matched_tokens.length > 0);
|
|
183
|
+
if (matched_label) {
|
|
184
|
+
alt_label = ` <span class="alt-label">(${matched_label.snippet})</span>`;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
label = label.replace(` (${data.type})`,""); // No need to include any type disambiguation in label, as types are always shown
|
|
188
|
+
return `<div>${label}${alt_label}<span class="type lozenge" data-type="${escape(data.type)}">${escape(data.type)}</span></div>`;
|
|
151
189
|
},
|
|
152
190
|
item: function(data, escape) {
|
|
153
|
-
return `<div class="lozenge" data-type="${escape(data.type)}">${escape(data.pref_label)}</div>`;
|
|
191
|
+
return `<div class="lozenge" data-type="${escape(data.type)}"><a href="${data.id}" target="_blank">${escape(data.pref_label)}</a></div>`;
|
|
154
192
|
},
|
|
155
193
|
},
|
|
156
194
|
});
|
|
195
|
+
if (selector.nextElementSibling) {
|
|
196
|
+
shadow.append(selector.nextElementSibling);
|
|
197
|
+
}
|
|
157
198
|
}
|
|
158
199
|
async searchRequest(searchParams) {
|
|
159
200
|
const key = this.getAttribute("data-api-key");
|
|
@@ -162,7 +203,10 @@ class LucosSearchComponent extends HTMLSpanElement {
|
|
|
162
203
|
searchParams.set('query_by_weights', "10,8,3,1");
|
|
163
204
|
searchParams.set('sort_by', "_text_match:desc,pref_label:asc");
|
|
164
205
|
searchParams.set('prioritize_num_matching_fields', false);
|
|
165
|
-
searchParams.set('include_fields', "id,pref_label,type");
|
|
206
|
+
searchParams.set('include_fields', "id,pref_label,type,labels");
|
|
207
|
+
searchParams.set('enable_highlight_v1', false);
|
|
208
|
+
searchParams.set('highlight_start_tag', '<span class="highlight">')
|
|
209
|
+
searchParams.set('highlight_end_tag', '</span>');
|
|
166
210
|
const response = await fetch("https://arachne.l42.eu/search?"+searchParams.toString(), {
|
|
167
211
|
headers: { 'X-TYPESENSE-API-KEY': key },
|
|
168
212
|
signal: AbortSignal.timeout(900),
|