From 983fd9af3d70758d1934eefb4c783d5109f604c2 Mon Sep 17 00:00:00 2001 From: coderiaser Date: Mon, 2 Feb 2026 22:36:19 +0200 Subject: [PATCH] feature: client: edit: migrate to ESM --- .webpack/js.mjs | 2 +- client/modules/{edit.js => edit.mjs} | 47 ++++++++++-------- client/modules/operation/index.mjs | 24 +++++----- client/modules/view/index.mjs | 2 +- common/cloudfunc.mjs | 71 ++++++++++++++-------------- 5 files changed, 76 insertions(+), 70 deletions(-) rename client/modules/{edit.js => edit.mjs} (76%) diff --git a/.webpack/js.mjs b/.webpack/js.mjs index 434a397c..50cf4caa 100644 --- a/.webpack/js.mjs +++ b/.webpack/js.mjs @@ -119,7 +119,7 @@ export default { 'user-menu': `${dirCss}/user-menu.css`, 'sw': `${dir}/sw/sw.mjs`, 'cloudcmd': `${dir}/cloudcmd.mjs`, - [`${modules}/edit`]: `${dirModules}/edit.js`, + [`${modules}/edit`]: `${dirModules}/edit.mjs`, [`${modules}/edit-file`]: `${dirModules}/edit-file.js`, [`${modules}/edit-file-vim`]: `${dirModules}/edit-file-vim.js`, [`${modules}/edit-names`]: `${dirModules}/edit-names.js`, diff --git a/client/modules/edit.js b/client/modules/edit.mjs similarity index 76% rename from client/modules/edit.js rename to client/modules/edit.mjs index 55ec0465..1b726284 100644 --- a/client/modules/edit.js +++ b/client/modules/edit.mjs @@ -1,23 +1,28 @@ /* global CloudCmd */ +import montag from 'montag'; +import {promisify} from 'es6-promisify'; +import {tryToCatch} from 'try-to-catch'; +import createElement from '@cloudcmd/create-element'; +import load from 'load.js'; +import {MAX_FILE_SIZE as maxSize} from '#common/cloudfunc'; +import {time, timeEnd} from '#common/util'; -'use strict'; +export function getEditor() { + return editor; +} -const montag = require('montag'); - -const {promisify} = require('es6-promisify'); -const {tryToCatch} = require('try-to-catch'); -const createElement = require('@cloudcmd/create-element'); -const load = require('load.js'); -const {MAX_FILE_SIZE: maxSize} = require('#common/cloudfunc'); - -const {time, timeEnd} = require('#common/util'); -const getEditor = () => editor; const isFn = (a) => typeof a === 'function'; const loadJS = load.js; const Name = 'Edit'; -CloudCmd[Name] = exports; +CloudCmd[Name] = { + init, + show, + hide, + getEditor, + getElement, +}; const EditorName = CloudCmd.config('editor'); @@ -33,12 +38,12 @@ const ConfigView = { }, }; -module.exports.init = async () => { +export async function init() { const element = create(); await CloudCmd.View(); await loadFiles(element); -}; +} function create() { const element = createElement('div', { @@ -79,7 +84,7 @@ function initConfig(options = {}) { return config; } -module.exports.show = (options) => { +export function show(options) { if (Loading) return; @@ -88,15 +93,15 @@ module.exports.show = (options) => { getEditor().setOptions({ fontSize: 16, }); -}; +} -module.exports.getEditor = getEditor; +export function getElement() { + return Element; +} -module.exports.getElement = () => Element; - -module.exports.hide = () => { +export function hide() { CloudCmd.View.hide(); -}; +} const loadFiles = async (element) => { const prefix = `${CloudCmd.prefix}/${EditorName}`; diff --git a/client/modules/operation/index.mjs b/client/modules/operation/index.mjs index 4ee9f6f8..1243a3d4 100644 --- a/client/modules/operation/index.mjs +++ b/client/modules/operation/index.mjs @@ -51,19 +51,19 @@ export const init = promisify((callback) => { exec.series([ DOM.loadSocket, async (callback) => { - if (config('dropbox')) - return callback(); - - const {prefix, prefixSocket} = CloudCmd; - - await loadAll(); - await initOperations(prefix, prefixSocket, callback); - }, + if (config('dropbox')) + return callback(); + + const {prefix, prefixSocket} = CloudCmd; + + await loadAll(); + await initOperations(prefix, prefixSocket, callback); + }, (callback) => { - Loaded = true; - Images.hide(); - callback(); - }, + Loaded = true; + Images.hide(); + callback(); + }, ], callback); }); diff --git a/client/modules/view/index.mjs b/client/modules/view/index.mjs index c843765c..da19f542 100644 --- a/client/modules/view/index.mjs +++ b/client/modules/view/index.mjs @@ -11,12 +11,12 @@ import * as Files from '#dom/files'; import * as Events from '#dom/events'; import {FS} from '#common/cloudfunc'; import * as Images from '#dom/images'; +import {encode} from '#common/entity'; import { isImage, isAudio, getType, } from './types.mjs'; -import {encode} from '#common/entity'; const CloudCmd = globalThis.CloudCmd || {}; const DOM = globalThis.DOM || {}; diff --git a/common/cloudfunc.mjs b/common/cloudfunc.mjs index fa1ca806..3a9f61ba 100644 --- a/common/cloudfunc.mjs +++ b/common/cloudfunc.mjs @@ -168,6 +168,7 @@ export const buildFromJSON = (params) => { Path(path); fileTable += `${header}';