chore: lint

This commit is contained in:
coderaiser 2023-07-09 12:43:24 +03:00
parent f1279666b5
commit 4717e035ee
173 changed files with 1388 additions and 1627 deletions

View file

@ -15,6 +15,7 @@ const {log} = CloudCmd;
const upload = currify(_upload);
const Name = 'Cloud';
CloudCmd[Name] = module.exports;
module.exports.init = async () => {
@ -41,10 +42,7 @@ module.exports.saveFile = (callback) => {
};
function _upload(callback, file) {
const {
url,
filename,
} = file;
const {url, filename} = file;
const responseType = 'arraybuffer';
const success = exec.with(callback, filename);
@ -64,4 +62,3 @@ function loadFiles() {
load.js(js),
]);
}

View file

@ -1,7 +1,6 @@
'use strict';
/* global CloudCmd */
CloudCmd.CommandLine = exports;
const Dialog = require('../dom/dialog');
@ -34,6 +33,4 @@ async function show() {
}
}
function hide() {
}
function hide() {}

View file

@ -1,7 +1,6 @@
'use strict';
/* global CloudCmd, DOM, io */
require('../../../css/config.css');
const rendy = require('rendy');
@ -22,6 +21,7 @@ const {getTitle} = require('../../../common/cloudfunc');
const {Dialog, setTitle} = DOM;
const Name = 'Config';
CloudCmd[Name] = module.exports;
const loadSocket = promisify(DOM.loadSocket);
@ -64,10 +64,7 @@ module.exports.init = async () => {
initSocket();
};
const {
config,
Key,
} = CloudCmd;
const {config, Key} = CloudCmd;
let Element;
@ -77,6 +74,7 @@ function getHost() {
origin,
protocol,
} = location;
const href = origin || `${protocol}//${host}`;
return href;
@ -84,10 +82,7 @@ function getHost() {
function initSocket() {
const href = getHost();
const {
prefixSocket,
prefix,
} = CloudCmd;
const {prefixSocket, prefix} = CloudCmd;
const ONE_MINUTE = 60 * 1000;
@ -156,7 +151,7 @@ async function fillTemplate() {
const innerHTML = rendy(Template, obj);
Element = createElement('form', {
className : 'config',
className: 'config',
innerHTML,
});
@ -173,11 +168,13 @@ async function fillTemplate() {
const getTarget = ({target}) => target;
const handleChange = squad(onChange, getTarget);
Array.from(inputs)
Array
.from(inputs)
.map(addKey(onKey))
.map(addChange(handleChange));
const autoSize = true;
CloudCmd.View.show(Element, {
autoSize,
afterShow,
@ -246,4 +243,3 @@ async function onKey({keyCode, target}) {
return await onChange(target);
}
}

View file

@ -11,8 +11,7 @@ module.exports.getElementByName = getElementByName;
function getElementByName(selector, element) {
const str = `[data-name="js-${selector}"]`;
return element
.querySelector(str);
return element.querySelector(str);
}
module.exports.getName = (element) => {
@ -40,7 +39,7 @@ module.exports.convert = (config) => {
function setState(state) {
if (state)
return ' checked';
return '';
}
@ -74,4 +73,3 @@ module.exports.setValue = (name, value, element) => {
break;
}
};

View file

@ -39,4 +39,3 @@ function onKey({keyCode}) {
if (keyCode === Key.ESC)
hide();
}

View file

@ -1,7 +1,6 @@
'use strict';
/* global CloudCmd */
CloudCmd.EditFileVim = exports;
const Events = require('../dom/events');
@ -23,8 +22,7 @@ module.exports.init = async () => {
module.exports.show = async () => {
Events.addKey(listener);
const editFile = await CloudCmd.EditFile
.show(ConfigView);
const editFile = await CloudCmd.EditFile.show(ConfigView);
editFile
.getEditor()
@ -38,14 +36,10 @@ function hide() {
}
function listener(event) {
const {
keyCode,
shiftKey,
} = event;
const {keyCode, shiftKey} = event;
if (shiftKey && keyCode === Key.ESC) {
event.preventDefault();
hide();
}
}

View file

@ -1,7 +1,6 @@
'use strict';
/* global CloudCmd, DOM*/
CloudCmd.EditFile = exports;
const Format = require('format-io');
@ -11,10 +10,7 @@ const supermenu = require('supermenu');
const Info = DOM.CurrentInfo;
const {
Dialog,
Images,
} = DOM;
const {Dialog, Images} = DOM;
const {config} = CloudCmd;
@ -65,7 +61,8 @@ module.exports.show = async (options) => {
Images.show.load();
CloudCmd.Edit
CloudCmd
.Edit
.getEditor()
.setOption('keyMap', 'default');
@ -81,7 +78,8 @@ module.exports.show = async (options) => {
setMsgChanged(name);
CloudCmd.Edit
CloudCmd
.Edit
.getEditor()
.setValueFirst(path, data)
.setModeForPath(name)
@ -133,7 +131,8 @@ function setMenu(event) {
},
afterClick: () => {
CloudCmd.Edit
CloudCmd
.Edit
.getEditor()
.focus();
},
@ -151,28 +150,28 @@ function getMenuData() {
const editor = CloudCmd.Edit.getEditor();
return {
'Save Ctrl+S' : () => {
'Save Ctrl+S': () => {
editor.save();
},
'Go To Line Ctrl+G' : () => {
'Go To Line Ctrl+G': () => {
editor.goToLine();
},
'Cut Ctrl+X' : () => {
'Cut Ctrl+X': () => {
editor.cutToClipboard();
},
'Copy Ctrl+C' : () => {
'Copy Ctrl+C': () => {
editor.copyToClipboard();
},
'Paste Ctrl+V' : () => {
'Paste Ctrl+V': () => {
editor.pasteFromClipboard();
},
'Delete Del' : () => {
'Delete Del': () => {
editor.remove('right');
},
'Select All Ctrl+A' : () => {
'Select All Ctrl+A': () => {
editor.selectAll();
},
'Close Esc' : hide,
'Close Esc': hide,
};
}
@ -196,4 +195,3 @@ async function isChanged() {
editor.save();
}

View file

@ -1,7 +1,6 @@
'use strict';
/* global CloudCmd */
CloudCmd.EditNamesVim = exports;
const Events = require('../dom/events');
@ -22,7 +21,8 @@ module.exports.init = async () => {
module.exports.show = () => {
Events.addKey(listener);
CloudCmd.EditNames
CloudCmd
.EditNames
.show(ConfigView)
.getEditor()
.setKeyMap('vim');
@ -35,14 +35,10 @@ function hide() {
}
function listener(event) {
const {
keyCode,
shiftKey,
} = event;
const {keyCode, shiftKey} = event;
if (shiftKey && keyCode === Key.ESC) {
event.preventDefault();
hide();
}
}

View file

@ -1,7 +1,6 @@
'use strict';
/* global CloudCmd, DOM */
CloudCmd.EditNames = exports;
const currify = require('currify');
@ -45,7 +44,8 @@ module.exports.show = (options) => {
DOM.Events.addKey(keyListener);
CloudCmd.Edit
CloudCmd
.Edit
.getEditor()
.setValueFirst('edit-names', names)
.setMode()
@ -65,7 +65,6 @@ async function keyListener(event) {
if (ctrlMeta && event.keyCode === Key.S)
hide();
else if (ctrlMeta && event.keyCode === Key.P) {
const [, pattern] = await Dialog.prompt('Apply pattern:', '[n][e]');
pattern && applyPattern(pattern);
@ -107,7 +106,8 @@ function applyNames() {
const root = CloudCmd.config('root');
Promise.resolve(root)
Promise
.resolve(root)
.then(rename(dir, from, to))
.then(refresh(to, nameIndex))
.catch(alert);
@ -115,7 +115,9 @@ function applyNames() {
function _refresh(to, nameIndex, res) {
if (res.status === 404)
return res.text().then(reject);
return res
.text()
.then(reject);
const currentName = to[nameIndex];
@ -127,7 +129,7 @@ function _refresh(to, nameIndex, res) {
function getDir(root, dir) {
if (root === '/')
return dir;
return root + dir;
}
@ -158,6 +160,7 @@ function setMenu(event) {
return;
const editor = CloudCmd.Edit.getEditor();
const options = {
beforeShow: (params) => {
params.x -= 18;
@ -170,29 +173,29 @@ function setMenu(event) {
};
const menuData = {
'Save Ctrl+S' : () => {
'Save Ctrl+S': () => {
applyNames();
hide();
},
'Go To Line Ctrl+G' : () => {
'Go To Line Ctrl+G': () => {
editor.goToLine();
},
'Cut Ctrl+X' : () => {
'Cut Ctrl+X': () => {
editor.cutToClipboard();
},
'Copy Ctrl+C' : () => {
'Copy Ctrl+C': () => {
editor.copyToClipboard();
},
'Paste Ctrl+V' : () => {
'Paste Ctrl+V': () => {
editor.pasteFromClipboard();
},
'Delete Del' : () => {
'Delete Del': () => {
editor.remove('right');
},
'Select All Ctrl+A' : () => {
'Select All Ctrl+A': () => {
editor.selectAll();
},
'Close Esc' : hide,
'Close Esc': hide,
};
const element = CloudCmd.Edit.getElement();
@ -215,4 +218,3 @@ async function isChanged() {
const [, names] = await Dialog.confirm(msg);
names && applyNames();
}

View file

@ -33,7 +33,7 @@ const ConfigView = {
module.exports.init = async () => {
const element = create();
await CloudCmd.View();
await loadFiles(element);
};
@ -47,9 +47,9 @@ function create() {
`,
notAppend: true,
});
Element = element;
return element;
}
@ -63,30 +63,29 @@ function initConfig(options = {}) {
...options,
...ConfigView,
};
if (!options.afterShow)
return config;
checkFn('options.afterShow', options.afterShow);
config.afterShow = () => {
ConfigView.afterShow();
options.afterShow();
};
return config;
}
module.exports.show = (options) => {
if (Loading)
return;
CloudCmd.View.show(Element, initConfig(options));
getEditor()
.setOptions({
fontSize: 16,
});
getEditor().setOptions({
fontSize: 16,
});
};
module.exports.getEditor = getEditor;
@ -106,11 +105,11 @@ const loadFiles = async (element) => {
const socketPath = CloudCmd.prefix;
const prefixSocket = `${CloudCmd.prefixSocket}/${EditorName}`;
const url = `${prefix}/${EditorName}.js`;
time(`${Name} load`);
await loadJS(url);
const word = promisify(window[EditorName]);
const [ed] = await tryToCatch(word, element, {
maxSize,
@ -118,9 +117,8 @@ const loadFiles = async (element) => {
prefixSocket,
socketPath,
});
timeEnd(`${Name} load`);
editor = ed;
Loading = false;
};

View file

@ -1,7 +1,6 @@
'use strict';
/* global CloudCmd */
CloudCmd.Help = exports;
const Images = require('../dom/images');
@ -17,15 +16,12 @@ function show() {
const positionLoad = 'top';
const relative = true;
CloudCmd
.Markdown
.show('/HELP.md', {
positionLoad,
relative,
});
CloudCmd.Markdown.show('/HELP.md', {
positionLoad,
relative,
});
}
function hide() {
CloudCmd.View.hide();
}

View file

@ -4,7 +4,6 @@
/* global Util */
/* global DOM */
/* global Console */
CloudCmd.Konsole = exports;
const exec = require('execon');
@ -14,10 +13,7 @@ const loadJS = require('load.js').js;
const createElement = require('@cloudcmd/create-element');
const Images = require('../dom/images');
const {
Dialog,
CurrentInfo:Info,
} = DOM;
const {Dialog, CurrentInfo: Info} = DOM;
const rmLastSlash = (a) => a.replace(/\/$/, '') || '/';
@ -147,4 +143,3 @@ const load = async () => {
cancel: false,
});
};

View file

@ -1,7 +1,6 @@
'use strict';
/* global CloudCmd */
CloudCmd.Markdown = exports;
const createElement = require('@cloudcmd/create-element');
@ -22,10 +21,7 @@ module.exports.hide = () => {
};
async function show(name, options = {}) {
const {
positionLoad,
relative,
} = options;
const {positionLoad, relative} = options;
Images.show.load(positionLoad);
@ -41,6 +37,7 @@ async function show(name, options = {}) {
});
const className = 'help';
const div = createElement('div', {
className,
innerHTML,
@ -48,4 +45,3 @@ async function show(name, options = {}) {
CloudCmd.View.show(div);
}

View file

@ -11,10 +11,7 @@ const {FS} = require('../../common/cloudfunc');
const {getIdBySrc} = require('../dom/load');
const RESTful = require('../dom/rest');
const {
config,
Key,
} = CloudCmd;
const {config, Key} = CloudCmd;
const {
Buffer,
@ -36,15 +33,16 @@ module.exports.ENABLED = false;
CloudCmd.Menu = exports;
module.exports.init = () => {
const {
isAuth,
menuDataFile,
} = getFileMenuData();
const {isAuth, menuDataFile} = getFileMenuData();
const fm = DOM.getFM();
const menuData = getMenuData(isAuth);
const options = getOptions({type: 'context'});
const optionsFile = getOptions({type: 'file'});
const options = getOptions({
type: 'context',
});
const optionsFile = getOptions({
type: 'file',
});
MenuContext = supermenu(fm, options, menuData);
MenuContextFile = supermenu(fm, optionsFile, menuDataFile);
@ -77,7 +75,7 @@ function getPosition(position) {
x: position.x,
y: position.y,
};
return getCurrentPosition();
}
@ -105,9 +103,9 @@ function getOptions({type}) {
}
const options = {
icon : true,
beforeClose : Key.setBind,
beforeShow : exec.with(beforeShow, func),
icon: true,
beforeClose: Key.setBind,
beforeShow: exec.with(beforeShow, func),
beforeClick,
name,
};
@ -252,7 +250,9 @@ function uploadFromCloud() {
if (e)
return;
await CloudCmd.refresh({currentName});
await CloudCmd.refresh({
currentName,
});
});
}
@ -292,7 +292,7 @@ function download(type) {
src = prefixURL + FS + encodedPath + '?download';
const element = createElement('iframe', {
id : id + '-' + date,
id: id + '-' + date,
async: false,
className: 'hidden',
src,
@ -321,10 +321,7 @@ function getCurrentPosition() {
}
function listener(event) {
const {
F9,
ESC,
} = Key;
const {F9, ESC} = Key;
const key = event.keyCode;
const isBind = Key.isBind();

View file

@ -3,7 +3,6 @@
module.exports = (operation, from, to) => {
if (!to)
return `${operation} ${from}`;
return `${operation} ${from} -> ${to}`;
};

View file

@ -16,4 +16,3 @@ module.exports = (currentName, names, removedNames) => {
return nextNames[length - 1];
};

View file

@ -20,6 +20,7 @@ const getNextCurrentName = require('./get-next-current-name');
const removeQuery = (a) => a.replace(/\?.*/, '');
const Name = 'Operation';
CloudCmd[Name] = exports;
const {config} = CloudCmd;
@ -61,10 +62,7 @@ module.exports.init = promisify((callback) => {
if (config('dropbox'))
return callback();
const {
prefix,
prefixSocket,
} = CloudCmd;
const {prefix, prefixSocket} = CloudCmd;
await loadAll();
await initOperations(prefix, prefixSocket, callback);
@ -94,7 +92,10 @@ const onConnect = currify((fn, operator) => {
async function initOperations(prefix, socketPrefix, fn) {
socketPrefix = `${socketPrefix}/fileop`;
const operator = await fileop({prefix, socketPrefix});
const operator = await fileop({
prefix,
socketPrefix,
});
operator.on('connect', authCheck(operator, onConnect(fn)));
}
@ -109,7 +110,8 @@ function setOperations(operator) {
to,
});
operator.tar(from, to, names)
operator
.tar(from, to, names)
.then(listen);
};
@ -123,7 +125,8 @@ function setOperations(operator) {
to,
});
operator.zip(from, to, names)
operator
.zip(from, to, names)
.then(listen);
};
@ -137,7 +140,8 @@ function setOperations(operator) {
from,
});
operator.remove(from, files)
operator
.remove(from, files)
.then(listen);
};
@ -151,7 +155,8 @@ function setOperations(operator) {
names,
});
operator.copy(from, to, names)
operator
.copy(from, to, names)
.then(listen);
};
@ -164,7 +169,8 @@ function setOperations(operator) {
to,
});
operator.move(from, to, names)
operator
.move(from, to, names)
.then(listen);
};
@ -178,7 +184,8 @@ function setOperations(operator) {
to,
});
operator.extract(from, to)
operator
.extract(from, to)
.then(listen);
};
}
@ -186,7 +193,7 @@ function setOperations(operator) {
function getPacker(type) {
if (type === 'zip')
return packZipFn;
return packTarFn;
}
@ -274,6 +281,7 @@ async function promptDelete() {
const type = getType(isDir) + ' ';
const name = DOM.getCurrentName(current);
msg = msgAsk + msgSel + type + name + '?';
}
@ -333,20 +341,19 @@ async function _processFiles(options, data) {
let names = [];
/* eslint no-multi-spaces: 0 */
if (data) {
from = data.from;
to = data.to;
names = data.names;
panel = Info.panel;
from = data.from;
to = data.to;
names = data.names;
panel = Info.panel;
} else {
from = Info.dirPath;
to = DOM.getNotCurrentDirPath();
selFiles = DOM.getSelectedFiles();
names = DOM.getFilenames(selFiles);
data = {};
shouldAsk = true;
panel = Info.panelPassive;
from = Info.dirPath;
to = DOM.getNotCurrentDirPath();
selFiles = DOM.getSelectedFiles();
names = DOM.getFilenames(selFiles);
data = {};
shouldAsk = true;
panel = Info.panelPassive;
}
if (!names.length)
@ -383,10 +390,14 @@ async function _processFiles(options, data) {
if (ok && !shouldAsk || !sameName)
return go();
const str = `"${ name }" already exist. Overwrite?`;
const str = `"${name}" already exist. Overwrite?`;
const cancel = false;
Dialog.confirm(str, {cancel}).then(go);
Dialog
.confirm(str, {
cancel,
})
.then(go);
function go() {
showLoad();
@ -400,10 +411,7 @@ async function _processFiles(options, data) {
operation(files, async () => {
await DOM.Storage.remove(from);
const {
panel,
panelPassive,
} = Info;
const {panel, panelPassive} = Info;
if (!Info.isOnePanel)
CloudCmd.refresh({
@ -429,10 +437,7 @@ function twopack(operation, type) {
let fileFrom;
let currentName = Info.name;
const {
path,
dirPath,
} = Info;
const {path, dirPath} = Info;
const activeFiles = DOM.getActiveFiles();
const names = DOM.getFilenames(activeFiles);
@ -446,7 +451,7 @@ function twopack(operation, type) {
case 'extract':
op = extractFn;
fileFrom = {
fileFrom = {
from: path,
to: dirPath,
};
@ -459,7 +464,7 @@ function twopack(operation, type) {
op = getPacker(type);
if (names.length > 1)
currentName = Info.dir;
currentName = Info.dir;
currentName += DOM.getPackerExt(type);
@ -487,9 +492,9 @@ async function prompt(msg, to, names) {
msg += ' ';
if (names.length > 1)
msg += `${n} file(s)`;
msg += `${n} file(s)`;
else
msg += `"${name}"`;
msg += `"${name}"`;
msg += ' to';
@ -507,4 +512,3 @@ async function loadAll() {
Loaded = true;
}

View file

@ -17,4 +17,3 @@ function getExtension(name) {
return getExt(name);
}

View file

@ -26,4 +26,3 @@ test('cloudcmd: client: modules: operation: removeExtension: .bz2', (t) => {
t.equal(removeExtension(fullName), name, 'should remove .bz2');
t.end();
});

View file

@ -1,16 +1,12 @@
'use strict';
/* global DOM */
const forEachKey = require('for-each-key');
const wraptile = require('wraptile');
const format = require('./format');
const {
Dialog,
Images,
} = DOM;
const {Dialog, Images} = DOM;
module.exports = (options) => (emitter) => {
const {
@ -28,6 +24,7 @@ module.exports = (options) => (emitter) => {
emitter.abort();
const msg = `${operation} aborted`;
lastError = true;
Dialog.alert(msg, {
@ -85,4 +82,3 @@ module.exports = (options) => (emitter) => {
forEachKey(on, listeners);
};

View file

@ -1,11 +1,10 @@
'use strict';
/* global DOM */
require('domtokenlist-shim');
const scrollIntoViewIfNeeded = require('scroll-into-view-if-needed').default;
DOM.scrollIntoViewIfNeeded = (el) => scrollIntoViewIfNeeded(el, {
block: 'nearest',
});

View file

@ -1,9 +1,7 @@
'use strict';
const {
test,
stub,
} = require('supertape');
const {test, stub} = require('supertape');
const mockRequire = require('mock-require');
const {stopAll} = mockRequire;
@ -25,10 +23,9 @@ test('cloudcmd: client: polyfill: scrollIntoViewIfNeaded', (t) => {
mockRequire.stop('scroll-into-view-if-neaded');
global.DOM = DOM;
const args = [
el, {
block: 'nearest',
}];
const args = [el, {
block: 'nearest',
}];
stopAll();

View file

@ -1,7 +1,6 @@
'use strict';
/* global CloudCmd, gritty */
const {promisify} = require('es6-promisify');
const tryToCatch = require('try-to-catch');
const fullstore = require('fullstore');
@ -14,10 +13,7 @@ const DOM = require('../dom');
const Images = require('../dom/images');
const {Dialog} = DOM;
const {
Key,
config,
} = CloudCmd;
const {Key, config} = CloudCmd;
CloudCmd.TerminalRun = exports;
@ -152,4 +148,3 @@ function authCheck(spawn) {
Dialog.alert('Wrong credentials!');
});
}

View file

@ -2,7 +2,6 @@
/* global CloudCmd */
/* global gritty */
const tryToCatch = require('try-to-catch');
require('../../css/terminal.css');
@ -15,10 +14,7 @@ const Images = require('../dom/images');
const loadParallel = load.parallel;
const {Dialog} = DOM;
const {
Key,
config,
} = CloudCmd;
const {Key, config} = CloudCmd;
CloudCmd.Terminal = exports;
@ -123,4 +119,3 @@ function show() {
},
});
}

View file

@ -66,4 +66,3 @@ function afterShow() {
uploadFiles(files);
});
}

View file

@ -8,4 +8,3 @@ module.exports = (menuFn) => {
return module.exports;
};

View file

@ -18,4 +18,3 @@ test('user-menu: getUserMenu', (t) => {
t.equal(key, 'F2 - Rename file');
t.end();
});

View file

@ -1,7 +1,6 @@
'use strict';
/* global CloudCmd, DOM */
require('../../../css/user-menu.css');
const currify = require('currify');
@ -25,6 +24,7 @@ const loadCSS = load.css;
const sourceStore = fullstore();
const Name = 'UserMenu';
CloudCmd[Name] = module.exports;
const {Key} = CloudCmd;
@ -52,7 +52,10 @@ async function show() {
Images.hide();
if (error)
return Dialog.alert(getCodeFrame({error, source}));
return Dialog.alert(getCodeFrame({
error,
source,
}));
sourceStore(source);
@ -118,10 +121,7 @@ const onButtonClick = wraptile(async (items, {value}) => {
});
const onKeyDown = currify(async ({keys, userMenu}, e) => {
const {
keyCode,
target,
} = e;
const {keyCode, target} = e;
const keyName = e.key.toUpperCase();
@ -156,6 +156,7 @@ const runUserMenu = async (fn) => {
return;
const source = sourceStore();
return Dialog.alert(getCodeFrame({
error,
source,
@ -169,6 +170,7 @@ function getCodeFrame({error, source}) {
return error.message;
const [line, column] = parseError(error);
const start = {
line,
column,
@ -185,4 +187,3 @@ function getCodeFrame({error, source}) {
return `<pre>${frame}</pre>`;
}

View file

@ -16,43 +16,42 @@ module.exports = (el, {key, keyCode}) => {
if (isDigit(key)) {
store(Number(key));
}
if (keyCode === DOWN || keyCode === J) {
const count = store();
store(1);
return down(el, count);
}
if (keyCode === UP || keyCode === K) {
const count = store();
store(1);
return up(el, count);
}
};
function down(el, count) {
const {length} = el;
if (el.selectedIndex === length - 1)
el.selectedIndex = 0;
else
el.selectedIndex += count;
if (el.selectedIndex < 0)
el.selectedIndex = length - 1;
}
function up(el, count) {
const {length} = el;
if (!el.selectedIndex)
el.selectedIndex = length - 1;
else
el.selectedIndex -= count;
if (el.selectedIndex < 0)
el.selectedIndex = 0;
}

View file

@ -15,11 +15,11 @@ test('cloudcmd: user-menu: navigate: DOWN', (t) => {
length: 3,
selectedIndex: 0,
};
navigate(el, {
keyCode: DOWN,
});
t.equal(el.selectedIndex, 1);
t.end();
});
@ -29,11 +29,11 @@ test('cloudcmd: user-menu: navigate: J', (t) => {
length: 3,
selectedIndex: 0,
};
navigate(el, {
keyCode: J,
});
t.equal(el.selectedIndex, 1);
t.end();
});
@ -43,11 +43,11 @@ test('cloudcmd: user-menu: navigate: DOWN: bottom', (t) => {
length: 3,
selectedIndex: 2,
};
navigate(el, {
keyCode: DOWN,
});
t.equal(el.selectedIndex, 0);
t.end();
});
@ -57,11 +57,11 @@ test('cloudcmd: user-menu: navigate: K', (t) => {
length: 3,
selectedIndex: 2,
};
navigate(el, {
keyCode: K,
});
t.equal(el.selectedIndex, 1);
t.end();
});
@ -71,11 +71,11 @@ test('cloudcmd: user-menu: navigate: UP', (t) => {
length: 3,
selectedIndex: 2,
};
navigate(el, {
keyCode: UP,
});
t.equal(el.selectedIndex, 1);
t.end();
});
@ -85,11 +85,11 @@ test('cloudcmd: user-menu: navigate: UP: top', (t) => {
length: 3,
selectedIndex: 0,
};
navigate(el, {
keyCode: UP,
});
t.equal(el.selectedIndex, 2);
t.end();
});
@ -99,11 +99,11 @@ test('cloudcmd: user-menu: navigate', (t) => {
length: 3,
selectedIndex: 0,
};
navigate(el, {
keyCode: 0,
});
t.equal(el.selectedIndex, 0, 'should not change');
t.end();
});
@ -113,16 +113,16 @@ test('cloudcmd: user-menu: navigate: DOWN: count', (t) => {
length: 3,
selectedIndex: 0,
};
navigate(el, {
keyCode: 53,
key: '5',
});
navigate(el, {
keyCode: DOWN,
});
t.equal(el.selectedIndex, 5);
t.end();
});
@ -132,16 +132,16 @@ test('cloudcmd: user-menu: navigate: J: count: to big', (t) => {
length: 3,
selectedIndex: -Infinity,
};
navigate(el, {
keyCode: 53,
key: '5',
});
navigate(el, {
keyCode: J,
});
t.equal(el.selectedIndex, 2);
t.end();
});
@ -151,16 +151,16 @@ test('cloudcmd: user-menu: navigate: K: count: to small', (t) => {
length: 3,
selectedIndex: -Infinity,
};
navigate(el, {
keyCode: 53,
key: '5',
});
navigate(el, {
keyCode: K,
});
t.equal(el.selectedIndex, 0);
t.end();
});

View file

@ -3,17 +3,11 @@
const isNumber = (a) => typeof a === 'number';
module.exports = (error) => {
const {
lineNumber,
columnNumber,
} = error;
const {lineNumber, columnNumber} = error;
// thank you firefox
if (isNumber(lineNumber) && isNumber(columnNumber))
return [
lineNumber,
columnNumber,
];
return [lineNumber, columnNumber];
const before = error.stack.indexOf('>');
const str = error.stack.slice(before + 1);
@ -27,4 +21,3 @@ module.exports = (error) => {
Number(column),
];
};

View file

@ -24,7 +24,9 @@ test('user-menu: parse-error: stack', (t) => {
at AsyncFunction.show (index.js:67)
`;
const result = parseError({stack});
const result = parseError({
stack,
});
const expected = [1, 2];
t.deepEqual(result, expected);

View file

@ -32,4 +32,3 @@ module.exports = (userMenu) => {
settings,
};
};

View file

@ -1,9 +1,7 @@
'use strict';
const {
test,
stub,
} = require('supertape');
const {test, stub} = require('supertape');
const parse = require('./parse-user-menu');
test('cloudcmd: user menu: parse', (t) => {
@ -15,7 +13,10 @@ test('cloudcmd: user menu: parse', (t) => {
'_f': fn,
});
const names = ['F2 - Rename file'];
const names = [
'F2 - Rename file',
];
const keys = {
F2: fn,
};

View file

@ -5,4 +5,3 @@ module.exports.runSelected = async (selectedItems, items, runUserMenu) => {
await runUserMenu(items[selected]);
}
};

View file

@ -1,17 +1,13 @@
'use strict';
const {
test,
stub,
} = require('supertape');
const {test, stub} = require('supertape');
const {runSelected} = require('./run');
test('cloudcmd: client: user menu: run', async (t) => {
const runUserMenu = stub();
const fn = stub();
const selected = [
'hello',
];
const selected = ['hello'];
const items = {
hello: fn,
@ -22,4 +18,3 @@ test('cloudcmd: client: user menu: run', async (t) => {
t.calledWith(runUserMenu, [fn]);
t.end();
});

View file

@ -1,7 +1,7 @@
'use strict';
/* global CloudCmd, DOM */
'use strict';
require('../../../css/view.css');
const rendy = require('rendy');
@ -15,6 +15,7 @@ const createElement = require('@cloudcmd/create-element');
const {time} = require('../../../common/util');
const {FS} = require('../../../common/cloudfunc');
const {
isImage,
isAudio,
@ -49,6 +50,7 @@ module.exports.hide = hide;
let Loading = false;
const Name = 'View';
CloudCmd[Name] = module.exports;
const Info = DOM.CurrentInfo;
@ -64,84 +66,88 @@ const Config = {
Images.hide();
Key.unsetBind();
},
beforeClose: () => {
Events.rmKey(listener);
Key.setBind();
},
afterShow: () => {
El.focus();
},
onOverlayClick,
afterClose: noop,
autoSize: false,
helpers: {
title: {},
},
};
module.exports._Config = Config;
module.exports.init = async () => {
await loadAll();
const events = [
'click',
'contextmenu',
];
events.forEach(addEvent(Overlay, onOverlayClick));
events.forEach(addEvent(
Overlay,
onOverlayClick,
));
};
async function show(data, options = {}) {
const prefixURL = CloudCmd.prefixURL + FS;
if (Loading)
return;
if (!options || options.bindKeys !== false)
Events.addKey(listener);
El = createElement('div', {
className: 'view',
notAppend: true,
});
El.tabIndex = 0;
if (data) {
if (isArray(data))
El.append(...data);
else
El.append(data);
modal.open(El, initConfig(options));
return;
}
Images.show.load();
const path = prefixURL + Info.path;
const type = options.raw ? '' : await getType(path);
switch(type) {
default:
return await viewFile();
case 'markdown':
return await CloudCmd.Markdown.show(Info.path);
case 'html':
return viewHtml(path);
case 'image':
return viewImage(Info.path, prefixURL);
case 'media':
return await viewMedia(path);
case 'pdf':
return viewPDF(path);
}
@ -154,11 +160,11 @@ function createIframe(src) {
width: '100%',
height: '100%',
});
element.addEventListener('load', () => {
element.contentWindow.addEventListener('keydown', listener);
});
return element;
}
@ -169,21 +175,21 @@ function viewHtml(src) {
function viewPDF(src) {
const element = createIframe(src);
const options = assign({}, Config);
if (CloudCmd.config('showFileName'))
options.title = Info.name;
modal.open(element, options);
}
async function viewMedia(path) {
const [e, element] = await getMediaElement(path);
if (e)
return alert(e);
const allConfig = {
...Config,
...{
@ -195,22 +201,22 @@ async function viewMedia(path) {
},
},
};
modal.open(element, allConfig);
}
async function viewFile() {
const [error, data] = await Info.getData();
if (error)
return Images.hide();
const element = document.createTextNode(data);
const options = Config;
if (CloudCmd.config('showFileName'))
options.title = Info.name;
El.append(element);
modal.open(El, options);
}
@ -220,25 +226,26 @@ const copy = (a) => assign({}, a);
module.exports._initConfig = initConfig;
function initConfig(options) {
const config = copy(Config);
if (!options)
return config;
const names = Object.keys(options);
for (const name of names) {
const isConfig = Boolean(config[name]);
const item = options[name];
if (!isFn(item) || !isConfig) {
config[name] = options[name];
continue;
}
const fn = config[name];
config[name] = series(fn, item);
}
return config;
}
@ -252,59 +259,60 @@ function viewImage(path, prefixURL) {
href: `${prefixURL}${path}`,
title: encode(basename(path)),
});
const names = Info.files
const names = Info
.files
.map(DOM.getCurrentPath)
.filter(isSupportedImage);
const titles = names
.map(makeTitle);
const titles = names.map(makeTitle);
const index = names.indexOf(Info.path);
const imageConfig = {
index,
autoSize : true,
arrows : true,
keys : true,
helpers : {
title : {},
autoSize: true,
arrows: true,
keys: true,
helpers: {
title: {},
},
};
const config = {
...Config,
...imageConfig,
};
modal.open(titles, config);
}
async function getMediaElement(src) {
check(src);
const [error, template] = await tryToCatch(Files.get, 'view/media-tmpl');
if (error)
return [error];
const {name} = Info;
if (!TemplateAudio)
TemplateAudio = template;
const is = isAudio(name);
const type = is ? 'audio' : 'video';
const innerHTML = rendy(TemplateAudio, {
src,
type,
name,
});
const element = createElement('div', {
innerHTML,
});
return [null, element];
}
@ -319,9 +327,9 @@ function check(src) {
*/
async function loadAll() {
const {DIR_DIST} = CloudCmd;
time(`${Name} load`);
Loading = true;
await loadCSS(`${DIR_DIST}/view.css`);
Loading = false;
@ -332,32 +340,29 @@ function onOverlayClick(event) {
x: event.clientX,
y: event.clientY,
};
setCurrentByPosition(position);
}
function setCurrentByPosition(position) {
const element = DOM.getCurrentByPosition(position);
if (!element)
return;
const {
files,
filesPassive,
} = Info;
const {files, filesPassive} = Info;
const isFiles = files.includes(element);
const isFilesPassive = filesPassive.includes(element);
if (!isFiles && !isFilesPassive)
return;
const isCurrent = DOM.isCurrentFile(element);
if (isCurrent)
return;
DOM.setCurrentFile(element);
}
@ -365,4 +370,3 @@ function listener({keyCode}) {
if (keyCode === Key.ESC)
hide();
}

View file

@ -64,12 +64,10 @@ test('cloudcmd: client: view: html', (t) => {
open,
});
const {
_viewHtml,
_Config,
} = reRequire('.');
const {_viewHtml, _Config} = reRequire('.');
const src = '/hello.html';
_viewHtml(src);
global.CloudCmd = CloudCmd;
@ -89,6 +87,7 @@ test('cloudcmd: client: view: createIframe', (t) => {
const el = {
addEventListener,
};
const createElement = stub().returns(el);
mockRequire('@cloudcmd/create-element', createElement);
@ -114,6 +113,7 @@ test('cloudcmd: client: view: createIframe: returns', (t) => {
const el = {
addEventListener,
};
const createElement = stub().returns(el);
mockRequire('@cloudcmd/create-element', createElement);

View file

@ -69,9 +69,10 @@ async function detectType(path) {
for (const [name, value] of headers) {
if (name === 'content-type')
return `.${value.split('/').pop()}`;
return `.${value
.split('/')
.pop()}`;
}
return '';
}

View file

@ -23,15 +23,14 @@ test('cloudcmd: client: view: types: detectType', async (t) => {
});
const originalFetch = global.fetch;
global.fetch = fetch;
await _detectType('/hello');
global.fetch = originalFetch;
const expected = [
'/hello', {
method: 'HEAD',
},
];
const expected = ['/hello', {
method: 'HEAD',
}];
t.calledWith(fetch, expected);
t.end();
@ -39,6 +38,7 @@ test('cloudcmd: client: view: types: detectType', async (t) => {
test('cloudcmd: client: view: types: detectType: found', async (t) => {
const originalFetch = global.fetch;
global.fetch = stub().returns({
headers: [
['content-type', 'image/png'],
@ -51,4 +51,3 @@ test('cloudcmd: client: view: types: detectType: found', async (t) => {
t.equal(result, '.png');
t.end();
});