tiptap-markdown-react 1.4.0 → 1.5.0
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/{ReportContent-B0HdrWAi.js → ReportContent-DUvhic0o.js} +13 -13
- package/dist/{ReportContent-B0HdrWAi.js.map → ReportContent-DUvhic0o.js.map} +1 -1
- package/dist/{ReportContentWithCharts-3cn7_5Tz.js → ReportContentWithCharts-CMMUE51M.js} +36 -26
- package/dist/ReportContentWithCharts-CMMUE51M.js.map +1 -0
- package/dist/{extractToc-Bz924Nh4.js → extractToc-B-hg0XuH.js} +4 -2
- package/dist/extractToc-B-hg0XuH.js.map +1 -0
- package/dist/formatBrush.d.ts +34 -0
- package/dist/formatBrush.test.d.ts +1 -0
- package/dist/icons/index.d.ts +3 -1
- package/dist/index.js +347 -15
- package/dist/index.js.map +1 -1
- package/dist/labels.d.ts +4 -0
- package/dist/reader.js +2 -2
- package/dist/server.js +4 -4
- package/dist/style-inline.css +369 -364
- package/dist/style.css +369 -364
- package/package.json +1 -1
- package/dist/ReportContentWithCharts-3cn7_5Tz.js.map +0 -1
- package/dist/extractToc-Bz924Nh4.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Markdown, MarkdownManager } from "@tiptap/markdown";
|
|
3
|
-
import { g as getLocaleBundle, S as SearchIcon, d as ChevronUpIcon, e as ChevronDownIcon, X as XIcon, h as ReplaceIcon, i as ReplaceAllIcon, j as renderOrUpdateChart, k as destroyChart, l as CheckIcon, T as TrashIcon, n as CopyIcon, o as ChevronsUpDownIcon, G as GripIcon, E as EraserIcon, D as DownloadIcon, u as useIsMobile, K as KeyboardIcon, p as EditorToc, I as ImagePreviewHost, q as sameTocItems$1, A as AlignRightIcon, t as AlignCenterIcon, v as AlignLeftIcon, w as CropIcon, x as CaptionsIcon, y as ExpandIcon, z as requestImagePreview, B as RotateCcwIcon, F as ExternalLinkIcon, H as TableDeleteIcon, J as ColumnBeforeIcon, L as ColumnAfterIcon, M as ColumnDeleteIcon, N as RowBeforeIcon, O as RowAfterIcon, P as RowDeleteIcon, U as UndoIcon, Q as RedoIcon, V as
|
|
4
|
-
import { C,
|
|
3
|
+
import { g as getLocaleBundle, S as SearchIcon, d as ChevronUpIcon, e as ChevronDownIcon, X as XIcon, h as ReplaceIcon, i as ReplaceAllIcon, j as renderOrUpdateChart, k as destroyChart, l as CheckIcon, T as TrashIcon, n as CopyIcon, o as ChevronsUpDownIcon, G as GripIcon, E as EraserIcon, D as DownloadIcon, u as useIsMobile, K as KeyboardIcon, p as EditorToc, I as ImagePreviewHost, q as sameTocItems$1, A as AlignRightIcon, t as AlignCenterIcon, v as AlignLeftIcon, w as CropIcon, x as CaptionsIcon, y as ExpandIcon, z as requestImagePreview, B as RotateCcwIcon, F as ExternalLinkIcon, H as TableDeleteIcon, J as ColumnBeforeIcon, L as ColumnAfterIcon, M as ColumnDeleteIcon, N as RowBeforeIcon, O as RowAfterIcon, P as RowDeleteIcon, U as UndoIcon, Q as RedoIcon, V as PaintbrushIcon, W as BoldIcon, Y as ItalicIcon, Z as UnderlineIcon, _ as StrikethroughIcon, $ as CodeIcon, a0 as LinkIcon, a1 as ImageIcon, a2 as DetailsIcon, a3 as AlignJustifyIcon, a4 as IndentIncreaseIcon, a5 as IndentDecreaseIcon, a6 as LineHeightIcon, a7 as ListUnorderedIcon, a8 as ListOrderedIcon, a9 as ListChecksIcon } from "./ReportContentWithCharts-CMMUE51M.js";
|
|
4
|
+
import { C, aa, ab, a, ac, ad, ae, af, b, c, ag, ah, ai, f, m, r, s } from "./ReportContentWithCharts-CMMUE51M.js";
|
|
5
5
|
import { jsx, jsxs, Fragment as Fragment$2 } from "react/jsx-runtime";
|
|
6
6
|
import CodeBlockLowlight from "@tiptap/extension-code-block-lowlight";
|
|
7
7
|
import FindAndReplace, { FindAndReplacePluginKey, createSearchRegex } from "@tiptap/extension-find-and-replace";
|
|
@@ -14,10 +14,10 @@ import { NodeViewWrapper, ReactNodeViewRenderer, useEditorState, ReactRenderer,
|
|
|
14
14
|
import { Extension, Node as Node$1, mergeAttributes } from "@tiptap/core";
|
|
15
15
|
import { createPortal } from "react-dom";
|
|
16
16
|
import { useState, useEffect, useCallback, useRef, useMemo, useSyncExternalStore, useLayoutEffect, forwardRef, useId, useImperativeHandle, Fragment as Fragment$1, useContext, createContext } from "react";
|
|
17
|
-
import { q as normalizeImageAlign, l as normalizeImageCrop, m as cropImageBox, e as enrichMarkdownCitations, o as styles$e, i as imageMarkdownTokenizer, c as imageParseMarkdown, d as imageRenderMarkdown, f as imageNodeHtml, g as imageFigureParseRule, h as imageCropAttribute, j as imageCaptionAttribute, k as imageAlignAttribute, r as normalizeImageCaption } from "./ReportContent-
|
|
18
|
-
import { R, a as a2, b as b2, s as s2 } from "./ReportContent-
|
|
19
|
-
import { C as CitationRef, i as mergeCommentIntervals, h as mapCommentAnchors, p as prepareChartMarkdown, j as reportChart, f as CommentMark, b as baseExtensions, l as lowlight, m as makeTocGetId, k as parseCodeTokenAsChartOrCodeBlock, a as pureCodeBlock, c as pureImage, n as renderMathInto, o as readCurrentNumberingFormat, q as subscribeMathClick, t as applyNumberingFormat, N as NUMBERING_FORMAT_IDS, u as NUMBERING_FORMAT_LABELS, v as NUMBERING_FORMAT_PREVIEWS, d as pureChart } from "./extractToc-
|
|
20
|
-
import { P, g, e, s as s3 } from "./extractToc-
|
|
17
|
+
import { q as normalizeImageAlign, l as normalizeImageCrop, m as cropImageBox, e as enrichMarkdownCitations, o as styles$e, i as imageMarkdownTokenizer, c as imageParseMarkdown, d as imageRenderMarkdown, f as imageNodeHtml, g as imageFigureParseRule, h as imageCropAttribute, j as imageCaptionAttribute, k as imageAlignAttribute, r as normalizeImageCaption } from "./ReportContent-DUvhic0o.js";
|
|
18
|
+
import { R, a as a2, b as b2, s as s2 } from "./ReportContent-DUvhic0o.js";
|
|
19
|
+
import { C as CitationRef, i as mergeCommentIntervals, h as mapCommentAnchors, p as prepareChartMarkdown, j as reportChart, f as CommentMark, b as baseExtensions, l as lowlight, m as makeTocGetId, k as parseCodeTokenAsChartOrCodeBlock, a as pureCodeBlock, c as pureImage, n as renderMathInto, o as readCurrentNumberingFormat, q as subscribeMathClick, t as applyNumberingFormat, N as NUMBERING_FORMAT_IDS, u as NUMBERING_FORMAT_LABELS, v as NUMBERING_FORMAT_PREVIEWS, d as pureChart } from "./extractToc-B-hg0XuH.js";
|
|
20
|
+
import { P, g, e, s as s3 } from "./extractToc-B-hg0XuH.js";
|
|
21
21
|
import { Slice, Fragment } from "@tiptap/pm/model";
|
|
22
22
|
import { PluginKey, Plugin, Selection, TextSelection, NodeSelection } from "@tiptap/pm/state";
|
|
23
23
|
import { DecorationSet, Decoration } from "@tiptap/pm/view";
|
|
@@ -4404,6 +4404,263 @@ const styles$6 = {
|
|
|
4404
4404
|
mathDone,
|
|
4405
4405
|
mathDoneKbd
|
|
4406
4406
|
};
|
|
4407
|
+
const FORMAT_MARKS = /* @__PURE__ */ new Set([
|
|
4408
|
+
"bold",
|
|
4409
|
+
"italic",
|
|
4410
|
+
"underline",
|
|
4411
|
+
"strike",
|
|
4412
|
+
"code",
|
|
4413
|
+
"highlight",
|
|
4414
|
+
"textStyle",
|
|
4415
|
+
"superscript",
|
|
4416
|
+
"subscript"
|
|
4417
|
+
]);
|
|
4418
|
+
const PLAIN_BLOCK = {
|
|
4419
|
+
type: "paragraph",
|
|
4420
|
+
level: null,
|
|
4421
|
+
textAlign: null,
|
|
4422
|
+
indent: null,
|
|
4423
|
+
lineHeight: null
|
|
4424
|
+
};
|
|
4425
|
+
function isFormatMark(name) {
|
|
4426
|
+
return FORMAT_MARKS.has(name);
|
|
4427
|
+
}
|
|
4428
|
+
function isStyleBlock(node) {
|
|
4429
|
+
return node.type.name === "paragraph" || node.type.name === "heading";
|
|
4430
|
+
}
|
|
4431
|
+
function readBlock(node) {
|
|
4432
|
+
const indent = Number(node.attrs.indent);
|
|
4433
|
+
const lineHeight = Number(node.attrs.lineHeight);
|
|
4434
|
+
return {
|
|
4435
|
+
type: node.type.name === "heading" ? "heading" : "paragraph",
|
|
4436
|
+
level: node.type.name === "heading" ? Number(node.attrs.level) || 1 : null,
|
|
4437
|
+
textAlign: typeof node.attrs.textAlign === "string" && node.attrs.textAlign ? node.attrs.textAlign : null,
|
|
4438
|
+
indent: Number.isFinite(indent) && indent > 0 ? indent : null,
|
|
4439
|
+
lineHeight: Number.isFinite(lineHeight) && lineHeight > 0 ? lineHeight : null
|
|
4440
|
+
};
|
|
4441
|
+
}
|
|
4442
|
+
function sameMarkSet(a3, b3) {
|
|
4443
|
+
if (a3.length !== b3.length) return false;
|
|
4444
|
+
return a3.every((mark) => b3.some((other) => mark.eq(other)));
|
|
4445
|
+
}
|
|
4446
|
+
function anchorTextblock(doc, from, to) {
|
|
4447
|
+
const $from = doc.resolve(from);
|
|
4448
|
+
if ($from.parent.isTextblock && !$from.parent.type.spec.code) {
|
|
4449
|
+
return { node: $from.parent, pos: $from.before() };
|
|
4450
|
+
}
|
|
4451
|
+
if (from === to) return null;
|
|
4452
|
+
let found = null;
|
|
4453
|
+
doc.nodesBetween(from, to, (node, pos) => {
|
|
4454
|
+
if (found) return false;
|
|
4455
|
+
if (node.isTextblock && !node.type.spec.code) {
|
|
4456
|
+
found = { node, pos };
|
|
4457
|
+
return false;
|
|
4458
|
+
}
|
|
4459
|
+
});
|
|
4460
|
+
return found;
|
|
4461
|
+
}
|
|
4462
|
+
function blockIsCovered(node, pos, from, to) {
|
|
4463
|
+
const contentFrom = pos + 1;
|
|
4464
|
+
const contentTo = pos + node.nodeSize - 1;
|
|
4465
|
+
return from <= contentFrom && to >= contentTo;
|
|
4466
|
+
}
|
|
4467
|
+
function sourceMarks(doc, from, to, stored) {
|
|
4468
|
+
var _a;
|
|
4469
|
+
if (from === to) {
|
|
4470
|
+
if (stored) return stored;
|
|
4471
|
+
return doc.resolve(from).marks();
|
|
4472
|
+
}
|
|
4473
|
+
const $from = doc.resolve(from);
|
|
4474
|
+
if ((_a = $from.nodeAfter) == null ? void 0 : _a.isText) return $from.nodeAfter.marks;
|
|
4475
|
+
return $from.marks();
|
|
4476
|
+
}
|
|
4477
|
+
function captureFormat(editor) {
|
|
4478
|
+
if (!editor.isEditable) return null;
|
|
4479
|
+
const { selection, storedMarks, doc } = editor.state;
|
|
4480
|
+
const anchor = anchorTextblock(doc, selection.from, selection.to);
|
|
4481
|
+
if (!anchor) return null;
|
|
4482
|
+
const marks = sourceMarks(doc, selection.from, selection.to, storedMarks).filter((mark) => isFormatMark(mark.type.name)).map((mark) => ({ type: mark.type.name, attrs: { ...mark.attrs } }));
|
|
4483
|
+
const block = isStyleBlock(anchor.node) && (selection.empty || blockIsCovered(anchor.node, anchor.pos, selection.from, selection.to)) ? readBlock(anchor.node) : null;
|
|
4484
|
+
return { marks, block };
|
|
4485
|
+
}
|
|
4486
|
+
function canPaint(doc, from, to) {
|
|
4487
|
+
return anchorTextblock(doc, from, to) != null;
|
|
4488
|
+
}
|
|
4489
|
+
function removeFormatMarks(tr, from, to) {
|
|
4490
|
+
if (from >= to) return;
|
|
4491
|
+
for (const name of FORMAT_MARKS) {
|
|
4492
|
+
const type = tr.doc.type.schema.marks[name];
|
|
4493
|
+
if (type) tr.removeMark(from, to, type);
|
|
4494
|
+
}
|
|
4495
|
+
}
|
|
4496
|
+
function addFormatMarks(tr, from, to, marks) {
|
|
4497
|
+
if (from >= to) return;
|
|
4498
|
+
for (const mark of marks) {
|
|
4499
|
+
const type = tr.doc.type.schema.marks[mark.type];
|
|
4500
|
+
if (!type || !isFormatMark(mark.type)) continue;
|
|
4501
|
+
tr.addMark(from, to, type.create(mark.attrs));
|
|
4502
|
+
}
|
|
4503
|
+
}
|
|
4504
|
+
function marksForNextInput(tr, stateStored) {
|
|
4505
|
+
if (tr.storedMarksSet) return tr.storedMarks ?? [];
|
|
4506
|
+
if (stateStored) return stateStored;
|
|
4507
|
+
return tr.selection.$from.marks();
|
|
4508
|
+
}
|
|
4509
|
+
function setFormatStoredMarks(tr, marks, stateStored) {
|
|
4510
|
+
const current = marksForNextInput(tr, stateStored);
|
|
4511
|
+
const kept = current.filter((mark) => !isFormatMark(mark.type.name));
|
|
4512
|
+
const next = [
|
|
4513
|
+
...kept,
|
|
4514
|
+
...marks.flatMap((mark) => {
|
|
4515
|
+
const type = tr.doc.type.schema.marks[mark.type];
|
|
4516
|
+
return type && isFormatMark(mark.type) ? [type.create(mark.attrs)] : [];
|
|
4517
|
+
})
|
|
4518
|
+
];
|
|
4519
|
+
if (sameMarkSet(current, next)) return;
|
|
4520
|
+
tr.setStoredMarks(next);
|
|
4521
|
+
}
|
|
4522
|
+
function stripFormatStoredMarks(tr, stateStored) {
|
|
4523
|
+
const current = marksForNextInput(tr, stateStored);
|
|
4524
|
+
const next = current.filter((mark) => !isFormatMark(mark.type.name));
|
|
4525
|
+
if (sameMarkSet(current, next)) return;
|
|
4526
|
+
tr.setStoredMarks(next);
|
|
4527
|
+
}
|
|
4528
|
+
function applyBlockAt(tr, pos, block) {
|
|
4529
|
+
var _a, _b, _c;
|
|
4530
|
+
const node = tr.doc.nodeAt(pos);
|
|
4531
|
+
if (!node || !isStyleBlock(node)) return;
|
|
4532
|
+
const $pos = tr.doc.resolve(pos);
|
|
4533
|
+
let typeName = node.type.name;
|
|
4534
|
+
if (block.type === "heading") {
|
|
4535
|
+
const heading = tr.doc.type.schema.nodes.heading;
|
|
4536
|
+
if (heading && $pos.parent.canReplaceWith($pos.index(), $pos.index() + 1, heading)) {
|
|
4537
|
+
typeName = "heading";
|
|
4538
|
+
}
|
|
4539
|
+
} else if (node.type.name === "heading") {
|
|
4540
|
+
const paragraph = tr.doc.type.schema.nodes.paragraph;
|
|
4541
|
+
if (paragraph && $pos.parent.canReplaceWith($pos.index(), $pos.index() + 1, paragraph)) {
|
|
4542
|
+
typeName = "paragraph";
|
|
4543
|
+
}
|
|
4544
|
+
}
|
|
4545
|
+
const type = tr.doc.type.schema.nodes[typeName];
|
|
4546
|
+
if (!type) return;
|
|
4547
|
+
const indent = Number(node.attrs.indent);
|
|
4548
|
+
const lineHeight = Number(node.attrs.lineHeight);
|
|
4549
|
+
const sameType = node.type === type;
|
|
4550
|
+
const sameLevel = typeName !== "heading" || Number(node.attrs.level) === (block.level ?? 1);
|
|
4551
|
+
const sameAlign = (node.attrs.textAlign || null) === block.textAlign;
|
|
4552
|
+
const sameIndent = (Number.isFinite(indent) && indent > 0 ? indent : null) === block.indent;
|
|
4553
|
+
const sameLine = (Number.isFinite(lineHeight) && lineHeight > 0 ? lineHeight : null) === block.lineHeight;
|
|
4554
|
+
if (sameType && sameLevel && sameAlign && sameIndent && sameLine) return;
|
|
4555
|
+
const attrs = { ...node.attrs };
|
|
4556
|
+
if (typeName === "heading") attrs.level = block.level ?? 1;
|
|
4557
|
+
else delete attrs.level;
|
|
4558
|
+
if ((_a = type.spec.attrs) == null ? void 0 : _a.textAlign) attrs.textAlign = block.textAlign;
|
|
4559
|
+
if ((_b = type.spec.attrs) == null ? void 0 : _b.indent) attrs.indent = block.indent;
|
|
4560
|
+
if ((_c = type.spec.attrs) == null ? void 0 : _c.lineHeight) attrs.lineHeight = block.lineHeight;
|
|
4561
|
+
tr.setNodeMarkup(pos, type, attrs);
|
|
4562
|
+
}
|
|
4563
|
+
function coveredStyleBlockPositions(doc, from, to) {
|
|
4564
|
+
const positions = [];
|
|
4565
|
+
doc.nodesBetween(from, to, (node, pos) => {
|
|
4566
|
+
if (!isStyleBlock(node)) return;
|
|
4567
|
+
if (blockIsCovered(node, pos, from, to)) positions.push(pos);
|
|
4568
|
+
});
|
|
4569
|
+
return positions;
|
|
4570
|
+
}
|
|
4571
|
+
function mutateFormatting(tr, mode, format, stateStored) {
|
|
4572
|
+
const docBefore = tr.doc;
|
|
4573
|
+
const ranges = tr.selection.ranges.map((range) => ({
|
|
4574
|
+
from: range.$from.pos,
|
|
4575
|
+
to: range.$to.pos
|
|
4576
|
+
}));
|
|
4577
|
+
const caretOnly = ranges.every((range) => range.from === range.to);
|
|
4578
|
+
if (caretOnly) {
|
|
4579
|
+
for (const range of ranges) {
|
|
4580
|
+
const $pos = tr.doc.resolve(range.from);
|
|
4581
|
+
const parent = $pos.parent;
|
|
4582
|
+
if (!parent.isTextblock || parent.type.spec.code) continue;
|
|
4583
|
+
if (mode === "clear") {
|
|
4584
|
+
removeFormatMarks(tr, $pos.start(), $pos.end());
|
|
4585
|
+
if (isStyleBlock(parent)) applyBlockAt(tr, $pos.before(), PLAIN_BLOCK);
|
|
4586
|
+
} else if ((format == null ? void 0 : format.block) && isStyleBlock(parent)) {
|
|
4587
|
+
applyBlockAt(tr, $pos.before(), format.block);
|
|
4588
|
+
}
|
|
4589
|
+
}
|
|
4590
|
+
if (mode === "clear") stripFormatStoredMarks(tr, stateStored);
|
|
4591
|
+
else if (format) setFormatStoredMarks(tr, format.marks, stateStored);
|
|
4592
|
+
} else {
|
|
4593
|
+
for (const range of ranges) {
|
|
4594
|
+
removeFormatMarks(tr, range.from, range.to);
|
|
4595
|
+
if (mode === "paint" && format) addFormatMarks(tr, range.from, range.to, format.marks);
|
|
4596
|
+
}
|
|
4597
|
+
const positions = /* @__PURE__ */ new Set();
|
|
4598
|
+
for (const range of ranges) {
|
|
4599
|
+
for (const pos of coveredStyleBlockPositions(tr.doc, range.from, range.to)) {
|
|
4600
|
+
positions.add(pos);
|
|
4601
|
+
}
|
|
4602
|
+
}
|
|
4603
|
+
const ordered = [...positions].sort((a3, b3) => b3 - a3);
|
|
4604
|
+
for (const pos of ordered) {
|
|
4605
|
+
if (mode === "clear") applyBlockAt(tr, pos, PLAIN_BLOCK);
|
|
4606
|
+
else if (format == null ? void 0 : format.block) applyBlockAt(tr, pos, format.block);
|
|
4607
|
+
}
|
|
4608
|
+
if (mode === "clear") stripFormatStoredMarks(tr, stateStored);
|
|
4609
|
+
else if (format) setFormatStoredMarks(tr, format.marks, stateStored);
|
|
4610
|
+
}
|
|
4611
|
+
const docChanged = !tr.doc.eq(docBefore);
|
|
4612
|
+
const storedChanged = tr.storedMarksSet && !sameMarkSet(tr.storedMarks ?? [], stateStored ?? []);
|
|
4613
|
+
return docChanged || storedChanged;
|
|
4614
|
+
}
|
|
4615
|
+
function runFormatCommand(editor, mutate) {
|
|
4616
|
+
return editor.chain().focus().command(({ tr }) => mutate(tr)).run();
|
|
4617
|
+
}
|
|
4618
|
+
function pinCursorMarks(editor, desired) {
|
|
4619
|
+
if (!editor.state.selection.empty) return;
|
|
4620
|
+
const current = editor.state.storedMarks ?? editor.state.selection.$from.marks();
|
|
4621
|
+
if (sameMarkSet(current, desired)) return;
|
|
4622
|
+
editor.view.dispatch(
|
|
4623
|
+
editor.state.tr.setStoredMarks(desired).setMeta("addToHistory", false)
|
|
4624
|
+
);
|
|
4625
|
+
}
|
|
4626
|
+
function storedMarksFor(editor, captured) {
|
|
4627
|
+
const current = editor.state.storedMarks ?? editor.state.selection.$from.marks();
|
|
4628
|
+
const kept = current.filter((mark) => !isFormatMark(mark.type.name));
|
|
4629
|
+
if (!captured) return kept;
|
|
4630
|
+
return [
|
|
4631
|
+
...kept,
|
|
4632
|
+
...captured.flatMap((mark) => {
|
|
4633
|
+
const type = editor.schema.marks[mark.type];
|
|
4634
|
+
return type && isFormatMark(mark.type) ? [type.create(mark.attrs)] : [];
|
|
4635
|
+
})
|
|
4636
|
+
];
|
|
4637
|
+
}
|
|
4638
|
+
function clearFormatting(editor) {
|
|
4639
|
+
if (!editor.isEditable) return false;
|
|
4640
|
+
const { selection, doc } = editor.state;
|
|
4641
|
+
if (!canPaint(doc, selection.from, selection.to)) return false;
|
|
4642
|
+
const stateStored = editor.state.storedMarks;
|
|
4643
|
+
const ok = runFormatCommand(
|
|
4644
|
+
editor,
|
|
4645
|
+
(tr) => mutateFormatting(tr, "clear", null, stateStored)
|
|
4646
|
+
);
|
|
4647
|
+
if (editor.state.selection.empty) pinCursorMarks(editor, storedMarksFor(editor, null));
|
|
4648
|
+
return ok;
|
|
4649
|
+
}
|
|
4650
|
+
function applyCapturedFormat(editor, format) {
|
|
4651
|
+
if (!editor.isEditable) return false;
|
|
4652
|
+
const { selection, doc } = editor.state;
|
|
4653
|
+
if (!canPaint(doc, selection.from, selection.to)) return false;
|
|
4654
|
+
const stateStored = editor.state.storedMarks;
|
|
4655
|
+
runFormatCommand(
|
|
4656
|
+
editor,
|
|
4657
|
+
(tr) => mutateFormatting(tr, "paint", format, stateStored)
|
|
4658
|
+
);
|
|
4659
|
+
if (editor.state.selection.empty) {
|
|
4660
|
+
pinCursorMarks(editor, storedMarksFor(editor, format.marks));
|
|
4661
|
+
}
|
|
4662
|
+
return true;
|
|
4663
|
+
}
|
|
4407
4664
|
const palette = "_palette_x5lrq_2";
|
|
4408
4665
|
const noneRow = "_noneRow_x5lrq_11";
|
|
4409
4666
|
const noneIcon = "_noneIcon_x5lrq_23";
|
|
@@ -6462,6 +6719,63 @@ function EditorToolbar({
|
|
|
6462
6719
|
editor.off("blur", onBlur);
|
|
6463
6720
|
};
|
|
6464
6721
|
}, [editor]);
|
|
6722
|
+
const [painter, setPainter] = useState("off");
|
|
6723
|
+
const [paintSample, setPaintSample] = useState(null);
|
|
6724
|
+
const painterClickAt = useRef(0);
|
|
6725
|
+
const painterEditor = useRef(editor);
|
|
6726
|
+
const disarmPainter = () => {
|
|
6727
|
+
painterClickAt.current = 0;
|
|
6728
|
+
setPainter("off");
|
|
6729
|
+
setPaintSample(null);
|
|
6730
|
+
};
|
|
6731
|
+
useEffect(() => {
|
|
6732
|
+
if (painterEditor.current === editor) return;
|
|
6733
|
+
painterEditor.current = editor;
|
|
6734
|
+
disarmPainter();
|
|
6735
|
+
}, [editor]);
|
|
6736
|
+
useEffect(() => {
|
|
6737
|
+
if (editor.isDestroyed) return;
|
|
6738
|
+
const dom = editor.view.dom;
|
|
6739
|
+
dom.classList.toggle("tmr-format-painter", painter !== "off");
|
|
6740
|
+
return () => {
|
|
6741
|
+
if (!editor.isDestroyed) dom.classList.remove("tmr-format-painter");
|
|
6742
|
+
};
|
|
6743
|
+
}, [editor, painter]);
|
|
6744
|
+
useEffect(() => {
|
|
6745
|
+
if (painter === "off" || !paintSample || editor.isDestroyed) return;
|
|
6746
|
+
const dom = editor.view.dom;
|
|
6747
|
+
const apply2 = () => {
|
|
6748
|
+
const handled = applyCapturedFormat(editor, paintSample);
|
|
6749
|
+
if (handled && painter === "once") disarmPainter();
|
|
6750
|
+
};
|
|
6751
|
+
const onKeyDown = (event) => {
|
|
6752
|
+
if (event.key !== "Escape") return;
|
|
6753
|
+
disarmPainter();
|
|
6754
|
+
};
|
|
6755
|
+
dom.addEventListener("mouseup", apply2);
|
|
6756
|
+
document.addEventListener("keydown", onKeyDown);
|
|
6757
|
+
return () => {
|
|
6758
|
+
dom.removeEventListener("mouseup", apply2);
|
|
6759
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
6760
|
+
};
|
|
6761
|
+
}, [editor, painter, paintSample]);
|
|
6762
|
+
const onFormatPainterClick = () => {
|
|
6763
|
+
const now = Date.now();
|
|
6764
|
+
const quick = now - painterClickAt.current < 300;
|
|
6765
|
+
painterClickAt.current = now;
|
|
6766
|
+
if (painter !== "off") {
|
|
6767
|
+
if (quick && painter === "once") {
|
|
6768
|
+
setPainter("locked");
|
|
6769
|
+
return;
|
|
6770
|
+
}
|
|
6771
|
+
disarmPainter();
|
|
6772
|
+
return;
|
|
6773
|
+
}
|
|
6774
|
+
const captured = captureFormat(editor);
|
|
6775
|
+
if (!captured) return;
|
|
6776
|
+
setPaintSample(captured);
|
|
6777
|
+
setPainter(quick ? "locked" : "once");
|
|
6778
|
+
};
|
|
6465
6779
|
const fileInputRef = useRef(null);
|
|
6466
6780
|
const chain = () => editor.chain().focus();
|
|
6467
6781
|
const imageUploadEnabled = hasImageUpload(editor);
|
|
@@ -6668,6 +6982,23 @@ function EditorToolbar({
|
|
|
6668
6982
|
children: /* @__PURE__ */ jsx(RedoIcon, {})
|
|
6669
6983
|
}
|
|
6670
6984
|
),
|
|
6985
|
+
/* @__PURE__ */ jsx(
|
|
6986
|
+
ToolbarButton,
|
|
6987
|
+
{
|
|
6988
|
+
title: t.formatPainter,
|
|
6989
|
+
active: painter !== "off",
|
|
6990
|
+
onClick: onFormatPainterClick,
|
|
6991
|
+
children: /* @__PURE__ */ jsx(PaintbrushIcon, {})
|
|
6992
|
+
}
|
|
6993
|
+
),
|
|
6994
|
+
/* @__PURE__ */ jsx(
|
|
6995
|
+
ToolbarButton,
|
|
6996
|
+
{
|
|
6997
|
+
title: t.clearFormatting,
|
|
6998
|
+
onClick: () => clearFormatting(editor),
|
|
6999
|
+
children: /* @__PURE__ */ jsx(EraserIcon, {})
|
|
7000
|
+
}
|
|
7001
|
+
),
|
|
6671
7002
|
/* @__PURE__ */ jsx(Divider, {}),
|
|
6672
7003
|
/* @__PURE__ */ jsxs(
|
|
6673
7004
|
MenuPopover,
|
|
@@ -7429,8 +7760,8 @@ export {
|
|
|
7429
7760
|
C as ChartMount,
|
|
7430
7761
|
CheckIcon,
|
|
7431
7762
|
ChevronDownIcon,
|
|
7432
|
-
|
|
7433
|
-
|
|
7763
|
+
aa as ChevronLeftIcon,
|
|
7764
|
+
ab as ChevronRightIcon,
|
|
7434
7765
|
ChevronUpIcon,
|
|
7435
7766
|
ChevronsUpDownIcon,
|
|
7436
7767
|
a as CitationInteractive,
|
|
@@ -7454,12 +7785,12 @@ export {
|
|
|
7454
7785
|
FIND_DEBOUNCE_MS,
|
|
7455
7786
|
default2 as FindAndReplace,
|
|
7456
7787
|
FindReplaceBar,
|
|
7457
|
-
|
|
7788
|
+
ac as FitIcon,
|
|
7458
7789
|
GripIcon,
|
|
7459
7790
|
ImageAlignTools,
|
|
7460
7791
|
ImageIcon,
|
|
7461
7792
|
ImageUploadNode,
|
|
7462
|
-
|
|
7793
|
+
ad as ImportIcon,
|
|
7463
7794
|
ImportPlaceholder,
|
|
7464
7795
|
IndentDecreaseIcon,
|
|
7465
7796
|
IndentIncreaseIcon,
|
|
@@ -7471,13 +7802,14 @@ export {
|
|
|
7471
7802
|
ListChecksIcon,
|
|
7472
7803
|
ListOrderedIcon,
|
|
7473
7804
|
ListUnorderedIcon,
|
|
7474
|
-
|
|
7805
|
+
ae as LockIcon,
|
|
7475
7806
|
MarkdownFileDrop,
|
|
7476
7807
|
MarkdownPaste,
|
|
7477
7808
|
MarkdownPreview,
|
|
7478
7809
|
MarkdownWysiwygEditor,
|
|
7479
|
-
|
|
7810
|
+
af as MenuIcon,
|
|
7480
7811
|
PENDING_ANCHOR_CLASS,
|
|
7812
|
+
PaintbrushIcon,
|
|
7481
7813
|
P as ParagraphStyles,
|
|
7482
7814
|
RedoIcon,
|
|
7483
7815
|
ReplaceAllIcon,
|
|
@@ -7486,7 +7818,7 @@ export {
|
|
|
7486
7818
|
b as ReportContentInteractive,
|
|
7487
7819
|
c as ReportContentWithCharts,
|
|
7488
7820
|
RotateCcwIcon,
|
|
7489
|
-
|
|
7821
|
+
ag as RotateCwIcon,
|
|
7490
7822
|
RowAfterIcon,
|
|
7491
7823
|
RowBeforeIcon,
|
|
7492
7824
|
RowDeleteIcon,
|
|
@@ -7499,8 +7831,8 @@ export {
|
|
|
7499
7831
|
UnderlineIcon,
|
|
7500
7832
|
UndoIcon,
|
|
7501
7833
|
XIcon,
|
|
7502
|
-
|
|
7503
|
-
|
|
7834
|
+
ah as ZoomInIcon,
|
|
7835
|
+
ai as ZoomOutIcon,
|
|
7504
7836
|
a2 as applyCitationSources,
|
|
7505
7837
|
applyCommentAnchorsToEditor,
|
|
7506
7838
|
applyLink,
|