cx 22.3.2 → 22.3.3

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 (760) hide show
  1. package/LICENSE-THIRD-PARTY.md +91 -91
  2. package/LICENSE.md +7 -7
  3. package/README.md +46 -46
  4. package/dist/data.js +2467 -2401
  5. package/dist/manifest.js +803 -797
  6. package/dist/ui.js +5209 -5188
  7. package/dist/widgets.js +21866 -21860
  8. package/index.js +17 -17
  9. package/locale/de-de.js +69 -69
  10. package/locale/en-us.js +71 -71
  11. package/locale/es-es.js +69 -69
  12. package/locale/fr-fr.js +70 -70
  13. package/locale/nl-nl.js +75 -75
  14. package/locale/pt-pt.js +63 -63
  15. package/locale/sr-latn-ba.js +70 -70
  16. package/package.json +30 -30
  17. package/src/charts/Bar.d.ts +27 -27
  18. package/src/charts/Bar.js +89 -89
  19. package/src/charts/Bar.scss +26 -26
  20. package/src/charts/BarGraph.d.ts +16 -16
  21. package/src/charts/BarGraph.js +110 -110
  22. package/src/charts/BarGraph.scss +27 -27
  23. package/src/charts/BubbleGraph.js +92 -92
  24. package/src/charts/BubbleGraph.scss +29 -29
  25. package/src/charts/Chart.d.ts +12 -12
  26. package/src/charts/Chart.js +77 -77
  27. package/src/charts/ColorMap.d.ts +26 -26
  28. package/src/charts/ColorMap.js +98 -98
  29. package/src/charts/Column.scss +26 -26
  30. package/src/charts/ColumnBarBase.d.ts +61 -61
  31. package/src/charts/ColumnBarBase.js +169 -169
  32. package/src/charts/ColumnBarGraphBase.d.ts +71 -71
  33. package/src/charts/ColumnBarGraphBase.js +119 -119
  34. package/src/charts/ColumnGraph.d.ts +19 -19
  35. package/src/charts/ColumnGraph.js +114 -114
  36. package/src/charts/ColumnGraph.scss +27 -27
  37. package/src/charts/Grid.js +5 -5
  38. package/src/charts/Gridlines.d.ts +24 -24
  39. package/src/charts/Gridlines.js +48 -48
  40. package/src/charts/Gridlines.scss +22 -22
  41. package/src/charts/Legend.d.ts +26 -26
  42. package/src/charts/Legend.js +142 -142
  43. package/src/charts/Legend.scss +41 -41
  44. package/src/charts/LegendEntry.d.ts +37 -37
  45. package/src/charts/LegendEntry.js +117 -117
  46. package/src/charts/LegendEntry.scss +30 -30
  47. package/src/charts/LineGraph.d.ts +90 -90
  48. package/src/charts/LineGraph.js +201 -201
  49. package/src/charts/LineGraph.scss +23 -23
  50. package/src/charts/Marker.d.ts +87 -87
  51. package/src/charts/Marker.js +287 -287
  52. package/src/charts/Marker.scss +41 -41
  53. package/src/charts/MarkerLine.d.ts +57 -57
  54. package/src/charts/MarkerLine.js +128 -128
  55. package/src/charts/MarkerLine.scss +17 -17
  56. package/src/charts/MouseTracker.d.ts +16 -16
  57. package/src/charts/MouseTracker.js +80 -80
  58. package/src/charts/Pie.js +8 -8
  59. package/src/charts/PieChart.d.ts +80 -80
  60. package/src/charts/PieChart.js +370 -370
  61. package/src/charts/PieChart.scss +26 -26
  62. package/src/charts/PieLabel.d.ts +26 -26
  63. package/src/charts/PieLabel.js +65 -65
  64. package/src/charts/PieLabelsContainer.d.ts +3 -3
  65. package/src/charts/PieLabelsContainer.js +55 -55
  66. package/src/charts/Range.d.ts +74 -74
  67. package/src/charts/Range.js +205 -205
  68. package/src/charts/Range.scss +18 -18
  69. package/src/charts/ScatterGraph.d.ts +65 -65
  70. package/src/charts/ScatterGraph.js +155 -155
  71. package/src/charts/ScatterGraph.scss +21 -21
  72. package/src/charts/axis/Axis.d.ts +82 -82
  73. package/src/charts/axis/Axis.js +222 -222
  74. package/src/charts/axis/Axis.scss +22 -22
  75. package/src/charts/axis/CategoryAxis.d.ts +21 -21
  76. package/src/charts/axis/CategoryAxis.js +224 -224
  77. package/src/charts/axis/CategoryAxis.scss +32 -32
  78. package/src/charts/axis/NumericAxis.js +349 -349
  79. package/src/charts/axis/NumericAxis.scss +32 -32
  80. package/src/charts/axis/Stack.d.ts +10 -10
  81. package/src/charts/axis/Stack.js +58 -58
  82. package/src/charts/axis/TimeAxis.d.ts +23 -23
  83. package/src/charts/axis/TimeAxis.js +510 -510
  84. package/src/charts/axis/TimeAxis.scss +32 -32
  85. package/src/charts/axis/index.d.ts +3 -3
  86. package/src/charts/axis/index.js +3 -3
  87. package/src/charts/axis/index.scss +5 -5
  88. package/src/charts/axis/variables.scss +2 -2
  89. package/src/charts/helpers/MinMaxFinder.js +37 -37
  90. package/src/charts/helpers/MinMaxReducer.d.ts +22 -22
  91. package/src/charts/helpers/PointReducer.d.ts +15 -15
  92. package/src/charts/helpers/PointReducer.js +39 -39
  93. package/src/charts/helpers/SnapPointFinder.d.ts +18 -18
  94. package/src/charts/helpers/SnapPointFinder.js +46 -46
  95. package/src/charts/helpers/ValueAtFinder.d.ts +16 -16
  96. package/src/charts/helpers/ValueAtFinder.js +41 -41
  97. package/src/charts/helpers/index.d.ts +4 -4
  98. package/src/charts/helpers/index.js +4 -4
  99. package/src/charts/index.d.ts +23 -23
  100. package/src/charts/index.js +31 -31
  101. package/src/charts/index.scss +20 -20
  102. package/src/charts/palette.scss +95 -95
  103. package/src/charts/shapes.d.ts +22 -22
  104. package/src/charts/shapes.js +79 -79
  105. package/src/charts/variables.scss +14 -14
  106. package/src/core.d.ts +231 -231
  107. package/src/data/AggregateFunction.d.ts +17 -17
  108. package/src/data/AggregateFunction.js +148 -148
  109. package/src/data/ArrayElementView.d.ts +13 -13
  110. package/src/data/ArrayElementView.js +46 -46
  111. package/src/data/ArrayRef.d.ts +14 -14
  112. package/src/data/ArrayRef.js +34 -34
  113. package/src/data/AugmentedViewBase.d.ts +18 -18
  114. package/src/data/AugmentedViewBase.js +67 -67
  115. package/src/data/Binding.d.ts +16 -16
  116. package/src/data/Binding.spec.js +51 -51
  117. package/src/data/ExposedRecordView.d.ts +14 -14
  118. package/src/data/ExposedRecordView.js +69 -69
  119. package/src/data/ExposedValueView.d.ts +19 -19
  120. package/src/data/ExposedValueView.js +72 -72
  121. package/src/data/Expression.d.ts +16 -16
  122. package/src/data/Grouper.d.ts +21 -21
  123. package/src/data/Grouper.js +120 -120
  124. package/src/data/Grouper.spec.js +22 -22
  125. package/src/data/NestedDataView.d.ts +19 -19
  126. package/src/data/NestedDataView.js +22 -22
  127. package/src/data/ReadOnlyDataView.d.ts +14 -14
  128. package/src/data/ReadOnlyDataView.js +26 -26
  129. package/src/data/Ref.js +79 -79
  130. package/src/data/Store.d.ts +14 -14
  131. package/src/data/Store.js +46 -46
  132. package/src/data/Store.spec.js +22 -22
  133. package/src/data/StoreProxy.d.ts +4 -4
  134. package/src/data/StoreProxy.js +16 -16
  135. package/src/data/StoreRef.js +54 -54
  136. package/src/data/StringTemplate.d.ts +13 -13
  137. package/src/data/StringTemplate.js +97 -97
  138. package/src/data/StringTemplate.spec.js +82 -82
  139. package/src/data/StructuredSelector.d.ts +16 -16
  140. package/src/data/StructuredSelector.js +131 -131
  141. package/src/data/StructuredSelector.spec.js +113 -113
  142. package/src/data/SubscribableView.d.ts +11 -11
  143. package/src/data/View.js +1 -1
  144. package/src/data/View.spec.js +60 -60
  145. package/src/data/ZoomIntoPropertyView.d.ts +11 -11
  146. package/src/data/ZoomIntoPropertyView.js +33 -33
  147. package/src/data/ZoomIntoPropertyView.spec.js +65 -65
  148. package/src/data/comparer.d.ts +7 -7
  149. package/src/data/comparer.js +46 -46
  150. package/src/data/comparer.spec.js +60 -60
  151. package/src/data/computable.js +56 -56
  152. package/src/data/computable.spec.js +55 -55
  153. package/src/data/createAccessorModelProxy.js +24 -24
  154. package/src/data/createAccessorModelProxy.spec.tsx +23 -23
  155. package/src/data/createStructuredSelector.d.ts +2 -2
  156. package/src/data/createStructuredSelector.js +43 -43
  157. package/src/data/createStructuredSelector.spec.js +46 -46
  158. package/src/data/defaultCompare.js +14 -14
  159. package/src/data/diff/diffArrays.d.ts +15 -15
  160. package/src/data/diff/diffArrays.js +41 -41
  161. package/src/data/diff/diffs.spec.js +49 -49
  162. package/src/data/diff/index.d.ts +1 -1
  163. package/src/data/diff/index.js +1 -1
  164. package/src/data/enableFatArrowExpansion.d.ts +1 -1
  165. package/src/data/enableFatArrowExpansion.js +6 -6
  166. package/src/data/getAccessor.d.ts +8 -8
  167. package/src/data/getSelector.d.ts +3 -3
  168. package/src/data/getSelector.spec.js +43 -43
  169. package/src/data/isSelector.d.ts +1 -1
  170. package/src/data/isSelector.js +26 -26
  171. package/src/data/ops/append.d.ts +1 -1
  172. package/src/data/ops/append.js +7 -7
  173. package/src/data/ops/append.spec.js +28 -28
  174. package/src/data/ops/filter.d.ts +1 -1
  175. package/src/data/ops/filter.js +8 -8
  176. package/src/data/ops/filter.spec.js +29 -29
  177. package/src/data/ops/findTreeNode.js +15 -15
  178. package/src/data/ops/findTreeNode.spec.js +24 -24
  179. package/src/data/ops/index.d.ts +10 -10
  180. package/src/data/ops/index.js +10 -10
  181. package/src/data/ops/insertElement.js +2 -2
  182. package/src/data/ops/merge.d.ts +3 -3
  183. package/src/data/ops/merge.js +9 -9
  184. package/src/data/ops/merge.spec.js +27 -27
  185. package/src/data/ops/moveElement.js +13 -13
  186. package/src/data/ops/removeTreeNodes.d.ts +1 -1
  187. package/src/data/ops/removeTreeNodes.js +5 -5
  188. package/src/data/ops/removeTreeNodes.spec.js +28 -28
  189. package/src/data/ops/updateArray.d.ts +5 -5
  190. package/src/data/ops/updateArray.js +24 -24
  191. package/src/data/ops/updateArray.spec.js +38 -38
  192. package/src/data/ops/updateTree.d.ts +7 -7
  193. package/src/data/ops/updateTree.js +25 -25
  194. package/src/data/ops/updateTree.spec.js +34 -34
  195. package/src/global.scss +13 -13
  196. package/src/hooks/createLocalStorageRef.d.ts +2 -2
  197. package/src/hooks/createLocalStorageRef.js +22 -22
  198. package/src/hooks/index.d.ts +8 -8
  199. package/src/hooks/index.js +7 -7
  200. package/src/hooks/invokeCallback.d.ts +5 -5
  201. package/src/hooks/invokeCallback.js +6 -6
  202. package/src/hooks/invokeCallback.spec.js +53 -53
  203. package/src/hooks/resolveCallback.d.ts +3 -3
  204. package/src/hooks/resolveCallback.js +11 -11
  205. package/src/hooks/resolveCallback.spec.js +54 -54
  206. package/src/hooks/store.d.ts +7 -7
  207. package/src/hooks/store.js +32 -32
  208. package/src/hooks/store.spec.js +73 -73
  209. package/src/hooks/useEffect.d.ts +2 -2
  210. package/src/hooks/useEffect.js +14 -14
  211. package/src/hooks/useInterval.js +7 -7
  212. package/src/hooks/useState.d.ts +2 -2
  213. package/src/hooks/useState.js +15 -15
  214. package/src/hooks/useTrigger.d.ts +4 -4
  215. package/src/hooks/useTrigger.js +20 -20
  216. package/src/hooks/useTrigger.spec.js +102 -102
  217. package/src/index.js +7 -7
  218. package/src/index.scss +6 -6
  219. package/src/svg/BoundedObject.d.ts +22 -22
  220. package/src/svg/BoundedObject.js +59 -59
  221. package/src/svg/ClipRect.d.ts +4 -4
  222. package/src/svg/ClipRect.js +23 -23
  223. package/src/svg/Ellipse.d.ts +23 -23
  224. package/src/svg/Ellipse.js +36 -36
  225. package/src/svg/Line.d.ts +20 -20
  226. package/src/svg/Line.js +32 -32
  227. package/src/svg/NonOverlappingRect.d.ts +5 -5
  228. package/src/svg/NonOverlappingRect.js +14 -14
  229. package/src/svg/NonOverlappingRectGroup.d.ts +3 -3
  230. package/src/svg/NonOverlappingRectGroup.js +36 -36
  231. package/src/svg/Rectangle.d.ts +23 -23
  232. package/src/svg/Rectangle.js +36 -36
  233. package/src/svg/Svg.d.ts +32 -32
  234. package/src/svg/Svg.js +177 -177
  235. package/src/svg/Svg.scss +26 -26
  236. package/src/svg/Text.d.ts +38 -38
  237. package/src/svg/Text.js +61 -61
  238. package/src/svg/TextualBoundedObject.d.ts +6 -6
  239. package/src/svg/TextualBoundedObject.js +28 -28
  240. package/src/svg/index.d.ts +11 -11
  241. package/src/svg/index.js +17 -17
  242. package/src/svg/index.scss +8 -8
  243. package/src/svg/util/Rect.d.ts +40 -40
  244. package/src/svg/util/Rect.js +108 -108
  245. package/src/ui/CSS.d.ts +19 -19
  246. package/src/ui/CSS.js +79 -79
  247. package/src/ui/CSSHelper.d.ts +10 -10
  248. package/src/ui/CSSHelper.js +17 -17
  249. package/src/ui/Container.d.ts +18 -18
  250. package/src/ui/Container.js +183 -183
  251. package/src/ui/ContentResolver.d.ts +13 -13
  252. package/src/ui/ContentResolver.js +78 -78
  253. package/src/ui/Controller.js +114 -114
  254. package/src/ui/Controller.spec.js +414 -414
  255. package/src/ui/Culture.d.ts +22 -22
  256. package/src/ui/Culture.js +65 -65
  257. package/src/ui/Cx.d.ts +18 -18
  258. package/src/ui/Cx.js +313 -313
  259. package/src/ui/Cx.spec.js +193 -193
  260. package/src/ui/DataProxy.d.ts +10 -10
  261. package/src/ui/DataProxy.js +44 -44
  262. package/src/ui/DataProxy.spec.js +335 -335
  263. package/src/ui/DetachedScope.d.ts +21 -21
  264. package/src/ui/DetachedScope.js +93 -93
  265. package/src/ui/FocusManager.d.ts +29 -29
  266. package/src/ui/FocusManager.js +163 -163
  267. package/src/ui/Format.d.ts +2 -2
  268. package/src/ui/Format.js +88 -88
  269. package/src/ui/HoverSync.d.ts +13 -13
  270. package/src/ui/HoverSync.js +147 -147
  271. package/src/ui/IsolatedScope.d.ts +16 -16
  272. package/src/ui/IsolatedScope.js +29 -29
  273. package/src/ui/IsolatedScope.spec.js +62 -62
  274. package/src/ui/Localization.d.ts +17 -17
  275. package/src/ui/Localization.js +72 -72
  276. package/src/ui/PureContainer.d.ts +16 -16
  277. package/src/ui/PureContainer.js +7 -7
  278. package/src/ui/RenderingContext.d.ts +9 -9
  279. package/src/ui/RenderingContext.js +88 -88
  280. package/src/ui/Repeater.d.ts +46 -46
  281. package/src/ui/Repeater.js +98 -98
  282. package/src/ui/Repeater.spec.js +59 -59
  283. package/src/ui/Rescope.d.ts +9 -9
  284. package/src/ui/Rescope.js +31 -31
  285. package/src/ui/Rescope.spec.js +195 -195
  286. package/src/ui/ResizeManager.d.ts +9 -9
  287. package/src/ui/ResizeManager.js +30 -30
  288. package/src/ui/Restate.d.ts +12 -12
  289. package/src/ui/Restate.js +155 -155
  290. package/src/ui/Restate.spec.js +422 -422
  291. package/src/ui/StaticText.d.ts +8 -8
  292. package/src/ui/StaticText.js +9 -9
  293. package/src/ui/StructuredInstanceDataAccessor.d.ts +16 -16
  294. package/src/ui/StructuredInstanceDataAccessor.js +26 -26
  295. package/src/ui/Text.d.ts +10 -10
  296. package/src/ui/Text.js +27 -27
  297. package/src/ui/VDOM.d.ts +3 -3
  298. package/src/ui/VDOM.js +2 -2
  299. package/src/ui/Widget.d.ts +14 -14
  300. package/src/ui/Widget.js +200 -200
  301. package/src/ui/ZIndexManager.d.ts +7 -7
  302. package/src/ui/ZIndexManager.js +11 -11
  303. package/src/ui/adapter/ArrayAdapter.d.ts +16 -16
  304. package/src/ui/adapter/ArrayAdapter.js +142 -142
  305. package/src/ui/adapter/DataAdapter.d.ts +19 -19
  306. package/src/ui/adapter/DataAdapter.js +19 -19
  307. package/src/ui/adapter/GroupAdapter.d.ts +4 -4
  308. package/src/ui/adapter/GroupAdapter.js +135 -135
  309. package/src/ui/adapter/TreeAdapter.d.ts +4 -4
  310. package/src/ui/adapter/TreeAdapter.js +73 -73
  311. package/src/ui/adapter/TreeAdapter.spec.js +67 -67
  312. package/src/ui/adapter/index.d.ts +4 -4
  313. package/src/ui/adapter/index.js +4 -4
  314. package/src/ui/app/History.d.ts +17 -17
  315. package/src/ui/app/History.js +114 -114
  316. package/src/ui/app/Url.d.ts +21 -21
  317. package/src/ui/app/Url.js +103 -103
  318. package/src/ui/app/Url.spec.js +51 -51
  319. package/src/ui/app/index.d.ts +4 -4
  320. package/src/ui/app/index.js +5 -5
  321. package/src/ui/app/startAppLoop.d.ts +3 -3
  322. package/src/ui/app/startAppLoop.js +57 -57
  323. package/src/ui/app/startHotAppLoop.d.ts +6 -6
  324. package/src/ui/app/startHotAppLoop.js +25 -25
  325. package/src/ui/batchUpdates.d.ts +10 -10
  326. package/src/ui/batchUpdates.js +67 -67
  327. package/src/ui/bind.js +7 -7
  328. package/src/ui/createFunctionalComponent.d.ts +1 -1
  329. package/src/ui/createFunctionalComponent.js +68 -68
  330. package/src/ui/createFunctionalComponent.spec.js +400 -400
  331. package/src/ui/expr.js +17 -17
  332. package/src/ui/flattenProps.js +21 -21
  333. package/src/ui/index.js +44 -44
  334. package/src/ui/index.scss +2 -2
  335. package/src/ui/keyboardShortcuts.d.ts +4 -4
  336. package/src/ui/keyboardShortcuts.js +32 -32
  337. package/src/ui/layout/Content.d.ts +11 -11
  338. package/src/ui/layout/Content.js +16 -16
  339. package/src/ui/layout/ContentPlaceholder.d.ts +17 -17
  340. package/src/ui/layout/ContentPlaceholder.js +79 -79
  341. package/src/ui/layout/ContentPlaceholder.spec.js +368 -368
  342. package/src/ui/layout/FirstVisibleChildLayout.d.ts +4 -4
  343. package/src/ui/layout/FirstVisibleChildLayout.js +65 -65
  344. package/src/ui/layout/FirstVisibleChildLayout.spec.js +196 -196
  345. package/src/ui/layout/LabelsLeftLayout.d.ts +11 -11
  346. package/src/ui/layout/LabelsLeftLayout.js +59 -59
  347. package/src/ui/layout/LabelsLeftLayout.scss +44 -44
  348. package/src/ui/layout/LabelsTopLayout.d.ts +15 -15
  349. package/src/ui/layout/LabelsTopLayout.js +134 -134
  350. package/src/ui/layout/LabelsTopLayout.scss +63 -63
  351. package/src/ui/layout/UseParentLayout.d.ts +4 -4
  352. package/src/ui/layout/UseParentLayout.js +6 -6
  353. package/src/ui/layout/exploreChildren.d.ts +14 -14
  354. package/src/ui/layout/exploreChildren.js +40 -40
  355. package/src/ui/layout/index.d.ts +10 -10
  356. package/src/ui/layout/index.js +10 -10
  357. package/src/ui/layout/index.scss +3 -3
  358. package/src/ui/layout/variables.scss +2 -2
  359. package/src/ui/selection/KeySelection.d.ts +17 -17
  360. package/src/ui/selection/KeySelection.js +129 -129
  361. package/src/ui/selection/PropertySelection.d.ts +17 -17
  362. package/src/ui/selection/PropertySelection.js +57 -57
  363. package/src/ui/selection/Selection.d.ts +27 -27
  364. package/src/ui/selection/Selection.js +97 -97
  365. package/src/ui/selection/index.d.ts +3 -3
  366. package/src/ui/selection/index.js +3 -3
  367. package/src/ui/tpl.d.ts +2 -2
  368. package/src/ui/tpl.js +4 -4
  369. package/src/ui/variables.scss +1 -1
  370. package/src/util/Component.d.ts +41 -41
  371. package/src/util/Component.js +107 -107
  372. package/src/util/Console.d.ts +9 -9
  373. package/src/util/Console.js +11 -11
  374. package/src/util/DOM.d.ts +33 -33
  375. package/src/util/DOM.js +72 -72
  376. package/src/util/Debug.d.ts +10 -10
  377. package/src/util/Debug.js +45 -45
  378. package/src/util/Format.d.ts +13 -13
  379. package/src/util/Format.js +241 -241
  380. package/src/util/Format.spec.js +69 -69
  381. package/src/util/GlobalCacheIdentifier.js +11 -11
  382. package/src/util/GlobalCacheldentifier.d.ts +6 -6
  383. package/src/util/KeyCode.d.ts +21 -21
  384. package/src/util/KeyCode.js +21 -21
  385. package/src/util/SubscriberList.d.ts +41 -41
  386. package/src/util/SubscriberList.js +57 -57
  387. package/src/util/Timing.d.ts +13 -13
  388. package/src/util/Timing.js +57 -57
  389. package/src/util/TraversalStack.js +42 -42
  390. package/src/util/TraversalStack.spec.js +46 -46
  391. package/src/util/addEventListenerWithOptions.d.ts +6 -6
  392. package/src/util/addEventListenerWithOptions.js +9 -9
  393. package/src/util/browserSupportsPassiveEventHandlers.d.ts +4 -4
  394. package/src/util/browserSupportsPassiveEventHandlers.js +18 -18
  395. package/src/util/calculateNaturalElementHeight.d.ts +1 -1
  396. package/src/util/calculateNaturalElementHeight.js +22 -22
  397. package/src/util/call-once.scss +6 -6
  398. package/src/util/coalesce.d.ts +1 -1
  399. package/src/util/coalesce.js +6 -6
  400. package/src/util/color/hslToRgb.d.ts +8 -8
  401. package/src/util/color/hslToRgb.js +27 -27
  402. package/src/util/color/index.d.ts +3 -3
  403. package/src/util/color/index.js +4 -4
  404. package/src/util/color/parseColor.d.ts +59 -59
  405. package/src/util/color/parseColor.js +119 -119
  406. package/src/util/color/rgbToHex.d.ts +8 -8
  407. package/src/util/color/rgbToHex.js +7 -7
  408. package/src/util/color/rgbToHsl.d.ts +8 -8
  409. package/src/util/color/rgbToHsl.js +27 -27
  410. package/src/util/date/dateDiff.d.ts +7 -7
  411. package/src/util/date/dateDiff.js +3 -3
  412. package/src/util/date/diff.d.ts +7 -7
  413. package/src/util/date/diff.js +7 -7
  414. package/src/util/date/encodeDateWithTimezoneOffset.js +18 -18
  415. package/src/util/date/index.d.ts +8 -8
  416. package/src/util/date/index.js +9 -9
  417. package/src/util/date/lowerBoundCheck.d.ts +7 -7
  418. package/src/util/date/lowerBoundCheck.js +6 -6
  419. package/src/util/date/maxDate.d.ts +5 -5
  420. package/src/util/date/maxDate.js +9 -9
  421. package/src/util/date/minDate.d.ts +5 -5
  422. package/src/util/date/minDate.js +9 -9
  423. package/src/util/date/monthStart.d.ts +5 -5
  424. package/src/util/date/monthStart.js +3 -3
  425. package/src/util/date/sameDate.d.ts +6 -6
  426. package/src/util/date/sameDate.js +5 -5
  427. package/src/util/date/upperBoundCheck.d.ts +7 -7
  428. package/src/util/date/upperBoundCheck.js +6 -6
  429. package/src/util/date/upperBoundCheck.spec.js +30 -30
  430. package/src/util/date/zeroTime.d.ts +6 -6
  431. package/src/util/date/zeroTime.js +3 -3
  432. package/src/util/debounce.d.ts +9 -9
  433. package/src/util/dummyCallback.d.ts +1 -1
  434. package/src/util/dummyCallback.js +1 -1
  435. package/src/util/escapeSpecialRegexCharacters.d.ts +6 -6
  436. package/src/util/escapeSpecialRegexCharacters.js +3 -3
  437. package/src/util/eventCallbacks.d.ts +4 -4
  438. package/src/util/eventCallbacks.js +2 -2
  439. package/src/util/expandFatArrows.js +118 -118
  440. package/src/util/findScrollableParent.js +16 -16
  441. package/src/util/getActiveElement.js +3 -3
  442. package/src/util/getParentFrameBoundingClientRect.js +18 -18
  443. package/src/util/getScrollerBoundingClientRect.js +21 -21
  444. package/src/util/getSearchQueryPredicate.js +58 -58
  445. package/src/util/getSearchQueryPredicate.spec.js +40 -40
  446. package/src/util/getTopLevelBoundingClientRect.js +13 -13
  447. package/src/util/getVendorPrefix.js +26 -26
  448. package/src/util/index.d.ts +50 -50
  449. package/src/util/index.js +52 -52
  450. package/src/util/index.scss +10 -10
  451. package/src/util/innerTextTrim.d.ts +6 -6
  452. package/src/util/innerTextTrim.js +5 -5
  453. package/src/util/isArray.js +3 -3
  454. package/src/util/isDefined.js +3 -3
  455. package/src/util/isDigit.d.ts +6 -6
  456. package/src/util/isDigit.js +3 -3
  457. package/src/util/isFunction.d.ts +1 -1
  458. package/src/util/isFunction.js +3 -3
  459. package/src/util/isNonEmptyArray.d.ts +1 -1
  460. package/src/util/isNonEmptyArray.js +3 -3
  461. package/src/util/isNumber.js +3 -3
  462. package/src/util/isObject.js +3 -3
  463. package/src/util/isPromise.d.ts +1 -1
  464. package/src/util/isPromise.js +6 -6
  465. package/src/util/isString.js +3 -3
  466. package/src/util/isTextInputElement.d.ts +1 -1
  467. package/src/util/isTextInputElement.js +2 -2
  468. package/src/util/isTouchDevice.d.ts +1 -1
  469. package/src/util/isTouchDevice.js +7 -7
  470. package/src/util/isTouchEvent.d.ts +3 -3
  471. package/src/util/isTouchEvent.js +52 -52
  472. package/src/util/isUndefined.js +3 -3
  473. package/src/util/onIdleCallback.js +13 -13
  474. package/src/util/parseStyle.d.ts +3 -3
  475. package/src/util/parseStyle.js +27 -27
  476. package/src/util/quote.d.ts +2 -2
  477. package/src/util/quote.js +5 -5
  478. package/src/util/reverseSlice.js +9 -9
  479. package/src/util/routeAppend.js +15 -15
  480. package/src/util/routeAppend.spec.js +19 -19
  481. package/src/util/scrollElementIntoView.d.ts +6 -6
  482. package/src/util/scrollElementIntoView.js +59 -59
  483. package/src/util/scss/add-rules.scss +39 -39
  484. package/src/util/scss/calc.scss +40 -40
  485. package/src/util/scss/call-once.scss +10 -10
  486. package/src/util/scss/clockwise.scss +47 -47
  487. package/src/util/scss/colors.scss +7 -7
  488. package/src/util/scss/deep-get.scss +9 -9
  489. package/src/util/scss/deep-merge.scss +18 -18
  490. package/src/util/scss/include.scss +47 -47
  491. package/src/util/scss/index.scss +8 -8
  492. package/src/util/shallowEquals.js +43 -43
  493. package/src/util/throttle.d.ts +8 -8
  494. package/src/util/throttle.js +14 -14
  495. package/src/variables.scss +217 -217
  496. package/src/widgets/AccessorBindings.spec.tsx +66 -66
  497. package/src/widgets/Button.d.ts +52 -52
  498. package/src/widgets/Button.scss +108 -108
  499. package/src/widgets/Button.variables.scss +107 -107
  500. package/src/widgets/CxCredit.d.ts +12 -12
  501. package/src/widgets/CxCredit.js +31 -31
  502. package/src/widgets/CxCredit.scss +41 -41
  503. package/src/widgets/DocumentTitle.d.ts +10 -10
  504. package/src/widgets/DocumentTitle.js +68 -68
  505. package/src/widgets/FlexBox.d.ts +69 -69
  506. package/src/widgets/FlexBox.js +92 -92
  507. package/src/widgets/FlexBox.scss +155 -155
  508. package/src/widgets/Heading.d.ts +16 -16
  509. package/src/widgets/Heading.js +32 -32
  510. package/src/widgets/Heading.scss +38 -38
  511. package/src/widgets/HighlightedSearchText.d.ts +9 -9
  512. package/src/widgets/HighlightedSearchText.js +36 -36
  513. package/src/widgets/HighlightedSearchText.scss +18 -18
  514. package/src/widgets/HtmlElement.d.ts +26 -26
  515. package/src/widgets/HtmlElement.js +273 -273
  516. package/src/widgets/HtmlElement.spec.js +57 -57
  517. package/src/widgets/Icon.d.ts +36 -36
  518. package/src/widgets/Icon.js +50 -50
  519. package/src/widgets/Icon.scss +20 -20
  520. package/src/widgets/List.d.ts +84 -70
  521. package/src/widgets/List.js +578 -578
  522. package/src/widgets/List.scss +92 -92
  523. package/src/widgets/ProgressBar.d.ts +17 -17
  524. package/src/widgets/ProgressBar.js +46 -46
  525. package/src/widgets/ProgressBar.scss +49 -49
  526. package/src/widgets/Resizer.d.ts +27 -27
  527. package/src/widgets/Resizer.js +151 -151
  528. package/src/widgets/Resizer.scss +42 -42
  529. package/src/widgets/Sandbox.d.ts +18 -18
  530. package/src/widgets/Sandbox.js +58 -58
  531. package/src/widgets/Section.d.ts +52 -52
  532. package/src/widgets/Section.js +139 -139
  533. package/src/widgets/Section.scss +54 -54
  534. package/src/widgets/animations.scss +10 -10
  535. package/src/widgets/autoFocus.d.ts +1 -1
  536. package/src/widgets/autoFocus.js +11 -11
  537. package/src/widgets/cx.d.ts +1 -1
  538. package/src/widgets/cx.js +71 -71
  539. package/src/widgets/drag-drop/DragClone.scss +33 -33
  540. package/src/widgets/drag-drop/DragHandle.d.ts +10 -10
  541. package/src/widgets/drag-drop/DragHandle.js +37 -37
  542. package/src/widgets/drag-drop/DragHandle.scss +16 -16
  543. package/src/widgets/drag-drop/DragSource.d.ts +34 -34
  544. package/src/widgets/drag-drop/DragSource.js +160 -160
  545. package/src/widgets/drag-drop/DragSource.scss +24 -24
  546. package/src/widgets/drag-drop/DropZone.d.ts +90 -90
  547. package/src/widgets/drag-drop/DropZone.js +213 -213
  548. package/src/widgets/drag-drop/DropZone.scss +74 -74
  549. package/src/widgets/drag-drop/index.d.ts +4 -4
  550. package/src/widgets/drag-drop/index.js +4 -4
  551. package/src/widgets/drag-drop/index.scss +3 -3
  552. package/src/widgets/drag-drop/ops.d.ts +56 -56
  553. package/src/widgets/drag-drop/ops.js +344 -344
  554. package/src/widgets/drag-drop/variables.scss +11 -11
  555. package/src/widgets/enableAllInternalDependencies.d.ts +1 -1
  556. package/src/widgets/enableAllInternalDependencies.js +11 -11
  557. package/src/widgets/form/Calendar.d.ts +57 -57
  558. package/src/widgets/form/Calendar.js +506 -506
  559. package/src/widgets/form/Calendar.scss +164 -164
  560. package/src/widgets/form/Calendar.variables.scss +63 -63
  561. package/src/widgets/form/Checkbox.d.ts +43 -43
  562. package/src/widgets/form/Checkbox.js +200 -200
  563. package/src/widgets/form/Checkbox.scss +122 -122
  564. package/src/widgets/form/Checkbox.variables.scss +39 -39
  565. package/src/widgets/form/ColorField.d.ts +43 -43
  566. package/src/widgets/form/ColorField.js +389 -389
  567. package/src/widgets/form/ColorField.scss +92 -92
  568. package/src/widgets/form/ColorPicker.d.ts +23 -23
  569. package/src/widgets/form/ColorPicker.js +451 -451
  570. package/src/widgets/form/ColorPicker.scss +184 -184
  571. package/src/widgets/form/ColorPicker.variables.scss +20 -20
  572. package/src/widgets/form/DateField.d.ts +6 -6
  573. package/src/widgets/form/DateField.js +12 -12
  574. package/src/widgets/form/DateTimeField.d.ts +83 -83
  575. package/src/widgets/form/DateTimeField.js +571 -571
  576. package/src/widgets/form/DateTimeField.scss +90 -90
  577. package/src/widgets/form/DateTimePicker.js +391 -391
  578. package/src/widgets/form/DateTimePicker.scss +44 -44
  579. package/src/widgets/form/Field.d.ts +112 -112
  580. package/src/widgets/form/Field.js +419 -419
  581. package/src/widgets/form/Field.scss +162 -162
  582. package/src/widgets/form/FieldGroup.d.ts +6 -6
  583. package/src/widgets/form/FieldGroup.js +5 -5
  584. package/src/widgets/form/HelpText.d.ts +10 -10
  585. package/src/widgets/form/HelpText.js +9 -9
  586. package/src/widgets/form/HelpText.scss +23 -23
  587. package/src/widgets/form/Label.d.ts +25 -25
  588. package/src/widgets/form/Label.js +86 -86
  589. package/src/widgets/form/Label.scss +36 -36
  590. package/src/widgets/form/LabeledContainer.d.ts +17 -17
  591. package/src/widgets/form/LabeledContainer.js +57 -57
  592. package/src/widgets/form/LookupField.d.ts +159 -159
  593. package/src/widgets/form/LookupField.js +1109 -1109
  594. package/src/widgets/form/LookupField.scss +210 -210
  595. package/src/widgets/form/MonthField.d.ts +88 -88
  596. package/src/widgets/form/MonthField.js +512 -512
  597. package/src/widgets/form/MonthField.scss +99 -99
  598. package/src/widgets/form/MonthPicker.d.ts +68 -68
  599. package/src/widgets/form/MonthPicker.js +631 -631
  600. package/src/widgets/form/MonthPicker.scss +120 -120
  601. package/src/widgets/form/NumberField.d.ts +94 -94
  602. package/src/widgets/form/NumberField.js +443 -443
  603. package/src/widgets/form/NumberField.scss +65 -65
  604. package/src/widgets/form/Radio.d.ts +37 -37
  605. package/src/widgets/form/Radio.js +188 -188
  606. package/src/widgets/form/Radio.scss +122 -122
  607. package/src/widgets/form/Radio.variables.scss +45 -45
  608. package/src/widgets/form/Select.d.ts +73 -73
  609. package/src/widgets/form/Select.js +274 -274
  610. package/src/widgets/form/Select.scss +98 -98
  611. package/src/widgets/form/Slider.d.ts +62 -62
  612. package/src/widgets/form/Slider.js +339 -339
  613. package/src/widgets/form/Slider.scss +121 -121
  614. package/src/widgets/form/Switch.d.ts +38 -38
  615. package/src/widgets/form/Switch.js +120 -120
  616. package/src/widgets/form/Switch.scss +140 -140
  617. package/src/widgets/form/TextArea.d.ts +17 -17
  618. package/src/widgets/form/TextArea.js +182 -182
  619. package/src/widgets/form/TextArea.scss +60 -60
  620. package/src/widgets/form/TextField.d.ts +75 -75
  621. package/src/widgets/form/TextField.js +286 -286
  622. package/src/widgets/form/TextField.scss +67 -67
  623. package/src/widgets/form/TimeField.d.ts +6 -6
  624. package/src/widgets/form/TimeField.js +11 -11
  625. package/src/widgets/form/TimeList.js +84 -84
  626. package/src/widgets/form/UploadButton.d.ts +31 -31
  627. package/src/widgets/form/UploadButton.js +213 -213
  628. package/src/widgets/form/UploadButton.scss +47 -47
  629. package/src/widgets/form/ValidationError.d.ts +10 -10
  630. package/src/widgets/form/ValidationError.js +37 -37
  631. package/src/widgets/form/ValidationError.scss +21 -21
  632. package/src/widgets/form/ValidationGroup.spec.js +148 -148
  633. package/src/widgets/form/Validator.d.ts +6 -6
  634. package/src/widgets/form/Wheel.js +261 -261
  635. package/src/widgets/form/Wheel.scss +148 -148
  636. package/src/widgets/form/index.d.ts +26 -26
  637. package/src/widgets/form/index.js +29 -29
  638. package/src/widgets/form/index.scss +24 -24
  639. package/src/widgets/form/variables.scss +351 -351
  640. package/src/widgets/grid/Grid.d.ts +368 -368
  641. package/src/widgets/grid/Grid.js +3208 -3208
  642. package/src/widgets/grid/Grid.scss +656 -656
  643. package/src/widgets/grid/GridCell.d.ts +29 -29
  644. package/src/widgets/grid/GridCell.js +70 -70
  645. package/src/widgets/grid/GridCellEditor.js +41 -41
  646. package/src/widgets/grid/GridRow.js +228 -228
  647. package/src/widgets/grid/GridRowLine.js +24 -24
  648. package/src/widgets/grid/Pagination.d.ts +14 -14
  649. package/src/widgets/grid/Pagination.js +94 -94
  650. package/src/widgets/grid/Pagination.scss +113 -113
  651. package/src/widgets/grid/TreeNode.d.ts +25 -25
  652. package/src/widgets/grid/TreeNode.js +102 -102
  653. package/src/widgets/grid/TreeNode.scss +90 -90
  654. package/src/widgets/grid/index.d.ts +3 -3
  655. package/src/widgets/grid/index.js +14 -14
  656. package/src/widgets/grid/index.scss +3 -3
  657. package/src/widgets/grid/variables.scss +88 -88
  658. package/src/widgets/icons/arrow-down.svg +3 -3
  659. package/src/widgets/icons/arrow-right.svg +2 -2
  660. package/src/widgets/icons/base.svg +104 -104
  661. package/src/widgets/icons/calendar-old.svg +169 -169
  662. package/src/widgets/icons/calendar.js +16 -16
  663. package/src/widgets/icons/calendar.svg +187 -187
  664. package/src/widgets/icons/check.js +12 -12
  665. package/src/widgets/icons/clear.js +14 -14
  666. package/src/widgets/icons/clear.svg +74 -74
  667. package/src/widgets/icons/close.js +19 -19
  668. package/src/widgets/icons/close.svg +74 -74
  669. package/src/widgets/icons/cx.js +37 -37
  670. package/src/widgets/icons/drop-down.js +14 -14
  671. package/src/widgets/icons/dropdown-arrow.svg +61 -61
  672. package/src/widgets/icons/file.js +12 -12
  673. package/src/widgets/icons/file.svg +4 -4
  674. package/src/widgets/icons/folder-open.js +14 -14
  675. package/src/widgets/icons/folder-open.svg +5 -5
  676. package/src/widgets/icons/folder.js +12 -12
  677. package/src/widgets/icons/folder.svg +58 -58
  678. package/src/widgets/icons/forward.js +21 -21
  679. package/src/widgets/icons/forward.svg +67 -67
  680. package/src/widgets/icons/index.js +14 -14
  681. package/src/widgets/icons/loading.js +23 -23
  682. package/src/widgets/icons/loading.svg +4 -4
  683. package/src/widgets/icons/menu.js +16 -16
  684. package/src/widgets/icons/registry.js +53 -53
  685. package/src/widgets/icons/search.js +12 -12
  686. package/src/widgets/icons/search.svg +107 -107
  687. package/src/widgets/icons/sort-asc.js +13 -13
  688. package/src/widgets/icons/sort-asc.svg +3 -3
  689. package/src/widgets/icons/square.js +17 -17
  690. package/src/widgets/index.d.ts +55 -55
  691. package/src/widgets/index.js +57 -57
  692. package/src/widgets/index.scss +16 -16
  693. package/src/widgets/nav/Link.d.ts +22 -22
  694. package/src/widgets/nav/Link.js +7 -7
  695. package/src/widgets/nav/LinkButton.d.ts +31 -31
  696. package/src/widgets/nav/LinkButton.js +127 -127
  697. package/src/widgets/nav/Menu.d.ts +27 -27
  698. package/src/widgets/nav/Menu.js +411 -411
  699. package/src/widgets/nav/Menu.scss +74 -74
  700. package/src/widgets/nav/Menu.variables.scss +17 -17
  701. package/src/widgets/nav/MenuItem.d.ts +32 -32
  702. package/src/widgets/nav/MenuItem.js +442 -442
  703. package/src/widgets/nav/MenuItem.scss +128 -128
  704. package/src/widgets/nav/MenuSpacer.d.ts +5 -5
  705. package/src/widgets/nav/MenuSpacer.js +12 -12
  706. package/src/widgets/nav/RedirectRoute.d.ts +9 -9
  707. package/src/widgets/nav/RedirectRoute.js +40 -40
  708. package/src/widgets/nav/Route.d.ts +21 -21
  709. package/src/widgets/nav/Route.js +105 -105
  710. package/src/widgets/nav/Route.spec.js +27 -27
  711. package/src/widgets/nav/Scroller.d.ts +17 -17
  712. package/src/widgets/nav/Scroller.js +214 -214
  713. package/src/widgets/nav/Scroller.scss +146 -146
  714. package/src/widgets/nav/Submenu.d.ts +6 -6
  715. package/src/widgets/nav/Submenu.js +6 -6
  716. package/src/widgets/nav/Tab.d.ts +33 -33
  717. package/src/widgets/nav/Tab.js +82 -82
  718. package/src/widgets/nav/Tab.scss +81 -81
  719. package/src/widgets/nav/Tab.variables.scss +80 -80
  720. package/src/widgets/nav/cover.scss +21 -21
  721. package/src/widgets/nav/index.d.ts +10 -10
  722. package/src/widgets/nav/index.js +10 -10
  723. package/src/widgets/nav/index.scss +5 -5
  724. package/src/widgets/nav/variables.scss +25 -25
  725. package/src/widgets/overlay/ContextMenu.d.ts +8 -8
  726. package/src/widgets/overlay/ContextMenu.js +28 -28
  727. package/src/widgets/overlay/Dropdown.d.ts +27 -27
  728. package/src/widgets/overlay/Dropdown.js +601 -601
  729. package/src/widgets/overlay/Dropdown.scss +184 -184
  730. package/src/widgets/overlay/FlyweightTooltipTracker.d.ts +8 -8
  731. package/src/widgets/overlay/FlyweightTooltipTracker.js +36 -36
  732. package/src/widgets/overlay/MsgBox.d.ts +16 -16
  733. package/src/widgets/overlay/MsgBox.js +116 -116
  734. package/src/widgets/overlay/Overlay.d.ts +69 -69
  735. package/src/widgets/overlay/Overlay.js +737 -737
  736. package/src/widgets/overlay/Overlay.scss +66 -66
  737. package/src/widgets/overlay/Toast.d.ts +30 -30
  738. package/src/widgets/overlay/Toast.js +92 -92
  739. package/src/widgets/overlay/Toast.scss +162 -162
  740. package/src/widgets/overlay/Tooltip.d.ts +50 -50
  741. package/src/widgets/overlay/Tooltip.js +283 -283
  742. package/src/widgets/overlay/Tooltip.scss +175 -175
  743. package/src/widgets/overlay/Window.d.ts +38 -38
  744. package/src/widgets/overlay/Window.js +195 -195
  745. package/src/widgets/overlay/Window.scss +112 -112
  746. package/src/widgets/overlay/Window.variables.scss +67 -67
  747. package/src/widgets/overlay/alerts.d.ts +7 -7
  748. package/src/widgets/overlay/alerts.js +39 -39
  749. package/src/widgets/overlay/captureMouse.d.ts +53 -53
  750. package/src/widgets/overlay/captureMouse.js +132 -132
  751. package/src/widgets/overlay/captureMouse.scss +13 -13
  752. package/src/widgets/overlay/index.d.ts +10 -10
  753. package/src/widgets/overlay/index.js +10 -10
  754. package/src/widgets/overlay/index.scss +15 -15
  755. package/src/widgets/overlay/tooltip-ops.d.ts +8 -8
  756. package/src/widgets/overlay/tooltip-ops.js +24 -24
  757. package/src/widgets/overlay/variables.scss +82 -82
  758. package/src/widgets/variables.scss +144 -144
  759. package/yarn-error.log +7973 -0
  760. package/dist/reset.js +0 -1
