@onehat/ui 0.1.2 → 0.2.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 (355) hide show
  1. package/ckeditor5/LICENSE.md +49 -0
  2. package/ckeditor5/README.md +68 -0
  3. package/ckeditor5/build/ckeditor.js +6 -0
  4. package/ckeditor5/build/ckeditor.js.map +1 -0
  5. package/ckeditor5/build/translations/af.js +1 -0
  6. package/ckeditor5/build/translations/ar.js +1 -0
  7. package/ckeditor5/build/translations/ast.js +1 -0
  8. package/ckeditor5/build/translations/az.js +1 -0
  9. package/ckeditor5/build/translations/bg.js +1 -0
  10. package/ckeditor5/build/translations/bn.js +1 -0
  11. package/ckeditor5/build/translations/bs.js +1 -0
  12. package/ckeditor5/build/translations/ca.js +1 -0
  13. package/ckeditor5/build/translations/cs.js +1 -0
  14. package/ckeditor5/build/translations/da.js +1 -0
  15. package/ckeditor5/build/translations/de-ch.js +1 -0
  16. package/ckeditor5/build/translations/de.js +1 -0
  17. package/ckeditor5/build/translations/el.js +1 -0
  18. package/ckeditor5/build/translations/en-au.js +1 -0
  19. package/ckeditor5/build/translations/en-gb.js +1 -0
  20. package/ckeditor5/build/translations/eo.js +1 -0
  21. package/ckeditor5/build/translations/es-co.js +1 -0
  22. package/ckeditor5/build/translations/es.js +1 -0
  23. package/ckeditor5/build/translations/et.js +1 -0
  24. package/ckeditor5/build/translations/eu.js +1 -0
  25. package/ckeditor5/build/translations/fa.js +1 -0
  26. package/ckeditor5/build/translations/fi.js +1 -0
  27. package/ckeditor5/build/translations/fr.js +1 -0
  28. package/ckeditor5/build/translations/gl.js +1 -0
  29. package/ckeditor5/build/translations/gu.js +1 -0
  30. package/ckeditor5/build/translations/he.js +1 -0
  31. package/ckeditor5/build/translations/hi.js +1 -0
  32. package/ckeditor5/build/translations/hr.js +1 -0
  33. package/ckeditor5/build/translations/hu.js +1 -0
  34. package/ckeditor5/build/translations/id.js +1 -0
  35. package/ckeditor5/build/translations/it.js +1 -0
  36. package/ckeditor5/build/translations/ja.js +1 -0
  37. package/ckeditor5/build/translations/jv.js +1 -0
  38. package/ckeditor5/build/translations/kk.js +1 -0
  39. package/ckeditor5/build/translations/km.js +1 -0
  40. package/ckeditor5/build/translations/kn.js +1 -0
  41. package/ckeditor5/build/translations/ko.js +1 -0
  42. package/ckeditor5/build/translations/ku.js +1 -0
  43. package/ckeditor5/build/translations/lt.js +1 -0
  44. package/ckeditor5/build/translations/lv.js +1 -0
  45. package/ckeditor5/build/translations/ms.js +1 -0
  46. package/ckeditor5/build/translations/nb.js +1 -0
  47. package/ckeditor5/build/translations/ne.js +1 -0
  48. package/ckeditor5/build/translations/nl.js +1 -0
  49. package/ckeditor5/build/translations/no.js +1 -0
  50. package/ckeditor5/build/translations/oc.js +1 -0
  51. package/ckeditor5/build/translations/pl.js +1 -0
  52. package/ckeditor5/build/translations/pt-br.js +1 -0
  53. package/ckeditor5/build/translations/pt.js +1 -0
  54. package/ckeditor5/build/translations/ro.js +1 -0
  55. package/ckeditor5/build/translations/ru.js +1 -0
  56. package/ckeditor5/build/translations/si.js +1 -0
  57. package/ckeditor5/build/translations/sk.js +1 -0
  58. package/ckeditor5/build/translations/sl.js +1 -0
  59. package/ckeditor5/build/translations/sq.js +1 -0
  60. package/ckeditor5/build/translations/sr-latn.js +1 -0
  61. package/ckeditor5/build/translations/sr.js +1 -0
  62. package/ckeditor5/build/translations/sv.js +1 -0
  63. package/ckeditor5/build/translations/th.js +1 -0
  64. package/ckeditor5/build/translations/tk.js +1 -0
  65. package/ckeditor5/build/translations/tr.js +1 -0
  66. package/ckeditor5/build/translations/tt.js +1 -0
  67. package/ckeditor5/build/translations/ug.js +1 -0
  68. package/ckeditor5/build/translations/uk.js +1 -0
  69. package/ckeditor5/build/translations/ur.js +1 -0
  70. package/ckeditor5/build/translations/uz.js +1 -0
  71. package/ckeditor5/build/translations/vi.js +1 -0
  72. package/ckeditor5/build/translations/zh-cn.js +1 -0
  73. package/ckeditor5/build/translations/zh.js +1 -0
  74. package/ckeditor5/package.json +46 -0
  75. package/ckeditor5/sample/index.html +130 -0
  76. package/ckeditor5/sample/styles.css +496 -0
  77. package/ckeditor5/src/ckeditor.js +138 -0
  78. package/ckeditor5/webpack.config.js +96 -0
  79. package/package.json +19 -23
  80. package/src/Components/Accordion/Accordion.js +144 -0
  81. package/src/Components/Blank.js +14 -0
  82. package/src/Components/Buttons/BackButton.js +16 -0
  83. package/src/Components/Buttons/CartButtonWithBadge.js +25 -0
  84. package/src/Components/Buttons/IconButton.js +42 -0
  85. package/src/Components/Container/Container.js +178 -0
  86. package/src/Components/Container/Splitter.js +61 -0
  87. package/src/Components/Filter/DateRange.js +99 -0
  88. package/src/Components/Filter/NumberRange.js +96 -0
  89. package/src/Components/Form/Field/CKEditor/CKEditor.js +62 -0
  90. package/src/Components/Form/Field/CKEditor/styles.css +503 -0
  91. package/src/Components/Form/Field/CKEditor.js +12 -0
  92. package/src/Components/Form/Field/CheckboxGroup/ArrayCheckboxGroup.js +13 -0
  93. package/src/Components/Form/Field/CheckboxGroup/CheckboxGroup.js +61 -0
  94. package/src/Components/Form/Field/Color.js +226 -0
  95. package/src/Components/Form/Field/Combo/ArrayCombo.js +15 -0
  96. package/src/Components/Form/Field/Combo/BooleanCombo.js +23 -0
  97. package/src/Components/Form/Field/Combo/Combo.js +504 -0
  98. package/src/Components/Form/Field/Combo/ComboEditor.js +22 -0
  99. package/src/Components/Form/Field/Combo/IntervalsCombo.js +18 -0
  100. package/src/Components/Form/Field/Combo/MonthsCombo.js +24 -0
  101. package/src/Components/Form/Field/Combo/PageSizeCombo.js +38 -0
  102. package/src/Components/Form/Field/Combo/Tag.js +12 -0
  103. package/src/Components/Form/Field/Combo/TimezonesCombo.js +432 -0
  104. package/src/Components/Form/Field/Combo/YearsCombo.js +35 -0
  105. package/src/Components/Form/Field/Date.js +370 -0
  106. package/src/Components/Form/Field/DisplayField.js +28 -0
  107. package/src/Components/Form/Field/Field.js +14 -0
  108. package/src/Components/Form/Field/File.js +218 -0
  109. package/src/Components/Form/Field/Input.js +96 -0
  110. package/src/Components/Form/Field/Number.js +151 -0
  111. package/src/Components/Form/Field/RadioGroup/ArrayRadioGroup.js +13 -0
  112. package/src/Components/Form/Field/RadioGroup/RadioGroup.js +62 -0
  113. package/src/Components/Form/Field/Tag.js +11 -0
  114. package/src/Components/Form/Field/Text.js +28 -0
  115. package/src/Components/Form/Field/TextArea.js +26 -0
  116. package/src/Components/Form/Field/Toggle.js +39 -0
  117. package/src/Components/Form/Field/datetime.css +5 -0
  118. package/src/Components/Form/FieldSet.js +64 -0
  119. package/src/Components/Form/FiltersForm.js +66 -0
  120. package/src/Components/Form/Form.js +535 -0
  121. package/src/Components/Form/Label.js +24 -0
  122. package/src/Components/Grid/Grid.js +877 -0
  123. package/src/Components/Grid/GridHeaderRow.js +455 -0
  124. package/src/Components/Grid/GridRow.js +134 -0
  125. package/src/Components/Grid/HeaderReorderHandle.js +29 -0
  126. package/src/Components/Grid/HeaderResizeHandle.js +29 -0
  127. package/src/Components/Grid/NoRecordsFound.js +43 -0
  128. package/src/Components/Grid/ReactGrid.js +468 -0
  129. package/src/Components/Grid/SenchaGrid.js +421 -0
  130. package/src/Components/Grid/reactgrid.css +6 -0
  131. package/src/Components/Hoc/withAlert.js +176 -0
  132. package/src/Components/Hoc/withBlank.js +12 -0
  133. package/src/Components/Hoc/withCollapsible.js +20 -0
  134. package/src/Components/Hoc/withContextMenu.js +127 -0
  135. package/src/Components/Hoc/withData.js +85 -0
  136. package/src/Components/Hoc/withDraggable.js +259 -0
  137. package/src/Components/Hoc/withEditor.js +160 -0
  138. package/src/Components/Hoc/withEvents.js +12 -0
  139. package/src/Components/Hoc/withFilters.js +456 -0
  140. package/src/Components/Hoc/withInlineEditor.js +119 -0
  141. package/src/Components/Hoc/withMultiSelection.js +16 -0
  142. package/src/Components/Hoc/withPresetButtons.js +239 -0
  143. package/src/Components/Hoc/withSelection.js +332 -0
  144. package/src/Components/Hoc/withTooltip.js +21 -0
  145. package/src/Components/Hoc/withValue.js +87 -0
  146. package/src/Components/Hoc/withWindowedEditor.js +51 -0
  147. package/src/Components/Icons/AddressBook.js +14 -0
  148. package/src/Components/Icons/Alt.js +17 -0
  149. package/src/Components/Icons/AngleLeft.js +18 -0
  150. package/src/Components/Icons/AngleRight.js +18 -0
  151. package/src/Components/Icons/AnglesLeft.js +18 -0
  152. package/src/Components/Icons/AnglesRight.js +18 -0
  153. package/src/Components/Icons/Asterisk.js +14 -0
  154. package/src/Components/Icons/Ban.js +18 -0
  155. package/src/Components/Icons/Bars.js +14 -0
  156. package/src/Components/Icons/BigCircle.js +17 -0
  157. package/src/Components/Icons/Book.js +14 -0
  158. package/src/Components/Icons/BookOpen.js +14 -0
  159. package/src/Components/Icons/Bug.js +14 -0
  160. package/src/Components/Icons/Building.js +14 -0
  161. package/src/Components/Icons/Calendar.js +18 -0
  162. package/src/Components/Icons/Calendar2.js +18 -0
  163. package/src/Components/Icons/CalendarDays.js +18 -0
  164. package/src/Components/Icons/Camera.js +18 -0
  165. package/src/Components/Icons/CaretDown.js +18 -0
  166. package/src/Components/Icons/CaretUp.js +18 -0
  167. package/src/Components/Icons/CartPlus.js +14 -0
  168. package/src/Components/Icons/CartShopping.js +14 -0
  169. package/src/Components/Icons/CashRegister.js +14 -0
  170. package/src/Components/Icons/ChartLine.js +14 -0
  171. package/src/Components/Icons/Check.js +14 -0
  172. package/src/Components/Icons/CheckDouble.js +14 -0
  173. package/src/Components/Icons/ChevronDown.js +14 -0
  174. package/src/Components/Icons/ChevronLeft.js +14 -0
  175. package/src/Components/Icons/ChevronRight.js +14 -0
  176. package/src/Components/Icons/ChevronUp.js +14 -0
  177. package/src/Components/Icons/CircleArrowRight.js +14 -0
  178. package/src/Components/Icons/CircleExclamation.js +18 -0
  179. package/src/Components/Icons/CircleInfo.js +14 -0
  180. package/src/Components/Icons/CircleQuestion.js +14 -0
  181. package/src/Components/Icons/CircleXmark.js +14 -0
  182. package/src/Components/Icons/CircleXmarkRegular.js +14 -0
  183. package/src/Components/Icons/Clipboard.js +18 -0
  184. package/src/Components/Icons/Clock.js +14 -0
  185. package/src/Components/Icons/ClockRegular.js +14 -0
  186. package/src/Components/Icons/ClockRotateLeft.js +14 -0
  187. package/src/Components/Icons/Clone.js +14 -0
  188. package/src/Components/Icons/Comment.js +14 -0
  189. package/src/Components/Icons/CommentRegular.js +14 -0
  190. package/src/Components/Icons/Comments.js +14 -0
  191. package/src/Components/Icons/CommentsRegular.js +14 -0
  192. package/src/Components/Icons/Copyright.js +14 -0
  193. package/src/Components/Icons/Duplicate.js +18 -0
  194. package/src/Components/Icons/Edit.js +18 -0
  195. package/src/Components/Icons/EllipsisVertical.js +18 -0
  196. package/src/Components/Icons/Envelope.js +14 -0
  197. package/src/Components/Icons/EnvelopeRegular.js +14 -0
  198. package/src/Components/Icons/Exclamation.js +14 -0
  199. package/src/Components/Icons/Expand.js +14 -0
  200. package/src/Components/Icons/Eye.js +18 -0
  201. package/src/Components/Icons/File.js +18 -0
  202. package/src/Components/Icons/FloppyDiskRegular.js +14 -0
  203. package/src/Components/Icons/Gear.js +18 -0
  204. package/src/Components/Icons/Gift.js +14 -0
  205. package/src/Components/Icons/Grip.js +18 -0
  206. package/src/Components/Icons/GripLines.js +18 -0
  207. package/src/Components/Icons/GripLinesVertical.js +18 -0
  208. package/src/Components/Icons/GripVertical.js +18 -0
  209. package/src/Components/Icons/Hammer.js +14 -0
  210. package/src/Components/Icons/Hand.js +14 -0
  211. package/src/Components/Icons/House.js +14 -0
  212. package/src/Components/Icons/Info.js +14 -0
  213. package/src/Components/Icons/ItunesNote.js +14 -0
  214. package/src/Components/Icons/List.js +14 -0
  215. package/src/Components/Icons/ListCheck.js +14 -0
  216. package/src/Components/Icons/LocationDot.js +14 -0
  217. package/src/Components/Icons/Loop.js +17 -0
  218. package/src/Components/Icons/Loop1.js +18 -0
  219. package/src/Components/Icons/LoopAll.js +18 -0
  220. package/src/Components/Icons/Maximize.js +14 -0
  221. package/src/Components/Icons/Microphone.js +14 -0
  222. package/src/Components/Icons/Minimize.js +14 -0
  223. package/src/Components/Icons/Minus.js +18 -0
  224. package/src/Components/Icons/MobileScreenButton.js +14 -0
  225. package/src/Components/Icons/MoneyBill.js +14 -0
  226. package/src/Components/Icons/MoneyBillWave.js +14 -0
  227. package/src/Components/Icons/Mouth.js +24 -0
  228. package/src/Components/Icons/Music.js +14 -0
  229. package/src/Components/Icons/NoLoop.js +24 -0
  230. package/src/Components/Icons/NoReorderRows.js +25 -0
  231. package/src/Components/Icons/ObjectGroupRegular.js +14 -0
  232. package/src/Components/Icons/Pause.js +14 -0
  233. package/src/Components/Icons/Pencil.js +18 -0
  234. package/src/Components/Icons/Phone.js +14 -0
  235. package/src/Components/Icons/Play.js +14 -0
  236. package/src/Components/Icons/Plus.js +18 -0
  237. package/src/Components/Icons/Presentation.js +19 -0
  238. package/src/Components/Icons/Print.js +18 -0
  239. package/src/Components/Icons/Question.js +14 -0
  240. package/src/Components/Icons/Rate-.25x.js +20 -0
  241. package/src/Components/Icons/Rate-.5x.js +19 -0
  242. package/src/Components/Icons/Rate-.75x.js +19 -0
  243. package/src/Components/Icons/Rate-1.25x.js +20 -0
  244. package/src/Components/Icons/Rate-1.5x.js +19 -0
  245. package/src/Components/Icons/Rate-1.75x.js +19 -0
  246. package/src/Components/Icons/Rate-1x.js +19 -0
  247. package/src/Components/Icons/Rate-2x.js +19 -0
  248. package/src/Components/Icons/RateIcon-.25x.js +20 -0
  249. package/src/Components/Icons/RateIcon-.5x.js +19 -0
  250. package/src/Components/Icons/RateIcon-.75x.js +19 -0
  251. package/src/Components/Icons/RateIcon-1.25x.js +20 -0
  252. package/src/Components/Icons/RateIcon-1.5x.js +19 -0
  253. package/src/Components/Icons/RateIcon-1.75x.js +19 -0
  254. package/src/Components/Icons/RateIcon-1x.js +19 -0
  255. package/src/Components/Icons/RateIcon-2x.js +19 -0
  256. package/src/Components/Icons/RectangleXmark.js +14 -0
  257. package/src/Components/Icons/RectangleXmarkRegular.js +14 -0
  258. package/src/Components/Icons/ReorderRows.js +21 -0
  259. package/src/Components/Icons/RightFromBracket.js +14 -0
  260. package/src/Components/Icons/RightToBracket.js +14 -0
  261. package/src/Components/Icons/Rotate.js +18 -0
  262. package/src/Components/Icons/RotateLeft.js +14 -0
  263. package/src/Components/Icons/RotateRight.js +18 -0
  264. package/src/Components/Icons/ScrewdriverWrench.js +14 -0
  265. package/src/Components/Icons/Scroll.js +14 -0
  266. package/src/Components/Icons/Share.js +14 -0
  267. package/src/Components/Icons/Shop.js +14 -0
  268. package/src/Components/Icons/SortDown.js +18 -0
  269. package/src/Components/Icons/SortUp.js +18 -0
  270. package/src/Components/Icons/Square.js +14 -0
  271. package/src/Components/Icons/SquareCheck.js +14 -0
  272. package/src/Components/Icons/SquareCheckRegular.js +14 -0
  273. package/src/Components/Icons/SquareMinus.js +18 -0
  274. package/src/Components/Icons/SquareRegular.js +14 -0
  275. package/src/Components/Icons/Store.js +14 -0
  276. package/src/Components/Icons/ThumbsDown.js +14 -0
  277. package/src/Components/Icons/ThumbsDownRegular.js +14 -0
  278. package/src/Components/Icons/ThumbsUp.js +14 -0
  279. package/src/Components/Icons/ThumbsUpRegular.js +14 -0
  280. package/src/Components/Icons/Trash.js +18 -0
  281. package/src/Components/Icons/TrashCan.js +18 -0
  282. package/src/Components/Icons/TriangleExclamation.js +18 -0
  283. package/src/Components/Icons/Truck.js +14 -0
  284. package/src/Components/Icons/TruckFast.js +14 -0
  285. package/src/Components/Icons/User.js +14 -0
  286. package/src/Components/Icons/UserGroup.js +14 -0
  287. package/src/Components/Icons/UserSecret.js +14 -0
  288. package/src/Components/Icons/X.js +14 -0
  289. package/src/Components/Icons/Xmark.js +14 -0
  290. package/src/Components/Mask.js +11 -0
  291. package/src/Components/Messages/ConfirmationMessage.js +26 -0
  292. package/src/Components/Messages/ErrorMessage.js +15 -0
  293. package/src/Components/Messages/Loading.js +16 -0
  294. package/src/Components/Messages/OkMessage.js +24 -0
  295. package/src/Components/Messages/WaitMessage.js +18 -0
  296. package/src/Components/Panel/AccordionGridPanel.js +94 -0
  297. package/src/Components/Panel/Footer.js +20 -0
  298. package/src/Components/Panel/FormPanel.js +23 -0
  299. package/src/Components/Panel/GridPanel.js +45 -0
  300. package/src/Components/Panel/Header.js +107 -0
  301. package/src/Components/Panel/Panel.js +152 -0
  302. package/src/Components/Panel/TabPanel.js +331 -0
  303. package/src/Components/Panel/UploadDownload.js +10 -0
  304. package/src/Components/Picker/Picker.js +64 -0
  305. package/src/Components/ScreenContainer.js +71 -0
  306. package/src/Components/Screens/DataMgt.js +250 -0
  307. package/src/Components/Toolbar/FilterToolbar.js +20 -0
  308. package/src/Components/Toolbar/Pagination.js +146 -0
  309. package/src/Components/Toolbar/PaginationToolbar.js +22 -0
  310. package/src/Components/Toolbar/Toolbar.js +18 -0
  311. package/src/Components/WaitModal.js +31 -0
  312. package/src/Components/Window/Editor.js +19 -0
  313. package/src/Constants/Alert.js +3 -0
  314. package/src/Constants/Date.js +3 -0
  315. package/src/Constants/Directions.js +8 -0
  316. package/src/Constants/EditorTypes.js +4 -0
  317. package/src/Constants/File.js +2 -0
  318. package/src/Constants/Grid.js +4 -0
  319. package/src/Constants/Input.js +1 -0
  320. package/src/Constants/Selection.js +5 -0
  321. package/src/Constants/Styles.js +86 -0
  322. package/src/Constants/UiModes.js +2 -0
  323. package/src/Data/Hoc/withRedux.js +48 -0
  324. package/src/Data/useOneHatData.js +75 -0
  325. package/src/Functions/BankersRound.js +11 -0
  326. package/src/Functions/Timer.js +92 -0
  327. package/src/Functions/deleteSecure.js +6 -0
  328. package/src/Functions/emptyFn.js +1 -0
  329. package/src/Functions/getComponentFromType.js +106 -0
  330. package/src/Functions/getIsMobile.js +5 -0
  331. package/src/Functions/getPref.js +7 -0
  332. package/src/Functions/getSecure.js +21 -0
  333. package/src/Functions/getTokenHeaders.js +13 -0
  334. package/src/Functions/inArray.js +5 -0
  335. package/src/Functions/isJson.js +8 -0
  336. package/src/Functions/processImage.js +16 -0
  337. package/src/Functions/setPref.js +14 -0
  338. package/src/Functions/setProgress.js +49 -0
  339. package/src/Functions/setSecure.js +35 -0
  340. package/src/Functions/setUiMode.js +5 -0
  341. package/src/Functions/sleep.js +3 -0
  342. package/src/Functions/testProps.js +24 -0
  343. package/src/Functions/trackEngagementHit.js +11 -0
  344. package/src/Functions/verifyCompleted.js +18 -0
  345. package/src/Functions/waitFor.js +16 -0
  346. package/src/Hooks/useAppState.js +34 -0
  347. package/src/Hooks/useAsync.js +13 -0
  348. package/src/Hooks/useBlocking.js +18 -0
  349. package/src/Hooks/useCameraRoll.js +41 -0
  350. package/src/Hooks/useForceUpdate.js +14 -0
  351. package/src/Hooks/useIsMounted.js +14 -0
  352. package/src/Hooks/useNotifications.js +279 -0
  353. package/src/Styles/StyleSheets.js +14 -0
  354. package/src/Styles/ThemeOverrides.js +264 -0
  355. package/src/UiConfig.js +19 -0
