@kerebron/extension-basic-editor 0.0.1

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 (70) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +31 -0
  3. package/esm/ExtensionBaseKeymap.d.ts +8 -0
  4. package/esm/ExtensionBaseKeymap.d.ts.map +1 -0
  5. package/esm/ExtensionBaseKeymap.js +37 -0
  6. package/esm/ExtensionBasicEditor.d.ts +26 -0
  7. package/esm/ExtensionBasicEditor.d.ts.map +1 -0
  8. package/esm/ExtensionBasicEditor.js +59 -0
  9. package/esm/ExtensionDropcursor.d.ts +12 -0
  10. package/esm/ExtensionDropcursor.d.ts.map +1 -0
  11. package/esm/ExtensionDropcursor.js +28 -0
  12. package/esm/ExtensionGapcursor.d.ts +12 -0
  13. package/esm/ExtensionGapcursor.d.ts.map +1 -0
  14. package/esm/ExtensionGapcursor.js +28 -0
  15. package/esm/ExtensionHistory.d.ts +14 -0
  16. package/esm/ExtensionHistory.d.ts.map +1 -0
  17. package/esm/ExtensionHistory.js +49 -0
  18. package/esm/MarkCode.d.ts +14 -0
  19. package/esm/MarkCode.d.ts.map +1 -0
  20. package/esm/MarkCode.js +45 -0
  21. package/esm/MarkItalic.d.ts +13 -0
  22. package/esm/MarkItalic.d.ts.map +1 -0
  23. package/esm/MarkItalic.js +51 -0
  24. package/esm/MarkLink.d.ts +18 -0
  25. package/esm/MarkLink.d.ts.map +1 -0
  26. package/esm/MarkLink.js +74 -0
  27. package/esm/MarkStrong.d.ts +14 -0
  28. package/esm/MarkStrong.d.ts.map +1 -0
  29. package/esm/MarkStrong.js +60 -0
  30. package/esm/MarkUnderline.d.ts +13 -0
  31. package/esm/MarkUnderline.d.ts.map +1 -0
  32. package/esm/MarkUnderline.js +55 -0
  33. package/esm/NodeAside.d.ts +11 -0
  34. package/esm/NodeAside.d.ts.map +1 -0
  35. package/esm/NodeAside.js +37 -0
  36. package/esm/NodeBlockquote.d.ts +16 -0
  37. package/esm/NodeBlockquote.d.ts.map +1 -0
  38. package/esm/NodeBlockquote.js +56 -0
  39. package/esm/NodeBulletList.d.ts +16 -0
  40. package/esm/NodeBulletList.d.ts.map +1 -0
  41. package/esm/NodeBulletList.js +56 -0
  42. package/esm/NodeDocument.d.ts +7 -0
  43. package/esm/NodeDocument.d.ts.map +1 -0
  44. package/esm/NodeDocument.js +26 -0
  45. package/esm/NodeHardBreak.d.ts +11 -0
  46. package/esm/NodeHardBreak.d.ts.map +1 -0
  47. package/esm/NodeHardBreak.js +98 -0
  48. package/esm/NodeHeading.d.ts +24 -0
  49. package/esm/NodeHeading.d.ts.map +1 -0
  50. package/esm/NodeHeading.js +75 -0
  51. package/esm/NodeHorizontalRule.d.ts +11 -0
  52. package/esm/NodeHorizontalRule.d.ts.map +1 -0
  53. package/esm/NodeHorizontalRule.js +43 -0
  54. package/esm/NodeImage.d.ts +25 -0
  55. package/esm/NodeImage.d.ts.map +1 -0
  56. package/esm/NodeImage.js +68 -0
  57. package/esm/NodeListItem.d.ts +13 -0
  58. package/esm/NodeListItem.d.ts.map +1 -0
  59. package/esm/NodeListItem.js +217 -0
  60. package/esm/NodeOrderedList.d.ts +22 -0
  61. package/esm/NodeOrderedList.d.ts.map +1 -0
  62. package/esm/NodeOrderedList.js +72 -0
  63. package/esm/NodeParagraph.d.ts +14 -0
  64. package/esm/NodeParagraph.d.ts.map +1 -0
  65. package/esm/NodeParagraph.js +47 -0
  66. package/esm/NodeText.d.ts +8 -0
  67. package/esm/NodeText.d.ts.map +1 -0
  68. package/esm/NodeText.js +23 -0
  69. package/esm/package.json +3 -0
  70. package/package.json +78 -0
