在实例化引擎时传入
//实例化引擎const engine = new Engine(渲染节点, {...配置项,});
string
zh-CN
zh-CN
、en-US
。可使用 locale
配置const engine = new Engine(渲染节点, {lang: 'zh-CN',});
object
zh-CN
语言包,默认语言包 https://github.com/big-camel/am-editor/blob/master/locale
const engine = new Engine(渲染节点, {locale: {'zh-CN': {test: '测试',a: {b: 'B',},},},});console.log(engine.language.get<string>('test'));
string
null
number
null
Node
Array<Plugin>
[]
Plugin
抽象类的插件集合Array<Card>
[]
Card
抽象类的卡片集合{ [key: string]: PluginOptions }
或者 (editor) => { [key: string]: PluginOptions }
{}
一些插件需要额外属性的配置:
// 图片上传[ImageUploader.pluginName]: {file: {action: `${DOMAIN}/upload/image`,headers: { Authorization: 213434 },},remote: {action: `${DOMAIN}/upload/image`,},isRemote: (src: string) => src.indexOf(DOMAIN) < 0,},// 文件上传[FileUploader.pluginName]: {action: `${DOMAIN}/upload/file`,},// 视频上传[VideoUploader.pluginName]: {action: `${DOMAIN}/upload/video`,},// 数学公式生成地址,项目在:https://drawing.aomao.com[Math.pluginName]: {action: `https://g.aomao.com/latex`,parse: (res: any) => {if (res.success) return { result: true, data: res.svg };return { result: false };},},// 提交插件配置[Mention.pluginName]: {action: `${DOMAIN}/user/search`,onLoading: (root: NodeInterface) => {// Vue 可以使用 createApp 渲染return ReactDOM.render(<Loading />, root.get<HTMLElement>()!);},onEmpty: (root: NodeInterface) => {// Vue 可以使用 createApp 渲染return ReactDOM.render(<Empty />, root.get<HTMLElement>()!);},onClick: (root: NodeInterface,{ key, name }: { key: string; name: string },) => {console.log('mention click:', key, '-', name);},onMouseEnter: (layout: NodeInterface,{ name }: { key: string; name: string },) => {// Vue 可以使用 createApp 渲染ReactDOM.render(<div style={{ padding: 5 }}><p>This is name: {name}</p><p>配置 mention 插件的 onMouseEnter 方法</p><p>此处使用 ReactDOM.render 自定义渲染</p><p>Use ReactDOM.render to customize rendering here</p></div>,layout.get<HTMLElement>()!,);},},// 字体大小配置[Fontsize.pluginName]: {//配置粘贴后需要过滤的字体大小filter: (fontSize: string) => {return (['12px','13px','14px','15px','16px','19px','22px','24px','29px','32px','40px','48px',].indexOf(fontSize) > -1);},},// 字体配置[Fontfamily.pluginName]: {//配置粘贴后需要过滤的字体filter: (fontfamily: string) => {const item = fontFamilyDefaultData.find((item) =>fontfamily.split(',').some((name) =>item.value.toLowerCase().indexOf(name.replace(/"/, '').toLowerCase()) >-1,),);return item ? item.value : false;},},// 行高配置[LineHeight.pluginName]: {//配置粘贴后需要过滤的行高filter: (lineHeight: string) => {if (lineHeight === '14px') return '1';if (lineHeight === '16px') return '1.15';if (lineHeight === '21px') return '1.5';if (lineHeight === '28px') return '2';if (lineHeight === '35px') return '2.5';if (lineHeight === '42px') return '3';// 不满足条件就移除掉return (['1', '1.15', '1.5', '2', '2.5', '3'].indexOf(lineHeight) > -1);},},
string
无
boolean
false
与 View
渲染不同的是,readonly
设置只读状态后依然可以看到协同者的编辑。
View
渲染后失去一切编辑能力和协同能力,View
能够渲染出具有交互效果的 card
插件
engine.getHtml()
只能获取到静态的 html
,无法还原 card
组件的交互效果,但是它对搜索引擎很友好
Node | (() => Node | null)
overflow
或者 overflow-y
为 auto
或者 scroll
的节点,如果没有就取 document.documentElement
scroll
事件设置弹层浮动位置和主动设置滚动到编辑器目标位置或者使用 setScrollNode
设置
engine.setScrollNode(滚动条节点);
boolena
true
Record<'url' | 'format', string>[] | string | false
url('//at.alicdn.com/t/font_1456030_lnqmc6a6ca.woff2?t=1638071536645') format('woff2'), url('//at.alicdn.com/t/font_1456030_lnqmc6a6ca.woff?t=1638071536645') format('woff'), url('//at.alicdn.com/t/font_1456030_lnqmc6a6ca.ttf?t=1638071536645') format('truetype')
const engine = new Engine(渲染节点, {iconFonts: [{url: '//at.alicdn.com/t/font_1456030_lnqmc6a6ca.woff2?t=1638071536645',format: 'woff2',// ...},],// oriconFonts:"url('//at.alicdn.com/t/font_1456030_lnqmc6a6ca.woff2?t=1638071536645') format('woff2'), url('//at.alicdn.com/t/font_1456030_lnqmc6a6ca.woff?t=1638071536645') format('woff'), url('//at.alicdn.com/t/font_1456030_lnqmc6a6ca.ttf?t=1638071536645') format('truetype')",});
boolean
true
boolean
true
类型:
markdown?: {/*** markdown 模式,默认 执行 check 函数返回 true 就直接转换* 1. 使用 confirm 模式,调用 engine.messageConfirm 确认后再次转换* 2. false 为关闭全部 markdown 功能*/mode?: 'confirm' | false;/*** 检测是否为 markdown 语法,如果为 true 则将 makrdown 转换后粘贴,如果默认检测不满足需求可以使用此函数进行自定义检测*/check?: (text: string, html: string) => Promise<string | false>;};
undefined
confirm
模式,需要调用engine.messageConfirm
确认后再转换。