@prosekit/extensions 0.16.0-beta.0 → 0.16.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/{prosekit-extensions-autocomplete.d.ts → autocomplete.d.ts} +1 -6
- package/dist/autocomplete.d.ts.map +1 -0
- package/dist/{prosekit-extensions-autocomplete.js → autocomplete.js} +1 -9
- package/dist/autocomplete.js.map +1 -0
- package/dist/{prosekit-extensions-background-color.d.ts → background-color.d.ts} +1 -8
- package/dist/background-color.d.ts.map +1 -0
- package/dist/{prosekit-extensions-background-color.js → background-color.js} +1 -7
- package/dist/background-color.js.map +1 -0
- package/dist/{prosekit-extensions-blockquote.d.ts → blockquote.d.ts} +1 -12
- package/dist/blockquote.d.ts.map +1 -0
- package/dist/{prosekit-extensions-blockquote.js → blockquote.js} +2 -12
- package/dist/blockquote.js.map +1 -0
- package/dist/{prosekit-extensions-bold.d.ts → bold.d.ts} +1 -12
- package/dist/bold.d.ts.map +1 -0
- package/dist/{prosekit-extensions-bold.js → bold.js} +2 -12
- package/dist/bold.js.map +1 -0
- package/dist/{prosekit-extensions-code-block.d.ts → code-block.d.ts} +1 -20
- package/dist/code-block.d.ts.map +1 -0
- package/dist/{prosekit-extensions-code-block.js → code-block.js} +3 -21
- package/dist/code-block.js.map +1 -0
- package/dist/{prosekit-extensions-code.d.ts → code.d.ts} +1 -12
- package/dist/code.d.ts.map +1 -0
- package/dist/{prosekit-extensions-code.js → code.js} +2 -12
- package/dist/code.js.map +1 -0
- package/dist/{prosekit-extensions-commit.d.ts → commit.d.ts} +1 -4
- package/dist/commit.d.ts.map +1 -0
- package/dist/{prosekit-extensions-commit.js → commit.js} +1 -3
- package/dist/commit.js.map +1 -0
- package/dist/{prosekit-extensions-doc.d.ts → doc.d.ts} +1 -4
- package/dist/doc.d.ts.map +1 -0
- package/dist/{prosekit-extensions-doc.js → doc.js} +1 -3
- package/dist/doc.js.map +1 -0
- package/dist/{prosekit-extensions-drop-cursor.d.ts → drop-cursor.d.ts} +1 -4
- package/dist/drop-cursor.d.ts.map +1 -0
- package/dist/{prosekit-extensions-drop-cursor.js → drop-cursor.js} +1 -3
- package/dist/drop-cursor.js.map +1 -0
- package/dist/{prosekit-extensions-drop-indicator.d.ts → drop-indicator.d.ts} +1 -4
- package/dist/drop-indicator.d.ts.map +1 -0
- package/dist/drop-indicator.js +2 -57
- package/dist/drop-indicator2.js +53 -0
- package/dist/drop-indicator2.js.map +1 -0
- package/dist/{prosekit-extensions-enter-rule.d.ts → enter-rule.d.ts} +1 -4
- package/dist/enter-rule.d.ts.map +1 -0
- package/dist/{prosekit-extensions-enter-rule.js → enter-rule.js} +1 -3
- package/dist/enter-rule.js.map +1 -0
- package/dist/file.js +2 -128
- package/dist/file2.js +120 -0
- package/dist/file2.js.map +1 -0
- package/dist/{prosekit-extensions-gap-cursor.d.ts → gap-cursor.d.ts} +1 -4
- package/dist/gap-cursor.d.ts.map +1 -0
- package/dist/{prosekit-extensions-gap-cursor.js → gap-cursor.js} +1 -3
- package/dist/gap-cursor.js.map +1 -0
- package/dist/{prosekit-extensions-hard-break.d.ts → hard-break.d.ts} +1 -10
- package/dist/hard-break.d.ts.map +1 -0
- package/dist/{prosekit-extensions-hard-break.js → hard-break.js} +1 -9
- package/dist/hard-break.js.map +1 -0
- package/dist/{prosekit-extensions-heading.d.ts → heading.d.ts} +1 -14
- package/dist/heading.d.ts.map +1 -0
- package/dist/{prosekit-extensions-heading.js → heading.js} +2 -12
- package/dist/heading.js.map +1 -0
- package/dist/{prosekit-extensions-horizontal-rule.d.ts → horizontal-rule.d.ts} +1 -10
- package/dist/horizontal-rule.d.ts.map +1 -0
- package/dist/{prosekit-extensions-horizontal-rule.js → horizontal-rule.js} +2 -10
- package/dist/horizontal-rule.js.map +1 -0
- package/dist/{prosekit-extensions-image.d.ts → image.d.ts} +1 -14
- package/dist/image.d.ts.map +1 -0
- package/dist/{prosekit-extensions-image.js → image.js} +2 -14
- package/dist/image.js.map +1 -0
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/{prosekit-extensions-input-rule.d.ts → input-rule.d.ts} +1 -4
- package/dist/input-rule.d.ts.map +1 -0
- package/dist/{prosekit-extensions-input-rule.js → input-rule.js} +1 -3
- package/dist/input-rule.js.map +1 -0
- package/dist/{prosekit-extensions-italic.d.ts → italic.d.ts} +1 -12
- package/dist/italic.d.ts.map +1 -0
- package/dist/{prosekit-extensions-italic.js → italic.js} +2 -12
- package/dist/italic.js.map +1 -0
- package/dist/{prosekit-extensions-link.d.ts → link.d.ts} +1 -8
- package/dist/link.d.ts.map +1 -0
- package/dist/{prosekit-extensions-link.js → link.js} +5 -11
- package/dist/link.js.map +1 -0
- package/dist/{prosekit-extensions-list.d.ts → list.d.ts} +1 -18
- package/dist/list.d.ts.map +1 -0
- package/dist/{prosekit-extensions-list.js → list.js} +3 -19
- package/dist/list.js.map +1 -0
- package/dist/{prosekit-extensions-loro.d.ts → loro.d.ts} +1 -14
- package/dist/loro.d.ts.map +1 -0
- package/dist/{prosekit-extensions-loro.js → loro.js} +1 -13
- package/dist/loro.js.map +1 -0
- package/dist/{prosekit-extensions-mark-rule.d.ts → mark-rule.d.ts} +1 -6
- package/dist/mark-rule.d.ts.map +1 -0
- package/dist/mark-rule.js +2 -157
- package/dist/mark-rule2.js +151 -0
- package/dist/mark-rule2.js.map +1 -0
- package/dist/{prosekit-extensions-math.d.ts → math.d.ts} +1 -10
- package/dist/math.d.ts.map +1 -0
- package/dist/{prosekit-extensions-math.js → math.js} +3 -11
- package/dist/math.js.map +1 -0
- package/dist/{prosekit-extensions-mention.d.ts → mention.d.ts} +1 -4
- package/dist/mention.d.ts.map +1 -0
- package/dist/{prosekit-extensions-mention.js → mention.js} +1 -3
- package/dist/mention.js.map +1 -0
- package/dist/{prosekit-extensions-mod-click-prevention.d.ts → mod-click-prevention.d.ts} +1 -4
- package/dist/mod-click-prevention.d.ts.map +1 -0
- package/dist/{prosekit-extensions-mod-click-prevention.js → mod-click-prevention.js} +1 -3
- package/dist/mod-click-prevention.js.map +1 -0
- package/dist/{prosekit-extensions-page.d.ts → page.d.ts} +1 -12
- package/dist/page.d.ts.map +1 -0
- package/dist/{prosekit-extensions-page.js → page.js} +3 -15
- package/dist/page.js.map +1 -0
- package/dist/{prosekit-extensions-paragraph.d.ts → paragraph.d.ts} +1 -10
- package/dist/paragraph.d.ts.map +1 -0
- package/dist/{prosekit-extensions-paragraph.js → paragraph.js} +1 -9
- package/dist/paragraph.js.map +1 -0
- package/dist/{prosekit-extensions-paste-rule.d.ts → paste-rule.d.ts} +1 -6
- package/dist/paste-rule.d.ts.map +1 -0
- package/dist/paste-rule.js +2 -158
- package/dist/paste-rule2.js +150 -0
- package/dist/paste-rule2.js.map +1 -0
- package/dist/{prosekit-extensions-placeholder.d.ts → placeholder.d.ts} +1 -4
- package/dist/placeholder.d.ts.map +1 -0
- package/dist/{prosekit-extensions-placeholder.js → placeholder.js} +2 -4
- package/dist/placeholder.js.map +1 -0
- package/dist/{prosekit-extensions-readonly.d.ts → readonly.d.ts} +1 -4
- package/dist/readonly.d.ts.map +1 -0
- package/dist/{prosekit-extensions-readonly.js → readonly.js} +6 -3
- package/dist/readonly.js.map +1 -0
- package/dist/{prosekit-extensions-search.d.ts → search.d.ts} +1 -4
- package/dist/search.d.ts.map +1 -0
- package/dist/{prosekit-extensions-search.js → search.js} +1 -3
- package/dist/search.js.map +1 -0
- package/dist/shiki-highlighter-chunk.js +0 -2
- package/dist/shiki-highlighter-chunk.js.map +1 -1
- package/dist/{prosekit-extensions-strike.d.ts → strike.d.ts} +1 -4
- package/dist/strike.d.ts.map +1 -0
- package/dist/{prosekit-extensions-strike.js → strike.js} +2 -4
- package/dist/strike.js.map +1 -0
- package/dist/{prosekit-extensions-table.d.ts → table.d.ts} +1 -26
- package/dist/table.d.ts.map +1 -0
- package/dist/table.js +2 -276
- package/dist/table2.js +252 -0
- package/dist/table2.js.map +1 -0
- package/dist/{prosekit-extensions-text-align.d.ts → text-align.d.ts} +1 -4
- package/dist/text-align.d.ts.map +1 -0
- package/dist/{prosekit-extensions-text-align.js → text-align.js} +1 -3
- package/dist/text-align.js.map +1 -0
- package/dist/{prosekit-extensions-text-color.d.ts → text-color.d.ts} +1 -8
- package/dist/text-color.d.ts.map +1 -0
- package/dist/{prosekit-extensions-text-color.js → text-color.js} +1 -7
- package/dist/text-color.js.map +1 -0
- package/dist/{prosekit-extensions-text.d.ts → text.d.ts} +1 -4
- package/dist/text.d.ts.map +1 -0
- package/dist/{prosekit-extensions-text.js → text.js} +1 -3
- package/dist/text.js.map +1 -0
- package/dist/{prosekit-extensions-underline.d.ts → underline.d.ts} +1 -4
- package/dist/underline.d.ts.map +1 -0
- package/dist/{prosekit-extensions-underline.js → underline.js} +1 -3
- package/dist/underline.js.map +1 -0
- package/dist/{prosekit-extensions-virtual-selection.d.ts → virtual-selection.d.ts} +1 -4
- package/dist/virtual-selection.d.ts.map +1 -0
- package/dist/{prosekit-extensions-virtual-selection.js → virtual-selection.js} +1 -3
- package/dist/virtual-selection.js.map +1 -0
- package/dist/{prosekit-extensions-yjs.d.ts → yjs.d.ts} +1 -16
- package/dist/yjs.d.ts.map +1 -0
- package/dist/{prosekit-extensions-yjs.js → yjs.js} +1 -13
- package/dist/yjs.js.map +1 -0
- package/package.json +136 -194
- package/src/page/page-element.ts +2 -2
- package/src/readonly/index.ts +6 -0
- package/dist/drop-indicator.js.map +0 -1
- package/dist/file.js.map +0 -1
- package/dist/mark-rule.js.map +0 -1
- package/dist/paste-rule.js.map +0 -1
- package/dist/prosekit-extensions-autocomplete.d.ts.map +0 -1
- package/dist/prosekit-extensions-autocomplete.js.map +0 -1
- package/dist/prosekit-extensions-background-color.d.ts.map +0 -1
- package/dist/prosekit-extensions-background-color.js.map +0 -1
- package/dist/prosekit-extensions-blockquote.d.ts.map +0 -1
- package/dist/prosekit-extensions-blockquote.js.map +0 -1
- package/dist/prosekit-extensions-bold.d.ts.map +0 -1
- package/dist/prosekit-extensions-bold.js.map +0 -1
- package/dist/prosekit-extensions-code-block.d.ts.map +0 -1
- package/dist/prosekit-extensions-code-block.js.map +0 -1
- package/dist/prosekit-extensions-code.d.ts.map +0 -1
- package/dist/prosekit-extensions-code.js.map +0 -1
- package/dist/prosekit-extensions-commit.d.ts.map +0 -1
- package/dist/prosekit-extensions-commit.js.map +0 -1
- package/dist/prosekit-extensions-doc.d.ts.map +0 -1
- package/dist/prosekit-extensions-doc.js.map +0 -1
- package/dist/prosekit-extensions-drop-cursor.d.ts.map +0 -1
- package/dist/prosekit-extensions-drop-cursor.js.map +0 -1
- package/dist/prosekit-extensions-drop-indicator.d.ts.map +0 -1
- package/dist/prosekit-extensions-drop-indicator.js +0 -2
- package/dist/prosekit-extensions-enter-rule.d.ts.map +0 -1
- package/dist/prosekit-extensions-enter-rule.js.map +0 -1
- package/dist/prosekit-extensions-file.js +0 -2
- package/dist/prosekit-extensions-gap-cursor.d.ts.map +0 -1
- package/dist/prosekit-extensions-gap-cursor.js.map +0 -1
- package/dist/prosekit-extensions-hard-break.d.ts.map +0 -1
- package/dist/prosekit-extensions-hard-break.js.map +0 -1
- package/dist/prosekit-extensions-heading.d.ts.map +0 -1
- package/dist/prosekit-extensions-heading.js.map +0 -1
- package/dist/prosekit-extensions-horizontal-rule.d.ts.map +0 -1
- package/dist/prosekit-extensions-horizontal-rule.js.map +0 -1
- package/dist/prosekit-extensions-image.d.ts.map +0 -1
- package/dist/prosekit-extensions-image.js.map +0 -1
- package/dist/prosekit-extensions-input-rule.d.ts.map +0 -1
- package/dist/prosekit-extensions-input-rule.js.map +0 -1
- package/dist/prosekit-extensions-italic.d.ts.map +0 -1
- package/dist/prosekit-extensions-italic.js.map +0 -1
- package/dist/prosekit-extensions-link.d.ts.map +0 -1
- package/dist/prosekit-extensions-link.js.map +0 -1
- package/dist/prosekit-extensions-list.d.ts.map +0 -1
- package/dist/prosekit-extensions-list.js.map +0 -1
- package/dist/prosekit-extensions-loro.d.ts.map +0 -1
- package/dist/prosekit-extensions-loro.js.map +0 -1
- package/dist/prosekit-extensions-mark-rule.d.ts.map +0 -1
- package/dist/prosekit-extensions-mark-rule.js +0 -2
- package/dist/prosekit-extensions-math.d.ts.map +0 -1
- package/dist/prosekit-extensions-math.js.map +0 -1
- package/dist/prosekit-extensions-mention.d.ts.map +0 -1
- package/dist/prosekit-extensions-mention.js.map +0 -1
- package/dist/prosekit-extensions-mod-click-prevention.d.ts.map +0 -1
- package/dist/prosekit-extensions-mod-click-prevention.js.map +0 -1
- package/dist/prosekit-extensions-page.d.ts.map +0 -1
- package/dist/prosekit-extensions-page.js.map +0 -1
- package/dist/prosekit-extensions-paragraph.d.ts.map +0 -1
- package/dist/prosekit-extensions-paragraph.js.map +0 -1
- package/dist/prosekit-extensions-paste-rule.d.ts.map +0 -1
- package/dist/prosekit-extensions-paste-rule.js +0 -2
- package/dist/prosekit-extensions-placeholder.d.ts.map +0 -1
- package/dist/prosekit-extensions-placeholder.js.map +0 -1
- package/dist/prosekit-extensions-readonly.d.ts.map +0 -1
- package/dist/prosekit-extensions-readonly.js.map +0 -1
- package/dist/prosekit-extensions-search.d.ts.map +0 -1
- package/dist/prosekit-extensions-search.js.map +0 -1
- package/dist/prosekit-extensions-strike.d.ts.map +0 -1
- package/dist/prosekit-extensions-strike.js.map +0 -1
- package/dist/prosekit-extensions-table.d.ts.map +0 -1
- package/dist/prosekit-extensions-table.js +0 -2
- package/dist/prosekit-extensions-text-align.d.ts.map +0 -1
- package/dist/prosekit-extensions-text-align.js.map +0 -1
- package/dist/prosekit-extensions-text-color.d.ts.map +0 -1
- package/dist/prosekit-extensions-text-color.js.map +0 -1
- package/dist/prosekit-extensions-text.d.ts.map +0 -1
- package/dist/prosekit-extensions-text.js.map +0 -1
- package/dist/prosekit-extensions-underline.d.ts.map +0 -1
- package/dist/prosekit-extensions-underline.js.map +0 -1
- package/dist/prosekit-extensions-virtual-selection.d.ts.map +0 -1
- package/dist/prosekit-extensions-virtual-selection.js.map +0 -1
- package/dist/prosekit-extensions-yjs.d.ts.map +0 -1
- package/dist/prosekit-extensions-yjs.js.map +0 -1
- package/dist/table.js.map +0 -1
- /package/dist/{prosekit-extensions-file.d.ts → file.d.ts} +0 -0
- /package/dist/{prosekit-extensions.js → index.js} +0 -0
- /package/dist/{prosekit-extensions.d.ts → index2.d.ts} +0 -0
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { defineCommands, defineKeymap, definePlugin, isApple, union, withPriority } from "@prosekit/core";
|
|
2
2
|
import { LoroCursorPlugin, LoroEphemeralCursorPlugin, LoroSyncPlugin, LoroUndoPlugin, redo, undo } from "loro-prosemirror";
|
|
3
|
-
//#region src/loro/loro-commands.ts
|
|
4
3
|
const commands = {
|
|
5
4
|
undo: () => undo,
|
|
6
5
|
redo: () => redo
|
|
@@ -8,8 +7,6 @@ const commands = {
|
|
|
8
7
|
function defineLoroCommands() {
|
|
9
8
|
return defineCommands(commands);
|
|
10
9
|
}
|
|
11
|
-
//#endregion
|
|
12
|
-
//#region src/loro/loro-cursor-plugin.ts
|
|
13
10
|
function defineLoroCursorPlugin(options) {
|
|
14
11
|
return definePlugin(createLoroCursorPlugin(options));
|
|
15
12
|
}
|
|
@@ -20,8 +17,6 @@ function createLoroCursorPlugin(options) {
|
|
|
20
17
|
else if (presence) return LoroEphemeralCursorPlugin(presence, rest);
|
|
21
18
|
else throw new Error("Either awareness or presence must be provided");
|
|
22
19
|
}
|
|
23
|
-
//#endregion
|
|
24
|
-
//#region src/loro/loro-keymap.ts
|
|
25
20
|
const keymap = {
|
|
26
21
|
"Mod-z": undo,
|
|
27
22
|
"Mod-Z": redo
|
|
@@ -30,18 +25,12 @@ if (!isApple) keymap["Mod-y"] = redo;
|
|
|
30
25
|
function defineLoroKeymap() {
|
|
31
26
|
return defineKeymap(keymap);
|
|
32
27
|
}
|
|
33
|
-
//#endregion
|
|
34
|
-
//#region src/loro/loro-sync-plugin.ts
|
|
35
28
|
function defineLoroSyncPlugin(options) {
|
|
36
29
|
return definePlugin(LoroSyncPlugin(options));
|
|
37
30
|
}
|
|
38
|
-
//#endregion
|
|
39
|
-
//#region src/loro/loro-undo-plugin.ts
|
|
40
31
|
function defineLoroUndoPlugin(options) {
|
|
41
32
|
return definePlugin(LoroUndoPlugin(options));
|
|
42
33
|
}
|
|
43
|
-
//#endregion
|
|
44
|
-
//#region src/loro/loro.ts
|
|
45
34
|
/**
|
|
46
35
|
* @public
|
|
47
36
|
*/
|
|
@@ -65,7 +54,6 @@ function defineLoro(options) {
|
|
|
65
54
|
})
|
|
66
55
|
]), 3);
|
|
67
56
|
}
|
|
68
|
-
//#endregion
|
|
69
57
|
export { defineLoro, defineLoroCommands, defineLoroCursorPlugin, defineLoroKeymap, defineLoroSyncPlugin, defineLoroUndoPlugin };
|
|
70
58
|
|
|
71
|
-
//# sourceMappingURL=
|
|
59
|
+
//# sourceMappingURL=loro.js.map
|
package/dist/loro.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loro.js","names":[],"sources":["../src/loro/loro-commands.ts","../src/loro/loro-cursor-plugin.ts","../src/loro/loro-keymap.ts","../src/loro/loro-sync-plugin.ts","../src/loro/loro-undo-plugin.ts","../src/loro/loro.ts"],"sourcesContent":["import { defineCommands, type Extension } from '@prosekit/core'\nimport { redo, undo } from 'loro-prosemirror'\n\nconst commands = {\n undo: () => undo,\n redo: () => redo,\n} as const\n\n/**\n * @internal\n */\nexport type LoroCommandsExtension = Extension<{\n Commands: {\n undo: []\n redo: []\n }\n}>\n\nexport function defineLoroCommands(): LoroCommandsExtension {\n return defineCommands(commands)\n}\n","import { definePlugin, type PlainExtension } from '@prosekit/core'\nimport type { Plugin } from '@prosekit/pm/state'\nimport type { CursorAwareness, CursorEphemeralStore, CursorPluginOptions } from 'loro-prosemirror'\nimport { LoroCursorPlugin, LoroEphemeralCursorPlugin } from 'loro-prosemirror'\n\nexport interface LoroCursorOptions extends CursorPluginOptions {\n awareness?: CursorAwareness\n presence?: CursorEphemeralStore\n}\n\nexport function defineLoroCursorPlugin(\n options: LoroCursorOptions,\n): PlainExtension {\n return definePlugin(createLoroCursorPlugin(options))\n}\n\nfunction createLoroCursorPlugin(options: LoroCursorOptions): Plugin {\n const { awareness, presence, ...rest } = options\n if (awareness && presence) {\n throw new Error('Only one of awareness and presence can be provided')\n } else if (awareness) {\n return LoroCursorPlugin(awareness, rest)\n } else if (presence) {\n return LoroEphemeralCursorPlugin(presence, rest)\n } else {\n throw new Error('Either awareness or presence must be provided')\n }\n}\n","import { defineKeymap, isApple, type Keymap, type PlainExtension } from '@prosekit/core'\nimport { redo, undo } from 'loro-prosemirror'\n\nconst keymap: Keymap = {\n 'Mod-z': undo,\n 'Mod-Z': redo,\n}\n\nif (!isApple) {\n keymap['Mod-y'] = redo\n}\n\nexport function defineLoroKeymap(): PlainExtension {\n return defineKeymap(keymap)\n}\n","import { definePlugin, type PlainExtension } from '@prosekit/core'\nimport { LoroSyncPlugin, type LoroSyncPluginProps } from 'loro-prosemirror'\n\nexport function defineLoroSyncPlugin(\n options: LoroSyncPluginProps,\n): PlainExtension {\n return definePlugin(LoroSyncPlugin(options))\n}\n","import { definePlugin, type PlainExtension } from '@prosekit/core'\nimport { LoroUndoPlugin, type LoroUndoPluginProps } from 'loro-prosemirror'\n\nexport function defineLoroUndoPlugin(options: LoroUndoPluginProps): PlainExtension {\n return definePlugin(LoroUndoPlugin(options))\n}\n","import type { Priority } from '@prosekit/core'\nimport { union, withPriority, type PlainExtension, type Union } from '@prosekit/core'\nimport type {\n CursorAwareness,\n CursorEphemeralStore,\n CursorPluginOptions,\n LoroDocType,\n LoroSyncPluginProps,\n LoroUndoPluginProps,\n} from 'loro-prosemirror'\n\nimport { defineLoroCommands, type LoroCommandsExtension } from './loro-commands.ts'\nimport { defineLoroCursorPlugin } from './loro-cursor-plugin.ts'\nimport { defineLoroKeymap } from './loro-keymap.ts'\nimport { defineLoroSyncPlugin } from './loro-sync-plugin.ts'\nimport { defineLoroUndoPlugin } from './loro-undo-plugin.ts'\n\nexport interface LoroOptions {\n /**\n * The Loro instance handles the state of shared data.\n */\n doc: LoroDocType\n\n /**\n * The (legacy) Awareness instance. One of `awareness` or `presence` must be provided.\n */\n awareness?: CursorAwareness\n\n /**\n * The CursorEphemeralStore instance. One of `awareness` or `presence` must be provided.\n */\n presence?: CursorEphemeralStore\n\n /**\n * Extra options for `LoroSyncPlugin`.\n */\n sync?: Omit<LoroSyncPluginProps, 'doc'>\n\n /**\n * Extra options for the `LoroUndoPlugin`.\n */\n undo?: Omit<LoroUndoPluginProps, 'doc'>\n\n /**\n * Extra options for `LoroCursorPlugin` or `LoroEphemeralCursorPlugin`.\n */\n cursor?: CursorPluginOptions\n}\n\n/**\n * @internal\n */\nexport type LoroExtension = Union<[LoroCommandsExtension, PlainExtension]>\n\n/**\n * @public\n */\nexport function defineLoro(options: LoroOptions): LoroExtension {\n const { doc, awareness, presence, sync, undo, cursor } = options\n\n return withPriority(\n union([\n defineLoroKeymap(),\n defineLoroCommands(),\n defineLoroCursorPlugin({ ...cursor, awareness, presence }),\n defineLoroUndoPlugin({ ...undo, doc }),\n defineLoroSyncPlugin({ ...sync, doc }),\n ]),\n 3 satisfies typeof Priority.high,\n )\n}\n"],"mappings":";;AAGA,MAAM,WAAW;CACf,YAAY;CACZ,YAAY;CACb;AAYD,SAAgB,qBAA4C;AAC1D,QAAO,eAAe,SAAS;;ACTjC,SAAgB,uBACd,SACgB;AAChB,QAAO,aAAa,uBAAuB,QAAQ,CAAC;;AAGtD,SAAS,uBAAuB,SAAoC;CAClE,MAAM,EAAE,WAAW,UAAU,GAAG,SAAS;AACzC,KAAI,aAAa,SACf,OAAM,IAAI,MAAM,qDAAqD;UAC5D,UACT,QAAO,iBAAiB,WAAW,KAAK;UAC/B,SACT,QAAO,0BAA0B,UAAU,KAAK;KAEhD,OAAM,IAAI,MAAM,gDAAgD;;ACtBpE,MAAM,SAAiB;CACrB,SAAS;CACT,SAAS;CACV;AAED,IAAI,CAAC,QACH,QAAO,WAAW;AAGpB,SAAgB,mBAAmC;AACjD,QAAO,aAAa,OAAO;;ACV7B,SAAgB,qBACd,SACgB;AAChB,QAAO,aAAa,eAAe,QAAQ,CAAC;;ACH9C,SAAgB,qBAAqB,SAA8C;AACjF,QAAO,aAAa,eAAe,QAAQ,CAAC;;;;;ACqD9C,SAAgB,WAAW,SAAqC;CAC9D,MAAM,EAAE,KAAK,WAAW,UAAU,MAAM,MAAM,WAAW;AAEzD,QAAO,aACL,MAAM;EACJ,kBAAkB;EAClB,oBAAoB;EACpB,uBAAuB;GAAE,GAAG;GAAQ;GAAW;GAAU,CAAC;EAC1D,qBAAqB;GAAE,GAAG;GAAM;GAAK,CAAC;EACtC,qBAAqB;GAAE,GAAG;GAAM;GAAK,CAAC;EACvC,CAAC,EACF,EACD"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { PlainExtension } from "@prosekit/core";
|
|
2
2
|
import { Attrs, MarkType } from "@prosekit/pm/model";
|
|
3
|
-
|
|
4
|
-
//#region src/mark-rule/types.d.ts
|
|
5
3
|
/**
|
|
6
4
|
* The options for {@link defineMarkRule}.
|
|
7
5
|
*
|
|
@@ -25,13 +23,10 @@ interface MarkRuleOptions {
|
|
|
25
23
|
*/
|
|
26
24
|
attrs?: Attrs | null | ((match: RegExpMatchArray) => Attrs | null);
|
|
27
25
|
}
|
|
28
|
-
//#endregion
|
|
29
|
-
//#region src/mark-rule/mark-rule.d.ts
|
|
30
26
|
/**
|
|
31
27
|
* A mark rule is something that can automatically apply marks to text if it
|
|
32
28
|
* matches a certain pattern, and remove them if it doesn't match anymore.
|
|
33
29
|
*/
|
|
34
30
|
declare function defineMarkRule(options: MarkRuleOptions): PlainExtension;
|
|
35
|
-
//#endregion
|
|
36
31
|
export { type MarkRuleOptions, defineMarkRule };
|
|
37
|
-
//# sourceMappingURL=
|
|
32
|
+
//# sourceMappingURL=mark-rule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mark-rule.d.ts","names":[],"sources":["../src/mark-rule/types.ts","../src/mark-rule/mark-rule.ts"],"mappings":";;;;AAOA;;;UAAiB,eAAA;EAUA;;;;EALf,KAAA,EAAO,MAAA;EAamD;;;EAR1D,IAAA,WAAe,QAAA;EAAA;;;;;;EAQf,KAAA,GAAQ,KAAA,YAAiB,KAAA,EAAO,gBAAA,KAAqB,KAAA;AAAA;;AAlBvD;;;iBCGgB,cAAA,CAAe,OAAA,EAAS,eAAA,GAAkB,cAAA"}
|
package/dist/mark-rule.js
CHANGED
|
@@ -1,157 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/mark-rule/range.ts
|
|
4
|
-
function getSpanTextRanges($from, $to) {
|
|
5
|
-
const nodeRange = $from.blockRange($to);
|
|
6
|
-
if (!nodeRange) return [];
|
|
7
|
-
const stack = [];
|
|
8
|
-
let start = nodeRange.start;
|
|
9
|
-
for (let i = nodeRange.startIndex; i < nodeRange.endIndex; i++) {
|
|
10
|
-
const child = nodeRange.parent.child(i);
|
|
11
|
-
stack.push([start, child]);
|
|
12
|
-
start += child.nodeSize;
|
|
13
|
-
}
|
|
14
|
-
const ranges = [];
|
|
15
|
-
while (stack.length > 0) {
|
|
16
|
-
const [start, node] = stack.pop();
|
|
17
|
-
if (node.type.spec.code) continue;
|
|
18
|
-
if (node.type.isTextblock) {
|
|
19
|
-
ranges.push([start + 1, start + 1 + node.content.size]);
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
node.forEach((child, offset) => {
|
|
23
|
-
stack.push([start + offset + 1, child]);
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
return ranges;
|
|
27
|
-
}
|
|
28
|
-
function getInlineTextRange($from, $to) {
|
|
29
|
-
return [$from.start(), $to.end()];
|
|
30
|
-
}
|
|
31
|
-
function getTextRanges(doc, from, to) {
|
|
32
|
-
const $from = doc.resolve(from);
|
|
33
|
-
const $to = doc.resolve(to);
|
|
34
|
-
if ($from.sameParent($to) && $from.parent.isTextblock) return [getInlineTextRange($from, $to)];
|
|
35
|
-
else {
|
|
36
|
-
if (!$from.blockRange($to)) return [];
|
|
37
|
-
return getSpanTextRanges($from, $to);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
function getMapRange(transactions, oldState, newState) {
|
|
41
|
-
let lo = oldState.selection.from;
|
|
42
|
-
let hi = oldState.selection.to;
|
|
43
|
-
for (const tr of transactions) for (const map of tr.mapping.maps) {
|
|
44
|
-
lo = map.map(lo);
|
|
45
|
-
hi = map.map(hi);
|
|
46
|
-
map.forEach((_oldStart, _oldEnd, newStart, newEnd) => {
|
|
47
|
-
lo = Math.min(lo, hi, newStart);
|
|
48
|
-
hi = Math.max(lo, hi, newEnd);
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
lo = Math.min(lo, hi, newState.selection.from);
|
|
52
|
-
hi = Math.min(lo, hi, newState.selection.to);
|
|
53
|
-
return [lo, hi];
|
|
54
|
-
}
|
|
55
|
-
function getCheckRanges(transactions, oldState, newState) {
|
|
56
|
-
const [from, to] = getMapRange(transactions, oldState, newState);
|
|
57
|
-
return getTextRanges(newState.doc, from, to);
|
|
58
|
-
}
|
|
59
|
-
//#endregion
|
|
60
|
-
//#region src/mark-rule/apply.ts
|
|
61
|
-
function getExpectedMarkings(rules, doc, from, to) {
|
|
62
|
-
const text = doc.textBetween(from, to, null, OBJECT_REPLACEMENT_CHARACTER);
|
|
63
|
-
const ranges = [];
|
|
64
|
-
for (const rule of rules) {
|
|
65
|
-
rule.regex.lastIndex = 0;
|
|
66
|
-
const matches = text.matchAll(rule.regex);
|
|
67
|
-
const markType = getMarkType(doc.type.schema, rule.type);
|
|
68
|
-
for (const match of matches) {
|
|
69
|
-
const index = match.index;
|
|
70
|
-
if (index == null) continue;
|
|
71
|
-
const attrs = maybeRun(rule.attrs, match);
|
|
72
|
-
const mark = markType.create(attrs);
|
|
73
|
-
ranges.push([
|
|
74
|
-
from + index,
|
|
75
|
-
from + index + match[0].length,
|
|
76
|
-
mark
|
|
77
|
-
]);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
ranges.sort((a, b) => a[0] - b[0] || b[1] - a[1]);
|
|
81
|
-
const result = [];
|
|
82
|
-
let freeIndex = 0;
|
|
83
|
-
for (const range of ranges) if (range[0] >= freeIndex) {
|
|
84
|
-
result.push(range);
|
|
85
|
-
freeIndex = range[1];
|
|
86
|
-
}
|
|
87
|
-
return result;
|
|
88
|
-
}
|
|
89
|
-
function getReceivedMarkings(rules, doc, from, to) {
|
|
90
|
-
const result = [];
|
|
91
|
-
const schema = doc.type.schema;
|
|
92
|
-
const markTypes = rules.map((rule) => getMarkType(schema, rule.type));
|
|
93
|
-
doc.nodesBetween(from, to, (node, pos) => {
|
|
94
|
-
if (!node.isInline) return;
|
|
95
|
-
for (const markType of markTypes) {
|
|
96
|
-
const mark = node.marks.find((mark) => mark.type === markType);
|
|
97
|
-
if (mark) result.push([
|
|
98
|
-
pos,
|
|
99
|
-
pos + node.nodeSize,
|
|
100
|
-
mark
|
|
101
|
-
]);
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
return result;
|
|
105
|
-
}
|
|
106
|
-
function markRangeEquals(a, b) {
|
|
107
|
-
return a[0] === b[0] && a[1] === b[1] && a[2].eq(b[2]);
|
|
108
|
-
}
|
|
109
|
-
function markRangeDiffs(a, b) {
|
|
110
|
-
return a.filter((x) => !b.some((y) => markRangeEquals(x, y)));
|
|
111
|
-
}
|
|
112
|
-
function applyMarkRules(rules, transactions, oldState, newState) {
|
|
113
|
-
if (transactions.length === 0 || transactions.every((tr) => !tr.docChanged)) return null;
|
|
114
|
-
const ranges = getCheckRanges(transactions, oldState, newState);
|
|
115
|
-
const toRemove = [];
|
|
116
|
-
const toCreate = [];
|
|
117
|
-
for (const [from, to] of ranges) {
|
|
118
|
-
const expected = getExpectedMarkings(rules, newState.doc, from, to);
|
|
119
|
-
const received = getReceivedMarkings(rules, newState.doc, from, to);
|
|
120
|
-
toRemove.push(...markRangeDiffs(received, expected));
|
|
121
|
-
toCreate.push(...markRangeDiffs(expected, received));
|
|
122
|
-
}
|
|
123
|
-
if (toCreate.length === 0 && toRemove.length === 0) return null;
|
|
124
|
-
const tr = newState.tr;
|
|
125
|
-
for (const [from, to, mark] of toRemove) tr.removeMark(from, to, mark);
|
|
126
|
-
for (const [from, to, mark] of toCreate) tr.addMark(from, to, mark);
|
|
127
|
-
return tr;
|
|
128
|
-
}
|
|
129
|
-
//#endregion
|
|
130
|
-
//#region src/mark-rule/mark-rule.ts
|
|
131
|
-
/**
|
|
132
|
-
* A mark rule is something that can automatically apply marks to text if it
|
|
133
|
-
* matches a certain pattern, and remove them if it doesn't match anymore.
|
|
134
|
-
*/
|
|
135
|
-
function defineMarkRule(options) {
|
|
136
|
-
return defineFacetPayload(markRuleFacet, [options]);
|
|
137
|
-
}
|
|
138
|
-
const markRuleFacet = defineFacet({
|
|
139
|
-
reduce: () => {
|
|
140
|
-
let rules = [];
|
|
141
|
-
const plugin = new ProseMirrorPlugin({
|
|
142
|
-
key: new PluginKey("prosekit-mark-rule"),
|
|
143
|
-
appendTransaction: (transactions, oldState, newState) => {
|
|
144
|
-
return applyMarkRules(rules, transactions, oldState, newState);
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
return function reducer(input) {
|
|
148
|
-
rules = input;
|
|
149
|
-
return plugin;
|
|
150
|
-
};
|
|
151
|
-
},
|
|
152
|
-
parent: pluginFacet
|
|
153
|
-
});
|
|
154
|
-
//#endregion
|
|
155
|
-
export { defineMarkRule as t };
|
|
156
|
-
|
|
157
|
-
//# sourceMappingURL=mark-rule.js.map
|
|
1
|
+
import { t as defineMarkRule } from "./mark-rule2.js";
|
|
2
|
+
export { defineMarkRule };
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { PluginKey, ProseMirrorPlugin } from "@prosekit/pm/state";
|
|
2
|
+
import { OBJECT_REPLACEMENT_CHARACTER, defineFacet, defineFacetPayload, getMarkType, maybeRun, pluginFacet } from "@prosekit/core";
|
|
3
|
+
function getSpanTextRanges($from, $to) {
|
|
4
|
+
const nodeRange = $from.blockRange($to);
|
|
5
|
+
if (!nodeRange) return [];
|
|
6
|
+
const stack = [];
|
|
7
|
+
let start = nodeRange.start;
|
|
8
|
+
for (let i = nodeRange.startIndex; i < nodeRange.endIndex; i++) {
|
|
9
|
+
const child = nodeRange.parent.child(i);
|
|
10
|
+
stack.push([start, child]);
|
|
11
|
+
start += child.nodeSize;
|
|
12
|
+
}
|
|
13
|
+
const ranges = [];
|
|
14
|
+
while (stack.length > 0) {
|
|
15
|
+
const [start, node] = stack.pop();
|
|
16
|
+
if (node.type.spec.code) continue;
|
|
17
|
+
if (node.type.isTextblock) {
|
|
18
|
+
ranges.push([start + 1, start + 1 + node.content.size]);
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
node.forEach((child, offset) => {
|
|
22
|
+
stack.push([start + offset + 1, child]);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return ranges;
|
|
26
|
+
}
|
|
27
|
+
function getInlineTextRange($from, $to) {
|
|
28
|
+
return [$from.start(), $to.end()];
|
|
29
|
+
}
|
|
30
|
+
function getTextRanges(doc, from, to) {
|
|
31
|
+
const $from = doc.resolve(from);
|
|
32
|
+
const $to = doc.resolve(to);
|
|
33
|
+
if ($from.sameParent($to) && $from.parent.isTextblock) return [getInlineTextRange($from, $to)];
|
|
34
|
+
else {
|
|
35
|
+
if (!$from.blockRange($to)) return [];
|
|
36
|
+
return getSpanTextRanges($from, $to);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function getMapRange(transactions, oldState, newState) {
|
|
40
|
+
let lo = oldState.selection.from;
|
|
41
|
+
let hi = oldState.selection.to;
|
|
42
|
+
for (const tr of transactions) for (const map of tr.mapping.maps) {
|
|
43
|
+
lo = map.map(lo);
|
|
44
|
+
hi = map.map(hi);
|
|
45
|
+
map.forEach((_oldStart, _oldEnd, newStart, newEnd) => {
|
|
46
|
+
lo = Math.min(lo, hi, newStart);
|
|
47
|
+
hi = Math.max(lo, hi, newEnd);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
lo = Math.min(lo, hi, newState.selection.from);
|
|
51
|
+
hi = Math.min(lo, hi, newState.selection.to);
|
|
52
|
+
return [lo, hi];
|
|
53
|
+
}
|
|
54
|
+
function getCheckRanges(transactions, oldState, newState) {
|
|
55
|
+
const [from, to] = getMapRange(transactions, oldState, newState);
|
|
56
|
+
return getTextRanges(newState.doc, from, to);
|
|
57
|
+
}
|
|
58
|
+
function getExpectedMarkings(rules, doc, from, to) {
|
|
59
|
+
const text = doc.textBetween(from, to, null, OBJECT_REPLACEMENT_CHARACTER);
|
|
60
|
+
const ranges = [];
|
|
61
|
+
for (const rule of rules) {
|
|
62
|
+
rule.regex.lastIndex = 0;
|
|
63
|
+
const matches = text.matchAll(rule.regex);
|
|
64
|
+
const markType = getMarkType(doc.type.schema, rule.type);
|
|
65
|
+
for (const match of matches) {
|
|
66
|
+
const index = match.index;
|
|
67
|
+
if (index == null) continue;
|
|
68
|
+
const attrs = maybeRun(rule.attrs, match);
|
|
69
|
+
const mark = markType.create(attrs);
|
|
70
|
+
ranges.push([
|
|
71
|
+
from + index,
|
|
72
|
+
from + index + match[0].length,
|
|
73
|
+
mark
|
|
74
|
+
]);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
ranges.sort((a, b) => a[0] - b[0] || b[1] - a[1]);
|
|
78
|
+
const result = [];
|
|
79
|
+
let freeIndex = 0;
|
|
80
|
+
for (const range of ranges) if (range[0] >= freeIndex) {
|
|
81
|
+
result.push(range);
|
|
82
|
+
freeIndex = range[1];
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
function getReceivedMarkings(rules, doc, from, to) {
|
|
87
|
+
const result = [];
|
|
88
|
+
const schema = doc.type.schema;
|
|
89
|
+
const markTypes = rules.map((rule) => getMarkType(schema, rule.type));
|
|
90
|
+
doc.nodesBetween(from, to, (node, pos) => {
|
|
91
|
+
if (!node.isInline) return;
|
|
92
|
+
for (const markType of markTypes) {
|
|
93
|
+
const mark = node.marks.find((mark) => mark.type === markType);
|
|
94
|
+
if (mark) result.push([
|
|
95
|
+
pos,
|
|
96
|
+
pos + node.nodeSize,
|
|
97
|
+
mark
|
|
98
|
+
]);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
function markRangeEquals(a, b) {
|
|
104
|
+
return a[0] === b[0] && a[1] === b[1] && a[2].eq(b[2]);
|
|
105
|
+
}
|
|
106
|
+
function markRangeDiffs(a, b) {
|
|
107
|
+
return a.filter((x) => !b.some((y) => markRangeEquals(x, y)));
|
|
108
|
+
}
|
|
109
|
+
function applyMarkRules(rules, transactions, oldState, newState) {
|
|
110
|
+
if (transactions.length === 0 || transactions.every((tr) => !tr.docChanged)) return null;
|
|
111
|
+
const ranges = getCheckRanges(transactions, oldState, newState);
|
|
112
|
+
const toRemove = [];
|
|
113
|
+
const toCreate = [];
|
|
114
|
+
for (const [from, to] of ranges) {
|
|
115
|
+
const expected = getExpectedMarkings(rules, newState.doc, from, to);
|
|
116
|
+
const received = getReceivedMarkings(rules, newState.doc, from, to);
|
|
117
|
+
toRemove.push(...markRangeDiffs(received, expected));
|
|
118
|
+
toCreate.push(...markRangeDiffs(expected, received));
|
|
119
|
+
}
|
|
120
|
+
if (toCreate.length === 0 && toRemove.length === 0) return null;
|
|
121
|
+
const tr = newState.tr;
|
|
122
|
+
for (const [from, to, mark] of toRemove) tr.removeMark(from, to, mark);
|
|
123
|
+
for (const [from, to, mark] of toCreate) tr.addMark(from, to, mark);
|
|
124
|
+
return tr;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* A mark rule is something that can automatically apply marks to text if it
|
|
128
|
+
* matches a certain pattern, and remove them if it doesn't match anymore.
|
|
129
|
+
*/
|
|
130
|
+
function defineMarkRule(options) {
|
|
131
|
+
return defineFacetPayload(markRuleFacet, [options]);
|
|
132
|
+
}
|
|
133
|
+
const markRuleFacet = defineFacet({
|
|
134
|
+
reduce: () => {
|
|
135
|
+
let rules = [];
|
|
136
|
+
const plugin = new ProseMirrorPlugin({
|
|
137
|
+
key: new PluginKey("prosekit-mark-rule"),
|
|
138
|
+
appendTransaction: (transactions, oldState, newState) => {
|
|
139
|
+
return applyMarkRules(rules, transactions, oldState, newState);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
return function reducer(input) {
|
|
143
|
+
rules = input;
|
|
144
|
+
return plugin;
|
|
145
|
+
};
|
|
146
|
+
},
|
|
147
|
+
parent: pluginFacet
|
|
148
|
+
});
|
|
149
|
+
export { defineMarkRule as t };
|
|
150
|
+
|
|
151
|
+
//# sourceMappingURL=mark-rule2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mark-rule2.js","names":[],"sources":["../src/mark-rule/range.ts","../src/mark-rule/apply.ts","../src/mark-rule/mark-rule.ts"],"sourcesContent":["import type { ProseMirrorNode, ResolvedPos } from '@prosekit/pm/model'\nimport type { EditorState, Transaction } from '@prosekit/pm/state'\nimport type { ProsemirrorNode } from 'prosemirror-flat-list'\n\nfunction getSpanTextRanges($from: ResolvedPos, $to: ResolvedPos) {\n const nodeRange = $from.blockRange($to)\n if (!nodeRange) {\n return []\n }\n\n const stack: Array<[start: number, node: ProseMirrorNode]> = []\n let start = nodeRange.start\n\n for (let i = nodeRange.startIndex; i < nodeRange.endIndex; i++) {\n const child = nodeRange.parent.child(i)\n stack.push([start, child])\n start += child.nodeSize\n }\n\n const ranges: Array<[number, number]> = []\n\n while (stack.length > 0) {\n const [start, node] = stack.pop()!\n if (node.type.spec.code) {\n continue\n }\n\n if (node.type.isTextblock) {\n ranges.push([start + 1, start + 1 + node.content.size])\n continue\n }\n\n node.forEach((child, offset) => {\n stack.push([start + offset + 1, child])\n })\n }\n\n return ranges\n}\n\nfunction getInlineTextRange(\n $from: ResolvedPos,\n $to: ResolvedPos,\n): [number, number] {\n return [$from.start(), $to.end()]\n}\n\nfunction getTextRanges(\n doc: ProsemirrorNode,\n from: number,\n to: number,\n): Array<[number, number]> {\n const $from = doc.resolve(from)\n const $to = doc.resolve(to)\n\n if ($from.sameParent($to) && $from.parent.isTextblock) {\n return [getInlineTextRange($from, $to)]\n } else {\n const nodeRange = $from.blockRange($to)\n if (!nodeRange) {\n return []\n }\n\n return getSpanTextRanges($from, $to)\n }\n}\n\nfunction getMapRange(\n transactions: readonly Transaction[],\n oldState: EditorState,\n newState: EditorState,\n) {\n let lo = oldState.selection.from\n let hi = oldState.selection.to\n\n for (const tr of transactions) {\n for (const map of tr.mapping.maps) {\n lo = map.map(lo)\n hi = map.map(hi)\n\n map.forEach((_oldStart, _oldEnd, newStart, newEnd) => {\n lo = Math.min(lo, hi, newStart)\n hi = Math.max(lo, hi, newEnd)\n })\n }\n }\n\n lo = Math.min(lo, hi, newState.selection.from)\n hi = Math.min(lo, hi, newState.selection.to)\n\n return [lo, hi] as const\n}\n\nexport function getCheckRanges(\n transactions: readonly Transaction[],\n oldState: EditorState,\n newState: EditorState,\n): Array<[number, number]> {\n const [from, to] = getMapRange(transactions, oldState, newState)\n return getTextRanges(newState.doc, from, to)\n}\n","import { getMarkType, maybeRun, OBJECT_REPLACEMENT_CHARACTER } from '@prosekit/core'\nimport type { Mark, ProseMirrorNode } from '@prosekit/pm/model'\nimport type { EditorState, Transaction } from '@prosekit/pm/state'\n\nimport { getCheckRanges } from './range.ts'\nimport type { MarkRuleOptions } from './types.ts'\n\ntype MarkRange = [from: number, to: number, mark: Mark]\n\nfunction getExpectedMarkings(\n rules: MarkRuleOptions[],\n doc: ProseMirrorNode,\n from: number,\n to: number,\n): MarkRange[] {\n const text = doc.textBetween(from, to, null, OBJECT_REPLACEMENT_CHARACTER)\n const ranges: MarkRange[] = []\n\n for (const rule of rules) {\n rule.regex.lastIndex = 0\n const matches = text.matchAll(rule.regex)\n const markType = getMarkType(doc.type.schema, rule.type)\n\n for (const match of matches) {\n const index = match.index\n if (index == null) continue\n const attrs = maybeRun(rule.attrs, match)\n const mark = markType.create(attrs)\n ranges.push([from + index, from + index + match[0].length, mark])\n }\n }\n\n // Sort by start position. If start positions are equal, the longer match\n // should be prioritized.\n ranges.sort((a, b) => a[0] - b[0] || b[1] - a[1])\n\n // Remove overlapped marks.\n const result: MarkRange[] = []\n let freeIndex = 0\n\n for (const range of ranges) {\n if (range[0] >= freeIndex) {\n result.push(range)\n freeIndex = range[1]\n }\n }\n\n return result\n}\n\nfunction getReceivedMarkings(\n rules: MarkRuleOptions[],\n doc: ProseMirrorNode,\n from: number,\n to: number,\n): MarkRange[] {\n const result: MarkRange[] = []\n const schema = doc.type.schema\n const markTypes = rules.map((rule) => getMarkType(schema, rule.type))\n\n doc.nodesBetween(from, to, (node, pos) => {\n if (!node.isInline) {\n return\n }\n\n for (const markType of markTypes) {\n const mark = node.marks.find((mark) => mark.type === markType)\n if (mark) {\n result.push([pos, pos + node.nodeSize, mark])\n }\n }\n })\n return result\n}\n\nfunction markRangeEquals(a: MarkRange, b: MarkRange): boolean {\n return a[0] === b[0] && a[1] === b[1] && a[2].eq(b[2])\n}\n\nfunction markRangeDiffs(a: MarkRange[], b: MarkRange[]): MarkRange[] {\n return a.filter((x) => !b.some((y) => markRangeEquals(x, y)))\n}\n\nexport function applyMarkRules(\n rules: MarkRuleOptions[],\n transactions: readonly Transaction[],\n oldState: EditorState,\n newState: EditorState,\n): Transaction | null {\n if (transactions.length === 0 || transactions.every((tr) => !tr.docChanged)) {\n return null\n }\n\n const ranges = getCheckRanges(transactions, oldState, newState)\n\n const toRemove: MarkRange[] = []\n const toCreate: MarkRange[] = []\n\n for (const [from, to] of ranges) {\n const expected = getExpectedMarkings(rules, newState.doc, from, to)\n const received = getReceivedMarkings(rules, newState.doc, from, to)\n\n toRemove.push(...markRangeDiffs(received, expected))\n toCreate.push(...markRangeDiffs(expected, received))\n }\n\n if (toCreate.length === 0 && toRemove.length === 0) {\n return null\n }\n\n const tr = newState.tr\n for (const [from, to, mark] of toRemove) {\n tr.removeMark(from, to, mark)\n }\n for (const [from, to, mark] of toCreate) {\n tr.addMark(from, to, mark)\n }\n return tr\n}\n","import { defineFacet, defineFacetPayload, pluginFacet, type PlainExtension, type PluginPayload } from '@prosekit/core'\nimport { PluginKey, ProseMirrorPlugin, type EditorState, type Transaction } from '@prosekit/pm/state'\n\nimport { applyMarkRules } from './apply.ts'\nimport type { MarkRuleOptions } from './types.ts'\n\n/**\n * A mark rule is something that can automatically apply marks to text if it\n * matches a certain pattern, and remove them if it doesn't match anymore.\n */\nexport function defineMarkRule(options: MarkRuleOptions): PlainExtension {\n return defineFacetPayload(markRuleFacet, [options]) as PlainExtension\n}\n\nconst markRuleFacet = defineFacet<MarkRuleOptions, PluginPayload>({\n reduce: () => {\n let rules: MarkRuleOptions[] = []\n\n const plugin = new ProseMirrorPlugin({\n key: new PluginKey('prosekit-mark-rule'),\n appendTransaction: (\n transactions: readonly Transaction[],\n oldState: EditorState,\n newState: EditorState,\n ) => {\n return applyMarkRules(rules, transactions, oldState, newState)\n },\n })\n\n return function reducer(input) {\n rules = input\n return plugin\n }\n },\n\n parent: pluginFacet,\n})\n"],"mappings":";;AAIA,SAAS,kBAAkB,OAAoB,KAAkB;CAC/D,MAAM,YAAY,MAAM,WAAW,IAAI;AACvC,KAAI,CAAC,UACH,QAAO,EAAE;CAGX,MAAM,QAAuD,EAAE;CAC/D,IAAI,QAAQ,UAAU;AAEtB,MAAK,IAAI,IAAI,UAAU,YAAY,IAAI,UAAU,UAAU,KAAK;EAC9D,MAAM,QAAQ,UAAU,OAAO,MAAM,EAAE;AACvC,QAAM,KAAK,CAAC,OAAO,MAAM,CAAC;AAC1B,WAAS,MAAM;;CAGjB,MAAM,SAAkC,EAAE;AAE1C,QAAO,MAAM,SAAS,GAAG;EACvB,MAAM,CAAC,OAAO,QAAQ,MAAM,KAAK;AACjC,MAAI,KAAK,KAAK,KAAK,KACjB;AAGF,MAAI,KAAK,KAAK,aAAa;AACzB,UAAO,KAAK,CAAC,QAAQ,GAAG,QAAQ,IAAI,KAAK,QAAQ,KAAK,CAAC;AACvD;;AAGF,OAAK,SAAS,OAAO,WAAW;AAC9B,SAAM,KAAK,CAAC,QAAQ,SAAS,GAAG,MAAM,CAAC;IACvC;;AAGJ,QAAO;;AAGT,SAAS,mBACP,OACA,KACkB;AAClB,QAAO,CAAC,MAAM,OAAO,EAAE,IAAI,KAAK,CAAC;;AAGnC,SAAS,cACP,KACA,MACA,IACyB;CACzB,MAAM,QAAQ,IAAI,QAAQ,KAAK;CAC/B,MAAM,MAAM,IAAI,QAAQ,GAAG;AAE3B,KAAI,MAAM,WAAW,IAAI,IAAI,MAAM,OAAO,YACxC,QAAO,CAAC,mBAAmB,OAAO,IAAI,CAAC;MAClC;AAEL,MAAI,CADc,MAAM,WAAW,IACrB,CACZ,QAAO,EAAE;AAGX,SAAO,kBAAkB,OAAO,IAAI;;;AAIxC,SAAS,YACP,cACA,UACA,UACA;CACA,IAAI,KAAK,SAAS,UAAU;CAC5B,IAAI,KAAK,SAAS,UAAU;AAE5B,MAAK,MAAM,MAAM,aACf,MAAK,MAAM,OAAO,GAAG,QAAQ,MAAM;AACjC,OAAK,IAAI,IAAI,GAAG;AAChB,OAAK,IAAI,IAAI,GAAG;AAEhB,MAAI,SAAS,WAAW,SAAS,UAAU,WAAW;AACpD,QAAK,KAAK,IAAI,IAAI,IAAI,SAAS;AAC/B,QAAK,KAAK,IAAI,IAAI,IAAI,OAAO;IAC7B;;AAIN,MAAK,KAAK,IAAI,IAAI,IAAI,SAAS,UAAU,KAAK;AAC9C,MAAK,KAAK,IAAI,IAAI,IAAI,SAAS,UAAU,GAAG;AAE5C,QAAO,CAAC,IAAI,GAAG;;AAGjB,SAAgB,eACd,cACA,UACA,UACyB;CACzB,MAAM,CAAC,MAAM,MAAM,YAAY,cAAc,UAAU,SAAS;AAChE,QAAO,cAAc,SAAS,KAAK,MAAM,GAAG;;AC1F9C,SAAS,oBACP,OACA,KACA,MACA,IACa;CACb,MAAM,OAAO,IAAI,YAAY,MAAM,IAAI,MAAM,6BAA6B;CAC1E,MAAM,SAAsB,EAAE;AAE9B,MAAK,MAAM,QAAQ,OAAO;AACxB,OAAK,MAAM,YAAY;EACvB,MAAM,UAAU,KAAK,SAAS,KAAK,MAAM;EACzC,MAAM,WAAW,YAAY,IAAI,KAAK,QAAQ,KAAK,KAAK;AAExD,OAAK,MAAM,SAAS,SAAS;GAC3B,MAAM,QAAQ,MAAM;AACpB,OAAI,SAAS,KAAM;GACnB,MAAM,QAAQ,SAAS,KAAK,OAAO,MAAM;GACzC,MAAM,OAAO,SAAS,OAAO,MAAM;AACnC,UAAO,KAAK;IAAC,OAAO;IAAO,OAAO,QAAQ,MAAM,GAAG;IAAQ;IAAK,CAAC;;;AAMrE,QAAO,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG;CAGjD,MAAM,SAAsB,EAAE;CAC9B,IAAI,YAAY;AAEhB,MAAK,MAAM,SAAS,OAClB,KAAI,MAAM,MAAM,WAAW;AACzB,SAAO,KAAK,MAAM;AAClB,cAAY,MAAM;;AAItB,QAAO;;AAGT,SAAS,oBACP,OACA,KACA,MACA,IACa;CACb,MAAM,SAAsB,EAAE;CAC9B,MAAM,SAAS,IAAI,KAAK;CACxB,MAAM,YAAY,MAAM,KAAK,SAAS,YAAY,QAAQ,KAAK,KAAK,CAAC;AAErE,KAAI,aAAa,MAAM,KAAK,MAAM,QAAQ;AACxC,MAAI,CAAC,KAAK,SACR;AAGF,OAAK,MAAM,YAAY,WAAW;GAChC,MAAM,OAAO,KAAK,MAAM,MAAM,SAAS,KAAK,SAAS,SAAS;AAC9D,OAAI,KACF,QAAO,KAAK;IAAC;IAAK,MAAM,KAAK;IAAU;IAAK,CAAC;;GAGjD;AACF,QAAO;;AAGT,SAAS,gBAAgB,GAAc,GAAuB;AAC5D,QAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,GAAG,EAAE,GAAG;;AAGxD,SAAS,eAAe,GAAgB,GAA6B;AACnE,QAAO,EAAE,QAAQ,MAAM,CAAC,EAAE,MAAM,MAAM,gBAAgB,GAAG,EAAE,CAAC,CAAC;;AAG/D,SAAgB,eACd,OACA,cACA,UACA,UACoB;AACpB,KAAI,aAAa,WAAW,KAAK,aAAa,OAAO,OAAO,CAAC,GAAG,WAAW,CACzE,QAAO;CAGT,MAAM,SAAS,eAAe,cAAc,UAAU,SAAS;CAE/D,MAAM,WAAwB,EAAE;CAChC,MAAM,WAAwB,EAAE;AAEhC,MAAK,MAAM,CAAC,MAAM,OAAO,QAAQ;EAC/B,MAAM,WAAW,oBAAoB,OAAO,SAAS,KAAK,MAAM,GAAG;EACnE,MAAM,WAAW,oBAAoB,OAAO,SAAS,KAAK,MAAM,GAAG;AAEnE,WAAS,KAAK,GAAG,eAAe,UAAU,SAAS,CAAC;AACpD,WAAS,KAAK,GAAG,eAAe,UAAU,SAAS,CAAC;;AAGtD,KAAI,SAAS,WAAW,KAAK,SAAS,WAAW,EAC/C,QAAO;CAGT,MAAM,KAAK,SAAS;AACpB,MAAK,MAAM,CAAC,MAAM,IAAI,SAAS,SAC7B,IAAG,WAAW,MAAM,IAAI,KAAK;AAE/B,MAAK,MAAM,CAAC,MAAM,IAAI,SAAS,SAC7B,IAAG,QAAQ,MAAM,IAAI,KAAK;AAE5B,QAAO;;;;;;AC3GT,SAAgB,eAAe,SAA0C;AACvE,QAAO,mBAAmB,eAAe,CAAC,QAAQ,CAAC;;AAGrD,MAAM,gBAAgB,YAA4C;CAChE,cAAc;EACZ,IAAI,QAA2B,EAAE;EAEjC,MAAM,SAAS,IAAI,kBAAkB;GACnC,KAAK,IAAI,UAAU,qBAAqB;GACxC,oBACE,cACA,UACA,aACG;AACH,WAAO,eAAe,OAAO,cAAc,UAAU,SAAS;;GAEjE,CAAC;AAEF,SAAO,SAAS,QAAQ,OAAO;AAC7B,WAAQ;AACR,UAAO;;;CAIX,QAAQ;CACT,CAAC"}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { Extension, PlainExtension, Union } from "@prosekit/core";
|
|
2
2
|
import { Attrs } from "@prosekit/pm/model";
|
|
3
3
|
import { RenderMathBlock, RenderMathInline } from "prosemirror-math";
|
|
4
|
-
|
|
5
|
-
//#region src/math/math-block.d.ts
|
|
6
4
|
/**
|
|
7
5
|
* @internal
|
|
8
6
|
*/
|
|
@@ -61,8 +59,6 @@ type MathBlockExtension = Union<[MathBlockSpecExtension]>;
|
|
|
61
59
|
* @public
|
|
62
60
|
*/
|
|
63
61
|
declare function defineMathBlock(options: MathBlockOptions): MathBlockExtension;
|
|
64
|
-
//#endregion
|
|
65
|
-
//#region src/math/math-inline.d.ts
|
|
66
62
|
/**
|
|
67
63
|
* @internal
|
|
68
64
|
*/
|
|
@@ -121,11 +117,7 @@ type MathInlineExtension = Union<[MathInlineSpecExtension]>;
|
|
|
121
117
|
* @public
|
|
122
118
|
*/
|
|
123
119
|
declare function defineMathInline(options: MathInlineOptions): MathInlineExtension;
|
|
124
|
-
//#endregion
|
|
125
|
-
//#region src/math/math-plugin.d.ts
|
|
126
120
|
declare function defineMathPlugin(): PlainExtension;
|
|
127
|
-
//#endregion
|
|
128
|
-
//#region src/math/math.d.ts
|
|
129
121
|
/**
|
|
130
122
|
* @public
|
|
131
123
|
*/
|
|
@@ -149,6 +141,5 @@ interface MathOptions {
|
|
|
149
141
|
* @public
|
|
150
142
|
*/
|
|
151
143
|
declare function defineMath(options: MathOptions): MathExtension;
|
|
152
|
-
//#endregion
|
|
153
144
|
export { type MathBlockExtension, type MathBlockOptions, type MathBlockSpecExtension, type MathBlockViewOptions, type MathExtension, type MathInlineExtension, type MathInlineOptions, type MathInlineSpecExtension, type MathInlineViewOptions, type MathOptions, defineMath, defineMathBlock, defineMathBlockEnterRule, defineMathBlockSpec, defineMathBlockView, defineMathInline, defineMathInlineInputRule, defineMathInlineSpec, defineMathInlineView, defineMathPlugin };
|
|
154
|
-
//# sourceMappingURL=
|
|
145
|
+
//# sourceMappingURL=math.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math.d.ts","names":[],"sources":["../src/math/math-block.ts","../src/math/math-inline.ts","../src/math/math-plugin.ts","../src/math/math.ts"],"mappings":";;;;AASA;;KAAY,sBAAA,GAAyB,SAAA;EACnC,KAAA;IACE,SAAA,EAAW,KAAA;EAAA;AAAA;;;;iBAOC,mBAAA,CAAA,GAAuB,sBAAA;;;;;AAmBvC;UAAiB,oBAAA;;;;EAIf,MAAA,EAAQ,eAAA;AAAA;;;;;;;iBASM,mBAAA,CAAA;EAAsB;AAAA,GAAU,oBAAA,GAAuB,SAAA;;;;iBAYvD,wBAAA,CAAA,GAA4B,cAAA;;AAA5C;;;;UASiB,gBAAA;EAAA;;;EAIf,MAAA,EAAQ,eAAA;AAAA;AAMV;;;AAAA,KAAY,kBAAA,GAAqB,KAAA,EAAO,sBAAA;;AAQxC;;;;;iBAAgB,eAAA,CAAgB,OAAA,EAAS,gBAAA,GAAmB,kBAAA;;AAhF5D;;KCAY,uBAAA,GAA0B,SAAA;EACpC,KAAA;IACE,UAAA,EAAY,KAAA;EAAA;AAAA;;;;iBAOA,oBAAA,CAAA,GAAwB,uBAAA;;;;;ADmBxC;UCPiB,qBAAA;;;;EAIf,MAAA,EAAQ,gBAAA;AAAA;;;;;;;iBASM,oBAAA,CAAA;EAAuB;AAAA,GAAU,qBAAA,GAAwB,SAAA;;;;iBAYzD,yBAAA,CAAA,GAA6B,cAAA;;ADO7C;;;;UCEiB,iBAAA;EDOA;;;ECHf,MAAA,EAAQ,gBAAA;AAAA;ADaV;;;AAAA,KCPY,mBAAA,GAAsB,KAAA,EAAO,uBAAA;;ADezC;;;;;iBCPgB,gBAAA,CAAiB,OAAA,EAAS,iBAAA,GAAoB,mBAAA;AAAA,iBC/E9C,gBAAA,CAAA,GAAoB,cAAA;AFMpC;;;AAAA,KGCY,aAAA,GAAgB,KAAA,EAAO,mBAAA,EAAqB,kBAAA;;;;;;UAOvC,WAAA;EHCD;;;EGGd,eAAA,EAAiB,eAAA;EHH0C;AAmB7D;;EGXE,gBAAA,EAAkB,gBAAA;AAAA;;AHwBpB;;iBGlBgB,UAAA,CAAW,OAAA,EAAS,WAAA,GAAc,aAAA"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { defineInputRule } from "./
|
|
2
|
-
import { defineEnterRule } from "./
|
|
1
|
+
import { defineInputRule } from "./input-rule.js";
|
|
2
|
+
import { defineEnterRule } from "./enter-rule.js";
|
|
3
3
|
import { defineNodeSpec, defineNodeView, definePlugin, union } from "@prosekit/core";
|
|
4
4
|
import { createCursorInsidePlugin, createMathBlockView, createMathInlineInputRule, createMathInlineView, mathBlockEnterRule, mathBlockSpec, mathInlineSpec } from "prosemirror-math";
|
|
5
|
-
//#region src/math/math-block.ts
|
|
6
5
|
/**
|
|
7
6
|
* @internal
|
|
8
7
|
*/
|
|
@@ -45,8 +44,6 @@ function defineMathBlockEnterRule() {
|
|
|
45
44
|
function defineMathBlock(options) {
|
|
46
45
|
return union(defineMathBlockSpec(), defineMathBlockView(options), defineMathBlockEnterRule());
|
|
47
46
|
}
|
|
48
|
-
//#endregion
|
|
49
|
-
//#region src/math/math-inline.ts
|
|
50
47
|
/**
|
|
51
48
|
* @internal
|
|
52
49
|
*/
|
|
@@ -85,20 +82,15 @@ function defineMathInlineInputRule() {
|
|
|
85
82
|
function defineMathInline(options) {
|
|
86
83
|
return union(defineMathInlineSpec(), defineMathInlineView(options), defineMathInlineInputRule());
|
|
87
84
|
}
|
|
88
|
-
//#endregion
|
|
89
|
-
//#region src/math/math-plugin.ts
|
|
90
85
|
function defineMathPlugin() {
|
|
91
86
|
return definePlugin(createCursorInsidePlugin());
|
|
92
87
|
}
|
|
93
|
-
//#endregion
|
|
94
|
-
//#region src/math/math.ts
|
|
95
88
|
/**
|
|
96
89
|
* @public
|
|
97
90
|
*/
|
|
98
91
|
function defineMath(options) {
|
|
99
92
|
return union(defineMathBlock({ render: options.renderMathBlock }), defineMathInline({ render: options.renderMathInline }), defineMathPlugin());
|
|
100
93
|
}
|
|
101
|
-
//#endregion
|
|
102
94
|
export { defineMath, defineMathBlock, defineMathBlockEnterRule, defineMathBlockSpec, defineMathBlockView, defineMathInline, defineMathInlineInputRule, defineMathInlineSpec, defineMathInlineView, defineMathPlugin };
|
|
103
95
|
|
|
104
|
-
//# sourceMappingURL=
|
|
96
|
+
//# sourceMappingURL=math.js.map
|
package/dist/math.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math.js","names":[],"sources":["../src/math/math-block.ts","../src/math/math-inline.ts","../src/math/math-plugin.ts","../src/math/math.ts"],"sourcesContent":["import { defineNodeSpec, defineNodeView, union, type Extension, type PlainExtension, type Union } from '@prosekit/core'\nimport type { Attrs } from '@prosekit/pm/model'\nimport { createMathBlockView, mathBlockEnterRule, mathBlockSpec, type RenderMathBlock } from 'prosemirror-math'\n\nimport { defineEnterRule } from '../enter-rule/index.ts'\n\n/**\n * @internal\n */\nexport type MathBlockSpecExtension = Extension<{\n Nodes: {\n mathBlock: Attrs\n }\n}>\n\n/**\n * @internal\n */\nexport function defineMathBlockSpec(): MathBlockSpecExtension {\n return defineNodeSpec<'mathBlock', Attrs>({\n ...mathBlockSpec,\n attrs: {\n // The language in the `mathBlock` node, useful for syntax highlighting.\n // This library doesn't focus on using the TeX language in a `mathBlock` node,\n // but this is the most common language used for math blocks in rich text\n // editors, so 'tex' is set as the default value.\n language: { default: 'tex', validate: 'string' },\n },\n name: 'mathBlock',\n })\n}\n\n/**\n * Options for {@link defineMathBlockView}.\n *\n * @internal\n */\nexport interface MathBlockViewOptions {\n /**\n * The function to render the math block.\n */\n render: RenderMathBlock\n}\n\n/**\n * Defines an extension that renders a math block using a custom node view.\n *\n * @param options\n * @internal\n */\nexport function defineMathBlockView({ render }: MathBlockViewOptions): Extension {\n return defineNodeView({\n name: 'mathBlock',\n constructor: (node, view, getPos, decorations) => {\n return createMathBlockView(render, node, decorations)\n },\n })\n}\n\n/**\n * @internal\n */\nexport function defineMathBlockEnterRule(): PlainExtension {\n return defineEnterRule(mathBlockEnterRule)\n}\n\n/**\n * Options for {@link defineMathBlock}.\n *\n * @internal\n */\nexport interface MathBlockOptions {\n /**\n * The function to render the math block.\n */\n render: RenderMathBlock\n}\n\n/**\n * @internal\n */\nexport type MathBlockExtension = Union<[MathBlockSpecExtension]>\n\n/**\n * Defines node `mathBlock` and related functionalities.\n *\n * @param options\n * @public\n */\nexport function defineMathBlock(options: MathBlockOptions): MathBlockExtension {\n return union(\n defineMathBlockSpec(),\n defineMathBlockView(options),\n defineMathBlockEnterRule(),\n )\n}\n","import { defineNodeSpec, defineNodeView, union, type Extension, type PlainExtension, type Union } from '@prosekit/core'\nimport type { Attrs } from '@prosekit/pm/model'\nimport { createMathInlineInputRule, createMathInlineView, mathInlineSpec, type RenderMathInline } from 'prosemirror-math'\n\nimport { defineInputRule } from '../input-rule/index.ts'\n\n/**\n * @internal\n */\nexport type MathInlineSpecExtension = Extension<{\n Nodes: {\n mathInline: Attrs\n }\n}>\n\n/**\n * @internal\n */\nexport function defineMathInlineSpec(): MathInlineSpecExtension {\n return defineNodeSpec<'mathInline', Attrs>({\n ...mathInlineSpec,\n name: 'mathInline',\n })\n}\n\n/**\n * Options for {@link defineMathInlineView}.\n *\n * @internal\n */\nexport interface MathInlineViewOptions {\n /**\n * The function to render the math inline.\n */\n render: RenderMathInline\n}\n\n/**\n * Defines an extension that renders a math inline using a custom node view.\n *\n * @param options\n * @internal\n */\nexport function defineMathInlineView({ render }: MathInlineViewOptions): Extension {\n return defineNodeView({\n name: 'mathInline',\n constructor: (node, view, getPos, decorations) => {\n return createMathInlineView(render, node, decorations)\n },\n })\n}\n\n/**\n * @internal\n */\nexport function defineMathInlineInputRule(): PlainExtension {\n return defineInputRule(createMathInlineInputRule('mathInline'))\n}\n\n/**\n * Options for {@link defineMathInline}.\n *\n * @internal\n */\nexport interface MathInlineOptions {\n /**\n * The function to render the math inline.\n */\n render: RenderMathInline\n}\n\n/**\n * @internal\n */\nexport type MathInlineExtension = Union<[MathInlineSpecExtension]>\n\n/**\n * Defines node `mathInline` and related functionalities.\n *\n * @param options\n * @public\n */\nexport function defineMathInline(options: MathInlineOptions): MathInlineExtension {\n return union(\n defineMathInlineSpec(),\n defineMathInlineView(options),\n defineMathInlineInputRule(),\n )\n}\n","import { definePlugin, type PlainExtension } from '@prosekit/core'\nimport { createCursorInsidePlugin } from 'prosemirror-math'\n\nexport function defineMathPlugin(): PlainExtension {\n return definePlugin(\n createCursorInsidePlugin(),\n )\n}\n","import { union, type Union } from '@prosekit/core'\nimport type { RenderMathBlock, RenderMathInline } from 'prosemirror-math'\n\nimport { defineMathBlock, type MathBlockExtension } from './math-block.ts'\nimport { defineMathInline, type MathInlineExtension } from './math-inline.ts'\nimport { defineMathPlugin } from './math-plugin.ts'\n\n/**\n * @public\n */\nexport type MathExtension = Union<[MathInlineExtension, MathBlockExtension]>\n\n/**\n * Options for {@link defineMath}.\n *\n * @public\n */\nexport interface MathOptions {\n /**\n * The function to render the math block.\n */\n renderMathBlock: RenderMathBlock\n\n /**\n * The function to render the math inline.\n */\n renderMathInline: RenderMathInline\n}\n\n/**\n * @public\n */\nexport function defineMath(options: MathOptions): MathExtension {\n return union(\n defineMathBlock({ render: options.renderMathBlock }),\n defineMathInline({ render: options.renderMathInline }),\n defineMathPlugin(),\n )\n}\n"],"mappings":";;;;;;;AAkBA,SAAgB,sBAA8C;AAC5D,QAAO,eAAmC;EACxC,GAAG;EACH,OAAO,EAKL,UAAU;GAAE,SAAS;GAAO,UAAU;GAAU,EACjD;EACD,MAAM;EACP,CAAC;;;;;;;;AAqBJ,SAAgB,oBAAoB,EAAE,UAA2C;AAC/E,QAAO,eAAe;EACpB,MAAM;EACN,cAAc,MAAM,MAAM,QAAQ,gBAAgB;AAChD,UAAO,oBAAoB,QAAQ,MAAM,YAAY;;EAExD,CAAC;;;;;AAMJ,SAAgB,2BAA2C;AACzD,QAAO,gBAAgB,mBAAmB;;;;;;;;AA0B5C,SAAgB,gBAAgB,SAA+C;AAC7E,QAAO,MACL,qBAAqB,EACrB,oBAAoB,QAAQ,EAC5B,0BAA0B,CAC3B;;;;;AC5EH,SAAgB,uBAAgD;AAC9D,QAAO,eAAoC;EACzC,GAAG;EACH,MAAM;EACP,CAAC;;;;;;;;AAqBJ,SAAgB,qBAAqB,EAAE,UAA4C;AACjF,QAAO,eAAe;EACpB,MAAM;EACN,cAAc,MAAM,MAAM,QAAQ,gBAAgB;AAChD,UAAO,qBAAqB,QAAQ,MAAM,YAAY;;EAEzD,CAAC;;;;;AAMJ,SAAgB,4BAA4C;AAC1D,QAAO,gBAAgB,0BAA0B,aAAa,CAAC;;;;;;;;AA0BjE,SAAgB,iBAAiB,SAAiD;AAChF,QAAO,MACL,sBAAsB,EACtB,qBAAqB,QAAQ,EAC7B,2BAA2B,CAC5B;;ACpFH,SAAgB,mBAAmC;AACjD,QAAO,aACL,0BAA0B,CAC3B;;;;;AC0BH,SAAgB,WAAW,SAAqC;AAC9D,QAAO,MACL,gBAAgB,EAAE,QAAQ,QAAQ,iBAAiB,CAAC,EACpD,iBAAiB,EAAE,QAAQ,QAAQ,kBAAkB,CAAC,EACtD,kBAAkB,CACnB"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { Extension, Union } from "@prosekit/core";
|
|
2
|
-
|
|
3
|
-
//#region src/mention/index.d.ts
|
|
4
2
|
interface MentionAttrs {
|
|
5
3
|
id: string;
|
|
6
4
|
value: string;
|
|
@@ -35,6 +33,5 @@ type MentionExtension = Union<[MentionSpecExtension, MentionCommandsExtension]>;
|
|
|
35
33
|
* @public
|
|
36
34
|
*/
|
|
37
35
|
declare function defineMention(): MentionExtension;
|
|
38
|
-
//#endregion
|
|
39
36
|
export { MentionAttrs, MentionCommandsExtension, MentionExtension, MentionSpecExtension, defineMention, defineMentionCommands, defineMentionSpec };
|
|
40
|
-
//# sourceMappingURL=
|
|
37
|
+
//# sourceMappingURL=mention.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mention.d.ts","names":[],"sources":["../src/mention/index.ts"],"mappings":";UAEiB,YAAA;EACf,EAAA;EACA,KAAA;EACA,IAAA;AAAA;;;;KAMU,oBAAA,GAAuB,SAAA;EACjC,KAAA;IACE,OAAA,EAAS,YAAA;EAAA;AAAA;;;;iBAOG,iBAAA,CAAA,GAAqB,oBAAA;;;;KAsCzB,wBAAA,GAA2B,SAAA;EACrC,QAAA;IACE,aAAA,GAAgB,KAAA,EAAO,YAAA;EAAA;AAAA;AAAA,iBAIX,qBAAA,CAAA,GAAyB,wBAAA;;;;KAW7B,gBAAA,GAAmB,KAAA,EAAO,oBAAA,EAAsB,wBAAA;;;;iBAK5C,aAAA,CAAA,GAAiB,gBAAA"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { defineCommands, defineNodeSpec, insertNode, union } from "@prosekit/core";
|
|
2
|
-
//#region src/mention/index.ts
|
|
3
2
|
/**
|
|
4
3
|
* @public
|
|
5
4
|
*/
|
|
@@ -52,7 +51,6 @@ function defineMentionCommands() {
|
|
|
52
51
|
function defineMention() {
|
|
53
52
|
return union(defineMentionSpec(), defineMentionCommands());
|
|
54
53
|
}
|
|
55
|
-
//#endregion
|
|
56
54
|
export { defineMention, defineMentionCommands, defineMentionSpec };
|
|
57
55
|
|
|
58
|
-
//# sourceMappingURL=
|
|
56
|
+
//# sourceMappingURL=mention.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mention.js","names":[],"sources":["../src/mention/index.ts"],"sourcesContent":["import { defineCommands, defineNodeSpec, insertNode, union, type Extension, type Union } from '@prosekit/core'\n\nexport interface MentionAttrs {\n id: string\n value: string\n kind: string\n}\n\n/**\n * @internal\n */\nexport type MentionSpecExtension = Extension<{\n Nodes: {\n mention: MentionAttrs\n }\n}>\n\n/**\n * @public\n */\nexport function defineMentionSpec(): MentionSpecExtension {\n return defineNodeSpec<'mention', MentionAttrs>({\n name: 'mention',\n atom: true,\n group: 'inline',\n attrs: {\n id: { validate: 'string' },\n value: { validate: 'string' },\n kind: { default: '', validate: 'string' },\n },\n inline: true,\n leafText: (node) => (node.attrs as MentionAttrs).value.toString(),\n parseDOM: [\n {\n tag: `span[data-mention]`,\n getAttrs: (dom: HTMLElement): MentionAttrs => ({\n id: dom.getAttribute('data-id') || '',\n kind: dom.getAttribute('data-mention') || '',\n value: dom.textContent || '',\n }),\n },\n ],\n toDOM(node) {\n return [\n 'span',\n {\n 'data-id': (node.attrs as MentionAttrs).id.toString(),\n 'data-mention': (node.attrs as MentionAttrs).kind.toString(),\n },\n (node.attrs as MentionAttrs).value.toString(),\n ]\n },\n })\n}\n\n/**\n * @internal\n */\nexport type MentionCommandsExtension = Extension<{\n Commands: {\n insertMention: [attrs: MentionAttrs]\n }\n}>\n\nexport function defineMentionCommands(): MentionCommandsExtension {\n return defineCommands({\n insertMention: (attrs: MentionAttrs) => {\n return insertNode({ type: 'mention', attrs })\n },\n })\n}\n\n/**\n * @internal\n */\nexport type MentionExtension = Union<[MentionSpecExtension, MentionCommandsExtension]>\n\n/**\n * @public\n */\nexport function defineMention(): MentionExtension {\n return union(defineMentionSpec(), defineMentionCommands())\n}\n"],"mappings":";;;;AAoBA,SAAgB,oBAA0C;AACxD,QAAO,eAAwC;EAC7C,MAAM;EACN,MAAM;EACN,OAAO;EACP,OAAO;GACL,IAAI,EAAE,UAAU,UAAU;GAC1B,OAAO,EAAE,UAAU,UAAU;GAC7B,MAAM;IAAE,SAAS;IAAI,UAAU;IAAU;GAC1C;EACD,QAAQ;EACR,WAAW,SAAU,KAAK,MAAuB,MAAM,UAAU;EACjE,UAAU,CACR;GACE,KAAK;GACL,WAAW,SAAoC;IAC7C,IAAI,IAAI,aAAa,UAAU,IAAI;IACnC,MAAM,IAAI,aAAa,eAAe,IAAI;IAC1C,OAAO,IAAI,eAAe;IAC3B;GACF,CACF;EACD,MAAM,MAAM;AACV,UAAO;IACL;IACA;KACE,WAAY,KAAK,MAAuB,GAAG,UAAU;KACrD,gBAAiB,KAAK,MAAuB,KAAK,UAAU;KAC7D;IACA,KAAK,MAAuB,MAAM,UAAU;IAC9C;;EAEJ,CAAC;;AAYJ,SAAgB,wBAAkD;AAChE,QAAO,eAAe,EACpB,gBAAgB,UAAwB;AACtC,SAAO,WAAW;GAAE,MAAM;GAAW;GAAO,CAAC;IAEhD,CAAC;;;;;AAWJ,SAAgB,gBAAkC;AAChD,QAAO,MAAM,mBAAmB,EAAE,uBAAuB,CAAC"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { PlainExtension } from "@prosekit/core";
|
|
2
|
-
|
|
3
|
-
//#region src/mod-click-prevention/index.d.ts
|
|
4
2
|
/**
|
|
5
3
|
* @internal
|
|
6
4
|
*/
|
|
@@ -12,6 +10,5 @@ type ModClickPreventionExtension = PlainExtension;
|
|
|
12
10
|
* @public
|
|
13
11
|
*/
|
|
14
12
|
declare function defineModClickPrevention(): ModClickPreventionExtension;
|
|
15
|
-
//#endregion
|
|
16
13
|
export { ModClickPreventionExtension, defineModClickPrevention };
|
|
17
|
-
//# sourceMappingURL=
|
|
14
|
+
//# sourceMappingURL=mod-click-prevention.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod-click-prevention.d.ts","names":[],"sources":["../src/mod-click-prevention/index.ts"],"mappings":";;AAOA;;KAAY,2BAAA,GAA8B,cAAA;;;AAQ1C;;;;iBAAgB,wBAAA,CAAA,GAA4B,2BAAA"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Plugin, PluginKey } from "@prosekit/pm/state";
|
|
2
2
|
import { definePlugin, isApple } from "@prosekit/core";
|
|
3
|
-
//#region src/mod-click-prevention/index.ts
|
|
4
3
|
/**
|
|
5
4
|
* By default, clicking a node while holding the mod key will select the node. This
|
|
6
5
|
* extension disables that behavior.
|
|
@@ -18,7 +17,6 @@ function handleClick(_view, _pos, event) {
|
|
|
18
17
|
return !!event[selectNodeModifier];
|
|
19
18
|
}
|
|
20
19
|
const selectNodeModifier = isApple ? "metaKey" : "ctrlKey";
|
|
21
|
-
//#endregion
|
|
22
20
|
export { defineModClickPrevention };
|
|
23
21
|
|
|
24
|
-
//# sourceMappingURL=
|
|
22
|
+
//# sourceMappingURL=mod-click-prevention.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod-click-prevention.js","names":[],"sources":["../src/mod-click-prevention/index.ts"],"sourcesContent":["import { definePlugin, isApple, type PlainExtension } from '@prosekit/core'\nimport { Plugin, PluginKey } from '@prosekit/pm/state'\nimport type { EditorView } from '@prosekit/pm/view'\n\n/**\n * @internal\n */\nexport type ModClickPreventionExtension = PlainExtension\n\n/**\n * By default, clicking a node while holding the mod key will select the node. This\n * extension disables that behavior.\n *\n * @public\n */\nexport function defineModClickPrevention(): ModClickPreventionExtension {\n return definePlugin(new Plugin({ key, props: { handleClick } }))\n}\n\nconst key = new PluginKey('prosekit-mod-click-prevention')\n\nfunction handleClick(_view: EditorView, _pos: number, event: MouseEvent) {\n return !!event[selectNodeModifier]\n}\n\nconst selectNodeModifier: 'metaKey' | 'ctrlKey' = isApple\n ? 'metaKey'\n : 'ctrlKey'\n"],"mappings":";;;;;;;;AAeA,SAAgB,2BAAwD;AACtE,QAAO,aAAa,IAAI,OAAO;EAAE;EAAK,OAAO,EAAE,aAAa;EAAE,CAAC,CAAC;;AAGlE,MAAM,MAAM,IAAI,UAAU,gCAAgC;AAE1D,SAAS,YAAY,OAAmB,MAAc,OAAmB;AACvE,QAAO,CAAC,CAAC,MAAM;;AAGjB,MAAM,qBAA4C,UAC9C,YACA"}
|