@pequity/squirrel 1.0.20-beta.3 → 1.0.20
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/squirrel.cjs.js +5 -0
- package/dist/squirrel.es.js +8220 -0
- package/dist/style.css +1 -2124
- package/package.json +20 -22
- package/dist/cjs/chunks/_plugin-vue_export-helper.js +0 -9
- package/dist/cjs/chunks/p-action-bar.js +0 -60
- package/dist/cjs/chunks/p-card.js +0 -28
- package/dist/cjs/chunks/p-checkbox.js +0 -24
- package/dist/cjs/chunks/p-dropdown-select.js +0 -414
- package/dist/cjs/chunks/p-input-percent.js +0 -53
- package/dist/cjs/chunks/p-pagination-info.js +0 -66
- package/dist/cjs/chunks/p-pagination.js +0 -122
- package/dist/cjs/chunks/p-ring-loader.js +0 -81
- package/dist/cjs/chunks/p-select-btn.js +0 -97
- package/dist/cjs/chunks/p-select.js +0 -123
- package/dist/cjs/chunks/p-table-loader.js +0 -70
- package/dist/cjs/chunks/p-tabs.js +0 -52
- package/dist/cjs/config.js +0 -105
- package/dist/cjs/currency.js +0 -9
- package/dist/cjs/dom.js +0 -27
- package/dist/cjs/index.js +0 -976
- package/dist/cjs/inputClassesMixin.js +0 -50
- package/dist/cjs/inputClassesShared.js +0 -76
- package/dist/cjs/listKeyboardNavigation.js +0 -110
- package/dist/cjs/number.js +0 -9
- package/dist/cjs/object.js +0 -4
- package/dist/cjs/p-action-bar.js +0 -3
- package/dist/cjs/p-alert.js +0 -65
- package/dist/cjs/p-avatar.js +0 -71
- package/dist/cjs/p-btn.js +0 -361
- package/dist/cjs/p-card.js +0 -3
- package/dist/cjs/p-checkbox.js +0 -3
- package/dist/cjs/p-chips.js +0 -110
- package/dist/cjs/p-close-btn.js +0 -36
- package/dist/cjs/p-date-picker.js +0 -139
- package/dist/cjs/p-drawer.js +0 -253
- package/dist/cjs/p-dropdown-select.js +0 -3
- package/dist/cjs/p-dropdown.js +0 -138
- package/dist/cjs/p-file-upload.js +0 -21
- package/dist/cjs/p-info-icon.js +0 -35
- package/dist/cjs/p-inline-date-picker.js +0 -142
- package/dist/cjs/p-input-number.js +0 -146
- package/dist/cjs/p-input-percent.js +0 -3
- package/dist/cjs/p-input-search.js +0 -110
- package/dist/cjs/p-input.js +0 -89
- package/dist/cjs/p-loading.js +0 -38
- package/dist/cjs/p-modal.js +0 -369
- package/dist/cjs/p-pagination-info.js +0 -3
- package/dist/cjs/p-pagination.js +0 -3
- package/dist/cjs/p-progress-bar.js +0 -41
- package/dist/cjs/p-ring-loader.js +0 -3
- package/dist/cjs/p-select-btn.js +0 -3
- package/dist/cjs/p-select-list.js +0 -4
- package/dist/cjs/p-select-pill.js +0 -111
- package/dist/cjs/p-select.js +0 -3
- package/dist/cjs/p-skeleton-loader.js +0 -73
- package/dist/cjs/p-table-filter-icon.js +0 -20
- package/dist/cjs/p-table-header-cell.js +0 -75
- package/dist/cjs/p-table-loader.js +0 -3
- package/dist/cjs/p-table-sort.js +0 -8
- package/dist/cjs/p-table-td.js +0 -88
- package/dist/cjs/p-table.js +0 -12
- package/dist/cjs/p-tabs.js +0 -3
- package/dist/cjs/p-textarea.js +0 -73
- package/dist/cjs/p-toggle.js +0 -114
- package/dist/cjs/pagination.js +0 -29
- package/dist/cjs/string.js +0 -12
- package/dist/cjs/tailwind.js +0 -4353
- package/dist/cjs/text.js +0 -16
- package/dist/cjs/useInputClasses.js +0 -44
- package/dist/cjs/usePLoading.js +0 -35
- package/dist/cjs/usePModal.js +0 -21
- package/dist/cjs/usePTableColResize.js +0 -81
- package/dist/cjs/usePTableRowVirtualizer.js +0 -31
- package/dist/cjs/useSelectList.js +0 -256
- package/dist/es/chunks/_plugin-vue_export-helper.js +0 -10
- package/dist/es/chunks/p-action-bar.js +0 -61
- package/dist/es/chunks/p-card.js +0 -29
- package/dist/es/chunks/p-checkbox.js +0 -25
- package/dist/es/chunks/p-dropdown-select.js +0 -415
- package/dist/es/chunks/p-input-percent.js +0 -54
- package/dist/es/chunks/p-pagination-info.js +0 -67
- package/dist/es/chunks/p-pagination.js +0 -123
- package/dist/es/chunks/p-ring-loader.js +0 -82
- package/dist/es/chunks/p-select-btn.js +0 -98
- package/dist/es/chunks/p-select.js +0 -124
- package/dist/es/chunks/p-table-loader.js +0 -71
- package/dist/es/chunks/p-tabs.js +0 -53
- package/dist/es/config.js +0 -105
- package/dist/es/currency.js +0 -9
- package/dist/es/dom.js +0 -27
- package/dist/es/index.js +0 -978
- package/dist/es/inputClassesMixin.js +0 -51
- package/dist/es/inputClassesShared.js +0 -76
- package/dist/es/listKeyboardNavigation.js +0 -110
- package/dist/es/number.js +0 -9
- package/dist/es/object.js +0 -4
- package/dist/es/p-action-bar.js +0 -4
- package/dist/es/p-alert.js +0 -66
- package/dist/es/p-avatar.js +0 -72
- package/dist/es/p-btn.js +0 -362
- package/dist/es/p-card.js +0 -4
- package/dist/es/p-checkbox.js +0 -4
- package/dist/es/p-chips.js +0 -111
- package/dist/es/p-close-btn.js +0 -37
- package/dist/es/p-date-picker.js +0 -140
- package/dist/es/p-drawer.js +0 -254
- package/dist/es/p-dropdown-select.js +0 -4
- package/dist/es/p-dropdown.js +0 -139
- package/dist/es/p-file-upload.js +0 -21
- package/dist/es/p-info-icon.js +0 -36
- package/dist/es/p-inline-date-picker.js +0 -143
- package/dist/es/p-input-number.js +0 -147
- package/dist/es/p-input-percent.js +0 -4
- package/dist/es/p-input-search.js +0 -111
- package/dist/es/p-input.js +0 -90
- package/dist/es/p-loading.js +0 -39
- package/dist/es/p-modal.js +0 -370
- package/dist/es/p-pagination-info.js +0 -4
- package/dist/es/p-pagination.js +0 -4
- package/dist/es/p-progress-bar.js +0 -42
- package/dist/es/p-ring-loader.js +0 -4
- package/dist/es/p-select-btn.js +0 -4
- package/dist/es/p-select-list.js +0 -4
- package/dist/es/p-select-pill.js +0 -112
- package/dist/es/p-select.js +0 -4
- package/dist/es/p-skeleton-loader.js +0 -74
- package/dist/es/p-table-filter-icon.js +0 -21
- package/dist/es/p-table-header-cell.js +0 -76
- package/dist/es/p-table-loader.js +0 -4
- package/dist/es/p-table-sort.js +0 -8
- package/dist/es/p-table-td.js +0 -89
- package/dist/es/p-table.js +0 -12
- package/dist/es/p-tabs.js +0 -4
- package/dist/es/p-textarea.js +0 -74
- package/dist/es/p-toggle.js +0 -115
- package/dist/es/pagination.js +0 -29
- package/dist/es/string.js +0 -12
- package/dist/es/tailwind.js +0 -4353
- package/dist/es/text.js +0 -16
- package/dist/es/useInputClasses.js +0 -44
- package/dist/es/usePLoading.js +0 -35
- package/dist/es/usePModal.js +0 -21
- package/dist/es/usePTableColResize.js +0 -81
- package/dist/es/usePTableRowVirtualizer.js +0 -31
- package/dist/es/useSelectList.js +0 -256
package/dist/es/text.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
const splitStringForHighlight = (textToSearchIn, searchStr) => {
|
|
2
|
-
const str = String(searchStr).trim();
|
|
3
|
-
const text = String(textToSearchIn).trim();
|
|
4
|
-
const index = text.indexOf(str);
|
|
5
|
-
if (index >= 0) {
|
|
6
|
-
const part1 = text.substring(0, index);
|
|
7
|
-
const part2 = text.substring(index, index + str.length);
|
|
8
|
-
const part3 = text.substring(index + str.length);
|
|
9
|
-
return [part1, part2, part3];
|
|
10
|
-
} else {
|
|
11
|
-
return [text];
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
export {
|
|
15
|
-
splitStringForHighlight
|
|
16
|
-
};
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { INPUT_BASE, INPUT_SIZES, SPACING_PREFIX, SPACING_LEFT, SPACING_SUFFIX, SPACING_RIGHT, INPUT_ERROR, INPUT_NORMAL, LABEL_BASE, LABEL_SIZES, LABEL_REQUIRED, SELECT_BASE, SELECT_ARROW, SELECT_SIZES, TEXTAREA_BASE, ERROR_MSG } from "./inputClassesShared.js";
|
|
2
|
-
import { ref, toRefs, computed } from "vue";
|
|
3
|
-
const defaults = {
|
|
4
|
-
size: ref("md"),
|
|
5
|
-
errorMsg: ref(""),
|
|
6
|
-
required: ref(false),
|
|
7
|
-
prefix: ref(false),
|
|
8
|
-
suffix: ref(false)
|
|
9
|
-
};
|
|
10
|
-
function useInputClasses(props) {
|
|
11
|
-
const opts = { ...defaults, ...toRefs(props) };
|
|
12
|
-
const { size, errorMsg, required, prefix, suffix } = opts;
|
|
13
|
-
const inputClasses = computed(() => {
|
|
14
|
-
const base = `${INPUT_BASE} ${INPUT_SIZES[size.value]}`;
|
|
15
|
-
const spacingLeft = prefix.value ? SPACING_PREFIX[size.value] : SPACING_LEFT[size.value];
|
|
16
|
-
const spacingRight = suffix.value ? SPACING_SUFFIX[size.value] : SPACING_RIGHT[size.value];
|
|
17
|
-
const res = `${base} ${spacingLeft} ${spacingRight} ${errorMsg.value ? INPUT_ERROR : INPUT_NORMAL}`;
|
|
18
|
-
return res;
|
|
19
|
-
});
|
|
20
|
-
const labelClasses = computed(() => {
|
|
21
|
-
const base = `${LABEL_BASE} ${LABEL_SIZES[size.value]}`;
|
|
22
|
-
const res = required.value ? `${base} ${LABEL_REQUIRED}` : base;
|
|
23
|
-
return res;
|
|
24
|
-
});
|
|
25
|
-
const selectClasses = computed(() => {
|
|
26
|
-
const res = `${inputClasses.value.replace(` ${SPACING_RIGHT[size.value]}`, "")} ${SELECT_BASE} ${SELECT_ARROW} ${SELECT_SIZES[size.value]}`;
|
|
27
|
-
return res;
|
|
28
|
-
});
|
|
29
|
-
const textareaClasses = computed(() => {
|
|
30
|
-
const res = `${inputClasses.value} ${TEXTAREA_BASE}`;
|
|
31
|
-
return res;
|
|
32
|
-
});
|
|
33
|
-
const errorMsgClasses = ref(ERROR_MSG);
|
|
34
|
-
return {
|
|
35
|
-
inputClasses,
|
|
36
|
-
labelClasses,
|
|
37
|
-
selectClasses,
|
|
38
|
-
textareaClasses,
|
|
39
|
-
errorMsgClasses
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
export {
|
|
43
|
-
useInputClasses
|
|
44
|
-
};
|
package/dist/es/usePLoading.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { ref, getCurrentScope, onScopeDispose } from "vue";
|
|
2
|
-
import { uniqueId } from "lodash-es";
|
|
3
|
-
const show = ref(false);
|
|
4
|
-
const loadingIds = [];
|
|
5
|
-
let timer;
|
|
6
|
-
const usePLoading = (options) => {
|
|
7
|
-
const { delay } = { delay: 200, ...options };
|
|
8
|
-
const scope = getCurrentScope();
|
|
9
|
-
const loadingShow = () => {
|
|
10
|
-
if (loadingIds.length === 0 && delay > 0) {
|
|
11
|
-
timer = setTimeout(() => {
|
|
12
|
-
show.value = true;
|
|
13
|
-
}, delay);
|
|
14
|
-
} else {
|
|
15
|
-
show.value = true;
|
|
16
|
-
}
|
|
17
|
-
loadingIds.push(uniqueId());
|
|
18
|
-
};
|
|
19
|
-
const loadingHide = () => {
|
|
20
|
-
if (loadingIds.length === 1) {
|
|
21
|
-
show.value = false;
|
|
22
|
-
}
|
|
23
|
-
clearTimeout(timer);
|
|
24
|
-
loadingIds.pop();
|
|
25
|
-
};
|
|
26
|
-
if (scope) {
|
|
27
|
-
onScopeDispose(() => {
|
|
28
|
-
loadingHide();
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
return { show, loadingShow, loadingHide };
|
|
32
|
-
};
|
|
33
|
-
export {
|
|
34
|
-
usePLoading
|
|
35
|
-
};
|
package/dist/es/usePModal.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { reactive } from "vue";
|
|
2
|
-
const state = reactive({
|
|
3
|
-
modals: {}
|
|
4
|
-
});
|
|
5
|
-
const usePModal = () => {
|
|
6
|
-
const show = (name) => {
|
|
7
|
-
state.modals[name] = true;
|
|
8
|
-
};
|
|
9
|
-
const hide = (name) => {
|
|
10
|
-
delete state.modals[name];
|
|
11
|
-
};
|
|
12
|
-
const hideAll = () => {
|
|
13
|
-
Object.keys(state.modals).forEach((modalName) => {
|
|
14
|
-
hide(modalName);
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
return { state, show, hide, hideAll };
|
|
18
|
-
};
|
|
19
|
-
export {
|
|
20
|
-
usePModal
|
|
21
|
-
};
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { MIN_WIDTH_COL_RESIZE } from "./p-table.js";
|
|
2
|
-
import { ref, onMounted, onBeforeUnmount, watch, nextTick } from "vue";
|
|
3
|
-
const usePTableColResize = (options) => {
|
|
4
|
-
const { enabled, ths } = options;
|
|
5
|
-
const isColResizing = ref(false);
|
|
6
|
-
const colResizeHandleLeft = ref("0px");
|
|
7
|
-
const colResizingWidth = ref(0);
|
|
8
|
-
const colResizingIndex = ref(-1);
|
|
9
|
-
const colResize = (e) => {
|
|
10
|
-
colResizeHandleLeft.value = `${e.clientX}px`;
|
|
11
|
-
if (isColResizing.value) {
|
|
12
|
-
document.body.classList.add("cursor-col-resize");
|
|
13
|
-
const th = ths.value[colResizingIndex.value];
|
|
14
|
-
const rect = th.getBoundingClientRect();
|
|
15
|
-
const diff = e.clientX - rect.left - th.offsetWidth;
|
|
16
|
-
const widthToSet = th.offsetWidth + diff;
|
|
17
|
-
setColResizingWidth(widthToSet);
|
|
18
|
-
colResizeHandleLeft.value = e.clientX < rect.left ? "0px" : `${e.clientX}px`;
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
const colResizeStart = (e, i) => {
|
|
22
|
-
if (e.detail === 1) {
|
|
23
|
-
e.preventDefault();
|
|
24
|
-
isColResizing.value = true;
|
|
25
|
-
colResizingWidth.value = ths.value[i].offsetWidth;
|
|
26
|
-
colResizingIndex.value = i;
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
const colResizeStop = () => {
|
|
30
|
-
if (!isColResizing.value) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
isColResizing.value = false;
|
|
34
|
-
document.body.classList.remove("cursor-col-resize");
|
|
35
|
-
};
|
|
36
|
-
const colResizeFitToData = (colIndex) => {
|
|
37
|
-
var _a;
|
|
38
|
-
isColResizing.value = true;
|
|
39
|
-
const tds = (_a = ths.value[colIndex].closest("table")) == null ? void 0 : _a.querySelectorAll("tbody tr td:nth-child(" + (colIndex + 1) + ") div.w-max");
|
|
40
|
-
if (!tds) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
const maxWidth = [...tds].reduce((max, td) => {
|
|
44
|
-
const width = td.getBoundingClientRect().width;
|
|
45
|
-
return width > max ? width : max;
|
|
46
|
-
}, 0);
|
|
47
|
-
setColResizingWidth(maxWidth);
|
|
48
|
-
nextTick(() => {
|
|
49
|
-
isColResizing.value = false;
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
const setColResizingWidth = (width) => {
|
|
53
|
-
colResizingWidth.value = width > MIN_WIDTH_COL_RESIZE ? Math.ceil(width) : MIN_WIDTH_COL_RESIZE;
|
|
54
|
-
};
|
|
55
|
-
onMounted(() => {
|
|
56
|
-
enabled.value && document.addEventListener("mouseup", colResizeStop);
|
|
57
|
-
});
|
|
58
|
-
onBeforeUnmount(() => {
|
|
59
|
-
enabled.value && document.removeEventListener("mouseup", colResizeStop);
|
|
60
|
-
});
|
|
61
|
-
watch(enabled, (nV) => {
|
|
62
|
-
if (nV) {
|
|
63
|
-
document.addEventListener("mouseup", colResizeStop);
|
|
64
|
-
} else {
|
|
65
|
-
document.removeEventListener("mouseup", colResizeStop);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
return {
|
|
69
|
-
isColResizing,
|
|
70
|
-
colResizeHandleLeft,
|
|
71
|
-
colResizingIndex,
|
|
72
|
-
colResizingWidth,
|
|
73
|
-
colResize,
|
|
74
|
-
colResizeStart,
|
|
75
|
-
colResizeStop,
|
|
76
|
-
colResizeFitToData
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
export {
|
|
80
|
-
usePTableColResize
|
|
81
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { ref, computed, isRef, unref } from "vue";
|
|
2
|
-
import { useVirtualizer } from "@tanstack/vue-virtual";
|
|
3
|
-
const usePTableRowVirtualizer = (options) => {
|
|
4
|
-
if (!options.value) {
|
|
5
|
-
return {
|
|
6
|
-
virtualizer: null,
|
|
7
|
-
virtualRows: ref([{ key: 0, index: 0 }]),
|
|
8
|
-
paddingTop: ref(0),
|
|
9
|
-
paddingBottom: ref(0),
|
|
10
|
-
measureElement: () => ref(void 0)
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
const virtualizer = useVirtualizer(options);
|
|
14
|
-
const virtualRows = computed(() => virtualizer.value.getVirtualItems());
|
|
15
|
-
const paddingTop = computed(() => virtualRows.value.length > 0 ? virtualRows.value[0].start : 0);
|
|
16
|
-
const paddingBottom = computed(
|
|
17
|
-
() => virtualRows.value.length > 0 ? (virtualizer == null ? void 0 : virtualizer.value.getTotalSize()) - virtualRows.value[virtualRows.value.length - 1].end : 0
|
|
18
|
-
);
|
|
19
|
-
const measureElement = (cmp) => {
|
|
20
|
-
const el = isRef(cmp) ? unref(cmp) : cmp == null ? void 0 : cmp.$el;
|
|
21
|
-
if (!el) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
virtualizer.value.measureElement(el);
|
|
25
|
-
return void 0;
|
|
26
|
-
};
|
|
27
|
-
return { virtualizer, virtualRows, paddingTop, paddingBottom, measureElement };
|
|
28
|
-
};
|
|
29
|
-
export {
|
|
30
|
-
usePTableRowVirtualizer
|
|
31
|
-
};
|
package/dist/es/useSelectList.js
DELETED
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import { ref, computed, watch, onUnmounted, nextTick } from "vue";
|
|
2
|
-
import { setupListKeyboardNavigation } from "./listKeyboardNavigation.js";
|
|
3
|
-
import { cloneDeep, uniqBy } from "lodash-es";
|
|
4
|
-
import { isObject } from "./object.js";
|
|
5
|
-
import { toString } from "./string.js";
|
|
6
|
-
import { useVirtualizer } from "@tanstack/vue-virtual";
|
|
7
|
-
const createInternalItems = (items) => {
|
|
8
|
-
let arr = Array.isArray(items) ? items.slice() : [];
|
|
9
|
-
if (arr.length && !isObject(arr[0])) {
|
|
10
|
-
arr = arr.filter((item, i, self) => self.indexOf(item) === i).map((item) => ({ value: item, text: item }));
|
|
11
|
-
}
|
|
12
|
-
return arr;
|
|
13
|
-
};
|
|
14
|
-
const createInternalValue = (modelValue, valueIsObject, multiple, itemValue, internalItems) => {
|
|
15
|
-
let val = modelValue;
|
|
16
|
-
if (valueIsObject && isObject(modelValue)) {
|
|
17
|
-
if (multiple) {
|
|
18
|
-
val = modelValue.map((v) => v[itemValue]);
|
|
19
|
-
} else {
|
|
20
|
-
val = modelValue ? modelValue[itemValue] : modelValue;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
const arr = Array.isArray(val) ? val : [val];
|
|
24
|
-
return arr;
|
|
25
|
-
};
|
|
26
|
-
const nextFrame = () => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)));
|
|
27
|
-
const nextLoop = (ms) => new Promise((resolve) => setTimeout(resolve, ms || 0));
|
|
28
|
-
const LIST_ITEM_SIZES = { sm: 32, md: 40, lg: 48 };
|
|
29
|
-
const LIST_ITEM_CLASS = "clear-both block w-full cursor-pointer whitespace-nowrap py-1 px-3 text-left text-sm font-medium hover:bg-p-blue-10";
|
|
30
|
-
const LIST_ITEM_ACTIVE_CLASS = "selected";
|
|
31
|
-
const useSelectList = (props, inputSearch, virtualizerRef, emit) => {
|
|
32
|
-
let navigationSvc = null;
|
|
33
|
-
const internalItems = ref([]);
|
|
34
|
-
const internalValue = ref([]);
|
|
35
|
-
const search = ref("");
|
|
36
|
-
const selectedItems = computed(() => {
|
|
37
|
-
return internalItems.value.filter((item) => internalValue.value.includes(item[props.itemValue]));
|
|
38
|
-
});
|
|
39
|
-
const computedItems = computed(() => {
|
|
40
|
-
return cloneDeep(internalItems.value).filter((item) => {
|
|
41
|
-
return String(item[props.itemText]).toLocaleLowerCase().includes(String(search.value).toLocaleLowerCase());
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
const computedItemSize = computed(() => props.itemSize ? props.itemSize : LIST_ITEM_SIZES[props.size]);
|
|
45
|
-
const computedInsideSelected = computed(() => {
|
|
46
|
-
const filteredItems = computedItems.value.map((item) => item[props.itemValue]);
|
|
47
|
-
return filteredItems.every((item) => internalValue.value.includes(item));
|
|
48
|
-
});
|
|
49
|
-
const rowVirtualizer = useVirtualizer(
|
|
50
|
-
computed(() => {
|
|
51
|
-
return {
|
|
52
|
-
count: computedItems.value.length,
|
|
53
|
-
getScrollElement: () => virtualizerRef.value,
|
|
54
|
-
getItemKey: (index) => toString(computedItems.value[index][props.itemValue]),
|
|
55
|
-
estimateSize: () => {
|
|
56
|
-
return props.itemSize ? props.itemSize : LIST_ITEM_SIZES[props.size];
|
|
57
|
-
},
|
|
58
|
-
overscan: 10
|
|
59
|
-
};
|
|
60
|
-
})
|
|
61
|
-
);
|
|
62
|
-
const getValue = (index) => {
|
|
63
|
-
var _a;
|
|
64
|
-
return (_a = computedItems.value[index]) == null ? void 0 : _a[props.itemValue];
|
|
65
|
-
};
|
|
66
|
-
const getText = (index) => {
|
|
67
|
-
var _a;
|
|
68
|
-
return (_a = computedItems.value[index]) == null ? void 0 : _a[props.itemText];
|
|
69
|
-
};
|
|
70
|
-
watch(
|
|
71
|
-
() => props.modelValue,
|
|
72
|
-
(nV) => {
|
|
73
|
-
internalValue.value = createInternalValue(
|
|
74
|
-
nV,
|
|
75
|
-
props.valueIsObject,
|
|
76
|
-
props.multiple,
|
|
77
|
-
props.itemValue,
|
|
78
|
-
internalItems.value
|
|
79
|
-
);
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
immediate: true,
|
|
83
|
-
deep: true
|
|
84
|
-
}
|
|
85
|
-
);
|
|
86
|
-
watch(search, async (nV) => {
|
|
87
|
-
await scrollScrollerToTop();
|
|
88
|
-
await nextFrame();
|
|
89
|
-
if (!navigationSvc) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
const firstItem = navigationSvc.getItems().filter((item) => item.style.transform.includes("translateY(0px)"))[0];
|
|
93
|
-
if (nV) {
|
|
94
|
-
navigationSvc.setFocusedItem(firstItem);
|
|
95
|
-
} else {
|
|
96
|
-
if (props.multiple) {
|
|
97
|
-
navigationSvc.setFocusedItem(firstItem);
|
|
98
|
-
} else {
|
|
99
|
-
getActiveItemIndex() > -1 ? scrollToActiveItem() : navigationSvc.clearFocusedState();
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
onUnmounted(() => {
|
|
104
|
-
navigationSvc == null ? void 0 : navigationSvc.destroy();
|
|
105
|
-
navigationSvc = null;
|
|
106
|
-
});
|
|
107
|
-
const putSelectedItemsOnTop = () => {
|
|
108
|
-
if (props.selectedTopShown) {
|
|
109
|
-
const arr = internalItems.value.reduce(
|
|
110
|
-
(acc, curr) => {
|
|
111
|
-
internalValue.value.includes(curr[props.itemValue]) ? acc[0].push(curr) : acc[1].push(curr);
|
|
112
|
-
return acc;
|
|
113
|
-
},
|
|
114
|
-
[[], []]
|
|
115
|
-
);
|
|
116
|
-
internalItems.value = arr[0].sort(
|
|
117
|
-
(a, b) => String(a[props.itemText]).localeCompare(String(b[props.itemText]), void 0, {
|
|
118
|
-
numeric: true,
|
|
119
|
-
sensitivity: "base"
|
|
120
|
-
})
|
|
121
|
-
).concat(arr[1]);
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
const select = async (e, val) => {
|
|
125
|
-
var _a, _b;
|
|
126
|
-
const el = e.currentTarget;
|
|
127
|
-
if (props.multiple && props.searchable && document.activeElement !== ((_a = inputSearch.value) == null ? void 0 : _a.$el.querySelector("input"))) {
|
|
128
|
-
(_b = inputSearch.value) == null ? void 0 : _b.$el.querySelector("input").focus();
|
|
129
|
-
}
|
|
130
|
-
if (props.multiple) {
|
|
131
|
-
if (!isSelected(val)) {
|
|
132
|
-
emit("update:modelValue", toArrOfObjIfNeeded([...internalValue.value, val]));
|
|
133
|
-
} else {
|
|
134
|
-
emit("update:modelValue", toArrOfObjIfNeeded(internalValue.value.filter((item) => item !== val)));
|
|
135
|
-
}
|
|
136
|
-
} else {
|
|
137
|
-
emit("update:modelValue", props.valueIsObject ? getItemByValue(val) : val);
|
|
138
|
-
}
|
|
139
|
-
await nextTick();
|
|
140
|
-
navigationSvc == null ? void 0 : navigationSvc.setFocusedItem(el.parentElement);
|
|
141
|
-
emit("select", val);
|
|
142
|
-
};
|
|
143
|
-
const toArrOfObjIfNeeded = (arr) => {
|
|
144
|
-
return props.valueIsObject ? arr.map((val) => getItemByValue(val)) : arr;
|
|
145
|
-
};
|
|
146
|
-
const getItemByValue = (value) => {
|
|
147
|
-
return internalItems.value.find((item) => item[props.itemValue] === value);
|
|
148
|
-
};
|
|
149
|
-
const isSelected = (val) => {
|
|
150
|
-
return internalValue.value.includes(val);
|
|
151
|
-
};
|
|
152
|
-
const setupNavigationSvc = () => {
|
|
153
|
-
if (navigationSvc) {
|
|
154
|
-
navigationSvc.init();
|
|
155
|
-
} else {
|
|
156
|
-
navigationSvc = setupListKeyboardNavigation({
|
|
157
|
-
itemContainer: virtualizerRef.value,
|
|
158
|
-
itemSelector: "[p-select-list-option]",
|
|
159
|
-
itemSelectSelector: `[p-select-list-option-item]`,
|
|
160
|
-
itemFocusClass: "bg-p-blue-10"
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
const destroyNavigationSvc = () => {
|
|
165
|
-
navigationSvc == null ? void 0 : navigationSvc.destroy();
|
|
166
|
-
navigationSvc = null;
|
|
167
|
-
};
|
|
168
|
-
const onFocus = async () => {
|
|
169
|
-
setupNavigationSvc();
|
|
170
|
-
};
|
|
171
|
-
const onMousemove = () => {
|
|
172
|
-
navigationSvc == null ? void 0 : navigationSvc.clearFocusedState();
|
|
173
|
-
};
|
|
174
|
-
const scrollScrollerToTop = async () => {
|
|
175
|
-
rowVirtualizer.value.scrollToOffset(0);
|
|
176
|
-
await nextFrame();
|
|
177
|
-
};
|
|
178
|
-
const scrollToActiveItem = async (options) => {
|
|
179
|
-
var _a;
|
|
180
|
-
if (options == null ? void 0 : options.wait) {
|
|
181
|
-
await nextLoop(options.wait);
|
|
182
|
-
}
|
|
183
|
-
const activeIndex = getActiveItemIndex();
|
|
184
|
-
if (virtualizerRef.value && rowVirtualizer.value && activeIndex > -1) {
|
|
185
|
-
rowVirtualizer.value.scrollToIndex(activeIndex, {
|
|
186
|
-
align: "center"
|
|
187
|
-
});
|
|
188
|
-
await nextLoop();
|
|
189
|
-
await nextFrame();
|
|
190
|
-
const activeEl = (_a = virtualizerRef.value) == null ? void 0 : _a.querySelector(`.${LIST_ITEM_ACTIVE_CLASS}`);
|
|
191
|
-
navigationSvc == null ? void 0 : navigationSvc.setFocusedItem(activeEl == null ? void 0 : activeEl.parentNode);
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
const getActiveItemIndex = () => {
|
|
195
|
-
return internalItems.value.indexOf(selectedItems.value[0]);
|
|
196
|
-
};
|
|
197
|
-
const selectAll = () => {
|
|
198
|
-
if (!props.multiple) {
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
const selectedItems2 = internalValue.value;
|
|
202
|
-
const filteredItems = computedItems.value.map((item) => item[props.itemValue]);
|
|
203
|
-
const toEmit = uniqBy([...selectedItems2, ...filteredItems], (item) => item);
|
|
204
|
-
emit("update:modelValue", toArrOfObjIfNeeded(toEmit));
|
|
205
|
-
};
|
|
206
|
-
const clearAll = () => {
|
|
207
|
-
search.value = "";
|
|
208
|
-
emit("update:modelValue", []);
|
|
209
|
-
};
|
|
210
|
-
watch(
|
|
211
|
-
() => props.items,
|
|
212
|
-
(nV) => {
|
|
213
|
-
internalItems.value = createInternalItems(nV);
|
|
214
|
-
if (props.multiple && props.items.length && internalValue.value.length) {
|
|
215
|
-
const internalValueFiltered = internalValue.value.filter((item) => {
|
|
216
|
-
return internalItems.value.some((i) => i[props.itemValue] === item);
|
|
217
|
-
});
|
|
218
|
-
if (internalValueFiltered.length !== internalValue.value.length) {
|
|
219
|
-
console.warn(`[p-select-list] Some values in the modelValue are not in the items list.`);
|
|
220
|
-
emit("update:modelValue", toArrOfObjIfNeeded(internalValueFiltered));
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
},
|
|
224
|
-
{
|
|
225
|
-
immediate: true
|
|
226
|
-
}
|
|
227
|
-
);
|
|
228
|
-
return {
|
|
229
|
-
LIST_ITEM_SIZES,
|
|
230
|
-
LIST_ITEM_CLASS,
|
|
231
|
-
LIST_ITEM_ACTIVE_CLASS,
|
|
232
|
-
selectedItems,
|
|
233
|
-
computedItems,
|
|
234
|
-
computedItemSize,
|
|
235
|
-
computedInsideSelected,
|
|
236
|
-
internalItems,
|
|
237
|
-
internalValue,
|
|
238
|
-
search,
|
|
239
|
-
rowVirtualizer,
|
|
240
|
-
getValue,
|
|
241
|
-
getText,
|
|
242
|
-
isSelected,
|
|
243
|
-
setupNavigationSvc,
|
|
244
|
-
destroyNavigationSvc,
|
|
245
|
-
select,
|
|
246
|
-
onFocus,
|
|
247
|
-
onMousemove,
|
|
248
|
-
scrollToActiveItem,
|
|
249
|
-
putSelectedItemsOnTop,
|
|
250
|
-
selectAll,
|
|
251
|
-
clearAll
|
|
252
|
-
};
|
|
253
|
-
};
|
|
254
|
-
export {
|
|
255
|
-
useSelectList
|
|
256
|
-
};
|