feature: client: key: vim: migrate to ESM

This commit is contained in:
coderiaser 2026-01-28 23:00:50 +02:00
parent 9ab2cec877
commit 265c0b491a
10 changed files with 31 additions and 53 deletions

View file

@ -4,7 +4,7 @@ import {fullstore} from 'fullstore';
import * as Events from '#dom/events';
import * as Buffer from '../dom/buffer.mjs';
import * as KEY from './key.mjs';
import _vim from './vim/index.js';
import _vim from './vim/index.mjs';
import setCurrentByChar from './set-current-by-char.mjs';
import {createBinder} from './binder.mjs';

View file

@ -2,7 +2,7 @@ import autoGlobals from 'auto-globals';
import supertape from 'supertape';
import {ESC} from './key.mjs';
import {Key, _listener} from './index.mjs';
import {getDOM, getCloudCmd} from './vim/globals.fixture.js';
import {getDOM, getCloudCmd} from './vim/globals.fixture.mjs';
const test = autoGlobals(supertape);
const {stub} = supertape;

View file

@ -1,12 +1,10 @@
'use strict';
const {fullstore} = require('fullstore');
const limier = require('limier');
import {fullstore} from 'fullstore';
import limier from 'limier';
const searchStore = fullstore([]);
const searchIndex = fullstore(0);
module.exports.find = (value, names) => {
export const find = (value, names) => {
const result = limier(value, names);
searchStore(result);
@ -15,7 +13,7 @@ module.exports.find = (value, names) => {
return result;
};
module.exports.findNext = () => {
export const findNext = () => {
const names = searchStore();
const index = next(searchIndex(), names.length);
@ -23,7 +21,7 @@ module.exports.findNext = () => {
return names[searchIndex()];
};
module.exports.findPrevious = () => {
export const findPrevious = () => {
const names = searchStore();
const index = previous(searchIndex(), names.length);
@ -31,8 +29,8 @@ module.exports.findPrevious = () => {
return names[index];
};
module.exports._next = next;
module.exports._previous = previous;
export const _next = next;
export const _previous = previous;
function next(index, length) {
if (index === length - 1)

View file

@ -1,14 +1,9 @@
'use strict';
const test = require('supertape');
const dir = './';
const {getDOM} = require('./globals.fixture');
import test from 'supertape';
import {getDOM} from './globals.fixture.mjs';
import {_next, _previous} from './find.mjs';
globalThis.DOM = getDOM();
const {_next, _previous} = require(`${dir}find`);
test('cloudcmd: client: vim: _next', (t) => {
const result = _next(1, 2);

View file

@ -1,8 +1,6 @@
'use strict';
const noop = () => {};
module.exports.getDOM = () => {
export const getDOM = () => {
const prompt = Promise.resolve.bind(Promise);
const CurrentInfo = {
element: {},
@ -34,7 +32,7 @@ module.exports.getDOM = () => {
};
};
module.exports.getCloudCmd = () => {
export const getCloudCmd = () => {
const show = () => {};
return {

View file

@ -1,15 +1,13 @@
'use strict';
/* global CloudCmd */
/* global DOM */
const vim = require('./vim');
const finder = require('./find');
const {
import vim from './vim.mjs';
import * as finder from './find.mjs';
import {
setCurrent,
selectFileNotParent,
} = require('./set-current');
} from './set-current.mjs';
module.exports = (key, event, overrides = {}) => {
export default (key, event, overrides = {}) => {
const defaults = {
...globalThis.DOM,
...globalThis.CloudCmd,
@ -131,7 +129,7 @@ const getOperations = (event, deps) => {
};
};
module.exports.selectFile = selectFileNotParent;
export const selectFile = selectFileNotParent;
const _createFindPrevious = (overrides = {}) => () => {
const {setCurrentByName} = overrides;

View file

@ -1,14 +1,10 @@
'use strict';
const {test, stub} = require('supertape');
const {getDOM, getCloudCmd} = require('./globals.fixture');
import {test, stub} from 'supertape';
import {getDOM, getCloudCmd} from './globals.fixture.mjs';
import vim, {selectFile as vimSelectFile} from './index.mjs';
globalThis.DOM = getDOM();
globalThis.CloudCmd = getCloudCmd();
const vim = require('./index.js');
const {assign} = Object;
const {DOM} = globalThis;
const {Buffer} = DOM;
@ -312,7 +308,7 @@ test('cloudcmd: client: key: selectFile: ..', (t) => {
const selectFile = stub();
const current = {};
vim.selectFile(current, {
vimSelectFile(current, {
selectFile,
getCurrentName,
});
@ -326,7 +322,7 @@ test('cloudcmd: client: key: selectFile', (t) => {
const getCurrentName = stub().returns('x');
const current = {};
vim.selectFile(current, {
vimSelectFile(current, {
selectFile,
getCurrentName,
});

View file

@ -1,8 +1,5 @@
'use strict';
/* global DOM */
module.exports.selectFileNotParent = selectFileNotParent;
function selectFileNotParent(current, {getCurrentName, selectFile} = DOM) {
export function selectFileNotParent(current, {getCurrentName, selectFile} = DOM) {
const name = getCurrentName(current);
if (name === '..')
@ -11,7 +8,7 @@ function selectFileNotParent(current, {getCurrentName, selectFile} = DOM) {
selectFile(current);
}
module.exports.setCurrent = (sibling, {count, isVisual, isDelete}, {Info, setCurrentFile, unselectFiles, Operation}) => {
export const setCurrent = (sibling, {count, isVisual, isDelete}, {Info, setCurrentFile, unselectFiles, Operation}) => {
let current = Info.element;
const select = isVisual ? selectFileNotParent : unselectFiles;

View file

@ -1,6 +1,5 @@
'use strict';
import {fullstore} from 'fullstore';
const {fullstore} = require('fullstore');
const store = fullstore('');
const visual = fullstore(false);
@ -21,7 +20,7 @@ const rmFirst = (a) => {
const noop = () => {};
module.exports = (key, operations = {}) => {
export default (key, operations = {}) => {
const prevStore = store();
const isVisual = visual();
const value = store(prevStore.concat(key));

View file

@ -1,8 +1,5 @@
'use strict';
const {test, stub} = require('supertape');
const vim = require('./vim');
import {test, stub} from 'supertape';
import vim from './vim.mjs';
test('vim: no operations', (t) => {
const result = vim('hello', {});