@polymer/iron-a11y-keys-behavior
Advanced tools
Comparing version 3.0.0-pre.12 to 3.0.0-pre.13
@@ -1,5 +0,1 @@ | ||
import '@polymer/polymer/polymer-legacy.js'; | ||
import { IronA11yKeysBehavior } from '../iron-a11y-keys-behavior.js'; | ||
import { Polymer } from '@polymer/polymer/lib/legacy/polymer-fn.js'; | ||
import { html } from '@polymer/polymer/lib/utils/html-tag.js'; | ||
/** | ||
@@ -14,2 +10,7 @@ @license | ||
*/ | ||
import '../../polymer/polymer-legacy.js'; | ||
import { IronA11yKeysBehavior } from '../iron-a11y-keys-behavior.js'; | ||
import { Polymer } from '../../polymer/lib/legacy/polymer-fn.js'; | ||
import { html } from '../../polymer/lib/utils/html-tag.js'; | ||
Polymer({ | ||
@@ -51,13 +52,6 @@ _template: html` | ||
is: 'x-key-aware', | ||
behaviors: [IronA11yKeysBehavior], | ||
behaviors: [ | ||
IronA11yKeysBehavior | ||
], | ||
properties: { | ||
pressed: { | ||
type: String, | ||
readOnly: true, | ||
value: '' | ||
}, | ||
pressed: {type: String, readOnly: true, value: ''}, | ||
@@ -71,7 +65,3 @@ boundKeys: { | ||
preventDefault: { | ||
type: Boolean, | ||
value: true, | ||
notify: true | ||
}, | ||
preventDefault: {type: Boolean, value: true, notify: true}, | ||
@@ -87,3 +77,4 @@ keyEventTarget: { | ||
keyBindings: { | ||
'* pageup pagedown left right down up home end space enter @ ~ " $ ? ! \\ + : # backspace': '_updatePressed', | ||
'* pageup pagedown left right down up home end space enter @ ~ " $ ? ! \\ + : # backspace': | ||
'_updatePressed', | ||
'a': '_updatePressed', | ||
@@ -100,6 +91,4 @@ 'shift+a alt+a': '_updatePressed', | ||
} | ||
this._setPressed( | ||
this.pressed + event.detail.combo + ' pressed!\n' | ||
); | ||
this._setPressed(this.pressed + event.detail.combo + ' pressed!\n'); | ||
} | ||
}); |
@@ -1,2 +0,11 @@ | ||
import '@polymer/polymer/polymer-legacy.js'; | ||
/** | ||
@license | ||
Copyright (c) 2015 The Polymer Project Authors. All rights reserved. | ||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt | ||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | ||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt | ||
Code distributed by Google as part of the polymer project is also | ||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt | ||
*/ | ||
import '../polymer/polymer-legacy.js'; | ||
@@ -7,3 +16,4 @@ /** | ||
* Most keys are labeled as text, but some are Unicode codepoints. | ||
* Values taken from: http://www.w3.org/TR/2007/WD-DOM-Level-3-Events-20071221/keyset.html#KeySet-Set | ||
* Values taken from: | ||
* http://www.w3.org/TR/2007/WD-DOM-Level-3-Events-20071221/keyset.html#KeySet-Set | ||
*/ | ||
@@ -23,3 +33,4 @@ var KEY_IDENTIFIER = { | ||
* | ||
* Values from: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent.keyCode#Value_of_keyCode | ||
* Values from: | ||
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent.keyCode#Value_of_keyCode | ||
*/ | ||
@@ -157,10 +168,10 @@ var KEY_CODE = { | ||
/** | ||
* Calculates the normalized key for a KeyboardEvent. | ||
* @param {KeyboardEvent} keyEvent | ||
* @param {Boolean} [noSpecialChars] Set to true to limit keyEvent.key | ||
* transformation to alpha-numeric chars. This is useful with key | ||
* combinations like shift + 2, which on FF for MacOS produces | ||
* keyEvent.key = @ | ||
* To get 2 returned, set noSpecialChars = true | ||
* To get @ returned, set noSpecialChars = false | ||
* Calculates the normalized key for a KeyboardEvent. | ||
* @param {KeyboardEvent} keyEvent | ||
* @param {Boolean} [noSpecialChars] Set to true to limit keyEvent.key | ||
* transformation to alpha-numeric chars. This is useful with key | ||
* combinations like shift + 2, which on FF for MacOS produces | ||
* keyEvent.key = @ | ||
* To get 2 returned, set noSpecialChars = true | ||
* To get @ returned, set noSpecialChars = false | ||
*/ | ||
@@ -177,3 +188,3 @@ function normalizedKeyForEvent(keyEvent, noSpecialChars) { | ||
return transformKeyIdentifier(keyEvent.keyIdentifier) || | ||
transformKeyCode(keyEvent.keyCode) || ''; | ||
transformKeyCode(keyEvent.keyCode) || ''; | ||
} | ||
@@ -185,8 +196,7 @@ | ||
return keyEvent === keyCombo.key && | ||
(!keyCombo.hasModifiers || ( | ||
!!event.shiftKey === !!keyCombo.shiftKey && | ||
!!event.ctrlKey === !!keyCombo.ctrlKey && | ||
!!event.altKey === !!keyCombo.altKey && | ||
!!event.metaKey === !!keyCombo.metaKey) | ||
); | ||
(!keyCombo.hasModifiers || | ||
(!!event.shiftKey === !!keyCombo.shiftKey && | ||
!!event.ctrlKey === !!keyCombo.ctrlKey && | ||
!!event.altKey === !!keyCombo.altKey && | ||
!!event.metaKey === !!keyCombo.metaKey)); | ||
} | ||
@@ -196,25 +206,20 @@ | ||
if (keyComboString.length === 1) { | ||
return { | ||
combo: keyComboString, | ||
key: keyComboString, | ||
event: 'keydown' | ||
}; | ||
return {combo: keyComboString, key: keyComboString, event: 'keydown'}; | ||
} | ||
return keyComboString.split('+').reduce(function(parsedKeyCombo, keyComboPart) { | ||
var eventParts = keyComboPart.split(':'); | ||
var keyName = eventParts[0]; | ||
var event = eventParts[1]; | ||
return keyComboString.split('+') | ||
.reduce(function(parsedKeyCombo, keyComboPart) { | ||
var eventParts = keyComboPart.split(':'); | ||
var keyName = eventParts[0]; | ||
var event = eventParts[1]; | ||
if (keyName in MODIFIER_KEYS) { | ||
parsedKeyCombo[MODIFIER_KEYS[keyName]] = true; | ||
parsedKeyCombo.hasModifiers = true; | ||
} else { | ||
parsedKeyCombo.key = keyName; | ||
parsedKeyCombo.event = event || 'keydown'; | ||
} | ||
if (keyName in MODIFIER_KEYS) { | ||
parsedKeyCombo[MODIFIER_KEYS[keyName]] = true; | ||
parsedKeyCombo.hasModifiers = true; | ||
} else { | ||
parsedKeyCombo.key = keyName; | ||
parsedKeyCombo.event = event || 'keydown'; | ||
} | ||
return parsedKeyCombo; | ||
}, { | ||
combo: keyComboString.split(':').shift() | ||
}); | ||
return parsedKeyCombo; | ||
}, {combo: keyComboString.split(':').shift()}); | ||
} | ||
@@ -228,2 +233,41 @@ | ||
/** | ||
* `Polymer.IronA11yKeysBehavior` provides a normalized interface for processing | ||
* keyboard commands that pertain to [WAI-ARIA best | ||
* practices](http://www.w3.org/TR/wai-aria-practices/#kbd_general_binding). The | ||
* element takes care of browser differences with respect to Keyboard events and | ||
* uses an expressive syntax to filter key presses. | ||
* | ||
* Use the `keyBindings` prototype property to express what combination of keys | ||
* will trigger the callback. A key binding has the format | ||
* `"KEY+MODIFIER:EVENT": "callback"` (`"KEY": "callback"` or | ||
* `"KEY:EVENT": "callback"` are valid as well). Some examples: | ||
* | ||
* keyBindings: { | ||
* 'space': '_onKeydown', // same as 'space:keydown' | ||
* 'shift+tab': '_onKeydown', | ||
* 'enter:keypress': '_onKeypress', | ||
* 'esc:keyup': '_onKeyup' | ||
* } | ||
* | ||
* The callback will receive with an event containing the following information | ||
* in `event.detail`: | ||
* | ||
* _onKeydown: function(event) { | ||
* console.log(event.detail.combo); // KEY+MODIFIER, e.g. "shift+tab" | ||
* console.log(event.detail.key); // KEY only, e.g. "tab" | ||
* console.log(event.detail.event); // EVENT, e.g. "keydown" | ||
* console.log(event.detail.keyboardEvent); // the original KeyboardEvent | ||
* } | ||
* | ||
* Use the `keyEventTarget` attribute to set up event handlers on a specific | ||
* node. | ||
* | ||
* See the [demo source | ||
* code](https://github.com/PolymerElements/iron-a11y-keys-behavior/blob/master/demo/x-key-aware.html) | ||
* for an example. | ||
* | ||
* @demo demo/index.html | ||
* @polymerBehavior | ||
*/ | ||
export const IronA11yKeysBehavior = { | ||
@@ -247,6 +291,3 @@ properties: { | ||
*/ | ||
stopKeyboardEventPropagation: { | ||
type: Boolean, | ||
value: false | ||
}, | ||
stopKeyboardEventPropagation: {type: Boolean, value: false}, | ||
@@ -270,5 +311,3 @@ _boundKeyHandlers: { | ||
observers: [ | ||
'_resetKeyEventListeners(keyEventTarget, _boundKeyHandlers)' | ||
], | ||
observers: ['_resetKeyEventListeners(keyEventTarget, _boundKeyHandlers)'], | ||
@@ -357,3 +396,4 @@ | ||
for (var eventString in this._imperativeKeyBindings) { | ||
this._addKeyBinding(eventString, this._imperativeKeyBindings[eventString]); | ||
this._addKeyBinding( | ||
eventString, this._imperativeKeyBindings[eventString]); | ||
} | ||
@@ -363,3 +403,3 @@ | ||
for (var eventName in this._keyBindings) { | ||
this._keyBindings[eventName].sort(function (kb1, kb2) { | ||
this._keyBindings[eventName].sort(function(kb1, kb2) { | ||
var b1 = kb1[0].hasModifiers; | ||
@@ -375,8 +415,5 @@ var b2 = kb2[0].hasModifiers; | ||
this._keyBindings[keyCombo.event] = | ||
this._keyBindings[keyCombo.event] || []; | ||
this._keyBindings[keyCombo.event] || []; | ||
this._keyBindings[keyCombo.event].push([ | ||
keyCombo, | ||
handlerName | ||
]); | ||
this._keyBindings[keyCombo.event].push([keyCombo, handlerName]); | ||
}, this); | ||
@@ -401,3 +438,4 @@ }, | ||
this._boundKeyHandlers.push([this.keyEventTarget, eventName, boundKeyHandler]); | ||
this._boundKeyHandlers.push( | ||
[this.keyEventTarget, eventName, boundKeyHandler]); | ||
@@ -451,6 +489,4 @@ this.keyEventTarget.addEventListener(eventName, boundKeyHandler); | ||
detail.keyboardEvent = keyboardEvent; | ||
var event = new CustomEvent(keyCombo.event, { | ||
detail: detail, | ||
cancelable: true | ||
}); | ||
var event = | ||
new CustomEvent(keyCombo.event, {detail: detail, cancelable: true}); | ||
this[handlerName].call(this, event); | ||
@@ -457,0 +493,0 @@ if (event.defaultPrevented) { |
@@ -19,13 +19,15 @@ { | ||
"bower": "^1.8.0", | ||
"@polymer/iron-demo-helpers": "3.0.0-pre.12", | ||
"@polymer/iron-component-page": "3.0.0-pre.12", | ||
"@polymer/iron-test-helpers": "3.0.0-pre.12", | ||
"@polymer/test-fixture": "3.0.0-pre.12", | ||
"wct-browser-legacy": "0.0.1-pre.11", | ||
"@webcomponents/webcomponentsjs": "^1.0.0" | ||
"webmat": "^0.2.0", | ||
"@polymer/iron-demo-helpers": "^3.0.0-pre.13", | ||
"@polymer/iron-component-page": "^3.0.0-pre.13", | ||
"@polymer/iron-test-helpers": "^3.0.0-pre.13", | ||
"@polymer/test-fixture": "^3.0.0-pre.13", | ||
"wct-browser-legacy": "^0.0.1-pre.11", | ||
"@webcomponents/webcomponentsjs": "^2.0.0-0" | ||
}, | ||
"scripts": { | ||
"update-types": "bower install && gen-typescript-declarations --deleteExisting --outDir ." | ||
"update-types": "bower install && gen-typescript-declarations --deleteExisting --outDir .", | ||
"format": "webmat && npm run update-types" | ||
}, | ||
"version": "3.0.0-pre.12", | ||
"version": "3.0.0-pre.13", | ||
"resolutions": { | ||
@@ -40,4 +42,4 @@ "inherits": "2.0.3", | ||
"dependencies": { | ||
"@polymer/polymer": "3.0.0-pre.12" | ||
"@polymer/polymer": "^3.0.0-pre.13" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43354
538
9
+ Added@polymer/polymer@3.5.2(transitive)
- Removed@polymer/polymer@3.0.0-pre.12(transitive)
- Removed@webcomponents/webcomponentsjs@1.3.3(transitive)