goodteditor-ui 1.0.21 → 1.0.23
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/.eslintrc.js +7 -7
- package/.prettierrc +14 -14
- package/README.md +35 -35
- package/babel.config.js +5 -5
- package/index.js +53 -53
- package/jsconfig.json +13 -13
- package/package.json +66 -70
- package/src/App.vue +36 -36
- package/src/components/ui/Avatar.md +68 -68
- package/src/components/ui/Avatar.vue +180 -177
- package/src/components/ui/Badge.md +20 -20
- package/src/components/ui/Badge.vue +75 -75
- package/src/components/ui/Collapse.md +90 -90
- package/src/components/ui/Collapse.vue +86 -86
- package/src/components/ui/ColorPicker/Alpha.vue +114 -114
- package/src/components/ui/ColorPicker/Colors.vue +117 -117
- package/src/components/ui/ColorPicker/Hue.vue +113 -113
- package/src/components/ui/ColorPicker/Preview.vue +55 -55
- package/src/components/ui/ColorPicker/Saturation.vue +123 -123
- package/src/components/ui/ColorPicker/mixin.js +105 -105
- package/src/components/ui/ColorPicker.md +17 -17
- package/src/components/ui/ColorPicker.vue +314 -314
- package/src/components/ui/Datalist.md +41 -41
- package/src/components/ui/Datalist.vue +157 -157
- package/src/components/ui/DatePicker.md +168 -168
- package/src/components/ui/DatePicker.vue +527 -527
- package/src/components/ui/FileSelector.md +105 -105
- package/src/components/ui/FileSelector.vue +82 -82
- package/src/components/ui/Grid.md +130 -130
- package/src/components/ui/Grid.vue +92 -92
- package/src/components/ui/Image.md +59 -59
- package/src/components/ui/Image.vue +57 -57
- package/src/components/ui/InputAutocomplete.md +115 -115
- package/src/components/ui/InputAutocomplete.vue +341 -341
- package/src/components/ui/InputColorPicker.md +51 -51
- package/src/components/ui/InputColorPicker.vue +151 -151
- package/src/components/ui/InputDatePicker.md +121 -121
- package/src/components/ui/InputDatePicker.vue +326 -326
- package/src/components/ui/InputTags.md +51 -51
- package/src/components/ui/InputTags.vue +184 -184
- package/src/components/ui/InputTimePicker.md +25 -25
- package/src/components/ui/InputTimePicker.vue +253 -253
- package/src/components/ui/InputUnits.md +20 -20
- package/src/components/ui/InputUnits.vue +257 -257
- package/src/components/ui/Lazy.md +37 -37
- package/src/components/ui/Lazy.vue +92 -92
- package/src/components/ui/Pagination.md +74 -74
- package/src/components/ui/Pagination.vue +138 -138
- package/src/components/ui/Paginator.md +34 -34
- package/src/components/ui/Paginator.vue +83 -83
- package/src/components/ui/Popover.md +34 -34
- package/src/components/ui/Popover.vue +274 -274
- package/src/components/ui/Popup.md +59 -59
- package/src/components/ui/Popup.vue +150 -150
- package/src/components/ui/ResponsiveContainer.md +58 -58
- package/src/components/ui/ResponsiveContainer.vue +99 -99
- package/src/components/ui/Select.md +187 -187
- package/src/components/ui/Select.vue +421 -421
- package/src/components/ui/TimePicker.md +50 -50
- package/src/components/ui/TimePicker.vue +252 -252
- package/src/components/ui/Tooltip.md +54 -114
- package/src/components/ui/Tooltip.vue +113 -113
- package/src/components/ui/WysiwygEditor/WysiwygEditor.d.ts +119 -119
- package/src/components/ui/WysiwygEditor/constants.js +264 -264
- package/src/components/ui/WysiwygEditor/extensions/blockquote.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/bold.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/bullet-list.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/code-block.js +13 -13
- package/src/components/ui/WysiwygEditor/extensions/code.js +13 -13
- package/src/components/ui/WysiwygEditor/extensions/font-size.js +34 -34
- package/src/components/ui/WysiwygEditor/extensions/formatting.js +14 -14
- package/src/components/ui/WysiwygEditor/extensions/heading.js +13 -13
- package/src/components/ui/WysiwygEditor/extensions/horizontal-rule.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/image.js +19 -19
- package/src/components/ui/WysiwygEditor/extensions/index.d.ts +32 -32
- package/src/components/ui/WysiwygEditor/extensions/index.js +32 -32
- package/src/components/ui/WysiwygEditor/extensions/italic.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/link.js +16 -16
- package/src/components/ui/WysiwygEditor/extensions/list-item.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/ordered-list.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/paragraph.js +23 -23
- package/src/components/ui/WysiwygEditor/extensions/strike.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/table-cell.js +13 -13
- package/src/components/ui/WysiwygEditor/extensions/table-header.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/table-row.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/table.js +29 -29
- package/src/components/ui/WysiwygEditor/extensions/text-align.js +6 -6
- package/src/components/ui/WysiwygEditor/extensions/text-style.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/underline.js +15 -15
- package/src/components/ui/WysiwygEditor/index.d.ts +4 -4
- package/src/components/ui/WysiwygEditor/index.js +4 -4
- package/src/components/ui/WysiwygEditor/renders/Button.vue +28 -28
- package/src/components/ui/WysiwygEditor/renders/ColorPicker.vue +41 -41
- package/src/components/ui/WysiwygEditor/renders/InputAuto.vue +34 -34
- package/src/components/ui/WysiwygEditor/renders/InputBrowse.vue +35 -35
- package/src/components/ui/WysiwygEditor/renders/InputUnits.vue +38 -38
- package/src/components/ui/WysiwygEditor/renders/Link.vue +87 -87
- package/src/components/ui/WysiwygEditor/renders/Select.vue +47 -47
- package/src/components/ui/WysiwygEditor/renders/ToolbarPopover.vue +49 -49
- package/src/components/ui/WysiwygEditor/renders/index.d.ts +8 -8
- package/src/components/ui/WysiwygEditor/renders/index.js +8 -8
- package/src/components/ui/WysiwygEditor/renders/mixins/RenderMixin.js +39 -39
- package/src/components/ui/WysiwygEditor/renders/mixins/index.js +1 -1
- package/src/components/ui/WysiwygEditor/tools-and-commands.js +704 -704
- package/src/components/ui/WysiwygEditor/utils.js +72 -72
- package/src/components/ui/WysiwygEditor.md +18 -18
- package/src/components/ui/WysiwygEditor.vue +271 -271
- package/src/components/ui/utils/FormComponent.js +107 -107
- package/src/components/ui/utils/Helpers.js +84 -84
- package/src/components/ui/utils/WithPopover.js +81 -99
- package/src/main.js +8 -8
- package/styleguide.config.js +37 -37
- package/vue.config.js +8 -8
- package/dist/js.png +0 -0
|
@@ -1,341 +1,341 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div
|
|
3
|
-
class="ui-input-autocomplete form-elem"
|
|
4
|
-
:class="cssClass"
|
|
5
|
-
@focus="onRootFocus"
|
|
6
|
-
tabindex="0"
|
|
7
|
-
:data-popover="popoverTargetId"
|
|
8
|
-
>
|
|
9
|
-
<div style="flex: 1 0 0">
|
|
10
|
-
<!--
|
|
11
|
-
@slot Custom input slot
|
|
12
|
-
@binding {String} id input id attribute value
|
|
13
|
-
@binding {String} value input value
|
|
14
|
-
@binding {Object} inputBinds input props (use v-bind)
|
|
15
|
-
@binding {Object} inputEvents input events (use v-on)
|
|
16
|
-
-->
|
|
17
|
-
<slot name="input" v-bind="{ id: inputId, value, inputBinds, inputEvents }">
|
|
18
|
-
<input
|
|
19
|
-
:id="inputId"
|
|
20
|
-
class="ui-input-autocomplete-input w-100"
|
|
21
|
-
type="text"
|
|
22
|
-
:value="value"
|
|
23
|
-
v-bind="inputBinds"
|
|
24
|
-
v-on="inputEvents"
|
|
25
|
-
/>
|
|
26
|
-
</slot>
|
|
27
|
-
</div>
|
|
28
|
-
<!--
|
|
29
|
-
@slot Loading custom content
|
|
30
|
-
-->
|
|
31
|
-
<slot name="loading" v-if="loading">
|
|
32
|
-
<div class="icon w-auto h-auto">
|
|
33
|
-
<div class="preloader"></div>
|
|
34
|
-
</div>
|
|
35
|
-
</slot>
|
|
36
|
-
<ui-popover :show.sync="popoverShow" v-bind="popoverOptions">
|
|
37
|
-
<ui-datalist
|
|
38
|
-
class="w-100 pull-left"
|
|
39
|
-
@select-option="onDatalistSelectOption"
|
|
40
|
-
v-bind="{ size, options: suggestedOptions }"
|
|
41
|
-
:cursorIndex.sync="dataListCursorIndex"
|
|
42
|
-
ref="datalist"
|
|
43
|
-
>
|
|
44
|
-
<template #header>
|
|
45
|
-
<!--
|
|
46
|
-
@slot Dropdown header content
|
|
47
|
-
-->
|
|
48
|
-
<slot name="dropdown-header"></slot>
|
|
49
|
-
<!--
|
|
50
|
-
@slot No results content
|
|
51
|
-
-->
|
|
52
|
-
<slot name="noresults" v-if="!loading && !suggestedOptions.length"></slot>
|
|
53
|
-
</template>
|
|
54
|
-
<template
|
|
55
|
-
#option="{
|
|
56
|
-
option,
|
|
57
|
-
index,
|
|
58
|
-
cursorIndex,
|
|
59
|
-
setCursorIndex,
|
|
60
|
-
}"
|
|
61
|
-
>
|
|
62
|
-
<!--
|
|
63
|
-
@slot Dropdown option
|
|
64
|
-
@binding {String} option option label
|
|
65
|
-
@binding {Number} optionIndex option index
|
|
66
|
-
@binding {String} value current value
|
|
67
|
-
@binding {String} valueLocal current delimited value
|
|
68
|
-
@binding {Number} cursorIndex current dropdown selection index
|
|
69
|
-
@binding {Function} selectOption function that select's the option
|
|
70
|
-
@binding {Function} setCursorIndex function that sets the cursor index
|
|
71
|
-
-->
|
|
72
|
-
<slot
|
|
73
|
-
name="option"
|
|
74
|
-
v-bind="{
|
|
75
|
-
option: option,
|
|
76
|
-
optionIndex: index,
|
|
77
|
-
value,
|
|
78
|
-
valueLocal: delimitedValue,
|
|
79
|
-
cursorIndex,
|
|
80
|
-
selectOption,
|
|
81
|
-
setCursorIndex,
|
|
82
|
-
}"
|
|
83
|
-
></slot>
|
|
84
|
-
</template>
|
|
85
|
-
<template #footer>
|
|
86
|
-
<slot name="dropdown-footer"></slot>
|
|
87
|
-
</template>
|
|
88
|
-
</ui-datalist>
|
|
89
|
-
</ui-popover>
|
|
90
|
-
</div>
|
|
91
|
-
</template>
|
|
92
|
-
<style lang="less" scoped>
|
|
93
|
-
.ui-input-autocomplete {
|
|
94
|
-
display: inline-flex;
|
|
95
|
-
align-items: center;
|
|
96
|
-
&-input {
|
|
97
|
-
border: none;
|
|
98
|
-
line-height: 1.5;
|
|
99
|
-
margin: 0;
|
|
100
|
-
padding: 0;
|
|
101
|
-
color: inherit;
|
|
102
|
-
background: transparent;
|
|
103
|
-
outline: none;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
</style>
|
|
107
|
-
<script>
|
|
108
|
-
import { Key } from './utils/Helpers';
|
|
109
|
-
import FormComponent from './utils/FormComponent';
|
|
110
|
-
import WithPopover from './utils/WithPopover';
|
|
111
|
-
import UiDatalist from './Datalist.vue';
|
|
112
|
-
import UiPopover from './Popover.vue';
|
|
113
|
-
|
|
114
|
-
export default {
|
|
115
|
-
mixins: [FormComponent, WithPopover],
|
|
116
|
-
components: { UiDatalist, UiPopover },
|
|
117
|
-
props: {
|
|
118
|
-
/**
|
|
119
|
-
* Dropdown option (suggestions)
|
|
120
|
-
*/
|
|
121
|
-
options: {
|
|
122
|
-
type: Array,
|
|
123
|
-
default() {
|
|
124
|
-
return [];
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
/**
|
|
128
|
-
* Function which filters suggestions function(val, options):Promise<Array>
|
|
129
|
-
*/
|
|
130
|
-
filter: {
|
|
131
|
-
type: Function,
|
|
132
|
-
default: null,
|
|
133
|
-
},
|
|
134
|
-
/**
|
|
135
|
-
* Filter debounce delay in ms
|
|
136
|
-
*/
|
|
137
|
-
filterDebounce: {
|
|
138
|
-
type: Number,
|
|
139
|
-
default: 0,
|
|
140
|
-
},
|
|
141
|
-
/**
|
|
142
|
-
* Value delimiter for multiple autocomplete suggestions
|
|
143
|
-
*/
|
|
144
|
-
delimiter: {
|
|
145
|
-
type: String,
|
|
146
|
-
default: ',',
|
|
147
|
-
},
|
|
148
|
-
/**
|
|
149
|
-
* Show suggestions on focus event
|
|
150
|
-
*/
|
|
151
|
-
suggestOnFocus: {
|
|
152
|
-
type: Boolean,
|
|
153
|
-
default: true,
|
|
154
|
-
},
|
|
155
|
-
/**
|
|
156
|
-
* Min length to show suggestions
|
|
157
|
-
*/
|
|
158
|
-
minLength: {
|
|
159
|
-
type: Number,
|
|
160
|
-
default: 0,
|
|
161
|
-
},
|
|
162
|
-
autoWidth: {
|
|
163
|
-
default: true,
|
|
164
|
-
},
|
|
165
|
-
},
|
|
166
|
-
data() {
|
|
167
|
-
return {
|
|
168
|
-
loading: false,
|
|
169
|
-
suggestedOptions: [],
|
|
170
|
-
caretIndex: 0,
|
|
171
|
-
dataListCursorIndex: -1,
|
|
172
|
-
filterTID: null,
|
|
173
|
-
inputBinds: {
|
|
174
|
-
placeholder: this.placeholder,
|
|
175
|
-
readonly: this.readonly,
|
|
176
|
-
},
|
|
177
|
-
inputEvents: {
|
|
178
|
-
change: this.onInputChange,
|
|
179
|
-
input: this.onInputInput,
|
|
180
|
-
keydown: this.onInputKeyDown,
|
|
181
|
-
focus: this.onInputFocus,
|
|
182
|
-
blur: this.onInputBlur,
|
|
183
|
-
},
|
|
184
|
-
delimitedValuePrev: null,
|
|
185
|
-
};
|
|
186
|
-
},
|
|
187
|
-
computed: {
|
|
188
|
-
delimitedIndex() {
|
|
189
|
-
let sub = this.value.substring(0, this.caretIndex);
|
|
190
|
-
let m = [];
|
|
191
|
-
let i = -1;
|
|
192
|
-
while ((i = sub.indexOf(this.delimiter, i + 1)) != -1) {
|
|
193
|
-
m.push(i);
|
|
194
|
-
}
|
|
195
|
-
return m ? m.length : 0;
|
|
196
|
-
},
|
|
197
|
-
delimitedValue() {
|
|
198
|
-
if (this.delimiter) {
|
|
199
|
-
return this.value.split(this.delimiter)[this.delimitedIndex];
|
|
200
|
-
}
|
|
201
|
-
return this.value;
|
|
202
|
-
},
|
|
203
|
-
},
|
|
204
|
-
methods: {
|
|
205
|
-
defaultFilter(val, options) {
|
|
206
|
-
return new Promise(resolve => {
|
|
207
|
-
let arr = options.filter(opt => opt.toLowerCase().indexOf(val.toLowerCase()) === 0);
|
|
208
|
-
resolve(arr);
|
|
209
|
-
});
|
|
210
|
-
},
|
|
211
|
-
callFilter(val) {
|
|
212
|
-
let prev = this.delimitedValuePrev;
|
|
213
|
-
this.delimitedValuePrev = val;
|
|
214
|
-
if (val === prev) {
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
if (!val.length && !this.filter) {
|
|
218
|
-
this.suggestedOptions = this.options;
|
|
219
|
-
this.dataListCursorIndex = -1;
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
this.loading = true;
|
|
223
|
-
let h = this.filter ? this.filter : this.defaultFilter;
|
|
224
|
-
h(val, this.options)
|
|
225
|
-
.then(arr => {
|
|
226
|
-
this.suggestedOptions = arr;
|
|
227
|
-
this.dataListCursorIndex = -1;
|
|
228
|
-
})
|
|
229
|
-
.finally(() => (this.loading = false));
|
|
230
|
-
},
|
|
231
|
-
callFilterDebounced(val) {
|
|
232
|
-
this.clearFilterTimeout();
|
|
233
|
-
this.filterTID = setTimeout(() => this.callFilter(val), this.filterDebounce);
|
|
234
|
-
},
|
|
235
|
-
clearFilterTimeout() {
|
|
236
|
-
if (this.filterTID) {
|
|
237
|
-
clearTimeout(this.filterTID);
|
|
238
|
-
this.filterTID = null;
|
|
239
|
-
}
|
|
240
|
-
},
|
|
241
|
-
selectOption(opt) {
|
|
242
|
-
let val = opt;
|
|
243
|
-
if (this.delimiter) {
|
|
244
|
-
let arr = this.value.split(this.delimiter);
|
|
245
|
-
arr[this.delimitedIndex] = opt;
|
|
246
|
-
val = arr.join(this.delimiter);
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Value change event
|
|
250
|
-
* @property {String} value
|
|
251
|
-
*/
|
|
252
|
-
this.$emit('input', val);
|
|
253
|
-
/**
|
|
254
|
-
* Value change event
|
|
255
|
-
* @property {String} value
|
|
256
|
-
*/
|
|
257
|
-
this.$emit('change', val);
|
|
258
|
-
this.popoverShow = false;
|
|
259
|
-
},
|
|
260
|
-
getDatalistRef() {
|
|
261
|
-
return this.$refs.datalist;
|
|
262
|
-
},
|
|
263
|
-
onRootFocus(e) {
|
|
264
|
-
let input = this.getInputRef();
|
|
265
|
-
input && input.focus();
|
|
266
|
-
},
|
|
267
|
-
onInputBlur(e) {
|
|
268
|
-
this.rootHasFocus = false;
|
|
269
|
-
},
|
|
270
|
-
onInputFocus(e) {
|
|
271
|
-
this.rootHasFocus = true;
|
|
272
|
-
/**
|
|
273
|
-
* Input focus event
|
|
274
|
-
* @property {Node} node
|
|
275
|
-
*/
|
|
276
|
-
this.$emit('focus', e.target);
|
|
277
|
-
|
|
278
|
-
if (!this.suggestOnFocus) {
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
this.popoverShow = true;
|
|
283
|
-
this.caretIndex = e.target ? e.target.selectionStart : 0;
|
|
284
|
-
this.$nextTick(() => {
|
|
285
|
-
if (this.delimitedValue.length < this.minLength) {
|
|
286
|
-
this.popoverShow = false;
|
|
287
|
-
this.suggestedOptions = [];
|
|
288
|
-
this.delimitedValuePrev = this.delimitedValue;
|
|
289
|
-
return;
|
|
290
|
-
}
|
|
291
|
-
this.callFilterDebounced(this.delimitedValue);
|
|
292
|
-
});
|
|
293
|
-
},
|
|
294
|
-
onInputChange(e) {
|
|
295
|
-
let val = e.target.value;
|
|
296
|
-
/**
|
|
297
|
-
* Change event
|
|
298
|
-
* @property {String} value
|
|
299
|
-
*/
|
|
300
|
-
this.$emit('change', val);
|
|
301
|
-
},
|
|
302
|
-
onInputInput(e) {
|
|
303
|
-
let val = e.target.value;
|
|
304
|
-
/**
|
|
305
|
-
* input event
|
|
306
|
-
* @property {String} value
|
|
307
|
-
*/
|
|
308
|
-
this.$emit('input', val);
|
|
309
|
-
|
|
310
|
-
this.popoverShow = true;
|
|
311
|
-
this.caretIndex = e.target ? e.target.selectionStart : 0;
|
|
312
|
-
this.$nextTick(() => {
|
|
313
|
-
if (this.delimitedValue.length < this.minLength) {
|
|
314
|
-
this.popoverShow = false;
|
|
315
|
-
this.suggestedOptions = [];
|
|
316
|
-
this.delimitedValuePrev = this.delimitedValue;
|
|
317
|
-
return;
|
|
318
|
-
}
|
|
319
|
-
this.callFilterDebounced(this.delimitedValue);
|
|
320
|
-
});
|
|
321
|
-
},
|
|
322
|
-
onInputKeyDown(e) {
|
|
323
|
-
let list = this.getDatalistRef();
|
|
324
|
-
if (e.key === Key.ESC) {
|
|
325
|
-
this.popoverShow = false;
|
|
326
|
-
}
|
|
327
|
-
if (e.key === Key.ENTER) {
|
|
328
|
-
if (!this.popoverShow) {
|
|
329
|
-
this.popoverShow = true;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
if (this.popoverShow) {
|
|
333
|
-
list && list.onKeyDown(e);
|
|
334
|
-
}
|
|
335
|
-
},
|
|
336
|
-
onDatalistSelectOption({ option }) {
|
|
337
|
-
this.selectOption(option);
|
|
338
|
-
},
|
|
339
|
-
},
|
|
340
|
-
};
|
|
341
|
-
</script>
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
class="ui-input-autocomplete form-elem"
|
|
4
|
+
:class="cssClass"
|
|
5
|
+
@focus="onRootFocus"
|
|
6
|
+
tabindex="0"
|
|
7
|
+
:data-popover="popoverTargetId"
|
|
8
|
+
>
|
|
9
|
+
<div style="flex: 1 0 0">
|
|
10
|
+
<!--
|
|
11
|
+
@slot Custom input slot
|
|
12
|
+
@binding {String} id input id attribute value
|
|
13
|
+
@binding {String} value input value
|
|
14
|
+
@binding {Object} inputBinds input props (use v-bind)
|
|
15
|
+
@binding {Object} inputEvents input events (use v-on)
|
|
16
|
+
-->
|
|
17
|
+
<slot name="input" v-bind="{ id: inputId, value, inputBinds, inputEvents }">
|
|
18
|
+
<input
|
|
19
|
+
:id="inputId"
|
|
20
|
+
class="ui-input-autocomplete-input w-100"
|
|
21
|
+
type="text"
|
|
22
|
+
:value="value"
|
|
23
|
+
v-bind="inputBinds"
|
|
24
|
+
v-on="inputEvents"
|
|
25
|
+
/>
|
|
26
|
+
</slot>
|
|
27
|
+
</div>
|
|
28
|
+
<!--
|
|
29
|
+
@slot Loading custom content
|
|
30
|
+
-->
|
|
31
|
+
<slot name="loading" v-if="loading">
|
|
32
|
+
<div class="icon w-auto h-auto">
|
|
33
|
+
<div class="preloader"></div>
|
|
34
|
+
</div>
|
|
35
|
+
</slot>
|
|
36
|
+
<ui-popover :show.sync="popoverShow" v-bind="popoverOptions">
|
|
37
|
+
<ui-datalist
|
|
38
|
+
class="w-100 pull-left"
|
|
39
|
+
@select-option="onDatalistSelectOption"
|
|
40
|
+
v-bind="{ size, options: suggestedOptions }"
|
|
41
|
+
:cursorIndex.sync="dataListCursorIndex"
|
|
42
|
+
ref="datalist"
|
|
43
|
+
>
|
|
44
|
+
<template #header>
|
|
45
|
+
<!--
|
|
46
|
+
@slot Dropdown header content
|
|
47
|
+
-->
|
|
48
|
+
<slot name="dropdown-header"></slot>
|
|
49
|
+
<!--
|
|
50
|
+
@slot No results content
|
|
51
|
+
-->
|
|
52
|
+
<slot name="noresults" v-if="!loading && !suggestedOptions.length"></slot>
|
|
53
|
+
</template>
|
|
54
|
+
<template
|
|
55
|
+
#option="{
|
|
56
|
+
option,
|
|
57
|
+
index,
|
|
58
|
+
cursorIndex,
|
|
59
|
+
setCursorIndex,
|
|
60
|
+
}"
|
|
61
|
+
>
|
|
62
|
+
<!--
|
|
63
|
+
@slot Dropdown option
|
|
64
|
+
@binding {String} option option label
|
|
65
|
+
@binding {Number} optionIndex option index
|
|
66
|
+
@binding {String} value current value
|
|
67
|
+
@binding {String} valueLocal current delimited value
|
|
68
|
+
@binding {Number} cursorIndex current dropdown selection index
|
|
69
|
+
@binding {Function} selectOption function that select's the option
|
|
70
|
+
@binding {Function} setCursorIndex function that sets the cursor index
|
|
71
|
+
-->
|
|
72
|
+
<slot
|
|
73
|
+
name="option"
|
|
74
|
+
v-bind="{
|
|
75
|
+
option: option,
|
|
76
|
+
optionIndex: index,
|
|
77
|
+
value,
|
|
78
|
+
valueLocal: delimitedValue,
|
|
79
|
+
cursorIndex,
|
|
80
|
+
selectOption,
|
|
81
|
+
setCursorIndex,
|
|
82
|
+
}"
|
|
83
|
+
></slot>
|
|
84
|
+
</template>
|
|
85
|
+
<template #footer>
|
|
86
|
+
<slot name="dropdown-footer"></slot>
|
|
87
|
+
</template>
|
|
88
|
+
</ui-datalist>
|
|
89
|
+
</ui-popover>
|
|
90
|
+
</div>
|
|
91
|
+
</template>
|
|
92
|
+
<style lang="less" scoped>
|
|
93
|
+
.ui-input-autocomplete {
|
|
94
|
+
display: inline-flex;
|
|
95
|
+
align-items: center;
|
|
96
|
+
&-input {
|
|
97
|
+
border: none;
|
|
98
|
+
line-height: 1.5;
|
|
99
|
+
margin: 0;
|
|
100
|
+
padding: 0;
|
|
101
|
+
color: inherit;
|
|
102
|
+
background: transparent;
|
|
103
|
+
outline: none;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
</style>
|
|
107
|
+
<script>
|
|
108
|
+
import { Key } from './utils/Helpers';
|
|
109
|
+
import FormComponent from './utils/FormComponent';
|
|
110
|
+
import WithPopover from './utils/WithPopover';
|
|
111
|
+
import UiDatalist from './Datalist.vue';
|
|
112
|
+
import UiPopover from './Popover.vue';
|
|
113
|
+
|
|
114
|
+
export default {
|
|
115
|
+
mixins: [FormComponent, WithPopover],
|
|
116
|
+
components: { UiDatalist, UiPopover },
|
|
117
|
+
props: {
|
|
118
|
+
/**
|
|
119
|
+
* Dropdown option (suggestions)
|
|
120
|
+
*/
|
|
121
|
+
options: {
|
|
122
|
+
type: Array,
|
|
123
|
+
default() {
|
|
124
|
+
return [];
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
/**
|
|
128
|
+
* Function which filters suggestions function(val, options):Promise<Array>
|
|
129
|
+
*/
|
|
130
|
+
filter: {
|
|
131
|
+
type: Function,
|
|
132
|
+
default: null,
|
|
133
|
+
},
|
|
134
|
+
/**
|
|
135
|
+
* Filter debounce delay in ms
|
|
136
|
+
*/
|
|
137
|
+
filterDebounce: {
|
|
138
|
+
type: Number,
|
|
139
|
+
default: 0,
|
|
140
|
+
},
|
|
141
|
+
/**
|
|
142
|
+
* Value delimiter for multiple autocomplete suggestions
|
|
143
|
+
*/
|
|
144
|
+
delimiter: {
|
|
145
|
+
type: String,
|
|
146
|
+
default: ',',
|
|
147
|
+
},
|
|
148
|
+
/**
|
|
149
|
+
* Show suggestions on focus event
|
|
150
|
+
*/
|
|
151
|
+
suggestOnFocus: {
|
|
152
|
+
type: Boolean,
|
|
153
|
+
default: true,
|
|
154
|
+
},
|
|
155
|
+
/**
|
|
156
|
+
* Min length to show suggestions
|
|
157
|
+
*/
|
|
158
|
+
minLength: {
|
|
159
|
+
type: Number,
|
|
160
|
+
default: 0,
|
|
161
|
+
},
|
|
162
|
+
autoWidth: {
|
|
163
|
+
default: true,
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
data() {
|
|
167
|
+
return {
|
|
168
|
+
loading: false,
|
|
169
|
+
suggestedOptions: [],
|
|
170
|
+
caretIndex: 0,
|
|
171
|
+
dataListCursorIndex: -1,
|
|
172
|
+
filterTID: null,
|
|
173
|
+
inputBinds: {
|
|
174
|
+
placeholder: this.placeholder,
|
|
175
|
+
readonly: this.readonly,
|
|
176
|
+
},
|
|
177
|
+
inputEvents: {
|
|
178
|
+
change: this.onInputChange,
|
|
179
|
+
input: this.onInputInput,
|
|
180
|
+
keydown: this.onInputKeyDown,
|
|
181
|
+
focus: this.onInputFocus,
|
|
182
|
+
blur: this.onInputBlur,
|
|
183
|
+
},
|
|
184
|
+
delimitedValuePrev: null,
|
|
185
|
+
};
|
|
186
|
+
},
|
|
187
|
+
computed: {
|
|
188
|
+
delimitedIndex() {
|
|
189
|
+
let sub = this.value.substring(0, this.caretIndex);
|
|
190
|
+
let m = [];
|
|
191
|
+
let i = -1;
|
|
192
|
+
while ((i = sub.indexOf(this.delimiter, i + 1)) != -1) {
|
|
193
|
+
m.push(i);
|
|
194
|
+
}
|
|
195
|
+
return m ? m.length : 0;
|
|
196
|
+
},
|
|
197
|
+
delimitedValue() {
|
|
198
|
+
if (this.delimiter) {
|
|
199
|
+
return this.value.split(this.delimiter)[this.delimitedIndex];
|
|
200
|
+
}
|
|
201
|
+
return this.value;
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
methods: {
|
|
205
|
+
defaultFilter(val, options) {
|
|
206
|
+
return new Promise(resolve => {
|
|
207
|
+
let arr = options.filter(opt => opt.toLowerCase().indexOf(val.toLowerCase()) === 0);
|
|
208
|
+
resolve(arr);
|
|
209
|
+
});
|
|
210
|
+
},
|
|
211
|
+
callFilter(val) {
|
|
212
|
+
let prev = this.delimitedValuePrev;
|
|
213
|
+
this.delimitedValuePrev = val;
|
|
214
|
+
if (val === prev) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if (!val.length && !this.filter) {
|
|
218
|
+
this.suggestedOptions = this.options;
|
|
219
|
+
this.dataListCursorIndex = -1;
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
this.loading = true;
|
|
223
|
+
let h = this.filter ? this.filter : this.defaultFilter;
|
|
224
|
+
h(val, this.options)
|
|
225
|
+
.then(arr => {
|
|
226
|
+
this.suggestedOptions = arr;
|
|
227
|
+
this.dataListCursorIndex = -1;
|
|
228
|
+
})
|
|
229
|
+
.finally(() => (this.loading = false));
|
|
230
|
+
},
|
|
231
|
+
callFilterDebounced(val) {
|
|
232
|
+
this.clearFilterTimeout();
|
|
233
|
+
this.filterTID = setTimeout(() => this.callFilter(val), this.filterDebounce);
|
|
234
|
+
},
|
|
235
|
+
clearFilterTimeout() {
|
|
236
|
+
if (this.filterTID) {
|
|
237
|
+
clearTimeout(this.filterTID);
|
|
238
|
+
this.filterTID = null;
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
selectOption(opt) {
|
|
242
|
+
let val = opt;
|
|
243
|
+
if (this.delimiter) {
|
|
244
|
+
let arr = this.value.split(this.delimiter);
|
|
245
|
+
arr[this.delimitedIndex] = opt;
|
|
246
|
+
val = arr.join(this.delimiter);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Value change event
|
|
250
|
+
* @property {String} value
|
|
251
|
+
*/
|
|
252
|
+
this.$emit('input', val);
|
|
253
|
+
/**
|
|
254
|
+
* Value change event
|
|
255
|
+
* @property {String} value
|
|
256
|
+
*/
|
|
257
|
+
this.$emit('change', val);
|
|
258
|
+
this.popoverShow = false;
|
|
259
|
+
},
|
|
260
|
+
getDatalistRef() {
|
|
261
|
+
return this.$refs.datalist;
|
|
262
|
+
},
|
|
263
|
+
onRootFocus(e) {
|
|
264
|
+
let input = this.getInputRef();
|
|
265
|
+
input && input.focus();
|
|
266
|
+
},
|
|
267
|
+
onInputBlur(e) {
|
|
268
|
+
this.rootHasFocus = false;
|
|
269
|
+
},
|
|
270
|
+
onInputFocus(e) {
|
|
271
|
+
this.rootHasFocus = true;
|
|
272
|
+
/**
|
|
273
|
+
* Input focus event
|
|
274
|
+
* @property {Node} node
|
|
275
|
+
*/
|
|
276
|
+
this.$emit('focus', e.target);
|
|
277
|
+
|
|
278
|
+
if (!this.suggestOnFocus) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
this.popoverShow = true;
|
|
283
|
+
this.caretIndex = e.target ? e.target.selectionStart : 0;
|
|
284
|
+
this.$nextTick(() => {
|
|
285
|
+
if (this.delimitedValue.length < this.minLength) {
|
|
286
|
+
this.popoverShow = false;
|
|
287
|
+
this.suggestedOptions = [];
|
|
288
|
+
this.delimitedValuePrev = this.delimitedValue;
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
this.callFilterDebounced(this.delimitedValue);
|
|
292
|
+
});
|
|
293
|
+
},
|
|
294
|
+
onInputChange(e) {
|
|
295
|
+
let val = e.target.value;
|
|
296
|
+
/**
|
|
297
|
+
* Change event
|
|
298
|
+
* @property {String} value
|
|
299
|
+
*/
|
|
300
|
+
this.$emit('change', val);
|
|
301
|
+
},
|
|
302
|
+
onInputInput(e) {
|
|
303
|
+
let val = e.target.value;
|
|
304
|
+
/**
|
|
305
|
+
* input event
|
|
306
|
+
* @property {String} value
|
|
307
|
+
*/
|
|
308
|
+
this.$emit('input', val);
|
|
309
|
+
|
|
310
|
+
this.popoverShow = true;
|
|
311
|
+
this.caretIndex = e.target ? e.target.selectionStart : 0;
|
|
312
|
+
this.$nextTick(() => {
|
|
313
|
+
if (this.delimitedValue.length < this.minLength) {
|
|
314
|
+
this.popoverShow = false;
|
|
315
|
+
this.suggestedOptions = [];
|
|
316
|
+
this.delimitedValuePrev = this.delimitedValue;
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
this.callFilterDebounced(this.delimitedValue);
|
|
320
|
+
});
|
|
321
|
+
},
|
|
322
|
+
onInputKeyDown(e) {
|
|
323
|
+
let list = this.getDatalistRef();
|
|
324
|
+
if (e.key === Key.ESC) {
|
|
325
|
+
this.popoverShow = false;
|
|
326
|
+
}
|
|
327
|
+
if (e.key === Key.ENTER) {
|
|
328
|
+
if (!this.popoverShow) {
|
|
329
|
+
this.popoverShow = true;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
if (this.popoverShow) {
|
|
333
|
+
list && list.onKeyDown(e);
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
onDatalistSelectOption({ option }) {
|
|
337
|
+
this.selectOption(option);
|
|
338
|
+
},
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
</script>
|