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; module.exports = DOM;
DOM.uploadDirectory = require('./directory'); DOM.uploadDirectory = require('./directory');
DOM.Buffer = require('./buffer'); DOM.Buffer = require('./buffer.mjs');
DOM.Events = require('#dom/events'); DOM.Events = require('#dom/events');
const loadRemote = require('./load-remote'); const loadRemote = require('./load-remote');

View file

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

View file

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