@kerebron/editor 0.4.27 → 0.4.28

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.
Files changed (110) hide show
  1. package/assets/base.css +114 -0
  2. package/assets/content.css +35 -0
  3. package/assets/gapcursor.css +25 -0
  4. package/assets/index.css +2 -0
  5. package/assets/main.css +8 -0
  6. package/assets/mobile.css +33 -0
  7. package/assets/prosemirror.css +20 -0
  8. package/assets/search.css +6 -0
  9. package/assets/vars.css +110 -0
  10. package/esm/CoreEditor.d.ts +40 -0
  11. package/esm/CoreEditor.d.ts.map +1 -0
  12. package/esm/CoreEditor.js +223 -0
  13. package/esm/DummyEditorView.d.ts +60 -0
  14. package/esm/DummyEditorView.d.ts.map +1 -0
  15. package/esm/DummyEditorView.js +242 -0
  16. package/esm/Extension.d.ts +31 -0
  17. package/esm/Extension.d.ts.map +1 -0
  18. package/esm/Extension.js +34 -0
  19. package/esm/ExtensionManager.d.ts +32 -0
  20. package/esm/ExtensionManager.d.ts.map +1 -0
  21. package/esm/ExtensionManager.js +222 -0
  22. package/esm/Mark.d.ts +23 -0
  23. package/esm/Mark.d.ts.map +1 -0
  24. package/esm/Mark.js +27 -0
  25. package/esm/Node.d.ts +32 -0
  26. package/esm/Node.d.ts.map +1 -0
  27. package/esm/Node.js +36 -0
  28. package/esm/commands/CommandManager.d.ts +24 -0
  29. package/esm/commands/CommandManager.d.ts.map +1 -0
  30. package/esm/commands/CommandManager.js +100 -0
  31. package/esm/commands/baseCommandFactories.d.ts +3 -0
  32. package/esm/commands/baseCommandFactories.d.ts.map +1 -0
  33. package/esm/commands/baseCommandFactories.js +861 -0
  34. package/esm/commands/createChainableState.d.ts +3 -0
  35. package/esm/commands/createChainableState.d.ts.map +1 -0
  36. package/esm/commands/createChainableState.js +29 -0
  37. package/esm/commands/keyCommandFactories.d.ts +3 -0
  38. package/esm/commands/keyCommandFactories.d.ts.map +1 -0
  39. package/esm/commands/keyCommandFactories.js +10 -0
  40. package/esm/commands/mod.d.ts +7 -0
  41. package/esm/commands/mod.d.ts.map +1 -0
  42. package/esm/commands/mod.js +81 -0
  43. package/esm/commands/replaceCommandFactories.d.ts +3 -0
  44. package/esm/commands/replaceCommandFactories.d.ts.map +1 -0
  45. package/esm/commands/replaceCommandFactories.js +94 -0
  46. package/esm/commands/types.d.ts +22 -0
  47. package/esm/commands/types.d.ts.map +1 -0
  48. package/esm/commands/types.js +1 -0
  49. package/esm/mod.d.ts +9 -0
  50. package/esm/mod.d.ts.map +1 -0
  51. package/esm/mod.js +8 -0
  52. package/esm/nodeToTreeString.d.ts +10 -0
  53. package/esm/nodeToTreeString.d.ts.map +1 -0
  54. package/esm/nodeToTreeString.js +74 -0
  55. package/esm/package.json +3 -0
  56. package/esm/plugins/TrackSelecionPlugin.d.ts +6 -0
  57. package/esm/plugins/TrackSelecionPlugin.d.ts.map +1 -0
  58. package/esm/plugins/TrackSelecionPlugin.js +24 -0
  59. package/esm/plugins/input-rules/InputRulesPlugin.d.ts +25 -0
  60. package/esm/plugins/input-rules/InputRulesPlugin.d.ts.map +1 -0
  61. package/esm/plugins/input-rules/InputRulesPlugin.js +168 -0
  62. package/esm/plugins/input-rules/mod.d.ts +3 -0
  63. package/esm/plugins/input-rules/mod.d.ts.map +1 -0
  64. package/esm/plugins/input-rules/mod.js +2 -0
  65. package/esm/plugins/input-rules/rulebuilders.d.ts +6 -0
  66. package/esm/plugins/input-rules/rulebuilders.d.ts.map +1 -0
  67. package/esm/plugins/input-rules/rulebuilders.js +64 -0
  68. package/esm/plugins/keymap/keymap.d.ts +12 -0
  69. package/esm/plugins/keymap/keymap.d.ts.map +1 -0
  70. package/esm/plugins/keymap/keymap.js +125 -0
  71. package/esm/plugins/keymap/mod.d.ts +2 -0
  72. package/esm/plugins/keymap/mod.d.ts.map +1 -0
  73. package/esm/plugins/keymap/mod.js +1 -0
  74. package/esm/plugins/keymap/w3c-keyname.d.ts +4 -0
  75. package/esm/plugins/keymap/w3c-keyname.d.ts.map +1 -0
  76. package/esm/plugins/keymap/w3c-keyname.js +124 -0
  77. package/esm/search/mod.d.ts +3 -0
  78. package/esm/search/mod.d.ts.map +1 -0
  79. package/esm/search/mod.js +2 -0
  80. package/esm/search/query.d.ts +45 -0
  81. package/esm/search/query.d.ts.map +1 -0
  82. package/esm/search/query.js +334 -0
  83. package/esm/search/search.d.ts +32 -0
  84. package/esm/search/search.d.ts.map +1 -0
  85. package/esm/search/search.js +199 -0
  86. package/esm/types.d.ts +59 -0
  87. package/esm/types.d.ts.map +1 -0
  88. package/esm/types.js +1 -0
  89. package/esm/ui.d.ts +15 -0
  90. package/esm/ui.d.ts.map +1 -0
  91. package/esm/ui.js +16 -0
  92. package/esm/utilities/SmartOutput.d.ts +41 -0
  93. package/esm/utilities/SmartOutput.d.ts.map +1 -0
  94. package/esm/utilities/SmartOutput.js +201 -0
  95. package/esm/utilities/createNodeFromContent.d.ts +9 -0
  96. package/esm/utilities/createNodeFromContent.d.ts.map +1 -0
  97. package/esm/utilities/createNodeFromContent.js +32 -0
  98. package/esm/utilities/getHtmlAttributes.d.ts +9 -0
  99. package/esm/utilities/getHtmlAttributes.d.ts.map +1 -0
  100. package/esm/utilities/getHtmlAttributes.js +47 -0
  101. package/esm/utilities/getShadowRoot.d.ts +2 -0
  102. package/esm/utilities/getShadowRoot.d.ts.map +1 -0
  103. package/esm/utilities/getShadowRoot.js +16 -0
  104. package/esm/utilities/mod.d.ts +6 -0
  105. package/esm/utilities/mod.d.ts.map +1 -0
  106. package/esm/utilities/mod.js +5 -0
  107. package/esm/utilities/toRawTextResult.d.ts +3 -0
  108. package/esm/utilities/toRawTextResult.d.ts.map +1 -0
  109. package/esm/utilities/toRawTextResult.js +21 -0
  110. package/package.json +1 -2
