@prosekit/core 0.2.7 → 0.3.0
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/dist/_tsup-dts-rollup.d.ts +17 -17
- package/dist/prosekit-core.d.ts +2 -2
- package/dist/prosekit-core.js +78 -65
- package/package.json +3 -3
@@ -9,7 +9,6 @@ import { EditorState } from '@prosekit/pm/state';
|
|
9
9
|
import type { EditorStateConfig } from '@prosekit/pm/state';
|
10
10
|
import { EditorView } from '@prosekit/pm/view';
|
11
11
|
import type { EmptyObject } from 'type-fest';
|
12
|
-
import { InputRule } from '@prosekit/pm/inputrules';
|
13
12
|
import type { IsEqual } from 'type-fest';
|
14
13
|
import { Mark } from '@prosekit/pm/model';
|
15
14
|
import type { MarkSpec } from '@prosekit/pm/model';
|
@@ -333,22 +332,6 @@ redo: [];
|
|
333
332
|
export { defineHistory }
|
334
333
|
export { defineHistory as defineHistory_alias_1 }
|
335
334
|
|
336
|
-
/**
|
337
|
-
* Defines an input rule extension.
|
338
|
-
*
|
339
|
-
* @param rule - The ProseMirror input rule to add, or an array of input rules,
|
340
|
-
* or a function that returns one or multiple input rules.
|
341
|
-
*
|
342
|
-
* @public
|
343
|
-
*
|
344
|
-
* @deprecated Use `prosekit/extensions/input-rule` instead.
|
345
|
-
*/
|
346
|
-
declare function defineInputRule(rule: InputRule | InputRule[] | ((context: {
|
347
|
-
schema: Schema;
|
348
|
-
}) => InputRule | InputRule[])): Extension;
|
349
|
-
export { defineInputRule }
|
350
|
-
export { defineInputRule as defineInputRule_alias_1 }
|
351
|
-
|
352
335
|
/**
|
353
336
|
* @public
|
354
337
|
*/
|
@@ -585,6 +568,20 @@ declare type EmptyValue = undefined | null | EmptyObject;
|
|
585
568
|
|
586
569
|
export declare type ExceptEmptyValue<T> = ConditionalExcept<T, EmptyValue>;
|
587
570
|
|
571
|
+
/**
|
572
|
+
* Expands the selection to include the entire mark at the current position.
|
573
|
+
*
|
574
|
+
* @public
|
575
|
+
*/
|
576
|
+
declare function expandMark(options: {
|
577
|
+
/**
|
578
|
+
* The type of the mark to expand.
|
579
|
+
*/
|
580
|
+
type: string | MarkType;
|
581
|
+
}): Command;
|
582
|
+
export { expandMark }
|
583
|
+
export { expandMark as expandMark_alias_1 }
|
584
|
+
|
588
585
|
/**
|
589
586
|
* @public
|
590
587
|
*/
|
@@ -834,6 +831,9 @@ declare function isMark(mark: unknown): mark is Mark;
|
|
834
831
|
export { isMark }
|
835
832
|
export { isMark as isMark_alias_1 }
|
836
833
|
|
834
|
+
/**
|
835
|
+
* @internal
|
836
|
+
*/
|
837
837
|
export declare function isMarkActive(state: EditorState, type: string | MarkType, attrs?: Attrs | null): boolean;
|
838
838
|
|
839
839
|
export declare function isNodeActive(state: EditorState, type: string | NodeType, attrs?: Attrs | null): boolean;
|
package/dist/prosekit-core.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
export { addMark } from './_tsup-dts-rollup';
|
2
|
+
export { expandMark } from './_tsup-dts-rollup';
|
2
3
|
export { insertNode } from './_tsup-dts-rollup';
|
3
4
|
export { removeMark } from './_tsup-dts-rollup';
|
4
5
|
export { setBlockType } from './_tsup-dts-rollup';
|
@@ -10,8 +11,8 @@ export { createEditor } from './_tsup-dts-rollup';
|
|
10
11
|
export { EditorOptions } from './_tsup-dts-rollup';
|
11
12
|
export { union } from './_tsup-dts-rollup';
|
12
13
|
export { withPriority } from './_tsup-dts-rollup';
|
13
|
-
export { ProseKitError_alias_1 as ProseKitError } from './_tsup-dts-rollup';
|
14
14
|
export { EditorNotFoundError_alias_1 as EditorNotFoundError } from './_tsup-dts-rollup';
|
15
|
+
export { ProseKitError_alias_1 as ProseKitError } from './_tsup-dts-rollup';
|
15
16
|
export { defineBaseCommands } from './_tsup-dts-rollup';
|
16
17
|
export { defineCommands } from './_tsup-dts-rollup';
|
17
18
|
export { defineDefaultState } from './_tsup-dts-rollup';
|
@@ -28,7 +29,6 @@ export { MountHandler } from './_tsup-dts-rollup';
|
|
28
29
|
export { UnmountHandler } from './_tsup-dts-rollup';
|
29
30
|
export { UpdateHandler } from './_tsup-dts-rollup';
|
30
31
|
export { defineHistory } from './_tsup-dts-rollup';
|
31
|
-
export { defineInputRule } from './_tsup-dts-rollup';
|
32
32
|
export { defineBaseKeymap } from './_tsup-dts-rollup';
|
33
33
|
export { defineKeymap } from './_tsup-dts-rollup';
|
34
34
|
export { keymapFacet } from './_tsup-dts-rollup';
|
package/dist/prosekit-core.js
CHANGED
@@ -43,6 +43,59 @@ function addMark(options) {
|
|
43
43
|
};
|
44
44
|
}
|
45
45
|
|
46
|
+
// src/commands/expand-mark.ts
|
47
|
+
import { TextSelection } from "@prosekit/pm/state";
|
48
|
+
function expandMark(options) {
|
49
|
+
return (state, dispatch) => {
|
50
|
+
const markType = getMarkType(state.schema, options.type);
|
51
|
+
const predicate = (mark) => mark.type === markType;
|
52
|
+
const from = expandMarkBefore(state.selection.$from, predicate);
|
53
|
+
const to = expandMarkAfter(state.selection.$to, predicate);
|
54
|
+
if (from === state.selection.from && to === state.selection.to) {
|
55
|
+
return false;
|
56
|
+
}
|
57
|
+
if (dispatch) {
|
58
|
+
dispatch(state.tr.setSelection(TextSelection.create(state.doc, from, to)));
|
59
|
+
}
|
60
|
+
return true;
|
61
|
+
};
|
62
|
+
}
|
63
|
+
function expandMarkBefore($pos, predicate) {
|
64
|
+
const { parent } = $pos;
|
65
|
+
if (!$pos.marks().some(predicate)) {
|
66
|
+
return $pos.pos;
|
67
|
+
}
|
68
|
+
const index = $pos.index();
|
69
|
+
let boundaryIndex = index;
|
70
|
+
for (let i = index; i >= 0; i--) {
|
71
|
+
const node = parent.child(i);
|
72
|
+
if (node.marks.some(predicate)) {
|
73
|
+
boundaryIndex = i;
|
74
|
+
} else {
|
75
|
+
break;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
return $pos.posAtIndex(boundaryIndex);
|
79
|
+
}
|
80
|
+
function expandMarkAfter($pos, predicate) {
|
81
|
+
const { parent } = $pos;
|
82
|
+
if (!$pos.marks().some(predicate)) {
|
83
|
+
return $pos.pos;
|
84
|
+
}
|
85
|
+
const index = Math.max(0, $pos.indexAfter() - 1);
|
86
|
+
const childCount = parent.childCount;
|
87
|
+
let boundaryIndex = index;
|
88
|
+
for (let i = index; i < childCount; i++) {
|
89
|
+
const node = parent.child(i);
|
90
|
+
if (node.marks.some(predicate)) {
|
91
|
+
boundaryIndex = i;
|
92
|
+
} else {
|
93
|
+
break;
|
94
|
+
}
|
95
|
+
}
|
96
|
+
return $pos.posAtIndex(boundaryIndex) + parent.child(boundaryIndex).nodeSize;
|
97
|
+
}
|
98
|
+
|
46
99
|
// src/commands/insert-node.ts
|
47
100
|
import "@prosekit/pm/state";
|
48
101
|
import { insertPoint } from "@prosekit/pm/transform";
|
@@ -61,11 +114,11 @@ function getNodeType(schema, type) {
|
|
61
114
|
}
|
62
115
|
|
63
116
|
// src/utils/set-selection-around.ts
|
64
|
-
import { TextSelection } from "@prosekit/pm/state";
|
117
|
+
import { TextSelection as TextSelection2 } from "@prosekit/pm/state";
|
65
118
|
function setSelectionAround(tr, pos) {
|
66
119
|
const docSize = tr.doc.content.size;
|
67
120
|
const $pos = tr.doc.resolve(pos > docSize ? docSize : pos < 0 ? 0 : pos);
|
68
|
-
const selection =
|
121
|
+
const selection = TextSelection2.between($pos, $pos);
|
69
122
|
tr.setSelection(selection);
|
70
123
|
}
|
71
124
|
|
@@ -115,13 +168,13 @@ function removeMark(options) {
|
|
115
168
|
import "@prosekit/pm/state";
|
116
169
|
|
117
170
|
// src/utils/get-custom-selection.ts
|
118
|
-
import { TextSelection as
|
171
|
+
import { TextSelection as TextSelection3 } from "@prosekit/pm/state";
|
119
172
|
function getCustomSelection(state, from, to) {
|
120
173
|
const pos = from != null ? from : to;
|
121
174
|
if (pos != null) {
|
122
175
|
const $from = state.doc.resolve(from != null ? from : pos);
|
123
176
|
const $to = state.doc.resolve(to != null ? to : pos);
|
124
|
-
return
|
177
|
+
return TextSelection3.between($from, $to);
|
125
178
|
}
|
126
179
|
return state.selection;
|
127
180
|
}
|
@@ -696,12 +749,25 @@ function updateExtension(prevInputs, prevConverters, extension, mode) {
|
|
696
749
|
// src/editor/builder.ts
|
697
750
|
import "@prosekit/pm/model";
|
698
751
|
|
752
|
+
// src/utils/is-mark-active.ts
|
753
|
+
function isMarkActive(state, type, attrs) {
|
754
|
+
const { from, $from, to, empty } = state.selection;
|
755
|
+
const markType = getMarkType(state.schema, type);
|
756
|
+
if (empty) {
|
757
|
+
const mark = attrs ? markType.create(attrs) : markType;
|
758
|
+
return !!mark.isInSet(state.storedMarks || $from.marks());
|
759
|
+
} else {
|
760
|
+
const markOrType = attrs ? markType.create(attrs) : markType;
|
761
|
+
return state.doc.rangeHasMark(from, to, markOrType);
|
762
|
+
}
|
763
|
+
}
|
764
|
+
|
699
765
|
// src/utils/type-assertion.ts
|
700
766
|
import { Mark, ProseMirrorNode } from "@prosekit/pm/model";
|
701
767
|
import {
|
702
768
|
AllSelection,
|
703
769
|
NodeSelection,
|
704
|
-
TextSelection as
|
770
|
+
TextSelection as TextSelection4
|
705
771
|
} from "@prosekit/pm/state";
|
706
772
|
function isProseMirrorNode(node) {
|
707
773
|
return node instanceof ProseMirrorNode;
|
@@ -710,7 +776,7 @@ function isMark(mark) {
|
|
710
776
|
return mark instanceof Mark;
|
711
777
|
}
|
712
778
|
function isTextSelection(sel) {
|
713
|
-
return sel instanceof
|
779
|
+
return sel instanceof TextSelection4;
|
714
780
|
}
|
715
781
|
function isNodeSelection(sel) {
|
716
782
|
return sel instanceof NodeSelection;
|
@@ -719,28 +785,6 @@ function isAllSelection(sel) {
|
|
719
785
|
return sel instanceof AllSelection;
|
720
786
|
}
|
721
787
|
|
722
|
-
// src/utils/is-mark-active.ts
|
723
|
-
function isMarkActive(state, type, attrs) {
|
724
|
-
const markType = getMarkType(state.schema, type);
|
725
|
-
const mark = attrs ? markType.create(attrs) : markType;
|
726
|
-
const { from, $from, to, empty } = state.selection;
|
727
|
-
if (empty) {
|
728
|
-
return hasMark(state.storedMarks || $from.marks(), mark);
|
729
|
-
} else {
|
730
|
-
return state.doc.rangeHasMark(from, to, mark);
|
731
|
-
}
|
732
|
-
}
|
733
|
-
function hasMark(marks, mark) {
|
734
|
-
if (marks.length === 0) {
|
735
|
-
return false;
|
736
|
-
}
|
737
|
-
if (isMark(mark)) {
|
738
|
-
return marks.some((m) => m.eq(mark));
|
739
|
-
} else {
|
740
|
-
return marks.some((m) => m.type === mark);
|
741
|
-
}
|
742
|
-
}
|
743
|
-
|
744
788
|
// src/editor/builder.ts
|
745
789
|
function createNodeBuilder(getState, type) {
|
746
790
|
const builder = (...args) => buildNode(type, args);
|
@@ -1405,16 +1449,11 @@ function defineFocusChangeHandler(handler) {
|
|
1405
1449
|
const handleBlur = () => handler(false);
|
1406
1450
|
const plugin = new ProseMirrorPlugin2({
|
1407
1451
|
key: new PluginKey2("prosekit-focus-handler"),
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1413
|
-
destroy: () => {
|
1414
|
-
dom.removeEventListener("focus", handleFocus);
|
1415
|
-
dom.removeEventListener("blur", handleBlur);
|
1416
|
-
}
|
1417
|
-
};
|
1452
|
+
props: {
|
1453
|
+
handleDOMEvents: {
|
1454
|
+
focus: handleFocus,
|
1455
|
+
blur: handleBlur
|
1456
|
+
}
|
1418
1457
|
}
|
1419
1458
|
});
|
1420
1459
|
return definePlugin(plugin);
|
@@ -1501,32 +1540,6 @@ function defineHistory() {
|
|
1501
1540
|
]);
|
1502
1541
|
}
|
1503
1542
|
|
1504
|
-
// src/extensions/input-rules.ts
|
1505
|
-
import { InputRule, inputRules } from "@prosekit/pm/inputrules";
|
1506
|
-
import "@prosekit/pm/model";
|
1507
|
-
import "@prosekit/pm/state";
|
1508
|
-
function defineInputRule(rule) {
|
1509
|
-
if (rule instanceof InputRule) {
|
1510
|
-
return inputRuleFacet.extension([() => rule]);
|
1511
|
-
}
|
1512
|
-
if (Array.isArray(rule) && rule.every((r) => r instanceof InputRule)) {
|
1513
|
-
return inputRuleFacet.extension([() => rule]);
|
1514
|
-
}
|
1515
|
-
if (typeof rule === "function") {
|
1516
|
-
return inputRuleFacet.extension([rule]);
|
1517
|
-
}
|
1518
|
-
throw new TypeError("Invalid input rule");
|
1519
|
-
}
|
1520
|
-
var inputRuleFacet = Facet.define({
|
1521
|
-
convert: (inputs) => {
|
1522
|
-
return (context) => {
|
1523
|
-
const rules = inputs.flatMap((callback) => callback(context));
|
1524
|
-
return [inputRules({ rules })];
|
1525
|
-
};
|
1526
|
-
},
|
1527
|
-
next: pluginFacet
|
1528
|
-
});
|
1529
|
-
|
1530
1543
|
// src/extensions/mark-spec.ts
|
1531
1544
|
function defineMarkSpec(options) {
|
1532
1545
|
const payload = [options, void 0];
|
@@ -1756,7 +1769,6 @@ export {
|
|
1756
1769
|
defineDocChangeHandler,
|
1757
1770
|
defineFocusChangeHandler,
|
1758
1771
|
defineHistory,
|
1759
|
-
defineInputRule,
|
1760
1772
|
defineKeymap,
|
1761
1773
|
defineMarkAttr,
|
1762
1774
|
defineMarkSpec,
|
@@ -1770,6 +1782,7 @@ export {
|
|
1770
1782
|
defineText,
|
1771
1783
|
defineUnmountHandler,
|
1772
1784
|
defineUpdateHandler,
|
1785
|
+
expandMark,
|
1773
1786
|
getMarkType,
|
1774
1787
|
getNodeType,
|
1775
1788
|
insertNode,
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prosekit/core",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.3.0",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -38,13 +38,13 @@
|
|
38
38
|
"@prosekit/pm": "^0.1.1",
|
39
39
|
"clsx": "^2.1.0",
|
40
40
|
"orderedmap": "^2.1.1",
|
41
|
-
"type-fest": "^4.10.
|
41
|
+
"type-fest": "^4.10.2"
|
42
42
|
},
|
43
43
|
"devDependencies": {
|
44
44
|
"@prosekit/dev": "*",
|
45
45
|
"tsup": "^8.0.1",
|
46
46
|
"typescript": "^5.3.3",
|
47
|
-
"vitest": "^1.2.
|
47
|
+
"vitest": "^1.2.2"
|
48
48
|
},
|
49
49
|
"scripts": {
|
50
50
|
"build:tsup": "tsup",
|