@wix/sdk-react 0.1.1 → 0.1.2

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.
@@ -1,12 +1,11 @@
1
1
  // src/index.tsx
2
2
  import * as React from "react";
3
- import { createContext, useEffect, useMemo } from "react";
3
+ import { createContext, useMemo } from "react";
4
4
  import {
5
5
  createClient
6
6
  } from "@wix/api-client";
7
7
  export * from "@wix/api-client";
8
8
  var WixContext = createContext(void 0);
9
- var HostEnvironmentContext = createContext(void 0);
10
9
  function WixProvider(props) {
11
10
  const { children, auth, modules, host } = props;
12
11
  const client = useMemo(
@@ -17,24 +16,7 @@ function WixProvider(props) {
17
16
  }),
18
17
  [auth, modules, host]
19
18
  );
20
- return /* @__PURE__ */ React.createElement(WixContext.Provider, { value: client }, host ? /* @__PURE__ */ React.createElement(HostEnvironmentProvider, { host }, children) : children);
21
- }
22
- function HostEnvironmentProvider(props) {
23
- const [environment, setEnvironment] = React.useState(null);
24
- useEffect(() => {
25
- if (props.host.environment) {
26
- setEnvironment(props.host.environment);
27
- } else {
28
- const handle = props.host.channel.observeEnvironment(setEnvironment);
29
- return () => {
30
- Promise.resolve(handle).then((h) => h.disconnect());
31
- };
32
- }
33
- }, [props.host.environment, props.host.channel]);
34
- if (!environment) {
35
- return null;
36
- }
37
- return /* @__PURE__ */ React.createElement(HostEnvironmentContext.Provider, { value: environment }, props.children);
19
+ return /* @__PURE__ */ React.createElement(WixContext.Provider, { value: client }, children);
38
20
  }
