@searchstax-inc/searchstudio-ux-js 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 CHANGED
@@ -1,61 +1,140 @@
1
- # vite-vanilla-ts-lib-starter
1
+ # searchstudio-ux-js
2
2
 
3
- The starter is built on top of Vite 4.x and prepared for writing libraries in TypeScript. It generates a hybrid package - both support for CommonJS and ESM modules.
3
+ Library to build searchstudio search page
4
4
 
5
- ## Features
5
+ ## Installation
6
6
 
7
- - Hybrid support - CommonJS and ESM modules
8
- - IIFE bundle for direct browser support without bundler
9
- - Typings bundle
10
- - ESLint - scripts linter
11
- - Stylelint - styles linter
12
- - Prettier - formatter
13
- - Vitest - test framework
14
- - Husky + lint-staged - pre-commit git hook set up for formatting
15
-
16
- ## GitHub Template
7
+ `npm install --save @searchstax-inc/searchstudio-ux-js`
8
+ ## Usage
17
9
 
18
- This is a template repo. Click the green [Use this template](https://github.com/kbysiec/vite-vanilla-ts-lib-starter/generate) button to get started.
10
+ After importing Searchstax class a new instance needs to be created:
19
11
 
20
- ## Clone to local
12
+ ```const searchstax = new Searchstax();```
21
13
 
22
- If you prefer to do it manually with the cleaner git history
14
+ ## Initialization
23
15
 
24
- ```bash
25
- git clone https://github.com/kbysiec/vite-vanilla-ts-lib-starter.git
26
- cd vite-vanilla-ts-lib-starter
27
- npm i
16
+ ```
17
+ searchstax.initialize({
18
+ language: "en",
19
+ searchURL: "",
20
+ suggesterURL: "",
21
+ authenticationValue: "",
22
+ trackApiKey: "",
23
+ searchApiKey: "",
24
+ authType: "basic",
25
+ });
28
26
  ```
29
27
 
30
- ## Checklist
31
-
32
- When you use this template, update the following:
33
-
34
- - Remove `.git` directory and run `git init` to clean up the history
35
- - Change the name in `package.json` - it will be the name of the IIFE bundle global variable and bundle files name (`.cjs`, `.mjs`, `.iife.js`, `d.ts`)
36
- - Change the author name in `LICENSE`
37
- - Clean up the `README` and `CHANGELOG` files
38
-
39
- And, enjoy :)
40
-
41
- ## Usage
42
-
43
- The starter contains the following scripts:
44
-
45
- - `dev` - starts dev server
46
- - `build` - generates the following bundles: CommonJS (`.cjs`) ESM (`.mjs`) and IIFE (`.iife.js`). The name of bundle is automatically taken from `package.json` name property
47
- - `test` - starts vitest and runs all tests
48
- - `test:coverage` - starts vitest and run all tests with code coverage report
49
- - `lint:scripts` - lint `.ts` files with eslint
50
- - `lint:styles` - lint `.css` and `.scss` files with stylelint
51
- - `format:scripts` - format `.ts`, `.html` and `.json` files with prettier
52
- - `format:styles` - format `.cs` and `.scss` files with stylelint
53
- - `format` - format all with prettier and stylelint
54
- - `prepare` - script for setting up husky pre-commit hook
55
- - `uninstall-husky` - script for removing husky from repository
28
+ ## Input widget
29
+ example of input widget initialization with various options
30
+ ```
31
+ searchstax.addSearchInputWidget("searchstax-input-container", {
32
+ suggestAfterMinChars: 3,
33
+ hideBranding: true,
34
+ hooks: {
35
+ beforeSearch: function (props: ISearchstaxSearchProps) {
36
+ // gets searchProps, if passed along further search will execute, if null then event gets canceled
37
+ // props can be modified and passed along
38
+ const propsCopy = { ...props };
39
+ // propsCopy.term = propsCopy.term;
40
+ return propsCopy;
41
+ },
42
+ afterSearch: function (results: ISearchstaxParsedResult[]) {
43
+ const copy = [...results];
44
+ // copy.splice(0, 1);
45
+ return copy;
46
+ },
47
+ afterAutosuggest: function (result: ISearchstaxSuggestResponse) {
48
+ const copy = { ...result };
49
+ console.log("copy", copy);
50
+ return copy;
51
+ },
52
+ beforeAutosuggest: function (props: ISearchstaxSuggestProps) {
53
+ // gets suggestProps, if passed along further autosuggest will execute, if null then event gets canceled
54
+ // props can be modified and passed along
55
+ const propsCopy = { ...props };
56
+ // propsCopy.term = propsCopy.term + '222';
57
+ return propsCopy;
58
+ },
59
+ },
60
+ templates: {
61
+ mainTemplate: `<div class="searchstax-search-input-container">
62
+ <div class="searchstax-search-input-wrapper">
63
+ <input type="text" id="searchstax-search-input" class="searchstax-search-input" placeholder="SEARCH FOR..." />
64
+ <button class="searchstax-spinner-icon" id="searchstax-search-input-action-button"></button>
65
+ </div>
66
+ </div>`,
67
+ searchInputId: "searchstax-input-container",
68
+ autosuggestItemTemplate: `<div class="searchstax-autosuggest-item-term-container">{{{term}}}</div>`,
69
+ },
70
+ });
71
+ ```
72
+ ## Result widget
56
73
 
57
- ## Acknowledgment
58
74
 
59
- If you found it useful somehow, I would be grateful if you could leave a star in the project's GitHub repository.
75
+ example of result widget initialization with various options
76
+ ```
77
+ searchstax.addSearchResultsWidget("searchstax-results-container", {
78
+ hideUniqueKey: true,
79
+ // searchResultUniqueIdAttribute: ' data-searchstax-unique-result-id', if custom result template is used
80
+ // points to an attribute that will be used to identify a result
81
+ searchResultsContainerId: "searchstax-result-container", // if main template is over ridden this points to an
82
+ // id in the main element where results need to be rendered
83
+ templates: {
84
+ mainTemplate: `
85
+ <div class="searchstax-search-results-container">
86
+ <div id="searchstax-result-container"></div>
87
+ </div>
88
+ `,
89
+ searchResultTemplate: `<div class="searchstax-search-result">
90
+ {{#url}}
91
+ <a href="{{url}}" data-searchstax-unique-result-id="{{uniqueId}}" class="searchstax-result-item-link"></a>
92
+ {{/url}}
93
+ {{#ribbon}}
94
+ <div class="searchstax-search-result-ribbon">
95
+ {{ribbon}}
96
+ </div>
97
+ {{/ribbon}}
98
+ {{#thumbnail}}
99
+ <img :src="thumbnail" class="searchstax-thumbnail">
100
+ {{/thumbnail}}
101
+ <div class="searchstax-search-result-title-container">
102
+ <span class="searchstax-search-result-title">{{title}}</span>
103
+ </div>
104
+ {{#paths}}
105
+ <p class="searchstax-search-result-common">
106
+ {{paths}}
107
+ </p>
108
+ {{/paths}}
109
+ {{#description}}
110
+ <p class="searchstax-search-result-description searchstax-search-result-common">
111
+ {{description}}
112
+ </p>
113
+ {{/description}}
114
+ {{#unmappedFields}}
115
+ {{#isImage}}
116
+ <div class="searchstax-search-result-image-container">
117
+ <img :src="result[value]" class="searchstax-result-image">
118
+ </div>
119
+ {{/isImage}}
120
+ {{^isImage}}
121
+ <p class="searchstax-search-result-common">
122
+ {{value}}
123
+ </p>
124
+ {{/isImage}}
125
+ {{/unmappedFields}}
126
+ </div>`,
127
+ },
128
+ hooks: {
129
+ afterLinkClick: function (result: ISearchstaxParsedResult) {
130
+ // gets result that was clicked, if passed along further functions will execute, if null then event gets canceled
131
+ const propsCopy = { ...result };
132
+
133
+ return propsCopy;
134
+ },
135
+ },
136
+ });
137
+ ```
60
138
 
61
- Thank you.
139
+ ## Template overrides
140
+ Templates use mustache templating. For more info see https://github.com/janl/mustache.js
@@ -16,6 +16,7 @@ export interface ISearchstaxParsedResult {
16
16
  unmappedFields: {
17
17
  key: string;
18
18
  value: string | string[] | boolean;
19
+ isImage?: boolean;
19
20
  }[];
20
21
  allFields: {
21
22
  key: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@searchstax-inc/searchstudio-ux-js",
3
3
  "private": false,
4
- "version": "0.0.1",
4
+ "version": "0.0.3",
5
5
  "files": [
6
6
  "dist"
7
7
  ],