@@ -1,1109 +1,1109 @@
1
- import { Widget, VDOM, getContent } from "../../ui/Widget";
2
- import { Cx } from "../../ui/Cx";
3
- import { Field, getFieldTooltip } from "./Field";
4
- import { ReadOnlyDataView } from "../../data/ReadOnlyDataView";
5
- import { HtmlElement } from "../HtmlElement";
6
- import { Binding } from "../../data/Binding";
7
- import { debug } from "../../util/Debug";
8
- import { Dropdown } from "../overlay/Dropdown";
9
- import { FocusManager } from "../../ui/FocusManager";
10
- import { isFocused } from "../../util/DOM";
11
- import { isTouchDevice } from "../../util/isTouchDevice";
12
- import { isTouchEvent } from "../../util/isTouchEvent";
13
- import {
14
- tooltipParentWillReceiveProps,
15
- tooltipParentWillUnmount,
16
- tooltipMouseMove,
17
- tooltipMouseLeave,
18
- tooltipParentDidMount,
19
- } from "../overlay/tooltip-ops";
20
- import { stopPropagation, preventDefault } from "../../util/eventCallbacks";
21
- import ClearIcon from "../icons/clear";
22
- import DropdownIcon from "../icons/drop-down";
23
- import { getSearchQueryPredicate } from "../../util/getSearchQueryPredicate";
24
- import { KeyCode } from "../../util/KeyCode";
25
- import { Localization } from "../../ui/Localization";
26
- import { StringTemplate } from "../../data/StringTemplate";
27
- import { Icon } from "../Icon";
28
- import { isString } from "../../util/isString";
29
- import { isDefined } from "../../util/isDefined";
30
- import { isArray } from "../../util/isArray";
31
- import { isNonEmptyArray } from "../../util/isNonEmptyArray";
32
- import { addEventListenerWithOptions } from "../../util/addEventListenerWithOptions";
33
- import { List } from "../List";
34
- import { Selection } from "../../ui/selection/Selection";
35
- import { HighlightedSearchText } from "../HighlightedSearchText";
36
- import { autoFocus } from "../autoFocus";
37
-
38
- export class LookupField extends Field {
39
- declareData() {
40
- let additionalAttributes = this.multiple
41
- ? { values: undefined, records: undefined }
42
- : { value: undefined, text: undefined };
43
-
44
- super.declareData(
45
- {
46
- disabled: undefined,
47
- enabled: undefined,
48
- placeholder: undefined,
49
- required: undefined,
50
- options: undefined,
51
- icon: undefined,
52
- autoOpen: undefined,
53
- readOnly: undefined,
54
- },
55
- additionalAttributes,
56
- ...arguments
57
- );
58
- }
59
-
60
- init() {
61
- if (isDefined(this.hideClear)) this.showClear = !this.hideClear;
62
-
63
- if (this.alwaysShowClear) this.showClear = true;
64
-
65
- if (!this.bindings) {
66
- let b = [];
67
- if (this.value && this.value.bind)
68
- b.push({
69
- key: true,
70
- local: this.value.bind,
71
- remote: `$option.${this.optionIdField}`,
72
- set: this.value.set,
73
- });
74
-
75
- if (this.text && this.text.bind)
76
- b.push({
77
- local: this.text.bind,
78
- remote: `$option.${this.optionTextField}`,
79
- set: this.text.set,
80
- });
81
- this.bindings = b;
82
- }
83
-
84
- if (this.bindings.length == 0 && this.multiple)
85
- this.bindings = [
86
- {
87
- key: true,
88
- local: `$value.${this.valueIdField}`,
89
- remote: `$option.${this.optionIdField}`,
90
- },
91
- {
92
- local: `$value.${this.valueTextField}`,
93
- remote: `$option.${this.optionTextField}`,
94
- },
95
- ];
96
-
97
- this.keyBindings = this.bindings.filter((b) => b.key);
98
-
99
- if (!this.items && !this.children)
100
- this.items = {
101
- $type: HighlightedSearchText,
102
- text: { bind: `$option.${this.optionTextField}` },
103
- query: { bind: "$query" },
104
- };
105
-
106
- this.itemConfig = this.children || this.items;
107
-
108
- delete this.items;
109
- delete this.children;
110
-
111
- super.init();
112
- }
113
-
114
- prepareData(context, instance) {
115
- let { data, store } = instance;
116
-
117
- data.stateMods = {
118
- multiple: this.multiple,
119
- disabled: data.disabled,
120
- readonly: data.readOnly,
121
- };
122
-
123
- data.selectedKeys = [];
124
-
125
- if (this.multiple) {
126
- if (isArray(data.values) && isArray(data.options)) {
127
- data.selectedKeys = data.values.map((v) => (this.keyBindings.length == 1 ? [v] : v));
128
- let map = {};
129
- data.options.filter(($option) => {
130
- let optionKey = getOptionKey(this.keyBindings, { $option });
131
- for (let i = 0; i < data.selectedKeys.length; i++)
132
- if (areKeysEqual(optionKey, data.selectedKeys[i])) {
133
- map[i] = convertOption(this.bindings, { $option });
134
- break;
135
- }
136
- });
137
- data.records = [];
138
- for (let i = 0; i < data.selectedKeys.length; i++) if (map[i]) data.records.push(map[i]);
139
- } else if (isArray(data.records))
140
- data.selectedKeys.push(
141
- ...data.records.map(($value) => this.keyBindings.map((b) => Binding.get(b.local).value({ $value })))
142
- );
143
- } else {
144
- let dataViewData = store.getData();
145
- data.selectedKeys.push(this.keyBindings.map((b) => Binding.get(b.local).value(dataViewData)));
146
- if (!this.text && isArray(data.options)) {
147
- let option = data.options.find(($option) =>
148
- areKeysEqual(getOptionKey(this.keyBindings, { $option }), data.selectedKeys[0])
149
- );
150
- data.text = (option && option[this.optionTextField]) || "";
151
- }
152
- }
153
-
154
- instance.lastDropdown = context.lastDropdown;
155
-
156
- super.prepareData(context, instance);
157
- }
158
-
159
- renderInput(context, instance, key) {
160
- return (
161
- <LookupComponent
162
- key={key}
163
- multiple={this.multiple}
164
- instance={instance}
165
- itemConfig={this.itemConfig}
166
- bindings={this.bindings}
167
- baseClass={this.baseClass}
168
- label={this.labelPlacement && getContent(this.renderLabel(context, instance, "label"))}
169
- help={this.helpPlacement && getContent(this.renderHelp(context, instance, "help"))}
170
- forceUpdate={context.forceUpdate}
171
- />
172
- );
173
- }
174
-
175
- filterOptions(instance, options, query) {
176
- if (!query) return options;
177
- let textPredicate = getSearchQueryPredicate(query);
178
- return options.filter((o) => isString(o[this.optionTextField]) && textPredicate(o[this.optionTextField]));
179
- }
180
-
181
- isEmpty(data) {
182
- if (this.multiple) return !isNonEmptyArray(data.values) && !isNonEmptyArray(data.records);
183
- return super.isEmpty(data);
184
- }
185
-
186
- formatValue(context, instance) {
187
- if (!this.multiple) return super.formatValue(context, instance);
188
-
189
- let { records, values, options } = instance.data;
190
- if (isArray(records))
191
- return records.map((record) => record[this.valueTextField] || record[this.valueIdField]).join(", ");
192
-
193
- if (isArray(values)) {
194
- if (isArray(options))
195
- return values
196
- .map((id) => {
197
- let option = options.find((o) => o[this.optionIdField] == id);
198
- return option ? option[this.valueTextField] : id;
199
- })
200
- .filter(Boolean)
201
- .join(", ");
202
-
203
- return values.join(", ");
204
- }
205
-
206
- return null;
207
- }
208
- }
209
-
210
- LookupField.prototype.baseClass = "lookupfield";
211
- //LookupField.prototype.memoize = false;
212
- LookupField.prototype.multiple = false;
213
- LookupField.prototype.queryDelay = 150;
214
- LookupField.prototype.minQueryLength = 0;
215
- LookupField.prototype.hideSearchField = false;
216
- LookupField.prototype.minOptionsForSearchField = 7;
217
- LookupField.prototype.loadingText = "Loading...";
218
- LookupField.prototype.queryErrorText = "Error occurred while querying for lookup data.";
219
- LookupField.prototype.noResultsText = "No results found.";
220
- LookupField.prototype.optionIdField = "id";
221
- LookupField.prototype.optionTextField = "text";
222
- LookupField.prototype.valueIdField = "id";
223
- LookupField.prototype.valueTextField = "text";
224
- LookupField.prototype.suppressErrorsUntilVisited = true;
225
- LookupField.prototype.fetchAll = false;
226
- LookupField.prototype.cacheAll = false;
227
- LookupField.prototype.showClear = true;
228
- LookupField.prototype.alwaysShowClear = false;
229
- LookupField.prototype.closeOnSelect = true;
230
- LookupField.prototype.minQueryLengthMessageText = "Type in at least {0} character(s).";
231
- LookupField.prototype.icon = null;
232
- LookupField.prototype.sort = false;
233
- LookupField.prototype.listOptions = null;
234
- LookupField.prototype.autoOpen = false;
235
- LookupField.prototype.submitOnEnterKey = false;
236
- LookupField.prototype.submitOnDropdownEnterKey = false;
237
- LookupField.prototype.pageSize = 100;
238
- LookupField.prototype.infinite = false;
239
- LookupField.prototype.quickSelectAll = false;
240
-
241
- Localization.registerPrototype("cx/widgets/LookupField", LookupField);
242
-
243
- Widget.alias("lookupfield", LookupField);
244
-
245
- function getOptionKey(bindings, data) {
246
- return bindings.filter((a) => a.key).map((b) => Binding.get(b.remote).value(data));
247
- }
248
-
249
- function areKeysEqual(key1, key2) {
250
- if (!key1 || !key2 || key1.length != key2.length) return false;
251
-
252
- for (let i = 0; i < key1.length; i++) if (key1[i] != key2[i]) return false;
253
-
254
- return true;
255
- }
256
-
257
- function convertOption(bindings, data) {
258
- let result = { $value: {} };
259
- bindings.forEach((b) => {
260
- let value = Binding.get(b.remote).value(data);
261
- result = Binding.get(b.local).set(result, value);
262
- });
263
- return result.$value;
264
- }
265
-
266
- class SelectionDelegate extends Selection {
267
- constructor({ delegate }) {
268
- super();
269
- this.delegate = delegate;
270
- }
271
-
272
- getIsSelectedDelegate(store) {
273
- return (record, index) => this.delegate(record, index);
274
- }
275
-
276
- select() {
277
- return false;
278
- }
279
- }
280
-
281
- class LookupComponent extends VDOM.Component {
282
- constructor(props) {
283
- super(props);
284
- let { data, store } = this.props.instance;
285
- this.dom = {};
286
- this.state = {
287
- options: [],
288
- formatted: data.formatted,
289
- value: data.formatted,
290
- dropdownOpen: false,
291
- focus: false,
292
- };
293
-
294
- this.itemStore = new ReadOnlyDataView({
295
- store: store,
296
- });
297
- }
298
-
299
- getOptionKey(data) {
300
- return this.props.bindings.filter((a) => a.key).map((b) => Binding.get(b.remote).value(data));
301
- }
302
-
303
- getLocalKey(data) {
304
- return this.props.bindings.filter((a) => a.key).map((b) => Binding.get(b.local).value(data));
305
- }
306
-
307
- findOption(options, key) {
308
- if (!key) return -1;
309
- for (let i = 0; i < options.length; i++) {
310
- let optionKey = this.getOptionKey({ $option: options[i] });
311
- if (areKeysEqual(key, optionKey)) return i;
312
- }
313
- return -1;
314
- }
315
-
316
- getDropdown() {
317
- if (this.dropdown) return this.dropdown;
318
-
319
- let { widget, lastDropdown } = this.props.instance;
320
-
321
- this.list = Widget.create(
322
- <cx>
323
- <List
324
- sortField={widget.sort && widget.optionTextField}
325
- sortDirection="ASC"
326
- mod="dropdown"
327
- scrollSelectionIntoView
328
- cached={widget.infinite}
329
- {...widget.listOptions}
330
- records-bind="$options"
331
- recordName="$option"
332
- onItemClick={(e, inst) => this.onItemClick(e, inst)}
333
- pipeKeyDown={(kd) => {
334
- this.listKeyDown = kd;
335
- }}
336
- selectOnTab
337
- focusable={false}
338
- selection={{
339
- type: SelectionDelegate,
340
- delegate: (data) =>
341
- this.props.instance.data.selectedKeys.find((x) =>
342
- areKeysEqual(x, this.getOptionKey({ $option: data }))
343
- ) != null,
344
- }}
345
- >
346
- {this.props.itemConfig}
347
- </List>
348
- </cx>
349
- );
350
-
351
- let dropdown = {
352
- constrain: true,
353
- scrollTracking: true,
354
- inline: !isTouchDevice() || !!lastDropdown,
355
- placementOrder: "down-right down-left up-right up-left",
356
- ...widget.dropdownOptions,
357
- type: Dropdown,
358
- relatedElement: this.dom.input,
359
- renderChildren: () => this.renderDropdownContents(),
360
- onFocusOut: (e) => this.closeDropdown(e),
361
- memoize: false,
362
- touchFriendly: isTouchDevice(),
363
- onMeasureNaturalContentSize: () => {
364
- if (this.dom.dropdown && this.dom.list) {
365
- return {
366
- height:
367
- this.dom.dropdown.offsetHeight -
368
- this.dom.list.offsetHeight +
369
- (this.dom.list.firstElementChild?.offsetHeight || 0),
370
- };
371
- }
372
- },
373
- onDismissAfterScroll: () => {
374
- this.closeDropdown(null, true);
375
- return false;
376
- },
377
- };
378
-
379
- return (this.dropdown = Widget.create(dropdown));
380
- }
381
-
382
- renderDropdownContents() {
383
- let content;
384
- let { instance } = this.props;
385
- let { data, widget } = instance;
386
- let { CSS, baseClass } = widget;
387
-
388
- let searchVisible =
389
- !widget.hideSearchField &&
390
- (!isArray(data.options) ||
391
- (widget.minOptionsForSearchField && data.options.length >= widget.minOptionsForSearchField));
392
-
393
- if (this.state.status == "loading") {
394
- content = (
395
- <div key="msg" className={CSS.element(baseClass, "message", "loading")}>
396
- {widget.loadingText}
397
- </div>
398
- );
399
- } else if (this.state.status == "error") {
400
- content = (
401
- <div key="msg" className={CSS.element(baseClass, "message", "error")}>
402
- {widget.queryErrorText}
403
- </div>
404
- );
405
- } else if (this.state.status == "info") {
406
- content = (
407
- <div key="msg" className={CSS.element(baseClass, "message", "info")}>
408
- {this.state.message}
409
- </div>
410
- );
411
- } else if (this.state.options.length == 0) {
412
- content = (
413
- <div key="msg" className={CSS.element(baseClass, "message", "no-results")}>
414
- {widget.noResultsText}
415
- </div>
416
- );
417
- } else {
418
- content = (
419
- <div
420
- key="msg"
421
- ref={(el) => {
422
- this.dom.list = el;
423
- this.subscribeListOnWheel(el);
424
- this.subscribeListOnScroll(el);
425
- }}
426
- className={CSS.element(baseClass, "scroll-container")}
427
- >
428
- <Cx widget={this.list} store={this.itemStore} options={{ name: "lookupfield-list" }} />
429
- </div>
430
- );
431
- }
432
-
433
- return (
434
- <div
435
- key="dropdown"
436
- ref={(el) => {
437
- this.dom.dropdown = el;
438
- }}
439
- className={CSS.element(baseClass, "dropdown")}
440
- tabIndex={0}
441
- onFocus={(e) => this.onDropdownFocus(e)}
442
- onKeyDown={(e) => this.onDropdownKeyPress(e)}
443
- >
444
- {searchVisible && (
445
- <input
446
- key="query"
447
- ref={(el) => {
448
- this.dom.query = el;
449
- }}
450
- type="text"
451
- className={CSS.element(baseClass, "query")}
452
- onClick={(e) => {
453
- e.preventDefault();
454
- e.stopPropagation();
455
- }}
456
- onChange={(e) => this.query(e.target.value)}
457
- onBlur={(e) => this.onQueryBlur(e)}
458
- />
459
- )}
460
- {content}
461
- </div>
462
- );
463
- }
464
-
465
- onListWheel(e) {
466
- let { list } = this.dom;
467
- if (
468
- (list.scrollTop + list.offsetHeight == list.scrollHeight && e.deltaY > 0) ||
469
- (list.scrollTop == 0 && e.deltaY < 0)
470
- ) {
471
- e.preventDefault();
472
- e.stopPropagation();
473
- }
474
- }
475
-
476
- onListScroll() {
477
- if (!this.dom.list) return;
478
- var el = this.dom.list;
479
- if (el.scrollTop > el.scrollHeight - 2 * el.offsetHeight) {
480
- this.loadAdditionalOptionPages();
481
- }
482
- }
483
-
484
- onDropdownFocus(e) {
485
- if (this.dom.query && !isFocused(this.dom.query) && !isTouchDevice()) FocusManager.focus(this.dom.query);
486
- }
487
-
488
- getPlaceholder(text) {
489
- let { CSS, baseClass } = this.props.instance.widget;
490
-
491
- if (text) return <span className={CSS.element(baseClass, "placeholder")}>{text}</span>;
492
-
493
- return <span className={CSS.element(baseClass, "placeholder")}>&nbsp;</span>;
494
- }
495
-
496
- render() {
497
- let { instance, label, help } = this.props;
498
- let { data, widget, state } = instance;
499
- let { CSS, baseClass, suppressErrorsUntilVisited } = widget;
500
-
501
- let icon = data.icon && (
502
- <div
503
- key="icon"
504
- className={CSS.element(baseClass, "left-icon")}
505
- onMouseDown={preventDefault}
506
- onClick={(e) => {
507
- this.openDropdown(e);
508
- e.stopPropagation();
509
- e.preventDefault();
510
- }}
511
- >
512
- {Icon.render(data.icon, {
513
- className: CSS.element(baseClass, "icon"),
514
- })}
515
- </div>
516
- );
517
-
518
- let dropdown;
519
- if (this.state.dropdownOpen) {
520
- this.itemStore.setData({
521
- $options: this.state.options,
522
- $query: this.lastQuery,
523
- });
524
- dropdown = (
525
- <Cx widget={this.getDropdown()} store={this.itemStore} options={{ name: "lookupfield-dropdown" }} />
526
- );
527
- }
528
-
529
- let insideButton = null;
530
- let multipleEntries = this.props.multiple && isArray(data.records) && data.records.length > 1;
531
-
532
- if (!data.readOnly) {
533
- if (
534
- widget.showClear &&
535
- !data.disabled &&
536
- !data.empty &&
537
- (widget.alwaysShowClear || (!data.required && !this.props.multiple) || multipleEntries)
538
- ) {
539
- insideButton = (
540
- <div
541
- key="ib"
542
- onMouseDown={preventDefault}
543
- onClick={(e) => (!this.props.multiple ? this.onClearClick(e) : this.onClearMultipleClick(e))}
544
- className={CSS.element(baseClass, "clear")}
545
- >
546
- <ClearIcon className={CSS.element(baseClass, "icon")} />
547
- </div>
548
- );
549
- } else {
550
- insideButton = (
551
- <div
552
- key="ib"
553
- className={CSS.element(baseClass, "tool")}
554
- onMouseDown={preventDefault}
555
- onClick={(e) => {
556
- this.toggleDropdown(e, true);
557
- e.stopPropagation();
558
- e.preventDefault();
559
- }}
560
- >
561
- <DropdownIcon className={CSS.element(baseClass, "icon")} />
562
- </div>
563
- );
564
- }
565
- }
566
-
567
- let text;
568
-
569
- if (this.props.multiple) {
570
- let readOnly = data.disabled || data.readOnly;
571
- if (isNonEmptyArray(data.records)) {
572
- text = data.records.map((v, i) => (
573
- <div
574
- key={i}
575
- className={CSS.element(baseClass, "tag", {
576
- readonly: readOnly,
577
- })}
578
- >
579
- <span className={CSS.element(baseClass, "tag-value")}>{v[widget.valueTextField]}</span>
580
- {!readOnly && (
581
- <div
582
- className={CSS.element(baseClass, "tag-clear")}
583
- onMouseDown={(e) => {
584
- e.preventDefault();
585
- e.stopPropagation();
586
- }}
587
- onClick={(e) => this.onClearClick(e, v)}
588
- >
589
- <ClearIcon className={CSS.element(baseClass, "icon")} />
590
- </div>
591
- )}
592
- </div>
593
- ));
594
- } else {
595
- text = this.getPlaceholder(data.placeholder);
596
- }
597
- } else {
598
- text = !data.empty ? data.text || this.getPlaceholder() : this.getPlaceholder(data.placeholder);
599
- }
600
-
601
- let states = {
602
- visited: state.visited,
603
- focus: this.state.focus || this.state.dropdownOpen,
604
- icon: !!data.icon,
605
- empty: !data.placeholder && data.empty,
606
- error: data.error && (state.visited || !suppressErrorsUntilVisited || !data.empty),
607
- };
608
-
609
- return (
610
- <div
611
- className={CSS.expand(data.classNames, CSS.state(states))}
612
- style={data.style}
613
- onMouseDown={stopPropagation}
614
- onTouchStart={stopPropagation}
615
- onKeyDown={(e) => this.onKeyDown(e)}
616
- >
617
- <div
618
- id={data.id}
619
- className={CSS.expand(CSS.element(widget.baseClass, "input"), data.inputClass)}
620
- style={data.inputStyle}
621
- tabIndex={data.disabled ? null : data.tabIndex || 0}
622
- ref={(el) => {
623
- this.dom.input = el;
624
- }}
625
- aria-labelledby={data.id + "-label"}
626
- onMouseMove={(e) => tooltipMouseMove(e, ...getFieldTooltip(this.props.instance))}
627
- onMouseLeave={(e) => tooltipMouseLeave(e, ...getFieldTooltip(this.props.instance))}
628
- onClick={(e) => this.onClick(e)}
629
- onInput={(e) => this.onChange(e, "input")}
630
- onChange={(e) => this.onChange(e, "change")}
631
- onKeyDown={(e) => this.onInputKeyDown(e)}
632
- onMouseDown={(e) => this.onMouseDown(e)}
633
- onBlur={(e) => this.onBlur(e)}
634
- onFocus={(e) => this.onFocus(e)}
635
- >
636
- {text}
637
- </div>
638
- {insideButton}
639
- {icon}
640
- {dropdown}
641
- {label}
642
- {help}
643
- </div>
644
- );
645
- }
646
-
647
- onMouseDown(e) {
648
- //skip touch start to allow touch scrolling
649
- if (isTouchEvent()) return;
650
- e.preventDefault();
651
- e.stopPropagation();
652
- this.toggleDropdown(e, true);
653
- }
654
-
655
- onClick(e) {
656
- //mouse down will handle it for non-touch events
657
- if (!isTouchEvent()) return;
658
- e.preventDefault();
659
- e.stopPropagation();
660
- this.toggleDropdown(e, true);
661
- }
662
-
663
- onItemClick(e, { store }) {
664
- this.select(e, [store.getData()]);
665
- if (!this.props.instance.widget.submitOnEnterKey || e.type != "keydown") e.stopPropagation();
666
- if (e.keyCode != KeyCode.tab) e.preventDefault();
667
- }
668
-
669
- onClearClick(e, value) {
670
- let { instance } = this.props;
671
- let { data, store, widget } = instance;
672
- let { keyBindings } = widget;
673
- e.stopPropagation();
674
- e.preventDefault();
675
- if (widget.multiple) {
676
- if (isArray(data.records)) {
677
- let itemKey = this.getLocalKey({ $value: value });
678
- let newRecords = data.records.filter((v) => !areKeysEqual(this.getLocalKey({ $value: v }), itemKey));
679
-
680
- instance.set("records", newRecords);
681
-
682
- let newValues = newRecords
683
- .map((rec) => this.getLocalKey({ $value: rec }))
684
- .map((k) => (keyBindings.length == 1 ? k[0] : k));
685
-
686
- instance.set("values", newValues);
687
- }
688
- } else {
689
- this.props.bindings.forEach((b) => {
690
- store.set(b.local, widget.emptyValue);
691
- });
692
- }
693
-
694
- if (!isTouchEvent(e)) this.dom.input.focus();
695
- }
696
-
697
- onClearMultipleClick(e) {
698
- let { instance } = this.props;
699
- instance.set("records", []);
700
- instance.set("values", []);
701
- }
702
-
703
- select(e, itemsData, reset) {
704
- let { instance } = this.props;
705
- let { store, data, widget } = instance;
706
- let { bindings, keyBindings } = widget;
707
-
708
- if (widget.multiple) {
709
- let { selectedKeys, records } = data;
710
-
711
- let newRecords = reset ? [] : [...(records || [])];
712
- let singleSelect = itemsData.length == 1;
713
- let optionKey = null;
714
- if (singleSelect) optionKey = this.getOptionKey(itemsData[0]);
715
-
716
- // deselect
717
- if (singleSelect && selectedKeys.find((k) => areKeysEqual(optionKey, k))) {
718
- newRecords = records.filter((v) => !areKeysEqual(optionKey, this.getLocalKey({ $value: v })));
719
- } else {
720
- itemsData.forEach((itemData) => {
721
- let valueData = {
722
- $value: {},
723
- };
724
- bindings.forEach((b) => {
725
- valueData = Binding.get(b.local).set(valueData, Binding.get(b.remote).value(itemData));
726
- });
727
- newRecords.push(valueData.$value);
728
- });
729
- }
730
-
731
- instance.set("records", newRecords);
732
-
733
- let newValues = newRecords
734
- .map((rec) => this.getLocalKey({ $value: rec }))
735
- .map((k) => (keyBindings.length == 1 ? k[0] : k));
736
-
737
- instance.set("values", newValues);
738
- } else {
739
- bindings.forEach((b) => {
740
- let v = Binding.get(b.remote).value(itemsData[0]);
741
- if (b.set) b.set(v, instance);
742
- else store.set(b.local, v);
743
- });
744
- }
745
-
746
- if (widget.closeOnSelect) {
747
- //Pressing Tab should work it's own thing. Focus will move elsewhere and the dropdown will close.
748
- if (e.keyCode != KeyCode.tab) {
749
- if (!isTouchEvent(e)) this.dom.input.focus();
750
- this.closeDropdown(e);
751
- }
752
- }
753
-
754
- if (e.keyCode == KeyCode.enter && widget.submitOnDropdownEnterKey) {
755
- this.submitOnEnter(e);
756
- }
757
- }
758
-
759
- onDropdownKeyPress(e) {
760
- switch (e.keyCode) {
761
- case KeyCode.esc:
762
- this.closeDropdown(e);
763
- this.dom.input.focus();
764
- break;
765
-
766
- case KeyCode.tab:
767
- // if tab needs to do a list selection, we have to first call List's handleKeyDown
768
- if (this.listKeyDown) this.listKeyDown(e);
769
- // if next focusable element is disabled, recalculate and update the dom before switching focus
770
- this.props.forceUpdate();
771
- break;
772
-
773
- case KeyCode.a:
774
- if (!e.ctrlKey) return;
775
-
776
- let { quickSelectAll, multiple } = this.props.instance.widget;
777
- if (!quickSelectAll || !multiple) return;
778
-
779
- let optionsToSelect = this.state.options.map((o) => ({
780
- $option: o,
781
- }));
782
- this.select(e, optionsToSelect, true);
783
- e.stopPropagation();
784
- e.preventDefault();
785
- break;
786
-
787
- default:
788
- if (this.listKeyDown) this.listKeyDown(e);
789
- break;
790
- }
791
- }
792
-
793
- onKeyDown(e) {
794
- switch (e.keyCode) {
795
- case KeyCode.pageDown:
796
- case KeyCode.pageUp:
797
- if (this.state.dropdownOpen) e.preventDefault();
798
- break;
799
- }
800
- }
801
-
802
- onInputKeyDown(e) {
803
- let { instance } = this.props;
804
- if (instance.widget.handleKeyDown(e, instance) === false) return;
805
-
806
- switch (e.keyCode) {
807
- case KeyCode.delete:
808
- this.onClearClick(e);
809
- return;
810
-
811
- case KeyCode.shift:
812
- case KeyCode.ctrl:
813
- case KeyCode.tab:
814
- case KeyCode.left:
815
- case KeyCode.right:
816
- case KeyCode.pageUp:
817
- case KeyCode.pageDown:
818
- case KeyCode.insert:
819
- case KeyCode.esc:
820
- break;
821
-
822
- case KeyCode.down:
823
- this.openDropdown(e);
824
- e.stopPropagation();
825
- break;
826
-
827
- case KeyCode.enter:
828
- if (this.props.instance.widget.submitOnEnterKey) {
829
- this.submitOnEnter(e);
830
- } else {
831
- this.openDropdown(e);
832
- }
833
- break;
834
-
835
- default:
836
- this.openDropdown(e);
837
- break;
838
- }
839
- }
840
-
841
- onQueryBlur(e) {
842
- FocusManager.nudge();
843
- }
844
-
845
- onFocus(e) {
846
- let { instance } = this.props;
847
- let { widget } = instance;
848
- if (widget.trackFocus) {
849
- this.setState({
850
- focus: true,
851
- });
852
- }
853
-
854
- if (this.props.instance.data.autoOpen) this.openDropdown(null);
855
- }
856
-
857
- onBlur(e) {
858
- if (!this.state.dropdownOpen) this.props.instance.setState({ visited: true });
859
-
860
- if (this.state.focus)
861
- this.setState({
862
- focus: false,
863
- });
864
- }
865
-
866
- toggleDropdown(e, keepFocus) {
867
- if (this.state.dropdownOpen) this.closeDropdown(e, keepFocus);
868
- else this.openDropdown(e);
869
- }
870
-
871
- closeDropdown(e, keepFocus) {
872
- if (this.state.dropdownOpen) {
873
- this.setState(
874
- {
875
- dropdownOpen: false,
876
- },
877
- () => keepFocus && this.dom.input.focus()
878
- );
879
-
880
- this.props.instance.setState({
881
- visited: true,
882
- });
883
- }
884
-
885
- //delete results valid only while the dropdown is open
886
- delete this.tmpCachedResult;
887
- }
888
-
889
- openDropdown(e) {
890
- let { instance } = this.props;
891
- let { data } = instance;
892
- if (!this.state.dropdownOpen && !data.disabled && !data.readOnly) {
893
- this.query("");
894
- this.setState(
895
- {
896
- dropdownOpen: true,
897
- },
898
- () => {
899
- if (this.dom.dropdown) this.dom.dropdown.focus();
900
- }
901
- );
902
- }
903
- }
904
-
905
- query(q) {
906
- /*
907
- In fetchAll mode onQuery should fetch all data and after
908
- that everything is done filtering is done client-side.
909
- If cacheAll is set results are cached for the lifetime of the
910
- widget, otherwise cache is invalidated when dropdown closes.
911
- */
912
-
913
- let { instance } = this.props;
914
- let { widget, data } = instance;
915
-
916
- this.lastQuery = q;
917
-
918
- //do not make duplicate queries if fetchAll is enabled
919
- if (widget.fetchAll && this.state.status == "loading") return;
920
-
921
- if (this.queryTimeoutId) clearTimeout(this.queryTimeoutId);
922
-
923
- if (q.length < widget.minQueryLength) {
924
- this.setState({
925
- status: "info",
926
- message: StringTemplate.format(widget.minQueryLengthMessageText, widget.minQueryLength),
927
- });
928
- return;
929
- }
930
-
931
- if (isArray(data.options)) {
932
- let results = widget.filterOptions(this.props.instance, data.options, q);
933
- this.setState({
934
- options: results,
935
- status: "loaded",
936
- });
937
- }
938
-
939
- if (widget.onQuery) {
940
- let { queryDelay, fetchAll, cacheAll, pageSize } = widget;
941
-
942
- if (fetchAll) queryDelay = 0;
943
-
944
- if (!this.cachedResult) {
945
- this.setState({
946
- status: "loading",
947
- });
948
- }
949
-
950
- this.queryTimeoutId = setTimeout(() => {
951
- delete this.queryTimeoutId;
952
-
953
- let result = this.tmpCachedResult || this.cachedResult;
954
- let query = fetchAll ? "" : q;
955
- let params = !widget.infinite
956
- ? query
957
- : {
958
- query,
959
- page: 1,
960
- pageSize,
961
- };
962
-
963
- if (!result) result = instance.invoke("onQuery", params, instance);
964
-
965
- let queryId = (this.lastQueryId = Date.now());
966
-
967
- Promise.resolve(result)
968
- .then((results) => {
969
- //discard results which do not belong to the last query
970
- if (queryId !== this.lastQueryId) return;
971
-
972
- if (!isArray(results)) results = [];
973
-
974
- if (fetchAll) {
975
- if (cacheAll) this.cachedResult = results;
976
- else this.tmpCachedResult = results;
977
-
978
- results = widget.filterOptions(this.props.instance, results, this.lastQuery);
979
- }
980
-
981
- this.setState(
982
- {
983
- page: 1,
984
- query,
985
- options: results,
986
- status: "loaded",
987
- },
988
- () => {
989
- if (widget.infinite) this.onListScroll();
990
- }
991
- );
992
- })
993
- .catch((err) => {
994
- this.setState({ status: "error" });
995
- debug("Lookup query error:", err);
996
- });
997
- }, queryDelay);
998
- }
999
- }
1000
-
1001
- loadAdditionalOptionPages() {
1002
- let { instance } = this.props;
1003
- let { widget } = instance;
1004
- if (!widget.infinite) return;
1005
-
1006
- let { query, page, status, options } = this.state;
1007
-
1008
- let blockerKey = query;
1009
-
1010
- if (status != "loaded") return;
1011
-
1012
- if (options.length < page * widget.pageSize) return; //some pages were not full which means we reached the end
1013
-
1014
- if (this.extraPageLoadingBlocker === blockerKey) return;
1015
-
1016
- this.extraPageLoadingBlocker = blockerKey;
1017
-
1018
- let params = {
1019
- page: page + 1,
1020
- query,
1021
- pageSize: widget.pageSize,
1022
- };
1023
-
1024
- var result = instance.invoke("onQuery", params, instance);
1025
-
1026
- Promise.resolve(result)
1027
- .then((results) => {
1028
- //discard results which do not belong to the last query
1029
- if (this.extraPageLoadingBlocker !== blockerKey) return;
1030
-
1031
- this.extraPageLoadingBlocker = false;
1032
-
1033
- if (!isArray(results)) return;
1034
-
1035
- this.setState(
1036
- {
1037
- page: params.page,
1038
- query,
1039
- options: [...options, ...results],
1040
- },
1041
- () => {
1042
- this.onListScroll();
1043
- }
1044
- );
1045
- })
1046
- .catch((err) => {
1047
- if (this.extraPageLoadingBlocker !== blockerKey) return;
1048
- this.extraPageLoadingBlocker = false;
1049
- this.setState({ status: "error" });
1050
- debug("Lookup query error:", err);
1051
- console.error(err);
1052
- });
1053
- }
1054
-
1055
- UNSAFE_componentWillReceiveProps(props) {
1056
- tooltipParentWillReceiveProps(this.dom.input, ...getFieldTooltip(props.instance));
1057
- }
1058
-
1059
- componentDidMount() {
1060
- tooltipParentDidMount(this.dom.input, ...getFieldTooltip(this.props.instance));
1061
- autoFocus(this.dom.input, this);
1062
- }
1063
-
1064
- componentDidUpdate() {
1065
- autoFocus(this.dom.input, this);
1066
- }
1067
-
1068
- componentWillUnmount() {
1069
- if (this.queryTimeoutId) clearTimeout(this.queryTimeoutId);
1070
- tooltipParentWillUnmount(this.props.instance);
1071
- this.subscribeListOnWheel(null);
1072
- }
1073
-
1074
- subscribeListOnWheel(list) {
1075
- if (this.unsubscribeListOnWheel) {
1076
- this.unsubscribeListOnWheel();
1077
- this.unsubscribeListOnWheel = null;
1078
- }
1079
- if (list) {
1080
- this.unsubscribeListOnWheel = addEventListenerWithOptions(list, "wheel", (e) => this.onListWheel(e), {
1081
- passive: false,
1082
- });
1083
- }
1084
- }
1085
-
1086
- subscribeListOnScroll(list) {
1087
- if (this.unsubscribeListOnScroll) {
1088
- this.unsubscribeListOnScroll();
1089
- this.unsubscribeListOnScroll = null;
1090
- }
1091
- if (list) {
1092
- this.unsubscribeListOnScroll = addEventListenerWithOptions(list, "scroll", (e) => this.onListScroll(e), {
1093
- passive: false,
1094
- });
1095
- }
1096
- }
1097
-
1098
- submitOnEnter(e) {
1099
- let instance = this.props.instance.parent;
1100
- while (instance) {
1101
- if (instance.events && instance.events.onSubmit) {
1102
- instance.events.onSubmit(e, instance);
1103
- break;
1104
- } else {
1105
- instance = instance.parent;
1106
- }
1107
- }
1108
- }
1109
- }
1
+ import { Widget, VDOM, getContent } from "../../ui/Widget";
2
+ import { Cx } from "../../ui/Cx";
3
+ import { Field, getFieldTooltip } from "./Field";
4
+ import { ReadOnlyDataView } from "../../data/ReadOnlyDataView";
5
+ import { HtmlElement } from "../HtmlElement";
6
+ import { Binding } from "../../data/Binding";
7
+ import { debug } from "../../util/Debug";
8
+ import { Dropdown } from "../overlay/Dropdown";
9
+ import { FocusManager } from "../../ui/FocusManager";
10
+ import { isFocused } from "../../util/DOM";
11
+ import { isTouchDevice } from "../../util/isTouchDevice";
12
+ import { isTouchEvent } from "../../util/isTouchEvent";
13
+ import {
14
+ tooltipParentWillReceiveProps,
15
+ tooltipParentWillUnmount,
16
+ tooltipMouseMove,
17
+ tooltipMouseLeave,
18
+ tooltipParentDidMount,
19
+ } from "../overlay/tooltip-ops";
20
+ import { stopPropagation, preventDefault } from "../../util/eventCallbacks";
21
+ import ClearIcon from "../icons/clear";
22
+ import DropdownIcon from "../icons/drop-down";
23
+ import { getSearchQueryPredicate } from "../../util/getSearchQueryPredicate";
24
+ import { KeyCode } from "../../util/KeyCode";
25
+ import { Localization } from "../../ui/Localization";
26
+ import { StringTemplate } from "../../data/StringTemplate";
27
+ import { Icon } from "../Icon";
28
+ import { isString } from "../../util/isString";
29
+ import { isDefined } from "../../util/isDefined";
30
+ import { isArray } from "../../util/isArray";
31
+ import { isNonEmptyArray } from "../../util/isNonEmptyArray";
32
+ import { addEventListenerWithOptions } from "../../util/addEventListenerWithOptions";
33
+ import { List } from "../List";
34
+ import { Selection } from "../../ui/selection/Selection";
35
+ import { HighlightedSearchText } from "../HighlightedSearchText";
36
+ import { autoFocus } from "../autoFocus";
37
+
38
+ export class LookupField extends Field {
39
+ declareData() {
40
+ let additionalAttributes = this.multiple
41
+ ? { values: undefined, records: undefined }
42
+ : { value: undefined, text: undefined };
43
+
44
+ super.declareData(
45
+ {
46
+ disabled: undefined,
47
+ enabled: undefined,
48
+ placeholder: undefined,
49
+ required: undefined,
50
+ options: undefined,
51
+ icon: undefined,
52
+ autoOpen: undefined,
53
+ readOnly: undefined,
54
+ },
55
+ additionalAttributes,
56
+ ...arguments
57
+ );
58
+ }
59
+
60
+ init() {
61
+ if (isDefined(this.hideClear)) this.showClear = !this.hideClear;
62
+
63
+ if (this.alwaysShowClear) this.showClear = true;
64
+
65
+ if (!this.bindings) {
66
+ let b = [];
67
+ if (this.value && this.value.bind)
68
+ b.push({
69
+ key: true,
70
+ local: this.value.bind,
71
+ remote: `$option.${this.optionIdField}`,
72
+ set: this.value.set,
73
+ });
74
+
75
+ if (this.text && this.text.bind)
76
+ b.push({
77
+ local: this.text.bind,
78
+ remote: `$option.${this.optionTextField}`,
79
+ set: this.text.set,
80
+ });
81
+ this.bindings = b;
82
+ }
83
+
84
+ if (this.bindings.length == 0 && this.multiple)
85
+ this.bindings = [
86
+ {
87
+ key: true,
88
+ local: `$value.${this.valueIdField}`,
89
+ remote: `$option.${this.optionIdField}`,
90
+ },
91
+ {
92
+ local: `$value.${this.valueTextField}`,
93
+ remote: `$option.${this.optionTextField}`,
94
+ },
95
+ ];
96
+
97
+ this.keyBindings = this.bindings.filter((b) => b.key);
98
+
99
+ if (!this.items && !this.children)
100
+ this.items = {
101
+ $type: HighlightedSearchText,
102
+ text: { bind: `$option.${this.optionTextField}` },
103
+ query: { bind: "$query" },
104
+ };
105
+
106
+ this.itemConfig = this.children || this.items;
107
+
108
+ delete this.items;
109
+ delete this.children;
110
+
111
+ super.init();
112
+ }
113
+
114
+ prepareData(context, instance) {
115
+ let { data, store } = instance;
116
+
117
+ data.stateMods = {
118
+ multiple: this.multiple,
119
+ disabled: data.disabled,
120
+ readonly: data.readOnly,
121
+ };
122
+
123
+ data.selectedKeys = [];
124
+
125
+ if (this.multiple) {
126
+ if (isArray(data.values) && isArray(data.options)) {
127
+ data.selectedKeys = data.values.map((v) => (this.keyBindings.length == 1 ? [v] : v));
128
+ let map = {};
129
+ data.options.filter(($option) => {
130
+ let optionKey = getOptionKey(this.keyBindings, { $option });
131
+ for (let i = 0; i < data.selectedKeys.length; i++)
132
+ if (areKeysEqual(optionKey, data.selectedKeys[i])) {
133
+ map[i] = convertOption(this.bindings, { $option });
134
+ break;
135
+ }
136
+ });
137
+ data.records = [];
138
+ for (let i = 0; i < data.selectedKeys.length; i++) if (map[i]) data.records.push(map[i]);
139
+ } else if (isArray(data.records))
140
+ data.selectedKeys.push(
141
+ ...data.records.map(($value) => this.keyBindings.map((b) => Binding.get(b.local).value({ $value })))
142
+ );
143
+ } else {
144
+ let dataViewData = store.getData();
145
+ data.selectedKeys.push(this.keyBindings.map((b) => Binding.get(b.local).value(dataViewData)));
146
+ if (!this.text && isArray(data.options)) {
147
+ let option = data.options.find(($option) =>
148
+ areKeysEqual(getOptionKey(this.keyBindings, { $option }), data.selectedKeys[0])
149
+ );
150
+ data.text = (option && option[this.optionTextField]) || "";
151
+ }
152
+ }
153
+
154
+ instance.lastDropdown = context.lastDropdown;
155
+
156
+ super.prepareData(context, instance);
157
+ }
158
+
159
+ renderInput(context, instance, key) {
160
+ return (
161
+ <LookupComponent
162
+ key={key}
163
+ multiple={this.multiple}
164
+ instance={instance}
165
+ itemConfig={this.itemConfig}
166
+ bindings={this.bindings}
167
+ baseClass={this.baseClass}
168
+ label={this.labelPlacement && getContent(this.renderLabel(context, instance, "label"))}
169
+ help={this.helpPlacement && getContent(this.renderHelp(context, instance, "help"))}
170
+ forceUpdate={context.forceUpdate}
171
+ />
172
+ );
173
+ }
174
+
175
+ filterOptions(instance, options, query) {
176
+ if (!query) return options;
177
+ let textPredicate = getSearchQueryPredicate(query);
178
+ return options.filter((o) => isString(o[this.optionTextField]) && textPredicate(o[this.optionTextField]));
179
+ }
180
+
181
+ isEmpty(data) {
182
+ if (this.multiple) return !isNonEmptyArray(data.values) && !isNonEmptyArray(data.records);
183
+ return super.isEmpty(data);
184
+ }
185
+
186
+ formatValue(context, instance) {
187
+ if (!this.multiple) return super.formatValue(context, instance);
188
+
189
+ let { records, values, options } = instance.data;
190
+ if (isArray(records))
191
+ return records.map((record) => record[this.valueTextField] || record[this.valueIdField]).join(", ");
192
+
193
+ if (isArray(values)) {
194
+ if (isArray(options))
195
+ return values
196
+ .map((id) => {
197
+ let option = options.find((o) => o[this.optionIdField] == id);
198
+ return option ? option[this.valueTextField] : id;
199
+ })
200
+ .filter(Boolean)
201
+ .join(", ");
202
+
203
+ return values.join(", ");
204
+ }
205
+
206
+ return null;
207
+ }
208
+ }
209
+
210
+ LookupField.prototype.baseClass = "lookupfield";
211
+ //LookupField.prototype.memoize = false;
212
+ LookupField.prototype.multiple = false;
213
+ LookupField.prototype.queryDelay = 150;
214
+ LookupField.prototype.minQueryLength = 0;
215
+ LookupField.prototype.hideSearchField = false;
216
+ LookupField.prototype.minOptionsForSearchField = 7;
217
+ LookupField.prototype.loadingText = "Loading...";
218
+ LookupField.prototype.queryErrorText = "Error occurred while querying for lookup data.";
219
+ LookupField.prototype.noResultsText = "No results found.";
220
+ LookupField.prototype.optionIdField = "id";
221
+ LookupField.prototype.optionTextField = "text";
222
+ LookupField.prototype.valueIdField = "id";
223
+ LookupField.prototype.valueTextField = "text";
224
+ LookupField.prototype.suppressErrorsUntilVisited = true;
225
+ LookupField.prototype.fetchAll = false;
226
+ LookupField.prototype.cacheAll = false;
227
+ LookupField.prototype.showClear = true;
228
+ LookupField.prototype.alwaysShowClear = false;
229
+ LookupField.prototype.closeOnSelect = true;
230
+ LookupField.prototype.minQueryLengthMessageText = "Type in at least {0} character(s).";
231
+ LookupField.prototype.icon = null;
232
+ LookupField.prototype.sort = false;
233
+ LookupField.prototype.listOptions = null;
234
+ LookupField.prototype.autoOpen = false;
235
+ LookupField.prototype.submitOnEnterKey = false;
236
+ LookupField.prototype.submitOnDropdownEnterKey = false;
237
+ LookupField.prototype.pageSize = 100;
238
+ LookupField.prototype.infinite = false;
239
+ LookupField.prototype.quickSelectAll = false;
240
+
241
+ Localization.registerPrototype("cx/widgets/LookupField", LookupField);
242
+
243
+ Widget.alias("lookupfield", LookupField);
244
+
245
+ function getOptionKey(bindings, data) {
246
+ return bindings.filter((a) => a.key).map((b) => Binding.get(b.remote).value(data));
247
+ }
248
+
249
+ function areKeysEqual(key1, key2) {
250
+ if (!key1 || !key2 || key1.length != key2.length) return false;
251
+
252
+ for (let i = 0; i < key1.length; i++) if (key1[i] != key2[i]) return false;
253
+
254
+ return true;
255
+ }
256
+
257
+ function convertOption(bindings, data) {
258
+ let result = { $value: {} };
259
+ bindings.forEach((b) => {
260
+ let value = Binding.get(b.remote).value(data);
261
+ result = Binding.get(b.local).set(result, value);
262
+ });
263
+ return result.$value;
264
+ }
265
+
266
+ class SelectionDelegate extends Selection {
267
+ constructor({ delegate }) {
268
+ super();
269
+ this.delegate = delegate;
270
+ }
271
+
272
+ getIsSelectedDelegate(store) {
273
+ return (record, index) => this.delegate(record, index);
274
+ }
275
+
276
+ select() {
277
+ return false;
278
+ }
279
+ }
280
+
281
+ class LookupComponent extends VDOM.Component {
282
+ constructor(props) {
283
+ super(props);
284
+ let { data, store } = this.props.instance;
285
+ this.dom = {};
286
+ this.state = {
287
+ options: [],
288
+ formatted: data.formatted,
289
+ value: data.formatted,
290
+ dropdownOpen: false,
291
+ focus: false,
292
+ };
293
+
294
+ this.itemStore = new ReadOnlyDataView({
295
+ store: store,
296
+ });
297
+ }
298
+
299
+ getOptionKey(data) {
300
+ return this.props.bindings.filter((a) => a.key).map((b) => Binding.get(b.remote).value(data));
301
+ }
302
+
303
+ getLocalKey(data) {
304
+ return this.props.bindings.filter((a) => a.key).map((b) => Binding.get(b.local).value(data));
305
+ }
306
+
307
+ findOption(options, key) {
308
+ if (!key) return -1;
309
+ for (let i = 0; i < options.length; i++) {
310
+ let optionKey = this.getOptionKey({ $option: options[i] });
311
+ if (areKeysEqual(key, optionKey)) return i;
312
+ }
313
+ return -1;
314
+ }
315
+
316
+ getDropdown() {
317
+ if (this.dropdown) return this.dropdown;
318
+
319
+ let { widget, lastDropdown } = this.props.instance;
320
+
321
+ this.list = Widget.create(
322
+ <cx>
323
+ <List
324
+ sortField={widget.sort && widget.optionTextField}
325
+ sortDirection="ASC"
326
+ mod="dropdown"
327
+ scrollSelectionIntoView
328
+ cached={widget.infinite}
329
+ {...widget.listOptions}
330
+ records-bind="$options"
331
+ recordName="$option"
332
+ onItemClick={(e, inst) => this.onItemClick(e, inst)}
333
+ pipeKeyDown={(kd) => {
334
+ this.listKeyDown = kd;
335
+ }}
336
+ selectOnTab
337
+ focusable={false}
338
+ selection={{
339
+ type: SelectionDelegate,
340
+ delegate: (data) =>
341
+ this.props.instance.data.selectedKeys.find((x) =>
342
+ areKeysEqual(x, this.getOptionKey({ $option: data }))
343
+ ) != null,
344
+ }}
345
+ >
346
+ {this.props.itemConfig}
347
+ </List>
348
+ </cx>
349
+ );
350
+
351
+ let dropdown = {
352
+ constrain: true,
353
+ scrollTracking: true,
354
+ inline: !isTouchDevice() || !!lastDropdown,
355
+ placementOrder: "down-right down-left up-right up-left",
356
+ ...widget.dropdownOptions,
357
+ type: Dropdown,
358
+ relatedElement: this.dom.input,
359
+ renderChildren: () => this.renderDropdownContents(),
360
+ onFocusOut: (e) => this.closeDropdown(e),
361
+ memoize: false,
362
+ touchFriendly: isTouchDevice(),
363
+ onMeasureNaturalContentSize: () => {
364
+ if (this.dom.dropdown && this.dom.list) {
365
+ return {
366
+ height:
367
+ this.dom.dropdown.offsetHeight -
368
+ this.dom.list.offsetHeight +
369
+ (this.dom.list.firstElementChild?.offsetHeight || 0),
370
+ };
371
+ }
372
+ },
373
+ onDismissAfterScroll: () => {
374
+ this.closeDropdown(null, true);
375
+ return false;
376
+ },
377
+ };
378
+
379
+ return (this.dropdown = Widget.create(dropdown));
380
+ }
381
+
382
+ renderDropdownContents() {
383
+ let content;
384
+ let { instance } = this.props;
385
+ let { data, widget } = instance;
386
+ let { CSS, baseClass } = widget;
387
+
388
+ let searchVisible =
389
+ !widget.hideSearchField &&
390
+ (!isArray(data.options) ||
391
+ (widget.minOptionsForSearchField && data.options.length >= widget.minOptionsForSearchField));
392
+
393
+ if (this.state.status == "loading") {
394
+ content = (
395
+ <div key="msg" className={CSS.element(baseClass, "message", "loading")}>
396
+ {widget.loadingText}
397
+ </div>
398
+ );
399
+ } else if (this.state.status == "error") {
400
+ content = (
401
+ <div key="msg" className={CSS.element(baseClass, "message", "error")}>
402
+ {widget.queryErrorText}
403
+ </div>
404
+ );
405
+ } else if (this.state.status == "info") {
406
+ content = (
407
+ <div key="msg" className={CSS.element(baseClass, "message", "info")}>
408
+ {this.state.message}
409
+ </div>
410
+ );
411
+ } else if (this.state.options.length == 0) {
412
+ content = (
413
+ <div key="msg" className={CSS.element(baseClass, "message", "no-results")}>
414
+ {widget.noResultsText}
415
+ </div>
416
+ );
417
+ } else {
418
+ content = (
419
+ <div
420
+ key="msg"
421
+ ref={(el) => {
422
+ this.dom.list = el;
423
+ this.subscribeListOnWheel(el);
424
+ this.subscribeListOnScroll(el);
425
+ }}
426
+ className={CSS.element(baseClass, "scroll-container")}
427
+ >
428
+ <Cx widget={this.list} store={this.itemStore} options={{ name: "lookupfield-list" }} />
429
+ </div>
430
+ );
431
+ }
432
+
433
+ return (
434
+ <div
435
+ key="dropdown"
436
+ ref={(el) => {
437
+ this.dom.dropdown = el;
438
+ }}
439
+ className={CSS.element(baseClass, "dropdown")}
440
+ tabIndex={0}
441
+ onFocus={(e) => this.onDropdownFocus(e)}
442
+ onKeyDown={(e) => this.onDropdownKeyPress(e)}
443
+ >
444
+ {searchVisible && (
445
+ <input
446
+ key="query"
447
+ ref={(el) => {
448
+ this.dom.query = el;
449
+ }}
450
+ type="text"
451
+ className={CSS.element(baseClass, "query")}
452
+ onClick={(e) => {
453
+ e.preventDefault();
454
+ e.stopPropagation();
455
+ }}
456
+ onChange={(e) => this.query(e.target.value)}
457
+ onBlur={(e) => this.onQueryBlur(e)}
458
+ />
459
+ )}
460
+ {content}
461
+ </div>
462
+ );
463
+ }
464
+
465
+ onListWheel(e) {
466
+ let { list } = this.dom;
467
+ if (
468
+ (list.scrollTop + list.offsetHeight == list.scrollHeight && e.deltaY > 0) ||
469
+ (list.scrollTop == 0 && e.deltaY < 0)
470
+ ) {
471
+ e.preventDefault();
472
+ e.stopPropagation();
473
+ }
474
+ }
475
+
476
+ onListScroll() {
477
+ if (!this.dom.list) return;
478
+ var el = this.dom.list;
479
+ if (el.scrollTop > el.scrollHeight - 2 * el.offsetHeight) {
480
+ this.loadAdditionalOptionPages();
481
+ }
482
+ }
483
+
484
+ onDropdownFocus(e) {
485
+ if (this.dom.query && !isFocused(this.dom.query) && !isTouchDevice()) FocusManager.focus(this.dom.query);
486
+ }
487
+
488
+ getPlaceholder(text) {
489
+ let { CSS, baseClass } = this.props.instance.widget;
490
+
491
+ if (text) return <span className={CSS.element(baseClass, "placeholder")}>{text}</span>;
492
+
493
+ return <span className={CSS.element(baseClass, "placeholder")}>&nbsp;</span>;
494
+ }
495
+
496
+ render() {
497
+ let { instance, label, help } = this.props;
498
+ let { data, widget, state } = instance;
499
+ let { CSS, baseClass, suppressErrorsUntilVisited } = widget;
500
+
501
+ let icon = data.icon && (
502
+ <div
503
+ key="icon"
504
+ className={CSS.element(baseClass, "left-icon")}
505
+ onMouseDown={preventDefault}
506
+ onClick={(e) => {
507
+ this.openDropdown(e);
508
+ e.stopPropagation();
509
+ e.preventDefault();
510
+ }}
511
+ >
512
+ {Icon.render(data.icon, {
513
+ className: CSS.element(baseClass, "icon"),
514
+ })}
515
+ </div>
516
+ );
517
+
518
+ let dropdown;
519
+ if (this.state.dropdownOpen) {
520
+ this.itemStore.setData({
521
+ $options: this.state.options,
522
+ $query: this.lastQuery,
523
+ });
524
+ dropdown = (
525
+ <Cx widget={this.getDropdown()} store={this.itemStore} options={{ name: "lookupfield-dropdown" }} />
526
+ );
527
+ }
528
+
529
+ let insideButton = null;
530
+ let multipleEntries = this.props.multiple && isArray(data.records) && data.records.length > 1;
531
+
532
+ if (!data.readOnly) {
533
+ if (
534
+ widget.showClear &&
535
+ !data.disabled &&
536
+ !data.empty &&
537
+ (widget.alwaysShowClear || (!data.required && !this.props.multiple) || multipleEntries)
538
+ ) {
539
+ insideButton = (
540
+ <div
541
+ key="ib"
542
+ onMouseDown={preventDefault}
543
+ onClick={(e) => (!this.props.multiple ? this.onClearClick(e) : this.onClearMultipleClick(e))}
544
+ className={CSS.element(baseClass, "clear")}
545
+ >
546
+ <ClearIcon className={CSS.element(baseClass, "icon")} />
547
+ </div>
548
+ );
549
+ } else {
550
+ insideButton = (
551
+ <div
552
+ key="ib"
553
+ className={CSS.element(baseClass, "tool")}
554
+ onMouseDown={preventDefault}
555
+ onClick={(e) => {
556
+ this.toggleDropdown(e, true);
557
+ e.stopPropagation();
558
+ e.preventDefault();
559
+ }}
560
+ >
561
+ <DropdownIcon className={CSS.element(baseClass, "icon")} />
562
+ </div>
563
+ );
564
+ }
565
+ }
566
+
567
+ let text;
568
+
569
+ if (this.props.multiple) {
570
+ let readOnly = data.disabled || data.readOnly;
571
+ if (isNonEmptyArray(data.records)) {
572
+ text = data.records.map((v, i) => (
573
+ <div
574
+ key={i}
575
+ className={CSS.element(baseClass, "tag", {
576
+ readonly: readOnly,
577
+ })}
578
+ >
579
+ <span className={CSS.element(baseClass, "tag-value")}>{v[widget.valueTextField]}</span>
580
+ {!readOnly && (
581
+ <div
582
+ className={CSS.element(baseClass, "tag-clear")}
583
+ onMouseDown={(e) => {
584
+ e.preventDefault();
585
+ e.stopPropagation();
586
+ }}
587
+ onClick={(e) => this.onClearClick(e, v)}
588
+ >
589
+ <ClearIcon className={CSS.element(baseClass, "icon")} />
590
+ </div>
591
+ )}
592
+ </div>
593
+ ));
594
+ } else {
595
+ text = this.getPlaceholder(data.placeholder);
596
+ }
597
+ } else {
598
+ text = !data.empty ? data.text || this.getPlaceholder() : this.getPlaceholder(data.placeholder);
599
+ }
600
+
601
+ let states = {
602
+ visited: state.visited,
603
+ focus: this.state.focus || this.state.dropdownOpen,
604
+ icon: !!data.icon,
605
+ empty: !data.placeholder && data.empty,
606
+ error: data.error && (state.visited || !suppressErrorsUntilVisited || !data.empty),
607
+ };
608
+
609
+ return (
610
+ <div
611
+ className={CSS.expand(data.classNames, CSS.state(states))}
612
+ style={data.style}
613
+ onMouseDown={stopPropagation}
614
+ onTouchStart={stopPropagation}
615
+ onKeyDown={(e) => this.onKeyDown(e)}
616
+ >
617
+ <div
618
+ id={data.id}
619
+ className={CSS.expand(CSS.element(widget.baseClass, "input"), data.inputClass)}
620
+ style={data.inputStyle}
621
+ tabIndex={data.disabled ? null : data.tabIndex || 0}
622
+ ref={(el) => {
623
+ this.dom.input = el;
624
+ }}
625
+ aria-labelledby={data.id + "-label"}
626
+ onMouseMove={(e) => tooltipMouseMove(e, ...getFieldTooltip(this.props.instance))}
627
+ onMouseLeave={(e) => tooltipMouseLeave(e, ...getFieldTooltip(this.props.instance))}
628
+ onClick={(e) => this.onClick(e)}
629
+ onInput={(e) => this.onChange(e, "input")}
630
+ onChange={(e) => this.onChange(e, "change")}
631
+ onKeyDown={(e) => this.onInputKeyDown(e)}
632
+ onMouseDown={(e) => this.onMouseDown(e)}
633
+ onBlur={(e) => this.onBlur(e)}
634
+ onFocus={(e) => this.onFocus(e)}
635
+ >
636
+ {text}
637
+ </div>
638
+ {insideButton}
639
+ {icon}
640
+ {dropdown}
641
+ {label}
642
+ {help}
643
+ </div>
644
+ );
645
+ }
646
+
647
+ onMouseDown(e) {
648
+ //skip touch start to allow touch scrolling
649
+ if (isTouchEvent()) return;
650
+ e.preventDefault();
651
+ e.stopPropagation();
652
+ this.toggleDropdown(e, true);
653
+ }
654
+
655
+ onClick(e) {
656
+ //mouse down will handle it for non-touch events
657
+ if (!isTouchEvent()) return;
658
+ e.preventDefault();
659
+ e.stopPropagation();
660
+ this.toggleDropdown(e, true);
661
+ }
662
+
663
+ onItemClick(e, { store }) {
664
+ this.select(e, [store.getData()]);
665
+ if (!this.props.instance.widget.submitOnEnterKey || e.type != "keydown") e.stopPropagation();
666
+ if (e.keyCode != KeyCode.tab) e.preventDefault();
667
+ }
668
+
669
+ onClearClick(e, value) {
670
+ let { instance } = this.props;
671
+ let { data, store, widget } = instance;
672
+ let { keyBindings } = widget;
673
+ e.stopPropagation();
674
+ e.preventDefault();
675
+ if (widget.multiple) {
676
+ if (isArray(data.records)) {
677
+ let itemKey = this.getLocalKey({ $value: value });
678
+ let newRecords = data.records.filter((v) => !areKeysEqual(this.getLocalKey({ $value: v }), itemKey));
679
+
680
+ instance.set("records", newRecords);
681
+
682
+ let newValues = newRecords
683
+ .map((rec) => this.getLocalKey({ $value: rec }))
684
+ .map((k) => (keyBindings.length == 1 ? k[0] : k));
685
+
686
+ instance.set("values", newValues);
687
+ }
688
+ } else {
689
+ this.props.bindings.forEach((b) => {
690
+ store.set(b.local, widget.emptyValue);
691
+ });
692
+ }
693
+
694
+ if (!isTouchEvent(e)) this.dom.input.focus();
695
+ }
696
+
697
+ onClearMultipleClick(e) {
698
+ let { instance } = this.props;
699
+ instance.set("records", []);
700
+ instance.set("values", []);
701
+ }
702
+
703
+ select(e, itemsData, reset) {
704
+ let { instance } = this.props;
705
+ let { store, data, widget } = instance;
706
+ let { bindings, keyBindings } = widget;
707
+
708
+ if (widget.multiple) {
709
+ let { selectedKeys, records } = data;
710
+
711
+ let newRecords = reset ? [] : [...(records || [])];
712
+ let singleSelect = itemsData.length == 1;
713
+ let optionKey = null;
714
+ if (singleSelect) optionKey = this.getOptionKey(itemsData[0]);
715
+
716
+ // deselect
717
+ if (singleSelect && selectedKeys.find((k) => areKeysEqual(optionKey, k))) {
718
+ newRecords = records.filter((v) => !areKeysEqual(optionKey, this.getLocalKey({ $value: v })));
719
+ } else {
720
+ itemsData.forEach((itemData) => {
721
+ let valueData = {
722
+ $value: {},
723
+ };
724
+ bindings.forEach((b) => {
725
+ valueData = Binding.get(b.local).set(valueData, Binding.get(b.remote).value(itemData));
726
+ });
727
+ newRecords.push(valueData.$value);
728
+ });
729
+ }
730
+
731
+ instance.set("records", newRecords);
732
+
733
+ let newValues = newRecords
734
+ .map((rec) => this.getLocalKey({ $value: rec }))
735
+ .map((k) => (keyBindings.length == 1 ? k[0] : k));
736
+
737
+ instance.set("values", newValues);
738
+ } else {
739
+ bindings.forEach((b) => {
740
+ let v = Binding.get(b.remote).value(itemsData[0]);
741
+ if (b.set) b.set(v, instance);
742
+ else store.set(b.local, v);
743
+ });
744
+ }
745
+
746
+ if (widget.closeOnSelect) {
747
+ //Pressing Tab should work it's own thing. Focus will move elsewhere and the dropdown will close.
748
+ if (e.keyCode != KeyCode.tab) {
749
+ if (!isTouchEvent(e)) this.dom.input.focus();
750
+ this.closeDropdown(e);
751
+ }
752
+ }
753
+
754
+ if (e.keyCode == KeyCode.enter && widget.submitOnDropdownEnterKey) {
755
+ this.submitOnEnter(e);
756
+ }
757
+ }
758
+
759
+ onDropdownKeyPress(e) {
760
+ switch (e.keyCode) {
761
+ case KeyCode.esc:
762
+ this.closeDropdown(e);
763
+ this.dom.input.focus();
764
+ break;
765
+
766
+ case KeyCode.tab:
767
+ // if tab needs to do a list selection, we have to first call List's handleKeyDown
768
+ if (this.listKeyDown) this.listKeyDown(e);
769
+ // if next focusable element is disabled, recalculate and update the dom before switching focus
770
+ this.props.forceUpdate();
771
+ break;
772
+
773
+ case KeyCode.a:
774
+ if (!e.ctrlKey) return;
775
+
776
+ let { quickSelectAll, multiple } = this.props.instance.widget;
777
+ if (!quickSelectAll || !multiple) return;
778
+
779
+ let optionsToSelect = this.state.options.map((o) => ({
780
+ $option: o,
781
+ }));
782
+ this.select(e, optionsToSelect, true);
783
+ e.stopPropagation();
784
+ e.preventDefault();
785
+ break;
786
+
787
+ default:
788
+ if (this.listKeyDown) this.listKeyDown(e);
789
+ break;
790
+ }
791
+ }
792
+
793
+ onKeyDown(e) {
794
+ switch (e.keyCode) {
795
+ case KeyCode.pageDown:
796
+ case KeyCode.pageUp:
797
+ if (this.state.dropdownOpen) e.preventDefault();
798
+ break;
799
+ }
800
+ }
801
+
802
+ onInputKeyDown(e) {
803
+ let { instance } = this.props;
804
+ if (instance.widget.handleKeyDown(e, instance) === false) return;
805
+
806
+ switch (e.keyCode) {
807
+ case KeyCode.delete:
808
+ this.onClearClick(e);
809
+ return;
810
+
811
+ case KeyCode.shift:
812
+ case KeyCode.ctrl:
813
+ case KeyCode.tab:
814
+ case KeyCode.left:
815
+ case KeyCode.right:
816
+ case KeyCode.pageUp:
817
+ case KeyCode.pageDown:
818
+ case KeyCode.insert:
819
+ case KeyCode.esc:
820
+ break;
821
+
822
+ case KeyCode.down:
823
+ this.openDropdown(e);
824
+ e.stopPropagation();
825
+ break;
826
+
827
+ case KeyCode.enter:
828
+ if (this.props.instance.widget.submitOnEnterKey) {
829
+ this.submitOnEnter(e);
830
+ } else {
831
+ this.openDropdown(e);
832
+ }
833
+ break;
834
+
835
+ default:
836
+ this.openDropdown(e);
837
+ break;
838
+ }
839
+ }
840
+
841
+ onQueryBlur(e) {
842
+ FocusManager.nudge();
843
+ }
844
+
845
+ onFocus(e) {
846
+ let { instance } = this.props;
847
+ let { widget } = instance;
848
+ if (widget.trackFocus) {
849
+ this.setState({
850
+ focus: true,
851
+ });
852
+ }
853
+
854
+ if (this.props.instance.data.autoOpen) this.openDropdown(null);
855
+ }
856
+
857
+ onBlur(e) {
858
+ if (!this.state.dropdownOpen) this.props.instance.setState({ visited: true });
859
+
860
+ if (this.state.focus)
861
+ this.setState({
862
+ focus: false,
863
+ });
864
+ }
865
+
866
+ toggleDropdown(e, keepFocus) {
867
+ if (this.state.dropdownOpen) this.closeDropdown(e, keepFocus);
868
+ else this.openDropdown(e);
869
+ }
870
+
871
+ closeDropdown(e, keepFocus) {
872
+ if (this.state.dropdownOpen) {
873
+ this.setState(
874
+ {
875
+ dropdownOpen: false,
876
+ },
877
+ () => keepFocus && this.dom.input.focus()
878
+ );
879
+
880
+ this.props.instance.setState({
881
+ visited: true,
882
+ });
883
+ }
884
+
885
+ //delete results valid only while the dropdown is open
886
+ delete this.tmpCachedResult;
887
+ }
888
+
889
+ openDropdown(e) {
890
+ let { instance } = this.props;
891
+ let { data } = instance;
892
+ if (!this.state.dropdownOpen && !data.disabled && !data.readOnly) {
893
+ this.query("");
894
+ this.setState(
895
+ {
896
+ dropdownOpen: true,
897
+ },
898
+ () => {
899
+ if (this.dom.dropdown) this.dom.dropdown.focus();
900
+ }
901
+ );
902
+ }
903
+ }
904
+
905
+ query(q) {
906
+ /*
907
+ In fetchAll mode onQuery should fetch all data and after
908
+ that everything is done filtering is done client-side.
909
+ If cacheAll is set results are cached for the lifetime of the
910
+ widget, otherwise cache is invalidated when dropdown closes.
911
+ */
912
+
913
+ let { instance } = this.props;
914
+ let { widget, data } = instance;
915
+
916
+ this.lastQuery = q;
917
+
918
+ //do not make duplicate queries if fetchAll is enabled
919
+ if (widget.fetchAll && this.state.status == "loading") return;
920
+
921
+ if (this.queryTimeoutId) clearTimeout(this.queryTimeoutId);
922
+
923
+ if (q.length < widget.minQueryLength) {
924
+ this.setState({
925
+ status: "info",
926
+ message: StringTemplate.format(widget.minQueryLengthMessageText, widget.minQueryLength),
927
+ });
928
+ return;
929
+ }
930
+
931
+ if (isArray(data.options)) {
932
+ let results = widget.filterOptions(this.props.instance, data.options, q);
933
+ this.setState({
934
+ options: results,
935
+ status: "loaded",
936
+ });
937
+ }
938
+
939
+ if (widget.onQuery) {
940
+ let { queryDelay, fetchAll, cacheAll, pageSize } = widget;
941
+
942
+ if (fetchAll) queryDelay = 0;
943
+
944
+ if (!this.cachedResult) {
945
+ this.setState({
946
+ status: "loading",
947
+ });
948
+ }
949
+
950
+ this.queryTimeoutId = setTimeout(() => {
951
+ delete this.queryTimeoutId;
952
+
953
+ let result = this.tmpCachedResult || this.cachedResult;
954
+ let query = fetchAll ? "" : q;
955
+ let params = !widget.infinite
956
+ ? query
957
+ : {
958
+ query,
959
+ page: 1,
960
+ pageSize,
961
+ };
962
+
963
+ if (!result) result = instance.invoke("onQuery", params, instance);
964
+
965
+ let queryId = (this.lastQueryId = Date.now());
966
+
967
+ Promise.resolve(result)
968
+ .then((results) => {
969
+ //discard results which do not belong to the last query
970
+ if (queryId !== this.lastQueryId) return;
971
+
972
+ if (!isArray(results)) results = [];
973
+
974
+ if (fetchAll) {
975
+ if (cacheAll) this.cachedResult = results;
976
+ else this.tmpCachedResult = results;
977
+
978
+ results = widget.filterOptions(this.props.instance, results, this.lastQuery);
979
+ }
980
+
981
+ this.setState(
982
+ {
983
+ page: 1,
984
+ query,
985
+ options: results,
986
+ status: "loaded",
987
+ },
988
+ () => {
989
+ if (widget.infinite) this.onListScroll();
990
+ }
991
+ );
992
+ })
993
+ .catch((err) => {
994
+ this.setState({ status: "error" });
995
+ debug("Lookup query error:", err);
996
+ });
997
+ }, queryDelay);
998
+ }
999
+ }
1000
+
1001
+ loadAdditionalOptionPages() {
1002
+ let { instance } = this.props;
1003
+ let { widget } = instance;
1004
+ if (!widget.infinite) return;
1005
+
1006
+ let { query, page, status, options } = this.state;
1007
+
1008
+ let blockerKey = query;
1009
+
1010
+ if (status != "loaded") return;
1011
+
1012
+ if (options.length < page * widget.pageSize) return; //some pages were not full which means we reached the end
1013
+
1014
+ if (this.extraPageLoadingBlocker === blockerKey) return;
1015
+
1016
+ this.extraPageLoadingBlocker = blockerKey;
1017
+
1018
+ let params = {
1019
+ page: page + 1,
1020
+ query,
1021
+ pageSize: widget.pageSize,
1022
+ };
1023
+
1024
+ var result = instance.invoke("onQuery", params, instance);
1025
+
1026
+ Promise.resolve(result)
1027
+ .then((results) => {
1028
+ //discard results which do not belong to the last query
1029
+ if (this.extraPageLoadingBlocker !== blockerKey) return;
1030
+
1031
+ this.extraPageLoadingBlocker = false;
1032
+
1033
+ if (!isArray(results)) return;
1034
+
1035
+ this.setState(
1036
+ {
1037
+ page: params.page,
1038
+ query,
1039
+ options: [...options, ...results],
1040
+ },
1041
+ () => {
1042
+ this.onListScroll();
1043
+ }
1044
+ );
1045
+ })
1046
+ .catch((err) => {
1047
+ if (this.extraPageLoadingBlocker !== blockerKey) return;
1048
+ this.extraPageLoadingBlocker = false;
1049
+ this.setState({ status: "error" });
1050
+ debug("Lookup query error:", err);
1051
+ console.error(err);
1052
+ });
1053
+ }
1054
+
1055
+ UNSAFE_componentWillReceiveProps(props) {
1056
+ tooltipParentWillReceiveProps(this.dom.input, ...getFieldTooltip(props.instance));
1057
+ }
1058
+
1059
+ componentDidMount() {
1060
+ tooltipParentDidMount(this.dom.input, ...getFieldTooltip(this.props.instance));
1061
+ autoFocus(this.dom.input, this);
1062
+ }
1063
+
1064
+ componentDidUpdate() {
1065
+ autoFocus(this.dom.input, this);
1066
+ }
1067
+
1068
+ componentWillUnmount() {
1069
+ if (this.queryTimeoutId) clearTimeout(this.queryTimeoutId);
1070
+ tooltipParentWillUnmount(this.props.instance);
1071
+ this.subscribeListOnWheel(null);
1072
+ }
1073
+
1074
+ subscribeListOnWheel(list) {
1075
+ if (this.unsubscribeListOnWheel) {
1076
+ this.unsubscribeListOnWheel();
1077
+ this.unsubscribeListOnWheel = null;
1078
+ }
1079
+ if (list) {
1080
+ this.unsubscribeListOnWheel = addEventListenerWithOptions(list, "wheel", (e) => this.onListWheel(e), {
1081
+ passive: false,
1082
+ });
1083
+ }
1084
+ }
1085
+
1086
+ subscribeListOnScroll(list) {
1087
+ if (this.unsubscribeListOnScroll) {
1088
+ this.unsubscribeListOnScroll();
1089
+ this.unsubscribeListOnScroll = null;
1090
+ }
1091
+ if (list) {
1092
+ this.unsubscribeListOnScroll = addEventListenerWithOptions(list, "scroll", (e) => this.onListScroll(e), {
1093
+ passive: false,
1094
+ });
1095
+ }
1096
+ }
1097
+
1098
+ submitOnEnter(e) {
1099
+ let instance = this.props.instance.parent;
1100
+ while (instance) {
1101
+ if (instance.events && instance.events.onSubmit) {
1102
+ instance.events.onSubmit(e, instance);
1103
+ break;
1104
+ } else {
1105
+ instance = instance.parent;
1106
+ }
1107
+ }
1108
+ }
1109
+ }