@kerebron/extension-dev-toolkit 0.3.2
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/LICENSE +23 -0
- package/README.md +67 -0
- package/esm/editor/src/CoreEditor.d.ts +31 -0
- package/esm/editor/src/CoreEditor.d.ts.map +1 -0
- package/esm/editor/src/CoreEditor.js +200 -0
- package/esm/editor/src/DummyEditorView.d.ts +60 -0
- package/esm/editor/src/DummyEditorView.d.ts.map +1 -0
- package/esm/editor/src/DummyEditorView.js +277 -0
- package/esm/editor/src/Extension.d.ts +26 -0
- package/esm/editor/src/Extension.d.ts.map +1 -0
- package/esm/editor/src/Extension.js +33 -0
- package/esm/editor/src/ExtensionManager.d.ts +33 -0
- package/esm/editor/src/ExtensionManager.d.ts.map +1 -0
- package/esm/editor/src/ExtensionManager.js +272 -0
- package/esm/editor/src/Mark.d.ts +20 -0
- package/esm/editor/src/Mark.d.ts.map +1 -0
- package/esm/editor/src/Mark.js +40 -0
- package/esm/editor/src/Node.d.ts +29 -0
- package/esm/editor/src/Node.d.ts.map +1 -0
- package/esm/editor/src/Node.js +49 -0
- package/esm/editor/src/commands/CommandManager.d.ts +16 -0
- package/esm/editor/src/commands/CommandManager.d.ts.map +1 -0
- package/esm/editor/src/commands/CommandManager.js +61 -0
- package/esm/editor/src/commands/createChainableState.d.ts +3 -0
- package/esm/editor/src/commands/createChainableState.d.ts.map +1 -0
- package/esm/editor/src/commands/createChainableState.js +29 -0
- package/esm/editor/src/commands/mod.d.ts +55 -0
- package/esm/editor/src/commands/mod.d.ts.map +1 -0
- package/esm/editor/src/commands/mod.js +883 -0
- package/esm/editor/src/mod.d.ts +7 -0
- package/esm/editor/src/mod.d.ts.map +1 -0
- package/esm/editor/src/mod.js +6 -0
- package/esm/editor/src/nodeToTreeString.d.ts +10 -0
- package/esm/editor/src/nodeToTreeString.d.ts.map +1 -0
- package/esm/editor/src/nodeToTreeString.js +74 -0
- package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts +23 -0
- package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts.map +1 -0
- package/esm/editor/src/plugins/input-rules/InputRulesPlugin.js +163 -0
- package/esm/editor/src/plugins/keymap/keymap.d.ts +11 -0
- package/esm/editor/src/plugins/keymap/keymap.d.ts.map +1 -0
- package/esm/editor/src/plugins/keymap/keymap.js +125 -0
- package/esm/editor/src/plugins/keymap/w3c-keyname.d.ts +4 -0
- package/esm/editor/src/plugins/keymap/w3c-keyname.d.ts.map +1 -0
- package/esm/editor/src/plugins/keymap/w3c-keyname.js +124 -0
- package/esm/editor/src/types.d.ts +34 -0
- package/esm/editor/src/types.d.ts.map +1 -0
- package/esm/editor/src/types.js +1 -0
- package/esm/editor/src/utilities/SmartOutput.d.ts +39 -0
- package/esm/editor/src/utilities/SmartOutput.d.ts.map +1 -0
- package/esm/editor/src/utilities/SmartOutput.js +213 -0
- package/esm/editor/src/utilities/createNodeFromContent.d.ts +9 -0
- package/esm/editor/src/utilities/createNodeFromContent.d.ts.map +1 -0
- package/esm/editor/src/utilities/createNodeFromContent.js +32 -0
- package/esm/editor/src/utilities/getHtmlAttributes.d.ts +9 -0
- package/esm/editor/src/utilities/getHtmlAttributes.d.ts.map +1 -0
- package/esm/editor/src/utilities/getHtmlAttributes.js +47 -0
- package/esm/extension-dev-toolkit/src/mod.d.ts +13 -0
- package/esm/extension-dev-toolkit/src/mod.d.ts.map +1 -0
- package/esm/extension-dev-toolkit/src/mod.js +50 -0
- package/esm/package.json +3 -0
- package/package.json +23 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/editor/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"}
|
|
@@ -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/editor/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,23 @@
|
|
|
1
|
+
import { Command, EditorState, Plugin, Transaction } from 'prosemirror-state';
|
|
2
|
+
export declare class InputRule {
|
|
3
|
+
readonly match: RegExp;
|
|
4
|
+
handler: (state: EditorState, match: RegExpMatchArray, start: number, end: number) => Transaction | null;
|
|
5
|
+
undoable: boolean;
|
|
6
|
+
inCode: boolean | 'only';
|
|
7
|
+
constructor(match: RegExp, handler: string | ((state: EditorState, match: RegExpMatchArray, start: number, end: number) => Transaction | null), options?: {
|
|
8
|
+
undoable?: boolean;
|
|
9
|
+
inCode?: boolean | 'only';
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
type PluginState = {
|
|
13
|
+
transform: Transaction;
|
|
14
|
+
from: number;
|
|
15
|
+
to: number;
|
|
16
|
+
text: string;
|
|
17
|
+
} | null;
|
|
18
|
+
export declare class InputRulesPlugin extends Plugin<PluginState> {
|
|
19
|
+
constructor(rules: readonly InputRule[]);
|
|
20
|
+
}
|
|
21
|
+
export declare const undoInputRule: Command;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=InputRulesPlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InputRulesPlugin.d.ts","sourceRoot":"","sources":["../../../../../src/editor/src/plugins/input-rules/InputRulesPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,WAAW,EACX,MAAM,EAEN,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAO3B,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;AA0BD,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;AAKT,qBAAa,gBAAiB,SAAQ,MAAM,CAAC,WAAW,CAAC;gBAC3C,KAAK,EAAE,SAAS,SAAS,EAAE;CAgCxC;AAsCD,eAAO,MAAM,aAAa,EAAE,OA4B3B,CAAC"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { Plugin, } from 'prosemirror-state';
|
|
2
|
+
/// Input rules are regular expressions describing a piece of text
|
|
3
|
+
/// that, when typed, causes something to happen. This might be
|
|
4
|
+
/// changing two dashes into an emdash, wrapping a paragraph starting
|
|
5
|
+
/// with `"> "` into a blockquote, or something entirely different.
|
|
6
|
+
export class InputRule {
|
|
7
|
+
// :: (RegExp, union<string, (state: EditorState, match: [string], start: number, end: number) → ?Transaction>)
|
|
8
|
+
/// Create an input rule. The rule applies when the user typed
|
|
9
|
+
/// something and the text directly in front of the cursor matches
|
|
10
|
+
/// `match`, which should end with `$`.
|
|
11
|
+
///
|
|
12
|
+
/// The `handler` can be a string, in which case the matched text, or
|
|
13
|
+
/// the first matched group in the regexp, is replaced by that
|
|
14
|
+
/// string.
|
|
15
|
+
///
|
|
16
|
+
/// Or a it can be a function, which will be called with the match
|
|
17
|
+
/// array produced by
|
|
18
|
+
/// [`RegExp.exec`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec),
|
|
19
|
+
/// as well as the start and end of the matched range, and which can
|
|
20
|
+
/// return a [transaction](#state.Transaction) that describes the
|
|
21
|
+
/// rule's effect, or null to indicate the input was not handled.
|
|
22
|
+
constructor(
|
|
23
|
+
/// @internal
|
|
24
|
+
match, handler, options = {}) {
|
|
25
|
+
Object.defineProperty(this, "match", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true,
|
|
29
|
+
value: match
|
|
30
|
+
});
|
|
31
|
+
/// @internal
|
|
32
|
+
Object.defineProperty(this, "handler", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
writable: true,
|
|
36
|
+
value: void 0
|
|
37
|
+
});
|
|
38
|
+
/// @internal
|
|
39
|
+
Object.defineProperty(this, "undoable", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
configurable: true,
|
|
42
|
+
writable: true,
|
|
43
|
+
value: void 0
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(this, "inCode", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
configurable: true,
|
|
48
|
+
writable: true,
|
|
49
|
+
value: void 0
|
|
50
|
+
});
|
|
51
|
+
this.match = match;
|
|
52
|
+
this.handler = typeof handler == 'string'
|
|
53
|
+
? stringHandler(handler)
|
|
54
|
+
: handler;
|
|
55
|
+
this.undoable = options.undoable !== false;
|
|
56
|
+
this.inCode = options.inCode || false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function stringHandler(string) {
|
|
60
|
+
return function (state, match, start, end) {
|
|
61
|
+
let insert = string;
|
|
62
|
+
if (match[1]) {
|
|
63
|
+
let offset = match[0].lastIndexOf(match[1]);
|
|
64
|
+
insert += match[0].slice(offset + match[1].length);
|
|
65
|
+
start += offset;
|
|
66
|
+
let cutOff = start - end;
|
|
67
|
+
if (cutOff > 0) {
|
|
68
|
+
insert = match[0].slice(offset - cutOff, offset) + insert;
|
|
69
|
+
start = end;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return state.tr.insertText(insert, start, end);
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const MAX_MATCH = 500;
|
|
76
|
+
/// Create an input rules plugin. When enabled, it will cause text
|
|
77
|
+
/// input that matches any of the given rules to trigger the rule's
|
|
78
|
+
/// action.
|
|
79
|
+
export class InputRulesPlugin extends Plugin {
|
|
80
|
+
constructor(rules) {
|
|
81
|
+
super({
|
|
82
|
+
state: {
|
|
83
|
+
init() {
|
|
84
|
+
return null;
|
|
85
|
+
},
|
|
86
|
+
apply(tr, prev) {
|
|
87
|
+
let stored = tr.getMeta(this);
|
|
88
|
+
if (stored)
|
|
89
|
+
return stored;
|
|
90
|
+
return tr.selectionSet || tr.docChanged ? null : prev;
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
props: {
|
|
94
|
+
handleTextInput(view, from, to, text) {
|
|
95
|
+
return run(view, from, to, text, rules, this);
|
|
96
|
+
},
|
|
97
|
+
handleDOMEvents: {
|
|
98
|
+
compositionend: (view) => {
|
|
99
|
+
setTimeout(() => {
|
|
100
|
+
let { $cursor } = view.state.selection;
|
|
101
|
+
if ($cursor) {
|
|
102
|
+
run(view, $cursor.pos, $cursor.pos, '', rules, this);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
isInputRules: true,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function run(view, from, to, text, rules, plugin) {
|
|
113
|
+
if (view.composing)
|
|
114
|
+
return false;
|
|
115
|
+
let state = view.state, $from = state.doc.resolve(from);
|
|
116
|
+
let textBefore = $from.parent.textBetween(Math.max(0, $from.parentOffset - MAX_MATCH), $from.parentOffset, null, '\ufffc') + text;
|
|
117
|
+
for (let i = 0; i < rules.length; i++) {
|
|
118
|
+
let rule = rules[i];
|
|
119
|
+
if ($from.parent.type.spec.code) {
|
|
120
|
+
if (!rule.inCode)
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
else if (rule.inCode === 'only') {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
let match = rule.match.exec(textBefore);
|
|
127
|
+
let tr = match &&
|
|
128
|
+
rule.handler(state, match, from - (match[0].length - text.length), to);
|
|
129
|
+
if (!tr)
|
|
130
|
+
continue;
|
|
131
|
+
if (rule.undoable)
|
|
132
|
+
tr.setMeta(plugin, { transform: tr, from, to, text });
|
|
133
|
+
view.dispatch(tr);
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
/// This is a command that will undo an input rule, if applying such a
|
|
139
|
+
/// rule was the last thing that the user did.
|
|
140
|
+
export const undoInputRule = (state, dispatch) => {
|
|
141
|
+
let plugins = state.plugins;
|
|
142
|
+
for (let i = 0; i < plugins.length; i++) {
|
|
143
|
+
let plugin = plugins[i], undoable;
|
|
144
|
+
if (plugin.spec.isInputRules && (undoable = plugin.getState(state))) {
|
|
145
|
+
if (dispatch) {
|
|
146
|
+
let tr = state.tr, toUndo = undoable.transform;
|
|
147
|
+
for (let j = toUndo.steps.length - 1; j >= 0; j--) {
|
|
148
|
+
tr.step(toUndo.steps[j].invert(toUndo.docs[j]));
|
|
149
|
+
}
|
|
150
|
+
if (undoable.text) {
|
|
151
|
+
let marks = tr.doc.resolve(undoable.from).marks();
|
|
152
|
+
tr.replaceWith(undoable.from, undoable.to, state.schema.text(undoable.text, marks));
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
tr.delete(undoable.from, undoable.to);
|
|
156
|
+
}
|
|
157
|
+
dispatch(tr);
|
|
158
|
+
}
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return false;
|
|
163
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Command, Plugin } from 'prosemirror-state';
|
|
2
|
+
import { EditorView } from 'prosemirror-view';
|
|
3
|
+
export declare class KeymapPlugin extends Plugin {
|
|
4
|
+
constructor(bindings: {
|
|
5
|
+
[key: string]: Command;
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
export declare function keydownHandler(bindings: {
|
|
9
|
+
[key: string]: Command;
|
|
10
|
+
}): (view: EditorView, event: KeyboardEvent) => boolean;
|
|
11
|
+
//# sourceMappingURL=keymap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keymap.d.ts","sourceRoot":"","sources":["../../../../../src/editor/src/plugins/keymap/keymap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAyE9C,qBAAa,YAAa,SAAQ,MAAM;gBAC1B,QAAQ,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE;CAGjD;AAKD,wBAAgB,cAAc,CAC5B,QAAQ,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,GACnC,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,aAAa,KAAK,OAAO,CA6BrD"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { Plugin } from 'prosemirror-state';
|
|
2
|
+
import { base, keyName } from './w3c-keyname.js';
|
|
3
|
+
const mac = typeof navigator != 'undefined' &&
|
|
4
|
+
/Mac|iP(hone|[oa]d)/.test(navigator?.platform);
|
|
5
|
+
const windows = typeof navigator != 'undefined' &&
|
|
6
|
+
/Win/.test(navigator?.platform);
|
|
7
|
+
function normalizeKeyName(name) {
|
|
8
|
+
let parts = name.split(/-(?!$)/), result = parts[parts.length - 1];
|
|
9
|
+
if (result == 'Space')
|
|
10
|
+
result = ' ';
|
|
11
|
+
let alt, ctrl, shift, meta;
|
|
12
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
13
|
+
let mod = parts[i];
|
|
14
|
+
if (/^(cmd|meta|m)$/i.test(mod))
|
|
15
|
+
meta = true;
|
|
16
|
+
else if (/^a(lt)?$/i.test(mod))
|
|
17
|
+
alt = true;
|
|
18
|
+
else if (/^(c|ctrl|control)$/i.test(mod))
|
|
19
|
+
ctrl = true;
|
|
20
|
+
else if (/^s(hift)?$/i.test(mod))
|
|
21
|
+
shift = true;
|
|
22
|
+
else if (/^mod$/i.test(mod)) {
|
|
23
|
+
if (mac)
|
|
24
|
+
meta = true;
|
|
25
|
+
else
|
|
26
|
+
ctrl = true;
|
|
27
|
+
}
|
|
28
|
+
else
|
|
29
|
+
throw new Error('Unrecognized modifier name: ' + mod);
|
|
30
|
+
}
|
|
31
|
+
if (alt)
|
|
32
|
+
result = 'Alt-' + result;
|
|
33
|
+
if (ctrl)
|
|
34
|
+
result = 'Ctrl-' + result;
|
|
35
|
+
if (meta)
|
|
36
|
+
result = 'Meta-' + result;
|
|
37
|
+
if (shift)
|
|
38
|
+
result = 'Shift-' + result;
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
function normalize(map) {
|
|
42
|
+
let copy = Object.create(null);
|
|
43
|
+
for (let prop in map)
|
|
44
|
+
copy[normalizeKeyName(prop)] = map[prop];
|
|
45
|
+
return copy;
|
|
46
|
+
}
|
|
47
|
+
function modifiers(name, event, shift = true) {
|
|
48
|
+
if (event.altKey)
|
|
49
|
+
name = 'Alt-' + name;
|
|
50
|
+
if (event.ctrlKey)
|
|
51
|
+
name = 'Ctrl-' + name;
|
|
52
|
+
if (event.metaKey)
|
|
53
|
+
name = 'Meta-' + name;
|
|
54
|
+
if (shift && event.shiftKey)
|
|
55
|
+
name = 'Shift-' + name;
|
|
56
|
+
return name;
|
|
57
|
+
}
|
|
58
|
+
/// Create a keymap plugin for the given set of bindings.
|
|
59
|
+
///
|
|
60
|
+
/// Bindings should map key names to [command](#commands)-style
|
|
61
|
+
/// functions, which will be called with `(EditorState, dispatch,
|
|
62
|
+
/// EditorView)` arguments, and should return true when they've handled
|
|
63
|
+
/// the key. Note that the view argument isn't part of the command
|
|
64
|
+
/// protocol, but can be used as an escape hatch if a binding needs to
|
|
65
|
+
/// directly interact with the UI.
|
|
66
|
+
///
|
|
67
|
+
/// Key names may be strings like `"Shift-Ctrl-Enter"`—a key
|
|
68
|
+
/// identifier prefixed with zero or more modifiers. Key identifiers
|
|
69
|
+
/// are based on the strings that can appear in
|
|
70
|
+
/// [`KeyEvent.key`](https:///developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key).
|
|
71
|
+
/// Use lowercase letters to refer to letter keys (or uppercase letters
|
|
72
|
+
/// if you want shift to be held). You may use `"Space"` as an alias
|
|
73
|
+
/// for the `" "` name.
|
|
74
|
+
///
|
|
75
|
+
/// Modifiers can be given in any order. `Shift-` (or `s-`), `Alt-` (or
|
|
76
|
+
/// `a-`), `Ctrl-` (or `c-` or `Control-`) and `Cmd-` (or `m-` or
|
|
77
|
+
/// `Meta-`) are recognized. For characters that are created by holding
|
|
78
|
+
/// shift, the `Shift-` prefix is implied, and should not be added
|
|
79
|
+
/// explicitly.
|
|
80
|
+
///
|
|
81
|
+
/// You can use `Mod-` as a shorthand for `Cmd-` on Mac and `Ctrl-` on
|
|
82
|
+
/// other platforms.
|
|
83
|
+
///
|
|
84
|
+
/// You can add multiple keymap plugins to an editor. The order in
|
|
85
|
+
/// which they appear determines their precedence (the ones early in
|
|
86
|
+
/// the array get to dispatch first).
|
|
87
|
+
export class KeymapPlugin extends Plugin {
|
|
88
|
+
constructor(bindings) {
|
|
89
|
+
super({ props: { handleKeyDown: keydownHandler(bindings) } });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/// Given a set of bindings (using the same format as
|
|
93
|
+
/// [`keymap`](#keymap.keymap)), return a [keydown
|
|
94
|
+
/// handler](#view.EditorProps.handleKeyDown) that handles them.
|
|
95
|
+
export function keydownHandler(bindings) {
|
|
96
|
+
let map = normalize(bindings);
|
|
97
|
+
return function (view, event) {
|
|
98
|
+
let name = keyName(event), baseName, direct = map[modifiers(name, event)];
|
|
99
|
+
if (direct && direct(view.state, view.dispatch, view))
|
|
100
|
+
return true;
|
|
101
|
+
// A character key
|
|
102
|
+
if (name.length == 1 && name != ' ') {
|
|
103
|
+
if (event.shiftKey) {
|
|
104
|
+
// In case the name was already modified by shift, try looking
|
|
105
|
+
// it up without its shift modifier
|
|
106
|
+
let noShift = map[modifiers(name, event, false)];
|
|
107
|
+
if (noShift && noShift(view.state, view.dispatch, view))
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
if ((event.altKey || event.metaKey || event.ctrlKey) &&
|
|
111
|
+
// Ctrl-Alt may be used for AltGr on Windows
|
|
112
|
+
!(windows && event.ctrlKey && event.altKey) &&
|
|
113
|
+
(baseName = base[event.keyCode]) && baseName != name) {
|
|
114
|
+
// Try falling back to the keyCode when there's a modifier
|
|
115
|
+
// active or the character produced isn't ASCII, and our table
|
|
116
|
+
// produces a different name from the the keyCode. See #668,
|
|
117
|
+
// #1060, #1529.
|
|
118
|
+
let fromCode = map[modifiers(baseName, event)];
|
|
119
|
+
if (fromCode && fromCode(view.state, view.dispatch, view))
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
};
|
|
125
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"w3c-keyname.d.ts","sourceRoot":"","sources":["../../../../../src/editor/src/plugins/keymap/w3c-keyname.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAqDvC,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAyBxC,CAAC;AAuBF,wBAAgB,OAAO,CAAC,KAAK,EAAE,aAAa,UAmB3C"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
export const base = {
|
|
2
|
+
8: 'Backspace',
|
|
3
|
+
9: 'Tab',
|
|
4
|
+
10: 'Enter',
|
|
5
|
+
12: 'NumLock',
|
|
6
|
+
13: 'Enter',
|
|
7
|
+
16: 'Shift',
|
|
8
|
+
17: 'Control',
|
|
9
|
+
18: 'Alt',
|
|
10
|
+
20: 'CapsLock',
|
|
11
|
+
27: 'Escape',
|
|
12
|
+
32: ' ',
|
|
13
|
+
33: 'PageUp',
|
|
14
|
+
34: 'PageDown',
|
|
15
|
+
35: 'End',
|
|
16
|
+
36: 'Home',
|
|
17
|
+
37: 'ArrowLeft',
|
|
18
|
+
38: 'ArrowUp',
|
|
19
|
+
39: 'ArrowRight',
|
|
20
|
+
40: 'ArrowDown',
|
|
21
|
+
44: 'PrintScreen',
|
|
22
|
+
45: 'Insert',
|
|
23
|
+
46: 'Delete',
|
|
24
|
+
59: ';',
|
|
25
|
+
61: '=',
|
|
26
|
+
91: 'Meta',
|
|
27
|
+
92: 'Meta',
|
|
28
|
+
106: '*',
|
|
29
|
+
107: '+',
|
|
30
|
+
108: ',',
|
|
31
|
+
109: '-',
|
|
32
|
+
110: '.',
|
|
33
|
+
111: '/',
|
|
34
|
+
144: 'NumLock',
|
|
35
|
+
145: 'ScrollLock',
|
|
36
|
+
160: 'Shift',
|
|
37
|
+
161: 'Shift',
|
|
38
|
+
162: 'Control',
|
|
39
|
+
163: 'Control',
|
|
40
|
+
164: 'Alt',
|
|
41
|
+
165: 'Alt',
|
|
42
|
+
173: '-',
|
|
43
|
+
186: ';',
|
|
44
|
+
187: '=',
|
|
45
|
+
188: ',',
|
|
46
|
+
189: '-',
|
|
47
|
+
190: '.',
|
|
48
|
+
191: '/',
|
|
49
|
+
192: '`',
|
|
50
|
+
219: '[',
|
|
51
|
+
220: '\\',
|
|
52
|
+
221: ']',
|
|
53
|
+
222: "'",
|
|
54
|
+
};
|
|
55
|
+
export const shift = {
|
|
56
|
+
48: ')',
|
|
57
|
+
49: '!',
|
|
58
|
+
50: '@',
|
|
59
|
+
51: '#',
|
|
60
|
+
52: '$',
|
|
61
|
+
53: '%',
|
|
62
|
+
54: '^',
|
|
63
|
+
55: '&',
|
|
64
|
+
56: '*',
|
|
65
|
+
57: '(',
|
|
66
|
+
59: ':',
|
|
67
|
+
61: '+',
|
|
68
|
+
173: '_',
|
|
69
|
+
186: ':',
|
|
70
|
+
187: '+',
|
|
71
|
+
188: '<',
|
|
72
|
+
189: '_',
|
|
73
|
+
190: '>',
|
|
74
|
+
191: '?',
|
|
75
|
+
192: '~',
|
|
76
|
+
219: '{',
|
|
77
|
+
220: '|',
|
|
78
|
+
221: '}',
|
|
79
|
+
222: '"',
|
|
80
|
+
};
|
|
81
|
+
const mac = typeof navigator != 'undefined' && /Mac/.test(navigator.platform);
|
|
82
|
+
const ie = typeof navigator != 'undefined' &&
|
|
83
|
+
/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);
|
|
84
|
+
// Fill in the digit keys
|
|
85
|
+
for (let i = 0; i < 10; i++)
|
|
86
|
+
base[48 + i] = base[96 + i] = String(i);
|
|
87
|
+
// The function keys
|
|
88
|
+
for (let i = 1; i <= 24; i++)
|
|
89
|
+
base[i + 111] = 'F' + i;
|
|
90
|
+
// And the alphabetic keys
|
|
91
|
+
for (let i = 65; i <= 90; i++) {
|
|
92
|
+
base[i] = String.fromCharCode(i + 32);
|
|
93
|
+
shift[i] = String.fromCharCode(i);
|
|
94
|
+
}
|
|
95
|
+
// For each code that doesn't have a shift-equivalent, copy the base name
|
|
96
|
+
for (const code in base) {
|
|
97
|
+
if (!shift.hasOwnProperty(code))
|
|
98
|
+
shift[code] = base[code];
|
|
99
|
+
}
|
|
100
|
+
export function keyName(event) {
|
|
101
|
+
// On macOS, keys held with Shift and Cmd don't reflect the effect of Shift in `.key`.
|
|
102
|
+
// On IE, shift effect is never included in `.key`.
|
|
103
|
+
const ignoreKey = mac && event.metaKey && event.shiftKey && !event.ctrlKey && !event.altKey ||
|
|
104
|
+
ie && event.shiftKey && event.key && event.key.length == 1 ||
|
|
105
|
+
event.key == 'Unidentified';
|
|
106
|
+
let name = (!ignoreKey && event.key) ||
|
|
107
|
+
(event.shiftKey ? shift : base)[event.keyCode] ||
|
|
108
|
+
event.key || 'Unidentified';
|
|
109
|
+
// Edge sometimes produces wrong names (Issue #3)
|
|
110
|
+
if (name == 'Esc')
|
|
111
|
+
name = 'Escape';
|
|
112
|
+
if (name == 'Del')
|
|
113
|
+
name = 'Delete';
|
|
114
|
+
// https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8860571/
|
|
115
|
+
if (name == 'Left')
|
|
116
|
+
name = 'ArrowLeft';
|
|
117
|
+
if (name == 'Up')
|
|
118
|
+
name = 'ArrowUp';
|
|
119
|
+
if (name == 'Right')
|
|
120
|
+
name = 'ArrowRight';
|
|
121
|
+
if (name == 'Down')
|
|
122
|
+
name = 'ArrowDown';
|
|
123
|
+
return name;
|
|
124
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Node as ProseMirrorNode, ParseOptions } from 'prosemirror-model';
|
|
2
|
+
import type { Extension } from './Extension.js';
|
|
3
|
+
import type { Mark } from './Mark.js';
|
|
4
|
+
import type { Node } from './Node.js';
|
|
5
|
+
export type AnyExtension = Extension | Node | Mark;
|
|
6
|
+
export type AnyExtensionOrReq = AnyExtension | {
|
|
7
|
+
requires: Array<AnyExtensionOrReq | string>;
|
|
8
|
+
};
|
|
9
|
+
export type Content = JSONContent | JSONContent[] | null;
|
|
10
|
+
export interface EditorOptions {
|
|
11
|
+
element: HTMLElement;
|
|
12
|
+
content: Content;
|
|
13
|
+
parseOptions: ParseOptions;
|
|
14
|
+
extensions: AnyExtensionOrReq[];
|
|
15
|
+
topNode?: string;
|
|
16
|
+
}
|
|
17
|
+
export type JSONContent = {
|
|
18
|
+
type?: string;
|
|
19
|
+
attrs?: Record<string, any>;
|
|
20
|
+
content?: JSONContent[];
|
|
21
|
+
marks?: {
|
|
22
|
+
type: string;
|
|
23
|
+
attrs?: Record<string, any>;
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
}[];
|
|
26
|
+
text?: string;
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
};
|
|
29
|
+
export type Attribute<T> = {
|
|
30
|
+
fromDom?: (element: HTMLElement) => T;
|
|
31
|
+
default: T;
|
|
32
|
+
toDom?: (node: ProseMirrorNode) => T;
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/editor/src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,IAAI,eAAe,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC;AACnD,MAAM,MAAM,iBAAiB,GAAG,YAAY,GAAG;IAC7C,QAAQ,EAAE,KAAK,CAAC,iBAAiB,GAAG,MAAM,CAAC,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG,WAAW,GAAG,WAAW,EAAE,GAAG,IAAI,CAAC;AAEzD,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,WAAW,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,YAAY,CAAC;IAC3B,UAAU,EAAE,iBAAiB,EAAE,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,OAAO,CAAC,EAAE,WAAW,EAAE,CAAC;IACxB,KAAK,CAAC,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,EAAE,CAAC;IACJ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IACzB,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,CAAC,CAAC;IACtC,OAAO,EAAE,CAAC,CAAC;IACX,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,CAAC,CAAC;CACtC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface OutputMeta<K> {
|
|
2
|
+
rowPos: number;
|
|
3
|
+
colPos: number;
|
|
4
|
+
item: K;
|
|
5
|
+
}
|
|
6
|
+
interface Mapping {
|
|
7
|
+
sourceNo: number;
|
|
8
|
+
sourceRowPos: number;
|
|
9
|
+
sourceColPos: number;
|
|
10
|
+
}
|
|
11
|
+
export interface SourceMap {
|
|
12
|
+
'version': 3;
|
|
13
|
+
'file': string;
|
|
14
|
+
'sourceRoot': string;
|
|
15
|
+
'sources': Array<string>;
|
|
16
|
+
'sourcesContent': Array<string>;
|
|
17
|
+
'names': Array<string>;
|
|
18
|
+
'mappings': string;
|
|
19
|
+
}
|
|
20
|
+
export declare class SmartOutput<K> {
|
|
21
|
+
private _rowPos;
|
|
22
|
+
private _colPos;
|
|
23
|
+
private chunks;
|
|
24
|
+
private metas;
|
|
25
|
+
log(text: string, item: K): void;
|
|
26
|
+
get chunkPos(): number;
|
|
27
|
+
rollback(pos: number): void;
|
|
28
|
+
get rowPos(): number;
|
|
29
|
+
get colPos(): number;
|
|
30
|
+
endsWith(text: string): boolean;
|
|
31
|
+
toString(): string;
|
|
32
|
+
getSourceMap(mapper: (item: K, rowPos: number, colPos: number) => Mapping | void): SourceMap;
|
|
33
|
+
}
|
|
34
|
+
/** @param {string} string */
|
|
35
|
+
export declare function decode(string: any): number[];
|
|
36
|
+
/** @param {number | number[]} value */
|
|
37
|
+
export declare function encode(value: any): string;
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=SmartOutput.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SmartOutput.d.ts","sourceRoot":"","sources":["../../../../src/editor/src/utilities/SmartOutput.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,CAAC,CAAC;CACT;AAED,UAAU,OAAO;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,CAAC,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACzB,gBAAgB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAChC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,WAAW,CAAC,CAAC;IACxB,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,OAAO,CAAK;IAEpB,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,KAAK,CAA4B;IAEzC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAiBzB,IAAI,QAAQ,WAEX;IAED,QAAQ,CAAC,GAAG,EAAE,MAAM;IAKpB,IAAI,MAAM,WAET;IAED,IAAI,MAAM,WAET;IAED,QAAQ,CAAC,IAAI,EAAE,MAAM;IAIrB,QAAQ;IAIR,YAAY,CACV,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,GAAG,IAAI,GAClE,SAAS;CAuDb;AA0DD,6BAA6B;AAC7B,wBAAgB,MAAM,CAAC,MAAM,KAAA,YAqC5B;AAED,uCAAuC;AACvC,wBAAgB,MAAM,CAAC,KAAK,KAAA,UAW3B"}
|