@noldova/code.editor.angular 0.0.0-stage → 0.0.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.
- package/LICENSE +21 -0
- package/README.md +12 -2
- package/api/index.d.ts +30 -0
- package/api/index.js +27 -0
- package/app/components/code-editor/code-editor.component.d.ts +332 -0
- package/app/components/code-editor/code-editor.component.js +648 -0
- package/app/components/code-text/code-text.component.d.ts +70 -0
- package/app/components/code-text/code-text.component.js +40 -0
- package/app/components/find-bar/find-bar.component.d.ts +40 -0
- package/app/components/find-bar/find-bar.component.js +95 -0
- package/app/enums/code-row-kind.d.ts +14 -0
- package/app/enums/code-row-kind.js +15 -0
- package/app/enums/fold-shortcut.d.ts +11 -0
- package/app/enums/fold-shortcut.js +12 -0
- package/app/exceptions/background-job-failed.exception.d.ts +33 -0
- package/app/exceptions/background-job-failed.exception.js +15 -0
- package/app/interfaces/i-code-decorations.d.ts +103 -0
- package/app/interfaces/i-code-decorations.js +7 -0
- package/app/interfaces/i-code-editor-view.d.ts +13 -0
- package/app/interfaces/i-code-editor-view.js +7 -0
- package/app/interfaces/i-code-numbering.d.ts +38 -0
- package/app/interfaces/i-code-numbering.js +7 -0
- package/app/models/code-editor-view.d.ts +18 -0
- package/app/models/code-editor-view.js +26 -0
- package/app/models/code-search.d.ts +18 -0
- package/app/models/code-search.js +52 -0
- package/app/models/code-text-line.d.ts +17 -0
- package/app/models/code-text-line.js +42 -0
- package/app/models/code-text-span.d.ts +15 -0
- package/app/models/code-text-span.js +19 -0
- package/app/models/decorations/code-bar-action-event.d.ts +39 -0
- package/app/models/decorations/code-bar-action-event.js +15 -0
- package/app/models/decorations/code-bar-action.d.ts +40 -0
- package/app/models/decorations/code-bar-action.js +17 -0
- package/app/models/decorations/code-bar.d.ts +78 -0
- package/app/models/decorations/code-bar.js +34 -0
- package/app/models/decorations/code-decorations.d.ts +121 -0
- package/app/models/decorations/code-decorations.js +42 -0
- package/app/models/decorations/code-gutter-marker.d.ts +46 -0
- package/app/models/decorations/code-gutter-marker.js +20 -0
- package/app/models/decorations/code-line-decoration.d.ts +48 -0
- package/app/models/decorations/code-line-decoration.js +21 -0
- package/app/models/decorations/code-range-decoration.d.ts +44 -0
- package/app/models/decorations/code-range-decoration.js +15 -0
- package/app/models/folding/code-block.d.ts +17 -0
- package/app/models/folding/code-block.js +21 -0
- package/app/models/folding/code-blocks.d.ts +17 -0
- package/app/models/folding/code-blocks.js +32 -0
- package/app/models/folding/code-fold.d.ts +53 -0
- package/app/models/folding/code-fold.js +23 -0
- package/app/models/folding/fold-shortcuts.d.ts +14 -0
- package/app/models/folding/fold-shortcuts.js +17 -0
- package/app/models/language-tokenizer.d.ts +39 -0
- package/app/models/language-tokenizer.js +22 -0
- package/app/models/rows/code-embedded-lines.d.ts +76 -0
- package/app/models/rows/code-embedded-lines.js +43 -0
- package/app/models/rows/code-inserted-rows.d.ts +19 -0
- package/app/models/rows/code-inserted-rows.js +7 -0
- package/app/models/rows/code-row.d.ts +27 -0
- package/app/models/rows/code-row.js +31 -0
- package/app/models/rows/code-spacer.d.ts +61 -0
- package/app/models/rows/code-spacer.js +30 -0
- package/app/models/rows/inserted-rows.d.ts +12 -0
- package/app/models/rows/inserted-rows.js +18 -0
- package/app/models/rows/layer-lines.d.ts +18 -0
- package/app/models/rows/layer-lines.js +17 -0
- package/app/models/rows/layout-row.d.ts +14 -0
- package/app/models/rows/layout-row.js +17 -0
- package/app/models/rows/line-index.d.ts +58 -0
- package/app/models/rows/line-index.js +50 -0
- package/app/models/rows/row-builder.d.ts +35 -0
- package/app/models/rows/row-builder.js +87 -0
- package/app/models/rows/row-layout.d.ts +22 -0
- package/app/models/rows/row-layout.js +58 -0
- package/app/models/rows/row-span.d.ts +13 -0
- package/app/models/rows/row-span.js +17 -0
- package/app/models/shapes/bar-shape.d.ts +13 -0
- package/app/models/shapes/bar-shape.js +15 -0
- package/app/models/shapes/change-shape.d.ts +14 -0
- package/app/models/shapes/change-shape.js +19 -0
- package/app/models/shapes/code-shape.d.ts +14 -0
- package/app/models/shapes/code-shape.js +19 -0
- package/app/models/shapes/match-shape.d.ts +14 -0
- package/app/models/shapes/match-shape.js +19 -0
- package/app/models/text-measure.d.ts +18 -0
- package/app/models/text-measure.js +50 -0
- package/app/models/view-command.d.ts +16 -0
- package/app/models/view-command.js +24 -0
- package/app/services/background-ticker.d.ts +47 -0
- package/app/services/background-ticker.js +34 -0
- package/app/services/code-editor-classes.d.ts +102 -0
- package/app/services/code-editor-classes.js +30 -0
- package/app/services/code-editor-contribution.d.ts +20 -0
- package/app/services/code-editor-contribution.js +41 -0
- package/app/services/code-editor-features.d.ts +13 -0
- package/app/services/code-editor-features.js +13 -0
- package/app/services/code-editor-registries.d.ts +43 -0
- package/app/services/code-editor-registries.js +23 -0
- package/app/services/key-scope.d.ts +79 -0
- package/app/services/key-scope.js +53 -0
- package/app/services/token-style-sheet.d.ts +11 -0
- package/app/services/token-style-sheet.js +44 -0
- package/app/services/worker-runner.d.ts +87 -0
- package/app/services/worker-runner.js +84 -0
- package/package.json +38 -4
- package/resources.d.ts +124 -0
- package/resources.js +137 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import type { TextRange } from "@noldova/code.editor";
|
|
9
|
+
/**
|
|
10
|
+
* A background over a range of characters, such as a diff's changed
|
|
11
|
+
* characters, on each line the range covers; a range that ends at column 0
|
|
12
|
+
* of a line paints nothing on that line.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* In 0.0.x its positions are its owner's to remap after an edit. Later
|
|
16
|
+
* fields, such as a text color and an underline for diagnostics, come as
|
|
17
|
+
* optional constructor parameters at the end.
|
|
18
|
+
*/
|
|
19
|
+
export declare class CodeRangeDecoration {
|
|
20
|
+
/**
|
|
21
|
+
* The characters it paints.
|
|
22
|
+
*/
|
|
23
|
+
readonly range: TextRange;
|
|
24
|
+
/**
|
|
25
|
+
* The CSS background it paints.
|
|
26
|
+
*/
|
|
27
|
+
readonly background: string;
|
|
28
|
+
/**
|
|
29
|
+
* Creates a range decoration.
|
|
30
|
+
*
|
|
31
|
+
* @param range The characters it paints.
|
|
32
|
+
* @param background The CSS background it paints.
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { TextPosition, TextRange } from "@noldova/code.editor";
|
|
36
|
+
* import { List } from "@noldova/context.collections";
|
|
37
|
+
* import { CodeDecorations, type CodeLineDecoration, CodeRangeDecoration } from "@noldova/code.editor.angular";
|
|
38
|
+
*
|
|
39
|
+
* const word = new CodeRangeDecoration(new TextRange(new TextPosition(2, 4), new TextPosition(2, 9)), "var(--nol-added-change)");
|
|
40
|
+
* const layer = new CodeDecorations(new List<CodeLineDecoration>(), new List([word]));
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
constructor(range: TextRange, background: string);
|
|
44
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export class CodeRangeDecoration {
|
|
9
|
+
range;
|
|
10
|
+
background;
|
|
11
|
+
constructor(range, background) {
|
|
12
|
+
this.range = range;
|
|
13
|
+
this.background = background;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import type { CodeFold } from "./code-fold.js";
|
|
9
|
+
import type { CodeInsertedRows } from "../rows/code-inserted-rows.js";
|
|
10
|
+
export declare class CodeBlock {
|
|
11
|
+
readonly line: number;
|
|
12
|
+
readonly length: number;
|
|
13
|
+
readonly hidden: number;
|
|
14
|
+
readonly rows: CodeInsertedRows | null;
|
|
15
|
+
readonly fold: CodeFold | null;
|
|
16
|
+
constructor(line: number, length: number, hidden: number, rows: CodeInsertedRows | null, fold: CodeFold | null);
|
|
17
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export class CodeBlock {
|
|
9
|
+
line;
|
|
10
|
+
length;
|
|
11
|
+
hidden;
|
|
12
|
+
rows;
|
|
13
|
+
fold;
|
|
14
|
+
constructor(line, length, hidden, rows, fold) {
|
|
15
|
+
this.line = line;
|
|
16
|
+
this.length = length;
|
|
17
|
+
this.hidden = hidden;
|
|
18
|
+
this.rows = rows;
|
|
19
|
+
this.fold = fold;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import type { IReadOnlyList } from "@noldova/context.collections";
|
|
9
|
+
import type { ICodeDecorations } from "../../interfaces/i-code-decorations.js";
|
|
10
|
+
import { CodeBlock } from "./code-block.js";
|
|
11
|
+
import type { CodeFold } from "./code-fold.js";
|
|
12
|
+
export declare class CodeBlocks {
|
|
13
|
+
readonly blocks: readonly CodeBlock[];
|
|
14
|
+
readonly largestNumber: number;
|
|
15
|
+
constructor(lineCount: number, layers: IReadOnlyList<ICodeDecorations>, folds: IReadOnlyList<CodeFold>);
|
|
16
|
+
private static collapsedOf;
|
|
17
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { CodeBlock } from "./code-block.js";
|
|
9
|
+
export class CodeBlocks {
|
|
10
|
+
blocks;
|
|
11
|
+
largestNumber;
|
|
12
|
+
constructor(lineCount, layers, folds) {
|
|
13
|
+
const collapsed = CodeBlocks.collapsedOf(lineCount, folds);
|
|
14
|
+
const rows = layers.selectMany(t => t.rows)
|
|
15
|
+
.where(t => t.rowCount > 0 && t.beforeLine <= lineCount && !collapsed.some(u => t.beforeLine > u.line && t.beforeLine < u.line + u.hidden)).toArray();
|
|
16
|
+
const inserted = rows.map(t => new CodeBlock(t.beforeLine, t.rowCount, 0, t, null));
|
|
17
|
+
this.blocks = [...inserted, ...collapsed].sort((a, b) => a.line - b.line || a.hidden - b.hidden);
|
|
18
|
+
this.largestNumber = rows.reduce((a, t) => Math.max(a, t.largestNumber), layers.aggregate(lineCount, (a, t) => Math.max(a, t.numbering?.largest ?? 0)));
|
|
19
|
+
}
|
|
20
|
+
static collapsedOf(lineCount, folds) {
|
|
21
|
+
const kept = [];
|
|
22
|
+
let end = 0;
|
|
23
|
+
for (const fold of folds.where(t => t.collapsed && t.startLine < lineCount).orderBy(t => t.startLine)) {
|
|
24
|
+
const hidden = Math.min(fold.lineCount, lineCount - fold.startLine);
|
|
25
|
+
if (hidden === 0 || fold.startLine < end)
|
|
26
|
+
continue;
|
|
27
|
+
kept.push(new CodeBlock(fold.startLine, 1, hidden, null, fold));
|
|
28
|
+
end = fold.startLine + hidden;
|
|
29
|
+
}
|
|
30
|
+
return kept;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* A region of lines of the code view that collapses to one row.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* The view shows a gutter toggle on a collapsed fold's row and on an
|
|
13
|
+
* expanded fold's first line, and gives a click on either, or on the
|
|
14
|
+
* collapsed row, to its owner through `CodeEditorComponent.foldToggle`; the
|
|
15
|
+
* owner holds each fold's state and gives the view new folds when it
|
|
16
|
+
* changes. A fold of no lines shows nothing. In 0.0.x its lines are its
|
|
17
|
+
* owner's to remap after an edit.
|
|
18
|
+
*/
|
|
19
|
+
export declare class CodeFold {
|
|
20
|
+
/**
|
|
21
|
+
* The first line it holds, from 0.
|
|
22
|
+
*/
|
|
23
|
+
readonly startLine: number;
|
|
24
|
+
/**
|
|
25
|
+
* How many lines it holds.
|
|
26
|
+
*/
|
|
27
|
+
readonly lineCount: number;
|
|
28
|
+
/**
|
|
29
|
+
* Whether it shows as one row.
|
|
30
|
+
*/
|
|
31
|
+
readonly collapsed: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* The collapsed row's text, or null for a count of its lines.
|
|
34
|
+
*/
|
|
35
|
+
readonly label: string | null;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a fold.
|
|
38
|
+
*
|
|
39
|
+
* @param startLine The first line it holds, from 0.
|
|
40
|
+
* @param lineCount How many lines it holds.
|
|
41
|
+
* @param collapsed Whether it shows as one row.
|
|
42
|
+
* @param label The collapsed row's text, or null, when not given, for a
|
|
43
|
+
* count of its lines.
|
|
44
|
+
* @throws {ArgumentOutOfRangeException} When `startLine` or `lineCount` is negative or not a whole number.
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { CodeFold } from "@noldova/code.editor.angular";
|
|
48
|
+
*
|
|
49
|
+
* const imports = new CodeFold(0, 12, true, "Imports");
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
constructor(startLine: number, lineCount: number, collapsed: boolean, label?: string | null);
|
|
53
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { TextPosition } from "@noldova/code.editor";
|
|
9
|
+
import { Resources } from "../../../resources.js";
|
|
10
|
+
export class CodeFold {
|
|
11
|
+
startLine;
|
|
12
|
+
lineCount;
|
|
13
|
+
collapsed;
|
|
14
|
+
label;
|
|
15
|
+
constructor(startLine, lineCount, collapsed, label = null) {
|
|
16
|
+
TextPosition.requireCount(startLine, Resources.startLineParameter);
|
|
17
|
+
TextPosition.requireCount(lineCount, Resources.lineCountParameter);
|
|
18
|
+
this.startLine = startLine;
|
|
19
|
+
this.lineCount = lineCount;
|
|
20
|
+
this.collapsed = collapsed;
|
|
21
|
+
this.label = label;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import "@noldova/context.core";
|
|
9
|
+
import type { IReadOnlyList } from "@noldova/context.collections";
|
|
10
|
+
import { FoldShortcut } from "../../enums/fold-shortcut.js";
|
|
11
|
+
import type { CodeFold } from "./code-fold.js";
|
|
12
|
+
export declare class FoldShortcuts {
|
|
13
|
+
static foldAt(folds: IReadOnlyList<CodeFold>, line: number, shortcut: FoldShortcut): CodeFold | null;
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import "@noldova/context.core";
|
|
9
|
+
import { FoldShortcut } from "../../enums/fold-shortcut.js";
|
|
10
|
+
export class FoldShortcuts {
|
|
11
|
+
static foldAt(folds, line, shortcut) {
|
|
12
|
+
const found = shortcut === FoldShortcut.Fold
|
|
13
|
+
? folds.where(t => !t.collapsed && t.lineCount > 0 && t.startLine <= line && line < t.startLine + t.lineCount).orderByDescending(t => t.startLine).firstOrDefault()
|
|
14
|
+
: folds.firstOrDefault(t => t.collapsed && t.lineCount > 0 && (t.startLine === line || t.startLine === line + 1 || t.startLine + t.lineCount === line));
|
|
15
|
+
return found ?? null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import "@noldova/context.core";
|
|
9
|
+
import { type Signal } from "@angular/core";
|
|
10
|
+
import type { ILanguageDefinition, ILineTokenizer } from "@noldova/code.editor";
|
|
11
|
+
/**
|
|
12
|
+
* Makes a language's tokenizer for a view, in the background, through the
|
|
13
|
+
* highlighters of the app's {@link CodeEditorRegistries}, which make each
|
|
14
|
+
* language's tokenizer once for the app.
|
|
15
|
+
*/
|
|
16
|
+
export declare class LanguageTokenizer {
|
|
17
|
+
/**
|
|
18
|
+
* The tokenizer of a view's language, for a view that colors code itself.
|
|
19
|
+
* @param language The language: its id in the app's registries, its
|
|
20
|
+
* definition, or null.
|
|
21
|
+
* @returns The tokenizer, or null while it loads, when the language is null
|
|
22
|
+
* or unknown, when no highlighter supports it, or when its load failed.
|
|
23
|
+
* @remarks Call it in an injection context, such as a field of a component.
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { Component, input, type InputSignal, type Signal } from "@angular/core";
|
|
27
|
+
* import type { ILineTokenizer } from "@noldova/code.editor";
|
|
28
|
+
* import { LanguageTokenizer } from "@noldova/code.editor.angular";
|
|
29
|
+
*
|
|
30
|
+
* @Component({ selector: "app-preview", template: "" })
|
|
31
|
+
* export class PreviewComponent {
|
|
32
|
+
* public readonly language: InputSignal<string | null> = input<string | null>(null);
|
|
33
|
+
* private readonly tokenizer: Signal<ILineTokenizer | null> = LanguageTokenizer.of(this.language);
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
static of(language: Signal<string | ILanguageDefinition | null>): Signal<ILineTokenizer | null>;
|
|
38
|
+
private static loadAsync;
|
|
39
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import "@noldova/context.core";
|
|
9
|
+
import { computed, inject, resource } from "@angular/core";
|
|
10
|
+
import { CodeEditorRegistries } from "../services/code-editor-registries.js";
|
|
11
|
+
export class LanguageTokenizer {
|
|
12
|
+
static of(language) {
|
|
13
|
+
const registries = inject(CodeEditorRegistries).registries;
|
|
14
|
+
const loaded = resource({ ...(ngDevMode ? { debugName: "loaded" } : /* istanbul ignore next */ {}), params: language,
|
|
15
|
+
loader: ({ params }) => LanguageTokenizer.loadAsync(registries, params) });
|
|
16
|
+
return computed(() => loaded.hasValue() ? loaded.value() : null);
|
|
17
|
+
}
|
|
18
|
+
static loadAsync(registries, language) {
|
|
19
|
+
const definition = Object.isString(language) ? registries.languages.find(language) : language;
|
|
20
|
+
return Object.isNull(definition) ? Promise.resolve(null) : registries.highlighters.tokenizerAsync(definition);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { type TextDocument, type TokenCache } from "@noldova/code.editor";
|
|
9
|
+
import type { ICodeDecorations } from "../../interfaces/i-code-decorations.js";
|
|
10
|
+
import { InsertedRows } from "./inserted-rows.js";
|
|
11
|
+
/**
|
|
12
|
+
* Lines of another document drawn read-only between two lines, such as the
|
|
13
|
+
* removed lines of an inline diff, with their own tokens and decorations.
|
|
14
|
+
* They are numbered by their own lines, in the second column when a layer
|
|
15
|
+
* gives the view a second numbering.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* Later fields come as optional constructor parameters at the end.
|
|
19
|
+
*/
|
|
20
|
+
export declare class CodeEmbeddedLines extends InsertedRows {
|
|
21
|
+
/**
|
|
22
|
+
* The line the rows come before, from 0; the document's line count puts
|
|
23
|
+
* them after its last line.
|
|
24
|
+
*/
|
|
25
|
+
readonly beforeLine: number;
|
|
26
|
+
/**
|
|
27
|
+
* The document the lines come from.
|
|
28
|
+
*/
|
|
29
|
+
readonly document: TextDocument;
|
|
30
|
+
/**
|
|
31
|
+
* The document's first line shown, from 0.
|
|
32
|
+
*/
|
|
33
|
+
readonly startLine: number;
|
|
34
|
+
/**
|
|
35
|
+
* How many of its lines show.
|
|
36
|
+
*/
|
|
37
|
+
readonly lineCount: number;
|
|
38
|
+
/**
|
|
39
|
+
* The document's tokens, which color the lines, or null for plain text.
|
|
40
|
+
*/
|
|
41
|
+
readonly tokens: TokenCache | null;
|
|
42
|
+
/**
|
|
43
|
+
* Decorations in the document's own lines, or null for none; their
|
|
44
|
+
* inserted rows and numbering are not drawn.
|
|
45
|
+
*/
|
|
46
|
+
readonly decorations: ICodeDecorations | null;
|
|
47
|
+
/**
|
|
48
|
+
* Creates embedded lines.
|
|
49
|
+
*
|
|
50
|
+
* @param beforeLine The line they come before, from 0.
|
|
51
|
+
* @param document The document they come from.
|
|
52
|
+
* @param startLine Its first line shown, from 0.
|
|
53
|
+
* @param lineCount How many of its lines show.
|
|
54
|
+
* @param tokens Its tokens, or null, when not given, for plain text.
|
|
55
|
+
* @param decorations Decorations in its own lines, or null, when not given,
|
|
56
|
+
* for none.
|
|
57
|
+
* @throws {ArgumentOutOfRangeException} When `beforeLine`, `startLine` or `lineCount` is negative or not a whole number.
|
|
58
|
+
* @throws {ArgumentOutOfRangeException} When `startLine` plus `lineCount` passes the document's line count.
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* import { TextDocument } from "@noldova/code.editor";
|
|
62
|
+
* import { List } from "@noldova/context.collections";
|
|
63
|
+
* import { CodeDecorations, CodeEmbeddedLines, type CodeGutterMarker, type CodeInsertedRows, type CodeLineDecoration, type CodeRangeDecoration }
|
|
64
|
+
* from "@noldova/code.editor.angular";
|
|
65
|
+
*
|
|
66
|
+
* const removed = TextDocument.fromText("old line\n");
|
|
67
|
+
* const layer = new CodeDecorations(new List<CodeLineDecoration>(), new List<CodeRangeDecoration>(), new List<CodeGutterMarker>(),
|
|
68
|
+
* new List<CodeInsertedRows>([new CodeEmbeddedLines(3, removed, 0, 1)]));
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
constructor(beforeLine: number, document: TextDocument, startLine: number, lineCount: number, tokens?: TokenCache | null, decorations?: ICodeDecorations | null);
|
|
72
|
+
/**
|
|
73
|
+
* The number of lines shown.
|
|
74
|
+
*/
|
|
75
|
+
get rowCount(): number;
|
|
76
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { ArgumentOutOfRangeException } from "@noldova/context.exceptions";
|
|
9
|
+
import { TextPosition } from "@noldova/code.editor";
|
|
10
|
+
import { Resources } from "../../../resources.js";
|
|
11
|
+
import { InsertedRows } from "./inserted-rows.js";
|
|
12
|
+
export class CodeEmbeddedLines extends InsertedRows {
|
|
13
|
+
beforeLine;
|
|
14
|
+
document;
|
|
15
|
+
startLine;
|
|
16
|
+
lineCount;
|
|
17
|
+
tokens;
|
|
18
|
+
decorations;
|
|
19
|
+
constructor(beforeLine, document, startLine, lineCount, tokens = null, decorations = null) {
|
|
20
|
+
super(beforeLine);
|
|
21
|
+
TextPosition.requireCount(startLine, Resources.startLineParameter);
|
|
22
|
+
TextPosition.requireCount(lineCount, Resources.lineCountParameter);
|
|
23
|
+
if (startLine + lineCount > document.lineCount)
|
|
24
|
+
throw new ArgumentOutOfRangeException(Resources.lineCountParameter, lineCount, Resources.formatPastDocument(document.lineCount));
|
|
25
|
+
this.beforeLine = beforeLine;
|
|
26
|
+
this.document = document;
|
|
27
|
+
this.startLine = startLine;
|
|
28
|
+
this.lineCount = lineCount;
|
|
29
|
+
this.tokens = tokens;
|
|
30
|
+
this.decorations = decorations;
|
|
31
|
+
}
|
|
32
|
+
get rowCount() {
|
|
33
|
+
return this.lineCount;
|
|
34
|
+
}
|
|
35
|
+
/** @internal */
|
|
36
|
+
get largestNumber() {
|
|
37
|
+
return this.document.lineCount;
|
|
38
|
+
}
|
|
39
|
+
/** @internal */
|
|
40
|
+
rowAt(builder, _line, index) {
|
|
41
|
+
return builder.embeddedRow(this, this.startLine + index);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import type { CodeBar } from "../decorations/code-bar.js";
|
|
9
|
+
import type { CodeEmbeddedLines } from "./code-embedded-lines.js";
|
|
10
|
+
import type { CodeSpacer } from "./code-spacer.js";
|
|
11
|
+
/**
|
|
12
|
+
* Rows the code view draws between two lines, which take no line of its
|
|
13
|
+
* document: a {@link CodeBar}, a {@link CodeSpacer} or
|
|
14
|
+
* {@link CodeEmbeddedLines}, and nothing else.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* In 0.0.x their line is their owner's to remap after an edit.
|
|
18
|
+
*/
|
|
19
|
+
export type CodeInsertedRows = CodeBar | CodeSpacer | CodeEmbeddedLines;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import type { LineSegment } from "@noldova/code.editor";
|
|
9
|
+
import type { IReadOnlyList } from "@noldova/context.collections";
|
|
10
|
+
import type { CodeRowKind } from "../../enums/code-row-kind.js";
|
|
11
|
+
import type { CodeBar } from "../decorations/code-bar.js";
|
|
12
|
+
import type { CodeFold } from "../folding/code-fold.js";
|
|
13
|
+
import type { CodeGutterMarker } from "../decorations/code-gutter-marker.js";
|
|
14
|
+
import type { RowSpan } from "./row-span.js";
|
|
15
|
+
export declare class CodeRow {
|
|
16
|
+
readonly number: number | null;
|
|
17
|
+
readonly otherNumber: number | null;
|
|
18
|
+
readonly text: string;
|
|
19
|
+
readonly segments: IReadOnlyList<LineSegment>;
|
|
20
|
+
readonly kind: CodeRowKind;
|
|
21
|
+
readonly paints: readonly string[];
|
|
22
|
+
readonly marker: CodeGutterMarker | null;
|
|
23
|
+
readonly spans: readonly RowSpan[];
|
|
24
|
+
readonly bar: CodeBar | null;
|
|
25
|
+
readonly fold: CodeFold | null;
|
|
26
|
+
constructor(number: number | null, otherNumber: number | null, text: string, segments: IReadOnlyList<LineSegment>, kind: CodeRowKind, paints: readonly string[], marker: CodeGutterMarker | null, spans: readonly RowSpan[], bar: CodeBar | null, fold: CodeFold | null);
|
|
27
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export class CodeRow {
|
|
9
|
+
number;
|
|
10
|
+
otherNumber;
|
|
11
|
+
text;
|
|
12
|
+
segments;
|
|
13
|
+
kind;
|
|
14
|
+
paints;
|
|
15
|
+
marker;
|
|
16
|
+
spans;
|
|
17
|
+
bar;
|
|
18
|
+
fold;
|
|
19
|
+
constructor(number, otherNumber, text, segments, kind, paints, marker, spans, bar, fold) {
|
|
20
|
+
this.number = number;
|
|
21
|
+
this.otherNumber = otherNumber;
|
|
22
|
+
this.text = text;
|
|
23
|
+
this.segments = segments;
|
|
24
|
+
this.kind = kind;
|
|
25
|
+
this.paints = paints;
|
|
26
|
+
this.marker = marker;
|
|
27
|
+
this.spans = spans;
|
|
28
|
+
this.bar = bar;
|
|
29
|
+
this.fold = fold;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { InsertedRows } from "./inserted-rows.js";
|
|
9
|
+
/**
|
|
10
|
+
* Filler rows between two lines, such as the shorter side of a change side
|
|
11
|
+
* by side: striped, or painted with a background, with an optional gutter
|
|
12
|
+
* sign.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* Later fields come as optional constructor parameters at the end.
|
|
16
|
+
*/
|
|
17
|
+
export declare class CodeSpacer extends InsertedRows {
|
|
18
|
+
/**
|
|
19
|
+
* The line the rows come before, from 0; the document's line count puts
|
|
20
|
+
* them after its last line.
|
|
21
|
+
*/
|
|
22
|
+
readonly beforeLine: number;
|
|
23
|
+
/**
|
|
24
|
+
* How many rows it takes.
|
|
25
|
+
*/
|
|
26
|
+
readonly rowCount: number;
|
|
27
|
+
/**
|
|
28
|
+
* The rows' CSS background, or null for the stripes of an empty row.
|
|
29
|
+
*/
|
|
30
|
+
readonly background: string | null;
|
|
31
|
+
/**
|
|
32
|
+
* A sign in the rows' gutter cells, or null for none.
|
|
33
|
+
*/
|
|
34
|
+
readonly sign: string | null;
|
|
35
|
+
/**
|
|
36
|
+
* The sign's CSS color, or null for the gutter's own color.
|
|
37
|
+
*/
|
|
38
|
+
readonly signColor: string | null;
|
|
39
|
+
/**
|
|
40
|
+
* Creates filler rows.
|
|
41
|
+
*
|
|
42
|
+
* @param beforeLine The line the rows come before, from 0.
|
|
43
|
+
* @param rowCount How many rows it takes.
|
|
44
|
+
* @param background The rows' CSS background, or null, when not given, for
|
|
45
|
+
* stripes.
|
|
46
|
+
* @param sign A gutter sign, or null, when not given, for none.
|
|
47
|
+
* @param signColor The sign's CSS color, or null, when not given, for the
|
|
48
|
+
* gutter's own.
|
|
49
|
+
* @throws {ArgumentOutOfRangeException} When `beforeLine` or `rowCount` is negative or not a whole number.
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { List } from "@noldova/context.collections";
|
|
53
|
+
* import { CodeDecorations, type CodeGutterMarker, type CodeInsertedRows, type CodeLineDecoration, type CodeRangeDecoration, CodeSpacer }
|
|
54
|
+
* from "@noldova/code.editor.angular";
|
|
55
|
+
*
|
|
56
|
+
* const filler = new CodeDecorations(new List<CodeLineDecoration>(), new List<CodeRangeDecoration>(), new List<CodeGutterMarker>(),
|
|
57
|
+
* new List<CodeInsertedRows>([new CodeSpacer(5, 2)]));
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
constructor(beforeLine: number, rowCount: number, background?: string | null, sign?: string | null, signColor?: string | null);
|
|
61
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { TextPosition } from "@noldova/code.editor";
|
|
9
|
+
import { Resources } from "../../../resources.js";
|
|
10
|
+
import { InsertedRows } from "./inserted-rows.js";
|
|
11
|
+
export class CodeSpacer extends InsertedRows {
|
|
12
|
+
beforeLine;
|
|
13
|
+
rowCount;
|
|
14
|
+
background;
|
|
15
|
+
sign;
|
|
16
|
+
signColor;
|
|
17
|
+
constructor(beforeLine, rowCount, background = null, sign = null, signColor = null) {
|
|
18
|
+
super(beforeLine);
|
|
19
|
+
TextPosition.requireCount(rowCount, Resources.rowCountParameter);
|
|
20
|
+
this.beforeLine = beforeLine;
|
|
21
|
+
this.rowCount = rowCount;
|
|
22
|
+
this.background = background;
|
|
23
|
+
this.sign = sign;
|
|
24
|
+
this.signColor = signColor;
|
|
25
|
+
}
|
|
26
|
+
/** @internal */
|
|
27
|
+
rowAt(builder, line) {
|
|
28
|
+
return builder.spacerRow(this, line);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class InsertedRows {
|
|
9
|
+
abstract readonly beforeLine: number;
|
|
10
|
+
protected constructor(beforeLine: number);
|
|
11
|
+
abstract readonly rowCount: number;
|
|
12
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { TextPosition } from "@noldova/code.editor";
|
|
9
|
+
import { Resources } from "../../../resources.js";
|
|
10
|
+
export class InsertedRows {
|
|
11
|
+
constructor(beforeLine) {
|
|
12
|
+
TextPosition.requireCount(beforeLine, Resources.beforeLineParameter);
|
|
13
|
+
}
|
|
14
|
+
/** @internal */
|
|
15
|
+
get largestNumber() {
|
|
16
|
+
return 0;
|
|
17
|
+
}
|
|
18
|
+
}
|