drawui-core 0.4.0 → 0.4.2
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/README.md +54 -0
- package/dist/index.cjs +25 -22
- package/dist/index.d.cts +527 -9
- package/dist/index.d.ts +527 -9
- package/dist/index.js +25 -22
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -61,6 +61,33 @@ interface EditorOptions {
|
|
|
61
61
|
|
|
62
62
|
## 更新日志
|
|
63
63
|
|
|
64
|
+
### v0.4.2
|
|
65
|
+
|
|
66
|
+
- 🖱️ **右键菜单所需能力全部内置**:`Editor` 新增一整套编辑操作 API —— `getSelectedShapes()` / `deleteSelected()` / `copySelected()` / `copySelectedAsImage()` / `paste()` / `duplicateSelected()` / `hasClipboard()` / `copyStyle()` / `pasteStyle()` / `hasCopiedStyle()` / `flipSelected('horizontal' | 'vertical')` / `rotateSelected90()` / `setSelectedShapesLocked()` / `setShapeLocked()` / `isShapeLocked()` / `bringToFront()` / `sendToBack()` / `bringForward()` / `sendBackward()`,全部走 `commitHistory()`,可撤销。同时内置对应快捷键(`Ctrl+C` / `Ctrl+Shift+C` / `Ctrl+V` / `Ctrl+D` / `Ctrl+Alt+C` / `Ctrl+Alt+V` / `Ctrl+Alt+L` / `Shift+H` / `Shift+V`)。
|
|
67
|
+
- 🔒 **锁定**:`BaseShape.locked` —— 锁定的图形不参与命中 / 框选 / 拖动 / 缩放 / 删除 / 双击编辑;`Renderer` 在包围盒右上角绘制**白底圆角挂锁标记**(20×20 屏幕像素,缩放不变),SVG / PNG 导出不带标记。新增 `isFlippableShapeType()`。
|
|
68
|
+
- 👥 **分组 = 给多个图形绑一把锁**:`BaseShape.groupId` + `Editor.groupSelected()` / `ungroupSelected()` / `setGroupLocked()` / `getSelectedGroupId()`,`Ctrl+G` / `Ctrl+Shift+G`。
|
|
69
|
+
- 成组时整组立即锁定;解锁后点任一成员即选中整组,拖动 / 删除 / 层级 / 复制整组生效,`Renderer` 画虚线组框。
|
|
70
|
+
- 复制 / 粘贴 / 创建副本时副本**自成新组**(`cloneWithOffset` 会重映射 `groupId`)。
|
|
71
|
+
- ↔️ **水平 / 垂直翻转**:`Shape.flipX` / `flipY`,在旋转后的本地坐标系里做镜像(`ctx.scale`),文字反向缩放保持可读;画布与 SVG 导出同源。文字、线条、箭头、手绘、表格、UML、思维导图、便签不支持翻转。
|
|
72
|
+
- 🖐️ **按住拖拽生成图形**:绘制工具按下后拖动超过 5px,图形锚定按下角随手势实时改尺寸;轻点仍是默认尺寸;`Shift` 拖动锁定默认宽高比;圆取拖拽矩形长边做直径;拖拽中 `Esc` 取消。
|
|
73
|
+
- 🚫 core 侧右键(`pointerdown` `button === 2`)直接短路,不会误入拖拽 / 框选状态,便于宿主自行接管 `contextmenu`。
|
|
74
|
+
- 🐞 **修复**:`setShapeLocked` 补上画布重绘(原先锁定后要等下一次交互才更新)。
|
|
75
|
+
|
|
76
|
+
### v0.4.1
|
|
77
|
+
|
|
78
|
+
- 📊 **新增图形「表格」(`table`)**:工具栏独立按钮 + 8×6 选择器一键插入,双击单元格就地编辑。
|
|
79
|
+
- **飞书式交互**:表格内拖拽 = 框选单元格(拖到表格外自动扩成整行 / 整列),只有左上角六点把手能移动整张表;选区浅蓝高亮,点合并块内任意一格即选中整块。
|
|
80
|
+
- **合并 / 拆分**:选区永远吸附完整合并块(不会再出现「选左边却合并右边」),合并**保留全部单元格内容**(按行优先拼接),拆分一次拆掉选区内所有合并区。
|
|
81
|
+
- **插入 / 删除行列可指定位置**:`insertTableRowRelative` / `insertTableColumnRelative`(`above` / `below` / `left` / `right`)、`deleteTableRowsInSelection` / `deleteTableColsInSelection`;插入的行列继承邻居的样式(底色 / 加粗 / 字号 / 对齐 / 文字色)与列宽行高,删除按选区批量进行且只占一步撤销。
|
|
82
|
+
- **单元格文字自动换行 + 行高按内容增高**:画布与 SVG / PNG 导出共用同一套折行规则;增删行列表格左上角保持不动。
|
|
83
|
+
- 表格缩放自动等比拉伸列宽 / 行高,撤销重做完整支持(一个编辑会话 = 一个撤销点)。
|
|
84
|
+
- ✨ **体验优化**:
|
|
85
|
+
- 网格线对齐到物理像素,非 100% 缩放不再出现摩尔纹「发花」。
|
|
86
|
+
- 悬停弹出的「全文提示块」只在文字真的被截断时出现,显示得下就不再打扰。
|
|
87
|
+
- 撤销粒度修正:连续编辑多个单元格后撤销,只回退最后一个编辑会话,不会一路退到第一次编辑之前。
|
|
88
|
+
- 界面文字不再被拖蓝选中复制(状态栏 / 工具栏 / 小地图等),输入框不受影响。
|
|
89
|
+
- 🐞 **UML 修复**:行文字统一由 `uml.ts` 生成(画布 / SVG 导出 / 尺寸计算同源,`umlAttrRowText` / `umlMethodRowText` 已导出);整行可自由删除(连可见性符号 `+ - # ~` 一起删),删空即空白、不会自己长回预设文字;就地编辑不再「删到冒号就删不动」。
|
|
90
|
+
|
|
64
91
|
### v0.4.0
|
|
65
92
|
|
|
66
93
|
- 💾 **新增 `exportJSON()` / `importJSON()`**:把**完整文档**(全部图形 + 相机位置 + 版本号)序列化 / 反序列化,宿主可用它实现「导出数据 → 下次导入继续绘制」的跨会话存档;`exportJSON()` 返回带版本号的 JSON 数据,`importJSON()` 校验格式后整体恢复(含相机),非法数据返回失败结果、不破坏现有文档。
|
|
@@ -211,6 +238,33 @@ interface EditorOptions {
|
|
|
211
238
|
|
|
212
239
|
## Changelog
|
|
213
240
|
|
|
241
|
+
### v0.4.2
|
|
242
|
+
|
|
243
|
+
- 🖱️ **Everything a context menu needs, built into `Editor`**: `getSelectedShapes()` / `deleteSelected()` / `copySelected()` / `copySelectedAsImage()` / `paste()` / `duplicateSelected()` / `hasClipboard()` / `copyStyle()` / `pasteStyle()` / `hasCopiedStyle()` / `flipSelected('horizontal' | 'vertical')` / `rotateSelected90()` / `setSelectedShapesLocked()` / `setShapeLocked()` / `isShapeLocked()` / `bringToFront()` / `sendToBack()` / `bringForward()` / `sendBackward()` — all through `commitHistory()`, so every one of them is undoable. Matching shortcuts ship too (`Ctrl+C` / `Ctrl+Shift+C` / `Ctrl+V` / `Ctrl+D` / `Ctrl+Alt+C` / `Ctrl+Alt+V` / `Ctrl+Alt+L` / `Shift+H` / `Shift+V`).
|
|
244
|
+
- 🔒 **Locking**: `BaseShape.locked` — a locked shape is excluded from hit-testing, brushing, dragging, resizing, deleting and double-click editing. The renderer draws a **rounded white padlock badge** (20×20 screen pixels, zoom-independent) at the top-right of its bounds; SVG / PNG exports omit it. New `isFlippableShapeType()` helper.
|
|
245
|
+
- 👥 **Groups = one lock shared by several shapes**: `BaseShape.groupId` plus `Editor.groupSelected()` / `ungroupSelected()` / `setGroupLocked()` / `getSelectedGroupId()`, bound to `Ctrl+G` / `Ctrl+Shift+G`.
|
|
246
|
+
- Grouping locks the whole group immediately. Once unlocked, clicking any member selects the entire group, so dragging / deleting / reordering / copying applies to all of them, and the renderer draws a dashed frame around the group.
|
|
247
|
+
- Copied / pasted / duplicated shapes get a **fresh group id**, so copies never rejoin the original group (`cloneWithOffset` remaps `groupId`).
|
|
248
|
+
- ↔️ **Horizontal / vertical flip**: `Shape.flipX` / `flipY`, applied as `ctx.scale` in the rotated local space (so the flip direction follows rotation, like Feishu). Text is counter-scaled to stay readable, and SVG export mirrors the canvas. Text, lines, arrows, freehand, tables, UML, mind maps and sticky notes are not flippable.
|
|
249
|
+
- 🖐️ **Drag to size while drawing**: after pressing down, dragging more than 5px resizes the shape live, anchored at the press corner; a plain click still yields the default size. Hold `Shift` to lock the shape's default aspect ratio, circles take the longer drag edge as their diameter, and `Esc` mid-drag reverts to the default size.
|
|
250
|
+
- 🚫 Right-click (`pointerdown` with `button === 2`) short-circuits in core, so it never enters drag / brush state — hosts can safely take over `contextmenu`.
|
|
251
|
+
- 🐞 **Fixed**: `setShapeLocked` now repaints the canvas (previously the lock badge only appeared on the next interaction).
|
|
252
|
+
|
|
253
|
+
### v0.4.1
|
|
254
|
+
|
|
255
|
+
- 📊 **New `table` shape**: insert one from its own toolbar button with an 8×6 picker, then double-click any cell to edit in place.
|
|
256
|
+
- **Feishu-style interaction**: dragging inside the table selects a cell range (dragging past the edge extends it to full rows / columns); only the six-dot handle at the top-left moves the whole table. The selection is highlighted in light blue, and clicking any cell inside a merged block selects the entire block.
|
|
257
|
+
- **Merge / split**: the selection always snaps to whole merged blocks (no more "selected the left, merged the right"), merging **keeps every cell's text** (joined row-major) and splitting clears all merged blocks in the selection.
|
|
258
|
+
- **Insert / delete rows & columns at a chosen position**: `insertTableRowRelative` / `insertTableColumnRelative` (`above` / `below` / `left` / `right`) and `deleteTableRowsInSelection` / `deleteTableColsInSelection`. Inserted rows / columns inherit their neighbour's style (fill / bold / font size / align / text color) and width / height; deletion is a single undo step.
|
|
259
|
+
- **Cell text wraps and rows grow to fit** — canvas and SVG / PNG export share the same wrapping rules. Adding or removing rows / columns keeps the table's top-left corner anchored.
|
|
260
|
+
- Resizing scales column widths and row heights proportionally; undo / redo fully supported (one editing session = one undo step).
|
|
261
|
+
- ✨ **Experience polish**:
|
|
262
|
+
- Grid lines snap to physical pixels, so non-100% zoom levels no longer show moiré artifacts.
|
|
263
|
+
- The hover "full text" tooltip now appears **only when the text is actually truncated**.
|
|
264
|
+
- Undo granularity fixed: after editing several cells in a row, undo rolls back just the last editing session.
|
|
265
|
+
- UI text can no longer be accidentally selected / copied (status bar, toolbar, minimap); inputs are unaffected.
|
|
266
|
+
- 🐞 **UML fixes**: row text is now produced by `uml.ts` only (canvas, SVG export and size calculation share `umlAttrRowText` / `umlMethodRowText`, both exported). A whole row can be deleted freely — including the visibility marker `+ - # ~` — and an emptied row stays empty instead of growing the preset text back. In-place editing no longer gets stuck at the colon.
|
|
267
|
+
|
|
214
268
|
### v0.4.0
|
|
215
269
|
|
|
216
270
|
- 💾 **New `exportJSON()` / `importJSON()`**: serialize / restore the **full document** (all shapes + camera + version). Hosts can use them for cross-session persistence ("export data now, import and keep drawing later"). `exportJSON()` returns versioned JSON; `importJSON()` validates and restores everything (camera included) — invalid input fails cleanly without touching the current document.
|