@prosekit/core 0.2.5 → 0.2.7
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 +90 -3
- package/dist/prosekit-core.d.ts +2 -0
- package/dist/prosekit-core.js +40 -0
- package/package.json +3 -3
- package/src/index.ts +0 -105
@@ -41,7 +41,9 @@ declare type Action = (options: {
|
|
41
41
|
}) => boolean;
|
42
42
|
|
43
43
|
/**
|
44
|
-
*
|
44
|
+
* Returns a command that adds the given mark with the given attributes.
|
45
|
+
*
|
46
|
+
* @public
|
45
47
|
*/
|
46
48
|
declare function addMark(options: {
|
47
49
|
/**
|
@@ -241,6 +243,11 @@ declare function defineBaseCommands(): Extension<{
|
|
241
243
|
from?: number | undefined;
|
242
244
|
to?: number | undefined;
|
243
245
|
}];
|
246
|
+
setNodeAttrs: [options: {
|
247
|
+
type: string | NodeType_2;
|
248
|
+
attrs: Attrs_2;
|
249
|
+
pos?: number | undefined;
|
250
|
+
}];
|
244
251
|
selectAll: [];
|
245
252
|
addMark: [options: {
|
246
253
|
type: string | MarkType_2;
|
@@ -506,7 +513,14 @@ declare class Editor<E extends Extension = any> {
|
|
506
513
|
* Whether the editor is focused.
|
507
514
|
*/
|
508
515
|
get focused(): boolean;
|
509
|
-
|
516
|
+
/**
|
517
|
+
* Mount the editor to the given HTML element.
|
518
|
+
* Pass `null` or `undefined` to unmount the editor.
|
519
|
+
*/
|
520
|
+
mount(place: HTMLElement | null | undefined): void;
|
521
|
+
/**
|
522
|
+
* Unmount the editor. This is equivalent to `mount(null)`.
|
523
|
+
*/
|
510
524
|
unmount(): void;
|
511
525
|
/**
|
512
526
|
* Focus the editor.
|
@@ -524,6 +538,15 @@ declare class Editor<E extends Extension = any> {
|
|
524
538
|
export { Editor }
|
525
539
|
export { Editor as Editor_alias_1 }
|
526
540
|
|
541
|
+
/**
|
542
|
+
* @internal
|
543
|
+
*/
|
544
|
+
declare class EditorNotFoundError extends ProseKitError {
|
545
|
+
constructor();
|
546
|
+
}
|
547
|
+
export { EditorNotFoundError }
|
548
|
+
export { EditorNotFoundError as EditorNotFoundError_alias_1 }
|
549
|
+
|
527
550
|
/**
|
528
551
|
* @public
|
529
552
|
*/
|
@@ -748,6 +771,12 @@ declare function getNodeType(schema: Schema, type: string | NodeType): NodeType;
|
|
748
771
|
export { getNodeType }
|
749
772
|
export { getNodeType as getNodeType_alias_1 }
|
750
773
|
|
774
|
+
/**
|
775
|
+
* Returns a command that inserts the given node at the current selection or at
|
776
|
+
* the given position.
|
777
|
+
*
|
778
|
+
* @public
|
779
|
+
*/
|
751
780
|
declare function insertNode(options: {
|
752
781
|
node: ProseMirrorNode;
|
753
782
|
pos?: number;
|
@@ -767,6 +796,11 @@ export declare function insertNodeAction({ node, pos, }: {
|
|
767
796
|
pos?: number;
|
768
797
|
}): Action;
|
769
798
|
|
799
|
+
/**
|
800
|
+
* Returns a command that inserts the given text.
|
801
|
+
*
|
802
|
+
* @public
|
803
|
+
*/
|
770
804
|
export declare function insertText({ text, from, to, }: {
|
771
805
|
text: string;
|
772
806
|
from?: number;
|
@@ -1104,6 +1138,8 @@ export { Priority as Priority_alias_1 }
|
|
1104
1138
|
|
1105
1139
|
/**
|
1106
1140
|
* Base class for all ProseKit errors.
|
1141
|
+
*
|
1142
|
+
* @internal
|
1107
1143
|
*/
|
1108
1144
|
declare class ProseKitError extends Error {
|
1109
1145
|
}
|
@@ -1111,7 +1147,9 @@ export { ProseKitError }
|
|
1111
1147
|
export { ProseKitError as ProseKitError_alias_1 }
|
1112
1148
|
|
1113
1149
|
/**
|
1114
|
-
*
|
1150
|
+
* Returns a command that removes the given mark.
|
1151
|
+
*
|
1152
|
+
* @public
|
1115
1153
|
*/
|
1116
1154
|
declare function removeMark(options: {
|
1117
1155
|
/**
|
@@ -1138,6 +1176,11 @@ export declare const schemaFacet: Facet<SchemaPayload, SchemaPayload>;
|
|
1138
1176
|
|
1139
1177
|
export declare type SchemaPayload = SchemaSpec;
|
1140
1178
|
|
1179
|
+
/**
|
1180
|
+
* Returns a command that selects the whole document.
|
1181
|
+
*
|
1182
|
+
* @public
|
1183
|
+
*/
|
1141
1184
|
export declare function selectAll(): Command;
|
1142
1185
|
|
1143
1186
|
/**
|
@@ -1156,6 +1199,8 @@ export { SelectionJSON as SelectionJSON_alias_1 }
|
|
1156
1199
|
/**
|
1157
1200
|
* Returns a command that tries to set the selected textblocks to the given node
|
1158
1201
|
* type with the given attributes.
|
1202
|
+
*
|
1203
|
+
* @public
|
1159
1204
|
*/
|
1160
1205
|
declare function setBlockType(options: {
|
1161
1206
|
type: NodeType | string;
|
@@ -1166,6 +1211,31 @@ declare function setBlockType(options: {
|
|
1166
1211
|
export { setBlockType }
|
1167
1212
|
export { setBlockType as setBlockType_alias_1 }
|
1168
1213
|
|
1214
|
+
/**
|
1215
|
+
* Returns a command that set the attributes of the current node.
|
1216
|
+
*
|
1217
|
+
* @public
|
1218
|
+
*/
|
1219
|
+
declare function setNodeAttrs(options: {
|
1220
|
+
/**
|
1221
|
+
* The type of node to set the attributes of.
|
1222
|
+
*
|
1223
|
+
* If current node is not of this type, the command will do nothing.
|
1224
|
+
*/
|
1225
|
+
type: string | NodeType;
|
1226
|
+
/**
|
1227
|
+
* The attributes to set.
|
1228
|
+
*/
|
1229
|
+
attrs: Attrs;
|
1230
|
+
/**
|
1231
|
+
* The position of the node. Defaults to the position of the wrapping node
|
1232
|
+
* containing the current selection.
|
1233
|
+
*/
|
1234
|
+
pos?: number;
|
1235
|
+
}): Command;
|
1236
|
+
export { setNodeAttrs }
|
1237
|
+
export { setNodeAttrs as setNodeAttrs_alias_1 }
|
1238
|
+
|
1169
1239
|
export declare function setSelectionAround(tr: Transaction, pos: number): void;
|
1170
1240
|
|
1171
1241
|
/**
|
@@ -1231,6 +1301,11 @@ export declare type ToCommandCreators<T extends CommandArgs> = {
|
|
1231
1301
|
[K in keyof T]: CommandCreator<T[K]>;
|
1232
1302
|
};
|
1233
1303
|
|
1304
|
+
/**
|
1305
|
+
* Returns a command that toggles the given mark with the given attributes.
|
1306
|
+
*
|
1307
|
+
* @public
|
1308
|
+
*/
|
1234
1309
|
declare function toggleMark({ type, attrs, }: {
|
1235
1310
|
type: string | MarkType;
|
1236
1311
|
attrs?: Attrs | null;
|
@@ -1238,6 +1313,12 @@ declare function toggleMark({ type, attrs, }: {
|
|
1238
1313
|
export { toggleMark }
|
1239
1314
|
export { toggleMark as toggleMark_alias_1 }
|
1240
1315
|
|
1316
|
+
/**
|
1317
|
+
* Returns a command that set the selected textblocks to the given node type
|
1318
|
+
* with the given attributes.
|
1319
|
+
*
|
1320
|
+
* @public
|
1321
|
+
*/
|
1241
1322
|
declare function toggleNode({ type, attrs, }: {
|
1242
1323
|
type: string | NodeType;
|
1243
1324
|
attrs?: Attrs | null;
|
@@ -1317,6 +1398,12 @@ declare function withSkipCodeBlock(command: Command): Command;
|
|
1317
1398
|
export { withSkipCodeBlock }
|
1318
1399
|
export { withSkipCodeBlock as withSkipCodeBlock_alias_1 }
|
1319
1400
|
|
1401
|
+
/**
|
1402
|
+
* Returns a command that wraps the selected textblock with the given node type
|
1403
|
+
* with the given attributes.
|
1404
|
+
*
|
1405
|
+
* @public
|
1406
|
+
*/
|
1320
1407
|
export declare function wrap({ nodeType, attrs, }: {
|
1321
1408
|
nodeType: NodeType;
|
1322
1409
|
attrs?: Attrs | null;
|
package/dist/prosekit-core.d.ts
CHANGED
@@ -2,6 +2,7 @@ export { addMark } from './_tsup-dts-rollup';
|
|
2
2
|
export { insertNode } from './_tsup-dts-rollup';
|
3
3
|
export { removeMark } from './_tsup-dts-rollup';
|
4
4
|
export { setBlockType } from './_tsup-dts-rollup';
|
5
|
+
export { setNodeAttrs } from './_tsup-dts-rollup';
|
5
6
|
export { toggleMark } from './_tsup-dts-rollup';
|
6
7
|
export { toggleNode } from './_tsup-dts-rollup';
|
7
8
|
export { Editor } from './_tsup-dts-rollup';
|
@@ -10,6 +11,7 @@ export { EditorOptions } from './_tsup-dts-rollup';
|
|
10
11
|
export { union } from './_tsup-dts-rollup';
|
11
12
|
export { withPriority } from './_tsup-dts-rollup';
|
12
13
|
export { ProseKitError_alias_1 as ProseKitError } from './_tsup-dts-rollup';
|
14
|
+
export { EditorNotFoundError_alias_1 as EditorNotFoundError } from './_tsup-dts-rollup';
|
13
15
|
export { defineBaseCommands } from './_tsup-dts-rollup';
|
14
16
|
export { defineCommands } from './_tsup-dts-rollup';
|
15
17
|
export { defineDefaultState } from './_tsup-dts-rollup';
|
package/dist/prosekit-core.js
CHANGED
@@ -8,6 +8,13 @@ import "@prosekit/pm/model";
|
|
8
8
|
// src/error.ts
|
9
9
|
var ProseKitError = class extends Error {
|
10
10
|
};
|
11
|
+
var EditorNotFoundError = class extends ProseKitError {
|
12
|
+
constructor() {
|
13
|
+
super(
|
14
|
+
"Unable to find editor. Pass it as an argument or call this function inside a ProseKit component."
|
15
|
+
);
|
16
|
+
}
|
17
|
+
};
|
11
18
|
|
12
19
|
// src/utils/get-mark-type.ts
|
13
20
|
function getMarkType(schema, type) {
|
@@ -161,6 +168,29 @@ function setBlockType(options) {
|
|
161
168
|
};
|
162
169
|
}
|
163
170
|
|
171
|
+
// src/commands/set-node-attrs.ts
|
172
|
+
function setNodeAttrs(options) {
|
173
|
+
return (state, dispatch) => {
|
174
|
+
var _a;
|
175
|
+
const nodeType = getNodeType(state.schema, options.type);
|
176
|
+
const pos = (_a = options.pos) != null ? _a : state.selection.$from.before();
|
177
|
+
const node = state.doc.nodeAt(pos);
|
178
|
+
if (!node || node.type !== nodeType) {
|
179
|
+
return false;
|
180
|
+
}
|
181
|
+
if (dispatch) {
|
182
|
+
const { tr } = state;
|
183
|
+
for (const [key, value] of Object.entries(options.attrs)) {
|
184
|
+
if (value !== void 0) {
|
185
|
+
tr.setNodeAttribute(pos, key, value);
|
186
|
+
}
|
187
|
+
}
|
188
|
+
dispatch(tr);
|
189
|
+
}
|
190
|
+
return true;
|
191
|
+
};
|
192
|
+
}
|
193
|
+
|
164
194
|
// src/commands/toggle-mark.ts
|
165
195
|
import { toggleMark as baseToggleMark } from "@prosekit/pm/commands";
|
166
196
|
import "@prosekit/pm/model";
|
@@ -1015,6 +1045,10 @@ var Editor = class _Editor {
|
|
1015
1045
|
var _a, _b;
|
1016
1046
|
return (_b = (_a = this.instance.view) == null ? void 0 : _a.hasFocus()) != null ? _b : false;
|
1017
1047
|
}
|
1048
|
+
/**
|
1049
|
+
* Mount the editor to the given HTML element.
|
1050
|
+
* Pass `null` or `undefined` to unmount the editor.
|
1051
|
+
*/
|
1018
1052
|
mount(place) {
|
1019
1053
|
if (!place) {
|
1020
1054
|
return this.unmount();
|
@@ -1022,6 +1056,9 @@ var Editor = class _Editor {
|
|
1022
1056
|
this.instance.mount(place);
|
1023
1057
|
this.afterMounted.forEach((callback) => callback());
|
1024
1058
|
}
|
1059
|
+
/**
|
1060
|
+
* Unmount the editor. This is equivalent to `mount(null)`.
|
1061
|
+
*/
|
1025
1062
|
unmount() {
|
1026
1063
|
if (this.mounted) {
|
1027
1064
|
this.instance.unmount();
|
@@ -1127,6 +1164,7 @@ function defineBaseCommands() {
|
|
1127
1164
|
insertNode,
|
1128
1165
|
wrap,
|
1129
1166
|
setBlockType,
|
1167
|
+
setNodeAttrs,
|
1130
1168
|
selectAll,
|
1131
1169
|
addMark,
|
1132
1170
|
removeMark
|
@@ -1700,6 +1738,7 @@ function withSkipCodeBlock(command) {
|
|
1700
1738
|
}
|
1701
1739
|
export {
|
1702
1740
|
Editor,
|
1741
|
+
EditorNotFoundError,
|
1703
1742
|
Facet,
|
1704
1743
|
OBJECT_REPLACEMENT_CHARACTER,
|
1705
1744
|
Priority,
|
@@ -1751,6 +1790,7 @@ export {
|
|
1751
1790
|
pluginFacet,
|
1752
1791
|
removeMark,
|
1753
1792
|
setBlockType,
|
1793
|
+
setNodeAttrs,
|
1754
1794
|
stateFromJSON,
|
1755
1795
|
toggleMark,
|
1756
1796
|
toggleNode,
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prosekit/core",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.2.
|
4
|
+
"version": "0.2.7",
|
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.
|
41
|
+
"type-fest": "^4.10.1"
|
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.1"
|
48
48
|
},
|
49
49
|
"scripts": {
|
50
50
|
"build:tsup": "tsup",
|
package/src/index.ts
DELETED
@@ -1,105 +0,0 @@
|
|
1
|
-
export { addMark } from './commands/add-mark'
|
2
|
-
export { insertNode } from './commands/insert-node'
|
3
|
-
export { removeMark } from './commands/remove-mark'
|
4
|
-
export { setBlockType } from './commands/set-block-type'
|
5
|
-
export { toggleMark } from './commands/toggle-mark'
|
6
|
-
export { toggleNode } from './commands/toggle-node'
|
7
|
-
export { Editor, createEditor, type EditorOptions } from './editor/editor'
|
8
|
-
export { union } from './editor/union'
|
9
|
-
export { withPriority } from './editor/with-priority'
|
10
|
-
export { ProseKitError } from './error'
|
11
|
-
export { defineBaseCommands, defineCommands } from './extensions/command'
|
12
|
-
export {
|
13
|
-
defineDefaultState,
|
14
|
-
type DefaultStateOptions,
|
15
|
-
} from './extensions/default-state'
|
16
|
-
export { defineDoc } from './extensions/doc'
|
17
|
-
export {
|
18
|
-
defineDocChangeHandler,
|
19
|
-
type DocChangeHandler,
|
20
|
-
} from './extensions/events/doc-change'
|
21
|
-
export {
|
22
|
-
defineFocusChangeHandler,
|
23
|
-
type FocusChangeHandler,
|
24
|
-
} from './extensions/events/focus'
|
25
|
-
export {
|
26
|
-
defineMountHandler,
|
27
|
-
defineUnmountHandler,
|
28
|
-
defineUpdateHandler,
|
29
|
-
type MountHandler,
|
30
|
-
type UnmountHandler,
|
31
|
-
type UpdateHandler,
|
32
|
-
} from './extensions/events/plugin-view'
|
33
|
-
export { defineHistory } from './extensions/history'
|
34
|
-
export { defineInputRule } from './extensions/input-rules'
|
35
|
-
export {
|
36
|
-
defineBaseKeymap,
|
37
|
-
defineKeymap,
|
38
|
-
keymapFacet,
|
39
|
-
type Keymap,
|
40
|
-
type KeymapPayload,
|
41
|
-
} from './extensions/keymap'
|
42
|
-
export {
|
43
|
-
defineMarkAttr,
|
44
|
-
defineMarkSpec,
|
45
|
-
type MarkAttrOptions,
|
46
|
-
type MarkSpecOptions,
|
47
|
-
} from './extensions/mark-spec'
|
48
|
-
export {
|
49
|
-
defineNodeAttr,
|
50
|
-
defineNodeSpec,
|
51
|
-
type NodeAttrOptions,
|
52
|
-
type NodeSpecOptions,
|
53
|
-
} from './extensions/node-spec'
|
54
|
-
export { defineNodeView, type NodeViewOptions } from './extensions/node-view'
|
55
|
-
export {
|
56
|
-
defineNodeViewFactory,
|
57
|
-
type NodeViewFactoryOptions,
|
58
|
-
} from './extensions/node-view-effect'
|
59
|
-
export { defineParagraph } from './extensions/paragraph'
|
60
|
-
export {
|
61
|
-
definePlugin,
|
62
|
-
pluginFacet,
|
63
|
-
type PluginPayload,
|
64
|
-
} from './extensions/plugin'
|
65
|
-
export { defineText } from './extensions/text'
|
66
|
-
export { Facet, type FacetOptions } from './facets/facet'
|
67
|
-
export type { BaseNodeViewOptions } from './types/base-node-view-options'
|
68
|
-
export { type CommandArgs } from './types/command'
|
69
|
-
export {
|
70
|
-
type Extension,
|
71
|
-
type ExtractCommandAppliers,
|
72
|
-
type ExtractCommandCreators,
|
73
|
-
type ExtractMarks,
|
74
|
-
type ExtractNodes,
|
75
|
-
type SimplifyExtension,
|
76
|
-
} from './types/extension'
|
77
|
-
export { type ExtensionTyping } from './types/extension-typing'
|
78
|
-
export type { NodeJSON, SelectionJSON, StateJSON } from './types/model'
|
79
|
-
export { Priority } from './types/priority'
|
80
|
-
export { type SimplifyUnion } from './types/simplify-union'
|
81
|
-
export { clsx } from './utils/clsx'
|
82
|
-
export { defaultBlockAt } from './utils/default-block-at'
|
83
|
-
export { getId as _getId } from './utils/get-id'
|
84
|
-
export { getMarkType } from './utils/get-mark-type'
|
85
|
-
export { getNodeType } from './utils/get-node-type'
|
86
|
-
export { isInCodeBlock } from './utils/is-in-code-block'
|
87
|
-
export {
|
88
|
-
jsonFromElement,
|
89
|
-
jsonFromHTML,
|
90
|
-
jsonFromNode,
|
91
|
-
jsonFromState,
|
92
|
-
nodeFromElement,
|
93
|
-
nodeFromHTML,
|
94
|
-
nodeFromJSON,
|
95
|
-
stateFromJSON,
|
96
|
-
} from './utils/parse'
|
97
|
-
export {
|
98
|
-
isAllSelection,
|
99
|
-
isMark,
|
100
|
-
isNodeSelection,
|
101
|
-
isProseMirrorNode,
|
102
|
-
isTextSelection,
|
103
|
-
} from './utils/type-assertion'
|
104
|
-
export * from './utils/unicode'
|
105
|
-
export { withSkipCodeBlock } from './utils/with-skip-code-block'
|