@wix/site-service-lightbox 1.0.6 → 2.1.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 +19 -16
- package/cjs/build/definition/index.d.ts +50 -25
- package/cjs/build/definition/index.js.map +1 -1
- package/cjs/build/implementations/lightboxService.js +9 -2
- package/cjs/build/implementations/lightboxService.js.map +1 -1
- package/cjs/build/types/index.d.ts +1 -1
- package/dist/definition/index.d.ts +50 -25
- package/dist/definition/index.js.map +1 -1
- package/dist/implementations/lightboxService.js +9 -2
- package/dist/implementations/lightboxService.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +2 -2
- package/src/definition/index.ts +53 -27
- package/src/implementations/lightboxService.ts +11 -3
- package/src/types/index.ts +1 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @wix/site-service-lightbox
|
|
2
2
|
|
|
3
|
-
Opens and closes **lightboxes** (popups) and reads the
|
|
3
|
+
Opens and closes **lightboxes** (popups) and reads the payload the open lightbox was
|
|
4
4
|
opened with. Only one lightbox is open at a time. UI & Viewport category.
|
|
5
5
|
|
|
6
6
|
## Install
|
|
@@ -16,13 +16,13 @@ import { LightboxDefinition } from '@wix/site-service-lightbox/definition'
|
|
|
16
16
|
|
|
17
17
|
const lightbox = useService(LightboxDefinition)
|
|
18
18
|
|
|
19
|
-
type
|
|
19
|
+
type SignupPayload = { source: string }
|
|
20
20
|
|
|
21
|
-
// Open a lightbox by its slug, passing it
|
|
22
|
-
await lightbox.open<
|
|
21
|
+
// Open a lightbox by its slug, passing it a payload:
|
|
22
|
+
await lightbox.open<SignupPayload>({ slug: 'signup', payload: { source: 'signup' } })
|
|
23
23
|
|
|
24
24
|
// In a component rendered inside the lightbox:
|
|
25
|
-
const
|
|
25
|
+
const payload = lightbox.getPayload<SignupPayload>()
|
|
26
26
|
lightbox.close()
|
|
27
27
|
```
|
|
28
28
|
|
|
@@ -40,8 +40,8 @@ createServicesMap().addService(LightboxDefinition, LightboxService, {
|
|
|
40
40
|
close: () => {
|
|
41
41
|
/* close the open lightbox */
|
|
42
42
|
},
|
|
43
|
-
|
|
44
|
-
/* return the open lightbox's
|
|
43
|
+
getPayload: () => {
|
|
44
|
+
/* return the open lightbox's payload */
|
|
45
45
|
},
|
|
46
46
|
})
|
|
47
47
|
```
|
|
@@ -50,15 +50,16 @@ createServicesMap().addService(LightboxDefinition, LightboxService, {
|
|
|
50
50
|
|
|
51
51
|
| Member | Type | Description |
|
|
52
52
|
|---|---|---|
|
|
53
|
-
| `open` | `<
|
|
53
|
+
| `open` | `<TPayload = LightboxPayload>(options: { slug: string; payload?: TPayload; context?: TPayload } \| { pageId: string; payload?: TPayload; context?: TPayload }) => Promise<void>` | Opens the lightbox with `payload`. Pass `slug` (the lightbox page's `pageUriSEO`), or the deprecated `pageId`, not both. The deprecated `context` option still works and is ignored when `payload` is set. Returns the host's promise. |
|
|
54
54
|
| `close` | `() => void` | Closes the currently open lightbox. Fire-and-forget: returns nothing, even if the host's close is async. |
|
|
55
|
-
| `
|
|
55
|
+
| `getPayload` | `<TPayload = LightboxPayload>() => TPayload` | Returns the payload the open lightbox was opened with. |
|
|
56
|
+
| `getContext` | `<TPayload = LightboxPayload>() => TPayload` | **Deprecated**, use `getPayload`. Same behavior. |
|
|
56
57
|
|
|
57
|
-
All
|
|
58
|
+
All four are plain methods — this service exposes no property getters.
|
|
58
59
|
|
|
59
|
-
The
|
|
60
|
-
(`
|
|
61
|
-
`
|
|
60
|
+
The payload is opaque to the service: it passes the value through unchanged and never reads it
|
|
61
|
+
(`LightboxPayload` is `unknown`; `LightboxContext` is its deprecated alias).
|
|
62
|
+
`TPayload` types it for the caller, but nothing checks that `getPayload<TPayload>()` asks for
|
|
62
63
|
the same type the lightbox was opened with; that is the caller's assertion.
|
|
63
64
|
|
|
64
65
|
## Configuration
|
|
@@ -69,11 +70,13 @@ the same type the lightbox was opened with; that is the caller's assertion.
|
|
|
69
70
|
export type ILightboxServiceConfig = {
|
|
70
71
|
open: (options: LightboxOpenOptions) => Promise<void>
|
|
71
72
|
close: () => void
|
|
72
|
-
|
|
73
|
+
getPayload: () => LightboxPayload
|
|
73
74
|
}
|
|
74
75
|
```
|
|
75
76
|
|
|
76
|
-
-
|
|
77
|
+
- Hosts upgrading from 1.x: `getContext` is renamed `getPayload` (2.0.0), and `open` reads `options.payload`.
|
|
78
|
+
- `open`, `close`, `getPayload` — the host's implementations. The service calls them on each use.
|
|
77
79
|
All three are required; the service has no fallback behavior.
|
|
78
80
|
- `open` receives the options unchanged, with either `slug` or `pageId`, and must handle both. It should
|
|
79
|
-
reject when no lightbox has the slug.
|
|
81
|
+
reject when no lightbox has the slug. The value is always in `payload`: the service moves the
|
|
82
|
+
deprecated `context` option into `payload` before calling `open`.
|
|
@@ -3,11 +3,15 @@ import type { ServiceDefinition } from '@wix/services-definitions';
|
|
|
3
3
|
* Value you specify when you open a popup. It can be any value. The service passes it through without
|
|
4
4
|
* reading or copying it.
|
|
5
5
|
*/
|
|
6
|
-
export type
|
|
6
|
+
export type LightboxPayload = unknown;
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use `LightboxPayload` instead.
|
|
9
|
+
*/
|
|
10
|
+
export type LightboxContext = LightboxPayload;
|
|
7
11
|
/**
|
|
8
12
|
* Options for `open()` that identify the popup by its slug.
|
|
9
13
|
*/
|
|
10
|
-
export type LightboxOpenBySlugOptions<
|
|
14
|
+
export type LightboxOpenBySlugOptions<TPayload = LightboxPayload> = {
|
|
11
15
|
/**
|
|
12
16
|
* Slug of the popup to open, the `pageUriSEO` of the popup page. It's the popup's `slug` in
|
|
13
17
|
* `@wix/site-service-pages`.
|
|
@@ -17,16 +21,22 @@ export type LightboxOpenBySlugOptions<TContext = LightboxContext> = {
|
|
|
17
21
|
slug: string;
|
|
18
22
|
pageId?: never;
|
|
19
23
|
/**
|
|
20
|
-
* Information to pass to the popup. Components inside the popup read it with `
|
|
24
|
+
* Information to pass to the popup. Components inside the popup read it with `getPayload()`.
|
|
21
25
|
*
|
|
22
26
|
* @exampleValue `{ "productId": "spring-jacket" }`
|
|
23
27
|
*/
|
|
24
|
-
|
|
28
|
+
payload?: TPayload;
|
|
29
|
+
/**
|
|
30
|
+
* Information to pass to the popup. Ignored when you specify `payload`.
|
|
31
|
+
*
|
|
32
|
+
* @deprecated Use `payload` instead.
|
|
33
|
+
*/
|
|
34
|
+
context?: TPayload;
|
|
25
35
|
};
|
|
26
36
|
/**
|
|
27
37
|
* Options for `open()` that identify the popup by its page ID.
|
|
28
38
|
*/
|
|
29
|
-
export type LightboxOpenByPageIdOptions<
|
|
39
|
+
export type LightboxOpenByPageIdOptions<TPayload = LightboxPayload> = {
|
|
30
40
|
/**
|
|
31
41
|
* Page ID of the popup to open.
|
|
32
42
|
*
|
|
@@ -42,25 +52,34 @@ export type LightboxOpenByPageIdOptions<TContext = LightboxContext> = {
|
|
|
42
52
|
pageId: string;
|
|
43
53
|
slug?: never;
|
|
44
54
|
/**
|
|
45
|
-
* Information to pass to the popup. Components inside the popup read it with `
|
|
55
|
+
* Information to pass to the popup. Components inside the popup read it with `getPayload()`.
|
|
46
56
|
*
|
|
47
57
|
* @exampleValue `{ "productId": "spring-jacket" }`
|
|
48
58
|
*/
|
|
49
|
-
|
|
59
|
+
payload?: TPayload;
|
|
60
|
+
/**
|
|
61
|
+
* Information to pass to the popup. Ignored when you specify `payload`.
|
|
62
|
+
*
|
|
63
|
+
* @deprecated Use `payload` instead.
|
|
64
|
+
*/
|
|
65
|
+
context?: TPayload;
|
|
50
66
|
};
|
|
51
67
|
/**
|
|
52
68
|
* Options for `open()`, with the popup to open and the value to open it with. Specify the popup by
|
|
53
69
|
* `slug`. Specifying it by `pageId` still works, but is deprecated.
|
|
54
70
|
*/
|
|
55
|
-
export type LightboxOpenOptions<
|
|
71
|
+
export type LightboxOpenOptions<TPayload = LightboxPayload> = LightboxOpenBySlugOptions<TPayload> | LightboxOpenByPageIdOptions<TPayload>;
|
|
56
72
|
/**
|
|
57
73
|
* Values the host supplies when it creates the service.
|
|
58
74
|
*/
|
|
59
75
|
export type ILightboxServiceConfig = {
|
|
60
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* Opens the popup with the slug or the page ID, and rejects when no popup has that slug. The service
|
|
78
|
+
* passes the value in `payload`, never in the deprecated `context`.
|
|
79
|
+
*/
|
|
61
80
|
open: (options: LightboxOpenOptions) => Promise<void>;
|
|
62
81
|
close: () => void;
|
|
63
|
-
|
|
82
|
+
getPayload: () => LightboxPayload;
|
|
64
83
|
};
|
|
65
84
|
/**
|
|
66
85
|
* Opens and closes popups on a Wix site, and passes data to the popup that opens.
|
|
@@ -70,8 +89,8 @@ export interface ILightboxService {
|
|
|
70
89
|
* Opens a popup over the current page.
|
|
71
90
|
*
|
|
72
91
|
* Opening a popup closes any popup that's already open. If the popup is already open, it stays open,
|
|
73
|
-
* and its
|
|
74
|
-
* `
|
|
92
|
+
* and its payload is replaced with the `payload` you specify, or with `undefined` if you omit
|
|
93
|
+
* `payload`.
|
|
75
94
|
*
|
|
76
95
|
* Specify the popup by `slug`. Specifying it by `pageId` is deprecated, but still works.
|
|
77
96
|
*
|
|
@@ -85,7 +104,7 @@ export interface ILightboxService {
|
|
|
85
104
|
* import { useService } from '@wix/services-manager-react'
|
|
86
105
|
* import { LightboxDefinition } from '@wix/site-service-lightbox/definition'
|
|
87
106
|
*
|
|
88
|
-
* type
|
|
107
|
+
* type QuickViewPayload = { productId: string }
|
|
89
108
|
*
|
|
90
109
|
* function QuickViewButton({ productId }: { productId: string }) {
|
|
91
110
|
* const lightboxService = useService(LightboxDefinition)
|
|
@@ -94,7 +113,7 @@ export interface ILightboxService {
|
|
|
94
113
|
* const openQuickView = () => {
|
|
95
114
|
* setFailed(false)
|
|
96
115
|
* lightboxService
|
|
97
|
-
* .open<
|
|
116
|
+
* .open<QuickViewPayload>({ slug: 'quick-view', payload: { productId } })
|
|
98
117
|
* .catch(() => setFailed(true))
|
|
99
118
|
* }
|
|
100
119
|
*
|
|
@@ -107,7 +126,7 @@ export interface ILightboxService {
|
|
|
107
126
|
* }
|
|
108
127
|
* ```
|
|
109
128
|
*/
|
|
110
|
-
open<
|
|
129
|
+
open<TPayload = LightboxPayload>(options: LightboxOpenOptions<TPayload>): Promise<void>;
|
|
111
130
|
/**
|
|
112
131
|
* Closes the open popup.
|
|
113
132
|
*
|
|
@@ -154,17 +173,17 @@ export interface ILightboxService {
|
|
|
154
173
|
*/
|
|
155
174
|
close(): void;
|
|
156
175
|
/**
|
|
157
|
-
* Retrieves the
|
|
176
|
+
* Retrieves the payload of the open popup.
|
|
158
177
|
*
|
|
159
|
-
* It returns the
|
|
178
|
+
* It returns the payload of whichever popup is open, regardless of the component that calls it, so call
|
|
160
179
|
* it from a component inside the popup.
|
|
161
180
|
*
|
|
162
|
-
* It takes no arguments. In TypeScript, you can specify the
|
|
163
|
-
* `
|
|
181
|
+
* It takes no arguments. In TypeScript, you can specify the payload's type in angle brackets, as in
|
|
182
|
+
* `getPayload<QuickViewPayload | undefined>()`. Use the type you specified for `payload` in `open()`,
|
|
164
183
|
* plus `undefined`. TypeScript doesn't check that the two match, so a different type gives you wrong
|
|
165
184
|
* types without an error. Without a type, the return type is `unknown`.
|
|
166
185
|
*
|
|
167
|
-
* @returns
|
|
186
|
+
* @returns Payload of the open popup.
|
|
168
187
|
*
|
|
169
188
|
* `undefined` when no popup is open.
|
|
170
189
|
*
|
|
@@ -175,21 +194,27 @@ export interface ILightboxService {
|
|
|
175
194
|
* import { useService } from '@wix/services-manager-react'
|
|
176
195
|
* import { LightboxDefinition } from '@wix/site-service-lightbox/definition'
|
|
177
196
|
*
|
|
178
|
-
* type
|
|
197
|
+
* type QuickViewPayload = { productId: string }
|
|
179
198
|
*
|
|
180
199
|
* function QuickViewDetails() {
|
|
181
200
|
* const lightboxService = useService(LightboxDefinition)
|
|
182
|
-
* const
|
|
201
|
+
* const payload = lightboxService.getPayload<QuickViewPayload | undefined>()
|
|
183
202
|
*
|
|
184
|
-
* if (!
|
|
203
|
+
* if (!payload) {
|
|
185
204
|
* return <p>Choose a product to see its details.</p>
|
|
186
205
|
* }
|
|
187
206
|
*
|
|
188
|
-
* return <ProductSummary productId={
|
|
207
|
+
* return <ProductSummary productId={payload.productId} />
|
|
189
208
|
* }
|
|
190
209
|
* ```
|
|
191
210
|
*/
|
|
192
|
-
|
|
211
|
+
getPayload<TPayload = LightboxPayload>(): TPayload;
|
|
212
|
+
/**
|
|
213
|
+
* Retrieves the payload of the open popup.
|
|
214
|
+
*
|
|
215
|
+
* @deprecated Use `getPayload()` instead.
|
|
216
|
+
*/
|
|
217
|
+
getContext<TPayload = LightboxPayload>(): TPayload;
|
|
193
218
|
}
|
|
194
219
|
export type ILightboxDefinition = ServiceDefinition<ILightboxService, ILightboxServiceConfig>;
|
|
195
220
|
export declare const LightboxDefinition: string & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/definition/index.ts"],"names":[],"mappings":";;;AAAA,oEAAyD;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/definition/index.ts"],"names":[],"mappings":";;;AAAA,oEAAyD;AAuO5C,QAAA,kBAAkB,GAAG,IAAA,oCAAa,EAA2C,4BAA4B,CAAC,CAAA"}
|
|
@@ -3,13 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.LightboxService = void 0;
|
|
4
4
|
const services_definitions_1 = require("@wix/services-definitions");
|
|
5
5
|
const definition_1 = require("../definition");
|
|
6
|
+
const withPayloadInsteadOfContext = ({ context, ...options }) => {
|
|
7
|
+
const isPayloadSpecified = 'payload' in options;
|
|
8
|
+
const payload = isPayloadSpecified ? options.payload : context;
|
|
9
|
+
return { ...options, payload };
|
|
10
|
+
};
|
|
6
11
|
exports.LightboxService = (0, services_definitions_1.implementService)(definition_1.LightboxDefinition, ({ config }) => {
|
|
12
|
+
const getPayload = () => config.getPayload();
|
|
7
13
|
return {
|
|
8
|
-
open: (options) => config.open(options),
|
|
14
|
+
open: (options) => config.open(withPayloadInsteadOfContext(options)),
|
|
9
15
|
close: () => {
|
|
10
16
|
config.close();
|
|
11
17
|
},
|
|
12
|
-
|
|
18
|
+
getPayload,
|
|
19
|
+
getContext: getPayload,
|
|
13
20
|
};
|
|
14
21
|
});
|
|
15
22
|
//# sourceMappingURL=lightboxService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lightboxService.js","sourceRoot":"","sources":["../../../src/implementations/lightboxService.ts"],"names":[],"mappings":";;;AAAA,oEAA4D;AAG5D,8CAAkD;
|
|
1
|
+
{"version":3,"file":"lightboxService.js","sourceRoot":"","sources":["../../../src/implementations/lightboxService.ts"],"names":[],"mappings":";;;AAAA,oEAA4D;AAG5D,8CAAkD;AAElD,MAAM,2BAA2B,GAAG,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,EAAuB,EAAuB,EAAE;IACzG,MAAM,kBAAkB,GAAG,SAAS,IAAI,OAAO,CAAA;IAC/C,MAAM,OAAO,GAAG,kBAAkB,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAA;IAC9D,OAAO,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,CAAA;AAC/B,CAAC,CAAA;AAEY,QAAA,eAAe,GAAG,IAAA,uCAAgB,EAC9C,+BAAkB,EAClB,CAAC,EAAE,MAAM,EAA8C,EAAoB,EAAE;IAC5E,MAAM,UAAU,GAAG,GAAa,EAAE,CAAC,MAAM,CAAC,UAAU,EAAc,CAAA;IAClE,OAAO;QACN,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,OAAO,CAAC,CAAC;QACpE,KAAK,EAAE,GAAG,EAAE;YACX,MAAM,CAAC,KAAK,EAAE,CAAA;QACf,CAAC;QACD,UAAU;QACV,UAAU,EAAE,UAAU;KACtB,CAAA;AACF,CAAC,CACD,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type { ILightboxService, ILightboxServiceConfig, ILightboxDefinition, LightboxContext, LightboxOpenOptions, LightboxOpenBySlugOptions, LightboxOpenByPageIdOptions, } from '../definition';
|
|
1
|
+
export type { ILightboxService, ILightboxServiceConfig, ILightboxDefinition, LightboxPayload, LightboxContext, LightboxOpenOptions, LightboxOpenBySlugOptions, LightboxOpenByPageIdOptions, } from '../definition';
|
|
@@ -3,11 +3,15 @@ import type { ServiceDefinition } from '@wix/services-definitions';
|
|
|
3
3
|
* Value you specify when you open a popup. It can be any value. The service passes it through without
|
|
4
4
|
* reading or copying it.
|
|
5
5
|
*/
|
|
6
|
-
export type
|
|
6
|
+
export type LightboxPayload = unknown;
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use `LightboxPayload` instead.
|
|
9
|
+
*/
|
|
10
|
+
export type LightboxContext = LightboxPayload;
|
|
7
11
|
/**
|
|
8
12
|
* Options for `open()` that identify the popup by its slug.
|
|
9
13
|
*/
|
|
10
|
-
export type LightboxOpenBySlugOptions<
|
|
14
|
+
export type LightboxOpenBySlugOptions<TPayload = LightboxPayload> = {
|
|
11
15
|
/**
|
|
12
16
|
* Slug of the popup to open, the `pageUriSEO` of the popup page. It's the popup's `slug` in
|
|
13
17
|
* `@wix/site-service-pages`.
|
|
@@ -17,16 +21,22 @@ export type LightboxOpenBySlugOptions<TContext = LightboxContext> = {
|
|
|
17
21
|
slug: string;
|
|
18
22
|
pageId?: never;
|
|
19
23
|
/**
|
|
20
|
-
* Information to pass to the popup. Components inside the popup read it with `
|
|
24
|
+
* Information to pass to the popup. Components inside the popup read it with `getPayload()`.
|
|
21
25
|
*
|
|
22
26
|
* @exampleValue `{ "productId": "spring-jacket" }`
|
|
23
27
|
*/
|
|
24
|
-
|
|
28
|
+
payload?: TPayload;
|
|
29
|
+
/**
|
|
30
|
+
* Information to pass to the popup. Ignored when you specify `payload`.
|
|
31
|
+
*
|
|
32
|
+
* @deprecated Use `payload` instead.
|
|
33
|
+
*/
|
|
34
|
+
context?: TPayload;
|
|
25
35
|
};
|
|
26
36
|
/**
|
|
27
37
|
* Options for `open()` that identify the popup by its page ID.
|
|
28
38
|
*/
|
|
29
|
-
export type LightboxOpenByPageIdOptions<
|
|
39
|
+
export type LightboxOpenByPageIdOptions<TPayload = LightboxPayload> = {
|
|
30
40
|
/**
|
|
31
41
|
* Page ID of the popup to open.
|
|
32
42
|
*
|
|
@@ -42,25 +52,34 @@ export type LightboxOpenByPageIdOptions<TContext = LightboxContext> = {
|
|
|
42
52
|
pageId: string;
|
|
43
53
|
slug?: never;
|
|
44
54
|
/**
|
|
45
|
-
* Information to pass to the popup. Components inside the popup read it with `
|
|
55
|
+
* Information to pass to the popup. Components inside the popup read it with `getPayload()`.
|
|
46
56
|
*
|
|
47
57
|
* @exampleValue `{ "productId": "spring-jacket" }`
|
|
48
58
|
*/
|
|
49
|
-
|
|
59
|
+
payload?: TPayload;
|
|
60
|
+
/**
|
|
61
|
+
* Information to pass to the popup. Ignored when you specify `payload`.
|
|
62
|
+
*
|
|
63
|
+
* @deprecated Use `payload` instead.
|
|
64
|
+
*/
|
|
65
|
+
context?: TPayload;
|
|
50
66
|
};
|
|
51
67
|
/**
|
|
52
68
|
* Options for `open()`, with the popup to open and the value to open it with. Specify the popup by
|
|
53
69
|
* `slug`. Specifying it by `pageId` still works, but is deprecated.
|
|
54
70
|
*/
|
|
55
|
-
export type LightboxOpenOptions<
|
|
71
|
+
export type LightboxOpenOptions<TPayload = LightboxPayload> = LightboxOpenBySlugOptions<TPayload> | LightboxOpenByPageIdOptions<TPayload>;
|
|
56
72
|
/**
|
|
57
73
|
* Values the host supplies when it creates the service.
|
|
58
74
|
*/
|
|
59
75
|
export type ILightboxServiceConfig = {
|
|
60
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* Opens the popup with the slug or the page ID, and rejects when no popup has that slug. The service
|
|
78
|
+
* passes the value in `payload`, never in the deprecated `context`.
|
|
79
|
+
*/
|
|
61
80
|
open: (options: LightboxOpenOptions) => Promise<void>;
|
|
62
81
|
close: () => void;
|
|
63
|
-
|
|
82
|
+
getPayload: () => LightboxPayload;
|
|
64
83
|
};
|
|
65
84
|
/**
|
|
66
85
|
* Opens and closes popups on a Wix site, and passes data to the popup that opens.
|
|
@@ -70,8 +89,8 @@ export interface ILightboxService {
|
|
|
70
89
|
* Opens a popup over the current page.
|
|
71
90
|
*
|
|
72
91
|
* Opening a popup closes any popup that's already open. If the popup is already open, it stays open,
|
|
73
|
-
* and its
|
|
74
|
-
* `
|
|
92
|
+
* and its payload is replaced with the `payload` you specify, or with `undefined` if you omit
|
|
93
|
+
* `payload`.
|
|
75
94
|
*
|
|
76
95
|
* Specify the popup by `slug`. Specifying it by `pageId` is deprecated, but still works.
|
|
77
96
|
*
|
|
@@ -85,7 +104,7 @@ export interface ILightboxService {
|
|
|
85
104
|
* import { useService } from '@wix/services-manager-react'
|
|
86
105
|
* import { LightboxDefinition } from '@wix/site-service-lightbox/definition'
|
|
87
106
|
*
|
|
88
|
-
* type
|
|
107
|
+
* type QuickViewPayload = { productId: string }
|
|
89
108
|
*
|
|
90
109
|
* function QuickViewButton({ productId }: { productId: string }) {
|
|
91
110
|
* const lightboxService = useService(LightboxDefinition)
|
|
@@ -94,7 +113,7 @@ export interface ILightboxService {
|
|
|
94
113
|
* const openQuickView = () => {
|
|
95
114
|
* setFailed(false)
|
|
96
115
|
* lightboxService
|
|
97
|
-
* .open<
|
|
116
|
+
* .open<QuickViewPayload>({ slug: 'quick-view', payload: { productId } })
|
|
98
117
|
* .catch(() => setFailed(true))
|
|
99
118
|
* }
|
|
100
119
|
*
|
|
@@ -107,7 +126,7 @@ export interface ILightboxService {
|
|
|
107
126
|
* }
|
|
108
127
|
* ```
|
|
109
128
|
*/
|
|
110
|
-
open<
|
|
129
|
+
open<TPayload = LightboxPayload>(options: LightboxOpenOptions<TPayload>): Promise<void>;
|
|
111
130
|
/**
|
|
112
131
|
* Closes the open popup.
|
|
113
132
|
*
|
|
@@ -154,17 +173,17 @@ export interface ILightboxService {
|
|
|
154
173
|
*/
|
|
155
174
|
close(): void;
|
|
156
175
|
/**
|
|
157
|
-
* Retrieves the
|
|
176
|
+
* Retrieves the payload of the open popup.
|
|
158
177
|
*
|
|
159
|
-
* It returns the
|
|
178
|
+
* It returns the payload of whichever popup is open, regardless of the component that calls it, so call
|
|
160
179
|
* it from a component inside the popup.
|
|
161
180
|
*
|
|
162
|
-
* It takes no arguments. In TypeScript, you can specify the
|
|
163
|
-
* `
|
|
181
|
+
* It takes no arguments. In TypeScript, you can specify the payload's type in angle brackets, as in
|
|
182
|
+
* `getPayload<QuickViewPayload | undefined>()`. Use the type you specified for `payload` in `open()`,
|
|
164
183
|
* plus `undefined`. TypeScript doesn't check that the two match, so a different type gives you wrong
|
|
165
184
|
* types without an error. Without a type, the return type is `unknown`.
|
|
166
185
|
*
|
|
167
|
-
* @returns
|
|
186
|
+
* @returns Payload of the open popup.
|
|
168
187
|
*
|
|
169
188
|
* `undefined` when no popup is open.
|
|
170
189
|
*
|
|
@@ -175,21 +194,27 @@ export interface ILightboxService {
|
|
|
175
194
|
* import { useService } from '@wix/services-manager-react'
|
|
176
195
|
* import { LightboxDefinition } from '@wix/site-service-lightbox/definition'
|
|
177
196
|
*
|
|
178
|
-
* type
|
|
197
|
+
* type QuickViewPayload = { productId: string }
|
|
179
198
|
*
|
|
180
199
|
* function QuickViewDetails() {
|
|
181
200
|
* const lightboxService = useService(LightboxDefinition)
|
|
182
|
-
* const
|
|
201
|
+
* const payload = lightboxService.getPayload<QuickViewPayload | undefined>()
|
|
183
202
|
*
|
|
184
|
-
* if (!
|
|
203
|
+
* if (!payload) {
|
|
185
204
|
* return <p>Choose a product to see its details.</p>
|
|
186
205
|
* }
|
|
187
206
|
*
|
|
188
|
-
* return <ProductSummary productId={
|
|
207
|
+
* return <ProductSummary productId={payload.productId} />
|
|
189
208
|
* }
|
|
190
209
|
* ```
|
|
191
210
|
*/
|
|
192
|
-
|
|
211
|
+
getPayload<TPayload = LightboxPayload>(): TPayload;
|
|
212
|
+
/**
|
|
213
|
+
* Retrieves the payload of the open popup.
|
|
214
|
+
*
|
|
215
|
+
* @deprecated Use `getPayload()` instead.
|
|
216
|
+
*/
|
|
217
|
+
getContext<TPayload = LightboxPayload>(): TPayload;
|
|
193
218
|
}
|
|
194
219
|
export type ILightboxDefinition = ServiceDefinition<ILightboxService, ILightboxServiceConfig>;
|
|
195
220
|
export declare const LightboxDefinition: string & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/definition/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/definition/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAuOzD,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAA2C,4BAA4B,CAAC,CAAA"}
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { implementService } from '@wix/services-definitions';
|
|
2
2
|
import { LightboxDefinition } from '../definition';
|
|
3
|
+
const withPayloadInsteadOfContext = ({ context, ...options }) => {
|
|
4
|
+
const isPayloadSpecified = 'payload' in options;
|
|
5
|
+
const payload = isPayloadSpecified ? options.payload : context;
|
|
6
|
+
return { ...options, payload };
|
|
7
|
+
};
|
|
3
8
|
export const LightboxService = implementService(LightboxDefinition, ({ config }) => {
|
|
9
|
+
const getPayload = () => config.getPayload();
|
|
4
10
|
return {
|
|
5
|
-
open: (options) => config.open(options),
|
|
11
|
+
open: (options) => config.open(withPayloadInsteadOfContext(options)),
|
|
6
12
|
close: () => {
|
|
7
13
|
config.close();
|
|
8
14
|
},
|
|
9
|
-
|
|
15
|
+
getPayload,
|
|
16
|
+
getContext: getPayload,
|
|
10
17
|
};
|
|
11
18
|
});
|
|
12
19
|
//# sourceMappingURL=lightboxService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lightboxService.js","sourceRoot":"","sources":["../../src/implementations/lightboxService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAG5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAElD,MAAM,CAAC,MAAM,eAAe,GAAG,gBAAgB,CAC9C,kBAAkB,EAClB,CAAC,EAAE,MAAM,EAA8C,EAAoB,EAAE;IAC5E,OAAO;QACN,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"lightboxService.js","sourceRoot":"","sources":["../../src/implementations/lightboxService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAG5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAElD,MAAM,2BAA2B,GAAG,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,EAAuB,EAAuB,EAAE;IACzG,MAAM,kBAAkB,GAAG,SAAS,IAAI,OAAO,CAAA;IAC/C,MAAM,OAAO,GAAG,kBAAkB,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAA;IAC9D,OAAO,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,CAAA;AAC/B,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,gBAAgB,CAC9C,kBAAkB,EAClB,CAAC,EAAE,MAAM,EAA8C,EAAoB,EAAE;IAC5E,MAAM,UAAU,GAAG,GAAa,EAAE,CAAC,MAAM,CAAC,UAAU,EAAc,CAAA;IAClE,OAAO;QACN,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,OAAO,CAAC,CAAC;QACpE,KAAK,EAAE,GAAG,EAAE;YACX,MAAM,CAAC,KAAK,EAAE,CAAA;QACf,CAAC;QACD,UAAU;QACV,UAAU,EAAE,UAAU;KACtB,CAAA;AACF,CAAC,CACD,CAAA"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export type { ILightboxService, ILightboxServiceConfig, ILightboxDefinition, LightboxContext, LightboxOpenOptions, LightboxOpenBySlugOptions, LightboxOpenByPageIdOptions, } from '../definition';
|
|
1
|
+
export type { ILightboxService, ILightboxServiceConfig, ILightboxDefinition, LightboxPayload, LightboxContext, LightboxOpenOptions, LightboxOpenBySlugOptions, LightboxOpenByPageIdOptions, } from '../definition';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/site-service-lightbox",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
]
|
|
78
78
|
}
|
|
79
79
|
},
|
|
80
|
-
"falconPackageHash": "
|
|
80
|
+
"falconPackageHash": "85ae3c49a94471c9119643e7aeb09af9ac4cedca4c52823caac48bec"
|
|
81
81
|
}
|
package/src/definition/index.ts
CHANGED
|
@@ -5,12 +5,17 @@ import type { ServiceDefinition } from '@wix/services-definitions'
|
|
|
5
5
|
* Value you specify when you open a popup. It can be any value. The service passes it through without
|
|
6
6
|
* reading or copying it.
|
|
7
7
|
*/
|
|
8
|
-
export type
|
|
8
|
+
export type LightboxPayload = unknown
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use `LightboxPayload` instead.
|
|
12
|
+
*/
|
|
13
|
+
export type LightboxContext = LightboxPayload
|
|
9
14
|
|
|
10
15
|
/**
|
|
11
16
|
* Options for `open()` that identify the popup by its slug.
|
|
12
17
|
*/
|
|
13
|
-
export type LightboxOpenBySlugOptions<
|
|
18
|
+
export type LightboxOpenBySlugOptions<TPayload = LightboxPayload> = {
|
|
14
19
|
/**
|
|
15
20
|
* Slug of the popup to open, the `pageUriSEO` of the popup page. It's the popup's `slug` in
|
|
16
21
|
* `@wix/site-service-pages`.
|
|
@@ -20,17 +25,23 @@ export type LightboxOpenBySlugOptions<TContext = LightboxContext> = {
|
|
|
20
25
|
slug: string
|
|
21
26
|
pageId?: never
|
|
22
27
|
/**
|
|
23
|
-
* Information to pass to the popup. Components inside the popup read it with `
|
|
28
|
+
* Information to pass to the popup. Components inside the popup read it with `getPayload()`.
|
|
24
29
|
*
|
|
25
30
|
* @exampleValue `{ "productId": "spring-jacket" }`
|
|
26
31
|
*/
|
|
27
|
-
|
|
32
|
+
payload?: TPayload
|
|
33
|
+
/**
|
|
34
|
+
* Information to pass to the popup. Ignored when you specify `payload`.
|
|
35
|
+
*
|
|
36
|
+
* @deprecated Use `payload` instead.
|
|
37
|
+
*/
|
|
38
|
+
context?: TPayload
|
|
28
39
|
}
|
|
29
40
|
|
|
30
41
|
/**
|
|
31
42
|
* Options for `open()` that identify the popup by its page ID.
|
|
32
43
|
*/
|
|
33
|
-
export type LightboxOpenByPageIdOptions<
|
|
44
|
+
export type LightboxOpenByPageIdOptions<TPayload = LightboxPayload> = {
|
|
34
45
|
/**
|
|
35
46
|
* Page ID of the popup to open.
|
|
36
47
|
*
|
|
@@ -46,29 +57,38 @@ export type LightboxOpenByPageIdOptions<TContext = LightboxContext> = {
|
|
|
46
57
|
pageId: string
|
|
47
58
|
slug?: never
|
|
48
59
|
/**
|
|
49
|
-
* Information to pass to the popup. Components inside the popup read it with `
|
|
60
|
+
* Information to pass to the popup. Components inside the popup read it with `getPayload()`.
|
|
50
61
|
*
|
|
51
62
|
* @exampleValue `{ "productId": "spring-jacket" }`
|
|
52
63
|
*/
|
|
53
|
-
|
|
64
|
+
payload?: TPayload
|
|
65
|
+
/**
|
|
66
|
+
* Information to pass to the popup. Ignored when you specify `payload`.
|
|
67
|
+
*
|
|
68
|
+
* @deprecated Use `payload` instead.
|
|
69
|
+
*/
|
|
70
|
+
context?: TPayload
|
|
54
71
|
}
|
|
55
72
|
|
|
56
73
|
/**
|
|
57
74
|
* Options for `open()`, with the popup to open and the value to open it with. Specify the popup by
|
|
58
75
|
* `slug`. Specifying it by `pageId` still works, but is deprecated.
|
|
59
76
|
*/
|
|
60
|
-
export type LightboxOpenOptions<
|
|
61
|
-
| LightboxOpenBySlugOptions<
|
|
62
|
-
| LightboxOpenByPageIdOptions<
|
|
77
|
+
export type LightboxOpenOptions<TPayload = LightboxPayload> =
|
|
78
|
+
| LightboxOpenBySlugOptions<TPayload>
|
|
79
|
+
| LightboxOpenByPageIdOptions<TPayload>
|
|
63
80
|
|
|
64
81
|
/**
|
|
65
82
|
* Values the host supplies when it creates the service.
|
|
66
83
|
*/
|
|
67
84
|
export type ILightboxServiceConfig = {
|
|
68
|
-
/**
|
|
85
|
+
/**
|
|
86
|
+
* Opens the popup with the slug or the page ID, and rejects when no popup has that slug. The service
|
|
87
|
+
* passes the value in `payload`, never in the deprecated `context`.
|
|
88
|
+
*/
|
|
69
89
|
open: (options: LightboxOpenOptions) => Promise<void>
|
|
70
90
|
close: () => void
|
|
71
|
-
|
|
91
|
+
getPayload: () => LightboxPayload
|
|
72
92
|
}
|
|
73
93
|
|
|
74
94
|
/**
|
|
@@ -79,8 +99,8 @@ export interface ILightboxService {
|
|
|
79
99
|
* Opens a popup over the current page.
|
|
80
100
|
*
|
|
81
101
|
* Opening a popup closes any popup that's already open. If the popup is already open, it stays open,
|
|
82
|
-
* and its
|
|
83
|
-
* `
|
|
102
|
+
* and its payload is replaced with the `payload` you specify, or with `undefined` if you omit
|
|
103
|
+
* `payload`.
|
|
84
104
|
*
|
|
85
105
|
* Specify the popup by `slug`. Specifying it by `pageId` is deprecated, but still works.
|
|
86
106
|
*
|
|
@@ -94,7 +114,7 @@ export interface ILightboxService {
|
|
|
94
114
|
* import { useService } from '@wix/services-manager-react'
|
|
95
115
|
* import { LightboxDefinition } from '@wix/site-service-lightbox/definition'
|
|
96
116
|
*
|
|
97
|
-
* type
|
|
117
|
+
* type QuickViewPayload = { productId: string }
|
|
98
118
|
*
|
|
99
119
|
* function QuickViewButton({ productId }: { productId: string }) {
|
|
100
120
|
* const lightboxService = useService(LightboxDefinition)
|
|
@@ -103,7 +123,7 @@ export interface ILightboxService {
|
|
|
103
123
|
* const openQuickView = () => {
|
|
104
124
|
* setFailed(false)
|
|
105
125
|
* lightboxService
|
|
106
|
-
* .open<
|
|
126
|
+
* .open<QuickViewPayload>({ slug: 'quick-view', payload: { productId } })
|
|
107
127
|
* .catch(() => setFailed(true))
|
|
108
128
|
* }
|
|
109
129
|
*
|
|
@@ -116,7 +136,7 @@ export interface ILightboxService {
|
|
|
116
136
|
* }
|
|
117
137
|
* ```
|
|
118
138
|
*/
|
|
119
|
-
open<
|
|
139
|
+
open<TPayload = LightboxPayload>(options: LightboxOpenOptions<TPayload>): Promise<void>
|
|
120
140
|
/**
|
|
121
141
|
* Closes the open popup.
|
|
122
142
|
*
|
|
@@ -163,17 +183,17 @@ export interface ILightboxService {
|
|
|
163
183
|
*/
|
|
164
184
|
close(): void
|
|
165
185
|
/**
|
|
166
|
-
* Retrieves the
|
|
186
|
+
* Retrieves the payload of the open popup.
|
|
167
187
|
*
|
|
168
|
-
* It returns the
|
|
188
|
+
* It returns the payload of whichever popup is open, regardless of the component that calls it, so call
|
|
169
189
|
* it from a component inside the popup.
|
|
170
190
|
*
|
|
171
|
-
* It takes no arguments. In TypeScript, you can specify the
|
|
172
|
-
* `
|
|
191
|
+
* It takes no arguments. In TypeScript, you can specify the payload's type in angle brackets, as in
|
|
192
|
+
* `getPayload<QuickViewPayload | undefined>()`. Use the type you specified for `payload` in `open()`,
|
|
173
193
|
* plus `undefined`. TypeScript doesn't check that the two match, so a different type gives you wrong
|
|
174
194
|
* types without an error. Without a type, the return type is `unknown`.
|
|
175
195
|
*
|
|
176
|
-
* @returns
|
|
196
|
+
* @returns Payload of the open popup.
|
|
177
197
|
*
|
|
178
198
|
* `undefined` when no popup is open.
|
|
179
199
|
*
|
|
@@ -184,21 +204,27 @@ export interface ILightboxService {
|
|
|
184
204
|
* import { useService } from '@wix/services-manager-react'
|
|
185
205
|
* import { LightboxDefinition } from '@wix/site-service-lightbox/definition'
|
|
186
206
|
*
|
|
187
|
-
* type
|
|
207
|
+
* type QuickViewPayload = { productId: string }
|
|
188
208
|
*
|
|
189
209
|
* function QuickViewDetails() {
|
|
190
210
|
* const lightboxService = useService(LightboxDefinition)
|
|
191
|
-
* const
|
|
211
|
+
* const payload = lightboxService.getPayload<QuickViewPayload | undefined>()
|
|
192
212
|
*
|
|
193
|
-
* if (!
|
|
213
|
+
* if (!payload) {
|
|
194
214
|
* return <p>Choose a product to see its details.</p>
|
|
195
215
|
* }
|
|
196
216
|
*
|
|
197
|
-
* return <ProductSummary productId={
|
|
217
|
+
* return <ProductSummary productId={payload.productId} />
|
|
198
218
|
* }
|
|
199
219
|
* ```
|
|
200
220
|
*/
|
|
201
|
-
|
|
221
|
+
getPayload<TPayload = LightboxPayload>(): TPayload
|
|
222
|
+
/**
|
|
223
|
+
* Retrieves the payload of the open popup.
|
|
224
|
+
*
|
|
225
|
+
* @deprecated Use `getPayload()` instead.
|
|
226
|
+
*/
|
|
227
|
+
getContext<TPayload = LightboxPayload>(): TPayload
|
|
202
228
|
}
|
|
203
229
|
|
|
204
230
|
export type ILightboxDefinition = ServiceDefinition<ILightboxService, ILightboxServiceConfig>
|
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
import { implementService } from '@wix/services-definitions'
|
|
2
2
|
import type { ServiceFactoryOpts } from '@wix/services-definitions'
|
|
3
|
-
import type { ILightboxService, ILightboxServiceConfig } from '../definition'
|
|
3
|
+
import type { ILightboxService, ILightboxServiceConfig, LightboxOpenOptions } from '../definition'
|
|
4
4
|
import { LightboxDefinition } from '../definition'
|
|
5
5
|
|
|
6
|
+
const withPayloadInsteadOfContext = ({ context, ...options }: LightboxOpenOptions): LightboxOpenOptions => {
|
|
7
|
+
const isPayloadSpecified = 'payload' in options
|
|
8
|
+
const payload = isPayloadSpecified ? options.payload : context
|
|
9
|
+
return { ...options, payload }
|
|
10
|
+
}
|
|
11
|
+
|
|
6
12
|
export const LightboxService = implementService(
|
|
7
13
|
LightboxDefinition,
|
|
8
14
|
({ config }: ServiceFactoryOpts<ILightboxServiceConfig>): ILightboxService => {
|
|
15
|
+
const getPayload = <TPayload>() => config.getPayload() as TPayload
|
|
9
16
|
return {
|
|
10
|
-
open: (options) => config.open(options),
|
|
17
|
+
open: (options) => config.open(withPayloadInsteadOfContext(options)),
|
|
11
18
|
close: () => {
|
|
12
19
|
config.close()
|
|
13
20
|
},
|
|
14
|
-
|
|
21
|
+
getPayload,
|
|
22
|
+
getContext: getPayload,
|
|
15
23
|
}
|
|
16
24
|
}
|
|
17
25
|
)
|