@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,118 +0,0 @@
1
- .aggregate-drop-down-wrap {
2
- box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15); // 浮层阴影
3
- background: #fff;
4
-
5
- .aggregate-drop-down {
6
- width: 100%;
7
- max-height: 380px;
8
- // padding: 4px 0;
9
- overflow: auto;
10
- justify-content: center;
11
- align-items: center;
12
-
13
- .@{ant-prefix}-spin-nested-loading {
14
-
15
- .@{ant-prefix}-spin {
16
- display: flex;
17
- align-items: center;
18
- justify-content: center;
19
-
20
- .@{ant-prefix}-spin-dot-spin,
21
- .@{ant-prefix}-spin-text {
22
- position: relative;
23
- margin: 0;
24
- padding: 0;
25
- top: 0;
26
- left: 0;
27
- }
28
-
29
- .@{ant-prefix}-spin-text {
30
- width: auto;
31
- margin-left: 4px;
32
- }
33
- }
34
- }
35
-
36
- .list-title {
37
- line-height: 32px;
38
- background-color: rgba(0, 0, 0, 0.02);
39
- padding: 0 10px;
40
- color: @text-color-show;
41
- }
42
-
43
- .list-title-des-wrapper {
44
- color: @text-color-secondary;
45
- max-width: 100px;
46
- margin-left: 12px;
47
- }
48
-
49
- .list-title-value-wrapper {
50
- flex: 1;
51
- width: 0;
52
- }
53
-
54
- .list-title:not(:first-child) {
55
- margin-top: 8px;
56
- }
57
-
58
- .list {
59
- &:hover {
60
- cursor: pointer;
61
- background-color: #E6F7FF;
62
-
63
- .des {
64
- display: none;
65
- }
66
-
67
- .action {
68
- display: flex;
69
- align-items: center;
70
- }
71
- }
72
-
73
- line-height: 32px;
74
- display: flex;
75
- padding: 0 10px;
76
- align-items: center;
77
-
78
- .action {
79
- display: none;
80
-
81
- .pre-icon {
82
- &:nth-child(2) {
83
- margin-right: 0;
84
- }
85
- }
86
- }
87
-
88
- .pre-icon {
89
- margin-right: 8px;
90
- }
91
- }
92
-
93
- .empty {
94
- line-height: 32px;
95
- padding: 0 10px;
96
- }
97
- }
98
-
99
- .desc {
100
- width: 100%;
101
- line-height: 32px;
102
- padding: 0 10px;
103
- background: rgba(0, 0, 0, 0.02);
104
- display: flex;
105
- justify-content: space-between;
106
- align-items: center;
107
- margin-top: 8px;
108
- color: @text-color-show;
109
-
110
- .desc-margin-32 {
111
- margin-left: 32px;
112
- }
113
-
114
- .@{ant-prefix}-btn-link {
115
- margin-left: 10px;
116
- }
117
- }
118
- }
@@ -1,17 +0,0 @@
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>
@@ -1,18 +0,0 @@
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>
@@ -1,27 +0,0 @@
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 { useIntl } from "../../../locales";
6
- import "./index.less";
7
- var SwitchBtn = function SwitchBtn(_ref) {
8
- var mode = _ref.mode,
9
- onChange = _ref.onChange;
10
- var intl = useIntl();
11
- var icon = mode === "text" ? textIcon : tagIcon;
12
- var title = mode === "text" ? intl.get("1e9cc6b2-f761-4aaa-a216-9f842c6f8fce").d("切换为筛选模式") : intl.get("5faa90fc-6455-499a-a0d5-c7ff9c9867df").d("切换为手写CQL语法模式");
13
- var onClick = function onClick() {
14
- onChange(mode === "text" ? "tag" : "text");
15
- };
16
- return /*#__PURE__*/React.createElement(_Tooltip, {
17
- title: title
18
- }, /*#__PURE__*/React.createElement("div", {
19
- className: "aggregate-search-switch-btn",
20
- onClick: onClick
21
- }, /*#__PURE__*/React.createElement("img", {
22
- src: icon,
23
- alt: "",
24
- mode: mode
25
- })));
26
- };
27
- export default SwitchBtn;
@@ -1,31 +0,0 @@
1
- .aggregate-search-switch-btn {
2
- // border: @border-width-base @border-style-base @input-border-color;
3
- // border-left: none;
4
- border-left: @border-width-base @border-style-base @input-border-color;
5
- min-height: 26px;
6
- cursor: pointer;
7
- background: rgba(0, 0, 0, 0.02);
8
- border-radius: 0 2px 2px 0;
9
- display: flex;
10
- padding: 0 9px;
11
- justify-content: center;
12
- align-items: flex-start;
13
- align-self: stretch; // 使得高度和父元素一致
14
- width: 35px;
15
- &:hover{
16
- border-left-color: @input-hover-border-color;
17
- }
18
- img{
19
- transform: translateY(7px);
20
- &[mode="tag"]{
21
- transform: translateY(8px);
22
- }
23
- }
24
- }
25
- .aggregate-search-text-wrapper.syntax-error{
26
- .aggregate-search-switch-btn{
27
- &:hover{
28
- border-left-color: @red-5;
29
- }
30
- }
31
- }
@@ -1,428 +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 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(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
5
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
6
- function _toPrimitive(t, e) { if ("object" != _typeof(t) || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
7
- function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _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(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; } }
10
- 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; }
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(r) { if (Array.isArray(r)) return r; }
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, onChange, onMatchOptionShow, onCombinedOptionShow) {
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
- useEffect(function () {
54
- var matchShow = dropStatus.match.isShow;
55
- if (matchShow) {
56
- var _getCurrentKeyAndValu = getCurrentKeyAndValue(),
57
- key = _getCurrentKeyAndValu.key,
58
- value = _getCurrentKeyAndValu.value;
59
- matchShow && onMatchOptionShow({
60
- key: key,
61
- value: value
62
- });
63
- }
64
- }, [dropStatus.match.isShow]);
65
- useEffect(function () {
66
- var combinedShow = dropStatus.combined.isShow;
67
- if (combinedShow) {
68
- var _getCurrentKeyAndValu2 = getCurrentKeyAndValue(),
69
- key = _getCurrentKeyAndValu2.key,
70
- value = _getCurrentKeyAndValu2.value;
71
- combinedShow && onCombinedOptionShow({
72
- key: key,
73
- value: value
74
- });
75
- }
76
- }, [dropStatus.combined.isShow]);
77
- var isContainMatch = function isContainMatch(str) {
78
- var reg = new RegExp(/(>=|<=|>|<|:)/);
79
- if (reg.exec(str)) {
80
- return reg.exec(str)[0];
81
- }
82
- return "";
83
- };
84
- var judgeHasNotMatch = function judgeHasNotMatch(str) {
85
- return str.toLowerCase().includes("not ");
86
- };
87
- var getCurrentTag = function getCurrentTag() {
88
- var _getCursorNodeAndInde = getCursorNodeAndIndex(container.current, currentPositionIndex.current),
89
- targetNode = _getCursorNodeAndInde.targetNode;
90
- var targetTag;
91
- var _loop = function loop(node) {
92
- if (!node) {
93
- return;
94
- }
95
- if (node.nodeType === 3) {
96
- var _node$parentNode$data;
97
- if (((_node$parentNode$data = node.parentNode.dataset) === null || _node$parentNode$data === void 0 ? void 0 : _node$parentNode$data["attr"]) === "tag-box") {
98
- targetTag = node.parentNode;
99
- return;
100
- } else {
101
- _loop(node.parentNode);
102
- }
103
- } else {
104
- var _node$dataset;
105
- if (((_node$dataset = node.dataset) === null || _node$dataset === void 0 ? void 0 : _node$dataset["attr"]) === "tag-box") {
106
- targetTag = node;
107
- return;
108
- } else {
109
- _loop(node.parentNode);
110
- }
111
- }
112
- };
113
- _loop(targetNode);
114
- return targetTag;
115
- };
116
- var quickSelect = function quickSelect(value, type) {
117
- var inputStr = container.current.innerText;
118
- var newStr = inputStr.slice(0, currentPositionIndex.current) + value + inputStr.slice(currentPositionIndex.current);
119
- var newIndex = currentPositionIndex.current + value.length;
120
- if (type === "key") {
121
- // 获取当前tag
122
- var curTag = getCurrentTag();
123
- if (curTag) {
124
- var containMatch = isContainMatch(curTag.innerText);
125
- var containNot = judgeHasNotMatch(curTag.innerText) ? "NOT " : "";
126
- if (containMatch) {
127
- var strArr = curTag.innerText.split(containMatch);
128
- strArr[0] = "".concat(containNot).concat(value);
129
- curTag.innerText = strArr.join(containMatch);
130
- newStr = container.current.innerText;
131
- newIndex = currentPositionIndex.current - curTagIndex.current + strArr[0].length + containMatch.length;
132
- } else {
133
- curTag.innerText = "".concat(containNot).concat(value, ":");
134
- newStr = container.current.innerText;
135
- newIndex = currentPositionIndex.current - curTagIndex.current + curTag.innerText.length;
136
- }
137
- } else {
138
- newStr = inputStr.slice(0, currentPositionIndex.current) + value + ":" + inputStr.slice(currentPositionIndex.current);
139
- newIndex = newIndex + 1;
140
- }
141
- }
142
- if (type === "value") {
143
- // 处理value 需要替换当前内容
144
- if (currentValueNodeAndType.current.type === 'value') {
145
- newIndex = currentPositionIndex.current + value.length - currentValueNodeAndType.current.node.innerText.length + (currentValueNodeAndType.current.node.innerText.length - currentValueNodeAndType.current.offset);
146
- currentValueNodeAndType.current.node.innerText = value;
147
- newStr = container.current.innerText;
148
- }
149
- }
150
- if (value === "NOT:") {
151
- // 获取当前tag
152
- var _curTag = getCurrentTag();
153
- if (_curTag) {
154
- var curTagText = _curTag.innerText;
155
- // 正则表达式是否包含 ">= <= > <"
156
- var reg = new RegExp(/(>=|<=|>|<)/);
157
- var addNotStr = "NOT ".concat(curTagText.replace(reg, ":"));
158
- _curTag.innerText = addNotStr;
159
- newStr = container.current.innerText;
160
- newIndex = currentPositionIndex.current + (addNotStr.length - curTagText.length);
161
- }
162
- }
163
-
164
- // 替换 ":"
165
- if ([">=", "<=", ">", "<", ":"].includes(value)) {
166
- newStr = inputStr.slice(0, currentPositionIndex.current - currentPositionValue.current.length) + value + inputStr.slice(currentPositionIndex.current);
167
- newIndex = currentPositionIndex.current + (value.length - currentPositionValue.current.length);
168
- }
169
- if (["[]", "()"].includes(value)) {
170
- newIndex = newIndex - 1;
171
- }
172
-
173
- // 插入字符串下标位置内容
174
- if (currentPositionIndex.current !== null) {
175
- handleValueChange(newStr);
176
- onChange(newStr);
177
- // 光标移动到插入字符串后面
178
- var _getCursorNodeAndInde2 = getCursorNodeAndIndex(container.current, newIndex),
179
- targetNode = _getCursorNodeAndInde2.targetNode,
180
- targetIndex = _getCursorNodeAndInde2.targetIndex;
181
- // 设置光标位置
182
- setCursorPosition(targetNode, targetIndex);
183
- }
184
-
185
- // 控制下拉框状态
186
- setTimeout(function () {
187
- var _getCurrentKeyAndValu3 = getCurrentKeyAndValue(),
188
- key = _getCurrentKeyAndValu3.key,
189
- value = _getCurrentKeyAndValu3.value;
190
- if (type === "match") {
191
- setDropStatus(function (pre) {
192
- return _objectSpread(_objectSpread({}, pre), {}, {
193
- key: {
194
- isShow: false
195
- },
196
- value: {
197
- isShow: true,
198
- value: {
199
- key: key,
200
- value: value
201
- }
202
- },
203
- match: {
204
- isShow: false
205
- },
206
- combined: {
207
- isShow: true
208
- }
209
- });
210
- });
211
- }
212
- if (type === "value") {
213
- // 选择完value,关闭弹窗
214
- setVisible(false);
215
- }
216
- if (type === "key") {
217
- setDropStatus(function (pre) {
218
- return _objectSpread(_objectSpread({}, pre), {}, {
219
- key: {
220
- isShow: false
221
- },
222
- value: {
223
- isShow: true,
224
- value: {
225
- key: key,
226
- value: ''
227
- }
228
- },
229
- match: {
230
- isShow: true
231
- },
232
- combined: {
233
- isShow: true
234
- }
235
- });
236
- });
237
- }
238
- });
239
- };
240
- var onHistorySelect = function onHistorySelect(value) {
241
- handleValueChange(value);
242
- onChange(value);
243
- // 光标移动到插入字符串后面
244
- var _getCursorNodeAndInde3 = getCursorNodeAndIndex(container.current, value.length),
245
- targetNode = _getCursorNodeAndInde3.targetNode,
246
- targetIndex = _getCursorNodeAndInde3.targetIndex;
247
- // 设置光标位置
248
- setCursorPosition(targetNode, targetIndex);
249
-
250
- // 关闭弹窗
251
- setTimeout(function () {
252
- setVisible(false);
253
- });
254
- };
255
- var judgeHasMatch = function judgeHasMatch(str) {
256
- return MATCH_LIST.find(function (match) {
257
- return str.includes(match);
258
- });
259
- };
260
- var getCurrentKeyAndValue = function getCurrentKeyAndValue() {
261
- var curTag = getCurrentTag();
262
- var hasMatch = judgeHasMatch(curTag === null || curTag === void 0 ? void 0 : curTag.innerText);
263
- var key;
264
- var value;
265
- if (hasMatch) {
266
- var strArr = curTag.innerText.split(hasMatch);
267
- key = judgeHasNotMatch(strArr[0]) ? strArr[0].slice(4) : strArr[0];
268
- value = strArr[1];
269
- } else {
270
- key = judgeHasNotMatch(curTag.innerText) ? curTag.innerText.slice(4) : curTag.innerText;
271
- value = "";
272
- }
273
- return {
274
- key: key,
275
- value: value
276
- };
277
- };
278
- useEffect(function () {
279
- var selectionChange = function selectionChange() {
280
- var selection = window.getSelection();
281
- if (selection.type === "Caret") {
282
- var _anchorNode$dataset, _anchorNode$parentNod;
283
- var anchorNode = selection.anchorNode;
284
- 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);
285
- if (dataAttr) {
286
- var _node$dataset2;
287
- // 计算当前光标位置(纯文本模式)
288
- // 整个容器
289
- var planeTextPosition = getCursorPosition(container.current);
290
- currentPositionIndex.current = planeTextPosition;
291
- currentPositionValue.current = anchorNode.data;
292
- // 当前tag 记录tag的纯文本下标
293
- var curTag = getCurrentTag();
294
- if (curTag) {
295
- curTagIndex.current = getCursorPosition(curTag);
296
- }
297
-
298
- // 确认光标所处位置
299
- var node;
300
- if (anchorNode.nodeType === 3) {
301
- node = anchorNode.parentNode;
302
- } else {
303
- node = anchorNode;
304
- }
305
- var type = (_node$dataset2 = node.dataset) === null || _node$dataset2 === void 0 ? void 0 : _node$dataset2.type;
306
- currentValueNodeAndType.current = {
307
- node: node,
308
- type: type,
309
- offset: selection.anchorOffset
310
- };
311
- if (type) {
312
- var _getCurrentKeyAndValu4 = getCurrentKeyAndValue(),
313
- key = _getCurrentKeyAndValu4.key,
314
- value = _getCurrentKeyAndValu4.value;
315
- var tagInfo = {
316
- type: type,
317
- id: curTag.id,
318
- key: key,
319
- value: value
320
- };
321
- if (isObjectEqual(tagInfo, preTagInfo.current)) {
322
- return;
323
- }
324
- if (type === "key") {
325
- setVisible(true);
326
- setDropStatus(function (pre) {
327
- return _objectSpread(_objectSpread({}, pre), {}, {
328
- key: {
329
- isShow: true,
330
- value: key
331
- },
332
- value: {
333
- isShow: false
334
- },
335
- match: {
336
- isShow: false
337
- },
338
- combined: {
339
- isShow: false
340
- }
341
- });
342
- });
343
- }
344
- if (type === "value") {
345
- setVisible(true);
346
- setDropStatus(function (pre) {
347
- return _objectSpread(_objectSpread({}, pre), {}, {
348
- key: {
349
- isShow: false,
350
- value: key
351
- },
352
- value: {
353
- isShow: true,
354
- value: {
355
- key: key,
356
- value: node.innerText
357
- }
358
- },
359
- match: {
360
- isShow: false
361
- },
362
- combined: {
363
- isShow: true
364
- }
365
- });
366
- });
367
- }
368
- if (type === "match") {
369
- setVisible(true);
370
- setDropStatus(function (pre) {
371
- return _objectSpread(_objectSpread({}, pre), {}, {
372
- key: {
373
- isShow: false
374
- },
375
- value: {
376
- isShow: false
377
- },
378
- match: {
379
- isShow: true
380
- },
381
- combined: {
382
- isShow: false
383
- }
384
- });
385
- });
386
- }
387
- // 记录当前tag的type和value
388
- preTagInfo.current = tagInfo;
389
- } else {
390
- // 外层激活key列表
391
- setVisible(true);
392
- setDropStatus(function (pre) {
393
- return _objectSpread(_objectSpread({}, pre), {}, {
394
- key: {
395
- isShow: true,
396
- value: ""
397
- },
398
- value: {
399
- isShow: false
400
- },
401
- match: {
402
- isShow: false
403
- },
404
- combined: {
405
- isShow: false
406
- }
407
- });
408
- });
409
- }
410
- }
411
- }
412
- };
413
- // 监听选区变化
414
- document.addEventListener("selectionchange", selectionChange, false);
415
- return function () {
416
- document.removeEventListener("selectionchange", selectionChange, false);
417
- };
418
- }, []);
419
- return {
420
- dropStatus: dropStatus,
421
- visible: visible,
422
- quickSelect: quickSelect,
423
- onHistorySelect: onHistorySelect,
424
- setVisible: setVisible,
425
- currentPositionIndex: currentPositionIndex
426
- };
427
- };
428
- export default useDropDown;