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

Merge branch 'fix-link' into 'master'

Fix link

See merge request !159
parents 226eb1e9 452eebd6
No related branches found
No related tags found
1 merge request!159Fix link
......@@ -14,18 +14,22 @@ Wax Editor is build on top of the Prosemirror library. Check Prosemirror [websit
Wax-prosemirror is under active development. The current roadmap is as follows:
### September 2020
Alpha version, including comments and track changes. See the rest of this file for a full list of current functionality.
### November 2020
Beta version, including some new features:
* Find and replace
* Spellchecker
* Special characters
* Transform cases
* Word counter
* Custom tags
- Find and replace
- Spellchecker
- Special characters
- Transform cases
- Word counter
- Custom tags
### January 2021
V1.0, freeze new feature development, focus on stability, testing and bug fixes
## Get up and running
......
......@@ -4,7 +4,7 @@
"version": "0.0.16",
"description": "Wax prosemirror UI components",
"license": "MIT",
"main": "dist/index.js",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "BABEL_ENV=production rollup -c"
......
......@@ -22,10 +22,7 @@ const Button = styled.button`
const LinkComponent = ({ mark, setPosition, position }) => {
const href = mark ? mark.attrs.href : null;
const linkMark = mark ? mark : null;
const {
view: { main },
activeView,
} = useContext(WaxContext);
const { activeView } = useContext(WaxContext);
const { state, dispatch } = activeView;
const ref = useRef(null);
const linkInput = useRef(null);
......@@ -57,7 +54,8 @@ const LinkComponent = ({ mark, setPosition, position }) => {
};
const removeLink = () => {
dispatch(state.tr.removeMark(mark.from, mark.to, state.schema.marks.link));
const { tr } = state;
dispatch(tr.removeMark(mark.from, mark.to, state.schema.marks.link));
activeView.focus();
};
......@@ -90,7 +88,7 @@ const LinkComponent = ({ mark, setPosition, position }) => {
selection: { $from, $to },
} = state;
const PMLinkMark = state.schema.marks['link'];
const actualMark = DocumentHelpers.getSelectionMark(state, PMLinkMark);
const actualMark = DocumentHelpers.findMark(state, PMLinkMark);
setLLastLinkMark(actualMark);
if (
......
......@@ -4,7 +4,7 @@
"version": "0.0.16",
"description": "Wax prosemirror core",
"license": "MIT",
"main": "dist/index.js",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "BABEL_ENV=production rollup -c"
......
......@@ -4,7 +4,7 @@
"version": "0.0.16",
"description": "Wax prosemirror layouts",
"license": "MIT",
"main": "dist/index.js",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "BABEL_ENV=production rollup -c"
......
......@@ -4,7 +4,7 @@
"version": "0.0.16",
"description": "Wax prosemirror plugins",
"license": "MIT",
"main": "dist/index.js",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "BABEL_ENV=production rollup -c"
......
......@@ -4,7 +4,7 @@
"version": "0.0.16",
"description": "Wax prosemirror schema",
"license": "MIT",
"main": "dist/index.js",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "BABEL_ENV=production rollup -c"
......
......@@ -4,7 +4,7 @@
"version": "0.0.16",
"description": "Wax prosemirror services",
"license": "MIT",
"main": "dist/index.js",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "BABEL_ENV=production rollup -c"
......
import { useState, useContext, useLayoutEffect, useCallback } from "react";
import { isObject } from "lodash";
import { WaxContext } from "wax-prosemirror-core";
import { DocumentHelpers } from "wax-prosemirror-utilities";
import { useState, useContext, useLayoutEffect, useCallback } from 'react';
import { isObject } from 'lodash';
import { WaxContext } from 'wax-prosemirror-core';
import { DocumentHelpers } from 'wax-prosemirror-utilities';
const defaultOverlay = {
left: null,
top: null,
from: null,
to: null,
mark: null
mark: null,
};
export default options => {
const { view: { main }, activeView } = useContext(WaxContext);
const {
view: { main },
activeView,
} = useContext(WaxContext);
const [position, setPosition] = useState({
position: "absolute",
...defaultOverlay
position: 'absolute',
...defaultOverlay,
});
let mark = {};
......@@ -34,7 +37,7 @@ export default options => {
const top = end.top + 20;
return {
top,
left
left,
};
};
......@@ -48,14 +51,14 @@ export default options => {
top,
from,
to,
selection
selection,
};
};
const displayOnMark = (activeView, options) => {
const { markType, followCursor } = options;
const PMmark = activeView.state.schema.marks[markType];
mark = DocumentHelpers.getSelectionMark(activeView.state, PMmark);
mark = DocumentHelpers.findMark(activeView.state, PMmark);
if (!isObject(mark)) return defaultOverlay;
const { from, to } = followCursor ? activeView.state.selection : mark;
......@@ -67,7 +70,7 @@ export default options => {
top,
from,
to,
mark
mark,
};
};
......@@ -81,15 +84,12 @@ export default options => {
return displayOnMark(activeView, options);
});
useLayoutEffect(
() => {
setPosition({
position: "absolute",
...updatePosition(options.followCursor)
});
},
[JSON.stringify(updatePosition(options.followCursor))]
);
useLayoutEffect(() => {
setPosition({
position: 'absolute',
...updatePosition(options.followCursor),
});
}, [JSON.stringify(updatePosition(options.followCursor))]);
return [position, setPosition, mark];
};
......@@ -4,7 +4,7 @@
"version": "0.0.16",
"description": "Wax prosemirror themes",
"license": "MIT",
"main": "dist/index.js",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "BABEL_ENV=production rollup -c"
......
......@@ -4,7 +4,7 @@
"version": "0.0.16",
"description": "Wax prosemirror utilities",
"license": "MIT",
"main": "dist/index.js",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "BABEL_ENV=production rollup -c"
......
......@@ -25,27 +25,27 @@ const findMark = (state, PMmark, toArr = false) => {
return markFound;
};
const getSelectionMark = (state, PMmark) => {
const {
selection: { $from, $to },
doc,
} = state;
let markFound;
doc.nodesBetween($from.pos, $to.pos, (node, from) => {
if (node.marks) {
const actualMark = node.marks.find(mark => mark.type === PMmark);
if (actualMark) {
markFound = {
from: $from.pos,
to: $to.pos,
attrs: actualMark.attrs,
};
}
}
});
return markFound;
};
// const getSelectionMark = (state, PMmark) => {
// const {
// selection: { $from, $to },
// doc,
// } = state;
// let markFound;
// doc.nodesBetween($from.pos, $to.pos, (node, from) => {
// if (node.marks) {
// const actualMark = node.marks.find(mark => mark.type === PMmark);
// if (actualMark) {
// markFound = {
// from,
// to: from + node.nodeSize,
// attrs: actualMark.attrs,
// };
// }
// }
// });
//
// return markFound;
// };
/* this is a workaround for now to find marks
that are pm will break them.
......@@ -104,11 +104,17 @@ const findMarkPosition = (activeView, initialPos, markType) => {
const actualMark = start.node.marks.find(mark => mark.type.name === markType);
let startIndex = $pos.index();
let startPos = $pos.start() + start.offset;
while (startIndex > 0 && actualMark.isInSet(parent.child(startIndex - 1).marks))
while (
startIndex > 0 &&
actualMark.isInSet(parent.child(startIndex - 1).marks)
)
startPos -= parent.child(--startIndex).nodeSize;
let endIndex = $pos.indexAfter();
let endPos = startPos + start.node.nodeSize;
while (endPos < parent.childCount && actualMark.isInSet(parent.child(endIndex).marks))
while (
endPos < parent.childCount &&
actualMark.isInSet(parent.child(endIndex).marks)
)
endPos += parent.child(endIndex++).nodeSize;
return { from: startPos, to: endPos };
};
......@@ -163,7 +169,6 @@ export default {
findInlineNodes,
findChildrenByMark,
findChildrenByAttr,
getSelectionMark,
findFragmentedMark,
findAllMarksWithSameId,
findMarkPosition,
......
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