@milkdown/crepe 7.5.0 → 7.5.1
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/{index--tnUmqZ_.js → index--2zEz40J.js} +8 -23
- package/lib/cjs/{index--tnUmqZ_.js.map → index--2zEz40J.js.map} +1 -1
- package/lib/cjs/{index-92bwto5V.js → index-5n9R-QCl.js} +5 -20
- package/lib/cjs/{index-92bwto5V.js.map → index-5n9R-QCl.js.map} +1 -1
- package/lib/cjs/{index-HH5lPgpj.js → index-HEdBw63r.js} +8 -23
- package/lib/cjs/{index-HH5lPgpj.js.map → index-HEdBw63r.js.map} +1 -1
- package/lib/cjs/{index-J1-yHn7v.js → index-Hlt9dRH5.js} +5 -20
- package/lib/cjs/{index-J1-yHn7v.js.map → index-Hlt9dRH5.js.map} +1 -1
- package/lib/cjs/{index-cb-5m0vG.js → index-KCW2CzRk.js} +8 -23
- package/lib/cjs/index-KCW2CzRk.js.map +1 -0
- package/lib/cjs/{index-VYwHTL3F.js → index-KSZhahYb.js} +6 -21
- package/lib/cjs/{index-VYwHTL3F.js.map → index-KSZhahYb.js.map} +1 -1
- package/lib/cjs/index-N1cRxqdw.js +39 -0
- package/lib/cjs/index-N1cRxqdw.js.map +1 -0
- package/lib/cjs/{index-c_OzudR7.js → index-NNo_VSEA.js} +5 -20
- package/lib/{esm/index-DS7Z4Ach.js.map → cjs/index-NNo_VSEA.js.map} +1 -1
- package/lib/cjs/{index-Tjg8KyK7.js → index-O1bDbloo.js} +5 -20
- package/lib/{esm/index-eqd5wtjX.js.map → cjs/index-O1bDbloo.js.map} +1 -1
- package/lib/cjs/{index-55VIM-52.js → index-OPh9naof.js} +8 -23
- package/lib/cjs/{index-55VIM-52.js.map → index-OPh9naof.js.map} +1 -1
- package/lib/cjs/{index-E4Ist86Z.js → index-PAhfZtcH.js} +5 -20
- package/lib/cjs/{index-E4Ist86Z.js.map → index-PAhfZtcH.js.map} +1 -1
- package/lib/cjs/{index-vfzLCXfi.js → index-PeRHVz4A.js} +5 -20
- package/lib/{esm/index-3bDzhU6z.js.map → cjs/index-PeRHVz4A.js.map} +1 -1
- package/lib/cjs/{index-Jztk6JlP.js → index-U7GWrg-w.js} +9 -456
- package/lib/cjs/index-U7GWrg-w.js.map +1 -0
- package/lib/cjs/{index-zXSAHvAj.js → index-UTb0Az5e.js} +2 -2
- package/lib/cjs/{index-zXSAHvAj.js.map → index-UTb0Az5e.js.map} +1 -1
- package/lib/cjs/{index-lBumFRUQ.js → index-UnEAyH8X.js} +5 -20
- package/lib/cjs/{index-lBumFRUQ.js.map → index-UnEAyH8X.js.map} +1 -1
- package/lib/cjs/{index-1vHyMXH8.js → index-VCkq0ru1.js} +5 -20
- package/lib/{esm/index-g_3dzLYU.js.map → cjs/index-VCkq0ru1.js.map} +1 -1
- package/lib/cjs/{index-FbNqlZU8.js → index-WQl7Du53.js} +4 -19
- package/lib/cjs/index-WQl7Du53.js.map +1 -0
- package/lib/cjs/{index-nTfDKYYi.js → index-ahL5MvrQ.js} +28 -43
- package/lib/cjs/{index-nTfDKYYi.js.map → index-ahL5MvrQ.js.map} +1 -1
- package/lib/cjs/{index--sa4NMpW.js → index-bpgWLeRY.js} +5 -20
- package/lib/cjs/{index--sa4NMpW.js.map → index-bpgWLeRY.js.map} +1 -1
- package/lib/cjs/index-dEVmN_aj.js +26 -0
- package/lib/cjs/index-dEVmN_aj.js.map +1 -0
- package/lib/cjs/{index-von4W2LG.js → index-fZupvR_f.js} +8 -23
- package/lib/{esm/index-NZ5-xr5_.js.map → cjs/index-fZupvR_f.js.map} +1 -1
- package/lib/cjs/{index-mcxgNBq9.js → index-gSM-jgti.js} +5 -20
- package/lib/cjs/{index-mcxgNBq9.js.map → index-gSM-jgti.js.map} +1 -1
- package/lib/cjs/{index-lUNj3xuC.js → index-jlPr_A_N.js} +5 -20
- package/lib/cjs/{index-lUNj3xuC.js.map → index-jlPr_A_N.js.map} +1 -1
- package/lib/cjs/index-ocxd4A-M.js +675 -0
- package/lib/cjs/index-ocxd4A-M.js.map +1 -0
- package/lib/cjs/{index-J3XY9IPt.js → index-rFFAL9YA.js} +9 -17
- package/lib/cjs/{index-J3XY9IPt.js.map → index-rFFAL9YA.js.map} +1 -1
- package/lib/cjs/index-tlx25I_m.js +36 -0
- package/lib/cjs/index-tlx25I_m.js.map +1 -0
- package/lib/cjs/index-tqAbVyds.js +28 -0
- package/lib/cjs/index-tqAbVyds.js.map +1 -0
- package/lib/cjs/{index-cpC-j5Nt.js → index-udZSknd8.js} +30 -39
- package/lib/cjs/{index-cpC-j5Nt.js.map → index-udZSknd8.js.map} +1 -1
- package/lib/cjs/index-uleaJDBC.js +19 -0
- package/lib/cjs/index-uleaJDBC.js.map +1 -0
- package/lib/cjs/{index-jn036wuh.js → index-urB-WDqA.js} +7 -22
- package/lib/{esm/index-VoX_n1l_.js.map → cjs/index-urB-WDqA.js.map} +1 -1
- package/lib/cjs/{index-jlfsu92T.js → index-xWgWtxUR.js} +6 -21
- package/lib/cjs/{index-jlfsu92T.js.map → index-xWgWtxUR.js.map} +1 -1
- package/lib/cjs/index.js +150 -14
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/{todoList-Ze4FLMlx.js → todoList-YYRQo7wG.js} +1 -12
- package/lib/cjs/todoList-YYRQo7wG.js.map +1 -0
- package/lib/esm/{index-Yuj7sNhQ.js → index-1NetiFdJ.js} +8 -23
- package/lib/esm/{index-Yuj7sNhQ.js.map → index-1NetiFdJ.js.map} +1 -1
- package/lib/esm/{index-6GrVnloh.js → index-2I_xbjAZ.js} +28 -43
- package/lib/esm/{index-6GrVnloh.js.map → index-2I_xbjAZ.js.map} +1 -1
- package/lib/esm/{index-bexsWrgs.js → index-2huXYfuJ.js} +8 -23
- package/lib/esm/{index-bexsWrgs.js.map → index-2huXYfuJ.js.map} +1 -1
- package/lib/esm/{index-zrQXXSXm.js → index-4x6_TVZv.js} +5 -20
- package/lib/esm/{index-zrQXXSXm.js.map → index-4x6_TVZv.js.map} +1 -1
- package/lib/esm/index-6JoGWH2I.js +17 -0
- package/lib/esm/index-6JoGWH2I.js.map +1 -0
- package/lib/esm/{index-OpUb5xP6.js → index-A-dNwMMf.js} +2 -2
- package/lib/esm/{index-OpUb5xP6.js.map → index-A-dNwMMf.js.map} +1 -1
- package/lib/esm/{index-SDPCpsD5.js → index-AV99ipmP.js} +5 -20
- package/lib/esm/{index-SDPCpsD5.js.map → index-AV99ipmP.js.map} +1 -1
- package/lib/esm/{index-MB6wQe1U.js → index-CMGDOz11.js} +5 -13
- package/lib/esm/{index-MB6wQe1U.js.map → index-CMGDOz11.js.map} +1 -1
- package/lib/esm/index-HlPKwzLC.js +34 -0
- package/lib/esm/index-HlPKwzLC.js.map +1 -0
- package/lib/esm/{index-MxgqkRtj.js → index-PC2bahtq.js} +5 -20
- package/lib/esm/{index-MxgqkRtj.js.map → index-PC2bahtq.js.map} +1 -1
- package/lib/esm/{index-eqd5wtjX.js → index-QBYz82jZ.js} +5 -20
- package/lib/{cjs/index-Tjg8KyK7.js.map → esm/index-QBYz82jZ.js.map} +1 -1
- package/lib/esm/{index-VP76m4nW.js → index-W1pAMr_8.js} +6 -21
- package/lib/esm/{index-VP76m4nW.js.map → index-W1pAMr_8.js.map} +1 -1
- package/lib/esm/{index-i79QMXpJ.js → index-Xzdc2jbA.js} +7 -454
- package/lib/esm/index-Xzdc2jbA.js.map +1 -0
- package/lib/esm/{index-_4fWmRbN.js → index-ZAtZWqJQ.js} +5 -20
- package/lib/esm/{index-_4fWmRbN.js.map → index-ZAtZWqJQ.js.map} +1 -1
- package/lib/esm/index-_A9vu1ED.js +673 -0
- package/lib/esm/index-_A9vu1ED.js.map +1 -0
- package/lib/esm/{index-x8SyiPMC.js → index-bnSKBrbD.js} +5 -20
- package/lib/esm/{index-x8SyiPMC.js.map → index-bnSKBrbD.js.map} +1 -1
- package/lib/esm/index-fVrfHXda.js +24 -0
- package/lib/esm/index-fVrfHXda.js.map +1 -0
- package/lib/esm/{index-Vl0W0S3h.js → index-ftnOhuRS.js} +4 -19
- package/lib/esm/index-ftnOhuRS.js.map +1 -0
- package/lib/esm/{index-1l-61HI-.js → index-iQPB0Rdl.js} +6 -21
- package/lib/esm/{index-1l-61HI-.js.map → index-iQPB0Rdl.js.map} +1 -1
- package/lib/esm/{index-grT-Kuf2.js → index-kPj3-TKp.js} +5 -20
- package/lib/esm/{index-grT-Kuf2.js.map → index-kPj3-TKp.js.map} +1 -1
- package/lib/esm/{index-NZ5-xr5_.js → index-kgOR7SZ6.js} +8 -23
- package/lib/{cjs/index-von4W2LG.js.map → esm/index-kgOR7SZ6.js.map} +1 -1
- package/lib/esm/{index-A83StUe6.js → index-lm00PM0y.js} +8 -17
- package/lib/esm/{index-A83StUe6.js.map → index-lm00PM0y.js.map} +1 -1
- package/lib/esm/{index-g_3dzLYU.js → index-m49Bj3q7.js} +5 -20
- package/lib/{cjs/index-1vHyMXH8.js.map → esm/index-m49Bj3q7.js.map} +1 -1
- package/lib/esm/index-ohmbt6Ys.js +37 -0
- package/lib/esm/index-ohmbt6Ys.js.map +1 -0
- package/lib/esm/{index-rvOBAXap.js → index-sWVjGw-3.js} +8 -23
- package/lib/esm/index-sWVjGw-3.js.map +1 -0
- package/lib/esm/{index-DS7Z4Ach.js → index-twh8lL5o.js} +5 -20
- package/lib/{cjs/index-c_OzudR7.js.map → esm/index-twh8lL5o.js.map} +1 -1
- package/lib/esm/{index-3bDzhU6z.js → index-v02MCz4_.js} +5 -20
- package/lib/{cjs/index-vfzLCXfi.js.map → esm/index-v02MCz4_.js.map} +1 -1
- package/lib/esm/index-v3rvbocl.js +26 -0
- package/lib/esm/index-v3rvbocl.js.map +1 -0
- package/lib/esm/{index-XH7OnwZl.js → index-wEXT8mbN.js} +5 -20
- package/lib/esm/{index-XH7OnwZl.js.map → index-wEXT8mbN.js.map} +1 -1
- package/lib/esm/{index-VoX_n1l_.js → index-wFIac5Kw.js} +7 -22
- package/lib/{cjs/index-jn036wuh.js.map → esm/index-wFIac5Kw.js.map} +1 -1
- package/lib/esm/{index-3HeWs5rX.js → index-wg94ewRo.js} +8 -23
- package/lib/esm/{index-3HeWs5rX.js.map → index-wg94ewRo.js.map} +1 -1
- package/lib/esm/index.js +152 -12
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/{todoList-M-PGJKde.js → todoList-9QsDDcmB.js} +2 -12
- package/lib/esm/todoList-9QsDDcmB.js.map +1 -0
- package/package.json +1 -1
- package/lib/cjs/_view-N32ied53.js +0 -27
- package/lib/cjs/_view-N32ied53.js.map +0 -1
- package/lib/cjs/floating-ui.dom-2cjBpir5.js +0 -1134
- package/lib/cjs/floating-ui.dom-2cjBpir5.js.map +0 -1
- package/lib/cjs/helper-1aludV1Z.js +0 -15
- package/lib/cjs/helper-1aludV1Z.js.map +0 -1
- package/lib/cjs/index-28q261C7.js +0 -448
- package/lib/cjs/index-28q261C7.js.map +0 -1
- package/lib/cjs/index-Buu2tD9O.js +0 -534
- package/lib/cjs/index-Buu2tD9O.js.map +0 -1
- package/lib/cjs/index-FbNqlZU8.js.map +0 -1
- package/lib/cjs/index-Jztk6JlP.js.map +0 -1
- package/lib/cjs/index-N6pPZY61.js +0 -191
- package/lib/cjs/index-N6pPZY61.js.map +0 -1
- package/lib/cjs/index-TUJs6KKL.js +0 -472
- package/lib/cjs/index-TUJs6KKL.js.map +0 -1
- package/lib/cjs/index-_GOdKqUK.js +0 -1147
- package/lib/cjs/index-_GOdKqUK.js.map +0 -1
- package/lib/cjs/index-cKQcw-eu.js +0 -386
- package/lib/cjs/index-cKQcw-eu.js.map +0 -1
- package/lib/cjs/index-cb-5m0vG.js.map +0 -1
- package/lib/cjs/index-crv_k6dv.js +0 -1353
- package/lib/cjs/index-crv_k6dv.js.map +0 -1
- package/lib/cjs/index-kqz-P6o6.js +0 -55
- package/lib/cjs/index-kqz-P6o6.js.map +0 -1
- package/lib/cjs/index-tBw4NmwY.js +0 -33852
- package/lib/cjs/index-tBw4NmwY.js.map +0 -1
- package/lib/cjs/schema-RVrwDDcq.js +0 -74
- package/lib/cjs/schema-RVrwDDcq.js.map +0 -1
- package/lib/cjs/todoList-Ze4FLMlx.js.map +0 -1
- package/lib/cjs/tooltip-plugin--lhebztC.js +0 -191
- package/lib/cjs/tooltip-plugin--lhebztC.js.map +0 -1
- package/lib/esm/_view-IlZC8FA6.js +0 -25
- package/lib/esm/_view-IlZC8FA6.js.map +0 -1
- package/lib/esm/floating-ui.dom-CAYjY8Gv.js +0 -1130
- package/lib/esm/floating-ui.dom-CAYjY8Gv.js.map +0 -1
- package/lib/esm/helper-wZAtC67x.js +0 -13
- package/lib/esm/helper-wZAtC67x.js.map +0 -1
- package/lib/esm/index-0-j8Icms.js +0 -384
- package/lib/esm/index-0-j8Icms.js.map +0 -1
- package/lib/esm/index-8QJbxTYk.js +0 -1145
- package/lib/esm/index-8QJbxTYk.js.map +0 -1
- package/lib/esm/index-9w_hdnvb.js +0 -532
- package/lib/esm/index-9w_hdnvb.js.map +0 -1
- package/lib/esm/index-AOoFzBaK.js +0 -53
- package/lib/esm/index-AOoFzBaK.js.map +0 -1
- package/lib/esm/index-LAdX6LsO.js +0 -33805
- package/lib/esm/index-LAdX6LsO.js.map +0 -1
- package/lib/esm/index-Vl0W0S3h.js.map +0 -1
- package/lib/esm/index-chrnjY1D.js +0 -470
- package/lib/esm/index-chrnjY1D.js.map +0 -1
- package/lib/esm/index-hF04phbf.js +0 -189
- package/lib/esm/index-hF04phbf.js.map +0 -1
- package/lib/esm/index-i79QMXpJ.js.map +0 -1
- package/lib/esm/index-rvOBAXap.js.map +0 -1
- package/lib/esm/index-uP9BKsTM.js +0 -446
- package/lib/esm/index-uP9BKsTM.js.map +0 -1
- package/lib/esm/index-ueQQMSgm.js +0 -1351
- package/lib/esm/index-ueQQMSgm.js.map +0 -1
- package/lib/esm/schema-JWJqD9qa.js +0 -71
- package/lib/esm/schema-JWJqD9qa.js.map +0 -1
- package/lib/esm/todoList-M-PGJKde.js.map +0 -1
- package/lib/esm/tooltip-plugin-iw2EQWIG.js +0 -185
- package/lib/esm/tooltip-plugin-iw2EQWIG.js.map +0 -1
|
@@ -1,1351 +0,0 @@
|
|
|
1
|
-
import { d as defIfNotExists, i as isInCodeBlock, a as isInList } from './index-Jvxff1vU.js';
|
|
2
|
-
import { c, useMemo, useHost, useState, useRef, useCallback, useEffect, html } from 'atomico';
|
|
3
|
-
import { t as textIcon, j as h1Icon, k as h2Icon, m as h3Icon, n as h4Icon, o as h5Icon, p as h6Icon, q as quoteIcon, u as dividerIcon, v as bulletListIcon, x as orderedListIcon, y as todoListIcon, i as imageIcon, z as codeIcon, A as tableIcon, B as plusIcon, C as menuIcon } from './todoList-M-PGJKde.js';
|
|
4
|
-
import { findWrapping } from '@milkdown/prose/transform';
|
|
5
|
-
import { i as imageBlockSchema } from './schema-JWJqD9qa.js';
|
|
6
|
-
import { $ as $ctx, e as editorViewCtx, d as $prose, p as paragraphSchema, h as headingSchema, f as blockquoteSchema, g as hrSchema, j as bulletListSchema, o as orderedListSchema, l as listItemSchema, c as codeBlockSchema, k as createTable } from './index-LAdX6LsO.js';
|
|
7
|
-
import { NodeSelection, PluginKey, Plugin, TextSelection } from '@milkdown/prose/state';
|
|
8
|
-
import { findParent, browser, findParentNode, posToDOMRect } from '@milkdown/prose';
|
|
9
|
-
import { d as debounce } from './index-0-j8Icms.js';
|
|
10
|
-
import { o as offset, c as computePosition, f as flip } from './floating-ui.dom-CAYjY8Gv.js';
|
|
11
|
-
import { t as throttle } from './index-uP9BKsTM.js';
|
|
12
|
-
import { DOMSerializer } from '@milkdown/prose/model';
|
|
13
|
-
import '@milkdown/prose/commands';
|
|
14
|
-
import '@milkdown/prose/inputrules';
|
|
15
|
-
import '@milkdown/prose/keymap';
|
|
16
|
-
import '@milkdown/prose/view';
|
|
17
|
-
import '@milkdown/prose/schema-list';
|
|
18
|
-
import '@milkdown/prose/history';
|
|
19
|
-
import '@milkdown/prose/tables';
|
|
20
|
-
|
|
21
|
-
function withMeta(plugin, meta) {
|
|
22
|
-
Object.assign(plugin, {
|
|
23
|
-
meta: {
|
|
24
|
-
package: "@milkdown/plugin-block",
|
|
25
|
-
...meta
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
return plugin;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const defaultNodeFilter = (pos) => {
|
|
32
|
-
const table = findParent((node) => node.type.name === "table")(pos);
|
|
33
|
-
if (table)
|
|
34
|
-
return false;
|
|
35
|
-
return true;
|
|
36
|
-
};
|
|
37
|
-
const blockConfig = $ctx({ filterNodes: defaultNodeFilter }, "blockConfig");
|
|
38
|
-
withMeta(blockConfig, {
|
|
39
|
-
displayName: "Ctx<blockConfig>"
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
function selectRootNodeByDom(view, coords, filterNodes) {
|
|
43
|
-
var _a;
|
|
44
|
-
const root = view.dom.parentElement;
|
|
45
|
-
if (!root)
|
|
46
|
-
return null;
|
|
47
|
-
const pos = (_a = view.posAtCoords({
|
|
48
|
-
left: coords.x,
|
|
49
|
-
top: coords.y
|
|
50
|
-
})) == null ? void 0 : _a.inside;
|
|
51
|
-
if (pos == null || pos < 0)
|
|
52
|
-
return null;
|
|
53
|
-
let $pos = view.state.doc.resolve(pos);
|
|
54
|
-
let node = view.state.doc.nodeAt(pos);
|
|
55
|
-
let element = view.nodeDOM(pos);
|
|
56
|
-
const filter = (needLookup) => {
|
|
57
|
-
const checkDepth = $pos.depth >= 1 && $pos.index($pos.depth) === 0;
|
|
58
|
-
const shouldLookUp = needLookup || checkDepth;
|
|
59
|
-
if (!shouldLookUp)
|
|
60
|
-
return;
|
|
61
|
-
const ancestorPos = $pos.before($pos.depth);
|
|
62
|
-
node = view.state.doc.nodeAt(ancestorPos);
|
|
63
|
-
element = view.nodeDOM(ancestorPos);
|
|
64
|
-
$pos = view.state.doc.resolve(ancestorPos);
|
|
65
|
-
if (!filterNodes($pos, node))
|
|
66
|
-
filter(true);
|
|
67
|
-
};
|
|
68
|
-
const filterResult = filterNodes($pos, node);
|
|
69
|
-
filter(!filterResult);
|
|
70
|
-
if (!element || !node)
|
|
71
|
-
return null;
|
|
72
|
-
return { node, $pos, el: element };
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
let _detachedDoc = null;
|
|
76
|
-
function detachedDoc() {
|
|
77
|
-
return _detachedDoc || (_detachedDoc = document.implementation.createHTMLDocument("title"));
|
|
78
|
-
}
|
|
79
|
-
const wrapMap = {
|
|
80
|
-
thead: ["table"],
|
|
81
|
-
tbody: ["table"],
|
|
82
|
-
tfoot: ["table"],
|
|
83
|
-
caption: ["table"],
|
|
84
|
-
colgroup: ["table"],
|
|
85
|
-
col: ["table", "colgroup"],
|
|
86
|
-
tr: ["table", "tbody"],
|
|
87
|
-
td: ["table", "tbody", "tr"],
|
|
88
|
-
th: ["table", "tbody", "tr"]
|
|
89
|
-
};
|
|
90
|
-
function serializeForClipboard(view, slice) {
|
|
91
|
-
const context = [];
|
|
92
|
-
let { openStart, openEnd, content } = slice;
|
|
93
|
-
while (openStart > 1 && openEnd > 1 && content.childCount === 1 && content.firstChild.childCount === 1) {
|
|
94
|
-
openStart -= 1;
|
|
95
|
-
openEnd -= 1;
|
|
96
|
-
const node = content.firstChild;
|
|
97
|
-
context.push(
|
|
98
|
-
node.type.name,
|
|
99
|
-
node.attrs !== node.type.defaultAttrs ? node.attrs : null
|
|
100
|
-
);
|
|
101
|
-
content = node.content;
|
|
102
|
-
}
|
|
103
|
-
const serializer = view.someProp("clipboardSerializer") || DOMSerializer.fromSchema(view.state.schema);
|
|
104
|
-
const doc = detachedDoc();
|
|
105
|
-
const wrap = doc.createElement("div");
|
|
106
|
-
wrap.appendChild(serializer.serializeFragment(content, { document: doc }));
|
|
107
|
-
let firstChild = wrap.firstChild;
|
|
108
|
-
let needsWrap;
|
|
109
|
-
let wrappers = 0;
|
|
110
|
-
while (firstChild && firstChild.nodeType === 1 && (needsWrap = wrapMap[firstChild.nodeName.toLowerCase()])) {
|
|
111
|
-
for (let i = needsWrap.length - 1; i >= 0; i--) {
|
|
112
|
-
const wrapper = doc.createElement(needsWrap[i]);
|
|
113
|
-
while (wrap.firstChild) wrapper.appendChild(wrap.firstChild);
|
|
114
|
-
wrap.appendChild(wrapper);
|
|
115
|
-
wrappers++;
|
|
116
|
-
}
|
|
117
|
-
firstChild = wrap.firstChild;
|
|
118
|
-
}
|
|
119
|
-
if (firstChild && firstChild.nodeType === 1) {
|
|
120
|
-
firstChild.setAttribute(
|
|
121
|
-
"data-pm-slice",
|
|
122
|
-
`${openStart} ${openEnd}${wrappers ? ` -${wrappers}` : ""} ${JSON.stringify(context)}`
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
const text = view.someProp("clipboardTextSerializer", (f) => f(slice, view)) || slice.content.textBetween(0, slice.content.size, "\n\n");
|
|
126
|
-
return { dom: wrap, text };
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
var __typeError$5 = (msg) => {
|
|
130
|
-
throw TypeError(msg);
|
|
131
|
-
};
|
|
132
|
-
var __accessCheck$5 = (obj, member, msg) => member.has(obj) || __typeError$5("Cannot " + msg);
|
|
133
|
-
var __privateGet$5 = (obj, member, getter) => (__accessCheck$5(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
134
|
-
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);
|
|
135
|
-
var __privateSet$5 = (obj, member, value, setter) => (__accessCheck$5(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
136
|
-
var _ctx$2, _createSelection, _activeSelection, _active, _activeDOMRect, _dragging, _BlockService_instances, filterNodes_get, view_get, _notify, _hide, _show, _handleMouseDown, _handleMouseUp, _handleDragStart, _mousemoveCallback, _dragEnd;
|
|
137
|
-
const brokenClipboardAPI = browser.ie && browser.ie_version < 15 || browser.ios && browser.webkit_version < 604;
|
|
138
|
-
const buffer = 20;
|
|
139
|
-
class BlockService {
|
|
140
|
-
constructor() {
|
|
141
|
-
__privateAdd$5(this, _BlockService_instances);
|
|
142
|
-
/// @internal
|
|
143
|
-
__privateAdd$5(this, _ctx$2);
|
|
144
|
-
/// @internal
|
|
145
|
-
__privateAdd$5(this, _createSelection, () => {
|
|
146
|
-
if (!__privateGet$5(this, _active))
|
|
147
|
-
return null;
|
|
148
|
-
const result = __privateGet$5(this, _active);
|
|
149
|
-
const view = __privateGet$5(this, _BlockService_instances, view_get);
|
|
150
|
-
if (view && NodeSelection.isSelectable(result.node)) {
|
|
151
|
-
const nodeSelection = NodeSelection.create(view.state.doc, result.$pos.pos);
|
|
152
|
-
view.dispatch(view.state.tr.setSelection(nodeSelection));
|
|
153
|
-
view.focus();
|
|
154
|
-
__privateSet$5(this, _activeSelection, nodeSelection);
|
|
155
|
-
return nodeSelection;
|
|
156
|
-
}
|
|
157
|
-
return null;
|
|
158
|
-
});
|
|
159
|
-
/// @internal
|
|
160
|
-
__privateAdd$5(this, _activeSelection, null);
|
|
161
|
-
/// @internal
|
|
162
|
-
__privateAdd$5(this, _active, null);
|
|
163
|
-
/// @internal
|
|
164
|
-
__privateAdd$5(this, _activeDOMRect);
|
|
165
|
-
/// @internal
|
|
166
|
-
__privateAdd$5(this, _dragging, false);
|
|
167
|
-
/// @internal
|
|
168
|
-
__privateAdd$5(this, _notify);
|
|
169
|
-
/// @internal
|
|
170
|
-
__privateAdd$5(this, _hide, () => {
|
|
171
|
-
var _a;
|
|
172
|
-
(_a = __privateGet$5(this, _notify)) == null ? void 0 : _a.call(this, { type: "hide" });
|
|
173
|
-
__privateSet$5(this, _active, null);
|
|
174
|
-
});
|
|
175
|
-
/// @internal
|
|
176
|
-
__privateAdd$5(this, _show, (active) => {
|
|
177
|
-
var _a;
|
|
178
|
-
__privateSet$5(this, _active, active);
|
|
179
|
-
(_a = __privateGet$5(this, _notify)) == null ? void 0 : _a.call(this, { type: "show", active });
|
|
180
|
-
});
|
|
181
|
-
/// Bind editor context and notify function to the service.
|
|
182
|
-
this.bind = (ctx, notify) => {
|
|
183
|
-
__privateSet$5(this, _ctx$2, ctx);
|
|
184
|
-
__privateSet$5(this, _notify, notify);
|
|
185
|
-
};
|
|
186
|
-
/// Add mouse event to the dom.
|
|
187
|
-
this.addEvent = (dom) => {
|
|
188
|
-
dom.addEventListener("mousedown", __privateGet$5(this, _handleMouseDown));
|
|
189
|
-
dom.addEventListener("mouseup", __privateGet$5(this, _handleMouseUp));
|
|
190
|
-
dom.addEventListener("dragstart", __privateGet$5(this, _handleDragStart));
|
|
191
|
-
};
|
|
192
|
-
/// Remove mouse event to the dom.
|
|
193
|
-
this.removeEvent = (dom) => {
|
|
194
|
-
dom.removeEventListener("mousedown", __privateGet$5(this, _handleMouseDown));
|
|
195
|
-
dom.removeEventListener("mouseup", __privateGet$5(this, _handleMouseUp));
|
|
196
|
-
dom.removeEventListener("dragstart", __privateGet$5(this, _handleDragStart));
|
|
197
|
-
};
|
|
198
|
-
/// Unbind the notify function.
|
|
199
|
-
this.unBind = () => {
|
|
200
|
-
__privateSet$5(this, _notify, void 0);
|
|
201
|
-
};
|
|
202
|
-
/// @internal
|
|
203
|
-
__privateAdd$5(this, _handleMouseDown, () => {
|
|
204
|
-
var _a;
|
|
205
|
-
__privateSet$5(this, _activeDOMRect, (_a = __privateGet$5(this, _active)) == null ? void 0 : _a.el.getBoundingClientRect());
|
|
206
|
-
__privateGet$5(this, _createSelection).call(this);
|
|
207
|
-
});
|
|
208
|
-
/// @internal
|
|
209
|
-
__privateAdd$5(this, _handleMouseUp, () => {
|
|
210
|
-
if (!__privateGet$5(this, _dragging)) {
|
|
211
|
-
requestAnimationFrame(() => {
|
|
212
|
-
var _a;
|
|
213
|
-
if (!__privateGet$5(this, _activeDOMRect))
|
|
214
|
-
return;
|
|
215
|
-
(_a = __privateGet$5(this, _BlockService_instances, view_get)) == null ? void 0 : _a.focus();
|
|
216
|
-
});
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
__privateSet$5(this, _dragging, false);
|
|
220
|
-
__privateSet$5(this, _activeSelection, null);
|
|
221
|
-
});
|
|
222
|
-
/// @internal
|
|
223
|
-
__privateAdd$5(this, _handleDragStart, (event) => {
|
|
224
|
-
var _a;
|
|
225
|
-
__privateSet$5(this, _dragging, true);
|
|
226
|
-
const view = __privateGet$5(this, _BlockService_instances, view_get);
|
|
227
|
-
if (!view)
|
|
228
|
-
return;
|
|
229
|
-
view.dom.dataset.dragging = "true";
|
|
230
|
-
const selection = __privateGet$5(this, _activeSelection);
|
|
231
|
-
if (event.dataTransfer && selection) {
|
|
232
|
-
const slice = selection.content();
|
|
233
|
-
event.dataTransfer.effectAllowed = "copyMove";
|
|
234
|
-
const { dom, text } = serializeForClipboard(view, slice);
|
|
235
|
-
event.dataTransfer.clearData();
|
|
236
|
-
event.dataTransfer.setData(brokenClipboardAPI ? "Text" : "text/html", dom.innerHTML);
|
|
237
|
-
if (!brokenClipboardAPI)
|
|
238
|
-
event.dataTransfer.setData("text/plain", text);
|
|
239
|
-
const activeEl = (_a = __privateGet$5(this, _active)) == null ? void 0 : _a.el;
|
|
240
|
-
if (activeEl)
|
|
241
|
-
event.dataTransfer.setDragImage(activeEl, 0, 0);
|
|
242
|
-
view.dragging = {
|
|
243
|
-
slice,
|
|
244
|
-
move: true
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
/// @internal
|
|
249
|
-
this.keydownCallback = (view) => {
|
|
250
|
-
__privateGet$5(this, _hide).call(this);
|
|
251
|
-
__privateSet$5(this, _dragging, false);
|
|
252
|
-
view.dom.dataset.dragging = "false";
|
|
253
|
-
return false;
|
|
254
|
-
};
|
|
255
|
-
/// @internal
|
|
256
|
-
__privateAdd$5(this, _mousemoveCallback, throttle((view, event) => {
|
|
257
|
-
if (!view.editable)
|
|
258
|
-
return;
|
|
259
|
-
const rect = view.dom.getBoundingClientRect();
|
|
260
|
-
const x = rect.left + rect.width / 2;
|
|
261
|
-
const dom = view.root.elementFromPoint(x, event.clientY);
|
|
262
|
-
if (!(dom instanceof Element)) {
|
|
263
|
-
__privateGet$5(this, _hide).call(this);
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
const filterNodes = __privateGet$5(this, _BlockService_instances, filterNodes_get);
|
|
267
|
-
if (!filterNodes)
|
|
268
|
-
return;
|
|
269
|
-
const result = selectRootNodeByDom(view, { x, y: event.clientY }, filterNodes);
|
|
270
|
-
if (!result) {
|
|
271
|
-
__privateGet$5(this, _hide).call(this);
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
__privateGet$5(this, _show).call(this, result);
|
|
275
|
-
}, 200));
|
|
276
|
-
/// @internal
|
|
277
|
-
this.mousemoveCallback = (view, event) => {
|
|
278
|
-
if (view.composing || !view.editable)
|
|
279
|
-
return false;
|
|
280
|
-
__privateGet$5(this, _mousemoveCallback).call(this, view, event);
|
|
281
|
-
return false;
|
|
282
|
-
};
|
|
283
|
-
/// @internal
|
|
284
|
-
this.dragoverCallback = (view, event) => {
|
|
285
|
-
var _a;
|
|
286
|
-
if (__privateGet$5(this, _dragging)) {
|
|
287
|
-
const root = (_a = __privateGet$5(this, _BlockService_instances, view_get)) == null ? void 0 : _a.dom.parentElement;
|
|
288
|
-
if (!root)
|
|
289
|
-
return false;
|
|
290
|
-
const hasHorizontalScrollbar = root.scrollHeight > root.clientHeight;
|
|
291
|
-
const rootRect = root.getBoundingClientRect();
|
|
292
|
-
if (hasHorizontalScrollbar) {
|
|
293
|
-
if (root.scrollTop > 0 && Math.abs(event.y - rootRect.y) < buffer) {
|
|
294
|
-
const top = root.scrollTop > 10 ? root.scrollTop - 10 : 0;
|
|
295
|
-
root.scrollTop = top;
|
|
296
|
-
return false;
|
|
297
|
-
}
|
|
298
|
-
const totalHeight = Math.round(view.dom.getBoundingClientRect().height);
|
|
299
|
-
const scrollBottom = Math.round(root.scrollTop + rootRect.height);
|
|
300
|
-
if (scrollBottom < totalHeight && Math.abs(event.y - (rootRect.height + rootRect.y)) < buffer) {
|
|
301
|
-
const top = root.scrollTop + 10;
|
|
302
|
-
root.scrollTop = top;
|
|
303
|
-
return false;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
return false;
|
|
308
|
-
};
|
|
309
|
-
/// @internal
|
|
310
|
-
this.dragenterCallback = (view) => {
|
|
311
|
-
if (!view.dragging)
|
|
312
|
-
return;
|
|
313
|
-
__privateSet$5(this, _dragging, true);
|
|
314
|
-
view.dom.dataset.dragging = "true";
|
|
315
|
-
};
|
|
316
|
-
/// @internal
|
|
317
|
-
this.dragleaveCallback = (view, event) => {
|
|
318
|
-
const x = event.clientX;
|
|
319
|
-
const y = event.clientY;
|
|
320
|
-
if (x < 0 || y < 0 || x > window.innerWidth || y > window.innerHeight) {
|
|
321
|
-
__privateSet$5(this, _active, null);
|
|
322
|
-
__privateGet$5(this, _dragEnd).call(this, view);
|
|
323
|
-
}
|
|
324
|
-
};
|
|
325
|
-
/// @internal
|
|
326
|
-
this.dropCallback = (view) => {
|
|
327
|
-
__privateGet$5(this, _dragEnd).call(this, view);
|
|
328
|
-
return false;
|
|
329
|
-
};
|
|
330
|
-
/// @internal
|
|
331
|
-
this.dragendCallback = (view) => {
|
|
332
|
-
__privateGet$5(this, _dragEnd).call(this, view);
|
|
333
|
-
};
|
|
334
|
-
/// @internal
|
|
335
|
-
__privateAdd$5(this, _dragEnd, (view) => {
|
|
336
|
-
__privateSet$5(this, _dragging, false);
|
|
337
|
-
view.dom.dataset.dragging = "false";
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
_ctx$2 = new WeakMap();
|
|
342
|
-
_createSelection = new WeakMap();
|
|
343
|
-
_activeSelection = new WeakMap();
|
|
344
|
-
_active = new WeakMap();
|
|
345
|
-
_activeDOMRect = new WeakMap();
|
|
346
|
-
_dragging = new WeakMap();
|
|
347
|
-
_BlockService_instances = new WeakSet();
|
|
348
|
-
filterNodes_get = function() {
|
|
349
|
-
var _a;
|
|
350
|
-
return (_a = __privateGet$5(this, _ctx$2)) == null ? void 0 : _a.get(blockConfig.key).filterNodes;
|
|
351
|
-
};
|
|
352
|
-
view_get = function() {
|
|
353
|
-
var _a;
|
|
354
|
-
return (_a = __privateGet$5(this, _ctx$2)) == null ? void 0 : _a.get(editorViewCtx);
|
|
355
|
-
};
|
|
356
|
-
_notify = new WeakMap();
|
|
357
|
-
_hide = new WeakMap();
|
|
358
|
-
_show = new WeakMap();
|
|
359
|
-
_handleMouseDown = new WeakMap();
|
|
360
|
-
_handleMouseUp = new WeakMap();
|
|
361
|
-
_handleDragStart = new WeakMap();
|
|
362
|
-
_mousemoveCallback = new WeakMap();
|
|
363
|
-
_dragEnd = new WeakMap();
|
|
364
|
-
|
|
365
|
-
const blockService = $ctx(new BlockService(), "blockService");
|
|
366
|
-
withMeta(blockConfig, {
|
|
367
|
-
displayName: "Ctx<blockService>"
|
|
368
|
-
});
|
|
369
|
-
const blockSpec = $ctx({}, "blockSpec");
|
|
370
|
-
withMeta(blockConfig, {
|
|
371
|
-
displayName: "Ctx<blockSpec>"
|
|
372
|
-
});
|
|
373
|
-
const blockPlugin = $prose((ctx) => {
|
|
374
|
-
const milkdownPluginBlockKey = new PluginKey("MILKDOWN_BLOCK");
|
|
375
|
-
const service = ctx.get(blockService.key);
|
|
376
|
-
const spec = ctx.get(blockSpec.key);
|
|
377
|
-
return new Plugin({
|
|
378
|
-
key: milkdownPluginBlockKey,
|
|
379
|
-
...spec,
|
|
380
|
-
props: {
|
|
381
|
-
...spec.props,
|
|
382
|
-
handleDOMEvents: {
|
|
383
|
-
drop: (view) => {
|
|
384
|
-
return service.dropCallback(view);
|
|
385
|
-
},
|
|
386
|
-
pointermove: (view, event) => {
|
|
387
|
-
return service.mousemoveCallback(view, event);
|
|
388
|
-
},
|
|
389
|
-
keydown: (view) => {
|
|
390
|
-
return service.keydownCallback(view);
|
|
391
|
-
},
|
|
392
|
-
dragover: (view, event) => {
|
|
393
|
-
return service.dragoverCallback(view, event);
|
|
394
|
-
},
|
|
395
|
-
dragleave: (view, event) => {
|
|
396
|
-
return service.dragleaveCallback(view, event);
|
|
397
|
-
},
|
|
398
|
-
dragenter: (view) => {
|
|
399
|
-
return service.dragenterCallback(view);
|
|
400
|
-
},
|
|
401
|
-
dragend: (view) => {
|
|
402
|
-
return service.dragendCallback(view);
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
});
|
|
407
|
-
});
|
|
408
|
-
withMeta(blockPlugin, {
|
|
409
|
-
displayName: "Prose<block>"
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
var __typeError$4 = (msg) => {
|
|
413
|
-
throw TypeError(msg);
|
|
414
|
-
};
|
|
415
|
-
var __accessCheck$4 = (obj, member, msg) => member.has(obj) || __typeError$4("Cannot " + msg);
|
|
416
|
-
var __privateGet$4 = (obj, member, getter) => (__accessCheck$4(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
417
|
-
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);
|
|
418
|
-
var __privateSet$4 = (obj, member, value, setter) => (__accessCheck$4(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
419
|
-
var __privateMethod$1 = (obj, member, method) => (__accessCheck$4(obj, member, "access private method"), method);
|
|
420
|
-
var _element, _ctx$1, _service, _activeNode, _initialized$1, _getOffset, _getPosition, _getPlacement, _BlockProvider_instances, init_fn;
|
|
421
|
-
class BlockProvider {
|
|
422
|
-
constructor(options) {
|
|
423
|
-
__privateAdd$4(this, _BlockProvider_instances);
|
|
424
|
-
/// @internal
|
|
425
|
-
__privateAdd$4(this, _element);
|
|
426
|
-
/// @internal
|
|
427
|
-
__privateAdd$4(this, _ctx$1);
|
|
428
|
-
/// @internal
|
|
429
|
-
__privateAdd$4(this, _service);
|
|
430
|
-
/// @internal
|
|
431
|
-
__privateAdd$4(this, _activeNode, null);
|
|
432
|
-
/// @internal
|
|
433
|
-
__privateAdd$4(this, _initialized$1, false);
|
|
434
|
-
/// @internal
|
|
435
|
-
__privateAdd$4(this, _getOffset);
|
|
436
|
-
/// @internal
|
|
437
|
-
__privateAdd$4(this, _getPosition);
|
|
438
|
-
/// @internal
|
|
439
|
-
__privateAdd$4(this, _getPlacement);
|
|
440
|
-
/// Update provider state by editor view.
|
|
441
|
-
this.update = () => {
|
|
442
|
-
requestAnimationFrame(() => {
|
|
443
|
-
if (!__privateGet$4(this, _initialized$1)) {
|
|
444
|
-
try {
|
|
445
|
-
__privateMethod$1(this, _BlockProvider_instances, init_fn).call(this);
|
|
446
|
-
__privateSet$4(this, _initialized$1, true);
|
|
447
|
-
} catch (e) {
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
});
|
|
451
|
-
};
|
|
452
|
-
/// Destroy the block.
|
|
453
|
-
this.destroy = () => {
|
|
454
|
-
var _a, _b;
|
|
455
|
-
(_a = __privateGet$4(this, _service)) == null ? void 0 : _a.unBind();
|
|
456
|
-
(_b = __privateGet$4(this, _service)) == null ? void 0 : _b.removeEvent(__privateGet$4(this, _element));
|
|
457
|
-
__privateGet$4(this, _element).remove();
|
|
458
|
-
};
|
|
459
|
-
/// Show the block.
|
|
460
|
-
this.show = (active) => {
|
|
461
|
-
const dom = active.el;
|
|
462
|
-
const editorDom = __privateGet$4(this, _ctx$1).get(editorViewCtx).dom;
|
|
463
|
-
const deriveContext = {
|
|
464
|
-
ctx: __privateGet$4(this, _ctx$1),
|
|
465
|
-
active,
|
|
466
|
-
editorDom,
|
|
467
|
-
blockDom: __privateGet$4(this, _element)
|
|
468
|
-
};
|
|
469
|
-
const virtualEl = {
|
|
470
|
-
contextElement: dom,
|
|
471
|
-
getBoundingClientRect: () => {
|
|
472
|
-
if (__privateGet$4(this, _getPosition))
|
|
473
|
-
return __privateGet$4(this, _getPosition).call(this, deriveContext);
|
|
474
|
-
return dom.getBoundingClientRect();
|
|
475
|
-
}
|
|
476
|
-
};
|
|
477
|
-
const middleware = [flip()];
|
|
478
|
-
if (__privateGet$4(this, _getOffset)) {
|
|
479
|
-
const offsetOption = __privateGet$4(this, _getOffset).call(this, deriveContext);
|
|
480
|
-
const offsetExt = offset(offsetOption);
|
|
481
|
-
middleware.push(offsetExt);
|
|
482
|
-
}
|
|
483
|
-
computePosition(virtualEl, __privateGet$4(this, _element), {
|
|
484
|
-
placement: __privateGet$4(this, _getPlacement) ? __privateGet$4(this, _getPlacement).call(this, deriveContext) : "left",
|
|
485
|
-
middleware
|
|
486
|
-
}).then(({ x, y }) => {
|
|
487
|
-
Object.assign(__privateGet$4(this, _element).style, {
|
|
488
|
-
left: `${x}px`,
|
|
489
|
-
top: `${y}px`
|
|
490
|
-
});
|
|
491
|
-
__privateGet$4(this, _element).dataset.show = "true";
|
|
492
|
-
});
|
|
493
|
-
};
|
|
494
|
-
/// Hide the block.
|
|
495
|
-
this.hide = () => {
|
|
496
|
-
__privateGet$4(this, _element).dataset.show = "false";
|
|
497
|
-
setTimeout(() => {
|
|
498
|
-
Object.assign(__privateGet$4(this, _element).style, {
|
|
499
|
-
left: `-999px`,
|
|
500
|
-
top: `-999px`
|
|
501
|
-
});
|
|
502
|
-
}, 200);
|
|
503
|
-
};
|
|
504
|
-
__privateSet$4(this, _ctx$1, options.ctx);
|
|
505
|
-
__privateSet$4(this, _element, options.content);
|
|
506
|
-
__privateSet$4(this, _getOffset, options.getOffset);
|
|
507
|
-
__privateSet$4(this, _getPosition, options.getPosition);
|
|
508
|
-
__privateSet$4(this, _getPlacement, options.getPlacement);
|
|
509
|
-
this.hide();
|
|
510
|
-
}
|
|
511
|
-
/// The context of current active node.
|
|
512
|
-
get active() {
|
|
513
|
-
return __privateGet$4(this, _activeNode);
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
_element = new WeakMap();
|
|
517
|
-
_ctx$1 = new WeakMap();
|
|
518
|
-
_service = new WeakMap();
|
|
519
|
-
_activeNode = new WeakMap();
|
|
520
|
-
_initialized$1 = new WeakMap();
|
|
521
|
-
_getOffset = new WeakMap();
|
|
522
|
-
_getPosition = new WeakMap();
|
|
523
|
-
_getPlacement = new WeakMap();
|
|
524
|
-
_BlockProvider_instances = new WeakSet();
|
|
525
|
-
/// @internal
|
|
526
|
-
init_fn = function() {
|
|
527
|
-
var _a;
|
|
528
|
-
const view = __privateGet$4(this, _ctx$1).get(editorViewCtx);
|
|
529
|
-
(_a = view.dom.parentElement) == null ? void 0 : _a.appendChild(__privateGet$4(this, _element));
|
|
530
|
-
const service = __privateGet$4(this, _ctx$1).get(blockService.key);
|
|
531
|
-
service.bind(__privateGet$4(this, _ctx$1), (message) => {
|
|
532
|
-
if (message.type === "hide") {
|
|
533
|
-
this.hide();
|
|
534
|
-
__privateSet$4(this, _activeNode, null);
|
|
535
|
-
} else if (message.type === "show") {
|
|
536
|
-
this.show(message.active);
|
|
537
|
-
__privateSet$4(this, _activeNode, message.active);
|
|
538
|
-
}
|
|
539
|
-
});
|
|
540
|
-
__privateSet$4(this, _service, service);
|
|
541
|
-
__privateGet$4(this, _service).addEvent(__privateGet$4(this, _element));
|
|
542
|
-
__privateGet$4(this, _element).draggable = true;
|
|
543
|
-
};
|
|
544
|
-
|
|
545
|
-
const block = [blockSpec, blockConfig, blockService, blockPlugin];
|
|
546
|
-
block.key = blockSpec.key;
|
|
547
|
-
block.pluginKey = blockPlugin.key;
|
|
548
|
-
|
|
549
|
-
function slashFactory(id) {
|
|
550
|
-
const slashSpec = $ctx({}, `${id}_SLASH_SPEC`);
|
|
551
|
-
const slashPlugin = $prose((ctx) => {
|
|
552
|
-
const spec = ctx.get(slashSpec.key);
|
|
553
|
-
return new Plugin({
|
|
554
|
-
key: new PluginKey(`${id}_SLASH`),
|
|
555
|
-
...spec
|
|
556
|
-
});
|
|
557
|
-
});
|
|
558
|
-
const result = [slashSpec, slashPlugin];
|
|
559
|
-
result.key = slashSpec.key;
|
|
560
|
-
result.pluginKey = slashPlugin.key;
|
|
561
|
-
slashSpec.meta = {
|
|
562
|
-
package: "@milkdown/plugin-slash",
|
|
563
|
-
displayName: `Ctx<slashSpec>|${id}`
|
|
564
|
-
};
|
|
565
|
-
slashPlugin.meta = {
|
|
566
|
-
package: "@milkdown/plugin-slash",
|
|
567
|
-
displayName: `Prose<slash>|${id}`
|
|
568
|
-
};
|
|
569
|
-
return result;
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
var __typeError$3 = (msg) => {
|
|
573
|
-
throw TypeError(msg);
|
|
574
|
-
};
|
|
575
|
-
var __accessCheck$3 = (obj, member, msg) => member.has(obj) || __typeError$3("Cannot " + msg);
|
|
576
|
-
var __privateGet$3 = (obj, member, getter) => (__accessCheck$3(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
577
|
-
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);
|
|
578
|
-
var __privateSet$3 = (obj, member, value, setter) => (__accessCheck$3(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
579
|
-
var __privateMethod = (obj, member, method) => (__accessCheck$3(obj, member, "access private method"), method);
|
|
580
|
-
var _initialized, _debounce, _trigger, _shouldShow, _offset, _onUpdate, _SlashProvider_instances, _shouldShow_fn;
|
|
581
|
-
class SlashProvider {
|
|
582
|
-
constructor(options) {
|
|
583
|
-
__privateAdd$3(this, _SlashProvider_instances);
|
|
584
|
-
/// @internal
|
|
585
|
-
__privateAdd$3(this, _initialized, false);
|
|
586
|
-
/// @internal
|
|
587
|
-
__privateAdd$3(this, _debounce);
|
|
588
|
-
/// @internal
|
|
589
|
-
__privateAdd$3(this, _trigger);
|
|
590
|
-
/// @internal
|
|
591
|
-
__privateAdd$3(this, _shouldShow);
|
|
592
|
-
/// The offset to get the block. Default is 0.
|
|
593
|
-
__privateAdd$3(this, _offset);
|
|
594
|
-
/// On show callback.
|
|
595
|
-
this.onShow = () => {
|
|
596
|
-
};
|
|
597
|
-
/// On hide callback.
|
|
598
|
-
this.onHide = () => {
|
|
599
|
-
};
|
|
600
|
-
/// @internal
|
|
601
|
-
__privateAdd$3(this, _onUpdate, (view, prevState) => {
|
|
602
|
-
var _a;
|
|
603
|
-
const { state, composing } = view;
|
|
604
|
-
const { selection, doc } = state;
|
|
605
|
-
const { ranges } = selection;
|
|
606
|
-
const from = Math.min(...ranges.map((range) => range.$from.pos));
|
|
607
|
-
const to = Math.max(...ranges.map((range) => range.$to.pos));
|
|
608
|
-
const isSame = prevState && prevState.doc.eq(doc) && prevState.selection.eq(selection);
|
|
609
|
-
if (!__privateGet$3(this, _initialized)) {
|
|
610
|
-
(_a = view.dom.parentElement) == null ? void 0 : _a.appendChild(this.element);
|
|
611
|
-
__privateSet$3(this, _initialized, true);
|
|
612
|
-
}
|
|
613
|
-
if (composing || isSame)
|
|
614
|
-
return;
|
|
615
|
-
if (!__privateGet$3(this, _shouldShow).call(this, view, prevState)) {
|
|
616
|
-
this.hide();
|
|
617
|
-
return;
|
|
618
|
-
}
|
|
619
|
-
const virtualEl = {
|
|
620
|
-
getBoundingClientRect: () => posToDOMRect(view, from, to)
|
|
621
|
-
};
|
|
622
|
-
computePosition(virtualEl, this.element, {
|
|
623
|
-
placement: "bottom-start",
|
|
624
|
-
middleware: [flip(), offset(__privateGet$3(this, _offset))]
|
|
625
|
-
}).then(({ x, y }) => {
|
|
626
|
-
Object.assign(this.element.style, {
|
|
627
|
-
left: `${x}px`,
|
|
628
|
-
top: `${y}px`
|
|
629
|
-
});
|
|
630
|
-
});
|
|
631
|
-
this.show();
|
|
632
|
-
});
|
|
633
|
-
/// Update provider state by editor view.
|
|
634
|
-
this.update = (view, prevState) => {
|
|
635
|
-
const updater = debounce(__privateGet$3(this, _onUpdate), __privateGet$3(this, _debounce));
|
|
636
|
-
updater(view, prevState);
|
|
637
|
-
};
|
|
638
|
-
/// Get the content of the current text block.
|
|
639
|
-
/// Pass the `matchNode` function to determine whether the current node should be matched, by default, it will match the paragraph node.
|
|
640
|
-
this.getContent = (view, matchNode = (node) => node.type.name === "paragraph") => {
|
|
641
|
-
const { selection } = view.state;
|
|
642
|
-
const { empty, $from } = selection;
|
|
643
|
-
const isTextBlock = view.state.selection instanceof TextSelection;
|
|
644
|
-
const isSlashChildren = this.element.contains(document.activeElement);
|
|
645
|
-
const notHasFocus = !view.hasFocus() && !isSlashChildren;
|
|
646
|
-
const isReadonly = !view.editable;
|
|
647
|
-
const paragraph = findParentNode(matchNode)(view.state.selection);
|
|
648
|
-
const isNotInParagraph = !paragraph;
|
|
649
|
-
if (notHasFocus || isReadonly || !empty || !isTextBlock || isNotInParagraph)
|
|
650
|
-
return;
|
|
651
|
-
return $from.parent.textBetween(Math.max(0, $from.parentOffset - 500), $from.parentOffset, void 0, "\uFFFC");
|
|
652
|
-
};
|
|
653
|
-
/// Destroy the slash.
|
|
654
|
-
this.destroy = () => {
|
|
655
|
-
};
|
|
656
|
-
/// Show the slash.
|
|
657
|
-
this.show = () => {
|
|
658
|
-
this.element.dataset.show = "true";
|
|
659
|
-
this.onShow();
|
|
660
|
-
};
|
|
661
|
-
/// Hide the slash.
|
|
662
|
-
this.hide = () => {
|
|
663
|
-
this.element.dataset.show = "false";
|
|
664
|
-
this.onHide();
|
|
665
|
-
};
|
|
666
|
-
var _a, _b, _c;
|
|
667
|
-
this.element = options.content;
|
|
668
|
-
__privateSet$3(this, _debounce, (_a = options.debounce) != null ? _a : 200);
|
|
669
|
-
__privateSet$3(this, _shouldShow, (_b = options.shouldShow) != null ? _b : __privateMethod(this, _SlashProvider_instances, _shouldShow_fn));
|
|
670
|
-
__privateSet$3(this, _trigger, (_c = options.trigger) != null ? _c : "/");
|
|
671
|
-
__privateSet$3(this, _offset, options.offset);
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
_initialized = new WeakMap();
|
|
675
|
-
_debounce = new WeakMap();
|
|
676
|
-
_trigger = new WeakMap();
|
|
677
|
-
_shouldShow = new WeakMap();
|
|
678
|
-
_offset = new WeakMap();
|
|
679
|
-
_onUpdate = new WeakMap();
|
|
680
|
-
_SlashProvider_instances = new WeakSet();
|
|
681
|
-
/// @internal
|
|
682
|
-
_shouldShow_fn = function(view) {
|
|
683
|
-
const currentTextBlockContent = this.getContent(view);
|
|
684
|
-
if (!currentTextBlockContent)
|
|
685
|
-
return false;
|
|
686
|
-
const target = currentTextBlockContent.at(-1);
|
|
687
|
-
if (!target)
|
|
688
|
-
return false;
|
|
689
|
-
return Array.isArray(__privateGet$3(this, _trigger)) ? __privateGet$3(this, _trigger).includes(target) : __privateGet$3(this, _trigger) === target;
|
|
690
|
-
};
|
|
691
|
-
|
|
692
|
-
function clearRange(tr) {
|
|
693
|
-
const { $from, $to } = tr.selection;
|
|
694
|
-
const { pos: from } = $from;
|
|
695
|
-
const { pos: to } = $to;
|
|
696
|
-
tr = tr.deleteRange(from - $from.node().content.size, to);
|
|
697
|
-
return tr;
|
|
698
|
-
}
|
|
699
|
-
function setBlockType(tr, nodeType, attrs = null) {
|
|
700
|
-
const { from, to } = tr.selection;
|
|
701
|
-
return tr.setBlockType(from, to, nodeType, attrs);
|
|
702
|
-
}
|
|
703
|
-
function wrapInBlockType(tr, nodeType, attrs = null) {
|
|
704
|
-
const { $from, $to } = tr.selection;
|
|
705
|
-
const range = $from.blockRange($to);
|
|
706
|
-
const wrapping = range && findWrapping(range, nodeType, attrs);
|
|
707
|
-
if (!wrapping)
|
|
708
|
-
return null;
|
|
709
|
-
return tr.wrap(range, wrapping);
|
|
710
|
-
}
|
|
711
|
-
function addBlockType(tr, nodeType, attrs = null) {
|
|
712
|
-
const node = nodeType.createAndFill(attrs);
|
|
713
|
-
if (!node)
|
|
714
|
-
return null;
|
|
715
|
-
return tr.replaceSelectionWith(node);
|
|
716
|
-
}
|
|
717
|
-
function clearContentAndSetBlockType(nodeType, attrs = null) {
|
|
718
|
-
return (state, dispatch) => {
|
|
719
|
-
if (dispatch) {
|
|
720
|
-
const tr = setBlockType(clearRange(state.tr), nodeType, attrs);
|
|
721
|
-
dispatch(tr.scrollIntoView());
|
|
722
|
-
}
|
|
723
|
-
return true;
|
|
724
|
-
};
|
|
725
|
-
}
|
|
726
|
-
function clearContentAndWrapInBlockType(nodeType, attrs = null) {
|
|
727
|
-
return (state, dispatch) => {
|
|
728
|
-
const tr = wrapInBlockType(clearRange(state.tr), nodeType, attrs);
|
|
729
|
-
if (!tr)
|
|
730
|
-
return false;
|
|
731
|
-
if (dispatch)
|
|
732
|
-
dispatch(tr.scrollIntoView());
|
|
733
|
-
return true;
|
|
734
|
-
};
|
|
735
|
-
}
|
|
736
|
-
function clearContentAndAddBlockType(nodeType, attrs = null) {
|
|
737
|
-
return (state, dispatch) => {
|
|
738
|
-
const tr = addBlockType(clearRange(state.tr), nodeType, attrs);
|
|
739
|
-
if (!tr)
|
|
740
|
-
return false;
|
|
741
|
-
if (dispatch)
|
|
742
|
-
dispatch(tr.scrollIntoView());
|
|
743
|
-
return true;
|
|
744
|
-
};
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
var __typeError$2 = (msg) => {
|
|
748
|
-
throw TypeError(msg);
|
|
749
|
-
};
|
|
750
|
-
var __accessCheck$2 = (obj, member, msg) => member.has(obj) || __typeError$2("Cannot " + msg);
|
|
751
|
-
var __privateGet$2 = (obj, member, getter) => (__accessCheck$2(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
752
|
-
var __privateAdd$2 = (obj, member, value) => member.has(obj) ? __typeError$2("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
753
|
-
var __privateSet$2 = (obj, member, value, setter) => (__accessCheck$2(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
754
|
-
var _groups, _getGroupInstance;
|
|
755
|
-
class GroupBuilder {
|
|
756
|
-
constructor() {
|
|
757
|
-
__privateAdd$2(this, _groups, []);
|
|
758
|
-
this.clear = () => {
|
|
759
|
-
__privateSet$2(this, _groups, []);
|
|
760
|
-
return this;
|
|
761
|
-
};
|
|
762
|
-
__privateAdd$2(this, _getGroupInstance, (group) => {
|
|
763
|
-
const groupInstance = {
|
|
764
|
-
group,
|
|
765
|
-
addItem: (key, item) => {
|
|
766
|
-
const data = { key, ...item };
|
|
767
|
-
group.items.push(data);
|
|
768
|
-
return groupInstance;
|
|
769
|
-
},
|
|
770
|
-
clear: () => {
|
|
771
|
-
group.items = [];
|
|
772
|
-
return groupInstance;
|
|
773
|
-
}
|
|
774
|
-
};
|
|
775
|
-
return groupInstance;
|
|
776
|
-
});
|
|
777
|
-
this.addGroup = (key, label) => {
|
|
778
|
-
const items = [];
|
|
779
|
-
const group = {
|
|
780
|
-
key,
|
|
781
|
-
label,
|
|
782
|
-
items
|
|
783
|
-
};
|
|
784
|
-
__privateGet$2(this, _groups).push(group);
|
|
785
|
-
return __privateGet$2(this, _getGroupInstance).call(this, group);
|
|
786
|
-
};
|
|
787
|
-
this.getGroup = (key) => {
|
|
788
|
-
const group = __privateGet$2(this, _groups).find((group2) => group2.key === key);
|
|
789
|
-
if (!group)
|
|
790
|
-
throw new Error(`Group with key ${key} not found`);
|
|
791
|
-
return __privateGet$2(this, _getGroupInstance).call(this, group);
|
|
792
|
-
};
|
|
793
|
-
this.build = () => {
|
|
794
|
-
return __privateGet$2(this, _groups);
|
|
795
|
-
};
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
_groups = new WeakMap();
|
|
799
|
-
_getGroupInstance = new WeakMap();
|
|
800
|
-
|
|
801
|
-
function getGroups(filter, config) {
|
|
802
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W;
|
|
803
|
-
const groupBuilder = new GroupBuilder();
|
|
804
|
-
groupBuilder.addGroup("text", (_a = config == null ? void 0 : config.slashMenuTextGroupLabel) != null ? _a : "Text").addItem("text", {
|
|
805
|
-
label: (_b = config == null ? void 0 : config.slashMenuTextGroupLabel) != null ? _b : "Text",
|
|
806
|
-
icon: (_d = (_c = config == null ? void 0 : config.slashMenuTextIcon) == null ? void 0 : _c.call(config)) != null ? _d : textIcon,
|
|
807
|
-
onRun: (ctx) => {
|
|
808
|
-
const view = ctx.get(editorViewCtx);
|
|
809
|
-
const { dispatch, state } = view;
|
|
810
|
-
const command = clearContentAndSetBlockType(paragraphSchema.type(ctx));
|
|
811
|
-
command(state, dispatch);
|
|
812
|
-
}
|
|
813
|
-
}).addItem("h1", {
|
|
814
|
-
label: (_e = config == null ? void 0 : config.slashMenuH1Label) != null ? _e : "Heading 1",
|
|
815
|
-
icon: (_g = (_f = config == null ? void 0 : config.slashMenuH1Icon) == null ? void 0 : _f.call(config)) != null ? _g : h1Icon,
|
|
816
|
-
onRun: (ctx) => {
|
|
817
|
-
const view = ctx.get(editorViewCtx);
|
|
818
|
-
const { dispatch, state } = view;
|
|
819
|
-
const command = clearContentAndSetBlockType(headingSchema.type(ctx), { level: 1 });
|
|
820
|
-
command(state, dispatch);
|
|
821
|
-
}
|
|
822
|
-
}).addItem("h2", {
|
|
823
|
-
label: (_h = config == null ? void 0 : config.slashMenuH2Label) != null ? _h : "Heading 2",
|
|
824
|
-
icon: (_j = (_i = config == null ? void 0 : config.slashMenuH2Icon) == null ? void 0 : _i.call(config)) != null ? _j : h2Icon,
|
|
825
|
-
onRun: (ctx) => {
|
|
826
|
-
const view = ctx.get(editorViewCtx);
|
|
827
|
-
const { dispatch, state } = view;
|
|
828
|
-
const command = clearContentAndSetBlockType(headingSchema.type(ctx), { level: 2 });
|
|
829
|
-
command(state, dispatch);
|
|
830
|
-
}
|
|
831
|
-
}).addItem("h3", {
|
|
832
|
-
label: (_k = config == null ? void 0 : config.slashMenuH3Label) != null ? _k : "Heading 3",
|
|
833
|
-
icon: (_m = (_l = config == null ? void 0 : config.slashMenuH3Icon) == null ? void 0 : _l.call(config)) != null ? _m : h3Icon,
|
|
834
|
-
onRun: (ctx) => {
|
|
835
|
-
const view = ctx.get(editorViewCtx);
|
|
836
|
-
const { dispatch, state } = view;
|
|
837
|
-
const command = clearContentAndSetBlockType(headingSchema.type(ctx), { level: 3 });
|
|
838
|
-
command(state, dispatch);
|
|
839
|
-
}
|
|
840
|
-
}).addItem("h4", {
|
|
841
|
-
label: (_n = config == null ? void 0 : config.slashMenuH4Label) != null ? _n : "Heading 4",
|
|
842
|
-
icon: (_p = (_o = config == null ? void 0 : config.slashMenuH4Icon) == null ? void 0 : _o.call(config)) != null ? _p : h4Icon,
|
|
843
|
-
onRun: (ctx) => {
|
|
844
|
-
const view = ctx.get(editorViewCtx);
|
|
845
|
-
const { dispatch, state } = view;
|
|
846
|
-
const command = clearContentAndSetBlockType(headingSchema.type(ctx), { level: 4 });
|
|
847
|
-
command(state, dispatch);
|
|
848
|
-
}
|
|
849
|
-
}).addItem("h5", {
|
|
850
|
-
label: (_q = config == null ? void 0 : config.slashMenuH5Label) != null ? _q : "Heading 5",
|
|
851
|
-
icon: (_s = (_r = config == null ? void 0 : config.slashMenuH5Icon) == null ? void 0 : _r.call(config)) != null ? _s : h5Icon,
|
|
852
|
-
onRun: (ctx) => {
|
|
853
|
-
const view = ctx.get(editorViewCtx);
|
|
854
|
-
const { dispatch, state } = view;
|
|
855
|
-
const command = clearContentAndSetBlockType(headingSchema.type(ctx), { level: 5 });
|
|
856
|
-
command(state, dispatch);
|
|
857
|
-
}
|
|
858
|
-
}).addItem("h6", {
|
|
859
|
-
label: (_t = config == null ? void 0 : config.slashMenuH6Label) != null ? _t : "Heading 6",
|
|
860
|
-
icon: (_v = (_u = config == null ? void 0 : config.slashMenuH6Icon) == null ? void 0 : _u.call(config)) != null ? _v : h6Icon,
|
|
861
|
-
onRun: (ctx) => {
|
|
862
|
-
const view = ctx.get(editorViewCtx);
|
|
863
|
-
const { dispatch, state } = view;
|
|
864
|
-
const command = clearContentAndSetBlockType(headingSchema.type(ctx), { level: 6 });
|
|
865
|
-
command(state, dispatch);
|
|
866
|
-
}
|
|
867
|
-
}).addItem("quote", {
|
|
868
|
-
label: (_w = config == null ? void 0 : config.slashMenuQuoteLabel) != null ? _w : "Quote",
|
|
869
|
-
icon: (_y = (_x = config == null ? void 0 : config.slashMenuQuoteIcon) == null ? void 0 : _x.call(config)) != null ? _y : quoteIcon,
|
|
870
|
-
onRun: (ctx) => {
|
|
871
|
-
const view = ctx.get(editorViewCtx);
|
|
872
|
-
const { dispatch, state } = view;
|
|
873
|
-
const command = clearContentAndWrapInBlockType(blockquoteSchema.type(ctx));
|
|
874
|
-
command(state, dispatch);
|
|
875
|
-
}
|
|
876
|
-
}).addItem("divider", {
|
|
877
|
-
label: (_z = config == null ? void 0 : config.slashMenuDividerLabel) != null ? _z : "Divider",
|
|
878
|
-
icon: (_B = (_A = config == null ? void 0 : config.slashMenuDividerIcon) == null ? void 0 : _A.call(config)) != null ? _B : dividerIcon,
|
|
879
|
-
onRun: (ctx) => {
|
|
880
|
-
const view = ctx.get(editorViewCtx);
|
|
881
|
-
const { dispatch, state } = view;
|
|
882
|
-
const command = clearContentAndAddBlockType(hrSchema.type(ctx));
|
|
883
|
-
command(state, dispatch);
|
|
884
|
-
}
|
|
885
|
-
});
|
|
886
|
-
groupBuilder.addGroup("list", (_C = config == null ? void 0 : config.slashMenuListGroupLabel) != null ? _C : "List").addItem("bullet-list", {
|
|
887
|
-
label: (_D = config == null ? void 0 : config.slashMenuBulletListLabel) != null ? _D : "Bullet List",
|
|
888
|
-
icon: (_F = (_E = config == null ? void 0 : config.slashMenuBulletListIcon) == null ? void 0 : _E.call(config)) != null ? _F : bulletListIcon,
|
|
889
|
-
onRun: (ctx) => {
|
|
890
|
-
const view = ctx.get(editorViewCtx);
|
|
891
|
-
const { dispatch, state } = view;
|
|
892
|
-
const command = clearContentAndWrapInBlockType(bulletListSchema.type(ctx));
|
|
893
|
-
command(state, dispatch);
|
|
894
|
-
}
|
|
895
|
-
}).addItem("ordered-list", {
|
|
896
|
-
label: (_G = config == null ? void 0 : config.slashMenuOrderedListLabel) != null ? _G : "Ordered List",
|
|
897
|
-
icon: (_I = (_H = config == null ? void 0 : config.slashMenuOrderedListIcon) == null ? void 0 : _H.call(config)) != null ? _I : orderedListIcon,
|
|
898
|
-
onRun: (ctx) => {
|
|
899
|
-
const view = ctx.get(editorViewCtx);
|
|
900
|
-
const { dispatch, state } = view;
|
|
901
|
-
const command = clearContentAndWrapInBlockType(orderedListSchema.type(ctx));
|
|
902
|
-
command(state, dispatch);
|
|
903
|
-
}
|
|
904
|
-
}).addItem("todo-list", {
|
|
905
|
-
label: (_J = config == null ? void 0 : config.slashMenuTaskListLabel) != null ? _J : "Todo List",
|
|
906
|
-
icon: (_L = (_K = config == null ? void 0 : config.slashMenuTaskListIcon) == null ? void 0 : _K.call(config)) != null ? _L : todoListIcon,
|
|
907
|
-
onRun: (ctx) => {
|
|
908
|
-
const view = ctx.get(editorViewCtx);
|
|
909
|
-
const { dispatch, state } = view;
|
|
910
|
-
const command = clearContentAndWrapInBlockType(listItemSchema.type(ctx), { checked: false });
|
|
911
|
-
command(state, dispatch);
|
|
912
|
-
}
|
|
913
|
-
});
|
|
914
|
-
groupBuilder.addGroup("advanced", (_M = config == null ? void 0 : config.slashMenuAdvancedGroupLabel) != null ? _M : "Advanced").addItem("image", {
|
|
915
|
-
label: (_N = config == null ? void 0 : config.slashMenuImageLabel) != null ? _N : "Image",
|
|
916
|
-
icon: (_P = (_O = config == null ? void 0 : config.slashMenuImageIcon) == null ? void 0 : _O.call(config)) != null ? _P : imageIcon,
|
|
917
|
-
onRun: (ctx) => {
|
|
918
|
-
const view = ctx.get(editorViewCtx);
|
|
919
|
-
const { dispatch, state } = view;
|
|
920
|
-
const command = clearContentAndAddBlockType(imageBlockSchema.type(ctx));
|
|
921
|
-
command(state, dispatch);
|
|
922
|
-
}
|
|
923
|
-
}).addItem("code", {
|
|
924
|
-
label: (_Q = config == null ? void 0 : config.slashMenuCodeBlockLabel) != null ? _Q : "Code",
|
|
925
|
-
icon: (_S = (_R = config == null ? void 0 : config.slashMenuCodeBlockIcon) == null ? void 0 : _R.call(config)) != null ? _S : codeIcon,
|
|
926
|
-
onRun: (ctx) => {
|
|
927
|
-
const view = ctx.get(editorViewCtx);
|
|
928
|
-
const { dispatch, state } = view;
|
|
929
|
-
const command = clearContentAndAddBlockType(codeBlockSchema.type(ctx));
|
|
930
|
-
command(state, dispatch);
|
|
931
|
-
}
|
|
932
|
-
}).addItem("table", {
|
|
933
|
-
label: (_T = config == null ? void 0 : config.slashMenuTableLabel) != null ? _T : "Table",
|
|
934
|
-
icon: (_V = (_U = config == null ? void 0 : config.slashMenuTableIcon) == null ? void 0 : _U.call(config)) != null ? _V : tableIcon,
|
|
935
|
-
onRun: (ctx) => {
|
|
936
|
-
const view = ctx.get(editorViewCtx);
|
|
937
|
-
const { dispatch, state } = view;
|
|
938
|
-
const tr = clearRange(state.tr);
|
|
939
|
-
const table = createTable(ctx, 3, 3);
|
|
940
|
-
tr.replaceSelectionWith(table);
|
|
941
|
-
const { from } = tr.selection;
|
|
942
|
-
const pos = from - table.nodeSize + 2;
|
|
943
|
-
dispatch(tr);
|
|
944
|
-
requestAnimationFrame(() => {
|
|
945
|
-
const selection = NodeSelection.create(view.state.tr.doc, pos);
|
|
946
|
-
dispatch(view.state.tr.setSelection(selection).scrollIntoView());
|
|
947
|
-
});
|
|
948
|
-
}
|
|
949
|
-
});
|
|
950
|
-
(_W = config == null ? void 0 : config.buildMenu) == null ? void 0 : _W.call(config, groupBuilder);
|
|
951
|
-
let groups = groupBuilder.build();
|
|
952
|
-
if (filter) {
|
|
953
|
-
groups = groups.map((group) => {
|
|
954
|
-
const items2 = group.items.filter((item) => item.label.toLowerCase().includes(filter.toLowerCase()));
|
|
955
|
-
return {
|
|
956
|
-
...group,
|
|
957
|
-
items: items2
|
|
958
|
-
};
|
|
959
|
-
}).filter((group) => group.items.length > 0);
|
|
960
|
-
}
|
|
961
|
-
const items = groups.flatMap((groups2) => groups2.items);
|
|
962
|
-
items.forEach((item, index) => {
|
|
963
|
-
Object.assign(item, { index });
|
|
964
|
-
});
|
|
965
|
-
groups.reduce((acc, group) => {
|
|
966
|
-
const end = acc + group.items.length;
|
|
967
|
-
Object.assign(group, {
|
|
968
|
-
range: [acc, end]
|
|
969
|
-
});
|
|
970
|
-
return end;
|
|
971
|
-
}, 0);
|
|
972
|
-
return {
|
|
973
|
-
groups,
|
|
974
|
-
size: items.length
|
|
975
|
-
};
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
const menuComponent = ({
|
|
979
|
-
show,
|
|
980
|
-
hide,
|
|
981
|
-
ctx,
|
|
982
|
-
filter,
|
|
983
|
-
config
|
|
984
|
-
}) => {
|
|
985
|
-
const { groups, size } = useMemo(() => getGroups(filter, config), [filter]);
|
|
986
|
-
const host = useHost();
|
|
987
|
-
const [hoverIndex, setHoverIndex] = useState(0);
|
|
988
|
-
const root = useMemo(() => host.current.getRootNode(), [host]);
|
|
989
|
-
const prevMousePosition = useRef({ x: -999, y: -999 });
|
|
990
|
-
const onMouseMove = useCallback((e) => {
|
|
991
|
-
const prevPos = prevMousePosition.current;
|
|
992
|
-
if (!prevPos)
|
|
993
|
-
return;
|
|
994
|
-
const { x, y } = e;
|
|
995
|
-
prevPos.x = x;
|
|
996
|
-
prevPos.y = y;
|
|
997
|
-
}, []);
|
|
998
|
-
useEffect(() => {
|
|
999
|
-
if (size === 0 && show)
|
|
1000
|
-
hide == null ? void 0 : hide();
|
|
1001
|
-
}, [size, show]);
|
|
1002
|
-
const onHover = useCallback((index, after) => {
|
|
1003
|
-
setHoverIndex((prev) => {
|
|
1004
|
-
const next = typeof index === "function" ? index(prev) : index;
|
|
1005
|
-
after == null ? void 0 : after(next);
|
|
1006
|
-
return next;
|
|
1007
|
-
});
|
|
1008
|
-
}, []);
|
|
1009
|
-
const scrollToIndex = useCallback((index) => {
|
|
1010
|
-
const target = host.current.querySelector(`[data-index="${index}"]`);
|
|
1011
|
-
const scrollRoot = host.current.querySelector(".menu-groups");
|
|
1012
|
-
if (!target || !scrollRoot)
|
|
1013
|
-
return;
|
|
1014
|
-
scrollRoot.scrollTop = target.offsetTop - scrollRoot.offsetTop;
|
|
1015
|
-
}, []);
|
|
1016
|
-
const runByIndex = useCallback((index) => {
|
|
1017
|
-
const item = groups.flatMap((group) => group.items).at(index);
|
|
1018
|
-
if (item && ctx)
|
|
1019
|
-
item.onRun(ctx);
|
|
1020
|
-
hide == null ? void 0 : hide();
|
|
1021
|
-
}, [groups]);
|
|
1022
|
-
const onKeydown = useCallback((e) => {
|
|
1023
|
-
if (e.key === "Escape") {
|
|
1024
|
-
e.preventDefault();
|
|
1025
|
-
hide == null ? void 0 : hide();
|
|
1026
|
-
return;
|
|
1027
|
-
}
|
|
1028
|
-
if (e.key === "ArrowDown") {
|
|
1029
|
-
e.preventDefault();
|
|
1030
|
-
return onHover((index) => index < size - 1 ? index + 1 : index, scrollToIndex);
|
|
1031
|
-
}
|
|
1032
|
-
if (e.key === "ArrowUp") {
|
|
1033
|
-
e.preventDefault();
|
|
1034
|
-
return onHover((index) => index <= 0 ? index : index - 1, scrollToIndex);
|
|
1035
|
-
}
|
|
1036
|
-
if (e.key === "ArrowLeft") {
|
|
1037
|
-
e.preventDefault();
|
|
1038
|
-
return onHover((index) => {
|
|
1039
|
-
const group = groups.find((group2) => group2.range[0] <= index && group2.range[1] > index);
|
|
1040
|
-
if (!group)
|
|
1041
|
-
return index;
|
|
1042
|
-
const prevGroup = groups[groups.indexOf(group) - 1];
|
|
1043
|
-
if (!prevGroup)
|
|
1044
|
-
return index;
|
|
1045
|
-
return prevGroup.range[1] - 1;
|
|
1046
|
-
}, scrollToIndex);
|
|
1047
|
-
}
|
|
1048
|
-
if (e.key === "ArrowRight") {
|
|
1049
|
-
e.preventDefault();
|
|
1050
|
-
return onHover((index) => {
|
|
1051
|
-
const group = groups.find((group2) => group2.range[0] <= index && group2.range[1] > index);
|
|
1052
|
-
if (!group)
|
|
1053
|
-
return index;
|
|
1054
|
-
const nextGroup = groups[groups.indexOf(group) + 1];
|
|
1055
|
-
if (!nextGroup)
|
|
1056
|
-
return index;
|
|
1057
|
-
return nextGroup.range[0];
|
|
1058
|
-
}, scrollToIndex);
|
|
1059
|
-
}
|
|
1060
|
-
if (e.key === "Enter") {
|
|
1061
|
-
e.preventDefault();
|
|
1062
|
-
runByIndex(hoverIndex);
|
|
1063
|
-
}
|
|
1064
|
-
}, [hide, groups, hoverIndex]);
|
|
1065
|
-
const onMouseEnter = useCallback((index) => {
|
|
1066
|
-
return (e) => {
|
|
1067
|
-
const prevPos = prevMousePosition.current;
|
|
1068
|
-
if (!prevPos)
|
|
1069
|
-
return;
|
|
1070
|
-
const { x, y } = e;
|
|
1071
|
-
if (x === prevPos.x && y === prevPos.y)
|
|
1072
|
-
return;
|
|
1073
|
-
onHover(index);
|
|
1074
|
-
};
|
|
1075
|
-
}, []);
|
|
1076
|
-
useEffect(() => {
|
|
1077
|
-
if (show)
|
|
1078
|
-
root.addEventListener("keydown", onKeydown, { capture: true });
|
|
1079
|
-
else root.removeEventListener("keydown", onKeydown, { capture: true });
|
|
1080
|
-
return () => {
|
|
1081
|
-
root.removeEventListener("keydown", onKeydown, { capture: true });
|
|
1082
|
-
};
|
|
1083
|
-
}, [show, onKeydown]);
|
|
1084
|
-
return html`
|
|
1085
|
-
<host onmousedown=${(e) => e.preventDefault()}>
|
|
1086
|
-
<nav class="tab-group">
|
|
1087
|
-
<ul>
|
|
1088
|
-
${groups.map((group) => html`<li
|
|
1089
|
-
key=${group.key}
|
|
1090
|
-
onmousedown=${() => onHover(group.range[0], scrollToIndex)}
|
|
1091
|
-
class=${hoverIndex >= group.range[0] && hoverIndex < group.range[1] ? "selected" : ""}
|
|
1092
|
-
>
|
|
1093
|
-
${group.label}
|
|
1094
|
-
</li>`)}
|
|
1095
|
-
</ul>
|
|
1096
|
-
</nav>
|
|
1097
|
-
<div class="menu-groups" onmousemove=${onMouseMove}>
|
|
1098
|
-
${groups.map((group) => {
|
|
1099
|
-
return html`
|
|
1100
|
-
<div key=${group.key} class="menu-group">
|
|
1101
|
-
<h6>${group.label}</h6>
|
|
1102
|
-
<ul>
|
|
1103
|
-
${group.items.map(
|
|
1104
|
-
(item) => html`<li
|
|
1105
|
-
key=${item.key}
|
|
1106
|
-
data-index=${item.index}
|
|
1107
|
-
class=${hoverIndex === item.index ? "hover" : ""}
|
|
1108
|
-
onmouseenter=${onMouseEnter(item.index)}
|
|
1109
|
-
onmousedown=${() => {
|
|
1110
|
-
var _a;
|
|
1111
|
-
(_a = host.current.querySelector(`[data-index="${item.index}"]`)) == null ? void 0 : _a.classList.add("active");
|
|
1112
|
-
}}
|
|
1113
|
-
onmouseup=${() => {
|
|
1114
|
-
var _a;
|
|
1115
|
-
(_a = host.current.querySelector(`[data-index="${item.index}"]`)) == null ? void 0 : _a.classList.remove("active");
|
|
1116
|
-
runByIndex(item.index);
|
|
1117
|
-
}}
|
|
1118
|
-
>
|
|
1119
|
-
${item.icon}
|
|
1120
|
-
<span>${item.label}</span>
|
|
1121
|
-
</li>`
|
|
1122
|
-
)}
|
|
1123
|
-
</ul>
|
|
1124
|
-
</div>
|
|
1125
|
-
`;
|
|
1126
|
-
})}
|
|
1127
|
-
</div>
|
|
1128
|
-
</host>
|
|
1129
|
-
`;
|
|
1130
|
-
};
|
|
1131
|
-
menuComponent.props = {
|
|
1132
|
-
ctx: Object,
|
|
1133
|
-
config: Object,
|
|
1134
|
-
show: Boolean,
|
|
1135
|
-
filter: String,
|
|
1136
|
-
hide: Function
|
|
1137
|
-
};
|
|
1138
|
-
const MenuElement = c(menuComponent);
|
|
1139
|
-
|
|
1140
|
-
var __typeError$1 = (msg) => {
|
|
1141
|
-
throw TypeError(msg);
|
|
1142
|
-
};
|
|
1143
|
-
var __accessCheck$1 = (obj, member, msg) => member.has(obj) || __typeError$1("Cannot " + msg);
|
|
1144
|
-
var __privateGet$1 = (obj, member, getter) => (__accessCheck$1(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
1145
|
-
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);
|
|
1146
|
-
var __privateSet$1 = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
1147
|
-
var _content$1, _slashProvider, _programmaticallyPos;
|
|
1148
|
-
const menu = slashFactory("CREPE_MENU");
|
|
1149
|
-
const menuAPI = $ctx({
|
|
1150
|
-
show: () => {
|
|
1151
|
-
},
|
|
1152
|
-
hide: () => {
|
|
1153
|
-
}
|
|
1154
|
-
}, "menuAPICtx");
|
|
1155
|
-
defIfNotExists("milkdown-slash-menu", MenuElement);
|
|
1156
|
-
function configureMenu(ctx, config) {
|
|
1157
|
-
ctx.set(menu.key, {
|
|
1158
|
-
view: (view) => new MenuView(ctx, view, config)
|
|
1159
|
-
});
|
|
1160
|
-
}
|
|
1161
|
-
class MenuView {
|
|
1162
|
-
constructor(ctx, view, config) {
|
|
1163
|
-
__privateAdd$1(this, _content$1);
|
|
1164
|
-
__privateAdd$1(this, _slashProvider);
|
|
1165
|
-
__privateAdd$1(this, _programmaticallyPos, null);
|
|
1166
|
-
this.update = (view) => {
|
|
1167
|
-
__privateGet$1(this, _slashProvider).update(view);
|
|
1168
|
-
};
|
|
1169
|
-
this.show = (pos) => {
|
|
1170
|
-
__privateSet$1(this, _programmaticallyPos, pos);
|
|
1171
|
-
__privateGet$1(this, _content$1).filter = "";
|
|
1172
|
-
__privateGet$1(this, _slashProvider).show();
|
|
1173
|
-
};
|
|
1174
|
-
this.hide = () => {
|
|
1175
|
-
__privateSet$1(this, _programmaticallyPos, null);
|
|
1176
|
-
__privateGet$1(this, _slashProvider).hide();
|
|
1177
|
-
};
|
|
1178
|
-
this.destroy = () => {
|
|
1179
|
-
__privateGet$1(this, _slashProvider).destroy();
|
|
1180
|
-
__privateGet$1(this, _content$1).remove();
|
|
1181
|
-
};
|
|
1182
|
-
__privateSet$1(this, _content$1, new MenuElement());
|
|
1183
|
-
__privateGet$1(this, _content$1).hide = this.hide;
|
|
1184
|
-
__privateGet$1(this, _content$1).ctx = ctx;
|
|
1185
|
-
__privateGet$1(this, _content$1).config = config;
|
|
1186
|
-
const self = this;
|
|
1187
|
-
__privateSet$1(this, _slashProvider, new SlashProvider({
|
|
1188
|
-
content: __privateGet$1(this, _content$1),
|
|
1189
|
-
debounce: 20,
|
|
1190
|
-
shouldShow(view2) {
|
|
1191
|
-
if (isInCodeBlock(view2.state.selection) || isInList(view2.state.selection))
|
|
1192
|
-
return false;
|
|
1193
|
-
const currentText = this.getContent(view2, (node) => ["paragraph", "heading"].includes(node.type.name));
|
|
1194
|
-
if (currentText == null)
|
|
1195
|
-
return false;
|
|
1196
|
-
const pos = __privateGet$1(self, _programmaticallyPos);
|
|
1197
|
-
__privateGet$1(self, _content$1).filter = currentText.startsWith("/") ? currentText.slice(1) : currentText;
|
|
1198
|
-
if (typeof pos === "number") {
|
|
1199
|
-
if (view2.state.doc.resolve(pos).node() !== view2.state.doc.resolve(view2.state.selection.from).node()) {
|
|
1200
|
-
__privateSet$1(self, _programmaticallyPos, null);
|
|
1201
|
-
return false;
|
|
1202
|
-
}
|
|
1203
|
-
return true;
|
|
1204
|
-
}
|
|
1205
|
-
if (!currentText.startsWith("/"))
|
|
1206
|
-
return false;
|
|
1207
|
-
return true;
|
|
1208
|
-
},
|
|
1209
|
-
offset: 10
|
|
1210
|
-
}));
|
|
1211
|
-
__privateGet$1(this, _slashProvider).onShow = () => {
|
|
1212
|
-
__privateGet$1(this, _content$1).show = true;
|
|
1213
|
-
};
|
|
1214
|
-
__privateGet$1(this, _slashProvider).onHide = () => {
|
|
1215
|
-
__privateGet$1(this, _content$1).show = false;
|
|
1216
|
-
};
|
|
1217
|
-
this.update(view);
|
|
1218
|
-
ctx.set(menuAPI.key, {
|
|
1219
|
-
show: (pos) => this.show(pos),
|
|
1220
|
-
hide: () => this.hide()
|
|
1221
|
-
});
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1224
|
-
_content$1 = new WeakMap();
|
|
1225
|
-
_slashProvider = new WeakMap();
|
|
1226
|
-
_programmaticallyPos = new WeakMap();
|
|
1227
|
-
|
|
1228
|
-
const blockHandleComponent = ({
|
|
1229
|
-
onAdd,
|
|
1230
|
-
addIcon,
|
|
1231
|
-
handleIcon
|
|
1232
|
-
}) => {
|
|
1233
|
-
const ref = useRef();
|
|
1234
|
-
useEffect(() => {
|
|
1235
|
-
var _a;
|
|
1236
|
-
(_a = ref.current) == null ? void 0 : _a.classList.remove("active");
|
|
1237
|
-
});
|
|
1238
|
-
const onMouseDown = (e) => {
|
|
1239
|
-
var _a;
|
|
1240
|
-
e.preventDefault();
|
|
1241
|
-
e.stopPropagation();
|
|
1242
|
-
(_a = ref.current) == null ? void 0 : _a.classList.add("active");
|
|
1243
|
-
};
|
|
1244
|
-
const onMouseUp = (e) => {
|
|
1245
|
-
var _a;
|
|
1246
|
-
e.preventDefault();
|
|
1247
|
-
e.stopPropagation();
|
|
1248
|
-
onAdd == null ? void 0 : onAdd();
|
|
1249
|
-
(_a = ref.current) == null ? void 0 : _a.classList.remove("active");
|
|
1250
|
-
};
|
|
1251
|
-
return html`
|
|
1252
|
-
<host>
|
|
1253
|
-
<div ref=${ref} onmousedown=${onMouseDown} onmouseup=${onMouseUp} class="operation-item">
|
|
1254
|
-
${(addIcon == null ? void 0 : addIcon()) || plusIcon}
|
|
1255
|
-
</div>
|
|
1256
|
-
<div class="operation-item">
|
|
1257
|
-
${(handleIcon == null ? void 0 : handleIcon()) || menuIcon}
|
|
1258
|
-
</div>
|
|
1259
|
-
</host>
|
|
1260
|
-
`;
|
|
1261
|
-
};
|
|
1262
|
-
blockHandleComponent.props = {
|
|
1263
|
-
show: Boolean,
|
|
1264
|
-
onAdd: Function,
|
|
1265
|
-
addIcon: Function,
|
|
1266
|
-
handleIcon: Function
|
|
1267
|
-
};
|
|
1268
|
-
const BlockHandleElement = c(blockHandleComponent);
|
|
1269
|
-
|
|
1270
|
-
var __typeError = (msg) => {
|
|
1271
|
-
throw TypeError(msg);
|
|
1272
|
-
};
|
|
1273
|
-
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
1274
|
-
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
1275
|
-
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1276
|
-
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
1277
|
-
var _content, _provider, _ctx;
|
|
1278
|
-
class BlockHandleView {
|
|
1279
|
-
constructor(ctx, config) {
|
|
1280
|
-
__privateAdd(this, _content);
|
|
1281
|
-
__privateAdd(this, _provider);
|
|
1282
|
-
__privateAdd(this, _ctx);
|
|
1283
|
-
this.update = () => {
|
|
1284
|
-
__privateGet(this, _provider).update();
|
|
1285
|
-
};
|
|
1286
|
-
this.destroy = () => {
|
|
1287
|
-
__privateGet(this, _provider).destroy();
|
|
1288
|
-
__privateGet(this, _content).remove();
|
|
1289
|
-
};
|
|
1290
|
-
this.onAdd = () => {
|
|
1291
|
-
const ctx = __privateGet(this, _ctx);
|
|
1292
|
-
const view = ctx.get(editorViewCtx);
|
|
1293
|
-
if (!view.hasFocus())
|
|
1294
|
-
view.focus();
|
|
1295
|
-
const { state, dispatch } = view;
|
|
1296
|
-
const active = __privateGet(this, _provider).active;
|
|
1297
|
-
if (!active)
|
|
1298
|
-
return;
|
|
1299
|
-
const $pos = active.$pos;
|
|
1300
|
-
const pos = $pos.pos + active.node.nodeSize;
|
|
1301
|
-
let tr = state.tr.insert(pos, paragraphSchema.type(ctx).create());
|
|
1302
|
-
tr = tr.setSelection(TextSelection.near(tr.doc.resolve(pos)));
|
|
1303
|
-
dispatch(tr.scrollIntoView());
|
|
1304
|
-
__privateGet(this, _provider).hide();
|
|
1305
|
-
ctx.get(menuAPI.key).show(tr.selection.from);
|
|
1306
|
-
};
|
|
1307
|
-
__privateSet(this, _ctx, ctx);
|
|
1308
|
-
const content = new BlockHandleElement();
|
|
1309
|
-
__privateSet(this, _content, content);
|
|
1310
|
-
__privateGet(this, _content).onAdd = this.onAdd;
|
|
1311
|
-
__privateGet(this, _content).addIcon = config == null ? void 0 : config.handleAddIcon;
|
|
1312
|
-
__privateGet(this, _content).handleIcon = config == null ? void 0 : config.handleDragIcon;
|
|
1313
|
-
__privateSet(this, _provider, new BlockProvider({
|
|
1314
|
-
ctx,
|
|
1315
|
-
content,
|
|
1316
|
-
getOffset: () => 16,
|
|
1317
|
-
getPlacement: ({ active, blockDom }) => {
|
|
1318
|
-
let totalDescendant = 0;
|
|
1319
|
-
active.node.descendants((node) => {
|
|
1320
|
-
totalDescendant += node.childCount;
|
|
1321
|
-
});
|
|
1322
|
-
const dom = active.el;
|
|
1323
|
-
const domRect = dom.getBoundingClientRect();
|
|
1324
|
-
const handleRect = blockDom.getBoundingClientRect();
|
|
1325
|
-
const style = window.getComputedStyle(dom);
|
|
1326
|
-
const paddingTop = Number.parseInt(style.paddingTop, 10) || 0;
|
|
1327
|
-
const paddingBottom = Number.parseInt(style.paddingBottom, 10) || 0;
|
|
1328
|
-
const height = domRect.height - paddingTop - paddingBottom;
|
|
1329
|
-
const handleHeight = handleRect.height;
|
|
1330
|
-
return totalDescendant > 2 || handleHeight * 2 < height ? "left-start" : "left";
|
|
1331
|
-
}
|
|
1332
|
-
}));
|
|
1333
|
-
this.update();
|
|
1334
|
-
}
|
|
1335
|
-
}
|
|
1336
|
-
_content = new WeakMap();
|
|
1337
|
-
_provider = new WeakMap();
|
|
1338
|
-
_ctx = new WeakMap();
|
|
1339
|
-
defIfNotExists("milkdown-block-handle", BlockHandleElement);
|
|
1340
|
-
function configureBlockHandle(ctx, config) {
|
|
1341
|
-
ctx.set(block.key, {
|
|
1342
|
-
view: () => new BlockHandleView(ctx, config)
|
|
1343
|
-
});
|
|
1344
|
-
}
|
|
1345
|
-
|
|
1346
|
-
const defineFeature = (editor, config) => {
|
|
1347
|
-
editor.config((ctx) => configureBlockHandle(ctx, config)).config((ctx) => configureMenu(ctx, config)).use(menuAPI).use(block).use(menu);
|
|
1348
|
-
};
|
|
1349
|
-
|
|
1350
|
-
export { defineFeature };
|
|
1351
|
-
//# sourceMappingURL=index-ueQQMSgm.js.map
|