@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
package/LICENSE
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Thomas Foster
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
Portions of this software (the document model, transforms, editor state,
|
|
26
|
+
view, keymap, commands and related modules, and their test suites) are
|
|
27
|
+
derived from ProseMirror (https://prosemirror.net), which is distributed under
|
|
28
|
+
the following license:
|
|
29
|
+
|
|
30
|
+
Copyright (C) 2015-2017 by Marijn Haverbeke <marijn@haverbeke.berlin> and others
|
|
31
|
+
|
|
32
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
33
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
34
|
+
in the Software without restriction, including without limitation the rights
|
|
35
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
36
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
37
|
+
furnished to do so, subject to the following conditions:
|
|
38
|
+
|
|
39
|
+
The above copyright notice and this permission notice shall be included in
|
|
40
|
+
all copies or substantial portions of the Software.
|
|
41
|
+
|
|
42
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
43
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
44
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
45
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
46
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
47
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
48
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,119 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @thomasfosterau/effect-richtext
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A reimplementation of the core [ProseMirror](https://prosemirror.net) toolkit (`prosemirror-model`, `-transform`, `-state`, `-view`, `-keymap`, `-commands`) on top of [Effect](https://effect.website) 4, in a single package.
|
|
4
|
+
|
|
5
|
+
- **Strongly typed documents.** Node and mark names are literal types, attributes are described with Effect `Schema`s, and content expressions are typed combinators, so the schema knows which children each node accepts: `doc` built from a `text` node is a compile error, as are a node built without one of its required attributes and a spec that refers to a node or mark it does not define, and `node.is("heading")` narrows `node.attrs` to `{ level: number }`.
|
|
6
|
+
- **Effect everywhere.** Every fallible operation returns an `Effect` with tagged errors (`PositionError`, `ReplaceError`, `StepError`, …). Each also has a synchronous `…Unsafe` twin for hot paths. Absent values are `Option`s.
|
|
7
|
+
- **Typed plugin requirements.** Plugins, commands and view props may return Effects that need services; those requirements (`R`) and errors (`E`) are tracked through `EditorState` and `EditorView`, and provided with ordinary Effect layers. The view is created in a `Scope` and destroyed with it.
|
|
8
|
+
- **Faithful port.** ProseMirror's own test suites are ported and pass (model, transform, state, commands, keymap, history, markdown, and all of prosemirror-view's browser tests in real Chromium).
|
|
9
|
+
- **Nice-to-haves**, all additive and unopinionated: extensions with typed `editor.commands` / `editor.chain()` / `editor.can()`, input rules, gap and drop cursors, placeholders, undo history, reactive bindings (`SubscriptionRef`/`Stream`), HTML and Markdown serializers.
|
|
10
|
+
|
|
11
|
+
See [`DESIGN.md`](https://github.com/thomasfosterau/effect-richtext/blob/trunk/DESIGN.md) for the design decisions and conventions.
|
|
12
|
+
|
|
13
|
+
> Status: experimental (0.x). APIs may change.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
pnpm add @thomasfosterau/effect-richtext effect
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`effect` (4.x) is a peer dependency: your application provides the single copy. The package is ESM-only and has no `.` entry; import the modules you use by subpath.
|
|
22
|
+
|
|
23
|
+
## Modules
|
|
24
|
+
|
|
25
|
+
| Module | Ported from / purpose |
|
|
26
|
+
| ---------------------------------------------- | ------------------------------------------------------------ |
|
|
27
|
+
| `@thomasfosterau/effect-richtext/model` | prosemirror-model (incl. DOM parser/serializer, JSON codecs) |
|
|
28
|
+
| `@thomasfosterau/effect-richtext/transform` | prosemirror-transform |
|
|
29
|
+
| `@thomasfosterau/effect-richtext/state` | prosemirror-state |
|
|
30
|
+
| `@thomasfosterau/effect-richtext/view` | prosemirror-view |
|
|
31
|
+
| `@thomasfosterau/effect-richtext/view-css` | prosemirror-view's stylesheet |
|
|
32
|
+
| `@thomasfosterau/effect-richtext/keymap` | prosemirror-keymap |
|
|
33
|
+
| `@thomasfosterau/effect-richtext/commands` | prosemirror-commands |
|
|
34
|
+
| `@thomasfosterau/effect-richtext/history` | prosemirror-history |
|
|
35
|
+
| `@thomasfosterau/effect-richtext/inputrules` | prosemirror-inputrules |
|
|
36
|
+
| `@thomasfosterau/effect-richtext/gapcursor` | prosemirror-gapcursor |
|
|
37
|
+
| `@thomasfosterau/effect-richtext/dropcursor` | prosemirror-dropcursor |
|
|
38
|
+
| `@thomasfosterau/effect-richtext/schema-basic` | prosemirror-schema-basic |
|
|
39
|
+
| `@thomasfosterau/effect-richtext/schema-list` | prosemirror-schema-list |
|
|
40
|
+
| `@thomasfosterau/effect-richtext/markdown` | prosemirror-markdown |
|
|
41
|
+
| `@thomasfosterau/effect-richtext/test-builder` | prosemirror-test-builder |
|
|
42
|
+
| `@thomasfosterau/effect-richtext/html` | HTML string helpers |
|
|
43
|
+
| `@thomasfosterau/effect-richtext/placeholder` | placeholder decorations |
|
|
44
|
+
| `@thomasfosterau/effect-richtext/reactive` | `SubscriptionRef`/`Stream` bindings |
|
|
45
|
+
| `@thomasfosterau/effect-richtext/extensions` | composable, typed extensions and chainable commands |
|
|
46
|
+
| `@thomasfosterau/effect-richtext/compat/*` | ProseMirror-compatible facade API |
|
|
47
|
+
|
|
48
|
+
## Example
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import { Effect, Schema } from "effect"
|
|
52
|
+
import { baseKeymap, toggleMark } from "@thomasfosterau/effect-richtext/commands"
|
|
53
|
+
import { history, redo, undo } from "@thomasfosterau/effect-richtext/history"
|
|
54
|
+
import { keymap } from "@thomasfosterau/effect-richtext/keymap"
|
|
55
|
+
import { Content, DocSchema } from "@thomasfosterau/effect-richtext/model"
|
|
56
|
+
import { EditorState } from "@thomasfosterau/effect-richtext/state"
|
|
57
|
+
import { EditorView } from "@thomasfosterau/effect-richtext/view"
|
|
58
|
+
|
|
59
|
+
const schema = DocSchema.makeUnsafe({
|
|
60
|
+
nodes: {
|
|
61
|
+
doc: { content: Content.oneOrMore("block") },
|
|
62
|
+
paragraph: { group: "block", content: Content.zeroOrMore("text"), toDOM: () => ["p", 0] },
|
|
63
|
+
heading: {
|
|
64
|
+
group: "block",
|
|
65
|
+
content: Content.zeroOrMore("text"),
|
|
66
|
+
attrs: { level: { schema: Schema.Literals([1, 2, 3]), default: 1 } },
|
|
67
|
+
toDOM: (node) => ["h" + node.attrs.level, 0]
|
|
68
|
+
},
|
|
69
|
+
text: {}
|
|
70
|
+
},
|
|
71
|
+
marks: { strong: { toDOM: () => ["strong", 0] } }
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
const mountEditor = Effect.fn("mountEditor")(function* (place: HTMLElement) {
|
|
75
|
+
const state = yield* EditorState.create({
|
|
76
|
+
schema,
|
|
77
|
+
plugins: [
|
|
78
|
+
history(),
|
|
79
|
+
keymap({ "Mod-z": undo, "Mod-y": redo, "Mod-b": toggleMark(schema.marks.strong) }),
|
|
80
|
+
keymap(baseKeymap)
|
|
81
|
+
]
|
|
82
|
+
})
|
|
83
|
+
const view = yield* EditorView.make(place, { state })
|
|
84
|
+
yield* view.dispatch(view.state.tr.insertTextUnsafe("Hello"))
|
|
85
|
+
// ...the view is destroyed when the scope closes
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
Effect.runFork(Effect.scoped(Effect.andThen(mountEditor(document.body), Effect.never)))
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
With `@thomasfosterau/effect-richtext/extensions`, the same editor is:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
import { Effect } from "effect"
|
|
95
|
+
import { createEditor, defineBasicExtension } from "@thomasfosterau/effect-richtext/extensions"
|
|
96
|
+
|
|
97
|
+
const mountBasicEditor = Effect.fn("mountBasicEditor")(function* (place: HTMLElement) {
|
|
98
|
+
const editor = yield* createEditor(defineBasicExtension())
|
|
99
|
+
yield* editor.mount(place)
|
|
100
|
+
yield* editor.chain().setBlockType("heading", { level: 2 }).toggleMark("strong").run()
|
|
101
|
+
})
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Development
|
|
105
|
+
|
|
106
|
+
Contributor setup, hooks and single checks are in [CONTRIBUTING.md](https://github.com/thomasfosterau/effect-richtext/blob/trunk/CONTRIBUTING.md); the gates every change runs are in [AGENTS.md](https://github.com/thomasfosterau/effect-richtext/blob/trunk/AGENTS.md#verification). In short, with pnpm 11:
|
|
107
|
+
|
|
108
|
+
```sh
|
|
109
|
+
pnpm install
|
|
110
|
+
vp check # format + lint
|
|
111
|
+
vp run check # type gate (src + tests, including type-level tests)
|
|
112
|
+
vp run test:unit # node tests
|
|
113
|
+
vp run test:browser # prosemirror-view's suites in Chromium
|
|
114
|
+
vp run build # dist/
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
MIT. Portions are derived from ProseMirror, © Marijn Haverbeke and others (MIT); see [`LICENSE`](https://github.com/thomasfosterau/effect-richtext/blob/trunk/LICENSE).
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
return target;
|
|
11
|
+
};
|
|
12
|
+
export { __exportAll };
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { ResolvedPos } from "../model/resolvedpos.js";
|
|
2
|
+
import { AnySchema, MarkAttrsInput, MarkNames, MarkType, NodeAttrsInput, NodeNames, NodeType } from "../model/schema.js";
|
|
3
|
+
import { Node } from "../model/node.js";
|
|
4
|
+
import "../model.js";
|
|
5
|
+
import { NodeTypeWithAttrs } from "../transform/structure.js";
|
|
6
|
+
import "../state.js";
|
|
7
|
+
import { Command } from "../state/transaction.js";
|
|
8
|
+
import { EditorState } from "../state/state.js";
|
|
9
|
+
import "../transform.js";
|
|
10
|
+
import * as Effect from "effect/Effect";
|
|
11
|
+
/**
|
|
12
|
+
* A text direction or vertical direction, as passed to
|
|
13
|
+
* `TextblockBoundaryView.endOfTextblock`.
|
|
14
|
+
*
|
|
15
|
+
* @since 0.1.0
|
|
16
|
+
* @category models
|
|
17
|
+
*/
|
|
18
|
+
export type TextblockBoundaryDirection = "up" | "down" | "left" | "right" | "forward" | "backward";
|
|
19
|
+
/**
|
|
20
|
+
* The part of an editor view used by commands that need accurate
|
|
21
|
+
* (bidi-aware) detection of textblock boundaries (`joinBackward`,
|
|
22
|
+
* `joinForward`, `selectNodeBackward`, `selectNodeForward`, …). When
|
|
23
|
+
* the view passed to such a command doesn't implement this interface,
|
|
24
|
+
* the command falls back to checking the cursor's offset in its parent.
|
|
25
|
+
*
|
|
26
|
+
* @since 0.1.0
|
|
27
|
+
* @category models
|
|
28
|
+
*/
|
|
29
|
+
export interface TextblockBoundaryView {
|
|
30
|
+
/**
|
|
31
|
+
* Whether the selection (in the given state, or the view's current
|
|
32
|
+
* state) is at the end of its textblock in the given direction.
|
|
33
|
+
*/
|
|
34
|
+
readonly endOfTextblock: (dir: TextblockBoundaryDirection, state?: EditorState<any, any, any>) => boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Check whether a view implements `TextblockBoundaryView`.
|
|
38
|
+
*
|
|
39
|
+
* @since 0.1.0
|
|
40
|
+
* @category guards
|
|
41
|
+
*/
|
|
42
|
+
export declare const isTextblockBoundaryView: (view: unknown) => view is TextblockBoundaryView;
|
|
43
|
+
/**
|
|
44
|
+
* Delete the selection, if there is one.
|
|
45
|
+
*
|
|
46
|
+
* @since 0.1.0
|
|
47
|
+
* @category commands
|
|
48
|
+
*/
|
|
49
|
+
export declare const deleteSelection: Command;
|
|
50
|
+
/**
|
|
51
|
+
* If the selection is empty and at the start of a textblock, try to
|
|
52
|
+
* reduce the distance between that block and the one before it—if
|
|
53
|
+
* there's a block directly before it that can be joined, join them.
|
|
54
|
+
* If not, try to move the selected block closer to the next one in
|
|
55
|
+
* the document structure by lifting it out of its parent or moving it
|
|
56
|
+
* into a parent of the previous block. Will use the view for accurate
|
|
57
|
+
* (bidi-aware) start-of-textblock detection if given (see
|
|
58
|
+
* `TextblockBoundaryView`).
|
|
59
|
+
*
|
|
60
|
+
* @since 0.1.0
|
|
61
|
+
* @category commands
|
|
62
|
+
*/
|
|
63
|
+
export declare const joinBackward: Command;
|
|
64
|
+
/**
|
|
65
|
+
* A more limited form of `joinBackward` that only tries to join the
|
|
66
|
+
* current textblock to the one before it, if the cursor is at the start
|
|
67
|
+
* of a textblock.
|
|
68
|
+
*
|
|
69
|
+
* @since 0.1.0
|
|
70
|
+
* @category commands
|
|
71
|
+
*/
|
|
72
|
+
export declare const joinTextblockBackward: Command;
|
|
73
|
+
/**
|
|
74
|
+
* A more limited form of `joinForward` that only tries to join the
|
|
75
|
+
* current textblock to the one after it, if the cursor is at the end of
|
|
76
|
+
* a textblock.
|
|
77
|
+
*
|
|
78
|
+
* @since 0.1.0
|
|
79
|
+
* @category commands
|
|
80
|
+
*/
|
|
81
|
+
export declare const joinTextblockForward: Command;
|
|
82
|
+
/**
|
|
83
|
+
* When the selection is empty and at the start of a textblock, select
|
|
84
|
+
* the node before that textblock, if possible. This is intended to be
|
|
85
|
+
* bound to keys like backspace, after `joinBackward` or other deleting
|
|
86
|
+
* commands, as a fall-back behavior when the schema doesn't allow
|
|
87
|
+
* deletion at the selected point.
|
|
88
|
+
*
|
|
89
|
+
* @since 0.1.0
|
|
90
|
+
* @category commands
|
|
91
|
+
*/
|
|
92
|
+
export declare const selectNodeBackward: Command;
|
|
93
|
+
/**
|
|
94
|
+
* If the selection is empty and the cursor is at the end of a
|
|
95
|
+
* textblock, try to reduce or remove the boundary between that block
|
|
96
|
+
* and the one after it, either by joining them or by moving the other
|
|
97
|
+
* block closer to this one in the tree structure. Will use the view for
|
|
98
|
+
* accurate start-of-textblock detection if given.
|
|
99
|
+
*
|
|
100
|
+
* @since 0.1.0
|
|
101
|
+
* @category commands
|
|
102
|
+
*/
|
|
103
|
+
export declare const joinForward: Command;
|
|
104
|
+
/**
|
|
105
|
+
* When the selection is empty and at the end of a textblock, select the
|
|
106
|
+
* node coming after that textblock, if possible. This is intended to be
|
|
107
|
+
* bound to keys like delete, after `joinForward` and similar deleting
|
|
108
|
+
* commands, to provide a fall-back behavior when the schema doesn't
|
|
109
|
+
* allow deletion at the selected point.
|
|
110
|
+
*
|
|
111
|
+
* @since 0.1.0
|
|
112
|
+
* @category commands
|
|
113
|
+
*/
|
|
114
|
+
export declare const selectNodeForward: Command;
|
|
115
|
+
/**
|
|
116
|
+
* Join the selected block or, if there is a text selection, the closest
|
|
117
|
+
* ancestor block of the selection that can be joined, with the sibling
|
|
118
|
+
* above it.
|
|
119
|
+
*
|
|
120
|
+
* @since 0.1.0
|
|
121
|
+
* @category commands
|
|
122
|
+
*/
|
|
123
|
+
export declare const joinUp: Command;
|
|
124
|
+
/**
|
|
125
|
+
* Join the selected block, or the closest ancestor of the selection
|
|
126
|
+
* that can be joined, with the sibling after it.
|
|
127
|
+
*
|
|
128
|
+
* @since 0.1.0
|
|
129
|
+
* @category commands
|
|
130
|
+
*/
|
|
131
|
+
export declare const joinDown: Command;
|
|
132
|
+
/**
|
|
133
|
+
* Lift the selected block, or the closest ancestor block of the
|
|
134
|
+
* selection that can be lifted, out of its parent node.
|
|
135
|
+
*
|
|
136
|
+
* @since 0.1.0
|
|
137
|
+
* @category commands
|
|
138
|
+
*/
|
|
139
|
+
export declare const lift: Command;
|
|
140
|
+
/**
|
|
141
|
+
* If the selection is in a node whose type has a truthy `code` property
|
|
142
|
+
* in its spec, replace the selection with a newline character.
|
|
143
|
+
*
|
|
144
|
+
* @since 0.1.0
|
|
145
|
+
* @category commands
|
|
146
|
+
*/
|
|
147
|
+
export declare const newlineInCode: Command;
|
|
148
|
+
/**
|
|
149
|
+
* When the selection is in a node with a truthy `code` property in its
|
|
150
|
+
* spec, create a default block after the code block, and move the
|
|
151
|
+
* cursor there.
|
|
152
|
+
*
|
|
153
|
+
* @since 0.1.0
|
|
154
|
+
* @category commands
|
|
155
|
+
*/
|
|
156
|
+
export declare const exitCode: Command;
|
|
157
|
+
/**
|
|
158
|
+
* If a block node is selected, create an empty paragraph before (if it
|
|
159
|
+
* is its parent's first child) or after it.
|
|
160
|
+
*
|
|
161
|
+
* @since 0.1.0
|
|
162
|
+
* @category commands
|
|
163
|
+
*/
|
|
164
|
+
export declare const createParagraphNear: Command;
|
|
165
|
+
/**
|
|
166
|
+
* If the cursor is in an empty textblock that can be lifted, lift the
|
|
167
|
+
* block.
|
|
168
|
+
*
|
|
169
|
+
* @since 0.1.0
|
|
170
|
+
* @category commands
|
|
171
|
+
*/
|
|
172
|
+
export declare const liftEmptyBlock: Command;
|
|
173
|
+
/**
|
|
174
|
+
* A function that determines the type of the block split off by
|
|
175
|
+
* `splitBlockAs`, given the parent node of the selection end, whether
|
|
176
|
+
* the split happens at the end of that node, and the selection start.
|
|
177
|
+
* Returning `null` (or `undefined`) uses the default behavior.
|
|
178
|
+
*
|
|
179
|
+
* @since 0.1.0
|
|
180
|
+
* @category models
|
|
181
|
+
*/
|
|
182
|
+
export type SplitNodeType<Sc extends AnySchema = AnySchema> = (node: Node<Sc>, atEnd: boolean, $from: ResolvedPos<Sc>) => NodeTypeWithAttrs<Sc> | null | undefined;
|
|
183
|
+
/**
|
|
184
|
+
* Create a variant of `splitBlock` that uses a custom function to
|
|
185
|
+
* determine the type of the newly split off block.
|
|
186
|
+
*
|
|
187
|
+
* @since 0.1.0
|
|
188
|
+
* @category commands
|
|
189
|
+
*/
|
|
190
|
+
export declare const splitBlockAs: <Sc extends AnySchema = AnySchema>(splitNode?: SplitNodeType<Sc>) => Command<Sc>;
|
|
191
|
+
/**
|
|
192
|
+
* Split the parent block of the selection. If the selection is a text
|
|
193
|
+
* selection, also delete its content.
|
|
194
|
+
*
|
|
195
|
+
* @since 0.1.0
|
|
196
|
+
* @category commands
|
|
197
|
+
*/
|
|
198
|
+
export declare const splitBlock: Command;
|
|
199
|
+
/**
|
|
200
|
+
* Acts like `splitBlock`, but without resetting the set of active marks
|
|
201
|
+
* at the cursor.
|
|
202
|
+
*
|
|
203
|
+
* @since 0.1.0
|
|
204
|
+
* @category commands
|
|
205
|
+
*/
|
|
206
|
+
export declare const splitBlockKeepMarks: Command;
|
|
207
|
+
/**
|
|
208
|
+
* Move the selection to the node wrapping the current selection, if
|
|
209
|
+
* any. (Will not select the document node.)
|
|
210
|
+
*
|
|
211
|
+
* @since 0.1.0
|
|
212
|
+
* @category commands
|
|
213
|
+
*/
|
|
214
|
+
export declare const selectParentNode: Command;
|
|
215
|
+
/**
|
|
216
|
+
* Select the whole document.
|
|
217
|
+
*
|
|
218
|
+
* @since 0.1.0
|
|
219
|
+
* @category commands
|
|
220
|
+
*/
|
|
221
|
+
export declare const selectAll: Command;
|
|
222
|
+
/**
|
|
223
|
+
* Moves the cursor to the start of current text block.
|
|
224
|
+
*
|
|
225
|
+
* @since 0.1.0
|
|
226
|
+
* @category commands
|
|
227
|
+
*/
|
|
228
|
+
export declare const selectTextblockStart: Command;
|
|
229
|
+
/**
|
|
230
|
+
* Moves the cursor to the end of current text block.
|
|
231
|
+
*
|
|
232
|
+
* @since 0.1.0
|
|
233
|
+
* @category commands
|
|
234
|
+
*/
|
|
235
|
+
export declare const selectTextblockEnd: Command;
|
|
236
|
+
/**
|
|
237
|
+
* Wrap the selection in a node of the given type with the given
|
|
238
|
+
* attributes.
|
|
239
|
+
*
|
|
240
|
+
* @since 0.1.0
|
|
241
|
+
* @category commands
|
|
242
|
+
*/
|
|
243
|
+
export declare const wrapIn: <Sc extends AnySchema, N extends NodeNames<Sc>>(nodeType: NodeType<Sc, N>, attrs?: NodeAttrsInput<Sc, N> | null) => Command<Sc>;
|
|
244
|
+
/**
|
|
245
|
+
* Returns a command that tries to set the selected textblocks to the
|
|
246
|
+
* given node type with the given attributes.
|
|
247
|
+
*
|
|
248
|
+
* @since 0.1.0
|
|
249
|
+
* @category commands
|
|
250
|
+
*/
|
|
251
|
+
export declare const setBlockType: <Sc extends AnySchema, N extends NodeNames<Sc>>(nodeType: NodeType<Sc, N>, attrs?: NodeAttrsInput<Sc, N> | null) => Command<Sc>;
|
|
252
|
+
/**
|
|
253
|
+
* Options for `toggleMark`.
|
|
254
|
+
*
|
|
255
|
+
* @since 0.1.0
|
|
256
|
+
* @category models
|
|
257
|
+
*/
|
|
258
|
+
export interface ToggleMarkOptions {
|
|
259
|
+
/**
|
|
260
|
+
* Controls whether, when part of the selected range has the mark
|
|
261
|
+
* already and part doesn't, the mark is removed (`true`, the default)
|
|
262
|
+
* or added (`false`).
|
|
263
|
+
*/
|
|
264
|
+
readonly removeWhenPresent?: boolean | undefined;
|
|
265
|
+
/**
|
|
266
|
+
* When set to false, this will prevent the command from acting on the
|
|
267
|
+
* content of inline nodes marked as atoms that are completely covered
|
|
268
|
+
* by a selection range.
|
|
269
|
+
*/
|
|
270
|
+
readonly enterInlineAtoms?: boolean | undefined;
|
|
271
|
+
/**
|
|
272
|
+
* By default, this command doesn't apply to leading and trailing
|
|
273
|
+
* whitespace in the selection. Set this to `true` to change that.
|
|
274
|
+
*/
|
|
275
|
+
readonly includeWhitespace?: boolean | undefined;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Create a command function that toggles the given mark with the given
|
|
279
|
+
* attributes. Will return `false` when the current selection doesn't
|
|
280
|
+
* support that mark. This will remove the mark if any marks of that
|
|
281
|
+
* type exist in the selection, or add it otherwise. If the selection is
|
|
282
|
+
* empty, this applies to the stored marks instead of a range of the
|
|
283
|
+
* document.
|
|
284
|
+
*
|
|
285
|
+
* @since 0.1.0
|
|
286
|
+
* @category commands
|
|
287
|
+
*/
|
|
288
|
+
export declare const toggleMark: <Sc extends AnySchema, M extends MarkNames<Sc>>(markType: MarkType<Sc, M>, attrs?: MarkAttrsInput<Sc, M>, options?: ToggleMarkOptions) => Command<Sc>;
|
|
289
|
+
/**
|
|
290
|
+
* Wrap a command so that, when it produces a transform that causes two
|
|
291
|
+
* joinable nodes to end up next to each other, those are joined. Nodes
|
|
292
|
+
* are considered joinable when they are of the same type and when the
|
|
293
|
+
* `isJoinable` predicate returns true for them or, if an array of
|
|
294
|
+
* strings was passed, if their node type name is in that array.
|
|
295
|
+
*
|
|
296
|
+
* @since 0.1.0
|
|
297
|
+
* @category combinators
|
|
298
|
+
*/
|
|
299
|
+
export declare const autoJoin: <Sc extends AnySchema, E, R>(command: Command<Sc, E, R>, isJoinable: ((before: Node<Sc>, after: Node<Sc>) => boolean) | ReadonlyArray<string>) => Command<Sc, E, R>;
|
|
300
|
+
/**
|
|
301
|
+
* The union of the error types of the given commands.
|
|
302
|
+
*
|
|
303
|
+
* @since 0.1.0
|
|
304
|
+
* @category type-level
|
|
305
|
+
*/
|
|
306
|
+
export type CommandError<C> = C extends ((...args: any) => Effect.Effect<any, infer E, any>) ? E : never;
|
|
307
|
+
/**
|
|
308
|
+
* The union of the requirements of the given commands.
|
|
309
|
+
*
|
|
310
|
+
* @since 0.1.0
|
|
311
|
+
* @category type-level
|
|
312
|
+
*/
|
|
313
|
+
export type CommandRequirements<C> = C extends ((...args: any) => Effect.Effect<any, any, infer R>) ? R : never;
|
|
314
|
+
/**
|
|
315
|
+
* Combine a number of command functions into a single function (which
|
|
316
|
+
* calls them one by one until one returns true). The resulting
|
|
317
|
+
* command's errors and requirements are the unions of those of the
|
|
318
|
+
* given commands.
|
|
319
|
+
*
|
|
320
|
+
* @since 0.1.0
|
|
321
|
+
* @category combinators
|
|
322
|
+
*/
|
|
323
|
+
export declare const chainCommands: <const Commands extends ReadonlyArray<Command<any, any, any>>>(...commands: Commands) => Command<AnySchema, CommandError<Commands[number]>, CommandRequirements<Commands[number]>>;
|