@react-fabric/draw 1.0.0-beta.5 → 1.0.0-beta.52
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/cjs/{packages/draw/src/canvas → canvas}/DrawCanvas.js +23 -0
- package/dist/cjs/{packages/draw/src/canvas → canvas}/shapes/avatar/AvatarShapeTool.js +4 -3
- package/dist/cjs/{packages/draw/src/canvas → canvas}/shapes/custom/AudioShape.js +2 -2
- package/dist/cjs/{packages/draw/src/canvas → canvas}/shapes/custom/CardShape.js +2 -2
- package/dist/cjs/{packages/draw/src/canvas → canvas}/shapes/custom/FileShape.js +2 -2
- package/dist/cjs/{packages/draw/src/canvas → canvas}/shapes/custom/ImageShape.js +2 -2
- package/dist/cjs/{packages/draw/src/canvas → canvas}/shapes/custom/VideoShape.js +2 -2
- package/dist/esm/{packages/draw/src/canvas → canvas}/DrawCanvas.js +23 -0
- package/dist/esm/{packages/draw/src/canvas → canvas}/shapes/avatar/AvatarShapeTool.js +3 -2
- package/dist/esm/{packages/draw/src/canvas → canvas}/shapes/custom/AudioShape.js +1 -1
- package/dist/esm/{packages/draw/src/canvas → canvas}/shapes/custom/CardShape.js +1 -1
- package/dist/esm/{packages/draw/src/canvas → canvas}/shapes/custom/FileShape.js +1 -1
- package/dist/esm/{packages/draw/src/canvas → canvas}/shapes/custom/ImageShape.js +1 -1
- package/dist/esm/{packages/draw/src/canvas → canvas}/shapes/custom/VideoShape.js +1 -1
- package/dist/types/canvas/DrawCanvas.d.ts +23 -2
- package/package.json +16 -12
- package/src/canvas/DrawCanvas.tsx +24 -2
- package/src/canvas/shapes/avatar/AvatarShapeTool.tsx +4 -1
- package/dist/cjs/_virtual/_commonjsHelpers.js +0 -7
- package/dist/cjs/_virtual/dom-to-image.js +0 -5
- package/dist/cjs/node_modules/dom-to-image/src/dom-to-image.js +0 -777
- package/dist/esm/_virtual/_commonjsHelpers.js +0 -7
- package/dist/esm/_virtual/dom-to-image.js +0 -5
- package/dist/esm/node_modules/dom-to-image/src/dom-to-image.js +0 -777
- /package/dist/cjs/{packages/draw/src/canvas → canvas}/DrawContext.js +0 -0
- /package/dist/cjs/{packages/draw/src/canvas → canvas}/shapes/avatar/IdleState.js +0 -0
- /package/dist/cjs/{packages/draw/src/canvas → canvas}/shapes/avatar/PointingState.js +0 -0
- /package/dist/cjs/{packages/draw/src/canvas → canvas}/shapes/avatar/type.js +0 -0
- /package/dist/cjs/{packages/draw/src/index.js → index.js} +0 -0
- /package/dist/esm/{packages/draw/src/canvas → canvas}/DrawContext.js +0 -0
- /package/dist/esm/{packages/draw/src/canvas → canvas}/shapes/avatar/IdleState.js +0 -0
- /package/dist/esm/{packages/draw/src/canvas → canvas}/shapes/avatar/PointingState.js +0 -0
- /package/dist/esm/{packages/draw/src/canvas → canvas}/shapes/avatar/type.js +0 -0
- /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,
|
|
@@ -315,6 +337,7 @@ var DrawCanvas = function DrawCanvas(_ref) {
|
|
|
315
337
|
className: "absolute inset-0",
|
|
316
338
|
onDragOver: handleDragOver,
|
|
317
339
|
onDrop: handleDrop,
|
|
340
|
+
"data-ref": "drawCanvas",
|
|
318
341
|
children: TLDraw
|
|
319
342
|
})
|
|
320
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
|
|
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
|
-
|
|
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
|
|
247
|
+
return domtoimage.toPng(el).then(function (dataUrl) {
|
|
247
248
|
return /*#__PURE__*/jsxRuntime.jsx("img", {
|
|
248
249
|
src: dataUrl,
|
|
249
250
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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,
|
|
@@ -315,6 +337,7 @@ var DrawCanvas = function DrawCanvas(_ref) {
|
|
|
315
337
|
className: "absolute inset-0",
|
|
316
338
|
onDragOver: handleDragOver,
|
|
317
339
|
onDrop: handleDrop,
|
|
340
|
+
"data-ref": "drawCanvas",
|
|
318
341
|
children: TLDraw
|
|
319
342
|
})
|
|
320
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 '
|
|
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
|
-
|
|
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));
|
|
@@ -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 '
|
|
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 '
|
|
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 '
|
|
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 '
|
|
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 '
|
|
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
|
|
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?:
|
|
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.
|
|
3
|
+
"version": "1.0.0-beta.52",
|
|
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.
|
|
37
|
-
"@react-fabric/utilities": "^1.0.0-beta.
|
|
38
|
-
"@tldraw/assets": "^3.
|
|
39
|
-
"@tldraw/editor": "^3.
|
|
40
|
-
"@tldraw/tldraw": "^3.
|
|
41
|
-
"classnames": "^2.5.1"
|
|
36
|
+
"@react-fabric/core": "^1.0.0-beta.52",
|
|
37
|
+
"@react-fabric/utilities": "^1.0.0-beta.52",
|
|
38
|
+
"@tldraw/assets": "^3.13.1",
|
|
39
|
+
"@tldraw/editor": "^3.13.1",
|
|
40
|
+
"@tldraw/tldraw": "^3.13.1",
|
|
41
|
+
"classnames": "^2.5.1",
|
|
42
|
+
"dom-to-image": "^2.6.0"
|
|
42
43
|
},
|
|
43
44
|
"peerDependencies": {
|
|
44
|
-
"i18next": "^
|
|
45
|
-
"react": "
|
|
46
|
-
"react-dom": "
|
|
47
|
-
"react-i18next": "^15.
|
|
45
|
+
"i18next": "^25.2.1",
|
|
46
|
+
"react": "^19.0.0",
|
|
47
|
+
"react-dom": "^19.0.0",
|
|
48
|
+
"react-i18next": "^15.5.2"
|
|
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": "
|
|
57
|
+
"gitHead": "0eabb9d88d91af93d657bcc209b226fd576e8260"
|
|
54
58
|
}
|
|
@@ -46,7 +46,7 @@ import {
|
|
|
46
46
|
useState,
|
|
47
47
|
type DragEvent,
|
|
48
48
|
type FC,
|
|
49
|
-
type
|
|
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?:
|
|
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,
|
|
@@ -281,6 +302,7 @@ export const DrawCanvas: FC<DrawProps> = ({
|
|
|
281
302
|
className="absolute inset-0"
|
|
282
303
|
onDragOver={handleDragOver}
|
|
283
304
|
onDrop={handleDrop}
|
|
305
|
+
data-ref="drawCanvas"
|
|
284
306
|
>
|
|
285
307
|
{TLDraw}
|
|
286
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) =>
|
|
210
|
+
ref={(el) => {
|
|
211
|
+
el?.select();
|
|
212
|
+
el?.focus();
|
|
213
|
+
}}
|
|
211
214
|
onKeyDown={(e) =>
|
|
212
215
|
e.key === "Enter" &&
|
|
213
216
|
(e.stopPropagation(),
|