seeonwall 0.4.0 → 0.5.0
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 +66 -1
- package/dist/index.d.ts +48 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +89 -8
- package/dist/index.js.map +1 -1
- package/dist/react.d.ts +12 -0
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +35 -2
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -120,9 +120,11 @@ the part of your app that uses SeeOnWall.
|
|
|
120
120
|
| `open(params)` | Opens the preview for one poster. |
|
|
121
121
|
| `close()` | Closes the preview. |
|
|
122
122
|
| `setLanguage(lang)` | Changes language at runtime. Only needed if your language switcher does not update `<html lang>`. |
|
|
123
|
-
| `isSessionReady()` | Returns the cached readiness hint for the current shop session. It is for optional
|
|
123
|
+
| `isSessionReady()` | Returns the cached readiness hint for the current shop session. It is for optional fast wall preview controls, never authorization. |
|
|
124
124
|
| `refreshSessionState()` | Refreshes the safe session hint and resolves to `none`, `creating`, `ready`, or `expired`. |
|
|
125
125
|
| `on('session-change', listener)` | Reacts to session changes in this or another same-origin shop tab. Returns an unsubscribe function. |
|
|
126
|
+
| `openCataloguePreview(params)` | Previews one poster on the wall the shopper already prepared. Resolves to `{ opened: true }` or a reason. |
|
|
127
|
+
| `whenLoaded()` | Resolves once the widget is available, including when `load()` has not been called yet. |
|
|
126
128
|
| `destroy()` | Stops the widget and removes everything it added. |
|
|
127
129
|
| `snippetVersion()` | The loaded widget version, or `null`. Useful in bug reports. |
|
|
128
130
|
|
|
@@ -132,6 +134,7 @@ From `seeonwall/react`:
|
|
|
132
134
|
|---|---|
|
|
133
135
|
| `useSeeOnWall(options)` | Loads the widget for as long as a component needs it. Same options as `load()`. |
|
|
134
136
|
| `SeeOnWallButton` | Renders a mount for the widget's button. |
|
|
137
|
+
| `useSessionReady()` | `true` while the shopper has a wall ready for this shop. Re-renders when that changes. |
|
|
135
138
|
|
|
136
139
|
### `load(options)`
|
|
137
140
|
|
|
@@ -156,8 +159,70 @@ if (isSessionReady()) showCatalogueComparison()
|
|
|
156
159
|
|
|
157
160
|
const unsubscribe = on('session-change', updateCatalogueControls)
|
|
158
161
|
// Call unsubscribe() when the page or component is disposed.
|
|
162
|
+
//
|
|
163
|
+
// The listener also runs when the shopper comes back to your page after setting
|
|
164
|
+
// up a wall on a phone, which is the moment the controls first make sense.
|
|
159
165
|
```
|
|
160
166
|
|
|
167
|
+
In React, prefer the hook — it subscribes, unsubscribes and re-renders for you:
|
|
168
|
+
|
|
169
|
+
```tsx
|
|
170
|
+
import { useSessionReady } from 'seeonwall/react'
|
|
171
|
+
|
|
172
|
+
function CompareButton(props) {
|
|
173
|
+
if (!useSessionReady()) return null
|
|
174
|
+
return <button onClick={() => openCataloguePreview(props)}>See on your wall</button>
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
It returns `false` on the server and on the first paint, so server and client markup agree, and it
|
|
179
|
+
turns `true` once the widget loads and finds a stored session.
|
|
180
|
+
|
|
181
|
+
### Fast wall preview
|
|
182
|
+
|
|
183
|
+
`openCataloguePreview(params)` shows one poster on the wall the shopper set up earlier, without
|
|
184
|
+
repeating the photo step. Use it on listing and recommendation surfaces, where the shopper is
|
|
185
|
+
comparing products rather than configuring one.
|
|
186
|
+
|
|
187
|
+
It takes the same `PosterParams` as `open()`, and it never throws — a refusal comes back as a
|
|
188
|
+
reason, so a control that ignores the result looks like a button that does nothing.
|
|
189
|
+
|
|
190
|
+
```ts
|
|
191
|
+
import { isSessionReady, openCataloguePreview } from 'seeonwall'
|
|
192
|
+
|
|
193
|
+
// Show the control only once a wall exists; the first-time visitor has none.
|
|
194
|
+
if (isSessionReady()) {
|
|
195
|
+
const result = await openCataloguePreview({
|
|
196
|
+
posterUrl: 'https://cdn.myshop.com/posters/dune.jpg',
|
|
197
|
+
posterTitle: 'Dune',
|
|
198
|
+
posterWidth: '50cm',
|
|
199
|
+
posterHeight: '70cm',
|
|
200
|
+
})
|
|
201
|
+
if (!result.opened) reportToShopper(result.reason)
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
| reason | |
|
|
206
|
+
|---|---|
|
|
207
|
+
| `no-ready-session` | The shopper has not set up a wall yet. Use `isSessionReady()` to avoid this one. |
|
|
208
|
+
| `session-expired` | The stored session is gone. Sessions last seven days. |
|
|
209
|
+
| `not-entitled` | The shop plan does not include fast wall preview. |
|
|
210
|
+
| `inactive-product` | The product is not active for SeeOnWall. Shopify and WooCommerce only. |
|
|
211
|
+
| `disabled` | The merchant turned fast wall preview off. Shopify and WooCommerce only. |
|
|
212
|
+
| `invalid-poster-data` | A missing poster URL, or a width or height that could not be read. |
|
|
213
|
+
| `poster-unavailable` | The artwork could not be prepared for preview. |
|
|
214
|
+
| `rate-limited` | Too many requests from this shopper. |
|
|
215
|
+
| `network-error` | The request did not complete. |
|
|
216
|
+
| `unsupported` | The widget on the page is older than this function. See below. |
|
|
217
|
+
|
|
218
|
+
Fast wall preview needs a paid SeeOnWall plan. Calling this function is itself the decision to show
|
|
219
|
+
it, so there is no separate switch for a script-tag storefront; the Shopify and WooCommerce apps keep
|
|
220
|
+
that choice in their own settings. Without a paid plan the call resolves with `not-entitled`.
|
|
221
|
+
|
|
222
|
+
The package fetches the widget at runtime rather than bundling it, so a browser can still hold a
|
|
223
|
+
copy from before this function existed. That copy resolves `unsupported` instead of failing, and it
|
|
224
|
+
keeps working for everything else. Treat `unsupported` as "not available here", not as an error.
|
|
225
|
+
|
|
161
226
|
## Notes
|
|
162
227
|
|
|
163
228
|
**Server rendering is safe.** Every function returns quietly when there is no
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,20 @@ import type { PosterParams, SizeUnit } from './types.js';
|
|
|
2
2
|
export type { PosterParams, SizeUnit };
|
|
3
3
|
/** The safe storefront state returned by the readiness refresh. */
|
|
4
4
|
export type StorefrontSessionState = 'none' | 'creating' | 'ready' | 'expired';
|
|
5
|
+
/**
|
|
6
|
+
* Why a fast wall preview did not open.
|
|
7
|
+
*
|
|
8
|
+
* The snippet gives all of these values but the last one. The package adds
|
|
9
|
+
* `unsupported`. The package gets the snippet at runtime, thus the copy on the
|
|
10
|
+
* page can be older than the package and can have no fast wall preview. Refer
|
|
11
|
+
* to ADR 172.
|
|
12
|
+
*/
|
|
13
|
+
export type CataloguePreviewLaunchResult = {
|
|
14
|
+
opened: true;
|
|
15
|
+
} | {
|
|
16
|
+
opened: false;
|
|
17
|
+
reason: 'no-ready-session' | 'session-expired' | 'inactive-product' | 'invalid-poster-data' | 'poster-unavailable' | 'not-entitled' | 'disabled' | 'rate-limited' | 'network-error' | 'unsupported';
|
|
18
|
+
};
|
|
5
19
|
export interface LoadOptions {
|
|
6
20
|
/** Your shop id. You get the shop id from the SeeOnWall dashboard. */
|
|
7
21
|
shopId: string;
|
|
@@ -31,6 +45,12 @@ interface SnippetApi {
|
|
|
31
45
|
isSessionReady: () => boolean;
|
|
32
46
|
refreshSessionState: () => Promise<StorefrontSessionState>;
|
|
33
47
|
on: (event: 'session-change', listener: () => void) => () => void;
|
|
48
|
+
/**
|
|
49
|
+
* Optional on purpose. A snippet that is older than this function does not
|
|
50
|
+
* have it, and {@link isRestartable} must not refuse such a copy. The refusal
|
|
51
|
+
* would stop the widget for a merchant who does not use fast wall preview.
|
|
52
|
+
*/
|
|
53
|
+
openCataloguePreview?: (params: PosterParams) => Promise<CataloguePreviewLaunchResult>;
|
|
34
54
|
version: string;
|
|
35
55
|
}
|
|
36
56
|
interface SnippetConfig {
|
|
@@ -71,15 +91,42 @@ export declare function close(): void;
|
|
|
71
91
|
* function only if your language selector does not change that attribute.
|
|
72
92
|
*/
|
|
73
93
|
export declare function setLanguage(lang: string): void;
|
|
94
|
+
/**
|
|
95
|
+
* Completes when the widget is available.
|
|
96
|
+
*
|
|
97
|
+
* The promise waits for a load that starts later. It does not complete early
|
|
98
|
+
* because no load is in progress yet. Thus the order of two React effects
|
|
99
|
+
* cannot make a caller miss the widget.
|
|
100
|
+
*
|
|
101
|
+
* The promise does not fail. A load that fails leaves the caller waiting for
|
|
102
|
+
* the next attempt. On the server the promise completes immediately.
|
|
103
|
+
*/
|
|
104
|
+
export declare function whenLoaded(): Promise<void>;
|
|
74
105
|
/**
|
|
75
106
|
* Returns the snippet's cached readiness hint for the current storefront session.
|
|
76
|
-
* It is useful for optional
|
|
107
|
+
* It is useful for optional fast wall preview controls and is never authorization.
|
|
77
108
|
*/
|
|
78
109
|
export declare function isSessionReady(): boolean;
|
|
79
110
|
/** Refreshes the storefront-safe session state from the SeeOnWall API. */
|
|
80
111
|
export declare function refreshSessionState(): Promise<StorefrontSessionState>;
|
|
81
112
|
/** Subscribes to same-origin storefront session changes and returns an unsubscribe function. */
|
|
82
113
|
export declare function on(event: 'session-change', listener: () => void): () => void;
|
|
114
|
+
/**
|
|
115
|
+
* Opens a read-only preview of one poster on the wall that the shopper prepared
|
|
116
|
+
* before. The function does not start the camera flow, thus it needs a session
|
|
117
|
+
* that is already ready.
|
|
118
|
+
*
|
|
119
|
+
* The function does not throw. It gives a reason instead. Show the reason, or
|
|
120
|
+
* hide your control when {@link isSessionReady} is false. A silent call looks
|
|
121
|
+
* like a button that does nothing.
|
|
122
|
+
*
|
|
123
|
+
* The shop must have a paid plan. Without one the call gives `not-entitled`.
|
|
124
|
+
* There is no separate switch for a storefront that loads this package: the
|
|
125
|
+
* call is itself the decision to offer the control. The Shopify and WooCommerce
|
|
126
|
+
* apps keep that choice in their own settings, and give `disabled` when a
|
|
127
|
+
* merchant turns it off there.
|
|
128
|
+
*/
|
|
129
|
+
export declare function openCataloguePreview(params: PosterParams): Promise<CataloguePreviewLaunchResult>;
|
|
83
130
|
/**
|
|
84
131
|
* Stops the snippet. The function removes the buttons, the styles, the
|
|
85
132
|
* observers and the listeners of the snippet.
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAExD,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAA;AAEtC,mEAAmE;AACnE,MAAM,MAAM,sBAAsB,GAAG,MAAM,GAAG,UAAU,GAAG,OAAO,GAAG,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAExD,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAA;AAEtC,mEAAmE;AACnE,MAAM,MAAM,sBAAsB,GAAG,MAAM,GAAG,UAAU,GAAG,OAAO,GAAG,SAAS,CAAA;AAE9E;;;;;;;GAOG;AACH,MAAM,MAAM,4BAA4B,GACpC;IAAE,MAAM,EAAE,IAAI,CAAA;CAAE,GAChB;IACE,MAAM,EAAE,KAAK,CAAA;IACb,MAAM,EACF,kBAAkB,GAClB,iBAAiB,GACjB,kBAAkB,GAClB,qBAAqB,GACrB,oBAAoB,GACpB,cAAc,GACd,UAAU,GACV,cAAc,GACd,eAAe,GACf,aAAa,CAAA;CAClB,CAAA;AAcL,MAAM,WAAW,WAAW;IAC1B,sEAAsE;IACtE,MAAM,EAAE,MAAM,CAAA;IACd,kFAAkF;IAClF,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,4EAA4E;IAC5E,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,iEAAiE;AACjE,UAAU,UAAU;IAClB,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IACzB,KAAK,EAAE,MAAM,OAAO,CAAC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AAC,IAAI,CAAC,CAU1C;AAED;;;GAGG;AACH,wBAAgB,cAAc,IAAI,OAAO,CAExC;AAED,0EAA0E;AAC1E,wBAAgB,mBAAmB,IAAI,OAAO,CAAC,sBAAsB,CAAC,CAKrE;AAED,gGAAgG;AAChG,wBAAgB,EAAE,CAAC,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAe5E;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAiBhG;AAaD;;;;;;;;GAQG;AACH,wBAAgB,OAAO,IAAI,IAAI,CAY9B;AAED;;;GAGG;AACH,wBAAgB,cAAc,IAAI,MAAM,GAAG,IAAI,CAE9C"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const UNSUPPORTED = { opened: false, reason: 'unsupported' };
|
|
1
2
|
/**
|
|
2
3
|
* The location of the snippet file.
|
|
3
4
|
*
|
|
@@ -9,6 +10,24 @@
|
|
|
9
10
|
const DEFAULT_SCRIPT_URL = 'https://seeonwall.com/seeonwall.js';
|
|
10
11
|
let loading = null;
|
|
11
12
|
let api = null;
|
|
13
|
+
/**
|
|
14
|
+
* One promise for every caller that waits for the widget.
|
|
15
|
+
*
|
|
16
|
+
* A wait can start before load() does. React runs the effect of a child before
|
|
17
|
+
* the effect of its parent, thus a component that watches the session usually
|
|
18
|
+
* starts before the component that loads the widget.
|
|
19
|
+
*
|
|
20
|
+
* All callers share one promise. A new promise for each caller would keep one
|
|
21
|
+
* more object for as long as no load occurs.
|
|
22
|
+
*/
|
|
23
|
+
let loadedPromise = null;
|
|
24
|
+
let resolveLoaded = null;
|
|
25
|
+
function announceLoaded() {
|
|
26
|
+
const resolve = resolveLoaded;
|
|
27
|
+
loadedPromise = null;
|
|
28
|
+
resolveLoaded = null;
|
|
29
|
+
resolve?.();
|
|
30
|
+
}
|
|
12
31
|
/**
|
|
13
32
|
* True when the caller wants the widget to run.
|
|
14
33
|
*
|
|
@@ -69,7 +88,10 @@ function isRestartable(candidate) {
|
|
|
69
88
|
typeof candidate.setLanguage === 'function' &&
|
|
70
89
|
typeof candidate.isSessionReady === 'function' &&
|
|
71
90
|
typeof candidate.refreshSessionState === 'function' &&
|
|
72
|
-
typeof candidate.on === 'function'
|
|
91
|
+
typeof candidate.on === 'function'
|
|
92
|
+
// openCataloguePreview is absent from this list on purpose. Refer to the
|
|
93
|
+
// note on that member of the interface.
|
|
94
|
+
);
|
|
73
95
|
}
|
|
74
96
|
/** Stops the widget and forgets it. The caller must set `active` first. */
|
|
75
97
|
function stop() {
|
|
@@ -129,6 +151,7 @@ export function load(options) {
|
|
|
129
151
|
if (!loading) {
|
|
130
152
|
loading = start(options).then((loaded) => {
|
|
131
153
|
api = loaded;
|
|
154
|
+
announceLoaded();
|
|
132
155
|
// A call to destroy() can occur while the widget loads. The widget
|
|
133
156
|
// starts itself when its script runs, thus the loader must stop it now.
|
|
134
157
|
// Before this point there was no widget to stop.
|
|
@@ -186,9 +209,30 @@ export function close() {
|
|
|
186
209
|
export function setLanguage(lang) {
|
|
187
210
|
withApi((loaded) => { loaded.setLanguage(lang); }, 'setLanguage');
|
|
188
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* Completes when the widget is available.
|
|
214
|
+
*
|
|
215
|
+
* The promise waits for a load that starts later. It does not complete early
|
|
216
|
+
* because no load is in progress yet. Thus the order of two React effects
|
|
217
|
+
* cannot make a caller miss the widget.
|
|
218
|
+
*
|
|
219
|
+
* The promise does not fail. A load that fails leaves the caller waiting for
|
|
220
|
+
* the next attempt. On the server the promise completes immediately.
|
|
221
|
+
*/
|
|
222
|
+
export function whenLoaded() {
|
|
223
|
+
if (!isBrowser() || api) {
|
|
224
|
+
return Promise.resolve();
|
|
225
|
+
}
|
|
226
|
+
if (!loadedPromise) {
|
|
227
|
+
loadedPromise = new Promise((resolve) => {
|
|
228
|
+
resolveLoaded = resolve;
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
return loadedPromise;
|
|
232
|
+
}
|
|
189
233
|
/**
|
|
190
234
|
* Returns the snippet's cached readiness hint for the current storefront session.
|
|
191
|
-
* It is useful for optional
|
|
235
|
+
* It is useful for optional fast wall preview controls and is never authorization.
|
|
192
236
|
*/
|
|
193
237
|
export function isSessionReady() {
|
|
194
238
|
return isBrowser() && api?.isSessionReady() === true;
|
|
@@ -209,19 +253,56 @@ export function on(event, listener) {
|
|
|
209
253
|
return () => undefined;
|
|
210
254
|
let cancelled = false;
|
|
211
255
|
let unsubscribe;
|
|
212
|
-
const subscribe = (
|
|
213
|
-
if (!cancelled)
|
|
214
|
-
unsubscribe =
|
|
256
|
+
const subscribe = () => {
|
|
257
|
+
if (!cancelled && api)
|
|
258
|
+
unsubscribe = api.on(event, listener);
|
|
215
259
|
};
|
|
260
|
+
// Through whenLoaded(), and not through `loading`, because a subscription can
|
|
261
|
+
// start before load(). The earlier form did nothing at all in that case.
|
|
216
262
|
if (api)
|
|
217
|
-
subscribe(
|
|
218
|
-
else
|
|
219
|
-
void
|
|
263
|
+
subscribe();
|
|
264
|
+
else
|
|
265
|
+
void whenLoaded().then(subscribe);
|
|
220
266
|
return () => {
|
|
221
267
|
cancelled = true;
|
|
222
268
|
unsubscribe?.();
|
|
223
269
|
};
|
|
224
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* Opens a read-only preview of one poster on the wall that the shopper prepared
|
|
273
|
+
* before. The function does not start the camera flow, thus it needs a session
|
|
274
|
+
* that is already ready.
|
|
275
|
+
*
|
|
276
|
+
* The function does not throw. It gives a reason instead. Show the reason, or
|
|
277
|
+
* hide your control when {@link isSessionReady} is false. A silent call looks
|
|
278
|
+
* like a button that does nothing.
|
|
279
|
+
*
|
|
280
|
+
* The shop must have a paid plan. Without one the call gives `not-entitled`.
|
|
281
|
+
* There is no separate switch for a storefront that loads this package: the
|
|
282
|
+
* call is itself the decision to offer the control. The Shopify and WooCommerce
|
|
283
|
+
* apps keep that choice in their own settings, and give `disabled` when a
|
|
284
|
+
* merchant turns it off there.
|
|
285
|
+
*/
|
|
286
|
+
export function openCataloguePreview(params) {
|
|
287
|
+
if (!isBrowser()) {
|
|
288
|
+
return Promise.resolve(UNSUPPORTED);
|
|
289
|
+
}
|
|
290
|
+
if (api) {
|
|
291
|
+
return launchCataloguePreview(api, params);
|
|
292
|
+
}
|
|
293
|
+
if (loading) {
|
|
294
|
+
return loading.then((loaded) => launchCataloguePreview(loaded, params), () => UNSUPPORTED);
|
|
295
|
+
}
|
|
296
|
+
console.warn('[seeonwall] You called openCataloguePreview() before load(). Call load({ shopId }) first.');
|
|
297
|
+
return Promise.resolve(UNSUPPORTED);
|
|
298
|
+
}
|
|
299
|
+
/** Calls the snippet, or reports that this copy of the snippet is too old. */
|
|
300
|
+
function launchCataloguePreview(loaded, params) {
|
|
301
|
+
if (typeof loaded.openCataloguePreview !== 'function') {
|
|
302
|
+
return Promise.resolve(UNSUPPORTED);
|
|
303
|
+
}
|
|
304
|
+
return loaded.openCataloguePreview(params);
|
|
305
|
+
}
|
|
225
306
|
/**
|
|
226
307
|
* Stops the snippet. The function removes the buttons, the styles, the
|
|
227
308
|
* observers and the listeners of the snippet.
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgCA,MAAM,WAAW,GAAiC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,CAAA;AAE1F;;;;;;;GAOG;AACH,MAAM,kBAAkB,GAAG,oCAAoC,CAAA;AAuD/D,IAAI,OAAO,GAA+B,IAAI,CAAA;AAC9C,IAAI,GAAG,GAAsB,IAAI,CAAA;AAEjC;;;;;;;;;GASG;AACH,IAAI,aAAa,GA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I,EAAE,CAAA;IACR,CAAC;IACD,2EAA2E;IAC3E,2EAA2E;IAC3E,4EAA4E;IAC5E,iDAAiD;AACnD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO,GAAG,EAAE,OAAO,IAAI,IAAI,CAAA;AAC7B,CAAC"}
|
package/dist/react.d.ts
CHANGED
|
@@ -13,6 +13,18 @@ export type { LoadOptions, PosterParams };
|
|
|
13
13
|
* runs this sequence two times in development. The result is the same.
|
|
14
14
|
*/
|
|
15
15
|
export declare function useSeeOnWall(options: LoadOptions): void;
|
|
16
|
+
/**
|
|
17
|
+
* Returns true while the shopper has a wall that is ready for this shop.
|
|
18
|
+
*
|
|
19
|
+
* Use the value to show or hide an optional control, for example a button that
|
|
20
|
+
* calls `openCataloguePreview` from the main entry. The value is a hint of the
|
|
21
|
+
* browser. It is never authorization: the server examines the session again on
|
|
22
|
+
* each action.
|
|
23
|
+
*
|
|
24
|
+
* The value is false on the server and on the first paint. It becomes true
|
|
25
|
+
* after the widget loads, thus your markup is the same on both sides.
|
|
26
|
+
*/
|
|
27
|
+
export declare function useSessionReady(): boolean;
|
|
16
28
|
/** The appearance settings that a merchant can set for one button. */
|
|
17
29
|
export interface SeeOnWallButtonStyleProps {
|
|
18
30
|
/** The background colour of the button, for example `"#b5502a"`. */
|
package/dist/react.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAExD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAE3D,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,CAAA;AAYzC;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CAwBvD;AAED,sEAAsE;AACtE,MAAM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qC;IACrC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,4DAA4D;IAC5D,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,uCAAuC;IACvC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,uEAAuE;IACvE,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;AAED,MAAM,WAAW,oBACf,SAAQ,IAAI,CAAC,YAAY,EAAE,aAAa,CAAC,EACvC,yBAAyB;IAC3B;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;IAC/B,qDAAqD;IACrD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,oDAAoD;IACpD,KAAK,CAAC,EAAE,aAAa,CAAA;CACtB;AAiBD;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,GAAG,YAAY,CA6DzE"}
|
package/dist/react.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect } from 'react';
|
|
3
|
-
import { load, destroy } from './index.js';
|
|
2
|
+
import { useEffect, useSyncExternalStore } from 'react';
|
|
3
|
+
import { load, destroy, isSessionReady, on, whenLoaded } from './index.js';
|
|
4
4
|
/**
|
|
5
5
|
* The number of components that use the widget at this moment.
|
|
6
6
|
*
|
|
@@ -44,6 +44,39 @@ export function useSeeOnWall(options) {
|
|
|
44
44
|
// again with the new value.
|
|
45
45
|
}, [shopId, embedUrl, lang, sizeUnit, scriptUrl]);
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Watches the widget for a session that is ready.
|
|
49
|
+
*
|
|
50
|
+
* The snippet does not report a change when it starts, thus a session that was
|
|
51
|
+
* already in storage becomes visible only when the widget arrives. The
|
|
52
|
+
* subscription below reads the value again at that moment.
|
|
53
|
+
*/
|
|
54
|
+
function subscribeToSession(onStoreChange) {
|
|
55
|
+
let cancelled = false;
|
|
56
|
+
const unsubscribe = on('session-change', onStoreChange);
|
|
57
|
+
void whenLoaded().then(() => {
|
|
58
|
+
if (!cancelled)
|
|
59
|
+
onStoreChange();
|
|
60
|
+
});
|
|
61
|
+
return () => {
|
|
62
|
+
cancelled = true;
|
|
63
|
+
unsubscribe();
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Returns true while the shopper has a wall that is ready for this shop.
|
|
68
|
+
*
|
|
69
|
+
* Use the value to show or hide an optional control, for example a button that
|
|
70
|
+
* calls `openCataloguePreview` from the main entry. The value is a hint of the
|
|
71
|
+
* browser. It is never authorization: the server examines the session again on
|
|
72
|
+
* each action.
|
|
73
|
+
*
|
|
74
|
+
* The value is false on the server and on the first paint. It becomes true
|
|
75
|
+
* after the widget loads, thus your markup is the same on both sides.
|
|
76
|
+
*/
|
|
77
|
+
export function useSessionReady() {
|
|
78
|
+
return useSyncExternalStore(subscribeToSession, isSessionReady, () => false);
|
|
79
|
+
}
|
|
47
80
|
/**
|
|
48
81
|
* Adds a value to the map of attributes, but only when the value is present.
|
|
49
82
|
* An absent attribute and an empty attribute do not mean the same thing to the
|
package/dist/react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.js","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"react.js","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAA;AAEvD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAK1E;;;;;;;GAOG;AACH,IAAI,SAAS,GAA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