UNPKG

react-markdown-editor-cm5

Version:
1,503 lines (1,500 loc) 157 kB
import de, { useRef as re, useState as B, useEffect as se, useImperativeHandle as nt, useContext as F, useReducer as bn, useLayoutEffect as Cn } from "react"; import oe from "jquery"; import { Resizable as En } from "re-resizable"; import le, { Pos as X } from "codemirror"; import Xe from "highlight.js"; import On from "clipboard"; import Sn from "rc-trigger"; import Pe from "classnames"; import kn from "markdown-it-sub"; import jn from "markdown-it-sup"; import Mn from "markdown-it-ins"; import Tn from "markdown-it-mark"; import An from "markdown-it-alerts"; import Rn from "markdown-it-anchor"; import It from "uslug"; import Nn from "markdown-it-task-lists"; import Ln from "markdown-it-emoji"; import Pn from "markdown-it-footnote"; import Hn from "markdown-it-abbr"; import zn from "markdown-it-deflist"; import Vn from "markdown-it-mathjax3"; import xt from "mermaid"; import $n from "markdown-it"; import wt from "dayjs"; import { debounce as _t, isString as Dn } from "lodash"; var In = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, n = {}, Bn = { get exports() { return n; }, set exports(e) { n = e; } }, ke = {}; /** * @license React * react-jsx-runtime.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var yt; function Wn() { if (yt) return ke; yt = 1; var e = de, t = Symbol.for("react.element"), a = Symbol.for("react.fragment"), i = Object.prototype.hasOwnProperty, o = e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, c = { key: !0, ref: !0, __self: !0, __source: !0 }; function s(l, v, S) { var _, x = {}, m = null, w = null; S !== void 0 && (m = "" + S), v.key !== void 0 && (m = "" + v.key), v.ref !== void 0 && (w = v.ref); for (_ in v) i.call(v, _) && !c.hasOwnProperty(_) && (x[_] = v[_]); if (l && l.defaultProps) for (_ in v = l.defaultProps, v) x[_] === void 0 && (x[_] = v[_]); return { $$typeof: t, type: l, key: m, ref: w, props: x, _owner: o.current }; } return ke.Fragment = a, ke.jsx = s, ke.jsxs = s, ke; } var je = {}; /** * @license React * react-jsx-runtime.development.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var bt; function Fn() { return bt || (bt = 1, process.env.NODE_ENV !== "production" && function() { var e = de, t = Symbol.for("react.element"), a = Symbol.for("react.portal"), i = Symbol.for("react.fragment"), o = Symbol.for("react.strict_mode"), c = Symbol.for("react.profiler"), s = Symbol.for("react.provider"), l = Symbol.for("react.context"), v = Symbol.for("react.forward_ref"), S = Symbol.for("react.suspense"), _ = Symbol.for("react.suspense_list"), x = Symbol.for("react.memo"), m = Symbol.for("react.lazy"), w = Symbol.for("react.offscreen"), f = Symbol.iterator, u = "@@iterator"; function h(r) { if (r === null || typeof r != "object") return null; var d = f && r[f] || r[u]; return typeof d == "function" ? d : null; } var k = e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; function y(r) { { for (var d = arguments.length, b = new Array(d > 1 ? d - 1 : 0), P = 1; P < d; P++) b[P - 1] = arguments[P]; M("error", r, b); } } function M(r, d, b) { { var P = k.ReactDebugCurrentFrame, I = P.getStackAddendum(); I !== "" && (d += "%s", b = b.concat([I])); var q = b.map(function($) { return String($); }); q.unshift("Warning: " + d), Function.prototype.apply.call(console[r], console, q); } } var g = !1, j = !1, p = !1, C = !1, E = !1, N; N = Symbol.for("react.module.reference"); function z(r) { return !!(typeof r == "string" || typeof r == "function" || r === i || r === c || E || r === o || r === S || r === _ || C || r === w || g || j || p || typeof r == "object" && r !== null && (r.$$typeof === m || r.$$typeof === x || r.$$typeof === s || r.$$typeof === l || r.$$typeof === v || // This needs to include all possible module reference object // types supported by any Flight configuration anywhere since // we don't know which Flight build this will end up being used // with. r.$$typeof === N || r.getModuleId !== void 0)); } function L(r, d, b) { var P = r.displayName; if (P) return P; var I = d.displayName || d.name || ""; return I !== "" ? b + "(" + I + ")" : b; } function T(r) { return r.displayName || "Context"; } function A(r) { if (r == null) return null; if (typeof r.tag == "number" && y("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof r == "function") return r.displayName || r.name || null; if (typeof r == "string") return r; switch (r) { case i: return "Fragment"; case a: return "Portal"; case c: return "Profiler"; case o: return "StrictMode"; case S: return "Suspense"; case _: return "SuspenseList"; } if (typeof r == "object") switch (r.$$typeof) { case l: var d = r; return T(d) + ".Consumer"; case s: var b = r; return T(b._context) + ".Provider"; case v: return L(r, r.render, "ForwardRef"); case x: var P = r.displayName || null; return P !== null ? P : A(r.type) || "Memo"; case m: { var I = r, q = I._payload, $ = I._init; try { return A($(q)); } catch { return null; } } } return null; } var R = Object.assign, K = 0, D, ne, O, H, J, Y, G; function U() { } U.__reactDisabledLog = !0; function pe() { { if (K === 0) { D = console.log, ne = console.info, O = console.warn, H = console.error, J = console.group, Y = console.groupCollapsed, G = console.groupEnd; var r = { configurable: !0, enumerable: !0, value: U, writable: !0 }; Object.defineProperties(console, { info: r, log: r, warn: r, error: r, group: r, groupCollapsed: r, groupEnd: r }); } K++; } } function ee() { { if (K--, K === 0) { var r = { configurable: !0, enumerable: !0, writable: !0 }; Object.defineProperties(console, { log: R({}, r, { value: D }), info: R({}, r, { value: ne }), warn: R({}, r, { value: O }), error: R({}, r, { value: H }), group: R({}, r, { value: J }), groupCollapsed: R({}, r, { value: Y }), groupEnd: R({}, r, { value: G }) }); } K < 0 && y("disabledDepth fell below zero. This is a bug in React. Please file an issue."); } } var ve = k.ReactCurrentDispatcher, ge; function ue(r, d, b) { { if (ge === void 0) try { throw Error(); } catch (I) { var P = I.stack.trim().match(/\n( *(at )?)/); ge = P && P[1] || ""; } return ` ` + ge + r; } } var _e = !1, ye; { var at = typeof WeakMap == "function" ? WeakMap : Map; ye = new at(); } function Oe(r, d) { if (!r || _e) return ""; { var b = ye.get(r); if (b !== void 0) return b; } var P; _e = !0; var I = Error.prepareStackTrace; Error.prepareStackTrace = void 0; var q; q = ve.current, ve.current = null, pe(); try { if (d) { var $ = function() { throw Error(); }; if (Object.defineProperty($.prototype, "props", { set: function() { throw Error(); } }), typeof Reflect == "object" && Reflect.construct) { try { Reflect.construct($, []); } catch (fe) { P = fe; } Reflect.construct(r, [], $); } else { try { $.call(); } catch (fe) { P = fe; } r.call($.prototype); } } else { try { throw Error(); } catch (fe) { P = fe; } r(); } } catch (fe) { if (fe && P && typeof fe.stack == "string") { for (var V = fe.stack.split(` `), te = P.stack.split(` `), Z = V.length - 1, Q = te.length - 1; Z >= 1 && Q >= 0 && V[Z] !== te[Q]; ) Q--; for (; Z >= 1 && Q >= 0; Z--, Q--) if (V[Z] !== te[Q]) { if (Z !== 1 || Q !== 1) do if (Z--, Q--, Q < 0 || V[Z] !== te[Q]) { var ce = ` ` + V[Z].replace(" at new ", " at "); return r.displayName && ce.includes("<anonymous>") && (ce = ce.replace("<anonymous>", r.displayName)), typeof r == "function" && ye.set(r, ce), ce; } while (Z >= 1 && Q >= 0); break; } } } finally { _e = !1, ve.current = q, ee(), Error.prepareStackTrace = I; } var Ce = r ? r.displayName || r.name : "", gt = Ce ? ue(Ce) : ""; return typeof r == "function" && ye.set(r, gt), gt; } function Te(r, d, b) { return Oe(r, !1); } function Ae(r) { var d = r.prototype; return !!(d && d.isReactComponent); } function me(r, d, b) { if (r == null) return ""; if (typeof r == "function") return Oe(r, Ae(r)); if (typeof r == "string") return ue(r); switch (r) { case S: return ue("Suspense"); case _: return ue("SuspenseList"); } if (typeof r == "object") switch (r.$$typeof) { case v: return Te(r.render); case x: return me(r.type, d, b); case m: { var P = r, I = P._payload, q = P._init; try { return me(q(I), d, b); } catch { } } } return ""; } var ie = Object.prototype.hasOwnProperty, it = {}, ot = k.ReactDebugCurrentFrame; function Re(r) { if (r) { var d = r._owner, b = me(r.type, r._source, d ? d.type : null); ot.setExtraStackFrame(b); } else ot.setExtraStackFrame(null); } function tn(r, d, b, P, I) { { var q = Function.call.bind(ie); for (var $ in r) if (q(r, $)) { var V = void 0; try { if (typeof r[$] != "function") { var te = Error((P || "React class") + ": " + b + " type `" + $ + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof r[$] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`."); throw te.name = "Invariant Violation", te; } V = r[$](d, $, P, b, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"); } catch (Z) { V = Z; } V && !(V instanceof Error) && (Re(I), y("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", P || "React class", b, $, typeof V), Re(null)), V instanceof Error && !(V.message in it) && (it[V.message] = !0, Re(I), y("Failed %s type: %s", b, V.message), Re(null)); } } } var nn = Array.isArray; function qe(r) { return nn(r); } function rn(r) { { var d = typeof Symbol == "function" && Symbol.toStringTag, b = d && r[Symbol.toStringTag] || r.constructor.name || "Object"; return b; } } function an(r) { try { return st(r), !1; } catch { return !0; } } function st(r) { return "" + r; } function ct(r) { if (an(r)) return y("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", rn(r)), st(r); } var Se = k.ReactCurrentOwner, on = { key: !0, ref: !0, __self: !0, __source: !0 }, lt, pt, Ye; Ye = {}; function sn(r) { if (ie.call(r, "ref")) { var d = Object.getOwnPropertyDescriptor(r, "ref").get; if (d && d.isReactWarning) return !1; } return r.ref !== void 0; } function cn(r) { if (ie.call(r, "key")) { var d = Object.getOwnPropertyDescriptor(r, "key").get; if (d && d.isReactWarning) return !1; } return r.key !== void 0; } function ln(r, d) { if (typeof r.ref == "string" && Se.current && d && Se.current.stateNode !== d) { var b = A(Se.current.type); Ye[b] || (y('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', A(Se.current.type), r.ref), Ye[b] = !0); } } function pn(r, d) { { var b = function() { lt || (lt = !0, y("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", d)); }; b.isReactWarning = !0, Object.defineProperty(r, "key", { get: b, configurable: !0 }); } } function dn(r, d) { { var b = function() { pt || (pt = !0, y("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", d)); }; b.isReactWarning = !0, Object.defineProperty(r, "ref", { get: b, configurable: !0 }); } } var un = function(r, d, b, P, I, q, $) { var V = { // This tag allows us to uniquely identify this as a React Element $$typeof: t, // Built-in properties that belong on the element type: r, key: d, ref: b, props: $, // Record the component responsible for creating this element. _owner: q }; return V._store = {}, Object.defineProperty(V._store, "validated", { configurable: !1, enumerable: !1, writable: !0, value: !1 }), Object.defineProperty(V, "_self", { configurable: !1, enumerable: !1, writable: !1, value: P }), Object.defineProperty(V, "_source", { configurable: !1, enumerable: !1, writable: !1, value: I }), Object.freeze && (Object.freeze(V.props), Object.freeze(V)), V; }; function mn(r, d, b, P, I) { { var q, $ = {}, V = null, te = null; b !== void 0 && (ct(b), V = "" + b), cn(d) && (ct(d.key), V = "" + d.key), sn(d) && (te = d.ref, ln(d, I)); for (q in d) ie.call(d, q) && !on.hasOwnProperty(q) && ($[q] = d[q]); if (r && r.defaultProps) { var Z = r.defaultProps; for (q in Z) $[q] === void 0 && ($[q] = Z[q]); } if (V || te) { var Q = typeof r == "function" ? r.displayName || r.name || "Unknown" : r; V && pn($, Q), te && dn($, Q); } return un(r, V, te, I, P, Se.current, $); } } var Ue = k.ReactCurrentOwner, dt = k.ReactDebugCurrentFrame; function be(r) { if (r) { var d = r._owner, b = me(r.type, r._source, d ? d.type : null); dt.setExtraStackFrame(b); } else dt.setExtraStackFrame(null); } var Ke; Ke = !1; function Ge(r) { return typeof r == "object" && r !== null && r.$$typeof === t; } function ut() { { if (Ue.current) { var r = A(Ue.current.type); if (r) return ` Check the render method of \`` + r + "`."; } return ""; } } function fn(r) { { if (r !== void 0) { var d = r.fileName.replace(/^.*[\\\/]/, ""), b = r.lineNumber; return ` Check your code at ` + d + ":" + b + "."; } return ""; } } var mt = {}; function hn(r) { { var d = ut(); if (!d) { var b = typeof r == "string" ? r : r.displayName || r.name; b && (d = ` Check the top-level render call using <` + b + ">."); } return d; } } function ft(r, d) { { if (!r._store || r._store.validated || r.key != null) return; r._store.validated = !0; var b = hn(d); if (mt[b]) return; mt[b] = !0; var P = ""; r && r._owner && r._owner !== Ue.current && (P = " It was passed a child from " + A(r._owner.type) + "."), be(r), y('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', b, P), be(null); } } function ht(r, d) { { if (typeof r != "object") return; if (qe(r)) for (var b = 0; b < r.length; b++) { var P = r[b]; Ge(P) && ft(P, d); } else if (Ge(r)) r._store && (r._store.validated = !0); else if (r) { var I = h(r); if (typeof I == "function" && I !== r.entries) for (var q = I.call(r), $; !($ = q.next()).done; ) Ge($.value) && ft($.value, d); } } } function vn(r) { { var d = r.type; if (d == null || typeof d == "string") return; var b; if (typeof d == "function") b = d.propTypes; else if (typeof d == "object" && (d.$$typeof === v || // Note: Memo only checks outer props here. // Inner props are checked in the reconciler. d.$$typeof === x)) b = d.propTypes; else return; if (b) { var P = A(d); tn(b, r.props, "prop", P, r); } else if (d.PropTypes !== void 0 && !Ke) { Ke = !0; var I = A(d); y("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", I || "Unknown"); } typeof d.getDefaultProps == "function" && !d.getDefaultProps.isReactClassApproved && y("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead."); } } function gn(r) { { for (var d = Object.keys(r.props), b = 0; b < d.length; b++) { var P = d[b]; if (P !== "children" && P !== "key") { be(r), y("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", P), be(null); break; } } r.ref !== null && (be(r), y("Invalid attribute `ref` supplied to `React.Fragment`."), be(null)); } } function vt(r, d, b, P, I, q) { { var $ = z(r); if (!$) { var V = ""; (r === void 0 || typeof r == "object" && r !== null && Object.keys(r).length === 0) && (V += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports."); var te = fn(I); te ? V += te : V += ut(); var Z; r === null ? Z = "null" : qe(r) ? Z = "array" : r !== void 0 && r.$$typeof === t ? (Z = "<" + (A(r.type) || "Unknown") + " />", V = " Did you accidentally export a JSX literal instead of a component?") : Z = typeof r, y("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", Z, V); } var Q = mn(r, d, b, I, q); if (Q == null) return Q; if ($) { var ce = d.children; if (ce !== void 0) if (P) if (qe(ce)) { for (var Ce = 0; Ce < ce.length; Ce++) ht(ce[Ce], r); Object.freeze && Object.freeze(ce); } else y("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."); else ht(ce, r); } return r === i ? gn(Q) : vn(Q), Q; } } function xn(r, d, b) { return vt(r, d, b, !0); } function wn(r, d, b) { return vt(r, d, b, !1); } var _n = wn, yn = xn; je.Fragment = i, je.jsx = _n, je.jsxs = yn; }()), je; } (function(e) { process.env.NODE_ENV === "production" ? e.exports = Wn() : e.exports = Fn(); })(Bn); const qn = (e, t) => (typeof e == "string" ? e = new RegExp(e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"), t ? "g" : "gi") : e.global || (e = new RegExp(e.source, e.ignoreCase ? "gi" : "g")), { token: function(a) { e.lastIndex = a.pos; var i = e.exec(a.string); if (i && i.index == a.pos) return a.pos += i[0].length || 1, "searching"; i ? a.pos = i.index : a.skipToEnd(); } }), Yn = (e) => e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"), Un = (e) => { let { searchInput: t, editor: a, showPannel: i, setSearchInput: o } = e; const c = re(null), [s, l] = B(), [v, S] = B(), [_, x] = B(), [m, w] = B(), [f, u] = B(""), [h, k] = B(!1), [y, M] = B(!1); let g = a; const j = () => { S(qn(p(t), y)); const O = p(t); w(O); }; se(() => { g.showMatchesOnScrollbar && m && (_ && _.clear(), x(g.showMatchesOnScrollbar(m))); }, [m]); const p = (O) => { if (!O) return ""; let H; try { h ? H = new RegExp(O, y ? "g" : "gi") : H = new RegExp(Yn(O), y ? "g" : "gi"); } catch { } return H || ""; }; se(() => { v && g.addOverlay(v); }, [v, g]); const C = () => { s && l(void 0), g.operation(function() { g.removeOverlay(v); }), _ && (_.clear(), x(null)); }, E = () => { let O = g.getSearchCursor(p(t), { line: 0, ch: 0 }); O.findNext() && (g.setSelection(O == null ? void 0 : O.from(), O == null ? void 0 : O.to()), g.scrollIntoView({ from: O.from(), to: O.to() }, 100)), l(O); }; se(() => { var Y; if ((Y = c.current) == null || Y.focus(), !t) { C(); return; } const O = g.getCursor(); let H; H = g.getSearchCursor(p(t), { line: O.line, ch: O.ch - t.length }), H.findNext() ? (g.setSelection(H == null ? void 0 : H.from(), H == null ? void 0 : H.to()), g.scrollIntoView({ from: H.from(), to: H.to() }, 40)) : (H = g.getSearchCursor(p(t), { line: 0, ch: 0 }), H.findNext() && (g.setSelection(H == null ? void 0 : H.from(), H == null ? void 0 : H.to()), g.scrollIntoView({ from: H.from(), to: H.to() }, 40))), l(H), C(), j(); }, [t, g]); const N = () => { if (!(s == null ? void 0 : s.findPrevious())) { E(); return; } g.setSelection(s == null ? void 0 : s.from(), s == null ? void 0 : s.to()), g.scrollIntoView( { from: s == null ? void 0 : s.from(), to: s == null ? void 0 : s.to() }, 40 ); }, z = () => { if (!(s == null ? void 0 : s.findNext())) { E(); return; } g.setSelection(s == null ? void 0 : s.from(), s == null ? void 0 : s.to()), g.scrollIntoView( { from: s == null ? void 0 : s.from(), to: s == null ? void 0 : s.to() }, 40 ); }, L = () => { C(), i(!1); }, T = () => { if (g.getOption("readOnly") || !f) return; s == null || s.replace(f), (s == null ? void 0 : s.findNext()) && (g.setSelection(s == null ? void 0 : s.from(), s == null ? void 0 : s.to()), g.scrollIntoView( { from: s == null ? void 0 : s.from(), to: s == null ? void 0 : s.to() }, 100 )); }, A = () => { for (var O = g.getSearchCursor(p(t)); O.findNext(); ) typeof t != "string" || O.replace(f); }, R = (O) => { u(O.target.value); }, K = (O) => { o(O.target.value), C(), t || j(); }, D = () => { k((O) => !O); }, ne = () => { M((O) => !O); }; return se(() => { C(), m && (j(), E()); }, [y, h]), /* @__PURE__ */ n.jsxs("div", { className: "search-replace-pannel", children: [ /* @__PURE__ */ n.jsxs("div", { className: "search", children: [ /* @__PURE__ */ n.jsx("div", { className: "search-input", children: /* @__PURE__ */ n.jsx("input", { ref: c, type: "text", value: t, onChange: (O) => K(O) }) }), /* @__PURE__ */ n.jsxs("div", { className: "button-group", children: [ /* @__PURE__ */ n.jsx("button", { onClick: D, style: { color: h ? "#e45649" : "" }, children: ".*" }), /* @__PURE__ */ n.jsx("button", { onClick: ne, style: { color: y ? "#e45649" : "" }, children: "Aa" }), /* @__PURE__ */ n.jsx("button", { onClick: N, children: "↑" }), /* @__PURE__ */ n.jsx("button", { onClick: z, children: "↓" }), /* @__PURE__ */ n.jsx("button", { onClick: L, children: "×" }) ] }) ] }), /* @__PURE__ */ n.jsx("div", { className: "replace", children: /* @__PURE__ */ n.jsxs("div", { className: "replace-input", children: [ /* @__PURE__ */ n.jsx("input", { type: "text", value: f, onChange: (O) => R(O) }), /* @__PURE__ */ n.jsxs("div", { className: "button-group", children: [ /* @__PURE__ */ n.jsx("button", { onClick: T, children: "replace" }), /* @__PURE__ */ n.jsx("button", { onClick: A, children: "replace all" }) ] }) ] }) }) ] }); }; function Ct(e, t) { for (var a = e.getCursor(), i = e.lineCount(), o = [], c = a.line + 1; c < i; c++) o.push(e.getLine(c)); return o = e.getLine(a.line).slice(a.ch) + ` ` + o.join(` `), t(o); } function Et(e) { var t; return t = e.match(/`{3,}/g), t && t.length % 2 ? !1 : (t = e.match(/`/g), !(t && t.length % 2)); } function Kn(e, t, a) { let i = e.getCursor(), o = e.getTokenAt(i); const c = a.text; let s = ""; Ct(e, Et) && (s = "\n\n```"); let l = c + s; e.replaceRange(l, { line: i.line, ch: 3 }, { line: i.line, ch: o.end }), Ct(e, Et) ? e.execCommand("goLineUp") : Promise.resolve().then(() => { e.closeHint(); }); } function Gn(e, t, a) { let i = e.getCursor(), o = e.getTokenAt(i), c = 0, l = o.state.streamSeen.string.match(/^\s+/); l && (c = l[0].length); const v = a.text; let S = ` h${v.length}`, _ = v + S; e.replaceRange(_, { line: i.line, ch: c }, { line: i.line, ch: o.end }), Promise.resolve().then(() => { let x = e.getCursor(), m = e.getTokenAt(x); e.setSelection({ line: x.line, ch: m.end }, { line: x.line, ch: m.end - 2 }); }); } const Zn = (e, t) => { let a = e.getCursor(), i = e.getTokenAt(a); if (i.type && /header\sheader-\d/.test(i.type)) { let o = []; const c = i.state.streamSeen.string; let s = c.trimStart().split(/\s+/); if (s.length === 1) { for (let v = s[0].length; v <= 6; v++) { let S = "#".repeat(v); o.push({ text: `${S}`, displayText: `${S} h${S.length}`, hint: Gn }); } const l = i.end; return { list: o, from: { ch: c.length, line: a.line }, to: { ch: l, line: a.line } }; } } if (i.type && i.type === "comment" && !i.start) { t = t || ["bash", "javascript", "typescript", "go", "python", "jsx", "tsx", "sql", "markmap"]; let o = i.state.base.fencedEndRE; const c = i.string; let s = c.split("```")[1]; if (c && /^`{3}/.test(c) && o && !t.includes(s)) { let l = []; t.filter((S) => S.startsWith(s)).forEach( (S) => l.push({ text: S, displayText: S, hint: Kn }) ); const v = i.end; return { list: l, from: { ch: i.string.length, line: a.line }, to: { ch: v, line: a.line } }; } } }; const Qn = { placeholder: "write somthing...", mode: "gfm", lineNumbers: !0, // 是否显示行号 theme: "atom-dark", // 主题 tabSize: 4, // 默认4 indentUnit: 4, // 代码块中换行缩进大小 matchBrackets: !0, // 括号匹配 matchTags: { bothTags: !0 }, //标签匹配 singleCursorHeightPerLine: !1, lineWrapping: !0, styleActiveLine: { nonEmpty: !0 }, // 当前行高亮,nonEmpty表示当选择具体文本时是否高亮当前行 foldGutter: !0, gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"], autoCloseBrackets: !0, // 自动闭合括号 autoCloseTags: !0 // 自动闭合标签 }, Xn = (e, t) => { const { editorRef: a, onSave: i, uploadImageMethod: o, initialValue: c, options: s, languages: l } = e, v = re(null), { state: S, onScroll: _, onMouseEnter: x, dispatch: m } = e, w = re(); w.current = S; const [f, u] = B(!1), [h, k] = B(""); return se(() => { a.current = le.fromTextArea(v.current, { ...Qn, ...s }), a.current.setSize("100%", "100%"); function y(p, C) { if (p.isReadOnly()) return le.Pass; p.operation(function() { for (var E = p.listSelections().length, N = [], z = -1, L = 0; L < E; L++) { var T = p.listSelections()[L].head; if (!(T.line <= z)) { var A = X(T.line + (C ? 0 : 1), 0); p.replaceRange(` `, A, void 0, "+insertLine"), p.indentLine(A.line, void 0), N.push({ head: A, anchor: A }), z = T.line + 1; } } p.setSelections(N); }), p.execCommand("indentAuto"); } const M = { "Ctrl-Down": function(p) { let C = p.listSelections().length; for (let N = 0; N < C; N++) { var E = p.listSelections()[N]; E.empty() ? p.replaceRange(p.getLine(E.head.line) + ` `, X(E.head.line, 0)) : p.replaceRange(p.getRange(E.from(), E.to()), E.from()); } }, "Alt-Up": function(p) { if (p.isReadOnly()) return le.Pass; let C = p.listSelections(), E = [], N = p.firstLine() - 1, z = []; for (let L = 0; L < C.length; L++) { let T = C[L], A = T.from().line - 1, R = T.to().line; z.push({ anchor: X(T.anchor.line - 1, T.anchor.ch), head: X(T.head.line - 1, T.head.ch) }), T.to().ch === 0 && !T.empty() && --R, A > N ? E.push(A, R) : E.length && (E[E.length - 1] = R), N = R; } p.operation(function() { for (let L = 0; L < E.length; L += 2) { let T = E[L], A = E[L + 1], R = p.getLine(T); p.replaceRange("", X(T, 0), X(T + 1, 0), "+swapLine"), A > p.lastLine() ? p.replaceRange(` ` + R, X(p.lastLine()), void 0, "+swapLine") : p.replaceRange(R + ` `, X(A, 0), void 0, "+swapLine"); } p.setSelections(z); }); }, "Alt-Down": function(p) { if (p.isReadOnly()) return le.Pass; let C = p.listSelections(), E = [], N = p.lastLine() + 1; for (let A = C.length - 1; A >= 0; A--) { var z = C[A], L = z.to().line + 1, T = z.from().line; z.to().ch === 0 && !z.empty() && L--, L < N ? E.push(L, T) : E.length && (E[E.length - 1] = T), N = T; } p.operation(function() { for (var A = E.length - 2; A >= 0; A -= 2) { let R = E[A], K = E[A + 1], D = p.getLine(R); R === p.lastLine() ? p.replaceRange("", X(R - 1), X(R), "+swapLine") : (p.replaceRange("", X(R, 0), X(R + 1, 0), "+swapLine"), p.replaceRange(D + ` `, X(K, 0), void 0, "+swapLine")); } p.scrollIntoView(X(L, 1)); }); }, "Ctrl-Shift-Z": function(p) { p.execCommand("Ctrl-Y"); }, "Ctrl-Enter": function(p) { return y(p, !1); }, "Shift-Ctrl-Enter": function(p) { return y(p, !0); }, "Ctrl-S": function() { i && i(w.current.markdown, w.current.toc); } }; a.current.getSearchCursor && (M["Ctrl-F"] = function(p) { let C = p.getSelection(); k(C), u(!0); }), a.current.setOption("extraKeys", M), a.current.setOption("hintOptions", { hint: (p) => Zn(p, l), completeSingle: !1, closeOnUnfocus: !1 }), a.current.on("change", function(p) { return m({ type: "setMarkdown", value: p.getValue() }), p.showHint && p.showHint(), le.Pass; }); const g = (p, C, E) => { const N = a.current; if (!N) return le.Pass; N.replaceRange(p, X(C, E)); }, j = (p, C, E, N) => { const z = `![${p || ""}](${C || ""} "${p || ""}")`; g(z, E, N); }; a.current.on("scroll", () => _()), a.current.on("paste", (p, C) => { if (!(C.clipboardData && C.clipboardData.items)) { alert("该浏览器不支持操作"); return; } for (var E = 0, N = C.clipboardData.items.length; E < N; E++) { var z = C.clipboardData.items[E]; if (z.kind === "string") z.getAsString(function() { }); else if (z.kind === "file") { var L = z.getAsFile(); const T = p.getCursor(); o && o(L, (A, R) => j(A, R, T.line, T.ch)); } } }); }, []), se(() => { a.current && a.current.setValue(c); }, [c]), /* @__PURE__ */ n.jsx(n.Fragment, { children: /* @__PURE__ */ n.jsxs("div", { className: "rmdcm5-editor", onMouseEnter: x, children: [ f && /* @__PURE__ */ n.jsx(Un, { searchInput: h, editor: a.current, showPannel: u, setSearchInput: k }), /* @__PURE__ */ n.jsx("textarea", { ref: v }) ] }) }); }, Jn = de.forwardRef(Xn); var Je = {}, er = { get exports() { return Je; }, set exports(e) { Je = e; } }; (function(e, t) { (function(a, i) { e.exports = i(de); })(In, function(a) { function i(x, m, w, f) { return m === void 0 && (m = {}), Object.keys(m).reduce(function(u, h) { if (/^on.*/.test(h)) return u; var k = h; /^(data|aria)-/.test(h) || w.filter(function(C) { return C instanceof RegExp ? C.test(h) : C === h; }).length === 0 && (k = o(h)); var y, M, g = f(x, k); if (g.name === "style") u[g.name] = (y = m.style, M = {}, y.split(";").filter(function(C) { return C.trim() !== ""; }).forEach(function(C) { var E, N = C.split(":"); if (N.length > 1) { var z = function(T) { return /^-ms-/.test(T) && (T = T.substr(1)), T.startsWith("--") ? T : o(T); }(N[0].trim()), L = (E = N.slice(1).join(":").trim(), /^\d+$/.test(E) ? Number(E) : E.replace(/'/g, '"')); M[z] = L; } }), M); else { var j = m[h], p = j === "" || String(j).toLowerCase() === k.toLowerCase(); u[g.name] = g.isBoolean ? p : j; } return u; }, {}); } function o(x) { return x.replace(/(-|:)(.)/g, function(m, w, f) { return f.toUpperCase(); }); } a = a && a.hasOwnProperty("default") ? a.default : a; var c = ["table", "tbody", "thead", "tfoot", "tr"], s = { for: "htmlFor", class: "className", allowfullscreen: ["allowFullScreen", "allowFullscreen"], autocomplete: "autoComplete", autofocus: ["autoFocus"], contenteditable: "contentEditable", spellcheck: "spellCheck", srcdoc: "srcDoc", srcset: "srcSet", itemscope: "itemScope", itemprop: "itemProp", itemtype: "itemType" }; function l(x, m) { var w = s[m], f = document.createElement(x); if (w) return { name: Array.isArray(w) ? w[0] : w, isBoolean: v(f, Array.isArray(w) ? w[1] || m : w) }; for (var u in f) if (u.toLowerCase() === m.toLowerCase()) return { name: u, isBoolean: v(f, u) }; return { name: m, isBoolean: v(f, m) }; } function v(x, m) { return x.setAttribute(m, ""), x[m] === !0 || S.indexOf(m) > -1; } var S = ["itemScope"]; function _(x, m, w, f) { f === void 0 && (f = null); var u = w[x], h = w._; return u ? a.createElement(u, m, f) : h ? h(x, m, f) : a.createElement(x, m, f); } return function(x, m) { if (m === void 0 && (m = {}), typeof x != "string") throw new TypeError("Expected HTML string"); var w = document.createElement("div"); w.innerHTML = x.trim(); var f = Array.from(w.childNodes).map(function(u, h) { return function k(y, M, g) { var j = g.transform || {}, p = g.preserveAttributes || [], C = g.dangerouslySetChildren || ["style"], E = j._; if (y.nodeType === 8) return null; if (y.nodeType === 3) { var N = y.textContent; return E ? E(N) : N; } for (var z = {}, L = y.attributes, T = 0; T < L.length; T++) z[L[T].name] = L[T].value; z.key = M.toString(); var A = y.tagName.toLowerCase(), R = i(A, z, p, l), K = Array.from(y.childNodes).map(function(O, H) { return c.indexOf(A) > -1 && O.nodeType === 3 && (O.textContent = O.textContent.trim(), O.textContent === "") ? null : k(O, M + "." + H, g); }).filter(Boolean); if (C.indexOf(A) > -1) { var D = y.innerHTML; return D && (A !== "style" && A !== "script" && (D = D.replace(/"/g, "&quot;")), R.dangerouslySetInnerHTML = { __html: D.trim() }), _(A, R, j); } var ne = K.length === 0 ? null : K; return _(A, R, j, ne); }(u, String(h), m); }).filter(Boolean); return f.length === 1 ? f[0] : f; }; }); })(er); const tr = Je; var rt = {}, He = {}, nr = { get exports() { return He; }, set exports(e) { He = e; } }; (function(e) { function t(a) { return a && a.__esModule ? a : { default: a }; } e.exports = t, e.exports.__esModule = !0, e.exports.default = e.exports; })(nr); var we = {}, rr = { get exports() { return we; }, set exports(e) { we = e; } }; (function(e) { function t(a) { return e.exports = t = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(i) { return typeof i; } : function(i) { return i && typeof Symbol == "function" && i.constructor === Symbol && i !== Symbol.prototype ? "symbol" : typeof i; }, e.exports.__esModule = !0, e.exports.default = e.exports, t(a); } e.exports = t, e.exports.__esModule = !0, e.exports.default = e.exports; })(rr); var ze = {}, ar = { get exports() { return ze; }, set exports(e) { ze = e; } }, Ot; function ir() { return Ot || (Ot = 1, function(e) { function t() { return e.exports = t = Object.assign ? Object.assign.bind() : function(a) { for (var i = 1; i < arguments.length; i++) { var o = arguments[i]; for (var c in o) Object.prototype.hasOwnProperty.call(o, c) && (a[c] = o[c]); } return a; }, e.exports.__esModule = !0, e.exports.default = e.exports, t.apply(this, arguments); } e.exports = t, e.exports.__esModule = !0, e.exports.default = e.exports; }(ar)), ze; } var Ve = {}, or = { get exports() { return Ve; }, set exports(e) { Ve = e; } }, $e = {}, sr = { get exports() { return $e; }, set exports(e) { $e = e; } }, De = {}, cr = { get exports() { return De; }, set exports(e) { De = e; } }, Ie = {}, lr = { get exports() { return Ie; }, set exports(e) { Ie = e; } }, St; function pr() { return St || (St = 1, function(e) { var t = we.default; function a(i, o) { if (t(i) !== "object" || i === null) return i; var c = i[Symbol.toPrimitive]; if (c !== void 0) { var s = c.call(i, o || "default"); if (t(s) !== "object") return s; throw new TypeError("@@toPrimitive must return a primitive value."); } return (o === "string" ? String : Number)(i); } e.exports = a, e.exports.__esModule = !0, e.exports.default = e.exports; }(lr)), Ie; } var kt; function dr() { return kt || (kt = 1, function(e) { var t = we.default, a = pr(); function i(o) { var c = a(o, "string"); return t(c) === "symbol" ? c : String(c); } e.exports = i, e.exports.__esModule = !0, e.exports.default = e.exports; }(cr)), De; } var jt; function ur() { return jt || (jt = 1, function(e) { var t = dr(); function a(i, o, c) { return o = t(o), o in i ? Object.defineProperty(i, o, { value: c, enumerable: !0, configurable: !0, writable: !0 }) : i[o] = c, i; } e.exports = a, e.exports.__esModule = !0, e.exports.default = e.exports; }(sr)), $e; } var Mt; function mr() { return Mt || (Mt = 1, function(e) { var t = ur(); function a(o, c) { var s = Object.keys(o); if (Object.getOwnPropertySymbols) { var l = Object.getOwnPropertySymbols(o); c && (l = l.filter(function(v) { return Object.getOwnPropertyDescriptor(o, v).enumerable; })), s.push.apply(s, l); } return s; } function i(o) { for (var c = 1; c < arguments.length; c++) { var s = arguments[c] != null ? arguments[c] : {}; c % 2 ? a(Object(s), !0).forEach(function(l) { t(o, l, s[l]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(o, Object.getOwnPropertyDescriptors(s)) : a(Object(s)).forEach(function(l) { Object.defineProperty(o, l, Object.getOwnPropertyDescriptor(s, l)); }); } return o; } e.exports = i, e.exports.__esModule = !0, e.exports.default = e.exports; }(or)), Ve; } var Be = {}, fr = { get exports() { return Be; }, set exports(e) { Be = e; } }, We = {}, hr = { get exports() { return We; }, set exports(e) { We = e; } }, Tt; function vr() { return Tt || (Tt = 1, function(e) { function t(a, i) { if (a == null) return {}; var o = {}, c = Object.keys(a), s, l; for (l = 0; l < c.length; l++) s = c[l], !(i.indexOf(s) >= 0) && (o[s] = a[s]); return o; } e.exports = t, e.exports.__esModule = !0, e.exports.default = e.exports; }(hr)), We; } var At; function gr() { return At || (At = 1, function(e) { var t = vr(); function a(i, o) { if (i == null) return {}; var c = t(i, o), s, l; if (Object.getOwnPropertySymbols) { var v = Object.getOwnPropertySymbols(i); for (l = 0; l < v.length; l++) s = v[l], !(o.indexOf(s) >= 0) && Object.prototype.propertyIsEnumerable.call(i, s) && (c[s] = i[s]); } return c; } e.exports = a, e.exports.__esModule = !0, e.exports.default = e.exports; }(fr)), Be; } var xe = {}, Rt; function Bt() { if (Rt) return xe; Rt = 1, Object.defineProperty(xe, "__esModule", { value: !0 }), xe.placements = xe.default = void 0; var e = { adjustX: 1, adjustY: 1 }, t = [0, 0], a = { left: { points: ["cr", "cl"], overflow: e, offset: [-4, 0], targetOffset: t }, right: { points: ["cl", "cr"], overflow: e, offset: [4, 0], targetOffset: t }, top: { points: ["bc", "tc"], overflow: e, offset: [0, -4], targetOffset: t }, bottom: { points: ["tc", "bc"], overflow: e, offset: [0, 4], targetOffset: t }, topLeft: { points: ["bl", "tl"], overflow: e, offset: [0, -4], targetOffset: t }, leftTop: { points: ["tr", "tl"], overflow: e, offset: [-4, 0], targetOffset: t }, topRight: { points: ["br", "tr"], overflow: e, offset: [0, -4], targetOffset: t }, rightTop: { points: ["tl", "tr"], overflow: e, offset: [4, 0], targetOffset: t }, bottomRight: { points: ["tr", "br"], overflow: e, offset: [0, 4], targetOffset: t }, rightBottom: { points: ["bl", "br"], overflow: e, offset: [4, 0], targetOffset: t }, bottomLeft: { points: ["tl", "bl"], overflow: e, offset: [0, 4], targetOffset: t }, leftBottom: { points: ["br", "bl"], overflow: e, offset: [-4, 0], targetOffset: t } }; xe.placements = a; var i = a; return xe.default = i, xe; } var Ne = {}, Nt; function xr() { if (Nt) return Ne; Nt = 1; var e = He, t = we; Object.defineProperty(Ne, "__esModule", { value: !0 }), Ne.default = s; var a = c(de), i = e(Pe); function o(l) { if (typeof WeakMap != "function") return null; var v = /* @__PURE__ */ new WeakMap(), S = /* @__PURE__ */ new WeakMap(); return (o = function(x) { return x ? S : v; })(l); } function c(l, v) { if (!v && l && l.__esModule) return l; if (l === null || t(l) !== "object" && typeof l != "function") return { default: l }; var S = o(v); if (S && S.has(l)) return S.get(l); var _ = {}, x = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var m in l) if (m !== "default" && Object.prototype.hasOwnProperty.call(l, m)) { var w = x ? Object.getOwnPropertyDescriptor(l, m) : null; w && (w.get || w.set) ? Object.defineProperty(_, m, w) : _[m] = l[m]; } return _.default = l, S && S.set(l, _), _; } function s(l) { var v = l.showArrow, S = l.arrowContent, _ = l.children, x = l.prefixCls, m = l.id, w = l.overlayInnerStyle, f = l.className, u = l.style; return /* @__PURE__ */ a.createElement("div", { className: (0, i.default)("".concat(x, "-content"), f), style: u }, v !== !1 && /* @__PURE__ */ a.createElement("div", { className: "".concat(x, "-arrow"), key: "arrow" }, S), /* @__PURE__ */ a.createElement("div", { className: "".concat(x, "-inner"), id: m, role: "tooltip", style: w }, typeof _ == "function" ? _() : _)); } return Ne; } var Ee = He, wr = we; Object.defineProperty(rt, "__esModule", { value: !0 }); var Wt = rt.default = void 0, _r = Ee(ir()), yr = Ee(we), br = Ee(mr()), Cr = Ee(gr()), Me = jr(de), Er = Ee(Sn), Or = Bt(), Sr = Ee(xr()), kr = ["overlayClassName", "trigger", "mouseEnterDelay", "mouseLeaveDelay", "overlayStyle", "prefixCls", "children", "onVisibleChange", "afterVisibleChange", "transitionName", "animation", "motion", "placement", "align", "destroyTooltipOnHide", "defaultVisible", "getTooltipContainer", "overlayInnerStyle", "arrowContent", "overlay", "id", "showArrow"]; function Ft(e) { if (typeof WeakMap != "function") return null; var t = /* @__PURE__ */ new WeakMap(), a = /* @__PURE__ */ new WeakMap(); return (Ft = function(o) { return o ? a : t; })(e); } function jr(e, t) { if (!t && e && e.__esModule) return e; if (e === null || wr(e) !== "object" && typeof e != "function") return { default: e }; var a = Ft(t); if (a && a.has(e)) return a.get(e); var i = {}, o = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var c in e) if (c !== "default" && Object.prototype.hasOwnProperty.call(e, c)) { var s = o ? Object.getOwnPropertyDescriptor(e, c) : null; s && (s.get || s.set) ? Object.defineProperty(i, c, s) : i[c] = e[c]; } return i.default = e, a && a.set(e, i), i; } var Mr = function(t, a) { var i = t.overlayClassName, o = t.trigger, c = o === void 0 ? ["hover"] : o, s = t.mouseEnterDelay, l = s === void 0 ? 0 : s, v = t.mouseLeaveDelay, S = v === void 0 ? 0.1 : v, _ = t.overlayStyle, x = t.prefixCls, m = x === void 0 ? "rc-tooltip" : x, w = t.children, f = t.onVisibleChange, u = t.afterVisibleChange, h = t.transitionName, k = t.animation, y = t.motion, M = t.placement, g = M === void 0 ? "right" : M, j = t.align, p = j === void 0 ? {} : j, C = t.destroyTooltipOnHide, E = C === void 0 ? !1 : C, N = t.defaultVisible, z = t.getTooltipContainer, L = t.overlayInnerStyle, T = t.arrowContent, A = t.overlay, R = t.id, K = t.showArrow, D = K === void 0 ? !0 : K, ne = (0, Cr.default)(t, kr), O = (0, Me.useRef)(null); (0, Me.useImperativeHandle)(a, function() { return O.current; }); var H = (0, br.default)({}, ne); "visible" in t && (H.popupVisible = t.visible); var J = function() { return /* @__PURE__ */ Me.createElement(Sr.default, { showArrow: D, arrowContent: T, key: "content", prefixCls: m, id: R, overlayInnerStyle: L }, A); }, Y