mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-22 06:53:25 +02:00
This reverts commit ef09c8cf6e
.
This commit is contained in:
@@ -14,7 +14,6 @@ import {
|
|||||||
Transforms,
|
Transforms,
|
||||||
} from './'
|
} from './'
|
||||||
import { DIRTY_PATHS, DIRTY_PATH_KEYS, FLUSHING } from './utils/weak-maps'
|
import { DIRTY_PATHS, DIRTY_PATH_KEYS, FLUSHING } from './utils/weak-maps'
|
||||||
import { TextUnit } from './interfaces/types'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Slate `Editor` object.
|
* Create a new Slate `Editor` object.
|
||||||
@@ -122,7 +121,7 @@ export const createEditor = (): Editor => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
deleteBackward: (unit: TextUnit) => {
|
deleteBackward: (unit: 'character' | 'word' | 'line' | 'block') => {
|
||||||
const { selection } = editor
|
const { selection } = editor
|
||||||
|
|
||||||
if (selection && Range.isCollapsed(selection)) {
|
if (selection && Range.isCollapsed(selection)) {
|
||||||
@@ -130,7 +129,7 @@ export const createEditor = (): Editor => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
deleteForward: (unit: TextUnit) => {
|
deleteForward: (unit: 'character' | 'word' | 'line' | 'block') => {
|
||||||
const { selection } = editor
|
const { selection } = editor
|
||||||
|
|
||||||
if (selection && Range.isCollapsed(selection)) {
|
if (selection && Range.isCollapsed(selection)) {
|
||||||
|
@@ -15,6 +15,7 @@ import {
|
|||||||
RangeRef,
|
RangeRef,
|
||||||
Span,
|
Span,
|
||||||
Text,
|
Text,
|
||||||
|
Transforms,
|
||||||
} from '..'
|
} from '..'
|
||||||
import {
|
import {
|
||||||
DIRTY_PATHS,
|
DIRTY_PATHS,
|
||||||
@@ -31,22 +32,11 @@ import {
|
|||||||
} from '../utils/string'
|
} from '../utils/string'
|
||||||
import { Descendant } from './node'
|
import { Descendant } from './node'
|
||||||
import { Element } from './element'
|
import { Element } from './element'
|
||||||
import {
|
|
||||||
LeafEdge,
|
|
||||||
SelectionMode,
|
|
||||||
TextDirection,
|
|
||||||
TextUnit,
|
|
||||||
TextUnitAdjustment,
|
|
||||||
RangeDirection,
|
|
||||||
MaximizeMode,
|
|
||||||
} from './types'
|
|
||||||
|
|
||||||
export type BaseSelection = Range | null
|
export type BaseSelection = Range | null
|
||||||
|
|
||||||
export type Selection = ExtendedType<'Selection', BaseSelection>
|
export type Selection = ExtendedType<'Selection', BaseSelection>
|
||||||
|
|
||||||
export type EditorMarks = Omit<Text, 'text'>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `Editor` interface stores all the state of a Slate editor. It is extended
|
* The `Editor` interface stores all the state of a Slate editor. It is extended
|
||||||
* by plugins that wish to add their own helpers and implement new behaviors.
|
* by plugins that wish to add their own helpers and implement new behaviors.
|
||||||
@@ -56,7 +46,7 @@ export interface BaseEditor {
|
|||||||
children: Descendant[]
|
children: Descendant[]
|
||||||
selection: Selection
|
selection: Selection
|
||||||
operations: Operation[]
|
operations: Operation[]
|
||||||
marks: EditorMarks | null
|
marks: Omit<Text, 'text'> | null
|
||||||
|
|
||||||
// Schema-specific node behaviors.
|
// Schema-specific node behaviors.
|
||||||
isInline: (element: Element) => boolean
|
isInline: (element: Element) => boolean
|
||||||
@@ -67,9 +57,9 @@ export interface BaseEditor {
|
|||||||
// Overrideable core actions.
|
// Overrideable core actions.
|
||||||
addMark: (key: string, value: any) => void
|
addMark: (key: string, value: any) => void
|
||||||
apply: (operation: Operation) => void
|
apply: (operation: Operation) => void
|
||||||
deleteBackward: (unit: TextUnit) => void
|
deleteBackward: (unit: 'character' | 'word' | 'line' | 'block') => void
|
||||||
deleteForward: (unit: TextUnit) => void
|
deleteForward: (unit: 'character' | 'word' | 'line' | 'block') => void
|
||||||
deleteFragment: (direction?: TextDirection) => void
|
deleteFragment: (direction?: 'forward' | 'backward') => void
|
||||||
getFragment: () => Descendant[]
|
getFragment: () => Descendant[]
|
||||||
insertBreak: () => void
|
insertBreak: () => void
|
||||||
insertSoftBreak: () => void
|
insertSoftBreak: () => void
|
||||||
@@ -81,151 +71,52 @@ export interface BaseEditor {
|
|||||||
|
|
||||||
export type Editor = ExtendedType<'Editor', BaseEditor>
|
export type Editor = ExtendedType<'Editor', BaseEditor>
|
||||||
|
|
||||||
export interface EditorAboveOptions<T extends Ancestor> {
|
|
||||||
at?: Location
|
|
||||||
match?: NodeMatch<T>
|
|
||||||
mode?: MaximizeMode
|
|
||||||
voids?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EditorAfterOptions {
|
|
||||||
distance?: number
|
|
||||||
unit?: TextUnitAdjustment
|
|
||||||
voids?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EditorBeforeOptions {
|
|
||||||
distance?: number
|
|
||||||
unit?: TextUnitAdjustment
|
|
||||||
voids?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EditorDirectedDeletionOptions {
|
|
||||||
unit?: TextUnit
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EditorFragmentDeletionOptions {
|
|
||||||
direction?: TextDirection
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EditorLeafOptions {
|
|
||||||
depth?: number
|
|
||||||
edge?: LeafEdge
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EditorLevelsOptions<T extends Node> {
|
|
||||||
at?: Location
|
|
||||||
match?: NodeMatch<T>
|
|
||||||
reverse?: boolean
|
|
||||||
voids?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EditorNextOptions<T extends Descendant> {
|
|
||||||
at?: Location
|
|
||||||
match?: NodeMatch<T>
|
|
||||||
mode?: SelectionMode
|
|
||||||
voids?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EditorNodeOptions {
|
|
||||||
depth?: number
|
|
||||||
edge?: LeafEdge
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EditorNodesOptions<T extends Node> {
|
|
||||||
at?: Location | Span
|
|
||||||
match?: NodeMatch<T>
|
|
||||||
mode?: SelectionMode
|
|
||||||
universal?: boolean
|
|
||||||
reverse?: boolean
|
|
||||||
voids?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EditorNormalizeOptions {
|
|
||||||
force?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EditorParentOptions {
|
|
||||||
depth?: number
|
|
||||||
edge?: LeafEdge
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EditorPathOptions {
|
|
||||||
depth?: number
|
|
||||||
edge?: LeafEdge
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EditorPathRefOptions {
|
|
||||||
affinity?: TextDirection | null
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EditorPointOptions {
|
|
||||||
edge?: LeafEdge
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EditorPointRefOptions {
|
|
||||||
affinity?: TextDirection | null
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EditorPositionsOptions {
|
|
||||||
at?: Location
|
|
||||||
unit?: TextUnitAdjustment
|
|
||||||
reverse?: boolean
|
|
||||||
voids?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EditorPreviousOptions<T extends Node> {
|
|
||||||
at?: Location
|
|
||||||
match?: NodeMatch<T>
|
|
||||||
mode?: SelectionMode
|
|
||||||
voids?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EditorRangeRefOptions {
|
|
||||||
affinity?: RangeDirection | null
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EditorStringOptions {
|
|
||||||
voids?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EditorUnhangRangeOptions {
|
|
||||||
voids?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EditorVoidOptions {
|
|
||||||
at?: Location
|
|
||||||
mode?: MaximizeMode
|
|
||||||
voids?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EditorInterface {
|
export interface EditorInterface {
|
||||||
above: <T extends Ancestor>(
|
above: <T extends Ancestor>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options?: EditorAboveOptions<T>
|
options?: {
|
||||||
|
at?: Location
|
||||||
|
match?: NodeMatch<T>
|
||||||
|
mode?: 'highest' | 'lowest'
|
||||||
|
voids?: boolean
|
||||||
|
}
|
||||||
) => NodeEntry<T> | undefined
|
) => NodeEntry<T> | undefined
|
||||||
addMark: (editor: Editor, key: string, value: any) => void
|
addMark: (editor: Editor, key: string, value: any) => void
|
||||||
after: (
|
after: (
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
at: Location,
|
at: Location,
|
||||||
options?: EditorAfterOptions
|
options?: {
|
||||||
|
distance?: number
|
||||||
|
unit?: 'offset' | 'character' | 'word' | 'line' | 'block'
|
||||||
|
voids?: boolean
|
||||||
|
}
|
||||||
) => Point | undefined
|
) => Point | undefined
|
||||||
before: (
|
before: (
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
at: Location,
|
at: Location,
|
||||||
options?: EditorBeforeOptions
|
options?: {
|
||||||
|
distance?: number
|
||||||
|
unit?: 'offset' | 'character' | 'word' | 'line' | 'block'
|
||||||
|
voids?: boolean
|
||||||
|
}
|
||||||
) => Point | undefined
|
) => Point | undefined
|
||||||
deleteBackward: (
|
deleteBackward: (
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options?: EditorDirectedDeletionOptions
|
options?: {
|
||||||
|
unit?: 'character' | 'word' | 'line' | 'block'
|
||||||
|
}
|
||||||
) => void
|
) => void
|
||||||
deleteForward: (
|
deleteForward: (
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options?: EditorDirectedDeletionOptions
|
options?: {
|
||||||
|
unit?: 'character' | 'word' | 'line' | 'block'
|
||||||
|
}
|
||||||
) => void
|
) => void
|
||||||
deleteFragment: (
|
deleteFragment: (
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options?: EditorFragmentDeletionOptions
|
options?: {
|
||||||
|
direction?: 'forward' | 'backward'
|
||||||
|
}
|
||||||
) => void
|
) => void
|
||||||
edges: (editor: Editor, at: Location) => [Point, Point]
|
edges: (editor: Editor, at: Location) => [Point, Point]
|
||||||
end: (editor: Editor, at: Location) => Point
|
end: (editor: Editor, at: Location) => Point
|
||||||
@@ -253,55 +144,119 @@ export interface EditorInterface {
|
|||||||
leaf: (
|
leaf: (
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
at: Location,
|
at: Location,
|
||||||
options?: EditorLeafOptions
|
options?: {
|
||||||
|
depth?: number
|
||||||
|
edge?: 'start' | 'end'
|
||||||
|
}
|
||||||
) => NodeEntry<Text>
|
) => NodeEntry<Text>
|
||||||
levels: <T extends Node>(
|
levels: <T extends Node>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options?: EditorLevelsOptions<T>
|
options?: {
|
||||||
|
at?: Location
|
||||||
|
match?: NodeMatch<T>
|
||||||
|
reverse?: boolean
|
||||||
|
voids?: boolean
|
||||||
|
}
|
||||||
) => Generator<NodeEntry<T>, void, undefined>
|
) => Generator<NodeEntry<T>, void, undefined>
|
||||||
marks: (editor: Editor) => Omit<Text, 'text'> | null
|
marks: (editor: Editor) => Omit<Text, 'text'> | null
|
||||||
next: <T extends Descendant>(
|
next: <T extends Descendant>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options?: EditorNextOptions<T>
|
options?: {
|
||||||
|
at?: Location
|
||||||
|
match?: NodeMatch<T>
|
||||||
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
|
voids?: boolean
|
||||||
|
}
|
||||||
) => NodeEntry<T> | undefined
|
) => NodeEntry<T> | undefined
|
||||||
node: (editor: Editor, at: Location, options?: EditorNodeOptions) => NodeEntry
|
node: (
|
||||||
|
editor: Editor,
|
||||||
|
at: Location,
|
||||||
|
options?: {
|
||||||
|
depth?: number
|
||||||
|
edge?: 'start' | 'end'
|
||||||
|
}
|
||||||
|
) => NodeEntry
|
||||||
nodes: <T extends Node>(
|
nodes: <T extends Node>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options?: EditorNodesOptions<T>
|
options?: {
|
||||||
|
at?: Location | Span
|
||||||
|
match?: NodeMatch<T>
|
||||||
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
|
universal?: boolean
|
||||||
|
reverse?: boolean
|
||||||
|
voids?: boolean
|
||||||
|
}
|
||||||
) => Generator<NodeEntry<T>, void, undefined>
|
) => Generator<NodeEntry<T>, void, undefined>
|
||||||
normalize: (editor: Editor, options?: EditorNormalizeOptions) => void
|
normalize: (
|
||||||
|
editor: Editor,
|
||||||
|
options?: {
|
||||||
|
force?: boolean
|
||||||
|
}
|
||||||
|
) => void
|
||||||
parent: (
|
parent: (
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
at: Location,
|
at: Location,
|
||||||
options?: EditorParentOptions
|
options?: {
|
||||||
|
depth?: number
|
||||||
|
edge?: 'start' | 'end'
|
||||||
|
}
|
||||||
) => NodeEntry<Ancestor>
|
) => NodeEntry<Ancestor>
|
||||||
path: (editor: Editor, at: Location, options?: EditorPathOptions) => Path
|
path: (
|
||||||
|
editor: Editor,
|
||||||
|
at: Location,
|
||||||
|
options?: {
|
||||||
|
depth?: number
|
||||||
|
edge?: 'start' | 'end'
|
||||||
|
}
|
||||||
|
) => Path
|
||||||
pathRef: (
|
pathRef: (
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
path: Path,
|
path: Path,
|
||||||
options?: EditorPathRefOptions
|
options?: {
|
||||||
|
affinity?: 'backward' | 'forward' | null
|
||||||
|
}
|
||||||
) => PathRef
|
) => PathRef
|
||||||
pathRefs: (editor: Editor) => Set<PathRef>
|
pathRefs: (editor: Editor) => Set<PathRef>
|
||||||
point: (editor: Editor, at: Location, options?: EditorPointOptions) => Point
|
point: (
|
||||||
|
editor: Editor,
|
||||||
|
at: Location,
|
||||||
|
options?: {
|
||||||
|
edge?: 'start' | 'end'
|
||||||
|
}
|
||||||
|
) => Point
|
||||||
pointRef: (
|
pointRef: (
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
point: Point,
|
point: Point,
|
||||||
options?: EditorPointRefOptions
|
options?: {
|
||||||
|
affinity?: 'backward' | 'forward' | null
|
||||||
|
}
|
||||||
) => PointRef
|
) => PointRef
|
||||||
pointRefs: (editor: Editor) => Set<PointRef>
|
pointRefs: (editor: Editor) => Set<PointRef>
|
||||||
positions: (
|
positions: (
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options?: EditorPositionsOptions
|
options?: {
|
||||||
|
at?: Location
|
||||||
|
unit?: 'offset' | 'character' | 'word' | 'line' | 'block'
|
||||||
|
reverse?: boolean
|
||||||
|
voids?: boolean
|
||||||
|
}
|
||||||
) => Generator<Point, void, undefined>
|
) => Generator<Point, void, undefined>
|
||||||
previous: <T extends Node>(
|
previous: <T extends Node>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options?: EditorPreviousOptions<T>
|
options?: {
|
||||||
|
at?: Location
|
||||||
|
match?: NodeMatch<T>
|
||||||
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
|
voids?: boolean
|
||||||
|
}
|
||||||
) => NodeEntry<T> | undefined
|
) => NodeEntry<T> | undefined
|
||||||
range: (editor: Editor, at: Location, to?: Location) => Range
|
range: (editor: Editor, at: Location, to?: Location) => Range
|
||||||
rangeRef: (
|
rangeRef: (
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
range: Range,
|
range: Range,
|
||||||
options?: EditorRangeRefOptions
|
options?: {
|
||||||
|
affinity?: 'backward' | 'forward' | 'outward' | 'inward' | null
|
||||||
|
}
|
||||||
) => RangeRef
|
) => RangeRef
|
||||||
rangeRefs: (editor: Editor) => Set<RangeRef>
|
rangeRefs: (editor: Editor) => Set<RangeRef>
|
||||||
removeMark: (editor: Editor, key: string) => void
|
removeMark: (editor: Editor, key: string) => void
|
||||||
@@ -310,16 +265,24 @@ export interface EditorInterface {
|
|||||||
string: (
|
string: (
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
at: Location,
|
at: Location,
|
||||||
options?: EditorStringOptions
|
options?: {
|
||||||
|
voids?: boolean
|
||||||
|
}
|
||||||
) => string
|
) => string
|
||||||
unhangRange: (
|
unhangRange: (
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
range: Range,
|
range: Range,
|
||||||
options?: EditorUnhangRangeOptions
|
options?: {
|
||||||
|
voids?: boolean
|
||||||
|
}
|
||||||
) => Range
|
) => Range
|
||||||
void: (
|
void: (
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options?: EditorVoidOptions
|
options?: {
|
||||||
|
at?: Location
|
||||||
|
mode?: 'highest' | 'lowest'
|
||||||
|
voids?: boolean
|
||||||
|
}
|
||||||
) => NodeEntry<Element> | undefined
|
) => NodeEntry<Element> | undefined
|
||||||
withoutNormalizing: (editor: Editor, fn: () => void) => void
|
withoutNormalizing: (editor: Editor, fn: () => void) => void
|
||||||
}
|
}
|
||||||
@@ -333,7 +296,12 @@ export const Editor: EditorInterface = {
|
|||||||
|
|
||||||
above<T extends Ancestor>(
|
above<T extends Ancestor>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options: EditorAboveOptions<T> = {}
|
options: {
|
||||||
|
at?: Location
|
||||||
|
match?: NodeMatch<T>
|
||||||
|
mode?: 'highest' | 'lowest'
|
||||||
|
voids?: boolean
|
||||||
|
} = {}
|
||||||
): NodeEntry<T> | undefined {
|
): NodeEntry<T> | undefined {
|
||||||
const {
|
const {
|
||||||
voids = false,
|
voids = false,
|
||||||
@@ -379,7 +347,11 @@ export const Editor: EditorInterface = {
|
|||||||
after(
|
after(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
at: Location,
|
at: Location,
|
||||||
options: EditorAfterOptions = {}
|
options: {
|
||||||
|
distance?: number
|
||||||
|
unit?: 'offset' | 'character' | 'word' | 'line' | 'block'
|
||||||
|
voids?: boolean
|
||||||
|
} = {}
|
||||||
): Point | undefined {
|
): Point | undefined {
|
||||||
const anchor = Editor.point(editor, at, { edge: 'end' })
|
const anchor = Editor.point(editor, at, { edge: 'end' })
|
||||||
const focus = Editor.end(editor, [])
|
const focus = Editor.end(editor, [])
|
||||||
@@ -413,7 +385,11 @@ export const Editor: EditorInterface = {
|
|||||||
before(
|
before(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
at: Location,
|
at: Location,
|
||||||
options: EditorBeforeOptions = {}
|
options: {
|
||||||
|
distance?: number
|
||||||
|
unit?: 'offset' | 'character' | 'word' | 'line' | 'block'
|
||||||
|
voids?: boolean
|
||||||
|
} = {}
|
||||||
): Point | undefined {
|
): Point | undefined {
|
||||||
const anchor = Editor.start(editor, [])
|
const anchor = Editor.start(editor, [])
|
||||||
const focus = Editor.point(editor, at, { edge: 'start' })
|
const focus = Editor.point(editor, at, { edge: 'start' })
|
||||||
@@ -447,7 +423,9 @@ export const Editor: EditorInterface = {
|
|||||||
|
|
||||||
deleteBackward(
|
deleteBackward(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options: EditorDirectedDeletionOptions = {}
|
options: {
|
||||||
|
unit?: 'character' | 'word' | 'line' | 'block'
|
||||||
|
} = {}
|
||||||
): void {
|
): void {
|
||||||
const { unit = 'character' } = options
|
const { unit = 'character' } = options
|
||||||
editor.deleteBackward(unit)
|
editor.deleteBackward(unit)
|
||||||
@@ -459,7 +437,9 @@ export const Editor: EditorInterface = {
|
|||||||
|
|
||||||
deleteForward(
|
deleteForward(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options: EditorDirectedDeletionOptions = {}
|
options: {
|
||||||
|
unit?: 'character' | 'word' | 'line' | 'block'
|
||||||
|
} = {}
|
||||||
): void {
|
): void {
|
||||||
const { unit = 'character' } = options
|
const { unit = 'character' } = options
|
||||||
editor.deleteForward(unit)
|
editor.deleteForward(unit)
|
||||||
@@ -471,7 +451,9 @@ export const Editor: EditorInterface = {
|
|||||||
|
|
||||||
deleteFragment(
|
deleteFragment(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options: EditorFragmentDeletionOptions = {}
|
options: {
|
||||||
|
direction?: 'forward' | 'backward'
|
||||||
|
} = {}
|
||||||
): void {
|
): void {
|
||||||
const { direction = 'forward' } = options
|
const { direction = 'forward' } = options
|
||||||
editor.deleteFragment(direction)
|
editor.deleteFragment(direction)
|
||||||
@@ -717,7 +699,10 @@ export const Editor: EditorInterface = {
|
|||||||
leaf(
|
leaf(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
at: Location,
|
at: Location,
|
||||||
options: EditorLeafOptions = {}
|
options: {
|
||||||
|
depth?: number
|
||||||
|
edge?: 'start' | 'end'
|
||||||
|
} = {}
|
||||||
): NodeEntry<Text> {
|
): NodeEntry<Text> {
|
||||||
const path = Editor.path(editor, at, options)
|
const path = Editor.path(editor, at, options)
|
||||||
const node = Node.leaf(editor, path)
|
const node = Node.leaf(editor, path)
|
||||||
@@ -730,7 +715,12 @@ export const Editor: EditorInterface = {
|
|||||||
|
|
||||||
*levels<T extends Node>(
|
*levels<T extends Node>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options: EditorLevelsOptions<T> = {}
|
options: {
|
||||||
|
at?: Location
|
||||||
|
match?: NodeMatch<T>
|
||||||
|
reverse?: boolean
|
||||||
|
voids?: boolean
|
||||||
|
} = {}
|
||||||
): Generator<NodeEntry<T>, void, undefined> {
|
): Generator<NodeEntry<T>, void, undefined> {
|
||||||
const { at = editor.selection, reverse = false, voids = false } = options
|
const { at = editor.selection, reverse = false, voids = false } = options
|
||||||
let { match } = options
|
let { match } = options
|
||||||
@@ -822,7 +812,12 @@ export const Editor: EditorInterface = {
|
|||||||
|
|
||||||
next<T extends Descendant>(
|
next<T extends Descendant>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options: EditorNextOptions<T> = {}
|
options: {
|
||||||
|
at?: Location
|
||||||
|
match?: NodeMatch<T>
|
||||||
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
|
voids?: boolean
|
||||||
|
} = {}
|
||||||
): NodeEntry<T> | undefined {
|
): NodeEntry<T> | undefined {
|
||||||
const { mode = 'lowest', voids = false } = options
|
const { mode = 'lowest', voids = false } = options
|
||||||
let { match, at = editor.selection } = options
|
let { match, at = editor.selection } = options
|
||||||
@@ -863,7 +858,10 @@ export const Editor: EditorInterface = {
|
|||||||
node(
|
node(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
at: Location,
|
at: Location,
|
||||||
options: EditorNodeOptions = {}
|
options: {
|
||||||
|
depth?: number
|
||||||
|
edge?: 'start' | 'end'
|
||||||
|
} = {}
|
||||||
): NodeEntry {
|
): NodeEntry {
|
||||||
const path = Editor.path(editor, at, options)
|
const path = Editor.path(editor, at, options)
|
||||||
const node = Node.get(editor, path)
|
const node = Node.get(editor, path)
|
||||||
@@ -876,7 +874,14 @@ export const Editor: EditorInterface = {
|
|||||||
|
|
||||||
*nodes<T extends Node>(
|
*nodes<T extends Node>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options: EditorNodesOptions<T> = {}
|
options: {
|
||||||
|
at?: Location | Span
|
||||||
|
match?: NodeMatch<T>
|
||||||
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
|
universal?: boolean
|
||||||
|
reverse?: boolean
|
||||||
|
voids?: boolean
|
||||||
|
} = {}
|
||||||
): Generator<NodeEntry<T>, void, undefined> {
|
): Generator<NodeEntry<T>, void, undefined> {
|
||||||
const {
|
const {
|
||||||
at = editor.selection,
|
at = editor.selection,
|
||||||
@@ -977,7 +982,12 @@ export const Editor: EditorInterface = {
|
|||||||
* Normalize any dirty objects in the editor.
|
* Normalize any dirty objects in the editor.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
normalize(editor: Editor, options: EditorNormalizeOptions = {}): void {
|
normalize(
|
||||||
|
editor: Editor,
|
||||||
|
options: {
|
||||||
|
force?: boolean
|
||||||
|
} = {}
|
||||||
|
): void {
|
||||||
const { force = false } = options
|
const { force = false } = options
|
||||||
const getDirtyPaths = (editor: Editor) => {
|
const getDirtyPaths = (editor: Editor) => {
|
||||||
return DIRTY_PATHS.get(editor) || []
|
return DIRTY_PATHS.get(editor) || []
|
||||||
@@ -1062,7 +1072,10 @@ export const Editor: EditorInterface = {
|
|||||||
parent(
|
parent(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
at: Location,
|
at: Location,
|
||||||
options: EditorParentOptions = {}
|
options: {
|
||||||
|
depth?: number
|
||||||
|
edge?: 'start' | 'end'
|
||||||
|
} = {}
|
||||||
): NodeEntry<Ancestor> {
|
): NodeEntry<Ancestor> {
|
||||||
const path = Editor.path(editor, at, options)
|
const path = Editor.path(editor, at, options)
|
||||||
const parentPath = Path.parent(path)
|
const parentPath = Path.parent(path)
|
||||||
@@ -1074,7 +1087,14 @@ export const Editor: EditorInterface = {
|
|||||||
* Get the path of a location.
|
* Get the path of a location.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
path(editor: Editor, at: Location, options: EditorPathOptions = {}): Path {
|
path(
|
||||||
|
editor: Editor,
|
||||||
|
at: Location,
|
||||||
|
options: {
|
||||||
|
depth?: number
|
||||||
|
edge?: 'start' | 'end'
|
||||||
|
} = {}
|
||||||
|
): Path {
|
||||||
const { depth, edge } = options
|
const { depth, edge } = options
|
||||||
|
|
||||||
if (Path.isPath(at)) {
|
if (Path.isPath(at)) {
|
||||||
@@ -1120,7 +1140,9 @@ export const Editor: EditorInterface = {
|
|||||||
pathRef(
|
pathRef(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
path: Path,
|
path: Path,
|
||||||
options: EditorPathRefOptions = {}
|
options: {
|
||||||
|
affinity?: 'backward' | 'forward' | null
|
||||||
|
} = {}
|
||||||
): PathRef {
|
): PathRef {
|
||||||
const { affinity = 'forward' } = options
|
const { affinity = 'forward' } = options
|
||||||
const ref: PathRef = {
|
const ref: PathRef = {
|
||||||
@@ -1159,7 +1181,13 @@ export const Editor: EditorInterface = {
|
|||||||
* Get the start or end point of a location.
|
* Get the start or end point of a location.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
point(editor: Editor, at: Location, options: EditorPointOptions = {}): Point {
|
point(
|
||||||
|
editor: Editor,
|
||||||
|
at: Location,
|
||||||
|
options: {
|
||||||
|
edge?: 'start' | 'end'
|
||||||
|
} = {}
|
||||||
|
): Point {
|
||||||
const { edge = 'start' } = options
|
const { edge = 'start' } = options
|
||||||
|
|
||||||
if (Path.isPath(at)) {
|
if (Path.isPath(at)) {
|
||||||
@@ -1200,7 +1228,9 @@ export const Editor: EditorInterface = {
|
|||||||
pointRef(
|
pointRef(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
point: Point,
|
point: Point,
|
||||||
options: EditorPointRefOptions = {}
|
options: {
|
||||||
|
affinity?: 'backward' | 'forward' | null
|
||||||
|
} = {}
|
||||||
): PointRef {
|
): PointRef {
|
||||||
const { affinity = 'forward' } = options
|
const { affinity = 'forward' } = options
|
||||||
const ref: PointRef = {
|
const ref: PointRef = {
|
||||||
@@ -1250,7 +1280,12 @@ export const Editor: EditorInterface = {
|
|||||||
|
|
||||||
*positions(
|
*positions(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options: EditorPositionsOptions = {}
|
options: {
|
||||||
|
at?: Location
|
||||||
|
unit?: 'offset' | 'character' | 'word' | 'line' | 'block'
|
||||||
|
reverse?: boolean
|
||||||
|
voids?: boolean
|
||||||
|
} = {}
|
||||||
): Generator<Point, void, undefined> {
|
): Generator<Point, void, undefined> {
|
||||||
const {
|
const {
|
||||||
at = editor.selection,
|
at = editor.selection,
|
||||||
@@ -1434,7 +1469,12 @@ export const Editor: EditorInterface = {
|
|||||||
|
|
||||||
previous<T extends Node>(
|
previous<T extends Node>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options: EditorPreviousOptions<T> = {}
|
options: {
|
||||||
|
at?: Location
|
||||||
|
match?: NodeMatch<T>
|
||||||
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
|
voids?: boolean
|
||||||
|
} = {}
|
||||||
): NodeEntry<T> | undefined {
|
): NodeEntry<T> | undefined {
|
||||||
const { mode = 'lowest', voids = false } = options
|
const { mode = 'lowest', voids = false } = options
|
||||||
let { match, at = editor.selection } = options
|
let { match, at = editor.selection } = options
|
||||||
@@ -1501,7 +1541,9 @@ export const Editor: EditorInterface = {
|
|||||||
rangeRef(
|
rangeRef(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
range: Range,
|
range: Range,
|
||||||
options: EditorRangeRefOptions = {}
|
options: {
|
||||||
|
affinity?: 'backward' | 'forward' | 'outward' | 'inward' | null
|
||||||
|
} = {}
|
||||||
): RangeRef {
|
): RangeRef {
|
||||||
const { affinity = 'forward' } = options
|
const { affinity = 'forward' } = options
|
||||||
const ref: RangeRef = {
|
const ref: RangeRef = {
|
||||||
@@ -1576,7 +1618,9 @@ export const Editor: EditorInterface = {
|
|||||||
string(
|
string(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
at: Location,
|
at: Location,
|
||||||
options: EditorStringOptions = {}
|
options: {
|
||||||
|
voids?: boolean
|
||||||
|
} = {}
|
||||||
): string {
|
): string {
|
||||||
const { voids = false } = options
|
const { voids = false } = options
|
||||||
const range = Editor.range(editor, at)
|
const range = Editor.range(editor, at)
|
||||||
@@ -1611,7 +1655,9 @@ export const Editor: EditorInterface = {
|
|||||||
unhangRange(
|
unhangRange(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
range: Range,
|
range: Range,
|
||||||
options: EditorUnhangRangeOptions = {}
|
options: {
|
||||||
|
voids?: boolean
|
||||||
|
} = {}
|
||||||
): Range {
|
): Range {
|
||||||
const { voids = false } = options
|
const { voids = false } = options
|
||||||
let [start, end] = Range.edges(range)
|
let [start, end] = Range.edges(range)
|
||||||
@@ -1656,7 +1702,11 @@ export const Editor: EditorInterface = {
|
|||||||
|
|
||||||
void(
|
void(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options: EditorVoidOptions = {}
|
options: {
|
||||||
|
at?: Location
|
||||||
|
mode?: 'highest' | 'lowest'
|
||||||
|
voids?: boolean
|
||||||
|
} = {}
|
||||||
): NodeEntry<Element> | undefined {
|
): NodeEntry<Element> | undefined {
|
||||||
return Editor.above(editor, {
|
return Editor.above(editor, {
|
||||||
...options,
|
...options,
|
||||||
|
@@ -10,68 +10,42 @@ import { Element, ElementEntry } from './element'
|
|||||||
export type BaseNode = Editor | Element | Text
|
export type BaseNode = Editor | Element | Text
|
||||||
export type Node = Editor | Element | Text
|
export type Node = Editor | Element | Text
|
||||||
|
|
||||||
export interface NodeAncestorsOptions {
|
|
||||||
reverse?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface NodeChildrenOptions {
|
|
||||||
reverse?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface NodeDescendantsOptions {
|
|
||||||
from?: Path
|
|
||||||
to?: Path
|
|
||||||
reverse?: boolean
|
|
||||||
pass?: (node: NodeEntry) => boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface NodeElementsOptions {
|
|
||||||
from?: Path
|
|
||||||
to?: Path
|
|
||||||
reverse?: boolean
|
|
||||||
pass?: (node: NodeEntry) => boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface NodeLevelsOptions {
|
|
||||||
reverse?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface NodeNodesOptions {
|
|
||||||
from?: Path
|
|
||||||
to?: Path
|
|
||||||
reverse?: boolean
|
|
||||||
pass?: (entry: NodeEntry) => boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface NodeTextsOptions {
|
|
||||||
from?: Path
|
|
||||||
to?: Path
|
|
||||||
reverse?: boolean
|
|
||||||
pass?: (node: NodeEntry) => boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface NodeInterface {
|
export interface NodeInterface {
|
||||||
ancestor: (root: Node, path: Path) => Ancestor
|
ancestor: (root: Node, path: Path) => Ancestor
|
||||||
ancestors: (
|
ancestors: (
|
||||||
root: Node,
|
root: Node,
|
||||||
path: Path,
|
path: Path,
|
||||||
options?: NodeAncestorsOptions
|
options?: {
|
||||||
|
reverse?: boolean
|
||||||
|
}
|
||||||
) => Generator<NodeEntry<Ancestor>, void, undefined>
|
) => Generator<NodeEntry<Ancestor>, void, undefined>
|
||||||
child: (root: Node, index: number) => Descendant
|
child: (root: Node, index: number) => Descendant
|
||||||
children: (
|
children: (
|
||||||
root: Node,
|
root: Node,
|
||||||
path: Path,
|
path: Path,
|
||||||
options?: NodeChildrenOptions
|
options?: {
|
||||||
|
reverse?: boolean
|
||||||
|
}
|
||||||
) => Generator<NodeEntry<Descendant>, void, undefined>
|
) => Generator<NodeEntry<Descendant>, void, undefined>
|
||||||
common: (root: Node, path: Path, another: Path) => NodeEntry
|
common: (root: Node, path: Path, another: Path) => NodeEntry
|
||||||
descendant: (root: Node, path: Path) => Descendant
|
descendant: (root: Node, path: Path) => Descendant
|
||||||
descendants: (
|
descendants: (
|
||||||
root: Node,
|
root: Node,
|
||||||
options?: NodeDescendantsOptions
|
options?: {
|
||||||
|
from?: Path
|
||||||
|
to?: Path
|
||||||
|
reverse?: boolean
|
||||||
|
pass?: (node: NodeEntry) => boolean
|
||||||
|
}
|
||||||
) => Generator<NodeEntry<Descendant>, void, undefined>
|
) => Generator<NodeEntry<Descendant>, void, undefined>
|
||||||
elements: (
|
elements: (
|
||||||
root: Node,
|
root: Node,
|
||||||
options?: NodeElementsOptions
|
options?: {
|
||||||
|
from?: Path
|
||||||
|
to?: Path
|
||||||
|
reverse?: boolean
|
||||||
|
pass?: (node: NodeEntry) => boolean
|
||||||
|
}
|
||||||
) => Generator<ElementEntry, void, undefined>
|
) => Generator<ElementEntry, void, undefined>
|
||||||
extractProps: (node: Node) => NodeProps
|
extractProps: (node: Node) => NodeProps
|
||||||
first: (root: Node, path: Path) => NodeEntry
|
first: (root: Node, path: Path) => NodeEntry
|
||||||
@@ -85,18 +59,30 @@ export interface NodeInterface {
|
|||||||
levels: (
|
levels: (
|
||||||
root: Node,
|
root: Node,
|
||||||
path: Path,
|
path: Path,
|
||||||
options?: NodeLevelsOptions
|
options?: {
|
||||||
|
reverse?: boolean
|
||||||
|
}
|
||||||
) => Generator<NodeEntry, void, undefined>
|
) => Generator<NodeEntry, void, undefined>
|
||||||
matches: (node: Node, props: Partial<Node>) => boolean
|
matches: (node: Node, props: Partial<Node>) => boolean
|
||||||
nodes: (
|
nodes: (
|
||||||
root: Node,
|
root: Node,
|
||||||
options?: NodeNodesOptions
|
options?: {
|
||||||
|
from?: Path
|
||||||
|
to?: Path
|
||||||
|
reverse?: boolean
|
||||||
|
pass?: (entry: NodeEntry) => boolean
|
||||||
|
}
|
||||||
) => Generator<NodeEntry, void, undefined>
|
) => Generator<NodeEntry, void, undefined>
|
||||||
parent: (root: Node, path: Path) => Ancestor
|
parent: (root: Node, path: Path) => Ancestor
|
||||||
string: (node: Node) => string
|
string: (node: Node) => string
|
||||||
texts: (
|
texts: (
|
||||||
root: Node,
|
root: Node,
|
||||||
options?: NodeTextsOptions
|
options?: {
|
||||||
|
from?: Path
|
||||||
|
to?: Path
|
||||||
|
reverse?: boolean
|
||||||
|
pass?: (node: NodeEntry) => boolean
|
||||||
|
}
|
||||||
) => Generator<NodeEntry<Text>, void, undefined>
|
) => Generator<NodeEntry<Text>, void, undefined>
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,7 +115,9 @@ export const Node: NodeInterface = {
|
|||||||
*ancestors(
|
*ancestors(
|
||||||
root: Node,
|
root: Node,
|
||||||
path: Path,
|
path: Path,
|
||||||
options: NodeAncestorsOptions = {}
|
options: {
|
||||||
|
reverse?: boolean
|
||||||
|
} = {}
|
||||||
): Generator<NodeEntry<Ancestor>, void, undefined> {
|
): Generator<NodeEntry<Ancestor>, void, undefined> {
|
||||||
for (const p of Path.ancestors(path, options)) {
|
for (const p of Path.ancestors(path, options)) {
|
||||||
const n = Node.ancestor(root, p)
|
const n = Node.ancestor(root, p)
|
||||||
@@ -169,7 +157,9 @@ export const Node: NodeInterface = {
|
|||||||
*children(
|
*children(
|
||||||
root: Node,
|
root: Node,
|
||||||
path: Path,
|
path: Path,
|
||||||
options: NodeChildrenOptions = {}
|
options: {
|
||||||
|
reverse?: boolean
|
||||||
|
} = {}
|
||||||
): Generator<NodeEntry<Descendant>, void, undefined> {
|
): Generator<NodeEntry<Descendant>, void, undefined> {
|
||||||
const { reverse = false } = options
|
const { reverse = false } = options
|
||||||
const ancestor = Node.ancestor(root, path)
|
const ancestor = Node.ancestor(root, path)
|
||||||
@@ -216,7 +206,12 @@ export const Node: NodeInterface = {
|
|||||||
|
|
||||||
*descendants(
|
*descendants(
|
||||||
root: Node,
|
root: Node,
|
||||||
options: NodeDescendantsOptions = {}
|
options: {
|
||||||
|
from?: Path
|
||||||
|
to?: Path
|
||||||
|
reverse?: boolean
|
||||||
|
pass?: (node: NodeEntry) => boolean
|
||||||
|
} = {}
|
||||||
): Generator<NodeEntry<Descendant>, void, undefined> {
|
): Generator<NodeEntry<Descendant>, void, undefined> {
|
||||||
for (const [node, path] of Node.nodes(root, options)) {
|
for (const [node, path] of Node.nodes(root, options)) {
|
||||||
if (path.length !== 0) {
|
if (path.length !== 0) {
|
||||||
@@ -235,7 +230,12 @@ export const Node: NodeInterface = {
|
|||||||
|
|
||||||
*elements(
|
*elements(
|
||||||
root: Node,
|
root: Node,
|
||||||
options: NodeElementsOptions = {}
|
options: {
|
||||||
|
from?: Path
|
||||||
|
to?: Path
|
||||||
|
reverse?: boolean
|
||||||
|
pass?: (node: NodeEntry) => boolean
|
||||||
|
} = {}
|
||||||
): Generator<ElementEntry, void, undefined> {
|
): Generator<ElementEntry, void, undefined> {
|
||||||
for (const [node, path] of Node.nodes(root, options)) {
|
for (const [node, path] of Node.nodes(root, options)) {
|
||||||
if (Element.isElement(node)) {
|
if (Element.isElement(node)) {
|
||||||
@@ -445,7 +445,9 @@ export const Node: NodeInterface = {
|
|||||||
*levels(
|
*levels(
|
||||||
root: Node,
|
root: Node,
|
||||||
path: Path,
|
path: Path,
|
||||||
options: NodeLevelsOptions = {}
|
options: {
|
||||||
|
reverse?: boolean
|
||||||
|
} = {}
|
||||||
): Generator<NodeEntry, void, undefined> {
|
): Generator<NodeEntry, void, undefined> {
|
||||||
for (const p of Path.levels(path, options)) {
|
for (const p of Path.levels(path, options)) {
|
||||||
const n = Node.get(root, p)
|
const n = Node.get(root, p)
|
||||||
@@ -476,7 +478,12 @@ export const Node: NodeInterface = {
|
|||||||
|
|
||||||
*nodes(
|
*nodes(
|
||||||
root: Node,
|
root: Node,
|
||||||
options: NodeNodesOptions = {}
|
options: {
|
||||||
|
from?: Path
|
||||||
|
to?: Path
|
||||||
|
reverse?: boolean
|
||||||
|
pass?: (entry: NodeEntry) => boolean
|
||||||
|
} = {}
|
||||||
): Generator<NodeEntry, void, undefined> {
|
): Generator<NodeEntry, void, undefined> {
|
||||||
const { pass, reverse = false } = options
|
const { pass, reverse = false } = options
|
||||||
const { from = [], to } = options
|
const { from = [], to } = options
|
||||||
@@ -582,7 +589,12 @@ export const Node: NodeInterface = {
|
|||||||
|
|
||||||
*texts(
|
*texts(
|
||||||
root: Node,
|
root: Node,
|
||||||
options: NodeTextsOptions = {}
|
options: {
|
||||||
|
from?: Path
|
||||||
|
to?: Path
|
||||||
|
reverse?: boolean
|
||||||
|
pass?: (node: NodeEntry) => boolean
|
||||||
|
} = {}
|
||||||
): Generator<NodeEntry<Text>, void, undefined> {
|
): Generator<NodeEntry<Text>, void, undefined> {
|
||||||
for (const [node, path] of Node.nodes(root, options)) {
|
for (const [node, path] of Node.nodes(root, options)) {
|
||||||
if (Text.isText(node)) {
|
if (Text.isText(node)) {
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
import { produce } from 'immer'
|
import { produce } from 'immer'
|
||||||
import { Operation } from '..'
|
import { Operation } from '..'
|
||||||
import { TextDirection } from './types'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* `Path` arrays are a list of indexes that describe a node's exact position in
|
* `Path` arrays are a list of indexes that describe a node's exact position in
|
||||||
@@ -10,20 +9,8 @@ import { TextDirection } from './types'
|
|||||||
|
|
||||||
export type Path = number[]
|
export type Path = number[]
|
||||||
|
|
||||||
export interface PathAncestorsOptions {
|
|
||||||
reverse?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PathLevelsOptions {
|
|
||||||
reverse?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PathTransformOptions {
|
|
||||||
affinity?: TextDirection | null
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PathInterface {
|
export interface PathInterface {
|
||||||
ancestors: (path: Path, options?: PathAncestorsOptions) => Path[]
|
ancestors: (path: Path, options?: { reverse?: boolean }) => Path[]
|
||||||
common: (path: Path, another: Path) => Path
|
common: (path: Path, another: Path) => Path
|
||||||
compare: (path: Path, another: Path) => -1 | 0 | 1
|
compare: (path: Path, another: Path) => -1 | 0 | 1
|
||||||
endsAfter: (path: Path, another: Path) => boolean
|
endsAfter: (path: Path, another: Path) => boolean
|
||||||
@@ -40,7 +27,12 @@ export interface PathInterface {
|
|||||||
isParent: (path: Path, another: Path) => boolean
|
isParent: (path: Path, another: Path) => boolean
|
||||||
isPath: (value: any) => value is Path
|
isPath: (value: any) => value is Path
|
||||||
isSibling: (path: Path, another: Path) => boolean
|
isSibling: (path: Path, another: Path) => boolean
|
||||||
levels: (path: Path, options?: PathLevelsOptions) => Path[]
|
levels: (
|
||||||
|
path: Path,
|
||||||
|
options?: {
|
||||||
|
reverse?: boolean
|
||||||
|
}
|
||||||
|
) => Path[]
|
||||||
next: (path: Path) => Path
|
next: (path: Path) => Path
|
||||||
operationCanTransformPath: (operation: Operation) => boolean
|
operationCanTransformPath: (operation: Operation) => boolean
|
||||||
parent: (path: Path) => Path
|
parent: (path: Path) => Path
|
||||||
@@ -49,7 +41,7 @@ export interface PathInterface {
|
|||||||
transform: (
|
transform: (
|
||||||
path: Path,
|
path: Path,
|
||||||
operation: Operation,
|
operation: Operation,
|
||||||
options?: PathTransformOptions
|
options?: { affinity?: 'forward' | 'backward' | null }
|
||||||
) => Path | null
|
) => Path | null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +53,7 @@ export const Path: PathInterface = {
|
|||||||
* `reverse: true` option is passed, they are reversed.
|
* `reverse: true` option is passed, they are reversed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ancestors(path: Path, options: PathAncestorsOptions = {}): Path[] {
|
ancestors(path: Path, options: { reverse?: boolean } = {}): Path[] {
|
||||||
const { reverse = false } = options
|
const { reverse = false } = options
|
||||||
let paths = Path.levels(path, options)
|
let paths = Path.levels(path, options)
|
||||||
|
|
||||||
@@ -265,7 +257,12 @@ export const Path: PathInterface = {
|
|||||||
* true` option is passed, they are reversed.
|
* true` option is passed, they are reversed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
levels(path: Path, options: PathLevelsOptions = {}): Path[] {
|
levels(
|
||||||
|
path: Path,
|
||||||
|
options: {
|
||||||
|
reverse?: boolean
|
||||||
|
} = {}
|
||||||
|
): Path[] {
|
||||||
const { reverse = false } = options
|
const { reverse = false } = options
|
||||||
const list: Path[] = []
|
const list: Path[] = []
|
||||||
|
|
||||||
@@ -370,7 +367,7 @@ export const Path: PathInterface = {
|
|||||||
transform(
|
transform(
|
||||||
path: Path | null,
|
path: Path | null,
|
||||||
operation: Operation,
|
operation: Operation,
|
||||||
options: PathTransformOptions = {}
|
options: { affinity?: 'forward' | 'backward' | null } = {}
|
||||||
): Path | null {
|
): Path | null {
|
||||||
return produce(path, p => {
|
return produce(path, p => {
|
||||||
const { affinity = 'forward' } = options
|
const { affinity = 'forward' } = options
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
import { Operation, Point } from '..'
|
import { Operation, Point } from '..'
|
||||||
import { TextDirection } from './types'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* `PointRef` objects keep a specific point in a document synced over time as new
|
* `PointRef` objects keep a specific point in a document synced over time as new
|
||||||
@@ -9,7 +8,7 @@ import { TextDirection } from './types'
|
|||||||
|
|
||||||
export interface PointRef {
|
export interface PointRef {
|
||||||
current: Point | null
|
current: Point | null
|
||||||
affinity: TextDirection | null
|
affinity: 'forward' | 'backward' | null
|
||||||
unref(): Point | null
|
unref(): Point | null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
import { isPlainObject } from 'is-plain-object'
|
import { isPlainObject } from 'is-plain-object'
|
||||||
import { produce } from 'immer'
|
import { produce } from 'immer'
|
||||||
import { ExtendedType, Operation, Path } from '..'
|
import { ExtendedType, Operation, Path } from '..'
|
||||||
import { TextDirection } from './types'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* `Point` objects refer to a specific location in a text node in a Slate
|
* `Point` objects refer to a specific location in a text node in a Slate
|
||||||
@@ -17,10 +16,6 @@ export interface BasePoint {
|
|||||||
|
|
||||||
export type Point = ExtendedType<'Point', BasePoint>
|
export type Point = ExtendedType<'Point', BasePoint>
|
||||||
|
|
||||||
export interface PointTransformOptions {
|
|
||||||
affinity?: TextDirection | null
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PointInterface {
|
export interface PointInterface {
|
||||||
compare: (point: Point, another: Point) => -1 | 0 | 1
|
compare: (point: Point, another: Point) => -1 | 0 | 1
|
||||||
isAfter: (point: Point, another: Point) => boolean
|
isAfter: (point: Point, another: Point) => boolean
|
||||||
@@ -30,7 +25,7 @@ export interface PointInterface {
|
|||||||
transform: (
|
transform: (
|
||||||
point: Point,
|
point: Point,
|
||||||
op: Operation,
|
op: Operation,
|
||||||
options?: PointTransformOptions
|
options?: { affinity?: 'forward' | 'backward' | null }
|
||||||
) => Point | null
|
) => Point | null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,7 +93,7 @@ export const Point: PointInterface = {
|
|||||||
transform(
|
transform(
|
||||||
point: Point | null,
|
point: Point | null,
|
||||||
op: Operation,
|
op: Operation,
|
||||||
options: PointTransformOptions = {}
|
options: { affinity?: 'forward' | 'backward' | null } = {}
|
||||||
): Point | null {
|
): Point | null {
|
||||||
return produce(point, p => {
|
return produce(point, p => {
|
||||||
if (p === null) {
|
if (p === null) {
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
import { produce } from 'immer'
|
import { produce } from 'immer'
|
||||||
import { isPlainObject } from 'is-plain-object'
|
import { isPlainObject } from 'is-plain-object'
|
||||||
import { ExtendedType, Operation, Path, Point, PointEntry } from '..'
|
import { ExtendedType, Operation, Path, Point, PointEntry } from '..'
|
||||||
import { RangeDirection } from './types'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* `Range` objects are a set of points that refer to a specific span of a Slate
|
* `Range` objects are a set of points that refer to a specific span of a Slate
|
||||||
@@ -16,16 +15,13 @@ export interface BaseRange {
|
|||||||
|
|
||||||
export type Range = ExtendedType<'Range', BaseRange>
|
export type Range = ExtendedType<'Range', BaseRange>
|
||||||
|
|
||||||
export interface RangeEdgesOptions {
|
export interface RangeInterface {
|
||||||
|
edges: (
|
||||||
|
range: Range,
|
||||||
|
options?: {
|
||||||
reverse?: boolean
|
reverse?: boolean
|
||||||
}
|
}
|
||||||
|
) => [Point, Point]
|
||||||
export interface RangeTransformOptions {
|
|
||||||
affinity?: RangeDirection | null
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface RangeInterface {
|
|
||||||
edges: (range: Range, options?: RangeEdgesOptions) => [Point, Point]
|
|
||||||
end: (range: Range) => Point
|
end: (range: Range) => Point
|
||||||
equals: (range: Range, another: Range) => boolean
|
equals: (range: Range, another: Range) => boolean
|
||||||
includes: (range: Range, target: Path | Point | Range) => boolean
|
includes: (range: Range, target: Path | Point | Range) => boolean
|
||||||
@@ -40,7 +36,9 @@ export interface RangeInterface {
|
|||||||
transform: (
|
transform: (
|
||||||
range: Range,
|
range: Range,
|
||||||
op: Operation,
|
op: Operation,
|
||||||
options?: RangeTransformOptions
|
options?: {
|
||||||
|
affinity?: 'forward' | 'backward' | 'outward' | 'inward' | null
|
||||||
|
}
|
||||||
) => Range | null
|
) => Range | null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +48,12 @@ export const Range: RangeInterface = {
|
|||||||
* in the document.
|
* in the document.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
edges(range: Range, options: RangeEdgesOptions = {}): [Point, Point] {
|
edges(
|
||||||
|
range: Range,
|
||||||
|
options: {
|
||||||
|
reverse?: boolean
|
||||||
|
} = {}
|
||||||
|
): [Point, Point] {
|
||||||
const { reverse = false } = options
|
const { reverse = false } = options
|
||||||
const { anchor, focus } = range
|
const { anchor, focus } = range
|
||||||
return Range.isBackward(range) === reverse
|
return Range.isBackward(range) === reverse
|
||||||
@@ -206,7 +209,9 @@ export const Range: RangeInterface = {
|
|||||||
transform(
|
transform(
|
||||||
range: Range | null,
|
range: Range | null,
|
||||||
op: Operation,
|
op: Operation,
|
||||||
options: RangeTransformOptions = {}
|
options: {
|
||||||
|
affinity?: 'forward' | 'backward' | 'outward' | 'inward' | null
|
||||||
|
} = {}
|
||||||
): Range | null {
|
): Range | null {
|
||||||
return produce(range, r => {
|
return produce(range, r => {
|
||||||
if (r === null) {
|
if (r === null) {
|
||||||
|
@@ -15,12 +15,8 @@ export interface BaseText {
|
|||||||
|
|
||||||
export type Text = ExtendedType<'Text', BaseText>
|
export type Text = ExtendedType<'Text', BaseText>
|
||||||
|
|
||||||
export interface TextEqualsOptions {
|
|
||||||
loose?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface TextInterface {
|
export interface TextInterface {
|
||||||
equals: (text: Text, another: Text, options?: TextEqualsOptions) => boolean
|
equals: (text: Text, another: Text, options?: { loose?: boolean }) => boolean
|
||||||
isText: (value: any) => value is Text
|
isText: (value: any) => value is Text
|
||||||
isTextList: (value: any) => value is Text[]
|
isTextList: (value: any) => value is Text[]
|
||||||
isTextProps: (props: any) => props is Partial<Text>
|
isTextProps: (props: any) => props is Partial<Text>
|
||||||
@@ -35,7 +31,11 @@ export const Text: TextInterface = {
|
|||||||
* When loose is set, the text is not compared. This is
|
* When loose is set, the text is not compared. This is
|
||||||
* used to check whether sibling text nodes can be merged.
|
* used to check whether sibling text nodes can be merged.
|
||||||
*/
|
*/
|
||||||
equals(text: Text, another: Text, options: TextEqualsOptions = {}): boolean {
|
equals(
|
||||||
|
text: Text,
|
||||||
|
another: Text,
|
||||||
|
options: { loose?: boolean } = {}
|
||||||
|
): boolean {
|
||||||
const { loose = false } = options
|
const { loose = false } = options
|
||||||
|
|
||||||
function omitText(obj: Record<any, any>) {
|
function omitText(obj: Record<any, any>) {
|
||||||
|
@@ -1,19 +0,0 @@
|
|||||||
export type LeafEdge = 'start' | 'end'
|
|
||||||
|
|
||||||
export type MaximizeMode = RangeMode | 'all'
|
|
||||||
|
|
||||||
export type MoveUnit = 'offset' | 'character' | 'word' | 'line'
|
|
||||||
|
|
||||||
export type RangeDirection = TextDirection | 'outward' | 'inward'
|
|
||||||
|
|
||||||
export type RangeMode = 'highest' | 'lowest'
|
|
||||||
|
|
||||||
export type SelectionEdge = 'anchor' | 'focus' | 'start' | 'end'
|
|
||||||
|
|
||||||
export type SelectionMode = 'all' | 'highest' | 'lowest'
|
|
||||||
|
|
||||||
export type TextDirection = 'forward' | 'backward'
|
|
||||||
|
|
||||||
export type TextUnit = 'character' | 'word' | 'line' | 'block'
|
|
||||||
|
|
||||||
export type TextUnitAdjustment = TextUnit | 'offset'
|
|
@@ -13,7 +13,6 @@ import {
|
|||||||
} from '..'
|
} from '..'
|
||||||
import { NodeMatch, PropsCompare, PropsMerge } from '../interfaces/editor'
|
import { NodeMatch, PropsCompare, PropsMerge } from '../interfaces/editor'
|
||||||
import { PointRef } from '../interfaces/point-ref'
|
import { PointRef } from '../interfaces/point-ref'
|
||||||
import { RangeMode, MaximizeMode } from '../interfaces/types'
|
|
||||||
|
|
||||||
export interface NodeTransforms {
|
export interface NodeTransforms {
|
||||||
insertNodes: <T extends Node>(
|
insertNodes: <T extends Node>(
|
||||||
@@ -22,7 +21,7 @@ export interface NodeTransforms {
|
|||||||
options?: {
|
options?: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: NodeMatch<T>
|
match?: NodeMatch<T>
|
||||||
mode?: RangeMode
|
mode?: 'highest' | 'lowest'
|
||||||
hanging?: boolean
|
hanging?: boolean
|
||||||
select?: boolean
|
select?: boolean
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
@@ -33,7 +32,7 @@ export interface NodeTransforms {
|
|||||||
options?: {
|
options?: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: NodeMatch<T>
|
match?: NodeMatch<T>
|
||||||
mode?: MaximizeMode
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
}
|
}
|
||||||
) => void
|
) => void
|
||||||
@@ -42,7 +41,7 @@ export interface NodeTransforms {
|
|||||||
options?: {
|
options?: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: NodeMatch<T>
|
match?: NodeMatch<T>
|
||||||
mode?: RangeMode
|
mode?: 'highest' | 'lowest'
|
||||||
hanging?: boolean
|
hanging?: boolean
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
}
|
}
|
||||||
@@ -52,7 +51,7 @@ export interface NodeTransforms {
|
|||||||
options: {
|
options: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: NodeMatch<T>
|
match?: NodeMatch<T>
|
||||||
mode?: MaximizeMode
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
to: Path
|
to: Path
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
}
|
}
|
||||||
@@ -62,7 +61,7 @@ export interface NodeTransforms {
|
|||||||
options?: {
|
options?: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: NodeMatch<T>
|
match?: NodeMatch<T>
|
||||||
mode?: RangeMode
|
mode?: 'highest' | 'lowest'
|
||||||
hanging?: boolean
|
hanging?: boolean
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
}
|
}
|
||||||
@@ -73,7 +72,7 @@ export interface NodeTransforms {
|
|||||||
options?: {
|
options?: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: NodeMatch<T>
|
match?: NodeMatch<T>
|
||||||
mode?: MaximizeMode
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
hanging?: boolean
|
hanging?: boolean
|
||||||
split?: boolean
|
split?: boolean
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
@@ -86,7 +85,7 @@ export interface NodeTransforms {
|
|||||||
options?: {
|
options?: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: NodeMatch<T>
|
match?: NodeMatch<T>
|
||||||
mode?: RangeMode
|
mode?: 'highest' | 'lowest'
|
||||||
always?: boolean
|
always?: boolean
|
||||||
height?: number
|
height?: number
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
@@ -98,7 +97,7 @@ export interface NodeTransforms {
|
|||||||
options?: {
|
options?: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: NodeMatch<T>
|
match?: NodeMatch<T>
|
||||||
mode?: MaximizeMode
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
split?: boolean
|
split?: boolean
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
}
|
}
|
||||||
@@ -108,7 +107,7 @@ export interface NodeTransforms {
|
|||||||
options?: {
|
options?: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: NodeMatch<T>
|
match?: NodeMatch<T>
|
||||||
mode?: MaximizeMode
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
split?: boolean
|
split?: boolean
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
}
|
}
|
||||||
@@ -119,7 +118,7 @@ export interface NodeTransforms {
|
|||||||
options?: {
|
options?: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: NodeMatch<T>
|
match?: NodeMatch<T>
|
||||||
mode?: MaximizeMode
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
split?: boolean
|
split?: boolean
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
}
|
}
|
||||||
@@ -137,7 +136,7 @@ export const NodeTransforms: NodeTransforms = {
|
|||||||
options: {
|
options: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: NodeMatch<T>
|
match?: NodeMatch<T>
|
||||||
mode?: RangeMode
|
mode?: 'highest' | 'lowest'
|
||||||
hanging?: boolean
|
hanging?: boolean
|
||||||
select?: boolean
|
select?: boolean
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
@@ -256,7 +255,7 @@ export const NodeTransforms: NodeTransforms = {
|
|||||||
options: {
|
options: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: NodeMatch<T>
|
match?: NodeMatch<T>
|
||||||
mode?: MaximizeMode
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
} = {}
|
} = {}
|
||||||
): void {
|
): void {
|
||||||
@@ -320,7 +319,7 @@ export const NodeTransforms: NodeTransforms = {
|
|||||||
options: {
|
options: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: NodeMatch<T>
|
match?: NodeMatch<T>
|
||||||
mode?: RangeMode
|
mode?: 'highest' | 'lowest'
|
||||||
hanging?: boolean
|
hanging?: boolean
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
} = {}
|
} = {}
|
||||||
@@ -460,7 +459,7 @@ export const NodeTransforms: NodeTransforms = {
|
|||||||
options: {
|
options: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: NodeMatch<T>
|
match?: NodeMatch<T>
|
||||||
mode?: MaximizeMode
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
to: Path
|
to: Path
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
}
|
}
|
||||||
@@ -521,7 +520,7 @@ export const NodeTransforms: NodeTransforms = {
|
|||||||
options: {
|
options: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: NodeMatch<T>
|
match?: NodeMatch<T>
|
||||||
mode?: RangeMode
|
mode?: 'highest' | 'lowest'
|
||||||
hanging?: boolean
|
hanging?: boolean
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
} = {}
|
} = {}
|
||||||
@@ -568,7 +567,7 @@ export const NodeTransforms: NodeTransforms = {
|
|||||||
options: {
|
options: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: NodeMatch<T>
|
match?: NodeMatch<T>
|
||||||
mode?: MaximizeMode
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
hanging?: boolean
|
hanging?: boolean
|
||||||
split?: boolean
|
split?: boolean
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
@@ -693,7 +692,7 @@ export const NodeTransforms: NodeTransforms = {
|
|||||||
options: {
|
options: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: NodeMatch<T>
|
match?: NodeMatch<T>
|
||||||
mode?: RangeMode
|
mode?: 'highest' | 'lowest'
|
||||||
always?: boolean
|
always?: boolean
|
||||||
height?: number
|
height?: number
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
@@ -822,7 +821,7 @@ export const NodeTransforms: NodeTransforms = {
|
|||||||
options: {
|
options: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: NodeMatch<T>
|
match?: NodeMatch<T>
|
||||||
mode?: MaximizeMode
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
split?: boolean
|
split?: boolean
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
} = {}
|
} = {}
|
||||||
@@ -850,7 +849,7 @@ export const NodeTransforms: NodeTransforms = {
|
|||||||
options: {
|
options: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: NodeMatch<T>
|
match?: NodeMatch<T>
|
||||||
mode?: MaximizeMode
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
split?: boolean
|
split?: boolean
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
} = {}
|
} = {}
|
||||||
@@ -916,7 +915,7 @@ export const NodeTransforms: NodeTransforms = {
|
|||||||
options: {
|
options: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: NodeMatch<T>
|
match?: NodeMatch<T>
|
||||||
mode?: MaximizeMode
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
split?: boolean
|
split?: boolean
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
} = {}
|
} = {}
|
||||||
|
@@ -1,30 +1,29 @@
|
|||||||
import { Editor, Location, Point, Range, Transforms } from '..'
|
import { Editor, Location, Point, Range, Transforms } from '..'
|
||||||
import { SelectionEdge, MoveUnit } from '../interfaces/types'
|
|
||||||
|
|
||||||
export interface SelectionCollapseOptions {
|
|
||||||
edge?: SelectionEdge
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SelectionMoveOptions {
|
|
||||||
distance?: number
|
|
||||||
unit?: MoveUnit
|
|
||||||
reverse?: boolean
|
|
||||||
edge?: SelectionEdge
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SelectionSetPointOptions {
|
|
||||||
edge?: SelectionEdge
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SelectionTransforms {
|
export interface SelectionTransforms {
|
||||||
collapse: (editor: Editor, options?: SelectionCollapseOptions) => void
|
collapse: (
|
||||||
|
editor: Editor,
|
||||||
|
options?: {
|
||||||
|
edge?: 'anchor' | 'focus' | 'start' | 'end'
|
||||||
|
}
|
||||||
|
) => void
|
||||||
deselect: (editor: Editor) => void
|
deselect: (editor: Editor) => void
|
||||||
move: (editor: Editor, options?: SelectionMoveOptions) => void
|
move: (
|
||||||
|
editor: Editor,
|
||||||
|
options?: {
|
||||||
|
distance?: number
|
||||||
|
unit?: 'offset' | 'character' | 'word' | 'line'
|
||||||
|
reverse?: boolean
|
||||||
|
edge?: 'anchor' | 'focus' | 'start' | 'end'
|
||||||
|
}
|
||||||
|
) => void
|
||||||
select: (editor: Editor, target: Location) => void
|
select: (editor: Editor, target: Location) => void
|
||||||
setPoint: (
|
setPoint: (
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
props: Partial<Point>,
|
props: Partial<Point>,
|
||||||
options?: SelectionSetPointOptions
|
options?: {
|
||||||
|
edge?: 'anchor' | 'focus' | 'start' | 'end'
|
||||||
|
}
|
||||||
) => void
|
) => void
|
||||||
setSelection: (editor: Editor, props: Partial<Range>) => void
|
setSelection: (editor: Editor, props: Partial<Range>) => void
|
||||||
}
|
}
|
||||||
@@ -34,7 +33,12 @@ export const SelectionTransforms: SelectionTransforms = {
|
|||||||
* Collapse the selection.
|
* Collapse the selection.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
collapse(editor: Editor, options: SelectionCollapseOptions = {}): void {
|
collapse(
|
||||||
|
editor: Editor,
|
||||||
|
options: {
|
||||||
|
edge?: 'anchor' | 'focus' | 'start' | 'end'
|
||||||
|
} = {}
|
||||||
|
): void {
|
||||||
const { edge = 'anchor' } = options
|
const { edge = 'anchor' } = options
|
||||||
const { selection } = editor
|
const { selection } = editor
|
||||||
|
|
||||||
@@ -73,7 +77,15 @@ export const SelectionTransforms: SelectionTransforms = {
|
|||||||
* Move the selection's point forward or backward.
|
* Move the selection's point forward or backward.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
move(editor: Editor, options: SelectionMoveOptions = {}): void {
|
move(
|
||||||
|
editor: Editor,
|
||||||
|
options: {
|
||||||
|
distance?: number
|
||||||
|
unit?: 'offset' | 'character' | 'word' | 'line'
|
||||||
|
reverse?: boolean
|
||||||
|
edge?: 'anchor' | 'focus' | 'start' | 'end'
|
||||||
|
} = {}
|
||||||
|
): void {
|
||||||
const { selection } = editor
|
const { selection } = editor
|
||||||
const { distance = 1, unit = 'character', reverse = false } = options
|
const { distance = 1, unit = 'character', reverse = false } = options
|
||||||
let { edge = null } = options
|
let { edge = null } = options
|
||||||
@@ -152,7 +164,9 @@ export const SelectionTransforms: SelectionTransforms = {
|
|||||||
setPoint(
|
setPoint(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
props: Partial<Point>,
|
props: Partial<Point>,
|
||||||
options: SelectionSetPointOptions = {}
|
options: {
|
||||||
|
edge?: 'anchor' | 'focus' | 'start' | 'end'
|
||||||
|
} = {}
|
||||||
): void {
|
): void {
|
||||||
const { selection } = editor
|
const { selection } = editor
|
||||||
let { edge = 'both' } = options
|
let { edge = 'both' } = options
|
||||||
|
@@ -10,39 +10,35 @@ import {
|
|||||||
Range,
|
Range,
|
||||||
Transforms,
|
Transforms,
|
||||||
} from '..'
|
} from '..'
|
||||||
import { TextUnit } from '../interfaces/types'
|
|
||||||
|
|
||||||
export interface TextDeleteOptions {
|
export interface TextTransforms {
|
||||||
|
delete: (
|
||||||
|
editor: Editor,
|
||||||
|
options?: {
|
||||||
at?: Location
|
at?: Location
|
||||||
distance?: number
|
distance?: number
|
||||||
unit?: TextUnit
|
unit?: 'character' | 'word' | 'line' | 'block'
|
||||||
reverse?: boolean
|
reverse?: boolean
|
||||||
hanging?: boolean
|
hanging?: boolean
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
}
|
}
|
||||||
|
) => void
|
||||||
export interface TextInsertFragmentOptions {
|
insertFragment: (
|
||||||
|
editor: Editor,
|
||||||
|
fragment: Node[],
|
||||||
|
options?: {
|
||||||
at?: Location
|
at?: Location
|
||||||
hanging?: boolean
|
hanging?: boolean
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TextInsertTextOptions {
|
|
||||||
at?: Location
|
|
||||||
voids?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface TextTransforms {
|
|
||||||
delete: (editor: Editor, options?: TextDeleteOptions) => void
|
|
||||||
insertFragment: (
|
|
||||||
editor: Editor,
|
|
||||||
fragment: Node[],
|
|
||||||
options?: TextInsertFragmentOptions
|
|
||||||
) => void
|
) => void
|
||||||
insertText: (
|
insertText: (
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
text: string,
|
text: string,
|
||||||
options?: TextInsertTextOptions
|
options?: {
|
||||||
|
at?: Location
|
||||||
|
voids?: boolean
|
||||||
|
}
|
||||||
) => void
|
) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +47,17 @@ export const TextTransforms: TextTransforms = {
|
|||||||
* Delete content in the editor.
|
* Delete content in the editor.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
delete(editor: Editor, options: TextDeleteOptions = {}): void {
|
delete(
|
||||||
|
editor: Editor,
|
||||||
|
options: {
|
||||||
|
at?: Location
|
||||||
|
distance?: number
|
||||||
|
unit?: 'character' | 'word' | 'line' | 'block'
|
||||||
|
reverse?: boolean
|
||||||
|
hanging?: boolean
|
||||||
|
voids?: boolean
|
||||||
|
} = {}
|
||||||
|
): void {
|
||||||
Editor.withoutNormalizing(editor, () => {
|
Editor.withoutNormalizing(editor, () => {
|
||||||
const {
|
const {
|
||||||
reverse = false,
|
reverse = false,
|
||||||
@@ -225,7 +231,11 @@ export const TextTransforms: TextTransforms = {
|
|||||||
insertFragment(
|
insertFragment(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
fragment: Node[],
|
fragment: Node[],
|
||||||
options: TextInsertFragmentOptions = {}
|
options: {
|
||||||
|
at?: Location
|
||||||
|
hanging?: boolean
|
||||||
|
voids?: boolean
|
||||||
|
} = {}
|
||||||
): void {
|
): void {
|
||||||
Editor.withoutNormalizing(editor, () => {
|
Editor.withoutNormalizing(editor, () => {
|
||||||
const { hanging = false, voids = false } = options
|
const { hanging = false, voids = false } = options
|
||||||
@@ -452,7 +462,10 @@ export const TextTransforms: TextTransforms = {
|
|||||||
insertText(
|
insertText(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
text: string,
|
text: string,
|
||||||
options: TextInsertTextOptions = {}
|
options: {
|
||||||
|
at?: Location
|
||||||
|
voids?: boolean
|
||||||
|
} = {}
|
||||||
): void {
|
): void {
|
||||||
Editor.withoutNormalizing(editor, () => {
|
Editor.withoutNormalizing(editor, () => {
|
||||||
const { voids = false } = options
|
const { voids = false } = options
|
||||||
|
Reference in New Issue
Block a user