39
21
  function useWix() {
40
22
  const sdk = React.useContext(WixContext);
@@ -53,18 +35,8 @@ function useWixModules(modules) {
53
35
  const sdk = useWix();
54
36
  return useMemo(() => sdk.use(modules), [sdk, modules]);
55
37
  }
56
- function useEnvironment() {
57
- const environment = React.useContext(HostEnvironmentContext);
58
- if (!environment) {
59
- throw new Error(
60
- "Host environment context not found. Make sure to render SDKProvider in the component tree and provide a host parameter"
61
- );
62
- }
63
- return environment;
64
- }
65
38
  export {
66
39
  WixProvider,
67
- useEnvironment,
68
40
  useWix,
69
41
  useWixAuth,
70
42
  useWixModules
package/build/index.d.mts CHANGED
@@ -1,15 +1,15 @@
1
1
  import * as React from 'react';
2
- import { Descriptors, Host, AuthenticationStrategy, AssertHostMatches, WixClient, BuildDescriptors } from '@wix/api-client';
2
+ import { Descriptors, AuthenticationStrategy, AssertHostMatches, WixClient, BuildDescriptors } from '@wix/api-client';
3
3
  export * from '@wix/api-client';
4
4
 
5
- declare function WixProvider<T extends Descriptors<H>, H extends Host<any> = Host>(props: React.PropsWithChildren<{
6
- auth?: AuthenticationStrategy<H>;
7
- modules?: AssertHostMatches<T, H>;
8
- host?: H;
9
- }>): React.JSX.Element;
5
+ declare function WixProvider<T extends Descriptors<Host>, Host = unknown>(props: {
6
+ children: React.ReactNode;
7
+ auth?: AuthenticationStrategy<Host>;
8
+ modules?: AssertHostMatches<T, Host>;
9
+ host?: Host;
10
+ }): React.JSX.Element;
10
11
  declare function useWix<T extends WixClient = WixClient>(): T;
11
12
  declare function useWixAuth<T extends AuthenticationStrategy>(): T;
12
- declare function useWixModules<T extends Descriptors<Host<any>>>(modules: T): BuildDescriptors<T>;
13
- declare function useEnvironment<T>(): T;
13
+ declare function useWixModules<T extends Descriptors<unknown>>(modules: T): BuildDescriptors<T>;
14
14
 
15
- export { WixProvider, useEnvironment, useWix, useWixAuth, useWixModules };
15
+ export { WixProvider, useWix, useWixAuth, useWixModules };
package/build/index.d.ts CHANGED
@@ -1,15 +1,15 @@
1
1
  import * as React from 'react';
2
- import { Descriptors, Host, AuthenticationStrategy, AssertHostMatches, WixClient, BuildDescriptors } from '@wix/api-client';
2
+ import { Descriptors, AuthenticationStrategy, AssertHostMatches, WixClient, BuildDescriptors } from '@wix/api-client';
3
3
  export * from '@wix/api-client';
4
4
 
5
- declare function WixProvider<T extends Descriptors<H>, H extends Host<any> = Host>(props: React.PropsWithChildren<{
6
- auth?: AuthenticationStrategy<H>;
7
- modules?: AssertHostMatches<T, H>;
8
- host?: H;
9
- }>): React.JSX.Element;
5
+ declare function WixProvider<T extends Descriptors<Host>, Host = unknown>(props: {
6
+ children: React.ReactNode;
7
+ auth?: AuthenticationStrategy<Host>;
8
+ modules?: AssertHostMatches<T, Host>;
9
+ host?: Host;
10
+ }): React.JSX.Element;
10
11
  declare function useWix<T extends WixClient = WixClient>(): T;
11
12
  declare function useWixAuth<T extends AuthenticationStrategy>(): T;
12
- declare function useWixModules<T extends Descriptors<Host<any>>>(modules: T): BuildDescriptors<T>;
13
- declare function useEnvironment<T>(): T;
13
+ declare function useWixModules<T extends Descriptors<unknown>>(modules: T): BuildDescriptors<T>;
14
14
 
15
- export { WixProvider, useEnvironment, useWix, useWixAuth, useWixModules };
15
+ export { WixProvider, useWix, useWixAuth, useWixModules };
package/build/index.js CHANGED
@@ -31,7 +31,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
33
  WixProvider: () => WixProvider,
34
- useEnvironment: () => useEnvironment,
35
34
  useWix: () => useWix,
36
35
  useWixAuth: () => useWixAuth,
37
36
  useWixModules: () => useWixModules
@@ -42,7 +41,6 @@ var import_react = require("react");
42
41
  var import_api_client = require("@wix/api-client");
43
42
  __reExport(src_exports, require("@wix/api-client"), module.exports);
44
43
  var WixContext = (0, import_react.createContext)(void 0);
45
- var HostEnvironmentContext = (0, import_react.createContext)(void 0);
46
44
  function WixProvider(props) {
47
45
  const { children, auth, modules, host } = props;
48
46
  const client = (0, import_react.useMemo)(
@@ -53,24 +51,7 @@ function WixProvider(props) {
53
51
  }),
54
52
  [auth, modules, host]
55
53
  );
56
- return /* @__PURE__ */ React.createElement(WixContext.Provider, { value: client }, host ? /* @__PURE__ */ React.createElement(HostEnvironmentProvider, { host }, children) : children);
57
- }
58
- function HostEnvironmentProvider(props) {
59
- const [environment, setEnvironment] = React.useState(null);
60
- (0, import_react.useEffect)(() => {
61
- if (props.host.environment) {
62
- setEnvironment(props.host.environment);
63
- } else {
64
- const handle = props.host.channel.observeEnvironment(setEnvironment);
65
- return () => {
66
- Promise.resolve(handle).then((h) => h.disconnect());
67
- };
68
- }
69
- }, [props.host.environment, props.host.channel]);
70
- if (!environment) {
71
- return null;
72
- }
73
- return /* @__PURE__ */ React.createElement(HostEnvironmentContext.Provider, { value: environment }, props.children);
54
+ return /* @__PURE__ */ React.createElement(WixContext.Provider, { value: client }, children);
74
55
  }
75
56
  function useWix() {
76
57
  const sdk = React.useContext(WixContext);
@@ -89,19 +70,9 @@ function useWixModules(modules) {
89
70
  const sdk = useWix();
90
71
  return (0, import_react.useMemo)(() => sdk.use(modules), [sdk, modules]);
91
72
  }
92
- function useEnvironment() {
93
- const environment = React.useContext(HostEnvironmentContext);
94
- if (!environment) {
95
- throw new Error(
96
- "Host environment context not found. Make sure to render SDKProvider in the component tree and provide a host parameter"
97
- );
98
- }
99
- return environment;
100
- }
101
73
  // Annotate the CommonJS export names for ESM import in node:
102
74
  0 && (module.exports = {
103
75
  WixProvider,
104
- useEnvironment,
105
76
  useWix,
106
77
  useWixAuth,
107
78
  useWixModules,
package/build/index.mjs CHANGED
@@ -1,12 +1,11 @@
1
1
  // src/index.tsx
2
2
  import * as React from "react";
3
- import { createContext, useEffect, useMemo } from "react";
3
+ import { createContext, useMemo } from "react";
4
4
  import {
5
5
  createClient
6
6
  } from "@wix/api-client";
7
7
  export * from "@wix/api-client";
8
8
  var WixContext = createContext(void 0);
9
- var HostEnvironmentContext = createContext(void 0);
10
9
  function WixProvider(props) {
11
10
  const { children, auth, modules, host } = props;
12
11
  const client = useMemo(
@@ -17,24 +16,7 @@ function WixProvider(props) {
17
16
  }),
18
17
  [auth, modules, host]
19
18
  );
20
- return /* @__PURE__ */ React.createElement(WixContext.Provider, { value: client }, host ? /* @__PURE__ */ React.createElement(HostEnvironmentProvider, { host }, children) : children);
21
- }
22
- function HostEnvironmentProvider(props) {
23
- const [environment, setEnvironment] = React.useState(null);
24
- useEffect(() => {
25
- if (props.host.environment) {
26
- setEnvironment(props.host.environment);
27
- } else {
28
- const handle = props.host.channel.observeEnvironment(setEnvironment);
29
- return () => {
30
- Promise.resolve(handle).then((h) => h.disconnect());
31
- };
32
- }
33
- }, [props.host.environment, props.host.channel]);
34
- if (!environment) {
35
- return null;
36
- }
37
- return /* @__PURE__ */ React.createElement(HostEnvironmentContext.Provider, { value: environment }, props.children);
19
+ return /* @__PURE__ */ React.createElement(WixContext.Provider, { value: client }, children);
38
20
  }
39
21
  function useWix() {
40
22
  const sdk = React.useContext(WixContext);
@@ -53,18 +35,8 @@ function useWixModules(modules) {
53
35
  const sdk = useWix();
54
36
  return useMemo(() => sdk.use(modules), [sdk, modules]);
55
37
  }
56
- function useEnvironment() {
57
- const environment = React.useContext(HostEnvironmentContext);
58
- if (!environment) {
59
- throw new Error(
60
- "Host environment context not found. Make sure to render SDKProvider in the component tree and provide a host parameter"
61
- );
62
- }
63
- return environment;
64
- }
65
38
  export {
66
39
  WixProvider,
67
- useEnvironment,
68
40
  useWix,
69
41
  useWixAuth,
70
42
  useWixModules
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/sdk-react",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "license": "UNLICENSED",
5
5
  "main": "build/index.js",
6
6
  "module": "build/index.mjs",
@@ -21,18 +21,18 @@
21
21
  "typecheck": "tsc --noEmit"
22
22
  },
23
23
  "dependencies": {
24
- "@wix/api-client": "1.2.2"
24
+ "@wix/api-client": "1.2.3"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "react": "^16.0.0 || ^17.0.0 || ^18.0.0"
28
28
  },
29
29
  "devDependencies": {
30
- "@swc/core": "^1.3.68",
30
+ "@swc/core": "^1.3.69",
31
31
  "@swc/jest": "^0.2.26",
32
32
  "@testing-library/jest-dom": "^5.16.5",
33
33
  "@testing-library/react": "^14.0.0",
34
- "@types/react": "^18.2.14",
35
- "@wix/ecom": "^1.0.254",
34
+ "@types/react": "^18.2.15",
35
+ "@wix/ecom": "^1.0.263",
36
36
  "eslint": "^7.32.0",
37
37
  "eslint-config-sdk": "0.0.0",
38
38
  "is-ci": "^3.0.1",
@@ -60,5 +60,5 @@
60
60
  "eslintConfig": {
61
61
  "extends": "sdk"
62
62
  },
63
- "falconPackageHash": "57448c2ba81a2bc2eaf017b547e916dabd082896c3879c916819b9e5"
63
+ "falconPackageHash": "696a948d6860320ac2cb1c1151e4b7df403a47000ab1caf70d340e0d"
64
64
  }