@prosekit/core 0.0.13 → 0.0.14
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 +52 -33
- package/dist/prosekit-core.d.ts +1 -3
- package/dist/prosekit-core.js +118 -78
- package/package.json +1 -1
- package/src/index.ts +4 -3
@@ -1,4 +1,5 @@
|
|
1
1
|
import { Attrs } from '@prosekit/pm/model';
|
2
|
+
import { Attrs as Attrs_2 } from 'prosemirror-model';
|
2
3
|
import { Command } from '@prosekit/pm/state';
|
3
4
|
import type { ConditionalExcept } from 'type-fest';
|
4
5
|
import type { DirectEditorProps } from '@prosekit/pm/view';
|
@@ -11,8 +12,10 @@ import type { IsEqual } from 'type-fest';
|
|
11
12
|
import { Mark } from '@prosekit/pm/model';
|
12
13
|
import type { MarkSpec } from '@prosekit/pm/model';
|
13
14
|
import { MarkType } from '@prosekit/pm/model';
|
15
|
+
import { Node as Node_2 } from 'prosemirror-model';
|
14
16
|
import type { NodeSpec } from '@prosekit/pm/model';
|
15
17
|
import { NodeType } from '@prosekit/pm/model';
|
18
|
+
import { NodeType as NodeType_2 } from 'prosemirror-model';
|
16
19
|
import { NodeViewConstructor } from '@prosekit/pm/view';
|
17
20
|
import { Options } from 'tsup';
|
18
21
|
import { Plugin as Plugin_2 } from '@prosekit/pm/state';
|
@@ -30,11 +33,7 @@ declare type Action = (options: {
|
|
30
33
|
view?: EditorView;
|
31
34
|
}) => boolean;
|
32
35
|
|
33
|
-
declare function addMark(options:
|
34
|
-
export { addMark }
|
35
|
-
export { addMark as addMark_alias_1 }
|
36
|
-
|
37
|
-
declare interface AddMarkOptions {
|
36
|
+
declare function addMark(options: {
|
38
37
|
type: string | MarkType;
|
39
38
|
attrs?: Attrs | null;
|
40
39
|
/**
|
@@ -45,9 +44,9 @@ declare interface AddMarkOptions {
|
|
45
44
|
* The end position of the mark. By default it will be the end position of current selection.
|
46
45
|
*/
|
47
46
|
to?: number;
|
48
|
-
}
|
49
|
-
export {
|
50
|
-
export {
|
47
|
+
}): Command;
|
48
|
+
export { addMark }
|
49
|
+
export { addMark as addMark_alias_1 }
|
51
50
|
|
52
51
|
export declare function applyAction(operator: Action): Command;
|
53
52
|
|
@@ -123,19 +122,14 @@ declare function defineBaseCommands(): Extension<{
|
|
123
122
|
to?: number | undefined;
|
124
123
|
}];
|
125
124
|
insertNode: [{
|
126
|
-
node:
|
125
|
+
node: Node_2;
|
127
126
|
pos?: number | undefined;
|
128
127
|
}];
|
129
128
|
wrap: [{
|
130
|
-
nodeType:
|
131
|
-
attrs?:
|
132
|
-
}];
|
133
|
-
setBlockType: [{
|
134
|
-
nodeType: NodeType;
|
135
|
-
attrs?: Attrs | null | undefined;
|
136
|
-
from?: number | undefined;
|
137
|
-
to?: number | undefined;
|
129
|
+
nodeType: NodeType_2;
|
130
|
+
attrs?: Attrs_2 | null | undefined;
|
138
131
|
}];
|
132
|
+
setBlockType: [nodeType: NodeType_2, attrs?: Attrs_2 | null | undefined];
|
139
133
|
selectAll: [];
|
140
134
|
};
|
141
135
|
}>;
|
@@ -432,11 +426,30 @@ declare function getNodeType(schema: Schema, type: string | NodeType): NodeType;
|
|
432
426
|
export { getNodeType }
|
433
427
|
export { getNodeType as getNodeType_alias_1 }
|
434
428
|
|
435
|
-
|
429
|
+
declare function insertNode(options: {
|
430
|
+
node: ProseMirrorNode;
|
431
|
+
pos?: number;
|
432
|
+
}): Command;
|
433
|
+
|
434
|
+
declare function insertNode(options: {
|
435
|
+
attrs?: Attrs;
|
436
|
+
type: string;
|
437
|
+
pos?: number;
|
438
|
+
}): Command;
|
439
|
+
export { insertNode }
|
440
|
+
export { insertNode as insertNode_alias_1 }
|
441
|
+
|
442
|
+
export declare function insertNode_alias_2({ node, pos, }: {
|
436
443
|
node: ProseMirrorNode;
|
437
444
|
pos?: number;
|
438
445
|
}): Action;
|
439
446
|
|
447
|
+
export declare function insertText({ text, from, to, }: {
|
448
|
+
text: string;
|
449
|
+
from?: number;
|
450
|
+
to?: number;
|
451
|
+
}): Command;
|
452
|
+
|
440
453
|
export declare const isMac: boolean;
|
441
454
|
|
442
455
|
export declare function isMark(mark: unknown): mark is Mark;
|
@@ -568,6 +581,8 @@ export declare const schemaFacet: Facet<SchemaPayload, SchemaPayload>;
|
|
568
581
|
|
569
582
|
export declare type SchemaPayload = SchemaSpec;
|
570
583
|
|
584
|
+
export declare function selectAll(): Command;
|
585
|
+
|
571
586
|
/**
|
572
587
|
* A JSON representation of the prosemirror selection.
|
573
588
|
*
|
@@ -581,6 +596,13 @@ declare interface SelectionJson {
|
|
581
596
|
export { SelectionJson }
|
582
597
|
export { SelectionJson as SelectionJson_alias_1 }
|
583
598
|
|
599
|
+
export declare function setBlockType({ nodeType, attrs, from, to, }: {
|
600
|
+
nodeType: NodeType;
|
601
|
+
attrs?: Attrs | null;
|
602
|
+
from?: number;
|
603
|
+
to?: number;
|
604
|
+
}): Command;
|
605
|
+
|
584
606
|
/**
|
585
607
|
* @internal
|
586
608
|
*/
|
@@ -635,28 +657,20 @@ export declare type ToCommandCreators<T extends CommandArgs> = {
|
|
635
657
|
[K in keyof T]: CommandCreator<T[K]>;
|
636
658
|
};
|
637
659
|
|
638
|
-
declare function toggleMark(
|
660
|
+
declare function toggleMark({ type, attrs, }: {
|
661
|
+
type: string | MarkType;
|
662
|
+
attrs?: Attrs | null;
|
663
|
+
}): Command;
|
639
664
|
export { toggleMark }
|
640
665
|
export { toggleMark as toggleMark_alias_1 }
|
641
666
|
|
642
|
-
declare
|
643
|
-
type: string |
|
667
|
+
declare function toggleNode({ type, attrs, }: {
|
668
|
+
type: string | NodeType;
|
644
669
|
attrs?: Attrs | null;
|
645
|
-
}
|
646
|
-
export { ToggleMarkOptions }
|
647
|
-
export { ToggleMarkOptions as ToggleMarkOptions_alias_1 }
|
648
|
-
|
649
|
-
declare function toggleNode(options: ToggleNodeOptions): Command;
|
670
|
+
}): Command;
|
650
671
|
export { toggleNode }
|
651
672
|
export { toggleNode as toggleNode_alias_1 }
|
652
673
|
|
653
|
-
declare interface ToggleNodeOptions {
|
654
|
-
type: string | NodeType;
|
655
|
-
attrs?: Attrs | null;
|
656
|
-
}
|
657
|
-
export { ToggleNodeOptions }
|
658
|
-
export { ToggleNodeOptions as ToggleNodeOptions_alias_1 }
|
659
|
-
|
660
674
|
declare type Tuple5<T> = [T, T, T, T, T];
|
661
675
|
|
662
676
|
declare function union<E extends Extension | Extension[]>(extension: E): SimplifyExtension<E>;
|
@@ -685,4 +699,9 @@ declare function withPriority<T extends Extension>(extension: T, priority: Prior
|
|
685
699
|
export { withPriority }
|
686
700
|
export { withPriority as withPriority_alias_1 }
|
687
701
|
|
702
|
+
export declare function wrap({ nodeType, attrs, }: {
|
703
|
+
nodeType: NodeType;
|
704
|
+
attrs?: Attrs | null;
|
705
|
+
}): Command;
|
706
|
+
|
688
707
|
export { }
|
package/dist/prosekit-core.d.ts
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
export { addMark } from './_tsup-dts-rollup';
|
2
|
-
export { AddMarkOptions } from './_tsup-dts-rollup';
|
3
2
|
export { toggleMark } from './_tsup-dts-rollup';
|
4
|
-
export {
|
3
|
+
export { insertNode } from './_tsup-dts-rollup';
|
5
4
|
export { toggleNode } from './_tsup-dts-rollup';
|
6
|
-
export { ToggleNodeOptions } from './_tsup-dts-rollup';
|
7
5
|
export { Editor } from './_tsup-dts-rollup';
|
8
6
|
export { createEditor } from './_tsup-dts-rollup';
|
9
7
|
export { EditorOptions } from './_tsup-dts-rollup';
|
package/dist/prosekit-core.js
CHANGED
@@ -40,19 +40,21 @@ function addMark(options) {
|
|
40
40
|
import { toggleMark as baseToggleMark } from "@prosekit/pm/commands";
|
41
41
|
import "@prosekit/pm/model";
|
42
42
|
import "@prosekit/pm/state";
|
43
|
-
function toggleMark(
|
43
|
+
function toggleMark({
|
44
|
+
type,
|
45
|
+
attrs
|
46
|
+
}) {
|
44
47
|
return (state, dispatch, view) => {
|
45
|
-
return baseToggleMark(
|
46
|
-
|
47
|
-
|
48
|
-
|
48
|
+
return baseToggleMark(getMarkType(state.schema, type), attrs)(
|
49
|
+
state,
|
50
|
+
dispatch,
|
51
|
+
view
|
52
|
+
);
|
49
53
|
};
|
50
54
|
}
|
51
55
|
|
52
|
-
// src/commands/
|
53
|
-
import {
|
54
|
-
import "@prosekit/pm/model";
|
55
|
-
import "@prosekit/pm/state";
|
56
|
+
// src/commands/insert-node.ts
|
57
|
+
import { insertPoint } from "@prosekit/pm/transform";
|
56
58
|
|
57
59
|
// src/utils/get-node-type.ts
|
58
60
|
import "@prosekit/pm/model";
|
@@ -67,6 +69,34 @@ function getNodeType(schema, type) {
|
|
67
69
|
return type;
|
68
70
|
}
|
69
71
|
|
72
|
+
// src/commands/insert-node.ts
|
73
|
+
function insertNode(options) {
|
74
|
+
return (state, dispatch) => {
|
75
|
+
var _a;
|
76
|
+
const node = options.node ? options.node : options.type ? getNodeType(state.schema, options.type).createChecked(options.attrs) : null;
|
77
|
+
if (!node) {
|
78
|
+
throw new ProseKitError("You must provide either a node or a type");
|
79
|
+
}
|
80
|
+
const insertPos = insertPoint(
|
81
|
+
state.doc,
|
82
|
+
(_a = options.pos) != null ? _a : state.selection.to,
|
83
|
+
node.type
|
84
|
+
);
|
85
|
+
if (insertPos == null)
|
86
|
+
return false;
|
87
|
+
if (dispatch) {
|
88
|
+
const tr = state.tr.insert(insertPos, node);
|
89
|
+
dispatch(tr);
|
90
|
+
}
|
91
|
+
return true;
|
92
|
+
};
|
93
|
+
}
|
94
|
+
|
95
|
+
// src/commands/toggle-node.ts
|
96
|
+
import { setBlockType } from "@prosekit/pm/commands";
|
97
|
+
import "@prosekit/pm/model";
|
98
|
+
import "@prosekit/pm/state";
|
99
|
+
|
70
100
|
// src/utils/object-euqal.ts
|
71
101
|
function objectEqual(a, b) {
|
72
102
|
if (a === b) {
|
@@ -111,17 +141,20 @@ function isNodeActive(state, type, attrs) {
|
|
111
141
|
}
|
112
142
|
|
113
143
|
// src/commands/toggle-node.ts
|
114
|
-
function toggleNode(
|
144
|
+
function toggleNode({
|
145
|
+
type,
|
146
|
+
attrs
|
147
|
+
}) {
|
115
148
|
return (state, dispatch, view) => {
|
116
|
-
if (isNodeActive(state,
|
149
|
+
if (isNodeActive(state, type, attrs)) {
|
117
150
|
const defaultType = state.schema.topNodeType.contentMatch.defaultType;
|
118
151
|
if (!defaultType) {
|
119
152
|
return false;
|
120
153
|
}
|
121
154
|
return setBlockType(defaultType)(state, dispatch, view);
|
122
155
|
} else {
|
123
|
-
const nodeType = getNodeType(state.schema,
|
124
|
-
return setBlockType(nodeType,
|
156
|
+
const nodeType = getNodeType(state.schema, type);
|
157
|
+
return setBlockType(nodeType, attrs)(state, dispatch, view);
|
125
158
|
}
|
126
159
|
};
|
127
160
|
}
|
@@ -776,77 +809,83 @@ function withPriority(extension, priority) {
|
|
776
809
|
}
|
777
810
|
|
778
811
|
// src/extensions/command.ts
|
779
|
-
import "@prosekit/pm/
|
812
|
+
import { setBlockType as setBlockType2 } from "@prosekit/pm/commands";
|
813
|
+
|
814
|
+
// src/commands/insert-text.ts
|
815
|
+
function insertText({
|
816
|
+
text,
|
817
|
+
from,
|
818
|
+
to
|
819
|
+
}) {
|
820
|
+
return (state, dispatch) => {
|
821
|
+
if (text) {
|
822
|
+
dispatch == null ? void 0 : dispatch(state.tr.insertText(text, from, to));
|
823
|
+
}
|
824
|
+
return true;
|
825
|
+
};
|
826
|
+
}
|
827
|
+
|
828
|
+
// src/commands/select-all.ts
|
780
829
|
import { AllSelection } from "@prosekit/pm/state";
|
781
|
-
|
830
|
+
function selectAll() {
|
831
|
+
return (state, dispatch) => {
|
832
|
+
dispatch == null ? void 0 : dispatch(state.tr.setSelection(new AllSelection(state.doc)));
|
833
|
+
return true;
|
834
|
+
};
|
835
|
+
}
|
836
|
+
|
837
|
+
// src/commands/wrap.ts
|
838
|
+
import "@prosekit/pm/model";
|
839
|
+
import "@prosekit/pm/state";
|
840
|
+
import { findWrapping } from "@prosekit/pm/transform";
|
841
|
+
function wrap({
|
842
|
+
nodeType,
|
843
|
+
attrs
|
844
|
+
}) {
|
845
|
+
return (state, dispatch) => {
|
846
|
+
const { $from, $to } = state.selection;
|
847
|
+
const range = $from.blockRange($to);
|
848
|
+
if (!range)
|
849
|
+
return false;
|
850
|
+
const wrapping = findWrapping(range, nodeType, attrs);
|
851
|
+
if (!wrapping)
|
852
|
+
return false;
|
853
|
+
dispatch == null ? void 0 : dispatch(state.tr.wrap(range, wrapping));
|
854
|
+
return true;
|
855
|
+
};
|
856
|
+
}
|
857
|
+
|
858
|
+
// src/extensions/actions.ts
|
859
|
+
import "@prosekit/pm/model";
|
860
|
+
import { Selection as Selection2 } from "@prosekit/pm/state";
|
861
|
+
import { insertPoint as insertPoint2 } from "@prosekit/pm/transform";
|
862
|
+
function insertNode2({
|
863
|
+
node,
|
864
|
+
pos
|
865
|
+
}) {
|
866
|
+
return ({ tr }) => {
|
867
|
+
const insertPos = insertPoint2(tr.doc, pos != null ? pos : tr.selection.to, node.type);
|
868
|
+
if (insertPos == null) {
|
869
|
+
return false;
|
870
|
+
}
|
871
|
+
tr.insert(insertPos, node);
|
872
|
+
const $pos = tr.doc.resolve(insertPos);
|
873
|
+
tr.setSelection(Selection2.near($pos));
|
874
|
+
return true;
|
875
|
+
};
|
876
|
+
}
|
877
|
+
|
878
|
+
// src/extensions/command.ts
|
782
879
|
function defineCommands(commands) {
|
783
880
|
return commandFacet.extension([commands]);
|
784
881
|
}
|
785
882
|
function defineBaseCommands() {
|
786
883
|
return defineCommands({
|
787
|
-
insertText
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
return (state, dispatch) => {
|
793
|
-
if (text) {
|
794
|
-
dispatch == null ? void 0 : dispatch(state.tr.insertText(text, from, to));
|
795
|
-
}
|
796
|
-
return true;
|
797
|
-
};
|
798
|
-
},
|
799
|
-
insertNode: ({ node, pos }) => {
|
800
|
-
return (state, dispatch) => {
|
801
|
-
const insertPos = insertPoint(
|
802
|
-
state.doc,
|
803
|
-
pos != null ? pos : state.selection.to,
|
804
|
-
node.type
|
805
|
-
);
|
806
|
-
if (insertPos == null)
|
807
|
-
return false;
|
808
|
-
if (dispatch) {
|
809
|
-
const tr = state.tr.insert(insertPos, node);
|
810
|
-
dispatch(tr);
|
811
|
-
}
|
812
|
-
return true;
|
813
|
-
};
|
814
|
-
},
|
815
|
-
wrap: ({
|
816
|
-
nodeType,
|
817
|
-
attrs
|
818
|
-
}) => {
|
819
|
-
return (state, dispatch) => {
|
820
|
-
const { $from, $to } = state.selection;
|
821
|
-
const range = $from.blockRange($to);
|
822
|
-
if (!range)
|
823
|
-
return false;
|
824
|
-
const wrapping = findWrapping(range, nodeType, attrs);
|
825
|
-
if (!wrapping)
|
826
|
-
return false;
|
827
|
-
dispatch == null ? void 0 : dispatch(state.tr.wrap(range, wrapping));
|
828
|
-
return true;
|
829
|
-
};
|
830
|
-
},
|
831
|
-
setBlockType: ({
|
832
|
-
nodeType,
|
833
|
-
attrs,
|
834
|
-
from,
|
835
|
-
to
|
836
|
-
}) => {
|
837
|
-
return (state, dispatch) => {
|
838
|
-
from = from != null ? from : state.selection.from;
|
839
|
-
to = from != null ? from : state.selection.from;
|
840
|
-
dispatch == null ? void 0 : dispatch(state.tr.setBlockType(from, to, nodeType, attrs));
|
841
|
-
return true;
|
842
|
-
};
|
843
|
-
},
|
844
|
-
selectAll: () => {
|
845
|
-
return (state, dispatch) => {
|
846
|
-
dispatch == null ? void 0 : dispatch(state.tr.setSelection(new AllSelection(state.doc)));
|
847
|
-
return true;
|
848
|
-
};
|
849
|
-
}
|
884
|
+
insertText,
|
885
|
+
insertNode: insertNode2,
|
886
|
+
wrap,
|
887
|
+
setBlockType: setBlockType2,
|
888
|
+
selectAll
|
850
889
|
});
|
851
890
|
}
|
852
891
|
|
@@ -1160,6 +1199,7 @@ export {
|
|
1160
1199
|
defineText,
|
1161
1200
|
getMarkType,
|
1162
1201
|
getNodeType,
|
1202
|
+
insertNode,
|
1163
1203
|
pluginFacet,
|
1164
1204
|
toggleMark,
|
1165
1205
|
toggleNode,
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
export { addMark
|
2
|
-
export { toggleMark
|
3
|
-
export {
|
1
|
+
export { addMark } from './commands/add-mark'
|
2
|
+
export { toggleMark } from './commands/toggle-mark'
|
3
|
+
export { insertNode } from './commands/insert-node'
|
4
|
+
export { toggleNode } from './commands/toggle-node'
|
4
5
|
export { Editor, createEditor, type EditorOptions } from './editor/editor'
|
5
6
|
export { Facet, FacetExtension, type FacetOptions } from './facets/facet'
|
6
7
|
export { union } from './editor/type-utils'
|