Skip to content

Commit

Permalink
convert to v2 addon
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeAstapov committed Feb 11, 2022
1 parent 90e87bf commit 6688753
Show file tree
Hide file tree
Showing 38 changed files with 339 additions and 122 deletions.
13 changes: 2 additions & 11 deletions addon/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,9 @@ module.exports = {
files: [
'./.eslintrc.js',
'./.prettierrc.js',
'./.template-lintrc.js',
'./addon-main.js',
'./ember-cli-build.js',
'./index.js',
'./testem.js',
'./blueprints/*/index.js',
'./config/**/*.js',
'./tests/dummy/config/**/*.js',
'./rollup.config.js',
],
parserOptions: {
sourceType: 'script',
Expand All @@ -44,10 +40,5 @@ module.exports = {
plugins: ['node'],
extends: ['plugin:node/recommended'],
},
{
// Test files:
files: ['tests/**/*-test.{js,ts}'],
extends: ['plugin:qunit/recommended'],
},
],
};
3 changes: 3 additions & 0 deletions addon/addon-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { addonV1Shim } = require('@embroider/addon-shim');

module.exports = addonV1Shim(__dirname);
1 change: 0 additions & 1 deletion addon/app/helpers/if-key.js

This file was deleted.

1 change: 0 additions & 1 deletion addon/app/helpers/on-key.js

This file was deleted.

1 change: 0 additions & 1 deletion addon/app/modifiers/on-key.js

This file was deleted.

1 change: 0 additions & 1 deletion addon/app/services/keyboard.js

This file was deleted.

7 changes: 7 additions & 0 deletions addon/babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"plugins": [
"@embroider/addon-dev/template-colocation-plugin",
["@babel/plugin-proposal-decorators", { "legacy": true }],
"@babel/plugin-proposal-class-properties"
]
}
36 changes: 0 additions & 36 deletions addon/index.js

This file was deleted.

