feature: client: load: migrate to ESM

This commit is contained in:
coderiaser 2026-01-27 20:40:17 +02:00
parent 116430e542
commit 41b5a96fa6
9 changed files with 19 additions and 22 deletions

View file

@ -4,7 +4,7 @@
const itype = require('itype');
const {promisify} = require('es6-promisify');
const load = require('./load');
const load = require('#dom/load');
const RESTful = require('./rest');
const Promises = {};

View file

@ -21,7 +21,7 @@ const DOM = {
const CurrentInfo = {};
DOM.Images = Images;
DOM.load = require('./load');
DOM.load = require('#dom/load');
DOM.Files = require('./files');
DOM.RESTful = RESTful;
DOM.IO = require('./io');

View file

@ -4,7 +4,7 @@
const {promisify} = require('es6-promisify');
const Images = require('../images.mjs');
const load = require('../load');
const load = require('#dom/load');
module.exports = promisify((params, callback) => {
const p = params;
@ -46,5 +46,5 @@ function replaceHash(url) {
* if we send ajax request -
* no need in hash so we escape #
*/
return url.replace(/#/g, '%23');
return url.replace(/#/g, '%' + '23');
}

View file

@ -1,19 +1,16 @@
'use strict';
import itype from 'itype';
import jonny from 'jonny';
import Emitify from 'emitify';
import exec from 'execon';
import * as Images from './images.mjs';
const itype = require('itype');
const jonny = require('jonny');
const Emitify = require('emitify');
const exec = require('execon');
const Images = require('./images.mjs');
module.exports.getIdBySrc = getIdBySrc;
/**
* Function gets id by src
* @param src
*
* Example: http://domain.com/1.js -> 1_js
*/
function getIdBySrc(src) {
export function getIdBySrc(src) {
const isStr = itype.string(src);
if (!isStr)
@ -37,7 +34,7 @@ function getIdBySrc(src) {
*
* @param params
*/
module.exports.ajax = (params) => {
export const ajax = (params) => {
const p = params;
const isObject = itype.object(p.data);
const isArray = itype.array(p.data);
@ -94,11 +91,11 @@ module.exports.ajax = (params) => {
xhr.send(data);
};
module.exports.put = (url, body) => {
export const put = (url, body) => {
const emitter = Emitify();
const xhr = new XMLHttpRequest();
url = encodeURI(url).replace(/#/g, '%23');
url = encodeURI(url).replace(/#/g, '#');
xhr.open('put', url, true);

View file

@ -4,7 +4,7 @@
const {eachSeries} = require('execon');
const wraptile = require('wraptile');
const load = require('./load');
const load = require('#dom/load');
const Images = require('./images.mjs');
const {alert} = require('./dialog');

View file

@ -6,7 +6,7 @@ const exec = require('execon');
const currify = require('currify');
const load = require('load.js');
const {ajax} = require('../dom/load');
const {ajax} = require('#dom/load');
const Files = require('../dom/files');
const Images = require('../dom/images.mjs');

View file

@ -7,7 +7,7 @@ const wrap = require('wraptile');
const createElement = require('@cloudcmd/create-element');
const {FS} = require('../../../common/cloudfunc.mjs');
const {getIdBySrc} = require('../../dom/load');
const {getIdBySrc} = require('#dom/load');
const RESTful = require('../../dom/rest');
const {config, Key} = CloudCmd;
@ -298,7 +298,7 @@ function download(type) {
* no need in hash so we escape #
* and all other characters, like "%"
*/
const encodedPath = encodeURI(path).replace(/#/g, '%23');
const encodedPath = encodeURI(path).replace(/#/g, '#');
const id = getIdBySrc(path);
let src;

View file

@ -96,4 +96,3 @@ async function addToCache(request, response) {
const cache = await caches.open(NAME);
return cache.put(request, response);
}

View file

@ -219,7 +219,8 @@
"webpackbar": "^7.0.0"
},
"imports": {
"#dom/events": "./client/dom/events/index.mjs"
"#dom/events": "./client/dom/events/index.mjs",
"#dom/load": "./client/dom/load.mjs"
},
"engines": {
"node": ">=22"