@kerebron/extension-lsp 0.4.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 (211) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +82 -0
  3. package/esm/_dnt.polyfills.d.ts +101 -0
  4. package/esm/_dnt.polyfills.d.ts.map +1 -0
  5. package/esm/_dnt.polyfills.js +127 -0
  6. package/esm/_dnt.shims.d.ts +6 -0
  7. package/esm/_dnt.shims.d.ts.map +1 -0
  8. package/esm/_dnt.shims.js +61 -0
  9. package/esm/editor/src/CoreEditor.d.ts +40 -0
  10. package/esm/editor/src/CoreEditor.d.ts.map +1 -0
  11. package/esm/editor/src/CoreEditor.js +252 -0
  12. package/esm/editor/src/DummyEditorView.d.ts +60 -0
  13. package/esm/editor/src/DummyEditorView.d.ts.map +1 -0
  14. package/esm/editor/src/DummyEditorView.js +277 -0
  15. package/esm/editor/src/Extension.d.ts +31 -0
  16. package/esm/editor/src/Extension.d.ts.map +1 -0
  17. package/esm/editor/src/Extension.js +53 -0
  18. package/esm/editor/src/ExtensionManager.d.ts +32 -0
  19. package/esm/editor/src/ExtensionManager.d.ts.map +1 -0
  20. package/esm/editor/src/ExtensionManager.js +260 -0
  21. package/esm/editor/src/Mark.d.ts +23 -0
  22. package/esm/editor/src/Mark.d.ts.map +1 -0
  23. package/esm/editor/src/Mark.js +51 -0
  24. package/esm/editor/src/Node.d.ts +32 -0
  25. package/esm/editor/src/Node.d.ts.map +1 -0
  26. package/esm/editor/src/Node.js +60 -0
  27. package/esm/editor/src/commands/CommandManager.d.ts +23 -0
  28. package/esm/editor/src/commands/CommandManager.d.ts.map +1 -0
  29. package/esm/editor/src/commands/CommandManager.js +118 -0
  30. package/esm/editor/src/commands/baseCommandFactories.d.ts +3 -0
  31. package/esm/editor/src/commands/baseCommandFactories.d.ts.map +1 -0
  32. package/esm/editor/src/commands/baseCommandFactories.js +836 -0
  33. package/esm/editor/src/commands/createChainableState.d.ts +3 -0
  34. package/esm/editor/src/commands/createChainableState.d.ts.map +1 -0
  35. package/esm/editor/src/commands/createChainableState.js +29 -0
  36. package/esm/editor/src/commands/keyCommandFactories.d.ts +3 -0
  37. package/esm/editor/src/commands/keyCommandFactories.d.ts.map +1 -0
  38. package/esm/editor/src/commands/keyCommandFactories.js +10 -0
  39. package/esm/editor/src/commands/mod.d.ts +7 -0
  40. package/esm/editor/src/commands/mod.d.ts.map +1 -0
  41. package/esm/editor/src/commands/mod.js +76 -0
  42. package/esm/editor/src/commands/replaceCommandFactories.d.ts +3 -0
  43. package/esm/editor/src/commands/replaceCommandFactories.d.ts.map +1 -0
  44. package/esm/editor/src/commands/replaceCommandFactories.js +94 -0
  45. package/esm/editor/src/commands/types.d.ts +18 -0
  46. package/esm/editor/src/commands/types.d.ts.map +1 -0
  47. package/esm/editor/src/commands/types.js +1 -0
  48. package/esm/editor/src/mod.d.ts +9 -0
  49. package/esm/editor/src/mod.d.ts.map +1 -0
  50. package/esm/editor/src/mod.js +8 -0
  51. package/esm/editor/src/nodeToTreeString.d.ts +10 -0
  52. package/esm/editor/src/nodeToTreeString.d.ts.map +1 -0
  53. package/esm/editor/src/nodeToTreeString.js +74 -0
  54. package/esm/editor/src/plugins/TrackSelecionPlugin.d.ts +6 -0
  55. package/esm/editor/src/plugins/TrackSelecionPlugin.d.ts.map +1 -0
  56. package/esm/editor/src/plugins/TrackSelecionPlugin.js +24 -0
  57. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts +23 -0
  58. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts.map +1 -0
  59. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.js +163 -0
  60. package/esm/editor/src/plugins/keymap/keymap.d.ts +11 -0
  61. package/esm/editor/src/plugins/keymap/keymap.d.ts.map +1 -0
  62. package/esm/editor/src/plugins/keymap/keymap.js +125 -0
  63. package/esm/editor/src/plugins/keymap/w3c-keyname.d.ts +4 -0
  64. package/esm/editor/src/plugins/keymap/w3c-keyname.d.ts.map +1 -0
  65. package/esm/editor/src/plugins/keymap/w3c-keyname.js +124 -0
  66. package/esm/editor/src/types.d.ts +52 -0
  67. package/esm/editor/src/types.d.ts.map +1 -0
  68. package/esm/editor/src/types.js +1 -0
  69. package/esm/editor/src/ui.d.ts +15 -0
  70. package/esm/editor/src/ui.d.ts.map +1 -0
  71. package/esm/editor/src/ui.js +16 -0
  72. package/esm/editor/src/utilities/SmartOutput.d.ts +41 -0
  73. package/esm/editor/src/utilities/SmartOutput.d.ts.map +1 -0
  74. package/esm/editor/src/utilities/SmartOutput.js +228 -0
  75. package/esm/editor/src/utilities/createNodeFromContent.d.ts +9 -0
  76. package/esm/editor/src/utilities/createNodeFromContent.d.ts.map +1 -0
  77. package/esm/editor/src/utilities/createNodeFromContent.js +32 -0
  78. package/esm/editor/src/utilities/getHtmlAttributes.d.ts +9 -0
  79. package/esm/editor/src/utilities/getHtmlAttributes.d.ts.map +1 -0
  80. package/esm/editor/src/utilities/getHtmlAttributes.js +47 -0
  81. package/esm/editor/src/utilities/getShadowRoot.d.ts +2 -0
  82. package/esm/editor/src/utilities/getShadowRoot.d.ts.map +1 -0
  83. package/esm/editor/src/utilities/getShadowRoot.js +16 -0
  84. package/esm/editor/src/utilities/mod.d.ts +6 -0
  85. package/esm/editor/src/utilities/mod.d.ts.map +1 -0
  86. package/esm/editor/src/utilities/mod.js +5 -0
  87. package/esm/editor/src/utilities/toRawTextResult.d.ts +3 -0
  88. package/esm/editor/src/utilities/toRawTextResult.d.ts.map +1 -0
  89. package/esm/editor/src/utilities/toRawTextResult.js +21 -0
  90. package/esm/extension-autocomplete/src/AutocompletePlugin.d.ts +8 -0
  91. package/esm/extension-autocomplete/src/AutocompletePlugin.d.ts.map +1 -0
  92. package/esm/extension-autocomplete/src/AutocompletePlugin.js +232 -0
  93. package/esm/extension-autocomplete/src/DefaultRenderer.d.ts +17 -0
  94. package/esm/extension-autocomplete/src/DefaultRenderer.d.ts.map +1 -0
  95. package/esm/extension-autocomplete/src/DefaultRenderer.js +137 -0
  96. package/esm/extension-autocomplete/src/ExtensionAutocomplete.d.ts +26 -0
  97. package/esm/extension-autocomplete/src/ExtensionAutocomplete.d.ts.map +1 -0
  98. package/esm/extension-autocomplete/src/ExtensionAutocomplete.js +30 -0
  99. package/esm/extension-autocomplete/src/createDefaultMatcher.d.ts +11 -0
  100. package/esm/extension-autocomplete/src/createDefaultMatcher.d.ts.map +1 -0
  101. package/esm/extension-autocomplete/src/createDefaultMatcher.js +58 -0
  102. package/esm/extension-autocomplete/src/createRegexMatcher.d.ts +4 -0
  103. package/esm/extension-autocomplete/src/createRegexMatcher.d.ts.map +1 -0
  104. package/esm/extension-autocomplete/src/createRegexMatcher.js +50 -0
  105. package/esm/extension-autocomplete/src/mod.d.ts +3 -0
  106. package/esm/extension-autocomplete/src/mod.d.ts.map +1 -0
  107. package/esm/extension-autocomplete/src/mod.js +2 -0
  108. package/esm/extension-autocomplete/src/types.d.ts +60 -0
  109. package/esm/extension-autocomplete/src/types.d.ts.map +1 -0
  110. package/esm/extension-autocomplete/src/types.js +1 -0
  111. package/esm/extension-basic-editor/src/ExtensionHtml.d.ts +15 -0
  112. package/esm/extension-basic-editor/src/ExtensionHtml.d.ts.map +1 -0
  113. package/esm/extension-basic-editor/src/ExtensionHtml.js +108 -0
  114. package/esm/extension-lsp/src/DiagnosticPlugin.d.ts +32 -0
  115. package/esm/extension-lsp/src/DiagnosticPlugin.d.ts.map +1 -0
  116. package/esm/extension-lsp/src/DiagnosticPlugin.js +131 -0
  117. package/esm/extension-lsp/src/ExtensionLsp.d.ts +25 -0
  118. package/esm/extension-lsp/src/ExtensionLsp.d.ts.map +1 -0
  119. package/esm/extension-lsp/src/ExtensionLsp.js +126 -0
  120. package/esm/extension-lsp/src/LSPClient.d.ts +56 -0
  121. package/esm/extension-lsp/src/LSPClient.d.ts.map +1 -0
  122. package/esm/extension-lsp/src/LSPClient.js +449 -0
  123. package/esm/extension-lsp/src/LspWebSocketTransport.d.ts +20 -0
  124. package/esm/extension-lsp/src/LspWebSocketTransport.d.ts.map +1 -0
  125. package/esm/extension-lsp/src/LspWebSocketTransport.js +137 -0
  126. package/esm/extension-lsp/src/computeIncrementalChanges.d.ts +8 -0
  127. package/esm/extension-lsp/src/computeIncrementalChanges.d.ts.map +1 -0
  128. package/esm/extension-lsp/src/computeIncrementalChanges.js +82 -0
  129. package/esm/extension-lsp/src/createLspAutocomplete.d.ts +23 -0
  130. package/esm/extension-lsp/src/createLspAutocomplete.d.ts.map +1 -0
  131. package/esm/extension-lsp/src/createLspAutocomplete.js +68 -0
  132. package/esm/extension-lsp/src/mod.d.ts +5 -0
  133. package/esm/extension-lsp/src/mod.d.ts.map +1 -0
  134. package/esm/extension-lsp/src/mod.js +4 -0
  135. package/esm/extension-lsp/src/types.d.ts +20 -0
  136. package/esm/extension-lsp/src/types.d.ts.map +1 -0
  137. package/esm/extension-lsp/src/types.js +1 -0
  138. package/esm/extension-lsp/src/workspace.d.ts +62 -0
  139. package/esm/extension-lsp/src/workspace.d.ts.map +1 -0
  140. package/esm/extension-lsp/src/workspace.js +168 -0
  141. package/esm/extension-markdown/src/DocumentMarkdownInlineTokenizer.d.ts +36 -0
  142. package/esm/extension-markdown/src/DocumentMarkdownInlineTokenizer.d.ts.map +1 -0
  143. package/esm/extension-markdown/src/DocumentMarkdownInlineTokenizer.js +240 -0
  144. package/esm/extension-markdown/src/DocumentMarkdownTokenizer.d.ts +26 -0
  145. package/esm/extension-markdown/src/DocumentMarkdownTokenizer.d.ts.map +1 -0
  146. package/esm/extension-markdown/src/DocumentMarkdownTokenizer.js +115 -0
  147. package/esm/extension-markdown/src/ExtensionMarkdown.d.ts +22 -0
  148. package/esm/extension-markdown/src/ExtensionMarkdown.d.ts.map +1 -0
  149. package/esm/extension-markdown/src/ExtensionMarkdown.js +48 -0
  150. package/esm/extension-markdown/src/MarkdownParser.d.ts +61 -0
  151. package/esm/extension-markdown/src/MarkdownParser.d.ts.map +1 -0
  152. package/esm/extension-markdown/src/MarkdownParser.js +249 -0
  153. package/esm/extension-markdown/src/MarkdownSerializer.d.ts +42 -0
  154. package/esm/extension-markdown/src/MarkdownSerializer.d.ts.map +1 -0
  155. package/esm/extension-markdown/src/MarkdownSerializer.js +325 -0
  156. package/esm/extension-markdown/src/PositionMapper.d.ts +15 -0
  157. package/esm/extension-markdown/src/PositionMapper.d.ts.map +1 -0
  158. package/esm/extension-markdown/src/PositionMapper.js +100 -0
  159. package/esm/extension-markdown/src/TokenSource.d.ts +11 -0
  160. package/esm/extension-markdown/src/TokenSource.d.ts.map +1 -0
  161. package/esm/extension-markdown/src/TokenSource.js +39 -0
  162. package/esm/extension-markdown/src/mdToPmConverter.d.ts +5 -0
  163. package/esm/extension-markdown/src/mdToPmConverter.d.ts.map +1 -0
  164. package/esm/extension-markdown/src/mdToPmConverter.js +111 -0
  165. package/esm/extension-markdown/src/pmToMdConverter.d.ts +16 -0
  166. package/esm/extension-markdown/src/pmToMdConverter.d.ts.map +1 -0
  167. package/esm/extension-markdown/src/pmToMdConverter.js +433 -0
  168. package/esm/extension-markdown/src/token_handlers/basic_token_handlers.d.ts +4 -0
  169. package/esm/extension-markdown/src/token_handlers/basic_token_handlers.d.ts.map +1 -0
  170. package/esm/extension-markdown/src/token_handlers/basic_token_handlers.js +151 -0
  171. package/esm/extension-markdown/src/token_handlers/footnote_token_handlers.d.ts +3 -0
  172. package/esm/extension-markdown/src/token_handlers/footnote_token_handlers.d.ts.map +1 -0
  173. package/esm/extension-markdown/src/token_handlers/footnote_token_handlers.js +34 -0
  174. package/esm/extension-markdown/src/token_handlers/inline_token_handlers.d.ts +6 -0
  175. package/esm/extension-markdown/src/token_handlers/inline_token_handlers.d.ts.map +1 -0
  176. package/esm/extension-markdown/src/token_handlers/inline_token_handlers.js +380 -0
  177. package/esm/extension-markdown/src/token_handlers/lists_token_handlers.d.ts +3 -0
  178. package/esm/extension-markdown/src/token_handlers/lists_token_handlers.d.ts.map +1 -0
  179. package/esm/extension-markdown/src/token_handlers/lists_token_handlers.js +323 -0
  180. package/esm/extension-markdown/src/token_handlers/table_token_handlers.d.ts +9 -0
  181. package/esm/extension-markdown/src/token_handlers/table_token_handlers.d.ts.map +1 -0
  182. package/esm/extension-markdown/src/token_handlers/table_token_handlers.js +308 -0
  183. package/esm/extension-markdown/src/treeSitterTokenizer.d.ts +5 -0
  184. package/esm/extension-markdown/src/treeSitterTokenizer.d.ts.map +1 -0
  185. package/esm/extension-markdown/src/treeSitterTokenizer.js +769 -0
  186. package/esm/extension-markdown/src/types.d.ts +28 -0
  187. package/esm/extension-markdown/src/types.d.ts.map +1 -0
  188. package/esm/extension-markdown/src/types.js +131 -0
  189. package/esm/extension-markdown/src/utils.d.ts +8 -0
  190. package/esm/extension-markdown/src/utils.d.ts.map +1 -0
  191. package/esm/extension-markdown/src/utils.js +86 -0
  192. package/esm/package.json +3 -0
  193. package/esm/tree-sitter-shim/src/main.d.ts +15 -0
  194. package/esm/tree-sitter-shim/src/main.d.ts.map +1 -0
  195. package/esm/tree-sitter-shim/src/main.js +25 -0
  196. package/esm/tree-sitter-shim/src/tree_sitter/node.d.ts +6 -0
  197. package/esm/tree-sitter-shim/src/tree_sitter/node.d.ts.map +1 -0
  198. package/esm/tree-sitter-shim/src/tree_sitter/node.js +1 -0
  199. package/esm/tree-sitter-shim/src/tree_sitter/parser.d.ts +7 -0
  200. package/esm/tree-sitter-shim/src/tree_sitter/parser.d.ts.map +1 -0
  201. package/esm/tree-sitter-shim/src/tree_sitter/parser.js +5 -0
  202. package/esm/tree-sitter-shim/src/tree_sitter/tree.d.ts +6 -0
  203. package/esm/tree-sitter-shim/src/tree_sitter/tree.d.ts.map +1 -0
  204. package/esm/tree-sitter-shim/src/tree_sitter/tree.js +1 -0
  205. package/esm/wasm/src/mod.d.ts +12 -0
  206. package/esm/wasm/src/mod.d.ts.map +1 -0
  207. package/esm/wasm/src/mod.js +48 -0
  208. package/esm/wasm/wasm.d.ts +138 -0
  209. package/esm/wasm/wasm.d.ts.map +1 -0
  210. package/esm/wasm/wasm.js +120 -0
  211. package/package.json +31 -0
