diff --git a/website/demo/demo.css b/website/demo/demo.css index 341e0a067..f29d99e74 100644 --- a/website/demo/demo.css +++ b/website/demo/demo.css @@ -24,6 +24,12 @@ body { .pane { max-width: 25%; + padding: 0 1em; +} + +.pane p.desc { + height: 150px; + overflow: scroll; } .editor-pane { @@ -76,7 +82,8 @@ body { #mobiledoc-to-load { } #mobiledoc-to-load textarea { - height: 300px; + height: 500px; + width: 100%; } .code-pane:first-child { diff --git a/website/demo/demo.js b/website/demo/demo.js index 02f5c3cb0..0571d2408 100644 --- a/website/demo/demo.js +++ b/website/demo/demo.js @@ -2,6 +2,9 @@ 'use strict'; +var ContentKit = exports.ContentKit, + $ = exports.$; + var ContentKitDemo = exports.ContentKitDemo = { syncCodePane: function(editor) { var codePaneJSON = document.getElementById('serialized-mobiledoc'); @@ -40,9 +43,10 @@ var ContentKitDemo = exports.ContentKitDemo = { }; -function bootEditor(element, payload) { +function bootEditor(element, mobiledoc) { var editor = new ContentKit.Editor(element, { - mobiledoc: payload, + autofocus: false, + mobiledoc: mobiledoc, cards: { 'pick-color': function renderPickColor(payload) { return 'PICK A COLOR: '+payload.options.join(', '); @@ -55,22 +59,106 @@ function bootEditor(element, payload) { }); } -function readPayload(textarea) { - var jqueryTextarea = $(textarea); - var textPayload = jqueryTextarea.val(); - return JSON.parse(textPayload); +function readMobiledoc(string) { + return JSON.parse(string); } -$(function() { - var textarea = $('#mobiledoc-to-load textarea'); - var editor; - textarea.on('input', function() { +function isValidJSON(string) { + try { + JSON.parse(string); + return true; + } catch(e) { + return false; + } +} + +function attemptEditorReboot(editor, textarea) { + var textPayload = $(textarea).val(); + if (isValidJSON(textPayload)) { + var mobiledoc = readMobiledoc(textPayload); if (editor) { editor.destroy(); } - editor = bootEditor($('#editor')[0], readPayload(textarea)); + bootEditor($('#editor')[0], mobiledoc); + } +} + +var sampleMobiledocs = { + simpleMobiledoc: [ + [], + [ + [1, "H2", [ + [[], 0, "headline h2"] + ]], + [1, "P", [ + [[], 0, "hello world"] + ]] + ] + ], + + mobileDocWithMarker: [ + [['B']], + [ + [1, "H2", [ + [[], 0, "headline h2"] + ]], + [1, "P", [ + [[0], 1, "bold world"] + ]] + ] + ], + + mobileDocWithMultipleMarkers: [ + [['B'], ['I']], + [ + [1, "H2", [ + [[], 0, "headline h2"] + ]], + [1, "P", [ + [[], 0, "hello "], + [[0], 1, "bold, "], + [[1], 1, "italic "], + [[], 0, "world."] + ]] + ] + ], + + mobileDocWithAttributeMarker: [ + [['A', ['href', 'http://github.com/bustlelabs/content-kit-editor']]], + [ + [1, "H2", [ + [[], 0, "headline h2"] + ]], + [1, "P", [ + [[], 0, "see it "], + [[0], 1, "on github."] + ]] + ] + ] +}; + + +$(function() { + var editor; + var editorEl = $('#editor')[0]; + var mobiledoc = sampleMobiledocs.simpleMobiledoc; + + var textarea = $('#mobiledoc-to-load textarea'); + textarea.val(JSON.stringify(mobiledoc, false, 2)); + + textarea.on('input', function() { + attemptEditorReboot(editor, textarea); }); - editor = bootEditor($('#editor')[0], readPayload(textarea)); + + $('#select-mobiledoc').on('change', function() { + var mobiledocName = $(this).val(); + var mobiledoc = sampleMobiledocs[mobiledocName]; + textarea.val(JSON.stringify(mobiledoc, false, 2)); + textarea.trigger('input'); + }); + + bootEditor(editorEl, mobiledoc); + $(editorEl).focus(); }); }(this, document)); diff --git a/website/demo/index.html b/website/demo/index.html index 1992c4058..a895c7415 100644 --- a/website/demo/index.html +++ b/website/demo/index.html @@ -1,5 +1,6 @@ +
+ This mobiledoc will be loaded into the editor.
+ You can change it and see the editor reload with the new contents.
+ (If there is a JSON syntax error it will be ignored; if there is a parser
+ error the editor may stop responding.)
+
+ Select a preloaded mobiledoc here:
+
+
+ The live-editing surface. Changes here are serialized to mobiledoc + format and displayed to the right. +
+ When the editor updates, it prints its serialized mobiledoc here. +
+ This is the output of using the runtime (client-side) + mobiledoc-dom-renderer + on the serialized mobiledoc. +
'; - }; - - exports['default'] = TwitterRenderer; -}); -define('content-kit-editor/renderers/youtube', ['exports'], function (exports) { +define('content-kit-editor/runtime/renderers/mobiledoc-dom', ['exports', 'mobiledoc-dom-renderer'], function (exports, _mobiledocDomRenderer) { 'use strict'; - var RegExVideoId = /.*(?:youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&\?]*).*/; - - function getVideoIdFromUrl(url) { - var match = url && url.match(RegExVideoId); - if (match && match[1].length === 11) { - return match[1]; - } - return null; - } - - function YouTubeRenderer() {} - YouTubeRenderer.prototype.render = function (model) { - var videoId = getVideoIdFromUrl(model.attributes.url); - var embedUrl = 'http://www.youtube.com/embed/' + videoId + '?controls=2&showinfo=0&color=white&theme=light'; - return ''; - }; - - exports['default'] = YouTubeRenderer; + exports['default'] = _mobiledocDomRenderer['default']; }); define('content-kit-editor/utils/compat', ['exports', 'content-kit-editor/utils/doc', 'content-kit-editor/utils/win'], function (exports, _contentKitEditorUtilsDoc, _contentKitEditorUtilsWin) { 'use strict'; @@ -2866,15 +1660,6 @@ define("content-kit-editor/utils/compiler", ["exports"], function (exports) { } } }); -define("content-kit-editor/utils/doc", ["exports"], function (exports) { - // FIXME in theory, we might want to make this safe for node usage and - // return a jsdom? - // In practice we probably don't need this for the editor since it won't ever - // execute in a solely server-side environment - "use strict"; - - exports["default"] = document; -}); define("content-kit-editor/utils/dom-utils", ["exports"], function (exports) { "use strict"; @@ -2918,27 +1703,27 @@ define('content-kit-editor/utils/element-map', ['exports'], function (exports) { _createClass(ElementMap, [{ key: 'set', value: function set(key, value) { - var uuid = key.dataset.uuid; + var uuid = key._uuid; if (!uuid) { - key.dataset.uuid = uuid = uuidGenerator++; + key._uuid = uuid = '' + uuidGenerator++; } this._map[uuid] = value; } }, { key: 'get', value: function get(key) { - if (key.dataset && key.dataset.uuid) { - return this._map[key.dataset.uuid]; + if (key._uuid) { + return this._map[key._uuid]; } return null; } }, { key: 'remove', value: function remove(key) { - if (!key.dataset.uuid) { + if (!key._uuid) { throw new Error('tried to fetch a value for an element not seen before'); } - delete this._map[key.dataset.uuid]; + delete this._map[key._uuid]; } }]); @@ -2947,11 +1732,11 @@ define('content-kit-editor/utils/element-map', ['exports'], function (exports) { exports['default'] = ElementMap; }); -define('content-kit-editor/utils/element-utils', ['exports', 'content-kit-editor/utils/compat'], function (exports, _contentKitEditorUtilsCompat) { +define('content-kit-editor/utils/element-utils', ['exports'], function (exports) { 'use strict'; function createDiv(className) { - var div = _contentKitEditorUtilsCompat.doc.createElement('div'); + var div = document.createElement('div'); if (className) { div.className = className; } @@ -3001,9 +1786,9 @@ define('content-kit-editor/utils/element-utils', ['exports', 'content-kit-editor } function getElementRelativeOffset(element) { - var offset = { left: 0, top: -_contentKitEditorUtilsCompat.win.pageYOffset }; + var offset = { left: 0, top: -window.pageYOffset }; var offsetParent = element.offsetParent; - var offsetParentPosition = _contentKitEditorUtilsCompat.win.getComputedStyle(offsetParent).position; + var offsetParentPosition = window.getComputedStyle(offsetParent).position; var offsetParentRect; if (offsetParentPosition === 'relative') { @@ -3015,7 +1800,7 @@ define('content-kit-editor/utils/element-utils', ['exports', 'content-kit-editor } function getElementComputedStyleNumericProp(element, prop) { - return parseFloat(_contentKitEditorUtilsCompat.win.getComputedStyle(element)[prop]); + return parseFloat(window.getComputedStyle(element)[prop]); } function positionElementToRect(element, rect, topOffset, leftOffset) { @@ -3115,8 +1900,7 @@ define("content-kit-editor/utils/event-emitter", ["exports"], function (exports) exports["default"] = EventEmitter; }); -define('content-kit-editor/utils/http-utils', ['exports', 'content-kit-editor/utils/compat'], function (exports, _contentKitEditorUtilsCompat) { - /* global JSON */ +define('content-kit-editor/utils/http-utils', ['exports'], function (exports) { 'use strict'; function createXHR(options) { @@ -3189,7 +1973,7 @@ define('content-kit-editor/utils/http-utils', ['exports', 'content-kit-editor/ut var file = options.file || fileInput && fileInput.files && fileInput.files[0]; var callback = options.complete; var maxFileSize = this.maxFileSize; - if (!file || !(file instanceof _contentKitEditorUtilsCompat.win.File)) { + if (!file || !(file instanceof window.File)) { return; } @@ -3257,11 +2041,74 @@ define("content-kit-editor/utils/keycodes", ["exports"], function (exports) { M: 77 }; }); -define('content-kit-editor/utils/selection-utils', ['exports', 'content-kit-editor/utils/element-utils', 'content-kit-compiler', 'content-kit-editor/utils/compat'], function (exports, _contentKitEditorUtilsElementUtils, _contentKitCompiler, _contentKitEditorUtilsCompat) { +define('content-kit-editor/utils/post-builder', ['exports', 'content-kit-editor/models/post'], function (exports, _contentKitEditorModelsPost) { + 'use strict'; + + exports.generateBuilder = generateBuilder; + + var builder = { + generatePost: function generatePost() { + return new _contentKitEditorModelsPost['default'](); + }, + generateSection: function generateSection(tagName, attributes, isGenerated) { + var section = { + type: 'markupSection', + tagName: tagName, + markers: [] + }; + if (attributes && attributes.length) { + section.attributes = attributes; + } + if (isGenerated) { + section.isGenerated = !!isGenerated; + } + return section; + }, + // open: Array + // close: Integer + // value: String + generateMarker: function generateMarker(open, close, value) { + return { + type: 'marker', + open: open, + close: close, + value: value + }; + }, + generateMarkerType: function generateMarkerType(tagName, attributes) { + if (attributes) { + // FIXME: This could also be cached + return { + type: 'markerType', + tagName: tagName, + attributes: attributes + }; + } + var markerType = this._markerTypeCache[tagName]; + if (!markerType) { + this._markerTypeCache[tagName] = markerType = { + type: 'markerType', + tagName: tagName + }; + } + return markerType; + } + }; + + function reset(builder) { + builder._markerTypeCache = {}; + } + + function generateBuilder() { + reset(builder); + return builder; + } +}); +define('content-kit-editor/utils/selection-utils', ['exports', 'content-kit-editor/utils/element-utils'], function (exports, _contentKitEditorUtilsElementUtils) { 'use strict'; // TODO: remove, pass in Editor's current block set - var RootTags = [_contentKitCompiler.Type.PARAGRAPH.tag, _contentKitCompiler.Type.HEADING.tag, _contentKitCompiler.Type.SUBHEADING.tag, _contentKitCompiler.Type.QUOTE.tag, _contentKitCompiler.Type.LIST.tag, _contentKitCompiler.Type.ORDERED_LIST.tag]; + var RootTags = ['p', 'h2', 'h3', 'blockquote', 'ul', 'ol']; var SelectionDirection = { LEFT_TO_RIGHT: 1, @@ -3281,13 +2128,13 @@ define('content-kit-editor/utils/selection-utils', ['exports', 'content-kit-edit } function getSelectionElement(selection) { - selection = selection || _contentKitEditorUtilsCompat.win.getSelection(); + selection = selection || window.getSelection(); var node = getDirectionOfSelection(selection) === SelectionDirection.LEFT_TO_RIGHT ? selection.anchorNode : selection.focusNode; return node && (node.nodeType === 3 ? node.parentNode : node); } function getSelectionBlockElement(selection) { - selection = selection || _contentKitEditorUtilsCompat.win.getSelection(); + selection = selection || window.getSelection(); var element = getSelectionElement(); var tag = element && element.tagName.toLowerCase(); while (tag && RootTags.indexOf(tag) === -1) { @@ -3336,14 +2183,14 @@ define('content-kit-editor/utils/selection-utils', ['exports', 'content-kit-edit } function restoreRange(range) { - var selection = _contentKitEditorUtilsCompat.win.getSelection(); + var selection = window.getSelection(); selection.removeAllRanges(); selection.addRange(range); } function selectNode(node) { - var range = _contentKitEditorUtilsCompat.doc.createRange(); - var selection = _contentKitEditorUtilsCompat.win.getSelection(); + var range = document.createRange(); + var selection = window.getSelection(); range.setStart(node, 0); range.setEnd(node, node.length); selection.removeAllRanges(); @@ -3351,8 +2198,8 @@ define('content-kit-editor/utils/selection-utils', ['exports', 'content-kit-edit } function setCursorIndexInElement(element, index) { - var range = _contentKitEditorUtilsCompat.doc.createRange(); - var selection = _contentKitEditorUtilsCompat.win.getSelection(); + var range = document.createRange(); + var selection = window.getSelection(); range.setStart(element, index); range.collapse(true); selection.removeAllRanges(); @@ -3366,7 +2213,7 @@ define('content-kit-editor/utils/selection-utils', ['exports', 'content-kit-edit function getCursorOffsetInElement(element) { // http://stackoverflow.com/questions/4811822/get-a-ranges-start-and-end-offsets-relative-to-its-parent-container/4812022#4812022 var caretOffset = 0; - var selection = _contentKitEditorUtilsCompat.win.getSelection(); + var selection = window.getSelection(); if (selection.rangeCount > 0) { var range = selection.getRangeAt(0); var preCaretRange = range.cloneRange(); @@ -3391,20 +2238,7 @@ define('content-kit-editor/utils/selection-utils', ['exports', 'content-kit-edit exports.setCursorIndexInElement = setCursorIndexInElement; exports.getCursorOffsetInElement = getCursorOffsetInElement; }); -define('content-kit-editor/utils/win', ['exports', 'content-kit-compiler'], function (exports, _contentKitCompiler) { - 'use strict'; - - var win; - if (typeof window !== 'undefined') { - win = window; - } else { - // jsdom provides a defaultView - win = _contentKitCompiler.doc.defaultView; - } - - exports['default'] = win; -}); -define('content-kit-editor/views/embed-intent', ['exports', 'content-kit-editor/views/view', 'content-kit-editor/views/toolbar', 'content-kit-utils', 'content-kit-editor/utils/selection-utils', 'content-kit-editor/utils/element-utils', 'content-kit-editor/utils/keycodes', 'content-kit-editor/utils/compat'], function (exports, _contentKitEditorViewsView, _contentKitEditorViewsToolbar, _contentKitUtils, _contentKitEditorUtilsSelectionUtils, _contentKitEditorUtilsElementUtils, _contentKitEditorUtilsKeycodes, _contentKitEditorUtilsCompat) { +define('content-kit-editor/views/embed-intent', ['exports', 'content-kit-editor/views/view', 'content-kit-editor/views/toolbar', 'content-kit-utils', 'content-kit-editor/utils/selection-utils', 'content-kit-editor/utils/element-utils', 'content-kit-editor/utils/keycodes'], function (exports, _contentKitEditorViewsView, _contentKitEditorViewsToolbar, _contentKitUtils, _contentKitEditorUtilsSelectionUtils, _contentKitEditorUtilsElementUtils, _contentKitEditorUtilsKeycodes) { 'use strict'; var LayoutStyle = { @@ -3428,7 +2262,7 @@ define('content-kit-editor/views/embed-intent', ['exports', 'content-kit-editor/ embedIntent.isActive = false; embedIntent.editorContext = options.editorContext; embedIntent.loadingIndicator = (0, _contentKitEditorUtilsElementUtils.createDiv)('ck-embed-loading'); - embedIntent.button = _contentKitEditorUtilsCompat.doc.createElement('button'); + embedIntent.button = document.createElement('button'); embedIntent.button.className = 'ck-embed-intent-btn'; embedIntent.button.title = 'Insert image or embed...'; embedIntent.element.appendChild(embedIntent.button); @@ -3459,19 +2293,19 @@ define('content-kit-editor/views/embed-intent', ['exports', 'content-kit-editor/ } rootElement.addEventListener('keyup', embedIntentHandler); - _contentKitEditorUtilsCompat.doc.addEventListener('mouseup', function () { + document.addEventListener('mouseup', function () { setTimeout(function () { embedIntentHandler(); }); }); - _contentKitEditorUtilsCompat.doc.addEventListener('keyup', function (e) { + document.addEventListener('keyup', function (e) { if (e.keyCode === _contentKitEditorUtilsKeycodes['default'].ESC) { embedIntent.hide(); } }); - _contentKitEditorUtilsCompat.win.addEventListener('resize', function () { + window.addEventListener('resize', function () { if (embedIntent.isShowing) { embedIntent.reposition(); } @@ -3561,10 +2395,10 @@ define('content-kit-editor/views/message', ['exports', 'content-kit-editor/views exports['default'] = Message; }); -define('content-kit-editor/views/prompt', ['exports', 'content-kit-editor/views/view', 'content-kit-utils', 'content-kit-editor/utils/selection-utils', 'content-kit-editor/utils/element-utils', 'content-kit-editor/utils/keycodes', 'content-kit-editor/utils/compat'], function (exports, _contentKitEditorViewsView, _contentKitUtils, _contentKitEditorUtilsSelectionUtils, _contentKitEditorUtilsElementUtils, _contentKitEditorUtilsKeycodes, _contentKitEditorUtilsCompat) { +define('content-kit-editor/views/prompt', ['exports', 'content-kit-editor/views/view', 'content-kit-utils', 'content-kit-editor/utils/selection-utils', 'content-kit-editor/utils/element-utils', 'content-kit-editor/utils/keycodes'], function (exports, _contentKitEditorViewsView, _contentKitUtils, _contentKitEditorUtilsSelectionUtils, _contentKitEditorUtilsElementUtils, _contentKitEditorUtilsKeycodes) { 'use strict'; - var container = _contentKitEditorUtilsCompat.doc.body; + var container = document.body; var hiliter = (0, _contentKitEditorUtilsElementUtils.createDiv)('ck-editor-hilite'); function positionHiliteRange(range) { @@ -3596,7 +2430,7 @@ define('content-kit-editor/views/prompt', ['exports', 'content-kit-editor/views/ } }); - _contentKitEditorUtilsCompat.win.addEventListener('resize', function () { + window.addEventListener('resize', function () { var activeHilite = hiliter.parentNode; var range = prompt.range; if (activeHilite && range) { @@ -3609,7 +2443,7 @@ define('content-kit-editor/views/prompt', ['exports', 'content-kit-editor/views/ Prompt.prototype.show = function (callback) { var prompt = this; var element = prompt.element; - var selection = _contentKitEditorUtilsCompat.win.getSelection(); + var selection = window.getSelection(); var range = selection && selection.rangeCount && selection.getRangeAt(0); element.value = null; prompt.range = range || null; @@ -3633,7 +2467,7 @@ define('content-kit-editor/views/prompt', ['exports', 'content-kit-editor/views/ exports['default'] = Prompt; }); -define('content-kit-editor/views/text-format-toolbar', ['exports', 'content-kit-editor/views/toolbar', 'content-kit-utils', 'content-kit-editor/utils/selection-utils', 'content-kit-editor/utils/keycodes', 'content-kit-editor/utils/compat'], function (exports, _contentKitEditorViewsToolbar, _contentKitUtils, _contentKitEditorUtilsSelectionUtils, _contentKitEditorUtilsKeycodes, _contentKitEditorUtilsCompat) { +define('content-kit-editor/views/text-format-toolbar', ['exports', 'content-kit-editor/views/toolbar', 'content-kit-utils', 'content-kit-editor/utils/selection-utils', 'content-kit-editor/utils/keycodes'], function (exports, _contentKitEditorViewsToolbar, _contentKitUtils, _contentKitEditorUtilsSelectionUtils, _contentKitEditorUtilsKeycodes) { 'use strict'; function selectionIsEditableByToolbar(selection, toolbar) { @@ -3641,7 +2475,7 @@ define('content-kit-editor/views/text-format-toolbar', ['exports', 'content-kit- } function handleTextSelection(toolbar) { - var selection = _contentKitEditorUtilsCompat.win.getSelection(); + var selection = window.getSelection(); if (toolbar.sticky) { toolbar.updateForSelection(selectionIsEditableByToolbar(selection, toolbar) ? selection : null); } else { @@ -3662,13 +2496,13 @@ define('content-kit-editor/views/text-format-toolbar', ['exports', 'content-kit- handleTextSelection(toolbar); }); - _contentKitEditorUtilsCompat.doc.addEventListener('mouseup', function () { + document.addEventListener('mouseup', function () { setTimeout(function () { handleTextSelection(toolbar); }); }); - _contentKitEditorUtilsCompat.doc.addEventListener('keyup', function (e) { + document.addEventListener('keyup', function (e) { var key = e.keyCode; if (key === 116) { //F5 @@ -3679,10 +2513,10 @@ define('content-kit-editor/views/text-format-toolbar', ['exports', 'content-kit- } }); - _contentKitEditorUtilsCompat.win.addEventListener('resize', function () { + window.addEventListener('resize', function () { if (!toolbar.sticky && toolbar.isShowing) { var activePromptRange = toolbar.activePrompt && toolbar.activePrompt.range; - toolbar.positionToContent(activePromptRange ? activePromptRange : _contentKitEditorUtilsCompat.win.getSelection().getRangeAt(0)); + toolbar.positionToContent(activePromptRange ? activePromptRange : window.getSelection().getRangeAt(0)); } }); } @@ -3690,7 +2524,7 @@ define('content-kit-editor/views/text-format-toolbar', ['exports', 'content-kit- exports['default'] = TextFormatToolbar; }); -define('content-kit-editor/views/toolbar-button', ['exports', 'content-kit-compiler'], function (exports, _contentKitCompiler) { +define('content-kit-editor/views/toolbar-button', ['exports'], function (exports) { 'use strict'; var buttonClassName = 'ck-toolbar-btn'; @@ -3700,7 +2534,7 @@ define('content-kit-editor/views/toolbar-button', ['exports', 'content-kit-compi var toolbar = options.toolbar; var command = options.command; var prompt = command.prompt; - var element = _contentKitCompiler.doc.createElement('button'); + var element = document.createElement('button'); button.element = element; button.command = command; @@ -3739,7 +2573,7 @@ define('content-kit-editor/views/toolbar-button', ['exports', 'content-kit-compi exports['default'] = ToolbarButton; }); -define('content-kit-editor/views/toolbar', ['exports', 'content-kit-editor/views/view', 'content-kit-editor/views/toolbar-button', 'content-kit-utils', 'content-kit-editor/utils/selection-utils', 'content-kit-editor/utils/element-utils', 'content-kit-editor/utils/compat'], function (exports, _contentKitEditorViewsView, _contentKitEditorViewsToolbarButton, _contentKitUtils, _contentKitEditorUtilsSelectionUtils, _contentKitEditorUtilsElementUtils, _contentKitEditorUtilsCompat) { +define('content-kit-editor/views/toolbar', ['exports', 'content-kit-editor/views/view', 'content-kit-editor/views/toolbar-button', 'content-kit-utils', 'content-kit-editor/utils/selection-utils', 'content-kit-editor/utils/element-utils'], function (exports, _contentKitEditorViewsView, _contentKitEditorViewsToolbarButton, _contentKitUtils, _contentKitEditorUtilsSelectionUtils, _contentKitEditorUtilsElementUtils) { 'use strict'; var ToolbarDirection = { @@ -3796,7 +2630,7 @@ define('content-kit-editor/views/toolbar', ['exports', 'content-kit-editor/views } // Closes prompt if displayed when changing selection - _contentKitEditorUtilsCompat.doc.addEventListener('mouseup', function () { + document.addEventListener('mouseup', function () { toolbar.dismissPrompt(); }); } @@ -3842,7 +2676,7 @@ define('content-kit-editor/views/toolbar', ['exports', 'content-kit-editor/views Toolbar.prototype.updateForSelection = function (selection) { var toolbar = this; - selection = selection || _contentKitEditorUtilsCompat.win.getSelection(); + selection = selection || window.getSelection(); if (toolbar.sticky) { updateButtonsForSelection(toolbar.buttons, selection); } else if (!selection.isCollapsed) { @@ -3862,7 +2696,7 @@ define('content-kit-editor/views/toolbar', ['exports', 'content-kit-editor/views positioningMethod = _contentKitEditorUtilsElementUtils.positionElementCenteredAbove; } position = positioningMethod(this.element, content); - sideEdgeOffset = Math.min(Math.max(10, position.left), _contentKitEditorUtilsCompat.doc.body.clientWidth - this.element.offsetWidth - 10); + sideEdgeOffset = Math.min(Math.max(10, position.left), document.body.clientWidth - this.element.offsetWidth - 10); this.contentElement.style.transform = 'translateX(' + (sideEdgeOffset - position.left) + 'px)'; }; @@ -3940,7 +2774,7 @@ define('content-kit-editor/views/tooltip', ['exports', 'content-kit-editor/views exports['default'] = Tooltip; }); -define('content-kit-editor/views/view', ['exports', 'content-kit-editor/utils/compat'], function (exports, _contentKitEditorUtilsCompat) { +define('content-kit-editor/views/view', ['exports'], function (exports) { 'use strict'; function renderClasses(view) { @@ -3956,8 +2790,8 @@ define('content-kit-editor/views/view', ['exports', 'content-kit-editor/utils/co options = options || {}; this.tagName = options.tagName || 'div'; this.classNames = options.classNames || []; - this.element = _contentKitEditorUtilsCompat.doc.createElement(this.tagName); - this.container = options.container || _contentKitEditorUtilsCompat.doc.body; + this.element = document.createElement(this.tagName); + this.container = options.container || document.body; this.isShowing = false; renderClasses(this); } @@ -4204,5 +3038,159 @@ define('content-kit-utils/string-utils', ['exports'], function (exports) { exports.sanitizeWhitespace = sanitizeWhitespace; exports.injectIntoString = injectIntoString; }); +define('mobiledoc-dom-renderer/dom-renderer', ['exports'], function (exports) { + /** + * runtime DOM renderer + * renders a mobiledoc to DOM + * + * input: mobiledoc + * output: DOM + */ + + 'use strict'; + + var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } }; })(); + + var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + + var utils = { + createElement: function createElement(tagName) { + return document.createElement(tagName); + }, + appendChild: function appendChild(target, child) { + target.appendChild(child); + }, + createTextNode: function createTextNode(text) { + return document.createTextNode(text); + } + }; + + function createElementFromMarkerType() { + var _ref = arguments[0] === undefined ? ['', []] : arguments[0]; + + var _ref2 = _slicedToArray(_ref, 2); + + var tagName = _ref2[0]; + var attributes = _ref2[1]; + + var element = utils.createElement(tagName); + attributes = attributes || []; + + for (var i = 0, l = attributes.length; i < l; i = i + 2) { + var propName = attributes[i], + propValue = attributes[i + 1]; + element.setAttribute(propName, propValue); + } + return element; + } + + var DOMRenderer = (function () { + function DOMRenderer() { + _classCallCheck(this, DOMRenderer); + } + + _createClass(DOMRenderer, [{ + key: 'render', + + /** + * @param mobiledoc + * @param rootElement optional, defaults to an empty div + * @return DOMNode + */ + value: function render(mobiledoc) { + var _this = this; + + var rootElement = arguments[1] === undefined ? utils.createElement('div') : arguments[1]; + + var _mobiledoc = _slicedToArray(mobiledoc, 2); + + var markerTypes = _mobiledoc[0]; + var sections = _mobiledoc[1]; + + this.root = rootElement; + this.markerTypes = markerTypes; + + sections.forEach(function (section) { + return _this.renderSection(section); + }); + + return this.root; + } + }, { + key: 'renderSection', + value: function renderSection(section) { + var _section = _slicedToArray(section, 1); + + var type = _section[0]; + + switch (type) { + case 1: + var rendered = this.renderParagraphSection(section); + utils.appendChild(this.root, rendered); + break; + default: + throw new Error('Unimplement renderer for type ' + type); + } + } + }, { + key: 'renderParagraphSection', + value: function renderParagraphSection(_ref3) { + var _ref32 = _slicedToArray(_ref3, 3); + + var type = _ref32[0]; + var tagName = _ref32[1]; + var markers = _ref32[2]; + + var element = utils.createElement(tagName); + var elements = [element]; + var currentElement = element; + + for (var i = 0, l = markers.length; i < l; i++) { + var marker = markers[i]; + + var _marker = _slicedToArray(marker, 3); + + var openTypes = _marker[0]; + var closeTypes = _marker[1]; + var text = _marker[2]; + + for (var j = 0, m = openTypes.length; j < m; j++) { + var markerType = this.markerTypes[openTypes[j]]; + var openedElement = createElementFromMarkerType(markerType); + utils.appendChild(currentElement, openedElement); + elements.push(openedElement); + currentElement = openedElement; + } + + utils.appendChild(currentElement, utils.createTextNode(text)); + + for (var j = 0, m = closeTypes; j < m; j++) { + elements.pop(); + currentElement = elements[elements.length - 1]; + } + } + + return element; + } + }]); + + return DOMRenderer; + })(); + + exports['default'] = DOMRenderer; +}); +define('mobiledoc-dom-renderer', ['exports', 'mobiledoc-dom-renderer/dom-renderer'], function (exports, _mobiledocDomRendererDomRenderer) { + 'use strict'; + + exports.registerGlobal = registerGlobal; + + function registerGlobal(window) { + window.MobiledocDOMRenderer = _mobiledocDomRendererDomRenderer['default']; + } + + exports['default'] = _mobiledocDomRendererDomRenderer['default']; +}); require("content-kit-editor")["registerGlobal"](window, document); })(); \ No newline at end of file