@react-fabric/draw 1.0.0-beta.6 → 1.0.0-beta.60

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.
Files changed (35) hide show
  1. package/dist/cjs/{packages/draw/src/canvas → canvas}/DrawCanvas.js +26 -4
  2. package/dist/cjs/{packages/draw/src/canvas → canvas}/shapes/avatar/AvatarShapeTool.js +4 -3
  3. package/dist/cjs/{packages/draw/src/canvas → canvas}/shapes/avatar/PointingState.js +1 -1
  4. package/dist/cjs/{packages/draw/src/canvas → canvas}/shapes/custom/AudioShape.js +2 -2
  5. package/dist/cjs/{packages/draw/src/canvas → canvas}/shapes/custom/CardShape.js +2 -2
  6. package/dist/cjs/{packages/draw/src/canvas → canvas}/shapes/custom/FileShape.js +2 -2
  7. package/dist/cjs/{packages/draw/src/canvas → canvas}/shapes/custom/ImageShape.js +2 -2
  8. package/dist/cjs/{packages/draw/src/canvas → canvas}/shapes/custom/VideoShape.js +2 -2
  9. package/dist/esm/{packages/draw/src/canvas → canvas}/DrawCanvas.js +26 -4
  10. package/dist/esm/{packages/draw/src/canvas → canvas}/shapes/avatar/AvatarShapeTool.js +3 -2
  11. package/dist/esm/{packages/draw/src/canvas → canvas}/shapes/avatar/PointingState.js +1 -1
  12. package/dist/esm/{packages/draw/src/canvas → canvas}/shapes/custom/AudioShape.js +1 -1
  13. package/dist/esm/{packages/draw/src/canvas → canvas}/shapes/custom/CardShape.js +1 -1
  14. package/dist/esm/{packages/draw/src/canvas → canvas}/shapes/custom/FileShape.js +1 -1
  15. package/dist/esm/{packages/draw/src/canvas → canvas}/shapes/custom/ImageShape.js +1 -1
  16. package/dist/esm/{packages/draw/src/canvas → canvas}/shapes/custom/VideoShape.js +1 -1
  17. package/dist/types/canvas/DrawCanvas.d.ts +23 -2
  18. package/package.json +16 -12
  19. package/src/canvas/DrawCanvas.tsx +27 -6
  20. package/src/canvas/shapes/avatar/AvatarShapeTool.tsx +4 -1
  21. package/src/canvas/shapes/avatar/PointingState.ts +1 -2
  22. package/dist/cjs/_virtual/_commonjsHelpers.js +0 -7
  23. package/dist/cjs/_virtual/dom-to-image.js +0 -5
  24. package/dist/cjs/node_modules/dom-to-image/src/dom-to-image.js +0 -777
  25. package/dist/esm/_virtual/_commonjsHelpers.js +0 -7
  26. package/dist/esm/_virtual/dom-to-image.js +0 -5
  27. package/dist/esm/node_modules/dom-to-image/src/dom-to-image.js +0 -777
  28. /package/dist/cjs/{packages/draw/src/canvas → canvas}/DrawContext.js +0 -0
  29. /package/dist/cjs/{packages/draw/src/canvas → canvas}/shapes/avatar/IdleState.js +0 -0
  30. /package/dist/cjs/{packages/draw/src/canvas → canvas}/shapes/avatar/type.js +0 -0
  31. /package/dist/cjs/{packages/draw/src/index.js → index.js} +0 -0
  32. /package/dist/esm/{packages/draw/src/canvas → canvas}/DrawContext.js +0 -0
  33. /package/dist/esm/{packages/draw/src/canvas → canvas}/shapes/avatar/IdleState.js +0 -0
  34. /package/dist/esm/{packages/draw/src/canvas → canvas}/shapes/avatar/type.js +0 -0
  35. /package/dist/esm/{packages/draw/src/index.js → index.js} +0 -0
@@ -112,6 +112,28 @@ var TypeMap = {
112
112
  file: "file-card",
113
113
  card: "data-card"
114
114
  };
