Skip to content

Commit

Permalink
built website from 1222772
Browse files Browse the repository at this point in the history
  • Loading branch information
mixonic committed Jun 6, 2017
1 parent 1222772 commit e75e339
Show file tree
Hide file tree
Showing 74 changed files with 10,403 additions and 6,269 deletions.
1,853 changes: 1,280 additions & 573 deletions website/amd/mobiledoc-kit.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion website/amd/mobiledoc-kit.map

Large diffs are not rendered by default.

30 changes: 23 additions & 7 deletions website/commonjs/mobiledoc-kit/editor/edit-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ function findLeafSectionAtIndex(post, index) {
}

var Snapshot = (function () {
function Snapshot(editor) {
function Snapshot(takenAt, editor) {
var editAction = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2];

_classCallCheck(this, Snapshot);

this.mobiledoc = editor.serialize();
this.editor = editor;
this.editAction = editAction;
this.takenAt = takenAt;

this.snapshotRange();
}
Expand Down Expand Up @@ -76,6 +80,11 @@ var Snapshot = (function () {
return head.toRange(tail);
}
}
}, {
key: 'groupsWith',
value: function groupsWith(groupingTimeout, editAction, takenAt) {
return editAction !== null && this.editAction === editAction && this.takenAt + groupingTimeout > takenAt;
}
}]);

