@tectra-ng/code-editor 0.0.1 → 0.2.2
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/README.md +81 -0
- package/fesm2022/tectra-ng-code-editor-highlight.mjs +1219 -0
- package/fesm2022/tectra-ng-code-editor-highlight.mjs.map +1 -0
- package/fesm2022/tectra-ng-code-editor.mjs +3080 -0
- package/fesm2022/tectra-ng-code-editor.mjs.map +1 -0
- package/highlight/README.md +39 -0
- package/package.json +62 -4
- package/types/tectra-ng-code-editor-highlight.d.ts +190 -0
- package/types/tectra-ng-code-editor-highlight.d.ts.map +1 -0
- package/types/tectra-ng-code-editor.d.ts +461 -0
- package/types/tectra-ng-code-editor.d.ts.map +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Code editor
|
|
2
|
+
|
|
3
|
+
```bash
|
|
4
|
+
npm install @tectra-ng/code-editor
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
Its own package: `tectra-ng` and `@tectra-ng/ui` do not include it, so apps without a code editor do not carry the engine. It needs `@tectra-ng/ui` (and with it `core`, `themes`, `icons`) of the same version.
|
|
8
|
+
|
|
9
|
+
An editor for HTML, CSS, JavaScript, TypeScript, JSON and Markdown. Syntax colours come from the design tokens (light, dark and every theme), line numbers, undo and redo, smart indents, auto-closed brackets, quotes and HTML tags, comments with Ctrl/⌘+/, line moves, bracket matching, search and replace, and form support. On the server it renders the highlighted code with the same size, so the page does not jump when the editor starts after hydration. `tx-code-diff` shows the changes between two texts; `@tectra-ng/code-editor/highlight` has the tokenizers and a static `tx-code-highlight` view without the engine.
|
|
10
|
+
|
|
11
|
+
```html
|
|
12
|
+
<tx-code-editor [(value)]="html" height="400px" />
|
|
13
|
+
|
|
14
|
+
<tx-code-editor language="json" [formControl]="settings" height="240px" />
|
|
15
|
+
|
|
16
|
+
<tx-code-editor diffMode [originalValue]="saved" [(value)]="draft" />
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The engine is the CodeMirror core (state and view): input, selection and the visible part of long files. Everything above it — the tokenizers, colours, undo history, commands, search and the diff — is part of the package. `@tectra-ng/ui` does not depend on it.
|
|
20
|
+
|
|
21
|
+
## Inputs
|
|
22
|
+
| Name | Description |
|
|
23
|
+
|---|---|
|
|
24
|
+
| value | Two-way: the text; a form control works too |
|
|
25
|
+
| language | `html`, `css`, `javascript`, `typescript`, `json`, `markdown` or `plain`; short names (`js`, `ts`, `md`, `plaintext`) work too |
|
|
26
|
+
| height | Height of the editor, e.g. `400px`; `100%` fills the parent |
|
|
27
|
+
| readOnly | Keeps the cursor, selection, copy and search, blocks edits |
|
|
28
|
+
| lineNumbers | Shows the line numbers |
|
|
29
|
+
| wordWrap | Wraps long lines instead of scrolling sideways; the rest of a line keeps its indent |
|
|
30
|
+
| indentGuides | Thin vertical lines at every indent level; they go on over blank lines |
|
|
31
|
+
| tabSize | Spaces per indent; taken from the text when not set |
|
|
32
|
+
| placeholder | Text shown while the editor is empty |
|
|
33
|
+
| search | Turns on search and replace (Ctrl/⌘+F) |
|
|
34
|
+
| disabled | Turns the editor off; follows the form control by default |
|
|
35
|
+
| invalid | Red frame; follows the form control by default |
|
|
36
|
+
| ariaLabel | Accessible name of the text area |
|
|
37
|
+
| ariaLabelledBy | Id of the element that names the text area |
|
|
38
|
+
| diffMode | Shows the changes from `originalValue` to `value` inline instead of the editor |
|
|
39
|
+
| originalValue | The original text for `diffMode` |
|
|
40
|
+
| diffView | `inline` or `split` for `diffMode` |
|
|
41
|
+
| dt | Design tokens of this editor (`codeEditor`); `syntax` changes the colours of the code (`codeSyntax`) |
|
|
42
|
+
| pt | Classes and styles of the parts: `root`, `editor`, `search`, `searchInput` |
|
|
43
|
+
| ptOptions | How `pt` merges with the global pass-through |
|
|
44
|
+
| unstyled | Drops the tectra styles, keeps the behaviour |
|
|
45
|
+
|
|
46
|
+
## Outputs
|
|
47
|
+
| Name | Description |
|
|
48
|
+
|---|---|
|
|
49
|
+
| valueChange | The text after every edit |
|
|
50
|
+
| codeChanged | The text after every edit (same as `valueChange`) |
|
|
51
|
+
| focused | The text area got focus |
|
|
52
|
+
| blurred | The text area lost focus; touches the form control |
|
|
53
|
+
| diffChanged | Counts of added and removed lines in `diffMode` |
|
|
54
|
+
|
|
55
|
+
## Methods
|
|
56
|
+
| Name | Description |
|
|
57
|
+
|---|---|
|
|
58
|
+
| focus() | Moves focus into the editor |
|
|
59
|
+
| undo() / redo() | Undoes or redoes the last change |
|
|
60
|
+
| openSearch(replace?) | Opens search, or search and replace |
|
|
61
|
+
| closeSearch() | Closes search and returns focus to the text |
|
|
62
|
+
| findNext() / findPrevious() | Selects the next or previous match |
|
|
63
|
+
| replaceCurrent() / replaceAll() | Replaces the selected match or every match |
|
|
64
|
+
|
|
65
|
+
## Keyboard
|
|
66
|
+
| Key | Action |
|
|
67
|
+
|---|---|
|
|
68
|
+
| Ctrl/⌘+Z, Ctrl/⌘+Shift+Z, Ctrl+Y | Undo, redo |
|
|
69
|
+
| Tab / Shift+Tab | Indents or outdents; Escape and then Tab moves focus out of the editor |
|
|
70
|
+
| Enter | New line with the same indent, one level more after an opening bracket or tag |
|
|
71
|
+
| Ctrl/⌘+/ | Comments or uncomments the lines |
|
|
72
|
+
| Ctrl/⌘+] / Ctrl/⌘+[ | Indents or outdents the lines |
|
|
73
|
+
| Alt+↑ / Alt+↓ | Moves the lines up or down |
|
|
74
|
+
| Shift+Alt+↑ / Shift+Alt+↓ | Copies the lines up or down |
|
|
75
|
+
| Ctrl/⌘+Shift+K | Deletes the lines |
|
|
76
|
+
| Ctrl/⌘+A | Selects all |
|
|
77
|
+
| Ctrl/⌘+F | Opens search |
|
|
78
|
+
| Ctrl+H, ⌥⌘F on macOS | Opens search and replace |
|
|
79
|
+
| Enter / Shift+Enter, F3 / Shift+F3 | Next or previous match |
|
|
80
|
+
| Ctrl/⌘+Enter in the replace field | Replaces every match |
|
|
81
|
+
| Escape | Closes search |
|