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

add extra headers

parent fe3001f4
No related branches found
No related tags found
1 merge request!333add extra headers
import React from 'react';
import { injectable } from 'inversify';
import { isEmpty } from 'lodash';
import { LeftSideButton } from 'wax-prosemirror-components';
import { Commands } from 'wax-prosemirror-utilities';
import Tools from '../../lib/Tools';
export default
@injectable()
class Heading2 extends Tools {
title = 'Change to heading level 5';
label = 'Heading 5';
name = 'Heading5';
get run() {
return (state, dispatch) => {
Commands.setBlockType(state.config.schema.nodes.heading5)(
state,
dispatch,
);
};
}
get active() {
return (state, activeViewId) => {
let isActive = false;
if (activeViewId !== 'main') return false;
const { from, to } = state.selection;
state.doc.nodesBetween(from, to, (node, pos) => {
if (node.type.name === 'heading5') {
isActive = true;
}
});
return isActive;
};
}
select = (state, activeViewId) => {
if (activeViewId !== 'main') return false;
return true;
};
get enable() {
return state => {
return Commands.setBlockType(state.config.schema.nodes.heading5)(state);
};
}
renderTool(view) {
if (isEmpty(view)) return null;
// eslint-disable-next-line no-underscore-dangle
return this._isDisplayed ? (
<LeftSideButton item={this.toJSON()} key="Heading5" view={view} />
) : null;
}
}
import React from 'react';
import { injectable } from 'inversify';
import { isEmpty } from 'lodash';
import { LeftSideButton } from 'wax-prosemirror-components';
import { Commands } from 'wax-prosemirror-utilities';
import Tools from '../../lib/Tools';
export default
@injectable()
class Heading2 extends Tools {
title = 'Change to heading level 6';
label = 'Heading 6';
name = 'Heading6';
get run() {
return (state, dispatch) => {
Commands.setBlockType(state.config.schema.nodes.heading6)(
state,
dispatch,
);
};
}
get active() {
return (state, activeViewId) => {
let isActive = false;
if (activeViewId !== 'main') return false;
const { from, to } = state.selection;
state.doc.nodesBetween(from, to, (node, pos) => {
if (node.type.name === 'heading6') {
isActive = true;
}
});
return isActive;
};
}
select = (state, activeViewId) => {
if (activeViewId !== 'main') return false;
return true;
};
get enable() {
return state => {
return Commands.setBlockType(state.config.schema.nodes.heading6)(state);
};
}
renderTool(view) {
if (isEmpty(view)) return null;
// eslint-disable-next-line no-underscore-dangle
return this._isDisplayed ? (
<LeftSideButton item={this.toJSON()} key="Heading5" view={view} />
) : null;
}
}
import Heading2 from './Heading2'; import Heading2 from './Heading2';
import Heading3 from './Heading3'; import Heading3 from './Heading3';
import Heading4 from './Heading4'; import Heading4 from './Heading4';
import Heading5 from './Heading5';
import Heading6 from './Heading6';
import Service from '../../Service'; import Service from '../../Service';
class HeadingService extends Service { class HeadingService extends Service {
// boot() {}
register() { register() {
this.container.bind('Heading2').to(Heading2); this.container.bind('Heading2').to(Heading2);
this.container.bind('Heading3').to(Heading3); this.container.bind('Heading3').to(Heading3);
this.container.bind('Heading4').to(Heading4); this.container.bind('Heading4').to(Heading4);
this.container.bind('Heading5').to(Heading5);
this.container.bind('Heading6').to(Heading6);
const createNode = this.container.get('CreateNode'); const createNode = this.container.get('CreateNode');
createNode({ createNode({
heading2: { heading2: {
...@@ -56,6 +58,36 @@ class HeadingService extends Service { ...@@ -56,6 +58,36 @@ class HeadingService extends Service {
}, },
}, },
}); });
createNode({
heading5: {
content: 'inline*',
group: 'block',
defining: true,
parseDOM: [
{
tag: 'h5',
},
],
toDOM(node) {
return ['h5', 0];
},
},
});
createNode({
heading6: {
content: 'inline*',
group: 'block',
defining: true,
parseDOM: [
{
tag: 'h6',
},
],
toDOM(node) {
return ['h6', 0];
},
},
});
} }
} }
......
...@@ -17,6 +17,8 @@ class Display extends ToolGroup { ...@@ -17,6 +17,8 @@ class Display extends ToolGroup {
@inject('Heading2') heading2, @inject('Heading2') heading2,
@inject('Heading3') heading3, @inject('Heading3') heading3,
@inject('Heading4') heading4, @inject('Heading4') heading4,
@inject('Heading5') heading5,
@inject('Heading6') heading6,
) { ) {
super(); super();
this.tools = [ this.tools = [
...@@ -28,6 +30,8 @@ class Display extends ToolGroup { ...@@ -28,6 +30,8 @@ class Display extends ToolGroup {
heading2, heading2,
heading3, heading3,
heading4, heading4,
heading5,
heading6,
]; ];
} }
} }
......
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