Skip to content
Snippets Groups Projects
Commit 4e7f52ca authored by chris's avatar chris
Browse files

headings Active

parent 7e55de78
No related branches found
No related tags found
1 merge request!172Block level active
...@@ -19,7 +19,7 @@ const Button = ({ view = {}, item }) => { ...@@ -19,7 +19,7 @@ const Button = ({ view = {}, item }) => {
run(state, dispatch); run(state, dispatch);
}; };
const isActive = active && active(state); const isActive = active && active(state, activeViewId);
const isDisabled = const isDisabled =
enable && !enable(state) && !(select && select(state, activeViewId)); enable && !enable(state) && !(select && select(state, activeViewId));
......
...@@ -19,8 +19,17 @@ class Heading1 extends Tools { ...@@ -19,8 +19,17 @@ class Heading1 extends Tools {
} }
get active() { get active() {
return state => { return (state, activeViewId) => {
return Commands.blockActive(state.config.schema.nodes.heading, { 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, level: 1,
})(state); })(state);
}; };
......
...@@ -19,8 +19,17 @@ class Heading2 extends Tools { ...@@ -19,8 +19,17 @@ class Heading2 extends Tools {
} }
get active() { get active() {
return state => { return (state, activeViewId) => {
return Commands.blockActive(state.config.schema.nodes.heading, { 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, level: 2,
})(state); })(state);
}; };
......
...@@ -19,8 +19,17 @@ class Heading3 extends Tools { ...@@ -19,8 +19,17 @@ class Heading3 extends Tools {
} }
get active() { get active() {
return state => { return (state, activeViewId) => {
return Commands.blockActive(state.config.schema.nodes.heading, { 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, level: 3,
})(state); })(state);
}; };
......
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