@milkdown/preset-commonmark 7.2.0 → 7.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/composed/commands.d.ts.map +1 -1
- package/lib/index.es.js +451 -426
- package/lib/index.es.js.map +1 -1
- package/lib/node/list-item.d.ts +2 -1
- package/lib/node/list-item.d.ts.map +1 -1
- package/lib/plugin/inline-sync-plugin/utils.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/composed/commands.ts +18 -1
- package/src/node/list-item.ts +45 -0
- package/src/plugin/inline-sync-plugin/utils.ts +8 -2
package/lib/node/list-item.d.ts
CHANGED
|
@@ -3,5 +3,6 @@ export declare const listItemSchema: import("@milkdown/utils").$NodeSchema<"list
|
|
|
3
3
|
export declare const sinkListItemCommand: import("@milkdown/utils").$Command<unknown>;
|
|
4
4
|
export declare const liftListItemCommand: import("@milkdown/utils").$Command<unknown>;
|
|
5
5
|
export declare const splitListItemCommand: import("@milkdown/utils").$Command<unknown>;
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const liftFirstListItemCommand: import("@milkdown/utils").$Command<unknown>;
|
|
7
|
+
export declare const listItemKeymap: import("@milkdown/utils").$UserKeymap<"listItemKeymap", "SinkListItem" | "LiftFirstListItem" | "NextListItem" | "LiftListItem">;
|
|
7
8
|
//# sourceMappingURL=list-item.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-item.d.ts","sourceRoot":"","sources":["../../src/node/list-item.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"list-item.d.ts","sourceRoot":"","sources":["../../src/node/list-item.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,YAAY,qCAAwB,CAAA;AAQjD,eAAO,MAAM,cAAc,oDA2DxB,CAAA;AAwBH,eAAO,MAAM,mBAAmB,6CAA4E,CAAA;AAmB5G,eAAO,MAAM,mBAAmB,6CAA6E,CAAA;AAoB7G,eAAO,MAAM,oBAAoB,6CAA8E,CAAA;AAqC/G,eAAO,MAAM,wBAAwB,6CAA+D,CAAA;AAWpG,eAAO,MAAM,cAAc,iIA6BzB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAEjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAGnD,eAAO,MAAM,QAAQ,QAAS,MAAM,WAUnC,CAAA;AAED,eAAO,MAAM,IAAI,SAAU,MAAM,SAAS,MAAM,QAAQ,MAAM,WAQ7D,CAAA;AAED,eAAO,MAAM,kBAAkB,oBAAqB,MAAM,YAAY,MAAM,WACtB,CAAA;AAEtD,eAAO,MAAM,oBAAoB,gBAAiB,mBAAmB,YAAY,MAAM,WAkBtF,CAAA;AAED,eAAO,MAAM,UAAU,SAAU,IAAI,QAAQ,MAAM,eAAe,MAAM,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAEjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAGnD,eAAO,MAAM,QAAQ,QAAS,MAAM,WAUnC,CAAA;AAED,eAAO,MAAM,IAAI,SAAU,MAAM,SAAS,MAAM,QAAQ,MAAM,WAQ7D,CAAA;AAED,eAAO,MAAM,kBAAkB,oBAAqB,MAAM,YAAY,MAAM,WACtB,CAAA;AAEtD,eAAO,MAAM,oBAAoB,gBAAiB,mBAAmB,YAAY,MAAM,WAkBtF,CAAA;AAED,eAAO,MAAM,UAAU,SAAU,IAAI,QAAQ,MAAM,eAAe,MAAM,WAwBvE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milkdown/preset-commonmark",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.2.
|
|
4
|
+
"version": "7.2.2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -32,15 +32,15 @@
|
|
|
32
32
|
"remark-inline-links": "^6.0.0",
|
|
33
33
|
"tslib": "^2.5.0",
|
|
34
34
|
"unist-util-visit": "^4.0.0",
|
|
35
|
-
"@milkdown/exception": "7.2.
|
|
36
|
-
"@milkdown/utils": "7.2.
|
|
35
|
+
"@milkdown/exception": "7.2.2",
|
|
36
|
+
"@milkdown/utils": "7.2.2"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/unist": "^2.0.6",
|
|
40
|
-
"@milkdown/core": "7.2.
|
|
41
|
-
"@milkdown/ctx": "7.2.
|
|
42
|
-
"@milkdown/prose": "7.2.
|
|
43
|
-
"@milkdown/transformer": "7.2.
|
|
40
|
+
"@milkdown/core": "7.2.2",
|
|
41
|
+
"@milkdown/ctx": "7.2.2",
|
|
42
|
+
"@milkdown/prose": "7.2.2",
|
|
43
|
+
"@milkdown/transformer": "7.2.2"
|
|
44
44
|
},
|
|
45
45
|
"nx": {
|
|
46
46
|
"targets": {
|
package/src/composed/commands.ts
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
import type { MilkdownPlugin } from '@milkdown/ctx'
|
|
3
3
|
import { toggleEmphasisCommand, toggleInlineCodeCommand, toggleLinkCommand, toggleStrongCommand, updateLinkCommand } from '../mark'
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
createCodeBlockCommand,
|
|
6
|
+
downgradeHeadingCommand,
|
|
7
|
+
insertHardbreakCommand,
|
|
8
|
+
insertHrCommand,
|
|
9
|
+
insertImageCommand,
|
|
10
|
+
liftFirstListItemCommand,
|
|
11
|
+
liftListItemCommand,
|
|
12
|
+
sinkListItemCommand,
|
|
13
|
+
splitListItemCommand,
|
|
14
|
+
turnIntoTextCommand,
|
|
15
|
+
updateImageCommand,
|
|
16
|
+
wrapInBlockquoteCommand,
|
|
17
|
+
wrapInBulletListCommand,
|
|
18
|
+
wrapInHeadingCommand,
|
|
19
|
+
wrapInOrderedListCommand,
|
|
20
|
+
} from '../node'
|
|
5
21
|
|
|
6
22
|
/// @internal
|
|
7
23
|
export const commands: MilkdownPlugin[] = [
|
|
@@ -21,6 +37,7 @@ export const commands: MilkdownPlugin[] = [
|
|
|
21
37
|
sinkListItemCommand,
|
|
22
38
|
splitListItemCommand,
|
|
23
39
|
liftListItemCommand,
|
|
40
|
+
liftFirstListItemCommand,
|
|
24
41
|
|
|
25
42
|
toggleEmphasisCommand,
|
|
26
43
|
toggleInlineCodeCommand,
|
package/src/node/list-item.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { commandsCtx } from '@milkdown/core'
|
|
|
3
3
|
import { expectDomTypeError } from '@milkdown/exception'
|
|
4
4
|
import { liftListItem, sinkListItem, splitListItem } from '@milkdown/prose/schema-list'
|
|
5
5
|
import { $command, $nodeAttr, $nodeSchema, $useKeymap } from '@milkdown/utils'
|
|
6
|
+
import { type Command, TextSelection } from '@milkdown/prose/state'
|
|
6
7
|
import { withMeta } from '../__internal__'
|
|
7
8
|
|
|
8
9
|
/// HTML attributes for list item node.
|
|
@@ -143,6 +144,43 @@ withMeta(splitListItemCommand, {
|
|
|
143
144
|
group: 'ListItem',
|
|
144
145
|
})
|
|
145
146
|
|
|
147
|
+
const liftFirstListItem: Command = (state, dispatch, view) => {
|
|
148
|
+
const { selection } = state
|
|
149
|
+
if (!(selection instanceof TextSelection))
|
|
150
|
+
return false
|
|
151
|
+
|
|
152
|
+
const { empty, $from } = selection
|
|
153
|
+
|
|
154
|
+
// selection should be empty and at the start of the node
|
|
155
|
+
if (!empty || $from.parentOffset !== 0)
|
|
156
|
+
return false
|
|
157
|
+
|
|
158
|
+
const parentItem = $from.node(-1)
|
|
159
|
+
// selection should be in list item and list item should be the first child of the list
|
|
160
|
+
if (parentItem.type !== listItemSchema.type() || parentItem.firstChild !== $from.node())
|
|
161
|
+
return false
|
|
162
|
+
|
|
163
|
+
const list = $from.node(-2)
|
|
164
|
+
// list should have only one list item
|
|
165
|
+
if (list.childCount > 1)
|
|
166
|
+
return false
|
|
167
|
+
|
|
168
|
+
return liftListItem(listItemSchema.type())(state, dispatch, view)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/// The command to remove list item **only if**:
|
|
172
|
+
///
|
|
173
|
+
/// - Selection is at the start of the list item.
|
|
174
|
+
/// - List item is the only child of the list.
|
|
175
|
+
///
|
|
176
|
+
/// Most of the time, you shouldn't use this command directly.
|
|
177
|
+
export const liftFirstListItemCommand = $command('LiftFirstListItem', () => () => liftFirstListItem)
|
|
178
|
+
|
|
179
|
+
withMeta(liftFirstListItemCommand, {
|
|
180
|
+
displayName: 'Command<liftFirstListItemCommand>',
|
|
181
|
+
group: 'ListItem',
|
|
182
|
+
})
|
|
183
|
+
|
|
146
184
|
/// Keymap for list item node.
|
|
147
185
|
/// - `<Enter>`: Split the current list item.
|
|
148
186
|
/// - `<Tab>/<Mod-]>`: Sink the current list item.
|
|
@@ -169,6 +207,13 @@ export const listItemKeymap = $useKeymap('listItemKeymap', {
|
|
|
169
207
|
return () => commands.call(liftListItemCommand.key)
|
|
170
208
|
},
|
|
171
209
|
},
|
|
210
|
+
LiftFirstListItem: {
|
|
211
|
+
shortcuts: ['Backspace', 'Delete'],
|
|
212
|
+
command: (ctx) => {
|
|
213
|
+
const commands = ctx.get(commandsCtx)
|
|
214
|
+
return () => commands.call(liftFirstListItemCommand.key)
|
|
215
|
+
},
|
|
216
|
+
},
|
|
172
217
|
})
|
|
173
218
|
|
|
174
219
|
withMeta(listItemKeymap.ctx, {
|
|
@@ -56,6 +56,10 @@ export const calcOffset = (node: Node, from: number, placeholder: string) => {
|
|
|
56
56
|
node.descendants((n) => {
|
|
57
57
|
if (find)
|
|
58
58
|
return false
|
|
59
|
+
if (!n.textContent.includes(placeholder)) {
|
|
60
|
+
offset += n.nodeSize
|
|
61
|
+
return false
|
|
62
|
+
}
|
|
59
63
|
if (n.isText) {
|
|
60
64
|
const i = n.text?.indexOf(placeholder)
|
|
61
65
|
if (i != null && i >= 0) {
|
|
@@ -64,8 +68,10 @@ export const calcOffset = (node: Node, from: number, placeholder: string) => {
|
|
|
64
68
|
return false
|
|
65
69
|
}
|
|
66
70
|
}
|
|
67
|
-
|
|
68
|
-
|
|
71
|
+
|
|
72
|
+
// enter the node
|
|
73
|
+
offset += 1
|
|
74
|
+
return true
|
|
69
75
|
})
|
|
70
76
|
return offset
|
|
71
77
|
}
|