dtable-ui-component 5.3.0-alpha1 → 5.3.1-beta

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 (223) hide show
  1. package/lib/CheckboxEditor/index.css +3 -20
  2. package/lib/CheckboxEditor/index.js +98 -35
  3. package/lib/CheckboxFormatter/index.js +6 -9
  4. package/lib/CollaboratorEditor/index.css +12 -35
  5. package/lib/CollaboratorEditor/index.js +18 -212
  6. package/lib/CollaboratorEditor/{mb-collaborator-editor-popover → mb-collaborator-editor}/index.js +26 -29
  7. package/lib/CollaboratorEditor/pc-collaborator-editor/index.js +257 -0
  8. package/lib/CollaboratorItem/index.css +1 -1
  9. package/lib/CollaboratorItem/index.js +6 -2
  10. package/lib/DTableFiltersPopover/utils/index.js +1 -7
  11. package/lib/DTableFiltersPopover/widgets/filter-calendar.js +2 -2
  12. package/lib/DTableSelect/index.js +3 -1
  13. package/lib/DateEditor/index.js +14 -51
  14. package/lib/DateEditor/pc-date-editor-popover.js +145 -12
  15. package/lib/DeleteTip/index.js +50 -0
  16. package/lib/Department-editor/department-single-select.js +1 -1
  17. package/lib/Department-editor/index.js +3 -4
  18. package/lib/DepartmentSingleSelectFormatter/index.js +2 -1
  19. package/lib/DigitalSignEditor/constants.js +7 -0
  20. package/lib/DigitalSignEditor/index.css +69 -0
  21. package/lib/DigitalSignEditor/index.js +182 -0
  22. package/lib/DigitalSignEditor/service.js +38 -0
  23. package/lib/DigitalSignEditor/signature-board/index.css +35 -0
  24. package/lib/DigitalSignEditor/signature-board/index.js +135 -0
  25. package/lib/DigitalSignEditor/signature-board/signature-tool.js +396 -0
  26. package/lib/DigitalSignEditor/utils.js +29 -0
  27. package/lib/DurationEditor/index.js +111 -0
  28. package/lib/EmailEditor/index.js +59 -0
  29. package/lib/FileEditor/addition-previewer/index.css +1 -0
  30. package/lib/FileEditor/addition-previewer/index.js +52 -0
  31. package/lib/FileEditor/addition-previewer/local-file-addition/index.css +1 -0
  32. package/lib/FileEditor/addition-previewer/local-file-addition/index.js +252 -0
  33. package/lib/FileEditor/constants.js +7 -0
  34. package/lib/FileEditor/files-previewer/file-previewer/dropdown-menu.js +74 -0
  35. package/lib/FileEditor/files-previewer/file-previewer/file-name-editor/index.css +5 -0
  36. package/lib/FileEditor/files-previewer/file-previewer/file-name-editor/index.js +77 -0
  37. package/lib/FileEditor/files-previewer/file-previewer/index.css +88 -0
  38. package/lib/FileEditor/files-previewer/file-previewer/index.js +167 -0
  39. package/lib/FileEditor/files-previewer/index.css +56 -0
  40. package/lib/FileEditor/files-previewer/index.js +277 -0
  41. package/lib/FileEditor/index.css +6 -0
  42. package/lib/FileEditor/index.js +244 -11
  43. package/lib/FileEditor/utils.js +22 -0
  44. package/lib/FileItemFormatter/index.js +19 -20
  45. package/lib/FileUploader/index.css +9 -0
  46. package/lib/FileUploader/index.js +268 -14
  47. package/lib/FormulaFormatter/index.js +2 -1
  48. package/lib/FormulaFormatter/utils.js +0 -31
  49. package/lib/GeolocationEditor/country-editor.js +319 -0
  50. package/lib/GeolocationEditor/index.css +641 -0
  51. package/lib/GeolocationEditor/index.js +241 -0
  52. package/lib/GeolocationEditor/location-editor.js +368 -0
  53. package/lib/GeolocationEditor/map-editor/index.js +456 -0
  54. package/lib/GeolocationEditor/map-editor/large-editor/index.css +137 -0
  55. package/lib/GeolocationEditor/map-editor/large-editor/index.js +461 -0
  56. package/lib/GeolocationEditor/map-editor-utils.js +153 -0
  57. package/lib/GeolocationEditor/map-selection-editor/index.js +455 -0
  58. package/lib/GeolocationEditor/map-selection-editor/large-editor/index.css +1 -0
  59. package/lib/GeolocationEditor/map-selection-editor/large-editor/index.js +447 -0
  60. package/lib/GeolocationEditor/parse-geolocation.js +282 -0
  61. package/lib/GeolocationEditor/province-city-editor.js +292 -0
  62. package/lib/GeolocationEditor/province-editor.js +226 -0
  63. package/lib/GeolocationEditor/selector-header-item.js +28 -0
  64. package/lib/GeolocationEditor/selector-list.js +33 -0
  65. package/lib/GeolocationEditor/with-ref.js +27 -0
  66. package/lib/ImageEditor/addition-previewer/image-link/index.css +45 -0
  67. package/lib/ImageEditor/addition-previewer/image-link/index.js +73 -0
  68. package/lib/ImageEditor/addition-previewer/index.css +106 -0
  69. package/lib/ImageEditor/addition-previewer/index.js +63 -0
  70. package/lib/ImageEditor/addition-previewer/local-image-addition/index.css +125 -0
  71. package/lib/ImageEditor/addition-previewer/local-image-addition/index.js +254 -0
  72. package/lib/ImageEditor/constants.js +7 -0
  73. package/lib/ImageEditor/images-previewer/image-preview/index.css +59 -0
  74. package/lib/ImageEditor/images-previewer/image-preview/index.js +155 -0
  75. package/lib/ImageEditor/images-previewer/index.css +18 -0
  76. package/lib/ImageEditor/images-previewer/index.js +140 -0
  77. package/lib/ImageEditor/index.css +24 -0
  78. package/lib/ImageEditor/index.js +194 -0
  79. package/lib/ImageThumbnail/index.css +20 -0
  80. package/lib/ImageThumbnail/index.js +136 -0
  81. package/lib/LinkEditor/pc-link-editor-popover/index.js +1 -1
  82. package/lib/MultipleSelectEditor/index.js +16 -177
  83. package/lib/NumberEditor/index.js +64 -77
  84. package/lib/RowExpandDialog/body/index.css +21 -0
  85. package/lib/RowExpandDialog/body/index.js +279 -0
  86. package/lib/RowExpandDialog/column-content/index.css +43 -0
  87. package/lib/RowExpandDialog/column-content/index.js +50 -0
  88. package/lib/RowExpandDialog/constants.js +114 -0
  89. package/lib/RowExpandDialog/header/index.css +31 -0
  90. package/lib/RowExpandDialog/header/index.js +33 -0
  91. package/lib/RowExpandDialog/index.css +24 -0
  92. package/lib/RowExpandDialog/index.js +268 -0
  93. package/lib/RowExpandDialog/utils.js +83 -0
  94. package/lib/RowExpandEditor/RowExpandAddBtn/index.css +22 -0
  95. package/lib/RowExpandEditor/RowExpandAddBtn/index.js +24 -0
  96. package/lib/RowExpandEditor/RowExpandCheckboxEditor/index.css +18 -0
  97. package/lib/RowExpandEditor/RowExpandCheckboxEditor/index.js +43 -0
  98. package/lib/RowExpandEditor/RowExpandCollaboratorEditor/index.css +5 -0
  99. package/lib/RowExpandEditor/RowExpandCollaboratorEditor/index.js +232 -0
  100. package/lib/RowExpandEditor/RowExpandDateEditor/index.js +130 -0
  101. package/lib/RowExpandEditor/RowExpandDepartmentEditor/index.js +129 -0
  102. package/lib/RowExpandEditor/RowExpandDigitalSignEditor/index.css +13 -0
  103. package/lib/RowExpandEditor/RowExpandDigitalSignEditor/index.js +208 -0
  104. package/lib/RowExpandEditor/RowExpandDurationEditor/index.js +105 -0
  105. package/lib/RowExpandEditor/RowExpandEmailEditor/index.css +2 -0
  106. package/lib/RowExpandEditor/RowExpandEmailEditor/index.js +125 -0
  107. package/lib/RowExpandEditor/RowExpandFileEditor/index.css +1 -0
  108. package/lib/RowExpandEditor/RowExpandFileEditor/index.js +146 -0
  109. package/lib/RowExpandEditor/RowExpandGeolocationEditor/index.css +17 -0
  110. package/lib/RowExpandEditor/RowExpandGeolocationEditor/index.js +165 -0
  111. package/lib/RowExpandEditor/RowExpandImageEditor/index.css +6 -0
  112. package/lib/RowExpandEditor/RowExpandImageEditor/index.js +170 -0
  113. package/lib/RowExpandEditor/RowExpandLongTextEditor/index.css +6 -0
  114. package/lib/RowExpandEditor/RowExpandLongTextEditor/index.js +124 -0
  115. package/lib/RowExpandEditor/RowExpandMultipleSelectEditor/index.css +44 -0
  116. package/lib/RowExpandEditor/RowExpandMultipleSelectEditor/index.js +224 -0
  117. package/lib/RowExpandEditor/RowExpandNumberEditor/index.js +105 -0
  118. package/lib/RowExpandEditor/RowExpandRateEditor/index.css +13 -0
  119. package/lib/RowExpandEditor/RowExpandRateEditor/index.js +152 -0
  120. package/lib/RowExpandEditor/RowExpandSingleSelectorEditor/index.css +58 -0
  121. package/lib/RowExpandEditor/RowExpandSingleSelectorEditor/index.js +192 -0
  122. package/lib/RowExpandEditor/RowExpandTextEditor/index.css +4 -0
  123. package/lib/RowExpandEditor/RowExpandTextEditor/index.js +127 -0
  124. package/lib/RowExpandEditor/RowExpandUrlEditor/index.css +31 -0
  125. package/lib/RowExpandEditor/RowExpandUrlEditor/index.js +130 -0
  126. package/lib/RowExpandEditor/constants.js +44 -0
  127. package/lib/RowExpandEditor/index.css +0 -0
  128. package/lib/RowExpandEditor/index.js +32 -0
  129. package/lib/RowExpandFormatter/RowExpandDepartmentFormatter/index.js +27 -0
  130. package/lib/{RowExpandEmailFormatter → RowExpandFormatter/RowExpandEmailFormatter}/index.css +1 -1
  131. package/lib/{RowExpandEmailFormatter → RowExpandFormatter/RowExpandEmailFormatter}/index.js +1 -1
  132. package/lib/{RowExpandFileFormatter → RowExpandFormatter/RowExpandFileFormatter}/index.css +6 -6
  133. package/lib/{RowExpandFileFormatter → RowExpandFormatter/RowExpandFileFormatter}/index.js +3 -1
  134. package/lib/{RowExpandFileFormatter → RowExpandFormatter/RowExpandFileFormatter}/row-expand-file-item-formatter.js +10 -11
  135. package/lib/{RowExpandFormulaFormatter → RowExpandFormatter/RowExpandFormulaFormatter}/index.js +11 -10
  136. package/lib/{RowExpandImageFormatter → RowExpandFormatter/RowExpandImageFormatter}/index.css +6 -6
  137. package/lib/{RowExpandImageFormatter → RowExpandFormatter/RowExpandImageFormatter}/index.js +1 -1
  138. package/lib/{RowExpandImageFormatter → RowExpandFormatter/RowExpandImageFormatter}/row-expand-image-item-formatter.js +3 -3
  139. package/lib/{RowExpandLinkFormatter → RowExpandFormatter/RowExpandLinkFormatter}/collaborator-item-formatter.js +1 -1
  140. package/lib/{RowExpandLinkFormatter → RowExpandFormatter/RowExpandLinkFormatter}/index.js +5 -5
  141. package/lib/{RowExpandLinkFormatter → RowExpandFormatter/RowExpandLinkFormatter}/utils.js +1 -1
  142. package/lib/{RowExpandRateFormatter → RowExpandFormatter/RowExpandRateFormatter}/index.css +1 -1
  143. package/lib/RowExpandFormatter/RowExpandUrlFormatter/index.css +1 -0
  144. package/lib/{RowExpandUrlFormatter → RowExpandFormatter/RowExpandUrlFormatter}/index.js +4 -3
  145. package/lib/RowExpandFormatter/constants.js +60 -0
  146. package/lib/RowExpandFormatter/index.css +26 -0
  147. package/lib/RowExpandFormatter/index.js +84 -100
  148. package/lib/SingleSelectEditor/index.js +16 -156
  149. package/lib/TextEditor/index.js +113 -42
  150. package/lib/UploadProgress/index.js +38 -0
  151. package/lib/UrlEditor/index.js +62 -0
  152. package/lib/common/editor-base.js +53 -0
  153. package/lib/constants/file.js +96 -0
  154. package/lib/constants/index.js +34 -2
  155. package/lib/constants/key-codes.js +109 -0
  156. package/lib/css/cell-editor.css +18 -2
  157. package/lib/hooks/index.js +16 -0
  158. package/lib/index.js +74 -46
  159. package/lib/lang/index.js +16 -14
  160. package/lib/locales/de.json +163 -0
  161. package/lib/locales/en.json +163 -0
  162. package/lib/locales/es.json +163 -0
  163. package/lib/locales/fr.json +163 -0
  164. package/lib/locales/pt.json +163 -0
  165. package/lib/locales/ru.json +163 -0
  166. package/lib/locales/zh-CN.json +163 -0
  167. package/lib/select-editor/index.js +6 -6
  168. package/lib/select-editor/{mb-select-editor-popover → mb-select-editor}/index.js +3 -3
  169. package/lib/select-editor/pc-select-editor/index.css +85 -0
  170. package/lib/select-editor/pc-select-editor/index.js +290 -0
  171. package/lib/utils/cell-comparer.js +35 -0
  172. package/lib/utils/cell.js +55 -0
  173. package/lib/utils/column-utils.js +25 -0
  174. package/lib/utils/editor-utils.js +1 -6
  175. package/lib/utils/get-event-transfer.js +75 -0
  176. package/lib/utils/object-utils.js +61 -0
  177. package/lib/utils/url.js +119 -8
  178. package/lib/utils/utils.js +89 -2
  179. package/package.json +3 -2
  180. package/lib/CollaboratorEditor/pc-collaborator-editor-popover/index.js +0 -97
  181. package/lib/FileEditor/pc-files-addition/index.js +0 -1
  182. package/lib/FileEditor/pc-files-addition/pc-file-uploaded-item.js +0 -1
  183. package/lib/FileEditor/pc-files-preview/index.js +0 -1
  184. package/lib/FileEditor/pc-files-preview/pc-file-item-preview.js +0 -1
  185. package/lib/FileItemFormatter/assets/file/192/excel.png +0 -0
  186. package/lib/FileItemFormatter/assets/file/192/file.png +0 -0
  187. package/lib/FileItemFormatter/assets/file/192/music.png +0 -0
  188. package/lib/FileItemFormatter/assets/file/192/pdf.png +0 -0
  189. package/lib/FileItemFormatter/assets/file/192/pic.png +0 -0
  190. package/lib/FileItemFormatter/assets/file/192/ppt.png +0 -0
  191. package/lib/FileItemFormatter/assets/file/192/txt.png +0 -0
  192. package/lib/FileItemFormatter/assets/file/192/video.png +0 -0
  193. package/lib/FileItemFormatter/assets/file/192/word.png +0 -0
  194. package/lib/FileItemFormatter/assets/file/24/excel.png +0 -0
  195. package/lib/FileItemFormatter/assets/file/24/file.png +0 -0
  196. package/lib/FileItemFormatter/assets/file/24/music.png +0 -0
  197. package/lib/FileItemFormatter/assets/file/24/pdf.png +0 -0
  198. package/lib/FileItemFormatter/assets/file/24/pic.png +0 -0
  199. package/lib/FileItemFormatter/assets/file/24/ppt.png +0 -0
  200. package/lib/FileItemFormatter/assets/file/24/txt.png +0 -0
  201. package/lib/FileItemFormatter/assets/file/24/video.png +0 -0
  202. package/lib/FileItemFormatter/assets/file/24/word.png +0 -0
  203. package/lib/FileItemFormatter/assets/folder/folder-192.png +0 -0
  204. package/lib/FileItemFormatter/assets/folder/folder-24.png +0 -0
  205. package/lib/FileItemFormatter/utils.js +0 -99
  206. package/lib/MultipleSelectEditor/index.css +0 -9
  207. package/lib/RowExpandUrlFormatter/index.css +0 -1
  208. package/lib/SingleSelectEditor/index.css +0 -14
  209. package/lib/locals/de.js +0 -103
  210. package/lib/locals/en.js +0 -104
  211. package/lib/locals/es.js +0 -103
  212. package/lib/locals/fr.js +0 -103
  213. package/lib/locals/pt.js +0 -103
  214. package/lib/locals/ru.js +0 -103
  215. package/lib/locals/zh-CN.js +0 -104
  216. package/lib/select-editor/pc-select-editor-popover/index.css +0 -71
  217. package/lib/select-editor/pc-select-editor-popover/index.js +0 -122
  218. /package/lib/CollaboratorEditor/{mb-collaborator-editor-popover → mb-collaborator-editor}/index.css +0 -0
  219. /package/lib/CollaboratorEditor/{pc-collaborator-editor-popover → pc-collaborator-editor}/index.css +0 -0
  220. /package/lib/{RowExpandLinkFormatter → RowExpandFormatter/RowExpandLinkFormatter}/index.css +0 -0
  221. /package/lib/{RowExpandLinkFormatter → RowExpandFormatter/RowExpandLinkFormatter}/value-display-utils.js +0 -0
  222. /package/lib/{RowExpandRateFormatter → RowExpandFormatter/RowExpandRateFormatter}/index.js +0 -0
  223. /package/lib/select-editor/{mb-select-editor-popover → mb-select-editor}/index.css +0 -0
