@base2datadesign/viewer-react 0.1.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/ViewerCanvas.d.ts +12 -0
- package/dist/ViewerCanvas.d.ts.map +1 -0
- package/dist/ViewerCanvas.js +55 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/package.json +35 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PresetCatalog, ViewerCreateOptions, ViewerHandle } from "@base2datadesign/viewer-kit";
|
|
2
|
+
export type ViewerCanvasProps = {
|
|
3
|
+
presetId?: string;
|
|
4
|
+
presets?: PresetCatalog;
|
|
5
|
+
assetResolver?: ViewerCreateOptions["assetResolver"];
|
|
6
|
+
camera?: ViewerCreateOptions["camera"];
|
|
7
|
+
renderer?: ViewerCreateOptions["renderer"];
|
|
8
|
+
className?: string;
|
|
9
|
+
onReady?: (handle: ViewerHandle | null) => void;
|
|
10
|
+
};
|
|
11
|
+
export default function ViewerCanvas({ presetId, presets, assetResolver, camera, renderer, className, onReady, }: ViewerCanvasProps): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
//# sourceMappingURL=ViewerCanvas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ViewerCanvas.d.ts","sourceRoot":"","sources":["../src/ViewerCanvas.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEpG,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,aAAa,CAAC,EAAE,mBAAmB,CAAC,eAAe,CAAC,CAAC;IACrD,MAAM,CAAC,EAAE,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IACvC,QAAQ,CAAC,EAAE,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,KAAK,IAAI,CAAC;CACjD,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EACnC,QAAQ,EACR,OAAO,EACP,aAAa,EACb,MAAM,EACN,QAAQ,EACR,SAAS,EACT,OAAO,GACR,EAAE,iBAAiB,2CAwDnB"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
3
|
+
import { createViewer } from "@base2datadesign/viewer-kit";
|
|
4
|
+
export default function ViewerCanvas({ presetId, presets, assetResolver, camera, renderer, className, onReady, }) {
|
|
5
|
+
const containerRef = useRef(null);
|
|
6
|
+
const handleRef = useRef(null);
|
|
7
|
+
const presetIdRef = useRef(presetId);
|
|
8
|
+
const initialPresetRef = useRef(presetId);
|
|
9
|
+
const createOptions = useMemo(() => {
|
|
10
|
+
return {
|
|
11
|
+
container: containerRef.current,
|
|
12
|
+
presetId: initialPresetRef.current,
|
|
13
|
+
presets,
|
|
14
|
+
assetResolver,
|
|
15
|
+
camera,
|
|
16
|
+
renderer,
|
|
17
|
+
hooks: {
|
|
18
|
+
onReady: (handle) => {
|
|
19
|
+
handleRef.current = handle;
|
|
20
|
+
onReady?.(handle);
|
|
21
|
+
},
|
|
22
|
+
onError: (error) => {
|
|
23
|
+
console.error("[viewer-react] Failed to initialise viewer", error);
|
|
24
|
+
onReady?.(null);
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}, [assetResolver, camera, onReady, presets, renderer]);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
const container = containerRef.current;
|
|
31
|
+
if (!container)
|
|
32
|
+
return;
|
|
33
|
+
const handle = createViewer({ ...createOptions, container });
|
|
34
|
+
handleRef.current = handle;
|
|
35
|
+
handle.start();
|
|
36
|
+
const handleResize = () => handle.resize();
|
|
37
|
+
window.addEventListener("resize", handleResize);
|
|
38
|
+
return () => {
|
|
39
|
+
window.removeEventListener("resize", handleResize);
|
|
40
|
+
handle.stop();
|
|
41
|
+
handle.dispose();
|
|
42
|
+
handleRef.current = null;
|
|
43
|
+
onReady?.(null);
|
|
44
|
+
};
|
|
45
|
+
}, [createOptions, onReady]);
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (!handleRef.current)
|
|
48
|
+
return;
|
|
49
|
+
if (presetId && presetIdRef.current !== presetId) {
|
|
50
|
+
presetIdRef.current = presetId;
|
|
51
|
+
handleRef.current.setPreset(presetId);
|
|
52
|
+
}
|
|
53
|
+
}, [presetId]);
|
|
54
|
+
return _jsx("div", { ref: containerRef, className: className });
|
|
55
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACzD,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as ViewerCanvas } from "./ViewerCanvas";
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@base2datadesign/viewer-react",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@base2datadesign/viewer-kit": "^0.1.1"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"react": ">=18"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"react": "19.1.0",
|
|
28
|
+
"@types/react": "^19",
|
|
29
|
+
"@types/react-dom": "^19"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc -b",
|
|
33
|
+
"typecheck": "tsc -b --pretty false --noEmit"
|
|
34
|
+
}
|
|
35
|
+
}
|