dtable-ui-component 5.3.6 → 5.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (256) hide show
  1. package/lib/ButtonFormatter/index.js +8 -2
  2. package/lib/CheckboxEditor/index.css +8 -20
  3. package/lib/CheckboxEditor/index.js +98 -35
  4. package/lib/CheckboxFormatter/index.css +5 -0
  5. package/lib/CheckboxFormatter/index.js +9 -15
  6. package/lib/CollaboratorEditor/index.css +12 -35
  7. package/lib/CollaboratorEditor/index.js +18 -212
  8. package/lib/CollaboratorEditor/{mb-collaborator-editor-popover → mb-collaborator-editor}/index.js +27 -30
  9. package/lib/CollaboratorEditor/pc-collaborator-editor/index.js +257 -0
  10. package/lib/CollaboratorItem/index.css +7 -1
  11. package/lib/CollaboratorItem/index.js +6 -2
  12. package/lib/Comment/body/comment.js +190 -0
  13. package/lib/Comment/body/index.css +95 -0
  14. package/lib/Comment/body/index.js +32 -0
  15. package/lib/Comment/footer/btns/index.css +40 -0
  16. package/lib/Comment/footer/btns/index.js +113 -0
  17. package/lib/Comment/footer/index.css +157 -0
  18. package/lib/Comment/footer/index.js +169 -0
  19. package/lib/Comment/footer/input/index.css +52 -0
  20. package/lib/Comment/footer/input/index.js +448 -0
  21. package/lib/Comment/footer/input/participant/index.css +0 -0
  22. package/lib/Comment/footer/input/participant/index.js +53 -0
  23. package/lib/Comment/footer/participants/index.css +22 -0
  24. package/lib/Comment/footer/participants/index.js +68 -0
  25. package/lib/Comment/footer/participants/participant/index.css +5 -0
  26. package/lib/Comment/footer/participants/participant/index.js +32 -0
  27. package/lib/Comment/footer/participants/participant-select/index.css +104 -0
  28. package/lib/Comment/footer/participants/participant-select/index.js +182 -0
  29. package/lib/Comment/index.css +19 -0
  30. package/lib/Comment/index.js +304 -0
  31. package/lib/Comment/model.js +25 -0
  32. package/lib/Comment/utils/common.js +62 -0
  33. package/lib/Comment/utils/index.js +27 -0
  34. package/lib/Comment/utils/utilities.js +176 -0
  35. package/lib/DTableCustomizeSelect/index.js +2 -2
  36. package/lib/DTableFiltersPopover/utils/index.js +1 -7
  37. package/lib/DTableFiltersPopover/widgets/filter-calendar.js +2 -2
  38. package/lib/DTableGroupSelect/index.js +3 -3
  39. package/lib/DTableSelect/index.js +3 -1
  40. package/lib/DateEditor/index.js +14 -51
  41. package/lib/DateEditor/pc-date-editor-popover.js +149 -12
  42. package/lib/{common/delete-tip.js → DeleteTip/index.js} +12 -16
  43. package/lib/Department-editor/department-single-select.js +1 -1
  44. package/lib/Department-editor/index.js +3 -4
  45. package/lib/DepartmentSingleSelectFormatter/index.js +3 -2
  46. package/lib/DigitalSignEditor/constants.js +7 -0
  47. package/lib/DigitalSignEditor/index.css +69 -0
  48. package/lib/DigitalSignEditor/index.js +182 -0
  49. package/lib/DigitalSignEditor/service.js +39 -0
  50. package/lib/DigitalSignEditor/signature-board/index.css +35 -0
  51. package/lib/DigitalSignEditor/signature-board/index.js +135 -0
  52. package/lib/DigitalSignEditor/signature-board/signature-tool.js +396 -0
  53. package/lib/DigitalSignEditor/utils.js +29 -0
  54. package/lib/DurationEditor/index.js +110 -0
  55. package/lib/EmailEditor/index.js +58 -0
  56. package/lib/FileEditor/addition-previewer/index.css +1 -0
  57. package/lib/FileEditor/addition-previewer/index.js +52 -0
  58. package/lib/FileEditor/addition-previewer/local-file-addition/index.css +1 -0
  59. package/lib/FileEditor/addition-previewer/local-file-addition/index.js +252 -0
  60. package/lib/FileEditor/constants.js +7 -0
  61. package/lib/FileEditor/files-previewer/file-previewer/dropdown-menu.js +74 -0
  62. package/lib/FileEditor/files-previewer/file-previewer/file-name-editor/index.css +5 -0
  63. package/lib/FileEditor/files-previewer/file-previewer/file-name-editor/index.js +77 -0
  64. package/lib/FileEditor/files-previewer/file-previewer/index.css +88 -0
  65. package/lib/FileEditor/files-previewer/file-previewer/index.js +167 -0
  66. package/lib/FileEditor/files-previewer/index.css +56 -0
  67. package/lib/FileEditor/files-previewer/index.js +277 -0
  68. package/lib/FileEditor/index.css +6 -0
  69. package/lib/FileEditor/index.js +258 -11
  70. package/lib/FileEditor/utils.js +22 -0
  71. package/lib/FileItemFormatter/index.js +19 -20
  72. package/lib/FileUploader/index.css +9 -0
  73. package/lib/FileUploader/index.js +268 -14
  74. package/lib/FormulaFormatter/cell-value-validator.js +17 -17
  75. package/lib/FormulaFormatter/index.js +2 -1
  76. package/lib/FormulaFormatter/utils.js +0 -31
  77. package/lib/GeolocationEditor/country-editor.js +319 -0
  78. package/lib/GeolocationEditor/index.css +641 -0
  79. package/lib/GeolocationEditor/index.js +240 -0
  80. package/lib/GeolocationEditor/location-editor.js +368 -0
  81. package/lib/GeolocationEditor/map-editor/index.js +456 -0
  82. package/lib/GeolocationEditor/map-editor/large-editor/index.css +137 -0
  83. package/lib/GeolocationEditor/map-editor/large-editor/index.js +461 -0
  84. package/lib/GeolocationEditor/map-editor-utils.js +153 -0
  85. package/lib/GeolocationEditor/map-selection-editor/index.js +455 -0
  86. package/lib/GeolocationEditor/map-selection-editor/large-editor/index.css +1 -0
  87. package/lib/GeolocationEditor/map-selection-editor/large-editor/index.js +447 -0
  88. package/lib/GeolocationEditor/parse-geolocation.js +282 -0
  89. package/lib/GeolocationEditor/province-city-editor.js +292 -0
  90. package/lib/GeolocationEditor/province-editor.js +226 -0
  91. package/lib/GeolocationEditor/selector-header-item.js +28 -0
  92. package/lib/GeolocationEditor/selector-list.js +33 -0
  93. package/lib/ImageEditor/addition-previewer/image-link/index.css +45 -0
  94. package/lib/ImageEditor/addition-previewer/image-link/index.js +73 -0
  95. package/lib/ImageEditor/addition-previewer/index.css +106 -0
  96. package/lib/ImageEditor/addition-previewer/index.js +63 -0
  97. package/lib/ImageEditor/addition-previewer/local-image-addition/index.css +125 -0
  98. package/lib/ImageEditor/addition-previewer/local-image-addition/index.js +254 -0
  99. package/lib/ImageEditor/constants.js +7 -0
  100. package/lib/ImageEditor/images-previewer/image-preview/index.css +59 -0
  101. package/lib/ImageEditor/images-previewer/image-preview/index.js +155 -0
  102. package/lib/ImageEditor/images-previewer/index.css +18 -0
  103. package/lib/ImageEditor/images-previewer/index.js +140 -0
  104. package/lib/ImageEditor/index.css +24 -0
  105. package/lib/ImageEditor/index.js +194 -0
  106. package/lib/ImageThumbnail/index.css +20 -0
  107. package/lib/ImageThumbnail/index.js +136 -0
  108. package/lib/LinkEditor/index.js +2 -3
  109. package/lib/LinkEditor/pc-link-editor-popover/index.js +1 -1
  110. package/lib/MultipleSelectEditor/index.js +16 -177
  111. package/lib/NumberEditor/index.js +63 -77
  112. package/lib/RowExpandDialog/body/index.css +21 -0
  113. package/lib/RowExpandDialog/body/index.js +262 -0
  114. package/lib/RowExpandDialog/column-content/index.css +48 -0
  115. package/lib/RowExpandDialog/column-content/index.js +50 -0
  116. package/lib/RowExpandDialog/header/index.css +31 -0
  117. package/lib/RowExpandDialog/header/index.js +55 -0
  118. package/lib/RowExpandDialog/index.css +28 -0
  119. package/lib/RowExpandDialog/index.js +237 -0
  120. package/lib/RowExpandEditor/RowExpandAddBtn/index.css +22 -0
  121. package/lib/RowExpandEditor/RowExpandAddBtn/index.js +24 -0
  122. package/lib/RowExpandEditor/RowExpandCheckboxEditor/index.css +18 -0
  123. package/lib/RowExpandEditor/RowExpandCheckboxEditor/index.js +43 -0
  124. package/lib/RowExpandEditor/RowExpandCollaboratorEditor/index.css +5 -0
  125. package/lib/RowExpandEditor/RowExpandCollaboratorEditor/index.js +232 -0
  126. package/lib/RowExpandEditor/RowExpandDateEditor/index.js +130 -0
  127. package/lib/RowExpandEditor/RowExpandDepartmentEditor/index.js +106 -0
  128. package/lib/RowExpandEditor/RowExpandDigitalSignEditor/index.css +13 -0
  129. package/lib/RowExpandEditor/RowExpandDigitalSignEditor/index.js +208 -0
  130. package/lib/RowExpandEditor/RowExpandDurationEditor/index.js +105 -0
  131. package/lib/RowExpandEditor/RowExpandEmailEditor/index.css +2 -0
  132. package/lib/RowExpandEditor/RowExpandEmailEditor/index.js +125 -0
  133. package/lib/RowExpandEditor/RowExpandFileEditor/index.css +1 -0
  134. package/lib/RowExpandEditor/RowExpandFileEditor/index.js +147 -0
  135. package/lib/RowExpandEditor/RowExpandGeolocationEditor/index.css +17 -0
  136. package/lib/RowExpandEditor/RowExpandGeolocationEditor/index.js +165 -0
  137. package/lib/RowExpandEditor/RowExpandImageEditor/index.css +6 -0
  138. package/lib/RowExpandEditor/RowExpandImageEditor/index.js +170 -0
  139. package/lib/RowExpandEditor/RowExpandLongTextEditor/index.css +6 -0
  140. package/lib/RowExpandEditor/RowExpandLongTextEditor/index.js +123 -0
  141. package/lib/RowExpandEditor/RowExpandMultipleSelectEditor/index.css +44 -0
  142. package/lib/RowExpandEditor/RowExpandMultipleSelectEditor/index.js +224 -0
  143. package/lib/RowExpandEditor/RowExpandNumberEditor/index.js +105 -0
  144. package/lib/RowExpandEditor/RowExpandRateEditor/index.css +13 -0
  145. package/lib/RowExpandEditor/RowExpandRateEditor/index.js +152 -0
  146. package/lib/RowExpandEditor/RowExpandSingleSelectorEditor/index.css +58 -0
  147. package/lib/RowExpandEditor/RowExpandSingleSelectorEditor/index.js +193 -0
  148. package/lib/RowExpandEditor/RowExpandTextEditor/index.css +4 -0
  149. package/lib/RowExpandEditor/RowExpandTextEditor/index.js +127 -0
  150. package/lib/RowExpandEditor/RowExpandUrlEditor/index.css +31 -0
  151. package/lib/RowExpandEditor/RowExpandUrlEditor/index.js +130 -0
  152. package/lib/RowExpandEditor/constants.js +44 -0
  153. package/lib/RowExpandEditor/index.css +0 -0
  154. package/lib/RowExpandEditor/index.js +32 -0
  155. package/lib/RowExpandFormatter/RowExpandDepartmentFormatter/index.js +27 -0
  156. package/lib/{RowExpandEmailFormatter → RowExpandFormatter/RowExpandEmailFormatter}/index.css +1 -1
  157. package/lib/{RowExpandEmailFormatter → RowExpandFormatter/RowExpandEmailFormatter}/index.js +1 -1
  158. package/lib/{RowExpandFileFormatter → RowExpandFormatter/RowExpandFileFormatter}/index.css +6 -6
  159. package/lib/{RowExpandFileFormatter → RowExpandFormatter/RowExpandFileFormatter}/index.js +3 -1
  160. package/lib/{RowExpandFileFormatter → RowExpandFormatter/RowExpandFileFormatter}/row-expand-file-item-formatter.js +12 -13
  161. package/lib/{RowExpandFormulaFormatter → RowExpandFormatter/RowExpandFormulaFormatter}/index.js +11 -10
  162. package/lib/{RowExpandImageFormatter → RowExpandFormatter/RowExpandImageFormatter}/index.css +6 -6
  163. package/lib/{RowExpandImageFormatter → RowExpandFormatter/RowExpandImageFormatter}/index.js +1 -1
  164. package/lib/{RowExpandImageFormatter → RowExpandFormatter/RowExpandImageFormatter}/row-expand-image-item-formatter.js +5 -5
  165. package/lib/{RowExpandLinkFormatter → RowExpandFormatter/RowExpandLinkFormatter}/collaborator-item-formatter.js +1 -1
  166. package/lib/{RowExpandLinkFormatter → RowExpandFormatter/RowExpandLinkFormatter}/index.css +2 -2
  167. package/lib/{RowExpandLinkFormatter → RowExpandFormatter/RowExpandLinkFormatter}/index.js +20 -20
  168. package/lib/{RowExpandRateFormatter → RowExpandFormatter/RowExpandRateFormatter}/index.css +1 -1
  169. package/lib/RowExpandFormatter/RowExpandUrlFormatter/index.css +1 -0
  170. package/lib/{RowExpandUrlFormatter → RowExpandFormatter/RowExpandUrlFormatter}/index.js +4 -3
  171. package/lib/RowExpandFormatter/constants.js +61 -0
  172. package/lib/RowExpandFormatter/index.css +28 -3
  173. package/lib/RowExpandFormatter/index.js +113 -131
  174. package/lib/SingleSelectEditor/index.js +16 -156
  175. package/lib/SvgIcon/index.css +11 -0
  176. package/lib/SvgIcon/index.js +29 -0
  177. package/lib/TextEditor/index.js +112 -42
  178. package/lib/UploadProgress/index.js +38 -0
  179. package/lib/UrlEditor/index.js +61 -0
  180. package/lib/common/editor-base.js +52 -0
  181. package/lib/constants/file.js +96 -0
  182. package/lib/constants/index.js +27 -15
  183. package/lib/constants/key-codes.js +109 -0
  184. package/lib/css/cell-editor.css +18 -2
  185. package/lib/formatterConfig/base-formatter-config.js +23 -23
  186. package/lib/formatterConfig/index.js +3 -3
  187. package/lib/hooks/index.js +16 -0
  188. package/lib/index.js +81 -46
  189. package/lib/lang/index.js +19 -16
  190. package/lib/locales/de.json +167 -0
  191. package/lib/locales/en.json +167 -0
  192. package/lib/locales/es.json +167 -0
  193. package/lib/locales/fr.json +167 -0
  194. package/lib/locales/pt.json +167 -0
  195. package/lib/locales/ru.json +167 -0
  196. package/lib/locales/zh-CN.json +167 -0
  197. package/lib/select-editor/index.js +6 -6
  198. package/lib/select-editor/{mb-select-editor-popover → mb-select-editor}/index.js +3 -3
  199. package/lib/select-editor/pc-select-editor/index.css +85 -0
  200. package/lib/select-editor/pc-select-editor/index.js +290 -0
  201. package/lib/utils/cell-comparer.js +35 -0
  202. package/lib/utils/cell.js +55 -0
  203. package/lib/utils/column-utils.js +25 -0
  204. package/lib/utils/editor-utils.js +1 -6
  205. package/lib/utils/get-event-transfer.js +75 -0
  206. package/lib/utils/hotkey.js +37 -0
  207. package/lib/utils/object-utils.js +61 -0
  208. package/lib/utils/url.js +121 -8
  209. package/lib/utils/utils.js +119 -2
  210. package/package.json +3 -2
  211. package/lib/CollaboratorEditor/pc-collaborator-editor-popover/index.js +0 -97
  212. package/lib/FileEditor/pc-files-addition/index.js +0 -1
  213. package/lib/FileEditor/pc-files-addition/pc-file-uploaded-item.js +0 -1
  214. package/lib/FileEditor/pc-files-preview/index.js +0 -1
  215. package/lib/FileEditor/pc-files-preview/pc-file-item-preview.js +0 -1
  216. package/lib/FileItemFormatter/assets/file/192/excel.png +0 -0
  217. package/lib/FileItemFormatter/assets/file/192/file.png +0 -0
  218. package/lib/FileItemFormatter/assets/file/192/music.png +0 -0
  219. package/lib/FileItemFormatter/assets/file/192/pdf.png +0 -0
  220. package/lib/FileItemFormatter/assets/file/192/pic.png +0 -0
  221. package/lib/FileItemFormatter/assets/file/192/ppt.png +0 -0
  222. package/lib/FileItemFormatter/assets/file/192/txt.png +0 -0
  223. package/lib/FileItemFormatter/assets/file/192/video.png +0 -0
  224. package/lib/FileItemFormatter/assets/file/192/word.png +0 -0
  225. package/lib/FileItemFormatter/assets/file/24/excel.png +0 -0
  226. package/lib/FileItemFormatter/assets/file/24/file.png +0 -0
  227. package/lib/FileItemFormatter/assets/file/24/music.png +0 -0
  228. package/lib/FileItemFormatter/assets/file/24/pdf.png +0 -0
  229. package/lib/FileItemFormatter/assets/file/24/pic.png +0 -0
  230. package/lib/FileItemFormatter/assets/file/24/ppt.png +0 -0
  231. package/lib/FileItemFormatter/assets/file/24/txt.png +0 -0
  232. package/lib/FileItemFormatter/assets/file/24/video.png +0 -0
  233. package/lib/FileItemFormatter/assets/file/24/word.png +0 -0
  234. package/lib/FileItemFormatter/assets/folder/folder-192.png +0 -0
  235. package/lib/FileItemFormatter/assets/folder/folder-24.png +0 -0
  236. package/lib/FileItemFormatter/utils.js +0 -99
  237. package/lib/MultipleSelectEditor/index.css +0 -9
  238. package/lib/RowExpandLinkFormatter/utils.js +0 -71
  239. package/lib/RowExpandUrlFormatter/index.css +0 -1
  240. package/lib/SingleSelectEditor/index.css +0 -14
  241. package/lib/common/modal-portal.js +0 -26
  242. package/lib/locals/de.js +0 -103
  243. package/lib/locals/en.js +0 -104
  244. package/lib/locals/es.js +0 -103
  245. package/lib/locals/fr.js +0 -103
  246. package/lib/locals/pt.js +0 -103
  247. package/lib/locals/ru.js +0 -103
  248. package/lib/locals/zh-CN.js +0 -104
  249. package/lib/select-editor/pc-select-editor-popover/index.css +0 -71
  250. package/lib/select-editor/pc-select-editor-popover/index.js +0 -122
  251. /package/lib/CollaboratorEditor/{mb-collaborator-editor-popover → mb-collaborator-editor}/index.css +0 -0
  252. /package/lib/CollaboratorEditor/{pc-collaborator-editor-popover → pc-collaborator-editor}/index.css +0 -0
  253. /package/lib/{common/delete-tip.css → DeleteTip/index.css} +0 -0
  254. /package/lib/{RowExpandLinkFormatter → RowExpandFormatter/RowExpandLinkFormatter}/value-display-utils.js +0 -0
  255. /package/lib/{RowExpandRateFormatter → RowExpandFormatter/RowExpandRateFormatter}/index.js +0 -0
  256. /package/lib/select-editor/{mb-select-editor-popover → mb-select-editor}/index.css +0 -0
