@kerebron/editor 0.4.27 → 0.4.28

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 (110) hide show
  1. package/assets/base.css +114 -0
  2. package/assets/content.css +35 -0
  3. package/assets/gapcursor.css +25 -0
  4. package/assets/index.css +2 -0
  5. package/assets/main.css +8 -0
  6. package/assets/mobile.css +33 -0
  7. package/assets/prosemirror.css +20 -0
  8. package/assets/search.css +6 -0
  9. package/assets/vars.css +110 -0
  10. package/esm/CoreEditor.d.ts +40 -0
  11. package/esm/CoreEditor.d.ts.map +1 -0
  12. package/esm/CoreEditor.js +223 -0
  13. package/esm/DummyEditorView.d.ts +60 -0
  14. package/esm/DummyEditorView.d.ts.map +1 -0
  15. package/esm/DummyEditorView.js +242 -0
  16. package/esm/Extension.d.ts +31 -0
  17. package/esm/Extension.d.ts.map +1 -0
  18. package/esm/Extension.js +34 -0
  19. package/esm/ExtensionManager.d.ts +32 -0
  20. package/esm/ExtensionManager.d.ts.map +1 -0
  21. package/esm/ExtensionManager.js +222 -0
  22. package/esm/Mark.d.ts +23 -0
  23. package/esm/Mark.d.ts.map +1 -0
  24. package/esm/Mark.js +27 -0
  25. package/esm/Node.d.ts +32 -0
  26. package/esm/Node.d.ts.map +1 -0
  27. package/esm/Node.js +36 -0
  28. package/esm/commands/CommandManager.d.ts +24 -0
  29. package/esm/commands/CommandManager.d.ts.map +1 -0
  30. package/esm/commands/CommandManager.js +100 -0
  31. package/esm/commands/baseCommandFactories.d.ts +3 -0
  32. package/esm/commands/baseCommandFactories.d.ts.map +1 -0
  33. package/esm/commands/baseCommandFactories.js +861 -0
  34. package/esm/commands/createChainableState.d.ts +3 -0
  35. package/esm/commands/createChainableState.d.ts.map +1 -0
  36. package/esm/commands/createChainableState.js +29 -0
  37. package/esm/commands/keyCommandFactories.d.ts +3 -0
  38. package/esm/commands/keyCommandFactories.d.ts.map +1 -0
  39. package/esm/commands/keyCommandFactories.js +10 -0
  40. package/esm/commands/mod.d.ts +7 -0
  41. package/esm/commands/mod.d.ts.map +1 -0
  42. package/esm/commands/mod.js +81 -0
  43. package/esm/commands/replaceCommandFactories.d.ts +3 -0
  44. package/esm/commands/replaceCommandFactories.d.ts.map +1 -0
  45. package/esm/commands/replaceCommandFactories.js +94 -0
  46. package/esm/commands/types.d.ts +22 -0
  47. package/esm/commands/types.d.ts.map +1 -0
  48. package/esm/commands/types.js +1 -0
  49. package/esm/mod.d.ts +9 -0
  50. package/esm/mod.d.ts.map +1 -0
  51. package/esm/mod.js +8 -0
  52. package/esm/nodeToTreeString.d.ts +10 -0
  53. package/esm/nodeToTreeString.d.ts.map +1 -0
  54. package/esm/nodeToTreeString.js +74 -0
  55. package/esm/package.json +3 -0
  56. package/esm/plugins/TrackSelecionPlugin.d.ts +6 -0
  57. package/esm/plugins/TrackSelecionPlugin.d.ts.map +1 -0
  58. package/esm/plugins/TrackSelecionPlugin.js +24 -0
  59. package/esm/plugins/input-rules/InputRulesPlugin.d.ts +25 -0
  60. package/esm/plugins/input-rules/InputRulesPlugin.d.ts.map +1 -0
  61. package/esm/plugins/input-rules/InputRulesPlugin.js +168 -0
  62. package/esm/plugins/input-rules/mod.d.ts +3 -0
  63. package/esm/plugins/input-rules/mod.d.ts.map +1 -0
  64. package/esm/plugins/input-rules/mod.js +2 -0
  65. package/esm/plugins/input-rules/rulebuilders.d.ts +6 -0
  66. package/esm/plugins/input-rules/rulebuilders.d.ts.map +1 -0
  67. package/esm/plugins/input-rules/rulebuilders.js +64 -0
  68. package/esm/plugins/keymap/keymap.d.ts +12 -0
  69. package/esm/plugins/keymap/keymap.d.ts.map +1 -0
  70. package/esm/plugins/keymap/keymap.js +125 -0
  71. package/esm/plugins/keymap/mod.d.ts +2 -0
  72. package/esm/plugins/keymap/mod.d.ts.map +1 -0
  73. package/esm/plugins/keymap/mod.js +1 -0
  74. package/esm/plugins/keymap/w3c-keyname.d.ts +4 -0
  75. package/esm/plugins/keymap/w3c-keyname.d.ts.map +1 -0
  76. package/esm/plugins/keymap/w3c-keyname.js +124 -0
  77. package/esm/search/mod.d.ts +3 -0
  78. package/esm/search/mod.d.ts.map +1 -0
  79. package/esm/search/mod.js +2 -0
  80. package/esm/search/query.d.ts +45 -0
  81. package/esm/search/query.d.ts.map +1 -0
  82. package/esm/search/query.js +334 -0
  83. package/esm/search/search.d.ts +32 -0
  84. package/esm/search/search.d.ts.map +1 -0
  85. package/esm/search/search.js +199 -0
  86. package/esm/types.d.ts +59 -0
  87. package/esm/types.d.ts.map +1 -0
  88. package/esm/types.js +1 -0
  89. package/esm/ui.d.ts +15 -0
  90. package/esm/ui.d.ts.map +1 -0
  91. package/esm/ui.js +16 -0
  92. package/esm/utilities/SmartOutput.d.ts +41 -0
  93. package/esm/utilities/SmartOutput.d.ts.map +1 -0
  94. package/esm/utilities/SmartOutput.js +201 -0
  95. package/esm/utilities/createNodeFromContent.d.ts +9 -0
  96. package/esm/utilities/createNodeFromContent.d.ts.map +1 -0
  97. package/esm/utilities/createNodeFromContent.js +32 -0
  98. package/esm/utilities/getHtmlAttributes.d.ts +9 -0
  99. package/esm/utilities/getHtmlAttributes.d.ts.map +1 -0
  100. package/esm/utilities/getHtmlAttributes.js +47 -0
  101. package/esm/utilities/getShadowRoot.d.ts +2 -0
  102. package/esm/utilities/getShadowRoot.d.ts.map +1 -0
  103. package/esm/utilities/getShadowRoot.js +16 -0
  104. package/esm/utilities/mod.d.ts +6 -0
  105. package/esm/utilities/mod.d.ts.map +1 -0
  106. package/esm/utilities/mod.js +5 -0
  107. package/esm/utilities/toRawTextResult.d.ts +3 -0
  108. package/esm/utilities/toRawTextResult.d.ts.map +1 -0
  109. package/esm/utilities/toRawTextResult.js +21 -0
  110. package/package.json +1 -2
