生态产品多个设计器现已发布候选版本

查看生态总览
Skip to content

CodeView ​

AI chat component. This page is the API reference, generated from the source code. Usage guidance and live examples are on the Chinese page.

Anatomy ​

Parts in bold are required.

data-scope="code-view": root · header · filename · lang-label · pre · code · line · line-number · line-content · token · fold-trigger · line-fold-trigger

API reference ​

Descriptions of individual props, events and slots are written in Chinese and appear on the Chinese page.

Artifacts ​

LayerValue
Custom element<xh-code-view>
Vue componentsXhCodeViewCode XhCodeViewFilename XhCodeViewFoldTrigger XhCodeViewHeader XhCodeViewLangLabel XhCodeViewPre XhCodeViewRoot
ComposableuseCodeView
State machinecodeViewMachine
Skin@xihan-ui/styles/code-view.css

Props ​

PropTypeRequired
codestringYes
langstring
filenamestring
labelledboolean
completeboolean
wrapboolean
lineNumbersboolean
startLinenumber
highlightLinesstring | readonly number[]
clampnumber
clampedboolean
blockFoldingboolean
foldedreadonly number[]
defaultFoldedreadonly number[]
onFoldedChange(details: CodeViewFoldedChangeDetails) => void
highlighterHighlighterPort
highlightWhileStreamingboolean
sizeSize
translationsPartial<CodeViewTranslations>
onClampToggle(details: CodeViewClampToggleDetails) => void

Events ​

Custom elements put the payload in detail; Vue emits an event of the same name.

EventPayload
clamp-toggleCustomEvent
folded-changeCustomEvent

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhCodeViewCodelineCodeViewLineSlotProps
XhCodeViewRootdefaultCodeViewRootSlotProps

React adapter props ​

Only the props each component declares itself: DOM attributes inherited from ComponentPropsWithRef are left out, and root props already listed in the Props table are not repeated. The Vue counterpart is the slot table above.

React componentPropTypeRequired
XhCodeViewCodechildrenSlotChildren<CodeViewLineSlotProps>
XhCodeViewFilenamefilenamestring
XhCodeViewRootchildrenSlotChildren<CodeViewRootSlotProps>

State ​

Public state is written to data-state.

PartValues
fold-trigger'closed' | 'open'
line-fold-trigger'open' | 'closed'

The following names are internal to the state machine.

States: idle

Events: PRESS.START · PRESS.END · FOLD.TOGGLE · FOLD.FOCUS

Guards: canPress

connect API ​

getXxxProps() returns the host attributes of the matching part.

MemberType
langstring
filenamestring | undefined
lineCountnumber
linesreadonly CodeLine[]
lineNumberAt(index: number) => number
lineNumbersboolean
foldableboolean
clampedboolean
setClamped(next: boolean) => void
foldRegionsreadonly CodeViewFoldRegion[]
foldedreadonly number[]
isFoldStart(index: number) => boolean
toggleFold(line: number) => void
getLineFoldTriggerProps(props: CodeViewLineProps) => T['button']
getRootProps() => T['element']
getHeaderProps() => T['element']
getFilenameProps() => T['element']
getLangLabelProps() => T['element']
getPreProps() => T['element']
getCodeProps() => T['element']
getLineProps(props: CodeViewLineProps) => T['element']
getLineNumberProps(props: CodeViewLineProps) => T['element']
getLineContentProps(props: CodeViewLineProps) => T['element']
getTokenProps(token: CodeToken) => T['element']
getFoldTriggerProps() => T['button']

Accessibility ​

Keyboard ​

Specification: W3C APG. Each row is a stable behavior id that the conformance tests cover; the conditions and effects are described on the Chinese page.

KeysBehavior
Tabcode-view.kbd.pre-focus
Enter / Spacecode-view.kbd.fold
Enter / Spacecode-view.kbd.press
Tabcode-view.kbd.block-fold-tab
Enter / Spacecode-view.kbd.block-fold-toggle
ArrowDown / ArrowUpcode-view.kbd.block-fold-move
Home / Endcode-view.kbd.block-fold-edge

ARIA ​

These attributes are produced by connect.

