@upscopeio/react 1.0.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.
Files changed (2) hide show
  1. package/package.json +13 -0
  2. package/react.tsx +53 -0
package/package.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "@upscopeio/react",
3
+ "main": "react.tsx",
4
+ "type": "module",
5
+ "dependencies": {
6
+ "@upscopeio/sdk": "1.0.1"
7
+ },
8
+ "peerDependencies": {
9
+ "react": "^18.2.0",
10
+ "react-dom": "^18.2.0"
11
+ },
12
+ "version": "1.0.1"
13
+ }
package/react.tsx ADDED
@@ -0,0 +1,53 @@
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
+ }