@baohu/canvas-editor-ui 0.0.0-stage → 1.1.0

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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 TaroXin
4
+ Portions (icons, dialog) adapted from canvas-editor, Copyright (c) 2021-present, hufe
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,103 @@
1
- # Temporary Holding Version
1
+ # @baohu/canvas-editor-ui
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [`@baohu/canvas-editor`](https://www.npmjs.com/package/@baohu/canvas-editor) 的工具栏、状态栏和弹窗,不依赖任何框架。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm i @baohu/canvas-editor @baohu/canvas-editor-ui
9
+ ```
10
+
11
+ ## 使用
12
+
13
+ 编辑器会撑满容器,容器需要有确定的高度。
14
+
15
+ ```js
16
+ import { createEditorUI } from '@baohu/canvas-editor-ui'
17
+
18
+ const ui = createEditorUI('#app', {
19
+ data: { main: [{ value: 'Hello' }] }, // 文档数据
20
+ options: { defaultSize: 16 } // canvas-editor 配置
21
+ })
22
+
23
+ ui.editor.command.getValue() // 编辑器实例
24
+ ui.destroy() // 销毁
25
+ ```
26
+
27
+ ### script 直接引入
28
+
29
+ ```html
30
+ <div id="app" style="height: 600px"></div>
31
+ <script src="https://unpkg.com/@baohu/canvas-editor/dist/canvas-editor.umd.cjs"></script>
32
+ <script src="https://unpkg.com/@baohu/canvas-editor-ui"></script>
33
+ <script>
34
+ var ui = CanvasEditorUI.createEditorUI('#app', { data: { main: [] } })
35
+ </script>
36
+ ```
37
+
38
+ 先引入编辑器核心(全局变量 `window['canvas-editor']`),再引入本包(全局变量 `CanvasEditorUI`)。编辑器核心的 UMD 文件后缀是 `.cjs`,jsDelivr 返回的 Content-Type 不是 JavaScript,浏览器会拒绝执行,请使用 unpkg 或自行部署。
39
+
40
+ ## 配置
41
+
42
+ | 参数 | 类型 | 说明 |
43
+ |---|---|---|
44
+ | `data` | `IEditorData \| IElement[]` | 文档数据 |
45
+ | `options` | `IEditorOption` | canvas-editor 配置 |
46
+ | `toolbar` | `IToolbarItem[] \| false` | 工具栏按钮,`false` 隐藏;默认 `DEFAULT_TOOLBAR` |
47
+ | `statusbar` | `IStatusbarItem[] \| false` | 状态栏项目,`false` 隐藏;默认 `DEFAULT_STATUSBAR` |
48
+ | `locale` | `Partial<ILocale>` | 覆盖界面文案 |
49
+
50
+ ### 工具栏
51
+
52
+ 数组元素可以是内置按钮的 key、分隔线 `'|'`,或自定义按钮对象。
53
+
54
+ 默认显示的按钮(`DEFAULT_TOOLBAR`):`undo` `redo` `painter` `format` `font` `size` `sizeAdd` `sizeMinus` `bold` `italic` `underline` `strikeout` `superscript` `subscript` `color` `highlight` `title` `left` `center` `right` `alignment` `justify` `rowMargin` `list` `table` `image` `hyperlink` `separator` `pageBreak` `checkbox` `date` `search`
55
+
56
+ 内置但默认不显示、需要时自行加入的按钮:`control`(插入控件)`print`(打印)`pdf`(导出 PDF)
57
+
58
+ ```js
59
+ createEditorUI('#app', {
60
+ toolbar: [...DEFAULT_TOOLBAR, '|', 'control', 'print', 'pdf']
61
+ })
62
+ ```
63
+
64
+ ```js
65
+ import { DEFAULT_TOOLBAR, createEditorUI } from '@baohu/canvas-editor-ui'
66
+
67
+ createEditorUI('#app', {
68
+ toolbar: [
69
+ 'undo', 'redo', '|', 'bold', 'italic', '|',
70
+ {
71
+ key: 'save',
72
+ text: '保存', // 或 icon: 图片地址
73
+ title: '保存文档',
74
+ keepEnabledInReadonly: true,
75
+ onClick: ({ editor }) => save(editor.command.getValue().data),
76
+ isActive: ({ style }) => false, // 可选:高亮状态
77
+ isDisabled: ({ style }) => false // 可选:禁用状态
78
+ }
79
+ ]
80
+ })
81
+ ```
82
+
83
+ ### 状态栏
84
+
85
+ 默认显示(`DEFAULT_STATUSBAR`):`pageNo`(页码)`wordCount`(字数)`rowCol`(行列)`pageMode`(分页/连页)`scale`(缩放)`paperDirection`(纸张方向)`paperMargin`(页边距)`fullscreen`(全屏)
86
+
87
+ 内置但默认不显示:`mode`(编辑模式切换)。不加入也可以用 `ui.setMode(mode)` 切换模式。
88
+
89
+ ```js
90
+ createEditorUI('#app', {
91
+ statusbar: [...DEFAULT_STATUSBAR, 'mode']
92
+ })
93
+ ```
94
+
95
+ ## 实例方法
96
+
97
+ | 方法 | 说明 |
98
+ |---|---|
99
+ | `ui.editor` | canvas-editor 实例 |
100
+ | `ui.setMode(mode)` | 切换编辑模式(直接调用 `editor.command.executeMode` 也会同步界面) |
101
+ | `ui.destroy()` | 销毁编辑器和界面 |
102
+
103
+ 另外导出了 `Dialog`,可以用来做和内置弹窗风格一致的自定义弹窗。