@semantic-components/code 0.62.0 → 0.64.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.
- package/esm2022/index.js +2 -0
- package/esm2022/index.js.map +1 -0
- package/esm2022/lib/components/code-editor/code-editor-content.js +435 -0
- package/esm2022/lib/components/code-editor/code-editor-content.js.map +1 -0
- package/esm2022/lib/components/code-editor/code-editor-copy-button.js +90 -0
- package/esm2022/lib/components/code-editor/code-editor-copy-button.js.map +1 -0
- package/esm2022/lib/components/code-editor/code-editor-footer.js +27 -0
- package/esm2022/lib/components/code-editor/code-editor-footer.js.map +1 -0
- package/esm2022/lib/components/code-editor/code-editor-header.js +27 -0
- package/esm2022/lib/components/code-editor/code-editor-header.js.map +1 -0
- package/esm2022/lib/components/code-editor/code-editor-label.js +27 -0
- package/esm2022/lib/components/code-editor/code-editor-label.js.map +1 -0
- package/esm2022/lib/components/code-editor/code-editor.js +27 -0
- package/esm2022/lib/components/code-editor/code-editor.js.map +1 -0
- package/esm2022/lib/components/code-editor/index.js +7 -0
- package/esm2022/lib/components/code-editor/index.js.map +1 -0
- package/esm2022/lib/components/code-viewer/code-viewer-content.js +70 -0
- package/esm2022/lib/components/code-viewer/code-viewer-content.js.map +1 -0
- package/esm2022/lib/components/code-viewer/code-viewer-header.js +27 -0
- package/esm2022/lib/components/code-viewer/code-viewer-header.js.map +1 -0
- package/esm2022/lib/components/code-viewer/code-viewer-label.js +27 -0
- package/esm2022/lib/components/code-viewer/code-viewer-label.js.map +1 -0
- package/esm2022/lib/components/code-viewer/code-viewer.js +27 -0
- package/esm2022/lib/components/code-viewer/code-viewer.js.map +1 -0
- package/esm2022/lib/components/code-viewer/index.js +5 -0
- package/esm2022/lib/components/code-viewer/index.js.map +1 -0
- package/esm2022/lib/components/index.js +3 -0
- package/esm2022/lib/components/index.js.map +1 -0
- package/esm2022/semantic-components-code.js +5 -0
- package/esm2022/semantic-components-code.js.map +1 -0
- package/lib/components/code-editor/code-editor-content.d.ts +57 -0
- package/lib/components/code-editor/code-editor-copy-button.d.ts +11 -0
- package/lib/components/code-editor/code-editor-footer.d.ts +7 -0
- package/lib/components/code-editor/code-editor-header.d.ts +7 -0
- package/lib/components/code-editor/code-editor-label.d.ts +7 -0
- package/lib/components/code-editor/code-editor.d.ts +7 -0
- package/lib/components/code-viewer/code-viewer-content.d.ts +17 -0
- package/lib/components/code-viewer/code-viewer-header.d.ts +7 -0
- package/lib/components/code-viewer/code-viewer-label.d.ts +7 -0
- package/lib/components/code-viewer/code-viewer.d.ts +7 -0
- package/package.json +15 -3
- package/semantic-components-code.d.ts +5 -0
- package/eslint.config.mjs +0 -48
- package/ng-package.json +0 -8
- package/project.json +0 -28
- package/src/lib/components/code-editor/README.md +0 -368
- package/src/lib/components/code-editor/code-editor-content.ts +0 -507
- package/src/lib/components/code-editor/code-editor-copy-button.ts +0 -77
- package/src/lib/components/code-editor/code-editor-footer.ts +0 -31
- package/src/lib/components/code-editor/code-editor-header.ts +0 -31
- package/src/lib/components/code-editor/code-editor-label.ts +0 -28
- package/src/lib/components/code-editor/code-editor.ts +0 -31
- package/src/lib/components/code-viewer/README.md +0 -178
- package/src/lib/components/code-viewer/code-viewer-content.ts +0 -96
- package/src/lib/components/code-viewer/code-viewer-header.ts +0 -31
- package/src/lib/components/code-viewer/code-viewer-label.ts +0 -28
- package/src/lib/components/code-viewer/code-viewer.ts +0 -28
- package/tsconfig.json +0 -28
- package/tsconfig.lib.json +0 -12
- package/tsconfig.lib.prod.json +0 -7
- /package/{src/index.ts → index.d.ts} +0 -0
- /package/{src/lib/components/code-editor/index.ts → lib/components/code-editor/index.d.ts} +0 -0
- /package/{src/lib/components/code-viewer/index.ts → lib/components/code-viewer/index.d.ts} +0 -0
- /package/{src/lib/components/index.ts → lib/components/index.d.ts} +0 -0
package/project.json
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "code",
|
|
3
|
-
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
-
"sourceRoot": "libs/code/src",
|
|
5
|
-
"prefix": "sc",
|
|
6
|
-
"projectType": "library",
|
|
7
|
-
"tags": [],
|
|
8
|
-
"targets": {
|
|
9
|
-
"build": {
|
|
10
|
-
"executor": "@nx/angular:ng-packagr-lite",
|
|
11
|
-
"outputs": ["{workspaceRoot}/dist/{projectRoot}"],
|
|
12
|
-
"options": {
|
|
13
|
-
"project": "libs/code/ng-package.json",
|
|
14
|
-
"tsConfig": "libs/code/tsconfig.lib.json"
|
|
15
|
-
},
|
|
16
|
-
"configurations": {
|
|
17
|
-
"production": {
|
|
18
|
-
"tsConfig": "libs/code/tsconfig.lib.prod.json"
|
|
19
|
-
},
|
|
20
|
-
"development": {}
|
|
21
|
-
},
|
|
22
|
-
"defaultConfiguration": "production"
|
|
23
|
-
},
|
|
24
|
-
"lint": {
|
|
25
|
-
"executor": "@nx/eslint:lint"
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,368 +0,0 @@
|
|
|
1
|
-
# Code Editor Components
|
|
2
|
-
|
|
3
|
-
An interactive code editor component with syntax highlighting powered by [Shiki](https://shiki.style/) and shadcn/ui styling. Features line numbers, auto-indent, tab handling, and cursor position tracking. Automatically follows the app's light/dark theme.
|
|
4
|
-
|
|
5
|
-
## Import
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
import { ScCodeEditor, ScCodeEditorHeader, ScCodeEditorLabel, ScCodeEditorFooter, ScCodeEditorContent, ScCodeEditorCopyButton, ScCodeEditorLanguage, detectLanguage } from '@semantic-components/ui-lab';
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Architecture
|
|
12
|
-
|
|
13
|
-
The component uses Shiki's dual-theme feature (`github-light` + `github-dark`) with `defaultColor: false` to generate CSS variable-based output. The CSS switches between `--shiki-light` and `--shiki-dark` variables based on the `.dark` class on the document root.
|
|
14
|
-
|
|
15
|
-
```
|
|
16
|
-
ScCodeEditor (Root - div[sc-code-editor])
|
|
17
|
-
├── ScCodeEditorHeader (Header - div[sc-code-editor-header])
|
|
18
|
-
│ ├── ScCodeEditorLabel (Label - span[sc-code-editor-label])
|
|
19
|
-
│ └── ScCodeEditorCopyButton (Copy button)
|
|
20
|
-
├── ScCodeEditorContent (Content - div[sc-code-editor-content])
|
|
21
|
-
│ ├── Line numbers (optional)
|
|
22
|
-
│ └── Editable textarea with syntax highlighting
|
|
23
|
-
└── ScCodeEditorFooter (Footer - div[sc-code-editor-footer])
|
|
24
|
-
└── Cursor position and stats
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## Components
|
|
28
|
-
|
|
29
|
-
| Component | Selector | Description |
|
|
30
|
-
| ------------------------ | ------------------------------------ | ------------------------------------- |
|
|
31
|
-
| `ScCodeEditor` | `div[sc-code-editor]` | Root container with border and focus |
|
|
32
|
-
| `ScCodeEditorHeader` | `div[sc-code-editor-header]` | Header bar with border |
|
|
33
|
-
| `ScCodeEditorLabel` | `span[sc-code-editor-label]` | Label for filename or language |
|
|
34
|
-
| `ScCodeEditorContent` | `div[sc-code-editor-content]` | Editable code area with highlighting |
|
|
35
|
-
| `ScCodeEditorCopyButton` | `button[sc-code-editor-copy-button]` | Copy button with visual feedback |
|
|
36
|
-
| `ScCodeEditorFooter` | `div[sc-code-editor-footer]` | Footer with cursor position and stats |
|
|
37
|
-
|
|
38
|
-
## Inputs
|
|
39
|
-
|
|
40
|
-
### ScCodeEditor (Root)
|
|
41
|
-
|
|
42
|
-
| Input | Type | Default | Description |
|
|
43
|
-
| ------- | -------- | ------- | ---------------------- |
|
|
44
|
-
| `class` | `string` | `''` | Additional CSS classes |
|
|
45
|
-
|
|
46
|
-
The root container with border, rounded corners, and focus-within ring.
|
|
47
|
-
|
|
48
|
-
### ScCodeEditorHeader
|
|
49
|
-
|
|
50
|
-
| Input | Type | Default | Description |
|
|
51
|
-
| ------- | -------- | ------- | ---------------------- |
|
|
52
|
-
| `class` | `string` | `''` | Additional CSS classes |
|
|
53
|
-
|
|
54
|
-
Header bar with bottom border for filename/language label and copy button.
|
|
55
|
-
|
|
56
|
-
### ScCodeEditorLabel
|
|
57
|
-
|
|
58
|
-
| Input | Type | Default | Description |
|
|
59
|
-
| ------- | -------- | ------- | ---------------------- |
|
|
60
|
-
| `class` | `string` | `''` | Additional CSS classes |
|
|
61
|
-
|
|
62
|
-
Label for displaying filename or language with muted foreground styling.
|
|
63
|
-
|
|
64
|
-
### ScCodeEditorFooter
|
|
65
|
-
|
|
66
|
-
| Input | Type | Default | Description |
|
|
67
|
-
| ------- | -------- | ------- | ---------------------- |
|
|
68
|
-
| `class` | `string` | `''` | Additional CSS classes |
|
|
69
|
-
|
|
70
|
-
Footer bar with top border for displaying cursor position and file statistics.
|
|
71
|
-
|
|
72
|
-
### ScCodeEditorCopyButton
|
|
73
|
-
|
|
74
|
-
| Input | Type | Default | Description |
|
|
75
|
-
| ------- | -------- | ------------ | ---------------------- |
|
|
76
|
-
| `code` | `string` | **required** | The code to copy |
|
|
77
|
-
| `class` | `string` | `''` | Additional CSS classes |
|
|
78
|
-
|
|
79
|
-
Copy button that shows a checkmark on successful copy for 2 seconds.
|
|
80
|
-
|
|
81
|
-
### ScCodeEditorContent
|
|
82
|
-
|
|
83
|
-
| Input | Type | Default | Description |
|
|
84
|
-
| -------------------- | ---------------------- | ------------- | --------------------------------- |
|
|
85
|
-
| `value` | `string` | `''` | Two-way bound editor value |
|
|
86
|
-
| `language` | `ScCodeEditorLanguage` | `'plaintext'` | Language for syntax highlighting |
|
|
87
|
-
| `filename` | `string` | `''` | Filename for language detection |
|
|
88
|
-
| `placeholder` | `string` | `''` | Placeholder text when empty |
|
|
89
|
-
| `disabled` | `boolean` | `false` | Whether the editor is disabled |
|
|
90
|
-
| `readonly` | `boolean` | `false` | Whether the editor is read-only |
|
|
91
|
-
| `showLineNumbers` | `boolean` | `true` | Whether to show line numbers |
|
|
92
|
-
| `tabSize` | `number` | `2` | Number of spaces per tab |
|
|
93
|
-
| `insertSpaces` | `boolean` | `true` | Insert spaces instead of tabs |
|
|
94
|
-
| `wordWrap` | `boolean` | `false` | Enable word wrapping |
|
|
95
|
-
| `autoDetectLanguage` | `boolean` | `false` | Auto-detect language from content |
|
|
96
|
-
| `ariaLabel` | `string` | `''` | Accessibility label |
|
|
97
|
-
| `ariaDescribedby` | `string` | `''` | Accessibility description ID |
|
|
98
|
-
| `class` | `string` | `''` | Additional CSS classes |
|
|
99
|
-
|
|
100
|
-
## Outputs
|
|
101
|
-
|
|
102
|
-
### ScCodeEditorContent
|
|
103
|
-
|
|
104
|
-
| Output | Type | Description |
|
|
105
|
-
| ------------------ | ---------------------------------- | --------------------------------- |
|
|
106
|
-
| `valueChange` | `string` | Emitted when editor value changes |
|
|
107
|
-
| `languageDetected` | `ScCodeEditorLanguage` | Emitted when language is detected |
|
|
108
|
-
| `cursorChange` | `{ line: number; column: number }` | Emitted when cursor moves |
|
|
109
|
-
|
|
110
|
-
## Supported Languages
|
|
111
|
-
|
|
112
|
-
`angular-ts` | `typescript` | `javascript` | `html` | `css` | `json` | `python` | `bash` | `shell` | `markdown` | `yaml` | `sql` | `go` | `rust` | `java` | `plaintext`
|
|
113
|
-
|
|
114
|
-
## Usage
|
|
115
|
-
|
|
116
|
-
### Basic Usage
|
|
117
|
-
|
|
118
|
-
```html
|
|
119
|
-
<div sc-code-editor>
|
|
120
|
-
<div sc-code-editor-content [(value)]="code" language="typescript"></div>
|
|
121
|
-
</div>
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
### Full Featured Editor
|
|
125
|
-
|
|
126
|
-
```html
|
|
127
|
-
<div sc-code-editor>
|
|
128
|
-
<div sc-code-editor-header>
|
|
129
|
-
<div class="flex items-center gap-2">
|
|
130
|
-
<span class="text-sm text-muted-foreground">{{ filename }}</span>
|
|
131
|
-
<span sc-code-editor-label>{{ language }}</span>
|
|
132
|
-
</div>
|
|
133
|
-
<button sc-code-editor-copy-button [code]="code"></button>
|
|
134
|
-
</div>
|
|
135
|
-
|
|
136
|
-
<div sc-code-editor-content [(value)]="code" [language]="language" [filename]="filename" [showLineNumbers]="true" (cursorChange)="onCursorChange($event)"></div>
|
|
137
|
-
|
|
138
|
-
<div sc-code-editor-footer>
|
|
139
|
-
<div class="flex items-center gap-3">
|
|
140
|
-
<span>Ln {{ line }}, Col {{ column }}</span>
|
|
141
|
-
</div>
|
|
142
|
-
<div class="flex items-center gap-3">
|
|
143
|
-
<span>{{ lineCount }} lines</span>
|
|
144
|
-
<span>{{ charCount }} chars</span>
|
|
145
|
-
</div>
|
|
146
|
-
</div>
|
|
147
|
-
</div>
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
### Minimal Editor (No Header/Footer)
|
|
151
|
-
|
|
152
|
-
```html
|
|
153
|
-
<div sc-code-editor>
|
|
154
|
-
<div sc-code-editor-content [(value)]="code" language="json" [showLineNumbers]="false"></div>
|
|
155
|
-
</div>
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
### With Auto-Detect Language
|
|
159
|
-
|
|
160
|
-
```html
|
|
161
|
-
<div sc-code-editor>
|
|
162
|
-
<div sc-code-editor-header>
|
|
163
|
-
<span sc-code-editor-label>{{ detectedLanguage }}</span>
|
|
164
|
-
<button sc-code-editor-copy-button [code]="code"></button>
|
|
165
|
-
</div>
|
|
166
|
-
|
|
167
|
-
<div sc-code-editor-content [(value)]="code" [autoDetectLanguage]="true" (languageDetected)="detectedLanguage = $event"></div>
|
|
168
|
-
</div>
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
### Read-Only Mode
|
|
172
|
-
|
|
173
|
-
```html
|
|
174
|
-
<div sc-code-editor>
|
|
175
|
-
<div sc-code-editor-content [(value)]="code" language="typescript" [readonly]="true"></div>
|
|
176
|
-
</div>
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
### With Word Wrap
|
|
180
|
-
|
|
181
|
-
```html
|
|
182
|
-
<div sc-code-editor>
|
|
183
|
-
<div sc-code-editor-content [(value)]="longCode" language="markdown" [wordWrap]="true" class="max-h-[400px]"></div>
|
|
184
|
-
</div>
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
### Custom Tab Size
|
|
188
|
-
|
|
189
|
-
```html
|
|
190
|
-
<div sc-code-editor>
|
|
191
|
-
<div sc-code-editor-content [(value)]="code" language="python" [tabSize]="4" [insertSpaces]="true"></div>
|
|
192
|
-
</div>
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
### Tracking Cursor Position
|
|
196
|
-
|
|
197
|
-
```typescript
|
|
198
|
-
export class MyComponent {
|
|
199
|
-
code = signal('');
|
|
200
|
-
cursorPosition = signal({ line: 1, column: 1 });
|
|
201
|
-
|
|
202
|
-
onCursorChange(position: { line: number; column: number }) {
|
|
203
|
-
this.cursorPosition.set(position);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
```html
|
|
209
|
-
<div sc-code-editor>
|
|
210
|
-
<div sc-code-editor-content [(value)]="code" language="typescript" (cursorChange)="onCursorChange($event)"></div>
|
|
211
|
-
|
|
212
|
-
<div sc-code-editor-footer>
|
|
213
|
-
<span>Ln {{ cursorPosition().line }}, Col {{ cursorPosition().column }}</span>
|
|
214
|
-
</div>
|
|
215
|
-
</div>
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
## Features
|
|
219
|
-
|
|
220
|
-
### Composable Architecture
|
|
221
|
-
|
|
222
|
-
Build custom layouts with separate header, content, and footer components.
|
|
223
|
-
|
|
224
|
-
### Syntax Highlighting
|
|
225
|
-
|
|
226
|
-
Powered by Shiki with 30+ languages supported. Real-time highlighting as you type.
|
|
227
|
-
|
|
228
|
-
### Smart Indentation
|
|
229
|
-
|
|
230
|
-
- **Tab key**: Insert spaces or tabs (configurable)
|
|
231
|
-
- **Shift+Tab**: Outdent current line
|
|
232
|
-
- **Enter**: Auto-indent based on previous line
|
|
233
|
-
- **Auto-indent**: Extra indent after `{`, `[`, or `:`
|
|
234
|
-
- **Smart brackets**: Auto-outdent when typing `}`, `]`, or `)`
|
|
235
|
-
|
|
236
|
-
### Line Numbers
|
|
237
|
-
|
|
238
|
-
Optional line numbers with active line highlighting.
|
|
239
|
-
|
|
240
|
-
### Language Detection
|
|
241
|
-
|
|
242
|
-
Automatic language detection from file extension or content patterns using the `detectLanguage()` function.
|
|
243
|
-
|
|
244
|
-
### Cursor Tracking
|
|
245
|
-
|
|
246
|
-
Real-time cursor position (line and column) tracking with change events.
|
|
247
|
-
|
|
248
|
-
### Copy Button
|
|
249
|
-
|
|
250
|
-
Built-in copy-to-clipboard functionality with visual feedback.
|
|
251
|
-
|
|
252
|
-
### Accessibility
|
|
253
|
-
|
|
254
|
-
- Proper ARIA labels and descriptions
|
|
255
|
-
- Keyboard navigation support
|
|
256
|
-
- Screen reader friendly
|
|
257
|
-
- Focus management
|
|
258
|
-
|
|
259
|
-
### Customizable
|
|
260
|
-
|
|
261
|
-
All components accept custom classes for styling flexibility.
|
|
262
|
-
|
|
263
|
-
## Theming
|
|
264
|
-
|
|
265
|
-
The component automatically follows the app's theme:
|
|
266
|
-
|
|
267
|
-
- **Light mode**: Uses `github-light` Shiki theme
|
|
268
|
-
- **Dark mode**: Uses `github-dark` Shiki theme (activated by `.dark` class on `<html>`)
|
|
269
|
-
|
|
270
|
-
No manual theme configuration is needed. The component renders both theme colors as CSS variables and switches between them with CSS.
|
|
271
|
-
|
|
272
|
-
## Keyboard Shortcuts
|
|
273
|
-
|
|
274
|
-
| Key | Action |
|
|
275
|
-
| ------------- | ----------------------------------------- |
|
|
276
|
-
| `Tab` | Insert indent (spaces or tab) |
|
|
277
|
-
| `Shift+Tab` | Remove indent |
|
|
278
|
-
| `Enter` | New line with auto-indent |
|
|
279
|
-
| `{`, `[`, `:` | Extra indent on next line after Enter |
|
|
280
|
-
| `}`, `]`, `)` | Auto-outdent when line is only whitespace |
|
|
281
|
-
|
|
282
|
-
## Utility Functions
|
|
283
|
-
|
|
284
|
-
### detectLanguage(code, filename?)
|
|
285
|
-
|
|
286
|
-
Automatically detects the programming language from code content or filename.
|
|
287
|
-
|
|
288
|
-
```typescript
|
|
289
|
-
import { detectLanguage } from '@semantic-components/ui-lab';
|
|
290
|
-
|
|
291
|
-
const language = detectLanguage(code, 'app.component.ts');
|
|
292
|
-
// Returns: 'typescript'
|
|
293
|
-
|
|
294
|
-
const detectedFromContent = detectLanguage('function hello() {}');
|
|
295
|
-
// Returns: 'javascript'
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
**Detection logic:**
|
|
299
|
-
|
|
300
|
-
1. If filename provided, detect from extension
|
|
301
|
-
2. If no filename, analyze code patterns:
|
|
302
|
-
- HTML tags → `html`
|
|
303
|
-
- JSON structure → `json`
|
|
304
|
-
- TypeScript types → `typescript`
|
|
305
|
-
- JavaScript keywords → `javascript`
|
|
306
|
-
- Python syntax → `python`
|
|
307
|
-
- SQL keywords → `sql`
|
|
308
|
-
- Markdown headers → `markdown`
|
|
309
|
-
- Shebang → `bash`
|
|
310
|
-
|
|
311
|
-
## Styling
|
|
312
|
-
|
|
313
|
-
The components use Tailwind CSS with shadcn/ui design tokens:
|
|
314
|
-
|
|
315
|
-
- **Container** (`ScCodeEditor`): Focus-within ring, rounded border
|
|
316
|
-
- **Header** (`ScCodeEditorHeader`): Flex layout with bottom border
|
|
317
|
-
- **Label** (`ScCodeEditorLabel`): Small muted text
|
|
318
|
-
- **Footer** (`ScCodeEditorFooter`): Flex layout with top border
|
|
319
|
-
- **Content** (`ScCodeEditorContent`): Relative positioning with overlay layers
|
|
320
|
-
- **Line numbers**: Muted at 50% opacity, active line at 100%
|
|
321
|
-
- **Code font**: System monospace stack (`ui-monospace, SFMono-Regular, ...`)
|
|
322
|
-
- **Textarea**: Transparent with colored caret for overlay effect
|
|
323
|
-
|
|
324
|
-
## Advanced Example
|
|
325
|
-
|
|
326
|
-
```typescript
|
|
327
|
-
export class CodeEditorExample {
|
|
328
|
-
code = signal(`function greet(name: string) {
|
|
329
|
-
console.log(\`Hello, \${name}!\`);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
greet('World');`);
|
|
333
|
-
|
|
334
|
-
filename = signal('example.ts');
|
|
335
|
-
language = signal<ScCodeEditorLanguage>('typescript');
|
|
336
|
-
stats = computed(() => {
|
|
337
|
-
const value = this.code();
|
|
338
|
-
return {
|
|
339
|
-
lines: value.split('\n').length,
|
|
340
|
-
chars: value.length,
|
|
341
|
-
};
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
```
|
|
345
|
-
|
|
346
|
-
```html
|
|
347
|
-
<div sc-code-editor>
|
|
348
|
-
<div sc-code-editor-header>
|
|
349
|
-
<div class="flex items-center gap-2">
|
|
350
|
-
<span class="text-sm text-muted-foreground">{{ filename() }}</span>
|
|
351
|
-
<span sc-code-editor-label>{{ language() }}</span>
|
|
352
|
-
</div>
|
|
353
|
-
<button sc-code-editor-copy-button [code]="code()"></button>
|
|
354
|
-
</div>
|
|
355
|
-
|
|
356
|
-
<div sc-code-editor-content [(value)]="code" [language]="language()" [filename]="filename()" [showLineNumbers]="true" [tabSize]="2" [insertSpaces]="true" class="max-h-[600px] min-h-[300px]"></div>
|
|
357
|
-
|
|
358
|
-
<div sc-code-editor-footer>
|
|
359
|
-
<div class="flex items-center gap-3">
|
|
360
|
-
<span>Ln {{ stats().line }}, Col {{ stats().column }}</span>
|
|
361
|
-
</div>
|
|
362
|
-
<div class="flex items-center gap-3">
|
|
363
|
-
<span>{{ stats().lines }} lines</span>
|
|
364
|
-
<span>{{ stats().chars }} chars</span>
|
|
365
|
-
</div>
|
|
366
|
-
</div>
|
|
367
|
-
</div>
|
|
368
|
-
```
|