diff --git a/client/dom/index.mjs b/client/dom/index.mjs index 456571e2..d19c8009 100644 --- a/client/dom/index.mjs +++ b/client/dom/index.mjs @@ -11,7 +11,7 @@ import renameCurrent from './operations/rename-current.mjs'; import * as CurrentFile from './current-file.mjs'; import * as DOMTree from './dom-tree.mjs'; import * as Cmd from './cmd.mjs'; -import IO from './io/index.js'; +import * as IO from './io/index.mjs'; import {uploadDirectory} from './directory.mjs'; import * as Buffer from './buffer.mjs'; import {loadRemote as _loadRemote} from './load-remote.mjs'; diff --git a/client/dom/io/index.js b/client/dom/io/index.mjs similarity index 78% rename from client/dom/io/index.js rename to client/dom/io/index.mjs index d69d31af..b0c55e0a 100644 --- a/client/dom/io/index.js +++ b/client/dom/io/index.mjs @@ -1,13 +1,11 @@ -'use strict'; - -const {FS} = require('#common/cloudfunc'); -const _sendRequest = require('./send-request'); +import {FS} from '#common/cloudfunc'; +import {sendRequest as _sendRequest} from './send-request.mjs'; const imgPosition = { top: true, }; -module.exports.delete = async (url, data) => { +export const remove = async (url, data) => { return await _sendRequest({ method: 'DELETE', url: FS + url, @@ -18,7 +16,7 @@ module.exports.delete = async (url, data) => { }); }; -module.exports.patch = async (url, data) => { +export const patch = async (url, data) => { return await _sendRequest({ method: 'PATCH', url: FS + url, @@ -27,7 +25,7 @@ module.exports.patch = async (url, data) => { }); }; -module.exports.write = async (url, data) => { +export const write = async (url, data) => { return await _sendRequest({ method: 'PUT', url: FS + url, @@ -36,7 +34,7 @@ module.exports.write = async (url, data) => { }); }; -module.exports.createDirectory = async (url, overrides = {}) => { +export const createDirectory = async (url, overrides = {}) => { const { sendRequest = _sendRequest, } = overrides; @@ -48,7 +46,7 @@ module.exports.createDirectory = async (url, overrides = {}) => { }); }; -module.exports.read = async (url, dataType = 'text') => { +export const read = async (url, dataType = 'text') => { const notLog = !url.includes('?'); return await _sendRequest({ @@ -59,7 +57,7 @@ module.exports.read = async (url, dataType = 'text') => { }); }; -module.exports.copy = async (from, to, names) => { +export const copy = async (from, to, names) => { return await _sendRequest({ method: 'PUT', url: '/copy', @@ -72,7 +70,7 @@ module.exports.copy = async (from, to, names) => { }); }; -module.exports.pack = async (data) => { +export const pack = async (data) => { return await _sendRequest({ method: 'PUT', url: '/pack', @@ -80,7 +78,7 @@ module.exports.pack = async (data) => { }); }; -module.exports.extract = async (data) => { +export const extract = async (data) => { return await _sendRequest({ method: 'PUT', url: '/extract', @@ -88,7 +86,7 @@ module.exports.extract = async (data) => { }); }; -module.exports.move = async (from, to, names) => { +export const move = async (from, to, names) => { return await _sendRequest({ method: 'PUT', url: '/move', @@ -101,7 +99,7 @@ module.exports.move = async (from, to, names) => { }); }; -module.exports.rename = async (from, to) => { +export const rename = async (from, to) => { return await _sendRequest({ method: 'PUT', url: '/rename', @@ -113,7 +111,7 @@ module.exports.rename = async (from, to) => { }); }; -module.exports.Config = { +export const Config = { read: async () => { return await _sendRequest({ method: 'GET', @@ -133,7 +131,7 @@ module.exports.Config = { }, }; -module.exports.Markdown = { +export const Markdown = { read: async (url) => { return await _sendRequest({ method: 'GET', diff --git a/client/dom/io/index.spec.js b/client/dom/io/index.spec.mjs similarity index 80% rename from client/dom/io/index.spec.js rename to client/dom/io/index.spec.mjs index 19ebe5bd..ec2f0dfc 100644 --- a/client/dom/io/index.spec.js +++ b/client/dom/io/index.spec.mjs @@ -1,7 +1,5 @@ -'use strict'; - -const {test, stub} = require('supertape'); -const io = require('.'); +import {test, stub} from 'supertape'; +import * as io from './index.mjs'; test('client: dom: io', (t) => { const sendRequest = stub(); diff --git a/client/dom/io/send-request.js b/client/dom/io/send-request.mjs similarity index 80% rename from client/dom/io/send-request.js rename to client/dom/io/send-request.mjs index e32edc56..177d34b5 100644 --- a/client/dom/io/send-request.js +++ b/client/dom/io/send-request.mjs @@ -1,12 +1,9 @@ -'use strict'; - /* global CloudCmd */ -const {promisify} = require('es6-promisify'); +import {promisify} from 'es6-promisify'; +import * as Images from '#dom/images'; +import * as load from '#dom/load'; -const Images = require('#dom/images'); -const load = require('#dom/load'); - -module.exports = promisify((params, callback) => { +export const sendRequest = promisify((params, callback) => { const p = params; const {prefixURL} = CloudCmd; @@ -40,7 +37,8 @@ module.exports = promisify((params, callback) => { }); }); -module.exports._replaceHash = replaceHash; +export const _replaceHash = replaceHash; + function replaceHash(url) { /* * if we send ajax request - diff --git a/client/dom/io/send-request.spec.js b/client/dom/io/send-request.spec.mjs similarity index 69% rename from client/dom/io/send-request.spec.js rename to client/dom/io/send-request.spec.mjs index d0c7aa88..9b151a3c 100644 --- a/client/dom/io/send-request.spec.js +++ b/client/dom/io/send-request.spec.mjs @@ -1,7 +1,5 @@ -'use strict'; - -const {test} = require('supertape'); -const {_replaceHash} = require('./send-request'); +import {test} from 'supertape'; +import {_replaceHash} from './send-request.mjs'; test('cloudcmd: client: io: replaceHash', (t) => { const url = '/hello/####world'; diff --git a/client/dom/rest.mjs b/client/dom/rest.mjs index 75562419..99504cb6 100644 --- a/client/dom/rest.mjs +++ b/client/dom/rest.mjs @@ -2,7 +2,7 @@ import {tryToCatch} from 'try-to-catch'; import * as Dialog from '#dom/dialog'; import * as Images from '#dom/images'; import {encode} from '#common/entity'; -import IO from './io/index.js'; +import * as IO from './io/index.mjs'; const handleError = (promise) => async (...args) => { const [e, data] = await tryToCatch(promise, ...args); @@ -18,7 +18,7 @@ const handleError = (promise) => async (...args) => { return [e, data]; }; -export const remove = handleError(IO.delete); +export const remove = handleError(IO.remove); export const patch = handleError(IO.patch); export const write = handleError(IO.write); export const createDirectory = handleError(IO.createDirectory); diff --git a/client/modules/markdown.mjs b/client/modules/markdown.mjs index b125717a..c94c64e8 100644 --- a/client/modules/markdown.mjs +++ b/client/modules/markdown.mjs @@ -4,6 +4,7 @@ import {Markdown} from '#dom/rest'; import {alert} from '#dom/dialog'; const {CloudCmd} = globalThis; + CloudCmd.Markdown = { init, show,