@prosekit/core 0.2.5 → 0.2.6
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 +71 -2
- package/dist/prosekit-core.d.ts +1 -0
- package/dist/prosekit-core.js +25 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
@@ -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;
|
@@ -748,6 +755,12 @@ declare function getNodeType(schema: Schema, type: string | NodeType): NodeType;
|
|
748
755
|
export { getNodeType }
|
749
756
|
export { getNodeType as getNodeType_alias_1 }
|
750
757
|
|
758
|
+
/**
|
759
|
+
* Returns a command that inserts the given node at the current selection or at
|
760
|
+
* the given position.
|
761
|
+
*
|
762
|
+
* @public
|
763
|
+
*/
|
751
764
|
declare function insertNode(options: {
|
752
765
|
node: ProseMirrorNode;
|
753
766
|
pos?: number;
|
@@ -767,6 +780,11 @@ export declare function insertNodeAction({ node, pos, }: {
|
|
767
780
|
pos?: number;
|
768
781
|
}): Action;
|
769
782
|
|
783
|
+
/**
|
784
|
+
* Returns a command that inserts the given text.
|
785
|
+
*
|
786
|
+
* @public
|
787
|
+
*/
|
770
788
|
export declare function insertText({ text, from, to, }: {
|
771
789
|
text: string;
|
772
790
|
from?: number;
|
@@ -1111,7 +1129,9 @@ export { ProseKitError }
|
|
1111
1129
|
export { ProseKitError as ProseKitError_alias_1 }
|
1112
1130
|
|
1113
1131
|
/**
|
1114
|
-
*
|
1132
|
+
* Returns a command that removes the given mark.
|
1133
|
+
*
|
1134
|
+
* @public
|
1115
1135
|
*/
|
1116
1136
|
declare function removeMark(options: {
|
1117
1137
|
/**
|
@@ -1138,6 +1158,11 @@ export declare const schemaFacet: Facet<SchemaPayload, SchemaPayload>;
|
|
1138
1158
|
|
1139
1159
|
export declare type SchemaPayload = SchemaSpec;
|
1140
1160
|
|
1161
|
+
/**
|
1162
|
+
* Returns a command that selects the whole document.
|
1163
|
+
*
|
1164
|
+
* @public
|
1165
|
+
*/
|
1141
1166
|
export declare function selectAll(): Command;
|
1142
1167
|
|
1143
1168
|
/**
|
@@ -1156,6 +1181,8 @@ export { SelectionJSON as SelectionJSON_alias_1 }
|
|
1156
1181
|
/**
|
1157
1182
|
* Returns a command that tries to set the selected textblocks to the given node
|
1158
1183
|
* type with the given attributes.
|
1184
|
+
*
|
1185
|
+
* @public
|
1159
1186
|
*/
|
1160
1187
|
declare function setBlockType(options: {
|
1161
1188
|
type: NodeType | string;
|
@@ -1166,6 +1193,31 @@ declare function setBlockType(options: {
|
|
1166
1193
|
export { setBlockType }
|
1167
1194
|
export { setBlockType as setBlockType_alias_1 }
|
1168
1195
|
|
1196
|
+
/**
|
1197
|
+
* Returns a command that set the attributes of the current node.
|
1198
|
+
*
|
1199
|
+
* @public
|
1200
|
+
*/
|
1201
|
+
declare function setNodeAttrs(options: {
|
1202
|
+
/**
|
1203
|
+
* The type of node to set the attributes of.
|
1204
|
+
*
|
1205
|
+
* If current node is not of this type, the command will do nothing.
|
1206
|
+
*/
|
1207
|
+
type: string | NodeType;
|
1208
|
+
/**
|
1209
|
+
* The attributes to set.
|
1210
|
+
*/
|
1211
|
+
attrs: Attrs;
|
1212
|
+
/**
|
1213
|
+
* The position of the node. Defaults to the position of the wrapping node
|
1214
|
+
* containing the current selection.
|
1215
|
+
*/
|
1216
|
+
pos?: number;
|
1217
|
+
}): Command;
|
1218
|
+
export { setNodeAttrs }
|
1219
|
+
export { setNodeAttrs as setNodeAttrs_alias_1 }
|
1220
|
+
|
1169
1221
|
export declare function setSelectionAround(tr: Transaction, pos: number): void;
|
1170
1222
|
|
1171
1223
|
/**
|
@@ -1231,6 +1283,11 @@ export declare type ToCommandCreators<T extends CommandArgs> = {
|
|
1231
1283
|
[K in keyof T]: CommandCreator<T[K]>;
|
1232
1284
|
};
|
1233
1285
|
|
1286
|
+
/**
|
1287
|
+
* Returns a command that toggles the given mark with the given attributes.
|
1288
|
+
*
|
1289
|
+
* @public
|
1290
|
+
*/
|
1234
1291
|
declare function toggleMark({ type, attrs, }: {
|
1235
1292
|
type: string | MarkType;
|
1236
1293
|
attrs?: Attrs | null;
|
@@ -1238,6 +1295,12 @@ declare function toggleMark({ type, attrs, }: {
|
|
1238
1295
|
export { toggleMark }
|
1239
1296
|
export { toggleMark as toggleMark_alias_1 }
|
1240
1297
|
|
1298
|
+
/**
|
1299
|
+
* Returns a command that set the selected textblocks to the given node type
|
1300
|
+
* with the given attributes.
|
1301
|
+
*
|
1302
|
+
* @public
|
1303
|
+
*/
|
1241
1304
|
declare function toggleNode({ type, attrs, }: {
|
1242
1305
|
type: string | NodeType;
|
1243
1306
|
attrs?: Attrs | null;
|
@@ -1317,6 +1380,12 @@ declare function withSkipCodeBlock(command: Command): Command;
|
|
1317
1380
|
export { withSkipCodeBlock }
|
1318
1381
|
export { withSkipCodeBlock as withSkipCodeBlock_alias_1 }
|
1319
1382
|
|
1383
|
+
/**
|
1384
|
+
* Returns a command that wraps the selected textblock with the given node type
|
1385
|
+
* with the given attributes.
|
1386
|
+
*
|
1387
|
+
* @public
|
1388
|
+
*/
|
1320
1389
|
export declare function wrap({ nodeType, attrs, }: {
|
1321
1390
|
nodeType: NodeType;
|
1322
1391
|
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';
|
package/dist/prosekit-core.js
CHANGED
@@ -161,6 +161,29 @@ function setBlockType(options) {
|
|
161
161
|
};
|
162
162
|
}
|
163
163
|
|
164
|
+
// src/commands/set-node-attrs.ts
|
165
|
+
function setNodeAttrs(options) {
|
166
|
+
return (state, dispatch) => {
|
167
|
+
var _a;
|
168
|
+
const nodeType = getNodeType(state.schema, options.type);
|
169
|
+
const pos = (_a = options.pos) != null ? _a : state.selection.$from.before();
|
170
|
+
const node = state.doc.nodeAt(pos);
|
171
|
+
if (!node || node.type !== nodeType) {
|
172
|
+
return false;
|
173
|
+
}
|
174
|
+
if (dispatch) {
|
175
|
+
const { tr } = state;
|
176
|
+
for (const [key, value] of Object.entries(options.attrs)) {
|
177
|
+
if (value !== void 0) {
|
178
|
+
tr.setNodeAttribute(pos, key, value);
|
179
|
+
}
|
180
|
+
}
|
181
|
+
dispatch(tr);
|
182
|
+
}
|
183
|
+
return true;
|
184
|
+
};
|
185
|
+
}
|
186
|
+
|
164
187
|
// src/commands/toggle-mark.ts
|
165
188
|
import { toggleMark as baseToggleMark } from "@prosekit/pm/commands";
|
166
189
|
import "@prosekit/pm/model";
|
@@ -1127,6 +1150,7 @@ function defineBaseCommands() {
|
|
1127
1150
|
insertNode,
|
1128
1151
|
wrap,
|
1129
1152
|
setBlockType,
|
1153
|
+
setNodeAttrs,
|
1130
1154
|
selectAll,
|
1131
1155
|
addMark,
|
1132
1156
|
removeMark
|
@@ -1751,6 +1775,7 @@ export {
|
|
1751
1775
|
pluginFacet,
|
1752
1776
|
removeMark,
|
1753
1777
|
setBlockType,
|
1778
|
+
setNodeAttrs,
|
1754
1779
|
stateFromJSON,
|
1755
1780
|
toggleMark,
|
1756
1781
|
toggleNode,
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
@@ -2,6 +2,7 @@ export { addMark } from './commands/add-mark'
|
|
2
2
|
export { insertNode } from './commands/insert-node'
|
3
3
|
export { removeMark } from './commands/remove-mark'
|
4
4
|
export { setBlockType } from './commands/set-block-type'
|
5
|
+
export { setNodeAttrs } from './commands/set-node-attrs'
|
5
6
|
export { toggleMark } from './commands/toggle-mark'
|
6
7
|
export { toggleNode } from './commands/toggle-node'
|
7
8
|
export { Editor, createEditor, type EditorOptions } from './editor/editor'
|