@@ -0,0 +1,125 @@
1
+ import { Plugin } from 'prosemirror-state';
2
+ import { base, keyName } from './w3c-keyname.js';
3
+ const mac = typeof navigator != 'undefined' &&
4
+ /Mac|iP(hone|[oa]d)/.test(navigator?.platform);
5
+ const windows = typeof navigator != 'undefined' &&
6
+ /Win/.test(navigator?.platform);
7
+ function normalizeKeyName(name) {
8
+ let parts = name.split(/-(?!$)/), result = parts[parts.length - 1];
9
+ if (result == 'Space')
10
+ result = ' ';
11
+ let alt, ctrl, shift, meta;
12
+ for (let i = 0; i < parts.length - 1; i++) {
13
+ let mod = parts[i];
14
+ if (/^(cmd|meta|m)$/i.test(mod))
15
+ meta = true;
16
+ else if (/^a(lt)?$/i.test(mod))
17
+ alt = true;
18
+ else if (/^(c|ctrl|control)$/i.test(mod))
19
+ ctrl = true;
20
+ else if (/^s(hift)?$/i.test(mod))
21
+ shift = true;
22
+ else if (/^mod$/i.test(mod)) {
23
+ if (mac)
24
+ meta = true;
25
+ else
26
+ ctrl = true;
27
+ }
28
+ else
29
+ throw new Error('Unrecognized modifier name: ' + mod);
30
+ }
31
+ if (alt)
32
+ result = 'Alt-' + result;
33
+ if (ctrl)
34
+ result = 'Ctrl-' + result;
35
+ if (meta)
36
+ result = 'Meta-' + result;
37
+ if (shift)
38
+ result = 'Shift-' + result;
39
+ return result;
40
+ }
41
+ function normalize(map) {
42
+ let copy = Object.create(null);
43
+ for (let prop in map)
44
+ copy[normalizeKeyName(prop)] = map[prop];
45
+ return copy;
46
+ }
47
+ function modifiers(name, event, shift = true) {
48
+ if (event.altKey)
49
+ name = 'Alt-' + name;
50
+ if (event.ctrlKey)
51
+ name = 'Ctrl-' + name;
52
+ if (event.metaKey)
53
+ name = 'Meta-' + name;
54
+ if (shift && event.shiftKey)
55
+ name = 'Shift-' + name;
56
+ return name;
57
+ }
58
+ /// Create a keymap plugin for the given set of bindings.
59
+ ///
60
+ /// Bindings should map key names to [command](#commands)-style
61
+ /// functions, which will be called with `(EditorState, dispatch,
62
+ /// EditorView)` arguments, and should return true when they've handled
63
+ /// the key. Note that the view argument isn't part of the command
64
+ /// protocol, but can be used as an escape hatch if a binding needs to
65
+ /// directly interact with the UI.
66
+ ///
67
+ /// Key names may be strings like `"Shift-Ctrl-Enter"`—a key
68
+ /// identifier prefixed with zero or more modifiers. Key identifiers
69
+ /// are based on the strings that can appear in
70
+ /// [`KeyEvent.key`](https:///developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key).
71
+ /// Use lowercase letters to refer to letter keys (or uppercase letters
72
+ /// if you want shift to be held). You may use `"Space"` as an alias
73
+ /// for the `" "` name.
74
+ ///
75
+ /// Modifiers can be given in any order. `Shift-` (or `s-`), `Alt-` (or
76
+ /// `a-`), `Ctrl-` (or `c-` or `Control-`) and `Cmd-` (or `m-` or
77
+ /// `Meta-`) are recognized. For characters that are created by holding
78
+ /// shift, the `Shift-` prefix is implied, and should not be added
79
+ /// explicitly.
80
+ ///
81
+ /// You can use `Mod-` as a shorthand for `Cmd-` on Mac and `Ctrl-` on
82
+ /// other platforms.
83
+ ///
84
+ /// You can add multiple keymap plugins to an editor. The order in
85
+ /// which they appear determines their precedence (the ones early in
86
+ /// the array get to dispatch first).
87
+ export class KeymapPlugin extends Plugin {
88
+ constructor(bindings) {
89
+ super({ props: { handleKeyDown: keydownHandler(bindings) } });
90
+ }
91
+ }
92
+ /// Given a set of bindings (using the same format as
93
+ /// [`keymap`](#keymap.keymap)), return a [keydown
94
+ /// handler](#view.EditorProps.handleKeyDown) that handles them.
95
+ export function keydownHandler(bindings) {
96
+ let map = normalize(bindings);
97
+ return function (view, event) {
98
+ let name = keyName(event), baseName, direct = map[modifiers(name, event)];
99
+ if (direct && direct(view.state, view.dispatch, view))
100
+ return true;
101
+ // A character key
102
+ if (name.length == 1 && name != ' ') {
103
+ if (event.shiftKey) {
104
+ // In case the name was already modified by shift, try looking
105
+ // it up without its shift modifier
106
+ let noShift = map[modifiers(name, event, false)];
107
+ if (noShift && noShift(view.state, view.dispatch, view))
108
+ return true;
109
+ }
110
+ if ((event.altKey || event.metaKey || event.ctrlKey) &&
111
+ // Ctrl-Alt may be used for AltGr on Windows
112
+ !(windows && event.ctrlKey && event.altKey) &&
113
+ (baseName = base[event.keyCode]) && baseName != name) {
114
+ // Try falling back to the keyCode when there's a modifier
115
+ // active or the character produced isn't ASCII, and our table
116
+ // produces a different name from the the keyCode. See #668,
117
+ // #1060, #1529.
118
+ let fromCode = map[modifiers(baseName, event)];
119
+ if (fromCode && fromCode(view.state, view.dispatch, view))
120
+ return true;
121
+ }
122
+ }
123
+ return false;
124
+ };
125
+ }
@@ -0,0 +1,4 @@
1
+ export declare const base: Record<number, string>;
2
+ export declare const shift: Record<number, string>;
3
+ export declare function keyName(event: KeyboardEvent): string;
4
+ //# sourceMappingURL=w3c-keyname.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"w3c-keyname.d.ts","sourceRoot":"","sources":["../../../../../src/editor/src/plugins/keymap/w3c-keyname.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAqDvC,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAyBxC,CAAC;AAuBF,wBAAgB,OAAO,CAAC,KAAK,EAAE,aAAa,UAmB3C"}
@@ -0,0 +1,124 @@
1
+ export const base = {
2
+ 8: 'Backspace',
3
+ 9: 'Tab',
4
+ 10: 'Enter',
5
+ 12: 'NumLock',
6
+ 13: 'Enter',
7
+ 16: 'Shift',
8
+ 17: 'Control',
9
+ 18: 'Alt',
10
+ 20: 'CapsLock',
11
+ 27: 'Escape',
12
+ 32: ' ',
13
+ 33: 'PageUp',
14
+ 34: 'PageDown',
15
+ 35: 'End',
16
+ 36: 'Home',
17
+ 37: 'ArrowLeft',
18
+ 38: 'ArrowUp',
19
+ 39: 'ArrowRight',
20
+ 40: 'ArrowDown',
21
+ 44: 'PrintScreen',
22
+ 45: 'Insert',
23
+ 46: 'Delete',
24
+ 59: ';',
25
+ 61: '=',
26
+ 91: 'Meta',
27
+ 92: 'Meta',
28
+ 106: '*',
29
+ 107: '+',
30
+ 108: ',',
31
+ 109: '-',
32
+ 110: '.',
33
+ 111: '/',
34
+ 144: 'NumLock',
35
+ 145: 'ScrollLock',
36
+ 160: 'Shift',
37
+ 161: 'Shift',
38
+ 162: 'Control',
39
+ 163: 'Control',
40
+ 164: 'Alt',
41
+ 165: 'Alt',
42
+ 173: '-',
43
+ 186: ';',
44
+ 187: '=',
45
+ 188: ',',
46
+ 189: '-',
47
+ 190: '.',
48
+ 191: '/',
49
+ 192: '`',
50
+ 219: '[',
51
+ 220: '\\',
52
+ 221: ']',
53
+ 222: "'",
54
+ };
55
+ export const shift = {
56
+ 48: ')',
57
+ 49: '!',
58
+ 50: '@',
59
+ 51: '#',
60
+ 52: '$',
61
+ 53: '%',
62
+ 54: '^',
63
+ 55: '&',
64
+ 56: '*',
65
+ 57: '(',
66
+ 59: ':',
67
+ 61: '+',
68
+ 173: '_',
69
+ 186: ':',
70
+ 187: '+',
71
+ 188: '<',
72
+ 189: '_',
73
+ 190: '>',
74
+ 191: '?',
75
+ 192: '~',
76
+ 219: '{',
77
+ 220: '|',
78
+ 221: '}',
79
+ 222: '"',
80
+ };
81
+ const mac = typeof navigator != 'undefined' && /Mac/.test(navigator.platform);
82
+ const ie = typeof navigator != 'undefined' &&
83
+ /MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);
84
+ // Fill in the digit keys
85
+ for (let i = 0; i < 10; i++)
86
+ base[48 + i] = base[96 + i] = String(i);
87
+ // The function keys
88
+ for (let i = 1; i <= 24; i++)
89
+ base[i + 111] = 'F' + i;
90
+ // And the alphabetic keys
91
+ for (let i = 65; i <= 90; i++) {
92
+ base[i] = String.fromCharCode(i + 32);
93
+ shift[i] = String.fromCharCode(i);
94
+ }
95
+ // For each code that doesn't have a shift-equivalent, copy the base name
96
+ for (const code in base) {
97
+ if (!shift.hasOwnProperty(code))
98
+ shift[code] = base[code];
99
+ }
100
+ export function keyName(event) {
101
+ // On macOS, keys held with Shift and Cmd don't reflect the effect of Shift in `.key`.
102
+ // On IE, shift effect is never included in `.key`.
103
+ const ignoreKey = mac && event.metaKey && event.shiftKey && !event.ctrlKey && !event.altKey ||
104
+ ie && event.shiftKey && event.key && event.key.length == 1 ||
105
+ event.key == 'Unidentified';
106
+ let name = (!ignoreKey && event.key) ||
107
+ (event.shiftKey ? shift : base)[event.keyCode] ||
108
+ event.key || 'Unidentified';
109
+ // Edge sometimes produces wrong names (Issue #3)
110
+ if (name == 'Esc')
111
+ name = 'Escape';
112
+ if (name == 'Del')
113
+ name = 'Delete';
114
+ // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8860571/
115
+ if (name == 'Left')
116
+ name = 'ArrowLeft';
117
+ if (name == 'Up')
118
+ name = 'ArrowUp';
119
+ if (name == 'Right')
120
+ name = 'ArrowRight';
121
+ if (name == 'Down')
122
+ name = 'ArrowDown';
123
+ return name;
124
+ }
@@ -0,0 +1,52 @@
1
+ import type { Node as ProseMirrorNode, ParseOptions } from 'prosemirror-model';
2
+ import type { Extension } from './Extension.js';
3
+ import type { Mark } from './Mark.js';
4
+ import type { Node } from './Node.js';
5
+ export type AnyExtension = Extension | Node | Mark;
6
+ export type AnyExtensionOrReq = AnyExtension | {
7
+ requires: Array<AnyExtensionOrReq | string>;
8
+ };
9
+ export type Content = JSONContent | JSONContent[] | null;
10
+ export interface EditorConfig {
11
+ element: HTMLElement;
12
+ content: Content;
13
+ parseOptions: ParseOptions;
14
+ extensions: AnyExtensionOrReq[];
15
+ cdnUrl?: string;
16
+ uri?: string;
17
+ languageID?: string;
18
+ topNode?: string;
19
+ }
20
+ export type JSONContent = {
21
+ type?: string;
22
+ attrs?: Record<string, any>;
23
+ content?: JSONContent[];
24
+ marks?: {
25
+ type: string;
26
+ attrs?: Record<string, any>;
27
+ [key: string]: any;
28
+ }[];
29
+ text?: string;
30
+ [key: string]: any;
31
+ };
32
+ export type Attribute<T> = {
33
+ fromDom?: (element: HTMLElement) => T;
34
+ default: T;
35
+ toDom?: (node: ProseMirrorNode) => T;
36
+ };
37
+ export interface TextRange {
38
+ from: number;
39
+ to: number;
40
+ }
41
+ export interface RawTextMapEntry {
42
+ nodeIdx: number;
43
+ targetRow: number;
44
+ targetCol: number;
45
+ sourceCol?: number;
46
+ targetPos: number;
47
+ }
48
+ export interface RawTextResult {
49
+ content: string;
50
+ rawTextMap: Array<RawTextMapEntry>;
51
+ }
52
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/editor/src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,IAAI,eAAe,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC;AACnD,MAAM,MAAM,iBAAiB,GAAG,YAAY,GAAG;IAC7C,QAAQ,EAAE,KAAK,CAAC,iBAAiB,GAAG,MAAM,CAAC,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG,WAAW,GAAG,WAAW,EAAE,GAAG,IAAI,CAAC;AAEzD,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,WAAW,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,YAAY,CAAC;IAC3B,UAAU,EAAE,iBAAiB,EAAE,CAAC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,OAAO,CAAC,EAAE,WAAW,EAAE,CAAC;IACxB,KAAK,CAAC,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,EAAE,CAAC;IACJ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IACzB,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,CAAC,CAAC;IACtC,OAAO,EAAE,CAAC,CAAC;IACX,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,CAAC,CAAC;CACtC,CAAC;AAEF,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,KAAK,CAAC,eAAe,CAAC,CAAC;CACpC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ import type { CoreEditor } from './CoreEditor.js';
2
+ interface SelectParams {
3
+ anchor: number;
4
+ scrollIntoView: boolean;
5
+ userEvent: string;
6
+ }
7
+ export interface EditorUi {
8
+ showMessage(msg: string): void;
9
+ showError(err: Error): void;
10
+ focus(): void;
11
+ select(params: SelectParams): void;
12
+ }
13
+ export declare function defaultUi(editor: CoreEditor): EditorUi;
14
+ export {};
15
+ //# sourceMappingURL=ui.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../../../src/editor/src/ui.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,UAAU,YAAY;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,OAAO,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,QAAQ;IACvB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,SAAS,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI,CAAC;IAC5B,KAAK,IAAI,IAAI,CAAC;IACd,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;CACpC;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,UAAU,GAAG,QAAQ,CAmBtD"}
@@ -0,0 +1,16 @@
1
+ export function defaultUi(editor) {
2
+ return {
3
+ showMessage(msg) {
4
+ globalThis.alert(msg);
5
+ },
6
+ showError(err) {
7
+ globalThis.alert(err.message);
8
+ console.error(err);
9
+ },
10
+ focus() {
11
+ // editor.run.focus();
12
+ },
13
+ select({ anchor: number, scrollIntoView: boolean, userEvent: string, }) {
14
+ },
15
+ };
16
+ }
@@ -0,0 +1,41 @@
1
+ export interface OutputMeta<K> {
2
+ pos: number;
3
+ rowPos: number;
4
+ colPos: number;
5
+ item?: K;
6
+ }
7
+ interface Mapping {
8
+ sourceNo: number;
9
+ sourceRowPos: number;
10
+ sourceColPos: number;
11
+ }
12
+ export interface SourceMap {
13
+ 'version': 3;
14
+ 'file': string;
15
+ 'sourceRoot': string;
16
+ 'sources': Array<string>;
17
+ 'sourcesContent': Array<string>;
18
+ 'names': Array<string>;
19
+ 'mappings': string;
20
+ }
21
+ export declare class SmartOutput<K> {
22
+ private _rowPos;
23
+ private _colPos;
24
+ private _pos;
25
+ private chunks;
26
+ private metas;
27
+ log(text: string, item?: K): void;
28
+ getMetas(): OutputMeta<K>[];
29
+ get chunkPos(): number;
30
+ rollback(pos: number): void;
31
+ get rowPos(): number;
32
+ get colPos(): number;
33
+ get pos(): number;
34
+ endsWith(text: string): boolean;
35
+ toString(): string;
36
+ getSourceMap(mapper: (rowPos: number, colPos: number, pos: number, item?: K) => Mapping | void): SourceMap;
37
+ }
38
+ export declare function decode(string: string): number[];
39
+ export declare function encode(value: number | number[]): string;
40
+ export {};
41
+ //# sourceMappingURL=SmartOutput.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SmartOutput.d.ts","sourceRoot":"","sources":["../../../../src/editor/src/utilities/SmartOutput.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,CAAC,CAAC;CACV;AAED,UAAU,OAAO;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,CAAC,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACzB,gBAAgB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAChC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,WAAW,CAAC,CAAC;IACxB,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,IAAI,CAAK;IAEjB,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,KAAK,CAA4B;IAEzC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC;IAyB1B,QAAQ;IAIR,IAAI,QAAQ,WAEX;IAED,QAAQ,CAAC,GAAG,EAAE,MAAM;IAKpB,IAAI,MAAM,WAET;IAED,IAAI,MAAM,WAET;IAED,IAAI,GAAG,WAEN;IAED,QAAQ,CAAC,IAAI,EAAE,MAAM;IAIrB,QAAQ;IAIR,YAAY,CACV,MAAM,EAAE,CACN,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,CAAC,KACL,OAAO,GAAG,IAAI,GAClB,SAAS;CA4Db;AAuDD,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,YAoCpC;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,UAW9C"}
@@ -0,0 +1,228 @@
1
+ export class SmartOutput {
2
+ constructor() {
3
+ Object.defineProperty(this, "_rowPos", {
4
+ enumerable: true,
5
+ configurable: true,
6
+ writable: true,
7
+ value: 0
8
+ });
9
+ Object.defineProperty(this, "_colPos", {
10
+ enumerable: true,
11
+ configurable: true,
12
+ writable: true,
13
+ value: 0
14
+ });
15
+ Object.defineProperty(this, "_pos", {
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true,
19
+ value: 0
20
+ });
21
+ Object.defineProperty(this, "chunks", {
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true,
25
+ value: []
26
+ });
27
+ Object.defineProperty(this, "metas", {
28
+ enumerable: true,
29
+ configurable: true,
30
+ writable: true,
31
+ value: []
32
+ });
33
+ }
34
+ log(text, item) {
35
+ if (text.length === 0) {
36
+ return;
37
+ }
38
+ this.chunks.push(text);
39
+ this.metas.push({
40
+ pos: this._pos,
41
+ colPos: this._colPos,
42
+ rowPos: this._rowPos,
43
+ item,
44
+ });
45
+ const lines = text.split('\n');
46
+ if (lines.length === 1) {
47
+ this._colPos += lines[lines.length - 1].length;
48
+ }
49
+ else {
50
+ this._rowPos += lines.length - 1;
51
+ this._colPos = lines[lines.length - 1].length;
52
+ }
53
+ this._pos += text.length;
54
+ }
55
+ getMetas() {
56
+ return this.metas;
57
+ }
58
+ get chunkPos() {
59
+ return this.chunks.length;
60
+ }
61
+ rollback(pos) {
62
+ this.chunks.splice(pos);
63
+ this.metas.splice(pos);
64
+ }
65
+ get rowPos() {
66
+ return this._rowPos;
67
+ }
68
+ get colPos() {
69
+ return this._colPos;
70
+ }
71
+ get pos() {
72
+ return this._pos;
73
+ }
74
+ endsWith(text) {
75
+ return this.chunks.join('').endsWith(text);
76
+ }
77
+ toString() {
78
+ return this.chunks.join('');
79
+ }
80
+ getSourceMap(mapper) {
81
+ const mappingRows = [];
82
+ let lastRow = -1;
83
+ let lastCol = -1;
84
+ let prevSourceNo = 0;
85
+ let prevSourceRowPos = 0;
86
+ let prevSourceColPos = 0;
87
+ let prevColPos = 0;
88
+ for (const meta of this.metas) {
89
+ while (meta.rowPos >= mappingRows.length) {
90
+ mappingRows.push([]);
91
+ }
92
+ if (lastRow != meta.rowPos || lastCol != meta.colPos) {
93
+ const currentRow = mappingRows[meta.rowPos];
94
+ if (lastRow != meta.rowPos) {
95
+ prevColPos = 0;
96
+ }
97
+ const mapping = mapper(meta.rowPos, meta.colPos, meta.pos, meta.item);
98
+ if (mapping) {
99
+ currentRow.push([
100
+ meta.colPos - prevColPos,
101
+ mapping.sourceNo - prevSourceNo,
102
+ mapping.sourceRowPos - prevSourceRowPos,
103
+ mapping.sourceColPos - prevSourceColPos,
104
+ ]);
105
+ prevColPos = meta.colPos;
106
+ prevSourceNo = mapping.sourceNo;
107
+ prevSourceRowPos = mapping.sourceRowPos;
108
+ prevSourceColPos = mapping.sourceColPos;
109
+ }
110
+ }
111
+ lastRow = meta.rowPos;
112
+ lastCol = meta.colPos;
113
+ }
114
+ const mappings = mappingRows
115
+ .map((row) => row.map((group) => encode(group))
116
+ .join(','))
117
+ .join(';');
118
+ return {
119
+ version: 3,
120
+ file: '',
121
+ sourceRoot: '',
122
+ sources: [],
123
+ sourcesContent: [],
124
+ names: [],
125
+ mappings,
126
+ };
127
+ }
128
+ }
129
+ const BASE64_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
130
+ function toVLQ(value) {
131
+ const vlq = [];
132
+ const isNegative = value < 0;
133
+ value = Math.abs(value);
134
+ if (value === 0) {
135
+ vlq.push(0);
136
+ return vlq;
137
+ }
138
+ while (value > 0) {
139
+ let digit = value & 0x1F;
140
+ value >>= 5;
141
+ if (value > 0) {
142
+ digit |= 0x20;
143
+ }
144
+ vlq.push(digit);
145
+ if (vlq.length === 1) {
146
+ digit = isNegative ? (digit | 0x1) : (digit & ~0x1);
147
+ vlq[0] = digit;
148
+ }
149
+ }
150
+ return vlq;
151
+ }
152
+ function encodeVLQ(input) {
153
+ const numbers = Array.isArray(input) ? input : [input];
154
+ let result = '';
155
+ for (const num of numbers) {
156
+ const vlq = toVLQ(num);
157
+ for (const digit of vlq) {
158
+ result += BASE64_CHARS[digit];
159
+ }
160
+ }
161
+ return result;
162
+ }
163
+ const char_to_integer = {};
164
+ const integer_to_char = {};
165
+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
166
+ .split('')
167
+ .forEach(function (char, i) {
168
+ char_to_integer[char] = i;
169
+ integer_to_char[i] = char;
170
+ });
171
+ export function decode(string) {
172
+ let result = [];
173
+ let shift = 0;
174
+ let value = 0;
175
+ for (let i = 0; i < string.length; i += 1) {
176
+ let integer = char_to_integer[string[i]];
177
+ if (integer === undefined) {
178
+ throw new Error('Invalid character (' + string[i] + ')');
179
+ }
180
+ const has_continuation_bit = integer & 32;
181
+ integer &= 31;
182
+ value += integer << shift;
183
+ if (has_continuation_bit) {
184
+ shift += 5;
185
+ }
186
+ else {
187
+ const should_negate = value & 1;
188
+ value >>>= 1;
189
+ if (should_negate) {
190
+ result.push(value === 0 ? -0x80000000 : -value);
191
+ }
192
+ else {
193
+ result.push(value);
194
+ }
195
+ // reset
196
+ value = shift = 0;
197
+ }
198
+ }
199
+ return result;
200
+ }
201
+ export function encode(value) {
202
+ if (typeof value === 'number') {
203
+ return encode_integer(value);
204
+ }
205
+ let result = '';
206
+ for (let i = 0; i < value.length; i += 1) {
207
+ result += encode_integer(value[i]);
208
+ }
209
+ return result;
210
+ }
211
+ function encode_integer(num) {
212
+ let result = '';
213
+ if (num < 0) {
214
+ num = (-num << 1) | 1;
215
+ }
216
+ else {
217
+ num <<= 1;
218
+ }
219
+ do {
220
+ let clamped = num & 31;
221
+ num >>>= 5;
222
+ if (num > 0) {
223
+ clamped |= 32;
224
+ }
225
+ result += integer_to_char[clamped];
226
+ } while (num > 0);
227
+ return result;
228
+ }
@@ -0,0 +1,9 @@
1
+ import { Fragment, Node as ProseMirrorNode, Schema } from 'prosemirror-model';
2
+ import type { JSONContent } from '../types.js';
3
+ export type CreateNodeFromContentOptions = {
4
+ errorOnInvalidContent?: boolean;
5
+ };
6
+ export declare function createNodeFromObject(content: JSONContent | ProseMirrorNode | Fragment, schema: Schema, options?: CreateNodeFromContentOptions): ProseMirrorNode;
7
+ export declare function createNodeFromArray(content: JSONContent[], schema: Schema): Fragment;
8
+ export declare function createNodeFromContent(content: JSONContent | ProseMirrorNode | Fragment, schema: Schema, options?: CreateNodeFromContentOptions): ProseMirrorNode | Fragment;
9
+ //# sourceMappingURL=createNodeFromContent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createNodeFromContent.d.ts","sourceRoot":"","sources":["../../../../src/editor/src/utilities/createNodeFromContent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,IAAI,eAAe,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE9E,OAAO,KAAK,EAAW,WAAW,EAAE,MAAM,aAAa,CAAC;AAExD,MAAM,MAAM,4BAA4B,GAAG;IACzC,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC,CAAC;AAEF,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,WAAW,GAAG,eAAe,GAAG,QAAQ,EACjD,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,4BAA4B,GACrC,eAAe,CA0BjB;AAED,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,WAAW,EAAE,EACtB,MAAM,EAAE,MAAM,GACb,QAAQ,CAIV;AAED,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,WAAW,GAAG,eAAe,GAAG,QAAQ,EACjD,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,4BAA4B,GACrC,eAAe,GAAG,QAAQ,CAY5B"}
@@ -0,0 +1,32 @@
1
+ import { Fragment, Node as ProseMirrorNode } from 'prosemirror-model';
2
+ export function createNodeFromObject(content, schema, options) {
3
+ try {
4
+ const node = schema.nodeFromJSON(content);
5
+ if (options?.errorOnInvalidContent) {
6
+ node.check();
7
+ }
8
+ return node;
9
+ }
10
+ catch (error) {
11
+ if (options?.errorOnInvalidContent) {
12
+ throw new Error('Invalid JSON content', {
13
+ cause: error,
14
+ });
15
+ }
16
+ console.warn('Invalid content.', 'Passed value:', content, 'Error:', error);
17
+ return schema.topNodeType.createAndFill(null, []);
18
+ }
19
+ }
20
+ export function createNodeFromArray(content, schema) {
21
+ return Fragment.fromArray(content.map((item) => schema.nodeFromJSON(item)));
22
+ }
23
+ export function createNodeFromContent(content, schema, options) {
24
+ if (content instanceof ProseMirrorNode || content instanceof Fragment) {
25
+ return content;
26
+ }
27
+ const isJSONContent = typeof content === 'object' && content !== null;
28
+ if (isJSONContent) {
29
+ return createNodeFromObject(content, schema, options);
30
+ }
31
+ return schema.topNodeType.createAndFill(null, []);
32
+ }