return Snapshot;
Expand All @@ -84,14 +93,15 @@ var Snapshot = (function () {
exports.Snapshot = Snapshot;

var EditHistory = (function () {
function EditHistory(editor, queueLength) {
function EditHistory(editor, queueLength, groupingTimeout) {
_classCallCheck(this, EditHistory);

this.editor = editor;
this._undoStack = new _utilsFixedQueue['default'](queueLength);
this._redoStack = new _utilsFixedQueue['default'](queueLength);

this._pendingSnapshot = null;
this._groupingTimeout = groupingTimeout;
}

_createClass(EditHistory, [{
Expand All @@ -105,14 +115,20 @@ var EditHistory = (function () {
}, {
key: 'storeSnapshot',
value: function storeSnapshot() {
var editAction = arguments.length <= 0 || arguments[0] === undefined ? null : arguments[0];

var now = Date.now();
// store pending snapshot
if (this._pendingSnapshot) {
this._undoStack.push(this._pendingSnapshot);
var pendingSnapshot = this._pendingSnapshot;
if (pendingSnapshot) {
if (!pendingSnapshot.groupsWith(this._groupingTimeout, editAction, now)) {
this._undoStack.push(pendingSnapshot);
}
this._redoStack.clear();
}

// take new pending snapshot to store next time `storeSnapshot` is called
this._pendingSnapshot = new Snapshot(this.editor);
this._pendingSnapshot = new Snapshot(now, this.editor, editAction);
}
}, {
key: 'stepBackward',
Expand All @@ -122,7 +138,7 @@ var EditHistory = (function () {

var snapshot = this._undoStack.pop();
if (snapshot) {
this._redoStack.push(new Snapshot(this.editor));
this._redoStack.push(new Snapshot(Date.now(), this.editor));
this._restoreFromSnapshot(snapshot, postEditor);
}
}
Expand All @@ -131,7 +147,7 @@ var EditHistory = (function () {
value: function stepForward(postEditor) {
var snapshot = this._redoStack.pop();
if (snapshot) {
this._undoStack.push(new Snapshot(this.editor));
this._undoStack.push(new Snapshot(Date.now(), this.editor));
this._restoreFromSnapshot(snapshot, postEditor);
}
postEditor.cancelSnapshot();
Expand Down
36 changes: 31 additions & 5 deletions website/commonjs/mobiledoc-kit/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ var _utilsCursorRange = require('../utils/cursor/range');

var _utilsCursorPosition = require('../utils/cursor/position');

var _utilsEnvironment = require('../utils/environment');

var _modelsPostNodeBuilder = require('../models/post-node-builder');

var _textInputHandlers = require('./text-input-handlers');
Expand All @@ -56,7 +58,7 @@ var _editorEventManager = require('../editor/event-manager');

var _editorEditState = require('../editor/edit-state');

var _mobiledocHtmlRenderer = require('mobiledoc-html-renderer');
var _mobiledocDomRenderer = require('mobiledoc-dom-renderer');

var _mobiledocTextRenderer = require('mobiledoc-text-renderer');

Expand All @@ -82,6 +84,7 @@ var defaults = {
spellcheck: true,
autofocus: true,
undoDepth: 5,
undoBlockTimeout: 5000, // ms for an undo event
cards: [],
atoms: [],
cardOptions: {},
Expand Down Expand Up @@ -192,7 +195,7 @@ var Editor = (function () {
this.post = this.loadPost();
this._renderTree = new _modelsRenderTree['default'](this.post);

this._editHistory = new _editorEditHistory['default'](this, this.undoDepth);
this._editHistory = new _editorEditHistory['default'](this, this.undoDepth, this.undoBlockTimeout);
this._eventManager = new _editorEventManager['default'](this);
this._mutationHandler = new _editorMutationHandler['default'](this);
this._editState = new _editorEditState['default'](this);
Expand Down Expand Up @@ -350,6 +353,22 @@ var Editor = (function () {
this.keyCommands.unshift(keyCommand);
}

/**
* @param {String} name If the keyCommand event has a name attribute it can be removed.
* @public
*/
}, {
key: 'unregisterKeyCommands',
value: function unregisterKeyCommands(name) {
for (var i = this.keyCommands.length - 1; i > -1; i--) {
var keyCommand = this.keyCommands[i];

if (keyCommand.name === name) {
this.keyCommands.splice(i, 1);
}
}
}

/**
* Convenience for {@link PostEditor#deleteAtPosition}. Deletes and puts the
* cursor in the new position.
Expand Down Expand Up @@ -633,8 +652,15 @@ var Editor = (function () {

switch (format) {
case 'html':
rendered = new _mobiledocHtmlRenderer['default'](rendererOptions).render(mobiledoc);
return rendered.result;
var result = undefined;
if (_utilsEnvironment['default'].hasDOM()) {
rendered = new _mobiledocDomRenderer['default'](rendererOptions).render(mobiledoc);
result = '<div>' + (0, _utilsDomUtils.serializeHTML)(rendered.result) + '</div>';
} else {
// Fallback to text serialization
result = this.serializePost(post, 'text', options);
}
return result;
case 'text':
rendered = new _mobiledocTextRenderer['default'](rendererOptions).render(mobiledoc);
return rendered.result;
Expand Down Expand Up @@ -794,7 +820,7 @@ var Editor = (function () {
if (postEditor._shouldCancelSnapshot) {
this._editHistory._pendingSnapshot = null;
}
this._editHistory.storeSnapshot();
this._editHistory.storeSnapshot(postEditor.editActionTaken);

return result;
}
Expand Down
10 changes: 10 additions & 0 deletions website/commonjs/mobiledoc-kit/editor/key-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ var DEFAULT_KEY_COMMANDS = [{
run: function run(editor) {
editor.toggleMarkup('em');
}
}, {
str: 'META+U',
run: function run(editor) {
editor.toggleMarkup('u');
}
}, {
str: 'CTRL+U',
run: function run(editor) {
editor.toggleMarkup('u');
}
}, {
str: 'CTRL+K',
run: function run(editor) {
Expand Down
13 changes: 13 additions & 0 deletions website/commonjs/mobiledoc-kit/editor/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ var CALLBACK_QUEUES = {
AFTER_COMPLETE: 'afterComplete'
};

// There are only two events that we're concerned about for Undo, that is inserting text and deleting content.
// These are the only two states that go on a "run" and create a combined undo, everything else has it's own
// deadicated undo.
var EDIT_ACTIONS = {
INSERT_TEXT: 1,
DELETE: 2
};

/**
* The PostEditor is used to modify a post. It should not be instantiated directly.
* Instead, a new instance of a PostEditor is created by the editor and passed
Expand Down Expand Up @@ -68,6 +76,7 @@ var PostEditor = (function () {
this._callbacks = new _modelsLifecycleCallbacks['default']((0, _utilsArrayUtils.values)(CALLBACK_QUEUES));

this._didComplete = false;
this.editActionTaken = null;

this._renderRange = function () {
return _this.editor.selectRange(_this._range);
Expand Down Expand Up @@ -157,6 +166,8 @@ var PostEditor = (function () {
value: function deleteRange(range) {
(0, _utilsAssert['default'])("Must pass MobiledocKit Range to `deleteRange`", range instanceof _utilsCursorRange['default']);

this.editActionTaken = EDIT_ACTIONS.DELETE;

var head = range.head;
var headSection = range.head.section;
var tail = range.tail;
Expand Down Expand Up @@ -688,6 +699,8 @@ var PostEditor = (function () {

(0, _utilsAssert['default'])('Cannot insert markers at non-markerable position', section.isMarkerable);

this.editActionTaken = EDIT_ACTIONS.INSERT_TEXT;

var edit = section.splitMarkerAtOffset(offset);
edit.removed.forEach(function (marker) {
return _this9._scheduleForRemoval(marker);
Expand Down
13 changes: 10 additions & 3 deletions website/commonjs/mobiledoc-kit/editor/text-input-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function replaceWithListSection(editor, listTagName) {
* Does nothing if the cursor position is not at the start of the section.
*
* @param {Editor} editor
* @param {String} headingTagName ("h1","h2","h3")
* @param {String} headingTagName ('h1', 'h2', 'h3', 'h4', 'h5', 'h6')
* @public
*/

Expand Down Expand Up @@ -81,8 +81,15 @@ var DEFAULT_TEXT_INPUT_HANDLERS = [{
}
}, {
name: 'heading',
// "# " -> h1, "## " -> h2, "### " -> h3
match: /^(#{1,3}) $/,
/*
* "# " -> h1
* "## " -> h2
* "### " -> h3
* "#### " -> h4
* "##### " -> h5
* "###### " -> h6
*/
match: /^(#{1,6}) $/,
run: function run(editor, matches) {
var capture = matches[1];
var headingTag = 'h' + capture.length;
Expand Down
6 changes: 3 additions & 3 deletions website/commonjs/mobiledoc-kit/models/markup-section.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ var _utilsArrayUtils = require('../utils/array-utils');
var _types = require('./types');

// valid values of `tagName` for a MarkupSection
var VALID_MARKUP_SECTION_TAGNAMES = ['p', 'h3', 'h2', 'h1', 'blockquote', 'pull-quote'].map(_utilsDomUtils.normalizeTagName);
var VALID_MARKUP_SECTION_TAGNAMES = ['aside', 'blockquote', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p'].map(_utilsDomUtils.normalizeTagName);

exports.VALID_MARKUP_SECTION_TAGNAMES = VALID_MARKUP_SECTION_TAGNAMES;
// valid element names for a MarkupSection. A MarkupSection with a tagName
// not in this will be rendered as a div with a className matching the
// tagName
var MARKUP_SECTION_ELEMENT_NAMES = ['p', 'h3', 'h2', 'h1', 'blockquote'].map(_utilsDomUtils.normalizeTagName);
var MARKUP_SECTION_ELEMENT_NAMES = ['aside', 'blockquote', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p'].map(_utilsDomUtils.normalizeTagName);
exports.MARKUP_SECTION_ELEMENT_NAMES = MARKUP_SECTION_ELEMENT_NAMES;
var DEFAULT_TAG_NAME = VALID_MARKUP_SECTION_TAGNAMES[0];
var DEFAULT_TAG_NAME = VALID_MARKUP_SECTION_TAGNAMES[8];

exports.DEFAULT_TAG_NAME = DEFAULT_TAG_NAME;
var MarkupSection = (function (_Markerable) {
Expand Down
8 changes: 4 additions & 4 deletions website/commonjs/mobiledoc-kit/models/markup.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ var _types = require('./types');

var _utilsAssert = require('../utils/assert');

var VALID_MARKUP_TAGNAMES = ['b', 'i', 'strong', 'em', 'a', 'u', 'sub', // subscript
var VALID_MARKUP_TAGNAMES = ['a', 'b', 'code', 'em', 'i', 's', // strikethrough
'strong', 'sub', // subscript
'sup', // superscript
's' // strikethrough
].map(_utilsDomUtils.normalizeTagName);
'u'].map(_utilsDomUtils.normalizeTagName);

exports.VALID_MARKUP_TAGNAMES = VALID_MARKUP_TAGNAMES;
var VALID_ATTRIBUTES = ['href', 'ref'];
var VALID_ATTRIBUTES = ['href', 'rel'];

exports.VALID_ATTRIBUTES = VALID_ATTRIBUTES;

Expand Down
2 changes: 1 addition & 1 deletion website/commonjs/mobiledoc-kit/parsers/mobiledoc/0-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ var MobiledocParser = (function () {
var tagName = _ref52[1];
var markers = _ref52[2];

var section = this.builder.createMarkupSection(tagName);
var section = this.builder.createMarkupSection(tagName.toLowerCase() === 'pull-quote' ? 'aside' : tagName);
post.sections.append(section);
this.parseMarkers(markers, section);
// Strip blank markers after they have been created. This ensures any
Expand Down

0 comments on commit e75e339

Please sign in to comment.