diff --git a/editors/demo/package.json b/editors/demo/package.json index 78a490331f9dd2fbeb1fe6d88bc3d4eef3172317..9ff3bcfe51eba92d72719fa29abc14a31d16df16 100644 --- a/editors/demo/package.json +++ b/editors/demo/package.json @@ -1,6 +1,6 @@ { "name": "demo", - "version": "0.9.17", + "version": "0.9.18", "private": true, "dependencies": { "@guardian/prosemirror-invisibles": "^1.2.0", @@ -15,10 +15,10 @@ "typeface-fira-sans-condensed": "^0.0.54", "typeface-inter": "^1.1.13", "typeface-vollkorn": "^0.0.54", - "wax-prosemirror-core": "^0.9.17", - "wax-prosemirror-services": "^0.9.17", - "wax-questions-service": "^0.9.17", - "wax-table-service": "^0.9.17" + "wax-prosemirror-core": "^0.9.18", + "wax-prosemirror-services": "^0.9.18", + "wax-questions-service": "^0.9.18", + "wax-table-service": "^0.9.18" }, "scripts": { "start": "react-app-rewired start", diff --git a/lerna.json b/lerna.json index f93f30b705023e998c4638f2f09ec5f43e9605d9..f0f90c9fac58644fff29b488bf041a5571096da4 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,6 @@ { "lerna": "2.6.0", "npmClient": "yarn", - "version": "0.9.17", + "version": "0.9.18", "useWorkspaces": true } diff --git a/wax-prosemirror-core/package.json b/wax-prosemirror-core/package.json index 766b5f8089a7250e5198e411969e0348166769a1..6e011eddf692e3d290ff033bd15b1c8bd3951040 100644 --- a/wax-prosemirror-core/package.json +++ b/wax-prosemirror-core/package.json @@ -1,7 +1,7 @@ { "name": "wax-prosemirror-core", "author": "Christos Kokosias & Giannis Kopanas", - "version": "0.9.17", + "version": "0.9.18", "description": "Wax prosemirror core", "license": "MIT", "main": "dist/index.js", diff --git a/wax-prosemirror-services/package.json b/wax-prosemirror-services/package.json index 1141f1463179331ee157d6cbd80c4e753ba5e897..9c48c5b0dbfc6c19c4bd1a43d3f3bcf68f8ca072 100644 --- a/wax-prosemirror-services/package.json +++ b/wax-prosemirror-services/package.json @@ -1,7 +1,7 @@ { "name": "wax-prosemirror-services", "author": "Christos Kokosias & Giannis Kopanas", - "version": "0.9.17", + "version": "0.9.18", "description": "Wax prosemirror services", "license": "MIT", "main": "dist/index.js", @@ -36,7 +36,7 @@ "react-i18next": "^13.3.1", "use-deep-compare-effect": "^1.3.1", "uuid": "^7.0.3", - "wax-prosemirror-core": "^0.9.17", + "wax-prosemirror-core": "^0.9.18", "y-prosemirror": "1.2.0", "y-protocols": "1.0.5", "y-webrtc": "10.2.0", diff --git a/wax-prosemirror-services/src/CommentsService/components/ui/comments/CommentBubbleComponent.js b/wax-prosemirror-services/src/CommentsService/components/ui/comments/CommentBubbleComponent.js index cc1bd37843fe54115e539996e22698ddd370d77b..eb9b7f5034ef1cb13b7d4fb51091988466ddbd97 100644 --- a/wax-prosemirror-services/src/CommentsService/components/ui/comments/CommentBubbleComponent.js +++ b/wax-prosemirror-services/src/CommentsService/components/ui/comments/CommentBubbleComponent.js @@ -1,6 +1,11 @@ /* eslint react/prop-types: 0 */ import React, { useLayoutEffect, useContext } from 'react'; import { WaxContext } from 'wax-prosemirror-core'; +import { + ySyncPluginKey, + relativePositionToAbsolutePosition, + absolutePositionToRelativePosition, +} from 'y-prosemirror'; import CommentBubble from './CommentBubble'; import { CommentDecorationPluginKey } from '../../../plugins/CommentDecorationPlugin'; @@ -31,6 +36,10 @@ const CommentBubbleComponent = ({ setPosition, position, group }) => { event.preventDefault(); const { selection } = state; + if (context.app.config.get('config.YjsService')) { + return createYjsComments(selection); + } + dispatch( state.tr.setMeta(CommentDecorationPluginKey, { type: 'addComment', @@ -52,6 +61,47 @@ const CommentBubbleComponent = ({ setPosition, position, group }) => { dispatch(state.tr); }; + const createYjsComments = selection => { + const ystate = ySyncPluginKey.getState(state); + const { doc, type, binding } = ystate; + const from = absolutePositionToRelativePosition( + selection.from, + type, + binding.mapping, + ); + const to = absolutePositionToRelativePosition( + selection.to, + type, + binding.mapping, + ); + + dispatch( + state.tr.setMeta(CommentDecorationPluginKey, { + type: 'addComment', + from: relativePositionToAbsolutePosition( + doc, + type, + from, + binding.mapping, + ), + to: relativePositionToAbsolutePosition(doc, type, to, binding.mapping), + data: { + yjsFrom: selection.from, + yjsTo: selection.to, + pmFrom: selection.from, + pmTo: selection.to, + type: 'comment', + conversation: [], + title: '', + group, + viewId: activeViewId, + }, + }), + ); + + dispatch(state.tr); + }; + const isCommentAllowed = () => { let allowed = true; state.doc.nodesBetween( diff --git a/wax-prosemirror-services/src/CommentsService/plugins/CommentState.js b/wax-prosemirror-services/src/CommentsService/plugins/CommentState.js index abe0758148af0b10d01c180a2a84a9a2a6cff28b..fd3ae51dd8cdf282df41181237fdb6d9b3961c70 100644 --- a/wax-prosemirror-services/src/CommentsService/plugins/CommentState.js +++ b/wax-prosemirror-services/src/CommentsService/plugins/CommentState.js @@ -208,15 +208,10 @@ export default class CommentState { if (ystate?.binding && ystate?.binding.mapping) { this.updateCommentPostions(ystate); + this.createDecorations(state); return this; // eslint-disable-next-line no-else-return } else { - map.forEach((annotation, _) => { - if ('from' in annotation && 'to' in annotation) { - annotation.from = transaction.mapping.map(annotation.from); - annotation.to = transaction.mapping.map(annotation.to); - } - }); this.createDecorations(state); return this; } diff --git a/wax-questions-service/package.json b/wax-questions-service/package.json index ccda4dfe320e626900eed25cf311d2d93c33a5d9..a18e18d8f7c199e42af95b8322ab2796f628a0d3 100644 --- a/wax-questions-service/package.json +++ b/wax-questions-service/package.json @@ -1,7 +1,7 @@ { "name": "wax-questions-service", "author": "Christos Kokosias & Giannis Kopanas", - "version": "0.9.17", + "version": "0.9.18", "description": "Wax Questions Service", "license": "MIT", "main": "dist/index.js", @@ -32,7 +32,7 @@ "react-i18next": "^13.3.1", "use-dynamic-refs": "^1.0.0", "uuid": "^7.0.3", - "wax-prosemirror-core": "^0.9.17" + "wax-prosemirror-core": "^0.9.18" }, "devDependencies": { "mocha": "^3.4.2", diff --git a/wax-table-service/package.json b/wax-table-service/package.json index f99098a568038d62197a708e578149ac363faffa..4962c5ab7469b8916986c646781a1239faaec0cf 100644 --- a/wax-table-service/package.json +++ b/wax-table-service/package.json @@ -1,7 +1,7 @@ { "name": "wax-table-service", "author": "Christos Kokosias & Giannis Kopanas", - "version": "0.9.17", + "version": "0.9.18", "description": "Wax Table Service", "license": "MIT", "main": "dist/index.js", @@ -23,7 +23,7 @@ "prosemirror-view": "1.30.2", "react-i18next": "^13.3.1", "uuid": "^7.0.3", - "wax-prosemirror-core": "^0.9.17" + "wax-prosemirror-core": "^0.9.18" }, "devDependencies": { "mocha": "^3.4.2",