UNPKG

@uiw/react-markdown-editor

Version:

A markdown editor with preview, implemented with React.js and TypeScript.

67 lines (61 loc) 2.07 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose"; var _excluded = ["prefixCls", "className", "onClick", "toolbars", "editor", "mode", "preview", "container", "containerEditor", "editorProps"]; import React from 'react'; import { defaultCommands } from '../../commands'; import "./index.css"; import { createElement as _createElement } from "react"; import { jsx as _jsx } from "react/jsx-runtime"; export default function ToolBar(props) { var { prefixCls = 'md-editor', className, toolbars = [], editor, mode, preview, container, containerEditor, editorProps = {} } = props, htmlProps = _objectWithoutPropertiesLoose(props, _excluded); if (!toolbars || toolbars.length === 0) return null; function handleClick(execute) { if (execute && editor && editor) { execute(editor.current); } } return /*#__PURE__*/_jsx("div", _extends({ className: prefixCls + "-toolbar " + (className || '') + " " + (mode ? prefixCls + "-toolbar-mode" : '') }, htmlProps, { children: [...toolbars].map((command, key) => { var buttonProps = { type: 'button' }; var obj = typeof command === 'string' ? defaultCommands[command] : command; if (!obj) return null; buttonProps.children = obj.icon; buttonProps.onClick = () => handleClick(obj.execute); if (obj.button && typeof obj.button === 'object') { var btn = obj.button; Object.keys(btn).forEach(key => { buttonProps[key] = btn[key]; }); } else if (typeof obj.button === 'function') { return /*#__PURE__*/React.cloneElement(obj.button(obj, editorProps, { preview, container, containerEditor, editor, editorProps }), { key }); } return /*#__PURE__*/_createElement("button", _extends({}, buttonProps, { key: key })); }) })); } //# sourceMappingURL=index.js.map