@prosekit/core 0.2.1 → 0.2.3
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 +166 -5
- package/dist/prosekit-core.d.ts +13 -1
- package/dist/prosekit-core.js +264 -66
- package/package.json +3 -2
- package/src/index.ts +25 -3
@@ -120,6 +120,17 @@ declare interface BaseNodeViewOptions {
|
|
120
120
|
export { BaseNodeViewOptions }
|
121
121
|
export { BaseNodeViewOptions as BaseNodeViewOptions_alias_1 }
|
122
122
|
|
123
|
+
/**
|
124
|
+
* A utility for constructing `className` strings conditionally.
|
125
|
+
*
|
126
|
+
* It is a re-export of [clsx/lite](https://www.npmjs.com/package/clsx) with stricter types.
|
127
|
+
*
|
128
|
+
* @public
|
129
|
+
*/
|
130
|
+
declare const clsx: (...args: Array<string | boolean | null | undefined>) => string;
|
131
|
+
export { clsx }
|
132
|
+
export { clsx as clsx_alias_1 }
|
133
|
+
|
123
134
|
export declare function collectNodes(content: NodeContent): ProseMirrorNode[];
|
124
135
|
|
125
136
|
export declare interface CommandApplier<Args extends any[] = any[]> {
|
@@ -277,6 +288,15 @@ NODES: "doc";
|
|
277
288
|
export { defineDoc }
|
278
289
|
export { defineDoc as defineDoc_alias_1 }
|
279
290
|
|
291
|
+
/**
|
292
|
+
* Registers a event handler that is called when the editor document is changed.
|
293
|
+
*
|
294
|
+
* @public
|
295
|
+
*/
|
296
|
+
declare function defineDocChangeHandler(handler: DocChangeHandler): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
297
|
+
export { defineDocChangeHandler }
|
298
|
+
export { defineDocChangeHandler as defineDocChangeHandler_alias_1 }
|
299
|
+
|
280
300
|
/**
|
281
301
|
* Add undo/redo history to the editor.
|
282
302
|
*/
|
@@ -312,6 +332,13 @@ declare function defineKeymap(keymap: Keymap): Extension;
|
|
312
332
|
export { defineKeymap }
|
313
333
|
export { defineKeymap as defineKeymap_alias_1 }
|
314
334
|
|
335
|
+
/**
|
336
|
+
* @public
|
337
|
+
*/
|
338
|
+
declare function defineMarkAttr(options: MarkAttrOptions): Extension;
|
339
|
+
export { defineMarkAttr }
|
340
|
+
export { defineMarkAttr as defineMarkAttr_alias_1 }
|
341
|
+
|
315
342
|
/**
|
316
343
|
* @public
|
317
344
|
*/
|
@@ -322,6 +349,26 @@ export { defineMarkSpec }
|
|
322
349
|
export { defineMarkSpec as defineMarkSpec_alias_1 }
|
323
350
|
|
324
351
|
/**
|
352
|
+
* Registers a event handler that is called when the editor view is mounted.
|
353
|
+
*
|
354
|
+
* @public
|
355
|
+
*/
|
356
|
+
declare function defineMountHandler(handler: MountHandler): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
357
|
+
export { defineMountHandler }
|
358
|
+
export { defineMountHandler as defineMountHandler_alias_1 }
|
359
|
+
|
360
|
+
/**
|
361
|
+
* Defines an attribute for a node type.
|
362
|
+
*
|
363
|
+
* @public
|
364
|
+
*/
|
365
|
+
declare function defineNodeAttr(options: NodeAttrOptions): Extension;
|
366
|
+
export { defineNodeAttr }
|
367
|
+
export { defineNodeAttr as defineNodeAttr_alias_1 }
|
368
|
+
|
369
|
+
/**
|
370
|
+
* Defines a node type.
|
371
|
+
*
|
325
372
|
* @public
|
326
373
|
*/
|
327
374
|
declare function defineNodeSpec<NodeName extends string>(options: NodeSpecOptions<NodeName>): Extension<{
|
@@ -385,12 +432,35 @@ export { defineText }
|
|
385
432
|
export { defineText as defineText_alias_1 }
|
386
433
|
|
387
434
|
/**
|
388
|
-
*
|
435
|
+
* Registers a event handler that is called when the editor view is unmounted.
|
436
|
+
*
|
437
|
+
* @public
|
438
|
+
*/
|
439
|
+
declare function defineUnmountHandler(handler: UnmountHandler): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
440
|
+
export { defineUnmountHandler }
|
441
|
+
export { defineUnmountHandler as defineUnmountHandler_alias_1 }
|
442
|
+
|
443
|
+
/**
|
444
|
+
* Registers a event handler that is called when the editor state is updated.
|
445
|
+
*
|
446
|
+
* @public
|
389
447
|
*/
|
390
448
|
declare function defineUpdateHandler(handler: UpdateHandler): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
391
449
|
export { defineUpdateHandler }
|
392
450
|
export { defineUpdateHandler as defineUpdateHandler_alias_1 }
|
393
451
|
|
452
|
+
/**
|
453
|
+
* A function that is called when the editor document is changed.
|
454
|
+
*
|
455
|
+
* @param view - The editor view.
|
456
|
+
* @param prevState - The previous editor state.
|
457
|
+
*
|
458
|
+
* @public
|
459
|
+
*/
|
460
|
+
declare type DocChangeHandler = (view: EditorView, prevState: EditorState) => void;
|
461
|
+
export { DocChangeHandler }
|
462
|
+
export { DocChangeHandler as DocChangeHandler_alias_1 }
|
463
|
+
|
394
464
|
/**
|
395
465
|
* @public
|
396
466
|
*/
|
@@ -660,6 +730,8 @@ declare function isAllSelection(sel: Selection_2): sel is AllSelection;
|
|
660
730
|
export { isAllSelection }
|
661
731
|
export { isAllSelection as isAllSelection_alias_1 }
|
662
732
|
|
733
|
+
export declare function isElement(value: unknown): value is Element;
|
734
|
+
|
663
735
|
export declare const isMac: boolean;
|
664
736
|
|
665
737
|
/**
|
@@ -755,6 +827,36 @@ declare type KeymapPayload = Keymap;
|
|
755
827
|
export { KeymapPayload }
|
756
828
|
export { KeymapPayload as KeymapPayload_alias_1 }
|
757
829
|
|
830
|
+
/**
|
831
|
+
* @public
|
832
|
+
*/
|
833
|
+
declare interface MarkAttrOptions {
|
834
|
+
/**
|
835
|
+
* The name of the mark type.
|
836
|
+
*/
|
837
|
+
type: string;
|
838
|
+
/**
|
839
|
+
* The name of the attribute.
|
840
|
+
*/
|
841
|
+
attr: string;
|
842
|
+
/**
|
843
|
+
* The default value for this attribute, to use when no explicit value is
|
844
|
+
* provided. Attributes that have no default must be provided whenever a mark
|
845
|
+
* of a type that has them is created.
|
846
|
+
*/
|
847
|
+
default?: any;
|
848
|
+
/**
|
849
|
+
* Returns the attribute key and value to be set on the DOM node.
|
850
|
+
*/
|
851
|
+
toDOM?: (value: any) => [key: string, value: string] | null | void;
|
852
|
+
/**
|
853
|
+
* Parses the attribute value from the DOM.
|
854
|
+
*/
|
855
|
+
parseDOM?: (node: HTMLElement) => any;
|
856
|
+
}
|
857
|
+
export { MarkAttrOptions }
|
858
|
+
export { MarkAttrOptions as MarkAttrOptions_alias_1 }
|
859
|
+
|
758
860
|
export declare interface MarkBuilder {
|
759
861
|
(attrs: Attrs | null, ...children: NodeChild[]): ProseMirrorNode[];
|
760
862
|
(...children: NodeChild[]): ProseMirrorNode[];
|
@@ -770,6 +872,47 @@ declare interface MarkSpecOptions<MarkName extends string = string> extends Mark
|
|
770
872
|
export { MarkSpecOptions }
|
771
873
|
export { MarkSpecOptions as MarkSpecOptions_alias_1 }
|
772
874
|
|
875
|
+
/**
|
876
|
+
* A function that is called when the editor view is mounted.
|
877
|
+
*
|
878
|
+
* @param view - The editor view.
|
879
|
+
*
|
880
|
+
* @public
|
881
|
+
*/
|
882
|
+
declare type MountHandler = (view: EditorView) => void;
|
883
|
+
export { MountHandler }
|
884
|
+
export { MountHandler as MountHandler_alias_1 }
|
885
|
+
|
886
|
+
/**
|
887
|
+
* @public
|
888
|
+
*/
|
889
|
+
declare interface NodeAttrOptions {
|
890
|
+
/**
|
891
|
+
* The name of the node type.
|
892
|
+
*/
|
893
|
+
type: string;
|
894
|
+
/**
|
895
|
+
* The name of the attribute.
|
896
|
+
*/
|
897
|
+
attr: string;
|
898
|
+
/**
|
899
|
+
* The default value for this attribute, to use when no explicit value is
|
900
|
+
* provided. Attributes that have no default must be provided whenever a node
|
901
|
+
* of a type that has them is created.
|
902
|
+
*/
|
903
|
+
default?: any;
|
904
|
+
/**
|
905
|
+
* Returns the attribute key and value to be set on the DOM node.
|
906
|
+
*/
|
907
|
+
toDOM?: (value: any) => [key: string, value: string] | null | void;
|
908
|
+
/**
|
909
|
+
* Parses the attribute value from the DOM.
|
910
|
+
*/
|
911
|
+
parseDOM?: (node: HTMLElement) => any;
|
912
|
+
}
|
913
|
+
export { NodeAttrOptions }
|
914
|
+
export { NodeAttrOptions as NodeAttrOptions_alias_1 }
|
915
|
+
|
773
916
|
export declare interface NodeBuilder {
|
774
917
|
(attrs: Attrs | null, ...children: NodeChild[]): ProseMirrorNode;
|
775
918
|
(...children: NodeChild[]): ProseMirrorNode;
|
@@ -879,6 +1022,8 @@ export { PluginPayload }
|
|
879
1022
|
export { PluginPayload as PluginPayload_alias_1 }
|
880
1023
|
|
881
1024
|
/**
|
1025
|
+
* ProseKit extension priority.
|
1026
|
+
*
|
882
1027
|
* @public
|
883
1028
|
*/
|
884
1029
|
declare const enum Priority {
|
@@ -1053,6 +1198,15 @@ export declare function uniqPush<T>(prev: readonly T[], next: readonly T[]): T[]
|
|
1053
1198
|
|
1054
1199
|
export declare function uniqRemove<T>(prev: T[], next: T[]): T[];
|
1055
1200
|
|
1201
|
+
/**
|
1202
|
+
* A function that is called when the editor view is unmounted.
|
1203
|
+
*
|
1204
|
+
* @public
|
1205
|
+
*/
|
1206
|
+
declare type UnmountHandler = () => void;
|
1207
|
+
export { UnmountHandler }
|
1208
|
+
export { UnmountHandler as UnmountHandler_alias_1 }
|
1209
|
+
|
1056
1210
|
export declare function updateExtension(prevInputs: Payloads, prevConverters: Converters, extension: Extension, mode: 'add' | 'remove'): {
|
1057
1211
|
schemaInput: SchemaPayload | null;
|
1058
1212
|
stateInput: StatePayload | null;
|
@@ -1060,10 +1214,17 @@ export declare function updateExtension(prevInputs: Payloads, prevConverters: Co
|
|
1060
1214
|
commandInput: CommandCreators | null;
|
1061
1215
|
};
|
1062
1216
|
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1217
|
+
/**
|
1218
|
+
* A function that is called when the editor state is updated.
|
1219
|
+
*
|
1220
|
+
* @param view - The editor view.
|
1221
|
+
* @param prevState - The previous editor state.
|
1222
|
+
*
|
1223
|
+
* @public
|
1224
|
+
*/
|
1225
|
+
declare type UpdateHandler = (view: EditorView, prevState: EditorState) => void;
|
1226
|
+
export { UpdateHandler }
|
1227
|
+
export { UpdateHandler as UpdateHandler_alias_1 }
|
1067
1228
|
|
1068
1229
|
export declare const viewFacet: Facet<ViewPayload, ViewPayload>;
|
1069
1230
|
|
package/dist/prosekit-core.d.ts
CHANGED
@@ -15,6 +15,14 @@ export { defineCommands } from './_tsup-dts-rollup';
|
|
15
15
|
export { defineDefaultState } from './_tsup-dts-rollup';
|
16
16
|
export { DefaultStateOptions } from './_tsup-dts-rollup';
|
17
17
|
export { defineDoc } from './_tsup-dts-rollup';
|
18
|
+
export { defineDocChangeHandler } from './_tsup-dts-rollup';
|
19
|
+
export { DocChangeHandler } from './_tsup-dts-rollup';
|
20
|
+
export { defineMountHandler } from './_tsup-dts-rollup';
|
21
|
+
export { defineUnmountHandler } from './_tsup-dts-rollup';
|
22
|
+
export { defineUpdateHandler } from './_tsup-dts-rollup';
|
23
|
+
export { MountHandler } from './_tsup-dts-rollup';
|
24
|
+
export { UnmountHandler } from './_tsup-dts-rollup';
|
25
|
+
export { UpdateHandler } from './_tsup-dts-rollup';
|
18
26
|
export { defineHistory } from './_tsup-dts-rollup';
|
19
27
|
export { defineInputRule } from './_tsup-dts-rollup';
|
20
28
|
export { defineBaseKeymap } from './_tsup-dts-rollup';
|
@@ -22,9 +30,13 @@ export { defineKeymap } from './_tsup-dts-rollup';
|
|
22
30
|
export { keymapFacet } from './_tsup-dts-rollup';
|
23
31
|
export { Keymap } from './_tsup-dts-rollup';
|
24
32
|
export { KeymapPayload } from './_tsup-dts-rollup';
|
33
|
+
export { defineMarkAttr } from './_tsup-dts-rollup';
|
25
34
|
export { defineMarkSpec } from './_tsup-dts-rollup';
|
35
|
+
export { MarkAttrOptions } from './_tsup-dts-rollup';
|
26
36
|
export { MarkSpecOptions } from './_tsup-dts-rollup';
|
37
|
+
export { defineNodeAttr } from './_tsup-dts-rollup';
|
27
38
|
export { defineNodeSpec } from './_tsup-dts-rollup';
|
39
|
+
export { NodeAttrOptions } from './_tsup-dts-rollup';
|
28
40
|
export { NodeSpecOptions } from './_tsup-dts-rollup';
|
29
41
|
export { defineNodeView } from './_tsup-dts-rollup';
|
30
42
|
export { NodeViewOptions } from './_tsup-dts-rollup';
|
@@ -35,7 +47,6 @@ export { definePlugin } from './_tsup-dts-rollup';
|
|
35
47
|
export { pluginFacet } from './_tsup-dts-rollup';
|
36
48
|
export { PluginPayload } from './_tsup-dts-rollup';
|
37
49
|
export { defineText } from './_tsup-dts-rollup';
|
38
|
-
export { defineUpdateHandler } from './_tsup-dts-rollup';
|
39
50
|
export { Facet } from './_tsup-dts-rollup';
|
40
51
|
export { FacetOptions } from './_tsup-dts-rollup';
|
41
52
|
export { BaseNodeViewOptions } from './_tsup-dts-rollup';
|
@@ -52,6 +63,7 @@ export { SelectionJSON } from './_tsup-dts-rollup';
|
|
52
63
|
export { StateJSON } from './_tsup-dts-rollup';
|
53
64
|
export { Priority } from './_tsup-dts-rollup';
|
54
65
|
export { SimplifyUnion } from './_tsup-dts-rollup';
|
66
|
+
export { clsx } from './_tsup-dts-rollup';
|
55
67
|
export { _getId } from './_tsup-dts-rollup';
|
56
68
|
export { getMarkType } from './_tsup-dts-rollup';
|
57
69
|
export { getNodeType } from './_tsup-dts-rollup';
|
package/dist/prosekit-core.js
CHANGED
@@ -1099,26 +1099,110 @@ function defineBaseCommands() {
|
|
1099
1099
|
});
|
1100
1100
|
}
|
1101
1101
|
|
1102
|
+
// src/utils/is-element.ts
|
1103
|
+
var hasElement = typeof Element !== "undefined";
|
1104
|
+
function isElement(value) {
|
1105
|
+
return hasElement && value instanceof Element;
|
1106
|
+
}
|
1107
|
+
|
1108
|
+
// src/utils/is-not-null.ts
|
1109
|
+
function isNotNull(value) {
|
1110
|
+
return value != null;
|
1111
|
+
}
|
1112
|
+
|
1102
1113
|
// src/extensions/node-spec.ts
|
1103
1114
|
function defineNodeSpec(options) {
|
1104
|
-
|
1115
|
+
const payload = [options, void 0];
|
1116
|
+
return nodeSpecFacet.extension([payload]);
|
1117
|
+
}
|
1118
|
+
function defineNodeAttr(options) {
|
1119
|
+
const payload = [void 0, options];
|
1120
|
+
return nodeSpecFacet.extension([payload]);
|
1105
1121
|
}
|
1106
1122
|
var nodeSpecFacet = Facet.define({
|
1107
|
-
convert: (
|
1123
|
+
convert: (payloads) => {
|
1108
1124
|
const nodes = {};
|
1109
1125
|
let topNodeName = void 0;
|
1110
|
-
|
1126
|
+
const specPayloads = payloads.map((input) => input[0]).filter(isNotNull);
|
1127
|
+
const attrPayloads = payloads.map((input) => input[1]).filter(isNotNull);
|
1128
|
+
for (const { name, topNode, ...spec } of specPayloads) {
|
1111
1129
|
if (nodes[name]) {
|
1112
1130
|
throw new ProseKitError(`Node type ${name} has already been defined`);
|
1113
1131
|
}
|
1114
|
-
if (
|
1132
|
+
if (topNode) {
|
1115
1133
|
topNodeName = name;
|
1116
1134
|
}
|
1117
1135
|
nodes[name] = spec;
|
1118
1136
|
}
|
1137
|
+
for (const {
|
1138
|
+
type,
|
1139
|
+
attr,
|
1140
|
+
default: defaultValue,
|
1141
|
+
toDOM,
|
1142
|
+
parseDOM
|
1143
|
+
} of attrPayloads) {
|
1144
|
+
const spec = nodes[type];
|
1145
|
+
if (!spec) {
|
1146
|
+
throw new ProseKitError(
|
1147
|
+
`Node type ${type} must be defined before defining attributes`
|
1148
|
+
);
|
1149
|
+
}
|
1150
|
+
if (!spec.attrs) {
|
1151
|
+
spec.attrs = {};
|
1152
|
+
}
|
1153
|
+
spec.attrs[attr] = { default: defaultValue };
|
1154
|
+
if (toDOM && spec.toDOM) {
|
1155
|
+
const existingToDom = spec.toDOM;
|
1156
|
+
spec.toDOM = (node) => {
|
1157
|
+
const dom = existingToDom(node);
|
1158
|
+
if (!dom) {
|
1159
|
+
return dom;
|
1160
|
+
}
|
1161
|
+
const attrDOM = toDOM(node.attrs[attr]);
|
1162
|
+
if (!attrDOM) {
|
1163
|
+
return dom;
|
1164
|
+
}
|
1165
|
+
const [key, value] = attrDOM;
|
1166
|
+
if (!key) {
|
1167
|
+
return dom;
|
1168
|
+
}
|
1169
|
+
if (Array.isArray(dom)) {
|
1170
|
+
if (typeof dom[1] === "object") {
|
1171
|
+
return [dom[0], { ...dom[1], [key]: value }, ...dom.slice(2)];
|
1172
|
+
} else {
|
1173
|
+
return [dom[0], { [key]: value }, ...dom.slice(1)];
|
1174
|
+
}
|
1175
|
+
} else if (isElement(dom)) {
|
1176
|
+
dom.setAttribute(key, value);
|
1177
|
+
} else if (typeof dom === "object" && "dom" in dom && isElement(dom.dom)) {
|
1178
|
+
dom.dom.setAttribute(key, value);
|
1179
|
+
}
|
1180
|
+
return dom;
|
1181
|
+
};
|
1182
|
+
}
|
1183
|
+
if (parseDOM && spec.parseDOM) {
|
1184
|
+
for (const rule of spec.parseDOM) {
|
1185
|
+
const existingGetAttrs = rule.getAttrs;
|
1186
|
+
const existingAttrs = rule.attrs;
|
1187
|
+
rule.getAttrs = (dom) => {
|
1188
|
+
var _a;
|
1189
|
+
const attrs = (_a = existingGetAttrs == null ? void 0 : existingGetAttrs(dom)) != null ? _a : existingAttrs;
|
1190
|
+
if (attrs === false || !dom || !isElement(dom)) {
|
1191
|
+
return attrs != null ? attrs : null;
|
1192
|
+
}
|
1193
|
+
const value = parseDOM(dom);
|
1194
|
+
return {
|
1195
|
+
...attrs,
|
1196
|
+
[attr]: value
|
1197
|
+
};
|
1198
|
+
};
|
1199
|
+
}
|
1200
|
+
}
|
1201
|
+
}
|
1119
1202
|
return { nodes, topNode: topNodeName };
|
1120
1203
|
},
|
1121
|
-
next: schemaFacet
|
1204
|
+
next: schemaFacet,
|
1205
|
+
singleton: true
|
1122
1206
|
});
|
1123
1207
|
|
1124
1208
|
// src/extensions/doc.ts
|
@@ -1130,16 +1214,8 @@ function defineDoc() {
|
|
1130
1214
|
});
|
1131
1215
|
}
|
1132
1216
|
|
1133
|
-
// src/extensions/
|
1134
|
-
import {
|
1135
|
-
|
1136
|
-
// src/utils/env.ts
|
1137
|
-
var isMac = typeof navigator !== "undefined" ? /Mac|iP(hone|[ao]d)/.test(navigator.platform) : false;
|
1138
|
-
|
1139
|
-
// src/extensions/keymap.ts
|
1140
|
-
import { baseKeymap, chainCommands } from "@prosekit/pm/commands";
|
1141
|
-
import { keydownHandler } from "@prosekit/pm/keymap";
|
1142
|
-
import { Plugin as Plugin3, PluginKey } from "@prosekit/pm/state";
|
1217
|
+
// src/extensions/events/plugin-view.ts
|
1218
|
+
import { PluginKey, ProseMirrorPlugin } from "@prosekit/pm/state";
|
1143
1219
|
|
1144
1220
|
// src/extensions/plugin.ts
|
1145
1221
|
import "@prosekit/pm/model";
|
@@ -1177,7 +1253,89 @@ var pluginFacet = Facet.define({
|
|
1177
1253
|
next: stateFacet
|
1178
1254
|
});
|
1179
1255
|
|
1256
|
+
// src/extensions/events/plugin-view.ts
|
1257
|
+
function defineMountHandler(handler) {
|
1258
|
+
return pluginViewFacet.extension([["mount", handler]]);
|
1259
|
+
}
|
1260
|
+
function defineUpdateHandler(handler) {
|
1261
|
+
return pluginViewFacet.extension([["update", handler]]);
|
1262
|
+
}
|
1263
|
+
function defineUnmountHandler(handler) {
|
1264
|
+
return pluginViewFacet.extension([["unmount", handler]]);
|
1265
|
+
}
|
1266
|
+
var pluginViewFacet = Facet.define({
|
1267
|
+
converter: () => {
|
1268
|
+
let mountHandlers = [];
|
1269
|
+
let updateHandlers = [];
|
1270
|
+
let unmountHandlers = [];
|
1271
|
+
const plugin = new ProseMirrorPlugin({
|
1272
|
+
key: pluginKey,
|
1273
|
+
view: (view) => {
|
1274
|
+
mountHandlers.forEach((fn) => fn(view));
|
1275
|
+
return {
|
1276
|
+
update: (view2, prevState) => {
|
1277
|
+
updateHandlers.forEach((fn) => fn(view2, prevState));
|
1278
|
+
},
|
1279
|
+
destroy: () => {
|
1280
|
+
unmountHandlers.forEach((fn) => fn());
|
1281
|
+
}
|
1282
|
+
};
|
1283
|
+
}
|
1284
|
+
});
|
1285
|
+
const pluginFunc = () => [plugin];
|
1286
|
+
const register = (input) => {
|
1287
|
+
mountHandlers = [];
|
1288
|
+
updateHandlers = [];
|
1289
|
+
unmountHandlers = [];
|
1290
|
+
for (const args of input) {
|
1291
|
+
switch (args[0]) {
|
1292
|
+
case "mount":
|
1293
|
+
mountHandlers.push(args[1]);
|
1294
|
+
break;
|
1295
|
+
case "update":
|
1296
|
+
updateHandlers.push(args[1]);
|
1297
|
+
break;
|
1298
|
+
case "unmount":
|
1299
|
+
unmountHandlers.push(args[1]);
|
1300
|
+
break;
|
1301
|
+
}
|
1302
|
+
}
|
1303
|
+
};
|
1304
|
+
return {
|
1305
|
+
create: (input) => {
|
1306
|
+
register(input);
|
1307
|
+
return pluginFunc;
|
1308
|
+
},
|
1309
|
+
update: (input) => {
|
1310
|
+
register(input);
|
1311
|
+
return null;
|
1312
|
+
}
|
1313
|
+
};
|
1314
|
+
},
|
1315
|
+
next: pluginFacet,
|
1316
|
+
singleton: true
|
1317
|
+
});
|
1318
|
+
var pluginKey = new PluginKey("prosekit-plugin-view-handler");
|
1319
|
+
|
1320
|
+
// src/extensions/events/doc-change.ts
|
1321
|
+
function defineDocChangeHandler(handler) {
|
1322
|
+
return defineUpdateHandler((view, prevState) => {
|
1323
|
+
if (!view.state.doc.eq(prevState.doc)) {
|
1324
|
+
handler(view, prevState);
|
1325
|
+
}
|
1326
|
+
});
|
1327
|
+
}
|
1328
|
+
|
1329
|
+
// src/extensions/history.ts
|
1330
|
+
import { history, redo, undo } from "@prosekit/pm/history";
|
1331
|
+
|
1332
|
+
// src/utils/env.ts
|
1333
|
+
var isMac = typeof navigator !== "undefined" ? /Mac|iP(hone|[ao]d)/.test(navigator.platform) : false;
|
1334
|
+
|
1180
1335
|
// src/extensions/keymap.ts
|
1336
|
+
import { baseKeymap, chainCommands } from "@prosekit/pm/commands";
|
1337
|
+
import { keydownHandler } from "@prosekit/pm/keymap";
|
1338
|
+
import { Plugin as Plugin3, PluginKey as PluginKey2 } from "@prosekit/pm/state";
|
1181
1339
|
function defineKeymap(keymap) {
|
1182
1340
|
return keymapFacet.extension([keymap]);
|
1183
1341
|
}
|
@@ -1228,7 +1386,7 @@ function mergeKeymaps(keymaps) {
|
|
1228
1386
|
])
|
1229
1387
|
);
|
1230
1388
|
}
|
1231
|
-
var keymapPluginKey = new
|
1389
|
+
var keymapPluginKey = new PluginKey2("prosekit-keymap");
|
1232
1390
|
|
1233
1391
|
// src/extensions/history.ts
|
1234
1392
|
function defineHistory() {
|
@@ -1277,24 +1435,97 @@ var inputRuleFacet = Facet.define({
|
|
1277
1435
|
|
1278
1436
|
// src/extensions/mark-spec.ts
|
1279
1437
|
function defineMarkSpec(options) {
|
1280
|
-
|
1438
|
+
const payload = [options, void 0];
|
1439
|
+
return markSpecFacet.extension([payload]);
|
1440
|
+
}
|
1441
|
+
function defineMarkAttr(options) {
|
1442
|
+
const payload = [void 0, options];
|
1443
|
+
return markSpecFacet.extension([payload]);
|
1281
1444
|
}
|
1282
1445
|
var markSpecFacet = Facet.define({
|
1283
|
-
convert: (
|
1446
|
+
convert: (payloads) => {
|
1284
1447
|
const marks = {};
|
1285
|
-
|
1448
|
+
const specPayloads = payloads.map((input) => input[0]).filter(isNotNull);
|
1449
|
+
const attrPayloads = payloads.map((input) => input[1]).filter(isNotNull);
|
1450
|
+
for (const { name, ...spec } of specPayloads) {
|
1286
1451
|
if (marks[name]) {
|
1287
1452
|
throw new ProseKitError(`Mark type ${name} has already been defined`);
|
1288
1453
|
}
|
1289
1454
|
marks[name] = spec;
|
1290
1455
|
}
|
1456
|
+
for (const {
|
1457
|
+
type,
|
1458
|
+
attr,
|
1459
|
+
default: defaultValue,
|
1460
|
+
toDOM,
|
1461
|
+
parseDOM
|
1462
|
+
} of attrPayloads) {
|
1463
|
+
const spec = marks[type];
|
1464
|
+
if (!spec) {
|
1465
|
+
throw new ProseKitError(
|
1466
|
+
`Mark type ${type} must be defined before defining attributes`
|
1467
|
+
);
|
1468
|
+
}
|
1469
|
+
if (!spec.attrs) {
|
1470
|
+
spec.attrs = {};
|
1471
|
+
}
|
1472
|
+
spec.attrs[attr] = { default: defaultValue };
|
1473
|
+
if (toDOM && spec.toDOM) {
|
1474
|
+
const existingToDom = spec.toDOM;
|
1475
|
+
spec.toDOM = (mark, inline) => {
|
1476
|
+
const dom = existingToDom(mark, inline);
|
1477
|
+
if (!dom) {
|
1478
|
+
return dom;
|
1479
|
+
}
|
1480
|
+
const attrDOM = toDOM(mark.attrs[attr]);
|
1481
|
+
if (!attrDOM) {
|
1482
|
+
return dom;
|
1483
|
+
}
|
1484
|
+
const [key, value] = attrDOM;
|
1485
|
+
if (!key) {
|
1486
|
+
return dom;
|
1487
|
+
}
|
1488
|
+
if (Array.isArray(dom)) {
|
1489
|
+
if (typeof dom[1] === "object") {
|
1490
|
+
return [dom[0], { ...dom[1], [key]: value }, ...dom.slice(2)];
|
1491
|
+
} else {
|
1492
|
+
return [dom[0], { [key]: value }, ...dom.slice(1)];
|
1493
|
+
}
|
1494
|
+
} else if (isElement(dom)) {
|
1495
|
+
dom.setAttribute(key, value);
|
1496
|
+
} else if (typeof dom === "object" && "dom" in dom && isElement(dom.dom)) {
|
1497
|
+
dom.dom.setAttribute(key, value);
|
1498
|
+
}
|
1499
|
+
return dom;
|
1500
|
+
};
|
1501
|
+
}
|
1502
|
+
if (parseDOM && spec.parseDOM) {
|
1503
|
+
for (const rule of spec.parseDOM) {
|
1504
|
+
const existingGetAttrs = rule.getAttrs;
|
1505
|
+
const existingAttrs = rule.attrs;
|
1506
|
+
rule.getAttrs = (dom) => {
|
1507
|
+
var _a;
|
1508
|
+
const attrs = (_a = existingGetAttrs == null ? void 0 : existingGetAttrs(dom)) != null ? _a : existingAttrs;
|
1509
|
+
if (attrs === false || !dom || !isElement(dom)) {
|
1510
|
+
return attrs != null ? attrs : null;
|
1511
|
+
}
|
1512
|
+
const value = parseDOM(dom);
|
1513
|
+
return {
|
1514
|
+
...attrs,
|
1515
|
+
[attr]: value
|
1516
|
+
};
|
1517
|
+
};
|
1518
|
+
}
|
1519
|
+
}
|
1520
|
+
}
|
1291
1521
|
return { marks, nodes: {} };
|
1292
1522
|
},
|
1293
|
-
next: schemaFacet
|
1523
|
+
next: schemaFacet,
|
1524
|
+
singleton: true
|
1294
1525
|
});
|
1295
1526
|
|
1296
1527
|
// src/extensions/node-view.ts
|
1297
|
-
import { ProseMirrorPlugin } from "@prosekit/pm/state";
|
1528
|
+
import { ProseMirrorPlugin as ProseMirrorPlugin2 } from "@prosekit/pm/state";
|
1298
1529
|
import "@prosekit/pm/view";
|
1299
1530
|
function defineNodeView(options) {
|
1300
1531
|
return nodeViewFacet.extension([options]);
|
@@ -1307,13 +1538,13 @@ var nodeViewFacet = Facet.define({
|
|
1307
1538
|
nodeViews[input.name] = input.constructor;
|
1308
1539
|
}
|
1309
1540
|
}
|
1310
|
-
return () => [new
|
1541
|
+
return () => [new ProseMirrorPlugin2({ props: { nodeViews } })];
|
1311
1542
|
},
|
1312
1543
|
next: pluginFacet
|
1313
1544
|
});
|
1314
1545
|
|
1315
1546
|
// src/extensions/node-view-effect.ts
|
1316
|
-
import { ProseMirrorPlugin as
|
1547
|
+
import { ProseMirrorPlugin as ProseMirrorPlugin3 } from "@prosekit/pm/state";
|
1317
1548
|
import "@prosekit/pm/view";
|
1318
1549
|
function defineNodeViewFactory(options) {
|
1319
1550
|
return nodeViewFactoryFacet.extension([options]);
|
@@ -1341,7 +1572,7 @@ var nodeViewFactoryFacet = Facet.define({
|
|
1341
1572
|
nodeViews[name] = factory(args);
|
1342
1573
|
}
|
1343
1574
|
}
|
1344
|
-
return () => [new
|
1575
|
+
return () => [new ProseMirrorPlugin3({ props: { nodeViews } })];
|
1345
1576
|
},
|
1346
1577
|
next: pluginFacet
|
1347
1578
|
});
|
@@ -1370,48 +1601,9 @@ function defineText() {
|
|
1370
1601
|
});
|
1371
1602
|
}
|
1372
1603
|
|
1373
|
-
// src/
|
1374
|
-
import
|
1375
|
-
|
1376
|
-
// src/utils/is-not-null.ts
|
1377
|
-
function isNotNull(value) {
|
1378
|
-
return value != null;
|
1379
|
-
}
|
1380
|
-
|
1381
|
-
// src/extensions/update-handler.ts
|
1382
|
-
function defineUpdateHandler(handler) {
|
1383
|
-
return updateHandlerFacet.extension([handler]);
|
1384
|
-
}
|
1385
|
-
var updateHandlerFacet = Facet.define({
|
1386
|
-
converter: () => {
|
1387
|
-
let updateHandlers = [];
|
1388
|
-
const plugin = new ProseMirrorPlugin3({
|
1389
|
-
key: pluginKey,
|
1390
|
-
view: (view) => {
|
1391
|
-
updateHandlers.forEach((fn) => fn({ view }));
|
1392
|
-
return {
|
1393
|
-
update: (view2, prevState) => {
|
1394
|
-
updateHandlers.forEach((fn) => fn({ view: view2, prevState }));
|
1395
|
-
}
|
1396
|
-
};
|
1397
|
-
}
|
1398
|
-
});
|
1399
|
-
const pluginFunc = () => [plugin];
|
1400
|
-
return {
|
1401
|
-
create: (handlers) => {
|
1402
|
-
updateHandlers = handlers.filter(isNotNull);
|
1403
|
-
return pluginFunc;
|
1404
|
-
},
|
1405
|
-
update: (handlers) => {
|
1406
|
-
updateHandlers = handlers.filter(isNotNull);
|
1407
|
-
return null;
|
1408
|
-
}
|
1409
|
-
};
|
1410
|
-
},
|
1411
|
-
next: pluginFacet,
|
1412
|
-
singleton: true
|
1413
|
-
});
|
1414
|
-
var pluginKey = new PluginKey2("prosekit-event-handler");
|
1604
|
+
// src/utils/clsx.ts
|
1605
|
+
import clsxLite from "clsx/lite";
|
1606
|
+
var clsx = clsxLite;
|
1415
1607
|
|
1416
1608
|
// src/utils/get-id.ts
|
1417
1609
|
var id = 0;
|
@@ -1426,22 +1618,28 @@ export {
|
|
1426
1618
|
ProseKitError,
|
1427
1619
|
getId as _getId,
|
1428
1620
|
addMark,
|
1621
|
+
clsx,
|
1429
1622
|
createEditor,
|
1430
1623
|
defineBaseCommands,
|
1431
1624
|
defineBaseKeymap,
|
1432
1625
|
defineCommands,
|
1433
1626
|
defineDefaultState,
|
1434
1627
|
defineDoc,
|
1628
|
+
defineDocChangeHandler,
|
1435
1629
|
defineHistory,
|
1436
1630
|
defineInputRule,
|
1437
1631
|
defineKeymap,
|
1632
|
+
defineMarkAttr,
|
1438
1633
|
defineMarkSpec,
|
1634
|
+
defineMountHandler,
|
1635
|
+
defineNodeAttr,
|
1439
1636
|
defineNodeSpec,
|
1440
1637
|
defineNodeView,
|
1441
1638
|
defineNodeViewFactory,
|
1442
1639
|
defineParagraph,
|
1443
1640
|
definePlugin,
|
1444
1641
|
defineText,
|
1642
|
+
defineUnmountHandler,
|
1445
1643
|
defineUpdateHandler,
|
1446
1644
|
getMarkType,
|
1447
1645
|
getNodeType,
|
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.3",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -36,6 +36,7 @@
|
|
36
36
|
],
|
37
37
|
"dependencies": {
|
38
38
|
"@prosekit/pm": "^0.1.1",
|
39
|
+
"clsx": "^2.1.0",
|
39
40
|
"orderedmap": "^2.1.1",
|
40
41
|
"type-fest": "^4.9.0"
|
41
42
|
},
|
@@ -43,7 +44,7 @@
|
|
43
44
|
"@prosekit/dev": "*",
|
44
45
|
"tsup": "^8.0.1",
|
45
46
|
"typescript": "^5.3.3",
|
46
|
-
"vitest": "^1.1.
|
47
|
+
"vitest": "^1.1.3"
|
47
48
|
},
|
48
49
|
"scripts": {
|
49
50
|
"build:tsup": "tsup",
|
package/src/index.ts
CHANGED
@@ -14,6 +14,18 @@ export {
|
|
14
14
|
type DefaultStateOptions,
|
15
15
|
} from './extensions/default-state'
|
16
16
|
export { defineDoc } from './extensions/doc'
|
17
|
+
export {
|
18
|
+
defineDocChangeHandler,
|
19
|
+
type DocChangeHandler,
|
20
|
+
} from './extensions/events/doc-change'
|
21
|
+
export {
|
22
|
+
defineMountHandler,
|
23
|
+
defineUnmountHandler,
|
24
|
+
defineUpdateHandler,
|
25
|
+
type MountHandler,
|
26
|
+
type UnmountHandler,
|
27
|
+
type UpdateHandler,
|
28
|
+
} from './extensions/events/plugin-view'
|
17
29
|
export { defineHistory } from './extensions/history'
|
18
30
|
export { defineInputRule } from './extensions/input-rules'
|
19
31
|
export {
|
@@ -23,8 +35,18 @@ export {
|
|
23
35
|
type Keymap,
|
24
36
|
type KeymapPayload,
|
25
37
|
} from './extensions/keymap'
|
26
|
-
export {
|
27
|
-
|
38
|
+
export {
|
39
|
+
defineMarkAttr,
|
40
|
+
defineMarkSpec,
|
41
|
+
type MarkAttrOptions,
|
42
|
+
type MarkSpecOptions,
|
43
|
+
} from './extensions/mark-spec'
|
44
|
+
export {
|
45
|
+
defineNodeAttr,
|
46
|
+
defineNodeSpec,
|
47
|
+
type NodeAttrOptions,
|
48
|
+
type NodeSpecOptions,
|
49
|
+
} from './extensions/node-spec'
|
28
50
|
export { defineNodeView, type NodeViewOptions } from './extensions/node-view'
|
29
51
|
export {
|
30
52
|
defineNodeViewFactory,
|
@@ -37,7 +59,6 @@ export {
|
|
37
59
|
type PluginPayload,
|
38
60
|
} from './extensions/plugin'
|
39
61
|
export { defineText } from './extensions/text'
|
40
|
-
export { defineUpdateHandler } from './extensions/update-handler'
|
41
62
|
export { Facet, type FacetOptions } from './facets/facet'
|
42
63
|
export type { BaseNodeViewOptions } from './types/base-node-view-options'
|
43
64
|
export { type CommandArgs } from './types/command'
|
@@ -53,6 +74,7 @@ export { type ExtensionTyping } from './types/extension-typing'
|
|
53
74
|
export type { NodeJSON, SelectionJSON, StateJSON } from './types/model'
|
54
75
|
export { Priority } from './types/priority'
|
55
76
|
export { type SimplifyUnion } from './types/simplify-union'
|
77
|
+
export { clsx } from './utils/clsx'
|
56
78
|
export { getId as _getId } from './utils/get-id'
|
57
79
|
export { getMarkType } from './utils/get-mark-type'
|
58
80
|
export { getNodeType } from './utils/get-node-type'
|