tiptap-markdown-react 0.8.1 → 0.8.3
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 +161 -139
- package/dist/index.js.map +1 -1
- package/dist/server.js +2 -2
- package/dist/style.css +128 -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_w3tos_2";
|
|
985
|
+
const inner = "_inner_w3tos_15";
|
|
986
|
+
const btn = "_btn_w3tos_27";
|
|
987
|
+
const btnActive = "_btnActive_w3tos_50";
|
|
988
|
+
const tableBubble = "_tableBubble_w3tos_66";
|
|
989
|
+
const txtIcon = "_txtIcon_w3tos_78";
|
|
990
|
+
const colorIcon = "_colorIcon_w3tos_86";
|
|
991
|
+
const colorIconGlyph = "_colorIconGlyph_w3tos_94";
|
|
992
|
+
const colorIconBar = "_colorIconBar_w3tos_100";
|
|
993
|
+
const scriptTrigger = "_scriptTrigger_w3tos_107";
|
|
994
|
+
const scriptTriggerGlyph = "_scriptTriggerGlyph_w3tos_127";
|
|
995
|
+
const divider = "_divider_w3tos_135";
|
|
996
|
+
const styleTrigger = "_styleTrigger_w3tos_144";
|
|
997
|
+
const styleTriggerLabel = "_styleTriggerLabel_w3tos_173";
|
|
998
|
+
const styleTriggerCaret = "_styleTriggerCaret_w3tos_181";
|
|
999
|
+
const styleItem = "_styleItem_w3tos_187";
|
|
1000
|
+
const styleIcon = "_styleIcon_w3tos_193";
|
|
1001
|
+
const scriptGlyph = "_scriptGlyph_w3tos_203";
|
|
1002
|
+
const menu = "_menu_w3tos_215";
|
|
1003
|
+
const menuItem = "_menuItem_w3tos_226";
|
|
1004
|
+
const menuItemSelected = "_menuItemSelected_w3tos_252";
|
|
1005
|
+
const popoverContent$1 = "_popoverContent_w3tos_266";
|
|
1006
|
+
const mathLayer = "_mathLayer_w3tos_270";
|
|
1007
|
+
const mathStack = "_mathStack_w3tos_275";
|
|
1008
|
+
const mathStackBlock = "_mathStackBlock_w3tos_282";
|
|
1009
|
+
const mathHint = "_mathHint_w3tos_287";
|
|
1010
|
+
const mathHintBlock = "_mathHintBlock_w3tos_299";
|
|
1011
|
+
const mathHintIcon = "_mathHintIcon_w3tos_305";
|
|
1012
|
+
const mathPreviewInline = "_mathPreviewInline_w3tos_311";
|
|
1013
|
+
const mathPreviewBlock = "_mathPreviewBlock_w3tos_337";
|
|
1014
|
+
const mathField = "_mathField_w3tos_367";
|
|
1015
|
+
const mathFieldBlock = "_mathFieldBlock_w3tos_379";
|
|
1016
|
+
const mathInput = "_mathInput_w3tos_386";
|
|
1017
|
+
const mathDone = "_mathDone_w3tos_404";
|
|
1018
|
+
const mathDoneKbd = "_mathDoneKbd_w3tos_429";
|
|
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,52 @@ 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 getMathPreviewFontSize(editor, pos) {
|
|
1138
|
+
const el = pos != null ? resolveNodeEl(editor, pos) : null;
|
|
1139
|
+
return getComputedStyle(el ?? editor.view.dom).fontSize;
|
|
1140
|
+
}
|
|
1141
|
+
function getMathLayerStyle(editor, kind, mode, pos) {
|
|
1142
|
+
const host = editor.view.dom.parentElement;
|
|
1143
|
+
if (!host) return {};
|
|
1144
|
+
const hostRect = host.getBoundingClientRect();
|
|
1134
1145
|
const editorRect = editor.view.dom.getBoundingClientRect();
|
|
1146
|
+
const gap = mode === "edit" ? 0 : 6;
|
|
1147
|
+
const blockWidth = editor.view.dom.clientWidth;
|
|
1135
1148
|
if (pos != null) {
|
|
1136
|
-
const
|
|
1137
|
-
const el = dom instanceof HTMLElement ? dom : dom instanceof Node ? dom.parentElement : null;
|
|
1149
|
+
const el = resolveNodeEl(editor, pos);
|
|
1138
1150
|
if (el) {
|
|
1139
1151
|
const r = el.getBoundingClientRect();
|
|
1140
1152
|
if (kind === "block") {
|
|
1141
|
-
return
|
|
1153
|
+
return {
|
|
1154
|
+
left: editorRect.left - hostRect.left,
|
|
1155
|
+
top: r.top - hostRect.top + gap,
|
|
1156
|
+
width: blockWidth
|
|
1157
|
+
};
|
|
1142
1158
|
}
|
|
1143
|
-
return
|
|
1159
|
+
return {
|
|
1160
|
+
left: r.left - hostRect.left,
|
|
1161
|
+
top: r.top - hostRect.top + gap
|
|
1162
|
+
};
|
|
1144
1163
|
}
|
|
1145
1164
|
}
|
|
1146
1165
|
const coords = editor.view.coordsAtPos(editor.state.selection.from);
|
|
1147
1166
|
if (kind === "block") {
|
|
1148
|
-
return
|
|
1167
|
+
return {
|
|
1168
|
+
left: editorRect.left - hostRect.left,
|
|
1169
|
+
top: coords.bottom - hostRect.top + gap,
|
|
1170
|
+
width: blockWidth
|
|
1171
|
+
};
|
|
1149
1172
|
}
|
|
1150
|
-
return
|
|
1173
|
+
return {
|
|
1174
|
+
left: coords.left - hostRect.left,
|
|
1175
|
+
top: coords.bottom - hostRect.top + gap
|
|
1176
|
+
};
|
|
1151
1177
|
}
|
|
1152
1178
|
function MathEditorPopover({
|
|
1153
1179
|
editor,
|
|
@@ -1162,38 +1188,53 @@ function MathEditorPopover({
|
|
|
1162
1188
|
onCancel
|
|
1163
1189
|
}) {
|
|
1164
1190
|
const [draft, setDraft] = useState(latex);
|
|
1165
|
-
const [
|
|
1191
|
+
const [layerStyle, setLayerStyle] = useState(
|
|
1192
|
+
() => getMathLayerStyle(editor, kind, mode, pos)
|
|
1193
|
+
);
|
|
1194
|
+
const [previewFontSize, setPreviewFontSize] = useState(
|
|
1195
|
+
() => getMathPreviewFontSize(editor, pos)
|
|
1196
|
+
);
|
|
1166
1197
|
const titleId = useId();
|
|
1167
1198
|
const inputRef = useRef(null);
|
|
1168
|
-
const
|
|
1199
|
+
const rootRef = useRef(null);
|
|
1169
1200
|
const isBlock = kind === "block";
|
|
1201
|
+
const host = editor.view.dom.parentElement;
|
|
1170
1202
|
useEffect(() => {
|
|
1171
1203
|
setDraft(latex);
|
|
1172
1204
|
}, [latex]);
|
|
1173
1205
|
useEffect(() => {
|
|
1174
|
-
const update = () =>
|
|
1206
|
+
const update = () => {
|
|
1207
|
+
setLayerStyle(getMathLayerStyle(editor, kind, mode, pos));
|
|
1208
|
+
setPreviewFontSize(getMathPreviewFontSize(editor, pos));
|
|
1209
|
+
};
|
|
1175
1210
|
update();
|
|
1176
1211
|
window.addEventListener("resize", update);
|
|
1177
|
-
window.
|
|
1178
|
-
|
|
1179
|
-
window.removeEventListener("resize", update);
|
|
1180
|
-
window.removeEventListener("scroll", update, true);
|
|
1181
|
-
};
|
|
1182
|
-
}, [editor, kind, pos]);
|
|
1212
|
+
return () => window.removeEventListener("resize", update);
|
|
1213
|
+
}, [editor, kind, mode, pos]);
|
|
1183
1214
|
useEffect(() => {
|
|
1184
1215
|
var _a;
|
|
1185
1216
|
(_a = inputRef.current) == null ? void 0 : _a.focus();
|
|
1186
1217
|
}, []);
|
|
1187
1218
|
useEffect(() => {
|
|
1188
1219
|
if (pos == null) return;
|
|
1189
|
-
const
|
|
1190
|
-
const el = dom instanceof HTMLElement ? dom : dom instanceof Node ? dom.parentElement : null;
|
|
1220
|
+
const el = resolveNodeEl(editor, pos);
|
|
1191
1221
|
if (!el) return;
|
|
1192
1222
|
el.classList.add("tmr-math-editing");
|
|
1193
1223
|
return () => {
|
|
1194
1224
|
el.classList.remove("tmr-math-editing");
|
|
1195
1225
|
};
|
|
1196
1226
|
}, [editor, pos]);
|
|
1227
|
+
useEffect(() => {
|
|
1228
|
+
const onPtr = (e) => {
|
|
1229
|
+
var _a;
|
|
1230
|
+
const target = e.target;
|
|
1231
|
+
if (!(target instanceof Node)) return;
|
|
1232
|
+
if ((_a = rootRef.current) == null ? void 0 : _a.contains(target)) return;
|
|
1233
|
+
onCancel();
|
|
1234
|
+
};
|
|
1235
|
+
document.addEventListener("pointerdown", onPtr);
|
|
1236
|
+
return () => document.removeEventListener("pointerdown", onPtr);
|
|
1237
|
+
}, [onCancel]);
|
|
1197
1238
|
const preview = useMemo(
|
|
1198
1239
|
() => renderMathHtml(draft.trim(), isBlock),
|
|
1199
1240
|
[draft, isBlock]
|
|
@@ -1202,7 +1243,6 @@ function MathEditorPopover({
|
|
|
1202
1243
|
const showHint = !canSubmit && mode === "insert";
|
|
1203
1244
|
const submit = () => {
|
|
1204
1245
|
if (!canSubmit) return;
|
|
1205
|
-
confirmedRef.current = true;
|
|
1206
1246
|
onConfirm(draft.trim());
|
|
1207
1247
|
};
|
|
1208
1248
|
const onKeyDown = (e) => {
|
|
@@ -1240,88 +1280,70 @@ function MathEditorPopover({
|
|
|
1240
1280
|
onKeyDown
|
|
1241
1281
|
}
|
|
1242
1282
|
);
|
|
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,
|
|
1283
|
+
if (!host) return null;
|
|
1284
|
+
return createPortal(
|
|
1285
|
+
/* @__PURE__ */ jsx(
|
|
1286
|
+
"div",
|
|
1287
|
+
{
|
|
1288
|
+
ref: rootRef,
|
|
1289
|
+
className: styles$3.mathLayer,
|
|
1290
|
+
style: layerStyle,
|
|
1291
|
+
role: "dialog",
|
|
1292
|
+
"aria-modal": "false",
|
|
1293
|
+
"aria-labelledby": titleId,
|
|
1294
|
+
children: /* @__PURE__ */ jsxs(
|
|
1295
|
+
"div",
|
|
1260
1296
|
{
|
|
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
|
-
|
|
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
|
-
)
|
|
1297
|
+
className: isBlock ? `${styles$3.mathStack} ${styles$3.mathStackBlock}` : styles$3.mathStack,
|
|
1298
|
+
children: [
|
|
1299
|
+
showHint ? /* @__PURE__ */ jsxs(
|
|
1300
|
+
"div",
|
|
1301
|
+
{
|
|
1302
|
+
id: titleId,
|
|
1303
|
+
className: isBlock ? `${styles$3.mathHint} ${styles$3.mathHintBlock}` : styles$3.mathHint,
|
|
1304
|
+
children: [
|
|
1305
|
+
/* @__PURE__ */ jsx("span", { className: styles$3.mathHintIcon, "aria-hidden": true, children: isBlock ? "TeX" : "√x" }),
|
|
1306
|
+
newLabel
|
|
1307
|
+
]
|
|
1308
|
+
}
|
|
1309
|
+
) : /* @__PURE__ */ jsx(
|
|
1310
|
+
"div",
|
|
1311
|
+
{
|
|
1312
|
+
id: titleId,
|
|
1313
|
+
className: isBlock ? styles$3.mathPreviewBlock : styles$3.mathPreviewInline,
|
|
1314
|
+
style: { fontSize: previewFontSize },
|
|
1315
|
+
dangerouslySetInnerHTML: { __html: preview }
|
|
1316
|
+
}
|
|
1317
|
+
),
|
|
1318
|
+
/* @__PURE__ */ jsxs(
|
|
1319
|
+
"div",
|
|
1320
|
+
{
|
|
1321
|
+
className: isBlock ? `${styles$3.mathField} ${styles$3.mathFieldBlock}` : styles$3.mathField,
|
|
1322
|
+
children: [
|
|
1323
|
+
field,
|
|
1324
|
+
/* @__PURE__ */ jsxs(
|
|
1325
|
+
"button",
|
|
1326
|
+
{
|
|
1327
|
+
type: "button",
|
|
1328
|
+
className: styles$3.mathDone,
|
|
1329
|
+
disabled: !canSubmit,
|
|
1330
|
+
title: isBlock ? `${doneLabel} (⌘/Ctrl+Enter)` : `${doneLabel} (Enter)`,
|
|
1331
|
+
onClick: submit,
|
|
1332
|
+
children: [
|
|
1333
|
+
doneLabel,
|
|
1334
|
+
/* @__PURE__ */ jsx("span", { className: styles$3.mathDoneKbd, "aria-hidden": true, children: "↵" })
|
|
1335
|
+
]
|
|
1336
|
+
}
|
|
1337
|
+
)
|
|
1338
|
+
]
|
|
1339
|
+
}
|
|
1340
|
+
)
|
|
1341
|
+
]
|
|
1321
1342
|
}
|
|
1322
|
-
)
|
|
1323
|
-
|
|
1324
|
-
|
|
1343
|
+
)
|
|
1344
|
+
}
|
|
1345
|
+
),
|
|
1346
|
+
host
|
|
1325
1347
|
);
|
|
1326
1348
|
}
|
|
1327
1349
|
function ToolbarButton({
|