@spectrum-web-components/reactive-controllers
Advanced tools
Comparing version 0.3.2 to 0.3.3
{ | ||
"name": "@spectrum-web-components/reactive-controllers", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"publishConfig": { | ||
@@ -71,4 +71,3 @@ "access": "public" | ||
"dependencies": { | ||
"lit": "^2.1.2", | ||
"tslib": "^2.0.0" | ||
"lit": "^2.1.2" | ||
}, | ||
@@ -80,3 +79,3 @@ "types": "./src/index.d.ts", | ||
], | ||
"gitHead": "31d083d1eb61a1382335030c190c85d85f41e15d" | ||
"gitHead": "8bd87724e91e23df83dbf63a434bbbe10b8daaa6" | ||
} |
"use strict"; | ||
function ensureMethod(value, type, fallback) { | ||
if (typeof value === type) { | ||
return () => value; | ||
} else if (typeof value === "function") { | ||
return value; | ||
} | ||
return fallback; | ||
} | ||
export class FocusGroupController { | ||
@@ -83,18 +91,18 @@ constructor(host, { | ||
this.isFocusableElement = isFocusableElement || this.isFocusableElement; | ||
if (typeof direction === "string") { | ||
this._direction = () => direction; | ||
} else if (typeof direction === "function") { | ||
this._direction = direction; | ||
} | ||
this._direction = ensureMethod( | ||
direction, | ||
"string", | ||
this._direction | ||
); | ||
this.elementEnterAction = elementEnterAction || this.elementEnterAction; | ||
if (typeof focusInIndex === "number") { | ||
this._focusInIndex = () => focusInIndex; | ||
} else if (typeof focusInIndex === "function") { | ||
this._focusInIndex = focusInIndex; | ||
} | ||
if (typeof listenerScope === "object") { | ||
this._listenerScope = () => listenerScope; | ||
} else if (typeof listenerScope === "function") { | ||
this._listenerScope = listenerScope; | ||
} | ||
this._focusInIndex = ensureMethod( | ||
focusInIndex, | ||
"number", | ||
this._focusInIndex | ||
); | ||
this._listenerScope = ensureMethod( | ||
listenerScope, | ||
"object", | ||
this._listenerScope | ||
); | ||
} | ||
@@ -101,0 +109,0 @@ get currentIndex() { |
@@ -1,2 +0,2 @@ | ||
"use strict";export class FocusGroupController{constructor(e,{direction:t,elementEnterAction:s,elements:n,focusInIndex:i,isFocusableElement:r,listenerScope:o}={elements:()=>[]}){this._currentIndex=-1;this._direction=()=>"both";this.directionLength=5;this.elementEnterAction=e=>{};this._focused=!1;this._focusInIndex=e=>0;this.isFocusableElement=e=>!0;this._listenerScope=()=>this.host;this.offset=0;this.handleFocusin=e=>{if(!this.isEventWithinListenerScope(e))return;this.isRelatedTargetAnElement(e)&&this.hostContainsFocus();const t=e.composedPath();let s=-1;t.find(n=>(s=this.elements.indexOf(n),s!==-1)),this.currentIndex=s>-1?s:this.currentIndex};this.handleFocusout=e=>{this.isRelatedTargetAnElement(e)&&this.hostNoLongerContainsFocus()};this.handleKeydown=e=>{if(!this.acceptsEventCode(e.code)||e.defaultPrevented)return;let t=0;switch(e.code){case"ArrowRight":t+=1;break;case"ArrowDown":t+=this.direction==="grid"?this.directionLength:1;break;case"ArrowLeft":t-=1;break;case"ArrowUp":t-=this.direction==="grid"?this.directionLength:1;break;case"End":this.currentIndex=0,t-=1;break;case"Home":this.currentIndex=this.elements.length-1,t+=1;break}e.preventDefault(),this.direction==="grid"&&this.currentIndex+t<0?this.currentIndex=0:this.direction==="grid"&&this.currentIndex+t>this.elements.length-1?this.currentIndex=this.elements.length-1:this.setCurrentIndexCircularly(t),this.elementEnterAction(this.elements[this.currentIndex]),this.focus()};this.host=e,this.host.addController(this),this._elements=n,this.isFocusableElement=r||this.isFocusableElement,typeof t=="string"?this._direction=()=>t:typeof t=="function"&&(this._direction=t),this.elementEnterAction=s||this.elementEnterAction,typeof i=="number"?this._focusInIndex=()=>i:typeof i=="function"&&(this._focusInIndex=i),typeof o=="object"?this._listenerScope=()=>o:typeof o=="function"&&(this._listenerScope=o)}get currentIndex(){return this._currentIndex===-1&&(this._currentIndex=this.focusInIndex),this._currentIndex-this.offset}set currentIndex(e){this._currentIndex=e+this.offset}get direction(){return this._direction()}get elements(){return this.cachedElements||(this.cachedElements=this._elements()),this.cachedElements}set focused(e){e!==this.focused&&(this._focused=e)}get focused(){return this._focused}get focusInElement(){return this.elements[this.focusInIndex]}get focusInIndex(){return this._focusInIndex(this.elements)}isEventWithinListenerScope(e){return this._listenerScope()===this.host?!0:e.composedPath().includes(this._listenerScope())}update({elements:e}={elements:()=>[]}){this.unmanage(),this._elements=e,this.clearElementCache(),this.manage()}focus(e){let t=this.elements[this.currentIndex];(!t||!this.isFocusableElement(t))&&(this.setCurrentIndexCircularly(1),t=this.elements[this.currentIndex]),t&&this.isFocusableElement(t)&&t.focus(e)}clearElementCache(e=0){delete this.cachedElements,this.offset=e}setCurrentIndexCircularly(e){const{length:t}=this.elements;let s=t,n=(t+this.currentIndex+e)%t;for(;s&&this.elements[n]&&!this.isFocusableElement(this.elements[n]);)n=(t+n+e)%t,s-=1;this.currentIndex=n}hostContainsFocus(){this.host.addEventListener("focusout",this.handleFocusout),this.host.addEventListener("keydown",this.handleKeydown),this.focused=!0}hostNoLongerContainsFocus(){this.host.addEventListener("focusin",this.handleFocusin),this.host.removeEventListener("focusout",this.handleFocusout),this.host.removeEventListener("keydown",this.handleKeydown),this.currentIndex=this.focusInIndex,this.focused=!1}isRelatedTargetAnElement(e){const t=e.relatedTarget;return!this.elements.includes(t)}acceptsEventCode(e){if(e==="End"||e==="Home")return!0;switch(this.direction){case"horizontal":return e==="ArrowLeft"||e==="ArrowRight";case"vertical":return e==="ArrowUp"||e==="ArrowDown";case"both":case"grid":return e.startsWith("Arrow")}}manage(){this.addEventListeners()}unmanage(){this.removeEventListeners()}addEventListeners(){this.host.addEventListener("focusin",this.handleFocusin)}removeEventListeners(){this.host.removeEventListener("focusin",this.handleFocusin),this.host.removeEventListener("focusout",this.handleFocusout),this.host.removeEventListener("keydown",this.handleKeydown)}hostConnected(){this.addEventListeners()}hostDisconnected(){this.removeEventListeners()}} | ||
"use strict";function r(i,e,t){return typeof i===e?()=>i:typeof i=="function"?i:t}export class FocusGroupController{constructor(e,{direction:t,elementEnterAction:n,elements:s,focusInIndex:o,isFocusableElement:h,listenerScope:c}={elements:()=>[]}){this._currentIndex=-1;this._direction=()=>"both";this.directionLength=5;this.elementEnterAction=e=>{};this._focused=!1;this._focusInIndex=e=>0;this.isFocusableElement=e=>!0;this._listenerScope=()=>this.host;this.offset=0;this.handleFocusin=e=>{if(!this.isEventWithinListenerScope(e))return;this.isRelatedTargetAnElement(e)&&this.hostContainsFocus();const t=e.composedPath();let n=-1;t.find(s=>(n=this.elements.indexOf(s),n!==-1)),this.currentIndex=n>-1?n:this.currentIndex};this.handleFocusout=e=>{this.isRelatedTargetAnElement(e)&&this.hostNoLongerContainsFocus()};this.handleKeydown=e=>{if(!this.acceptsEventCode(e.code)||e.defaultPrevented)return;let t=0;switch(e.code){case"ArrowRight":t+=1;break;case"ArrowDown":t+=this.direction==="grid"?this.directionLength:1;break;case"ArrowLeft":t-=1;break;case"ArrowUp":t-=this.direction==="grid"?this.directionLength:1;break;case"End":this.currentIndex=0,t-=1;break;case"Home":this.currentIndex=this.elements.length-1,t+=1;break}e.preventDefault(),this.direction==="grid"&&this.currentIndex+t<0?this.currentIndex=0:this.direction==="grid"&&this.currentIndex+t>this.elements.length-1?this.currentIndex=this.elements.length-1:this.setCurrentIndexCircularly(t),this.elementEnterAction(this.elements[this.currentIndex]),this.focus()};this.host=e,this.host.addController(this),this._elements=s,this.isFocusableElement=h||this.isFocusableElement,this._direction=r(t,"string",this._direction),this.elementEnterAction=n||this.elementEnterAction,this._focusInIndex=r(o,"number",this._focusInIndex),this._listenerScope=r(c,"object",this._listenerScope)}get currentIndex(){return this._currentIndex===-1&&(this._currentIndex=this.focusInIndex),this._currentIndex-this.offset}set currentIndex(e){this._currentIndex=e+this.offset}get direction(){return this._direction()}get elements(){return this.cachedElements||(this.cachedElements=this._elements()),this.cachedElements}set focused(e){e!==this.focused&&(this._focused=e)}get focused(){return this._focused}get focusInElement(){return this.elements[this.focusInIndex]}get focusInIndex(){return this._focusInIndex(this.elements)}isEventWithinListenerScope(e){return this._listenerScope()===this.host?!0:e.composedPath().includes(this._listenerScope())}update({elements:e}={elements:()=>[]}){this.unmanage(),this._elements=e,this.clearElementCache(),this.manage()}focus(e){let t=this.elements[this.currentIndex];(!t||!this.isFocusableElement(t))&&(this.setCurrentIndexCircularly(1),t=this.elements[this.currentIndex]),t&&this.isFocusableElement(t)&&t.focus(e)}clearElementCache(e=0){delete this.cachedElements,this.offset=e}setCurrentIndexCircularly(e){const{length:t}=this.elements;let n=t,s=(t+this.currentIndex+e)%t;for(;n&&this.elements[s]&&!this.isFocusableElement(this.elements[s]);)s=(t+s+e)%t,n-=1;this.currentIndex=s}hostContainsFocus(){this.host.addEventListener("focusout",this.handleFocusout),this.host.addEventListener("keydown",this.handleKeydown),this.focused=!0}hostNoLongerContainsFocus(){this.host.addEventListener("focusin",this.handleFocusin),this.host.removeEventListener("focusout",this.handleFocusout),this.host.removeEventListener("keydown",this.handleKeydown),this.currentIndex=this.focusInIndex,this.focused=!1}isRelatedTargetAnElement(e){const t=e.relatedTarget;return!this.elements.includes(t)}acceptsEventCode(e){if(e==="End"||e==="Home")return!0;switch(this.direction){case"horizontal":return e==="ArrowLeft"||e==="ArrowRight";case"vertical":return e==="ArrowUp"||e==="ArrowDown";case"both":case"grid":return e.startsWith("Arrow")}}manage(){this.addEventListeners()}unmanage(){this.removeEventListeners()}addEventListeners(){this.host.addEventListener("focusin",this.handleFocusin)}removeEventListeners(){this.host.removeEventListener("focusin",this.handleFocusin),this.host.removeEventListener("focusout",this.handleFocusout),this.host.removeEventListener("keydown",this.handleKeydown)}hostConnected(){this.addEventListeners()}hostDisconnected(){this.removeEventListeners()}} | ||
//# sourceMappingURL=FocusGroup.js.map |
import type { ReactiveController, ReactiveElement } from 'lit'; | ||
export declare const languageResolverUpdatedSymbol: unique symbol; | ||
export declare class LanguageResolutionController implements ReactiveController { | ||
@@ -3,0 +4,0 @@ private host; |
"use strict"; | ||
export const languageResolverUpdatedSymbol = Symbol( | ||
"language resolver updated" | ||
); | ||
export class LanguageResolutionController { | ||
@@ -23,5 +26,9 @@ constructor(host) { | ||
callback: (lang, unsubscribe) => { | ||
const previous = this.language; | ||
this.language = lang; | ||
this.unsubscribe = unsubscribe; | ||
this.host.requestUpdate(); | ||
this.host.requestUpdate( | ||
languageResolverUpdatedSymbol, | ||
previous | ||
); | ||
} | ||
@@ -28,0 +35,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
"use strict";export class LanguageResolutionController{constructor(e){this.language=document.documentElement.lang||navigator.language;this.host=e,this.host.addController(this)}hostConnected(){this.resolveLanguage()}hostDisconnected(){var e;(e=this.unsubscribe)==null||e.call(this)}resolveLanguage(){const e=new CustomEvent("sp-language-context",{bubbles:!0,composed:!0,detail:{callback:(t,o)=>{this.language=t,this.unsubscribe=o,this.host.requestUpdate()}},cancelable:!0});this.host.dispatchEvent(e)}} | ||
"use strict";export const languageResolverUpdatedSymbol=Symbol("language resolver updated");export class LanguageResolutionController{constructor(e){this.language=document.documentElement.lang||navigator.language;this.host=e,this.host.addController(this)}hostConnected(){this.resolveLanguage()}hostDisconnected(){var e;(e=this.unsubscribe)==null||e.call(this)}resolveLanguage(){const e=new CustomEvent("sp-language-context",{bubbles:!0,composed:!0,detail:{callback:(t,o)=>{const a=this.language;this.language=t,this.unsubscribe=o,this.host.requestUpdate(languageResolverUpdatedSymbol,a)}},cancelable:!0});this.host.dispatchEvent(e)}} | ||
//# sourceMappingURL=LanguageResolution.js.map |
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
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
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
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
150716
1
972
- Removedtslib@^2.0.0
- Removedtslib@2.8.1(transitive)