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

Merge branch 'block-level-active' into 'master'

Block level active

See merge request !172
parents f7eace14 4e7f52ca
No related branches found
No related tags found
1 merge request!172Block level active
Showing
with 147 additions and 11 deletions
......@@ -19,10 +19,10 @@ const Button = ({ view = {}, item }) => {
run(state, dispatch);
};
const isActive = active && active(state);
const isActive = active && active(state, activeViewId);
const isDisabled =
enable && !enable(state) && !(select && select(view.state, activeViewId));
enable && !enable(state) && !(select && select(state, activeViewId));
return (
<MenuButton
......
......@@ -16,6 +16,12 @@ class Author extends Tools {
};
}
get active() {
return state => {
return Commands.blockActive(state.config.schema.nodes.author)(state);
};
}
select = (state, activeViewId) => {
if (activeViewId !== 'main') return false;
return true;
......
......@@ -16,6 +16,14 @@ class EpigraphPoetry extends Tools {
};
}
get active() {
return state => {
return Commands.blockActive(state.config.schema.nodes.epigraphPoetry)(
state,
);
};
}
select = (state, activeViewId) => {
if (activeViewId !== 'main') return false;
return true;
......
......@@ -17,6 +17,14 @@ class EpigraphProse extends Tools {
};
}
get active() {
return state => {
return Commands.blockActive(state.config.schema.nodes.epigraphProse)(
state,
);
};
}
select = (state, activeViewId) => {
if (activeViewId !== 'main') return false;
return true;
......
......@@ -18,6 +18,23 @@ class Heading1 extends Tools {
};
}
get active() {
return (state, activeViewId) => {
let isActive = true;
if (activeViewId !== 'main') return false;
const { from, to } = state.selection;
state.doc.nodesBetween(from, to, (node, pos) => {
if (node.type.name === 'list_item') {
isActive = false;
}
});
if (!isActive) return false;
return !Commands.setBlockType(state.config.schema.nodes.heading, {
level: 1,
})(state);
};
}
select = (state, activeViewId) => {
if (activeViewId !== 'main') return false;
return true;
......
......@@ -18,6 +18,23 @@ class Heading2 extends Tools {
};
}
get active() {
return (state, activeViewId) => {
let isActive = true;
if (activeViewId !== 'main') return false;
const { from, to } = state.selection;
state.doc.nodesBetween(from, to, (node, pos) => {
if (node.type.name === 'list_item') {
isActive = false;
}
});
if (!isActive) return false;
return !Commands.setBlockType(state.config.schema.nodes.heading, {
level: 2,
})(state);
};
}
select = (state, activeViewId) => {
if (activeViewId !== 'main') return false;
return true;
......
......@@ -18,6 +18,23 @@ class Heading3 extends Tools {
};
}
get active() {
return (state, activeViewId) => {
let isActive = true;
if (activeViewId !== 'main') return false;
const { from, to } = state.selection;
state.doc.nodesBetween(from, to, (node, pos) => {
if (node.type.name === 'list_item') {
isActive = false;
}
});
if (!isActive) return false;
return !Commands.setBlockType(state.config.schema.nodes.heading, {
level: 3,
})(state);
};
}
select = (state, activeViewId) => {
if (activeViewId !== 'main') return false;
return true;
......
......@@ -17,6 +17,12 @@ class SubTitle extends Tools {
};
}
get active() {
return state => {
return Commands.blockActive(state.config.schema.nodes.subtitle)(state);
};
}
select = (state, activeViewId) => {
if (activeViewId !== 'main') return false;
return true;
......
......@@ -2,7 +2,7 @@ import Tools from '../../lib/Tools';
import { injectable } from 'inversify';
import { Commands } from 'wax-prosemirror-utilities';
export default
export default
@injectable()
class Title extends Tools {
title = 'Change to Title';
......@@ -17,6 +17,12 @@ class Title extends Tools {
};
}
get active() {
return state => {
return Commands.blockActive(state.config.schema.nodes.title)(state);
};
}
select = (state, activeViewId) => {
if (activeViewId !== 'main') return false;
return true;
......
......@@ -21,6 +21,14 @@ class ExtractPoetry extends Tools {
return true;
};
get active() {
return state => {
return Commands.blockActive(state.config.schema.nodes.extractPoetry)(
state,
);
};
}
get enable() {
return state => {
return Commands.setBlockType(state.config.schema.nodes.extractPoetry)(
......
......@@ -16,6 +16,14 @@ class ExtractProse extends Tools {
};
}
get active() {
return state => {
return Commands.blockActive(state.config.schema.nodes.extractProse)(
state,
);
};
}
select = (state, activeViewId) => {
if (activeViewId !== 'main') return false;
return true;
......
......@@ -16,6 +16,14 @@ class ParagraphContinued extends Tools {
};
}
get active() {
return state => {
return Commands.blockActive(state.config.schema.nodes.paragraphCont)(
state,
);
};
}
select = (state, activeViewId) => {
if (activeViewId !== 'main') return false;
return true;
......
......@@ -17,6 +17,12 @@ class Paragraph extends Tools {
};
}
get active() {
return state => {
return Commands.blockActive(state.config.schema.nodes.paragraph)(state);
};
}
select = (state, activeViewId) => {
if (activeViewId !== 'main') return false;
return true;
......
......@@ -16,6 +16,12 @@ class SourceNote extends Tools {
};
}
get active() {
return state => {
return Commands.blockActive(state.config.schema.nodes.sourceNote)(state);
};
}
select = (state, activeViewId) => {
if (activeViewId !== 'main') return false;
return true;
......
......@@ -38,16 +38,31 @@ const markActive = type => state => {
: state.doc.rangeHasMark(from, to, type);
};
const blockActive = (type, attrs = {}) => state => {
const { $from, to, node } = state.selection;
if (node) {
return node.hasMarkup(type, attrs);
}
return to <= $from.end() && $from.parent.hasMarkup(type, attrs);
const blockActive = (nodeType, attrs = {}) => {
return (state, dispatch) => {
const { from, to } = state.selection;
let isActive = false;
state.doc.nodesBetween(from, to, (node, pos) => {
if (!node.isTextblock || node.hasMarkup(nodeType, attrs)) return;
if (node.type === nodeType) {
isActive = true;
}
});
return isActive;
};
};
//
// const blockActive = (type, attrs = {}) => state => {
// const { $from, to, node } = state.selection;
//
// if (node) {
// return node.hasMarkup(type, attrs);
// }
//
// return to <= $from.end() && $from.parent.hasMarkup(type, attrs);
// };
const canInsert = type => state => {
const { $from } = state.selection;
......
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