@react-fabric/draw 1.0.0-beta.3 → 1.0.0-beta.5
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.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
3
4
|
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
|
|
4
5
|
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
5
6
|
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
@@ -7,7 +8,6 @@ var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
|
|
|
7
8
|
var _regeneratorRuntime = require('@babel/runtime/regenerator');
|
|
8
9
|
var core = require('@react-fabric/core');
|
|
9
10
|
var utilities = require('@react-fabric/utilities');
|
|
10
|
-
var urls = require('@tldraw/assets/urls');
|
|
11
11
|
var tldraw = require('@tldraw/tldraw');
|
|
12
12
|
require('@tldraw/tldraw/tldraw.css');
|
|
13
13
|
var react = require('react');
|
|
@@ -21,6 +21,13 @@ var VideoShape = require('./shapes/custom/VideoShape.js');
|
|
|
21
21
|
var jsxRuntime = require('react/jsx-runtime');
|
|
22
22
|
|
|
23
23
|
var _excluded = ["type"];
|
|
24
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
25
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
26
|
+
var customAssetUrls = {
|
|
27
|
+
icons: {
|
|
28
|
+
avatar: "data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0IiB2aWV3Qm94PSIwIDAgMjQgMjQiPgo8cGF0aCBkPSJNMjIuOCAyMi44di0yLjRjMC0xLjY1Ni0wLjY3My0zLjE1OC0xLjc1Ny00LjI0M3MtMi41ODctMS43NTctNC4yNDMtMS43NTdoLTkuNmMtMS42NTYgMC0zLjE1OCAwLjY3My00LjI0MyAxLjc1N3MtMS43NTcgMi41ODctMS43NTcgNC4yNDN2Mi40YzAgMC42NjIgMC41MzggMS4yIDEuMiAxLjJzMS4yLTAuNTM4IDEuMi0xLjJ2LTIuNGMwLTAuOTk1IDAuNDAyLTEuODkyIDEuMDU1LTIuNTQ1czEuNTUtMS4wNTUgMi41NDUtMS4wNTVoOS42YzAuOTk1IDAgMS44OTIgMC40MDIgMi41NDUgMS4wNTVzMS4wNTUgMS41NSAxLjA1NSAyLjU0NXYyLjRjMCAwLjY2MiAwLjUzOCAxLjIgMS4yIDEuMnMxLjItMC41MzggMS4yLTEuMnpNMTggNmMwLTEuNjU2LTAuNjczLTMuMTU4LTEuNzU3LTQuMjQzcy0yLjU4Ny0xLjc1Ny00LjI0My0xLjc1Ny0zLjE1OCAwLjY3My00LjI0MyAxLjc1Ny0xLjc1NyAyLjU4Ny0xLjc1NyA0LjI0MyAwLjY3MyAzLjE1OCAxLjc1NyA0LjI0MyAyLjU4NyAxLjc1NyA0LjI0MyAxLjc1NyAzLjE1OC0wLjY3MyA0LjI0My0xLjc1NyAxLjc1Ny0yLjU4NyAxLjc1Ny00LjI0M3pNMTUuNiA2YzAgMC45OTUtMC40MDIgMS44OTItMS4wNTUgMi41NDVzLTEuNTUgMS4wNTUtMi41NDUgMS4wNTUtMS44OTItMC40MDItMi41NDUtMS4wNTUtMS4wNTUtMS41NS0xLjA1NS0yLjU0NSAwLjQwMi0xLjg5MiAxLjA1NS0yLjU0NSAxLjU1LTEuMDU1IDIuNTQ1LTEuMDU1IDEuODkyIDAuNDAyIDIuNTQ1IDEuMDU1IDEuMDU1IDEuNTUgMS4wNTUgMi41NDV6Ij48L3BhdGg+Cjwvc3ZnPgo="
|
|
29
|
+
}
|
|
30
|
+
};
|
|
24
31
|
function getSvgAsDataUrl(_x) {
|
|
25
32
|
return _getSvgAsDataUrl.apply(this, arguments);
|
|
26
33
|
}
|
|
@@ -121,11 +128,14 @@ var DrawCanvas = function DrawCanvas(_ref) {
|
|
|
121
128
|
});
|
|
122
129
|
}, [editorRef, isDark]);
|
|
123
130
|
react.useEffect(function () {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}, 500)
|
|
131
|
+
var handler = utilities.debounce(function () {
|
|
132
|
+
editorRef && (onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate(tldraw.getSnapshot(editorRef.store)));
|
|
133
|
+
}, 500);
|
|
134
|
+
editorRef === null || editorRef === void 0 || editorRef.sideEffects.registerAfterChangeHandler("shape", handler);
|
|
135
|
+
editorRef === null || editorRef === void 0 || editorRef.sideEffects.registerAfterCreateHandler("shape", handler);
|
|
136
|
+
editorRef === null || editorRef === void 0 || editorRef.sideEffects.registerAfterDeleteHandler("shape", handler);
|
|
127
137
|
return function () {
|
|
128
|
-
|
|
138
|
+
//
|
|
129
139
|
};
|
|
130
140
|
}, [editorRef]);
|
|
131
141
|
react.useLayoutEffect(function () {
|
|
@@ -257,12 +267,28 @@ var DrawCanvas = function DrawCanvas(_ref) {
|
|
|
257
267
|
}, [editorRef]);
|
|
258
268
|
var TLDraw = react.useMemo(function () {
|
|
259
269
|
return /*#__PURE__*/jsxRuntime.jsx(tldraw.Tldraw, {
|
|
260
|
-
assetUrls:
|
|
270
|
+
assetUrls: customAssetUrls,
|
|
261
271
|
shapeUtils: [AvatarShapeTool.AvatarShapeUtil, AudioShape.AudioShapeUtil, ImageShape.ImageShapeUtil, VideoShape.VideoShapeUtil, CardShape.CardShapeUtil, FileShape.FileShapeUtil],
|
|
262
272
|
tools: [AvatarShapeTool.AvatarShapeTool],
|
|
263
273
|
onMount: setEditor,
|
|
274
|
+
components: {
|
|
275
|
+
Toolbar: function Toolbar(props) {
|
|
276
|
+
var tools = tldraw.useTools();
|
|
277
|
+
var isAvatarSelected = tldraw.useIsToolSelected(tools.avatar);
|
|
278
|
+
return /*#__PURE__*/jsxRuntime.jsxs(tldraw.DefaultToolbar, _objectSpread(_objectSpread({}, props), {}, {
|
|
279
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(tldraw.DefaultToolbarContent, {}), /*#__PURE__*/jsxRuntime.jsx(tldraw.TldrawUiMenuItem, _objectSpread(_objectSpread({}, tools.avatar), {}, {
|
|
280
|
+
isSelected: isAvatarSelected
|
|
281
|
+
}))]
|
|
282
|
+
}));
|
|
283
|
+
}
|
|
284
|
+
},
|
|
264
285
|
overrides: {
|
|
265
|
-
|
|
286
|
+
translations: {
|
|
287
|
+
en: {
|
|
288
|
+
"tool.avatar": "Avatar"
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
tools: function tools(editor, schema) {
|
|
266
292
|
schema.avatar = {
|
|
267
293
|
id: "avatar",
|
|
268
294
|
label: "tool.avatar",
|
|
@@ -272,11 +298,11 @@ var DrawCanvas = function DrawCanvas(_ref) {
|
|
|
272
298
|
editor.setCurrentTool("avatar");
|
|
273
299
|
}
|
|
274
300
|
};
|
|
275
|
-
return schema;
|
|
301
|
+
return _objectSpread({}, schema);
|
|
276
302
|
},
|
|
277
|
-
actions: function actions(editor, schema
|
|
278
|
-
schema["insert-embed"]
|
|
279
|
-
schema["insert-media"]
|
|
303
|
+
actions: function actions(editor, schema) {
|
|
304
|
+
delete schema["insert-embed"];
|
|
305
|
+
delete schema["insert-media"];
|
|
280
306
|
return schema;
|
|
281
307
|
}
|
|
282
308
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
4
|
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
4
5
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
5
6
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
@@ -7,8 +8,7 @@ import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
|
7
8
|
import _regeneratorRuntime from '@babel/runtime/regenerator';
|
|
8
9
|
import { useIsDark, Section } from '@react-fabric/core';
|
|
9
10
|
import { debounce } from '@react-fabric/utilities';
|
|
10
|
-
import {
|
|
11
|
-
import { getSnapshot, loadSnapshot, Tldraw } from '@tldraw/tldraw';
|
|
11
|
+
import { getSnapshot, loadSnapshot, Tldraw, useTools, useIsToolSelected, DefaultToolbar, DefaultToolbarContent, TldrawUiMenuItem } from '@tldraw/tldraw';
|
|
12
12
|
import '@tldraw/tldraw/tldraw.css';
|
|
13
13
|
import { useState, useEffect, useLayoutEffect, useCallback, useImperativeHandle, useMemo } from 'react';
|
|
14
14
|
import { DrawContextProvider } from './DrawContext.js';
|
|
@@ -18,9 +18,16 @@ import { CardShapeUtil } from './shapes/custom/CardShape.js';
|
|
|
18
18
|
import { FileShapeUtil } from './shapes/custom/FileShape.js';
|
|
19
19
|
import { ImageShapeUtil } from './shapes/custom/ImageShape.js';
|
|
20
20
|
import { VideoShapeUtil } from './shapes/custom/VideoShape.js';
|
|
21
|
-
import { jsx } from 'react/jsx-runtime';
|
|
21
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
22
22
|
|
|
23
23
|
var _excluded = ["type"];
|
|
24
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
25
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
26
|
+
var customAssetUrls = {
|
|
27
|
+
icons: {
|
|
28
|
+
avatar: "data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0IiB2aWV3Qm94PSIwIDAgMjQgMjQiPgo8cGF0aCBkPSJNMjIuOCAyMi44di0yLjRjMC0xLjY1Ni0wLjY3My0zLjE1OC0xLjc1Ny00LjI0M3MtMi41ODctMS43NTctNC4yNDMtMS43NTdoLTkuNmMtMS42NTYgMC0zLjE1OCAwLjY3My00LjI0MyAxLjc1N3MtMS43NTcgMi41ODctMS43NTcgNC4yNDN2Mi40YzAgMC42NjIgMC41MzggMS4yIDEuMiAxLjJzMS4yLTAuNTM4IDEuMi0xLjJ2LTIuNGMwLTAuOTk1IDAuNDAyLTEuODkyIDEuMDU1LTIuNTQ1czEuNTUtMS4wNTUgMi41NDUtMS4wNTVoOS42YzAuOTk1IDAgMS44OTIgMC40MDIgMi41NDUgMS4wNTVzMS4wNTUgMS41NSAxLjA1NSAyLjU0NXYyLjRjMCAwLjY2MiAwLjUzOCAxLjIgMS4yIDEuMnMxLjItMC41MzggMS4yLTEuMnpNMTggNmMwLTEuNjU2LTAuNjczLTMuMTU4LTEuNzU3LTQuMjQzcy0yLjU4Ny0xLjc1Ny00LjI0My0xLjc1Ny0zLjE1OCAwLjY3My00LjI0MyAxLjc1Ny0xLjc1NyAyLjU4Ny0xLjc1NyA0LjI0MyAwLjY3MyAzLjE1OCAxLjc1NyA0LjI0MyAyLjU4NyAxLjc1NyA0LjI0MyAxLjc1NyAzLjE1OC0wLjY3MyA0LjI0My0xLjc1NyAxLjc1Ny0yLjU4NyAxLjc1Ny00LjI0M3pNMTUuNiA2YzAgMC45OTUtMC40MDIgMS44OTItMS4wNTUgMi41NDVzLTEuNTUgMS4wNTUtMi41NDUgMS4wNTUtMS44OTItMC40MDItMi41NDUtMS4wNTUtMS4wNTUtMS41NS0xLjA1NS0yLjU0NSAwLjQwMi0xLjg5MiAxLjA1NS0yLjU0NSAxLjU1LTEuMDU1IDIuNTQ1LTEuMDU1IDEuODkyIDAuNDAyIDIuNTQ1IDEuMDU1IDEuMDU1IDEuNTUgMS4wNTUgMi41NDV6Ij48L3BhdGg+Cjwvc3ZnPgo="
|
|
29
|
+
}
|
|
30
|
+
};
|
|
24
31
|
function getSvgAsDataUrl(_x) {
|
|
25
32
|
return _getSvgAsDataUrl.apply(this, arguments);
|
|
26
33
|
}
|
|
@@ -121,11 +128,14 @@ var DrawCanvas = function DrawCanvas(_ref) {
|
|
|
121
128
|
});
|
|
122
129
|
}, [editorRef, isDark]);
|
|
123
130
|
useEffect(function () {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}, 500)
|
|
131
|
+
var handler = debounce(function () {
|
|
132
|
+
editorRef && (onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate(getSnapshot(editorRef.store)));
|
|
133
|
+
}, 500);
|
|
134
|
+
editorRef === null || editorRef === void 0 || editorRef.sideEffects.registerAfterChangeHandler("shape", handler);
|
|
135
|
+
editorRef === null || editorRef === void 0 || editorRef.sideEffects.registerAfterCreateHandler("shape", handler);
|
|
136
|
+
editorRef === null || editorRef === void 0 || editorRef.sideEffects.registerAfterDeleteHandler("shape", handler);
|
|
127
137
|
return function () {
|
|
128
|
-
|
|
138
|
+
//
|
|
129
139
|
};
|
|
130
140
|
}, [editorRef]);
|
|
131
141
|
useLayoutEffect(function () {
|
|
@@ -257,12 +267,28 @@ var DrawCanvas = function DrawCanvas(_ref) {
|
|
|
257
267
|
}, [editorRef]);
|
|
258
268
|
var TLDraw = useMemo(function () {
|
|
259
269
|
return /*#__PURE__*/jsx(Tldraw, {
|
|
260
|
-
assetUrls:
|
|
270
|
+
assetUrls: customAssetUrls,
|
|
261
271
|
shapeUtils: [AvatarShapeUtil, AudioShapeUtil, ImageShapeUtil, VideoShapeUtil, CardShapeUtil, FileShapeUtil],
|
|
262
272
|
tools: [AvatarShapeTool],
|
|
263
273
|
onMount: setEditor,
|
|
274
|
+
components: {
|
|
275
|
+
Toolbar: function Toolbar(props) {
|
|
276
|
+
var tools = useTools();
|
|
277
|
+
var isAvatarSelected = useIsToolSelected(tools.avatar);
|
|
278
|
+
return /*#__PURE__*/jsxs(DefaultToolbar, _objectSpread(_objectSpread({}, props), {}, {
|
|
279
|
+
children: [/*#__PURE__*/jsx(DefaultToolbarContent, {}), /*#__PURE__*/jsx(TldrawUiMenuItem, _objectSpread(_objectSpread({}, tools.avatar), {}, {
|
|
280
|
+
isSelected: isAvatarSelected
|
|
281
|
+
}))]
|
|
282
|
+
}));
|
|
283
|
+
}
|
|
284
|
+
},
|
|
264
285
|
overrides: {
|
|
265
|
-
|
|
286
|
+
translations: {
|
|
287
|
+
en: {
|
|
288
|
+
"tool.avatar": "Avatar"
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
tools: function tools(editor, schema) {
|
|
266
292
|
schema.avatar = {
|
|
267
293
|
id: "avatar",
|
|
268
294
|
label: "tool.avatar",
|
|
@@ -272,11 +298,11 @@ var DrawCanvas = function DrawCanvas(_ref) {
|
|
|
272
298
|
editor.setCurrentTool("avatar");
|
|
273
299
|
}
|
|
274
300
|
};
|
|
275
|
-
return schema;
|
|
301
|
+
return _objectSpread({}, schema);
|
|
276
302
|
},
|
|
277
|
-
actions: function actions(editor, schema
|
|
278
|
-
schema["insert-embed"]
|
|
279
|
-
schema["insert-media"]
|
|
303
|
+
actions: function actions(editor, schema) {
|
|
304
|
+
delete schema["insert-embed"];
|
|
305
|
+
delete schema["insert-media"];
|
|
280
306
|
return schema;
|
|
281
307
|
}
|
|
282
308
|
}
|
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.5",
|
|
4
4
|
"description": "RUF: TLDraw canvas",
|
|
5
5
|
"author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,8 +33,8 @@
|
|
|
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.
|
|
36
|
+
"@react-fabric/core": "^1.0.0-beta.5",
|
|
37
|
+
"@react-fabric/utilities": "^1.0.0-beta.5",
|
|
38
38
|
"@tldraw/assets": "^3.3.1",
|
|
39
39
|
"@tldraw/editor": "^3.3.1",
|
|
40
40
|
"@tldraw/tldraw": "^3.3.1",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"node": ">=18.12.0",
|
|
51
51
|
"npm": ">=8.19.0"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "7d4a7ed1ea9890652826bef58d01c31280d761c8"
|
|
54
54
|
}
|
|
@@ -23,13 +23,18 @@
|
|
|
23
23
|
|
|
24
24
|
import { Section, useIsDark } from "@react-fabric/core";
|
|
25
25
|
import { debounce } from "@react-fabric/utilities";
|
|
26
|
-
import { getAssetUrlsByMetaUrl } from "@tldraw/assets/urls";
|
|
27
26
|
import {
|
|
27
|
+
DefaultToolbar,
|
|
28
|
+
DefaultToolbarContent,
|
|
28
29
|
getSnapshot,
|
|
29
30
|
loadSnapshot,
|
|
30
31
|
Tldraw,
|
|
32
|
+
TldrawUiMenuItem,
|
|
33
|
+
useIsToolSelected,
|
|
34
|
+
useTools,
|
|
31
35
|
type Editor,
|
|
32
36
|
type TLEditorSnapshot,
|
|
37
|
+
type TLUiAssetUrlOverrides,
|
|
33
38
|
} from "@tldraw/tldraw";
|
|
34
39
|
import "@tldraw/tldraw/tldraw.css";
|
|
35
40
|
import {
|
|
@@ -54,6 +59,13 @@ import { FileShapeUtil } from "./shapes/custom/FileShape";
|
|
|
54
59
|
import { ImageShapeUtil } from "./shapes/custom/ImageShape";
|
|
55
60
|
import { VideoShapeUtil } from "./shapes/custom/VideoShape";
|
|
56
61
|
|
|
62
|
+
const customAssetUrls: TLUiAssetUrlOverrides = {
|
|
63
|
+
icons: {
|
|
64
|
+
avatar:
|
|
65
|
+
"data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0IiB2aWV3Qm94PSIwIDAgMjQgMjQiPgo8cGF0aCBkPSJNMjIuOCAyMi44di0yLjRjMC0xLjY1Ni0wLjY3My0zLjE1OC0xLjc1Ny00LjI0M3MtMi41ODctMS43NTctNC4yNDMtMS43NTdoLTkuNmMtMS42NTYgMC0zLjE1OCAwLjY3My00LjI0MyAxLjc1N3MtMS43NTcgMi41ODctMS43NTcgNC4yNDN2Mi40YzAgMC42NjIgMC41MzggMS4yIDEuMiAxLjJzMS4yLTAuNTM4IDEuMi0xLjJ2LTIuNGMwLTAuOTk1IDAuNDAyLTEuODkyIDEuMDU1LTIuNTQ1czEuNTUtMS4wNTUgMi41NDUtMS4wNTVoOS42YzAuOTk1IDAgMS44OTIgMC40MDIgMi41NDUgMS4wNTVzMS4wNTUgMS41NSAxLjA1NSAyLjU0NXYyLjRjMCAwLjY2MiAwLjUzOCAxLjIgMS4yIDEuMnMxLjItMC41MzggMS4yLTEuMnpNMTggNmMwLTEuNjU2LTAuNjczLTMuMTU4LTEuNzU3LTQuMjQzcy0yLjU4Ny0xLjc1Ny00LjI0My0xLjc1Ny0zLjE1OCAwLjY3My00LjI0MyAxLjc1Ny0xLjc1NyAyLjU4Ny0xLjc1NyA0LjI0MyAwLjY3MyAzLjE1OCAxLjc1NyA0LjI0MyAyLjU4NyAxLjc1NyA0LjI0MyAxLjc1NyAzLjE1OC0wLjY3MyA0LjI0My0xLjc1NyAxLjc1Ny0yLjU4NyAxLjc1Ny00LjI0M3pNMTUuNiA2YzAgMC45OTUtMC40MDIgMS44OTItMS4wNTUgMi41NDVzLTEuNTUgMS4wNTUtMi41NDUgMS4wNTUtMS44OTItMC40MDItMi41NDUtMS4wNTUtMS4wNTUtMS41NS0xLjA1NS0yLjU0NSAwLjQwMi0xLjg5MiAxLjA1NS0yLjU0NSAxLjU1LTEuMDU1IDIuNTQ1LTEuMDU1IDEuODkyIDAuNDAyIDIuNTQ1IDEuMDU1IDEuMDU1IDEuNTUgMS4wNTUgMi41NDV6Ij48L3BhdGg+Cjwvc3ZnPgo=",
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
|
|
57
69
|
export async function getSvgAsDataUrl(svg: SVGElement) {
|
|
58
70
|
const clone = svg.cloneNode(true) as SVGGraphicsElement;
|
|
59
71
|
clone.setAttribute("encoding", 'UTF-8"');
|
|
@@ -116,13 +128,15 @@ export const DrawCanvas: FC<DrawProps> = ({
|
|
|
116
128
|
}, [editorRef, isDark]);
|
|
117
129
|
|
|
118
130
|
useEffect(() => {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
);
|
|
131
|
+
const handler = debounce(() => {
|
|
132
|
+
editorRef && onUpdate?.(getSnapshot(editorRef.store));
|
|
133
|
+
}, 500);
|
|
134
|
+
editorRef?.sideEffects.registerAfterChangeHandler("shape", handler);
|
|
135
|
+
editorRef?.sideEffects.registerAfterCreateHandler("shape", handler);
|
|
136
|
+
editorRef?.sideEffects.registerAfterDeleteHandler("shape", handler);
|
|
123
137
|
|
|
124
138
|
return () => {
|
|
125
|
-
|
|
139
|
+
//
|
|
126
140
|
};
|
|
127
141
|
}, [editorRef]);
|
|
128
142
|
|
|
@@ -205,7 +219,7 @@ export const DrawCanvas: FC<DrawProps> = ({
|
|
|
205
219
|
const TLDraw = useMemo(
|
|
206
220
|
() => (
|
|
207
221
|
<Tldraw
|
|
208
|
-
assetUrls={
|
|
222
|
+
assetUrls={customAssetUrls}
|
|
209
223
|
shapeUtils={[
|
|
210
224
|
AvatarShapeUtil,
|
|
211
225
|
AudioShapeUtil,
|
|
@@ -216,8 +230,28 @@ export const DrawCanvas: FC<DrawProps> = ({
|
|
|
216
230
|
]}
|
|
217
231
|
tools={[AvatarShapeTool]}
|
|
218
232
|
onMount={setEditor}
|
|
233
|
+
components={{
|
|
234
|
+
Toolbar: (props) => {
|
|
235
|
+
const tools = useTools();
|
|
236
|
+
const isAvatarSelected = useIsToolSelected(tools.avatar);
|
|
237
|
+
return (
|
|
238
|
+
<DefaultToolbar {...props}>
|
|
239
|
+
<DefaultToolbarContent />
|
|
240
|
+
<TldrawUiMenuItem
|
|
241
|
+
{...tools.avatar}
|
|
242
|
+
isSelected={isAvatarSelected}
|
|
243
|
+
/>
|
|
244
|
+
</DefaultToolbar>
|
|
245
|
+
);
|
|
246
|
+
},
|
|
247
|
+
}}
|
|
219
248
|
overrides={{
|
|
220
|
-
|
|
249
|
+
translations: {
|
|
250
|
+
en: {
|
|
251
|
+
"tool.avatar": "Avatar",
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
tools(editor, schema) {
|
|
221
255
|
schema.avatar = {
|
|
222
256
|
id: "avatar",
|
|
223
257
|
label: "tool.avatar" as AnyObject,
|
|
@@ -227,11 +261,11 @@ export const DrawCanvas: FC<DrawProps> = ({
|
|
|
227
261
|
editor.setCurrentTool("avatar");
|
|
228
262
|
},
|
|
229
263
|
};
|
|
230
|
-
return schema;
|
|
264
|
+
return { ...schema };
|
|
231
265
|
},
|
|
232
|
-
actions(editor, schema
|
|
233
|
-
schema["insert-embed"]
|
|
234
|
-
schema["insert-media"]
|
|
266
|
+
actions(editor, schema) {
|
|
267
|
+
delete schema["insert-embed"];
|
|
268
|
+
delete schema["insert-media"];
|
|
235
269
|
return schema;
|
|
236
270
|
},
|
|
237
271
|
}}
|