@imfusion/sdk-react 1.3.1-dev.7.g4d538b0f → 1.3.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.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/useBrush.d.ts +31 -0
- package/dist/useBrush.js +44 -0
- package/dist/useDisplayOptions.js +2 -2
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -17,3 +17,4 @@ export { useFrameSelection } from './useFrameSelection.js';
|
|
|
17
17
|
export { useContextMenu } from './useContextMenu.js';
|
|
18
18
|
export { useLabelConfig } from './useLabelConfig.js';
|
|
19
19
|
export { useThumbnail } from './useThumbnail.js';
|
|
20
|
+
export { useBrush } from './useBrush.js';
|
package/dist/index.js
CHANGED
|
@@ -17,3 +17,4 @@ export { useFrameSelection } from './useFrameSelection.js';
|
|
|
17
17
|
export { useContextMenu } from './useContextMenu.js';
|
|
18
18
|
export { useLabelConfig } from './useLabelConfig.js';
|
|
19
19
|
export { useThumbnail } from './useThumbnail.js';
|
|
20
|
+
export { useBrush } from './useBrush.js';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the reactive Brush state.
|
|
3
|
+
*
|
|
4
|
+
* Subscribes to {@link @imfusion/sdk!Brush.onBrushSettingsChanged | onBrushSettingsChanged} so the component re-renders
|
|
5
|
+
* when the brush's settings change.
|
|
6
|
+
*
|
|
7
|
+
* @returns The {@link @imfusion/sdk!Brush | Brush} handle
|
|
8
|
+
* @throws If called outside of an {@link ImFusionProvider}
|
|
9
|
+
* @throws If called before the SDK has finished initializing
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* function BrushAdaptivenessSlider() {
|
|
14
|
+
* const brush = useBrush();
|
|
15
|
+
*
|
|
16
|
+
* return (
|
|
17
|
+
* <input
|
|
18
|
+
* type="range"
|
|
19
|
+
* min={0}
|
|
20
|
+
* max={1}
|
|
21
|
+
* value={brush.adaptiveness}
|
|
22
|
+
* step={0.01}
|
|
23
|
+
* onChange={(event) => {
|
|
24
|
+
* brush.adaptiveness = parseFloat(event.target.value);
|
|
25
|
+
* }}
|
|
26
|
+
* ></input>
|
|
27
|
+
* );
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function useBrush(): import("@imfusion/sdk").Brush;
|
package/dist/useBrush.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useState, useEffect, useReducer } from 'react';
|
|
2
|
+
import { useImFusion } from './useImFusion.js';
|
|
3
|
+
/**
|
|
4
|
+
* Returns the reactive Brush state.
|
|
5
|
+
*
|
|
6
|
+
* Subscribes to {@link @imfusion/sdk!Brush.onBrushSettingsChanged | onBrushSettingsChanged} so the component re-renders
|
|
7
|
+
* when the brush's settings change.
|
|
8
|
+
*
|
|
9
|
+
* @returns The {@link @imfusion/sdk!Brush | Brush} handle
|
|
10
|
+
* @throws If called outside of an {@link ImFusionProvider}
|
|
11
|
+
* @throws If called before the SDK has finished initializing
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* function BrushAdaptivenessSlider() {
|
|
16
|
+
* const brush = useBrush();
|
|
17
|
+
*
|
|
18
|
+
* return (
|
|
19
|
+
* <input
|
|
20
|
+
* type="range"
|
|
21
|
+
* min={0}
|
|
22
|
+
* max={1}
|
|
23
|
+
* value={brush.adaptiveness}
|
|
24
|
+
* step={0.01}
|
|
25
|
+
* onChange={(event) => {
|
|
26
|
+
* brush.adaptiveness = parseFloat(event.target.value);
|
|
27
|
+
* }}
|
|
28
|
+
* ></input>
|
|
29
|
+
* );
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export function useBrush() {
|
|
34
|
+
const imf = useImFusion();
|
|
35
|
+
const [brush, setBrush] = useState(() => imf.brush);
|
|
36
|
+
// Triggers a re-render without mirroring all C++ properties as React state.
|
|
37
|
+
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
38
|
+
useEffect(function syncBrush() {
|
|
39
|
+
setBrush(imf.brush);
|
|
40
|
+
const off = brush.onBrushSettingsChanged(() => forceUpdate());
|
|
41
|
+
return off;
|
|
42
|
+
}, [imf, brush]);
|
|
43
|
+
return brush;
|
|
44
|
+
}
|
|
@@ -32,7 +32,7 @@ import { useStableHandle } from './useStableHandle.js';
|
|
|
32
32
|
export function useDisplayOptions2d(sis) {
|
|
33
33
|
useImFusion();
|
|
34
34
|
// Triggers a re-render without mirroring all C++ properties as React state.
|
|
35
|
-
const [, forceUpdate] = useReducer((x) =>
|
|
35
|
+
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
36
36
|
const stableSis = useStableHandle(sis);
|
|
37
37
|
const [options, setOptions] = useState(() => stableSis.displayOptions2d());
|
|
38
38
|
useEffect(() => {
|
|
@@ -74,7 +74,7 @@ export function useDisplayOptions2d(sis) {
|
|
|
74
74
|
export function useDisplayOptions3d(sis) {
|
|
75
75
|
useImFusion();
|
|
76
76
|
// Triggers a re-render without mirroring all C++ properties as React state.
|
|
77
|
-
const [, forceUpdate] = useReducer((x) =>
|
|
77
|
+
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
78
78
|
const stableSis = useStableHandle(sis);
|
|
79
79
|
const [options, setOptions] = useState(() => stableSis.displayOptions3d());
|
|
80
80
|
useEffect(() => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imfusion/sdk-react",
|
|
3
|
-
"version": "1.3.1
|
|
3
|
+
"version": "1.3.1",
|
|
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.3.1
|
|
33
|
+
"@imfusion/sdk": "1.3.1",
|
|
34
34
|
"react": ">=18"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|