Commit d4865270 authored by chris's avatar chris

expiremental track changes

parent b29a5f30
......@@ -125,6 +125,7 @@ class Editoria extends Component {
layout="editoria"
fileUpload={file => renderImage(file)}
debug
TrackChange
value=""
>
{({ editor, view, ...props }) => (
......
......@@ -3,3 +3,4 @@ export { default as CreateSchema } from "./src/config/classes/CreateSchema";
export {
default as CreateShortCuts
} from "./src/config/classes/CreateShortCuts";
export { amendTransaction } from "./src/amend_transaction";
......@@ -7,6 +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 { amendTransaction } from "./amend_transaction";
class WaxView extends Component {
constructor(props) {
......@@ -93,7 +94,9 @@ class WaxView extends Component {
};
dispatchTransaction = transaction => {
const state = this.view.state.apply(transaction);
console.log(amendTransaction(transaction, this.view.state, this));
const trackedTr = amendTransaction(transaction, this.view.state, this);
const state = this.view.state.apply(trackedTr);
this.view.updateState(state);
this.props.onChange(state.doc.content);
this.forceUpdate();
......
This diff is collapsed.
......@@ -116,7 +116,7 @@ export default options => {
},
handleDOMEvents: {
focus: (view, _event) => {
view.dispatch(deactivateAllSelectedChanges(view.state.tr));
// view.dispatch(deactivateAllSelectedChanges(view.state.tr));
}
}
}
......
......@@ -7,6 +7,22 @@ const emDOM = ["em", 0],
strongDOM = ["strong", 0],
codeDOM = ["code", 0];
const parseFormatList = str => {
if (!str) {
return [];
}
let formatList;
try {
formatList = JSON.parse(str);
} catch (error) {
return [];
}
if (!Array.isArray(formatList)) {
return [];
}
return formatList.filter(format => typeof format === "string"); // ensure there are only strings in list
};
const EditoriaSchema = {
nodes: {
doc: {
......@@ -378,6 +394,63 @@ const EditoriaSchema = {
return ["cite", 0];
}
},
insertion: {
attrs: {
user: {
default: 0
},
username: {
default: ""
},
date: {
default: 0
},
approved: {
default: true
}
},
inclusive: false,
group: "track",
parseDOM: [
{
tag: "span.insertion",
getAttrs(dom) {
return {
user: parseInt(dom.dataset.user),
username: dom.dataset.username,
date: parseInt(dom.dataset.date),
inline: true,
approved: false
};
}
},
{
tag: "span.approved-insertion",
getAttrs(dom) {
return {
user: parseInt(dom.dataset.user),
username: dom.dataset.username,
date: parseInt(dom.dataset.date),
inline: true,
approved: true
};
}
}
],
toDOM(node) {
return [
"span",
{
class: node.attrs.approved
? "approved-insertion"
: `insertion user-${node.attrs.user}`,
"data-user": node.attrs.user,
"data-username": node.attrs.username,
"data-date": node.attrs.date
}
];
}
},
deletion: {
attrs: {
user: {
......@@ -397,9 +470,55 @@ const EditoriaSchema = {
tag: "span.deletion",
getAttrs(dom) {
return {
user: { id: "123" },
username: "chris",
date: "2333"
user: parseInt(dom.dataset.user),
username: dom.dataset.username,
date: parseInt(dom.dataset.date)
};
}
}
],
toDOM(node) {
return [
"span",
{
class: `deletion user-${node.attrs.user}`,
"data-user": node.attrs.user,
"data-username": node.attrs.username,
"data-date": node.attrs.date
}
];
}
},
format_change: {
attrs: {
user: {
default: 0
},
username: {
default: ""
},
date: {
default: 0
},
before: {
default: []
},
after: {
default: []
}
},
inclusive: false,
group: "track",
parseDOM: [
{
tag: "span.format-change",
getAttrs(dom) {
return {
user: parseInt(dom.dataset.user),
username: dom.dataset.username,
date: parseInt(dom.dataset.date),
before: parseFormatList(dom.dataset.before),
after: parseFormatList(dom.dataset.after)
};
}
}
......@@ -408,10 +527,12 @@ const EditoriaSchema = {
return [
"span",
{
class: `deletion user-chris`,
"data-user": '{id: "123"}',
"data-username": "chris",
"data-date": "32323"
class: `format-change user-${node.attrs.user}`,
"data-user": node.attrs.user,
"data-username": node.attrs.username,
"data-date": node.attrs.date,
"data-before": JSON.stringify(node.attrs.before),
"data-after": JSON.stringify(node.attrs.after)
}
];
}
......
......@@ -170,3 +170,60 @@
border-bottom-width: 0;
border-top-color: white;
}
span.deletion {
text-decoration: line-through;
color: red;
}
span.insertion {
color: blue;
}
.selected-insertion,
.selected-deletion,
.selected-format_change,
.selected-block_change {
background-color: #fffacf;
}
.tag.selected-insertion,
.contributor.selected-insertion,
.tag.selected-deletion,
.contributor.selected-deletion {
background-color: #fffacf;
color: #000;
}
.margin-box.track > div {
padding: 10px;
}
.margin-box .track-title {
font-weight: 700;
}
.margin-box .format-change-info {
margin-bottom: 9px;
}
.margin-box .format-change-info b {
font-weight: 700;
}
[data-track] {
position: relative;
}
[data-track]::before {
content: "";
position: absolute;
border-left: 1px solid black;
left: -10px;
height: 22px;
}
li[data-track]::before,
li [data-track]::before {
left: -5px;
}
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