CodeBlock
可选择、无插入光标的代码视图,支持 Tree-sitter 着色和逻辑行虚拟化。
默认不包含任何语言语法。Rust 可注册静态链接的语法;Go 和 TypeScript 可通过 LoadLanguagePack / loadLanguagePack 加载单个跨平台包,其中包含所选 Tree-sitter Wasm 语法与查询。
组件默认不带视觉样式:文本和行号继承颜色,不添加背景、边框、圆角、内边距或语法/差异配色。外观由应用显式提供样式与颜色。
#导入
bun add @quickgui/extension-editorimport { CodeBlock } from "@quickgui/extension-editor";// quickgui.config.ts
extensions: ["@quickgui/extension-editor"]#用法
<CodeBlock
value={"export function answer(): number { return 42; }\n"}
language="typescript"
lineNumbers
wrap={false}
style={{ width: "100%", height: 280 }}
/>#语法高亮
language 选择已注册的 Tree-sitter 语法和高亮查询。捕获结果通过 syntaxTheme 映射为只影响前景色的区间,因此高亮不会改变布局。源码或语言变化时由 Rust 核心解析;滚动只挂载逻辑行并创建预先计算的区间。解析最多处理 2 MiB,超过 32 KiB 的单行保持普通颜色,捕获数量也有上限。
#API 参考
展开条目查看说明和完整签名。短横线表示声明中未记录默认值。
CodeBlock
查看源码CodeBlock(props: CodeBlockProps): NativeNodeaccessibilityLabelstring—
Declares accessibilityLabel (optional). Reactive JSX expressions update this property in place.
string查看源码styleStyleProp—
disabledboolean—
invalidboolean—
selectedboolean—
groupboolean | string—
Makes this element the group its descendants' `groupHover` and `groupActive` styles follow, like Tailwind's `group`: `true` opens an unnamed group, and a string names it so a descendant can follow it past a nearer group with `groupHover: { group: "name" }`.
boolean | string查看源码rolestring—
tabIndexnumber—
focusOnPointerboolean—
overlayboolean—
focusTrapboolean—
restorePreviousFocusboolean—
autoFocusboolean—
aria-modalboolean—
ariaModalboolean—
dismissOnEscapeboolean—
Declares dismissOnEscape (optional). Reactive JSX expressions update this property in place.
boolean查看源码dismissOnPointerOutsideboolean—
Declares dismissOnPointerOutside (optional). Reactive JSX expressions update this property in place.
boolean查看源码tooltipstring—
tooltipPlacementPopoverPlacement—
Declares tooltipPlacement (optional). Reactive JSX expressions update this property in place.
PopoverPlacement查看源码tooltipDelaynumber—
tooltipGapnumber—
tooltipViewportMarginnumber—
Declares tooltipViewportMargin (optional). Reactive JSX expressions update this property in place.
number查看源码hitSlopnumber | string—
Declares hitSlop (optional). Reactive JSX expressions update this property in place.
number | string查看源码hitSlopTopnumber | string—
Declares hitSlopTop (optional). Reactive JSX expressions update this property in place.
number | string查看源码hitSlopRightnumber | string—
Declares hitSlopRight (optional). Reactive JSX expressions update this property in place.
number | string查看源码hitSlopBottomnumber | string—
Declares hitSlopBottom (optional). Reactive JSX expressions update this property in place.
number | string查看源码hitSlopLeftnumber | string—
Declares hitSlopLeft (optional). Reactive JSX expressions update this property in place.
number | string查看源码aria-labelstring—
ariaLabelstring—
ref((node: NativeNode) => void) | NativeNode—
Declares ref (optional). Reactive JSX expressions update this property in place.
((node: NativeNode) => void) | NativeNode查看源码onClickEventHandler—
Declares onClick (optional). Reactive JSX expressions update this property in place.
EventHandler查看源码onMouseEnterEventHandler—
Declares onMouseEnter (optional). Reactive JSX expressions update this property in place.
EventHandler查看源码onMouseLeaveEventHandler—
Declares onMouseLeave (optional). Reactive JSX expressions update this property in place.
EventHandler查看源码onPointerEnterEventHandler—
Declares onPointerEnter (optional). Reactive JSX expressions update this property in place.
EventHandler查看源码onPointerLeaveEventHandler—
Declares onPointerLeave (optional). Reactive JSX expressions update this property in place.
EventHandler查看源码onPointerEventHandler—
Captured pointer stream from press through release/cancel, including outside the element.
EventHandler查看源码onInputEventHandler—
Declares onInput (optional). Reactive JSX expressions update this property in place.
EventHandler查看源码onChangeEventHandler—
Declares onChange (optional). Reactive JSX expressions update this property in place.
EventHandler查看源码onSubmitEventHandler—
Declares onSubmit (optional). Reactive JSX expressions update this property in place.
EventHandler查看源码onDismissEventHandler—
Declares onDismiss (optional). Reactive JSX expressions update this property in place.
EventHandler查看源码onKeyDownEventHandler—
onKeyUpEventHandler—
Declares onKeyUp (optional). Reactive JSX expressions update this property in place.
EventHandler查看源码onMouseDownEventHandler—
Declares onMouseDown (optional). Reactive JSX expressions update this property in place.
EventHandler查看源码onMouseUpEventHandler—
Declares onMouseUp (optional). Reactive JSX expressions update this property in place.
EventHandler查看源码onMouseMoveEventHandler—
Declares onMouseMove (optional). Reactive JSX expressions update this property in place.
EventHandler查看源码onDoubleClickEventHandler—
onWheelEventHandler—
Declares onWheel (optional). Reactive JSX expressions update this property in place.
EventHandler查看源码onContextMenuEventHandler—
onPinchEventHandler—
Declares onPinch (optional). Reactive JSX expressions update this property in place.
EventHandler查看源码onRotateEventHandler—
Declares onRotate (optional). Reactive JSX expressions update this property in place.
EventHandler查看源码onSmartMagnifyEventHandler—
Declares onSmartMagnify (optional). Reactive JSX expressions update this property in place.
EventHandler查看源码onPressureEventHandler—
Declares onPressure (optional). Reactive JSX expressions update this property in place.
EventHandler查看源码onFocusEventHandler—
Declares onFocus (optional). Reactive JSX expressions update this property in place.
EventHandler查看源码onBlurEventHandler—
keymapKeymap—
onActionEventHandler—
draggableboolean | DragSource—
onDragStartEventHandler—
Declares onDragStart (optional). Reactive JSX expressions update this property in place.
EventHandler查看源码onDragEndEventHandler—
Declares onDragEnd (optional). Reactive JSX expressions update this property in place.
EventHandler查看源码dropKindsDropKind | readonly DropKind[]—
Payload kinds this element accepts, declared ahead of the native drag.
DropKind | readonly DropKind[]查看源码onDropEventHandler—
onFilesDroppedEventHandler—
Declares onFilesDropped (optional). Reactive JSX expressions update this property in place.
EventHandler查看源码valuestring—
languageEditorLanguage—
Declares language (optional). Reactive JSX expressions update this property in place.
EditorLanguage查看源码lineNumbersboolean—
wrapboolean—
contentPaddingContentPadding—
Declares contentPadding (optional). Reactive JSX expressions update this property in place.
ContentPadding查看源码gutterPaddingGutterPadding—
Declares gutterPadding (optional). Reactive JSX expressions update this property in place.
GutterPadding查看源码gutterBackgroundColorValue—
Declares gutterBackground (optional). Reactive JSX expressions update this property in place.
ColorValue查看源码gutterColorColorValue—
Declares gutterColor (optional). Reactive JSX expressions update this property in place.
ColorValue查看源码syntaxThemeSyntaxTheme—
Declares syntaxTheme (optional). Reactive JSX expressions update this property in place.
SyntaxTheme查看源码