picosh 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +21 -30
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -16,44 +16,35 @@ function saveClipboardImage(clipboard) {
16
16
  return filepath;
17
17
  }
18
18
 
19
- exports.middleware = (store) => (next) => (action) => {
20
- if (action.type === 'SESSION_PTY_DATA') {
21
- return next(action);
22
- }
23
- return next(action);
24
- };
25
-
26
- exports.decorateTerm = (Term, {React, notify}) => {
19
+ exports.decorateTerm = (Term, {React}) => {
27
20
  return class extends React.Component {
28
- constructor(props) {
29
- super(props);
30
- this._handleKeyDown = this._handleKeyDown.bind(this);
31
- }
21
+ componentDidMount() {
22
+ this._onKeyDown = (e) => {
23
+ if (!((e.ctrlKey || e.metaKey) && e.key === 'v')) return;
32
24
 
33
- _handleKeyDown(e) {
34
- const isCtrlV = (e.ctrlKey || e.metaKey) && e.key === 'v';
35
- if (!isCtrlV) return;
25
+ try {
26
+ const {clipboard} = require('electron');
27
+ const filepath = saveClipboardImage(clipboard);
28
+ if (!filepath) return;
36
29
 
37
- try {
38
- const {clipboard} = require('electron');
39
- const filepath = saveClipboardImage(clipboard);
40
- if (!filepath) return;
30
+ e.preventDefault();
31
+ e.stopPropagation();
41
32
 
42
- e.preventDefault();
43
- e.stopPropagation();
33
+ if (this.props.onData) {
34
+ this.props.onData(filepath);
35
+ }
36
+ } catch (_) {}
37
+ };
38
+
39
+ document.addEventListener('keydown', this._onKeyDown, true);
40
+ }
44
41
 
45
- if (this.props.onData) {
46
- this.props.onData(filepath);
47
- }
48
- } catch (err) {
49
- // clipboard had no image, let default paste happen
50
- }
42
+ componentWillUnmount() {
43
+ document.removeEventListener('keydown', this._onKeyDown, true);
51
44
  }
52
45
 
53
46
  render() {
54
- return React.createElement(Term, Object.assign({}, this.props, {
55
- onKeyDown: this._handleKeyDown,
56
- }));
47
+ return React.createElement(Term, this.props);
57
48
  }
58
49
  };
59
50
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "picosh",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Hyper plugin: paste clipboard images as file paths",
5
5
  "main": "index.js",
6
6
  "license": "MIT",