jazz-tools 0.17.7 → 0.17.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/.turbo/turbo-build.log +38 -38
- package/CHANGELOG.md +11 -0
- package/dist/{chunk-SJHXI5AB.js → chunk-L3GGWY3X.js} +13 -3
- package/dist/chunk-L3GGWY3X.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/prosemirror/index.js +36 -12
- package/dist/prosemirror/index.js.map +1 -1
- package/dist/prosemirror/lib/sync.d.ts.map +1 -1
- package/dist/testing.js +1 -1
- package/dist/tools/exports.d.ts +1 -1
- package/dist/tools/exports.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.d.ts +1 -1
- package/dist/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/prosemirror/lib/sync.ts +46 -16
- package/src/prosemirror/tests/plugin.test.ts +87 -31
- package/src/tools/exports.ts +1 -0
- package/src/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.ts +7 -2
- package/src/tools/implementation/zodSchema/zodCo.ts +11 -0
- package/src/tools/implementation/zodSchema/zodReExport.ts +7 -2
- package/src/tools/tests/account.test.ts +6 -0
- package/src/tools/tests/coMap.test.ts +6 -0
- package/dist/chunk-SJHXI5AB.js.map +0 -1
package/dist/index.js
CHANGED
@@ -2086,28 +2086,52 @@ function proseMirrorToHtml(doc2) {
|
|
2086
2086
|
|
2087
2087
|
// src/prosemirror/lib/sync.ts
|
2088
2088
|
import { recreateTransform } from "@manuscripts/prosemirror-recreate-steps";
|
2089
|
+
import { EditorState } from "prosemirror-state";
|
2089
2090
|
var META_KEY = "fromJazz";
|
2090
2091
|
function createSyncHandlers(coRichText) {
|
2091
2092
|
let view;
|
2093
|
+
let localChange = false;
|
2094
|
+
let remoteChange = false;
|
2092
2095
|
function handleCoRichTextChange(newText) {
|
2093
|
-
if (!view || !newText) return;
|
2094
|
-
const
|
2095
|
-
|
2096
|
-
|
2097
|
-
|
2098
|
-
|
2099
|
-
|
2100
|
-
|
2101
|
-
|
2096
|
+
if (!view || !newText || localChange || remoteChange) return;
|
2097
|
+
const currentView = view;
|
2098
|
+
remoteChange = true;
|
2099
|
+
queueMicrotask(() => {
|
2100
|
+
const pmDoc = htmlToProseMirror(
|
2101
|
+
newText.toString(),
|
2102
|
+
currentView.state.doc.type.schema
|
2103
|
+
);
|
2104
|
+
try {
|
2105
|
+
const transform = recreateTransform(currentView.state.doc, pmDoc);
|
2106
|
+
const tr = currentView.state.tr;
|
2107
|
+
transform.steps.forEach((step) => {
|
2108
|
+
tr.step(step);
|
2109
|
+
});
|
2110
|
+
tr.setMeta(META_KEY, true);
|
2111
|
+
currentView.dispatch(tr);
|
2112
|
+
} catch (err) {
|
2113
|
+
const newState = EditorState.create({
|
2114
|
+
schema: currentView.state.schema,
|
2115
|
+
doc: pmDoc,
|
2116
|
+
plugins: currentView.state.plugins,
|
2117
|
+
selection: currentView.state.selection
|
2118
|
+
});
|
2119
|
+
currentView.updateState(newState);
|
2120
|
+
} finally {
|
2121
|
+
remoteChange = false;
|
2122
|
+
}
|
2102
2123
|
});
|
2103
|
-
tr.setMeta(META_KEY, true);
|
2104
|
-
view.dispatch(tr);
|
2105
2124
|
}
|
2106
2125
|
function handleProseMirrorChange(tr) {
|
2107
2126
|
if (!coRichText || tr.getMeta(META_KEY)) return;
|
2108
2127
|
if (tr.docChanged) {
|
2109
2128
|
const str = proseMirrorToHtml(tr.doc);
|
2110
|
-
|
2129
|
+
localChange = true;
|
2130
|
+
try {
|
2131
|
+
coRichText.applyDiff(str);
|
2132
|
+
} finally {
|
2133
|
+
localChange = false;
|
2134
|
+
}
|
2111
2135
|
}
|
2112
2136
|
}
|
2113
2137
|
return {
|