跳到正文

Editor

保留式原生代码编辑器,支持语法着色、行号、缩进和双轴滚动。

默认不包含任何语言语法。Rust 可注册静态链接的语法;Go 和 TypeScript 可通过 LoadLanguagePack / loadLanguagePack 加载单个跨平台包,其中包含所选 Tree-sitter Wasm 语法与查询。

组件默认不带视觉样式:文本和行号继承颜色,不添加背景、边框、圆角、内边距或语法/差异配色。外观由应用显式提供样式与颜色。

#导入

bun add @quickgui/extension-editor
import { createSignal } from "solid-js";
import { Editor, loadLanguagePack } from "@quickgui/extension-editor";
// quickgui.config.ts
extensions: ["@quickgui/extension-editor"]

#用法

const [source, setSource] = createSignal("export function answer() { return 42; }\n");

<Editor
  value={source()}
  language="typescript"
  lineNumbers
  tabSize={2}
  onInput={(event) => setSource(event.value ?? "")}
  style={{ width: "100%", height: 360 }}
/>;

#语法高亮

language 选择已注册的 Tree-sitter 语法和高亮查询。查询捕获结果通过 syntaxTheme 映射为八种只影响前景色的绘制类别,因此颜色不会改变文本尺寸。源码或语言变化时重新解析受限文档;调色板变化只重新映射已有捕获,滚动不会执行语法分析。解析最多处理 2 MiB,超过 32 KiB 的单行保持普通颜色,捕获数量也有上限,且不需要语言服务器。

#API 参考

展开条目查看说明和完整签名。短横线表示声明中未记录默认值。

Editor(props: EditorProps): 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 document.

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
查看源码
tabSizenumber—

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

number
查看源码
insertSpacesboolean—

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

boolean
查看源码
autoIndentboolean—

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

boolean
查看源码
readOnlyboolean—

Declares readOnly (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
查看源码
activeLineBackgroundColorValue—

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

ColorValue
查看源码
activeLineNumberColorColorValue—

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

ColorValue
查看源码
syntaxThemeSyntaxTheme—

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

SyntaxTheme
查看源码