@@ -0,0 +1,319 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+ var _react = _interopRequireWildcard(require("react"));
10
+ var _reactstrap = require("reactstrap");
11
+ var _constants = require("../constants");
12
+ var _Loading = _interopRequireDefault(require("../Loading"));
13
+ var _lang = require("../lang");
14
+ class CountryEditor extends _react.Component {
15
+ constructor(props) {
16
+ super(props);
17
+ this.onHotKey = e => {
18
+ if (e.keyCode === _constants.KeyCodes.Enter) {
19
+ this.onEnter(e);
20
+ } else if (e.keyCode === _constants.KeyCodes.UpArrow) {
21
+ this.onUpArrow(e);
22
+ } else if (e.keyCode === _constants.KeyCodes.DownArrow) {
23
+ this.onDownArrow(e);
24
+ } else if (e.keyCode === _constants.KeyCodes.Tab) {
25
+ if (this.props.onPressTab) {
26
+ this.props.onPressTab(e);
27
+ }
28
+ }
29
+ };
30
+ this.onDownArrow = e => {
31
+ e.preventDefault();
32
+ e.stopPropagation();
33
+ let {
34
+ highlightIndexes
35
+ } = this.state;
36
+ const continents = Object.keys(this.filteredCountry);
37
+ if (continents.length === 0) return;
38
+ const continent = continents[highlightIndexes[0]];
39
+ if (highlightIndexes[1] < this.filteredCountry[continent].length - 1) {
40
+ highlightIndexes[1] = highlightIndexes[1] + 1;
41
+ } else if (highlightIndexes[1] === this.filteredCountry[continent].length - 1 && highlightIndexes[0] < continents.length - 1) {
42
+ highlightIndexes[0] = highlightIndexes[0] + 1;
43
+ highlightIndexes[1] = 0;
44
+ }
45
+ this.setState({
46
+ highlightIndexes: [...highlightIndexes]
47
+ }, () => {
48
+ let itemCount = this.getItemCount(highlightIndexes[0], highlightIndexes[1]);
49
+ if (itemCount >= this.maxItemNum) {
50
+ this.selectContainer.scrollTop += this.itemHeight * (highlightIndexes[1] === 0 ? 2 : 1);
51
+ }
52
+ });
53
+ };
54
+ this.onUpArrow = e => {
55
+ e.preventDefault();
56
+ e.stopPropagation();
57
+ let {
58
+ highlightIndexes
59
+ } = this.state;
60
+ const continents = Object.keys(this.filteredCountry);
61
+ if (continents.length === 0) return;
62
+ if (highlightIndexes[1] === 0 && highlightIndexes[0] !== 0) {
63
+ highlightIndexes[0] = highlightIndexes[0] - 1;
64
+ highlightIndexes[1] = this.filteredCountry[continents[highlightIndexes[0]]].length - 1;
65
+ } else if (highlightIndexes[1] === 0 && highlightIndexes[0] === 0) {
66
+ highlightIndexes = [0, 0];
67
+ } else {
68
+ highlightIndexes[1] = highlightIndexes[1] - 1;
69
+ }
70
+ this.setState({
71
+ highlightIndexes: [...highlightIndexes]
72
+ }, () => {
73
+ let itemCount = this.getItemCount(highlightIndexes[0], highlightIndexes[1]);
74
+ if (itemCount < this.getItemCount(continents.length - 1, this.filteredCountry[continents[continents.length - 1]].length - 1) - this.maxItemNum) {
75
+ this.selectContainer.scrollTop -= this.itemHeight * (highlightIndexes[1] === 0 ? 2 : 1);
76
+ }
77
+ });
78
+ };
79
+ this.getItemCount = (continentIndex, countryIndex) => {
80
+ const continents = Object.keys(this.filteredCountry);
81
+ let count = continentIndex + 1;
82
+ for (let index = 0; index < continentIndex; index++) {
83
+ count += this.filteredCountry[continents[index]].length;
84
+ }
85
+ count = count + countryIndex;
86
+ return count;
87
+ };
88
+ this.onEnter = e => {
89
+ e.stopPropagation();
90
+ const cuntries = Object.values(this.filteredCountry).flat();
91
+ if (cuntries && cuntries.length === 1) {
92
+ this.props.setValue({
93
+ country_region: cuntries[0]
94
+ });
95
+ this.props.onSubmit();
96
+ } else {
97
+ const {
98
+ highlightIndexes
99
+ } = this.state;
100
+ const continents = Object.keys(this.filteredCountry);
101
+ if (continents.length > 0) {
102
+ const continent = continents[highlightIndexes[0]];
103
+ const country = this.filteredCountry[continent][highlightIndexes[1]];
104
+ if (!country) return;
105
+ this.props.setValue({
106
+ country_region: country
107
+ });
108
+ this.props.onSubmit();
109
+ }
110
+ }
111
+ };
112
+ this.onMenuMouseEnter = (continentIndex, countryIndex) => {
113
+ this.setState({
114
+ highlightIndexes: [continentIndex, countryIndex]
115
+ });
116
+ };
117
+ this.onMenuMouseLeave = (continentIndex, countryIndex) => {
118
+ this.timer = setTimeout(() => {
119
+ const {
120
+ highlightIndexes
121
+ } = this.state;
122
+ if (highlightIndexes[0] === continentIndex && highlightIndexes[1] === countryIndex) {
123
+ this.setState({
124
+ highlightIndexes: [0, -1]
125
+ });
126
+ }
127
+ }, 300);
128
+ };
129
+ this.getLocationData = () => {
130
+ const {
131
+ config
132
+ } = this.props;
133
+ const {
134
+ mediaUrl
135
+ } = {
136
+ ...window.dtable,
137
+ ...config
138
+ };
139
+ let geoFileName = 'en-region-location';
140
+ if (this.lang === 'cn') {
141
+ geoFileName = 'cn-region-location';
142
+ }
143
+ return fetch("".concat(mediaUrl, "geo-data/").concat(geoFileName, ".json")).then(res => {
144
+ return res.json();
145
+ }).catch(() => {
146
+ // get locations from local
147
+ return fetch("./geo-data/".concat(geoFileName, ".json")).then(res => {
148
+ return res.json();
149
+ });
150
+ });
151
+ };
152
+ this.createContinentList = () => {
153
+ let isSearchResultEmpty = true;
154
+ const continents = Object.keys(this.filteredCountry);
155
+ const continentsList = continents.map((continent, index) => {
156
+ const countryList = this.createCountryList(continent, index);
157
+ if (countryList.length > 0) {
158
+ isSearchResultEmpty = false;
159
+ return /*#__PURE__*/_react.default.createElement(_react.Fragment, {
160
+ key: continent
161
+ }, /*#__PURE__*/_react.default.createElement("div", {
162
+ className: "geolocation-region-editor-continent"
163
+ }, continent), countryList);
164
+ }
165
+ return null;
166
+ });
167
+ if (isSearchResultEmpty) {
168
+ return /*#__PURE__*/_react.default.createElement("div", {
169
+ className: "country-list-empty"
170
+ }, (0, _lang.getLocale)('No_options'));
171
+ }
172
+ return continentsList;
173
+ };
174
+ this.createCountryList = (continent, continentIndex) => {
175
+ const {
176
+ value,
177
+ highlightIndexes
178
+ } = this.state;
179
+ let countryList = this.filteredCountry[continent].map((country, index) => {
180
+ const isHighlight = highlightIndexes[0] === continentIndex && highlightIndexes[1] === index;
181
+ return /*#__PURE__*/_react.default.createElement("div", {
182
+ className: "geolocation-region-editor-country ".concat(isHighlight ? 'geolocation-region-editor-province-highlight' : ''),
183
+ key: country,
184
+ onMouseEnter: () => this.onMenuMouseEnter(continentIndex, index),
185
+ onMouseLeave: () => this.onMenuMouseLeave(continentIndex, index),
186
+ title: country,
187
+ "aria-label": country,
188
+ onClick: () => this.onClick(country)
189
+ }, /*#__PURE__*/_react.default.createElement("span", {
190
+ className: "icon ".concat(value === country ? 'dtable-font dtable-icon-check-mark' : '')
191
+ }), /*#__PURE__*/_react.default.createElement("span", {
192
+ className: "country-name"
193
+ }, country));
194
+ });
195
+ return countryList;
196
+ };
197
+ this.onClick = country => {
198
+ this.props.setValue({
199
+ country_region: country
200
+ });
201
+ this.props.onSubmit();
202
+ };
203
+ this.onChange = e => {
204
+ const value = e.target.value.trim();
205
+ if (value.length === 0) {
206
+ this.countryReg = null;
207
+ }
208
+ if (value.length > 0) {
209
+ let regStr = '(.*)' + value.split('').join('(.*)') + '(.*)';
210
+ this.countryReg = new RegExp(regStr, 'i');
211
+ }
212
+ this.filteredCountry = this.filterCountry();
213
+ this.setState({
214
+ searchingCountry: e.target.value,
215
+ highlightIndexes: Object.keys(this.filteredCountry).length > 0 ? [0, 0] : [0, -1]
216
+ });
217
+ };
218
+ this.filterCountry = () => {
219
+ const continents = Object.keys(this.geolocationRegions);
220
+ const map = {};
221
+ for (let i = 0; i < continents.length; i++) {
222
+ const countries = this.geolocationRegions[continents[i]];
223
+ const continent = continents[i];
224
+ map[continent] = [];
225
+ countries.forEach(item => {
226
+ if (this.countryReg && this.countryReg.test(item)) {
227
+ map[continent].push(item);
228
+ } else if (!this.countryReg) {
229
+ map[continent].push(item);
230
+ }
231
+ });
232
+ if (map[continent].length === 0) {
233
+ delete map[continent];
234
+ }
235
+ }
236
+ return map;
237
+ };
238
+ this.onKeyDown = e => {
239
+ if (e.keyCode === _constants.KeyCodes.ChineseInputMethod || e.keyCode === _constants.KeyCodes.Enter || e.keyCode === _constants.KeyCodes.LeftArrow || e.keyCode === _constants.KeyCodes.RightArrow) {
240
+ e.stopPropagation();
241
+ }
242
+ };
243
+ this.countryReg = null;
244
+ const {
245
+ column,
246
+ value: _value
247
+ } = props;
248
+ const columnData = column.data || {};
249
+ this.lang = columnData.lang === 'cn' ? 'cn' : 'en';
250
+ this.state = {
251
+ searchingCountry: '',
252
+ value: _value.country_region,
253
+ isLoadingData: true,
254
+ highlightIndexes: [0, -1]
255
+ };
256
+ this.filteredCountry = [];
257
+ this.timer = null;
258
+ this.maxItemNum = 6;
259
+ this.itemHeight = 30;
260
+ }
261
+ componentDidMount() {
262
+ document.addEventListener('keydown', this.onHotKey, true);
263
+ if (this.lang === 'cn' && window.app.countryListCn) {
264
+ this.geolocationRegions = window.app.countryListCn;
265
+ this.filteredCountry = this.geolocationRegions;
266
+ this.setState({
267
+ isLoadingData: false
268
+ });
269
+ return;
270
+ }
271
+ if (this.lang !== 'cn' && window.app.countryListEn) {
272
+ this.geolocationRegions = window.app.countryListEn;
273
+ this.filteredCountry = this.geolocationRegions;
274
+ this.setState({
275
+ isLoadingData: false
276
+ });
277
+ return;
278
+ }
279
+ this.getLocationData().then(data => {
280
+ this.geolocationRegions = data || {};
281
+ this.filteredCountry = this.geolocationRegions;
282
+ if (this.lang === 'cn') {
283
+ window.app.countryListCn = this.geolocationRegions;
284
+ } else {
285
+ window.app.countryListEn = this.geolocationRegions;
286
+ }
287
+ this.setState({
288
+ isLoadingData: false
289
+ });
290
+ });
291
+ }
292
+ componentWillUnmount() {
293
+ document.removeEventListener('keydown', this.onHotKey, true);
294
+ if (this.timer) {
295
+ clearTimeout(this.timer);
296
+ this.timer = null;
297
+ }
298
+ }
299
+ render() {
300
+ const {
301
+ isLoadingData
302
+ } = this.state;
303
+ return /*#__PURE__*/_react.default.createElement("div", {
304
+ className: "dtable-ui-geolocation-country-editor"
305
+ }, /*#__PURE__*/_react.default.createElement("div", {
306
+ className: "geolocation-region-list-header"
307
+ }, /*#__PURE__*/_react.default.createElement(_reactstrap.Input, {
308
+ value: this.state.searchingCountry,
309
+ onChange: this.onChange,
310
+ autoFocus: true,
311
+ onKeyDown: this.onKeyDown,
312
+ placeholder: (0, _lang.getLocale)('Search_country')
313
+ })), /*#__PURE__*/_react.default.createElement("div", {
314
+ className: "geolocation-region-list-container",
315
+ ref: ref => this.selectContainer = ref
316
+ }, isLoadingData ? /*#__PURE__*/_react.default.createElement(_Loading.default, null) : this.createContinentList()));
317
+ }
318
+ }
319
+ var _default = exports.default = CountryEditor;