Skip to content

Commit

Permalink
built website from 5fe628e
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeeJab committed Jan 10, 2020
1 parent 5fe628e commit 7b87e74
Show file tree
Hide file tree
Showing 97 changed files with 13,484 additions and 4,774 deletions.
1,657 changes: 1,397 additions & 260 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.

2 changes: 0 additions & 2 deletions website/commonjs/mobiledoc-kit/cards/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ exports['default'] = {
type: 'dom',

render: function render(_ref) {
var env = _ref.env;
var options = _ref.options;
var payload = _ref.payload;

var img = document.createElement('img');
Expand Down
31 changes: 29 additions & 2 deletions website/commonjs/mobiledoc-kit/editor/edit-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ var EditState = (function () {
range: _utilsCursorRange['default'].blankRange(),
activeMarkups: [],
activeSections: [],
activeSectionTagNames: []
activeSectionTagNames: [],
activeSectionAttributes: {}
};

this.prevState = this.state = defaultState;
Expand Down Expand Up @@ -65,7 +66,7 @@ var EditState = (function () {
var state = this.state;
var prevState = this.prevState;

return !(0, _utilsArrayUtils.isArrayEqual)(state.activeMarkups, prevState.activeMarkups) || !(0, _utilsArrayUtils.isArrayEqual)(state.activeSectionTagNames, prevState.activeSectionTagNames);
return !(0, _utilsArrayUtils.isArrayEqual)(state.activeMarkups, prevState.activeMarkups) || !(0, _utilsArrayUtils.isArrayEqual)(state.activeSectionTagNames, prevState.activeSectionTagNames) || !(0, _utilsArrayUtils.isArrayEqual)((0, _utilsArrayUtils.objectToSortedKVArray)(state.activeSectionAttributes), (0, _utilsArrayUtils.objectToSortedKVArray)(prevState.activeSectionAttributes));
}

/**
Expand Down Expand Up @@ -102,6 +103,7 @@ var EditState = (function () {
state.activeSectionTagNames = state.activeSections.map(function (s) {
return s.isNested ? s.parent.tagName : s.tagName;
});
state.activeSectionAttributes = this._readSectionAttributes(state.activeSections);
return state;
}
}, {
Expand All @@ -124,6 +126,22 @@ var EditState = (function () {

return post.markupsInRange(range);
}
}, {
key: '_readSectionAttributes',
value: function _readSectionAttributes(sections) {
return sections.reduce(function (sectionAttributes, s) {
var attributes = s.isNested ? s.parent.attributes : s.attributes;
Object.keys(attributes || {}).forEach(function (attrName) {
var camelizedAttrName = attrName.replace(/^data-md-/, '');
var attrValue = attributes[attrName];
sectionAttributes[camelizedAttrName] = sectionAttributes[camelizedAttrName] || [];
if (!(0, _utilsArrayUtils.contains)(sectionAttributes[camelizedAttrName], attrValue)) {
sectionAttributes[camelizedAttrName].push(attrValue);
}
});
return sectionAttributes;
}, {});
}
}, {
key: '_removeActiveMarkup',
value: function _removeActiveMarkup(markup) {
Expand All @@ -150,6 +168,15 @@ var EditState = (function () {
return this.state.activeSections;
}

/**
* @return {Object}
*/
}, {
key: 'activeSectionAttributes',
get: function get() {
return this.state.activeSectionAttributes;
}

/**
* @return {Markup[]}
*/
Expand Down
148 changes: 126 additions & 22 deletions website/commonjs/mobiledoc-kit/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ var defaults = {
placeholder: 'Write here...',
spellcheck: true,
autofocus: true,
showLinkTooltips: true,
undoDepth: 5,
undoBlockTimeout: 5000, // ms for an undo event
cards: [],
Expand Down Expand Up @@ -136,6 +137,8 @@ var CALLBACK_QUEUES = {
* a custom toolbar.
* * {@link Editor#onTextInput} -- Register callbacks when the user enters text
* that matches a given string or regex.
* * {@link Editor#beforeToggleMarkup} -- Register callbacks that will be run before
* applying changes from {@link Editor#toggleMarkup}
*/

var Editor = (function () {
Expand All @@ -156,6 +159,7 @@ var Editor = (function () {
* @param {String} [options.placeholder] Default text to show before user starts typing.
* @param {Boolean} [options.spellcheck=true] Whether to enable spellcheck
* @param {Boolean} [options.autofocus=true] Whether to focus the editor when it is first rendered.
* @param {Boolean} [options.showLinkTooltips=true] Whether to show the url tooltip for links
* @param {number} [options.undoDepth=5] How many undo levels will be available.
* Set to 0 to disable undo/redo functionality.
* @return {Editor}
Expand All @@ -171,7 +175,7 @@ var Editor = (function () {

(0, _utilsAssert['default'])('editor create accepts an options object. For legacy usage passing an element for the first argument, consider the `html` option for loading DOM or HTML posts. For other cases call `editor.render(domNode)` after editor creation', options && !options.nodeType);
this._views = [];
this.isEditable = null;
this.isEditable = true;
this._parserPlugins = options.parserPlugins || [];

// FIXME: This should merge onto this.options
Expand Down Expand Up @@ -200,6 +204,7 @@ var Editor = (function () {
this._mutationHandler = new _editorMutationHandler['default'](this);
this._editState = new _editorEditState['default'](this);
this._callbacks = new _modelsLifecycleCallbacks['default']((0, _utilsArrayUtils.values)(CALLBACK_QUEUES));
this._beforeHooks = { toggleMarkup: [] };

_textInputHandlers.DEFAULT_TEXT_INPUT_HANDLERS.forEach(function (handler) {
return _this.onTextInput(handler);
Expand Down Expand Up @@ -306,12 +311,10 @@ var Editor = (function () {

this.element = element;

if (this.isEditable === null) {
this.enableEditing();
if (this.showLinkTooltips) {
this._addTooltip();
}

this._addTooltip();

// A call to `run` will trigger the didUpdatePostCallbacks hooks with a
// postEditor.
this.run(function () {});
Expand All @@ -325,6 +328,12 @@ var Editor = (function () {
this._mutationHandler.init();
this._eventManager.init();

if (this.isEditable === false) {
this.disableEditing();
} else {
this.enableEditing();
}

if (this.autofocus) {
this.selectRange(this.post.headPosition());
}
Expand Down Expand Up @@ -652,15 +661,17 @@ var Editor = (function () {

switch (format) {
case 'html':
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);
{
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;
}
return result;
case 'text':
rendered = new _mobiledocTextRenderer['default'](rendererOptions).render(mobiledoc);
return rendered.result;
Expand Down Expand Up @@ -725,12 +736,9 @@ var Editor = (function () {
}, {
key: 'disableEditing',
value: function disableEditing() {
if (this.isEditable === false) {
return;
}

this.isEditable = false;
if (this.hasRendered) {
this._eventManager.stop();
this.element.setAttribute('contentEditable', false);
this.setPlaceholder('');
this.selectRange(_utilsCursorRange['default'].blankRange());
Expand All @@ -748,7 +756,8 @@ var Editor = (function () {
key: 'enableEditing',
value: function enableEditing() {
this.isEditable = true;
if (this.element) {
if (this.hasRendered) {
this._eventManager.start();
this.element.setAttribute('contentEditable', true);
this.setPlaceholder(this.placeholder);
}
Expand Down Expand Up @@ -986,22 +995,55 @@ var Editor = (function () {
});
}

/**
* @callback editorBeforeCallback
* @param { Object } details
* @param { Markup } details.markup
* @param { Range } details.range
* @param { boolean } details.willAdd Whether the markup will be applied
*/

/**
* Register a callback that will be run before {@link Editor#toggleMarkup} is applied.
* If any callback returns literal `false`, the toggling of markup will be canceled.
* Note this only applies to calling `editor#toggleMarkup`. Using `editor.run` and
* modifying markup with the `postEditor` will skip any `beforeToggleMarkup` callbacks.
* @param {editorBeforeCallback}
*/
}, {
key: 'beforeToggleMarkup',
value: function beforeToggleMarkup(callback) {
this._beforeHooks.toggleMarkup.push(callback);
}

/**
* Toggles the given markup at the editor's current {@link Range}.
* If the range is collapsed this changes the editor's state so that the
* next characters typed will be affected. If there is text selected
* (aka a non-collapsed range), the selections' markup will be toggled.
* If the editor is not focused and has no active range, nothing happens.
* Hooks added using #beforeToggleMarkup will be run before toggling,
* and if any of them returns literal false, toggling the markup will be canceled
* and no change will be applied.
* @param {String} markup E.g. "b", "em", "a"
* @param {Object} [attributes={}] E.g. {href: "http://bustle.com"}
* @public
* @see PostEditor#toggleMarkup
*/
}, {
key: 'toggleMarkup',
value: function toggleMarkup(markup) {
markup = this.builder.createMarkup(markup);
var attributes = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];

markup = this.builder.createMarkup(markup, attributes);
var range = this.range;

var willAdd = !this.detectMarkupInRange(range, markup.tagName);
var shouldCancel = this._runBeforeHooks('toggleMarkup', { markup: markup, range: range, willAdd: willAdd });
if (shouldCancel) {
return;
}

if (range.isCollapsed) {
this._editState.toggleMarkupState(markup);
this._inputModeDidChange();
Expand Down Expand Up @@ -1074,6 +1116,41 @@ var Editor = (function () {
});
}

/**
* Sets an attribute for the current active section(s).
*
* @param {String} key The attribute. The only valid attribute is 'text-align'.
* @param {String} value The value of the attribute.
* @public
* @see PostEditor#setAttribute
*/
}, {
key: 'setAttribute',
value: function setAttribute(key, value) {
var _this7 = this;

this.run(function (postEditor) {
return postEditor.setAttribute(key, value, _this7.range);
});
}

/**
* Removes an attribute from the current active section(s).
*
* @param {String} key The attribute. The only valid attribute is 'text-align'.
* @public
* @see PostEditor#removeAttribute
*/
}, {
key: 'removeAttribute',
value: function removeAttribute(key) {
var _this8 = this;

this.run(function (postEditor) {
return postEditor.removeAttribute(key, _this8.range);
});
}

/**
* Finds and runs the first matching key command for the event
*
Expand Down Expand Up @@ -1185,7 +1262,7 @@ var Editor = (function () {
}, {
key: 'insertCard',
value: function insertCard(cardName) {
var _this7 = this;
var _this9 = this;

var cardPayload = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var inEditMode = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2];
Expand All @@ -1204,7 +1281,7 @@ var Editor = (function () {
var position = range.tail;
card = postEditor.builder.createCardSection(cardName, cardPayload);
if (inEditMode) {
_this7.editCard(card);
_this9.editCard(card);
}

if (!range.isCollapsed) {
Expand All @@ -1219,7 +1296,7 @@ var Editor = (function () {
if (section.isBlank) {
postEditor.replaceSection(section, card);
} else {
var collection = _this7.post.sections;
var collection = _this9.post.sections;
postEditor.insertSectionBefore(collection, card, section.next);
}

Expand Down Expand Up @@ -1291,6 +1368,28 @@ var Editor = (function () {
}
(_callbacks3 = this._callbacks).runCallbacks.apply(_callbacks3, arguments);
}

/**
* Runs each callback for the given hookName.
* Only the hookName 'toggleMarkup' is currently supported
* @return {Boolean} shouldCancel Whether the action in `hookName` should be canceled
* @private
*/
}, {
key: '_runBeforeHooks',
value: function _runBeforeHooks(hookName) {
var hooks = this._beforeHooks[hookName] || [];

for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}

for (var i = 0; i < hooks.length; i++) {
if (hooks[i].apply(hooks, args) === false) {
return true;
}
}
}
}, {
key: 'builder',
get: function get() {
Expand Down Expand Up @@ -1345,6 +1444,11 @@ var Editor = (function () {

return activeSections[activeSections.length - 1];
}
}, {
key: 'activeSectionAttributes',
get: function get() {
return this._editState.activeSectionAttributes;
}
}, {
key: 'activeMarkups',
get: function get() {
Expand Down
Loading

0 comments on commit 7b87e74

Please sign in to comment.