mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature: client: cloudcmd: migrate to ESM
This commit is contained in:
parent
3bdf47a5bb
commit
a94fa0d465
4 changed files with 40 additions and 35 deletions
|
|
@ -114,7 +114,7 @@ export default {
|
||||||
'terminal': `${dirCss}/terminal.css`,
|
'terminal': `${dirCss}/terminal.css`,
|
||||||
'user-menu': `${dirCss}/user-menu.css`,
|
'user-menu': `${dirCss}/user-menu.css`,
|
||||||
'sw': `${dir}/sw/sw.js`,
|
'sw': `${dir}/sw/sw.js`,
|
||||||
'cloudcmd': `${dir}/cloudcmd.js`,
|
'cloudcmd': `${dir}/cloudcmd.mjs`,
|
||||||
[`${modules}/edit`]: `${dirModules}/edit.js`,
|
[`${modules}/edit`]: `${dirModules}/edit.js`,
|
||||||
[`${modules}/edit-file`]: `${dirModules}/edit-file.js`,
|
[`${modules}/edit-file`]: `${dirModules}/edit-file.js`,
|
||||||
[`${modules}/edit-file-vim`]: `${dirModules}/edit-file-vim.js`,
|
[`${modules}/edit-file-vim`]: `${dirModules}/edit-file-vim.js`,
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,11 @@ const isDev = process.env.NODE_ENV === 'development';
|
||||||
|
|
||||||
inherits(CloudCmdProto, Emitify);
|
inherits(CloudCmdProto, Emitify);
|
||||||
|
|
||||||
export const createCloudCmd = (DOM) => {
|
export const createCloudCmd = ({DOM, Listeners}) => {
|
||||||
return new CloudCmdProto(DOM);
|
return new CloudCmdProto({
|
||||||
|
DOM,
|
||||||
|
Listeners,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
load.addErrorListener((e, src) => {
|
load.addErrorListener((e, src) => {
|
||||||
|
|
@ -35,9 +38,7 @@ load.addErrorListener((e, src) => {
|
||||||
Images.show.error(msg);
|
Images.show.error(msg);
|
||||||
});
|
});
|
||||||
|
|
||||||
function CloudCmdProto(DOM) {
|
function CloudCmdProto({DOM, Listeners}) {
|
||||||
let Listeners;
|
|
||||||
|
|
||||||
Emitify.call(this);
|
Emitify.call(this);
|
||||||
|
|
||||||
const CloudCmd = this;
|
const CloudCmd = this;
|
||||||
|
|
@ -224,7 +225,6 @@ function CloudCmdProto(DOM) {
|
||||||
|
|
||||||
const dirPath = DOM.getCurrentDirPath();
|
const dirPath = DOM.getCurrentDirPath();
|
||||||
|
|
||||||
({Listeners} = CloudCmd);
|
|
||||||
Listeners.init();
|
Listeners.init();
|
||||||
|
|
||||||
const panels = getPanels();
|
const panels = getPanels();
|
||||||
|
|
|
||||||
|
|
@ -1,33 +1,32 @@
|
||||||
'use strict';
|
import process from 'node:process';
|
||||||
|
import wraptile from 'wraptile';
|
||||||
const process = require('node:process');
|
import load from 'load.js';
|
||||||
require('../css/main.css');
|
import '../css/main.css';
|
||||||
|
import {registerSW, listenSW} from './sw/register.js';
|
||||||
const wraptile = require('wraptile');
|
import {initSortPanel, sortPanel} from './sort.mjs';
|
||||||
const load = require('load.js');
|
import Util from '../common/util.js';
|
||||||
|
import * as CloudFunc from '../common/cloudfunc.mjs';
|
||||||
const {registerSW, listenSW} = require('./sw/register');
|
import DOM from './dom/index.js';
|
||||||
const {initSortPanel, sortPanel} = require('./sort.mjs');
|
import {createCloudCmd} from './client.mjs';
|
||||||
const Util = require('../common/util');
|
import * as Listeners from './listeners/index.js';
|
||||||
const CloudFunc = require('../common/cloudfunc.mjs');
|
|
||||||
const DOM = require('./dom');
|
|
||||||
const {createCloudCmd} = require('./client.mjs');
|
|
||||||
|
|
||||||
const isDev = process.env.NODE_ENV === 'development';
|
const isDev = process.env.NODE_ENV === 'development';
|
||||||
|
|
||||||
module.exports = init;
|
export default init;
|
||||||
|
|
||||||
|
globalThis.CloudCmd = init;
|
||||||
|
|
||||||
async function init(config) {
|
async function init(config) {
|
||||||
globalThis.CloudCmd = createCloudCmd(DOM);
|
globalThis.CloudCmd = createCloudCmd({
|
||||||
|
DOM,
|
||||||
|
Listeners,
|
||||||
|
});
|
||||||
globalThis.DOM = DOM;
|
globalThis.DOM = DOM;
|
||||||
globalThis.Util = Util;
|
globalThis.Util = Util;
|
||||||
globalThis.CloudFunc = CloudFunc;
|
globalThis.CloudFunc = CloudFunc;
|
||||||
|
|
||||||
await register(config);
|
await register(config);
|
||||||
|
|
||||||
require('./listeners');
|
|
||||||
require('./key');
|
|
||||||
|
|
||||||
initSortPanel();
|
initSortPanel();
|
||||||
globalThis.CloudCmd.sortPanel = sortPanel;
|
globalThis.CloudCmd.sortPanel = sortPanel;
|
||||||
const prefix = getPrefix(config.prefix);
|
const prefix = getPrefix(config.prefix);
|
||||||
|
|
@ -41,8 +40,6 @@ async function init(config) {
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
globalThis.CloudCmd = init;
|
|
||||||
|
|
||||||
function getPrefix(prefix) {
|
function getPrefix(prefix) {
|
||||||
if (!prefix)
|
if (!prefix)
|
||||||
return '';
|
return '';
|
||||||
|
|
@ -75,3 +72,4 @@ async function register(config) {
|
||||||
|
|
||||||
listenSW(sw, 'updatefound', onUpdateFound(config));
|
listenSW(sw, 'updatefound', onUpdateFound(config));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -29,8 +29,6 @@ module.exports.init = async () => {
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
CloudCmd.Listeners = module.exports;
|
|
||||||
|
|
||||||
const unselect = (event) => {
|
const unselect = (event) => {
|
||||||
const isMac = /Mac/.test(globalThis.navigator.platform);
|
const isMac = /Mac/.test(globalThis.navigator.platform);
|
||||||
const {
|
const {
|
||||||
|
|
@ -50,9 +48,6 @@ const execAll = currify((funcs, event) => {
|
||||||
fn(event);
|
fn(event);
|
||||||
});
|
});
|
||||||
|
|
||||||
const Info = DOM.CurrentInfo;
|
|
||||||
const {Events} = DOM;
|
|
||||||
|
|
||||||
const EventsFiles = {
|
const EventsFiles = {
|
||||||
mousedown: exec.with(execIfNotUL, setCurrentFileByEvent),
|
mousedown: exec.with(execIfNotUL, setCurrentFileByEvent),
|
||||||
click: execAll([onClick, exec.with(execIfNotMobile, unselect)]),
|
click: execAll([onClick, exec.with(execIfNotMobile, unselect)]),
|
||||||
|
|
@ -70,6 +65,8 @@ function header() {
|
||||||
return /^js-(left|right)$/.test(el.dataset.name);
|
return /^js-(left|right)$/.test(el.dataset.name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const {Events} = DOM;
|
||||||
|
|
||||||
Events.addClick(fm, (event) => {
|
Events.addClick(fm, (event) => {
|
||||||
const el = event.target;
|
const el = event.target;
|
||||||
const parent = el.parentElement;
|
const parent = el.parentElement;
|
||||||
|
|
@ -106,6 +103,7 @@ async function config() {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.initKeysPanel = () => {
|
module.exports.initKeysPanel = () => {
|
||||||
|
const {Events} = DOM;
|
||||||
const keysElement = DOM.getById('js-keyspanel');
|
const keysElement = DOM.getById('js-keyspanel');
|
||||||
|
|
||||||
if (!keysElement)
|
if (!keysElement)
|
||||||
|
|
@ -152,6 +150,7 @@ const getPanel = (side) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.setOnPanel = (side) => {
|
module.exports.setOnPanel = (side) => {
|
||||||
|
const {Events} = DOM;
|
||||||
const panel = getPanel(side);
|
const panel = getPanel(side);
|
||||||
|
|
||||||
const filesElement = DOM.getByDataName('js-files', panel);
|
const filesElement = DOM.getByDataName('js-files', panel);
|
||||||
|
|
@ -167,6 +166,7 @@ function getPathListener(panel) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function isNoCurrent(panel) {
|
function isNoCurrent(panel) {
|
||||||
|
const Info = DOM.CurrentInfo;
|
||||||
const infoPanel = Info.panel;
|
const infoPanel = Info.panel;
|
||||||
|
|
||||||
if (!infoPanel)
|
if (!infoPanel)
|
||||||
|
|
@ -191,6 +191,7 @@ function decodePath(path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onPathElementClick(panel, event) {
|
async function onPathElementClick(panel, event) {
|
||||||
|
const Info = DOM.CurrentInfo;
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
const element = event.target;
|
const element = event.target;
|
||||||
|
|
@ -261,6 +262,7 @@ function toggleSelect(key, files) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function changePanel(element) {
|
function changePanel(element) {
|
||||||
|
const Info = DOM.CurrentInfo;
|
||||||
const {panel} = Info;
|
const {panel} = Info;
|
||||||
const files = DOM.getByDataName('js-files', panel);
|
const files = DOM.getByDataName('js-files', panel);
|
||||||
const ul = getULElement(element);
|
const ul = getULElement(element);
|
||||||
|
|
@ -302,6 +304,7 @@ async function onTouch(event) {
|
||||||
* in Chrome (HTML5)
|
* in Chrome (HTML5)
|
||||||
*/
|
*/
|
||||||
function onDragStart(event) {
|
function onDragStart(event) {
|
||||||
|
const Info = DOM.CurrentInfo;
|
||||||
const {prefixURL} = CloudCmd;
|
const {prefixURL} = CloudCmd;
|
||||||
const element = getLIElement(event.target);
|
const element = getLIElement(event.target);
|
||||||
const {isDir} = Info;
|
const {isDir} = Info;
|
||||||
|
|
@ -338,6 +341,7 @@ function getULElement(element) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function setCurrentFileByEvent(event) {
|
function setCurrentFileByEvent(event) {
|
||||||
|
const Info = DOM.CurrentInfo;
|
||||||
const BUTTON_LEFT = 0;
|
const BUTTON_LEFT = 0;
|
||||||
|
|
||||||
const key = {
|
const key = {
|
||||||
|
|
@ -376,6 +380,7 @@ function getFilesRange(from, to) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function contextMenu() {
|
function contextMenu() {
|
||||||
|
const {Events} = DOM;
|
||||||
const fm = DOM.getFM();
|
const fm = DOM.getFM();
|
||||||
|
|
||||||
Events.addOnce('contextmenu', fm, (event) => {
|
Events.addOnce('contextmenu', fm, (event) => {
|
||||||
|
|
@ -391,6 +396,7 @@ function contextMenu() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function dragndrop() {
|
function dragndrop() {
|
||||||
|
const {Events} = DOM;
|
||||||
const panels = DOM.getByClassAll('panel');
|
const panels = DOM.getByClassAll('panel');
|
||||||
const select = ({target}) => {
|
const select = ({target}) => {
|
||||||
target.classList.add('selected-panel');
|
target.classList.add('selected-panel');
|
||||||
|
|
@ -464,7 +470,7 @@ function unload() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function pop() {
|
function pop() {
|
||||||
Events.add('popstate', async ({state}) => {
|
DOM.Events.add('popstate', async ({state}) => {
|
||||||
const path = (state || '').replace(FS, '');
|
const path = (state || '').replace(FS, '');
|
||||||
|
|
||||||
if (!path)
|
if (!path)
|
||||||
|
|
@ -479,7 +485,8 @@ function pop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function resize() {
|
function resize() {
|
||||||
Events.add('resize', () => {
|
DOM.Events.add('resize', () => {
|
||||||
|
const Info = DOM.CurrentInfo;
|
||||||
const is = globalThis.innerWidth < CloudCmd.MIN_ONE_PANEL_WIDTH;
|
const is = globalThis.innerWidth < CloudCmd.MIN_ONE_PANEL_WIDTH;
|
||||||
|
|
||||||
if (!is)
|
if (!is)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue