UNPKG

@datazymes/dz-rich-text-editor

Version:

A comprehensive React rich text editor component with image upload, resize functionality, and standalone CSS. Ready for NPM publishing.

1,422 lines (1,419 loc) 80.1 kB
import Mt, { useRef as We, useState as g, useCallback as Fe, useEffect as Y } from "react"; var zt = { exports: {} }, ct = {}; /** * @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 $t; function ur() { if ($t) return ct; $t = 1; var O = Mt, j = Symbol.for("react.element"), ee = Symbol.for("react.fragment"), A = Object.prototype.hasOwnProperty, _ = O.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, te = { key: !0, ref: !0, __self: !0, __source: !0 }; function M(T, y, z) { var R, D = {}, V = null, h = null; z !== void 0 && (V = "" + z), y.key !== void 0 && (V = "" + y.key), y.ref !== void 0 && (h = y.ref); for (R in y) A.call(y, R) && !te.hasOwnProperty(R) && (D[R] = y[R]); if (T && T.defaultProps) for (R in y = T.defaultProps, y) D[R] === void 0 && (D[R] = y[R]); return { $$typeof: j, type: T, key: V, ref: h, props: D, _owner: _.current }; } return ct.Fragment = ee, ct.jsx = M, ct.jsxs = M, ct; } var dt = {}; /** * @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 Ot; function fr() { return Ot || (Ot = 1, process.env.NODE_ENV !== "production" && function() { var O = Mt, j = Symbol.for("react.element"), ee = Symbol.for("react.portal"), A = Symbol.for("react.fragment"), _ = Symbol.for("react.strict_mode"), te = Symbol.for("react.profiler"), M = Symbol.for("react.provider"), T = Symbol.for("react.context"), y = Symbol.for("react.forward_ref"), z = Symbol.for("react.suspense"), R = Symbol.for("react.suspense_list"), D = Symbol.for("react.memo"), V = Symbol.for("react.lazy"), h = Symbol.for("react.offscreen"), Re = Symbol.iterator, qe = "@@iterator"; function yt(t) { if (t === null || typeof t != "object") return null; var s = Re && t[Re] || t[qe]; return typeof s == "function" ? s : null; } var ce = O.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; function S(t) { { for (var s = arguments.length, o = new Array(s > 1 ? s - 1 : 0), d = 1; d < s; d++) o[d - 1] = arguments[d]; Ue("error", t, o); } } function Ue(t, s, o) { { var d = ce.ReactDebugCurrentFrame, m = d.getStackAddendum(); m !== "" && (s += "%s", o = o.concat([m])); var b = o.map(function(u) { return String(u); }); b.unshift("Warning: " + s), Function.prototype.apply.call(console[t], console, b); } } var Ne = !1, Ye = !1, Ve = !1, Le = !1, ut = !1, de; de = Symbol.for("react.module.reference"); function xt(t) { return !!(typeof t == "string" || typeof t == "function" || t === A || t === te || ut || t === _ || t === z || t === R || Le || t === h || Ne || Ye || Ve || typeof t == "object" && t !== null && (t.$$typeof === V || t.$$typeof === D || t.$$typeof === M || t.$$typeof === T || t.$$typeof === y || // 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. t.$$typeof === de || t.getModuleId !== void 0)); } function Xe(t, s, o) { var d = t.displayName; if (d) return d; var m = s.displayName || s.name || ""; return m !== "" ? o + "(" + m + ")" : o; } function _e(t) { return t.displayName || "Context"; } function B(t) { if (t == null) return null; if (typeof t.tag == "number" && S("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof t == "function") return t.displayName || t.name || null; if (typeof t == "string") return t; switch (t) { case A: return "Fragment"; case ee: return "Portal"; case te: return "Profiler"; case _: return "StrictMode"; case z: return "Suspense"; case R: return "SuspenseList"; } if (typeof t == "object") switch (t.$$typeof) { case T: var s = t; return _e(s) + ".Consumer"; case M: var o = t; return _e(o._context) + ".Provider"; case y: return Xe(t, t.render, "ForwardRef"); case D: var d = t.displayName || null; return d !== null ? d : B(t.type) || "Memo"; case V: { var m = t, b = m._payload, u = m._init; try { return B(u(b)); } catch { return null; } } } return null; } var re = Object.assign, ae = 0, Je, Ke, ft, Ae, be, mt, ve; function pt() { } pt.__reactDisabledLog = !0; function Ge() { { if (ae === 0) { Je = console.log, Ke = console.info, ft = console.warn, Ae = console.error, be = console.group, mt = console.groupCollapsed, ve = console.groupEnd; var t = { configurable: !0, enumerable: !0, value: pt, writable: !0 }; Object.defineProperties(console, { info: t, log: t, warn: t, error: t, group: t, groupCollapsed: t, groupEnd: t }); } ae++; } } function Ze() { { if (ae--, ae === 0) { var t = { configurable: !0, enumerable: !0, writable: !0 }; Object.defineProperties(console, { log: re({}, t, { value: Je }), info: re({}, t, { value: Ke }), warn: re({}, t, { value: ft }), error: re({}, t, { value: Ae }), group: re({}, t, { value: be }), groupCollapsed: re({}, t, { value: mt }), groupEnd: re({}, t, { value: ve }) }); } ae < 0 && S("disabledDepth fell below zero. This is a bug in React. Please file an issue."); } } var I = ce.ReactCurrentDispatcher, Qe; function De(t, s, o) { { if (Qe === void 0) try { throw Error(); } catch (m) { var d = m.stack.trim().match(/\n( *(at )?)/); Qe = d && d[1] || ""; } return ` ` + Qe + t; } } var Pe = !1, X; { var ze = typeof WeakMap == "function" ? WeakMap : Map; X = new ze(); } function wt(t, s) { if (!t || Pe) return ""; { var o = X.get(t); if (o !== void 0) return o; } var d; Pe = !0; var m = Error.prepareStackTrace; Error.prepareStackTrace = void 0; var b; b = I.current, I.current = null, Ge(); try { if (s) { var u = function() { throw Error(); }; if (Object.defineProperty(u.prototype, "props", { set: function() { throw Error(); } }), typeof Reflect == "object" && Reflect.construct) { try { Reflect.construct(u, []); } catch (L) { d = L; } Reflect.construct(t, [], u); } else { try { u.call(); } catch (L) { d = L; } t.call(u.prototype); } } else { try { throw Error(); } catch (L) { d = L; } t(); } } catch (L) { if (L && d && typeof L.stack == "string") { for (var f = L.stack.split(` `), E = d.stack.split(` `), C = f.length - 1, w = E.length - 1; C >= 1 && w >= 0 && f[C] !== E[w]; ) w--; for (; C >= 1 && w >= 0; C--, w--) if (f[C] !== E[w]) { if (C !== 1 || w !== 1) do if (C--, w--, w < 0 || f[C] !== E[w]) { var N = ` ` + f[C].replace(" at new ", " at "); return t.displayName && N.includes("<anonymous>") && (N = N.replace("<anonymous>", t.displayName)), typeof t == "function" && X.set(t, N), N; } while (C >= 1 && w >= 0); break; } } } finally { Pe = !1, I.current = b, Ze(), Error.prepareStackTrace = m; } var J = t ? t.displayName || t.name : "", $ = J ? De(J) : ""; return typeof t == "function" && X.set(t, $), $; } function Be(t, s, o) { return wt(t, !1); } function P(t) { var s = t.prototype; return !!(s && s.isReactComponent); } function ne(t, s, o) { if (t == null) return ""; if (typeof t == "function") return wt(t, P(t)); if (typeof t == "string") return De(t); switch (t) { case z: return De("Suspense"); case R: return De("SuspenseList"); } if (typeof t == "object") switch (t.$$typeof) { case y: return Be(t.render); case D: return ne(t.type, s, o); case V: { var d = t, m = d._payload, b = d._init; try { return ne(b(m), s, o); } catch { } } } return ""; } var W = Object.prototype.hasOwnProperty, Ie = {}, ye = ce.ReactDebugCurrentFrame; function le(t) { if (t) { var s = t._owner, o = ne(t.type, t._source, s ? s.type : null); ye.setExtraStackFrame(o); } else ye.setExtraStackFrame(null); } function se(t, s, o, d, m) { { var b = Function.call.bind(W); for (var u in t) if (b(t, u)) { var f = void 0; try { if (typeof t[u] != "function") { var E = Error((d || "React class") + ": " + o + " type `" + u + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof t[u] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`."); throw E.name = "Invariant Violation", E; } f = t[u](s, u, d, o, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"); } catch (C) { f = C; } f && !(f instanceof Error) && (le(m), S("%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).", d || "React class", o, u, typeof f), le(null)), f instanceof Error && !(f.message in Ie) && (Ie[f.message] = !0, le(m), S("Failed %s type: %s", o, f.message), le(null)); } } } var He = Array.isArray; function et(t) { return He(t); } function ue(t) { { var s = typeof Symbol == "function" && Symbol.toStringTag, o = s && t[Symbol.toStringTag] || t.constructor.name || "Object"; return o; } } function ht(t) { try { return oe(t), !1; } catch { return !0; } } function oe(t) { return "" + t; } function tt(t) { if (ht(t)) return S("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", ue(t)), oe(t); } var fe = ce.ReactCurrentOwner, Bt = { key: !0, ref: !0, __self: !0, __source: !0 }, rt, Ct, $e; $e = {}; function kt(t) { if (W.call(t, "ref")) { var s = Object.getOwnPropertyDescriptor(t, "ref").get; if (s && s.isReactWarning) return !1; } return t.ref !== void 0; } function Oe(t) { if (W.call(t, "key")) { var s = Object.getOwnPropertyDescriptor(t, "key").get; if (s && s.isReactWarning) return !1; } return t.key !== void 0; } function at(t, s) { if (typeof t.ref == "string" && fe.current && s && fe.current.stateNode !== s) { var o = B(fe.current.type); $e[o] || (S('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', B(fe.current.type), t.ref), $e[o] = !0); } } function jt(t, s) { { var o = function() { rt || (rt = !0, S("%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)", s)); }; o.isReactWarning = !0, Object.defineProperty(t, "key", { get: o, configurable: !0 }); } } function F(t, s) { { var o = function() { Ct || (Ct = !0, S("%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)", s)); }; o.isReactWarning = !0, Object.defineProperty(t, "ref", { get: o, configurable: !0 }); } } var St = function(t, s, o, d, m, b, u) { var f = { // This tag allows us to uniquely identify this as a React Element $$typeof: j, // Built-in properties that belong on the element type: t, key: s, ref: o, props: u, // Record the component responsible for creating this element. _owner: b }; return f._store = {}, Object.defineProperty(f._store, "validated", { configurable: !1, enumerable: !1, writable: !0, value: !1 }), Object.defineProperty(f, "_self", { configurable: !1, enumerable: !1, writable: !1, value: d }), Object.defineProperty(f, "_source", { configurable: !1, enumerable: !1, writable: !1, value: m }), Object.freeze && (Object.freeze(f.props), Object.freeze(f)), f; }; function me(t, s, o, d, m) { { var b, u = {}, f = null, E = null; o !== void 0 && (tt(o), f = "" + o), Oe(s) && (tt(s.key), f = "" + s.key), kt(s) && (E = s.ref, at(s, m)); for (b in s) W.call(s, b) && !Bt.hasOwnProperty(b) && (u[b] = s[b]); if (t && t.defaultProps) { var C = t.defaultProps; for (b in C) u[b] === void 0 && (u[b] = C[b]); } if (f || E) { var w = typeof t == "function" ? t.displayName || t.name || "Unknown" : t; f && jt(u, w), E && F(u, w); } return St(t, f, E, m, d, fe.current, u); } } var nt = ce.ReactCurrentOwner, lt = ce.ReactDebugCurrentFrame; function pe(t) { if (t) { var s = t._owner, o = ne(t.type, t._source, s ? s.type : null); lt.setExtraStackFrame(o); } else lt.setExtraStackFrame(null); } var k; k = !1; function xe(t) { return typeof t == "object" && t !== null && t.$$typeof === j; } function he() { { if (nt.current) { var t = B(nt.current.type); if (t) return ` Check the render method of \`` + t + "`."; } return ""; } } function st(t) { { if (t !== void 0) { var s = t.fileName.replace(/^.*[\\\/]/, ""), o = t.lineNumber; return ` Check your code at ` + s + ":" + o + "."; } return ""; } } var we = {}; function Me(t) { { var s = he(); if (!s) { var o = typeof t == "string" ? t : t.displayName || t.name; o && (s = ` Check the top-level render call using <` + o + ">."); } return s; } } function Ce(t, s) { { if (!t._store || t._store.validated || t.key != null) return; t._store.validated = !0; var o = Me(s); if (we[o]) return; we[o] = !0; var d = ""; t && t._owner && t._owner !== nt.current && (d = " It was passed a child from " + B(t._owner.type) + "."), pe(t), S('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', o, d), pe(null); } } function ke(t, s) { { if (typeof t != "object") return; if (et(t)) for (var o = 0; o < t.length; o++) { var d = t[o]; xe(d) && Ce(d, s); } else if (xe(t)) t._store && (t._store.validated = !0); else if (t) { var m = yt(t); if (typeof m == "function" && m !== t.entries) for (var b = m.call(t), u; !(u = b.next()).done; ) xe(u.value) && Ce(u.value, s); } } } function ot(t) { { var s = t.type; if (s == null || typeof s == "string") return; var o; if (typeof s == "function") o = s.propTypes; else if (typeof s == "object" && (s.$$typeof === y || // Note: Memo only checks outer props here. // Inner props are checked in the reconciler. s.$$typeof === D)) o = s.propTypes; else return; if (o) { var d = B(s); se(o, t.props, "prop", d, t); } else if (s.PropTypes !== void 0 && !k) { k = !0; var m = B(s); S("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", m || "Unknown"); } typeof s.getDefaultProps == "function" && !s.getDefaultProps.isReactClassApproved && S("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead."); } } function v(t) { { for (var s = Object.keys(t.props), o = 0; o < s.length; o++) { var d = s[o]; if (d !== "children" && d !== "key") { pe(t), S("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", d), pe(null); break; } } t.ref !== null && (pe(t), S("Invalid attribute `ref` supplied to `React.Fragment`."), pe(null)); } } var H = {}; function gt(t, s, o, d, m, b) { { var u = xt(t); if (!u) { var f = ""; (t === void 0 || typeof t == "object" && t !== null && Object.keys(t).length === 0) && (f += " 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 E = st(m); E ? f += E : f += he(); var C; t === null ? C = "null" : et(t) ? C = "array" : t !== void 0 && t.$$typeof === j ? (C = "<" + (B(t.type) || "Unknown") + " />", f = " Did you accidentally export a JSX literal instead of a component?") : C = typeof t, S("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", C, f); } var w = me(t, s, o, m, b); if (w == null) return w; if (u) { var N = s.children; if (N !== void 0) if (d) if (et(N)) { for (var J = 0; J < N.length; J++) ke(N[J], t); Object.freeze && Object.freeze(N); } else S("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 ke(N, t); } if (W.call(s, "key")) { var $ = B(t), L = Object.keys(s).filter(function(_t) { return _t !== "key"; }), q = L.length > 0 ? "{key: someKey, " + L.join(": ..., ") + ": ...}" : "{key: someKey}"; if (!H[$ + q]) { var Lt = L.length > 0 ? "{" + L.join(": ..., ") + ": ...}" : "{}"; S(`A props object containing a "key" prop is being spread into JSX: let props = %s; <%s {...props} /> React keys must be passed directly to JSX without using spread: let props = %s; <%s key={someKey} {...props} />`, q, $, Lt, $), H[$ + q] = !0; } } return t === A ? v(w) : ot(w), w; } } function Et(t, s, o) { return gt(t, s, o, !0); } function Tt(t, s, o) { return gt(t, s, o, !1); } var Rt = Tt, Nt = Et; dt.Fragment = A, dt.jsx = Rt, dt.jsxs = Nt; }()), dt; } process.env.NODE_ENV === "production" ? zt.exports = ur() : zt.exports = fr(); var a = zt.exports; const Pt = async (O, j = {}) => { var ee; if (!O) throw new Error("No file provided for upload."); try { const { uploadApiUrl: A = "~/upload", clientId: _ = "00", clientSecret: te = "00" } = j; if (!A) throw new Error("Upload API URL is required in configuration"); const M = new FormData(); M.append("image", O), _ && M.append("client_id", _), te && M.append("client_secret", te); const T = await fetch(A, { method: "POST", body: M, headers: { accept: "application/json" } }); if (!T.ok) throw new Error( `Upload failed: ${T.status} ${T.statusText}` ); const z = (ee = (await T.json()).data) == null ? void 0 : ee.authenticatedUrl; if (!z) throw new Error("No authenticatedUrl received from server"); return z; } catch (A) { throw console.error("Upload failed:", A), A; } }, pr = ({ value: O = "", onChange: j, toolbarOptions: ee = [ "bold", "italic", "underline", "strikethrough", "highlight", "fontColor", "headings", "fontFamily", "lineSpacing", "alignLeft", "alignCenter", "alignRight", "alignJustify", "unorderedList", "orderedList", "todoList", "increaseIndent", "decreaseIndent", "link", "insertImage", "blockquote", "codeBlock", "pageBreak", "caseChange", "insertTable" ], placeholder: A = "Start typing...", readOnly: _ = !1, height: te = "h-64", width: M = "w-full", toolbarPosition: T = "top", stickyToolbar: y = !1, stickyOffset: z = 0, debounceTime: R = 300, customClasses: D = {}, uploadConfig: V = {} }) => { const h = We(null), Re = We(null), qe = We(null), [yt, ce] = g({}), [S, Ue] = g(!1), [Ne, Ye] = g(""), [Ve, Le] = g(""), [ut, de] = g(null), [xt, Xe] = g(!1), [_e, B] = g("#000000"), [re, ae] = g(!1), [Je, Ke] = g("#ffff00"), [ft, Ae] = g(!1), [be, mt] = g(3), [ve, pt] = g(3), [Ge, Ze] = g({}), [I, Qe] = g(!1), [De, Pe] = g(0), [X, ze] = g(!1), [wt, Be] = g(null), [P, ne] = g(null), [W, Ie] = g(null), [ye, le] = g({ x: 0, y: 0 }), [se, He] = g(null), [et, ue] = g(!1), ht = We(null), oe = We(!1), [tt, fe] = g(null), [Bt, rt] = g(!1), [Ct, $e] = g(null), [kt, Oe] = g(!1), [at, jt] = g(null), [F, St] = g(null), [me, nt] = g([]), [lt, pe] = g({ x: 0, y: 0 }), [k, xe] = g({ tableBackground: "#ffffff", tableBorderColor: "#cccccc", tableBorderWidth: "1", tableBorderStyle: "solid", tableAlignment: "left", cellPadding: "8", cellSpacing: "0", cellBackground: "#ffffff", cellTextAlign: "left", cellVerticalAlign: "middle", cellBorderColor: "#cccccc", cellBorderWidth: "1", cellBorderStyle: "solid" }), he = We(null), st = Fe((e) => { he.current && clearTimeout(he.current), he.current = setTimeout(() => { j == null || j(e); }, R); }, [j, R]), we = { wrapper: `editor-wrapper ${M}`, toolbar: "editor-toolbar", contentArea: `editor-content ${te}`, button: "toolbar-btn" }, Me = { wrapper: `${we.wrapper} ${D.wrapper || ""}`, toolbar: `${we.toolbar} ${D.toolbar || ""} ${y ? "editor-toolbar-sticky" : ""}`, contentArea: `${we.contentArea} ${D.contentArea || ""}`, button: `${we.button} ${D.button || ""}` }; Y(() => { if (!y || !Re.current || !qe.current) return; const e = Re.current, n = qe.current; Pe(e.offsetHeight); const r = () => { const i = n.getBoundingClientRect().top <= z; i !== I && Qe(i); }, l = () => { Pe(e.offsetHeight); }; return window.addEventListener("scroll", r), window.addEventListener("resize", l), r(), () => { window.removeEventListener("scroll", r), window.removeEventListener("resize", l); }; }, [y, z, I]); const Ce = () => { const e = window.getSelection(); e.rangeCount > 0 && de(e.getRangeAt(0).cloneRange()); }, ke = () => { if (ut) { const e = window.getSelection(); e.removeAllRanges(), e.addRange(ut); } }, ot = () => { const e = {}; ee.forEach((n) => { switch (n) { case "bold": e.bold = document.queryCommandState("bold"); break; case "italic": e.italic = document.queryCommandState("italic"); break; case "underline": e.underline = document.queryCommandState("underline"); break; case "strikethrough": e.strikethrough = document.queryCommandState("strikeThrough"); break; case "unorderedList": e.unorderedList = document.queryCommandState("insertUnorderedList"); break; case "orderedList": e.orderedList = document.queryCommandState("insertOrderedList"); break; } }), ce(e); }, v = (e, n = null) => { var r; _ || ((r = h.current) == null || r.focus(), document.execCommand(e, !1, n), ot(), q()); }, H = (e, n = null) => { if (!_) switch (e) { case "bold": v("bold"); break; case "italic": v("italic"); break; case "underline": v("underline"); break; case "strikethrough": v("strikeThrough"); break; case "highlight": n ? v("hiliteColor", n) : (ae(!0), Ce()); break; case "fontColor": n ? v("foreColor", n) : (Xe(!0), Ce()); break; case "alignLeft": v("justifyLeft"); break; case "alignCenter": v("justifyCenter"); break; case "alignRight": v("justifyRight"); break; case "alignJustify": v("justifyFull"); break; case "unorderedList": v("insertUnorderedList"); break; case "orderedList": v("insertOrderedList"); break; case "todoList": Tt(); break; case "increaseIndent": v("indent"); break; case "decreaseIndent": v("outdent"); break; case "blockquote": v("formatBlock", "<blockquote>"); break; case "codeBlock": v("formatBlock", "<pre>"); break; case "pageBreak": Rt(); break; case "caseChange": Nt(); break; case "insertTable": Ae(!0), Ce(); break; case "lineSpacing": break; case "link": gt(); break; case "insertImage": rr(); break; } }, gt = () => { const e = window.getSelection(); e.toString() ? (Le(e.toString()), Ce(), Ue(!0)) : alert("Please select text to create a link"); }, Et = () => { Ne && Ve && (ke(), v("createLink", Ne)), Ue(!1), Ye(""), Le(""), de(null); }, Tt = () => { v("insertHTML", ` <ul style="list-style: none; padding-left: 0;"> <li style="margin: 8px 0;"> <input type="checkbox" style="margin-right: 8px;" /> Todo item 1 </li> <li style="margin: 8px 0;"> <input type="checkbox" style="margin-right: 8px;" /> Todo item 2 </li> </ul> `); }, Rt = () => { v("insertHTML", '<div style="page-break-after: always; border-bottom: 2px dashed #ccc; margin: 20px 0; padding-bottom: 20px;"><br></div>'); }, Nt = () => { const e = window.getSelection(); if (e.toString()) { const n = e.toString(); let r; n === n.toUpperCase() ? r = n.toLowerCase() : n === n.toLowerCase() ? r = n.replace( /\w\S*/g, (l) => l.charAt(0).toUpperCase() + l.substr(1).toLowerCase() ) : r = n.toUpperCase(), v("insertText", r); } }, t = (e) => { e === "p" ? v("formatBlock", "<p>") : v("formatBlock", `<${e}>`); }, s = (e) => { v("fontName", e); }, o = (e) => { const n = window.getSelection(), r = n.rangeCount > 0 ? n.getRangeAt(0) : null; if (r && !r.collapsed) { const l = document.createElement("span"); l.style.lineHeight = e.lineHeight, l.style.marginBottom = e.paragraphSpacing, l.style.display = "block"; try { r.surroundContents(l); } catch { const i = r.extractContents(); l.appendChild(i), r.insertNode(l); } } else { const l = h.current; l && (l.style.lineHeight = e.lineHeight, l.querySelectorAll("p, div, h1, h2, h3, h4, h5, h6").forEach((i) => { i.style.marginBottom = e.paragraphSpacing; })); } q(); }, d = (e) => { ke(), v("foreColor", e), Xe(!1), B(e), de(null); }, m = (e) => { ke(), v("hiliteColor", e), ae(!1), Ke(e), de(null); }, b = () => { let n = `<table id="${`table_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`}" class="resizable-table" style="border-collapse: collapse; width: 100%; margin: 10px 0; position: relative;"><tbody>`; for (let r = 0; r < be; r++) { n += "<tr>"; for (let l = 0; l < ve; l++) n += '<td style="border: 1px solid #ccc; padding: 8px; min-width: 100px; min-height: 30px; position: relative;">&nbsp;</td>'; n += "</tr>"; } n += "</tbody></table>", ke(), v("insertHTML", n), Ae(!1), de(null), setTimeout(() => { u(); }, 100); }, u = () => { if (!h.current) return; h.current.querySelectorAll("table").forEach((r) => { r.classList.contains("resizable-table") || (r.classList.add("resizable-table"), r.style.position || (r.style.position = "relative")); }), h.current.querySelectorAll("table.resizable-table").forEach((r) => { r.querySelectorAll(".resize-handle").forEach((x) => x.remove()); const l = document.createElement("div"); l.className = "resize-handle table-resize-handle", l.title = "Drag to resize table", l.addEventListener("mousedown", (x) => f(x, r)), r.appendChild(l); const c = r.querySelector("tr"); if (c) { const x = c.querySelectorAll("td, th"); x.forEach((K, U) => { if (U < x.length - 1) { const p = document.createElement("div"); p.className = "resize-handle column-resize-handle", p.title = "Drag to resize column", p.addEventListener("mousedown", (G) => E(G, r, U)), K.appendChild(p); } }); } const i = r.querySelectorAll("tr"); i.forEach((x, K) => { if (K < i.length - 1) { const U = x.querySelector("td, th"); if (U) { const p = document.createElement("div"); p.className = "resize-handle row-resize-handle", p.title = "Drag to resize row", p.addEventListener("mousedown", (G) => C(G, r, K)), U.appendChild(p); } } }); }); }, f = (e, n) => { e.preventDefault(), e.stopPropagation(); const r = n.getBoundingClientRect(); ze(!0), Be("table"), ne(n), le({ x: e.clientX, y: e.clientY }), He({ width: r.width, height: r.height }), n.classList.add("resizing"), document.body.classList.add("resizing"), document.addEventListener("mousemove", w), document.addEventListener("mouseup", $), document.body.style.cursor = "nw-resize"; }, E = (e, n, r) => { e.preventDefault(), e.stopPropagation(); const l = Array.from(n.querySelectorAll("tr")).map( (c) => c.querySelectorAll("td, th")[r] ).filter(Boolean); ze(!0), Be("column"), ne(n), Ie({ columnIndex: r, cells: l }), le({ x: e.clientX, y: e.clientY }), He({ width: l[0] ? l[0].getBoundingClientRect().width : 100 }), n.classList.add("resizing"), document.body.classList.add("resizing"), document.addEventListener("mousemove", N), document.addEventListener("mouseup", $), document.body.style.cursor = "col-resize"; }, C = (e, n, r) => { e.preventDefault(), e.stopPropagation(); const l = n.querySelectorAll("tr")[r]; l && (ze(!0), Be("row"), ne(n), Ie({ rowIndex: r, row: l }), le({ x: e.clientX, y: e.clientY }), He({ height: l.getBoundingClientRect().height }), n.classList.add("resizing"), document.body.classList.add("resizing"), document.addEventListener("mousemove", J), document.addEventListener("mouseup", $), document.body.style.cursor = "row-resize"); }, w = (e) => { if (!X || !P || !se) return; const n = e.clientX - ye.x, r = e.clientY - ye.y, l = Math.max(200, se.width + n), c = Math.max(100, se.height + r); P.style.width = `${l}px`, P.style.height = `${c}px`, P.style.transform = "scale(1.02)", P.style.transition = "none"; }, N = (e) => { if (!X || !W || !se) return; const n = e.clientX - ye.x, r = Math.max(50, se.width + n); W.cells.forEach((l) => { l && (l.style.width = `${r}px`, l.style.minWidth = `${r}px`, l.style.maxWidth = `${r}px`); }); }, J = (e) => { if (!X || !W || !se) return; const n = e.clientY - ye.y, r = Math.max(30, se.height + n); W.row && (W.row.style.height = `${r}px`, W.row.querySelectorAll("td, th").forEach((c) => { c.style.height = `${r}px`, c.style.minHeight = `${r}px`; })); }, $ = () => { P && (P.classList.remove("resizing"), P.classList.add("resize-complete"), P.style.transform = "", P.style.transition = "", setTimeout(() => { P && P.classList.remove("resize-complete"); }, 600)), document.body.classList.remove("resizing"), ze(!1), Be(null), ne(null), Ie(null), le({ x: 0, y: 0 }), He(null), document.removeEventListener("mousemove", w), document.removeEventListener("mousemove", N), document.removeEventListener("mousemove", J), document.removeEventListener("mouseup", $), document.body.style.cursor = "default", q(); }; Y(() => () => { document.removeEventListener("mousemove", w), document.removeEventListener("mousemove", N), document.removeEventListener("mousemove", J), document.removeEventListener("mouseup", $); }, []), Y(() => { h.current && setTimeout(() => { u(); }, 100); }, [O]); const L = (e) => { const n = document.createElement("div"); return n.innerHTML = e, n.querySelectorAll(".image-resize-wrapper").forEach((i) => { const x = i.querySelector("img"); x && (x.removeAttribute("data-resize-enabled"), x.removeAttribute("data-original-cursor"), x.style.cursor === "pointer" && x.style.removeProperty("cursor"), i.parentNode.insertBefore(x, i)), i.remove(); }), n.querySelectorAll("img").forEach((i) => { i.removeAttribute("data-resize-enabled"), i.removeAttribute("data-original-cursor"), i.style.cursor === "pointer" && i.style.removeProperty("cursor"); }), n.querySelectorAll(".resize-handle").forEach((i) => i.remove()), n.innerHTML; }, q = () => { if (h.current) { const e = h.current.innerHTML; if (oe.current) { st(e); return; } if (e.includes("image-resize-wrapper") || e.includes("resize-handle")) { const r = L(e); st(r); } else st(e); } }, Lt = () => { oe.current = !0, q(), ot(), setTimeout(() => { u(); }, 50), setTimeout(() => { oe.current = !1; }, 100); }, _t = (e) => { if (_) { e.preventDefault(); return; } if (e.key === "Tab") { e.preventDefault(), e.shiftKey ? H("decreaseIndent") : H("increaseIndent"); return; } if (e.ctrlKey || e.metaKey) switch (e.key) { case "b": e.preventDefault(), H("bold"); break; case "i": e.preventDefault(), H("italic"); break; case "u": e.preventDefault(), H("underline"); break; case "l": e.preventDefault(), H("alignLeft"); break; case "e": e.preventDefault(), H("alignCenter"); break; case "r": e.preventDefault(), H("alignRight"); break; case "j": e.preventDefault(), H("alignJustify"); break; case "1": e.preventDefault(), o(bt[0]); break; case "2": e.preventDefault(), o(bt[3]); break; case "5": e.preventDefault(), o(bt[2]); break; } }; Y(() => { if (h.current && O !== h.current.innerHTML) { const e = oe.current; oe.current = !1, h.current.innerHTML = O, oe.current = e; } }, [O]), Y(() => { const e = () => { document.activeElement === h.current && ot(); }; return document.addEventListener("selectionchange", e), () => document.removeEventListener("selectionchange", e); }, []), Y(() => () => { he.current && clearTimeout(he.current); }, []), Y(() => { const e = (n) => { if (!Object.values(Ge).some((i) => i)) return; const l = document.querySelectorAll(".dropdown-container"); let c = !0; l.forEach((i) => { i.contains(n.target) && (c = !1); }), c && Ze({}); }; return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e); }, [Ge]), Y(() => { const e = (r) => { X || Qt(r); }, n = (r) => { const l = document.querySelector(".table-style-menu"), c = l && l.contains(r.target), i = r.target.closest("table.resizable-table"); !c && !i && Oe(!1); }; return h.current && h.current.addEventListener("click", e), document.addEventListener("click", n), () => { h.current && h.current.removeEventListener("click", e), document.removeEventListener("click", n); }; }, [X]); const Wt = { bold: { label: "B", title: "Bold (Ctrl+B)", className: "font-bold" }, italic: { label: "I", title: "Italic (Ctrl+I)", className: "italic" }, underline: { label: "U", title: "Underline (Ctrl+U)", className: "underline" }, strikethrough: { label: "S", title: "Strikethrough", className: "line-through" }, highlight: { label: "🖍️", title: "Highlight Text", className: "" }, fontColor: { label: "🎨", title: "Font Color", className: "" }, headings: { label: "H", title: "Headings", className: "font-bold", isDropdown: !0 }, fontFamily: { label: "Font", title: "Font Family", className: "", isDropdown: !0 }, lineSpacing: { label: "⫽", title: "Line & Paragraph Spacing (Ctrl+1/2/5)", className: "", isDropdown: !0 }, alignLeft: { label: "⬅️", title: "Align Left", className: "" }, alignCenter: { label: "⬆️", title: "Align Center", className: "" }, alignRight: { label: "➡️", title: "Align Right", className: "" }, alignJustify: { label: "↔️", title: "Justify", className: "" }, unorderedList: { label: "•", title: "Bullet List", className: "" }, orderedList: { label: "1.", title: "Numbered List", className: "" }, todoList: { label: "☑️", title: "Todo List", className: "" }, increaseIndent: { label: "→", title: "Increase Indent", className: "" }, decreaseIndent: { label: "←", title: "Decrease Indent", className: "" }, link: { label: "🔗", title: "Insert Link", className: "" }, insertImage: { label: "🖼️", title: "Insert Image", className: "" }, blockquote: { label: "❝", title: "Quote", className: "" }, codeBlock: { label: "<>", title: "Code Block", className: "font-mono" }, pageBreak: { label: "📄", title: "Page Break", className: "" }, caseChange: { label: "Aa", title: "Change Case", className: "" }, insertTable: { label: "⊞", title: "Insert Table", className: "" } }, Ft = [ { value: "p", label: "Normal" }, { value: "h1", label: "Heading 1" }, { value: "h2", label: "Heading 2" }, { value: "h3", label: "Heading 3" }, { value: "h4", label: "Heading 4" }, { value: "h5", label: "Heading 5" }, { value: "h6", label: "Heading 6" } ], qt = [ { value: "Arial", label: "Arial" }, { value: "Georgia", label: "Georgia" }, { value: "Times New Roman", label: "Times New Roman" }, { value: "Courier New", label: "Courier New" }, { value: "Verdana", label: "Verdana" }, { value: "Helvetica", label: "Helvetica" } ], bt = [ { value: "1.0", label: "Single (1.0)", lineHeight: "1.0", paragraphSpacing: "0" }, { value: "1.15", label: "1.15", lineHeight: "1.15", paragraphSpacing: "0.2em" }, { value: "1.5", label: "1.5", lineHeight: "1.5", paragraphSpacing: "0.5em" }, { value: "2.0", label: "Double (2.0)", lineHeight: "2.0", paragraphSpacing: "1em" }, { value: "2.5", label: "2.5", lineHeight: "2.5", paragraphSpacing: "1.2em" }, { value: "3.0", label: "Triple (3.0)", lineHeight: "3.0", paragraphSpacing: "1.5em" } ], Ut = [ "#000000", "#333333", "#666666", "#999999", "#cccccc", "#ffffff", "#ff0000", "#ff9900", "#ffff00", "#00ff00", "#0099ff", "#6600ff", "#ff00ff", "#ff3366", "#33ff99", "#3366ff", "#9933ff", "#ff6633" ], Yt = [ "#ffff00", "#ffcc00", "#ff9900", "#ff6600", "#ff3300", "#ff0066", "#ff00cc", "#cc00ff", "#6600ff", "#0066ff", "#00ccff", "#00ffcc", "#00ff66", "#66ff00", "#ccff00", "#ffff66", "#ffcccc", "#ccffcc" ], Vt = (e) => { const n = Wt[e]; if (!n) return null; if (n.isDropdown) return Xt(e, n); const r = yt[e], l = `${Me.button} ${n.className} ${r ? "toolbar-btn-active" : ""}`; return /* @__PURE__ */ a.jsx( "button", { type: "button", className: l, title: n.title, onClick: () => H(e), disabled: _, children: n.label }, e ); }, Xt = (e, n) => { const r = Ge[e] || !1, l = () => { Ze((i) => ({ ...i, [e]: !r })); }, c = () => { Ze((i) => ({ ...i, [e]: !1 })); }; return /* @__PURE__ */ a.jsxs("div", { className: "dropdown-container", children: [ /* @__PURE__ */ a.jsxs( "button", { type: "button", className: `dropdown-trigger ${r ? "active" : ""}`, title: n.title, onClick: l, disabled: _, children: [ /* @__PURE__ */ a.jsx("span", { children: n.label }), /* @__PURE__ */ a.jsx("span", { className: "dropdown-arrow", children: "▼" }) ] } ), r && /* @__PURE__ */ a.jsxs("div", { className: "dropdown-menu", children: [ e === "headings" && Ft.map((i) => /* @__PURE__ */ a.jsx( "button", { type: "button", className: "dropdown-item", onClick: () => { t(i.value), c(); }, style: { fontFamily: (i.value === "h1", "inherit"), fontSize: i.value === "h1" ? "1.1rem" : i.value === "h2" ? "1.05rem" : i.value === "h3" ? "1rem" : "0.875rem", fontWeight: i.value.startsWith("h") ? "600" : "400" }, children: i.label }, i.value )), e === "fontFamily" && qt.map((i) => /* @__PURE__ */ a.jsx( "button", { type: "button", className: "dropdown-item font-preview", style: { "--font-family": i.value, fontFamily: i.value }, onClick: () => { s(i.value), c(); }, children: i.label }, i.value )), e === "lineSpacing" && bt.map((i) => /* @__PURE__ */ a.jsx( "button", { type: "button", className: "dropdown-item", onClick: () => { o(i), c(); }, children: /* @__PURE__ */ a.jsxs("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between" }, children: [ /* @__PURE__ */ a.jsx("span", { children: i.label }), /* @__PURE__ */ a.jsx("span", { style: { fontSize: "0.75rem", opacity: 0.6 }, children: i.lineHeight }) ] }) }, i.value )) ] }) ] }, e); }, It = () => /* @__PURE__ */ a.jsx( "div", { ref: Re, className: Me.toolbar, style: { position: y && I ? "fixed" : "relative", top: y && I ? `${z}px` : "auto", left: y && I ? "0" : "auto", right: y && I ? "0" : "auto", zIndex: y && I ? "1000" : "auto", width: y && I ? "100%" : "auto", transition: "all 0.2s cubic-bezier(0.4, 0, 0.2, 1)" }, children: ee.map((e) => Vt(e)) } ), Jt = () => S ? /* @__PURE__ */ a.jsx("div", { className: "modal-backdrop", children: /* @__PURE__ */ a.jsxs("div", { className: "compact-modal", children: [ /* @__PURE__ */ a.jsx("h3", { children: "🔗 Insert Link" }), /* @__PURE__ */ a.jsxs("div", { className: "compact-form", children: [ /* @__PURE__ */ a.jsx( "input", { type: "text", value: Ve, onChange: (e) => Le(e.target.value), className: "compact-input", placeholder: "Link text", autoFocus: !0 } ), /* @__PURE__ */ a.jsx( "input", { type: "url", value: Ne, onChange: (e) => Ye(e.target.value), className: "compact-input", placeholder: "https://example.com" } ) ] }), /* @__PURE__ */ a.jsxs("div", { className: "compact-actions", children: [ /* @__PURE__ */ a.jsx( "button", { type: "button", onClick: () => { Ue(!1), Ye(""), Le(""); }, className: "btn-compact-secondary", children: "Cancel" } ), /* @__PURE__ */ a.jsx( "button", { type: "button", onClick: Et, className: "btn-compact-primary", disabled: !Ne || !Ve, children: "Insert" } ) ] }) ] }) }) : null, Kt = () => xt ? /* @__PURE__ */ a.jsx("div", { className: "modal-backdrop", children: /* @__PURE__ */ a.jsxs("div", { className: "compact-modal color-modal", children: [ /* @__PURE__ */ a.jsx("h3", { children: "🎨 Text Color" }), /* @__PURE__ */ a.jsxs("div", { className: "compact-color-section", children: [ /* @__PURE__ */ a.jsx("div", { className: "compact-color-grid", children: Ut.slice(0, 12).map((e) => /* @__PURE__ */ a.jsx( "button", { type: "button", className: `compact-color-btn ${_e === e ? "selected" : ""}`, style: { backgroundColor: e }, onClick: () => d(e), title: e }, e )) }), /* @__PURE__ */ a.jsxs("div", { className: "compact-custom-color", children: [ /* @__PURE__ */ a.jsx( "input", { type: "color", value: _e, onChange: (e) => B(e.target.value), className: "compact-color-input" } ), /* @__PURE__ */ a.jsx( "button", { type: "button", onClick: () => d(_e), className: "btn-compact-accent", children: "Custom" } ) ] }) ] }), /* @__PURE__ */ a.jsx("div", { className: "compact-actions", children: /* @__PURE__ */ a.jsx( "button", { type: "button", onClick: () => Xe(!1), className: "btn-compact-secondary", children: "Cancel" } ) }) ] }) }) : null, Gt = () => re ? /* @__PURE__ */ a.jsx("div", { className: "modal-backdrop", children: /* @__PURE__ */ a.jsxs("div", { className: "compact-modal color-modal", children: [ /* @__PURE__ */ a.jsx("h3", { children: "🖍️ Highlight" }), /* @__PURE__ */ a.jsxs("div", { className: "compact-color-section", children: [ /* @__PURE__ */ a.jsx("div", { className: "compact-color-grid", children: Yt.slice(0, 12).map((e) => /* @__PURE__ */ a.jsx( "button", { type: "button", className: `compact-color-btn ${Je === e ? "selected" : ""}`, style: { backgroundColor: e }, onClick: () => m(e), title: e }, e )) }), /* @__PURE__ */ a.jsxs("div", { className: "compact-custom-color", children: [ /* @__PURE__ */ a.jsx(