@edifice.io/react 2.6.8 → 2.6.9-chore-tiptap-v3.20261013175230
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/dist/editor.js +2 -0
- package/dist/homepage.js +2 -1
- package/dist/modules/editor/components/BubbleMenuEditImage/BubbleMenuEditImage.js +97 -90
- package/dist/modules/editor/components/BubbleMenuEditInformationPane/BubbleMenuEditInformationPane.js +111 -95
- package/dist/modules/editor/components/EditorToolbar/EditorToolbar.Typography.js +3 -3
- package/dist/modules/editor/components/EditorToolbar/EditorToolbar.js +6 -4
- package/dist/modules/editor/components/Toolbar/LinkToolbar.FloatingOptions.js +12 -0
- package/dist/modules/editor/components/Toolbar/LinkToolbar.js +5 -4
- package/dist/modules/editor/components/Toolbar/TableToolbar.js +11 -5
- package/dist/modules/editor/hooks/index.d.ts +1 -0
- package/dist/modules/editor/hooks/useCommentEditor.d.ts +1 -1
- package/dist/modules/editor/hooks/useCommentEditor.js +12 -4
- package/dist/modules/editor/hooks/useEditorState.d.ts +20 -0
- package/dist/modules/editor/hooks/useEditorState.js +16 -0
- package/dist/modules/editor/hooks/useTipTapEditor.d.ts +1 -1
- package/dist/modules/editor/hooks/useTipTapEditor.js +64 -24
- package/dist/modules/homepage/components/Communities/Communities.d.ts +2 -1
- package/dist/modules/homepage/components/Communities/Communities.js +14 -13
- package/dist/modules/homepage/components/Communities/CommunitiesContainer.d.ts +1 -1
- package/dist/modules/homepage/components/Communities/CommunitiesContainer.js +9 -5
- package/dist/modules/homepage/components/Communities/CommunitiesSkeleton.js +4 -7
- package/dist/modules/homepage/components/Communities/useCommunities.d.ts +4 -1
- package/dist/modules/homepage/components/Communities/useCommunities.js +8 -3
- package/dist/modules/homepage/components/HomeCard/HomeCardHeader.js +2 -2
- package/dist/modules/multimedia/MediaLibrary/MediaLibrary.d.ts +2 -0
- package/dist/modules/multimedia/MediaLibrary/MediaLibrary.js +2 -0
- package/dist/modules/multimedia/MediaLibrary/MediaLibraryContext.d.ts +4 -0
- package/dist/modules/multimedia/MediaLibrary/innertabs/Upload.js +2 -1
- package/dist/modules/multimedia/MediaLibrary/innertabs/Workspace.js +3 -0
- package/dist/node_modules/.pnpm/@tiptap_extension-floating-menu@3.32.0_@floating-ui_dom@1.6.0_@tiptap_core@3.32.0_@tiptap_pm@3.32.0__@tiptap_pm@3.32.0/node_modules/@tiptap/extension-floating-menu/dist/index.js +159 -0
- package/dist/node_modules/.pnpm/@tiptap_react@3.32.0_@floating-ui_dom@1.6.0_@tiptap_core@3.32.0_@tiptap_pm@3.32.0__@tiptap_pm_6inmb43gajy4fnlwtngbwkv7um/node_modules/@tiptap/react/dist/menus/index.js +341 -0
- package/dist/node_modules/.pnpm/prosemirror-model@1.25.12/node_modules/prosemirror-model/dist/index.js +419 -0
- package/dist/node_modules/.pnpm/prosemirror-state@1.4.4/node_modules/prosemirror-state/dist/index.js +489 -0
- package/dist/node_modules/.pnpm/prosemirror-transform@1.12.2/node_modules/prosemirror-transform/dist/index.js +607 -0
- package/package.json +35 -43
- package/dist/modules/editor/components/Toolbar/LinkToolbar.TippyOptions.d.ts +0 -2
- package/dist/modules/editor/components/Toolbar/LinkToolbar.TippyOptions.js +0 -8
|
@@ -0,0 +1,607 @@
|
|
|
1
|
+
import { Slice, ReplaceError, Fragment } from "../../../../prosemirror-model@1.25.12/node_modules/prosemirror-model/dist/index.js";
|
|
2
|
+
const lower16 = 65535, factor16 = Math.pow(2, 16);
|
|
3
|
+
function makeRecover(index, offset) {
|
|
4
|
+
return index + offset * factor16;
|
|
5
|
+
}
|
|
6
|
+
function recoverIndex(value) {
|
|
7
|
+
return value & lower16;
|
|
8
|
+
}
|
|
9
|
+
function recoverOffset(value) {
|
|
10
|
+
return (value - (value & lower16)) / factor16;
|
|
11
|
+
}
|
|
12
|
+
const DEL_BEFORE = 1, DEL_AFTER = 2, DEL_ACROSS = 4, DEL_SIDE = 8;
|
|
13
|
+
class MapResult {
|
|
14
|
+
/**
|
|
15
|
+
@internal
|
|
16
|
+
*/
|
|
17
|
+
constructor(pos, delInfo, recover) {
|
|
18
|
+
this.pos = pos, this.delInfo = delInfo, this.recover = recover;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
Tells you whether the position was deleted, that is, whether the
|
|
22
|
+
step removed the token on the side queried (via the `assoc`)
|
|
23
|
+
argument from the document.
|
|
24
|
+
*/
|
|
25
|
+
get deleted() {
|
|
26
|
+
return (this.delInfo & DEL_SIDE) > 0;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
Tells you whether the token before the mapped position was deleted.
|
|
30
|
+
*/
|
|
31
|
+
get deletedBefore() {
|
|
32
|
+
return (this.delInfo & (DEL_BEFORE | DEL_ACROSS)) > 0;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
True when the token after the mapped position was deleted.
|
|
36
|
+
*/
|
|
37
|
+
get deletedAfter() {
|
|
38
|
+
return (this.delInfo & (DEL_AFTER | DEL_ACROSS)) > 0;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
Tells whether any of the steps mapped through deletes across the
|
|
42
|
+
position (including both the token before and after the
|
|
43
|
+
position).
|
|
44
|
+
*/
|
|
45
|
+
get deletedAcross() {
|
|
46
|
+
return (this.delInfo & DEL_ACROSS) > 0;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
class StepMap {
|
|
50
|
+
/**
|
|
51
|
+
Create a position map. The modifications to the document are
|
|
52
|
+
represented as an array of numbers, in which each group of three
|
|
53
|
+
represents a modified chunk as `[start, oldSize, newSize]`.
|
|
54
|
+
*/
|
|
55
|
+
constructor(ranges, inverted = !1) {
|
|
56
|
+
if (this.ranges = ranges, this.inverted = inverted, !ranges.length && StepMap.empty)
|
|
57
|
+
return StepMap.empty;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
@internal
|
|
61
|
+
*/
|
|
62
|
+
recover(value) {
|
|
63
|
+
let diff = 0, index = recoverIndex(value);
|
|
64
|
+
if (!this.inverted)
|
|
65
|
+
for (let i = 0; i < index; i++)
|
|
66
|
+
diff += this.ranges[i * 3 + 2] - this.ranges[i * 3 + 1];
|
|
67
|
+
return this.ranges[index * 3] + diff + recoverOffset(value);
|
|
68
|
+
}
|
|
69
|
+
mapResult(pos, assoc = 1) {
|
|
70
|
+
return this._map(pos, assoc, !1);
|
|
71
|
+
}
|
|
72
|
+
map(pos, assoc = 1) {
|
|
73
|
+
return this._map(pos, assoc, !0);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
@internal
|
|
77
|
+
*/
|
|
78
|
+
_map(pos, assoc, simple) {
|
|
79
|
+
let diff = 0, oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;
|
|
80
|
+
for (let i = 0; i < this.ranges.length; i += 3) {
|
|
81
|
+
let start = this.ranges[i] - (this.inverted ? diff : 0);
|
|
82
|
+
if (start > pos)
|
|
83
|
+
break;
|
|
84
|
+
let oldSize = this.ranges[i + oldIndex], newSize = this.ranges[i + newIndex], end = start + oldSize;
|
|
85
|
+
if (pos <= end) {
|
|
86
|
+
let side = oldSize ? pos == start ? -1 : pos == end ? 1 : assoc : assoc, result = start + diff + (side < 0 ? 0 : newSize);
|
|
87
|
+
if (simple)
|
|
88
|
+
return result;
|
|
89
|
+
let recover = pos == (assoc < 0 ? start : end) ? null : makeRecover(i / 3, pos - start), del = 0;
|
|
90
|
+
return oldSize && (del |= pos == start ? DEL_AFTER : pos == end ? DEL_BEFORE : DEL_ACROSS, (assoc < 0 ? pos != start : pos != end) && (del |= DEL_SIDE)), new MapResult(result, del, recover);
|
|
91
|
+
}
|
|
92
|
+
diff += newSize - oldSize;
|
|
93
|
+
}
|
|
94
|
+
return simple ? pos + diff : new MapResult(pos + diff, 0, null);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
@internal
|
|
98
|
+
*/
|
|
99
|
+
touches(pos, recover) {
|
|
100
|
+
let diff = 0, index = recoverIndex(recover), oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;
|
|
101
|
+
for (let i = 0; i < this.ranges.length; i += 3) {
|
|
102
|
+
let start = this.ranges[i] - (this.inverted ? diff : 0);
|
|
103
|
+
if (start > pos)
|
|
104
|
+
break;
|
|
105
|
+
let oldSize = this.ranges[i + oldIndex], end = start + oldSize;
|
|
106
|
+
if (pos <= end && i == index * 3)
|
|
107
|
+
return !0;
|
|
108
|
+
diff += this.ranges[i + newIndex] - oldSize;
|
|
109
|
+
}
|
|
110
|
+
return !1;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
Calls the given function on each of the changed ranges included in
|
|
114
|
+
this map.
|
|
115
|
+
*/
|
|
116
|
+
forEach(f) {
|
|
117
|
+
let oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;
|
|
118
|
+
for (let i = 0, diff = 0; i < this.ranges.length; i += 3) {
|
|
119
|
+
let start = this.ranges[i], oldStart = start - (this.inverted ? diff : 0), newStart = start + (this.inverted ? 0 : diff), oldSize = this.ranges[i + oldIndex], newSize = this.ranges[i + newIndex];
|
|
120
|
+
f(oldStart, oldStart + oldSize, newStart, newStart + newSize), diff += newSize - oldSize;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
Create an inverted version of this map. The result can be used to
|
|
125
|
+
map positions in the post-step document to the pre-step document.
|
|
126
|
+
*/
|
|
127
|
+
invert() {
|
|
128
|
+
return new StepMap(this.ranges, !this.inverted);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
@internal
|
|
132
|
+
*/
|
|
133
|
+
toString() {
|
|
134
|
+
return (this.inverted ? "-" : "") + JSON.stringify(this.ranges);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
Create a map that moves all positions by offset `n` (which may be
|
|
138
|
+
negative). This can be useful when applying steps meant for a
|
|
139
|
+
sub-document to a larger document, or vice-versa.
|
|
140
|
+
*/
|
|
141
|
+
static offset(n) {
|
|
142
|
+
return n == 0 ? StepMap.empty : new StepMap(n < 0 ? [0, -n, 0] : [0, 0, n]);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
StepMap.empty = new StepMap([]);
|
|
146
|
+
const stepsByID = /* @__PURE__ */ Object.create(null);
|
|
147
|
+
class Step {
|
|
148
|
+
/**
|
|
149
|
+
Get the step map that represents the changes made by this step,
|
|
150
|
+
and which can be used to transform between positions in the old
|
|
151
|
+
and the new document.
|
|
152
|
+
*/
|
|
153
|
+
getMap() {
|
|
154
|
+
return StepMap.empty;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
Try to merge this step with another one, to be applied directly
|
|
158
|
+
after it. Returns the merged step when possible, null if the
|
|
159
|
+
steps can't be merged.
|
|
160
|
+
*/
|
|
161
|
+
merge(other) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
Deserialize a step from its JSON representation. Will call
|
|
166
|
+
through to the step class' own implementation of this method.
|
|
167
|
+
*/
|
|
168
|
+
static fromJSON(schema, json) {
|
|
169
|
+
if (!json || !json.stepType)
|
|
170
|
+
throw new RangeError("Invalid input for Step.fromJSON");
|
|
171
|
+
let type = stepsByID[json.stepType];
|
|
172
|
+
if (!type)
|
|
173
|
+
throw new RangeError(`No step type ${json.stepType} defined`);
|
|
174
|
+
return type.fromJSON(schema, json);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
To be able to serialize steps to JSON, each step needs a string
|
|
178
|
+
ID to attach to its JSON representation. Use this method to
|
|
179
|
+
register an ID for your step classes. Try to pick something
|
|
180
|
+
that's unlikely to clash with steps from other modules.
|
|
181
|
+
*/
|
|
182
|
+
static jsonID(id, stepClass) {
|
|
183
|
+
if (id in stepsByID)
|
|
184
|
+
throw new RangeError("Duplicate use of step JSON ID " + id);
|
|
185
|
+
return stepsByID[id] = stepClass, stepClass.prototype.jsonID = id, stepClass;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
class StepResult {
|
|
189
|
+
/**
|
|
190
|
+
@internal
|
|
191
|
+
*/
|
|
192
|
+
constructor(doc, failed) {
|
|
193
|
+
this.doc = doc, this.failed = failed;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
Create a successful step result.
|
|
197
|
+
*/
|
|
198
|
+
static ok(doc) {
|
|
199
|
+
return new StepResult(doc, null);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
Create a failed step result.
|
|
203
|
+
*/
|
|
204
|
+
static fail(message) {
|
|
205
|
+
return new StepResult(null, message);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
Call [`Node.replace`](https://prosemirror.net/docs/ref/#model.Node.replace) with the given
|
|
209
|
+
arguments. Create a successful result if it succeeds, and a
|
|
210
|
+
failed one if it throws a `ReplaceError`.
|
|
211
|
+
*/
|
|
212
|
+
static fromReplace(doc, from, to, slice) {
|
|
213
|
+
try {
|
|
214
|
+
return StepResult.ok(doc.replace(from, to, slice));
|
|
215
|
+
} catch (e) {
|
|
216
|
+
if (e instanceof ReplaceError)
|
|
217
|
+
return StepResult.fail(e.message);
|
|
218
|
+
throw e;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
function mapFragment(fragment, f, parent) {
|
|
223
|
+
let mapped = [];
|
|
224
|
+
for (let i = 0; i < fragment.childCount; i++) {
|
|
225
|
+
let child = fragment.child(i);
|
|
226
|
+
child.content.size && (child = child.copy(mapFragment(child.content, f, child))), child.isInline && (child = f(child, parent, i)), mapped.push(child);
|
|
227
|
+
}
|
|
228
|
+
return Fragment.fromArray(mapped);
|
|
229
|
+
}
|
|
230
|
+
class AddMarkStep extends Step {
|
|
231
|
+
/**
|
|
232
|
+
Create a mark step.
|
|
233
|
+
*/
|
|
234
|
+
constructor(from, to, mark) {
|
|
235
|
+
super(), this.from = from, this.to = to, this.mark = mark;
|
|
236
|
+
}
|
|
237
|
+
apply(doc) {
|
|
238
|
+
let oldSlice = doc.slice(this.from, this.to), $from = doc.resolve(this.from), parent = $from.node($from.sharedDepth(this.to)), slice = new Slice(mapFragment(oldSlice.content, (node, parent2) => !node.isAtom || !parent2.type.allowsMarkType(this.mark.type) ? node : node.mark(this.mark.addToSet(node.marks)), parent), oldSlice.openStart, oldSlice.openEnd);
|
|
239
|
+
return StepResult.fromReplace(doc, this.from, this.to, slice);
|
|
240
|
+
}
|
|
241
|
+
invert() {
|
|
242
|
+
return new RemoveMarkStep(this.from, this.to, this.mark);
|
|
243
|
+
}
|
|
244
|
+
map(mapping) {
|
|
245
|
+
let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
|
|
246
|
+
return from.deleted && to.deleted || from.pos >= to.pos ? null : new AddMarkStep(from.pos, to.pos, this.mark);
|
|
247
|
+
}
|
|
248
|
+
merge(other) {
|
|
249
|
+
return other instanceof AddMarkStep && other.mark.eq(this.mark) && this.from <= other.to && this.to >= other.from ? new AddMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark) : null;
|
|
250
|
+
}
|
|
251
|
+
toJSON() {
|
|
252
|
+
return {
|
|
253
|
+
stepType: "addMark",
|
|
254
|
+
mark: this.mark.toJSON(),
|
|
255
|
+
from: this.from,
|
|
256
|
+
to: this.to
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
@internal
|
|
261
|
+
*/
|
|
262
|
+
static fromJSON(schema, json) {
|
|
263
|
+
if (typeof json.from != "number" || typeof json.to != "number")
|
|
264
|
+
throw new RangeError("Invalid input for AddMarkStep.fromJSON");
|
|
265
|
+
return new AddMarkStep(json.from, json.to, schema.markFromJSON(json.mark));
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
Step.jsonID("addMark", AddMarkStep);
|
|
269
|
+
class RemoveMarkStep extends Step {
|
|
270
|
+
/**
|
|
271
|
+
Create a mark-removing step.
|
|
272
|
+
*/
|
|
273
|
+
constructor(from, to, mark) {
|
|
274
|
+
super(), this.from = from, this.to = to, this.mark = mark;
|
|
275
|
+
}
|
|
276
|
+
apply(doc) {
|
|
277
|
+
let oldSlice = doc.slice(this.from, this.to), slice = new Slice(mapFragment(oldSlice.content, (node) => node.mark(this.mark.removeFromSet(node.marks)), doc), oldSlice.openStart, oldSlice.openEnd);
|
|
278
|
+
return StepResult.fromReplace(doc, this.from, this.to, slice);
|
|
279
|
+
}
|
|
280
|
+
invert() {
|
|
281
|
+
return new AddMarkStep(this.from, this.to, this.mark);
|
|
282
|
+
}
|
|
283
|
+
map(mapping) {
|
|
284
|
+
let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
|
|
285
|
+
return from.deleted && to.deleted || from.pos >= to.pos ? null : new RemoveMarkStep(from.pos, to.pos, this.mark);
|
|
286
|
+
}
|
|
287
|
+
merge(other) {
|
|
288
|
+
return other instanceof RemoveMarkStep && other.mark.eq(this.mark) && this.from <= other.to && this.to >= other.from ? new RemoveMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark) : null;
|
|
289
|
+
}
|
|
290
|
+
toJSON() {
|
|
291
|
+
return {
|
|
292
|
+
stepType: "removeMark",
|
|
293
|
+
mark: this.mark.toJSON(),
|
|
294
|
+
from: this.from,
|
|
295
|
+
to: this.to
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
@internal
|
|
300
|
+
*/
|
|
301
|
+
static fromJSON(schema, json) {
|
|
302
|
+
if (typeof json.from != "number" || typeof json.to != "number")
|
|
303
|
+
throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");
|
|
304
|
+
return new RemoveMarkStep(json.from, json.to, schema.markFromJSON(json.mark));
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
Step.jsonID("removeMark", RemoveMarkStep);
|
|
308
|
+
class AddNodeMarkStep extends Step {
|
|
309
|
+
/**
|
|
310
|
+
Create a node mark step.
|
|
311
|
+
*/
|
|
312
|
+
constructor(pos, mark) {
|
|
313
|
+
super(), this.pos = pos, this.mark = mark;
|
|
314
|
+
}
|
|
315
|
+
apply(doc) {
|
|
316
|
+
let node = doc.nodeAt(this.pos);
|
|
317
|
+
if (!node)
|
|
318
|
+
return StepResult.fail("No node at mark step's position");
|
|
319
|
+
let updated = node.type.create(node.attrs, null, this.mark.addToSet(node.marks));
|
|
320
|
+
return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
|
|
321
|
+
}
|
|
322
|
+
invert(doc) {
|
|
323
|
+
let node = doc.nodeAt(this.pos);
|
|
324
|
+
if (node) {
|
|
325
|
+
let newSet = this.mark.addToSet(node.marks);
|
|
326
|
+
if (newSet.length == node.marks.length) {
|
|
327
|
+
for (let i = 0; i < node.marks.length; i++)
|
|
328
|
+
if (!node.marks[i].isInSet(newSet))
|
|
329
|
+
return new AddNodeMarkStep(this.pos, node.marks[i]);
|
|
330
|
+
return new AddNodeMarkStep(this.pos, this.mark);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return new RemoveNodeMarkStep(this.pos, this.mark);
|
|
334
|
+
}
|
|
335
|
+
map(mapping) {
|
|
336
|
+
let pos = mapping.mapResult(this.pos, 1);
|
|
337
|
+
return pos.deletedAfter ? null : new AddNodeMarkStep(pos.pos, this.mark);
|
|
338
|
+
}
|
|
339
|
+
toJSON() {
|
|
340
|
+
return { stepType: "addNodeMark", pos: this.pos, mark: this.mark.toJSON() };
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
@internal
|
|
344
|
+
*/
|
|
345
|
+
static fromJSON(schema, json) {
|
|
346
|
+
if (typeof json.pos != "number")
|
|
347
|
+
throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");
|
|
348
|
+
return new AddNodeMarkStep(json.pos, schema.markFromJSON(json.mark));
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
Step.jsonID("addNodeMark", AddNodeMarkStep);
|
|
352
|
+
class RemoveNodeMarkStep extends Step {
|
|
353
|
+
/**
|
|
354
|
+
Create a mark-removing step.
|
|
355
|
+
*/
|
|
356
|
+
constructor(pos, mark) {
|
|
357
|
+
super(), this.pos = pos, this.mark = mark;
|
|
358
|
+
}
|
|
359
|
+
apply(doc) {
|
|
360
|
+
let node = doc.nodeAt(this.pos);
|
|
361
|
+
if (!node)
|
|
362
|
+
return StepResult.fail("No node at mark step's position");
|
|
363
|
+
let updated = node.type.create(node.attrs, null, this.mark.removeFromSet(node.marks));
|
|
364
|
+
return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
|
|
365
|
+
}
|
|
366
|
+
invert(doc) {
|
|
367
|
+
let node = doc.nodeAt(this.pos);
|
|
368
|
+
return !node || !this.mark.isInSet(node.marks) ? this : new AddNodeMarkStep(this.pos, this.mark);
|
|
369
|
+
}
|
|
370
|
+
map(mapping) {
|
|
371
|
+
let pos = mapping.mapResult(this.pos, 1);
|
|
372
|
+
return pos.deletedAfter ? null : new RemoveNodeMarkStep(pos.pos, this.mark);
|
|
373
|
+
}
|
|
374
|
+
toJSON() {
|
|
375
|
+
return { stepType: "removeNodeMark", pos: this.pos, mark: this.mark.toJSON() };
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
@internal
|
|
379
|
+
*/
|
|
380
|
+
static fromJSON(schema, json) {
|
|
381
|
+
if (typeof json.pos != "number")
|
|
382
|
+
throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");
|
|
383
|
+
return new RemoveNodeMarkStep(json.pos, schema.markFromJSON(json.mark));
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
Step.jsonID("removeNodeMark", RemoveNodeMarkStep);
|
|
387
|
+
class ReplaceStep extends Step {
|
|
388
|
+
/**
|
|
389
|
+
The given `slice` should fit the 'gap' between `from` and
|
|
390
|
+
`to`—the depths must line up, and the surrounding nodes must be
|
|
391
|
+
able to be joined with the open sides of the slice. When
|
|
392
|
+
`structure` is true, the step will fail if the content between
|
|
393
|
+
from and to is not just a sequence of closing and then opening
|
|
394
|
+
tokens (this is to guard against rebased replace steps
|
|
395
|
+
overwriting something they weren't supposed to).
|
|
396
|
+
*/
|
|
397
|
+
constructor(from, to, slice, structure = !1) {
|
|
398
|
+
super(), this.from = from, this.to = to, this.slice = slice, this.structure = structure;
|
|
399
|
+
}
|
|
400
|
+
apply(doc) {
|
|
401
|
+
return this.structure && contentBetween(doc, this.from, this.to) ? StepResult.fail("Structure replace would overwrite content") : StepResult.fromReplace(doc, this.from, this.to, this.slice);
|
|
402
|
+
}
|
|
403
|
+
getMap() {
|
|
404
|
+
return new StepMap([this.from, this.to - this.from, this.slice.size]);
|
|
405
|
+
}
|
|
406
|
+
invert(doc) {
|
|
407
|
+
return new ReplaceStep(this.from, this.from + this.slice.size, doc.slice(this.from, this.to));
|
|
408
|
+
}
|
|
409
|
+
map(mapping) {
|
|
410
|
+
let to = mapping.mapResult(this.to, -1), from = this.from == this.to && ReplaceStep.MAP_BIAS < 0 ? to : mapping.mapResult(this.from, 1);
|
|
411
|
+
return from.deletedAcross && to.deletedAcross ? null : new ReplaceStep(from.pos, Math.max(from.pos, to.pos), this.slice, this.structure);
|
|
412
|
+
}
|
|
413
|
+
merge(other) {
|
|
414
|
+
if (!(other instanceof ReplaceStep) || other.structure || this.structure)
|
|
415
|
+
return null;
|
|
416
|
+
if (this.from + this.slice.size == other.from && !this.slice.openEnd && !other.slice.openStart) {
|
|
417
|
+
let slice = this.slice.size + other.slice.size == 0 ? Slice.empty : new Slice(this.slice.content.append(other.slice.content), this.slice.openStart, other.slice.openEnd);
|
|
418
|
+
return new ReplaceStep(this.from, this.to + (other.to - other.from), slice, this.structure);
|
|
419
|
+
} else if (other.to == this.from && !this.slice.openStart && !other.slice.openEnd) {
|
|
420
|
+
let slice = this.slice.size + other.slice.size == 0 ? Slice.empty : new Slice(other.slice.content.append(this.slice.content), other.slice.openStart, this.slice.openEnd);
|
|
421
|
+
return new ReplaceStep(other.from, this.to, slice, this.structure);
|
|
422
|
+
} else
|
|
423
|
+
return null;
|
|
424
|
+
}
|
|
425
|
+
toJSON() {
|
|
426
|
+
let json = { stepType: "replace", from: this.from, to: this.to };
|
|
427
|
+
return this.slice.size && (json.slice = this.slice.toJSON()), this.structure && (json.structure = !0), json;
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
@internal
|
|
431
|
+
*/
|
|
432
|
+
static fromJSON(schema, json) {
|
|
433
|
+
if (typeof json.from != "number" || typeof json.to != "number")
|
|
434
|
+
throw new RangeError("Invalid input for ReplaceStep.fromJSON");
|
|
435
|
+
return new ReplaceStep(json.from, json.to, Slice.fromJSON(schema, json.slice), !!json.structure);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
ReplaceStep.MAP_BIAS = 1;
|
|
439
|
+
Step.jsonID("replace", ReplaceStep);
|
|
440
|
+
class ReplaceAroundStep extends Step {
|
|
441
|
+
/**
|
|
442
|
+
Create a replace-around step with the given range and gap.
|
|
443
|
+
`insert` should be the point in the slice into which the content
|
|
444
|
+
of the gap should be moved. `structure` has the same meaning as
|
|
445
|
+
it has in the [`ReplaceStep`](https://prosemirror.net/docs/ref/#transform.ReplaceStep) class.
|
|
446
|
+
*/
|
|
447
|
+
constructor(from, to, gapFrom, gapTo, slice, insert, structure = !1) {
|
|
448
|
+
super(), this.from = from, this.to = to, this.gapFrom = gapFrom, this.gapTo = gapTo, this.slice = slice, this.insert = insert, this.structure = structure;
|
|
449
|
+
}
|
|
450
|
+
apply(doc) {
|
|
451
|
+
if (this.structure && (contentBetween(doc, this.from, this.gapFrom) || contentBetween(doc, this.gapTo, this.to)))
|
|
452
|
+
return StepResult.fail("Structure gap-replace would overwrite content");
|
|
453
|
+
let gap = doc.slice(this.gapFrom, this.gapTo);
|
|
454
|
+
if (gap.openStart || gap.openEnd)
|
|
455
|
+
return StepResult.fail("Gap is not a flat range");
|
|
456
|
+
let inserted = this.slice.insertAt(this.insert, gap.content);
|
|
457
|
+
return inserted ? StepResult.fromReplace(doc, this.from, this.to, inserted) : StepResult.fail("Content does not fit in gap");
|
|
458
|
+
}
|
|
459
|
+
getMap() {
|
|
460
|
+
return new StepMap([
|
|
461
|
+
this.from,
|
|
462
|
+
this.gapFrom - this.from,
|
|
463
|
+
this.insert,
|
|
464
|
+
this.gapTo,
|
|
465
|
+
this.to - this.gapTo,
|
|
466
|
+
this.slice.size - this.insert
|
|
467
|
+
]);
|
|
468
|
+
}
|
|
469
|
+
invert(doc) {
|
|
470
|
+
let gap = this.gapTo - this.gapFrom;
|
|
471
|
+
return new ReplaceAroundStep(this.from, this.from + this.slice.size + gap, this.from + this.insert, this.from + this.insert + gap, doc.slice(this.from, this.to).removeBetween(this.gapFrom - this.from, this.gapTo - this.from), this.gapFrom - this.from, this.structure);
|
|
472
|
+
}
|
|
473
|
+
map(mapping) {
|
|
474
|
+
let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1), gapFrom = this.from == this.gapFrom ? from.pos : mapping.map(this.gapFrom, -1), gapTo = this.to == this.gapTo ? to.pos : mapping.map(this.gapTo, 1);
|
|
475
|
+
return from.deletedAcross && to.deletedAcross || gapFrom < from.pos || gapTo > to.pos ? null : new ReplaceAroundStep(from.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure);
|
|
476
|
+
}
|
|
477
|
+
toJSON() {
|
|
478
|
+
let json = {
|
|
479
|
+
stepType: "replaceAround",
|
|
480
|
+
from: this.from,
|
|
481
|
+
to: this.to,
|
|
482
|
+
gapFrom: this.gapFrom,
|
|
483
|
+
gapTo: this.gapTo,
|
|
484
|
+
insert: this.insert
|
|
485
|
+
};
|
|
486
|
+
return this.slice.size && (json.slice = this.slice.toJSON()), this.structure && (json.structure = !0), json;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
@internal
|
|
490
|
+
*/
|
|
491
|
+
static fromJSON(schema, json) {
|
|
492
|
+
if (typeof json.from != "number" || typeof json.to != "number" || typeof json.gapFrom != "number" || typeof json.gapTo != "number" || typeof json.insert != "number")
|
|
493
|
+
throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");
|
|
494
|
+
return new ReplaceAroundStep(json.from, json.to, json.gapFrom, json.gapTo, Slice.fromJSON(schema, json.slice), json.insert, !!json.structure);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
Step.jsonID("replaceAround", ReplaceAroundStep);
|
|
498
|
+
function contentBetween(doc, from, to) {
|
|
499
|
+
let $from = doc.resolve(from), dist = to - from, depth = $from.depth;
|
|
500
|
+
for (; dist > 0 && depth > 0 && $from.indexAfter(depth) == $from.node(depth).childCount; )
|
|
501
|
+
depth--, dist--;
|
|
502
|
+
if (dist > 0) {
|
|
503
|
+
let next = $from.node(depth).maybeChild($from.indexAfter(depth));
|
|
504
|
+
for (; dist > 0; ) {
|
|
505
|
+
if (!next || next.isLeaf)
|
|
506
|
+
return !0;
|
|
507
|
+
next = next.firstChild, dist--;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
return !1;
|
|
511
|
+
}
|
|
512
|
+
class AttrStep extends Step {
|
|
513
|
+
/**
|
|
514
|
+
Construct an attribute step.
|
|
515
|
+
*/
|
|
516
|
+
constructor(pos, attr, value) {
|
|
517
|
+
super(), this.pos = pos, this.attr = attr, this.value = value;
|
|
518
|
+
}
|
|
519
|
+
apply(doc) {
|
|
520
|
+
let node = doc.nodeAt(this.pos);
|
|
521
|
+
if (!node)
|
|
522
|
+
return StepResult.fail("No node at attribute step's position");
|
|
523
|
+
let attrs = /* @__PURE__ */ Object.create(null);
|
|
524
|
+
for (let name in node.attrs)
|
|
525
|
+
attrs[name] = node.attrs[name];
|
|
526
|
+
attrs[this.attr] = this.value;
|
|
527
|
+
let updated = node.type.create(attrs, null, node.marks);
|
|
528
|
+
return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
|
|
529
|
+
}
|
|
530
|
+
getMap() {
|
|
531
|
+
return StepMap.empty;
|
|
532
|
+
}
|
|
533
|
+
invert(doc) {
|
|
534
|
+
return new AttrStep(this.pos, this.attr, doc.nodeAt(this.pos).attrs[this.attr]);
|
|
535
|
+
}
|
|
536
|
+
map(mapping) {
|
|
537
|
+
let pos = mapping.mapResult(this.pos, 1);
|
|
538
|
+
return pos.deletedAfter ? null : new AttrStep(pos.pos, this.attr, this.value);
|
|
539
|
+
}
|
|
540
|
+
toJSON() {
|
|
541
|
+
return { stepType: "attr", pos: this.pos, attr: this.attr, value: this.value };
|
|
542
|
+
}
|
|
543
|
+
static fromJSON(schema, json) {
|
|
544
|
+
if (typeof json.pos != "number" || typeof json.attr != "string")
|
|
545
|
+
throw new RangeError("Invalid input for AttrStep.fromJSON");
|
|
546
|
+
return new AttrStep(json.pos, json.attr, json.value);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
Step.jsonID("attr", AttrStep);
|
|
550
|
+
class DocAttrStep extends Step {
|
|
551
|
+
/**
|
|
552
|
+
Construct an attribute step.
|
|
553
|
+
*/
|
|
554
|
+
constructor(attr, value) {
|
|
555
|
+
super(), this.attr = attr, this.value = value;
|
|
556
|
+
}
|
|
557
|
+
apply(doc) {
|
|
558
|
+
let attrs = /* @__PURE__ */ Object.create(null);
|
|
559
|
+
for (let name in doc.attrs)
|
|
560
|
+
attrs[name] = doc.attrs[name];
|
|
561
|
+
attrs[this.attr] = this.value;
|
|
562
|
+
let updated = doc.type.create(attrs, doc.content, doc.marks);
|
|
563
|
+
return StepResult.ok(updated);
|
|
564
|
+
}
|
|
565
|
+
getMap() {
|
|
566
|
+
return StepMap.empty;
|
|
567
|
+
}
|
|
568
|
+
invert(doc) {
|
|
569
|
+
return new DocAttrStep(this.attr, doc.attrs[this.attr]);
|
|
570
|
+
}
|
|
571
|
+
map(mapping) {
|
|
572
|
+
return this;
|
|
573
|
+
}
|
|
574
|
+
toJSON() {
|
|
575
|
+
return { stepType: "docAttr", attr: this.attr, value: this.value };
|
|
576
|
+
}
|
|
577
|
+
static fromJSON(schema, json) {
|
|
578
|
+
if (typeof json.attr != "string")
|
|
579
|
+
throw new RangeError("Invalid input for DocAttrStep.fromJSON");
|
|
580
|
+
return new DocAttrStep(json.attr, json.value);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
Step.jsonID("docAttr", DocAttrStep);
|
|
584
|
+
let TransformError = class extends Error {
|
|
585
|
+
};
|
|
586
|
+
TransformError = function TransformError2(message) {
|
|
587
|
+
let err = Error.call(this, message);
|
|
588
|
+
return err.__proto__ = TransformError2.prototype, err;
|
|
589
|
+
};
|
|
590
|
+
TransformError.prototype = Object.create(Error.prototype);
|
|
591
|
+
TransformError.prototype.constructor = TransformError;
|
|
592
|
+
TransformError.prototype.name = "TransformError";
|
|
593
|
+
export {
|
|
594
|
+
AddMarkStep,
|
|
595
|
+
AddNodeMarkStep,
|
|
596
|
+
AttrStep,
|
|
597
|
+
DocAttrStep,
|
|
598
|
+
MapResult,
|
|
599
|
+
RemoveMarkStep,
|
|
600
|
+
RemoveNodeMarkStep,
|
|
601
|
+
ReplaceAroundStep,
|
|
602
|
+
ReplaceStep,
|
|
603
|
+
Step,
|
|
604
|
+
StepMap,
|
|
605
|
+
StepResult,
|
|
606
|
+
TransformError
|
|
607
|
+
};
|