From 75f2f5cc67a9eb072fbb29e520b6a11ab8982b91 Mon Sep 17 00:00:00 2001 From: wuchenguang1998 <63847336+wuchenguang1998@users.noreply.github.com> Date: Tue, 4 Jun 2024 23:34:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20pathText=E5=92=8CfreeDraw=E5=85=83?= =?UTF-8?q?=E7=B4=A0=E7=BB=98=E5=88=B6=E6=97=B6=E8=AE=BE=E7=BD=AE=E5=94=AF?= =?UTF-8?q?=E4=B8=80id=20(#416)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/plugin/FreeDrawPlugin.ts | 15 +++++++++++++++ packages/core/plugin/PathTextPlugin.ts | 2 ++ 2 files changed, 17 insertions(+) diff --git a/packages/core/plugin/FreeDrawPlugin.ts b/packages/core/plugin/FreeDrawPlugin.ts index 594266e1..6e70b3c4 100644 --- a/packages/core/plugin/FreeDrawPlugin.ts +++ b/packages/core/plugin/FreeDrawPlugin.ts @@ -1,5 +1,6 @@ import { fabric } from 'fabric'; import Editor from '../Editor'; +import { v4 as uuid } from 'uuid'; type IEditor = Editor; @@ -12,14 +13,28 @@ export default class FreeDrawPlugin { static apis = ['startDraw', 'endDraw']; constructor(public canvas: fabric.Canvas, public editor: IEditor) {} + _bindEvent() { + this.canvas.on('path:created', this._createdHandler); + } + + _unbindEvent() { + this.canvas.off('path:created', this._createdHandler); + } + + _createdHandler = (opt: any) => { + opt.path.set('id', uuid()); + }; + startDraw(options: DrawOptions) { this.canvas.isDrawingMode = true; this.canvas.freeDrawingBrush = new fabric.PencilBrush(this.canvas); this.canvas.freeDrawingBrush.width = options.width; + this._bindEvent(); } endDraw() { if (this.canvas.isDrawingMode) { this.canvas.isDrawingMode = false; + this._unbindEvent(); return; } } diff --git a/packages/core/plugin/PathTextPlugin.ts b/packages/core/plugin/PathTextPlugin.ts index 491e3471..20a76aa7 100644 --- a/packages/core/plugin/PathTextPlugin.ts +++ b/packages/core/plugin/PathTextPlugin.ts @@ -1,5 +1,6 @@ import { fabric } from 'fabric'; import Editor from '../Editor'; +import { v4 as uuid } from 'uuid'; type IEditor = Editor; type DrawOptions = { @@ -31,6 +32,7 @@ export default class PathTextPlugin { left: path.left, fill: this.options.color, path: path, + id: uuid(), }); this.canvas.add(textObject); };