@@ -0,0 +1,241 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _dtableUtils = require("dtable-utils");
10
+ var _constants = require("../constants");
11
+ var _withRef = _interopRequireDefault(require("./with-ref"));
12
+ var _objectUtils = _interopRequireDefault(require("../utils/object-utils"));
13
+ var _locationEditor = _interopRequireDefault(require("./location-editor"));
14
+ var _mapEditor = _interopRequireDefault(require("./map-editor"));
15
+ var _mapSelectionEditor = _interopRequireDefault(require("./map-selection-editor"));
16
+ var _countryEditor = _interopRequireDefault(require("./country-editor"));
17
+ var _provinceEditor = _interopRequireDefault(require("./province-editor"));
18
+ var _provinceCityEditor = _interopRequireDefault(require("./province-city-editor"));
19
+ require("./index.css");
20
+ class GeolocationEditor extends _react.default.Component {
21
+ constructor(_props) {
22
+ super(_props);
23
+ this.onHotKey = e => {
24
+ if (e.keyCode === _constants.KeyCodes.Enter && e.target.tagName !== 'TEXTAREA') {
25
+ this.onSubmit();
26
+ } else if (e.keyCode === _constants.KeyCodes.Escape) {
27
+ if (this.props.isInModal) {
28
+ e.stopPropagation();
29
+ this.onCancel();
30
+ }
31
+ }
32
+ };
33
+ this.getValue = () => {
34
+ return this.value;
35
+ };
36
+ this.setValue = value => {
37
+ this.value = value;
38
+ };
39
+ this.onSubmit = () => {
40
+ if (_objectUtils.default.isSameObject(this.initValue, this.value)) {
41
+ this.onCancel();
42
+ return;
43
+ }
44
+ this.props.onCommit(this.value);
45
+ };
46
+ this.onCancel = () => {
47
+ this.props.onCommitCancel && this.props.onCommitCancel();
48
+ };
49
+ this.setEditorPosition = () => {
50
+ const {
51
+ isInModal
52
+ } = this.props;
53
+ const editorFormat = this.getGeoFormat();
54
+ if (this.ref && (editorFormat === _dtableUtils.GEOLOCATION_FORMAT.COUNTRY_REGION || editorFormat === _dtableUtils.GEOLOCATION_FORMAT.PROVINCE)) {
55
+ let height = 240;
56
+ let width = 200;
57
+ let left = this.ref.parentNode.getBoundingClientRect().x;
58
+ let top = this.ref.parentNode.getBoundingClientRect().y;
59
+ if (isInModal) {
60
+ left = 220;
61
+ }
62
+ if (top + height > window.innerHeight) {
63
+ top = window.innerHeight - height - 35;
64
+ }
65
+ this.setState({
66
+ editorPosition: {
67
+ top,
68
+ left,
69
+ width,
70
+ zIndex: 1000,
71
+ position: 'fixed'
72
+ }
73
+ });
74
+ return;
75
+ }
76
+ if (this.ref && editorFormat === _dtableUtils.GEOLOCATION_FORMAT.PROVINCE_CITY) {
77
+ let height = 215;
78
+ let width = 400;
79
+ let left = this.ref.parentNode.getBoundingClientRect().x;
80
+ let top = this.ref.parentNode.getBoundingClientRect().y;
81
+ if (isInModal) {
82
+ left = 220;
83
+ if (top + height + 35 + 200 > window.innerHeight) {
84
+ top = window.innerHeight - height - 235;
85
+ }
86
+ } else {
87
+ if (top + height + 200 > window.innerHeight) {
88
+ top = window.innerHeight - height - 200 - 5;
89
+ }
90
+ if (left + width > window.innerWidth) {
91
+ left = window.innerWidth - width - 10;
92
+ }
93
+ }
94
+ this.setState({
95
+ editorPosition: {
96
+ top,
97
+ left,
98
+ width,
99
+ zIndex: 1000,
100
+ position: 'fixed'
101
+ }
102
+ });
103
+ return;
104
+ }
105
+ if (this.ref) {
106
+ const isMapTypeEditor = editorFormat === _dtableUtils.GEOLOCATION_FORMAT.LNG_LAT || editorFormat === _dtableUtils.GEOLOCATION_FORMAT.MAP_SELECTION;
107
+ let width = isMapTypeEditor ? 500 : 400;
108
+ let height = isMapTypeEditor ? 454 : 310;
109
+ let geoEditorTop = 0;
110
+ let geoEditorLeft = 0;
111
+ if (isInModal) {
112
+ let innerHeight = window.innerHeight;
113
+ const offsetTop = this.ref.parentNode.getBoundingClientRect().y;
114
+ geoEditorTop = offsetTop;
115
+ geoEditorTop = height + geoEditorTop > innerHeight ? innerHeight - height - 30 : geoEditorTop;
116
+ geoEditorLeft = -30;
117
+ } else {
118
+ let {
119
+ offsetLeft,
120
+ offsetTop
121
+ } = this.ref.parentNode;
122
+ geoEditorLeft = offsetLeft - width;
123
+ geoEditorTop = offsetTop;
124
+ if (offsetLeft < width) {
125
+ geoEditorLeft = offsetLeft + this.props.column.width;
126
+ }
127
+ if (geoEditorLeft + width > window.innerWidth) {
128
+ geoEditorLeft = window.innerWidth - width;
129
+ }
130
+ if (offsetTop + height > window.innerHeight) {
131
+ geoEditorTop = window.innerHeight - height;
132
+ }
133
+ }
134
+ this.setState({
135
+ editorPosition: {
136
+ top: geoEditorTop,
137
+ left: geoEditorLeft,
138
+ zIndex: 1000,
139
+ position: 'fixed'
140
+ }
141
+ });
142
+ }
143
+ };
144
+ this.getGeoFormat = () => {
145
+ const {
146
+ column
147
+ } = this.props;
148
+ let data = column.data || {};
149
+ return data.geo_format ? data.geo_format : _dtableUtils.DEFAULT_GEOLOCATION_FORMAT;
150
+ };
151
+ this.getLargeEditorState = () => {
152
+ var _this$editor, _this$editor$state;
153
+ return (_this$editor = this.editor) === null || _this$editor === void 0 ? void 0 : (_this$editor$state = _this$editor.state) === null || _this$editor$state === void 0 ? void 0 : _this$editor$state.isShowLargeEditor;
154
+ };
155
+ this.createEditor = () => {
156
+ const geoFormat = this.getGeoFormat();
157
+ const {
158
+ config,
159
+ column
160
+ } = this.props;
161
+ const props = {
162
+ column,
163
+ config,
164
+ value: this.value,
165
+ setValue: this.setValue,
166
+ onSubmit: this.onSubmit,
167
+ onCancel: this.onCancel
168
+ };
169
+ switch (geoFormat) {
170
+ case _dtableUtils.GEOLOCATION_FORMAT.LNG_LAT:
171
+ {
172
+ return /*#__PURE__*/_react.default.createElement(_mapEditor.default, Object.assign({}, props, {
173
+ ref: ref => this.editor = ref
174
+ }));
175
+ }
176
+ case _dtableUtils.GEOLOCATION_FORMAT.MAP_SELECTION:
177
+ {
178
+ return /*#__PURE__*/_react.default.createElement(_mapSelectionEditor.default, Object.assign({}, props, {
179
+ ref: ref => this.editor = ref
180
+ }));
181
+ }
182
+ case _dtableUtils.GEOLOCATION_FORMAT.COUNTRY_REGION:
183
+ {
184
+ return /*#__PURE__*/_react.default.createElement(_countryEditor.default, Object.assign({}, props, {
185
+ ref: ref => this.editor = ref
186
+ }));
187
+ }
188
+ case _dtableUtils.GEOLOCATION_FORMAT.PROVINCE:
189
+ {
190
+ return /*#__PURE__*/_react.default.createElement(_provinceEditor.default, Object.assign({}, props, {
191
+ onPressTab: this.props.onPressTab,
192
+ ref: ref => this.editor = ref
193
+ }));
194
+ }
195
+ case _dtableUtils.GEOLOCATION_FORMAT.PROVINCE_CITY:
196
+ {
197
+ return /*#__PURE__*/_react.default.createElement(_provinceCityEditor.default, Object.assign({}, props, {
198
+ ref: ref => this.editor = ref
199
+ }));
200
+ }
201
+ case _dtableUtils.GEOLOCATION_FORMAT.PROVINCE_CITY_DISTRICT:
202
+ {
203
+ return /*#__PURE__*/_react.default.createElement(_locationEditor.default, Object.assign({}, props, {
204
+ ref: ref => this.editor = ref
205
+ }));
206
+ }
207
+ default:
208
+ {
209
+ return /*#__PURE__*/_react.default.createElement(_locationEditor.default, Object.assign({}, props, {
210
+ isShowAddressDetail: true,
211
+ ref: ref => this.editor = ref
212
+ }));
213
+ }
214
+ }
215
+ };
216
+ this.value = _props.value || {};
217
+ this.initValue = this.value;
218
+ this.state = {
219
+ editorPosition: null
220
+ };
221
+ this.editor = null;
222
+ }
223
+ componentDidMount() {
224
+ this.setEditorPosition();
225
+ document.addEventListener('keydown', this.onHotKey, true);
226
+ }
227
+ componentWillUnmount() {
228
+ document.removeEventListener('keydown', this.onHotKey, true);
229
+ }
230
+ render() {
231
+ const {
232
+ editorPosition
233
+ } = this.state;
234
+ return /*#__PURE__*/_react.default.createElement("div", {
235
+ ref: ref => this.ref = ref,
236
+ style: editorPosition,
237
+ className: "dtable-ui-dtable-ui-geolocation-editor"
238
+ }, this.createEditor());
239
+ }
240
+ }
241
+ var _default = exports.default = (0, _withRef.default)(GeolocationEditor);
@@ -0,0 +1,368 @@
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 _selectorList = _interopRequireDefault(require("./selector-list"));
12
+ var _selectorHeaderItem = _interopRequireDefault(require("./selector-header-item"));
13
+ var _constants = require("../constants");
14
+ var _Loading = _interopRequireDefault(require("../Loading"));
15
+ var _parseGeolocation = _interopRequireDefault(require("./parse-geolocation"));
16
+ var _lang = require("../lang");
17
+ class LocationEditor extends _react.Component {
18
+ constructor(props) {
19
+ super(props);
20
+ this.getLocationText = (province, city, district) => {
21
+ return (province ? province.name : '') + (city ? city.name : '') + (district ? district.name : '');
22
+ };
23
+ this.initLocationSelecting = value => {
24
+ let selectedProvince = this.locations.children.find(province => {
25
+ return value.province && value.province.length > 0 && province.name.includes(value.province);
26
+ });
27
+ if (!selectedProvince) {
28
+ return {
29
+ selectedProvince: null,
30
+ selectedCity: null,
31
+ selectedCounty: null,
32
+ selectedItem: 'province'
33
+ };
34
+ }
35
+ let selectedCity = selectedProvince.children.find(city => {
36
+ return value.city && value.city.length > 0 && city.name.includes(value.city);
37
+ });
38
+ if (!selectedCity) {
39
+ return {
40
+ selectedProvince,
41
+ selectedCity: null,
42
+ selectedCounty: null,
43
+ selectedItem: 'city'
44
+ };
45
+ }
46
+ let selectedCounty = selectedCity.children.find(county => {
47
+ return value.district && value.district.length > 0 && county.name.includes(value.district);
48
+ });
49
+ if (!selectedCounty) {
50
+ return {
51
+ selectedProvince,
52
+ selectedCity,
53
+ selectedCounty: null,
54
+ selectedItem: 'county'
55
+ };
56
+ }
57
+ return {
58
+ selectedProvince,
59
+ selectedCity,
60
+ selectedCounty,
61
+ selectedItem: 'county'
62
+ };
63
+ };
64
+ this.getLocationData = () => {
65
+ const {
66
+ mediaUrl
67
+ } = window.dtable;
68
+
69
+ // get locations from server
70
+ return fetch("".concat(mediaUrl, "geo-data/cn-location.json")).then(res => {
71
+ return res.json();
72
+ }).catch(() => {
73
+ // get locations from local
74
+ return fetch('./geo-data/cn-location.json').then(res => {
75
+ return res.json();
76
+ });
77
+ });
78
+ };
79
+ this.onKeyDown = e => {
80
+ e.stopPropagation();
81
+ e.nativeEvent.stopImmediatePropagation();
82
+ if (e.keyCode === _constants.KeyCodes.Escape) {
83
+ this.props.onCancel();
84
+ }
85
+ };
86
+ this.onToggleSelector = () => {
87
+ this.setState({
88
+ isShowSelector: !this.state.isShowSelector,
89
+ errMessage: ''
90
+ });
91
+ };
92
+ this.selectProvince = province => {
93
+ this.setState({
94
+ selectedProvince: province,
95
+ selectedItem: province ? 'city' : 'province',
96
+ selectedCity: null,
97
+ selectedCounty: null,
98
+ location: this.getLocationText(province)
99
+ });
100
+ this.value = Object.assign({}, this.value, {
101
+ province: province ? province.name : '',
102
+ city: '',
103
+ district: ''
104
+ });
105
+ this.props.setValue(this.value);
106
+ };
107
+ this.selectCity = city => {
108
+ this.setState({
109
+ selectedCity: city,
110
+ selectedItem: city ? 'county' : 'city',
111
+ selectedCounty: null,
112
+ location: this.getLocationText(this.state.selectedProvince, city)
113
+ });
114
+ this.value = Object.assign({}, this.value, {
115
+ city: city ? city.name : '',
116
+ district: ''
117
+ });
118
+ this.props.setValue(this.value);
119
+ };
120
+ this.selectCounty = county => {
121
+ this.setState({
122
+ selectedCounty: county,
123
+ isShowSelector: false,
124
+ location: this.getLocationText(this.state.selectedProvince, this.state.selectedCity, county)
125
+ });
126
+ this.value = Object.assign({}, this.value, {
127
+ district: county ? county.name : ''
128
+ });
129
+ this.props.setValue(this.value);
130
+ };
131
+ this.selectSelectorType = type => {
132
+ const {
133
+ selectedProvince,
134
+ selectedCity
135
+ } = this.state;
136
+ if (!selectedProvince) return;
137
+ if (type === 'county' && !selectedCity) return;
138
+ this.setState({
139
+ selectedItem: type
140
+ });
141
+ };
142
+ this.onChange = () => {
143
+ this.value = Object.assign({}, this.value, {
144
+ detail: this.detailInfo.value
145
+ });
146
+ this.props.setValue(this.value);
147
+ };
148
+ this.onClick = e => {
149
+ e.stopPropagation();
150
+ e.nativeEvent.stopImmediatePropagation();
151
+ };
152
+ this.onParseChange = () => {
153
+ if (this.timer) {
154
+ clearTimeout(this.timer);
155
+ this.timer = null;
156
+ }
157
+ this.timer = setTimeout(() => {
158
+ clearTimeout(this.timer);
159
+ this.timer = null;
160
+ const value = this.parseRef.value;
161
+ if (this.isComposing) return;
162
+ const {
163
+ province,
164
+ city,
165
+ district,
166
+ detail
167
+ } = (0, _parseGeolocation.default)(this.locations, value);
168
+ if (this.detailInfo) {
169
+ this.detailInfo.value = detail || '';
170
+ this.value = Object.assign({}, this.value, {
171
+ detail: this.detailInfo.value
172
+ });
173
+ }
174
+ this.props.setValue(this.value);
175
+ this.selectProvince(province);
176
+ if (!province) return;
177
+ this.selectCity(city);
178
+ if (!city) return;
179
+ this.selectCounty(district);
180
+ }, 100);
181
+ };
182
+ this.onCompositionStart = () => {
183
+ this.isComposing = true;
184
+ };
185
+ this.onCompositionEnd = () => {
186
+ this.isComposing = false;
187
+ };
188
+ this.onSubmit = () => {
189
+ const {
190
+ province,
191
+ city,
192
+ district
193
+ } = this.value;
194
+ if (!province || !city || !district) {
195
+ const errMessage = (0, _lang.getLocale)('Province/City/District_must_be_filled_in');
196
+ this.setState({
197
+ errMessage
198
+ });
199
+ return;
200
+ }
201
+ this.props.onSubmit();
202
+ };
203
+ this.createFooter = () => {
204
+ return /*#__PURE__*/_react.default.createElement(_reactstrap.ModalFooter, {
205
+ className: "dtable-ui-geolocation-editor-footer"
206
+ }, /*#__PURE__*/_react.default.createElement(_reactstrap.Button, {
207
+ onClick: this.props.onCancel,
208
+ color: "secondary"
209
+ }, (0, _lang.getLocale)('Cancel')), /*#__PURE__*/_react.default.createElement(_reactstrap.Button, {
210
+ onClick: this.onSubmit,
211
+ color: "primary"
212
+ }, (0, _lang.getLocale)('Submit')));
213
+ };
214
+ this.value = props.value;
215
+ this.locations = {};
216
+ this.state = {
217
+ isShowSelector: false,
218
+ location: "".concat(this.value.province || '').concat(this.value.city || '').concat(this.value.district || ''),
219
+ selectedProvince: null,
220
+ selectedCity: null,
221
+ selectedCounty: null,
222
+ selectedItem: 'province',
223
+ isLoadingData: true,
224
+ errMessage: ''
225
+ };
226
+ this.isComposing = false;
227
+ this.timer = null;
228
+ }
229
+ UNSAFE_componentWillMount() {
230
+ if (!window.app.location) {
231
+ this.getLocationData().then(data => {
232
+ this.locations = data;
233
+ window.app.location = data;
234
+ const {
235
+ selectedProvince,
236
+ selectedCity,
237
+ selectedCounty,
238
+ selectedItem
239
+ } = this.initLocationSelecting(this.value);
240
+ this.setState({
241
+ isLoadingData: false,
242
+ selectedProvince,
243
+ selectedCity,
244
+ selectedCounty,
245
+ selectedItem
246
+ });
247
+ });
248
+ } else {
249
+ this.locations = window.app.location;
250
+ const {
251
+ selectedProvince,
252
+ selectedCity,
253
+ selectedCounty,
254
+ selectedItem
255
+ } = this.initLocationSelecting(this.value);
256
+ this.setState({
257
+ isLoadingData: false,
258
+ selectedProvince,
259
+ selectedCity,
260
+ selectedCounty,
261
+ selectedItem
262
+ });
263
+ }
264
+ }
265
+ render() {
266
+ const {
267
+ selectedItem,
268
+ selectedCity,
269
+ selectedProvince,
270
+ selectedCounty,
271
+ isShowSelector,
272
+ isLoadingData,
273
+ location
274
+ } = this.state;
275
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, !isLoadingData ? /*#__PURE__*/_react.default.createElement("div", {
276
+ onClick: this.onClick,
277
+ className: "dtable-ui-geolocation-editor-content"
278
+ }, /*#__PURE__*/_react.default.createElement("div", {
279
+ className: "dtable-ui-geolocation-editor-item dtable-ui-geolocation-editor-selector-container"
280
+ }, /*#__PURE__*/_react.default.createElement("div", {
281
+ className: "dtable-ui-geolocation-editor-item-left"
282
+ }, (0, _lang.getLocale)('Address_information') + ':'), /*#__PURE__*/_react.default.createElement("div", {
283
+ className: "dtable-ui-geolocation-editor-item-right"
284
+ }, /*#__PURE__*/_react.default.createElement("div", {
285
+ onClick: this.onToggleSelector,
286
+ className: "dtable-ui-geolocation-editor-selector text-truncate ".concat(isShowSelector ? 'focus' : '')
287
+ }, /*#__PURE__*/_react.default.createElement("span", {
288
+ className: "selected-option-show"
289
+ }, location ? location : (0, _lang.getLocale)('Select_province_city_district')), /*#__PURE__*/_react.default.createElement("span", {
290
+ "aria-hidden": "true",
291
+ className: "dtable-font dtable-icon-down3 dtable-ui-geolocation-editor-parameter-icon"
292
+ }))), isShowSelector && /*#__PURE__*/_react.default.createElement("div", {
293
+ className: "geolocation-selector-container"
294
+ }, /*#__PURE__*/_react.default.createElement("div", {
295
+ className: "geolocation-selector-header"
296
+ }, /*#__PURE__*/_react.default.createElement(_selectorHeaderItem.default, {
297
+ type: "province",
298
+ clickHandler: this.selectSelectorType,
299
+ selectedType: selectedItem,
300
+ selectedItem: selectedProvince
301
+ }), /*#__PURE__*/_react.default.createElement(_selectorHeaderItem.default, {
302
+ type: "city",
303
+ clickHandler: this.selectSelectorType,
304
+ selectedType: selectedItem,
305
+ selectedItem: selectedCity
306
+ }), /*#__PURE__*/_react.default.createElement(_selectorHeaderItem.default, {
307
+ type: "county",
308
+ clickHandler: this.selectSelectorType,
309
+ selectedType: selectedItem,
310
+ selectedItem: selectedCounty
311
+ })), /*#__PURE__*/_react.default.createElement("div", {
312
+ className: "geolocation-selector-body"
313
+ }, selectedItem === 'province' && /*#__PURE__*/_react.default.createElement(_selectorList.default, {
314
+ type: "province",
315
+ parent: this.locations,
316
+ selectedItem: selectedProvince,
317
+ clickHandler: this.selectProvince
318
+ }), selectedItem === 'city' && /*#__PURE__*/_react.default.createElement(_selectorList.default, {
319
+ type: "city",
320
+ parent: selectedProvince,
321
+ selectedItem: selectedCity,
322
+ clickHandler: this.selectCity
323
+ }), selectedItem === 'county' && /*#__PURE__*/_react.default.createElement(_selectorList.default, {
324
+ type: "county",
325
+ parent: selectedCity,
326
+ selectedItem: selectedCounty,
327
+ clickHandler: this.selectCounty
328
+ })))), this.props.isShowAddressDetail && /*#__PURE__*/_react.default.createElement("div", {
329
+ className: "dtable-ui-geolocation-editor-item dtable-ui-geolocation-editor-detail"
330
+ }, /*#__PURE__*/_react.default.createElement("div", {
331
+ className: "dtable-ui-geolocation-editor-item-left"
332
+ }, (0, _lang.getLocale)('Detailed_address') + ':'), /*#__PURE__*/_react.default.createElement("div", {
333
+ className: "dtable-ui-geolocation-editor-item-right"
334
+ }, /*#__PURE__*/_react.default.createElement("textarea", {
335
+ ref: ref => this.detailInfo = ref,
336
+ placeholder: (0, _lang.getLocale)('Detailed_address_placeholder'),
337
+ className: "dtable-ui-geolocation-editor-detail-info",
338
+ type: "text",
339
+ onChange: this.onChange,
340
+ defaultValue: this.value.detail,
341
+ onKeyDown: this.onKeyDown,
342
+ autoFocus: true
343
+ }))), /*#__PURE__*/_react.default.createElement("div", {
344
+ className: "dtable-ui-geolocation-editor-item dtable-ui-geolocation-editor-parse"
345
+ }, /*#__PURE__*/_react.default.createElement("div", {
346
+ className: "dtable-ui-geolocation-editor-item-left"
347
+ }, (0, _lang.getLocale)('Auto_recognition') + ':'), /*#__PURE__*/_react.default.createElement("div", {
348
+ className: "dtable-ui-geolocation-editor-item-right"
349
+ }, /*#__PURE__*/_react.default.createElement("textarea", {
350
+ ref: ref => this.parseRef = ref,
351
+ placeholder: (0, _lang.getLocale)('Try_pasting_addresses_such_as_provinces/cities/districts_roads_neighborhoods_etc_to_quickly_identify_the_address_information'),
352
+ className: "dtable-ui-geolocation-editor-detail-info dtable-ui-geolocation-editor-recognition",
353
+ type: "text",
354
+ onChange: this.onParseChange,
355
+ onKeyDown: this.onKeyDown,
356
+ onCompositionEnd: this.onCompositionEnd,
357
+ onCompositionStart: this.onCompositionStart
358
+ })))) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_Loading.default, null), /*#__PURE__*/_react.default.createElement("div", {
359
+ style: {
360
+ textAlign: 'center'
361
+ }
362
+ }, (0, _lang.getLocale)('Loading_geolocation_data'))), this.state.errMessage && /*#__PURE__*/_react.default.createElement(_reactstrap.Alert, {
363
+ color: "danger",
364
+ className: "mt-2"
365
+ }, this.state.errMessage), this.createFooter());
366
+ }
367
+ }
368
+ var _default = exports.default = LocationEditor;