@wix/site-service-lightbox 2.0.0 → 2.1.1

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
@@ -50,26 +50,18 @@ createServicesMap().addService(LightboxDefinition, LightboxService, {
50
50
 
51
51
  | Member | Type | Description |
52
52
  |---|---|---|
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. |
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 three are plain methods — this service exposes no property getters.
58
+ All four are plain methods — this service exposes no property getters.
58
59
 
59
60
  The payload is opaque to the service: it passes the value through unchanged and never reads it
60
- (`LightboxPayload` is `unknown`).
61
+ (`LightboxPayload` is `unknown`; `LightboxContext` is its deprecated alias).
61
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
- ## 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
-
73
65
  ## Configuration
74
66
 
75
67
  `ILightboxServiceConfig`:
@@ -82,7 +74,9 @@ export type ILightboxServiceConfig = {
82
74
  }
83
75
  ```
84
76
 
77
+ - Hosts upgrading from 1.x: `getContext` is renamed `getPayload` (2.0.0), and `open` reads `options.payload`.
85
78
  - `open`, `close`, `getPayload` — the host's implementations. The service calls them on each use.
86
79
  All three are required; the service has no fallback behavior.
87
80
  - `open` receives the options unchanged, with either `slug` or `pageId`, and must handle both. It should
88
- 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`.
@@ -4,6 +4,10 @@ import type { ServiceDefinition } from '@wix/services-definitions';
4
4
  * reading or copying it.
5
5
  */
6
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
  */
@@ -22,6 +26,12 @@ export type LightboxOpenBySlugOptions<TPayload = LightboxPayload> = {
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.
@@ -47,6 +57,12 @@ export type LightboxOpenByPageIdOptions<TPayload = LightboxPayload> = {
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
@@ -57,7 +73,10 @@ export type LightboxOpenOptions<TPayload = LightboxPayload> = LightboxOpenBySlug
57
73
  * Values the host supplies when it creates the service.
58
74
  */
59
75
  export type ILightboxServiceConfig = {
60
- /** Opens the popup with the slug or the page ID, and rejects when no popup has that slug. */
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;
@@ -190,6 +209,12 @@ export interface ILightboxService {
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;AA6M5C,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;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
- getPayload: () => config.getPayload(),
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;AAErC,QAAA,eAAe,GAAG,IAAA,uCAAgB,EAC9C,+BAAkB,EAClB,CAAC,EAAE,MAAM,EAA8C,EAAoB,EAAE;IAC5E,OAAO;QACN,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;QACvC,KAAK,EAAE,GAAG,EAAE;YACX,MAAM,CAAC,KAAK,EAAE,CAAA;QACf,CAAC;QACD,UAAU,EAAE,GAAa,EAAE,CAAC,MAAM,CAAC,UAAU,EAAc;KAC3D,CAAA;AACF,CAAC,CACD,CAAA"}
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, LightboxPayload, LightboxOpenOptions, LightboxOpenBySlugOptions, LightboxOpenByPageIdOptions, } from '../definition';
1
+ export type { ILightboxService, ILightboxServiceConfig, ILightboxDefinition, LightboxPayload, LightboxContext, LightboxOpenOptions, LightboxOpenBySlugOptions, LightboxOpenByPageIdOptions, } from '../definition';
@@ -4,6 +4,10 @@ import type { ServiceDefinition } from '@wix/services-definitions';
4
4
  * reading or copying it.
5
5
  */
6
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
  */
@@ -22,6 +26,12 @@ export type LightboxOpenBySlugOptions<TPayload = LightboxPayload> = {
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.
@@ -47,6 +57,12 @@ export type LightboxOpenByPageIdOptions<TPayload = LightboxPayload> = {
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
@@ -57,7 +73,10 @@ export type LightboxOpenOptions<TPayload = LightboxPayload> = LightboxOpenBySlug
57
73
  * Values the host supplies when it creates the service.
58
74
  */
59
75
  export type ILightboxServiceConfig = {
60
- /** Opens the popup with the slug or the page ID, and rejects when no popup has that slug. */
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;
@@ -190,6 +209,12 @@ export interface ILightboxService {
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;AA6MzD,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;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
- getPayload: () => config.getPayload(),
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;QACvC,KAAK,EAAE,GAAG,EAAE;YACX,MAAM,CAAC,KAAK,EAAE,CAAA;QACf,CAAC;QACD,UAAU,EAAE,GAAa,EAAE,CAAC,MAAM,CAAC,UAAU,EAAc;KAC3D,CAAA;AACF,CAAC,CACD,CAAA"}
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"}
@@ -1 +1 @@
1
- export type { ILightboxService, ILightboxServiceConfig, ILightboxDefinition, LightboxPayload, 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": "2.0.0",
3
+ "version": "2.1.1",
4
4
  "license": "UNLICENSED",
5
5
  "files": [
6
6
  "dist",
@@ -77,5 +77,5 @@
77
77
  ]
78
78
  }
79
79
  },
80
- "falconPackageHash": "b35a9b392c11fd370d1fe4bfd7ebab689a58367c71709783ddd00835"
80
+ "falconPackageHash": "43b10ef0a0cbee94dbe188d6b1262f4bee2284ee51cf16b35058d77a"
81
81
  }
@@ -7,6 +7,11 @@ import type { ServiceDefinition } from '@wix/services-definitions'
7
7
  */
8
8
  export type LightboxPayload = unknown
9
9
 
10
+ /**
11
+ * @deprecated Use `LightboxPayload` instead.
12
+ */
13
+ export type LightboxContext = LightboxPayload
14
+
10
15
  /**
11
16
  * Options for `open()` that identify the popup by its slug.
12
17
  */
@@ -25,6 +30,12 @@ export type LightboxOpenBySlugOptions<TPayload = LightboxPayload> = {
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
  /**
@@ -51,6 +62,12 @@ export type LightboxOpenByPageIdOptions<TPayload = LightboxPayload> = {
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
  /**
@@ -65,7 +82,10 @@ export type LightboxOpenOptions<TPayload = LightboxPayload> =
65
82
  * Values the host supplies when it creates the service.
66
83
  */
67
84
  export type ILightboxServiceConfig = {
68
- /** Opens the popup with the slug or the page ID, and rejects when no popup has that slug. */
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
@@ -199,6 +219,12 @@ export interface ILightboxService {
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
- getPayload: <TPayload>() => config.getPayload() as TPayload,
21
+ getPayload,
22
+ getContext: getPayload,
15
23
  }
16
24
  }
17
25
  )
@@ -3,6 +3,7 @@ export type {
3
3
  ILightboxServiceConfig,
4
4
  ILightboxDefinition,
5
5
  LightboxPayload,
6
+ LightboxContext,
6
7
  LightboxOpenOptions,
7
8
  LightboxOpenBySlugOptions,
8
9
  LightboxOpenByPageIdOptions,