@@ -0,0 +1,114 @@
1
+ /* Base editor container */
2
+ .kb-component {
3
+ background: var(--kb-color-surface);
4
+ color: var(--kb-color-text);
5
+ background-clip: padding-box;
6
+ border-radius: var(--kb-radius-md);
7
+ border: 2px solid var(--kb-color-border);
8
+ padding: var(--kb-space-sm) 0;
9
+ margin-bottom: var(--kb-space-lg);
10
+ font-family:
11
+ -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue',
12
+ Arial, sans-serif;
13
+ line-height: 1.5;
14
+ }
15
+
16
+ /* ProseMirror core styles */
17
+ .kb-editor {
18
+ position: relative;
19
+ word-wrap: break-word;
20
+ white-space: pre-wrap;
21
+ -webkit-font-variant-ligatures: none;
22
+ font-variant-ligatures: none;
23
+ padding: var(--kb-space-sm) var(--kb-space-md) var(--kb-space-sm)
24
+ var(--kb-space-lg);
25
+ outline: none;
26
+ font-size: var(--kb-text-base);
27
+ line-height: 1.6;
28
+ }
29
+
30
+ /* Mobile optimization */
31
+ @media (max-width: 767px) {
32
+ .kb-editor {
33
+ padding: var(--kb-space-md);
34
+ font-size: var(--kb-text-base);
35
+ line-height: 1.7;
36
+ }
37
+ }
38
+
39
+ /* Selection styles */
40
+ .kb-editor-hideselection *::selection {
41
+ background: transparent;
42
+ }
43
+
44
+ .kb-editor-hideselection *::-moz-selection {
45
+ background: transparent;
46
+ }
47
+
48
+ .kb-editor-hideselection {
49
+ caret-color: transparent;
50
+ }
51
+
52
+ @keyframes kb-cursor-blink {
53
+ to {
54
+ visibility: hidden;
55
+ }
56
+ }
57
+
58
+ /* Horizontal rule styling */
59
+ .kb-editor hr {
60
+ padding: 0;
61
+ border: none;
62
+ margin: 1em 0;
63
+ height: 2px;
64
+ background-color: var(--kb-color-text);
65
+ }
66
+
67
+ /* Image styles */
68
+ .kb-editor img {
69
+ cursor: default;
70
+ max-width: 100%;
71
+ height: auto;
72
+ }
73
+
74
+ /* Focus states */
75
+ .kb-component:focus-within {
76
+ border-color: var(--kb-color-primary);
77
+ box-shadow: 0 0 0 3px var(--kb-color-focus);
78
+ }
79
+
80
+ /* High contrast mode support */
81
+ @media (prefers-contrast: more) {
82
+ .kb-component {
83
+ border-width: 3px;
84
+ }
85
+
86
+ .ProseMirror-selectednode {
87
+ outline-width: 3px;
88
+ }
89
+ }
90
+
91
+ .kb-lsp__error {
92
+ position: relative;
93
+ display: inline-block;
94
+ padding-bottom: 4px; /* Space for wave */
95
+ }
96
+
97
+ .kb-lsp__error::after {
98
+ content: '';
99
+ position: absolute;
100
+ left: 0;
101
+ right: 0;
102
+ bottom: 6px;
103
+ height: 6px;
104
+ background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 4' preserveAspectRatio='none'%3E%3Cpath d='M0,2 Q5,0 10,2 T20,2' stroke='red' stroke-width='1.5' fill='none'/%3E%3C/svg%3E")
105
+ repeat-x bottom center;
106
+ background-size: 20px 4px;
107
+ }
108
+
109
+ .kb-shortcode-inline {
110
+ background-color: green;
111
+ border-radius: 3px;
112
+ margin: 0 5px 0;
113
+ padding: 4px 10px;
114
+ }
@@ -0,0 +1,35 @@
1
+ /* Typography */
2
+ .kb-editor p {
3
+ margin-bottom: 1em;
4
+ }
5
+
6
+ .kb-editor p:first-child,
7
+ .kb-editor h1:first-child,
8
+ .kb-editor h2:first-child,
9
+ .kb-editor h3:first-child,
10
+ .kb-editor h4:first-child,
11
+ .kb-editor h5:first-child,
12
+ .kb-editor h6:first-child {
13
+ margin-top: var(--kb-space-md);
14
+ }
15
+
16
+ .kb-editor pre {
17
+ white-space: pre-wrap;
18
+ }
19
+
20
+ .kb-editor li {
21
+ position: relative;
22
+ }
23
+
24
+ .kb-editor ul,
25
+ .kb-editor ol {
26
+ padding-left: 30px;
27
+ }
28
+
29
+ .kb-editor blockquote {
30
+ padding-left: 1em;
31
+ border-left: 3px solid var(--kb-color-border);
32
+ margin-left: 0;
33
+ margin-right: 0;
34
+ color: var(--kb-color-text-muted);
35
+ }
@@ -0,0 +1,25 @@
1
+ .kb-gapcursor {
2
+ display: none;
3
+ pointer-events: none;
4
+ position: absolute;
5
+ }
6
+
7
+ .kb-gapcursor:after {
8
+ content: '';
9
+ display: block;
10
+ position: absolute;
11
+ top: -2px;
12
+ width: 20px;
13
+ border-top: 1px solid black;
14
+ animation: ProseMirror-cursor-blink 1.1s steps(2, start) infinite;
15
+ }
16
+
17
+ @keyframes kb-cursor-blink {
18
+ to {
19
+ visibility: hidden;
20
+ }
21
+ }
22
+
23
+ .ProseMirror-focused .kb-gapcursor {
24
+ display: block;
25
+ }
@@ -0,0 +1,2 @@
1
+ @import 'vars.css';
2
+ @import 'main.css';
@@ -0,0 +1,8 @@
1
+ @import 'base.css';
2
+
3
+ @import 'content.css';
4
+ @import 'prosemirror.css';
5
+ @import 'gapcursor.css';
6
+ @import 'search.css';
7
+
8
+ @import 'mobile.css';
@@ -0,0 +1,33 @@
1
+ /* Mobile viewport handling */
2
+ @supports (-webkit-touch-callout: none) {
3
+ /* iOS Safari specific fixes */
4
+ .kb-component {
5
+ -webkit-text-size-adjust: 100%;
6
+ -webkit-font-smoothing: antialiased;
7
+ }
8
+ }
9
+
10
+ /* Selection handles for mobile text selection */
11
+ @media (max-width: 767px) {
12
+ .kb-editor::selection {
13
+ background: rgba(var(--kb-color-primary-rgb), 0.3);
14
+ }
15
+
16
+ .kb-editor::-moz-selection {
17
+ background: rgba(var(--kb-color-primary-rgb), 0.3);
18
+ }
19
+ }
20
+
21
+ /* Print styles */
22
+ @media print {
23
+ .kb-component {
24
+ border: none;
25
+ box-shadow: none;
26
+ margin: 0;
27
+ padding: 0;
28
+ }
29
+
30
+ .kb-editor {
31
+ padding: 0;
32
+ }
33
+ }
@@ -0,0 +1,20 @@
1
+ .ProseMirror-selectednode {
2
+ outline: 2px solid var(--kb-color-primary);
3
+ outline-offset: 2px;
4
+ }
5
+
6
+ /* List item selection styling */
7
+ li.ProseMirror-selectednode {
8
+ outline: none;
9
+ }
10
+
11
+ li.ProseMirror-selectednode:after {
12
+ content: '';
13
+ position: absolute;
14
+ left: -32px;
15
+ right: -2px;
16
+ top: -2px;
17
+ bottom: -2px;
18
+ border: 2px solid var(--kb-color-primary);
19
+ pointer-events: none;
20
+ }
@@ -0,0 +1,6 @@
1
+ .kb-search-match {
2
+ background-color: #ffff0054;
3
+ }
4
+ .kb-active-search-match {
5
+ background-color: #ff6a0054;
6
+ }
@@ -0,0 +1,110 @@
1
+ :root,
2
+ :host {
3
+ /* Spacing System */
4
+ --kb-space-xs: 0.25rem; /* 4px */
5
+ --kb-space-sm: 0.5rem; /* 8px */
6
+ --kb-space-md: 1rem; /* 16px */
7
+ --kb-space-lg: 1.5rem; /* 24px */
8
+ --kb-space-xl: 2rem; /* 32px */
9
+
10
+ /* Typography Scale */
11
+ --kb-text-xs: 0.75rem; /* 12px */
12
+ --kb-text-sm: 0.875rem; /* 14px */
13
+ --kb-text-base: 1rem; /* 16px */
14
+ --kb-text-lg: 1.125rem; /* 18px */
15
+
16
+ /* Touch Targets */
17
+ --kb-touch-target-min: 44px;
18
+ --kb-touch-target-comfortable: 48px;
19
+
20
+ /* Interactive States */
21
+ --kb-color-hover: rgba(59, 130, 246, 0.05);
22
+ --kb-color-active: rgba(59, 130, 246, 0.1);
23
+ --kb-color-focus: rgba(59, 130, 246, 0.2);
24
+
25
+ /* Layout & Borders */
26
+ --kb-radius-sm: 4px;
27
+ --kb-radius-md: 6px;
28
+ --kb-radius-lg: 8px;
29
+ --kb-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
30
+ --kb-shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
31
+ --kb-shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
32
+
33
+ /* Z-index Scale */
34
+ --kb-z-dropdown: 1100;
35
+ --kb-z-tooltip: 1200;
36
+ --kb-z-modal: 1300;
37
+ --kb-z-notification: 1400;
38
+
39
+ /* Brand Colors (Customizable) */
40
+ --kb-color-primary: #3b82f6;
41
+ --kb-color-primary-hover: #2563eb;
42
+ --kb-color-primary-active: #1d4ed8;
43
+ --kb-color-primary-rgb: 59, 130, 246;
44
+ --kb-color-text: #1f2937;
45
+ --kb-color-text-muted: #6b7280;
46
+ --kb-color-surface: #ffffff;
47
+ --kb-color-surface-elevated: #f9fafb;
48
+ --kb-color-surface-hover: rgba(60, 64, 67, 0.08);
49
+ --kb-color-border: #e5e7eb;
50
+ --kb-color-border-strong: #d1d5db;
51
+
52
+ /* Menu specific colors (Google Docs style) - Light mode */
53
+ --kb-menu-dropdown-bg: #ffffff;
54
+ --kb-menu-dropdown-border: #dadce0;
55
+ --kb-menu-dropdown-text: #3c4043;
56
+ --kb-menu-dropdown-hover: rgba(60, 64, 67, 0.08);
57
+ --kb-menu-info-bg: #e8f0fe;
58
+ --kb-menu-info-text: #1967d2;
59
+ }
60
+
61
+ /* Dark mode support */
62
+ @media (prefers-color-scheme: dark) {
63
+ :root,
64
+ :host {
65
+ --kb-color-text: #f9fafb;
66
+ --kb-color-text-muted: #9ca3af;
67
+ --kb-color-surface: #1f2937;
68
+ --kb-color-surface-elevated: #374151;
69
+ --kb-color-border: #374151;
70
+ --kb-color-border-strong: #4b5563;
71
+ --kb-color-hover: rgba(59, 130, 246, 0.1);
72
+ --kb-color-active: rgba(59, 130, 246, 0.2);
73
+
74
+ /* Menu dropdown - Dark mode */
75
+ --kb-menu-dropdown-bg: #344154;
76
+ --kb-menu-dropdown-border: #5f6368;
77
+ --kb-menu-dropdown-text: #e8eaed;
78
+ --kb-menu-dropdown-hover: rgba(232, 234, 237, 0.08);
79
+ }
80
+ }
81
+
82
+ /* Theme variants */
83
+ .kb-component--brand-corporate {
84
+ --kb-color-primary: #1e40af;
85
+ --kb-color-primary-hover: #1e3a8a;
86
+ --kb-color-primary-rgb: 30, 64, 175;
87
+ }
88
+
89
+ .kb-component--brand-creative {
90
+ --kb-color-primary: #7c3aed;
91
+ --kb-color-primary-hover: #6d28d9;
92
+ --kb-color-primary-rgb: 124, 58, 237;
93
+ }
94
+
95
+ .kb-component--dark {
96
+ --kb-color-text: #f9fafb;
97
+ --kb-color-text-muted: #9ca3af;
98
+ --kb-color-surface: #1f2937;
99
+ --kb-color-surface-elevated: #374151;
100
+ --kb-color-border: #374151;
101
+ --kb-color-border-strong: #4b5563;
102
+ --kb-color-hover: rgba(59, 130, 246, 0.1);
103
+ --kb-color-active: rgba(59, 130, 246, 0.2);
104
+
105
+ /* Menu dropdown - Dark mode */
106
+ --kb-menu-dropdown-bg: #344154;
107
+ --kb-menu-dropdown-border: #5f6368;
108
+ --kb-menu-dropdown-text: #e8eaed;
109
+ --kb-menu-dropdown-hover: rgba(232, 234, 237, 0.08);
110
+ }
@@ -0,0 +1,40 @@
1
+ import { EditorView } from 'prosemirror-view';
2
+ import { Node as ProseMirrorNode, Schema } from 'prosemirror-model';
3
+ import type { EditorConfig, JSONContent } from './types.js';
4
+ import { EditorState, Transaction } from 'prosemirror-state';
5
+ import { DummyEditorView } from './DummyEditorView.js';
6
+ import { ChainedCommands } from './commands/mod.js';
7
+ import { Extension } from './Extension.js';
8
+ import { EditorUi } from './ui.js';
9
+ export declare class CoreEditor extends EventTarget {
10
+ readonly config: Partial<EditorConfig>;
11
+ private extensionManager;
12
+ private commandManager;
13
+ view: EditorView | DummyEditorView;
14
+ state: EditorState;
15
+ ui: EditorUi;
16
+ constructor(config?: Partial<EditorConfig>);
17
+ getExtension<T extends Extension>(name: string): T | undefined;
18
+ get schema(): Schema<any, any>;
19
+ get run(): {
20
+ [key: string]: (...args: any[]) => boolean;
21
+ };
22
+ get commandFactories(): {
23
+ [key: string]: import("./commands/types.js").CommandFactory;
24
+ };
25
+ chain(): ChainedCommands;
26
+ can(): ChainedCommands;
27
+ private createView;
28
+ dispatchTransaction(transaction: Transaction): void;
29
+ private setupPlugins;
30
+ clearDocument(): void;
31
+ setDocument(content: any): void;
32
+ getDocument(): ProseMirrorNode;
33
+ loadDocument(mediaType: string, content: Uint8Array): Promise<void>;
34
+ saveDocument(mediaType: string): Promise<Uint8Array>;
35
+ getJSON(): JSONContent;
36
+ clone(options?: Partial<EditorConfig>): CoreEditor;
37
+ debug(doc?: ProseMirrorNode): void;
38
+ destroy(): void;
39
+ }
40
+ //# sourceMappingURL=CoreEditor.d.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W;IAIL,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU;IA0BnD,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAY1D,OAAO,IAAI,WAAW;IAItB,KAAK,CAAC,OAAO,GAAE,OAAO,CAAC,YAAY,CAAM,GAAG,UAAU;IAOtD,KAAK,CAAC,GAAG,CAAC,EAAE,eAAe;IAO3B,OAAO;CAOf"}
@@ -0,0 +1,223 @@
1
+ import { EditorView } from 'prosemirror-view';
2
+ import { Node as ProseMirrorNode } from 'prosemirror-model';
3
+ import { ExtensionManager } from './ExtensionManager.js';
4
+ import { EditorState } from 'prosemirror-state';
5
+ import { CommandManager } from './commands/CommandManager.js';
6
+ import { nodeToTreeString } from './nodeToTreeString.js';
7
+ import { DummyEditorView } from './DummyEditorView.js';
8
+ import { createNodeFromObject } from './utilities/createNodeFromContent.js';
9
+ import { defaultUi } from './ui.js';
10
+ function ensureDocSchema(doc, schema) {
11
+ if (doc.type.schema === schema) {
12
+ return doc;
13
+ }
14
+ const json = doc.toJSON();
15
+ return ProseMirrorNode.fromJSON(schema, json);
16
+ }
17
+ export class CoreEditor extends EventTarget {
18
+ config = {
19
+ element: undefined,
20
+ extensions: [],
21
+ };
22
+ extensionManager;
23
+ commandManager;
24
+ view;
25
+ state;
26
+ ui = defaultUi(this);
27
+ constructor(config = {}) {
28
+ super();
29
+ this.config = {
30
+ ...this.config,
31
+ ...config,
32
+ };
33
+ this.commandManager = new CommandManager(this);
34
+ this.extensionManager = new ExtensionManager(this.config.extensions || [], this, this.commandManager);
35
+ this.extensionManager.created();
36
+ // const content = this.options.content ? this.options.content : {
37
+ // type: this.extensionManager.schema.topNodeType.name,
38
+ // content: this.extensionManager.schema.topNodeType.spec.EMPTY_DOC,
39
+ // };
40
+ const content = this.config.content
41
+ ? this.config.content
42
+ : this.extensionManager.schema.topNodeType.spec.EMPTY_DOC;
43
+ this.createView(content);
44
+ this.setupPlugins();
45
+ }
46
+ getExtension(name) {
47
+ return this.extensionManager.getExtension(name);
48
+ }
49
+ get schema() {
50
+ return this.extensionManager.schema;
51
+ }
52
+ get run() {
53
+ return this.commandManager.run;
54
+ }
55
+ get commandFactories() {
56
+ return this.commandManager.commandFactories;
57
+ }
58
+ chain() {
59
+ return this.commandManager.createChain();
60
+ }
61
+ can() {
62
+ return this.commandManager.createCan();
63
+ }
64
+ createView(content) {
65
+ const doc = createNodeFromObject(content, this.schema);
66
+ this.state = EditorState.create({ doc });
67
+ if (this.config.element) {
68
+ const view = new EditorView(this.config.element, {
69
+ state: this.state,
70
+ attributes: {
71
+ class: 'kb-editor',
72
+ },
73
+ dispatchTransaction: (tx) => this.dispatchTransaction(tx),
74
+ editable: () => !this.config.readOnly,
75
+ });
76
+ this.view = view;
77
+ const parent = this.config.element.parentNode;
78
+ if (parent) {
79
+ const observer = new MutationObserver((mutations) => {
80
+ for (const mutation of mutations) {
81
+ for (const removedNode of mutation.removedNodes) {
82
+ if (removedNode.contains(view.dom)) {
83
+ // Editor DOM was removed
84
+ observer.disconnect(); // Prevent multiple calls
85
+ view.destroy();
86
+ return;
87
+ }
88
+ }
89
+ }
90
+ });
91
+ }
92
+ }
93
+ else {
94
+ this.view = new DummyEditorView({
95
+ state: this.state,
96
+ dispatchTransaction: (tx) => this.dispatchTransaction(tx),
97
+ });
98
+ }
99
+ const event = new CustomEvent('doc:loaded', {
100
+ detail: {
101
+ editor: this,
102
+ doc,
103
+ },
104
+ });
105
+ this.dispatchEvent(event);
106
+ }
107
+ dispatchTransaction(transaction) {
108
+ this.state = this.state.apply(transaction);
109
+ if (this.view) {
110
+ this.view.updateState(this.state);
111
+ const event = new CustomEvent('transaction', {
112
+ detail: {
113
+ editor: this,
114
+ transaction,
115
+ },
116
+ });
117
+ this.dispatchEvent(event);
118
+ }
119
+ if (transaction.docChanged) {
120
+ const event = new CustomEvent('changed', {
121
+ detail: {
122
+ editor: this,
123
+ },
124
+ });
125
+ this.dispatchEvent(event);
126
+ }
127
+ }
128
+ setupPlugins() {
129
+ this.state = this.state.reconfigure({
130
+ plugins: this.extensionManager.plugins,
131
+ });
132
+ if (this.view) {
133
+ this.view.updateState(this.state);
134
+ this.view.setProps({
135
+ nodeViews: this.extensionManager.nodeViews,
136
+ });
137
+ }
138
+ }
139
+ clearDocument() {
140
+ const content = {
141
+ type: this.extensionManager.schema.topNodeType.name,
142
+ content: this.extensionManager.schema.topNodeType.spec.EMPTY_DOC.content,
143
+ };
144
+ this.setDocument(content);
145
+ }
146
+ setDocument(content) {
147
+ let doc = createNodeFromObject(content, this.schema, {
148
+ errorOnInvalidContent: true,
149
+ });
150
+ doc = ensureDocSchema(doc, this.schema);
151
+ this.state = EditorState.create({
152
+ doc,
153
+ plugins: this.state.plugins,
154
+ storedMarks: this.state.storedMarks,
155
+ });
156
+ if (this.view) {
157
+ this.view.updateState(this.state);
158
+ }
159
+ const event = new CustomEvent('doc:loaded', {
160
+ detail: {
161
+ editor: this,
162
+ doc,
163
+ },
164
+ });
165
+ this.dispatchEvent(event);
166
+ }
167
+ getDocument() {
168
+ return this.state.doc;
169
+ }
170
+ async loadDocument(mediaType, content) {
171
+ const converter = this.extensionManager.converters[mediaType];
172
+ if (!converter) {
173
+ throw new Error('Converter not found for: ' + mediaType);
174
+ }
175
+ const doc = await converter.toDoc(content);
176
+ this.state = EditorState.create({
177
+ doc,
178
+ plugins: this.state.plugins,
179
+ storedMarks: this.state.storedMarks,
180
+ });
181
+ if (this.view) {
182
+ this.view.updateState(this.state);
183
+ }
184
+ const event = new CustomEvent('doc:loaded', {
185
+ detail: {
186
+ editor: this,
187
+ doc,
188
+ },
189
+ });
190
+ this.dispatchEvent(event);
191
+ }
192
+ async saveDocument(mediaType) {
193
+ const converter = this.extensionManager.converters[mediaType];
194
+ if (!converter) {
195
+ throw new Error('Converter not found for: ' + mediaType);
196
+ }
197
+ const json = this.state.doc.toJSON();
198
+ const clonedDoc = ProseMirrorNode.fromJSON(this.state.schema, json);
199
+ return await converter.fromDoc(clonedDoc);
200
+ }
201
+ getJSON() {
202
+ return this.state.doc.toJSON();
203
+ }
204
+ clone(options = {}) {
205
+ return new CoreEditor({
206
+ ...options,
207
+ extensions: [...(Array.from(this.extensionManager.extensions) || [])],
208
+ });
209
+ }
210
+ debug(doc) {
211
+ if (!doc) {
212
+ doc = this.state.doc;
213
+ }
214
+ console.debug(nodeToTreeString(doc));
215
+ }
216
+ destroy() {
217
+ const event = new CustomEvent('beforeDestroy', {
218
+ detail: {},
219
+ });
220
+ this.dispatchEvent(event);
221
+ this.view.destroy();
222
+ }
223
+ }
@@ -0,0 +1,60 @@
1
+ import { EditorState, Plugin, Transaction } from 'prosemirror-state';
2
+ import { Mark, Node } from 'prosemirror-model';
3
+ import { EditorView, MarkView, NodeView } from 'prosemirror-view';
4
+ import { Decoration, DecorationSource } from 'prosemirror-view';
5
+ export declare class DummyEditorView {
6
+ private _props;
7
+ private directPlugins;
8
+ private nodeViews;
9
+ private prevDirectPlugins;
10
+ private pluginViews;
11
+ state: EditorState;
12
+ constructor(props: DirectEditorProps);
13
+ editable: boolean;
14
+ get composing(): boolean;
15
+ get dom(): {
16
+ addEventListener(): void;
17
+ removeEventListener(): void;
18
+ };
19
+ get props(): DirectEditorProps;
20
+ update(props: DirectEditorProps): void;
21
+ setProps(props: Partial<DirectEditorProps>): void;
22
+ updateState(state: EditorState): void;
23
+ private updateStateInner;
24
+ scrollToSelection(): void;
25
+ private destroyPluginViews;
26
+ private updatePluginViews;
27
+ someProp<PropName extends keyof EditorProps, Result>(propName: PropName, f: (value: NonNullable<EditorProps[PropName]>) => Result): Result | undefined;
28
+ someProp<PropName extends keyof EditorProps>(propName: PropName): NonNullable<EditorProps[PropName]> | undefined;
29
+ hasFocus(): boolean;
30
+ focus(): void;
31
+ destroy(): void;
32
+ get isDestroyed(): boolean;
33
+ dispatchEvent(event: Event): void;
34
+ dispatch: (tr: Transaction) => void;
35
+ }
36
+ export type NodeViewConstructor = (node: Node, view: EditorView, getPos: () => number | undefined, decorations: readonly Decoration[], innerDecorations: DecorationSource) => NodeView;
37
+ export type MarkViewConstructor = (mark: Mark, view: EditorView, inline: boolean) => MarkView;
38
+ export interface DOMEventMap extends HTMLElementEventMap {
39
+ [event: string]: any;
40
+ }
41
+ export interface EditorProps<P = any> {
42
+ nodeViews?: {
43
+ [node: string]: NodeViewConstructor;
44
+ };
45
+ markViews?: {
46
+ [mark: string]: MarkViewConstructor;
47
+ };
48
+ editable?: (this: P, state: EditorState) => boolean;
49
+ attributes?: {
50
+ [name: string]: string;
51
+ } | ((state: EditorState) => {
52
+ [name: string]: string;
53
+ });
54
+ }
55
+ export interface DirectEditorProps extends EditorProps {
56
+ state: EditorState;
57
+ plugins?: readonly Plugin[];
58
+ dispatchTransaction?: (tr: Transaction) => void;
59
+ }
60
+ //# sourceMappingURL=DummyEditorView.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DummyEditorView.d.ts","sourceRoot":"","sources":["../src/DummyEditorView.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,WAAW,EACX,MAAM,EAEN,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAElE,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAKhE,qBAAa,eAAe;IAE1B,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,aAAa,CAAoB;IAEzC,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,iBAAiB,CAAyB;IAClD,OAAO,CAAC,WAAW,CAAoB;IAGhC,KAAK,EAAE,WAAW,CAAC;gBAOd,KAAK,EAAE,iBAAiB;IAepC,QAAQ,EAAE,OAAO,CAAC;IAKlB,IAAI,SAAS,YAEZ;IAED,IAAI,GAAG;;;M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