Skip to content

Commit 580a869

Browse files
authored
Merge pull request #13 from adidas/bugfix/update-choicesjs
Bugfix: update ChoicesJS
2 parents e0cdd4f + 7f93faf commit 580a869

File tree

5 files changed

+147
-48
lines changed

5 files changed

+147
-48
lines changed

CHANGELOG.md

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,32 @@
11
# 1.5.0
22

3-
- Update `choices.js` to version `9.0.1`. Changes:
4-
- `hiddenState` className is removed.
5-
- `itemOption` className is replaced by `itemChoice` className.
6-
- New `selectedState` className is added.
7-
- `fusejs.io` updates from `2.7.4` to version `3.4.6`. Changes:
8-
- New options added to `FuseOptions`:
9-
- `includeMateches`,
10-
- `includeScore`,
11-
- `findAllMatches`,
12-
- `sortFn`,
13-
- and `getFn`.
14-
- Changes on `IchoicesProps`:
15-
- `addItemFilterFn` renamed to `addItemFilter`. It also allows `string` and `RegExp` types.
16-
- `sortFn` renamed to `sorter`.
17-
- Added `uniqueItemText`.
18-
- Added `customAddItemText`.
19-
- Added `valueComparer`.
20-
- Removed `ajax` on `IChoicesMethods`.
21-
- Update `@stencil/core` to version `1.12.7`.
22-
- See: https://github.com/ionic-team/stencil/blob/master/CHANGELOG.md
23-
- Update other dev dependencies:
24-
- `@babel/plugin-syntax-dynamic-import` to version `7.8.3`.
25-
- `@stencil/sass` to version `1.3.1`.
26-
- `@types/jest` to version `25.2.1`.
27-
- `choices.js` to version `9.0.1`.
28-
- `jest` to version `25.5.2`.
29-
- `jest-dot-reporter` to version `1.0.14`.
30-
- `rimraf` to version `3.0.2`.
31-
- `tslint` to version `6.1.2`.
32-
- `typedoc` to version `0.17.6`.
33-
- `workbox-build` to version `5.1.3`.
34-
- `fsevents` to version `2.1.3`.
35-
- Rename `utils.tsx` to `utils.ts`
3+
- Updated `choices.js` to version `9.0.1`.
4+
- [Release changes](https://github.com/jshjohnson/Choices/releases).
5+
- Updated `@stencil/core` to version `1.12.7`.
6+
- [CHANGELOG](https://github.com/ionic-team/stencil/blob/master/CHANGELOG.md).
7+
- Updated demo application.
8+
- Changed web component interface:
9+
- `ClassNames`:
10+
- Added `selectedState`.
11+
- Removed `hiddenState`.
12+
- Replaced `itemOption` with `itemChoice`.
13+
- `FuseOptions` (`fusejs.io` updates from `2.7.4` to version `3.4.6`):
14+
- Added options:
15+
- `includeMatches`.
16+
- `includeScore`.
17+
- `findAllMatches`.
18+
- `sortFn`.
19+
- `getFn`.
20+
- `IchoicesProps`:
21+
- Added properties:
22+
- `uniqueItemText`.
23+
- `customAddItemText`.
24+
- `valueComparer`.
25+
- Replaced properties:
26+
- `addItemFilterFn` with `addItemFilter` (it allows `string` and `RegExp` types).
27+
- `sortFn` with `sorter`.
28+
- `IChoicesMethods`:
29+
- Removed `ajax` method.
3630

3731
# 1.4.0
3832

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ The library is based on [ChoicesJS][choicesjs], but it is not bundle along with
2929
This dependency can be added to the bundle as external library, or it can just be added to the page via GitHub script:
3030

3131
```html
32-
<script src="https://rawgit.com/jshjohnson/Choices/v7.0.0/public/assets/scripts/choices.js"></script>
32+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/public/assets/scripts/choices.js"></script>
3333
```
3434

3535
## Installation and running

index.html

Lines changed: 115 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
77
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
88
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
9-
<script src="https://rawgit.com/jshjohnson/Choices/v7.0.0/public/assets/scripts/choices.js"></script>
9+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/public/assets/scripts/choices.js"></script>
1010
<script src="dist/choicesjsstencil.js"></script>
1111
<style>
1212
html {
@@ -85,10 +85,6 @@ <h2 class="col-sm-12">ChoicesJS Web Component: test page</h2>
8585
<div class="pull-left values-container">
8686
<p class="values-container__text"></p>
8787
</div>
88-
<div class="form-group pull-right">
89-
<button class="btn btn-primary" type="submit">Apply</button>
90-
<button class="btn btn-default" type="reset">Reset</button>
91-
</div>
9288
</div>
9389
</div>
9490
<div class="row">
@@ -102,6 +98,8 @@ <h2 class="col-sm-12">ChoicesJS Web Component: test page</h2>
10298
<option value="single">Single</option>
10399
<option value="multiple">Multiple</option>
104100
</select>
101+
<button class="btn btn-primary" type="submit">Apply</button>
102+
<button class="btn btn-default" type="reset">Reset</button>
105103
<div class="pull-right">
106104
<button class="btn btn-info" type="button" data-toggle="modal" data-target="#customSearchModal">Search options</button>
107105
<button class="btn btn-success" type="button" data-toggle="modal" data-target="#customStylesModal">Custom Styles</button>
@@ -499,7 +497,7 @@ <h2 class="col-sm-12">ChoicesJS Web Component: test page</h2>
499497
</textarea>
500498
<label for="callbackOnCreateTemplates">}</label>
501499
<br/>
502-
<a href="https://github.com/jshjohnson/Choices/blob/v7.0.0/public/assets/scripts/choices.js#L713-L788" target="_blank">
500+
<a href="https://github.com/jshjohnson/Choices/blob/v9.0.1/public/assets/scripts/choices.js#L2777-L2926" target="_blank">
503501
Templates reference
504502
</a>
505503
</div>
@@ -525,7 +523,7 @@ <h2 class="col-sm-12">ChoicesJS Web Component: test page</h2>
525523
<div class="col-md-12">
526524
<p class="text-center pad-top">
527525
See full documentation in
528-
<a href="https://www.npmjs.com/package/choices.js/v/7.0.0" target="_blank">choices.js</a>
526+
<a href="https://www.npmjs.com/package/choices.js/v/9.0.1" target="_blank">choices.js</a>
529527
npm package.
530528
</p>
531529
</div>
@@ -579,7 +577,7 @@ <h4 class="modal-title">Custom Styles</h4>
579577
"openState": "is-open",
580578
"disabledState": "is-disabled",
581579
"highlightedState": "is-highlighted",
582-
"hiddenState": "is-hidden",
580+
"selectedState": "is-selected",
583581
"flippedState": "is-flipped",
584582
"loadingState": "is-loading",
585583
"noResults": "has-no-results",
@@ -626,6 +624,24 @@ <h5 class="text-center pad-bottom">
626624
<span class="glyphicon glyphicon glyphicon-question-sign"></span>
627625
</span>
628626
</div>
627+
<div class="form-group">
628+
<label for="includeMatches">
629+
Include matches
630+
<input type="checkbox" name="includeMatches">
631+
</label>
632+
<span class="description" data-toggle="tooltip" title="Whether the matches should be included in the result set. When true, each record in the result set will include the indices of the matched characters. These can consequently be used for highlighting purposes.">
633+
<span class="glyphicon glyphicon glyphicon-question-sign"></span>
634+
</span>
635+
</div>
636+
<div class="form-group">
637+
<label for="includeScore">
638+
Include score
639+
<input type="checkbox" name="includeScore" checked disabled>
640+
</label>
641+
<span class="description" data-toggle="tooltip" title="Whether the score should be included in the result set. This option is mandatory, Choices.JS uses the score property by default.">
642+
<span class="glyphicon glyphicon glyphicon-question-sign"></span>
643+
</span>
644+
</div>
629645
<div class="form-group">
630646
<label for="shouldSort">
631647
Sort
@@ -671,6 +687,80 @@ <h5 class="text-center pad-bottom">
671687
<span class="glyphicon glyphicon glyphicon-question-sign"></span>
672688
</span>
673689
</div>
690+
<div class="form-group">
691+
<label for="sortFn">
692+
sortFn(a, b) {
693+
</label>
694+
<span class="description" data-toggle="tooltip" title="The function that will sort choices and items before they are displayed (unless a user is searching). By default choices and items are sorted by score.<br/><br/>The function takes two parameters: a, b.">
695+
<span class="glyphicon glyphicon glyphicon-question-sign"></span>
696+
</span>
697+
<textarea class="form-control textarea--vertical" name="sortFn" rows="2">
698+
return a.score - b.score;
699+
</textarea>
700+
<label for="sortFn">}</label>
701+
</div>
702+
<div class="form-group">
703+
<label for="getFn">
704+
getFn(obj, path) {
705+
</label>
706+
<span class="description" data-toggle="tooltip" title="The get function to use when fetching an object properties. The default will search nested paths *ie foo.bar.baz*">
707+
<span class="glyphicon glyphicon glyphicon-question-sign"></span>
708+
</span>
709+
<textarea class="form-control textarea--vertical" name="getFn" rows="8">
710+
var list = [];
711+
712+
function baseToString(value) {
713+
// Exit early for strings to avoid a performance hit in some environments.
714+
if (typeof value == 'string') {
715+
return value;
716+
}
717+
718+
var result = (value + '');
719+
return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
720+
}
721+
722+
function toString(value) {
723+
return value == null ? '' : baseToString(value);
724+
}
725+
726+
function _get(obj, path) {
727+
if (!path) {
728+
// If there's no path left, we've gotten to the object we care about.
729+
list.push(obj);
730+
} else {
731+
var dotIndex = path.indexOf('.')
732+
var key = path;
733+
var remaining = null;
734+
735+
if (dotIndex !== -1) {
736+
key = path.slice(0, dotIndex);
737+
remaining = path.slice(dotIndex + 1);
738+
}
739+
740+
var value = obj[key];
741+
742+
if (value !== null && value !== undefined) {
743+
if (!remaining && (typeof value === 'string' || typeof value === 'number')) {
744+
list.push(toString(value));
745+
} else if (Array.isArray(value)) {
746+
// Search each item in the array.
747+
for (var i = 0, len = value.length; i < len; i += 1) {
748+
_get(value[i], remaining);
749+
}
750+
} else if (remaining) {
751+
// An object. Recurse further.
752+
_get(value, remaining);
753+
}
754+
}
755+
}
756+
}
757+
758+
_get(obj, path);
759+
760+
return list;
761+
</textarea>
762+
<label for="getFn">}</label>
763+
</div>
674764
</div>
675765
<div class="col-md-6">
676766
<div class="form-group">
@@ -713,6 +803,15 @@ <h5 class="text-center pad-bottom">
713803
</span>
714804
<input type="number" class="form-control" name="minMatchCharLength" value="1">
715805
</div>
806+
<div class="form-group">
807+
<label for="findAllMatches">
808+
Find all matches
809+
<input type="checkbox" name="findAllMatches">
810+
</label>
811+
<span class="description" data-toggle="tooltip" title="When true, the matching function will continue to the end of a search pattern even if a perfect match has already been located in the string.">
812+
<span class="glyphicon glyphicon glyphicon-question-sign"></span>
813+
</span>
814+
</div>
716815
<div class="form-group">
717816
<label for="location">
718817
Location
@@ -852,7 +951,13 @@ <h5 class="text-center pad-bottom">
852951
location: Number,
853952
threshold: Number,
854953
minMatchCharLength: Number,
855-
maxPatternLength: Number
954+
maxPatternLength: Number,
955+
sortFn: function(value) {
956+
return new Function('a', 'b', value.trim());
957+
},
958+
getFn: function(value) {
959+
return new Function('obj', 'path', value.trim());
960+
}
856961
});
857962

