import React from 'react'; import { isEngine, Range, EngineInterface } from '@aomao/engine'; import type { EditorInterface } from '@aomao/engine'; import type { ButtonProps, DropdownProps, ColorProps, CollapseProps, } from '../../types'; import TableSelector from '../../table'; import fontfamily, { defaultData as fontFamilyDefaultData } from './fontfamily'; import './index.css'; export { fontfamily, fontFamilyDefaultData }; export const getToolbarDefaultConfig = ( engine: EditorInterface, ): Array => { const language = engine.language.get('toolbar'); const headingLanguage = language['heading']; const fontSizeInContainer = engine.container.css('font-size'); return [ { type: 'collapse', header: language['collapse']['title'], icon: 'collapse', groups: [ { items: [ { name: 'image-uploader', icon: ( ), title: language['image']['title'], search: '图片,tupian,image,img', }, { name: 'codeblock', icon: ( ), title: language['codeblock']['title'], search: '代码块,daimakuai,code', }, { name: 'table', command: { name: 'table', args: [3, 3] }, placement: 'rightTop', onDisabled: () => { // 有激活卡片 或者没有启用插件 return ( !!engine.card.active || !engine.command.queryEnabled('table') ); }, prompt: !!engine.card.active || !engine.command.queryEnabled('table') ? undefined : (props) => { return ( { if (props.onClick) props.onClick( event, 'table', engine as EngineInterface, ); engine.command.execute( 'table', rows, cols, ); }} /> ); }, icon: ( ), title: language['table']['title'], search: 'biaoge,table', }, { name: 'file-uploader', icon: ( ), title: language['file']['title'], search: '附件,文件,fujian,wenjian,file', }, { name: 'video-uploader', icon: ( ), title: language['video']['title'], search: '视频,MP4,shipin,video', }, { name: 'math', icon: ( ), title: language['math']['title'], search: '公式,数学公式,gongshi,formula,math,latex', }, { name: 'tag', icon: ( ), title: language['tag']['title'], search: 'tag,label,标签', }, { name: 'status', icon: ( ), title: language['status']['title'], search: 'status,label,状态', }, { name: 'lightblock', icon: ( ), title: language['lightblock']['title'], search: 'light,lightblock,高亮块', onDisabled: () => { // 有激活卡片 或者没有启用插件 return ( !!engine.card.active || !engine.command.queryEnabled('lightblock') ); }, }, { name: 'mulit_codeblock', icon: ( ), title: language['mulitCodeblock']['title'], search: '代码块,mulit,codeblock,mulit_codeblock', onDisabled: () => { // 有激活卡片 或者没有启用插件 return ( !!engine.card.active || !engine.command.queryEnabled( 'mulit_codeblock', ) ); }, }, /**{ name: 'mind', icon: ( ), title: language['mind']['title'], search: '脑图,思维导图,mind,naotu,shiweidaotu', },**/ ], }, ], }, { type: 'button', name: 'undo', icon: 'undo', title: language['undo']['title'], onDisabled: () => { return ( !engine.command.queryState('undo') || !engine.command.queryEnabled('undo') ); }, onActive: () => false, }, { type: 'button', name: 'redo', icon: 'redo', title: language['redo']['title'], onDisabled: () => { return ( !engine.command.queryState('redo') || !engine.command.queryEnabled('redo') ); }, onActive: () => false, }, { type: 'button', name: 'paintformat', icon: 'paintformat', title: language['paintformat']['title'], }, { type: 'button', name: 'removeformat', icon: 'clean', title: language['removeformat']['title'], }, { type: 'dropdown', name: 'heading', className: 'toolbar-dropdown-heading', title: headingLanguage['title'], items: [ { key: 'p', className: 'heading-item-p', content: headingLanguage['p'], }, { key: 'h1', className: 'heading-item-h1', content: headingLanguage['h1'], }, { key: 'h2', className: 'heading-item-h2', content: headingLanguage['h2'], }, { key: 'h3', className: 'heading-item-h3', content: headingLanguage['h3'], }, { key: 'h4', className: 'heading-item-h4', content: headingLanguage['h4'], }, { key: 'h5', className: 'heading-item-h5', content: headingLanguage['h5'], }, { key: 'h6', className: 'heading-item-h6', content: headingLanguage['h6'], }, ], }, { type: 'dropdown', name: 'fontsize', className: 'toolbar-dropdown-fontsize', title: language['fontsize']['title'], items: [ { key: '12px', content: '12px', hotkey: false }, { key: '13px', content: '13px', hotkey: false }, { key: '14px', content: '14px', hotkey: false }, { key: '15px', content: '15px', hotkey: false }, { key: '16px', content: '16px', hotkey: false }, { key: '19px', content: '19px', hotkey: false }, { key: '22px', content: '22px', hotkey: false }, { key: '24px', content: '24px', hotkey: false }, { key: '29px', content: '29px', hotkey: false }, { key: '32px', content: '32px', hotkey: false }, { key: '40px', content: '40px', hotkey: false }, { key: '48px', content: '48px', hotkey: false }, ].map((item) => item.key === fontSizeInContainer ? { ...item, isDefault: true } : item, ), onDisabled: () => { const tag = engine.command.queryState('heading') || 'p'; return ( /^h\d$/.test(tag) || !engine.command.queryEnabled('fontsize') ); }, }, { type: 'dropdown', name: 'fontfamily', className: 'toolbar-dropdown-fontfamily', title: language['fontfamily']['title'], items: fontfamily(fontFamilyDefaultData, { ...language['fontfamily']['items'], notInstalled: language['fontfamily']['notInstalled'], }), onActive: (items) => { const values = engine.command.queryState('fontfamily'); if (!values || !Array.isArray(values) || values.length === 0) return ''; const familys: Array = values[0] .split(',') .map((name: string) => name.replace(/"/g, '').trim().toLowerCase(), ); return ( items.find( (item) => familys.indexOf( item['faimlyName'].trim().toLowerCase(), ) > -1, )?.key || '' ); }, }, { type: 'button', name: 'bold', icon: 'bold', title: language['bold']['title'], onDisabled: () => { const tag = engine.command.queryState('heading') || 'p'; return ( /^h\d$/.test(tag) || !engine.command.queryEnabled('bold') ); }, }, { type: 'button', name: 'italic', icon: 'italic', title: language['italic']['title'], }, { type: 'button', name: 'strikethrough', icon: 'strikethrough', title: language['strikethrough']['title'], }, { type: 'button', name: 'underline', icon: 'underline', title: language['underline']['title'], }, { type: 'dropdown', name: 'moremark', icon: 'moremark', single: false, title: language['moremark']['title'], items: [ { key: 'sup', icon: 'sup', content: language['moremark']['sup'], disabled: !engine.command.queryEnabled('sup'), command: { name: 'sup', args: [] }, }, { key: 'sub', icon: 'sub', disabled: !engine.command.queryEnabled('sub'), content: language['moremark']['sub'], command: { name: 'sub', args: [] }, }, { key: 'code', icon: 'code', disabled: !engine.command.queryEnabled('code'), content: language['moremark']['code'], command: { name: 'code', args: [] }, }, ], onDisabled: () => { const plugins = []; if (engine.command.queryEnabled('sup') === true) plugins.push('sup'); if (engine.command.queryEnabled('sub') === true) plugins.push('sub'); if (engine.command.queryEnabled('code') === true) plugins.push('code'); return plugins.length === 0; }, onActive: () => { const plugins = []; if (engine.command.queryState('sup') === true) plugins.push('sup'); if (engine.command.queryState('sub') === true) plugins.push('sub'); if (engine.command.queryState('code') === true) plugins.push('code'); return plugins; }, }, { type: 'color', name: 'fontcolor', defaultColor: '#262626', defaultActiveColor: '#F5222D', buttonTitle: language['fontcolor']['title'], dropdownTitle: language['fontcolor']['more'], content: (color: string, stroke: string, disabled?: boolean) => { if (disabled === true) { color = '#BFBFBF'; stroke = '#BFBFBF'; } return ( color-font Created with Sketch. ); }, }, { type: 'color', name: 'backcolor', defaultColor: 'transparent', defaultActiveColor: '#FADB14', buttonTitle: language['backcolor']['title'], dropdownTitle: language['backcolor']['more'], content: (color: string, stroke: string, disabled?: boolean) => { if (disabled === true) { color = '#BFBFBF'; stroke = '#BFBFBF'; } return ( ); }, }, { type: 'dropdown', name: 'alignment', title: language['alignment']['title'], items: [ { key: 'left', icon: 'align-left', content: language['alignment']['left'], }, { key: 'center', icon: 'align-center', content: language['alignment']['center'], }, { key: 'right', icon: 'align-right', content: language['alignment']['right'], }, { key: 'justify', icon: 'align-justify', content: language['alignment']['justify'], }, ], }, { type: 'button', name: 'unorderedlist', icon: 'unordered-list', title: language['unorderedlist']['title'], }, { type: 'button', name: 'orderedlist', icon: 'ordered-list', title: language['orderedlist']['title'], }, { type: 'button', name: 'tasklist', icon: 'task-list', title: language['tasklist']['title'], }, { type: 'dropdown', name: 'indent', icon: 'indent', hasDot: false, title: language['indent']['title'], items: [ { key: 'in', icon: 'indent', content: language['indent']['in'], }, { key: 'out', icon: 'outdent', content: language['indent']['out'], }, ], }, { type: 'dropdown', name: 'line-height', renderContent: () => ( ), title: language['line-height']['title'], items: [ { key: 'default', content: language['line-height']['default'], }, { key: '1', content: '1', }, { key: '1.15', content: '1.15', }, { key: '1.5', content: '1.5', }, { key: '2', content: '2', }, { key: '2.5', content: '2.5', }, { key: '3', content: '3', }, ], }, { type: 'button', name: 'link', icon: 'link', command: { name: 'link', args: ['_blank'] }, title: language['link']['title'], onDisabled: () => { const { card } = engine; const range = isEngine(engine) ? engine.change.range.get() : Range.from(engine); if (!range) return !engine.command.queryEnabled('link'); const cardComponent = card.find(range.startNode); return ( (!!cardComponent && !cardComponent.isCursor(range.startNode)) || range.containsCard() || !engine.command.queryEnabled('link') ); }, }, { type: 'button', name: 'quote', icon: 'quote', title: language['quote']['title'], }, { type: 'button', name: 'hr', icon: 'hr', title: language['hr']['title'], }, ]; };