BlockSuite API Documentation / @blocksuite/inline / InlineEditor
Class: InlineEditor<TextAttributes> ​
Contents ​
- Type parameters
- Constructors
- Properties
- _attributeService
- _deltaService
- _disposables
- _eventService
- _hooksService
- _isReadonly
- _mounted
- _rangeService
- _rootElement
- _yText
- focusEnd
- focusIndex
- focusStart
- getDeltaByRangeIndex
- getDeltasByInlineRange
- getFormat
- getInlineRange
- getInlineRangeFromElement
- getLine
- getNativeSelection
- getTextPoint
- inlineRangeProvider
- isEmbed
- isFirstLine
- isLastLine
- isNormalizedDeltaSelected
- isValidInlineRange
- mapDeltasInInlineRange
- resetMarks
- selectAll
- setAttributeRenderer
- setAttributeSchema
- setInlineRange
- setMarks
- slots
- syncInlineRange
- toDomRange
- toInlineRange
- getTextNodesFromElement
- nativePointToTextPoint
- textPointToDomPoint
- Accessors
- Methods
Type parameters ​
• TextAttributes extends BaseTextAttributes
= BaseTextAttributes
Constructors ​
new InlineEditor(yText, ops) ​
new InlineEditor<
TextAttributes
>(yText
,ops
):InlineEditor
<TextAttributes
>
Parameters ​
• yText: Text
• ops: Object
= {}
• ops.hooks?: Object
• ops.hooks.beforeinput?: (props
) => null
| BeforeinputHookCtx
<TextAttributes
>
• ops.hooks.compositionEnd?: (props
) => null
| CompositionEndHookCtx
<TextAttributes
>
• ops.inlineRangeProvider?: InlineRangeProvider
• ops.isEmbed?: (delta
) => boolean
Returns ​
InlineEditor
<TextAttributes
>
Source ​
packages/inline/src/inline-editor.ts:162
Properties ​
_attributeService ​
private
_attributeService:AttributeService
<TextAttributes
>
Source ​
packages/inline/src/inline-editor.ts:60
_deltaService ​
private
_deltaService:DeltaService
<TextAttributes
>
Source ​
packages/inline/src/inline-editor.ts:63
_disposables ​
private
_disposables:DisposableGroup
Source ​
packages/inline/src/inline-editor.ts:45
_eventService ​
private
_eventService:EventService
<TextAttributes
>
Source ​
packages/inline/src/inline-editor.ts:54
_hooksService ​
private
_hooksService:InlineHookService
<TextAttributes
>
Source ​
packages/inline/src/inline-editor.ts:66
_isReadonly ​
private
_isReadonly:boolean
=false
Source ​
packages/inline/src/inline-editor.ts:52
_mounted ​
private
_mounted:boolean
=false
Source ​
packages/inline/src/inline-editor.ts:68
_rangeService ​
private
_rangeService:RangeService
<TextAttributes
>
Source ​
packages/inline/src/inline-editor.ts:57
_rootElement ​
private
_rootElement:null
|InlineRootElement
<TextAttributes
> =null
Source ​
packages/inline/src/inline-editor.ts:51
_yText ​
private
readonly
_yText:Text
Source ​
packages/inline/src/inline-editor.ts:50
focusEnd ​
focusEnd: () =>
void
Returns ​
void
Source ​
packages/inline/src/inline-editor.ts:146
focusIndex ​
focusIndex: (
index
) =>void
Parameters ​
• index: number
Returns ​
void
Source ​
packages/inline/src/inline-editor.ts:148
focusStart ​
focusStart: () =>
void
Returns ​
void
Source ​
packages/inline/src/inline-editor.ts:145
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/inline/src/inline-editor.ts:153
getDeltasByInlineRange ​
getDeltasByInlineRange: (
inlineRange
) =>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 },
},
]
getDeltasByInlineRange({ index: 0, length: 0 })
returns
[{ insert: 'aaa', attributes: { bold: true }, }, { index: 0, length: 3, }]]
getDeltasByInlineRange({ index: 0, length: 1 })
returns
[{ insert: 'aaa', attributes: { bold: true }, }, { index: 0, length: 3, }]]
getDeltasByInlineRange({ index: 0, length: 4 })
returns
[{ insert: 'aaa', attributes: { bold: true }, }, { index: 0, length: 3, }],
[{ insert: 'bbb', attributes: { italic: true }, }, { index: 3, length: 3, }]]
getDeltasByInlineRange({ index: 3, length: 1 })
returns
[{ insert: 'aaa', attributes: { bold: true }, }, { index: 0, length: 3, }],
[{ insert: 'bbb', attributes: { italic: true }, }, { index: 3, length: 3, }]]
getDeltasByInlineRange({ index: 3, length: 3 })
returns
[{ insert: 'aaa', attributes: { bold: true }, }, { index: 0, length: 3, }],
[{ insert: 'bbb', attributes: { italic: true }, }, { index: 3, length: 3, }]]
getDeltasByInlineRange({ 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 ​
• inlineRange: InlineRange
Returns ​
DeltaEntry
<TextAttributes
>[]
Source ​
packages/inline/src/inline-editor.ts:152
getFormat ​
getFormat: (
inlineRange
,loose
) =>TextAttributes
Parameters ​
• inlineRange: InlineRange
• loose: boolean
= false
Returns ​
TextAttributes
Source ​
packages/inline/src/inline-editor.ts:131
getInlineRange ​
getInlineRange: () =>
null
|InlineRange
Returns ​
null
| InlineRange
Source ​
packages/inline/src/inline-editor.ts:136
getInlineRangeFromElement ​
getInlineRangeFromElement: (
element
) =>null
|InlineRange
Parameters ​
• element: Element
Returns ​
null
| InlineRange
Source ​
packages/inline/src/inline-editor.ts:137
getLine ​
getLine: (
rangeIndex
) => readonly [VLine
,number
]
Parameters ​
• rangeIndex: number
Returns ​
readonly [VLine
, number
]
Source ​
packages/inline/src/inline-editor.ts:140
getNativeSelection ​
getNativeSelection: () =>
null
|Selection
Returns ​
null
| Selection
Source ​
packages/inline/src/inline-editor.ts:138
getTextPoint ​
getTextPoint: (
rangeIndex
) =>TextPoint
Parameters ​
• rangeIndex: number
Returns ​
Source ​
packages/inline/src/inline-editor.ts:139
inlineRangeProvider ​
readonly
inlineRangeProvider:null
|InlineRangeProvider
Source ​
packages/inline/src/inline-editor.ts:71
isEmbed ​
readonly
isEmbed: (delta
) =>boolean
Parameters ​
• delta: DeltaInsert
<TextAttributes
>
Returns ​
boolean
Source ​
packages/inline/src/inline-editor.ts:70
isFirstLine ​
isFirstLine: (
inlineRange
) =>boolean
There are two cases to have the second line:
- long text auto wrap in span element
- soft break
Parameters ​
• inlineRange: null
| InlineRange
Returns ​
boolean
Source ​
packages/inline/src/inline-editor.ts:142
isLastLine ​
isLastLine: (
inlineRange
) =>boolean
There are two cases to have the second line:
- long text auto wrap in span element
- soft break
Parameters ​
• inlineRange: null
| InlineRange
Returns ​
boolean
Source ​
packages/inline/src/inline-editor.ts:143
isNormalizedDeltaSelected ​
isNormalizedDeltaSelected: (
normalizedDeltaIndex
,inlineRange
) =>boolean
Parameters ​
• normalizedDeltaIndex: number
• inlineRange: InlineRange
Returns ​
boolean
Source ​
packages/inline/src/inline-editor.ts:155
isValidInlineRange ​
isValidInlineRange: (
inlineRange
) =>boolean
Parameters ​
• inlineRange: null
| InlineRange
Returns ​
boolean
Source ​
packages/inline/src/inline-editor.ts:141
mapDeltasInInlineRange ​
mapDeltasInInlineRange: <
Result
>(inlineRange
,callback
,normalize
) =>Result
[]
Type parameters ​
• Result
Parameters ​
• inlineRange: InlineRange
• callback: (delta
, rangeIndex
, deltaIndex
) => Result
• normalize: boolean
= false
Returns ​
Result
[]
Source ​
packages/inline/src/inline-editor.ts:154
resetMarks ​
resetMarks: () =>
void
Returns ​
void
Source ​
packages/inline/src/inline-editor.ts:130
selectAll ​
selectAll: () =>
void
Returns ​
void
Source ​
packages/inline/src/inline-editor.ts:147
setAttributeRenderer ​
setAttributeRenderer: (
renderer
) =>void
Parameters ​
• renderer: AttributeRenderer
<TextAttributes
>
Returns ​
void
Source ​
packages/inline/src/inline-editor.ts:128
setAttributeSchema ​
setAttributeSchema: (
schema
) =>void
Parameters ​
• schema: ZodType
<TextAttributes
, ZodTypeDef
, unknown
>
Returns ​
void
Source ​
packages/inline/src/inline-editor.ts:127
setInlineRange ​
setInlineRange: (
inlineRange
,sync
) =>void
the inline ranage is synced to the native selection asynchronically if sync is true, the native selection will be synced immediately
Parameters ​
• inlineRange: null
| InlineRange
• sync: boolean
= true
Returns ​
void
Source ​
packages/inline/src/inline-editor.ts:144
setMarks ​
setMarks: (
marks
) =>void
Parameters ​
• marks: TextAttributes
Returns ​
void
Source ​
packages/inline/src/inline-editor.ts:129
slots ​
slots:
Object
Type declaration ​
inlineRangeUpdated ​
inlineRangeUpdated:
Slot
<InlineRangeUpdatedProp
>
mounted ​
mounted:
Slot
<void
>
rangeUpdated ​
rangeUpdated:
Slot
<Range
>
unmounted ​
unmounted:
Slot
<void
>
updated ​
updated:
Slot
<void
>
Source ​
packages/inline/src/inline-editor.ts:73
syncInlineRange ​
syncInlineRange: () =>
void
sync the dom selection from inline ranage for this Editor
Returns ​
void
Source ​
packages/inline/src/inline-editor.ts:149
toDomRange ​
toDomRange: (
inlineRange
) =>null
|Range
calculate the dom selection from inline ranage for this Editor
Parameters ​
• inlineRange: InlineRange
Returns ​
null
| Range
Source ​
packages/inline/src/inline-editor.ts:134
toInlineRange ​
toInlineRange: (
range
) =>null
|InlineRange
calculate the inline ranage from dom selection for this Editor there are three cases when the inline ranage 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 inline ranage 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 inline ranage of first Editor is {index: 3, length: 3}, the second is {index: 0, length: 5}, the third is null 2.2 the inline ranage of first Editor is null, the second is {index: 5, length: 1}, the third is {index: 0, length: 2}
- anchor and focus are in another Editor aa|aaaa bbbbbb cccc|cc the inline range of first Editor is {index: 2, length: 4}, the second is {index: 0, length: 6}, the third is {index: 0, length: 4}
Parameters ​
• range: Range
Returns ​
null
| InlineRange
Source ​
packages/inline/src/inline-editor.ts:135
getTextNodesFromElement ​
static
getTextNodesFromElement: (element
) =>Text
[] =getTextNodesFromElement
Parameters ​
• element: Element
Returns ​
Text
[]
Source ​
packages/inline/src/inline-editor.ts:43
nativePointToTextPoint ​
static
nativePointToTextPoint: (node
,offset
) =>TextPoint
|null
=nativePointToTextPoint
Parameters ​
• node: unknown
• offset: number
Returns ​
TextPoint
| null
Source ​
packages/inline/src/inline-editor.ts:41
textPointToDomPoint ​
static
textPointToDomPoint: (text
,offset
,rootElement
) =>DomPoint
|null
=textPointToDomPoint
Parameters ​
• text: Text
• offset: number
• rootElement: HTMLElement
Returns ​
DomPoint
| null
Source ​
packages/inline/src/inline-editor.ts:42
Accessors ​
attributeService ​
get
attributeService():AttributeService
<TextAttributes
>
Returns ​
AttributeService
<TextAttributes
>
Source ​
packages/inline/src/inline-editor.ts:110
deltaService ​
get
deltaService():DeltaService
<TextAttributes
>
Returns ​
DeltaService
<TextAttributes
>
Source ​
packages/inline/src/inline-editor.ts:114
disposables ​
get
disposables():DisposableGroup
Returns ​
DisposableGroup
Source ​
packages/inline/src/inline-editor.ts:46
eventService ​
get
eventService():EventService
<TextAttributes
>
Returns ​
EventService
<TextAttributes
>
Source ​
packages/inline/src/inline-editor.ts:102
hooks ​
get
hooks():Object
Returns ​
Object
beforeinput? ​
beforeinput?: (
props
) =>null
|BeforeinputHookCtx
<TextAttributes
>Parameters ​
• props:
BeforeinputHookCtx
<TextAttributes
>Returns ​
null
|BeforeinputHookCtx
<TextAttributes
>compositionEnd? ​
compositionEnd?: (
props
) =>null
|CompositionEndHookCtx
<TextAttributes
>Parameters ​
• props:
CompositionEndHookCtx
<TextAttributes
>Returns ​
null
|CompositionEndHookCtx
<TextAttributes
>
Source ​
packages/inline/src/inline-editor.ts:158
isReadonly ​
get
isReadonly():boolean
Returns ​
boolean
Source ​
packages/inline/src/inline-editor.ts:246
marks ​
get
marks():null
|TextAttributes
Returns ​
null
| TextAttributes
Source ​
packages/inline/src/inline-editor.ts:123
mounted ​
get
mounted():boolean
Returns ​
boolean
Source ​
packages/inline/src/inline-editor.ts:118
rangeService ​
get
rangeService():RangeService
<TextAttributes
>
Returns ​
RangeService
<TextAttributes
>
Source ​
packages/inline/src/inline-editor.ts:106
rootElement ​
get
rootElement():InlineRootElement
<TextAttributes
>
Returns ​
InlineRootElement
<TextAttributes
>
Source ​
packages/inline/src/inline-editor.ts:97
yText ​
get
yText():Text
Returns ​
Source ​
packages/inline/src/inline-editor.ts:81
yTextDeltas ​
get
yTextDeltas():any
Returns ​
any
Source ​
packages/inline/src/inline-editor.ts:93
yTextLength ​
get
yTextLength():number
Returns ​
number
Source ​
packages/inline/src/inline-editor.ts:89
yTextString ​
get
yTextString():string
Returns ​
string
Source ​
packages/inline/src/inline-editor.ts:85
Methods ​
_bindYTextObserver() ​
private
_bindYTextObserver():void
Returns ​
void
Source ​
packages/inline/src/inline-editor.ts:386
_onYTextChange() ​
private
_onYTextChange():void
Returns ​
void
Source ​
packages/inline/src/inline-editor.ts:365
_transact() ​
private
_transact(fn
):void
Parameters ​
• fn: () => void
Returns ​
void
Source ​
packages/inline/src/inline-editor.ts:377
deleteText() ​
deleteText(
inlineRange
):void
Parameters ​
• inlineRange: InlineRange
Returns ​
void
Source ​
packages/inline/src/inline-editor.ts:250
formatText() ​
formatText(
inlineRange
,attributes
,options
):void
Parameters ​
• inlineRange: InlineRange
• attributes: TextAttributes
• options: Object
= {}
• options.match?: (delta
, deltaInlineRange
) => boolean
• options.mode?: "replace"
| "merge"
Returns ​
void
Source ​
packages/inline/src/inline-editor.ts:284
insertLineBreak() ​
insertLineBreak(
inlineRange
):void
Parameters ​
• inlineRange: InlineRange
Returns ​
void
Source ​
packages/inline/src/inline-editor.ts:277
insertText() ​
insertText(
inlineRange
,text
,attributes
):void
Parameters ​
• inlineRange: InlineRange
• text: string
• attributes: TextAttributes
= undefined
Returns ​
void
Source ​
packages/inline/src/inline-editor.ts:256
mount() ​
mount(
rootElement
):void
Parameters ​
• rootElement: HTMLElement
Returns ​
void
Source ​
packages/inline/src/inline-editor.ts:206
requestUpdate() ​
requestUpdate(
syncInlineRange
):void
Parameters ​
• syncInlineRange: boolean
= true
Returns ​
void
Source ​
packages/inline/src/inline-editor.ts:232
rerenderWholeEditor() ​
rerenderWholeEditor():
void
Returns ​
void
Source ​
packages/inline/src/inline-editor.ts:360
resetText() ​
resetText(
inlineRange
):void
Parameters ​
• inlineRange: InlineRange
Returns ​
void
Source ​
packages/inline/src/inline-editor.ts:322
setReadonly() ​
setReadonly(
isReadonly
):void
Parameters ​
• isReadonly: boolean
Returns ​
void
Source ​
packages/inline/src/inline-editor.ts:241
setText() ​
setText(
text
,attributes
):void
Parameters ​
• text: string
• attributes: TextAttributes
= undefined
Returns ​
void
Source ​
packages/inline/src/inline-editor.ts:350
unmount() ​
unmount():
void
Returns ​
void
Source ​
packages/inline/src/inline-editor.ts:223
waitForUpdate() ​
waitForUpdate():
Promise
<void
>
Returns ​
Promise
<void
>
Source ​
packages/inline/src/inline-editor.ts:236
Generated using typedoc-plugin-markdown and TypeDoc