@imfusion/sdk-react 1.2.2-dev.4.g7a1b1c20 → 1.2.2-dev.5.g9f4fc80b
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/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/useLabelConfig.d.ts +46 -0
- package/dist/useLabelConfig.js +68 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -15,4 +15,5 @@ export { useViewVisibility } from './useViewVisibility.js';
|
|
|
15
15
|
export { useDisplayOptions2d, useDisplayOptions3d } from './useDisplayOptions.js';
|
|
16
16
|
export { useFrameSelection } from './useFrameSelection.js';
|
|
17
17
|
export { useContextMenu } from './useContextMenu.js';
|
|
18
|
+
export { useLabelConfig } from './useLabelConfig.js';
|
|
18
19
|
export { useThumbnail } from './useThumbnail.js';
|
package/dist/index.js
CHANGED
|
@@ -15,4 +15,5 @@ export { useViewVisibility } from './useViewVisibility.js';
|
|
|
15
15
|
export { useDisplayOptions2d, useDisplayOptions3d } from './useDisplayOptions.js';
|
|
16
16
|
export { useFrameSelection } from './useFrameSelection.js';
|
|
17
17
|
export { useContextMenu } from './useContextMenu.js';
|
|
18
|
+
export { useLabelConfig } from './useLabelConfig.js';
|
|
18
19
|
export { useThumbnail } from './useThumbnail.js';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { LabelConfig, SharedImageSet } from '@imfusion/sdk';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the reactive `LabelConfigMap` state of a label map.
|
|
4
|
+
*
|
|
5
|
+
* Subscribes to {@link @imfusion/sdk!EmbindModule.onLabelConfigChanged | onLabelConfigChanged}
|
|
6
|
+
*
|
|
7
|
+
* @param labelMap - The label map to observe
|
|
8
|
+
* @returns The current label config state as a `Map<number, LabelConfig>`, a function to change the whole map and a function to change individual entries
|
|
9
|
+
* @throws If called outside of an {@link ImFusionProvider}
|
|
10
|
+
* @throws If called before the SDK has finished initializing
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* function ToggleLabelVisibility({ labelMap }: { labelMap: SharedImageSet }) {
|
|
15
|
+
* const { labelConfigs, setLabelConfigs, setLabelConfig } = useLabelConfig(labelMap);
|
|
16
|
+
*
|
|
17
|
+
* if (!labelConfigs) return;
|
|
18
|
+
*
|
|
19
|
+
* const keys = [...labelConfigs.keys()];
|
|
20
|
+
* const toggleVisibility = (labelValue: number, config: LabelConfig) => {
|
|
21
|
+
* let next = config;
|
|
22
|
+
* next.isVisible2d = !next.isVisible2d;
|
|
23
|
+
* setLabelConfig(labelValue, next);
|
|
24
|
+
* };
|
|
25
|
+
*
|
|
26
|
+
* return (
|
|
27
|
+
* <ul>
|
|
28
|
+
* {keys.map((labelValue) => {
|
|
29
|
+
* const config = labelConfigs.get(labelValue)!;
|
|
30
|
+
* return (
|
|
31
|
+
* <li onClick={() => toggleVisibility(labelValue, config)}>
|
|
32
|
+
* {config.isVisible2d ? 'visible' : 'invisible'}
|
|
33
|
+
* </li>
|
|
34
|
+
* );
|
|
35
|
+
* })}
|
|
36
|
+
* </ul>
|
|
37
|
+
* );
|
|
38
|
+
* }
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function useLabelConfig(labelMap: SharedImageSet | null): {
|
|
43
|
+
labelConfigs: Map<number, LabelConfig> | undefined;
|
|
44
|
+
setLabelConfigs: (labelConfigMap: Map<number, LabelConfig>) => void;
|
|
45
|
+
setLabelConfig: (labelValue: number, labelConfig: LabelConfig) => void;
|
|
46
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { useState, useEffect, useCallback } from 'react';
|
|
2
|
+
import { useImFusion } from './useImFusion.js';
|
|
3
|
+
import { useStableHandle } from './useStableHandle.js';
|
|
4
|
+
/**
|
|
5
|
+
* Returns the reactive `LabelConfigMap` state of a label map.
|
|
6
|
+
*
|
|
7
|
+
* Subscribes to {@link @imfusion/sdk!EmbindModule.onLabelConfigChanged | onLabelConfigChanged}
|
|
8
|
+
*
|
|
9
|
+
* @param labelMap - The label map to observe
|
|
10
|
+
* @returns The current label config state as a `Map<number, LabelConfig>`, a function to change the whole map and a function to change individual entries
|
|
11
|
+
* @throws If called outside of an {@link ImFusionProvider}
|
|
12
|
+
* @throws If called before the SDK has finished initializing
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* function ToggleLabelVisibility({ labelMap }: { labelMap: SharedImageSet }) {
|
|
17
|
+
* const { labelConfigs, setLabelConfigs, setLabelConfig } = useLabelConfig(labelMap);
|
|
18
|
+
*
|
|
19
|
+
* if (!labelConfigs) return;
|
|
20
|
+
*
|
|
21
|
+
* const keys = [...labelConfigs.keys()];
|
|
22
|
+
* const toggleVisibility = (labelValue: number, config: LabelConfig) => {
|
|
23
|
+
* let next = config;
|
|
24
|
+
* next.isVisible2d = !next.isVisible2d;
|
|
25
|
+
* setLabelConfig(labelValue, next);
|
|
26
|
+
* };
|
|
27
|
+
*
|
|
28
|
+
* return (
|
|
29
|
+
* <ul>
|
|
30
|
+
* {keys.map((labelValue) => {
|
|
31
|
+
* const config = labelConfigs.get(labelValue)!;
|
|
32
|
+
* return (
|
|
33
|
+
* <li onClick={() => toggleVisibility(labelValue, config)}>
|
|
34
|
+
* {config.isVisible2d ? 'visible' : 'invisible'}
|
|
35
|
+
* </li>
|
|
36
|
+
* );
|
|
37
|
+
* })}
|
|
38
|
+
* </ul>
|
|
39
|
+
* );
|
|
40
|
+
* }
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export function useLabelConfig(labelMap) {
|
|
45
|
+
const imf = useImFusion();
|
|
46
|
+
const stableLabelMap = useStableHandle(labelMap ?? undefined);
|
|
47
|
+
const [labelConfigs, setLabelConfigsState] = useState(() => stableLabelMap ? imf.bindings.getLabelConfigs(stableLabelMap) : undefined);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (!stableLabelMap) {
|
|
50
|
+
setLabelConfigsState(undefined);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
setLabelConfigsState(imf.bindings.getLabelConfigs(stableLabelMap));
|
|
54
|
+
const off = imf.bindings.onLabelConfigChanged(stableLabelMap, () => {
|
|
55
|
+
setLabelConfigsState(imf.bindings.getLabelConfigs(stableLabelMap));
|
|
56
|
+
});
|
|
57
|
+
return off;
|
|
58
|
+
}, [imf, stableLabelMap]);
|
|
59
|
+
const setLabelConfigs = useCallback((labelConfigMap) => {
|
|
60
|
+
if (stableLabelMap)
|
|
61
|
+
imf.bindings.setLabelConfigs(stableLabelMap, labelConfigMap);
|
|
62
|
+
}, [imf, stableLabelMap]);
|
|
63
|
+
const setLabelConfig = useCallback((labelValue, labelConfig) => {
|
|
64
|
+
if (stableLabelMap)
|
|
65
|
+
imf.bindings.setLabelConfig(stableLabelMap, labelValue, labelConfig);
|
|
66
|
+
}, [imf, stableLabelMap]);
|
|
67
|
+
return { labelConfigs, setLabelConfigs, setLabelConfig };
|
|
68
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imfusion/sdk-react",
|
|
3
|
-
"version": "1.2.2-dev.
|
|
3
|
+
"version": "1.2.2-dev.5.g9f4fc80b",
|
|
4
4
|
"description": "React bindings for ImFusion Web SDK",
|
|
5
5
|
"homepage": "https://docs.imfusion.com/websdk",
|
|
6
6
|
"author": "ImFusion GmbH",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"LICENSE.txt"
|
|
31
31
|
],
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@imfusion/sdk": "1.2.2-dev.
|
|
33
|
+
"@imfusion/sdk": "1.2.2-dev.5.g9f4fc80b",
|
|
34
34
|
"react": ">=18"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|