@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,195 @@
|
|
|
1
|
+
import { attempt } from "../internal/attempt.js";
|
|
2
|
+
import { Mark } from "../model/mark.js";
|
|
3
|
+
import { isTransformOrModelError } from "../transform/errors.js";
|
|
4
|
+
import { Transform } from "../transform/transform.js";
|
|
5
|
+
import { SelectionError } from "./errors.js";
|
|
6
|
+
import { Selection } from "./selection.js";
|
|
7
|
+
import * as Option from "effect/Option";
|
|
8
|
+
// src/state/transaction.ts
|
|
9
|
+
const UPDATED_SEL = 1;
|
|
10
|
+
const UPDATED_MARKS = 2;
|
|
11
|
+
const UPDATED_SCROLL = 4;
|
|
12
|
+
/**
|
|
13
|
+
* An editor state transaction, which can be applied to a state to
|
|
14
|
+
* create an updated state. Use `EditorState.tr` to create an instance.
|
|
15
|
+
*
|
|
16
|
+
* Transactions track changes to the document (they are a subclass of
|
|
17
|
+
* `Transform`), but also other state changes, like selection updates and
|
|
18
|
+
* adjustments of the set of stored marks. In addition, you can store
|
|
19
|
+
* metadata properties in a transaction, which are extra pieces of
|
|
20
|
+
* information that client code or plugins can use to describe what a
|
|
21
|
+
* transaction represents, so that they can update their own state
|
|
22
|
+
* accordingly.
|
|
23
|
+
*
|
|
24
|
+
* Like transforms, transactions are mutable builders.
|
|
25
|
+
*
|
|
26
|
+
* @since 0.1.0
|
|
27
|
+
* @category models
|
|
28
|
+
*/
|
|
29
|
+
var Transaction = class extends Transform {
|
|
30
|
+
/** @internal */
|
|
31
|
+
constructor(state) {
|
|
32
|
+
super(state.doc);
|
|
33
|
+
this.curSelectionFor = 0;
|
|
34
|
+
this.updated = 0;
|
|
35
|
+
this.meta = Object.create(null);
|
|
36
|
+
this.time = Date.now();
|
|
37
|
+
this.curSelection = state.selection;
|
|
38
|
+
this.storedMarksOrNull = state.storedMarksOrNull;
|
|
39
|
+
}
|
|
40
|
+
/** The stored marks set by this transaction, if any. */
|
|
41
|
+
get storedMarks() {
|
|
42
|
+
return Option.fromNullishOr(this.storedMarksOrNull);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The transaction's current selection. This defaults to the editor
|
|
46
|
+
* selection mapped through the steps in the transaction, but can be
|
|
47
|
+
* overwritten with `setSelection`.
|
|
48
|
+
*/
|
|
49
|
+
get selection() {
|
|
50
|
+
if (this.curSelectionFor < this.steps.length) {
|
|
51
|
+
this.curSelection = this.curSelection.map(this.doc, this.mapping.slice(this.curSelectionFor));
|
|
52
|
+
this.curSelectionFor = this.steps.length;
|
|
53
|
+
}
|
|
54
|
+
return this.curSelection;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Update the transaction's current selection. Will determine the
|
|
58
|
+
* selection that the editor gets when the transaction is applied.
|
|
59
|
+
* Fails with a `SelectionError` when the selection doesn't point into
|
|
60
|
+
* the transaction's current document.
|
|
61
|
+
*/
|
|
62
|
+
setSelection(selection) {
|
|
63
|
+
return attempt(() => this.setSelectionUnsafe(selection), (u) => u instanceof SelectionError);
|
|
64
|
+
}
|
|
65
|
+
/** Like `setSelection`, but throws a `SelectionError` on failure. */
|
|
66
|
+
setSelectionUnsafe(selection) {
|
|
67
|
+
if (selection.$from.doc !== this.doc) throw new SelectionError({ message: "Selection passed to setSelection must point at the current document" });
|
|
68
|
+
this.curSelection = selection;
|
|
69
|
+
this.curSelectionFor = this.steps.length;
|
|
70
|
+
this.updated = (this.updated | UPDATED_SEL) & -3;
|
|
71
|
+
this.storedMarksOrNull = null;
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
/** Whether the selection was explicitly updated by this transaction. */
|
|
75
|
+
get selectionSet() {
|
|
76
|
+
return (this.updated & UPDATED_SEL) > 0;
|
|
77
|
+
}
|
|
78
|
+
/** Set the current stored marks. */
|
|
79
|
+
setStoredMarks(marks) {
|
|
80
|
+
this.storedMarksOrNull = marks;
|
|
81
|
+
this.updated |= UPDATED_MARKS;
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Make sure the current stored marks or, if that is null, the marks at
|
|
86
|
+
* the selection, match the given set of marks. Does nothing if this is
|
|
87
|
+
* already the case.
|
|
88
|
+
*/
|
|
89
|
+
ensureMarks(marks) {
|
|
90
|
+
if (!Mark.sameSet(this.storedMarksOrNull || this.selection.$from.marks(), marks)) this.setStoredMarks(marks);
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
/** Add a mark to the set of stored marks. */
|
|
94
|
+
addStoredMark(mark) {
|
|
95
|
+
return this.ensureMarks(mark.addToSet(this.storedMarksOrNull || this.selection.$head.marks()));
|
|
96
|
+
}
|
|
97
|
+
/** Remove a mark or mark type from the set of stored marks. */
|
|
98
|
+
removeStoredMark(mark) {
|
|
99
|
+
const set = this.storedMarksOrNull || this.selection.$head.marks();
|
|
100
|
+
return this.ensureMarks(mark instanceof Mark ? mark.removeFromSet(set) : mark.removeFromSet(set));
|
|
101
|
+
}
|
|
102
|
+
/** Whether the stored marks were explicitly set for this transaction. */
|
|
103
|
+
get storedMarksSet() {
|
|
104
|
+
return (this.updated & UPDATED_MARKS) > 0;
|
|
105
|
+
}
|
|
106
|
+
/** @internal */
|
|
107
|
+
addStep(step, doc) {
|
|
108
|
+
super.addStep(step, doc);
|
|
109
|
+
this.updated = this.updated & -3;
|
|
110
|
+
this.storedMarksOrNull = null;
|
|
111
|
+
}
|
|
112
|
+
/** Update the timestamp for the transaction. */
|
|
113
|
+
setTime(time) {
|
|
114
|
+
this.time = time;
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
/** Replace the current selection with the given slice. */
|
|
118
|
+
replaceSelection(slice) {
|
|
119
|
+
this.selection.replace(this, slice);
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Replace the selection with the given node. When `inheritMarks` is
|
|
124
|
+
* true and the content is inline, it inherits the marks from the place
|
|
125
|
+
* where it is inserted.
|
|
126
|
+
*/
|
|
127
|
+
replaceSelectionWith(node, inheritMarks = true) {
|
|
128
|
+
const selection = this.selection;
|
|
129
|
+
if (inheritMarks) node = node.mark(this.storedMarksOrNull || (selection.empty ? selection.$from.marks() : selection.$from.marksAcrossOrNull(selection.$to) || Mark.none));
|
|
130
|
+
selection.replaceWith(this, node);
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
/** Delete the selection. */
|
|
134
|
+
deleteSelection() {
|
|
135
|
+
this.selection.replace(this);
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Replace the given range, or the selection if no range is given,
|
|
140
|
+
* with a text node containing the given string.
|
|
141
|
+
*/
|
|
142
|
+
insertText(text, from, to) {
|
|
143
|
+
return attempt(() => this.insertTextUnsafe(text, from, to), isTransformOrModelError);
|
|
144
|
+
}
|
|
145
|
+
/** Like `insertText`, but throws on failure (for example for positions outside of the document). */
|
|
146
|
+
insertTextUnsafe(text, from, to) {
|
|
147
|
+
const schema = this.doc.type.schema;
|
|
148
|
+
if (from == null) {
|
|
149
|
+
if (!text) return this.deleteSelection();
|
|
150
|
+
return this.replaceSelectionWith(schema.textUnsafe(text), true);
|
|
151
|
+
} else {
|
|
152
|
+
if (to == null) to = from;
|
|
153
|
+
if (!text) return this.deleteRangeUnsafe(from, to);
|
|
154
|
+
let marks = this.storedMarksOrNull;
|
|
155
|
+
if (!marks) {
|
|
156
|
+
const $from = this.doc.resolveUnsafe(from);
|
|
157
|
+
marks = to === from ? $from.marks() : $from.marksAcrossOrNull(this.doc.resolveUnsafe(to));
|
|
158
|
+
}
|
|
159
|
+
this.replaceRangeWithUnsafe(from, to, schema.textUnsafe(text, marks));
|
|
160
|
+
if (!this.selection.empty && this.selection.to === from + text.length) this.setSelectionUnsafe(Selection.near(this.selection.$to));
|
|
161
|
+
return this;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/** Store a metadata property in this transaction, keyed either by name or by plugin. */
|
|
165
|
+
setMeta(key, value) {
|
|
166
|
+
this.meta[typeof key === "string" ? key : key.key] = value;
|
|
167
|
+
return this;
|
|
168
|
+
}
|
|
169
|
+
/** Retrieve a metadata property for a given name or plugin, if it was set. */
|
|
170
|
+
getMeta(key) {
|
|
171
|
+
const name = typeof key === "string" ? key : key.key;
|
|
172
|
+
return name in this.meta ? Option.some(this.meta[name]) : Option.none();
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Returns true if this transaction doesn't contain any metadata, and
|
|
176
|
+
* can thus safely be extended.
|
|
177
|
+
*/
|
|
178
|
+
get isGeneric() {
|
|
179
|
+
for (const _ in this.meta) return false;
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Indicate that the editor should scroll the selection into view when
|
|
184
|
+
* updated to the state produced by this transaction.
|
|
185
|
+
*/
|
|
186
|
+
scrollIntoView() {
|
|
187
|
+
this.updated |= UPDATED_SCROLL;
|
|
188
|
+
return this;
|
|
189
|
+
}
|
|
190
|
+
/** True when this transaction has had `scrollIntoView` called on it. */
|
|
191
|
+
get scrolledIntoView() {
|
|
192
|
+
return (this.updated & UPDATED_SCROLL) > 0;
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
export { Transaction };
|
package/dist/state.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { SelectionError, StateError, StateFailure, isStateFailure } from "./state/errors.js";
|
|
2
|
+
import { AnyPlugin, EditorViewLike, MaybeEffect, Plugin, PluginErrors, PluginKey, PluginProps, PluginRequirements, PluginSpec, PluginTypeId, PluginView, StateField, getField } from "./state/plugin.js";
|
|
3
|
+
import { AllSelection, NodeSelection, Selection, SelectionBookmark, SelectionDeserializer, SelectionFromJSON, SelectionJSON, SelectionRange, TextSelection } from "./state/selection.js";
|
|
4
|
+
import { ApplyResult, Configuration, EditorState, EditorStateConfig, EditorStateJSON, EditorStateTypeId, runSyncUnsafe } from "./state/state.js";
|
|
5
|
+
import { Command, Dispatch, MetaKey, Transaction } from "./state/transaction.js";
|
|
6
|
+
export { AllSelection, AnyPlugin, ApplyResult, Command, Configuration, Dispatch, EditorState, EditorStateConfig, EditorStateJSON, EditorStateTypeId, EditorViewLike, MaybeEffect, MetaKey, NodeSelection, Plugin, PluginErrors, PluginKey, PluginProps, PluginRequirements, PluginSpec, PluginTypeId, PluginView, Selection, SelectionBookmark, SelectionDeserializer, SelectionError, SelectionFromJSON, SelectionJSON, SelectionRange, StateError, StateFailure, StateField, TextSelection, Transaction, getField, isStateFailure, runSyncUnsafe };
|
package/dist/state.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { SelectionError, StateError, isStateFailure } from "./state/errors.js";
|
|
2
|
+
import { Plugin, PluginKey, PluginTypeId, getField } from "./state/plugin.js";
|
|
3
|
+
import { AllSelection, NodeSelection, Selection, SelectionFromJSON, SelectionRange, TextSelection } from "./state/selection.js";
|
|
4
|
+
import { Configuration, EditorState, EditorStateTypeId, runSyncUnsafe } from "./state/state.js";
|
|
5
|
+
import { Transaction } from "./state/transaction.js";
|
|
6
|
+
export { AllSelection, Configuration, EditorState, EditorStateTypeId, NodeSelection, Plugin, PluginKey, PluginTypeId, Selection, SelectionError, SelectionFromJSON, SelectionRange, StateError, TextSelection, Transaction, getField, isStateFailure, runSyncUnsafe };
|