@tsdraw/react 0.9.2 → 0.9.4
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.cjs +19 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +19 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -911,6 +911,11 @@ function getHandlePagePoint(bounds, handle) {
|
|
|
911
911
|
return { x: bounds.maxX, y: bounds.maxY };
|
|
912
912
|
}
|
|
913
913
|
}
|
|
914
|
+
function resolveAutoShapeOption(input) {
|
|
915
|
+
if (input === false) return { enabled: false };
|
|
916
|
+
if (input === true || input == null) return { enabled: true };
|
|
917
|
+
return { enabled: input.enabled ?? true, ...input };
|
|
918
|
+
}
|
|
914
919
|
var ZOOM_WHEEL_CAP = 10;
|
|
915
920
|
var VIEW_ONLY_TOOLS = /* @__PURE__ */ new Set(["select", "hand"]);
|
|
916
921
|
function useTsdrawCanvasController(options = {}) {
|
|
@@ -922,6 +927,7 @@ function useTsdrawCanvasController(options = {}) {
|
|
|
922
927
|
const touchOptionsRef = react.useRef(options.touchOptions);
|
|
923
928
|
const keyboardShortcutsRef = react.useRef(options.keyboardShortcuts);
|
|
924
929
|
const penOptionsRef = react.useRef(options.penOptions);
|
|
930
|
+
const autoShapeRef = react.useRef(options.autoShape);
|
|
925
931
|
const backgroundRef = react.useRef(options.background);
|
|
926
932
|
const readOnlyRef = react.useRef(options.readOnly ?? false);
|
|
927
933
|
const containerRef = react.useRef(null);
|
|
@@ -1004,6 +1010,11 @@ function useTsdrawCanvasController(options = {}) {
|
|
|
1004
1010
|
react.useEffect(() => {
|
|
1005
1011
|
penOptionsRef.current = options.penOptions;
|
|
1006
1012
|
}, [options.penOptions]);
|
|
1013
|
+
react.useEffect(() => {
|
|
1014
|
+
autoShapeRef.current = options.autoShape;
|
|
1015
|
+
const editor = editorRef.current;
|
|
1016
|
+
if (editor) editor.setAutoShape(resolveAutoShapeOption(options.autoShape));
|
|
1017
|
+
}, [options.autoShape]);
|
|
1007
1018
|
react.useEffect(() => {
|
|
1008
1019
|
backgroundRef.current = options.background;
|
|
1009
1020
|
}, [options.background]);
|
|
@@ -1142,7 +1153,8 @@ function useTsdrawCanvasController(options = {}) {
|
|
|
1142
1153
|
const editor = new core.Editor({
|
|
1143
1154
|
toolDefinitions: options.toolDefinitions,
|
|
1144
1155
|
initialToolId: initialTool,
|
|
1145
|
-
zoomRange: cameraOpts?.zoomRange
|
|
1156
|
+
zoomRange: cameraOpts?.zoomRange,
|
|
1157
|
+
autoShape: resolveAutoShapeOption(autoShapeRef.current)
|
|
1146
1158
|
});
|
|
1147
1159
|
editor.renderer.setTheme(options.theme ?? "light");
|
|
1148
1160
|
if (!editor.tools.hasTool(initialTool)) {
|
|
@@ -1775,6 +1787,10 @@ function useTsdrawCanvasController(options = {}) {
|
|
|
1775
1787
|
if (ignorePersistenceChanges) return;
|
|
1776
1788
|
schedulePersist();
|
|
1777
1789
|
});
|
|
1790
|
+
const cleanupRenderRequest = editor.onRequestRender(() => {
|
|
1791
|
+
render();
|
|
1792
|
+
refreshSelectionBounds(editor);
|
|
1793
|
+
});
|
|
1778
1794
|
resize();
|
|
1779
1795
|
const ro = new ResizeObserver(resize);
|
|
1780
1796
|
ro.observe(container);
|
|
@@ -1843,6 +1859,7 @@ function useTsdrawCanvasController(options = {}) {
|
|
|
1843
1859
|
schedulePersistRef.current = null;
|
|
1844
1860
|
cleanupEditorListener();
|
|
1845
1861
|
cleanupHistoryListener();
|
|
1862
|
+
cleanupRenderRequest();
|
|
1846
1863
|
disposeMount?.();
|
|
1847
1864
|
ro.disconnect();
|
|
1848
1865
|
canvas.removeEventListener("pointerdown", handlePointerDown);
|
|
@@ -2112,6 +2129,7 @@ function Tsdraw(props) {
|
|
|
2112
2129
|
touchOptions: props.touchOptions,
|
|
2113
2130
|
keyboardShortcuts: props.keyboardShortcuts,
|
|
2114
2131
|
penOptions: props.penOptions,
|
|
2132
|
+
autoShape: props.autoShape,
|
|
2115
2133
|
background: props.background,
|
|
2116
2134
|
readOnly: props.readOnly,
|
|
2117
2135
|
autoFocus: props.autoFocus,
|