new LinwitDocEditor({
element: "#aiEditor",
toolbarKeys: ["undo", "redo", "brush", "eraser",
"|", "heading", "font-family", "font-size",
"|", "bold", "italic", "underline", "strike", "link", "code", "subscript", "superscript", "hr", "todo", "emoji",
"|", "highlight", "font-color",
"|", "align", "line-height",
"|", "bullet-list", "ordered-list", "indent-decrease", "indent-increase", "break",
"|", "image", "video", "attachment", "quote", "code-block", "table",
"|", "source-code", "printer", "fullscreen", "ai"
],
})
以上的配置为 LinwitDocEditor 工具类的默认配置,"|" 代表的是分割线,其他的含义如下:
另外,商业版还支持以下的配置:
通过配置 toolbarSize 用于设置工具栏按钮尺寸:
new LinwitDocEditor({
element: "#aiEditor",
toolbarSize: 'medium', // 默认 small,可选 'small' | 'medium' | 'large'
})
通过配置 toolbarExcludeKeys 用于排除部分工具的初始化,示例代码如下:
new LinwitDocEditor({
element: "#aiEditor",
toolbarExcludeKeys: ["heading", "font-family", "font-size", "ai"],
})
在 LinwitDocEditor 中,我们可以通过在 toolbarKeys 配置中进行自定义工具栏的扩展,配置示例代码如下:
new LinwitDocEditor({
element: "#aiEditor",
toolbarKeys: ["undo", "redo", "brush", "eraser",
"|", "heading", "font-family", "font-size",
"|",
{
icon: "<svg .....>",
html: "<div ...>",
onClick: (event, editor) => {
//点击事件
},
tip: "鼠标移动上去的提示内容",
},
"printer", "fullscreen", "ai"
],
})
自定义工具类配置项说明:
icon 和 html 只能配置其中一个。tip国际化配置示例代码
new LinwitDocEditor({
element: "#aiEditor",
toolbarKeys: ["undo", "redo", "brush", "eraser",
"|", "heading", "font-family", "font-size",
"|",
{
icon: "<svg .....>",
html: "<div ...>",
onClick: (event, editor) => {
//点击事件
},
tip: "myKey",
},
"printer", "fullscreen", "ai"
],
i18n: {
zh: {
"myKey": "自定义国际化显示中文内容",
},
en: {
"myKey": "Custom your i18n content",
}
}
})
工具栏分组指的是可以把一部分工具,归类到一个分组里,通过点击分组的按钮,弹出菜单内容。如下图所示:
配置代码如下:
new LinwitDocEditor({
element: "#aiEditor",
toolbarKeys: ["undo", "redo", "brush", "eraser",
"|", "heading", "font-family", "font-size",
"|", "bold", "italic", "underline", "strike", "link", "code", "subscript", "superscript", "hr", "todo", "emoji",
"|", "highlight", "font-color",
"|", "align", "line-height",
"|", "bullet-list", "ordered-list", "indent-decrease", "indent-increase", "break",
"|", "image", "video", "attachment", "quote", "code-block", "table",
"|", "source-code", "printer", "fullscreen", "ai",
{
// title:"menu group",
// icon:`<svg.... />`,
toolbarKeys: ["undo", "redo", "brush"]
}
],
})
如上所示,通过在 toolbarKeys 配置一个 MenuGroup 对象,即可对菜单进行分组。
MenuGroup 支持的配置如下:
高级用法:在工具栏分组中自定义菜单
在菜单分组中,添加自定义的菜单按钮,示例代码如下:
new LinwitDocEditor({
element: "#aiEditor",
toolbarKeys: ["undo", "redo", "brush", "eraser",
"|", "heading", "font-family", "font-size",
"|", "bold", "italic", "underline", "strike", "link", "code", "subscript", "superscript", "hr", "todo", "emoji",
"|", "highlight", "font-color",
"|", "align", "line-height",
"|", "bullet-list", "ordered-list", "indent-decrease", "indent-increase", "break",
"|", "image", "video", "attachment", "quote", "code-block", "table",
"|", "source-code", "printer", "fullscreen", "ai",
{
// title:"menu group",
// icon:`<svg.... />`,
toolbarKeys: ["undo", "redo", "brush",
{
icon: "<svg .....>",
html: "<div ...>",
onClick: (event, editor) => {
//点击事件
},
tip: "myKey",
},
]
}
],
})
其具体含义参考:#自定义工具栏