@@ -0,0 +1,877 @@
1
+ import React, { useState, useEffect, useRef, useMemo, } from 'react';
2
+ import {
3
+ Column,
4
+ FlatList,
5
+ Pressable,
6
+ Icon,
7
+ Row,
8
+ Text,
9
+ } from 'native-base';
10
+ import {
11
+ SELECTION_MODE_SINGLE,
12
+ SELECTION_MODE_MULTI,
13
+ } from '../../Constants/Selection';
14
+ import styles from '../../Constants/Styles';
15
+ import {
16
+ v4 as uuid,
17
+ } from 'uuid';
18
+ import {
19
+ VERTICAL,
20
+ } from '../../Constants/Directions';
21
+ import {
22
+ DROP_POSITION_BEFORE,
23
+ DROP_POSITION_AFTER,
24
+ } from '../../Constants/Grid';
25
+ import useForceUpdate from '../../Hooks/useForceUpdate';
26
+ import withContextMenu from '../Hoc/withContextMenu';
27
+ import withAlert from '../Hoc/withAlert';
28
+ import withData from '../Hoc/withData';
29
+ import withEvents from '../Hoc/withEvents';
30
+ import withFilters from '../Hoc/withFilters';
31
+ import withPresetButtons from '../Hoc/withPresetButtons';
32
+ import withMultiSelection from '../Hoc/withMultiSelection';
33
+ import withSelection from '../Hoc/withSelection';
34
+ import withWindowedEditor from '../Hoc/withWindowedEditor';
35
+ import withInlineEditor from '../Hoc/withInlineEditor';
36
+ import testProps from '../../Functions/testProps';
37
+ import GridHeaderRow from './GridHeaderRow';
38
+ import GridRow, { ReorderableGridRow } from './GridRow';
39
+ import IconButton from '../Buttons/IconButton';
40
+ import PaginationToolbar from '../Toolbar/PaginationToolbar';
41
+ import NoRecordsFound from './NoRecordsFound';
42
+ import Toolbar from '../Toolbar/Toolbar';
43
+ import NoReorderRows from '../Icons/NoReorderRows';
44
+ import ReorderRows from '../Icons/ReorderRows';
45
+ import _ from 'lodash';
46
+
47
+ // Grid requires the use of HOC withSelection() whenever it's used.
48
+ // The default export is *with* the HOC. A separate *raw* component is
49
+ // exported which can be combined with many HOCs for various functionality.
50
+
51
+ // Desired features: ---------
52
+ // Rows
53
+ // Rows with ability to use multiple lines (I was thinking custom render fns on rows, could possibly already do this!)
54
+ // selection
55
+ // Draggable selection (not super important)
56
+ // editor
57
+ // [ ] Show inline editor for selected row
58
+ // Dragging of window (see withWindowedEditor)
59
+ // custom cell types
60
+ // Most would use text, and depend on @onehat/data for formatting
61
+ // Display tree data
62
+
63
+ export function Grid(props) {
64
+ const {
65
+
66
+ columnsConfig = [], // json configurations for each column
67
+
68
+ columnProps = {},
69
+ getRowProps = () => {
70
+ return {
71
+ borderBottomWidth: 1,
72
+ borderBottomColor: 'trueGray.500',
73
+ py: 2,
74
+ pl: 4,
75
+ pr: 2,
76
+ };
77
+ },
78
+ flatListProps = {},
79
+ // enableEditors = false,
80
+ pullToRefresh = true,
81
+ hideNavColumn = true,
82
+ noneFoundText,
83
+ disableLoadingIndicator = false,
84
+ showRowExpander = false,
85
+ rowExpanderTpl = '',
86
+ showHeaders = true,
87
+ showHovers = true,
88
+ canColumnsSort = true,
89
+ canColumnsReorder = true,
90
+ canColumnsResize = true,
91
+ canRowsReorder = false,
92
+ allowToggleSelection = true, // i.e. single click with no shift key toggles the selection of the item clicked on
93
+ disableBottomToolbar = false,
94
+ disablePagination = false,
95
+ bottomToolbar = 'pagination',
96
+ topToolbar = null,
97
+ additionalToolbarButtons = [],
98
+
99
+ // withEditor
100
+ onAdd,
101
+ onEdit,
102
+ onDelete,
103
+ onView,
104
+ onDuplicate,
105
+ onReset,
106
+ onContextMenu,
107
+
108
+ // withData
109
+ Repository,
110
+ data,
111
+ fields,
112
+ idField,
113
+ displayField,
114
+ idIx,
115
+ displayIx,
116
+
117
+ // withPresetButtons
118
+ onChangeColumnsConfig,
119
+
120
+ // withSelection
121
+ selection,
122
+ setSelection,
123
+ selectionMode,
124
+ removeFromSelection,
125
+ addToSelection,
126
+ deselectAll,
127
+ selectRangeTo,
128
+ isInSelection,
129
+ noSelectorMeansNoResults = false,
130
+
131
+ // selectorSelected
132
+ selectorId,
133
+ selectorSelected,
134
+ disableSelectorSelected = false,
135
+
136
+ // withInlineEditor
137
+ inlineEditorRef,
138
+ onScrollRow,
139
+ onEditorRowClick,
140
+
141
+ } = props,
142
+ forceUpdate = useForceUpdate(),
143
+ gridRef = useRef(),
144
+ [isReady, setIsReady] = useState(false),
145
+ [isLoading, setIsLoading] = useState(false),
146
+ [isReorderMode, setIsReorderMode] = useState(false),
147
+ [localColumnsConfig, setLocalColumnsConfigRaw] = useState([]),
148
+ [dragRowSlot, setDragRowSlot] = useState(null),
149
+ [dragRowIx, setDragRowIx] = useState(),
150
+ setLocalColumnsConfig = (config) => {
151
+ setLocalColumnsConfigRaw(config);
152
+ if (onChangeColumnsConfig) {
153
+ onChangeColumnsConfig(config);
154
+ }
155
+ },
156
+ onRowClick = (item, rowIndex, e) => {
157
+ const
158
+ {
159
+ shiftKey,
160
+ metaKey,
161
+ } = e;
162
+
163
+ if (selectionMode === SELECTION_MODE_MULTI) {
164
+ if (shiftKey) {
165
+ if (isInSelection(item)) {
166
+ removeFromSelection(item);
167
+ } else {
168
+ selectRangeTo(item);
169
+ }
170
+ } else if (metaKey) {
171
+ if (isInSelection(item)) {
172
+ // Already selected
173
+ if (allowToggleSelection) {
174
+ removeFromSelection(item);
175
+ } else {
176
+ // Do nothing.
177
+ }
178
+ } else {
179
+ addToSelection(item);
180
+ }
181
+ } else {
182
+ if (isInSelection(item)) {
183
+ // Already selected
184
+ if (allowToggleSelection) {
185
+ removeFromSelection(item);
186
+ } else {
187
+ // Do nothing.
188
+ }
189
+ } else {
190
+ // select just this one
191
+ setSelection([item]);
192
+ }
193
+ }
194
+ } else {
195
+ // selectionMode is SELECTION_MODE_SINGLE
196
+ let newSelection = selection;
197
+ if (isInSelection(item)) {
198
+ // Already selected
199
+ if (allowToggleSelection) {
200
+ // Create empty selection
201
+ newSelection = [];
202
+ } else {
203
+ // Do nothing.
204
+ }
205
+ } else {
206
+ // Select it alone
207
+ newSelection = [item];
208
+ }
209
+ if (newSelection) {
210
+ setSelection(newSelection);
211
+ }
212
+ }
213
+ },
214
+ onRefresh = () => {
215
+ if (!Repository) {
216
+ return;
217
+ }
218
+ const promise = Repository.reload();
219
+ if (promise) { // Some repository types don't use promises
220
+ promise.then(() => {
221
+ setIsLoading(false);
222
+ forceUpdate();
223
+ });
224
+ }
225
+ },
226
+ getFooterToolbarItems = () => {
227
+ const
228
+ iconButtonProps = {
229
+ _hover: {
230
+ bg: 'trueGray.400',
231
+ },
232
+ mx: 1,
233
+ px: 3,
234
+ },
235
+ iconProps = {
236
+ alignSelf: 'center',
237
+ size: styles.GRID_TOOLBAR_ITEMS_ICON_SIZE,
238
+ h: 20,
239
+ w: 20,
240
+ },
241
+ items = _.map(additionalToolbarButtons, (config, ix) => {
242
+ let {
243
+ text,
244
+ handler,
245
+ icon = null,
246
+ isDisabled = false,
247
+ } = config;
248
+ if (icon) {
249
+ const thisIconProps = {
250
+ color: isDisabled ? styles.GRID_TOOLBAR_ITEMS_DISABLED_COLOR : styles.GRID_TOOLBAR_ITEMS_COLOR,
251
+ };
252
+ icon = React.cloneElement(icon, {...iconProps, ...thisIconProps});
253
+ }
254
+ return <IconButton
255
+ key={ix}
256
+ {...iconButtonProps}
257
+ onPress={handler}
258
+ icon={icon}
259
+ isDisabled={isDisabled}
260
+ tooltip={text}
261
+ />;
262
+ });
263
+ if (canRowsReorder) {
264
+ items.unshift(<IconButton
265
+ key="reorderBtn"
266
+ {...iconButtonProps}
267
+ onPress={() => setIsReorderMode(!isReorderMode)}
268
+ icon={<Icon as={isReorderMode ? NoReorderRows : ReorderRows} color={styles.GRID_TOOLBAR_ITEMS_COLOR} />}
269
+ />);
270
+ }
271
+ return items;
272
+ },
273
+ renderRow = (row) => {
274
+ if (row.item.isDestroyed) {
275
+ return null;
276
+ }
277
+
278
+ let {
279
+ item,
280
+ index,
281
+ } = row,
282
+ isHeaderRow = row.item.id === 'headerRow',
283
+ rowProps = getRowProps && !isHeaderRow ? getRowProps(item) : {},
284
+ isSelected = !isHeaderRow && isInSelection(item);
285
+
286
+ return <Pressable
287
+ // {...testProps(Repository ? Repository.schema.name + '-' + item.id : item.id)}
288
+ onPress={(e) => {
289
+ if (isHeaderRow || isReorderMode) {
290
+ return
291
+ }
292
+ switch (e.detail) {
293
+ case 1: // single click
294
+ onRowClick(item, index, e); // sets selection
295
+ if (onEditorRowClick) {
296
+ onEditorRowClick(item, index, e);
297
+ }
298
+ break;
299
+ case 2: // double click
300
+ if (!isSelected) { // If a row was already selected when double-clicked, the first click will deselect it,
301
+ onRowClick(item, index, e); // so reselect it
302
+ }
303
+ if (onEdit) {
304
+ onEdit();
305
+ }
306
+ break;
307
+ case 3: // triple click
308
+ break;
309
+ default:
310
+ }
311
+ }}
312
+ onLongPress={(e) => {
313
+ if (isHeaderRow || isReorderMode) {
314
+ return
315
+ }
316
+ // context menu
317
+ const selection = [item];
318
+ setSelection(selection);
319
+ if (onEditorRowClick) { // e.g. inline editor
320
+ onEditorRowClick(item, index, e);
321
+ }
322
+ if (onContextMenu) {
323
+ onContextMenu(item, index, e, selection, setSelection);
324
+ }
325
+ }}
326
+ flexDirection="row"
327
+ flexGrow={1}
328
+ >
329
+ {({
330
+ isHovered,
331
+ isFocused,
332
+ isPressed,
333
+ }) => {
334
+ if (isHeaderRow) {
335
+ return <GridHeaderRow
336
+ Repository={Repository}
337
+ columnsConfig={localColumnsConfig}
338
+ setColumnsConfig={setLocalColumnsConfig}
339
+ hideNavColumn={hideNavColumn}
340
+ canColumnsSort={canColumnsSort}
341
+ canColumnsReorder={canColumnsReorder}
342
+ canColumnsResize={canColumnsResize}
343
+ setSelection={setSelection}
344
+ gridRef={gridRef}
345
+ isHovered={isHovered}
346
+ />;
347
+ }
348
+
349
+ let bg = styles.GRID_ROW_BG;
350
+ if (isSelected) {
351
+ if (showHovers && isHovered) {
352
+ bg = styles.GRID_ROW_SELECTED_HOVER_BG;
353
+ } else {
354
+ bg = styles.GRID_ROW_SELECTED_BG;
355
+ }
356
+ } else {
357
+ if (showHovers && isHovered) {
358
+ bg = styles.GRID_ROW_HOVER_BG;
359
+ } else {
360
+ bg = styles.GRID_ROW_BG;
361
+ }
362
+ }
363
+ let WhichGridRow = GridRow;
364
+ if (canRowsReorder && isReorderMode) {
365
+ WhichGridRow = ReorderableGridRow;
366
+ }
367
+ return <WhichGridRow
368
+ columnsConfig={localColumnsConfig}
369
+ columnProps={columnProps}
370
+ fields={fields}
371
+ rowProps={rowProps}
372
+ hideNavColumn={hideNavColumn}
373
+ bg={bg}
374
+ item={item}
375
+
376
+ mode={VERTICAL}
377
+ onDragStart={onRowReorderDragStart}
378
+ onDrag={onRowReorderDrag}
379
+ onDragStop={onRowReorderDragStop}
380
+ proxyParent={gridRef.current?.getScrollableNode().children[0]}
381
+ proxyPositionRelativeToParent={true}
382
+ getParentNode={(node) => node.parentElement.parentElement.parentElement}
383
+ getProxy={getReorderProxy}
384
+ />;
385
+ }}
386
+ </Pressable>;
387
+ },
388
+ getReorderProxy = (node) => {
389
+ const
390
+ row = node.parentElement.parentElement,
391
+ rowRect = row.getBoundingClientRect(),
392
+ parent = row.parentElement,
393
+ parentRect = parent.getBoundingClientRect(),
394
+ proxy = row.cloneNode(true),
395
+ top = rowRect.top - parentRect.top,
396
+ dragRowIx = Array.from(parent.children).indexOf(row)
397
+
398
+ setDragRowIx(dragRowIx); // the ix of which record is being dragged
399
+
400
+ proxy.style.top = top + 'px';
401
+ proxy.style.left = '20px';
402
+ proxy.style.height = rowRect.height + 'px';
403
+ proxy.style.width = rowRect.width + 'px';
404
+ proxy.style.display = 'flex';
405
+ // proxy.style.backgroundColor = '#ccc';
406
+ proxy.style.position = 'absolute';
407
+ proxy.style.border = '1px solid #000';
408
+ return proxy;
409
+ },
410
+ onRowReorderDragStart = (info, e, proxy, node) => {
411
+ // console.log('onRowReorderDragStart', info, e, proxy, node);
412
+ const
413
+ proxyRect = proxy.getBoundingClientRect(),
414
+ row = node.parentElement.parentElement,
415
+ parent = row.parentElement,
416
+ parentRect = parent.getBoundingClientRect(),
417
+ rows = _.filter(row.parentElement.children, (childNode) => {
418
+ return childNode.getBoundingClientRect().height !== 0; // Skip zero-height children
419
+ }),
420
+ currentY = proxyRect.top - parentRect.top, // top position of pointer, relative to page
421
+ headerRowIx = showHeaders ? 0 : null,
422
+ firstActualRowIx = showHeaders ? 1 : 0;
423
+
424
+ // Figure out which index the user wants
425
+ let newIx = 0;
426
+ _.each(rows, (child, ix, all) => {
427
+ const
428
+ rect = child.getBoundingClientRect(), // rect of the row of this iteration
429
+ {
430
+ top,
431
+ bottom,
432
+ height,
433
+ } = rect,
434
+ compensatedTop = top - parentRect.top,
435
+ compensatedBottom = bottom - parentRect.top,
436
+ halfHeight = height / 2;
437
+
438
+ if (ix === headerRowIx || child === proxy) {
439
+ return;
440
+ }
441
+ if (ix === firstActualRowIx) {
442
+ // first row
443
+ if (currentY < compensatedTop + halfHeight) {
444
+ newIx = firstActualRowIx;
445
+ return false;
446
+ } else if (currentY < compensatedBottom) {
447
+ newIx = firstActualRowIx + 1;
448
+ return false;
449
+ }
450
+ return;
451
+ } else if (ix === all.length -1) {
452
+ // last row
453
+ if (currentY < compensatedTop + halfHeight) {
454
+ newIx = ix;
455
+ return false;
456
+ }
457
+ newIx = ix +1;
458
+ return false;
459
+ }
460
+
461
+ // all other rows
462
+ if (compensatedTop <= currentY && currentY < compensatedTop + halfHeight) {
463
+ newIx = ix;
464
+ return false;
465
+ } else if (currentY < compensatedBottom) {
466
+ newIx = ix +1;
467
+ return false;
468
+ }
469
+ });
470
+
471
+ let useBottom = false;
472
+ if (!rows[newIx] || rows[newIx] === proxy) {
473
+ newIx--;
474
+ useBottom = true;
475
+ }
476
+
477
+ // Render marker showing destination location
478
+ const
479
+ rowContainerRect = rows[newIx].getBoundingClientRect(),
480
+ top = (useBottom ? rowContainerRect.bottom : rowContainerRect.top) - parentRect.top - parseInt(parent.style.borderWidth), // get relative Y position
481
+ gridRowsContainer = gridRef.current._listRef._scrollRef.childNodes[0],
482
+ gridRowsContainerRect = gridRowsContainer.getBoundingClientRect(),
483
+ marker = document.createElement('div');
484
+
485
+ marker.style.position = 'absolute';
486
+ marker.style.top = top -4 + 'px'; // -4 so it's always visible
487
+ marker.style.height = '4px';
488
+ marker.style.width = gridRowsContainerRect.width + 'px';
489
+ marker.style.backgroundColor = '#f00';
490
+
491
+ gridRowsContainer.appendChild(marker);
492
+
493
+ setDragRowSlot({ ix: newIx, marker, useBottom, });
494
+ },
495
+ onRowReorderDrag = (info, e, proxy, node) => {
496
+ // console.log('onRowReorderDrag', info, e, proxy, node);
497
+ const
498
+ proxyRect = proxy.getBoundingClientRect(),
499
+ row = node.parentElement.parentElement,
500
+ parent = row.parentElement,
501
+ parentRect = parent.getBoundingClientRect(),
502
+ rows = _.filter(row.parentElement.children, (childNode) => {
503
+ return childNode.getBoundingClientRect().height !== 0; // Skip zero-height children
504
+ }),
505
+ currentY = proxyRect.top - parentRect.top, // top position of pointer, relative to page
506
+ headerRowIx = showHeaders ? 0 : null,
507
+ firstActualRowIx = showHeaders ? 1 : 0;
508
+
509
+ // Figure out which index the user wants
510
+ let newIx = 0;
511
+ _.each(rows, (child, ix, all) => {
512
+ const
513
+ rect = child.getBoundingClientRect(), // rect of the row of this iteration
514
+ {
515
+ top,
516
+ bottom,
517
+ height,
518
+ } = rect,
519
+ compensatedTop = top - parentRect.top,
520
+ compensatedBottom = bottom - parentRect.top,
521
+ halfHeight = height / 2;
522
+
523
+ if (ix === headerRowIx || child === proxy) {
524
+ return;
525
+ }
526
+ if (ix === firstActualRowIx) {
527
+ // first row
528
+ if (currentY < compensatedTop + halfHeight) {
529
+ newIx = firstActualRowIx;
530
+ return false;
531
+ } else if (currentY < compensatedBottom) {
532
+ newIx = firstActualRowIx + 1;
533
+ return false;
534
+ }
535
+ return;
536
+ } else if (ix === all.length -1) {
537
+ // last row
538
+ if (currentY < compensatedTop + halfHeight) {
539
+ newIx = ix;
540
+ return false;
541
+ }
542
+ newIx = ix +1;
543
+ return false;
544
+ }
545
+
546
+ // all other rows
547
+ if (compensatedTop <= currentY && currentY < compensatedTop + halfHeight) {
548
+ newIx = ix;
549
+ return false;
550
+ } else if (currentY < compensatedBottom) {
551
+ newIx = ix +1;
552
+ return false;
553
+ }
554
+ });
555
+
556
+ let useBottom = false;
557
+ if (!rows[newIx] || rows[newIx] === proxy) {
558
+ newIx--;
559
+ useBottom = true;
560
+ }
561
+
562
+ // Render marker showing destination location (can't use regular render cycle because this div is absolutely positioned on page)
563
+ const
564
+ rowContainerRect = rows[newIx].getBoundingClientRect(),
565
+ top = (useBottom ? rowContainerRect.bottom : rowContainerRect.top) - parentRect.top - parseInt(parent.style.borderWidth); // get relative Y position
566
+ let marker = dragRowSlot && dragRowSlot.marker;
567
+ if (marker) {
568
+ marker.style.top = top -4 + 'px'; // -4 so it's always visible
569
+ }
570
+
571
+ setDragRowSlot({ ix: newIx, marker, useBottom, });
572
+ // console.log('onRowReorderDrag', newIx);
573
+
574
+ },
575
+ onRowReorderDragStop = (delta, e, config) => {
576
+ // console.log('onRowReorderDragStop', delta, e, config);
577
+ const
578
+ dropIx = dragRowSlot.ix,
579
+ compensatedDragIx = showHeaders ? dragRowIx -1 : dragRowIx, // ix, without taking header row into account
580
+ compensatedDropIx = showHeaders ? dropIx -1 : dropIx, // // ix, without taking header row into account
581
+ dropPosition = dragRowSlot.useBottom ? DROP_POSITION_AFTER : DROP_POSITION_BEFORE;
582
+
583
+ let shouldMove = true,
584
+ finalDropIx = compensatedDropIx;
585
+
586
+ if (dropPosition === DROP_POSITION_BEFORE) {
587
+ if (dragRowIx === dropIx || dragRowIx === dropIx -1) { // basically before or after the drag row's origin
588
+ // Same as origin; don't do anything
589
+ shouldMove = false;
590
+ } else {
591
+ // Actually move it
592
+ if (!Repository) { // If we're just going to be switching rows, rather than telling server to reorder rows, so maybe adjust finalDropIx...
593
+ if (finalDropIx > compensatedDragIx) { // if we're dropping *before* the origin ix
594
+ finalDropIx = finalDropIx -1; // Because we're using BEFORE, we want to switch with the row *prior to* the ix we're dropping before
595
+ }
596
+ }
597
+ }
598
+ } else if (dropPosition === DROP_POSITION_AFTER) {
599
+ // Only happens on the very last row. Everything else is BEFORE...
600
+ if (dragRowIx === dropIx) {
601
+ // Same as origin; don't do anything
602
+ shouldMove = false;
603
+ }
604
+ }
605
+
606
+ if (shouldMove) {
607
+ // Update the row with the new ix
608
+ let dragRecord,
609
+ dropRecord;
610
+ if (Repository) {
611
+ dragRecord = Repository.getByIx(compensatedDragIx);
612
+ dropRecord = Repository.getByIx(finalDropIx);
613
+
614
+ Repository.reorder(dragRecord, dropRecord, dropPosition);
615
+
616
+ } else {
617
+ function arrayMove(arr, fromIndex, toIndex) {
618
+ var element = arr[fromIndex];
619
+ arr.splice(fromIndex, 1);
620
+ arr.splice(toIndex, 0, element);
621
+ }
622
+ arrayMove(data, compensatedDragIx, finalDropIx);
623
+ }
624
+ }
625
+
626
+ if (dragRowSlot) {
627
+ dragRowSlot.marker.remove();
628
+ }
629
+ setDragRowSlot(null);
630
+ };
631
+
632
+ useEffect(() => {
633
+
634
+ const calculateLocalColumnsConfig = () => {
635
+ // convert json config into actual elements
636
+ const localColumnsConfig = [];
637
+ if (_.isEmpty(columnsConfig)) {
638
+ if (Repository) {
639
+ // create a column for the displayProperty
640
+ localColumnsConfig.push({
641
+ fieldName: Repository.schema.model.displayProperty,
642
+ });
643
+ } else {
644
+ localColumnsConfig.push({
645
+ fieldName: displayField,
646
+ });
647
+ }
648
+ } else {
649
+ _.each(columnsConfig, (columnConfig) => {
650
+ if (!_.isPlainObject(columnConfig)) {
651
+ localColumnsConfig.push(columnConfig);
652
+ return;
653
+ }
654
+
655
+ // destructure so we can set defaults
656
+ const {
657
+ header,
658
+ fieldName, // from @onehat/data model
659
+ type, // specify which column type to use (custom or built-in)
660
+ isEditable = false,
661
+ editor,
662
+ format,
663
+ renderer, // React component will render the output
664
+ reorderable = true,
665
+ resizable = true,
666
+ sortable = true,
667
+ w,
668
+ flex,
669
+ } = columnConfig,
670
+
671
+ config = {
672
+ columnId: uuid(),
673
+ header,
674
+ fieldName,
675
+ type,
676
+ isEditable,
677
+ editor,
678
+ format,
679
+ renderer,
680
+ reorderable,
681
+ resizable,
682
+ sortable,
683
+ w,
684
+ flex,
685
+ showDragHandles: false,
686
+ };
687
+
688
+ if (!config.w && !config.flex) {
689
+ // Neither is set
690
+ config.w = 100; // default
691
+ } else if (config.flex && config.width) {
692
+ // Both are set. Width overrules flex.
693
+ delete config.flex;
694
+ }
695
+
696
+ localColumnsConfig.push(config);
697
+ });
698
+ }
699
+ return localColumnsConfig;
700
+ };
701
+
702
+ if (!isReady) {
703
+ setLocalColumnsConfig(calculateLocalColumnsConfig());
704
+ setIsReady(true);
705
+ }
706
+ if (!Repository) {
707
+ return () => {};
708
+ }
709
+
710
+ // set up @onehat/data repository
711
+ const
712
+ setTrue = () => setIsLoading(true),
713
+ setFalse = () => setIsLoading(false),
714
+ onChangeFilters = () => {
715
+ if (!Repository.isAutoLoad) {
716
+ Repository.reload();
717
+ }
718
+ },
719
+ onChangeSorters = () => {
720
+ if (!Repository.isAutoLoad) {
721
+ Repository.reload();
722
+ }
723
+ };
724
+
725
+ Repository.on('beforeLoad', setTrue);
726
+ Repository.on('load', setFalse);
727
+ Repository.ons(['changePage', 'changePageSize',], deselectAll);
728
+ Repository.ons(['changeData', 'change'], forceUpdate);
729
+ Repository.on('changeFilters', onChangeFilters);
730
+ Repository.on('changeSorters', onChangeSorters);
731
+
732
+
733
+ return () => {
734
+ Repository.off('beforeLoad', setTrue);
735
+ Repository.off('load', setFalse);
736
+ Repository.offs(['changePage', 'changePageSize',], deselectAll);
737
+ Repository.offs(['changeData', 'change'], forceUpdate);
738
+ Repository.off('changeFilters', onChangeFilters);
739
+ Repository.off('changeSorters', onChangeSorters);
740
+ };
741
+ }, [deselectAll]);
742
+
743
+ useEffect(() => {
744
+ if (!Repository) {
745
+ return () => {};
746
+ }
747
+ if (!disableSelectorSelected) {
748
+ let matches = selectorSelected?.[0]?.id;
749
+ if (_.isEmpty(selectorSelected)) {
750
+ matches = noSelectorMeansNoResults ? 'NO_MATCHES' : null;
751
+ }
752
+ Repository.filter(selectorId, matches, false); // so it doesn't clear existing filters
753
+ }
754
+
755
+ }, [selectorId, selectorSelected]);
756
+
757
+ const footerToolbarItemComponents = useMemo(() => getFooterToolbarItems(), [additionalToolbarButtons, isReorderMode]);
758
+
759
+ if (!isReady) {
760
+ return null;
761
+ }
762
+
763
+ // Actual data to show in the grid
764
+ const entities = Repository ? (Repository.isRemote ? Repository.entities : Repository.getEntitiesOnPage()) : data;
765
+ let rowData = _.clone(entities); // don't use the original array, make a new one so alterations to it are temporary
766
+ if (showHeaders) {
767
+ rowData.unshift({ id: 'headerRow' });
768
+ }
769
+ const initialNumToRender = rowData.length || 10;
770
+
771
+ // headers & footers
772
+ let listFooterComponent = null;
773
+ if (!disableBottomToolbar) {
774
+ if (Repository && bottomToolbar === 'pagination' && !disablePagination && Repository.isPaginated) {
775
+ listFooterComponent = <PaginationToolbar Repository={Repository} toolbarItems={footerToolbarItemComponents} />;
776
+ } else if (footerToolbarItemComponents.length) {
777
+ listFooterComponent = <Toolbar>{footerToolbarItemComponents}</Toolbar>;
778
+ }
779
+ }
780
+
781
+ return <Column
782
+ {...testProps('Grid')}
783
+ flex={1}
784
+ w="100%"
785
+ >
786
+ {topToolbar}
787
+
788
+ <Column w="100%" flex={1} borderTopWidth={isLoading ? 2 : 1} borderTopColor={isLoading ? '#f00' : 'trueGray.300'} onClick={() => {
789
+ if (!isReorderMode) {
790
+ deselectAll();
791
+ }
792
+ }}>
793
+ {!entities.length ? <NoRecordsFound text={noneFoundText} onRefresh={onRefresh} /> :
794
+ <FlatList
795
+ ref={gridRef}
796
+ // ListHeaderComponent={listHeaderComponent}
797
+ // ListFooterComponent={listFooterComponent}
798
+ scrollEnabled={true}
799
+ nestedScrollEnabled={true}
800
+ contentContainerStyle={{
801
+ overflow: 'scroll',
802
+ borderWidth: isReorderMode ? 4 : 0,
803
+ borderColor: isReorderMode ? '#23d9ea' : null,
804
+ borderStyle: 'dashed',
805
+ }}
806
+ refreshing={isLoading}
807
+ onRefresh={pullToRefresh ? onRefresh : null}
808
+ progressViewOffset={100}
809
+ data={rowData}
810
+ keyExtractor={(item) => {
811
+ let id;
812
+ if (item.id) {
813
+ id = item.id;
814
+ } else if (fields) {
815
+ id = item[idIx];
816
+ }
817
+ return String(id);
818
+ }}
819
+ // getItemLayout={(data, index) => ( // an optional optimization that allows skipping the measurement of dynamic content if you know the size (height or width) of items ahead of time. getItemLayout is efficient if you have fixed size items
820
+ // {length: ITEM_HEIGHT, offset: ITEM_HEIGHT * index, index}
821
+ // )}
822
+ // numColumns={1}
823
+ initialNumToRender={initialNumToRender}
824
+ initialScrollIndex={0}
825
+ renderItem={renderRow}
826
+ bg="trueGray.100"
827
+ {...flatListProps}
828
+ />}
829
+ </Column>
830
+
831
+ {listFooterComponent}
832
+
833
+ </Column>;
834
+
835
+ }
836
+
837
+ export const WindowedGridEditor = withAlert(
838
+ withEvents(
839
+ withData(
840
+ withMultiSelection(
841
+ withSelection(
842
+ withWindowedEditor(
843
+ withFilters(
844
+ withPresetButtons(
845
+ withContextMenu(
846
+ Grid
847
+ )
848
+ )
849
+ )
850
+ )
851
+ )
852
+ )
853
+ )
854
+ )
855
+ );
856
+
857
+ export const InlineGridEditor = withAlert(
858
+ withEvents(
859
+ withData(
860
+ withMultiSelection(
861
+ withSelection(
862
+ withInlineEditor(
863
+ withPresetButtons(
864
+ withContextMenu(
865
+ withFilters(
866
+ Grid
867
+ )
868
+ )
869
+ )
870
+ )
871
+ )
872
+ )
873
+ )
874
+ )
875
+ );
876
+
877
+ export default WindowedGridEditor;