@milkdown/preset-commonmark 7.12.1 → 7.13.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/commands/index.d.ts +20 -0
- package/lib/commands/index.d.ts.map +1 -0
- package/lib/composed/commands.d.ts.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +119 -5
- package/lib/index.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/src/commands/index.ts +140 -0
- package/src/composed/commands.ts +18 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Node, type Attrs, type MarkType, type NodeType } from '@milkdown/prose/model';
|
|
2
|
+
export declare const isMarkSelectedCommand: import("@milkdown/utils").$Command<MarkType>;
|
|
3
|
+
export declare const isNodeSelectedCommand: import("@milkdown/utils").$Command<NodeType>;
|
|
4
|
+
export declare const clearTextInCurrentBlockCommand: import("@milkdown/utils").$Command<unknown>;
|
|
5
|
+
export declare const setBlockTypeCommand: import("@milkdown/utils").$Command<{
|
|
6
|
+
nodeType: NodeType;
|
|
7
|
+
attrs?: Attrs | null;
|
|
8
|
+
}>;
|
|
9
|
+
export declare const wrapInBlockTypeCommand: import("@milkdown/utils").$Command<{
|
|
10
|
+
nodeType: NodeType;
|
|
11
|
+
attrs?: Attrs | null;
|
|
12
|
+
}>;
|
|
13
|
+
export declare const addBlockTypeCommand: import("@milkdown/utils").$Command<{
|
|
14
|
+
nodeType: NodeType | Node;
|
|
15
|
+
attrs?: Attrs | null;
|
|
16
|
+
}>;
|
|
17
|
+
export declare const selectTextNearPosCommand: import("@milkdown/utils").$Command<{
|
|
18
|
+
pos?: number;
|
|
19
|
+
}>;
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,IAAI,EACJ,KAAK,KAAK,EACV,KAAK,QAAQ,EACb,KAAK,QAAQ,EACd,MAAM,uBAAuB,CAAA;AAM9B,eAAO,MAAM,qBAAqB,8CAQjC,CAAA;AAGD,eAAO,MAAM,qBAAqB,8CAOjC,CAAA;AAGD,eAAO,MAAM,8BAA8B,6CAc1C,CAAA;AAGD,eAAO,MAAM,mBAAmB;cAGL,QAAQ;YAAU,KAAK,GAAG,IAAI;EAcxD,CAAA;AAGD,eAAO,MAAM,sBAAsB;cAGR,QAAQ;YAAU,KAAK,GAAG,IAAI;EAoBxD,CAAA;AAGD,eAAO,MAAM,mBAAmB;cAGL,QAAQ,GAAG,IAAI;YAAU,KAAK,GAAG,IAAI;EAkB/D,CAAA;AAGD,eAAO,MAAM,wBAAwB;UAEV,MAAM;EAiBhC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../src/composed/commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../src/composed/commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAqCnD,eAAO,MAAM,QAAQ,EAAE,cAAc,EAkCpC,CAAA"}
|
package/lib/index.d.ts
CHANGED
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAWnD,cAAc,QAAQ,CAAA;AACtB,cAAc,QAAQ,CAAA;AACtB,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA;AAG1B,eAAO,MAAM,UAAU,EAAE,cAAc,EAO/B,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAWnD,cAAc,QAAQ,CAAA;AACtB,cAAc,QAAQ,CAAA;AACtB,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAG1B,eAAO,MAAM,UAAU,EAAE,cAAc,EAO/B,CAAA"}
|
package/lib/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import { markRule, findSelectedNodeOfType, findNodeInSelection } from "@milkdown/prose";
|
|
2
|
+
import { Fragment, Node } from "@milkdown/prose/model";
|
|
3
|
+
import { TextSelection, Selection, PluginKey, Plugin } from "@milkdown/prose/state";
|
|
4
|
+
import { findWrapping, ReplaceStep, AddMarkStep } from "@milkdown/prose/transform";
|
|
1
5
|
import { $markAttr, $markSchema, $inputRule, $command, $useKeymap, $node, $remark, $nodeAttr, $nodeSchema, $ctx, $prose } from "@milkdown/utils";
|
|
2
6
|
import { remarkStringifyOptionsCtx, commandsCtx, editorViewCtx } from "@milkdown/core";
|
|
3
7
|
import { toggleMark, setBlockType, wrapIn } from "@milkdown/prose/commands";
|
|
4
8
|
import { visitParents } from "unist-util-visit-parents";
|
|
5
|
-
import { Fragment } from "@milkdown/prose/model";
|
|
6
9
|
import { expectDomTypeError } from "@milkdown/exception";
|
|
7
10
|
import { textblockTypeInputRule, wrappingInputRule, InputRule } from "@milkdown/prose/inputrules";
|
|
8
|
-
import { TextSelection, Selection, PluginKey, Plugin } from "@milkdown/prose/state";
|
|
9
|
-
import { markRule, findSelectedNodeOfType } from "@milkdown/prose";
|
|
10
11
|
import { sinkListItem, splitListItem, liftListItem } from "@milkdown/prose/schema-list";
|
|
11
|
-
import { ReplaceStep, AddMarkStep } from "@milkdown/prose/transform";
|
|
12
12
|
import { Decoration, DecorationSet } from "@milkdown/prose/view";
|
|
13
13
|
import { visit } from "unist-util-visit";
|
|
14
14
|
import remarkInlineLinks from "remark-inline-links";
|
|
@@ -1683,6 +1683,106 @@ const markInputRules = [
|
|
|
1683
1683
|
inlineCodeInputRule,
|
|
1684
1684
|
strongInputRule
|
|
1685
1685
|
];
|
|
1686
|
+
const isMarkSelectedCommand = $command(
|
|
1687
|
+
"IsMarkSelected",
|
|
1688
|
+
() => (markType) => (state) => {
|
|
1689
|
+
if (!markType) return false;
|
|
1690
|
+
const { doc, selection } = state;
|
|
1691
|
+
const hasLink = doc.rangeHasMark(selection.from, selection.to, markType);
|
|
1692
|
+
return hasLink;
|
|
1693
|
+
}
|
|
1694
|
+
);
|
|
1695
|
+
const isNodeSelectedCommand = $command(
|
|
1696
|
+
"IsNoteSelected",
|
|
1697
|
+
() => (nodeType) => (state) => {
|
|
1698
|
+
if (!nodeType) return false;
|
|
1699
|
+
const result = findNodeInSelection(state, nodeType);
|
|
1700
|
+
return result.hasNode;
|
|
1701
|
+
}
|
|
1702
|
+
);
|
|
1703
|
+
const clearTextInCurrentBlockCommand = $command(
|
|
1704
|
+
"ClearTextInCurrentBlock",
|
|
1705
|
+
() => () => (state, dispatch) => {
|
|
1706
|
+
let tr = state.tr;
|
|
1707
|
+
const { $from, $to } = tr.selection;
|
|
1708
|
+
const { pos: from } = $from;
|
|
1709
|
+
const { pos: right } = $to;
|
|
1710
|
+
const left = from - $from.node().content.size;
|
|
1711
|
+
if (left < 0) return false;
|
|
1712
|
+
tr = tr.deleteRange(left, right);
|
|
1713
|
+
dispatch == null ? void 0 : dispatch(tr);
|
|
1714
|
+
return true;
|
|
1715
|
+
}
|
|
1716
|
+
);
|
|
1717
|
+
const setBlockTypeCommand = $command(
|
|
1718
|
+
"SetBlockType",
|
|
1719
|
+
() => (payload) => (state, dispatch) => {
|
|
1720
|
+
const { nodeType, attrs = null } = payload ?? {};
|
|
1721
|
+
if (!nodeType) return false;
|
|
1722
|
+
const tr = state.tr;
|
|
1723
|
+
const { from, to } = tr.selection;
|
|
1724
|
+
try {
|
|
1725
|
+
tr.setBlockType(from, to, nodeType, attrs);
|
|
1726
|
+
} catch {
|
|
1727
|
+
return false;
|
|
1728
|
+
}
|
|
1729
|
+
dispatch == null ? void 0 : dispatch(tr);
|
|
1730
|
+
return true;
|
|
1731
|
+
}
|
|
1732
|
+
);
|
|
1733
|
+
const wrapInBlockTypeCommand = $command(
|
|
1734
|
+
"WrapInBlockType",
|
|
1735
|
+
() => (payload) => (state, dispatch) => {
|
|
1736
|
+
const { nodeType, attrs = null } = payload ?? {};
|
|
1737
|
+
if (!nodeType) return false;
|
|
1738
|
+
let tr = state.tr;
|
|
1739
|
+
try {
|
|
1740
|
+
const { $from, $to } = tr.selection;
|
|
1741
|
+
const blockRange = $from.blockRange($to);
|
|
1742
|
+
const wrapping = blockRange && findWrapping(blockRange, nodeType, attrs);
|
|
1743
|
+
if (!wrapping) return false;
|
|
1744
|
+
tr = tr.wrap(blockRange, wrapping);
|
|
1745
|
+
} catch {
|
|
1746
|
+
return false;
|
|
1747
|
+
}
|
|
1748
|
+
dispatch == null ? void 0 : dispatch(tr);
|
|
1749
|
+
return true;
|
|
1750
|
+
}
|
|
1751
|
+
);
|
|
1752
|
+
const addBlockTypeCommand = $command(
|
|
1753
|
+
"AddBlockType",
|
|
1754
|
+
() => (payload) => (state, dispatch) => {
|
|
1755
|
+
const { nodeType, attrs = null } = payload ?? {};
|
|
1756
|
+
if (!nodeType) return false;
|
|
1757
|
+
const tr = state.tr;
|
|
1758
|
+
try {
|
|
1759
|
+
const node = nodeType instanceof Node ? nodeType : nodeType.createAndFill(attrs);
|
|
1760
|
+
if (!node) return false;
|
|
1761
|
+
tr.replaceSelectionWith(node);
|
|
1762
|
+
} catch {
|
|
1763
|
+
return false;
|
|
1764
|
+
}
|
|
1765
|
+
dispatch == null ? void 0 : dispatch(tr);
|
|
1766
|
+
return true;
|
|
1767
|
+
}
|
|
1768
|
+
);
|
|
1769
|
+
const selectTextNearPosCommand = $command(
|
|
1770
|
+
"SelectTextNearPos",
|
|
1771
|
+
() => (payload) => (state, dispatch) => {
|
|
1772
|
+
const { pos } = payload ?? {};
|
|
1773
|
+
if (pos == null) return false;
|
|
1774
|
+
const clamp = (value, min, max) => Math.min(Math.max(value, min), max);
|
|
1775
|
+
const tr = state.tr;
|
|
1776
|
+
try {
|
|
1777
|
+
const $pos = state.doc.resolve(clamp(pos, 0, state.doc.content.size));
|
|
1778
|
+
tr.setSelection(TextSelection.near($pos));
|
|
1779
|
+
} catch {
|
|
1780
|
+
return false;
|
|
1781
|
+
}
|
|
1782
|
+
dispatch == null ? void 0 : dispatch(tr.scrollIntoView());
|
|
1783
|
+
return true;
|
|
1784
|
+
}
|
|
1785
|
+
);
|
|
1686
1786
|
const commands = [
|
|
1687
1787
|
turnIntoTextCommand,
|
|
1688
1788
|
wrapInBlockquoteCommand,
|
|
@@ -1703,7 +1803,14 @@ const commands = [
|
|
|
1703
1803
|
toggleInlineCodeCommand,
|
|
1704
1804
|
toggleStrongCommand,
|
|
1705
1805
|
toggleLinkCommand,
|
|
1706
|
-
updateLinkCommand
|
|
1806
|
+
updateLinkCommand,
|
|
1807
|
+
isMarkSelectedCommand,
|
|
1808
|
+
isNodeSelectedCommand,
|
|
1809
|
+
clearTextInCurrentBlockCommand,
|
|
1810
|
+
setBlockTypeCommand,
|
|
1811
|
+
wrapInBlockTypeCommand,
|
|
1812
|
+
addBlockTypeCommand,
|
|
1813
|
+
selectTextNearPosCommand
|
|
1707
1814
|
];
|
|
1708
1815
|
const keymap = [
|
|
1709
1816
|
blockquoteKeymap,
|
|
@@ -2155,12 +2262,14 @@ const commonmark = [
|
|
|
2155
2262
|
plugins
|
|
2156
2263
|
].flat();
|
|
2157
2264
|
export {
|
|
2265
|
+
addBlockTypeCommand,
|
|
2158
2266
|
blockquoteAttr,
|
|
2159
2267
|
blockquoteKeymap,
|
|
2160
2268
|
blockquoteSchema,
|
|
2161
2269
|
bulletListAttr,
|
|
2162
2270
|
bulletListKeymap,
|
|
2163
2271
|
bulletListSchema,
|
|
2272
|
+
clearTextInCurrentBlockCommand,
|
|
2164
2273
|
codeBlockAttr,
|
|
2165
2274
|
codeBlockKeymap,
|
|
2166
2275
|
codeBlockSchema,
|
|
@@ -2202,6 +2311,8 @@ export {
|
|
|
2202
2311
|
insertHrInputRule,
|
|
2203
2312
|
insertImageCommand,
|
|
2204
2313
|
insertImageInputRule,
|
|
2314
|
+
isMarkSelectedCommand,
|
|
2315
|
+
isNodeSelectedCommand,
|
|
2205
2316
|
keymap,
|
|
2206
2317
|
liftFirstListItemCommand,
|
|
2207
2318
|
liftListItemCommand,
|
|
@@ -2225,6 +2336,8 @@ export {
|
|
|
2225
2336
|
remarkMarker,
|
|
2226
2337
|
remarkPreserveEmptyLinePlugin,
|
|
2227
2338
|
schema,
|
|
2339
|
+
selectTextNearPosCommand,
|
|
2340
|
+
setBlockTypeCommand,
|
|
2228
2341
|
sinkListItemCommand,
|
|
2229
2342
|
splitListItemCommand,
|
|
2230
2343
|
strongAttr,
|
|
@@ -2242,6 +2355,7 @@ export {
|
|
|
2242
2355
|
updateCodeBlockLanguageCommand,
|
|
2243
2356
|
updateImageCommand,
|
|
2244
2357
|
updateLinkCommand,
|
|
2358
|
+
wrapInBlockTypeCommand,
|
|
2245
2359
|
wrapInBlockquoteCommand,
|
|
2246
2360
|
wrapInBlockquoteInputRule,
|
|
2247
2361
|
wrapInBulletListCommand,
|