Skip to content

Commit

Permalink
Drop compiler dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
mixonic committed Jul 9, 2015
1 parent bb36364 commit 45ce1f0
Show file tree
Hide file tree
Showing 43 changed files with 572 additions and 356 deletions.
3 changes: 1 addition & 2 deletions Brocfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ var demo = require('./broccoli/demo');
var jquery = require('./broccoli/jquery');

var vendoredModules = [
{name: 'content-kit-compiler', options: {libDirName: 'src'}},
{name: 'content-kit-utils', options: {libDirName: 'src'}}
{name: 'content-kit-utils', options: {libDirName: 'src'}}
];
var packageName = require('./package.json').name;

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"broccoli-merge-trees": "^0.2.1",
"broccoli-multi-builder": "^0.2.5",
"broccoli-test-builder": "^0.1.0",
"content-kit-compiler": "^0.3.1",
"content-kit-utils": "^0.2.0",
"del": "^1.1.1",
"esperanto": "^0.6.32",
Expand Down
5 changes: 2 additions & 3 deletions src/js/commands/bold.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import TextFormatCommand from './text-format';
import { getSelectionBlockTagName } from '../utils/selection-utils';
import { inherit } from 'content-kit-utils';
import { Type } from 'content-kit-compiler';

var RegExpHeadingTag = /^(h1|h2|h3|h4|h5|h6)$/i;

function BoldCommand() {
TextFormatCommand.call(this, {
name: 'bold',
tag: Type.BOLD.tag,
mappedTags: Type.BOLD.mappedTags,
tag: 'strong',
mappedTags: ['b'],
button: '<i class="ck-icon-bold"></i>'
});
}
Expand Down
5 changes: 1 addition & 4 deletions src/js/commands/card.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import Command from './base';
import { inherit } from 'content-kit-utils';
import {
BlockModel,
Type
} from 'content-kit-compiler';

