@gantfdt/semiword 1.0.1 → 1.1.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/README.md +20 -0
- package/dist-lib/{FlowchartEditor-S3WKMPDU.mjs → FlowchartEditor-LT6T7ZQV.mjs} +4 -4
- package/dist-lib/{FlowchartEditor-S3WKMPDU.mjs.map → FlowchartEditor-LT6T7ZQV.mjs.map} +1 -1
- package/dist-lib/{MindmapEditor-KXVEAEQ5.mjs → MindmapEditor-TMXT2VG3.mjs} +4 -4
- package/dist-lib/{MindmapEditor-KXVEAEQ5.mjs.map → MindmapEditor-TMXT2VG3.mjs.map} +1 -1
- package/dist-lib/{WhiteboardEditor-HZFL4ZPY.mjs → WhiteboardEditor-FSYK6RVN.mjs} +4 -4
- package/dist-lib/{WhiteboardEditor-HZFL4ZPY.mjs.map → WhiteboardEditor-FSYK6RVN.mjs.map} +1 -1
- package/dist-lib/ai.mjs +7 -7
- package/dist-lib/{chunk-N3YIYJWU.mjs → chunk-3K44CBQF.mjs} +1000 -97
- package/dist-lib/chunk-3K44CBQF.mjs.map +1 -0
- package/dist-lib/{chunk-KS6IR3BG.mjs → chunk-6XGJMUU3.mjs} +1142 -168
- package/dist-lib/chunk-6XGJMUU3.mjs.map +1 -0
- package/dist-lib/{chunk-4W6PPBHQ.mjs → chunk-7D6NMYFG.mjs} +32 -6
- package/dist-lib/chunk-7D6NMYFG.mjs.map +1 -0
- package/dist-lib/{chunk-SYHECPDJ.mjs → chunk-DRZQC4T6.mjs} +5 -5
- package/dist-lib/{chunk-SYHECPDJ.mjs.map → chunk-DRZQC4T6.mjs.map} +1 -1
- package/dist-lib/{chunk-Y2RC2UZD.mjs → chunk-KD56TONW.mjs} +4 -4
- package/dist-lib/{chunk-Y2RC2UZD.mjs.map → chunk-KD56TONW.mjs.map} +1 -1
- package/dist-lib/{chunk-4JNPZORJ.mjs → chunk-MC3JHNMW.mjs} +8 -8
- package/dist-lib/{chunk-4JNPZORJ.mjs.map → chunk-MC3JHNMW.mjs.map} +1 -1
- package/dist-lib/{chunk-QWDJU3H7.mjs → chunk-NRQTMBH3.mjs} +3 -3
- package/dist-lib/{chunk-QWDJU3H7.mjs.map → chunk-NRQTMBH3.mjs.map} +1 -1
- package/dist-lib/{chunk-G4OJCQKQ.mjs → chunk-SG6KJKDX.mjs} +28 -5
- package/dist-lib/chunk-SG6KJKDX.mjs.map +1 -0
- package/dist-lib/{chunk-766SMPYW.mjs → chunk-THKKUOIF.mjs} +9 -9
- package/dist-lib/chunk-THKKUOIF.mjs.map +1 -0
- package/dist-lib/{chunk-ZM3WULHX.mjs → chunk-WT7ZJINB.mjs} +288 -4
- package/dist-lib/chunk-WT7ZJINB.mjs.map +1 -0
- package/dist-lib/designer.mjs +8 -8
- package/dist-lib/document.mjs +2 -2
- package/dist-lib/editor.d.mts +3 -3
- package/dist-lib/editor.mjs +9 -9
- package/dist-lib/gant-ai.mjs +7 -7
- package/dist-lib/index.d.mts +2 -2
- package/dist-lib/index.mjs +9 -9
- package/dist-lib/io.mjs +4 -4
- package/dist-lib/sdk.mjs +6 -6
- package/dist-lib/storage.d.mts +3 -3
- package/dist-lib/{types-vl8k8NDK.d.mts → types-D7kCE5Mu.d.mts} +18 -2
- package/dist-lib/{useDocumentPersistence-DOpnQsZQ.d.mts → useDocumentPersistence-CDUT0u5S.d.mts} +1 -1
- package/package.json +1 -1
- package/dist-lib/chunk-4W6PPBHQ.mjs.map +0 -1
- package/dist-lib/chunk-766SMPYW.mjs.map +0 -1
- package/dist-lib/chunk-G4OJCQKQ.mjs.map +0 -1
- package/dist-lib/chunk-KS6IR3BG.mjs.map +0 -1
- package/dist-lib/chunk-N3YIYJWU.mjs.map +0 -1
- package/dist-lib/chunk-ZM3WULHX.mjs.map +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { createStyles, useBlockStyles, Button, createGraphicBlockView, createGraphicBlockNode, Tooltip, Modal as Modal$1, Input, DatePicker } from './chunk-
|
|
2
|
-
import { sanitizeSvg } from './chunk-
|
|
1
|
+
import { createStyles, useBlockStyles, Button, IconEdit, IconDelete, IconVideo, IconAttachment, createGraphicBlockView, createGraphicBlockNode, IconUndo, IconRedo, IconParagraph, IconQuote, IconCode, IconDivider, IconBulletList, IconOrderedList, IconTaskList, IconBold, IconItalic, IconUnderline, IconStrikethrough, IconTextColor, IconAlignLeft, IconAlignCenter, IconAlignRight, IconClearFormat, IconFormatPainter, IconBackgroundColor, IconTable, IconImage, IconFlowchart, IconWhiteboard, IconMindmap, IconMention, Tooltip, IconLink, Modal as Modal$1, Input, DatePicker } from './chunk-WT7ZJINB.mjs';
|
|
2
|
+
import { sanitizeSvg, DATA_MEDIA_URI_PATTERN } from './chunk-7D6NMYFG.mjs';
|
|
3
3
|
import { readTemplateBlockMeta, renderTemplateBlockMeta, parseTemplateBlockMeta, getTemplateBlockRegistry, effectivePin, createTemplateController, getRegisteredTemplateBlockExtensions, createIntegrityExtension } from './chunk-EOUNN3NA.mjs';
|
|
4
4
|
import { tr } from './chunk-W627LLF4.mjs';
|
|
5
5
|
import { Node, mergeAttributes, Extension, getMarkRange } from '@tiptap/core';
|
|
6
6
|
import { NodeViewWrapper, ReactNodeViewRenderer, ReactRenderer } from '@tiptap/react';
|
|
7
7
|
import { memo, useState, useRef, useCallback, useEffect, forwardRef, useImperativeHandle } from 'react';
|
|
8
|
-
import { PictureOutlined, LoadingOutlined, ReloadOutlined, EditOutlined, DeleteOutlined, ApartmentOutlined, BorderOutlined, PartitionOutlined
|
|
8
|
+
import { PictureOutlined, LoadingOutlined, ReloadOutlined, EditOutlined, DeleteOutlined, ApartmentOutlined, BorderOutlined, PartitionOutlined } from '@ant-design/icons';
|
|
9
9
|
import { message, Modal } from 'antd';
|
|
10
10
|
import { jsx, jsxs, Fragment as Fragment$1 } from 'react/jsx-runtime';
|
|
11
11
|
import { NodeSelection, PluginKey, Plugin, Selection, AllSelection } from '@tiptap/pm/state';
|
|
@@ -30,8 +30,8 @@ import Strike from '@tiptap/extension-strike';
|
|
|
30
30
|
import Underline from '@tiptap/extension-underline';
|
|
31
31
|
import TextStyle from '@tiptap/extension-text-style';
|
|
32
32
|
import Color from '@tiptap/extension-color';
|
|
33
|
-
import Highlight from '@tiptap/extension-highlight';
|
|
34
33
|
import TextAlign from '@tiptap/extension-text-align';
|
|
34
|
+
import Highlight from '@tiptap/extension-highlight';
|
|
35
35
|
import Table from '@tiptap/extension-table';
|
|
36
36
|
import TableRow from '@tiptap/extension-table-row';
|
|
37
37
|
import TableCell from '@tiptap/extension-table-cell';
|
|
@@ -1365,7 +1365,7 @@ var starterPlugin = {
|
|
|
1365
1365
|
order: 0,
|
|
1366
1366
|
label: tr("\u64A4\u9500"),
|
|
1367
1367
|
shortcut: "Ctrl Z",
|
|
1368
|
-
icon: /* @__PURE__ */ jsx(
|
|
1368
|
+
icon: /* @__PURE__ */ jsx(IconUndo, {}),
|
|
1369
1369
|
disabled: (editor) => !editor.can().undo(),
|
|
1370
1370
|
onClick: (editor) => editor.chain().focus().undo().run()
|
|
1371
1371
|
},
|
|
@@ -1377,7 +1377,7 @@ var starterPlugin = {
|
|
|
1377
1377
|
label: tr("\u91CD\u505A"),
|
|
1378
1378
|
// Windows 侧 ProseMirror 绑定 Ctrl Y,macOS 侧为 ⌘⇧Z(Mod-Shift-Z),并列展示兼容两平台
|
|
1379
1379
|
shortcut: "Ctrl Y / \u2318\u21E7Z",
|
|
1380
|
-
icon: /* @__PURE__ */ jsx(
|
|
1380
|
+
icon: /* @__PURE__ */ jsx(IconRedo, {}),
|
|
1381
1381
|
disabled: (editor) => !editor.can().redo(),
|
|
1382
1382
|
onClick: (editor) => editor.chain().focus().redo().run()
|
|
1383
1383
|
}
|
|
@@ -1401,7 +1401,7 @@ var headingPlugin = {
|
|
|
1401
1401
|
group: "block",
|
|
1402
1402
|
order: 10,
|
|
1403
1403
|
label: tr("\u6807\u9898"),
|
|
1404
|
-
icon: /* @__PURE__ */ jsx(
|
|
1404
|
+
icon: /* @__PURE__ */ jsx(IconParagraph, {}),
|
|
1405
1405
|
options: [
|
|
1406
1406
|
{
|
|
1407
1407
|
label: tr("\u6B63\u6587"),
|
|
@@ -1424,7 +1424,7 @@ var headingPlugin = {
|
|
|
1424
1424
|
].map(({ level, label, description, searchTerms }, index) => ({
|
|
1425
1425
|
id: `heading-${level}`,
|
|
1426
1426
|
label,
|
|
1427
|
-
icon: /* @__PURE__ */ jsx(
|
|
1427
|
+
icon: /* @__PURE__ */ jsx(IconParagraph, {}),
|
|
1428
1428
|
category: tr("\u57FA\u672C\u5757"),
|
|
1429
1429
|
order: 10 + index,
|
|
1430
1430
|
description,
|
|
@@ -1456,7 +1456,7 @@ var blockquotePlugin = {
|
|
|
1456
1456
|
group: "block",
|
|
1457
1457
|
order: 15,
|
|
1458
1458
|
label: tr("\u5F15\u7528"),
|
|
1459
|
-
icon: /* @__PURE__ */ jsx(
|
|
1459
|
+
icon: /* @__PURE__ */ jsx(IconQuote, {}),
|
|
1460
1460
|
isActive: (editor) => editor.isActive("blockquote"),
|
|
1461
1461
|
onClick: (editor) => editor.chain().focus().toggleBlockquote().run()
|
|
1462
1462
|
}
|
|
@@ -1465,7 +1465,7 @@ var blockquotePlugin = {
|
|
|
1465
1465
|
{
|
|
1466
1466
|
id: "blockquote",
|
|
1467
1467
|
label: tr("\u5F15\u7528"),
|
|
1468
|
-
icon: /* @__PURE__ */ jsx(
|
|
1468
|
+
icon: /* @__PURE__ */ jsx(IconQuote, {}),
|
|
1469
1469
|
category: tr("\u57FA\u672C\u5757"),
|
|
1470
1470
|
order: 40,
|
|
1471
1471
|
description: tr("\u521B\u5EFA\u5F15\u7528\u5757"),
|
|
@@ -1726,7 +1726,7 @@ var codeBlockPlugin = {
|
|
|
1726
1726
|
group: "block",
|
|
1727
1727
|
order: 16,
|
|
1728
1728
|
label: tr("\u4EE3\u7801\u5757"),
|
|
1729
|
-
icon: /* @__PURE__ */ jsx(
|
|
1729
|
+
icon: /* @__PURE__ */ jsx(IconCode, {}),
|
|
1730
1730
|
isActive: (editor) => editor.isActive("codeBlock"),
|
|
1731
1731
|
onClick: (editor) => editor.chain().focus().toggleCodeBlock().run()
|
|
1732
1732
|
}
|
|
@@ -1735,7 +1735,7 @@ var codeBlockPlugin = {
|
|
|
1735
1735
|
{
|
|
1736
1736
|
id: "code-block",
|
|
1737
1737
|
label: tr("\u4EE3\u7801\u5757"),
|
|
1738
|
-
icon: /* @__PURE__ */ jsx(
|
|
1738
|
+
icon: /* @__PURE__ */ jsx(IconCode, {}),
|
|
1739
1739
|
category: tr("\u9AD8\u7EA7\u5757"),
|
|
1740
1740
|
order: 10,
|
|
1741
1741
|
description: tr("\u63D2\u5165\u4EE3\u7801\u5757"),
|
|
@@ -1769,7 +1769,7 @@ var horizontalRulePlugin = {
|
|
|
1769
1769
|
group: "block",
|
|
1770
1770
|
order: 17,
|
|
1771
1771
|
label: tr("\u5206\u5272\u7EBF"),
|
|
1772
|
-
icon: /* @__PURE__ */ jsx(
|
|
1772
|
+
icon: /* @__PURE__ */ jsx(IconDivider, {}),
|
|
1773
1773
|
onClick: (editor) => editor.chain().focus().setHorizontalRule().run()
|
|
1774
1774
|
}
|
|
1775
1775
|
],
|
|
@@ -1777,7 +1777,7 @@ var horizontalRulePlugin = {
|
|
|
1777
1777
|
{
|
|
1778
1778
|
id: "horizontal-rule",
|
|
1779
1779
|
label: tr("\u5206\u5272\u7EBF"),
|
|
1780
|
-
icon: /* @__PURE__ */ jsx(
|
|
1780
|
+
icon: /* @__PURE__ */ jsx(IconDivider, {}),
|
|
1781
1781
|
category: tr("\u57FA\u672C\u5757"),
|
|
1782
1782
|
order: 50,
|
|
1783
1783
|
description: tr("\u63D2\u5165\u6C34\u5E73\u5206\u5272\u7EBF"),
|
|
@@ -1815,7 +1815,7 @@ var listPlugin = {
|
|
|
1815
1815
|
group: "list",
|
|
1816
1816
|
order: 50,
|
|
1817
1817
|
label: tr("\u65E0\u5E8F\u5217\u8868"),
|
|
1818
|
-
icon: /* @__PURE__ */ jsx(
|
|
1818
|
+
icon: /* @__PURE__ */ jsx(IconBulletList, {}),
|
|
1819
1819
|
isActive: (editor) => editor.isActive("bulletList"),
|
|
1820
1820
|
onClick: (editor) => editor.chain().focus().toggleBulletList().run()
|
|
1821
1821
|
},
|
|
@@ -1825,7 +1825,7 @@ var listPlugin = {
|
|
|
1825
1825
|
group: "list",
|
|
1826
1826
|
order: 51,
|
|
1827
1827
|
label: tr("\u6709\u5E8F\u5217\u8868"),
|
|
1828
|
-
icon: /* @__PURE__ */ jsx(
|
|
1828
|
+
icon: /* @__PURE__ */ jsx(IconOrderedList, {}),
|
|
1829
1829
|
isActive: (editor) => editor.isActive("orderedList"),
|
|
1830
1830
|
onClick: (editor) => editor.chain().focus().toggleOrderedList().run()
|
|
1831
1831
|
}
|
|
@@ -1834,7 +1834,7 @@ var listPlugin = {
|
|
|
1834
1834
|
{
|
|
1835
1835
|
id: "bullet-list",
|
|
1836
1836
|
label: tr("\u65E0\u5E8F\u5217\u8868"),
|
|
1837
|
-
icon: /* @__PURE__ */ jsx(
|
|
1837
|
+
icon: /* @__PURE__ */ jsx(IconBulletList, {}),
|
|
1838
1838
|
category: tr("\u57FA\u672C\u5757"),
|
|
1839
1839
|
order: 20,
|
|
1840
1840
|
description: tr("\u521B\u5EFA\u65E0\u5E8F\u5217\u8868"),
|
|
@@ -1844,7 +1844,7 @@ var listPlugin = {
|
|
|
1844
1844
|
{
|
|
1845
1845
|
id: "ordered-list",
|
|
1846
1846
|
label: tr("\u6709\u5E8F\u5217\u8868"),
|
|
1847
|
-
icon: /* @__PURE__ */ jsx(
|
|
1847
|
+
icon: /* @__PURE__ */ jsx(IconOrderedList, {}),
|
|
1848
1848
|
category: tr("\u57FA\u672C\u5757"),
|
|
1849
1849
|
order: 21,
|
|
1850
1850
|
description: tr("\u521B\u5EFA\u6709\u5E8F\u5217\u8868"),
|
|
@@ -1882,7 +1882,7 @@ var taskListPlugin = {
|
|
|
1882
1882
|
group: "list",
|
|
1883
1883
|
order: 52,
|
|
1884
1884
|
label: tr("\u4EFB\u52A1\u5217\u8868"),
|
|
1885
|
-
icon: /* @__PURE__ */ jsx(
|
|
1885
|
+
icon: /* @__PURE__ */ jsx(IconTaskList, {}),
|
|
1886
1886
|
isActive: (editor) => editor.isActive("taskList"),
|
|
1887
1887
|
onClick: (editor) => editor.chain().focus().toggleTaskList().run()
|
|
1888
1888
|
}
|
|
@@ -1891,7 +1891,7 @@ var taskListPlugin = {
|
|
|
1891
1891
|
{
|
|
1892
1892
|
id: "task-list",
|
|
1893
1893
|
label: tr("\u4EFB\u52A1\u5217\u8868"),
|
|
1894
|
-
icon: /* @__PURE__ */ jsx(
|
|
1894
|
+
icon: /* @__PURE__ */ jsx(IconTaskList, {}),
|
|
1895
1895
|
category: tr("\u57FA\u672C\u5757"),
|
|
1896
1896
|
order: 30,
|
|
1897
1897
|
description: tr("\u521B\u5EFA\u5F85\u529E\u4E8B\u9879\u5217\u8868"),
|
|
@@ -2489,7 +2489,7 @@ var textFormatPlugin = {
|
|
|
2489
2489
|
group: "format",
|
|
2490
2490
|
order: 20,
|
|
2491
2491
|
label: tr("\u52A0\u7C97"),
|
|
2492
|
-
icon: /* @__PURE__ */ jsx(
|
|
2492
|
+
icon: /* @__PURE__ */ jsx(IconBold, {}),
|
|
2493
2493
|
isActive: (editor) => editor.isActive("bold"),
|
|
2494
2494
|
onClick: (editor) => editor.chain().focus().toggleBold().run()
|
|
2495
2495
|
},
|
|
@@ -2499,7 +2499,7 @@ var textFormatPlugin = {
|
|
|
2499
2499
|
group: "format",
|
|
2500
2500
|
order: 21,
|
|
2501
2501
|
label: tr("\u659C\u4F53"),
|
|
2502
|
-
icon: /* @__PURE__ */ jsx(
|
|
2502
|
+
icon: /* @__PURE__ */ jsx(IconItalic, {}),
|
|
2503
2503
|
isActive: (editor) => editor.isActive("italic"),
|
|
2504
2504
|
onClick: (editor) => editor.chain().focus().toggleItalic().run()
|
|
2505
2505
|
},
|
|
@@ -2509,7 +2509,7 @@ var textFormatPlugin = {
|
|
|
2509
2509
|
group: "format",
|
|
2510
2510
|
order: 22,
|
|
2511
2511
|
label: tr("\u4E0B\u5212\u7EBF"),
|
|
2512
|
-
icon: /* @__PURE__ */ jsx(
|
|
2512
|
+
icon: /* @__PURE__ */ jsx(IconUnderline, {}),
|
|
2513
2513
|
isActive: (editor) => editor.isActive("underline"),
|
|
2514
2514
|
onClick: (editor) => editor.chain().focus().toggleUnderline().run()
|
|
2515
2515
|
},
|
|
@@ -2519,7 +2519,7 @@ var textFormatPlugin = {
|
|
|
2519
2519
|
group: "format",
|
|
2520
2520
|
order: 23,
|
|
2521
2521
|
label: tr("\u5220\u9664\u7EBF"),
|
|
2522
|
-
icon: /* @__PURE__ */ jsx(
|
|
2522
|
+
icon: /* @__PURE__ */ jsx(IconStrikethrough, {}),
|
|
2523
2523
|
isActive: (editor) => editor.isActive("strike"),
|
|
2524
2524
|
onClick: (editor) => editor.chain().focus().toggleStrike().run()
|
|
2525
2525
|
}
|
|
@@ -2576,12 +2576,34 @@ var textFormatPlugin = {
|
|
|
2576
2576
|
}
|
|
2577
2577
|
]
|
|
2578
2578
|
};
|
|
2579
|
+
var TextStyleGradient = Extension.create({
|
|
2580
|
+
name: "textStyleGradient",
|
|
2581
|
+
addGlobalAttributes() {
|
|
2582
|
+
return [
|
|
2583
|
+
{
|
|
2584
|
+
types: ["textStyle"],
|
|
2585
|
+
attributes: {
|
|
2586
|
+
gradient: {
|
|
2587
|
+
default: null,
|
|
2588
|
+
parseHTML: (element) => element.style.backgroundImage?.replace(/['"]+/g, "") || null,
|
|
2589
|
+
renderHTML: (attributes) => {
|
|
2590
|
+
if (!attributes.gradient) return {};
|
|
2591
|
+
return {
|
|
2592
|
+
style: `background-image: ${attributes.gradient}; background-clip: text; -webkit-background-clip: text; color: transparent; -webkit-text-fill-color: transparent;`
|
|
2593
|
+
};
|
|
2594
|
+
}
|
|
2595
|
+
}
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
];
|
|
2599
|
+
}
|
|
2600
|
+
});
|
|
2579
2601
|
var textColorPlugin = {
|
|
2580
2602
|
name: "text-color",
|
|
2581
2603
|
category: "format",
|
|
2582
2604
|
dependencies: ["starter"],
|
|
2583
2605
|
defaultEnabled: true,
|
|
2584
|
-
tiptapExtensions: () => [TextStyle, Color],
|
|
2606
|
+
tiptapExtensions: () => [TextStyle, Color, TextStyleGradient],
|
|
2585
2607
|
toolbarItems: () => [
|
|
2586
2608
|
{
|
|
2587
2609
|
id: "text-color",
|
|
@@ -2589,24 +2611,33 @@ var textColorPlugin = {
|
|
|
2589
2611
|
group: "color",
|
|
2590
2612
|
order: 30,
|
|
2591
2613
|
label: tr("\u6587\u5B57\u989C\u8272"),
|
|
2592
|
-
icon: /* @__PURE__ */ jsx(
|
|
2593
|
-
|
|
2594
|
-
|
|
2614
|
+
icon: /* @__PURE__ */ jsx(IconTextColor, {}),
|
|
2615
|
+
defaultSwatch: "#000000",
|
|
2616
|
+
getActiveValue: (editor) => {
|
|
2617
|
+
const attrs = editor.getAttributes("textStyle");
|
|
2618
|
+
return attrs.gradient || attrs.color || null;
|
|
2619
|
+
},
|
|
2620
|
+
onColorSelect: (editor, color, options) => {
|
|
2621
|
+
const chain = options?.focus === false ? editor.chain() : editor.chain().focus();
|
|
2622
|
+
chain.setMark("textStyle", { color, gradient: null }).run();
|
|
2623
|
+
},
|
|
2624
|
+
onGradientSelect: (editor, gradient) => {
|
|
2625
|
+
editor.chain().focus().setMark("textStyle", { color: null, gradient }).run();
|
|
2595
2626
|
},
|
|
2596
2627
|
onClear: (editor) => {
|
|
2597
|
-
editor.chain().focus().
|
|
2628
|
+
editor.chain().focus().setMark("textStyle", { color: null, gradient: null }).removeEmptyTextStyle().run();
|
|
2598
2629
|
}
|
|
2599
2630
|
}
|
|
2600
2631
|
],
|
|
2601
|
-
// AI 能力声明:mark 类——文字颜色(@tiptap/extension-color 的
|
|
2602
|
-
//
|
|
2632
|
+
// AI 能力声明:mark 类——文字颜色(@tiptap/extension-color 的 color 属性)。
|
|
2633
|
+
// set 语义:重复设置同色幂等;清除必须走 unsetColor 条目。
|
|
2603
2634
|
aiCommands: () => [
|
|
2604
2635
|
{
|
|
2605
2636
|
id: "text-color.setColor",
|
|
2606
2637
|
zhLabel: tr("\u8BBE\u7F6E\u6587\u5B57\u989C\u8272"),
|
|
2607
2638
|
kind: "mark",
|
|
2608
2639
|
description: tr(
|
|
2609
|
-
"\u628A\u951A\u6587\u672C\u8BBE\u4E3A\u6307\u5B9A\u989C\u8272\u3002\u53C2\u6570 color \u4E3A CSS \u989C\u8272\u503C\uFF08\u5982 #ff0000\u3001red\u3001rgb(255,0,0)\uFF09\u3002\u6E05\u9664\u989C\u8272\u7528 text-color.unsetColor \u6761\u76EE\uFF0C\u4E0D\u8981\u628A color \u8BBE\u6210\u9ED1\u8272\u6765\u300C\u6062\u590D\u9ED8\u8BA4\u300D\u3002"
|
|
2640
|
+
"\u628A\u951A\u6587\u672C\u8BBE\u4E3A\u6307\u5B9A\u989C\u8272\u3002\u53C2\u6570 color \u4E3A CSS \u989C\u8272\u503C\uFF08\u5982 #ff0000\u3001red\u3001rgb(255,0,0)\uFF09\u3002\u91CD\u590D\u8BBE\u7F6E\u540C\u8272\u5E42\u7B49\u3002\u6E05\u9664\u989C\u8272\u7528 text-color.unsetColor \u6761\u76EE\uFF0C\u4E0D\u8981\u628A color \u8BBE\u6210\u9ED1\u8272\u6765\u300C\u6062\u590D\u9ED8\u8BA4\u300D\u3002"
|
|
2610
2641
|
),
|
|
2611
2642
|
params: [
|
|
2612
2643
|
{
|
|
@@ -2618,74 +2649,19 @@ var textColorPlugin = {
|
|
|
2618
2649
|
apply: createMarkApply((chain, _range, params) => {
|
|
2619
2650
|
const color = params?.color;
|
|
2620
2651
|
if (typeof color !== "string" || !color.trim()) return false;
|
|
2621
|
-
return chain.
|
|
2652
|
+
return chain.setMark("textStyle", { color, gradient: null });
|
|
2622
2653
|
})
|
|
2623
2654
|
},
|
|
2624
2655
|
{
|
|
2625
2656
|
id: "text-color.unsetColor",
|
|
2626
2657
|
zhLabel: tr("\u6E05\u9664\u6587\u5B57\u989C\u8272"),
|
|
2627
2658
|
kind: "mark",
|
|
2628
|
-
description: tr("\u6E05\u9664\u951A\u6587\u672C\u7684\u6587\u5B57\u989C\u8272\uFF08\u6062\u590D\u9ED8\u8BA4\u8272\uFF0C\u6587\u5B57\u4FDD\u7559\uFF09\u3002\u65E0\u53C2\u6570\u3002\u628A\u7EA2\u5B57/\u5F69\u8272\u5B57\u6062\u590D\u9ED8\u8BA4\u7528\u672C\u6761\u76EE\u3002"),
|
|
2629
|
-
apply: createMarkApply((chain) => chain.unsetColor())
|
|
2630
|
-
}
|
|
2631
|
-
]
|
|
2632
|
-
};
|
|
2633
|
-
var highlightPlugin = {
|
|
2634
|
-
name: "highlight",
|
|
2635
|
-
category: "format",
|
|
2636
|
-
dependencies: ["starter"],
|
|
2637
|
-
defaultEnabled: true,
|
|
2638
|
-
tiptapExtensions: () => [
|
|
2639
|
-
Highlight.configure({
|
|
2640
|
-
multicolor: true
|
|
2641
|
-
})
|
|
2642
|
-
],
|
|
2643
|
-
toolbarItems: () => [
|
|
2644
|
-
{
|
|
2645
|
-
id: "highlight",
|
|
2646
|
-
type: "button",
|
|
2647
|
-
group: "format",
|
|
2648
|
-
order: 24,
|
|
2649
|
-
label: tr("\u9AD8\u4EAE"),
|
|
2650
|
-
icon: /* @__PURE__ */ jsx(HighlightOutlined, {}),
|
|
2651
|
-
isActive: (editor) => editor.isActive("highlight"),
|
|
2652
|
-
onClick: (editor) => editor.chain().focus().toggleHighlight().run()
|
|
2653
|
-
}
|
|
2654
|
-
],
|
|
2655
|
-
// AI 能力声明:mark 类——高亮背景色(multicolor 模式,@tiptap/extension-highlight
|
|
2656
|
-
// 的 setHighlight/toggleHighlight 命令)。set 幂等设色;toggle 同色互切。
|
|
2657
|
-
aiCommands: () => [
|
|
2658
|
-
{
|
|
2659
|
-
id: "highlight.setHighlight",
|
|
2660
|
-
zhLabel: tr("\u8BBE\u7F6E\u9AD8\u4EAE"),
|
|
2661
|
-
kind: "mark",
|
|
2662
|
-
description: tr(
|
|
2663
|
-
"\u7ED9\u951A\u6587\u672C\u8BBE\u7F6E\u9AD8\u4EAE\u80CC\u666F\u8272\u3002\u53C2\u6570 color \u4E3A CSS \u989C\u8272\u503C\uFF08\u5982 #ffff00\uFF09\uFF0C\u7F3A\u7701\u7528\u7F16\u8F91\u5668\u9ED8\u8BA4\u9AD8\u4EAE\u8272\u3002\u91CD\u590D\u8BBE\u7F6E\u540C\u8272\u5E42\u7B49\u3002\u6E05\u9664\u9AD8\u4EAE\u7528 highlight.toggleHighlight\uFF08\u540C\u8272\u518D\u5207\u4E00\u6B21\u5373\u53D6\u6D88\uFF09\u3002"
|
|
2664
|
-
),
|
|
2665
|
-
params: [
|
|
2666
|
-
{
|
|
2667
|
-
key: "color",
|
|
2668
|
-
type: "string",
|
|
2669
|
-
description: tr("\u53EF\u9009\uFF1ACSS \u9AD8\u4EAE\u989C\u8272\u503C\uFF08\u5982 #ffff00 \u9EC4\u3001#d4edda \u7EFF\uFF09\uFF1B\u7F3A\u7701=\u9ED8\u8BA4\u9AD8\u4EAE\u8272")
|
|
2670
|
-
}
|
|
2671
|
-
],
|
|
2672
|
-
apply: createMarkApply((chain, _range, params) => {
|
|
2673
|
-
const color = params?.color;
|
|
2674
|
-
return typeof color === "string" && color.trim() ? chain.setHighlight({ color }) : chain.setHighlight();
|
|
2675
|
-
})
|
|
2676
|
-
},
|
|
2677
|
-
{
|
|
2678
|
-
id: "highlight.toggleHighlight",
|
|
2679
|
-
zhLabel: tr("\u5207\u6362\u9AD8\u4EAE"),
|
|
2680
|
-
kind: "mark",
|
|
2681
2659
|
description: tr(
|
|
2682
|
-
"\
|
|
2660
|
+
"\u6E05\u9664\u951A\u6587\u672C\u7684\u6587\u5B57\u989C\u8272\u4E0E\u6E10\u53D8\uFF08\u6062\u590D\u9ED8\u8BA4\u8272\uFF0C\u6587\u5B57\u4FDD\u7559\uFF09\u3002\u65E0\u53C2\u6570\u3002\u628A\u7EA2\u5B57/\u5F69\u8272\u5B57/\u6E10\u53D8\u5B57\u6062\u590D\u9ED8\u8BA4\u7528\u672C\u6761\u76EE\u3002"
|
|
2683
2661
|
),
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
return typeof color === "string" && color.trim() ? chain.toggleHighlight({ color }) : chain.toggleHighlight();
|
|
2688
|
-
})
|
|
2662
|
+
apply: createMarkApply(
|
|
2663
|
+
(chain) => chain.setMark("textStyle", { color: null, gradient: null }).removeEmptyTextStyle()
|
|
2664
|
+
)
|
|
2689
2665
|
}
|
|
2690
2666
|
]
|
|
2691
2667
|
};
|
|
@@ -2706,7 +2682,7 @@ var textAlignPlugin = {
|
|
|
2706
2682
|
group: "align",
|
|
2707
2683
|
order: 40,
|
|
2708
2684
|
label: tr("\u5DE6\u5BF9\u9F50"),
|
|
2709
|
-
icon: /* @__PURE__ */ jsx(
|
|
2685
|
+
icon: /* @__PURE__ */ jsx(IconAlignLeft, {}),
|
|
2710
2686
|
isActive: (editor) => editor.isActive({ textAlign: "left" }),
|
|
2711
2687
|
onClick: (editor) => editor.chain().focus().setTextAlign("left").run()
|
|
2712
2688
|
},
|
|
@@ -2716,7 +2692,7 @@ var textAlignPlugin = {
|
|
|
2716
2692
|
group: "align",
|
|
2717
2693
|
order: 41,
|
|
2718
2694
|
label: tr("\u5C45\u4E2D"),
|
|
2719
|
-
icon: /* @__PURE__ */ jsx(
|
|
2695
|
+
icon: /* @__PURE__ */ jsx(IconAlignCenter, {}),
|
|
2720
2696
|
isActive: (editor) => editor.isActive({ textAlign: "center" }),
|
|
2721
2697
|
onClick: (editor) => editor.chain().focus().setTextAlign("center").run()
|
|
2722
2698
|
},
|
|
@@ -2726,7 +2702,7 @@ var textAlignPlugin = {
|
|
|
2726
2702
|
group: "align",
|
|
2727
2703
|
order: 42,
|
|
2728
2704
|
label: tr("\u53F3\u5BF9\u9F50"),
|
|
2729
|
-
icon: /* @__PURE__ */ jsx(
|
|
2705
|
+
icon: /* @__PURE__ */ jsx(IconAlignRight, {}),
|
|
2730
2706
|
isActive: (editor) => editor.isActive({ textAlign: "right" }),
|
|
2731
2707
|
onClick: (editor) => editor.chain().focus().setTextAlign("right").run()
|
|
2732
2708
|
}
|
|
@@ -2744,6 +2720,227 @@ var textAlignPlugin = {
|
|
|
2744
2720
|
}
|
|
2745
2721
|
]
|
|
2746
2722
|
};
|
|
2723
|
+
var clearFormatPlugin = {
|
|
2724
|
+
name: "clear-format",
|
|
2725
|
+
category: "format",
|
|
2726
|
+
dependencies: ["starter"],
|
|
2727
|
+
defaultEnabled: true,
|
|
2728
|
+
tiptapExtensions: () => [],
|
|
2729
|
+
toolbarItems: () => [
|
|
2730
|
+
{
|
|
2731
|
+
id: "clear-format",
|
|
2732
|
+
type: "button",
|
|
2733
|
+
group: "format",
|
|
2734
|
+
order: 26,
|
|
2735
|
+
label: tr("\u6E05\u9664\u683C\u5F0F"),
|
|
2736
|
+
icon: /* @__PURE__ */ jsx(IconClearFormat, {}),
|
|
2737
|
+
onClick: (editor) => editor.chain().focus().unsetAllMarks().clearNodes().run()
|
|
2738
|
+
}
|
|
2739
|
+
]
|
|
2740
|
+
};
|
|
2741
|
+
|
|
2742
|
+
// src/editor/plugins/builtin/formatpainter/formatPainterState.ts
|
|
2743
|
+
var painterStates = /* @__PURE__ */ new WeakMap();
|
|
2744
|
+
function isFormatPainterArmed(editor) {
|
|
2745
|
+
return painterStates.get(editor)?.armed === true;
|
|
2746
|
+
}
|
|
2747
|
+
function captureFormatMarks(editor) {
|
|
2748
|
+
const { selection, storedMarks } = editor.state;
|
|
2749
|
+
const marks = selection.empty ? storedMarks ?? selection.$from.marks() : selection.$from.marks();
|
|
2750
|
+
return marks.filter((mark) => mark.type.name !== "link");
|
|
2751
|
+
}
|
|
2752
|
+
function notifyToolbar(editor) {
|
|
2753
|
+
if (editor.isDestroyed) return;
|
|
2754
|
+
editor.view.dispatch(editor.state.tr.setMeta("formatPainter", true));
|
|
2755
|
+
}
|
|
2756
|
+
function armFormatPainter(editor) {
|
|
2757
|
+
const marks = captureFormatMarks(editor);
|
|
2758
|
+
if (marks.length === 0) {
|
|
2759
|
+
showMessage(tr("\u5F53\u524D\u5149\u6807\u5904\u6CA1\u6709\u53EF\u590D\u5236\u7684\u683C\u5F0F"), { type: "warning" });
|
|
2760
|
+
return false;
|
|
2761
|
+
}
|
|
2762
|
+
painterStates.set(editor, { armed: true, marks });
|
|
2763
|
+
notifyToolbar(editor);
|
|
2764
|
+
return true;
|
|
2765
|
+
}
|
|
2766
|
+
function cancelFormatPainter(editor) {
|
|
2767
|
+
painterStates.set(editor, { armed: false, marks: [] });
|
|
2768
|
+
notifyToolbar(editor);
|
|
2769
|
+
}
|
|
2770
|
+
function applyFormatPainter(editor) {
|
|
2771
|
+
const state = painterStates.get(editor);
|
|
2772
|
+
if (!state?.armed || editor.isDestroyed) return false;
|
|
2773
|
+
const { from, to, empty } = editor.state.selection;
|
|
2774
|
+
if (empty) return false;
|
|
2775
|
+
painterStates.set(editor, { armed: false, marks: [] });
|
|
2776
|
+
const tr2 = editor.state.tr;
|
|
2777
|
+
const linkMarks = [];
|
|
2778
|
+
editor.state.doc.nodesBetween(from, to, (node, pos) => {
|
|
2779
|
+
if (!node.isText) return;
|
|
2780
|
+
node.marks.forEach((mark) => {
|
|
2781
|
+
if (mark.type.name !== "link") return;
|
|
2782
|
+
linkMarks.push({ from: Math.max(from, pos), to: Math.min(to, pos + node.nodeSize), mark });
|
|
2783
|
+
});
|
|
2784
|
+
});
|
|
2785
|
+
tr2.removeMark(from, to);
|
|
2786
|
+
state.marks.forEach((mark) => tr2.addMark(from, to, mark));
|
|
2787
|
+
linkMarks.forEach(({ from: start, to: end, mark }) => tr2.addMark(start, end, mark));
|
|
2788
|
+
editor.view.dispatch(tr2);
|
|
2789
|
+
editor.commands.focus();
|
|
2790
|
+
return true;
|
|
2791
|
+
}
|
|
2792
|
+
function installFormatPainterListeners(editor) {
|
|
2793
|
+
const dom = editor.view.dom;
|
|
2794
|
+
const handleMouseUp = () => {
|
|
2795
|
+
window.setTimeout(() => {
|
|
2796
|
+
if (!editor.isDestroyed) applyFormatPainter(editor);
|
|
2797
|
+
}, 0);
|
|
2798
|
+
};
|
|
2799
|
+
const handleKeyDown = (event) => {
|
|
2800
|
+
if (event.key === "Escape" && isFormatPainterArmed(editor)) {
|
|
2801
|
+
cancelFormatPainter(editor);
|
|
2802
|
+
}
|
|
2803
|
+
};
|
|
2804
|
+
const handleKeyUp = (event) => {
|
|
2805
|
+
if (event.key === "Escape" || editor.isDestroyed) return;
|
|
2806
|
+
applyFormatPainter(editor);
|
|
2807
|
+
};
|
|
2808
|
+
dom.addEventListener("mouseup", handleMouseUp);
|
|
2809
|
+
dom.addEventListener("keydown", handleKeyDown);
|
|
2810
|
+
dom.addEventListener("keyup", handleKeyUp);
|
|
2811
|
+
return () => {
|
|
2812
|
+
dom.removeEventListener("mouseup", handleMouseUp);
|
|
2813
|
+
dom.removeEventListener("keydown", handleKeyDown);
|
|
2814
|
+
dom.removeEventListener("keyup", handleKeyUp);
|
|
2815
|
+
};
|
|
2816
|
+
}
|
|
2817
|
+
var listenerCleanups = /* @__PURE__ */ new WeakMap();
|
|
2818
|
+
function attachFormatPainter(editor) {
|
|
2819
|
+
listenerCleanups.set(editor, installFormatPainterListeners(editor));
|
|
2820
|
+
}
|
|
2821
|
+
function detachFormatPainter(editor) {
|
|
2822
|
+
listenerCleanups.get(editor)?.();
|
|
2823
|
+
listenerCleanups.delete(editor);
|
|
2824
|
+
}
|
|
2825
|
+
var formatPainterPlugin = {
|
|
2826
|
+
name: "format-painter",
|
|
2827
|
+
category: "format",
|
|
2828
|
+
dependencies: ["starter"],
|
|
2829
|
+
defaultEnabled: true,
|
|
2830
|
+
tiptapExtensions: () => [],
|
|
2831
|
+
toolbarItems: () => [
|
|
2832
|
+
{
|
|
2833
|
+
id: "format-painter",
|
|
2834
|
+
type: "button",
|
|
2835
|
+
group: "format",
|
|
2836
|
+
order: 25,
|
|
2837
|
+
label: tr("\u683C\u5F0F\u5237"),
|
|
2838
|
+
icon: /* @__PURE__ */ jsx(IconFormatPainter, {}),
|
|
2839
|
+
isActive: (editor) => isFormatPainterArmed(editor),
|
|
2840
|
+
onClick: (editor) => {
|
|
2841
|
+
if (isFormatPainterArmed(editor)) {
|
|
2842
|
+
cancelFormatPainter(editor);
|
|
2843
|
+
return;
|
|
2844
|
+
}
|
|
2845
|
+
armFormatPainter(editor);
|
|
2846
|
+
}
|
|
2847
|
+
}
|
|
2848
|
+
],
|
|
2849
|
+
onEditorCreate: (editor) => {
|
|
2850
|
+
attachFormatPainter(editor);
|
|
2851
|
+
},
|
|
2852
|
+
onEditorDestroy: (editor) => {
|
|
2853
|
+
detachFormatPainter(editor);
|
|
2854
|
+
}
|
|
2855
|
+
};
|
|
2856
|
+
var HighlightGradient = Extension.create({
|
|
2857
|
+
name: "highlightGradient",
|
|
2858
|
+
addGlobalAttributes() {
|
|
2859
|
+
return [
|
|
2860
|
+
{
|
|
2861
|
+
types: ["highlight"],
|
|
2862
|
+
attributes: {
|
|
2863
|
+
gradient: {
|
|
2864
|
+
default: null,
|
|
2865
|
+
parseHTML: (element) => element.style.backgroundImage?.replace(/['"]+/g, "") || null,
|
|
2866
|
+
renderHTML: (attributes) => {
|
|
2867
|
+
if (!attributes.gradient) return {};
|
|
2868
|
+
return { style: `background-image: ${attributes.gradient}` };
|
|
2869
|
+
}
|
|
2870
|
+
}
|
|
2871
|
+
}
|
|
2872
|
+
}
|
|
2873
|
+
];
|
|
2874
|
+
}
|
|
2875
|
+
});
|
|
2876
|
+
var backgroundColorPlugin = {
|
|
2877
|
+
name: "background-color",
|
|
2878
|
+
category: "format",
|
|
2879
|
+
dependencies: ["starter"],
|
|
2880
|
+
defaultEnabled: true,
|
|
2881
|
+
tiptapExtensions: () => [
|
|
2882
|
+
Highlight.configure({
|
|
2883
|
+
multicolor: true
|
|
2884
|
+
}),
|
|
2885
|
+
HighlightGradient
|
|
2886
|
+
],
|
|
2887
|
+
toolbarItems: () => [
|
|
2888
|
+
{
|
|
2889
|
+
id: "background-color",
|
|
2890
|
+
type: "color-picker",
|
|
2891
|
+
group: "color",
|
|
2892
|
+
order: 31,
|
|
2893
|
+
label: tr("\u80CC\u666F\u989C\u8272"),
|
|
2894
|
+
icon: /* @__PURE__ */ jsx(IconBackgroundColor, {}),
|
|
2895
|
+
// 首次点击左侧图标区时应用编辑器默认高亮色
|
|
2896
|
+
initialColor: "#FADB14",
|
|
2897
|
+
getActiveValue: (editor) => {
|
|
2898
|
+
const attrs = editor.getAttributes("highlight");
|
|
2899
|
+
return attrs.gradient || attrs.color || null;
|
|
2900
|
+
},
|
|
2901
|
+
onColorSelect: (editor, color, options) => {
|
|
2902
|
+
const chain = options?.focus === false ? editor.chain() : editor.chain().focus();
|
|
2903
|
+
chain.setMark("highlight", { color, gradient: null }).run();
|
|
2904
|
+
},
|
|
2905
|
+
onGradientSelect: (editor, gradient) => {
|
|
2906
|
+
editor.chain().focus().setMark("highlight", { color: null, gradient }).run();
|
|
2907
|
+
},
|
|
2908
|
+
onClear: (editor) => {
|
|
2909
|
+
editor.chain().focus().unsetHighlight().run();
|
|
2910
|
+
}
|
|
2911
|
+
}
|
|
2912
|
+
],
|
|
2913
|
+
// AI 能力声明:mark 类——文字背景色(@tiptap/extension-highlight 的
|
|
2914
|
+
// setHighlight/unsetHighlight 命令)。set 幂等设色;清除走 unsetBackground。
|
|
2915
|
+
aiCommands: () => [
|
|
2916
|
+
{
|
|
2917
|
+
id: "background-color.setBackground",
|
|
2918
|
+
zhLabel: tr("\u8BBE\u7F6E\u80CC\u666F\u989C\u8272"),
|
|
2919
|
+
kind: "mark",
|
|
2920
|
+
description: tr(
|
|
2921
|
+
"\u7ED9\u951A\u6587\u672C\u8BBE\u7F6E\u80CC\u666F\u989C\u8272\u3002\u53C2\u6570 color \u4E3A CSS \u989C\u8272\u503C\uFF08\u5982 #ffff00\uFF09\uFF0C\u7F3A\u7701\u7528\u7F16\u8F91\u5668\u9ED8\u8BA4\u80CC\u666F\u8272\u3002\u91CD\u590D\u8BBE\u7F6E\u540C\u8272\u5E42\u7B49\u3002\u6E05\u9664\u80CC\u666F\u8272\u7528 background-color.unsetBackground\u3002"
|
|
2922
|
+
),
|
|
2923
|
+
params: [
|
|
2924
|
+
{
|
|
2925
|
+
key: "color",
|
|
2926
|
+
type: "string",
|
|
2927
|
+
description: tr("\u53EF\u9009\uFF1ACSS \u80CC\u666F\u8272\u503C\uFF08\u5982 #ffff00 \u9EC4\u3001#d4edda \u7EFF\uFF09\uFF1B\u7F3A\u7701=\u9ED8\u8BA4\u80CC\u666F\u8272")
|
|
2928
|
+
}
|
|
2929
|
+
],
|
|
2930
|
+
apply: createMarkApply((chain, _range, params) => {
|
|
2931
|
+
const color = params?.color;
|
|
2932
|
+
return typeof color === "string" && color.trim() ? chain.setMark("highlight", { color, gradient: null }) : chain.setMark("highlight", { color: null, gradient: null });
|
|
2933
|
+
})
|
|
2934
|
+
},
|
|
2935
|
+
{
|
|
2936
|
+
id: "background-color.unsetBackground",
|
|
2937
|
+
zhLabel: tr("\u6E05\u9664\u80CC\u666F\u989C\u8272"),
|
|
2938
|
+
kind: "mark",
|
|
2939
|
+
description: tr("\u6E05\u9664\u951A\u6587\u672C\u7684\u80CC\u666F\u989C\u8272\u4E0E\u6E10\u53D8\uFF08\u6587\u5B57\u4FDD\u7559\uFF09\u3002\u65E0\u53C2\u6570\u3002"),
|
|
2940
|
+
apply: createMarkApply((chain) => chain.unsetHighlight())
|
|
2941
|
+
}
|
|
2942
|
+
]
|
|
2943
|
+
};
|
|
2747
2944
|
|
|
2748
2945
|
// src/editor/styles/glassFragments.ts
|
|
2749
2946
|
function glassSurfaceCss({ token, getAlphaColor, glassEffect, borderRadius }, opts = {}) {
|
|
@@ -4073,7 +4270,7 @@ var tablePlugin = {
|
|
|
4073
4270
|
group: "insert",
|
|
4074
4271
|
order: 60,
|
|
4075
4272
|
label: tr("\u8868\u683C"),
|
|
4076
|
-
icon: /* @__PURE__ */ jsx(
|
|
4273
|
+
icon: /* @__PURE__ */ jsx(IconTable, {}),
|
|
4077
4274
|
isActive: (editor) => editor.isActive("table"),
|
|
4078
4275
|
onClick: (editor, rows, cols) => insertTableBelowSelection(editor, { rows, cols, withHeaderRow: true })
|
|
4079
4276
|
}
|
|
@@ -4082,7 +4279,7 @@ var tablePlugin = {
|
|
|
4082
4279
|
{
|
|
4083
4280
|
id: "table",
|
|
4084
4281
|
label: tr("\u8868\u683C"),
|
|
4085
|
-
icon: /* @__PURE__ */ jsx(
|
|
4282
|
+
icon: /* @__PURE__ */ jsx(IconTable, {}),
|
|
4086
4283
|
category: tr("\u9AD8\u7EA7\u5757"),
|
|
4087
4284
|
order: 20,
|
|
4088
4285
|
description: tr("\u63D2\u5165 3x3 \u8868\u683C"),
|
|
@@ -4419,7 +4616,7 @@ var imagePlugin = {
|
|
|
4419
4616
|
group: "insert",
|
|
4420
4617
|
order: 61,
|
|
4421
4618
|
label: tr("\u56FE\u7247"),
|
|
4422
|
-
icon: /* @__PURE__ */ jsx(
|
|
4619
|
+
icon: /* @__PURE__ */ jsx(IconImage, {}),
|
|
4423
4620
|
onClick: (editor) => runInsertImage(editor, config)
|
|
4424
4621
|
}
|
|
4425
4622
|
],
|
|
@@ -4427,7 +4624,7 @@ var imagePlugin = {
|
|
|
4427
4624
|
{
|
|
4428
4625
|
id: "image",
|
|
4429
4626
|
label: tr("\u56FE\u7247"),
|
|
4430
|
-
icon: /* @__PURE__ */ jsx(
|
|
4627
|
+
icon: /* @__PURE__ */ jsx(IconImage, {}),
|
|
4431
4628
|
category: tr("\u9AD8\u7EA7\u5757"),
|
|
4432
4629
|
order: 30,
|
|
4433
4630
|
description: tr("\u63D2\u5165\u56FE\u7247\u6587\u4EF6"),
|
|
@@ -4449,46 +4646,792 @@ var imagePlugin = {
|
|
|
4449
4646
|
}
|
|
4450
4647
|
]
|
|
4451
4648
|
};
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4649
|
+
|
|
4650
|
+
// src/editor/utils/sanitizeUrl.ts
|
|
4651
|
+
var DATA_IMAGE_RE = /^data:image\/[a-z0-9.+-]+;base64,/i;
|
|
4652
|
+
function sanitizeUrl(url, options) {
|
|
4653
|
+
const trimmed = url.trim();
|
|
4654
|
+
if (!trimmed) return null;
|
|
4655
|
+
if (/^(https?:|mailto:|tel:|ftp:|ftps:)/i.test(trimmed)) return trimmed;
|
|
4656
|
+
if (/^[/?#]/.test(trimmed)) return trimmed;
|
|
4657
|
+
if (options?.allowDataImage && DATA_IMAGE_RE.test(trimmed)) return trimmed;
|
|
4658
|
+
if (options?.allowDataMedia && DATA_MEDIA_URI_PATTERN.test(trimmed)) return trimmed;
|
|
4659
|
+
if (/^[a-z0-9.-]+\.[a-z]{2,}/i.test(trimmed)) return `https://${trimmed}`;
|
|
4660
|
+
return null;
|
|
4661
|
+
}
|
|
4662
|
+
|
|
4663
|
+
// src/editor/plugins/builtin/video/style.ts
|
|
4664
|
+
var useVideoStyles = createStyles(({ css, token, sizeToken }) => {
|
|
4665
|
+
const { borderRadius } = sizeToken;
|
|
4666
|
+
return {
|
|
4667
|
+
wrapper: css`
|
|
4668
|
+
position: relative;
|
|
4669
|
+
margin: 0.75em 0;
|
|
4670
|
+
border-radius: ${borderRadius}px;
|
|
4671
|
+
`,
|
|
4672
|
+
video: css`
|
|
4673
|
+
display: block;
|
|
4674
|
+
width: 100%;
|
|
4675
|
+
max-width: 100%;
|
|
4676
|
+
height: auto;
|
|
4677
|
+
border-radius: ${borderRadius}px;
|
|
4678
|
+
background: #000;
|
|
4679
|
+
`,
|
|
4680
|
+
toolbar: css`
|
|
4681
|
+
position: absolute;
|
|
4682
|
+
top: 8px;
|
|
4683
|
+
right: 8px;
|
|
4684
|
+
display: flex;
|
|
4685
|
+
gap: 4px;
|
|
4686
|
+
opacity: 0;
|
|
4687
|
+
transition: opacity 0.2s;
|
|
4688
|
+
background: ${token.colorBgElevated};
|
|
4689
|
+
border-radius: ${borderRadius}px;
|
|
4690
|
+
padding: 2px 4px;
|
|
4691
|
+
box-shadow: ${token.boxShadowSecondary};
|
|
4692
|
+
|
|
4693
|
+
/* 悬停在卡片上时显示操作按钮(wrapper 为直接父级 div) */
|
|
4694
|
+
div:hover > & {
|
|
4695
|
+
opacity: 1;
|
|
4696
|
+
}
|
|
4697
|
+
`,
|
|
4698
|
+
uploadWrapper: css`
|
|
4699
|
+
margin: 0.75em 0;
|
|
4700
|
+
`,
|
|
4701
|
+
uploadCard: css`
|
|
4702
|
+
display: flex;
|
|
4703
|
+
align-items: center;
|
|
4704
|
+
gap: 12px;
|
|
4705
|
+
box-sizing: border-box;
|
|
4706
|
+
width: 100%;
|
|
4707
|
+
padding: 12px 14px;
|
|
4708
|
+
border: 1px dashed ${token.colorBorderSecondary};
|
|
4709
|
+
border-radius: ${borderRadius}px;
|
|
4710
|
+
background: ${token.colorFillQuaternary};
|
|
4711
|
+
`,
|
|
4712
|
+
uploadIcon: css`
|
|
4713
|
+
flex-shrink: 0;
|
|
4714
|
+
font-size: 22px;
|
|
4715
|
+
color: ${token.colorPrimary};
|
|
4716
|
+
`,
|
|
4717
|
+
uploadMeta: css`
|
|
4718
|
+
display: flex;
|
|
4719
|
+
flex: 1;
|
|
4720
|
+
flex-direction: column;
|
|
4721
|
+
gap: 4px;
|
|
4722
|
+
min-width: 0;
|
|
4723
|
+
`,
|
|
4724
|
+
uploadName: css`
|
|
4725
|
+
overflow: hidden;
|
|
4726
|
+
color: ${token.colorText};
|
|
4727
|
+
text-overflow: ellipsis;
|
|
4728
|
+
white-space: nowrap;
|
|
4729
|
+
`,
|
|
4730
|
+
uploadInfo: css`
|
|
4731
|
+
font-size: 12px;
|
|
4732
|
+
color: ${token.colorTextTertiary};
|
|
4733
|
+
`,
|
|
4734
|
+
progressTrack: css`
|
|
4735
|
+
height: 4px;
|
|
4736
|
+
overflow: hidden;
|
|
4737
|
+
border-radius: 2px;
|
|
4738
|
+
background: ${token.colorFillSecondary};
|
|
4739
|
+
`,
|
|
4740
|
+
progressBar: css`
|
|
4741
|
+
height: 100%;
|
|
4742
|
+
border-radius: 2px;
|
|
4743
|
+
background: ${token.colorPrimary};
|
|
4744
|
+
transition: width 0.2s;
|
|
4745
|
+
`
|
|
4746
|
+
};
|
|
4468
4747
|
});
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4748
|
+
|
|
4749
|
+
// src/editor/plugins/builtin/video/videoSource.ts
|
|
4750
|
+
function pickVideoFile() {
|
|
4751
|
+
return pickFile("video/*");
|
|
4752
|
+
}
|
|
4753
|
+
function formatSizeLimit2(size) {
|
|
4754
|
+
const mb = size / (1024 * 1024);
|
|
4755
|
+
return `${Number.isInteger(mb) ? mb : mb.toFixed(1)}MB`;
|
|
4756
|
+
}
|
|
4757
|
+
function formatFileSize(size) {
|
|
4758
|
+
if (!Number.isFinite(size) || size <= 0) return "";
|
|
4759
|
+
const units = ["B", "KB", "MB", "GB"];
|
|
4760
|
+
let value = size;
|
|
4761
|
+
let unit = 0;
|
|
4762
|
+
while (value >= 1024 && unit < units.length - 1) {
|
|
4763
|
+
value /= 1024;
|
|
4764
|
+
unit += 1;
|
|
4765
|
+
}
|
|
4766
|
+
return `${value >= 10 || unit === 0 ? Math.round(value) : value.toFixed(1)} ${units[unit]}`;
|
|
4767
|
+
}
|
|
4768
|
+
function formatVideoMeta(name, size, mime) {
|
|
4769
|
+
const ext = name.includes(".") ? name.split(".").pop().toUpperCase() : "";
|
|
4770
|
+
const type = ext || (mime.includes("/") ? mime.split("/")[1].toUpperCase() : "");
|
|
4771
|
+
return [type, formatFileSize(size)].filter(Boolean).join(" \xB7 ");
|
|
4772
|
+
}
|
|
4773
|
+
function readFileAsDataUrl(file, onProgress) {
|
|
4774
|
+
return new Promise((resolve, reject) => {
|
|
4775
|
+
const reader = new FileReader();
|
|
4776
|
+
reader.onprogress = (event) => {
|
|
4777
|
+
if (event.lengthComputable) onProgress?.(Math.round(event.loaded / event.total * 100));
|
|
4778
|
+
};
|
|
4779
|
+
reader.onload = () => {
|
|
4780
|
+
if (typeof reader.result === "string") {
|
|
4781
|
+
resolve(reader.result);
|
|
4782
|
+
} else {
|
|
4783
|
+
reject(new Error(tr("\u6587\u4EF6\u8BFB\u53D6\u5931\u8D25")));
|
|
4784
|
+
}
|
|
4785
|
+
};
|
|
4786
|
+
reader.onerror = () => reject(new Error(tr("\u6587\u4EF6\u8BFB\u53D6\u5931\u8D25")));
|
|
4787
|
+
reader.readAsDataURL(file);
|
|
4788
|
+
});
|
|
4789
|
+
}
|
|
4790
|
+
function normalizeVideoUrl(raw) {
|
|
4791
|
+
const value = sanitizeUrl(raw, { allowDataMedia: true });
|
|
4792
|
+
if (!value || /^(mailto:|tel:|ftp:|ftps:)/i.test(value)) return null;
|
|
4793
|
+
return value;
|
|
4794
|
+
}
|
|
4795
|
+
function validateVideoFile(file, config) {
|
|
4796
|
+
if (config.maxSize && config.maxSize > 0 && file.size > config.maxSize) {
|
|
4797
|
+
showMessage(tr("\u89C6\u9891\u5927\u5C0F\u4E0D\u80FD\u8D85\u8FC7 ${0}", [formatSizeLimit2(config.maxSize)]), { type: "warning" });
|
|
4798
|
+
return false;
|
|
4799
|
+
}
|
|
4800
|
+
return true;
|
|
4801
|
+
}
|
|
4802
|
+
async function resolveVideoFile(file, config, onProgress) {
|
|
4803
|
+
const report = (percent) => {
|
|
4804
|
+
onProgress?.(Math.max(0, Math.min(100, Math.round(percent))));
|
|
4805
|
+
};
|
|
4806
|
+
try {
|
|
4807
|
+
const raw = config.uploadVideo ? await config.uploadVideo(file, report) : await readFileAsDataUrl(file, report);
|
|
4808
|
+
const src = raw ? normalizeVideoUrl(raw) : null;
|
|
4809
|
+
if (!src) {
|
|
4810
|
+
showMessage(tr("\u89C6\u9891\u4E0A\u4F20\u5931\u8D25"), { type: "warning" });
|
|
4811
|
+
return null;
|
|
4812
|
+
}
|
|
4813
|
+
return src;
|
|
4814
|
+
} catch (error) {
|
|
4815
|
+
showMessage(error instanceof Error ? error.message : tr("\u89C6\u9891\u4E0A\u4F20\u5931\u8D25"), { type: "warning" });
|
|
4816
|
+
return null;
|
|
4817
|
+
}
|
|
4818
|
+
}
|
|
4819
|
+
var UPLOAD_NODE_NAME = "videoUpload";
|
|
4820
|
+
var uploadSeq = 0;
|
|
4821
|
+
function createUploadId() {
|
|
4822
|
+
uploadSeq += 1;
|
|
4823
|
+
return `video-upload-${Date.now()}-${uploadSeq}`;
|
|
4824
|
+
}
|
|
4825
|
+
function findPlaceholder(doc, uploadId) {
|
|
4826
|
+
let found = null;
|
|
4827
|
+
doc.descendants((node, pos) => {
|
|
4828
|
+
if (found) return false;
|
|
4829
|
+
if (node.type.name === UPLOAD_NODE_NAME && node.attrs.uploadId === uploadId) {
|
|
4830
|
+
found = { pos, node };
|
|
4831
|
+
return false;
|
|
4832
|
+
}
|
|
4833
|
+
return true;
|
|
4834
|
+
});
|
|
4835
|
+
return found;
|
|
4836
|
+
}
|
|
4837
|
+
function createPlaceholderAttrs(file, uploadId) {
|
|
4838
|
+
return { uploadId, name: file.name, size: file.size, mime: file.type, progress: 0 };
|
|
4839
|
+
}
|
|
4840
|
+
function collapseSelectionIfCovering(editor, from, to) {
|
|
4841
|
+
if (editor.isDestroyed) return;
|
|
4842
|
+
const { selection, doc } = editor.state;
|
|
4843
|
+
const covers = selection.from < to && selection.to > from;
|
|
4844
|
+
if (!covers) return;
|
|
4845
|
+
const after = Math.min(to, doc.content.size);
|
|
4846
|
+
const next = Selection.near(doc.resolve(after), 1);
|
|
4847
|
+
editor.view.dispatch(editor.state.tr.setSelection(next));
|
|
4848
|
+
}
|
|
4849
|
+
function insertNodeAtBookmark(editor, bookmark, nodeJson) {
|
|
4850
|
+
if (editor.isDestroyed) return false;
|
|
4851
|
+
try {
|
|
4852
|
+
const selection = bookmark.resolve(editor.state.doc);
|
|
4853
|
+
if (selection instanceof NodeSelection) {
|
|
4854
|
+
return editor.chain().focus().insertContentAt(selection.to, nodeJson).run();
|
|
4855
|
+
}
|
|
4856
|
+
editor.view.dispatch(editor.state.tr.setSelection(selection));
|
|
4857
|
+
} catch {
|
|
4858
|
+
}
|
|
4859
|
+
return editor.chain().focus().insertContent(nodeJson).run();
|
|
4860
|
+
}
|
|
4861
|
+
function insertVideoUploadPlaceholder(editor, bookmark, file) {
|
|
4862
|
+
const uploadId = createUploadId();
|
|
4863
|
+
const attrs = createPlaceholderAttrs(file, uploadId);
|
|
4864
|
+
const ok = insertNodeAtBookmark(editor, bookmark, { type: UPLOAD_NODE_NAME, attrs });
|
|
4865
|
+
if (!ok) return null;
|
|
4866
|
+
const found = findPlaceholder(editor.state.doc, uploadId);
|
|
4867
|
+
if (found) collapseSelectionIfCovering(editor, found.pos, found.pos + found.node.nodeSize);
|
|
4868
|
+
return uploadId;
|
|
4869
|
+
}
|
|
4870
|
+
function replaceVideoWithPlaceholder(editor, pos, nodeSize, file) {
|
|
4871
|
+
if (editor.isDestroyed) return null;
|
|
4872
|
+
const node = editor.state.doc.nodeAt(pos);
|
|
4873
|
+
if (!node || node.type.name !== "video") return null;
|
|
4874
|
+
const uploadId = createUploadId();
|
|
4875
|
+
const placeholder = editor.schema.nodes[UPLOAD_NODE_NAME].create(createPlaceholderAttrs(file, uploadId));
|
|
4876
|
+
editor.view.dispatch(editor.state.tr.replaceWith(pos, pos + nodeSize, placeholder));
|
|
4877
|
+
collapseSelectionIfCovering(editor, pos, pos + placeholder.nodeSize);
|
|
4878
|
+
return uploadId;
|
|
4879
|
+
}
|
|
4880
|
+
function updateVideoUploadProgress(editor, uploadId, progress) {
|
|
4881
|
+
if (editor.isDestroyed) return;
|
|
4882
|
+
const found = findPlaceholder(editor.state.doc, uploadId);
|
|
4883
|
+
if (!found) return;
|
|
4884
|
+
const next = Math.max(0, Math.min(100, Math.round(progress)));
|
|
4885
|
+
if (found.node.attrs.progress === next) return;
|
|
4886
|
+
editor.view.dispatch(
|
|
4887
|
+
editor.state.tr.setNodeMarkup(found.pos, void 0, { ...found.node.attrs, progress: next })
|
|
4888
|
+
);
|
|
4889
|
+
}
|
|
4890
|
+
function finishVideoUpload(editor, uploadId, src) {
|
|
4891
|
+
if (editor.isDestroyed) return false;
|
|
4892
|
+
const found = findPlaceholder(editor.state.doc, uploadId);
|
|
4893
|
+
if (!found) return false;
|
|
4894
|
+
const video = editor.schema.nodes.video.create({ src });
|
|
4895
|
+
editor.view.dispatch(editor.state.tr.replaceWith(found.pos, found.pos + found.node.nodeSize, video));
|
|
4896
|
+
collapseSelectionIfCovering(editor, found.pos, found.pos + video.nodeSize);
|
|
4897
|
+
return true;
|
|
4898
|
+
}
|
|
4899
|
+
function removeVideoUploadPlaceholder(editor, uploadId) {
|
|
4900
|
+
if (editor.isDestroyed) return;
|
|
4901
|
+
const found = findPlaceholder(editor.state.doc, uploadId);
|
|
4902
|
+
if (!found) return;
|
|
4903
|
+
editor.view.dispatch(editor.state.tr.delete(found.pos, found.pos + found.node.nodeSize));
|
|
4904
|
+
}
|
|
4905
|
+
function restoreVideoUpload(editor, uploadId, attrs) {
|
|
4906
|
+
if (editor.isDestroyed) return;
|
|
4907
|
+
const found = findPlaceholder(editor.state.doc, uploadId);
|
|
4908
|
+
if (!found) return;
|
|
4909
|
+
const video = editor.schema.nodes.video.create(attrs);
|
|
4910
|
+
editor.view.dispatch(editor.state.tr.replaceWith(found.pos, found.pos + found.node.nodeSize, video));
|
|
4911
|
+
collapseSelectionIfCovering(editor, found.pos, found.pos + video.nodeSize);
|
|
4912
|
+
}
|
|
4913
|
+
function removeOrphanVideoUploads(editor) {
|
|
4914
|
+
const positions = [];
|
|
4915
|
+
editor.state.doc.descendants((node, pos) => {
|
|
4916
|
+
if (node.type.name === UPLOAD_NODE_NAME) positions.push(pos);
|
|
4917
|
+
return true;
|
|
4918
|
+
});
|
|
4919
|
+
if (positions.length === 0) return;
|
|
4920
|
+
const tr2 = editor.state.tr;
|
|
4921
|
+
for (let i = positions.length - 1; i >= 0; i -= 1) {
|
|
4922
|
+
const node = tr2.doc.nodeAt(positions[i]);
|
|
4923
|
+
if (node) tr2.delete(positions[i], positions[i] + node.nodeSize);
|
|
4924
|
+
}
|
|
4925
|
+
editor.view.dispatch(tr2);
|
|
4926
|
+
}
|
|
4927
|
+
function createVideoUploadProgressReporter(editor, uploadId) {
|
|
4928
|
+
let last = -1;
|
|
4929
|
+
return (percent) => {
|
|
4930
|
+
const stepped = Math.round(percent / 5) * 5;
|
|
4931
|
+
if (stepped === last) return;
|
|
4932
|
+
last = stepped;
|
|
4933
|
+
updateVideoUploadProgress(editor, uploadId, stepped);
|
|
4934
|
+
};
|
|
4935
|
+
}
|
|
4936
|
+
var VideoView = memo(({ node, deleteNode, editor, extension, getPos }) => {
|
|
4937
|
+
const { styles } = useVideoStyles();
|
|
4938
|
+
const src = node.attrs.src;
|
|
4939
|
+
const poster = node.attrs.poster ?? void 0;
|
|
4940
|
+
const editable = editor.isEditable;
|
|
4941
|
+
const { uploadVideo, maxSize } = extension.options;
|
|
4942
|
+
const handleReplace = useCallback(async () => {
|
|
4943
|
+
if (!editor.isEditable) return;
|
|
4944
|
+
const pos = getPos();
|
|
4945
|
+
if (typeof pos !== "number") return;
|
|
4946
|
+
const oldAttrs = {
|
|
4947
|
+
src: node.attrs.src,
|
|
4948
|
+
poster: node.attrs.poster ?? null
|
|
4949
|
+
};
|
|
4950
|
+
const file = await pickVideoFile();
|
|
4951
|
+
if (!file || editor.isDestroyed) return;
|
|
4952
|
+
const config = { uploadVideo, maxSize };
|
|
4953
|
+
if (!validateVideoFile(file, config)) return;
|
|
4954
|
+
const uploadId = replaceVideoWithPlaceholder(editor, pos, node.nodeSize, file);
|
|
4955
|
+
if (!uploadId) return;
|
|
4956
|
+
const nextSrc = await resolveVideoFile(file, config, createVideoUploadProgressReporter(editor, uploadId));
|
|
4957
|
+
if (editor.isDestroyed) return;
|
|
4958
|
+
if (nextSrc) finishVideoUpload(editor, uploadId, nextSrc);
|
|
4959
|
+
else restoreVideoUpload(editor, uploadId, oldAttrs);
|
|
4960
|
+
}, [editor, getPos, node, uploadVideo, maxSize]);
|
|
4961
|
+
const handleDelete = useCallback(() => {
|
|
4962
|
+
if (!editable) return;
|
|
4963
|
+
deleteNode();
|
|
4964
|
+
}, [editable, deleteNode]);
|
|
4965
|
+
return /* @__PURE__ */ jsxs(NodeViewWrapper, { className: styles.wrapper, children: [
|
|
4966
|
+
/* @__PURE__ */ jsx("video", { className: styles.video, src, poster, controls: true, preload: "metadata" }),
|
|
4967
|
+
editable && /* @__PURE__ */ jsxs("div", { className: styles.toolbar, children: [
|
|
4968
|
+
/* @__PURE__ */ jsx(Button, { type: "text", size: "small", icon: /* @__PURE__ */ jsx(IconEdit, {}), onClick: handleReplace, children: tr("\u91CD\u65B0\u9009\u62E9") }),
|
|
4969
|
+
/* @__PURE__ */ jsx(Button, { type: "text", size: "small", icon: /* @__PURE__ */ jsx(IconDelete, {}), onClick: handleDelete, danger: true, children: tr("\u5220\u9664") })
|
|
4970
|
+
] })
|
|
4971
|
+
] });
|
|
4972
|
+
});
|
|
4973
|
+
var VideoView_default = VideoView;
|
|
4974
|
+
var VideoUploadView = memo(({ node }) => {
|
|
4975
|
+
const { styles } = useVideoStyles();
|
|
4976
|
+
const name = node.attrs.name || tr("\u89C6\u9891");
|
|
4977
|
+
const size = typeof node.attrs.size === "number" ? node.attrs.size : 0;
|
|
4978
|
+
const mime = node.attrs.mime || "";
|
|
4979
|
+
const progress = typeof node.attrs.progress === "number" ? node.attrs.progress : 0;
|
|
4980
|
+
const meta = formatVideoMeta(name, size, mime);
|
|
4981
|
+
return /* @__PURE__ */ jsx(NodeViewWrapper, { className: styles.uploadWrapper, children: /* @__PURE__ */ jsxs("div", { className: styles.uploadCard, children: [
|
|
4982
|
+
/* @__PURE__ */ jsx(IconVideo, { size: 22, className: styles.uploadIcon }),
|
|
4983
|
+
/* @__PURE__ */ jsxs("div", { className: styles.uploadMeta, children: [
|
|
4984
|
+
/* @__PURE__ */ jsx("div", { className: styles.uploadName, children: name }),
|
|
4985
|
+
/* @__PURE__ */ jsxs("div", { className: styles.uploadInfo, children: [
|
|
4986
|
+
meta ? `${meta} \xB7 ` : "",
|
|
4987
|
+
tr("\u4E0A\u4F20\u4E2D ${0}%", [progress])
|
|
4988
|
+
] }),
|
|
4989
|
+
/* @__PURE__ */ jsx("div", { className: styles.progressTrack, children: /* @__PURE__ */ jsx("div", { className: styles.progressBar, style: { width: `${progress}%` } }) })
|
|
4990
|
+
] })
|
|
4991
|
+
] }) });
|
|
4992
|
+
});
|
|
4993
|
+
var VideoUploadView_default = VideoUploadView;
|
|
4994
|
+
var VideoNode = Node.create({
|
|
4995
|
+
name: "video",
|
|
4996
|
+
group: "block",
|
|
4997
|
+
atom: true,
|
|
4998
|
+
draggable: true,
|
|
4999
|
+
// 与图片一致:点击只落光标,不整块选中,避免打字时误删
|
|
5000
|
+
selectable: false,
|
|
5001
|
+
addOptions() {
|
|
5002
|
+
return { uploadVideo: void 0, maxSize: void 0 };
|
|
5003
|
+
},
|
|
5004
|
+
addAttributes() {
|
|
5005
|
+
return {
|
|
5006
|
+
src: {
|
|
5007
|
+
default: null,
|
|
5008
|
+
parseHTML: (element) => {
|
|
5009
|
+
const src = element.getAttribute("src");
|
|
5010
|
+
return src ? sanitizeUrl(src, { allowDataMedia: true }) : null;
|
|
5011
|
+
}
|
|
5012
|
+
},
|
|
5013
|
+
poster: {
|
|
5014
|
+
default: null,
|
|
5015
|
+
parseHTML: (element) => {
|
|
5016
|
+
const poster = element.getAttribute("poster");
|
|
5017
|
+
return poster ? sanitizeUrl(poster) : null;
|
|
5018
|
+
}
|
|
5019
|
+
}
|
|
5020
|
+
};
|
|
5021
|
+
},
|
|
5022
|
+
parseHTML() {
|
|
5023
|
+
return [{ tag: "video[src]" }];
|
|
5024
|
+
},
|
|
5025
|
+
renderHTML({ HTMLAttributes }) {
|
|
5026
|
+
return [
|
|
5027
|
+
"video",
|
|
5028
|
+
mergeAttributes(
|
|
5029
|
+
{ "data-type": "video", controls: "true", preload: "metadata", playsinline: "true" },
|
|
5030
|
+
HTMLAttributes
|
|
5031
|
+
)
|
|
5032
|
+
];
|
|
5033
|
+
},
|
|
5034
|
+
addNodeView() {
|
|
5035
|
+
return ReactNodeViewRenderer(VideoView_default);
|
|
5036
|
+
}
|
|
5037
|
+
});
|
|
5038
|
+
var VideoUploadNode = Node.create({
|
|
5039
|
+
name: "videoUpload",
|
|
5040
|
+
group: "block",
|
|
5041
|
+
atom: true,
|
|
5042
|
+
selectable: false,
|
|
5043
|
+
draggable: false,
|
|
5044
|
+
addAttributes() {
|
|
5045
|
+
return {
|
|
5046
|
+
uploadId: { default: "" },
|
|
5047
|
+
name: { default: "" },
|
|
5048
|
+
size: { default: 0 },
|
|
5049
|
+
mime: { default: "" },
|
|
5050
|
+
progress: { default: 0 }
|
|
5051
|
+
};
|
|
5052
|
+
},
|
|
5053
|
+
parseHTML() {
|
|
5054
|
+
return [];
|
|
5055
|
+
},
|
|
5056
|
+
renderHTML({ node }) {
|
|
5057
|
+
return ["div", { "data-type": "video-upload" }, node.attrs.name || tr("\u89C6\u9891\u4E0A\u4F20\u4E2D\u2026")];
|
|
5058
|
+
},
|
|
5059
|
+
addNodeView() {
|
|
5060
|
+
return ReactNodeViewRenderer(VideoUploadView_default);
|
|
5061
|
+
}
|
|
5062
|
+
});
|
|
5063
|
+
function startInsertVideo(editor, config) {
|
|
5064
|
+
void (async () => {
|
|
5065
|
+
const bookmark = editor.state.selection.getBookmark();
|
|
5066
|
+
const file = await pickVideoFile();
|
|
5067
|
+
if (!file || editor.isDestroyed) return;
|
|
5068
|
+
if (!validateVideoFile(file, config)) return;
|
|
5069
|
+
const uploadId = insertVideoUploadPlaceholder(editor, bookmark, file);
|
|
5070
|
+
if (!uploadId) {
|
|
5071
|
+
showMessage(tr("\u89C6\u9891\u63D2\u5165\u5931\u8D25"), { type: "warning" });
|
|
5072
|
+
return;
|
|
5073
|
+
}
|
|
5074
|
+
const src = await resolveVideoFile(file, config, createVideoUploadProgressReporter(editor, uploadId));
|
|
5075
|
+
if (editor.isDestroyed) return;
|
|
5076
|
+
if (src) finishVideoUpload(editor, uploadId, src);
|
|
5077
|
+
else removeVideoUploadPlaceholder(editor, uploadId);
|
|
5078
|
+
})().catch((error) => {
|
|
5079
|
+
showMessage(error instanceof Error ? error.message : tr("\u89C6\u9891\u63D2\u5165\u5931\u8D25"), { type: "warning" });
|
|
5080
|
+
});
|
|
5081
|
+
}
|
|
5082
|
+
var videoPlugin = {
|
|
5083
|
+
name: "video",
|
|
5084
|
+
category: "media",
|
|
5085
|
+
dependencies: ["starter"],
|
|
5086
|
+
defaultEnabled: true,
|
|
5087
|
+
tiptapExtensions: (config) => [
|
|
5088
|
+
VideoNode.configure({ uploadVideo: config.uploadVideo, maxSize: config.maxSize }),
|
|
5089
|
+
VideoUploadNode
|
|
5090
|
+
],
|
|
5091
|
+
toolbarItems: (config) => [
|
|
5092
|
+
{
|
|
5093
|
+
id: "video",
|
|
5094
|
+
type: "button",
|
|
5095
|
+
group: "insert",
|
|
5096
|
+
order: 62,
|
|
5097
|
+
label: tr("\u89C6\u9891"),
|
|
5098
|
+
icon: /* @__PURE__ */ jsx(IconVideo, {}),
|
|
5099
|
+
onClick: (editor) => startInsertVideo(editor, config)
|
|
5100
|
+
}
|
|
5101
|
+
],
|
|
5102
|
+
onEditorCreate: (editor) => {
|
|
5103
|
+
removeOrphanVideoUploads(editor);
|
|
5104
|
+
},
|
|
5105
|
+
// AI 能力声明:knowledge 类——视频块 HTML 写法(供 block_generate/set_content 产 HTML 参考)
|
|
5106
|
+
aiCommands: () => [
|
|
5107
|
+
{
|
|
5108
|
+
id: "video.htmlSyntax",
|
|
5109
|
+
zhLabel: tr("\u89C6\u9891 HTML \u5199\u6CD5"),
|
|
5110
|
+
kind: "knowledge",
|
|
5111
|
+
description: tr(
|
|
5112
|
+
'\u89C6\u9891\u7528 <video data-type="video" src="URL" controls poster="\u5C01\u9762URL"></video>\uFF0Csrc \u652F\u6301 http(s) \u5730\u5740\u4E0E data:video base64\uFF08\u672C\u5730\u6587\u4EF6\u515C\u5E95\uFF09\uFF1B\u5C01\u9762 poster \u53EF\u7701\u7565\u3002'
|
|
5113
|
+
)
|
|
5114
|
+
}
|
|
5115
|
+
]
|
|
5116
|
+
};
|
|
5117
|
+
|
|
5118
|
+
// src/editor/plugins/builtin/attachment/style.ts
|
|
5119
|
+
var useAttachmentStyles = createStyles(({ css, token, sizeToken }) => {
|
|
5120
|
+
const { borderRadius } = sizeToken;
|
|
5121
|
+
return {
|
|
5122
|
+
wrapper: css`
|
|
5123
|
+
position: relative;
|
|
5124
|
+
margin: 0.75em 0;
|
|
5125
|
+
`,
|
|
5126
|
+
card: css`
|
|
5127
|
+
display: flex;
|
|
5128
|
+
align-items: center;
|
|
5129
|
+
gap: 10px;
|
|
5130
|
+
box-sizing: border-box;
|
|
5131
|
+
width: 100%;
|
|
5132
|
+
padding: 10px 12px;
|
|
5133
|
+
border: 1px solid ${token.colorBorderSecondary};
|
|
5134
|
+
border-radius: ${borderRadius}px;
|
|
5135
|
+
background: ${token.colorFillQuaternary};
|
|
5136
|
+
transition: border-color 0.2s, background-color 0.2s;
|
|
5137
|
+
|
|
5138
|
+
&& {
|
|
5139
|
+
color: ${token.colorText};
|
|
5140
|
+
text-decoration: none;
|
|
5141
|
+
}
|
|
5142
|
+
|
|
5143
|
+
&:hover {
|
|
5144
|
+
border-color: ${token.colorPrimaryHover};
|
|
5145
|
+
background: ${token.colorFillTertiary};
|
|
5146
|
+
}
|
|
5147
|
+
`,
|
|
5148
|
+
icon: css`
|
|
5149
|
+
flex-shrink: 0;
|
|
5150
|
+
font-size: 20px;
|
|
5151
|
+
color: ${token.colorPrimary};
|
|
5152
|
+
`,
|
|
5153
|
+
meta: css`
|
|
5154
|
+
display: flex;
|
|
5155
|
+
flex-direction: column;
|
|
5156
|
+
gap: 2px;
|
|
5157
|
+
min-width: 0;
|
|
5158
|
+
`,
|
|
5159
|
+
name: css`
|
|
5160
|
+
overflow: hidden;
|
|
5161
|
+
text-overflow: ellipsis;
|
|
5162
|
+
white-space: nowrap;
|
|
5163
|
+
`,
|
|
5164
|
+
size: css`
|
|
5165
|
+
font-size: 12px;
|
|
5166
|
+
color: ${token.colorTextTertiary};
|
|
5167
|
+
`,
|
|
5168
|
+
toolbar: css`
|
|
5169
|
+
position: absolute;
|
|
5170
|
+
top: 6px;
|
|
5171
|
+
right: 8px;
|
|
5172
|
+
display: flex;
|
|
5173
|
+
gap: 4px;
|
|
5174
|
+
opacity: 0;
|
|
5175
|
+
transition: opacity 0.2s;
|
|
5176
|
+
background: ${token.colorBgElevated};
|
|
5177
|
+
border-radius: ${borderRadius}px;
|
|
5178
|
+
padding: 2px 4px;
|
|
5179
|
+
box-shadow: ${token.boxShadowSecondary};
|
|
5180
|
+
|
|
5181
|
+
/* 悬停在卡片上时显示操作按钮(wrapper 为直接父级 div) */
|
|
5182
|
+
div:hover > & {
|
|
5183
|
+
opacity: 1;
|
|
5184
|
+
}
|
|
5185
|
+
`
|
|
5186
|
+
};
|
|
5187
|
+
});
|
|
5188
|
+
|
|
5189
|
+
// src/editor/plugins/builtin/attachment/attachmentSource.ts
|
|
5190
|
+
var DEFAULT_ATTACHMENT_MAX_SIZE = 20 * 1024 * 1024;
|
|
5191
|
+
function formatFileSize2(size) {
|
|
5192
|
+
if (!Number.isFinite(size) || size <= 0) return "";
|
|
5193
|
+
const units = ["B", "KB", "MB", "GB"];
|
|
5194
|
+
let value = size;
|
|
5195
|
+
let unit = 0;
|
|
5196
|
+
while (value >= 1024 && unit < units.length - 1) {
|
|
5197
|
+
value /= 1024;
|
|
5198
|
+
unit += 1;
|
|
5199
|
+
}
|
|
5200
|
+
return `${value >= 10 || unit === 0 ? Math.round(value) : value.toFixed(1)} ${units[unit]}`;
|
|
5201
|
+
}
|
|
5202
|
+
function readFileAsDataUrl2(file) {
|
|
5203
|
+
return new Promise((resolve, reject) => {
|
|
5204
|
+
const reader = new FileReader();
|
|
5205
|
+
reader.onload = () => {
|
|
5206
|
+
if (typeof reader.result === "string") {
|
|
5207
|
+
resolve(reader.result);
|
|
5208
|
+
} else {
|
|
5209
|
+
reject(new Error(tr("\u6587\u4EF6\u8BFB\u53D6\u5931\u8D25")));
|
|
5210
|
+
}
|
|
5211
|
+
};
|
|
5212
|
+
reader.onerror = () => reject(new Error(tr("\u6587\u4EF6\u8BFB\u53D6\u5931\u8D25")));
|
|
5213
|
+
reader.readAsDataURL(file);
|
|
5214
|
+
});
|
|
5215
|
+
}
|
|
5216
|
+
async function resolveAttachment(file, config) {
|
|
5217
|
+
const maxSize = config.maxSize && config.maxSize > 0 ? config.maxSize : DEFAULT_ATTACHMENT_MAX_SIZE;
|
|
5218
|
+
if (file.size > maxSize) {
|
|
5219
|
+
showMessage(tr("\u9644\u4EF6\u5927\u5C0F\u4E0D\u80FD\u8D85\u8FC7 ${0}", [formatFileSize2(maxSize)]), { type: "warning" });
|
|
5220
|
+
return null;
|
|
5221
|
+
}
|
|
5222
|
+
try {
|
|
5223
|
+
const rawSrc = config.uploadFile ? await config.uploadFile(file) : await readFileAsDataUrl2(file);
|
|
5224
|
+
const src = rawSrc ? sanitizeUrl(rawSrc, { allowDataMedia: true }) : null;
|
|
5225
|
+
if (!src) {
|
|
5226
|
+
showMessage(tr("\u9644\u4EF6\u4E0A\u4F20\u5931\u8D25"), { type: "warning" });
|
|
5227
|
+
return null;
|
|
5228
|
+
}
|
|
5229
|
+
return { src, name: file.name, size: file.size, mime: file.type };
|
|
5230
|
+
} catch (error) {
|
|
5231
|
+
showMessage(error instanceof Error ? error.message : tr("\u9644\u4EF6\u4E0A\u4F20\u5931\u8D25"), { type: "warning" });
|
|
5232
|
+
return null;
|
|
5233
|
+
}
|
|
5234
|
+
}
|
|
5235
|
+
async function pickAttachment(config) {
|
|
5236
|
+
const file = await pickFile("");
|
|
5237
|
+
if (!file) return null;
|
|
5238
|
+
return resolveAttachment(file, config);
|
|
5239
|
+
}
|
|
5240
|
+
var AttachmentView = memo(({ node, updateAttributes, deleteNode, editor, extension }) => {
|
|
5241
|
+
const { styles } = useAttachmentStyles();
|
|
5242
|
+
const src = node.attrs.src;
|
|
5243
|
+
const name = node.attrs.name || tr("\u9644\u4EF6");
|
|
5244
|
+
const size = typeof node.attrs.size === "number" ? node.attrs.size : 0;
|
|
5245
|
+
const editable = editor.isEditable;
|
|
5246
|
+
const handleReplace = useCallback(async () => {
|
|
5247
|
+
if (!editor.isEditable) return;
|
|
5248
|
+
const options = extension.options ?? {};
|
|
5249
|
+
const attrs = await pickAttachment(options);
|
|
5250
|
+
if (attrs && !editor.isDestroyed) updateAttributes(attrs);
|
|
5251
|
+
}, [editor, extension, updateAttributes]);
|
|
5252
|
+
const handleDelete = useCallback(() => {
|
|
5253
|
+
if (!editable) return;
|
|
5254
|
+
deleteNode();
|
|
5255
|
+
}, [editable, deleteNode]);
|
|
5256
|
+
return /* @__PURE__ */ jsxs(NodeViewWrapper, { className: styles.wrapper, children: [
|
|
5257
|
+
/* @__PURE__ */ jsxs("a", { className: styles.card, href: src, download: name, target: "_blank", rel: "noopener noreferrer", children: [
|
|
5258
|
+
/* @__PURE__ */ jsx(IconAttachment, { size: 20, className: styles.icon }),
|
|
5259
|
+
/* @__PURE__ */ jsxs("span", { className: styles.meta, children: [
|
|
5260
|
+
/* @__PURE__ */ jsx("span", { className: styles.name, children: name }),
|
|
5261
|
+
size > 0 && /* @__PURE__ */ jsx("span", { className: styles.size, children: formatFileSize2(size) })
|
|
5262
|
+
] })
|
|
5263
|
+
] }),
|
|
5264
|
+
editable && /* @__PURE__ */ jsxs("div", { className: styles.toolbar, children: [
|
|
5265
|
+
/* @__PURE__ */ jsx(Button, { type: "text", size: "small", icon: /* @__PURE__ */ jsx(IconEdit, {}), onClick: handleReplace, children: tr("\u91CD\u65B0\u9009\u62E9") }),
|
|
5266
|
+
/* @__PURE__ */ jsx(Button, { type: "text", size: "small", icon: /* @__PURE__ */ jsx(IconDelete, {}), onClick: handleDelete, danger: true, children: tr("\u5220\u9664") })
|
|
5267
|
+
] })
|
|
5268
|
+
] });
|
|
5269
|
+
});
|
|
5270
|
+
var AttachmentView_default = AttachmentView;
|
|
5271
|
+
var AttachmentNode = Node.create({
|
|
5272
|
+
name: "attachment",
|
|
5273
|
+
group: "block",
|
|
5274
|
+
atom: true,
|
|
5275
|
+
draggable: true,
|
|
5276
|
+
// 与图片一致:点击只落光标,不整块选中,避免打字时误删
|
|
5277
|
+
selectable: false,
|
|
5278
|
+
addOptions() {
|
|
5279
|
+
return { uploadFile: void 0, maxSize: DEFAULT_ATTACHMENT_MAX_SIZE };
|
|
5280
|
+
},
|
|
5281
|
+
addAttributes() {
|
|
5282
|
+
return {
|
|
5283
|
+
src: {
|
|
5284
|
+
default: null,
|
|
5285
|
+
parseHTML: (element) => {
|
|
5286
|
+
const href = element.getAttribute("href");
|
|
5287
|
+
return href ? sanitizeUrl(href, { allowDataMedia: true }) : null;
|
|
5288
|
+
},
|
|
5289
|
+
renderHTML: (attrs) => attrs.src ? { href: attrs.src } : {}
|
|
5290
|
+
},
|
|
5291
|
+
name: {
|
|
5292
|
+
default: "",
|
|
5293
|
+
parseHTML: (element) => element.getAttribute("data-name") || element.getAttribute("download") || "",
|
|
5294
|
+
renderHTML: (attrs) => attrs.name ? { "data-name": attrs.name, download: attrs.name } : {}
|
|
5295
|
+
},
|
|
5296
|
+
size: {
|
|
5297
|
+
default: 0,
|
|
5298
|
+
parseHTML: (element) => Number(element.getAttribute("data-size")) || 0,
|
|
5299
|
+
renderHTML: (attrs) => attrs.size ? { "data-size": attrs.size } : {}
|
|
5300
|
+
},
|
|
5301
|
+
mime: {
|
|
5302
|
+
default: "",
|
|
5303
|
+
parseHTML: (element) => element.getAttribute("data-mime") || "",
|
|
5304
|
+
renderHTML: (attrs) => attrs.mime ? { "data-mime": attrs.mime } : {}
|
|
5305
|
+
}
|
|
5306
|
+
};
|
|
5307
|
+
},
|
|
5308
|
+
parseHTML() {
|
|
5309
|
+
return [
|
|
5310
|
+
{
|
|
5311
|
+
tag: 'a[data-type="attachment"]',
|
|
5312
|
+
// 高于链接 mark 的默认优先级:同名 a[href] 规则下先命中附件节点,避免回导退化为普通链接
|
|
5313
|
+
priority: 60,
|
|
5314
|
+
// 无有效 href(被净化剥离或本来缺失)时不创建附件节点,避免留下不可点击的死卡片
|
|
5315
|
+
getAttrs: (element) => {
|
|
5316
|
+
const href = element.getAttribute("href");
|
|
5317
|
+
return href && sanitizeUrl(href, { allowDataMedia: true }) ? {} : false;
|
|
5318
|
+
},
|
|
5319
|
+
// 文件名/大小由 data-* 属性承载,锚点内的展示文本不再解析为文档内容
|
|
5320
|
+
getContent: () => Fragment.empty
|
|
5321
|
+
}
|
|
5322
|
+
];
|
|
5323
|
+
},
|
|
5324
|
+
renderHTML({ node, HTMLAttributes }) {
|
|
5325
|
+
const name = node.attrs.name || tr("\u9644\u4EF6");
|
|
5326
|
+
const sizeText = formatFileSize2(Number(node.attrs.size));
|
|
5327
|
+
const nameSpan = ["span", { class: "attachment-name" }, name];
|
|
5328
|
+
const sizeSpan = ["span", { class: "attachment-size" }, sizeText];
|
|
5329
|
+
return [
|
|
5330
|
+
"a",
|
|
5331
|
+
mergeAttributes({ "data-type": "attachment", target: "_blank", rel: "noopener noreferrer" }, HTMLAttributes),
|
|
5332
|
+
nameSpan,
|
|
5333
|
+
...sizeText ? [sizeSpan] : []
|
|
5334
|
+
];
|
|
5335
|
+
},
|
|
5336
|
+
addNodeView() {
|
|
5337
|
+
return ReactNodeViewRenderer(AttachmentView_default);
|
|
5338
|
+
}
|
|
5339
|
+
});
|
|
5340
|
+
function insertAttachmentAtBookmark(editor, bookmark, attrs) {
|
|
5341
|
+
if (editor.isDestroyed) return;
|
|
5342
|
+
try {
|
|
5343
|
+
const selection = bookmark.resolve(editor.state.doc);
|
|
5344
|
+
if (selection instanceof NodeSelection) {
|
|
5345
|
+
editor.chain().focus().insertContentAt(selection.to, { type: "attachment", attrs }).run();
|
|
5346
|
+
return;
|
|
5347
|
+
}
|
|
5348
|
+
editor.view.dispatch(editor.state.tr.setSelection(selection));
|
|
5349
|
+
} catch {
|
|
5350
|
+
}
|
|
5351
|
+
editor.chain().focus().insertContent({ type: "attachment", attrs }).run();
|
|
5352
|
+
}
|
|
5353
|
+
function runInsertAttachment(editor, config) {
|
|
5354
|
+
void (async () => {
|
|
5355
|
+
const bookmark = editor.state.selection.getBookmark();
|
|
5356
|
+
const attrs = await pickAttachment(config);
|
|
5357
|
+
if (!attrs || editor.isDestroyed) return;
|
|
5358
|
+
insertAttachmentAtBookmark(editor, bookmark, attrs);
|
|
5359
|
+
})().catch((error) => {
|
|
5360
|
+
showMessage(error instanceof Error ? error.message : tr("\u9644\u4EF6\u63D2\u5165\u5931\u8D25"), { type: "warning" });
|
|
5361
|
+
});
|
|
5362
|
+
}
|
|
5363
|
+
var attachmentPlugin = {
|
|
5364
|
+
name: "attachment",
|
|
5365
|
+
category: "media",
|
|
5366
|
+
dependencies: ["starter"],
|
|
5367
|
+
defaultEnabled: true,
|
|
5368
|
+
defaultConfig: { maxSize: DEFAULT_ATTACHMENT_MAX_SIZE },
|
|
5369
|
+
tiptapExtensions: (config) => [
|
|
5370
|
+
AttachmentNode.configure({ uploadFile: config.uploadFile, maxSize: config.maxSize })
|
|
5371
|
+
],
|
|
5372
|
+
toolbarItems: (config) => [
|
|
5373
|
+
{
|
|
5374
|
+
id: "attachment",
|
|
5375
|
+
type: "button",
|
|
5376
|
+
group: "insert",
|
|
5377
|
+
order: 63,
|
|
5378
|
+
label: tr("\u9644\u4EF6"),
|
|
5379
|
+
icon: /* @__PURE__ */ jsx(IconAttachment, {}),
|
|
5380
|
+
onClick: (editor) => runInsertAttachment(editor, config)
|
|
5381
|
+
}
|
|
5382
|
+
],
|
|
5383
|
+
// AI 能力声明:knowledge 类——附件锚点 HTML 写法(供 block_generate/set_content 产 HTML 参考)
|
|
5384
|
+
aiCommands: () => [
|
|
5385
|
+
{
|
|
5386
|
+
id: "attachment.htmlSyntax",
|
|
5387
|
+
zhLabel: tr("\u9644\u4EF6 HTML \u5199\u6CD5"),
|
|
5388
|
+
kind: "knowledge",
|
|
5389
|
+
description: tr(
|
|
5390
|
+
'\u9644\u4EF6\u7528 <a data-type="attachment" href="URL" download="\u6587\u4EF6\u540D" data-name="\u6587\u4EF6\u540D" data-size="\u5B57\u8282\u6570" data-mime="\u6587\u4EF6\u7C7B\u578B">\u6587\u4EF6\u540D</a>\uFF1Bhref \u652F\u6301 http(s) \u5730\u5740\u6216\u9644\u4EF6 base64 data URL\u3002'
|
|
5391
|
+
)
|
|
5392
|
+
}
|
|
5393
|
+
]
|
|
5394
|
+
};
|
|
5395
|
+
var FlowchartView = createGraphicBlockView({
|
|
5396
|
+
previewStrategy: "imgDataUri",
|
|
5397
|
+
placeholderIcon: /* @__PURE__ */ jsx(ApartmentOutlined, { style: { fontSize: 48 } }),
|
|
5398
|
+
placeholderText: () => tr("\u70B9\u51FB\u7F16\u8F91\u6D41\u7A0B\u56FE"),
|
|
5399
|
+
loadingText: () => tr("\u52A0\u8F7D\u6D41\u7A0B\u56FE\u7F16\u8F91\u5668\u2026"),
|
|
5400
|
+
alt: "flowchart",
|
|
5401
|
+
// x6 画布较重,仅在进入编辑态时懒加载,不拖累编辑器初始包体
|
|
5402
|
+
editorLoader: () => import('./FlowchartEditor-LT6T7ZQV.mjs')
|
|
5403
|
+
});
|
|
5404
|
+
var FlowchartView_default = FlowchartView;
|
|
5405
|
+
var FlowchartBlock = createGraphicBlockNode({
|
|
5406
|
+
name: "flowchartBlock",
|
|
5407
|
+
dataType: "flowchart-block",
|
|
5408
|
+
alt: "flowchart",
|
|
5409
|
+
commandName: "insertFlowchartBlock",
|
|
5410
|
+
view: FlowchartView_default
|
|
5411
|
+
});
|
|
5412
|
+
var flowchartPlugin = {
|
|
5413
|
+
name: "flowchart",
|
|
5414
|
+
category: "media",
|
|
5415
|
+
dependencies: ["starter"],
|
|
5416
|
+
defaultEnabled: true,
|
|
5417
|
+
defaultConfig: {},
|
|
5418
|
+
tiptapExtensions: () => [FlowchartBlock],
|
|
5419
|
+
toolbarItems: () => [
|
|
5420
|
+
{
|
|
5421
|
+
id: "flowchart",
|
|
5422
|
+
type: "button",
|
|
5423
|
+
group: "insert",
|
|
5424
|
+
order: 64,
|
|
5425
|
+
label: tr("\u6D41\u7A0B\u56FE"),
|
|
5426
|
+
icon: /* @__PURE__ */ jsx(IconFlowchart, {}),
|
|
5427
|
+
onClick: (editor) => editor.chain().focus().insertFlowchartBlock().run()
|
|
4485
5428
|
}
|
|
4486
5429
|
],
|
|
4487
5430
|
slashCommands: () => [
|
|
4488
5431
|
{
|
|
4489
5432
|
id: "flowchart",
|
|
4490
5433
|
label: tr("\u6D41\u7A0B\u56FE"),
|
|
4491
|
-
icon: /* @__PURE__ */ jsx(
|
|
5434
|
+
icon: /* @__PURE__ */ jsx(IconFlowchart, {}),
|
|
4492
5435
|
category: tr("\u9AD8\u7EA7\u5757"),
|
|
4493
5436
|
order: 41,
|
|
4494
5437
|
description: tr("\u7ED8\u5236\u6D41\u7A0B\u56FE"),
|
|
@@ -4525,7 +5468,7 @@ var WhiteboardView = createGraphicBlockView({
|
|
|
4525
5468
|
placeholderText: () => tr("\u70B9\u51FB\u7F16\u8F91\u753B\u677F"),
|
|
4526
5469
|
loadingText: () => tr("\u52A0\u8F7D\u753B\u677F\u7F16\u8F91\u5668\u2026"),
|
|
4527
5470
|
// Excalidraw 体积较大,仅在进入编辑态时懒加载
|
|
4528
|
-
editorLoader: () => import('./WhiteboardEditor-
|
|
5471
|
+
editorLoader: () => import('./WhiteboardEditor-FSYK6RVN.mjs')
|
|
4529
5472
|
});
|
|
4530
5473
|
var WhiteboardView_default = WhiteboardView;
|
|
4531
5474
|
var WhiteboardBlock = createGraphicBlockNode({
|
|
@@ -4549,7 +5492,7 @@ var whiteboardPlugin = {
|
|
|
4549
5492
|
group: "insert",
|
|
4550
5493
|
order: 65,
|
|
4551
5494
|
label: tr("\u753B\u677F"),
|
|
4552
|
-
icon: /* @__PURE__ */ jsx(
|
|
5495
|
+
icon: /* @__PURE__ */ jsx(IconWhiteboard, {}),
|
|
4553
5496
|
onClick: (editor) => editor.chain().focus().insertWhiteboardBlock().run()
|
|
4554
5497
|
}
|
|
4555
5498
|
],
|
|
@@ -4557,7 +5500,7 @@ var whiteboardPlugin = {
|
|
|
4557
5500
|
{
|
|
4558
5501
|
id: "whiteboard",
|
|
4559
5502
|
label: tr("\u753B\u677F"),
|
|
4560
|
-
icon: /* @__PURE__ */ jsx(
|
|
5503
|
+
icon: /* @__PURE__ */ jsx(IconWhiteboard, {}),
|
|
4561
5504
|
category: tr("\u9AD8\u7EA7\u5757"),
|
|
4562
5505
|
order: 42,
|
|
4563
5506
|
description: tr("\u63D2\u5165\u753B\u677F\uFF0C\u53EF\u7ED8\u5236\u56FE\u5F62\u3001\u8FDE\u7EBF\u548C\u56FE\u7247"),
|
|
@@ -4572,7 +5515,7 @@ var MindmapView = createGraphicBlockView({
|
|
|
4572
5515
|
placeholderText: () => tr("\u70B9\u51FB\u7F16\u8F91\u601D\u7EF4\u5BFC\u56FE"),
|
|
4573
5516
|
loadingText: () => tr("\u52A0\u8F7D\u601D\u7EF4\u5BFC\u56FE\u7F16\u8F91\u5668\u2026"),
|
|
4574
5517
|
// simple-mind-map 体积较大,仅在进入编辑态时懒加载
|
|
4575
|
-
editorLoader: () => import('./MindmapEditor-
|
|
5518
|
+
editorLoader: () => import('./MindmapEditor-TMXT2VG3.mjs')
|
|
4576
5519
|
});
|
|
4577
5520
|
var MindmapView_default = MindmapView;
|
|
4578
5521
|
var MindmapBlock = createGraphicBlockNode({
|
|
@@ -4596,7 +5539,7 @@ var mindmapPlugin = {
|
|
|
4596
5539
|
group: "insert",
|
|
4597
5540
|
order: 66,
|
|
4598
5541
|
label: tr("\u601D\u7EF4\u5BFC\u56FE"),
|
|
4599
|
-
icon: /* @__PURE__ */ jsx(
|
|
5542
|
+
icon: /* @__PURE__ */ jsx(IconMindmap, {}),
|
|
4600
5543
|
onClick: (editor) => editor.chain().focus().insertMindmapBlock().run()
|
|
4601
5544
|
}
|
|
4602
5545
|
],
|
|
@@ -4604,7 +5547,7 @@ var mindmapPlugin = {
|
|
|
4604
5547
|
{
|
|
4605
5548
|
id: "mindmap",
|
|
4606
5549
|
label: tr("\u601D\u7EF4\u5BFC\u56FE"),
|
|
4607
|
-
icon: /* @__PURE__ */ jsx(
|
|
5550
|
+
icon: /* @__PURE__ */ jsx(IconMindmap, {}),
|
|
4608
5551
|
category: tr("\u9AD8\u7EA7\u5757"),
|
|
4609
5552
|
order: 43,
|
|
4610
5553
|
description: tr("\u68B3\u7406\u4FE1\u606F\u548C\u5934\u8111\u98CE\u66B4"),
|
|
@@ -4633,18 +5576,6 @@ var mindmapPlugin = {
|
|
|
4633
5576
|
}
|
|
4634
5577
|
]
|
|
4635
5578
|
};
|
|
4636
|
-
|
|
4637
|
-
// src/editor/utils/sanitizeUrl.ts
|
|
4638
|
-
var DATA_IMAGE_RE = /^data:image\/[a-z0-9.+-]+;base64,/i;
|
|
4639
|
-
function sanitizeUrl(url, options) {
|
|
4640
|
-
const trimmed = url.trim();
|
|
4641
|
-
if (!trimmed) return null;
|
|
4642
|
-
if (/^(https?:|mailto:|tel:|ftp:|ftps:)/i.test(trimmed)) return trimmed;
|
|
4643
|
-
if (/^[/?#]/.test(trimmed)) return trimmed;
|
|
4644
|
-
if (options?.allowDataImage && DATA_IMAGE_RE.test(trimmed)) return trimmed;
|
|
4645
|
-
if (/^[a-z0-9.-]+\.[a-z]{2,}/i.test(trimmed)) return `https://${trimmed}`;
|
|
4646
|
-
return null;
|
|
4647
|
-
}
|
|
4648
5579
|
var useLinkButtonStyles = createStyles(({ css, token, sizeToken, getAlphaColor }) => ({
|
|
4649
5580
|
activeBtn: css`
|
|
4650
5581
|
background: ${getAlphaColor(token.colorPrimary, 0.1)} !important;
|
|
@@ -4681,6 +5612,9 @@ function linkClickHandler() {
|
|
|
4681
5612
|
});
|
|
4682
5613
|
}
|
|
4683
5614
|
var IdocsLink = Link.extend({
|
|
5615
|
+
inclusive() {
|
|
5616
|
+
return false;
|
|
5617
|
+
},
|
|
4684
5618
|
addProseMirrorPlugins() {
|
|
4685
5619
|
const plugins = this.parent ? this.parent() : [];
|
|
4686
5620
|
if (this.options.openOnClick === false) {
|
|
@@ -4762,8 +5696,8 @@ function LinkEditorButton({ editor }) {
|
|
|
4762
5696
|
Button,
|
|
4763
5697
|
{
|
|
4764
5698
|
type: "text",
|
|
4765
|
-
size: "
|
|
4766
|
-
icon: /* @__PURE__ */ jsx(
|
|
5699
|
+
size: "middle",
|
|
5700
|
+
icon: /* @__PURE__ */ jsx(IconLink, {}),
|
|
4767
5701
|
className: active ? styles.activeBtn : void 0,
|
|
4768
5702
|
onClick: openDialog
|
|
4769
5703
|
}
|
|
@@ -5330,7 +6264,7 @@ var mentionPlugin = {
|
|
|
5330
6264
|
name: "mention",
|
|
5331
6265
|
category: "interaction",
|
|
5332
6266
|
dependencies: ["starter"],
|
|
5333
|
-
defaultEnabled:
|
|
6267
|
+
defaultEnabled: false,
|
|
5334
6268
|
tiptapExtensions: (config) => [
|
|
5335
6269
|
Mention.configure({
|
|
5336
6270
|
HTMLAttributes: {
|
|
@@ -5346,7 +6280,7 @@ var mentionPlugin = {
|
|
|
5346
6280
|
group: "insert",
|
|
5347
6281
|
order: 63,
|
|
5348
6282
|
label: tr("\u63D0\u53CA"),
|
|
5349
|
-
icon: /* @__PURE__ */ jsx(
|
|
6283
|
+
icon: /* @__PURE__ */ jsx(IconMention, {}),
|
|
5350
6284
|
onClick: (editor) => {
|
|
5351
6285
|
editor.chain().focus().insertContent("@").run();
|
|
5352
6286
|
}
|
|
@@ -5356,7 +6290,7 @@ var mentionPlugin = {
|
|
|
5356
6290
|
{
|
|
5357
6291
|
id: "mention",
|
|
5358
6292
|
label: tr("\u63D0\u53CA\u6210\u5458"),
|
|
5359
|
-
icon: /* @__PURE__ */ jsx(
|
|
6293
|
+
icon: /* @__PURE__ */ jsx(IconMention, {}),
|
|
5360
6294
|
category: tr("\u9AD8\u7EA7\u5757"),
|
|
5361
6295
|
order: 50,
|
|
5362
6296
|
description: tr("@\u63D0\u53CA\u7528\u6237"),
|
|
@@ -5395,7 +6329,7 @@ var characterCountPlugin = {
|
|
|
5395
6329
|
name: "character-count",
|
|
5396
6330
|
category: "interaction",
|
|
5397
6331
|
dependencies: ["starter"],
|
|
5398
|
-
defaultEnabled:
|
|
6332
|
+
defaultEnabled: false,
|
|
5399
6333
|
tiptapExtensions: () => [CharacterCount]
|
|
5400
6334
|
};
|
|
5401
6335
|
var DRAG_HANDLE_KEY = new PluginKey("idocs-block-drag-handle");
|
|
@@ -5651,11 +6585,15 @@ var BUILTIN_PLUGINS = [
|
|
|
5651
6585
|
// format - 文本格式
|
|
5652
6586
|
textFormatPlugin,
|
|
5653
6587
|
textColorPlugin,
|
|
5654
|
-
highlightPlugin,
|
|
5655
6588
|
textAlignPlugin,
|
|
6589
|
+
clearFormatPlugin,
|
|
6590
|
+
formatPainterPlugin,
|
|
6591
|
+
backgroundColorPlugin,
|
|
5656
6592
|
// media - 媒体块
|
|
5657
6593
|
tablePlugin,
|
|
5658
6594
|
imagePlugin,
|
|
6595
|
+
videoPlugin,
|
|
6596
|
+
attachmentPlugin,
|
|
5659
6597
|
flowchartPlugin,
|
|
5660
6598
|
whiteboardPlugin,
|
|
5661
6599
|
mindmapPlugin,
|
|
@@ -5674,7 +6612,7 @@ var BUILTIN_PLUGINS = [
|
|
|
5674
6612
|
var MAX_DEPTH = 64;
|
|
5675
6613
|
var MAX_NODES = 5e4;
|
|
5676
6614
|
var MAX_STRING_CHARS = 2 * 1024 * 1024;
|
|
5677
|
-
var URL_ATTR_KEYS = /* @__PURE__ */ new Set(["href", "src", "url"]);
|
|
6615
|
+
var URL_ATTR_KEYS = /* @__PURE__ */ new Set(["href", "src", "url", "poster"]);
|
|
5678
6616
|
var BLOCKED_OBJECT_KEYS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
5679
6617
|
function isPlainObject2(value) {
|
|
5680
6618
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -5682,36 +6620,36 @@ function isPlainObject2(value) {
|
|
|
5682
6620
|
function capString(value) {
|
|
5683
6621
|
return value.length > MAX_STRING_CHARS ? value.slice(0, MAX_STRING_CHARS) : value;
|
|
5684
6622
|
}
|
|
5685
|
-
function sanitizeAttrValue(key, value) {
|
|
6623
|
+
function sanitizeAttrValue(key, value, allowDataMedia) {
|
|
5686
6624
|
if (typeof value === "string") {
|
|
5687
6625
|
const capped = capString(value);
|
|
5688
6626
|
if (URL_ATTR_KEYS.has(key)) {
|
|
5689
|
-
const safe = key === "src" ? sanitizeUrl(capped, { allowDataImage: true }) : sanitizeUrl(capped);
|
|
6627
|
+
const safe = key === "src" ? sanitizeUrl(capped, { allowDataImage: true, allowDataMedia }) : sanitizeUrl(capped);
|
|
5690
6628
|
return safe ?? void 0;
|
|
5691
6629
|
}
|
|
5692
6630
|
return capped;
|
|
5693
6631
|
}
|
|
5694
6632
|
if (Array.isArray(value)) {
|
|
5695
|
-
return value.map((item) => sanitizeAttrValue(key, item));
|
|
6633
|
+
return value.map((item) => sanitizeAttrValue(key, item, allowDataMedia));
|
|
5696
6634
|
}
|
|
5697
6635
|
if (isPlainObject2(value)) {
|
|
5698
6636
|
const out = {};
|
|
5699
6637
|
for (const [k, v] of Object.entries(value)) {
|
|
5700
6638
|
if (BLOCKED_OBJECT_KEYS.has(k)) continue;
|
|
5701
|
-
const sanitized = sanitizeAttrValue(k, v);
|
|
6639
|
+
const sanitized = sanitizeAttrValue(k, v, allowDataMedia);
|
|
5702
6640
|
if (sanitized !== void 0) out[k] = sanitized;
|
|
5703
6641
|
}
|
|
5704
6642
|
return out;
|
|
5705
6643
|
}
|
|
5706
6644
|
return value;
|
|
5707
6645
|
}
|
|
5708
|
-
function sanitizeAttrs(raw, allowedAttrs) {
|
|
6646
|
+
function sanitizeAttrs(raw, allowedAttrs, allowDataMedia) {
|
|
5709
6647
|
if (!isPlainObject2(raw)) return void 0;
|
|
5710
6648
|
const out = {};
|
|
5711
6649
|
for (const [key, value] of Object.entries(raw)) {
|
|
5712
6650
|
if (BLOCKED_OBJECT_KEYS.has(key)) continue;
|
|
5713
6651
|
if (allowedAttrs && !Object.prototype.hasOwnProperty.call(allowedAttrs, key)) continue;
|
|
5714
|
-
const sanitized = sanitizeAttrValue(key, value);
|
|
6652
|
+
const sanitized = sanitizeAttrValue(key, value, allowDataMedia);
|
|
5715
6653
|
if (sanitized !== void 0) out[key] = sanitized;
|
|
5716
6654
|
}
|
|
5717
6655
|
return Object.keys(out).length > 0 ? out : void 0;
|
|
@@ -5724,7 +6662,7 @@ function sanitizeMark(mark, schema, budget) {
|
|
|
5724
6662
|
budget.droppedMarks += 1;
|
|
5725
6663
|
return null;
|
|
5726
6664
|
}
|
|
5727
|
-
const attrs = sanitizeAttrs(mark.attrs, markType?.spec.attrs);
|
|
6665
|
+
const attrs = sanitizeAttrs(mark.attrs, markType?.spec.attrs, false);
|
|
5728
6666
|
if (type === "link" && !attrs?.href) {
|
|
5729
6667
|
budget.droppedMarks += 1;
|
|
5730
6668
|
return null;
|
|
@@ -5744,7 +6682,7 @@ function sanitizeNode(node, schema, budget, depth) {
|
|
|
5744
6682
|
return null;
|
|
5745
6683
|
}
|
|
5746
6684
|
const result = { type };
|
|
5747
|
-
const attrs = sanitizeAttrs(node.attrs, nodeType?.spec.attrs);
|
|
6685
|
+
const attrs = sanitizeAttrs(node.attrs, nodeType?.spec.attrs, type === "attachment" || type === "video");
|
|
5748
6686
|
if (attrs) result.attrs = attrs;
|
|
5749
6687
|
if (type === "text") {
|
|
5750
6688
|
if (typeof node.text !== "string") {
|
|
@@ -5959,6 +6897,42 @@ function typographyCss({
|
|
|
5959
6897
|
outline: 2px solid ${token.colorPrimary};
|
|
5960
6898
|
}` : ""}
|
|
5961
6899
|
|
|
6900
|
+
${mode === "export" ? `/* \u89C6\u9891\uFF08\u7F16\u8F91\u5668\u5185\u7531\u8282\u70B9\u89C6\u56FE\u627F\u8F7D\u6837\u5F0F\uFF0C\u5BFC\u51FA\u65F6\u8865\u64AD\u653E\u5668\u7248\u5F0F\uFF09 */
|
|
6901
|
+
${s("video")} {
|
|
6902
|
+
display: block;
|
|
6903
|
+
max-width: 100%;
|
|
6904
|
+
height: auto;
|
|
6905
|
+
margin: 0.75em 0;
|
|
6906
|
+
border-radius: ${borderRadius}px;
|
|
6907
|
+
background: #000;
|
|
6908
|
+
}` : ""}
|
|
6909
|
+
|
|
6910
|
+
/* \u9644\u4EF6\u5361\u7247\uFF08\u5BFC\u51FA\u4E3A\u7EAF\u951A\u70B9\uFF0C\u7F16\u8F91\u5668\u5185\u7531\u8282\u70B9\u89C6\u56FE\u6E32\u67D3\u5361\u7247\uFF09 */
|
|
6911
|
+
${s('a[data-type="attachment"]')} {
|
|
6912
|
+
display: flex;
|
|
6913
|
+
align-items: center;
|
|
6914
|
+
gap: 10px;
|
|
6915
|
+
box-sizing: border-box;
|
|
6916
|
+
width: 100%;
|
|
6917
|
+
padding: 10px 12px;
|
|
6918
|
+
margin: 0.75em 0;
|
|
6919
|
+
border: 1px solid ${token.colorBorderSecondary};
|
|
6920
|
+
border-radius: ${borderRadius}px;
|
|
6921
|
+
background: ${token.colorFillContent};
|
|
6922
|
+
color: ${token.colorText};
|
|
6923
|
+
text-decoration: none;
|
|
6924
|
+
}
|
|
6925
|
+
${s('a[data-type="attachment"] .attachment-name')} {
|
|
6926
|
+
overflow: hidden;
|
|
6927
|
+
text-overflow: ellipsis;
|
|
6928
|
+
white-space: nowrap;
|
|
6929
|
+
}
|
|
6930
|
+
${s('a[data-type="attachment"] .attachment-size')} {
|
|
6931
|
+
margin-left: auto;
|
|
6932
|
+
font-size: 12px;
|
|
6933
|
+
color: ${token.colorTextTertiary};
|
|
6934
|
+
}
|
|
6935
|
+
|
|
5962
6936
|
/* \u9AD8\u4EAE */
|
|
5963
6937
|
${s("mark")} {
|
|
5964
6938
|
background-color: ${getAlphaColor(HIGHLIGHT_COLOR, 0.4)};
|
|
@@ -6323,5 +7297,5 @@ function fixedTableCss({ token, pa, borderRadius, mode, sel: s }) {
|
|
|
6323
7297
|
}
|
|
6324
7298
|
|
|
6325
7299
|
export { BUILTIN_PLUGINS, DEFAULT_TOOLBAR_GROUP_ORDER, FIXED_CELL_BG, HIGHLIGHT_THEME_CSS, MINIMAL_PLUGINS, PluginRegistry, codeBlockCss, configureEditorFeedback, configureEditorLocale, createCssScope, downloadFile, escapeHtml, findAncestor, fixedTableCss, getDefaultPlaceholder, glassSurfaceCss, headerControlForCol, isPlainObject, isSafeCssColor, lowlight, normalizeFixedTableBackgroundColor, outlinePlugin, parseFormula, pickFile, readFileAsText, readFixedCellControl, resolveCellControl, sanitizeJsonContent, showConfirmModal, showMessage, tableCss, templateCss, templatePlugin, typographyCss, validateFormula };
|
|
6326
|
-
//# sourceMappingURL=chunk-
|
|
6327
|
-
//# sourceMappingURL=chunk-
|
|
7300
|
+
//# sourceMappingURL=chunk-6XGJMUU3.mjs.map
|
|
7301
|
+
//# sourceMappingURL=chunk-6XGJMUU3.mjs.map
|