53 changes: 44 additions & 9 deletions addon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,53 @@
"doc": "doc",
"test": "tests"
},
"exports": {
".": "./dist/index.js",
"./*": "./dist/*",
"./test-support/key-event": "./dist/test-support/key-event.js",
"./test-support/test-helpers": "./dist/test-support/test-helpers.js",
"./addon-main.js": "./addon-main.js"
},
"files": [
"addon-main.js",
"dist"
],
"scripts": {
"lint": "npm-run-all --aggregate-output --continue-on-error --parallel \"lint:!(fix)\"",
"lint:fix": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*:fix",
"build": "rollup --config",
"lint": "eslint . --cache",
"lint:fix": "eslint . --fix",
"lint:js": "eslint . --cache",
"lint:js:fix": "eslint . --fix"
"lint:js:fix": "eslint . --fix",
"prepublishOnly": "rollup --config",
"start": "rollup --config --watch"
},
"dependencies": {
"ember-cli-babel": "^7.26.6",
"ember-modifier": "^2.1.2 || ^3.0.0",
"ember-modifier-manager-polyfill": "^1.2.0"
"@embroider/addon-shim": "^1.2.0",
"ember-modifier": "^2.1.2 || ^3.1.0"
},
"devDependencies": {
"@babel/core": "^7.17.2",
"@babel/plugin-proposal-class-properties": "^7.16.7",
"@babel/plugin-proposal-decorators": "^7.17.2",
"@embroider/addon-dev": "^1.2.0",
"@rollup/plugin-babel": "^5.3.0",
"ember-template-lint": "^4.0.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-ember": "^10.5.7",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-qunit": "^7.0.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.4.1"
"prettier": "^2.4.1",
"rollup": "^2.67.2"
},
"peerDependencies": {
"@ember/test-helpers": "^2.6.0"
},
"peerDependenciesMeta": {
"@ember/test-helpers": {
"optional": true
}
},
"engines": {
"node": "12.* || 14.* || >= 16"
Expand All @@ -41,7 +67,16 @@
"edition": "octane"
},
"ember-addon": {
"demoURL": "https://adopted-ember-addons.github.io/ember-keyboard/"
"demoURL": "https://adopted-ember-addons.github.io/ember-keyboard/",
"main": "addon-main.js",
"type": "addon",
"version": 2,
"app-js": {
"./helpers/if-key.js": "./dist/_app_/helpers/if-key.js",
"./helpers/on-key.js": "./dist/_app_/helpers/on-key.js",
"./modifiers/on-key.js": "./dist/_app_/modifiers/on-key.js",
"./services/keyboard.js": "./dist/_app_/services/keyboard.js"
}
},
"release-it": {
"plugins": {
Expand Down
64 changes: 64 additions & 0 deletions addon/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import babel from '@rollup/plugin-babel';
import { Addon } from '@embroider/addon-dev/rollup';

const addon = new Addon({
srcDir: 'src',
destDir: 'dist',
});

export default {
// This provides defaults that work well alongside `publicEntrypoints` below.
// You can augment this if you need to.
output: addon.output(),

plugins: [
// These are the modules that users should be able to import from your
// addon. Anything not listed here may get optimized away.
addon.publicEntrypoints([
'decorators/**/*.js',
'fixtures/**/*.js',
'helpers/**/*.js',
'listeners/**/*.js',
'modifiers/**/*.js',
'services/**/*.js',
'test-support/key-event.js',
'test-support/test-helpers.js',
'utils/**/*.js',
'index.js',
]),

// These are the modules that should get reexported into the traditional
// "app" tree. Things in here should also be in publicEntrypoints above, but
// not everything in publicEntrypoints necessarily needs to go here.
addon.appReexports([
'helpers/**/*.js',
'modifiers/**/*.js',
'services/**/*.js',
]),

// This babel config should *not* apply presets or compile away ES modules.
// It exists only to provide development niceties for you, like automatic
// template colocation.
//
// By default, this will load the actual babel config from the file
// babel.config.json.
babel({
babelHelpers: 'bundled',
}),

// Follow the V2 Addon rules about dependencies. Your code can import from
// `dependencies` and `peerDependencies` as well as standard Ember-provided
// package names.
addon.dependencies(),

// Ensure that standalone .hbs files are properly integrated as Javascript.
addon.hbs(),

// addons are allowed to contain imports of .css files, which we want rollup
// to leave alone and keep in the published output.
addon.keepAssets(['**/*.css']),

// Remove leftover build artifacts when starting a new build.
addon.clean(),
],
};
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import listenerName from 'ember-keyboard/utils/listener-name';
import listenerName from '../utils/listener-name';
const DEFAULT_EVENT_NAME = 'keydown';

export default function onKey(keyCombo, opts = {}) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions addon/addon/helpers/if-key.js → addon/src/helpers/if-key.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { helper } from '@ember/component/helper';
import isKey from 'ember-keyboard/utils/is-key';
import listenerName from 'ember-keyboard/utils/listener-name';
import { assert } from '@ember/debug';
import isKey from '../utils/is-key';
import listenerName from '../utils/listener-name';

export default helper(function ifKey([keyCombo, callback] /*, named*/) {
return function (event) {
Expand Down
4 changes: 2 additions & 2 deletions addon/addon/helpers/on-key.js → addon/src/helpers/on-key.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Helper from '@ember/component/helper';
import { inject as service } from '@ember/service';
import listenerName from 'ember-keyboard/utils/listener-name';
import { assert } from '@ember/debug';
import { inject as service } from '@ember/service';
import listenerName from '../utils/listener-name';

export default class extends Helper {
@service keyboard;
Expand Down
18 changes: 7 additions & 11 deletions addon/addon/index.js → addon/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import getMouseCode from 'ember-keyboard/utils/get-mouse-code';
import { default as keyResponder } from 'ember-keyboard/decorators/key-responder';
import { default as onKey } from 'ember-keyboard/decorators/on-key';
import getMouseCode from './utils/get-mouse-code';
import { default as keyResponder } from './decorators/key-responder';
import { default as onKey } from './decorators/on-key';

function getCode() {
throw new Error(
Expand All @@ -16,15 +16,11 @@ function getKeyCode() {

export { getCode, getKeyCode, getMouseCode, keyResponder, onKey };

export { keyDown, keyUp, keyPress } from 'ember-keyboard/listeners/key-events';
export {
click,
mouseDown,
mouseUp,
} from 'ember-keyboard/listeners/mouse-events';
export { touchStart, touchEnd } from 'ember-keyboard/listeners/touch-events';
export { keyDown, keyUp, keyPress } from './listeners/key-events';
export { click, mouseDown, mouseUp } from './listeners/mouse-events';
export { touchStart, touchEnd } from './listeners/touch-events';
export {
triggerKeyDown,
triggerKeyPress,
triggerKeyUp,
} from 'ember-keyboard/utils/trigger-event';
} from './utils/trigger-event';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import listenerName from 'ember-keyboard/utils/listener-name';
import listenerName from '../utils/listener-name';

export function keyDown(keyCombo) {
return listenerName('keydown', keyCombo);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import listenerName from 'ember-keyboard/utils/listener-name';
import validMouseButtons from 'ember-keyboard/fixtures/mouse-buttons-array';
import validModifiers from 'ember-keyboard/fixtures/modifiers-array';
import listenerName from '../utils/listener-name';
import validMouseButtons from '../fixtures/mouse-buttons-array';
import validModifiers from '../fixtures/modifiers-array';

const validKeys = validMouseButtons.concat(validModifiers);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import listenerName from 'ember-keyboard/utils/listener-name';
import validModifiers from 'ember-keyboard/fixtures/modifiers-array';
import listenerName from '../utils/listener-name';
import validModifiers from '../fixtures/modifiers-array';

function validateKeys(keysString) {
const keys = keysString !== undefined ? keysString.split('+') : [];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Modifier from 'ember-modifier';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import listenerName from 'ember-keyboard/utils/listener-name';
import isKey from 'ember-keyboard/utils/is-key';
import listenerName from '../utils/listener-name';
import isKey from '../utils/is-key';

const ONLY_WHEN_FOCUSED_TAG_NAMES = ['input', 'select', 'textarea'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import Service from '@ember/service';
import { getOwner } from '@ember/application';
import { action } from '@ember/object';
import { run } from '@ember/runloop';
import { keyDown, keyPress, keyUp } from 'ember-keyboard/listeners/key-events';
import { handleKeyEventWithPropagation } from 'ember-keyboard/utils/handle-key-event';
import { reverseCompareProp } from 'ember-keyboard/utils/sort';
import { keyDown, keyPress, keyUp } from '../listeners/key-events';
import { handleKeyEventWithPropagation } from '../utils/handle-key-event';
import { reverseCompareProp } from '../utils/sort';

export default class KeyboardService extends Service {
registeredResponders = new Set();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getMouseCode } from 'ember-keyboard';
import validModifiers from 'ember-keyboard/fixtures/modifiers-array';
import validMouseButtons from 'ember-keyboard/fixtures/mouse-buttons-array';
import getCmdKey from 'ember-keyboard/utils/get-cmd-key';
import getMouseCode from '../utils/get-mouse-code';
import validModifiers from '../fixtures/modifiers-array';
import validMouseButtons from '../fixtures/mouse-buttons-array';
import getCmdKey from '../utils/get-cmd-key';
import { triggerEvent } from '@ember/test-helpers';

export function keyEvent(
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import isKey from 'ember-keyboard/utils/is-key';
import isKey from './is-key';

export function handleKeyEventWithPropagation(
event,
Expand Down
6 changes: 3 additions & 3 deletions addon/addon/utils/is-key.js → addon/src/utils/is-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
SHIFT_KEY_MAP,
MAC_ALT_KEY_MAP,
MAC_SHIFT_ALT_KEY_MAP,
} from 'ember-keyboard/fixtures/key-maps';
import ALL_MODIFIERS from 'ember-keyboard/fixtures/modifiers-array';
import getMouseName from 'ember-keyboard/utils/get-mouse-name';
} from '../fixtures/key-maps';
import ALL_MODIFIERS from '../fixtures/modifiers-array';
import getMouseName from './get-mouse-name';

const ALL_SYMBOL = '_all';

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import getCmdKey from 'ember-keyboard/utils/get-cmd-key';
import getCmdKey from './get-cmd-key';

function sortedKeys(keyArray) {
return keyArray.sort().join('+');
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions test-app/app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
</nav>
<div class="main">
<div class="header">
<img src="./ember-keyboard.svg" alt="" role="presentation" class="logo">
<img src="/ember-keyboard.svg" alt="" role="presentation" class="logo">
<h1 class="header-text">
<code>ember-keyboard</code>
</h1>
<a href="https://github.com/adopted-ember-addons/ember-keyboard" target="_blank" class="github" rel="noopener noreferrer">
<img src="./octocat.png" alt="Octocat" class="octocat">
<img src="/octocat.png" alt="Octocat" class="octocat">
</a>
</div>
{{outlet}}
Expand Down
Loading

0 comments on commit 6688753

Please sign in to comment.