diff --git a/.putout.json b/.putout.json index 569397a7..534fc0a9 100644 --- a/.putout.json +++ b/.putout.json @@ -1,4 +1,7 @@ { + "plugins": [ + "cloudcmd" + ], "ignore": [ "html", "fixture*", diff --git a/client/client.js b/client/client.js index 0c2ef983..f779cf83 100644 --- a/client/client.js +++ b/client/client.js @@ -77,28 +77,8 @@ function CloudCmdProto(DOM) { right: 'asc', }; - /** - * Функция привязываеться ко всем ссылкам и - * загружает содержимое каталогов - * - * @param params - { - * paramLink - ссылка - * needRefresh - необходимость обязательной загрузки данных с сервера - * panel - * } - * @param callback - */ - this.loadDir = async (params) => { - const p = params; - const refresh = p.isRefresh; - - const { - panel, - history = true, - noCurrent, - currentName, - } = p; - + this.changeDir = async (path, {isRefresh, panel, history = true, noCurrent, currentName} = {}) => { + const refresh = isRefresh; let panelChanged; if (!noCurrent && panel && panel !== Info.panel) { @@ -112,10 +92,9 @@ function CloudCmdProto(DOM) { imgPosition = 'top'; Images.show.load(imgPosition, panel); - const path = addSlashToEnd(p.path); /* загружаем содержимое каталога */ - await ajaxLoad(path, { + await ajaxLoad(addSlashToEnd(path), { refresh, history, noCurrent, @@ -302,8 +281,7 @@ function CloudCmdProto(DOM) { const history = false; const noCurrent = options ? options.noCurrent : false; - await CloudCmd.loadDir({ - path, + await CloudCmd.changeDir(path, { isRefresh, history, panel, @@ -455,9 +433,7 @@ function CloudCmdProto(DOM) { const path = parentDirPath; - await CloudCmd.loadDir({ - path, - }); + await CloudCmd.changeDir(path); const current = DOM.getCurrentByName(dir); const [first] = DOM.getFiles(panel); diff --git a/client/dom/index.js b/client/dom/index.js index 31300a29..42424d16 100644 --- a/client/dom/index.js +++ b/client/dom/index.js @@ -719,9 +719,7 @@ module.exports.goToDirectory = async () => { if (cancel) return; - await CloudCmd.loadDir({ - path, - }); + await CloudCmd.changeDir(path); }; module.exports.duplicatePanel = async () => { @@ -739,8 +737,7 @@ module.exports.duplicatePanel = async () => { const path = getPath(isDir); - await CloudCmd.loadDir({ - path, + await CloudCmd.changeDir(path, { panel, noCurrent, }); @@ -760,14 +757,12 @@ module.exports.swapPanels = async () => { let currentIndex = files.indexOf(element); - await CloudCmd.loadDir({ - path, + await CloudCmd.changeDir(path, { panel: panelPassive, noCurrent: true, }); - await CloudCmd.loadDir({ - path: dirPathPassive, + await CloudCmd.changeDir(dirPathPassive, { panel, }); diff --git a/client/dom/index.spec.js b/client/dom/index.spec.js index 64bb51ce..914862a4 100644 --- a/client/dom/index.spec.js +++ b/client/dom/index.spec.js @@ -11,10 +11,10 @@ global.CloudCmd = {}; test('cloudcmd: client: dom: goToDirectory', async (t) => { const path = ''; const {CloudCmd} = global; - const loadDir = stub(); + const changeDir = stub(); const prompt = stub().returns([null, path]); - CloudCmd.loadDir = loadDir; + CloudCmd.changeDir = changeDir; mockRequire('./dialog', { prompt, @@ -26,7 +26,7 @@ test('cloudcmd: client: dom: goToDirectory', async (t) => { stopAll(); - t.calledWith(loadDir, [{path}]); + t.calledWith(changeDir, [path]); t.end(); }); diff --git a/client/key/index.js b/client/key/index.js index 7a45028e..3890121c 100644 --- a/client/key/index.js +++ b/client/key/index.js @@ -133,7 +133,7 @@ async function switchKey(event) { const { Operation, - loadDir, + changeDir, config, } = CloudCmd; const {keyCode} = event; @@ -200,9 +200,7 @@ async function switchKey(event) { event.preventDefault(); if (Info.isDir) - await loadDir({ - path, - }); + await changeDir(path); else if (shift) CloudCmd.View.show(null, { raw: true, @@ -402,7 +400,7 @@ async function switchKey(event) { case KEY.ENTER: if (Info.isDir) - await loadDir({path}); + await changeDir(path); else CloudCmd.View.show(); @@ -415,9 +413,7 @@ async function switchKey(event) { case KEY.BACKSLASH: if (ctrlMeta) - await loadDir({ - path: '/', - }); + await changeDir('/'); break; diff --git a/client/listeners/index.js b/client/listeners/index.js index 040ed0a3..d923c3ed 100644 --- a/client/listeners/index.js +++ b/client/listeners/index.js @@ -212,8 +212,7 @@ async function onPathElementClick(panel, event) { const {href} = element; const path = decodePath(href); - await CloudCmd.loadDir({ - path, + await CloudCmd.changeDir(path, { isRefresh: false, panel: noCurrent ? panel : Info.panel, }); @@ -272,9 +271,7 @@ async function onDblClick(event) { if (!isDir) return CloudCmd.View.show(); - await CloudCmd.loadDir({ - path, - }); + await CloudCmd.changeDir(path); } async function onTouch(event) { @@ -289,9 +286,7 @@ async function onTouch(event) { if (!isCurrent) return; - await CloudCmd.loadDir({ - path: DOM.getCurrentPath(current), - }); + await CloudCmd.changeDir(DOM.getCurrentPath(current)); } /* @@ -472,8 +467,7 @@ function pop() { return CloudCmd.route(location.hash); const history = false; - await CloudCmd.loadDir({ - path, + await CloudCmd.changeDir(path, { history, }); }); diff --git a/client/modules/konsole.js b/client/modules/konsole.js index df143e8d..e52e5910 100644 --- a/client/modules/konsole.js +++ b/client/modules/konsole.js @@ -71,9 +71,7 @@ async function onPath(path) { if (Info.dirPath === path) return; - await CloudCmd.loadDir({ - path, - }); + await CloudCmd.changeDir(path); } const getDirPath = () => { diff --git a/package.json b/package.json index 6a92c322..65df3ce3 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,7 @@ "@cloudcmd/move-files": "^6.0.0", "@cloudcmd/read-files-sync": "^2.0.0", "@putout/cli-validate-args": "^1.0.1", - "@putout/plugin-cloudcmd": "^1.2.0", + "@putout/plugin-cloudcmd": "^2.0.0", "apart": "^2.0.0", "chalk": "^4.0.0", "compression": "^1.7.4",