bkui-vue 0.0.1-beta.27 → 0.0.1-beta.28

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.
@@ -81,6 +81,7 @@ var transfer = "";
81
81
  var pagination = "";
82
82
  var timeline = "";
83
83
  var resizeLayout = "";
84
+ var tagInput = "";
84
85
  const BKLAYERD_INDEX_EFAULT_VALUE = {
85
86
  ["bottom"]: 0,
86
87
  ["content"]: 1,
@@ -10372,7 +10373,7 @@ function useRegistry(data2) {
10372
10373
  unregister
10373
10374
  };
10374
10375
  }
10375
- function useDebouncedRef(value, delay = 200) {
10376
+ function useDebouncedRef$1(value, delay = 200) {
10376
10377
  let timeout;
10377
10378
  let innerValue = value;
10378
10379
  return vue.customRef((track, trigger) => ({
@@ -10416,7 +10417,7 @@ function usePopover(config) {
10416
10417
  };
10417
10418
  }
10418
10419
  function useRemoteSearch(method) {
10419
- const searchKey = useDebouncedRef("");
10420
+ const searchKey = useDebouncedRef$1("");
10420
10421
  const searchLoading = vue.ref(false);
10421
10422
  vue.watch(searchKey, async () => {
10422
10423
  searchLoading.value = true;
@@ -12827,6 +12828,939 @@ var Component$4 = vue.defineComponent({
12827
12828
  }
12828
12829
  });
12829
12830
  const BkTable = withInstall(Component$4);
12831
+ const INPUT_MIN_WIDTH = 12;
12832
+ function useDebouncedRef(value, delay = 200) {
12833
+ let timeout;
12834
+ let innerValue = value;
12835
+ return vue.customRef((track, trigger) => ({
12836
+ get() {
12837
+ track();
12838
+ return innerValue;
12839
+ },
12840
+ set(newValue) {
12841
+ clearTimeout(timeout);
12842
+ timeout = setTimeout(() => {
12843
+ innerValue = newValue;
12844
+ trigger();
12845
+ }, delay);
12846
+ }
12847
+ }));
12848
+ }
12849
+ function usePage(pageSize) {
12850
+ const state = vue.reactive({
12851
+ curPage: 1,
12852
+ totalSize: 0,
12853
+ totalPage: 0,
12854
+ pageSize,
12855
+ isPageLoading: false,
12856
+ curPageList: [],
12857
+ renderListPaged: []
12858
+ });
12859
+ const initPage = (allList = []) => {
12860
+ state.curPage = 1;
12861
+ state.totalSize = allList.length;
12862
+ state.totalPage = Math.ceil(state.totalSize / state.pageSize) || 1;
12863
+ const list = [];
12864
+ if (state.pageSize > 0) {
12865
+ for (let i2 = 0; i2 < state.totalSize; i2 += state.pageSize) {
12866
+ list.push(allList.slice(i2, i2 + state.pageSize));
12867
+ }
12868
+ }
12869
+ state.renderListPaged.splice(0, state.renderListPaged.length, ...list);
12870
+ state.curPageList.splice(0, state.curPageList.length, ...state.renderListPaged[state.curPage - 1] || []);
12871
+ };
12872
+ const pageChange = (page) => {
12873
+ state.curPage = page;
12874
+ state.curPageList.splice(state.curPageList.length, 0, ...state.renderListPaged[state.curPage - 1] || []);
12875
+ state.isPageLoading = false;
12876
+ };
12877
+ return {
12878
+ pageState: state,
12879
+ initPage,
12880
+ pageChange
12881
+ };
12882
+ }
12883
+ function useFlatList(props) {
12884
+ const {
12885
+ useGroup,
12886
+ saveKey,
12887
+ displayKey,
12888
+ list
12889
+ } = vue.toRefs(props);
12890
+ const flatList = vue.reactive([]);
12891
+ vue.watch([useGroup, saveKey, displayKey, list], () => {
12892
+ let formatList = list.value;
12893
+ if (useGroup.value) {
12894
+ formatList = list.value.reduce((formatList2, item) => {
12895
+ let children = [];
12896
+ if (item.children) {
12897
+ children = item.children.map((child) => __spreadValues({
12898
+ group: {
12899
+ groupId: item[saveKey.value],
12900
+ groupName: item[displayKey.value]
12901
+ }
12902
+ }, child));
12903
+ }
12904
+ return formatList2.concat(children);
12905
+ }, []);
12906
+ }
12907
+ flatList.splice(0, flatList.length, ...formatList);
12908
+ }, { immediate: true, deep: true });
12909
+ return flatList;
12910
+ }
12911
+ const getCharLength = (str) => {
12912
+ const len = str.length;
12913
+ let bitLen = 0;
12914
+ for (let i2 = 0; i2 < len; i2++) {
12915
+ if ((str.charCodeAt(i2) & 65280) !== 0) {
12916
+ bitLen += 1;
12917
+ }
12918
+ bitLen += 1;
12919
+ }
12920
+ return bitLen;
12921
+ };
12922
+ var ListTagRender = vue.defineComponent({
12923
+ name: "ListTagRender",
12924
+ props: {
12925
+ node: PropTypes.object,
12926
+ searchKey: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
12927
+ displayKey: PropTypes.string,
12928
+ searchKeyword: PropTypes.string,
12929
+ tpl: {
12930
+ type: Function,
12931
+ default: null
12932
+ }
12933
+ },
12934
+ render() {
12935
+ const highlightKeyword = (value) => {
12936
+ if (this.searchKeyword) {
12937
+ const keywordReg = new RegExp(`(${this.searchKeyword})`, "i");
12938
+ return value.replace(keywordReg, '<strong class="highlight-text">$1</strong>');
12939
+ }
12940
+ return value;
12941
+ };
12942
+ if (this.tpl) {
12943
+ return this.tpl(this.node, highlightKeyword, vue.h, this);
12944
+ }
12945
+ const displayText = this.node[this.displayKey];
12946
+ return vue.createVNode("div", {
12947
+ "class": "bk-selector-node"
12948
+ }, [vue.createVNode("span", {
12949
+ "class": "text",
12950
+ "innerHTML": highlightKeyword(displayText)
12951
+ }, [displayText])]);
12952
+ }
12953
+ });
12954
+ const tagProps = () => ({
12955
+ modelValue: PropTypes.arrayOf(PropTypes.string).def([]),
12956
+ placeholder: PropTypes.string.def("\u8BF7\u8F93\u5165\u5E76\u6309 Enter \u7ED3\u675F"),
12957
+ list: PropTypes.arrayOf(PropTypes.object).def([]),
12958
+ disabled: PropTypes.bool.def(false),
12959
+ tooltipKey: PropTypes.string.def(""),
12960
+ saveKey: PropTypes.string.def("id"),
12961
+ displayKey: PropTypes.string.def("name"),
12962
+ hasDeleteIcon: PropTypes.bool.def(false),
12963
+ clearable: PropTypes.bool.def(true),
12964
+ trigger: PropTypes.commonType(["focus", "search"]).def("search"),
12965
+ searchKey: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]).def("name"),
12966
+ useGroup: PropTypes.bool.def(false),
12967
+ allowCreate: PropTypes.bool.def(false),
12968
+ maxData: PropTypes.number.def(-1),
12969
+ maxResult: PropTypes.number.def(10),
12970
+ contentMaxHeight: PropTypes.number.def(300),
12971
+ contentWidth: PropTypes.number.def(190),
12972
+ separator: PropTypes.string.def(""),
12973
+ allowNextFocus: PropTypes.bool.def(true),
12974
+ allowAutoMatch: PropTypes.bool.def(false),
12975
+ showClearOnlyHover: PropTypes.bool.def(false),
12976
+ leftSpace: PropTypes.number.def(0),
12977
+ createTagValidator: {
12978
+ type: Function,
12979
+ default: null
12980
+ },
12981
+ filterCallback: {
12982
+ type: Function,
12983
+ default: null
12984
+ },
12985
+ tagTpl: {
12986
+ type: Function,
12987
+ default: null
12988
+ },
12989
+ tpl: {
12990
+ type: Function,
12991
+ default: null
12992
+ },
12993
+ pasteFn: {
12994
+ type: Function,
12995
+ default: null
12996
+ }
12997
+ });
12998
+ var TagRender = vue.defineComponent({
12999
+ name: "TagRender",
13000
+ props: {
13001
+ node: PropTypes.object,
13002
+ displayKey: PropTypes.string,
13003
+ tpl: {
13004
+ type: Function,
13005
+ default: null
13006
+ }
13007
+ },
13008
+ render() {
13009
+ if (this.tpl) {
13010
+ return this.tpl(this.node, vue.h, this);
13011
+ }
13012
+ return vue.createVNode("div", {
13013
+ "class": "tag"
13014
+ }, [vue.createVNode("span", {
13015
+ "class": "text"
13016
+ }, [this.node[this.displayKey]])]);
13017
+ }
13018
+ });
13019
+ var TagInput = vue.defineComponent({
13020
+ name: "BkTagInput",
13021
+ directives: {
13022
+ bkTooltips: tooltips
13023
+ },
13024
+ props: tagProps(),
13025
+ emits: ["update:modelValue", "change", "select", "blur", "remove", "removeAll"],
13026
+ setup(props, {
13027
+ emit
13028
+ }) {
13029
+ const state = vue.reactive({
13030
+ isEdit: false,
13031
+ isHover: false,
13032
+ focusItemIndex: props.allowCreate ? -1 : 0
13033
+ });
13034
+ const popoverProps = vue.reactive({
13035
+ isShow: false,
13036
+ width: 190,
13037
+ modifiers: [{
13038
+ name: "offset",
13039
+ options: {
13040
+ offset: [0, 4]
13041
+ }
13042
+ }]
13043
+ });
13044
+ const {
13045
+ maxResult
13046
+ } = vue.toRefs(props);
13047
+ const {
13048
+ pageState,
13049
+ initPage,
13050
+ pageChange
13051
+ } = usePage(maxResult);
13052
+ const curInputValue = useDebouncedRef("", 150);
13053
+ const tagInputRef = vue.ref(null);
13054
+ const bkTagSelectorRef = vue.ref(null);
13055
+ const tagListRef = vue.ref(null);
13056
+ const tagInputItemRef = vue.ref(null);
13057
+ const selectorListRef = vue.ref(null);
13058
+ const popoverRef = vue.ref(null);
13059
+ const timer = vue.ref(null);
13060
+ const showTagClose = vue.computed(() => !props.disabled && props.hasDeleteIcon);
13061
+ const isSingleSelect = vue.computed(() => props.maxData === 1);
13062
+ const isShowPlaceholder = vue.computed(() => listState.selectedTagList.length === 0 && curInputValue.value === "" && !state.isEdit);
13063
+ const isShowClear = vue.computed(() => props.clearable && !props.disabled && listState.selectedTagList.length !== 0 && (props.showClearOnlyHover ? state.isHover : true));
13064
+ const triggerClass = vue.computed(() => ({
13065
+ "bk-tag-input-trigger": true,
13066
+ active: state.isEdit,
13067
+ disabled: props.disabled
13068
+ }));
13069
+ vue.watch([() => [...props.modelValue], () => [...props.list]], () => {
13070
+ initData();
13071
+ });
13072
+ vue.watch(curInputValue, (value) => {
13073
+ const hasShowCount = pageState.curPageList.length !== 0;
13074
+ if (value !== "" && hasShowCount || value === "" && props.trigger === "focus") {
13075
+ popoverProps.isShow = true;
13076
+ } else if (props.trigger !== "focus" || !hasShowCount) {
13077
+ popoverProps.isShow = false;
13078
+ }
13079
+ });
13080
+ vue.watch(() => popoverProps.isShow, (show) => {
13081
+ changePopoverOffset();
13082
+ if (show) {
13083
+ if (selectorListRef.value) {
13084
+ vue.nextTick(() => {
13085
+ selectorListRef.value.scrollTop = 0;
13086
+ });
13087
+ selectorListRef.value.removeEventListener("scroll", scrollHandler);
13088
+ selectorListRef.value.addEventListener("scroll", scrollHandler);
13089
+ }
13090
+ }
13091
+ });
13092
+ const changePopoverOffset = () => {
13093
+ var _a, _b;
13094
+ const left2 = isSingleSelect.value ? 0 : (_a = tagInputItemRef.value) == null ? void 0 : _a.offsetLeft;
13095
+ popoverProps.modifiers = [{
13096
+ name: "offset",
13097
+ options: {
13098
+ offset: [left2, 4]
13099
+ }
13100
+ }];
13101
+ (_b = popoverRef.value) == null ? void 0 : _b.update();
13102
+ };
13103
+ const scrollHandler = () => {
13104
+ if (pageState.isPageLoading || selectorListRef.value.scrollTop === 0) {
13105
+ return;
13106
+ }
13107
+ const {
13108
+ scrollTop,
13109
+ offsetHeight,
13110
+ scrollHeight
13111
+ } = selectorListRef.value;
13112
+ if (scrollTop + offsetHeight >= scrollHeight) {
13113
+ const curPage = pageState.curPage + 1;
13114
+ if (curPage <= pageState.totalPage) {
13115
+ pageState.isPageLoading = true;
13116
+ setTimeout(() => {
13117
+ pageChange(curPage);
13118
+ }, 500);
13119
+ }
13120
+ }
13121
+ };
13122
+ const getSelectedTagNodes = () => {
13123
+ var _a;
13124
+ const nodes = Array.from(((_a = tagListRef.value) == null ? void 0 : _a.childNodes) || []);
13125
+ return nodes.filter((node) => node.nodeType !== Node.TEXT_NODE);
13126
+ };
13127
+ const focusInputTrigger = (e) => {
13128
+ if (props.disabled)
13129
+ return;
13130
+ if (e == null ? void 0 : e.target) {
13131
+ const {
13132
+ className
13133
+ } = e.target;
13134
+ if (className.indexOf("bk-tag-input-trigger") > -1 || className.indexOf("tag-list") > -1) {
13135
+ tagListRef.value.appendChild(tagInputItemRef.value);
13136
+ }
13137
+ }
13138
+ clearTimeout(timer.value);
13139
+ if (isSingleSelect.value && tagList.value.length) {
13140
+ listState.tagListCache = [...tagList.value];
13141
+ listState.selectedTagListCache = [...listState.selectedTagList];
13142
+ curInputValue.value = listState.selectedTagListCache[0][props.saveKey];
13143
+ removeTag(listState.selectedTagList[0], 0);
13144
+ handleInput();
13145
+ }
13146
+ state.isEdit = true;
13147
+ vue.nextTick(() => {
13148
+ var _a;
13149
+ (_a = tagInputRef.value) == null ? void 0 : _a.focus();
13150
+ if (props.trigger === "focus" && listState.localList.length !== 0) {
13151
+ filterData();
13152
+ if (popoverProps.isShow) {
13153
+ changePopoverOffset();
13154
+ } else {
13155
+ popoverProps.isShow = true;
13156
+ }
13157
+ }
13158
+ });
13159
+ };
13160
+ const listState = vue.reactive({
13161
+ localList: [],
13162
+ tagListCache: [],
13163
+ selectedTagList: [],
13164
+ selectedTagListCache: []
13165
+ });
13166
+ const tagList = vue.computed(() => listState.selectedTagList.map((tag2) => tag2[props.saveKey]));
13167
+ const formatList = useFlatList(props);
13168
+ const renderList = vue.computed(() => {
13169
+ if (props.useGroup) {
13170
+ const groupMap = {};
13171
+ pageState.curPageList.forEach((item, index) => {
13172
+ item.__index__ = index;
13173
+ if (!groupMap[item.group.groupId]) {
13174
+ groupMap[item.group.groupId] = {
13175
+ id: item.group.groupId,
13176
+ name: item.group.groupName,
13177
+ children: []
13178
+ };
13179
+ }
13180
+ groupMap[item.group.groupId].children.push(item);
13181
+ });
13182
+ return Object.keys(groupMap).map((key) => groupMap[key]);
13183
+ }
13184
+ return pageState.curPageList;
13185
+ });
13186
+ const initData = () => {
13187
+ const {
13188
+ saveKey,
13189
+ modelValue,
13190
+ displayKey,
13191
+ allowCreate,
13192
+ trigger
13193
+ } = props;
13194
+ listState.selectedTagList = [];
13195
+ listState.localList = [...formatList];
13196
+ if (modelValue.length) {
13197
+ modelValue.forEach((tag2) => {
13198
+ const value = listState.localList.find((val) => tag2 === val[saveKey]);
13199
+ if (value !== void 0) {
13200
+ listState.selectedTagList.push(value);
13201
+ } else if (allowCreate && !tagList.value.includes(tag2)) {
13202
+ listState.selectedTagList.push({
13203
+ [saveKey]: tag2,
13204
+ [displayKey]: tag2
13205
+ });
13206
+ }
13207
+ });
13208
+ if (!isSingleSelect.value) {
13209
+ listState.localList = listState.localList.filter((val) => !modelValue.includes(val[saveKey]));
13210
+ }
13211
+ }
13212
+ if (trigger === "focus") {
13213
+ filterData();
13214
+ }
13215
+ };
13216
+ const filterData = (value = "") => {
13217
+ const {
13218
+ searchKey,
13219
+ filterCallback
13220
+ } = props;
13221
+ const lowerCaseValue = value.toLowerCase();
13222
+ let filterData2 = [];
13223
+ if (typeof filterCallback === "function") {
13224
+ filterData2 = filterCallback(lowerCaseValue, searchKey, listState.localList) || [];
13225
+ } else {
13226
+ if (Array.isArray(searchKey)) {
13227
+ const filterDataList = searchKey.map((searchKey2) => listState.localList.filter((item) => item[searchKey2].toLowerCase().indexOf(lowerCaseValue) !== -1));
13228
+ filterData2 = Array.from(new Set(filterDataList.flat()));
13229
+ } else {
13230
+ filterData2 = listState.localList.filter((item) => item[searchKey].toLowerCase().indexOf(lowerCaseValue) !== -1);
13231
+ }
13232
+ }
13233
+ initPage(filterData2);
13234
+ };
13235
+ const activeClass = (data2, index) => {
13236
+ const style = {
13237
+ "bk-selector-actived": false,
13238
+ "bk-selector-selected": tagList.value.includes(data2[props.saveKey])
13239
+ };
13240
+ if (props.useGroup) {
13241
+ style["bk-selector-actived"] = data2.__index__ === state.focusItemIndex;
13242
+ } else {
13243
+ style["bk-selector-actived"] = index === state.focusItemIndex;
13244
+ }
13245
+ return style;
13246
+ };
13247
+ vue.onMounted(() => {
13248
+ initData();
13249
+ });
13250
+ const clearSingleCache = () => {
13251
+ listState.tagListCache = [];
13252
+ listState.selectedTagListCache = [];
13253
+ listState.selectedTagList = [];
13254
+ };
13255
+ const clearInput = () => {
13256
+ curInputValue.value = "";
13257
+ };
13258
+ const getTagInputItemSite = () => {
13259
+ if (isSingleSelect.value) {
13260
+ return 0;
13261
+ }
13262
+ const childNodes = getSelectedTagNodes();
13263
+ const index = childNodes.findIndex(({
13264
+ id
13265
+ }) => id === "tagInputItem");
13266
+ return index >= 0 ? index : 0;
13267
+ };
13268
+ const swapElementPositions = (newNode, referenceNode, isNextElementSibling = false) => {
13269
+ if (!referenceNode || !newNode)
13270
+ return;
13271
+ let swap = referenceNode;
13272
+ if (isNextElementSibling) {
13273
+ swap = referenceNode.nextElementSibling || null;
13274
+ }
13275
+ referenceNode.parentNode.insertBefore(newNode, swap);
13276
+ };
13277
+ const handleInput = (e) => {
13278
+ const {
13279
+ maxData,
13280
+ trigger,
13281
+ allowCreate
13282
+ } = props;
13283
+ if (maxData === -1 || maxData > tagList.value.length) {
13284
+ const {
13285
+ value
13286
+ } = (e == null ? void 0 : e.target) ? e.target : curInputValue;
13287
+ const charLen = getCharLength(value);
13288
+ if (charLen) {
13289
+ filterData(value);
13290
+ tagInputRef.value.style.width = `${charLen * INPUT_MIN_WIDTH}px`;
13291
+ } else {
13292
+ if (trigger === "focus") {
13293
+ filterData();
13294
+ }
13295
+ }
13296
+ } else {
13297
+ handleBlur();
13298
+ curInputValue.value = "";
13299
+ popoverProps.isShow = false;
13300
+ }
13301
+ state.isEdit = true;
13302
+ state.focusItemIndex = allowCreate ? -1 : 0;
13303
+ };
13304
+ const handleFocus = () => {
13305
+ var _a;
13306
+ popoverProps.width = isSingleSelect.value ? (_a = bkTagSelectorRef.value) == null ? void 0 : _a.clientWidth : props.contentWidth;
13307
+ };
13308
+ const handleBlur = () => {
13309
+ timer.value = setTimeout(() => {
13310
+ const inputValue = curInputValue.value;
13311
+ clearInput();
13312
+ state.isEdit = false;
13313
+ if (isSingleSelect.value) {
13314
+ const [oldValue] = listState.tagListCache;
13315
+ if (inputValue && inputValue === oldValue && listState.selectedTagListCache.length) {
13316
+ addTag(listState.selectedTagListCache[0], "select");
13317
+ } else {
13318
+ handleChange("remove");
13319
+ }
13320
+ } else if (props.allowAutoMatch && inputValue) {
13321
+ const matchItem = pageState.curPageList.find((item) => {
13322
+ if (Array.isArray(props.searchKey)) {
13323
+ const searchValue = props.searchKey.map((key) => item[key]);
13324
+ return searchValue.includes(inputValue);
13325
+ }
13326
+ return item[props.searchKey] === inputValue;
13327
+ });
13328
+ if (matchItem) {
13329
+ handleTagSelected(matchItem, "select");
13330
+ } else if (props.allowCreate) {
13331
+ handleTagSelected(inputValue, "custom");
13332
+ }
13333
+ }
13334
+ popoverProps.isShow = false;
13335
+ emit("blur", inputValue, tagList.value);
13336
+ }, 50);
13337
+ };
13338
+ const handleTagSelected = (item, type, e) => {
13339
+ e == null ? void 0 : e.stopPropagation();
13340
+ if (!item || item.disabled) {
13341
+ return;
13342
+ }
13343
+ if (isSingleSelect.value) {
13344
+ clearSingleCache();
13345
+ }
13346
+ addTag(item, type);
13347
+ handleChange("select");
13348
+ clearInput();
13349
+ popoverProps.isShow = false;
13350
+ };
13351
+ const handleTagRemove = (data2, index, e) => {
13352
+ e == null ? void 0 : e.stopPropagation();
13353
+ removeTag(data2, index);
13354
+ clearInput();
13355
+ handleChange("remove");
13356
+ tagInputRef.value.style.width = `${INPUT_MIN_WIDTH}px`;
13357
+ };
13358
+ const handleChange = (type) => {
13359
+ emit("change", tagList.value);
13360
+ emit(type);
13361
+ emit("update:modelValue", tagList.value);
13362
+ };
13363
+ const handleClear = (e) => {
13364
+ e.stopPropagation();
13365
+ const removeList = listState.selectedTagList;
13366
+ listState.selectedTagList = [];
13367
+ const existList = formatList.filter((item) => removeList.some((removeItem) => removeItem[props.saveKey] === item[props.saveKey]));
13368
+ if ((props.allowCreate && existList.length !== 0 || !props.allowCreate) && !isSingleSelect.value) {
13369
+ listState.localList.push(...existList);
13370
+ }
13371
+ handleChange("removeAll");
13372
+ };
13373
+ const updateScrollTop = () => {
13374
+ const panelInfo = {
13375
+ height: selectorListRef.value.clientHeight,
13376
+ yAxis: selectorListRef.value.getBoundingClientRect().y
13377
+ };
13378
+ vue.nextTick(() => {
13379
+ const activeObj = selectorListRef.value.querySelector(".bk-selector-actived");
13380
+ if (!activeObj) {
13381
+ return;
13382
+ }
13383
+ const activeInfo = {
13384
+ height: activeObj.clientHeight,
13385
+ yAxis: activeObj.getBoundingClientRect().y
13386
+ };
13387
+ if (activeInfo.yAxis < panelInfo.yAxis) {
13388
+ selectorListRef.value.scrollTop = selectorListRef.value.scrollTop - (panelInfo.yAxis - activeInfo.yAxis);
13389
+ }
13390
+ const distanceToBottom = activeInfo.yAxis + activeInfo.height - panelInfo.yAxis;
13391
+ if (distanceToBottom > panelInfo.height) {
13392
+ selectorListRef.value.scrollTop = selectorListRef.value.scrollTop + distanceToBottom - panelInfo.height;
13393
+ }
13394
+ });
13395
+ };
13396
+ const backspaceHandler = (index, target) => {
13397
+ const nodes = getSelectedTagNodes();
13398
+ swapElementPositions(tagInputItemRef.value, nodes[index - 1]);
13399
+ listState.selectedTagList.splice(index - 1, 1);
13400
+ focusInputTrigger();
13401
+ const isExistInit = formatList.some((item) => item === target[props.saveKey]);
13402
+ if ((props.allowCreate && isExistInit || !props.allowCreate) && !isSingleSelect.value) {
13403
+ listState.localList.push(target);
13404
+ }
13405
+ tagInputRef.value = `${INPUT_MIN_WIDTH}px`;
13406
+ handleChange("remove");
13407
+ };
13408
+ const handleKeydown = (e) => {
13409
+ if (pageState.isPageLoading) {
13410
+ return;
13411
+ }
13412
+ let target;
13413
+ const val = e.target.value;
13414
+ const valLen = getCharLength(val);
13415
+ const tagInputItemIndex = getTagInputItemSite();
13416
+ const nodes = getSelectedTagNodes();
13417
+ switch (e.code) {
13418
+ case "ArrowUp":
13419
+ e.preventDefault();
13420
+ if (!popoverProps.isShow) {
13421
+ return;
13422
+ }
13423
+ state.focusItemIndex = state.focusItemIndex - 1;
13424
+ state.focusItemIndex = state.focusItemIndex < 0 ? -1 : state.focusItemIndex;
13425
+ if (state.focusItemIndex === -1) {
13426
+ state.focusItemIndex = pageState.curPageList.length - 1;
13427
+ }
13428
+ updateScrollTop();
13429
+ break;
13430
+ case "ArrowDown":
13431
+ e.preventDefault();
13432
+ if (!popoverProps.isShow) {
13433
+ return;
13434
+ }
13435
+ state.focusItemIndex = state.focusItemIndex + 1;
13436
+ state.focusItemIndex = state.focusItemIndex > pageState.curPageList.length - 1 ? pageState.curPageList.length : state.focusItemIndex;
13437
+ if (state.focusItemIndex === pageState.curPageList.length) {
13438
+ state.focusItemIndex = 0;
13439
+ }
13440
+ updateScrollTop();
13441
+ break;
13442
+ case "ArrowLeft":
13443
+ state.isEdit = true;
13444
+ if (!valLen) {
13445
+ if (tagInputItemIndex < 1) {
13446
+ return;
13447
+ }
13448
+ swapElementPositions(tagInputItemRef.value, nodes[tagInputItemIndex - 1]);
13449
+ focusInputTrigger();
13450
+ }
13451
+ break;
13452
+ case "ArrowRight":
13453
+ state.isEdit = true;
13454
+ if (!valLen) {
13455
+ if (tagInputItemIndex === nodes.length - 1) {
13456
+ return;
13457
+ }
13458
+ swapElementPositions(nodes[tagInputItemIndex + 1], tagInputItemRef.value);
13459
+ focusInputTrigger();
13460
+ }
13461
+ break;
13462
+ case "Enter":
13463
+ case "NumpadEnter":
13464
+ if (!props.allowCreate && popoverProps.isShow || props.allowCreate && state.focusItemIndex >= 0 && popoverProps.isShow) {
13465
+ handleTagSelected(pageState.curPageList[state.focusItemIndex], "select", e);
13466
+ } else if (props.allowCreate) {
13467
+ handleTagSelected(curInputValue.value, "custom", e);
13468
+ }
13469
+ e.preventDefault();
13470
+ break;
13471
+ case "Backspace":
13472
+ if (tagInputItemIndex !== 0 && !curInputValue.value) {
13473
+ target = listState.selectedTagList[tagInputItemIndex - 1];
13474
+ backspaceHandler(tagInputItemIndex, target);
13475
+ }
13476
+ break;
13477
+ }
13478
+ };
13479
+ const defaultPasteFn = (value) => {
13480
+ const target = [];
13481
+ const textArr = value.split(";");
13482
+ textArr.forEach((item) => {
13483
+ if (item.match(/^[a-zA-Z][a-zA-Z_]+/g)) {
13484
+ const finalItem = item.match(/^[a-zA-Z][a-zA-Z_]+/g).join("");
13485
+ target.push({
13486
+ [props.saveKey]: finalItem,
13487
+ [props.displayKey]: finalItem
13488
+ });
13489
+ }
13490
+ });
13491
+ return target;
13492
+ };
13493
+ const handlePaste = (e) => {
13494
+ e.preventDefault();
13495
+ if (isSingleSelect.value) {
13496
+ return false;
13497
+ }
13498
+ const {
13499
+ maxData,
13500
+ saveKey,
13501
+ pasteFn
13502
+ } = props;
13503
+ const value = e.clipboardData.getData("text");
13504
+ const valArr = pasteFn ? pasteFn(value) : defaultPasteFn(value);
13505
+ let tags = valArr.map((value2) => value2[saveKey]);
13506
+ if (tags.length) {
13507
+ const nodes = getSelectedTagNodes();
13508
+ const index = getTagInputItemSite();
13509
+ const localInitData = listState.localList.map((data2) => data2[saveKey]);
13510
+ tags = tags.filter((tag2) => (tag2 == null ? void 0 : tag2.trim()) && !tagList.value.includes(tag2) && localInitData.includes(tag2));
13511
+ if (maxData !== -1) {
13512
+ const selectedLength = listState.selectedTagList.length;
13513
+ if (selectedLength < maxData) {
13514
+ const differ = maxData - selectedLength;
13515
+ if (tags.length > differ) {
13516
+ tags = [...tags.slice(0, differ)];
13517
+ }
13518
+ } else {
13519
+ tags = [];
13520
+ }
13521
+ }
13522
+ const localTags = listState.localList.filter((tag2) => tags.includes(tag2[saveKey]));
13523
+ if (tags.length) {
13524
+ listState.selectedTagList.splice(index, 0, ...localTags);
13525
+ swapElementPositions(tagInputItemRef.value, nodes[index]);
13526
+ tagInputRef.value.style.width = `${INPUT_MIN_WIDTH}px`;
13527
+ listState.localList = listState.localList.filter((val) => !tags.includes(val[saveKey]));
13528
+ handleChange("select");
13529
+ focusInputTrigger();
13530
+ }
13531
+ }
13532
+ };
13533
+ const tagFocus = (e) => {
13534
+ if (props.disabled) {
13535
+ return;
13536
+ }
13537
+ swapElementPositions(tagInputItemRef.value, e.currentTarget, true);
13538
+ tagInputRef.value.style.width = `${INPUT_MIN_WIDTH}px`;
13539
+ popoverProps.isShow && changePopoverOffset();
13540
+ };
13541
+ const addTag = (item, type) => {
13542
+ if (listState.selectedTagList.length >= props.maxData && props.maxData !== -1)
13543
+ return;
13544
+ const {
13545
+ separator,
13546
+ saveKey,
13547
+ displayKey,
13548
+ createTagValidator
13549
+ } = props;
13550
+ const targetIndex = getTagInputItemSite();
13551
+ let moveCount = 1;
13552
+ let isSelected = false;
13553
+ let newValue;
13554
+ const validateTag = (value) => {
13555
+ if (typeof createTagValidator === "function") {
13556
+ return createTagValidator(value);
13557
+ }
13558
+ return true;
13559
+ };
13560
+ const existTag = (value) => listState.localList.find((tag2) => tag2[saveKey] === value);
13561
+ if (type === "custom") {
13562
+ if (separator) {
13563
+ let tags = item.split(separator);
13564
+ tags = tags.filter((tag2) => (tag2 == null ? void 0 : tag2.trim()) && !tagList.value.includes(tag2) && validateTag(tag2));
13565
+ const localTags = tags.map((tag2) => existTag(tag2) || {
13566
+ [saveKey]: tag2,
13567
+ [displayKey]: tag2
13568
+ });
13569
+ if (tags.length) {
13570
+ listState.selectedTagList.splice(targetIndex, 0, ...localTags);
13571
+ moveCount = localTags.length;
13572
+ isSelected = true;
13573
+ }
13574
+ } else {
13575
+ const isObject2 = typeof item === "object";
13576
+ newValue = isObject2 ? item[saveKey] : item.trim();
13577
+ newValue = newValue.replace(/\s+/g, "");
13578
+ if (newValue !== void 0 && !tagList.value.includes(newValue) && validateTag(newValue)) {
13579
+ const localItem = existTag(newValue) || (isObject2 ? item : {
13580
+ [saveKey]: newValue,
13581
+ [displayKey]: newValue
13582
+ });
13583
+ listState.selectedTagList.splice(targetIndex, 0, localItem);
13584
+ isSelected = true;
13585
+ }
13586
+ }
13587
+ } else if (item) {
13588
+ newValue = item[saveKey];
13589
+ if (newValue !== void 0 && !tagList.value.includes(newValue)) {
13590
+ listState.selectedTagList.splice(targetIndex, 0, item);
13591
+ isSelected = true;
13592
+ }
13593
+ }
13594
+ if (isSelected) {
13595
+ vue.nextTick(() => {
13596
+ for (let count = 1; count <= moveCount; count++) {
13597
+ const nodes = getSelectedTagNodes();
13598
+ const site = nodes[targetIndex + count];
13599
+ swapElementPositions(site, tagInputItemRef.value);
13600
+ }
13601
+ tagInputRef.value.style.width = `${INPUT_MIN_WIDTH}px`;
13602
+ if (!isSingleSelect.value) {
13603
+ props.allowNextFocus && focusInputTrigger();
13604
+ listState.localList = listState.localList.filter((val) => !tagList.value.includes(val[saveKey]));
13605
+ }
13606
+ });
13607
+ }
13608
+ };
13609
+ const removeTag = (data2, index) => {
13610
+ listState.selectedTagList.splice(index, 1);
13611
+ const isExistInit = formatList.some((item) => item === data2[props.saveKey]);
13612
+ if ((props.allowCreate && isExistInit || !props.allowCreate) && !isSingleSelect.value) {
13613
+ listState.localList.push(data2);
13614
+ }
13615
+ };
13616
+ return __spreadProps(__spreadValues(__spreadValues(__spreadValues({
13617
+ popoverProps
13618
+ }, vue.toRefs(state)), vue.toRefs(listState)), vue.toRefs(pageState)), {
13619
+ isShowPlaceholder,
13620
+ isShowClear,
13621
+ curInputValue,
13622
+ formatList,
13623
+ renderList,
13624
+ showTagClose,
13625
+ tagInputRef,
13626
+ bkTagSelectorRef,
13627
+ tagListRef,
13628
+ tagInputItemRef,
13629
+ selectorListRef,
13630
+ popoverRef,
13631
+ triggerClass,
13632
+ focusInputTrigger,
13633
+ activeClass,
13634
+ handleInput,
13635
+ handleFocus,
13636
+ handleBlur,
13637
+ handleTagSelected,
13638
+ handleTagRemove,
13639
+ handleClear,
13640
+ tagFocus,
13641
+ handleKeydown,
13642
+ handlePaste
13643
+ });
13644
+ },
13645
+ render() {
13646
+ const renderSelectorList = () => {
13647
+ if (this.useGroup) {
13648
+ return this.renderList.map((group) => vue.createVNode("li", {
13649
+ "class": "bk-selector-group-item"
13650
+ }, [vue.createVNode("span", {
13651
+ "class": "group-name"
13652
+ }, [group.name, vue.createTextVNode(" ("), group.children.length, vue.createTextVNode(")")]), vue.createVNode("ul", {
13653
+ "class": "bk-selector-group-list-item"
13654
+ }, [group.children.map((item, index) => vue.createVNode("li", {
13655
+ "class": ["bk-selector-list-item", {
13656
+ disabled: item.disabled
13657
+ }, this.activeClass(item, index)],
13658
+ "onClick": this.handleTagSelected.bind(this, item, "select")
13659
+ }, [vue.createVNode(ListTagRender, {
13660
+ "node": item,
13661
+ "displayKey": this.displayKey,
13662
+ "tpl": this.tpl,
13663
+ "searchKey": this.searchKey,
13664
+ "searchKeyword": this.curInputValue
13665
+ }, null)]))])]));
13666
+ }
13667
+ return this.renderList.map((item, index) => vue.createVNode("li", {
13668
+ "class": ["bk-selector-list-item", {
13669
+ disabled: item.disabled
13670
+ }, this.activeClass(item, index)],
13671
+ "onClick": this.handleTagSelected.bind(this, item, "select")
13672
+ }, [vue.createVNode(ListTagRender, {
13673
+ "node": item,
13674
+ "displayKey": this.displayKey,
13675
+ "tpl": this.tpl,
13676
+ "searchKey": this.searchKey,
13677
+ "searchKeyword": this.curInputValue
13678
+ }, null)]));
13679
+ };
13680
+ return vue.createVNode("div", {
13681
+ "class": "bk-tag-input",
13682
+ "ref": "bkTagSelectorRef",
13683
+ "onClick": this.focusInputTrigger,
13684
+ "onMouseenter": () => this.isHover = true,
13685
+ "onMouseleave": () => this.isHover = false
13686
+ }, [vue.createVNode(BkPopover, {
13687
+ "ref": "popoverRef",
13688
+ "theme": "light",
13689
+ "trigger": "manual",
13690
+ "placement": "bottom-start",
13691
+ "arrow": false,
13692
+ "width": this.popoverProps.width,
13693
+ "isShow": this.popoverProps.isShow,
13694
+ "modifiers": this.popoverProps.modifiers
13695
+ }, {
13696
+ default: () => vue.createVNode("div", {
13697
+ "class": this.triggerClass
13698
+ }, [vue.createVNode("ul", {
13699
+ "class": "tag-list",
13700
+ "ref": "tagListRef",
13701
+ "style": {
13702
+ marginLeft: `${this.leftSpace}px`
13703
+ }
13704
+ }, [this.selectedTagList.map((item, index) => {
13705
+ const tooltips2 = {
13706
+ boundary: "window",
13707
+ theme: "light",
13708
+ distance: 12,
13709
+ content: item[this.tooltipKey],
13710
+ disabled: !this.tooltipKey
13711
+ };
13712
+ return vue.withDirectives(vue.createVNode("li", {
13713
+ "class": "tag-item",
13714
+ "onClick": this.tagFocus
13715
+ }, [vue.createVNode(TagRender, {
13716
+ "node": item,
13717
+ "tpl": this.tagTpl,
13718
+ "displayKey": this.displayKey
13719
+ }, null), this.showTagClose ? vue.createVNode(error, {
13720
+ "class": "remove-tag",
13721
+ "onClick": this.handleTagRemove.bind(this, item, index)
13722
+ }, null) : null]), [[vue.resolveDirective("bk-tooltips"), tooltips2]]);
13723
+ }), vue.withDirectives(vue.createVNode("li", {
13724
+ "ref": "tagInputItemRef",
13725
+ "id": "tagInputItem",
13726
+ "class": "tag-input-item",
13727
+ "role": "input"
13728
+ }, [vue.withDirectives(vue.createVNode("input", {
13729
+ "type": "text",
13730
+ "class": "tag-input",
13731
+ "ref": "tagInputRef",
13732
+ "onUpdate:modelValue": ($event) => this.curInputValue = $event,
13733
+ "onInput": this.handleInput,
13734
+ "onFocus": this.handleFocus,
13735
+ "onBlur": this.handleBlur,
13736
+ "onKeydown": this.handleKeydown,
13737
+ "onPaste": this.handlePaste
13738
+ }, null), [[vue.vModelText, this.curInputValue]])]), [[vue.vShow, this.isEdit]])]), vue.withDirectives(vue.createVNode("p", {
13739
+ "class": "placeholder"
13740
+ }, [this.placeholder]), [[vue.vShow, this.isShowPlaceholder]]), this.isShowClear ? vue.createVNode(close$1, {
13741
+ "class": "clear-icon",
13742
+ "onClick": this.handleClear
13743
+ }, null) : null]),
13744
+ content: () => vue.createVNode("div", {
13745
+ "class": "bk-selector-list"
13746
+ }, [vue.createVNode("ul", {
13747
+ "ref": "selectorListRef",
13748
+ "style": {
13749
+ "max-height": `${this.contentMaxHeight}px`
13750
+ },
13751
+ "class": "outside-ul"
13752
+ }, [renderSelectorList(), this.isPageLoading ? vue.createVNode("li", {
13753
+ "class": "bk-selector-list-item loading"
13754
+ }, [vue.createVNode(BkLoading, {
13755
+ "theme": "primary",
13756
+ "size": BkLoadingSize.Small
13757
+ }, null)]) : null])])
13758
+ })]);
13759
+ }
13760
+ });
13761
+ TagInput.install = (Vue) => {
13762
+ Vue.component(TagInput.name, TagInput);
13763
+ };
12830
13764
  var bkDivider = vue.defineComponent({
12831
13765
  name: "Divider",
12832
13766
  props: {
@@ -18468,35 +19402,41 @@ const getFlatdata = (props, treeData = void 0, cachedSchema = []) => {
18468
19402
  const outputData = [];
18469
19403
  let order2 = 0;
18470
19404
  const schema = /* @__PURE__ */ new Map();
18471
- function isCachedTreeNodeOpened(uuid2, node) {
19405
+ function getCachedTreeNodeAttr(uuid2, node, attr, cachedAttr) {
18472
19406
  const cached = (cachedSchema || []).find((item) => item.__uuid === uuid2);
18473
19407
  if (cached) {
18474
- return cached.__isOpen;
19408
+ return cached[cachedAttr];
18475
19409
  }
18476
- return node.isOpen;
19410
+ return node[attr];
19411
+ }
19412
+ function isCachedTreeNodeOpened(uuid2, node) {
19413
+ return getCachedTreeNodeAttr(uuid2, node, "isOpen", "__isOpen");
19414
+ }
19415
+ function isCachedTreeNodeChecked(uuid2, node) {
19416
+ return getCachedTreeNodeAttr(uuid2, node, "checked", "__checked");
18477
19417
  }
18478
19418
  function flatten(array, depth = 0, parent = null, path = null) {
18479
- for (let i2 = 0; i2 < array.length; i2++) {
19419
+ const arrLength = array.length;
19420
+ for (let i2 = 0; i2 < arrLength; i2++) {
18480
19421
  const item = array[i2];
18481
19422
  if (Array.isArray(item)) {
18482
19423
  flatten(item, depth, parent, path);
18483
19424
  } else {
18484
19425
  if (typeof item === "object" && item !== null) {
18485
19426
  const uuid2 = item.__uuid || uuid_1.v4();
18486
- const isOpen = isCachedTreeNodeOpened(uuid2, item);
18487
19427
  const currentPath = path !== null ? `${path}-${i2}` : `${i2}`;
19428
+ const hasChildren = !!(item[children] || []).length;
18488
19429
  const attrs = {
18489
19430
  __depth: depth,
18490
19431
  __index: i2,
18491
19432
  __uuid: uuid2,
18492
19433
  __parentId: parent,
18493
- __parentPath: path,
18494
- __hasChild: !!(item[children] || []).length,
19434
+ __hasChild: hasChildren,
18495
19435
  __path: currentPath,
18496
19436
  __isRoot: parent === null,
18497
19437
  __order: order2,
18498
- __isOpen: isOpen,
18499
- __checked: !!item.checked,
19438
+ __isOpen: isCachedTreeNodeOpened(uuid2, item) && hasChildren,
19439
+ __checked: isCachedTreeNodeChecked(uuid2, item),
18500
19440
  [children]: null
18501
19441
  };
18502
19442
  Object.assign(item, { __uuid: uuid2 });
@@ -19182,6 +20122,7 @@ var components = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProp
19182
20122
  Switcher: BkSwitcher,
19183
20123
  Table: BkTable,
19184
20124
  Tag: BkTag,
20125
+ TagInput,
19185
20126
  Divider: BkDivider,
19186
20127
  Tab: BKTab,
19187
20128
  TabPanel: BKTabPanel,
@@ -19256,6 +20197,7 @@ exports.Tab = BKTab;
19256
20197
  exports.TabPanel = BKTabPanel;
19257
20198
  exports.Table = BkTable;
19258
20199
  exports.Tag = BkTag;
20200
+ exports.TagInput = TagInput;
19259
20201
  exports.Transfer = Transfer;
19260
20202
  exports.Tree = BkTree;
19261
20203
  exports.VirtualRender = BkVirtualRender;