@kerebron/extension-basic-editor 0.9.2 → 0.9.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 (84) hide show
  1. package/esm/ExtensionSelection.d.ts +14 -0
  2. package/esm/ExtensionSelection.js.map +1 -1
  3. package/esm/ExtensionTextAlign.d.ts +12 -0
  4. package/esm/ExtensionTextAlign.js.map +1 -1
  5. package/esm/ExtensionUser.d.ts +10 -0
  6. package/esm/ExtensionUser.js.map +1 -1
  7. package/esm/MarkCode.d.ts +6 -0
  8. package/esm/MarkCode.js.map +1 -1
  9. package/esm/MarkItalic.d.ts +6 -0
  10. package/esm/MarkItalic.js.map +1 -1
  11. package/esm/MarkStrike.d.ts +6 -0
  12. package/esm/MarkStrike.js.map +1 -1
  13. package/esm/MarkStrong.d.ts +6 -0
  14. package/esm/MarkStrong.js.map +1 -1
  15. package/esm/MarkSubscript.d.ts +6 -0
  16. package/esm/MarkSubscript.js.map +1 -1
  17. package/esm/MarkSuperscript.d.ts +6 -0
  18. package/esm/MarkSuperscript.js.map +1 -1
  19. package/esm/MarkUnderline.d.ts +6 -0
  20. package/esm/MarkUnderline.js.map +1 -1
  21. package/esm/NodeBlockquote.d.ts +6 -0
  22. package/esm/NodeBlockquote.js.map +1 -1
  23. package/esm/NodeCodeBlock.d.ts +12 -2
  24. package/esm/NodeCodeBlock.js +35 -7
  25. package/esm/NodeCodeBlock.js.map +1 -1
  26. package/esm/NodeCommentAnchor.d.ts +11 -0
  27. package/esm/NodeCommentAnchor.js.map +1 -1
  28. package/esm/NodeDefinitionList.d.ts +6 -0
  29. package/esm/NodeDefinitionList.js.map +1 -1
  30. package/esm/NodeDocument.d.ts +22 -0
  31. package/esm/NodeDocument.js.map +1 -1
  32. package/esm/NodeHardBreak.d.ts +6 -0
  33. package/esm/NodeHardBreak.js.map +1 -1
  34. package/esm/NodeHeading.d.ts +16 -0
  35. package/esm/NodeHeading.js.map +1 -1
  36. package/esm/NodeHorizontalRule.d.ts +6 -0
  37. package/esm/NodeHorizontalRule.js.map +1 -1
  38. package/esm/NodeInlineShortCode.d.ts +11 -1
  39. package/esm/NodeInlineShortCode.js.map +1 -1
  40. package/esm/NodeParagraph.d.ts +6 -0
  41. package/esm/NodeParagraph.js.map +1 -1
  42. package/esm/lists/NodeBulletList.d.ts +6 -0
  43. package/esm/lists/NodeBulletList.js.map +1 -1
  44. package/esm/lists/NodeListItem.d.ts +10 -0
  45. package/esm/lists/NodeListItem.js.map +1 -1
  46. package/esm/lists/NodeOrderedList.d.ts +6 -0
  47. package/esm/lists/NodeOrderedList.js.map +1 -1
  48. package/esm/lists/NodeTaskItem.d.ts +10 -0
  49. package/esm/lists/NodeTaskItem.js.map +1 -1
  50. package/esm/lists/NodeTaskList.d.ts +6 -0
  51. package/esm/lists/NodeTaskList.js.map +1 -1
  52. package/esm/media/ExtensionPaste.d.ts +16 -0
  53. package/esm/media/ExtensionPaste.js +2 -2
  54. package/esm/media/ExtensionPaste.js.map +1 -1
  55. package/esm/pairing/PairNodesPlugin.js +4 -2
  56. package/esm/pairing/PairNodesPlugin.js.map +1 -1
  57. package/package.json +18 -5
  58. package/src/ExtensionSelection.ts +19 -0
  59. package/src/ExtensionTextAlign.ts +13 -0
  60. package/src/ExtensionUser.ts +11 -0
  61. package/src/MarkCode.ts +7 -0
  62. package/src/MarkItalic.ts +7 -0
  63. package/src/MarkStrike.ts +7 -0
  64. package/src/MarkStrong.ts +7 -0
  65. package/src/MarkSubscript.ts +7 -0
  66. package/src/MarkSuperscript.ts +7 -0
  67. package/src/MarkUnderline.ts +7 -0
  68. package/src/NodeBlockquote.ts +7 -0
  69. package/src/NodeCodeBlock.ts +56 -9
  70. package/src/NodeCommentAnchor.ts +12 -0
  71. package/src/NodeDefinitionList.ts +8 -4
  72. package/src/NodeDocument.ts +23 -0
  73. package/src/NodeHardBreak.ts +7 -0
  74. package/src/NodeHeading.ts +17 -0
  75. package/src/NodeHorizontalRule.ts +8 -0
  76. package/src/NodeInlineShortCode.ts +16 -0
  77. package/src/NodeParagraph.ts +7 -0
  78. package/src/lists/NodeBulletList.ts +7 -0
  79. package/src/lists/NodeListItem.ts +11 -0
  80. package/src/lists/NodeOrderedList.ts +8 -0
  81. package/src/lists/NodeTaskItem.ts +11 -0
  82. package/src/lists/NodeTaskList.ts +9 -2
  83. package/src/media/ExtensionPaste.ts +19 -2
  84. package/src/pairing/PairNodesPlugin.ts +4 -2
