UNPKG

@uiw/react-markdown-editor

Version:

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

94 lines (93 loc) 2.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.codeBlock = exports.code = void 0; var _state = require("@codemirror/state"); var _jsxRuntime = require("react/jsx-runtime"); var code = { name: 'code', keyCommand: 'code', button: { 'aria-label': 'Insert code' }, icon: /*#__PURE__*/(0, _jsxRuntime.jsxs)("svg", { viewBox: "0 0 48 48", fill: "none", height: "15", width: "15", children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("path", { d: "M16 13 4 25.432 16 37m16-24 12 12.432L32 37", stroke: "currentColor", strokeWidth: "5", strokeLinecap: "round", strokeLinejoin: "round" }), /*#__PURE__*/(0, _jsxRuntime.jsx)("path", { d: "m28 4-7 40", stroke: "currentColor", strokeWidth: "5", strokeLinecap: "round" })] }), execute: function execute(_ref) { var state = _ref.state, view = _ref.view; if (!state || !view) return; view.dispatch(view.state.changeByRange(function (range) { return { changes: [{ from: range.from, insert: '`' }, { from: range.to, insert: '`' }], range: _state.EditorSelection.range(range.from + 1, range.to + 1) }; })); } }; exports.code = code; var codeBlock = { name: 'codeBlock', keyCommand: 'codeBlock', button: { 'aria-label': 'Insert Code Block' }, icon: /*#__PURE__*/(0, _jsxRuntime.jsxs)("svg", { viewBox: "0 0 48 48", fill: "none", height: "15", width: "15", children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("path", { d: "M21 6H9a3 3 0 0 0-3 3v22a3 3 0 0 0 3 3h30a3 3 0 0 0 3-3V21M24 34v8", stroke: "currentColor", strokeWidth: "5", strokeLinecap: "round", strokeLinejoin: "round" }), /*#__PURE__*/(0, _jsxRuntime.jsx)("path", { d: "m32 6-4 4 4 4m6-8 4 4-4 4M14 42h20", stroke: "currentColor", strokeWidth: "5", strokeLinecap: "round", strokeLinejoin: "round" })] }), execute: function execute(_ref2) { var state = _ref2.state, view = _ref2.view; if (!state || !view) return; var main = view.state.selection.main; var txt = view.state.sliceDoc(view.state.selection.main.from, view.state.selection.main.to); view.dispatch({ changes: { from: main.from, to: main.to, insert: "```js\n".concat(txt, "\n```") }, selection: _state.EditorSelection.range(main.from + 3, main.from + 5) }); } }; exports.codeBlock = codeBlock; //# sourceMappingURL=code.js.map