@dou-ui/code 0.0.0-stage → 0.1.0-alpha.0

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 (158) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +10 -2
  3. package/dist/_virtual/_rolldown/runtime.js +12 -0
  4. package/dist/assets/default-BZBMZKf_.js.map +1 -0
  5. package/dist/code-diff.js +6 -0
  6. package/dist/code-diff.js.map +1 -0
  7. package/dist/code-diff.vue_vue_type_script_setup_true_lang.js +792 -0
  8. package/dist/code-diff.vue_vue_type_script_setup_true_lang.js.map +1 -0
  9. package/dist/code-editor.js +6 -0
  10. package/dist/code-editor.js.map +1 -0
  11. package/dist/code-editor.vue_vue_type_script_setup_true_lang.js +4917 -0
  12. package/dist/code-editor.vue_vue_type_script_setup_true_lang.js.map +1 -0
  13. package/dist/code-input.js +6 -0
  14. package/dist/code-input.js.map +1 -0
  15. package/dist/code-input.vue_vue_type_script_setup_true_lang.js +237 -0
  16. package/dist/code-input.vue_vue_type_script_setup_true_lang.js.map +1 -0
  17. package/dist/code-keys.js +42 -0
  18. package/dist/code-keys.js.map +1 -0
  19. package/dist/code-keys.vue_vue_type_script_setup_true_lang.js +168 -0
  20. package/dist/code-keys.vue_vue_type_script_setup_true_lang.js.map +1 -0
  21. package/dist/code-keys2.js +6 -0
  22. package/dist/code-keys2.js.map +1 -0
  23. package/dist/collaboration/index.js +255 -0
  24. package/dist/collaboration/index.js.map +1 -0
  25. package/dist/completion/match.js +55 -0
  26. package/dist/completion/match.js.map +1 -0
  27. package/dist/completion/snippet.js +71 -0
  28. package/dist/completion/snippet.js.map +1 -0
  29. package/dist/core/brackets.js +55 -0
  30. package/dist/core/brackets.js.map +1 -0
  31. package/dist/core/changes.js +185 -0
  32. package/dist/core/changes.js.map +1 -0
  33. package/dist/core/chars.js +130 -0
  34. package/dist/core/chars.js.map +1 -0
  35. package/dist/core/commands.js +910 -0
  36. package/dist/core/commands.js.map +1 -0
  37. package/dist/core/diff.js +215 -0
  38. package/dist/core/diff.js.map +1 -0
  39. package/dist/core/folding.js +87 -0
  40. package/dist/core/folding.js.map +1 -0
  41. package/dist/core/history.js +74 -0
  42. package/dist/core/history.js.map +1 -0
  43. package/dist/core/keymap.js +326 -0
  44. package/dist/core/keymap.js.map +1 -0
  45. package/dist/core/search.js +91 -0
  46. package/dist/core/search.js.map +1 -0
  47. package/dist/core/selection.js +88 -0
  48. package/dist/core/selection.js.map +1 -0
  49. package/dist/core/text.js +320 -0
  50. package/dist/core/text.js.map +1 -0
  51. package/dist/core/transaction.js +98 -0
  52. package/dist/core/transaction.js.map +1 -0
  53. package/dist/extension.js +16 -0
  54. package/dist/extension.js.map +1 -0
  55. package/dist/index.js +38 -0
  56. package/dist/index.js.map +1 -0
  57. package/dist/language/highlighter.js +336 -0
  58. package/dist/language/highlighter.js.map +1 -0
  59. package/dist/language/language.js +138 -0
  60. package/dist/language/language.js.map +1 -0
  61. package/dist/language/stream.js +112 -0
  62. package/dist/language/stream.js.map +1 -0
  63. package/dist/language/to-html.js +36 -0
  64. package/dist/language/to-html.js.map +1 -0
  65. package/dist/language/worker-client.js +198 -0
  66. package/dist/language/worker-client.js.map +1 -0
  67. package/dist/language/worker-protocol.js +48 -0
  68. package/dist/language/worker-protocol.js.map +1 -0
  69. package/dist/languages/css.js +128 -0
  70. package/dist/languages/css.js.map +1 -0
  71. package/dist/languages/html.js +175 -0
  72. package/dist/languages/html.js.map +1 -0
  73. package/dist/languages/javascript.js +300 -0
  74. package/dist/languages/javascript.js.map +1 -0
  75. package/dist/languages/json.js +45 -0
  76. package/dist/languages/json.js.map +1 -0
  77. package/dist/languages/markdown.js +82 -0
  78. package/dist/languages/markdown.js.map +1 -0
  79. package/dist/languages/python.js +88 -0
  80. package/dist/languages/python.js.map +1 -0
  81. package/dist/languages/shell.js +153 -0
  82. package/dist/languages/shell.js.map +1 -0
  83. package/dist/languages/sql.js +91 -0
  84. package/dist/languages/sql.js.map +1 -0
  85. package/dist/languages/yaml.js +85 -0
  86. package/dist/languages/yaml.js.map +1 -0
  87. package/dist/locale.js +164 -0
  88. package/dist/locale.js.map +1 -0
  89. package/dist/lsp/index.js +715 -0
  90. package/dist/lsp/index.js.map +1 -0
  91. package/dist/lsp/markup.js +139 -0
  92. package/dist/lsp/markup.js.map +1 -0
  93. package/dist/render-part.js +14 -0
  94. package/dist/render-part.js.map +1 -0
  95. package/dist/shiki/index.js +140 -0
  96. package/dist/shiki/index.js.map +1 -0
  97. package/dist/style.css +1 -0
  98. package/dist/style.d.ts +1 -0
  99. package/dist/style.js +4 -0
  100. package/dist/types/code-diff.vue.d.ts +45 -0
  101. package/dist/types/code-editor.vue.d.ts +43 -0
  102. package/dist/types/code-input.vue.d.ts +32 -0
  103. package/dist/types/code-keys.d.ts +9 -0
  104. package/dist/types/code-keys.vue.d.ts +8 -0
  105. package/dist/types/collaboration/index.d.ts +36 -0
  106. package/dist/types/completion/match.d.ts +13 -0
  107. package/dist/types/completion/snippet.d.ts +17 -0
  108. package/dist/types/core/brackets.d.ts +15 -0
  109. package/dist/types/core/changes.d.ts +52 -0
  110. package/dist/types/core/chars.d.ts +24 -0
  111. package/dist/types/core/commands.d.ts +199 -0
  112. package/dist/types/core/diff.d.ts +52 -0
  113. package/dist/types/core/folding.d.ts +23 -0
  114. package/dist/types/core/history.d.ts +24 -0
  115. package/dist/types/core/keymap.d.ts +29 -0
  116. package/dist/types/core/search.d.ts +37 -0
  117. package/dist/types/core/selection.d.ts +28 -0
  118. package/dist/types/core/text.d.ts +79 -0
  119. package/dist/types/core/transaction.d.ts +65 -0
  120. package/dist/types/extension.d.ts +321 -0
  121. package/dist/types/index.d.ts +159 -0
  122. package/dist/types/language/highlighter.d.ts +99 -0
  123. package/dist/types/language/language.d.ts +100 -0
  124. package/dist/types/language/stream.d.ts +56 -0
  125. package/dist/types/language/to-html.d.ts +17 -0
  126. package/dist/types/language/worker-client.d.ts +52 -0
  127. package/dist/types/language/worker-protocol.d.ts +50 -0
  128. package/dist/types/languages/css.d.ts +17 -0
  129. package/dist/types/languages/html.d.ts +34 -0
  130. package/dist/types/languages/javascript.d.ts +29 -0
  131. package/dist/types/languages/json.d.ts +7 -0
  132. package/dist/types/languages/markdown.d.ts +17 -0
  133. package/dist/types/languages/python.d.ts +9 -0
  134. package/dist/types/languages/shell.d.ts +11 -0
  135. package/dist/types/languages/sql.d.ts +9 -0
  136. package/dist/types/languages/yaml.d.ts +14 -0
  137. package/dist/types/locale.d.ts +79 -0
  138. package/dist/types/lsp/index.d.ts +119 -0
  139. package/dist/types/lsp/markup.d.ts +14 -0
  140. package/dist/types/render-part.d.ts +14 -0
  141. package/dist/types/shiki/index.d.ts +63 -0
  142. package/dist/types/types.d.ts +267 -0
  143. package/dist/types/view/input.d.ts +12 -0
  144. package/dist/types/view/layout.d.ts +55 -0
  145. package/dist/types/view/measure.d.ts +22 -0
  146. package/dist/types/worker/default.d.ts +1 -0
  147. package/dist/types/worker/index.d.ts +34 -0
  148. package/dist/view/input.js +27 -0
  149. package/dist/view/input.js.map +1 -0
  150. package/dist/view/layout.js +194 -0
  151. package/dist/view/layout.js.map +1 -0
  152. package/dist/view/measure.js +104 -0
  153. package/dist/view/measure.js.map +1 -0
  154. package/dist/worker/default.js +20 -0
  155. package/dist/worker/default.js.map +1 -0
  156. package/dist/worker/index.js +139 -0
  157. package/dist/worker/index.js.map +1 -0
  158. package/package.json +88 -4
