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

查看生态总览
Skip to content

DiffView ​

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="diff-view": root · header · summary · viewport · body · row · line-number · line-content · change-label · inline-change · token · gap · gap-cell · gap-trigger · empty · truncation · comment-trigger · comment-thread

API reference ​

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

Artifacts ​

LayerValue
Custom element<xh-diff-view>
Vue componentsXhDiffViewBody XhDiffViewEmpty XhDiffViewHeader XhDiffViewRoot XhDiffViewSummary XhDiffViewTruncation XhDiffViewViewport
ComposableuseDiffView
State machinediffViewMachine
Skin@xihan-ui/styles/diff-view.css

Props ​

PropTypeRequired
modelDiffModel
viewDiffViewMode
contextLinesnumber
expandedValuereadonly string[]
defaultExpandedValuereadonly string[]
wrapboolean
labelledboolean
commentableboolean
commentLinesreadonly DiffViewLineRef[]
sizeSize
translationsPartial<DiffViewTranslations>
onExpandedValueChange(details: DiffViewExpandedValueChangeDetails) => void
onCommentRequest(details: DiffViewCommentRequestDetails) => void

DiffViewLineRef ​

Elements of commentLines.

FieldTypeRequired
sideDiffSideYes
linenumberYes

Events ​

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

EventPayload
comment-mountCustomEvent
expanded-value-changeDiffViewExpandedValueChangeDetails
comment-requestDiffViewCommentRequestDetails

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhDiffViewBodydefault—
XhDiffViewBodycommentDiffViewCommentRequestDetails
XhDiffViewRootdefaultDiffViewRootSlotProps
XhDiffViewSummarydefault{ count: number }
XhDiffViewTruncationdefault{ count: number }

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
XhDiffViewBodyrenderComment(details: DiffViewCommentRequestDetails) => ReactNode
XhDiffViewRootchildrenSlotChildren<DiffViewRootSlotProps>
XhDiffViewSummarychangeExtract<DiffChange, 'added' | 'removed'>Yes
XhDiffViewSummarychildrenSlotChildren<{ count: number }>
XhDiffViewTruncationchildrenSlotChildren<{ count: number }>

State ​

The following names are internal to the state machine.

States: idle

Events: GAP.EXPAND · GAP.COLLAPSE · CONTROLLED.EXPANDED.SET · PRESS.START · PRESS.END · COMMENT.FOCUS

Guards: isExpandedControlled

connect API ​

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

MemberType
viewDiffViewMode
rowsreadonly DiffViewRow[]
expandedValuestring[]
stats{ added: number, removed: number }
truncatedboolean
truncatedLinesnumber
truncationTextstring
isEmptyboolean
setExpandedValue(next: string[]) => void
toggleGap(id: string) => void
commentableboolean
commentRefAt(props: DiffViewCellProps) => DiffViewLineRef | undefined
hasComment(props: DiffViewCellProps) => boolean
getCommentTriggerProps(props: DiffViewCellProps) => T['button']
getCommentThreadProps(props: DiffViewCellProps) => T['element']
getRootProps() => T['element']
getHeaderProps() => T['element']
getSummaryProps(props: { change: DiffChange }) => T['element']
getViewportProps() => T['element']
getBodyProps() => T['element']
getRowProps(props: DiffViewRowProps) => T['element']
getLineNumberProps(props: DiffViewCellProps) => T['element']
getLineContentProps(props: DiffViewCellProps) => T['element']
getChangeLabelProps(props: { change: DiffChange }) => T['element']
getInlineChangeProps(props: DiffViewInlineChangeProps) => T['element']
getTokenProps(token: CodeToken) => T['element']
getGapProps(props: DiffViewGapProps) => T['element']
getGapCellProps() => T['element']
getGapTriggerProps(props: DiffViewGapProps) => T['button']
getEmptyProps() => T['element']
getTruncationProps() => T['element']
changeLabel(change: DiffChange) => string
cellText(props: DiffViewCellProps) => string | undefined
cellNumber(props: DiffViewCellProps) => number | undefined
cellTokens(props: DiffViewCellProps) => readonly CodeToken[]
cellSegments(props: DiffViewCellProps) => readonly DiffViewSegment[]

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
Tabdiff-view.kbd.viewport-focus
Enter / Spacediff-view.kbd.expand-gap
Enter / Spacediff-view.kbd.press
Tabdiff-view.kbd.comment-tab
Enter / Spacediff-view.kbd.comment-request
ArrowDown / ArrowUpdiff-view.kbd.comment-move
Home / Enddiff-view.kbd.comment-edge

