henry-search 1.0.2 → 1.0.3

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/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "henry-search",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
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",
@@ -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>
@@ -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>