@@ -0,0 +1,3 @@
1
+ import { EditorState, Transaction } from 'prosemirror-state';
2
+ export declare function createChainableState(transaction: Transaction, state: EditorState): EditorState;
3
+ //# sourceMappingURL=createChainableState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createChainableState.d.ts","sourceRoot":"","sources":["../../src/commands/createChainableState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE7D,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,WAAW,GACjB,WAAW,CA8Bb"}
@@ -0,0 +1,29 @@
1
+ export function createChainableState(transaction, state) {
2
+ let { selection } = transaction;
3
+ let { doc } = transaction;
4
+ let { storedMarks } = transaction;
5
+ return {
6
+ ...state,
7
+ apply: state.apply.bind(state),
8
+ applyTransaction: state.applyTransaction.bind(state),
9
+ plugins: state.plugins,
10
+ schema: state.schema,
11
+ reconfigure: state.reconfigure.bind(state),
12
+ toJSON: state.toJSON.bind(state),
13
+ get storedMarks() {
14
+ return storedMarks;
15
+ },
16
+ get selection() {
17
+ return selection;
18
+ },
19
+ get doc() {
20
+ return doc;
21
+ },
22
+ get tr() {
23
+ selection = transaction.selection;
24
+ doc = transaction.doc;
25
+ storedMarks = transaction.storedMarks;
26
+ return transaction;
27
+ },
28
+ };
29
+ }
@@ -0,0 +1,3 @@
1
+ import { CommandFactory } from './mod.js';
2
+ export declare const keyCommandFactories: Record<string, CommandFactory>;
3
+ //# sourceMappingURL=keyCommandFactories.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyCommandFactories.d.ts","sourceRoot":"","sources":["../../src/commands/keyCommandFactories.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAgB,MAAM,UAAU,CAAC;AAqBxD,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAI9D,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { firstCommand } from './mod.js';
2
+ import { baseCommandFactories } from './baseCommandFactories.js';
3
+ const backspace = firstCommand(baseCommandFactories.undoInputRule(), baseCommandFactories.deleteSelection(), baseCommandFactories.joinBackward(), baseCommandFactories.selectNodeBackward());
4
+ const del = firstCommand(baseCommandFactories.deleteSelection(), baseCommandFactories.joinForward(), baseCommandFactories.selectNodeForward());
5
+ const enter = firstCommand(baseCommandFactories.newlineInCode(), baseCommandFactories.createParagraphNear(), baseCommandFactories.liftEmptyBlock(), baseCommandFactories.splitBlock());
6
+ export const keyCommandFactories = {
7
+ backspace: () => backspace,
8
+ del: () => del,
9
+ enter: () => enter,
10
+ };
@@ -0,0 +1,7 @@
1
+ import type { Node } from 'prosemirror-model';
2
+ import type { Command } from './types.js';
3
+ export * from './types.js';
4
+ export declare function firstCommand(...commands: readonly Command[]): Command;
5
+ export declare function alternativeCommands(...commands: readonly Command[]): Command;
6
+ export declare function autoJoin(command: Command, isJoinable: ((before: Node, after: Node) => boolean) | readonly string[]): Command;
7
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/commands/mod.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAG1C,cAAc,YAAY,CAAC;AAI3B,wBAAgB,YAAY,CAAC,GAAG,QAAQ,EAAE,SAAS,OAAO,EAAE,GAAG,OAAO,CAmBrE;AAED,wBAAgB,mBAAmB,CAAC,GAAG,QAAQ,EAAE,SAAS,OAAO,EAAE,GAAG,OAAO,CAO5E;AAyDD,wBAAgB,QAAQ,CACtB,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,KAAK,OAAO,CAAC,GAAG,SAAS,MAAM,EAAE,GACvE,OAAO,CAMT"}
@@ -0,0 +1,81 @@
1
+ import { canJoin } from 'prosemirror-transform';
2
+ export * from './types.js';
3
+ /// Combine a number of command functions into a single function (which
4
+ /// calls them one by one until one returns true).
5
+ export function firstCommand(...commands) {
6
+ const cmd = function (state, dispatch, view) {
7
+ for (let i = 0; i < commands.length; i++) {
8
+ if (commands[i](state, dispatch, view)) {
9
+ const cmd = commands[i];
10
+ if (cmd.displayName !== 'first') {
11
+ console.debug('firstCommand: ', commands[i].displayName || commands[i]);
12
+ }
13
+ return true;
14
+ }
15
+ }
16
+ return false;
17
+ };
18
+ cmd.displayName = 'first';
19
+ return cmd;
20
+ }
21
+ export function alternativeCommands(...commands) {
22
+ return function (state, dispatch, view) {
23
+ for (let i = 0; i < commands.length; i++) {
24
+ if (commands[i](state, dispatch, view))
25
+ return true;
26
+ }
27
+ return false;
28
+ };
29
+ }
30
+ function wrapDispatchForJoin(dispatch, isJoinable) {
31
+ return (tr) => {
32
+ if (!tr.isGeneric)
33
+ return dispatch(tr);
34
+ let ranges = [];
35
+ for (let i = 0; i < tr.mapping.maps.length; i++) {
36
+ let map = tr.mapping.maps[i];
37
+ for (let j = 0; j < ranges.length; j++) {
38
+ ranges[j] = map.map(ranges[j]);
39
+ }
40
+ map.forEach((_s, _e, from, to) => ranges.push(from, to));
41
+ }
42
+ // Figure out which joinable points exist inside those ranges,
43
+ // by checking all node boundaries in their parent nodes.
44
+ let joinable = [];
45
+ for (let i = 0; i < ranges.length; i += 2) {
46
+ let from = ranges[i], to = ranges[i + 1];
47
+ let $from = tr.doc.resolve(from), depth = $from.sharedDepth(to), parent = $from.node(depth);
48
+ for (let index = $from.indexAfter(depth), pos = $from.after(depth + 1); pos <= to; ++index) {
49
+ let after = parent.maybeChild(index);
50
+ if (!after)
51
+ break;
52
+ if (index && joinable.indexOf(pos) == -1) {
53
+ let before = parent.child(index - 1);
54
+ if (before.type == after.type && isJoinable(before, after)) {
55
+ joinable.push(pos);
56
+ }
57
+ }
58
+ pos += after.nodeSize;
59
+ }
60
+ }
61
+ // Join the joinable points
62
+ joinable.sort((a, b) => a - b);
63
+ for (let i = joinable.length - 1; i >= 0; i--) {
64
+ if (canJoin(tr.doc, joinable[i]))
65
+ tr.join(joinable[i]);
66
+ }
67
+ dispatch(tr);
68
+ };
69
+ }
70
+ /// Wrap a command so that, when it produces a transform that causes
71
+ /// two joinable nodes to end up next to each other, those are joined.
72
+ /// Nodes are considered joinable when they are of the same type and
73
+ /// when the `isJoinable` predicate returns true for them or, if an
74
+ /// array of strings was passed, if their node type name is in that
75
+ /// array.
76
+ export function autoJoin(command, isJoinable) {
77
+ let canJoin = Array.isArray(isJoinable)
78
+ ? (node) => isJoinable.indexOf(node.type.name) > -1
79
+ : isJoinable;
80
+ return (state, dispatch, view) => command(state, dispatch && wrapDispatchForJoin(dispatch, canJoin), view);
81
+ }
@@ -0,0 +1,3 @@
1
+ import type { CommandFactory } from './mod.js';
2
+ export declare const replaceCommandFactories: Record<string, CommandFactory>;
3
+ //# sourceMappingURL=replaceCommandFactories.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replaceCommandFactories.d.ts","sourceRoot":"","sources":["../../src/commands/replaceCommandFactories.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAW,cAAc,EAAE,MAAM,UAAU,CAAC;AAwHxD,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAMlE,CAAC"}
@@ -0,0 +1,94 @@
1
+ import { Fragment, Slice } from 'prosemirror-model';
2
+ const replaceRangeText = (range, text) => {
3
+ return (state, dispatch) => {
4
+ const tr = state.tr;
5
+ const from = tr.mapping.map(range.from);
6
+ const to = tr.mapping.map(range.to);
7
+ const frag = Fragment.from(state.schema.text(text));
8
+ const insert = new Slice(frag, 0, 0);
9
+ tr.replace(from, to, insert);
10
+ if (dispatch) {
11
+ dispatch(tr);
12
+ }
13
+ return true;
14
+ };
15
+ };
16
+ const replaceRangeSlice = (range, insert) => {
17
+ return (state, dispatch) => {
18
+ const tr = state.tr;
19
+ const from = tr.mapping.map(range.from);
20
+ const to = tr.mapping.map(range.to);
21
+ tr.replace(from, to, insert);
22
+ if (dispatch) {
23
+ dispatch(tr);
24
+ }
25
+ return true;
26
+ };
27
+ };
28
+ function getTopMostBlockStartForOffset(state, offset) {
29
+ const { doc } = state;
30
+ const $pos = doc.resolve(offset);
31
+ const blockPos = $pos.before($pos.depth);
32
+ if ($pos.depth === 1)
33
+ return blockPos;
34
+ return $pos.start(1);
35
+ }
36
+ function getTopMostBlockEndForOffset(state, offset) {
37
+ const { doc } = state;
38
+ const $pos = doc.resolve(offset);
39
+ return $pos.end(1);
40
+ }
41
+ function getAdjacentTopBlock(state, offset) {
42
+ const { doc } = state;
43
+ if (offset < 0 || offset > doc.content.size) {
44
+ throw new RangeError('Offset is outside the document');
45
+ }
46
+ const $pos = doc.resolve(offset);
47
+ const atBlockStart = $pos.pos === $pos.start($pos.depth);
48
+ if (atBlockStart) {
49
+ return getTopMostBlockStartForOffset(state, offset);
50
+ }
51
+ else {
52
+ return getTopMostBlockEndForOffset(state, offset);
53
+ }
54
+ }
55
+ const insertBlockBefore = (pos, insert) => {
56
+ return (state, dispatch) => {
57
+ const tr = state.tr;
58
+ const blockPos = getTopMostBlockStartForOffset(state, tr.mapping.map(pos));
59
+ tr.insert(blockPos, insert);
60
+ if (dispatch) {
61
+ dispatch(tr);
62
+ }
63
+ return true;
64
+ };
65
+ };
66
+ const insertBlockAfter = (pos, insert) => {
67
+ return (state, dispatch) => {
68
+ const tr = state.tr;
69
+ const blockPos = getTopMostBlockEndForOffset(state, tr.mapping.map(pos));
70
+ tr.insert(blockPos, insert);
71
+ if (dispatch) {
72
+ dispatch(tr);
73
+ }
74
+ return true;
75
+ };
76
+ };
77
+ const insertBlockSmart = (pos, insert) => {
78
+ return (state, dispatch) => {
79
+ const tr = state.tr;
80
+ const blockPos = getAdjacentTopBlock(state, tr.mapping.map(pos));
81
+ tr.insert(blockPos, insert);
82
+ if (dispatch) {
83
+ dispatch(tr);
84
+ }
85
+ return true;
86
+ };
87
+ };
88
+ export const replaceCommandFactories = {
89
+ replaceRangeText,
90
+ replaceRangeSlice,
91
+ insertBlockBefore,
92
+ insertBlockAfter,
93
+ insertBlockSmart,
94
+ };
@@ -0,0 +1,22 @@
1
+ import type { Command as PmCommand } from 'prosemirror-state';
2
+ interface Command extends PmCommand {
3
+ displayName?: string;
4
+ description?: string;
5
+ }
6
+ export type { Command };
7
+ export type CommandFactory = (...args: any[]) => Command;
8
+ export interface Commands {
9
+ [name: string]: Command;
10
+ }
11
+ export interface CommandFactories {
12
+ [name: string]: CommandFactory;
13
+ }
14
+ export type CommandShortcuts = {
15
+ [name: string]: string;
16
+ };
17
+ export type ChainedCommands = {
18
+ [Item in keyof Commands]: (...args: unknown[]) => ChainedCommands;
19
+ } & {
20
+ run: () => boolean;
21
+ };
22
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/commands/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9D,UAAU,OAAQ,SAAQ,SAAS;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,YAAY,EAAE,OAAO,EAAE,CAAC;AAExB,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC;AAEzD,MAAM,WAAW,QAAQ;IACvB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,gBAAgB;IAC/B,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAAC;CAChC;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,eAAe,GACvB;KACC,IAAI,IAAI,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,eAAe;CAClE,GACC;IACA,GAAG,EAAE,MAAM,OAAO,CAAC;CACpB,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
package/esm/mod.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ export * from './CoreEditor.js';
2
+ export * from './Extension.js';
3
+ export * from './Mark.js';
4
+ export * from './Node.js';
5
+ export * from './nodeToTreeString.js';
6
+ export * from './types.js';
7
+ export * from './utilities/SmartOutput.js';
8
+ export * from './ui.js';
9
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC;AAC3B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,SAAS,CAAC"}
package/esm/mod.js ADDED
@@ -0,0 +1,8 @@
1
+ export * from './CoreEditor.js';
2
+ export * from './Extension.js';
3
+ export * from './Mark.js';
4
+ export * from './Node.js';
5
+ export * from './nodeToTreeString.js';
6
+ export * from './types.js';
7
+ export * from './utilities/SmartOutput.js';
8
+ export * from './ui.js';
@@ -0,0 +1,10 @@
1
+ import type { Node } from 'prosemirror-model';
2
+ import { SmartOutput } from './utilities/SmartOutput.js';
3
+ export interface NodeAndPos {
4
+ node: Node;
5
+ pos: number;
6
+ }
7
+ export declare function nodeToTreeStringOutput(output: SmartOutput<NodeAndPos>, node: Node | Node[] | readonly Node[], level?: number, currentPos?: number): SmartOutput<NodeAndPos> | undefined;
8
+ export declare function nodeToTreeString(node: Node | Node[] | readonly Node[]): string;
9
+ export declare function debugNode(node: Node | Node[]): void;
10
+ //# sourceMappingURL=nodeToTreeString.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodeToTreeString.d.ts","sourceRoot":"","sources":["../src/nodeToTreeString.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAYzD,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,IAAI,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;CACb;AAED,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,WAAW,CAAC,UAAU,CAAC,EAC/B,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,GAAG,SAAS,IAAI,EAAE,EACrC,KAAK,SAAI,EACT,UAAU,SAAI,uCAmEf;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,GAAG,SAAS,IAAI,EAAE,UAIrE;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,QAE5C"}
@@ -0,0 +1,74 @@
1
+ import { SmartOutput } from './utilities/SmartOutput.js';
2
+ function trimText(str, maxLen = 20) {
3
+ str = str.replaceAll('\n', '\\n');
4
+ if (str.length <= maxLen) {
5
+ return str;
6
+ }
7
+ return str.slice(0, maxLen) + '...';
8
+ }
9
+ export function nodeToTreeStringOutput(output, node, level = 0, currentPos = 0) {
10
+ let delim = '';
11
+ for (let i = 0; i < level; i++) {
12
+ delim += ' ';
13
+ }
14
+ if (Array.isArray(node)) {
15
+ for (const child of node) {
16
+ output.log(delim, { node: child, pos: currentPos });
17
+ nodeToTreeStringOutput(output, child, level + 1, currentPos);
18
+ // .replace(/\s+$/gm, '') +
19
+ // '\n'
20
+ }
21
+ return;
22
+ }
23
+ // https://prosemirror.net/docs/guide/#doc.indexing
24
+ let line = '';
25
+ // if (node.type) {
26
+ if ('type' in node) {
27
+ line += ` - [${node.type.name}] `;
28
+ // } else {
29
+ // line += ` - `;
30
+ // }
31
+ line += `pos: ${currentPos}, `;
32
+ line += `nodeSize: ${node.nodeSize}, `; // isLeaf ? 1 : 2 + this.content.size
33
+ line += `epos: ${currentPos + node.nodeSize}, `; // isLeaf ? 1 : 2 + this.content.size
34
+ if (node.content) {
35
+ line += `fragment.size: ${node.content.size}, `;
36
+ }
37
+ output.log((delim + line) + '\n', { node, pos: currentPos });
38
+ let marksLine = '';
39
+ if (node.marks) {
40
+ for (const mark of node.marks) {
41
+ marksLine += `(${mark.type.name}), `;
42
+ }
43
+ }
44
+ if (marksLine) {
45
+ output.log((delim + ' ' + marksLine) + '\n', {
46
+ node,
47
+ pos: currentPos,
48
+ });
49
+ }
50
+ if (node.text) {
51
+ output.log((delim + ' "' + trimText(node.text) + '"') + '\n', {
52
+ node,
53
+ pos: currentPos,
54
+ });
55
+ }
56
+ }
57
+ node.forEach((child, offset) => {
58
+ // output +=
59
+ nodeToTreeStringOutput(output, child, level + 1, currentPos + offset + 1);
60
+ // .replace(
61
+ // /\s+$/gm,
62
+ // '',
63
+ // ) + '\n'; // + (node.isLeaf ? 1 : 2)
64
+ });
65
+ return output;
66
+ }
67
+ export function nodeToTreeString(node) {
68
+ const output = new SmartOutput();
69
+ nodeToTreeStringOutput(output, node);
70
+ return output.toString();
71
+ }
72
+ export function debugNode(node) {
73
+ console.debug(nodeToTreeString(node));
74
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,6 @@
1
+ import { Plugin } from 'prosemirror-state';
2
+ import type { CoreEditor } from '../mod.js';
3
+ export declare class TrackSelecionPlugin extends Plugin {
4
+ constructor(editor: CoreEditor);
5
+ }
6
+ //# sourceMappingURL=TrackSelecionPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TrackSelecionPlugin.d.ts","sourceRoot":"","sources":["../../src/plugins/TrackSelecionPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C,qBAAa,mBAAoB,SAAQ,MAAM;gBACjC,MAAM,EAAE,UAAU;CAsB/B"}
@@ -0,0 +1,24 @@
1
+ import { Plugin } from 'prosemirror-state';
2
+ export class TrackSelecionPlugin extends Plugin {
3
+ constructor(editor) {
4
+ super({
5
+ view(editorView) {
6
+ return {
7
+ update(view, prevState) {
8
+ const state = view.state;
9
+ const prevSelection = prevState.selection;
10
+ const selection = state.selection;
11
+ if (!prevSelection.eq(selection)) {
12
+ const event = new CustomEvent('selection', {
13
+ detail: {
14
+ selection,
15
+ },
16
+ });
17
+ editor.dispatchEvent(event);
18
+ }
19
+ },
20
+ };
21
+ },
22
+ });
23
+ }
24
+ }
@@ -0,0 +1,25 @@
1
+ import { EditorState, Plugin, Transaction } from 'prosemirror-state';
2
+ import type { Command, CommandFactory } from '../../commands/types.js';
3
+ type PluginState = {
4
+ transform: Transaction;
5
+ from: number;
6
+ to: number;
7
+ text: string;
8
+ } | null;
9
+ export declare class InputRule {
10
+ readonly match: RegExp;
11
+ handler: (state: EditorState, match: RegExpMatchArray, start: number, end: number) => Transaction | null;
12
+ undoable: boolean;
13
+ inCode: boolean | 'only';
14
+ constructor(match: RegExp, handler: string | ((state: EditorState, match: RegExpMatchArray, start: number, end: number) => Transaction | null), options?: {
15
+ undoable?: boolean;
16
+ inCode?: boolean | 'only';
17
+ });
18
+ }
19
+ export declare class InputRulesPlugin extends Plugin<PluginState> {
20
+ constructor(rules: readonly InputRule[]);
21
+ }
22
+ export declare const runInputRules: CommandFactory;
23
+ export declare const undoInputRuleCommand: Command;
24
+ export {};
25
+ //# sourceMappingURL=InputRulesPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InputRulesPlugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/input-rules/InputRulesPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,MAAM,EAEN,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAG3B,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAIvE,KAAK,WAAW,GAAG;IACjB,SAAS,EAAE,WAAW,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,IAAI,CAAC;AAMT,qBAAa,SAAS;IA8BlB,QAAQ,CAAC,KAAK,EAAE,MAAM;IA5BxB,OAAO,EAAE,CACP,KAAK,EAAE,WAAW,EAClB,KAAK,EAAE,gBAAgB,EACvB,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,KACR,WAAW,GAAG,IAAI,CAAC;IAGxB,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC;gBAmBd,KAAK,EAAE,MAAM,EACtB,OAAO,EACH,MAAM,GACN,CAAC,CACD,KAAK,EAAE,WAAW,EAClB,KAAK,EAAE,gBAAgB,EACvB,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,KACR,WAAW,GAAG,IAAI,CAAC,EAC1B,OAAO,GAAE;QAIP,QAAQ,CAAC,EAAE,OAAO,CAAC;QAInB,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;KACtB;CAST;AA2BD,qBAAa,gBAAiB,SAAQ,MAAM,CAAC,WAAW,CAAC;gBAC3C,KAAK,EAAE,SAAS,SAAS,EAAE;CA4CxC;AAED,eAAO,MAAM,aAAa,EAAE,cAiD3B,CAAC;AAIF,eAAO,MAAM,oBAAoB,EAAE,OAiClC,CAAC"}
@@ -0,0 +1,168 @@
1
+ import { Plugin, } from 'prosemirror-state';
2
+ const MAX_MATCH = 500;
3
+ /// Input rules are regular expressions describing a piece of text
4
+ /// that, when typed, causes something to happen. This might be
5
+ /// changing two dashes into an emdash, wrapping a paragraph starting
6
+ /// with `"> "` into a blockquote, or something entirely different.
7
+ export class InputRule {
8
+ match;
9
+ /// @internal
10
+ handler;
11
+ /// @internal
12
+ undoable;
13
+ inCode;
14
+ // :: (RegExp, union<string, (state: EditorState, match: [string], start: number, end: number) → ?Transaction>)
15
+ /// Create an input rule. The rule applies when the user typed
16
+ /// something and the text directly in front of the cursor matches
17
+ /// `match`, which should end with `$`.
18
+ ///
19
+ /// The `handler` can be a string, in which case the matched text, or
20
+ /// the first matched group in the regexp, is replaced by that
21
+ /// string.
22
+ ///
23
+ /// Or a it can be a function, which will be called with the match
24
+ /// array produced by
25
+ /// [`RegExp.exec`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec),
26
+ /// as well as the start and end of the matched range, and which can
27
+ /// return a [transaction](#state.Transaction) that describes the
28
+ /// rule's effect, or null to indicate the input was not handled.
29
+ constructor(
30
+ /// @internal
31
+ match, handler, options = {}) {
32
+ this.match = match;
33
+ this.match = match;
34
+ this.handler = typeof handler == 'string'
35
+ ? stringHandler(handler)
36
+ : handler;
37
+ this.undoable = options.undoable !== false;
38
+ this.inCode = options.inCode || false;
39
+ }
40
+ }
41
+ function stringHandler(string) {
42
+ return function (state, match, start, end) {
43
+ let insert = string;
44
+ if (match[1]) {
45
+ const offset = match[0].lastIndexOf(match[1]);
46
+ insert += match[0].slice(offset + match[1].length);
47
+ start += offset;
48
+ const cutOff = start - end;
49
+ if (cutOff > 0) {
50
+ insert = match[0].slice(offset - cutOff, offset) + insert;
51
+ start = end;
52
+ }
53
+ }
54
+ return state.tr.insertText(insert, start, end);
55
+ };
56
+ }
57
+ /// Create an input rules plugin. When enabled, it will cause text
58
+ /// input that matches any of the given rules to trigger the rule's
59
+ /// action.
60
+ export class InputRulesPlugin extends Plugin {
61
+ constructor(rules) {
62
+ super({
63
+ state: {
64
+ init() {
65
+ return null;
66
+ },
67
+ apply(tr, prev) {
68
+ const stored = tr.getMeta(this);
69
+ if (stored) {
70
+ return stored;
71
+ }
72
+ return tr.selectionSet || tr.docChanged ? null : prev;
73
+ },
74
+ },
75
+ props: {
76
+ handleTextInput(view, from, to, text) {
77
+ const cmd = runInputRules(from, to, text, rules);
78
+ const dispatch = (tr) => {
79
+ view.dispatch(tr);
80
+ };
81
+ return cmd(view.state, dispatch, view);
82
+ // return run(view, from, to, text, rules, this);
83
+ },
84
+ handleDOMEvents: {
85
+ compositionend: (view) => {
86
+ setTimeout(() => {
87
+ const { $cursor } = view.state.selection;
88
+ if ($cursor) {
89
+ const cmd = runInputRules($cursor.pos, $cursor.pos, '', rules);
90
+ const dispatch = (tr) => {
91
+ view.dispatch(tr);
92
+ };
93
+ return cmd(view.state, dispatch, view);
94
+ // run(view, $cursor.pos, $cursor.pos, '', rules, this);
95
+ }
96
+ });
97
+ },
98
+ },
99
+ },
100
+ isInputRules: true,
101
+ });
102
+ }
103
+ }
104
+ export const runInputRules = (from, to, text, rules) => {
105
+ const cmd = (state, dispatch, view) => {
106
+ const plugins = state.plugins;
107
+ const plugin = plugins.find((plugin) => plugin.spec.isInputRules);
108
+ if (!plugin) {
109
+ return false;
110
+ }
111
+ if (view?.composing)
112
+ return false;
113
+ const $from = state.doc.resolve(from);
114
+ const textBefore = $from.parent.textBetween(Math.max(0, $from.parentOffset - MAX_MATCH), $from.parentOffset, null, '\ufffc') + text;
115
+ for (let i = 0; i < rules.length; i++) {
116
+ const rule = rules[i];
117
+ if ($from.parent.type.spec.code) {
118
+ if (!rule.inCode)
119
+ continue;
120
+ }
121
+ else if (rule.inCode === 'only') {
122
+ continue;
123
+ }
124
+ const match = rule.match.exec(textBefore);
125
+ const tr = match &&
126
+ rule.handler(state, match, from - (match[0].length - text.length), to);
127
+ if (!tr)
128
+ continue;
129
+ if (rule.undoable) {
130
+ tr.setMeta(plugin, { transform: tr, from, to, text });
131
+ }
132
+ view?.dispatch(tr);
133
+ return true;
134
+ }
135
+ return false;
136
+ };
137
+ cmd.displayName = 'runInputRules';
138
+ return cmd;
139
+ };
140
+ /// This is a command that will undo an input rule, if applying such a
141
+ /// rule was the last thing that the user did.
142
+ export const undoInputRuleCommand = (state, dispatch) => {
143
+ const plugins = state.plugins;
144
+ const plugin = plugins.find((plugin) => plugin.spec.isInputRules);
145
+ if (!plugin) {
146
+ return false;
147
+ }
148
+ const undoable = plugin.getState(state);
149
+ if (!undoable) {
150
+ return false;
151
+ }
152
+ if (dispatch) {
153
+ const tr = state.tr;
154
+ const toUndo = undoable.transform;
155
+ for (let j = toUndo.steps.length - 1; j >= 0; j--) {
156
+ tr.step(toUndo.steps[j].invert(toUndo.docs[j]));
157
+ }
158
+ if (undoable.text) {
159
+ const marks = tr.doc.resolve(undoable.from).marks();
160
+ tr.replaceWith(undoable.from, undoable.to, state.schema.text(undoable.text, marks));
161
+ }
162
+ else {
163
+ tr.delete(undoable.from, undoable.to);
164
+ }
165
+ dispatch(tr);
166
+ }
167
+ return true;
168
+ };
@@ -0,0 +1,3 @@
1
+ export * from './InputRulesPlugin.js';
2
+ export * from './rulebuilders.js';
3
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/plugins/input-rules/mod.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './InputRulesPlugin.js';
2
+ export * from './rulebuilders.js';