tiptap-markdown-react 0.8.1 → 0.8.2
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.
- package/dist/components/MathEditorPopover.d.ts +1 -1
- package/dist/{extractToc-C0E_xYTj.js → extractToc-CMvSKha8.js} +3 -3
- package/dist/{extractToc-C0E_xYTj.js.map → extractToc-CMvSKha8.js.map} +1 -1
- package/dist/index.js +150 -139
- package/dist/index.js.map +1 -1
- package/dist/server.js +2 -2
- package/dist/style.css +97 -107
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,8 +6,8 @@ import Image from "@tiptap/extension-image";
|
|
|
6
6
|
import { TableOfContents } from "@tiptap/extension-table-of-contents";
|
|
7
7
|
import { NodeViewWrapper, ReactNodeViewRenderer, NodeViewContent, useEditor, EditorContent, useEditorState } from "@tiptap/react";
|
|
8
8
|
import { forwardRef, useEffect, useRef, useImperativeHandle, useMemo, useState, useId, useCallback, useContext, createContext } from "react";
|
|
9
|
-
import { C as CitationRef, m as mergeCommentIntervals, a as mapCommentAnchors, e as enrichMarkdownCitations, s as styles$5, b as baseExtensions, c as CommentMark, l as lowlight, d as makeTocGetId, p as pureCodeBlock, f as pureImage, r as renderMathHtml, g as subscribeMathClick, R as ReportContent } from "./extractToc-
|
|
10
|
-
import { h, i, j } from "./extractToc-
|
|
9
|
+
import { C as CitationRef, m as mergeCommentIntervals, a as mapCommentAnchors, e as enrichMarkdownCitations, s as styles$5, b as baseExtensions, c as CommentMark, l as lowlight, d as makeTocGetId, p as pureCodeBlock, f as pureImage, r as renderMathHtml, g as subscribeMathClick, R as ReportContent } from "./extractToc-CMvSKha8.js";
|
|
10
|
+
import { h, i, j } from "./extractToc-CMvSKha8.js";
|
|
11
11
|
import { Slice, Fragment } from "@tiptap/pm/model";
|
|
12
12
|
import { Extension } from "@tiptap/core";
|
|
13
13
|
import { PluginKey, Plugin } from "@tiptap/pm/state";
|
|
@@ -981,42 +981,41 @@ function insertMarkdown(editor, markdown, sources = []) {
|
|
|
981
981
|
const prepared = enrichMarkdownCitations(markdown, sources);
|
|
982
982
|
editor.chain().focus().insertContent(prepared, { contentType: "markdown" }).run();
|
|
983
983
|
}
|
|
984
|
-
const toolbar = "
|
|
985
|
-
const inner = "
|
|
986
|
-
const btn = "
|
|
987
|
-
const btnActive = "
|
|
988
|
-
const tableBubble = "
|
|
989
|
-
const txtIcon = "
|
|
990
|
-
const colorIcon = "
|
|
991
|
-
const colorIconGlyph = "
|
|
992
|
-
const colorIconBar = "
|
|
993
|
-
const scriptTrigger = "
|
|
994
|
-
const scriptTriggerGlyph = "
|
|
995
|
-
const divider = "
|
|
996
|
-
const styleTrigger = "
|
|
997
|
-
const styleTriggerLabel = "
|
|
998
|
-
const styleTriggerCaret = "
|
|
999
|
-
const styleItem = "
|
|
1000
|
-
const styleIcon = "
|
|
1001
|
-
const scriptGlyph = "
|
|
1002
|
-
const menu = "
|
|
1003
|
-
const menuItem = "
|
|
1004
|
-
const menuItemSelected = "
|
|
1005
|
-
const popoverContent$1 = "
|
|
1006
|
-
const
|
|
1007
|
-
const
|
|
1008
|
-
const
|
|
1009
|
-
const
|
|
1010
|
-
const
|
|
1011
|
-
const
|
|
1012
|
-
const
|
|
1013
|
-
const
|
|
1014
|
-
const
|
|
1015
|
-
const
|
|
1016
|
-
const
|
|
1017
|
-
const
|
|
1018
|
-
const
|
|
1019
|
-
const mathDoneKbd = "_mathDoneKbd_z6tes_409";
|
|
984
|
+
const toolbar = "_toolbar_16b09_2";
|
|
985
|
+
const inner = "_inner_16b09_15";
|
|
986
|
+
const btn = "_btn_16b09_27";
|
|
987
|
+
const btnActive = "_btnActive_16b09_50";
|
|
988
|
+
const tableBubble = "_tableBubble_16b09_66";
|
|
989
|
+
const txtIcon = "_txtIcon_16b09_78";
|
|
990
|
+
const colorIcon = "_colorIcon_16b09_86";
|
|
991
|
+
const colorIconGlyph = "_colorIconGlyph_16b09_94";
|
|
992
|
+
const colorIconBar = "_colorIconBar_16b09_100";
|
|
993
|
+
const scriptTrigger = "_scriptTrigger_16b09_107";
|
|
994
|
+
const scriptTriggerGlyph = "_scriptTriggerGlyph_16b09_127";
|
|
995
|
+
const divider = "_divider_16b09_135";
|
|
996
|
+
const styleTrigger = "_styleTrigger_16b09_144";
|
|
997
|
+
const styleTriggerLabel = "_styleTriggerLabel_16b09_173";
|
|
998
|
+
const styleTriggerCaret = "_styleTriggerCaret_16b09_181";
|
|
999
|
+
const styleItem = "_styleItem_16b09_187";
|
|
1000
|
+
const styleIcon = "_styleIcon_16b09_193";
|
|
1001
|
+
const scriptGlyph = "_scriptGlyph_16b09_203";
|
|
1002
|
+
const menu = "_menu_16b09_215";
|
|
1003
|
+
const menuItem = "_menuItem_16b09_226";
|
|
1004
|
+
const menuItemSelected = "_menuItemSelected_16b09_252";
|
|
1005
|
+
const popoverContent$1 = "_popoverContent_16b09_266";
|
|
1006
|
+
const mathLayer = "_mathLayer_16b09_270";
|
|
1007
|
+
const mathStack = "_mathStack_16b09_275";
|
|
1008
|
+
const mathStackBlock = "_mathStackBlock_16b09_282";
|
|
1009
|
+
const mathHint = "_mathHint_16b09_287";
|
|
1010
|
+
const mathHintBlock = "_mathHintBlock_16b09_299";
|
|
1011
|
+
const mathHintIcon = "_mathHintIcon_16b09_305";
|
|
1012
|
+
const mathPreviewInline = "_mathPreviewInline_16b09_311";
|
|
1013
|
+
const mathPreviewBlock = "_mathPreviewBlock_16b09_321";
|
|
1014
|
+
const mathField = "_mathField_16b09_336";
|
|
1015
|
+
const mathFieldBlock = "_mathFieldBlock_16b09_348";
|
|
1016
|
+
const mathInput = "_mathInput_16b09_355";
|
|
1017
|
+
const mathDone = "_mathDone_16b09_373";
|
|
1018
|
+
const mathDoneKbd = "_mathDoneKbd_16b09_398";
|
|
1020
1019
|
const styles$3 = {
|
|
1021
1020
|
toolbar,
|
|
1022
1021
|
inner,
|
|
@@ -1040,8 +1039,7 @@ const styles$3 = {
|
|
|
1040
1039
|
menuItem,
|
|
1041
1040
|
menuItemSelected,
|
|
1042
1041
|
popoverContent: popoverContent$1,
|
|
1043
|
-
|
|
1044
|
-
mathContent,
|
|
1042
|
+
mathLayer,
|
|
1045
1043
|
mathStack,
|
|
1046
1044
|
mathStackBlock,
|
|
1047
1045
|
mathHint,
|
|
@@ -1130,24 +1128,48 @@ function ColorPalette({ value, onPick, labels }) {
|
|
|
1130
1128
|
)) })
|
|
1131
1129
|
] });
|
|
1132
1130
|
}
|
|
1133
|
-
function
|
|
1131
|
+
function resolveNodeEl(editor, pos) {
|
|
1132
|
+
const dom = editor.view.nodeDOM(pos);
|
|
1133
|
+
if (dom instanceof HTMLElement) return dom;
|
|
1134
|
+
if (dom instanceof Node) return dom.parentElement;
|
|
1135
|
+
return null;
|
|
1136
|
+
}
|
|
1137
|
+
function getMathLayerStyle(editor, kind, mode, pos) {
|
|
1138
|
+
const host = editor.view.dom.parentElement;
|
|
1139
|
+
if (!host) return {};
|
|
1140
|
+
const hostRect = host.getBoundingClientRect();
|
|
1134
1141
|
const editorRect = editor.view.dom.getBoundingClientRect();
|
|
1142
|
+
const gap = mode === "edit" ? 0 : 6;
|
|
1143
|
+
const blockWidth = editor.view.dom.clientWidth;
|
|
1135
1144
|
if (pos != null) {
|
|
1136
|
-
const
|
|
1137
|
-
const el = dom instanceof HTMLElement ? dom : dom instanceof Node ? dom.parentElement : null;
|
|
1145
|
+
const el = resolveNodeEl(editor, pos);
|
|
1138
1146
|
if (el) {
|
|
1139
1147
|
const r = el.getBoundingClientRect();
|
|
1140
1148
|
if (kind === "block") {
|
|
1141
|
-
return
|
|
1149
|
+
return {
|
|
1150
|
+
left: editorRect.left - hostRect.left,
|
|
1151
|
+
top: r.top - hostRect.top + gap,
|
|
1152
|
+
width: blockWidth
|
|
1153
|
+
};
|
|
1142
1154
|
}
|
|
1143
|
-
return
|
|
1155
|
+
return {
|
|
1156
|
+
left: r.left - hostRect.left,
|
|
1157
|
+
top: r.top - hostRect.top + gap
|
|
1158
|
+
};
|
|
1144
1159
|
}
|
|
1145
1160
|
}
|
|
1146
1161
|
const coords = editor.view.coordsAtPos(editor.state.selection.from);
|
|
1147
1162
|
if (kind === "block") {
|
|
1148
|
-
return
|
|
1163
|
+
return {
|
|
1164
|
+
left: editorRect.left - hostRect.left,
|
|
1165
|
+
top: coords.bottom - hostRect.top + gap,
|
|
1166
|
+
width: blockWidth
|
|
1167
|
+
};
|
|
1149
1168
|
}
|
|
1150
|
-
return
|
|
1169
|
+
return {
|
|
1170
|
+
left: coords.left - hostRect.left,
|
|
1171
|
+
top: coords.bottom - hostRect.top + gap
|
|
1172
|
+
};
|
|
1151
1173
|
}
|
|
1152
1174
|
function MathEditorPopover({
|
|
1153
1175
|
editor,
|
|
@@ -1162,38 +1184,47 @@ function MathEditorPopover({
|
|
|
1162
1184
|
onCancel
|
|
1163
1185
|
}) {
|
|
1164
1186
|
const [draft, setDraft] = useState(latex);
|
|
1165
|
-
const [
|
|
1187
|
+
const [layerStyle, setLayerStyle] = useState(
|
|
1188
|
+
() => getMathLayerStyle(editor, kind, mode, pos)
|
|
1189
|
+
);
|
|
1166
1190
|
const titleId = useId();
|
|
1167
1191
|
const inputRef = useRef(null);
|
|
1168
|
-
const
|
|
1192
|
+
const rootRef = useRef(null);
|
|
1169
1193
|
const isBlock = kind === "block";
|
|
1194
|
+
const host = editor.view.dom.parentElement;
|
|
1170
1195
|
useEffect(() => {
|
|
1171
1196
|
setDraft(latex);
|
|
1172
1197
|
}, [latex]);
|
|
1173
1198
|
useEffect(() => {
|
|
1174
|
-
const update = () =>
|
|
1199
|
+
const update = () => setLayerStyle(getMathLayerStyle(editor, kind, mode, pos));
|
|
1175
1200
|
update();
|
|
1176
1201
|
window.addEventListener("resize", update);
|
|
1177
|
-
window.
|
|
1178
|
-
|
|
1179
|
-
window.removeEventListener("resize", update);
|
|
1180
|
-
window.removeEventListener("scroll", update, true);
|
|
1181
|
-
};
|
|
1182
|
-
}, [editor, kind, pos]);
|
|
1202
|
+
return () => window.removeEventListener("resize", update);
|
|
1203
|
+
}, [editor, kind, mode, pos]);
|
|
1183
1204
|
useEffect(() => {
|
|
1184
1205
|
var _a;
|
|
1185
1206
|
(_a = inputRef.current) == null ? void 0 : _a.focus();
|
|
1186
1207
|
}, []);
|
|
1187
1208
|
useEffect(() => {
|
|
1188
1209
|
if (pos == null) return;
|
|
1189
|
-
const
|
|
1190
|
-
const el = dom instanceof HTMLElement ? dom : dom instanceof Node ? dom.parentElement : null;
|
|
1210
|
+
const el = resolveNodeEl(editor, pos);
|
|
1191
1211
|
if (!el) return;
|
|
1192
1212
|
el.classList.add("tmr-math-editing");
|
|
1193
1213
|
return () => {
|
|
1194
1214
|
el.classList.remove("tmr-math-editing");
|
|
1195
1215
|
};
|
|
1196
1216
|
}, [editor, pos]);
|
|
1217
|
+
useEffect(() => {
|
|
1218
|
+
const onPtr = (e) => {
|
|
1219
|
+
var _a;
|
|
1220
|
+
const target = e.target;
|
|
1221
|
+
if (!(target instanceof Node)) return;
|
|
1222
|
+
if ((_a = rootRef.current) == null ? void 0 : _a.contains(target)) return;
|
|
1223
|
+
onCancel();
|
|
1224
|
+
};
|
|
1225
|
+
document.addEventListener("pointerdown", onPtr);
|
|
1226
|
+
return () => document.removeEventListener("pointerdown", onPtr);
|
|
1227
|
+
}, [onCancel]);
|
|
1197
1228
|
const preview = useMemo(
|
|
1198
1229
|
() => renderMathHtml(draft.trim(), isBlock),
|
|
1199
1230
|
[draft, isBlock]
|
|
@@ -1202,7 +1233,6 @@ function MathEditorPopover({
|
|
|
1202
1233
|
const showHint = !canSubmit && mode === "insert";
|
|
1203
1234
|
const submit = () => {
|
|
1204
1235
|
if (!canSubmit) return;
|
|
1205
|
-
confirmedRef.current = true;
|
|
1206
1236
|
onConfirm(draft.trim());
|
|
1207
1237
|
};
|
|
1208
1238
|
const onKeyDown = (e) => {
|
|
@@ -1240,88 +1270,69 @@ function MathEditorPopover({
|
|
|
1240
1270
|
onKeyDown
|
|
1241
1271
|
}
|
|
1242
1272
|
);
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
}
|
|
1257
|
-
) }),
|
|
1258
|
-
/* @__PURE__ */ jsx(Popover.Portal, { children: /* @__PURE__ */ jsx(
|
|
1259
|
-
Popover.Content,
|
|
1273
|
+
if (!host) return null;
|
|
1274
|
+
return createPortal(
|
|
1275
|
+
/* @__PURE__ */ jsx(
|
|
1276
|
+
"div",
|
|
1277
|
+
{
|
|
1278
|
+
ref: rootRef,
|
|
1279
|
+
className: styles$3.mathLayer,
|
|
1280
|
+
style: layerStyle,
|
|
1281
|
+
role: "dialog",
|
|
1282
|
+
"aria-modal": "false",
|
|
1283
|
+
"aria-labelledby": titleId,
|
|
1284
|
+
children: /* @__PURE__ */ jsxs(
|
|
1285
|
+
"div",
|
|
1260
1286
|
{
|
|
1261
|
-
className: styles$3.
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
"
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
className: styles$3.mathDone,
|
|
1306
|
-
disabled: !canSubmit,
|
|
1307
|
-
title: isBlock ? `${doneLabel} (⌘/Ctrl+Enter)` : `${doneLabel} (Enter)`,
|
|
1308
|
-
onClick: submit,
|
|
1309
|
-
children: [
|
|
1310
|
-
doneLabel,
|
|
1311
|
-
/* @__PURE__ */ jsx("span", { className: styles$3.mathDoneKbd, "aria-hidden": true, children: "↵" })
|
|
1312
|
-
]
|
|
1313
|
-
}
|
|
1314
|
-
)
|
|
1315
|
-
]
|
|
1316
|
-
}
|
|
1317
|
-
)
|
|
1318
|
-
]
|
|
1319
|
-
}
|
|
1320
|
-
)
|
|
1287
|
+
className: isBlock ? `${styles$3.mathStack} ${styles$3.mathStackBlock}` : styles$3.mathStack,
|
|
1288
|
+
children: [
|
|
1289
|
+
showHint ? /* @__PURE__ */ jsxs(
|
|
1290
|
+
"div",
|
|
1291
|
+
{
|
|
1292
|
+
id: titleId,
|
|
1293
|
+
className: isBlock ? `${styles$3.mathHint} ${styles$3.mathHintBlock}` : styles$3.mathHint,
|
|
1294
|
+
children: [
|
|
1295
|
+
/* @__PURE__ */ jsx("span", { className: styles$3.mathHintIcon, "aria-hidden": true, children: isBlock ? "TeX" : "√x" }),
|
|
1296
|
+
newLabel
|
|
1297
|
+
]
|
|
1298
|
+
}
|
|
1299
|
+
) : /* @__PURE__ */ jsx(
|
|
1300
|
+
"div",
|
|
1301
|
+
{
|
|
1302
|
+
id: titleId,
|
|
1303
|
+
className: isBlock ? styles$3.mathPreviewBlock : styles$3.mathPreviewInline,
|
|
1304
|
+
dangerouslySetInnerHTML: { __html: preview }
|
|
1305
|
+
}
|
|
1306
|
+
),
|
|
1307
|
+
/* @__PURE__ */ jsxs(
|
|
1308
|
+
"div",
|
|
1309
|
+
{
|
|
1310
|
+
className: isBlock ? `${styles$3.mathField} ${styles$3.mathFieldBlock}` : styles$3.mathField,
|
|
1311
|
+
children: [
|
|
1312
|
+
field,
|
|
1313
|
+
/* @__PURE__ */ jsxs(
|
|
1314
|
+
"button",
|
|
1315
|
+
{
|
|
1316
|
+
type: "button",
|
|
1317
|
+
className: styles$3.mathDone,
|
|
1318
|
+
disabled: !canSubmit,
|
|
1319
|
+
title: isBlock ? `${doneLabel} (⌘/Ctrl+Enter)` : `${doneLabel} (Enter)`,
|
|
1320
|
+
onClick: submit,
|
|
1321
|
+
children: [
|
|
1322
|
+
doneLabel,
|
|
1323
|
+
/* @__PURE__ */ jsx("span", { className: styles$3.mathDoneKbd, "aria-hidden": true, children: "↵" })
|
|
1324
|
+
]
|
|
1325
|
+
}
|
|
1326
|
+
)
|
|
1327
|
+
]
|
|
1328
|
+
}
|
|
1329
|
+
)
|
|
1330
|
+
]
|
|
1321
1331
|
}
|
|
1322
|
-
)
|
|
1323
|
-
|
|
1324
|
-
|
|
1332
|
+
)
|
|
1333
|
+
}
|
|
1334
|
+
),
|
|
1335
|
+
host
|
|
1325
1336
|
);
|
|
1326
1337
|
}
|
|
1327
1338
|
function ToolbarButton({
|