BlockSuite API Documentation / @blocksuite/inline / InlineEditor
Class: InlineEditor<TextAttributes> β
Contents β
- Type parameters
- Constructors
- Properties
- _attributeService
- _deltaService
- _disposables
- _eventService
- _eventSource
- _hooksService
- _isReadonly
- _mounted
- _rangeService
- _rootElement
- _textService
- _yText
- deleteText
- focusEnd
- focusIndex
- focusStart
- formatText
- getDeltaByRangeIndex
- getDeltasByInlineRange
- getFormat
- getInlineRange
- getInlineRangeFromElement
- getLine
- getNativeSelection
- getTextPoint
- inlineRangeProvider
- insertLineBreak
- insertText
- isEmbed
- isFirstLine
- isLastLine
- isNormalizedDeltaSelected
- isValidInlineRange
- mapDeltasInInlineRange
- resetMarks
- resetText
- selectAll
- setAttributeRenderer
- setAttributeSchema
- setInlineRange
- setMarks
- setText
- 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:181
Properties β
_attributeService β
private
_attributeService:AttributeService
<TextAttributes
>
Source β
packages/inline/src/inline-editor.ts:61
_deltaService β
private
_deltaService:DeltaService
<TextAttributes
>
Source β
packages/inline/src/inline-editor.ts:64
_disposables β
private
_disposables:DisposableGroup
Source β
packages/inline/src/inline-editor.ts:45
_eventService β
private
_eventService:EventService
<TextAttributes
>
Source β
packages/inline/src/inline-editor.ts:55
_eventSource β
private
_eventSource:null
|HTMLElement
=null
Source β
packages/inline/src/inline-editor.ts:52
_hooksService β
private
_hooksService:InlineHookService
<TextAttributes
>
Source β
packages/inline/src/inline-editor.ts:70
_isReadonly β
private
_isReadonly:boolean
=false
Source β
packages/inline/src/inline-editor.ts:53
_mounted β
private
_mounted:boolean
=false
Source β
packages/inline/src/inline-editor.ts:72
_rangeService β
private
_rangeService:RangeService
<TextAttributes
>
Source β
packages/inline/src/inline-editor.ts:58
_rootElement β
private
_rootElement:null
|InlineRootElement
<TextAttributes
> =null
Source β
packages/inline/src/inline-editor.ts:51
_textService β
private
_textService:InlineTextService
<TextAttributes
>
Source β
packages/inline/src/inline-editor.ts:67
_yText β
private
readonly
_yText:Text
Source β
packages/inline/src/inline-editor.ts:50
deleteText β
deleteText: (
inlineRange
) =>void
Parameters β
β’ inlineRange: InlineRange
Returns β
void
Source β
packages/inline/src/inline-editor.ts:169
focusEnd β
focusEnd: () =>
void
Returns β
void
Source β
packages/inline/src/inline-editor.ts:157
focusIndex β
focusIndex: (
index
) =>void
Parameters β
β’ index: number
Returns β
void
Source β
packages/inline/src/inline-editor.ts:159
focusStart β
focusStart: () =>
void
Returns β
void
Source β
packages/inline/src/inline-editor.ts:156
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:172
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:164
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:163
getFormat β
getFormat: (
inlineRange
,loose
) =>TextAttributes
Parameters β
β’ inlineRange: InlineRange
β’ loose: boolean
= false
Returns β
TextAttributes
Source β
packages/inline/src/inline-editor.ts:142
getInlineRange β
getInlineRange: () =>
null
|InlineRange
Returns β
null
| InlineRange
Source β
packages/inline/src/inline-editor.ts:147
getInlineRangeFromElement β
getInlineRangeFromElement: (
element
) =>null
|InlineRange
Parameters β
β’ element: Element
Returns β
null
| InlineRange
Source β
packages/inline/src/inline-editor.ts:148
getLine β
getLine: (
rangeIndex
) => readonly [VLine
,number
]
Parameters β
β’ rangeIndex: number
Returns β
readonly [VLine
, number
]
Source β
packages/inline/src/inline-editor.ts:151
getNativeSelection β
getNativeSelection: () =>
null
|Selection
Returns β
null
| Selection
Source β
packages/inline/src/inline-editor.ts:149
getTextPoint β
getTextPoint: (
rangeIndex
) =>TextPoint
Parameters β
β’ rangeIndex: number
Returns β
Source β
packages/inline/src/inline-editor.ts:150
inlineRangeProvider β
readonly
inlineRangeProvider:null
|InlineRangeProvider
Source β
packages/inline/src/inline-editor.ts:75
insertLineBreak β
insertLineBreak: (
inlineRange
) =>void
Parameters β
β’ inlineRange: InlineRange
Returns β
void
Source β
packages/inline/src/inline-editor.ts:171
insertText β
insertText: (
inlineRange
,text
,attributes
) =>void
Parameters β
β’ inlineRange: InlineRange
β’ text: string
β’ attributes: TextAttributes
= undefined
Returns β
void
Source β
packages/inline/src/inline-editor.ts:170
isEmbed β
readonly
isEmbed: (delta
) =>boolean
Parameters β
β’ delta: DeltaInsert
<TextAttributes
>
Returns β
boolean
Source β
packages/inline/src/inline-editor.ts:74
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:153
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:154
isNormalizedDeltaSelected β
isNormalizedDeltaSelected: (
normalizedDeltaIndex
,inlineRange
) =>boolean
Parameters β
β’ normalizedDeltaIndex: number
β’ inlineRange: InlineRange
Returns β
boolean
Source β
packages/inline/src/inline-editor.ts:166
isValidInlineRange β
isValidInlineRange: (
inlineRange
) =>boolean
Parameters β
β’ inlineRange: null
| InlineRange
Returns β
boolean
Source β
packages/inline/src/inline-editor.ts:152
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:165
resetMarks β
resetMarks: () =>
void
Returns β
void
Source β
packages/inline/src/inline-editor.ts:141
resetText β
resetText: (
inlineRange
) =>void
Parameters β
β’ inlineRange: InlineRange
Returns β
void
Source β
packages/inline/src/inline-editor.ts:173
selectAll β
selectAll: () =>
void
Returns β
void
Source β
packages/inline/src/inline-editor.ts:158
setAttributeRenderer β
setAttributeRenderer: (
renderer
) =>void
Parameters β
β’ renderer: AttributeRenderer
<TextAttributes
>
Returns β
void
Source β
packages/inline/src/inline-editor.ts:139
setAttributeSchema β
setAttributeSchema: (
schema
) =>void
Parameters β
β’ schema: ZodType
<TextAttributes
, ZodTypeDef
, unknown
>
Returns β
void
Source β
packages/inline/src/inline-editor.ts:138
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:155
setMarks β
setMarks: (
marks
) =>void
Parameters β
β’ marks: TextAttributes
Returns β
void
Source β
packages/inline/src/inline-editor.ts:140
setText β
setText: (
text
,attributes
) =>void
Parameters β
β’ text: string
β’ attributes: TextAttributes
= undefined
Returns β
void
Source β
packages/inline/src/inline-editor.ts:174
slots β
readonly
slots:Object
Type declaration β
inlineRangeApply β
inlineRangeApply:
Slot
<Range
>
inlineRangeUpdate β
inlineRangeUpdate:
Slot
<InlineRangeUpdatedProp
>
mounted β
mounted:
Slot
<void
>
render β
render:
Slot
<void
>
renderComplete β
renderComplete:
Slot
<void
>
textChange β
textChange:
Slot
<void
>
unmounted β
unmounted:
Slot
<void
>
Source β
packages/inline/src/inline-editor.ts:77
syncInlineRange β
syncInlineRange: () =>
void
sync the dom selection from inline ranage for this Editor
Returns β
void
Source β
packages/inline/src/inline-editor.ts:160
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:145
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 Editorthe inline ranage of second Editor is
aaaaaa b|bbbb|b cccccc
{index: 1, length: 4}
, the others are null - anchor and focus one in this Editor, one in another Editor2.1 the inline ranage of first Editor is
aaa|aaa aaaaaa bbbbb|b or bbbbb|b cccccc cc|cccc
{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 Editorthe inline range of first Editor is
aa|aaaa bbbbbb cccc|cc
{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:146
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:121
deltaService β
get
deltaService():DeltaService
<TextAttributes
>
Returns β
DeltaService
<TextAttributes
>
Source β
packages/inline/src/inline-editor.ts:125
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:113
eventSource β
get
eventSource():HTMLElement
Returns β
HTMLElement
Source β
packages/inline/src/inline-editor.ts:108
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:177
isReadonly β
get
isReadonly():boolean
Returns β
boolean
Source β
packages/inline/src/inline-editor.ts:259
marks β
get
marks():null
|TextAttributes
Returns β
null
| TextAttributes
Source β
packages/inline/src/inline-editor.ts:134
mounted β
get
mounted():boolean
Returns β
boolean
Source β
packages/inline/src/inline-editor.ts:129
rangeService β
get
rangeService():RangeService
<TextAttributes
>
Returns β
RangeService
<TextAttributes
>
Source β
packages/inline/src/inline-editor.ts:117
rootElement β
get
rootElement():InlineRootElement
<TextAttributes
>
Returns β
InlineRootElement
<TextAttributes
>
Source β
packages/inline/src/inline-editor.ts:103
yText β
get
yText():Text
Returns β
Source β
packages/inline/src/inline-editor.ts:87
yTextDeltas β
get
yTextDeltas():any
Returns β
any
Source β
packages/inline/src/inline-editor.ts:99
yTextLength β
get
yTextLength():number
Returns β
number
Source β
packages/inline/src/inline-editor.ts:95
yTextString β
get
yTextString():string
Returns β
string
Source β
packages/inline/src/inline-editor.ts:91
Methods β
_bindYTextObserver() β
private
_bindYTextObserver():void
Returns β
void
Source β
packages/inline/src/inline-editor.ts:291
_onYTextChange() β
private
_onYTextChange():void
Returns β
void
Source β
packages/inline/src/inline-editor.ts:277
mount() β
mount(
rootElement
,eventSource
):void
Parameters β
β’ rootElement: HTMLElement
β’ eventSource: HTMLElement
= rootElement
Returns β
void
Source β
packages/inline/src/inline-editor.ts:217
requestUpdate() β
requestUpdate(
syncInlineRange
):void
Parameters β
β’ syncInlineRange: boolean
= true
Returns β
void
Source β
packages/inline/src/inline-editor.ts:245
rerenderWholeEditor() β
rerenderWholeEditor():
void
Returns β
void
Source β
packages/inline/src/inline-editor.ts:263
setReadonly() β
setReadonly(
isReadonly
):void
Parameters β
β’ isReadonly: boolean
Returns β
void
Source β
packages/inline/src/inline-editor.ts:254
transact() β
transact(
fn
):void
Parameters β
β’ fn: () => void
Returns β
void
Source β
packages/inline/src/inline-editor.ts:268
unmount() β
unmount():
void
Returns β
void
Source β
packages/inline/src/inline-editor.ts:236
waitForUpdate() β
waitForUpdate():
Promise
<void
>
Returns β
Promise
<void
>
Source β
packages/inline/src/inline-editor.ts:249
Generated using typedoc-plugin-markdown and TypeDoc