@chaoswise/business 1.1.0 → 2.1.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.
Files changed (82) hide show
  1. package/lib/I18nInput/index.d.ts +31 -0
  2. package/lib/I18nInput/index.js +159 -58
  3. package/lib/index.d.ts +1 -0
  4. package/lib/index.js +0 -4
  5. package/lib/locales/en_US.json +1 -1
  6. package/lib/locales/index.d.ts +7 -0
  7. package/lib/locales/index.js +15 -19
  8. package/lib/locales/intl.d.ts +11 -0
  9. package/lib/locales/intl.js +18 -58
  10. package/lib/locales/ja_JP.json +1 -1
  11. package/lib/locales/normalizeLocale.d.ts +2 -0
  12. package/lib/locales/normalizeLocale.js +27 -0
  13. package/lib/locales/withLocale.d.ts +28 -0
  14. package/lib/locales/withLocale.js +1 -1
  15. package/lib/locales/zh_CN.json +1 -1
  16. package/lib/locales/zh_HK.json +1 -1
  17. package/lib/locales/zh_TW.json +1 -1
  18. package/package.json +8 -6
  19. package/lib/AggregateSearch/CLSPL/CLQLLexer.js +0 -78
  20. package/lib/AggregateSearch/CLSPL/CLQLParser.js +0 -2724
  21. package/lib/AggregateSearch/CLSPL/CLQLParserListener.js +0 -347
  22. package/lib/AggregateSearch/CLSPL/CLQLParserVisitor.js +0 -251
  23. package/lib/AggregateSearch/CLSPL/SPLStagy.js +0 -197
  24. package/lib/AggregateSearch/CLSPL/index.js +0 -196
  25. package/lib/AggregateSearch/CLSPL/makeTokenizeFn.js +0 -18
  26. package/lib/AggregateSearch/CLSPL/token.js +0 -7
  27. package/lib/AggregateSearch/components/CloseAllIcon/index.js +0 -13
  28. package/lib/AggregateSearch/components/CloseAllIcon/index.less +0 -11
  29. package/lib/AggregateSearch/components/DropDown/assets/combined.svg +0 -22
  30. package/lib/AggregateSearch/components/DropDown/assets/copy.svg +0 -22
  31. package/lib/AggregateSearch/components/DropDown/assets/delete.svg +0 -24
  32. package/lib/AggregateSearch/components/DropDown/assets/home.svg +0 -20
  33. package/lib/AggregateSearch/components/DropDown/assets/key.svg +0 -21
  34. package/lib/AggregateSearch/components/DropDown/assets/star.svg +0 -22
  35. package/lib/AggregateSearch/components/DropDown/assets/time-circle.svg +0 -20
  36. package/lib/AggregateSearch/components/DropDown/assets/value.svg +0 -23
  37. package/lib/AggregateSearch/components/DropDown/config.js +0 -54
  38. package/lib/AggregateSearch/components/DropDown/index.js +0 -576
  39. package/lib/AggregateSearch/components/DropDown/index.less +0 -118
  40. package/lib/AggregateSearch/components/SwitchBtn/assets/tag-icon.svg +0 -17
  41. package/lib/AggregateSearch/components/SwitchBtn/assets/text-icon.svg +0 -18
  42. package/lib/AggregateSearch/components/SwitchBtn/index.js +0 -27
  43. package/lib/AggregateSearch/components/SwitchBtn/index.less +0 -31
  44. package/lib/AggregateSearch/hooks/useDropDown.js +0 -428
  45. package/lib/AggregateSearch/index.js +0 -503
  46. package/lib/AggregateSearch/index.less +0 -225
  47. package/lib/AggregateSearch/utils/index.js +0 -391
  48. package/lib/ContentEditableSearch/components/CloseAllIcon/index.js +0 -13
  49. package/lib/ContentEditableSearch/components/CloseAllIcon/index.less +0 -11
  50. package/lib/ContentEditableSearch/index.js +0 -155
  51. package/lib/ContentEditableSearch/index.less +0 -65
  52. package/lib/ContentEditableSearch/utils/index.js +0 -98
  53. package/lib/PropertyControlViewer/assets/doCommon.less +0 -75
  54. package/lib/PropertyControlViewer/assets/doSelect.less +0 -74
  55. package/lib/PropertyControlViewer/assets/index.less +0 -189
  56. package/lib/PropertyControlViewer/components/DoAppIcon/CustomIcon/iconfont.js +0 -1
  57. package/lib/PropertyControlViewer/components/DoAppIcon/CustomIcon/index.js +0 -29
  58. package/lib/PropertyControlViewer/components/DoAppIcon/iconData/IconJson.js +0 -0
  59. package/lib/PropertyControlViewer/components/DoAppIcon/index.js +0 -41
  60. package/lib/PropertyControlViewer/components/DoCiUnitBitmap.js +0 -50
  61. package/lib/PropertyControlViewer/components/DoCommon.js +0 -36
  62. package/lib/PropertyControlViewer/components/DoDefaultPlaceholder.js +0 -9
  63. package/lib/PropertyControlViewer/components/DoImage.js +0 -107
  64. package/lib/PropertyControlViewer/components/DoQuote/components/QuoteView.js +0 -63
  65. package/lib/PropertyControlViewer/components/DoQuote/components/TableQuoteView.js +0 -18
  66. package/lib/PropertyControlViewer/components/DoQuote/index.js +0 -16
  67. package/lib/PropertyControlViewer/components/DoSelect.js +0 -80
  68. package/lib/PropertyControlViewer/components/DoTable.js +0 -44
  69. package/lib/PropertyControlViewer/components/DoUser.js +0 -61
  70. package/lib/PropertyControlViewer/components/TagShowMoreList/index.js +0 -132
  71. package/lib/PropertyControlViewer/components/TagShowMoreList/index.less +0 -106
  72. package/lib/PropertyControlViewer/config/constants.js +0 -84
  73. package/lib/PropertyControlViewer/config/utils.js +0 -353
  74. package/lib/PropertyControlViewer/index.js +0 -195
  75. package/lib/PropertyControlViewer/index.less +0 -107
  76. package/lib/Watermark/index.js +0 -184
  77. package/lib/Watermark/index.less +0 -17
  78. package/lib/demo.js +0 -0
  79. package/lib/locale/en_US.js +0 -9
  80. package/lib/locale/index.js +0 -12
  81. package/lib/locale/zh_CN.js +0 -9
  82. package/lib/locales/localeCode.js +0 -13
