var dword =
/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId]) {
/******/ 			return installedModules[moduleId].exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			i: moduleId,
/******/ 			l: false,
/******/ 			exports: {}
/******/ 		};
/******/
/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ 		// Flag the module as loaded
/******/ 		module.l = true;
/******/
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/
/******/
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;
/******/
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;
/******/
/******/ 	// define getter function for harmony exports
/******/ 	__webpack_require__.d = function(exports, name, getter) {
/******/ 		if(!__webpack_require__.o(exports, name)) {
/******/ 			Object.defineProperty(exports, name, {
/******/ 				configurable: false,
/******/ 				enumerable: true,
/******/ 				get: getter
/******/ 			});
/******/ 		}
/******/ 	};
/******/
/******/ 	// getDefaultExport function for compatibility with non-harmony modules
/******/ 	__webpack_require__.n = function(module) {
/******/ 		var getter = module && module.__esModule ?
/******/ 			function getDefault() { return module['default']; } :
/******/ 			function getModuleExports() { return module; };
/******/ 		__webpack_require__.d(getter, 'a', getter);
/******/ 		return getter;
/******/ 	};
/******/
/******/ 	// Object.prototype.hasOwnProperty.call
/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";
/******/
/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/*!*************************!*\
  !*** ./client/dword.js ***!
  \*************************/
