feature: client: buffer: migrate to ESM

This commit is contained in:
coderiaser 2026-01-20 18:54:48 +02:00
parent 8876f050e0
commit 3b6b0b5a5b
5 changed files with 352 additions and 366 deletions

View file

@ -1,135 +0,0 @@
'use strict';
/* global CloudCmd */
const tryToPromiseAll = require('../../common/try-to-promise-all');
const Storage = require('./storage');
const DOM = require('./');
module.exports = new BufferProto();
function BufferProto() {
const Info = DOM.CurrentInfo;
const CLASS = 'cut-file';
const COPY = 'copy';
const CUT = 'cut';
const Buffer = {
cut: callIfEnabled.bind(null, cut),
copy: callIfEnabled.bind(null, copy),
clear: callIfEnabled.bind(null, clear),
paste: callIfEnabled.bind(null, paste),
};
function showMessage(msg) {
DOM.Dialog.alert(msg);
}
function getNames() {
const files = DOM.getActiveFiles();
return DOM.getFilenames(files);
}
function addCutClass() {
const files = DOM.getActiveFiles();
for (const element of files) {
element.classList.add(CLASS);
}
}
function rmCutClass() {
const files = DOM.getByClassAll(CLASS);
for (const element of files) {
element.classList.remove(CLASS);
}
}
function callIfEnabled(callback) {
const is = CloudCmd.config('buffer');
if (is)
return callback();
showMessage('Buffer disabled in config!');
}
async function readBuffer() {
const [e, cp, ct] = await tryToPromiseAll([
Storage.getJson(COPY),
Storage.getJson(CUT),
]);
return [
e,
cp,
ct,
];
}
async function copy() {
const names = getNames();
const from = Info.dirPath;
await clear();
if (!names.length)
return;
await Storage.remove(CUT);
await Storage.setJson(COPY, {
from,
names,
});
}
async function cut() {
const names = getNames();
const from = Info.dirPath;
await clear();
if (!names.length)
return;
addCutClass();
await Storage.setJson(CUT, {
from,
names,
});
}
async function clear() {
await Storage.remove(COPY);
await Storage.remove(CUT);
rmCutClass();
}
async function paste() {
const [error, cp, ct] = await readBuffer();
if (error || !cp && !ct)
return showMessage(error || 'Buffer is empty!');
const opStr = cp ? 'copy' : 'move';
const data = cp || ct;
const {Operation} = CloudCmd;
const msg = 'Path is same!';
const to = Info.dirPath;
if (data.from === to)
return showMessage(msg);
Operation.show(opStr, {
...data,
to,
});
await clear();
}
return Buffer;
}

120
client/dom/buffer.mjs Normal file
View file

@ -0,0 +1,120 @@
/* global CloudCmd */
import tryToPromiseAll from '../../common/try-to-promise-all.js';
import Storage from './storage.js';
import DOM from './index.js';
const Info = DOM.CurrentInfo;
const CLASS = 'cut-file';
const COPY = 'copy';
const CUT = 'cut';
function showMessage(msg) {
DOM.Dialog.alert(msg);
}
function getNames() {
const files = DOM.getActiveFiles();
return DOM.getFilenames(files);
}
function addCutClass() {
const files = DOM.getActiveFiles();
for (const element of files) {
element.classList.add(CLASS);
}
}
function rmCutClass() {
const files = DOM.getByClassAll(CLASS);
for (const element of files) {
element.classList.remove(CLASS);
}
}
const checkEnabled = (fn) => () => {
const is = CloudCmd.config('buffer');
if (is)
return fn();
showMessage('Buffer disabled in config!');
};
async function readBuffer() {
const [e, cp, ct] = await tryToPromiseAll([
Storage.getJson(COPY),
Storage.getJson(CUT),
]);
return [
e,
cp,
ct,
];
}
export const copy = checkEnabled(async () => {
const names = getNames();
const from = Info.dirPath;
await clear();
if (!names.length)
return;
await Storage.remove(CUT);
await Storage.setJson(COPY, {
from,
names,
});
});
export const cut = checkEnabled(async () => {
const names = getNames();
const from = Info.dirPath;
await clear();
if (!names.length)
return;
addCutClass();
await Storage.setJson(CUT, {
from,
names,
});
});
export const clear = checkEnabled(async () => {
await Storage.remove(COPY);
await Storage.remove(CUT);
rmCutClass();
});
export const paste = checkEnabled(async () => {
const [error, cp, ct] = await readBuffer();
if (error || !cp && !ct)
return showMessage(error || 'Buffer is empty!');
const opStr = cp ? 'copy' : 'move';
const data = cp || ct;
const {Operation} = CloudCmd;
const msg = 'Path is same!';
const to = Info.dirPath;
if (data.from === to)
return showMessage(msg);
Operation.show(opStr, {
...data,
to,
});
await clear();
});

View file

@ -32,7 +32,7 @@ DOM.CurrentInfo = CurrentInfo;
module.exports = DOM;
DOM.uploadDirectory = require('./directory');
DOM.Buffer = require('./buffer');
DOM.Buffer = require('./buffer.mjs');
DOM.Events = require('#dom/events');
const loadRemote = require('./load-remote');

View file

@ -4,7 +4,7 @@
const clipboard = require('@cloudcmd/clipboard');
const {fullstore} = require('fullstore');
const Buffer = require('../dom/buffer');
const Buffer = require('../dom/buffer.mjs');
const Events = require('#dom/events');
const KEY = require('./key');

View file

@ -1,232 +1,233 @@
{
"name": "cloudcmd",
"version": "19.1.7",
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
"description": "File manager for the web with console and editor",
"homepage": "http://cloudcmd.io",
"funding": "https://opencollective.com/cloudcmd",
"repository": {
"type": "git",
"url": "git+https://github.com/coderaiser/cloudcmd.git"
},
"main": "server/cloudcmd.mjs",
"keywords": [
"console",
"terminal",
"edit",
"editor",
"file",
"file manager",
"folder",
"orthodox",
"view",
"viewer",
"copy",
"rename",
"move",
"rm",
"mv",
"cp",
"delete",
"delete file",
"delete directory",
"remove",
"remove file",
"remove directory",
"file operation",
"pack",
"server"
],
"bin": {
"cloudcmd": "bin/cloudcmd.mjs"
},
"scripts": {
"start": "madrun start",
"start:dev": "madrun start:dev",
"build:start": "madrun build:start",
"build:start:dev": "madrun build:start:dev",
"lint:all": "madrun lint:all",
"lint": "madrun lint",
"lint:progress": "madrun lint:progress",
"watch:lint": "madrun watch:lint",
"fresh:lint": "madrun fresh:lint",
"lint:fresh": "madrun lint:fresh",
"fix:lint": "madrun fix:lint",
"lint:stream": "madrun lint:stream",
"test": "madrun test",
"test:client": "madrun test:client",
"test:server": "madrun test:server",
"wisdom": "madrun wisdom",
"wisdom:type": "madrun wisdom:type",
"coverage": "madrun coverage",
"coverage:report": "madrun coverage:report",
"report": "madrun report",
"6to5": "madrun 6to5",
"6to5:client": "madrun 6to5:client",
"6to5:client:dev": "madrun 6to5:client:dev",
"watch:client": "madrun watch:client",
"watch:client:dev": "madrun watch:client:dev",
"watch:server": "madrun watch:server",
"watch:test": "madrun watch:test",
"watch:test:client": "madrun watch:test:client",
"watch:test:server": "madrun watch:test:server",
"watch:coverage": "madrun watch:coverage",
"build": "madrun build",
"build:dev": "madrun build:dev",
"build:client": "madrun build:client",
"build:client:dev": "madrun build:client:dev",
"heroku-postbuild": "madrun heroku-postbuild"
},
"directories": {
"man": "man"
},
"subdomain": "cloudcmd",
"dependencies": {
"@babel/plugin-transform-optional-chaining": "^7.21.0",
"@cloudcmd/dropbox": "^5.0.1",
"@cloudcmd/fileop": "^8.0.0",
"@cloudcmd/move-files": "^8.0.0",
"@cloudcmd/read-files-sync": "^2.0.0",
"@putout/cli-validate-args": "^2.0.0",
"aleman": "^1.16.5",
"apart": "^2.0.0",
"chalk": "^5.3.0",
"compression": "^1.7.4",
"console-io": "^14.0.0",
"copymitter": "^9.0.0",
"criton": "^2.0.0",
"currify": "^4.0.0",
"deepmerge": "^4.0.0",
"deepword": "^10.0.0",
"dword": "^15.0.0",
"edward": "^15.0.0",
"es6-promisify": "^7.0.0",
"execon": "^1.2.0",
"express": "^5.1.0",
"files-io": "^4.0.0",
"find-up": "^8.0.0",
"for-each-key": "^2.0.0",
"format-io": "^2.0.0",
"fullstore": "^4.0.0",
"http-auth": "^4.2.1",
"inly": "^5.0.0",
"jaguar": "^6.0.0",
"jju": "^1.3.0",
"jonny": "^3.0.0",
"just-snake-case": "^3.2.0",
"markdown-it": "^14.0.0",
"mellow": "^3.0.0",
"mime-types": "^3.0.1",
"montag": "^1.2.1",
"nano-memoize": "^3.0.16",
"nomine": "^4.0.0",
"object.omit": "^3.0.0",
"once": "^1.4.0",
"onezip": "^6.0.1",
"open": "^11.0.0",
"package-json": "^10.0.0",
"pipe-io": "^4.0.1",
"ponse": "^7.0.0",
"pullout": "^5.0.0",
"putout": "^41.0.0",
"redzip": "^3.0.0",
"rendy": "^4.1.3",
"restafary": "^12.0.0",
"restbox": "^4.0.0",
"shortdate": "^2.0.0",
"simport": "^1.0.1",
"socket.io": "^4.0.0",
"socket.io-client": "^4.0.1",
"squad": "^3.0.0",
"table": "^6.0.1",
"try-catch": "^4.0.4",
"try-to-catch": "^4.0.0",
"tryrequire": "^3.0.0",
"win32": "^7.0.0",
"wraptile": "^3.0.0",
"writejson": "^3.0.0",
"yargs-parser": "^22.0.0"
},
"devDependencies": {
"@babel/code-frame": "^7.22.5",
"@babel/core": "^7.22.5",
"@babel/preset-env": "^7.0.0",
"@cloudcmd/clipboard": "^2.0.0",
"@cloudcmd/create-element": "^2.0.0",
"@cloudcmd/modal": "^3.0.0",
"@cloudcmd/olark": "^3.0.2",
"@cloudcmd/stub": "^5.0.0",
"@iocmd/wait": "^2.1.0",
"@putout/eslint-flat": "^3.0.1",
"@putout/plugin-cloudcmd": "^4.0.0",
"@types/node-fetch": "^2.6.11",
"auto-globals": "^4.0.0",
"babel-loader": "^10.0.0",
"babel-plugin-macros": "^3.0.0",
"c8": "^10.1.2",
"cheerio": "^1.0.0-rc.5",
"clean-css-loader": "^4.2.1",
"codegen.macro": "^4.0.0",
"css-loader": "^7.1.2",
"css-modules-require-hook": "^4.2.3",
"cssnano-preset-default": "^7.0.10",
"domtokenlist-shim": "^1.2.0",
"emitify": "^4.0.1",
"eslint": "^9.23.0",
"eslint-plugin-n": "^17.0.0-4",
"eslint-plugin-putout": "^30.0.0",
"globals": "^17.0.0",
"gritty": "^9.0.0",
"gunzip-maybe": "^1.3.1",
"html-webpack-plugin": "^5.6.3",
"inherits": "^2.0.3",
"itype": "^3.0.1",
"just-capitalize": "^3.2.0",
"just-pascal-case": "^3.2.0",
"limier": "^3.0.0",
"load.js": "^3.0.0",
"madrun": "^12.1.0",
"memfs": "^4.2.0",
"mini-css-extract-plugin": "^2.9.2",
"minor": "^1.2.2",
"mock-require": "^3.0.1",
"morgan": "^1.6.1",
"multi-rename": "^3.0.0",
"nodemon": "^3.0.1",
"optimize-css-assets-webpack-plugin": "^6.0.1",
"path-browserify": "^1.0.1",
"philip": "^3.0.0",
"place": "^1.1.4",
"postcss": "^8.5.3",
"process": "^0.11.10",
"readjson": "^2.0.1",
"redlint": "^5.0.0",
"request": "^2.76.0",
"rimraf": "^6.0.1",
"scroll-into-view-if-needed": "^3.0.4",
"serve-once": "^3.0.1",
"smalltalk": "^4.0.0",
"style-loader": "^4.0.0",
"supermenu": "^4.0.1",
"supertape": "^12.0.0",
"tar-stream": "^3.0.0",
"unionfs": "^4.0.0",
"url-loader": "^4.0.0",
"webpack": "^5.99.9",
"webpack-cli": "^6.0.1",
"webpack-merge": "^6.0.1",
"webpackbar": "^7.0.0"
},
"imports": {
"#dom/events": {
"default": "./client/dom/events/index.mjs"
"name": "cloudcmd",
"version": "19.1.7",
"type": "commonjs",
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
"description": "File manager for the web with console and editor",
"homepage": "http://cloudcmd.io",
"funding": "https://opencollective.com/cloudcmd",
"repository": {
"type": "git",
"url": "git+https://github.com/coderaiser/cloudcmd.git"
},
"main": "server/cloudcmd.mjs",
"keywords": [
"console",
"terminal",
"edit",
"editor",
"file",
"file manager",
"folder",
"orthodox",
"view",
"viewer",
"copy",
"rename",
"move",
"rm",
"mv",
"cp",
"delete",
"delete file",
"delete directory",
"remove",
"remove file",
"remove directory",
"file operation",
"pack",
"server"
],
"bin": {
"cloudcmd": "bin/cloudcmd.mjs"
},
"scripts": {
"start": "madrun start",
"start:dev": "madrun start:dev",
"build:start": "madrun build:start",
"build:start:dev": "madrun build:start:dev",
"lint:all": "madrun lint:all",
"lint": "madrun lint",
"lint:progress": "madrun lint:progress",
"watch:lint": "madrun watch:lint",
"fresh:lint": "madrun fresh:lint",
"lint:fresh": "madrun lint:fresh",
"fix:lint": "madrun fix:lint",
"lint:stream": "madrun lint:stream",
"test": "madrun test",
"test:client": "madrun test:client",
"test:server": "madrun test:server",
"wisdom": "madrun wisdom",
"wisdom:type": "madrun wisdom:type",
"coverage": "madrun coverage",
"coverage:report": "madrun coverage:report",
"report": "madrun report",
"6to5": "madrun 6to5",
"6to5:client": "madrun 6to5:client",
"6to5:client:dev": "madrun 6to5:client:dev",
"watch:client": "madrun watch:client",
"watch:client:dev": "madrun watch:client:dev",
"watch:server": "madrun watch:server",
"watch:test": "madrun watch:test",
"watch:test:client": "madrun watch:test:client",
"watch:test:server": "madrun watch:test:server",
"watch:coverage": "madrun watch:coverage",
"build": "madrun build",
"build:dev": "madrun build:dev",
"build:client": "madrun build:client",
"build:client:dev": "madrun build:client:dev",
"heroku-postbuild": "madrun heroku-postbuild"
},
"directories": {
"man": "man"
},
"subdomain": "cloudcmd",
"dependencies": {
"@babel/plugin-transform-optional-chaining": "^7.21.0",
"@cloudcmd/dropbox": "^5.0.1",
"@cloudcmd/fileop": "^8.0.0",
"@cloudcmd/move-files": "^8.0.0",
"@cloudcmd/read-files-sync": "^2.0.0",
"@putout/cli-validate-args": "^2.0.0",
"aleman": "^1.16.5",
"apart": "^2.0.0",
"chalk": "^5.3.0",
"compression": "^1.7.4",
"console-io": "^14.0.0",
"copymitter": "^9.0.0",
"criton": "^2.0.0",
"currify": "^4.0.0",
"deepmerge": "^4.0.0",
"deepword": "^10.0.0",
"dword": "^15.0.0",
"edward": "^15.0.0",
"es6-promisify": "^7.0.0",
"execon": "^1.2.0",
"express": "^5.1.0",
"files-io": "^4.0.0",
"find-up": "^8.0.0",
"for-each-key": "^2.0.0",
"format-io": "^2.0.0",
"fullstore": "^4.0.0",
"http-auth": "^4.2.1",
"inly": "^5.0.0",
"jaguar": "^6.0.0",
"jju": "^1.3.0",
"jonny": "^3.0.0",
"just-snake-case": "^3.2.0",
"markdown-it": "^14.0.0",
"mellow": "^3.0.0",
"mime-types": "^3.0.1",
"montag": "^1.2.1",
"nano-memoize": "^3.0.16",
"nomine": "^4.0.0",
"object.omit": "^3.0.0",
"once": "^1.4.0",
"onezip": "^6.0.1",
"open": "^11.0.0",
"package-json": "^10.0.0",
"pipe-io": "^4.0.1",
"ponse": "^7.0.0",
"pullout": "^5.0.0",
"putout": "^41.0.0",
"redzip": "^3.0.0",
"rendy": "^4.1.3",
"restafary": "^12.0.0",
"restbox": "^4.0.0",
"shortdate": "^2.0.0",
"simport": "^1.0.1",
"socket.io": "^4.0.0",
"socket.io-client": "^4.0.1",
"squad": "^3.0.0",
"table": "^6.0.1",
"try-catch": "^4.0.4",
"try-to-catch": "^4.0.0",
"tryrequire": "^3.0.0",
"win32": "^7.0.0",
"wraptile": "^3.0.0",
"writejson": "^3.0.0",
"yargs-parser": "^22.0.0"
},
"devDependencies": {
"@babel/code-frame": "^7.22.5",
"@babel/core": "^7.22.5",
"@babel/preset-env": "^7.0.0",
"@cloudcmd/clipboard": "^2.0.0",
"@cloudcmd/create-element": "^2.0.0",
"@cloudcmd/modal": "^3.0.0",
"@cloudcmd/olark": "^3.0.2",
"@cloudcmd/stub": "^5.0.0",
"@iocmd/wait": "^2.1.0",
"@putout/eslint-flat": "^3.0.1",
"@putout/plugin-cloudcmd": "^4.0.0",
"@types/node-fetch": "^2.6.11",
"auto-globals": "^4.0.0",
"babel-loader": "^10.0.0",
"babel-plugin-macros": "^3.0.0",
"c8": "^10.1.2",
"cheerio": "^1.0.0-rc.5",
"clean-css-loader": "^4.2.1",
"codegen.macro": "^4.0.0",
"css-loader": "^7.1.2",
"css-modules-require-hook": "^4.2.3",
"cssnano-preset-default": "^7.0.10",
"domtokenlist-shim": "^1.2.0",
"emitify": "^4.0.1",
"eslint": "^9.23.0",
"eslint-plugin-n": "^17.0.0-4",
"eslint-plugin-putout": "^30.0.0",
"globals": "^17.0.0",
"gritty": "^9.0.0",
"gunzip-maybe": "^1.3.1",
"html-webpack-plugin": "^5.6.3",
"inherits": "^2.0.3",
"itype": "^3.0.1",
"just-capitalize": "^3.2.0",
"just-pascal-case": "^3.2.0",
"limier": "^3.0.0",
"load.js": "^3.0.0",
"madrun": "^12.1.0",
"memfs": "^4.2.0",
"mini-css-extract-plugin": "^2.9.2",
"minor": "^1.2.2",
"mock-require": "^3.0.1",
"morgan": "^1.6.1",
"multi-rename": "^3.0.0",
"nodemon": "^3.0.1",
"optimize-css-assets-webpack-plugin": "^6.0.1",
"path-browserify": "^1.0.1",
"philip": "^3.0.0",
"place": "^1.1.4",
"postcss": "^8.5.3",
"process": "^0.11.10",
"readjson": "^2.0.1",
"redlint": "^5.0.0",
"request": "^2.76.0",
"rimraf": "^6.0.1",
"scroll-into-view-if-needed": "^3.0.4",
"serve-once": "^3.0.1",
"smalltalk": "^4.0.0",
"style-loader": "^4.0.0",
"supermenu": "^4.0.1",
"supertape": "^12.0.0",
"tar-stream": "^3.0.0",
"unionfs": "^4.0.0",
"url-loader": "^4.0.0",
"webpack": "^5.99.9",
"webpack-cli": "^6.0.1",
"webpack-merge": "^6.0.1",
"webpackbar": "^7.0.0"
},
"imports": {
"#dom/events": {
"default": "./client/dom/events/index.mjs"
}
},
"engines": {
"node": ">=22"
},
"license": "MIT",
"publishConfig": {
"access": "public"
}
},
"engines": {
"node": ">=22"
},
"license": "MIT",
"publishConfig": {
"access": "public"
}
}