@searchstax-inc/searchstudio-ux-react 0.0.1 → 0.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/README.md +1 -1
- package/dist/components/SearchstaxInputWidget.d.ts +11 -0
- package/dist/components/SearchstaxResultWidget.d.ts +7 -0
- package/dist/components/SearchstaxWrapper.d.ts +12 -0
- package/{src/main.tsx → dist/main.d.ts} +1 -2
- package/dist/searchstudio-ux-react-ts.cjs.js +95 -0
- package/dist/searchstudio-ux-react-ts.es.js +1726 -0
- package/dist/searchstudio-ux-react-ts.umd.js +95 -0
- package/package.json +4 -1
- package/index.html +0 -24
- package/src/App.scss +0 -1
- package/src/App.tsx +0 -234
- package/src/assets/react.svg +0 -1
- package/src/components/SearchstaxInputWidget.tsx +0 -83
- package/src/components/SearchstaxResultWidget.tsx +0 -202
- package/src/components/SearchstaxWrapper.tsx +0 -34
- package/src/index.css +0 -0
- package/src/main.js +0 -4
- package/src/stores/searchstaxStore.js +0 -5
- package/src/vite-env.d.ts +0 -1
- package/tsconfig.json +0 -24
- package/tsconfig.node.json +0 -10
- package/vite.config.ts +0 -30
- /package/{public → dist}/vite.svg +0 -0
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from "react";
|
|
2
|
-
//@ts-expect-error
|
|
3
|
-
|
|
4
|
-
import { store } from "./../stores/searchstaxStore.js";
|
|
5
|
-
//@ts-expect-error
|
|
6
|
-
import type { ISearchstaxParsedResult, ISearchstaxSearchMetadata } from '@searchstax-inc/searchstudio-ux-js'
|
|
7
|
-
|
|
8
|
-
function SearchstaxResultWidget(props: {
|
|
9
|
-
afterLinkClick: (
|
|
10
|
-
results: ISearchstaxParsedResult[]
|
|
11
|
-
) => ISearchstaxParsedResult[];
|
|
12
|
-
noResultTemplate?: (searchTerm: string, searchSuggestion: string) => React.ReactElement;
|
|
13
|
-
resultsTemplate?: (results: ISearchstaxParsedResult[], resultClicked: (result: ISearchstaxParsedResult, event: any) => any) => React.ReactElement;
|
|
14
|
-
}) {
|
|
15
|
-
//state variable
|
|
16
|
-
const [searchResults, setResults] = useState(
|
|
17
|
-
null as ISearchstaxParsedResult[] | null
|
|
18
|
-
);
|
|
19
|
-
const [searchTerm, setSearchTerm] = useState("");
|
|
20
|
-
const [searchSuggestion, setSearchSuggestion] = useState("");
|
|
21
|
-
|
|
22
|
-
const resultClicked = (result: ISearchstaxParsedResult, event: any) => {
|
|
23
|
-
event.preventDefault();
|
|
24
|
-
event.stopPropagation();
|
|
25
|
-
store.searchstax.executeLinkClick(result.uniqueId);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
const hooks: { [key: string]: (prop: any) => any } = {};
|
|
30
|
-
if (props.afterLinkClick) {
|
|
31
|
-
hooks.afterLinkClick = props.afterLinkClick;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
store.searchstax.dataLayer.searchResultsObservable.subscribe(
|
|
35
|
-
(results: ISearchstaxParsedResult[] | null) => {
|
|
36
|
-
setResults(results);
|
|
37
|
-
}
|
|
38
|
-
);
|
|
39
|
-
store.searchstax.dataLayer.searchResultsMetadataObservable.subscribe(
|
|
40
|
-
(results: ISearchstaxSearchMetadata | null) => {
|
|
41
|
-
setSearchSuggestion(results?.spellingSuggestion ?? "");
|
|
42
|
-
}
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
store.searchstax.dataLayer.searchTermChangeObservable.subscribe(
|
|
46
|
-
(result: string) => {
|
|
47
|
-
setSearchTerm(result);
|
|
48
|
-
}
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
store.searchstax.addSearchResultsWidget("searchstax-results-container", {
|
|
52
|
-
searchResultsContainerId: "searchstax-result-container", // if main template is over ridden this points to an
|
|
53
|
-
templates: {},
|
|
54
|
-
hooks: hooks,
|
|
55
|
-
});
|
|
56
|
-
}, []);
|
|
57
|
-
|
|
58
|
-
return (
|
|
59
|
-
<>
|
|
60
|
-
<div id="searchstax-results-container">
|
|
61
|
-
<div className="searchstax-search-results-container">
|
|
62
|
-
<div id="searchstax-result-container">
|
|
63
|
-
{searchResults &&
|
|
64
|
-
searchResults.length === 0 &&
|
|
65
|
-
!props.noResultTemplate && (
|
|
66
|
-
<div>
|
|
67
|
-
<div className="searchstax-no-results">
|
|
68
|
-
Showing <strong>no results</strong> for
|
|
69
|
-
<strong>"{searchTerm}"</strong>
|
|
70
|
-
<br />
|
|
71
|
-
{searchSuggestion && (
|
|
72
|
-
<span>
|
|
73
|
-
Did you mean
|
|
74
|
-
<a href="#" className="searchstax-suggestion-term">
|
|
75
|
-
{searchSuggestion}
|
|
76
|
-
</a>
|
|
77
|
-
?
|
|
78
|
-
</span>
|
|
79
|
-
)}
|
|
80
|
-
</div>
|
|
81
|
-
<div>
|
|
82
|
-
<p>
|
|
83
|
-
Try searching for search related terms or topics. We offer
|
|
84
|
-
a wide variety of content to help you get the information
|
|
85
|
-
you need.
|
|
86
|
-
</p>
|
|
87
|
-
<p>
|
|
88
|
-
Lost? Click on the ‘X” in the Search Box to reset your
|
|
89
|
-
search.
|
|
90
|
-
</p>
|
|
91
|
-
</div>
|
|
92
|
-
</div>
|
|
93
|
-
)}
|
|
94
|
-
|
|
95
|
-
{searchResults &&
|
|
96
|
-
searchResults.length === 0 &&
|
|
97
|
-
props.noResultTemplate && (
|
|
98
|
-
<>{props.noResultTemplate(searchTerm, searchSuggestion)}</>
|
|
99
|
-
)}
|
|
100
|
-
|
|
101
|
-
{searchResults &&
|
|
102
|
-
searchResults.length &&
|
|
103
|
-
!props.resultsTemplate && (
|
|
104
|
-
<div className="searchstax-search-results">
|
|
105
|
-
{searchResults !== null &&
|
|
106
|
-
searchResults.map(function (searchResult) {
|
|
107
|
-
return (
|
|
108
|
-
<div
|
|
109
|
-
className="searchstax-search-result"
|
|
110
|
-
key={searchResult.uniqueId}
|
|
111
|
-
>
|
|
112
|
-
{searchResult.url && (
|
|
113
|
-
<a
|
|
114
|
-
href={searchResult.url}
|
|
115
|
-
data-searchstax-unique-result-id={
|
|
116
|
-
searchResult.uniqueId
|
|
117
|
-
}
|
|
118
|
-
onClick={(event) => {
|
|
119
|
-
resultClicked(searchResult, event);
|
|
120
|
-
}}
|
|
121
|
-
className="searchstax-result-item-link"
|
|
122
|
-
></a>
|
|
123
|
-
)}
|
|
124
|
-
|
|
125
|
-
{searchResult.ribbon && (
|
|
126
|
-
<div className="searchstax-search-result-ribbon">
|
|
127
|
-
{searchResult.ribbon}
|
|
128
|
-
</div>
|
|
129
|
-
)}
|
|
130
|
-
|
|
131
|
-
{searchResult.thumbnail && (
|
|
132
|
-
<img
|
|
133
|
-
src={searchResult.thumbnail}
|
|
134
|
-
className="searchstax-thumbnail"
|
|
135
|
-
/>
|
|
136
|
-
)}
|
|
137
|
-
|
|
138
|
-
<div className="searchstax-search-result-title-container">
|
|
139
|
-
<span className="searchstax-search-result-title">
|
|
140
|
-
{searchResult.title}
|
|
141
|
-
</span>
|
|
142
|
-
</div>
|
|
143
|
-
|
|
144
|
-
{searchResult.paths && (
|
|
145
|
-
<p className="searchstax-search-result-common">
|
|
146
|
-
{searchResult.paths}
|
|
147
|
-
</p>
|
|
148
|
-
)}
|
|
149
|
-
|
|
150
|
-
{searchResult.description && (
|
|
151
|
-
<p className="searchstax-search-result-description searchstax-search-result-common">
|
|
152
|
-
{searchResult.description}
|
|
153
|
-
</p>
|
|
154
|
-
)}
|
|
155
|
-
|
|
156
|
-
{searchResult.unmappedFields.map(function (
|
|
157
|
-
unmappedField: any
|
|
158
|
-
) {
|
|
159
|
-
return (
|
|
160
|
-
<div key={unmappedField.value}>
|
|
161
|
-
{unmappedField.isImage && (
|
|
162
|
-
<div className="searchstax-search-result-image-container">
|
|
163
|
-
<img
|
|
164
|
-
src={unmappedField.value}
|
|
165
|
-
className="searchstax-result-image"
|
|
166
|
-
/>
|
|
167
|
-
</div>
|
|
168
|
-
)}
|
|
169
|
-
|
|
170
|
-
{!unmappedField.isImage && (
|
|
171
|
-
<div>
|
|
172
|
-
<p className="searchstax-search-result-common">
|
|
173
|
-
{unmappedField.value}
|
|
174
|
-
</p>
|
|
175
|
-
</div>
|
|
176
|
-
)}
|
|
177
|
-
</div>
|
|
178
|
-
);
|
|
179
|
-
})}
|
|
180
|
-
</div>
|
|
181
|
-
);
|
|
182
|
-
})}
|
|
183
|
-
|
|
184
|
-
{searchResults !== null && searchResults.length && (
|
|
185
|
-
<div v-if="searchResults && searchResults.length && hasResultSlot">
|
|
186
|
-
{/* <slot name="results" ></slot> */}
|
|
187
|
-
</div>
|
|
188
|
-
)}
|
|
189
|
-
</div>
|
|
190
|
-
)}
|
|
191
|
-
|
|
192
|
-
{searchResults && searchResults.length && props.resultsTemplate && (
|
|
193
|
-
<>{props.resultsTemplate(searchResults, resultClicked)}</>
|
|
194
|
-
)}
|
|
195
|
-
</div>
|
|
196
|
-
</div>
|
|
197
|
-
</div>
|
|
198
|
-
</>
|
|
199
|
-
);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
export default SearchstaxResultWidget;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
2
|
-
//@ts-expect-error
|
|
3
|
-
import { store } from "./../stores/searchstaxStore.js";
|
|
4
|
-
//@ts-expect-error
|
|
5
|
-
import Searchstax from '@searchstax-inc/searchstudio-ux-js'
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function SearchstaxWrapper(props: {
|
|
9
|
-
language?: string;
|
|
10
|
-
searchURL: string;
|
|
11
|
-
suggesterURL: string;
|
|
12
|
-
trackApiKey: string;
|
|
13
|
-
searchAuth: string;
|
|
14
|
-
authType?: "basic" | "token";
|
|
15
|
-
children: any;
|
|
16
|
-
initialized: (searchstax: Searchstax) => void;
|
|
17
|
-
}) {
|
|
18
|
-
useEffect(() => {
|
|
19
|
-
store.searchstax.initialize({
|
|
20
|
-
language: props.language ?? 'en',
|
|
21
|
-
searchURL: props.searchURL,
|
|
22
|
-
suggesterURL: props.suggesterURL,
|
|
23
|
-
trackApiKey: props.trackApiKey,
|
|
24
|
-
searchAuth: props.searchAuth,
|
|
25
|
-
authType: props.authType ?? "basic"
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
props.initialized(store.searchstax);
|
|
29
|
-
}, [props.initialized]);
|
|
30
|
-
|
|
31
|
-
return <>{props.children}</>;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export default SearchstaxWrapper;
|
package/src/index.css
DELETED
|
File without changes
|
package/src/main.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import SearchstaxWrapper from './components/SearchstaxWrapper.vue'
|
|
2
|
-
import SearchstaxResultWidget from './components/SearchstaxResultWidget.vue'
|
|
3
|
-
import SearchstaxInputWidget from './components/SearchstaxInputWidget.vue'
|
|
4
|
-
export { SearchstaxWrapper, SearchstaxResultWidget, SearchstaxInputWidget }
|
package/src/vite-env.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/// <reference types="vite/client" />
|
package/tsconfig.json
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ESNext",
|
|
4
|
-
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
|
5
|
-
"module": "ESNext",
|
|
6
|
-
"skipLibCheck": true,
|
|
7
|
-
|
|
8
|
-
/* Bundler mode */
|
|
9
|
-
"moduleResolution": "bundler",
|
|
10
|
-
"allowImportingTsExtensions": true,
|
|
11
|
-
"resolveJsonModule": true,
|
|
12
|
-
"isolatedModules": true,
|
|
13
|
-
"noEmit": true,
|
|
14
|
-
"jsx": "react-jsx",
|
|
15
|
-
|
|
16
|
-
/* Linting */
|
|
17
|
-
"strict": true,
|
|
18
|
-
"noUnusedLocals": true,
|
|
19
|
-
"noUnusedParameters": true,
|
|
20
|
-
"noFallthroughCasesInSwitch": true
|
|
21
|
-
},
|
|
22
|
-
"include": ["src"],
|
|
23
|
-
"references": [{ "path": "./tsconfig.node.json" }]
|
|
24
|
-
}
|
package/tsconfig.node.json
DELETED
package/vite.config.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'vite'
|
|
2
|
-
import react from '@vitejs/plugin-react'
|
|
3
|
-
import dts from 'vite-plugin-dts';
|
|
4
|
-
|
|
5
|
-
export default defineConfig({
|
|
6
|
-
plugins: [
|
|
7
|
-
react(),
|
|
8
|
-
dts({
|
|
9
|
-
insertTypesEntry: true,
|
|
10
|
-
}),
|
|
11
|
-
],
|
|
12
|
-
build: {
|
|
13
|
-
lib: {
|
|
14
|
-
entry: "src/main.tsx",
|
|
15
|
-
name: 'searchstudioUxReactTs',
|
|
16
|
-
formats: ["es", "cjs", "umd"],
|
|
17
|
-
fileName: (format) => `searchstudio-ux-react-ts.${format}.js`,
|
|
18
|
-
},
|
|
19
|
-
rollupOptions: {
|
|
20
|
-
external: ['react', 'react-dom', 'styled-components'],
|
|
21
|
-
output: {
|
|
22
|
-
globals: {
|
|
23
|
-
react: 'React',
|
|
24
|
-
'react-dom': 'ReactDOM',
|
|
25
|
-
'styled-components': 'styled',
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
});
|
|
File without changes
|