From 78dc6397bdd176ba67ea729e08e0643c28401612 Mon Sep 17 00:00:00 2001 From: Nightt <87569709+nightt5879@users.noreply.github.com> Date: Thu, 27 Aug 2026 11:02:07 +0800 Subject: [PATCH] feat(freehand): extract standalone plugin package --- README.md | 1 + README_en.md | 1 + packages/drawnix/package.json | 1 + .../components/toolbar/creation-toolbar.tsx | 2 +- .../toolbar/freehand-panel/freehand-panel.tsx | 13 ++-- .../freehand-style-preset-item.spec.tsx | 5 +- .../freehand-style-preset-item.tsx | 4 +- .../toolbar/popup-toolbar/popup-toolbar.tsx | 2 +- packages/drawnix/src/constants/freehand.ts | 25 ++++++- packages/drawnix/src/drawnix.tsx | 4 +- .../drawnix/src/hooks/use-drawnix.spec.ts | 2 +- packages/drawnix/src/hooks/use-drawnix.tsx | 4 +- packages/drawnix/src/plugins/with-freehand.ts | 27 +++++++ packages/drawnix/src/plugins/with-hotkey.ts | 2 +- .../src/plugins/with-tool-state-sync.spec.ts | 2 +- packages/drawnix/vite.config.ts | 1 + packages/freehand/README.md | 26 +++++++ packages/freehand/package.json | 24 ++++++ packages/freehand/project.json | 8 ++ .../src}/freehand.component.spec.ts | 0 .../src}/freehand.component.ts | 0 .../src}/freehand.generator.ts | 0 packages/freehand/src/index.ts | 9 +++ packages/freehand/src/plugin-options.spec.ts | 23 ++++++ packages/freehand/src/plugin-options.ts | 64 ++++++++++++++++ .../src}/pointer-button.spec.ts | 75 ++++++++++++++++--- .../freehand => freehand/src}/presets.ts | 20 +---- .../freehand => freehand/src}/smoother.ts | 0 .../plugins/freehand => freehand/src}/type.ts | 0 .../freehand => freehand/src}/utils.spec.ts | 0 .../freehand => freehand/src}/utils.ts | 28 ++----- .../src}/with-freehand-create.ts | 7 +- .../src}/with-freehand-erase.ts | 14 ++-- .../src}/with-freehand-fragment.ts | 0 packages/freehand/src/with-freehand.spec.ts | 28 +++++++ .../src}/with-freehand.ts | 11 ++- packages/freehand/tsconfig.json | 21 ++++++ packages/freehand/tsconfig.lib.json | 18 +++++ packages/freehand/tsconfig.spec.json | 20 +++++ packages/freehand/vite.config.ts | 43 +++++++++++ scripts/publish.js | 2 +- tsconfig.base.json | 1 + 42 files changed, 452 insertions(+), 86 deletions(-) create mode 100644 packages/drawnix/src/plugins/with-freehand.ts create mode 100644 packages/freehand/README.md create mode 100644 packages/freehand/package.json create mode 100644 packages/freehand/project.json rename packages/{drawnix/src/plugins/freehand => freehand/src}/freehand.component.spec.ts (100%) rename packages/{drawnix/src/plugins/freehand => freehand/src}/freehand.component.ts (100%) rename packages/{drawnix/src/plugins/freehand => freehand/src}/freehand.generator.ts (100%) create mode 100644 packages/freehand/src/index.ts create mode 100644 packages/freehand/src/plugin-options.spec.ts create mode 100644 packages/freehand/src/plugin-options.ts rename packages/{drawnix/src/plugins/freehand => freehand/src}/pointer-button.spec.ts (61%) rename packages/{drawnix/src/plugins/freehand => freehand/src}/presets.ts (62%) rename packages/{drawnix/src/plugins/freehand => freehand/src}/smoother.ts (100%) rename packages/{drawnix/src/plugins/freehand => freehand/src}/type.ts (100%) rename packages/{drawnix/src/plugins/freehand => freehand/src}/utils.spec.ts (100%) rename packages/{drawnix/src/plugins/freehand => freehand/src}/utils.ts (86%) rename packages/{drawnix/src/plugins/freehand => freehand/src}/with-freehand-create.ts (93%) rename packages/{drawnix/src/plugins/freehand => freehand/src}/with-freehand-erase.ts (88%) rename packages/{drawnix/src/plugins/freehand => freehand/src}/with-freehand-fragment.ts (100%) create mode 100644 packages/freehand/src/with-freehand.spec.ts rename packages/{drawnix/src/plugins/freehand => freehand/src}/with-freehand.ts (83%) create mode 100644 packages/freehand/tsconfig.json create mode 100644 packages/freehand/tsconfig.lib.json create mode 100644 packages/freehand/tsconfig.spec.json create mode 100644 packages/freehand/vite.config.ts diff --git a/README.md b/README.md index 8325e901..3f194d3d 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,7 @@ drawnix/ ├── dist/ # 构建产物 ├── packages/ │ └── drawnix/ # 白板应用 +│ └── freehand/ # 自由画笔插件 │ └── react-board/ # 白板 React 视图层 │ └── react-text/ # 文本渲染模块 ├── package.json diff --git a/README_en.md b/README_en.md index bc719635..18f47f61 100644 --- a/README_en.md +++ b/README_en.md @@ -86,6 +86,7 @@ drawnix/ ├── dist/ # Build artifacts ├── packages/ │ └── drawnix/ # Whiteboard application core +│ └── freehand/ # Reusable freehand plugin │ └── react-board/ # Whiteboard react view layer │ └── react-text/ # Text rendering module ├── package.json diff --git a/packages/drawnix/package.json b/packages/drawnix/package.json index eb4cebcc..86a6cf2c 100644 --- a/packages/drawnix/package.json +++ b/packages/drawnix/package.json @@ -14,6 +14,7 @@ }, "dependencies": { "@floating-ui/react": "^0.26.24", + "@plait-board/freehand": "^0.4.0", "@plait-board/markdown-to-drawnix": "^0.0.8", "@plait-board/mermaid-to-drawnix": "^0.0.7", "laser-pen": "^1.0.1", diff --git a/packages/drawnix/src/components/toolbar/creation-toolbar.tsx b/packages/drawnix/src/components/toolbar/creation-toolbar.tsx index 19925868..f8b218a7 100644 --- a/packages/drawnix/src/components/toolbar/creation-toolbar.tsx +++ b/packages/drawnix/src/components/toolbar/creation-toolbar.tsx @@ -28,7 +28,7 @@ import { ShapePicker, SHAPES } from '../shape-picker'; import { ArrowPicker, ARROWS } from '../arrow-picker'; import { useEffect, useState } from 'react'; import { Popover, PopoverContent, PopoverTrigger } from '../popover/popover'; -import { FreehandShape } from '../../plugins/freehand/type'; +import { FreehandShape } from '@plait-board/freehand'; import { DrawnixFreehandPointer, DrawnixPointerType, diff --git a/packages/drawnix/src/components/toolbar/freehand-panel/freehand-panel.tsx b/packages/drawnix/src/components/toolbar/freehand-panel/freehand-panel.tsx index 508c682f..db604654 100644 --- a/packages/drawnix/src/components/toolbar/freehand-panel/freehand-panel.tsx +++ b/packages/drawnix/src/components/toolbar/freehand-panel/freehand-panel.tsx @@ -8,14 +8,15 @@ import { BoardCreationMode, setCreationMode } from '@plait/common'; import { useBoard } from '@plait-board/react-board'; import { DrawnixPointerType } from '../../../hooks/use-drawnix'; import { useI18n } from '../../../i18n'; -import { FreehandShape } from '../../../plugins/freehand/type'; -import { FREEHANDS, FREEHAND_PRESET_IDS, type FreehandPresetId } from '../../../constants/freehand'; -import { FreehandStylePresetItem, type FreehandStylePreset } from './freehand-style-preset-item'; -import './freehand-style-preset-item.scss'; +import { FreehandShape, type FreehandDrawOptions } from '@plait-board/freehand'; import { DEFAULT_FREEHAND_PRESETS, - type FreehandDrawOptions, -} from '../../../plugins/freehand/presets'; + FREEHANDS, + FREEHAND_PRESET_IDS, + type FreehandPresetId, +} from '../../../constants/freehand'; +import { FreehandStylePresetItem, type FreehandStylePreset } from './freehand-style-preset-item'; +import './freehand-style-preset-item.scss'; const FreehandStyleDivider = () =>