@kerebron/extension-codemirror 0.3.1 → 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 (242) hide show
  1. package/README.md +3 -3
  2. package/esm/_dnt.polyfills.d.ts +101 -0
  3. package/esm/_dnt.polyfills.d.ts.map +1 -0
  4. package/esm/_dnt.polyfills.js +127 -0
  5. package/esm/_dnt.shims.d.ts +6 -0
  6. package/esm/_dnt.shims.d.ts.map +1 -0
  7. package/esm/_dnt.shims.js +61 -0
  8. package/esm/editor/src/CoreEditor.d.ts +13 -4
  9. package/esm/editor/src/CoreEditor.d.ts.map +1 -1
  10. package/esm/editor/src/CoreEditor.js +64 -12
  11. package/esm/editor/src/Extension.d.ts +6 -1
  12. package/esm/editor/src/Extension.d.ts.map +1 -1
  13. package/esm/editor/src/Extension.js +21 -1
  14. package/esm/editor/src/ExtensionManager.d.ts +5 -6
  15. package/esm/editor/src/ExtensionManager.d.ts.map +1 -1
  16. package/esm/editor/src/ExtensionManager.js +43 -55
  17. package/esm/editor/src/Mark.d.ts +3 -0
  18. package/esm/editor/src/Mark.d.ts.map +1 -1
  19. package/esm/editor/src/Mark.js +11 -0
  20. package/esm/editor/src/Node.d.ts +5 -2
  21. package/esm/editor/src/Node.d.ts.map +1 -1
  22. package/esm/editor/src/Node.js +13 -2
  23. package/esm/editor/src/commands/CommandManager.d.ts +13 -6
  24. package/esm/editor/src/commands/CommandManager.d.ts.map +1 -1
  25. package/esm/editor/src/commands/CommandManager.js +59 -2
  26. package/esm/editor/src/commands/baseCommandFactories.d.ts +3 -0
  27. package/esm/editor/src/commands/baseCommandFactories.d.ts.map +1 -0
  28. package/esm/editor/src/commands/baseCommandFactories.js +836 -0
  29. package/esm/editor/src/commands/keyCommandFactories.d.ts +3 -0
  30. package/esm/editor/src/commands/keyCommandFactories.d.ts.map +1 -0
  31. package/esm/editor/src/commands/keyCommandFactories.js +10 -0
  32. package/esm/editor/src/commands/mod.d.ts +5 -53
  33. package/esm/editor/src/commands/mod.d.ts.map +1 -1
  34. package/esm/editor/src/commands/mod.js +14 -821
  35. package/esm/editor/src/commands/replaceCommandFactories.d.ts +3 -0
  36. package/esm/editor/src/commands/replaceCommandFactories.d.ts.map +1 -0
  37. package/esm/editor/src/commands/replaceCommandFactories.js +94 -0
  38. package/esm/editor/src/commands/types.d.ts +18 -0
  39. package/esm/editor/src/commands/types.d.ts.map +1 -0
  40. package/esm/editor/src/commands/types.js +1 -0
  41. package/esm/editor/src/mod.d.ts +2 -0
  42. package/esm/editor/src/mod.d.ts.map +1 -1
  43. package/esm/editor/src/mod.js +2 -0
  44. package/esm/editor/src/plugins/TrackSelecionPlugin.d.ts +6 -0
  45. package/esm/editor/src/plugins/TrackSelecionPlugin.d.ts.map +1 -0
  46. package/esm/editor/src/plugins/TrackSelecionPlugin.js +24 -0
  47. package/esm/editor/src/types.d.ts +20 -2
  48. package/esm/editor/src/types.d.ts.map +1 -1
  49. package/esm/editor/src/ui.d.ts +15 -0
  50. package/esm/editor/src/ui.d.ts.map +1 -0
  51. package/esm/editor/src/ui.js +16 -0
  52. package/esm/editor/src/utilities/SmartOutput.d.ts +9 -7
  53. package/esm/editor/src/utilities/SmartOutput.d.ts.map +1 -1
  54. package/esm/editor/src/utilities/SmartOutput.js +35 -20
  55. package/esm/editor/src/utilities/getShadowRoot.d.ts +2 -0
  56. package/esm/editor/src/utilities/getShadowRoot.d.ts.map +1 -0
  57. package/esm/editor/src/utilities/getShadowRoot.js +16 -0
  58. package/esm/editor/src/utilities/mod.d.ts +2 -0
  59. package/esm/editor/src/utilities/mod.d.ts.map +1 -1
  60. package/esm/editor/src/utilities/mod.js +2 -0
  61. package/esm/editor/src/utilities/toRawTextResult.d.ts +3 -0
  62. package/esm/editor/src/utilities/toRawTextResult.d.ts.map +1 -0
  63. package/esm/editor/src/utilities/toRawTextResult.js +21 -0
  64. package/esm/extension-autocomplete/src/AutocompletePlugin.d.ts +8 -0
  65. package/esm/extension-autocomplete/src/AutocompletePlugin.d.ts.map +1 -0
  66. package/esm/extension-autocomplete/src/AutocompletePlugin.js +232 -0
  67. package/esm/extension-autocomplete/src/DefaultRenderer.d.ts +17 -0
  68. package/esm/extension-autocomplete/src/DefaultRenderer.d.ts.map +1 -0
  69. package/esm/extension-autocomplete/src/DefaultRenderer.js +137 -0
  70. package/esm/extension-autocomplete/src/ExtensionAutocomplete.d.ts +26 -0
  71. package/esm/extension-autocomplete/src/ExtensionAutocomplete.d.ts.map +1 -0
  72. package/esm/extension-autocomplete/src/ExtensionAutocomplete.js +30 -0
  73. package/esm/extension-autocomplete/src/createDefaultMatcher.d.ts +11 -0
  74. package/esm/extension-autocomplete/src/createDefaultMatcher.d.ts.map +1 -0
  75. package/esm/extension-autocomplete/src/createDefaultMatcher.js +58 -0
  76. package/esm/extension-autocomplete/src/createRegexMatcher.d.ts +4 -0
  77. package/esm/extension-autocomplete/src/createRegexMatcher.d.ts.map +1 -0
  78. package/esm/extension-autocomplete/src/createRegexMatcher.js +50 -0
  79. package/esm/extension-autocomplete/src/mod.d.ts +3 -0
  80. package/esm/extension-autocomplete/src/mod.d.ts.map +1 -0
  81. package/esm/extension-autocomplete/src/mod.js +2 -0
  82. package/esm/extension-autocomplete/src/types.d.ts +60 -0
  83. package/esm/extension-autocomplete/src/types.d.ts.map +1 -0
  84. package/esm/extension-autocomplete/src/types.js +1 -0
  85. package/esm/extension-basic-editor/src/ExtensionHtml.d.ts +15 -0
  86. package/esm/extension-basic-editor/src/ExtensionHtml.d.ts.map +1 -0
  87. package/esm/extension-basic-editor/src/ExtensionHtml.js +108 -0
  88. package/esm/extension-basic-editor/src/NodeCodeBlock.d.ts +9 -0
  89. package/esm/extension-basic-editor/src/NodeCodeBlock.d.ts.map +1 -0
  90. package/esm/extension-basic-editor/src/NodeCodeBlock.js +58 -0
  91. package/esm/extension-basic-editor/src/remote-selection/ExtensionRemoteSelection.d.ts +24 -0
  92. package/esm/extension-basic-editor/src/remote-selection/ExtensionRemoteSelection.d.ts.map +1 -0
  93. package/esm/extension-basic-editor/src/remote-selection/ExtensionRemoteSelection.js +35 -0
  94. package/esm/extension-basic-editor/src/remote-selection/remoteSelectionPlugin.d.ts +25 -0
  95. package/esm/extension-basic-editor/src/remote-selection/remoteSelectionPlugin.d.ts.map +1 -0
  96. package/esm/extension-basic-editor/src/remote-selection/remoteSelectionPlugin.js +96 -0
  97. package/esm/extension-codemirror/src/ExtensionCodeMirror.d.ts +15 -2
  98. package/esm/extension-codemirror/src/ExtensionCodeMirror.d.ts.map +1 -1
  99. package/esm/extension-codemirror/src/ExtensionCodeMirror.js +74 -2
  100. package/esm/extension-codemirror/src/NodeCodeMirror.d.ts +13 -9
  101. package/esm/extension-codemirror/src/NodeCodeMirror.d.ts.map +1 -1
  102. package/esm/extension-codemirror/src/NodeCodeMirror.js +34 -121
  103. package/esm/extension-codemirror/src/codeMirrorBlockNodeView.d.ts +3 -2
  104. package/esm/extension-codemirror/src/codeMirrorBlockNodeView.d.ts.map +1 -1
  105. package/esm/extension-codemirror/src/codeMirrorBlockNodeView.js +164 -103
  106. package/esm/extension-codemirror/src/defaults.d.ts +1 -1
  107. package/esm/extension-codemirror/src/defaults.d.ts.map +1 -1
  108. package/esm/extension-codemirror/src/defaults.js +4 -3
  109. package/esm/extension-codemirror/src/languageLoaders.d.ts.map +1 -1
  110. package/esm/extension-codemirror/src/languageLoaders.js +1 -2
  111. package/esm/extension-codemirror/src/lsp/LSPExtension.d.ts +14 -0
  112. package/esm/extension-codemirror/src/lsp/LSPExtension.d.ts.map +1 -0
  113. package/esm/extension-codemirror/src/lsp/LSPExtension.js +38 -0
  114. package/esm/extension-codemirror/src/lsp/completion.d.ts +8 -0
  115. package/esm/extension-codemirror/src/lsp/completion.d.ts.map +1 -0
  116. package/esm/extension-codemirror/src/lsp/completion.js +179 -0
  117. package/esm/extension-codemirror/src/lsp/hover.d.ts +5 -0
  118. package/esm/extension-codemirror/src/lsp/hover.d.ts.map +1 -0
  119. package/esm/extension-codemirror/src/lsp/hover.js +81 -0
  120. package/esm/extension-codemirror/src/lsp/index.d.ts +7 -0
  121. package/esm/extension-codemirror/src/lsp/index.d.ts.map +1 -0
  122. package/esm/extension-codemirror/src/lsp/index.js +49 -0
  123. package/esm/extension-codemirror/src/lsp/plugin.d.ts +37 -0
  124. package/esm/extension-codemirror/src/lsp/plugin.d.ts.map +1 -0
  125. package/esm/extension-codemirror/src/lsp/plugin.js +125 -0
  126. package/esm/extension-codemirror/src/lsp/pos.d.ts +5 -0
  127. package/esm/extension-codemirror/src/lsp/pos.d.ts.map +1 -0
  128. package/esm/extension-codemirror/src/lsp/pos.js +8 -0
  129. package/esm/extension-codemirror/src/lsp/text.d.ts +2 -0
  130. package/esm/extension-codemirror/src/lsp/text.d.ts.map +1 -0
  131. package/esm/extension-codemirror/src/lsp/text.js +47 -0
  132. package/esm/extension-codemirror/src/lsp/theme.d.ts +2 -0
  133. package/esm/extension-codemirror/src/lsp/theme.d.ts.map +1 -0
  134. package/esm/extension-codemirror/src/lsp/theme.js +76 -0
  135. package/esm/extension-codemirror/src/{y-remote-selections.d.ts → remote-selections.d.ts} +5 -5
  136. package/esm/extension-codemirror/src/remote-selections.d.ts.map +1 -0
  137. package/esm/extension-codemirror/src/{y-remote-selections.js → remote-selections.js} +49 -69
  138. package/esm/extension-codemirror/src/remote-sync.d.ts +11 -0
  139. package/esm/extension-codemirror/src/remote-sync.d.ts.map +1 -0
  140. package/esm/extension-codemirror/src/{y-sync.js → remote-sync.js} +6 -6
  141. package/esm/extension-codemirror/src/types.d.ts +10 -10
  142. package/esm/extension-codemirror/src/types.d.ts.map +1 -1
  143. package/esm/extension-codemirror/src/utils.d.ts +7 -6
  144. package/esm/extension-codemirror/src/utils.d.ts.map +1 -1
  145. package/esm/extension-codemirror/src/utils.js +21 -10
  146. package/esm/extension-lsp/src/DiagnosticPlugin.d.ts +32 -0
  147. package/esm/extension-lsp/src/DiagnosticPlugin.d.ts.map +1 -0
  148. package/esm/extension-lsp/src/DiagnosticPlugin.js +131 -0
  149. package/esm/extension-lsp/src/ExtensionLsp.d.ts +25 -0
  150. package/esm/extension-lsp/src/ExtensionLsp.d.ts.map +1 -0
  151. package/esm/extension-lsp/src/ExtensionLsp.js +126 -0
  152. package/esm/extension-lsp/src/LSPClient.d.ts +56 -0
  153. package/esm/extension-lsp/src/LSPClient.d.ts.map +1 -0
  154. package/esm/extension-lsp/src/LSPClient.js +449 -0
  155. package/esm/extension-lsp/src/computeIncrementalChanges.d.ts +8 -0
  156. package/esm/extension-lsp/src/computeIncrementalChanges.d.ts.map +1 -0
  157. package/esm/extension-lsp/src/computeIncrementalChanges.js +82 -0
  158. package/esm/extension-lsp/src/createLspAutocomplete.d.ts +23 -0
  159. package/esm/extension-lsp/src/createLspAutocomplete.d.ts.map +1 -0
  160. package/esm/extension-lsp/src/createLspAutocomplete.js +68 -0
  161. package/esm/extension-lsp/src/mod.d.ts +4 -0
  162. package/esm/extension-lsp/src/mod.d.ts.map +1 -0
  163. package/esm/extension-lsp/src/mod.js +3 -0
  164. package/esm/extension-lsp/src/workspace.d.ts +62 -0
  165. package/esm/extension-lsp/src/workspace.d.ts.map +1 -0
  166. package/esm/extension-lsp/src/workspace.js +168 -0
  167. package/esm/extension-markdown/src/DocumentMarkdownInlineTokenizer.d.ts +36 -0
  168. package/esm/extension-markdown/src/DocumentMarkdownInlineTokenizer.d.ts.map +1 -0
  169. package/esm/extension-markdown/src/DocumentMarkdownInlineTokenizer.js +240 -0
  170. package/esm/extension-markdown/src/DocumentMarkdownTokenizer.d.ts +26 -0
  171. package/esm/extension-markdown/src/DocumentMarkdownTokenizer.d.ts.map +1 -0
  172. package/esm/extension-markdown/src/DocumentMarkdownTokenizer.js +115 -0
  173. package/esm/extension-markdown/src/ExtensionMarkdown.d.ts +22 -0
  174. package/esm/extension-markdown/src/ExtensionMarkdown.d.ts.map +1 -0
  175. package/esm/extension-markdown/src/ExtensionMarkdown.js +48 -0
  176. package/esm/extension-markdown/src/MarkdownParser.d.ts +61 -0
  177. package/esm/extension-markdown/src/MarkdownParser.d.ts.map +1 -0
  178. package/esm/extension-markdown/src/MarkdownParser.js +249 -0
  179. package/esm/extension-markdown/src/MarkdownSerializer.d.ts +42 -0
  180. package/esm/extension-markdown/src/MarkdownSerializer.d.ts.map +1 -0
  181. package/esm/extension-markdown/src/MarkdownSerializer.js +325 -0
  182. package/esm/extension-markdown/src/PositionMapper.d.ts +15 -0
  183. package/esm/extension-markdown/src/PositionMapper.d.ts.map +1 -0
  184. package/esm/extension-markdown/src/PositionMapper.js +100 -0
  185. package/esm/extension-markdown/src/TokenSource.d.ts +11 -0
  186. package/esm/extension-markdown/src/TokenSource.d.ts.map +1 -0
  187. package/esm/extension-markdown/src/TokenSource.js +39 -0
  188. package/esm/extension-markdown/src/mdToPmConverter.d.ts +5 -0
  189. package/esm/extension-markdown/src/mdToPmConverter.d.ts.map +1 -0
  190. package/esm/extension-markdown/src/mdToPmConverter.js +111 -0
  191. package/esm/extension-markdown/src/pmToMdConverter.d.ts +16 -0
  192. package/esm/extension-markdown/src/pmToMdConverter.d.ts.map +1 -0
  193. package/esm/extension-markdown/src/pmToMdConverter.js +433 -0
  194. package/esm/extension-markdown/src/token_handlers/basic_token_handlers.d.ts +4 -0
  195. package/esm/extension-markdown/src/token_handlers/basic_token_handlers.d.ts.map +1 -0
  196. package/esm/extension-markdown/src/token_handlers/basic_token_handlers.js +151 -0
  197. package/esm/extension-markdown/src/token_handlers/footnote_token_handlers.d.ts +3 -0
  198. package/esm/extension-markdown/src/token_handlers/footnote_token_handlers.d.ts.map +1 -0
  199. package/esm/extension-markdown/src/token_handlers/footnote_token_handlers.js +34 -0
  200. package/esm/extension-markdown/src/token_handlers/inline_token_handlers.d.ts +6 -0
  201. package/esm/extension-markdown/src/token_handlers/inline_token_handlers.d.ts.map +1 -0
  202. package/esm/extension-markdown/src/token_handlers/inline_token_handlers.js +380 -0
  203. package/esm/extension-markdown/src/token_handlers/lists_token_handlers.d.ts +3 -0
  204. package/esm/extension-markdown/src/token_handlers/lists_token_handlers.d.ts.map +1 -0
  205. package/esm/extension-markdown/src/token_handlers/lists_token_handlers.js +323 -0
  206. package/esm/extension-markdown/src/token_handlers/table_token_handlers.d.ts +9 -0
  207. package/esm/extension-markdown/src/token_handlers/table_token_handlers.d.ts.map +1 -0
  208. package/esm/extension-markdown/src/token_handlers/table_token_handlers.js +308 -0
  209. package/esm/extension-markdown/src/treeSitterTokenizer.d.ts +5 -0
  210. package/esm/extension-markdown/src/treeSitterTokenizer.d.ts.map +1 -0
  211. package/esm/extension-markdown/src/treeSitterTokenizer.js +769 -0
  212. package/esm/extension-markdown/src/types.d.ts +28 -0
  213. package/esm/extension-markdown/src/types.d.ts.map +1 -0
  214. package/esm/extension-markdown/src/types.js +131 -0
  215. package/esm/extension-markdown/src/utils.d.ts +8 -0
  216. package/esm/extension-markdown/src/utils.d.ts.map +1 -0
  217. package/esm/extension-markdown/src/utils.js +86 -0
  218. package/esm/tree-sitter-shim/src/main.d.ts +15 -0
  219. package/esm/tree-sitter-shim/src/main.d.ts.map +1 -0
  220. package/esm/tree-sitter-shim/src/main.js +25 -0
  221. package/esm/tree-sitter-shim/src/tree_sitter/node.d.ts +6 -0
  222. package/esm/tree-sitter-shim/src/tree_sitter/node.d.ts.map +1 -0
  223. package/esm/tree-sitter-shim/src/tree_sitter/node.js +1 -0
  224. package/esm/tree-sitter-shim/src/tree_sitter/parser.d.ts +7 -0
  225. package/esm/tree-sitter-shim/src/tree_sitter/parser.d.ts.map +1 -0
  226. package/esm/tree-sitter-shim/src/tree_sitter/parser.js +5 -0
  227. package/esm/tree-sitter-shim/src/tree_sitter/tree.d.ts +6 -0
  228. package/esm/tree-sitter-shim/src/tree_sitter/tree.d.ts.map +1 -0
  229. package/esm/tree-sitter-shim/src/tree_sitter/tree.js +1 -0
  230. package/esm/wasm/src/mod.d.ts +12 -0
  231. package/esm/wasm/src/mod.d.ts.map +1 -0
  232. package/esm/wasm/src/mod.js +48 -0
  233. package/esm/wasm/wasm.d.ts +138 -0
  234. package/esm/wasm/wasm.d.ts.map +1 -0
  235. package/esm/wasm/wasm.js +120 -0
  236. package/package.json +6 -26
  237. package/esm/extension-codemirror/src/NodeDocumentCode.d.ts +0 -7
  238. package/esm/extension-codemirror/src/NodeDocumentCode.d.ts.map +0 -1
  239. package/esm/extension-codemirror/src/NodeDocumentCode.js +0 -37
  240. package/esm/extension-codemirror/src/y-remote-selections.d.ts.map +0 -1
  241. package/esm/extension-codemirror/src/y-sync.d.ts +0 -11
  242. package/esm/extension-codemirror/src/y-sync.d.ts.map +0 -1