@@ -4,6 +4,29 @@ import { CoreEditor, Node } from '@kerebron/editor';
4
4
  import { CommandFactories, CommandFactory } from '@kerebron/editor/commands';
5
5
  import { EditorState, Transaction } from 'prosemirror-state';
6
6
 
7
+ declare module '@kerebron/editor/commands' {
8
+ interface Commands<ReturnType = any> {
9
+ /**
10
+ * Read the document's `meta` attribute.
11
+ *
12
+ * @param cb Called with a structured clone of the current `meta` value.
13
+ */
14
+ getMeta: (cb: (meta: any) => void) => ReturnType;
15
+ /**
16
+ * Replace the document's `meta` attribute.
17
+ *
18
+ * @param meta New `meta` value.
19
+ */
20
+ setMeta: (meta: any) => ReturnType;
21
+ /**
22
+ * Update the document's `meta` attribute in place.
23
+ *
24
+ * @param updater Receives the current `meta`, returns the new one.
25
+ */
26
+ updateMeta: (updater: (meta: unknown) => unknown) => ReturnType;
27
+ }
28
+ }
29
+
7
30
  export class NodeDocument extends Node {
8
31
  override name = 'doc';
9
32
 
@@ -8,6 +8,13 @@ import {
8
8
  type CommandShortcuts,
9
9
  } from '@kerebron/editor/commands';
10
10
 
11
+ declare module '@kerebron/editor/commands' {
12
+ interface Commands<ReturnType = any> {
13
+ /** Replace the selection with a hard break (`br`) node. */
14
+ setHardBreak: () => ReturnType;
15
+ }
16
+ }
17
+
11
18
  export class NodeHardBreak extends Node {
12
19
  override name = 'br';
13
20
  requires = ['doc'];
@@ -10,6 +10,23 @@ import {
10
10
  textblockTypeInputRule,
11
11
  } from '@kerebron/editor/plugins/input-rules';
12
12
 
13
+ declare module '@kerebron/editor/commands' {
14
+ interface Commands<ReturnType = any> {
15
+ /** Set the textblock type to a level-1 heading. */
16
+ setHeading1: () => ReturnType;
17
+ /** Set the textblock type to a level-2 heading. */
18
+ setHeading2: () => ReturnType;
19
+ /** Set the textblock type to a level-3 heading. */
20
+ setHeading3: () => ReturnType;
21
+ /** Set the textblock type to a level-4 heading. */
22
+ setHeading4: () => ReturnType;
23
+ /** Set the textblock type to a level-5 heading. */
24
+ setHeading5: () => ReturnType;
25
+ /** Set the textblock type to a level-6 heading. */
26
+ setHeading6: () => ReturnType;
27
+ }
28
+ }
29
+
13
30
  const maxLevel = 6;
14
31
 
15
32
  export class NodeHeading extends Node {
@@ -1,10 +1,18 @@
1
1
  import type { NodeSpec, NodeType } from 'prosemirror-model';
2
+
2
3
  import { type CoreEditor, Node } from '@kerebron/editor';
3
4
  import type {
4
5
  CommandFactories,
5
6
  CommandShortcuts,
6
7
  } from '@kerebron/editor/commands';
7
8
 
9
+ declare module '@kerebron/editor/commands' {
10
+ interface Commands<ReturnType = any> {
11
+ /** Replace the selection with a horizontal rule (`hr`) node, scrolling into view. */
12
+ setHorizontalRule: () => ReturnType;
13
+ }
14
+ }
15
+
8
16
  export class NodeHorizontalRule extends Node {
9
17
  override name = 'hr';
10
18
  requires = ['doc'];
@@ -13,6 +13,22 @@ import {
13
13
  replaceInlineNode,
14
14
  } from '@kerebron/editor/plugins/input-rules';
15
15
 
16
+ declare module '@kerebron/editor/commands' {
17
+ interface Commands<ReturnType = any> {
18
+ /**
19
+ * Replace every `shortcode_inline` node in the document.
20
+ *
21
+ * @param createReplacementNode Builds the replacement node for each match.
22
+ */
23
+ renderShortCode: (
24
+ createReplacementNode: (
25
+ oldNode: PmNode,
26
+ schema: Schema,
27
+ ) => PmNode,
28
+ ) => ReturnType;
29
+ }
30
+ }
31
+
16
32
  export function fixCharacters(text: string) {
17
33
  return text
18
34
  .replace(/’/g, "'")
@@ -5,6 +5,13 @@ import {
5
5
  type CommandShortcuts,
6
6
  } from '@kerebron/editor/commands';
7
7
 
8
+ declare module '@kerebron/editor/commands' {
9
+ interface Commands<ReturnType = any> {
10
+ /** Set the textblock type to a paragraph. */
11
+ setParagraph: () => ReturnType;
12
+ }
13
+ }
14
+
8
15
  export type TextAlign = 'left' | 'center' | 'right' | 'justify' | undefined;
9
16
 
10
17
  export class NodeParagraph extends Node {
@@ -11,6 +11,13 @@ import {
11
11
  } from '@kerebron/editor/plugins/input-rules';
12
12
  import { toggleList } from './commands.js';
13
13
 
14
+ declare module '@kerebron/editor/commands' {
15
+ interface Commands<ReturnType = any> {
16
+ /** Toggle a bullet list around the selection. */
17
+ toggleBulletList: () => ReturnType;
18
+ }
19
+ }
20
+
14
21
  export class NodeBulletList extends Node {
15
22
  override name = 'bullet_list';
16
23
  requires = ['doc'];
@@ -11,6 +11,17 @@ import {
11
11
  } from '@kerebron/editor/utilities';
12
12
  import { liftListItem, sinkListItem, splitListItem } from './commands.js';
13
13
 
14
+ declare module '@kerebron/editor/commands' {
15
+ interface Commands<ReturnType = any> {
16
+ /** Split the current list item at the cursor (Enter). */
17
+ splitListItem: () => ReturnType;
18
+ /** Lift the list item, decreasing nesting (Shift-Tab). */
19
+ liftListItem: () => ReturnType;
20
+ /** Increase nesting of the list item (Tab). */
21
+ sinkListItem: () => ReturnType;
22
+ }
23
+ }
24
+
14
25
  export class NodeListItem extends Node {
15
26
  override name = 'list_item';
16
27
  requires = ['doc'];
@@ -14,8 +14,16 @@ import {
14
14
  type CommandFactories,
15
15
  type CommandShortcuts,
16
16
  } from '@kerebron/editor/commands';
17
+
17
18
  import { toggleList } from './commands.js';
18
19
 
20
+ declare module '@kerebron/editor/commands' {
21
+ interface Commands<ReturnType = any> {
22
+ /** Toggle an ordered list around the selection. */
23
+ toggleOrderedList: () => ReturnType;
24
+ }
25
+ }
26
+
19
27
  export class NodeOrderedList extends Node {
20
28
  override name = 'ordered_list';
21
29
  requires = ['doc'];
@@ -10,6 +10,17 @@ import { liftListItem, sinkListItem, splitListItem } from './commands.js';
10
10
  import { NodeViewConstructor } from '@kerebron/editor/DummyEditorView';
11
11
  import { NodeViewTaskItem } from './NodeViewTaskItem.js';
12
12
 
13
+ declare module '@kerebron/editor/commands' {
14
+ interface Commands<ReturnType = any> {
15
+ /** Split the current task item at the cursor (Enter). */
16
+ splitListItem: () => ReturnType;
17
+ /** Lift the task item, decreasing nesting (Shift-Tab). */
18
+ liftListItem: () => ReturnType;
19
+ /** Increase nesting of the task item (Tab). */
20
+ sinkListItem: () => ReturnType;
21
+ }
22
+ }
23
+
13
24
  export interface TaskItemOptions {
14
25
  onReadOnlyChecked?: (node: PmNode, checked: boolean) => boolean;
15
26
  nested: boolean;
@@ -1,12 +1,19 @@
1
- import type { NodeSpec, NodeType } from 'prosemirror-model';
1
+ import type { NodeSpec } from 'prosemirror-model';
2
2
 
3
- import { type CoreEditor, Node } from '@kerebron/editor';
3
+ import { Node } from '@kerebron/editor';
4
4
  import {
5
5
  type CommandFactories,
6
6
  type CommandShortcuts,
7
7
  } from '@kerebron/editor/commands';
8
8
  import { toggleList } from './commands.js';
9
9
 
10
+ declare module '@kerebron/editor/commands' {
11
+ interface Commands<ReturnType = any> {
12
+ /** Toggle a task list around the selection. */
13
+ toggleTaskList: () => ReturnType;
14
+ }
15
+ }
16
+
10
17
  export class NodeTaskList extends Node {
11
18
  override name = 'task_list';
12
19
  requires = ['doc'];
@@ -15,6 +15,23 @@ import { elementFromString } from './ExtensionHtml.js';
15
15
  import { YamlService } from '@kerebron/editor/yaml';
16
16
  import { BlankFrontmatterServiceImpl } from '@kerebron/editor/frontmatter';
17
17
 
18
+ declare module '@kerebron/editor/commands' {
19
+ interface Commands<ReturnType = any> {
20
+ /**
21
+ * Read the currently registered paste rules.
22
+ *
23
+ * @param cb Called with the active paste rules.
24
+ */
25
+ getPasteRules: (cb: (pasteRules: PasteRule[]) => void) => ReturnType;
26
+ /**
27
+ * Replace the plugin's active paste rules.
28
+ *
29
+ * @param pasteRules The new paste rules.
30
+ */
31
+ setPasteRules: (pasteRules: PasteRule[]) => ReturnType;
32
+ }
33
+ }
34
+
18
35
  type PasteRuleStep =
19
36
  | PasteRuleStepDefault
20
37
  | PasteRuleStepReplaceTag
@@ -121,7 +138,7 @@ class PasteState {
121
138
  let replaceDocument = false;
122
139
 
123
140
  const metaOps: any[] = [];
124
- const yaml = editor.ci.resolve('yaml') as YamlService;
141
+ const yaml = editor.di.resolve('yaml') as YamlService;
125
142
 
126
143
  for (const rule of this.pasteRules) {
127
144
  if ('string' === typeof rule.match) {
@@ -277,7 +294,7 @@ export class ExtensionPaste extends Extension {
277
294
 
278
295
  (async () => {
279
296
  if (!(cloned.state.selection instanceof AllSelection)) {
280
- cloned.ci.register(
297
+ cloned.di.register(
281
298
  'frontmatter',
282
299
  new BlankFrontmatterServiceImpl(),
283
300
  );
@@ -14,7 +14,9 @@ export const createPairingPlugin = (types: string[]) => {
14
14
  for (const tr of transactions) {
15
15
  if (!tr.docChanged) continue;
16
16
 
17
- for (const step of tr.steps) {
17
+ for (let idx = 0; idx < tr.steps.length; idx++) {
18
+ const step = tr.steps[idx];
19
+ const doc = tr.docs[idx];
18
20
  if (
19
21
  !(step instanceof ReplaceStep || step instanceof ReplaceAroundStep)
20
22
  ) {
@@ -30,7 +32,7 @@ export const createPairingPlugin = (types: string[]) => {
30
32
  }
31
33
 
32
34
  if (step.from != null && step.to != null && step.from !== step.to) {
33
- oldState.doc.nodesBetween(step.from, step.to, (node) => {
35
+ doc.nodesBetween(step.from, step.to, (node) => {
34
36
  if (types.includes(node.type.name)) {
35
37
  typesToRebuild.add(node.type.name);
36
38
  }