@milkdown/preset-commonmark 7.2.1 → 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.
@@ -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 listItemKeymap: import("@milkdown/utils").$UserKeymap<"listItemKeymap", "SinkListItem" | "NextListItem" | "LiftListItem">;
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":"AAQA,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;AAW/G,eAAO,MAAM,cAAc,2GAsBzB,CAAA"}
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"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@milkdown/preset-commonmark",
3
3
  "type": "module",
4
- "version": "7.2.1",
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.1",
36
- "@milkdown/utils": "7.2.1"
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.1",
41
- "@milkdown/ctx": "7.2.1",
42
- "@milkdown/prose": "7.2.1",
43
- "@milkdown/transformer": "7.2.1"
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": {
@@ -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 { createCodeBlockCommand, downgradeHeadingCommand, insertHardbreakCommand, insertHrCommand, insertImageCommand, liftListItemCommand, sinkListItemCommand, splitListItemCommand, turnIntoTextCommand, updateImageCommand, wrapInBlockquoteCommand, wrapInBulletListCommand, wrapInHeadingCommand, wrapInOrderedListCommand } from '../node'
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,
@@ -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, {