@upscopeio/react 1.0.1 → 1.0.3

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/index.js ADDED
@@ -0,0 +1,43 @@
1
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
+ import UpscopeSDK from '@upscopeio/sdk';
3
+ import { useEffect, useState } from 'react';
4
+ const Upscope = function ({ children, ...props }) {
5
+ const [initiated, setInitiated] = useState(false);
6
+ const keys = Object.keys(props).sort((a, b) => a.localeCompare(b));
7
+ const values = keys.map((key) => props[key]);
8
+ useEffect(() => {
9
+ if (initiated) {
10
+ UpscopeSDK('updateConnection', props);
11
+ }
12
+ else {
13
+ UpscopeSDK('init', props);
14
+ setInitiated(true);
15
+ }
16
+ }, values);
17
+ return children;
18
+ };
19
+ export default Upscope;
20
+ export function Masked({ children }) {
21
+ useEffect(() => {
22
+ if (children) {
23
+ children.__upscopeMasked = true;
24
+ // @ts-ignore
25
+ for (const child of children) {
26
+ child.__upscopeMasked = true;
27
+ }
28
+ }
29
+ }, [children]);
30
+ return (_jsx(_Fragment, { children: children }));
31
+ }
32
+ export function NoRemoteControl({ children }) {
33
+ useEffect(() => {
34
+ if (children) {
35
+ children.__upscopeNoRemoteControl = true;
36
+ // @ts-ignore
37
+ for (const child of children) {
38
+ child.__upscopeNoRemoteControl = true;
39
+ }
40
+ }
41
+ }, [children]);
42
+ return (_jsx(_Fragment, { children: children }));
43
+ }
package/index.tsx ADDED
@@ -0,0 +1,68 @@
1
+ import type {CobrowsingSdkConfiguration, Upscope} from '@upscopeio/sdk';
2
+ import type {ReactNode} from 'react';
3
+ import UpscopeSDK from '@upscopeio/sdk';
4
+ import React, {useEffect, useState} from 'react';
5
+
6
+ type Child = ReactNode & {
7
+ __upscopeMasked?: boolean;
8
+ __upscopeNoRemoteControl?: boolean;
9
+ };
10
+
11
+ type Children = {children: Child};
12
+
13
+ type Props = Children & Partial<CobrowsingSdkConfiguration>;
14
+
15
+
16
+ const Upscope: React.FC<Props> = function({children, ...props}: Props) {
17
+ const [initiated, setInitiated] = useState(false);
18
+ const keys = Object.keys(props).sort((a, b) => a.localeCompare(b)) as (keyof CobrowsingSdkConfiguration)[];
19
+ const values: unknown[] = keys.map((key: keyof CobrowsingSdkConfiguration) => props[key] as unknown);
20
+
21
+ useEffect(() => {
22
+ if (initiated) {
23
+ (UpscopeSDK as Upscope)('updateConnection', props);
24
+ } else {
25
+ (UpscopeSDK as Upscope)('init', props);
26
+ setInitiated(true);
27
+ }
28
+ }, values);
29
+
30
+ return children;
31
+ };
32
+ export default Upscope;
33
+
34
+
35
+ export function Masked({children}: Children): ReactNode {
36
+ useEffect(() => {
37
+ if (children) {
38
+ children.__upscopeMasked = true;
39
+ // @ts-ignore
40
+ for (const child of children) {
41
+ (child as Child).__upscopeMasked = true;
42
+ }
43
+ }
44
+ }, [children]);
45
+ return (
46
+ <>
47
+ {children}
48
+ </>
49
+ );
50
+ }
51
+
52
+
53
+ export function NoRemoteControl({children}: Children): ReactNode {
54
+ useEffect(() => {
55
+ if (children) {
56
+ children.__upscopeNoRemoteControl = true;
57
+ // @ts-ignore
58
+ for (const child of children) {
59
+ (child as Child).__upscopeNoRemoteControl = true;
60
+ }
61
+ }
62
+ }, [children]);
63
+ return (
64
+ <>
65
+ {children}
66
+ </>
67
+ );
68
+ }
package/package.json CHANGED
@@ -1,13 +1,16 @@
1
1
  {
2
2
  "name": "@upscopeio/react",
3
- "main": "react.tsx",
3
+ "main": "index.js",
4
4
  "type": "module",
5
5
  "dependencies": {
6
- "@upscopeio/sdk": "1.0.1"
6
+ "@upscopeio/sdk": "1.0.3"
7
7
  },
8
8
  "peerDependencies": {
9
- "react": "^18.2.0",
10
- "react-dom": "^18.2.0"
9
+ "react": "^18.2.0"
11
10
  },
12
- "version": "1.0.1"
11
+ "devDependencies": {
12
+ "@types/react": "^18.2.14",
13
+ "typescript": "^5.1.6"
14
+ },
15
+ "version": "1.0.3"
13
16
  }
package/tsconfig.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "esnext",
4
+ "jsx": "react-jsx",
5
+ "module": "esnext",
6
+ "esModuleInterop": true,
7
+ "forceConsistentCasingInFileNames": true,
8
+ "moduleResolution": "node",
9
+ "strict": true,
10
+ "skipLibCheck": true
11
+ }
12
+ }
package/react.tsx DELETED
@@ -1,53 +0,0 @@
1
- import type {CobrowsingSdkConfiguration} from '@upscopeio/sdk';
2
- import React, {ReactNode, useEffect, useRef, useState} from 'react';
3
- import UpscopeSDK from '@upscopeio/sdk';
4
-
5
- type Children = {children: ReactNode};
6
- type Props = Children & Partial<CobrowsingSdkConfiguration>;
7
-
8
-
9
- const UpscopeComponent: React.FC<Props> = ({children, ...props}) => {
10
- const [initiated, setInitiated] = useState(false);
11
- useEffect(() => {
12
- if (initiated) {
13
- UpscopeSDK('updateConnection', props);
14
- } else {
15
- UpscopeSDK('init', props);
16
- setInitiated(true);
17
- }
18
- }, [...Object.values(props)]);
19
-
20
- return children;
21
- };
22
-
23
- export default UpscopeComponent;
24
-
25
-
26
- export function Masked({children}: Children): ReactNode {
27
- const fragmentRef = useRef<React.Fragment>(null);
28
- useEffect(() => {
29
- const children = fragmentRef.current?.children;
30
- for (const child of children) {
31
- child.__upscopeMasked = true;
32
- }
33
- }, [children]);
34
-
35
- return <React.Fragment ref={fragmentRef}>
36
- {children}
37
- </React.Fragment>
38
- }
39
-
40
-
41
- export function NoRemoteControl({children}: Children): ReactNode {
42
- const fragmentRef = useRef<React.Fragment>(null);
43
- useEffect(() => {
44
- const children = fragmentRef.current?.children;
45
- for (const child of children) {
46
- child.__upscopeNoRemoteControl = true;
47
- }
48
- }, [children]);
49
-
50
- return <React.Fragment ref={fragmentRef}>
51
- {children}
52
- </React.Fragment>
53
- }