@kerebron/editor 0.5.2 → 0.5.4

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 (52) hide show
  1. package/assets/base.css +114 -0
  2. package/assets/content.css +70 -0
  3. package/assets/gapcursor.css +25 -0
  4. package/assets/index-light.css +2 -0
  5. package/assets/index.css +3 -0
  6. package/assets/main.css +8 -0
  7. package/assets/mobile.css +33 -0
  8. package/assets/prosemirror.css +20 -0
  9. package/assets/search.css +6 -0
  10. package/assets/vars-dark.css +39 -0
  11. package/assets/vars.css +73 -0
  12. package/esm/CoreEditor.d.ts +8 -1
  13. package/esm/CoreEditor.d.ts.map +1 -1
  14. package/esm/CoreEditor.js +20 -14
  15. package/esm/CoreEditor.js.map +1 -1
  16. package/esm/DummyEditorView.d.ts.map +1 -1
  17. package/esm/DummyEditorView.js +4 -2
  18. package/esm/DummyEditorView.js.map +1 -1
  19. package/esm/ExtensionManager.d.ts +2 -2
  20. package/esm/ExtensionManager.d.ts.map +1 -1
  21. package/esm/ExtensionManager.js +10 -3
  22. package/esm/ExtensionManager.js.map +1 -1
  23. package/esm/commands/CommandManager.d.ts.map +1 -1
  24. package/esm/commands/types.d.ts +4 -1
  25. package/esm/commands/types.d.ts.map +1 -1
  26. package/esm/plugins/input-rules/InputRulesPlugin.js +6 -6
  27. package/esm/plugins/input-rules/InputRulesPlugin.js.map +1 -1
  28. package/esm/plugins/input-rules/rulebuilders.d.ts.map +1 -1
  29. package/esm/plugins/input-rules/rulebuilders.js +5 -1
  30. package/esm/plugins/input-rules/rulebuilders.js.map +1 -1
  31. package/esm/plugins/keymap/w3c-keyname.d.ts.map +1 -1
  32. package/esm/plugins/keymap/w3c-keyname.js +2 -1
  33. package/esm/plugins/keymap/w3c-keyname.js.map +1 -1
  34. package/esm/types.d.ts +4 -0
  35. package/esm/types.d.ts.map +1 -1
  36. package/esm/types.js +3 -1
  37. package/esm/types.js.map +1 -1
  38. package/esm/utilities/SmartOutput.d.ts +2 -0
  39. package/esm/utilities/SmartOutput.d.ts.map +1 -1
  40. package/esm/utilities/SmartOutput.js +28 -0
  41. package/esm/utilities/SmartOutput.js.map +1 -1
  42. package/package.json +3 -2
  43. package/src/CoreEditor.ts +33 -15
  44. package/src/DummyEditorView.ts +5 -2
  45. package/src/ExtensionManager.ts +10 -4
  46. package/src/commands/CommandManager.ts +1 -1
  47. package/src/commands/types.ts +13 -1
  48. package/src/plugins/input-rules/InputRulesPlugin.ts +7 -7
  49. package/src/plugins/input-rules/rulebuilders.ts +7 -9
  50. package/src/plugins/keymap/w3c-keyname.ts +3 -1
  51. package/src/types.ts +5 -0
  52. package/src/utilities/SmartOutput.ts +30 -0
@@ -49,9 +49,7 @@ export class ExtensionManager {
49
49
 
50
50
  public converters: Record<string, Converter> = {};
51
51
 
52
- private debug = true;
53
-
54
- constructor(public readonly editorKits: EditorKit[]) {
52
+ constructor(public readonly editorKits: EditorKit[], private debug = false) {
55
53
  const extensions: AnyExtensionOrReq[] = editorKits
56
54
  .reduce(
57
55
  (prev: AnyExtensionOrReq[], cur) => prev.concat(cur.getExtensions()),
@@ -192,6 +190,12 @@ export class ExtensionManager {
192
190
  const createMap = (extensions: Set<AnyExtensionOrReq>) => {
193
191
  for (const extension of extensions) {
194
192
  if ('name' in extension) {
193
+ const existing = allExtensions.get(extension.name);
194
+ if (
195
+ existing && 'type' in existing && extension.type !== existing.type
196
+ ) {
197
+ throw new Error(`Duplicate mark/node: ${extension.name}`);
198
+ }
195
199
  allExtensions.set(extension.name, extension);
196
200
  }
197
201
  if ('requires' in extension) {
@@ -208,7 +212,9 @@ export class ExtensionManager {
208
212
  const initialized: Set<string> = new Set();
209
213
 
210
214
  const initializeExtension = (extension: AnyExtension) => {
211
- console.info(`Initialize ${extension.type} ${extension.name}`);
215
+ if (this.debug) {
216
+ console.info(`Initialize ${extension.type} ${extension.name}`);
217
+ }
212
218
  this.extensions.add(extension);
213
219
  };
214
220
 
@@ -1,5 +1,5 @@
1
1
  import { EditorView } from 'prosemirror-view';
2
- import type { EditorState, Transaction } from 'prosemirror-state';
2
+ import type { Transaction } from 'prosemirror-state';
3
3
 
4
4
  import type { CoreEditor } from '../CoreEditor.js';
5
5
  import { createChainableState } from './createChainableState.js';
@@ -1,4 +1,9 @@
1
- import type { Command as PmCommand } from 'prosemirror-state';
1
+ import type {
2
+ Command as PmCommand,
3
+ EditorState,
4
+ Transaction,
5
+ } from 'prosemirror-state';
6
+ import { EditorView } from 'prosemirror-view';
2
7
 
3
8
  interface Command extends PmCommand {
4
9
  displayName?: string;
@@ -9,6 +14,13 @@ export type { Command };
9
14
 
10
15
  export type CommandFactory = (...args: any[]) => Command;
11
16
 
17
+ export type AsyncCommand = (
18
+ state: EditorState,
19
+ dispatch?: (tr: Transaction) => void,
20
+ view?: EditorView,
21
+ ) => Promise<boolean>;
22
+ export type AsyncCommandFactory = (...args: any[]) => AsyncCommand;
23
+
12
24
  export interface Commands {
13
25
  [name: string]: Command;
14
26
  }
@@ -205,8 +205,6 @@ export const runInputRulesTexts: CommandFactory = () => {
205
205
 
206
206
  let text = node.text;
207
207
 
208
- // throw new Error('aaaaaaaaaaa');
209
-
210
208
  if (node.type.spec.code) {
211
209
  if (!rule.inCode) continue;
212
210
  } else if (rule.inCode === 'only') {
@@ -217,14 +215,16 @@ export const runInputRulesTexts: CommandFactory = () => {
217
215
  continue;
218
216
  }
219
217
 
220
- const from = pos;
221
- const to = pos + node.nodeSize;
218
+ const index = match.index;
219
+
220
+ const from = pos + index;
221
+ const to = pos + index + match[0].length;
222
222
 
223
223
  let subTr = rule.handler(
224
224
  tr,
225
225
  state,
226
226
  match,
227
- from - (match[0].length - text.length),
227
+ from,
228
228
  to,
229
229
  );
230
230
  if (!subTr) continue;
@@ -238,11 +238,11 @@ export const runInputRulesTexts: CommandFactory = () => {
238
238
  }
239
239
  }
240
240
 
241
- if (dispatch && tr.docChanged) {
241
+ if (dispatch) {
242
242
  dispatch(tr);
243
243
  }
244
244
 
245
- return true;
245
+ return tr.docChanged;
246
246
  };
247
247
 
248
248
  cmd.displayName = 'runInputRulesTexts';
@@ -1,12 +1,5 @@
1
- import { canJoin, findWrapping, replaceStep } from 'prosemirror-transform';
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';
12
5
  import { Command } from '../../commands/types.js';
@@ -120,6 +113,11 @@ export function replaceInlineNode(
120
113
 
121
114
  const attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs;
122
115
 
116
+ const $pos = state.doc.resolve(start);
117
+ if ($pos.parent.type === state.schema.nodes.code_block) {
118
+ return tr;
119
+ }
120
+
123
121
  const node = nodeType.createAndFill(attrs);
124
122
 
125
123
  const from = tr.mapping.map(start);
@@ -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 (!shift.hasOwnProperty(code)) shift[code] = base[code];
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) {
package/src/types.ts CHANGED
@@ -3,6 +3,10 @@ import type { Extension } from './Extension.js';
3
3
  import type { Mark } from './Mark.js';
4
4
  import type { Node } from './Node.js';
5
5
 
6
+ export const NESTING_OPENING = 1;
7
+ export const NESTING_SELF_CLOSING = 0;
8
+ export const NESTING_CLOSING = -1;
9
+
6
10
  export interface EditorKit {
7
11
  getExtensions(): AnyExtensionOrReq[];
8
12
  }
@@ -55,6 +59,7 @@ export interface UrlRewriteContext {
55
59
  type: 'IMG' | 'A';
56
60
  dest: string; // Dest format, eg: kerebron, md, odt
57
61
  filesMap?: Record<string, Uint8Array>;
62
+ setMeta?: (key: string, val: string) => void;
58
63
  }
59
64
 
60
65
  export type UrlRewriter = (
@@ -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;
@@ -79,6 +90,25 @@ export class SmartOutput<K> {
79
90
  return this._pos;
80
91
  }
81
92
 
93
+ backspace(count: number) {
94
+ const metasToRestore: Array<OutputMeta<K>> = [];
95
+ const chunksToRestore: Array<string> = [];
96
+ while (count > 0 && this.chunks[0].length > 0) {
97
+ const lastMeta = this.metas.pop();
98
+ let lastChunk = this.chunks.pop();
99
+ if (!lastChunk || !lastMeta) {
100
+ break;
101
+ }
102
+ const origLen = lastChunk.length;
103
+ lastChunk = lastChunk.substring(0, Math.max(0, lastChunk.length - count));
104
+ metasToRestore.unshift(lastMeta);
105
+ chunksToRestore.unshift(lastChunk);
106
+ count -= origLen - lastChunk.length;
107
+ }
108
+ this.chunks.push(...chunksToRestore);
109
+ this.metas.push(...metasToRestore);
110
+ }
111
+
82
112
  endsWith(text: string) {
83
113
  return this.chunks.join('').endsWith(text);
84
114
  }