henry-search 1.0.2 → 1.0.4
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/HenrySearch.css +1 -1
- package/dist/HenrySearch.js +26700 -25558
- package/dist/HenrySearch.umd.cjs +88 -127
- package/package.json +6 -2
- package/src/assets/main-icons-sprite.svg +14 -2
- package/src/components/Autocomplete.vue +141 -0
- package/src/components/PAccordion.vue +25 -2
- package/src/components/PTabs.vue +98 -0
- package/src/components/Search.vue +180 -2032
- package/src/components/SearchDetail.vue +160 -0
- package/src/components/SearchHistory.vue +40 -0
- package/src/components/SearchTab.vue +707 -0
- package/src/components/constants.js +1 -0
- package/src/composables/FocusableElements.js +13 -0
- package/src/composables/UseDirectionalKeys.js +105 -0
- package/src/composables/focusWithArrows.js +52 -0
- package/src/composables/formatDate.js +15 -0
- package/src/composables/slugify.js +10 -0
- package/src/main.js +3 -1
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "henry-search",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Searches a typesense archive of musical performances",
|
|
5
5
|
"main": "js/main.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "vite",
|
|
8
8
|
"build": "vite build",
|
|
9
|
-
"preview": "vite preview"
|
|
9
|
+
"preview": "vite preview",
|
|
10
|
+
"watch": "vite build --watch"
|
|
10
11
|
},
|
|
11
12
|
"repository": {
|
|
12
13
|
"type": "git",
|
|
@@ -22,7 +23,10 @@
|
|
|
22
23
|
},
|
|
23
24
|
"homepage": "https://github.com/bostonsymphony/henry-search#readme",
|
|
24
25
|
"dependencies": {
|
|
26
|
+
"@algolia/autocomplete-js": "^1.19.4",
|
|
27
|
+
"@algolia/autocomplete-theme-classic": "^1.19.4",
|
|
25
28
|
"@babel/runtime": "^7.28.4",
|
|
29
|
+
"@vitejs/plugin-vue-jsx": "^5.1.1",
|
|
26
30
|
"@vuepic/vue-datepicker": "^11.0.2",
|
|
27
31
|
"instantsearch.js": "^4.80.0",
|
|
28
32
|
"typesense": "^2.1.0",
|
|
@@ -97,5 +97,17 @@
|
|
|
97
97
|
<path fill="var(--icon-color, currentColor)" d="M192 512s192-208 192-320C384 86 298 0 192 0S0 86 0 192C0 304 192 512 192 512zm0-384a64 64 0 1 1 0 128 64 64 0 1 1 0-128z"></path>
|
|
98
98
|
</symbol>
|
|
99
99
|
|
|
100
|
-
<symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" id="bars"
|
|
101
|
-
|
|
100
|
+
<symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" id="bars">
|
|
101
|
+
<path fill="var(--icon-color, currentColor)" d="M0 96C0 78.3 14.3 64 32 64l384 0c17.7 0 32 14.3 32 32s-14.3 32-32 32L32 128C14.3 128 0 113.7 0 96zM0 256c0-17.7 14.3-32 32-32l384 0c17.7 0 32 14.3 32 32s-14.3 32-32 32L32 288c-17.7 0-32-14.3-32-32zM448 416c0 17.7-14.3 32-32 32L32 448c-17.7 0-32-14.3-32-32s14.3-32 32-32l384 0c17.7 0 32 14.3 32 32z"/>
|
|
102
|
+
</symbol>
|
|
103
|
+
|
|
104
|
+
<symbol width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" id="filter">
|
|
105
|
+
<rect width="24" height="24" rx="4" fill="#01ABE6"/>
|
|
106
|
+
<path d="M6 7.25H18.8864" stroke="white" stroke-linecap="round"/>
|
|
107
|
+
<path d="M6 12.5681H18.8864" stroke="white" stroke-linecap="round"/>
|
|
108
|
+
<path d="M6 17.75H18.8864" stroke="white" stroke-linecap="round"/>
|
|
109
|
+
<circle cx="8.72709" cy="17.9544" r="1.54545" fill="#01ABE6" stroke="white"/>
|
|
110
|
+
<circle cx="14.8633" cy="12.5" r="1.54545" fill="#01ABE6" stroke="white"/>
|
|
111
|
+
<circle cx="10.7725" cy="7.04545" r="1.54545" fill="#01ABE6" stroke="white"/>
|
|
112
|
+
</symbol>
|
|
113
|
+
</svg>
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
<script lang="jsx">
|
|
2
|
+
// recommended auto complete setup per https://www.algolia.com/doc/ui-libraries/autocomplete/integrations/with-vue-instantsearch
|
|
3
|
+
|
|
4
|
+
import { h as createElement, Fragment, render } from "vue"
|
|
5
|
+
|
|
6
|
+
import { createWidgetMixin } from "vue-instantsearch/vue3/es"
|
|
7
|
+
import { connectSearchBox } from "instantsearch.js/es/connectors"
|
|
8
|
+
import { autocomplete } from "@algolia/autocomplete-js"
|
|
9
|
+
import Typesense from 'typesense'
|
|
10
|
+
|
|
11
|
+
import "@algolia/autocomplete-theme-classic"
|
|
12
|
+
|
|
13
|
+
import { INSTANT_SEARCH_INDEX_NAME } from "./constants"
|
|
14
|
+
|
|
15
|
+
export default {
|
|
16
|
+
mixins: [createWidgetMixin({ connector: connectSearchBox })],
|
|
17
|
+
mounted() {
|
|
18
|
+
if (this.autocompleteInstance) {
|
|
19
|
+
this.autocompleteInstance.destroy()
|
|
20
|
+
}
|
|
21
|
+
const { instantSearchInstance } = this
|
|
22
|
+
function setInstantSearchUiState({ query }) {
|
|
23
|
+
instantSearchInstance.setUiState((uiState) => ({
|
|
24
|
+
...uiState,
|
|
25
|
+
[INSTANT_SEARCH_INDEX_NAME]: {
|
|
26
|
+
...uiState[INSTANT_SEARCH_INDEX_NAME],
|
|
27
|
+
page: 1,
|
|
28
|
+
query,
|
|
29
|
+
}
|
|
30
|
+
}))
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const initialState = instantSearchInstance.mainIndex.getHelper()?.state || {}
|
|
34
|
+
|
|
35
|
+
let client = new Typesense.Client({
|
|
36
|
+
'nodes': [{
|
|
37
|
+
'host': 'go8f04wi19tuvlyrp-1.a1.typesense.net',
|
|
38
|
+
'port': '443',
|
|
39
|
+
'protocol': 'https'
|
|
40
|
+
}],
|
|
41
|
+
'apiKey': 'EBKGVrW6FHYnuSvdav8q9ABBjeuThaKU',
|
|
42
|
+
'connectionTimeoutSeconds': 2
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
this.autocompleteInstance = autocomplete( {
|
|
46
|
+
container: this.$refs.autocompleteContainer,
|
|
47
|
+
placeholder: "Search for performances",
|
|
48
|
+
detachedMediaQuery: "none",
|
|
49
|
+
async getSources({ query }) {
|
|
50
|
+
const results = await client.collections('archived_performances').documents().search({
|
|
51
|
+
q: query,
|
|
52
|
+
query_by: 'conductor',
|
|
53
|
+
highlight_full_fields: 'conductor'
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
return [
|
|
57
|
+
{
|
|
58
|
+
sourceId: 'predictions',
|
|
59
|
+
getItems() {
|
|
60
|
+
return results.hits
|
|
61
|
+
},
|
|
62
|
+
getItemInputValue({ item }) {
|
|
63
|
+
return item.document.name
|
|
64
|
+
},
|
|
65
|
+
templates: {
|
|
66
|
+
header() {
|
|
67
|
+
return 'Is this a thing?'
|
|
68
|
+
},
|
|
69
|
+
item({ item, createElement, Fragment }) {
|
|
70
|
+
|
|
71
|
+
let html_fragment = ""
|
|
72
|
+
item?.highlights?.forEach((highlight) => {
|
|
73
|
+
console.log('highlight.field', highlight.field)
|
|
74
|
+
if (highlight.field === 'conductor') {
|
|
75
|
+
console.log('highlight.values', highlight.values[0])
|
|
76
|
+
html_fragment = `${highlight.values[0]}`
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
return (
|
|
80
|
+
<div class="aa-ItemWrapper">
|
|
81
|
+
<div class="aa-ItemContent">
|
|
82
|
+
<div class="aa-ItemContentBody">
|
|
83
|
+
<div class="aa-ItemContentTitle">
|
|
84
|
+
{ html_fragment}
|
|
85
|
+
</div>
|
|
86
|
+
</div>
|
|
87
|
+
<div class="aa-ItemActions">
|
|
88
|
+
<button
|
|
89
|
+
class="aa-ItemActionButton aa-DesktopOnly aa-ActiveOnly"
|
|
90
|
+
type="button"
|
|
91
|
+
title="Select">
|
|
92
|
+
<svg
|
|
93
|
+
viewBox="0 0 24 24"
|
|
94
|
+
width="20"
|
|
95
|
+
height="20"
|
|
96
|
+
fill="currentColor">
|
|
97
|
+
<path
|
|
98
|
+
d="M18.984 6.984h2.016v6h-15.188l3.609 3.609-1.406 1.406-6-6 6-6 1.406 1.406-3.609 3.609h13.172v-4.031z"
|
|
99
|
+
/>
|
|
100
|
+
</svg>
|
|
101
|
+
</button>
|
|
102
|
+
</div>
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
},
|
|
108
|
+
noResults() {
|
|
109
|
+
return 'No results found'
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
]
|
|
114
|
+
},
|
|
115
|
+
renderer: { createElement, Fragment, render }
|
|
116
|
+
// initialState: { query: initialState.query || "" },
|
|
117
|
+
// onSubmit({ state }) {
|
|
118
|
+
// setInstantSearchUiState({ query: state. query })
|
|
119
|
+
// },
|
|
120
|
+
// onReset() {
|
|
121
|
+
// setInstantSearchUiState({ query: "" })
|
|
122
|
+
// },
|
|
123
|
+
// onStateChange({ prevState, state }) {
|
|
124
|
+
// if (prevState.query !== state.query ) {
|
|
125
|
+
// setInstantSearchUiState({ query: state.query })
|
|
126
|
+
// }
|
|
127
|
+
// },
|
|
128
|
+
// renderer: { createElement, Fragment, render },
|
|
129
|
+
})
|
|
130
|
+
},
|
|
131
|
+
beforeUnmount() {
|
|
132
|
+
this.autocompleteInstance?.destroy()
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
</script>
|
|
137
|
+
|
|
138
|
+
<template>
|
|
139
|
+
<h2>TEMPLATE HERE</h2>
|
|
140
|
+
<div ref="autocompleteContainer"></div>
|
|
141
|
+
</template>
|
|
@@ -14,12 +14,19 @@ import { onMounted, useTemplateRef } from 'vue'
|
|
|
14
14
|
|
|
15
15
|
const props = defineProps({
|
|
16
16
|
duration: { type: Number },
|
|
17
|
-
summary: { type: String, default: 'summary:first-of-type' }
|
|
17
|
+
summary: { type: String, default: 'summary:first-of-type' },
|
|
18
|
+
startOpen: { type: Boolean, default: true},
|
|
19
|
+
openText: { type: String, default: null},
|
|
20
|
+
closedText: { type: String, default: null}
|
|
18
21
|
})
|
|
19
22
|
const details = useTemplateRef('details')
|
|
23
|
+
const summaryText = null
|
|
20
24
|
|
|
21
25
|
onMounted(() => {
|
|
22
26
|
details.value.style.setProperty('--accordion-height-closed', 'auto')
|
|
27
|
+
if (props.startOpen) {
|
|
28
|
+
details.value.open = true
|
|
29
|
+
}
|
|
23
30
|
})
|
|
24
31
|
|
|
25
32
|
const handleToggle = event => {
|
|
@@ -32,7 +39,7 @@ const handleToggle = event => {
|
|
|
32
39
|
}
|
|
33
40
|
|
|
34
41
|
const summaryHeight = summary?.clientHeight
|
|
35
|
-
|
|
42
|
+
|
|
36
43
|
if (!summary.contains(event.target)) {
|
|
37
44
|
return
|
|
38
45
|
}
|
|
@@ -58,6 +65,22 @@ const handleToggle = event => {
|
|
|
58
65
|
el.open = true
|
|
59
66
|
})
|
|
60
67
|
}
|
|
68
|
+
if (props.openText && props.closedText) {
|
|
69
|
+
console.log('open closed text', props.openText, props.closedText)
|
|
70
|
+
let replacementText = ""
|
|
71
|
+
console.log('details.value.open', details.value.open)
|
|
72
|
+
if (details.value.open) {
|
|
73
|
+
replacementText = props.closedText
|
|
74
|
+
} else {
|
|
75
|
+
replacementText = props.openText
|
|
76
|
+
}
|
|
77
|
+
console.log(summary.children)
|
|
78
|
+
if (summary.children) {
|
|
79
|
+
summary.children[0].innerHTML = replacementText
|
|
80
|
+
} else {
|
|
81
|
+
summary.innerHTML = replacementText
|
|
82
|
+
}
|
|
83
|
+
}
|
|
61
84
|
}
|
|
62
85
|
</script>
|
|
63
86
|
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { computed, ref, useTemplateRef, isRef, isReactive, onMounted, watchEffect } from 'vue'
|
|
3
|
+
import focusWithArrows from '../composables/focusWithArrows'
|
|
4
|
+
|
|
5
|
+
const props = defineProps({
|
|
6
|
+
titles: { type: Array, required: true },
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
const tablist = useTemplateRef('tablist')
|
|
10
|
+
const visibleTab = ref(0)
|
|
11
|
+
const firstLoad = ref(true)
|
|
12
|
+
|
|
13
|
+
const focusedElement = focusWithArrows(tablist)
|
|
14
|
+
|
|
15
|
+
watchEffect(() => {
|
|
16
|
+
if (focusedElement.value) {
|
|
17
|
+
visibleTab.value = tablist.value.indexOf(focusedElement.value)
|
|
18
|
+
if (!firstLoad.value) {
|
|
19
|
+
history.replaceState(undefined, undefined, `${window.location.pathname}#${tabs.value[visibleTab.value]['title']}`)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
const tabs = computed(() => props.titles.map((title, i) => ({
|
|
25
|
+
title,
|
|
26
|
+
selected: i === visibleTab.value,
|
|
27
|
+
tabindex: i === visibleTab.value ? 0 : -1,
|
|
28
|
+
|
|
29
|
+
buttonId: `tab-${i + 1}`,
|
|
30
|
+
panelId: `tabpanel-${i + 1}`,
|
|
31
|
+
})))
|
|
32
|
+
|
|
33
|
+
onMounted(() => {
|
|
34
|
+
setInitActiveItem ()
|
|
35
|
+
addEventListener('hashchange', event => {
|
|
36
|
+
event.preventDefault()
|
|
37
|
+
setInitActiveItem()
|
|
38
|
+
})
|
|
39
|
+
firstLoad.value = false
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
function setInitActiveItem () {
|
|
43
|
+
if (location.hash) {
|
|
44
|
+
tabs.value.every((el, index) => {
|
|
45
|
+
console.log('el, index', el, index)
|
|
46
|
+
if (location.hash.substring(1) == el.title) {
|
|
47
|
+
visibleTab.value = index
|
|
48
|
+
return true
|
|
49
|
+
}
|
|
50
|
+
return true
|
|
51
|
+
})
|
|
52
|
+
} else {
|
|
53
|
+
visibleTab.value = 0
|
|
54
|
+
if (!firstLoad.value) {
|
|
55
|
+
history.replaceState(undefined, undefined, `#${tabs.value[visibleTab.value]['title']}`)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// handleOnOpen( payload ) {
|
|
61
|
+
// this.activeItem = payload
|
|
62
|
+
// if (this.setHash && !this.firstLoad) {
|
|
63
|
+
// history.replaceState(undefined, undefined, `#${this.activeItem}`)
|
|
64
|
+
// }
|
|
65
|
+
// },
|
|
66
|
+
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<template>
|
|
70
|
+
<div class="tabs">
|
|
71
|
+
<div class="tabs__tablist" role="tablist" aria-label="Sample Tabs">
|
|
72
|
+
<button
|
|
73
|
+
class="tabs__button"
|
|
74
|
+
:class="{ '-selected': tab.selected }"
|
|
75
|
+
v-for="tab in tabs"
|
|
76
|
+
role="tab"
|
|
77
|
+
:aria-selected="tab.selected"
|
|
78
|
+
:aria-controls="tab.panelId"
|
|
79
|
+
:id="tab.buttonId"
|
|
80
|
+
ref="tablist"
|
|
81
|
+
:tabindex="tab.tabindex"
|
|
82
|
+
v-text="tab.title"
|
|
83
|
+
></button>
|
|
84
|
+
</div>
|
|
85
|
+
|
|
86
|
+
<div
|
|
87
|
+
class="tabs__panel"
|
|
88
|
+
v-for="tab in tabs"
|
|
89
|
+
role="tabpanel"
|
|
90
|
+
:tabindex="tab.tabindex"
|
|
91
|
+
:id="tab.panelId"
|
|
92
|
+
:aria-labelledby="tab.buttonId"
|
|
93
|
+
:hidden="!tab.selected"
|
|
94
|
+
>
|
|
95
|
+
<slot :name="tab.panelId" />
|
|
96
|
+
</div>
|
|
97
|
+
</div>
|
|
98
|
+
</template>
|