@uiw/react-markdown-editor
Version:
A markdown editor with preview, implemented with React.js and TypeScript.
61 lines • 2.13 kB
JavaScript
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, { Fragment, createElement as _createElement } from 'react';
import { defaultCommands } from "../../commands/index.js";
import "./index.css";
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);
}
}
editorProps.prefixCls = prefixCls;
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') {
var CustomButton = obj.button(obj, editorProps, {
preview,
container,
containerEditor,
editor,
editorProps
});
return /*#__PURE__*/_jsx(Fragment, {
children: CustomButton
}, key);
}
return /*#__PURE__*/_createElement("button", _extends({}, buttonProps, {
key: key
}));
})
}));
}