@mekari/pixel3-autocomplete 0.0.0
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/dist/autocomplete.d.mts +291 -0
- package/dist/autocomplete.d.ts +291 -0
- package/dist/autocomplete.js +639 -0
- package/dist/autocomplete.mjs +9 -0
- package/dist/chunk-OX7ZBBEQ.mjs +126 -0
- package/dist/chunk-QZ7VFGWC.mjs +6 -0
- package/dist/chunk-XA465WRM.mjs +111 -0
- package/dist/chunk-YGOZYS5H.mjs +394 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +641 -0
- package/dist/index.mjs +9 -0
- package/dist/metafile-cjs.json +1 -0
- package/dist/metafile-esm.json +1 -0
- package/dist/modules/autocomplete.hooks.d.mts +65 -0
- package/dist/modules/autocomplete.hooks.d.ts +65 -0
- package/dist/modules/autocomplete.hooks.js +415 -0
- package/dist/modules/autocomplete.hooks.mjs +7 -0
- package/dist/modules/autocomplete.props.d.mts +136 -0
- package/dist/modules/autocomplete.props.d.ts +136 -0
- package/dist/modules/autocomplete.props.js +151 -0
- package/dist/modules/autocomplete.props.mjs +9 -0
- package/package.json +46 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,641 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/index.tsx
|
|
22
|
+
var src_exports = {};
|
|
23
|
+
__export(src_exports, {
|
|
24
|
+
MpAutocomplete: () => MpAutocomplete
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(src_exports);
|
|
27
|
+
|
|
28
|
+
// src/autocomplete.tsx
|
|
29
|
+
var import_vue2 = require("vue");
|
|
30
|
+
var import_vue3 = require("vue");
|
|
31
|
+
var import_pixel3_popover = require("@mekari/pixel3-popover");
|
|
32
|
+
var import_pixel3_input = require("@mekari/pixel3-input");
|
|
33
|
+
var import_pixel3_spinner = require("@mekari/pixel3-spinner");
|
|
34
|
+
var import_pixel3_icon = require("@mekari/pixel3-icon");
|
|
35
|
+
var import_pixel3_text = require("@mekari/pixel3-text");
|
|
36
|
+
|
|
37
|
+
// src/modules/autocomplete.props.ts
|
|
38
|
+
var autocompleteProps = {
|
|
39
|
+
id: {
|
|
40
|
+
type: String,
|
|
41
|
+
default: ""
|
|
42
|
+
},
|
|
43
|
+
data: {
|
|
44
|
+
type: [Array],
|
|
45
|
+
default: () => []
|
|
46
|
+
},
|
|
47
|
+
modelValue: {
|
|
48
|
+
type: [Number, String, Object, Array]
|
|
49
|
+
},
|
|
50
|
+
defaultValue: [Number, String, Object],
|
|
51
|
+
placeholder: {
|
|
52
|
+
type: String
|
|
53
|
+
},
|
|
54
|
+
labelProp: {
|
|
55
|
+
type: String,
|
|
56
|
+
default: "value"
|
|
57
|
+
},
|
|
58
|
+
valueProp: {
|
|
59
|
+
type: String,
|
|
60
|
+
default: "value"
|
|
61
|
+
},
|
|
62
|
+
isReadOnly: {
|
|
63
|
+
type: [Boolean],
|
|
64
|
+
default: false
|
|
65
|
+
},
|
|
66
|
+
isDisabled: {
|
|
67
|
+
type: [Boolean],
|
|
68
|
+
default: false
|
|
69
|
+
},
|
|
70
|
+
isInvalid: {
|
|
71
|
+
type: [Boolean],
|
|
72
|
+
default: false
|
|
73
|
+
},
|
|
74
|
+
isRequired: {
|
|
75
|
+
type: [Boolean],
|
|
76
|
+
default: false
|
|
77
|
+
},
|
|
78
|
+
isFullWidth: {
|
|
79
|
+
type: [Boolean],
|
|
80
|
+
default: true
|
|
81
|
+
},
|
|
82
|
+
isLoading: {
|
|
83
|
+
type: [Boolean],
|
|
84
|
+
default: false
|
|
85
|
+
},
|
|
86
|
+
isContentLoading: {
|
|
87
|
+
type: [Boolean],
|
|
88
|
+
default: false
|
|
89
|
+
},
|
|
90
|
+
isClearable: {
|
|
91
|
+
type: [Boolean],
|
|
92
|
+
default: false
|
|
93
|
+
},
|
|
94
|
+
isSearchable: {
|
|
95
|
+
type: [Boolean],
|
|
96
|
+
default: false
|
|
97
|
+
},
|
|
98
|
+
contentAttrs: {
|
|
99
|
+
type: Object
|
|
100
|
+
},
|
|
101
|
+
emptyText: {
|
|
102
|
+
type: [String],
|
|
103
|
+
default: "No result found"
|
|
104
|
+
},
|
|
105
|
+
contentLoadingText: {
|
|
106
|
+
type: [String],
|
|
107
|
+
default: "Loading"
|
|
108
|
+
},
|
|
109
|
+
isInfinityScroll: {
|
|
110
|
+
type: [Boolean],
|
|
111
|
+
default: false
|
|
112
|
+
},
|
|
113
|
+
isManualFilter: {
|
|
114
|
+
type: [Boolean],
|
|
115
|
+
default: false
|
|
116
|
+
},
|
|
117
|
+
usePortal: {
|
|
118
|
+
type: Boolean,
|
|
119
|
+
default: false
|
|
120
|
+
},
|
|
121
|
+
isShowButtonAction: {
|
|
122
|
+
type: Boolean,
|
|
123
|
+
default: false
|
|
124
|
+
},
|
|
125
|
+
buttonActionText: {
|
|
126
|
+
type: String,
|
|
127
|
+
default: "Button"
|
|
128
|
+
},
|
|
129
|
+
isGroupSuggestions: {
|
|
130
|
+
type: Boolean,
|
|
131
|
+
default: false
|
|
132
|
+
},
|
|
133
|
+
groupKey: {
|
|
134
|
+
type: String,
|
|
135
|
+
default: "group"
|
|
136
|
+
},
|
|
137
|
+
keyCode: {
|
|
138
|
+
type: Array,
|
|
139
|
+
default: () => ["Enter"]
|
|
140
|
+
},
|
|
141
|
+
isRawValue: {
|
|
142
|
+
type: [Boolean],
|
|
143
|
+
default: false
|
|
144
|
+
},
|
|
145
|
+
isListItemActiveFunction: {
|
|
146
|
+
type: Function
|
|
147
|
+
},
|
|
148
|
+
isKeepAlive: {
|
|
149
|
+
type: Boolean,
|
|
150
|
+
default: true
|
|
151
|
+
},
|
|
152
|
+
isAdaptiveWidth: {
|
|
153
|
+
type: Boolean,
|
|
154
|
+
default: true
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// src/modules/autocomplete.hooks.ts
|
|
159
|
+
var import_vue = require("vue");
|
|
160
|
+
var import_pixel3_utils = require("@mekari/pixel3-utils");
|
|
161
|
+
var import_css = require("@mekari/pixel3-styled-system/css");
|
|
162
|
+
function useAutocomplete(props, emit) {
|
|
163
|
+
const {
|
|
164
|
+
data,
|
|
165
|
+
usePortal,
|
|
166
|
+
isKeepAlive,
|
|
167
|
+
isClearable,
|
|
168
|
+
isSearchable,
|
|
169
|
+
isReadOnly,
|
|
170
|
+
isFullWidth,
|
|
171
|
+
labelProp,
|
|
172
|
+
valueProp,
|
|
173
|
+
isInfinityScroll,
|
|
174
|
+
placeholder,
|
|
175
|
+
isAdaptiveWidth
|
|
176
|
+
} = (0, import_vue.toRefs)(props);
|
|
177
|
+
const scrollEndNode = (0, import_vue.ref)();
|
|
178
|
+
const currentValue = (0, import_vue.ref)();
|
|
179
|
+
const currentLabel = (0, import_vue.ref)("");
|
|
180
|
+
const currentCursor = (0, import_vue.ref)("");
|
|
181
|
+
const currentSearch = (0, import_vue.ref)("");
|
|
182
|
+
const isOutside = (0, import_vue.ref)(true);
|
|
183
|
+
const isPopoverOpen = (0, import_vue.ref)(false);
|
|
184
|
+
const {
|
|
185
|
+
resume: enableIntersectionObserver,
|
|
186
|
+
pause: disableIntersectionObserver
|
|
187
|
+
} = (0, import_pixel3_utils.useIntersectionObserver)(scrollEndNode, ([{
|
|
188
|
+
isIntersecting
|
|
189
|
+
}]) => {
|
|
190
|
+
if (isIntersecting) {
|
|
191
|
+
emit("scrollEnd");
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
const getId = props.id || (0, import_pixel3_utils.getUniqueId)("", "autocomplete").value;
|
|
195
|
+
const getSuggestionDatas = (0, import_vue.computed)(() => {
|
|
196
|
+
const datas = data.value || [];
|
|
197
|
+
if (props.isManualFilter)
|
|
198
|
+
return datas;
|
|
199
|
+
if (!currentSearch.value)
|
|
200
|
+
return datas;
|
|
201
|
+
if (currentSearch.value === currentLabel.value)
|
|
202
|
+
return datas;
|
|
203
|
+
return datas.filter((item) => {
|
|
204
|
+
const label = getLabel(item).toLocaleLowerCase();
|
|
205
|
+
const search = currentSearch.value.toLocaleLowerCase();
|
|
206
|
+
return label.includes(search);
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
const getGroupSuggestions = (0, import_vue.computed)(() => {
|
|
210
|
+
const mapped = getSuggestionDatas.value.map((item, index) => {
|
|
211
|
+
const groupKey = item[props.groupKey];
|
|
212
|
+
const isUncategorized = /* @__PURE__ */ __name((value) => {
|
|
213
|
+
if ((0, import_pixel3_utils.isUndef)(value) || value === "")
|
|
214
|
+
return true;
|
|
215
|
+
return false;
|
|
216
|
+
}, "isUncategorized");
|
|
217
|
+
return {
|
|
218
|
+
...item,
|
|
219
|
+
index,
|
|
220
|
+
[props.groupKey]: isUncategorized(groupKey) ? "UNCATEGORIZED" : groupKey
|
|
221
|
+
};
|
|
222
|
+
});
|
|
223
|
+
const grouped = (0, import_pixel3_utils.groupBy)(mapped, props.groupKey);
|
|
224
|
+
const keys = Object.keys(grouped);
|
|
225
|
+
const results = keys.map((item) => {
|
|
226
|
+
return {
|
|
227
|
+
key: item,
|
|
228
|
+
values: grouped[item]
|
|
229
|
+
};
|
|
230
|
+
});
|
|
231
|
+
return results;
|
|
232
|
+
});
|
|
233
|
+
const getValueOfSuggestions = (0, import_vue.computed)(() => {
|
|
234
|
+
if (props.isRawValue)
|
|
235
|
+
return getSuggestionDatas.value;
|
|
236
|
+
const isArrayOfObject = getSuggestionDatas.value.some((item) => (0, import_pixel3_utils.isObject)(item));
|
|
237
|
+
if (isArrayOfObject) {
|
|
238
|
+
return getSuggestionDatas.value.map((item) => item[valueProp.value]);
|
|
239
|
+
}
|
|
240
|
+
return getSuggestionDatas.value;
|
|
241
|
+
});
|
|
242
|
+
const getCursorPosition = (0, import_vue.computed)(() => getValueOfSuggestions.value.findIndex((item) => (0, import_pixel3_utils.isEqual)(getValue(item), currentCursor.value)));
|
|
243
|
+
function onOpenPopover(e) {
|
|
244
|
+
isPopoverOpen.value = true;
|
|
245
|
+
if (isSearchable.value) {
|
|
246
|
+
const target = e.target;
|
|
247
|
+
target.setSelectionRange(0, target.value.length || 0);
|
|
248
|
+
}
|
|
249
|
+
if (props.modelValue) {
|
|
250
|
+
currentCursor.value = getValue(props.modelValue);
|
|
251
|
+
(0, import_vue.nextTick)(() => {
|
|
252
|
+
handleAdjustScrollPosition();
|
|
253
|
+
});
|
|
254
|
+
} else {
|
|
255
|
+
handleSetFirstSuggestion();
|
|
256
|
+
}
|
|
257
|
+
if (isInfinityScroll.value) {
|
|
258
|
+
enableIntersectionObserver();
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
__name(onOpenPopover, "onOpenPopover");
|
|
262
|
+
function onBlur() {
|
|
263
|
+
isPopoverOpen.value = false;
|
|
264
|
+
const inputEl = document.getElementById(`${getId}-control`);
|
|
265
|
+
inputEl == null ? void 0 : inputEl.blur();
|
|
266
|
+
if (isInfinityScroll.value) {
|
|
267
|
+
disableIntersectionObserver();
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
__name(onBlur, "onBlur");
|
|
271
|
+
function onInputChange(e) {
|
|
272
|
+
const target = e.target;
|
|
273
|
+
currentSearch.value = target.value;
|
|
274
|
+
onSearchChange();
|
|
275
|
+
emit("input", e);
|
|
276
|
+
}
|
|
277
|
+
__name(onInputChange, "onInputChange");
|
|
278
|
+
function onSelectListItem(value) {
|
|
279
|
+
const innerValue = getValue(value);
|
|
280
|
+
emit("update:modelValue", innerValue);
|
|
281
|
+
emit("change", innerValue);
|
|
282
|
+
onBlur();
|
|
283
|
+
}
|
|
284
|
+
__name(onSelectListItem, "onSelectListItem");
|
|
285
|
+
function onSearchChange() {
|
|
286
|
+
(0, import_vue.nextTick)(() => {
|
|
287
|
+
const hasSearchAndResult = currentSearch.value && getValueOfSuggestions.value.length;
|
|
288
|
+
const isEqualSearchAndLabel = currentSearch.value === currentLabel.value;
|
|
289
|
+
const emptySearchButHaveLabel = !currentSearch.value && currentLabel.value;
|
|
290
|
+
if (hasSearchAndResult) {
|
|
291
|
+
if (isEqualSearchAndLabel) {
|
|
292
|
+
currentCursor.value = currentValue.value;
|
|
293
|
+
handleAdjustScrollPosition();
|
|
294
|
+
} else {
|
|
295
|
+
handleSetFirstSuggestion();
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
if (emptySearchButHaveLabel) {
|
|
299
|
+
currentCursor.value = currentValue.value;
|
|
300
|
+
handleAdjustScrollPosition();
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
__name(onSearchChange, "onSearchChange");
|
|
305
|
+
function onModelValueChange() {
|
|
306
|
+
const data2 = props.data.find((item) => {
|
|
307
|
+
return (0, import_pixel3_utils.isEqual)(getValue(item), props.modelValue);
|
|
308
|
+
});
|
|
309
|
+
if (data2) {
|
|
310
|
+
currentValue.value = props.modelValue;
|
|
311
|
+
currentLabel.value = getLabel(data2);
|
|
312
|
+
currentSearch.value = getLabel(data2);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
__name(onModelValueChange, "onModelValueChange");
|
|
316
|
+
function handleForceFocusToInput() {
|
|
317
|
+
const inputEl = document.getElementById(`${getId}-control`);
|
|
318
|
+
inputEl == null ? void 0 : inputEl.focus();
|
|
319
|
+
}
|
|
320
|
+
__name(handleForceFocusToInput, "handleForceFocusToInput");
|
|
321
|
+
function onKeydown(e) {
|
|
322
|
+
if (e.code === "Enter") {
|
|
323
|
+
if (getSuggestionDatas.value.length) {
|
|
324
|
+
onSelectListItem(currentCursor.value);
|
|
325
|
+
emit("enter", getSuggestionDatas.value, currentSearch.value);
|
|
326
|
+
} else {
|
|
327
|
+
emit("enter", getSuggestionDatas.value, currentSearch.value);
|
|
328
|
+
onBlur();
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
if (e.code === "ArrowDown") {
|
|
332
|
+
e.preventDefault();
|
|
333
|
+
e.stopPropagation();
|
|
334
|
+
const totalData = getSuggestionDatas.value.length - 1;
|
|
335
|
+
const position = getCursorPosition.value;
|
|
336
|
+
const isLastPosition = totalData === position;
|
|
337
|
+
if (!isLastPosition) {
|
|
338
|
+
const nextPosition = position + 1;
|
|
339
|
+
currentCursor.value = getValueOfSuggestions.value[nextPosition];
|
|
340
|
+
handleAdjustScrollPosition();
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
if (e.code === "ArrowUp") {
|
|
344
|
+
e.preventDefault();
|
|
345
|
+
e.stopPropagation();
|
|
346
|
+
const position = getCursorPosition.value;
|
|
347
|
+
const isFirstPosition = position === 0;
|
|
348
|
+
if (!isFirstPosition) {
|
|
349
|
+
const nextPosition = position - 1;
|
|
350
|
+
currentCursor.value = getValueOfSuggestions.value[nextPosition];
|
|
351
|
+
handleAdjustScrollPosition();
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
__name(onKeydown, "onKeydown");
|
|
356
|
+
async function handleAdjustScrollPosition() {
|
|
357
|
+
const position = getValueOfSuggestions.value.indexOf(currentCursor.value);
|
|
358
|
+
const containerElement = document.getElementById(`popover-content-${getId}`);
|
|
359
|
+
const targetElement = containerElement == null ? void 0 : containerElement.querySelector(`[data-index="${position}"]`);
|
|
360
|
+
if ((0, import_pixel3_utils.isDef)(targetElement)) {
|
|
361
|
+
const isVisible = await (0, import_pixel3_utils.isElementVisible)(targetElement);
|
|
362
|
+
const getPosition = /* @__PURE__ */ __name(() => {
|
|
363
|
+
if (getCursorPosition.value === 0)
|
|
364
|
+
return "top";
|
|
365
|
+
if (props.data.length === getCursorPosition.value + 1)
|
|
366
|
+
return "bottom";
|
|
367
|
+
return void 0;
|
|
368
|
+
}, "getPosition");
|
|
369
|
+
if (!isVisible) {
|
|
370
|
+
(0, import_vue.nextTick)(() => {
|
|
371
|
+
(0, import_pixel3_utils.scrollToTargetElement)(targetElement, containerElement, getPosition());
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
__name(handleAdjustScrollPosition, "handleAdjustScrollPosition");
|
|
377
|
+
function handleSetFirstSuggestion() {
|
|
378
|
+
currentCursor.value = getValueOfSuggestions.value[0] || "";
|
|
379
|
+
handleAdjustScrollPosition();
|
|
380
|
+
}
|
|
381
|
+
__name(handleSetFirstSuggestion, "handleSetFirstSuggestion");
|
|
382
|
+
function getValue(value) {
|
|
383
|
+
if (props.isRawValue)
|
|
384
|
+
return value;
|
|
385
|
+
return (0, import_pixel3_utils.isObject)(value) ? value[valueProp.value] : value;
|
|
386
|
+
}
|
|
387
|
+
__name(getValue, "getValue");
|
|
388
|
+
function getLabel(value) {
|
|
389
|
+
return (0, import_pixel3_utils.isObject)(value) ? value[labelProp.value] : value;
|
|
390
|
+
}
|
|
391
|
+
__name(getLabel, "getLabel");
|
|
392
|
+
function isListItemActive(item) {
|
|
393
|
+
if (props.isListItemActiveFunction)
|
|
394
|
+
return props.isListItemActiveFunction(props.modelValue, item);
|
|
395
|
+
return (0, import_pixel3_utils.isEqual)(props.modelValue, getValue(item));
|
|
396
|
+
}
|
|
397
|
+
__name(isListItemActive, "isListItemActive");
|
|
398
|
+
const rootAtrrs = (0, import_vue.computed)(() => {
|
|
399
|
+
return {
|
|
400
|
+
style: {
|
|
401
|
+
width: "100%",
|
|
402
|
+
position: "relative"
|
|
403
|
+
},
|
|
404
|
+
onMouseenter: () => {
|
|
405
|
+
isOutside.value = false;
|
|
406
|
+
},
|
|
407
|
+
onMouseleave: () => {
|
|
408
|
+
isOutside.value = true;
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
});
|
|
412
|
+
const popoverAtrrs = (0, import_vue.computed)(() => {
|
|
413
|
+
return {
|
|
414
|
+
id: getId,
|
|
415
|
+
isManual: true,
|
|
416
|
+
isOpen: isPopoverOpen.value,
|
|
417
|
+
usePortal: usePortal.value,
|
|
418
|
+
isKeepAlive: isKeepAlive.value,
|
|
419
|
+
isAdaptiveWidth: isAdaptiveWidth.value
|
|
420
|
+
};
|
|
421
|
+
});
|
|
422
|
+
const popoverContentAtrrs = (0, import_vue.computed)(() => {
|
|
423
|
+
return {
|
|
424
|
+
class: (0, import_css.css)({
|
|
425
|
+
maxHeight: "300px",
|
|
426
|
+
overflowY: "auto",
|
|
427
|
+
position: "relative"
|
|
428
|
+
}),
|
|
429
|
+
onClick: handleForceFocusToInput,
|
|
430
|
+
...props.contentAttrs
|
|
431
|
+
};
|
|
432
|
+
});
|
|
433
|
+
const inputAtrrs = (0, import_vue.computed)(() => {
|
|
434
|
+
return {
|
|
435
|
+
// key: currentLabel.value,
|
|
436
|
+
id: getId,
|
|
437
|
+
modelValue: currentLabel.value,
|
|
438
|
+
isClearable: isClearable.value,
|
|
439
|
+
autocomplete: "off",
|
|
440
|
+
isReadOnly: !isSearchable.value || isReadOnly.value,
|
|
441
|
+
isFullWidth: isFullWidth.value,
|
|
442
|
+
placeholder: placeholder == null ? void 0 : placeholder.value,
|
|
443
|
+
onInput: onInputChange,
|
|
444
|
+
onKeydown,
|
|
445
|
+
onFocus: onOpenPopover,
|
|
446
|
+
onBlur: () => {
|
|
447
|
+
if (isOutside.value) {
|
|
448
|
+
onBlur();
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
});
|
|
453
|
+
const buttonActionAttrs = (0, import_vue.computed)(() => {
|
|
454
|
+
return {
|
|
455
|
+
class: (0, import_css.css)({
|
|
456
|
+
cursor: "pointer",
|
|
457
|
+
width: "full",
|
|
458
|
+
textAlign: "center",
|
|
459
|
+
roundedTop: "0",
|
|
460
|
+
borderTopWidth: "1px",
|
|
461
|
+
borderColor: "blue.50",
|
|
462
|
+
color: "blue.400",
|
|
463
|
+
position: "sticky",
|
|
464
|
+
bottom: "0px",
|
|
465
|
+
bg: "white",
|
|
466
|
+
fontSize: "md",
|
|
467
|
+
zIndex: "999",
|
|
468
|
+
py: 2,
|
|
469
|
+
height: "9.5",
|
|
470
|
+
_hover: {
|
|
471
|
+
color: "blue.500"
|
|
472
|
+
}
|
|
473
|
+
}),
|
|
474
|
+
onClick: (e) => {
|
|
475
|
+
e.stopPropagation();
|
|
476
|
+
emit("buttonAction", getSuggestionDatas.value, currentSearch.value);
|
|
477
|
+
isOutside.value = true;
|
|
478
|
+
onBlur();
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
});
|
|
482
|
+
const emptyTextAttrs = {
|
|
483
|
+
color: "gray.400",
|
|
484
|
+
class: (0, import_css.css)({
|
|
485
|
+
px: 3,
|
|
486
|
+
py: 2
|
|
487
|
+
})
|
|
488
|
+
};
|
|
489
|
+
const contentLoadingAttrs = {
|
|
490
|
+
class: (0, import_css.css)({
|
|
491
|
+
px: 3,
|
|
492
|
+
py: 2,
|
|
493
|
+
display: "flex",
|
|
494
|
+
alignItems: "center",
|
|
495
|
+
gap: 3
|
|
496
|
+
})
|
|
497
|
+
};
|
|
498
|
+
const popoverListItemAttrs = /* @__PURE__ */ __name((item, index) => {
|
|
499
|
+
const innerValue = getValue(item);
|
|
500
|
+
return {
|
|
501
|
+
onClick: (e) => {
|
|
502
|
+
e.stopPropagation();
|
|
503
|
+
onSelectListItem(item);
|
|
504
|
+
},
|
|
505
|
+
onMouseenter: () => currentCursor.value = innerValue,
|
|
506
|
+
isActive: isListItemActive(item),
|
|
507
|
+
"data-highlight": (0, import_pixel3_utils.isEqual)(innerValue, currentCursor.value) ? true : void 0,
|
|
508
|
+
"data-index": index,
|
|
509
|
+
"aria-selected": isListItemActive(item) ? true : void 0
|
|
510
|
+
};
|
|
511
|
+
}, "popoverListItemAttrs");
|
|
512
|
+
(0, import_vue.watch)(() => props.modelValue, (newValue) => {
|
|
513
|
+
if (newValue)
|
|
514
|
+
onModelValueChange();
|
|
515
|
+
});
|
|
516
|
+
(0, import_vue.watch)(() => props.data, () => {
|
|
517
|
+
if (props.isManualFilter && isPopoverOpen.value) {
|
|
518
|
+
(0, import_vue.nextTick)(() => {
|
|
519
|
+
handleSetFirstSuggestion();
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
});
|
|
523
|
+
(0, import_vue.onMounted)(() => {
|
|
524
|
+
if (props.modelValue)
|
|
525
|
+
onModelValueChange();
|
|
526
|
+
});
|
|
527
|
+
return {
|
|
528
|
+
currentSearch,
|
|
529
|
+
scrollEndNode,
|
|
530
|
+
getSuggestionDatas,
|
|
531
|
+
getGroupSuggestions,
|
|
532
|
+
rootAtrrs,
|
|
533
|
+
popoverAtrrs,
|
|
534
|
+
popoverContentAtrrs,
|
|
535
|
+
inputAtrrs,
|
|
536
|
+
buttonActionAttrs,
|
|
537
|
+
emptyTextAttrs,
|
|
538
|
+
contentLoadingAttrs,
|
|
539
|
+
popoverListItemAttrs,
|
|
540
|
+
getLabel
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
__name(useAutocomplete, "useAutocomplete");
|
|
544
|
+
|
|
545
|
+
// src/autocomplete.tsx
|
|
546
|
+
var import_patterns = require("@mekari/pixel3-styled-system/patterns");
|
|
547
|
+
var import_css2 = require("@mekari/pixel3-styled-system/css");
|
|
548
|
+
var MpAutocomplete = (0, import_vue3.defineComponent)({
|
|
549
|
+
name: "MpAutocomplete",
|
|
550
|
+
props: autocompleteProps,
|
|
551
|
+
emits: ["update:modelValue", "input", "change", "enter", "scrollEnd", "buttonAction"],
|
|
552
|
+
setup(props, {
|
|
553
|
+
emit,
|
|
554
|
+
slots
|
|
555
|
+
}) {
|
|
556
|
+
const {
|
|
557
|
+
getSuggestionDatas,
|
|
558
|
+
getGroupSuggestions,
|
|
559
|
+
currentSearch,
|
|
560
|
+
scrollEndNode,
|
|
561
|
+
rootAtrrs,
|
|
562
|
+
popoverAtrrs,
|
|
563
|
+
popoverContentAtrrs,
|
|
564
|
+
inputAtrrs,
|
|
565
|
+
buttonActionAttrs,
|
|
566
|
+
emptyTextAttrs,
|
|
567
|
+
contentLoadingAttrs,
|
|
568
|
+
popoverListItemAttrs,
|
|
569
|
+
getLabel
|
|
570
|
+
} = useAutocomplete(props, emit);
|
|
571
|
+
return () => {
|
|
572
|
+
const suggestionsNode = !props.isGroupSuggestions ? getSuggestionDatas.value.map((item, index) => {
|
|
573
|
+
return (0, import_vue2.createVNode)(import_pixel3_popover.MpPopoverListItem, popoverListItemAttrs(item, index), {
|
|
574
|
+
default: () => [slots.default ? slots.default({
|
|
575
|
+
item
|
|
576
|
+
}) : getLabel(item)]
|
|
577
|
+
});
|
|
578
|
+
}) : getGroupSuggestions.value.map((group, groupIndex) => {
|
|
579
|
+
return (0, import_vue2.createVNode)("div", {
|
|
580
|
+
"key": groupIndex,
|
|
581
|
+
"data-category": group.key,
|
|
582
|
+
"class": (0, import_patterns.flex)({
|
|
583
|
+
direction: "column",
|
|
584
|
+
alignItems: "start",
|
|
585
|
+
width: "full"
|
|
586
|
+
})
|
|
587
|
+
}, [slots.group ? slots.group({
|
|
588
|
+
group
|
|
589
|
+
}) : (0, import_vue2.createVNode)(import_pixel3_text.MpText, {
|
|
590
|
+
"size": "body-small",
|
|
591
|
+
"color": "gray.600",
|
|
592
|
+
"class": (0, import_css2.css)({
|
|
593
|
+
px: 3,
|
|
594
|
+
py: 2
|
|
595
|
+
})
|
|
596
|
+
}, {
|
|
597
|
+
default: () => [group.key]
|
|
598
|
+
}), group.values.map((item) => {
|
|
599
|
+
return (0, import_vue2.createVNode)(import_pixel3_popover.MpPopoverListItem, popoverListItemAttrs(item, item.index), {
|
|
600
|
+
default: () => [slots.default ? slots.default({
|
|
601
|
+
item
|
|
602
|
+
}) : getLabel(item)]
|
|
603
|
+
});
|
|
604
|
+
})]);
|
|
605
|
+
});
|
|
606
|
+
const buttonActionNode = props.isShowButtonAction && (0, import_vue2.createVNode)("button", buttonActionAttrs.value, [(0, import_vue2.createTextVNode)(" "), slots.buttonAction ? slots.buttonAction(getSuggestionDatas.value, currentSearch.value) : props.buttonActionText, (0, import_vue2.createTextVNode)(" ")]);
|
|
607
|
+
const emptyTextNode = (0, import_vue2.createVNode)(import_pixel3_text.MpText, emptyTextAttrs, {
|
|
608
|
+
default: () => [(0, import_vue2.createTextVNode)(" "), props.emptyText, (0, import_vue2.createTextVNode)(" ")]
|
|
609
|
+
});
|
|
610
|
+
const contentLoadingNode = props.isContentLoading && (0, import_vue2.createVNode)("div", contentLoadingAttrs, [(0, import_vue2.createVNode)(import_pixel3_spinner.MpSpinner, {
|
|
611
|
+
"size": "md"
|
|
612
|
+
}, null), (0, import_vue2.createVNode)(import_pixel3_text.MpText, null, {
|
|
613
|
+
default: () => [(0, import_vue2.createTextVNode)(" "), props.contentLoadingText, (0, import_vue2.createTextVNode)(" ")]
|
|
614
|
+
})]);
|
|
615
|
+
return (0, import_vue2.createVNode)("div", rootAtrrs.value, [(0, import_vue2.createVNode)(import_pixel3_popover.MpPopover, popoverAtrrs.value, {
|
|
616
|
+
default: () => [(0, import_vue2.createVNode)(import_pixel3_popover.MpPopoverTrigger, null, {
|
|
617
|
+
default: () => [(0, import_vue2.createVNode)(import_pixel3_input.MpInputGroup, null, {
|
|
618
|
+
default: () => [slots.leftAddon && (0, import_vue2.createVNode)(import_pixel3_input.MpInputLeftAddon, null, {
|
|
619
|
+
default: () => [(0, import_vue2.createTextVNode)(" "), slots.leftAddon(), (0, import_vue2.createTextVNode)(" ")]
|
|
620
|
+
}), (0, import_vue2.createVNode)(import_pixel3_input.MpInput, inputAtrrs.value, null), (0, import_vue2.createVNode)(import_pixel3_input.MpInputRightAddon, null, {
|
|
621
|
+
default: () => [props.isLoading ? (0, import_vue2.createVNode)(import_pixel3_spinner.MpSpinner, null, null) : (0, import_vue2.createVNode)(import_pixel3_icon.MpIcon, {
|
|
622
|
+
"name": "chevrons-down",
|
|
623
|
+
"size": "sm"
|
|
624
|
+
}, null)]
|
|
625
|
+
})]
|
|
626
|
+
})]
|
|
627
|
+
}), (0, import_vue2.createVNode)(import_pixel3_popover.MpPopoverContent, popoverContentAtrrs.value, {
|
|
628
|
+
default: () => [(0, import_vue2.createVNode)(import_pixel3_popover.MpPopoverList, null, {
|
|
629
|
+
default: () => [getSuggestionDatas.value.length === 0 ? emptyTextNode : suggestionsNode, contentLoadingNode]
|
|
630
|
+
}), props.isInfinityScroll && (0, import_vue2.createVNode)("div", {
|
|
631
|
+
"ref": scrollEndNode
|
|
632
|
+
}, null), buttonActionNode]
|
|
633
|
+
})]
|
|
634
|
+
})]);
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
});
|
|
638
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
639
|
+
0 && (module.exports = {
|
|
640
|
+
MpAutocomplete
|
|
641
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"src/modules/autocomplete.props.ts":{"bytes":3460,"imports":[],"format":"esm"},"src/modules/autocomplete.hooks.ts":{"bytes":12037,"imports":[{"path":"vue","kind":"import-statement","external":true},{"path":"@mekari/pixel3-utils","kind":"import-statement","external":true},{"path":"@mekari/pixel3-styled-system/css","kind":"import-statement","external":true},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/autocomplete.tsx":{"bytes":4706,"imports":[{"path":"vue","kind":"import-statement","external":true},{"path":"vue","kind":"import-statement","external":true},{"path":"@mekari/pixel3-popover","kind":"import-statement","external":true},{"path":"@mekari/pixel3-input","kind":"import-statement","external":true},{"path":"@mekari/pixel3-spinner","kind":"import-statement","external":true},{"path":"@mekari/pixel3-icon","kind":"import-statement","external":true},{"path":"@mekari/pixel3-text","kind":"import-statement","external":true},{"path":"src/modules/autocomplete.props.ts","kind":"import-statement","original":"./modules/autocomplete.props"},{"path":"src/modules/autocomplete.hooks.ts","kind":"import-statement","original":"./modules/autocomplete.hooks"},{"path":"@mekari/pixel3-styled-system/patterns","kind":"import-statement","external":true},{"path":"@mekari/pixel3-styled-system/css","kind":"import-statement","external":true}],"format":"esm"},"src/index.tsx":{"bytes":133,"imports":[{"path":"src/autocomplete.tsx","kind":"import-statement","original":"./autocomplete"}],"format":"esm"}},"outputs":{"dist/autocomplete.js":{"imports":[{"path":"vue","kind":"require-call","external":true},{"path":"vue","kind":"require-call","external":true},{"path":"@mekari/pixel3-popover","kind":"require-call","external":true},{"path":"@mekari/pixel3-input","kind":"require-call","external":true},{"path":"@mekari/pixel3-spinner","kind":"require-call","external":true},{"path":"@mekari/pixel3-icon","kind":"require-call","external":true},{"path":"@mekari/pixel3-text","kind":"require-call","external":true},{"path":"vue","kind":"require-call","external":true},{"path":"@mekari/pixel3-utils","kind":"require-call","external":true},{"path":"@mekari/pixel3-styled-system/css","kind":"require-call","external":true},{"path":"@mekari/pixel3-styled-system/patterns","kind":"require-call","external":true},{"path":"@mekari/pixel3-styled-system/css","kind":"require-call","external":true}],"exports":[],"entryPoint":"src/autocomplete.tsx","inputs":{"src/autocomplete.tsx":{"bytesInOutput":5172},"src/modules/autocomplete.props.ts":{"bytesInOutput":1882},"src/modules/autocomplete.hooks.ts":{"bytesInOutput":12295}},"bytes":20472},"dist/index.js":{"imports":[{"path":"vue","kind":"require-call","external":true},{"path":"vue","kind":"require-call","external":true},{"path":"@mekari/pixel3-popover","kind":"require-call","external":true},{"path":"@mekari/pixel3-input","kind":"require-call","external":true},{"path":"@mekari/pixel3-spinner","kind":"require-call","external":true},{"path":"@mekari/pixel3-icon","kind":"require-call","external":true},{"path":"@mekari/pixel3-text","kind":"require-call","external":true},{"path":"vue","kind":"require-call","external":true},{"path":"@mekari/pixel3-utils","kind":"require-call","external":true},{"path":"@mekari/pixel3-styled-system/css","kind":"require-call","external":true},{"path":"@mekari/pixel3-styled-system/patterns","kind":"require-call","external":true},{"path":"@mekari/pixel3-styled-system/css","kind":"require-call","external":true}],"exports":[],"entryPoint":"src/index.tsx","inputs":{"src/index.tsx":{"bytesInOutput":133},"src/autocomplete.tsx":{"bytesInOutput":5012},"src/modules/autocomplete.props.ts":{"bytesInOutput":1882},"src/modules/autocomplete.hooks.ts":{"bytesInOutput":12295}},"bytes":20463},"dist/modules/autocomplete.hooks.js":{"imports":[{"path":"vue","kind":"require-call","external":true},{"path":"@mekari/pixel3-utils","kind":"require-call","external":true},{"path":"@mekari/pixel3-styled-system/css","kind":"require-call","external":true}],"exports":[],"entryPoint":"src/modules/autocomplete.hooks.ts","inputs":{"src/modules/autocomplete.hooks.ts":{"bytesInOutput":12475}},"bytes":13511},"dist/modules/autocomplete.props.js":{"imports":[],"exports":[],"entryPoint":"src/modules/autocomplete.props.ts","inputs":{"src/modules/autocomplete.props.ts":{"bytesInOutput":2213}},"bytes":3181}}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"src/modules/autocomplete.props.ts":{"bytes":3460,"imports":[],"format":"esm"},"src/modules/autocomplete.hooks.ts":{"bytes":12037,"imports":[{"path":"vue","kind":"import-statement","external":true},{"path":"@mekari/pixel3-utils","kind":"import-statement","external":true},{"path":"@mekari/pixel3-styled-system/css","kind":"import-statement","external":true},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/autocomplete.tsx":{"bytes":4706,"imports":[{"path":"vue","kind":"import-statement","external":true},{"path":"vue","kind":"import-statement","external":true},{"path":"@mekari/pixel3-popover","kind":"import-statement","external":true},{"path":"@mekari/pixel3-input","kind":"import-statement","external":true},{"path":"@mekari/pixel3-spinner","kind":"import-statement","external":true},{"path":"@mekari/pixel3-icon","kind":"import-statement","external":true},{"path":"@mekari/pixel3-text","kind":"import-statement","external":true},{"path":"src/modules/autocomplete.props.ts","kind":"import-statement","original":"./modules/autocomplete.props"},{"path":"src/modules/autocomplete.hooks.ts","kind":"import-statement","original":"./modules/autocomplete.hooks"},{"path":"@mekari/pixel3-styled-system/patterns","kind":"import-statement","external":true},{"path":"@mekari/pixel3-styled-system/css","kind":"import-statement","external":true}],"format":"esm"},"src/index.tsx":{"bytes":133,"imports":[{"path":"src/autocomplete.tsx","kind":"import-statement","original":"./autocomplete"}],"format":"esm"}},"outputs":{"dist/autocomplete.mjs":{"imports":[{"path":"dist/chunk-XA465WRM.mjs","kind":"import-statement"},{"path":"dist/chunk-YGOZYS5H.mjs","kind":"import-statement"},{"path":"dist/chunk-OX7ZBBEQ.mjs","kind":"import-statement"},{"path":"dist/chunk-QZ7VFGWC.mjs","kind":"import-statement"}],"exports":["MpAutocomplete"],"entryPoint":"src/autocomplete.tsx","inputs":{},"bytes":179},"dist/index.mjs":{"imports":[{"path":"dist/chunk-XA465WRM.mjs","kind":"import-statement"},{"path":"dist/chunk-YGOZYS5H.mjs","kind":"import-statement"},{"path":"dist/chunk-OX7ZBBEQ.mjs","kind":"import-statement"},{"path":"dist/chunk-QZ7VFGWC.mjs","kind":"import-statement"}],"exports":["MpAutocomplete"],"entryPoint":"src/index.tsx","inputs":{"src/index.tsx":{"bytesInOutput":0}},"bytes":179},"dist/chunk-XA465WRM.mjs":{"imports":[{"path":"dist/chunk-YGOZYS5H.mjs","kind":"import-statement"},{"path":"dist/chunk-OX7ZBBEQ.mjs","kind":"import-statement"},{"path":"vue","kind":"import-statement","external":true},{"path":"vue","kind":"import-statement","external":true},{"path":"@mekari/pixel3-popover","kind":"import-statement","external":true},{"path":"@mekari/pixel3-input","kind":"import-statement","external":true},{"path":"@mekari/pixel3-spinner","kind":"import-statement","external":true},{"path":"@mekari/pixel3-icon","kind":"import-statement","external":true},{"path":"@mekari/pixel3-text","kind":"import-statement","external":true},{"path":"@mekari/pixel3-styled-system/patterns","kind":"import-statement","external":true},{"path":"@mekari/pixel3-styled-system/css","kind":"import-statement","external":true}],"exports":["MpAutocomplete"],"inputs":{"src/autocomplete.tsx":{"bytesInOutput":4269}},"bytes":4442},"dist/modules/autocomplete.hooks.mjs":{"imports":[{"path":"dist/chunk-YGOZYS5H.mjs","kind":"import-statement"},{"path":"dist/chunk-QZ7VFGWC.mjs","kind":"import-statement"}],"exports":["useAutocomplete"],"entryPoint":"src/modules/autocomplete.hooks.ts","inputs":{},"bytes":121},"dist/chunk-YGOZYS5H.mjs":{"imports":[{"path":"dist/chunk-QZ7VFGWC.mjs","kind":"import-statement"},{"path":"vue","kind":"import-statement","external":true},{"path":"@mekari/pixel3-utils","kind":"import-statement","external":true},{"path":"@mekari/pixel3-styled-system/css","kind":"import-statement","external":true}],"exports":["useAutocomplete"],"inputs":{"src/modules/autocomplete.hooks.ts":{"bytesInOutput":11634}},"bytes":11752},"dist/modules/autocomplete.props.mjs":{"imports":[{"path":"dist/chunk-OX7ZBBEQ.mjs","kind":"import-statement"},{"path":"dist/chunk-QZ7VFGWC.mjs","kind":"import-statement"}],"exports":["autocompleteEmit","autocompleteProps"],"entryPoint":"src/modules/autocomplete.props.ts","inputs":{},"bytes":165},"dist/chunk-OX7ZBBEQ.mjs":{"imports":[],"exports":["autocompleteEmit","autocompleteProps"],"inputs":{"src/modules/autocomplete.props.ts":{"bytesInOutput":1985}},"bytes":2075},"dist/chunk-QZ7VFGWC.mjs":{"imports":[],"exports":["__name"],"inputs":{},"bytes":151}}}
|