Skip to content
Snippets Groups Projects
Commit af625139 authored by Christos's avatar Christos
Browse files

Merge branch 'publish@0.9.20' into 'master'

Publish@0.9.20

See merge request !559
parents d99e671a 9e17fb5a
No related branches found
No related tags found
1 merge request!559Publish@0.9.20
Pipeline #60036 passed with stages
in 3 minutes and 40 seconds
...@@ -304,8 +304,9 @@ export default { ...@@ -304,8 +304,9 @@ export default {
}, },
YjsService: { YjsService: {
// eslint-disable-next-line no-restricted-globals // eslint-disable-next-line no-restricted-globals
connectionUrl: 'ws://localhost:4000', connectionUrl: 'ws://localhost:5010',
docIdentifier: 'prosemirror-demo', // connectionUrl: 'ws://0.tcp.ap.ngrok.io:17607',
docIdentifier: 'prosemirror-demo7',
YjsType: 'prosemirror', YjsType: 'prosemirror',
}, },
......
...@@ -11,11 +11,6 @@ export default class CommentsService extends Service { ...@@ -11,11 +11,6 @@ export default class CommentsService extends Service {
boot() { boot() {
const commentsConfig = this.app.config.get('config.CommentsService'); const commentsConfig = this.app.config.get('config.CommentsService');
this.app.PmPlugins.add(
'commentPlugin',
CommentPlugin('commentPlugin', this.app.context),
);
const options = { const options = {
existingComments: () => { existingComments: () => {
const map = this.app.config.get('config.YjsService') const map = this.app.config.get('config.YjsService')
...@@ -52,7 +47,6 @@ export default class CommentsService extends Service { ...@@ -52,7 +47,6 @@ export default class CommentsService extends Service {
} }
commentsConfig.getComments(this.allCommentsFromStates); commentsConfig.getComments(this.allCommentsFromStates);
this.app.context.setOption({ comments: this.allCommentsFromStates });
}, },
}; };
...@@ -61,6 +55,11 @@ export default class CommentsService extends Service { ...@@ -61,6 +55,11 @@ export default class CommentsService extends Service {
CommentDecorationPlugin('commentDecorationPlugin', options), CommentDecorationPlugin('commentDecorationPlugin', options),
); );
this.app.PmPlugins.add(
'commentPlugin',
CommentPlugin('commentPlugin', this.app.context),
);
const createOverlay = this.container.get('CreateOverlay'); const createOverlay = this.container.get('CreateOverlay');
const layout = this.container.get('Layout'); const layout = this.container.get('Layout');
createOverlay( createOverlay(
......
...@@ -32,7 +32,6 @@ export default ({ comment, top, commentId, recalculateTops, users }) => { ...@@ -32,7 +32,6 @@ export default ({ comment, top, commentId, recalculateTops, users }) => {
}, },
app, app,
activeView, activeView,
options: { commentsMap },
} = context; } = context;
const [isActive, setIsActive] = useState(false); const [isActive, setIsActive] = useState(false);
...@@ -118,20 +117,6 @@ export default ({ comment, top, commentId, recalculateTops, users }) => { ...@@ -118,20 +117,6 @@ export default ({ comment, top, commentId, recalculateTops, users }) => {
dispatch(state.tr); dispatch(state.tr);
activeView.focus(); activeView.focus();
if (context.app.config.get('config.YjsService')) {
commentsMap.observe(() => {
const transaction = context.pmViews.main.state.tr.setMeta(
CommentDecorationPluginKey,
{
type: 'deleteComment',
id: activeComment.id,
},
);
context.pmViews.main.dispatch(transaction);
});
}
}; };
const onTextAreaBlur = () => { const onTextAreaBlur = () => {
......
/* eslint react/prop-types: 0 */ /* eslint react/prop-types: 0 */
import React, { useLayoutEffect, useContext, useEffect, useState } from 'react'; import React, { useLayoutEffect, useContext } from 'react';
import { WaxContext } from 'wax-prosemirror-core'; import { WaxContext } from 'wax-prosemirror-core';
import {
ySyncPluginKey,
relativePositionToAbsolutePosition,
absolutePositionToRelativePosition,
} from 'y-prosemirror';
import CommentBubble from './CommentBubble'; import CommentBubble from './CommentBubble';
import { CommentDecorationPluginKey } from '../../../plugins/CommentDecorationPlugin'; import { CommentDecorationPluginKey } from '../../../plugins/CommentDecorationPlugin';
const CommentBubbleComponent = ({ setPosition, position, group }) => { const CommentBubbleComponent = ({ setPosition, position, group }) => {
const context = useContext(WaxContext); const context = useContext(WaxContext);
const { const { activeView, activeViewId } = context;
activeView,
activeViewId,
options: { comments },
} = context;
const { state, dispatch } = activeView; const { state, dispatch } = activeView;
const [fromPos, setFromPos] = useState(state.selection.from);
const [toPos, setToPos] = useState(state.selection.to);
useLayoutEffect(() => { useLayoutEffect(() => {
const WaxSurface = activeView.dom.getBoundingClientRect(); const WaxSurface = activeView.dom.getBoundingClientRect();
...@@ -37,10 +25,6 @@ const CommentBubbleComponent = ({ setPosition, position, group }) => { ...@@ -37,10 +25,6 @@ const CommentBubbleComponent = ({ setPosition, position, group }) => {
event.preventDefault(); event.preventDefault();
const { selection } = state; const { selection } = state;
if (context.app.config.get('config.YjsService')) {
return createYjsComments(selection);
}
dispatch( dispatch(
state.tr.setMeta(CommentDecorationPluginKey, { state.tr.setMeta(CommentDecorationPluginKey, {
type: 'addComment', type: 'addComment',
...@@ -62,50 +46,6 @@ const CommentBubbleComponent = ({ setPosition, position, group }) => { ...@@ -62,50 +46,6 @@ const CommentBubbleComponent = ({ setPosition, position, group }) => {
dispatch(state.tr); dispatch(state.tr);
}; };
const createYjsComments = selection => {
const ystate = ySyncPluginKey.getState(state);
const { doc, type, binding } = ystate;
const from = absolutePositionToRelativePosition(
fromPos,
type,
binding.mapping,
);
const to = absolutePositionToRelativePosition(toPos, 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: fromPos,
yjsTo: toPos,
pmFrom: fromPos,
pmTo: toPos,
type: 'comment',
conversation: [],
title: '',
group,
viewId: activeViewId,
},
}),
);
dispatch(state.tr);
};
useEffect(() => {
if (context.app.config.get('config.YjsService')) {
setFromPos(state.tr.mapping.map(activeView.state.selection.from));
setToPos(state.tr.mapping.map(activeView.state.selection.to));
}
}, [activeView.state]);
const isCommentAllowed = () => { const isCommentAllowed = () => {
let allowed = true; let allowed = true;
state.doc.nodesBetween( state.doc.nodesBetween(
...@@ -121,17 +61,21 @@ const CommentBubbleComponent = ({ setPosition, position, group }) => { ...@@ -121,17 +61,21 @@ const CommentBubbleComponent = ({ setPosition, position, group }) => {
} }
}, },
); );
const commentsMap = CommentDecorationPluginKey.getState(state).getMap();
if ( const commentData = [];
comments.find( commentsMap.forEach(comment => {
comm => console.log(comment);
comm.data.pmFrom === state.selection.from && if (
comm.data.pmTo === state.selection.to, comment.data.pmFrom === state.selection.from &&
) comment.data.pmTo === state.selection.to
) { ) {
allowed = false; console.log('here');
} commentData.push(comment);
}
console.log(commentData);
if (commentData.length !== 0) allowed = false;
console.log(allowed);
});
return allowed; return allowed;
}; };
......
...@@ -2,17 +2,21 @@ ...@@ -2,17 +2,21 @@
import { inRange, last, sortBy } from 'lodash'; import { inRange, last, sortBy } from 'lodash';
import { Plugin, PluginKey } from 'prosemirror-state'; import { Plugin, PluginKey } from 'prosemirror-state';
import { Decoration, DecorationSet } from 'prosemirror-view'; import { Decoration, DecorationSet } from 'prosemirror-view';
import { CommentDecorationPluginKey } from './CommentDecorationPlugin';
const commentPlugin = new PluginKey('commentPlugin'); const commentPlugin = new PluginKey('commentPlugin');
const getComment = (state, context) => { const getComment = state => {
const { const commentsMap = CommentDecorationPluginKey.getState(state).getMap();
options: { comments },
} = context; if (commentsMap.size === 0) return;
if (!comments?.length) return; let commentData = [];
let commentData = comments.filter(comment =>
inRange(state.selection.from, comment.data.pmFrom, comment.data.pmTo), commentsMap.forEach(comment => {
); if (inRange(state.selection.from, comment.data.pmFrom, comment.data.pmTo)) {
commentData.push(comment);
}
});
commentData = sortBy(commentData, ['data.pmFrom']); commentData = sortBy(commentData, ['data.pmFrom']);
if (commentData.length > 0) { if (commentData.length > 0) {
...@@ -29,15 +33,15 @@ const getComment = (state, context) => { ...@@ -29,15 +33,15 @@ const getComment = (state, context) => {
return undefined; return undefined;
}; };
export default (key, context) => { export default () => {
return new Plugin({ return new Plugin({
key: commentPlugin, key: commentPlugin,
state: { state: {
init: (_, state) => { init: (_, state) => {
return { comment: getComment(state, context) }; return { comment: getComment(state) };
}, },
apply(tr, prev, _, newState) { apply(tr, prev, _, newState) {
const comment = getComment(newState, context); const comment = getComment(newState);
let createDecoration; let createDecoration;
if (comment) { if (comment) {
createDecoration = DecorationSet.create(newState.doc, [ createDecoration = DecorationSet.create(newState.doc, [
......
...@@ -66,17 +66,21 @@ export default class CommentState { ...@@ -66,17 +66,21 @@ export default class CommentState {
if (ystate?.binding) { if (ystate?.binding) {
const { doc, type, binding } = ystate; const { doc, type, binding } = ystate;
this.allCommentsList().forEach((annotation, id) => { this.allCommentsList().forEach((annotation, id) => {
annotation.data.yjsFrom = absolutePositionToRelativePosition( if (typeof annotation.data.yjsFrom !== 'object') {
annotation.data.pmFrom, annotation.data.yjsFrom = absolutePositionToRelativePosition(
type, annotation.data.pmFrom,
binding.mapping, type,
); binding.mapping,
);
}
annotation.data.yjsTo = absolutePositionToRelativePosition( if (typeof annotation.data.yjsTo !== 'object') {
annotation.data.pmTo, annotation.data.yjsTo = absolutePositionToRelativePosition(
type, annotation.data.pmTo,
binding.mapping, type,
); binding.mapping,
);
}
const from = relativePositionToAbsolutePosition( const from = relativePositionToAbsolutePosition(
doc, doc,
...@@ -157,6 +161,18 @@ export default class CommentState { ...@@ -157,6 +161,18 @@ export default class CommentState {
annotation.from = newFrom; annotation.from = newFrom;
annotation.to = newTo; annotation.to = newTo;
annotation.data.pmFrom = relativePositionToAbsolutePosition(
ystate.doc,
ystate.type,
newFrom,
ystate.binding.mapping,
);
annotation.data.pmTo = relativePositionToAbsolutePosition(
ystate.doc,
ystate.type,
newTo,
ystate.binding.mapping,
);
this.options.map.set(id, annotation); this.options.map.set(id, annotation);
}); });
...@@ -185,26 +201,17 @@ export default class CommentState { ...@@ -185,26 +201,17 @@ export default class CommentState {
const ystate = ySyncPluginKey.getState(state); const ystate = ySyncPluginKey.getState(state);
if (ystate?.isChangeOrigin) {
// this.updateCommentPostions(ystate);
this.createDecorations(state);
return this;
}
this.decorations = this.decorations.map( this.decorations = this.decorations.map(
transaction.mapping, transaction.mapping,
transaction.doc, transaction.doc,
); );
map.forEach((annotation, _) => { if (ystate?.isChangeOrigin) {
if ('from' in annotation && 'to' in annotation) { this.updateCommentPostions(ystate);
annotation.data.pmFrom = transaction.mapping.map( this.createDecorations(state);
annotation.data.pmFrom,
); return this;
annotation.data.pmTo = transaction.mapping.map(annotation.data.pmTo); }
}
});
if (ystate?.binding && ystate?.binding.mapping) { if (ystate?.binding && ystate?.binding.mapping) {
this.updateCommentPostions(ystate); this.updateCommentPostions(ystate);
...@@ -212,6 +219,15 @@ export default class CommentState { ...@@ -212,6 +219,15 @@ export default class CommentState {
return this; return this;
// eslint-disable-next-line no-else-return // eslint-disable-next-line no-else-return
} else { } else {
// Not YJS
map.forEach((annotation, _) => {
if ('from' in annotation && 'to' in annotation) {
annotation.data.pmFrom = transaction.mapping.map(
annotation.data.pmFrom,
);
annotation.data.pmTo = transaction.mapping.map(annotation.data.pmTo);
}
});
this.createDecorations(state); this.createDecorations(state);
return this; return this;
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment