feature: client: dom: migrate to ESM

This commit is contained in:
coderiaser 2026-01-29 16:04:43 +02:00
parent 9d2c4e4a0d
commit f9c2831939
20 changed files with 211 additions and 178 deletions

View file

@ -1,12 +1,12 @@
import process from 'node:process'; import process from 'node:process';
import wraptile from 'wraptile'; import wraptile from 'wraptile';
import load from 'load.js'; import load from 'load.js';
import * as Util from '#common/util';
import '../css/main.css'; import '../css/main.css';
import {registerSW, listenSW} from './sw/register.mjs'; import {registerSW, listenSW} from './sw/register.mjs';
import {initSortPanel, sortPanel} from './sort.mjs'; import {initSortPanel, sortPanel} from './sort.mjs';
import Util from '../common/util.js';
import * as CloudFunc from '../common/cloudfunc.mjs'; import * as CloudFunc from '../common/cloudfunc.mjs';
import DOM from './dom/index.js'; import DOM from './dom/index.mjs';
import {createCloudCmd} from './client.mjs'; import {createCloudCmd} from './client.mjs';
import * as Listeners from './listeners/index.mjs'; import * as Listeners from './listeners/index.mjs';

View file

@ -1,5 +1,4 @@
/* global DOM */ /* global DOM */
const SELECTED_FILE = 'selected-file'; const SELECTED_FILE = 'selected-file';
const Cmd = { const Cmd = {
getSelectedFiles, getSelectedFiles,
@ -82,4 +81,3 @@ export function getSelectedFiles() {
return Array.from(selected); return Array.from(selected);
} }

View file

@ -1,29 +1,82 @@
'use strict';
/* global CloudCmd */ /* global CloudCmd */
const Util = require('../../common/util'); import * as load from '#dom/load';
import * as Files from '#dom/files';
import * as Dialog from '#dom/dialog';
import * as Events from '#dom/events';
import {getExt} from '#common/util';
import * as Images from './images.mjs';
import RESTful from './rest.js';
import Storage from './storage.js';
import renameCurrent from './operations/rename-current.js';
import * as CurrentFile from './current-file.mjs';
import * as DOMTree from './dom-tree.mjs';
import * as Cmd from './cmd.mjs';
import IO from './io/index.js';
import {uploadDirectory} from './directory.mjs';
import * as Buffer from './buffer.mjs';
import _loadRemote from './load-remote.js';
import {selectByPattern} from './select-by-pattern.mjs';
const Images = require('./images.mjs'); const {assign} = Object;
const RESTful = require('./rest');
const Storage = require('./storage');
const renameCurrent = require('./operations/rename-current');
const CurrentFile = require('./current-file.mjs');
const DOMTree = require('./dom-tree.mjs');
const Cmd = require('./cmd.mjs');
const DOM = { const DOM = {
getCurrentDirName,
getNotCurrentDirPath,
getParentDirPath,
load,
RESTful,
Storage,
loadRemote,
loadSocket,
promptNewDir,
promptNewFile,
unselectFiles,
getActiveFiles,
getCurrentDate,
getCurrentSize,
loadCurrentSize,
loadCurrentHash,
setCurrentSize,
getCurrentMode,
getCurrentOwner,
getCurrentData,
getRefreshButton,
getAllFiles,
expandSelection,
shrinkSelection,
setHistory,
getCurrentLink,
getFilenames,
checkStorageHash,
saveDataToStorage,
getFM,
getPanelPosition,
getCSSVar,
getPanel,
getFiles,
showPanel,
hidePanel,
remove,
deleteCurrent,
deleteSelected,
renameCurrent,
scrollIntoViewIfNeeded,
scrollByPages,
changePanel,
getPackerExt,
goToDirectory,
duplicatePanel,
swapPanels,
updateCurrentInfo,
};
assign(DOM, {
...DOMTree, ...DOMTree,
...CurrentFile, ...CurrentFile,
...Cmd, ...Cmd,
}; });
const CurrentInfo = {}; export const CurrentInfo = {};
const load = require('#dom/load');
const Files = require('#dom/files');
const IO = require('./io');
const Dialog = require('#dom/dialog');
DOM.Images = Images; DOM.Images = Images;
DOM.load = load; DOM.load = load;
@ -34,18 +87,11 @@ DOM.Storage = Storage;
DOM.Dialog = Dialog; DOM.Dialog = Dialog;
DOM.CurrentInfo = CurrentInfo; DOM.CurrentInfo = CurrentInfo;
module.exports = DOM; export default DOM;
const {uploadDirectory} = require('./directory.mjs');
const Buffer = require('./buffer.mjs');
const Events = require('#dom/events');
DOM.uploadDirectory = uploadDirectory; DOM.uploadDirectory = uploadDirectory;
DOM.Buffer = Buffer; DOM.Buffer = Buffer;
DOM.Events = Events; DOM.Events = Events;
const _loadRemote = require('./load-remote');
const selectByPattern = require('./select-by-pattern');
const isString = (a) => typeof a === 'string'; const isString = (a) => typeof a === 'string';
const TabPanel = { const TabPanel = {
@ -53,26 +99,26 @@ const TabPanel = {
'js-right': null, 'js-right': null,
}; };
module.exports.loadRemote = (name, options, callback) => { export function loadRemote(name, options, callback) {
_loadRemote(name, options, callback); _loadRemote(name, options, callback);
return DOM; return DOM;
}; }
module.exports.loadSocket = (callback) => { export function loadSocket(callback) {
DOM.loadRemote('socket', { DOM.loadRemote('socket', {
name: 'io', name: 'io',
}, callback); }, callback);
return DOM; return DOM;
}; }
/** /**
* create new folder * create new folder
* *
*/ */
module.exports.promptNewDir = async function() { export async function promptNewDir() {
await promptNew('directory'); await promptNew('directory');
}; }
/** /**
* create new file * create new file
@ -80,9 +126,9 @@ module.exports.promptNewDir = async function() {
* @typeName * @typeName
* @type * @type
*/ */
module.exports.promptNewFile = async () => { export async function promptNewFile() {
await promptNew('file'); await promptNew('file');
}; }
async function promptNew(typeName) { async function promptNew(typeName) {
const {Dialog} = DOM; const {Dialog} = DOM;
@ -119,7 +165,7 @@ async function promptNew(typeName) {
/** /**
* get current directory name * get current directory name
*/ */
module.exports.getCurrentDirName = () => { export function getCurrentDirName() {
const href = DOM const href = DOM
.getCurrentDirPath() .getCurrentDirPath()
.replace(/\/$/, ''); .replace(/\/$/, '');
@ -127,12 +173,12 @@ module.exports.getCurrentDirName = () => {
const substr = href.substr(href, href.lastIndexOf('/')); const substr = href.substr(href, href.lastIndexOf('/'));
return href.replace(`${substr}/`, '') || '/'; return href.replace(`${substr}/`, '') || '/';
}; }
/** /**
* get current directory path * get current directory path
*/ */
module.exports.getParentDirPath = (panel) => { export function getParentDirPath(panel) {
const path = DOM.getCurrentDirPath(panel); const path = DOM.getCurrentDirPath(panel);
const dirName = DOM.getCurrentDirName() + '/'; const dirName = DOM.getCurrentDirName() + '/';
const index = path.lastIndexOf(dirName); const index = path.lastIndexOf(dirName);
@ -141,36 +187,36 @@ module.exports.getParentDirPath = (panel) => {
return path.slice(0, index); return path.slice(0, index);
return path; return path;
}; }
/** /**
* get not current directory path * get not current directory path
*/ */
module.exports.getNotCurrentDirPath = () => { export function getNotCurrentDirPath() {
const panel = DOM.getPanel({ const panel = DOM.getPanel({
active: false, active: false,
}); });
return DOM.getCurrentDirPath(panel); return DOM.getCurrentDirPath(panel);
}; }
/* /*
* unselect all files * unselect all files
*/ */
module.exports.unselectFiles = (files) => { export function unselectFiles(files) {
files = files || DOM.getSelectedFiles(); files = files || DOM.getSelectedFiles();
Array Array
.from(files) .from(files)
.forEach(DOM.toggleSelectedFile); .forEach(DOM.toggleSelectedFile);
}; }
/** /**
* get all selected files or current when none selected * get all selected files or current when none selected
* *
* @currentFile * @currentFile
*/ */
module.exports.getActiveFiles = () => { export function getActiveFiles() {
const current = DOM.getCurrentFile(); const current = DOM.getCurrentFile();
const files = DOM.getSelectedFiles(); const files = DOM.getSelectedFiles();
const name = DOM.getCurrentName(current); const name = DOM.getCurrentName(current);
@ -179,19 +225,19 @@ module.exports.getActiveFiles = () => {
return [current]; return [current];
return files; return files;
}; }
module.exports.getCurrentDate = (currentFile) => { export function getCurrentDate(currentFile) {
const current = currentFile || DOM.getCurrentFile(); const current = currentFile || DOM.getCurrentFile();
return DOM.getByDataName('js-date', current).textContent; return DOM.getByDataName('js-date', current).textContent;
}; }
/** /**
* get size * get size
* @currentFile * @currentFile
*/ */
module.exports.getCurrentSize = (currentFile) => { export function getCurrentSize(currentFile) {
const current = currentFile || DOM.getCurrentFile(); const current = currentFile || DOM.getCurrentFile();
/* если это папка - возвращаем слово dir вместо размера*/ /* если это папка - возвращаем слово dir вместо размера*/
@ -201,13 +247,13 @@ module.exports.getCurrentSize = (currentFile) => {
.replace(/^<|>$/g, ''); .replace(/^<|>$/g, '');
return size; return size;
}; }
/** /**
* get size * get size
* @currentFile * @currentFile
*/ */
module.exports.loadCurrentSize = async (currentFile) => { export async function loadCurrentSize(currentFile) {
const current = currentFile || DOM.getCurrentFile(); const current = currentFile || DOM.getCurrentFile();
const query = '?size'; const query = '?size';
const link = DOM.getCurrentPath(current); const link = DOM.getCurrentPath(current);
@ -223,14 +269,14 @@ module.exports.loadCurrentSize = async (currentFile) => {
Images.hide(); Images.hide();
return current; return current;
}; }
/** /**
* load hash * load hash
* @callback * @callback
* @currentFile * @currentFile
*/ */
module.exports.loadCurrentHash = async (currentFile) => { export async function loadCurrentHash(currentFile) {
const current = currentFile || DOM.getCurrentFile(); const current = currentFile || DOM.getCurrentFile();
const query = '?hash'; const query = '?hash';
const link = DOM.getCurrentPath(current); const link = DOM.getCurrentPath(current);
@ -238,45 +284,45 @@ module.exports.loadCurrentHash = async (currentFile) => {
const [, data] = await RESTful.read(link + query); const [, data] = await RESTful.read(link + query);
return data; return data;
}; }
/** /**
* set size * set size
* @currentFile * @currentFile
*/ */
module.exports.setCurrentSize = (size, currentFile) => { export function setCurrentSize(size, currentFile) {
const current = currentFile || DOM.getCurrentFile(); const current = currentFile || DOM.getCurrentFile();
const sizeElement = DOM.getByDataName('js-size', current); const sizeElement = DOM.getByDataName('js-size', current);
sizeElement.textContent = size; sizeElement.textContent = size;
}; }
/** /**
* @currentFile * @currentFile
*/ */
module.exports.getCurrentMode = (currentFile) => { export function getCurrentMode(currentFile) {
const current = currentFile || DOM.getCurrentFile(); const current = currentFile || DOM.getCurrentFile();
const mode = DOM.getByDataName('js-mode', current); const mode = DOM.getByDataName('js-mode', current);
return mode.textContent; return mode.textContent;
}; }
/** /**
* @currentFile * @currentFile
*/ */
module.exports.getCurrentOwner = (currentFile) => { export function getCurrentOwner(currentFile) {
const current = currentFile || DOM.getCurrentFile(); const current = currentFile || DOM.getCurrentFile();
const owner = DOM.getByDataName('js-owner', current); const owner = DOM.getByDataName('js-owner', current);
return owner.textContent; return owner.textContent;
}; }
/** /**
* unified way to get current file content * unified way to get current file content
* *
* @param currentFile * @param currentFile
*/ */
module.exports.getCurrentData = async (currentFile) => { export async function getCurrentData(currentFile) {
const {Dialog} = DOM; const {Dialog} = DOM;
const Info = DOM.CurrentInfo; const Info = DOM.CurrentInfo;
const current = currentFile || DOM.getCurrentFile(); const current = currentFile || DOM.getCurrentFile();
@ -318,16 +364,16 @@ module.exports.getCurrentData = async (currentFile) => {
await DOM.saveDataToStorage(path, data, hashNew); await DOM.saveDataToStorage(path, data, hashNew);
return [null, data]; return [null, data];
}; }
/** /**
* unified way to get RefreshButton * unified way to get RefreshButton
*/ */
module.exports.getRefreshButton = (panel = DOM.getPanel()) => { export function getRefreshButton(panel = DOM.getPanel()) {
return DOM.getByDataName('js-refresh', panel); return DOM.getByDataName('js-refresh', panel);
}; }
module.exports.getAllFiles = () => { export function getAllFiles() {
const panel = DOM.getPanel(); const panel = DOM.getPanel();
const files = DOM.getFiles(panel); const files = DOM.getFiles(panel);
const name = DOM.getCurrentName(files[0]); const name = DOM.getCurrentName(files[0]);
@ -338,32 +384,32 @@ module.exports.getAllFiles = () => {
return Array return Array
.from(files) .from(files)
.slice(i); .slice(i);
}; }
/** /**
* open dialog with expand selection * open dialog with expand selection
*/ */
module.exports.expandSelection = async () => { export async function expandSelection() {
const msg = 'expand'; const msg = 'expand';
const {files} = CurrentInfo; const {files} = CurrentInfo;
await selectByPattern(msg, files); await selectByPattern(msg, files);
}; }
/** /**
* open dialog with shrink selection * open dialog with shrink selection
*/ */
module.exports.shrinkSelection = async () => { export async function shrinkSelection() {
const msg = 'shrink'; const msg = 'shrink';
const {files} = CurrentInfo; const {files} = CurrentInfo;
await selectByPattern(msg, files); await selectByPattern(msg, files);
}; }
/** /**
* setting history wrapper * setting history wrapper
*/ */
module.exports.setHistory = (data, title, url) => { export function setHistory(data, title, url) {
const ret = globalThis.history; const ret = globalThis.history;
const {prefix} = CloudCmd; const {prefix} = CloudCmd;
@ -373,21 +419,21 @@ module.exports.setHistory = (data, title, url) => {
history.pushState(data, title, url); history.pushState(data, title, url);
return ret; return ret;
}; }
/** /**
* get link from current (or param) file * get link from current (or param) file
* *
* @param currentFile - current file by default * @param currentFile - current file by default
*/ */
module.exports.getCurrentLink = (currentFile) => { export function getCurrentLink(currentFile) {
const current = currentFile || DOM.getCurrentFile(); const current = currentFile || DOM.getCurrentFile();
const link = DOM.getByTag('a', current); const link = DOM.getByTag('a', current);
return link[0]; return link[0];
}; }
module.exports.getFilenames = (files) => { export function getFilenames(files) {
if (!files) if (!files)
throw Error('AllFiles could not be empty'); throw Error('AllFiles could not be empty');
@ -404,12 +450,12 @@ module.exports.getFilenames = (files) => {
}); });
return names; return names;
}; }
/** /**
* check storage hash * check storage hash
*/ */
module.exports.checkStorageHash = async (name) => { export async function checkStorageHash(name) {
const nameHash = `${name}-hash`; const nameHash = `${name}-hash`;
if (!isString(name)) if (!isString(name))
@ -421,7 +467,7 @@ module.exports.checkStorageHash = async (name) => {
]); ]);
return [loadHash, storeHash]; return [loadHash, storeHash];
}; }
/** /**
* save data to storage * save data to storage
@ -429,9 +475,8 @@ module.exports.checkStorageHash = async (name) => {
* @param name * @param name
* @param data * @param data
* @param hash * @param hash
* @param callback
*/ */
module.exports.saveDataToStorage = async (name, data, hash) => { export async function saveDataToStorage(name, data, hash) {
const isDir = DOM.isCurrentIsDir(); const isDir = DOM.isCurrentIsDir();
if (isDir) if (isDir)
@ -446,25 +491,27 @@ module.exports.saveDataToStorage = async (name, data, hash) => {
await Storage.set(nameData, data); await Storage.set(nameData, data);
return hash; return hash;
}; }
module.exports.getFM = () => DOM.getPanel().parentElement; export function getFM() {
const {parentElement} = DOM.getPanel();
module.exports.getPanelPosition = (panel) => { return parentElement;
}
export function getPanelPosition(panel) {
panel = panel || DOM.getPanel(); panel = panel || DOM.getPanel();
return panel.dataset.name.replace('js-', ''); return panel.dataset.name.replace('js-', '');
}; }
module.exports.getCSSVar = (name, {body = document.body} = {}) => { export function getCSSVar(name, {body = document.body} = {}) {
const bodyStyle = getComputedStyle(body); const bodyStyle = getComputedStyle(body);
return bodyStyle.getPropertyValue(`--${name}`); return bodyStyle.getPropertyValue(`--${name}`);
}; }
/** function getting panel active, or passive /** function getting panel active, or passive
* @param options = {active: true} * @param options = {active: true}
*/ */
module.exports.getPanel = (options) => { export function getPanel(options) {
let files; let files;
let panel; let panel;
let isLeft; let isLeft;
@ -497,17 +544,17 @@ module.exports.getPanel = (options) => {
throw Error('can not find Active Panel!'); throw Error('can not find Active Panel!');
return panel; return panel;
}; }
module.exports.getFiles = (element) => { export function getFiles(element) {
const files = DOM.getByDataName('js-files', element); const files = DOM.getByDataName('js-files', element);
return files.children || []; return files.children || [];
}; }
/** /**
* shows panel right or left (or active) * shows panel right or left (or active)
*/ */
module.exports.showPanel = (active) => { export function showPanel(active) {
const panel = DOM.getPanel({ const panel = DOM.getPanel({
active, active,
}); });
@ -518,12 +565,12 @@ module.exports.showPanel = (active) => {
DOM.show(panel); DOM.show(panel);
return true; return true;
}; }
/** /**
* hides panel right or left (or active) * hides panel right or left (or active)
*/ */
module.exports.hidePanel = (active) => { export function hidePanel(active) {
const panel = DOM.getPanel({ const panel = DOM.getPanel({
active, active,
}); });
@ -532,27 +579,27 @@ module.exports.hidePanel = (active) => {
return false; return false;
return DOM.hide(panel); return DOM.hide(panel);
}; }
/** /**
* remove child of element * remove child of element
* @param pChild * @param child
* @param element * @param element
*/ */
module.exports.remove = (child, element) => { export function remove(child, element) {
const parent = element || document.body; const parent = element || document.body;
parent.removeChild(child); parent.removeChild(child);
return DOM; return DOM;
}; }
/** /**
* remove current file from file table * remove current file from file table
* @param current * @param current
* *
*/ */
module.exports.deleteCurrent = (current) => { export function deleteCurrent(current) {
if (!current) if (!current)
DOM.getCurrentFile(); DOM.getCurrentFile();
@ -566,51 +613,44 @@ module.exports.deleteCurrent = (current) => {
DOM.setCurrentFile(next || prev); DOM.setCurrentFile(next || prev);
parent.removeChild(current); parent.removeChild(current);
} }
}; }
/** /**
* remove selected files from file table * remove selected files from file table
* @Selected * @Selected
*/ */
module.exports.deleteSelected = (selected) => { export function deleteSelected(selected) {
selected = selected || DOM.getSelectedFiles(); selected = selected || DOM.getSelectedFiles();
if (!selected) if (!selected)
return; return;
selected.map(DOM.deleteCurrent); selected.map(DOM.deleteCurrent);
}; }
/** /**
* rename current file * rename current file
* *
* @currentFile * @currentFile
*/ */
module.exports.renameCurrent = renameCurrent; export function scrollIntoViewIfNeeded(element, center = false) {
/**
* unified way to scrollIntoViewIfNeeded
* (native suporte by webkit only)
* @param element
* @param center - to scroll as small as possible param should be false
*/
module.exports.scrollIntoViewIfNeeded = (element, center = false) => {
if (!element || !element.scrollIntoViewIfNeeded) if (!element || !element.scrollIntoViewIfNeeded)
return; return;
element.scrollIntoViewIfNeeded(center); element.scrollIntoViewIfNeeded(center);
}; }
/* scroll on one page */ /* scroll on one page */
module.exports.scrollByPages = (element, pPages) => { export function scrollByPages(element, pPages) {
const ret = element?.scrollByPages && pPages; const ret = element?.scrollByPages && pPages;
if (ret) if (ret)
element.scrollByPages(pPages); element.scrollByPages(pPages);
return ret; return ret;
}; }
module.exports.changePanel = () => { export function changePanel() {
const Info = CurrentInfo; const Info = CurrentInfo;
let panel = DOM.getPanel(); let panel = DOM.getPanel();
@ -656,16 +696,16 @@ module.exports.changePanel = () => {
CloudCmd.emit('active-dir', Info.dirPath); CloudCmd.emit('active-dir', Info.dirPath);
return DOM; return DOM;
}; }
module.exports.getPackerExt = (type) => { export function getPackerExt(type) {
if (type === 'zip') if (type === 'zip')
return '.zip'; return '.zip';
return '.tar.gz'; return '.tar.gz';
}; }
module.exports.goToDirectory = async (overrides = {}) => { export async function goToDirectory(overrides = {}) {
const {Dialog} = DOM; const {Dialog} = DOM;
const {prompt = Dialog.prompt, changeDir = CloudCmd.changeDir} = overrides; const {prompt = Dialog.prompt, changeDir = CloudCmd.changeDir} = overrides;
@ -678,9 +718,9 @@ module.exports.goToDirectory = async (overrides = {}) => {
return; return;
await changeDir(path); await changeDir(path);
}; }
module.exports.duplicatePanel = async () => { export async function duplicatePanel() {
const Info = CurrentInfo; const Info = CurrentInfo;
const {isDir} = Info; const {isDir} = Info;
const panel = Info.panelPassive; const panel = Info.panelPassive;
@ -699,9 +739,9 @@ module.exports.duplicatePanel = async () => {
panel, panel,
noCurrent, noCurrent,
}); });
}; }
module.exports.swapPanels = async () => { export async function swapPanels() {
const Info = CurrentInfo; const Info = CurrentInfo;
const { const {
panel, panel,
@ -732,11 +772,9 @@ module.exports.swapPanels = async () => {
const el = Info.files[currentIndex]; const el = Info.files[currentIndex];
DOM.setCurrentFile(el); DOM.setCurrentFile(el);
}; }
module.exports.CurrentInfo = CurrentInfo; export function updateCurrentInfo(currentFile) {
module.exports.updateCurrentInfo = (currentFile) => {
const info = DOM.CurrentInfo; const info = DOM.CurrentInfo;
const current = currentFile || DOM.getCurrentFile(); const current = currentFile || DOM.getCurrentFile();
const files = current.parentElement; const files = current.parentElement;
@ -752,7 +790,7 @@ module.exports.updateCurrentInfo = (currentFile) => {
info.dirPath = DOM.getCurrentDirPath(); info.dirPath = DOM.getCurrentDirPath();
info.parentDirPath = DOM.getParentDirPath(); info.parentDirPath = DOM.getParentDirPath();
info.element = current; info.element = current;
info.ext = Util.getExt(name); info.ext = getExt(name);
info.files = Array.from(files.children); info.files = Array.from(files.children);
info.filesPassive = Array.from(filesPassive); info.filesPassive = Array.from(filesPassive);
info.first = files.firstChild; info.first = files.firstChild;
@ -773,4 +811,4 @@ module.exports.updateCurrentInfo = (currentFile) => {
.name .name
.replace('js-', ''); .replace('js-', '');
info.isOnePanel = info.panel.getAttribute('data-name') === info.panelPassive.getAttribute('data-name'); info.isOnePanel = info.panel.getAttribute('data-name') === info.panelPassive.getAttribute('data-name');
}; }

View file

@ -3,7 +3,7 @@
require('css-modules-require-hook/preset'); require('css-modules-require-hook/preset');
const {test, stub} = require('supertape'); const {test, stub} = require('supertape');
const {getCSSVar, goToDirectory} = require('./index'); const {getCSSVar, goToDirectory} = require('./index.mjs');
globalThis.CloudCmd = {}; globalThis.CloudCmd = {};

View file

@ -6,7 +6,7 @@ const itype = require('itype');
const load = require('load.js'); const load = require('load.js');
const {tryToCatch} = require('try-to-catch'); const {tryToCatch} = require('try-to-catch');
const {findObjByNameInArr} = require('../../common/util'); const {findObjByNameInArr} = require('#common/util');
const Files = require('#dom/files'); const Files = require('#dom/files');

View file

@ -1,13 +1,14 @@
'use strict'; import {alert, prompt} from '#dom/dialog';
import {getRegExp} from '#common/util';
import {getCurrentName} from './current-file.mjs';
import {
isSelected,
toggleSelectedFile,
} from './cmd.mjs';
let SelectType = '*.*'; let SelectType = '*.*';
const {getRegExp} = require('../../common/util'); export const selectByPattern = async (msg, files) => {
const {alert, prompt} = require('#dom/dialog');
const DOM = require('.');
module.exports = async (msg, files) => {
if (!files) if (!files)
return; return;
@ -23,21 +24,21 @@ module.exports = async (msg, files) => {
let matches = 0; let matches = 0;
for (const current of files) { for (const current of files) {
const name = DOM.getCurrentName(current); const name = getCurrentName(current);
if (name === '..' || !regExp.test(name)) if (name === '..' || !regExp.test(name))
continue; continue;
++matches; ++matches;
let isSelected = DOM.isSelected(current); let selected = isSelected(current);
const shouldSel = msg === 'expand'; const shouldSel = msg === 'expand';
if (shouldSel) if (shouldSel)
isSelected = !isSelected; selected = !selected;
if (isSelected) if (selected)
DOM.toggleSelectedFile(current); toggleSelectedFile(current);
} }
if (!matches) if (!matches)

View file

@ -9,8 +9,8 @@ const Images = require('./images.mjs');
const {alert} = require('#dom/dialog'); const {alert} = require('#dom/dialog');
const {FS} = require('../../common/cloudfunc.mjs'); const {FS} = require('../../common/cloudfunc.mjs');
const {getCurrentDirPath} = require('./current-file.mjs');
const {getCurrentDirPath: getPathWhenRootEmpty} = require('.');
const loadFile = wraptile(_loadFile); const loadFile = wraptile(_loadFile);
const onEnd = wraptile(_onEnd); const onEnd = wraptile(_onEnd);
@ -18,7 +18,7 @@ const onEnd = wraptile(_onEnd);
module.exports = (dir, files) => { module.exports = (dir, files) => {
if (!files) { if (!files) {
files = dir; files = dir;
dir = getPathWhenRootEmpty(); dir = getCurrentDirPath();
} }
const n = files.length; const n = files.length;

View file

@ -1,5 +1,5 @@
/* global DOM */ /* global DOM */
import {escapeRegExp} from '../../common/util.js'; import {escapeRegExp} from '#common/util';
export default function setCurrentByChar(char, charStore) { export default function setCurrentByChar(char, charStore) {
const Info = DOM.CurrentInfo; const Info = DOM.CurrentInfo;

View file

@ -8,10 +8,10 @@ import {tryToCatch} from 'try-to-catch';
import load from 'load.js'; import load from 'load.js';
import createElement from '@cloudcmd/create-element'; import createElement from '@cloudcmd/create-element';
import * as Events from '#dom/events'; import * as Events from '#dom/events';
import * as Files from '#dom/files';
import '../../../css/config.css'; import '../../../css/config.css';
import * as input from './input.mjs'; import * as input from './input.mjs';
import * as Images from '../../dom/images.mjs'; import * as Images from '../../dom/images.mjs';
import * as Files from '#dom/files';
import {getTitle} from '../../../common/cloudfunc.mjs'; import {getTitle} from '../../../common/cloudfunc.mjs';
const {Dialog, setTitle} = DOM; const {Dialog, setTitle} = DOM;

View file

@ -10,7 +10,7 @@ const createElement = require('@cloudcmd/create-element');
const load = require('load.js'); const load = require('load.js');
const {MAX_FILE_SIZE: maxSize} = require('../../common/cloudfunc.mjs'); const {MAX_FILE_SIZE: maxSize} = require('../../common/cloudfunc.mjs');
const {time, timeEnd} = require('../../common/util'); const {time, timeEnd} = require('#common/util');
const getEditor = () => editor; const getEditor = () => editor;
const isFn = (a) => typeof a === 'function'; const isFn = (a) => typeof a === 'function';
const loadJS = load.js; const loadJS = load.js;

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
const {getExt} = require('../../../common/util'); const {getExt} = require('#common/util');
module.exports = (name) => { module.exports = (name) => {
const ext = getExtension(name); const ext = getExtension(name);

View file

@ -9,7 +9,7 @@ require('../../css/terminal.css');
const exec = require('execon'); const exec = require('execon');
const load = require('load.js'); const load = require('load.js');
const DOM = require('../dom'); const DOM = require('../dom/index.mjs');
const Images = require('../dom/images.mjs'); const Images = require('../dom/images.mjs');
const {Dialog} = DOM; const {Dialog} = DOM;

View file

@ -8,7 +8,7 @@ require('../../css/terminal.css');
const exec = require('execon'); const exec = require('execon');
const load = require('load.js'); const load = require('load.js');
const DOM = require('../dom'); const DOM = require('../dom/index.mjs');
const Images = require('../dom/images.mjs'); const Images = require('../dom/images.mjs');
const loadParallel = load.parallel; const loadParallel = load.parallel;

View file

@ -16,7 +16,7 @@ const load = require('load.js');
const _modal = require('@cloudcmd/modal'); const _modal = require('@cloudcmd/modal');
const _createElement = require('@cloudcmd/create-element'); const _createElement = require('@cloudcmd/create-element');
const {time} = require('../../../common/util'); const {time} = require('#common/util');
const {FS} = require('../../../common/cloudfunc.mjs'); const {FS} = require('../../../common/cloudfunc.mjs');
const { const {

View file

@ -1,6 +1,6 @@
/* global CloudCmd */ /* global CloudCmd */
import {fullstore} from 'fullstore'; import {fullstore} from 'fullstore';
import DOM from './dom/index.js'; import DOM from './dom/index.mjs';
const sortPrevious = fullstore(); const sortPrevious = fullstore();

View file

@ -1,9 +1,8 @@
'use strict'; import exec from 'execon';
const exec = require('execon');
const isString = (a) => typeof a === 'string'; const isString = (a) => typeof a === 'string';
module.exports.escapeRegExp = (str) => { export const escapeRegExp = (str) => {
const isStr = isString(str); const isStr = isString(str);
if (isStr) if (isStr)
@ -15,7 +14,7 @@ module.exports.escapeRegExp = (str) => {
/** /**
* get regexp from wild card * get regexp from wild card
*/ */
module.exports.getRegExp = (wildcard) => { export const getRegExp = (wildcard) => {
const escaped = `^${wildcard // search from start of line const escaped = `^${wildcard // search from start of line
.replace(/\./g, '\\.') .replace(/\./g, '\\.')
.replace(/\*/g, '.*') .replace(/\*/g, '.*')
@ -25,14 +24,13 @@ module.exports.getRegExp = (wildcard) => {
return RegExp(escaped); return RegExp(escaped);
}; };
module.exports.exec = exec;
/** /**
* function gets file extension * function gets file extension
* *
* @param name * @param name
* @return ext * @return ext
*/ */
module.exports.getExt = (name) => { export const getExt = (name) => {
const isStr = isString(name); const isStr = isString(name);
if (!isStr) if (!isStr)
@ -52,7 +50,7 @@ module.exports.getExt = (name) => {
* @param array * @param array
* @param name * @param name
*/ */
module.exports.findObjByNameInArr = (array, name) => { export const findObjByNameInArr = (array, name) => {
let ret; let ret;
if (!Array.isArray(array)) if (!Array.isArray(array))
@ -90,7 +88,7 @@ module.exports.findObjByNameInArr = (array, name) => {
* start timer * start timer
* @param name * @param name
*/ */
module.exports.time = (name) => { export const time = (name) => {
exec.ifExist(console, 'time', [name]); exec.ifExist(console, 'time', [name]);
}; };
@ -98,6 +96,6 @@ module.exports.time = (name) => {
* stop timer * stop timer
* @param name * @param name
*/ */
module.exports.timeEnd = (name) => { export const timeEnd = (name) => {
exec.ifExist(console, 'timeEnd', [name]); exec.ifExist(console, 'timeEnd', [name]);
}; };

View file

@ -1,19 +1,16 @@
'use strict'; import test from 'supertape';
import {tryCatch} from 'try-catch';
const test = require('supertape'); import {
const {tryCatch} = require('try-catch');
const Util = require('./util');
const {
findObjByNameInArr, findObjByNameInArr,
getRegExp, getRegExp,
escapeRegExp, escapeRegExp,
} = Util; getExt,
} from '#common/util';
test('getExt: no extension', (t) => { test('getExt: no extension', (t) => {
const EXT = ''; const EXT = '';
const name = 'file-withot-extension'; const name = 'file-without-extension';
const ext = Util.getExt(name); const ext = getExt(name);
t.equal(ext, EXT, 'should return "" when extension is none'); t.equal(ext, EXT, 'should return "" when extension is none');
t.end(); t.end();
@ -22,14 +19,14 @@ test('getExt: no extension', (t) => {
test('getExt: return extension', (t) => { test('getExt: return extension', (t) => {
const EXT = '.png'; const EXT = '.png';
const name = 'picture.png'; const name = 'picture.png';
const ext = Util.getExt(name); const ext = getExt(name);
t.equal(ext, EXT, 'should return ".png" in files "picture.png"'); t.equal(ext, EXT, 'should return ".png" in files "picture.png"');
t.end(); t.end();
}); });
test('util: getExt: no name', (t) => { test('util: getExt: no name', (t) => {
const ext = Util.getExt(); const ext = getExt();
t.equal(ext, '', 'should return empty string'); t.equal(ext, '', 'should return empty string');
t.end(); t.end();

View file

@ -9,7 +9,7 @@ export const match = {
'no-console': 'off', 'no-console': 'off',
'n/hashbang': 'off', 'n/hashbang': 'off',
}, },
'client/dom/index.js': { 'client/dom/index.*': {
'no-multi-spaces': 'off', 'no-multi-spaces': 'off',
}, },
'{client,static}/**/*.{js,mjs}': { '{client,static}/**/*.{js,mjs}': {

View file

@ -221,7 +221,8 @@
"#dom/events": "./client/dom/events/index.mjs", "#dom/events": "./client/dom/events/index.mjs",
"#dom/load": "./client/dom/load.mjs", "#dom/load": "./client/dom/load.mjs",
"#dom/dialog": "./client/dom/dialog.mjs", "#dom/dialog": "./client/dom/dialog.mjs",
"#dom/files": "./client/dom/files.mjs" "#dom/files": "./client/dom/files.mjs",
"#common/util": "./common/util.mjs"
}, },
"engines": { "engines": {
"node": ">=22" "node": ">=22"

View file

@ -6,7 +6,7 @@ const {tryCatch} = require('try-catch');
const test = require('supertape'); const test = require('supertape');
const readFilesSync = require('@cloudcmd/read-files-sync'); const readFilesSync = require('@cloudcmd/read-files-sync');
const {time, timeEnd} = require(`../../common/util`); const {time, timeEnd} = require(`../../common/util.mjs`);
const CloudFunc = require('../../common/cloudfunc.mjs'); const CloudFunc = require('../../common/cloudfunc.mjs');
const DIR = `${__dirname}/../../`; const DIR = `${__dirname}/../../`;