import * as React from 'react'; import { entity } from '../../common'; import { Layer } from './layer'; import { EditorState, EditorStateConfigEntity, PlaygroundConfigEntity, ToolbarConfigEntity, } from './config'; import { domUtils } from '@gedit/utils/lib/browser'; import clx from 'clsx'; import { isOSX } from '@gedit/utils'; /** * 工具条绘制 */ export class ToolbarLayer extends Layer { readonly node = domUtils.createDivWithClass('gedit-toolbar-layer'); @entity(PlaygroundConfigEntity) protected playgroundConfigEntity: PlaygroundConfigEntity; @entity(ToolbarConfigEntity) protected toolbarConfig: ToolbarConfigEntity; @entity(EditorStateConfigEntity) protected editorStateConfig: EditorStateConfigEntity; get currentState(): EditorState | undefined { return this.editorStateConfig.getCurrentState(); } onReady(): void { this.pipelineNode.parentNode?.appendChild(this.node); } draw(): React.JSX.Element { const toolbar = this.toolbarConfig.config; // const percentageInfoVisible = toolbar.percentageInfoVisible; const states = this.editorStateConfig .getStateGroups() .map(c => c.filter( s => !(typeof s.hidden === 'function' ? s.hidden(this.config) : s.hidden) ) ) .filter(c => c.length); const selectedState = this.editorStateConfig.getCurrentState(); const style: React.CSSProperties = { display: toolbar.visible ? 'block' : 'none', }; const onSelect = (state: EditorState, e: React.MouseEvent) => { if ( typeof state.disabled === 'function' ? state.disabled(this.config) : state.disabled ) return; this.editorStateConfig.changeState(state.id, e); e.stopPropagation(); e.preventDefault(); }; return ( <> {/* percentageInfoVisible ?