@prosekit/core 0.7.9 → 0.7.10

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.
@@ -167,6 +167,7 @@ declare type BaseCommandsExtension = Extension<{
167
167
  wrap: [options: WrapOptions];
168
168
  setBlockType: [options: SetBlockTypeOptions];
169
169
  setNodeAttrs: [options: SetNodeAttrsOptions];
170
+ insertDefaultBlock: [options?: InsertDefaultBlockOptions];
170
171
  selectAll: [];
171
172
  addMark: [options: AddMarkOptions];
172
173
  removeMark: [options: RemoveMarkOptions];
@@ -299,7 +300,7 @@ export declare function combineEventHandlers<Handler extends (...args: any[]) =>
299
300
  /**
300
301
  * A function to apply a command to the editor. It will return `true` if the command was applied, and `false` otherwise.
301
302
  *
302
- * It also has a `canApply` method to check if the command can be applied.
303
+ * It also has a `canExec` method to check if the command can be applied.
303
304
  *
304
305
  * @public
305
306
  */
@@ -1489,6 +1490,31 @@ export { htmlFromNode as htmlFromNode_alias_1 }
1489
1490
 
1490
1491
  export declare function includesMark(marks: readonly Mark[], markType: MarkType, attrs?: Attrs | null): boolean;
1491
1492
 
1493
+ export declare function inputText(input: string): Promise<void>;
1494
+
1495
+ /**
1496
+ * Returns a command that inserts a default block after current selection or at
1497
+ * the given position.
1498
+ *
1499
+ * @public
1500
+ */
1501
+ declare function insertDefaultBlock(options?: InsertDefaultBlockOptions): Command;
1502
+ export { insertDefaultBlock }
1503
+ export { insertDefaultBlock as insertDefaultBlock_alias_1 }
1504
+
1505
+ /**
1506
+ * @public
1507
+ */
1508
+ declare interface InsertDefaultBlockOptions {
1509
+ /**
1510
+ * The position to insert the node at. By default it will insert after the
1511
+ * current selection.
1512
+ */
1513
+ pos?: number;
1514
+ }
1515
+ export { InsertDefaultBlockOptions }
1516
+ export { InsertDefaultBlockOptions as InsertDefaultBlockOptions_alias_1 }
1517
+
1492
1518
  /**
1493
1519
  * Returns a command that inserts the given node at the current selection or at
1494
1520
  * the given position.
@@ -4,6 +4,8 @@ export { expandMark } from './_tsup-dts-rollup';
4
4
  export { ExpandMarkOptions } from './_tsup-dts-rollup';
5
5
  export { insertNode } from './_tsup-dts-rollup';
6
6
  export { InsertNodeOptions } from './_tsup-dts-rollup';
7
+ export { insertDefaultBlock } from './_tsup-dts-rollup';
8
+ export { InsertDefaultBlockOptions } from './_tsup-dts-rollup';
7
9
  export { removeMark } from './_tsup-dts-rollup';
8
10
  export { RemoveMarkOptions } from './_tsup-dts-rollup';
9
11
  export { removeNode } from './_tsup-dts-rollup';
@@ -142,6 +142,41 @@ function insertNode(options) {
142
142
  };
143
143
  }
144
144
 
145
+ // src/commands/insert-default-block.ts
146
+ import { TextSelection as TextSelection3 } from "@prosekit/pm/state";
147
+
148
+ // src/utils/default-block-at.ts
149
+ function defaultBlockAt(match) {
150
+ for (let i = 0; i < match.edgeCount; i++) {
151
+ const { type } = match.edge(i);
152
+ if (type.isTextblock && !type.hasRequiredAttrs()) return type;
153
+ }
154
+ return null;
155
+ }
156
+
157
+ // src/commands/insert-default-block.ts
158
+ function insertDefaultBlock(options) {
159
+ return (state, dispatch) => {
160
+ const $pos = (options == null ? void 0 : options.pos) == null ? state.selection.$to : state.doc.resolve(options.pos);
161
+ const depth = $pos.parent.isTextblock ? $pos.depth - 1 : $pos.depth;
162
+ const parent = $pos.node(depth);
163
+ const index = $pos.indexAfter(depth);
164
+ const type = defaultBlockAt(parent.contentMatchAt(index));
165
+ if (!type) return false;
166
+ if (dispatch) {
167
+ const pos = $pos.posAtIndex(index, depth);
168
+ const node = type.createAndFill();
169
+ if (!node) return false;
170
+ const tr = state.tr.insert(pos, node);
171
+ const selection = TextSelection3.findFrom(tr.doc.resolve(pos), 1);
172
+ if (!selection) return false;
173
+ tr.setSelection(selection);
174
+ dispatch(tr.scrollIntoView());
175
+ }
176
+ return true;
177
+ };
178
+ }
179
+
145
180
  // src/commands/remove-mark.ts
146
181
  function removeMark(options) {
147
182
  return (state, dispatch) => {
@@ -189,13 +224,13 @@ function removeNode(options) {
189
224
  }
190
225
 
191
226
  // src/utils/get-custom-selection.ts
192
- import { TextSelection as TextSelection3 } from "@prosekit/pm/state";
227
+ import { TextSelection as TextSelection4 } from "@prosekit/pm/state";
193
228
  function getCustomSelection(state, from, to) {
194
229
  const pos = from != null ? from : to;
195
230
  if (pos != null) {
196
231
  const $from = state.doc.resolve(from != null ? from : pos);
197
232
  const $to = state.doc.resolve(to != null ? to : pos);
198
- return TextSelection3.between($from, $to);
233
+ return TextSelection4.between($from, $to);
199
234
  }
200
235
  return state.selection;
201
236
  }
@@ -429,6 +464,7 @@ function defineBaseCommands() {
429
464
  wrap,
430
465
  setBlockType,
431
466
  setNodeAttrs,
467
+ insertDefaultBlock,
432
468
  selectAll,
433
469
  addMark,
434
470
  removeMark,
@@ -1260,15 +1296,6 @@ function containsInlineNode(doc, from, to) {
1260
1296
  return found;
1261
1297
  }
1262
1298
 
1263
- // src/utils/default-block-at.ts
1264
- function defaultBlockAt(match) {
1265
- for (let i = 0; i < match.edgeCount; i++) {
1266
- const { type } = match.edge(i);
1267
- if (type.isTextblock && !type.hasRequiredAttrs()) return type;
1268
- }
1269
- return null;
1270
- }
1271
-
1272
1299
  // src/utils/get-id.ts
1273
1300
  var id = 0;
1274
1301
  function getId() {
@@ -1371,6 +1398,7 @@ export {
1371
1398
  getNodeType,
1372
1399
  htmlFromJSON,
1373
1400
  htmlFromNode,
1401
+ insertDefaultBlock,
1374
1402
  insertNode,
1375
1403
  isAllSelection,
1376
1404
  isApple,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/core",
3
3
  "type": "module",
4
- "version": "0.7.9",
4
+ "version": "0.7.10",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -49,6 +49,7 @@
49
49
  "@prosekit/pm": "^0.1.8"
50
50
  },
51
51
  "devDependencies": {
52
+ "@vitest/browser": "^2.0.5",
52
53
  "tsup": "^8.2.4",
53
54
  "typescript": "^5.5.4",
54
55
  "vitest": "^2.0.5",