@stacksjs/components 0.2.854 → 0.2.857
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/dist/CodeEditor-jg4w7e15.stx +497 -0
- package/dist/ContextMenu-43g3w5tp.stx +188 -0
- package/dist/DataGrid-7rt7v865.stx +376 -0
- package/dist/GraphView-0t3t9mec.stx +320 -0
- package/dist/JsonTree-satc4010.stx +317 -0
- package/dist/PreviewFrame-erbgvzj8.stx +257 -0
- package/dist/SplitPane-7sqfdwqa.stx +159 -0
- package/dist/code-editor/editor.js +2166 -0
- package/dist/component-api/component-api.js +36 -0
- package/dist/components/CodeBlock.d.ts +12 -5
- package/dist/context-menu/context-menu.js +575 -0
- package/dist/data-grid/data-grid.js +1244 -0
- package/dist/graph-view/graph-view.js +1408 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +34 -15
- package/dist/json-tree/json-tree.js +1121 -0
- package/dist/preview-frame/preview-frame.js +356 -0
- package/dist/split-pane/split-pane.js +364 -0
- package/dist/ui/code-editor/CodeEditor.d.ts +46 -0
- package/dist/ui/code-editor/controller.d.ts +103 -0
- package/dist/ui/code-editor/core/commands.d.ts +55 -0
- package/dist/ui/code-editor/core/completion.d.ts +40 -0
- package/dist/ui/code-editor/core/editor.d.ts +69 -0
- package/dist/ui/code-editor/core/highlight.d.ts +61 -0
- package/dist/ui/code-editor/core/history.d.ts +27 -0
- package/dist/ui/code-editor/core/index.d.ts +13 -0
- package/dist/ui/code-editor/core/keymap.d.ts +38 -0
- package/dist/ui/code-editor/core/selection.d.ts +30 -0
- package/dist/ui/code-editor/core/text.d.ts +64 -0
- package/dist/ui/code-editor/editor.d.ts +15 -0
- package/dist/ui/code-editor/index.d.ts +29 -0
- package/dist/ui/code-editor/tokenizer.d.ts +18 -0
- package/dist/ui/code-editor/view.d.ts +59 -0
- package/dist/ui/context-menu/ContextMenu.d.ts +14 -0
- package/dist/ui/context-menu/context-menu.d.ts +8 -0
- package/dist/ui/context-menu/core.d.ts +74 -0
- package/dist/ui/context-menu/index.d.ts +11 -0
- package/dist/ui/context-menu/view.d.ts +36 -0
- package/dist/ui/data-grid/DataGrid.d.ts +30 -0
- package/dist/ui/data-grid/core.d.ts +141 -0
- package/dist/ui/data-grid/data-grid.d.ts +9 -0
- package/dist/ui/data-grid/index.d.ts +20 -0
- package/dist/ui/data-grid/view.d.ts +56 -0
- package/dist/ui/graph-view/GraphView.d.ts +21 -0
- package/dist/ui/graph-view/core/edges.d.ts +34 -0
- package/dist/ui/graph-view/core/force.d.ts +10 -0
- package/dist/ui/graph-view/core/graph.d.ts +83 -0
- package/dist/ui/graph-view/core/index.d.ts +5 -0
- package/dist/ui/graph-view/core/layered.d.ts +24 -0
- package/dist/ui/graph-view/core/viewport.d.ts +34 -0
- package/dist/ui/graph-view/graph-view.d.ts +9 -0
- package/dist/ui/graph-view/index.d.ts +21 -0
- package/dist/ui/graph-view/view.d.ts +51 -0
- package/dist/ui/json-tree/JsonTree.d.ts +18 -0
- package/dist/ui/json-tree/core.d.ts +108 -0
- package/dist/ui/json-tree/index.d.ts +18 -0
- package/dist/ui/json-tree/json-tree.d.ts +10 -0
- package/dist/ui/json-tree/tinker.d.ts +84 -0
- package/dist/ui/json-tree/view.d.ts +59 -0
- package/dist/ui/preview-frame/PreviewFrame.d.ts +44 -0
- package/dist/ui/preview-frame/core.d.ts +81 -0
- package/dist/ui/preview-frame/index.d.ts +19 -0
- package/dist/ui/preview-frame/preview-frame.d.ts +8 -0
- package/dist/ui/preview-frame/view.d.ts +37 -0
- package/dist/ui/split-pane/SplitPane.d.ts +18 -0
- package/dist/ui/split-pane/core.d.ts +58 -0
- package/dist/ui/split-pane/index.d.ts +15 -0
- package/dist/ui/split-pane/split-pane.d.ts +8 -0
- package/dist/ui/split-pane/view.d.ts +27 -0
- package/dist/ui/virtual-table/index.d.ts +6 -0
- package/dist/utils/component-api.d.ts +4 -0
- package/dist/utils/highlighter.d.ts +19 -1
- package/dist/utils/highlighter.js +24 -7
- package/dist/utils/syntax-theme.d.ts +44 -0
- package/package.json +44 -4
- package/src/components/CodeBlock.stx +195 -17
- package/src/index.ts +10 -0
- package/src/ui/code-editor/CodeEditor.stx +497 -0
- package/src/ui/code-editor/README.md +135 -0
- package/src/ui/code-editor/controller.ts +517 -0
- package/src/ui/code-editor/core/commands.ts +381 -0
- package/src/ui/code-editor/core/completion.ts +212 -0
- package/src/ui/code-editor/core/editor.ts +319 -0
- package/src/ui/code-editor/core/highlight.ts +203 -0
- package/src/ui/code-editor/core/history.ts +190 -0
- package/src/ui/code-editor/core/index.ts +14 -0
- package/src/ui/code-editor/core/keymap.ts +125 -0
- package/src/ui/code-editor/core/selection.ts +104 -0
- package/src/ui/code-editor/core/text.ts +252 -0
- package/src/ui/code-editor/editor.ts +16 -0
- package/src/ui/code-editor/index.ts +46 -0
- package/src/ui/code-editor/tokenizer.ts +74 -0
- package/src/ui/code-editor/view.ts +1066 -0
- package/src/ui/context-menu/ContextMenu.stx +188 -0
- package/src/ui/context-menu/README.md +117 -0
- package/src/ui/context-menu/context-menu.ts +8 -0
- package/src/ui/context-menu/core.ts +250 -0
- package/src/ui/context-menu/index.ts +16 -0
- package/src/ui/context-menu/view.ts +540 -0
- package/src/ui/data-grid/DataGrid.stx +376 -0
- package/src/ui/data-grid/README.md +204 -0
- package/src/ui/data-grid/core.ts +813 -0
- package/src/ui/data-grid/data-grid.ts +9 -0
- package/src/ui/data-grid/index.ts +34 -0
- package/src/ui/data-grid/view.ts +806 -0
- package/src/ui/graph-view/GraphView.stx +320 -0
- package/src/ui/graph-view/README.md +210 -0
- package/src/ui/graph-view/core/edges.ts +180 -0
- package/src/ui/graph-view/core/force.ts +237 -0
- package/src/ui/graph-view/core/graph.ts +277 -0
- package/src/ui/graph-view/core/index.ts +5 -0
- package/src/ui/graph-view/core/layered.ts +256 -0
- package/src/ui/graph-view/core/viewport.ts +141 -0
- package/src/ui/graph-view/graph-view.ts +9 -0
- package/src/ui/graph-view/index.ts +35 -0
- package/src/ui/graph-view/view.ts +809 -0
- package/src/ui/json-tree/JsonTree.stx +317 -0
- package/src/ui/json-tree/README.md +193 -0
- package/src/ui/json-tree/core.ts +588 -0
- package/src/ui/json-tree/index.ts +28 -0
- package/src/ui/json-tree/json-tree.ts +10 -0
- package/src/ui/json-tree/tinker.ts +349 -0
- package/src/ui/json-tree/view.ts +665 -0
- package/src/ui/preview-frame/PreviewFrame.stx +257 -0
- package/src/ui/preview-frame/README.md +107 -0
- package/src/ui/preview-frame/core.ts +195 -0
- package/src/ui/preview-frame/index.ts +31 -0
- package/src/ui/preview-frame/preview-frame.ts +8 -0
- package/src/ui/preview-frame/view.ts +336 -0
- package/src/ui/split-pane/README.md +87 -0
- package/src/ui/split-pane/SplitPane.stx +159 -0
- package/src/ui/split-pane/core.ts +200 -0
- package/src/ui/split-pane/index.ts +24 -0
- package/src/ui/split-pane/split-pane.ts +8 -0
- package/src/ui/split-pane/view.ts +305 -0
- package/src/ui/virtual-table/index.ts +6 -0
- package/src/utils/component-api.ts +72 -0
- package/src/utils/highlighter.ts +121 -218
- package/src/utils/syntax-theme.ts +144 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export type { CodeEditorConfig, CodeEditorHooks, CompletionRequest, PopupItem, PopupState, RunDetail, RunSelectionDetail, SelectionDetail } from './controller'
|
|
2
|
+
export type { CompletionItem, Keymap, Position } from './core'
|
|
3
|
+
export type { CaretAnchor, DiagnosticSeverity, EditorDiagnostic, EditorViewOptions, EditorWidget } from './view'
|
|
4
|
+
export { default as CodeEditor } from './CodeEditor.stx'
|
|
5
|
+
|
|
6
|
+
export interface CodeEditorProps {
|
|
7
|
+
/** The text. Two-way with `v-model:value`. */
|
|
8
|
+
value?: string
|
|
9
|
+
/** A language id the highlighter knows. Default `typescript`. */
|
|
10
|
+
language?: string
|
|
11
|
+
readonly?: boolean
|
|
12
|
+
disabled?: boolean
|
|
13
|
+
/** Show the gutter. Default true. */
|
|
14
|
+
lineNumbers?: boolean
|
|
15
|
+
/** Colour the code. Default true. */
|
|
16
|
+
highlight?: boolean
|
|
17
|
+
/** Columns per indent level. Default 2. */
|
|
18
|
+
tabSize?: number
|
|
19
|
+
/** Indent with spaces rather than tab characters. Default true. */
|
|
20
|
+
insertSpaces?: boolean
|
|
21
|
+
/** Offer completions while typing, not only on Ctrl-Space. Default true. */
|
|
22
|
+
autoComplete?: boolean
|
|
23
|
+
/** Names always on offer in the completion popup. */
|
|
24
|
+
completions?: import('./core').CompletionItem[]
|
|
25
|
+
/** Results, notes and errors shown beside lines. Lines are zero-based. */
|
|
26
|
+
widgets?: import('./view').EditorWidget[]
|
|
27
|
+
/** Ranges drawn with a squiggle. */
|
|
28
|
+
diagnostics?: import('./view').EditorDiagnostic[]
|
|
29
|
+
/** Show each diagnostic's message after its line. Default true. */
|
|
30
|
+
inlineDiagnostics?: boolean
|
|
31
|
+
/** A suggestion shown at the caret. Tab takes it, Escape lets it go. */
|
|
32
|
+
ghostText?: string
|
|
33
|
+
/** Bindings laid over the defaults, such as `{ 'Mod-s': 'run' }`. */
|
|
34
|
+
keymap?: import('./core').Keymap
|
|
35
|
+
/** Pin the code colours to `light` or `dark`. Follows the page otherwise. */
|
|
36
|
+
theme?: 'light' | 'dark'
|
|
37
|
+
/** A CSS length. Default `20rem`. */
|
|
38
|
+
height?: string
|
|
39
|
+
placeholder?: string
|
|
40
|
+
/** The field's accessible name. Default `Code editor`. */
|
|
41
|
+
label?: string
|
|
42
|
+
autofocus?: boolean
|
|
43
|
+
name?: string
|
|
44
|
+
id?: string
|
|
45
|
+
className?: string
|
|
46
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The highlighter, as the line tokenizer the editor core asks for.
|
|
3
|
+
*
|
|
4
|
+
* The core takes a tokenizer rather than importing one, so this is the only
|
|
5
|
+
* file in the editor that knows `ts-syntax-highlighter` exists. It reaches it
|
|
6
|
+
* through the package's browser entry: the root entry loads a config file from
|
|
7
|
+
* disk, which a page cannot do.
|
|
8
|
+
*/
|
|
9
|
+
import type { TokenizerState } from 'ts-syntax-highlighter/browser'
|
|
10
|
+
import type { HighlightToken, LineTokenizer } from './core/highlight'
|
|
11
|
+
import { resolveGrammar, tokenClass, Tokenizer } from 'ts-syntax-highlighter/browser'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A line longer than this is shown plain.
|
|
15
|
+
*
|
|
16
|
+
* A minified bundle is one line of a hundred thousand characters. Nobody reads
|
|
17
|
+
* it, some grammars are quadratic in it, and it would be re-tokenized whole on
|
|
18
|
+
* every key typed into it.
|
|
19
|
+
*/
|
|
20
|
+
export const MAX_TOKENIZED_LINE_LENGTH = 10_000
|
|
21
|
+
|
|
22
|
+
/** A string equal exactly when two tokenizer states are. */
|
|
23
|
+
export function tokenizerStateKey(state: TokenizerState): string {
|
|
24
|
+
const { frames } = state
|
|
25
|
+
// Nearly every line of nearly every file ends where it began: at the root.
|
|
26
|
+
if (frames.length === 1 && frames[0]!.pattern === null && !frames[0]!.raw)
|
|
27
|
+
return ''
|
|
28
|
+
|
|
29
|
+
let key = ''
|
|
30
|
+
for (const frame of frames)
|
|
31
|
+
key += `${frame.pattern ?? ''}\u0001${frame.raw ? frame.end ?? '' : ''}\u0001${frame.scopes.join(' ')}\u0002`
|
|
32
|
+
|
|
33
|
+
return key
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A line tokenizer for a language, or null when the highlighter has no grammar
|
|
38
|
+
* for it. The editor shows plain text then, which is the right floor: the code
|
|
39
|
+
* is the content and the colour is decoration.
|
|
40
|
+
*/
|
|
41
|
+
export async function createLanguageTokenizer(language: string): Promise<LineTokenizer<TokenizerState> | null> {
|
|
42
|
+
const grammar = await resolveGrammar(language)
|
|
43
|
+
if (!grammar)
|
|
44
|
+
return null
|
|
45
|
+
|
|
46
|
+
const tokenizer = new Tokenizer(grammar)
|
|
47
|
+
const lines: string[] = ['']
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
initialState: () => tokenizer.initialState(),
|
|
51
|
+
stateKey: tokenizerStateKey,
|
|
52
|
+
tokenizeLine(text, state) {
|
|
53
|
+
if (text.length > MAX_TOKENIZED_LINE_LENGTH)
|
|
54
|
+
return { tokens: [{ type: '', content: text }], endState: state }
|
|
55
|
+
|
|
56
|
+
lines[0] = text
|
|
57
|
+
const result = tokenizer.tokenizeLinesFrom(lines, state, 1)
|
|
58
|
+
const tokens: HighlightToken[] = []
|
|
59
|
+
let last: HighlightToken | undefined
|
|
60
|
+
|
|
61
|
+
for (const token of result.lines[0]!.tokens) {
|
|
62
|
+
const type = tokenClass(token.type)
|
|
63
|
+
// Neighbours of one colour are one run: half the elements to create,
|
|
64
|
+
// and nothing a reader could tell apart.
|
|
65
|
+
if (last && last.type === type)
|
|
66
|
+
last.content += token.content
|
|
67
|
+
else
|
|
68
|
+
tokens.push(last = { type, content: token.content })
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return { tokens, endState: result.endState }
|
|
72
|
+
},
|
|
73
|
+
}
|
|
74
|
+
}
|