@textcomplete/core
Advanced tools
Comparing version 0.1.6 to 0.1.7
@@ -68,2 +68,3 @@ import { EventEmitter } from "eventemitter3"; | ||
activate(index: number): this; | ||
deactivateAll(): this; | ||
isShown(): boolean; | ||
@@ -83,2 +84,3 @@ getActiveItem(): DropdownItem | null; | ||
private readonly props; | ||
private readonly activationHandler; | ||
readonly el: HTMLLIElement; | ||
@@ -88,3 +90,3 @@ private active; | ||
private readonly activeClassName; | ||
constructor(dropdown: Dropdown, index: number, searchResult: SearchResult<unknown>, props: DropdownItemOption); | ||
constructor(dropdown: Dropdown, index: number, searchResult: SearchResult<unknown>, props: DropdownItemOption, activationHandler: any); | ||
destroy(): this; | ||
@@ -91,0 +93,0 @@ activate(): this; |
@@ -50,3 +50,6 @@ "use strict"; | ||
.slice(0, this.option.maxCount || exports.DEFAULT_DROPDOWN_MAX_COUNT) | ||
.map((r, index) => { var _a; return new DropdownItem(this, index, r, ((_a = this.option) === null || _a === void 0 ? void 0 : _a.item) || {}); }); | ||
.map((r, index) => { | ||
var _a; | ||
return new DropdownItem(this, index, r, ((_a = this.option) === null || _a === void 0 ? void 0 : _a.item) || {}, this.activate.bind(this, index)); | ||
}); | ||
this.setStrategyId(searchResults[0]) | ||
@@ -149,5 +152,3 @@ .renderEdge(searchResults, "header") | ||
if (this.activeIndex !== index) { | ||
if (this.activeIndex != null) { | ||
this.items[this.activeIndex].deactivate(); | ||
} | ||
this.deactivateAll(); | ||
this.activeIndex = index; | ||
@@ -158,2 +159,6 @@ this.items[index].activate(); | ||
} | ||
deactivateAll() { | ||
this.items.forEach((i) => i.deactivate()); | ||
return this; | ||
} | ||
isShown() { | ||
@@ -249,3 +254,3 @@ return this.shown; | ||
class DropdownItem { | ||
constructor(dropdown, index, searchResult, props) { | ||
constructor(dropdown, index, searchResult, props, activationHandler) { | ||
this.dropdown = dropdown; | ||
@@ -255,2 +260,3 @@ this.index = index; | ||
this.props = props; | ||
this.activationHandler = activationHandler; | ||
this.active = false; | ||
@@ -272,2 +278,3 @@ this.onClick = (e) => { | ||
li.addEventListener("touchstart", this.onClick); | ||
li.addEventListener("mouseenter", activationHandler); | ||
this.el = li; | ||
@@ -274,0 +281,0 @@ } |
{ | ||
"name": "@textcomplete/core", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "Textcomplete core.", | ||
@@ -40,3 +40,3 @@ "main": "dist/index.js", | ||
}, | ||
"gitHead": "03b7bee368cea9812a3c4cf8403ea24c84ed9a0f" | ||
"gitHead": "f5fec92a8e7bbab791409f5129cf2a499ba4d67e" | ||
} |
@@ -81,3 +81,10 @@ import { EventEmitter } from "eventemitter3" | ||
.map( | ||
(r, index) => new DropdownItem(this, index, r, this.option?.item || {}) | ||
(r, index) => | ||
new DropdownItem( | ||
this, | ||
index, | ||
r, | ||
this.option?.item || {}, | ||
this.activate.bind(this, index) | ||
) | ||
) | ||
@@ -187,5 +194,3 @@ this.setStrategyId(searchResults[0]) | ||
if (this.activeIndex !== index) { | ||
if (this.activeIndex != null) { | ||
this.items[this.activeIndex].deactivate() | ||
} | ||
this.deactivateAll() | ||
this.activeIndex = index | ||
@@ -197,2 +202,7 @@ this.items[index].activate() | ||
deactivateAll(): this { | ||
this.items.forEach((i) => i.deactivate()) | ||
return this | ||
} | ||
isShown(): boolean { | ||
@@ -308,3 +318,4 @@ return this.shown | ||
public readonly searchResult: SearchResult<unknown>, | ||
private readonly props: DropdownItemOption | ||
private readonly props: DropdownItemOption, | ||
private readonly activationHandler: any | ||
) { | ||
@@ -325,2 +336,3 @@ this.className = this.props.className || DEFAULT_DROPDOWN_ITEM_CLASS_NAME | ||
li.addEventListener("touchstart", this.onClick) | ||
li.addEventListener("mouseenter", activationHandler) | ||
@@ -327,0 +339,0 @@ this.el = li |
Sorry, the diff of this file is not supported yet
84762
1870