@@ -1,503 +0,0 @@
1
- function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
2
- 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."); }
3
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
4
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
5
- 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; } }
6
- function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
7
- function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
8
- function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
9
- function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
10
- function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
11
- import React, { useEffect, useRef, useState, forwardRef, useImperativeHandle } from "react";
12
- import PropTypes from "prop-types";
13
- import { textInit, getCursorPosition, getCursorNodeAndIndex, setCursorPosition, genHtmlAndSyntaxCheckResByString, checkSyntax, cloneDomRemoveCloseBtn } from "./utils";
14
- import SwitchBtn from "./components/SwitchBtn";
15
- import DropDown from "./components/DropDown";
16
- import useDropDown from "./hooks/useDropDown";
17
- import CloseAllIcon from "./components/CloseAllIcon";
18
- import classnames from "classnames";
19
- import "./index.less";
20
- var AggregateSearch = /*#__PURE__*/forwardRef(function (props, ref) {
21
- var _props$onChange = props.onChange,
22
- onChange = _props$onChange === void 0 ? function () {} : _props$onChange,
23
- value = props.value,
24
- _props$fetchKeyList = props.fetchKeyList,
25
- fetchKeyList = _props$fetchKeyList === void 0 ? /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
26
- return _regenerator().w(function (_context) {
27
- while (1) switch (_context.n) {
28
- case 0:
29
- return _context.a(2, []);
30
- }
31
- }, _callee);
32
- })) : _props$fetchKeyList,
33
- _props$fetchValueList = props.fetchValueList,
34
- fetchValueList = _props$fetchValueList === void 0 ? /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
35
- return _regenerator().w(function (_context2) {
36
- while (1) switch (_context2.n) {
37
- case 0:
38
- return _context2.a(2, []);
39
- }
40
- }, _callee2);
41
- })) : _props$fetchValueList,
42
- _props$fetchHistoryLi = props.fetchHistoryList,
43
- fetchHistoryList = _props$fetchHistoryLi === void 0 ? /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
44
- return _regenerator().w(function (_context3) {
45
- while (1) switch (_context3.n) {
46
- case 0:
47
- return _context3.a(2, []);
48
- }
49
- }, _callee3);
50
- })) : _props$fetchHistoryLi,
51
- _props$onHistoryDelet = props.onHistoryDelete,
52
- onHistoryDelete = _props$onHistoryDelet === void 0 ? /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
53
- return _regenerator().w(function (_context4) {
54
- while (1) switch (_context4.n) {
55
- case 0:
56
- return _context4.a(2, false);
57
- }
58
- }, _callee4);
59
- })) : _props$onHistoryDelet,
60
- _props$onHelpClick = props.onHelpClick,
61
- onHelpClick = _props$onHelpClick === void 0 ? function () {} : _props$onHelpClick,
62
- _props$onPressEnter = props.onPressEnter,
63
- onPressEnter = _props$onPressEnter === void 0 ? function () {} : _props$onPressEnter,
64
- mode = props.mode,
65
- _props$defaultMode = props.defaultMode,
66
- defaultMode = _props$defaultMode === void 0 ? "tag" : _props$defaultMode,
67
- placeholder = props.placeholder,
68
- className = props.className,
69
- _props$style = props.style,
70
- style = _props$style === void 0 ? {} : _props$style,
71
- _props$debounceWait = props.debounceWait,
72
- debounceWait = _props$debounceWait === void 0 ? 300 : _props$debounceWait,
73
- _props$option = props.option,
74
- _props$option2 = _props$option === void 0 ? {} : _props$option,
75
- matchOptionList = _props$option2.matchOptionList,
76
- combinedOptionList = _props$option2.combinedOptionList,
77
- _props$option2$onMatc = _props$option2.onMatchOptionShow,
78
- onMatchOptionShow = _props$option2$onMatc === void 0 ? function () {} : _props$option2$onMatc,
79
- _props$option2$onComb = _props$option2.onCombinedOptionShow,
80
- onCombinedOptionShow = _props$option2$onComb === void 0 ? function () {} : _props$option2$onComb;
81
-
82
- // 输入模式
83
- var _useState = useState(defaultMode),
84
- _useState2 = _slicedToArray(_useState, 2),
85
- selMode = _useState2[0],
86
- setSelMode = _useState2[1]; // tag | text
87
-
88
- var curMode = mode || selMode;
89
-
90
- // 输入内容
91
- var _useState3 = useState(""),
92
- _useState4 = _slicedToArray(_useState3, 2),
93
- selValue = _useState4[0],
94
- setSelValue = _useState4[1];
95
- var container = useRef(null);
96
- var containerWrapperRef = useRef(null);
97
- // 是否可编辑,若点击编辑区域外内容则不可编辑 todo:用于修复聚焦bug
98
- var _useState5 = useState(false),
99
- _useState6 = _slicedToArray(_useState5, 2),
100
- contentEditable = _useState6[0],
101
- setContentEditable = _useState6[1];
102
- var _useState7 = useState(null),
103
- _useState8 = _slicedToArray(_useState7, 2),
104
- errorDom = _useState8[0],
105
- setErrorDom = _useState8[1];
106
- var tooltipDomRef = useRef(null);
107
- // 是否正在输入中文
108
- var isComposing = useRef(false);
109
- useImperativeHandle(ref, function () {
110
- return {
111
- getContainerWrapper: function getContainerWrapper() {
112
- return containerWrapperRef.current;
113
- }
114
- };
115
- });
116
- var handleSyntaxCheck = /*#__PURE__*/function () {
117
- var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(inputStr) {
118
- var checkRes, column, msg, _getCursorNodeAndInde, errorNode, _findParent, errorTag;
119
- return _regenerator().w(function (_context5) {
120
- while (1) switch (_context5.n) {
121
- case 0:
122
- _context5.n = 1;
123
- return checkSyntax(inputStr);
124
- case 1:
125
- checkRes = _context5.v;
126
- if (!checkRes) {
127
- _context5.n = 2;
128
- break;
129
- }
130
- column = checkRes.column, msg = checkRes.msg; // 找到目标节点,高亮提示错误
131
- _getCursorNodeAndInde = getCursorNodeAndIndex(container.current, column), errorNode = _getCursorNodeAndInde.targetNode;
132
- _findParent = function findParent(node) {
133
- var _node$dataset;
134
- if (!node || node === container.current) {
135
- var nextSiblingIndex = column > 0 ? column - 1 : column + 1;
136
- column = nextSiblingIndex;
137
- var _getCursorNodeAndInde2 = getCursorNodeAndIndex(container.current, nextSiblingIndex),
138
- newErrorNode = _getCursorNodeAndInde2.targetNode;
139
- if (!newErrorNode && (nextSiblingIndex < 0 || nextSiblingIndex > inputStr.length)) {
140
- return null;
141
- }
142
- return _findParent(newErrorNode);
143
- }
144
- var dataAttr = (_node$dataset = node.dataset) === null || _node$dataset === void 0 ? void 0 : _node$dataset["attr"];
145
- if (dataAttr && ["tag-box"].includes(dataAttr)) {
146
- return node;
147
- }
148
- return _findParent(node.parentNode);
149
- };
150
- errorTag = _findParent(errorNode);
151
- if (errorTag) {
152
- errorTag.classList.add("syntax-error");
153
- errorTag.setAttribute("data-error", msg);
154
- }
155
- setErrorDom(errorTag);
156
- return _context5.a(2, true);
157
- case 2:
158
- setErrorDom(null);
159
- return _context5.a(2, false);
160
- }
161
- }, _callee5);
162
- }));
163
- return function handleSyntaxCheck(_x) {
164
- return _ref5.apply(this, arguments);
165
- };
166
- }();
167
- var handleValueChange = /*#__PURE__*/function () {
168
- var _ref6 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(inputStr, mode) {
169
- var checkRes, planeTextPosition, htmlString, _getCursorNodeAndInde3, targetNode, targetIndex;
170
- return _regenerator().w(function (_context6) {
171
- while (1) switch (_context6.n) {
172
- case 0:
173
- if (!((mode || curMode) === "text")) {
174
- _context6.n = 2;
175
- break;
176
- }
177
- _context6.n = 1;
178
- return checkSyntax(inputStr);
179
- case 1:
180
- checkRes = _context6.v;
181
- if (container.current.innerText !== inputStr) {
182
- // 重复触发container.current.innerText赋值会影响光标位置
183
- container.current.innerText = inputStr;
184
- }
185
- if (checkRes) {
186
- setErrorDom(containerWrapperRef.current);
187
- containerWrapperRef.current.classList.add("syntax-error");
188
- containerWrapperRef.current.setAttribute("data-error", checkRes.msg);
189
- } else {
190
- setErrorDom(null);
191
- containerWrapperRef.current.classList.remove("syntax-error");
192
- containerWrapperRef.current.removeAttribute("data-error");
193
- }
194
- return _context6.a(2);
195
- case 2:
196
- // 计算当前光标位置(纯文本模式)
197
- planeTextPosition = getCursorPosition(container.current); // 将纯文本模式转为html模式(语法解析器)
198
- htmlString = genHtmlAndSyntaxCheckResByString(inputStr);
199
- if (!htmlString.trim()) {
200
- // 修复空状态placeholder
201
- container.current.innerHTML = "";
202
- } else {
203
- container.current.innerHTML = htmlString;
204
- }
205
- // 找到格式化后的光标位置
206
- if (planeTextPosition !== null) {
207
- _getCursorNodeAndInde3 = getCursorNodeAndIndex(container.current, planeTextPosition), targetNode = _getCursorNodeAndInde3.targetNode, targetIndex = _getCursorNodeAndInde3.targetIndex; // 设置光标位置
208
- setCursorPosition(targetNode, targetIndex);
209
- }
210
- // 检测语法
211
- _context6.n = 3;
212
- return handleSyntaxCheck(inputStr);
213
- case 3:
214
- setSelValue(container.current.innerText.replace(/\s{1}$/g, ""));
215
- case 4:
216
- return _context6.a(2);
217
- }
218
- }, _callee6);
219
- }));
220
- return function handleValueChange(_x2, _x3) {
221
- return _ref6.apply(this, arguments);
222
- };
223
- }();
224
- var _useDropDown = useDropDown(container, handleValueChange, onChange, onMatchOptionShow, onCombinedOptionShow),
225
- dropStatus = _useDropDown.dropStatus,
226
- visible = _useDropDown.visible,
227
- quickSelect = _useDropDown.quickSelect,
228
- onHistorySelect = _useDropDown.onHistorySelect,
229
- setVisible = _useDropDown.setVisible,
230
- currentPositionIndex = _useDropDown.currentPositionIndex;
231
- var onInput = /*#__PURE__*/function () {
232
- var _ref7 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(e) {
233
- var cloneDomRemoveCloseBtnDom;
234
- return _regenerator().w(function (_context7) {
235
- while (1) switch (_context7.n) {
236
- case 0:
237
- if (!isComposing.current) {
238
- _context7.n = 1;
239
- break;
240
- }
241
- return _context7.a(2);
242
- case 1:
243
- cloneDomRemoveCloseBtnDom = cloneDomRemoveCloseBtn(e.target);
244
- handleValueChange(cloneDomRemoveCloseBtnDom.innerText);
245
- onChange(cloneDomRemoveCloseBtnDom.innerText);
246
- case 2:
247
- return _context7.a(2);
248
- }
249
- }, _callee7);
250
- }));
251
- return function onInput(_x4) {
252
- return _ref7.apply(this, arguments);
253
- };
254
- }();
255
- useEffect(function () {
256
- if ("value" in props) {
257
- handleValueChange(value);
258
- }
259
- }, [value]);
260
-
261
- // 监听点击事件(container以外的地方)
262
- useEffect(function () {
263
- var handleClick = function handleClick(e) {
264
- // 可编辑文本框边框线e.target !== containerWrapperRef.current
265
- // e.target 为svg图标时,className为SVGAnimatedString类型(object)
266
- var isClickClose = e.target.className && typeof e.target.className === "string" ? e.target.className.includes("tag-box-item-close") : false;
267
- if (container.current && (!container.current.contains(e.target) || isClickClose) && e.target !== containerWrapperRef.current) {
268
- setVisible(false);
269
- setContentEditable(false);
270
- } else {
271
- var _container$current;
272
- setContentEditable(true);
273
- (_container$current = container.current) === null || _container$current === void 0 || _container$current.focus();
274
- }
275
- if (isClickClose) {
276
- var CloseTagWrapper = e.target.parentNode;
277
- var nextSiblingWrappr = CloseTagWrapper.nextSibling;
278
- if (nextSiblingWrappr) {
279
- // 将下个文本元素的第一个空格去掉
280
- nextSiblingWrappr.nodeValue = nextSiblingWrappr.nodeValue.replace(/(^\s{1})/, "");
281
- }
282
- container.current.removeChild(CloseTagWrapper);
283
- currentPositionIndex.current = 0; // 点击关闭按钮重置当前光标位置
284
- handleValueChange(container.current.innerText);
285
- onChange(container.current.innerText);
286
- }
287
- };
288
- document.addEventListener("click", handleClick);
289
- return function () {
290
- document.removeEventListener("click", handleClick);
291
- };
292
- }, []);
293
- var handleMouseEnter = function handleMouseEnter(event) {
294
- var errorContent = event.target.dataset["error"];
295
- var rect = event.target.getBoundingClientRect();
296
- var className = event.target.className;
297
- var isTagBox = className.includes("tag-box");
298
- var top = isTagBox ? 26 : 22;
299
- if (!tooltipDomRef.current) {
300
- tooltipDomRef.current = document.createElement("div");
301
- tooltipDomRef.current.classList.add("uniq-aggregateSearch-tooltip");
302
- document.body.appendChild(tooltipDomRef.current);
303
- }
304
- tooltipDomRef.current.style.top = "".concat(rect.top - top, "px");
305
- tooltipDomRef.current.style.left = "".concat(rect.left, "px");
306
- tooltipDomRef.current.style.position = "absolute";
307
- tooltipDomRef.current.innerHTML = errorContent;
308
- tooltipDomRef.current.style.display = "block";
309
- };
310
- var handleMouseLeave = function handleMouseLeave() {
311
- if (tooltipDomRef.current) {
312
- tooltipDomRef.current.style.display = "none";
313
- }
314
- };
315
- useEffect(function () {
316
- if (errorDom) {
317
- errorDom.addEventListener("mouseenter", handleMouseEnter);
318
- errorDom.addEventListener("mouseleave", handleMouseLeave);
319
- } else {
320
- if (tooltipDomRef.current) {
321
- document.body.removeChild(tooltipDomRef.current);
322
- tooltipDomRef.current = null;
323
- }
324
- }
325
- return function () {
326
- if (errorDom) {
327
- errorDom.removeEventListener("mouseenter", handleMouseEnter);
328
- errorDom.removeEventListener("mouseleave", handleMouseLeave);
329
- }
330
- };
331
- }, [errorDom]);
332
- var onFocus = function onFocus() {
333
- setVisible(true);
334
- };
335
- var onModeChange = function onModeChange(mode) {
336
- setSelMode(mode);
337
- if (mode === "text") {
338
- // container.current.innerText = container.current.innerText; old sonar扫描过不去
339
- container.current.innerHTML = container.current.innerText;
340
- } else {
341
- // 移除错误提示
342
- containerWrapperRef.current.classList.remove("syntax-error");
343
- containerWrapperRef.current.removeAttribute("data-error");
344
- if (tooltipDomRef.current) {
345
- tooltipDomRef.current.style.display = "none";
346
- }
347
- }
348
- handleValueChange(container.current.innerText, mode);
349
- };
350
- var onKeyDown = function onKeyDown(e) {
351
- var keyCode = e.keyCode;
352
- if (keyCode === 13) {
353
- // 回车阻止默认的换行行为
354
- e.preventDefault();
355
- var cloneDomRemoveCloseBtnDom = cloneDomRemoveCloseBtn(e.target);
356
- onPressEnter(cloneDomRemoveCloseBtnDom.innerText);
357
- setContentEditable(false);
358
- setVisible(false);
359
- }
360
- };
361
- return /*#__PURE__*/React.createElement(DropDown, {
362
- onHelpClick: onHelpClick,
363
- visible: contentEditable && visible && curMode === "tag",
364
- keyOption: {
365
- value: dropStatus.key.isShow ? dropStatus.key.value : null,
366
- fetchFuc: fetchKeyList,
367
- onSelect: function onSelect(value) {
368
- quickSelect(value, "key");
369
- }
370
- },
371
- valueOption: {
372
- value: dropStatus.value.isShow ? dropStatus.value.value : null,
373
- fetchFuc: fetchValueList,
374
- onSelect: function onSelect(value) {
375
- quickSelect(value, "value");
376
- }
377
- },
378
- historyOption: {
379
- value: selValue,
380
- fetchFuc: fetchHistoryList,
381
- onSelect: function onSelect(value, record) {
382
- onHistorySelect(value);
383
- },
384
- onCopy: function onCopy() {},
385
- onDelete: onHistoryDelete
386
- },
387
- matchOption: {
388
- isShow: dropStatus.match.isShow,
389
- onSelect: function onSelect(value) {
390
- quickSelect(value, "match");
391
- },
392
- list: matchOptionList
393
- },
394
- combinedOption: {
395
- isShow: dropStatus.combined.isShow,
396
- onSelect: function onSelect(value) {
397
- quickSelect(value, "combined");
398
- },
399
- list: combinedOptionList
400
- },
401
- containerWrapperRef: containerWrapperRef,
402
- debounceWait: debounceWait
403
- }, /*#__PURE__*/React.createElement("div", {
404
- className: classnames("aggregate-search-wrapper", className, {
405
- "aggregate-search-text-wrapper": curMode === "text"
406
- }),
407
- ref: containerWrapperRef,
408
- style: style
409
- }, /*#__PURE__*/React.createElement("div", {
410
- spellCheck: false,
411
- onCompositionEnd: function onCompositionEnd(e) {
412
- isComposing.current = false;
413
- // 输入中文结束再触发一次,保证文本框对应内容与当前返回值一致,选项效果不会丢失
414
- var cloneDomRemoveCloseBtnDom = cloneDomRemoveCloseBtn(e.target);
415
- handleValueChange(cloneDomRemoveCloseBtnDom.innerText);
416
- onChange(cloneDomRemoveCloseBtnDom.innerText);
417
- },
418
- onCompositionStart: function onCompositionStart() {
419
- return isComposing.current = true;
420
- },
421
- className: "aggregate-search-input",
422
- ref: container,
423
- "data-attr": "container",
424
- "data-placeholder": placeholder,
425
- contentEditable: contentEditable,
426
- suppressContentEditableWarning: true,
427
- onPaste: textInit // 只粘贴纯文本 去除html标签
428
- ,
429
- onInput: onInput,
430
- onFocus: onFocus,
431
- onKeyDown: onKeyDown
432
- }), /*#__PURE__*/React.createElement(CloseAllIcon, {
433
- onClickCloseAll: function onClickCloseAll() {
434
- container.current.innerText = "";
435
- handleValueChange("");
436
- onChange("");
437
- }
438
- }), /*#__PURE__*/React.createElement(SwitchBtn, {
439
- onChange: onModeChange,
440
- mode: mode || selMode
441
- })));
442
- });
443
- AggregateSearch.propTypes = {
444
- /**
445
- * 受控value
446
- */
447
- value: PropTypes.string,
448
- /**
449
- * 文本内容变化的回调,(value) => {}
450
- */
451
- onChange: PropTypes.func,
452
- /**
453
- * 文本内容回车变化的回调,(value) => {}
454
- */
455
- onPressEnter: PropTypes.func,
456
- /**
457
- * 可生成标签对模式下触发搜索标签key的回调,需要返回promise,async(key)=>[],参数为当前光标所在标签的key值:需要该值请求下拉列表key值数据
458
- */
459
- fetchKeyList: PropTypes.func,
460
- /**
461
- * 可生成标签对模式下触发搜索标签value的回调,需要返回promise,async({key,value})=>[],参数为当前光标所在标签的key和value值:需要该值请求下拉列表value值数据
462
- */
463
- fetchValueList: PropTypes.func,
464
- /**
465
- * 可生成标签对模式下触发历史记录搜索的回调,需要返回promise,async(value)=>[],参数为聚合搜索框内当前所有文本内容:需要该值请求下拉列表历史记录数据
466
- */
467
- fetchHistoryList: PropTypes.func,
468
- /**
469
- * 帮助按钮点击回调
470
- */
471
- onHelpClick: PropTypes.func,
472
- /**
473
- * 删除历史记录回调,需要返回promise,async(id)=>Boolean
474
- */
475
- onHistoryDelete: PropTypes.func,
476
- /**
477
- * 内容为空提示
478
- */
479
- placeholder: PropTypes.string,
480
- /**
481
- * 聚合搜索框外层容器的类名
482
- */
483
- className: PropTypes.string,
484
- /**
485
- * 用于设置容器外壳的样式
486
- */
487
- style: PropTypes.object,
488
- /**
489
- * 防抖时间默认为300ms
490
- */
491
- debounceWait: PropTypes.number,
492
- /**
493
- * 配置项:目前有匹配方式和组合模式的配置
494
- * {
495
- * matchOptionList, // 匹配方式下拉列表,若不传使用默认的配置项
496
- * combinedOptionList, // 组合模式下拉列表,若不传使用默认的配置项
497
- * onMatchOptionShow = () => {}, // 匹配方式下拉列表显示回调
498
- * onCombinedOptionShow = () => {}, // 组合模式下拉列表显示回调
499
- * }
500
- */
501
- option: PropTypes.object
502
- };
503
- export default AggregateSearch;