New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

makeup-navigation-emitter

Package Overview
Dependencies
Maintainers
7
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

makeup-navigation-emitter - npm Package Compare versions

Comparing version 0.6.0 to 0.6.2

./dist/cjs/index.js

4

browser.json
{
"dependencies":[
"require: ./dist/index.js"
]
"dependencies": ["require: ./dist/index.js"]
}

@@ -9,8 +9,8 @@ "use strict";

var ExitEmitter = _interopRequireWildcard(require("makeup-exit-emitter"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var defaultOptions = {
axis: 'both',
autoInit: 'interactive',
autoReset: 'current',
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
const defaultOptions = {
axis: "both",
autoInit: "interactive",
autoReset: "current",
ignoreByDelegateSelector: null,

@@ -20,3 +20,3 @@ wrap: false

function isItemNavigable(el) {
return !el.hidden && el.getAttribute('aria-disabled') !== 'true';
return !el.hidden && el.getAttribute("aria-disabled") !== "true";
}

@@ -40,6 +40,6 @@ function isIndexNavigable(items, index) {

function findFirstNavigableAriaCheckedIndex(items) {
return findIndexByAttribute(items, 'aria-checked', 'true');
return findIndexByAttribute(items, "aria-checked", "true");
}
function findFirstNavigableAriaSelectedIndex(items) {
return findIndexByAttribute(items, 'aria-selected', 'true');
return findIndexByAttribute(items, "aria-selected", "true");
}

@@ -50,6 +50,4 @@ function findIgnoredByDelegateItems(el, options) {

function findPreviousNavigableIndex(items, index, wrap) {
var previousNavigableIndex = -1;
if (index === null) {
// no-op
} else if (atStart(items, index)) {
let previousNavigableIndex = -1;
if (index === null || atStart(items, index)) {
if (wrap === true) {

@@ -59,3 +57,3 @@ previousNavigableIndex = findLastNavigableIndex(items);

} else {
var i = index;
let i = index;
while (--i >= 0) {

@@ -71,3 +69,3 @@ if (isItemNavigable(items[i])) {

function findNextNavigableIndex(items, index, wrap) {
var nextNavigableIndex = -1;
let nextNavigableIndex = -1;
if (index === null) {

@@ -80,3 +78,3 @@ nextNavigableIndex = findFirstNavigableIndex(items);

} else {
var i = index;
let i = index;
while (++i < items.length) {

@@ -94,20 +92,20 @@ if (isItemNavigable(items[i])) {

function findIndexPositionByType(typeOrNum, items, currentIndex) {
var index = -1;
let index = -1;
switch (typeOrNum) {
case 'none':
case "none":
index = null;
break;
case 'current':
case "current":
index = currentIndex;
break;
case 'interactive':
case "interactive":
index = findFirstNavigableIndex(items);
break;
case 'ariaChecked':
case "ariaChecked":
index = findFirstNavigableAriaCheckedIndex(items);
break;
case 'ariaSelected':
case "ariaSelected":
index = findFirstNavigableAriaSelectedIndex(items);
break;
case 'ariaSelectedOrInteractive':
case "ariaSelectedOrInteractive":
index = findFirstNavigableAriaSelectedIndex(items);

@@ -117,3 +115,3 @@ index = index === -1 ? findFirstNavigableIndex(items) : index;

default:
index = typeof typeOrNum === 'number' || typeOrNum === null ? typeOrNum : -1;
index = typeof typeOrNum === "number" || typeOrNum === null ? typeOrNum : -1;
}

@@ -129,3 +127,3 @@ return index;

function onKeyPrev(e) {
var ignoredByDelegateItems = findIgnoredByDelegateItems(this._el, this.options);
const ignoredByDelegateItems = findIgnoredByDelegateItems(this._el, this.options);

@@ -138,3 +136,3 @@ // todo: update KeyEmitter to deal with ignored items?

function onKeyNext(e) {
var ignoredByDelegateItems = findIgnoredByDelegateItems(this._el, this.options);
const ignoredByDelegateItems = findIgnoredByDelegateItems(this._el, this.options);

@@ -147,3 +145,3 @@ // todo: update KeyEmitter to deal with ignored items?

function onClick(e) {
var itemIndex = this.indexOf(e.target.closest(this._itemSelector));
const itemIndex = this.indexOf(e.target.closest(this._itemSelector));
if (isIndexNavigable(this.items, itemIndex)) {

@@ -154,3 +152,3 @@ this.index = itemIndex;

function onKeyHome(e) {
var ignoredByDelegateItems = findIgnoredByDelegateItems(this._el, this.options);
const ignoredByDelegateItems = findIgnoredByDelegateItems(this._el, this.options);

@@ -163,3 +161,3 @@ // todo: update KeyEmitter to deal with ignored items?

function onKeyEnd(e) {
var ignoredByDelegateItems = findIgnoredByDelegateItems(this._el, this.options);
const ignoredByDelegateItems = findIgnoredByDelegateItems(this._el, this.options);

@@ -177,6 +175,6 @@ // todo: update KeyEmitter to deal with ignored items?

function onMutation(e) {
var fromIndex = this.index;
var toIndex = this.index;
const fromIndex = this.index;
let toIndex = this.index;
// https://developer.mozilla.org/en-US/docs/Web/API/MutationRecord
var {
const {
addedNodes,

@@ -188,8 +186,8 @@ attributeName,

} = e[0];
if (type === 'attributes') {
if (type === "attributes") {
if (target === this.currentItem) {
if (attributeName === 'aria-disabled') {
if (attributeName === "aria-disabled") {
// current item was disabled - keep it as current index (until a keyboard navigation happens)
toIndex = this.index;
} else if (attributeName === 'hidden') {
} else if (attributeName === "hidden") {
// current item was hidden and focus is lost - reset index to first interactive element

@@ -201,3 +199,3 @@ toIndex = findFirstNavigableIndex(this.items);

}
} else if (type === 'childList') {
} else if (type === "childList") {
if (removedNodes.length > 0 && [...removedNodes].includes(this._cachedElement)) {

@@ -212,3 +210,3 @@ // current item was removed and focus is lost - reset index to first interactive element

this._index = toIndex;
this._el.dispatchEvent(new CustomEvent('navigationModelMutation', {
this._el.dispatchEvent(new CustomEvent("navigationModelMutation", {
bubbles: false,

@@ -246,4 +244,4 @@ detail: {

super(el, itemSelector, selectedOptions);
var fromIndex = this._index;
var toIndex = findIndexPositionByType(this.options.autoInit, this.items, this.index);
const fromIndex = this._index;
const toIndex = findIndexPositionByType(this.options.autoInit, this.items, this.index);

@@ -256,3 +254,3 @@ // do not use setter as it will trigger a change event

this._cachedElement = this.items[toIndex];
this._el.dispatchEvent(new CustomEvent('navigationModelInit', {
this._el.dispatchEvent(new CustomEvent("navigationModelInit", {
bubbles: false,

@@ -288,7 +286,7 @@ detail: {

} else {
var fromIndex = this.index;
const fromIndex = this.index;
// update cached element reference (for use in mutation observer if DOM node gets removed)
this._cachedElement = this.items[toIndex];
this._index = toIndex;
this._el.dispatchEvent(new CustomEvent('navigationModelChange', {
this._el.dispatchEvent(new CustomEvent("navigationModelChange", {
bubbles: false,

@@ -306,8 +304,8 @@ detail: {

reset() {
var fromIndex = this.index;
var toIndex = findIndexPositionByType(this.options.autoReset, this.items, this.index);
const fromIndex = this.index;
const toIndex = findIndexPositionByType(this.options.autoReset, this.items, this.index);
if (toIndex !== fromIndex) {
// do not use setter as it will trigger a navigationModelChange event
this._index = toIndex;
this._el.dispatchEvent(new CustomEvent('navigationModelReset', {
this._el.dispatchEvent(new CustomEvent("navigationModelReset", {
bubbles: false,

@@ -351,19 +349,19 @@ detail: {

ExitEmitter.addFocusExit(this.el);
var axis = model.options.axis;
if (axis === 'both' || axis === 'x') {
this.el.addEventListener('arrowLeftKeyDown', this._keyPrevListener);
this.el.addEventListener('arrowRightKeyDown', this._keyNextListener);
const axis = model.options.axis;
if (axis === "both" || axis === "x") {
this.el.addEventListener("arrowLeftKeyDown", this._keyPrevListener);
this.el.addEventListener("arrowRightKeyDown", this._keyNextListener);
}
if (axis === 'both' || axis === 'y') {
this.el.addEventListener('arrowUpKeyDown', this._keyPrevListener);
this.el.addEventListener('arrowDownKeyDown', this._keyNextListener);
if (axis === "both" || axis === "y") {
this.el.addEventListener("arrowUpKeyDown", this._keyPrevListener);
this.el.addEventListener("arrowDownKeyDown", this._keyNextListener);
}
this.el.addEventListener('homeKeyDown', this._keyHomeListener);
this.el.addEventListener('endKeyDown', this._keyEndListener);
this.el.addEventListener('click', this._clickListener);
this.el.addEventListener('focusExit', this._focusExitListener);
this.el.addEventListener("homeKeyDown", this._keyHomeListener);
this.el.addEventListener("endKeyDown", this._keyEndListener);
this.el.addEventListener("click", this._clickListener);
this.el.addEventListener("focusExit", this._focusExitListener);
this._observer.observe(this.el, {
childList: true,
subtree: true,
attributeFilter: ['aria-disabled', 'hidden'],
attributeFilter: ["aria-disabled", "hidden"],
attributes: true,

@@ -376,10 +374,10 @@ attributeOldValue: true

ExitEmitter.removeFocusExit(this.el);
this.el.removeEventListener('arrowLeftKeyDown', this._keyPrevListener);
this.el.removeEventListener('arrowRightKeyDown', this._keyNextListener);
this.el.removeEventListener('arrowUpKeyDown', this._keyPrevListener);
this.el.removeEventListener('arrowDownKeyDown', this._keyNextListener);
this.el.removeEventListener('homeKeyDown', this._keyHomeListener);
this.el.removeEventListener('endKeyDown', this._keyEndListener);
this.el.removeEventListener('click', this._clickListener);
this.el.removeEventListener('focusExit', this._focusExitListener);
this.el.removeEventListener("arrowLeftKeyDown", this._keyPrevListener);
this.el.removeEventListener("arrowRightKeyDown", this._keyNextListener);
this.el.removeEventListener("arrowUpKeyDown", this._keyPrevListener);
this.el.removeEventListener("arrowDownKeyDown", this._keyNextListener);
this.el.removeEventListener("homeKeyDown", this._keyHomeListener);
this.el.removeEventListener("endKeyDown", this._keyEndListener);
this.el.removeEventListener("click", this._clickListener);
this.el.removeEventListener("focusExit", this._focusExitListener);
this._observer.disconnect();

@@ -389,3 +387,3 @@ }

function createLinear(el, itemSelector, selectedOptions) {
var model = new LinearNavigationModel(el, itemSelector, selectedOptions);
const model = new LinearNavigationModel(el, itemSelector, selectedOptions);
return new NavigationEmitter(el, model);

@@ -392,0 +390,0 @@ }

@@ -39,4 +39,3 @@ import * as KeyEmitter from "makeup-key-emitter";

let previousNavigableIndex = -1;
if (index === null) {
} else if (atStart(items, index)) {
if (index === null || atStart(items, index)) {
if (wrap === true) {

@@ -165,8 +164,15 @@ previousNavigableIndex = findLastNavigableIndex(items);

this._index = toIndex;
this._el.dispatchEvent(new CustomEvent("navigationModelMutation", {
bubbles: false,
detail: { fromIndex, toIndex }
}));
this._el.dispatchEvent(
new CustomEvent("navigationModelMutation", {
bubbles: false,
detail: { fromIndex, toIndex }
})
);
}
class NavigationModel {
/**
* @param {HTMLElement} el
* @param {string} itemSelector
* @param {typeof defaultOptions} selectedOptions
*/
constructor(el, itemSelector, selectedOptions) {

@@ -179,2 +185,7 @@ this.options = Object.assign({}, defaultOptions, selectedOptions);

class LinearNavigationModel extends NavigationModel {
/**
* @param {HTMLElement} el
* @param {string} itemSelector
* @param {typeof defaultOptions} selectedOptions
*/
constructor(el, itemSelector, selectedOptions) {

@@ -186,11 +197,13 @@ super(el, itemSelector, selectedOptions);

this._cachedElement = this.items[toIndex];
this._el.dispatchEvent(new CustomEvent("navigationModelInit", {
bubbles: false,
detail: {
firstInteractiveIndex: this.firstNavigableIndex,
fromIndex,
items: this.items,
toIndex
}
}));
this._el.dispatchEvent(
new CustomEvent("navigationModelInit", {
bubbles: false,
detail: {
firstInteractiveIndex: this.firstNavigableIndex,
fromIndex,
items: this.items,
toIndex
}
})
);
}

@@ -200,2 +213,3 @@ get currentItem() {

}
// todo: code smell as getter abstracts that the query selector re-runs every time getter is accessed
get items() {

@@ -207,2 +221,5 @@ return [...this._el.querySelectorAll(`${this._itemSelector}`)];

}
/**
* @param {number} toIndex - update index position in this.items (non-interactive indexes fail silently)
*/
set index(toIndex) {

@@ -216,6 +233,8 @@ if (toIndex === this.index) {

this._index = toIndex;
this._el.dispatchEvent(new CustomEvent("navigationModelChange", {
bubbles: false,
detail: { fromIndex, toIndex }
}));
this._el.dispatchEvent(
new CustomEvent("navigationModelChange", {
bubbles: false,
detail: { fromIndex, toIndex }
})
);
}

@@ -231,6 +250,8 @@ }

this._index = toIndex;
this._el.dispatchEvent(new CustomEvent("navigationModelReset", {
bubbles: false,
detail: { fromIndex, toIndex }
}));
this._el.dispatchEvent(
new CustomEvent("navigationModelReset", {
bubbles: false,
detail: { fromIndex, toIndex }
})
);
}

@@ -240,2 +261,6 @@ }

class NavigationEmitter {
/**
* @param {HTMLElement} el
* @param {LinearNavigationModel} model
*/
constructor(el, model) {

@@ -242,0 +267,0 @@ this.model = model;

{
"name": "makeup-navigation-emitter",
"description": "Emits custom events based on keyboard navigation of one or two dimensional model",
"version": "0.6.0",
"version": "0.6.2",
"main": "./dist/cjs/index.js",

@@ -13,3 +13,3 @@ "module": "dist/mjs/index.js",

},
"repository": "https://github.com/makeup/makeup-js/tree/master/packages/makeup-navigation-emitter",
"repository": "https://github.com/makeup/makeup-js/tree/master/packages/core/makeup-navigation-emitter",
"author": "Ian McBurnie <ianmcburnie@hotmail.com>",

@@ -30,4 +30,4 @@ "license": "MIT",

"dependencies": {
"makeup-exit-emitter": "~0.4.0",
"makeup-key-emitter": "~0.3.0"
"makeup-exit-emitter": "^0.4.2",
"makeup-key-emitter": "^0.3.2"
},

@@ -42,3 +42,4 @@ "files": [

"extends @ebay/browserslist-config"
]
],
"gitHead": "4d199965cba30b5f63cfc38b5b58544cfc5b27c1"
}

@@ -11,3 +11,3 @@ # makeup-navigation-emitter

**NOTE**: All examples below show *abstract* markup examples/structures. In an effort to make clear what this module does and does not do, all examples **do not** include ARIA roles, state or properties.
**NOTE**: All examples below show _abstract_ markup examples/structures. In an effort to make clear what this module does and does not do, all examples **do not** include ARIA roles, state or properties.

@@ -24,7 +24,7 @@ ## Example 1

<div class="widget">
<ul>
<li tabindex="0">Item 0</li>
<li>Item 1</li>
<li>Item 2</li>
</ul>
<ul>
<li tabindex="0">Item 0</li>
<li>Item 1</li>
<li>Item 2</li>
</ul>
</div>

@@ -56,7 +56,7 @@ ```

<div class="widget" tabindex="0">
<ul>
<li>Item 0</li>
<li>Item 1</li>
<li>Item 2</li>
</ul>
<ul>
<li>Item 0</li>
<li>Item 1</li>
<li>Item 2</li>
</ul>
</div>

@@ -87,8 +87,8 @@ ```

<div class="widget">
<input type="text" />
<ul>
<li>Item 0</li>
<li>Item 1</li>
<li>Item 2</li>
</ul>
<input type="text" />
<ul>
<li>Item 0</li>
<li>Item 1</li>
<li>Item 2</li>
</ul>
</div>

@@ -111,35 +111,35 @@ ```

* `autoInit`: declares the initial item (default: "interactive"). Possible values are:
* "none": no index position is set (useful in programmatic active-descendant)
* "interactive": first non aria-disabled or hidden element (default)
* "ariaChecked": first element with aria-checked=true (useful in ARIA menu)
* "ariaSelected": first element with aria-selected=true (useful in ARIA tabs)
* "ariaSelectedOrInteractive": first element with aria-selected=true, falling back to "interactive" if not found (useful in ARIA listbox)
* *number*: specific index position of items (throws error if non-interactive)
* `autoReset`: declares the item after a reset and/or when keyboard focus exits the widget (default: "current"). Possible values are:
* "none": no index position is set (useful in programmatic active-descendant)
* "current": index remains current (radio button like behaviour)
* "interactive": index moves to first non aria-disabled or hidden element
* "ariaChecked": index moves to first element with aria-checked=true
* "ariaSelected": index moves to first element with aria-selected=true
* *number*: specific index position of items (throws error if non-interactive)
* `axis` : specify 'x' for left/right arrow keys, 'y' for up/down arrow keys, or 'both' (default: 'both')
* `ignoreByDelegateSelector`: CSS selector of descendant elements that will be ignored by the key event delegation (i.e. these elements will *not* operate the navigation emitter) (default: null)
* `wrap` : specify whether arrow keys should wrap/loop (default: false)
- `autoInit`: declares the initial item (default: "interactive"). Possible values are:
- "none": no index position is set (useful in programmatic active-descendant)
- "interactive": first non aria-disabled or hidden element (default)
- "ariaChecked": first element with aria-checked=true (useful in ARIA menu)
- "ariaSelected": first element with aria-selected=true (useful in ARIA tabs)
- "ariaSelectedOrInteractive": first element with aria-selected=true, falling back to "interactive" if not found (useful in ARIA listbox)
- _number_: specific index position of items (throws error if non-interactive)
- `autoReset`: declares the item after a reset and/or when keyboard focus exits the widget (default: "current"). Possible values are:
- "none": no index position is set (useful in programmatic active-descendant)
- "current": index remains current (radio button like behaviour)
- "interactive": index moves to first non aria-disabled or hidden element
- "ariaChecked": index moves to first element with aria-checked=true
- "ariaSelected": index moves to first element with aria-selected=true
- _number_: specific index position of items (throws error if non-interactive)
- `axis` : specify 'x' for left/right arrow keys, 'y' for up/down arrow keys, or 'both' (default: 'both')
- `ignoreByDelegateSelector`: CSS selector of descendant elements that will be ignored by the key event delegation (i.e. these elements will _not_ operate the navigation emitter) (default: null)
- `wrap` : specify whether arrow keys should wrap/loop (default: false)
## Methods
* `destroy`: destroys all event listeners
* `reset`: will force a reset to the value specified by `autoReset`
- `destroy`: destroys all event listeners
- `reset`: will force a reset to the value specified by `autoReset`
## Properties
* `matchingItems`: returns all items that match item selector
* `navigableItems`: returns navigable subset of matchingItems (e.g. non-hidden & non aria-disabled items)
- `matchingItems`: returns all items that match item selector
- `navigableItems`: returns navigable subset of matchingItems (e.g. non-hidden & non aria-disabled items)
## Events
* `navigationModelInit` - fired when the model is auto initialised (bubbles: false)
* `navigationModelChange` - fired when the index is set by any means other than auto init or auto reset (bubbles: false)
* `navigationModelReset` - fired when the model is auto reset (bubbles: false)
* `navigationModelMutation` - fired when any changes to the elements DOM (bubbles: false)
- `navigationModelInit` - fired when the model is auto initialised (bubbles: false)
- `navigationModelChange` - fired when the index is set by any means other than auto init or auto reset (bubbles: false)
- `navigationModelReset` - fired when the model is auto reset (bubbles: false)
- `navigationModelMutation` - fired when any changes to the elements DOM (bubbles: false)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc