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