smartrte-core 1.0.0-beta.6 → 1.0.0-beta.8
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/CHANGELOG.md +8 -0
- package/LICENSE +21 -0
- package/README.md +54 -17
- package/dist/foundation/block/commands.js +27 -0
- package/dist/foundation/clipboard/transfer.js +99 -27
- package/dist/foundation/surface/input.js +23 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.8
|
|
4
|
+
|
|
5
|
+
- Fix Blockquote (and unwrap) throwing an uncaught error ("replaceNode before payload does not match document node.") and applying nothing, for a selection spanning a list item's own text and a nested sub-list item's text — two selected blocks resolving to two different, nested "list" ancestors were treated as independent (and mutually conflicting) wrap targets instead of recognizing the inner one is already covered by the outer one. Also fixed the identical latent issue for unwrapping nested blockquotes (the schema allows blockquote nesting), even though no live report had surfaced it yet. See `docs/bugs/blockquote-crashes-on-selection-spanning-outer-and-nested-list.md`.
|
|
6
|
+
|
|
7
|
+
## 1.0.0-beta.7
|
|
8
|
+
|
|
9
|
+
- Fix copy, cut, and native drag throwing an uncaught error ("Clipboard copy is clamped to one structural parent.") for any selection whose two endpoints weren't immediate siblings — e.g. starting in a plain paragraph and dragging into a nested list item, or spanning two list items at different nesting depths. This was not an exotic shape: any selection reaching into a list, table, or blockquote from outside it hit this, and the failure was a silent no-op (nothing copied) with a console error, not a graceful fallback. See `docs/bugs/clipboard-copy-cut-throws-across-differently-nested-endpoints.md`.
|
|
10
|
+
|
|
3
11
|
## 1.0.0-beta.6
|
|
4
12
|
|
|
5
13
|
- Fix pasting a long, list-free document (many short paragraphs, no images) being slow enough to look broken — the Office/Google Docs list normalizers recursed into every paragraph hunting for nested lists a `<p>` can never structurally contain. Pasting a few thousand blocks now completes in well under a second instead of multiple seconds to tens of seconds. See `docs/bugs/clipboard-paste-slow-on-large-list-free-documents.md` for the full investigation, including a known remaining limitation for very large (10,000+ block) pastes.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Smart RTE Contributors
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,28 +1,65 @@
|
|
|
1
|
-
#
|
|
1
|
+
# smartrte-core
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
React editor; it establishes the compatibility-safe migration boundary.
|
|
3
|
+
[](https://www.npmjs.com/package/smartrte-core)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
Framework-agnostic document model, selection, transaction, and editing primitives that power [`smartrte-react`](https://www.npmjs.com/package/smartrte-react). Everything here is plain TypeScript with no DOM/React dependency in its core data structures — schema, operations, and history all operate on a plain JSON document tree.
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
**If you're building a React app, install `smartrte-react` instead** — it depends on this package and re-exports everything you're likely to need. Install `smartrte-core` directly only if you're building a custom editing surface (a different UI framework, a headless document pipeline, a server-side format converter) on top of the same document model.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install smartrte-core
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## What's in here
|
|
10
17
|
|
|
11
18
|
```ts
|
|
12
19
|
import {
|
|
13
20
|
createFoundationEditor,
|
|
14
21
|
foundationSchema,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
type SmartTransaction,
|
|
22
|
+
createPluginRegistry,
|
|
23
|
+
builtInPlugins,
|
|
18
24
|
} from "smartrte-core/foundation";
|
|
19
25
|
```
|
|
20
26
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
- **Document model & schema** (`types`, `schema`, `identity`) — a plain JSON tree of typed nodes (paragraph, heading, list, table, image, formula, ...), each with a stable id that survives edits.
|
|
28
|
+
- **Editing engine** (`editor`, `transactions`, `operations`, `history`) — `createFoundationEditor` builds a stateful editor: dispatch a transaction, get back an updated document plus mapped selection, with full undo/redo.
|
|
29
|
+
- **Selection & scope resolution** (`scope/`) — resolves "what does the current selection actually touch" (a text range, a set of list items, a table-cell rectangle, a mix) so commands can act on the right thing regardless of how deeply nested it is.
|
|
30
|
+
- **Browser input surface** (`surface/`) — the `beforeinput`/paste/cut/drop/composition handling layer a real contentEditable-backed UI wires up to; this is what `smartrte-react` builds its editing surface on.
|
|
31
|
+
- **Format adapters** (`formats/`) — HTML, Markdown, DOCX (via `mammoth`/`@xmldom`), and PDF (`pdfjs-dist`) import/export, each declaring an explicit fidelity contract (`builtInFormatFidelity`) for exactly what's lossless vs. lossy per format/feature pair.
|
|
32
|
+
- **Diff, versioning, comments, suggestions, plugin system** (`diff/`, `versioning/`, `comments/`, `suggestions/`, `plugin/`) — the primitives `smartrte-react`'s version history, comment threads, and track-changes UI are built on. A `PluginRegistry` (`createPluginRegistry`, `builtInPlugins`) is how new commands, keyboard shortcuts, toolbar contributions, and renderer behavior are added — see [`docs/PLUGIN_ARCHITECTURE.md`](https://github.com/ayush1852017/smart-rte/blob/master/docs/PLUGIN_ARCHITECTURE.md) in the repository.
|
|
33
|
+
- **Collab contract** (`collab/`) — the operation-transform machinery (`mapOperation`) a real-time transport would rebase concurrent edits through. A contract for hosts building multi-writer collaboration against; no transport implementation ships here.
|
|
34
|
+
|
|
35
|
+
## Subpath exports
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
".": "compatibility root (legacy pre-foundation API)",
|
|
40
|
+
"./foundation": "the current, actively-developed API - use this",
|
|
41
|
+
"./legacy": "retired raw-path contracts, kept only for migration"
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
New code should import from `smartrte-core/foundation` exclusively. The package root is a compatibility surface for older integrations; it is not where new capability lands.
|
|
46
|
+
|
|
47
|
+
## Security
|
|
48
|
+
|
|
49
|
+
Format importers (HTML, DOCX, PDF) sanitize what they parse (DOMPurify for HTML), but this package holds no storage credentials and performs no network I/O itself — persistence, uploads, and real-time transport are all host-owned boundaries (see `smartrte-react`'s `MediaProvider`/`VersionProvider`/`CommentProvider`/`SuggestionProvider`/`CollabTransport`).
|
|
50
|
+
|
|
51
|
+
## Development
|
|
52
|
+
|
|
53
|
+
This package lives in a pnpm workspace monorepo alongside `smartrte-react`.
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
git clone https://github.com/ayush1852017/smart-rte.git
|
|
57
|
+
cd smart-rte
|
|
58
|
+
pnpm install
|
|
59
|
+
pnpm --filter smartrte-core build
|
|
60
|
+
pnpm --filter smartrte-core test
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
|
|
65
|
+
MIT — see [LICENSE](https://github.com/ayush1852017/smart-rte/blob/master/LICENSE).
|
|
@@ -29,6 +29,31 @@ const ancestorWithRole = (nodeId, role, ctx) => {
|
|
|
29
29
|
}
|
|
30
30
|
return null;
|
|
31
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* Two different selected blocks can resolve to two different target
|
|
34
|
+
* ancestors (both matching `role`) where one target is itself nested inside
|
|
35
|
+
* the other - e.g. a selection spanning a top-level list item and a
|
|
36
|
+
* sub-item of its own nested list has one selected block whose nearest
|
|
37
|
+
* "list" ancestor is the outer list, and another whose nearest "list"
|
|
38
|
+
* ancestor is the inner one. Both are real, valid `role` ancestors, but
|
|
39
|
+
* treating them as two independent wrap/unwrap targets is wrong: the outer
|
|
40
|
+
* target's own subtree already contains the inner one, so replacing both
|
|
41
|
+
* separately means the second operation's `before` snapshot (captured
|
|
42
|
+
* against the pre-edit document) no longer matches the document by the time
|
|
43
|
+
* it runs, since the first operation already mutated a node inside it -
|
|
44
|
+
* `applyOperations` throws "replaceNode before payload does not match
|
|
45
|
+
* document node." Kept only the outermost target per such chain - wrapping/
|
|
46
|
+
* unwrapping it already covers everything nested inside it.
|
|
47
|
+
*/
|
|
48
|
+
const dropNestedTargets = (targets, ctx) => {
|
|
49
|
+
const idsToDrop = [];
|
|
50
|
+
targets.forEach((_target, id) => {
|
|
51
|
+
const resolved = ctx.positions.positionOf(id);
|
|
52
|
+
if (resolved?.ancestors.some((ancestor) => ancestor.id !== id && targets.has(ancestor.id)))
|
|
53
|
+
idsToDrop.push(id);
|
|
54
|
+
});
|
|
55
|
+
idsToDrop.forEach((id) => targets.delete(id));
|
|
56
|
+
};
|
|
32
57
|
const ancestorTargets = (scope, role, ctx) => {
|
|
33
58
|
const targets = new Map();
|
|
34
59
|
selectedBlockIds(scope).forEach((nodeId) => {
|
|
@@ -37,6 +62,7 @@ const ancestorTargets = (scope, role, ctx) => {
|
|
|
37
62
|
return;
|
|
38
63
|
targets.set(ancestor.id, locate(ancestor.id, ctx));
|
|
39
64
|
});
|
|
65
|
+
dropNestedTargets(targets, ctx);
|
|
40
66
|
return [...targets.values()].sort((left, right) => right.pos.path.length - left.pos.path.length || right.pos.offset - left.pos.offset);
|
|
41
67
|
};
|
|
42
68
|
const typeAttrs = (node, type, attrs) => {
|
|
@@ -145,6 +171,7 @@ export const unwrapBlocks = (_document, scope, params, ctx) => {
|
|
|
145
171
|
return;
|
|
146
172
|
wrappers.set(target.id, locate(target.id, ctx));
|
|
147
173
|
});
|
|
174
|
+
dropNestedTargets(wrappers, ctx);
|
|
148
175
|
return [...wrappers.values()].sort((left, right) => right.pos.path.length - left.pos.path.length || right.pos.offset - left.pos.offset).flatMap(({ node, pos }) => {
|
|
149
176
|
if (node.type !== wrapperType)
|
|
150
177
|
return [];
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { isTextNode } from "../identity.js";
|
|
2
2
|
import { comparePos, nodeAtPath } from "../positions.js";
|
|
3
3
|
const samePath = (left, right) => left.length === right.length && left.every((part, index) => part === right[index]);
|
|
4
|
+
const commonPrefixLength = (left, right) => {
|
|
5
|
+
let index = 0;
|
|
6
|
+
while (index < left.length && index < right.length && left[index] === right[index])
|
|
7
|
+
index += 1;
|
|
8
|
+
return index;
|
|
9
|
+
};
|
|
4
10
|
const size = (node) => isTextNode(node) ? node.text.length : 1;
|
|
5
11
|
const split = (children, offset) => {
|
|
6
12
|
const before = [];
|
|
@@ -31,6 +37,42 @@ const element = (document, pos) => {
|
|
|
31
37
|
throw new Error("Clipboard selection owner is invalid.");
|
|
32
38
|
return node;
|
|
33
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* `node`'s content, keeping only what lies at-or-after (path, offset) within it -
|
|
42
|
+
* fully-included later siblings at every level, and a recursively-trimmed branch
|
|
43
|
+
* for the one that actually contains the position. Used for the tail (or "from")
|
|
44
|
+
* endpoint of a selection that crosses into a different structural ancestor than
|
|
45
|
+
* its other endpoint (e.g. from a plain paragraph into a nested list item) - a
|
|
46
|
+
* selection shape that isn't naturally isTextNode/same-parent, but is still a
|
|
47
|
+
* perfectly ordinary drag-selection a user can make.
|
|
48
|
+
*/
|
|
49
|
+
const afterSlice = (node, path, offset) => {
|
|
50
|
+
const children = node.children || [];
|
|
51
|
+
if (path.length === 0) {
|
|
52
|
+
const [, tail] = split(children, offset);
|
|
53
|
+
return { ...node, children: tail };
|
|
54
|
+
}
|
|
55
|
+
const index = path[0];
|
|
56
|
+
const child = children[index];
|
|
57
|
+
if (!child || isTextNode(child))
|
|
58
|
+
throw new Error("Clipboard selection path is malformed.");
|
|
59
|
+
const rest = children.slice(index + 1).map((sibling) => structuredClone(sibling));
|
|
60
|
+
return { ...node, children: [afterSlice(child, path.slice(1), offset), ...rest] };
|
|
61
|
+
};
|
|
62
|
+
/** Mirror of {@link afterSlice}: keeps only what lies strictly before (path, offset). */
|
|
63
|
+
const beforeSlice = (node, path, offset) => {
|
|
64
|
+
const children = node.children || [];
|
|
65
|
+
if (path.length === 0) {
|
|
66
|
+
const [before] = split(children, offset);
|
|
67
|
+
return { ...node, children: before };
|
|
68
|
+
}
|
|
69
|
+
const index = path[0];
|
|
70
|
+
const child = children[index];
|
|
71
|
+
if (!child || isTextNode(child))
|
|
72
|
+
throw new Error("Clipboard selection path is malformed.");
|
|
73
|
+
const rest = children.slice(0, index).map((sibling) => structuredClone(sibling));
|
|
74
|
+
return { ...node, children: [...rest, beforeSlice(child, path.slice(1), offset)] };
|
|
75
|
+
};
|
|
34
76
|
export const sliceClipboardSelection = (document, selection) => {
|
|
35
77
|
const selected = range(selection);
|
|
36
78
|
if (selection.type === "node" || selection.type === "cell") {
|
|
@@ -45,24 +87,27 @@ export const sliceClipboardSelection = (document, selection) => {
|
|
|
45
87
|
const [content] = split(tail, selected.to.offset - selected.from.offset);
|
|
46
88
|
return { type: "doc", id: document.id, children: [{ ...fromOwner, children: content }] };
|
|
47
89
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
90
|
+
// The two endpoints don't share an immediate parent - they may still share a
|
|
91
|
+
// deeper common ancestor (e.g. one endpoint is a plain paragraph and the other
|
|
92
|
+
// is nested inside a list item or table cell several levels down, an entirely
|
|
93
|
+
// ordinary drag-selection). Slice each endpoint's own top-level branch under
|
|
94
|
+
// that ancestor recursively, rather than assuming a flat sibling relationship.
|
|
95
|
+
const commonLength = commonPrefixLength(selected.from.path, selected.to.path);
|
|
96
|
+
const ancestorPath = selected.from.path.slice(0, commonLength);
|
|
97
|
+
const ancestor = nodeAtPath(document, ancestorPath);
|
|
98
|
+
if (!ancestor || isTextNode(ancestor) || !ancestor.children)
|
|
99
|
+
throw new Error("Clipboard selection ancestor is invalid.");
|
|
100
|
+
const fromIndex = selected.from.path[commonLength];
|
|
101
|
+
const toIndex = selected.to.path[commonLength];
|
|
102
|
+
const fromBranch = ancestor.children[fromIndex];
|
|
103
|
+
const toBranch = ancestor.children[toIndex];
|
|
104
|
+
if (!fromBranch || !toBranch || isTextNode(fromBranch) || isTextNode(toBranch))
|
|
105
|
+
throw new Error("Clipboard selection endpoint is invalid.");
|
|
106
|
+
const first = afterSlice(fromBranch, selected.from.path.slice(commonLength + 1), selected.from.offset);
|
|
107
|
+
const last = beforeSlice(toBranch, selected.to.path.slice(commonLength + 1), selected.to.offset);
|
|
59
108
|
return {
|
|
60
109
|
type: "doc", id: document.id,
|
|
61
|
-
children: [
|
|
62
|
-
{ ...fromOwner, children: first },
|
|
63
|
-
...parent.children.slice(fromIndex + 1, toIndex).map((node) => structuredClone(node)),
|
|
64
|
-
{ ...toOwner, children: last },
|
|
65
|
-
],
|
|
110
|
+
children: [first, ...ancestor.children.slice(fromIndex + 1, toIndex).map((node) => structuredClone(node)), last],
|
|
66
111
|
};
|
|
67
112
|
};
|
|
68
113
|
export const deleteClipboardSelection = (document, selection, positions) => {
|
|
@@ -91,18 +136,45 @@ export const deleteClipboardSelection = (document, selection, positions) => {
|
|
|
91
136
|
};
|
|
92
137
|
}
|
|
93
138
|
const parentPath = selected.from.path.slice(0, -1);
|
|
94
|
-
const parent = nodeAtPath(document, parentPath);
|
|
95
139
|
const toOwner = element(document, selected.to);
|
|
96
|
-
if (
|
|
97
|
-
|
|
140
|
+
if (samePath(parentPath, selected.to.path.slice(0, -1))) {
|
|
141
|
+
const parent = nodeAtPath(document, parentPath);
|
|
142
|
+
if (!parent || isTextNode(parent) || !parent.children)
|
|
143
|
+
throw new Error("Clipboard deletion parent is invalid.");
|
|
144
|
+
const fromIndex = selected.from.path[selected.from.path.length - 1];
|
|
145
|
+
const toIndex = selected.to.path[selected.to.path.length - 1];
|
|
146
|
+
const [before] = split(owner.children || [], selected.from.offset);
|
|
147
|
+
const [, after] = split(toOwner.children || [], selected.to.offset);
|
|
148
|
+
const operations = [];
|
|
149
|
+
for (let index = toIndex; index > fromIndex; index -= 1)
|
|
150
|
+
operations.push({ type: "removeNode", pos: { path: [...parentPath], offset: index }, node: parent.children[index] });
|
|
151
|
+
operations.push({ type: "replaceNode", pos: ownerPosition.pos, before: owner, after: { ...owner, children: [...before, ...after] } });
|
|
152
|
+
return { operations, selectionTarget: { ownerId: owner.id, offset: selected.from.offset } };
|
|
153
|
+
}
|
|
154
|
+
// Endpoints live under different immediate parents (e.g. cutting from a plain
|
|
155
|
+
// paragraph into a nested list item) - too structurally different to merge
|
|
156
|
+
// into one owner the way same-parent siblings do above, but still coherent:
|
|
157
|
+
// trim each endpoint's own top-level branch down to what's unselected, remove
|
|
158
|
+
// any branch fully between them, and leave both trimmed branches in place.
|
|
159
|
+
const commonLength = commonPrefixLength(selected.from.path, selected.to.path);
|
|
160
|
+
const ancestorPath = selected.from.path.slice(0, commonLength);
|
|
161
|
+
const ancestor = nodeAtPath(document, ancestorPath);
|
|
162
|
+
if (!ancestor || isTextNode(ancestor) || !ancestor.children)
|
|
163
|
+
throw new Error("Clipboard deletion ancestor is invalid.");
|
|
164
|
+
const fromIndex = selected.from.path[commonLength];
|
|
165
|
+
const toIndex = selected.to.path[commonLength];
|
|
166
|
+
const fromBranch = ancestor.children[fromIndex];
|
|
167
|
+
const toBranch = ancestor.children[toIndex];
|
|
168
|
+
if (!fromBranch || !toBranch || isTextNode(fromBranch) || isTextNode(toBranch))
|
|
169
|
+
throw new Error("Clipboard deletion endpoint is invalid.");
|
|
170
|
+
const trimmedFrom = beforeSlice(fromBranch, selected.from.path.slice(commonLength + 1), selected.from.offset);
|
|
171
|
+
const trimmedTo = afterSlice(toBranch, selected.to.path.slice(commonLength + 1), selected.to.offset);
|
|
172
|
+
const operations = [
|
|
173
|
+
{ type: "replaceNode", pos: { path: [...ancestorPath], offset: toIndex }, before: toBranch, after: trimmedTo },
|
|
174
|
+
];
|
|
175
|
+
for (let index = toIndex - 1; index > fromIndex; index -= 1) {
|
|
176
|
+
operations.push({ type: "removeNode", pos: { path: [...ancestorPath], offset: index }, node: ancestor.children[index] });
|
|
98
177
|
}
|
|
99
|
-
|
|
100
|
-
const toIndex = selected.to.path[selected.to.path.length - 1];
|
|
101
|
-
const [before] = split(owner.children || [], selected.from.offset);
|
|
102
|
-
const [, after] = split(toOwner.children || [], selected.to.offset);
|
|
103
|
-
const operations = [];
|
|
104
|
-
for (let index = toIndex; index > fromIndex; index -= 1)
|
|
105
|
-
operations.push({ type: "removeNode", pos: { path: [...parentPath], offset: index }, node: parent.children[index] });
|
|
106
|
-
operations.push({ type: "replaceNode", pos: ownerPosition.pos, before: owner, after: { ...owner, children: [...before, ...after] } });
|
|
178
|
+
operations.push({ type: "replaceNode", pos: { path: [...ancestorPath], offset: fromIndex }, before: fromBranch, after: trimmedFrom });
|
|
107
179
|
return { operations, selectionTarget: { ownerId: owner.id, offset: selected.from.offset } };
|
|
108
180
|
};
|
|
@@ -601,15 +601,25 @@ export class FoundationInputPipeline {
|
|
|
601
601
|
if (!event.clipboardData || collapsed(this.editor.selection))
|
|
602
602
|
return;
|
|
603
603
|
event.preventDefault();
|
|
604
|
-
|
|
604
|
+
try {
|
|
605
|
+
this.writeTransfer(event.clipboardData, sliceClipboardSelection(this.editor.document, this.editor.selection));
|
|
606
|
+
}
|
|
607
|
+
catch {
|
|
608
|
+
this.unhandled.push("copy-rejected");
|
|
609
|
+
}
|
|
605
610
|
}
|
|
606
611
|
handleCut(event) {
|
|
607
612
|
if (!event.clipboardData || collapsed(this.editor.selection))
|
|
608
613
|
return;
|
|
609
614
|
event.preventDefault();
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
615
|
+
try {
|
|
616
|
+
this.writeTransfer(event.clipboardData, sliceClipboardSelection(this.editor.document, this.editor.selection));
|
|
617
|
+
const deletion = deleteClipboardSelection(this.editor.document, this.editor.selection, this.editor.positions);
|
|
618
|
+
this.commitClipboard({ ...deletion, definingAncestorId: null }, "cut");
|
|
619
|
+
}
|
|
620
|
+
catch {
|
|
621
|
+
this.unhandled.push("cut-rejected");
|
|
622
|
+
}
|
|
613
623
|
}
|
|
614
624
|
handlePaste(event) {
|
|
615
625
|
event.preventDefault();
|
|
@@ -635,10 +645,15 @@ export class FoundationInputPipeline {
|
|
|
635
645
|
handleDragStart(event) {
|
|
636
646
|
if (!event.dataTransfer || collapsed(this.editor.selection))
|
|
637
647
|
return;
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
648
|
+
try {
|
|
649
|
+
const fragment = sliceClipboardSelection(this.editor.document, this.editor.selection);
|
|
650
|
+
this.internalDrag = { selection: this.editor.selection, fragment };
|
|
651
|
+
this.writeTransfer(event.dataTransfer, fragment);
|
|
652
|
+
event.dataTransfer.effectAllowed = "move";
|
|
653
|
+
}
|
|
654
|
+
catch {
|
|
655
|
+
this.unhandled.push("dragstart-rejected");
|
|
656
|
+
}
|
|
642
657
|
}
|
|
643
658
|
handleDrop(event) {
|
|
644
659
|
event.preventDefault();
|