115
+
116
+ /**
117
+ * DrawCanvas component to render a Tldraw editor canvas.
118
+ * It allows users to create and manipulate shapes, images, videos, audio, files, and cards.
119
+ * It supports drag-and-drop functionality for adding shapes to the canvas.
120
+ * It also provides a method to export the current pages as snapshots.
121
+ *
122
+ * @param {DrawProps} props - The properties for the component.
123
+ * @returns {JSX.Element} The rendered DrawCanvas component.
124
+ *
125
+ * @example
126
+ * ```jsx
127
+ * <DrawCanvas
128
+ * snapshot={snapshot}
129
+ * onUpdate={(snapshot) => console.log(snapshot)}
130
+ * canvasRef={canvasRef}
131
+ * />
132
+ * ```
133
+ *
134
+ * @see {@link https://adarshpastakia.github.io/react-fabric/?path=/story/draw-playground--playground}
135
+ * @see {@link https://tldraw.com/docs/}
136
+ */
115
137
  var DrawCanvas = function DrawCanvas(_ref) {
116
138
  var snapshot = _ref.snapshot,
117
139
  renderer = _ref.renderer,
@@ -185,7 +207,7 @@ var DrawCanvas = function DrawCanvas(_ref) {
185
207
  while (1) switch (_context2.prev = _context2.next) {
186
208
  case 0:
187
209
  currentPage = editorRef === null || editorRef === void 0 ? void 0 : editorRef.getCurrentPageId();
188
- pages = Object.keys((_editorRef$store$getS = editorRef === null || editorRef === void 0 ? void 0 : editorRef.store.getSnapshot().store) !== null && _editorRef$store$getS !== void 0 ? _editorRef$store$getS : {}).filter(function (key) {
210
+ pages = Object.keys((_editorRef$store$getS = editorRef === null || editorRef === void 0 ? void 0 : editorRef.store.getStoreSnapshot().store) !== null && _editorRef$store$getS !== void 0 ? _editorRef$store$getS : {}).filter(function (key) {
189
211
  return key.startsWith("page:");
190
212
  });
191
213
  pageSnapshots = [];
@@ -208,7 +230,7 @@ var DrawCanvas = function DrawCanvas(_ref) {
208
230
  case 3:
209
231
  shapes = editorRef === null || editorRef === void 0 ? void 0 : editorRef.getCurrentPageShapeIds();
210
232
  _context.next = 6;
211
- return editorRef === null || editorRef === void 0 ? void 0 : editorRef.getSvg(_toConsumableArray(shapes), {
233
+ return editorRef === null || editorRef === void 0 ? void 0 : editorRef.getSvgElement(_toConsumableArray(shapes), {
212
234
  scale: 1,
213
235
  background: true
214
236
  });
@@ -222,7 +244,7 @@ var DrawCanvas = function DrawCanvas(_ref) {
222
244
  _context.t1 = pg;
223
245
  _context.t2 = editorRef === null || editorRef === void 0 ? void 0 : editorRef.getCurrentPage().name;
224
246
  _context.next = 13;
225
- return getSvgAsDataUrl(svg);
247
+ return getSvgAsDataUrl(svg.svg);
226
248
  case 13:
227
249
  _context.t3 = _context.sent;
228
250
  _context.t4 = {
@@ -315,7 +337,7 @@ var DrawCanvas = function DrawCanvas(_ref) {
315
337
  className: "absolute inset-0",
316
338
  onDragOver: handleDragOver,
317
339
  onDrop: handleDrop,
318
- "data-testid": "draw-canvas",
340
+ "data-ref": "drawCanvas",
319
341
  children: TLDraw
320
342
  })
321
343
  })
@@ -11,7 +11,7 @@ var _regeneratorRuntime = require('@babel/runtime/regenerator');
11
11
  var core = require('@react-fabric/core');
12
12
  var editor = require('@tldraw/editor');
13
13
  var tldraw = require('@tldraw/tldraw');
14
- var domToImage = require('../../../../../../node_modules/dom-to-image/src/dom-to-image.js');
14
+ var domtoimage = require('dom-to-image');
15
15
  var react = require('react');
16
16
  var IdleState = require('./IdleState.js');
17
17
  var PointingState = require('./PointingState.js');
@@ -210,7 +210,8 @@ var AvatarShapeUtil = /*#__PURE__*/function (_ShapeUtil) {
210
210
  wrap: "off",
211
211
  dir: "auto",
212
212
  ref: function ref(el) {
213
- return [el === null || el === void 0 ? void 0 : el.select(), el === null || el === void 0 ? void 0 : el.focus()];
213
+ el === null || el === void 0 || el.select();
214
+ el === null || el === void 0 || el.focus();
214
215
  },
215
216
  onKeyDown: function onKeyDown(e) {
216
217
  return e.key === "Enter" && (e.stopPropagation(), _this3.onChange(shape, inputRef.current), _this3.editor.setEditingShape(null));
@@ -243,7 +244,7 @@ var AvatarShapeUtil = /*#__PURE__*/function (_ShapeUtil) {
243
244
  }));
244
245
  case 3:
245
246
  _context.next = 5;
246
- return domToImage.toPng(el).then(function (dataUrl) {
247
+ return domtoimage.toPng(el).then(function (dataUrl) {
247
248
  return /*#__PURE__*/jsxRuntime.jsx("img", {
248
249
  src: dataUrl,
249
250
  alt: "svg"
@@ -39,7 +39,6 @@ var Pointing = /*#__PURE__*/function (_StateNode) {
39
39
  var originPagePoint = _this.editor.inputs.originPagePoint;
40
40
  var id = tldraw.createShapeId();
41
41
  _this.markId = "creating:".concat(id);
42
- _this.editor.mark(_this.markId);
43
42
  _this.editor.createShapes([{
44
43
  id: id,
45
44
  type: "avatar",
@@ -56,6 +55,7 @@ var Pointing = /*#__PURE__*/function (_StateNode) {
56
55
  target: "selection",
57
56
  handle: "bottom_right",
58
57
  isCreating: true,
58
+ creatingMarkId: _this.markId,
59
59
  creationCursorOffset: {
60
60
  x: 1,
61
61
  y: 1
@@ -10,7 +10,7 @@ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
10
10
  var _regeneratorRuntime = require('@babel/runtime/regenerator');
11
11
  var utilities = require('@react-fabric/utilities');
12
12
  var tldraw = require('@tldraw/tldraw');
13
- var domToImage = require('../../../../../../node_modules/dom-to-image/src/dom-to-image.js');
13
+ var domtoimage = require('dom-to-image');
14
14
  var react = require('react');
15
15
  var jsxRuntime = require('react/jsx-runtime');
16
16
 
@@ -124,7 +124,7 @@ var AudioShapeUtil = /*#__PURE__*/function (_ShapeUtil) {
124
124
  el.childNodes.item(0).style.display = "none";
125
125
  el.childNodes.item(1).style.display = "block";
126
126
  _context.next = 7;
127
- return domToImage.toPng(el).then(function (dataUrl) {
127
+ return domtoimage.toPng(el).then(function (dataUrl) {
128
128
  el.childNodes.item(0).style.display = "block";
129
129
  el.childNodes.item(1).style.display = "none";
130
130
  return /*#__PURE__*/jsxRuntime.jsx("img", {
@@ -9,7 +9,7 @@ var _inherits = require('@babel/runtime/helpers/inherits');
9
9
  var _defineProperty = require('@babel/runtime/helpers/defineProperty');
10
10
  var _regeneratorRuntime = require('@babel/runtime/regenerator');
11
11
  var tldraw = require('@tldraw/tldraw');
12
- var domToImage = require('../../../../../../node_modules/dom-to-image/src/dom-to-image.js');
12
+ var domtoimage = require('dom-to-image');
13
13
  var DrawContext = require('../../DrawContext.js');
14
14
  var jsxRuntime = require('react/jsx-runtime');
15
15
 
@@ -89,7 +89,7 @@ var CardShapeUtil = /*#__PURE__*/function (_ShapeUtil) {
89
89
  }));
90
90
  case 3:
91
91
  _context.next = 5;
92
- return domToImage.toPng(el).then(function (dataUrl) {
92
+ return domtoimage.toPng(el).then(function (dataUrl) {
93
93
  return /*#__PURE__*/jsxRuntime.jsx("img", {
94
94
  src: dataUrl,
95
95
  alt: "svg"
@@ -10,7 +10,7 @@ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
10
10
  var _regeneratorRuntime = require('@babel/runtime/regenerator');
11
11
  var utilities = require('@react-fabric/utilities');
12
12
  var tldraw = require('@tldraw/tldraw');
13
- var domToImage = require('../../../../../../node_modules/dom-to-image/src/dom-to-image.js');
13
+ var domtoimage = require('dom-to-image');
14
14
  var jsxRuntime = require('react/jsx-runtime');
15
15
 
16
16
  function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
@@ -102,7 +102,7 @@ var FileShapeUtil = /*#__PURE__*/function (_ShapeUtil) {
102
102
  }));
103
103
  case 3:
104
104
  _context.next = 5;
105
- return domToImage.toPng(el).then(function (dataUrl) {
105
+ return domtoimage.toPng(el).then(function (dataUrl) {
106
106
  return /*#__PURE__*/jsxRuntime.jsx("img", {
107
107
  src: dataUrl,
108
108
  alt: "svg"
@@ -10,7 +10,7 @@ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
10
10
  var _regeneratorRuntime = require('@babel/runtime/regenerator');
11
11
  var utilities = require('@react-fabric/utilities');
12
12
  var tldraw = require('@tldraw/tldraw');
13
- var domToImage = require('../../../../../../node_modules/dom-to-image/src/dom-to-image.js');
13
+ var domtoimage = require('dom-to-image');
14
14
  var jsxRuntime = require('react/jsx-runtime');
15
15
 
16
16
  function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
@@ -111,7 +111,7 @@ var ImageShapeUtil = /*#__PURE__*/function (_ShapeUtil) {
111
111
  }));
112
112
  case 3:
113
113
  _context.next = 5;
114
- return domToImage.toPng(el).then(function (dataUrl) {
114
+ return domtoimage.toPng(el).then(function (dataUrl) {
115
115
  return /*#__PURE__*/jsxRuntime.jsx("img", {
116
116
  src: dataUrl,
117
117
  alt: "svg"
@@ -10,7 +10,7 @@ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
10
10
  var _regeneratorRuntime = require('@babel/runtime/regenerator');
11
11
  var utilities = require('@react-fabric/utilities');
12
12
  var tldraw = require('@tldraw/tldraw');
13
- var domToImage = require('../../../../../../node_modules/dom-to-image/src/dom-to-image.js');
13
+ var domtoimage = require('dom-to-image');
14
14
  var react = require('react');
15
15
  var jsxRuntime = require('react/jsx-runtime');
16
16
 
@@ -132,7 +132,7 @@ var VideoShapeUtil = /*#__PURE__*/function (_ShapeUtil) {
132
132
  el.childNodes.item(0).style.display = "none";
133
133
  el.childNodes.item(1).style.display = "block";
134
134
  _context.next = 7;
135
- return domToImage.toPng(el).then(function (dataUrl) {
135
+ return domtoimage.toPng(el).then(function (dataUrl) {
136
136
  el.childNodes.item(0).style.display = "block";
137
137
  el.childNodes.item(1).style.display = "none";
138
138
  return /*#__PURE__*/jsxRuntime.jsx("img", {
@@ -112,6 +112,28 @@ var TypeMap = {
112
112
  file: "file-card",
113
113
  card: "data-card"
114
114
  };
115
+
116
+ /**
117
+ * DrawCanvas component to render a Tldraw editor canvas.
118
+ * It allows users to create and manipulate shapes, images, videos, audio, files, and cards.
119
+ * It supports drag-and-drop functionality for adding shapes to the canvas.
120
+ * It also provides a method to export the current pages as snapshots.
121
+ *
122
+ * @param {DrawProps} props - The properties for the component.
123
+ * @returns {JSX.Element} The rendered DrawCanvas component.
124
+ *
125
+ * @example
126
+ * ```jsx
127
+ * <DrawCanvas
128
+ * snapshot={snapshot}
129
+ * onUpdate={(snapshot) => console.log(snapshot)}
130
+ * canvasRef={canvasRef}
131
+ * />
132
+ * ```
133
+ *
134
+ * @see {@link https://adarshpastakia.github.io/react-fabric/?path=/story/draw-playground--playground}
135
+ * @see {@link https://tldraw.com/docs/}
136
+ */
115
137
  var DrawCanvas = function DrawCanvas(_ref) {
116
138
  var snapshot = _ref.snapshot,
117
139
  renderer = _ref.renderer,
@@ -185,7 +207,7 @@ var DrawCanvas = function DrawCanvas(_ref) {
185
207
  while (1) switch (_context2.prev = _context2.next) {
186
208
  case 0:
187
209
  currentPage = editorRef === null || editorRef === void 0 ? void 0 : editorRef.getCurrentPageId();
188
- pages = Object.keys((_editorRef$store$getS = editorRef === null || editorRef === void 0 ? void 0 : editorRef.store.getSnapshot().store) !== null && _editorRef$store$getS !== void 0 ? _editorRef$store$getS : {}).filter(function (key) {
210
+ pages = Object.keys((_editorRef$store$getS = editorRef === null || editorRef === void 0 ? void 0 : editorRef.store.getStoreSnapshot().store) !== null && _editorRef$store$getS !== void 0 ? _editorRef$store$getS : {}).filter(function (key) {
189
211
  return key.startsWith("page:");
190
212
  });
191
213
  pageSnapshots = [];
@@ -208,7 +230,7 @@ var DrawCanvas = function DrawCanvas(_ref) {
208
230
  case 3:
209
231
  shapes = editorRef === null || editorRef === void 0 ? void 0 : editorRef.getCurrentPageShapeIds();
210
232
  _context.next = 6;
211
- return editorRef === null || editorRef === void 0 ? void 0 : editorRef.getSvg(_toConsumableArray(shapes), {
233
+ return editorRef === null || editorRef === void 0 ? void 0 : editorRef.getSvgElement(_toConsumableArray(shapes), {
212
234
  scale: 1,
213
235
  background: true
214
236
  });
@@ -222,7 +244,7 @@ var DrawCanvas = function DrawCanvas(_ref) {
222
244
  _context.t1 = pg;
223
245
  _context.t2 = editorRef === null || editorRef === void 0 ? void 0 : editorRef.getCurrentPage().name;
224
246
  _context.next = 13;
225
- return getSvgAsDataUrl(svg);
247
+ return getSvgAsDataUrl(svg.svg);
226
248
  case 13:
227
249
  _context.t3 = _context.sent;
228
250
  _context.t4 = {
@@ -315,7 +337,7 @@ var DrawCanvas = function DrawCanvas(_ref) {
315
337
  className: "absolute inset-0",
316
338
  onDragOver: handleDragOver,
317
339
  onDrop: handleDrop,
318
- "data-testid": "draw-canvas",
340
+ "data-ref": "drawCanvas",
319
341
  children: TLDraw
320
342
  })
321
343
  })
@@ -11,7 +11,7 @@ import _regeneratorRuntime from '@babel/runtime/regenerator';
11
11
  import { useIsDark } from '@react-fabric/core';
12
12
  import { StateNode } from '@tldraw/editor';
13
13
  import { Rectangle2d, useIsEditing, getDefaultColorTheme, ShapeUtil } from '@tldraw/tldraw';
14
- import domtoimage from '../../../../../../node_modules/dom-to-image/src/dom-to-image.js';
14
+ import domtoimage from 'dom-to-image';
15
15
  import { useRef, useEffect } from 'react';
16
16
  import { Idle } from './IdleState.js';
17
17
  import { Pointing } from './PointingState.js';
@@ -210,7 +210,8 @@ var AvatarShapeUtil = /*#__PURE__*/function (_ShapeUtil) {
210
210
  wrap: "off",
211
211
  dir: "auto",
212
212
  ref: function ref(el) {
213
- return [el === null || el === void 0 ? void 0 : el.select(), el === null || el === void 0 ? void 0 : el.focus()];
213
+ el === null || el === void 0 || el.select();
214
+ el === null || el === void 0 || el.focus();
214
215
  },
215
216
  onKeyDown: function onKeyDown(e) {
216
217
  return e.key === "Enter" && (e.stopPropagation(), _this3.onChange(shape, inputRef.current), _this3.editor.setEditingShape(null));
@@ -39,7 +39,6 @@ var Pointing = /*#__PURE__*/function (_StateNode) {
39
39
  var originPagePoint = _this.editor.inputs.originPagePoint;
40
40
  var id = createShapeId();
41
41
  _this.markId = "creating:".concat(id);
42
- _this.editor.mark(_this.markId);
43
42
  _this.editor.createShapes([{
44
43
  id: id,
45
44
  type: "avatar",
@@ -56,6 +55,7 @@ var Pointing = /*#__PURE__*/function (_StateNode) {
56
55
  target: "selection",
57
56
  handle: "bottom_right",
58
57
  isCreating: true,
58
+ creatingMarkId: _this.markId,
59
59
  creationCursorOffset: {
60
60
  x: 1,
61
61
  y: 1
@@ -10,7 +10,7 @@ import _defineProperty from '@babel/runtime/helpers/defineProperty';
10
10
  import _regeneratorRuntime from '@babel/runtime/regenerator';
11
11
  import { Format } from '@react-fabric/utilities';
12
12
  import { Rectangle2d, HTMLContainer, ShapeUtil } from '@tldraw/tldraw';
13
- import domtoimage from '../../../../../../node_modules/dom-to-image/src/dom-to-image.js';
13
+ import domtoimage from 'dom-to-image';
14
14
  import { useRef, useEffect } from 'react';
15
15
  import { jsx, jsxs } from 'react/jsx-runtime';
16
16
 
@@ -9,7 +9,7 @@ import _inherits from '@babel/runtime/helpers/inherits';
9
9
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
10
10
  import _regeneratorRuntime from '@babel/runtime/regenerator';
11
11
  import { Rectangle2d, HTMLContainer, ShapeUtil } from '@tldraw/tldraw';
12
- import domtoimage from '../../../../../../node_modules/dom-to-image/src/dom-to-image.js';
12
+ import domtoimage from 'dom-to-image';
13
13
  import { useDrawContext } from '../../DrawContext.js';
14
14
  import { jsx } from 'react/jsx-runtime';
15
15
 
@@ -10,7 +10,7 @@ import _defineProperty from '@babel/runtime/helpers/defineProperty';
10
10
  import _regeneratorRuntime from '@babel/runtime/regenerator';
11
11
  import { Format } from '@react-fabric/utilities';
12
12
  import { Rectangle2d, HTMLContainer, ShapeUtil } from '@tldraw/tldraw';
13
- import domtoimage from '../../../../../../node_modules/dom-to-image/src/dom-to-image.js';
13
+ import domtoimage from 'dom-to-image';
14
14
  import { jsx, jsxs } from 'react/jsx-runtime';
15
15
 
16
16
  function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
@@ -10,7 +10,7 @@ import _defineProperty from '@babel/runtime/helpers/defineProperty';
10
10
  import _regeneratorRuntime from '@babel/runtime/regenerator';
11
11
  import { Format } from '@react-fabric/utilities';
12
12
  import { Rectangle2d, HTMLContainer, ShapeUtil } from '@tldraw/tldraw';
13
- import domtoimage from '../../../../../../node_modules/dom-to-image/src/dom-to-image.js';
13
+ import domtoimage from 'dom-to-image';
14
14
  import { jsx, jsxs } from 'react/jsx-runtime';
15
15
 
16
16
  function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
@@ -10,7 +10,7 @@ import _defineProperty from '@babel/runtime/helpers/defineProperty';
10
10
  import _regeneratorRuntime from '@babel/runtime/regenerator';
11
11
  import { Format } from '@react-fabric/utilities';
12
12
  import { Rectangle2d, HTMLContainer, ShapeUtil } from '@tldraw/tldraw';
13
- import domtoimage from '../../../../../../node_modules/dom-to-image/src/dom-to-image.js';
13
+ import domtoimage from 'dom-to-image';
14
14
  import { useRef, useEffect } from 'react';
15
15
  import { jsx, jsxs } from 'react/jsx-runtime';
16
16
 
@@ -1,13 +1,34 @@
1
1
  import { type TLEditorSnapshot } from "@tldraw/tldraw";
2
2
  import "@tldraw/tldraw/tldraw.css";
3
- import { type FC, type RefObject } from "react";
3
+ import { type FC, type Ref } from "react";
4
4
  export declare function getSvgAsDataUrl(svg: SVGElement): Promise<string>;
5
5
  export interface DrawProps {
6
6
  snapshot?: TLEditorSnapshot;
7
7
  onUpdate?: (snapshot: TLEditorSnapshot) => void;
8
8
  renderer?: (props: KeyValue) => AnyObject;
9
- canvasRef?: RefObject<{
9
+ canvasRef?: Ref<{
10
10
  exportPages: () => Promise<KeyValue[]>;
11
11
  }>;
12
12
  }
13
+ /**
14
+ * DrawCanvas component to render a Tldraw editor canvas.
15
+ * It allows users to create and manipulate shapes, images, videos, audio, files, and cards.
16
+ * It supports drag-and-drop functionality for adding shapes to the canvas.
17
+ * It also provides a method to export the current pages as snapshots.
18
+ *
19
+ * @param {DrawProps} props - The properties for the component.
20
+ * @returns {JSX.Element} The rendered DrawCanvas component.
21
+ *
22
+ * @example
23
+ * ```jsx
24
+ * <DrawCanvas
25
+ * snapshot={snapshot}
26
+ * onUpdate={(snapshot) => console.log(snapshot)}
27
+ * canvasRef={canvasRef}
28
+ * />
29
+ * ```
30
+ *
31
+ * @see {@link https://adarshpastakia.github.io/react-fabric/?path=/story/draw-playground--playground}
32
+ * @see {@link https://tldraw.com/docs/}
33
+ */
13
34
  export declare const DrawCanvas: FC<DrawProps>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-fabric/draw",
3
- "version": "1.0.0-beta.6",
3
+ "version": "1.0.0-beta.60",
4
4
  "description": "RUF: TLDraw canvas",
5
5
  "author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
6
6
  "license": "MIT",
@@ -33,22 +33,26 @@
33
33
  "watch": "npm-run-all -p watch:rollup watch:dts"
34
34
  },
35
35
  "dependencies": {
36
- "@react-fabric/core": "^1.0.0-beta.6",
37
- "@react-fabric/utilities": "^1.0.0-beta.6",
38
- "@tldraw/assets": "^3.3.1",
39
- "@tldraw/editor": "^3.3.1",
40
- "@tldraw/tldraw": "^3.3.1",
41
- "classnames": "^2.5.1"
36
+ "@react-fabric/core": "^1.0.0-beta.60",
37
+ "@react-fabric/utilities": "^1.0.0-beta.60",
38
+ "@tldraw/assets": "~4.1.2",
39
+ "@tldraw/editor": "~4.1.2",
40
+ "@tldraw/tldraw": "~4.1.2",
41
+ "classnames": "~2.5.1",
42
+ "dom-to-image": "~2.6.0"
42
43
  },
43
44
  "peerDependencies": {
44
- "i18next": "^23.15.1",
45
- "react": ">=18.0.0 <20.0.0",
46
- "react-dom": ">=18.0.0 <20.0.0",
47
- "react-i18next": "^15.0.2"
45
+ "i18next": "~25.6.0",
46
+ "react": "~19.2.0",
47
+ "react-dom": "~19.2.0",
48
+ "react-i18next": "~16.2.1"
49
+ },
50
+ "devDependencies": {
51
+ "@types/dom-to-image": "~2.6.7"
48
52
  },
49
53
  "engines": {
50
54
  "node": ">=18.12.0",
51
55
  "npm": ">=8.19.0"
52
56
  },
53
- "gitHead": "21167df13cedeae8b365e87b9bab6d7401298cb6"
57
+ "gitHead": "a79f053ee7e13422c06d7d9c35d4f0c2610cdf5d"
54
58
  }
@@ -46,7 +46,7 @@ import {
46
46
  useState,
47
47
  type DragEvent,
48
48
  type FC,
49
- type RefObject,
49
+ type Ref,
50
50
  } from "react";
51
51
  import { DrawContextProvider } from "./DrawContext";
52
52
  import {
@@ -101,7 +101,7 @@ export interface DrawProps {
101
101
  snapshot?: TLEditorSnapshot;
102
102
  onUpdate?: (snapshot: TLEditorSnapshot) => void;
103
103
  renderer?: (props: KeyValue) => AnyObject;
104
- canvasRef?: RefObject<{ exportPages: () => Promise<KeyValue[]> }>;
104
+ canvasRef?: Ref<{ exportPages: () => Promise<KeyValue[]> }>;
105
105
  }
106
106
 
107
107
  const TypeMap: KeyValue = {
@@ -112,6 +112,27 @@ const TypeMap: KeyValue = {
112
112
  card: "data-card",
113
113
  };
114
114
 
115
+ /**
116
+ * DrawCanvas component to render a Tldraw editor canvas.
117
+ * It allows users to create and manipulate shapes, images, videos, audio, files, and cards.
118
+ * It supports drag-and-drop functionality for adding shapes to the canvas.
119
+ * It also provides a method to export the current pages as snapshots.
120
+ *
121
+ * @param {DrawProps} props - The properties for the component.
122
+ * @returns {JSX.Element} The rendered DrawCanvas component.
123
+ *
124
+ * @example
125
+ * ```jsx
126
+ * <DrawCanvas
127
+ * snapshot={snapshot}
128
+ * onUpdate={(snapshot) => console.log(snapshot)}
129
+ * canvasRef={canvasRef}
130
+ * />
131
+ * ```
132
+ *
133
+ * @see {@link https://adarshpastakia.github.io/react-fabric/?path=/story/draw-playground--playground}
134
+ * @see {@link https://tldraw.com/docs/}
135
+ */
115
136
  export const DrawCanvas: FC<DrawProps> = ({
116
137
  snapshot,
117
138
  renderer,
@@ -183,7 +204,7 @@ export const DrawCanvas: FC<DrawProps> = ({
183
204
  exportPages: async () => {
184
205
  const currentPage = editorRef?.getCurrentPageId();
185
206
  const pages = Object.keys(
186
- editorRef?.store.getSnapshot().store ?? {},
207
+ editorRef?.store.getStoreSnapshot().store ?? {},
187
208
  ).filter((key) => key.startsWith("page:"));
188
209
  const pageSnapshots: KeyValue[] = [];
189
210
  while (pages.length) {
@@ -198,7 +219,7 @@ export const DrawCanvas: FC<DrawProps> = ({
198
219
  editorRef?.setCurrentPage(pg);
199
220
  });
200
221
  const shapes: AnyObject = editorRef?.getCurrentPageShapeIds();
201
- const svg = await editorRef?.getSvg([...shapes], {
222
+ const svg = await editorRef?.getSvgElement([...shapes], {
202
223
  scale: 1,
203
224
  background: true,
204
225
  });
@@ -206,7 +227,7 @@ export const DrawCanvas: FC<DrawProps> = ({
206
227
  pageSnapshots.push({
207
228
  id: pg,
208
229
  name: editorRef?.getCurrentPage().name,
209
- content: { image: await getSvgAsDataUrl(svg) },
230
+ content: { image: await getSvgAsDataUrl(svg.svg) },
210
231
  });
211
232
  }
212
233
  currentPage && editorRef?.setCurrentPage(currentPage);
@@ -281,7 +302,7 @@ export const DrawCanvas: FC<DrawProps> = ({
281
302
  className="absolute inset-0"
282
303
  onDragOver={handleDragOver}
283
304
  onDrop={handleDrop}
284
- data-testid="draw-canvas"
305
+ data-ref="drawCanvas"
285
306
  >
286
307
  {TLDraw}
287
308
  </div>
@@ -207,7 +207,10 @@ export class AvatarShapeUtil extends ShapeUtil<AvatarShape> {
207
207
  spellCheck="true"
208
208
  wrap="off"
209
209
  dir="auto"
210
- ref={(el) => [el?.select(), el?.focus()]}
210
+ ref={(el) => {
211
+ el?.select();
212
+ el?.focus();
213
+ }}
211
214
  onKeyDown={(e) =>
212
215
  e.key === "Enter" &&
213
216
  (e.stopPropagation(),
@@ -56,8 +56,6 @@ export class Pointing extends StateNode {
56
56
 
57
57
  this.markId = `creating:${id}`;
58
58
 
59
- this.editor.mark(this.markId);
60
-
61
59
  this.editor
62
60
  .createShapes<AvatarShape>([
63
61
  {
@@ -80,6 +78,7 @@ export class Pointing extends StateNode {
80
78
  target: "selection",
81
79
  handle: "bottom_right",
82
80
  isCreating: true,
81
+ creatingMarkId: this.markId,
83
82
  creationCursorOffset: { x: 1, y: 1 },
84
83
  onInteractionEnd: "avatar",
85
84
  });
@@ -1,7 +0,0 @@
1
- 'use strict';
2
-
3
- function getDefaultExportFromCjs (x) {
4
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
5
- }
6
-
7
- exports.getDefaultExportFromCjs = getDefaultExportFromCjs;
@@ -1,5 +0,0 @@
1
- 'use strict';
2
-
3
- var domToImage = {exports: {}};
4
-
5
- exports.__module = domToImage;