@github/text-expander-element
Advanced tools
Comparing version 2.5.0 to 2.6.0
@@ -322,2 +322,23 @@ const ctrlBindings = !!navigator.userAgent.match(/Macintosh/); | ||
const states = new WeakMap(); | ||
function isTopLayer(el) { | ||
try { | ||
if (el.matches(':popover-open')) | ||
return true; | ||
} | ||
catch (_a) { | ||
} | ||
try { | ||
if (el.matches('dialog:modal')) | ||
return true; | ||
} | ||
catch (_b) { | ||
} | ||
try { | ||
if (el.matches(':fullscreen')) | ||
return true; | ||
} | ||
catch (_c) { | ||
} | ||
return false; | ||
} | ||
class TextExpander { | ||
@@ -366,3 +387,9 @@ constructor(expander, input) { | ||
this.combobox = new Combobox(this.input, menu); | ||
const { top, left } = textFieldSelectionPosition(this.input, match.position); | ||
this.expander.dispatchEvent(new Event('text-expander-activate')); | ||
let { top, left } = textFieldSelectionPosition(this.input, match.position); | ||
if (isTopLayer(menu)) { | ||
const rect = this.input.getBoundingClientRect(); | ||
top += rect.top; | ||
left += rect.left; | ||
} | ||
menu.style.top = `${top}px`; | ||
@@ -379,2 +406,3 @@ menu.style.left = `${left}px`; | ||
return false; | ||
this.expander.dispatchEvent(new Event('text-expander-deactivate')); | ||
this.menu = null; | ||
@@ -381,0 +409,0 @@ menu.removeEventListener('combobox-commit', this.oncommit); |
@@ -152,2 +152,23 @@ import Combobox from '@github/combobox-nav'; | ||
const states = new WeakMap(); | ||
function isTopLayer(el) { | ||
try { | ||
if (el.matches(':popover-open')) | ||
return true; | ||
} | ||
catch (_a) { | ||
} | ||
try { | ||
if (el.matches('dialog:modal')) | ||
return true; | ||
} | ||
catch (_b) { | ||
} | ||
try { | ||
if (el.matches(':fullscreen')) | ||
return true; | ||
} | ||
catch (_c) { | ||
} | ||
return false; | ||
} | ||
class TextExpander { | ||
@@ -196,3 +217,9 @@ constructor(expander, input) { | ||
this.combobox = new Combobox(this.input, menu); | ||
const { top, left } = textFieldSelectionPosition(this.input, match.position); | ||
this.expander.dispatchEvent(new Event('text-expander-activate')); | ||
let { top, left } = textFieldSelectionPosition(this.input, match.position); | ||
if (isTopLayer(menu)) { | ||
const rect = this.input.getBoundingClientRect(); | ||
top += rect.top; | ||
left += rect.left; | ||
} | ||
menu.style.top = `${top}px`; | ||
@@ -209,2 +236,3 @@ menu.style.left = `${left}px`; | ||
return false; | ||
this.expander.dispatchEvent(new Event('text-expander-deactivate')); | ||
this.menu = null; | ||
@@ -211,0 +239,0 @@ menu.removeEventListener('combobox-commit', this.oncommit); |
@@ -5,2 +5,23 @@ import Combobox from '@github/combobox-nav'; | ||
const states = new WeakMap(); | ||
function isTopLayer(el) { | ||
try { | ||
if (el.matches(':popover-open')) | ||
return true; | ||
} | ||
catch (_a) { | ||
} | ||
try { | ||
if (el.matches('dialog:modal')) | ||
return true; | ||
} | ||
catch (_b) { | ||
} | ||
try { | ||
if (el.matches(':fullscreen')) | ||
return true; | ||
} | ||
catch (_c) { | ||
} | ||
return false; | ||
} | ||
class TextExpander { | ||
@@ -49,3 +70,9 @@ constructor(expander, input) { | ||
this.combobox = new Combobox(this.input, menu); | ||
const { top, left } = textFieldSelectionPosition(this.input, match.position); | ||
this.expander.dispatchEvent(new Event('text-expander-activate')); | ||
let { top, left } = textFieldSelectionPosition(this.input, match.position); | ||
if (isTopLayer(menu)) { | ||
const rect = this.input.getBoundingClientRect(); | ||
top += rect.top; | ||
left += rect.left; | ||
} | ||
menu.style.top = `${top}px`; | ||
@@ -62,2 +89,3 @@ menu.style.left = `${left}px`; | ||
return false; | ||
this.expander.dispatchEvent(new Event('text-expander-deactivate')); | ||
this.menu = null; | ||
@@ -64,0 +92,0 @@ menu.removeEventListener('combobox-commit', this.oncommit); |
{ | ||
"name": "@github/text-expander-element", | ||
"version": "2.5.0", | ||
"version": "2.6.0", | ||
"description": "Activates a suggestion menu to expand text snippets as you type.", | ||
@@ -5,0 +5,0 @@ "repository": "github/text-expander-element", |
@@ -108,2 +108,6 @@ # <text-expander> element | ||
**`text-expander-activate`** is fired just after the menu has been assigned and appended to the DOM, and just before it is about to be positioned near the text to expand. This is useful for assigning classes or calling imperative methods to show the menu, such as `.showPopover()`. | ||
**`text-expander-dectivate`** is fired just before the menu is goind to be unassigned and removed from the DOM. This is useful for removing classes or running cleanup like removing from caches. | ||
## Browser support | ||
@@ -110,0 +114,0 @@ |
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
53455
1357
134