PartAttributeValue
lang-labelaria-hidden'true'
prerole'group'
line-numberaria-hidden'true'
fold-triggeraria-controlsid of the pre part
fold-triggeraria-expanded'false' | 'true'
fold-triggeraria-labeltranslations.expand | translations.collapse
line-fold-triggeraria-expanded'true' | 'false'
line-fold-triggeraria-labelundefined | foldLabel(lineNumberAt(region.start + 1), lineNumberA…

Style reference ​

Skin ​

@xihan-ui/styles/code-view.css is written against [data-scope="code-view"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-code-view in place of data-scope (same specificity) and sits in the xihan.components layer. Put overrides in xihan.overrides; the part selectors work as usual.

Data attributes ​

Produced by connect; valueless attributes are omitted while their condition does not hold.

PartAttributeValue
rootdata-block-folding'' (present only while the condition holds)
rootdata-clamped'' (present only while the condition holds)
rootdata-complete'' (present only while the condition holds)
rootdata-digitsString(Math.min( String(lineNumberAt(lineCount - 1)).…
rootdata-foldable'' (present only while the condition holds)
rootdata-langprop('lang')?.trim() || CODE_VIEW_FALLBACK_LANG
rootdata-line-numbers'' (present only while the condition holds)
rootdata-sizeprops.size
predata-complete'' (present only while the condition holds)
predata-wrap'' (present only while the condition holds)
codedata-langprop('lang')?.trim() || CODE_VIEW_FALLBACK_LANG
codedata-wrap'' (present only while the condition holds)
linedata-folded'' (present only while the condition holds)
linedata-highlighted'' (present only while the condition holds)
linedata-line-numberString(lineNumberAt(index))
line-numberdata-folded'' (present only while the condition holds)
line-numberdata-highlighted'' (present only while the condition holds)
line-numberdata-line-numberString(lineNumberAt(index))
line-contentdata-folded'' (present only while the condition holds)
line-contentdata-highlighted'' (present only while the condition holds)
line-contentdata-line-numberString(lineNumberAt(index))
tokendata-kindtoken.kind
fold-triggerdata-pressed'' (present only while the condition holds)
fold-triggerdata-state'closed' | 'open'
fold-triggerdata-xh-action-control''
fold-triggerdata-xh-action-display'always'
fold-triggerdata-xh-action-profile'disclosure-trigger'
fold-triggerdata-xh-action-sizeprops.size
fold-triggerdata-xh-action-variant'ghost'
line-fold-triggerdata-state'open' | 'closed'
line-fold-triggerdata-xh-action-control''
line-fold-triggerdata-xh-action-display'always'
line-fold-triggerdata-xh-action-profile'icon'
line-fold-triggerdata-xh-action-sizeprops.size
line-fold-triggerdata-xh-action-variant'ghost'

CSS variables ​

The public override slots, generated from what the standalone skin actually consumes.

VariablePartCSS propertyStateDefault from
--xh-code-view-bgrootbackgrounddefault--xh-bg-surface
--xh-code-view-borderrootborderdefault--xh-border-default
--xh-code-view-comment-fgtokencolorkind=comment--xh-fg-muted
--xh-code-view-fgrootcolordefault--xh-fg-muted
--xh-code-view-filename-fgfilenamecolordefault--xh-fg-default
--xh-code-view-fold-bg-hoverfold-triggerbackground-colordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-_action-variant-bg-hover
--xh-code-view-fold-colline-content
line-fold-trigger
root
block-size
inline-size
min-block-size
min-inline-size
padding-inline-start
block-folding
line-numbers
not([data-line-numbers])
xh-action-profile=disclosure-trigger
xh-action-profile=icon
--xh-code-view-line-height
--xh-code-view-fold-fgfold-triggercolordefault--xh-fg-muted
--xh-code-view-fold-pyfold-triggerpadding-blockxh-action-profile=disclosure-trigger--xh-space-2
--xh-code-view-folded-fgline-contentbackground-colorfolded--xh-fg-subtle
--xh-code-view-folded-gapline-contentmargin-inline-startfolded--xh-space-1
--xh-code-view-fontcode
filename
font-familydefault--xh-font-family-mono
--xh-code-view-font-sizerootfont-sizedefault--xh-_code-view-font-size
--xh-code-view-gutter-borderline-numberborder-inline-enddefault--xh-border-subtle
--xh-code-view-gutter-gapline-numberpadding-inline-enddefault--xh-space-1
--xh-code-view-header-borderfold-trigger
header
border
border-block-end
border-color
default
disabled
focus-visible
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-border-subtle
--xh-code-view-header-fgheadercolordefault--xh-fg-muted
--xh-code-view-header-font-sizefold-trigger
header
font-sizedefault--xh-text-secondary-size
--xh-code-view-header-gapheadergapdefault--xh-space-2
--xh-code-view-header-hheadermin-block-sizedefault--xh-control-h-lg
--xh-code-view-header-pxheaderpadding-inlinedefault--xh-space-4
--xh-code-view-header-pyheaderpadding-blockdefault--xh-space-2
--xh-code-view-highlight-barlinebox-shadow
outline
outline-offset
@media print
highlighted
--xh-stroke-thick
--xh-code-view-highlight-bglinebackgroundhighlighted--xh-bg-subtle
--xh-code-view-highlight-fglinebox-shadowhighlighted--xh-border-strong
--xh-code-view-icon-sizeline-fold-trigger--xh-icon-sizedefault--xh-glyph-size-sm
--xh-code-view-keyword-fgtokencolorkind=keyword--xh-syntax-keyword
--xh-code-view-keyword-weighttokenfont-weightkind=keyword--xh-font-weight-semibold
--xh-code-view-label-fglang-labelcolordefault--xh-fg-subtle
--xh-code-view-label-font-sizelang-labelfont-sizedefault--xh-text-caption-size
--xh-code-view-line-fold-trigger-fgline-fold-triggercolordefault--xh-fg-subtle
--xh-code-view-line-fold-trigger-radiusline-fold-triggerborder-radiusdefault--xh-shape-control
--xh-code-view-line-heightline
line-content
line-fold-trigger
pre
root
block-size
inline-size
line-height
min-block-size
min-inline-size
padding-inline-start
block-folding
default
line-numbers
not([data-line-numbers])
xh-action-profile=disclosure-trigger
xh-action-profile=icon
--xh-text-code-leading
--xh-code-view-number-fgline-numbercolordefault--xh-fg-subtle
--xh-code-view-number-font-sizeline-numberfont-sizedefault--xh-text-caption-size
--xh-code-view-number-token-fgtokencolorkind=number--xh-syntax-number
--xh-code-view-punctuation-fgtokencolorkind=punctuation--xh-fg-subtle
--xh-code-view-pxfold-trigger
line
line-content
line-fold-trigger
line-number
root
inset-inline-start
padding-inline
padding-inline-end
padding-inline-start
block-folding
default
line-numbers
not([data-line-numbers])
--xh-space-3
--xh-code-view-pyprepadding-blockdefault--xh-space-3
--xh-code-view-radiusrootborder-radiusdefault--xh-shape-surface
--xh-code-view-shadowrootbox-shadowdefaultnone
--xh-code-view-string-fgtokencolorkind=string--xh-syntax-string

Released under The MIT License