@kerebron/editor 0.5.1 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/base.css +114 -0
- package/assets/content.css +70 -0
- package/assets/gapcursor.css +25 -0
- package/assets/index-light.css +2 -0
- package/assets/index.css +3 -0
- package/assets/main.css +8 -0
- package/assets/mobile.css +33 -0
- package/assets/prosemirror.css +20 -0
- package/assets/search.css +6 -0
- package/assets/vars-dark.css +39 -0
- package/assets/vars.css +73 -0
- package/esm/CoreEditor.d.ts.map +1 -1
- package/esm/CoreEditor.js +20 -13
- package/esm/CoreEditor.js.map +1 -1
- package/esm/DummyEditorView.d.ts.map +1 -1
- package/esm/DummyEditorView.js +4 -2
- package/esm/DummyEditorView.js.map +1 -1
- package/esm/Extension.d.ts +1 -1
- package/esm/Extension.d.ts.map +1 -1
- package/esm/Extension.js.map +1 -1
- package/esm/ExtensionManager.d.ts.map +1 -1
- package/esm/ExtensionManager.js +1 -3
- package/esm/ExtensionManager.js.map +1 -1
- package/esm/plugins/TrackSelecionPlugin.d.ts.map +1 -1
- package/esm/plugins/TrackSelecionPlugin.js +2 -1
- package/esm/plugins/TrackSelecionPlugin.js.map +1 -1
- package/esm/plugins/input-rules/InputRulesPlugin.d.ts.map +1 -1
- package/esm/plugins/input-rules/InputRulesPlugin.js +13 -10
- package/esm/plugins/input-rules/InputRulesPlugin.js.map +1 -1
- package/esm/plugins/input-rules/rulebuilders.d.ts +2 -0
- package/esm/plugins/input-rules/rulebuilders.d.ts.map +1 -1
- package/esm/plugins/input-rules/rulebuilders.js +20 -1
- package/esm/plugins/input-rules/rulebuilders.js.map +1 -1
- package/esm/plugins/keymap/keymap.d.ts.map +1 -1
- package/esm/plugins/keymap/keymap.js +5 -2
- package/esm/plugins/keymap/keymap.js.map +1 -1
- package/esm/plugins/keymap/w3c-keyname.d.ts.map +1 -1
- package/esm/plugins/keymap/w3c-keyname.js +2 -1
- package/esm/plugins/keymap/w3c-keyname.js.map +1 -1
- package/esm/utilities/SmartOutput.d.ts +1 -0
- package/esm/utilities/SmartOutput.d.ts.map +1 -1
- package/esm/utilities/SmartOutput.js +10 -0
- package/esm/utilities/SmartOutput.js.map +1 -1
- package/package.json +3 -2
- package/src/CoreEditor.ts +22 -14
- package/src/DummyEditorView.ts +5 -2
- package/src/Extension.ts +1 -1
- package/src/ExtensionManager.ts +1 -3
- package/src/plugins/TrackSelecionPlugin.ts +2 -1
- package/src/plugins/input-rules/InputRulesPlugin.ts +18 -12
- package/src/plugins/input-rules/rulebuilders.ts +32 -9
- package/src/plugins/keymap/keymap.ts +5 -2
- package/src/plugins/keymap/w3c-keyname.ts +3 -1
- package/src/utilities/SmartOutput.ts +11 -0
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Node as ProseMirrorNode } from 'prosemirror-model';
|
|
2
2
|
import {
|
|
3
3
|
EditorState,
|
|
4
4
|
Plugin,
|
|
5
|
+
PluginKey,
|
|
5
6
|
TextSelection,
|
|
6
7
|
Transaction,
|
|
7
8
|
} from 'prosemirror-state';
|
|
@@ -116,6 +117,7 @@ function stringHandler(string: string) {
|
|
|
116
117
|
export class InputRulesPlugin extends Plugin<PluginState> {
|
|
117
118
|
constructor(rules: readonly InputRule[]) {
|
|
118
119
|
super({
|
|
120
|
+
key: new PluginKey('input-rules'),
|
|
119
121
|
state: {
|
|
120
122
|
init() {
|
|
121
123
|
return null;
|
|
@@ -203,8 +205,6 @@ export const runInputRulesTexts: CommandFactory = () => {
|
|
|
203
205
|
|
|
204
206
|
let text = node.text;
|
|
205
207
|
|
|
206
|
-
// throw new Error('aaaaaaaaaaa');
|
|
207
|
-
|
|
208
208
|
if (node.type.spec.code) {
|
|
209
209
|
if (!rule.inCode) continue;
|
|
210
210
|
} else if (rule.inCode === 'only') {
|
|
@@ -215,14 +215,16 @@ export const runInputRulesTexts: CommandFactory = () => {
|
|
|
215
215
|
continue;
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
-
const
|
|
219
|
-
|
|
218
|
+
const index = match.index;
|
|
219
|
+
|
|
220
|
+
const from = pos + index;
|
|
221
|
+
const to = pos + index + match[0].length;
|
|
220
222
|
|
|
221
223
|
let subTr = rule.handler(
|
|
222
224
|
tr,
|
|
223
225
|
state,
|
|
224
226
|
match,
|
|
225
|
-
from
|
|
227
|
+
from,
|
|
226
228
|
to,
|
|
227
229
|
);
|
|
228
230
|
if (!subTr) continue;
|
|
@@ -236,11 +238,11 @@ export const runInputRulesTexts: CommandFactory = () => {
|
|
|
236
238
|
}
|
|
237
239
|
}
|
|
238
240
|
|
|
239
|
-
if (dispatch
|
|
241
|
+
if (dispatch) {
|
|
240
242
|
dispatch(tr);
|
|
241
243
|
}
|
|
242
244
|
|
|
243
|
-
return
|
|
245
|
+
return tr.docChanged;
|
|
244
246
|
};
|
|
245
247
|
|
|
246
248
|
cmd.displayName = 'runInputRulesTexts';
|
|
@@ -269,6 +271,7 @@ export const runInputRulesRange: CommandFactory = (
|
|
|
269
271
|
const rules: readonly InputRule[] = plugin.spec.rules;
|
|
270
272
|
|
|
271
273
|
if (view?.composing) return false;
|
|
274
|
+
|
|
272
275
|
const $from = state.doc.resolve(from);
|
|
273
276
|
const textBefore = $from.parent.textBetween(
|
|
274
277
|
Math.max(0, $from.parentOffset - MAX_MATCH),
|
|
@@ -277,6 +280,7 @@ export const runInputRulesRange: CommandFactory = (
|
|
|
277
280
|
'\ufffc',
|
|
278
281
|
) + text;
|
|
279
282
|
let tr = state.tr;
|
|
283
|
+
|
|
280
284
|
for (let i = 0; i < rules.length; i++) {
|
|
281
285
|
const rule = rules[i];
|
|
282
286
|
if ($from.parent.type.spec.code) {
|
|
@@ -293,8 +297,8 @@ export const runInputRulesRange: CommandFactory = (
|
|
|
293
297
|
tr,
|
|
294
298
|
state,
|
|
295
299
|
match,
|
|
296
|
-
from - (match[0].length - text.length),
|
|
297
|
-
to,
|
|
300
|
+
tr.mapping.map(from - (match[0].length - text.length)),
|
|
301
|
+
tr.mapping.map(to),
|
|
298
302
|
);
|
|
299
303
|
if (!subTr) continue;
|
|
300
304
|
|
|
@@ -302,10 +306,12 @@ export const runInputRulesRange: CommandFactory = (
|
|
|
302
306
|
if (rule.undoable) {
|
|
303
307
|
tr.setMeta(plugin, { transform: tr, from, to, text });
|
|
304
308
|
}
|
|
309
|
+
break;
|
|
305
310
|
}
|
|
306
311
|
|
|
307
|
-
if (
|
|
308
|
-
dispatch(tr);
|
|
312
|
+
if (tr.docChanged) {
|
|
313
|
+
dispatch?.(tr);
|
|
314
|
+
return true;
|
|
309
315
|
}
|
|
310
316
|
|
|
311
317
|
return false;
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
Attrs,
|
|
4
|
-
Fragment,
|
|
5
|
-
Node,
|
|
6
|
-
NodeType,
|
|
7
|
-
ResolvedPos,
|
|
8
|
-
Slice,
|
|
9
|
-
} from 'prosemirror-model';
|
|
1
|
+
import { Attrs, Fragment, Node, NodeType } from 'prosemirror-model';
|
|
2
|
+
import { canJoin, findWrapping } from 'prosemirror-transform';
|
|
10
3
|
|
|
11
4
|
import { InputRule } from './InputRulesPlugin.js';
|
|
5
|
+
import { Command } from '../../commands/types.js';
|
|
6
|
+
import { Transaction } from 'prosemirror-state';
|
|
12
7
|
|
|
13
8
|
/// Build an input rule for automatically wrapping a textblock when a
|
|
14
9
|
/// given string is typed. The `regexp` argument is
|
|
@@ -83,6 +78,29 @@ export function textblockTypeInputRule(
|
|
|
83
78
|
});
|
|
84
79
|
}
|
|
85
80
|
|
|
81
|
+
export function commandInputRule(
|
|
82
|
+
regexp: RegExp,
|
|
83
|
+
command: Command,
|
|
84
|
+
getAttrs: Attrs | null | ((match: RegExpMatchArray) => Attrs | null) = null,
|
|
85
|
+
) {
|
|
86
|
+
return new InputRule(regexp, (tr, state, match, start, end) => {
|
|
87
|
+
if (!tr) {
|
|
88
|
+
tr = state.tr;
|
|
89
|
+
}
|
|
90
|
+
const $start = state.doc.resolve(start);
|
|
91
|
+
|
|
92
|
+
const dispatch = (newTr: Transaction) => {
|
|
93
|
+
tr = newTr;
|
|
94
|
+
state = state.apply(tr);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
dispatch(tr.delete(start, end));
|
|
98
|
+
command(state, dispatch);
|
|
99
|
+
|
|
100
|
+
return tr;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
86
104
|
export function replaceInlineNode(
|
|
87
105
|
regexp: RegExp,
|
|
88
106
|
nodeType: NodeType,
|
|
@@ -95,6 +113,11 @@ export function replaceInlineNode(
|
|
|
95
113
|
|
|
96
114
|
const attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs;
|
|
97
115
|
|
|
116
|
+
const $pos = state.doc.resolve(start);
|
|
117
|
+
if ($pos.parent.type === state.schema.nodes.code_block) {
|
|
118
|
+
return tr;
|
|
119
|
+
}
|
|
120
|
+
|
|
98
121
|
const node = nodeType.createAndFill(attrs);
|
|
99
122
|
|
|
100
123
|
const from = tr.mapping.map(start);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Plugin } from 'prosemirror-state';
|
|
1
|
+
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
2
2
|
import { EditorView } from 'prosemirror-view';
|
|
3
3
|
|
|
4
4
|
import type { Command } from '../../commands/types.js';
|
|
@@ -76,7 +76,10 @@ function modifiers(name: string, event: KeyboardEvent, shift = true) {
|
|
|
76
76
|
/// the array get to dispatch first).
|
|
77
77
|
export class KeymapPlugin extends Plugin {
|
|
78
78
|
constructor(bindings: { [key: string]: Command }) {
|
|
79
|
-
super({
|
|
79
|
+
super({
|
|
80
|
+
key: new PluginKey('keymap'),
|
|
81
|
+
props: { handleKeyDown: keydownHandler(bindings) },
|
|
82
|
+
});
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
85
|
|
|
@@ -98,7 +98,9 @@ for (let i = 65; i <= 90; i++) {
|
|
|
98
98
|
|
|
99
99
|
// For each code that doesn't have a shift-equivalent, copy the base name
|
|
100
100
|
for (const code in base) {
|
|
101
|
-
if (!
|
|
101
|
+
if (!Object.prototype.hasOwnProperty.call(shift, code)) {
|
|
102
|
+
shift[code] = base[code];
|
|
103
|
+
}
|
|
102
104
|
}
|
|
103
105
|
|
|
104
106
|
export function keyName(event: KeyboardEvent) {
|
|
@@ -29,6 +29,17 @@ export class SmartOutput<K> {
|
|
|
29
29
|
private chunks: Array<string> = [];
|
|
30
30
|
private metas: Array<OutputMeta<K>> = [];
|
|
31
31
|
|
|
32
|
+
rtrim() {
|
|
33
|
+
if (this.chunks.length === 0) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const lastText = this.chunks[this.chunks.length - 1];
|
|
37
|
+
this.chunks[this.chunks.length - 1] = lastText.replace(/[ \t]+$/, '');
|
|
38
|
+
const delta = lastText.length - this.chunks[this.chunks.length - 1].length;
|
|
39
|
+
this._colPos -= delta;
|
|
40
|
+
this._pos -= delta;
|
|
41
|
+
}
|
|
42
|
+
|
|
32
43
|
log(text: string, item?: K) {
|
|
33
44
|
if (text.length === 0) {
|
|
34
45
|
return;
|