@prosekit/core 0.0.19 → 0.1.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 +104 -63
- package/dist/prosekit-core.d.ts +10 -8
- package/dist/prosekit-core.js +94 -73
- package/dist/style.css +1 -1
- package/package.json +3 -3
@@ -144,17 +144,17 @@ declare interface DefaultStateOptions {
|
|
144
144
|
* A JSON object representing the starting document to use when creating the
|
145
145
|
* editor.
|
146
146
|
*/
|
147
|
-
defaultDoc?:
|
147
|
+
defaultDoc?: NodeJSON;
|
148
148
|
/**
|
149
|
-
* A HTML string representing the starting document to use
|
150
|
-
* editor.
|
149
|
+
* A HTML element or a HTML string representing the starting document to use
|
150
|
+
* when creating the editor.
|
151
151
|
*/
|
152
|
-
defaultHTML?: string;
|
152
|
+
defaultHTML?: string | HTMLElement;
|
153
153
|
/**
|
154
154
|
* A JSON object representing the starting selection to use when creating the
|
155
155
|
* editor. It's only used when `defaultDoc` or `defaultHTML` is also provided.
|
156
156
|
*/
|
157
|
-
defaultSelection?:
|
157
|
+
defaultSelection?: SelectionJSON;
|
158
158
|
}
|
159
159
|
export { DefaultStateOptions }
|
160
160
|
export { DefaultStateOptions as DefaultStateOptions_alias_1 }
|
@@ -231,15 +231,6 @@ NODES: "doc";
|
|
231
231
|
export { defineDoc }
|
232
232
|
export { defineDoc as defineDoc_alias_1 }
|
233
233
|
|
234
|
-
/**
|
235
|
-
* @internal
|
236
|
-
*/
|
237
|
-
declare function defineEventHandler(options: {
|
238
|
-
update?: VoidFunction;
|
239
|
-
}): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
240
|
-
export { defineEventHandler }
|
241
|
-
export { defineEventHandler as defineEventHandler_alias_1 }
|
242
|
-
|
243
234
|
/**
|
244
235
|
* Add undo/redo history to the editor.
|
245
236
|
*/
|
@@ -253,11 +244,16 @@ export { defineHistory }
|
|
253
244
|
export { defineHistory as defineHistory_alias_1 }
|
254
245
|
|
255
246
|
/**
|
247
|
+
* Defines an input rule extension.
|
248
|
+
*
|
249
|
+
* @param rule - The ProseMirror input rule to add, or an array of input rules,
|
250
|
+
* or a function that returns one or multiple input rules.
|
251
|
+
*
|
256
252
|
* @public
|
257
253
|
*/
|
258
|
-
declare function defineInputRule(
|
254
|
+
declare function defineInputRule(rule: InputRule | InputRule[] | ((context: {
|
259
255
|
schema: Schema;
|
260
|
-
}) => InputRule[]): Extension;
|
256
|
+
}) => InputRule | InputRule[])): Extension;
|
261
257
|
export { defineInputRule }
|
262
258
|
export { defineInputRule as defineInputRule_alias_1 }
|
263
259
|
|
@@ -318,13 +314,13 @@ NODES: "paragraph";
|
|
318
314
|
* Adds a ProseMirror plugin to the editor.
|
319
315
|
*
|
320
316
|
* @param plugin - The ProseMirror plugin to add, or an array of plugins, or a
|
321
|
-
* function that returns
|
317
|
+
* function that returns one or multiple plugins.
|
322
318
|
*
|
323
319
|
* @public
|
324
320
|
*/
|
325
321
|
declare function definePlugin(plugin: Plugin_2 | Plugin_2[] | ((context: {
|
326
322
|
schema: Schema;
|
327
|
-
}) => Plugin_2[])): Extension;
|
323
|
+
}) => Plugin_2 | Plugin_2[])): Extension;
|
328
324
|
export { definePlugin }
|
329
325
|
export { definePlugin as definePlugin_alias_1 }
|
330
326
|
|
@@ -337,6 +333,13 @@ NODES: "text";
|
|
337
333
|
export { defineText }
|
338
334
|
export { defineText as defineText_alias_1 }
|
339
335
|
|
336
|
+
/**
|
337
|
+
* @internal
|
338
|
+
*/
|
339
|
+
declare function defineUpdateHandler(handler: UpdateHandler): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
340
|
+
export { defineUpdateHandler }
|
341
|
+
export { defineUpdateHandler as defineUpdateHandler_alias_1 }
|
342
|
+
|
340
343
|
/**
|
341
344
|
* @public
|
342
345
|
*/
|
@@ -381,34 +384,27 @@ declare interface EditorOptions<E extends Extension> {
|
|
381
384
|
* A JSON object representing the starting document to use when creating the
|
382
385
|
* editor.
|
383
386
|
*/
|
384
|
-
defaultDoc?:
|
387
|
+
defaultDoc?: NodeJSON;
|
385
388
|
/**
|
386
|
-
* A HTML string representing the starting document to use
|
387
|
-
* editor.
|
389
|
+
* A HTML element or a HTML string representing the starting document to use
|
390
|
+
* when creating the editor.
|
388
391
|
*/
|
389
|
-
defaultHTML?: string;
|
392
|
+
defaultHTML?: string | HTMLElement;
|
390
393
|
/**
|
391
394
|
* A JSON object representing the starting selection to use when creating the
|
392
395
|
* editor. It's only used when `defaultDoc` or `defaultHTML` is also provided.
|
393
396
|
*/
|
394
|
-
defaultSelection?:
|
397
|
+
defaultSelection?: SelectionJSON;
|
395
398
|
}
|
396
399
|
export { EditorOptions }
|
397
400
|
export { EditorOptions as EditorOptions_alias_1 }
|
398
401
|
|
399
402
|
/**
|
400
|
-
* Parse a HTML
|
401
|
-
|
402
|
-
|
403
|
-
export { elementToJSON }
|
404
|
-
export { elementToJSON as elementToJSON_alias_1 }
|
405
|
-
|
406
|
-
/**
|
407
|
-
* Parse a HTML element to a ProseMirror node.
|
403
|
+
* Parse a HTML string to a HTML element.
|
404
|
+
*
|
405
|
+
* @internal
|
408
406
|
*/
|
409
|
-
declare function
|
410
|
-
export { elementToNode }
|
411
|
-
export { elementToNode as elementToNode_alias_1 }
|
407
|
+
export declare function elementFromHTML(html: string): HTMLElement;
|
412
408
|
|
413
409
|
declare type EmptyValue = undefined | null | EmptyObject;
|
414
410
|
|
@@ -580,20 +576,6 @@ declare function getNodeType(schema: Schema, type: string | NodeType): NodeType;
|
|
580
576
|
export { getNodeType }
|
581
577
|
export { getNodeType as getNodeType_alias_1 }
|
582
578
|
|
583
|
-
/**
|
584
|
-
* Parse a HTML element to a ProseMirror document JSON.
|
585
|
-
*/
|
586
|
-
declare function htmlToJSON(html: string, schema: Schema): NodeJson;
|
587
|
-
export { htmlToJSON }
|
588
|
-
export { htmlToJSON as htmlToJSON_alias_1 }
|
589
|
-
|
590
|
-
/**
|
591
|
-
* Parse a HTML string to a ProseMirror node.
|
592
|
-
*/
|
593
|
-
declare function htmlToNode(html: string, schema: Schema): ProseMirrorNode;
|
594
|
-
export { htmlToNode }
|
595
|
-
export { htmlToNode as htmlToNode_alias_1 }
|
596
|
-
|
597
579
|
declare function insertNode(options: {
|
598
580
|
node: ProseMirrorNode;
|
599
581
|
pos?: number;
|
@@ -645,6 +627,8 @@ declare function isNodeSelection(sel: Selection_2): sel is NodeSelection;
|
|
645
627
|
export { isNodeSelection }
|
646
628
|
export { isNodeSelection as isNodeSelection_alias_1 }
|
647
629
|
|
630
|
+
export declare function isNotNull<T>(value: T | null | undefined): value is T;
|
631
|
+
|
648
632
|
/**
|
649
633
|
* @internal
|
650
634
|
*/
|
@@ -659,6 +643,42 @@ declare function isTextSelection(sel: Selection_2): sel is TextSelection;
|
|
659
643
|
export { isTextSelection }
|
660
644
|
export { isTextSelection as isTextSelection_alias_1 }
|
661
645
|
|
646
|
+
/**
|
647
|
+
* Parse a HTML element to a ProseMirror document JSON.
|
648
|
+
*
|
649
|
+
* @public
|
650
|
+
*/
|
651
|
+
declare function jsonFromElement(element: HTMLElement, schema: Schema): NodeJSON;
|
652
|
+
export { jsonFromElement }
|
653
|
+
export { jsonFromElement as jsonFromElement_alias_1 }
|
654
|
+
|
655
|
+
/**
|
656
|
+
* Parse a HTML string to a ProseMirror document JSON.
|
657
|
+
*
|
658
|
+
* @public
|
659
|
+
*/
|
660
|
+
declare function jsonFromHTML(html: string, schema: Schema): NodeJSON;
|
661
|
+
export { jsonFromHTML }
|
662
|
+
export { jsonFromHTML as jsonFromHTML_alias_1 }
|
663
|
+
|
664
|
+
/**
|
665
|
+
* Return a JSON object representing this node.
|
666
|
+
*
|
667
|
+
* @public
|
668
|
+
*/
|
669
|
+
declare function jsonFromNode(node: ProseMirrorNode): NodeJSON;
|
670
|
+
export { jsonFromNode }
|
671
|
+
export { jsonFromNode as jsonFromNode_alias_1 }
|
672
|
+
|
673
|
+
/**
|
674
|
+
* Return a JSON object representing this state.
|
675
|
+
*
|
676
|
+
* @public
|
677
|
+
*/
|
678
|
+
declare function jsonFromState(state: EditorState): StateJSON;
|
679
|
+
export { jsonFromState }
|
680
|
+
export { jsonFromState as jsonFromState_alias_1 }
|
681
|
+
|
662
682
|
/**
|
663
683
|
* @public
|
664
684
|
*/
|
@@ -693,20 +713,38 @@ export declare type NodeChild = ProseMirrorNode | string | NodeChild[];
|
|
693
713
|
|
694
714
|
export declare type NodeContent = ProseMirrorNode | ProseMirrorFragment | NodeContent[];
|
695
715
|
|
716
|
+
/**
|
717
|
+
* Parse a HTML element to a ProseMirror node.
|
718
|
+
*
|
719
|
+
* @public
|
720
|
+
*/
|
721
|
+
declare function nodeFromElement(element: HTMLElement, schema: Schema): ProseMirrorNode;
|
722
|
+
export { nodeFromElement }
|
723
|
+
export { nodeFromElement as nodeFromElement_alias_1 }
|
724
|
+
|
725
|
+
/**
|
726
|
+
* Parse a HTML string to a ProseMirror node.
|
727
|
+
*
|
728
|
+
* @public
|
729
|
+
*/
|
730
|
+
declare function nodeFromHTML(html: string, schema: Schema): ProseMirrorNode;
|
731
|
+
export { nodeFromHTML }
|
732
|
+
export { nodeFromHTML as nodeFromHTML_alias_1 }
|
733
|
+
|
696
734
|
/**
|
697
735
|
* A JSON representation of the prosemirror node.
|
698
736
|
*
|
699
737
|
* @public
|
700
738
|
*/
|
701
|
-
declare interface
|
739
|
+
declare interface NodeJSON {
|
702
740
|
type: string;
|
703
741
|
marks?: Array<any>;
|
704
742
|
text?: string;
|
705
|
-
content?:
|
743
|
+
content?: NodeJSON[];
|
706
744
|
attrs?: Record<string, any>;
|
707
745
|
}
|
708
|
-
export {
|
709
|
-
export {
|
746
|
+
export { NodeJSON }
|
747
|
+
export { NodeJSON as NodeJSON_alias_1 }
|
710
748
|
|
711
749
|
/**
|
712
750
|
* @public
|
@@ -737,8 +775,6 @@ declare interface NodeViewOptions {
|
|
737
775
|
export { NodeViewOptions }
|
738
776
|
export { NodeViewOptions as NodeViewOptions_alias_1 }
|
739
777
|
|
740
|
-
export declare function notNull<T>(value: T | null | undefined): value is T;
|
741
|
-
|
742
778
|
export declare function objectEqual<T>(a: T, b: T): boolean;
|
743
779
|
|
744
780
|
declare type Payload = unknown;
|
@@ -759,7 +795,7 @@ export { pluginFacet as pluginFacet_alias_1 }
|
|
759
795
|
*/
|
760
796
|
declare type PluginPayload = (context: {
|
761
797
|
schema: Schema;
|
762
|
-
}) => Plugin_2[];
|
798
|
+
}) => Plugin_2 | Plugin_2[];
|
763
799
|
export { PluginPayload }
|
764
800
|
export { PluginPayload as PluginPayload_alias_1 }
|
765
801
|
|
@@ -819,13 +855,13 @@ export declare function selectAll(): Command;
|
|
819
855
|
*
|
820
856
|
* @public
|
821
857
|
*/
|
822
|
-
declare interface
|
858
|
+
declare interface SelectionJSON {
|
823
859
|
anchor: number;
|
824
860
|
head: number;
|
825
861
|
type: string;
|
826
862
|
}
|
827
|
-
export {
|
828
|
-
export {
|
863
|
+
export { SelectionJSON }
|
864
|
+
export { SelectionJSON as SelectionJSON_alias_1 }
|
829
865
|
|
830
866
|
/**
|
831
867
|
* Returns a command that tries to set the selected textblocks to the given node
|
@@ -865,18 +901,18 @@ export declare const stateFacet: Facet<StatePayload, StatePayload>;
|
|
865
901
|
*
|
866
902
|
* @public
|
867
903
|
*/
|
868
|
-
declare interface
|
904
|
+
declare interface StateJSON {
|
869
905
|
/**
|
870
906
|
* The main `ProseMirror` doc.
|
871
907
|
*/
|
872
|
-
doc:
|
908
|
+
doc: NodeJSON;
|
873
909
|
/**
|
874
910
|
* The current selection.
|
875
911
|
*/
|
876
|
-
selection:
|
912
|
+
selection: SelectionJSON;
|
877
913
|
}
|
878
|
-
export {
|
879
|
-
export {
|
914
|
+
export { StateJSON }
|
915
|
+
export { StateJSON as StateJSON_alias_1 }
|
880
916
|
|
881
917
|
export declare type StatePayload = (ctx: {
|
882
918
|
schema: Schema;
|
@@ -934,6 +970,11 @@ export declare function updateExtension(prevInputs: Payloads, prevConverters: Co
|
|
934
970
|
commandInput: CommandCreators | null;
|
935
971
|
};
|
936
972
|
|
973
|
+
export declare type UpdateHandler = (options: {
|
974
|
+
view: EditorView;
|
975
|
+
prevState: EditorState;
|
976
|
+
}) => void;
|
977
|
+
|
937
978
|
export declare const viewFacet: Facet<ViewPayload, ViewPayload>;
|
938
979
|
|
939
980
|
export declare type ViewPayload = Omit<DirectEditorProps, 'state'>;
|
package/dist/prosekit-core.d.ts
CHANGED
@@ -15,7 +15,6 @@ 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 { defineEventHandler } from './_tsup-dts-rollup';
|
19
18
|
export { defineHistory } from './_tsup-dts-rollup';
|
20
19
|
export { defineInputRule } from './_tsup-dts-rollup';
|
21
20
|
export { defineBaseKeymap } from './_tsup-dts-rollup';
|
@@ -34,6 +33,7 @@ export { definePlugin } from './_tsup-dts-rollup';
|
|
34
33
|
export { pluginFacet } from './_tsup-dts-rollup';
|
35
34
|
export { PluginPayload } from './_tsup-dts-rollup';
|
36
35
|
export { defineText } from './_tsup-dts-rollup';
|
36
|
+
export { defineUpdateHandler } from './_tsup-dts-rollup';
|
37
37
|
export { Facet } from './_tsup-dts-rollup';
|
38
38
|
export { FacetOptions } from './_tsup-dts-rollup';
|
39
39
|
export { CommandArgs } from './_tsup-dts-rollup';
|
@@ -44,17 +44,19 @@ export { ExtractMarks } from './_tsup-dts-rollup';
|
|
44
44
|
export { ExtractNodes } from './_tsup-dts-rollup';
|
45
45
|
export { SimplifyExtension } from './_tsup-dts-rollup';
|
46
46
|
export { ExtensionTyping } from './_tsup-dts-rollup';
|
47
|
-
export {
|
48
|
-
export {
|
49
|
-
export {
|
47
|
+
export { NodeJSON } from './_tsup-dts-rollup';
|
48
|
+
export { SelectionJSON } from './_tsup-dts-rollup';
|
49
|
+
export { StateJSON } from './_tsup-dts-rollup';
|
50
50
|
export { Priority } from './_tsup-dts-rollup';
|
51
51
|
export { SimplifyUnion } from './_tsup-dts-rollup';
|
52
52
|
export { getMarkType } from './_tsup-dts-rollup';
|
53
53
|
export { getNodeType } from './_tsup-dts-rollup';
|
54
|
-
export {
|
55
|
-
export {
|
56
|
-
export {
|
57
|
-
export {
|
54
|
+
export { jsonFromElement } from './_tsup-dts-rollup';
|
55
|
+
export { jsonFromHTML } from './_tsup-dts-rollup';
|
56
|
+
export { jsonFromNode } from './_tsup-dts-rollup';
|
57
|
+
export { jsonFromState } from './_tsup-dts-rollup';
|
58
|
+
export { nodeFromElement } from './_tsup-dts-rollup';
|
59
|
+
export { nodeFromHTML } from './_tsup-dts-rollup';
|
58
60
|
export { isAllSelection } from './_tsup-dts-rollup';
|
59
61
|
export { isMark } from './_tsup-dts-rollup';
|
60
62
|
export { isNodeSelection } from './_tsup-dts-rollup';
|
package/dist/prosekit-core.js
CHANGED
@@ -368,19 +368,19 @@ function getBrowserWindow() {
|
|
368
368
|
}
|
369
369
|
|
370
370
|
// src/utils/parse.ts
|
371
|
-
function
|
371
|
+
function nodeFromElement(element, schema) {
|
372
372
|
return DOMParser.fromSchema(schema).parse(element);
|
373
373
|
}
|
374
|
-
function
|
375
|
-
return
|
374
|
+
function jsonFromElement(element, schema) {
|
375
|
+
return jsonFromNode(nodeFromElement(element, schema));
|
376
376
|
}
|
377
|
-
function
|
378
|
-
return
|
377
|
+
function nodeFromHTML(html, schema) {
|
378
|
+
return nodeFromElement(elementFromHTML(html), schema);
|
379
379
|
}
|
380
|
-
function
|
381
|
-
return
|
380
|
+
function jsonFromHTML(html, schema) {
|
381
|
+
return jsonFromElement(elementFromHTML(html), schema);
|
382
382
|
}
|
383
|
-
function
|
383
|
+
function elementFromHTML(html) {
|
384
384
|
const win = getBrowserWindow();
|
385
385
|
if (!win) {
|
386
386
|
throw new ProseKitError(
|
@@ -390,6 +390,12 @@ function htmlToElement(html) {
|
|
390
390
|
const parser = new win.DOMParser();
|
391
391
|
return parser.parseFromString(`<body>${html}</body>`, "text/html").body;
|
392
392
|
}
|
393
|
+
function jsonFromState(state) {
|
394
|
+
return state.toJSON();
|
395
|
+
}
|
396
|
+
function jsonFromNode(node) {
|
397
|
+
return node.toJSON();
|
398
|
+
}
|
393
399
|
|
394
400
|
// src/extensions/default-state.ts
|
395
401
|
function defineDefaultState({
|
@@ -406,7 +412,11 @@ function defineDefaultState({
|
|
406
412
|
({ schema }) => {
|
407
413
|
const config = {};
|
408
414
|
if (defaultHTML) {
|
409
|
-
|
415
|
+
if (typeof defaultHTML === "string") {
|
416
|
+
defaultDoc = jsonFromHTML(defaultHTML, schema);
|
417
|
+
} else {
|
418
|
+
defaultDoc = jsonFromElement(defaultHTML, schema);
|
419
|
+
}
|
410
420
|
}
|
411
421
|
if (defaultDoc) {
|
412
422
|
config.doc = schema.nodeFromJSON(defaultDoc);
|
@@ -1132,12 +1142,16 @@ function defineDoc() {
|
|
1132
1142
|
});
|
1133
1143
|
}
|
1134
1144
|
|
1135
|
-
// src/extensions/
|
1136
|
-
import {
|
1145
|
+
// src/extensions/history.ts
|
1146
|
+
import { history, redo, undo } from "@prosekit/pm/history";
|
1147
|
+
|
1148
|
+
// src/utils/env.ts
|
1149
|
+
var isMac = typeof navigator !== "undefined" ? /Mac|iP(hone|[ao]d)/.test(navigator.platform) : false;
|
1137
1150
|
|
1138
|
-
// src/
|
1139
|
-
|
1140
|
-
}
|
1151
|
+
// src/extensions/keymap.ts
|
1152
|
+
import { baseKeymap, chainCommands } from "@prosekit/pm/commands";
|
1153
|
+
import { keydownHandler } from "@prosekit/pm/keymap";
|
1154
|
+
import { Plugin as Plugin3, PluginKey } from "@prosekit/pm/state";
|
1141
1155
|
|
1142
1156
|
// src/extensions/plugin.ts
|
1143
1157
|
import "@prosekit/pm/model";
|
@@ -1164,53 +1178,7 @@ var pluginFacet = Facet.define({
|
|
1164
1178
|
next: stateFacet
|
1165
1179
|
});
|
1166
1180
|
|
1167
|
-
// src/extensions/event-handler.ts
|
1168
|
-
function defineEventHandler(options) {
|
1169
|
-
var _a;
|
1170
|
-
const updateHandler = (_a = options == null ? void 0 : options.update) != null ? _a : voidFunction;
|
1171
|
-
return eventFacet.extension([updateHandler]);
|
1172
|
-
}
|
1173
|
-
var eventFacet = Facet.define({
|
1174
|
-
converter: () => {
|
1175
|
-
let updateHandlers = [];
|
1176
|
-
const plugin = new ProseMirrorPlugin({
|
1177
|
-
key: pluginKey,
|
1178
|
-
view: () => {
|
1179
|
-
updateHandlers.forEach((fn) => fn());
|
1180
|
-
return {
|
1181
|
-
update: (_view, _prevState) => {
|
1182
|
-
updateHandlers.forEach((fn) => fn());
|
1183
|
-
}
|
1184
|
-
};
|
1185
|
-
}
|
1186
|
-
});
|
1187
|
-
const pluginFunc = () => [plugin];
|
1188
|
-
return {
|
1189
|
-
create: (handlers) => {
|
1190
|
-
updateHandlers = handlers;
|
1191
|
-
return pluginFunc;
|
1192
|
-
},
|
1193
|
-
update: (handlers) => {
|
1194
|
-
updateHandlers = handlers;
|
1195
|
-
return null;
|
1196
|
-
}
|
1197
|
-
};
|
1198
|
-
},
|
1199
|
-
next: pluginFacet,
|
1200
|
-
singleton: true
|
1201
|
-
});
|
1202
|
-
var pluginKey = new PluginKey("prosekit-event-handler");
|
1203
|
-
|
1204
|
-
// src/extensions/history.ts
|
1205
|
-
import { history, redo, undo } from "@prosekit/pm/history";
|
1206
|
-
|
1207
|
-
// src/utils/env.ts
|
1208
|
-
var isMac = typeof navigator !== "undefined" ? /Mac|iP(hone|[ao]d)/.test(navigator.platform) : false;
|
1209
|
-
|
1210
1181
|
// src/extensions/keymap.ts
|
1211
|
-
import { baseKeymap, chainCommands } from "@prosekit/pm/commands";
|
1212
|
-
import { keydownHandler } from "@prosekit/pm/keymap";
|
1213
|
-
import { Plugin as Plugin3, PluginKey as PluginKey2 } from "@prosekit/pm/state";
|
1214
1182
|
function defineKeymap(keymap) {
|
1215
1183
|
return keymapFacet.extension([keymap]);
|
1216
1184
|
}
|
@@ -1259,7 +1227,7 @@ function mergeKeymaps(keymaps) {
|
|
1259
1227
|
])
|
1260
1228
|
);
|
1261
1229
|
}
|
1262
|
-
var keymapPluginKey = new
|
1230
|
+
var keymapPluginKey = new PluginKey("prosekit-keymap");
|
1263
1231
|
|
1264
1232
|
// src/extensions/history.ts
|
1265
1233
|
function defineHistory() {
|
@@ -1281,11 +1249,20 @@ function defineHistory() {
|
|
1281
1249
|
}
|
1282
1250
|
|
1283
1251
|
// src/extensions/input-rules.ts
|
1284
|
-
import { inputRules } from "@prosekit/pm/inputrules";
|
1252
|
+
import { InputRule, inputRules } from "@prosekit/pm/inputrules";
|
1285
1253
|
import "@prosekit/pm/model";
|
1286
1254
|
import "@prosekit/pm/state";
|
1287
|
-
function defineInputRule(
|
1288
|
-
|
1255
|
+
function defineInputRule(rule) {
|
1256
|
+
if (rule instanceof InputRule) {
|
1257
|
+
return inputRuleFacet.extension([() => rule]);
|
1258
|
+
}
|
1259
|
+
if (Array.isArray(rule) && rule.every((r) => r instanceof InputRule)) {
|
1260
|
+
return inputRuleFacet.extension([() => rule]);
|
1261
|
+
}
|
1262
|
+
if (typeof rule === "function") {
|
1263
|
+
return inputRuleFacet.extension([rule]);
|
1264
|
+
}
|
1265
|
+
throw new TypeError("Invalid input rule");
|
1289
1266
|
}
|
1290
1267
|
var inputRuleFacet = Facet.define({
|
1291
1268
|
convert: (inputs) => {
|
@@ -1316,7 +1293,7 @@ var markSpecFacet = Facet.define({
|
|
1316
1293
|
});
|
1317
1294
|
|
1318
1295
|
// src/extensions/node-view.ts
|
1319
|
-
import { ProseMirrorPlugin
|
1296
|
+
import { ProseMirrorPlugin } from "@prosekit/pm/state";
|
1320
1297
|
import "@prosekit/pm/view";
|
1321
1298
|
function defineNodeView(options) {
|
1322
1299
|
return nodeViewFacet.extension([options]);
|
@@ -1329,13 +1306,13 @@ var nodeViewFacet = Facet.define({
|
|
1329
1306
|
nodeViews[input.name] = input.constructor;
|
1330
1307
|
}
|
1331
1308
|
}
|
1332
|
-
return () => [new
|
1309
|
+
return () => [new ProseMirrorPlugin({ props: { nodeViews } })];
|
1333
1310
|
},
|
1334
1311
|
next: pluginFacet
|
1335
1312
|
});
|
1336
1313
|
|
1337
1314
|
// src/extensions/node-view-effect.ts
|
1338
|
-
import { ProseMirrorPlugin as
|
1315
|
+
import { ProseMirrorPlugin as ProseMirrorPlugin2 } from "@prosekit/pm/state";
|
1339
1316
|
import "@prosekit/pm/view";
|
1340
1317
|
function defineNodeViewEffect(options) {
|
1341
1318
|
return nodeViewEffectFacet.extension([options]);
|
@@ -1363,7 +1340,7 @@ var nodeViewEffectFacet = Facet.define({
|
|
1363
1340
|
nodeViews[name] = factory(args);
|
1364
1341
|
}
|
1365
1342
|
}
|
1366
|
-
return () => Object.keys(nodeViews).length > 0 ? [new
|
1343
|
+
return () => Object.keys(nodeViews).length > 0 ? [new ProseMirrorPlugin2({ props: { nodeViews } })] : [];
|
1367
1344
|
},
|
1368
1345
|
next: pluginFacet
|
1369
1346
|
});
|
@@ -1391,6 +1368,48 @@ function defineText() {
|
|
1391
1368
|
group: "inline"
|
1392
1369
|
});
|
1393
1370
|
}
|
1371
|
+
|
1372
|
+
// src/extensions/update-handler.ts
|
1373
|
+
import { PluginKey as PluginKey2, ProseMirrorPlugin as ProseMirrorPlugin3 } from "@prosekit/pm/state";
|
1374
|
+
|
1375
|
+
// src/utils/is-not-null.ts
|
1376
|
+
function isNotNull(value) {
|
1377
|
+
return value != null;
|
1378
|
+
}
|
1379
|
+
|
1380
|
+
// src/extensions/update-handler.ts
|
1381
|
+
function defineUpdateHandler(handler) {
|
1382
|
+
return updateHandlerFacet.extension([handler]);
|
1383
|
+
}
|
1384
|
+
var updateHandlerFacet = Facet.define({
|
1385
|
+
converter: () => {
|
1386
|
+
let updateHandlers = [];
|
1387
|
+
const plugin = new ProseMirrorPlugin3({
|
1388
|
+
key: pluginKey,
|
1389
|
+
view: () => {
|
1390
|
+
return {
|
1391
|
+
update: (view, prevState) => {
|
1392
|
+
updateHandlers.forEach((fn) => fn({ view, prevState }));
|
1393
|
+
}
|
1394
|
+
};
|
1395
|
+
}
|
1396
|
+
});
|
1397
|
+
const pluginFunc = () => [plugin];
|
1398
|
+
return {
|
1399
|
+
create: (handlers) => {
|
1400
|
+
updateHandlers = handlers.filter(isNotNull);
|
1401
|
+
return pluginFunc;
|
1402
|
+
},
|
1403
|
+
update: (handlers) => {
|
1404
|
+
updateHandlers = handlers.filter(isNotNull);
|
1405
|
+
return null;
|
1406
|
+
}
|
1407
|
+
};
|
1408
|
+
},
|
1409
|
+
next: pluginFacet,
|
1410
|
+
singleton: true
|
1411
|
+
});
|
1412
|
+
var pluginKey = new PluginKey2("prosekit-event-handler");
|
1394
1413
|
export {
|
1395
1414
|
Editor,
|
1396
1415
|
Facet,
|
@@ -1403,7 +1422,6 @@ export {
|
|
1403
1422
|
defineCommands,
|
1404
1423
|
defineDefaultState,
|
1405
1424
|
defineDoc,
|
1406
|
-
defineEventHandler,
|
1407
1425
|
defineHistory,
|
1408
1426
|
defineInputRule,
|
1409
1427
|
defineKeymap,
|
@@ -1414,18 +1432,21 @@ export {
|
|
1414
1432
|
defineParagraph,
|
1415
1433
|
definePlugin,
|
1416
1434
|
defineText,
|
1417
|
-
|
1418
|
-
elementToNode,
|
1435
|
+
defineUpdateHandler,
|
1419
1436
|
getMarkType,
|
1420
1437
|
getNodeType,
|
1421
|
-
htmlToJSON,
|
1422
|
-
htmlToNode,
|
1423
1438
|
insertNode,
|
1424
1439
|
isAllSelection,
|
1425
1440
|
isMark,
|
1426
1441
|
isNodeSelection,
|
1427
1442
|
isProseMirrorNode,
|
1428
1443
|
isTextSelection,
|
1444
|
+
jsonFromElement,
|
1445
|
+
jsonFromHTML,
|
1446
|
+
jsonFromNode,
|
1447
|
+
jsonFromState,
|
1448
|
+
nodeFromElement,
|
1449
|
+
nodeFromHTML,
|
1429
1450
|
pluginFacet,
|
1430
1451
|
removeMark,
|
1431
1452
|
setBlockType,
|
package/dist/style.css
CHANGED
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prosekit/core",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.0
|
4
|
+
"version": "0.1.0",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -38,9 +38,9 @@
|
|
38
38
|
"dist"
|
39
39
|
],
|
40
40
|
"dependencies": {
|
41
|
-
"@prosekit/pm": "^0.0
|
41
|
+
"@prosekit/pm": "^0.1.0",
|
42
42
|
"orderedmap": "^2.1.1",
|
43
|
-
"type-fest": "^4.
|
43
|
+
"type-fest": "^4.7.1"
|
44
44
|
},
|
45
45
|
"devDependencies": {
|
46
46
|
"@prosekit/dev": "*",
|