@@ -0,0 +1,32 @@
1
+ import type { CodeTransactionResult } from './core/transaction';
2
+ import type { CodeEditorExpose, CodeInputProps } from './types';
3
+ declare const __VLS_export: import("vue").DefineComponent<CodeInputProps, CodeEditorExpose, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
4
+ enter: () => any;
5
+ blur: (event: FocusEvent) => any;
6
+ focus: (event: FocusEvent) => any;
7
+ "update:modelValue": (value: string) => any;
8
+ transaction: (result: CodeTransactionResult) => any;
9
+ }, string, import("vue").PublicProps, Readonly<CodeInputProps> & Readonly<{
10
+ onEnter?: (() => any) | undefined;
11
+ onBlur?: ((event: FocusEvent) => any) | undefined;
12
+ onFocus?: ((event: FocusEvent) => any) | undefined;
13
+ "onUpdate:modelValue"?: ((value: string) => any) | undefined;
14
+ onTransaction?: ((result: CodeTransactionResult) => any) | undefined;
15
+ }>, {
16
+ keys: boolean | readonly (string | import("./types").CodeKey)[];
17
+ invalid: boolean;
18
+ language: import("./index.js").CodeLanguage<any> | null;
19
+ messages: Partial<import("./locale.js").CodeMessages>;
20
+ modelValue: string;
21
+ readonly: boolean;
22
+ disabled: boolean;
23
+ closeBrackets: boolean;
24
+ teleport: string | false | HTMLElement;
25
+ multiline: boolean;
26
+ autosize: {
27
+ minRows?: number;
28
+ maxRows?: number;
29
+ };
30
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
31
+ declare const _default: typeof __VLS_export;
32
+ export default _default;
@@ -0,0 +1,9 @@
1
+ import type { CodeMessages } from './locale';
2
+ import type { CodeKey } from './types';
3
+ /**
4
+ * The keys of the bar that scroll: Tab, the symbols code is full of, then
5
+ * undo and redo. Spread it to add keys: `[...defaultCodeKeys, { label: '=>', text: ' => ' }]`.
6
+ */
7
+ export declare const defaultCodeKeys: readonly CodeKey[];
8
+ /** What screen readers read for a key, when its label doesn't say it. */
9
+ export declare function keyName(key: CodeKey, messages: CodeMessages): string | undefined;
@@ -0,0 +1,8 @@
1
+ import type { CodeKey, CodeKeysProps } from './types';
2
+ declare const __VLS_export: import("vue").DefineComponent<CodeKeysProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<CodeKeysProps> & Readonly<{}>, {
3
+ keys: readonly (string | CodeKey)[];
4
+ editor: (Pick<import("./types").CodeEditorExpose, "run"> & Partial<Pick<import("./types").CodeEditorExpose, "focus">>) | null;
5
+ messages: Partial<import("./locale").CodeMessages>;
6
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
7
+ declare const _default: typeof __VLS_export;
8
+ export default _default;
@@ -0,0 +1,36 @@
1
+ import { collaborationColors } from 'dou-ui';
2
+ import * as Y from 'yjs';
3
+ import { type CodeExtension } from '../extension';
4
+ /** What the editor needs of a Yjs awareness instance (`y-protocols/awareness`). */
5
+ export interface AwarenessLike {
6
+ clientID: number;
7
+ getLocalState(): Record<string, unknown> | null;
8
+ setLocalStateField(field: string, value: unknown): void;
9
+ getStates(): Map<number, Record<string, unknown>>;
10
+ on(event: 'change', listener: (...args: unknown[]) => void): void;
11
+ off(event: 'change', listener: (...args: unknown[]) => void): void;
12
+ }
13
+ /** How the people editing together see each other. */
14
+ export interface CollaborationUser {
15
+ name: string;
16
+ /** The color of this user's cursor and selection, any CSS color. Picked from the client id when left out. */
17
+ color?: string;
18
+ }
19
+ export interface CollaborationOptions {
20
+ /** Where the text lives, e.g. `ydoc.getText('code')`. */
21
+ text: Y.Text;
22
+ /** Shares cursors and selections (`y-protocols/awareness`). Without it, others' cursors are not shown. */
23
+ awareness?: AwarenessLike;
24
+ /** This user, shown at their cursor to the others. Needs `awareness`. */
25
+ user?: CollaborationUser;
26
+ }
27
+ export { collaborationColors };
28
+ /**
29
+ * Edit together through a Yjs text. The text lives in `text`: the
30
+ * editor starts from it, whatever `v-model` holds, and `v-model` then
31
+ * mirrors it; a new `v-model` value is written into it as a change, to
32
+ * everyone. Undo only takes back this user's own changes.
33
+ *
34
+ * One extension per editor: two editors on the same text each need their own.
35
+ */
36
+ export declare function collaboration(options: CollaborationOptions): CodeExtension;
@@ -0,0 +1,13 @@
1
+ /** How well a typed word matches a label, and which characters of the label it hit. */
2
+ export interface CodeCompletionMatch {
3
+ score: number;
4
+ /** `[from, to]` pieces of the label that were typed, for drawing them stronger. */
5
+ ranges: Array<[number, number]>;
6
+ }
7
+ /**
8
+ * Matches `query` against `label`: its characters in order, ignoring
9
+ * case. A prefix scores best, then characters at word starts (`gEB` for
10
+ * `getElementById`), then characters further apart. `null` when some
11
+ * character can't be found.
12
+ */
13
+ export declare function matchCompletion(label: string, query: string): CodeCompletionMatch | null;
@@ -0,0 +1,17 @@
1
+ /** A place in a snippet to fill in, `from`–`to` in its text. */
2
+ export interface SnippetField {
3
+ /** Its number: Tab goes through them in order, `0` last. */
4
+ index: number;
5
+ from: number;
6
+ to: number;
7
+ }
8
+ /**
9
+ * Reads a snippet: `${1:name}` is field 1 holding `name`, `$1` or `${1}`
10
+ * field 1 again (holding the same), and `$0` where the cursor ends. Every
11
+ * place of a field is filled in together. `\$` and `\}`
12
+ * are the characters themselves.
13
+ */
14
+ export declare function parseSnippet(source: string): {
15
+ text: string;
16
+ fields: SnippetField[];
17
+ };
@@ -0,0 +1,15 @@
1
+ import type { CodeText } from './text';
2
+ export interface BracketMatch {
3
+ /** The bracket next to the cursor. */
4
+ from: number;
5
+ /** Its partner, or `null` when there is none within reach. */
6
+ match: number | null;
7
+ }
8
+ /**
9
+ * The bracket at `pos` (the one after it, else the one before) and its
10
+ * partner. `skip(pos)` tells whether a character is inside a string or a
11
+ * comment, where brackets don't count.
12
+ */
13
+ export declare function matchBracket(doc: CodeText, pos: number, brackets: string, skip?: (pos: number) => boolean): BracketMatch | null;
14
+ /** The partner of the bracket at `from`, which is `brackets[index]`. */
15
+ export declare function findPartner(doc: CodeText, from: number, brackets: string, index: number, skip?: (pos: number) => boolean): number | null;
@@ -0,0 +1,52 @@
1
+ import type { CodeText } from './text';
2
+ /** Replace `from`–`to` of the old text with `insert`. */
3
+ export interface CodeChange {
4
+ from: number;
5
+ to: number;
6
+ insert: string;
7
+ }
8
+ /** A change as written by hand: `to` defaults to `from`, `insert` to nothing. */
9
+ export interface CodeChangeSpec {
10
+ from: number;
11
+ to?: number;
12
+ insert?: string;
13
+ }
14
+ /** Which side of an insertion at the very spot a position ends up on. */
15
+ export type MapAssoc = -1 | 1;
16
+ /**
17
+ * The changes one step makes to a text: replacements sorted by position,
18
+ * never overlapping, every offset counted in the text before the step.
19
+ *
20
+ * A change set maps positions from the old text to the new one (cursors,
21
+ * marks, diagnostics follow the edit), inverts (undo), and composes with the
22
+ * one after it (merging steps).
23
+ */
24
+ export declare class ChangeSet {
25
+ /** The replacements, sorted. */
26
+ readonly changes: readonly CodeChange[];
27
+ /** Length of the text the changes apply to. */
28
+ readonly length: number;
29
+ /** Running length difference after each change, for mapping by binary search. */
30
+ private shifts?;
31
+ private constructor();
32
+ /**
33
+ * Changes to a text of `length`. Specs may come in any order; touching
34
+ * ones are joined, overlapping ones are a mistake.
35
+ */
36
+ static of(specs: CodeChangeSpec | readonly CodeChangeSpec[], length: number): ChangeSet;
37
+ /** No changes at all. */
38
+ static empty(length: number): ChangeSet;
39
+ get empty(): boolean;
40
+ /** Length of the text after the changes. */
41
+ get newLength(): number;
42
+ /** Applies the changes to `text`, which must be the text they were made for. */
43
+ apply(text: CodeText): CodeText;
44
+ /** The changes that undo these, given the text before them. */
45
+ invert(text: CodeText): ChangeSet;
46
+ /** Where `pos` in the old text is in the new one. */
47
+ mapPos(pos: number, assoc?: MapAssoc): number;
48
+ /** Whether any change touches `from`–`to` of the old text. */
49
+ touches(from: number, to?: number): boolean;
50
+ /** These changes followed by `next`, which was made for the text these produce. */
51
+ compose(next: ChangeSet): ChangeSet;
52
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Characters as people see them: the cursor steps over a whole emoji or an
3
+ * accented letter, and words follow the language, so a run of Chinese
4
+ * splits into words instead of being one long one.
5
+ */
6
+ export declare const isAscii: (text: string) => boolean;
7
+ /** Where each user-perceived character starts, plus the end of the line. */
8
+ export declare function clusterStarts(text: string): number[];
9
+ /** The next character boundary after `col` (or before it with `dir` −1). */
10
+ export declare function moveCluster(text: string, col: number, dir: 1 | -1): number;
11
+ /** Snaps `col` to the start of the character it falls in. */
12
+ export declare function snapCluster(text: string, col: number): number;
13
+ /**
14
+ * Where a word move from `col` lands: past any spaces, then to the far end
15
+ * of the word or the run of punctuation that follows.
16
+ */
17
+ export declare function moveWord(text: string, col: number, dir: 1 | -1): number;
18
+ /** The word, space run or punctuation run around `col`, for a double click. */
19
+ export declare function wordAt(text: string, col: number): {
20
+ from: number;
21
+ to: number;
22
+ };
23
+ /** Leading spaces and tabs. */
24
+ export declare const indentOf: (text: string) => string;
@@ -0,0 +1,199 @@
1
+ import type { CodeLanguage, CodeTokenType } from '../language/language';
2
+ import { type CodeRange } from './selection';
3
+ import type { CodeState, CodeTransaction } from './transaction';
4
+ /** What a command works on: the current state and a way to change it. */
5
+ export interface CodeCommandTarget {
6
+ readonly state: CodeState;
7
+ readonly readonly: boolean;
8
+ /** Columns per tab stop. */
9
+ readonly tabSize: number;
10
+ /** Indent with tabs instead of spaces. */
11
+ readonly indentWithTabs: boolean;
12
+ /** Starts a transaction from the current state. */
13
+ transaction(): CodeTransaction;
14
+ dispatch(tr: CodeTransaction): void;
15
+ /** Where `range`'s head lands `lines` lines up (negative) or down, keeping its column on screen. */
16
+ moveVertically(range: CodeRange, lines: number): number;
17
+ /** How many lines fit on one screen. */
18
+ readonly pageLines: number;
19
+ undo(): boolean;
20
+ redo(): boolean;
21
+ /** The text's language, if it has one. */
22
+ readonly language: CodeLanguage | null;
23
+ /** The language at a position: an inner one inside a language that holds others, e.g. a `<script>` in HTML. */
24
+ languageAt(pos: number): CodeLanguage | null;
25
+ /** The kind of token the character at `pos` belongs to, when it is known. */
26
+ syntaxAt(pos: number): CodeTokenType | null;
27
+ /** Typing an opening bracket or quote also types its partner. */
28
+ readonly closeBrackets: boolean;
29
+ /** The editor's search panel, when it has one. */
30
+ readonly search?: CodeSearchControl;
31
+ /** The editor's folding, when it folds. */
32
+ readonly folding?: CodeFoldControl;
33
+ /** The problems found in the text, when there are any to go through. */
34
+ readonly diagnostics?: CodeDiagnosticControl;
35
+ /** Completions, hover text and snippet fields from extensions. */
36
+ readonly assist?: CodeAssistControl;
37
+ }
38
+ /** What commands can do with what extensions offer while typing. */
39
+ export interface CodeAssistControl {
40
+ /** Asks for completions at the cursor; `false` when none can be given. */
41
+ complete(): boolean;
42
+ /** Shows the text about the cursor's place, and its problems; `false` when there is none. */
43
+ hover(): boolean;
44
+ /** Selects the next / previous place to fill in of the snippet being filled in; `false` when there is none. */
45
+ field(dir: 1 | -1): boolean;
46
+ }
47
+ /** What commands can do with the problems found in the text. */
48
+ export interface CodeDiagnosticControl {
49
+ /** Moves the cursor to the next problem and shows it; `false` when there are none. */
50
+ next(): boolean;
51
+ /** Moves the cursor to the previous problem and shows it; `false` when there are none. */
52
+ previous(): boolean;
53
+ /** Shows the problems at the cursor with their fixes, to pick one by keyboard; `false` when there are none. */
54
+ showFixes(): boolean;
55
+ }
56
+ /** What commands can do with folds. Lines are counted from 1; without one, the main cursor's line. */
57
+ export interface CodeFoldControl {
58
+ /** Folds the block that starts at the line, or else the innermost one around it; `false` when there is none. */
59
+ fold(line?: number): boolean;
60
+ /** Unfolds the folds that start at the line or hide it; `false` when there were none. */
61
+ unfold(line?: number): boolean;
62
+ /** Folds every outermost block. */
63
+ foldAll(): boolean;
64
+ /** Unfolds everything; `false` when nothing was folded. */
65
+ unfoldAll(): boolean;
66
+ }
67
+ /** What commands can do with the editor's search panel. */
68
+ export interface CodeSearchControl {
69
+ /** Opens the panel (with the replace box when `replace` is set) and focuses it. */
70
+ open(replace?: boolean): void;
71
+ /** Closes the panel; `false` when it wasn't open. */
72
+ close(): boolean;
73
+ /** Selects the next match; `false` without matches. */
74
+ next(): boolean;
75
+ /** Selects the previous match; `false` without matches. */
76
+ previous(): boolean;
77
+ }
78
+ /** Does something to the editor; returns whether it applied, so a key can fall through when it didn't. */
79
+ export type CodeCommand = (target: CodeCommandTarget) => boolean;
80
+ /** Expands tabs before `col` to get the column on screen, counting one per other character. */
81
+ export declare function visualColumn(text: string, col: number, tabSize: number): number;
82
+ export declare const cursorCharLeft: CodeCommand;
83
+ export declare const cursorCharRight: CodeCommand;
84
+ export declare const selectCharLeft: CodeCommand;
85
+ export declare const selectCharRight: CodeCommand;
86
+ export declare const cursorWordLeft: CodeCommand;
87
+ export declare const cursorWordRight: CodeCommand;
88
+ export declare const selectWordLeft: CodeCommand;
89
+ export declare const selectWordRight: CodeCommand;
90
+ export declare const cursorLineStart: CodeCommand;
91
+ export declare const cursorLineEnd: CodeCommand;
92
+ export declare const selectLineStart: CodeCommand;
93
+ export declare const selectLineEnd: CodeCommand;
94
+ export declare const cursorDocStart: CodeCommand;
95
+ export declare const cursorDocEnd: CodeCommand;
96
+ export declare const selectDocStart: CodeCommand;
97
+ export declare const selectDocEnd: CodeCommand;
98
+ export declare const cursorLineUp: CodeCommand;
99
+ export declare const cursorLineDown: CodeCommand;
100
+ export declare const selectLineUp: CodeCommand;
101
+ export declare const selectLineDown: CodeCommand;
102
+ export declare const cursorPageUp: CodeCommand;
103
+ export declare const cursorPageDown: CodeCommand;
104
+ export declare const selectPageUp: CodeCommand;
105
+ export declare const selectPageDown: CodeCommand;
106
+ export declare const selectAll: CodeCommand;
107
+ /**
108
+ * Selects the word at the cursor; with a selection, adds the next place
109
+ * the same text occurs as another selection (wrapping around the end).
110
+ */
111
+ export declare const selectNextOccurrence: CodeCommand;
112
+ /** Selects every place the selected text (or the word at the cursor) occurs. */
113
+ export declare const selectAllOccurrences: CodeCommand;
114
+ /** Adds a cursor on the line above the topmost one. */
115
+ export declare const addCursorAbove: CodeCommand;
116
+ /** Adds a cursor on the line below the bottommost one. */
117
+ export declare const addCursorBelow: CodeCommand;
118
+ /** Leaves only the main range, then only a cursor; returns false when there was nothing to drop. */
119
+ export declare const simplifySelection: CodeCommand;
120
+ /** Backspace; between a pair of brackets or quotes, `(|)`, it deletes both. */
121
+ export declare const deleteCharBackward: CodeCommand;
122
+ export declare const deleteCharForward: CodeCommand;
123
+ export declare const deleteWordBackward: CodeCommand;
124
+ export declare const deleteWordForward: CodeCommand;
125
+ export declare const deleteLineStart: CodeCommand;
126
+ export declare const deleteLineEnd: CodeCommand;
127
+ /**
128
+ * A line break that keeps the indentation. After an opening bracket (or
129
+ * what the language indents after, such as an HTML tag) it indents one
130
+ * more; between a pair, `{|}`, it puts the closing one on a line of its own.
131
+ */
132
+ export declare const insertNewline: CodeCommand;
133
+ /**
134
+ * Types `text` at every cursor, as typing does, with the help of the
135
+ * language: an opening bracket or quote brings its partner, a closing one
136
+ * steps over the partner already there, a selection gets wrapped, and a
137
+ * closing bracket typed on a blank line lines up with its opener.
138
+ * Returns `false` when it would only type the text, so the caller does that.
139
+ */
140
+ export declare function insertText(target: CodeCommandTarget, text: string): boolean;
141
+ export declare const indentMore: CodeCommand;
142
+ export declare const indentLess: CodeCommand;
143
+ /** Tab: indents selected lines, otherwise fills to the next tab stop at each cursor. */
144
+ export declare const insertTab: CodeCommand;
145
+ /**
146
+ * Types `text` as if from the keyboard: a bracket or quote closes itself,
147
+ * a line break indents. For buttons that type, like a bar of symbols.
148
+ */
149
+ export declare const typeText: (text: string) => CodeCommand;
150
+ export declare const undo: CodeCommand;
151
+ export declare const redo: CodeCommand;
152
+ /** Moves the lines with a cursor or selection up one line. */
153
+ export declare const moveLineUp: CodeCommand;
154
+ /** Moves the lines with a cursor or selection down one line. */
155
+ export declare const moveLineDown: CodeCommand;
156
+ /** Copies the lines with a cursor or selection above them; the cursor stays on the upper copy. */
157
+ export declare const copyLineUp: CodeCommand;
158
+ /** Copies the lines with a cursor or selection below them, and moves the cursor to the copy. */
159
+ export declare const copyLineDown: CodeCommand;
160
+ /** Deletes the lines with a cursor or selection, line breaks and all. */
161
+ export declare const deleteLine: CodeCommand;
162
+ /**
163
+ * Comments the lines with a cursor or selection out, or back in when they
164
+ * all are: with the language's line comment (`//`), or wrapped in its block
165
+ * comment (`<!-- … -->`) when it has none. Inside a language held by
166
+ * another (a `<script>` in HTML), the inner language's comments are used.
167
+ */
168
+ export declare const toggleComment: CodeCommand;
169
+ /** Moves the cursor to the bracket matching the one next to it. */
170
+ export declare const cursorMatchingBracket: CodeCommand;
171
+ /** Opens the search panel, filled with the selected text. */
172
+ export declare const openSearch: CodeCommand;
173
+ /** Opens the search panel with the replace box. */
174
+ export declare const openReplace: CodeCommand;
175
+ /** Selects the next match of the search. */
176
+ export declare const findNext: CodeCommand;
177
+ /** Selects the previous match of the search. */
178
+ export declare const findPrevious: CodeCommand;
179
+ /** Closes the search panel. */
180
+ export declare const closeSearch: CodeCommand;
181
+ /** Folds the block at the cursor's line, or the innermost one around it. */
182
+ export declare const foldCode: CodeCommand;
183
+ /** Unfolds the block at the cursor's line. */
184
+ export declare const unfoldCode: CodeCommand;
185
+ /** Folds every outermost block. */
186
+ export declare const foldAll: CodeCommand;
187
+ /** Unfolds everything. */
188
+ export declare const unfoldAll: CodeCommand;
189
+ export declare const nextDiagnostic: CodeCommand;
190
+ export declare const previousDiagnostic: CodeCommand;
191
+ export declare const showFixes: CodeCommand;
192
+ /** Opens the completion list at the cursor. */
193
+ export declare const startCompletion: CodeCommand;
194
+ /** Shows the hover text at the cursor, as hovering does with a mouse. */
195
+ export declare const showHover: CodeCommand;
196
+ /** Goes to the next place to fill in of a snippet. */
197
+ export declare const nextSnippetField: CodeCommand;
198
+ /** Goes to the previous place to fill in of a snippet. */
199
+ export declare const previousSnippetField: CodeCommand;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Where two texts differ inside a changed block: characters `from` to `to`
3
+ * of the original text became characters `from` to `to` of the modified
4
+ * one (offsets in each whole text). An empty side is a pure insertion or
5
+ * deletion.
6
+ */
7
+ export interface CodeDiffPart {
8
+ original: {
9
+ from: number;
10
+ to: number;
11
+ };
12
+ modified: {
13
+ from: number;
14
+ to: number;
15
+ };
16
+ }
17
+ /**
18
+ * A block of lines that changed, numbered as in a unified diff: from line
19
+ * `originalStart` (from 1) `originalCount` lines of the original became
20
+ * `modifiedCount` lines from `modifiedStart`. A count of 0 is a pure
21
+ * insertion or deletion, placed after the line before its start.
22
+ */
23
+ export interface CodeDiffHunk {
24
+ originalStart: number;
25
+ originalCount: number;
26
+ modifiedStart: number;
27
+ modifiedCount: number;
28
+ /**
29
+ * The words that differ, when lines changed on both sides and enough of
30
+ * them stayed the same to be worth marking; empty otherwise.
31
+ */
32
+ parts: CodeDiffPart[];
33
+ }
34
+ export interface CodeDiffOptions {
35
+ /** Treats lines that differ only in spaces as the same. */
36
+ ignoreWhitespace?: boolean;
37
+ /** Works out the words that differ inside changed lines. On by default. */
38
+ words?: boolean;
39
+ /**
40
+ * How hard to look for the smallest diff, in edit steps per block; past
41
+ * it the rest of a block counts as replaced. Defaults to 1000.
42
+ */
43
+ maxCost?: number;
44
+ }
45
+ /** Where each line starts in the text, plus where the text would go on after the last one. */
46
+ export declare function lineStarts(lines: readonly string[]): number[];
47
+ /**
48
+ * The blocks of lines that differ between `original` and `modified`, in
49
+ * order, each with the words that differ inside it. Lines are compared
50
+ * whole (Myers' algorithm, in linear space).
51
+ */
52
+ export declare function diffText(original: string, modified: string, options?: CodeDiffOptions): CodeDiffHunk[];
@@ -0,0 +1,23 @@
1
+ import type { CodeText } from './text';
2
+ /** A folded block: the line ending at `from` stays, the lines after it up to the one ending at `to` are hidden. */
3
+ export interface CodeFold {
4
+ from: number;
5
+ to: number;
6
+ }
7
+ /**
8
+ * The last line a fold starting at line `n` would hide, or `null` when the
9
+ * line starts no block. A line ending in an open bracket folds up to the
10
+ * line before its partner, so the closing bracket stays in view; any other
11
+ * line folds the lines indented deeper below it.
12
+ */
13
+ export declare function foldEndAt(doc: CodeText, n: number, options?: {
14
+ brackets?: string;
15
+ skip?: (pos: number) => boolean;
16
+ tabSize?: number;
17
+ /** The text of line `n`, when the caller has the lines at hand already. */
18
+ lineText?: (n: number) => string;
19
+ }): number | null;
20
+ /** The lines hidden by `folds`, as sorted ranges that don't overlap. */
21
+ export declare function hiddenLines(doc: CodeText, folds: readonly CodeFold[]): Array<[number, number]>;
22
+ /** Line ranges sorted, with the ones that overlap or touch joined. */
23
+ export declare function mergeRanges(ranges: ReadonlyArray<readonly [number, number]>): Array<[number, number]>;
@@ -0,0 +1,24 @@
1
+ import type { ChangeSet } from './changes';
2
+ import { type CodeSelection } from './selection';
3
+ import type { CodeTransactionResult } from './transaction';
4
+ /** Undo and redo stacks. Selection-only steps aren't kept; each entry remembers the selection around it. */
5
+ export declare class CodeHistory {
6
+ private done;
7
+ private undone;
8
+ get canUndo(): boolean;
9
+ get canRedo(): boolean;
10
+ /** Remembers a transaction that changed the text. */
11
+ record(result: CodeTransactionResult, time?: number): void;
12
+ /** Starts a new entry with the next change, even if it would join the last one. */
13
+ close(): void;
14
+ /** Takes the last entry off: the changes that undo it and the selection to go back to. */
15
+ undo(): {
16
+ changes: ChangeSet;
17
+ selection: CodeSelection;
18
+ } | null;
19
+ redo(): {
20
+ changes: ChangeSet;
21
+ selection: CodeSelection;
22
+ } | null;
23
+ clear(): void;
24
+ }
@@ -0,0 +1,29 @@
1
+ import * as cmd from './commands';
2
+ import type { CodeCommand } from './commands';
3
+ /**
4
+ * A key and what it runs. Keys are written like `mod+shift+z`: `mod` is ⌘
5
+ * on Apple devices and Ctrl elsewhere. `mac` replaces `key` on Apple
6
+ * devices; leave `key` out for a binding that only exists there.
7
+ */
8
+ export interface CodeKeyBinding {
9
+ key?: string;
10
+ mac?: string;
11
+ run: CodeCommand;
12
+ /** Runs this with Shift held too, as the selecting version of a move. */
13
+ shift?: CodeCommand;
14
+ }
15
+ /**
16
+ * Keys and the commands they run, as `{ 'mod+s': save }`. A command that
17
+ * returns `false` lets the next binding of the same key try.
18
+ */
19
+ export type CodeKeymap = Record<string, CodeCommand>;
20
+ /** A keymap as bindings, in its own order. */
21
+ export declare const keymapBindings: (keymap: CodeKeymap | null | undefined) => CodeKeyBinding[];
22
+ /** A key written as a binding, in one spelling for both platforms. */
23
+ export declare function normalizeKey(key: string, apple: boolean): string;
24
+ /** A key press, spelled like `normalizeKey`. Letters and digits are read from the physical key, so ⌥ and layouts don't change them. */
25
+ export declare function eventKey(event: KeyboardEvent, apple: boolean): string;
26
+ /** Looks up bindings by key; later bindings win over earlier ones. */
27
+ export declare function buildKeymap(bindings: readonly CodeKeyBinding[], apple: boolean): Map<string, cmd.CodeCommand[]>;
28
+ /** The editing and moving keys every editor has. */
29
+ export declare const defaultKeymap: readonly CodeKeyBinding[];
@@ -0,0 +1,37 @@
1
+ import type { CodeText } from './text';
2
+ /** What to look for. */
3
+ export interface CodeSearchQuery {
4
+ /** The text, or a regular expression with `regexp`. */
5
+ search: string;
6
+ /** Tells upper and lower case apart. */
7
+ caseSensitive?: boolean;
8
+ /** Only matches that are whole words. */
9
+ wholeWord?: boolean;
10
+ /** `search` is a regular expression (JavaScript syntax). */
11
+ regexp?: boolean;
12
+ /** What `replace` puts in; with `regexp`, `$1` and `$<name>` refer to groups. */
13
+ replace?: string;
14
+ }
15
+ export interface CodeMatch {
16
+ from: number;
17
+ to: number;
18
+ }
19
+ export interface CodeSearchResult {
20
+ matches: CodeMatch[];
21
+ /** More matches exist beyond `limit`. */
22
+ capped: boolean;
23
+ /** Why the regular expression is not valid, when it isn't. */
24
+ error?: string;
25
+ }
26
+ /** The query as one global regular expression, or the reason it can't be one. */
27
+ export declare function queryRegExp(query: CodeSearchQuery): RegExp | string;
28
+ /**
29
+ * Every match of `query` in `doc`, in order, at most `limit` of them. An
30
+ * empty match (a regular expression like `^`) is skipped, since it would
31
+ * select nothing.
32
+ */
33
+ export declare function searchText(doc: CodeText, query: CodeSearchQuery, limit?: number): CodeSearchResult;
34
+ /** The text that replaces one match: `query.replace`, with groups filled in for a regular expression. */
35
+ export declare function replacementFor(doc: CodeText, match: CodeMatch, query: CodeSearchQuery): string;
36
+ /** The index of the first match at or after `pos` (wrapping to the first), or `-1` without matches. */
37
+ export declare function matchAfter(matches: readonly CodeMatch[], pos: number): number;
@@ -0,0 +1,28 @@
1
+ import type { ChangeSet } from './changes';
2
+ /** One selected range. `anchor` stays put while `head` (the cursor) moves; equal means a bare cursor. */
3
+ export interface CodeRange {
4
+ anchor: number;
5
+ head: number;
6
+ }
7
+ /** The selection: one or more ranges, sorted and apart, and which one is the main one. */
8
+ export interface CodeSelection {
9
+ ranges: CodeRange[];
10
+ main: number;
11
+ }
12
+ export declare const rangeFrom: (range: CodeRange) => number;
13
+ export declare const rangeTo: (range: CodeRange) => number;
14
+ export declare const isEmptyRange: (range: CodeRange) => boolean;
15
+ /** A selection of one range; just a cursor when `head` is left out. */
16
+ export declare function selectionOf(anchor: number, head?: number): CodeSelection;
17
+ /** The main range. */
18
+ export declare const mainRange: (selection: CodeSelection) => CodeRange;
19
+ /**
20
+ * Clamps every range into a text of `length`, sorts them and joins the ones
21
+ * that overlap (or are cursors at the same spot). The main range keeps its
22
+ * place in whichever range it ended up in.
23
+ */
24
+ export declare function normalizeSelection(selection: CodeSelection, length: number): CodeSelection;
25
+ /** Moves every range through `changes`. Cursors stay after text typed at them. */
26
+ export declare function mapSelection(selection: CodeSelection, changes: ChangeSet): CodeSelection;
27
+ /** Whether two selections are the same. */
28
+ export declare function sameSelection(a: CodeSelection, b: CodeSelection): boolean;