mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-15 20:25:18 +02:00
added new config option decodeHTMLSpecialChars. fix for #1031.
This commit is contained in:
parent
06d16cd857
commit
17615c2293
|
@ -397,7 +397,9 @@ function () {
|
||||||
value: option.value,
|
value: option.value,
|
||||||
label: option.innerHTML,
|
label: option.innerHTML,
|
||||||
selected: !!option.selected,
|
selected: !!option.selected,
|
||||||
disabled: option.disabled || option.parentNode.disabled,
|
disabled: option.disabled
|
||||||
|
/* || option.parentNode.disabled */
|
||||||
|
,
|
||||||
placeholder: option.value === '' || option.hasAttribute('placeholder'),
|
placeholder: option.value === '' || option.hasAttribute('placeholder'),
|
||||||
customProperties: option.dataset['custom-properties']
|
customProperties: option.dataset['custom-properties']
|
||||||
});
|
});
|
||||||
|
@ -3477,6 +3479,7 @@ exports.DEFAULT_CONFIG = {
|
||||||
removeItemButton: false,
|
removeItemButton: false,
|
||||||
editItems: false,
|
editItems: false,
|
||||||
allowHTML: true,
|
allowHTML: true,
|
||||||
|
decodeHTMLSpecialChars: true,
|
||||||
duplicateItemsAllowed: true,
|
duplicateItemsAllowed: true,
|
||||||
delimiter: ',',
|
delimiter: ',',
|
||||||
paste: true,
|
paste: true,
|
||||||
|
@ -3756,7 +3759,7 @@ Object.defineProperty(exports, "__esModule", ({
|
||||||
Object.defineProperty(exports, "__esModule", ({
|
Object.defineProperty(exports, "__esModule", ({
|
||||||
value: true
|
value: true
|
||||||
}));
|
}));
|
||||||
exports.diff = exports.cloneObject = exports.existsInArray = exports.dispatchEvent = exports.sortByScore = exports.sortByAlpha = exports.strToEl = exports.sanitise = exports.isScrolledIntoView = exports.getAdjacentEl = exports.wrap = exports.isType = exports.getType = exports.generateId = exports.generateChars = exports.getRandomNumber = void 0;
|
exports.decodeHTMLSpecialCharacters = exports.diff = exports.cloneObject = exports.existsInArray = exports.dispatchEvent = exports.sortByScore = exports.sortByAlpha = exports.strToEl = exports.sanitise = exports.isScrolledIntoView = exports.getAdjacentEl = exports.wrap = exports.isType = exports.getType = exports.generateId = exports.generateChars = exports.getRandomNumber = void 0;
|
||||||
|
|
||||||
var getRandomNumber = function (min, max) {
|
var getRandomNumber = function (min, max) {
|
||||||
return Math.floor(Math.random() * (max - min) + min);
|
return Math.floor(Math.random() * (max - min) + min);
|
||||||
|
@ -3959,6 +3962,27 @@ var diff = function (a, b) {
|
||||||
|
|
||||||
exports.diff = diff;
|
exports.diff = diff;
|
||||||
|
|
||||||
|
var decodeHTMLSpecialCharacters = function (text) {
|
||||||
|
var map = {
|
||||||
|
'&': '&',
|
||||||
|
'&': '&',
|
||||||
|
'<': '<',
|
||||||
|
'<': '<',
|
||||||
|
'>': '>',
|
||||||
|
'>': '>',
|
||||||
|
'"': '"',
|
||||||
|
'"': '"',
|
||||||
|
''': "'",
|
||||||
|
''': "'"
|
||||||
|
};
|
||||||
|
var searchValue = new RegExp(Object.keys(map).join('|'), 'g');
|
||||||
|
return text.replace(searchValue, function (m) {
|
||||||
|
return map[m];
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.decodeHTMLSpecialCharacters = decodeHTMLSpecialCharacters;
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 273:
|
/***/ 273:
|
||||||
|
@ -4575,7 +4599,7 @@ exports["default"] = Store;
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 686:
|
/***/ 686:
|
||||||
/***/ (function(__unused_webpack_module, exports) {
|
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4586,6 +4610,9 @@ exports["default"] = Store;
|
||||||
Object.defineProperty(exports, "__esModule", ({
|
Object.defineProperty(exports, "__esModule", ({
|
||||||
value: true
|
value: true
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
var utils_1 = __webpack_require__(799);
|
||||||
|
|
||||||
var templates = {
|
var templates = {
|
||||||
containerOuter: function (_a, dir, isSelectElement, isSelectOneElement, searchEnabled, passedElementType, labelId) {
|
containerOuter: function (_a, dir, isSelectElement, isSelectOneElement, searchEnabled, passedElementType, labelId) {
|
||||||
var containerOuter = _a.classNames.containerOuter;
|
var containerOuter = _a.classNames.containerOuter;
|
||||||
|
@ -4647,6 +4674,7 @@ var templates = {
|
||||||
var _c, _d;
|
var _c, _d;
|
||||||
|
|
||||||
var allowHTML = _a.allowHTML,
|
var allowHTML = _a.allowHTML,
|
||||||
|
decodeHTMLSpecialChars = _a.decodeHTMLSpecialChars,
|
||||||
_e = _a.classNames,
|
_e = _a.classNames,
|
||||||
item = _e.item,
|
item = _e.item,
|
||||||
button = _e.button,
|
button = _e.button,
|
||||||
|
@ -4663,7 +4691,7 @@ var templates = {
|
||||||
isPlaceholder = _b.placeholder;
|
isPlaceholder = _b.placeholder;
|
||||||
var div = Object.assign(document.createElement('div'), (_c = {
|
var div = Object.assign(document.createElement('div'), (_c = {
|
||||||
className: item
|
className: item
|
||||||
}, _c[allowHTML ? 'innerHTML' : 'innerText'] = label, _c));
|
}, _c[allowHTML ? 'innerHTML' : 'innerText'] = decodeHTMLSpecialChars ? (0, utils_1.decodeHTMLSpecialCharacters)(label) : label, _c));
|
||||||
Object.assign(div.dataset, {
|
Object.assign(div.dataset, {
|
||||||
item: '',
|
item: '',
|
||||||
id: id,
|
id: id,
|
||||||
|
@ -4752,6 +4780,7 @@ var templates = {
|
||||||
var _c;
|
var _c;
|
||||||
|
|
||||||
var allowHTML = _a.allowHTML,
|
var allowHTML = _a.allowHTML,
|
||||||
|
decodeHTMLSpecialChars = _a.decodeHTMLSpecialChars,
|
||||||
_d = _a.classNames,
|
_d = _a.classNames,
|
||||||
item = _d.item,
|
item = _d.item,
|
||||||
itemChoice = _d.itemChoice,
|
itemChoice = _d.itemChoice,
|
||||||
|
@ -4769,7 +4798,7 @@ var templates = {
|
||||||
isPlaceholder = _b.placeholder;
|
isPlaceholder = _b.placeholder;
|
||||||
var div = Object.assign(document.createElement('div'), (_c = {
|
var div = Object.assign(document.createElement('div'), (_c = {
|
||||||
id: elementId
|
id: elementId
|
||||||
}, _c[allowHTML ? 'innerHTML' : 'innerText'] = label, _c.className = "".concat(item, " ").concat(itemChoice), _c));
|
}, _c[allowHTML ? 'innerHTML' : 'innerText'] = decodeHTMLSpecialChars ? (0, utils_1.decodeHTMLSpecialCharacters)(label) : label, _c.className = "".concat(item, " ").concat(itemChoice), _c));
|
||||||
|
|
||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
div.classList.add(selectedState);
|
div.classList.add(selectedState);
|
||||||
|
|
2
public/assets/scripts/choices.min.js
vendored
2
public/assets/scripts/choices.min.js
vendored
File diff suppressed because one or more lines are too long
62
public/test/select-one/bug2.html
Normal file
62
public/test/select-one/bug2.html
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<!-- Ignore these -->
|
||||||
|
<link rel="stylesheet" href="../../assets/styles/base.min.css" />
|
||||||
|
<!-- End ignore these -->
|
||||||
|
|
||||||
|
<!-- Choices includes -->
|
||||||
|
<link rel="stylesheet" href="../../assets/styles/choices.min.css" />
|
||||||
|
<script src="../../assets/scripts/choices.min.js"></script>
|
||||||
|
<!-- End Choices includes -->
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<div class="section">
|
||||||
|
<label>Choices with allowHTML = false, decodeHTMLSpecialChars = false</label>
|
||||||
|
<select name="test3" id="test3">
|
||||||
|
<option value="1">Option A&1<strong>XX</strong></option>
|
||||||
|
<option value="1">Option A&1</option>
|
||||||
|
<option value="2">Option B < X</option>
|
||||||
|
<option value="2">Option B < X</option>
|
||||||
|
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<label>Choices with allowHTML = false, decodeHTMLSpecialChars = true</label>
|
||||||
|
<select name="test1" id="test1">
|
||||||
|
<option value="1">Option A&1<strong>XX</strong></option>
|
||||||
|
<option value="1">Option A&1</option>
|
||||||
|
<option value="2">Option B < X</option>
|
||||||
|
<option value="2">Option B < X</option>
|
||||||
|
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<label>Choices with allowHTML = true, decodeHTMLSpecialChars = false</label>
|
||||||
|
<select name="test2" id="test2">
|
||||||
|
<option value="1">Option A&1<strong>XX</strong></option>
|
||||||
|
<option value="1">Option A&1</option>
|
||||||
|
<option value="2">Option B < X</option>
|
||||||
|
<option value="2">Option B < X</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
const test3Select = document.getElementById('test3');
|
||||||
|
const choices3 = new Choices(test3Select, {allowHTML: false, decodeHTMLSpecialChars: false, });
|
||||||
|
|
||||||
|
const test1Select = document.getElementById('test1');
|
||||||
|
const choices1 = new Choices(test1Select, {allowHTML: false, decodeHTMLSpecialChars: true, });
|
||||||
|
|
||||||
|
const test2Select = document.getElementById('test2', {allowHTML: true, decodeHTMLSpecialChars: false});
|
||||||
|
const choices2 = new Choices(test2Select);
|
||||||
|
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../../../src/scripts/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAG/C,eAAO,MAAM,kBAAkB,EAAE,UA2BhC,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,OA+C5B,CAAC"}
|
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../../../src/scripts/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAG/C,eAAO,MAAM,kBAAkB,EAAE,UA2BhC,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,OAgD5B,CAAC"}
|
10
public/types/src/scripts/interfaces/options.d.ts
vendored
10
public/types/src/scripts/interfaces/options.d.ts
vendored
|
@ -159,6 +159,16 @@ export interface Options {
|
||||||
* @default true
|
* @default true
|
||||||
*/
|
*/
|
||||||
allowHTML: boolean;
|
allowHTML: boolean;
|
||||||
|
/**
|
||||||
|
* Whether HTML special chars (like &) should be decoded in all Choices elements labels.
|
||||||
|
* If `false`, all elements labels will be displayed unchanged - depending on your allowHTML setting they will be displayed differently.
|
||||||
|
* If `true`, all elements labels will be decoded before they are displayed.
|
||||||
|
*
|
||||||
|
* **Input types affected:** text, select-one, select-multiple
|
||||||
|
*
|
||||||
|
* @default true
|
||||||
|
*/
|
||||||
|
decodeHTMLSpecialChars: boolean;
|
||||||
/**
|
/**
|
||||||
* Whether each inputted/chosen item should be unique.
|
* Whether each inputted/chosen item should be unique.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../../../src/scripts/interfaces/options.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC;;;;;;;;GAQG;AACH,MAAM,WAAW,OAAO;IACtB;;;;;;OAMG;IACH,MAAM,EAAE,OAAO,CAAC;IAEhB;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC;IAE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IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;;;;OAMG;IACH,aAAa,EAAE,MAAM,GAAG,KAAK,CAAC,cAAc,CAAC;IAE7C;;;;;;OAMG;IACH,aAAa,EAAE,MAAM,GAAG,KAAK,CAAC,cAAc,CAAC;IAE7C;;;;;;OAMG;IACH,cAAc,EAAE,MAAM,CAAC;IAEvB;;;;;;;;;OASG;IACH,WAAW,EAAE,MAAM,GAAG,KAAK,CAAC,mBAAmB,CAAC;IAEhD;;;;OAIG;IACH,cAAc,EAAE,MAAM,GAAG,KAAK,CAAC,oBAAoB,CAAC;IAEpD;;;;;;OAMG;IACH,iBAAiB,EAAE,MAAM,GAAG,KAAK,CAAC,oBAAoB,CAAC;IAEvD;;;;;;;;;OASG;IACH,aAAa,EAAE,KAAK,CAAC,oBAAoB,CAAC;IAE1C;;;;OAIG;IACH,UAAU,EAAE,UAAU,CAAC;IAEvB;;OAEG;IACH,WAAW,EAAE,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAExC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;;;;;;OAQG;IACH,cAAc,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IAEjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,yBAAyB,EAAE,CAAC,CAAC,QAAQ,EAAE,KAAK,CAAC,OAAO,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;CACvE"}
|
1
public/types/src/scripts/lib/utils.d.ts
vendored
1
public/types/src/scripts/lib/utils.d.ts
vendored
|
@ -23,5 +23,6 @@ export declare const cloneObject: (obj: object) => object;
|
||||||
* Returns an array of keys present on the first but missing on the second object
|
* Returns an array of keys present on the first but missing on the second object
|
||||||
*/
|
*/
|
||||||
export declare const diff: (a: Record<string, any>, b: Record<string, any>) => string[];
|
export declare const diff: (a: Record<string, any>, b: Record<string, any>) => string[];
|
||||||
|
export declare const decodeHTMLSpecialCharacters: (text: string) => string;
|
||||||
export {};
|
export {};
|
||||||
//# sourceMappingURL=utils.d.ts.map
|
//# sourceMappingURL=utils.d.ts.map
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../src/scripts/lib/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD,eAAO,MAAM,eAAe,QAAS,MAAM,OAAO,MAAM,KAAG,MACZ,CAAC;AAEhD,eAAO,MAAM,aAAa,WAAY,MAAM,KAAG,MAC6B,CAAC;AAE7E,eAAO,MAAM,UAAU,YACZ,gBAAgB,GAAG,iBAAiB,UACrC,MAAM,KACb,MASF,CAAC;AAEF,eAAO,MAAM,OAAO,QAAS,GAAG,KAAG,MACe,CAAC;AAEnD,eAAO,MAAM,MAAM,SAAU,MAAM,OAAO,GAAG,KAAG,OACY,CAAC;AAE7D,eAAO,MAAM,IAAI,YACN,WAAW,YACX,WAAW,KACnB,WAUF,CAAC;AAEF,eAAO,MAAM,aAAa,YACf,OAAO,YACN,MAAM,yBAEf,OAYF,CAAC;AAEF,eAAO,MAAM,kBAAkB,YACpB,WAAW,UACZ,WAAW,yBAElB,OAkBF,CAAC;AAEF,eAAO,MAAM,QAAQ,sCAUpB,CAAC;AAEF,eAAO,MAAM,OAAO,QAAe,MAAM,KAAK,OAc1C,CAAC;AAEL,UAAU,eAAe;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AACD,eAAO,MAAM,WAAW,qBACI,eAAe,oCACE,eAAe,KACzD,MAKC,CAAC;AAEL,eAAO,MAAM,WAAW,MACnB,KAAK,MAAM,EAAE,OAAO,CAAC,KACrB,KAAK,MAAM,EAAE,OAAO,CAAC,KACvB,MAKF,CAAC;AAEF,eAAO,MAAM,aAAa,YACf,WAA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,eAAe,oCACE,eAAe,KACzD,MAKC,CAAC;AAEL,eAAO,MAAM,WAAW,MACnB,KAAK,MAAM,EAAE,OAAO,CAAC,KACrB,KAAK,MAAM,EAAE,OAAO,CAAC,KACvB,MAKF,CAAC;AAEF,eAAO,MAAM,aAAa,YACf,WAAW,QACd,SAAS,eACH,MAAM,GAAG,IAAI,KACxB,OAQF,CAAC;AAEF,eAAO,MAAM,aAAa,UACjB,GAAG,EAAE,SACL,MAAM,mBAEZ,OAOC,CAAC;AAEL,eAAO,MAAM,WAAW,QAAS,MAAM,KAAG,MACT,CAAC;AAElC;;GAEG;AACH,eAAO,MAAM,IAAI,MACZ,OAAO,MAAM,EAAE,GAAG,CAAC,KACnB,OAAO,MAAM,EAAE,GAAG,CAAC,KACrB,MAAM,EAKR,CAAC;AAEF,eAAO,MAAM,2BAA2B,SAAU,MAAM,KAAG,MAmB1D,CAAC"}
|
6
public/types/src/scripts/templates.d.ts
vendored
6
public/types/src/scripts/templates.d.ts
vendored
|
@ -6,16 +6,16 @@ import { Choice } from './interfaces/choice';
|
||||||
import { Group } from './interfaces/group';
|
import { Group } from './interfaces/group';
|
||||||
import { Item } from './interfaces/item';
|
import { Item } from './interfaces/item';
|
||||||
import { PassedElementType } from './interfaces/passed-element-type';
|
import { PassedElementType } from './interfaces/passed-element-type';
|
||||||
declare type TemplateOptions = Record<'classNames' | 'allowHTML', any>;
|
declare type TemplateOptions = Record<'classNames' | 'allowHTML' | 'decodeHTMLSpecialChars', any>;
|
||||||
declare const templates: {
|
declare const templates: {
|
||||||
containerOuter({ classNames: { containerOuter } }: TemplateOptions, dir: HTMLElement['dir'], isSelectElement: boolean, isSelectOneElement: boolean, searchEnabled: boolean, passedElementType: PassedElementType, labelId: string): HTMLDivElement;
|
containerOuter({ classNames: { containerOuter } }: TemplateOptions, dir: HTMLElement['dir'], isSelectElement: boolean, isSelectOneElement: boolean, searchEnabled: boolean, passedElementType: PassedElementType, labelId: string): HTMLDivElement;
|
||||||
containerInner({ classNames: { containerInner }, }: TemplateOptions): HTMLDivElement;
|
containerInner({ classNames: { containerInner }, }: TemplateOptions): HTMLDivElement;
|
||||||
itemList({ classNames: { list, listSingle, listItems } }: TemplateOptions, isSelectOneElement: boolean): HTMLDivElement;
|
itemList({ classNames: { list, listSingle, listItems } }: TemplateOptions, isSelectOneElement: boolean): HTMLDivElement;
|
||||||
placeholder({ allowHTML, classNames: { placeholder } }: TemplateOptions, value: string): HTMLDivElement;
|
placeholder({ allowHTML, classNames: { placeholder } }: TemplateOptions, value: string): HTMLDivElement;
|
||||||
item({ allowHTML, classNames: { item, button, highlightedState, itemSelectable, placeholder, }, }: TemplateOptions, { id, value, label, customProperties, active, disabled, highlighted, placeholder: isPlaceholder, }: Item, removeItemButton: boolean): HTMLDivElement;
|
item({ allowHTML, decodeHTMLSpecialChars, classNames: { item, button, highlightedState, itemSelectable, placeholder, }, }: TemplateOptions, { id, value, label, customProperties, active, disabled, highlighted, placeholder: isPlaceholder, }: Item, removeItemButton: boolean): HTMLDivElement;
|
||||||
choiceList({ classNames: { list } }: TemplateOptions, isSelectOneElement: boolean): HTMLDivElement;
|
choiceList({ classNames: { list } }: TemplateOptions, isSelectOneElement: boolean): HTMLDivElement;
|
||||||
choiceGroup({ allowHTML, classNames: { group, groupHeading, itemDisabled }, }: TemplateOptions, { id, value, disabled }: Group): HTMLDivElement;
|
choiceGroup({ allowHTML, classNames: { group, groupHeading, itemDisabled }, }: TemplateOptions, { id, value, disabled }: Group): HTMLDivElement;
|
||||||
choice({ allowHTML, classNames: { item, itemChoice, itemSelectable, selectedState, itemDisabled, placeholder, }, }: TemplateOptions, { id, value, label, groupId, elementId, disabled: isDisabled, selected: isSelected, placeholder: isPlaceholder, }: Choice, selectText: string): HTMLDivElement;
|
choice({ allowHTML, decodeHTMLSpecialChars, classNames: { item, itemChoice, itemSelectable, selectedState, itemDisabled, placeholder, }, }: TemplateOptions, { id, value, label, groupId, elementId, disabled: isDisabled, selected: isSelected, placeholder: isPlaceholder, }: Choice, selectText: string): HTMLDivElement;
|
||||||
input({ classNames: { input, inputCloned } }: TemplateOptions, placeholderValue: string): HTMLInputElement;
|
input({ classNames: { input, inputCloned } }: TemplateOptions, placeholderValue: string): HTMLInputElement;
|
||||||
dropdown({ classNames: { list, listDropdown }, }: TemplateOptions): HTMLDivElement;
|
dropdown({ classNames: { list, listDropdown }, }: TemplateOptions): HTMLDivElement;
|
||||||
notice({ allowHTML, classNames: { item, itemChoice, noResults, noChoices }, }: TemplateOptions, innerText: string, type?: 'no-choices' | 'no-results' | ''): HTMLDivElement;
|
notice({ allowHTML, classNames: { item, itemChoice, noResults, noChoices }, }: TemplateOptions, innerText: string, type?: 'no-choices' | 'no-results' | ''): HTMLDivElement;
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../../../src/scripts/templates.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAGrE,aAAK,eAAe,GAAG,MAAM,CAAC,YAAY,GAAG,WAAW,EAAE,GAAG,CAAC,CAAC;AAE/D,QAAA,MAAM,SAAS;uDAEyB,eAAe,OAC9C,WAAW,CAAC,KAAK,CAAC,mBACN,OAAO,sBACJ,OAAO,iBACZ,OAAO,qBACH,iBAAiB,WAC3B,MAAM,GACd,cAAc;wDAiCd,eAAe,GAAG,cAAc;8DAOgB,eAAe,sBAC5C,OAAO,GAC1B,cAAc;4DAO6B,eAAe,SACpD,MAAM,GACZ,cAAc;uGAiBZ,eAAe,sGAUf,IAAI,oBACW,OAAO,GACxB,cAAc;yCAmDW,eAAe,sBACrB,OAAO,GAC1B,cAAc;mFAiBZ,eAAe,2BACO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,GAAG,EAAE,GACrC,cAAc;kEAqBd,IAAI,GAAG,iBAAiB;CAW5B,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@ -43,6 +43,7 @@ export const DEFAULT_CONFIG: Options = {
|
||||||
removeItemButton: false,
|
removeItemButton: false,
|
||||||
editItems: false,
|
editItems: false,
|
||||||
allowHTML: true,
|
allowHTML: true,
|
||||||
|
decodeHTMLSpecialChars: true,
|
||||||
duplicateItemsAllowed: true,
|
duplicateItemsAllowed: true,
|
||||||
delimiter: ',',
|
delimiter: ',',
|
||||||
paste: true,
|
paste: true,
|
||||||
|
|
|
@ -172,6 +172,17 @@ export interface Options {
|
||||||
*/
|
*/
|
||||||
allowHTML: boolean;
|
allowHTML: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether HTML special chars (like &) should be decoded in all Choices elements labels.
|
||||||
|
* If `false`, all elements labels will be displayed unchanged - depending on your allowHTML setting they will be displayed differently.
|
||||||
|
* If `true`, all elements labels will be decoded before they are displayed.
|
||||||
|
*
|
||||||
|
* **Input types affected:** text, select-one, select-multiple
|
||||||
|
*
|
||||||
|
* @default true
|
||||||
|
*/
|
||||||
|
decodeHTMLSpecialChars: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether each inputted/chosen item should be unique.
|
* Whether each inputted/chosen item should be unique.
|
||||||
*
|
*
|
||||||
|
|
|
@ -180,3 +180,24 @@ export const diff = (
|
||||||
|
|
||||||
return aKeys.filter((i) => bKeys.indexOf(i) < 0);
|
return aKeys.filter((i) => bKeys.indexOf(i) < 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const decodeHTMLSpecialCharacters = (text: string): string => {
|
||||||
|
const map = {
|
||||||
|
'&': '&',
|
||||||
|
'&': '&',
|
||||||
|
'<': '<',
|
||||||
|
'<': '<',
|
||||||
|
'>': '>',
|
||||||
|
'>': '>',
|
||||||
|
'"': '"',
|
||||||
|
'"': '"',
|
||||||
|
''': "'",
|
||||||
|
''': "'",
|
||||||
|
};
|
||||||
|
|
||||||
|
const searchValue = new RegExp(Object.keys(map).join('|'), 'g');
|
||||||
|
|
||||||
|
return text.replace(searchValue, (m: string): string => {
|
||||||
|
return map[m];
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
|
@ -7,9 +7,13 @@ import { Choice } from './interfaces/choice';
|
||||||
import { Group } from './interfaces/group';
|
import { Group } from './interfaces/group';
|
||||||
import { Item } from './interfaces/item';
|
import { Item } from './interfaces/item';
|
||||||
import { PassedElementType } from './interfaces/passed-element-type';
|
import { PassedElementType } from './interfaces/passed-element-type';
|
||||||
|
import { decodeHTMLSpecialCharacters } from './lib/utils';
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
type TemplateOptions = Record<'classNames' | 'allowHTML', any>;
|
type TemplateOptions = Record<
|
||||||
|
'classNames' | 'allowHTML' | 'decodeHTMLSpecialChars',
|
||||||
|
any
|
||||||
|
>;
|
||||||
|
|
||||||
const templates = {
|
const templates = {
|
||||||
containerOuter(
|
containerOuter(
|
||||||
|
@ -81,6 +85,7 @@ const templates = {
|
||||||
item(
|
item(
|
||||||
{
|
{
|
||||||
allowHTML,
|
allowHTML,
|
||||||
|
decodeHTMLSpecialChars,
|
||||||
classNames: {
|
classNames: {
|
||||||
item,
|
item,
|
||||||
button,
|
button,
|
||||||
|
@ -103,7 +108,9 @@ const templates = {
|
||||||
): HTMLDivElement {
|
): HTMLDivElement {
|
||||||
const div = Object.assign(document.createElement('div'), {
|
const div = Object.assign(document.createElement('div'), {
|
||||||
className: item,
|
className: item,
|
||||||
[allowHTML ? 'innerHTML' : 'innerText']: label,
|
[allowHTML ? 'innerHTML' : 'innerText']: decodeHTMLSpecialChars
|
||||||
|
? decodeHTMLSpecialCharacters(label)
|
||||||
|
: label,
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.assign(div.dataset, {
|
Object.assign(div.dataset, {
|
||||||
|
@ -202,6 +209,7 @@ const templates = {
|
||||||
choice(
|
choice(
|
||||||
{
|
{
|
||||||
allowHTML,
|
allowHTML,
|
||||||
|
decodeHTMLSpecialChars,
|
||||||
classNames: {
|
classNames: {
|
||||||
item,
|
item,
|
||||||
itemChoice,
|
itemChoice,
|
||||||
|
@ -225,7 +233,9 @@ const templates = {
|
||||||
): HTMLDivElement {
|
): HTMLDivElement {
|
||||||
const div = Object.assign(document.createElement('div'), {
|
const div = Object.assign(document.createElement('div'), {
|
||||||
id: elementId,
|
id: elementId,
|
||||||
[allowHTML ? 'innerHTML' : 'innerText']: label,
|
[allowHTML ? 'innerHTML' : 'innerText']: decodeHTMLSpecialChars
|
||||||
|
? decodeHTMLSpecialCharacters(label)
|
||||||
|
: label,
|
||||||
className: `${item} ${itemChoice}`,
|
className: `${item} ${itemChoice}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue