@sigmacomputing/react-embed-sdk 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.mts +76 -3
- package/dist/index.d.ts +76 -3
- package/dist/index.js +15 -0
- package/dist/index.mjs +15 -1
- package/package.json +3 -2
package/dist/index.d.mts
CHANGED
@@ -1,6 +1,79 @@
|
|
1
|
+
import * as react from 'react';
|
1
2
|
import { WorkbookLoadedEvent, WorkbookErrorEvent } from '@sigmacomputing/embed-sdk';
|
3
|
+
export * from '@sigmacomputing/embed-sdk';
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
+
type OnLoaded = (event: WorkbookLoadedEvent) => void;
|
6
|
+
type OnError = (event: WorkbookErrorEvent) => void;
|
7
|
+
/**
|
8
|
+
* Listen for a workbook loaded event, and execute the given callback when it occurs.
|
9
|
+
*
|
10
|
+
* @example
|
11
|
+
* ```
|
12
|
+
* function MyEmbed() {
|
13
|
+
* const [loading, setLoading] = useState(true);
|
14
|
+
* const loadingCallback = useCallback(() => setLoading(false), []);
|
15
|
+
* const iframeRef = useRef<HTMLIFrameElement>(null);
|
16
|
+
* useWorkbookLoaded(iframeRef, loadingCallback);
|
17
|
+
* return (
|
18
|
+
* <iframe
|
19
|
+
* className{loading ? "hidden" : "show"}
|
20
|
+
* ref={iframeRef}
|
21
|
+
* src="https://sigmacomputing.app/embed"
|
22
|
+
* />
|
23
|
+
* );
|
24
|
+
* }
|
25
|
+
* ```
|
26
|
+
*
|
27
|
+
*/
|
28
|
+
declare function useWorkbookLoaded(iframeRef: React.RefObject<HTMLIFrameElement>, onLoaded: OnLoaded): void;
|
29
|
+
/**
|
30
|
+
* Listen for a workbook error event, and execute the given callback when it occurs.
|
31
|
+
*
|
32
|
+
* @example
|
33
|
+
* ```
|
34
|
+
* function MyEmbed() {
|
35
|
+
* const [error, setError] = useState<string | null>(null);
|
36
|
+
* const onError = useCallback((event: WorkbookErrorEvent) => {
|
37
|
+
* sendToErrorReporting(event.message);
|
38
|
+
* setError(event.message);
|
39
|
+
* }, []);
|
40
|
+
* const iframeRef = useRef<HTMLIFrameElement>(null);
|
41
|
+
* return (
|
42
|
+
* <iframe
|
43
|
+
* ref={iframeRef}
|
44
|
+
* src="https://sigmacomputing.app/embed"
|
45
|
+
* />
|
46
|
+
* );
|
47
|
+
* }
|
48
|
+
* ```
|
49
|
+
*
|
50
|
+
*/
|
51
|
+
declare function useWorkbookError(iframeRef: React.RefObject<HTMLIFrameElement>, onError: OnError): void;
|
52
|
+
/**
|
53
|
+
* A hook that returns a ref to be used with an iframe element, and the loading and error state of the embed.
|
54
|
+
*
|
55
|
+
* @example
|
56
|
+
* ```
|
57
|
+
* function MyEmbed() {
|
58
|
+
* const { iframeRef, loading, error } = useSigmaIframe();
|
59
|
+
* return (
|
60
|
+
* <>
|
61
|
+
* {loading && <p>Loading...</p>}
|
62
|
+
* {error && <p>Error: {error.message}</p>}
|
63
|
+
* <iframe
|
64
|
+
* className={loading || error ? "hidden" : "show"}
|
65
|
+
* ref={iframeRef}
|
66
|
+
* src="https://sigmacomputing.app/embed"
|
67
|
+
* />
|
68
|
+
* </>
|
69
|
+
* );
|
70
|
+
* }
|
71
|
+
* ```
|
72
|
+
*/
|
73
|
+
declare function useSigmaIframe(): {
|
74
|
+
iframeRef: react.RefObject<HTMLIFrameElement>;
|
75
|
+
loading: boolean;
|
76
|
+
error: WorkbookErrorEvent | null;
|
77
|
+
};
|
5
78
|
|
6
|
-
export { useWorkbookError, useWorkbookLoaded };
|
79
|
+
export { type OnError, type OnLoaded, useSigmaIframe, useWorkbookError, useWorkbookLoaded };
|
package/dist/index.d.ts
CHANGED
@@ -1,6 +1,79 @@
|
|
1
|
+
import * as react from 'react';
|
1
2
|
import { WorkbookLoadedEvent, WorkbookErrorEvent } from '@sigmacomputing/embed-sdk';
|
3
|
+
export * from '@sigmacomputing/embed-sdk';
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
+
type OnLoaded = (event: WorkbookLoadedEvent) => void;
|
6
|
+
type OnError = (event: WorkbookErrorEvent) => void;
|
7
|
+
/**
|
8
|
+
* Listen for a workbook loaded event, and execute the given callback when it occurs.
|
9
|
+
*
|
10
|
+
* @example
|
11
|
+
* ```
|
12
|
+
* function MyEmbed() {
|
13
|
+
* const [loading, setLoading] = useState(true);
|
14
|
+
* const loadingCallback = useCallback(() => setLoading(false), []);
|
15
|
+
* const iframeRef = useRef<HTMLIFrameElement>(null);
|
16
|
+
* useWorkbookLoaded(iframeRef, loadingCallback);
|
17
|
+
* return (
|
18
|
+
* <iframe
|
19
|
+
* className{loading ? "hidden" : "show"}
|
20
|
+
* ref={iframeRef}
|
21
|
+
* src="https://sigmacomputing.app/embed"
|
22
|
+
* />
|
23
|
+
* );
|
24
|
+
* }
|
25
|
+
* ```
|
26
|
+
*
|
27
|
+
*/
|
28
|
+
declare function useWorkbookLoaded(iframeRef: React.RefObject<HTMLIFrameElement>, onLoaded: OnLoaded): void;
|
29
|
+
/**
|
30
|
+
* Listen for a workbook error event, and execute the given callback when it occurs.
|
31
|
+
*
|
32
|
+
* @example
|
33
|
+
* ```
|
34
|
+
* function MyEmbed() {
|
35
|
+
* const [error, setError] = useState<string | null>(null);
|
36
|
+
* const onError = useCallback((event: WorkbookErrorEvent) => {
|
37
|
+
* sendToErrorReporting(event.message);
|
38
|
+
* setError(event.message);
|
39
|
+
* }, []);
|
40
|
+
* const iframeRef = useRef<HTMLIFrameElement>(null);
|
41
|
+
* return (
|
42
|
+
* <iframe
|
43
|
+
* ref={iframeRef}
|
44
|
+
* src="https://sigmacomputing.app/embed"
|
45
|
+
* />
|
46
|
+
* );
|
47
|
+
* }
|
48
|
+
* ```
|
49
|
+
*
|
50
|
+
*/
|
51
|
+
declare function useWorkbookError(iframeRef: React.RefObject<HTMLIFrameElement>, onError: OnError): void;
|
52
|
+
/**
|
53
|
+
* A hook that returns a ref to be used with an iframe element, and the loading and error state of the embed.
|
54
|
+
*
|
55
|
+
* @example
|
56
|
+
* ```
|
57
|
+
* function MyEmbed() {
|
58
|
+
* const { iframeRef, loading, error } = useSigmaIframe();
|
59
|
+
* return (
|
60
|
+
* <>
|
61
|
+
* {loading && <p>Loading...</p>}
|
62
|
+
* {error && <p>Error: {error.message}</p>}
|
63
|
+
* <iframe
|
64
|
+
* className={loading || error ? "hidden" : "show"}
|
65
|
+
* ref={iframeRef}
|
66
|
+
* src="https://sigmacomputing.app/embed"
|
67
|
+
* />
|
68
|
+
* </>
|
69
|
+
* );
|
70
|
+
* }
|
71
|
+
* ```
|
72
|
+
*/
|
73
|
+
declare function useSigmaIframe(): {
|
74
|
+
iframeRef: react.RefObject<HTMLIFrameElement>;
|
75
|
+
loading: boolean;
|
76
|
+
error: WorkbookErrorEvent | null;
|
77
|
+
};
|
5
78
|
|
6
|
-
export { useWorkbookError, useWorkbookLoaded };
|
79
|
+
export { type OnError, type OnLoaded, useSigmaIframe, useWorkbookError, useWorkbookLoaded };
|
package/dist/index.js
CHANGED
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
20
20
|
// src/index.ts
|
21
21
|
var src_exports = {};
|
22
22
|
__export(src_exports, {
|
23
|
+
useSigmaIframe: () => useSigmaIframe,
|
23
24
|
useWorkbookError: () => useWorkbookError,
|
24
25
|
useWorkbookLoaded: () => useWorkbookLoaded
|
25
26
|
});
|
@@ -50,8 +51,22 @@ function useWorkbookError(iframeRef, onError) {
|
|
50
51
|
return () => window.removeEventListener("message", listener);
|
51
52
|
}, [iframeRef, onError]);
|
52
53
|
}
|
54
|
+
function useSigmaIframe() {
|
55
|
+
const iframeRef = (0, import_react.useRef)(null);
|
56
|
+
const [loading, setLoading] = (0, import_react.useState)(true);
|
57
|
+
const [error, setError] = (0, import_react.useState)(null);
|
58
|
+
const loadingCallback = (0, import_react.useCallback)(() => setLoading(false), []);
|
59
|
+
const errorCallback = (0, import_react.useCallback)((event) => {
|
60
|
+
setError(event);
|
61
|
+
setLoading(false);
|
62
|
+
}, []);
|
63
|
+
useWorkbookLoaded(iframeRef, loadingCallback);
|
64
|
+
useWorkbookError(iframeRef, errorCallback);
|
65
|
+
return { iframeRef, loading, error };
|
66
|
+
}
|
53
67
|
// Annotate the CommonJS export names for ESM import in node:
|
54
68
|
0 && (module.exports = {
|
69
|
+
useSigmaIframe,
|
55
70
|
useWorkbookError,
|
56
71
|
useWorkbookLoaded
|
57
72
|
});
|
package/dist/index.mjs
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
// src/index.ts
|
2
|
-
import { useEffect } from "react";
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
3
3
|
import {
|
4
4
|
workbookErrorListener,
|
5
5
|
workbookLoadedListener
|
@@ -28,7 +28,21 @@ function useWorkbookError(iframeRef, onError) {
|
|
28
28
|
return () => window.removeEventListener("message", listener);
|
29
29
|
}, [iframeRef, onError]);
|
30
30
|
}
|
31
|
+
function useSigmaIframe() {
|
32
|
+
const iframeRef = useRef(null);
|
33
|
+
const [loading, setLoading] = useState(true);
|
34
|
+
const [error, setError] = useState(null);
|
35
|
+
const loadingCallback = useCallback(() => setLoading(false), []);
|
36
|
+
const errorCallback = useCallback((event) => {
|
37
|
+
setError(event);
|
38
|
+
setLoading(false);
|
39
|
+
}, []);
|
40
|
+
useWorkbookLoaded(iframeRef, loadingCallback);
|
41
|
+
useWorkbookError(iframeRef, errorCallback);
|
42
|
+
return { iframeRef, loading, error };
|
43
|
+
}
|
31
44
|
export {
|
45
|
+
useSigmaIframe,
|
32
46
|
useWorkbookError,
|
33
47
|
useWorkbookLoaded
|
34
48
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sigmacomputing/react-embed-sdk",
|
3
|
-
"version": "0.2.
|
3
|
+
"version": "0.2.2",
|
4
4
|
"description": "React JavaScript SDK to interact with Sigma Computing's Embed API",
|
5
5
|
"scripts": {
|
6
6
|
"prepublish": "npm run build",
|
@@ -23,11 +23,12 @@
|
|
23
23
|
"react-dom": "^16.8 || ^17 || ^18"
|
24
24
|
},
|
25
25
|
"devDependencies": {
|
26
|
+
"@sigmacomputing/typescript-config": "*",
|
26
27
|
"@types/react": "^18.2.66",
|
27
28
|
"react": "^18.2.0",
|
28
29
|
"react-dom": "^18.2.0"
|
29
30
|
},
|
30
31
|
"dependencies": {
|
31
|
-
"@sigmacomputing/embed-sdk": "
|
32
|
+
"@sigmacomputing/embed-sdk": "latest"
|
32
33
|
}
|
33
34
|
}
|