Skip to content

Commit ebabad9

Browse files
committed
feature: common: entity: migrate to ESM
1 parent c3b7165 commit ebabad9

10 files changed

Lines changed: 61 additions & 66 deletions

File tree

client/dom/current-file.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* global CloudCmd */
33
import createElement from '@cloudcmd/create-element';
44
import {getTitle, FS} from '#common/cloudfunc';
5-
import {encode, decode} from '../../common/entity.js';
5+
import {encode, decode} from '#common/entity';
66

77
let Title;
88

client/dom/rest.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {tryToCatch} from 'try-to-catch';
22
import * as Dialog from '#dom/dialog';
3-
import {encode} from '../../common/entity.js';
43
import * as Images from '#dom/images';
4+
import {encode} from '#common/entity';
55
import IO from './io/index.js';
66

77
const handleError = (promise) => async (...args) => {

client/modules/config/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import createElement from '@cloudcmd/create-element';
1111
import * as Events from '#dom/events';
1212
import * as Files from '#dom/files';
1313
import {getTitle} from '#common/cloudfunc';
14-
import * as input from './input.mjs';
1514
import * as Images from '#dom/images';
15+
import * as input from './input.mjs';
1616

1717
const {Dialog, setTitle} = DOM;
1818

client/modules/operation/index.mjs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {promisify} from 'es6-promisify';
44
import exec from 'execon';
55
import load from 'load.js';
66
import {tryToCatch} from 'try-to-catch';
7-
import {encode} from '../../../common/entity.js';
7+
import {encode} from '#common/entity';
88
import {removeExtension} from './remove-extension.mjs';
99
import {setListeners} from './set-listeners.mjs';
1010
import {getNextCurrentName} from './get-next-current-name.mjs';
@@ -51,19 +51,19 @@ export const init = promisify((callback) => {
5151
exec.series([
5252
DOM.loadSocket,
5353
async (callback) => {
54-
if (config('dropbox'))
55-
return callback();
56-
57-
const {prefix, prefixSocket} = CloudCmd;
58-
59-
await loadAll();
60-
await initOperations(prefix, prefixSocket, callback);
61-
},
54+
if (config('dropbox'))
55+
return callback();
56+
57+
const {prefix, prefixSocket} = CloudCmd;
58+
59+
await loadAll();
60+
await initOperations(prefix, prefixSocket, callback);
61+
},
6262
(callback) => {
63-
Loaded = true;
64-
Images.hide();
65-
callback();
66-
},
63+
Loaded = true;
64+
Images.hide();
65+
callback();
66+
},
6767
], callback);
6868
});
6969

client/modules/user-menu/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* global CloudCmd, DOM */
2+
import '../../../css/user-menu.css';
23
import currify from 'currify';
34
import wraptile from 'wraptile';
45
import {fullstore} from 'fullstore';
@@ -8,7 +9,6 @@ import {tryCatch} from 'try-catch';
89
import {tryToCatch} from 'try-to-catch';
910
import {codeFrameColumns} from '@babel/code-frame';
1011
import * as Dialog from '#dom/dialog';
11-
import '../../../css/user-menu.css';
1212
import * as Images from '#dom/images';
1313
import {getUserMenu} from './get-user-menu.mjs';
1414
import {navigate} from './navigate.mjs';

client/modules/view/index.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import {time} from '#common/util';
1010
import * as Files from '#dom/files';
1111
import * as Events from '#dom/events';
1212
import {FS} from '#common/cloudfunc';
13+
import * as Images from '#dom/images';
1314
import {
1415
isImage,
1516
isAudio,
1617
getType,
1718
} from './types.mjs';
18-
import * as Images from '#dom/images';
19-
import {encode} from '../../../common/entity.js';
19+
import {encode} from '#common/entity';
2020

2121
const CloudCmd = globalThis.CloudCmd || {};
2222
const DOM = globalThis.DOM || {};

