selectic 3.0.0 → 3.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/selectic.common.js +177 -90
- package/dist/selectic.esm.js +178 -91
- package/doc/breakingChanges.md +55 -0
- package/doc/events.md +68 -17
- package/doc/main.md +7 -0
- package/doc/params.md +5 -2
- package/package.json +6 -5
- package/src/Filter.tsx +21 -8
- package/src/List.tsx +2 -1
- package/src/Store.tsx +136 -57
- package/src/index.tsx +69 -11
- package/test/Store/Store_creation.spec.js +93 -0
- package/test/Store/clearCache.spec.js +20 -0
- package/test/Store/commit.spec.js +188 -1
- package/test/helper.js +3 -0
- package/types/Store.d.ts +13 -1
- package/types/index.d.ts +13 -3
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Breaking changes
|
|
2
|
+
|
|
3
|
+
[Back to documentation index](main.md)
|
|
4
|
+
|
|
5
|
+
This document is mainly for users which had projects with oldest Selectic
|
|
6
|
+
version which want to upgrade them to latest version.
|
|
7
|
+
|
|
8
|
+
**This is not something you have to read to understand and to use Selectic.**
|
|
9
|
+
|
|
10
|
+
## 1.3.x → 3.x
|
|
11
|
+
|
|
12
|
+
### Vue2 → Vue3
|
|
13
|
+
|
|
14
|
+
Selectic 3.x uses Vue3 instead of Vue2. The library should be changed and may
|
|
15
|
+
impact the whole project.
|
|
16
|
+
|
|
17
|
+
You should read [Vue3 migration strategy](https://v3.vuejs.org/guide/migration/introduction.html)
|
|
18
|
+
to see all implications.
|
|
19
|
+
|
|
20
|
+
### Events listener
|
|
21
|
+
|
|
22
|
+
The argument given when events are emitted have been changed.
|
|
23
|
+
|
|
24
|
+
For example to listen to a `change` event with Selectic 1.3.x you could write something like:
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
<Selectic @change="(id, isExcluded, instance) => ..."></Selectic>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
With Selectic 3.x you should write:
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
<Selectic @change="(id, information) => ..."></Selectic>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
where `information` contains all options related to the event.
|
|
37
|
+
```
|
|
38
|
+
{
|
|
39
|
+
instance: selecticInstance,
|
|
40
|
+
eventType: 'change';
|
|
41
|
+
automatic: false,
|
|
42
|
+
isExcluded: false,
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
An object rather than severals arguments is much better because it is much
|
|
46
|
+
more robust to further changes.
|
|
47
|
+
|
|
48
|
+
[Read more about the events in the dedicated section](events.md).
|
|
49
|
+
|
|
50
|
+
### `<option>` slots
|
|
51
|
+
|
|
52
|
+
It is currently no more possible to use `<option>` slots in Selectic.
|
|
53
|
+
|
|
54
|
+
We can hope that a solution will be found soon, but currently only the static
|
|
55
|
+
and dynamic mode are available.
|
package/doc/events.md
CHANGED
|
@@ -4,48 +4,99 @@
|
|
|
4
4
|
|
|
5
5
|
Selectic component emits some events that can be caught by the parent.
|
|
6
6
|
|
|
7
|
+
* [input](#input)
|
|
8
|
+
* [change](#change)
|
|
9
|
+
* [item:click](#itemclick)
|
|
10
|
+
* [open](#open)
|
|
11
|
+
* [focus](#focus)
|
|
12
|
+
* [close](#close)
|
|
13
|
+
* [blur](#blur)
|
|
14
|
+
|
|
7
15
|
## input
|
|
8
16
|
|
|
9
|
-
An event _input_ is
|
|
17
|
+
An event _input_ is emitted each time user select another option.
|
|
10
18
|
|
|
11
|
-
This event is
|
|
19
|
+
This event is emitted even if the list doesn't close (like in _multiple_ mode).
|
|
12
20
|
|
|
13
21
|
Any changes on **value** will also trigger this event.
|
|
14
22
|
|
|
15
|
-
|
|
16
|
-
* The selection which is the id of the selected option or an array of id in
|
|
17
|
-
|
|
18
|
-
*
|
|
23
|
+
2 arguments are sent with the event:
|
|
24
|
+
* The selection which is the id of the selected option or an array of id in
|
|
25
|
+
_multiple_ mode.
|
|
26
|
+
* Information about the event. This is an
|
|
27
|
+
[`EventChangeOptions` object](#eventchangeoptions). It includes the `isExcluded`
|
|
28
|
+
information ([(read more about isExcluded flag)](dynamic.md#exclude-selection)).
|
|
19
29
|
|
|
20
30
|
## change
|
|
21
31
|
|
|
22
|
-
An event _change_ is
|
|
32
|
+
An event _change_ is emitted when list is closing and selection has changed.
|
|
23
33
|
|
|
24
34
|
If changes are done on **value** and selectic is closed, the event will also be emited.
|
|
25
35
|
|
|
26
|
-
|
|
27
|
-
* The selection which is the id of the selected option or an array of id in
|
|
28
|
-
|
|
29
|
-
*
|
|
36
|
+
2 arguments are sent with the event:
|
|
37
|
+
* The selection which is the id of the selected option or an array of id in
|
|
38
|
+
_multiple_ mode.
|
|
39
|
+
* Information about the event. This is an
|
|
40
|
+
[`EventChangeOptions` object](#eventchangeoptions). It includes the `isExcluded`
|
|
41
|
+
information ([(read more about isExcluded flag)](dynamic.md#exclude-selection)).
|
|
30
42
|
|
|
31
43
|
## item:click
|
|
32
44
|
|
|
33
|
-
An event _item:click_ is
|
|
45
|
+
An event _item:click_ is emitted when user click on a selected item in _multiple_ mode (which are displayed in the main input).
|
|
34
46
|
|
|
35
47
|
2 arguments are sent with the event:
|
|
36
48
|
* The id of the selected item.
|
|
37
|
-
*
|
|
49
|
+
* Information about the event. This is an [`EventOptions` object](#eventoptions).
|
|
38
50
|
|
|
39
51
|
## open
|
|
40
52
|
|
|
41
|
-
An event _open_ is
|
|
53
|
+
An event _open_ is emitted when list is opening.
|
|
42
54
|
|
|
43
55
|
1 argument is sent with the event:
|
|
44
|
-
*
|
|
56
|
+
* Information about the event. This is an [`EventOptions` object](#eventoptions).
|
|
57
|
+
|
|
58
|
+
## focus
|
|
59
|
+
|
|
60
|
+
Is an alias of the [open](#open) event.
|
|
45
61
|
|
|
46
62
|
## close
|
|
47
63
|
|
|
48
|
-
An event _close_ is
|
|
64
|
+
An event _close_ is emitted when list is closing.
|
|
49
65
|
|
|
50
66
|
1 argument is sent with the event:
|
|
51
|
-
*
|
|
67
|
+
* Information about the event. This is an [`EventOptions` object](#eventoptions).
|
|
68
|
+
|
|
69
|
+
## blur
|
|
70
|
+
|
|
71
|
+
Is an alias of the [close](#close) event.
|
|
72
|
+
|
|
73
|
+
# Types
|
|
74
|
+
|
|
75
|
+
## EventType
|
|
76
|
+
|
|
77
|
+
This is a string of an event that can be triggered by Selectic.
|
|
78
|
+
|
|
79
|
+
Its value can be `'input' | 'change' | 'open' | 'close' | 'focus' | 'blur' | 'item:click'`
|
|
80
|
+
|
|
81
|
+
## EventOptions
|
|
82
|
+
|
|
83
|
+
This is an object with the following arguments:
|
|
84
|
+
|
|
85
|
+
* **eventType** (*[`EventType`](#eventoptions)*): The type of the triggered
|
|
86
|
+
event.
|
|
87
|
+
|
|
88
|
+
* **instance** (*Selectic*): A reference to the Selectic instance which had
|
|
89
|
+
triggered the event.
|
|
90
|
+
|
|
91
|
+
* **automatic** (*boolean*): It is worth `true` When the event is
|
|
92
|
+
automatically triggered by Selectic (for example like when value is
|
|
93
|
+
automatically selected at start).
|
|
94
|
+
|
|
95
|
+
## EventChangeOptions
|
|
96
|
+
|
|
97
|
+
This is an object with the same argument as [`EventOptions`](#eventoptions)
|
|
98
|
+
and the following arguments:
|
|
99
|
+
|
|
100
|
+
* **isExcluded** (*boolean*): The current state of `selectionIsExcluded` which
|
|
101
|
+
can be `true` in _dynamic_ and _multiple_ mode if `allowRevert` is set to
|
|
102
|
+
`true` [(read more about dynamic mode)](dynamic.md).
|
package/doc/main.md
CHANGED
package/doc/params.md
CHANGED
|
@@ -10,13 +10,16 @@ This property is an object with several attributes which are listed below.
|
|
|
10
10
|
|
|
11
11
|
## hideFilter
|
|
12
12
|
|
|
13
|
-
Type: `boolean` | `'auto'`
|
|
13
|
+
Type: `boolean` | `'auto'` | `'open'`
|
|
14
14
|
|
|
15
15
|
If `hideFilter` is set to `true`, the handler to open the filter panel is hidden and it will not be possible to search for options.
|
|
16
16
|
|
|
17
17
|
If `hideFilter` is set to `'auto`, the handler to open the filter panel is hidden only if there is less than 10 options (when there is no scroll), and is displayed otherwise. _This is the default value_.
|
|
18
18
|
|
|
19
|
-
If `hideFilter` is set to `
|
|
19
|
+
If `hideFilter` is set to `false`, the handler to open the filter panel is always displayed.
|
|
20
|
+
|
|
21
|
+
If `hideFilter` is set to `'open'`, the handler to open or close the filter panel
|
|
22
|
+
will not be displayed and the filter panel is always open.
|
|
20
23
|
|
|
21
24
|
```html
|
|
22
25
|
<selectic
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "selectic",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4",
|
|
4
4
|
"description": "Smart Select for VueJS 3.x",
|
|
5
5
|
"main": "dist/selectic.common.js",
|
|
6
6
|
"module": "dist/selectic.esm.js",
|
|
@@ -36,12 +36,13 @@
|
|
|
36
36
|
"test": "npm run build && tape test/**/*.spec.js"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"vtyx": "4.0.
|
|
39
|
+
"vtyx": "4.0.3"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"
|
|
42
|
+
"@babel/types": "^7.16.7",
|
|
43
|
+
"rollup": "^2.63.0",
|
|
43
44
|
"rollup-plugin-postcss": "^3.1.8",
|
|
44
|
-
"tape": "^4.
|
|
45
|
-
"typescript": "~4.
|
|
45
|
+
"tape": "^4.14.0",
|
|
46
|
+
"typescript": "~4.5"
|
|
46
47
|
}
|
|
47
48
|
}
|
package/src/Filter.tsx
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import {Vue, Component, Prop, Watch, h} from 'vtyx';
|
|
6
|
+
import { unref } from 'vue';
|
|
6
7
|
|
|
7
8
|
import Store from './Store';
|
|
8
9
|
|
|
@@ -42,7 +43,7 @@ export default class FilterPanel extends Vue<Props> {
|
|
|
42
43
|
const state = store.state;
|
|
43
44
|
const isMultiple = state.multiple;
|
|
44
45
|
const hasItems = state.filteredOptions.length === 0;
|
|
45
|
-
const canNotSelect = !!state.searchText && !store.hasAllItems
|
|
46
|
+
const canNotSelect = !!state.searchText && !unref(store.hasAllItems);
|
|
46
47
|
|
|
47
48
|
return !isMultiple || hasItems || canNotSelect;
|
|
48
49
|
}
|
|
@@ -50,7 +51,7 @@ export default class FilterPanel extends Vue<Props> {
|
|
|
50
51
|
get disableRevert() {
|
|
51
52
|
const store = this.store;
|
|
52
53
|
|
|
53
|
-
return !store.state.multiple || !store.hasFetchedAllItems
|
|
54
|
+
return !store.state.multiple || !unref(store.hasFetchedAllItems);
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
get enableRevert() {
|
|
@@ -99,6 +100,10 @@ export default class FilterPanel extends Vue<Props> {
|
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
private togglePanel() {
|
|
103
|
+
if (this.store.state.keepFilterOpen === true) {
|
|
104
|
+
this.closed = false;
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
102
107
|
this.closed = !this.closed;
|
|
103
108
|
}
|
|
104
109
|
|
|
@@ -121,7 +126,8 @@ export default class FilterPanel extends Vue<Props> {
|
|
|
121
126
|
/* {{{ Life cycle */
|
|
122
127
|
|
|
123
128
|
public mounted() {
|
|
124
|
-
|
|
129
|
+
const state = this.store.state;
|
|
130
|
+
this.closed = !state.keepFilterOpen && !state.searchText;
|
|
125
131
|
document.addEventListener('keypress', this.onKeyPressed);
|
|
126
132
|
|
|
127
133
|
this.getFocus();
|
|
@@ -134,6 +140,10 @@ export default class FilterPanel extends Vue<Props> {
|
|
|
134
140
|
/* }}} */
|
|
135
141
|
|
|
136
142
|
public render() {
|
|
143
|
+
const store = this.store;
|
|
144
|
+
const state = store.state;
|
|
145
|
+
const labels = store.data.labels;
|
|
146
|
+
|
|
137
147
|
return (
|
|
138
148
|
<div class="filter-panel">
|
|
139
149
|
<div
|
|
@@ -147,7 +157,7 @@ export default class FilterPanel extends Vue<Props> {
|
|
|
147
157
|
type="text"
|
|
148
158
|
class="form-control filter-input"
|
|
149
159
|
placeholder={this.searchPlaceholder}
|
|
150
|
-
value={
|
|
160
|
+
value={state.searchText}
|
|
151
161
|
on={{
|
|
152
162
|
'input.stop.prevent': this.onInput,
|
|
153
163
|
}}
|
|
@@ -157,7 +167,7 @@ export default class FilterPanel extends Vue<Props> {
|
|
|
157
167
|
form-control-feedback"
|
|
158
168
|
></span>
|
|
159
169
|
</div>
|
|
160
|
-
{
|
|
170
|
+
{state.multiple && (
|
|
161
171
|
<div class="toggle-selectic">
|
|
162
172
|
<label
|
|
163
173
|
class={['control-label', {
|
|
@@ -166,13 +176,13 @@ export default class FilterPanel extends Vue<Props> {
|
|
|
166
176
|
>
|
|
167
177
|
<input
|
|
168
178
|
type="checkbox"
|
|
169
|
-
checked={
|
|
179
|
+
checked={state.status.areAllSelected}
|
|
170
180
|
disabled={this.disableSelectAll}
|
|
171
181
|
on={{
|
|
172
182
|
change: this.onSelectAll,
|
|
173
183
|
}}
|
|
174
184
|
/>
|
|
175
|
-
{
|
|
185
|
+
{labels.selectAll}
|
|
176
186
|
</label>
|
|
177
187
|
</div>
|
|
178
188
|
)}
|
|
@@ -191,11 +201,13 @@ export default class FilterPanel extends Vue<Props> {
|
|
|
191
201
|
change: this.onExclude,
|
|
192
202
|
}}
|
|
193
203
|
/>
|
|
194
|
-
{
|
|
204
|
+
{labels.excludeResult}
|
|
195
205
|
</label>
|
|
196
206
|
</div>
|
|
197
207
|
)}
|
|
198
208
|
</div>
|
|
209
|
+
|
|
210
|
+
{!state.keepFilterOpen && (
|
|
199
211
|
<div class="curtain-handler"
|
|
200
212
|
on={{
|
|
201
213
|
'click.prevent.stop': this.togglePanel,
|
|
@@ -208,6 +220,7 @@ export default class FilterPanel extends Vue<Props> {
|
|
|
208
220
|
'fa-caret-up': !this.closed,
|
|
209
221
|
}}></span>
|
|
210
222
|
</div>
|
|
223
|
+
)}
|
|
211
224
|
</div>
|
|
212
225
|
);
|
|
213
226
|
}
|
package/src/List.tsx
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import {Vue, Component, Prop, Watch, h} from 'vtyx';
|
|
7
|
+
import { unref } from 'vue';
|
|
7
8
|
|
|
8
9
|
import Store, {
|
|
9
10
|
OptionItem,
|
|
@@ -49,7 +50,7 @@ export default class List extends Vue<Props> {
|
|
|
49
50
|
|
|
50
51
|
get itemsMargin(): number {
|
|
51
52
|
/* XXX: I don't really know when we should use value or not... */
|
|
52
|
-
return this.store.marginSize
|
|
53
|
+
return unref(this.store.marginSize);
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
get shortOptions(): OptionItem[] {
|