@wix/sdk-react 0.1.0 → 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.
- package/build/browser/index.mjs +3 -30
- package/build/index.d.mts +10 -9
- package/build/index.d.ts +10 -9
- package/build/index.js +5 -31
- package/build/index.mjs +3 -30
- package/package.json +6 -6
package/build/browser/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// src/index.tsx
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import { createContext,
|
|
3
|
+
import { createContext, useMemo } from "react";
|
|
4
4
|
import {
|
|
5
5
|
createClient
|
|
6
6
|
} from "@wix/api-client";
|
|
7
|
+
export * from "@wix/api-client";
|
|
7
8
|
var WixContext = createContext(void 0);
|
|
8
|
-
var HostEnvironmentContext = createContext(void 0);
|
|
9
9
|
function WixProvider(props) {
|
|
10
10
|
const { children, auth, modules, host } = props;
|
|
11
11
|
const client = useMemo(
|
|
@@ -16,24 +16,7 @@ function WixProvider(props) {
|
|
|
16
16
|
}),
|
|
17
17
|
[auth, modules, host]
|
|
18
18
|
);
|
|
19
|
-
return /* @__PURE__ */ React.createElement(WixContext.Provider, { value: client },
|
|
20
|
-
}
|
|
21
|
-
function HostEnvironmentProvider(props) {
|
|
22
|
-
const [environment, setEnvironment] = React.useState(null);
|
|
23
|
-
useEffect(() => {
|
|
24
|
-
if (props.host.environment) {
|
|
25
|
-
setEnvironment(props.host.environment);
|
|
26
|
-
} else {
|
|
27
|
-
const handle = props.host.channel.observeEnvironment(setEnvironment);
|
|
28
|
-
return () => {
|
|
29
|
-
Promise.resolve(handle).then((h) => h.disconnect());
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
}, [props.host.environment, props.host.channel]);
|
|
33
|
-
if (!environment) {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
return /* @__PURE__ */ React.createElement(HostEnvironmentContext.Provider, { value: environment }, props.children);
|
|
19
|
+
return /* @__PURE__ */ React.createElement(WixContext.Provider, { value: client }, children);
|
|
37
20
|
}
|
|
38
21
|
function useWix() {
|
|
39
22
|
const sdk = React.useContext(WixContext);
|
|
@@ -52,18 +35,8 @@ function useWixModules(modules) {
|
|
|
52
35
|
const sdk = useWix();
|
|
53
36
|
return useMemo(() => sdk.use(modules), [sdk, modules]);
|
|
54
37
|
}
|
|
55
|
-
function useEnvironment() {
|
|
56
|
-
const environment = React.useContext(HostEnvironmentContext);
|
|
57
|
-
if (!environment) {
|
|
58
|
-
throw new Error(
|
|
59
|
-
"Host environment context not found. Make sure to render SDKProvider in the component tree and provide a host parameter"
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
return environment;
|
|
63
|
-
}
|
|
64
38
|
export {
|
|
65
39
|
WixProvider,
|
|
66
|
-
useEnvironment,
|
|
67
40
|
useWix,
|
|
68
41
|
useWixAuth,
|
|
69
42
|
useWixModules
|
package/build/index.d.mts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { Descriptors,
|
|
2
|
+
import { Descriptors, AuthenticationStrategy, AssertHostMatches, WixClient, BuildDescriptors } from '@wix/api-client';
|
|
3
|
+
export * from '@wix/api-client';
|
|
3
4
|
|
|
4
|
-
declare function WixProvider<T extends Descriptors<
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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;
|
|
9
11
|
declare function useWix<T extends WixClient = WixClient>(): T;
|
|
10
12
|
declare function useWixAuth<T extends AuthenticationStrategy>(): T;
|
|
11
|
-
declare function useWixModules<T extends Descriptors<
|
|
12
|
-
declare function useEnvironment<T>(): T;
|
|
13
|
+
declare function useWixModules<T extends Descriptors<unknown>>(modules: T): BuildDescriptors<T>;
|
|
13
14
|
|
|
14
|
-
export { WixProvider,
|
|
15
|
+
export { WixProvider, useWix, useWixAuth, useWixModules };
|
package/build/index.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { Descriptors,
|
|
2
|
+
import { Descriptors, AuthenticationStrategy, AssertHostMatches, WixClient, BuildDescriptors } from '@wix/api-client';
|
|
3
|
+
export * from '@wix/api-client';
|
|
3
4
|
|
|
4
|
-
declare function WixProvider<T extends Descriptors<
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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;
|
|
9
11
|
declare function useWix<T extends WixClient = WixClient>(): T;
|
|
10
12
|
declare function useWixAuth<T extends AuthenticationStrategy>(): T;
|
|
11
|
-
declare function useWixModules<T extends Descriptors<
|
|
12
|
-
declare function useEnvironment<T>(): T;
|
|
13
|
+
declare function useWixModules<T extends Descriptors<unknown>>(modules: T): BuildDescriptors<T>;
|
|
13
14
|
|
|
14
|
-
export { WixProvider,
|
|
15
|
+
export { WixProvider, useWix, useWixAuth, useWixModules };
|
package/build/index.js
CHANGED
|
@@ -16,6 +16,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
}
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
20
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
21
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
22
|
// file that has been converted to a CommonJS file using a Babel-
|
|
@@ -30,7 +31,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
31
|
var src_exports = {};
|
|
31
32
|
__export(src_exports, {
|
|
32
33
|
WixProvider: () => WixProvider,
|
|
33
|
-
useEnvironment: () => useEnvironment,
|
|
34
34
|
useWix: () => useWix,
|
|
35
35
|
useWixAuth: () => useWixAuth,
|
|
36
36
|
useWixModules: () => useWixModules
|
|
@@ -39,8 +39,8 @@ module.exports = __toCommonJS(src_exports);
|
|
|
39
39
|
var React = __toESM(require("react"));
|
|
40
40
|
var import_react = require("react");
|
|
41
41
|
var import_api_client = require("@wix/api-client");
|
|
42
|
+
__reExport(src_exports, require("@wix/api-client"), module.exports);
|
|
42
43
|
var WixContext = (0, import_react.createContext)(void 0);
|
|
43
|
-
var HostEnvironmentContext = (0, import_react.createContext)(void 0);
|
|
44
44
|
function WixProvider(props) {
|
|
45
45
|
const { children, auth, modules, host } = props;
|
|
46
46
|
const client = (0, import_react.useMemo)(
|
|
@@ -51,24 +51,7 @@ function WixProvider(props) {
|
|
|
51
51
|
}),
|
|
52
52
|
[auth, modules, host]
|
|
53
53
|
);
|
|
54
|
-
return /* @__PURE__ */ React.createElement(WixContext.Provider, { value: client },
|
|
55
|
-
}
|
|
56
|
-
function HostEnvironmentProvider(props) {
|
|
57
|
-
const [environment, setEnvironment] = React.useState(null);
|
|
58
|
-
(0, import_react.useEffect)(() => {
|
|
59
|
-
if (props.host.environment) {
|
|
60
|
-
setEnvironment(props.host.environment);
|
|
61
|
-
} else {
|
|
62
|
-
const handle = props.host.channel.observeEnvironment(setEnvironment);
|
|
63
|
-
return () => {
|
|
64
|
-
Promise.resolve(handle).then((h) => h.disconnect());
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
}, [props.host.environment, props.host.channel]);
|
|
68
|
-
if (!environment) {
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
return /* @__PURE__ */ React.createElement(HostEnvironmentContext.Provider, { value: environment }, props.children);
|
|
54
|
+
return /* @__PURE__ */ React.createElement(WixContext.Provider, { value: client }, children);
|
|
72
55
|
}
|
|
73
56
|
function useWix() {
|
|
74
57
|
const sdk = React.useContext(WixContext);
|
|
@@ -87,20 +70,11 @@ function useWixModules(modules) {
|
|
|
87
70
|
const sdk = useWix();
|
|
88
71
|
return (0, import_react.useMemo)(() => sdk.use(modules), [sdk, modules]);
|
|
89
72
|
}
|
|
90
|
-
function useEnvironment() {
|
|
91
|
-
const environment = React.useContext(HostEnvironmentContext);
|
|
92
|
-
if (!environment) {
|
|
93
|
-
throw new Error(
|
|
94
|
-
"Host environment context not found. Make sure to render SDKProvider in the component tree and provide a host parameter"
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
return environment;
|
|
98
|
-
}
|
|
99
73
|
// Annotate the CommonJS export names for ESM import in node:
|
|
100
74
|
0 && (module.exports = {
|
|
101
75
|
WixProvider,
|
|
102
|
-
useEnvironment,
|
|
103
76
|
useWix,
|
|
104
77
|
useWixAuth,
|
|
105
|
-
useWixModules
|
|
78
|
+
useWixModules,
|
|
79
|
+
...require("@wix/api-client")
|
|
106
80
|
});
|
package/build/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// src/index.tsx
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import { createContext,
|
|
3
|
+
import { createContext, useMemo } from "react";
|
|
4
4
|
import {
|
|
5
5
|
createClient
|
|
6
6
|
} from "@wix/api-client";
|
|
7
|
+
export * from "@wix/api-client";
|
|
7
8
|
var WixContext = createContext(void 0);
|
|
8
|
-
var HostEnvironmentContext = createContext(void 0);
|
|
9
9
|
function WixProvider(props) {
|
|
10
10
|
const { children, auth, modules, host } = props;
|
|
11
11
|
const client = useMemo(
|
|
@@ -16,24 +16,7 @@ function WixProvider(props) {
|
|
|
16
16
|
}),
|
|
17
17
|
[auth, modules, host]
|
|
18
18
|
);
|
|
19
|
-
return /* @__PURE__ */ React.createElement(WixContext.Provider, { value: client },
|
|
20
|
-
}
|
|
21
|
-
function HostEnvironmentProvider(props) {
|
|
22
|
-
const [environment, setEnvironment] = React.useState(null);
|
|
23
|
-
useEffect(() => {
|
|
24
|
-
if (props.host.environment) {
|
|
25
|
-
setEnvironment(props.host.environment);
|
|
26
|
-
} else {
|
|
27
|
-
const handle = props.host.channel.observeEnvironment(setEnvironment);
|
|
28
|
-
return () => {
|
|
29
|
-
Promise.resolve(handle).then((h) => h.disconnect());
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
}, [props.host.environment, props.host.channel]);
|
|
33
|
-
if (!environment) {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
return /* @__PURE__ */ React.createElement(HostEnvironmentContext.Provider, { value: environment }, props.children);
|
|
19
|
+
return /* @__PURE__ */ React.createElement(WixContext.Provider, { value: client }, children);
|
|
37
20
|
}
|
|
38
21
|
function useWix() {
|
|
39
22
|
const sdk = React.useContext(WixContext);
|
|
@@ -52,18 +35,8 @@ function useWixModules(modules) {
|
|
|
52
35
|
const sdk = useWix();
|
|
53
36
|
return useMemo(() => sdk.use(modules), [sdk, modules]);
|
|
54
37
|
}
|
|
55
|
-
function useEnvironment() {
|
|
56
|
-
const environment = React.useContext(HostEnvironmentContext);
|
|
57
|
-
if (!environment) {
|
|
58
|
-
throw new Error(
|
|
59
|
-
"Host environment context not found. Make sure to render SDKProvider in the component tree and provide a host parameter"
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
return environment;
|
|
63
|
-
}
|
|
64
38
|
export {
|
|
65
39
|
WixProvider,
|
|
66
|
-
useEnvironment,
|
|
67
40
|
useWix,
|
|
68
41
|
useWixAuth,
|
|
69
42
|
useWixModules
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/sdk-react",
|
|
3
|
-
"version": "0.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.
|
|
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.
|
|
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.
|
|
35
|
-
"@wix/ecom": "^1.0.
|
|
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": "
|
|
63
|
+
"falconPackageHash": "696a948d6860320ac2cb1c1151e4b7df403a47000ab1caf70d340e0d"
|
|
64
64
|
}
|