/*! no static exports found */
/*! all exports used */
/***/ (function(module, exports, __webpack_require__) {

"use strict";
eval("/* WEBPACK VAR INJECTION */(function(global) {/* global CodeMirror, exec, load, io, join, daffy, restafary, Emitify, loadRemote */\n/* global smalltalk */\n\n\n\nconst Story = __webpack_require__(/*! ./story */ 2);\nconst wraptile = __webpack_require__(/*! wraptile/legacy */ 3);\n\nmodule.exports = (el, options, callback) => {\n    Dword(el, options, callback);\n};\n\nfunction Dword(el, options, callback) {\n    if (!(this instanceof Dword))\n        return new Dword(el, options, callback);\n    \n    this._Ace;\n    this._Value;\n    this._Config;\n    this._Options;\n    this._FileName;\n    this._ElementMsg;\n    this._JSHintConfig;\n    this._Ext;\n    this._DIR = '/modules/';\n    this._TITLE = 'Dword';\n    this._story = Story();\n    this._Emitter;\n    this._Separator = '\\n';\n    this._isKey = true;\n    \n    if (!callback)\n        callback = options;\n    \n    if (typeof el === 'string')\n        el = document.querySelector(el);\n    \n    this._MAX_FILE_SIZE   = options.maxSize || 512000;\n    this._PREFIX          = options.prefix || '/dword';\n    this._SOCKET_PATH     = options.socketPath || '';\n    \n    this._Element = el || document.body;\n    \n    const onDrop = this._onDrop.bind(this);\n    const onDragOver = this._onDragOver.bind(this);\n    \n    this._Element.addEventListener('drop', onDrop);\n    this._Element.addEventListener('dragover', onDragOver);\n    \n    loadScript(this._PREFIX + '/modules/execon/lib/exec.js', () => {\n        this._init(() => {\n            callback(this);\n        });\n    });\n    \n    this._patch = function(path, patch) {\n        this._patchHttp(path, patch);\n    };\n\n    this._write = function(path, result) {\n        this._writeHttp(path, result);\n    };\n}\n\nDword.prototype.isKey = function() {\n    return this._isKey;\n};\n\nDword.prototype.enableKey = function() {\n    this._isKey = true;\n    return this;\n};\n\nDword.prototype.disableKey = function() {\n    this._isKey = false;\n    return this;\n};\n\nDword.prototype._showMessageOnce = function(msg) {\n    if (!this._showedOnce) {\n        this.showMessage(msg);\n        this._showedOnce = true;\n    }\n};\n\nfunction empty() {}\n\nDword.prototype._init = function(fn) {\n    const loadFiles = this._loadFiles.bind(this);\n    const loadFilesAll = this._loadFilesAll.bind(this);\n    const loadStyles = this._loadStyles.bind(this);\n    \n    exec.series([\n        loadFiles,\n        (callback) => {\n            load.json(this._PREFIX + '/edit.json', (error, config) => {\n                if (error)\n                    return smalltalk.alert(this._TITLE, 'Could not load edit.json!');\n                \n                this._Config = config;\n                callback();\n            });\n        },\n        \n        (callback) => {\n            const name = 'smalltalk';\n            const js = '.min.js';\n            const dir = '/modules/' + name + '/dist/';\n            const isFlex = () => {\n                return document.body.style.flex !== 'undefined';\n            };\n            \n            const getJsName = () => {\n                const is = window.Promise;\n                const jsName = is ? js : '.poly' + js;\n                \n                if (isFlex())\n                    return jsName;\n                    \n                return '.native' + jsName;\n            }\n            \n            const jsName = getJsName();\n            const names = [jsName, '.min.css'].map((ext) => {\n                return this._PREFIX + dir + name + ext;\n            });\n            \n            load.parallel(names, callback);\n        },\n        \n        loadFilesAll,\n        loadStyles,\n        \n        () => {\n            const options = this._Config.options;\n            const Value = this._Value;\n            const all = {\n                autofocus           : true,\n                autoRefresh         : true,\n                lineNumbers         : true,\n                showTrailing        : true,\n                autoCloseBrackets   : true,\n                matchBrackets       : true,\n                matchTags           : false,\n                gutters             : ['CodeMirror-lint-markers'],\n                maxInvisibles       : 32,\n                searchbox           : true,\n                continueComments    : true,\n                \n                highlightSelectionMatches: true\n            };\n            \n            this._Emitter = Emitify();\n            this._Emitter.on('auth', (username, password) => {\n                this._socket.emit('auth', username, password);\n            });\n            \n            Object.keys(options).forEach((name) => {\n                if (name === 'tabSize')\n                    return all.indentUnit = options.tabSize;\n                \n                if (name === 'wrap')\n                    return all.lineWrapping = options.wrap;\n                \n                all[name] = options[name];\n            });\n            \n            this._Ace = CodeMirror(this._Element, all);\n            \n            if (Value)\n                this._initValue(this._FileName, Value);\n            \n            this._Ace.on('change', () => {\n                this._Emitter.emit('change');\n            });\n            \n            addCommands(this);\n            \n            fn();\n            \n            this.setOptions(options);\n        },\n    ]);\n};\n\nfunction _run(dword, fn) {\n    dword.isKey() && fn();\n}\n\nfunction addCommands(dword) {\n    const run = wraptile(_run, dword);\n    \n    const commands = {\n        'Ctrl-G': function () {\n            dword.goToLine();\n        },\n        'Ctrl-S': run(() => {\n            dword.save();\n        }),\n        'F2': run(() => {\n            dword.save();\n        }),\n        'Ctrl-B' : run(() => {\n            dword.beautify();\n        }),\n        'Ctrl-M' : run(() => {\n            dword.minify();\n        }),\n        'Ctrl-E' : run(() => {\n            dword.evaluate();\n        }),\n        'Ctrl-/' : 'toggleComment'\n    };\n    \n    Object.keys(commands).forEach((name) => {\n        if (/^Ctrl/.test(name)) {\n            const nameCmd = name.replace('Ctrl', 'Cmd');\n            commands[nameCmd] = commands[name];\n        }\n    });\n    \n    dword.addKeyMap(commands);\n}\n\nDword.prototype.evaluate = function() {\n    const focus = this.focus.bind(this);\n    const {\n        _FileName,\n        _TITLE,\n    } = this;\n    \n    const isJS = /\\.js$/.test(_FileName);\n    \n    let msg;\n    \n    if (!isJS) {\n        msg = 'Evaluation supported for JavaScript only';\n    } else {\n        const value = this.getValue();\n        msg = exec.try(Function(value));\n    }\n    \n    msg && smalltalk.alert(_TITLE, msg)\n        .then(focus);\n    \n    return this;\n};\n\nfunction createMsg() {\n    const wrapper = document.createElement('div');\n    const html = '<div class=\"dword-msg\">/div>';\n    \n    wrapper.innerHTML = html;\n    \n    return wrapper.firstChild;\n}\n\nDword.prototype.addKeyMap = function(keyMap) {\n    this._Ace.addKeyMap(keyMap);\n    return this;\n};\n\nDword.prototype.goToLine = function() {\n    const dword = this;\n    const Ace = this._Ace;\n    const msg = 'Enter line number:';\n    const cursor = dword.getCursor();\n    const number = cursor.row + 1;\n    \n    smalltalk.prompt(this._TITLE, msg, number).then((line) => {\n        const ch = 0;\n        \n        Ace.setCursor({\n            line: line - 1,\n            ch,\n        });\n        \n        const myHeight = Ace.getScrollInfo().clientHeight;\n        const coords = Ace.charCoords({line, ch}, 'local');\n        \n        Ace.scrollTo(null, (coords.top + coords.bottom - myHeight) / 2);\n    }).catch(empty).then(() => {\n        dword.focus();\n    });\n    \n    return this;\n};\n\nDword.prototype.moveCursorTo = function(row, column) {\n    this._Ace.setCursor(row, column);\n    return this;\n};\n\nDword.prototype.refresh = function() {\n    this._Ace.refresh();\n    return this;\n};\n\nDword.prototype.focus = function() {\n    this._Ace.focus();\n    return this;\n};\n\nDword.prototype.remove = function(direction) {\n    const cmd = (direction) => {\n        if (direction === 'right')\n            return 'delCharAfter';\n        \n        return 'delCharBefore';\n    };\n    \n    this._Ace.execCommand(cmd(direction));\n    \n    return this;\n};\n\nDword.prototype.getCursor = function() {\n    const {line, ch} = this._Ace.getCursor();\n    const cursor = {\n        row: line,\n        column: ch\n    };\n    \n    return cursor;\n};\n\nDword.prototype.getValue = function() {\n    return this._Ace.getValue();\n};\n\nDword.prototype.on = function(event, fn) {\n    this._Emitter.on(event, fn);\n    return this;\n};\n\nDword.prototype.once = function(event, fn) {\n    this._Emitter.once(event, fn);\n    return this;\n};\n\nDword.prototype.emit = function() {\n    this._Emitter.emit.apply(this._Emitter, arguments);\n    return this;\n};\n\nDword.prototype.isChanged = function() {\n    const value = this._Ace.getValue(this._Separator);\n    const isEqual = value === this._Value;\n    \n    return !isEqual;\n};\n\nDword.prototype.setValue = function(value) {\n    this._Ace.setValue(value);\n    return this;\n};\n\nDword.prototype.setValueFirst = function(name, value) {\n    const Ace = this._Ace;\n    const dword = this;\n    \n    dword.setValue(value)\n    \n    // fix of linenumbers overlap\n    dword.refresh();\n    \n    /*\n     * getCursor returns another\n     * information so set\n     * cursor manually\n     */\n    Ace.setCursor(1, 0);\n    Ace.clearHistory();\n    \n    this._FileName    = name;\n    this._Value       = value;\n    \n    setTimeout(() => {\n        this._Separator = getLineSeparator(value);\n    }, 0);\n    \n    return this;\n};\n    \n/*\n * CodeMirror set default line separator to \"\\n\"\n * what is great for Linux, but Windows use \"\\r\\n\"\n * and when trying to check that fact that file was changed\n * it's harder to do when you expect\n * to read saved file without change and\n * receive some changes insteed.\n */\nfunction getLineSeparator(value) {\n    if (typeof value !== 'string')\n        throw Error('value should be string!');\n    \n    if (~value.indexOf('\\r\\n'))\n        return '\\r\\n';\n    \n    return '\\n';\n}\n\nDword.prototype.setOption = function(name, value) {\n    const {_Ace} = this;\n    const preventOverwrite = () => {\n        this._Config.options[name] = value;\n    };\n    \n    preventOverwrite();\n    \n    switch(name) {\n    default:\n        _Ace.setOption(name, value);\n        break;\n    case 'fontSize':\n        _Ace.display.wrapper.style.fontSize = value + 'px';\n        break;\n    }\n    \n    return this;\n};\n\nDword.prototype.setOptions = function(options) {\n    Object.keys(options).forEach((name) => {\n        const value = options[name];\n        \n        this.setOption(name, value);\n    });\n    \n    return this;\n};\n\nDword.prototype.setMode = function(mode, callback) {\n    const isJSON = mode === 'json';\n    \n    var fn = (mode) => {\n        this._Ace.setOption('mode', mode);\n        \n        exec(callback);\n    };\n    \n    if (isJSON)\n        mode = 'javascript';\n    else if (!mode)\n        mode = null;\n    \n    const is = CodeMirror.modes[mode];\n    \n    if (is || !mode) {\n        fn(mode);\n        return this;\n    }\n    \n    CodeMirror.requireMode(mode, () => {\n        fn(mode);\n    });\n    \n    return this;\n};\n\nDword.prototype.setModeForPath   = function(path) {\n    var dword = this;\n    var self = this;\n    var modesByName = CodeMirror.findModeByFileName;\n    var name = path.split('/').pop();\n    \n    self._addExt(name, function(name) {\n        var info = modesByName(name) || {};\n        var mode = info.mode;\n        var htmlMode = modesByName('.html').mode;\n        var isHTML = mode === htmlMode;\n        \n        dword.setOption('matchTags', isHTML);\n        \n        if (isHTML)\n            self._setEmmet();\n        \n        dword.setMode(mode, function() {\n            var reg     = /^(json|javascript)$/,\n                isLint  = reg.test(mode),\n                isJS    = /.js$/.test(name);\n            \n            if (!isLint)\n                return dword.setOption('lint', false);\n            \n            if (!isJS)\n                return dword.setOption('lint', true);\n            \n            self._setJsHintConfig(function(jshint) {\n                dword.setOption('lint', jshint);\n            });\n        });\n    });\n    \n    return this;\n};\n\nDword.prototype.selectAll = function() {\n    this._Ace.execCommand('selectAll');\n    return this;\n};\n\nDword.prototype.copyToClipboard = function() {\n    var msg = 'Could not copy, use &ltCtrl&gt + &ltС&gt insted!';\n    \n    if (!this._clipboard('copy'))\n        smalltalk.alert(this._TITLE, msg);\n};\n\nDword.prototype.cutToClipboard = function() {\n    var msg = 'Could not cut, use &ltCtrl&gt + &ltX&gt insted!';\n    \n    if (!this._clipboard('cut'))\n        return smalltalk.alert(this._TITLE, msg);\n    \n    this.remove('right');\n};\n\nDword.prototype.pasteFromClipboard = function() {\n    var msg = 'Could not paste, use &ltCtrl&gt + &ltV&gt insted!';\n    \n    if (!this._clipboard('paste'))\n        smalltalk.alert(this._TITLE, msg);\n};\n\nDword.prototype._clipboard = function(cmd) {\n    var result;\n    var value;\n    var Ace = this._Ace;\n    var story = this._story;\n    var NAME = 'editor-clipboard';\n    var body = document.body;\n    var textarea = document.createElement('textarea');\n    \n    if (!/^cut|copy|paste$/.test(cmd))\n        throw Error('cmd could be \"cut\" or \"copy\" only!');\n    \n    body.appendChild(textarea);\n    \n    if (cmd === 'paste') {\n        textarea.focus();\n        result = document.execCommand(cmd);\n        value = textarea.value;\n        \n        if (!result) {\n            this._showMessageOnce('Could not paste from clipboard. Inner buffer used.');\n            result  = true;\n            value   = story.getData(NAME);\n        }\n        \n        if (value)\n            Ace.getDoc().replaceSelection(value);\n    } else {\n        textarea.value = Ace.getSelection('\\n');\n        story.setData(NAME, textarea.value);\n        textarea.select();\n        result = document.execCommand(cmd);\n    }\n    \n    body.removeChild(textarea);\n    \n    return result;\n};\n\nDword.prototype.showMessage = function(text) {\n    var self        = this,\n        HIDE_TIME   = 2000;\n    \n    if (!this._ElementMsg) {\n        this._ElementMsg = createMsg();\n        this._Element.appendChild(this._ElementMsg);\n    }\n    \n    this._ElementMsg.textContent = text;\n    this._ElementMsg.hidden = false;\n    \n    setTimeout(function() {\n        self._ElementMsg.hidden = true;\n    }, HIDE_TIME);\n    \n    return this;\n};\n\nDword.prototype.sha          = function(callback) {\n    var dword   = this,\n        url     = this._PREFIX + this._DIR + 'jsSHA/src/sha.js';\n    \n    load.js(url, function() {\n        var shaObj, hash, error,\n            value   = dword.getValue();\n        \n        error = exec.try(function() {\n            shaObj  = new window.jsSHA('SHA-1', 'TEXT');\n            shaObj.update(value);\n            hash    = shaObj.getHash('HEX');\n        });\n        \n        callback(error, hash);\n    });\n    \n    return dword;\n};\n\nDword.prototype.beautify = function() {\n    this._readWithFlag('beautify');\n    return this;\n};\n\nDword.prototype.minify = function() {\n    this._readWithFlag('minify');\n    return this;\n};\n\nDword.prototype.save = function() {\n    var self    = this,\n        dword   = this,\n        value   = dword.getValue();\n    \n    this._loadOptions(function(error, config) {\n        var isDiff      = config.diff,\n            isZip       = config.zip,\n            doDiff      = self._doDiff.bind(self);\n        \n        exec.if(!isDiff, function(patch) {\n            var query           = '',\n                patchLength     = patch && patch.length || 0,\n                length          = self._Value.length,\n                isLessMaxLength = length < self._MAX_FILE_SIZE,\n                isLessLength    = isLessMaxLength && patchLength < length,\n                isStr           = typeof patch === 'string',\n                isPatch         = patch && isStr && isLessLength;\n            \n            self._Value         = value;\n            \n            exec.if(!isZip || isPatch, function(equal, data) {\n                var result  = data || self._Value;\n                \n                if (isPatch)\n                    dword._patch(self._FileName, patch);\n                else\n                    dword._write(self._FileName + query, result);\n            }, function(func) {\n                self._zip(value, function(error, data) {\n                    if (error)\n                        console.error(error);\n                    \n                    query = '?unzip';\n                    func(null, data);\n                });\n            });\n            \n        }, exec.with(doDiff, self._FileName));\n    });\n    \n    return dword;\n};\n\nDword.prototype._loadOptions = function(callback) {\n    var self    = this,\n        url     = this._PREFIX + '/options.json';\n    \n    if (self._Options)\n        callback(null, self._Options);\n    else\n        load.json(url, function(error, data) {\n            self._Options = data;\n            callback(error, data);\n        });\n};\n    \nDword.prototype._patchHttp = function(path, patch) {\n    var onSave = this._onSave.bind(this);\n    restafary.patch(path, patch, onSave);\n};\n\nDword.prototype._writeHttp = function(path, result) {\n    var onSave = this._onSave.bind(this);\n    restafary.write(path, result, onSave);\n};\n\nDword.prototype._onSave = function(error, text) {\n    var self        = this,\n        dword       = this,\n        Value       = self._Value,\n        FileName    = self._FileName,\n        msg         = 'Try again?';\n        \n    if (error) {\n        if (error.message)\n            msg = error.message + '\\n' + msg;\n        else\n            msg = 'Can\\'t save.' + msg;\n        \n        smalltalk.confirm(this._TITLE, msg).then(function() {\n            var onSave = self._onSave.bind(self);\n            restafary.write(self._FileName, self._Value, onSave);\n        }).catch(empty).then(function(){\n            dword.focus();\n        });\n    } else {\n        dword.showMessage(text);\n        \n        dword.sha(function(error, hash) {\n            if (error)\n                console.error(error);\n            \n            self._story.setData(FileName, Value)\n                .setHash(FileName, hash);\n        });\n        \n        self._Emitter.emit('save', Value.length);\n    }\n};\n\nDword.prototype._doDiff = function(path, callback) {\n    var self    = this,\n        value   = this.getValue();\n    \n    this._diff(value, function(patch) {\n        self._story.checkHash(path, function(error, equal) {\n            if (!equal)\n                patch = '';\n            \n            callback(patch);\n        });\n    });\n};\n\nDword.prototype._diff = function(newValue, callback) {\n    var self = this;\n    \n    self._loadDiff(function(error) {\n        var patch;\n        \n        if (error) {\n            smalltalk.alert(this._TITLE, error);\n        } else {\n            self._Value = self._story.getData(self._FileName);\n            patch       = daffy.createPatch(self._Value, newValue);\n            callback(patch);\n        }\n    });\n};\n\nDword.prototype._loadDiff = function(callback) {\n    var self    = this,\n        url     = this._PREFIX + join([\n            'google-diff-match-patch/diff_match_patch.js',\n            'daffy/lib/daffy.js'\n        ].map(function(name) {\n            return self._DIR + name;\n        }));\n    \n    load.js(url, callback);\n};\n\nDword.prototype._zip = function(value, callback) {\n    var self    = this,\n        prefix  = this._PREFIX;\n    \n    exec.parallel([\n        function(callback) {\n            var url = prefix + self._DIR + 'zipio/lib/zipio.js';\n            \n            load.js(url, callback);\n        },\n        function(callback) {\n            loadRemote('pako', {prefix: prefix}, callback);\n        }\n    ], function(error) {\n        if (!error)\n            global.zipio(value, callback);\n        else\n            smalltalk.alert(this._TITLE, error);\n    });\n};\n\nDword.prototype._setEmmet = function() {\n    var dir = this._DIR + 'codemirror-emmet/dist/';\n    var extensions = this._Config.extensions;\n    var isEmmet = extensions.emmet;\n    \n    if (isEmmet)\n        load.js(this._PREFIX + join([\n            dir + 'emmet.min.js'\n        ]));\n};\n\nDword.prototype._setJsHintConfig = function(callback) {\n    var self        = this,\n        JSHINT_PATH = this._PREFIX + '/jshint.json';\n    \n    if (this._JSHintConfig)\n        callback(this._JSHintConfig);\n    else\n        load.json(JSHINT_PATH, function(error, json) {\n            if (!error)\n                self._JSHintConfig = json;\n            else\n                smalltalk.alert(this._TITLE, error);\n            \n            callback(self._JSHintConfig);\n        });\n};\n\nDword.prototype._addExt = function(name, fn) {\n    var self = this;\n    \n    if (self._Ext)\n        add(null, self._Ext);\n    else\n        load.json(self._PREFIX + '/json/ext.json', function(error, data) {\n            self._Ext = data;\n            add(error, self._Ext);\n        });\n    \n    function add(error, exts) {\n        if (error)\n            console.error(Error('Could not load ext.json!'));\n        else\n            Object.keys(exts).some(function(ext) {\n                var arr = exts[ext],\n                    is  = ~arr.indexOf(name);\n                \n                if (is)\n                    name += '.' + ext;\n                \n                return is;\n            });\n        \n        fn(name);\n    }\n};\n\nfunction getHost() {\n    var l       = location,\n        href    = l.origin || l.protocol + '//' + l.host;\n    \n    return href;\n}\n\nDword.prototype._initSocket = function(error) {\n    var socket,\n        self            = this,\n        dword           = this,\n        href            = getHost(),\n        FIVE_SECONDS    = 5000,\n        patch    = function(name, data) {\n            socket.emit('patch', name, data);\n        };\n        \n    if (error)\n        return smalltalk.alert(this._TITLE, error);\n    \n    socket  = io.connect(href + this._PREFIX, {\n        'max reconnection attempts' : Math.pow(2, 32),\n        'reconnection limit'        : FIVE_SECONDS,\n        path                        : this._SOCKET_PATH + '/socket.io'\n    });\n    \n    socket.on('reject', function() {\n        self.emit('reject');\n    });\n    \n    self._socket = socket;\n    \n    socket.on('connect', function() {\n        dword._patch = patch;\n    });\n    \n    socket.on('message', function(msg) {\n        self._onSave(null, msg);\n    });\n    \n    socket.on('file', function(name, data) {\n        if (self._Ace) {\n            self._initValue(name, data);\n        } else {\n            self._FileName    = name;\n            self._Value       = data;\n        }\n    });\n    \n    socket.on('patch', function(name, data, hash) {\n        if (name !== self._FileName)\n            return;\n        \n        self._loadDiff(function(error) {\n            var cursor, value;\n            \n            if (error)\n                return console.error(error);\n            \n            if (hash !== self._story.getHash(name))\n                return;\n                \n            cursor  = dword.getCursor(),\n            value   = dword.getValue();\n            value   = daffy.applyPatch(value, data);\n            \n            dword.setValue(value);\n            \n            dword.sha(function(error, hash) {\n                self._story.setData(name, value)\n                    .setHash(name, hash);\n                \n                dword.moveCursorTo(cursor.row, cursor.column);\n            });\n        });\n    });\n    \n    socket.on('disconnect', function() {\n        dword._patch = self._patchHttp;\n    });\n    \n    socket.on('err', function(error) {\n        smalltalk.alert(this._TITLE, error);\n    });\n};\n\nDword.prototype._initValue = function(name, data) {\n    return this.setModeForPath(name)\n        .setValueFirst(name, data)\n        .moveCursorTo(0, 0);\n};\n\nDword.prototype._readWithFlag = function(flag) {\n    var dword   = this,\n        path    = this._FileName + '?' + flag;\n    \n    restafary.read(path, function(error, data) {\n        if (error)\n            smalltalk.alert(dword._TITLE, error);\n        else\n            dword\n                .setValue(data)\n                .moveCursorTo(0, 0);\n    });\n};\n\n/**\n * In Mac OS Chrome dropEffect = 'none'\n * so drop do not firing up when try\n * to upload file from download bar\n */\nDword.prototype._onDragOver = function(event) {\n    var dataTransfer    = event.dataTransfer,\n        effectAllowed   = dataTransfer.effectAllowed;\n    \n    if (/move|linkMove/.test(effectAllowed))\n        dataTransfer.dropEffect = 'move';\n    else\n        dataTransfer.dropEffect = 'copy';\n    \n    event.preventDefault();\n};\n\nDword.prototype._onDrop = function(event) {\n    var dword   = this,\n        reader, files,\n        onLoad   =  function(event) {\n            var data    = event.target.result;\n            \n            dword.setValue(data);\n        };\n    \n    event.preventDefault();\n    \n    files   = event.dataTransfer.files;\n    \n    [].forEach.call(files, function(file) {\n        reader  = new FileReader();\n        reader.addEventListener('load', onLoad);\n        reader.readAsBinaryString(file);\n    });\n};\n\nfunction getModulePath(name, lib, ext) {\n    ext = ext || '.js';\n    \n    var path = '';\n    var libdir = '/';\n    var dir = '/modules/';\n    \n    if (lib)\n        libdir  = '/' + lib + '/';\n    \n    path    = dir + name + libdir + name + ext;\n    \n    return path;\n}\n\nDword.prototype._loadStyles = function(callback) {\n    var urlCSS  = '',\n        dir     = this._DIR + 'codemirror/',\n        addon   = dir + 'addon/',\n        lint    = addon + 'lint/',\n        theme   = this._Config.options.theme,\n        urls    =[\n            addon   + 'dialog/dialog',\n            addon   + 'search/matchesonscrollbar',\n            lint    + 'lint',\n            '/css/dword',\n        ];\n    \n    if (theme && theme !== 'default')\n        urls.unshift(dir + 'theme/' + theme);\n    \n    urlCSS = this._PREFIX + join(urls\n        .map(function(name) {\n            return name + '.css';\n        }));\n    \n    load(urlCSS, callback);\n};\n\nDword.prototype._loadFiles = function(callback) {\n    var self = this;\n    var obj = {\n        loadRemote  : getModulePath('loadremote', 'lib'),\n        load        : getModulePath('load'),\n        Emitify     : getModulePath('emitify', 'dist', '.min.js'),\n        join        : '/join/join.js'\n    };\n        \n    var scripts = Object.keys(obj)\n        .filter(function(name) {\n            return !window[name];\n        })\n        .map(function(name) {\n            return self._PREFIX + obj[name];\n        });\n    \n    exec.if(!scripts.length, callback, function() {\n        loadScript(scripts, callback);\n    });\n};\n \nDword.prototype._loadFilesAll = function(callback) {\n    var self        = this,\n        DIR         = this._DIR,\n        PREFIX      = this._PREFIX,\n        initSocket  = this._initSocket.bind(this);\n    \n    exec.series([\n        function(callback) {\n            var options = {\n                prefix: PREFIX\n            };\n            \n            loadRemote('codemirror', options, callback);\n        },\n        \n        function(callback) {\n            loadRemote('socket', {\n                name : 'io',\n                prefix: self._SOCKET_PATH\n            }, initSocket);\n            \n            callback();\n        },\n        \n        function(callback) {\n            CodeMirror.modeURL = PREFIX + DIR + 'codemirror/mode/%N/%N.js';\n            callback();\n        },\n         \n        function(callback) {\n            var js = PREFIX + '/restafary.js';\n            var dir = DIR + 'codemirror/';\n            var client = 'client/codemirror/';\n            var addon = dir + 'addon/';\n            var lint = addon + 'lint/';\n            \n            var urlJS = PREFIX + join([\n                dir     + 'mode/meta',\n                \n                lint    + 'lint',\n                lint    + 'javascript-lint',\n                lint    + 'json-lint',\n                \n                client  + 'show-trailing',\n                client  + 'use-soft-tabs',\n                \n                DIR     + 'jshint/dist/jshint',\n                DIR     + 'cm-searchbox/lib/searchbox',\n                DIR     + 'cm-show-invisibles/dist/show-invisibles',\n                getKeyMapPath(dir, self._Config),\n                dir     + 'keymap/vim',\n            ].filter(function(name) {\n                return name;\n            }).concat([\n                'display/autorefresh',\n                \n                'comment/comment',\n                'comment/continuecomment',\n                \n                'mode/loadmode',\n                'mode/overlay',\n                \n                'search/searchcursor',\n                'search/match-highlighter',\n                'search/matchesonscrollbar',\n                \n                'dialog/dialog',\n                'scroll/annotatescrollbar',\n                'fold/xml-fold',\n                \n                'edit/closebrackets',\n                'edit/matchbrackets',\n                'edit/matchtags'\n            ].map(function(name) {\n                return addon + name;\n            })\n            ).map(function(name) {\n                return name + '.js';\n            }));\n             \n            load.parallel([urlJS, js], callback);\n        },\n        \n        function() {\n            restafary.prefix(PREFIX + '/api/v1/fs');\n            callback();\n        }\n    ]);\n};\n \nfunction getKeyMapPath(dir, config) {\n    var path = '';\n    var keyMap = config && config.options && config.options.keyMap;\n    \n    if (keyMap && keyMap !== 'default')\n        path = dir + 'keymap/' + keyMap;\n    \n    return path;\n}\n\nfunction loadScript(srcs, callback) {\n    var i,\n        func    = function() {\n            --i;\n            \n            if (!i)\n                callback();\n        };\n    \n    if (typeof srcs === 'string')\n        srcs = [srcs];\n    \n    i = srcs.length;\n    \n    srcs.forEach(function(src) {\n        var element = document.createElement('script');\n    \n        element.src = src;\n        element.addEventListener('load', function load() {\n            func();\n            element.removeEventListener('load', load);\n        });\n    \n        document.body.appendChild(element);\n    });\n}\n\n\n/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(/*! ./../node_modules/webpack/buildin/global.js */ 1)))\n\n//////////////////\n// WEBPACK FOOTER\n// ./client/dword.js\n// module id = 0\n// module chunks = 0\n\n//# sourceURL=file://dword/client/dword.js");

/***/ }),
/* 1 */
/*!***********************************!*\
  !*** (webpack)/buildin/global.js ***!
  \***********************************/
