@imfusion/sdk-react 0.7.0-dev.36.g68b6e3f0 → 0.7.0-dev.38.gb2cede30
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/README.md +2 -2
- package/dist/context.d.ts +1 -14
- package/dist/useDataLoader.d.ts +8 -7
- package/dist/useDataLoader.js +22 -9
- package/dist/useStableHandle.d.ts +1 -15
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -35,12 +35,12 @@ import { useImFusion, useDataLoader, useData } from '@imfusion/sdk-react';
|
|
|
35
35
|
|
|
36
36
|
function Viewer() {
|
|
37
37
|
const imf = useImFusion();
|
|
38
|
-
const {
|
|
38
|
+
const { loadFileFromUrl, isLoading, progress } = useDataLoader();
|
|
39
39
|
const datasets = useData();
|
|
40
40
|
|
|
41
41
|
return (
|
|
42
42
|
<div>
|
|
43
|
-
<button onClick={() =>
|
|
43
|
+
<button onClick={() => loadFileFromUrl('/data/scan.nii.gz')} disabled={isLoading}>
|
|
44
44
|
{isLoading ? 'Loading...' : 'Load'}
|
|
45
45
|
</button>
|
|
46
46
|
<p>{datasets.length} dataset(s) loaded</p>
|
package/dist/context.d.ts
CHANGED
|
@@ -1,14 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Internal context value shared between provider, canvas, and hooks.
|
|
4
|
-
*
|
|
5
|
-
* @internal Use {@link useImFusion},
|
|
6
|
-
* {@link useImFusionError}, or {@link useImFusionState} instead.
|
|
7
|
-
*/
|
|
8
|
-
export interface ImFusionContextValue {
|
|
9
|
-
imf: ImFusion | null;
|
|
10
|
-
error: Error | null;
|
|
11
|
-
registerCanvas: (canvas: HTMLCanvasElement) => void;
|
|
12
|
-
}
|
|
13
|
-
/** @internal */
|
|
14
|
-
export declare const ImFusionContext: import("react").Context<ImFusionContextValue | null>;
|
|
1
|
+
export {};
|
package/dist/useDataLoader.d.ts
CHANGED
|
@@ -6,9 +6,9 @@ export interface DataLoaderProgress {
|
|
|
6
6
|
/**
|
|
7
7
|
* Provides data loading methods with reactive loading, progress, and error state.
|
|
8
8
|
*
|
|
9
|
-
* Wraps {@link @imfusion/sdk!ImFusion.
|
|
10
|
-
* {@link @imfusion/sdk!ImFusion.
|
|
11
|
-
* React-friendly state management.
|
|
9
|
+
* Wraps {@link @imfusion/sdk!ImFusion.loadFile | ImFusion.loadFile}, {@link @imfusion/sdk!ImFusion.loadFileFromUrl | ImFusion.loadFileFromUrl},
|
|
10
|
+
* {@link @imfusion/sdk!ImFusion.loadFolder | ImFusion.loadFolder}, {@link @imfusion/sdk!ImFusion.loadFolderFromUrls | ImFusion.loadFolderFromUrls}, and
|
|
11
|
+
* {@link @imfusion/sdk!ImFusion.loadBuffer | ImFusion.loadBuffer} with React-friendly state management.
|
|
12
12
|
*
|
|
13
13
|
* State (`isLoading`, `progress`, `error`) tracks a single load operation at a time.
|
|
14
14
|
* Concurrent loads from the same hook instance are not supported, use separate instances if needed.
|
|
@@ -20,10 +20,10 @@ export interface DataLoaderProgress {
|
|
|
20
20
|
* @example
|
|
21
21
|
* ```tsx
|
|
22
22
|
* function LoadButton() {
|
|
23
|
-
* const {
|
|
23
|
+
* const { loadFileFromUrl, isLoading, progress, error } = useDataLoader();
|
|
24
24
|
* return (
|
|
25
25
|
* <>
|
|
26
|
-
* <button onClick={() =>
|
|
26
|
+
* <button onClick={() => loadFileFromUrl('/data/ct.nii.gz')} disabled={isLoading}>
|
|
27
27
|
* Load CT
|
|
28
28
|
* </button>
|
|
29
29
|
* {isLoading && progress && (
|
|
@@ -39,10 +39,11 @@ export interface DataLoaderProgress {
|
|
|
39
39
|
* @see {@link useVisibleData}
|
|
40
40
|
*/
|
|
41
41
|
export declare function useDataLoader(): {
|
|
42
|
-
loadUrl: (url: string) => Promise<HandleArray<Data>>;
|
|
43
42
|
loadFile: (file: File) => Promise<HandleArray<Data>>;
|
|
44
|
-
|
|
43
|
+
loadFileFromUrl: (url: string) => Promise<HandleArray<Data>>;
|
|
45
44
|
loadFolder: (files: File[]) => Promise<HandleArray<Data>>;
|
|
45
|
+
loadFolderFromUrls: (urls: ReadonlyArray<string>) => Promise<HandleArray<Data>>;
|
|
46
|
+
loadBuffer: (buffer: ArrayBufferLike, filename: string) => Promise<HandleArray<Data>>;
|
|
46
47
|
isLoading: boolean;
|
|
47
48
|
progress: DataLoaderProgress | null;
|
|
48
49
|
error: Error | null;
|
package/dist/useDataLoader.js
CHANGED
|
@@ -3,9 +3,9 @@ import { useImFusion } from './useImFusion.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* Provides data loading methods with reactive loading, progress, and error state.
|
|
5
5
|
*
|
|
6
|
-
* Wraps {@link @imfusion/sdk!ImFusion.
|
|
7
|
-
* {@link @imfusion/sdk!ImFusion.
|
|
8
|
-
* React-friendly state management.
|
|
6
|
+
* Wraps {@link @imfusion/sdk!ImFusion.loadFile | ImFusion.loadFile}, {@link @imfusion/sdk!ImFusion.loadFileFromUrl | ImFusion.loadFileFromUrl},
|
|
7
|
+
* {@link @imfusion/sdk!ImFusion.loadFolder | ImFusion.loadFolder}, {@link @imfusion/sdk!ImFusion.loadFolderFromUrls | ImFusion.loadFolderFromUrls}, and
|
|
8
|
+
* {@link @imfusion/sdk!ImFusion.loadBuffer | ImFusion.loadBuffer} with React-friendly state management.
|
|
9
9
|
*
|
|
10
10
|
* State (`isLoading`, `progress`, `error`) tracks a single load operation at a time.
|
|
11
11
|
* Concurrent loads from the same hook instance are not supported, use separate instances if needed.
|
|
@@ -17,10 +17,10 @@ import { useImFusion } from './useImFusion.js';
|
|
|
17
17
|
* @example
|
|
18
18
|
* ```tsx
|
|
19
19
|
* function LoadButton() {
|
|
20
|
-
* const {
|
|
20
|
+
* const { loadFileFromUrl, isLoading, progress, error } = useDataLoader();
|
|
21
21
|
* return (
|
|
22
22
|
* <>
|
|
23
|
-
* <button onClick={() =>
|
|
23
|
+
* <button onClick={() => loadFileFromUrl('/data/ct.nii.gz')} disabled={isLoading}>
|
|
24
24
|
* Load CT
|
|
25
25
|
* </button>
|
|
26
26
|
* {isLoading && progress && (
|
|
@@ -56,15 +56,28 @@ export function useDataLoader() {
|
|
|
56
56
|
setIsLoading(false);
|
|
57
57
|
}
|
|
58
58
|
}, []);
|
|
59
|
-
const
|
|
59
|
+
const loadFile = useCallback((file) => run(() => imf.loadFile(file)), [imf, run]);
|
|
60
|
+
const loadFileFromUrl = useCallback((url) => run(() => imf.loadFileFromUrl(url, {
|
|
60
61
|
onProgress: (received, total) => setProgress({ received, total }),
|
|
61
62
|
})), [imf, run]);
|
|
62
|
-
const loadFile = useCallback((file) => run(() => imf.loadFile(file)), [imf, run]);
|
|
63
|
-
const loadBuffer = useCallback((buffer, filename) => run(() => imf.loadBuffer(buffer, filename)), [imf, run]);
|
|
64
63
|
const loadFolder = useCallback((files) => run(() => imf.loadFolder(files)), [imf, run]);
|
|
64
|
+
const loadFolderFromUrls = useCallback((urls) => run(() => imf.loadFolderFromUrls(urls, {
|
|
65
|
+
onProgress: (received, total) => setProgress({ received, total }),
|
|
66
|
+
})), [imf, run]);
|
|
67
|
+
const loadBuffer = useCallback((buffer, filename) => run(() => imf.loadBuffer(buffer, filename)), [imf, run]);
|
|
65
68
|
const reset = useCallback(() => {
|
|
66
69
|
setError(null);
|
|
67
70
|
setProgress(null);
|
|
68
71
|
}, []);
|
|
69
|
-
return useMemo(() => ({
|
|
72
|
+
return useMemo(() => ({
|
|
73
|
+
loadFile,
|
|
74
|
+
loadFileFromUrl,
|
|
75
|
+
loadFolder,
|
|
76
|
+
loadFolderFromUrls,
|
|
77
|
+
loadBuffer,
|
|
78
|
+
isLoading,
|
|
79
|
+
progress,
|
|
80
|
+
error,
|
|
81
|
+
reset,
|
|
82
|
+
}), [loadFile, loadFileFromUrl, loadFolder, loadFolderFromUrls, loadBuffer, isLoading, progress, error, reset]);
|
|
70
83
|
}
|
|
@@ -1,15 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Returns a stable reference for a WASM handle, using
|
|
4
|
-
* {@link @imfusion/sdk!ClassHandle.isAliasOf | isAliasOf} instead of `===` to detect
|
|
5
|
-
* identity changes.
|
|
6
|
-
*
|
|
7
|
-
* Different JS wrapper objects can alias the same underlying C++ object.
|
|
8
|
-
* This hook ensures that the returned reference only changes when the
|
|
9
|
-
* underlying C++ object actually changes, making it safe to use in
|
|
10
|
-
* `useEffect` dependency arrays and other identity-sensitive contexts.
|
|
11
|
-
*
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
export declare function useStableHandle<T extends ClassHandle>(handle: T): T;
|
|
15
|
-
export declare function useStableHandle<T extends ClassHandle>(handle: T | undefined): T | undefined;
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imfusion/sdk-react",
|
|
3
|
-
"version": "0.7.0-dev.
|
|
3
|
+
"version": "0.7.0-dev.38.gb2cede30",
|
|
4
4
|
"description": "React bindings for ImFusion Web SDK",
|
|
5
5
|
"author": "ImFusion GmbH",
|
|
6
6
|
"license": "SEE LICENSE IN License.rtf",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"License.rtf"
|
|
30
30
|
],
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@imfusion/sdk": "0.7.0-dev.
|
|
32
|
+
"@imfusion/sdk": "0.7.0-dev.38.gb2cede30",
|
|
33
33
|
"react": ">=18"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|