@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.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ReactNode, CSSProperties } from 'react';
3
- import { ZoomRange, ToolId, ColorStyle, DashStyle, FillStyle, SizeStyle, Editor, ToolDefinition, TsdrawBackgroundOptions, TsdrawEditorSnapshot, TsdrawDocumentSnapshot, Viewport } from '@tsdraw/core';
4
- export { TsdrawBackgroundCustom, TsdrawBackgroundOptions, TsdrawBackgroundPreset, TsdrawBackgroundType } from '@tsdraw/core';
3
+ import { ZoomRange, ToolId, ColorStyle, DashStyle, FillStyle, SizeStyle, Editor, ToolDefinition, AutoShapeOptions, TsdrawBackgroundOptions, TsdrawEditorSnapshot, TsdrawDocumentSnapshot, Viewport } from '@tsdraw/core';
4
+ export { AutoShapeKind, AutoShapeOptions, AutoShapeThresholds, TsdrawBackgroundCustom, TsdrawBackgroundOptions, TsdrawBackgroundPreset, TsdrawBackgroundType } from '@tsdraw/core';
5
5
 
6
6
  interface TsdrawCameraOptions {
7
7
  panSpeed?: number;
@@ -156,6 +156,7 @@ interface TsdrawProps {
156
156
  touchOptions?: TsdrawTouchOptions;
157
157
  keyboardShortcuts?: TsdrawKeyboardShortcutOptions;
158
158
  penOptions?: TsdrawPenOptions;
159
+ autoShape?: boolean | AutoShapeOptions;
159
160
  background?: TsdrawBackgroundOptions;
160
161
  readOnly?: boolean;
161
162
  autoFocus?: boolean;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ReactNode, CSSProperties } from 'react';
3
- import { ZoomRange, ToolId, ColorStyle, DashStyle, FillStyle, SizeStyle, Editor, ToolDefinition, TsdrawBackgroundOptions, TsdrawEditorSnapshot, TsdrawDocumentSnapshot, Viewport } from '@tsdraw/core';
4
- export { TsdrawBackgroundCustom, TsdrawBackgroundOptions, TsdrawBackgroundPreset, TsdrawBackgroundType } from '@tsdraw/core';
3
+ import { ZoomRange, ToolId, ColorStyle, DashStyle, FillStyle, SizeStyle, Editor, ToolDefinition, AutoShapeOptions, TsdrawBackgroundOptions, TsdrawEditorSnapshot, TsdrawDocumentSnapshot, Viewport } from '@tsdraw/core';
4
+ export { AutoShapeKind, AutoShapeOptions, AutoShapeThresholds, TsdrawBackgroundCustom, TsdrawBackgroundOptions, TsdrawBackgroundPreset, TsdrawBackgroundType } from '@tsdraw/core';
5
5
 
6
6
  interface TsdrawCameraOptions {
7
7
  panSpeed?: number;
@@ -156,6 +156,7 @@ interface TsdrawProps {
156
156
  touchOptions?: TsdrawTouchOptions;
157
157
  keyboardShortcuts?: TsdrawKeyboardShortcutOptions;
158
158
  penOptions?: TsdrawPenOptions;
159
+ autoShape?: boolean | AutoShapeOptions;
159
160
  background?: TsdrawBackgroundOptions;
160
161
  readOnly?: boolean;
161
162
  autoFocus?: boolean;
package/dist/index.js CHANGED
@@ -909,6 +909,11 @@ function getHandlePagePoint(bounds, handle) {
909
909
  return { x: bounds.maxX, y: bounds.maxY };
910
910
  }
911
911
  }
912
+ function resolveAutoShapeOption(input) {
913
+ if (input === false) return { enabled: false };
914
+ if (input === true || input == null) return { enabled: true };
915
+ return { enabled: input.enabled ?? true, ...input };
916
+ }
912
917
  var ZOOM_WHEEL_CAP = 10;
913
918
  var VIEW_ONLY_TOOLS = /* @__PURE__ */ new Set(["select", "hand"]);
914
919
  function useTsdrawCanvasController(options = {}) {
@@ -920,6 +925,7 @@ function useTsdrawCanvasController(options = {}) {
920
925
  const touchOptionsRef = useRef(options.touchOptions);
921
926
  const keyboardShortcutsRef = useRef(options.keyboardShortcuts);
922
927
  const penOptionsRef = useRef(options.penOptions);
928
+ const autoShapeRef = useRef(options.autoShape);
923
929
  const backgroundRef = useRef(options.background);
924
930
  const readOnlyRef = useRef(options.readOnly ?? false);
925
931
  const containerRef = useRef(null);
@@ -1002,6 +1008,11 @@ function useTsdrawCanvasController(options = {}) {
1002
1008
  useEffect(() => {
1003
1009
  penOptionsRef.current = options.penOptions;
1004
1010
  }, [options.penOptions]);
1011
+ useEffect(() => {
1012
+ autoShapeRef.current = options.autoShape;
1013
+ const editor = editorRef.current;
1014
+ if (editor) editor.setAutoShape(resolveAutoShapeOption(options.autoShape));
1015
+ }, [options.autoShape]);
1005
1016
  useEffect(() => {
1006
1017
  backgroundRef.current = options.background;
1007
1018
  }, [options.background]);
@@ -1140,7 +1151,8 @@ function useTsdrawCanvasController(options = {}) {
1140
1151
  const editor = new Editor({
1141
1152
  toolDefinitions: options.toolDefinitions,
1142
1153
  initialToolId: initialTool,
1143
- zoomRange: cameraOpts?.zoomRange
1154
+ zoomRange: cameraOpts?.zoomRange,
1155
+ autoShape: resolveAutoShapeOption(autoShapeRef.current)
1144
1156
  });
1145
1157
  editor.renderer.setTheme(options.theme ?? "light");
1146
1158
  if (!editor.tools.hasTool(initialTool)) {
@@ -1773,6 +1785,10 @@ function useTsdrawCanvasController(options = {}) {
1773
1785
  if (ignorePersistenceChanges) return;
1774
1786
  schedulePersist();
1775
1787
  });
1788
+ const cleanupRenderRequest = editor.onRequestRender(() => {
1789
+ render();
1790
+ refreshSelectionBounds(editor);
1791
+ });
1776
1792
  resize();
1777
1793
  const ro = new ResizeObserver(resize);
1778
1794
  ro.observe(container);
@@ -1841,6 +1857,7 @@ function useTsdrawCanvasController(options = {}) {
1841
1857
  schedulePersistRef.current = null;
1842
1858
  cleanupEditorListener();
1843
1859
  cleanupHistoryListener();
1860
+ cleanupRenderRequest();
1844
1861
  disposeMount?.();
1845
1862
  ro.disconnect();
1846
1863
  canvas.removeEventListener("pointerdown", handlePointerDown);
@@ -2110,6 +2127,7 @@ function Tsdraw(props) {
2110
2127
  touchOptions: props.touchOptions,
2111
2128
  keyboardShortcuts: props.keyboardShortcuts,
2112
2129
  penOptions: props.penOptions,
2130
+ autoShape: props.autoShape,
2113
2131
  background: props.background,
2114
2132
  readOnly: props.readOnly,
2115
2133
  autoFocus: props.autoFocus,