/*! no static exports found */
/*! all exports used */
/***/ (function(module, exports) {

eval("var g;\r\n\r\n// This works in non-strict mode\r\ng = (function() {\r\n\treturn this;\r\n})();\r\n\r\ntry {\r\n\t// This works if eval is allowed (see CSP)\r\n\tg = g || Function(\"return this\")() || (1,eval)(\"this\");\r\n} catch(e) {\r\n\t// This works if the window reference is available\r\n\tif(typeof window === \"object\")\r\n\t\tg = window;\r\n}\r\n\r\n// g can still be undefined, but nothing to do about it...\r\n// We return undefined, instead of nothing here, so it's\r\n// easier to handle this case. if(!global) { ...}\r\n\r\nmodule.exports = g;\r\n\n\n//////////////////\n// WEBPACK FOOTER\n// (webpack)/buildin/global.js\n// module id = 1\n// module chunks = 0\n\n//# sourceURL=file://dword/node_modules/webpack/buildin/global.js");

/***/ }),
/* 2 */
/*!*************************!*\
  !*** ./client/story.js ***!
  \*************************/
/*! no static exports found */
/*! all exports used */
/***/ (function(module, exports, __webpack_require__) {

"use strict";
eval("\n\n/* global restafary */\n\nmodule.exports = Story;\n\nfunction Story() {\n    if (!(this instanceof Story))\n        return new Story();\n}\n\nStory.prototype.checkHash = function(name, callback) {\n    this.loadHash(name, (error, loadHash) => {\n        const nameHash = name + '-hash';\n        const storeHash = localStorage.getItem(nameHash);\n        const equal = loadHash === storeHash;\n        \n        callback(error, equal);\n    });\n    \n    return this;\n};\n\nStory.prototype.loadHash = function(name, callback) {\n    const query = '?hash';\n    \n    restafary.read(name + query, callback);\n    \n    return this;\n};\n\nStory.prototype.setData = function(name, data) {\n    const nameData = name + '-data';\n    \n    localStorage.setItem(nameData, data);\n    \n    return this;\n};\n\nStory.prototype.setHash = function(name, hash) {\n    const nameHash = name + '-hash';\n    \n    localStorage.setItem(nameHash, hash);\n    \n    return this;\n};\n\nStory.prototype.getData = function(name) {\n    const nameData = name + '-data';\n    const data = localStorage.getItem(nameData);\n    \n    return data || '';\n};\n\nStory.prototype.getHash = function(name) {\n    const item = name + '-hash';\n    const data = localStorage.getItem(item);\n    \n    return data || '';\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./client/story.js\n// module id = 2\n// module chunks = 0\n\n//# sourceURL=file://dword/client/story.js");

/***/ }),
/* 3 */
/*!***********************************************!*\
  !*** ./node_modules/wraptile/legacy/index.js ***!
  \***********************************************/
