@thomasfosterau/effect-richtext 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +48 -0
- package/README.md +118 -2
- package/dist/_virtual/_rolldown/runtime.js +12 -0
- package/dist/commands/commands.d.ts +323 -0
- package/dist/commands/commands.js +722 -0
- package/dist/commands/internal.js +43 -0
- package/dist/commands/keymaps.d.ts +46 -0
- package/dist/commands/keymaps.js +64 -0
- package/dist/commands.d.ts +3 -0
- package/dist/commands.js +3 -0
- package/dist/compat/commands.d.ts +250 -0
- package/dist/compat/commands.js +275 -0
- package/dist/compat/internal/core.d.ts +20 -0
- package/dist/compat/internal/core.js +148 -0
- package/dist/compat/internal/props.js +82 -0
- package/dist/compat/keymap.d.ts +21 -0
- package/dist/compat/keymap.js +38 -0
- package/dist/compat/model.d.ts +893 -0
- package/dist/compat/model.js +1212 -0
- package/dist/compat/orderedmap.d.ts +74 -0
- package/dist/compat/orderedmap.js +124 -0
- package/dist/compat/schema-basic.d.ts +38 -0
- package/dist/compat/schema-basic.js +238 -0
- package/dist/compat/schema-list.d.ts +81 -0
- package/dist/compat/schema-list.js +156 -0
- package/dist/compat/state.d.ts +415 -0
- package/dist/compat/state.js +689 -0
- package/dist/compat/test-builder.d.ts +98 -0
- package/dist/compat/test-builder.js +197 -0
- package/dist/compat/transform.d.ts +458 -0
- package/dist/compat/transform.js +803 -0
- package/dist/compat/view.d.ts +411 -0
- package/dist/compat/view.js +409 -0
- package/dist/dropcursor.d.ts +46 -0
- package/dist/dropcursor.js +176 -0
- package/dist/extensions/defaults.d.ts +716 -0
- package/dist/extensions/defaults.js +209 -0
- package/dist/extensions/editor.d.ts +246 -0
- package/dist/extensions/editor.js +271 -0
- package/dist/extensions/extension.d.ts +375 -0
- package/dist/extensions/extension.js +233 -0
- package/dist/extensions.d.ts +4 -0
- package/dist/extensions.js +4 -0
- package/dist/gapcursor.d.ts +66 -0
- package/dist/gapcursor.js +273 -0
- package/dist/history.d.ts +178 -0
- package/dist/history.js +412 -0
- package/dist/html.d.ts +158 -0
- package/dist/html.js +164 -0
- package/dist/inputrules.d.ts +271 -0
- package/dist/inputrules.js +321 -0
- package/dist/internal/attempt.js +15 -0
- package/dist/internal/json.js +29 -0
- package/dist/keymap/keymap.d.ts +130 -0
- package/dist/keymap/keymap.js +159 -0
- package/dist/keymap.d.ts +2 -0
- package/dist/keymap.js +1 -0
- package/dist/markdown/errors.d.ts +23 -0
- package/dist/markdown/errors.js +26 -0
- package/dist/markdown/from_markdown.d.ts +185 -0
- package/dist/markdown/from_markdown.js +266 -0
- package/dist/markdown/schema.d.ts +522 -0
- package/dist/markdown/schema.js +292 -0
- package/dist/markdown/to_markdown.d.ts +251 -0
- package/dist/markdown/to_markdown.js +413 -0
- package/dist/markdown.d.ts +5 -0
- package/dist/markdown.js +5 -0
- package/dist/model/attrsCodec.js +48 -0
- package/dist/model/comparedeep.js +17 -0
- package/dist/model/content.d.ts +232 -0
- package/dist/model/content.js +630 -0
- package/dist/model/diff.js +66 -0
- package/dist/model/dom.d.ts +3 -0
- package/dist/model/errors.d.ts +90 -0
- package/dist/model/errors.js +76 -0
- package/dist/model/fragment.d.ts +131 -0
- package/dist/model/fragment.js +262 -0
- package/dist/model/from_dom.d.ts +299 -0
- package/dist/model/from_dom.js +618 -0
- package/dist/model/json.d.ts +37 -0
- package/dist/model/json.js +126 -0
- package/dist/model/mark.d.ts +73 -0
- package/dist/model/mark.js +121 -0
- package/dist/model/node.d.ts +267 -0
- package/dist/model/node.js +434 -0
- package/dist/model/replace.d.ts +78 -0
- package/dist/model/replace.js +207 -0
- package/dist/model/resolvedpos.d.ts +196 -0
- package/dist/model/resolvedpos.js +305 -0
- package/dist/model/schema.d.ts +740 -0
- package/dist/model/schema.js +451 -0
- package/dist/model/to_dom.d.ts +169 -0
- package/dist/model/to_dom.js +238 -0
- package/dist/model.d.ts +12 -0
- package/dist/model.js +12 -0
- package/dist/placeholder.d.ts +53 -0
- package/dist/placeholder.js +79 -0
- package/dist/reactive/observer.d.ts +54 -0
- package/dist/reactive/observer.js +61 -0
- package/dist/reactive/selectors.d.ts +22 -0
- package/dist/reactive/selectors.js +61 -0
- package/dist/reactive/stateref.d.ts +72 -0
- package/dist/reactive/stateref.js +71 -0
- package/dist/reactive/streams.d.ts +83 -0
- package/dist/reactive/streams.js +85 -0
- package/dist/reactive.d.ts +16 -0
- package/dist/reactive.js +26 -0
- package/dist/schema-basic.d.ts +448 -0
- package/dist/schema-basic.js +269 -0
- package/dist/schema-list/commands.d.ts +66 -0
- package/dist/schema-list/commands.js +203 -0
- package/dist/schema-list.d.ts +92 -0
- package/dist/schema-list.js +100 -0
- package/dist/state/errors.d.ts +39 -0
- package/dist/state/errors.js +32 -0
- package/dist/state/plugin.d.ts +232 -0
- package/dist/state/plugin.js +82 -0
- package/dist/state/selection.d.ts +297 -0
- package/dist/state/selection.js +486 -0
- package/dist/state/state.d.ts +212 -0
- package/dist/state/state.js +489 -0
- package/dist/state/transaction.d.ts +145 -0
- package/dist/state/transaction.js +195 -0
- package/dist/state.d.ts +6 -0
- package/dist/state.js +6 -0
- package/dist/test-builder.d.ts +3582 -0
- package/dist/test-builder.js +239 -0
- package/dist/transform/attr_step.d.ts +60 -0
- package/dist/transform/attr_step.js +105 -0
- package/dist/transform/errors.d.ts +50 -0
- package/dist/transform/errors.js +35 -0
- package/dist/transform/map.d.ts +182 -0
- package/dist/transform/map.js +280 -0
- package/dist/transform/mark.js +98 -0
- package/dist/transform/mark_set_step.js +69 -0
- package/dist/transform/mark_step.d.ts +113 -0
- package/dist/transform/mark_step.js +225 -0
- package/dist/transform/replace.d.ts +18 -0
- package/dist/transform/replace.js +381 -0
- package/dist/transform/replace_step.d.ts +109 -0
- package/dist/transform/replace_step.js +175 -0
- package/dist/transform/step.d.ts +157 -0
- package/dist/transform/step.js +168 -0
- package/dist/transform/structure.d.ts +89 -0
- package/dist/transform/structure.js +350 -0
- package/dist/transform/transform.d.ts +248 -0
- package/dist/transform/transform.js +373 -0
- package/dist/transform.d.ts +10 -0
- package/dist/transform.js +10 -0
- package/dist/view/browser.js +39 -0
- package/dist/view/capturekeys.js +282 -0
- package/dist/view/clipboard.d.ts +8 -0
- package/dist/view/clipboard.js +245 -0
- package/dist/view/decoration.d.ts +339 -0
- package/dist/view/decoration.js +566 -0
- package/dist/view/dom.d.ts +18 -0
- package/dist/view/dom.js +140 -0
- package/dist/view/domchange.js +295 -0
- package/dist/view/domcoords.d.ts +22 -0
- package/dist/view/domcoords.js +448 -0
- package/dist/view/domobserver.d.ts +47 -0
- package/dist/view/domobserver.js +328 -0
- package/dist/view/errors.d.ts +18 -0
- package/dist/view/errors.js +21 -0
- package/dist/view/input.d.ts +58 -0
- package/dist/view/input.js +704 -0
- package/dist/view/selection.js +198 -0
- package/dist/view/view.d.ts +699 -0
- package/dist/view/view.js +623 -0
- package/dist/view/viewdesc.d.ts +236 -0
- package/dist/view/viewdesc.js +1205 -0
- package/dist/view-css.d.ts +43 -0
- package/dist/view-css.js +124 -0
- package/dist/view.d.ts +6 -0
- package/dist/view.js +4 -0
- package/package.json +206 -3
|
@@ -0,0 +1,699 @@
|
|
|
1
|
+
import { ResolvedPos } from "../model/resolvedpos.js";
|
|
2
|
+
import { Slice } from "../model/replace.js";
|
|
3
|
+
import { DOMParser } from "../model/from_dom.js";
|
|
4
|
+
import { DOMSerializer } from "../model/to_dom.js";
|
|
5
|
+
import { AnySchema, MarkNames, NodeNames } from "../model/schema.js";
|
|
6
|
+
import { Mark } from "../model/mark.js";
|
|
7
|
+
import { Node } from "../model/node.js";
|
|
8
|
+
import "../model.js";
|
|
9
|
+
import { StateFailure } from "../state/errors.js";
|
|
10
|
+
import "../state.js";
|
|
11
|
+
import { parseFromClipboard } from "./clipboard.js";
|
|
12
|
+
import { Decoration, DecorationSource } from "./decoration.js";
|
|
13
|
+
import { DOMNode, DOMSelection, DOMSelectionRange } from "./dom.js";
|
|
14
|
+
import { Rect, TextblockDir } from "./domcoords.js";
|
|
15
|
+
import { DOMObserver } from "./domobserver.js";
|
|
16
|
+
import { ViewError } from "./errors.js";
|
|
17
|
+
import { InputState, endComposition } from "./input.js";
|
|
18
|
+
import { Transaction } from "../state/transaction.js";
|
|
19
|
+
import { Selection } from "../state/selection.js";
|
|
20
|
+
import { EditorState } from "../state/state.js";
|
|
21
|
+
import { Plugin } from "../state/plugin.js";
|
|
22
|
+
import { MarkViewConstructor, NodeViewConstructor, NodeViewDesc, ViewDesc } from "./viewdesc.js";
|
|
23
|
+
import * as Effect from "effect/Effect";
|
|
24
|
+
import * as Option from "effect/Option";
|
|
25
|
+
import * as Cause from "effect/Cause";
|
|
26
|
+
import * as Exit from "effect/Exit";
|
|
27
|
+
import * as Context from "effect/Context";
|
|
28
|
+
import * as Scope from "effect/Scope";
|
|
29
|
+
/** @internal */
|
|
30
|
+
export declare const __parseFromClipboard: typeof parseFromClipboard;
|
|
31
|
+
/** @internal */
|
|
32
|
+
export declare const __endComposition: typeof endComposition;
|
|
33
|
+
/**
|
|
34
|
+
* The value an event-handling prop may return: `true` when it handled
|
|
35
|
+
* the event, `false`/`undefined` when it didn't, or an `Effect` that
|
|
36
|
+
* produces that boolean.
|
|
37
|
+
*
|
|
38
|
+
* Effects are run with the context captured when the view was created.
|
|
39
|
+
* When the effect completes synchronously, its result is used exactly
|
|
40
|
+
* like a plain boolean. When it suspends (is asynchronous), the event is
|
|
41
|
+
* treated as handled (`true`) and the effect keeps running in the
|
|
42
|
+
* background. Failures are reported to the view's `onError` prop and
|
|
43
|
+
* treated as "not handled".
|
|
44
|
+
*
|
|
45
|
+
* @since 0.1.0
|
|
46
|
+
* @category models
|
|
47
|
+
*/
|
|
48
|
+
export type HandlerResult<R = never, E = never> = boolean | void | Effect.Effect<boolean, E, R>;
|
|
49
|
+
/**
|
|
50
|
+
* Helper type that maps event names to event object types, but includes
|
|
51
|
+
* events that TypeScript's `HTMLElementEventMap` doesn't know about.
|
|
52
|
+
*
|
|
53
|
+
* @since 0.1.0
|
|
54
|
+
* @category models
|
|
55
|
+
*/
|
|
56
|
+
export interface DOMEventMap extends HTMLElementEventMap {
|
|
57
|
+
[event: string]: any;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Node view constructors, keyed (and typed) by node name.
|
|
61
|
+
*
|
|
62
|
+
* @since 0.1.0
|
|
63
|
+
* @category models
|
|
64
|
+
*/
|
|
65
|
+
export type NodeViews<Sc extends AnySchema = AnySchema> = { readonly [N in NodeNames<Sc>]?: NodeViewConstructor<Sc, N> | undefined; };
|
|
66
|
+
/**
|
|
67
|
+
* Mark view constructors, keyed (and typed) by mark name.
|
|
68
|
+
*
|
|
69
|
+
* @since 0.1.0
|
|
70
|
+
* @category models
|
|
71
|
+
*/
|
|
72
|
+
export type MarkViews<Sc extends AnySchema = AnySchema> = { readonly [M in MarkNames<Sc>]?: MarkViewConstructor<Sc, M> | undefined; };
|
|
73
|
+
/**
|
|
74
|
+
* Something that can serialize a fragment for the clipboard (usually a
|
|
75
|
+
* `DOMSerializer`).
|
|
76
|
+
*
|
|
77
|
+
* @since 0.1.0
|
|
78
|
+
* @category models
|
|
79
|
+
*/
|
|
80
|
+
export type ClipboardSerializer<Sc extends AnySchema = AnySchema> = Pick<DOMSerializer<Sc>, "serializeFragment">;
|
|
81
|
+
/**
|
|
82
|
+
* Props are configuration values that can be passed to an editor view
|
|
83
|
+
* or included in a plugin. This interface lists the supported props.
|
|
84
|
+
*
|
|
85
|
+
* The various event-handling functions may all return `true` to
|
|
86
|
+
* indicate that they handled the given event, or an `Effect` producing
|
|
87
|
+
* that boolean (see `HandlerResult`). The view will then take care to
|
|
88
|
+
* call `preventDefault` on the event, except with `handleDOMEvents`,
|
|
89
|
+
* where the handler itself is responsible for that.
|
|
90
|
+
*
|
|
91
|
+
* How a prop is resolved depends on the prop. Handler functions are
|
|
92
|
+
* called one at a time, starting with the base props and then searching
|
|
93
|
+
* through the plugins (in order of appearance) until one of them returns
|
|
94
|
+
* true. For some props, the first plugin that yields a value gets
|
|
95
|
+
* precedence.
|
|
96
|
+
*
|
|
97
|
+
* The view passed to props is typed `EditorView<Sc, any, any>`:
|
|
98
|
+
* handler effects run with the view's captured context anyway.
|
|
99
|
+
*
|
|
100
|
+
* The optional `P` type parameter refers to the type of `this` in prop
|
|
101
|
+
* functions, and is used to pass in the plugin type when defining a
|
|
102
|
+
* plugin.
|
|
103
|
+
*
|
|
104
|
+
* @since 0.1.0
|
|
105
|
+
* @category models
|
|
106
|
+
*/
|
|
107
|
+
export interface EditorProps<Sc extends AnySchema = AnySchema, R = never, E = never, P = any> {
|
|
108
|
+
/**
|
|
109
|
+
* Can be an object mapping DOM event type names to functions that
|
|
110
|
+
* handle them. Such functions will be called before any handling the
|
|
111
|
+
* view does of events fired on the editable DOM element. Contrary to
|
|
112
|
+
* the other event handling props, when returning true from such a
|
|
113
|
+
* function, you are responsible for calling `preventDefault` yourself
|
|
114
|
+
* (or not, if you want to allow the default behavior).
|
|
115
|
+
*/
|
|
116
|
+
readonly handleDOMEvents?: { readonly [event in keyof DOMEventMap]?: ((this: P, view: EditorView<Sc, any, any>, event: DOMEventMap[event]) => HandlerResult<R, E>) | undefined; } | undefined;
|
|
117
|
+
/** Called when the editor receives a `keydown` event. */
|
|
118
|
+
readonly handleKeyDown?: ((this: P, view: EditorView<Sc, any, any>, event: KeyboardEvent) => HandlerResult<R, E>) | undefined;
|
|
119
|
+
/** Handler for `keypress` events. */
|
|
120
|
+
readonly handleKeyPress?: ((this: P, view: EditorView<Sc, any, any>, event: KeyboardEvent) => HandlerResult<R, E>) | undefined;
|
|
121
|
+
/**
|
|
122
|
+
* Whenever the user directly input text, this handler is called before
|
|
123
|
+
* the input is applied. If it returns `true`, the default behavior of
|
|
124
|
+
* actually inserting the text is suppressed.
|
|
125
|
+
*/
|
|
126
|
+
readonly handleTextInput?: ((this: P, view: EditorView<Sc, any, any>, from: number, to: number, text: string, deflt: () => Transaction<Sc>) => HandlerResult<R, E>) | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* Called for each node around a click, from the inside out. The
|
|
129
|
+
* `direct` flag will be true for the inner node.
|
|
130
|
+
*/
|
|
131
|
+
readonly handleClickOn?: ((this: P, view: EditorView<Sc, any, any>, pos: number, node: Node<Sc>, nodePos: number, event: MouseEvent, direct: boolean) => HandlerResult<R, E>) | undefined;
|
|
132
|
+
/** Called when the editor is clicked, after `handleClickOn` handlers have been called. */
|
|
133
|
+
readonly handleClick?: ((this: P, view: EditorView<Sc, any, any>, pos: number, event: MouseEvent) => HandlerResult<R, E>) | undefined;
|
|
134
|
+
/** Called for each node around a double click. */
|
|
135
|
+
readonly handleDoubleClickOn?: ((this: P, view: EditorView<Sc, any, any>, pos: number, node: Node<Sc>, nodePos: number, event: MouseEvent, direct: boolean) => HandlerResult<R, E>) | undefined;
|
|
136
|
+
/** Called when the editor is double-clicked, after `handleDoubleClickOn`. */
|
|
137
|
+
readonly handleDoubleClick?: ((this: P, view: EditorView<Sc, any, any>, pos: number, event: MouseEvent) => HandlerResult<R, E>) | undefined;
|
|
138
|
+
/** Called for each node around a triple click. */
|
|
139
|
+
readonly handleTripleClickOn?: ((this: P, view: EditorView<Sc, any, any>, pos: number, node: Node<Sc>, nodePos: number, event: MouseEvent, direct: boolean) => HandlerResult<R, E>) | undefined;
|
|
140
|
+
/** Called when the editor is triple-clicked, after `handleTripleClickOn`. */
|
|
141
|
+
readonly handleTripleClick?: ((this: P, view: EditorView<Sc, any, any>, pos: number, event: MouseEvent) => HandlerResult<R, E>) | undefined;
|
|
142
|
+
/**
|
|
143
|
+
* Can be used to override the behavior of pasting. `slice` is the
|
|
144
|
+
* pasted content parsed by the editor, but you can directly access the
|
|
145
|
+
* event to get at the raw content.
|
|
146
|
+
*/
|
|
147
|
+
readonly handlePaste?: ((this: P, view: EditorView<Sc, any, any>, event: ClipboardEvent, slice: Slice<Sc>) => HandlerResult<R, E>) | undefined;
|
|
148
|
+
/**
|
|
149
|
+
* Called when something is dropped on the editor. `moved` will be true
|
|
150
|
+
* if this drop moves from the current selection (which should thus be
|
|
151
|
+
* deleted).
|
|
152
|
+
*/
|
|
153
|
+
readonly handleDrop?: ((this: P, view: EditorView<Sc, any, any>, event: DragEvent, slice: Slice<Sc>, moved: boolean) => HandlerResult<R, E>) | undefined;
|
|
154
|
+
/**
|
|
155
|
+
* Called when the view, after updating its state, tries to scroll the
|
|
156
|
+
* selection into view. A handler function may return false to indicate
|
|
157
|
+
* that it did not handle the scrolling and further handlers or the
|
|
158
|
+
* default behavior should be tried.
|
|
159
|
+
*/
|
|
160
|
+
readonly handleScrollToSelection?: ((this: P, view: EditorView<Sc, any, any>) => HandlerResult<R, E>) | undefined;
|
|
161
|
+
/**
|
|
162
|
+
* Determines whether an in-editor drag event should copy or move the
|
|
163
|
+
* selection. When not given, the event's `altKey` property is used on
|
|
164
|
+
* macOS, `ctrlKey` on other platforms.
|
|
165
|
+
*/
|
|
166
|
+
readonly dragCopies?: ((event: DragEvent) => boolean) | undefined;
|
|
167
|
+
/**
|
|
168
|
+
* Can be used to override the way a selection is created when reading
|
|
169
|
+
* a DOM selection between the given anchor and head.
|
|
170
|
+
*/
|
|
171
|
+
readonly createSelectionBetween?: ((this: P, view: EditorView<Sc, any, any>, anchor: ResolvedPos<Sc>, head: ResolvedPos<Sc>) => Selection<Sc> | null | undefined) | undefined;
|
|
172
|
+
/**
|
|
173
|
+
* The parser to use when reading editor changes from the DOM. Defaults
|
|
174
|
+
* to calling `DOMParser.fromSchema` on the editor's schema.
|
|
175
|
+
*/
|
|
176
|
+
readonly domParser?: DOMParser<Sc> | undefined;
|
|
177
|
+
/**
|
|
178
|
+
* Can be used to transform pasted HTML text, _before_ it is parsed, for
|
|
179
|
+
* example to clean it up.
|
|
180
|
+
*/
|
|
181
|
+
readonly transformPastedHTML?: ((this: P, html: string, view: EditorView<Sc, any, any>) => string) | undefined;
|
|
182
|
+
/**
|
|
183
|
+
* The parser to use when reading content from the clipboard. When not
|
|
184
|
+
* given, the value of the `domParser` prop is used.
|
|
185
|
+
*/
|
|
186
|
+
readonly clipboardParser?: DOMParser<Sc> | undefined;
|
|
187
|
+
/**
|
|
188
|
+
* Transform pasted plain text. The `plain` flag will be true when the
|
|
189
|
+
* text is pasted as plain text.
|
|
190
|
+
*/
|
|
191
|
+
readonly transformPastedText?: ((this: P, text: string, plain: boolean, view: EditorView<Sc, any, any>) => string) | undefined;
|
|
192
|
+
/**
|
|
193
|
+
* A function to parse text from the clipboard into a document slice.
|
|
194
|
+
* Called after `transformPastedText`. The default behavior is to split
|
|
195
|
+
* the text into lines, wrap them in `<p>` tags, and call
|
|
196
|
+
* `clipboardParser` on it. The `plain` flag will be true when the text
|
|
197
|
+
* is pasted as plain text.
|
|
198
|
+
*/
|
|
199
|
+
readonly clipboardTextParser?: ((this: P, text: string, $context: ResolvedPos<Sc>, plain: boolean, view: EditorView<Sc, any, any>) => Slice<Sc> | null | undefined) | undefined;
|
|
200
|
+
/**
|
|
201
|
+
* Can be used to transform pasted or dragged-and-dropped content
|
|
202
|
+
* before it is applied to the document. The `plain` flag will be true
|
|
203
|
+
* when the text is pasted as plain text.
|
|
204
|
+
*/
|
|
205
|
+
readonly transformPasted?: ((this: P, slice: Slice<Sc>, view: EditorView<Sc, any, any>, plain: boolean) => Slice<Sc>) | undefined;
|
|
206
|
+
/**
|
|
207
|
+
* Can be used to transform copied or cut content before it is
|
|
208
|
+
* serialized to the clipboard.
|
|
209
|
+
*/
|
|
210
|
+
readonly transformCopied?: ((this: P, slice: Slice<Sc>, view: EditorView<Sc, any, any>) => Slice<Sc>) | undefined;
|
|
211
|
+
/**
|
|
212
|
+
* Allows you to pass custom rendering and behavior logic for nodes.
|
|
213
|
+
* Should map node names to constructor functions that produce a
|
|
214
|
+
* `NodeView` object implementing the node's display behavior. The
|
|
215
|
+
* constructors are typed per node name, so `node.attrs` is typed.
|
|
216
|
+
*
|
|
217
|
+
* The `getPos` argument is a function that can be called to get the
|
|
218
|
+
* node's current position, which can be useful when creating
|
|
219
|
+
* transactions to update it. Note that if the node is not in the
|
|
220
|
+
* document, the position returned by this function will be
|
|
221
|
+
* `undefined`.
|
|
222
|
+
*
|
|
223
|
+
* `decorations` is an array of node or inline decorations that are
|
|
224
|
+
* active around the node. `innerDecorations` holds the decorations for
|
|
225
|
+
* the node's content.
|
|
226
|
+
*/
|
|
227
|
+
readonly nodeViews?: NodeViews<Sc> | undefined;
|
|
228
|
+
/**
|
|
229
|
+
* Pass custom mark rendering functions. Note that these cannot provide
|
|
230
|
+
* the kind of dynamic behavior that node views can—they just provide
|
|
231
|
+
* custom rendering logic. The third argument indicates whether the
|
|
232
|
+
* mark's content is inline.
|
|
233
|
+
*/
|
|
234
|
+
readonly markViews?: MarkViews<Sc> | undefined;
|
|
235
|
+
/**
|
|
236
|
+
* The DOM serializer to use when putting content onto the clipboard.
|
|
237
|
+
* If not given, the result of `DOMSerializer.fromSchema` will be used.
|
|
238
|
+
* This object will only have its `serializeFragment` method called.
|
|
239
|
+
*/
|
|
240
|
+
readonly clipboardSerializer?: ClipboardSerializer<Sc> | undefined;
|
|
241
|
+
/**
|
|
242
|
+
* A function that will be called to get the text for the current
|
|
243
|
+
* selection when copying text to the clipboard. By default, the editor
|
|
244
|
+
* will use `textBetween` on the selected range.
|
|
245
|
+
*/
|
|
246
|
+
readonly clipboardTextSerializer?: ((this: P, content: Slice<Sc>, view: EditorView<Sc, any, any>) => string) | undefined;
|
|
247
|
+
/** A set of document decorations to show in the view. */
|
|
248
|
+
readonly decorations?: ((this: P, state: EditorState<Sc>) => DecorationSource | null | undefined) | undefined;
|
|
249
|
+
/** When this returns false, the content of the view is not directly editable. */
|
|
250
|
+
readonly editable?: ((this: P, state: EditorState<Sc>) => boolean) | undefined;
|
|
251
|
+
/**
|
|
252
|
+
* Control the DOM attributes of the editable element. May be either an
|
|
253
|
+
* object or a function going from an editor state to an object. By
|
|
254
|
+
* default, the element will get a class `"ProseMirror"`, and will have
|
|
255
|
+
* its `contentEditable` attribute determined by the `editable` prop.
|
|
256
|
+
* Additional classes provided here will be added to the class. For
|
|
257
|
+
* other attributes, the value provided first (as in `someProp`) will
|
|
258
|
+
* be used.
|
|
259
|
+
*/
|
|
260
|
+
readonly attributes?: {
|
|
261
|
+
readonly [name: string]: string;
|
|
262
|
+
} | ((state: EditorState<Sc>) => {
|
|
263
|
+
readonly [name: string]: string;
|
|
264
|
+
} | null | undefined) | undefined;
|
|
265
|
+
/**
|
|
266
|
+
* Determines the distance (in pixels) between the cursor and the end
|
|
267
|
+
* of the visible viewport at which point, when scrolling the cursor
|
|
268
|
+
* into view, scrolling takes place. Defaults to 0.
|
|
269
|
+
*/
|
|
270
|
+
readonly scrollThreshold?: number | Rect | undefined;
|
|
271
|
+
/**
|
|
272
|
+
* Determines the extra space (in pixels) that is left above or below
|
|
273
|
+
* the cursor when it is scrolled into view. Defaults to 5.
|
|
274
|
+
*/
|
|
275
|
+
readonly scrollMargin?: number | Rect | undefined;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* The props object given directly to the editor view supports some
|
|
279
|
+
* fields that can't be used in plugins.
|
|
280
|
+
*
|
|
281
|
+
* @since 0.1.0
|
|
282
|
+
* @category models
|
|
283
|
+
*/
|
|
284
|
+
export interface DirectEditorProps<Sc extends AnySchema = AnySchema, R = never, E = never> extends EditorProps<Sc, R, E> {
|
|
285
|
+
/** The current state of the editor. */
|
|
286
|
+
readonly state: EditorState<Sc, R, E>;
|
|
287
|
+
/**
|
|
288
|
+
* A set of plugins to use in the view, applying their plugin view and
|
|
289
|
+
* props. Passing plugins with a state component (a state field or a
|
|
290
|
+
* transaction filter or appender) will result in an error (a defect),
|
|
291
|
+
* since such plugins must be present in the state to work.
|
|
292
|
+
*/
|
|
293
|
+
readonly plugins?: ReadonlyArray<Plugin<any, any, E, R>> | undefined;
|
|
294
|
+
/**
|
|
295
|
+
* The callback over which to send transactions (state updates)
|
|
296
|
+
* produced by the view. If you specify this, you probably want to make
|
|
297
|
+
* sure this ends up calling the view's `updateState` method with a new
|
|
298
|
+
* state that has the transaction applied. The callback will be bound
|
|
299
|
+
* to have the view instance as its `this` binding. It may return an
|
|
300
|
+
* `Effect`, which is run with the view's captured context.
|
|
301
|
+
*/
|
|
302
|
+
readonly dispatchTransaction?: ((tr: Transaction<Sc>) => void | Effect.Effect<void, E, R>) | undefined;
|
|
303
|
+
/**
|
|
304
|
+
* Called with the cause of failures of effects run by the view on
|
|
305
|
+
* behalf of DOM events: event handler effects, dispatched
|
|
306
|
+
* transactions (including failing plugin hooks) and
|
|
307
|
+
* `dispatchTransaction` effects. Defaults to logging the cause with
|
|
308
|
+
* `Effect.logError` (run with the view's captured context).
|
|
309
|
+
*/
|
|
310
|
+
readonly onError?: ((cause: Cause.Cause<unknown>) => void) | undefined;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Describes a state update of an editor view, as passed to the listeners
|
|
314
|
+
* registered with `EditorView.subscribe`.
|
|
315
|
+
*
|
|
316
|
+
* @since 0.1.0
|
|
317
|
+
* @category models
|
|
318
|
+
*/
|
|
319
|
+
export interface ViewUpdate<Sc extends AnySchema = AnySchema, R = never, E = never> {
|
|
320
|
+
/** The view's new state. */
|
|
321
|
+
readonly state: EditorState<Sc, R, E>;
|
|
322
|
+
/** The view's state before the update. */
|
|
323
|
+
readonly prevState: EditorState<Sc, R, E>;
|
|
324
|
+
/**
|
|
325
|
+
* The transactions that produced the update, when it was caused by a
|
|
326
|
+
* dispatch: the dispatched transaction followed by those appended by
|
|
327
|
+
* plugins (with a custom `dispatchTransaction` prop, only the
|
|
328
|
+
* dispatched transaction is known). Empty for updates made directly
|
|
329
|
+
* through `updateState`, `update` or `setProps`.
|
|
330
|
+
*/
|
|
331
|
+
readonly transactions: ReadonlyArray<Transaction<Sc>>;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Where to put the editor: a DOM node that the editor should be appended
|
|
335
|
+
* to, a function that will place it into the document, an object whose
|
|
336
|
+
* `mount` property holds the node to use as the document container, or
|
|
337
|
+
* `null` to not add it to the document.
|
|
338
|
+
*
|
|
339
|
+
* @since 0.1.0
|
|
340
|
+
* @category models
|
|
341
|
+
*/
|
|
342
|
+
export type ViewPlace = null | DOMNode | ((editor: HTMLElement) => void) | {
|
|
343
|
+
readonly mount: HTMLElement;
|
|
344
|
+
};
|
|
345
|
+
type NodeViewSet = {
|
|
346
|
+
[name: string]: NodeViewConstructor<any, any> | MarkViewConstructor<any, any>;
|
|
347
|
+
};
|
|
348
|
+
/**
|
|
349
|
+
* The result of `EditorView.posAtCoords`.
|
|
350
|
+
*
|
|
351
|
+
* @since 0.1.0
|
|
352
|
+
* @category models
|
|
353
|
+
*/
|
|
354
|
+
export interface PosAtCoords {
|
|
355
|
+
/** The position nearest to the coordinates. */
|
|
356
|
+
readonly pos: number;
|
|
357
|
+
/**
|
|
358
|
+
* The position of the inner node that the position falls inside of,
|
|
359
|
+
* or -1 if it is at the top level, not in any node.
|
|
360
|
+
*/
|
|
361
|
+
readonly inside: number;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* The result of `EditorView.serializeForClipboard`.
|
|
365
|
+
*
|
|
366
|
+
* @since 0.1.0
|
|
367
|
+
* @category models
|
|
368
|
+
*/
|
|
369
|
+
export interface ClipboardSerialization<Sc extends AnySchema = AnySchema> {
|
|
370
|
+
readonly dom: HTMLElement;
|
|
371
|
+
readonly text: string;
|
|
372
|
+
readonly slice: Slice<Sc>;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* @since 0.1.0
|
|
376
|
+
* @category symbols
|
|
377
|
+
*/
|
|
378
|
+
export declare const EditorViewTypeId: unique symbol;
|
|
379
|
+
/**
|
|
380
|
+
* @since 0.1.0
|
|
381
|
+
* @category symbols
|
|
382
|
+
*/
|
|
383
|
+
export type EditorViewTypeId = typeof EditorViewTypeId;
|
|
384
|
+
/**
|
|
385
|
+
* An editor view manages the DOM structure that represents an editable
|
|
386
|
+
* document. Its state and behavior are determined by its props.
|
|
387
|
+
*
|
|
388
|
+
* `R` and `E` are the requirements and errors of the effects the view
|
|
389
|
+
* runs: those of its state's plugins and of its effectful props. Create
|
|
390
|
+
* a view with `EditorView.make`, inside an Effect that provides `R` and a
|
|
391
|
+
* `Scope`: the view captures the current context to run handler effects
|
|
392
|
+
* later, and is destroyed when the scope closes.
|
|
393
|
+
*
|
|
394
|
+
* @since 0.1.0
|
|
395
|
+
* @category models
|
|
396
|
+
*/
|
|
397
|
+
export declare class EditorView<Sc extends AnySchema = AnySchema, R = never, E = never> {
|
|
398
|
+
readonly [EditorViewTypeId]: {
|
|
399
|
+
readonly _R: (_: never) => R;
|
|
400
|
+
readonly _E: (_: never) => E;
|
|
401
|
+
};
|
|
402
|
+
/** @internal */
|
|
403
|
+
_props: DirectEditorProps<Sc, R, E>;
|
|
404
|
+
private directPlugins;
|
|
405
|
+
private _root;
|
|
406
|
+
/** @internal */
|
|
407
|
+
focused: boolean;
|
|
408
|
+
/** Kludge used to work around a Chrome bug @internal */
|
|
409
|
+
trackWrites: DOMNode | null;
|
|
410
|
+
private mounted;
|
|
411
|
+
/** @internal */
|
|
412
|
+
markCursor: ReadonlyArray<Mark<any, any>> | null;
|
|
413
|
+
/** @internal */
|
|
414
|
+
cursorWrapper: {
|
|
415
|
+
dom: DOMNode;
|
|
416
|
+
deco: Decoration;
|
|
417
|
+
} | null;
|
|
418
|
+
/** @internal */
|
|
419
|
+
nodeViews: NodeViewSet;
|
|
420
|
+
/** @internal */
|
|
421
|
+
lastSelectedViewDesc: ViewDesc | undefined;
|
|
422
|
+
/** @internal */
|
|
423
|
+
docView: NodeViewDesc;
|
|
424
|
+
/** @internal */
|
|
425
|
+
input: InputState;
|
|
426
|
+
private prevDirectPlugins;
|
|
427
|
+
private pluginViews;
|
|
428
|
+
private listeners;
|
|
429
|
+
private dispatching;
|
|
430
|
+
/** @internal */
|
|
431
|
+
domObserver: DOMObserver;
|
|
432
|
+
/**
|
|
433
|
+
* Holds `true` when a hack node is needed in Firefox to prevent the
|
|
434
|
+
* space is eaten issue.
|
|
435
|
+
*
|
|
436
|
+
* @internal
|
|
437
|
+
*/
|
|
438
|
+
requiresGeckoHackNode: boolean;
|
|
439
|
+
/**
|
|
440
|
+
* The context captured when the view was created, used to run effects.
|
|
441
|
+
*
|
|
442
|
+
* @internal
|
|
443
|
+
*/
|
|
444
|
+
readonly context: Context.Context<any>;
|
|
445
|
+
private readonly runContext;
|
|
446
|
+
/** The view's current state. */
|
|
447
|
+
state: EditorState<Sc, R, E>;
|
|
448
|
+
/** @internal */
|
|
449
|
+
constructor(place: ViewPlace, props: DirectEditorProps<Sc, R, E>, context: Context.Context<R>);
|
|
450
|
+
/**
|
|
451
|
+
* Create a view inside a scope. `place` may be a DOM node that the
|
|
452
|
+
* editor should be appended to, a function that will place it into the
|
|
453
|
+
* document, or an object whose `mount` property holds the node to use
|
|
454
|
+
* as the document container. If it is `null`, the editor will not be
|
|
455
|
+
* added to the document.
|
|
456
|
+
*
|
|
457
|
+
* The view captures the current context (which must provide `R`) to
|
|
458
|
+
* run the effects of its plugins and props, and is destroyed when the
|
|
459
|
+
* scope closes.
|
|
460
|
+
*
|
|
461
|
+
* When props' handlers require services that the state's plugins
|
|
462
|
+
* don't, pass the type arguments explicitly
|
|
463
|
+
* (`EditorView.make<typeof schema, ServiceA | ServiceB>(...)`).
|
|
464
|
+
*/
|
|
465
|
+
static make<Sc extends AnySchema, R = never, E = never>(place: ViewPlace, props: DirectEditorProps<Sc, R, E>): Effect.Effect<EditorView<Sc, R, E>, never, Scope.Scope | R>;
|
|
466
|
+
/**
|
|
467
|
+
* Create a view without a scope. The caller is responsible for calling
|
|
468
|
+
* `destroy`. When `R` is not `never`, a context providing it must be
|
|
469
|
+
* passed; it is used to run the effects of plugins and props.
|
|
470
|
+
*/
|
|
471
|
+
static makeUnsafe<Sc extends AnySchema, E = never>(place: ViewPlace, props: DirectEditorProps<Sc, never, E>): EditorView<Sc, never, E>;
|
|
472
|
+
static makeUnsafe<Sc extends AnySchema, R, E = never>(place: ViewPlace, props: DirectEditorProps<Sc, R, E>, context: Context.Context<R>): EditorView<Sc, R, E>;
|
|
473
|
+
/**
|
|
474
|
+
* An editable DOM node containing the document. (You probably should
|
|
475
|
+
* not directly interfere with its content.)
|
|
476
|
+
*/
|
|
477
|
+
readonly dom: HTMLElement;
|
|
478
|
+
/** Indicates whether the editor is currently editable. */
|
|
479
|
+
editable: boolean;
|
|
480
|
+
/**
|
|
481
|
+
* When editor content is being dragged, this object contains
|
|
482
|
+
* information about the dragged slice and whether it is being copied
|
|
483
|
+
* or moved. At any other time, it is null.
|
|
484
|
+
*/
|
|
485
|
+
dragging: null | {
|
|
486
|
+
readonly slice: Slice<Sc>;
|
|
487
|
+
readonly move: boolean;
|
|
488
|
+
};
|
|
489
|
+
/** Holds `true` when a composition is active. */
|
|
490
|
+
get composing(): boolean;
|
|
491
|
+
/** The view's current props. */
|
|
492
|
+
get props(): DirectEditorProps<Sc, R, E>;
|
|
493
|
+
/** Update the view's props. Will immediately cause an update to the DOM. */
|
|
494
|
+
update(props: DirectEditorProps<Sc, R, E>): void;
|
|
495
|
+
/**
|
|
496
|
+
* Update the view by updating existing props object with the object
|
|
497
|
+
* given as argument. Equivalent to
|
|
498
|
+
* `view.update(Object.assign({}, view.props, props))`.
|
|
499
|
+
*/
|
|
500
|
+
setProps(props: Partial<DirectEditorProps<Sc, R, E>>): void;
|
|
501
|
+
/** Update the editor's `state` prop, without touching any of the other props. */
|
|
502
|
+
updateState(state: EditorState<Sc, R, E>): void;
|
|
503
|
+
private updateStateInner;
|
|
504
|
+
private notifyListeners;
|
|
505
|
+
/**
|
|
506
|
+
* Register a listener called after every state update of the view
|
|
507
|
+
* (once the DOM and plugin views have been updated). Returns a
|
|
508
|
+
* function that removes the listener. Exceptions thrown by listeners
|
|
509
|
+
* are reported to `onError`.
|
|
510
|
+
*/
|
|
511
|
+
subscribe(listener: (update: ViewUpdate<Sc, R, E>) => void): () => void;
|
|
512
|
+
private withDispatching;
|
|
513
|
+
/** @internal */
|
|
514
|
+
scrollToSelection(): void;
|
|
515
|
+
private destroyPluginViews;
|
|
516
|
+
private updatePluginViews;
|
|
517
|
+
private updateDraggedNode;
|
|
518
|
+
/**
|
|
519
|
+
* Goes over the values of a prop, first those provided directly, then
|
|
520
|
+
* those from plugins given to the view, then from plugins in the state
|
|
521
|
+
* (in order), and calls `f` every time a non-undefined value is found.
|
|
522
|
+
* When `f` returns a truthy value, that is immediately returned. When
|
|
523
|
+
* `f` isn't provided, it is treated as the identity function (the prop
|
|
524
|
+
* value is returned directly).
|
|
525
|
+
*
|
|
526
|
+
* Note that event handler props may return Effects, which are returned
|
|
527
|
+
* as-is (and are truthy).
|
|
528
|
+
*/
|
|
529
|
+
someProp<PropName extends keyof EditorProps<Sc, R, E>, Result>(propName: PropName, f: (value: NonNullable<EditorProps<Sc, R, E>[PropName]>) => Result): Result | undefined;
|
|
530
|
+
someProp<PropName extends keyof EditorProps<Sc, R, E>>(propName: PropName): NonNullable<EditorProps<Sc, R, E>[PropName]> | undefined;
|
|
531
|
+
/**
|
|
532
|
+
* Like `someProp`, but for event handler props, whose results may be
|
|
533
|
+
* Effects: those are run (see `HandlerResult`) and their results used.
|
|
534
|
+
*
|
|
535
|
+
* @internal
|
|
536
|
+
*/
|
|
537
|
+
someHandler<PropName extends keyof EditorProps<Sc, R, E>>(propName: PropName, f: (value: NonNullable<EditorProps<Sc, R, E>[PropName]>) => HandlerResult<any, any>): boolean;
|
|
538
|
+
/**
|
|
539
|
+
* Interpret the result of an event handler prop, running it with the
|
|
540
|
+
* view's context when it is an Effect.
|
|
541
|
+
*
|
|
542
|
+
* @internal
|
|
543
|
+
*/
|
|
544
|
+
runHandler(result: HandlerResult<any, any>): boolean;
|
|
545
|
+
/**
|
|
546
|
+
* Run an effect with the view's captured context. Returns its exit
|
|
547
|
+
* when it completed synchronously (reporting failures to `onError`),
|
|
548
|
+
* or `undefined` when it is still running in the background (in which
|
|
549
|
+
* case failures are reported when it completes).
|
|
550
|
+
*
|
|
551
|
+
* @internal
|
|
552
|
+
*/
|
|
553
|
+
runEffect<A>(effect: Effect.Effect<A, unknown, R>): Exit.Exit<A, unknown> | undefined;
|
|
554
|
+
/** @internal */
|
|
555
|
+
reportError(cause: Cause.Cause<unknown>): void;
|
|
556
|
+
/** Query whether the view has focus. */
|
|
557
|
+
hasFocus(): boolean;
|
|
558
|
+
/** Focus the editor. */
|
|
559
|
+
focus(): void;
|
|
560
|
+
/**
|
|
561
|
+
* Get the document root in which the editor exists. This will usually
|
|
562
|
+
* be the top-level `document`, but might be a shadow DOM root if the
|
|
563
|
+
* editor is inside one.
|
|
564
|
+
*/
|
|
565
|
+
get root(): Document | ShadowRoot;
|
|
566
|
+
/**
|
|
567
|
+
* When an existing editor view is moved to a new document or shadow
|
|
568
|
+
* tree, call this to make it recompute its root.
|
|
569
|
+
*/
|
|
570
|
+
updateRoot(): void;
|
|
571
|
+
/**
|
|
572
|
+
* Given a pair of viewport coordinates, return the document position
|
|
573
|
+
* that corresponds to them. Returns `None` if the given coordinates
|
|
574
|
+
* aren't inside of the editor.
|
|
575
|
+
*/
|
|
576
|
+
posAtCoords(coords: {
|
|
577
|
+
readonly left: number;
|
|
578
|
+
readonly top: number;
|
|
579
|
+
}): Option.Option<PosAtCoords>;
|
|
580
|
+
/**
|
|
581
|
+
* Returns the viewport rectangle at a given document position. `left`
|
|
582
|
+
* and `right` will be the same number, as this returns a flat
|
|
583
|
+
* cursor-ish rectangle. If the position is between two things that
|
|
584
|
+
* aren't directly adjacent, `side` determines which element is used.
|
|
585
|
+
* When < 0, the element before the position is used, otherwise the
|
|
586
|
+
* element after.
|
|
587
|
+
*/
|
|
588
|
+
coordsAtPos(pos: number, side?: number): Rect;
|
|
589
|
+
/**
|
|
590
|
+
* Find the DOM position that corresponds to the given document
|
|
591
|
+
* position. When `side` is negative, find the position as close as
|
|
592
|
+
* possible to the content before the position. When positive, prefer
|
|
593
|
+
* positions close to the content after the position. When zero,
|
|
594
|
+
* prefer as shallow a position as possible.
|
|
595
|
+
*
|
|
596
|
+
* Note that you should **not** mutate the editor's internal DOM, only
|
|
597
|
+
* inspect it (and even that is usually not necessary).
|
|
598
|
+
*/
|
|
599
|
+
domAtPos(pos: number, side?: number): {
|
|
600
|
+
node: DOMNode;
|
|
601
|
+
offset: number;
|
|
602
|
+
};
|
|
603
|
+
/**
|
|
604
|
+
* Find the DOM node that represents the document node after the given
|
|
605
|
+
* position. Returns `None` when the position doesn't point in front of
|
|
606
|
+
* a node or if the node is inside an opaque node view.
|
|
607
|
+
*
|
|
608
|
+
* This is intended to be able to call things like
|
|
609
|
+
* `getBoundingClientRect` on that DOM node. Do **not** mutate the
|
|
610
|
+
* editor DOM directly, or add styling this way, since that will be
|
|
611
|
+
* immediately overriden by the editor as it redraws the node.
|
|
612
|
+
*/
|
|
613
|
+
nodeDOM(pos: number): Option.Option<DOMNode>;
|
|
614
|
+
/**
|
|
615
|
+
* Find the document position that corresponds to a given DOM position.
|
|
616
|
+
* (Whenever possible, it is preferable to inspect the document
|
|
617
|
+
* structure directly, rather than poking around in the DOM, but
|
|
618
|
+
* sometimes—for example when interpreting an event target—you don't
|
|
619
|
+
* have a choice.)
|
|
620
|
+
*
|
|
621
|
+
* The `bias` parameter can be used to influence which side of a DOM
|
|
622
|
+
* node to use when the position is inside a leaf node. Fails with a
|
|
623
|
+
* `ViewError` when the DOM position is not inside the editor.
|
|
624
|
+
*/
|
|
625
|
+
posAtDOM(node: DOMNode, offset: number, bias?: number): Effect.Effect<number, ViewError>;
|
|
626
|
+
/** Like `posAtDOM`, but throws a `ViewError` when the position is not inside the editor. */
|
|
627
|
+
posAtDOMUnsafe(node: DOMNode, offset: number, bias?: number): number;
|
|
628
|
+
/**
|
|
629
|
+
* Find out whether the selection is at the end of a textblock when
|
|
630
|
+
* moving in a given direction. When, for example, given `"left"`, it
|
|
631
|
+
* will return true if moving left from the current cursor position
|
|
632
|
+
* would leave that position's parent textblock. Will apply to the
|
|
633
|
+
* view's current state by default, but it is possible to pass a
|
|
634
|
+
* different state.
|
|
635
|
+
*/
|
|
636
|
+
endOfTextblock(dir: TextblockDir, state?: EditorState<any, any, any>): boolean;
|
|
637
|
+
/**
|
|
638
|
+
* Run the editor's paste logic with the given HTML string. The
|
|
639
|
+
* `event`, if given, will be passed to the `handlePaste` hook.
|
|
640
|
+
*/
|
|
641
|
+
pasteHTML(html: string, event?: ClipboardEvent): boolean;
|
|
642
|
+
/** Run the editor's paste logic with the given plain-text input. */
|
|
643
|
+
pasteText(text: string, event?: ClipboardEvent): boolean;
|
|
644
|
+
/**
|
|
645
|
+
* Serialize the given slice as it would be if it was copied from this
|
|
646
|
+
* editor. Returns a DOM element that contains a representation of the
|
|
647
|
+
* slice as its children, a textual representation, and the
|
|
648
|
+
* transformed slice (which can be different from the given input due
|
|
649
|
+
* to hooks like `transformCopied`).
|
|
650
|
+
*/
|
|
651
|
+
serializeForClipboard(slice: Slice<Sc>): ClipboardSerialization<Sc>;
|
|
652
|
+
/** Removes the editor from the DOM and destroys all node views. */
|
|
653
|
+
destroy(): void;
|
|
654
|
+
/**
|
|
655
|
+
* This is true when the view has been destroyed (and thus should not
|
|
656
|
+
* be used anymore).
|
|
657
|
+
*/
|
|
658
|
+
get isDestroyed(): boolean;
|
|
659
|
+
/** Used for testing. */
|
|
660
|
+
dispatchEvent(event: Event): void;
|
|
661
|
+
/**
|
|
662
|
+
* Dispatch a transaction. Will call `dispatchTransaction` when given,
|
|
663
|
+
* and otherwise defaults to applying the transaction to the current
|
|
664
|
+
* state and calling `updateState` with the result.
|
|
665
|
+
*
|
|
666
|
+
* The returned effect runs with the view's captured context (so it
|
|
667
|
+
* requires nothing), and failures (of plugin hooks or of a
|
|
668
|
+
* `dispatchTransaction` effect) are reported to the `onError` prop
|
|
669
|
+
* rather than to the error channel—use `tryDispatch` to observe them.
|
|
670
|
+
* This is a bound function, usable as a command's `Dispatch`.
|
|
671
|
+
*/
|
|
672
|
+
readonly dispatch: (tr: Transaction<Sc>) => Effect.Effect<void>;
|
|
673
|
+
/**
|
|
674
|
+
* Like `dispatch`, but fails with the errors of the plugin hooks and
|
|
675
|
+
* of `dispatchTransaction` instead of reporting them to `onError`.
|
|
676
|
+
* Runs with the view's captured context.
|
|
677
|
+
*/
|
|
678
|
+
tryDispatch(tr: Transaction<Sc>): Effect.Effect<void, E | StateFailure>;
|
|
679
|
+
/**
|
|
680
|
+
* Dispatch a transaction synchronously, throwing its failure (as
|
|
681
|
+
* `tryDispatch` would fail). When the dispatch is asynchronous (a
|
|
682
|
+
* plugin hook suspends), it keeps running in the background and
|
|
683
|
+
* failures are reported to `onError`. Bound to the view instance.
|
|
684
|
+
*/
|
|
685
|
+
readonly dispatchUnsafe: (tr: Transaction<Sc>) => void;
|
|
686
|
+
/**
|
|
687
|
+
* Dispatch a transaction on behalf of a DOM event: like
|
|
688
|
+
* `dispatchUnsafe`, but failures are reported to `onError` instead of
|
|
689
|
+
* thrown.
|
|
690
|
+
*
|
|
691
|
+
* @internal
|
|
692
|
+
*/
|
|
693
|
+
dispatchInternal(tr: Transaction<any>): void;
|
|
694
|
+
/** @internal */
|
|
695
|
+
domSelectionRange(): DOMSelectionRange;
|
|
696
|
+
/** @internal */
|
|
697
|
+
domSelection(): DOMSelection | null;
|
|
698
|
+
}
|
|
699
|
+
export {};
|