1
0
mirror of https://github.com/S2-/gitlit synced 2025-08-03 12:50:04 +02:00

remove electron-in-page-search

This commit is contained in:
s2
2019-06-06 15:44:24 +02:00
parent e2a57318a7
commit c5f9b551ab
92637 changed files with 636010 additions and 15 deletions

View File

@@ -0,0 +1,67 @@
# keyboardevent-from-electron-accelerator
[![Travis Build Status](https://img.shields.io/travis/parro-it/keyboardevent-from-electron-accelerator/master.svg)](http://travis-ci.org/parro-it/keyboardevent-from-electron-accelerator)
[![NPM downloads](https://img.shields.io/npm/dt/keyboardevent-from-electron-accelerator.svg)](https://npmjs.org/package/keyboardevent-from-electron-accelerator)
[![AppVeyor Build status](https://ci.appveyor.com/api/projects/status/l1qdd90e7xagkgq7/branch/master?svg=true)](https://ci.appveyor.com/project/parro-it/keyboardevent-from-electron-accelerator/branch/master)
> Transform an Electron Accelerator string into a DOM KeyboardEvent.
This module export a function that take an Electron Accelerator as input
and return a corresponding KeyboardEvent object.
E.g. `'Ctrl+Alt+C' => {code: 'c', ctrlKey: true, altKey: true}`
## Usage
This example convert a string containing an Electron Accelerator to a corresponding KeyboardEvent object. Returned object is the keyevent that would be emitted if that key combination was pressed.
```js
const {toKeyEvent} = require('keyboardevent-from-electron-accelerator');
console.log(toKeyEvent('Shift+Delete'));
```
This will output
{key: 'Delete', shiftKey: true}
## Context and motivation for this module.
This module is part of an ongoing effort to make [electron-localshortcut](https://github.com/parro-it/electron-localshortcut) less error prone, using keyboard DOM listener instead of 'globalShortcut' method to trigger shortcuts handlers.
`electron-localshortcut` will listen for DOM `keydown` and `keyup` events, and will
trigger shortcuts handlers if emitted DOM events match the Accelerator.
This module wrap the core logic of that match operation.
You can help by testing the module on [runkit](https://npm.runkit.com/keyboardevent-from-electron-accelerator) and [opening an issue](https://github.com/parro-it/keyboardevent-from-electron-accelerator/issues/new) if you found some wrong
result.
## API
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
### toKeyEvent
This function transform an Electron Accelerator string into
a DOM KeyboardEvent object.
**Parameters**
- `accelerator` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** an Electron Accelerator string, e.g. `Ctrl+C` or `Shift+Space`.
Returns **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** a DOM KeyboardEvent object derivate from the `accelerator` argument.
## Install
With [npm](https://npmjs.org/) installed, run
$ npm install keyboardevent-from-electron-accelerator
## See Also
- [`noffle/common-readme`](https://github.com/noffle/common-readme)
## License
MIT

View File

@@ -0,0 +1,6 @@
const {toKeyEvent} = require('keyboardevent-from-electron-accelerator');
console.log(toKeyEvent('Ctrl+Shift+V'));
console.log(toKeyEvent('Control+c'));
console.log(toKeyEvent('Alt+Delete'));

View File

@@ -0,0 +1,264 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const modifiers = /^(CommandOrControl|CmdOrCtrl|Command|Cmd|Control|Ctrl|Alt|Option|AltGr|Shift|Super)/i;
const keyCodes = /^(Plus|Space|Tab|Backspace|Delete|Insert|Return|Enter|Up|Down|Left|Right|Home|End|PageUp|PageDown|Escape|Esc|VolumeUp|VolumeDown|VolumeMute|MediaNextTrack|MediaPreviousTrack|MediaStop|MediaPlayPause|PrintScreen|F24|F23|F22|F21|F20|F19|F18|F17|F16|F15|F14|F13|F12|F11|F10|F9|F8|F7|F6|F5|F4|F3|F2|F1|[0-9A-Z)!@#$%^&*(:+<_>?~{|}";=,\-./`[\\\]'])/i;
const UNSUPPORTED = {};
function reduceModifier({accelerator, event}, modifier) {
switch (modifier) {
case 'command':
case 'cmd': {
if (process.platform !== 'darwin') {
return UNSUPPORTED;
}
if (event.metaKey) {
throw new Error('Double `Command` modifier specified.');
}
return {
event: Object.assign({}, event, {metaKey: true}),
accelerator: accelerator.slice(modifier.length)
};
}
case 'super': {
if (event.metaKey) {
throw new Error('Double `Super` modifier specified.');
}
return {
event: Object.assign({}, event, {metaKey: true}),
accelerator: accelerator.slice(modifier.length)
};
}
case 'control':
case 'ctrl': {
if (event.ctrlKey) {
throw new Error('Double `Control` modifier specified.');
}
return {
event: Object.assign({}, event, {ctrlKey: true}),
accelerator: accelerator.slice(modifier.length)
};
}
case 'commandorcontrol':
case 'cmdorctrl': {
if (process.platform === 'darwin') {
if (event.metaKey) {
throw new Error('Double `Command` modifier specified.');
}
return {
event: Object.assign({}, event, {metaKey: true}),
accelerator: accelerator.slice(modifier.length)
};
}
if (event.ctrlKey) {
throw new Error('Double `Control` modifier specified.');
}
return {
event: Object.assign({}, event, {ctrlKey: true}),
accelerator: accelerator.slice(modifier.length)
};
}
case 'option':
case 'altgr':
case 'alt': {
if (modifier === 'option' && process.platform !== 'darwin') {
return UNSUPPORTED;
}
if (event.altKey) {
throw new Error('Double `Alt` modifier specified.');
}
return {
event: Object.assign({}, event, {altKey: true}),
accelerator: accelerator.slice(modifier.length)
};
}
case 'shift': {
if (event.shiftKey) {
throw new Error('Double `Shift` modifier specified.');
}
return {
event: Object.assign({}, event, {shiftKey: true}),
accelerator: accelerator.slice(modifier.length)
};
}
default:
console.error(modifier);
}
}
function reducePlus({accelerator, event}) {
return {
event,
accelerator: accelerator.trim().slice(1)
};
}
const virtualKeyCodes = {
0: 'Digit0',
1: 'Digit1',
2: 'Digit2',
3: 'Digit3',
4: 'Digit4',
5: 'Digit5',
6: 'Digit6',
7: 'Digit7',
8: 'Digit8',
9: 'Digit9',
'-': 'Minus',
'=': 'Equal',
Q: 'KeyQ',
W: 'KeyW',
E: 'KeyE',
R: 'KeyR',
T: 'KeyT',
Y: 'KeyY',
U: 'KeyU',
I: 'KeyI',
O: 'KeyO',
P: 'KeyP',
'[': 'BracketLeft',
']': 'BracketRight',
A: 'KeyA',
S: 'KeyS',
D: 'KeyD',
F: 'KeyF',
G: 'KeyG',
H: 'KeyH',
J: 'KeyJ',
K: 'KeyK',
L: 'KeyL',
';': 'Semicolon',
'\'': 'Quote',
'`': 'Backquote',
'/': 'Backslash',
Z: 'KeyZ',
X: 'KeyX',
C: 'KeyC',
V: 'KeyV',
B: 'KeyB',
N: 'KeyN',
M: 'KeyM',
',': 'Comma',
'.': 'Period',
'\\': 'Slash',
' ': 'Space'
};
function reduceKey({accelerator, event}, key) {
if (key.length > 1 || event.key) {
throw new Error(`Unvalid keycode \`${key}\`.`);
}
const code =
key.toUpperCase() in virtualKeyCodes ?
virtualKeyCodes[key.toUpperCase()] :
null;
return {
event: Object.assign({}, event, {key}, code ? {code} : null),
accelerator: accelerator.trim().slice(key.length)
};
}
const domKeys = Object.assign(Object.create(null), {
plus: 'Add',
space: ' ',
tab: 'Tab',
backspace: 'Backspace',
delete: 'Delete',
insert: 'Insert',
return: 'Return',
enter: 'Return',
up: 'ArrowUp',
down: 'ArrowDown',
left: 'ArrowLeft',
right: 'ArrowRight',
home: 'Home',
end: 'End',
pageup: 'PageUp',
pagedown: 'PageDown',
escape: 'Escape',
esc: 'Escape',
volumeup: 'AudioVolumeUp',
volumedown: 'AudioVolumeDown',
volumemute: 'AudioVolumeMute',
medianexttrack: 'MediaTrackNext',
mediaprevioustrack: 'MediaTrackPrevious',
mediastop: 'MediaStop',
mediaplaypause: 'MediaPlayPause',
printscreen: 'PrintScreen'
});
// Add function keys
for (let i = 1; i <= 24; i++) {
domKeys[`f${i}`] = `F${i}`;
}
function reduceCode({accelerator, event}, {code, key}) {
if (event.code) {
throw new Error(`Duplicated keycode \`${key}\`.`);
}
return {
event: Object.assign({}, event, {key}, code ? {code} : null),
accelerator: accelerator.trim().slice((key && key.length) || 0)
};
}
/**
* This function transform an Electron Accelerator string into
* a DOM KeyboardEvent object.
*
* @param {string} accelerator an Electron Accelerator string, e.g. `Ctrl+C` or `Shift+Space`.
* @return {object} a DOM KeyboardEvent object derivate from the `accelerator` argument.
*/
function toKeyEvent(accelerator) {
let state = {accelerator, event: {}};
while (state.accelerator !== '') {
const modifierMatch = state.accelerator.match(modifiers);
if (modifierMatch) {
const modifier = modifierMatch[0].toLowerCase();
state = reduceModifier(state, modifier);
if (state === UNSUPPORTED) {
return {unsupportedKeyForPlatform: true};
}
} else if (state.accelerator.trim()[0] === '+') {
state = reducePlus(state);
} else {
const codeMatch = state.accelerator.match(keyCodes);
if (codeMatch) {
const code = codeMatch[0].toLowerCase();
if (code in domKeys) {
state = reduceCode(state, {
code: domKeys[code],
key: code
});
} else {
state = reduceKey(state, code);
}
} else {
throw new Error(`Unvalid accelerator: "${state.accelerator}"`);
}
}
}
return state.event;
}
exports.UNSUPPORTED = UNSUPPORTED;
exports.reduceModifier = reduceModifier;
exports.reducePlus = reducePlus;
exports.reduceKey = reduceKey;
exports.reduceCode = reduceCode;
exports.toKeyEvent = toKeyEvent;

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 Andrea Parodi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,59 @@
{
"_from": "keyboardevent-from-electron-accelerator@^1.1.0",
"_id": "keyboardevent-from-electron-accelerator@1.1.0",
"_inBundle": false,
"_integrity": "sha512-VDC4vKWGrR3VgIKCE4CsXnvObGgP8C2idnTKEMUkuEuvDGE1GEBX9FtNdJzrD00iQlhI3xFxRaeItsUmlERVng==",
"_location": "/keyboardevent-from-electron-accelerator",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "keyboardevent-from-electron-accelerator@^1.1.0",
"name": "keyboardevent-from-electron-accelerator",
"escapedName": "keyboardevent-from-electron-accelerator",
"rawSpec": "^1.1.0",
"saveSpec": null,
"fetchSpec": "^1.1.0"
},
"_requiredBy": [
"/electron-localshortcut"
],
"_resolved": "https://registry.npmjs.org/keyboardevent-from-electron-accelerator/-/keyboardevent-from-electron-accelerator-1.1.0.tgz",
"_shasum": "324614f6e33490c37ffc5be5876b3e85fe223c84",
"_spec": "keyboardevent-from-electron-accelerator@^1.1.0",
"_where": "F:\\projects\\p\\gitlit\\app\\node_modules\\electron-localshortcut",
"author": {
"name": "Andrea",
"email": "andrea@parro.it"
},
"bugs": {
"url": "https://github.com/parro-it/keyboardevent-from-electron-accelerator/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "Transform an Electron Accelerator string into a DOM KeyboardEvent.",
"devDependencies": {
"ava": "^0.19.1",
"documentation": "^4.0.0-rc.1",
"rollup": "^0.43.0",
"xo": "^0.18.2"
},
"files": [
"index.js",
"example.js"
],
"homepage": "https://github.com/parro-it/keyboardevent-from-electron-accelerator#readme",
"keywords": [],
"license": "MIT",
"name": "keyboardevent-from-electron-accelerator",
"repository": {
"type": "git",
"url": "git+https://github.com/parro-it/keyboardevent-from-electron-accelerator.git"
},
"scripts": {
"doc": "documentation readme main.js --section=API",
"test": "rollup -c && ava && xo --ignore example.js --ignore index.js"
},
"tonicExampleFilename": "example.js",
"version": "1.1.0"
}