@chaoswise/business 0.0.6 → 0.0.8
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/lib/AggregateSearch/CLSPL/CLQLLexer.js +80 -0
- package/lib/AggregateSearch/CLSPL/CLQLParser.js +2797 -0
- package/lib/AggregateSearch/CLSPL/CLQLParserListener.js +349 -0
- package/lib/AggregateSearch/CLSPL/CLQLParserVisitor.js +253 -0
- package/lib/AggregateSearch/CLSPL/SPLStagy.js +189 -0
- package/lib/AggregateSearch/CLSPL/index.js +176 -0
- package/lib/AggregateSearch/CLSPL/makeTokenizeFn.js +18 -0
- package/lib/AggregateSearch/CLSPL/token.js +7 -0
- package/lib/AggregateSearch/components/DropDown/assets/combined.svg +22 -0
- package/lib/AggregateSearch/components/DropDown/assets/copy.svg +22 -0
- package/lib/AggregateSearch/components/DropDown/assets/delete.svg +24 -0
- package/lib/AggregateSearch/components/DropDown/assets/home.svg +20 -0
- package/lib/AggregateSearch/components/DropDown/assets/key.svg +21 -0
- package/lib/AggregateSearch/components/DropDown/assets/star.svg +22 -0
- package/lib/AggregateSearch/components/DropDown/assets/time-circle.svg +20 -0
- package/lib/AggregateSearch/components/DropDown/assets/value.svg +23 -0
- package/lib/AggregateSearch/components/DropDown/index.js +556 -0
- package/lib/AggregateSearch/components/DropDown/index.less +102 -0
- package/lib/AggregateSearch/components/SwitchBtn/assets/tag-icon.svg +17 -0
- package/lib/AggregateSearch/components/SwitchBtn/assets/text-icon.svg +18 -0
- package/lib/AggregateSearch/components/SwitchBtn/index.js +24 -0
- package/lib/AggregateSearch/components/SwitchBtn/index.less +15 -0
- package/lib/AggregateSearch/hooks/useDropDown.js +399 -0
- package/lib/AggregateSearch/index.js +350 -0
- package/lib/AggregateSearch/index.less +123 -0
- package/lib/AggregateSearch/utils/index.js +362 -0
- package/lib/PropertyControlViewer/assets/doSelect.less +1 -1
- package/lib/PropertyControlViewer/assets/index.less +3 -3
- package/lib/PropertyControlViewer/components/DoCiUnitBitmap.js +1 -1
- package/lib/PropertyControlViewer/components/DoDefaultPlaceholder.js +1 -1
- package/lib/PropertyControlViewer/components/DoUser.js +4 -4
- package/lib/PropertyControlViewer/components/TagShowMoreList/index.js +1 -1
- package/lib/PropertyControlViewer/config/utils.js +5 -4
- package/lib/PropertyControlViewer/index.js +77 -76
- package/lib/PropertyControlViewer/index.less +30 -0
- package/lib/index.js +2 -1
- package/package.json +5 -3
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<svg width="16px" height="10px" viewBox="0 0 16 10" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
3
|
+
<title>形状</title>
|
|
4
|
+
<g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" fill-opacity="0.85">
|
|
5
|
+
<g id="聚合搜索框" transform="translate(-1310.000000, -277.000000)" fill="#000000" fill-rule="nonzero">
|
|
6
|
+
<g id="1" transform="translate(120.000000, 230.000000)">
|
|
7
|
+
<g id="搜索框" transform="translate(0.000000, 38.000000)">
|
|
8
|
+
<g id="编组-25备份" transform="translate(1180.000000, 0.000000)">
|
|
9
|
+
<g id="编组-9" transform="translate(10.000000, 6.000000)">
|
|
10
|
+
<path d="M5.08002268,3.66666666 C4.85170706,3.44444445 4.50923361,3.44444445 4.28091799,3.66666666 L0.171236715,7.55555555 C-0.057078905,7.77777777 -0.057078905,8.11111112 0.171236715,8.33333333 L4.16676018,12.2222222 C4.3950758,12.4444444 4.73754926,12.4444444 4.96586488,12.2222222 C5.1941805,12 5.1941805,11.6666667 4.96586488,11.4444444 L1.42697266,8 L5.08002268,4.44444444 C5.1941805,4.22222222 5.1941805,3.88888888 5.08002268,3.66666666 Z M9.18970396,3.66666666 C8.96138834,3.66666666 8.61891489,3.77777778 8.50475709,4.11111111 L6.44991645,11.6666667 C6.33575863,12 6.56407426,12.2222222 6.9065477,12.3333333 C7.24902114,12.4444444 7.47733678,12.2222222 7.59149458,11.8888889 L9.64633522,4.33333332 C9.76049304,4.11111111 9.5321774,3.77777776 9.18970396,3.66666666 L9.18970396,3.66666666 Z M15.925015,7.55555555 L11.9294915,3.66666666 C11.7011759,3.44444445 11.3587024,3.44444445 11.1303868,3.66666666 C10.9020712,3.88888888 10.9020712,4.22222222 11.1303868,4.44444444 L14.669279,8 L11.016229,11.5555556 C10.7879134,11.7777778 10.7879134,12.1111111 11.016229,12.3333333 C11.2445446,12.5555556 11.5870181,12.5555556 11.8153337,12.3333333 L15.8108571,8.44444445 C16.0391728,8.22222223 16.0391728,7.77777778 15.925015,7.55555555 Z" id="形状"></path>
|
|
11
|
+
</g>
|
|
12
|
+
</g>
|
|
13
|
+
</g>
|
|
14
|
+
</g>
|
|
15
|
+
</g>
|
|
16
|
+
</g>
|
|
17
|
+
</svg>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<svg width="14px" height="12px" viewBox="0 0 14 12" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
3
|
+
<title>filter</title>
|
|
4
|
+
<g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
|
5
|
+
<g id="聚合搜索框" transform="translate(-1311.000000, -2572.000000)" fill="#000000">
|
|
6
|
+
<g id="6" transform="translate(120.000000, 2436.000000)">
|
|
7
|
+
<g id="搜索框" transform="translate(0.000000, 90.000000)">
|
|
8
|
+
<g id="编组-25" transform="translate(1180.000000, 38.000000)">
|
|
9
|
+
<g id="编组" transform="translate(10.000000, 6.000000)">
|
|
10
|
+
<rect id="矩形" fill-rule="nonzero" opacity="0" x="0" y="0" width="16" height="16"></rect>
|
|
11
|
+
<path d="M13.7515625,2.40625 L2.2484375,2.40625 C1.865625,2.40625 1.6265625,2.8234375 1.81875,3.15625 L5.453125,9.334375 L5.453125,13.09375 C5.453125,13.3703125 5.675,13.59375 5.95,13.59375 L10.05,13.59375 C10.325,13.59375 10.546875,13.3703125 10.546875,13.09375 L10.546875,9.334375 L14.1828125,3.15625 C14.3734375,2.8234375 14.134375,2.40625 13.7515625,2.40625 Z M9.428125,12.46875 L6.571875,12.46875 L6.571875,10.03125 L9.4296875,10.03125 L9.4296875,12.46875 L9.428125,12.46875 Z M9.578125,8.771875 L9.4296875,9.03125 L6.5703125,9.03125 L6.421875,8.771875 L3.3234375,3.53125 L12.6765625,3.53125 L9.578125,8.771875 Z" id="形状" fill-opacity="0.85"></path>
|
|
12
|
+
</g>
|
|
13
|
+
</g>
|
|
14
|
+
</g>
|
|
15
|
+
</g>
|
|
16
|
+
</g>
|
|
17
|
+
</g>
|
|
18
|
+
</svg>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import _Tooltip from "@chaoswise/ui/lib/Tooltip";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import textIcon from "./assets/text-icon.svg";
|
|
4
|
+
import tagIcon from "./assets/tag-icon.svg";
|
|
5
|
+
import "./index.less";
|
|
6
|
+
var SwitchBtn = function SwitchBtn(_ref) {
|
|
7
|
+
var mode = _ref.mode,
|
|
8
|
+
onChange = _ref.onChange;
|
|
9
|
+
var icon = mode === "text" ? textIcon : tagIcon;
|
|
10
|
+
var title = mode === "text" ? "切换为手写CQL语法模式" : "切换为筛选模式";
|
|
11
|
+
var onClick = function onClick() {
|
|
12
|
+
onChange(mode === "text" ? "tag" : "text");
|
|
13
|
+
};
|
|
14
|
+
return /*#__PURE__*/React.createElement(_Tooltip, {
|
|
15
|
+
title: title
|
|
16
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
17
|
+
className: "aggregate-search-switch-btn",
|
|
18
|
+
onClick: onClick
|
|
19
|
+
}, /*#__PURE__*/React.createElement("img", {
|
|
20
|
+
src: icon,
|
|
21
|
+
alt: ""
|
|
22
|
+
})));
|
|
23
|
+
};
|
|
24
|
+
export default SwitchBtn;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
.aggregate-search-switch-btn {
|
|
2
|
+
border: @border-width-base @border-style-base @input-border-color;
|
|
3
|
+
border-left: none;
|
|
4
|
+
min-height: 26px;
|
|
5
|
+
cursor: pointer;
|
|
6
|
+
background: rgba(0, 0, 0, 0.02);
|
|
7
|
+
border-radius: 0 2px 2px 0;
|
|
8
|
+
display: flex;
|
|
9
|
+
padding: 0 10px;
|
|
10
|
+
align-items: flex-start;
|
|
11
|
+
align-self: stretch; // 使得高度和父元素一致
|
|
12
|
+
img{
|
|
13
|
+
transform: translateY(7px);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
7
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
10
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
11
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
12
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
+
import React, { useRef, useEffect, useState } from "react";
|
|
14
|
+
import { getCursorPosition, getCursorNodeAndIndex, setCursorPosition, isObjectEqual } from "../utils";
|
|
15
|
+
var MATCH_LIST = [">=", "<=", ">", "<", ":"];
|
|
16
|
+
var useDropDown = function useDropDown(container, handleValueChange) {
|
|
17
|
+
// 记录上一次的tag光标所处的type和value
|
|
18
|
+
var preTagInfo = useRef({});
|
|
19
|
+
|
|
20
|
+
// 下拉列表展示
|
|
21
|
+
var _useState = useState(false),
|
|
22
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
23
|
+
visible = _useState2[0],
|
|
24
|
+
setVisible = _useState2[1];
|
|
25
|
+
var currentPositionIndex = useRef(null);
|
|
26
|
+
var currentPositionValue = useRef(null);
|
|
27
|
+
var curTagIndex = useRef(null);
|
|
28
|
+
var currentValueNodeAndType = useRef({});
|
|
29
|
+
// 搜索内容
|
|
30
|
+
var _useState3 = useState({
|
|
31
|
+
key: {
|
|
32
|
+
isShow: false,
|
|
33
|
+
value: ""
|
|
34
|
+
},
|
|
35
|
+
value: {
|
|
36
|
+
isShow: false,
|
|
37
|
+
value: ""
|
|
38
|
+
},
|
|
39
|
+
match: {
|
|
40
|
+
isShow: false
|
|
41
|
+
},
|
|
42
|
+
combined: {
|
|
43
|
+
isShow: false
|
|
44
|
+
},
|
|
45
|
+
history: {
|
|
46
|
+
isShow: false,
|
|
47
|
+
value: ""
|
|
48
|
+
}
|
|
49
|
+
}),
|
|
50
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
51
|
+
dropStatus = _useState4[0],
|
|
52
|
+
setDropStatus = _useState4[1];
|
|
53
|
+
var isContainMatch = function isContainMatch(str) {
|
|
54
|
+
var reg = new RegExp(/(>=|<=|>|<|:)/);
|
|
55
|
+
if (reg.exec(str)) {
|
|
56
|
+
return reg.exec(str)[0];
|
|
57
|
+
}
|
|
58
|
+
return "";
|
|
59
|
+
};
|
|
60
|
+
var judgeHasNotMatch = function judgeHasNotMatch(str) {
|
|
61
|
+
return str.toLowerCase().includes("not ");
|
|
62
|
+
};
|
|
63
|
+
var getCurrentTag = function getCurrentTag() {
|
|
64
|
+
var _getCursorNodeAndInde = getCursorNodeAndIndex(container.current, currentPositionIndex.current),
|
|
65
|
+
targetNode = _getCursorNodeAndInde.targetNode;
|
|
66
|
+
var targetTag;
|
|
67
|
+
var loop = function loop(node) {
|
|
68
|
+
if (!node) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (node.nodeType === 3) {
|
|
72
|
+
var _node$parentNode$data;
|
|
73
|
+
if (((_node$parentNode$data = node.parentNode.dataset) === null || _node$parentNode$data === void 0 ? void 0 : _node$parentNode$data["attr"]) === "tag-box") {
|
|
74
|
+
targetTag = node.parentNode;
|
|
75
|
+
return;
|
|
76
|
+
} else {
|
|
77
|
+
loop(node.parentNode);
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
var _node$dataset;
|
|
81
|
+
if (((_node$dataset = node.dataset) === null || _node$dataset === void 0 ? void 0 : _node$dataset["attr"]) === "tag-box") {
|
|
82
|
+
targetTag = node;
|
|
83
|
+
return;
|
|
84
|
+
} else {
|
|
85
|
+
loop(node.parentNode);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
loop(targetNode);
|
|
90
|
+
return targetTag;
|
|
91
|
+
};
|
|
92
|
+
var quickSelect = function quickSelect(value, type) {
|
|
93
|
+
var inputStr = container.current.innerText;
|
|
94
|
+
var newStr = inputStr.slice(0, currentPositionIndex.current) + value + inputStr.slice(currentPositionIndex.current);
|
|
95
|
+
var newIndex = currentPositionIndex.current + value.length;
|
|
96
|
+
if (type === "key") {
|
|
97
|
+
// 获取当前tag
|
|
98
|
+
var curTag = getCurrentTag();
|
|
99
|
+
if (curTag) {
|
|
100
|
+
var containMatch = isContainMatch(curTag.innerText);
|
|
101
|
+
var containNot = judgeHasNotMatch(curTag.innerText) ? "NOT " : "";
|
|
102
|
+
if (containMatch) {
|
|
103
|
+
var strArr = curTag.innerText.split(containMatch);
|
|
104
|
+
strArr[0] = "".concat(containNot).concat(value);
|
|
105
|
+
curTag.innerText = strArr.join(containMatch);
|
|
106
|
+
newStr = container.current.innerText;
|
|
107
|
+
newIndex = currentPositionIndex.current - curTagIndex.current + strArr[0].length + containMatch.length;
|
|
108
|
+
} else {
|
|
109
|
+
curTag.innerText = "".concat(containNot).concat(value, ":");
|
|
110
|
+
newStr = container.current.innerText;
|
|
111
|
+
newIndex = currentPositionIndex.current - curTagIndex.current + curTag.innerText.length;
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
newStr = inputStr.slice(0, currentPositionIndex.current) + value + ":" + inputStr.slice(currentPositionIndex.current);
|
|
115
|
+
newIndex = newIndex + 1;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (type === "value") {
|
|
119
|
+
// 处理value 需要替换当前内容
|
|
120
|
+
if (currentValueNodeAndType.current.type === 'value') {
|
|
121
|
+
newIndex = currentPositionIndex.current + value.length - currentValueNodeAndType.current.node.innerText.length + (currentValueNodeAndType.current.node.innerText.length - currentValueNodeAndType.current.offset);
|
|
122
|
+
currentValueNodeAndType.current.node.innerText = value;
|
|
123
|
+
newStr = container.current.innerText;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (value === "NOT:") {
|
|
127
|
+
// 获取当前tag
|
|
128
|
+
var _curTag = getCurrentTag();
|
|
129
|
+
if (_curTag) {
|
|
130
|
+
var curTagText = _curTag.innerText;
|
|
131
|
+
// 正则表达式是否包含 ">= <= > <"
|
|
132
|
+
var reg = new RegExp(/(>=|<=|>|<)/);
|
|
133
|
+
var addNotStr = "NOT ".concat(curTagText.replace(reg, ":"));
|
|
134
|
+
_curTag.innerText = addNotStr;
|
|
135
|
+
newStr = container.current.innerText;
|
|
136
|
+
newIndex = currentPositionIndex.current + (addNotStr.length - curTagText.length);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// 替换 ":"
|
|
141
|
+
if ([">=", "<=", ">", "<", ":"].includes(value)) {
|
|
142
|
+
newStr = inputStr.slice(0, currentPositionIndex.current - currentPositionValue.current.length) + value + inputStr.slice(currentPositionIndex.current);
|
|
143
|
+
newIndex = currentPositionIndex.current + (value.length - currentPositionValue.current.length);
|
|
144
|
+
}
|
|
145
|
+
if (["[]", "()"].includes(value)) {
|
|
146
|
+
newIndex = newIndex - 1;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// 插入字符串下标位置内容
|
|
150
|
+
if (currentPositionIndex.current !== null) {
|
|
151
|
+
handleValueChange(newStr);
|
|
152
|
+
// 光标移动到插入字符串后面
|
|
153
|
+
var _getCursorNodeAndInde2 = getCursorNodeAndIndex(container.current, newIndex),
|
|
154
|
+
targetNode = _getCursorNodeAndInde2.targetNode,
|
|
155
|
+
targetIndex = _getCursorNodeAndInde2.targetIndex;
|
|
156
|
+
// 设置光标位置
|
|
157
|
+
setCursorPosition(targetNode, targetIndex);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// 控制下拉框状态
|
|
161
|
+
setTimeout(function () {
|
|
162
|
+
var _getCurrentKeyAndValu = getCurrentKeyAndValue(),
|
|
163
|
+
key = _getCurrentKeyAndValu.key,
|
|
164
|
+
value = _getCurrentKeyAndValu.value;
|
|
165
|
+
if (type === "match") {
|
|
166
|
+
setDropStatus(function (pre) {
|
|
167
|
+
return _objectSpread(_objectSpread({}, pre), {}, {
|
|
168
|
+
key: {
|
|
169
|
+
isShow: false
|
|
170
|
+
},
|
|
171
|
+
value: {
|
|
172
|
+
isShow: true,
|
|
173
|
+
value: {
|
|
174
|
+
key: key,
|
|
175
|
+
value: value
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
match: {
|
|
179
|
+
isShow: false
|
|
180
|
+
},
|
|
181
|
+
combined: {
|
|
182
|
+
isShow: true
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
if (type === "value") {
|
|
188
|
+
// 选择完value,关闭弹窗
|
|
189
|
+
setVisible(false);
|
|
190
|
+
}
|
|
191
|
+
if (type === "key") {
|
|
192
|
+
setDropStatus(function (pre) {
|
|
193
|
+
return _objectSpread(_objectSpread({}, pre), {}, {
|
|
194
|
+
key: {
|
|
195
|
+
isShow: false
|
|
196
|
+
},
|
|
197
|
+
value: {
|
|
198
|
+
isShow: true,
|
|
199
|
+
value: {
|
|
200
|
+
key: key,
|
|
201
|
+
value: ''
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
match: {
|
|
205
|
+
isShow: true
|
|
206
|
+
},
|
|
207
|
+
combined: {
|
|
208
|
+
isShow: true
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
};
|
|
215
|
+
var onHistorySelect = function onHistorySelect(value) {
|
|
216
|
+
handleValueChange(value);
|
|
217
|
+
// 光标移动到插入字符串后面
|
|
218
|
+
var _getCursorNodeAndInde3 = getCursorNodeAndIndex(container.current, value.length),
|
|
219
|
+
targetNode = _getCursorNodeAndInde3.targetNode,
|
|
220
|
+
targetIndex = _getCursorNodeAndInde3.targetIndex;
|
|
221
|
+
// 设置光标位置
|
|
222
|
+
setCursorPosition(targetNode, targetIndex);
|
|
223
|
+
|
|
224
|
+
// 关闭弹窗
|
|
225
|
+
setTimeout(function () {
|
|
226
|
+
setVisible(false);
|
|
227
|
+
});
|
|
228
|
+
};
|
|
229
|
+
var judgeHasMatch = function judgeHasMatch(str) {
|
|
230
|
+
return MATCH_LIST.find(function (match) {
|
|
231
|
+
return str.includes(match);
|
|
232
|
+
});
|
|
233
|
+
};
|
|
234
|
+
var getCurrentKeyAndValue = function getCurrentKeyAndValue() {
|
|
235
|
+
var curTag = getCurrentTag();
|
|
236
|
+
var hasMatch = judgeHasMatch(curTag === null || curTag === void 0 ? void 0 : curTag.innerText);
|
|
237
|
+
var key;
|
|
238
|
+
var value;
|
|
239
|
+
if (hasMatch) {
|
|
240
|
+
var strArr = curTag.innerText.split(hasMatch);
|
|
241
|
+
key = judgeHasNotMatch(strArr[0]) ? strArr[0].slice(4) : strArr[0];
|
|
242
|
+
value = strArr[1];
|
|
243
|
+
} else {
|
|
244
|
+
key = judgeHasNotMatch(curTag.innerText) ? curTag.innerText.slice(4) : curTag.innerText;
|
|
245
|
+
value = "";
|
|
246
|
+
}
|
|
247
|
+
return {
|
|
248
|
+
key: key,
|
|
249
|
+
value: value
|
|
250
|
+
};
|
|
251
|
+
};
|
|
252
|
+
useEffect(function () {
|
|
253
|
+
var selectionChange = function selectionChange() {
|
|
254
|
+
var selection = window.getSelection();
|
|
255
|
+
if (selection.type === "Caret") {
|
|
256
|
+
var _anchorNode$dataset, _anchorNode$parentNod;
|
|
257
|
+
var anchorNode = selection.anchorNode;
|
|
258
|
+
var dataAttr = ((_anchorNode$dataset = anchorNode.dataset) === null || _anchorNode$dataset === void 0 ? void 0 : _anchorNode$dataset.attr) || ((_anchorNode$parentNod = anchorNode.parentNode) === null || _anchorNode$parentNod === void 0 || (_anchorNode$parentNod = _anchorNode$parentNod.dataset) === null || _anchorNode$parentNod === void 0 ? void 0 : _anchorNode$parentNod.attr);
|
|
259
|
+
if (dataAttr) {
|
|
260
|
+
var _node$dataset2;
|
|
261
|
+
// 计算当前光标位置(纯文本模式)
|
|
262
|
+
// 整个容器
|
|
263
|
+
var planeTextPosition = getCursorPosition(container.current);
|
|
264
|
+
currentPositionIndex.current = planeTextPosition;
|
|
265
|
+
currentPositionValue.current = anchorNode.data;
|
|
266
|
+
// 当前tag 记录tag的纯文本下标
|
|
267
|
+
var curTag = getCurrentTag();
|
|
268
|
+
if (curTag) {
|
|
269
|
+
curTagIndex.current = getCursorPosition(curTag);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// 确认光标所处位置
|
|
273
|
+
var node;
|
|
274
|
+
if (anchorNode.nodeType === 3) {
|
|
275
|
+
node = anchorNode.parentNode;
|
|
276
|
+
} else {
|
|
277
|
+
node = anchorNode;
|
|
278
|
+
}
|
|
279
|
+
var type = (_node$dataset2 = node.dataset) === null || _node$dataset2 === void 0 ? void 0 : _node$dataset2.type;
|
|
280
|
+
currentValueNodeAndType.current = {
|
|
281
|
+
node: node,
|
|
282
|
+
type: type,
|
|
283
|
+
offset: selection.anchorOffset
|
|
284
|
+
};
|
|
285
|
+
if (type) {
|
|
286
|
+
var _getCurrentKeyAndValu2 = getCurrentKeyAndValue(),
|
|
287
|
+
key = _getCurrentKeyAndValu2.key,
|
|
288
|
+
value = _getCurrentKeyAndValu2.value;
|
|
289
|
+
var tagInfo = {
|
|
290
|
+
type: type,
|
|
291
|
+
id: curTag.id,
|
|
292
|
+
key: key,
|
|
293
|
+
value: value
|
|
294
|
+
};
|
|
295
|
+
if (isObjectEqual(tagInfo, preTagInfo.current)) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
if (type === "key") {
|
|
299
|
+
setVisible(true);
|
|
300
|
+
setDropStatus(function (pre) {
|
|
301
|
+
return _objectSpread(_objectSpread({}, pre), {}, {
|
|
302
|
+
key: {
|
|
303
|
+
isShow: true,
|
|
304
|
+
value: key
|
|
305
|
+
},
|
|
306
|
+
value: {
|
|
307
|
+
isShow: false
|
|
308
|
+
},
|
|
309
|
+
match: {
|
|
310
|
+
isShow: false
|
|
311
|
+
},
|
|
312
|
+
combined: {
|
|
313
|
+
isShow: false
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
if (type === "value") {
|
|
319
|
+
setVisible(true);
|
|
320
|
+
setDropStatus(function (pre) {
|
|
321
|
+
return _objectSpread(_objectSpread({}, pre), {}, {
|
|
322
|
+
key: {
|
|
323
|
+
isShow: false,
|
|
324
|
+
value: key
|
|
325
|
+
},
|
|
326
|
+
value: {
|
|
327
|
+
isShow: true,
|
|
328
|
+
key: key,
|
|
329
|
+
value: node.innerText
|
|
330
|
+
},
|
|
331
|
+
match: {
|
|
332
|
+
isShow: false
|
|
333
|
+
},
|
|
334
|
+
combined: {
|
|
335
|
+
isShow: true
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
if (type === "match") {
|
|
341
|
+
setVisible(true);
|
|
342
|
+
setDropStatus(function (pre) {
|
|
343
|
+
return _objectSpread(_objectSpread({}, pre), {}, {
|
|
344
|
+
key: {
|
|
345
|
+
isShow: false
|
|
346
|
+
},
|
|
347
|
+
value: {
|
|
348
|
+
isShow: false
|
|
349
|
+
},
|
|
350
|
+
match: {
|
|
351
|
+
isShow: true
|
|
352
|
+
},
|
|
353
|
+
combined: {
|
|
354
|
+
isShow: false
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
// 记录当前tag的type和value
|
|
360
|
+
preTagInfo.current = tagInfo;
|
|
361
|
+
} else {
|
|
362
|
+
// 外层激活key列表
|
|
363
|
+
setVisible(true);
|
|
364
|
+
setDropStatus(function (pre) {
|
|
365
|
+
return _objectSpread(_objectSpread({}, pre), {}, {
|
|
366
|
+
key: {
|
|
367
|
+
isShow: true,
|
|
368
|
+
value: ""
|
|
369
|
+
},
|
|
370
|
+
value: {
|
|
371
|
+
isShow: false
|
|
372
|
+
},
|
|
373
|
+
match: {
|
|
374
|
+
isShow: false
|
|
375
|
+
},
|
|
376
|
+
combined: {
|
|
377
|
+
isShow: false
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
// 监听选区变化
|
|
386
|
+
document.addEventListener("selectionchange", selectionChange, false);
|
|
387
|
+
return function () {
|
|
388
|
+
document.removeEventListener("selectionchange", selectionChange, false);
|
|
389
|
+
};
|
|
390
|
+
}, []);
|
|
391
|
+
return {
|
|
392
|
+
dropStatus: dropStatus,
|
|
393
|
+
visible: visible,
|
|
394
|
+
quickSelect: quickSelect,
|
|
395
|
+
onHistorySelect: onHistorySelect,
|
|
396
|
+
setVisible: setVisible
|
|
397
|
+
};
|
|
398
|
+
};
|
|
399
|
+
export default useDropDown;
|