rsuite 5.0.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (365) hide show
  1. package/CHANGELOG.md +67 -6
  2. package/Grid/styles/index.less +1 -2
  3. package/IconButton/styles/index.less +1 -1
  4. package/MaskedInput/package.json +7 -0
  5. package/MultiCascader/styles/index.less +3 -0
  6. package/Navbar/styles/index.less +8 -0
  7. package/Picker/styles/index.less +1 -1
  8. package/Picker/styles/mixin.less +1 -1
  9. package/README.md +16 -10
  10. package/Sidenav/styles/index.less +13 -16
  11. package/Toggle/styles/index.less +20 -0
  12. package/Toggle/styles/mixin.less +12 -0
  13. package/Uploader/styles/index.less +10 -1
  14. package/cjs/@types/common.d.ts +0 -1
  15. package/cjs/Animation/Collapse.js +8 -8
  16. package/cjs/AutoComplete/AutoComplete.js +10 -14
  17. package/cjs/Badge/Badge.js +6 -10
  18. package/cjs/Breadcrumb/Breadcrumb.js +8 -12
  19. package/cjs/Breadcrumb/BreadcrumbItem.js +4 -8
  20. package/cjs/Button/Button.js +6 -10
  21. package/cjs/ButtonGroup/ButtonGroup.js +6 -10
  22. package/cjs/Calendar/Calendar.js +4 -8
  23. package/cjs/Calendar/CalendarPanel.js +6 -10
  24. package/cjs/Calendar/Header.js +4 -8
  25. package/cjs/Calendar/MonthDropdown.js +10 -14
  26. package/cjs/Calendar/MonthDropdownItem.js +6 -10
  27. package/cjs/Calendar/Table.js +6 -10
  28. package/cjs/Calendar/TableHeaderRow.js +4 -7
  29. package/cjs/Calendar/TableRow.js +7 -11
  30. package/cjs/Calendar/TimeDropdown.js +4 -8
  31. package/cjs/Calendar/View.js +4 -8
  32. package/cjs/Carousel/Carousel.js +10 -14
  33. package/cjs/Cascader/Cascader.js +29 -26
  34. package/cjs/Cascader/DropdownMenu.js +19 -21
  35. package/cjs/CheckPicker/CheckPicker.js +33 -29
  36. package/cjs/CheckTreePicker/CheckTreeNode.js +4 -6
  37. package/cjs/CheckTreePicker/CheckTreePicker.js +47 -35
  38. package/cjs/Checkbox/Checkbox.js +8 -13
  39. package/cjs/CheckboxGroup/CheckboxGroup.d.ts +1 -12
  40. package/cjs/CheckboxGroup/CheckboxGroup.js +7 -13
  41. package/cjs/CheckboxGroup/CheckboxGroupContext.d.ts +13 -0
  42. package/cjs/CheckboxGroup/CheckboxGroupContext.js +12 -0
  43. package/cjs/CheckboxGroup/index.d.ts +4 -3
  44. package/cjs/CheckboxGroup/index.js +6 -4
  45. package/cjs/Col/Col.js +3 -2
  46. package/cjs/Container/Container.js +4 -7
  47. package/cjs/DOMHelper/index.d.ts +1 -1
  48. package/cjs/DatePicker/DatePicker.js +27 -22
  49. package/cjs/DatePicker/Toolbar.js +4 -8
  50. package/cjs/DateRangePicker/Calendar.js +12 -14
  51. package/cjs/DateRangePicker/DateRangePicker.js +40 -33
  52. package/cjs/Divider/Divider.js +4 -8
  53. package/cjs/Drawer/Drawer.js +8 -10
  54. package/cjs/Dropdown/Dropdown.js +8 -12
  55. package/cjs/Dropdown/DropdownItem.js +25 -22
  56. package/cjs/Dropdown/DropdownMenu.js +2 -6
  57. package/cjs/Dropdown/DropdownToggle.js +4 -8
  58. package/cjs/FlexboxGrid/FlexboxGrid.js +8 -12
  59. package/cjs/FlexboxGrid/FlexboxGridItem.js +8 -12
  60. package/cjs/Form/Form.js +12 -16
  61. package/cjs/FormControl/FormControl.js +6 -2
  62. package/cjs/IconButton/IconButton.js +4 -8
  63. package/cjs/Input/Input.js +6 -10
  64. package/cjs/InputNumber/InputNumber.js +14 -18
  65. package/cjs/InputPicker/InputAutosize.js +2 -4
  66. package/cjs/InputPicker/InputPicker.js +32 -30
  67. package/cjs/List/List.js +12 -16
  68. package/cjs/List/ListItem.js +6 -10
  69. package/cjs/Loader/Loader.js +6 -10
  70. package/cjs/MaskedInput/MaskedInput.d.ts +43 -0
  71. package/cjs/MaskedInput/MaskedInput.js +80 -0
  72. package/cjs/MaskedInput/adjustCaretPosition.d.ts +11 -0
  73. package/cjs/MaskedInput/adjustCaretPosition.js +218 -0
  74. package/cjs/MaskedInput/conformToMask.d.ts +8 -0
  75. package/cjs/MaskedInput/conformToMask.js +247 -0
  76. package/cjs/MaskedInput/createTextMaskInputElement.d.ts +7 -0
  77. package/cjs/MaskedInput/createTextMaskInputElement.js +226 -0
  78. package/cjs/MaskedInput/index.d.ts +3 -0
  79. package/cjs/MaskedInput/index.js +11 -0
  80. package/cjs/MaskedInput/types.d.ts +10 -0
  81. package/cjs/{@types/icons.js → MaskedInput/types.js} +0 -0
  82. package/cjs/MaskedInput/utilities.d.ts +7 -0
  83. package/cjs/MaskedInput/utilities.js +47 -0
  84. package/cjs/Menu/Menu.d.ts +0 -1
  85. package/cjs/Menu/Menu.js +3 -5
  86. package/cjs/Message/Message.js +8 -12
  87. package/cjs/Modal/Modal.d.ts +1 -10
  88. package/cjs/Modal/Modal.js +35 -27
  89. package/cjs/Modal/ModalBody.js +6 -10
  90. package/cjs/Modal/ModalContext.d.ts +12 -0
  91. package/cjs/Modal/ModalContext.js +12 -0
  92. package/cjs/Modal/ModalDialog.js +8 -8
  93. package/cjs/Modal/ModalHeader.js +8 -12
  94. package/cjs/Modal/ModalTitle.d.ts +3 -2
  95. package/cjs/Modal/ModalTitle.js +43 -4
  96. package/cjs/MultiCascader/DropdownMenu.js +21 -23
  97. package/cjs/MultiCascader/MultiCascader.js +35 -32
  98. package/cjs/Nav/Nav.js +6 -10
  99. package/cjs/Navbar/Navbar.js +6 -9
  100. package/cjs/Notification/Notification.js +6 -10
  101. package/cjs/Overlay/Modal.js +11 -18
  102. package/cjs/Overlay/Overlay.js +2 -5
  103. package/cjs/Overlay/OverlayTrigger.js +9 -9
  104. package/cjs/Overlay/Position.js +4 -8
  105. package/cjs/Overlay/positionUtils.js +1 -1
  106. package/cjs/Pagination/Pagination.js +10 -13
  107. package/cjs/Pagination/PaginationButton.js +4 -8
  108. package/cjs/Pagination/PaginationGroup.js +11 -12
  109. package/cjs/Panel/Panel.js +6 -10
  110. package/cjs/PanelGroup/PanelGroup.js +4 -8
  111. package/cjs/Picker/DropdownMenu.js +2 -3
  112. package/cjs/Picker/DropdownMenuGroup.js +4 -8
  113. package/cjs/Picker/DropdownMenuItem.js +4 -8
  114. package/cjs/Picker/PickerToggle.js +15 -14
  115. package/cjs/Picker/propTypes.d.ts +2 -16
  116. package/cjs/Picker/propTypes.js +4 -17
  117. package/cjs/Picker/utils.js +14 -9
  118. package/cjs/Placeholder/PlaceholderGraph.js +6 -10
  119. package/cjs/Placeholder/PlaceholderGrid.js +12 -16
  120. package/cjs/Placeholder/PlaceholderParagraph.js +10 -14
  121. package/cjs/Popover/Popover.js +4 -8
  122. package/cjs/Progress/ProgressCircle.js +18 -22
  123. package/cjs/Progress/ProgressLine.js +8 -12
  124. package/cjs/Radio/Radio.js +6 -11
  125. package/cjs/RadioGroup/RadioGroup.js +6 -9
  126. package/cjs/RangeSlider/RangeSlider.js +17 -20
  127. package/cjs/Rate/Character.js +4 -7
  128. package/cjs/Rate/Rate.js +14 -18
  129. package/cjs/Ripple/Ripple.js +4 -8
  130. package/cjs/SelectPicker/SelectPicker.js +31 -28
  131. package/cjs/Sidebar/Sidebar.js +6 -10
  132. package/cjs/Sidenav/Sidenav.js +8 -11
  133. package/cjs/Sidenav/SidenavDropdown.d.ts +6 -1
  134. package/cjs/Sidenav/SidenavDropdown.js +19 -19
  135. package/cjs/Sidenav/SidenavDropdownCollapse.js +2 -6
  136. package/cjs/Sidenav/SidenavDropdownItem.js +4 -8
  137. package/cjs/Sidenav/SidenavDropdownMenu.js +4 -8
  138. package/cjs/Sidenav/SidenavToggle.js +4 -8
  139. package/cjs/Slider/Graduated.js +4 -8
  140. package/cjs/Slider/Handle.d.ts +2 -0
  141. package/cjs/Slider/Handle.js +23 -12
  142. package/cjs/Slider/Input.d.ts +3 -0
  143. package/cjs/Slider/Input.js +35 -0
  144. package/cjs/Slider/Mark.js +4 -8
  145. package/cjs/Slider/ProgressBar.js +4 -8
  146. package/cjs/Slider/Slider.d.ts +0 -3
  147. package/cjs/Slider/Slider.js +14 -22
  148. package/cjs/Steps/StepItem.js +4 -7
  149. package/cjs/Steps/Steps.js +8 -12
  150. package/cjs/Table/Table.d.ts +7 -7
  151. package/cjs/Table/Table.js +5 -5
  152. package/cjs/TagInput/index.js +4 -6
  153. package/cjs/TagPicker/index.d.ts +1 -1
  154. package/cjs/TagPicker/index.js +4 -6
  155. package/cjs/Timeline/Timeline.js +6 -11
  156. package/cjs/Timeline/TimelineItem.js +4 -8
  157. package/cjs/Toggle/Toggle.d.ts +2 -0
  158. package/cjs/Toggle/Toggle.js +27 -13
  159. package/cjs/Tooltip/Tooltip.js +4 -8
  160. package/cjs/Tree/Tree.d.ts +6 -0
  161. package/cjs/TreePicker/TreeNode.js +4 -6
  162. package/cjs/TreePicker/TreePicker.js +38 -29
  163. package/cjs/Uploader/UploadFileItem.d.ts +1 -0
  164. package/cjs/Uploader/UploadFileItem.js +42 -33
  165. package/cjs/Uploader/UploadTrigger.js +4 -8
  166. package/cjs/Uploader/Uploader.d.ts +2 -0
  167. package/cjs/Uploader/Uploader.js +28 -29
  168. package/cjs/index.d.ts +2 -0
  169. package/cjs/index.js +5 -1
  170. package/cjs/locales/fa_IR.d.ts +105 -0
  171. package/cjs/locales/fa_IR.js +84 -0
  172. package/cjs/locales/index.d.ts +1 -0
  173. package/cjs/locales/index.js +6 -2
  174. package/cjs/toaster/ToastContainer.js +6 -10
  175. package/cjs/utils/createComponent.d.ts +1 -2
  176. package/cjs/utils/createComponent.js +10 -13
  177. package/cjs/utils/previewFile.d.ts +1 -0
  178. package/cjs/utils/previewFile.js +11 -0
  179. package/cjs/utils/useUniqueId.d.ts +3 -1
  180. package/cjs/utils/useUniqueId.js +4 -2
  181. package/dist/rsuite-rtl.css +115 -44
  182. package/dist/rsuite-rtl.min.css +1 -1
  183. package/dist/rsuite-rtl.min.css.map +1 -1
  184. package/dist/rsuite.css +115 -44
  185. package/dist/rsuite.js +233 -144
  186. package/dist/rsuite.js.map +1 -1
  187. package/dist/rsuite.min.css +1 -1
  188. package/dist/rsuite.min.css.map +1 -1
  189. package/dist/rsuite.min.js +1 -1
  190. package/dist/rsuite.min.js.map +1 -1
  191. package/esm/@types/common.d.ts +0 -1
  192. package/esm/Animation/Collapse.js +8 -8
  193. package/esm/AutoComplete/AutoComplete.js +11 -14
  194. package/esm/Badge/Badge.js +6 -9
  195. package/esm/Breadcrumb/Breadcrumb.js +8 -11
  196. package/esm/Breadcrumb/BreadcrumbItem.js +4 -7
  197. package/esm/Button/Button.js +6 -9
  198. package/esm/ButtonGroup/ButtonGroup.js +6 -9
  199. package/esm/Calendar/Calendar.js +4 -7
  200. package/esm/Calendar/CalendarPanel.js +6 -9
  201. package/esm/Calendar/Header.js +4 -7
  202. package/esm/Calendar/MonthDropdown.js +10 -13
  203. package/esm/Calendar/MonthDropdownItem.js +6 -9
  204. package/esm/Calendar/Table.js +6 -9
  205. package/esm/Calendar/TableHeaderRow.js +4 -7
  206. package/esm/Calendar/TableRow.js +7 -10
  207. package/esm/Calendar/TimeDropdown.js +4 -7
  208. package/esm/Calendar/View.js +4 -7
  209. package/esm/Carousel/Carousel.js +10 -13
  210. package/esm/Cascader/Cascader.js +29 -26
  211. package/esm/Cascader/DropdownMenu.js +19 -21
  212. package/esm/CheckPicker/CheckPicker.js +33 -29
  213. package/esm/CheckTreePicker/CheckTreeNode.js +4 -6
  214. package/esm/CheckTreePicker/CheckTreePicker.js +47 -37
  215. package/esm/Checkbox/Checkbox.js +8 -12
  216. package/esm/CheckboxGroup/CheckboxGroup.d.ts +1 -12
  217. package/esm/CheckboxGroup/CheckboxGroup.js +5 -8
  218. package/esm/CheckboxGroup/CheckboxGroupContext.d.ts +13 -0
  219. package/esm/CheckboxGroup/CheckboxGroupContext.js +2 -0
  220. package/esm/CheckboxGroup/index.d.ts +4 -3
  221. package/esm/CheckboxGroup/index.js +2 -2
  222. package/esm/Col/Col.js +3 -2
  223. package/esm/Container/Container.js +4 -7
  224. package/esm/DOMHelper/index.d.ts +1 -1
  225. package/esm/DatePicker/DatePicker.js +27 -23
  226. package/esm/DatePicker/Toolbar.js +5 -8
  227. package/esm/DateRangePicker/Calendar.js +12 -13
  228. package/esm/DateRangePicker/DateRangePicker.js +40 -34
  229. package/esm/Divider/Divider.js +4 -7
  230. package/esm/Drawer/Drawer.js +8 -9
  231. package/esm/Dropdown/Dropdown.js +9 -12
  232. package/esm/Dropdown/DropdownItem.js +26 -22
  233. package/esm/Dropdown/DropdownMenu.js +3 -6
  234. package/esm/Dropdown/DropdownToggle.js +4 -7
  235. package/esm/FlexboxGrid/FlexboxGrid.js +8 -11
  236. package/esm/FlexboxGrid/FlexboxGridItem.js +8 -11
  237. package/esm/Form/Form.js +12 -15
  238. package/esm/FormControl/FormControl.js +6 -2
  239. package/esm/IconButton/IconButton.js +4 -7
  240. package/esm/Input/Input.js +6 -9
  241. package/esm/InputNumber/InputNumber.js +14 -17
  242. package/esm/InputPicker/InputAutosize.js +2 -4
  243. package/esm/InputPicker/InputPicker.js +32 -30
  244. package/esm/List/List.js +12 -15
  245. package/esm/List/ListItem.js +6 -9
  246. package/esm/Loader/Loader.js +6 -9
  247. package/esm/MaskedInput/MaskedInput.d.ts +43 -0
  248. package/esm/MaskedInput/MaskedInput.js +67 -0
  249. package/esm/MaskedInput/adjustCaretPosition.d.ts +11 -0
  250. package/esm/MaskedInput/adjustCaretPosition.js +213 -0
  251. package/esm/MaskedInput/conformToMask.d.ts +8 -0
  252. package/esm/MaskedInput/conformToMask.js +239 -0
  253. package/esm/MaskedInput/createTextMaskInputElement.d.ts +7 -0
  254. package/esm/MaskedInput/createTextMaskInputElement.js +212 -0
  255. package/esm/MaskedInput/index.d.ts +3 -0
  256. package/esm/MaskedInput/index.js +2 -0
  257. package/esm/MaskedInput/types.d.ts +10 -0
  258. package/esm/{@types/icons.js → MaskedInput/types.js} +0 -0
  259. package/esm/MaskedInput/utilities.d.ts +7 -0
  260. package/esm/MaskedInput/utilities.js +38 -0
  261. package/esm/Menu/Menu.d.ts +0 -1
  262. package/esm/Menu/Menu.js +3 -5
  263. package/esm/Message/Message.js +8 -11
  264. package/esm/Modal/Modal.d.ts +1 -10
  265. package/esm/Modal/Modal.js +31 -21
  266. package/esm/Modal/ModalBody.js +5 -8
  267. package/esm/Modal/ModalContext.d.ts +12 -0
  268. package/esm/Modal/ModalContext.js +2 -0
  269. package/esm/Modal/ModalDialog.js +8 -8
  270. package/esm/Modal/ModalHeader.js +7 -10
  271. package/esm/Modal/ModalTitle.d.ts +3 -2
  272. package/esm/Modal/ModalTitle.js +35 -4
  273. package/esm/MultiCascader/DropdownMenu.js +21 -23
  274. package/esm/MultiCascader/MultiCascader.js +35 -32
  275. package/esm/Nav/Nav.js +6 -9
  276. package/esm/Navbar/Navbar.js +6 -9
  277. package/esm/Notification/Notification.js +6 -9
  278. package/esm/Overlay/Modal.js +11 -18
  279. package/esm/Overlay/Overlay.js +2 -5
  280. package/esm/Overlay/OverlayTrigger.js +9 -9
  281. package/esm/Overlay/Position.js +4 -7
  282. package/esm/Overlay/positionUtils.js +1 -1
  283. package/esm/Pagination/Pagination.js +10 -13
  284. package/esm/Pagination/PaginationButton.js +4 -7
  285. package/esm/Pagination/PaginationGroup.js +10 -11
  286. package/esm/Panel/Panel.js +6 -9
  287. package/esm/PanelGroup/PanelGroup.js +4 -7
  288. package/esm/Picker/DropdownMenu.js +2 -3
  289. package/esm/Picker/DropdownMenuGroup.js +4 -7
  290. package/esm/Picker/DropdownMenuItem.js +4 -7
  291. package/esm/Picker/PickerToggle.js +13 -12
  292. package/esm/Picker/propTypes.d.ts +2 -16
  293. package/esm/Picker/propTypes.js +2 -13
  294. package/esm/Picker/utils.js +14 -9
  295. package/esm/Placeholder/PlaceholderGraph.js +6 -9
  296. package/esm/Placeholder/PlaceholderGrid.js +12 -15
  297. package/esm/Placeholder/PlaceholderParagraph.js +10 -13
  298. package/esm/Popover/Popover.js +4 -7
  299. package/esm/Progress/ProgressCircle.js +18 -21
  300. package/esm/Progress/ProgressLine.js +8 -11
  301. package/esm/Radio/Radio.js +6 -10
  302. package/esm/RadioGroup/RadioGroup.js +6 -9
  303. package/esm/RangeSlider/RangeSlider.js +17 -20
  304. package/esm/Rate/Character.js +4 -7
  305. package/esm/Rate/Rate.js +14 -17
  306. package/esm/Ripple/Ripple.js +4 -7
  307. package/esm/SelectPicker/SelectPicker.js +31 -28
  308. package/esm/Sidebar/Sidebar.js +6 -9
  309. package/esm/Sidenav/Sidenav.js +8 -11
  310. package/esm/Sidenav/SidenavDropdown.d.ts +6 -1
  311. package/esm/Sidenav/SidenavDropdown.js +19 -18
  312. package/esm/Sidenav/SidenavDropdownCollapse.js +2 -5
  313. package/esm/Sidenav/SidenavDropdownItem.js +5 -8
  314. package/esm/Sidenav/SidenavDropdownMenu.js +5 -8
  315. package/esm/Sidenav/SidenavToggle.js +4 -7
  316. package/esm/Slider/Graduated.js +4 -7
  317. package/esm/Slider/Handle.d.ts +2 -0
  318. package/esm/Slider/Handle.js +23 -12
  319. package/esm/Slider/Input.d.ts +3 -0
  320. package/esm/Slider/Input.js +23 -0
  321. package/esm/Slider/Mark.js +4 -7
  322. package/esm/Slider/ProgressBar.js +4 -7
  323. package/esm/Slider/Slider.d.ts +0 -3
  324. package/esm/Slider/Slider.js +14 -22
  325. package/esm/Steps/StepItem.js +4 -7
  326. package/esm/Steps/Steps.js +8 -11
  327. package/esm/Table/Table.d.ts +7 -7
  328. package/esm/Table/Table.js +5 -5
  329. package/esm/TagInput/index.js +4 -6
  330. package/esm/TagPicker/index.d.ts +1 -1
  331. package/esm/TagPicker/index.js +4 -6
  332. package/esm/Timeline/Timeline.js +6 -10
  333. package/esm/Timeline/TimelineItem.js +4 -7
  334. package/esm/Toggle/Toggle.d.ts +2 -0
  335. package/esm/Toggle/Toggle.js +27 -13
  336. package/esm/Tooltip/Tooltip.js +4 -7
  337. package/esm/Tree/Tree.d.ts +6 -0
  338. package/esm/TreePicker/TreeNode.js +4 -6
  339. package/esm/TreePicker/TreePicker.js +38 -31
  340. package/esm/Uploader/UploadFileItem.d.ts +1 -0
  341. package/esm/Uploader/UploadFileItem.js +42 -33
  342. package/esm/Uploader/UploadTrigger.js +4 -7
  343. package/esm/Uploader/Uploader.d.ts +2 -0
  344. package/esm/Uploader/Uploader.js +28 -28
  345. package/esm/index.d.ts +2 -0
  346. package/esm/index.js +1 -0
  347. package/esm/locales/fa_IR.d.ts +105 -0
  348. package/esm/locales/fa_IR.js +74 -0
  349. package/esm/locales/index.d.ts +1 -0
  350. package/esm/locales/index.js +2 -1
  351. package/esm/toaster/ToastContainer.js +6 -9
  352. package/esm/utils/createComponent.d.ts +1 -2
  353. package/esm/utils/createComponent.js +10 -13
  354. package/esm/utils/previewFile.d.ts +1 -0
  355. package/esm/utils/previewFile.js +9 -0
  356. package/esm/utils/useUniqueId.d.ts +3 -1
  357. package/esm/utils/useUniqueId.js +4 -2
  358. package/locales/fa_IR/package.json +7 -0
  359. package/package.json +6 -8
  360. package/styles/color-modes/dark.less +1 -0
  361. package/styles/color-modes/high-contrast.less +1 -0
  362. package/styles/color-modes/light.less +3 -0
  363. package/styles/variables.less +3 -1
  364. package/cjs/@types/icons.d.ts +0 -1
  365. package/esm/@types/icons.d.ts +0 -1