function injectCardBlock(cardName, cardPayload, editor, index) {
throw new Error('Unimplemented: BlockModel and Type.CARD are no longer things');
// FIXME: Do we change the block model internal representation here?
var cardBlock = BlockModel.createWithType(Type.CARD, {
attributes: {
Expand Down
5 changes: 2 additions & 3 deletions src/js/commands/format-block.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import TextFormatCommand from './text-format';
import { getSelectionBlockElement, selectNode } from '../utils/selection-utils';
import { inherit } from 'content-kit-utils';
import { Type } from 'content-kit-compiler';
import { doc } from 'content-kit-compiler';

function FormatBlockCommand(options) {
options = options || {};
Expand All @@ -18,12 +16,13 @@ FormatBlockCommand.prototype.exec = function() {
var blockElement = getSelectionBlockElement();
// Allow block commands to be toggled back to a text block
if(tag === blockElement.tagName.toLowerCase()) {
throw new Error('Unimplemented: Type.BOLD.paragraph must be replaced');
value = Type.PARAGRAPH.tag;
} else {
// Flattens the selection before applying the block format.
// Otherwise, undesirable nested blocks can occur.
// TODO: would love to be able to remove this
var flatNode = doc.createTextNode(blockElement.textContent);
var flatNode = document.createTextNode(blockElement.textContent);
blockElement.parentNode.insertBefore(flatNode, blockElement);
blockElement.parentNode.removeChild(blockElement);
selectNode(flatNode);
Expand Down
3 changes: 1 addition & 2 deletions src/js/commands/heading.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import FormatBlockCommand from './format-block';
import { inherit } from 'content-kit-utils';
import { Type } from 'content-kit-compiler';

function HeadingCommand() {
FormatBlockCommand.call(this, {
name: 'heading',
tag: Type.HEADING.tag,
tag: 'h2',
button: '<i class="ck-icon-heading"></i>1'
});
}
Expand Down
12 changes: 4 additions & 8 deletions src/js/commands/image.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import Command from './base';
import Message from '../views/message';
import {
Type,
BlockModel,
} from 'content-kit-compiler';
import { win, doc } from 'content-kit-editor/utils/compat';
import { inherit } from 'content-kit-utils';
import { FileUploader } from '../utils/http-utils';

function createFileInput(command) {
var fileInput = doc.createElement('input');
var fileInput = document.createElement('input');
fileInput.type = 'file';
fileInput.accept = 'image/*';
fileInput.className = 'ck-file-input';
Expand All @@ -20,12 +15,13 @@ function createFileInput(command) {
}

function injectImageBlock(src, editor, index) {
throw new Error('Unimplemented: BlockModel and Type.IMAGE are no longer things');
var imageModel = BlockModel.createWithType(Type.IMAGE, { attributes: { src: src } });
editor.replaceBlock(imageModel, index);
}

function renderFromFile(file, editor, index) {
if (file && win.FileReader) {
if (file && window.FileReader) {
var reader = new FileReader();
reader.onload = function(e) {
var base64Src = e.target.result;
Expand All @@ -51,7 +47,7 @@ ImageCommand.prototype = {
var fileInput = this.fileInput;
if (!fileInput) {
fileInput = this.fileInput = createFileInput(this);
doc.body.appendChild(fileInput);
document.body.appendChild(fileInput);
}
fileInput.dispatchEvent(new MouseEvent('click', { bubbles: false }));
},
Expand Down
5 changes: 2 additions & 3 deletions src/js/commands/italic.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import TextFormatCommand from './text-format';
import { inherit } from 'content-kit-utils';
import { Type }from 'content-kit-compiler';

function ItalicCommand() {
TextFormatCommand.call(this, {
name: 'italic',
tag: Type.ITALIC.tag,
mappedTags: Type.ITALIC.mappedTags,
tag: 'em',
mappedTags: ['i'],
button: '<i class="ck-icon-italic"></i>'
});
}
Expand Down
3 changes: 1 addition & 2 deletions src/js/commands/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import TextFormatCommand from './text-format';
import Prompt from '../views/prompt';
import { getSelectionTagName } from '../utils/selection-utils';
import { inherit } from 'content-kit-utils';
import { Type } from 'content-kit-compiler';

var RegExpHttp = /^https?:\/\//i;

function LinkCommand() {
TextFormatCommand.call(this, {
name: 'link',
tag: Type.LINK.tag,
tag: 'a',
action: 'createLink',
removeAction: 'unlink',
button: '<i class="ck-icon-link"></i>',
Expand Down
8 changes: 3 additions & 5 deletions src/js/commands/list.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import TextFormatCommand from './text-format';
import { getSelectionBlockElement, selectNode, getSelectionTagName } from '../utils/selection-utils';
import { inherit } from 'content-kit-utils';
import { Type } from 'content-kit-compiler';
import { win } from 'content-kit-editor/utils/compat';

function ListCommand(options) {
TextFormatCommand.call(this, options);
Expand All @@ -11,7 +9,7 @@ inherit(ListCommand, TextFormatCommand);

ListCommand.prototype.exec = function() {
ListCommand._super.prototype.exec.call(this);

// After creation, lists need to be unwrapped
// TODO: eventually can remove this when direct model manipulation is ready
var listElement = getSelectionBlockElement();
Expand All @@ -30,9 +28,9 @@ ListCommand.prototype.checkAutoFormat = function(node) {
var regex = this.autoFormatRegex, text;
if (node && regex) {
text = node.textContent;
if (Type.LIST_ITEM.tag !== getSelectionTagName() && regex.test(text)) {
if ('li' !== getSelectionTagName() && regex.test(text)) {
this.exec();
win.getSelection().anchorNode.textContent = text.replace(regex, '');
window.getSelection().anchorNode.textContent = text.replace(regex, '');
return true;
}
}
Expand Down
14 changes: 5 additions & 9 deletions src/js/commands/oembed.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import Command from './base';
import Prompt from '../views/prompt';
import Message from '../views/message';
import {
EmbedModel,
doc
} from 'content-kit-compiler';
import { inherit } from 'content-kit-utils';
import { OEmbedder } from '../utils/http-utils';
import { win } from 'content-kit-editor/utils/compat';

function loadTwitterWidgets(element) {
if (win.twttr) {
win.twttr.widgets.load(element);
if (window.twttr) {
window.twttr.widgets.load(element);
} else {
var script = doc.createElement('script');
var script = document.createElement('script');
script.async = true;
script.src = 'http://platform.twitter.com/widgets.js';
doc.head.appendChild(script);
document.head.appendChild(script);
}
}

Expand Down Expand Up @@ -58,6 +53,7 @@ OEmbedCommand.prototype.exec = function(url) {
new Message().showError(response.error_message);
embedIntent.show();
} else {
throw new Error('Unimplemented EmbedModel is not a thing');
var embedModel = new EmbedModel(response);
editorContext.insertBlock(embedModel, index);
editorContext.renderBlockAt(index);
Expand Down
3 changes: 1 addition & 2 deletions src/js/commands/ordered-list.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import ListCommand from './list';
import { inherit } from 'content-kit-utils';
import { Type } from 'content-kit-compiler';

function OrderedListCommand() {
ListCommand.call(this, {
name: 'ordered list',
tag: Type.ORDERED_LIST.tag,
tag: 'ol',
action: 'insertOrderedList'
});
}
Expand Down
3 changes: 1 addition & 2 deletions src/js/commands/quote.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import FormatBlockCommand from './format-block';
import { inherit } from 'content-kit-utils';
import { Type } from 'content-kit-compiler';

function QuoteCommand() {
FormatBlockCommand.call(this, {
name: 'quote',
tag: Type.QUOTE.tag,
tag: 'blockquote',
button: '<i class="ck-icon-quote"></i>'
});
}
Expand Down
3 changes: 1 addition & 2 deletions src/js/commands/subheading.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import FormatBlockCommand from './format-block';
import { inherit } from 'content-kit-utils';
import { Type } from 'content-kit-compiler';

function SubheadingCommand() {
FormatBlockCommand.call(this, {
name: 'subheading',
tag: Type.SUBHEADING.tag,
tag: 'h3',
button: '<i class="ck-icon-heading"></i>2'
});
}
Expand Down
5 changes: 2 additions & 3 deletions src/js/commands/text-format.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Command from './base';
import { inherit } from 'content-kit-utils';
import { doc } from 'content-kit-compiler';

function TextFormatCommand(options) {
options = options || {};
Expand All @@ -15,10 +14,10 @@ inherit(TextFormatCommand, Command);

TextFormatCommand.prototype = {
exec: function(value) {
doc.execCommand(this.action, false, value || null);
document.execCommand(this.action, false, value || null);
},
unexec: function(value) {
doc.execCommand(this.removeAction, false, value || null);
document.execCommand(this.removeAction, false, value || null);
}
};

Expand Down
3 changes: 1 addition & 2 deletions src/js/commands/unordered-list.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import ListCommand from './list';
import { inherit } from 'content-kit-utils';
import { Type } from 'content-kit-compiler';

function UnorderedListCommand() {
ListCommand.call(this, {
name: 'list',
tag: Type.LIST.tag,
tag: 'ul',
action: 'insertUnorderedList'
});
}
Expand Down
38 changes: 0 additions & 38 deletions src/js/editor/editor-factory.js

This file was deleted.

Loading

0 comments on commit 45ce1f0

Please sign in to comment.