Commit b29a5f30 authored by chris's avatar chris

testing

parent 282ae348
......@@ -124,6 +124,7 @@ class Editoria extends Component {
theme="editoria"
layout="editoria"
fileUpload={file => renderImage(file)}
debug
value=""
>
{({ editor, view, ...props }) => (
......
......@@ -118,19 +118,19 @@ export default {
select: state => true,
menu: props => <Button key={uuid()} {...props} />
},
small_caps: {
title: "Toggle Small Caps",
content: icons.small_caps,
active: state => {
return markActive(state.config.schema.marks.small_caps)(state);
},
run(state, dispatch) {
toggleMark(state.config.schema.marks.small_caps)(state, dispatch);
},
select: state => true,
menu: props => <Button key={uuid()} {...props} />
},
// small_caps: {
// title: "Toggle Small Caps",
// content: icons.small_caps,
// active: state => {
// return markActive(state.config.schema.marks.small_caps)(state);
// },
// run(state, dispatch) {
// toggleMark(state.config.schema.marks.small_caps)(state, dispatch);
// },
//
// select: state => true,
// menu: props => <Button key={uuid()} {...props} />
// },
subscript: {
title: "Toggle subscript",
content: icons.subscript,
......
import { Plugin, PluginKey } from "prosemirror-state";
import { Decoration, DecorationSet, EditorView } from "prosemirror-view";
import { Decoration, DecorationSet } from "prosemirror-view";
import { findSelectedChanges } from "./find_selected_changes";
import { deactivateAllSelectedChanges } from "./helpers";
......@@ -15,18 +15,18 @@ export default options => {
key,
state: {
init(config, state) {
// Make sure there are colors for all users who have left marks in the document
const userIds = "33";
const userIds = ["33"];
state.doc.descendants(node => {
if (node.attrs.track) {
console.log("11111111");
node.attrs.track.forEach(track => {
if (!userIds.includes(track.user) && track.user !== 0) {
userIds.push(track.user);
}
});
} else {
console.log(node.marks);
node.marks.forEach(mark => {
console.log("dkddkdkdk");
if (
["deletion", "insertion", "format_change"].includes(
mark.type.name
......@@ -63,6 +63,7 @@ export default options => {
? Decoration.node
: Decoration.inline;
if (insertion) {
console.log("insertion");
decos = decos.add(tr.doc, [
decoType(
insertion.from,
......@@ -75,6 +76,7 @@ export default options => {
]);
}
if (deletion) {
console.log("deletion");
decos = decos.add(tr.doc, [
decoType(
deletion.from,
......@@ -87,6 +89,7 @@ export default options => {
]);
}
if (formatChange) {
console.log("change format");
decos = decos.add(tr.doc, [
decoType(
formatChange.from,
......@@ -113,7 +116,6 @@ export default options => {
},
handleDOMEvents: {
focus: (view, _event) => {
console.log(view);
view.dispatch(deactivateAllSelectedChanges(view.state.tr));
}
}
......
import {
getFromToMark
} from "./helpers"
import { getFromToMark } from "./helpers";
export function findSelectedChanges(state) {
const selection = state.selection,
selectedChanges = {
insertion: false,
deletion: false,
formatChange: false
};
let insertionPos = false,
deletionPos = false,
formatChangePos = false,
insertionMark,
deletionMark,
formatChangeMark,
insertionSize,
deletionSize,
formatChangeSize;
const selection = state.selection,
selectedChanges = {insertion: false, deletion: false, formatChange: false}
let insertionPos = false,
deletionPos = false,
formatChangePos = false,
insertionMark,
deletionMark,
formatChangeMark,
insertionSize,
deletionSize,
formatChangeSize
if (selection.empty) {
const resolvedPos = state.doc.resolve(selection.from), marks = resolvedPos.marks()
if (marks) {
insertionMark = marks.find(mark => mark.type.name==='insertion' && !mark.attrs.approved)
if (insertionMark) {
insertionPos = selection.from
}
deletionMark = marks.find(mark => mark.type.name==='deletion')
if (deletionMark) {
deletionPos = selection.from
}
formatChangeMark = marks.find(mark => mark.type.name==='format_change')
if (formatChangeMark) {
formatChangePos = selection.from
}
}
} else {
state.doc.nodesBetween(
selection.from,
selection.to,
(node, pos) => {
if (pos < selection.from) {
return true
}
if (!insertionMark) {
insertionMark = node.attrs.track ?
node.attrs.track.find(trackAttr => trackAttr.type==='insertion') :
node.marks.find(mark => mark.type.name==='insertion' && !mark.attrs.approved)
if (insertionMark) {
insertionPos = pos
if (!node.isInline) {
insertionSize = node.nodeSize
}
}
}
if (!deletionMark) {
deletionMark = node.attrs.track ?
node.attrs.track.find(trackAttr => trackAttr.type==='deletion') :
node.marks.find(mark => mark.type.name==='deletion')
if (deletionMark) {
deletionPos = pos
if (!node.isInline) {
deletionSize = node.nodeSize
}
}
}
if (!formatChangeMark) {
formatChangeMark = node.marks.find(mark => mark.type.name==='format_change')
if (formatChangeMark) {
formatChangePos = pos
if (!node.isInline) {
formatChangeSize = node.nodeSize
}
}
}
}
)
}
if (insertionMark) {
selectedChanges.insertion = insertionSize ?
{from: insertionPos, to: insertionPos + insertionSize} :
getFromToMark(state.doc, insertionPos, insertionMark)
}
if (deletionMark) {
selectedChanges.deletion = deletionSize ?
{from: deletionPos, to: deletionPos + deletionSize} :
getFromToMark(state.doc, deletionPos, deletionMark)
if (selection.empty) {
const resolvedPos = state.doc.resolve(selection.from),
marks = resolvedPos.marks();
if (marks) {
insertionMark = marks.find(
mark => mark.type.name === "insertion" && !mark.attrs.approved
);
if (insertionMark) {
insertionPos = selection.from;
}
deletionMark = marks.find(mark => mark.type.name === "deletion");
console.log("selection", state);
if (deletionMark) {
deletionPos = selection.from;
}
formatChangeMark = marks.find(mark => mark.type.name === "format_change");
if (formatChangeMark) {
formatChangePos = selection.from;
}
}
} else {
state.doc.nodesBetween(selection.from, selection.to, (node, pos) => {
if (pos < selection.from) {
return true;
}
if (!insertionMark) {
insertionMark = node.attrs.track
? node.attrs.track.find(trackAttr => trackAttr.type === "insertion")
: node.marks.find(
mark => mark.type.name === "insertion" && !mark.attrs.approved
);
if (insertionMark) {
insertionPos = pos;
if (!node.isInline) {
insertionSize = node.nodeSize;
}
}
}
if (!deletionMark) {
console.log("deletion");
deletionMark = node.attrs.track
? node.attrs.track.find(trackAttr => trackAttr.type === "deletion")
: node.marks.find(mark => mark.type.name === "deletion");
if (deletionMark) {
deletionPos = pos;
if (!node.isInline) {
deletionSize = node.nodeSize;
}
}
}
if (!formatChangeMark) {
formatChangeMark = node.marks.find(
mark => mark.type.name === "format_change"
);
if (formatChangeMark) {
formatChangePos = pos;
if (!node.isInline) {
formatChangeSize = node.nodeSize;
}
}
}
});
}
if (insertionMark) {
selectedChanges.insertion = insertionSize
? { from: insertionPos, to: insertionPos + insertionSize }
: getFromToMark(state.doc, insertionPos, insertionMark);
}
if (formatChangeMark) {
selectedChanges.formatChange = formatChangeSize ?
{from: formatChangePos, to: formatChangePos + formatChangeSize} :
getFromToMark(state.doc, formatChangePos, formatChangeMark)
if (deletionMark) {
selectedChanges.deletion = deletionSize
? { from: deletionPos, to: deletionPos + deletionSize }
: getFromToMark(state.doc, deletionPos, deletionMark);
}
}
return selectedChanges
if (formatChangeMark) {
selectedChanges.formatChange = formatChangeSize
? { from: formatChangePos, to: formatChangePos + formatChangeSize }
: getFromToMark(state.doc, formatChangePos, formatChangeMark);
}
console.log(selectedChanges);
return selectedChanges;
}
......@@ -355,23 +355,23 @@ const EditoriaSchema = {
}
]
},
small_caps: {
attrs: {
class: { default: "small-caps" }
},
inclusive: false,
parseDOM: [
{
tag: "span",
getAttrs(dom) {
return { class: dom.getAttribute("class") };
}
}
],
toDOM(node) {
return ["span", node.attrs, 0];
}
},
// small_caps: {
// attrs: {
// class: { default: "small-caps" }
// },
// inclusive: false,
// parseDOM: [
// {
// tag: "span",
// getAttrs(dom) {
// return { class: dom.getAttribute("class") };
// }
// }
// ],
// toDOM(node) {
// return ["span", node.attrs, 0];
// }
// },
source: {
parseDOM: [{ tag: "cite" }],
toDOM() {
......
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