@@ -0,0 +1,62 @@
1
+ import type * as lsp from 'vscode-languageserver-protocol';
2
+ import type { EditorUi } from '../../editor/src/mod.js';
3
+ import { LSPClient } from './LSPClient.js';
4
+ import { PositionMapper } from '../../extension-markdown/src/PositionMapper.js';
5
+ export interface LspSource {
6
+ ui: EditorUi;
7
+ getMappedContent(): {
8
+ content: string;
9
+ mapper: PositionMapper;
10
+ };
11
+ }
12
+ export interface WorkspaceFile {
13
+ uri: string;
14
+ languageId: string;
15
+ version: number;
16
+ content: string;
17
+ source: LspSource;
18
+ getUi(): EditorUi | undefined;
19
+ mapper: PositionMapper;
20
+ }
21
+ interface WorkspaceFileUpdate {
22
+ file: WorkspaceFile;
23
+ prevDoc: string;
24
+ changes: lsp.TextDocumentContentChangeEvent[];
25
+ }
26
+ export declare abstract class Workspace {
27
+ readonly client: LSPClient;
28
+ abstract files: WorkspaceFile[];
29
+ protected isConnected: boolean;
30
+ constructor(client: LSPClient);
31
+ getFile(uri: string): WorkspaceFile | null;
32
+ abstract syncFiles(): readonly WorkspaceFileUpdate[];
33
+ requestFile(uri: string): Promise<WorkspaceFile | null>;
34
+ abstract openFile(uri: string, languageId: string, source: LspSource): void;
35
+ abstract changedFile(uri: string): void;
36
+ abstract closeFile(uri: string): void;
37
+ connected(): Promise<void>;
38
+ disconnected(): void;
39
+ getUi(uri: string): Promise<EditorUi | undefined>;
40
+ }
41
+ declare class DefaultWorkspaceFile implements WorkspaceFile {
42
+ readonly uri: string;
43
+ readonly languageId: string;
44
+ version: number;
45
+ content: string;
46
+ mapper: PositionMapper;
47
+ source: LspSource;
48
+ syncedContent: string;
49
+ constructor(uri: string, languageId: string, version: number, content: string, mapper: PositionMapper, source: LspSource);
50
+ getUi(): EditorUi;
51
+ }
52
+ export declare class DefaultWorkspace extends Workspace {
53
+ files: DefaultWorkspaceFile[];
54
+ private fileVersions;
55
+ nextFileVersion(uri: string): number;
56
+ syncFiles(): WorkspaceFileUpdate[];
57
+ changedFile(uri: string): Promise<void>;
58
+ openFile(uri: string, languageId: string, source: LspSource): void;
59
+ closeFile(uri: string): void;
60
+ }
61
+ export {};
62
+ //# sourceMappingURL=workspace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../../../src/extension-lsp/src/workspace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,gCAAgC,CAAC;AAG3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,gDAAgD,CAAC;AAGhF,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,QAAQ,CAAC;IACb,gBAAgB,IAAI;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,cAAc,CAAA;KAAE,CAAC;CACjE;AAED,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,SAAS,CAAC;IAClB,KAAK,IAAI,QAAQ,GAAG,SAAS,CAAC;IAC9B,MAAM,EAAE,cAAc,CAAC;CACxB;AAED,UAAU,mBAAmB;IAC3B,IAAI,EAAE,aAAa,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,GAAG,CAAC,8BAA8B,EAAE,CAAC;CAC/C;AAED,8BAAsB,SAAS;IAK3B,QAAQ,CAAC,MAAM,EAAE,SAAS;IAJ5B,QAAQ,CAAC,KAAK,EAAE,aAAa,EAAE,CAAC;IAChC,SAAS,CAAC,WAAW,UAAS;gBAGnB,MAAM,EAAE,SAAS;IAG5B,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI;IAI1C,QAAQ,CAAC,SAAS,IAAI,SAAS,mBAAmB,EAAE;IAEpD,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAIvD,QAAQ,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,IAAI;IAC3E,QAAQ,CAAC,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IACvC,QAAQ,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAE/B,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAOhC,YAAY,IAAI,IAAI;IAOpB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;CAIlD;AAED,cAAM,oBAAqB,YAAW,aAAa;IAG/C,QAAQ,CAAC,GAAG,EAAE,MAAM;IACpB,QAAQ,CAAC,UAAU,EAAE,MAAM;IACpB,OAAO,EAAE,MAAM;IACf,OAAO,EAAE,MAAM;IACf,MAAM,EAAE,cAAc;IACtB,MAAM,EAAE,SAAS;IAPnB,aAAa,EAAE,MAAM,CAAM;gBAEvB,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,EACpB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,cAAc,EACtB,MAAM,EAAE,SAAS;IAI1B,KAAK;CAGN;AAED,qBAAa,gBAAiB,SAAQ,SAAS;IAC7C,KAAK,EAAE,oBAAoB,EAAE,CAAM;IACnC,OAAO,CAAC,YAAY,CAAkD;IAEtE,eAAe,CAAC,GAAG,EAAE,MAAM;IAI3B,SAAS;IAaH,WAAW,CAAC,GAAG,EAAE,MAAM;IAkC7B,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS;IAsB3D,SAAS,CAAC,GAAG,EAAE,MAAM;CAOtB"}
@@ -0,0 +1,168 @@
1
+ import { TextDocumentSyncKind } from 'vscode-languageserver-protocol';
2
+ import { computeIncrementalChanges } from './computeIncrementalChanges.js';
3
+ export class Workspace {
4
+ constructor(client) {
5
+ Object.defineProperty(this, "client", {
6
+ enumerable: true,
7
+ configurable: true,
8
+ writable: true,
9
+ value: client
10
+ });
11
+ Object.defineProperty(this, "isConnected", {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value: false
16
+ });
17
+ }
18
+ getFile(uri) {
19
+ return this.files.find((f) => f.uri == uri) || null;
20
+ }
21
+ requestFile(uri) {
22
+ return Promise.resolve(this.getFile(uri));
23
+ }
24
+ async connected() {
25
+ this.isConnected = true;
26
+ for await (const file of this.files) {
27
+ const result = await this.client.didOpen(file);
28
+ }
29
+ }
30
+ disconnected() {
31
+ for (const file of this.files) {
32
+ this.client.workspace.closeFile(file.uri);
33
+ }
34
+ this.isConnected = false;
35
+ }
36
+ getUi(uri) {
37
+ const file = this.getFile(uri);
38
+ return Promise.resolve(file ? file.getUi() : undefined);
39
+ }
40
+ }
41
+ class DefaultWorkspaceFile {
42
+ constructor(uri, languageId, version, content, mapper, source) {
43
+ Object.defineProperty(this, "uri", {
44
+ enumerable: true,
45
+ configurable: true,
46
+ writable: true,
47
+ value: uri
48
+ });
49
+ Object.defineProperty(this, "languageId", {
50
+ enumerable: true,
51
+ configurable: true,
52
+ writable: true,
53
+ value: languageId
54
+ });
55
+ Object.defineProperty(this, "version", {
56
+ enumerable: true,
57
+ configurable: true,
58
+ writable: true,
59
+ value: version
60
+ });
61
+ Object.defineProperty(this, "content", {
62
+ enumerable: true,
63
+ configurable: true,
64
+ writable: true,
65
+ value: content
66
+ });
67
+ Object.defineProperty(this, "mapper", {
68
+ enumerable: true,
69
+ configurable: true,
70
+ writable: true,
71
+ value: mapper
72
+ });
73
+ Object.defineProperty(this, "source", {
74
+ enumerable: true,
75
+ configurable: true,
76
+ writable: true,
77
+ value: source
78
+ });
79
+ Object.defineProperty(this, "syncedContent", {
80
+ enumerable: true,
81
+ configurable: true,
82
+ writable: true,
83
+ value: ''
84
+ });
85
+ }
86
+ getUi() {
87
+ return this.source.ui;
88
+ }
89
+ }
90
+ export class DefaultWorkspace extends Workspace {
91
+ constructor() {
92
+ super(...arguments);
93
+ Object.defineProperty(this, "files", {
94
+ enumerable: true,
95
+ configurable: true,
96
+ writable: true,
97
+ value: []
98
+ });
99
+ Object.defineProperty(this, "fileVersions", {
100
+ enumerable: true,
101
+ configurable: true,
102
+ writable: true,
103
+ value: Object.create(null)
104
+ });
105
+ }
106
+ nextFileVersion(uri) {
107
+ return this.fileVersions[uri] = (this.fileVersions[uri] ?? -1) + 1;
108
+ }
109
+ syncFiles() {
110
+ if (!this.client.supportSync) {
111
+ return [];
112
+ }
113
+ const result = [];
114
+ for (const file of this.files) {
115
+ this.changedFile(file.uri);
116
+ }
117
+ return result;
118
+ }
119
+ async changedFile(uri) {
120
+ const file = this.files.find((f) => f.uri == uri) || null;
121
+ if (file) {
122
+ const { content, mapper } = file.source.getMappedContent();
123
+ if (!this.isConnected) {
124
+ file.content = content;
125
+ file.mapper = mapper;
126
+ return;
127
+ }
128
+ if (await this.client.notification('textDocument/didChange', {
129
+ textDocument: { uri: file.uri, version: file.version },
130
+ contentChanges: contentChangesFor(file, content, mapper, this.client.supportSync == TextDocumentSyncKind.Incremental),
131
+ })) {
132
+ file.syncedContent = file.content;
133
+ file.content = content;
134
+ file.mapper = mapper;
135
+ file.version = this.nextFileVersion(file.uri);
136
+ }
137
+ }
138
+ }
139
+ openFile(uri, languageId, source) {
140
+ // if (uri) {}
141
+ if (this.getFile(uri)) {
142
+ this.closeFile(uri);
143
+ }
144
+ const mappedContent = source.getMappedContent();
145
+ const { content, mapper } = mappedContent;
146
+ const file = new DefaultWorkspaceFile(uri, languageId, this.nextFileVersion(uri), content, mapper, source);
147
+ this.files.push(file);
148
+ this.client.didOpen(file);
149
+ }
150
+ closeFile(uri) {
151
+ const file = this.getFile(uri);
152
+ if (file) {
153
+ this.files = this.files.filter((f) => f.uri !== uri);
154
+ this.client.didClose(uri);
155
+ }
156
+ }
157
+ }
158
+ var Sync;
159
+ (function (Sync) {
160
+ Sync[Sync["AlwaysIfSmaller"] = 1024] = "AlwaysIfSmaller";
161
+ })(Sync || (Sync = {}));
162
+ function contentChangesFor(file, newContent, mapper, supportInc) {
163
+ if (!supportInc || newContent.length < Sync.AlwaysIfSmaller) {
164
+ return [{ text: newContent }];
165
+ }
166
+ const changes = computeIncrementalChanges(file.content, newContent);
167
+ return changes.reverse();
168
+ }
@@ -0,0 +1,36 @@
1
+ import type { Mark, Node } from 'prosemirror-model';
2
+ import { Token } from './types.js';
3
+ export type MarkTokenizerSpec = {
4
+ open?: string | ((mark: Mark) => Token);
5
+ close?: string | ((mark: Mark) => Token);
6
+ mixable?: boolean;
7
+ expelEnclosingWhitespace?: boolean;
8
+ escape?: boolean;
9
+ };
10
+ export type DocumentMarkdownTokenizerSpec = {
11
+ open?: string | ((node: Node) => Token);
12
+ close?: string | ((node: Node) => Token);
13
+ selfClose?: string | ((node: Node) => Token);
14
+ };
15
+ export declare class DocumentMarkdownInlineTokenizer {
16
+ readonly nodes: {
17
+ [node: string]: (node: Node, index: number) => DocumentMarkdownTokenizerSpec;
18
+ };
19
+ readonly marks: {
20
+ [mark: string]: MarkTokenizerSpec;
21
+ };
22
+ readonly options: {
23
+ hardBreakNodeName: string;
24
+ };
25
+ constructor(nodes: {
26
+ [node: string]: (node: Node, index: number) => DocumentMarkdownTokenizerSpec;
27
+ }, marks: {
28
+ [mark: string]: MarkTokenizerSpec;
29
+ }, options: {
30
+ hardBreakNodeName: string;
31
+ });
32
+ private getMark;
33
+ renderInline(parent: Node, currentPos: number, level: number): Array<Token>;
34
+ markString(mark: Mark, open: boolean, tokens: Token[]): void;
35
+ }
36
+ //# sourceMappingURL=DocumentMarkdownInlineTokenizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DocumentMarkdownInlineTokenizer.d.ts","sourceRoot":"","sources":["../../../src/extension-markdown/src/DocumentMarkdownInlineTokenizer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,KAAK,KAAK,CAAC,CAAC;IACxC,KAAK,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,KAAK,KAAK,CAAC,CAAC;IACzC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG;IAC1C,IAAI,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,KAAK,KAAK,CAAC,CAAC;IACxC,KAAK,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,KAAK,KAAK,CAAC,CAAC;IACzC,SAAS,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,KAAK,KAAK,CAAC,CAAC;CAC9C,CAAC;AAuCF,qBAAa,+BAA+B;IAExC,QAAQ,CAAC,KAAK,EAAE;QACd,CAAC,IAAI,EAAE,MAAM,GAAG,CACd,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,MAAM,KACV,6BAA6B,CAAC;KACpC;IACD,QAAQ,CAAC,KAAK,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,CAAA;KAAE;IACrD,QAAQ,CAAC,OAAO,EAAE;QAAE,iBAAiB,EAAE,MAAM,CAAA;KAAE;gBAPtC,KAAK,EAAE;QACd,CAAC,IAAI,EAAE,MAAM,GAAG,CACd,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,MAAM,KACV,6BAA6B,CAAC;KACpC,EACQ,KAAK,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,CAAA;KAAE,EAC5C,OAAO,EAAE;QAAE,iBAAiB,EAAE,MAAM,CAAA;KAAE;IAIjD,OAAO,CAAC,OAAO;IAaf,YAAY,CAAC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC;IAwK3E,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE;CAoCtD"}
@@ -0,0 +1,240 @@
1
+ import { Token } from './types.js';
2
+ const blankMark = { open: '', close: '', mixable: true };
3
+ const blankNode = { open: '', close: '' };
4
+ function generateInlineTokens(input) {
5
+ const tokens = [];
6
+ let currentPos = -1;
7
+ let currentText = '';
8
+ for (const [text, inlinePos] of input) {
9
+ if (true || currentPos !== inlinePos) {
10
+ if (currentText.length > 0) {
11
+ const token = new Token('text', '', 0);
12
+ token.meta = 'generateInline1';
13
+ token.map = [currentPos];
14
+ token.content = currentText;
15
+ tokens.push(token);
16
+ }
17
+ currentText = '';
18
+ currentPos = inlinePos;
19
+ }
20
+ currentText += text;
21
+ }
22
+ if (currentText.length > 0) {
23
+ const token = new Token('text', '', 0);
24
+ token.meta = 'generateInline2';
25
+ token.map = [currentPos];
26
+ token.content = currentText;
27
+ tokens.push(token);
28
+ }
29
+ return tokens;
30
+ }
31
+ export class DocumentMarkdownInlineTokenizer {
32
+ constructor(nodes, marks, options) {
33
+ Object.defineProperty(this, "nodes", {
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true,
37
+ value: nodes
38
+ });
39
+ Object.defineProperty(this, "marks", {
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true,
43
+ value: marks
44
+ });
45
+ Object.defineProperty(this, "options", {
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true,
49
+ value: options
50
+ });
51
+ }
52
+ getMark(name) {
53
+ let info = this.marks[name];
54
+ if (!info) {
55
+ // if (this.options.strict !== false) {
56
+ // throw new Error(
57
+ // `Mark type \`${name}\` not supported by Markdown renderer`,
58
+ // );
59
+ // }
60
+ return blankMark;
61
+ }
62
+ return info;
63
+ }
64
+ renderInline(parent, currentPos, level) {
65
+ const active = [];
66
+ const trailing = [];
67
+ const inlineTokens = [];
68
+ const progress = (node, offset, index) => {
69
+ const inlinePos = currentPos + offset;
70
+ let marks = node ? node.marks : [];
71
+ // Remove marks from `hard_break` that are the last node inside
72
+ // that mark to prevent parser edge cases with new lines just
73
+ // before closing marks.
74
+ // TODO:
75
+ if (node && node.type.name === this.options.hardBreakNodeName) {
76
+ marks = marks.filter((m) => {
77
+ if (index + 1 == parent.childCount)
78
+ return false;
79
+ let next = parent.child(index + 1);
80
+ return m.isInSet(next.marks) &&
81
+ (!next.isText || /\S/.test(next.text));
82
+ });
83
+ }
84
+ const leading = trailing.splice(0, trailing.length);
85
+ // If whitespace has to be expelled from the node, adjust
86
+ // leading and trailing accordingly.
87
+ if (node.isText && marks.some((mark) => {
88
+ let info = this.getMark(mark.type.name);
89
+ return info && info.expelEnclosingWhitespace && !mark.isInSet(active);
90
+ })) {
91
+ let [_, lead, rest] = /^(\s*)(.*)$/m.exec(node.text);
92
+ if (lead) {
93
+ leading.push([lead, inlinePos]);
94
+ node = rest ? node.withText(rest) : null;
95
+ if (!node)
96
+ marks = active;
97
+ }
98
+ }
99
+ if (node.isText && marks.some((mark) => {
100
+ let info = this.getMark(mark.type.name);
101
+ return info && info.expelEnclosingWhitespace &&
102
+ (index == parent.childCount - 1 ||
103
+ !mark.isInSet(parent.child(index + 1).marks));
104
+ })) {
105
+ let [_, rest, trail] = /^(.*?)(\s*)$/m.exec(node.text);
106
+ if (trail) {
107
+ trailing.push([trail, inlinePos]);
108
+ node = rest ? node.withText(rest) : null;
109
+ if (!node)
110
+ marks = active;
111
+ }
112
+ }
113
+ let inner = marks.length ? marks[marks.length - 1] : null;
114
+ let noEsc = inner && this.getMark(inner.type.name).escape === false;
115
+ let len = marks.length - (noEsc ? 1 : 0);
116
+ // Try to reorder 'mixable' marks, such as em and strong, which
117
+ // in Markdown may be opened and closed in different order, so
118
+ // that order of the marks for the token matches the order in
119
+ // active.
120
+ outer: for (let i = 0; i < len; i++) {
121
+ let mark = marks[i];
122
+ if (!this.getMark(mark.type.name).mixable)
123
+ break;
124
+ for (let j = 0; j < active.length; j++) {
125
+ let other = active[j];
126
+ if (!this.getMark(other.type.name).mixable)
127
+ break;
128
+ if (mark.eq(other)) {
129
+ if (i > j) {
130
+ marks = marks.slice(0, j).concat(mark).concat(marks.slice(j, i))
131
+ .concat(marks.slice(i + 1, len));
132
+ }
133
+ else if (j > i) {
134
+ marks = marks.slice(0, i).concat(marks.slice(i + 1, j)).concat(mark).concat(marks.slice(j, len));
135
+ }
136
+ continue outer;
137
+ }
138
+ }
139
+ }
140
+ // Find the prefix of the mark set that didn't change
141
+ let keep = 0;
142
+ while (keep < Math.min(active.length, len) && marks[keep].eq(active[keep]))
143
+ ++keep;
144
+ // Close the marks that need to be closed
145
+ while (keep < active.length) {
146
+ const x = active.pop();
147
+ this.markString(x, false, inlineTokens);
148
+ }
149
+ // Output any previously expelled trailing whitespace outside the marks
150
+ inlineTokens.push(...generateInlineTokens(leading.splice(0, leading.length)));
151
+ // Open the marks that need to be opened
152
+ while (active.length < len) {
153
+ let add = marks[active.length];
154
+ active.push(add);
155
+ this.markString(add, true, inlineTokens);
156
+ }
157
+ // Render the node. Special case code marks, since their content
158
+ // may not be escaped.
159
+ if (noEsc && node.isText) {
160
+ this.markString(inner, true, inlineTokens);
161
+ if (node.text) {
162
+ const token = new Token('text', '', 0);
163
+ token.meta = 'noEscText';
164
+ token.map = [inlinePos];
165
+ token.content = node.text;
166
+ inlineTokens.push(token);
167
+ }
168
+ this.markString(inner, false, inlineTokens);
169
+ }
170
+ else {
171
+ const nodeSpec = this.nodes[node.type.name]
172
+ ? this.nodes[node.type.name](node, currentPos)
173
+ : blankNode;
174
+ let tag = '';
175
+ if (node.type.spec.toDOM) {
176
+ const dom = node.type.spec.toDOM(node);
177
+ if (Array.isArray(dom) && dom.length > 0) {
178
+ tag = dom[0];
179
+ }
180
+ }
181
+ if (nodeSpec.selfClose) {
182
+ if (typeof nodeSpec.selfClose === 'string') {
183
+ const token = new Token(nodeSpec.selfClose, tag, 0);
184
+ token.meta = 'nodeSpec.selfClose';
185
+ token.level = level;
186
+ token.map = [inlinePos];
187
+ inlineTokens.push(token);
188
+ }
189
+ else {
190
+ const token = nodeSpec.selfClose(node);
191
+ token.meta = '!nodeSpec.selfClose';
192
+ token.level = level;
193
+ token.map = [inlinePos];
194
+ inlineTokens.push(token);
195
+ }
196
+ }
197
+ }
198
+ };
199
+ parent.forEach((child, offset, index) => progress(child, offset, index));
200
+ // Close the marks that need to be closed
201
+ while (active.length > 0) {
202
+ const x = active.pop();
203
+ this.markString(x, false, inlineTokens);
204
+ }
205
+ // Output any previously expelled trailing whitespace outside the marks
206
+ inlineTokens.push(...generateInlineTokens(trailing.splice(0, trailing.length)));
207
+ return inlineTokens;
208
+ }
209
+ markString(mark, open, tokens) {
210
+ let info = this.getMark(mark.type.name);
211
+ let value = open ? info.open : info.close;
212
+ if (!value) {
213
+ /** Skip unknown marks (like textColor, highlight) - they'll be lost in markdown but won't crash */
214
+ console.warn('Unsupported mark type for markdown: ' + mark.type.name +
215
+ ', available types: ' +
216
+ Object.keys(this.marks).join(', ') + '. Mark will be ignored.');
217
+ return;
218
+ }
219
+ const token = typeof value == 'string' ? value : value(mark);
220
+ let tag = '';
221
+ if (mark.type.spec.toDOM) {
222
+ const dom = mark.type.spec.toDOM(mark, true);
223
+ if (Array.isArray(dom) && dom.length > 0) {
224
+ tag = dom[0];
225
+ }
226
+ }
227
+ if (typeof value === 'string') {
228
+ const token = new Token(value, tag, open ? 1 : -1);
229
+ token.meta = 'markString';
230
+ tokens.push(token);
231
+ }
232
+ else {
233
+ const token = value(mark);
234
+ if (token) {
235
+ token.meta = token.meta || 'markString()';
236
+ tokens.push(token);
237
+ }
238
+ }
239
+ }
240
+ }
@@ -0,0 +1,26 @@
1
+ import type { Node } from 'prosemirror-model';
2
+ import { Token } from './types.js';
3
+ import { DocumentMarkdownInlineTokenizer, DocumentMarkdownTokenizerSpec, MarkTokenizerSpec } from './DocumentMarkdownInlineTokenizer.js';
4
+ export declare class DocumentMarkdownTokenizer {
5
+ readonly nodes: {
6
+ [node: string]: (node: Node, index: number) => DocumentMarkdownTokenizerSpec;
7
+ };
8
+ readonly marks: {
9
+ [mark: string]: MarkTokenizerSpec;
10
+ };
11
+ readonly options: {
12
+ hardBreakNodeName: string;
13
+ };
14
+ private tokens;
15
+ inlineTokenizer: DocumentMarkdownInlineTokenizer;
16
+ constructor(nodes: {
17
+ [node: string]: (node: Node, index: number) => DocumentMarkdownTokenizerSpec;
18
+ }, marks: {
19
+ [mark: string]: MarkTokenizerSpec;
20
+ }, options?: {
21
+ hardBreakNodeName: string;
22
+ });
23
+ iterateNode(node: Node, currentPos: number, level?: number): void;
24
+ serialize(content: Node, options?: {}): Token[];
25
+ }
26
+ //# sourceMappingURL=DocumentMarkdownTokenizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DocumentMarkdownTokenizer.d.ts","sourceRoot":"","sources":["../../../src/extension-markdown/src/DocumentMarkdownTokenizer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EACL,+BAA+B,EAC/B,6BAA6B,EAC7B,iBAAiB,EAClB,MAAM,sCAAsC,CAAC;AAI9C,qBAAa,yBAAyB;IAKlC,QAAQ,CAAC,KAAK,EAAE;QACd,CAAC,IAAI,EAAE,MAAM,GAAG,CACd,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,MAAM,KACV,6BAA6B,CAAC;KACpC;IACD,QAAQ,CAAC,KAAK,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,CAAA;KAAE;IACrD,QAAQ,CAAC,OAAO,EAAE;QAAE,iBAAiB,EAAE,MAAM,CAAA;KAAE;IAXjD,OAAO,CAAC,MAAM,CAAoB;IAClC,eAAe,EAAE,+BAA+B,CAAC;gBAGtC,KAAK,EAAE;QACd,CAAC,IAAI,EAAE,MAAM,GAAG,CACd,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,MAAM,KACV,6BAA6B,CAAC;KACpC,EACQ,KAAK,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,CAAA;KAAE,EAC5C,OAAO,GAAE;QAAE,iBAAiB,EAAE,MAAM,CAAA;KAE5C;IASH,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,SAAK;IA8EtD,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,GAAE,EAAO,GAAG,KAAK,EAAE;CAIpD"}
@@ -0,0 +1,115 @@
1
+ import { Token } from './types.js';
2
+ import { DocumentMarkdownInlineTokenizer, } from './DocumentMarkdownInlineTokenizer.js';
3
+ const blankNode = { open: '', close: '' };
4
+ export class DocumentMarkdownTokenizer {
5
+ constructor(nodes, marks, options = {
6
+ hardBreakNodeName: 'hard_break',
7
+ }) {
8
+ Object.defineProperty(this, "nodes", {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value: nodes
13
+ });
14
+ Object.defineProperty(this, "marks", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: marks
19
+ });
20
+ Object.defineProperty(this, "options", {
21
+ enumerable: true,
22
+ configurable: true,
23
+ writable: true,
24
+ value: options
25
+ });
26
+ Object.defineProperty(this, "tokens", {
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true,
30
+ value: []
31
+ });
32
+ Object.defineProperty(this, "inlineTokenizer", {
33
+ enumerable: true,
34
+ configurable: true,
35
+ writable: true,
36
+ value: void 0
37
+ });
38
+ this.inlineTokenizer = new DocumentMarkdownInlineTokenizer(nodes, marks, options);
39
+ }
40
+ iterateNode(node, currentPos, level = -1) {
41
+ const nodeSpec = this.nodes[node.type.name]
42
+ ? this.nodes[node.type.name](node, currentPos)
43
+ : blankNode;
44
+ let tag = '';
45
+ if (node.type.spec.toDOM) {
46
+ const dom = node.type.spec.toDOM(node);
47
+ if (Array.isArray(dom) && dom.length > 0) {
48
+ tag = dom[0];
49
+ }
50
+ }
51
+ if (nodeSpec.open) {
52
+ if (typeof nodeSpec.open === 'string') {
53
+ const token = new Token(nodeSpec.open, tag, 1);
54
+ token.level = level;
55
+ token.meta = 'nodeSpec.open';
56
+ token.map = [currentPos];
57
+ this.tokens.push(token);
58
+ }
59
+ else {
60
+ const token = nodeSpec.open(node);
61
+ token.level = level;
62
+ token.meta = 'nodeSpec.open()';
63
+ token.map = [currentPos];
64
+ this.tokens.push(token);
65
+ }
66
+ }
67
+ if (nodeSpec.selfClose) {
68
+ if (typeof nodeSpec.selfClose === 'string') {
69
+ const token = new Token(nodeSpec.selfClose, tag, 0);
70
+ token.level = level;
71
+ token.map = [currentPos];
72
+ this.tokens.push(token);
73
+ }
74
+ else {
75
+ const token = nodeSpec.selfClose(node);
76
+ token.level = level;
77
+ token.map = [currentPos];
78
+ this.tokens.push(token);
79
+ }
80
+ return;
81
+ }
82
+ if (node.inlineContent) {
83
+ const token = new Token('inline', '', 0);
84
+ token.level = level + 1;
85
+ token.map = [currentPos];
86
+ this.tokens.push(token);
87
+ token.children = this.inlineTokenizer.renderInline(node, currentPos + 1, level + 1);
88
+ }
89
+ else if (node.childCount > 0) {
90
+ node.forEach((child, offset) => {
91
+ this.iterateNode(child, currentPos + offset + 1, level + 1);
92
+ });
93
+ }
94
+ if (nodeSpec.close) {
95
+ if (typeof nodeSpec.close === 'string') {
96
+ const token = new Token(nodeSpec.close, tag, -1);
97
+ token.meta = 'nodeSpec.close';
98
+ token.level = level;
99
+ // token.map = [currentPos];
100
+ this.tokens.push(token);
101
+ }
102
+ else {
103
+ const token = nodeSpec.close(node);
104
+ token.meta = 'nodeSpec.close()';
105
+ token.level = level;
106
+ // token.map = [currentPos];
107
+ this.tokens.push(token);
108
+ }
109
+ }
110
+ }
111
+ serialize(content, options = {}) {
112
+ this.iterateNode(content, -1); // doc does not have index, so I put -1 for correct calculation
113
+ return this.tokens;
114
+ }
115
+ }