@placeholderco/placeholder-ui 3.3.2 → 3.3.4

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.
@@ -0,0 +1,196 @@
1
+ import { javascript } from '@codemirror/lang-javascript';
2
+ import { html } from '@codemirror/lang-html';
3
+ import { css } from '@codemirror/lang-css';
4
+ import { json } from '@codemirror/lang-json';
5
+ import { markdown } from '@codemirror/lang-markdown';
6
+ import { sql, MSSQL } from '@codemirror/lang-sql';
7
+ import { LanguageSupport, StreamLanguage } from '@codemirror/language';
8
+ import { completeAnyWord, completeFromList } from '@codemirror/autocomplete';
9
+ import { csharp } from '@codemirror/legacy-modes/mode/clike';
10
+ import { diff } from '@codemirror/legacy-modes/mode/diff';
11
+ import { dockerFile } from '@codemirror/legacy-modes/mode/dockerfile';
12
+ import { powerShell } from '@codemirror/legacy-modes/mode/powershell';
13
+ import { properties } from '@codemirror/legacy-modes/mode/properties';
14
+ import { python } from '@codemirror/legacy-modes/mode/python';
15
+ import { shell } from '@codemirror/legacy-modes/mode/shell';
16
+ import { toml } from '@codemirror/legacy-modes/mode/toml';
17
+ import { xml } from '@codemirror/legacy-modes/mode/xml';
18
+ import { yaml } from '@codemirror/legacy-modes/mode/yaml';
19
+ import { log } from './log.js';
20
+ // Languages without a native CodeMirror 6 package use legacy stream parsers. Those provide
21
+ // highlighting only, so keyword lists plus word matching stand in for the scope-aware
22
+ // completions the native language packages ship with.
23
+ const CSHARP_KEYWORDS = ('abstract as async await base bool break byte case catch char checked class const continue ' +
24
+ 'decimal default delegate do double dynamic else enum event explicit extern false finally fixed ' +
25
+ 'float for foreach get global goto if implicit in init int interface internal is lock long ' +
26
+ 'nameof namespace new null object operator out override params partial private protected public ' +
27
+ 'readonly record ref required return sbyte sealed set short sizeof stackalloc static string ' +
28
+ 'struct switch this throw true try typeof uint ulong unchecked unsafe ushort using value var ' +
29
+ 'virtual void volatile when where while yield').split(' ');
30
+ const CSHARP_COMMON_TYPES = ('Console Convert DateTime Dictionary Exception Guid IEnumerable IList List Math Nullable ' +
31
+ 'Object StringBuilder Task TimeSpan').split(' ');
32
+ const POWERSHELL_KEYWORDS = ('begin break catch class continue data do dynamicparam else elseif end enum exit filter ' +
33
+ 'finally for foreach from function hidden if in param process return static switch throw trap ' +
34
+ 'try until using var while workflow').split(' ');
35
+ const POWERSHELL_CMDLETS = ('Add-Content Add-Member Clear-Content Clear-Variable Compare-Object ConvertFrom-Json ' +
36
+ 'ConvertTo-Json Copy-Item Export-Csv ForEach-Object Format-List Format-Table Get-ChildItem ' +
37
+ 'Get-Command Get-Content Get-Date Get-Help Get-Item Get-ItemProperty Get-Location Get-Member ' +
38
+ 'Get-Module Get-Process Get-Random Get-Service Get-Variable Group-Object Import-Csv ' +
39
+ 'Import-Module Install-Module Invoke-Command Invoke-Expression Invoke-RestMethod ' +
40
+ 'Invoke-WebRequest Join-Path Measure-Object Move-Item New-Item New-Object Out-File Out-Null ' +
41
+ 'Read-Host Remove-Item Remove-Variable Rename-Item Resolve-Path Restart-Service Select-Object ' +
42
+ 'Select-String Set-Content Set-ExecutionPolicy Set-Item Set-Location Set-Variable Sort-Object ' +
43
+ 'Split-Path Start-Process Start-Service Start-Sleep Stop-Process Stop-Service Tee-Object ' +
44
+ 'Test-Connection Test-Path Wait-Process Where-Object Write-Debug Write-Error Write-Host ' +
45
+ 'Write-Output Write-Verbose Write-Warning').split(' ');
46
+ const PYTHON_KEYWORDS = ('and as assert async await break case class continue def del elif else except False finally ' +
47
+ 'for from global if import in is lambda match None nonlocal not or pass raise return True try ' +
48
+ 'while with yield').split(' ');
49
+ const PYTHON_BUILTINS = ('abs all any bool dict enumerate filter float getattr hasattr int isinstance len list map max ' +
50
+ 'min next open print range repr reversed round set setattr sorted str sum super tuple type zip').split(' ');
51
+ function toCompletions(words, type) {
52
+ return words.map((label) => ({ label, type }));
53
+ }
54
+ function legacySupport(parser, completions = []) {
55
+ const language = StreamLanguage.define(parser);
56
+ return new LanguageSupport(language, [
57
+ language.data.of({ autocomplete: completeFromList(completions) }),
58
+ language.data.of({ autocomplete: completeAnyWord })
59
+ ]);
60
+ }
61
+ /** Every language the CodeMirror editor and rich code blocks can highlight */
62
+ export const codeLanguages = [
63
+ {
64
+ id: 'plaintext',
65
+ label: 'Plain text',
66
+ aliases: ['text', 'plain', 'txt', 'none'],
67
+ load: () => []
68
+ },
69
+ {
70
+ id: 'javascript',
71
+ label: 'JavaScript',
72
+ aliases: ['js', 'jsx', 'mjs', 'node'],
73
+ load: () => javascript({ jsx: true })
74
+ },
75
+ {
76
+ id: 'typescript',
77
+ label: 'TypeScript',
78
+ aliases: ['ts', 'tsx'],
79
+ load: () => javascript({ typescript: true, jsx: true })
80
+ },
81
+ {
82
+ id: 'html',
83
+ label: 'HTML',
84
+ aliases: ['markup', 'xhtml'],
85
+ load: () => html()
86
+ },
87
+ {
88
+ id: 'css',
89
+ label: 'CSS',
90
+ aliases: ['scss', 'less'],
91
+ load: () => css()
92
+ },
93
+ {
94
+ id: 'json',
95
+ label: 'JSON',
96
+ aliases: ['jsonc'],
97
+ load: () => json()
98
+ },
99
+ {
100
+ id: 'markdown',
101
+ label: 'Markdown',
102
+ aliases: ['md'],
103
+ load: () => markdown()
104
+ },
105
+ {
106
+ id: 'sql',
107
+ label: 'SQL',
108
+ aliases: ['tsql', 'mssql', 'sqlserver', 'mysql', 'postgres', 'postgresql', 'sqlite', 'plsql'],
109
+ // T-SQL dialect: covers standard SQL plus SQL Server extras
110
+ // ([bracketed] identifiers, @variables, TOP, NVARCHAR, ...)
111
+ load: () => sql({ dialect: MSSQL, upperCaseKeywords: true })
112
+ },
113
+ {
114
+ id: 'csharp',
115
+ label: 'C#',
116
+ aliases: ['cs', 'c#', 'dotnet'],
117
+ load: () => legacySupport(csharp, [
118
+ ...toCompletions(CSHARP_KEYWORDS, 'keyword'),
119
+ ...toCompletions(CSHARP_COMMON_TYPES, 'class')
120
+ ])
121
+ },
122
+ {
123
+ id: 'powershell',
124
+ label: 'PowerShell',
125
+ aliases: ['ps', 'ps1', 'psm1', 'psd1', 'pwsh', 'posh'],
126
+ load: () => legacySupport(powerShell, [
127
+ ...toCompletions(POWERSHELL_KEYWORDS, 'keyword'),
128
+ ...toCompletions(POWERSHELL_CMDLETS, 'function')
129
+ ])
130
+ },
131
+ {
132
+ id: 'python',
133
+ label: 'Python',
134
+ aliases: ['py', 'python3'],
135
+ load: () => legacySupport(python, [
136
+ ...toCompletions(PYTHON_KEYWORDS, 'keyword'),
137
+ ...toCompletions(PYTHON_BUILTINS, 'function')
138
+ ])
139
+ },
140
+ {
141
+ id: 'shell',
142
+ label: 'Shell',
143
+ aliases: ['sh', 'bash', 'zsh'],
144
+ load: () => legacySupport(shell)
145
+ },
146
+ {
147
+ id: 'yaml',
148
+ label: 'YAML',
149
+ aliases: ['yml'],
150
+ load: () => legacySupport(yaml)
151
+ },
152
+ {
153
+ // 'xml' and 'svg' were HTML aliases; the XML parser reads them more accurately.
154
+ id: 'xml',
155
+ label: 'XML',
156
+ aliases: ['svg', 'xsd', 'xsl', 'xslt', 'csproj'],
157
+ load: () => legacySupport(xml)
158
+ },
159
+ {
160
+ id: 'toml',
161
+ label: 'TOML',
162
+ aliases: [],
163
+ load: () => legacySupport(toml)
164
+ },
165
+ {
166
+ id: 'ini',
167
+ label: 'INI',
168
+ aliases: ['properties', 'conf', 'cfg', 'env'],
169
+ load: () => legacySupport(properties)
170
+ },
171
+ {
172
+ id: 'dockerfile',
173
+ label: 'Dockerfile',
174
+ aliases: ['docker', 'containerfile'],
175
+ load: () => legacySupport(dockerFile)
176
+ },
177
+ {
178
+ id: 'diff',
179
+ label: 'Diff',
180
+ aliases: ['patch'],
181
+ load: () => legacySupport(diff)
182
+ },
183
+ {
184
+ id: 'log',
185
+ label: 'Log',
186
+ aliases: ['logs'],
187
+ load: () => log()
188
+ }
189
+ ];
190
+ /** Look up a language definition by id or alias (case-insensitive) */
191
+ export function resolveCodeLanguage(language) {
192
+ if (!language)
193
+ return undefined;
194
+ const normalized = language.toLowerCase();
195
+ return codeLanguages.find((def) => def.id === normalized || def.aliases.includes(normalized));
196
+ }
@@ -0,0 +1,6 @@
1
+ import type { Extension, Text } from '@codemirror/state';
2
+ export type LogLevel = 'error' | 'warning' | 'info' | 'debug' | 'marker';
3
+ /** A line's level: its own, or for a continuation line, that of the entry it belongs to. */
4
+ export declare function logLevelAt(doc: Text, lineNumber: number): LogLevel | undefined;
5
+ /** Log output: each line coloured by its level, with stack traces in their entry's colour. */
6
+ export declare function log(): Extension;
@@ -0,0 +1,122 @@
1
+ import { RangeSetBuilder } from '@codemirror/state';
2
+ import { Decoration, EditorView, ViewPlugin } from '@codemirror/view';
3
+ import { LanguageSupport, StreamLanguage } from '@codemirror/language';
4
+ // `[2026-11-10 17:11:30]`, an ISO timestamp (Serilog's default puts a space before the offset),
5
+ // or a bare `17:11:30` at the start of the line.
6
+ const TIMESTAMP = /^(?:\[?\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z| ?[+-]\d{2}:?\d{2})?\]?|\d{2}:\d{2}:\d{2}(?:\.\d+)?)/;
7
+ // Run boundaries as a job wrapper writes them, and separator rules.
8
+ const MARKER = /\] (?:START|END|STOPPED|RETRY|TIMED OUT|TIMEOUT)\b|^\s*(?:-{20,}|={20,})\s*$/i;
9
+ const TAG = /^\[(?:ERROR|ERR|FATAL|FTL|CRITICAL|WARN(?:ING)?|WRN|DEBUG|DBG|VERBOSE|VRB|TRACE|INFO(?:RMATION)?|INF)\]/i;
10
+ // A bracketed tag anywhere wins, in this order; otherwise a bare level word after the timestamp.
11
+ // Serilog writes `[ERR]` (`{Level:u3}`) or `[Error]`; .NET's console logger starts a line `fail: `.
12
+ const TAGS = [
13
+ [/\[(?:ERROR|ERR|FATAL|FTL|CRITICAL)\]/i, 'error'],
14
+ [/\[(?:WARN(?:ING)?|WRN)\]/i, 'warning'],
15
+ [/\[(?:DEBUG|DBG|VERBOSE|VRB|TRACE)\]/i, 'debug'],
16
+ [/\[(?:INFO(?:RMATION)?|INF)\]/i, 'info']
17
+ ];
18
+ const WORDS = [
19
+ [
20
+ /^\s*(?:(?:ERROR|FATAL|CRITICAL)\b|(?:fail|crit):|Traceback \(most recent call last\)|UNHANDLED EXCEPTION)/i,
21
+ 'error'
22
+ ],
23
+ [/^\s*WARN(?:ING)?\b/i, 'warning'],
24
+ [/^\s*(?:(?:DEBUG|VERBOSE|TRACE)\b|(?:dbug|trce):)/i, 'debug'],
25
+ [/^\s*INFO\b/i, 'info']
26
+ ];
27
+ // The rest of a multi-line entry: an indented line (a stack frame, a Python traceback),
28
+ // `--- End of ...` and ` ---> Inner`, or an exception's first line.
29
+ const CONTINUATION = /^\s+\S|^\s*---[\s>]|^[A-Za-z_][\w.`]*(?:Exception|Error)\b/;
30
+ // How far a continuation line looks back for the entry it belongs to.
31
+ const LOOKBACK = 500;
32
+ function ownLevel(line) {
33
+ for (const [pattern, level] of TAGS) {
34
+ if (pattern.test(line))
35
+ return level;
36
+ }
37
+ if (MARKER.test(line))
38
+ return 'marker';
39
+ const stamp = TIMESTAMP.exec(line);
40
+ const body = stamp ? line.slice(stamp[0].length) : line;
41
+ for (const [pattern, level] of WORDS) {
42
+ if (pattern.test(body))
43
+ return level;
44
+ }
45
+ return undefined;
46
+ }
47
+ function continues(line) {
48
+ const stamp = TIMESTAMP.exec(line);
49
+ return CONTINUATION.test(stamp ? line.slice(stamp[0].length).replace(/^ /, '') : line);
50
+ }
51
+ /** A line's level: its own, or for a continuation line, that of the entry it belongs to. */
52
+ export function logLevelAt(doc, lineNumber) {
53
+ const own = ownLevel(doc.line(lineNumber).text);
54
+ if (own || !continues(doc.line(lineNumber).text))
55
+ return own;
56
+ for (let n = lineNumber - 1; n >= Math.max(1, lineNumber - LOOKBACK); n--) {
57
+ const text = doc.line(n).text;
58
+ const level = ownLevel(text);
59
+ if (level)
60
+ return level === 'marker' ? undefined : level;
61
+ if (!continues(text))
62
+ return undefined;
63
+ }
64
+ return undefined;
65
+ }
66
+ const lineClasses = Object.fromEntries(['error', 'warning', 'info', 'debug', 'marker'].map((level) => [
67
+ level,
68
+ Decoration.line({ class: `cm-log-${level}` })
69
+ ]));
70
+ function levelDecorations(view) {
71
+ const builder = new RangeSetBuilder();
72
+ const doc = view.state.doc;
73
+ for (const { from, to } of view.visibleRanges) {
74
+ for (let n = doc.lineAt(from).number; n <= doc.lineAt(to).number; n++) {
75
+ const level = logLevelAt(doc, n);
76
+ if (level)
77
+ builder.add(doc.line(n).from, doc.line(n).from, lineClasses[level]);
78
+ }
79
+ }
80
+ return builder.finish();
81
+ }
82
+ const levelPlugin = ViewPlugin.fromClass(class {
83
+ decorations;
84
+ constructor(view) {
85
+ this.decorations = levelDecorations(view);
86
+ }
87
+ update(update) {
88
+ if (update.docChanged || update.viewportChanged) {
89
+ this.decorations = levelDecorations(update.view);
90
+ }
91
+ }
92
+ }, { decorations: (plugin) => plugin.decorations });
93
+ // Timestamps and level tags as tokens; the line's colour comes from its level.
94
+ const parser = {
95
+ name: 'log',
96
+ startState: () => null,
97
+ token(stream) {
98
+ if (stream.sol() && stream.match(TIMESTAMP))
99
+ return 'meta';
100
+ if (stream.match(TAG))
101
+ return 'strong';
102
+ stream.next();
103
+ stream.eatWhile(/[^[]/);
104
+ return null;
105
+ }
106
+ };
107
+ // Overridable per app through the `--cm-log-*` custom properties.
108
+ const levelTheme = EditorView.baseTheme({
109
+ '&light .cm-log-error': { color: 'var(--cm-log-error, #c92a2a)' },
110
+ '&light .cm-log-warning': { color: 'var(--cm-log-warning, #b45309)' },
111
+ '&light .cm-log-info': { color: 'var(--cm-log-info, #0e7490)' },
112
+ '&light .cm-log-debug': { color: 'var(--cm-log-debug, #15803d)' },
113
+ '&dark .cm-log-error': { color: 'var(--cm-log-error, #ffa8a8)' },
114
+ '&dark .cm-log-warning': { color: 'var(--cm-log-warning, #ffd43b)' },
115
+ '&dark .cm-log-info': { color: 'var(--cm-log-info, #66d9e8)' },
116
+ '&dark .cm-log-debug': { color: 'var(--cm-log-debug, #8ce99a)' },
117
+ '.cm-log-marker': { fontWeight: '600' }
118
+ });
119
+ /** Log output: each line coloured by its level, with stack traces in their entry's colour. */
120
+ export function log() {
121
+ return new LanguageSupport(StreamLanguage.define(parser), [levelPlugin, levelTheme]);
122
+ }
@@ -0,0 +1,3 @@
1
+ import type { Extension } from '@codemirror/state';
2
+ /** The editor theme for the library's own light or dark mode */
3
+ export declare function libraryTheme(dark: boolean): Extension;
@@ -0,0 +1,64 @@
1
+ import { EditorView } from '@codemirror/view';
2
+ import { HighlightStyle, syntaxHighlighting } from '@codemirror/language';
3
+ import { tags as t } from '@lezer/highlight';
4
+ // The editor's surfaces come from the library's tokens, so it matches inputs and papers and
5
+ // follows a re-brand. Syntax colours are `--cm-*` properties, set per mode by CodeMirror.svelte.
6
+ const chrome = {
7
+ '&': { color: 'var(--text-color)', backgroundColor: 'var(--input-bg-color)' },
8
+ '.cm-content': { caretColor: 'var(--text-color)' },
9
+ '.cm-cursor, .cm-dropCursor': { borderLeftColor: 'var(--text-color)' },
10
+ '.cm-gutters': {
11
+ backgroundColor: 'var(--input-bg-color)',
12
+ color: 'var(--text-muted)',
13
+ borderRight: '1px solid var(--border-color)'
14
+ },
15
+ '.cm-activeLine, .cm-activeLineGutter': { backgroundColor: 'var(--hover-bg)' },
16
+ '&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection': { backgroundColor: 'rgba(var(--ui-tertiary-rgbc), 0.35)' },
17
+ '.cm-selectionMatch': { backgroundColor: 'rgba(var(--ui-tertiary-rgbc), 0.2)' },
18
+ '.cm-panels': { backgroundColor: 'var(--paper-body-bg)', color: 'var(--text-color)' },
19
+ '.cm-tooltip': {
20
+ backgroundColor: 'var(--paper-body-bg)',
21
+ color: 'var(--text-color)',
22
+ border: '1px solid var(--border-color)'
23
+ },
24
+ '.cm-placeholder': { color: 'var(--text-muted)' }
25
+ };
26
+ const lightChrome = EditorView.theme(chrome);
27
+ // `dark` also switches the `&dark` rules in base themes, such as the log level colours.
28
+ const darkChrome = EditorView.theme(chrome, { dark: true });
29
+ const highlightStyle = HighlightStyle.define([
30
+ {
31
+ tag: [t.keyword, t.controlKeyword, t.operatorKeyword, t.modifier, t.definitionKeyword],
32
+ color: 'var(--cm-keyword)'
33
+ },
34
+ { tag: [t.string, t.special(t.string), t.regexp, t.inserted], color: 'var(--cm-string)' },
35
+ { tag: [t.number, t.bool, t.null, t.atom, t.unit], color: 'var(--cm-number)' },
36
+ {
37
+ tag: [t.comment, t.lineComment, t.blockComment, t.docComment],
38
+ color: 'var(--cm-comment)',
39
+ fontStyle: 'italic'
40
+ },
41
+ { tag: [t.meta, t.processingInstruction], color: 'var(--cm-comment)' },
42
+ {
43
+ tag: [t.function(t.variableName), t.function(t.propertyName), t.macroName, t.labelName],
44
+ color: 'var(--cm-function)'
45
+ },
46
+ { tag: [t.typeName, t.className, t.namespace, t.standard(t.typeName)], color: 'var(--cm-type)' },
47
+ {
48
+ tag: [t.definition(t.variableName), t.special(t.variableName), t.local(t.variableName)],
49
+ color: 'var(--cm-variable)'
50
+ },
51
+ { tag: [t.propertyName, t.attributeName], color: 'var(--cm-property)' },
52
+ { tag: [t.tagName, t.angleBracket], color: 'var(--cm-tag)' },
53
+ { tag: [t.operator, t.derefOperator], color: 'var(--cm-operator)' },
54
+ { tag: [t.invalid, t.deleted], color: 'var(--cm-invalid)' },
55
+ { tag: t.heading, color: 'var(--cm-keyword)', fontWeight: '600' },
56
+ { tag: t.strong, fontWeight: '600' },
57
+ { tag: t.emphasis, fontStyle: 'italic' },
58
+ { tag: t.strikethrough, textDecoration: 'line-through' },
59
+ { tag: [t.link, t.url], color: 'var(--ui-link-color)', textDecoration: 'underline' }
60
+ ]);
61
+ /** The editor theme for the library's own light or dark mode */
62
+ export function libraryTheme(dark) {
63
+ return [dark ? darkChrome : lightChrome, syntaxHighlighting(highlightStyle)];
64
+ }
@@ -1,18 +1,3 @@
1
- import type { Extension } from '@codemirror/state';
2
1
  import './codeBlockEditor.css';
3
- /** Language identifiers supported by the rich code block editor */
4
- export type CodeBlockLanguageId = 'plaintext' | 'javascript' | 'typescript' | 'html' | 'css' | 'json' | 'markdown' | 'sql' | 'csharp' | 'powershell';
5
- export interface CodeBlockLanguageDef {
6
- /** Value stored in the code block's language attribute and `language-` CSS class */
7
- id: CodeBlockLanguageId;
8
- /** Human-readable name shown in the language picker */
9
- label: string;
10
- /** Alternative names recognised when parsing existing content (e.g. 'cs' for csharp) */
11
- aliases: string[];
12
- /** Factory for the CodeMirror language support (highlighting + completions) */
13
- load: () => Extension;
14
- }
15
- /** All languages available to rich code blocks */
16
- export declare const codeBlockLanguages: CodeBlockLanguageDef[];
17
- /** Look up a language definition by id or alias (case-insensitive) */
18
- export declare function resolveCodeBlockLanguage(language: string | null | undefined): CodeBlockLanguageDef | undefined;
2
+ export { codeLanguages as codeBlockLanguages, resolveCodeLanguage as resolveCodeBlockLanguage } from '../../codemirror/languages.js';
3
+ export type { CodeLanguageDef as CodeBlockLanguageDef, CodeLanguageId as CodeBlockLanguageId } from '../../codemirror/languages.js';
@@ -1,128 +1,6 @@
1
- import { javascript } from '@codemirror/lang-javascript';
2
- import { html } from '@codemirror/lang-html';
3
- import { css } from '@codemirror/lang-css';
4
- import { json } from '@codemirror/lang-json';
5
- import { markdown } from '@codemirror/lang-markdown';
6
- import { sql, MSSQL } from '@codemirror/lang-sql';
7
- import { LanguageSupport, StreamLanguage } from '@codemirror/language';
8
- import { completeAnyWord, completeFromList } from '@codemirror/autocomplete';
9
- import { csharp } from '@codemirror/legacy-modes/mode/clike';
10
- import { powerShell } from '@codemirror/legacy-modes/mode/powershell';
11
1
  // Code block styles are imported here rather than in CodeBlockEditor so that read-only
12
2
  // renderers using only resolveCodeBlockLanguage still load them. Production builds split
13
3
  // CSS per chunk, so an import that lives only in the editor would not reach those routes.
14
4
  import './codeBlockEditor.css';
15
- // C# and PowerShell have no native CodeMirror 6 packages, so they use legacy stream
16
- // parsers. Those provide highlighting only, so keyword/cmdlet lists plus word matching
17
- // stand in for the scope-aware completions the native language packages ship with.
18
- const CSHARP_KEYWORDS = ('abstract as async await base bool break byte case catch char checked class const continue ' +
19
- 'decimal default delegate do double dynamic else enum event explicit extern false finally fixed ' +
20
- 'float for foreach get global goto if implicit in init int interface internal is lock long ' +
21
- 'nameof namespace new null object operator out override params partial private protected public ' +
22
- 'readonly record ref required return sbyte sealed set short sizeof stackalloc static string ' +
23
- 'struct switch this throw true try typeof uint ulong unchecked unsafe ushort using value var ' +
24
- 'virtual void volatile when where while yield').split(' ');
25
- const CSHARP_COMMON_TYPES = ('Console Convert DateTime Dictionary Exception Guid IEnumerable IList List Math Nullable ' +
26
- 'Object StringBuilder Task TimeSpan').split(' ');
27
- const POWERSHELL_KEYWORDS = ('begin break catch class continue data do dynamicparam else elseif end enum exit filter ' +
28
- 'finally for foreach from function hidden if in param process return static switch throw trap ' +
29
- 'try until using var while workflow').split(' ');
30
- const POWERSHELL_CMDLETS = ('Add-Content Add-Member Clear-Content Clear-Variable Compare-Object ConvertFrom-Json ' +
31
- 'ConvertTo-Json Copy-Item Export-Csv ForEach-Object Format-List Format-Table Get-ChildItem ' +
32
- 'Get-Command Get-Content Get-Date Get-Help Get-Item Get-ItemProperty Get-Location Get-Member ' +
33
- 'Get-Module Get-Process Get-Random Get-Service Get-Variable Group-Object Import-Csv ' +
34
- 'Import-Module Install-Module Invoke-Command Invoke-Expression Invoke-RestMethod ' +
35
- 'Invoke-WebRequest Join-Path Measure-Object Move-Item New-Item New-Object Out-File Out-Null ' +
36
- 'Read-Host Remove-Item Remove-Variable Rename-Item Resolve-Path Restart-Service Select-Object ' +
37
- 'Select-String Set-Content Set-ExecutionPolicy Set-Item Set-Location Set-Variable Sort-Object ' +
38
- 'Split-Path Start-Process Start-Service Start-Sleep Stop-Process Stop-Service Tee-Object ' +
39
- 'Test-Connection Test-Path Wait-Process Where-Object Write-Debug Write-Error Write-Host ' +
40
- 'Write-Output Write-Verbose Write-Warning').split(' ');
41
- function toCompletions(words, type) {
42
- return words.map((label) => ({ label, type }));
43
- }
44
- function legacySupport(parser, completions) {
45
- const language = StreamLanguage.define(parser);
46
- return new LanguageSupport(language, [
47
- language.data.of({ autocomplete: completeFromList(completions) }),
48
- language.data.of({ autocomplete: completeAnyWord })
49
- ]);
50
- }
51
- /** All languages available to rich code blocks */
52
- export const codeBlockLanguages = [
53
- {
54
- id: 'plaintext',
55
- label: 'Plain text',
56
- aliases: ['text', 'plain', 'txt', 'none'],
57
- load: () => []
58
- },
59
- {
60
- id: 'javascript',
61
- label: 'JavaScript',
62
- aliases: ['js', 'jsx', 'mjs', 'node'],
63
- load: () => javascript({ jsx: true })
64
- },
65
- {
66
- id: 'typescript',
67
- label: 'TypeScript',
68
- aliases: ['ts', 'tsx'],
69
- load: () => javascript({ typescript: true, jsx: true })
70
- },
71
- {
72
- id: 'html',
73
- label: 'HTML',
74
- aliases: ['xml', 'svg', 'markup', 'xhtml'],
75
- load: () => html()
76
- },
77
- {
78
- id: 'css',
79
- label: 'CSS',
80
- aliases: ['scss', 'less'],
81
- load: () => css()
82
- },
83
- {
84
- id: 'json',
85
- label: 'JSON',
86
- aliases: ['jsonc'],
87
- load: () => json()
88
- },
89
- {
90
- id: 'markdown',
91
- label: 'Markdown',
92
- aliases: ['md'],
93
- load: () => markdown()
94
- },
95
- {
96
- id: 'sql',
97
- label: 'SQL',
98
- aliases: ['tsql', 'mssql', 'sqlserver', 'mysql', 'postgres', 'postgresql', 'sqlite', 'plsql'],
99
- // T-SQL dialect: covers standard SQL plus SQL Server extras
100
- // ([bracketed] identifiers, @variables, TOP, NVARCHAR, ...)
101
- load: () => sql({ dialect: MSSQL, upperCaseKeywords: true })
102
- },
103
- {
104
- id: 'csharp',
105
- label: 'C#',
106
- aliases: ['cs', 'c#', 'dotnet'],
107
- load: () => legacySupport(csharp, [
108
- ...toCompletions(CSHARP_KEYWORDS, 'keyword'),
109
- ...toCompletions(CSHARP_COMMON_TYPES, 'class')
110
- ])
111
- },
112
- {
113
- id: 'powershell',
114
- label: 'PowerShell',
115
- aliases: ['ps', 'ps1', 'pwsh', 'posh'],
116
- load: () => legacySupport(powerShell, [
117
- ...toCompletions(POWERSHELL_KEYWORDS, 'keyword'),
118
- ...toCompletions(POWERSHELL_CMDLETS, 'function')
119
- ])
120
- }
121
- ];
122
- /** Look up a language definition by id or alias (case-insensitive) */
123
- export function resolveCodeBlockLanguage(language) {
124
- if (!language)
125
- return undefined;
126
- const normalized = language.toLowerCase();
127
- return codeBlockLanguages.find((def) => def.id === normalized || def.aliases.includes(normalized));
128
- }
5
+ // Code blocks and the CodeMirror component share one registry; these names predate it.
6
+ export { codeLanguages as codeBlockLanguages, resolveCodeLanguage as resolveCodeBlockLanguage } from '../../codemirror/languages.js';
package/dist/index.d.ts CHANGED
@@ -125,6 +125,8 @@ export { editorButtonVariants, editorButtonSizes, editorButtonClass, parseEditor
125
125
  export type { EditorButtonVariant, EditorButtonSize, EditorButtonStyle } from './editors/tiptap/buttonLink.js';
126
126
  export { default as CodeMirror } from './editors/CodeMirror.svelte';
127
127
  export type { CodeMirrorProps } from './editors/CodeMirror.svelte';
128
+ export { codeLanguages, resolveCodeLanguage } from './editors/codemirror/languages.js';
129
+ export type { CodeLanguageDef, CodeLanguageId } from './editors/codemirror/languages.js';
128
130
  export { default as GitCard } from './cards/GitCard.svelte';
129
131
  export type { GitCardProps } from './cards/GitCard.svelte';
130
132
  export * from './icon/index.js';
package/dist/index.js CHANGED
@@ -61,6 +61,7 @@ export { default as TipTapBubble } from './editors/tiptap/TipTapBubble.svelte';
61
61
  export { ClassAttribute, defaultClassAttributeTypes, CodeBlockEditor, codeBlockLanguages, resolveCodeBlockLanguage } from './editors/tiptap/extensions/index.js';
62
62
  export { editorButtonVariants, editorButtonSizes, editorButtonClass, parseEditorButtonClass } from './editors/tiptap/buttonLink.js';
63
63
  export { default as CodeMirror } from './editors/CodeMirror.svelte';
64
+ export { codeLanguages, resolveCodeLanguage } from './editors/codemirror/languages.js';
64
65
  export { default as GitCard } from './cards/GitCard.svelte';
65
66
  export * from './icon/index.js';
66
67
  export * from './models/ComboBoxItem.js';