common/cloudfunc.mjs

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import rendy from 'rendy';
22
import currify from 'currify';
33
import store from 'fullstore';
4-
import {encode} from './entity.js';
4+
import {encode} from '#common/entity';
55

66
export const getHeaderField = currify(_getHeaderField);
77

@@ -168,7 +168,6 @@ export const buildFromJSON = (params) => {
168168
Path(path);
169169

170170
fileTable += `${header}<ul data-name="js-files" class="files">`;
171-
172171
/* Если мы не в корне */
173172
if (path !== '/') {
174173
const dotDot = getDotDot(path);
@@ -199,43 +198,43 @@ export const buildFromJSON = (params) => {
199198

200199
fileTable += files
201200
.filter(filterOutDotFiles({
202-
showDotFiles,
203-
}))
201+
showDotFiles,
202+
}))
204203
.map(updateField)
205204
.map((file) => {
206-
const name = encode(file.name);
207-
const link = prefix + FS + path + name;
208-
209-
const {
210-
type,
211-
mode,
212-
date,
213-
owner,
214-
size,
215-
} = file;
216-
217-
const linkResult = rendy(templateLink, {
218-
link,
219-
title: name,
220-
name,
221-
attribute: getAttribute(file.type),
222-
});
223-
224-
const dataName = _getDataName(file.name);
225-
const attribute = `draggable="true" ${dataName}`;
226-
227-
return rendy(templateFile, {
228-
tag: 'li',
229-
attribute,
230-
className: '',
231-
type,
232-
name: linkResult,
233-
size,
234-
date,
235-
owner,
236-
mode,
237-
});
238-
})
205+
const name = encode(file.name);
206+
const link = prefix + FS + path + name;
207+
208+
const {
209+
type,
210+
mode,
211+
date,
212+
owner,
213+
size,
214+
} = file;
215+
216+
const linkResult = rendy(templateLink, {
217+
link,
218+
title: name,
219+
name,
220+
attribute: getAttribute(file.type),
221+
});
222+
223+
const dataName = _getDataName(file.name);
224+
const attribute = `draggable="true" ${dataName}`;
225+
226+
return rendy(templateFile, {
227+
tag: 'li',
228+
attribute,
229+
className: '',
230+
type,
231+
name: linkResult,
232+
size,
233+
date,
234+
owner,
235+
mode,
236+
});
237+
})
239238
.join('');
240239

241240
fileTable += '</ul>';

common/entity.js renamed to common/entity.mjs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
'use strict';
2-
31
const Entities = {
4-
// '&nbsp;': ' ',
52
'&lt;': '<',
63
'&gt;': '>',
74
'&quot;': '"',
85
};
96

107
const keys = Object.keys(Entities);
118

12-
module.exports.encode = (str) => {
9+
export const encode = (str) => {
1310
for (const code of keys) {
1411
const char = Entities[code];
1512
const reg = RegExp(char, 'g');
@@ -20,7 +17,7 @@ module.exports.encode = (str) => {
2017
return str;
2118
};
2219

23-
module.exports.decode = (str) => {
20+
export const decode = (str) => {
2421
for (const code of keys) {
2522
const char = Entities[code];
2623
const reg = RegExp(code, 'g');
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
'use strict';
2-
3-
const {test} = require('supertape');
4-
const entity = require('./entity');
1+
import {test} from 'supertape';
2+
import * as entity from '#common/entity';
53

64
test('cloudcmd: entity: encode', (t) => {
75
const result = entity.encode('<hello> ');

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@
230230
"#dom/storage": "./client/dom/storage.mjs",
231231
"#dom/rest": "./client/dom/rest.mjs",
232232
"#common/util": "./common/util.mjs",
233-
"#common/cloudfunc": "./common/cloudfunc.mjs"
233+
"#common/cloudfunc": "./common/cloudfunc.mjs",
234+
"#common/entity": "./common/entity.mjs"
234235
},
235236
"engines": {
236237
"node": ">=22"

0 commit comments

Comments
 (0)