diff --git a/src/js/content-kit-editor/commands/bold.js b/src/js/content-kit-editor/commands/bold.js index d3b95885a..5c3c613df 100644 --- a/src/js/content-kit-editor/commands/bold.js +++ b/src/js/content-kit-editor/commands/bold.js @@ -1,9 +1,10 @@ import TextFormatCommand from './text-format'; -import { RegEx } from '../constants'; import { getSelectionBlockTagName } from '../utils/selection-utils'; import { inherit } from '../../content-kit-utils/object-utils'; import Type from '../../content-kit-compiler/types/type'; +var RegExpHeadingTag = /^(h1|h2|h3|h4|h5|h6)$/i; + function BoldCommand() { TextFormatCommand.call(this, { name: 'bold', @@ -15,7 +16,7 @@ inherit(BoldCommand, TextFormatCommand); BoldCommand.prototype.exec = function() { // Don't allow executing bold command on heading tags - if (!RegEx.HEADING_TAG.test(getSelectionBlockTagName())) { + if (!RegExpHeadingTag.test(getSelectionBlockTagName())) { BoldCommand._super.prototype.exec.call(this); } }; diff --git a/src/js/content-kit-editor/commands/link.js b/src/js/content-kit-editor/commands/link.js index b069f2791..cc310ff05 100644 --- a/src/js/content-kit-editor/commands/link.js +++ b/src/js/content-kit-editor/commands/link.js @@ -1,10 +1,11 @@ import TextFormatCommand from './text-format'; import Prompt from '../views/prompt'; -import { RegEx } from '../constants'; import { getSelectionTagName } from '../utils/selection-utils'; import { inherit } from '../../content-kit-utils/object-utils'; import Type from '../../content-kit-compiler/types/type'; +var RegExpHttp = /^https?:\/\//i; + function LinkCommand() { TextFormatCommand.call(this, { name: 'link', @@ -24,7 +25,7 @@ LinkCommand.prototype.exec = function(url) { if(this.tag === getSelectionTagName()) { this.unexec(); } else { - if (!RegEx.HTTP_PROTOCOL.test(url)) { + if (!RegExpHttp.test(url)) { url = 'http://' + url; } LinkCommand._super.prototype.exec.call(this, url); diff --git a/src/js/content-kit-editor/constants.js b/src/js/content-kit-editor/constants.js deleted file mode 100644 index f8133ee2f..000000000 --- a/src/js/content-kit-editor/constants.js +++ /dev/null @@ -1,37 +0,0 @@ -import Type from '../content-kit-compiler/types/type'; - -var Keycodes = { - BKSP : 8, - ENTER : 13, - ESC : 27, - DEL : 46 -}; - -var RegEx = { - NEWLINE : /[\r\n]/g, - HTTP_PROTOCOL : /^https?:\/\//i, - HEADING_TAG : /^(h1|h2|h3|h4|h5|h6)$/i -}; - -var SelectionDirection = { - LEFT_TO_RIGHT : 1, - RIGHT_TO_LEFT : 2, - SAME_NODE : 3 -}; - -var ToolbarDirection = { - TOP : 1, - RIGHT : 2 -}; - -// TODO: remove, get from Compiler DefaultBlockTypeSet -var RootTags = [ - Type.TEXT.tag, - Type.HEADING.tag, - Type.SUBHEADING.tag, - Type.QUOTE.tag, - Type.LIST.tag, - Type.ORDERED_LIST.tag -]; - -export { Keycodes, RegEx, SelectionDirection, ToolbarDirection, RootTags }; diff --git a/src/js/content-kit-editor/editor/editor-html-renderer.js b/src/js/content-kit-editor/editor/editor-html-renderer.js index e3f913be2..0a42a6e53 100644 --- a/src/js/content-kit-editor/editor/editor-html-renderer.js +++ b/src/js/content-kit-editor/editor/editor-html-renderer.js @@ -1,8 +1,9 @@ -import { RegEx } from '../constants'; import HTMLRenderer from '../../content-kit-compiler/renderers/html-renderer'; import Type from '../../content-kit-compiler/types/type'; import { inherit } from '../../content-kit-utils/object-utils'; +var RegExpHttp = /^https?:\/\//i; + function embedRenderer(model) { var embedAttrs = model.attributes; var isVideo = embedAttrs.embed_type === 'video'; @@ -17,7 +18,7 @@ function embedRenderer(model) { } function imageRenderer(model) { - var imagePersisted = RegEx.HTTP_PROTOCOL.test(model.attributes.src); + var imagePersisted = RegExpHttp.test(model.attributes.src); return '
'; diff --git a/src/js/content-kit-editor/editor/editor.js b/src/js/content-kit-editor/editor/editor.js index e265a6c75..1d5a31cd9 100644 --- a/src/js/content-kit-editor/editor/editor.js +++ b/src/js/content-kit-editor/editor/editor.js @@ -13,7 +13,7 @@ import OrderedListCommand from '../commands/ordered-list'; import ImageCommand from '../commands/image'; import OEmbedCommand from '../commands/oembed'; import TextFormatCommand from '../commands/text-format'; -import { Keycodes } from '../constants'; +import Keycodes from '../utils/keycodes'; import { getSelectionBlockElement, getSelectionBlockTagName } from '../utils/selection-utils'; import EventEmitter from '../utils/event-emitter'; import { cleanPastedContent } from '../utils/paste-utils'; diff --git a/src/js/content-kit-editor/utils/keycodes.js b/src/js/content-kit-editor/utils/keycodes.js new file mode 100644 index 000000000..eee91fda5 --- /dev/null +++ b/src/js/content-kit-editor/utils/keycodes.js @@ -0,0 +1,6 @@ +export default { + BKSP : 8, + ENTER : 13, + ESC : 27, + DEL : 46 +}; diff --git a/src/js/content-kit-editor/utils/paste-utils.js b/src/js/content-kit-editor/utils/paste-utils.js index 0e428df29..b66e8daed 100644 --- a/src/js/content-kit-editor/utils/paste-utils.js +++ b/src/js/content-kit-editor/utils/paste-utils.js @@ -1,9 +1,11 @@ -import { RegEx } from '../constants'; + +var RegExpNewLine = /[\r\n]/g; function plainTextToBlocks(plainText, tag) { - var blocks = plainText.split(RegEx.NEWLINE), - len = blocks.length, - block, openTag, closeTag, content, i; + var blocks = plainText.split(RegExpNewLine); + var len = blocks.length; + var block, openTag, closeTag, content, i; + if(len < 2) { return plainText; } else { diff --git a/src/js/content-kit-editor/utils/selection-utils.js b/src/js/content-kit-editor/utils/selection-utils.js index e1781e31c..91cb35c3d 100644 --- a/src/js/content-kit-editor/utils/selection-utils.js +++ b/src/js/content-kit-editor/utils/selection-utils.js @@ -1,5 +1,21 @@ -import { SelectionDirection, RootTags } from '../constants'; import { nodeIsDescendantOfElement } from './element-utils'; +import Type from '../../content-kit-compiler/types/type'; + +// TODO: remove, pass in Editor's current block set +var RootTags = [ + Type.TEXT.tag, + Type.HEADING.tag, + Type.SUBHEADING.tag, + Type.QUOTE.tag, + Type.LIST.tag, + Type.ORDERED_LIST.tag +]; + +var SelectionDirection = { + LEFT_TO_RIGHT : 1, + RIGHT_TO_LEFT : 2, + SAME_NODE : 3 +}; function getDirectionOfSelection(selection) { var node = selection.anchorNode; diff --git a/src/js/content-kit-editor/views/embed-intent.js b/src/js/content-kit-editor/views/embed-intent.js index ace92c320..0ebe26769 100644 --- a/src/js/content-kit-editor/views/embed-intent.js +++ b/src/js/content-kit-editor/views/embed-intent.js @@ -3,7 +3,7 @@ import Toolbar from './toolbar'; import { inherit } from '../../content-kit-utils/object-utils'; import { getSelectionBlockElement } from '../utils/selection-utils'; import { elementContentIsEmpty, positionElementToLeftOf, positionElementCenteredIn } from '../utils/element-utils'; -import { ToolbarDirection, Keycodes } from '../constants'; +import Keycodes from '../utils/keycodes'; import { createDiv } from '../utils/element-utils'; var LayoutStyle = { @@ -37,7 +37,7 @@ function EmbedIntent(options) { e.stopPropagation(); }); - embedIntent.toolbar = new Toolbar({ embedIntent: embedIntent, editor: embedIntent.editorContext, commands: options.commands, direction: ToolbarDirection.RIGHT }); + embedIntent.toolbar = new Toolbar({ embedIntent: embedIntent, editor: embedIntent.editorContext, commands: options.commands, direction: Toolbar.Direction.RIGHT }); embedIntent.isActive = false; function embedIntentHandler() { diff --git a/src/js/content-kit-editor/views/prompt.js b/src/js/content-kit-editor/views/prompt.js index 69f945850..ffa210b92 100644 --- a/src/js/content-kit-editor/views/prompt.js +++ b/src/js/content-kit-editor/views/prompt.js @@ -3,7 +3,7 @@ import { inherit } from '../../content-kit-utils/object-utils'; import { inherit } from '../../content-kit-utils/object-utils'; import { restoreRange } from '../utils/selection-utils'; import { createDiv, positionElementToRect } from '../utils/element-utils'; -import { Keycodes } from '../constants'; +import Keycodes from '../utils/keycodes'; var container = document.body; var hiliter = createDiv('ck-editor-hilite'); diff --git a/src/js/content-kit-editor/views/text-format-toolbar.js b/src/js/content-kit-editor/views/text-format-toolbar.js index 901cc2c5d..b8828983c 100644 --- a/src/js/content-kit-editor/views/text-format-toolbar.js +++ b/src/js/content-kit-editor/views/text-format-toolbar.js @@ -1,7 +1,7 @@ import Toolbar from './toolbar'; import { inherit } from '../../content-kit-utils/object-utils'; import { selectionIsEditable, selectionIsInElement } from '../utils/selection-utils'; -import { Keycodes } from '../constants'; +import Keycodes from '../utils/keycodes'; function handleTextSelection(toolbar) { var selection = window.getSelection(); diff --git a/src/js/content-kit-editor/views/toolbar.js b/src/js/content-kit-editor/views/toolbar.js index 2da02bd12..4f58878c8 100644 --- a/src/js/content-kit-editor/views/toolbar.js +++ b/src/js/content-kit-editor/views/toolbar.js @@ -2,9 +2,13 @@ import View from './view'; import ToolbarButton from './toolbar-button'; import { inherit } from '../../content-kit-utils/object-utils'; import { tagsInSelection } from '../utils/selection-utils'; -import { ToolbarDirection } from '../constants'; import { createDiv, swapElements, positionElementToRightOf, positionElementCenteredAbove } from '../utils/element-utils'; +var ToolbarDirection = { + TOP : 1, + RIGHT : 2 +}; + function updateButtonsForSelection(buttons, selection) { var selectedTags = tagsInSelection(selection), len = buttons.length, @@ -118,4 +122,6 @@ Toolbar.prototype.setDirection = function(direction) { } }; +Toolbar.Direction = ToolbarDirection; + export default Toolbar;