BlockSuite API Documentation / @blocksuite/virgo / VEditor
Class: VEditor<TextAttributes> ​
Contents ​
- Type parameters
- Constructors
- Properties
- _attributeService
- _deltaService
- _disposables
- _eventService
- _hooksService
- _isReadonly
- _mounted
- _rangeService
- _rootElement
- _yText
- focusEnd
- focusIndex
- focusStart
- getDeltaByRangeIndex
- getDeltasByVRange
- getFormat
- getLine
- getNativeSelection
- getTextPoint
- getVRange
- getVRangeFromElement
- isEmbed
- isFirstLine
- isLastLine
- isNormalizedDeltaSelected
- isVRangeValid
- mapDeltasInVRange
- resetMarks
- selectAll
- setAttributeRenderer
- setAttributeSchema
- setMarks
- setVRange
- slots
- syncVRange
- toDomRange
- toVRange
- vRangeProvider
- getTextNodesFromElement
- nativePointToTextPoint
- textPointToDomPoint
- Accessors
- Methods
Type parameters ​
• TextAttributes extends BaseTextAttributes
= BaseTextAttributes
Constructors ​
new VEditor(yText, ops) ​
new VEditor<
TextAttributes
>(yText
,ops
):VEditor
<TextAttributes
>
Parameters ​
• yText: Text
• ops: Object
= {}
• ops.hooks?: Object
• ops.hooks.beforeinput?: (props
) => null
| VBeforeinputHookCtx
<TextAttributes
>
• ops.hooks.compositionEnd?: (props
) => null
| VCompositionEndHookCtx
<TextAttributes
>
• ops.isEmbed?: (delta
) => boolean
• ops.vRangeProvider?: VRangeProvider
Returns ​
VEditor
<TextAttributes
>
Source ​
packages/virgo/src/virgo.ts:158
Properties ​
_attributeService ​
private
_attributeService:VirgoAttributeService
<TextAttributes
>
Source ​
packages/virgo/src/virgo.ts:56
_deltaService ​
private
_deltaService:VirgoDeltaService
<TextAttributes
>
Source ​
packages/virgo/src/virgo.ts:59
_disposables ​
private
_disposables:DisposableGroup
Source ​
packages/virgo/src/virgo.ts:41
_eventService ​
private
_eventService:VirgoEventService
<TextAttributes
>
Source ​
packages/virgo/src/virgo.ts:50
_hooksService ​
private
_hooksService:VirgoHookService
<TextAttributes
>
Source ​
packages/virgo/src/virgo.ts:62
_isReadonly ​
private
_isReadonly:boolean
=false
Source ​
packages/virgo/src/virgo.ts:48
_mounted ​
private
_mounted:boolean
=false
Source ​
packages/virgo/src/virgo.ts:64
_rangeService ​
private
_rangeService:VirgoRangeService
<TextAttributes
>
Source ​
packages/virgo/src/virgo.ts:53
_rootElement ​
private
_rootElement:null
|VirgoRootElement
<TextAttributes
> =null
Source ​
packages/virgo/src/virgo.ts:47
_yText ​
private
readonly
_yText:Text
Source ​
packages/virgo/src/virgo.ts:46
focusEnd ​
focusEnd: () =>
void
Returns ​
void
Source ​
packages/virgo/src/virgo.ts:142
focusIndex ​
focusIndex: (
index
) =>void
Parameters ​
• index: number
Returns ​
void
Source ​
packages/virgo/src/virgo.ts:144
focusStart ​
focusStart: () =>
void
Returns ​
void
Source ​
packages/virgo/src/virgo.ts:141
getDeltaByRangeIndex ​
getDeltaByRangeIndex: (
rangeIndex
) =>null
|DeltaInsert
<TextAttributes
>
Here are examples of how this function computes and gets the delta.
We have such a text:
[
{
insert: 'aaa',
attributes: { bold: true },
},
{
insert: 'bbb',
attributes: { italic: true },
},
]
getDeltaByRangeIndex(0)
returns { insert: 'aaa', attributes: { bold: true } }
.
getDeltaByRangeIndex(1)
returns { insert: 'aaa', attributes: { bold: true } }
.
getDeltaByRangeIndex(3)
returns { insert: 'aaa', attributes: { bold: true } }
.
getDeltaByRangeIndex(4)
returns { insert: 'bbb', attributes: { italic: true } }
.
Parameters ​
• rangeIndex: number
Returns ​
null
| DeltaInsert
<TextAttributes
>
Source ​
packages/virgo/src/virgo.ts:149
getDeltasByVRange ​
getDeltasByVRange: (
vRange
) =>DeltaEntry
<TextAttributes
>[]
Here are examples of how this function computes and gets the deltas.
We have such a text:
[
{
insert: 'aaa',
attributes: { bold: true },
},
{
insert: 'bbb',
attributes: { italic: true },
},
{
insert: 'ccc',
attributes: { underline: true },
},
]
getDeltasByVRange({ index: 0, length: 0 })
returns
[{ insert: 'aaa', attributes: { bold: true }, }, { index: 0, length: 3, }]]
getDeltasByVRange({ index: 0, length: 1 })
returns
[{ insert: 'aaa', attributes: { bold: true }, }, { index: 0, length: 3, }]]
getDeltasByVRange({ index: 0, length: 4 })
returns
[{ insert: 'aaa', attributes: { bold: true }, }, { index: 0, length: 3, }],
[{ insert: 'bbb', attributes: { italic: true }, }, { index: 3, length: 3, }]]
getDeltasByVRange({ index: 3, length: 1 })
returns
[{ insert: 'aaa', attributes: { bold: true }, }, { index: 0, length: 3, }],
[{ insert: 'bbb', attributes: { italic: true }, }, { index: 3, length: 3, }]]
getDeltasByVRange({ index: 3, length: 3 })
returns
[{ insert: 'aaa', attributes: { bold: true }, }, { index: 0, length: 3, }],
[{ insert: 'bbb', attributes: { italic: true }, }, { index: 3, length: 3, }]]
getDeltasByVRange({ index: 3, length: 4 })
returns
[{ insert: 'aaa', attributes: { bold: true }, }, { index: 0, length: 3, }],
[{ insert: 'bbb', attributes: { italic: true }, }, { index: 3, length: 3, }],
[{ insert: 'ccc', attributes: { underline: true }, }, { index: 6, length: 3, }]]
Parameters ​
• vRange: VRange
Returns ​
DeltaEntry
<TextAttributes
>[]
Source ​
packages/virgo/src/virgo.ts:148
getFormat ​
getFormat: (
vRange
,loose
) =>TextAttributes
Parameters ​
• vRange: VRange
• loose: boolean
= false
Returns ​
TextAttributes
Source ​
packages/virgo/src/virgo.ts:127
getLine ​
getLine: (
rangeIndex
) => readonly [VirgoLine
,number
]
Parameters ​
• rangeIndex: number
Returns ​
readonly [VirgoLine
, number
]
Source ​
packages/virgo/src/virgo.ts:136
getNativeSelection ​
getNativeSelection: () =>
null
|Selection
Returns ​
null
| Selection
Source ​
packages/virgo/src/virgo.ts:134
getTextPoint ​
getTextPoint: (
rangeIndex
) =>TextPoint
Parameters ​
• rangeIndex: number
Returns ​
Source ​
packages/virgo/src/virgo.ts:135
getVRange ​
getVRange: () =>
null
|VRange
Returns ​
null
| VRange
Source ​
packages/virgo/src/virgo.ts:132
getVRangeFromElement ​
getVRangeFromElement: (
element
) =>null
|VRange
Parameters ​
• element: Element
Returns ​
null
| VRange
Source ​
packages/virgo/src/virgo.ts:133
isEmbed ​
readonly
isEmbed: (delta
) =>boolean
Parameters ​
• delta: DeltaInsert
<TextAttributes
>
Returns ​
boolean
Source ​
packages/virgo/src/virgo.ts:66
isFirstLine ​
isFirstLine: (
vRange
) =>boolean
There are two cases to have the second line:
- long text auto wrap in span element
- soft break
Parameters ​
• vRange: null
| VRange
Returns ​
boolean
Source ​
packages/virgo/src/virgo.ts:138
isLastLine ​
isLastLine: (
vRange
) =>boolean
There are two cases to have the second line:
- long text auto wrap in span element
- soft break
Parameters ​
• vRange: null
| VRange
Returns ​
boolean
Source ​
packages/virgo/src/virgo.ts:139
isNormalizedDeltaSelected ​
isNormalizedDeltaSelected: (
normalizedDeltaIndex
,vRange
) =>boolean
Parameters ​
• normalizedDeltaIndex: number
• vRange: VRange
Returns ​
boolean
Source ​
packages/virgo/src/virgo.ts:151
isVRangeValid ​
isVRangeValid: (
vRange
) =>boolean
Parameters ​
• vRange: null
| VRange
Returns ​
boolean
Source ​
packages/virgo/src/virgo.ts:137
mapDeltasInVRange ​
mapDeltasInVRange: <
Result
>(vRange
,callback
,normalize
) =>Result
[]
Type parameters ​
• Result
Parameters ​
• vRange: VRange
• callback: (delta
, rangeIndex
, deltaIndex
) => Result
• normalize: boolean
= false
Returns ​
Result
[]
Source ​
packages/virgo/src/virgo.ts:150
resetMarks ​
resetMarks: () =>
void
Returns ​
void
Source ​
packages/virgo/src/virgo.ts:126
selectAll ​
selectAll: () =>
void
Returns ​
void
Source ​
packages/virgo/src/virgo.ts:143
setAttributeRenderer ​
setAttributeRenderer: (
renderer
) =>void
Parameters ​
• renderer: AttributeRenderer
<TextAttributes
>
Returns ​
void
Source ​
packages/virgo/src/virgo.ts:124
setAttributeSchema ​
setAttributeSchema: (
schema
) =>void
Parameters ​
• schema: ZodType
<TextAttributes
, ZodTypeDef
, unknown
>
Returns ​
void
Source ​
packages/virgo/src/virgo.ts:123
setMarks ​
setMarks: (
marks
) =>void
Parameters ​
• marks: TextAttributes
Returns ​
void
Source ​
packages/virgo/src/virgo.ts:125
setVRange ​
setVRange: (
vRange
,sync
) =>void
the vRange is synced to the native selection asynchronically if sync is true, the native selection will be synced immediately
Parameters ​
• vRange: null
| VRange
• sync: boolean
= true
Returns ​
void
Source ​
packages/virgo/src/virgo.ts:140
slots ​
slots:
Object
Type declaration ​
mounted ​
mounted:
Slot
<void
>
rangeUpdated ​
rangeUpdated:
Slot
<Range
>
unmounted ​
unmounted:
Slot
<void
>
updated ​
updated:
Slot
<void
>
vRangeUpdated ​
vRangeUpdated:
Slot
<VRangeUpdatedProp
>
Source ​
packages/virgo/src/virgo.ts:69
syncVRange ​
syncVRange: () =>
void
sync the dom selection from vRange for this Editor
Returns ​
void
Source ​
packages/virgo/src/virgo.ts:145
toDomRange ​
toDomRange: (
vRange
) =>null
|Range
calculate the dom selection from vRange for this Editor
Parameters ​
• vRange: VRange
Returns ​
null
| Range
Source ​
packages/virgo/src/virgo.ts:130
toVRange ​
toVRange: (
range
) =>null
|VRange
calculate the vRange from dom selection for this Editor there are three cases when the vRange of this Editor is not null: (In the following, "|" mean anchor and focus, each line is a separate Editor)
- anchor and focus are in this Editor aaaaaa b|bbbb|b cccccc the vRange of second Editor is {index: 1, length: 4}, the others are null
- anchor and focus one in this Editor, one in another Editor aaa|aaa aaaaaa bbbbb|b or bbbbb|b cccccc cc|cccc 2.1 the vRange of first Editor is {index: 3, length: 3}, the second is {index: 0, length: 5}, the third is null 2.2 the vRange of first Editor is null, the second is {index: 5, length: 1}, the third is
- anchor and focus are in another Editor aa|aaaa bbbbbb cccc|cc the vRange of first Editor is {index: 2, length: 4}, the second is {index: 0, length: 6}, the third is
Parameters ​
• range: Range
Returns ​
null
| VRange
Source ​
packages/virgo/src/virgo.ts:131
vRangeProvider ​
readonly
vRangeProvider:null
|VRangeProvider
Source ​
packages/virgo/src/virgo.ts:67
getTextNodesFromElement ​
static
getTextNodesFromElement: (element
) =>Text
[] =getTextNodesFromElement
Parameters ​
• element: Element
Returns ​
Text
[]
Source ​
packages/virgo/src/virgo.ts:39
nativePointToTextPoint ​
static
nativePointToTextPoint: (node
,offset
) =>TextPoint
|null
=nativePointToTextPoint
Parameters ​
• node: unknown
• offset: number
Returns ​
TextPoint
| null
Source ​
packages/virgo/src/virgo.ts:37
textPointToDomPoint ​
static
textPointToDomPoint: (text
,offset
,rootElement
) =>DomPoint
|null
=textPointToDomPoint
Parameters ​
• text: Text
• offset: number
• rootElement: HTMLElement
Returns ​
DomPoint
| null
Source ​
packages/virgo/src/virgo.ts:38
Accessors ​
attributeService ​
get
attributeService():VirgoAttributeService
<TextAttributes
>
Returns ​
VirgoAttributeService
<TextAttributes
>
Source ​
packages/virgo/src/virgo.ts:106
deltaService ​
get
deltaService():VirgoDeltaService
<TextAttributes
>
Returns ​
VirgoDeltaService
<TextAttributes
>
Source ​
packages/virgo/src/virgo.ts:110
disposables ​
get
disposables():DisposableGroup
Returns ​
DisposableGroup
Source ​
packages/virgo/src/virgo.ts:42
eventService ​
get
eventService():VirgoEventService
<TextAttributes
>
Returns ​
VirgoEventService
<TextAttributes
>
Source ​
packages/virgo/src/virgo.ts:98
hooks ​
get
hooks():Object
Returns ​
Object
beforeinput? ​
beforeinput?: (
props
) =>null
|VBeforeinputHookCtx
<TextAttributes
>Parameters ​
• props:
VBeforeinputHookCtx
<TextAttributes
>Returns ​
null
|VBeforeinputHookCtx
<TextAttributes
>compositionEnd? ​
compositionEnd?: (
props
) =>null
|VCompositionEndHookCtx
<TextAttributes
>Parameters ​
• props:
VCompositionEndHookCtx
<TextAttributes
>Returns ​
null
|VCompositionEndHookCtx
<TextAttributes
>
Source ​
packages/virgo/src/virgo.ts:154
isReadonly ​
get
isReadonly():boolean
Returns ​
boolean
Source ​
packages/virgo/src/virgo.ts:238
marks ​
get
marks():null
|TextAttributes
Returns ​
null
| TextAttributes
Source ​
packages/virgo/src/virgo.ts:119
mounted ​
get
mounted():boolean
Returns ​
boolean
Source ​
packages/virgo/src/virgo.ts:114
rangeService ​
get
rangeService():VirgoRangeService
<TextAttributes
>
Returns ​
VirgoRangeService
<TextAttributes
>
Source ​
packages/virgo/src/virgo.ts:102
rootElement ​
get
rootElement():VirgoRootElement
<TextAttributes
>
Returns ​
VirgoRootElement
<TextAttributes
>
Source ​
packages/virgo/src/virgo.ts:93
yText ​
get
yText():Text
Returns ​
Source ​
packages/virgo/src/virgo.ts:77
yTextDeltas ​
get
yTextDeltas():any
Returns ​
any
Source ​
packages/virgo/src/virgo.ts:89
yTextLength ​
get
yTextLength():number
Returns ​
number
Source ​
packages/virgo/src/virgo.ts:85
yTextString ​
get
yTextString():string
Returns ​
string
Source ​
packages/virgo/src/virgo.ts:81
Methods ​
_bindYTextObserver() ​
private
_bindYTextObserver():void
Returns ​
void
Source ​
packages/virgo/src/virgo.ts:371
_onYTextChange() ​
private
_onYTextChange():void
Returns ​
void
Source ​
packages/virgo/src/virgo.ts:350
_transact() ​
private
_transact(fn
):void
Parameters ​
• fn: () => void
Returns ​
void
Source ​
packages/virgo/src/virgo.ts:362
deleteText() ​
deleteText(
vRange
):void
Parameters ​
• vRange: VRange
Returns ​
void
Source ​
packages/virgo/src/virgo.ts:242
formatText() ​
formatText(
vRange
,attributes
,options
):void
Parameters ​
• vRange: VRange
• attributes: TextAttributes
• options: Object
= {}
• options.match?: (delta
, deltaVRange
) => boolean
• options.mode?: "replace"
| "merge"
Returns ​
void
Source ​
packages/virgo/src/virgo.ts:276
insertLineBreak() ​
insertLineBreak(
vRange
):void
Parameters ​
• vRange: VRange
Returns ​
void
Source ​
packages/virgo/src/virgo.ts:269
insertText() ​
insertText(
vRange
,text
,attributes
):void
Parameters ​
• vRange: VRange
• text: string
• attributes: TextAttributes
= undefined
Returns ​
void
Source ​
packages/virgo/src/virgo.ts:248
mount() ​
mount(
rootElement
):void
Parameters ​
• rootElement: HTMLElement
Returns ​
void
Source ​
packages/virgo/src/virgo.ts:198
requestUpdate() ​
requestUpdate(
syncVRange
):void
Parameters ​
• syncVRange: boolean
= true
Returns ​
void
Source ​
packages/virgo/src/virgo.ts:224
rerenderWholeEditor() ​
rerenderWholeEditor():
void
Returns ​
void
Source ​
packages/virgo/src/virgo.ts:345
resetText() ​
resetText(
vRange
):void
Parameters ​
• vRange: VRange
Returns ​
void
Source ​
packages/virgo/src/virgo.ts:311
setReadonly() ​
setReadonly(
isReadonly
):void
Parameters ​
• isReadonly: boolean
Returns ​
void
Source ​
packages/virgo/src/virgo.ts:233
setText() ​
setText(
text
,attributes
):void
Parameters ​
• text: string
• attributes: TextAttributes
= undefined
Returns ​
void
Source ​
packages/virgo/src/virgo.ts:335
unmount() ​
unmount():
void
Returns ​
void
Source ​
packages/virgo/src/virgo.ts:215
waitForUpdate() ​
waitForUpdate():
Promise
<void
>
Returns ​
Promise
<void
>
Source ​
packages/virgo/src/virgo.ts:228
Generated using typedoc-plugin-markdown and TypeDoc