feature: client: dom: cmd: move out

This commit is contained in:
coderiaser 2026-01-29 14:51:15 +02:00
parent 5a2aa70f90
commit 9d2c4e4a0d
2 changed files with 89 additions and 77 deletions

85
client/dom/cmd.mjs Normal file
View file

@ -0,0 +1,85 @@
/* global DOM */
const SELECTED_FILE = 'selected-file';
const Cmd = {
getSelectedFiles,
isSelected,
unselectFile,
selectFile,
selectAllFiles,
toggleSelectedFile,
toggleAllSelectedFiles,
};
/**
* selected file check
*
* @param currentFile
*/
export function isSelected(currentFile) {
if (!currentFile)
return false;
return DOM.isContainClass(currentFile, SELECTED_FILE);
}
/**
* select current file
* @param currentFile
*/
export function selectFile(currentFile) {
const current = currentFile || DOM.getCurrentFile();
current.classList.add(SELECTED_FILE);
return Cmd;
}
export function unselectFile(currentFile) {
const current = currentFile || DOM.getCurrentFile();
current.classList.remove(SELECTED_FILE);
return Cmd;
}
export function toggleSelectedFile(currentFile) {
const current = currentFile || DOM.getCurrentFile();
const name = DOM.getCurrentName(current);
if (name === '..')
return Cmd;
current.classList.toggle(SELECTED_FILE);
return Cmd;
}
export function toggleAllSelectedFiles() {
DOM
.getAllFiles()
.map(DOM.toggleSelectedFile);
return Cmd;
}
export function selectAllFiles() {
DOM
.getAllFiles()
.map(DOM.selectFile);
return Cmd;
}
/**
* unified way to get selected files
*
* @currentFile
*/
export function getSelectedFiles() {
const panel = DOM.getPanel();
const selected = DOM.getByClassAll(SELECTED_FILE, panel);
return Array.from(selected);
}

View file

@ -11,7 +11,7 @@ const renameCurrent = require('./operations/rename-current');
const CurrentFile = require('./current-file.mjs');
const DOMTree = require('./dom-tree.mjs');
const Cmd = module.exports;
const Cmd = require('./cmd.mjs');
const DOM = {
...DOMTree,
...CurrentFile,
@ -47,7 +47,6 @@ DOM.Events = Events;
const _loadRemote = require('./load-remote');
const selectByPattern = require('./select-by-pattern');
const isString = (a) => typeof a === 'string';
const SELECTED_FILE = 'selected-file';
const TabPanel = {
'js-left': null,
@ -118,7 +117,7 @@ async function promptNew(typeName) {
}
/**
* get current direcotory name
* get current directory name
*/
module.exports.getCurrentDirName = () => {
const href = DOM
@ -131,7 +130,7 @@ module.exports.getCurrentDirName = () => {
};
/**
* get current direcotory path
* get current directory path
*/
module.exports.getParentDirPath = (panel) => {
const path = DOM.getCurrentDirPath(panel);
@ -145,7 +144,7 @@ module.exports.getParentDirPath = (panel) => {
};
/**
* get not current direcotory path
* get not current directory path
*/
module.exports.getNotCurrentDirPath = () => {
const panel = DOM.getPanel({
@ -155,18 +154,6 @@ module.exports.getNotCurrentDirPath = () => {
return DOM.getCurrentDirPath(panel);
};
/**
* unified way to get selected files
*
* @currentFile
*/
module.exports.getSelectedFiles = () => {
const panel = DOM.getPanel();
const selected = DOM.getByClassAll(SELECTED_FILE, panel);
return Array.from(selected);
};
/*
* unselect all files
*/
@ -340,54 +327,6 @@ module.exports.getRefreshButton = (panel = DOM.getPanel()) => {
return DOM.getByDataName('js-refresh', panel);
};
/**
* select current file
* @param currentFile
*/
module.exports.selectFile = (currentFile) => {
const current = currentFile || DOM.getCurrentFile();
current.classList.add(SELECTED_FILE);
return Cmd;
};
module.exports.unselectFile = (currentFile) => {
const current = currentFile || DOM.getCurrentFile();
current.classList.remove(SELECTED_FILE);
return Cmd;
};
module.exports.toggleSelectedFile = (currentFile) => {
const current = currentFile || DOM.getCurrentFile();
const name = DOM.getCurrentName(current);
if (name === '..')
return Cmd;
current.classList.toggle(SELECTED_FILE);
return Cmd;
};
module.exports.toggleAllSelectedFiles = () => {
DOM
.getAllFiles()
.map(DOM.toggleSelectedFile);
return Cmd;
};
module.exports.selectAllFiles = () => {
DOM
.getAllFiles()
.map(DOM.selectFile);
return Cmd;
};
module.exports.getAllFiles = () => {
const panel = DOM.getPanel();
const files = DOM.getFiles(panel);
@ -436,18 +375,6 @@ module.exports.setHistory = (data, title, url) => {
return ret;
};
/**
* selected file check
*
* @param currentFile
*/
module.exports.isSelected = (currentFile) => {
if (!currentFile)
return false;
return DOM.isContainClass(currentFile, SELECTED_FILE);
};
/**
* get link from current (or param) file
*