@@ -0,0 +1,213 @@
1
+ var defaultArray = [];
2
+ var emptyString = '';
3
+ export default function adjustCaretPosition(_ref) {
4
+ var _ref$previousConforme = _ref.previousConformedValue,
5
+ previousConformedValue = _ref$previousConforme === void 0 ? emptyString : _ref$previousConforme,
6
+ _ref$previousPlacehol = _ref.previousPlaceholder,
7
+ previousPlaceholder = _ref$previousPlacehol === void 0 ? emptyString : _ref$previousPlacehol,
8
+ _ref$currentCaretPosi = _ref.currentCaretPosition,
9
+ currentCaretPosition = _ref$currentCaretPosi === void 0 ? 0 : _ref$currentCaretPosi,
10
+ conformedValue = _ref.conformedValue,
11
+ rawValue = _ref.rawValue,
12
+ placeholderChar = _ref.placeholderChar,
13
+ placeholder = _ref.placeholder,
14
+ _ref$indexesOfPipedCh = _ref.indexesOfPipedChars,
15
+ indexesOfPipedChars = _ref$indexesOfPipedCh === void 0 ? defaultArray : _ref$indexesOfPipedCh,
16
+ _ref$caretTrapIndexes = _ref.caretTrapIndexes,
17
+ caretTrapIndexes = _ref$caretTrapIndexes === void 0 ? defaultArray : _ref$caretTrapIndexes;
18
+
19
+ if (currentCaretPosition === 0 || !rawValue.length) {
20
+ return 0;
21
+ } // Store lengths for faster performance?
22
+
23
+
24
+ var rawValueLength = rawValue.length;
25
+ var previousConformedValueLength = previousConformedValue.length;
26
+ var placeholderLength = placeholder.length;
27
+ var conformedValueLength = conformedValue.length; // This tells us how long the edit is. If user modified input from `(2__)` to `(243__)`,
28
+ // we know the user in this instance pasted two characters
29
+
30
+ var editLength = rawValueLength - previousConformedValueLength; // If the edit length is positive, that means the user is adding characters, not deleting.
31
+
32
+ var isAddition = editLength > 0; // This is the first raw value the user entered that needs to be conformed to mask
33
+
34
+ var isFirstRawValue = previousConformedValueLength === 0; // A partial multi-character edit happens when the user makes a partial selection in their
35
+ // input and edits that selection. That is going from `(123) 432-4348` to `() 432-4348` by
36
+ // selecting the first 3 digits and pressing backspace.
37
+ //
38
+ // Such cases can also happen when the user presses the backspace while holding down the ALT
39
+ // key.
40
+
41
+ var isPartialMultiCharEdit = editLength > 1 && !isFirstRawValue; // This algorithm doesn't support all cases of multi-character edits, so we just return
42
+ // the current caret position.
43
+ //
44
+ // This works fine for most cases.
45
+
46
+ if (isPartialMultiCharEdit) {
47
+ return currentCaretPosition;
48
+ } // For a mask like (111), if the `previousConformedValue` is (1__) and user attempts to enter
49
+ // `f` so the `rawValue` becomes (1f__), the new `conformedValue` would be (1__), which is the
50
+ // same as the original `previousConformedValue`. We handle this case differently for caret
51
+ // positioning.
52
+
53
+
54
+ var possiblyHasRejectedChar = isAddition && (previousConformedValue === conformedValue || conformedValue === placeholder);
55
+ var startingSearchIndex = 0;
56
+ var trackRightCharacter;
57
+ var targetChar;
58
+
59
+ if (possiblyHasRejectedChar) {
60
+ startingSearchIndex = currentCaretPosition - editLength;
61
+ } else {
62
+ // At this point in the algorithm, we want to know where the caret is right before the raw input
63
+ // has been conformed, and then see if we can find that same spot in the conformed input.
64
+ //
65
+ // We do that by seeing what character lies immediately before the caret, and then look for that
66
+ // same character in the conformed input and place the caret there.
67
+ // First, we need to normalize the inputs so that letter capitalization between raw input and
68
+ // conformed input wouldn't matter.
69
+ var normalizedConformedValue = conformedValue.toLowerCase();
70
+ var normalizedRawValue = rawValue.toLowerCase(); // Then we take all characters that come before where the caret currently is.
71
+
72
+ var leftHalfChars = normalizedRawValue.substr(0, currentCaretPosition).split(emptyString); // Now we find all the characters in the left half that exist in the conformed input
73
+ // This step ensures that we don't look for a character that was filtered out or rejected by `conformToMask`.
74
+
75
+ var intersection = leftHalfChars.filter(function (char) {
76
+ return normalizedConformedValue.indexOf(char) !== -1;
77
+ }); // The last character in the intersection is the character we want to look for in the conformed
78
+ // value and the one we want to adjust the caret close to
79
+
80
+ targetChar = intersection[intersection.length - 1]; // Calculate the number of mask characters in the previous placeholder
81
+ // from the start of the string up to the place where the caret is
82
+
83
+ var previousLeftMaskChars = previousPlaceholder.substr(0, intersection.length).split(emptyString).filter(function (char) {
84
+ return char !== placeholderChar;
85
+ }).length; // Calculate the number of mask characters in the current placeholder
86
+ // from the start of the string up to the place where the caret is
87
+
88
+ var leftMaskChars = placeholder.substr(0, intersection.length).split(emptyString).filter(function (char) {
89
+ return char !== placeholderChar;
90
+ }).length; // Has the number of mask characters up to the caret changed?
91
+
92
+ var masklengthChanged = leftMaskChars !== previousLeftMaskChars; // Detect if `targetChar` is a mask character and has moved to the left
93
+
94
+ var targetIsMaskMovingLeft = previousPlaceholder[intersection.length - 1] !== undefined && placeholder[intersection.length - 2] !== undefined && previousPlaceholder[intersection.length - 1] !== placeholderChar && previousPlaceholder[intersection.length - 1] !== placeholder[intersection.length - 1] && previousPlaceholder[intersection.length - 1] === placeholder[intersection.length - 2]; // If deleting and the `targetChar` `is a mask character and `masklengthChanged` is true
95
+ // or the mask is moving to the left, we can't use the selected `targetChar` any longer
96
+ // if we are not at the end of the string.
97
+ // In this case, change tracking strategy and track the character to the right of the caret.
98
+
99
+ if (!isAddition && (masklengthChanged || targetIsMaskMovingLeft) && previousLeftMaskChars > 0 && placeholder.indexOf(targetChar) > -1 && rawValue[currentCaretPosition] !== undefined) {
100
+ trackRightCharacter = true;
101
+ targetChar = rawValue[currentCaretPosition];
102
+ } // It is possible that `targetChar` will appear multiple times in the conformed value.
103
+ // We need to know not to select a character that looks like our target character from the placeholder or
104
+ // the piped characters, so we inspect the piped characters and the placeholder to see if they contain
105
+ // characters that match our target character.
106
+ // If the `conformedValue` got piped, we need to know which characters were piped in so that when we look for
107
+ // our `targetChar`, we don't select a piped char by mistake
108
+
109
+
110
+ var pipedChars = indexesOfPipedChars.map(function (index) {
111
+ return normalizedConformedValue[index];
112
+ }); // We need to know how many times the `targetChar` occurs in the piped characters.
113
+
114
+ var countTargetCharInPipedChars = pipedChars.filter(function (char) {
115
+ return char === targetChar;
116
+ }).length; // We need to know how many times it occurs in the intersection
117
+
118
+ var countTargetCharInIntersection = intersection.filter(function (char) {
119
+ return char === targetChar;
120
+ }).length; // We need to know if the placeholder contains characters that look like
121
+ // our `targetChar`, so we don't select one of those by mistake.
122
+
123
+ var countTargetCharInPlaceholder = placeholder.substr(0, placeholder.indexOf(placeholderChar)).split(emptyString).filter(function (char, index) {
124
+ return (// Check if `char` is the same as our `targetChar`, so we account for it
125
+ char === targetChar && // but also make sure that both the `rawValue` and placeholder don't have the same character at the same
126
+ // index because if they are equal, that means we are already counting those characters in
127
+ // `countTargetCharInIntersection`
128
+ rawValue[index] !== char
129
+ );
130
+ }).length; // The number of times we need to see occurrences of the `targetChar` before we know it is the one we're looking
131
+ // for is:
132
+
133
+ var requiredNumberOfMatches = countTargetCharInPlaceholder + countTargetCharInIntersection + countTargetCharInPipedChars + ( // The character to the right of the caret isn't included in `intersection`
134
+ // so add one if we are tracking the character to the right
135
+ trackRightCharacter ? 1 : 0); // Now we start looking for the location of the `targetChar`.
136
+ // We keep looping forward and store the index in every iteration. Once we have encountered
137
+ // enough occurrences of the target character, we break out of the loop
138
+ // If are searching for the second `1` in `1214`, `startingSearchIndex` will point at `4`.
139
+
140
+ var numberOfEncounteredMatches = 0;
141
+
142
+ for (var i = 0; i < conformedValueLength; i++) {
143
+ var conformedValueChar = normalizedConformedValue[i];
144
+ startingSearchIndex = i + 1;
145
+
146
+ if (conformedValueChar === targetChar) {
147
+ numberOfEncounteredMatches++;
148
+ }
149
+
150
+ if (numberOfEncounteredMatches >= requiredNumberOfMatches) {
151
+ break;
152
+ }
153
+ }
154
+ } // At this point, if we simply return `startingSearchIndex` as the adjusted caret position,
155
+ // most cases would be handled. However, we want to fast forward or rewind the caret to the
156
+ // closest placeholder character if it happens to be in a non-editable spot. That's what the next
157
+ // logic is for.
158
+ // In case of addition, we fast forward.
159
+
160
+
161
+ if (isAddition) {
162
+ // We want to remember the last placeholder character encountered so that if the mask
163
+ // contains more characters after the last placeholder character, we don't forward the caret
164
+ // that far to the right. Instead, we stop it at the last encountered placeholder character.
165
+ var lastPlaceholderChar = startingSearchIndex;
166
+
167
+ for (var _i = startingSearchIndex; _i <= placeholderLength; _i++) {
168
+ if (placeholder[_i] === placeholderChar) {
169
+ lastPlaceholderChar = _i;
170
+ }
171
+
172
+ if ( // If we're adding, we can position the caret at the next placeholder character.
173
+ placeholder[_i] === placeholderChar || // If a caret trap was set by a mask function, we need to stop at the trap.
174
+ caretTrapIndexes.indexOf(_i) !== -1 || // This is the end of the placeholder. We cannot move any further. Let's put the caret there.
175
+ _i === placeholderLength) {
176
+ return lastPlaceholderChar;
177
+ }
178
+ }
179
+ } else {
180
+ // In case of deletion, we rewind.
181
+ if (trackRightCharacter) {
182
+ // Searching for the character that was to the right of the caret
183
+ // We start at `startingSearchIndex` - 1 because it includes one character extra to the right
184
+ for (var _i2 = startingSearchIndex - 1; _i2 >= 0; _i2--) {
185
+ // If tracking the character to the right of the cursor, we move to the left until
186
+ // we found the character and then place the caret right before it
187
+ if ( // `targetChar` should be in `conformedValue`, since it was in `rawValue`, just
188
+ // to the right of the caret
189
+ conformedValue[_i2] === targetChar || // If a caret trap was set by a mask function, we need to stop at the trap.
190
+ caretTrapIndexes.indexOf(_i2) !== -1 || // This is the beginning of the placeholder. We cannot move any further.
191
+ // Let's put the caret there.
192
+ _i2 === 0) {
193
+ return _i2;
194
+ }
195
+ }
196
+ } else {
197
+ // Searching for the first placeholder or caret trap to the left
198
+ for (var _i3 = startingSearchIndex; _i3 >= 0; _i3--) {
199
+ // If we're deleting, we stop the caret right before the placeholder character.
200
+ // For example, for mask `(111) 11`, current conformed input `(456) 86`. If user
201
+ // modifies input to `(456 86`. That is, they deleted the `)`, we place the caret
202
+ // right after the first `6`
203
+ if ( // If we're deleting, we can position the caret right before the placeholder character
204
+ placeholder[_i3 - 1] === placeholderChar || // If a caret trap was set by a mask function, we need to stop at the trap.
205
+ caretTrapIndexes.indexOf(_i3) !== -1 || // This is the beginning of the placeholder. We cannot move any further.
206
+ // Let's put the caret there.
207
+ _i3 === 0) {
208
+ return _i3;
209
+ }
210
+ }
211
+ }
212
+ }
213
+ }
@@ -0,0 +1,8 @@
1
+ import { MaskType, ConfigType, MaskFunctionType } from './types';
2
+ export declare function isArray(value: any): boolean;
3
+ export default function conformToMask(rawValue?: string, mask?: MaskType | MaskFunctionType, config?: ConfigType): {
4
+ conformedValue: string;
5
+ meta: {
6
+ someCharsRejected: boolean;
7
+ };
8
+ };
@@ -0,0 +1,239 @@
1
+ import { convertMaskToPlaceholder, processCaretTraps, defaultPlaceholderChar } from './utilities';
2
+ export function isArray(value) {
3
+ return Array.isArray && Array.isArray(value) || value instanceof Array;
4
+ }
5
+ export default function conformToMask(rawValue, mask, config) {
6
+ if (rawValue === void 0) {
7
+ rawValue = '';
8
+ }
9
+
10
+ if (mask === void 0) {
11
+ mask = [];
12
+ }
13
+
14
+ if (config === void 0) {
15
+ config = {};
16
+ }
17
+
18
+ if (!isArray(mask)) {
19
+ // If someone passes a function as the mask property, we should call the
20
+ // function to get the mask array - Normally this is handled by the
21
+ // `createTextMaskInputElement:update` function - this allows mask functions
22
+ // to be used directly with `conformToMask`
23
+ if (typeof mask === 'function') {
24
+ // call the mask function to get the mask array
25
+ mask = mask(rawValue, config); // mask functions can setup caret traps to have some control over how the caret moves. We need to process
26
+ // the mask for any caret traps. `processCaretTraps` will remove the caret traps from the mask
27
+
28
+ mask = processCaretTraps(mask).maskWithoutCaretTraps;
29
+ } else {
30
+ throw new Error('Text-mask:conformToMask; The mask property must be an array.');
31
+ }
32
+ } // These configurations tell us how to conform the mask
33
+
34
+
35
+ var _config = config,
36
+ _config$guide = _config.guide,
37
+ guide = _config$guide === void 0 ? true : _config$guide,
38
+ _config$previousConfo = _config.previousConformedValue,
39
+ previousConformedValue = _config$previousConfo === void 0 ? '' : _config$previousConfo,
40
+ _config$placeholderCh = _config.placeholderChar,
41
+ placeholderChar = _config$placeholderCh === void 0 ? defaultPlaceholderChar : _config$placeholderCh,
42
+ _config$placeholder = _config.placeholder,
43
+ placeholder = _config$placeholder === void 0 ? convertMaskToPlaceholder(mask, placeholderChar) : _config$placeholder,
44
+ currentCaretPosition = _config.currentCaretPosition,
45
+ keepCharPositions = _config.keepCharPositions; // The configs below indicate that the user wants the algorithm to work in *no guide* mode
46
+
47
+ var suppressGuide = guide === false && previousConformedValue !== undefined; // Calculate lengths once for performance
48
+
49
+ var rawValueLength = rawValue.length;
50
+ var previousConformedValueLength = previousConformedValue.length;
51
+ var placeholderLength = placeholder.length;
52
+ var maskLength = mask.length; // This tells us the number of edited characters and the direction in which they were edited (+/-)
53
+
54
+ var editDistance = rawValueLength - previousConformedValueLength; // In *no guide* mode, we need to know if the user is trying to add a character or not
55
+
56
+ var isAddition = editDistance > 0; // Tells us the index of the first change. For (438) 394-4938 to (38) 394-4938, that would be 1
57
+
58
+ var indexOfFirstChange = currentCaretPosition + (isAddition ? -editDistance : 0); // We're also gonna need the index of last change, which we can derive as follows...
59
+
60
+ var indexOfLastChange = indexOfFirstChange + Math.abs(editDistance); // If `conformToMask` is configured to keep character positions, that is, for mask 111, previous value
61
+ // _2_ and raw value 3_2_, the new conformed value should be 32_, not 3_2 (default behavior). That's in the case of
62
+ // addition. And in the case of deletion, previous value _23, raw value _3, the new conformed string should be
63
+ // __3, not _3_ (default behavior)
64
+ //
65
+ // The next block of logic handles keeping character positions for the case of deletion. (Keeping
66
+ // character positions for the case of addition is further down since it is handled differently.)
67
+ // To do this, we want to compensate for all characters that were deleted
68
+
69
+ if (keepCharPositions === true && !isAddition) {
70
+ // We will be storing the new placeholder characters in this variable.
71
+ var compensatingPlaceholderChars = ''; // For every character that was deleted from a placeholder position, we add a placeholder char
72
+
73
+ for (var i = indexOfFirstChange; i < indexOfLastChange; i++) {
74
+ if (placeholder[i] === placeholderChar) {
75
+ compensatingPlaceholderChars += placeholderChar;
76
+ }
77
+ } // Now we trick our algorithm by modifying the raw value to make it contain additional placeholder characters
78
+ // That way when the we start laying the characters again on the mask, it will keep the non-deleted characters
79
+ // in their positions.
80
+
81
+
82
+ rawValue = rawValue.slice(0, indexOfFirstChange) + compensatingPlaceholderChars + rawValue.slice(indexOfFirstChange, rawValueLength);
83
+ } // Convert `rawValue` string to an array, and mark characters based on whether they are newly added or have
84
+ // existed in the previous conformed value. Identifying new and old characters is needed for `conformToMask`
85
+ // to work if it is configured to keep character positions.
86
+
87
+
88
+ var rawValueArr = rawValue.split('').map(function (char, i) {
89
+ return {
90
+ char: char,
91
+ isNew: i >= indexOfFirstChange && i < indexOfLastChange
92
+ };
93
+ }); // The loop below removes masking characters from user input. For example, for mask
94
+ // `00 (111)`, the placeholder would be `00 (___)`. If user input is `00 (234)`, the loop below
95
+ // would remove all characters but `234` from the `rawValueArr`. The rest of the algorithm
96
+ // then would lay `234` on top of the available placeholder positions in the mask.
97
+
98
+ for (var _i = rawValueLength - 1; _i >= 0; _i--) {
99
+ var char = rawValueArr[_i].char;
100
+
101
+ if (char !== placeholderChar) {
102
+ var shouldOffset = _i >= indexOfFirstChange && previousConformedValueLength === maskLength;
103
+
104
+ if (char === placeholder[shouldOffset ? _i - editDistance : _i]) {
105
+ rawValueArr.splice(_i, 1);
106
+ }
107
+ }
108
+ } // This is the variable that we will be filling with characters as we figure them out
109
+ // in the algorithm below
110
+
111
+
112
+ var conformedValue = '';
113
+ var someCharsRejected = false; // Ok, so first we loop through the placeholder looking for placeholder characters to fill up.
114
+
115
+ placeholderLoop: for (var _i2 = 0; _i2 < placeholderLength; _i2++) {
116
+ var charInPlaceholder = placeholder[_i2]; // We see one. Let's find out what we can put in it.
117
+
118
+ if (charInPlaceholder === placeholderChar) {
119
+ // But before that, do we actually have any user characters that need a place?
120
+ if (rawValueArr.length > 0) {
121
+ // We will keep chipping away at user input until either we run out of characters
122
+ // or we find at least one character that we can map.
123
+ while (rawValueArr.length > 0) {
124
+ // Let's retrieve the first user character in the queue of characters we have left
125
+ var _rawValueArr$shift = rawValueArr.shift(),
126
+ rawValueChar = _rawValueArr$shift.char,
127
+ isNew = _rawValueArr$shift.isNew; // If the character we got from the user input is a placeholder character (which happens
128
+ // regularly because user input could be something like (540) 90_-____, which includes
129
+ // a bunch of `_` which are placeholder characters) and we are not in *no guide* mode,
130
+ // then we map this placeholder character to the current spot in the placeholder
131
+
132
+
133
+ if (rawValueChar === placeholderChar && suppressGuide !== true) {
134
+ conformedValue += placeholderChar; // And we go to find the next placeholder character that needs filling
135
+
136
+ continue placeholderLoop; // Else if, the character we got from the user input is not a placeholder, let's see
137
+ // if the current position in the mask can accept it.
138
+ } else if (mask[_i2].test(rawValueChar)) {
139
+ // we map the character differently based on whether we are keeping character positions or not.
140
+ // If any of the conditions below are met, we simply map the raw value character to the
141
+ // placeholder position.
142
+ if (keepCharPositions !== true || isNew === false || previousConformedValue === '' || guide === false || !isAddition) {
143
+ conformedValue += rawValueChar;
144
+ } else {
145
+ // We enter this block of code if we are trying to keep character positions and none of the conditions
146
+ // above is met. In this case, we need to see if there's an available spot for the raw value character
147
+ // to be mapped to. If we couldn't find a spot, we will discard the character.
148
+ //
149
+ // For example, for mask `1111`, previous conformed value `_2__`, raw value `942_2__`. We can map the
150
+ // `9`, to the first available placeholder position, but then, there are no more spots available for the
151
+ // `4` and `2`. So, we discard them and end up with a conformed value of `92__`.
152
+ var rawValueArrLength = rawValueArr.length;
153
+ var indexOfNextAvailablePlaceholderChar = null; // Let's loop through the remaining raw value characters. We are looking for either a suitable spot, ie,
154
+ // a placeholder character or a non-suitable spot, ie, a non-placeholder character that is not new.
155
+ // If we see a suitable spot first, we store its position and exit the loop. If we see a non-suitable
156
+ // spot first, we exit the loop and our `indexOfNextAvailablePlaceholderChar` will stay as `null`.
157
+
158
+ for (var _i3 = 0; _i3 < rawValueArrLength; _i3++) {
159
+ var charData = rawValueArr[_i3];
160
+
161
+ if (charData.char !== placeholderChar && charData.isNew === false) {
162
+ break;
163
+ }
164
+
165
+ if (charData.char === placeholderChar) {
166
+ indexOfNextAvailablePlaceholderChar = _i3;
167
+ break;
168
+ }
169
+ } // If `indexOfNextAvailablePlaceholderChar` is not `null`, that means the character is not blocked.
170
+ // We can map it. And to keep the character positions, we remove the placeholder character
171
+ // from the remaining characters
172
+
173
+
174
+ if (indexOfNextAvailablePlaceholderChar !== null) {
175
+ conformedValue += rawValueChar;
176
+ rawValueArr.splice(indexOfNextAvailablePlaceholderChar, 1); // If `indexOfNextAvailablePlaceholderChar` is `null`, that means the character is blocked. We have to
177
+ // discard it.
178
+ } else {
179
+ _i2--;
180
+ }
181
+ } // Since we've mapped this placeholder position. We move on to the next one.
182
+
183
+
184
+ continue placeholderLoop;
185
+ } else {
186
+ someCharsRejected = true;
187
+ }
188
+ }
189
+ } // We reach this point when we've mapped all the user input characters to placeholder
190
+ // positions in the mask. In *guide* mode, we append the left over characters in the
191
+ // placeholder to the `conformedString`, but in *no guide* mode, we don't wanna do that.
192
+ //
193
+ // That is, for mask `(111)` and user input `2`, we want to return `(2`, not `(2__)`.
194
+
195
+
196
+ if (suppressGuide === false) {
197
+ conformedValue += placeholder.substr(_i2, placeholderLength);
198
+ } // And we break
199
+
200
+
201
+ break; // Else, the charInPlaceholder is not a placeholderChar. That is, we cannot fill it
202
+ // with user input. So we just map it to the final output
203
+ } else {
204
+ conformedValue += charInPlaceholder;
205
+ }
206
+ } // The following logic is needed to deal with the case of deletion in *no guide* mode.
207
+ //
208
+ // Consider the silly mask `(111) /// 1`. What if user tries to delete the last placeholder
209
+ // position? Something like `(589) /// `. We want to conform that to `(589`. Not `(589) /// `.
210
+ // That's why the logic below finds the last filled placeholder character, and removes everything
211
+ // from that point on.
212
+
213
+
214
+ if (suppressGuide && isAddition === false) {
215
+ var indexOfLastFilledPlaceholderChar = null; // Find the last filled placeholder position and substring from there
216
+
217
+ for (var _i4 = 0; _i4 < conformedValue.length; _i4++) {
218
+ if (placeholder[_i4] === placeholderChar) {
219
+ indexOfLastFilledPlaceholderChar = _i4;
220
+ }
221
+ }
222
+
223
+ if (indexOfLastFilledPlaceholderChar !== null) {
224
+ // We substring from the beginning until the position after the last filled placeholder char.
225
+ conformedValue = conformedValue.substr(0, indexOfLastFilledPlaceholderChar + 1);
226
+ } else {
227
+ // If we couldn't find `indexOfLastFilledPlaceholderChar` that means the user deleted
228
+ // the first character in the mask. So we return an empty string.
229
+ conformedValue = '';
230
+ }
231
+ }
232
+
233
+ return {
234
+ conformedValue: conformedValue,
235
+ meta: {
236
+ someCharsRejected: someCharsRejected
237
+ }
238
+ };
239
+ }
@@ -0,0 +1,7 @@
1
+ export default function createTextMaskInputElement(config: any): {
2
+ state: {
3
+ previousConformedValue: any;
4
+ previousPlaceholder: any;
5
+ };
6
+ update(rawValue: any, { inputElement, mask: providedMask, guide, pipe, placeholderChar, keepCharPositions, showMask }?: any): void;
7
+ };