@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,535 @@
1
+ import { useEffect, useState, } from 'react';
2
+ import {
3
+ Box,
4
+ Button,
5
+ Column,
6
+ Icon,
7
+ Row,
8
+ ScrollView,
9
+ Text,
10
+ } from 'native-base';
11
+ import {
12
+ EDITOR_TYPE_INLINE,
13
+ EDITOR_TYPE_WINDOWED,
14
+ EDITOR_TYPE_SMART,
15
+ EDITOR_TYPE_PLAIN,
16
+ } from '../../Constants/EditorTypes';
17
+ import { useForm, Controller } from 'react-hook-form'; // https://react-hook-form.com/api/
18
+ import * as yup from 'yup'; // https://github.com/jquense/yup#string
19
+ import { yupResolver } from '@hookform/resolvers/yup';
20
+ import useForceUpdate from '../../Hooks/useForceUpdate';
21
+ import withAlert from '../Hoc/withAlert';
22
+ import withEditor from '../Hoc/withEditor';
23
+ import inArray from '../../Functions/inArray';
24
+ import getComponentFromType from '../../Functions/getComponentFromType';
25
+ import IconButton from '../Buttons/IconButton';
26
+ import Rotate from '../Icons/Rotate';
27
+ import Pencil from '../Icons/Pencil';
28
+ import Footer from '../Panel/Footer';
29
+ import Label from '../Form/Label';
30
+ import _ from 'lodash';
31
+
32
+ // TODO: memoize field Components
33
+
34
+ // Modes:
35
+ // EDITOR_TYPE_INLINE
36
+ // Form is a single scrollable row, based on columnsConfig and Repository
37
+ //
38
+ // EDITOR_TYPE_WINDOWED
39
+ // Form is a popup window, used for editing items in a grid. Integrated with Repository
40
+ //
41
+ // EDITOR_TYPE_SMART
42
+ // Form is a standalone editor
43
+ //
44
+ // EDITOR_TYPE_PLAIN
45
+ // Form is embedded on screen in some other way. Mainly use startingValues, items, validator
46
+
47
+ function Form(props) {
48
+ const
49
+ {
50
+ editorType = EDITOR_TYPE_WINDOWED, // EDITOR_TYPE_INLINE | EDITOR_TYPE_WINDOWED | EDITOR_TYPE_PLAIN
51
+ startingValues = {},
52
+ items = [], // Columns, FieldSets, Fields, etc to define the form
53
+ columnDefaults = {}, // defaults for each Column defined in items (above)
54
+ columnsConfig, // Which columns are shown in Grid, so the inline editor can match. Used only for EDITOR_TYPE_INLINE
55
+ validator, // custom validator, mainly for EDITOR_TYPE_PLAIN
56
+ footerProps = {},
57
+ buttonGroupProps = {}, // buttons in footer
58
+
59
+ // sizing of outer container
60
+ h,
61
+ maxHeight,
62
+ w,
63
+ maxWidth,
64
+ flex,
65
+ onLayout, // onLayout handler for main view
66
+
67
+ // withData
68
+ Repository,
69
+
70
+ // withEditor
71
+ isViewOnly = false,
72
+ onCancel,
73
+ onEditorSave,
74
+ onSave = onEditorSave,
75
+ onClose,
76
+
77
+ // withSelection
78
+ selectorId,
79
+ selectorSelected,
80
+
81
+ // withAlert
82
+ alert,
83
+ confirm,
84
+ } = props,
85
+ record = props.record?.length === 1 ? props.record[0] : props.record,
86
+ isMultiple = _.isArray(record),
87
+ isSingle = !isMultiple, // for convenience
88
+ forceUpdate = useForceUpdate(),
89
+ initialValues = _.merge(startingValues, (record && !record.isDestroyed ? record.submitValues : {})),
90
+ defaultValues = isMultiple ? getNullFieldValues(initialValues, Repository) : initialValues, // when multiple entities, set all default values to null
91
+ {
92
+ control,
93
+ formState,
94
+ handleSubmit,
95
+ // register,
96
+ // unregister,
97
+ reset,
98
+ // watch,
99
+ // resetField,
100
+ // setError,
101
+ // clearErrors,
102
+ // setValue,
103
+ // setFocus,
104
+ getValues,
105
+ getFieldState,
106
+ // trigger,
107
+ } = useForm({
108
+ mode: 'onChange', // onChange | onBlur | onSubmit | onTouched | all
109
+ // reValidateMode: 'onChange', // onChange | onBlur | onSubmit
110
+ defaultValues,
111
+ values: defaultValues,
112
+ // resetOptions: {
113
+ // keepDirtyValues: false, // user-interacted input will be retained
114
+ // keepErrors: false, // input errors will be retained with value update
115
+ // },
116
+ // criteriaMode: 'firstError', // firstError | all
117
+ // shouldFocusError: false,
118
+ // delayError: 0,
119
+ // shouldUnregister: false,
120
+ // shouldUseNativeValidation: false,
121
+ resolver: yupResolver(validator || (isMultiple ? disableRequiredYupFields(Repository?.schema?.model?.validator) : Repository?.schema?.model?.validator) || yup.object()),
122
+ }),
123
+ buildFromColumnsConfig = () => {
124
+ // For InlineEditor
125
+ // Build the fields that match the current columnsConfig in the grid
126
+ const
127
+ model = Repository.getSchema().model,
128
+ elements = [],
129
+ columnProps = {
130
+ justifyContent: 'center',
131
+ alignItems: 'center',
132
+ borderRightWidth: 1,
133
+ borderRightColor: 'trueGray.200',
134
+ px: 1,
135
+ };
136
+ _.each(columnsConfig, (config, ix) => {
137
+ let {
138
+ fieldName,
139
+ isEditable,
140
+ editor,
141
+ renderer,
142
+ w,
143
+ flex,
144
+ } = config;
145
+
146
+ if (!isEditable) {
147
+ const renderedValue = renderer ? renderer(record) : record[fieldName];
148
+ elements.push(<Box key={ix} w={w} flex={flex} {...columnProps}>
149
+ <Text numberOfLines={1} ellipsizeMode="head">{renderedValue}</Text>
150
+ </Box>);
151
+ } else {
152
+ elements.push(<Controller
153
+ key={'controller-' + ix}
154
+ name={fieldName}
155
+ // rules={rules}
156
+ control={control}
157
+ render={(args) => {
158
+ const {
159
+ field,
160
+ fieldState,
161
+ // formState,
162
+ } = args,
163
+ {
164
+ onChange,
165
+ onBlur,
166
+ name,
167
+ value,
168
+ // ref,
169
+ } = field,
170
+ {
171
+ isTouched,
172
+ isDirty,
173
+ error,
174
+ } = fieldState;
175
+ let editorProps = {};
176
+ if (!editor) {
177
+ editor = model.editorTypes[fieldName];
178
+ if (_.isPlainObject(editor)) {
179
+ const {
180
+ type,
181
+ ...p
182
+ } = editor;
183
+ editorProps = p;
184
+ editor = type;
185
+ }
186
+ }
187
+ const Element = getComponentFromType(editor);
188
+ if (!Element) {
189
+ debugger;
190
+ // LEFT OFF HERE
191
+ // Trying inline editor, based on columnsConfig
192
+ // Getting an error that the OrdersEditor is missing users__email.
193
+ // Why is this even on the OrdersEditor? Runner?
194
+ }
195
+ let element = <Element
196
+ name={name}
197
+ value={value}
198
+ setValue={(newValue) => {
199
+ onChange(newValue);
200
+ }}
201
+ onBlur={onBlur}
202
+ selectorId={selectorId}
203
+ selectorSelected={selectorSelected}
204
+ flex={1}
205
+ {...editorProps}
206
+ // {...defaults}
207
+ // {...propsToPass}
208
+ />;
209
+
210
+ // element = <Tooltip key={ix} label={header} placement="bottom">
211
+ // {element}
212
+ // </Tooltip>;
213
+ // if (error) {
214
+ // element = <Column pt={1} flex={1}>
215
+ // {element}
216
+ // <Text color="#f00">{error.message}</Text>
217
+ // </Column>;
218
+ // }
219
+
220
+ const dirtyIcon = isDirty ? <Icon as={Pencil} size="2xs" color="trueGray.300" position="absolute" top="2px" left="2px" /> : null;
221
+ return <Row key={ix} bg={error ? '#fdd' : '#fff'} w={w} flex={flex} {...columnProps}>{dirtyIcon}{element}</Row>;
222
+ }}
223
+ />);
224
+ }
225
+ });
226
+ return <Row>{elements}</Row>;
227
+ },
228
+ buildFromItems = () => {
229
+ return _.map(items, (item, ix) => buildNextLayer(item, ix, columnDefaults));
230
+ },
231
+ buildNextLayer = (item, ix, defaults) => {
232
+ let {
233
+ type,
234
+ title,
235
+ name,
236
+ isEditable = true,
237
+ label,
238
+ items,
239
+ ...propsToPass
240
+ } = item;
241
+ let editorTypeProps = {};
242
+
243
+ const model = Repository?.getSchema().model;
244
+ if (!type && Repository) {
245
+ const
246
+ editorTypes = model.editorTypes,
247
+ {
248
+ type: t,
249
+ ...p
250
+ } = editorTypes[name];
251
+ type = t;
252
+ editorTypeProps = p;
253
+ }
254
+ if (type.match(/Combo$/) && Repository?.isRemote && !Repository?.isLoaded) {
255
+ editorTypeProps.autoLoad = true;
256
+ }
257
+ const Element = getComponentFromType(type);
258
+ let children;
259
+
260
+ if (inArray(type, ['Column', 'FieldSet'])) {
261
+ if (_.isEmpty(items)) {
262
+ return null;
263
+ }
264
+ const defaults = item.defaults;
265
+ children = _.map(items, (item, ix) => {
266
+ return buildNextLayer(item, ix, defaults);
267
+ });
268
+ return <Element key={ix} title={title} {...defaults} {...propsToPass} {...editorTypeProps}>{children}</Element>;
269
+ }
270
+
271
+ if (!name) {
272
+ throw new Error('name is required');
273
+ }
274
+
275
+ if (isViewOnly || !isEditable) {
276
+ const Text = getComponentFromType('Text');
277
+ if (!label && Repository) {
278
+ label = model.titles[name];
279
+ }
280
+ const value = (record && record[name]) || (startingValues && startingValues[name]) || null;
281
+ let element = <Text
282
+ value={value}
283
+ {...propsToPass}
284
+ />;
285
+ if (label) {
286
+ const labelProps = {};
287
+ if (defaults?.labelWidth) {
288
+ labelProps.w = defaults.labelWidth;
289
+ }
290
+ element = <><Label {...labelProps}>{label}</Label>{element}</>;
291
+ }
292
+ return <Row key={ix} px={2} pb={1}>{element}</Row>;
293
+ }
294
+
295
+ if (!label && Repository) {
296
+ label = model.titles[name];
297
+ }
298
+
299
+
300
+ // // These rules are for fields *outside* the model
301
+ // // but which want validation on the form anyway.
302
+ // // The useForm() resolver disables this
303
+ // const
304
+ // rules = {},
305
+ // rulesToCheck = [
306
+ // 'required',
307
+ // 'min',
308
+ // 'max',
309
+ // 'minLength',
310
+ // 'maxLength',
311
+ // 'pattern',
312
+ // 'validate',
313
+ // ];
314
+ // _.each(rulesToCheck, (rule) => {
315
+ // if (item.hasOwnProperty(rule)) {
316
+ // rules[rule] = item[rule];
317
+ // }
318
+ // });
319
+
320
+ return <Controller
321
+ key={'controller-' + ix}
322
+ name={name}
323
+ // rules={rules}
324
+ control={control}
325
+ render={(args) => {
326
+ const {
327
+ field,
328
+ fieldState,
329
+ // formState,
330
+ } = args,
331
+ {
332
+ onChange,
333
+ onBlur,
334
+ name,
335
+ value,
336
+ // ref,
337
+ } = field,
338
+ {
339
+ isTouched,
340
+ isDirty,
341
+ error,
342
+ } = fieldState;
343
+ let element = <Element
344
+ name={name}
345
+ value={value}
346
+ onChangeValue={onChange}
347
+ onBlur={onBlur}
348
+ selectorId={selectorId}
349
+ selectorSelected={selectorSelected}
350
+ flex={1}
351
+ {...defaults}
352
+ {...propsToPass}
353
+ {...editorTypeProps}
354
+ />;
355
+ if (error) {
356
+ if (editorType !== EDITOR_TYPE_INLINE) {
357
+ element = <Column pt={1} flex={1}>
358
+ {element}
359
+ <Text color="#f00">{error.message}</Text>
360
+ </Column>;
361
+ } else {
362
+ debugger;
363
+
364
+
365
+ }
366
+ }
367
+ if (label && editorType !== EDITOR_TYPE_INLINE) {
368
+ const labelProps = {};
369
+ if (defaults?.labelWidth) {
370
+ labelProps.w = defaults.labelWidth;
371
+ }
372
+ element = <Row w="100%">
373
+ <Label {...labelProps}>{label}</Label>
374
+ {element}
375
+ </Row>;
376
+ }
377
+
378
+ const dirtyIcon = isDirty ? <Icon as={Pencil} size="2xs" color="trueGray.300" position="absolute" top="2px" left="2px" /> : null;
379
+ return <Row key={ix} px={2} pb={1} bg={error ? '#fdd' : null}>{dirtyIcon}{element}</Row>;
380
+ }}
381
+ />;
382
+ },
383
+ onSubmitError = (errors, e) => {
384
+ debugger;
385
+ if (editorType === EDITOR_TYPE_INLINE) {
386
+ alert(errors.message);
387
+ }
388
+ };
389
+
390
+ useEffect(() => {
391
+ if (!Repository) {
392
+ return () => {};
393
+ }
394
+
395
+ Repository.ons(['changeData', 'change'], forceUpdate);
396
+
397
+ return () => {
398
+ Repository.offs(['changeData', 'change'], forceUpdate);
399
+ };
400
+ }, [Repository]);
401
+
402
+ // if (Repository && (!record || _.isEmpty(record))) {
403
+ // return null;
404
+ // }
405
+
406
+ const sizeProps = {};
407
+ if (!flex && !h && !w) {
408
+ sizeProps.flex = 1;
409
+ } else {
410
+ if (h) {
411
+ sizeProps.h = h;
412
+ }
413
+ if (w) {
414
+ sizeProps.w = w;
415
+ }
416
+ if (flex) {
417
+ sizeProps.flex = flex;
418
+ }
419
+ }
420
+ if (maxWidth) {
421
+ sizeProps.maxWidth = maxWidth;
422
+ }
423
+ if (maxHeight) {
424
+ sizeProps.maxHeight = maxHeight;
425
+ }
426
+
427
+ let formComponents,
428
+ editor;
429
+ if (editorType === EDITOR_TYPE_INLINE) {
430
+ // for inline editor
431
+ formComponents = buildFromColumnsConfig();
432
+ editor = <ScrollView
433
+ horizontal={true}
434
+ flex={1}
435
+ bg="#fff"
436
+ py={1}
437
+ borderTopWidth={3}
438
+ borderBottomWidth={5}
439
+ borderTopColor="primary.100"
440
+ borderBottomColor="primary.100"
441
+ >{formComponents}</ScrollView>;
442
+ } else {
443
+ // for Windowed editor
444
+ formComponents = buildFromItems();
445
+ editor = <ScrollView flex={1} width="100%" pb={1}>
446
+ <Row flex={1}>{formComponents}</Row>
447
+ </ScrollView>;
448
+ }
449
+
450
+ return <Column {...sizeProps} onLayout={onLayout}>
451
+
452
+ {editor}
453
+
454
+ <Footer justifyContent="flex-end" {...footerProps}>
455
+ <Button.Group space={2} {...buttonGroupProps}>
456
+ {!isViewOnly && <IconButton
457
+ key="resetBtn"
458
+ onPress={reset}
459
+ icon={<Rotate color="#fff" />}
460
+ />}
461
+ {!isViewOnly && onCancel && <Button
462
+ key="cancelBtn"
463
+ variant="ghost"
464
+ onPress={() => {
465
+ if (formState.isDirty) {
466
+ confirm('This record has unsaved changes. Are you sure you want to cancel editing? Changes will be lost.', onCancel);
467
+ } else {
468
+ onCancel();
469
+ }
470
+ }}
471
+ color="#fff"
472
+ >Cancel</Button>}
473
+ {!isViewOnly && onSave && <Button
474
+ key="saveBtn"
475
+ onPress={(e) => handleSubmit(onSave, onSubmitError)(e)}
476
+ isDisabled={!_.isEmpty(formState.errors) || (!isSingle && !record?.isPhantom && !formState.isDirty)}
477
+ color="#fff"
478
+ >Save</Button>}
479
+ {isViewOnly && onClose && <Button
480
+ key="closeBtn"
481
+ onPress={onClose}
482
+ color="#fff"
483
+ >Close</Button>}
484
+ </Button.Group>
485
+ </Footer>
486
+ </Column>;
487
+ }
488
+
489
+ // helper fns
490
+ function disableRequiredYupFields(validator) {
491
+ // based on https://github.com/jquense/yup/issues/1466#issuecomment-944386480
492
+ if (!validator) {
493
+ return null;
494
+ }
495
+
496
+ const nextSchema = validator.clone();
497
+ return nextSchema.withMutation((next) => {
498
+ if (typeof next.fields === 'object' && next.fields != null) {
499
+ for (const key in next.fields) {
500
+ const nestedField = next.fields[key];
501
+
502
+ let nestedFieldNext = nestedField.notRequired();
503
+
504
+ if (Array.isArray(nestedField.conditions) && nestedField.conditions.length > 0) {
505
+ // Next is done to disable required() inside a condition
506
+ // https://github.com/jquense/yup/issues/1002
507
+ nestedFieldNext = nestedFieldNext.when('whatever', (_: unknown, schema: yup.AnySchema) =>
508
+ schema.notRequired(),
509
+ );
510
+ }
511
+
512
+ next.fields[key] = nestedFieldNext;
513
+ }
514
+ }
515
+ });
516
+ }
517
+ function getNullFieldValues(initialValues, Repository) {
518
+ const ret = {};
519
+ if (Repository) {
520
+ const properties = Repository.getSchema().model.properties;
521
+ _.each(properties, (propertyDef) => {
522
+ ret[propertyDef.name] = null;
523
+ });
524
+ } else {
525
+ // takes a JSON object of fieldValues and sets them all to null
526
+ _.each(initialValues, (value, field) => {
527
+ ret[field] = null;
528
+ });
529
+ }
530
+ return ret;
531
+ }
532
+
533
+ export const FormEditor = withAlert(withEditor(Form));
534
+
535
+ export default withAlert(Form);
@@ -0,0 +1,24 @@
1
+ import {
2
+ Row,
3
+ Text,
4
+ } from 'native-base';
5
+ import styles from '../../Constants/Styles';
6
+
7
+ export default function Label(props) {
8
+ const {
9
+ w = styles.FORM_LABEL_WIDTH,
10
+ } = props;
11
+ return <Row
12
+ w={w}
13
+ // maxWidth="30%"
14
+ alignItems="center"
15
+ pl={2}
16
+ {...props}
17
+ >
18
+ <Text
19
+ fontSize={styles.FORM_LABEL_FONTSIZE}
20
+ numberOfLines={1}
21
+ ellipsizeMode="head"
22
+ >{props.children}</Text>
23
+ </Row>;
24
+ }