Skip to content

Commit 08b5c6b

Browse files
committed
feature: client: menu: aleman: add
1 parent 83a1e52 commit 08b5c6b

File tree

15 files changed

+80
-15
lines changed

15 files changed

+80
-15
lines changed

.webpack/js.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const plugins = [
5454
new NormalModuleReplacementPlugin(/^node:/, (resource) => {
5555
resource.request = resource.request.replace(/^node:/, '');
5656
}),
57+
new NormalModuleReplacementPlugin(/^putout$/, '@putout/bundle'),
5758
new EnvironmentPlugin({
5859
NODE_ENV,
5960
}),
@@ -125,7 +126,7 @@ module.exports = {
125126
[`${modules}/edit-file-vim`]: `${dirModules}/edit-file-vim.js`,
126127
[`${modules}/edit-names`]: `${dirModules}/edit-names.js`,
127128
[`${modules}/edit-names-vim`]: `${dirModules}/edit-names-vim.js`,
128-
[`${modules}/menu`]: `${dirModules}/menu.js`,
129+
[`${modules}/menu`]: `${dirModules}/menu/index.js`,
129130
[`${modules}/view`]: `${dirModules}/view/index.js`,
130131
[`${modules}/help`]: `${dirModules}/help.js`,
131132
[`${modules}/markdown`]: `${dirModules}/markdown.js`,

HELP.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ Cloud Commander supports the following command-line parameters:
8282
| `--confirm-move` | confirm move
8383
| `--open` | open web browser when server starts
8484
| `--name` | set tab name in web browser
85+
| `--menu` | set menu: "supermenu" or "aleman"
8586
| `--one-file-panel` | show one file panel
8687
| `--keys-panel` | show keys panel
8788
| `--contact` | enable contact
@@ -434,6 +435,7 @@ Some config options can be overridden with environment variables, such as:
434435
- `CLOUDCMD_EDITOR` - set editor
435436
- `CLOUDCMD_COLUMNS` - set visible themes
436437
- `CLOUDCMD_THEME` - set themes "light" or "dark"
438+
- `CLOUDCMD_MENU` - set menu "supermenu" or "aleman"
437439
- `CLOUDCMD_CONTACT` - enable contact
438440
- `CLOUDCMD_CONFIG_DIALOG` - enable config dialog
439441
- `CLOUDCMD_CONFIG_AUTH` - enable auth change in config dialog

bin/cloudcmd.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const yargsOptions = {
6262
'terminal-path',
6363
'terminal-command',
6464
'columns',
65+
'menu',
6566
'theme',
6667
'import-url',
6768
'import-token',
@@ -106,6 +107,7 @@ const yargsOptions = {
106107
'online': config('online'),
107108
'open': choose(env.bool('open'), config('open')),
108109
'editor': env('editor') || config('editor'),
110+
'menu': env('menu') || config('menu'),
109111
'packer': config('packer') || 'tar',
110112
'zip': config('zip'),
111113
'username': env('username') || config('username'),
@@ -199,6 +201,7 @@ async function main() {
199201
config('terminalCommand', args.terminalCommand);
200202
config('terminalAutoRestart', args.terminalAutoRestart);
201203
config('editor', args.editor);
204+
config('menu', args.menu);
202205
config('prefix', prefixer(args.prefix));
203206
config('prefixSocket', prefixer(args.prefixSocket));
204207
config('root', args.root || '/');
@@ -232,6 +235,7 @@ async function main() {
232235
prefixSocket: config('prefixSocket'),
233236
columns: config('columns'),
234237
theme: config('theme'),
238+
menu: config('menu'),
235239
};
236240

237241
const password = env('password') || args.password;

client/cloudcmd.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ module.exports = async (config) => {
2626
const prefix = getPrefix(config.prefix);
2727

2828
window.CloudCmd.init(prefix, config);
29+
30+
if (window.CloudCmd.config('menu') === 'aleman')
31+
setTimeout(() => {
32+
import('https://esm.sh/@putout/processor-html');
33+
import('https://esm.sh/@putout/bundle');
34+
}, 100);
2935
};
3036
window.CloudCmd = module.exports;
3137

@@ -61,3 +67,4 @@ async function register(config) {
6167

6268
listenSW(sw, 'updatefound', onUpdateFound(config));
6369
}
70+

client/listeners/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ module.exports.initKeysPanel = () => {
111111
if (!keysElement)
112112
return;
113113

114-
Events.addClick(keysElement, ({target}) => {
114+
Events.addClick(keysElement, (event) => {
115+
event.stopPropagation();
116+
117+
const {target} = event;
115118
const {id} = target;
116119
const operation = (name) => {
117120
const {Operation} = CloudCmd;

client/modules/config/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,15 @@ async function fillTemplate() {
135135

136136
const {
137137
editor,
138+
menu,
138139
packer,
139140
columns,
140141
theme,
141142
configAuth,
142143
...obj
143144
} = input.convert(config);
144145

146+
obj[`${menu}-selected`] = 'selected';
145147
obj[`${editor}-selected`] = 'selected';
146148
obj[`${packer}-selected`] = 'selected';
147149
obj[`${columns}-selected`] = 'selected';

client/modules/menu/cloudmenu.mjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import supermenu from 'supermenu';
2+
3+
const noop = () => {};
4+
const {CloudCmd} = globalThis;
5+
6+
export const createCloudMenu = async (fm, options, menuData) => {
7+
const createMenu = await loadMenu();
8+
const menu = await createMenu(fm, options, menuData);
9+
10+
menu.addContextMenuListener = menu.addContextMenuListener || noop;
11+
12+
return menu;
13+
};
14+
15+
async function loadMenu() {
16+
if (CloudCmd.config('menu') === 'aleman') {
17+
const {host, protocol} = window.location;
18+
const url = `${protocol}//${host}/node_modules/aleman/menu/menu.js`;
19+
const {createMenu} = await import(/* webpackIgnore: true */url);
20+
21+
return createMenu;
22+
}
23+
24+
return supermenu;
25+
}
26+
Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44

55
const exec = require('execon');
66
const wrap = require('wraptile');
7-
const supermenu = require('supermenu');
87
const createElement = require('@cloudcmd/create-element');
98

10-
const {FS} = require('../../common/cloudfunc');
11-
const {getIdBySrc} = require('../dom/load');
12-
const RESTful = require('../dom/rest');
9+
const {FS} = require('../../../common/cloudfunc');
10+
const {getIdBySrc} = require('../../dom/load');
11+
const RESTful = require('../../dom/rest');
1312

1413
const {config, Key} = CloudCmd;
1514

@@ -32,7 +31,7 @@ module.exports.ENABLED = false;
3231

3332
CloudCmd.Menu = exports;
3433

35-
module.exports.init = () => {
34+
module.exports.init = async () => {
3635
const {isAuth, menuDataFile} = getFileMenuData();
3736

3837
const fm = DOM.getFM();
@@ -46,8 +45,9 @@ module.exports.init = () => {
4645
type: 'file',
4746
});
4847

49-
MenuContext = supermenu(fm, options, menuData);
50-
MenuContextFile = supermenu(fm, optionsFile, menuDataFile);
48+
const {createCloudMenu} = await import('./cloudmenu.mjs');
49+
MenuContext = await createCloudMenu(fm, options, menuData);
50+
MenuContextFile = await createCloudMenu(fm, optionsFile, menuDataFile);
5151

5252
MenuContext.addContextMenuListener();
5353
MenuContextFile.addContextMenuListener();
@@ -107,6 +107,7 @@ function getOptions({type}) {
107107
const options = {
108108
icon: true,
109109
beforeClose: Key.setBind,
110+
beforeHide: Key.setBind,
110111
beforeShow: exec.with(beforeShow, func),
111112
beforeClick,
112113
name,
@@ -198,16 +199,17 @@ function isPath(x, y) {
198199
const el = document.elementFromPoint(x, y);
199200
const elements = panel.querySelectorAll('[data-name="js-path"] *');
200201

201-
return ~[].indexOf.call(elements, el);
202+
return !~[].indexOf.call(elements, el);
202203
}
203204

204205
function beforeShow(callback, params) {
205206
Key.unsetBind();
206207

207-
const {name} = params;
208+
const {name, position = {x: params.x, y: params.y}} = params;
209+
const {x, y} = position;
208210
const el = DOM.getCurrentByPosition({
209-
x: params.x,
210-
y: params.y,
211+
x,
212+
y,
211213
});
212214

213215
const menuName = getMenuNameByEl(el);
@@ -223,7 +225,7 @@ function beforeShow(callback, params) {
223225
exec(callback);
224226

225227
if (isShow)
226-
isShow = isPath(params.x, params.y);
228+
isShow = isPath(x, y);
227229

228230
return isShow;
229231
}
@@ -341,3 +343,4 @@ function listener(event) {
341343
event.preventDefault();
342344
}
343345
}
346+

json/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"password": "2b64f2e3f9fee1942af9ff60d40aa5a719db33b8ba8dd4864bb4f11e25ca2bee00907de32a59429602336cac832c8f2eeff5177cc14c864dd116c8bf6ca5d9a9",
66
"algo": "sha512WithRSAEncryption",
77
"editor": "edward",
8+
"menu": "supermenu",
89
"packer": "tar",
910
"diff": true,
1011
"zip": true,

json/help.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"--confirm-move ": "confirm move",
2121
"--open ": "open web browser when server started",
2222
"--name ": "set tab name in web browser",
23+
"--menu ": "set menu: \"supermenu\" or \"aleman\"",
2324
"--one-file-panel ": "show one file panel",
2425
"--keys-panel ": "show keys panel",
2526
"--config-dialog ": "enable config dialog",

0 commit comments

Comments
 (0)