UNPKG

zcloudcmd

Version:

### [Main][MainURL] [Blog][BlogURL] Live([Heroku][HerokuURL], [Now][NowURL])

192 lines (182 loc) 15.5 kB
/******/ (function(modules) { // webpackBootstrap /******/ // install a JSONP callback for chunk loading /******/ function webpackJsonpCallback(data) { /******/ var chunkIds = data[0]; /******/ var moreModules = data[1]; /******/ var executeModules = data[2]; /******/ /******/ // add "moreModules" to the modules object, /******/ // then flag all "chunkIds" as loaded and fire callback /******/ var moduleId, chunkId, i = 0, resolves = []; /******/ for(;i < chunkIds.length; i++) { /******/ chunkId = chunkIds[i]; /******/ if(installedChunks[chunkId]) { /******/ resolves.push(installedChunks[chunkId][0]); /******/ } /******/ installedChunks[chunkId] = 0; /******/ } /******/ for(moduleId in moreModules) { /******/ if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) { /******/ modules[moduleId] = moreModules[moduleId]; /******/ } /******/ } /******/ if(parentJsonpFunction) parentJsonpFunction(data); /******/ /******/ while(resolves.length) { /******/ resolves.shift()(); /******/ } /******/ /******/ // add entry modules from loaded chunk to deferred list /******/ deferredModules.push.apply(deferredModules, executeModules || []); /******/ /******/ // run deferred modules when all chunks ready /******/ return checkDeferredModules(); /******/ }; /******/ function checkDeferredModules() { /******/ var result; /******/ for(var i = 0; i < deferredModules.length; i++) { /******/ var deferredModule = deferredModules[i]; /******/ var fulfilled = true; /******/ for(var j = 1; j < deferredModule.length; j++) { /******/ var depId = deferredModule[j]; /******/ if(installedChunks[depId] !== 0) fulfilled = false; /******/ } /******/ if(fulfilled) { /******/ deferredModules.splice(i--, 1); /******/ result = __webpack_require__(__webpack_require__.s = deferredModule[0]); /******/ } /******/ } /******/ return result; /******/ } /******/ /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // object to store loaded and loading chunks /******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched /******/ // Promise = chunk loading, 0 = chunk loaded /******/ var installedChunks = { /******/ "./modules/config": 0 /******/ }; /******/ /******/ var deferredModules = []; /******/ /******/ // 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, { enumerable: true, get: getter }); /******/ } /******/ }; /******/ /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ /******/ // create a fake namespace object /******/ // mode & 1: value is a module id, require it /******/ // mode & 2: merge all properties of value into the ns /******/ // mode & 4: return value when already ns object /******/ // mode & 8|1: behave like require /******/ __webpack_require__.t = function(value, mode) { /******/ if(mode & 1) value = __webpack_require__(value); /******/ if(mode & 8) return value; /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; /******/ var ns = Object.create(null); /******/ __webpack_require__.r(ns); /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); /******/ return ns; /******/ }; /******/ /******/ // 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 = "/dist/"; /******/ /******/ var jsonpArray = window["webpackJsonp"] = window["webpackJsonp"] || []; /******/ var oldJsonpFunction = jsonpArray.push.bind(jsonpArray); /******/ jsonpArray.push = webpackJsonpCallback; /******/ jsonpArray = jsonpArray.slice(); /******/ for(var i = 0; i < jsonpArray.length; i++) webpackJsonpCallback(jsonpArray[i]); /******/ var parentJsonpFunction = oldJsonpFunction; /******/ /******/ /******/ // add entry module to deferred list /******/ deferredModules.push(["./client/modules/config.js","cloudcmd.common"]); /******/ // run deferred modules when ready /******/ return checkDeferredModules(); /******/ }) /************************************************************************/ /******/ ({ /***/ "./client/input.js": /*!*************************!*\ !*** ./client/input.js ***! \*************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; eval("\n\nconst currify = __webpack_require__(/*! currify/legacy */ \"./node_modules/currify/legacy/index.js\");\n\nconst isType = currify((type, object, name) => {\n return typeof object[name] === type;\n});\n\nconst isBool = isType('boolean');\n\nmodule.exports.getElementByName = getElementByName;\n\nfunction getElementByName(selector, element) {\n const str = `[data-name=\"js-${selector}\"]`;\n \n return element\n .querySelector(str);\n}\n\nmodule.exports.getName = (element) => {\n const name = element\n .getAttribute('data-name')\n .replace(/^js-/, '');\n \n return name;\n};\n\nmodule.exports.convert = (config) => {\n const result = {\n ...config,\n };\n \n const array = Object.keys(result);\n \n array\n .filter(isBool(result))\n .forEach((name) => {\n const item = result[name];\n \n result[name] = setState(item);\n });\n \n return result;\n};\n\nfunction setState(state) {\n if (state)\n return ' checked';\n \n return '';\n}\n\nmodule.exports.getValue = (name, element) => {\n const el = getElementByName(name, element);\n const {type} = el;\n \n switch(type) {\n case 'checkbox':\n return el.checked;\n \n case 'number':\n return Number(el.value);\n \n default:\n return el.value;\n }\n};\n\nmodule.exports.setValue = (name, value, element) => {\n const el = getElementByName(name, element);\n const {type} = el;\n \n switch(type) {\n case 'checkbox':\n el.checked = value;\n break;\n \n default:\n el.value = value;\n break;\n }\n};\n\n\n\n//# sourceURL=file://cloudcmd/client/input.js"); /***/ }), /***/ "./client/modules/config.js": /*!**********************************!*\ !*** ./client/modules/config.js ***! \**********************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; eval("\n\n/* global CloudCmd, DOM, io */\n\n__webpack_require__(/*! ../../css/config.css */ \"./css/config.css\");\n\nconst rendy = __webpack_require__(/*! rendy/legacy */ \"./node_modules/rendy/legacy/index.js\");\nconst exec = __webpack_require__(/*! execon */ \"./node_modules/execon/lib/exec.js\");\nconst currify = __webpack_require__(/*! currify/legacy */ \"./node_modules/currify/legacy/index.js\");\nconst wraptile = __webpack_require__(/*! wraptile/legacy */ \"./node_modules/wraptile/legacy/index.js\");\nconst squad = __webpack_require__(/*! squad/legacy */ \"./node_modules/squad/legacy/index.js\");\nconst {promisify} = __webpack_require__(/*! es6-promisify */ \"./node_modules/es6-promisify/dist/promisify.js\");\nconst load = __webpack_require__(/*! load.js */ \"./node_modules/load.js/legacy/load.js\");\nconst createElement = __webpack_require__(/*! @cloudcmd/create-element */ \"./node_modules/@cloudcmd/create-element/legacy/create-element.js\");\n\nconst input = __webpack_require__(/*! ../input */ \"./client/input.js\");\nconst Images = __webpack_require__(/*! ../dom/images */ \"./client/dom/images.js\");\nconst Events = __webpack_require__(/*! ../dom/events */ \"./client/dom/events/index.js\");\nconst Files = __webpack_require__(/*! ../dom/files */ \"./client/dom/files.js\");\n\nconst {getTitle} = __webpack_require__(/*! ../../common/cloudfunc */ \"./common/cloudfunc.js\");\nconst {Dialog, setTitle} = DOM;\n\nconst Name = 'Config';\nCloudCmd[Name] = module.exports;\nconst alert = currify(Dialog.alert, Name);\n\nconst loadSocket = promisify(DOM.loadSocket);\n\nconst showLoad = () => {\n Images.show.load('top');\n};\n\nconst addKey = currify((fn, input) => {\n Events.addKey(input, fn);\n return input;\n});\n\nconst addChange = currify((fn, input) => {\n Events.add('change', input, fn);\n return input;\n});\n\nconst Config = {};\n\nlet Loading = true;\n\nmodule.exports.init = async () => {\n if (!CloudCmd.config('configDialog'))\n return;\n \n showLoad();\n \n await CloudCmd.View();\n await loadSocket();\n initSocket();\n Loading = false;\n};\n\nconst {\n config,\n Key,\n} = CloudCmd;\n\nlet Element;\nlet Template;\n\nfunction getHost() {\n const {\n host,\n origin,\n protocol,\n } = location;\n const href = origin || `${protocol}//${host}`;\n \n return href;\n}\n\nfunction initSocket() {\n const href = getHost();\n const {\n prefixSocket,\n prefix,\n } = CloudCmd;\n \n const ONE_MINUTE = 60 * 1000;\n \n const socket = io.connect(href + prefixSocket + '/config', {\n reconnectionAttempts: Infinity,\n reconnectionDelay: ONE_MINUTE,\n path: prefix + '/socket.io',\n });\n \n const save = (data) => {\n onSave(data);\n socket.send(data);\n };\n \n authCheck(socket);\n \n socket.on('connect', () => {\n Config.save = save;\n });\n \n socket.on('message', onSave);\n socket.on('log', CloudCmd.log);\n \n socket.on('disconnect', () => {\n Config.save = saveHttp;\n });\n \n socket.on('err', alert);\n}\n\nfunction authCheck(socket) {\n socket.emit('auth', config('username'), config('password'));\n socket.on('reject', wraptile(alert, 'Wrong credentials!'));\n}\n\nConfig.save = saveHttp;\n\nmodule.exports.show = show;\n\nfunction show() {\n if (!CloudCmd.config('configDialog'))\n return;\n \n const {prefix} = CloudCmd;\n const funcs = [\n exec.with(Files.get, 'config-tmpl'),\n exec.with(load.css, prefix + '/dist/config.css'),\n ];\n \n if (Loading)\n return;\n \n showLoad();\n exec.parallel(funcs, fillTemplate);\n}\n\nfunction fillTemplate(error, template) {\n if (!Template)\n Template = template;\n \n Files.get('config', (error, config) => {\n if (error)\n return alert('Could not load config!');\n \n const {\n editor,\n packer,\n columns,\n configAuth,\n ...obj\n } = input.convert(config);\n \n obj[editor + '-selected'] = 'selected';\n obj[packer + '-selected'] = 'selected';\n obj[columns + '-selected'] = 'selected';\n obj.configAuth = configAuth ? '' : 'hidden';\n \n const innerHTML = rendy(Template, obj);\n \n Element = createElement('form', {\n className : 'config',\n innerHTML,\n });\n \n const inputs = document.querySelectorAll('input, select', Element);\n const [inputFirst] = inputs;\n \n let afterShow;\n \n if (inputFirst) {\n onAuthChange(inputFirst.checked);\n afterShow = inputFirst.focus.bind(inputFirst);\n }\n \n const getTarget = ({target}) => target;\n const handleChange = squad(onChange, getTarget);\n \n [...inputs]\n .map(addKey(onKey))\n .map(addChange(handleChange));\n \n const autoSize = true;\n CloudCmd.View.show(Element, {\n autoSize,\n afterShow,\n });\n });\n}\n\nmodule.exports.hide = hide;\n\nfunction hide() {\n CloudCmd.View.hide();\n}\n\nfunction onChange(el) {\n const obj = {};\n const name = input.getName(el);\n const data = input.getValue(name, Element);\n \n if (name === 'name')\n onNameChange(data);\n else if (name === 'auth')\n onAuthChange(data);\n \n obj[name] = data;\n \n Config.save(obj);\n}\n\nfunction onSave(obj) {\n Object.keys(obj).forEach((name) => {\n const data = obj[name];\n \n CloudCmd._config(name, data);\n input.setValue(name, data, Element);\n });\n}\n\nfunction saveHttp(obj) {\n const {RESTful} = DOM;\n \n RESTful.Config.write(obj, (error) => {\n if (error)\n return;\n \n onSave(obj);\n });\n}\n\nfunction onAuthChange(checked) {\n const elUsername = input.getElementByName('username', Element);\n const elPassword = input.getElementByName('password', Element);\n \n elUsername.disabled =\n elPassword.disabled = !checked;\n}\n\nfunction onNameChange(name) {\n setTitle(getTitle({\n name,\n }));\n}\n\nfunction onKey({keyCode, target}) {\n switch(keyCode) {\n case Key.ESC:\n return hide();\n \n case Key.ENTER:\n return onChange(target);\n }\n}\n\n\n\n//# sourceURL=file://cloudcmd/client/modules/config.js"); /***/ }), /***/ "./css/config.css": /*!************************!*\ !*** ./css/config.css ***! \************************/ /*! no static exports found */ /***/ (function(module, exports) { eval("// removed by extract-text-webpack-plugin\n\n//# sourceURL=file://cloudcmd/css/config.css"); /***/ }) /******/ });