From 6e778a35baf372b6230c306f6bb644481ef2833f Mon Sep 17 00:00:00 2001 From: coderiaser Date: Thu, 15 Jan 2026 18:03:09 +0200 Subject: [PATCH] feature: client: sort: migrate to ESM --- client/cloudcmd.js | 6 ++++-- client/sort.mjs | 26 ++++++++++++++++---------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/client/cloudcmd.js b/client/cloudcmd.js index d4bac384..152cf865 100644 --- a/client/cloudcmd.js +++ b/client/cloudcmd.js @@ -7,6 +7,7 @@ const wraptile = require('wraptile'); const load = require('load.js'); const {registerSW, listenSW} = require('./sw/register'); +const {initSortPanel, sortPanel} = require('./sort.mjs'); const isDev = process.env.NODE_ENV === 'development'; @@ -21,11 +22,12 @@ module.exports = async (config) => { require('./listeners'); require('./key'); - require('./sort'); + initSortPanel(); + globalThis.CloudCmd.sortPanel = sortPanel; const prefix = getPrefix(config.prefix); - window.CloudCmd.init(prefix, config); + globalThis.CloudCmd.init(prefix, config); if (window.CloudCmd.config('menu') === 'aleman') setTimeout(() => { diff --git a/client/sort.mjs b/client/sort.mjs index cf9fb4a4..5625b433 100644 --- a/client/sort.mjs +++ b/client/sort.mjs @@ -1,26 +1,31 @@ -'use strict'; - /* global CloudCmd */ -const DOM = require('./dom'); +import {fullstore} from 'fullstore'; +import DOM from './dom/index.js'; -const Info = DOM.CurrentInfo; -const {sort, order} = CloudCmd; -const position = DOM.getPanelPosition(); -let sortPrevious = sort[position]; +const sortPrevious = fullstore(); const {getPanel} = DOM; -CloudCmd.sortPanel = (name, panel = getPanel()) => { +export const initSortPanel = () => { + const {sort, order} = CloudCmd; + const position = DOM.getPanelPosition(); + + sortPrevious(sort[position]); +}; + +export const sortPanel = (name, panel = getPanel()) => { + const {sort, order} = CloudCmd; + const Info = DOM.CurrentInfo; const position = panel.dataset.name.replace('js-', ''); - if (name !== sortPrevious) + if (name !== sortPrevious()) order[position] = 'asc'; else if (order[position] === 'asc') order[position] = 'desc'; else order[position] = 'asc'; - sortPrevious = name; + sortPrevious(name); sort[position] = name; const noCurrent = position !== Info.panelPosition; @@ -29,3 +34,4 @@ CloudCmd.sortPanel = (name, panel = getPanel()) => { noCurrent, }); }; +