本文へスキップ

CodeBlock

Tree-sitter カラーリングと論理行の仮想化を備えた、選択可能でキャレットのないコード表示です。

既定では言語文法を含みません。Rust はリンク済み文法を登録でき、Go / TypeScript は LoadLanguagePack / loadLanguagePack で選択した Tree-sitter Wasm 文法とクエリをまとめた単一の移植可能なパックを読み込めます。

既定では見た目のスタイルを持ちません。文字と行番号の色は継承され、背景、枠線、角丸、余白、構文・差分の配色は追加されません。外観はアプリ側で明示的に指定します。

#インポート

bun add @quickgui/extension-editor
import { 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(props: CodeBlockProps): NativeNode
accessibilityLabelstring—

Declares accessibilityLabel (optional). Reactive JSX expressions update this property in place.

string
ソースを見る
styleStyleProp—

Layout, typography, paint, and interaction-state styles. Arrays merge left to right.

StyleProp
ソースを見る
disabledboolean—

Declares disabled (optional). Reactive JSX expressions update this property in place.

boolean
ソースを見る
invalidboolean—

Expose web-style invalid state; the `style.invalid` variant paints while it is set.

boolean
ソースを見る
selectedboolean—

Expose web-style selected state; the `style.selected` variant paints while it is set.

boolean
ソースを見る
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—

Declares role (optional). Reactive JSX expressions update this property in place.

string
ソースを見る
tabIndexnumber—

Declares tabIndex (optional). Reactive JSX expressions update this property in place.

number
ソースを見る
focusOnPointerboolean—

Keep keyboard focus where it is when this element is activated with a pointer.

boolean
ソースを見る
overlayboolean—

Paint this subtree in the viewport overlay plane above embedded native views.

boolean
ソースを見る
focusTrapboolean—

Contain keyboard focus within this subtree while it is the topmost trap.

boolean
ソースを見る
restorePreviousFocusboolean—

Restore the previously focused mounted control when this surface unmounts.

boolean
ソースを見る
autoFocusboolean—

Prefer this control when its containing focus trap takes focus.

boolean
ソースを見る
aria-modalboolean—

Expose modal semantics to assistive technology.

boolean
ソースを見る
ariaModalboolean—

Declares ariaModal (optional). Reactive JSX expressions update this property in place.

boolean
ソースを見る
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—

Delayed, pointer-passive native tooltip text shown while this element is hovered.

string
ソースを見る
tooltipPlacementPopoverPlacement—

Declares tooltipPlacement (optional). Reactive JSX expressions update this property in place.

PopoverPlacement
ソースを見る
tooltipDelaynumber—

Hover delay in milliseconds, clamped by the Rust core to at most ten seconds.

number
ソースを見る
tooltipGapnumber—

Declares tooltipGap (optional). Reactive JSX expressions update this property in place.

number
ソースを見る
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—

Declares aria-label (optional). Reactive JSX expressions update this property in place.

string
ソースを見る
ariaLabelstring—

Declares ariaLabel (optional). Reactive JSX expressions update this property in place.

string
ソースを見る
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—

Focused key press. Declare a `tabIndex` to make an ordinary container focusable.

EventHandler
ソースを見る
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—

Second press of one exact native multi-click sequence.

EventHandler
ソースを見る
onWheelEventHandler—

Declares onWheel (optional). Reactive JSX expressions update this property in place.

EventHandler
ソースを見る
onContextMenuEventHandler—

Secondary-button press. Use `ContextMenu` for a declared native menu.

EventHandler
ソースを見る
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—

Declares onBlur (optional). Reactive JSX expressions update this property in place.

EventHandler
ソースを見る
keymapKeymap—

Bounded accelerator table resolved by the core while this element is focused.

Keymap
ソースを見る
onActionEventHandler—

Typed binding id dispatched by `keymap`.

EventHandler
ソースを見る
draggableboolean | DragSource—

Declared drag payload promoted when this element starts a drag.

boolean | 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—

Declares onDrop (optional). Reactive JSX expressions update this property in place.

EventHandler
ソースを見る
onFilesDroppedEventHandler—

Declares onFilesDropped (optional). Reactive JSX expressions update this property in place.

EventHandler
ソースを見る
valuestring—

Controlled UTF-8 source displayed without an editor caret.

string
ソースを見る
languageEditorLanguage—

Declares language (optional). Reactive JSX expressions update this property in place.

EditorLanguage
ソースを見る
lineNumbersboolean—

Declares lineNumbers (optional). Reactive JSX expressions update this property in place.

boolean
ソースを見る
wrapboolean—

Declares wrap (optional). Reactive JSX expressions update this property in place.

boolean
ソースを見る
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
ソースを見る