Skip to content
Snippets Groups Projects
Commit b4b34d37 authored by chris's avatar chris
Browse files

mapping

parent 871fa9a6
No related branches found
No related tags found
1 merge request!548Merge yjs with standard comments
...@@ -55,7 +55,7 @@ const Editoria = () => { ...@@ -55,7 +55,7 @@ const Editoria = () => {
autoFocus autoFocus
placeholder="Type Something..." placeholder="Type Something..."
fileUpload={file => renderImage(file)} fileUpload={file => renderImage(file)}
value={demo} // value={demo}
// readonly // readonly
layout={layout} layout={layout}
// onChange={debounce(source => { // onChange={debounce(source => {
......
...@@ -26,7 +26,7 @@ import { ...@@ -26,7 +26,7 @@ import {
disallowPasteImagesPlugin, disallowPasteImagesPlugin,
BlockDropDownToolGroupService, BlockDropDownToolGroupService,
AskAiContentService, AskAiContentService,
// YjsService, YjsService,
CommentDecoration, CommentDecoration,
} from 'wax-prosemirror-services'; } from 'wax-prosemirror-services';
...@@ -149,7 +149,7 @@ export default { ...@@ -149,7 +149,7 @@ export default {
'HighlightToolGroup', 'HighlightToolGroup',
'TransformToolGroup', 'TransformToolGroup',
'CustomTagInline', 'CustomTagInline',
'Notes', // 'Notes',
'Lists', 'Lists',
'Images', 'Images',
'SpecialCharacters', 'SpecialCharacters',
...@@ -227,11 +227,11 @@ export default { ...@@ -227,11 +227,11 @@ export default {
], ],
updateTags: saveTags, updateTags: saveTags,
}, },
// YjsService: { YjsService: {
// // eslint-disable-next-line no-restricted-globals // eslint-disable-next-line no-restricted-globals
// connectionUrl: 'ws://localhost:4000', connectionUrl: 'ws://localhost:4000',
// docIdentifier: 'prosemirror-demo', docIdentifier: 'prosemirror-demo',
// }, },
AskAiContentService: { AskAiContentService: {
AskAiContentTransformation: DummyPromise, AskAiContentTransformation: DummyPromise,
...@@ -239,7 +239,7 @@ export default { ...@@ -239,7 +239,7 @@ export default {
}, },
services: [ services: [
// new YjsService(), new YjsService(),
new BlockDropDownToolGroupService(), new BlockDropDownToolGroupService(),
new AskAiContentService(), new AskAiContentService(),
new CustomTagService(), new CustomTagService(),
...@@ -253,7 +253,7 @@ export default { ...@@ -253,7 +253,7 @@ export default {
new ImageService(), new ImageService(),
new TablesService(), new TablesService(),
new BaseService(), new BaseService(),
new NoteService(), // new NoteService(),
new CodeBlockService(), new CodeBlockService(),
new EditingSuggestingService(), new EditingSuggestingService(),
new DisplayTextToolGroupService(), new DisplayTextToolGroupService(),
......
import { Service } from 'wax-prosemirror-core'; import { Service } from 'wax-prosemirror-core';
import * as Y from 'yjs';
import CommentBubbleComponent from './components/ui/comments/CommentBubbleComponent'; import CommentBubbleComponent from './components/ui/comments/CommentBubbleComponent';
import RightArea from './components/RightArea'; import RightArea from './components/RightArea';
import commentMark from './schema/commentMark'; import commentMark from './schema/commentMark';
......
/* eslint-disable no-param-reassign */ /* eslint-disable no-param-reassign */
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import { Decoration, DecorationSet } from 'prosemirror-view'; import { Decoration, DecorationSet } from 'prosemirror-view';
import {
ySyncPluginKey,
relativePositionToAbsolutePosition,
absolutePositionToRelativePosition,
} from 'y-prosemirror';
import CommentDecoration from './CommentDecoration'; import CommentDecoration from './CommentDecoration';
import { CommentDecorationPluginKey } from './CommentDecorationPlugin'; import { CommentDecorationPluginKey } from './CommentDecorationPlugin';
...@@ -51,26 +56,70 @@ export default class CommentState { ...@@ -51,26 +56,70 @@ export default class CommentState {
createDecorations(state) { createDecorations(state) {
const decorations = []; const decorations = [];
const ystate = ySyncPluginKey.getState(state);
const { doc, type, binding } = ystate;
this.allCommentsList().forEach(annotation => { const { map } = this.options;
const { from, to } = annotation; console.log(binding);
if (binding) {
decorations.push( console.log(doc, type, binding);
Decoration.inline( map.forEach((annotation, id) => {
from, console.log(annotation);
to, const from = relativePositionToAbsolutePosition(
{ doc,
class: 'comment', type,
'data-id': annotation.id, annotation.from,
}, binding.mapping,
{ );
id: annotation.id, console.log(from);
data: annotation, const to = relativePositionToAbsolutePosition(
inclusiveEnd: true, doc,
}, type,
), annotation.to,
); binding.mapping,
}); );
if (!from || !to) {
return;
}
decorations.push(
Decoration.inline(
from,
to,
{
class: 'comment',
'data-id': annotation.id,
},
{
id: annotation.id,
data: annotation,
inclusiveEnd: true,
},
),
);
});
}
// this.allCommentsList().forEach(annotation => {
// const { from, to } = annotation;
// decorations.push(
// Decoration.inline(
// from,
// to,
// {
// class: 'comment',
// 'data-id': annotation.id,
// },
// {
// id: annotation.id,
// data: annotation,
// inclusiveEnd: true,
// },
// ),
// );
// });
this.decorations = DecorationSet.create(state.doc, decorations); this.decorations = DecorationSet.create(state.doc, decorations);
} }
......
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