@@ -0,0 +1,60 @@
1
+ import { Mark } from '@kerebron/editor';
2
+ import { toggleMark, } from '@kerebron/editor/commands';
3
+ export class MarkStrong extends Mark {
4
+ constructor() {
5
+ super(...arguments);
6
+ Object.defineProperty(this, "name", {
7
+ enumerable: true,
8
+ configurable: true,
9
+ writable: true,
10
+ value: 'strong'
11
+ });
12
+ Object.defineProperty(this, "requires", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: ['doc']
17
+ });
18
+ Object.defineProperty(this, "automerge", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: {
23
+ markName: 'strong',
24
+ }
25
+ });
26
+ }
27
+ getMarkSpec() {
28
+ return {
29
+ parseDOM: [
30
+ { tag: 'strong' },
31
+ // This works around a Google Docs misbehavior where
32
+ // pasted content will be inexplicably wrapped in `<b>`
33
+ // tags with a font-weight normal.
34
+ {
35
+ tag: 'b',
36
+ getAttrs: (node) => node.style.fontWeight != 'normal' && null,
37
+ },
38
+ { style: 'font-weight=400', clearMark: (m) => m.type.name == 'strong' },
39
+ {
40
+ style: 'font-weight',
41
+ getAttrs: (value) => /^(bold(er)?|[5-9]\d{2,})$/.test(value) && null,
42
+ },
43
+ ],
44
+ toDOM() {
45
+ return ['strong', 0];
46
+ },
47
+ };
48
+ }
49
+ getCommands(editor, type) {
50
+ return {
51
+ 'toggleStrong': () => toggleMark(type),
52
+ };
53
+ }
54
+ getKeyboardShortcuts() {
55
+ return {
56
+ 'Mod-b': 'toggleStrong',
57
+ 'Mod-B': 'toggleStrong',
58
+ };
59
+ }
60
+ }
@@ -0,0 +1,13 @@
1
+ import { CoreEditor, Mark } from '@kerebron/editor';
2
+ import { Commands, CommandShortcuts } from '@kerebron/editor/commands';
3
+ export declare class MarkUnderline extends Mark {
4
+ name: string;
5
+ requires: string[];
6
+ automerge: {
7
+ markName: string;
8
+ };
9
+ getMarkSpec(): MarkSpec;
10
+ getCommands(editor: CoreEditor, type: MarkType): Partial<Commands>;
11
+ getKeyboardShortcuts(): Partial<CommandShortcuts>;
12
+ }
13
+ //# sourceMappingURL=MarkUnderline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MarkUnderline.d.ts","sourceRoot":"","sources":["../src/MarkUnderline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EACL,QAAQ,EACR,gBAAgB,EAEjB,MAAM,2BAA2B,CAAC;AAEnC,qBAAa,aAAc,SAAQ,IAAI;IAC5B,IAAI,SAAe;IAC5B,QAAQ,WAAW;IAEnB,SAAS;;MAEP;IAEF,WAAW,IAAI,QAAQ;IAoBvB,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAMlE,oBAAoB,IAAI,OAAO,CAAC,gBAAgB,CAAC;CAMlD"}
@@ -0,0 +1,55 @@
1
+ import { Mark } from '@kerebron/editor';
2
+ import { toggleMark, } from '@kerebron/editor/commands';
3
+ export class MarkUnderline extends Mark {
4
+ constructor() {
5
+ super(...arguments);
6
+ Object.defineProperty(this, "name", {
7
+ enumerable: true,
8
+ configurable: true,
9
+ writable: true,
10
+ value: 'underline'
11
+ });
12
+ Object.defineProperty(this, "requires", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: ['doc']
17
+ });
18
+ Object.defineProperty(this, "automerge", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: {
23
+ markName: 'u',
24
+ }
25
+ });
26
+ }
27
+ getMarkSpec() {
28
+ return {
29
+ parseDOM: [
30
+ {
31
+ tag: 'u',
32
+ },
33
+ {
34
+ style: 'text-decoration',
35
+ consuming: false,
36
+ getAttrs: (style) => (style.includes('underline') ? {} : false),
37
+ },
38
+ ],
39
+ toDOM() {
40
+ return ['u', 0];
41
+ },
42
+ };
43
+ }
44
+ getCommands(editor, type) {
45
+ return {
46
+ 'toggleUnderline': () => toggleMark(type),
47
+ };
48
+ }
49
+ getKeyboardShortcuts() {
50
+ return {
51
+ 'Mod-u': 'toggleUnderline',
52
+ 'Mod-U': 'toggleUnderline',
53
+ };
54
+ }
55
+ }
@@ -0,0 +1,11 @@
1
+ import { NodeSpec } from 'prosemirror-model';
2
+ import { Node } from '@kerebron/editor';
3
+ export declare class NodeAside extends Node {
4
+ name: string;
5
+ requires: string[];
6
+ automerge: {
7
+ block: string;
8
+ };
9
+ getNodeSpec(): NodeSpec;
10
+ }
11
+ //# sourceMappingURL=NodeAside.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NodeAside.d.ts","sourceRoot":"","sources":["../src/NodeAside.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC,qBAAa,SAAU,SAAQ,IAAI;IACxB,IAAI,SAAW;IACxB,QAAQ,WAAW;IAEnB,SAAS;;MAEP;IAEO,WAAW,IAAI,QAAQ;CAWjC"}
@@ -0,0 +1,37 @@
1
+ import { Node } from '@kerebron/editor';
2
+ export class NodeAside extends Node {
3
+ constructor() {
4
+ super(...arguments);
5
+ Object.defineProperty(this, "name", {
6
+ enumerable: true,
7
+ configurable: true,
8
+ writable: true,
9
+ value: 'aside'
10
+ });
11
+ Object.defineProperty(this, "requires", {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value: ['doc']
16
+ });
17
+ Object.defineProperty(this, "automerge", {
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true,
21
+ value: {
22
+ block: 'aside',
23
+ }
24
+ });
25
+ }
26
+ getNodeSpec() {
27
+ return {
28
+ content: 'block+',
29
+ group: 'block',
30
+ defining: true,
31
+ parseDOM: [{ tag: 'aside' }],
32
+ toDOM() {
33
+ return ['aside', 0];
34
+ },
35
+ };
36
+ }
37
+ }
@@ -0,0 +1,16 @@
1
+ import { NodeSpec, NodeType } from 'prosemirror-model';
2
+ import { Node } from '@kerebron/editor';
3
+ import { type Commands, type CommandShortcuts } from '@kerebron/editor/commands';
4
+ import { InputRule } from '@kerebron/editor/plugins/input-rules';
5
+ export declare class NodeBlockquote extends Node {
6
+ name: string;
7
+ requires: string[];
8
+ automerge: {
9
+ block: string;
10
+ };
11
+ getNodeSpec(): NodeSpec;
12
+ getInputRules(type: NodeType): InputRule[];
13
+ getCommands(editor: CoreEditor, type: NodeType): Partial<Commands>;
14
+ getKeyboardShortcuts(): Partial<CommandShortcuts>;
15
+ }
16
+ //# sourceMappingURL=NodeBlockquote.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NodeBlockquote.d.ts","sourceRoot":"","sources":["../src/NodeBlockquote.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,gBAAgB,EAEtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,SAAS,EAEV,MAAM,sCAAsC,CAAC;AAE9C,qBAAa,cAAe,SAAQ,IAAI;IAC7B,IAAI,SAAgB;IAC7B,QAAQ,WAAW;IAEnB,SAAS;;MAEP;IAEO,WAAW,IAAI,QAAQ;IAYvB,aAAa,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,EAAE;IAQnD,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAMlE,oBAAoB,IAAI,OAAO,CAAC,gBAAgB,CAAC;CAKlD"}
@@ -0,0 +1,56 @@
1
+ import { Node } from '@kerebron/editor';
2
+ import { wrapInList, } from '@kerebron/editor/commands';
3
+ import { wrappingInputRule, } from '@kerebron/editor/plugins/input-rules';
4
+ export class NodeBlockquote extends Node {
5
+ constructor() {
6
+ super(...arguments);
7
+ Object.defineProperty(this, "name", {
8
+ enumerable: true,
9
+ configurable: true,
10
+ writable: true,
11
+ value: 'blockquote'
12
+ });
13
+ Object.defineProperty(this, "requires", {
14
+ enumerable: true,
15
+ configurable: true,
16
+ writable: true,
17
+ value: ['doc']
18
+ });
19
+ Object.defineProperty(this, "automerge", {
20
+ enumerable: true,
21
+ configurable: true,
22
+ writable: true,
23
+ value: {
24
+ block: 'blockquote',
25
+ }
26
+ });
27
+ }
28
+ getNodeSpec() {
29
+ return {
30
+ content: 'block+',
31
+ group: 'block',
32
+ defining: true,
33
+ parseDOM: [{ tag: 'blockquote' }],
34
+ toDOM() {
35
+ return ['blockquote', 0];
36
+ },
37
+ };
38
+ }
39
+ getInputRules(type) {
40
+ return [
41
+ /// Given a blockquote node type, returns an input rule that turns `"> "`
42
+ /// at the start of a textblock into a blockquote.
43
+ wrappingInputRule(/^\s*>\s$/, type),
44
+ ];
45
+ }
46
+ getCommands(editor, type) {
47
+ return {
48
+ 'toggleBlockquote': () => wrapInList(type),
49
+ };
50
+ }
51
+ getKeyboardShortcuts() {
52
+ return {
53
+ 'Ctrl->': 'toggleBlockquote',
54
+ };
55
+ }
56
+ }
@@ -0,0 +1,16 @@
1
+ import { NodeSpec, NodeType } from 'prosemirror-model';
2
+ import { CoreEditor, Node } from '@kerebron/editor';
3
+ import { type Commands, type CommandShortcuts } from '@kerebron/editor/commands';
4
+ import { type InputRule } from '@kerebron/editor/plugins/input-rules';
5
+ export declare class NodeBulletList extends Node {
6
+ name: string;
7
+ requires: string[];
8
+ getNodeSpec(): NodeSpec;
9
+ getInputRules(type: NodeType): InputRule[];
10
+ getCommands(editor: CoreEditor, type: NodeType): Partial<Commands>;
11
+ getKeyboardShortcuts(): Partial<CommandShortcuts>;
12
+ automerge: {
13
+ block: string;
14
+ };
15
+ }
16
+ //# sourceMappingURL=NodeBulletList.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NodeBulletList.d.ts","sourceRoot":"","sources":["../src/NodeBulletList.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,gBAAgB,EAEtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,KAAK,SAAS,EAEf,MAAM,sCAAsC,CAAC;AAE9C,qBAAa,cAAe,SAAQ,IAAI;IAC7B,IAAI,SAAiB;IAC9B,QAAQ,WAAW;IAEV,WAAW,IAAI,QAAQ;IAWvB,aAAa,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,EAAE;IASnD,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAMlE,oBAAoB,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAMjD,SAAS;;MAEP;CACH"}
@@ -0,0 +1,56 @@
1
+ import { Node } from '@kerebron/editor';
2
+ import { wrapInList, } from '@kerebron/editor/commands';
3
+ import { wrappingInputRule, } from '@kerebron/editor/plugins/input-rules';
4
+ export class NodeBulletList extends Node {
5
+ constructor() {
6
+ super(...arguments);
7
+ Object.defineProperty(this, "name", {
8
+ enumerable: true,
9
+ configurable: true,
10
+ writable: true,
11
+ value: 'bullet_list'
12
+ });
13
+ Object.defineProperty(this, "requires", {
14
+ enumerable: true,
15
+ configurable: true,
16
+ writable: true,
17
+ value: ['doc']
18
+ });
19
+ Object.defineProperty(this, "automerge", {
20
+ enumerable: true,
21
+ configurable: true,
22
+ writable: true,
23
+ value: {
24
+ block: 'bullet_list',
25
+ }
26
+ });
27
+ }
28
+ getNodeSpec() {
29
+ return {
30
+ content: 'list_item+',
31
+ group: 'block',
32
+ parseDOM: [{ tag: 'ul' }],
33
+ toDOM() {
34
+ return ['ul', 0];
35
+ },
36
+ };
37
+ }
38
+ getInputRules(type) {
39
+ /// Given a list node type, returns an input rule that turns a bullet
40
+ /// (dash, plush, or asterisk) at the start of a textblock into a
41
+ /// bullet list.
42
+ return [
43
+ wrappingInputRule(/^\s*([-+*])\s$/, type),
44
+ ];
45
+ }
46
+ getCommands(editor, type) {
47
+ return {
48
+ 'toggleBulletList': () => wrapInList(type),
49
+ };
50
+ }
51
+ getKeyboardShortcuts() {
52
+ return {
53
+ 'Shift-Ctrl-8': 'toggleBulletList',
54
+ };
55
+ }
56
+ }
@@ -0,0 +1,7 @@
1
+ import { NodeSpec } from 'prosemirror-model';
2
+ import { Node } from '@kerebron/editor';
3
+ export declare class NodeDocument extends Node {
4
+ name: string;
5
+ getNodeSpec(): NodeSpec;
6
+ }
7
+ //# sourceMappingURL=NodeDocument.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NodeDocument.d.ts","sourceRoot":"","sources":["../src/NodeDocument.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAc,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC,qBAAa,YAAa,SAAQ,IAAI;IAC3B,IAAI,SAAS;IAEb,WAAW,IAAI,QAAQ;CAcjC"}
@@ -0,0 +1,26 @@
1
+ import { Node } from '@kerebron/editor';
2
+ export class NodeDocument extends Node {
3
+ constructor() {
4
+ super(...arguments);
5
+ Object.defineProperty(this, "name", {
6
+ enumerable: true,
7
+ configurable: true,
8
+ writable: true,
9
+ value: 'doc'
10
+ });
11
+ }
12
+ getNodeSpec() {
13
+ return {
14
+ content: 'block+',
15
+ EMPTY_DOC: {
16
+ 'type': this.name,
17
+ 'content': [
18
+ {
19
+ 'type': 'paragraph',
20
+ 'content': [],
21
+ },
22
+ ],
23
+ },
24
+ };
25
+ }
26
+ }
@@ -0,0 +1,11 @@
1
+ import type { NodeSpec, NodeType } from 'prosemirror-model';
2
+ import { type CoreEditor, Node } from '@kerebron/editor';
3
+ import { type Commands, type CommandShortcuts } from '@kerebron/editor/commands';
4
+ export declare class NodeHardBreak extends Node {
5
+ name: string;
6
+ requires: string[];
7
+ getNodeSpec(): NodeSpec;
8
+ getCommands(editor: CoreEditor, type: NodeType): Partial<Commands>;
9
+ getKeyboardShortcuts(): Partial<CommandShortcuts>;
10
+ }
11
+ //# sourceMappingURL=NodeHardBreak.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NodeHardBreak.d.ts","sourceRoot":"","sources":["../src/NodeHardBreak.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,KAAK,UAAU,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,gBAAgB,EAEtB,MAAM,2BAA2B,CAAC;AAEnC,qBAAa,aAAc,SAAQ,IAAI;IAC5B,IAAI,SAAQ;IACrB,QAAQ,WAAW;IAEV,WAAW,IAAI,QAAQ;IAkBvB,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAoDlE,oBAAoB,IAAI,OAAO,CAAC,gBAAgB,CAAC;CAiB3D"}
@@ -0,0 +1,98 @@
1
+ import { Node } from '@kerebron/editor';
2
+ import { exitCode, } from '@kerebron/editor/commands';
3
+ export class NodeHardBreak extends Node {
4
+ constructor() {
5
+ super(...arguments);
6
+ Object.defineProperty(this, "name", {
7
+ enumerable: true,
8
+ configurable: true,
9
+ writable: true,
10
+ value: 'br'
11
+ });
12
+ Object.defineProperty(this, "requires", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: ['doc']
17
+ });
18
+ // TODO automerge
19
+ }
20
+ getNodeSpec() {
21
+ return {
22
+ inline: true,
23
+ group: 'inline',
24
+ selectable: false,
25
+ linebreakReplacement: true,
26
+ parseDOM: [{ tag: 'br' }],
27
+ toDOM() {
28
+ return ['br'];
29
+ },
30
+ };
31
+ }
32
+ /*if (!exitCode(view.state, view.dispatch)) return false
33
+ view.focus()
34
+ return true
35
+ }},*/
36
+ getCommands(editor, type) {
37
+ return {
38
+ // 'first': commands => first(commands),
39
+ 'setHardBreak': () => (state, dispatch) => {
40
+ if (!exitCode(state, dispatch)) {
41
+ return false;
42
+ }
43
+ editor.view.focus();
44
+ if (dispatch) {
45
+ dispatch(state.tr.replaceSelectionWith(type.create()).scrollIntoView());
46
+ }
47
+ return true;
48
+ },
49
+ // const commands = editor.commands;
50
+ // return commands.first([
51
+ // () => commands.exitCode(),
52
+ // () => commands.command(() => {
53
+ // const { selection, storedMarks } = state
54
+ //
55
+ // if (selection.$from.parent.type.spec.isolating) {
56
+ // return false
57
+ // }
58
+ //
59
+ // const { keepMarks } = this.options
60
+ // const { splittableMarks } = editor.extensionManager
61
+ // const marks = storedMarks
62
+ // || (selection.$to.parentOffset && selection.$from.marks())
63
+ //
64
+ // return chain()
65
+ // .insertContent({ type: this.name })
66
+ // .command(({ tr, dispatch }) => {
67
+ // if (dispatch && marks && keepMarks) {
68
+ // const filteredMarks = marks
69
+ // .filter(mark => splittableMarks.includes(mark.type.name))
70
+ //
71
+ // tr.ensureMarks(filteredMarks)
72
+ // }
73
+ //
74
+ // return true
75
+ // })
76
+ // .run()
77
+ // }),
78
+ // ])
79
+ // chainCommands(exitCode, (state, dispatch) => {
80
+ // if (dispatch) dispatch(state.tr.replaceSelectionWith(br.create()).scrollIntoView())
81
+ // return true
82
+ // })
83
+ };
84
+ }
85
+ getKeyboardShortcuts() {
86
+ const mac = typeof navigator != 'undefined'
87
+ ? /Mac|iP(hone|[oa]d)/.test(navigator.platform)
88
+ : false;
89
+ const shortcuts = {
90
+ 'Ctrl-Enter': 'setHardBreak',
91
+ };
92
+ if (mac) {
93
+ shortcuts['Mod-Enter'] = 'setHardBreak';
94
+ shortcuts['Shift-Enter'] = 'setHardBreak';
95
+ }
96
+ return shortcuts;
97
+ }
98
+ }
@@ -0,0 +1,24 @@
1
+ import { NodeSpec, NodeType } from 'prosemirror-model';
2
+ import { type CoreEditor, Node } from '@kerebron/editor';
3
+ import { type Commands, type CommandShortcuts } from '@kerebron/editor/commands';
4
+ import { type InputRule } from '@kerebron/editor/plugins/input-rules';
5
+ export declare class NodeHeading extends Node {
6
+ name: string;
7
+ requires: string[];
8
+ automerge: {
9
+ block: string;
10
+ attrParsers: {
11
+ fromAutomerge: (block: any) => {
12
+ level: any;
13
+ };
14
+ fromProsemirror: (node: any) => {
15
+ level: any;
16
+ };
17
+ };
18
+ };
19
+ getNodeSpec(): NodeSpec;
20
+ getInputRules(type: NodeType): InputRule[];
21
+ getCommands(editor: CoreEditor, type: NodeType): Partial<Commands>;
22
+ getKeyboardShortcuts(): Partial<CommandShortcuts>;
23
+ }
24
+ //# sourceMappingURL=NodeHeading.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NodeHeading.d.ts","sourceRoot":"","sources":["../src/NodeHeading.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,KAAK,UAAU,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,gBAAgB,EAEtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,KAAK,SAAS,EAEf,MAAM,sCAAsC,CAAC;AAI9C,qBAAa,WAAY,SAAQ,IAAI;IAC1B,IAAI,SAAa;IAC1B,QAAQ,WAAW;IAEnB,SAAS;;;;;;;;;;MAMP;IAEO,WAAW,IAAI,QAAQ;IAoBvB,aAAa,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,EAAE;IAc1C,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAUlE,oBAAoB,IAAI,OAAO,CAAC,gBAAgB,CAAC;CAS3D"}
@@ -0,0 +1,75 @@
1
+ import { Node } from '@kerebron/editor';
2
+ import { setBlockType, } from '@kerebron/editor/commands';
3
+ import { textblockTypeInputRule, } from '@kerebron/editor/plugins/input-rules';
4
+ const maxLevel = 6;
5
+ export class NodeHeading extends Node {
6
+ constructor() {
7
+ super(...arguments);
8
+ Object.defineProperty(this, "name", {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value: 'heading'
13
+ });
14
+ Object.defineProperty(this, "requires", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: ['doc']
19
+ });
20
+ Object.defineProperty(this, "automerge", {
21
+ enumerable: true,
22
+ configurable: true,
23
+ writable: true,
24
+ value: {
25
+ block: 'heading',
26
+ attrParsers: {
27
+ fromAutomerge: (block) => ({ level: block.attrs.level }),
28
+ fromProsemirror: (node) => ({ level: node.attrs.level }),
29
+ },
30
+ }
31
+ });
32
+ }
33
+ getNodeSpec() {
34
+ return {
35
+ attrs: { level: { default: 1 } },
36
+ content: 'inline*',
37
+ group: 'block',
38
+ defining: true,
39
+ parseDOM: [
40
+ { tag: 'h1', attrs: { level: 1 } },
41
+ { tag: 'h2', attrs: { level: 2 } },
42
+ { tag: 'h3', attrs: { level: 3 } },
43
+ { tag: 'h4', attrs: { level: 4 } },
44
+ { tag: 'h5', attrs: { level: 5 } },
45
+ { tag: 'h6', attrs: { level: 6 } },
46
+ ],
47
+ toDOM(node) {
48
+ return ['h' + node.attrs.level, 0];
49
+ },
50
+ };
51
+ }
52
+ getInputRules(type) {
53
+ /// Given a node type and a maximum level, creates an input rule that
54
+ /// turns up to that number of `#` characters followed by a space at
55
+ /// the start of a textblock into a heading whose level corresponds to
56
+ /// the number of `#` signs.
57
+ return [
58
+ textblockTypeInputRule(new RegExp('^(#{1,' + maxLevel + '})\\s$'), type, (match) => ({ level: match[1].length })),
59
+ ];
60
+ }
61
+ getCommands(editor, type) {
62
+ const commands = {};
63
+ for (let i = 1; i <= maxLevel; i++) {
64
+ commands['setHeading' + i] = () => setBlockType(type, { level: i });
65
+ }
66
+ return commands;
67
+ }
68
+ getKeyboardShortcuts() {
69
+ const keys = {};
70
+ for (let i = 1; i <= maxLevel; i++) {
71
+ keys['Shift-Ctrl-' + i] = 'setHeading' + i;
72
+ }
73
+ return keys;
74
+ }
75
+ }
@@ -0,0 +1,11 @@
1
+ import { NodeSpec, NodeType } from 'prosemirror-model';
2
+ import { CoreEditor, Node } from '@kerebron/editor';
3
+ import { Commands, CommandShortcuts } from '@kerebron/editor/commands';
4
+ export declare class NodeHorizontalRule extends Node {
5
+ name: string;
6
+ requires: string[];
7
+ getNodeSpec(): NodeSpec;
8
+ getCommands(editor: CoreEditor, type: NodeType): Partial<Commands>;
9
+ getKeyboardShortcuts(): Partial<CommandShortcuts>;
10
+ }
11
+ //# sourceMappingURL=NodeHorizontalRule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NodeHorizontalRule.d.ts","sourceRoot":"","sources":["../src/NodeHorizontalRule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAEvE,qBAAa,kBAAmB,SAAQ,IAAI;IACjC,IAAI,SAAQ;IACrB,QAAQ,WAAW;IAEV,WAAW,IAAI,QAAQ;IAUvB,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAalE,oBAAoB,IAAI,OAAO,CAAC,gBAAgB,CAAC;CAO3D"}
@@ -0,0 +1,43 @@
1
+ import { Node } from '@kerebron/editor';
2
+ export class NodeHorizontalRule extends Node {
3
+ constructor() {
4
+ super(...arguments);
5
+ Object.defineProperty(this, "name", {
6
+ enumerable: true,
7
+ configurable: true,
8
+ writable: true,
9
+ value: 'hr'
10
+ });
11
+ Object.defineProperty(this, "requires", {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value: ['doc']
16
+ });
17
+ // TODO automerge
18
+ }
19
+ getNodeSpec() {
20
+ return {
21
+ group: 'block',
22
+ parseDOM: [{ tag: 'hr' }],
23
+ toDOM() {
24
+ return ['hr'];
25
+ },
26
+ };
27
+ }
28
+ getCommands(editor, type) {
29
+ return {
30
+ 'setHorizontalRule': () => (state, dispatch) => {
31
+ if (dispatch) {
32
+ dispatch(state.tr.replaceSelectionWith(type.create()).scrollIntoView());
33
+ }
34
+ return true;
35
+ },
36
+ };
37
+ }
38
+ getKeyboardShortcuts() {
39
+ return {
40
+ 'Mod-_': 'setHorizontalRule',
41
+ };
42
+ }
43
+ }