@prosekit/core 0.7.9 → 0.7.11

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.
@@ -165,8 +165,10 @@ declare type BaseCommandsExtension = Extension<{
165
165
  insertNode: [options: InsertNodeOptions];
166
166
  removeNode: [options: RemoveNodeOptions];
167
167
  wrap: [options: WrapOptions];
168
+ toggleWrap: [options: ToggleWrapOptions];
168
169
  setBlockType: [options: SetBlockTypeOptions];
169
170
  setNodeAttrs: [options: SetNodeAttrsOptions];
171
+ insertDefaultBlock: [options?: InsertDefaultBlockOptions];
170
172
  selectAll: [];
171
173
  addMark: [options: AddMarkOptions];
172
174
  removeMark: [options: RemoveMarkOptions];
@@ -299,7 +301,7 @@ export declare function combineEventHandlers<Handler extends (...args: any[]) =>
299
301
  /**
300
302
  * A function to apply a command to the editor. It will return `true` if the command was applied, and `false` otherwise.
301
303
  *
302
- * It also has a `canApply` method to check if the command can be applied.
304
+ * It also has a `canExec` method to check if the command can be applied.
303
305
  *
304
306
  * @public
305
307
  */
@@ -1489,6 +1491,31 @@ export { htmlFromNode as htmlFromNode_alias_1 }
1489
1491
 
1490
1492
  export declare function includesMark(marks: readonly Mark[], markType: MarkType, attrs?: Attrs | null): boolean;
1491
1493
 
1494
+ export declare function inputText(input: string): Promise<void>;
1495
+
1496
+ /**
1497
+ * Returns a command that inserts a default block after current selection or at
1498
+ * the given position.
1499
+ *
1500
+ * @public
1501
+ */
1502
+ declare function insertDefaultBlock(options?: InsertDefaultBlockOptions): Command;
1503
+ export { insertDefaultBlock }
1504
+ export { insertDefaultBlock as insertDefaultBlock_alias_1 }
1505
+
1506
+ /**
1507
+ * @public
1508
+ */
1509
+ declare interface InsertDefaultBlockOptions {
1510
+ /**
1511
+ * The position to insert the node at. By default it will insert after the
1512
+ * current selection.
1513
+ */
1514
+ pos?: number;
1515
+ }
1516
+ export { InsertDefaultBlockOptions }
1517
+ export { InsertDefaultBlockOptions as InsertDefaultBlockOptions_alias_1 }
1518
+
1492
1519
  /**
1493
1520
  * Returns a command that inserts the given node at the current selection or at
1494
1521
  * the given position.
@@ -2602,6 +2629,31 @@ declare interface ToggleNodeOptions {
2602
2629
  export { ToggleNodeOptions }
2603
2630
  export { ToggleNodeOptions as ToggleNodeOptions_alias_1 }
2604
2631
 
2632
+ /**
2633
+ * Toggle between wrapping an inactive node with the provided node type, and
2634
+ * lifting it up into it's parent.
2635
+ *
2636
+ * @param options
2637
+ *
2638
+ * @public
2639
+ */
2640
+ declare function toggleWrap(options: ToggleWrapOptions): Command;
2641
+ export { toggleWrap }
2642
+ export { toggleWrap as toggleWrap_alias_1 }
2643
+
2644
+ declare interface ToggleWrapOptions {
2645
+ /**
2646
+ * The type of the node to toggle.
2647
+ */
2648
+ type: string | NodeType;
2649
+ /**
2650
+ * The attributes of the node to toggle.
2651
+ */
2652
+ attrs?: Attrs | null;
2653
+ }
2654
+ export { ToggleWrapOptions }
2655
+ export { ToggleWrapOptions as ToggleWrapOptions_alias_1 }
2656
+
2605
2657
  /**
2606
2658
  * @internal
2607
2659
  */
@@ -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';
@@ -20,6 +22,8 @@ export { unsetBlockType } from './_tsup-dts-rollup';
20
22
  export { UnsetBlockTypeOptions } from './_tsup-dts-rollup';
21
23
  export { unsetMark } from './_tsup-dts-rollup';
22
24
  export { UnsetMarkOptions } from './_tsup-dts-rollup';
25
+ export { toggleWrap } from './_tsup-dts-rollup';
26
+ export { ToggleWrapOptions } from './_tsup-dts-rollup';
23
27
  export { wrap } from './_tsup-dts-rollup';
24
28
  export { WrapOptions } from './_tsup-dts-rollup';
25
29
  export { MarkAction } 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
  }
@@ -366,6 +401,9 @@ function unsetMark(options) {
366
401
  };
367
402
  }
368
403
 
404
+ // src/commands/toggle-wrap.ts
405
+ import { lift } from "@prosekit/pm/commands";
406
+
369
407
  // src/commands/wrap.ts
370
408
  import { findWrapping } from "@prosekit/pm/transform";
371
409
  function wrap(options) {
@@ -381,6 +419,17 @@ function wrap(options) {
381
419
  };
382
420
  }
383
421
 
422
+ // src/commands/toggle-wrap.ts
423
+ function toggleWrap(options) {
424
+ const { type, attrs } = options;
425
+ return (state, dispatch) => {
426
+ if (isNodeActive(state, type, attrs)) {
427
+ return lift(state, dispatch);
428
+ }
429
+ return wrap({ type, attrs })(state, dispatch);
430
+ };
431
+ }
432
+
384
433
  // src/editor/with-priority.ts
385
434
  function withPriority(extension, priority) {
386
435
  const result = union(extension);
@@ -427,8 +476,10 @@ function defineBaseCommands() {
427
476
  insertNode,
428
477
  removeNode,
429
478
  wrap,
479
+ toggleWrap,
430
480
  setBlockType,
431
481
  setNodeAttrs,
482
+ insertDefaultBlock,
432
483
  selectAll,
433
484
  addMark,
434
485
  removeMark,
@@ -1260,15 +1311,6 @@ function containsInlineNode(doc, from, to) {
1260
1311
  return found;
1261
1312
  }
1262
1313
 
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
1314
  // src/utils/get-id.ts
1273
1315
  var id = 0;
1274
1316
  function getId() {
@@ -1371,6 +1413,7 @@ export {
1371
1413
  getNodeType,
1372
1414
  htmlFromJSON,
1373
1415
  htmlFromNode,
1416
+ insertDefaultBlock,
1374
1417
  insertNode,
1375
1418
  isAllSelection,
1376
1419
  isApple,
@@ -1401,6 +1444,7 @@ export {
1401
1444
  stateFromJSON,
1402
1445
  toggleMark,
1403
1446
  toggleNode,
1447
+ toggleWrap,
1404
1448
  union,
1405
1449
  unsetBlockType,
1406
1450
  unsetMark,
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.11",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -45,10 +45,11 @@
45
45
  "just-map-values": "^3.2.0",
46
46
  "orderedmap": "^2.1.1",
47
47
  "prosemirror-splittable": "^0.1.1",
48
- "type-fest": "^4.25.0",
48
+ "type-fest": "^4.26.0",
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",