digi-mathchem-editor 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import e, { useState as W, useEffect as O, useMemo as we, useRef as
|
|
2
|
-
import { createPortal as
|
|
1
|
+
import e, { useState as W, useEffect as O, useMemo as we, useRef as te, useCallback as ce } from "react";
|
|
2
|
+
import { createPortal as le } from "react-dom";
|
|
3
3
|
import { FontAwesomeIcon as ie } from "@fortawesome/react-fontawesome";
|
|
4
4
|
import { faBold as fe, faItalic as ve } from "@fortawesome/free-solid-svg-icons";
|
|
5
5
|
import { MathfieldElement as xe } from "mathlive";
|
|
@@ -3752,15 +3752,15 @@ function Ge({ matrixType: l, x: o, y: n, onSelect: s, onMouseEnter: r, onMouseLe
|
|
|
3752
3752
|
onMouseLeave: h
|
|
3753
3753
|
},
|
|
3754
3754
|
/* @__PURE__ */ e.createElement("div", { className: "cme-matrix-hover-grid" }, Array.from({ length: x }).map((p, f) => /* @__PURE__ */ e.createElement("div", { key: f, className: "cme-matrix-hover-row" }, Array.from({ length: B }).map((C, M) => {
|
|
3755
|
-
const P = parseInt(m.r, 10) || 0,
|
|
3755
|
+
const P = parseInt(m.r, 10) || 0, Q = parseInt(m.c, 10) || 0, J = f < P && M < Q;
|
|
3756
3756
|
return /* @__PURE__ */ e.createElement(
|
|
3757
3757
|
"div",
|
|
3758
3758
|
{
|
|
3759
3759
|
key: `${f}-${M}`,
|
|
3760
3760
|
className: `cme-matrix-hover-cell${J ? " selected" : ""}`,
|
|
3761
3761
|
onMouseEnter: () => k({ r: f + 1, c: M + 1 }),
|
|
3762
|
-
onClick: (
|
|
3763
|
-
|
|
3762
|
+
onClick: (X) => {
|
|
3763
|
+
X.preventDefault(), X.stopPropagation(), s(f + 1, M + 1);
|
|
3764
3764
|
}
|
|
3765
3765
|
}
|
|
3766
3766
|
);
|
|
@@ -3804,9 +3804,9 @@ function Ge({ matrixType: l, x: o, y: n, onSelect: s, onMouseEnter: r, onMouseLe
|
|
|
3804
3804
|
}
|
|
3805
3805
|
let Z = !1, de = null, U = null;
|
|
3806
3806
|
function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: r }) {
|
|
3807
|
-
const h =
|
|
3808
|
-
|
|
3809
|
-
const [C, M] = W({ x: 0, y: 0 }), [P,
|
|
3807
|
+
const h = te(null), [m, k] = W(0), [x, B] = W(null), [E, D] = W(null), [g, y] = W(null), [p, f] = W(null);
|
|
3808
|
+
te(null);
|
|
3809
|
+
const [C, M] = W({ x: 0, y: 0 }), [P, Q] = W(!1), J = te({ x: 0, y: 0 }), [X, be] = W(!1), [Te, ge] = W(!1), [We, K] = W(!1), oe = te(null);
|
|
3810
3810
|
O(() => {
|
|
3811
3811
|
const t = (a) => {
|
|
3812
3812
|
if (!P) return;
|
|
@@ -3816,14 +3816,14 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: r })
|
|
|
3816
3816
|
d < c && (d = c), d > T && (d = T), b < L && (b = L), b > R && (b = R);
|
|
3817
3817
|
}
|
|
3818
3818
|
M({ x: d, y: b });
|
|
3819
|
-
}, i = () =>
|
|
3819
|
+
}, i = () => Q(!1);
|
|
3820
3820
|
return P && (window.addEventListener("mousemove", t), window.addEventListener("mouseup", i)), () => {
|
|
3821
3821
|
window.removeEventListener("mousemove", t), window.removeEventListener("mouseup", i);
|
|
3822
3822
|
};
|
|
3823
3823
|
}, [P]);
|
|
3824
3824
|
const Ie = (t) => {
|
|
3825
3825
|
if (t.target.closest(".cme-popup-controls")) return;
|
|
3826
|
-
|
|
3826
|
+
Q(!0), J.current = {
|
|
3827
3827
|
x: t.clientX - C.x,
|
|
3828
3828
|
y: t.clientY - C.y
|
|
3829
3829
|
};
|
|
@@ -3945,8 +3945,8 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: r })
|
|
|
3945
3945
|
let R = L;
|
|
3946
3946
|
const z = u.fontSize === "auto" ? 5 : parseInt(u.fontSize, 10);
|
|
3947
3947
|
if (z !== 5) {
|
|
3948
|
-
const
|
|
3949
|
-
|
|
3948
|
+
const Y = { 1: "\\tiny", 2: "\\scriptsize", 3: "\\footnotesize", 4: "\\small", 5: "\\normalsize", 6: "\\large", 7: "\\Large", 8: "\\LARGE", 9: "\\huge", 10: "\\Huge" };
|
|
3949
|
+
Y[z] && (R = `{${Y[z]} ${R}}`);
|
|
3950
3950
|
}
|
|
3951
3951
|
u.color !== "none" && (R = `\\textcolor{${u.color}}{${R}}`), t.executeCommand(["insert", R]);
|
|
3952
3952
|
return;
|
|
@@ -4000,7 +4000,7 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: r })
|
|
|
4000
4000
|
return;
|
|
4001
4001
|
}
|
|
4002
4002
|
const a = i.getValue ? i.getValue("latex") : i.value, d = s || "";
|
|
4003
|
-
!a || a.trim() === "" || a === d ? n && n() :
|
|
4003
|
+
!a || a.trim() === "" || a === d ? n && n() : K(!0);
|
|
4004
4004
|
}, Re = () => {
|
|
4005
4005
|
const t = U;
|
|
4006
4006
|
if (!t) return;
|
|
@@ -4014,7 +4014,7 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: r })
|
|
|
4014
4014
|
return /* @__PURE__ */ e.createElement(
|
|
4015
4015
|
"div",
|
|
4016
4016
|
{
|
|
4017
|
-
className: `cme-editor-popup ${
|
|
4017
|
+
className: `cme-editor-popup ${X ? "maximized" : ""} ${Te ? "minimized" : ""}`,
|
|
4018
4018
|
style: { transform: `translate(${C.x}px, ${C.y}px)` },
|
|
4019
4019
|
onMouseDown: (t) => t.stopPropagation()
|
|
4020
4020
|
},
|
|
@@ -4105,13 +4105,13 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: r })
|
|
|
4105
4105
|
b.items.map((c, T) => {
|
|
4106
4106
|
const L = q[m];
|
|
4107
4107
|
if (c.type === "dropdown") {
|
|
4108
|
-
const N = c.label === "Font...", v = c.label === "Size",
|
|
4108
|
+
const N = c.label === "Font...", v = c.label === "Size", _ = N && u.fontFamily !== "none", G = v && u.fontSize !== "auto" && u.fontSize !== "5", $ = N ? u.fontFamily === "none" ? "" : u.fontFamily : v ? u.fontSize === "auto" || u.fontSize === "5" ? "" : u.fontSize : "";
|
|
4109
4109
|
return /* @__PURE__ */ e.createElement(
|
|
4110
4110
|
"select",
|
|
4111
4111
|
{
|
|
4112
4112
|
key: T,
|
|
4113
|
-
className: `cme-btn template${
|
|
4114
|
-
value:
|
|
4113
|
+
className: `cme-btn template${_ || G ? " active" : ""}`,
|
|
4114
|
+
value: $,
|
|
4115
4115
|
style: {
|
|
4116
4116
|
width: c.width || "60px",
|
|
4117
4117
|
height: "18px",
|
|
@@ -4125,8 +4125,8 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: r })
|
|
|
4125
4125
|
margin: "2px 0",
|
|
4126
4126
|
gridColumn: b.cols === 3 || b.cols === 1 ? "span 1" : "span 2"
|
|
4127
4127
|
},
|
|
4128
|
-
onChange: (
|
|
4129
|
-
const F =
|
|
4128
|
+
onChange: (ee) => {
|
|
4129
|
+
const F = ee.target.value, H = U;
|
|
4130
4130
|
!H || typeof H.applyStyle != "function" || (H.focus(), N ? H.applyStyle({ fontFamily: F || "none" }) : v && H.applyStyle({ fontSize: F ? parseInt(F, 10) : "auto" }), V());
|
|
4131
4131
|
}
|
|
4132
4132
|
},
|
|
@@ -4185,7 +4185,7 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: r })
|
|
|
4185
4185
|
)
|
|
4186
4186
|
)
|
|
4187
4187
|
);
|
|
4188
|
-
const R = c.action === "BOLD", z = c.action === "ITALIC",
|
|
4188
|
+
const R = c.action === "BOLD", z = c.action === "ITALIC", Y = c.action === "TEXT_COLOR", Oe = R && u.bold || z && u.italic || Y && u.color !== "none" && u.color !== "black";
|
|
4189
4189
|
return /* @__PURE__ */ e.createElement(
|
|
4190
4190
|
"button",
|
|
4191
4191
|
{
|
|
@@ -4194,7 +4194,7 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: r })
|
|
|
4194
4194
|
className: `cme-btn${L.isTemplate ? " template" : ""}${c.cls ? ` ${c.cls}` : ""}${Oe ? " active" : ""}`,
|
|
4195
4195
|
title: c.title || c.label || c.insert,
|
|
4196
4196
|
onMouseDown: (N) => {
|
|
4197
|
-
var G, $, ee,
|
|
4197
|
+
var _, G, $, ee, F, H, ue;
|
|
4198
4198
|
N.preventDefault();
|
|
4199
4199
|
const v = h.current;
|
|
4200
4200
|
if (c.action === "SPECIAL_CHARS") {
|
|
@@ -4227,7 +4227,7 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: r })
|
|
|
4227
4227
|
}
|
|
4228
4228
|
se((S) => ({ ...S, italic: A }));
|
|
4229
4229
|
}
|
|
4230
|
-
} else c.action === "UNDO" ? (
|
|
4230
|
+
} else c.action === "UNDO" ? (_ = h.current) == null || _.executeCommand("undo") : c.action === "REDO" ? (G = h.current) == null || G.executeCommand("redo") : c.action === "CUT" ? (($ = h.current) == null || $.focus(), (ee = h.current) == null || ee.executeCommand("cutToClipboard")) : c.action === "COPY" ? ((F = h.current) == null || F.focus(), (H = h.current) == null || H.executeCommand("copyToClipboard")) : c.action === "PASTE" ? ((ue = h.current) == null || ue.focus(), navigator.clipboard.readText().then((A) => {
|
|
4231
4231
|
var I;
|
|
4232
4232
|
(I = h.current) == null || I.executeCommand(["insert", A]);
|
|
4233
4233
|
}).catch((A) => {
|
|
@@ -4261,7 +4261,7 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: r })
|
|
|
4261
4261
|
})
|
|
4262
4262
|
));
|
|
4263
4263
|
})())),
|
|
4264
|
-
p &&
|
|
4264
|
+
p && le(/* @__PURE__ */ e.createElement(
|
|
4265
4265
|
"div",
|
|
4266
4266
|
{
|
|
4267
4267
|
ref: (t) => {
|
|
@@ -4345,17 +4345,14 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: r })
|
|
|
4345
4345
|
)
|
|
4346
4346
|
),
|
|
4347
4347
|
/* @__PURE__ */ e.createElement("div", { className: "cme-popup-footer" }, /* @__PURE__ */ e.createElement("button", { type: "button", className: "cme-insert-btn", onClick: Re }, r ? "Update" : "Insert"), /* @__PURE__ */ e.createElement("button", { type: "button", className: "cme-cancel-btn", onClick: ke }, "Cancel")),
|
|
4348
|
-
We &&
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
document.body
|
|
4357
|
-
),
|
|
4358
|
-
x && Q(
|
|
4348
|
+
We && /* @__PURE__ */ e.createElement("div", { className: "cme-confirm-overlay", onMouseDown: (t) => {
|
|
4349
|
+
t.stopPropagation(), K(!1);
|
|
4350
|
+
} }, /* @__PURE__ */ e.createElement("div", { className: "cme-confirm-modal", onMouseDown: (t) => t.stopPropagation() }, /* @__PURE__ */ e.createElement("p", null, "Are you sure you want to leave? The changes you made will be lost."), /* @__PURE__ */ e.createElement("div", { className: "cme-confirm-actions" }, /* @__PURE__ */ e.createElement("button", { type: "button", className: "cme-confirm-close-btn", onClick: (t) => {
|
|
4351
|
+
t.stopPropagation(), K(!1), n && n();
|
|
4352
|
+
} }, "Close"), /* @__PURE__ */ e.createElement("button", { type: "button", className: "cme-confirm-cancel-btn", onClick: (t) => {
|
|
4353
|
+
t.stopPropagation(), K(!1);
|
|
4354
|
+
} }, "Cancel")))),
|
|
4355
|
+
x && le(
|
|
4359
4356
|
/* @__PURE__ */ e.createElement(
|
|
4360
4357
|
Ge,
|
|
4361
4358
|
{
|
|
@@ -4373,7 +4370,7 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: r })
|
|
|
4373
4370
|
),
|
|
4374
4371
|
document.body
|
|
4375
4372
|
),
|
|
4376
|
-
E &&
|
|
4373
|
+
E && le(
|
|
4377
4374
|
/* @__PURE__ */ e.createElement(
|
|
4378
4375
|
je,
|
|
4379
4376
|
{
|
|
@@ -4387,7 +4384,7 @@ function $e({ mode: l, onInsert: o, onClose: n, initialLatex: s, isEditing: r })
|
|
|
4387
4384
|
),
|
|
4388
4385
|
document.body
|
|
4389
4386
|
),
|
|
4390
|
-
g &&
|
|
4387
|
+
g && le(
|
|
4391
4388
|
/* @__PURE__ */ e.createElement(
|
|
4392
4389
|
"div",
|
|
4393
4390
|
{
|