@wix/site-service-lightbox 1.0.5 → 2.0.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 +23 -14
- package/cjs/build/definition/index.d.ts +26 -25
- package/cjs/build/definition/index.js.map +1 -1
- package/cjs/build/implementations/lightboxService.js +1 -1
- package/cjs/build/types/index.d.ts +1 -1
- package/dist/definition/index.d.ts +26 -25
- package/dist/definition/index.js.map +1 -1
- package/dist/implementations/lightboxService.js +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +2 -2
- package/src/definition/index.ts +28 -27
- package/src/implementations/lightboxService.ts +1 -1
- package/src/types/index.ts +1 -1
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,17 +50,26 @@ createServicesMap().addService(LightboxDefinition, LightboxService, {
|
|
|
50
50
|
|
|
51
51
|
| Member | Type | Description |
|
|
52
52
|
|---|---|---|
|
|
53
|
-
| `open` | `<
|
|
53
|
+
| `open` | `<TPayload = LightboxPayload>(options: { slug: string; payload?: TPayload } \| { pageId: string; payload?: TPayload }) => Promise<void>` | Opens the lightbox with `payload`. Pass `slug` (the lightbox page's `pageUriSEO`), or the deprecated `pageId`, not both. 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
56
|
|
|
57
57
|
All three are plain methods — this service exposes no property getters.
|
|
58
58
|
|
|
59
|
-
The
|
|
60
|
-
(`
|
|
61
|
-
`
|
|
59
|
+
The payload is opaque to the service: it passes the value through unchanged and never reads it
|
|
60
|
+
(`LightboxPayload` is `unknown`).
|
|
61
|
+
`TPayload` types it for the caller, but nothing checks that `getPayload<TPayload>()` asks for
|
|
62
62
|
the same type the lightbox was opened with; that is the caller's assertion.
|
|
63
63
|
|
|
64
|
+
## Migrating from 1.x
|
|
65
|
+
|
|
66
|
+
2.0.0 renames the value you pass to a lightbox from "context" to "payload", with no aliases:
|
|
67
|
+
|
|
68
|
+
- `open({ slug, context })` becomes `open({ slug, payload })`.
|
|
69
|
+
- `getContext()` becomes `getPayload()`.
|
|
70
|
+
- `LightboxContext` becomes `LightboxPayload`, and the `TContext` type parameter becomes `TPayload`.
|
|
71
|
+
- The host config's `getContext` becomes `getPayload`, and `open` reads `options.payload`.
|
|
72
|
+
|
|
64
73
|
## Configuration
|
|
65
74
|
|
|
66
75
|
`ILightboxServiceConfig`:
|
|
@@ -69,11 +78,11 @@ the same type the lightbox was opened with; that is the caller's assertion.
|
|
|
69
78
|
export type ILightboxServiceConfig = {
|
|
70
79
|
open: (options: LightboxOpenOptions) => Promise<void>
|
|
71
80
|
close: () => void
|
|
72
|
-
|
|
81
|
+
getPayload: () => LightboxPayload
|
|
73
82
|
}
|
|
74
83
|
```
|
|
75
84
|
|
|
76
|
-
- `open`, `close`, `
|
|
85
|
+
- `open`, `close`, `getPayload` — the host's implementations. The service calls them on each use.
|
|
77
86
|
All three are required; the service has no fallback behavior.
|
|
78
87
|
- `open` receives the options unchanged, with either `slug` or `pageId`, and must handle both. It should
|
|
79
88
|
reject when no lightbox has the slug.
|
|
@@ -3,29 +3,30 @@ 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
7
|
/**
|
|
8
8
|
* Options for `open()` that identify the popup by its slug.
|
|
9
9
|
*/
|
|
10
|
-
export type LightboxOpenBySlugOptions<
|
|
10
|
+
export type LightboxOpenBySlugOptions<TPayload = LightboxPayload> = {
|
|
11
11
|
/**
|
|
12
|
-
* Slug of the popup to open, the `pageUriSEO` of the popup page.
|
|
12
|
+
* Slug of the popup to open, the `pageUriSEO` of the popup page. It's the popup's `slug` in
|
|
13
|
+
* `@wix/site-service-pages`.
|
|
13
14
|
*
|
|
14
15
|
* @exampleValue 'quick-view'
|
|
15
16
|
*/
|
|
16
17
|
slug: string;
|
|
17
18
|
pageId?: never;
|
|
18
19
|
/**
|
|
19
|
-
* Information to pass to the popup. Components inside the popup read it with `
|
|
20
|
+
* Information to pass to the popup. Components inside the popup read it with `getPayload()`.
|
|
20
21
|
*
|
|
21
22
|
* @exampleValue `{ "productId": "spring-jacket" }`
|
|
22
23
|
*/
|
|
23
|
-
|
|
24
|
+
payload?: TPayload;
|
|
24
25
|
};
|
|
25
26
|
/**
|
|
26
27
|
* Options for `open()` that identify the popup by its page ID.
|
|
27
28
|
*/
|
|
28
|
-
export type LightboxOpenByPageIdOptions<
|
|
29
|
+
export type LightboxOpenByPageIdOptions<TPayload = LightboxPayload> = {
|
|
29
30
|
/**
|
|
30
31
|
* Page ID of the popup to open.
|
|
31
32
|
*
|
|
@@ -41,17 +42,17 @@ export type LightboxOpenByPageIdOptions<TContext = LightboxContext> = {
|
|
|
41
42
|
pageId: string;
|
|
42
43
|
slug?: never;
|
|
43
44
|
/**
|
|
44
|
-
* Information to pass to the popup. Components inside the popup read it with `
|
|
45
|
+
* Information to pass to the popup. Components inside the popup read it with `getPayload()`.
|
|
45
46
|
*
|
|
46
47
|
* @exampleValue `{ "productId": "spring-jacket" }`
|
|
47
48
|
*/
|
|
48
|
-
|
|
49
|
+
payload?: TPayload;
|
|
49
50
|
};
|
|
50
51
|
/**
|
|
51
52
|
* Options for `open()`, with the popup to open and the value to open it with. Specify the popup by
|
|
52
53
|
* `slug`. Specifying it by `pageId` still works, but is deprecated.
|
|
53
54
|
*/
|
|
54
|
-
export type LightboxOpenOptions<
|
|
55
|
+
export type LightboxOpenOptions<TPayload = LightboxPayload> = LightboxOpenBySlugOptions<TPayload> | LightboxOpenByPageIdOptions<TPayload>;
|
|
55
56
|
/**
|
|
56
57
|
* Values the host supplies when it creates the service.
|
|
57
58
|
*/
|
|
@@ -59,7 +60,7 @@ export type ILightboxServiceConfig = {
|
|
|
59
60
|
/** Opens the popup with the slug or the page ID, and rejects when no popup has that slug. */
|
|
60
61
|
open: (options: LightboxOpenOptions) => Promise<void>;
|
|
61
62
|
close: () => void;
|
|
62
|
-
|
|
63
|
+
getPayload: () => LightboxPayload;
|
|
63
64
|
};
|
|
64
65
|
/**
|
|
65
66
|
* Opens and closes popups on a Wix site, and passes data to the popup that opens.
|
|
@@ -69,8 +70,8 @@ export interface ILightboxService {
|
|
|
69
70
|
* Opens a popup over the current page.
|
|
70
71
|
*
|
|
71
72
|
* Opening a popup closes any popup that's already open. If the popup is already open, it stays open,
|
|
72
|
-
* and its
|
|
73
|
-
* `
|
|
73
|
+
* and its payload is replaced with the `payload` you specify, or with `undefined` if you omit
|
|
74
|
+
* `payload`.
|
|
74
75
|
*
|
|
75
76
|
* Specify the popup by `slug`. Specifying it by `pageId` is deprecated, but still works.
|
|
76
77
|
*
|
|
@@ -84,7 +85,7 @@ export interface ILightboxService {
|
|
|
84
85
|
* import { useService } from '@wix/services-manager-react'
|
|
85
86
|
* import { LightboxDefinition } from '@wix/site-service-lightbox/definition'
|
|
86
87
|
*
|
|
87
|
-
* type
|
|
88
|
+
* type QuickViewPayload = { productId: string }
|
|
88
89
|
*
|
|
89
90
|
* function QuickViewButton({ productId }: { productId: string }) {
|
|
90
91
|
* const lightboxService = useService(LightboxDefinition)
|
|
@@ -93,7 +94,7 @@ export interface ILightboxService {
|
|
|
93
94
|
* const openQuickView = () => {
|
|
94
95
|
* setFailed(false)
|
|
95
96
|
* lightboxService
|
|
96
|
-
* .open<
|
|
97
|
+
* .open<QuickViewPayload>({ slug: 'quick-view', payload: { productId } })
|
|
97
98
|
* .catch(() => setFailed(true))
|
|
98
99
|
* }
|
|
99
100
|
*
|
|
@@ -106,7 +107,7 @@ export interface ILightboxService {
|
|
|
106
107
|
* }
|
|
107
108
|
* ```
|
|
108
109
|
*/
|
|
109
|
-
open<
|
|
110
|
+
open<TPayload = LightboxPayload>(options: LightboxOpenOptions<TPayload>): Promise<void>;
|
|
110
111
|
/**
|
|
111
112
|
* Closes the open popup.
|
|
112
113
|
*
|
|
@@ -153,17 +154,17 @@ export interface ILightboxService {
|
|
|
153
154
|
*/
|
|
154
155
|
close(): void;
|
|
155
156
|
/**
|
|
156
|
-
* Retrieves the
|
|
157
|
+
* Retrieves the payload of the open popup.
|
|
157
158
|
*
|
|
158
|
-
* It returns the
|
|
159
|
+
* It returns the payload of whichever popup is open, regardless of the component that calls it, so call
|
|
159
160
|
* it from a component inside the popup.
|
|
160
161
|
*
|
|
161
|
-
* It takes no arguments. In TypeScript, you can specify the
|
|
162
|
-
* `
|
|
162
|
+
* It takes no arguments. In TypeScript, you can specify the payload's type in angle brackets, as in
|
|
163
|
+
* `getPayload<QuickViewPayload | undefined>()`. Use the type you specified for `payload` in `open()`,
|
|
163
164
|
* plus `undefined`. TypeScript doesn't check that the two match, so a different type gives you wrong
|
|
164
165
|
* types without an error. Without a type, the return type is `unknown`.
|
|
165
166
|
*
|
|
166
|
-
* @returns
|
|
167
|
+
* @returns Payload of the open popup.
|
|
167
168
|
*
|
|
168
169
|
* `undefined` when no popup is open.
|
|
169
170
|
*
|
|
@@ -174,21 +175,21 @@ export interface ILightboxService {
|
|
|
174
175
|
* import { useService } from '@wix/services-manager-react'
|
|
175
176
|
* import { LightboxDefinition } from '@wix/site-service-lightbox/definition'
|
|
176
177
|
*
|
|
177
|
-
* type
|
|
178
|
+
* type QuickViewPayload = { productId: string }
|
|
178
179
|
*
|
|
179
180
|
* function QuickViewDetails() {
|
|
180
181
|
* const lightboxService = useService(LightboxDefinition)
|
|
181
|
-
* const
|
|
182
|
+
* const payload = lightboxService.getPayload<QuickViewPayload | undefined>()
|
|
182
183
|
*
|
|
183
|
-
* if (!
|
|
184
|
+
* if (!payload) {
|
|
184
185
|
* return <p>Choose a product to see its details.</p>
|
|
185
186
|
* }
|
|
186
187
|
*
|
|
187
|
-
* return <ProductSummary productId={
|
|
188
|
+
* return <ProductSummary productId={payload.productId} />
|
|
188
189
|
* }
|
|
189
190
|
* ```
|
|
190
191
|
*/
|
|
191
|
-
|
|
192
|
+
getPayload<TPayload = LightboxPayload>(): TPayload;
|
|
192
193
|
}
|
|
193
194
|
export type ILightboxDefinition = ServiceDefinition<ILightboxService, ILightboxServiceConfig>;
|
|
194
195
|
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;AA6M5C,QAAA,kBAAkB,GAAG,IAAA,oCAAa,EAA2C,4BAA4B,CAAC,CAAA"}
|
|
@@ -9,7 +9,7 @@ exports.LightboxService = (0, services_definitions_1.implementService)(definitio
|
|
|
9
9
|
close: () => {
|
|
10
10
|
config.close();
|
|
11
11
|
},
|
|
12
|
-
|
|
12
|
+
getPayload: () => config.getPayload(),
|
|
13
13
|
};
|
|
14
14
|
});
|
|
15
15
|
//# sourceMappingURL=lightboxService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type { ILightboxService, ILightboxServiceConfig, ILightboxDefinition,
|
|
1
|
+
export type { ILightboxService, ILightboxServiceConfig, ILightboxDefinition, LightboxPayload, LightboxOpenOptions, LightboxOpenBySlugOptions, LightboxOpenByPageIdOptions, } from '../definition';
|
|
@@ -3,29 +3,30 @@ 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
7
|
/**
|
|
8
8
|
* Options for `open()` that identify the popup by its slug.
|
|
9
9
|
*/
|
|
10
|
-
export type LightboxOpenBySlugOptions<
|
|
10
|
+
export type LightboxOpenBySlugOptions<TPayload = LightboxPayload> = {
|
|
11
11
|
/**
|
|
12
|
-
* Slug of the popup to open, the `pageUriSEO` of the popup page.
|
|
12
|
+
* Slug of the popup to open, the `pageUriSEO` of the popup page. It's the popup's `slug` in
|
|
13
|
+
* `@wix/site-service-pages`.
|
|
13
14
|
*
|
|
14
15
|
* @exampleValue 'quick-view'
|
|
15
16
|
*/
|
|
16
17
|
slug: string;
|
|
17
18
|
pageId?: never;
|
|
18
19
|
/**
|
|
19
|
-
* Information to pass to the popup. Components inside the popup read it with `
|
|
20
|
+
* Information to pass to the popup. Components inside the popup read it with `getPayload()`.
|
|
20
21
|
*
|
|
21
22
|
* @exampleValue `{ "productId": "spring-jacket" }`
|
|
22
23
|
*/
|
|
23
|
-
|
|
24
|
+
payload?: TPayload;
|
|
24
25
|
};
|
|
25
26
|
/**
|
|
26
27
|
* Options for `open()` that identify the popup by its page ID.
|
|
27
28
|
*/
|
|
28
|
-
export type LightboxOpenByPageIdOptions<
|
|
29
|
+
export type LightboxOpenByPageIdOptions<TPayload = LightboxPayload> = {
|
|
29
30
|
/**
|
|
30
31
|
* Page ID of the popup to open.
|
|
31
32
|
*
|
|
@@ -41,17 +42,17 @@ export type LightboxOpenByPageIdOptions<TContext = LightboxContext> = {
|
|
|
41
42
|
pageId: string;
|
|
42
43
|
slug?: never;
|
|
43
44
|
/**
|
|
44
|
-
* Information to pass to the popup. Components inside the popup read it with `
|
|
45
|
+
* Information to pass to the popup. Components inside the popup read it with `getPayload()`.
|
|
45
46
|
*
|
|
46
47
|
* @exampleValue `{ "productId": "spring-jacket" }`
|
|
47
48
|
*/
|
|
48
|
-
|
|
49
|
+
payload?: TPayload;
|
|
49
50
|
};
|
|
50
51
|
/**
|
|
51
52
|
* Options for `open()`, with the popup to open and the value to open it with. Specify the popup by
|
|
52
53
|
* `slug`. Specifying it by `pageId` still works, but is deprecated.
|
|
53
54
|
*/
|
|
54
|
-
export type LightboxOpenOptions<
|
|
55
|
+
export type LightboxOpenOptions<TPayload = LightboxPayload> = LightboxOpenBySlugOptions<TPayload> | LightboxOpenByPageIdOptions<TPayload>;
|
|
55
56
|
/**
|
|
56
57
|
* Values the host supplies when it creates the service.
|
|
57
58
|
*/
|
|
@@ -59,7 +60,7 @@ export type ILightboxServiceConfig = {
|
|
|
59
60
|
/** Opens the popup with the slug or the page ID, and rejects when no popup has that slug. */
|
|
60
61
|
open: (options: LightboxOpenOptions) => Promise<void>;
|
|
61
62
|
close: () => void;
|
|
62
|
-
|
|
63
|
+
getPayload: () => LightboxPayload;
|
|
63
64
|
};
|
|
64
65
|
/**
|
|
65
66
|
* Opens and closes popups on a Wix site, and passes data to the popup that opens.
|
|
@@ -69,8 +70,8 @@ export interface ILightboxService {
|
|
|
69
70
|
* Opens a popup over the current page.
|
|
70
71
|
*
|
|
71
72
|
* Opening a popup closes any popup that's already open. If the popup is already open, it stays open,
|
|
72
|
-
* and its
|
|
73
|
-
* `
|
|
73
|
+
* and its payload is replaced with the `payload` you specify, or with `undefined` if you omit
|
|
74
|
+
* `payload`.
|
|
74
75
|
*
|
|
75
76
|
* Specify the popup by `slug`. Specifying it by `pageId` is deprecated, but still works.
|
|
76
77
|
*
|
|
@@ -84,7 +85,7 @@ export interface ILightboxService {
|
|
|
84
85
|
* import { useService } from '@wix/services-manager-react'
|
|
85
86
|
* import { LightboxDefinition } from '@wix/site-service-lightbox/definition'
|
|
86
87
|
*
|
|
87
|
-
* type
|
|
88
|
+
* type QuickViewPayload = { productId: string }
|
|
88
89
|
*
|
|
89
90
|
* function QuickViewButton({ productId }: { productId: string }) {
|
|
90
91
|
* const lightboxService = useService(LightboxDefinition)
|
|
@@ -93,7 +94,7 @@ export interface ILightboxService {
|
|
|
93
94
|
* const openQuickView = () => {
|
|
94
95
|
* setFailed(false)
|
|
95
96
|
* lightboxService
|
|
96
|
-
* .open<
|
|
97
|
+
* .open<QuickViewPayload>({ slug: 'quick-view', payload: { productId } })
|
|
97
98
|
* .catch(() => setFailed(true))
|
|
98
99
|
* }
|
|
99
100
|
*
|
|
@@ -106,7 +107,7 @@ export interface ILightboxService {
|
|
|
106
107
|
* }
|
|
107
108
|
* ```
|
|
108
109
|
*/
|
|
109
|
-
open<
|
|
110
|
+
open<TPayload = LightboxPayload>(options: LightboxOpenOptions<TPayload>): Promise<void>;
|
|
110
111
|
/**
|
|
111
112
|
* Closes the open popup.
|
|
112
113
|
*
|
|
@@ -153,17 +154,17 @@ export interface ILightboxService {
|
|
|
153
154
|
*/
|
|
154
155
|
close(): void;
|
|
155
156
|
/**
|
|
156
|
-
* Retrieves the
|
|
157
|
+
* Retrieves the payload of the open popup.
|
|
157
158
|
*
|
|
158
|
-
* It returns the
|
|
159
|
+
* It returns the payload of whichever popup is open, regardless of the component that calls it, so call
|
|
159
160
|
* it from a component inside the popup.
|
|
160
161
|
*
|
|
161
|
-
* It takes no arguments. In TypeScript, you can specify the
|
|
162
|
-
* `
|
|
162
|
+
* It takes no arguments. In TypeScript, you can specify the payload's type in angle brackets, as in
|
|
163
|
+
* `getPayload<QuickViewPayload | undefined>()`. Use the type you specified for `payload` in `open()`,
|
|
163
164
|
* plus `undefined`. TypeScript doesn't check that the two match, so a different type gives you wrong
|
|
164
165
|
* types without an error. Without a type, the return type is `unknown`.
|
|
165
166
|
*
|
|
166
|
-
* @returns
|
|
167
|
+
* @returns Payload of the open popup.
|
|
167
168
|
*
|
|
168
169
|
* `undefined` when no popup is open.
|
|
169
170
|
*
|
|
@@ -174,21 +175,21 @@ export interface ILightboxService {
|
|
|
174
175
|
* import { useService } from '@wix/services-manager-react'
|
|
175
176
|
* import { LightboxDefinition } from '@wix/site-service-lightbox/definition'
|
|
176
177
|
*
|
|
177
|
-
* type
|
|
178
|
+
* type QuickViewPayload = { productId: string }
|
|
178
179
|
*
|
|
179
180
|
* function QuickViewDetails() {
|
|
180
181
|
* const lightboxService = useService(LightboxDefinition)
|
|
181
|
-
* const
|
|
182
|
+
* const payload = lightboxService.getPayload<QuickViewPayload | undefined>()
|
|
182
183
|
*
|
|
183
|
-
* if (!
|
|
184
|
+
* if (!payload) {
|
|
184
185
|
* return <p>Choose a product to see its details.</p>
|
|
185
186
|
* }
|
|
186
187
|
*
|
|
187
|
-
* return <ProductSummary productId={
|
|
188
|
+
* return <ProductSummary productId={payload.productId} />
|
|
188
189
|
* }
|
|
189
190
|
* ```
|
|
190
191
|
*/
|
|
191
|
-
|
|
192
|
+
getPayload<TPayload = LightboxPayload>(): TPayload;
|
|
192
193
|
}
|
|
193
194
|
export type ILightboxDefinition = ServiceDefinition<ILightboxService, ILightboxServiceConfig>;
|
|
194
195
|
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;AA6MzD,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAA2C,4BAA4B,CAAC,CAAA"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export type { ILightboxService, ILightboxServiceConfig, ILightboxDefinition,
|
|
1
|
+
export type { ILightboxService, ILightboxServiceConfig, ILightboxDefinition, LightboxPayload, LightboxOpenOptions, LightboxOpenBySlugOptions, LightboxOpenByPageIdOptions, } from '../definition';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/site-service-lightbox",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.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": "b35a9b392c11fd370d1fe4bfd7ebab689a58367c71709783ddd00835"
|
|
81
81
|
}
|
package/src/definition/index.ts
CHANGED
|
@@ -5,31 +5,32 @@ 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
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Options for `open()` that identify the popup by its slug.
|
|
12
12
|
*/
|
|
13
|
-
export type LightboxOpenBySlugOptions<
|
|
13
|
+
export type LightboxOpenBySlugOptions<TPayload = LightboxPayload> = {
|
|
14
14
|
/**
|
|
15
|
-
* Slug of the popup to open, the `pageUriSEO` of the popup page.
|
|
15
|
+
* Slug of the popup to open, the `pageUriSEO` of the popup page. It's the popup's `slug` in
|
|
16
|
+
* `@wix/site-service-pages`.
|
|
16
17
|
*
|
|
17
18
|
* @exampleValue 'quick-view'
|
|
18
19
|
*/
|
|
19
20
|
slug: string
|
|
20
21
|
pageId?: never
|
|
21
22
|
/**
|
|
22
|
-
* Information to pass to the popup. Components inside the popup read it with `
|
|
23
|
+
* Information to pass to the popup. Components inside the popup read it with `getPayload()`.
|
|
23
24
|
*
|
|
24
25
|
* @exampleValue `{ "productId": "spring-jacket" }`
|
|
25
26
|
*/
|
|
26
|
-
|
|
27
|
+
payload?: TPayload
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
31
|
* Options for `open()` that identify the popup by its page ID.
|
|
31
32
|
*/
|
|
32
|
-
export type LightboxOpenByPageIdOptions<
|
|
33
|
+
export type LightboxOpenByPageIdOptions<TPayload = LightboxPayload> = {
|
|
33
34
|
/**
|
|
34
35
|
* Page ID of the popup to open.
|
|
35
36
|
*
|
|
@@ -45,20 +46,20 @@ export type LightboxOpenByPageIdOptions<TContext = LightboxContext> = {
|
|
|
45
46
|
pageId: string
|
|
46
47
|
slug?: never
|
|
47
48
|
/**
|
|
48
|
-
* Information to pass to the popup. Components inside the popup read it with `
|
|
49
|
+
* Information to pass to the popup. Components inside the popup read it with `getPayload()`.
|
|
49
50
|
*
|
|
50
51
|
* @exampleValue `{ "productId": "spring-jacket" }`
|
|
51
52
|
*/
|
|
52
|
-
|
|
53
|
+
payload?: TPayload
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
/**
|
|
56
57
|
* Options for `open()`, with the popup to open and the value to open it with. Specify the popup by
|
|
57
58
|
* `slug`. Specifying it by `pageId` still works, but is deprecated.
|
|
58
59
|
*/
|
|
59
|
-
export type LightboxOpenOptions<
|
|
60
|
-
| LightboxOpenBySlugOptions<
|
|
61
|
-
| LightboxOpenByPageIdOptions<
|
|
60
|
+
export type LightboxOpenOptions<TPayload = LightboxPayload> =
|
|
61
|
+
| LightboxOpenBySlugOptions<TPayload>
|
|
62
|
+
| LightboxOpenByPageIdOptions<TPayload>
|
|
62
63
|
|
|
63
64
|
/**
|
|
64
65
|
* Values the host supplies when it creates the service.
|
|
@@ -67,7 +68,7 @@ export type ILightboxServiceConfig = {
|
|
|
67
68
|
/** Opens the popup with the slug or the page ID, and rejects when no popup has that slug. */
|
|
68
69
|
open: (options: LightboxOpenOptions) => Promise<void>
|
|
69
70
|
close: () => void
|
|
70
|
-
|
|
71
|
+
getPayload: () => LightboxPayload
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
/**
|
|
@@ -78,8 +79,8 @@ export interface ILightboxService {
|
|
|
78
79
|
* Opens a popup over the current page.
|
|
79
80
|
*
|
|
80
81
|
* Opening a popup closes any popup that's already open. If the popup is already open, it stays open,
|
|
81
|
-
* and its
|
|
82
|
-
* `
|
|
82
|
+
* and its payload is replaced with the `payload` you specify, or with `undefined` if you omit
|
|
83
|
+
* `payload`.
|
|
83
84
|
*
|
|
84
85
|
* Specify the popup by `slug`. Specifying it by `pageId` is deprecated, but still works.
|
|
85
86
|
*
|
|
@@ -93,7 +94,7 @@ export interface ILightboxService {
|
|
|
93
94
|
* import { useService } from '@wix/services-manager-react'
|
|
94
95
|
* import { LightboxDefinition } from '@wix/site-service-lightbox/definition'
|
|
95
96
|
*
|
|
96
|
-
* type
|
|
97
|
+
* type QuickViewPayload = { productId: string }
|
|
97
98
|
*
|
|
98
99
|
* function QuickViewButton({ productId }: { productId: string }) {
|
|
99
100
|
* const lightboxService = useService(LightboxDefinition)
|
|
@@ -102,7 +103,7 @@ export interface ILightboxService {
|
|
|
102
103
|
* const openQuickView = () => {
|
|
103
104
|
* setFailed(false)
|
|
104
105
|
* lightboxService
|
|
105
|
-
* .open<
|
|
106
|
+
* .open<QuickViewPayload>({ slug: 'quick-view', payload: { productId } })
|
|
106
107
|
* .catch(() => setFailed(true))
|
|
107
108
|
* }
|
|
108
109
|
*
|
|
@@ -115,7 +116,7 @@ export interface ILightboxService {
|
|
|
115
116
|
* }
|
|
116
117
|
* ```
|
|
117
118
|
*/
|
|
118
|
-
open<
|
|
119
|
+
open<TPayload = LightboxPayload>(options: LightboxOpenOptions<TPayload>): Promise<void>
|
|
119
120
|
/**
|
|
120
121
|
* Closes the open popup.
|
|
121
122
|
*
|
|
@@ -162,17 +163,17 @@ export interface ILightboxService {
|
|
|
162
163
|
*/
|
|
163
164
|
close(): void
|
|
164
165
|
/**
|
|
165
|
-
* Retrieves the
|
|
166
|
+
* Retrieves the payload of the open popup.
|
|
166
167
|
*
|
|
167
|
-
* It returns the
|
|
168
|
+
* It returns the payload of whichever popup is open, regardless of the component that calls it, so call
|
|
168
169
|
* it from a component inside the popup.
|
|
169
170
|
*
|
|
170
|
-
* It takes no arguments. In TypeScript, you can specify the
|
|
171
|
-
* `
|
|
171
|
+
* It takes no arguments. In TypeScript, you can specify the payload's type in angle brackets, as in
|
|
172
|
+
* `getPayload<QuickViewPayload | undefined>()`. Use the type you specified for `payload` in `open()`,
|
|
172
173
|
* plus `undefined`. TypeScript doesn't check that the two match, so a different type gives you wrong
|
|
173
174
|
* types without an error. Without a type, the return type is `unknown`.
|
|
174
175
|
*
|
|
175
|
-
* @returns
|
|
176
|
+
* @returns Payload of the open popup.
|
|
176
177
|
*
|
|
177
178
|
* `undefined` when no popup is open.
|
|
178
179
|
*
|
|
@@ -183,21 +184,21 @@ export interface ILightboxService {
|
|
|
183
184
|
* import { useService } from '@wix/services-manager-react'
|
|
184
185
|
* import { LightboxDefinition } from '@wix/site-service-lightbox/definition'
|
|
185
186
|
*
|
|
186
|
-
* type
|
|
187
|
+
* type QuickViewPayload = { productId: string }
|
|
187
188
|
*
|
|
188
189
|
* function QuickViewDetails() {
|
|
189
190
|
* const lightboxService = useService(LightboxDefinition)
|
|
190
|
-
* const
|
|
191
|
+
* const payload = lightboxService.getPayload<QuickViewPayload | undefined>()
|
|
191
192
|
*
|
|
192
|
-
* if (!
|
|
193
|
+
* if (!payload) {
|
|
193
194
|
* return <p>Choose a product to see its details.</p>
|
|
194
195
|
* }
|
|
195
196
|
*
|
|
196
|
-
* return <ProductSummary productId={
|
|
197
|
+
* return <ProductSummary productId={payload.productId} />
|
|
197
198
|
* }
|
|
198
199
|
* ```
|
|
199
200
|
*/
|
|
200
|
-
|
|
201
|
+
getPayload<TPayload = LightboxPayload>(): TPayload
|
|
201
202
|
}
|
|
202
203
|
|
|
203
204
|
export type ILightboxDefinition = ServiceDefinition<ILightboxService, ILightboxServiceConfig>
|