API > @blocksuite/virgo > VEditor
Class: VEditor<TextAttributes> ​
Constructors ​
constructor ​
new VEditor<
TextAttributes>(yText,ops={}):VEditor<TextAttributes>
Type parameters ​
| Parameter | Default |
|---|---|
TextAttributes extends {bold: null | true; code: null | true; italic: null | true; link: null | string; strike: null | true; underline: null | true;} | {bold: null | true; code: null | true; italic: null | true; link: null | string; strike: null | true; underline: null | true;} |
Parameters ​
| Parameter | Type |
|---|---|
yText | Text |
ops | object |
ops.hooks? | object |
ops.hooks.beforeinput? | function |
ops.hooks.compositionEnd? | function |
ops.isEmbed? | function |
ops.vRangeProvider? | VRangeProvider |
Returns ​
VEditor< TextAttributes >
Defined In ​
packages/virgo/src/virgo.ts:158
Properties ​
_attributeService ​
private_attributeService:VirgoAttributeService<TextAttributes>
Defined In ​
packages/virgo/src/virgo.ts:56
_deltaService ​
private_deltaService:VirgoDeltaService<TextAttributes>
Defined In ​
packages/virgo/src/virgo.ts:59
_disposables ​
private_disposables:DisposableGroup
Defined In ​
packages/virgo/src/virgo.ts:41
_eventService ​
private_eventService:VirgoEventService<TextAttributes>
Defined In ​
packages/virgo/src/virgo.ts:50
_hooksService ​
private_hooksService:VirgoHookService<TextAttributes>
Defined In ​
packages/virgo/src/virgo.ts:62
_isReadonly ​
private_isReadonly:boolean=false
Defined In ​
packages/virgo/src/virgo.ts:48
_mounted ​
private_mounted:boolean=false
Defined In ​
packages/virgo/src/virgo.ts:64
_rangeService ​
private_rangeService:VirgoRangeService<TextAttributes>
Defined In ​
packages/virgo/src/virgo.ts:53
_rootElement ​
private_rootElement:null|VirgoRootElement<TextAttributes> =null
Defined In ​
packages/virgo/src/virgo.ts:47
_yText ​
privatereadonly_yText:Text
Defined In ​
packages/virgo/src/virgo.ts:46
focusEnd ​
focusEnd:
function
Returns ​
void
Defined In ​
packages/virgo/src/virgo.ts:142
focusIndex ​
focusIndex:
function
Parameters ​
| Parameter | Type |
|---|---|
index | number |
Returns ​
void
Defined In ​
packages/virgo/src/virgo.ts:144
focusStart ​
focusStart:
function
Returns ​
void
Defined In ​
packages/virgo/src/virgo.ts:141
getDeltaByRangeIndex ​
getDeltaByRangeIndex:
function
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 },
},
][
{
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 ​
| Parameter | Type |
|---|---|
rangeIndex | number |
Returns ​
null | DeltaInsert< TextAttributes >
Defined In ​
packages/virgo/src/virgo.ts:149
getDeltasByVRange ​
getDeltasByVRange:
function
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 },
},
][
{
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, }]][{ insert: 'aaa', attributes: { bold: true }, }, { index: 0, length: 3, }]]getDeltasByVRange({ index: 0, length: 1 }) returns
[{ insert: 'aaa', attributes: { bold: true }, }, { index: 0, length: 3, }]][{ 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, }]][{ 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, }]][{ 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, }]][{ 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, }]][{ 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 ​
| Parameter | Type |
|---|---|
vRange | VRange |
Returns ​
DeltaEntry< TextAttributes >[]
Defined In ​
packages/virgo/src/virgo.ts:148
getFormat ​
getFormat:
function
Parameters ​
| Parameter | Type | Default value |
|---|---|---|
vRange | VRange | undefined |
loose | boolean | false |
Returns ​
TextAttributes
Defined In ​
packages/virgo/src/virgo.ts:127
getLine ​
getLine:
function
Parameters ​
| Parameter | Type |
|---|---|
rangeIndex | number |
Returns ​
readonly [VirgoLine, number]
Defined In ​
packages/virgo/src/virgo.ts:136
getNativeSelection ​
getNativeSelection:
function
Returns ​
null | Selection
Defined In ​
packages/virgo/src/virgo.ts:134
getTextPoint ​
getTextPoint:
function
Parameters ​
| Parameter | Type |
|---|---|
rangeIndex | number |
Returns ​
Defined In ​
packages/virgo/src/virgo.ts:135
getVRange ​
getVRange:
function
Returns ​
null | VRange
Defined In ​
packages/virgo/src/virgo.ts:132
getVRangeFromElement ​
getVRangeFromElement:
function
Parameters ​
| Parameter | Type |
|---|---|
element | Element |
Returns ​
null | VRange
Defined In ​
packages/virgo/src/virgo.ts:133
isEmbed ​
readonlyisEmbed:function
Parameters ​
| Parameter | Type |
|---|---|
delta | DeltaInsert< TextAttributes > |
Returns ​
boolean
Defined In ​
packages/virgo/src/virgo.ts:66
isFirstLine ​
isFirstLine:
function
There are two cases to have the second line:
- long text auto wrap in span element
- soft break
Parameters ​
| Parameter | Type |
|---|---|
vRange | null | VRange |
Returns ​
boolean
Defined In ​
packages/virgo/src/virgo.ts:138
isLastLine ​
isLastLine:
function
There are two cases to have the second line:
- long text auto wrap in span element
- soft break
Parameters ​
| Parameter | Type |
|---|---|
vRange | null | VRange |
Returns ​
boolean
Defined In ​
packages/virgo/src/virgo.ts:139
isNormalizedDeltaSelected ​
isNormalizedDeltaSelected:
function
Parameters ​
| Parameter | Type |
|---|---|
normalizedDeltaIndex | number |
vRange | VRange |
Returns ​
boolean
Defined In ​
packages/virgo/src/virgo.ts:151
isVRangeValid ​
isVRangeValid:
function
Parameters ​
| Parameter | Type |
|---|---|
vRange | null | VRange |
Returns ​
boolean
Defined In ​
packages/virgo/src/virgo.ts:137
mapDeltasInVRange ​
mapDeltasInVRange:
function
Type parameters ​
| Parameter |
|---|
Result |
Parameters ​
| Parameter | Type | Default value |
|---|---|---|
vRange | VRange | undefined |
callback | function | undefined |
normalize | boolean | false |
Returns ​
Result[]
Defined In ​
packages/virgo/src/virgo.ts:150
resetMarks ​
resetMarks:
function
Returns ​
void
Defined In ​
packages/virgo/src/virgo.ts:126
selectAll ​
selectAll:
function
Returns ​
void
Defined In ​
packages/virgo/src/virgo.ts:143
setAttributeRenderer ​
setAttributeRenderer:
function
Parameters ​
| Parameter | Type |
|---|---|
renderer | AttributeRenderer< TextAttributes > |
Returns ​
void
Defined In ​
packages/virgo/src/virgo.ts:124
setAttributeSchema ​
setAttributeSchema:
function
Parameters ​
| Parameter | Type |
|---|---|
schema | ZodType< TextAttributes, ZodTypeDef, unknown > |
Returns ​
void
Defined In ​
packages/virgo/src/virgo.ts:123
setMarks ​
setMarks:
function
Parameters ​
| Parameter | Type |
|---|---|
marks | TextAttributes |
Returns ​
void
Defined In ​
packages/virgo/src/virgo.ts:125
setVRange ​
setVRange:
function
the vRange is synced to the native selection asynchronically if sync is true, the native selection will be synced immediately
Parameters ​
| Parameter | Type | Default value |
|---|---|---|
vRange | null | VRange | undefined |
sync | boolean | true |
Returns ​
void
Defined In ​
packages/virgo/src/virgo.ts:140
slots ​
slots:
object
Type declaration ​
slots.mounted​mounted:
Slot<void>
slots.rangeUpdated​rangeUpdated:
Slot<Range>
slots.unmounted​unmounted:
Slot<void>
slots.updated​updated:
Slot<void>
slots.vRangeUpdated​vRangeUpdated:
Slot<VRangeUpdatedProp>
Defined In ​
packages/virgo/src/virgo.ts:69
syncVRange ​
syncVRange:
function
sync the dom selection from vRange for this Editor
Returns ​
void
Defined In ​
packages/virgo/src/virgo.ts:145
toDomRange ​
toDomRange:
function
calculate the dom selection from vRange for this Editor
Parameters ​
| Parameter | Type |
|---|---|
vRange | VRange |
Returns ​
null | Range
Defined In ​
packages/virgo/src/virgo.ts:130
toVRange ​
toVRange:
function
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 ​
| Parameter | Type |
|---|---|
range | Range |
Returns ​
null | VRange
Defined In ​
packages/virgo/src/virgo.ts:131
vRangeProvider ​
readonlyvRangeProvider:null|VRangeProvider
Defined In ​
packages/virgo/src/virgo.ts:67
getTextNodesFromElement ​
staticgetTextNodesFromElement:function=getTextNodesFromElement
Parameters ​
| Parameter | Type |
|---|---|
element | Element |
Returns ​
Text[]
Defined In ​
packages/virgo/src/virgo.ts:39
nativePointToTextPoint ​
staticnativePointToTextPoint:function=nativePointToTextPoint
Parameters ​
| Parameter | Type |
|---|---|
node | unknown |
offset | number |
Returns ​
TextPoint | null
Defined In ​
packages/virgo/src/virgo.ts:37
textPointToDomPoint ​
statictextPointToDomPoint:function=textPointToDomPoint
Parameters ​
| Parameter | Type |
|---|---|
text | Text |
offset | number |
rootElement | HTMLElement |
Returns ​
DomPoint | null
Defined In ​
packages/virgo/src/virgo.ts:38
Accessors ​
attributeService ​
getattributeService():VirgoAttributeService<TextAttributes>
Defined In ​
packages/virgo/src/virgo.ts:106
deltaService ​
getdeltaService():VirgoDeltaService<TextAttributes>
Defined In ​
packages/virgo/src/virgo.ts:110
disposables ​
getdisposables():DisposableGroup
Defined In ​
packages/virgo/src/virgo.ts:42
eventService ​
geteventService():VirgoEventService<TextAttributes>
Defined In ​
packages/virgo/src/virgo.ts:98
hooks ​
gethooks():object
Defined In ​
packages/virgo/src/virgo.ts:154
isReadonly ​
getisReadonly():boolean
Defined In ​
packages/virgo/src/virgo.ts:238
marks ​
getmarks():null|TextAttributes
Defined In ​
packages/virgo/src/virgo.ts:119
mounted ​
getmounted():boolean
Defined In ​
packages/virgo/src/virgo.ts:114
rangeService ​
getrangeService():VirgoRangeService<TextAttributes>
Defined In ​
packages/virgo/src/virgo.ts:102
rootElement ​
getrootElement():VirgoRootElement<TextAttributes>
Defined In ​
packages/virgo/src/virgo.ts:93
yText ​
getyText():Text
Defined In ​
packages/virgo/src/virgo.ts:77
yTextDeltas ​
getyTextDeltas():any
Defined In ​
packages/virgo/src/virgo.ts:89
yTextLength ​
getyTextLength():number
Defined In ​
packages/virgo/src/virgo.ts:85
yTextString ​
getyTextString():string
Defined In ​
packages/virgo/src/virgo.ts:81
Methods ​
_bindYTextObserver ​
private_bindYTextObserver():void
Returns ​
void
Defined In ​
packages/virgo/src/virgo.ts:371
_onYTextChange ​
private_onYTextChange():void
Returns ​
void
Defined In ​
packages/virgo/src/virgo.ts:350
_transact ​
private_transact(fn):void
Parameters ​
| Parameter | Type |
|---|---|
fn | function |
Returns ​
void
Defined In ​
packages/virgo/src/virgo.ts:362
deleteText ​
deleteText(
vRange):void
Parameters ​
| Parameter | Type |
|---|---|
vRange | VRange |
Returns ​
void
Defined In ​
packages/virgo/src/virgo.ts:242
formatText ​
formatText(
vRange,attributes,options={}):void
Parameters ​
| Parameter | Type |
|---|---|
vRange | VRange |
attributes | TextAttributes |
options | object |
options.match? | function |
options.mode? | "replace" | "merge" |
Returns ​
void
Defined In ​
packages/virgo/src/virgo.ts:276
insertLineBreak ​
insertLineBreak(
vRange):void
Parameters ​
| Parameter | Type |
|---|---|
vRange | VRange |
Returns ​
void
Defined In ​
packages/virgo/src/virgo.ts:269
insertText ​
insertText(
vRange,text,attributes=...):void
Parameters ​
| Parameter | Type |
|---|---|
vRange | VRange |
text | string |
attributes | TextAttributes |
Returns ​
void
Defined In ​
packages/virgo/src/virgo.ts:248
mount ​
mount(
rootElement):void
Parameters ​
| Parameter | Type |
|---|---|
rootElement | HTMLElement |
Returns ​
void
Defined In ​
packages/virgo/src/virgo.ts:198
requestUpdate ​
requestUpdate(
syncVRange=true):void
Parameters ​
| Parameter | Type | Default value |
|---|---|---|
syncVRange | boolean | true |
Returns ​
void
Defined In ​
packages/virgo/src/virgo.ts:224
rerenderWholeEditor ​
rerenderWholeEditor():
void
Returns ​
void
Defined In ​
packages/virgo/src/virgo.ts:345
resetText ​
resetText(
vRange):void
Parameters ​
| Parameter | Type |
|---|---|
vRange | VRange |
Returns ​
void
Defined In ​
packages/virgo/src/virgo.ts:311
setReadonly ​
setReadonly(
isReadonly):void
Parameters ​
| Parameter | Type |
|---|---|
isReadonly | boolean |
Returns ​
void
Defined In ​
packages/virgo/src/virgo.ts:233
setText ​
setText(
text,attributes=...):void
Parameters ​
| Parameter | Type |
|---|---|
text | string |
attributes | TextAttributes |
Returns ​
void
Defined In ​
packages/virgo/src/virgo.ts:335
unmount ​
unmount():
void
Returns ​
void
Defined In ​
packages/virgo/src/virgo.ts:215
waitForUpdate ​
waitForUpdate():
Promise<void>
Returns ​
Promise< void >
Defined In ​
packages/virgo/src/virgo.ts:228