/*! no static exports found */
/*! all exports used */
/***/ (function(module, exports, __webpack_require__) {

eval("module.exports = __webpack_require__(/*! ./lib/wraptile */ 4);\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/wraptile/legacy/index.js\n// module id = 3\n// module chunks = 0\n\n//# sourceURL=file://dword/node_modules/wraptile/legacy/index.js");

/***/ }),
/* 4 */
/*!******************************************************!*\
  !*** ./node_modules/wraptile/legacy/lib/wraptile.js ***!
  \******************************************************/
/*! no static exports found */
/*! all exports used */
/***/ (function(module, exports, __webpack_require__) {

"use strict";
eval("\n\nvar wrap = function wrap(fn) {\n    for (var _len = arguments.length, a = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {\n        a[_key - 1] = arguments[_key];\n    }\n\n    return function () {\n        for (var _len2 = arguments.length, b = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {\n            b[_key2] = arguments[_key2];\n        }\n\n        return function () {\n            for (var _len3 = arguments.length, c = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {\n                c[_key3] = arguments[_key3];\n            }\n\n            return fn.apply(undefined, a.concat(b, c));\n        };\n    };\n};\n\nmodule.exports = function (fn) {\n    for (var _len4 = arguments.length, a = Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {\n        a[_key4 - 1] = arguments[_key4];\n    }\n\n    check(fn);\n\n    return wrap.apply(undefined, [fn].concat(a));\n};\n\nfunction check(fn) {\n    if (typeof fn !== 'function') throw Error('fn should be function!');\n}\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/wraptile/legacy/lib/wraptile.js\n// module id = 4\n// module chunks = 0\n\n//# sourceURL=file://dword/node_modules/wraptile/legacy/lib/wraptile.js");

/***/ })
/******/ ]);