Skip to content

Commit 983fd9a

Browse files
committed
feature: client: edit: migrate to ESM
1 parent ebabad9 commit 983fd9a

5 files changed

Lines changed: 77 additions & 71 deletions

File tree

.webpack/js.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export default {
119119
'user-menu': `${dirCss}/user-menu.css`,
120120
'sw': `${dir}/sw/sw.mjs`,
121121
'cloudcmd': `${dir}/cloudcmd.mjs`,
122-
[`${modules}/edit`]: `${dirModules}/edit.js`,
122+
[`${modules}/edit`]: `${dirModules}/edit.mjs`,
123123
[`${modules}/edit-file`]: `${dirModules}/edit-file.js`,
124124
[`${modules}/edit-file-vim`]: `${dirModules}/edit-file-vim.js`,
125125
[`${modules}/edit-names`]: `${dirModules}/edit-names.js`,
Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
/* global CloudCmd */
2+
import montag from 'montag';
3+
import {promisify} from 'es6-promisify';
4+
import {tryToCatch} from 'try-to-catch';
5+
import createElement from '@cloudcmd/create-element';
6+
import load from 'load.js';
7+
import {MAX_FILE_SIZE as maxSize} from '#common/cloudfunc';
8+
import {time, timeEnd} from '#common/util';
9+
10+
export function getEditor() {
11+
return editor;
12+
}
213

3-
'use strict';
4-
5-
const montag = require('montag');
6-
7-
const {promisify} = require('es6-promisify');
8-
const {tryToCatch} = require('try-to-catch');
9-
const createElement = require('@cloudcmd/create-element');
10-
const load = require('load.js');
11-
const {MAX_FILE_SIZE: maxSize} = require('#common/cloudfunc');
12-
13-
const {time, timeEnd} = require('#common/util');
14-
const getEditor = () => editor;
1514
const isFn = (a) => typeof a === 'function';
1615
const loadJS = load.js;
1716

1817
const Name = 'Edit';
1918

20-
CloudCmd[Name] = exports;
19+
CloudCmd[Name] = {
20+
init,
21+
show,
22+
hide,
23+
getEditor,
24+
getElement,
25+
};
2126

2227
const EditorName = CloudCmd.config('editor');
2328

@@ -33,12 +38,12 @@ const ConfigView = {
3338
},
3439
};
3540

36-
module.exports.init = async () => {
41+
export async function init() {
3742
const element = create();
3843

3944
await CloudCmd.View();
4045
await loadFiles(element);
41-
};
46+
}
4247

4348
function create() {
4449
const element = createElement('div', {
@@ -79,7 +84,7 @@ function initConfig(options = {}) {
7984
return config;
8085
}
8186

82-
module.exports.show = (options) => {
87+
export function show(options) {
8388
if (Loading)
8489
return;
8590

@@ -88,15 +93,15 @@ module.exports.show = (options) => {
8893
getEditor().setOptions({
8994
fontSize: 16,
9095
});
91-
};
92-
93-
module.exports.getEditor = getEditor;
96+
}
9497

95-
module.exports.getElement = () => Element;
98+
export function getElement() {
99+
return Element;
100+
}
96101

97-
module.exports.hide = () => {
102+
export function hide() {
98103
CloudCmd.View.hide();
99-
};
104+
}
100105

101106
const loadFiles = async (element) => {
102107
const prefix = `${CloudCmd.prefix}/${EditorName}`;

client/modules/operation/index.mjs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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/view/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import * as Files from '#dom/files';
1111
import * as Events from '#dom/events';
1212
import {FS} from '#common/cloudfunc';
1313
import * as Images from '#dom/images';
14+
import {encode} from '#common/entity';
1415
import {
1516
isImage,
1617
isAudio,
1718
getType,
1819
} from './types.mjs';
19-
import {encode} from '#common/entity';
2020

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

common/cloudfunc.mjs

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ export const buildFromJSON = (params) => {
168168
Path(path);
169169

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

199200
fileTable += files
200201
.filter(filterOutDotFiles({
201-
showDotFiles,
202-
}))
202+
showDotFiles,
203+
}))
203204
.map(updateField)
204205
.map((file) => {
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-
})
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+
})
238239
.join('');
239240

240241
fileTable += '</ul>';

0 commit comments

Comments
 (0)