@searchspring/snap-preact 0.27.2 → 0.27.5

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.
Files changed (3) hide show
  1. package/README.md +1 -297
  2. package/package.json +12 -13
  3. package/LICENSE +0 -21
package/README.md CHANGED
@@ -2,300 +2,4 @@
2
2
 
3
3
  <a href="https://www.npmjs.com/package/@searchspring/snap-preact"><img alt="NPM Status" src="https://img.shields.io/npm/v/@searchspring/snap-preact.svg?style=flat"></a>
4
4
 
5
- Snap Preact is an abstraction layer that provides a config based interface for creating a Searchspring integration quickly.
6
-
7
-
8
- ## Installation
9
-
10
- To install the `snap-preact` package and it's dependencies:
11
-
12
- ```bash
13
- npm install --save @searchspring/snap-preact
14
- ```
15
-
16
- ## Instantiation
17
-
18
- ```typescript
19
- import { Snap } from '@searchspring/snap-preact';
20
-
21
- const snap = new Snap(config);
22
- ```
23
-
24
- ## Configuration
25
- A configuration object provided to Snap will determine the services that will be created.
26
-
27
- Full example:
28
-
29
- ```typescript
30
- const config = {
31
- context: globalContext,
32
- url: {
33
- parameters: {
34
- core: {
35
- query: { name: 'search' },
36
- },
37
- },
38
- },
39
- client: {
40
- globals: {
41
- siteId: 'xxxxxx',
42
- },
43
- },
44
- controllers: {
45
- search: [
46
- {
47
- config: {
48
- id: 'search',
49
- settings: {
50
- redirects: {
51
- merchandising: false,
52
- },
53
- },
54
- },
55
- targets: [
56
- {
57
- selector: '#searchspring-content',
58
- component: () => Content,
59
- hideTarget: true,
60
- },
61
- {
62
- selector: '#searchspring-sidebar',
63
- component: () => Sidebar,
64
- hideTarget: true,
65
- },
66
- ],
67
- },
68
- ],
69
- autocomplete: [
70
- {
71
- config: {
72
- id: 'autocomplete',
73
- selector: 'input.searchspring-ac',
74
- settings: {
75
- trending: {
76
- limit: 5,
77
- },
78
- },
79
- },
80
- targets: [
81
- {
82
- selector: 'input.searchspring-ac',
83
- component: () => Autocomplete,
84
- hideTarget: true,
85
- },
86
- ],
87
- },
88
- ],
89
- },
90
- };
91
- ```
92
-
93
- ### `config.context` - optional `Context` object to be used to set the global context. If no context is provided, a default context taken from the integration script (`shopper` variable) will be used, otherwise the provided `config.context` is merged with the script context. This context becomes the `globalContext` that is passed to all controllers that are created.
94
-
95
- ### config.client
96
- A single client instance will be created and shared across all services using the provided config.
97
-
98
- See [@searchspring/snap-client](https://github.com/searchspring/snap/tree/main/packages/snap-client) documentation for full client config options.
99
-
100
- ```typescript
101
- const config = {
102
- client: {
103
- globals: {
104
- siteId: 'xxxxxx'
105
- }
106
- }
107
- }
108
- ```
109
-
110
- ### config.instantiators
111
- The `instantiators` object must be defined if any Recommendation controllers have also been defined via `config.controllers.recommendation`
112
-
113
- ```typescript
114
- const config = {
115
- instantiators: {
116
- recommendation: {
117
- context: recommendationContext,
118
- components: {
119
- Standard: () => Standard
120
- },
121
- config: {
122
- branch: BRANCHNAME,
123
- batched: true
124
- },
125
- selector: '',
126
- services: {}
127
- }
128
- },
129
- controllers: {
130
- recommendation: []
131
- }
132
- }
133
- ```
134
-
135
- `recommendation.components` - required mapping of recommendation components.
136
-
137
- `recommendation.context` - optional `Context` object to be used to set controller specific context. Defaults to the global context if no context prop is provided, or if one is provided, it is merged into the global context.
138
-
139
- `recommendation.config.branch` - required current git branch name. Defined via webpack during bundle build:
140
-
141
- ```typescript
142
- const webpack = require('webpack');
143
- const childProcess = require('child_process');
144
- const branchName = childProcess.execSync('git rev-parse --abbrev-ref HEAD').toString().trim();
145
-
146
- module.exports = {
147
- plugins: [
148
- new webpack.DefinePlugin({
149
- BRANCHNAME: `"${branchName}"`,
150
- }),
151
- ],
152
- }
153
- ```
154
-
155
- `recommendation.config.batched` - optional boolean (default: `true`) to batch multiple recommendations into a single network request
156
-
157
- `recommendation.selector` - optional selector to target recommendation instances if using a non-standard installation. Default selector: `script[type="searchspring/recommend"]`
158
-
159
- `recommendation.services` - optional object of `ControllerServices`
160
-
161
-
162
-
163
- ### config.url
164
- The `url` object contains the config provided to each [`UrlTranslator`](https://github.com/searchspring/snap/tree/main/packages/snap-url-manager/src/Translators/Url) created by Snap Preact.
165
-
166
- ```typescript
167
- const config = {
168
- url: {
169
- parameters: {
170
- core: {
171
- query: { name: 'search' },
172
- page: { name: 'p' }
173
- },
174
- },
175
- },
176
- }
177
- ```
178
-
179
- ### config.controllers
180
- The `controllers` object contains a list of controllers to create for each controller type.
181
-
182
- Available controllers:
183
-
184
- - [SearchController](https://github.com/searchspring/snap/tree/main/packages/snap-controller/src/Search)
185
- - [AutocompleteController](https://github.com/searchspring/snap/tree/main/packages/snap-controller/src/Autocomplete)
186
- - [FinderController](https://github.com/searchspring/snap/tree/main/packages/snap-controller/src/Finder)
187
- - [RecommendationController](https://github.com/searchspring/snap/tree/main/packages/snap-controller/src/Recommendation)
188
-
189
- ```typescript
190
- const config = {
191
- controllers: {
192
- search: [],
193
- autocomplete: [],
194
- finder: [],
195
- recommendation: [],
196
- }
197
- }
198
- ```
199
-
200
- Each array entry contains an object with the following properties:
201
-
202
- `config` - required controller config for the corresponding controller. See Controller specific documentation for all available configuration options.
203
-
204
- `targets` - optional array of Target objects. Targets thats have been found will have the corresponding controller provided to the target component `controller` prop and the controller's `search` method invoked.
205
-
206
- ```typescript
207
- type ExtendedTarget = {
208
- selector: string;
209
- inject?: {
210
- action: 'before' | 'after' | 'append' | 'prepend' | 'replace';
211
- element: Element | ((target: Target, element: Element) => Element);
212
- };
213
- hideTarget?: boolean;
214
- emptyTarget?: boolean;
215
- name?: string;
216
- component?: () => Promise<RootComponent> | RootComponent;
217
- props?: unknown; // additional props to pass to the component
218
- onTarget?: OnTarget; // additional scripts to execute when target is found
219
- prefetch?: boolean; // run controller search before finding targets
220
- }
221
- ```
222
-
223
- `services` - optional object of `ControllerServices` to be used for this controller in place of the default services
224
-
225
- `url` - optional `UrlTranslator` config object to be used with the `UrlManager` for this controller
226
-
227
- `context` - optional `Context` object to be used to set controller specific context. Defaults to the global context if no context prop is provided, or if one is provided, it is merged into the global context.
228
-
229
- An example creating a SearchController:
230
-
231
- ```typescript
232
- const config = {
233
- controllers: {
234
- search: [
235
- {
236
- context: searchContext,
237
- config: {
238
- id: 'search',
239
- },
240
- targets: [
241
- {
242
- selector: '#searchspring-content',
243
- component: () => Content,
244
- hideTarget: true,
245
- },
246
- {
247
- selector: '#searchspring-sidebar',
248
- component: () => Sidebar,
249
- hideTarget: true,
250
- },
251
- ],
252
- services: {}
253
- }
254
- ]
255
- }
256
- }
257
- ```
258
- The controller config `id` will be the name of the controller that you will then interface from the return of creating the `new Snap()` instance via the `controllers` object.
259
-
260
- For example, if using the `config` example above:
261
-
262
- ```typescript
263
- const snap = new Snap(config);
264
- const { search } = snap.controllers;
265
- ```
266
-
267
- ## properties
268
-
269
- After instantiating an instance of Snap, the following properties can be accessed.
270
-
271
- ### config
272
- A reference to the config that was provided.
273
-
274
- ### logger
275
- A reference to the shared [@searchspring/snap-logger](https://github.com/searchspring/snap/tree/main/packages/snap-logger) instance used by each controller.
276
-
277
- ### client
278
- A reference to the shared [@searchspring/snap-client](https://github.com/searchspring/snap/tree/main/packages/snap-client) instance used by each controller.
279
-
280
- ### tracker
281
- A reference to the shared [@searchspring/snap-tracker](https://github.com/searchspring/snap/tree/main/packages/snap-tracker) instance used by each controller.
282
-
283
- ### controllers
284
- An object containing all controllers that have been created.
285
-
286
-
287
- ### recommendations
288
- A reference to `RecommendationInstantiator` instance if creating recommendation instances.
289
-
290
-
291
- ## polyfills
292
-
293
- Snap Preact provides various polyfills to ensure legacy browser support.
294
-
295
- ```typescript
296
- import { polyfills } from '@searchspring/snap-preact';
297
-
298
- polyfills.then(() => {
299
- import('./index');
300
- })
301
- ```
5
+ Snap Preact is an abstraction layer that provides a config based interface for creating a Searchspring integration quickly.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@searchspring/snap-preact",
3
- "version": "0.27.2",
3
+ "version": "0.27.5",
4
4
  "description": "Snap Preact",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -20,16 +20,16 @@
20
20
  "test:watch": "jest --watch"
21
21
  },
22
22
  "dependencies": {
23
- "@searchspring/snap-client": "^0.27.2",
24
- "@searchspring/snap-controller": "^0.27.2",
25
- "@searchspring/snap-event-manager": "^0.27.2",
26
- "@searchspring/snap-logger": "^0.27.2",
27
- "@searchspring/snap-preact-components": "^0.27.2",
28
- "@searchspring/snap-profiler": "^0.27.2",
29
- "@searchspring/snap-store-mobx": "^0.27.2",
30
- "@searchspring/snap-toolbox": "^0.27.2",
31
- "@searchspring/snap-tracker": "^0.27.2",
32
- "@searchspring/snap-url-manager": "^0.27.2",
23
+ "@searchspring/snap-client": "^0.27.5",
24
+ "@searchspring/snap-controller": "^0.27.5",
25
+ "@searchspring/snap-event-manager": "^0.27.5",
26
+ "@searchspring/snap-logger": "^0.27.5",
27
+ "@searchspring/snap-preact-components": "^0.27.5",
28
+ "@searchspring/snap-profiler": "^0.27.5",
29
+ "@searchspring/snap-store-mobx": "^0.27.5",
30
+ "@searchspring/snap-toolbox": "^0.27.5",
31
+ "@searchspring/snap-tracker": "^0.27.5",
32
+ "@searchspring/snap-url-manager": "^0.27.5",
33
33
  "deepmerge": "^4.2.2",
34
34
  "intersection-observer": "^0.12.0",
35
35
  "is-plain-object": "^5.0.0"
@@ -40,6 +40,5 @@
40
40
  "sideEffects": false,
41
41
  "files": [
42
42
  "dist/**/*"
43
- ],
44
- "gitHead": "4b0a534583ab1ef24fdda8c408ec23296c135ef4"
43
+ ]
45
44
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 Searchspring
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.