858963
console.info('changeSearch', fields);
@@ -874,7 +979,7 @@ <h5 class="text-center pad-bottom">
874979
var values = [];
875980
var i, lng;
876981

877-
// forEach is not available in all browsers
982+
// FormData:forEach() is not available in all browsers
878983
if (typeof form.forEach === 'function') {
879984
form.forEach(function(value, name) {
880985
values.push(name + ': `' + value + '`') ;

src/components/choicesjs-stencil/choicesjs-stencil.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ export class ChoicesJSStencil implements IChoicesProps, IChoicesMethods {
239239
break;
240240
case 'multiple':
241241
this.element =
242-
<select multiple { ...attributes }>
242+
<select { ...attributes } multiple>
243243
{ this.value ? this.createSelectOptions(this.value) : null }
244244
</select>;
245245
break;

src/components/choicesjs-stencil/interfaces.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ export type ClassNames = {
3131
};
3232

3333
/**
34-
* @link https://github.com/krisk/Fuse/tree/v2.7.4#weighted-search
34+
* @link https://github.com/krisk/Fuse/blob/v3.6.1/src/typings.d.ts#L51
3535
*/
3636
export type WeightedField = {
3737
[key: string]: any;
3838
weight: number;
3939
};
4040

4141
/**
42-
* @version 3.4.6
43-
* @link https://fusejs.io/api/options.html#basic-options
42+
* @version 3.6.1
43+
* @link https://github.com/krisk/Fuse/blob/v3.6.1/src/typings.d.ts#L43
4444
*/
4545
export type FuseOptions = {
4646
id?: string;

0 commit comments

Comments
 (0)