Skip to content

Commit

Permalink
4.15.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Yair Even Or authored and Yair Even Or committed Aug 5, 2022
1 parent 948c2d0 commit 621d402
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 60 deletions.
6 changes: 3 additions & 3 deletions dist/jQuery.tagify.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/react.tagify.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 34 additions & 26 deletions dist/tagify.esm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Tagify (v 4.15.2) - tags input component
* Tagify (v 4.15.3) - tags input component
* By Yair Even-Or
* https://github.com/yairEO/tagify
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down Expand Up @@ -674,7 +674,8 @@ var _dropdown = {

callbacks: {
onKeyDown(e) {
// get the "active" element, and if there was none (yet) active, use first child
if (!this.state.hasFocus) return; // get the "active" element, and if there was none (yet) active, use first child

var selectedElm = this.DOM.dropdown.querySelector(this.settings.classNames.dropdownItemActiveSelector),
selectedElmData = this.dropdown.getSuggestionDataByNode(selectedElm);

Expand Down Expand Up @@ -800,9 +801,14 @@ var _dropdown = {
}
},

/**
* Given a suggestion-item, return the data associated with it
* @param {HTMLElement} tagElm
* @returns Object
*/
getSuggestionDataByNode(tagElm) {
var idx = tagElm ? +tagElm.getAttribute('tagifySuggestionIdx') : -1;
return this.suggestedListItems.find(item => item.value == idx) || null;
var value = tagElm && tagElm.getAttribute('value');
return this.suggestedListItems.find(item => item.value == value) || null;
},

getNextOrPrevOption(selected) {
Expand Down Expand Up @@ -868,17 +874,17 @@ var _dropdown = {
event = event || {}; // if in edit-mode, do not continue but instead replace the tag's text.
// the scenario is that "addTags" was called from a dropdown suggested option selected while editing

var tagifySuggestionIdx = elm.getAttribute('tagifySuggestionIdx'),
isNoMatch = tagifySuggestionIdx == 'noMatch',
tagData = this.suggestedListItems.find(item => (item.value || item) == tagifySuggestionIdx); // The below event must be triggered, regardless of anything else which might go wrong
var value = elm.getAttribute('value'),
isNoMatch = value == 'noMatch',
tagData = this.suggestedListItems.find(item => (item.value || item) == value); // The below event must be triggered, regardless of anything else which might go wrong

this.trigger("dropdown:select", {
data: tagData,
elm,
event
});

if (!tagifySuggestionIdx || !tagData && !isNoMatch) {
if (!value || !tagData && !isNoMatch) {
closeOnSelect && setTimeout(this.dropdown.hide.bind(this));
return;
}
Expand Down Expand Up @@ -1030,14 +1036,11 @@ var _dropdown = {
if (typeof suggestion == 'string' || typeof suggestion == 'number') suggestion = {
value: suggestion
};
var value = this.dropdown.getMappedValue(suggestion);
suggestion.value = typeof value == 'string' ? escapeHTML(value) : value;
var tagHTMLString = this.settings.templates.dropdownItem.apply(this, [suggestion, this]); // make sure the sugestion index is present as attribute, to match the data when one is selected

tagHTMLString = tagHTMLString.replace(/\s*tagifySuggestionIdx=(["'])(.*?)\1/gmi, '') // remove the "tagifySuggestionIdx" attribute if for some reason it was there
.replace('>', ` tagifySuggestionIdx="${suggestion.value}">`); // add "tagifySuggestionIdx"

return tagHTMLString;
var mappedValue = this.dropdown.getMappedValue(suggestion);
mappedValue = typeof mappedValue == 'string' ? escapeHTML(mappedValue) : mappedValue;
return this.settings.templates.dropdownItem.apply(this, [_objectSpread2(_objectSpread2({}, suggestion), {}, {
mappedValue
}), this]);
}).join("");
}

Expand Down Expand Up @@ -1147,11 +1150,11 @@ var templates = {
`;
},

dropdownItem(item, tagify) {
dropdownItem(item) {
return `<div ${this.getAttributes(item)}
class='${this.settings.classNames.dropdownItem} ${item.class ? item.class : ""}'
tabindex="0"
role="option">${item.value}</div>`;
role="option">${item.mappedValue || item.value}</div>`;
},

/**
Expand Down Expand Up @@ -2232,6 +2235,18 @@ Tagify.prototype = {
return this.settings.whitelist;
},

generateClassSelectors(classNames) {
for (let name in classNames) {
let currentName = name;
Object.defineProperty(classNames, currentName + "Selector", {
get() {
return "." + this[currentName].split(" ")[0];
}

});
}
},

applySettings(input, settings) {
DEFAULTS.templates = this.templates;

Expand All @@ -2241,14 +2256,7 @@ Tagify.prototype = {
_s.readonly = _s.readonly || input.hasAttribute('readonly');
_s.placeholder = escapeHTML(input.getAttribute('placeholder') || _s.placeholder || "");
_s.required = input.hasAttribute('required');

for (let name in _s.classNames) Object.defineProperty(_s.classNames, name + "Selector", {
get() {
return "." + this[name].split(" ")[0];
}

});

this.generateClassSelectors(_s.classNames);
if (this.isIE) _s.autoComplete = false; // IE goes crazy if this isn't false

["whitelist", "blacklist"].forEach(name => {
Expand Down
60 changes: 34 additions & 26 deletions dist/tagify.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Tagify (v 4.15.2) - tags input component
* Tagify (v 4.15.3) - tags input component
* By Yair Even-Or
* https://github.com/yairEO/tagify
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down Expand Up @@ -680,7 +680,8 @@

callbacks: {
onKeyDown(e) {
// get the "active" element, and if there was none (yet) active, use first child
if (!this.state.hasFocus) return; // get the "active" element, and if there was none (yet) active, use first child

var selectedElm = this.DOM.dropdown.querySelector(this.settings.classNames.dropdownItemActiveSelector),
selectedElmData = this.dropdown.getSuggestionDataByNode(selectedElm);

Expand Down Expand Up @@ -806,9 +807,14 @@
}
},

/**
* Given a suggestion-item, return the data associated with it
* @param {HTMLElement} tagElm
* @returns Object
*/
getSuggestionDataByNode(tagElm) {
var idx = tagElm ? +tagElm.getAttribute('tagifySuggestionIdx') : -1;
return this.suggestedListItems.find(item => item.value == idx) || null;
var value = tagElm && tagElm.getAttribute('value');
return this.suggestedListItems.find(item => item.value == value) || null;
},

getNextOrPrevOption(selected) {
Expand Down Expand Up @@ -874,17 +880,17 @@
event = event || {}; // if in edit-mode, do not continue but instead replace the tag's text.
// the scenario is that "addTags" was called from a dropdown suggested option selected while editing

var tagifySuggestionIdx = elm.getAttribute('tagifySuggestionIdx'),
isNoMatch = tagifySuggestionIdx == 'noMatch',
tagData = this.suggestedListItems.find(item => (item.value || item) == tagifySuggestionIdx); // The below event must be triggered, regardless of anything else which might go wrong
var value = elm.getAttribute('value'),
isNoMatch = value == 'noMatch',
tagData = this.suggestedListItems.find(item => (item.value || item) == value); // The below event must be triggered, regardless of anything else which might go wrong

this.trigger("dropdown:select", {
data: tagData,
elm,
event
});

if (!tagifySuggestionIdx || !tagData && !isNoMatch) {
if (!value || !tagData && !isNoMatch) {
closeOnSelect && setTimeout(this.dropdown.hide.bind(this));
return;
}
Expand Down Expand Up @@ -1036,14 +1042,11 @@
if (typeof suggestion == 'string' || typeof suggestion == 'number') suggestion = {
value: suggestion
};
var value = this.dropdown.getMappedValue(suggestion);
suggestion.value = typeof value == 'string' ? escapeHTML(value) : value;
var tagHTMLString = this.settings.templates.dropdownItem.apply(this, [suggestion, this]); // make sure the sugestion index is present as attribute, to match the data when one is selected

tagHTMLString = tagHTMLString.replace(/\s*tagifySuggestionIdx=(["'])(.*?)\1/gmi, '') // remove the "tagifySuggestionIdx" attribute if for some reason it was there
.replace('>', ` tagifySuggestionIdx="${suggestion.value}">`); // add "tagifySuggestionIdx"

return tagHTMLString;
var mappedValue = this.dropdown.getMappedValue(suggestion);
mappedValue = typeof mappedValue == 'string' ? escapeHTML(mappedValue) : mappedValue;
return this.settings.templates.dropdownItem.apply(this, [_objectSpread2(_objectSpread2({}, suggestion), {}, {
mappedValue
}), this]);
}).join("");
}

Expand Down Expand Up @@ -1153,11 +1156,11 @@
`;
},

dropdownItem(item, tagify) {
dropdownItem(item) {
return `<div ${this.getAttributes(item)}
class='${this.settings.classNames.dropdownItem} ${item.class ? item.class : ""}'
tabindex="0"
role="option">${item.value}</div>`;
role="option">${item.mappedValue || item.value}</div>`;
},

/**
Expand Down Expand Up @@ -2238,6 +2241,18 @@
return this.settings.whitelist;
},

generateClassSelectors(classNames) {
for (let name in classNames) {
let currentName = name;
Object.defineProperty(classNames, currentName + "Selector", {
get() {
return "." + this[currentName].split(" ")[0];
}

});
}
},

applySettings(input, settings) {
DEFAULTS.templates = this.templates;

Expand All @@ -2247,14 +2262,7 @@
_s.readonly = _s.readonly || input.hasAttribute('readonly');
_s.placeholder = escapeHTML(input.getAttribute('placeholder') || _s.placeholder || "");
_s.required = input.hasAttribute('required');

for (let name in _s.classNames) Object.defineProperty(_s.classNames, name + "Selector", {
get() {
return "." + this[name].split(" ")[0];
}

});

this.generateClassSelectors(_s.classNames);
if (this.isIE) _s.autoComplete = false; // IE goes crazy if this isn't false

["whitelist", "blacklist"].forEach(name => {
Expand Down
4 changes: 2 additions & 2 deletions dist/tagify.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/tagify.polyfills.min.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Tagify (v 4.15.2) - tags input component
* Tagify (v 4.15.3) - tags input component
* By Yair Even-Or
* https://github.com/yairEO/tagify
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yaireo/tagify",
"version": "4.15.2",
"version": "4.15.3",
"homepage": "https://github.com/yairEO/tagify",
"description": "lightweight, efficient Tags input component in Vanilla JS / React / Angular [super customizable, tiny size & top performance]",
"keywords": [
Expand Down

0 comments on commit 621d402

Please sign in to comment.