Commit e587cd5c authored by chris's avatar chris

break into seperate files based on funcionality

parent bfde29ff
......@@ -7,7 +7,7 @@ import { EditorView } from "prosemirror-view";
import placeholderPlugin from "./config/plugins/placeholderPlugin";
import "prosemirror-view/style/prosemirror.css";
import "prosemirror-gapcursor/style/gapcursor.css";
import trackedTransaction from "./trackedTransaction";
import trackedTransaction from "./config/track-changes/trackedTransaction";
class WaxView extends Component {
constructor(props) {
......
import { Selection, TextSelection } from "prosemirror-state";
import { Slice } from "prosemirror-model";
import { ReplaceStep, Mapping } from "prosemirror-transform";
const markDeletion = (tr, from, to, user, username, date1, date10) => {
const deletionMark = tr.doc.type.schema.marks.deletion.create({
user,
username,
date: date10
});
let firstTableCellChild = false;
const deletionMap = new Mapping();
// Add deletion mark to block nodes (figures, text blocks) and find already deleted inline nodes (and leave them alone)
tr.doc.nodesBetween(from, to, (node, pos) => {
if (pos < from && node.type.name === "table_cell") {
firstTableCellChild = true;
return true;
} else if ((pos < from && node.isBlock) || firstTableCellChild) {
firstTableCellChild = false;
return true;
} else if (["table_row", "table_cell"].includes(node.type.name)) {
return false;
} else if (
node.isInline &&
node.marks.find(
mark =>
mark.type.name === "insertion" &&
mark.attrs.user === user &&
!mark.attrs.approved
)
) {
const removeStep = new ReplaceStep(
deletionMap.map(Math.max(from, pos)),
deletionMap.map(Math.min(to, pos + node.nodeSize)),
Slice.empty
);
if (!tr.maybeStep(removeStep).failed) {
deletionMap.appendMap(removeStep.getMap());
}
} else if (
node.isInline &&
!node.marks.find(mark => mark.type.name === "deletion")
) {
tr.addMark(
deletionMap.map(Math.max(from, pos)),
deletionMap.map(Math.min(to, pos + node.nodeSize)),
deletionMark
);
} else if (
node.attrs.track &&
!node.attrs.track.find(trackAttr => trackAttr.type === "deletion") &&
!["bullet_list", "ordered_list"].includes(node.type.name)
) {
if (
node.attrs.track.find(
trackAttr => trackAttr.type === "insertion" && trackAttr.user === user
)
) {
let removeStep;
// user has created element. so (s)he is allowed to delete it again.
if (node.isTextblock && to < pos + node.nodeSize) {
// The node is a textblock. So we need to merge into the last possible position inside the last text block.
const selectionBefore = Selection.findFrom(tr.doc.resolve(pos), -1);
if (selectionBefore instanceof TextSelection) {
removeStep = new ReplaceStep(
deletionMap.map(selectionBefore.$anchor.pos),
deletionMap.map(to),
Slice.empty
);
}
} else {
removeStep = new ReplaceStep(
deletionMap.map(Math.max(from, pos)),
deletionMap.map(Math.min(to, pos + node.nodeSize)),
Slice.empty
);
}
if (!tr.maybeStep(removeStep).failed) {
deletionMap.appendMap(removeStep.getMap());
}
} else {
const track = node.attrs.track.slice();
track.push({ type: "deletion", user, username, date: date1 });
tr.setNodeMarkup(
deletionMap.map(pos),
null,
Object.assign({}, node.attrs, { track }),
node.marks
);
}
}
});
return deletionMap;
};
export default markDeletion;
const markInsertion = (
tr,
from,
to,
user,
username,
date1,
date10,
approved
) => {
tr.removeMark(from, to, tr.doc.type.schema.marks.deletion);
tr.removeMark(from, to, tr.doc.type.schema.marks.insertion);
const insertionMark = tr.doc.type.schema.marks.insertion.create({
user,
username,
date: date10,
approved
});
tr.addMark(from, to, insertionMark);
// Add insertion mark also to block nodes (figures, text blocks) but not table cells/rows and lists.
tr.doc.nodesBetween(from, to, (node, pos) => {
if (
pos < from ||
["bullet_list", "ordered_list"].includes(node.type.name)
) {
return true;
} else if (
node.isInline ||
["table_row", "table_cell"].includes(node.type.name)
) {
return false;
}
if (node.attrs.track) {
const track = [];
if (!approved) {
track.push({ type: "insertion", user, username, date: date1 });
}
tr.setNodeMarkup(
pos,
null,
Object.assign({}, node.attrs, { track }),
node.marks
);
}
if (node.type.name === "table") {
return false;
}
});
};
export default markInsertion;
const markWrapping = (tr, pos, oldNode, newNode, user, username, date1) => {
let track = oldNode.attrs.track.slice(),
blockTrack = track.find(track => track.type === "block_change");
if (blockTrack) {
track = track.filter(track => track !== blockTrack);
if (
blockTrack.before.type !== newNode.type.name ||
blockTrack.before.attrs.level !== newNode.attrs.level
) {
blockTrack = {
type: "block_change",
user,
username,
date: date1,
before: blockTrack.before
};
track.push(blockTrack);
}
} else {
blockTrack = {
type: "block_change",
user,
username,
date: date1,
before: { type: oldNode.type.name, attrs: oldNode.attrs }
};
// if (blockTrack.before.attrs.id) {
// delete blockTrack.before.attrs.id;
// }
if (blockTrack.before.attrs.track) {
delete blockTrack.before.attrs.track;
}
track.push(blockTrack);
}
tr.setNodeMarkup(pos, null, Object.assign({}, newNode.attrs, { track }));
};
export default markWrapping;
......@@ -9,189 +9,9 @@ import {
} from "prosemirror-transform";
import { CellSelection } from "prosemirror-tables";
const markInsertion = (
tr,
from,
to,
user,
username,
date1,
date10,
approved
) => {
tr.removeMark(from, to, tr.doc.type.schema.marks.deletion);
tr.removeMark(from, to, tr.doc.type.schema.marks.insertion);
const insertionMark = tr.doc.type.schema.marks.insertion.create({
user,
username,
date: date10,
approved
});
tr.addMark(from, to, insertionMark);
// Add insertion mark also to block nodes (figures, text blocks) but not table cells/rows and lists.
tr.doc.nodesBetween(from, to, (node, pos) => {
if (
pos < from ||
["bullet_list", "ordered_list"].includes(node.type.name)
) {
return true;
} else if (
node.isInline ||
["table_row", "table_cell"].includes(node.type.name)
) {
return false;
}
if (node.attrs.track) {
const track = [];
if (!approved) {
track.push({ type: "insertion", user, username, date: date1 });
}
tr.setNodeMarkup(
pos,
null,
Object.assign({}, node.attrs, { track }),
node.marks
);
}
if (node.type.name === "table") {
return false;
}
});
};
const markDeletion = (tr, from, to, user, username, date1, date10) => {
const deletionMark = tr.doc.type.schema.marks.deletion.create({
user,
username,
date: date10
});
let firstTableCellChild = false;
const deletionMap = new Mapping();
// Add deletion mark to block nodes (figures, text blocks) and find already deleted inline nodes (and leave them alone)
tr.doc.nodesBetween(from, to, (node, pos) => {
if (pos < from && node.type.name === "table_cell") {
firstTableCellChild = true;
return true;
} else if ((pos < from && node.isBlock) || firstTableCellChild) {
firstTableCellChild = false;
return true;
} else if (["table_row", "table_cell"].includes(node.type.name)) {
return false;
} else if (
node.isInline &&
node.marks.find(
mark =>
mark.type.name === "insertion" &&
mark.attrs.user === user &&
!mark.attrs.approved
)
) {
const removeStep = new ReplaceStep(
deletionMap.map(Math.max(from, pos)),
deletionMap.map(Math.min(to, pos + node.nodeSize)),
Slice.empty
);
if (!tr.maybeStep(removeStep).failed) {
deletionMap.appendMap(removeStep.getMap());
}
} else if (
node.isInline &&
!node.marks.find(mark => mark.type.name === "deletion")
) {
tr.addMark(
deletionMap.map(Math.max(from, pos)),
deletionMap.map(Math.min(to, pos + node.nodeSize)),
deletionMark
);
} else if (
node.attrs.track &&
!node.attrs.track.find(trackAttr => trackAttr.type === "deletion") &&
!["bullet_list", "ordered_list"].includes(node.type.name)
) {
if (
node.attrs.track.find(
trackAttr => trackAttr.type === "insertion" && trackAttr.user === user
)
) {
let removeStep;
// user has created element. so (s)he is allowed to delete it again.
if (node.isTextblock && to < pos + node.nodeSize) {
// The node is a textblock. So we need to merge into the last possible position inside the last text block.
const selectionBefore = Selection.findFrom(tr.doc.resolve(pos), -1);
if (selectionBefore instanceof TextSelection) {
removeStep = new ReplaceStep(
deletionMap.map(selectionBefore.$anchor.pos),
deletionMap.map(to),
Slice.empty
);
}
} else {
removeStep = new ReplaceStep(
deletionMap.map(Math.max(from, pos)),
deletionMap.map(Math.min(to, pos + node.nodeSize)),
Slice.empty
);
}
if (!tr.maybeStep(removeStep).failed) {
deletionMap.appendMap(removeStep.getMap());
}
} else {
const track = node.attrs.track.slice();
track.push({ type: "deletion", user, username, date: date1 });
tr.setNodeMarkup(
deletionMap.map(pos),
null,
Object.assign({}, node.attrs, { track }),
node.marks
);
}
}
});
return deletionMap;
};
const markWrapping = (tr, pos, oldNode, newNode, user, username, date1) => {
let track = oldNode.attrs.track.slice(),
blockTrack = track.find(track => track.type === "block_change");
if (blockTrack) {
track = track.filter(track => track !== blockTrack);
if (
blockTrack.before.type !== newNode.type.name ||
blockTrack.before.attrs.level !== newNode.attrs.level
) {
blockTrack = {
type: "block_change",
user,
username,
date: date1,
before: blockTrack.before
};
track.push(blockTrack);
}
} else {
blockTrack = {
type: "block_change",
user,
username,
date: date1,
before: { type: oldNode.type.name, attrs: oldNode.attrs }
};
// if (blockTrack.before.attrs.id) {
// delete blockTrack.before.attrs.id;
// }
if (blockTrack.before.attrs.track) {
delete blockTrack.before.attrs.track;
}
track.push(blockTrack);
}
tr.setNodeMarkup(pos, null, Object.assign({}, newNode.attrs, { track }));
};
import markDeletion from "./markDeletion";
import markInsertion from "./markInsertion";
import markWrapping from "./markWrapping";
const trackedTransaction = (tr, state, editor) => {
if (
......
Markdown is supported
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