@wix/site-service-lightbox 1.0.4 → 1.0.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.
package/README.md CHANGED
@@ -18,8 +18,8 @@ const lightbox = useService(LightboxDefinition)
18
18
 
19
19
  type SignupContext = { source: string }
20
20
 
21
- // Open a lightbox page, passing it some context:
22
- await lightbox.open<SignupContext>({ pageId: 'lightbox-page-id', context: { source: 'signup' } })
21
+ // Open a lightbox by its slug, passing it some context:
22
+ await lightbox.open<SignupContext>({ slug: 'signup', context: { source: 'signup' } })
23
23
 
24
24
  // In a component rendered inside the lightbox:
25
25
  const context = lightbox.getContext<SignupContext>()
@@ -33,8 +33,9 @@ import { LightboxDefinition } from '@wix/site-service-lightbox/definition'
33
33
  import { LightboxService } from '@wix/site-service-lightbox/implementations'
34
34
 
35
35
  createServicesMap().addService(LightboxDefinition, LightboxService, {
36
- open: async ({ pageId, context }) => {
37
- /* open the lightbox page */
36
+ open: async (options) => {
37
+ /* open the lightbox page whose pageUriSEO is options.slug (reject if there is none),
38
+ or, for the deprecated form, the lightbox page options.pageId */
38
39
  },
39
40
  close: () => {
40
41
  /* close the open lightbox */
@@ -49,7 +50,7 @@ createServicesMap().addService(LightboxDefinition, LightboxService, {
49
50
 
50
51
  | Member | Type | Description |
51
52
  |---|---|---|
52
- | `open` | `<TContext = LightboxContext>(options: { pageId: string; context?: TContext }) => Promise<void>` | Opens the lightbox page `pageId` with `context`. Returns the host's promise. |
53
+ | `open` | `<TContext = LightboxContext>(options: { slug: string; context?: TContext } \| { pageId: string; context?: TContext }) => Promise<void>` | Opens the lightbox with `context`. Pass `slug` (the lightbox page's `pageUriSEO`), or the deprecated `pageId`, not both. Returns the host's promise. |
53
54
  | `close` | `() => void` | Closes the currently open lightbox. Fire-and-forget: returns nothing, even if the host's close is async. |
54
55
  | `getContext` | `<TContext = LightboxContext>() => TContext` | Returns the context the open lightbox was opened with. |
55
56
 
@@ -74,3 +75,5 @@ export type ILightboxServiceConfig = {
74
75
 
75
76
  - `open`, `close`, `getContext` — the host's implementations. The service calls them on each use.
76
77
  All three are required; the service has no fallback behavior.
78
+ - `open` receives the options unchanged, with either `slug` or `pageId`, and must handle both. It should
79
+ reject when no lightbox has the slug.
@@ -5,9 +5,27 @@ import type { ServiceDefinition } from '@wix/services-definitions';
5
5
  */
6
6
  export type LightboxContext = unknown;
7
7
  /**
8
- * Options for `open()`, with the popup to open and the value to open it with.
8
+ * Options for `open()` that identify the popup by its slug.
9
9
  */
10
- export type LightboxOpenOptions<TContext = LightboxContext> = {
10
+ export type LightboxOpenBySlugOptions<TContext = LightboxContext> = {
11
+ /**
12
+ * Slug of the popup to open, the `pageUriSEO` of the popup page.
13
+ *
14
+ * @exampleValue 'quick-view'
15
+ */
16
+ slug: string;
17
+ pageId?: never;
18
+ /**
19
+ * Information to pass to the popup. Components inside the popup read it with `getContext()`.
20
+ *
21
+ * @exampleValue `{ "productId": "spring-jacket" }`
22
+ */
23
+ context?: TContext;
24
+ };
25
+ /**
26
+ * Options for `open()` that identify the popup by its page ID.
27
+ */
28
+ export type LightboxOpenByPageIdOptions<TContext = LightboxContext> = {
11
29
  /**
12
30
  * Page ID of the popup to open.
13
31
  *
@@ -16,9 +34,12 @@ export type LightboxOpenOptions<TContext = LightboxContext> = {
16
34
  *
17
35
  * It isn't the page's `appPageId`.
18
36
  *
37
+ * @deprecated Use `slug` instead.
38
+ *
19
39
  * @exampleValue 'k4q7s'
20
40
  */
21
41
  pageId: string;
42
+ slug?: never;
22
43
  /**
23
44
  * Information to pass to the popup. Components inside the popup read it with `getContext()`.
24
45
  *
@@ -26,10 +47,16 @@ export type LightboxOpenOptions<TContext = LightboxContext> = {
26
47
  */
27
48
  context?: TContext;
28
49
  };
50
+ /**
51
+ * Options for `open()`, with the popup to open and the value to open it with. Specify the popup by
52
+ * `slug`. Specifying it by `pageId` still works, but is deprecated.
53
+ */
54
+ export type LightboxOpenOptions<TContext = LightboxContext> = LightboxOpenBySlugOptions<TContext> | LightboxOpenByPageIdOptions<TContext>;
29
55
  /**
30
56
  * Values the host supplies when it creates the service.
31
57
  */
32
58
  export type ILightboxServiceConfig = {
59
+ /** Opens the popup with the slug or the page ID, and rejects when no popup has that slug. */
33
60
  open: (options: LightboxOpenOptions) => Promise<void>;
34
61
  close: () => void;
35
62
  getContext: () => LightboxContext;
@@ -45,8 +72,11 @@ export interface ILightboxService {
45
72
  * and its context is replaced with the `context` you specify, or with `undefined` if you omit
46
73
  * `context`.
47
74
  *
75
+ * Specify the popup by `slug`. Specifying it by `pageId` is deprecated, but still works.
76
+ *
48
77
  * @param options Options for opening the popup.
49
- * @returns Promise that resolves with no value once the popup is open.
78
+ * @returns Promise that resolves with no value once the popup is open. It rejects when the popup
79
+ * can't be opened, for example when no popup has the `slug` you specify.
50
80
  *
51
81
  * @example Open a quick view popup from a button
52
82
  * ```tsx
@@ -63,7 +93,7 @@ export interface ILightboxService {
63
93
  * const openQuickView = () => {
64
94
  * setFailed(false)
65
95
  * lightboxService
66
- * .open<QuickViewContext>({ pageId: 'k4q7s', context: { productId } })
96
+ * .open<QuickViewContext>({ slug: 'quick-view', context: { productId } })
67
97
  * .catch(() => setFailed(true))
68
98
  * }
69
99
  *
@@ -75,29 +105,6 @@ export interface ILightboxService {
75
105
  * )
76
106
  * }
77
107
  * ```
78
- *
79
- * @example Open an app's popup found in the pages service
80
- * ```ts
81
- * // pagesService and lightboxService are resolved from @wix/site-service-pages and
82
- * // @wix/site-service-lightbox, as in the first example. QuickViewContext is your own type for the
83
- * // popup's context.
84
- * function findPopupPageId(appPageId: string): string | undefined {
85
- * const entry = Object.entries(pagesService.pages).find(([, page]) => page.popup && page.appPageId === appPageId)
86
- *
87
- * // The page ID is the map key, not the page's appPageId.
88
- * return entry?.[0]
89
- * }
90
- *
91
- * async function openAppPopup(appPageId: string, context: QuickViewContext) {
92
- * const pageId = findPopupPageId(appPageId)
93
- * if (!pageId) {
94
- * return false
95
- * }
96
- *
97
- * await lightboxService.open({ pageId, context })
98
- * return true
99
- * }
100
- * ```
101
108
  */
102
109
  open<TContext = LightboxContext>(options: LightboxOpenOptions<TContext>): Promise<void>;
103
110
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/definition/index.ts"],"names":[],"mappings":";;;AAAA,oEAAyD;AAiM5C,QAAA,kBAAkB,GAAG,IAAA,oCAAa,EAA2C,4BAA4B,CAAC,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/definition/index.ts"],"names":[],"mappings":";;;AAAA,oEAAyD;AA4M5C,QAAA,kBAAkB,GAAG,IAAA,oCAAa,EAA2C,4BAA4B,CAAC,CAAA"}
@@ -1 +1 @@
1
- export type { ILightboxService, ILightboxServiceConfig, ILightboxDefinition, LightboxContext, LightboxOpenOptions, } from '../definition';
1
+ export type { ILightboxService, ILightboxServiceConfig, ILightboxDefinition, LightboxContext, LightboxOpenOptions, LightboxOpenBySlugOptions, LightboxOpenByPageIdOptions, } from '../definition';
@@ -5,9 +5,27 @@ import type { ServiceDefinition } from '@wix/services-definitions';
5
5
  */
6
6
  export type LightboxContext = unknown;
7
7
  /**
8
- * Options for `open()`, with the popup to open and the value to open it with.
8
+ * Options for `open()` that identify the popup by its slug.
9
9
  */
10
- export type LightboxOpenOptions<TContext = LightboxContext> = {
10
+ export type LightboxOpenBySlugOptions<TContext = LightboxContext> = {
11
+ /**
12
+ * Slug of the popup to open, the `pageUriSEO` of the popup page.
13
+ *
14
+ * @exampleValue 'quick-view'
15
+ */
16
+ slug: string;
17
+ pageId?: never;
18
+ /**
19
+ * Information to pass to the popup. Components inside the popup read it with `getContext()`.
20
+ *
21
+ * @exampleValue `{ "productId": "spring-jacket" }`
22
+ */
23
+ context?: TContext;
24
+ };
25
+ /**
26
+ * Options for `open()` that identify the popup by its page ID.
27
+ */
28
+ export type LightboxOpenByPageIdOptions<TContext = LightboxContext> = {
11
29
  /**
12
30
  * Page ID of the popup to open.
13
31
  *
@@ -16,9 +34,12 @@ export type LightboxOpenOptions<TContext = LightboxContext> = {
16
34
  *
17
35
  * It isn't the page's `appPageId`.
18
36
  *
37
+ * @deprecated Use `slug` instead.
38
+ *
19
39
  * @exampleValue 'k4q7s'
20
40
  */
21
41
  pageId: string;
42
+ slug?: never;
22
43
  /**
23
44
  * Information to pass to the popup. Components inside the popup read it with `getContext()`.
24
45
  *
@@ -26,10 +47,16 @@ export type LightboxOpenOptions<TContext = LightboxContext> = {
26
47
  */
27
48
  context?: TContext;
28
49
  };
50
+ /**
51
+ * Options for `open()`, with the popup to open and the value to open it with. Specify the popup by
52
+ * `slug`. Specifying it by `pageId` still works, but is deprecated.
53
+ */
54
+ export type LightboxOpenOptions<TContext = LightboxContext> = LightboxOpenBySlugOptions<TContext> | LightboxOpenByPageIdOptions<TContext>;
29
55
  /**
30
56
  * Values the host supplies when it creates the service.
31
57
  */
32
58
  export type ILightboxServiceConfig = {
59
+ /** Opens the popup with the slug or the page ID, and rejects when no popup has that slug. */
33
60
  open: (options: LightboxOpenOptions) => Promise<void>;
34
61
  close: () => void;
35
62
  getContext: () => LightboxContext;
@@ -45,8 +72,11 @@ export interface ILightboxService {
45
72
  * and its context is replaced with the `context` you specify, or with `undefined` if you omit
46
73
  * `context`.
47
74
  *
75
+ * Specify the popup by `slug`. Specifying it by `pageId` is deprecated, but still works.
76
+ *
48
77
  * @param options Options for opening the popup.
49
- * @returns Promise that resolves with no value once the popup is open.
78
+ * @returns Promise that resolves with no value once the popup is open. It rejects when the popup
79
+ * can't be opened, for example when no popup has the `slug` you specify.
50
80
  *
51
81
  * @example Open a quick view popup from a button
52
82
  * ```tsx
@@ -63,7 +93,7 @@ export interface ILightboxService {
63
93
  * const openQuickView = () => {
64
94
  * setFailed(false)
65
95
  * lightboxService
66
- * .open<QuickViewContext>({ pageId: 'k4q7s', context: { productId } })
96
+ * .open<QuickViewContext>({ slug: 'quick-view', context: { productId } })
67
97
  * .catch(() => setFailed(true))
68
98
  * }
69
99
  *
@@ -75,29 +105,6 @@ export interface ILightboxService {
75
105
  * )
76
106
  * }
77
107
  * ```
78
- *
79
- * @example Open an app's popup found in the pages service
80
- * ```ts
81
- * // pagesService and lightboxService are resolved from @wix/site-service-pages and
82
- * // @wix/site-service-lightbox, as in the first example. QuickViewContext is your own type for the
83
- * // popup's context.
84
- * function findPopupPageId(appPageId: string): string | undefined {
85
- * const entry = Object.entries(pagesService.pages).find(([, page]) => page.popup && page.appPageId === appPageId)
86
- *
87
- * // The page ID is the map key, not the page's appPageId.
88
- * return entry?.[0]
89
- * }
90
- *
91
- * async function openAppPopup(appPageId: string, context: QuickViewContext) {
92
- * const pageId = findPopupPageId(appPageId)
93
- * if (!pageId) {
94
- * return false
95
- * }
96
- *
97
- * await lightboxService.open({ pageId, context })
98
- * return true
99
- * }
100
- * ```
101
108
  */
102
109
  open<TContext = LightboxContext>(options: LightboxOpenOptions<TContext>): Promise<void>;
103
110
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/definition/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAiMzD,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAA2C,4BAA4B,CAAC,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/definition/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AA4MzD,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAA2C,4BAA4B,CAAC,CAAA"}
@@ -1 +1 @@
1
- export type { ILightboxService, ILightboxServiceConfig, ILightboxDefinition, LightboxContext, LightboxOpenOptions, } from '../definition';
1
+ export type { ILightboxService, ILightboxServiceConfig, ILightboxDefinition, 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.4",
3
+ "version": "1.0.5",
4
4
  "license": "UNLICENSED",
5
5
  "files": [
6
6
  "dist",
@@ -77,5 +77,5 @@
77
77
  ]
78
78
  }
79
79
  },
80
- "falconPackageHash": "199bdec5995c3f1e1d582da1111ff32fbabbf9bbc47a13c567dd1593"
80
+ "falconPackageHash": "7938722bcf6840d5f3e7bd2f8f496f385169197d92de8fe79e96c6d9"
81
81
  }
@@ -8,9 +8,28 @@ import type { ServiceDefinition } from '@wix/services-definitions'
8
8
  export type LightboxContext = unknown
9
9
 
10
10
  /**
11
- * Options for `open()`, with the popup to open and the value to open it with.
11
+ * Options for `open()` that identify the popup by its slug.
12
12
  */
13
- export type LightboxOpenOptions<TContext = LightboxContext> = {
13
+ export type LightboxOpenBySlugOptions<TContext = LightboxContext> = {
14
+ /**
15
+ * Slug of the popup to open, the `pageUriSEO` of the popup page.
16
+ *
17
+ * @exampleValue 'quick-view'
18
+ */
19
+ slug: string
20
+ pageId?: never
21
+ /**
22
+ * Information to pass to the popup. Components inside the popup read it with `getContext()`.
23
+ *
24
+ * @exampleValue `{ "productId": "spring-jacket" }`
25
+ */
26
+ context?: TContext
27
+ }
28
+
29
+ /**
30
+ * Options for `open()` that identify the popup by its page ID.
31
+ */
32
+ export type LightboxOpenByPageIdOptions<TContext = LightboxContext> = {
14
33
  /**
15
34
  * Page ID of the popup to open.
16
35
  *
@@ -19,9 +38,12 @@ export type LightboxOpenOptions<TContext = LightboxContext> = {
19
38
  *
20
39
  * It isn't the page's `appPageId`.
21
40
  *
41
+ * @deprecated Use `slug` instead.
42
+ *
22
43
  * @exampleValue 'k4q7s'
23
44
  */
24
45
  pageId: string
46
+ slug?: never
25
47
  /**
26
48
  * Information to pass to the popup. Components inside the popup read it with `getContext()`.
27
49
  *
@@ -30,10 +52,19 @@ export type LightboxOpenOptions<TContext = LightboxContext> = {
30
52
  context?: TContext
31
53
  }
32
54
 
55
+ /**
56
+ * Options for `open()`, with the popup to open and the value to open it with. Specify the popup by
57
+ * `slug`. Specifying it by `pageId` still works, but is deprecated.
58
+ */
59
+ export type LightboxOpenOptions<TContext = LightboxContext> =
60
+ | LightboxOpenBySlugOptions<TContext>
61
+ | LightboxOpenByPageIdOptions<TContext>
62
+
33
63
  /**
34
64
  * Values the host supplies when it creates the service.
35
65
  */
36
66
  export type ILightboxServiceConfig = {
67
+ /** Opens the popup with the slug or the page ID, and rejects when no popup has that slug. */
37
68
  open: (options: LightboxOpenOptions) => Promise<void>
38
69
  close: () => void
39
70
  getContext: () => LightboxContext
@@ -50,8 +81,11 @@ export interface ILightboxService {
50
81
  * and its context is replaced with the `context` you specify, or with `undefined` if you omit
51
82
  * `context`.
52
83
  *
84
+ * Specify the popup by `slug`. Specifying it by `pageId` is deprecated, but still works.
85
+ *
53
86
  * @param options Options for opening the popup.
54
- * @returns Promise that resolves with no value once the popup is open.
87
+ * @returns Promise that resolves with no value once the popup is open. It rejects when the popup
88
+ * can't be opened, for example when no popup has the `slug` you specify.
55
89
  *
56
90
  * @example Open a quick view popup from a button
57
91
  * ```tsx
@@ -68,7 +102,7 @@ export interface ILightboxService {
68
102
  * const openQuickView = () => {
69
103
  * setFailed(false)
70
104
  * lightboxService
71
- * .open<QuickViewContext>({ pageId: 'k4q7s', context: { productId } })
105
+ * .open<QuickViewContext>({ slug: 'quick-view', context: { productId } })
72
106
  * .catch(() => setFailed(true))
73
107
  * }
74
108
  *
@@ -80,29 +114,6 @@ export interface ILightboxService {
80
114
  * )
81
115
  * }
82
116
  * ```
83
- *
84
- * @example Open an app's popup found in the pages service
85
- * ```ts
86
- * // pagesService and lightboxService are resolved from @wix/site-service-pages and
87
- * // @wix/site-service-lightbox, as in the first example. QuickViewContext is your own type for the
88
- * // popup's context.
89
- * function findPopupPageId(appPageId: string): string | undefined {
90
- * const entry = Object.entries(pagesService.pages).find(([, page]) => page.popup && page.appPageId === appPageId)
91
- *
92
- * // The page ID is the map key, not the page's appPageId.
93
- * return entry?.[0]
94
- * }
95
- *
96
- * async function openAppPopup(appPageId: string, context: QuickViewContext) {
97
- * const pageId = findPopupPageId(appPageId)
98
- * if (!pageId) {
99
- * return false
100
- * }
101
- *
102
- * await lightboxService.open({ pageId, context })
103
- * return true
104
- * }
105
- * ```
106
117
  */
107
118
  open<TContext = LightboxContext>(options: LightboxOpenOptions<TContext>): Promise<void>
108
119
  /**
@@ -4,4 +4,6 @@ export type {
4
4
  ILightboxDefinition,
5
5
  LightboxContext,
6
6
  LightboxOpenOptions,
7
+ LightboxOpenBySlugOptions,
8
+ LightboxOpenByPageIdOptions,
7
9
  } from '../definition'