smartrte-core 1.0.0-beta.7 → 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 +4 -0
- package/LICENSE +21 -0
- package/README.md +54 -17
- package/dist/foundation/block/commands.js +27 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
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
|
+
|
|
3
7
|
## 1.0.0-beta.7
|
|
4
8
|
|
|
5
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`.
|
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 [];
|