@jvs-milkdown/crepe 1.2.12 → 1.2.14
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/lib/cjs/builder.js +41 -2
- package/lib/cjs/builder.js.map +1 -1
- package/lib/cjs/feature/block-edit/index.js +10 -2
- package/lib/cjs/feature/block-edit/index.js.map +1 -1
- package/lib/cjs/feature/code-mirror/index.js +9 -2
- package/lib/cjs/feature/code-mirror/index.js.map +1 -1
- package/lib/cjs/feature/cursor/index.js +9 -2
- package/lib/cjs/feature/cursor/index.js.map +1 -1
- package/lib/cjs/feature/image-block/index.js +10 -3
- package/lib/cjs/feature/image-block/index.js.map +1 -1
- package/lib/cjs/feature/inline-diff/index.js +1298 -0
- package/lib/cjs/feature/inline-diff/index.js.map +1 -0
- package/lib/cjs/feature/latex/index.js +9 -2
- package/lib/cjs/feature/latex/index.js.map +1 -1
- package/lib/cjs/feature/link-tooltip/index.js +10 -2
- package/lib/cjs/feature/link-tooltip/index.js.map +1 -1
- package/lib/cjs/feature/list-item/index.js +9 -2
- package/lib/cjs/feature/list-item/index.js.map +1 -1
- package/lib/cjs/feature/placeholder/index.js +9 -2
- package/lib/cjs/feature/placeholder/index.js.map +1 -1
- package/lib/cjs/feature/table/index.js +10 -2
- package/lib/cjs/feature/table/index.js.map +1 -1
- package/lib/cjs/feature/toolbar/index.js +134 -12
- package/lib/cjs/feature/toolbar/index.js.map +1 -1
- package/lib/cjs/index.js +1410 -241
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/builder.js +41 -2
- package/lib/esm/builder.js.map +1 -1
- package/lib/esm/feature/block-edit/index.js +10 -2
- package/lib/esm/feature/block-edit/index.js.map +1 -1
- package/lib/esm/feature/code-mirror/index.js +9 -2
- package/lib/esm/feature/code-mirror/index.js.map +1 -1
- package/lib/esm/feature/cursor/index.js +9 -2
- package/lib/esm/feature/cursor/index.js.map +1 -1
- package/lib/esm/feature/image-block/index.js +10 -3
- package/lib/esm/feature/image-block/index.js.map +1 -1
- package/lib/esm/feature/inline-diff/index.js +1274 -0
- package/lib/esm/feature/inline-diff/index.js.map +1 -0
- package/lib/esm/feature/latex/index.js +9 -2
- package/lib/esm/feature/latex/index.js.map +1 -1
- package/lib/esm/feature/link-tooltip/index.js +10 -2
- package/lib/esm/feature/link-tooltip/index.js.map +1 -1
- package/lib/esm/feature/list-item/index.js +9 -2
- package/lib/esm/feature/list-item/index.js.map +1 -1
- package/lib/esm/feature/placeholder/index.js +9 -2
- package/lib/esm/feature/placeholder/index.js.map +1 -1
- package/lib/esm/feature/table/index.js +10 -2
- package/lib/esm/feature/table/index.js.map +1 -1
- package/lib/esm/feature/toolbar/index.js +134 -12
- package/lib/esm/feature/toolbar/index.js.map +1 -1
- package/lib/esm/index.js +1392 -242
- package/lib/esm/index.js.map +1 -1
- package/lib/theme/common/diff-block.css +41 -0
- package/lib/theme/common/inline-diff.css +142 -0
- package/lib/theme/common/style.css +2 -0
- package/lib/theme/common/table.css +4 -4
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/core/builder.d.ts +2 -0
- package/lib/types/core/builder.d.ts.map +1 -1
- package/lib/types/core/locale.d.ts +4 -0
- package/lib/types/core/locale.d.ts.map +1 -1
- package/lib/types/feature/diff-block/index.d.ts +10 -0
- package/lib/types/feature/diff-block/index.d.ts.map +1 -0
- package/lib/types/feature/fixed-toolbar/document-header.d.ts.map +1 -1
- package/lib/types/feature/fixed-toolbar/index.d.ts.map +1 -1
- package/lib/types/feature/fixed-toolbar/menu-bar.d.ts.map +1 -1
- package/lib/types/feature/fixed-toolbar/outline-panel.d.ts.map +1 -1
- package/lib/types/feature/index.d.ts +7 -1
- package/lib/types/feature/index.d.ts.map +1 -1
- package/lib/types/feature/inline-diff/change-panel.d.ts +4 -0
- package/lib/types/feature/inline-diff/change-panel.d.ts.map +1 -0
- package/lib/types/feature/inline-diff/config.d.ts +12 -0
- package/lib/types/feature/inline-diff/config.d.ts.map +1 -0
- package/lib/types/feature/inline-diff/diff-engine.d.ts +20 -0
- package/lib/types/feature/inline-diff/diff-engine.d.ts.map +1 -0
- package/lib/types/feature/inline-diff/diff-view.d.ts +2 -0
- package/lib/types/feature/inline-diff/diff-view.d.ts.map +1 -0
- package/lib/types/feature/inline-diff/doc-builder.d.ts +21 -0
- package/lib/types/feature/inline-diff/doc-builder.d.ts.map +1 -0
- package/lib/types/feature/inline-diff/index.d.ts +9 -0
- package/lib/types/feature/inline-diff/index.d.ts.map +1 -0
- package/lib/types/feature/loader.d.ts.map +1 -1
- package/lib/types/feature/toolbar/component.d.ts.map +1 -1
- package/lib/types/feature/toolbar/index.d.ts.map +1 -1
- package/lib/types/icons/remove.d.ts +1 -1
- package/lib/types/icons/remove.d.ts.map +1 -1
- package/lib/types/utils/fixed-toolbar-popup-state.d.ts +7 -0
- package/lib/types/utils/fixed-toolbar-popup-state.d.ts.map +1 -0
- package/package.json +15 -4
- package/src/core/builder.ts +19 -0
- package/src/core/locale.ts +7 -0
- package/src/feature/diff-block/index.ts +48 -0
- package/src/feature/fixed-toolbar/index.ts +97 -25
- package/src/feature/fixed-toolbar/menu-bar.tsx +13 -2
- package/src/feature/fixed-toolbar/outline-panel.tsx +3 -2
- package/src/feature/fixed-toolbar/shortcut-help-modal.tsx +1 -1
- package/src/feature/fixed-toolbar/view-menu-state.ts +1 -1
- package/src/feature/image-block/index.ts +1 -1
- package/src/feature/index.ts +12 -0
- package/src/feature/inline-diff/change-panel.ts +280 -0
- package/src/feature/inline-diff/config.ts +28 -0
- package/src/feature/inline-diff/diff-engine.ts +181 -0
- package/src/feature/inline-diff/diff-view.ts +2 -0
- package/src/feature/inline-diff/doc-builder.ts +139 -0
- package/src/feature/inline-diff/index.ts +514 -0
- package/src/feature/loader.ts +8 -0
- package/src/feature/toolbar/component.tsx +97 -9
- package/src/feature/toolbar/index.ts +33 -0
- package/src/icons/remove.ts +1 -0
- package/src/theme/common/diff-block.css +43 -0
- package/src/theme/common/inline-diff.css +148 -0
- package/src/theme/common/style.css +2 -0
- package/src/theme/common/table.css +4 -4
- package/src/utils/fixed-toolbar-popup-state.ts +27 -0
package/lib/esm/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { $ctx, $nodeSchema, $view, $remark, $markAttr, $markSchema, $command, $p
|
|
|
6
6
|
import { defineComponent, shallowRef, ref, computed, h, createApp, watchEffect, watch, onUnmounted, Fragment, reactive, onMounted, onBeforeUnmount, nextTick } from 'vue';
|
|
7
7
|
import { Icon } from '@jvs-milkdown/kit/component';
|
|
8
8
|
import { blockConfig, block, BlockProvider } from '@jvs-milkdown/kit/plugin/block';
|
|
9
|
-
import { commandsCtx, editorViewCtx, editorCtx, EditorStatus, schemaCtx, editorViewOptionsCtx, Editor, rootCtx, defaultValueCtx } from '@jvs-milkdown/kit/core';
|
|
9
|
+
import { commandsCtx, editorViewCtx, editorCtx, EditorStatus, schemaCtx, parserCtx, editorViewOptionsCtx, Editor, rootCtx, defaultValueCtx } from '@jvs-milkdown/kit/core';
|
|
10
10
|
import { findNodeInSelection, findParent, nodeRule } from '@jvs-milkdown/kit/prose';
|
|
11
11
|
import { NodeSelection, TextSelection, Plugin, PluginKey, EditorState, AllSelection } from '@jvs-milkdown/kit/prose/state';
|
|
12
12
|
import { computePosition, flip, shift, offset } from '@floating-ui/dom';
|
|
@@ -24,6 +24,7 @@ import { codeBlockConfig, codeBlockComponent } from '@jvs-milkdown/kit/component
|
|
|
24
24
|
import { basicSetup } from 'codemirror';
|
|
25
25
|
import { dropIndicatorConfig, cursor as cursor$1 } from '@jvs-milkdown/kit/plugin/cursor';
|
|
26
26
|
import { createVirtualCursor } from 'prosemirror-virtual-cursor';
|
|
27
|
+
import { diffBlockConfig, diffBlock } from '@jvs-milkdown/kit/component/diff-block';
|
|
27
28
|
import { mergeCells, splitCell, CellSelection, selectedRect, splitCellWithType } from '@jvs-milkdown/kit/prose/tables';
|
|
28
29
|
import clsx from 'clsx';
|
|
29
30
|
import { toggleLinkCommand, configureLinkTooltip, linkTooltipConfig, linkTooltipPlugin } from '@jvs-milkdown/kit/component/link-tooltip';
|
|
@@ -31,6 +32,7 @@ import { Decoration, DecorationSet, EditorView } from '@jvs-milkdown/kit/prose/v
|
|
|
31
32
|
import { inlineImageConfig, imageInlineComponent } from '@jvs-milkdown/kit/component/image-inline';
|
|
32
33
|
import { Plugin as Plugin$1 } from '@jvs-milkdown/prose/state';
|
|
33
34
|
import { $prose as $prose$1 } from '@jvs-milkdown/utils';
|
|
35
|
+
import * as Diff from 'diff';
|
|
34
36
|
import { tooltipFactory, TooltipProvider } from '@jvs-milkdown/kit/plugin/tooltip';
|
|
35
37
|
import { redo, undo } from '@jvs-milkdown/kit/prose/history';
|
|
36
38
|
import { keymap as keymap$1 } from '@jvs-milkdown/kit/prose/keymap';
|
|
@@ -59,6 +61,8 @@ var CrepeFeature = /* @__PURE__ */ ((CrepeFeature2) => {
|
|
|
59
61
|
CrepeFeature2["Table"] = "table";
|
|
60
62
|
CrepeFeature2["Latex"] = "latex";
|
|
61
63
|
CrepeFeature2["Attachment"] = "attachment";
|
|
64
|
+
CrepeFeature2["InlineDiff"] = "inline-diff";
|
|
65
|
+
CrepeFeature2["DiffBlock"] = "diff-block";
|
|
62
66
|
return CrepeFeature2;
|
|
63
67
|
})(CrepeFeature || {});
|
|
64
68
|
const defaultFeatures = {
|
|
@@ -73,7 +77,9 @@ const defaultFeatures = {
|
|
|
73
77
|
["code-mirror" /* CodeMirror */]: true,
|
|
74
78
|
["table" /* Table */]: true,
|
|
75
79
|
["latex" /* Latex */]: true,
|
|
76
|
-
["attachment" /* Attachment */]: true
|
|
80
|
+
["attachment" /* Attachment */]: true,
|
|
81
|
+
["inline-diff" /* InlineDiff */]: false,
|
|
82
|
+
["diff-block" /* DiffBlock */]: true
|
|
77
83
|
};
|
|
78
84
|
|
|
79
85
|
const alignCenterIcon = `
|
|
@@ -439,6 +445,7 @@ const removeIcon = `
|
|
|
439
445
|
>
|
|
440
446
|
<path
|
|
441
447
|
d="M7.30775 20.4997C6.81058 20.4997 6.385 20.3227 6.031 19.9687C5.677 19.6147 5.5 19.1892 5.5 18.692V5.99973H5.25C5.0375 5.99973 4.85942 5.92782 4.71575 5.78398C4.57192 5.64015 4.5 5.46198 4.5 5.24948C4.5 5.03682 4.57192 4.85873 4.71575 4.71523C4.85942 4.57157 5.0375 4.49973 5.25 4.49973H9C9 4.2549 9.08625 4.04624 9.25875 3.87374C9.43108 3.7014 9.63967 3.61523 9.8845 3.61523H14.1155C14.3603 3.61523 14.5689 3.7014 14.7413 3.87374C14.9138 4.04624 15 4.2549 15 4.49973H18.75C18.9625 4.49973 19.1406 4.57165 19.2843 4.71548C19.4281 4.85932 19.5 5.03748 19.5 5.24998C19.5 5.46265 19.4281 5.64073 19.2843 5.78423C19.1406 5.9279 18.9625 5.99973 18.75 5.99973H18.5V18.692C18.5 19.1892 18.323 19.6147 17.969 19.9687C17.615 20.3227 17.1894 20.4997 16.6923 20.4997H7.30775ZM17 5.99973H7V18.692C7 18.7818 7.02883 18.8556 7.0865 18.9132C7.14417 18.9709 7.21792 18.9997 7.30775 18.9997H16.6923C16.7821 18.9997 16.8558 18.9709 16.9135 18.9132C16.9712 18.8556 17 18.7818 17 18.692V5.99973ZM10.1543 16.9997C10.3668 16.9997 10.5448 16.9279 10.6885 16.7842C10.832 16.6404 10.9037 16.4622 10.9037 16.2497V8.74973C10.9037 8.53723 10.8318 8.35907 10.688 8.21523C10.5443 8.07157 10.3662 7.99973 10.1535 7.99973C9.941 7.99973 9.76292 8.07157 9.61925 8.21523C9.47575 8.35907 9.404 8.53723 9.404 8.74973V16.2497C9.404 16.4622 9.47583 16.6404 9.6195 16.7842C9.76333 16.9279 9.94158 16.9997 10.1543 16.9997ZM13.8465 16.9997C14.059 16.9997 14.2371 16.9279 14.3807 16.7842C14.5243 16.6404 14.596 16.4622 14.596 16.2497V8.74973C14.596 8.53723 14.5242 8.35907 14.3805 8.21523C14.2367 8.07157 14.0584 7.99973 13.8458 7.99973C13.6333 7.99973 13.4552 8.07157 13.3115 8.21523C13.168 8.35907 13.0962 8.53723 13.0962 8.74973V16.2497C13.0962 16.4622 13.1682 16.6404 13.312 16.7842C13.4557 16.9279 13.6338 16.9997 13.8465 16.9997Z"
|
|
448
|
+
fill="#363B4C"
|
|
442
449
|
/>
|
|
443
450
|
</svg>
|
|
444
451
|
`;
|
|
@@ -808,7 +815,10 @@ const zhCN = {
|
|
|
808
815
|
"shortcuts.hardBreak": "\u6362\u884C",
|
|
809
816
|
"shortcuts.history": "\u5386\u53F2\u8BB0\u5F55",
|
|
810
817
|
"shortcuts.undo": "\u64A4\u9500",
|
|
811
|
-
"shortcuts.redo": "\u91CD\u505A"
|
|
818
|
+
"shortcuts.redo": "\u91CD\u505A",
|
|
819
|
+
// inline-diff
|
|
820
|
+
"inlineDiff.accept": "\u63A5\u53D7",
|
|
821
|
+
"inlineDiff.reject": "\u62D2\u7EDD"
|
|
812
822
|
};
|
|
813
823
|
const enUS = {
|
|
814
824
|
"handle.add": "Add content",
|
|
@@ -950,7 +960,9 @@ const enUS = {
|
|
|
950
960
|
"shortcuts.hardBreak": "Hard Break",
|
|
951
961
|
"shortcuts.history": "History",
|
|
952
962
|
"shortcuts.undo": "Undo",
|
|
953
|
-
"shortcuts.redo": "Redo"
|
|
963
|
+
"shortcuts.redo": "Redo",
|
|
964
|
+
"inlineDiff.accept": "Accept",
|
|
965
|
+
"inlineDiff.reject": "Reject"
|
|
954
966
|
};
|
|
955
967
|
const translationsCtx = createSlice(
|
|
956
968
|
{
|
|
@@ -1387,22 +1399,22 @@ function isInList(selection) {
|
|
|
1387
1399
|
return (type == null ? void 0 : type.name) === "list_item";
|
|
1388
1400
|
}
|
|
1389
1401
|
|
|
1390
|
-
var __typeError$
|
|
1402
|
+
var __typeError$7 = (msg) => {
|
|
1391
1403
|
throw TypeError(msg);
|
|
1392
1404
|
};
|
|
1393
|
-
var __accessCheck$
|
|
1394
|
-
var __privateGet$
|
|
1395
|
-
var __privateAdd$
|
|
1396
|
-
var __privateSet$
|
|
1405
|
+
var __accessCheck$7 = (obj, member, msg) => member.has(obj) || __typeError$7("Cannot " + msg);
|
|
1406
|
+
var __privateGet$7 = (obj, member, getter) => (__accessCheck$7(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
1407
|
+
var __privateAdd$7 = (obj, member, value) => member.has(obj) ? __typeError$7("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1408
|
+
var __privateSet$7 = (obj, member, value, setter) => (__accessCheck$7(obj, member, "write to private field"), member.set(obj, value), value);
|
|
1397
1409
|
var _groups, _getGroupInstance;
|
|
1398
1410
|
class GroupBuilder {
|
|
1399
1411
|
constructor() {
|
|
1400
|
-
__privateAdd$
|
|
1412
|
+
__privateAdd$7(this, _groups, []);
|
|
1401
1413
|
this.clear = () => {
|
|
1402
|
-
__privateSet$
|
|
1414
|
+
__privateSet$7(this, _groups, []);
|
|
1403
1415
|
return this;
|
|
1404
1416
|
};
|
|
1405
|
-
__privateAdd$
|
|
1417
|
+
__privateAdd$7(this, _getGroupInstance, (group) => {
|
|
1406
1418
|
const groupInstance = {
|
|
1407
1419
|
group,
|
|
1408
1420
|
addItem: (key, item) => {
|
|
@@ -1424,16 +1436,16 @@ class GroupBuilder {
|
|
|
1424
1436
|
label,
|
|
1425
1437
|
items
|
|
1426
1438
|
};
|
|
1427
|
-
__privateGet$
|
|
1428
|
-
return __privateGet$
|
|
1439
|
+
__privateGet$7(this, _groups).push(group);
|
|
1440
|
+
return __privateGet$7(this, _getGroupInstance).call(this, group);
|
|
1429
1441
|
};
|
|
1430
1442
|
this.getGroup = (key) => {
|
|
1431
|
-
const group = __privateGet$
|
|
1443
|
+
const group = __privateGet$7(this, _groups).find((group2) => group2.key === key);
|
|
1432
1444
|
if (!group) throw new Error(`Group with key ${key} not found`);
|
|
1433
|
-
return __privateGet$
|
|
1445
|
+
return __privateGet$7(this, _getGroupInstance).call(this, group);
|
|
1434
1446
|
};
|
|
1435
1447
|
this.build = () => {
|
|
1436
|
-
return __privateGet$
|
|
1448
|
+
return __privateGet$7(this, _groups);
|
|
1437
1449
|
};
|
|
1438
1450
|
}
|
|
1439
1451
|
}
|
|
@@ -3585,14 +3597,14 @@ const Menu = defineComponent({
|
|
|
3585
3597
|
}
|
|
3586
3598
|
});
|
|
3587
3599
|
|
|
3588
|
-
var __typeError$
|
|
3600
|
+
var __typeError$6 = (msg) => {
|
|
3589
3601
|
throw TypeError(msg);
|
|
3590
3602
|
};
|
|
3591
|
-
var __accessCheck$
|
|
3592
|
-
var __privateGet$
|
|
3593
|
-
var __privateAdd$
|
|
3594
|
-
var __privateSet$
|
|
3595
|
-
var _content$4, _app$4, _filter, _slashProvider, _activeKey, _view$
|
|
3603
|
+
var __accessCheck$6 = (obj, member, msg) => member.has(obj) || __typeError$6("Cannot " + msg);
|
|
3604
|
+
var __privateGet$6 = (obj, member, getter) => (__accessCheck$6(obj, member, "read from private field"), member.get(obj));
|
|
3605
|
+
var __privateAdd$6 = (obj, member, value) => member.has(obj) ? __typeError$6("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
3606
|
+
var __privateSet$6 = (obj, member, value, setter) => (__accessCheck$6(obj, member, "write to private field"), member.set(obj, value), value);
|
|
3607
|
+
var _content$4, _app$4, _filter, _slashProvider, _activeKey, _view$2, _programmaticallyPos, _mode, _hideTimeout, _isMenuHovered, _keepOpenUntilClickOutside;
|
|
3596
3608
|
const menu = slashFactory("CREPE_MENU");
|
|
3597
3609
|
function configureMenu(ctx, config) {
|
|
3598
3610
|
ctx.set(menu.key, {
|
|
@@ -3601,50 +3613,50 @@ function configureMenu(ctx, config) {
|
|
|
3601
3613
|
}
|
|
3602
3614
|
class MenuView {
|
|
3603
3615
|
constructor(ctx, view, config) {
|
|
3604
|
-
__privateAdd$
|
|
3605
|
-
__privateAdd$
|
|
3606
|
-
__privateAdd$
|
|
3607
|
-
__privateAdd$
|
|
3608
|
-
__privateAdd$
|
|
3609
|
-
__privateAdd$
|
|
3610
|
-
__privateAdd$
|
|
3611
|
-
__privateAdd$
|
|
3612
|
-
__privateAdd$
|
|
3613
|
-
__privateAdd$
|
|
3614
|
-
__privateAdd$
|
|
3616
|
+
__privateAdd$6(this, _content$4);
|
|
3617
|
+
__privateAdd$6(this, _app$4);
|
|
3618
|
+
__privateAdd$6(this, _filter);
|
|
3619
|
+
__privateAdd$6(this, _slashProvider);
|
|
3620
|
+
__privateAdd$6(this, _activeKey);
|
|
3621
|
+
__privateAdd$6(this, _view$2);
|
|
3622
|
+
__privateAdd$6(this, _programmaticallyPos, null);
|
|
3623
|
+
__privateAdd$6(this, _mode, null);
|
|
3624
|
+
__privateAdd$6(this, _hideTimeout);
|
|
3625
|
+
__privateAdd$6(this, _isMenuHovered, false);
|
|
3626
|
+
__privateAdd$6(this, _keepOpenUntilClickOutside, false);
|
|
3615
3627
|
this.onHoverDelayHide = () => {
|
|
3616
|
-
window.clearTimeout(__privateGet$
|
|
3617
|
-
__privateSet$
|
|
3618
|
-
if (!__privateGet$
|
|
3628
|
+
window.clearTimeout(__privateGet$6(this, _hideTimeout));
|
|
3629
|
+
__privateSet$6(this, _hideTimeout, window.setTimeout(() => {
|
|
3630
|
+
if (!__privateGet$6(this, _isMenuHovered) && !__privateGet$6(this, _keepOpenUntilClickOutside) && __privateGet$6(this, _programmaticallyPos) !== null) {
|
|
3619
3631
|
this.hide();
|
|
3620
3632
|
}
|
|
3621
3633
|
}, 150));
|
|
3622
3634
|
};
|
|
3623
3635
|
this.cancelHide = () => {
|
|
3624
|
-
window.clearTimeout(__privateGet$
|
|
3636
|
+
window.clearTimeout(__privateGet$6(this, _hideTimeout));
|
|
3625
3637
|
};
|
|
3626
3638
|
this.update = (view) => {
|
|
3627
|
-
__privateGet$
|
|
3639
|
+
__privateGet$6(this, _slashProvider).update(view);
|
|
3628
3640
|
};
|
|
3629
3641
|
this.show = (pos, isClick = false, triggerElement, mode = "block") => {
|
|
3630
3642
|
if (isClick) {
|
|
3631
|
-
__privateSet$
|
|
3643
|
+
__privateSet$6(this, _keepOpenUntilClickOutside, true);
|
|
3632
3644
|
} else {
|
|
3633
|
-
__privateSet$
|
|
3645
|
+
__privateSet$6(this, _keepOpenUntilClickOutside, false);
|
|
3634
3646
|
}
|
|
3635
|
-
__privateSet$
|
|
3636
|
-
__privateSet$
|
|
3637
|
-
__privateGet$
|
|
3638
|
-
const node = __privateGet$
|
|
3647
|
+
__privateSet$6(this, _programmaticallyPos, pos);
|
|
3648
|
+
__privateSet$6(this, _mode, mode);
|
|
3649
|
+
__privateGet$6(this, _filter).value = "";
|
|
3650
|
+
const node = __privateGet$6(this, _view$2).state.doc.nodeAt(pos);
|
|
3639
3651
|
if (node) {
|
|
3640
|
-
__privateGet$
|
|
3652
|
+
__privateGet$6(this, _activeKey).value = getBlockKey(node);
|
|
3641
3653
|
} else {
|
|
3642
|
-
__privateGet$
|
|
3654
|
+
__privateGet$6(this, _activeKey).value = "text";
|
|
3643
3655
|
}
|
|
3644
|
-
__privateGet$
|
|
3645
|
-
__privateGet$
|
|
3656
|
+
__privateGet$6(this, _slashProvider).show();
|
|
3657
|
+
__privateGet$6(this, _content$4).dataset.mode = mode;
|
|
3646
3658
|
if (triggerElement) {
|
|
3647
|
-
void computePosition(triggerElement, __privateGet$
|
|
3659
|
+
void computePosition(triggerElement, __privateGet$6(this, _content$4), {
|
|
3648
3660
|
placement: "bottom-start",
|
|
3649
3661
|
middleware: [
|
|
3650
3662
|
flip(),
|
|
@@ -3665,7 +3677,7 @@ class MenuView {
|
|
|
3665
3677
|
})
|
|
3666
3678
|
]
|
|
3667
3679
|
}).then(({ x, y }) => {
|
|
3668
|
-
Object.assign(__privateGet$
|
|
3680
|
+
Object.assign(__privateGet$6(this, _content$4).style, {
|
|
3669
3681
|
left: `${x}px`,
|
|
3670
3682
|
top: `${y}px`
|
|
3671
3683
|
});
|
|
@@ -3673,25 +3685,25 @@ class MenuView {
|
|
|
3673
3685
|
}
|
|
3674
3686
|
};
|
|
3675
3687
|
this.hide = () => {
|
|
3676
|
-
__privateSet$
|
|
3677
|
-
__privateSet$
|
|
3678
|
-
__privateGet$
|
|
3688
|
+
__privateSet$6(this, _programmaticallyPos, null);
|
|
3689
|
+
__privateSet$6(this, _mode, null);
|
|
3690
|
+
__privateGet$6(this, _content$4).removeAttribute("data-mode");
|
|
3679
3691
|
this.cancelHide();
|
|
3680
|
-
__privateGet$
|
|
3692
|
+
__privateGet$6(this, _slashProvider).hide();
|
|
3681
3693
|
};
|
|
3682
3694
|
this.destroy = () => {
|
|
3683
|
-
__privateGet$
|
|
3684
|
-
__privateGet$
|
|
3685
|
-
__privateGet$
|
|
3695
|
+
__privateGet$6(this, _slashProvider).destroy();
|
|
3696
|
+
__privateGet$6(this, _app$4).unmount();
|
|
3697
|
+
__privateGet$6(this, _content$4).remove();
|
|
3686
3698
|
};
|
|
3687
|
-
__privateSet$
|
|
3699
|
+
__privateSet$6(this, _view$2, view);
|
|
3688
3700
|
const content = document.createElement("div");
|
|
3689
3701
|
content.classList.add("milkdown-slash-menu");
|
|
3690
3702
|
const show = ref(false);
|
|
3691
3703
|
const filter = ref("");
|
|
3692
|
-
__privateSet$
|
|
3704
|
+
__privateSet$6(this, _filter, filter);
|
|
3693
3705
|
const activeKey = ref("text");
|
|
3694
|
-
__privateSet$
|
|
3706
|
+
__privateSet$6(this, _activeKey, activeKey);
|
|
3695
3707
|
const hide = this.hide;
|
|
3696
3708
|
const app = createApp(Menu, {
|
|
3697
3709
|
ctx,
|
|
@@ -3701,20 +3713,20 @@ class MenuView {
|
|
|
3701
3713
|
hide,
|
|
3702
3714
|
activeKey
|
|
3703
3715
|
});
|
|
3704
|
-
__privateSet$
|
|
3716
|
+
__privateSet$6(this, _app$4, app);
|
|
3705
3717
|
app.mount(content);
|
|
3706
|
-
__privateSet$
|
|
3707
|
-
__privateGet$
|
|
3708
|
-
__privateSet$
|
|
3718
|
+
__privateSet$6(this, _content$4, content);
|
|
3719
|
+
__privateGet$6(this, _content$4).addEventListener("pointerenter", () => {
|
|
3720
|
+
__privateSet$6(this, _isMenuHovered, true);
|
|
3709
3721
|
this.cancelHide();
|
|
3710
3722
|
});
|
|
3711
|
-
__privateGet$
|
|
3712
|
-
__privateSet$
|
|
3723
|
+
__privateGet$6(this, _content$4).addEventListener("pointerleave", () => {
|
|
3724
|
+
__privateSet$6(this, _isMenuHovered, false);
|
|
3713
3725
|
this.onHoverDelayHide();
|
|
3714
3726
|
});
|
|
3715
3727
|
const self = this;
|
|
3716
|
-
__privateSet$
|
|
3717
|
-
content: __privateGet$
|
|
3728
|
+
__privateSet$6(this, _slashProvider, new SlashProvider({
|
|
3729
|
+
content: __privateGet$6(this, _content$4),
|
|
3718
3730
|
debounce: 20,
|
|
3719
3731
|
shouldShow(view2) {
|
|
3720
3732
|
if (isInCodeBlock(view2.state.selection) || isInList(view2.state.selection))
|
|
@@ -3727,13 +3739,13 @@ class MenuView {
|
|
|
3727
3739
|
if (!isSelectionAtEndOfNode(view2.state.selection)) {
|
|
3728
3740
|
return false;
|
|
3729
3741
|
}
|
|
3730
|
-
const pos = __privateGet$
|
|
3742
|
+
const pos = __privateGet$6(self, _programmaticallyPos);
|
|
3731
3743
|
filter.value = currentText.startsWith("/") ? currentText.slice(1) : currentText;
|
|
3732
3744
|
if (typeof pos === "number") {
|
|
3733
3745
|
const maxSize = view2.state.doc.nodeSize - 2;
|
|
3734
3746
|
const validPos = Math.min(pos, maxSize);
|
|
3735
3747
|
if (view2.state.doc.resolve(validPos).node() !== view2.state.doc.resolve(view2.state.selection.from).node()) {
|
|
3736
|
-
__privateSet$
|
|
3748
|
+
__privateSet$6(self, _programmaticallyPos, null);
|
|
3737
3749
|
return false;
|
|
3738
3750
|
}
|
|
3739
3751
|
return true;
|
|
@@ -3743,12 +3755,12 @@ class MenuView {
|
|
|
3743
3755
|
},
|
|
3744
3756
|
offset: 10
|
|
3745
3757
|
}));
|
|
3746
|
-
__privateGet$
|
|
3758
|
+
__privateGet$6(this, _slashProvider).onShow = () => {
|
|
3747
3759
|
show.value = true;
|
|
3748
3760
|
};
|
|
3749
|
-
__privateGet$
|
|
3761
|
+
__privateGet$6(this, _slashProvider).onHide = () => {
|
|
3750
3762
|
show.value = false;
|
|
3751
|
-
__privateSet$
|
|
3763
|
+
__privateSet$6(this, _keepOpenUntilClickOutside, false);
|
|
3752
3764
|
};
|
|
3753
3765
|
this.update(view);
|
|
3754
3766
|
ctx.set(menuAPI.key, {
|
|
@@ -3759,10 +3771,10 @@ class MenuView {
|
|
|
3759
3771
|
hide: () => this.hide(),
|
|
3760
3772
|
onHoverDelayHide: () => this.onHoverDelayHide(),
|
|
3761
3773
|
cancelHide: () => this.cancelHide(),
|
|
3762
|
-
isProgrammatic: () => __privateGet$
|
|
3763
|
-
getPos: () => __privateGet$
|
|
3774
|
+
isProgrammatic: () => __privateGet$6(this, _programmaticallyPos) !== null,
|
|
3775
|
+
getPos: () => __privateGet$6(this, _programmaticallyPos),
|
|
3764
3776
|
isShow: () => show.value,
|
|
3765
|
-
getMode: () => __privateGet$
|
|
3777
|
+
getMode: () => __privateGet$6(this, _mode)
|
|
3766
3778
|
});
|
|
3767
3779
|
}
|
|
3768
3780
|
}
|
|
@@ -3771,7 +3783,7 @@ _app$4 = new WeakMap();
|
|
|
3771
3783
|
_filter = new WeakMap();
|
|
3772
3784
|
_slashProvider = new WeakMap();
|
|
3773
3785
|
_activeKey = new WeakMap();
|
|
3774
|
-
_view$
|
|
3786
|
+
_view$2 = new WeakMap();
|
|
3775
3787
|
_programmaticallyPos = new WeakMap();
|
|
3776
3788
|
_mode = new WeakMap();
|
|
3777
3789
|
_hideTimeout = new WeakMap();
|
|
@@ -3930,25 +3942,25 @@ const BlockHandle = defineComponent({
|
|
|
3930
3942
|
}
|
|
3931
3943
|
});
|
|
3932
3944
|
|
|
3933
|
-
var __typeError$
|
|
3945
|
+
var __typeError$5 = (msg) => {
|
|
3934
3946
|
throw TypeError(msg);
|
|
3935
3947
|
};
|
|
3936
|
-
var __accessCheck$
|
|
3937
|
-
var __privateGet$
|
|
3938
|
-
var __privateAdd$
|
|
3939
|
-
var __privateSet$
|
|
3940
|
-
var _content$3, _provider$1, _state, _app$3, _ctx, _syncIcon;
|
|
3948
|
+
var __accessCheck$5 = (obj, member, msg) => member.has(obj) || __typeError$5("Cannot " + msg);
|
|
3949
|
+
var __privateGet$5 = (obj, member, getter) => (__accessCheck$5(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
3950
|
+
var __privateAdd$5 = (obj, member, value) => member.has(obj) ? __typeError$5("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
3951
|
+
var __privateSet$5 = (obj, member, value, setter) => (__accessCheck$5(obj, member, "write to private field"), member.set(obj, value), value);
|
|
3952
|
+
var _content$3, _provider$1, _state, _app$3, _ctx$1, _syncIcon;
|
|
3941
3953
|
class BlockHandleView {
|
|
3942
3954
|
constructor(ctx, config) {
|
|
3943
|
-
__privateAdd$
|
|
3944
|
-
__privateAdd$
|
|
3945
|
-
__privateAdd$
|
|
3946
|
-
__privateAdd$
|
|
3947
|
-
__privateAdd$
|
|
3955
|
+
__privateAdd$5(this, _content$3);
|
|
3956
|
+
__privateAdd$5(this, _provider$1);
|
|
3957
|
+
__privateAdd$5(this, _state, reactive({ icon: textIcon }));
|
|
3958
|
+
__privateAdd$5(this, _app$3);
|
|
3959
|
+
__privateAdd$5(this, _ctx$1);
|
|
3948
3960
|
this.update = () => {
|
|
3949
|
-
__privateGet$
|
|
3950
|
-
if (__privateGet$
|
|
3951
|
-
const node = __privateGet$
|
|
3961
|
+
__privateGet$5(this, _provider$1).update();
|
|
3962
|
+
if (__privateGet$5(this, _provider$1).active) {
|
|
3963
|
+
const node = __privateGet$5(this, _provider$1).active.node;
|
|
3952
3964
|
let hasMediaChild = false;
|
|
3953
3965
|
if (node.type.name === "paragraph") {
|
|
3954
3966
|
node.content.forEach((child) => {
|
|
@@ -3960,24 +3972,24 @@ class BlockHandleView {
|
|
|
3960
3972
|
const isMedia = node.type.name.includes("image") || node.type.name.includes("attachment") || node.type.name === "hr" || node.type.name.includes("math") || hasMediaChild;
|
|
3961
3973
|
const isEmpty = node.textContent.length === 0 && node.content.size <= 2 && !isMedia;
|
|
3962
3974
|
if (isEmpty) {
|
|
3963
|
-
__privateGet$
|
|
3975
|
+
__privateGet$5(this, _content$3).classList.add("empty-block");
|
|
3964
3976
|
} else {
|
|
3965
|
-
__privateGet$
|
|
3977
|
+
__privateGet$5(this, _content$3).classList.remove("empty-block");
|
|
3966
3978
|
}
|
|
3967
|
-
__privateGet$
|
|
3979
|
+
__privateGet$5(this, _syncIcon).call(this, node);
|
|
3968
3980
|
} else {
|
|
3969
|
-
__privateGet$
|
|
3970
|
-
__privateGet$
|
|
3981
|
+
__privateGet$5(this, _content$3).classList.remove("empty-block");
|
|
3982
|
+
__privateGet$5(this, _state).icon = textIcon;
|
|
3971
3983
|
}
|
|
3972
3984
|
};
|
|
3973
|
-
__privateAdd$
|
|
3985
|
+
__privateAdd$5(this, _syncIcon, (node) => {
|
|
3974
3986
|
var _a;
|
|
3975
3987
|
if (node.type.name.includes("image")) {
|
|
3976
|
-
__privateGet$
|
|
3988
|
+
__privateGet$5(this, _state).icon = imageIcon;
|
|
3977
3989
|
return;
|
|
3978
3990
|
}
|
|
3979
3991
|
if (node.type.name.includes("attachment")) {
|
|
3980
|
-
__privateGet$
|
|
3992
|
+
__privateGet$5(this, _state).icon = fileLinkIcon;
|
|
3981
3993
|
return;
|
|
3982
3994
|
}
|
|
3983
3995
|
switch (node.type.name) {
|
|
@@ -3992,87 +4004,87 @@ class BlockHandleView {
|
|
|
3992
4004
|
h5Icon,
|
|
3993
4005
|
h6Icon
|
|
3994
4006
|
];
|
|
3995
|
-
__privateGet$
|
|
4007
|
+
__privateGet$5(this, _state).icon = (_a = headingIcons[level]) != null ? _a : textIcon;
|
|
3996
4008
|
break;
|
|
3997
4009
|
}
|
|
3998
4010
|
case "blockquote":
|
|
3999
|
-
__privateGet$
|
|
4011
|
+
__privateGet$5(this, _state).icon = quoteIcon;
|
|
4000
4012
|
break;
|
|
4001
4013
|
case "code_block":
|
|
4002
|
-
__privateGet$
|
|
4014
|
+
__privateGet$5(this, _state).icon = codeIcon;
|
|
4003
4015
|
break;
|
|
4004
4016
|
case "math_display":
|
|
4005
4017
|
case "math_inline":
|
|
4006
|
-
__privateGet$
|
|
4018
|
+
__privateGet$5(this, _state).icon = functionsIcon;
|
|
4007
4019
|
break;
|
|
4008
4020
|
case "hr":
|
|
4009
|
-
__privateGet$
|
|
4021
|
+
__privateGet$5(this, _state).icon = dividerIcon;
|
|
4010
4022
|
break;
|
|
4011
4023
|
case "table":
|
|
4012
|
-
__privateGet$
|
|
4024
|
+
__privateGet$5(this, _state).icon = tableIcon;
|
|
4013
4025
|
break;
|
|
4014
4026
|
case "list_item":
|
|
4015
4027
|
if (node.attrs.checked != null) {
|
|
4016
|
-
__privateGet$
|
|
4028
|
+
__privateGet$5(this, _state).icon = todoListIcon;
|
|
4017
4029
|
} else {
|
|
4018
|
-
__privateGet$
|
|
4030
|
+
__privateGet$5(this, _state).icon = bulletListIcon;
|
|
4019
4031
|
}
|
|
4020
4032
|
break;
|
|
4021
4033
|
case "bullet_list":
|
|
4022
|
-
__privateGet$
|
|
4034
|
+
__privateGet$5(this, _state).icon = bulletListIcon;
|
|
4023
4035
|
break;
|
|
4024
4036
|
case "ordered_list":
|
|
4025
|
-
__privateGet$
|
|
4037
|
+
__privateGet$5(this, _state).icon = orderedListIcon;
|
|
4026
4038
|
break;
|
|
4027
4039
|
default:
|
|
4028
|
-
__privateGet$
|
|
4040
|
+
__privateGet$5(this, _state).icon = textIcon;
|
|
4029
4041
|
}
|
|
4030
4042
|
});
|
|
4031
4043
|
this.destroy = () => {
|
|
4032
|
-
__privateGet$
|
|
4033
|
-
__privateGet$
|
|
4034
|
-
__privateGet$
|
|
4044
|
+
__privateGet$5(this, _provider$1).destroy();
|
|
4045
|
+
__privateGet$5(this, _content$3).remove();
|
|
4046
|
+
__privateGet$5(this, _app$3).unmount();
|
|
4035
4047
|
};
|
|
4036
4048
|
this.onAdd = (el) => {
|
|
4037
|
-
const ctx = __privateGet$
|
|
4049
|
+
const ctx = __privateGet$5(this, _ctx$1);
|
|
4038
4050
|
const view = ctx.get(editorViewCtx);
|
|
4039
4051
|
if (!view.hasFocus()) view.focus();
|
|
4040
|
-
const active = __privateGet$
|
|
4052
|
+
const active = __privateGet$5(this, _provider$1).active;
|
|
4041
4053
|
if (!active) return;
|
|
4042
4054
|
const $pos = active.$pos;
|
|
4043
4055
|
ctx.get(menuAPI.key).show($pos.pos, true, el, "list");
|
|
4044
4056
|
};
|
|
4045
4057
|
this.onOpenMenu = (el) => {
|
|
4046
|
-
const ctx = __privateGet$
|
|
4047
|
-
const active = __privateGet$
|
|
4058
|
+
const ctx = __privateGet$5(this, _ctx$1);
|
|
4059
|
+
const active = __privateGet$5(this, _provider$1).active;
|
|
4048
4060
|
if (!active) return;
|
|
4049
4061
|
const $pos = active.$pos;
|
|
4050
4062
|
ctx.get(menuAPI.key).show($pos.pos, true, el, "block");
|
|
4051
4063
|
};
|
|
4052
4064
|
this.onHoverAdd = (el) => {
|
|
4053
|
-
const ctx = __privateGet$
|
|
4054
|
-
const active = __privateGet$
|
|
4065
|
+
const ctx = __privateGet$5(this, _ctx$1);
|
|
4066
|
+
const active = __privateGet$5(this, _provider$1).active;
|
|
4055
4067
|
if (!active) return;
|
|
4056
4068
|
const $pos = active.$pos;
|
|
4057
4069
|
ctx.get(menuAPI.key).show($pos.pos, false, el, "list");
|
|
4058
4070
|
};
|
|
4059
4071
|
this.onLeaveAdd = () => {
|
|
4060
|
-
const ctx = __privateGet$
|
|
4072
|
+
const ctx = __privateGet$5(this, _ctx$1);
|
|
4061
4073
|
ctx.get(menuAPI.key).onHoverDelayHide();
|
|
4062
4074
|
};
|
|
4063
4075
|
this.onHoverMenu = (el) => {
|
|
4064
|
-
const ctx = __privateGet$
|
|
4065
|
-
const active = __privateGet$
|
|
4076
|
+
const ctx = __privateGet$5(this, _ctx$1);
|
|
4077
|
+
const active = __privateGet$5(this, _provider$1).active;
|
|
4066
4078
|
if (!active) return;
|
|
4067
4079
|
const $pos = active.$pos;
|
|
4068
4080
|
ctx.get(menuAPI.key).show($pos.pos, false, el, "block");
|
|
4069
4081
|
};
|
|
4070
4082
|
this.onLeaveMenu = () => {
|
|
4071
|
-
const ctx = __privateGet$
|
|
4083
|
+
const ctx = __privateGet$5(this, _ctx$1);
|
|
4072
4084
|
ctx.get(menuAPI.key).onHoverDelayHide();
|
|
4073
4085
|
};
|
|
4074
4086
|
var _a, _b, _c;
|
|
4075
|
-
__privateSet$
|
|
4087
|
+
__privateSet$5(this, _ctx$1, ctx);
|
|
4076
4088
|
const content = document.createElement("div");
|
|
4077
4089
|
content.classList.add("milkdown-block-handle");
|
|
4078
4090
|
document.querySelectorAll(".milkdown-block-handle").forEach((el) => {
|
|
@@ -4087,14 +4099,14 @@ class BlockHandleView {
|
|
|
4087
4099
|
onLeaveMenu: this.onLeaveMenu,
|
|
4088
4100
|
addIcon: (_a = config == null ? void 0 : config.handleAddIcon) != null ? _a : plusIcon,
|
|
4089
4101
|
handleIcon: (_b = config == null ? void 0 : config.handleDragIcon) != null ? _b : menuIcon,
|
|
4090
|
-
ctx: __privateGet$
|
|
4091
|
-
state: __privateGet$
|
|
4102
|
+
ctx: __privateGet$5(this, _ctx$1),
|
|
4103
|
+
state: __privateGet$5(this, _state)
|
|
4092
4104
|
});
|
|
4093
4105
|
app.mount(content);
|
|
4094
|
-
__privateSet$
|
|
4095
|
-
__privateSet$
|
|
4106
|
+
__privateSet$5(this, _app$3, app);
|
|
4107
|
+
__privateSet$5(this, _content$3, content);
|
|
4096
4108
|
const blockProviderOptions = (_c = config == null ? void 0 : config.blockHandle) != null ? _c : {};
|
|
4097
|
-
__privateSet$
|
|
4109
|
+
__privateSet$5(this, _provider$1, new BlockProvider({
|
|
4098
4110
|
ctx,
|
|
4099
4111
|
content,
|
|
4100
4112
|
getOffset: () => 16,
|
|
@@ -4111,11 +4123,11 @@ class BlockHandleView {
|
|
|
4111
4123
|
const isMedia = node.type.name.includes("image") || node.type.name.includes("attachment") || node.type.name === "hr" || node.type.name.includes("math") || hasMediaChild;
|
|
4112
4124
|
const isEmpty = node.textContent.length === 0 && node.content.size <= 2 && !isMedia;
|
|
4113
4125
|
if (isEmpty) {
|
|
4114
|
-
__privateGet$
|
|
4126
|
+
__privateGet$5(this, _content$3).classList.add("empty-block");
|
|
4115
4127
|
} else {
|
|
4116
|
-
__privateGet$
|
|
4128
|
+
__privateGet$5(this, _content$3).classList.remove("empty-block");
|
|
4117
4129
|
}
|
|
4118
|
-
__privateGet$
|
|
4130
|
+
__privateGet$5(this, _syncIcon).call(this, active.node);
|
|
4119
4131
|
let totalDescendant = 0;
|
|
4120
4132
|
active.node.descendants((node2) => {
|
|
4121
4133
|
totalDescendant += node2.childCount;
|
|
@@ -4147,7 +4159,7 @@ _content$3 = new WeakMap();
|
|
|
4147
4159
|
_provider$1 = new WeakMap();
|
|
4148
4160
|
_state = new WeakMap();
|
|
4149
4161
|
_app$3 = new WeakMap();
|
|
4150
|
-
_ctx = new WeakMap();
|
|
4162
|
+
_ctx$1 = new WeakMap();
|
|
4151
4163
|
_syncIcon = new WeakMap();
|
|
4152
4164
|
function configureBlockHandle(ctx, config) {
|
|
4153
4165
|
ctx.set(blockConfig.key, {
|
|
@@ -4294,6 +4306,50 @@ const cursor = (editor, config) => {
|
|
|
4294
4306
|
editor.use($prose(() => virtualCursor));
|
|
4295
4307
|
};
|
|
4296
4308
|
|
|
4309
|
+
const diffBlockFeature = (editor, config = {}) => {
|
|
4310
|
+
editor.config(crepeFeatureConfig(CrepeFeature.DiffBlock)).config((ctx) => {
|
|
4311
|
+
const { languages = [], theme } = config;
|
|
4312
|
+
const extensions = [basicSetup];
|
|
4313
|
+
if (theme) {
|
|
4314
|
+
extensions.push(theme);
|
|
4315
|
+
} else {
|
|
4316
|
+
extensions.push(oneDark);
|
|
4317
|
+
}
|
|
4318
|
+
if (config.extensions) {
|
|
4319
|
+
extensions.push(...config.extensions);
|
|
4320
|
+
}
|
|
4321
|
+
ctx.update(diffBlockConfig.key, (defaultConfig) => ({
|
|
4322
|
+
...defaultConfig,
|
|
4323
|
+
extensions,
|
|
4324
|
+
languages: languages.length > 0 ? languages : defaultConfig.languages,
|
|
4325
|
+
renderLanguage: config.renderLanguage || defaultConfig.renderLanguage
|
|
4326
|
+
}));
|
|
4327
|
+
}).use(diffBlock);
|
|
4328
|
+
};
|
|
4329
|
+
|
|
4330
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
4331
|
+
let _popupCount = 0;
|
|
4332
|
+
function getIsAnyPopupOpen() {
|
|
4333
|
+
return _popupCount > 0;
|
|
4334
|
+
}
|
|
4335
|
+
function addPopupChangeListener(fn) {
|
|
4336
|
+
listeners.add(fn);
|
|
4337
|
+
return () => listeners.delete(fn);
|
|
4338
|
+
}
|
|
4339
|
+
function incrementPopupCount() {
|
|
4340
|
+
const wasZero = _popupCount === 0;
|
|
4341
|
+
_popupCount++;
|
|
4342
|
+
if (wasZero) {
|
|
4343
|
+
listeners.forEach((fn) => fn());
|
|
4344
|
+
}
|
|
4345
|
+
}
|
|
4346
|
+
function decrementPopupCount() {
|
|
4347
|
+
_popupCount = Math.max(0, _popupCount - 1);
|
|
4348
|
+
if (_popupCount === 0) {
|
|
4349
|
+
listeners.forEach((fn) => fn());
|
|
4350
|
+
}
|
|
4351
|
+
}
|
|
4352
|
+
|
|
4297
4353
|
const remarkHighlightMarkPlugin = $remark(
|
|
4298
4354
|
"remarkHighlightMark",
|
|
4299
4355
|
() => function() {
|
|
@@ -5390,6 +5446,8 @@ const Toolbar = defineComponent({
|
|
|
5390
5446
|
const {
|
|
5391
5447
|
marks: savedMarks,
|
|
5392
5448
|
align: savedAlign,
|
|
5449
|
+
blockType: savedBlockType,
|
|
5450
|
+
blockAttrs: savedBlockAttrs,
|
|
5393
5451
|
isPersistent
|
|
5394
5452
|
} = formatPainterState.value;
|
|
5395
5453
|
let applied = false;
|
|
@@ -5411,6 +5469,30 @@ const Toolbar = defineComponent({
|
|
|
5411
5469
|
}
|
|
5412
5470
|
);
|
|
5413
5471
|
}
|
|
5472
|
+
if (savedBlockType) {
|
|
5473
|
+
curState.doc.nodesBetween(
|
|
5474
|
+
curSelection.from,
|
|
5475
|
+
curSelection.to,
|
|
5476
|
+
(node, pos) => {
|
|
5477
|
+
if (node.type.name === "paragraph") {
|
|
5478
|
+
tr.setNodeMarkup(
|
|
5479
|
+
pos,
|
|
5480
|
+
curState.schema.nodes[savedBlockType],
|
|
5481
|
+
{
|
|
5482
|
+
...savedBlockAttrs,
|
|
5483
|
+
...savedAlign ? { align: savedAlign } : {}
|
|
5484
|
+
}
|
|
5485
|
+
);
|
|
5486
|
+
} else if (node.type.name === "heading" && savedBlockAttrs) {
|
|
5487
|
+
tr.setNodeMarkup(pos, null, {
|
|
5488
|
+
...node.attrs,
|
|
5489
|
+
...savedBlockAttrs,
|
|
5490
|
+
...savedAlign ? { align: savedAlign } : {}
|
|
5491
|
+
});
|
|
5492
|
+
}
|
|
5493
|
+
}
|
|
5494
|
+
);
|
|
5495
|
+
}
|
|
5414
5496
|
dispatch(tr);
|
|
5415
5497
|
applied = true;
|
|
5416
5498
|
} else {
|
|
@@ -5443,6 +5525,22 @@ const Toolbar = defineComponent({
|
|
|
5443
5525
|
});
|
|
5444
5526
|
}
|
|
5445
5527
|
}
|
|
5528
|
+
if (savedBlockType) {
|
|
5529
|
+
const pos = curSelection.$from.before(curSelection.$from.depth);
|
|
5530
|
+
const node = curState.doc.nodeAt(pos);
|
|
5531
|
+
if (node && node.type.name === "paragraph") {
|
|
5532
|
+
tr.setNodeMarkup(pos, curState.schema.nodes[savedBlockType], {
|
|
5533
|
+
...savedBlockAttrs,
|
|
5534
|
+
...savedAlign ? { align: savedAlign } : {}
|
|
5535
|
+
});
|
|
5536
|
+
} else if (node && node.type.name === "heading" && savedBlockAttrs) {
|
|
5537
|
+
tr.setNodeMarkup(pos, null, {
|
|
5538
|
+
...node.attrs,
|
|
5539
|
+
...savedBlockAttrs,
|
|
5540
|
+
...savedAlign ? { align: savedAlign } : {}
|
|
5541
|
+
});
|
|
5542
|
+
}
|
|
5543
|
+
}
|
|
5446
5544
|
tr.setStoredMarks(savedMarks);
|
|
5447
5545
|
dispatch(tr);
|
|
5448
5546
|
applied = true;
|
|
@@ -5491,7 +5589,22 @@ const Toolbar = defineComponent({
|
|
|
5491
5589
|
}
|
|
5492
5590
|
}
|
|
5493
5591
|
align = foundAlign;
|
|
5494
|
-
|
|
5592
|
+
let blockType = null;
|
|
5593
|
+
let blockAttrs = null;
|
|
5594
|
+
{
|
|
5595
|
+
const parent = selection.$from.parent;
|
|
5596
|
+
if (parent.type.name === "heading") {
|
|
5597
|
+
blockType = "heading";
|
|
5598
|
+
blockAttrs = { level: parent.attrs.level };
|
|
5599
|
+
}
|
|
5600
|
+
}
|
|
5601
|
+
formatPainterState.value = {
|
|
5602
|
+
marks,
|
|
5603
|
+
align,
|
|
5604
|
+
blockType,
|
|
5605
|
+
blockAttrs,
|
|
5606
|
+
isPersistent
|
|
5607
|
+
};
|
|
5495
5608
|
document.removeEventListener("pointerup", formatPainterHandler);
|
|
5496
5609
|
setTimeout(() => {
|
|
5497
5610
|
document.addEventListener("pointerup", formatPainterHandler);
|
|
@@ -5544,6 +5657,13 @@ const Toolbar = defineComponent({
|
|
|
5544
5657
|
const showOverflowMenu = ref(false);
|
|
5545
5658
|
const overflowMenuPos = ref({ top: 0 });
|
|
5546
5659
|
const cachedWidths = /* @__PURE__ */ new Map();
|
|
5660
|
+
const anyFixedPopup = computed(
|
|
5661
|
+
() => !!isFixed && (showBlockMenu.value || showAlignMenu.value || showColorMenu.value || showFontFamilyMenu.value || showFontSizeMenu.value || showTableMenu.value || showOverflowMenu.value)
|
|
5662
|
+
);
|
|
5663
|
+
watch(anyFixedPopup, (val) => {
|
|
5664
|
+
if (val) incrementPopupCount();
|
|
5665
|
+
else decrementPopupCount();
|
|
5666
|
+
});
|
|
5547
5667
|
const getMenuLeftPos = (rect, menuWidth) => {
|
|
5548
5668
|
let left = rect.left;
|
|
5549
5669
|
if (left + menuWidth > window.innerWidth) {
|
|
@@ -5586,7 +5706,8 @@ const Toolbar = defineComponent({
|
|
|
5586
5706
|
containerWidth = container.clientWidth;
|
|
5587
5707
|
}
|
|
5588
5708
|
} else {
|
|
5589
|
-
|
|
5709
|
+
const view = ctx.get(editorViewCtx);
|
|
5710
|
+
containerWidth = view.dom.clientWidth - 32;
|
|
5590
5711
|
}
|
|
5591
5712
|
if (containerWidth === lastContainerWidth) {
|
|
5592
5713
|
return;
|
|
@@ -5780,6 +5901,7 @@ const Toolbar = defineComponent({
|
|
|
5780
5901
|
if (hideFontFamilyTimer) clearTimeout(hideFontFamilyTimer);
|
|
5781
5902
|
if (hideFontSizeTimer) clearTimeout(hideFontSizeTimer);
|
|
5782
5903
|
if (hideTableTimer) clearTimeout(hideTableTimer);
|
|
5904
|
+
if (anyFixedPopup.value) decrementPopupCount();
|
|
5783
5905
|
});
|
|
5784
5906
|
let overflowResizeObserver = null;
|
|
5785
5907
|
let overflowSetupDone = false;
|
|
@@ -6218,13 +6340,11 @@ const Toolbar = defineComponent({
|
|
|
6218
6340
|
});
|
|
6219
6341
|
}
|
|
6220
6342
|
});
|
|
6221
|
-
const nonHeadingGroups = toolbarGroupInfo.value.filter(
|
|
6222
|
-
(group)
|
|
6223
|
-
|
|
6224
|
-
|
|
6225
|
-
|
|
6226
|
-
}
|
|
6227
|
-
);
|
|
6343
|
+
const nonHeadingGroups = toolbarGroupInfo.value.filter((group) => {
|
|
6344
|
+
if (group.key === "heading") return false;
|
|
6345
|
+
if (props.isFixed && group.key === "function") return false;
|
|
6346
|
+
return true;
|
|
6347
|
+
});
|
|
6228
6348
|
const isSectionOverflowed = (idx) => idx >= overflowVisibleCount.value;
|
|
6229
6349
|
const hasOverflow = overflowVisibleCount.value < totalSectionCount.value;
|
|
6230
6350
|
return /* @__PURE__ */ h(
|
|
@@ -7520,7 +7640,7 @@ const createViewMenuState = () => reactive({
|
|
|
7520
7640
|
outlineVisible: false,
|
|
7521
7641
|
outlinePosition: "left",
|
|
7522
7642
|
outlineWidth: 250,
|
|
7523
|
-
documentBackground:
|
|
7643
|
+
documentBackground: "#FFFFFF",
|
|
7524
7644
|
showTitle: false,
|
|
7525
7645
|
showCover: false,
|
|
7526
7646
|
coverUrl: "",
|
|
@@ -7620,10 +7740,15 @@ const MenuBar = defineComponent({
|
|
|
7620
7740
|
onUnmounted(() => {
|
|
7621
7741
|
document.removeEventListener("click", closeMenu);
|
|
7622
7742
|
if (rafId) cancelAnimationFrame(rafId);
|
|
7743
|
+
if (showMenu.value) decrementPopupCount();
|
|
7744
|
+
});
|
|
7745
|
+
watch(showMenu, (val) => {
|
|
7746
|
+
if (val) incrementPopupCount();
|
|
7747
|
+
else decrementPopupCount();
|
|
7623
7748
|
});
|
|
7624
7749
|
const viewState = computed(() => props.ctx.get(viewMenuStateCtx.key));
|
|
7625
7750
|
const bgColors = [
|
|
7626
|
-
{ name: "\
|
|
7751
|
+
{ name: "\u767D\u8272", value: "#FFFFFF" },
|
|
7627
7752
|
{ name: "\u6D45\u7070", value: "#F7F7F5" },
|
|
7628
7753
|
{ name: "\u6D45\u68D5", value: "#F4EEDB" },
|
|
7629
7754
|
{ name: "\u6D45\u6A59", value: "#FBECDD" },
|
|
@@ -8111,7 +8236,7 @@ const rightGroups = [
|
|
|
8111
8236
|
titleKey: "shortcuts.history",
|
|
8112
8237
|
items: [
|
|
8113
8238
|
{ labelKey: "shortcuts.undo", keys: ["Mod+z"] },
|
|
8114
|
-
{ labelKey: "shortcuts.redo", keys: ["Mod+y", "Shift+Mod+
|
|
8239
|
+
{ labelKey: "shortcuts.redo", keys: ["Mod+y", "Shift+Mod+Z"] }
|
|
8115
8240
|
]
|
|
8116
8241
|
}
|
|
8117
8242
|
];
|
|
@@ -9256,11 +9381,11 @@ const OutlinePanel = defineComponent({
|
|
|
9256
9381
|
"div",
|
|
9257
9382
|
{
|
|
9258
9383
|
style: {
|
|
9259
|
-
padding: "
|
|
9384
|
+
padding: "12px 16px",
|
|
9260
9385
|
fontWeight: "bold",
|
|
9261
9386
|
fontSize: "14px",
|
|
9262
9387
|
color: "var(--crepe-color-on-surface)",
|
|
9263
|
-
borderBottom: "1px solid var(--crepe-color-outline-variant)",
|
|
9388
|
+
borderBottom: "1px solid var(--crepe-color-outline-variant, color-mix(in srgb, var(--crepe-color-outline, #ddd), transparent 80%))",
|
|
9264
9389
|
display: "flex",
|
|
9265
9390
|
justifyContent: "space-between",
|
|
9266
9391
|
alignItems: "center"
|
|
@@ -9432,14 +9557,14 @@ const OutlinePanel = defineComponent({
|
|
|
9432
9557
|
}
|
|
9433
9558
|
});
|
|
9434
9559
|
|
|
9435
|
-
var __typeError$
|
|
9560
|
+
var __typeError$4 = (msg) => {
|
|
9436
9561
|
throw TypeError(msg);
|
|
9437
9562
|
};
|
|
9438
|
-
var __accessCheck$
|
|
9439
|
-
var __privateGet$
|
|
9440
|
-
var __privateAdd$
|
|
9441
|
-
var __privateSet$
|
|
9442
|
-
var _content$2, _app$2, _headerContent, _headerApp, _outlineContent, _outlineApp, _watcher, _selection$1, _show$1, _resizeObserver, _updateOutlineGeometry, _scrollContainers, _view;
|
|
9563
|
+
var __accessCheck$4 = (obj, member, msg) => member.has(obj) || __typeError$4("Cannot " + msg);
|
|
9564
|
+
var __privateGet$4 = (obj, member, getter) => (__accessCheck$4(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
9565
|
+
var __privateAdd$4 = (obj, member, value) => member.has(obj) ? __typeError$4("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
9566
|
+
var __privateSet$4 = (obj, member, value, setter) => (__accessCheck$4(obj, member, "write to private field"), member.set(obj, value), value);
|
|
9567
|
+
var _content$2, _app$2, _headerContent, _headerApp, _outlineContent, _outlineApp, _watcher, _selection$1, _show$1, _resizeObserver$1, _updateOutlineGeometry, _scrollContainers$1, _onDblClick, _view$1, _editorContainer;
|
|
9443
9568
|
const fixedToolbarConfig = $ctx(
|
|
9444
9569
|
{},
|
|
9445
9570
|
"fixedToolbarConfigCtx"
|
|
@@ -9447,88 +9572,127 @@ const fixedToolbarConfig = $ctx(
|
|
|
9447
9572
|
const fixedToolbarKey = new PluginKey("MILKDOWN_FIXED_TOOLBAR");
|
|
9448
9573
|
class FixedToolbarView {
|
|
9449
9574
|
constructor(ctx, view) {
|
|
9450
|
-
__privateAdd$
|
|
9451
|
-
__privateAdd$
|
|
9452
|
-
__privateAdd$
|
|
9453
|
-
__privateAdd$
|
|
9454
|
-
__privateAdd$
|
|
9455
|
-
__privateAdd$
|
|
9456
|
-
__privateAdd$
|
|
9457
|
-
__privateAdd$
|
|
9458
|
-
__privateAdd$
|
|
9459
|
-
__privateAdd$
|
|
9460
|
-
__privateAdd$
|
|
9461
|
-
__privateAdd$
|
|
9462
|
-
__privateAdd$
|
|
9575
|
+
__privateAdd$4(this, _content$2);
|
|
9576
|
+
__privateAdd$4(this, _app$2);
|
|
9577
|
+
__privateAdd$4(this, _headerContent);
|
|
9578
|
+
__privateAdd$4(this, _headerApp);
|
|
9579
|
+
__privateAdd$4(this, _outlineContent);
|
|
9580
|
+
__privateAdd$4(this, _outlineApp);
|
|
9581
|
+
__privateAdd$4(this, _watcher);
|
|
9582
|
+
__privateAdd$4(this, _selection$1);
|
|
9583
|
+
__privateAdd$4(this, _show$1, ref(true));
|
|
9584
|
+
__privateAdd$4(this, _resizeObserver$1);
|
|
9585
|
+
__privateAdd$4(this, _updateOutlineGeometry);
|
|
9586
|
+
__privateAdd$4(this, _scrollContainers$1, []);
|
|
9587
|
+
__privateAdd$4(this, _onDblClick);
|
|
9588
|
+
__privateAdd$4(this, _view$1);
|
|
9589
|
+
__privateAdd$4(this, _editorContainer);
|
|
9463
9590
|
this.update = (view) => {
|
|
9464
|
-
__privateGet$
|
|
9591
|
+
__privateGet$4(this, _selection$1).value = view.state.selection;
|
|
9465
9592
|
};
|
|
9466
9593
|
this.destroy = () => {
|
|
9467
|
-
if (__privateGet$
|
|
9468
|
-
if (__privateGet$
|
|
9469
|
-
|
|
9470
|
-
|
|
9594
|
+
if (__privateGet$4(this, _watcher)) __privateGet$4(this, _watcher).call(this);
|
|
9595
|
+
if (__privateGet$4(this, _onDblClick)) {
|
|
9596
|
+
__privateGet$4(this, _view$1).dom.removeEventListener("dblclick", __privateGet$4(this, _onDblClick));
|
|
9597
|
+
}
|
|
9598
|
+
if (__privateGet$4(this, _resizeObserver$1)) __privateGet$4(this, _resizeObserver$1).disconnect();
|
|
9599
|
+
window.removeEventListener("resize", __privateGet$4(this, _updateOutlineGeometry));
|
|
9600
|
+
window.removeEventListener("scroll", __privateGet$4(this, _updateOutlineGeometry), {
|
|
9471
9601
|
capture: true
|
|
9472
9602
|
});
|
|
9473
|
-
__privateGet$
|
|
9474
|
-
el.removeEventListener("scroll", __privateGet$
|
|
9603
|
+
__privateGet$4(this, _scrollContainers$1).forEach((el) => {
|
|
9604
|
+
el.removeEventListener("scroll", __privateGet$4(this, _updateOutlineGeometry));
|
|
9475
9605
|
});
|
|
9476
|
-
__privateSet$
|
|
9477
|
-
__privateGet$
|
|
9478
|
-
__privateGet$
|
|
9479
|
-
if (__privateGet$
|
|
9480
|
-
if (__privateGet$
|
|
9481
|
-
if (__privateGet$
|
|
9482
|
-
if (__privateGet$
|
|
9606
|
+
__privateSet$4(this, _scrollContainers$1, []);
|
|
9607
|
+
__privateGet$4(this, _app$2).unmount();
|
|
9608
|
+
__privateGet$4(this, _content$2).remove();
|
|
9609
|
+
if (__privateGet$4(this, _headerApp)) __privateGet$4(this, _headerApp).unmount();
|
|
9610
|
+
if (__privateGet$4(this, _headerContent)) __privateGet$4(this, _headerContent).remove();
|
|
9611
|
+
if (__privateGet$4(this, _outlineApp)) __privateGet$4(this, _outlineApp).unmount();
|
|
9612
|
+
if (__privateGet$4(this, _outlineContent)) __privateGet$4(this, _outlineContent).remove();
|
|
9483
9613
|
};
|
|
9484
|
-
__privateSet$
|
|
9614
|
+
__privateSet$4(this, _view$1, view);
|
|
9485
9615
|
const config = ctx.get(fixedToolbarConfig.key);
|
|
9486
9616
|
const content = document.createElement("div");
|
|
9487
9617
|
content.className = "milkdown-fixed-toolbar";
|
|
9488
|
-
__privateSet$
|
|
9618
|
+
__privateSet$4(this, _selection$1, shallowRef(view.state.selection));
|
|
9489
9619
|
const app = createApp(FixedToolbarComponent, {
|
|
9490
9620
|
ctx,
|
|
9491
9621
|
hide: () => {
|
|
9492
9622
|
},
|
|
9493
9623
|
// No-op for fixed toolbar
|
|
9494
9624
|
config,
|
|
9495
|
-
selection: __privateGet$
|
|
9496
|
-
show: __privateGet$
|
|
9625
|
+
selection: __privateGet$4(this, _selection$1),
|
|
9626
|
+
show: __privateGet$4(this, _show$1)
|
|
9497
9627
|
});
|
|
9498
9628
|
app.mount(content);
|
|
9499
|
-
__privateSet$
|
|
9500
|
-
__privateSet$
|
|
9629
|
+
__privateSet$4(this, _content$2, content);
|
|
9630
|
+
__privateSet$4(this, _app$2, app);
|
|
9501
9631
|
const root = view.dom.parentElement;
|
|
9502
9632
|
if (root) {
|
|
9503
9633
|
root.style.position = "relative";
|
|
9504
|
-
root.style.transition = "
|
|
9505
|
-
root.prepend(__privateGet$
|
|
9634
|
+
root.style.transition = "background-color 0.2s ease-out";
|
|
9635
|
+
root.prepend(__privateGet$4(this, _content$2));
|
|
9636
|
+
const editorContainer = document.createElement("div");
|
|
9637
|
+
editorContainer.className = "milkdown-editor-container";
|
|
9638
|
+
editorContainer.style.transition = "padding 0.1s ease-out";
|
|
9639
|
+
editorContainer.style.display = "flex";
|
|
9640
|
+
editorContainer.style.flexDirection = "column";
|
|
9641
|
+
editorContainer.style.flexGrow = "1";
|
|
9642
|
+
root.insertBefore(editorContainer, view.dom);
|
|
9643
|
+
editorContainer.appendChild(view.dom);
|
|
9644
|
+
__privateSet$4(this, _editorContainer, editorContainer);
|
|
9506
9645
|
const headerContent = document.createElement("div");
|
|
9507
|
-
__privateSet$
|
|
9508
|
-
__privateGet$
|
|
9509
|
-
__privateSet$
|
|
9510
|
-
|
|
9646
|
+
__privateSet$4(this, _headerApp, createApp(DocumentHeader, { ctx, config }));
|
|
9647
|
+
__privateGet$4(this, _headerApp).mount(headerContent);
|
|
9648
|
+
__privateSet$4(this, _headerContent, headerContent);
|
|
9649
|
+
editorContainer.insertBefore(headerContent, view.dom);
|
|
9511
9650
|
const outlineContent = document.createElement("div");
|
|
9512
9651
|
outlineContent.style.position = "fixed";
|
|
9513
9652
|
outlineContent.style.zIndex = "100";
|
|
9514
|
-
__privateSet$
|
|
9515
|
-
__privateGet$
|
|
9516
|
-
__privateSet$
|
|
9653
|
+
__privateSet$4(this, _outlineApp, createApp(OutlinePanel, { ctx }));
|
|
9654
|
+
__privateGet$4(this, _outlineApp).mount(outlineContent);
|
|
9655
|
+
__privateSet$4(this, _outlineContent, outlineContent);
|
|
9517
9656
|
root.appendChild(outlineContent);
|
|
9518
|
-
|
|
9657
|
+
__privateSet$4(this, _onDblClick, (event) => {
|
|
9658
|
+
const view2 = __privateGet$4(this, _view$1);
|
|
9659
|
+
if (!view2.editable) return;
|
|
9660
|
+
const dom = view2.dom;
|
|
9661
|
+
const children = dom.children;
|
|
9662
|
+
if (children.length === 0) return;
|
|
9663
|
+
const lastChild = children[children.length - 1];
|
|
9664
|
+
if (!lastChild) return;
|
|
9665
|
+
const lastRect = lastChild.getBoundingClientRect();
|
|
9666
|
+
if (event.clientY <= lastRect.bottom) return;
|
|
9667
|
+
const { doc } = view2.state;
|
|
9668
|
+
const lastNode = doc.lastChild;
|
|
9669
|
+
if (!lastNode) return;
|
|
9670
|
+
if (lastNode.type.name === "paragraph" && lastNode.content.size === 0)
|
|
9671
|
+
return;
|
|
9672
|
+
const paragraphType = view2.state.schema.nodes["paragraph"];
|
|
9673
|
+
if (!paragraphType) return;
|
|
9674
|
+
const pos = doc.content.size;
|
|
9675
|
+
const tr = view2.state.tr.insert(pos, paragraphType.create());
|
|
9676
|
+
const sel = TextSelection.create(tr.doc, pos + 1);
|
|
9677
|
+
tr.setSelection(sel);
|
|
9678
|
+
view2.dispatch(tr);
|
|
9679
|
+
view2.focus();
|
|
9680
|
+
});
|
|
9681
|
+
view.dom.addEventListener("dblclick", __privateGet$4(this, _onDblClick));
|
|
9682
|
+
__privateGet$4(this, _content$2).style.transition = "margin 0.1s ease-out, width 0.1s ease-out";
|
|
9519
9683
|
const viewState = ctx.get(viewMenuStateCtx.key);
|
|
9520
9684
|
if (config.outlinePosition) {
|
|
9521
9685
|
viewState.outlinePosition = config.outlinePosition;
|
|
9522
9686
|
}
|
|
9523
|
-
__privateSet$
|
|
9687
|
+
__privateSet$4(this, _updateOutlineGeometry, () => {
|
|
9524
9688
|
const rootRect = root.getBoundingClientRect();
|
|
9525
9689
|
let outlineTop = rootRect.top;
|
|
9526
|
-
if (__privateGet$
|
|
9527
|
-
const toolbarRect = __privateGet$
|
|
9690
|
+
if (__privateGet$4(this, _content$2) && __privateGet$4(this, _content$2).offsetHeight > 0) {
|
|
9691
|
+
const toolbarRect = __privateGet$4(this, _content$2).getBoundingClientRect();
|
|
9528
9692
|
outlineTop = Math.max(outlineTop, toolbarRect.bottom);
|
|
9529
9693
|
}
|
|
9530
|
-
if (viewState.showCover && __privateGet$
|
|
9531
|
-
const coverEl = __privateGet$
|
|
9694
|
+
if (viewState.showCover && __privateGet$4(this, _headerContent)) {
|
|
9695
|
+
const coverEl = __privateGet$4(this, _headerContent).querySelector(
|
|
9532
9696
|
".milkdown-document-cover"
|
|
9533
9697
|
);
|
|
9534
9698
|
if (coverEl) {
|
|
@@ -9550,28 +9714,50 @@ class FixedToolbarView {
|
|
|
9550
9714
|
outlineContent.style.right = "auto";
|
|
9551
9715
|
} else {
|
|
9552
9716
|
outlineContent.style.left = "auto";
|
|
9553
|
-
|
|
9717
|
+
let baseOffset = window.innerWidth - rootRect.right;
|
|
9718
|
+
let rightOffset = baseOffset;
|
|
9719
|
+
let hasVScroll = false;
|
|
9720
|
+
if (document.documentElement.scrollHeight > window.innerHeight) {
|
|
9721
|
+
hasVScroll = true;
|
|
9722
|
+
}
|
|
9723
|
+
let parent = root;
|
|
9724
|
+
while (parent && parent !== document.body) {
|
|
9725
|
+
const { overflowY } = getComputedStyle(parent);
|
|
9726
|
+
if (overflowY === "auto" || overflowY === "scroll") {
|
|
9727
|
+
if (parent.scrollHeight > parent.clientHeight) {
|
|
9728
|
+
hasVScroll = true;
|
|
9729
|
+
break;
|
|
9730
|
+
}
|
|
9731
|
+
}
|
|
9732
|
+
parent = parent.parentElement;
|
|
9733
|
+
}
|
|
9734
|
+
if (hasVScroll) {
|
|
9735
|
+
rightOffset = Math.max(rightOffset, 32);
|
|
9736
|
+
} else {
|
|
9737
|
+
rightOffset = Math.max(rightOffset, 0);
|
|
9738
|
+
}
|
|
9739
|
+
outlineContent.style.right = `${rightOffset}px`;
|
|
9554
9740
|
}
|
|
9555
9741
|
}
|
|
9556
9742
|
});
|
|
9557
|
-
__privateSet$
|
|
9558
|
-
__privateGet$
|
|
9559
|
-
window.addEventListener("resize", __privateGet$
|
|
9560
|
-
window.addEventListener("scroll", __privateGet$
|
|
9743
|
+
__privateSet$4(this, _resizeObserver$1, new ResizeObserver(__privateGet$4(this, _updateOutlineGeometry)));
|
|
9744
|
+
__privateGet$4(this, _resizeObserver$1).observe(root);
|
|
9745
|
+
window.addEventListener("resize", __privateGet$4(this, _updateOutlineGeometry));
|
|
9746
|
+
window.addEventListener("scroll", __privateGet$4(this, _updateOutlineGeometry), {
|
|
9561
9747
|
capture: true,
|
|
9562
9748
|
passive: true
|
|
9563
9749
|
});
|
|
9564
9750
|
let scrollerNode = root;
|
|
9565
9751
|
while (scrollerNode && scrollerNode !== document) {
|
|
9566
9752
|
if (scrollerNode instanceof Element) {
|
|
9567
|
-
scrollerNode.addEventListener("scroll", __privateGet$
|
|
9753
|
+
scrollerNode.addEventListener("scroll", __privateGet$4(this, _updateOutlineGeometry), {
|
|
9568
9754
|
passive: true
|
|
9569
9755
|
});
|
|
9570
|
-
__privateGet$
|
|
9756
|
+
__privateGet$4(this, _scrollContainers$1).push(scrollerNode);
|
|
9571
9757
|
}
|
|
9572
9758
|
scrollerNode = scrollerNode.parentNode || scrollerNode.host;
|
|
9573
9759
|
}
|
|
9574
|
-
__privateSet$
|
|
9760
|
+
__privateSet$4(this, _watcher, watch(
|
|
9575
9761
|
() => [
|
|
9576
9762
|
viewState.outlineVisible,
|
|
9577
9763
|
viewState.outlinePosition,
|
|
@@ -9586,41 +9772,43 @@ class FixedToolbarView {
|
|
|
9586
9772
|
} else {
|
|
9587
9773
|
root.style.backgroundColor = "";
|
|
9588
9774
|
}
|
|
9589
|
-
|
|
9590
|
-
|
|
9591
|
-
|
|
9592
|
-
|
|
9593
|
-
|
|
9594
|
-
|
|
9595
|
-
|
|
9775
|
+
root.style.paddingLeft = "0";
|
|
9776
|
+
root.style.paddingRight = "0";
|
|
9777
|
+
__privateGet$4(this, _content$2).style.width = "100%";
|
|
9778
|
+
__privateGet$4(this, _content$2).style.marginLeft = "0";
|
|
9779
|
+
__privateGet$4(this, _content$2).style.marginRight = "0";
|
|
9780
|
+
if (__privateGet$4(this, _editorContainer)) {
|
|
9781
|
+
if (viewState.outlineVisible) {
|
|
9782
|
+
if (viewState.outlinePosition === "left") {
|
|
9783
|
+
__privateGet$4(this, _editorContainer).style.paddingLeft = `${viewState.outlineWidth}px`;
|
|
9784
|
+
__privateGet$4(this, _editorContainer).style.paddingRight = "0";
|
|
9785
|
+
} else {
|
|
9786
|
+
__privateGet$4(this, _editorContainer).style.paddingLeft = "0";
|
|
9787
|
+
__privateGet$4(this, _editorContainer).style.paddingRight = `${viewState.outlineWidth}px`;
|
|
9788
|
+
}
|
|
9596
9789
|
} else {
|
|
9597
|
-
|
|
9598
|
-
|
|
9599
|
-
__privateGet$3(this, _content$2).style.width = `calc(100% + ${viewState.outlineWidth}px)`;
|
|
9600
|
-
__privateGet$3(this, _content$2).style.marginLeft = "0";
|
|
9601
|
-
__privateGet$3(this, _content$2).style.marginRight = `-${viewState.outlineWidth}px`;
|
|
9790
|
+
__privateGet$4(this, _editorContainer).style.paddingLeft = "0";
|
|
9791
|
+
__privateGet$4(this, _editorContainer).style.paddingRight = "0";
|
|
9602
9792
|
}
|
|
9603
|
-
} else {
|
|
9604
|
-
root.style.paddingLeft = "0";
|
|
9605
|
-
root.style.paddingRight = "0";
|
|
9606
|
-
__privateGet$3(this, _content$2).style.width = "100%";
|
|
9607
|
-
__privateGet$3(this, _content$2).style.marginLeft = "0";
|
|
9608
|
-
__privateGet$3(this, _content$2).style.marginRight = "0";
|
|
9609
9793
|
}
|
|
9610
9794
|
const maxWidth = editorWidthMap[viewState.editorWidth];
|
|
9611
9795
|
const isFull = maxWidth === "none";
|
|
9612
9796
|
const px = isFull ? "80px" : "0";
|
|
9613
|
-
__privateGet$
|
|
9614
|
-
__privateGet$
|
|
9615
|
-
__privateGet$
|
|
9616
|
-
__privateGet$
|
|
9617
|
-
if (__privateGet$
|
|
9618
|
-
__privateGet$
|
|
9619
|
-
__privateGet$
|
|
9797
|
+
__privateGet$4(this, _view$1).dom.style.maxWidth = maxWidth;
|
|
9798
|
+
__privateGet$4(this, _view$1).dom.style.width = isFull ? "100%" : maxWidth;
|
|
9799
|
+
__privateGet$4(this, _view$1).dom.style.margin = isFull ? "0" : "0 auto";
|
|
9800
|
+
__privateGet$4(this, _view$1).dom.style.padding = `20px ${px} 36px`;
|
|
9801
|
+
if (__privateGet$4(this, _headerContent)) {
|
|
9802
|
+
__privateGet$4(this, _headerContent).style.margin = isFull && !viewState.showCover ? "0 auto" : "0";
|
|
9803
|
+
__privateGet$4(this, _headerContent).style.padding = `0px`;
|
|
9620
9804
|
}
|
|
9621
|
-
nextTick(() => {
|
|
9805
|
+
void nextTick(() => {
|
|
9622
9806
|
var _a;
|
|
9623
|
-
(_a = __privateGet$
|
|
9807
|
+
(_a = __privateGet$4(this, _updateOutlineGeometry)) == null ? void 0 : _a.call(this);
|
|
9808
|
+
setTimeout(() => {
|
|
9809
|
+
var _a2;
|
|
9810
|
+
(_a2 = __privateGet$4(this, _updateOutlineGeometry)) == null ? void 0 : _a2.call(this);
|
|
9811
|
+
}, 100);
|
|
9624
9812
|
});
|
|
9625
9813
|
},
|
|
9626
9814
|
{ immediate: true }
|
|
@@ -9637,10 +9825,12 @@ _outlineApp = new WeakMap();
|
|
|
9637
9825
|
_watcher = new WeakMap();
|
|
9638
9826
|
_selection$1 = new WeakMap();
|
|
9639
9827
|
_show$1 = new WeakMap();
|
|
9640
|
-
_resizeObserver = new WeakMap();
|
|
9828
|
+
_resizeObserver$1 = new WeakMap();
|
|
9641
9829
|
_updateOutlineGeometry = new WeakMap();
|
|
9642
|
-
_scrollContainers = new WeakMap();
|
|
9643
|
-
|
|
9830
|
+
_scrollContainers$1 = new WeakMap();
|
|
9831
|
+
_onDblClick = new WeakMap();
|
|
9832
|
+
_view$1 = new WeakMap();
|
|
9833
|
+
_editorContainer = new WeakMap();
|
|
9644
9834
|
const fixedToolbarPlugin = $prose((ctx) => {
|
|
9645
9835
|
return new Plugin({
|
|
9646
9836
|
key: fixedToolbarKey,
|
|
@@ -9761,11 +9951,922 @@ const imageBlockConverter = $prose$1((ctx) => {
|
|
|
9761
9951
|
const r = replacements[i];
|
|
9762
9952
|
tr.replaceWith(r.from, r.to, r.blocks);
|
|
9763
9953
|
}
|
|
9764
|
-
return tr;
|
|
9954
|
+
return tr.setMeta("addToHistory", false);
|
|
9765
9955
|
}
|
|
9766
9956
|
});
|
|
9767
9957
|
});
|
|
9768
9958
|
|
|
9959
|
+
const typeLabels = {
|
|
9960
|
+
added: "\u65B0\u589E",
|
|
9961
|
+
removed: "\u5220\u9664"
|
|
9962
|
+
};
|
|
9963
|
+
const typeColors = {
|
|
9964
|
+
added: "#4caf50",
|
|
9965
|
+
removed: "#c0392b"
|
|
9966
|
+
};
|
|
9967
|
+
function mountChangePanel(container, changes, onNavigate, onClose) {
|
|
9968
|
+
const app = createApp({
|
|
9969
|
+
setup() {
|
|
9970
|
+
const activeTab = ref("all");
|
|
9971
|
+
const filteredChanges = computed(() => {
|
|
9972
|
+
if (activeTab.value === "all") return changes;
|
|
9973
|
+
return changes.filter((c) => c.type === activeTab.value);
|
|
9974
|
+
});
|
|
9975
|
+
const counts = computed(() => ({
|
|
9976
|
+
all: changes.length,
|
|
9977
|
+
removed: changes.filter((c) => c.type === "removed").length,
|
|
9978
|
+
added: changes.filter((c) => c.type === "added").length
|
|
9979
|
+
}));
|
|
9980
|
+
function renderTab(tab, label) {
|
|
9981
|
+
const isActive = activeTab.value === tab;
|
|
9982
|
+
return h(
|
|
9983
|
+
"button",
|
|
9984
|
+
{
|
|
9985
|
+
style: {
|
|
9986
|
+
padding: "6px 10px",
|
|
9987
|
+
border: "none",
|
|
9988
|
+
background: "none",
|
|
9989
|
+
cursor: "pointer",
|
|
9990
|
+
fontSize: "12px",
|
|
9991
|
+
color: isActive ? "#1890ff" : "#666",
|
|
9992
|
+
borderBottom: isActive ? "2px solid #1890ff" : "2px solid transparent"
|
|
9993
|
+
},
|
|
9994
|
+
onClick: () => {
|
|
9995
|
+
activeTab.value = tab;
|
|
9996
|
+
}
|
|
9997
|
+
},
|
|
9998
|
+
label
|
|
9999
|
+
);
|
|
10000
|
+
}
|
|
10001
|
+
function renderItem(change, index) {
|
|
10002
|
+
const color = typeColors[change.type];
|
|
10003
|
+
const children = [
|
|
10004
|
+
h("div", { style: { marginBottom: "4px" } }, [
|
|
10005
|
+
h(
|
|
10006
|
+
"span",
|
|
10007
|
+
{
|
|
10008
|
+
style: {
|
|
10009
|
+
display: "inline-block",
|
|
10010
|
+
padding: "1px 6px",
|
|
10011
|
+
borderRadius: "3px",
|
|
10012
|
+
color: "#fff",
|
|
10013
|
+
fontSize: "11px",
|
|
10014
|
+
fontWeight: "500",
|
|
10015
|
+
backgroundColor: color
|
|
10016
|
+
}
|
|
10017
|
+
},
|
|
10018
|
+
`${index} ${typeLabels[change.type]}`
|
|
10019
|
+
)
|
|
10020
|
+
])
|
|
10021
|
+
];
|
|
10022
|
+
if (change.oldText) {
|
|
10023
|
+
children.push(
|
|
10024
|
+
h(
|
|
10025
|
+
"div",
|
|
10026
|
+
{
|
|
10027
|
+
style: {
|
|
10028
|
+
marginTop: "3px",
|
|
10029
|
+
fontSize: "12px",
|
|
10030
|
+
lineHeight: "1.5",
|
|
10031
|
+
color: "#555",
|
|
10032
|
+
wordBreak: "break-all"
|
|
10033
|
+
}
|
|
10034
|
+
},
|
|
10035
|
+
[
|
|
10036
|
+
h(
|
|
10037
|
+
"span",
|
|
10038
|
+
{ style: { color: "#999", fontSize: "11px" } },
|
|
10039
|
+
"\u539F\u6587: "
|
|
10040
|
+
),
|
|
10041
|
+
h("span", null, change.oldText)
|
|
10042
|
+
]
|
|
10043
|
+
)
|
|
10044
|
+
);
|
|
10045
|
+
}
|
|
10046
|
+
if (change.newText) {
|
|
10047
|
+
children.push(
|
|
10048
|
+
h(
|
|
10049
|
+
"div",
|
|
10050
|
+
{
|
|
10051
|
+
style: {
|
|
10052
|
+
marginTop: "3px",
|
|
10053
|
+
fontSize: "12px",
|
|
10054
|
+
lineHeight: "1.5",
|
|
10055
|
+
wordBreak: "break-all"
|
|
10056
|
+
}
|
|
10057
|
+
},
|
|
10058
|
+
[
|
|
10059
|
+
h(
|
|
10060
|
+
"span",
|
|
10061
|
+
{ style: { color: "#999", fontSize: "11px" } },
|
|
10062
|
+
"\u5DEE\u5F02: "
|
|
10063
|
+
),
|
|
10064
|
+
h("span", { style: { color } }, change.newText)
|
|
10065
|
+
]
|
|
10066
|
+
)
|
|
10067
|
+
);
|
|
10068
|
+
}
|
|
10069
|
+
return h(
|
|
10070
|
+
"div",
|
|
10071
|
+
{
|
|
10072
|
+
style: {
|
|
10073
|
+
padding: "8px 10px",
|
|
10074
|
+
borderRadius: "4px",
|
|
10075
|
+
marginBottom: "6px",
|
|
10076
|
+
background: "rgba(0,0,0,0.02)",
|
|
10077
|
+
border: "1px solid #eee",
|
|
10078
|
+
cursor: change.from > 0 ? "pointer" : "default"
|
|
10079
|
+
},
|
|
10080
|
+
onClick: () => {
|
|
10081
|
+
if (change.from > 0) onNavigate(change.from);
|
|
10082
|
+
}
|
|
10083
|
+
},
|
|
10084
|
+
children
|
|
10085
|
+
);
|
|
10086
|
+
}
|
|
10087
|
+
return () => h(
|
|
10088
|
+
"div",
|
|
10089
|
+
{
|
|
10090
|
+
style: {
|
|
10091
|
+
width: "100%",
|
|
10092
|
+
height: "100%",
|
|
10093
|
+
display: "flex",
|
|
10094
|
+
flexDirection: "column",
|
|
10095
|
+
backgroundColor: "var(--crepe-color-surface, #fff)",
|
|
10096
|
+
boxSizing: "border-box",
|
|
10097
|
+
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
|
|
10098
|
+
fontSize: "13px",
|
|
10099
|
+
color: "var(--crepe-color-on-surface, #333)",
|
|
10100
|
+
overflow: "hidden"
|
|
10101
|
+
}
|
|
10102
|
+
},
|
|
10103
|
+
[
|
|
10104
|
+
// Header
|
|
10105
|
+
h(
|
|
10106
|
+
"div",
|
|
10107
|
+
{
|
|
10108
|
+
style: {
|
|
10109
|
+
padding: "12px 16px",
|
|
10110
|
+
fontSize: "14px",
|
|
10111
|
+
fontWeight: "bold",
|
|
10112
|
+
borderBottom: "1px solid var(--crepe-color-outline-variant, color-mix(in srgb, var(--crepe-color-outline, #ddd), transparent 80%))",
|
|
10113
|
+
color: "var(--crepe-color-on-surface, #333)",
|
|
10114
|
+
display: "flex",
|
|
10115
|
+
justifyContent: "space-between",
|
|
10116
|
+
alignItems: "center",
|
|
10117
|
+
flexShrink: 0
|
|
10118
|
+
}
|
|
10119
|
+
},
|
|
10120
|
+
[
|
|
10121
|
+
h("span", null, "\u6587\u6863\u5DEE\u5F02\u53D8\u66F4"),
|
|
10122
|
+
onClose ? h(
|
|
10123
|
+
"div",
|
|
10124
|
+
{
|
|
10125
|
+
style: {
|
|
10126
|
+
cursor: "pointer",
|
|
10127
|
+
display: "flex",
|
|
10128
|
+
alignItems: "center",
|
|
10129
|
+
justifyContent: "center",
|
|
10130
|
+
width: "24px",
|
|
10131
|
+
height: "24px",
|
|
10132
|
+
borderRadius: "4px",
|
|
10133
|
+
color: "var(--crepe-color-outline, #999)",
|
|
10134
|
+
transition: "background-color 0.2s, color 0.2s"
|
|
10135
|
+
},
|
|
10136
|
+
onClick: onClose,
|
|
10137
|
+
onMouseenter: (e) => {
|
|
10138
|
+
const target = e.currentTarget;
|
|
10139
|
+
target.style.backgroundColor = "var(--crepe-color-hover, rgba(0,0,0,0.05))";
|
|
10140
|
+
target.style.color = "var(--crepe-color-on-surface, #333)";
|
|
10141
|
+
},
|
|
10142
|
+
onMouseleave: (e) => {
|
|
10143
|
+
const target = e.currentTarget;
|
|
10144
|
+
target.style.backgroundColor = "transparent";
|
|
10145
|
+
target.style.color = "var(--crepe-color-outline, #999)";
|
|
10146
|
+
},
|
|
10147
|
+
title: "\u5173\u95ED\u5DEE\u5F02"
|
|
10148
|
+
},
|
|
10149
|
+
[
|
|
10150
|
+
h(
|
|
10151
|
+
"svg",
|
|
10152
|
+
{
|
|
10153
|
+
width: "16",
|
|
10154
|
+
height: "16",
|
|
10155
|
+
viewBox: "0 0 24 24",
|
|
10156
|
+
fill: "none",
|
|
10157
|
+
stroke: "currentColor",
|
|
10158
|
+
strokeWidth: "2",
|
|
10159
|
+
strokeLinecap: "round",
|
|
10160
|
+
strokeLinejoin: "round"
|
|
10161
|
+
},
|
|
10162
|
+
[
|
|
10163
|
+
h("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
|
|
10164
|
+
h("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
|
|
10165
|
+
]
|
|
10166
|
+
)
|
|
10167
|
+
]
|
|
10168
|
+
) : null
|
|
10169
|
+
]
|
|
10170
|
+
),
|
|
10171
|
+
// Tabs
|
|
10172
|
+
h(
|
|
10173
|
+
"div",
|
|
10174
|
+
{
|
|
10175
|
+
style: {
|
|
10176
|
+
display: "flex",
|
|
10177
|
+
borderBottom: "1px solid #eee",
|
|
10178
|
+
padding: "0 8px",
|
|
10179
|
+
flexShrink: 0
|
|
10180
|
+
}
|
|
10181
|
+
},
|
|
10182
|
+
[
|
|
10183
|
+
renderTab("all", `\u5168\u90E8(${counts.value.all})`),
|
|
10184
|
+
renderTab("removed", `\u5220\u9664(${counts.value.removed})`),
|
|
10185
|
+
renderTab("added", `\u65B0\u589E(${counts.value.added})`)
|
|
10186
|
+
]
|
|
10187
|
+
),
|
|
10188
|
+
// List
|
|
10189
|
+
h(
|
|
10190
|
+
"div",
|
|
10191
|
+
{
|
|
10192
|
+
style: {
|
|
10193
|
+
flex: 1,
|
|
10194
|
+
overflowY: "auto",
|
|
10195
|
+
padding: "8px"
|
|
10196
|
+
}
|
|
10197
|
+
},
|
|
10198
|
+
filteredChanges.value.map(
|
|
10199
|
+
(change, i) => renderItem(change, i + 1)
|
|
10200
|
+
)
|
|
10201
|
+
)
|
|
10202
|
+
]
|
|
10203
|
+
);
|
|
10204
|
+
}
|
|
10205
|
+
});
|
|
10206
|
+
app.mount(container);
|
|
10207
|
+
return app;
|
|
10208
|
+
}
|
|
10209
|
+
|
|
10210
|
+
const inlineDiffConfig = $ctx(
|
|
10211
|
+
{
|
|
10212
|
+
addedClass: "crepe-diff-added",
|
|
10213
|
+
deletedClass: "crepe-diff-deleted"
|
|
10214
|
+
},
|
|
10215
|
+
"inlineDiffConfigCtx"
|
|
10216
|
+
);
|
|
10217
|
+
const noopApi = {
|
|
10218
|
+
showDiff: () => {
|
|
10219
|
+
},
|
|
10220
|
+
hideDiff: () => {
|
|
10221
|
+
},
|
|
10222
|
+
isShowing: () => false
|
|
10223
|
+
};
|
|
10224
|
+
const inlineDiffApiCtx = $ctx(noopApi, "inlineDiffApiCtx");
|
|
10225
|
+
|
|
10226
|
+
function lcs(a, b, eq) {
|
|
10227
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
10228
|
+
const m = a.length;
|
|
10229
|
+
const n = b.length;
|
|
10230
|
+
const dp = Array.from(
|
|
10231
|
+
{ length: m + 1 },
|
|
10232
|
+
() => Array.from({ length: n + 1 }, () => 0)
|
|
10233
|
+
);
|
|
10234
|
+
for (let i2 = m - 1; i2 >= 0; i2--) {
|
|
10235
|
+
for (let j2 = n - 1; j2 >= 0; j2--) {
|
|
10236
|
+
const diag = (_b = (_a = dp[i2 + 1]) == null ? void 0 : _a[j2 + 1]) != null ? _b : 0;
|
|
10237
|
+
const down = (_d = (_c = dp[i2 + 1]) == null ? void 0 : _c[j2]) != null ? _d : 0;
|
|
10238
|
+
const right = (_f = (_e = dp[i2]) == null ? void 0 : _e[j2 + 1]) != null ? _f : 0;
|
|
10239
|
+
dp[i2][j2] = eq(a[i2], b[j2]) ? 1 + diag : Math.max(down, right);
|
|
10240
|
+
}
|
|
10241
|
+
}
|
|
10242
|
+
const pairs = [];
|
|
10243
|
+
let i = 0;
|
|
10244
|
+
let j = 0;
|
|
10245
|
+
while (i < m && j < n) {
|
|
10246
|
+
const down = (_h = (_g = dp[i + 1]) == null ? void 0 : _g[j]) != null ? _h : 0;
|
|
10247
|
+
const right = (_j = (_i = dp[i]) == null ? void 0 : _i[j + 1]) != null ? _j : 0;
|
|
10248
|
+
if (eq(a[i], b[j])) {
|
|
10249
|
+
pairs.push([i, j]);
|
|
10250
|
+
i++;
|
|
10251
|
+
j++;
|
|
10252
|
+
} else if (down >= right) {
|
|
10253
|
+
i++;
|
|
10254
|
+
} else {
|
|
10255
|
+
j++;
|
|
10256
|
+
}
|
|
10257
|
+
}
|
|
10258
|
+
return pairs;
|
|
10259
|
+
}
|
|
10260
|
+
function computeDiff(oldBlocks, newBlocks) {
|
|
10261
|
+
const result = [];
|
|
10262
|
+
let chunkCounter = 0;
|
|
10263
|
+
const pushChunk = (diffs) => {
|
|
10264
|
+
if (diffs.length > 0) {
|
|
10265
|
+
result.push({
|
|
10266
|
+
id: `chunk-${chunkCounter++}`,
|
|
10267
|
+
diffs,
|
|
10268
|
+
status: "pending"
|
|
10269
|
+
});
|
|
10270
|
+
}
|
|
10271
|
+
};
|
|
10272
|
+
const pairs = lcs(
|
|
10273
|
+
oldBlocks,
|
|
10274
|
+
newBlocks,
|
|
10275
|
+
(a, b) => a.textContent === b.textContent
|
|
10276
|
+
);
|
|
10277
|
+
let oi = 0;
|
|
10278
|
+
let ni = 0;
|
|
10279
|
+
for (const [pi, pj] of pairs) {
|
|
10280
|
+
const gapOld = pi - oi;
|
|
10281
|
+
const gapNew = pj - ni;
|
|
10282
|
+
const gapMax = Math.max(gapOld, gapNew);
|
|
10283
|
+
for (let k = 0; k < gapMax; k++) {
|
|
10284
|
+
const hasOld = oi + k < pi;
|
|
10285
|
+
const hasNew = ni + k < pj;
|
|
10286
|
+
const currentDiffs = [];
|
|
10287
|
+
if (hasOld && hasNew) {
|
|
10288
|
+
const oldNode2 = oldBlocks[oi + k];
|
|
10289
|
+
const newNode2 = newBlocks[ni + k];
|
|
10290
|
+
const changes = Diff.diffWordsWithSpace(
|
|
10291
|
+
oldNode2.textContent,
|
|
10292
|
+
newNode2.textContent
|
|
10293
|
+
);
|
|
10294
|
+
const parts = changes.map((c) => ({
|
|
10295
|
+
type: c.added ? "insert" : c.removed ? "delete" : "equal",
|
|
10296
|
+
value: c.value
|
|
10297
|
+
}));
|
|
10298
|
+
currentDiffs.push({ type: "removed", oldNode: oldNode2, parts });
|
|
10299
|
+
currentDiffs.push({ type: "added", newNode: newNode2, parts });
|
|
10300
|
+
} else if (hasOld) {
|
|
10301
|
+
currentDiffs.push({ type: "removed", oldNode: oldBlocks[oi + k] });
|
|
10302
|
+
} else {
|
|
10303
|
+
currentDiffs.push({ type: "added", newNode: newBlocks[ni + k] });
|
|
10304
|
+
}
|
|
10305
|
+
pushChunk(currentDiffs);
|
|
10306
|
+
}
|
|
10307
|
+
const oldNode = oldBlocks[pi];
|
|
10308
|
+
const newNode = newBlocks[pj];
|
|
10309
|
+
if (oldNode.textContent === newNode.textContent && oldNode.eq(newNode)) {
|
|
10310
|
+
pushChunk([{ type: "unchanged", oldNode, newNode }]);
|
|
10311
|
+
} else {
|
|
10312
|
+
const changes = Diff.diffWordsWithSpace(
|
|
10313
|
+
oldNode.textContent,
|
|
10314
|
+
newNode.textContent
|
|
10315
|
+
);
|
|
10316
|
+
const parts = changes.map((c) => ({
|
|
10317
|
+
type: c.added ? "insert" : c.removed ? "delete" : "equal",
|
|
10318
|
+
value: c.value
|
|
10319
|
+
}));
|
|
10320
|
+
pushChunk([
|
|
10321
|
+
{ type: "removed", oldNode, parts },
|
|
10322
|
+
{ type: "added", newNode, parts }
|
|
10323
|
+
]);
|
|
10324
|
+
}
|
|
10325
|
+
oi = pi + 1;
|
|
10326
|
+
ni = pj + 1;
|
|
10327
|
+
}
|
|
10328
|
+
const trailOld = oldBlocks.length - oi;
|
|
10329
|
+
const trailNew = newBlocks.length - ni;
|
|
10330
|
+
const trailMax = Math.max(trailOld, trailNew);
|
|
10331
|
+
for (let k = 0; k < trailMax; k++) {
|
|
10332
|
+
const hasOld = oi + k < oldBlocks.length;
|
|
10333
|
+
const hasNew = ni + k < newBlocks.length;
|
|
10334
|
+
const currentDiffs = [];
|
|
10335
|
+
if (hasOld && hasNew) {
|
|
10336
|
+
const oldNode = oldBlocks[oi + k];
|
|
10337
|
+
const newNode = newBlocks[ni + k];
|
|
10338
|
+
const changes = Diff.diffWordsWithSpace(
|
|
10339
|
+
oldNode.textContent,
|
|
10340
|
+
newNode.textContent
|
|
10341
|
+
);
|
|
10342
|
+
const parts = changes.map((c) => ({
|
|
10343
|
+
type: c.added ? "insert" : c.removed ? "delete" : "equal",
|
|
10344
|
+
value: c.value
|
|
10345
|
+
}));
|
|
10346
|
+
currentDiffs.push({ type: "removed", oldNode, parts });
|
|
10347
|
+
currentDiffs.push({ type: "added", newNode, parts });
|
|
10348
|
+
} else if (hasOld) {
|
|
10349
|
+
currentDiffs.push({ type: "removed", oldNode: oldBlocks[oi + k] });
|
|
10350
|
+
} else {
|
|
10351
|
+
currentDiffs.push({ type: "added", newNode: newBlocks[ni + k] });
|
|
10352
|
+
}
|
|
10353
|
+
pushChunk(currentDiffs);
|
|
10354
|
+
}
|
|
10355
|
+
return result;
|
|
10356
|
+
}
|
|
10357
|
+
|
|
10358
|
+
function buildNewDoc(chunks, schema) {
|
|
10359
|
+
var _a, _b, _c, _d;
|
|
10360
|
+
const children = [];
|
|
10361
|
+
const pending = [];
|
|
10362
|
+
for (const chunk of chunks) {
|
|
10363
|
+
if (chunk.status === "accepted") {
|
|
10364
|
+
for (const diff of chunk.diffs) {
|
|
10365
|
+
if (diff.type === "added") children.push(diff.newNode);
|
|
10366
|
+
if (diff.type === "unchanged") children.push(diff.newNode);
|
|
10367
|
+
}
|
|
10368
|
+
} else if (chunk.status === "rejected") {
|
|
10369
|
+
for (const diff of chunk.diffs) {
|
|
10370
|
+
if (diff.type === "removed") children.push(diff.oldNode);
|
|
10371
|
+
if (diff.type === "unchanged") children.push(diff.oldNode);
|
|
10372
|
+
}
|
|
10373
|
+
} else {
|
|
10374
|
+
for (const diff of chunk.diffs) {
|
|
10375
|
+
if (diff.type === "unchanged") {
|
|
10376
|
+
children.push(diff.newNode);
|
|
10377
|
+
} else if (diff.type === "added") {
|
|
10378
|
+
pending.push({
|
|
10379
|
+
type: "added",
|
|
10380
|
+
childIndex: children.length,
|
|
10381
|
+
oldText: "",
|
|
10382
|
+
newText: (_b = (_a = diff.newNode) == null ? void 0 : _a.textContent) != null ? _b : "",
|
|
10383
|
+
parts: diff.parts,
|
|
10384
|
+
chunkId: chunk.id
|
|
10385
|
+
});
|
|
10386
|
+
children.push(diff.newNode);
|
|
10387
|
+
} else if (diff.type === "removed") {
|
|
10388
|
+
pending.push({
|
|
10389
|
+
type: "removed",
|
|
10390
|
+
childIndex: children.length,
|
|
10391
|
+
oldText: (_d = (_c = diff.oldNode) == null ? void 0 : _c.textContent) != null ? _d : "",
|
|
10392
|
+
newText: "",
|
|
10393
|
+
parts: diff.parts,
|
|
10394
|
+
chunkId: chunk.id
|
|
10395
|
+
});
|
|
10396
|
+
children.push(diff.oldNode);
|
|
10397
|
+
}
|
|
10398
|
+
}
|
|
10399
|
+
}
|
|
10400
|
+
}
|
|
10401
|
+
if (children.length === 0) {
|
|
10402
|
+
children.push(schema.node("paragraph", null, []));
|
|
10403
|
+
}
|
|
10404
|
+
const doc = schema.node("doc", null, children);
|
|
10405
|
+
let pos = 0;
|
|
10406
|
+
const positions = [];
|
|
10407
|
+
for (const child of children) {
|
|
10408
|
+
positions.push({ from: pos, to: pos + child.nodeSize });
|
|
10409
|
+
pos += child.nodeSize;
|
|
10410
|
+
}
|
|
10411
|
+
const changes = pending.map((pc) => {
|
|
10412
|
+
var _a2, _b2;
|
|
10413
|
+
const cp = positions[pc.childIndex];
|
|
10414
|
+
const inlineRanges = [];
|
|
10415
|
+
let offset = cp.from + 1;
|
|
10416
|
+
if (pc.type === "removed") {
|
|
10417
|
+
for (const part of (_a2 = pc.parts) != null ? _a2 : []) {
|
|
10418
|
+
if (part.type === "delete") {
|
|
10419
|
+
inlineRanges.push({ from: offset, to: offset + part.value.length });
|
|
10420
|
+
offset += part.value.length;
|
|
10421
|
+
} else if (part.type === "equal") {
|
|
10422
|
+
offset += part.value.length;
|
|
10423
|
+
}
|
|
10424
|
+
}
|
|
10425
|
+
return {
|
|
10426
|
+
type: "removed",
|
|
10427
|
+
from: cp.from,
|
|
10428
|
+
oldText: pc.oldText,
|
|
10429
|
+
newText: "",
|
|
10430
|
+
blockRange: { from: cp.from, to: cp.to },
|
|
10431
|
+
inlineRanges,
|
|
10432
|
+
chunkId: pc.chunkId
|
|
10433
|
+
};
|
|
10434
|
+
}
|
|
10435
|
+
for (const part of (_b2 = pc.parts) != null ? _b2 : []) {
|
|
10436
|
+
if (part.type === "insert") {
|
|
10437
|
+
inlineRanges.push({ from: offset, to: offset + part.value.length });
|
|
10438
|
+
offset += part.value.length;
|
|
10439
|
+
} else if (part.type === "equal") {
|
|
10440
|
+
offset += part.value.length;
|
|
10441
|
+
}
|
|
10442
|
+
}
|
|
10443
|
+
return {
|
|
10444
|
+
type: "added",
|
|
10445
|
+
from: cp.from,
|
|
10446
|
+
oldText: "",
|
|
10447
|
+
newText: pc.newText,
|
|
10448
|
+
blockRange: { from: cp.from, to: cp.to },
|
|
10449
|
+
inlineRanges,
|
|
10450
|
+
chunkId: pc.chunkId
|
|
10451
|
+
};
|
|
10452
|
+
});
|
|
10453
|
+
return { doc, changes };
|
|
10454
|
+
}
|
|
10455
|
+
|
|
10456
|
+
var __typeError$3 = (msg) => {
|
|
10457
|
+
throw TypeError(msg);
|
|
10458
|
+
};
|
|
10459
|
+
var __accessCheck$3 = (obj, member, msg) => member.has(obj) || __typeError$3("Cannot " + msg);
|
|
10460
|
+
var __privateGet$3 = (obj, member, getter) => (__accessCheck$3(obj, member, "read from private field"), member.get(obj));
|
|
10461
|
+
var __privateAdd$3 = (obj, member, value) => member.has(obj) ? __typeError$3("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
10462
|
+
var __privateSet$3 = (obj, member, value, setter) => (__accessCheck$3(obj, member, "write to private field"), member.set(obj, value), value);
|
|
10463
|
+
var __privateMethod = (obj, member, method) => (__accessCheck$3(obj, member, "access private method"), method);
|
|
10464
|
+
var _ctx, _view, _isActive, _panelApp, _panelContainer, _resizeObserver, _scrollContainers, _updateGeometry, _originalEditable, _chunks, _schema, _render, _InlineDiffView_instances, scrollTo_fn, createPanel_fn, removePanel_fn;
|
|
10465
|
+
const inlineDiffKey = new PluginKey("CREPE_INLINE_DIFF");
|
|
10466
|
+
const PANEL_WIDTH = 280;
|
|
10467
|
+
let sharedDecorationSet = DecorationSet.empty;
|
|
10468
|
+
class InlineDiffView {
|
|
10469
|
+
constructor(ctx, view) {
|
|
10470
|
+
__privateAdd$3(this, _InlineDiffView_instances);
|
|
10471
|
+
__privateAdd$3(this, _ctx);
|
|
10472
|
+
__privateAdd$3(this, _view);
|
|
10473
|
+
__privateAdd$3(this, _isActive, false);
|
|
10474
|
+
__privateAdd$3(this, _panelApp, null);
|
|
10475
|
+
__privateAdd$3(this, _panelContainer, null);
|
|
10476
|
+
__privateAdd$3(this, _resizeObserver, null);
|
|
10477
|
+
__privateAdd$3(this, _scrollContainers, []);
|
|
10478
|
+
__privateAdd$3(this, _updateGeometry, null);
|
|
10479
|
+
__privateAdd$3(this, _originalEditable, null);
|
|
10480
|
+
__privateAdd$3(this, _chunks, []);
|
|
10481
|
+
__privateAdd$3(this, _schema, null);
|
|
10482
|
+
this.showDiff = (oldMarkdown, newMarkdown) => {
|
|
10483
|
+
if (__privateGet$3(this, _isActive)) return;
|
|
10484
|
+
const parser = __privateGet$3(this, _ctx).get(parserCtx);
|
|
10485
|
+
__privateSet$3(this, _schema, __privateGet$3(this, _view).state.schema);
|
|
10486
|
+
let oldDoc;
|
|
10487
|
+
let newDoc;
|
|
10488
|
+
try {
|
|
10489
|
+
oldDoc = parser(oldMarkdown);
|
|
10490
|
+
if (typeof newMarkdown === "string" && newMarkdown.trim() !== "") {
|
|
10491
|
+
newDoc = parser(newMarkdown);
|
|
10492
|
+
} else {
|
|
10493
|
+
newDoc = __privateGet$3(this, _view).state.doc;
|
|
10494
|
+
}
|
|
10495
|
+
} catch (e) {
|
|
10496
|
+
return;
|
|
10497
|
+
}
|
|
10498
|
+
const oldBlocks = [];
|
|
10499
|
+
const newBlocks = [];
|
|
10500
|
+
oldDoc.forEach((node) => oldBlocks.push(node));
|
|
10501
|
+
newDoc.forEach((node) => newBlocks.push(node));
|
|
10502
|
+
__privateSet$3(this, _chunks, computeDiff(oldBlocks, newBlocks));
|
|
10503
|
+
const { changes } = buildNewDoc(__privateGet$3(this, _chunks), __privateGet$3(this, _schema));
|
|
10504
|
+
if (changes.length === 0) {
|
|
10505
|
+
return;
|
|
10506
|
+
}
|
|
10507
|
+
if (!__privateGet$3(this, _originalEditable)) {
|
|
10508
|
+
__privateSet$3(this, _originalEditable, __privateGet$3(this, _view).someProp("editable") || (() => true));
|
|
10509
|
+
}
|
|
10510
|
+
__privateGet$3(this, _view).setProps({
|
|
10511
|
+
editable: () => false
|
|
10512
|
+
});
|
|
10513
|
+
__privateSet$3(this, _isActive, true);
|
|
10514
|
+
__privateGet$3(this, _render).call(this, true);
|
|
10515
|
+
};
|
|
10516
|
+
__privateAdd$3(this, _render, (initPanel = false) => {
|
|
10517
|
+
const { doc: newDocWithPos, changes } = buildNewDoc(
|
|
10518
|
+
__privateGet$3(this, _chunks),
|
|
10519
|
+
__privateGet$3(this, _schema)
|
|
10520
|
+
);
|
|
10521
|
+
const acceptText = i18n(__privateGet$3(this, _ctx), "inlineDiff.accept");
|
|
10522
|
+
const rejectText = i18n(__privateGet$3(this, _ctx), "inlineDiff.reject");
|
|
10523
|
+
const ds = buildDecorations(
|
|
10524
|
+
newDocWithPos,
|
|
10525
|
+
changes,
|
|
10526
|
+
(id) => this.acceptChunk(id),
|
|
10527
|
+
(id) => this.rejectChunk(id),
|
|
10528
|
+
acceptText,
|
|
10529
|
+
rejectText
|
|
10530
|
+
);
|
|
10531
|
+
sharedDecorationSet = ds;
|
|
10532
|
+
const tr = __privateGet$3(this, _view).state.tr.replaceWith(
|
|
10533
|
+
0,
|
|
10534
|
+
__privateGet$3(this, _view).state.doc.content.size,
|
|
10535
|
+
newDocWithPos.content
|
|
10536
|
+
);
|
|
10537
|
+
__privateGet$3(this, _view).dispatch(tr);
|
|
10538
|
+
if (initPanel) {
|
|
10539
|
+
__privateMethod(this, _InlineDiffView_instances, createPanel_fn).call(this, changes);
|
|
10540
|
+
} else if (__privateGet$3(this, _panelApp)) {
|
|
10541
|
+
__privateMethod(this, _InlineDiffView_instances, createPanel_fn).call(this, changes);
|
|
10542
|
+
}
|
|
10543
|
+
});
|
|
10544
|
+
this.acceptChunk = (id) => {
|
|
10545
|
+
const chunk = __privateGet$3(this, _chunks).find((c) => c.id === id);
|
|
10546
|
+
if (chunk) {
|
|
10547
|
+
chunk.status = "accepted";
|
|
10548
|
+
const hasPending = __privateGet$3(this, _chunks).some(
|
|
10549
|
+
(c) => c.status === "pending" && c.diffs.some((d) => d.type !== "unchanged")
|
|
10550
|
+
);
|
|
10551
|
+
if (!hasPending) {
|
|
10552
|
+
this.hideDiff();
|
|
10553
|
+
} else {
|
|
10554
|
+
__privateGet$3(this, _render).call(this);
|
|
10555
|
+
}
|
|
10556
|
+
}
|
|
10557
|
+
};
|
|
10558
|
+
this.rejectChunk = (id) => {
|
|
10559
|
+
const chunk = __privateGet$3(this, _chunks).find((c) => c.id === id);
|
|
10560
|
+
if (chunk) {
|
|
10561
|
+
chunk.status = "rejected";
|
|
10562
|
+
const hasPending = __privateGet$3(this, _chunks).some(
|
|
10563
|
+
(c) => c.status === "pending" && c.diffs.some((d) => d.type !== "unchanged")
|
|
10564
|
+
);
|
|
10565
|
+
if (!hasPending) {
|
|
10566
|
+
this.hideDiff();
|
|
10567
|
+
} else {
|
|
10568
|
+
__privateGet$3(this, _render).call(this);
|
|
10569
|
+
}
|
|
10570
|
+
}
|
|
10571
|
+
};
|
|
10572
|
+
this.hideDiff = () => {
|
|
10573
|
+
if (!__privateGet$3(this, _isActive)) return;
|
|
10574
|
+
__privateMethod(this, _InlineDiffView_instances, removePanel_fn).call(this);
|
|
10575
|
+
for (const chunk of __privateGet$3(this, _chunks)) {
|
|
10576
|
+
if (chunk.status === "pending") {
|
|
10577
|
+
chunk.status = "accepted";
|
|
10578
|
+
}
|
|
10579
|
+
}
|
|
10580
|
+
const { doc: finalDoc } = buildNewDoc(__privateGet$3(this, _chunks), __privateGet$3(this, _schema));
|
|
10581
|
+
const tr = __privateGet$3(this, _view).state.tr.replaceWith(
|
|
10582
|
+
0,
|
|
10583
|
+
__privateGet$3(this, _view).state.doc.content.size,
|
|
10584
|
+
finalDoc.content
|
|
10585
|
+
);
|
|
10586
|
+
sharedDecorationSet = DecorationSet.empty;
|
|
10587
|
+
__privateSet$3(this, _isActive, false);
|
|
10588
|
+
__privateSet$3(this, _chunks, []);
|
|
10589
|
+
__privateGet$3(this, _view).dispatch(tr);
|
|
10590
|
+
if (__privateGet$3(this, _originalEditable)) {
|
|
10591
|
+
__privateGet$3(this, _view).setProps({
|
|
10592
|
+
editable: __privateGet$3(this, _originalEditable)
|
|
10593
|
+
});
|
|
10594
|
+
__privateSet$3(this, _originalEditable, null);
|
|
10595
|
+
} else {
|
|
10596
|
+
__privateGet$3(this, _view).setProps({
|
|
10597
|
+
editable: () => true
|
|
10598
|
+
});
|
|
10599
|
+
}
|
|
10600
|
+
};
|
|
10601
|
+
this.update = (view) => {
|
|
10602
|
+
__privateSet$3(this, _view, view);
|
|
10603
|
+
};
|
|
10604
|
+
this.destroy = () => {
|
|
10605
|
+
__privateMethod(this, _InlineDiffView_instances, removePanel_fn).call(this);
|
|
10606
|
+
};
|
|
10607
|
+
__privateSet$3(this, _ctx, ctx);
|
|
10608
|
+
__privateSet$3(this, _view, view);
|
|
10609
|
+
const api = {
|
|
10610
|
+
showDiff: (oldMd, newMd) => this.showDiff(oldMd, newMd),
|
|
10611
|
+
hideDiff: () => this.hideDiff(),
|
|
10612
|
+
isShowing: () => __privateGet$3(this, _isActive)
|
|
10613
|
+
};
|
|
10614
|
+
ctx.set(inlineDiffApiCtx.key, api);
|
|
10615
|
+
}
|
|
10616
|
+
}
|
|
10617
|
+
_ctx = new WeakMap();
|
|
10618
|
+
_view = new WeakMap();
|
|
10619
|
+
_isActive = new WeakMap();
|
|
10620
|
+
_panelApp = new WeakMap();
|
|
10621
|
+
_panelContainer = new WeakMap();
|
|
10622
|
+
_resizeObserver = new WeakMap();
|
|
10623
|
+
_scrollContainers = new WeakMap();
|
|
10624
|
+
_updateGeometry = new WeakMap();
|
|
10625
|
+
_originalEditable = new WeakMap();
|
|
10626
|
+
_chunks = new WeakMap();
|
|
10627
|
+
_schema = new WeakMap();
|
|
10628
|
+
_render = new WeakMap();
|
|
10629
|
+
_InlineDiffView_instances = new WeakSet();
|
|
10630
|
+
scrollTo_fn = function(pos) {
|
|
10631
|
+
try {
|
|
10632
|
+
const view = __privateGet$3(this, _view);
|
|
10633
|
+
const coords = view.coordsAtPos(pos);
|
|
10634
|
+
let scrollTarget = view.dom;
|
|
10635
|
+
while (scrollTarget) {
|
|
10636
|
+
const { overflowY } = getComputedStyle(scrollTarget);
|
|
10637
|
+
if ((overflowY === "auto" || overflowY === "scroll") && scrollTarget.scrollHeight > scrollTarget.clientHeight) {
|
|
10638
|
+
break;
|
|
10639
|
+
}
|
|
10640
|
+
scrollTarget = scrollTarget.parentElement;
|
|
10641
|
+
}
|
|
10642
|
+
if (scrollTarget) {
|
|
10643
|
+
const targetRect = scrollTarget.getBoundingClientRect();
|
|
10644
|
+
const scrollOffset = coords.top - targetRect.top + scrollTarget.scrollTop - 60;
|
|
10645
|
+
scrollTarget.scrollTo({ top: scrollOffset, behavior: "smooth" });
|
|
10646
|
+
} else {
|
|
10647
|
+
window.scrollTo({
|
|
10648
|
+
top: coords.top + window.scrollY - 100,
|
|
10649
|
+
behavior: "smooth"
|
|
10650
|
+
});
|
|
10651
|
+
}
|
|
10652
|
+
} catch (e) {
|
|
10653
|
+
}
|
|
10654
|
+
};
|
|
10655
|
+
createPanel_fn = function(changes) {
|
|
10656
|
+
__privateMethod(this, _InlineDiffView_instances, removePanel_fn).call(this);
|
|
10657
|
+
const editorContainer = __privateGet$3(this, _view).dom.parentElement;
|
|
10658
|
+
if (!editorContainer) return;
|
|
10659
|
+
const root = editorContainer.parentElement;
|
|
10660
|
+
if (!root) return;
|
|
10661
|
+
const container = document.createElement("div");
|
|
10662
|
+
container.style.position = "fixed";
|
|
10663
|
+
container.style.zIndex = "100";
|
|
10664
|
+
container.style.width = `${PANEL_WIDTH}px`;
|
|
10665
|
+
container.style.overflow = "hidden";
|
|
10666
|
+
container.style.borderLeft = "1px solid var(--crepe-color-outline-variant, color-mix(in srgb, var(--crepe-color-outline, #ddd), transparent 80%))";
|
|
10667
|
+
container.style.backgroundColor = "var(--crepe-color-surface, #fff)";
|
|
10668
|
+
root.appendChild(container);
|
|
10669
|
+
__privateSet$3(this, _panelContainer, container);
|
|
10670
|
+
editorContainer.style.paddingRight = `${PANEL_WIDTH}px`;
|
|
10671
|
+
__privateSet$3(this, _panelApp, mountChangePanel(
|
|
10672
|
+
container,
|
|
10673
|
+
changes,
|
|
10674
|
+
(from) => __privateMethod(this, _InlineDiffView_instances, scrollTo_fn).call(this, from),
|
|
10675
|
+
() => this.hideDiff()
|
|
10676
|
+
));
|
|
10677
|
+
__privateSet$3(this, _updateGeometry, () => {
|
|
10678
|
+
const rootRect = root.getBoundingClientRect();
|
|
10679
|
+
let top = rootRect.top;
|
|
10680
|
+
const toolbar = root.querySelector(
|
|
10681
|
+
".milkdown-fixed-toolbar"
|
|
10682
|
+
);
|
|
10683
|
+
if (toolbar && toolbar.offsetHeight > 0) {
|
|
10684
|
+
const toolbarRect = toolbar.getBoundingClientRect();
|
|
10685
|
+
top = Math.max(top, toolbarRect.bottom);
|
|
10686
|
+
}
|
|
10687
|
+
const coverEl = root.querySelector(
|
|
10688
|
+
".milkdown-document-cover"
|
|
10689
|
+
);
|
|
10690
|
+
if (coverEl && coverEl.offsetHeight > 0) {
|
|
10691
|
+
top = Math.max(top, coverEl.getBoundingClientRect().bottom);
|
|
10692
|
+
}
|
|
10693
|
+
let height = window.innerHeight - top;
|
|
10694
|
+
if (top + height > rootRect.bottom) {
|
|
10695
|
+
height = Math.max(0, rootRect.bottom - top);
|
|
10696
|
+
}
|
|
10697
|
+
container.style.top = `${top}px`;
|
|
10698
|
+
container.style.height = `${height}px`;
|
|
10699
|
+
container.style.left = "auto";
|
|
10700
|
+
let baseOffset = window.innerWidth - rootRect.right;
|
|
10701
|
+
let rightOffset = baseOffset;
|
|
10702
|
+
let hasVScroll = false;
|
|
10703
|
+
if (document.documentElement.scrollHeight > window.innerHeight) {
|
|
10704
|
+
hasVScroll = true;
|
|
10705
|
+
}
|
|
10706
|
+
let parent = root;
|
|
10707
|
+
while (parent && parent !== document.body) {
|
|
10708
|
+
const { overflowY } = getComputedStyle(parent);
|
|
10709
|
+
if (overflowY === "auto" || overflowY === "scroll") {
|
|
10710
|
+
if (parent.scrollHeight > parent.clientHeight) {
|
|
10711
|
+
hasVScroll = true;
|
|
10712
|
+
break;
|
|
10713
|
+
}
|
|
10714
|
+
}
|
|
10715
|
+
parent = parent.parentElement;
|
|
10716
|
+
}
|
|
10717
|
+
if (hasVScroll) {
|
|
10718
|
+
rightOffset = Math.max(rightOffset, 32);
|
|
10719
|
+
} else {
|
|
10720
|
+
rightOffset = Math.max(rightOffset, 0);
|
|
10721
|
+
}
|
|
10722
|
+
container.style.right = `${rightOffset}px`;
|
|
10723
|
+
editorContainer.style.paddingRight = `${PANEL_WIDTH}px`;
|
|
10724
|
+
});
|
|
10725
|
+
__privateGet$3(this, _updateGeometry).call(this);
|
|
10726
|
+
setTimeout(() => {
|
|
10727
|
+
var _a;
|
|
10728
|
+
(_a = __privateGet$3(this, _updateGeometry)) == null ? void 0 : _a.call(this);
|
|
10729
|
+
}, 100);
|
|
10730
|
+
__privateSet$3(this, _resizeObserver, new ResizeObserver(__privateGet$3(this, _updateGeometry)));
|
|
10731
|
+
__privateGet$3(this, _resizeObserver).observe(root);
|
|
10732
|
+
window.addEventListener("resize", __privateGet$3(this, _updateGeometry));
|
|
10733
|
+
window.addEventListener("scroll", __privateGet$3(this, _updateGeometry), {
|
|
10734
|
+
capture: true,
|
|
10735
|
+
passive: true
|
|
10736
|
+
});
|
|
10737
|
+
let scrollerNode = root;
|
|
10738
|
+
while (scrollerNode && scrollerNode !== document) {
|
|
10739
|
+
if (scrollerNode instanceof Element) {
|
|
10740
|
+
scrollerNode.addEventListener("scroll", __privateGet$3(this, _updateGeometry), {
|
|
10741
|
+
passive: true
|
|
10742
|
+
});
|
|
10743
|
+
__privateGet$3(this, _scrollContainers).push(scrollerNode);
|
|
10744
|
+
}
|
|
10745
|
+
scrollerNode = scrollerNode.parentNode || scrollerNode.host;
|
|
10746
|
+
}
|
|
10747
|
+
};
|
|
10748
|
+
removePanel_fn = function() {
|
|
10749
|
+
if (__privateGet$3(this, _panelApp)) {
|
|
10750
|
+
__privateGet$3(this, _panelApp).unmount();
|
|
10751
|
+
__privateSet$3(this, _panelApp, null);
|
|
10752
|
+
}
|
|
10753
|
+
if (__privateGet$3(this, _panelContainer)) {
|
|
10754
|
+
__privateGet$3(this, _panelContainer).remove();
|
|
10755
|
+
__privateSet$3(this, _panelContainer, null);
|
|
10756
|
+
}
|
|
10757
|
+
if (__privateGet$3(this, _resizeObserver)) {
|
|
10758
|
+
__privateGet$3(this, _resizeObserver).disconnect();
|
|
10759
|
+
__privateSet$3(this, _resizeObserver, null);
|
|
10760
|
+
}
|
|
10761
|
+
if (__privateGet$3(this, _updateGeometry)) {
|
|
10762
|
+
window.removeEventListener("resize", __privateGet$3(this, _updateGeometry));
|
|
10763
|
+
window.removeEventListener("scroll", __privateGet$3(this, _updateGeometry), {
|
|
10764
|
+
capture: true
|
|
10765
|
+
});
|
|
10766
|
+
for (const container of __privateGet$3(this, _scrollContainers)) {
|
|
10767
|
+
container.removeEventListener("scroll", __privateGet$3(this, _updateGeometry));
|
|
10768
|
+
}
|
|
10769
|
+
__privateSet$3(this, _scrollContainers, []);
|
|
10770
|
+
__privateSet$3(this, _updateGeometry, null);
|
|
10771
|
+
}
|
|
10772
|
+
const editorContainer = __privateGet$3(this, _view).dom.parentElement;
|
|
10773
|
+
if (editorContainer) {
|
|
10774
|
+
editorContainer.style.paddingRight = "";
|
|
10775
|
+
}
|
|
10776
|
+
};
|
|
10777
|
+
function buildDecorations(doc, changes, onAccept, onReject, acceptText, rejectText) {
|
|
10778
|
+
const decorations = [];
|
|
10779
|
+
const addedWidgets = /* @__PURE__ */ new Set();
|
|
10780
|
+
for (const change of changes) {
|
|
10781
|
+
if (!addedWidgets.has(change.chunkId)) {
|
|
10782
|
+
addedWidgets.add(change.chunkId);
|
|
10783
|
+
decorations.push(
|
|
10784
|
+
Decoration.widget(
|
|
10785
|
+
change.blockRange.from,
|
|
10786
|
+
() => {
|
|
10787
|
+
const wrapper = document.createElement("div");
|
|
10788
|
+
wrapper.style.position = "relative";
|
|
10789
|
+
wrapper.style.width = "100%";
|
|
10790
|
+
wrapper.style.height = "0";
|
|
10791
|
+
wrapper.style.overflow = "visible";
|
|
10792
|
+
const container = document.createElement("div");
|
|
10793
|
+
container.className = "crepe-diff-actions";
|
|
10794
|
+
container.style.position = "absolute";
|
|
10795
|
+
container.style.right = "4px";
|
|
10796
|
+
container.style.top = "4px";
|
|
10797
|
+
container.style.zIndex = "10";
|
|
10798
|
+
container.style.display = "flex";
|
|
10799
|
+
container.style.gap = "4px";
|
|
10800
|
+
const btnAccept = document.createElement("button");
|
|
10801
|
+
btnAccept.textContent = acceptText;
|
|
10802
|
+
btnAccept.style.backgroundColor = "#2ea043";
|
|
10803
|
+
btnAccept.style.color = "white";
|
|
10804
|
+
btnAccept.style.border = "none";
|
|
10805
|
+
btnAccept.style.borderRadius = "4px";
|
|
10806
|
+
btnAccept.style.padding = "2px 8px";
|
|
10807
|
+
btnAccept.style.cursor = "pointer";
|
|
10808
|
+
btnAccept.style.fontSize = "12px";
|
|
10809
|
+
btnAccept.addEventListener("mousedown", (e) => {
|
|
10810
|
+
e.preventDefault();
|
|
10811
|
+
onAccept(change.chunkId);
|
|
10812
|
+
});
|
|
10813
|
+
const btnReject = document.createElement("button");
|
|
10814
|
+
btnReject.textContent = rejectText;
|
|
10815
|
+
btnReject.style.backgroundColor = "#f85149";
|
|
10816
|
+
btnReject.style.color = "white";
|
|
10817
|
+
btnReject.style.border = "none";
|
|
10818
|
+
btnReject.style.borderRadius = "4px";
|
|
10819
|
+
btnReject.style.padding = "2px 8px";
|
|
10820
|
+
btnReject.style.cursor = "pointer";
|
|
10821
|
+
btnReject.style.fontSize = "12px";
|
|
10822
|
+
btnReject.addEventListener("mousedown", (e) => {
|
|
10823
|
+
e.preventDefault();
|
|
10824
|
+
onReject(change.chunkId);
|
|
10825
|
+
});
|
|
10826
|
+
container.appendChild(btnAccept);
|
|
10827
|
+
container.appendChild(btnReject);
|
|
10828
|
+
wrapper.appendChild(container);
|
|
10829
|
+
return wrapper;
|
|
10830
|
+
},
|
|
10831
|
+
{ side: -1 }
|
|
10832
|
+
)
|
|
10833
|
+
);
|
|
10834
|
+
}
|
|
10835
|
+
const blockCls = change.type === "added" ? "crepe-diff-added" : "crepe-diff-deleted";
|
|
10836
|
+
decorations.push(
|
|
10837
|
+
Decoration.node(change.blockRange.from, change.blockRange.to, {
|
|
10838
|
+
class: blockCls
|
|
10839
|
+
})
|
|
10840
|
+
);
|
|
10841
|
+
const inlineCls = change.type === "added" ? "crepe-diff-inline-added" : "crepe-diff-inline-deleted";
|
|
10842
|
+
for (const r of change.inlineRanges) {
|
|
10843
|
+
if (r.to > r.from) {
|
|
10844
|
+
decorations.push(Decoration.inline(r.from, r.to, { class: inlineCls }));
|
|
10845
|
+
}
|
|
10846
|
+
}
|
|
10847
|
+
}
|
|
10848
|
+
return DecorationSet.create(doc, decorations);
|
|
10849
|
+
}
|
|
10850
|
+
const inlineDiffPlugin = $prose((ctx) => {
|
|
10851
|
+
return new Plugin({
|
|
10852
|
+
key: inlineDiffKey,
|
|
10853
|
+
view: (view) => new InlineDiffView(ctx, view),
|
|
10854
|
+
props: {
|
|
10855
|
+
decorations: () => sharedDecorationSet
|
|
10856
|
+
}
|
|
10857
|
+
});
|
|
10858
|
+
});
|
|
10859
|
+
const inlineDiff = (editor, config) => {
|
|
10860
|
+
editor.config(crepeFeatureConfig(CrepeFeature.InlineDiff)).config((ctx) => {
|
|
10861
|
+
if (config) {
|
|
10862
|
+
ctx.update(inlineDiffConfig.key, (prev) => ({
|
|
10863
|
+
...prev,
|
|
10864
|
+
...config
|
|
10865
|
+
}));
|
|
10866
|
+
}
|
|
10867
|
+
}).use(inlineDiffApiCtx).use(inlineDiffConfig).use(inlineDiffPlugin);
|
|
10868
|
+
};
|
|
10869
|
+
|
|
9769
10870
|
const blockLatexSchema = codeBlockSchema.extendSchema((prev) => {
|
|
9770
10871
|
return (ctx) => {
|
|
9771
10872
|
const baseSchema = prev(ctx);
|
|
@@ -10242,7 +11343,7 @@ var __accessCheck$1 = (obj, member, msg) => member.has(obj) || __typeError$1("Ca
|
|
|
10242
11343
|
var __privateGet$1 = (obj, member, getter) => (__accessCheck$1(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
10243
11344
|
var __privateAdd$1 = (obj, member, value) => member.has(obj) ? __typeError$1("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
10244
11345
|
var __privateSet$1 = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
|
|
10245
|
-
var _tooltipProvider, _content, _app, _selection, _show, _mousePressed;
|
|
11346
|
+
var _tooltipProvider, _content, _app, _selection, _show, _mousePressed, _removePopupListener, _onDocumentMouseUp;
|
|
10246
11347
|
const toolbarTooltip = tooltipFactory("CREPE_TOOLBAR");
|
|
10247
11348
|
class ToolbarView {
|
|
10248
11349
|
constructor(ctx, view, config) {
|
|
@@ -10252,11 +11353,18 @@ class ToolbarView {
|
|
|
10252
11353
|
__privateAdd$1(this, _selection);
|
|
10253
11354
|
__privateAdd$1(this, _show, ref(false));
|
|
10254
11355
|
__privateAdd$1(this, _mousePressed, false);
|
|
11356
|
+
__privateAdd$1(this, _removePopupListener);
|
|
11357
|
+
__privateAdd$1(this, _onDocumentMouseUp);
|
|
10255
11358
|
this.update = (view, prevState) => {
|
|
10256
11359
|
__privateGet$1(this, _tooltipProvider).update(view, prevState);
|
|
10257
11360
|
__privateGet$1(this, _selection).value = view.state.selection;
|
|
10258
11361
|
};
|
|
10259
11362
|
this.destroy = () => {
|
|
11363
|
+
var _a;
|
|
11364
|
+
(_a = __privateGet$1(this, _removePopupListener)) == null ? void 0 : _a.call(this);
|
|
11365
|
+
if (__privateGet$1(this, _onDocumentMouseUp)) {
|
|
11366
|
+
document.removeEventListener("mouseup", __privateGet$1(this, _onDocumentMouseUp));
|
|
11367
|
+
}
|
|
10260
11368
|
__privateGet$1(this, _tooltipProvider).destroy();
|
|
10261
11369
|
__privateGet$1(this, _app).unmount();
|
|
10262
11370
|
__privateGet$1(this, _content).remove();
|
|
@@ -10286,12 +11394,23 @@ class ToolbarView {
|
|
|
10286
11394
|
this.update(view);
|
|
10287
11395
|
}, 0);
|
|
10288
11396
|
});
|
|
11397
|
+
const onDocumentMouseUp = () => {
|
|
11398
|
+
if (__privateGet$1(this, _mousePressed)) {
|
|
11399
|
+
__privateSet$1(this, _mousePressed, false);
|
|
11400
|
+
setTimeout(() => {
|
|
11401
|
+
this.update(view);
|
|
11402
|
+
}, 0);
|
|
11403
|
+
}
|
|
11404
|
+
};
|
|
11405
|
+
document.addEventListener("mouseup", onDocumentMouseUp);
|
|
11406
|
+
__privateSet$1(this, _onDocumentMouseUp, onDocumentMouseUp);
|
|
10289
11407
|
__privateSet$1(this, _tooltipProvider, new TooltipProvider({
|
|
10290
11408
|
content: __privateGet$1(this, _content),
|
|
10291
11409
|
debounce: 20,
|
|
10292
11410
|
offset: 10,
|
|
10293
11411
|
shouldShow: (view2) => {
|
|
10294
11412
|
if (__privateGet$1(this, _mousePressed)) return false;
|
|
11413
|
+
if (getIsAnyPopupOpen()) return false;
|
|
10295
11414
|
const { doc, selection } = view2.state;
|
|
10296
11415
|
const { empty, from, to } = selection;
|
|
10297
11416
|
const isEmptyTextBlock = !doc.textBetween(from, to).length && selection instanceof TextSelection;
|
|
@@ -10311,6 +11430,13 @@ class ToolbarView {
|
|
|
10311
11430
|
__privateGet$1(this, _tooltipProvider).onHide = () => {
|
|
10312
11431
|
__privateGet$1(this, _show).value = false;
|
|
10313
11432
|
};
|
|
11433
|
+
__privateSet$1(this, _removePopupListener, addPopupChangeListener(() => {
|
|
11434
|
+
if (getIsAnyPopupOpen()) {
|
|
11435
|
+
__privateGet$1(this, _tooltipProvider).hide();
|
|
11436
|
+
} else {
|
|
11437
|
+
__privateGet$1(this, _tooltipProvider).update(view);
|
|
11438
|
+
}
|
|
11439
|
+
}));
|
|
10314
11440
|
this.update(view);
|
|
10315
11441
|
}
|
|
10316
11442
|
}
|
|
@@ -10320,6 +11446,8 @@ _app = new WeakMap();
|
|
|
10320
11446
|
_selection = new WeakMap();
|
|
10321
11447
|
_show = new WeakMap();
|
|
10322
11448
|
_mousePressed = new WeakMap();
|
|
11449
|
+
_removePopupListener = new WeakMap();
|
|
11450
|
+
_onDocumentMouseUp = new WeakMap();
|
|
10323
11451
|
const toolbar = (editor, config) => {
|
|
10324
11452
|
editor.config(crepeFeatureConfig(CrepeFeature.Toolbar)).config((ctx) => {
|
|
10325
11453
|
ctx.set(toolbarTooltip.key, {
|
|
@@ -10377,6 +11505,12 @@ function loadFeature(feature, editor, config) {
|
|
|
10377
11505
|
case CrepeFeature.Attachment: {
|
|
10378
11506
|
return attachment(editor, config);
|
|
10379
11507
|
}
|
|
11508
|
+
case CrepeFeature.InlineDiff: {
|
|
11509
|
+
return inlineDiff(editor, config);
|
|
11510
|
+
}
|
|
11511
|
+
case CrepeFeature.DiffBlock: {
|
|
11512
|
+
return diffBlockFeature(editor, config);
|
|
11513
|
+
}
|
|
10380
11514
|
}
|
|
10381
11515
|
}
|
|
10382
11516
|
|
|
@@ -10433,6 +11567,22 @@ class CrepeBuilder {
|
|
|
10433
11567
|
this.getMarkdown = () => {
|
|
10434
11568
|
return __privateGet(this, _editor).action(getMarkdown());
|
|
10435
11569
|
};
|
|
11570
|
+
/// Show inline diff between two markdown versions.
|
|
11571
|
+
this.showDiff = (oldMarkdown, newMarkdown) => {
|
|
11572
|
+
__privateGet(this, _editor).action((ctx) => {
|
|
11573
|
+
const api = ctx.get(inlineDiffApiCtx.key);
|
|
11574
|
+
api.showDiff(oldMarkdown, newMarkdown);
|
|
11575
|
+
});
|
|
11576
|
+
return this;
|
|
11577
|
+
};
|
|
11578
|
+
/// Hide inline diff and return to editing mode.
|
|
11579
|
+
this.hideDiff = () => {
|
|
11580
|
+
__privateGet(this, _editor).action((ctx) => {
|
|
11581
|
+
const api = ctx.get(inlineDiffApiCtx.key);
|
|
11582
|
+
api.hideDiff();
|
|
11583
|
+
});
|
|
11584
|
+
return this;
|
|
11585
|
+
};
|
|
10436
11586
|
/// Register event listeners.
|
|
10437
11587
|
this.on = (fn) => {
|
|
10438
11588
|
if (__privateGet(this, _editor).status !== EditorStatus.Created) {
|