-
Notifications
You must be signed in to change notification settings - Fork 396
/
Copy pathscribe-heading-plugin.js
40 lines (33 loc) · 1.19 KB
/
scribe-heading-plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"use strict";
var scribeHeadingPlugin = function(block) {
return function(scribe) {
let { defaultHeadingLevel, headingLevels } = block.editorOptions;
headingLevels = headingLevels.sort();
const minHeadingLevel = headingLevels[0];
const maxHeadingLevel = headingLevels[headingLevels.length - 1];
const headingCommand = new scribe.api.Command(`heading`);
headingCommand.queryEnabled = () => {
return block.inline_editable;
};
headingCommand.queryState = () => {
if (block.type === 'heading') {
return block.getBlockData().level || defaultHeadingLevel || minHeadingLevel;
} else {
return false;
}
};
headingCommand.execute = function headingCommandExecute(value) {
const nextIndex = headingLevels.indexOf(block.getBlockData().level) + 1;
const level = headingLevels[nextIndex];
const blockType = level ? 'Heading' : 'Text';
var data = {
format: 'html',
level: level,
text: block.getScribeInnerContent()
};
block.mediator.trigger("block:replace", block.el, blockType, data);
};
scribe.commands.heading = headingCommand;
};
};
module.exports = scribeHeadingPlugin;