ARIA ​

These attributes are produced by connect.

PartAttributeValue
bodyaria-colcount2 | 1
bodyaria-labelundefined | model.newPath
bodyaria-labelledbyid of the header part | undefined
bodyaria-rowcountrows.length
bodyrole'table'
rowaria-rowindexrowIndex
rowrole'row'
line-numberaria-hidden'true'
line-contentaria-colindex2 | 1
line-contentrole'cell'
gaprole'row'
gap-cellaria-colindex1
gap-cellrole'cell'
gap-triggeraria-expanded'true' | 'false'
gap-triggeraria-labelexpandGapLabel(hiddenCountOf(gapId))
comment-triggeraria-labelundefined | commentLabel(ref.line, ref.side)

Style reference ​

Skin ​

@xihan-ui/styles/diff-view.css is written against [data-scope="diff-view"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-diff-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-commentable'' (present only while the condition holds)
rootdata-sizeprops.size
rootdata-truncated'' (present only while the condition holds)
rootdata-viewprops.view
rootdata-wrap'' (present only while the condition holds)
summarydata-changechange
rowdata-changelineAt(rowIndex)?.change
rowdata-revealed'' (present only while the condition holds)
line-numberdata-changelineAt(rowIndex)?.change
line-numberdata-line-numbercellNumber({ rowIndex, side })?.toString()
line-numberdata-sideside
line-contentdata-changelineAt(rowIndex)?.change
line-contentdata-empty'' (present only while the condition holds)
line-contentdata-sideside
change-labeldata-changechange
inline-changedata-changelineAt(rowIndex)?.change | undefined
tokendata-kindtoken.kind
gapdata-expanded'' (present only while the condition holds)
gapdata-valuehunkIndex:0
gap-triggerdata-pressed'' (present only while the condition holds)
gap-triggerdata-valuehunkIndex:0
gap-triggerdata-xh-action-control''
gap-triggerdata-xh-action-display'always'
gap-triggerdata-xh-action-profile'disclosure-trigger'
gap-triggerdata-xh-action-sizeprops.size
gap-triggerdata-xh-action-variant'ghost'
comment-triggerdata-sideref?.side
comment-triggerdata-xh-action-control''
comment-triggerdata-xh-action-display'always'
comment-triggerdata-xh-action-profile'icon'
comment-triggerdata-xh-action-sizeprops.size
comment-triggerdata-xh-action-variant'ghost'
comment-threaddata-sideref?.side

CSS variables ​

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

VariablePartCSS propertyStateDefault from
--xh-diff-view-added-bgrowbackgroundchange=added--xh-diff-added-bg
--xh-diff-view-added-fginline-change
line-content
line-number
row
summary
background
box-shadow
color
change=added--xh-diff-added-fg
--xh-diff-view-bgrootbackgrounddefault--xh-bg-surface
--xh-diff-view-borderrootborderdefault--xh-border-default
--xh-diff-view-change-barrowbackground
box-shadow
change=added
change=removed
--xh-stroke-thick
--xh-diff-view-comment-colcomment-trigger
line-content
root
block-size
inline-size
min-block-size
min-inline-size
padding-inline-start
commentable
xh-action-profile=disclosure-trigger
xh-action-profile=icon
--xh-diff-view-line-height
--xh-diff-view-comment-fgtokencolorkind=comment--xh-fg-muted
--xh-diff-view-comment-thread-bgcomment-threadbackgrounddefault--xh-bg-surface
--xh-diff-view-comment-thread-bordercomment-threadborderdefault--xh-border-default
--xh-diff-view-comment-thread-fgcomment-threadcolordefault--xh-fg-default
--xh-diff-view-comment-thread-max-wcomment-threadmax-inline-sizedefault--xh-measure-prose
--xh-diff-view-comment-thread-mycomment-threadmargin-blockdefault--xh-space-2
--xh-diff-view-comment-thread-pcomment-threadpaddingdefault--xh-space-3
--xh-diff-view-comment-thread-radiuscomment-threadborder-radiusdefault--xh-shape-surface
--xh-diff-view-comment-trigger-fgcomment-triggercolordefault--xh-fg-muted
--xh-diff-view-comment-trigger-icon-sizecomment-trigger--xh-icon-sizedefault--xh-glyph-size-sm
--xh-diff-view-comment-trigger-radiuscomment-triggerborder-radiusdefault--xh-shape-control
--xh-diff-view-dividerheader
line-number
root
border-block-end
border-inline-end
border-inline-start
@media (min-width: 1024px)
default
side=new
view=split
--xh-border-subtle
--xh-diff-view-empty-bgline-contentbackgroundempty--xh-bg-subtle
--xh-diff-view-empty-fgemptycolordefault--xh-fg-muted
--xh-diff-view-fontbody
header
font-familydefault--xh-font-family-mono
--xh-diff-view-font-sizebody
gap-trigger
font-sizedefault--xh-_diff-view-font-size
--xh-diff-view-gap-bggapbackgrounddefault--xh-bg-subtle
--xh-diff-view-gap-bg-hovergap-triggerbackground-colordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-_action-variant-bg-hover
--xh-diff-view-gap-fggap-triggercolordefault--xh-fg-muted
--xh-diff-view-gutterline-numberinline-sizedefault4ch
--xh-diff-view-header-fgheadercolordefault--xh-fg-muted
--xh-diff-view-header-font-sizeempty
header
truncation
font-sizedefault--xh-text-secondary-size
--xh-diff-view-header-gapheadergapdefault--xh-space-2
--xh-diff-view-icon-sizeroot--xh-icon-sizedefault
size=lg
size=sm
--xh-glyph-size-lg
--xh-glyph-size-md
--xh-glyph-size-sm
--xh-diff-view-inline-change-radiusinline-changeborder-radiuschange--xh-shape-inset
--xh-diff-view-keyword-fgtokencolorkind=keyword--xh-syntax-keyword
--xh-diff-view-keyword-weighttokenfont-weightkind=keyword--xh-font-weight-semibold
--xh-diff-view-line-heightbody
comment-trigger
gap
gap-trigger
line-content
root
row
block-size
inline-size
line-height
min-block-size
min-inline-size
padding-inline-start
commentable
default
xh-action-profile=disclosure-trigger
xh-action-profile=icon
--xh-text-code-leading
--xh-diff-view-max-hviewportmax-block-sizedefault--xh-viewport-max-h
--xh-diff-view-number-fgline-numbercolordefault--xh-fg-subtle
--xh-diff-view-number-token-fgtokencolorkind=number--xh-syntax-number
--xh-diff-view-punctuation-fgtokencolorkind=punctuation--xh-fg-subtle
--xh-diff-view-pxempty
gap-trigger
header
line-content
line-number
truncation
padding-inline
padding-inline-end
default--xh-_diff-view-px
--xh-diff-view-pyempty
header
truncation
padding-blockdefault--xh-_diff-view-py
--xh-diff-view-radiusrootborder-radiusdefault--xh-shape-surface
--xh-diff-view-removed-bgrowbackgroundchange=removed--xh-diff-removed-bg
--xh-diff-view-removed-fginline-change
line-content
line-number
row
summary
background
color
change=removed--xh-diff-removed-fg
--xh-diff-view-shadowrootbox-shadowdefaultnone
--xh-diff-view-string-fgtokencolorkind=string--xh-syntax-string
--xh-diff-view-truncation-bgtruncationbackgrounddefault--xh-fg-warning
--xh-diff-view-truncation-bordertruncationborder-block-startdefault--xh-border-subtle
--xh-diff-view-truncation-fgtruncationcolordefault--xh-fg-warning
--xh-diff-view-truncation-gaptruncationgapdefault--xh-space-2

Released under The MIT License