-
-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f97918
commit c629f8e
Showing
24 changed files
with
281 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
'F2 - Rename file': ({DOM}) => { | ||
const {element} = DOM.CurrentInfo; | ||
DOM.renameCurrent(element); | ||
}, | ||
'D - Build Dev': async ({DOM, tryToCatch}) => { | ||
return 'npm run build:client:dev'; | ||
}, | ||
'P - Build Prod': () => { | ||
return 'npm run build:client'; | ||
}, | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
'use strict'; | ||
|
||
/* global DOM */ | ||
/* global CloudCmd */ | ||
|
||
const { | ||
Dialog, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
'use strict'; | ||
|
||
/* global CloudCmd, DOM */ | ||
|
||
require('../../css/user-menu.css'); | ||
|
||
const currify = require('currify/legacy'); | ||
const {promisify} = require('es6-promisify'); | ||
const load = require('load.js'); | ||
const createElement = require('@cloudcmd/create-element'); | ||
const Images = require('../dom/images'); | ||
|
||
const loadCSS = promisify(load.css); | ||
|
||
const Name = 'UserMenu'; | ||
CloudCmd[Name] = module.exports; | ||
|
||
const {Key} = CloudCmd; | ||
const {stringify} = JSON; | ||
|
||
const userMenuUrl = '/api/v1/user-menu'; | ||
|
||
module.exports.init = async () => { | ||
await Promise.all([ | ||
loadCSS(`${CloudCmd.prefix}/dist/user-menu.css`), | ||
CloudCmd.View(), | ||
]); | ||
}; | ||
|
||
module.exports.show = show; | ||
module.exports.hide = hide; | ||
|
||
const getKey = (a) => a.split(' - ')[0]; | ||
const beginWith = (a) => (b) => !b.indexOf(a); | ||
|
||
const defaultUserMenu = { | ||
'F2 - Rename file': async ({DOM}) => { | ||
const {element} = DOM.CurrentInfo; | ||
DOM.renameCurrent(element); | ||
}, | ||
}; | ||
|
||
function getUserMenu(menuFn) { | ||
if (!menuFn) | ||
return defaultUserMenu; | ||
|
||
const module = {}; | ||
const fn = Function('module', menuFn); | ||
|
||
fn(module); | ||
|
||
return module.exports; | ||
} | ||
|
||
const {CurrentInfo} = DOM; | ||
|
||
async function show() { | ||
Images.show.load('top'); | ||
|
||
const {dirPath} = CurrentInfo; | ||
const res = await fetch(`${userMenuUrl}?dir=${dirPath}`); | ||
const userMenu = getUserMenu(await res.text()); | ||
const options = Object.keys(userMenu); | ||
|
||
const el = createElement('select', { | ||
className: 'cloudcmd-user-menu', | ||
innerHTML: fillTemplate(options), | ||
size: 10, | ||
}); | ||
|
||
const keys = options.map(getKey); | ||
el.addEventListener('keydown', onKeyDown(keys, options, userMenu)); | ||
|
||
const afterShow = () => el.focus(); | ||
const autoSize = true; | ||
|
||
Images.hide(); | ||
|
||
CloudCmd.View.show(el, { | ||
autoSize, | ||
afterShow, | ||
}); | ||
} | ||
|
||
function fillTemplate(options) { | ||
const result = []; | ||
|
||
for (const option of options) { | ||
result.push(`<option>${option}</option>`); | ||
} | ||
|
||
return result.join(''); | ||
} | ||
|
||
function hide() { | ||
CloudCmd.View.hide(); | ||
} | ||
|
||
const onKeyDown = currify(async (keys, options, userMenu, e) => { | ||
const {keyCode} = e; | ||
const key = e.key.toUpperCase(); | ||
|
||
let value; | ||
|
||
if (keyCode === Key.ENTER) | ||
({value} = e.target); | ||
else if (keys.includes(key)) | ||
value = options.find(beginWith(key)); | ||
else | ||
return; | ||
|
||
e.preventDefault(); | ||
e.stopPropagation(); | ||
|
||
hide(); | ||
|
||
const cmd = await userMenu[value]({ | ||
DOM, | ||
}); | ||
|
||
if (!cmd) | ||
return; | ||
|
||
const res = await fetch(userMenuUrl, { | ||
method: 'PUT', | ||
body: stringify({ | ||
cmd, | ||
}), | ||
}); | ||
|
||
const data = await res.text(); | ||
|
||
if (data) | ||
DOM.Dialog.alert(data); | ||
|
||
CloudCmd.refresh(); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.cloudcmd-user-menu { | ||
font-size: 16px; | ||
font-family: 'Droid Sans Mono', 'Ubuntu Mono', 'Consolas', monospace; | ||
width: 400px; | ||
} | ||
|
||
.cloudcmd-user-menu:focus { | ||
outline: 0; | ||
} | ||
|
||
.cloudcmd-user-menu > option:checked { | ||
box-shadow: 20px -20px 0 2px rgba(49, 123, 249) inset; | ||
} | ||
|
Binary file not shown.
Oops, something went wrong.