diff --git a/addon/.eslintrc.js b/addon/.eslintrc.js index ab627f4f0..36d6543b2 100644 --- a/addon/.eslintrc.js +++ b/addon/.eslintrc.js @@ -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', @@ -44,10 +40,5 @@ module.exports = { plugins: ['node'], extends: ['plugin:node/recommended'], }, - { - // Test files: - files: ['tests/**/*-test.{js,ts}'], - extends: ['plugin:qunit/recommended'], - }, ], }; diff --git a/addon/addon-main.js b/addon/addon-main.js new file mode 100644 index 000000000..3cde686e1 --- /dev/null +++ b/addon/addon-main.js @@ -0,0 +1,3 @@ +const { addonV1Shim } = require('@embroider/addon-shim'); + +module.exports = addonV1Shim(__dirname); diff --git a/addon/app/helpers/if-key.js b/addon/app/helpers/if-key.js deleted file mode 100644 index 2cf2bf337..000000000 --- a/addon/app/helpers/if-key.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'ember-keyboard/helpers/if-key'; diff --git a/addon/app/helpers/on-key.js b/addon/app/helpers/on-key.js deleted file mode 100644 index 09db44c65..000000000 --- a/addon/app/helpers/on-key.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'ember-keyboard/helpers/on-key'; diff --git a/addon/app/modifiers/on-key.js b/addon/app/modifiers/on-key.js deleted file mode 100644 index 7223adda8..000000000 --- a/addon/app/modifiers/on-key.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'ember-keyboard/modifiers/on-key'; diff --git a/addon/app/services/keyboard.js b/addon/app/services/keyboard.js deleted file mode 100644 index 2c4de666e..000000000 --- a/addon/app/services/keyboard.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'ember-keyboard/services/keyboard'; diff --git a/addon/babel.config.json b/addon/babel.config.json new file mode 100644 index 000000000..cfcf8a3c3 --- /dev/null +++ b/addon/babel.config.json @@ -0,0 +1,7 @@ +{ + "plugins": [ + "@embroider/addon-dev/template-colocation-plugin", + ["@babel/plugin-proposal-decorators", { "legacy": true }], + "@babel/plugin-proposal-class-properties" + ] +} diff --git a/addon/index.js b/addon/index.js deleted file mode 100644 index 979a62839..000000000 --- a/addon/index.js +++ /dev/null @@ -1,36 +0,0 @@ -'use strict'; - -module.exports = { - name: require('./package').name, - - config(environment, appConfig) { - const addonConfig = appConfig['emberKeyboard'] || {}; - - if ( - 'disableInputsInitializer' in addonConfig && - !this.disableInputsInitializerDeprecationPrinted - ) { - // Do not print deprecation message multiple times - // as this hook may be invoked more than once. - this.disableInputsInitializerDeprecationPrinted = true; - - this.ui.writeDeprecateLine( - '[ember-keyboard] The `emberKeyboard.disableInputsInitializer` option is obsolete. ' + - 'You can remove it from your `config/environment.js` file.', - false - ); - } - - if ('propagation' in addonConfig && !this.propagationDeprecationPrinted) { - // Do not print deprecation message multiple times - // as this hook may be invoked more than once. - this.propagationDeprecationPrinted = true; - - this.ui.writeDeprecateLine( - '[ember-keyboard] The `emberKeyboard.propagation` option is obsolete. ' + - 'You can remove it from your `config/environment.js` file.', - false - ); - } - }, -}; diff --git a/addon/package.json b/addon/package.json index eb5f16c64..97cd1a154 100644 --- a/addon/package.json +++ b/addon/package.json @@ -12,18 +12,36 @@ "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", @@ -31,8 +49,16 @@ "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" @@ -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": { diff --git a/addon/rollup.config.js b/addon/rollup.config.js new file mode 100644 index 000000000..d59b1a377 --- /dev/null +++ b/addon/rollup.config.js @@ -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(), + ], +}; diff --git a/addon/addon/decorators/key-responder.js b/addon/src/decorators/key-responder.js similarity index 100% rename from addon/addon/decorators/key-responder.js rename to addon/src/decorators/key-responder.js diff --git a/addon/addon/decorators/on-key.js b/addon/src/decorators/on-key.js similarity index 95% rename from addon/addon/decorators/on-key.js rename to addon/src/decorators/on-key.js index 1b54cd7e4..f57786c72 100644 --- a/addon/addon/decorators/on-key.js +++ b/addon/src/decorators/on-key.js @@ -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 = {}) { diff --git a/addon/addon/fixtures/key-maps.js b/addon/src/fixtures/key-maps.js similarity index 100% rename from addon/addon/fixtures/key-maps.js rename to addon/src/fixtures/key-maps.js diff --git a/addon/addon/fixtures/modifiers-array.js b/addon/src/fixtures/modifiers-array.js similarity index 100% rename from addon/addon/fixtures/modifiers-array.js rename to addon/src/fixtures/modifiers-array.js diff --git a/addon/addon/fixtures/mouse-buttons-array.js b/addon/src/fixtures/mouse-buttons-array.js similarity index 100% rename from addon/addon/fixtures/mouse-buttons-array.js rename to addon/src/fixtures/mouse-buttons-array.js diff --git a/addon/addon/helpers/if-key.js b/addon/src/helpers/if-key.js similarity index 83% rename from addon/addon/helpers/if-key.js rename to addon/src/helpers/if-key.js index f89496c91..aca12b5df 100644 --- a/addon/addon/helpers/if-key.js +++ b/addon/src/helpers/if-key.js @@ -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) { diff --git a/addon/addon/helpers/on-key.js b/addon/src/helpers/on-key.js similarity index 93% rename from addon/addon/helpers/on-key.js rename to addon/src/helpers/on-key.js index b3a0a7169..e7be51269 100644 --- a/addon/addon/helpers/on-key.js +++ b/addon/src/helpers/on-key.js @@ -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; diff --git a/addon/addon/index.js b/addon/src/index.js similarity index 51% rename from addon/addon/index.js rename to addon/src/index.js index 34f47a7cc..41877f854 100644 --- a/addon/addon/index.js +++ b/addon/src/index.js @@ -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( @@ -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'; diff --git a/addon/addon/listeners/key-events.js b/addon/src/listeners/key-events.js similarity index 79% rename from addon/addon/listeners/key-events.js rename to addon/src/listeners/key-events.js index 2844b695e..802538886 100644 --- a/addon/addon/listeners/key-events.js +++ b/addon/src/listeners/key-events.js @@ -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); diff --git a/addon/addon/listeners/mouse-events.js b/addon/src/listeners/mouse-events.js similarity index 78% rename from addon/addon/listeners/mouse-events.js rename to addon/src/listeners/mouse-events.js index c7d111a83..621153f04 100644 --- a/addon/addon/listeners/mouse-events.js +++ b/addon/src/listeners/mouse-events.js @@ -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); diff --git a/addon/addon/listeners/touch-events.js b/addon/src/listeners/touch-events.js similarity index 82% rename from addon/addon/listeners/touch-events.js rename to addon/src/listeners/touch-events.js index a032e3c16..c20b2f535 100644 --- a/addon/addon/listeners/touch-events.js +++ b/addon/src/listeners/touch-events.js @@ -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('+') : []; diff --git a/addon/addon/modifiers/on-key.js b/addon/src/modifiers/on-key.js similarity index 96% rename from addon/addon/modifiers/on-key.js rename to addon/src/modifiers/on-key.js index 98c909b62..458772238 100644 --- a/addon/addon/modifiers/on-key.js +++ b/addon/src/modifiers/on-key.js @@ -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']; diff --git a/addon/addon/services/keyboard.js b/addon/src/services/keyboard.js similarity index 91% rename from addon/addon/services/keyboard.js rename to addon/src/services/keyboard.js index 0370df09b..bfa8b1da5 100644 --- a/addon/addon/services/keyboard.js +++ b/addon/src/services/keyboard.js @@ -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(); diff --git a/addon/addon-test-support/key-event.js b/addon/src/test-support/key-event.js similarity index 77% rename from addon/addon-test-support/key-event.js rename to addon/src/test-support/key-event.js index 98f840200..a94203a2c 100644 --- a/addon/addon-test-support/key-event.js +++ b/addon/src/test-support/key-event.js @@ -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( diff --git a/addon/addon-test-support/test-helpers.js b/addon/src/test-support/test-helpers.js similarity index 100% rename from addon/addon-test-support/test-helpers.js rename to addon/src/test-support/test-helpers.js diff --git a/addon/addon/utils/get-cmd-key.js b/addon/src/utils/get-cmd-key.js similarity index 100% rename from addon/addon/utils/get-cmd-key.js rename to addon/src/utils/get-cmd-key.js diff --git a/addon/addon/utils/get-mouse-code.js b/addon/src/utils/get-mouse-code.js similarity index 100% rename from addon/addon/utils/get-mouse-code.js rename to addon/src/utils/get-mouse-code.js diff --git a/addon/addon/utils/get-mouse-name.js b/addon/src/utils/get-mouse-name.js similarity index 100% rename from addon/addon/utils/get-mouse-name.js rename to addon/src/utils/get-mouse-name.js diff --git a/addon/addon/utils/handle-key-event.js b/addon/src/utils/handle-key-event.js similarity index 97% rename from addon/addon/utils/handle-key-event.js rename to addon/src/utils/handle-key-event.js index 7eaaac014..3a740fb1c 100644 --- a/addon/addon/utils/handle-key-event.js +++ b/addon/src/utils/handle-key-event.js @@ -1,4 +1,4 @@ -import isKey from 'ember-keyboard/utils/is-key'; +import isKey from './is-key'; export function handleKeyEventWithPropagation( event, diff --git a/addon/addon/utils/is-key.js b/addon/src/utils/is-key.js similarity index 95% rename from addon/addon/utils/is-key.js rename to addon/src/utils/is-key.js index 7ec7a6215..38d5f7d4f 100644 --- a/addon/addon/utils/is-key.js +++ b/addon/src/utils/is-key.js @@ -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'; diff --git a/addon/addon/utils/keyboard-listener.js b/addon/src/utils/keyboard-listener.js similarity index 100% rename from addon/addon/utils/keyboard-listener.js rename to addon/src/utils/keyboard-listener.js diff --git a/addon/addon/utils/listener-name.js b/addon/src/utils/listener-name.js similarity index 89% rename from addon/addon/utils/listener-name.js rename to addon/src/utils/listener-name.js index 32693fccc..f61051a75 100644 --- a/addon/addon/utils/listener-name.js +++ b/addon/src/utils/listener-name.js @@ -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('+'); diff --git a/addon/addon/utils/platform.js b/addon/src/utils/platform.js similarity index 100% rename from addon/addon/utils/platform.js rename to addon/src/utils/platform.js diff --git a/addon/addon/utils/sort.js b/addon/src/utils/sort.js similarity index 100% rename from addon/addon/utils/sort.js rename to addon/src/utils/sort.js diff --git a/addon/addon/utils/trigger-event.js b/addon/src/utils/trigger-event.js similarity index 100% rename from addon/addon/utils/trigger-event.js rename to addon/src/utils/trigger-event.js diff --git a/test-app/app/templates/application.hbs b/test-app/app/templates/application.hbs index 5dcf7b935..289dc7482 100644 --- a/test-app/app/templates/application.hbs +++ b/test-app/app/templates/application.hbs @@ -10,12 +10,12 @@
ember-keyboard