cx 22.4.0 → 22.4.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 (773) 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 +2490 -2470
  5. package/dist/manifest.js +581 -581
  6. package/dist/reset.js +1 -0
  7. package/dist/ui.js +5213 -5213
  8. package/dist/util.js +7 -3
  9. package/dist/widgets.js +21871 -21857
  10. package/index.js +17 -17
  11. package/locale/de-de.js +69 -69
  12. package/locale/en-us.js +71 -71
  13. package/locale/es-es.js +69 -69
  14. package/locale/fr-fr.js +70 -70
  15. package/locale/nl-nl.js +75 -75
  16. package/locale/pt-pt.js +63 -63
  17. package/locale/sr-latn-ba.js +70 -70
  18. package/package.json +30 -30
  19. package/src/charts/Bar.d.ts +27 -27
  20. package/src/charts/Bar.js +89 -89
  21. package/src/charts/Bar.scss +26 -26
  22. package/src/charts/BarGraph.d.ts +16 -16
  23. package/src/charts/BarGraph.js +110 -110
  24. package/src/charts/BarGraph.scss +27 -27
  25. package/src/charts/BubbleGraph.js +92 -92
  26. package/src/charts/BubbleGraph.scss +29 -29
  27. package/src/charts/Chart.d.ts +12 -12
  28. package/src/charts/Chart.js +77 -77
  29. package/src/charts/ColorMap.d.ts +26 -26
  30. package/src/charts/ColorMap.js +98 -98
  31. package/src/charts/Column.scss +26 -26
  32. package/src/charts/ColumnBarBase.d.ts +61 -61
  33. package/src/charts/ColumnBarBase.js +169 -169
  34. package/src/charts/ColumnBarGraphBase.d.ts +71 -71
  35. package/src/charts/ColumnBarGraphBase.js +119 -119
  36. package/src/charts/ColumnGraph.d.ts +19 -19
  37. package/src/charts/ColumnGraph.js +114 -114
  38. package/src/charts/ColumnGraph.scss +27 -27
  39. package/src/charts/Grid.js +5 -5
  40. package/src/charts/Gridlines.d.ts +24 -24
  41. package/src/charts/Gridlines.js +48 -48
  42. package/src/charts/Gridlines.scss +22 -22
  43. package/src/charts/Legend.d.ts +26 -26
  44. package/src/charts/Legend.js +142 -142
  45. package/src/charts/Legend.scss +41 -41
  46. package/src/charts/LegendEntry.d.ts +37 -37
  47. package/src/charts/LegendEntry.js +117 -117
  48. package/src/charts/LegendEntry.scss +30 -30
  49. package/src/charts/LineGraph.d.ts +90 -90
  50. package/src/charts/LineGraph.js +201 -201
  51. package/src/charts/LineGraph.scss +23 -23
  52. package/src/charts/Marker.d.ts +87 -87
  53. package/src/charts/Marker.js +287 -287
  54. package/src/charts/Marker.scss +41 -41
  55. package/src/charts/MarkerLine.d.ts +57 -57
  56. package/src/charts/MarkerLine.js +128 -128
  57. package/src/charts/MarkerLine.scss +17 -17
  58. package/src/charts/MouseTracker.d.ts +16 -16
  59. package/src/charts/MouseTracker.js +80 -80
  60. package/src/charts/Pie.js +8 -8
  61. package/src/charts/PieChart.d.ts +80 -80
  62. package/src/charts/PieChart.js +370 -370
  63. package/src/charts/PieChart.scss +26 -26
  64. package/src/charts/PieLabel.d.ts +26 -26
  65. package/src/charts/PieLabel.js +65 -65
  66. package/src/charts/PieLabelsContainer.d.ts +3 -3
  67. package/src/charts/PieLabelsContainer.js +55 -55
  68. package/src/charts/Range.d.ts +74 -74
  69. package/src/charts/Range.js +205 -205
  70. package/src/charts/Range.scss +18 -18
  71. package/src/charts/ScatterGraph.d.ts +65 -65
  72. package/src/charts/ScatterGraph.js +155 -155
  73. package/src/charts/ScatterGraph.scss +21 -21
  74. package/src/charts/axis/Axis.d.ts +82 -82
  75. package/src/charts/axis/Axis.js +222 -222
  76. package/src/charts/axis/Axis.scss +22 -22
  77. package/src/charts/axis/CategoryAxis.d.ts +21 -21
  78. package/src/charts/axis/CategoryAxis.js +224 -224
  79. package/src/charts/axis/CategoryAxis.scss +32 -32
  80. package/src/charts/axis/NumericAxis.js +349 -349
  81. package/src/charts/axis/NumericAxis.scss +32 -32
  82. package/src/charts/axis/Stack.d.ts +10 -10
  83. package/src/charts/axis/Stack.js +58 -58
  84. package/src/charts/axis/TimeAxis.d.ts +23 -23
  85. package/src/charts/axis/TimeAxis.js +510 -510
  86. package/src/charts/axis/TimeAxis.scss +32 -32
  87. package/src/charts/axis/index.d.ts +3 -3
  88. package/src/charts/axis/index.js +3 -3
  89. package/src/charts/axis/index.scss +5 -5
  90. package/src/charts/axis/variables.scss +2 -2
  91. package/src/charts/helpers/MinMaxFinder.js +37 -37
  92. package/src/charts/helpers/MinMaxReducer.d.ts +22 -22
  93. package/src/charts/helpers/PointReducer.d.ts +15 -15
  94. package/src/charts/helpers/PointReducer.js +39 -39
  95. package/src/charts/helpers/SnapPointFinder.d.ts +18 -18
  96. package/src/charts/helpers/SnapPointFinder.js +46 -46
  97. package/src/charts/helpers/ValueAtFinder.d.ts +16 -16
  98. package/src/charts/helpers/ValueAtFinder.js +41 -41
  99. package/src/charts/helpers/index.d.ts +4 -4
  100. package/src/charts/helpers/index.js +4 -4
  101. package/src/charts/index.d.ts +23 -23
  102. package/src/charts/index.js +31 -31
  103. package/src/charts/index.scss +20 -20
  104. package/src/charts/palette.scss +95 -95
  105. package/src/charts/shapes.d.ts +22 -22
  106. package/src/charts/shapes.js +79 -79
  107. package/src/charts/variables.scss +14 -14
  108. package/src/core.d.ts +241 -231
  109. package/src/data/AggregateFunction.d.ts +17 -17
  110. package/src/data/AggregateFunction.js +148 -148
  111. package/src/data/ArrayElementView.d.ts +13 -13
  112. package/src/data/ArrayElementView.js +46 -46
  113. package/src/data/ArrayRef.d.ts +14 -14
  114. package/src/data/ArrayRef.js +34 -34
  115. package/src/data/AugmentedViewBase.d.ts +18 -18
  116. package/src/data/AugmentedViewBase.js +67 -67
  117. package/src/data/Binding.d.ts +16 -16
  118. package/src/data/Binding.js +86 -86
  119. package/src/data/Binding.spec.js +51 -51
  120. package/src/data/ExposedRecordView.d.ts +14 -14
  121. package/src/data/ExposedRecordView.js +69 -69
  122. package/src/data/ExposedValueView.d.ts +19 -19
  123. package/src/data/ExposedValueView.js +72 -72
  124. package/src/data/Expression.d.ts +16 -16
  125. package/src/data/Grouper.d.ts +21 -21
  126. package/src/data/Grouper.js +120 -120
  127. package/src/data/Grouper.spec.js +22 -22
  128. package/src/data/NestedDataView.d.ts +19 -19
  129. package/src/data/NestedDataView.js +22 -22
  130. package/src/data/ReadOnlyDataView.d.ts +14 -14
  131. package/src/data/ReadOnlyDataView.js +26 -26
  132. package/src/data/Ref.js +79 -79
  133. package/src/data/Store.d.ts +14 -14
  134. package/src/data/Store.js +46 -46
  135. package/src/data/Store.spec.js +22 -22
  136. package/src/data/StoreProxy.d.ts +4 -4
  137. package/src/data/StoreProxy.js +16 -16
  138. package/src/data/StoreRef.js +54 -54
  139. package/src/data/StringTemplate.d.ts +13 -13
  140. package/src/data/StringTemplate.js +97 -97
  141. package/src/data/StringTemplate.spec.js +82 -82
  142. package/src/data/StructuredSelector.d.ts +16 -16
  143. package/src/data/StructuredSelector.js +131 -131
  144. package/src/data/StructuredSelector.spec.js +113 -113
  145. package/src/data/SubscribableView.d.ts +11 -11
  146. package/src/data/View.d.ts +122 -122
  147. package/src/data/View.js +182 -182
  148. package/src/data/View.spec.js +60 -60
  149. package/src/data/ZoomIntoPropertyView.d.ts +11 -11
  150. package/src/data/ZoomIntoPropertyView.js +33 -33
  151. package/src/data/ZoomIntoPropertyView.spec.js +65 -65
  152. package/src/data/comparer.d.ts +7 -7
  153. package/src/data/comparer.js +51 -51
  154. package/src/data/comparer.spec.js +60 -60
  155. package/src/data/computable.d.ts +46 -46
  156. package/src/data/computable.js +56 -56
  157. package/src/data/computable.spec.js +55 -55
  158. package/src/data/createAccessorModelProxy.d.ts +6 -6
  159. package/src/data/createAccessorModelProxy.js +46 -24
  160. package/src/data/createAccessorModelProxy.spec.tsx +37 -23
  161. package/src/data/createStructuredSelector.d.ts +2 -2
  162. package/src/data/createStructuredSelector.js +43 -43
  163. package/src/data/createStructuredSelector.spec.js +46 -46
  164. package/src/data/defaultCompare.js +14 -14
  165. package/src/data/diff/diffArrays.d.ts +15 -15
  166. package/src/data/diff/diffArrays.js +41 -41
  167. package/src/data/diff/diffs.spec.js +49 -49
  168. package/src/data/diff/index.d.ts +1 -1
  169. package/src/data/diff/index.js +1 -1
  170. package/src/data/enableFatArrowExpansion.d.ts +1 -1
  171. package/src/data/enableFatArrowExpansion.js +6 -6
  172. package/src/data/getAccessor.d.ts +8 -8
  173. package/src/data/getAccessor.js +61 -61
  174. package/src/data/getSelector.d.ts +3 -3
  175. package/src/data/getSelector.js +48 -48
  176. package/src/data/getSelector.spec.js +43 -43
  177. package/src/data/index.d.ts +30 -30
  178. package/src/data/index.js +28 -28
  179. package/src/data/isSelector.d.ts +1 -1
  180. package/src/data/isSelector.js +26 -26
  181. package/src/data/ops/append.d.ts +1 -1
  182. package/src/data/ops/append.js +7 -7
  183. package/src/data/ops/append.spec.js +28 -28
  184. package/src/data/ops/filter.d.ts +1 -1
  185. package/src/data/ops/filter.js +8 -8
  186. package/src/data/ops/filter.spec.js +29 -29
  187. package/src/data/ops/findTreeNode.js +15 -15
  188. package/src/data/ops/findTreeNode.spec.js +24 -24
  189. package/src/data/ops/index.d.ts +10 -10
  190. package/src/data/ops/index.js +10 -10
  191. package/src/data/ops/insertElement.js +2 -2
  192. package/src/data/ops/merge.d.ts +3 -3
  193. package/src/data/ops/merge.js +9 -9
  194. package/src/data/ops/merge.spec.js +27 -27
  195. package/src/data/ops/moveElement.js +13 -13
  196. package/src/data/ops/removeTreeNodes.d.ts +1 -1
  197. package/src/data/ops/removeTreeNodes.js +5 -5
  198. package/src/data/ops/removeTreeNodes.spec.js +28 -28
  199. package/src/data/ops/updateArray.d.ts +5 -5
  200. package/src/data/ops/updateArray.js +24 -24
  201. package/src/data/ops/updateArray.spec.js +38 -38
  202. package/src/data/ops/updateTree.d.ts +7 -7
  203. package/src/data/ops/updateTree.js +25 -25
  204. package/src/data/ops/updateTree.spec.js +34 -34
  205. package/src/global.scss +13 -13
  206. package/src/hooks/createLocalStorageRef.d.ts +2 -2
  207. package/src/hooks/createLocalStorageRef.js +22 -22
  208. package/src/hooks/index.d.ts +8 -8
  209. package/src/hooks/index.js +7 -7
  210. package/src/hooks/invokeCallback.d.ts +5 -5
  211. package/src/hooks/invokeCallback.js +6 -6
  212. package/src/hooks/invokeCallback.spec.js +53 -53
  213. package/src/hooks/resolveCallback.d.ts +3 -3
  214. package/src/hooks/resolveCallback.js +11 -11
  215. package/src/hooks/resolveCallback.spec.js +54 -54
  216. package/src/hooks/store.d.ts +7 -7
  217. package/src/hooks/store.js +32 -32
  218. package/src/hooks/store.spec.js +73 -73
  219. package/src/hooks/useEffect.d.ts +2 -2
  220. package/src/hooks/useEffect.js +14 -14
  221. package/src/hooks/useInterval.js +7 -7
  222. package/src/hooks/useState.d.ts +2 -2
  223. package/src/hooks/useState.js +15 -15
  224. package/src/hooks/useTrigger.d.ts +4 -4
  225. package/src/hooks/useTrigger.js +20 -20
  226. package/src/hooks/useTrigger.spec.js +102 -102
  227. package/src/index.js +7 -7
  228. package/src/index.scss +6 -6
  229. package/src/svg/BoundedObject.d.ts +22 -22
  230. package/src/svg/BoundedObject.js +59 -59
  231. package/src/svg/ClipRect.d.ts +4 -4
  232. package/src/svg/ClipRect.js +23 -23
  233. package/src/svg/Ellipse.d.ts +23 -23
  234. package/src/svg/Ellipse.js +36 -36
  235. package/src/svg/Line.d.ts +20 -20
  236. package/src/svg/Line.js +32 -32
  237. package/src/svg/NonOverlappingRect.d.ts +5 -5
  238. package/src/svg/NonOverlappingRect.js +14 -14
  239. package/src/svg/NonOverlappingRectGroup.d.ts +3 -3
  240. package/src/svg/NonOverlappingRectGroup.js +36 -36
  241. package/src/svg/Rectangle.d.ts +23 -23
  242. package/src/svg/Rectangle.js +36 -36
  243. package/src/svg/Svg.d.ts +32 -32
  244. package/src/svg/Svg.js +177 -177
  245. package/src/svg/Svg.scss +26 -26
  246. package/src/svg/Text.d.ts +38 -38
  247. package/src/svg/Text.js +61 -61
  248. package/src/svg/TextualBoundedObject.d.ts +6 -6
  249. package/src/svg/TextualBoundedObject.js +28 -28
  250. package/src/svg/index.d.ts +11 -11
  251. package/src/svg/index.js +17 -17
  252. package/src/svg/index.scss +8 -8
  253. package/src/svg/util/Rect.d.ts +40 -40
  254. package/src/svg/util/Rect.js +108 -108
  255. package/src/ui/CSS.d.ts +19 -19
  256. package/src/ui/CSS.js +79 -79
  257. package/src/ui/CSSHelper.d.ts +10 -10
  258. package/src/ui/CSSHelper.js +17 -17
  259. package/src/ui/Container.d.ts +18 -18
  260. package/src/ui/Container.js +183 -183
  261. package/src/ui/ContentResolver.d.ts +13 -13
  262. package/src/ui/ContentResolver.js +78 -78
  263. package/src/ui/Controller.d.ts +70 -33
  264. package/src/ui/Controller.js +114 -114
  265. package/src/ui/Controller.spec.js +414 -414
  266. package/src/ui/Culture.d.ts +22 -22
  267. package/src/ui/Culture.js +65 -65
  268. package/src/ui/Cx.d.ts +18 -18
  269. package/src/ui/Cx.js +313 -313
  270. package/src/ui/Cx.spec.js +193 -193
  271. package/src/ui/DataProxy.d.ts +10 -10
  272. package/src/ui/DataProxy.js +44 -44
  273. package/src/ui/DataProxy.spec.js +335 -335
  274. package/src/ui/DetachedScope.d.ts +21 -21
  275. package/src/ui/DetachedScope.js +93 -93
  276. package/src/ui/FocusManager.d.ts +29 -29
  277. package/src/ui/FocusManager.js +163 -163
  278. package/src/ui/Format.d.ts +2 -2
  279. package/src/ui/Format.js +88 -88
  280. package/src/ui/HoverSync.d.ts +13 -13
  281. package/src/ui/HoverSync.js +147 -147
  282. package/src/ui/Instance.d.ts +69 -69
  283. package/src/ui/IsolatedScope.d.ts +16 -16
  284. package/src/ui/IsolatedScope.js +29 -29
  285. package/src/ui/IsolatedScope.spec.js +62 -62
  286. package/src/ui/Localization.d.ts +17 -17
  287. package/src/ui/Localization.js +72 -72
  288. package/src/ui/PureContainer.d.ts +16 -16
  289. package/src/ui/PureContainer.js +7 -7
  290. package/src/ui/RenderingContext.d.ts +9 -9
  291. package/src/ui/RenderingContext.js +88 -88
  292. package/src/ui/Repeater.d.ts +46 -46
  293. package/src/ui/Repeater.js +98 -98
  294. package/src/ui/Repeater.spec.js +59 -59
  295. package/src/ui/Rescope.d.ts +9 -9
  296. package/src/ui/Rescope.js +31 -31
  297. package/src/ui/Rescope.spec.js +195 -195
  298. package/src/ui/ResizeManager.d.ts +9 -9
  299. package/src/ui/ResizeManager.js +30 -30
  300. package/src/ui/Restate.d.ts +12 -12
  301. package/src/ui/Restate.js +155 -155
  302. package/src/ui/Restate.spec.js +422 -422
  303. package/src/ui/StaticText.d.ts +8 -8
  304. package/src/ui/StaticText.js +9 -9
  305. package/src/ui/StructuredInstanceDataAccessor.d.ts +16 -16
  306. package/src/ui/StructuredInstanceDataAccessor.js +26 -26
  307. package/src/ui/Text.d.ts +10 -10
  308. package/src/ui/Text.js +27 -27
  309. package/src/ui/VDOM.d.ts +3 -3
  310. package/src/ui/VDOM.js +2 -2
  311. package/src/ui/Widget.d.ts +14 -14
  312. package/src/ui/Widget.js +200 -200
  313. package/src/ui/ZIndexManager.d.ts +7 -7
  314. package/src/ui/ZIndexManager.js +11 -11
  315. package/src/ui/adapter/ArrayAdapter.d.ts +16 -16
  316. package/src/ui/adapter/ArrayAdapter.js +142 -142
  317. package/src/ui/adapter/DataAdapter.d.ts +19 -19
  318. package/src/ui/adapter/DataAdapter.js +19 -19
  319. package/src/ui/adapter/GroupAdapter.d.ts +4 -4
  320. package/src/ui/adapter/GroupAdapter.js +135 -135
  321. package/src/ui/adapter/TreeAdapter.d.ts +4 -4
  322. package/src/ui/adapter/TreeAdapter.js +73 -73
  323. package/src/ui/adapter/TreeAdapter.spec.js +67 -67
  324. package/src/ui/adapter/index.d.ts +4 -4
  325. package/src/ui/adapter/index.js +4 -4
  326. package/src/ui/app/History.d.ts +17 -17
  327. package/src/ui/app/History.js +114 -114
  328. package/src/ui/app/Url.d.ts +21 -21
  329. package/src/ui/app/Url.js +103 -103
  330. package/src/ui/app/Url.spec.js +51 -51
  331. package/src/ui/app/index.d.ts +4 -4
  332. package/src/ui/app/index.js +5 -5
  333. package/src/ui/app/startAppLoop.d.ts +3 -3
  334. package/src/ui/app/startAppLoop.js +57 -57
  335. package/src/ui/app/startHotAppLoop.d.ts +6 -6
  336. package/src/ui/app/startHotAppLoop.js +25 -25
  337. package/src/ui/batchUpdates.d.ts +10 -10
  338. package/src/ui/batchUpdates.js +67 -67
  339. package/src/ui/bind.d.ts +4 -4
  340. package/src/ui/bind.js +7 -7
  341. package/src/ui/createFunctionalComponent.d.ts +1 -1
  342. package/src/ui/createFunctionalComponent.js +68 -68
  343. package/src/ui/createFunctionalComponent.spec.js +400 -400
  344. package/src/ui/expr.d.ts +24 -24
  345. package/src/ui/expr.js +17 -17
  346. package/src/ui/flattenProps.js +21 -21
  347. package/src/ui/index.js +44 -44
  348. package/src/ui/index.scss +2 -2
  349. package/src/ui/keyboardShortcuts.d.ts +4 -4
  350. package/src/ui/keyboardShortcuts.js +32 -32
  351. package/src/ui/layout/Content.d.ts +11 -11
  352. package/src/ui/layout/Content.js +16 -16
  353. package/src/ui/layout/ContentPlaceholder.d.ts +17 -17
  354. package/src/ui/layout/ContentPlaceholder.js +79 -79
  355. package/src/ui/layout/ContentPlaceholder.spec.js +368 -368
  356. package/src/ui/layout/FirstVisibleChildLayout.d.ts +4 -4
  357. package/src/ui/layout/FirstVisibleChildLayout.js +65 -65
  358. package/src/ui/layout/FirstVisibleChildLayout.spec.js +196 -196
  359. package/src/ui/layout/LabelsLeftLayout.d.ts +11 -11
  360. package/src/ui/layout/LabelsLeftLayout.js +59 -59
  361. package/src/ui/layout/LabelsLeftLayout.scss +44 -44
  362. package/src/ui/layout/LabelsTopLayout.d.ts +15 -15
  363. package/src/ui/layout/LabelsTopLayout.js +134 -134
  364. package/src/ui/layout/LabelsTopLayout.scss +63 -63
  365. package/src/ui/layout/UseParentLayout.d.ts +4 -4
  366. package/src/ui/layout/UseParentLayout.js +6 -6
  367. package/src/ui/layout/exploreChildren.d.ts +14 -14
  368. package/src/ui/layout/exploreChildren.js +40 -40
  369. package/src/ui/layout/index.d.ts +10 -10
  370. package/src/ui/layout/index.js +10 -10
  371. package/src/ui/layout/index.scss +3 -3
  372. package/src/ui/layout/variables.scss +2 -2
  373. package/src/ui/selection/KeySelection.d.ts +17 -17
  374. package/src/ui/selection/KeySelection.js +129 -129
  375. package/src/ui/selection/PropertySelection.d.ts +17 -17
  376. package/src/ui/selection/PropertySelection.js +57 -57
  377. package/src/ui/selection/Selection.d.ts +27 -27
  378. package/src/ui/selection/Selection.js +97 -97
  379. package/src/ui/selection/index.d.ts +3 -3
  380. package/src/ui/selection/index.js +3 -3
  381. package/src/ui/tpl.d.ts +2 -2
  382. package/src/ui/tpl.js +4 -4
  383. package/src/ui/variables.scss +1 -1
  384. package/src/util/Component.d.ts +41 -41
  385. package/src/util/Component.js +107 -107
  386. package/src/util/Console.d.ts +9 -9
  387. package/src/util/Console.js +11 -11
  388. package/src/util/DOM.d.ts +33 -33
  389. package/src/util/DOM.js +72 -72
  390. package/src/util/Debug.d.ts +10 -10
  391. package/src/util/Debug.js +45 -45
  392. package/src/util/Format.d.ts +13 -13
  393. package/src/util/Format.js +241 -241
  394. package/src/util/Format.spec.js +69 -69
  395. package/src/util/GlobalCacheIdentifier.js +11 -11
  396. package/src/util/GlobalCacheldentifier.d.ts +6 -6
  397. package/src/util/KeyCode.d.ts +21 -21
  398. package/src/util/KeyCode.js +21 -21
  399. package/src/util/SubscriberList.d.ts +41 -41
  400. package/src/util/SubscriberList.js +57 -57
  401. package/src/util/Timing.d.ts +13 -13
  402. package/src/util/Timing.js +57 -57
  403. package/src/util/TraversalStack.js +42 -42
  404. package/src/util/TraversalStack.spec.js +46 -46
  405. package/src/util/addEventListenerWithOptions.d.ts +6 -6
  406. package/src/util/addEventListenerWithOptions.js +9 -9
  407. package/src/util/browserSupportsPassiveEventHandlers.d.ts +4 -4
  408. package/src/util/browserSupportsPassiveEventHandlers.js +18 -18
  409. package/src/util/calculateNaturalElementHeight.d.ts +1 -1
  410. package/src/util/calculateNaturalElementHeight.js +22 -22
  411. package/src/util/call-once.scss +6 -6
  412. package/src/util/coalesce.d.ts +1 -1
  413. package/src/util/coalesce.js +6 -6
  414. package/src/util/color/hslToRgb.d.ts +8 -8
  415. package/src/util/color/hslToRgb.js +27 -27
  416. package/src/util/color/index.d.ts +3 -3
  417. package/src/util/color/index.js +4 -4
  418. package/src/util/color/parseColor.d.ts +59 -59
  419. package/src/util/color/parseColor.js +119 -119
  420. package/src/util/color/rgbToHex.d.ts +8 -8
  421. package/src/util/color/rgbToHex.js +7 -7
  422. package/src/util/color/rgbToHsl.d.ts +8 -8
  423. package/src/util/color/rgbToHsl.js +27 -27
  424. package/src/util/date/dateDiff.d.ts +7 -7
  425. package/src/util/date/dateDiff.js +3 -3
  426. package/src/util/date/diff.d.ts +7 -7
  427. package/src/util/date/diff.js +7 -7
  428. package/src/util/date/encodeDateWithTimezoneOffset.js +18 -18
  429. package/src/util/date/index.d.ts +8 -8
  430. package/src/util/date/index.js +9 -9
  431. package/src/util/date/lowerBoundCheck.d.ts +7 -7
  432. package/src/util/date/lowerBoundCheck.js +6 -6
  433. package/src/util/date/maxDate.d.ts +5 -5
  434. package/src/util/date/maxDate.js +9 -9
  435. package/src/util/date/minDate.d.ts +5 -5
  436. package/src/util/date/minDate.js +9 -9
  437. package/src/util/date/monthStart.d.ts +5 -5
  438. package/src/util/date/monthStart.js +3 -3
  439. package/src/util/date/sameDate.d.ts +6 -6
  440. package/src/util/date/sameDate.js +5 -5
  441. package/src/util/date/upperBoundCheck.d.ts +7 -7
  442. package/src/util/date/upperBoundCheck.js +6 -6
  443. package/src/util/date/upperBoundCheck.spec.js +30 -30
  444. package/src/util/date/zeroTime.d.ts +6 -6
  445. package/src/util/date/zeroTime.js +3 -3
  446. package/src/util/debounce.d.ts +9 -9
  447. package/src/util/dummyCallback.d.ts +1 -1
  448. package/src/util/dummyCallback.js +1 -1
  449. package/src/util/escapeSpecialRegexCharacters.d.ts +6 -6
  450. package/src/util/escapeSpecialRegexCharacters.js +3 -3
  451. package/src/util/eventCallbacks.d.ts +4 -4
  452. package/src/util/eventCallbacks.js +2 -2
  453. package/src/util/expandFatArrows.js +118 -118
  454. package/src/util/findScrollableParent.js +16 -16
  455. package/src/util/getActiveElement.js +3 -3
  456. package/src/util/getParentFrameBoundingClientRect.js +18 -18
  457. package/src/util/getScrollerBoundingClientRect.js +21 -21
  458. package/src/util/getSearchQueryPredicate.js +58 -58
  459. package/src/util/getSearchQueryPredicate.spec.js +40 -40
  460. package/src/util/getTopLevelBoundingClientRect.js +13 -13
  461. package/src/util/getVendorPrefix.js +26 -26
  462. package/src/util/index.d.ts +50 -50
  463. package/src/util/index.js +52 -52
  464. package/src/util/index.scss +10 -10
  465. package/src/util/innerTextTrim.d.ts +6 -6
  466. package/src/util/innerTextTrim.js +5 -5
  467. package/src/util/isArray.js +3 -3
  468. package/src/util/isDefined.js +3 -3
  469. package/src/util/isDigit.d.ts +6 -6
  470. package/src/util/isDigit.js +3 -3
  471. package/src/util/isFunction.d.ts +1 -1
  472. package/src/util/isFunction.js +3 -3
  473. package/src/util/isNonEmptyArray.d.ts +1 -1
  474. package/src/util/isNonEmptyArray.js +3 -3
  475. package/src/util/isNumber.js +3 -3
  476. package/src/util/isObject.js +3 -3
  477. package/src/util/isPromise.d.ts +1 -1
  478. package/src/util/isPromise.js +6 -6
  479. package/src/util/isString.js +3 -3
  480. package/src/util/isTextInputElement.d.ts +1 -1
  481. package/src/util/isTextInputElement.js +2 -2
  482. package/src/util/isTouchDevice.d.ts +1 -1
  483. package/src/util/isTouchDevice.js +7 -7
  484. package/src/util/isTouchEvent.d.ts +3 -3
  485. package/src/util/isTouchEvent.js +52 -52
  486. package/src/util/isUndefined.js +3 -3
  487. package/src/util/onIdleCallback.js +13 -13
  488. package/src/util/parseStyle.d.ts +3 -3
  489. package/src/util/parseStyle.js +27 -27
  490. package/src/util/quote.d.ts +2 -2
  491. package/src/util/quote.js +5 -5
  492. package/src/util/reverseSlice.js +9 -9
  493. package/src/util/routeAppend.js +15 -15
  494. package/src/util/routeAppend.spec.js +19 -19
  495. package/src/util/scrollElementIntoView.d.ts +7 -6
  496. package/src/util/scrollElementIntoView.js +34 -59
  497. package/src/util/scss/add-rules.scss +39 -39
  498. package/src/util/scss/calc.scss +40 -40
  499. package/src/util/scss/call-once.scss +10 -10
  500. package/src/util/scss/clockwise.scss +47 -47
  501. package/src/util/scss/colors.scss +7 -7
  502. package/src/util/scss/deep-get.scss +9 -9
  503. package/src/util/scss/deep-merge.scss +18 -18
  504. package/src/util/scss/include.scss +47 -47
  505. package/src/util/scss/index.scss +8 -8
  506. package/src/util/shallowEquals.js +43 -43
  507. package/src/util/throttle.d.ts +8 -8
  508. package/src/util/throttle.js +14 -14
  509. package/src/variables.scss +217 -217
  510. package/src/widgets/AccessorBindings.spec.tsx +66 -66
  511. package/src/widgets/Button.d.ts +52 -52
  512. package/src/widgets/Button.scss +108 -108
  513. package/src/widgets/Button.variables.scss +107 -107
  514. package/src/widgets/CxCredit.d.ts +12 -12
  515. package/src/widgets/CxCredit.js +31 -31
  516. package/src/widgets/CxCredit.scss +41 -41
  517. package/src/widgets/DocumentTitle.d.ts +11 -10
  518. package/src/widgets/DocumentTitle.js +68 -68
  519. package/src/widgets/FlexBox.d.ts +69 -69
  520. package/src/widgets/FlexBox.js +92 -92
  521. package/src/widgets/FlexBox.scss +155 -155
  522. package/src/widgets/Heading.d.ts +16 -16
  523. package/src/widgets/Heading.js +32 -32
  524. package/src/widgets/Heading.scss +38 -38
  525. package/src/widgets/HighlightedSearchText.d.ts +9 -9
  526. package/src/widgets/HighlightedSearchText.js +36 -36
  527. package/src/widgets/HighlightedSearchText.scss +18 -18
  528. package/src/widgets/HtmlElement.d.ts +26 -26
  529. package/src/widgets/HtmlElement.js +273 -273
  530. package/src/widgets/HtmlElement.spec.js +57 -57
  531. package/src/widgets/Icon.d.ts +36 -36
  532. package/src/widgets/Icon.js +50 -50
  533. package/src/widgets/Icon.scss +20 -20
  534. package/src/widgets/List.d.ts +84 -84
  535. package/src/widgets/List.js +580 -578
  536. package/src/widgets/List.scss +92 -92
  537. package/src/widgets/ProgressBar.d.ts +17 -17
  538. package/src/widgets/ProgressBar.js +46 -46
  539. package/src/widgets/ProgressBar.scss +49 -49
  540. package/src/widgets/Resizer.d.ts +27 -27
  541. package/src/widgets/Resizer.js +151 -151
  542. package/src/widgets/Resizer.scss +42 -42
  543. package/src/widgets/Sandbox.d.ts +18 -18
  544. package/src/widgets/Sandbox.js +58 -58
  545. package/src/widgets/Section.d.ts +52 -52
  546. package/src/widgets/Section.js +139 -139
  547. package/src/widgets/Section.scss +54 -54
  548. package/src/widgets/animations.scss +10 -10
  549. package/src/widgets/autoFocus.d.ts +1 -1
  550. package/src/widgets/autoFocus.js +11 -11
  551. package/src/widgets/cx.d.ts +1 -1
  552. package/src/widgets/cx.js +71 -71
  553. package/src/widgets/drag-drop/DragClone.scss +33 -33
  554. package/src/widgets/drag-drop/DragHandle.d.ts +10 -10
  555. package/src/widgets/drag-drop/DragHandle.js +37 -37
  556. package/src/widgets/drag-drop/DragHandle.scss +16 -16
  557. package/src/widgets/drag-drop/DragSource.d.ts +34 -34
  558. package/src/widgets/drag-drop/DragSource.js +160 -160
  559. package/src/widgets/drag-drop/DragSource.scss +24 -24
  560. package/src/widgets/drag-drop/DropZone.d.ts +90 -90
  561. package/src/widgets/drag-drop/DropZone.js +213 -213
  562. package/src/widgets/drag-drop/DropZone.scss +74 -74
  563. package/src/widgets/drag-drop/index.d.ts +4 -4
  564. package/src/widgets/drag-drop/index.js +4 -4
  565. package/src/widgets/drag-drop/index.scss +3 -3
  566. package/src/widgets/drag-drop/ops.d.ts +56 -56
  567. package/src/widgets/drag-drop/ops.js +344 -344
  568. package/src/widgets/drag-drop/variables.scss +11 -11
  569. package/src/widgets/enableAllInternalDependencies.d.ts +1 -1
  570. package/src/widgets/enableAllInternalDependencies.js +11 -11
  571. package/src/widgets/form/Calendar.d.ts +57 -57
  572. package/src/widgets/form/Calendar.js +506 -506
  573. package/src/widgets/form/Calendar.scss +164 -164
  574. package/src/widgets/form/Calendar.variables.scss +63 -63
  575. package/src/widgets/form/Checkbox.d.ts +43 -43
  576. package/src/widgets/form/Checkbox.js +200 -200
  577. package/src/widgets/form/Checkbox.scss +122 -122
  578. package/src/widgets/form/Checkbox.variables.scss +39 -39
  579. package/src/widgets/form/ColorField.d.ts +43 -43
  580. package/src/widgets/form/ColorField.js +389 -389
  581. package/src/widgets/form/ColorField.scss +92 -92
  582. package/src/widgets/form/ColorPicker.d.ts +23 -23
  583. package/src/widgets/form/ColorPicker.js +451 -451
  584. package/src/widgets/form/ColorPicker.scss +184 -184
  585. package/src/widgets/form/ColorPicker.variables.scss +20 -20
  586. package/src/widgets/form/DateField.d.ts +6 -6
  587. package/src/widgets/form/DateField.js +12 -12
  588. package/src/widgets/form/DateTimeField.d.ts +83 -83
  589. package/src/widgets/form/DateTimeField.js +571 -571
  590. package/src/widgets/form/DateTimeField.scss +90 -90
  591. package/src/widgets/form/DateTimePicker.js +391 -391
  592. package/src/widgets/form/DateTimePicker.scss +44 -44
  593. package/src/widgets/form/Field.d.ts +112 -112
  594. package/src/widgets/form/Field.js +419 -419
  595. package/src/widgets/form/Field.scss +162 -162
  596. package/src/widgets/form/FieldGroup.d.ts +6 -6
  597. package/src/widgets/form/FieldGroup.js +5 -5
  598. package/src/widgets/form/HelpText.d.ts +10 -10
  599. package/src/widgets/form/HelpText.js +9 -9
  600. package/src/widgets/form/HelpText.scss +23 -23
  601. package/src/widgets/form/Label.d.ts +25 -25
  602. package/src/widgets/form/Label.js +86 -86
  603. package/src/widgets/form/Label.scss +36 -36
  604. package/src/widgets/form/LabeledContainer.d.ts +17 -17
  605. package/src/widgets/form/LabeledContainer.js +57 -57
  606. package/src/widgets/form/LookupField.d.ts +159 -159
  607. package/src/widgets/form/LookupField.js +1109 -1109
  608. package/src/widgets/form/LookupField.scss +210 -210
  609. package/src/widgets/form/MonthField.d.ts +88 -88
  610. package/src/widgets/form/MonthField.js +512 -512
  611. package/src/widgets/form/MonthField.scss +99 -99
  612. package/src/widgets/form/MonthPicker.d.ts +68 -68
  613. package/src/widgets/form/MonthPicker.js +631 -631
  614. package/src/widgets/form/MonthPicker.scss +120 -120
  615. package/src/widgets/form/NumberField.d.ts +94 -94
  616. package/src/widgets/form/NumberField.js +443 -443
  617. package/src/widgets/form/NumberField.scss +65 -65
  618. package/src/widgets/form/Radio.d.ts +37 -37
  619. package/src/widgets/form/Radio.js +188 -188
  620. package/src/widgets/form/Radio.scss +122 -122
  621. package/src/widgets/form/Radio.variables.scss +45 -45
  622. package/src/widgets/form/Select.d.ts +73 -73
  623. package/src/widgets/form/Select.js +274 -274
  624. package/src/widgets/form/Select.scss +98 -98
  625. package/src/widgets/form/Slider.d.ts +62 -62
  626. package/src/widgets/form/Slider.js +339 -339
  627. package/src/widgets/form/Slider.scss +121 -121
  628. package/src/widgets/form/Switch.d.ts +38 -38
  629. package/src/widgets/form/Switch.js +120 -120
  630. package/src/widgets/form/Switch.scss +140 -140
  631. package/src/widgets/form/TextArea.d.ts +17 -17
  632. package/src/widgets/form/TextArea.js +182 -182
  633. package/src/widgets/form/TextArea.scss +60 -60
  634. package/src/widgets/form/TextField.d.ts +75 -75
  635. package/src/widgets/form/TextField.js +285 -286
  636. package/src/widgets/form/TextField.scss +67 -67
  637. package/src/widgets/form/TimeField.d.ts +6 -6
  638. package/src/widgets/form/TimeField.js +11 -11
  639. package/src/widgets/form/TimeList.js +84 -84
  640. package/src/widgets/form/UploadButton.d.ts +31 -31
  641. package/src/widgets/form/UploadButton.js +213 -213
  642. package/src/widgets/form/UploadButton.scss +47 -47
  643. package/src/widgets/form/ValidationError.d.ts +10 -10
  644. package/src/widgets/form/ValidationError.js +37 -37
  645. package/src/widgets/form/ValidationError.scss +21 -21
  646. package/src/widgets/form/ValidationGroup.spec.js +148 -148
  647. package/src/widgets/form/Validator.d.ts +6 -6
  648. package/src/widgets/form/Wheel.js +261 -261
  649. package/src/widgets/form/Wheel.scss +148 -148
  650. package/src/widgets/form/index.d.ts +26 -26
  651. package/src/widgets/form/index.js +29 -29
  652. package/src/widgets/form/index.scss +24 -24
  653. package/src/widgets/form/variables.scss +351 -351
  654. package/src/widgets/grid/Grid.d.ts +368 -368
  655. package/src/widgets/grid/Grid.js +3208 -3199
  656. package/src/widgets/grid/Grid.scss +680 -680
  657. package/src/widgets/grid/GridCell.d.ts +29 -29
  658. package/src/widgets/grid/GridCell.js +70 -70
  659. package/src/widgets/grid/GridCellEditor.js +41 -41
  660. package/src/widgets/grid/GridRow.js +228 -228
  661. package/src/widgets/grid/GridRowLine.js +24 -24
  662. package/src/widgets/grid/Pagination.d.ts +14 -14
  663. package/src/widgets/grid/Pagination.js +94 -94
  664. package/src/widgets/grid/Pagination.scss +113 -113
  665. package/src/widgets/grid/TreeNode.d.ts +25 -25
  666. package/src/widgets/grid/TreeNode.js +102 -102
  667. package/src/widgets/grid/TreeNode.scss +90 -90
  668. package/src/widgets/grid/index.d.ts +3 -3
  669. package/src/widgets/grid/index.js +14 -14
  670. package/src/widgets/grid/index.scss +3 -3
  671. package/src/widgets/grid/variables.scss +88 -88
  672. package/src/widgets/icons/arrow-down.svg +3 -3
  673. package/src/widgets/icons/arrow-right.svg +2 -2
  674. package/src/widgets/icons/base.svg +104 -104
  675. package/src/widgets/icons/calendar-old.svg +169 -169
  676. package/src/widgets/icons/calendar.js +16 -16
  677. package/src/widgets/icons/calendar.svg +187 -187
  678. package/src/widgets/icons/check.js +12 -12
  679. package/src/widgets/icons/clear.js +14 -14
  680. package/src/widgets/icons/clear.svg +74 -74
  681. package/src/widgets/icons/close.js +19 -19
  682. package/src/widgets/icons/close.svg +74 -74
  683. package/src/widgets/icons/cx.js +37 -37
  684. package/src/widgets/icons/drop-down.js +14 -14
  685. package/src/widgets/icons/dropdown-arrow.svg +61 -61
  686. package/src/widgets/icons/file.js +12 -12
  687. package/src/widgets/icons/file.svg +4 -4
  688. package/src/widgets/icons/folder-open.js +14 -14
  689. package/src/widgets/icons/folder-open.svg +5 -5
  690. package/src/widgets/icons/folder.js +12 -12
  691. package/src/widgets/icons/folder.svg +58 -58
  692. package/src/widgets/icons/forward.js +21 -21
  693. package/src/widgets/icons/forward.svg +67 -67
  694. package/src/widgets/icons/index.js +14 -14
  695. package/src/widgets/icons/loading.js +23 -23
  696. package/src/widgets/icons/loading.svg +4 -4
  697. package/src/widgets/icons/menu.js +16 -16
  698. package/src/widgets/icons/registry.js +53 -53
  699. package/src/widgets/icons/search.js +12 -12
  700. package/src/widgets/icons/search.svg +107 -107
  701. package/src/widgets/icons/sort-asc.js +13 -13
  702. package/src/widgets/icons/sort-asc.svg +3 -3
  703. package/src/widgets/icons/square.js +17 -17
  704. package/src/widgets/index.d.ts +55 -55
  705. package/src/widgets/index.js +57 -57
  706. package/src/widgets/index.scss +16 -16
  707. package/src/widgets/nav/Link.d.ts +22 -22
  708. package/src/widgets/nav/Link.js +7 -7
  709. package/src/widgets/nav/LinkButton.d.ts +31 -31
  710. package/src/widgets/nav/LinkButton.js +127 -127
  711. package/src/widgets/nav/Menu.d.ts +27 -27
  712. package/src/widgets/nav/Menu.js +411 -411
  713. package/src/widgets/nav/Menu.scss +74 -74
  714. package/src/widgets/nav/Menu.variables.scss +17 -17
  715. package/src/widgets/nav/MenuItem.d.ts +32 -32
  716. package/src/widgets/nav/MenuItem.js +444 -442
  717. package/src/widgets/nav/MenuItem.scss +128 -128
  718. package/src/widgets/nav/MenuSpacer.d.ts +5 -5
  719. package/src/widgets/nav/MenuSpacer.js +12 -12
  720. package/src/widgets/nav/RedirectRoute.d.ts +9 -9
  721. package/src/widgets/nav/RedirectRoute.js +40 -40
  722. package/src/widgets/nav/Route.d.ts +21 -21
  723. package/src/widgets/nav/Route.js +105 -105
  724. package/src/widgets/nav/Route.spec.js +27 -27
  725. package/src/widgets/nav/Scroller.d.ts +17 -17
  726. package/src/widgets/nav/Scroller.js +214 -214
  727. package/src/widgets/nav/Scroller.scss +146 -146
  728. package/src/widgets/nav/Submenu.d.ts +6 -6
  729. package/src/widgets/nav/Submenu.js +6 -6
  730. package/src/widgets/nav/Tab.d.ts +33 -33
  731. package/src/widgets/nav/Tab.js +82 -82
  732. package/src/widgets/nav/Tab.scss +81 -81
  733. package/src/widgets/nav/Tab.variables.scss +80 -80
  734. package/src/widgets/nav/cover.scss +21 -21
  735. package/src/widgets/nav/index.d.ts +10 -10
  736. package/src/widgets/nav/index.js +10 -10
  737. package/src/widgets/nav/index.scss +5 -5
  738. package/src/widgets/nav/variables.scss +25 -25
  739. package/src/widgets/overlay/ContextMenu.d.ts +8 -8
  740. package/src/widgets/overlay/ContextMenu.js +28 -28
  741. package/src/widgets/overlay/Dropdown.d.ts +27 -27
  742. package/src/widgets/overlay/Dropdown.js +601 -601
  743. package/src/widgets/overlay/Dropdown.scss +184 -184
  744. package/src/widgets/overlay/FlyweightTooltipTracker.d.ts +8 -8
  745. package/src/widgets/overlay/FlyweightTooltipTracker.js +36 -36
  746. package/src/widgets/overlay/MsgBox.d.ts +16 -16
  747. package/src/widgets/overlay/MsgBox.js +116 -116
  748. package/src/widgets/overlay/Overlay.d.ts +69 -69
  749. package/src/widgets/overlay/Overlay.js +737 -737
  750. package/src/widgets/overlay/Overlay.scss +66 -66
  751. package/src/widgets/overlay/Toast.d.ts +30 -30
  752. package/src/widgets/overlay/Toast.js +92 -92
  753. package/src/widgets/overlay/Toast.scss +162 -162
  754. package/src/widgets/overlay/Tooltip.d.ts +50 -50
  755. package/src/widgets/overlay/Tooltip.js +283 -283
  756. package/src/widgets/overlay/Tooltip.scss +175 -175
  757. package/src/widgets/overlay/Window.d.ts +38 -38
  758. package/src/widgets/overlay/Window.js +195 -195
  759. package/src/widgets/overlay/Window.scss +112 -112
  760. package/src/widgets/overlay/Window.variables.scss +67 -67
  761. package/src/widgets/overlay/alerts.d.ts +7 -7
  762. package/src/widgets/overlay/alerts.js +39 -39
  763. package/src/widgets/overlay/captureMouse.d.ts +53 -53
  764. package/src/widgets/overlay/captureMouse.js +132 -132
  765. package/src/widgets/overlay/captureMouse.scss +13 -13
  766. package/src/widgets/overlay/index.d.ts +10 -10
  767. package/src/widgets/overlay/index.js +10 -10
  768. package/src/widgets/overlay/index.scss +15 -15
  769. package/src/widgets/overlay/tooltip-ops.d.ts +8 -8
  770. package/src/widgets/overlay/tooltip-ops.js +24 -24
  771. package/src/widgets/overlay/variables.scss +82 -82
  772. package/src/widgets/variables.scss +144 -144
  773. package/yarn-error.log +0 -7973
package/dist/data.js CHANGED
@@ -1,2470 +1,2490 @@
1
- import {
2
- isObject,
3
- isString,
4
- isFunction,
5
- Format,
6
- isDigit,
7
- quoteStr,
8
- Component,
9
- isArray,
10
- isDefined,
11
- SubscriberList,
12
- isUndefined,
13
- expandFatArrows
14
- } from "cx/util";
15
-
16
- function createAccessorModelProxy(chain) {
17
- var _this = this;
18
-
19
- if (chain === void 0) {
20
- chain = "";
21
- }
22
-
23
- var proxy = new Proxy(function() {}, {
24
- get: function get(target, name) {
25
- if (name === "isAccessorChain") return true;
26
- if (typeof name !== "string") return _this;
27
- if (name === "toString" || name === "valueOf") return proxy;
28
- var newChain = chain;
29
- if (newChain.length > 0) newChain += ".";
30
- newChain += name;
31
- return createAccessorModelProxy(newChain);
32
- },
33
- apply: function apply() {
34
- return chain;
35
- }
36
- });
37
- proxy.isAccessorChain = true;
38
- return proxy;
39
- }
40
- function isAccessorChain(value) {
41
- return value != null && !!value.isAccessorChain;
42
- }
43
-
44
- var bindingCache = {};
45
- var Binding = /*#__PURE__*/ (function() {
46
- function Binding(path) {
47
- this.path = path;
48
- this.parts = path.split(".");
49
- var body = "return (x";
50
- var selector = "x";
51
-
52
- for (var i = 0; i < this.parts.length; i++) {
53
- if (this.parts[i][0] >= "0" && this.parts[i][0] <= "9") selector += "[" + this.parts[i] + "]";
54
- else selector += "." + this.parts[i];
55
- if (i + 1 < this.parts.length) body += " && " + selector;
56
- else body += " ? " + selector + " : undefined";
57
- }
58
-
59
- body += ")";
60
- this.value = new Function("x", body);
61
- }
62
-
63
- var _proto = Binding.prototype;
64
-
65
- _proto.set = function set(state, value) {
66
- var cv = this.value(state);
67
- if (cv === value) return state;
68
- var ns = Object.assign({}, state);
69
- var o = ns;
70
-
71
- for (var i = 0; i < this.parts.length; i++) {
72
- var part = this.parts[i];
73
- var no = i == this.parts.length - 1 ? value : Object.assign({}, o[part]);
74
- o[part] = no;
75
- o = no;
76
- }
77
-
78
- return ns;
79
- };
80
-
81
- _proto["delete"] = function _delete(state) {
82
- var ns = Object.assign({}, state);
83
- var o = ns;
84
- var part;
85
-
86
- for (var i = 0; i < this.parts.length - 1; i++) {
87
- part = this.parts[i];
88
- var no = Object.assign({}, o[part]);
89
- o[part] = no;
90
- o = no;
91
- }
92
-
93
- part = this.parts[this.parts.length - 1];
94
- if (!o.hasOwnProperty(part)) return state;
95
- delete o[part];
96
- return ns;
97
- };
98
-
99
- Binding.get = function get(path) {
100
- if (isString(path)) {
101
- var b = bindingCache[path];
102
- if (b) return b;
103
- b = new Binding(path);
104
- bindingCache[path] = b;
105
- return b;
106
- }
107
-
108
- if (isObject(path) && isString(path.bind)) return this.get(path.bind);
109
- if (path instanceof Binding) return path;
110
- if (isAccessorChain(path)) return this.get(path.toString());
111
- throw new Error("Invalid binding definition provided.");
112
- };
113
-
114
- return Binding;
115
- })();
116
- function isBinding(value) {
117
- if (isObject(value) && isString(value.bind)) return true;
118
- if (value && value.isAccessorChain) return true;
119
- return value instanceof Binding;
120
- }
121
-
122
- function _defineProperty(obj, key, value) {
123
- if (key in obj) {
124
- Object.defineProperty(obj, key, {
125
- value: value,
126
- enumerable: true,
127
- configurable: true,
128
- writable: true
129
- });
130
- } else {
131
- obj[key] = value;
132
- }
133
-
134
- return obj;
135
- }
136
-
137
- function ownKeys(object, enumerableOnly) {
138
- var keys = Object.keys(object);
139
-
140
- if (Object.getOwnPropertySymbols) {
141
- var symbols = Object.getOwnPropertySymbols(object);
142
- if (enumerableOnly)
143
- symbols = symbols.filter(function(sym) {
144
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
145
- });
146
- keys.push.apply(keys, symbols);
147
- }
148
-
149
- return keys;
150
- }
151
-
152
- function _objectSpread2(target) {
153
- for (var i = 1; i < arguments.length; i++) {
154
- var source = arguments[i] != null ? arguments[i] : {};
155
-
156
- if (i % 2) {
157
- ownKeys(Object(source), true).forEach(function(key) {
158
- _defineProperty(target, key, source[key]);
159
- });
160
- } else if (Object.getOwnPropertyDescriptors) {
161
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
162
- } else {
163
- ownKeys(Object(source)).forEach(function(key) {
164
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
165
- });
166
- }
167
- }
168
-
169
- return target;
170
- }
171
-
172
- function _inheritsLoose(subClass, superClass) {
173
- subClass.prototype = Object.create(superClass.prototype);
174
- subClass.prototype.constructor = subClass;
175
-
176
- _setPrototypeOf(subClass, superClass);
177
- }
178
-
179
- function _setPrototypeOf(o, p) {
180
- _setPrototypeOf =
181
- Object.setPrototypeOf ||
182
- function _setPrototypeOf(o, p) {
183
- o.__proto__ = p;
184
- return o;
185
- };
186
-
187
- return _setPrototypeOf(o, p);
188
- }
189
-
190
- function _isNativeReflectConstruct() {
191
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
192
- if (Reflect.construct.sham) return false;
193
- if (typeof Proxy === "function") return true;
194
-
195
- try {
196
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
197
- return true;
198
- } catch (e) {
199
- return false;
200
- }
201
- }
202
-
203
- function _construct(Parent, args, Class) {
204
- if (_isNativeReflectConstruct()) {
205
- _construct = Reflect.construct;
206
- } else {
207
- _construct = function _construct(Parent, args, Class) {
208
- var a = [null];
209
- a.push.apply(a, args);
210
- var Constructor = Function.bind.apply(Parent, a);
211
- var instance = new Constructor();
212
- if (Class) _setPrototypeOf(instance, Class.prototype);
213
- return instance;
214
- };
215
- }
216
-
217
- return _construct.apply(null, arguments);
218
- }
219
-
220
- function _assertThisInitialized(self) {
221
- if (self === void 0) {
222
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
223
- }
224
-
225
- return self;
226
- }
227
-
228
- function computable() {
229
- var _ref;
230
-
231
- if (arguments.length == 0)
232
- throw new Error("computable requires at least a compute function to be passed in arguments.");
233
- var compute = ((_ref = arguments.length - 1), _ref < 0 || arguments.length <= _ref ? undefined : arguments[_ref]);
234
- if (typeof compute != "function") throw new Error("Last argument to the computable function should be a function.");
235
- var inputs = [],
236
- a;
237
-
238
- for (var i = 0; i + 1 < arguments.length; i++) {
239
- a = i < 0 || arguments.length <= i ? undefined : arguments[i];
240
- if (isString(a) || isAccessorChain(a)) inputs.push(Binding.get(a.toString()).value);
241
- else if (a.memoize) inputs.push(a.memoize());
242
- else if (isFunction(a)) inputs.push(a);
243
- else throw new Error("Invalid selector type '" + typeof a + "' received.");
244
- }
245
-
246
- function memoize(warmupData) {
247
- var lastValue,
248
- lastArgs =
249
- warmupData &&
250
- inputs.map(function(s) {
251
- return s(warmupData);
252
- });
253
- return function(data) {
254
- var dirty = false;
255
-
256
- if (!lastArgs) {
257
- lastArgs = Array.from({
258
- length: inputs.length
259
- });
260
- dirty = true;
261
- }
262
-
263
- for (var _i = 0; _i < inputs.length; _i++) {
264
- var v = inputs[_i](data);
265
-
266
- if (v === lastArgs[_i]) continue;
267
- lastArgs[_i] = v;
268
- dirty = true;
269
- }
270
-
271
- if (dirty) lastValue = compute.apply(null, lastArgs);
272
- return lastValue;
273
- };
274
- }
275
-
276
- var selector = function selector(data) {
277
- return compute.apply(
278
- null,
279
- inputs.map(function(s) {
280
- return s(data);
281
- })
282
- );
283
- };
284
-
285
- selector.memoize = memoize;
286
- return selector;
287
- }
288
-
289
- /*
290
- Helper usage example
291
-
292
- Expression.registerHelper('_', _);
293
- let e = Expression.compile('_.min({data})');
294
- */
295
-
296
- var expCache = {},
297
- helpers = {},
298
- helperNames = [],
299
- helperValues = [],
300
- expFatArrows = null;
301
-
302
- function getExpr(expr) {
303
- if (expr.memoize) return expr;
304
-
305
- function memoize() {
306
- var lastValue,
307
- lastRunBindings = {},
308
- lastRunResults = {},
309
- getters = {},
310
- currentData,
311
- len = -1;
312
-
313
- var get = function get(bindingWithFormat) {
314
- var getter = getters[bindingWithFormat];
315
-
316
- if (!getter) {
317
- var binding = bindingWithFormat,
318
- format;
319
- var colonIndex = bindingWithFormat.indexOf(":");
320
-
321
- if (colonIndex != -1) {
322
- format = Format.parse(bindingWithFormat.substring(colonIndex + 1));
323
- binding = bindingWithFormat.substring(0, colonIndex);
324
- } else {
325
- var nullSeparatorIndex = bindingWithFormat.indexOf(":");
326
-
327
- if (nullSeparatorIndex != -1) {
328
- format = Format.parse(bindingWithFormat.substring(nullSeparatorIndex));
329
- binding = bindingWithFormat.substring(0, nullSeparatorIndex - 1);
330
- }
331
- }
332
-
333
- var b = Binding.get(binding);
334
-
335
- getter = function getter(data) {
336
- var value = b.value(data);
337
- lastRunBindings[len] = b.value;
338
- lastRunResults[len] = value;
339
- len++;
340
- return value;
341
- };
342
-
343
- if (format) {
344
- var valueGetter = getter;
345
-
346
- getter = function getter(data) {
347
- return format(valueGetter(data));
348
- };
349
- }
350
-
351
- getters[bindingWithFormat] = getter;
352
- }
353
-
354
- return getter(currentData);
355
- };
356
-
357
- return function(data) {
358
- var i = 0;
359
-
360
- for (; i < len; i++) {
361
- if (lastRunBindings[i](data) !== lastRunResults[i]) break;
362
- }
363
-
364
- if (i !== len) {
365
- len = 0;
366
- currentData = data;
367
- lastValue = expr(get);
368
- }
369
-
370
- return lastValue;
371
- };
372
- }
373
-
374
- var result = memoize();
375
- result.memoize = memoize;
376
- return result;
377
- }
378
-
379
- function expression(str) {
380
- if (isFunction(str)) return getExpr(str);
381
- var r = expCache[str];
382
- if (r) return r;
383
- var quote = false;
384
- var termStart = -1,
385
- curlyBrackets = 0,
386
- percentExpression;
387
- var fb = ["return ("];
388
- var args = {};
389
- var formats = [];
390
- var subExpr = 0;
391
-
392
- for (var i = 0; i < str.length; i++) {
393
- var c = str[i];
394
-
395
- switch (c) {
396
- case "{":
397
- if (curlyBrackets > 0) curlyBrackets++;
398
- else {
399
- if (!quote && termStart < 0 && (str[i + 1] != "{" || str[i - 1] == "%")) {
400
- termStart = i + 1;
401
- curlyBrackets = 1;
402
- percentExpression = str[i - 1] == "%";
403
- if (percentExpression) fb.pop(); //%
404
- } else if (str[i - 1] != "{") fb.push(c);
405
- }
406
- break;
407
-
408
- case "}":
409
- if (termStart >= 0) {
410
- if (--curlyBrackets == 0) {
411
- var term = str.substring(termStart, i);
412
- var formatStart = 0;
413
- if (term[0] == "[") formatStart = term.indexOf("]");
414
- var colon = term.indexOf(":", formatStart > 0 ? formatStart : 0);
415
- var binding = colon == -1 ? term : term.substring(0, colon);
416
- var format = colon == -1 ? null : term.substring(colon + 1);
417
-
418
- if (colon == -1) {
419
- var nullSepIndex = binding.indexOf("|", formatStart);
420
-
421
- if (nullSepIndex != -1) {
422
- format = binding.substring(nullSepIndex);
423
- binding = binding.substring(0, nullSepIndex);
424
- }
425
- }
426
-
427
- var argName = binding.replace(/\./g, "_");
428
- if (isDigit(argName[0])) argName = "$" + argName;
429
-
430
- if (percentExpression || (binding[0] == "[" && binding[binding.length - 1] == "]")) {
431
- argName = "expr" + ++subExpr;
432
- args[argName] = expression(percentExpression ? binding : binding.substring(1, binding.length - 1));
433
- } else args[argName] = binding;
434
-
435
- if (format) {
436
- var formatter = "fmt" + formats.length;
437
- fb.push(formatter, "(", argName, ", ", quoteStr(format), ")");
438
- formats.push(Format.parse(format));
439
- } else fb.push(argName);
440
-
441
- termStart = -1;
442
- }
443
- } else fb.push(c);
444
-
445
- break;
446
-
447
- case '"':
448
- case "'":
449
- if (curlyBrackets == 0) {
450
- if (!quote) quote = c;
451
- else if (str[i - 1] != "\\" && quote == c) quote = false;
452
- fb.push(c);
453
- }
454
-
455
- break;
456
-
457
- default:
458
- if (termStart < 0) fb.push(c);
459
- break;
460
- }
461
- }
462
-
463
- fb.push(")");
464
- var body = fb.join("");
465
- if (expFatArrows) body = expFatArrows(body); //console.log(body);
466
-
467
- var keys = Object.keys(args);
468
-
469
- try {
470
- var _Function;
471
-
472
- var compute = (_Function = _construct(
473
- Function,
474
- formats
475
- .map(function(f, i) {
476
- return "fmt" + i;
477
- })
478
- .concat(keys, helperNames, [body])
479
- )).bind.apply(_Function, [Format].concat(formats, helperValues));
480
-
481
- var selector = computable.apply(
482
- void 0,
483
- keys
484
- .map(function(k) {
485
- return args[k];
486
- })
487
- .concat([compute])
488
- );
489
- expCache[str] = selector;
490
- return selector;
491
- } catch (err) {
492
- throw new Error("Failed to parse expression: '" + str + "'. Error: " + err.message);
493
- }
494
- }
495
- var Expression = {
496
- get: function get(str) {
497
- return expression(str);
498
- },
499
- compile: function compile(str) {
500
- return this.get(str).memoize();
501
- },
502
- registerHelper: function registerHelper(name, helper) {
503
- helpers[name] = helper;
504
- helperNames = Object.keys(helpers);
505
- helperValues = helperNames.map(function(n) {
506
- return helpers[n];
507
- });
508
- }
509
- };
510
- function plugFatArrowExpansion(impl) {
511
- expFatArrows = impl;
512
- }
513
- function invalidateExpressionCache() {
514
- expCache = {};
515
- }
516
-
517
- function plus(str) {
518
- return str.length ? str + " + " : str;
519
- }
520
-
521
- var tplCache = {};
522
- function stringTemplate(str) {
523
- var expr = tplCache[str];
524
- if (expr) return expr;
525
- expr = "";
526
- var termStart = -1,
527
- quoteStart = 0,
528
- term,
529
- bracketsOpen = 0,
530
- percentSign;
531
-
532
- for (var i = 0; i < str.length; i++) {
533
- var c = str[i];
534
-
535
- switch (c) {
536
- case "{":
537
- if (termStart < 0) {
538
- if (str[i + 1] == "{" && str[i - 1] != "%") {
539
- expr = plus(expr) + quoteStr(str.substring(quoteStart, i) + "{");
540
- i++;
541
- quoteStart = i + 1;
542
- } else {
543
- termStart = i + 1;
544
- percentSign = str[i - 1] == "%";
545
- if (i > quoteStart) expr = plus(expr) + quoteStr(str.substring(quoteStart, percentSign ? i - 1 : i));
546
- bracketsOpen = 1;
547
- }
548
- } else bracketsOpen++;
549
-
550
- break;
551
-
552
- case "}":
553
- if (termStart >= 0) {
554
- if (--bracketsOpen == 0) {
555
- term = str.substring(termStart, i);
556
-
557
- if (term.indexOf(":") == -1) {
558
- var nullSepIndex = term.indexOf("|");
559
- if (nullSepIndex == -1) term += ":s";
560
- else term = term.substring(0, nullSepIndex) + ":s" + term.substring(nullSepIndex);
561
- }
562
-
563
- expr = plus(expr) + (percentSign ? "%{" : "{") + term + "}";
564
- termStart = -1;
565
- quoteStart = i + 1;
566
- bracketsOpen = 0;
567
- }
568
- } else if (str[i + 1] == "}") {
569
- expr = plus(expr) + quoteStr(str.substring(quoteStart, i) + "}");
570
- i++;
571
- quoteStart = i + 1;
572
- }
573
-
574
- break;
575
- }
576
- }
577
-
578
- if (quoteStart < str.length) expr = plus(expr) + quoteStr(str.substring(quoteStart)); //console.log(expr);
579
-
580
- return (tplCache[str] = expression(expr));
581
- }
582
- var StringTemplate = {
583
- get: function get(str) {
584
- return stringTemplate(str);
585
- },
586
- compile: function compile(str) {
587
- return stringTemplate(str).memoize();
588
- },
589
- format: function format(_format) {
590
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
591
- args[_key - 1] = arguments[_key];
592
- }
593
-
594
- return stringTemplate(_format)(args);
595
- }
596
- };
597
- function invalidateStringTemplateCache() {
598
- tplCache = {};
599
- }
600
-
601
- var Ref = /*#__PURE__*/ (function(_Component) {
602
- _inheritsLoose(Ref, _Component);
603
-
604
- function Ref(config) {
605
- var _this;
606
-
607
- _this = _Component.call(this, config) || this;
608
- _this.get = _this.get.bind(_assertThisInitialized(_this));
609
- if (_this.set) _this.set = _this.set.bind(_assertThisInitialized(_this));
610
- return _this;
611
- }
612
-
613
- var _proto = Ref.prototype;
614
-
615
- _proto.get = function get() {
616
- throw new Error("Ref's get method is not implemented.");
617
- };
618
-
619
- _proto.init = function init(value) {
620
- if (this.get() === undefined) this.set(value);
621
- };
622
-
623
- _proto.toggle = function toggle() {
624
- this.set(!this.get());
625
- };
626
-
627
- _proto.update = function update(cb) {
628
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
629
- args[_key - 1] = arguments[_key];
630
- }
631
-
632
- this.set(cb.apply(void 0, [this.get()].concat(args)));
633
- };
634
-
635
- _proto.as = function as(config) {
636
- return Ref.create(config, {
637
- get: this.get,
638
- set: this.set
639
- });
640
- };
641
-
642
- _proto.ref = function ref(path) {
643
- var _this2 = this;
644
-
645
- var binding = Binding.get(path);
646
- return Ref.create({
647
- get: function get() {
648
- return binding.value(_this2.get());
649
- },
650
- set: function set(value) {
651
- var data = _this2.get();
652
-
653
- var newData = binding.set(data, value);
654
- if (data === newData) return false;
655
- return _this2.set(newData);
656
- }
657
- });
658
- }; //allows the function to be passed as a selector, e.g. to computable or addTrigger
659
-
660
- _proto.memoize = function memoize() {
661
- return this.get;
662
- };
663
-
664
- return Ref;
665
- })(Component);
666
- Ref.prototype.isRef = true;
667
-
668
- Ref.factory = function(alias, config, more) {
669
- if (isFunction(alias)) {
670
- var cfg = _objectSpread2(_objectSpread2({}, config), more);
671
-
672
- if (cfg.store) Object.assign(cfg, cfg.store.getMethods());
673
- var result = alias(cfg);
674
- if (result instanceof Ref) return result;
675
- return this.create(_objectSpread2(_objectSpread2(_objectSpread2({}, config), more), result));
676
- }
677
-
678
- return this.create(_objectSpread2(_objectSpread2({}, config), more));
679
- };
680
-
681
- var StoreRef = /*#__PURE__*/ (function(_Ref) {
682
- _inheritsLoose(StoreRef, _Ref);
683
-
684
- function StoreRef(config) {
685
- var _this;
686
-
687
- _this = _Ref.call(this, config) || this;
688
- if (isAccessorChain(_this.path)) _this.path = _this.path.toString();
689
- return _this;
690
- }
691
-
692
- var _proto = StoreRef.prototype;
693
-
694
- _proto.get = function get() {
695
- return this.store.get(this.path);
696
- };
697
-
698
- _proto.set = function set(value) {
699
- return this.store.set(this.path, value);
700
- };
701
-
702
- _proto.init = function init(value) {
703
- return this.store.init(this.path, value);
704
- };
705
-
706
- _proto.toggle = function toggle() {
707
- return this.store.toggle(this.path);
708
- };
709
-
710
- _proto["delete"] = function _delete() {
711
- return this.store["delete"](this.path);
712
- };
713
-
714
- _proto.update = function update() {
715
- var _this$store;
716
-
717
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
718
- args[_key] = arguments[_key];
719
- }
720
-
721
- return (_this$store = this.store).update.apply(_this$store, [this.path].concat(args));
722
- }; //allows the function to be passed as a selector, e.g. to computable or addTrigger
723
-
724
- _proto.memoize = function memoize() {
725
- return this.get;
726
- };
727
-
728
- _proto.ref = function ref(path) {
729
- return new StoreRef({
730
- path: this.path + "." + path,
731
- store: this.store
732
- });
733
- };
734
-
735
- _proto.as = function as(config) {
736
- return StoreRef.create(config, {
737
- path: this.path,
738
- store: this.store,
739
- get: this.get,
740
- set: this.set
741
- });
742
- };
743
-
744
- return StoreRef;
745
- })(Ref);
746
-
747
- var View = /*#__PURE__*/ (function() {
748
- function View(config) {
749
- Object.assign(this, config);
750
- this.cache = {
751
- version: -1
752
- };
753
- if (this.store) this.setStore(this.store);
754
- }
755
-
756
- var _proto = View.prototype;
757
-
758
- _proto.getData = function getData() {
759
- throw new Error("abstract method");
760
- };
761
-
762
- _proto.init = function init(path, value) {
763
- if (typeof path == "object" && path != null) {
764
- var changed = false;
765
-
766
- for (var key in path) {
767
- if (path.hasOwnProperty(key) && this.get(key) === undefined && this.setItem(key, path[key])) changed = true;
768
- }
769
-
770
- return changed;
771
- }
772
-
773
- var binding = Binding.get(path);
774
- if (this.get(binding.path) === undefined) return this.setItem(binding.path, value);
775
- return false;
776
- };
777
-
778
- _proto.set = function set(path, value) {
779
- if (isObject(path)) {
780
- var changed = false;
781
-
782
- for (var key in path) {
783
- if (path.hasOwnProperty(key) && this.setItem(key, path[key])) changed = true;
784
- }
785
-
786
- return changed;
787
- }
788
-
789
- var binding = Binding.get(path);
790
- return this.setItem(binding.path, value);
791
- };
792
-
793
- _proto.copy = function copy(from, to) {
794
- var value = this.get(from);
795
- this.set(to, value);
796
- };
797
-
798
- _proto.move = function move(from, to) {
799
- var _this = this;
800
-
801
- this.batch(function() {
802
- _this.copy(from, to);
803
-
804
- _this["delete"](from);
805
- });
806
- }; //protected
807
-
808
- _proto.setItem = function setItem(path, value) {
809
- if (this.store) return this.store.setItem(path, value);
810
- throw new Error("abstract method");
811
- };
812
-
813
- _proto["delete"] = function _delete(path) {
814
- var _this2 = this;
815
-
816
- if (arguments.length > 1) path = Array.from(arguments);
817
- if (isArray(path))
818
- return path
819
- .map(function(arg) {
820
- return _this2["delete"](arg);
821
- })
822
- .some(Boolean);
823
- var binding = Binding.get(path);
824
- return this.deleteItem(binding.path);
825
- }; //protected
826
-
827
- _proto.deleteItem = function deleteItem(path) {
828
- if (this.store) return this.store.deleteItem(path);
829
- throw new Error("abstract method");
830
- };
831
-
832
- _proto.clear = function clear() {
833
- if (this.store) return this.store.clear();
834
- throw new Error("abstract method");
835
- };
836
-
837
- _proto.get = function get(path) {
838
- var storeData = this.getData();
839
- if (arguments.length > 1) path = Array.from(arguments);
840
- if (isArray(path))
841
- return path.map(function(arg) {
842
- return Binding.get(arg).value(storeData);
843
- });
844
- return Binding.get(path).value(storeData);
845
- };
846
-
847
- _proto.toggle = function toggle(path) {
848
- return this.set(path, !this.get(path));
849
- };
850
-
851
- _proto.update = function update(path, updateFn) {
852
- for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
853
- args[_key - 2] = arguments[_key];
854
- }
855
-
856
- if (arguments.length == 1 && isFunction(path))
857
- return this.load(path.apply(null, [this.getData(), updateFn].concat(args)));
858
- return this.set(path, updateFn.apply(null, [this.get(path)].concat(args)));
859
- };
860
-
861
- _proto.batch = function batch(callback) {
862
- var dirty = this.silently(callback);
863
- if (dirty) this.notify();
864
- return dirty;
865
- };
866
-
867
- _proto.silently = function silently(callback) {
868
- if (this.store) return this.store.silently(callback);
869
- throw new Error("abstract method");
870
- };
871
-
872
- _proto.notify = function notify(path) {
873
- if (this.notificationsSuspended) this.dirty = true;
874
- else this.doNotify(path);
875
- };
876
-
877
- _proto.doNotify = function doNotify(path) {
878
- if (this.store) return this.store.notify(path);
879
- throw new Error("abstract method");
880
- };
881
-
882
- _proto.subscribe = function subscribe(callback) {
883
- if (this.store) return this.store.subscribe(callback);
884
- throw new Error("abstract method");
885
- };
886
-
887
- _proto.load = function load(data) {
888
- return this.batch(function(store) {
889
- for (var key in data) {
890
- store.set(key, data[key]);
891
- }
892
- });
893
- };
894
-
895
- _proto.dispatch = function dispatch(action) {
896
- if (this.store) return this.store.dispatch(action);
897
- throw new Error("The underlying store doesn't support dispatch.");
898
- };
899
-
900
- _proto.getMeta = function getMeta() {
901
- return this.meta;
902
- };
903
-
904
- _proto.setStore = function setStore(store) {
905
- this.store = store;
906
- this.meta = store.getMeta();
907
- };
908
-
909
- _proto.ref = function ref(path, defaultValue) {
910
- if (isDefined(defaultValue)) this.init(path, defaultValue);
911
- return StoreRef.create({
912
- store: this,
913
- path: path
914
- });
915
- };
916
-
917
- _proto.getMethods = function getMethods() {
918
- return {
919
- getData: this.getData.bind(this),
920
- set: this.set.bind(this),
921
- get: this.get.bind(this),
922
- update: this.update.bind(this),
923
- delete: this["delete"].bind(this),
924
- toggle: this.toggle.bind(this),
925
- init: this.init.bind(this),
926
- ref: this.ref.bind(this),
927
- mutate: this.ref.bind(this)
928
- };
929
- };
930
-
931
- return View;
932
- })();
933
- View.prototype.sealed = false; //indicate that data should be copied before virtual items are added
934
- //Immer integration point
935
-
936
- View.prototype.mutate = function() {
937
- throw new Error(
938
- "Mutate requires Immer. Please install 'immer' and 'cx-immer' packages and enable store mutation by calling enableImmerMutate()."
939
- );
940
- };
941
-
942
- var SubscribableView = /*#__PURE__*/ (function(_View) {
943
- _inheritsLoose(SubscribableView, _View);
944
-
945
- function SubscribableView(config) {
946
- var _this;
947
-
948
- _this = _View.call(this, config) || this;
949
- _this.subscribers = new SubscriberList();
950
- _this.changes = [];
951
- return _this;
952
- }
953
-
954
- var _proto = SubscribableView.prototype;
955
-
956
- _proto.subscribe = function subscribe(callback) {
957
- return this.subscribers.subscribe(callback);
958
- };
959
-
960
- _proto.unsubscribeAll = function unsubscribeAll() {
961
- this.subscribers.clear();
962
- };
963
-
964
- _proto.doNotify = function doNotify(path) {
965
- var _this2 = this;
966
-
967
- if (this.notificationsSuspended) return;
968
-
969
- if (!this.async) {
970
- this.subscribers.notify([path]);
971
- } else {
972
- this.changes.push(path || "");
973
-
974
- if (!this.scheduled) {
975
- this.scheduled = true;
976
- setTimeout(function() {
977
- _this2.scheduled = false;
978
- var changes = _this2.changes;
979
- _this2.changes = [];
980
-
981
- _this2.subscribers.notify(changes);
982
- }, 0);
983
- }
984
- }
985
- };
986
-
987
- _proto.silently = function silently(callback) {
988
- this.notificationsSuspended = (this.notificationsSuspended || 0) + 1;
989
- var wasDirty = this.dirty,
990
- dirty;
991
- this.dirty = false;
992
-
993
- try {
994
- callback(this);
995
- } finally {
996
- this.notificationsSuspended--;
997
- dirty = this.dirty;
998
- this.dirty = wasDirty;
999
- }
1000
-
1001
- return dirty;
1002
- };
1003
-
1004
- return SubscribableView;
1005
- })(View);
1006
- SubscribableView.prototype.async = false;
1007
-
1008
- var Store = /*#__PURE__*/ (function(_SubscribableView) {
1009
- _inheritsLoose(Store, _SubscribableView);
1010
-
1011
- function Store(config) {
1012
- var _this;
1013
-
1014
- if (config === void 0) {
1015
- config = {};
1016
- }
1017
-
1018
- _this = _SubscribableView.call(this, config) || this;
1019
- _this.data = config.data || {};
1020
- _this.meta = {
1021
- version: 0
1022
- };
1023
- return _this;
1024
- }
1025
-
1026
- var _proto = Store.prototype;
1027
-
1028
- _proto.getData = function getData() {
1029
- return this.data;
1030
- };
1031
-
1032
- _proto.setItem = function setItem(path, value) {
1033
- var next = Binding.get(path).set(this.data, value);
1034
-
1035
- if (next != this.data) {
1036
- this.data = next;
1037
- this.meta.version++;
1038
- this.notify(path);
1039
- return true;
1040
- }
1041
-
1042
- return false;
1043
- };
1044
-
1045
- _proto.deleteItem = function deleteItem(path) {
1046
- var next = Binding.get(path)["delete"](this.data);
1047
-
1048
- if (next != this.data) {
1049
- this.data = next;
1050
- this.meta.version++;
1051
- this.notify(path);
1052
- return true;
1053
- }
1054
-
1055
- return false;
1056
- };
1057
-
1058
- _proto.clear = function clear() {
1059
- this.data = {};
1060
- this.meta.version++;
1061
- this.notify();
1062
- };
1063
-
1064
- return Store;
1065
- })(SubscribableView);
1066
- Store.prototype.async = false;
1067
-
1068
- var ExposedRecordView = /*#__PURE__*/ (function(_View) {
1069
- _inheritsLoose(ExposedRecordView, _View);
1070
-
1071
- function ExposedRecordView() {
1072
- return _View.apply(this, arguments) || this;
1073
- }
1074
-
1075
- var _proto = ExposedRecordView.prototype;
1076
-
1077
- _proto.getData = function getData() {
1078
- if (this.sealed && this.meta.version === this.cache.version && this.cache.itemIndex === this.itemIndex)
1079
- return this.cache.result;
1080
- this.cache.result = this.embed(this.store.getData());
1081
- this.cache.version = this.meta.version;
1082
- this.cache.itemIndex = this.itemIndex;
1083
- return this.cache.result;
1084
- };
1085
-
1086
- _proto.embed = function embed(data) {
1087
- var collection = this.collectionBinding.value(data);
1088
- var record = collection[this.itemIndex];
1089
- var copy = this.sealed || this.immutable || this.store.sealed ? _objectSpread2({}, data) : data;
1090
- copy[this.recordName] = record;
1091
- if (this.indexName) copy[this.indexName] = this.itemIndex;
1092
- return copy;
1093
- };
1094
-
1095
- _proto.setIndex = function setIndex(index) {
1096
- this.itemIndex = index;
1097
- };
1098
-
1099
- _proto.setItem = function setItem(path, value) {
1100
- if (path == this.recordName || path.indexOf(this.recordName + ".") == 0) {
1101
- var storeData = this.store.getData();
1102
- var collection = this.collectionBinding.value(storeData);
1103
- var data = this.embed(storeData);
1104
- var d = Binding.get(path).set(data, value);
1105
- if (d === data) return false;
1106
- var record = d[this.recordName];
1107
- var newCollection = [].concat(
1108
- collection.slice(0, this.itemIndex),
1109
- [record],
1110
- collection.slice(this.itemIndex + 1)
1111
- );
1112
- return this.store.setItem(this.collectionBinding.path, newCollection);
1113
- }
1114
-
1115
- return this.store.setItem(path, value);
1116
- };
1117
-
1118
- _proto.deleteItem = function deleteItem(path) {
1119
- var storeData, collection, newCollection;
1120
-
1121
- if (path == this.recordName) {
1122
- storeData = this.store.getData();
1123
- collection = this.collectionBinding.value(storeData);
1124
- newCollection = [].concat(collection.slice(0, this.itemIndex), collection.slice(this.itemIndex + 1));
1125
- return this.store.setItem(this.collectionBinding.path, newCollection);
1126
- } else if (path.indexOf(this.recordName + ".") == 0) {
1127
- storeData = this.store.getData();
1128
- collection = this.collectionBinding.value(storeData);
1129
- var data = this.embed(storeData);
1130
- var d = Binding.get(path)["delete"](data);
1131
- if (d === data) return false;
1132
- var record = d[this.recordName];
1133
- newCollection = [].concat(collection.slice(0, this.itemIndex), [record], collection.slice(this.itemIndex + 1));
1134
- return this.store.setItem(this.collectionBinding.path, newCollection);
1135
- }
1136
-
1137
- return this.store.deleteItem(path);
1138
- };
1139
-
1140
- return ExposedRecordView;
1141
- })(View);
1142
- ExposedRecordView.prototype.immutable = false;
1143
-
1144
- var ExposedValueView = /*#__PURE__*/ (function(_View) {
1145
- _inheritsLoose(ExposedValueView, _View);
1146
-
1147
- function ExposedValueView() {
1148
- return _View.apply(this, arguments) || this;
1149
- }
1150
-
1151
- var _proto = ExposedValueView.prototype;
1152
-
1153
- _proto.getData = function getData() {
1154
- if (this.sealed && this.meta.version === this.cache.version && this.cache.key === this.key)
1155
- return this.cache.result;
1156
- var data = this.store.getData();
1157
- var container = this.containerBinding.value(data) || {};
1158
- var record = container[this.key];
1159
- this.cache.version = this.meta.version;
1160
- this.cache.key = this.key;
1161
- this.cache.result = this.sealed || this.immutable || this.store.sealed ? _objectSpread2({}, data) : data;
1162
- this.cache.result[this.recordName] = record;
1163
- return this.cache.result;
1164
- };
1165
-
1166
- _proto.setKey = function setKey(key) {
1167
- this.key = key;
1168
- };
1169
-
1170
- _proto.getKey = function getKey() {
1171
- return this.key;
1172
- };
1173
-
1174
- _proto.setItem = function setItem(path, value) {
1175
- if (path == this.recordName || path.indexOf(this.recordName + ".") == 0) {
1176
- var data = this.getData();
1177
- var d = Binding.get(path).set(data, value);
1178
- if (d === data) return false;
1179
- var container = this.containerBinding.value(d);
1180
- var record = d[this.recordName];
1181
- var newContainer = Object.assign({}, container);
1182
- newContainer[this.key] = record;
1183
- return this.store.setItem(this.containerBinding.path, newContainer);
1184
- }
1185
-
1186
- return this.store.setItem(path, value);
1187
- };
1188
-
1189
- _proto.deleteItem = function deleteItem(path) {
1190
- var data, container, newContainer;
1191
-
1192
- if (path == this.recordName) {
1193
- data = this.getData();
1194
- container = this.containerBinding.value(data);
1195
- if (!container || !container.hasOwnProperty(path)) return false;
1196
- newContainer = Object.assign({}, container);
1197
- delete newContainer[this.key];
1198
- this.store.set(this.containerBinding.path, newContainer);
1199
- } else if (path.indexOf(this.recordName + ".") == 0) {
1200
- data = this.getData();
1201
- var d = Binding.get(path)["delete"](data);
1202
- if (d === data) return false;
1203
- container = this.containerBinding.value(d);
1204
- var record = d[this.recordName];
1205
- newContainer = Object.assign({}, container);
1206
- newContainer[this.key] = record;
1207
- return this.store.setItem(this.containerBinding.path, newContainer);
1208
- }
1209
-
1210
- return this.store.deleteItem(path);
1211
- };
1212
-
1213
- return ExposedValueView;
1214
- })(View);
1215
- ExposedValueView.prototype.immutable = false;
1216
-
1217
- var ReadOnlyDataView = /*#__PURE__*/ (function(_View) {
1218
- _inheritsLoose(ReadOnlyDataView, _View);
1219
-
1220
- function ReadOnlyDataView() {
1221
- return _View.apply(this, arguments) || this;
1222
- }
1223
-
1224
- var _proto = ReadOnlyDataView.prototype;
1225
-
1226
- _proto.getData = function getData() {
1227
- if (this.sealed && this.meta.version === this.cache.version && this.cache.data === this.data)
1228
- return this.cache.result;
1229
- var data = this.store.getData();
1230
- this.cache.result =
1231
- this.sealed || this.immutable || this.store.sealed
1232
- ? Object.assign({}, data, this.getAdditionalData(data))
1233
- : Object.assign(data, this.getAdditionalData(data));
1234
- this.cache.version = this.meta.version;
1235
- this.cache.data = this.data;
1236
- return this.cache.result;
1237
- };
1238
-
1239
- _proto.getAdditionalData = function getAdditionalData() {
1240
- return this.data;
1241
- };
1242
-
1243
- _proto.setData = function setData(data) {
1244
- this.data = data;
1245
- };
1246
-
1247
- return ReadOnlyDataView;
1248
- })(View);
1249
- ReadOnlyDataView.prototype.immutable = false;
1250
-
1251
- var AugmentedViewBase = /*#__PURE__*/ (function(_View) {
1252
- _inheritsLoose(AugmentedViewBase, _View);
1253
-
1254
- function AugmentedViewBase() {
1255
- return _View.apply(this, arguments) || this;
1256
- }
1257
-
1258
- var _proto = AugmentedViewBase.prototype;
1259
-
1260
- _proto.getData = function getData() {
1261
- if (this.meta.version === this.cache.version && this.sealed) return this.cache.result;
1262
- var parentStoreData = this.store.getData();
1263
- var result = this.getBaseData(parentStoreData);
1264
- this.embedAugmentData(result, parentStoreData);
1265
- this.cache.result = result;
1266
- this.cache.parentStoreData = parentStoreData;
1267
- this.cache.version = this.meta.version;
1268
- return this.cache.result;
1269
- };
1270
-
1271
- _proto.getBaseData = function getBaseData(parentStoreData) {
1272
- if (this.sealed || this.immutable || this.store.sealed) return _objectSpread2({}, parentStoreData);
1273
- return parentStoreData;
1274
- };
1275
-
1276
- _proto.embedAugmentData = function embedAugmentData(result, parentStoreData) {
1277
- throw new Error("abstract");
1278
- };
1279
-
1280
- _proto.isExtraKey = function isExtraKey(key) {
1281
- throw new Error("abstract");
1282
- };
1283
-
1284
- _proto.setExtraKeyValue = function setExtraKeyValue(key, value) {
1285
- throw new Error("abstract");
1286
- };
1287
-
1288
- _proto.deleteExtraKeyValue = function deleteExtraKeyValue(key) {
1289
- throw new Error("abstract");
1290
- };
1291
-
1292
- _proto.setItem = function setItem(path, value) {
1293
- var binding = Binding.get(path);
1294
-
1295
- if (this.isExtraKey(binding.parts[0])) {
1296
- var bindingRoot = binding.parts[0];
1297
- var newValue = value;
1298
-
1299
- if (binding.parts.length > 1) {
1300
- var data = {};
1301
- this.embedAugmentData(data, this.store.getData());
1302
- newValue = binding.set(data, value)[bindingRoot];
1303
- }
1304
-
1305
- return this.setExtraKeyValue(bindingRoot, newValue);
1306
- }
1307
-
1308
- return _View.prototype.setItem.call(this, path, value);
1309
- };
1310
-
1311
- _proto.deleteItem = function deleteItem(path) {
1312
- var binding = Binding.get(path);
1313
-
1314
- if (this.isExtraKey(binding.parts[0])) {
1315
- var bindingRoot = binding.parts[0];
1316
- if (binding.parts.length == 1) return this.deleteExtraKeyValue(bindingRoot);
1317
- var data = {};
1318
- this.embedAugmentData(data, this.store.getData());
1319
- var newValue = binding["delete"](data)[bindingRoot];
1320
- return this.setExtraKeyValue(bindingRoot, newValue);
1321
- }
1322
-
1323
- return _View.prototype.deleteItem.call(this, path);
1324
- };
1325
-
1326
- return AugmentedViewBase;
1327
- })(View);
1328
- AugmentedViewBase.prototype.immutable = false;
1329
-
1330
- var NestedDataView = /*#__PURE__*/ (function(_AugmentedViewBase) {
1331
- _inheritsLoose(NestedDataView, _AugmentedViewBase);
1332
-
1333
- function NestedDataView() {
1334
- return _AugmentedViewBase.apply(this, arguments) || this;
1335
- }
1336
-
1337
- var _proto = NestedDataView.prototype;
1338
-
1339
- _proto.embedAugmentData = function embedAugmentData(result, parentStoreData) {
1340
- if (this.nestedData) {
1341
- var nested = this.nestedData.getSelector()(parentStoreData);
1342
-
1343
- for (var key in nested) {
1344
- result[key] = nested[key];
1345
- }
1346
- }
1347
- };
1348
-
1349
- _proto.isExtraKey = function isExtraKey(key) {
1350
- return this.nestedData && this.nestedData.containsKey(key);
1351
- };
1352
-
1353
- _proto.setExtraKeyValue = function setExtraKeyValue(key, value) {
1354
- this.nestedData.setItem(key, value);
1355
- };
1356
-
1357
- _proto.deleteExtraKeyValue = function deleteExtraKeyValue(key) {
1358
- this.setExtraKeyValue(key, undefined);
1359
- };
1360
-
1361
- return NestedDataView;
1362
- })(AugmentedViewBase);
1363
-
1364
- var ZoomIntoPropertyView = /*#__PURE__*/ (function(_NestedDataView) {
1365
- _inheritsLoose(ZoomIntoPropertyView, _NestedDataView);
1366
-
1367
- function ZoomIntoPropertyView() {
1368
- return _NestedDataView.apply(this, arguments) || this;
1369
- }
1370
-
1371
- var _proto = ZoomIntoPropertyView.prototype;
1372
-
1373
- _proto.getBaseData = function getBaseData(parentStoreData) {
1374
- var x = this.binding.value(parentStoreData);
1375
- if (x != null && typeof x != "object") throw new Error("Zoomed value must be an object.");
1376
- return _objectSpread2({}, x);
1377
- };
1378
-
1379
- _proto.embedAugmentData = function embedAugmentData(result, parentStoreData) {
1380
- result[this.rootName] = parentStoreData;
1381
-
1382
- _NestedDataView.prototype.embedAugmentData.call(this, result, parentStoreData);
1383
- };
1384
-
1385
- _proto.setItem = function setItem(path, value) {
1386
- if (path.indexOf(this.rootName + ".") == 0) this.store.setItem(path.substring(this.rootName.length + 1), value);
1387
- else if (this.isExtraKey(Binding.get(path).parts[0])) _NestedDataView.prototype.setItem.call(this, path, value);
1388
- else _NestedDataView.prototype.setItem.call(this, this.binding.path + "." + path, value);
1389
- };
1390
-
1391
- _proto.deleteItem = function deleteItem(path) {
1392
- if (path.indexOf(this.rootName + ".") == 0) this.store.deleteItem(path.substring(this.rootName.length + 1));
1393
- else if (this.isExtraKey(Binding.get(path).parts[0])) _NestedDataView.prototype.deleteItem.call(this, path);
1394
- else _NestedDataView.prototype.deleteItem.call(this, this.binding.path + "." + path);
1395
- };
1396
-
1397
- return ZoomIntoPropertyView;
1398
- })(NestedDataView);
1399
- ZoomIntoPropertyView.prototype.rootName = "$root";
1400
-
1401
- function createStructuredSelector(selector, constants) {
1402
- var keys = Object.keys(selector);
1403
- if (keys.length == 0)
1404
- return function() {
1405
- return constants;
1406
- };
1407
-
1408
- function memoize() {
1409
- var lastResult = Object.assign({}, constants);
1410
- var memoizedSelectors = {};
1411
- keys.forEach(function(key) {
1412
- memoizedSelectors[key] = selector[key].memoize ? selector[key].memoize() : selector[key];
1413
- lastResult[key] = undefined;
1414
- });
1415
- return function(data) {
1416
- var result = lastResult,
1417
- k,
1418
- v,
1419
- i;
1420
-
1421
- for (i = 0; i < keys.length; i++) {
1422
- k = keys[i];
1423
- v = memoizedSelectors[k](data);
1424
-
1425
- if (result === lastResult) {
1426
- if (v === lastResult[k]) continue;
1427
- result = Object.assign({}, lastResult);
1428
- }
1429
-
1430
- result[k] = v;
1431
- }
1432
-
1433
- return (lastResult = result);
1434
- };
1435
- }
1436
-
1437
- function evaluate(data) {
1438
- var result = Object.assign({}, constants);
1439
-
1440
- for (var i = 0; i < keys.length; i++) {
1441
- result[keys[i]] = selector[keys[i]](data);
1442
- }
1443
-
1444
- return result;
1445
- }
1446
-
1447
- evaluate.memoize = memoize;
1448
- return evaluate;
1449
- }
1450
-
1451
- function isSelector(config) {
1452
- if (config == null) return true;
1453
-
1454
- switch (typeof config) {
1455
- case "object":
1456
- if (config.type || config.$type) return false;
1457
- return !!(config.bind || config.tpl || config.expr || config.get);
1458
-
1459
- case "function":
1460
- return true;
1461
-
1462
- case "string":
1463
- return true;
1464
-
1465
- case "number":
1466
- return true;
1467
-
1468
- case "boolean":
1469
- return true;
1470
- }
1471
-
1472
- return false;
1473
- }
1474
-
1475
- var undefinedF = function undefinedF() {
1476
- return undefined;
1477
- };
1478
-
1479
- var nullF = function nullF() {
1480
- return null;
1481
- };
1482
-
1483
- function getSelector(config) {
1484
- if (config === undefined) return undefinedF;
1485
- if (config === null) return nullF;
1486
-
1487
- switch (typeof config) {
1488
- case "object":
1489
- if (isArray(config)) {
1490
- var _selectors = config.map(function(x) {
1491
- return getSelector(x);
1492
- });
1493
-
1494
- return function(data) {
1495
- return _selectors.map(function(elementSelector) {
1496
- return elementSelector(data);
1497
- });
1498
- };
1499
- } //toString converts accessor chains to binding paths
1500
-
1501
- if (config.bind) return Binding.get(config.bind.toString()).value;
1502
- if (config.tpl) return StringTemplate.get(config.tpl);
1503
- if (config.expr) return Expression.get(config.expr);
1504
- if (config.get) return config.get;
1505
- var selectors = {};
1506
- var constants = {};
1507
-
1508
- for (var key in config) {
1509
- if (isSelector(config[key])) selectors[key] = getSelector(config[key]);
1510
- else constants[key] = config[key];
1511
- }
1512
-
1513
- return createStructuredSelector(selectors, constants);
1514
-
1515
- case "function":
1516
- if (isAccessorChain(config)) return Binding.get(config.toString()).value;
1517
- return config;
1518
-
1519
- default:
1520
- return function() {
1521
- return config;
1522
- };
1523
- }
1524
- }
1525
-
1526
- function defaultValue(pv) {
1527
- if (typeof pv == "object" && pv && pv.structured) return pv.defaultValue;
1528
- return pv;
1529
- }
1530
-
1531
- function getSelectorConfig(props, values, nameMap) {
1532
- var functions = {},
1533
- structures = {},
1534
- defaultValues = {},
1535
- constants,
1536
- p,
1537
- v,
1538
- pv,
1539
- constant = true;
1540
-
1541
- for (p in props) {
1542
- v = values[p];
1543
- pv = props[p];
1544
- if (isUndefined(v) && pv && (pv.bind || pv.tpl || pv.expr)) v = pv;
1545
-
1546
- if (v === null) {
1547
- if (!constants) constants = {};
1548
- constants[p] = null;
1549
- } else if (typeof v == "object") {
1550
- if (v.bind) {
1551
- if (isUndefined(v.defaultValue) && v != pv) v.defaultValue = defaultValue(pv);
1552
- if (isDefined(v.defaultValue)) defaultValues[v.bind] = v.defaultValue;
1553
- nameMap[p] = v.bind;
1554
- functions[p] = Binding.get(v.bind).value;
1555
- constant = false;
1556
- } else if (v.expr) {
1557
- functions[p] = Expression.get(v.expr);
1558
- constant = false;
1559
- } else if (v.get) {
1560
- functions[p] = v.get;
1561
- constant = false;
1562
- } else if (v.tpl) {
1563
- functions[p] = StringTemplate.get(v.tpl);
1564
- constant = false;
1565
- } else if (pv && typeof pv == "object" && pv.structured) {
1566
- if (isArray(v)) functions[p] = getSelector(v);
1567
- else {
1568
- var s = getSelectorConfig(v, v, {});
1569
- structures[p] = s;
1570
- Object.assign(defaultValues, s.defaultValues);
1571
- }
1572
- constant = false;
1573
- } else {
1574
- if (!constants) constants = {};
1575
- constants[p] = v;
1576
- }
1577
- } else if (isFunction(v)) {
1578
- if (isAccessorChain(v)) {
1579
- var path = v.toString();
1580
- nameMap[p] = path;
1581
- functions[p] = Binding.get(path).value;
1582
- } else functions[p] = v;
1583
-
1584
- constant = false;
1585
- } else {
1586
- if (isUndefined(v)) {
1587
- if (isUndefined(pv)) continue;
1588
- v = defaultValue(pv);
1589
- }
1590
-
1591
- if (isUndefined(v)) continue;
1592
- if (!constants) constants = {};
1593
- constants[p] = v;
1594
- }
1595
- }
1596
-
1597
- return {
1598
- functions: functions,
1599
- structures: structures,
1600
- defaultValues: defaultValues,
1601
- constants: constants,
1602
- constant: constant
1603
- };
1604
- }
1605
-
1606
- function createSelector(_ref) {
1607
- var functions = _ref.functions,
1608
- structures = _ref.structures,
1609
- constants = _ref.constants,
1610
- defaultValues = _ref.defaultValues;
1611
- var selector = {};
1612
-
1613
- for (var n in functions) {
1614
- selector[n] = functions[n];
1615
- }
1616
-
1617
- for (var _n in structures) {
1618
- selector[_n] = createSelector(structures[_n]);
1619
- }
1620
-
1621
- return createStructuredSelector(selector, constants);
1622
- }
1623
-
1624
- var StructuredSelector = /*#__PURE__*/ (function() {
1625
- function StructuredSelector(_ref2) {
1626
- var props = _ref2.props,
1627
- values = _ref2.values;
1628
- this.nameMap = {};
1629
- this.config = getSelectorConfig(props, values, this.nameMap);
1630
- }
1631
-
1632
- var _proto = StructuredSelector.prototype;
1633
-
1634
- _proto.init = function init(store) {
1635
- store.init(this.config.defaultValues);
1636
- };
1637
-
1638
- _proto.create = function create() {
1639
- var selector = createSelector(this.config);
1640
- if (selector.memoize) return selector.memoize();
1641
- return selector;
1642
- };
1643
-
1644
- _proto.createStoreSelector = function createStoreSelector() {
1645
- if (this.config.constant) {
1646
- var result = _objectSpread2({}, this.config.constants);
1647
-
1648
- return function() {
1649
- return result;
1650
- };
1651
- }
1652
-
1653
- var selector = this.create();
1654
- return function(store) {
1655
- return selector(store.getData());
1656
- };
1657
- };
1658
-
1659
- return StructuredSelector;
1660
- })();
1661
-
1662
- var AggregateFunction = /*#__PURE__*/ (function() {
1663
- function AggregateFunction() {}
1664
-
1665
- AggregateFunction.sum = function sum() {
1666
- return new Sum();
1667
- };
1668
-
1669
- AggregateFunction.avg = function avg() {
1670
- return new Avg();
1671
- };
1672
-
1673
- AggregateFunction.count = function count() {
1674
- return new Count();
1675
- };
1676
-
1677
- AggregateFunction.distinct = function distinct() {
1678
- return new Distinct();
1679
- };
1680
-
1681
- AggregateFunction.min = function min() {
1682
- return new Min();
1683
- };
1684
-
1685
- AggregateFunction.max = function max() {
1686
- return new Max();
1687
- };
1688
-
1689
- return AggregateFunction;
1690
- })();
1691
-
1692
- var Sum = /*#__PURE__*/ (function() {
1693
- function Sum() {}
1694
-
1695
- var _proto = Sum.prototype;
1696
-
1697
- _proto.process = function process(value) {
1698
- this.empty = false;
1699
- if (!isNaN(value)) this.result += value;
1700
- else this.invalid = true;
1701
- };
1702
-
1703
- _proto.getResult = function getResult() {
1704
- if (this.invalid) return null;
1705
- return this.result;
1706
- };
1707
-
1708
- return Sum;
1709
- })();
1710
-
1711
- Sum.prototype.result = 0;
1712
- Sum.prototype.empty = true;
1713
-
1714
- var Avg = /*#__PURE__*/ (function() {
1715
- function Avg() {}
1716
-
1717
- var _proto2 = Avg.prototype;
1718
-
1719
- _proto2.process = function process(value, count) {
1720
- if (count === void 0) {
1721
- count = 1;
1722
- }
1723
-
1724
- this.empty = false;
1725
-
1726
- if (!isNaN(value) && !isNaN(count)) {
1727
- this.result += value * count;
1728
- this.count += count;
1729
- } else this.invalid = true;
1730
- };
1731
-
1732
- _proto2.getResult = function getResult() {
1733
- if (this.empty || this.invalid || this.count == 0) return null;
1734
- return this.result / this.count;
1735
- };
1736
-
1737
- return Avg;
1738
- })();
1739
-
1740
- Avg.prototype.result = 0;
1741
- Avg.prototype.count = 0;
1742
- Avg.prototype.empty = true;
1743
-
1744
- var Count = /*#__PURE__*/ (function() {
1745
- function Count() {}
1746
-
1747
- var _proto3 = Count.prototype;
1748
-
1749
- _proto3.process = function process(value) {
1750
- if (value != null) this.result++;
1751
- };
1752
-
1753
- _proto3.getResult = function getResult() {
1754
- return this.result;
1755
- };
1756
-
1757
- return Count;
1758
- })();
1759
-
1760
- Count.prototype.result = 0;
1761
-
1762
- var Distinct = /*#__PURE__*/ (function() {
1763
- function Distinct() {
1764
- this.values = {};
1765
- }
1766
-
1767
- var _proto4 = Distinct.prototype;
1768
-
1769
- _proto4.process = function process(value) {
1770
- if (value == null || this.values[value]) return;
1771
- this.values[value] = true;
1772
- this.empty = false;
1773
- this.result++;
1774
- };
1775
-
1776
- _proto4.getResult = function getResult() {
1777
- if (this.empty || this.invalid) return null;
1778
- return this.result;
1779
- };
1780
-
1781
- return Distinct;
1782
- })();
1783
-
1784
- Distinct.prototype.result = 0;
1785
- Distinct.prototype.empty = true;
1786
-
1787
- var Max = /*#__PURE__*/ (function() {
1788
- function Max() {}
1789
-
1790
- var _proto5 = Max.prototype;
1791
-
1792
- _proto5.process = function process(value) {
1793
- if (!isNaN(value)) {
1794
- if (this.empty) this.result = value;
1795
- else if (value > this.result) this.result = value;
1796
- this.empty = false;
1797
- } else if (value != null) this.invalid = true;
1798
- };
1799
-
1800
- _proto5.getResult = function getResult() {
1801
- if (this.empty || this.invalid) return null;
1802
- return this.result;
1803
- };
1804
-
1805
- return Max;
1806
- })();
1807
-
1808
- Max.prototype.result = 0;
1809
- Max.prototype.empty = true;
1810
-
1811
- var Min = /*#__PURE__*/ (function() {
1812
- function Min() {}
1813
-
1814
- var _proto6 = Min.prototype;
1815
-
1816
- _proto6.process = function process(value) {
1817
- if (!isNaN(value)) {
1818
- if (this.empty) this.result = value;
1819
- else if (value < this.result) this.result = value;
1820
- this.empty = false;
1821
- } else if (value != null) this.invalid = true;
1822
- };
1823
-
1824
- _proto6.getResult = function getResult() {
1825
- if (this.empty || this.invalid) return null;
1826
- return this.result;
1827
- };
1828
-
1829
- return Min;
1830
- })();
1831
-
1832
- Min.prototype.result = 0;
1833
- Min.prototype.empty = true;
1834
-
1835
- /*
1836
- 'column': {
1837
- index: 0,
1838
- sort: 'asc',
1839
- group: true
1840
- aggregate: 'count'
1841
- }
1842
- */
1843
-
1844
- function transform(o, f) {
1845
- var res = {};
1846
-
1847
- for (var k in o) {
1848
- res[k] = f(o[k], k);
1849
- }
1850
-
1851
- return res;
1852
- }
1853
-
1854
- var Grouper = /*#__PURE__*/ (function() {
1855
- function Grouper(key, aggregates, dataGetter, nameGetter) {
1856
- this.keys = Object.keys(key).map(function(k) {
1857
- return {
1858
- name: k,
1859
- value: getSelector(key[k])
1860
- };
1861
- });
1862
- if (nameGetter) this.nameGetter = getSelector(nameGetter);
1863
-
1864
- this.dataGetter =
1865
- dataGetter ||
1866
- function(x) {
1867
- return x;
1868
- };
1869
-
1870
- this.aggregates =
1871
- aggregates &&
1872
- transform(aggregates, function(prop) {
1873
- if (!AggregateFunction[prop.type]) throw new Error("Unknown aggregate function '" + prop.type + "'.");
1874
- return {
1875
- value: getSelector(prop.value),
1876
- weight: getSelector(prop.weight || 1),
1877
- type: prop.type
1878
- };
1879
- });
1880
- this.reset();
1881
- }
1882
-
1883
- var _proto = Grouper.prototype;
1884
-
1885
- _proto.reset = function reset() {
1886
- this.groups = this.initGroup(this.keys.length == 0);
1887
- };
1888
-
1889
- _proto.initGroup = function initGroup(leaf) {
1890
- if (!leaf) return {};
1891
- return {
1892
- records: [],
1893
- indexes: [],
1894
- aggregates:
1895
- this.aggregates &&
1896
- transform(this.aggregates, function(prop) {
1897
- var f = AggregateFunction[prop.type];
1898
- return {
1899
- processor: f(),
1900
- value: prop.value,
1901
- weight: prop.weight
1902
- };
1903
- })
1904
- };
1905
- };
1906
-
1907
- _proto.process = function process(record, index) {
1908
- var data = this.dataGetter(record);
1909
- var key = this.keys.map(function(k) {
1910
- return k.value(data);
1911
- });
1912
- var g = this.groups;
1913
-
1914
- for (var i = 0; i < key.length; i++) {
1915
- var sg = g[key[i]];
1916
-
1917
- if (!sg) {
1918
- sg = g[key[i]] = this.initGroup(i + 1 == key.length);
1919
- if (this.nameGetter) sg.name = this.nameGetter(data);
1920
- }
1921
-
1922
- g = sg;
1923
- }
1924
-
1925
- g.records.push(record);
1926
- g.indexes.push(index);
1927
-
1928
- if (g.aggregates) {
1929
- for (var k in g.aggregates) {
1930
- g.aggregates[k].processor.process(g.aggregates[k].value(data), g.aggregates[k].weight(data));
1931
- }
1932
- }
1933
- };
1934
-
1935
- _proto.processAll = function processAll(records, indexes) {
1936
- var _this = this;
1937
-
1938
- if (indexes) {
1939
- for (var i = 0; i < records.length; i++) {
1940
- this.process(records[i], indexes[i]);
1941
- }
1942
- } else
1943
- records.forEach(function(r, i) {
1944
- return _this.process(r, i);
1945
- });
1946
- };
1947
-
1948
- _proto.report = function report(g, path, level, results) {
1949
- var _this2 = this;
1950
-
1951
- if (level == this.keys.length) {
1952
- var key = {};
1953
- this.keys.forEach(function(k, i) {
1954
- return (key[k.name] = path[i]);
1955
- });
1956
- results.push({
1957
- key: key,
1958
- name: g.name,
1959
- records: g.records,
1960
- indexes: g.indexes,
1961
- aggregates: transform(g.aggregates, function(p) {
1962
- return p.processor.getResult();
1963
- })
1964
- });
1965
- } else {
1966
- Object.keys(g).forEach(function(k) {
1967
- return _this2.report(g[k], [].concat(path, [k]), level + 1, results);
1968
- });
1969
- }
1970
- };
1971
-
1972
- _proto.getResults = function getResults() {
1973
- var g = this.groups;
1974
- var results = [];
1975
- this.report(g, [], 0, results);
1976
- return results;
1977
- };
1978
-
1979
- return Grouper;
1980
- })();
1981
-
1982
- function defaultCompare(av, bv) {
1983
- if (av == null) {
1984
- if (bv == null) return 0;
1985
- return -1;
1986
- }
1987
-
1988
- if (bv == null || av > bv) return 1;
1989
- if (av < bv) return -1;
1990
- return 0;
1991
- }
1992
-
1993
- function getComparer(sorters, dataAccessor, comparer) {
1994
- var data = (sorters || []).map(function(s) {
1995
- var selector = isDefined(s.value)
1996
- ? getSelector(s.value)
1997
- : s.field
1998
- ? function(x) {
1999
- return x[s.field];
2000
- }
2001
- : function() {
2002
- return null;
2003
- };
2004
- return {
2005
- getter: dataAccessor
2006
- ? function(x) {
2007
- return selector(dataAccessor(x));
2008
- }
2009
- : selector,
2010
- factor: s.direction && s.direction[0].toLowerCase() == "d" ? -1 : 1,
2011
- compare: s.comparer || s.compare || comparer || defaultCompare
2012
- };
2013
- });
2014
- return function(a, b) {
2015
- var d, av, bv;
2016
-
2017
- for (var i = 0; i < data.length; i++) {
2018
- d = data[i];
2019
- av = d.getter(a);
2020
- bv = d.getter(b); // show nulls always on the bottom
2021
-
2022
- if (av == null) return bv == null ? 0 : 1;
2023
- if (bv == null) return -1;
2024
- var r = d.compare(av, bv);
2025
- if (r == 0) continue;
2026
- return d.factor * r;
2027
- }
2028
-
2029
- return 0;
2030
- };
2031
- }
2032
- function indexSorter(sorters, dataAccessor, compare) {
2033
- var cmp = getComparer(sorters, dataAccessor, compare);
2034
- return function(data) {
2035
- var result = Array.from(
2036
- {
2037
- length: data.length
2038
- },
2039
- function(v, k) {
2040
- return k;
2041
- }
2042
- );
2043
- result.sort(function(ia, ib) {
2044
- return cmp(data[ia], data[ib]);
2045
- });
2046
- return result;
2047
- };
2048
- }
2049
- function sorter(sorters, dataAccessor, compare) {
2050
- var cmp = getComparer(sorters, dataAccessor, compare);
2051
- return function(data) {
2052
- var result = [].concat(data);
2053
- result.sort(cmp);
2054
- return result;
2055
- };
2056
- }
2057
-
2058
- function enableFatArrowExpansion() {
2059
- plugFatArrowExpansion(expandFatArrows);
2060
- }
2061
-
2062
- function append(array) {
2063
- for (var _len = arguments.length, items = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
2064
- items[_key - 1] = arguments[_key];
2065
- }
2066
-
2067
- if (items.length == 0) return array;
2068
- if (!array) return items;
2069
- return [].concat(array, items);
2070
- }
2071
-
2072
- function merge(item, data) {
2073
- var result = item;
2074
- if (data)
2075
- for (var key in data) {
2076
- result = Binding.get(key).set(result, data[key]);
2077
- }
2078
- return result;
2079
- }
2080
-
2081
- function filter(array, callback) {
2082
- if (array == null) return array;
2083
- var result = array.filter(callback);
2084
- if (result.length == array.length) return array;
2085
- return result;
2086
- }
2087
-
2088
- function updateArray(array, updateCallback, itemFilter, removeFilter) {
2089
- if (!array) return array;
2090
- var newArray = [];
2091
- var dirty = false;
2092
-
2093
- for (var index = 0; index < array.length; index++) {
2094
- var item = array[index];
2095
-
2096
- if (removeFilter && removeFilter(item, index)) {
2097
- dirty = true;
2098
- continue;
2099
- }
2100
-
2101
- if (!itemFilter || itemFilter(item, index)) {
2102
- var newItem = updateCallback(item, index);
2103
- newArray.push(newItem);
2104
- if (newItem !== item) dirty = true;
2105
- } else newArray.push(item);
2106
- }
2107
-
2108
- return dirty ? newArray : array;
2109
- }
2110
-
2111
- function updateTree(array, updateCallback, itemFilter, childrenField, removeFilter) {
2112
- return updateArray(
2113
- array,
2114
- function(item) {
2115
- var _objectSpread2$1;
2116
-
2117
- if (!itemFilter || itemFilter(item)) item = updateCallback(item);
2118
- var children = item[childrenField];
2119
- if (!Array.isArray(children)) return item;
2120
- var updatedChildren = updateTree(children, updateCallback, itemFilter, childrenField, removeFilter);
2121
- if (updatedChildren != children)
2122
- return _objectSpread2(
2123
- _objectSpread2({}, item),
2124
- {},
2125
- ((_objectSpread2$1 = {}), (_objectSpread2$1[childrenField] = updatedChildren), _objectSpread2$1)
2126
- );
2127
- return item;
2128
- },
2129
- null,
2130
- removeFilter
2131
- );
2132
- }
2133
-
2134
- function removeTreeNodes(array, criteria, childrenField) {
2135
- if (childrenField === void 0) {
2136
- childrenField = "$children";
2137
- }
2138
-
2139
- return updateTree(
2140
- array,
2141
- null,
2142
- function() {
2143
- return false;
2144
- },
2145
- childrenField,
2146
- criteria
2147
- );
2148
- }
2149
-
2150
- function findTreeNode(array, criteria, childrenField) {
2151
- if (childrenField === void 0) {
2152
- childrenField = "$children";
2153
- }
2154
-
2155
- if (!Array.isArray(array)) return false;
2156
-
2157
- for (var i = 0; i < array.length; i++) {
2158
- if (criteria(array[i])) return array[i];
2159
- var child = findTreeNode(array[i][childrenField], criteria, childrenField);
2160
- if (child) return child;
2161
- }
2162
-
2163
- return false;
2164
- }
2165
-
2166
- function moveElement(array, sourceIndex, targetIndex) {
2167
- if (targetIndex == sourceIndex) return array;
2168
- var el = array[sourceIndex];
2169
- var res = [].concat(array);
2170
-
2171
- if (sourceIndex < targetIndex) {
2172
- for (var i = sourceIndex; i + 1 < targetIndex; i++) {
2173
- res[i] = res[i + 1];
2174
- }
2175
-
2176
- targetIndex--;
2177
- } else {
2178
- for (var _i = sourceIndex; _i > targetIndex; _i--) {
2179
- res[_i] = res[_i - 1];
2180
- }
2181
- }
2182
-
2183
- res[targetIndex] = el;
2184
- return res;
2185
- }
2186
-
2187
- function insertElement(array, index) {
2188
- for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
2189
- args[_key - 2] = arguments[_key];
2190
- }
2191
-
2192
- return [].concat(array.slice(0, index), args, array.slice(index));
2193
- }
2194
-
2195
- function diffArrays(oldArray, newArray, keyFn) {
2196
- if (!keyFn)
2197
- keyFn = function keyFn(e) {
2198
- return e;
2199
- };
2200
- var map = new Map();
2201
-
2202
- for (var i = 0; i < oldArray.length; i++) {
2203
- map.set(keyFn(oldArray[i]), oldArray[i]);
2204
- }
2205
-
2206
- var added = [],
2207
- changed = [],
2208
- unchanged = [];
2209
-
2210
- for (var _i = 0; _i < newArray.length; _i++) {
2211
- var el = newArray[_i];
2212
- var k = keyFn(el);
2213
- var old = map.get(k);
2214
- if (isUndefined(old)) added.push(el);
2215
- else {
2216
- map["delete"](k);
2217
- if (el == old) unchanged.push(el);
2218
- else
2219
- changed.push({
2220
- before: old,
2221
- after: el
2222
- });
2223
- }
2224
- }
2225
-
2226
- var removed = Array.from(map.values());
2227
- return {
2228
- added: added,
2229
- changed: changed,
2230
- unchanged: unchanged,
2231
- removed: removed
2232
- };
2233
- }
2234
-
2235
- var ArrayRef = /*#__PURE__*/ (function(_Ref) {
2236
- _inheritsLoose(ArrayRef, _Ref);
2237
-
2238
- function ArrayRef() {
2239
- return _Ref.apply(this, arguments) || this;
2240
- }
2241
-
2242
- var _proto = ArrayRef.prototype;
2243
-
2244
- _proto.append = function append$1() {
2245
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2246
- args[_key] = arguments[_key];
2247
- }
2248
-
2249
- this.update.apply(this, [append].concat(args));
2250
- };
2251
-
2252
- _proto.insert = function insert(index) {
2253
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
2254
- args[_key2 - 1] = arguments[_key2];
2255
- }
2256
-
2257
- this.update.apply(this, [insertElement].concat(args));
2258
- };
2259
-
2260
- _proto.filter = function filter(predicate) {
2261
- this.update(function(array) {
2262
- return array.filter(function(a) {
2263
- return predicate(a);
2264
- });
2265
- });
2266
- };
2267
-
2268
- _proto.move = function move(fromIndex, toIndex) {
2269
- this.update(moveElement, fromIndex, toIndex);
2270
- };
2271
-
2272
- _proto.clear = function clear() {
2273
- this.set([]);
2274
- };
2275
-
2276
- _proto.sort = function sort(compare) {
2277
- var data = this.get();
2278
- if (!data) return;
2279
- var x = [].concat(data);
2280
- x.sort(compare);
2281
- this.set(x);
2282
- };
2283
-
2284
- return ArrayRef;
2285
- })(Ref);
2286
-
2287
- var StoreProxy = /*#__PURE__*/ (function(_View) {
2288
- _inheritsLoose(StoreProxy, _View);
2289
-
2290
- function StoreProxy(getStore) {
2291
- var _this;
2292
-
2293
- _this =
2294
- _View.call(this, {
2295
- store: getStore()
2296
- }) || this;
2297
- Object.defineProperty(_assertThisInitialized(_this), "store", {
2298
- get: getStore
2299
- });
2300
- return _this;
2301
- }
2302
-
2303
- var _proto = StoreProxy.prototype;
2304
-
2305
- _proto.getData = function getData() {
2306
- return this.store.getData();
2307
- };
2308
-
2309
- return StoreProxy;
2310
- })(View);
2311
-
2312
- var ArrayElementView = /*#__PURE__*/ (function(_AugmentedViewBase) {
2313
- _inheritsLoose(ArrayElementView, _AugmentedViewBase);
2314
-
2315
- function ArrayElementView() {
2316
- return _AugmentedViewBase.apply(this, arguments) || this;
2317
- }
2318
-
2319
- var _proto = ArrayElementView.prototype;
2320
-
2321
- _proto.isExtraKey = function isExtraKey(key) {
2322
- return key == this.recordAlias || key == this.indexAlias || key == this.lengthAlias;
2323
- };
2324
-
2325
- _proto.deleteExtraKeyValue = function deleteExtraKeyValue(key) {
2326
- if (key != this.recordAlias) throw new Error("Field " + key + " cannot be deleted.");
2327
- var array = this.arrayAccessor.get(this.store.getData());
2328
- if (!array) return false;
2329
- var newArray = [].concat(array.slice(0, this.itemIndex), array.slice(this.itemIndex + 1));
2330
- return this.arrayAccessor.set(newArray, this.store);
2331
- };
2332
-
2333
- _proto.setExtraKeyValue = function setExtraKeyValue(key, value) {
2334
- if (key != this.recordAlias) throw new Error("Field " + key + " is read-only.");
2335
- var array = this.arrayAccessor.get(this.store.getData());
2336
- if (!array || value === array[this.itemIndex]) return false;
2337
- var newArray = [].concat(array.slice(0, this.itemIndex), [value], array.slice(this.itemIndex + 1));
2338
- return this.arrayAccessor.set(newArray, this.store);
2339
- };
2340
-
2341
- _proto.embedAugmentData = function embedAugmentData(result, parentStoreData) {
2342
- var array = this.arrayAccessor.get(parentStoreData);
2343
- if (!isArray(array)) return;
2344
- result[this.recordAlias] = array[this.itemIndex];
2345
- result[this.indexAlias] = this.itemIndex;
2346
- result[this.lengthAlias] = array.length;
2347
- };
2348
-
2349
- _proto.setIndex = function setIndex(itemIndex) {
2350
- this.itemIndex = itemIndex;
2351
- };
2352
-
2353
- return ArrayElementView;
2354
- })(AugmentedViewBase);
2355
- ArrayElementView.prototype.recordAlias = "$record";
2356
- ArrayElementView.prototype.indexAlias = "$index";
2357
- ArrayElementView.prototype.lengthAlias = "$length";
2358
-
2359
- /*
2360
- Accessor provides a common ground between refs and bindings.
2361
- Refs offer simplicity, bindings have better performance with more arguments.
2362
- Accessor works as a common interface which works with both patterns.
2363
- */
2364
-
2365
- function getAccessor(accessor, options) {
2366
- if (accessor == null) return null;
2367
-
2368
- if (isObject(accessor)) {
2369
- if (accessor.isAccessor || accessor.isRef) return accessor;
2370
-
2371
- if (isBinding(accessor)) {
2372
- var binding = Binding.get(accessor);
2373
- return {
2374
- get: binding.value,
2375
- set: function set(v, store) {
2376
- return store.set(binding.path, v);
2377
- },
2378
- isAccessor: true
2379
- };
2380
- }
2381
- }
2382
-
2383
- if (isAccessorChain(accessor)) {
2384
- var _binding = Binding.get(accessor);
2385
-
2386
- return {
2387
- get: _binding.value,
2388
- set: function set(v, store) {
2389
- return store.set(_binding.path, v);
2390
- },
2391
- isAccessor: true
2392
- };
2393
- }
2394
-
2395
- if (isSelector(accessor)) {
2396
- var selector = getSelector(accessor);
2397
- if (accessor && accessor.set)
2398
- return {
2399
- get: selector,
2400
- isAccessor: true,
2401
- bindInstance: function bindInstance(instance) {
2402
- return {
2403
- get: selector,
2404
- set: function set(value) {
2405
- return accessor.set(value, instance);
2406
- },
2407
- isAccessor: true
2408
- };
2409
- }
2410
- };
2411
- return {
2412
- get: selector,
2413
- isAccessor: true
2414
- };
2415
- }
2416
-
2417
- return {
2418
- get: function get() {
2419
- return accessor;
2420
- }
2421
- };
2422
- }
2423
-
2424
- export {
2425
- ArrayElementView,
2426
- ArrayRef,
2427
- AugmentedViewBase,
2428
- Binding,
2429
- ExposedRecordView,
2430
- ExposedValueView,
2431
- Expression,
2432
- Grouper,
2433
- NestedDataView,
2434
- ReadOnlyDataView,
2435
- Ref,
2436
- Store,
2437
- StoreProxy,
2438
- StringTemplate,
2439
- StructuredSelector,
2440
- SubscribableView,
2441
- View,
2442
- ZoomIntoPropertyView,
2443
- append,
2444
- computable,
2445
- createAccessorModelProxy,
2446
- defaultCompare,
2447
- diffArrays,
2448
- enableFatArrowExpansion,
2449
- expression,
2450
- filter,
2451
- findTreeNode,
2452
- getAccessor,
2453
- getComparer,
2454
- getSelector,
2455
- indexSorter,
2456
- insertElement,
2457
- invalidateExpressionCache,
2458
- invalidateStringTemplateCache,
2459
- isAccessorChain,
2460
- isBinding,
2461
- isSelector,
2462
- merge,
2463
- moveElement,
2464
- plugFatArrowExpansion,
2465
- removeTreeNodes,
2466
- sorter,
2467
- stringTemplate,
2468
- updateArray,
2469
- updateTree
2470
- };
1
+ import {
2
+ isObject,
3
+ isString,
4
+ isFunction,
5
+ Format,
6
+ isDigit,
7
+ quoteStr,
8
+ Component,
9
+ isArray,
10
+ isDefined,
11
+ SubscriberList,
12
+ isUndefined,
13
+ expandFatArrows
14
+ } from "cx/util";
15
+
16
+ var emptyFn = function emptyFn() {};
17
+
18
+ function createAccessorModelProxy(chain) {
19
+ if (chain === void 0) {
20
+ chain = "";
21
+ }
22
+
23
+ var lastOp = null;
24
+ var lastName = null;
25
+ var proxy = new Proxy(emptyFn, {
26
+ get: function get(_, name) {
27
+ if (typeof name !== "string") return proxy;
28
+
29
+ switch (name) {
30
+ case "isAccessorChain":
31
+ return true;
32
+
33
+ case "toString":
34
+ case "valueOf":
35
+ case "nameOf":
36
+ lastOp = name;
37
+ return proxy;
38
+ }
39
+
40
+ var newChain = chain;
41
+ if (newChain.length > 0) newChain += ".";
42
+ newChain += name;
43
+ lastName = name;
44
+ return createAccessorModelProxy(newChain);
45
+ },
46
+ apply: function apply() {
47
+ switch (lastOp) {
48
+ case "nameOf":
49
+ if (lastName != null) return lastName;
50
+ var lastDotIndex = chain.lastIndexOf(".");
51
+ return lastDotIndex > 0 ? chain.substring(lastDotIndex + 1) : chain;
52
+
53
+ default:
54
+ return chain;
55
+ }
56
+ }
57
+ });
58
+ return proxy;
59
+ }
60
+ function isAccessorChain(value) {
61
+ return value != null && !!value.isAccessorChain;
62
+ }
63
+
64
+ var bindingCache = {};
65
+ var Binding = /*#__PURE__*/ (function() {
66
+ function Binding(path) {
67
+ this.path = path;
68
+ this.parts = path.split(".");
69
+ var body = "return (x";
70
+ var selector = "x";
71
+
72
+ for (var i = 0; i < this.parts.length; i++) {
73
+ if (this.parts[i][0] >= "0" && this.parts[i][0] <= "9") selector += "[" + this.parts[i] + "]";
74
+ else selector += "." + this.parts[i];
75
+ if (i + 1 < this.parts.length) body += " && " + selector;
76
+ else body += " ? " + selector + " : undefined";
77
+ }
78
+
79
+ body += ")";
80
+ this.value = new Function("x", body);
81
+ }
82
+
83
+ var _proto = Binding.prototype;
84
+
85
+ _proto.set = function set(state, value) {
86
+ var cv = this.value(state);
87
+ if (cv === value) return state;
88
+ var ns = Object.assign({}, state);
89
+ var o = ns;
90
+
91
+ for (var i = 0; i < this.parts.length; i++) {
92
+ var part = this.parts[i];
93
+ var no = i == this.parts.length - 1 ? value : Object.assign({}, o[part]);
94
+ o[part] = no;
95
+ o = no;
96
+ }
97
+
98
+ return ns;
99
+ };
100
+
101
+ _proto["delete"] = function _delete(state) {
102
+ var ns = Object.assign({}, state);
103
+ var o = ns;
104
+ var part;
105
+
106
+ for (var i = 0; i < this.parts.length - 1; i++) {
107
+ part = this.parts[i];
108
+ var no = Object.assign({}, o[part]);
109
+ o[part] = no;
110
+ o = no;
111
+ }
112
+
113
+ part = this.parts[this.parts.length - 1];
114
+ if (!o.hasOwnProperty(part)) return state;
115
+ delete o[part];
116
+ return ns;
117
+ };
118
+
119
+ Binding.get = function get(path) {
120
+ if (isString(path)) {
121
+ var b = bindingCache[path];
122
+ if (b) return b;
123
+ b = new Binding(path);
124
+ bindingCache[path] = b;
125
+ return b;
126
+ }
127
+
128
+ if (isObject(path) && isString(path.bind)) return this.get(path.bind);
129
+ if (path instanceof Binding) return path;
130
+ if (isAccessorChain(path)) return this.get(path.toString());
131
+ throw new Error("Invalid binding definition provided.");
132
+ };
133
+
134
+ return Binding;
135
+ })();
136
+ function isBinding(value) {
137
+ if (isObject(value) && isString(value.bind)) return true;
138
+ if (value && value.isAccessorChain) return true;
139
+ return value instanceof Binding;
140
+ }
141
+
142
+ function _defineProperty(obj, key, value) {
143
+ if (key in obj) {
144
+ Object.defineProperty(obj, key, {
145
+ value: value,
146
+ enumerable: true,
147
+ configurable: true,
148
+ writable: true
149
+ });
150
+ } else {
151
+ obj[key] = value;
152
+ }
153
+
154
+ return obj;
155
+ }
156
+
157
+ function ownKeys(object, enumerableOnly) {
158
+ var keys = Object.keys(object);
159
+
160
+ if (Object.getOwnPropertySymbols) {
161
+ var symbols = Object.getOwnPropertySymbols(object);
162
+ if (enumerableOnly)
163
+ symbols = symbols.filter(function(sym) {
164
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
165
+ });
166
+ keys.push.apply(keys, symbols);
167
+ }
168
+
169
+ return keys;
170
+ }
171
+
172
+ function _objectSpread2(target) {
173
+ for (var i = 1; i < arguments.length; i++) {
174
+ var source = arguments[i] != null ? arguments[i] : {};
175
+
176
+ if (i % 2) {
177
+ ownKeys(Object(source), true).forEach(function(key) {
178
+ _defineProperty(target, key, source[key]);
179
+ });
180
+ } else if (Object.getOwnPropertyDescriptors) {
181
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
182
+ } else {
183
+ ownKeys(Object(source)).forEach(function(key) {
184
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
185
+ });
186
+ }
187
+ }
188
+
189
+ return target;
190
+ }
191
+
192
+ function _inheritsLoose(subClass, superClass) {
193
+ subClass.prototype = Object.create(superClass.prototype);
194
+ subClass.prototype.constructor = subClass;
195
+
196
+ _setPrototypeOf(subClass, superClass);
197
+ }
198
+
199
+ function _setPrototypeOf(o, p) {
200
+ _setPrototypeOf =
201
+ Object.setPrototypeOf ||
202
+ function _setPrototypeOf(o, p) {
203
+ o.__proto__ = p;
204
+ return o;
205
+ };
206
+
207
+ return _setPrototypeOf(o, p);
208
+ }
209
+
210
+ function _isNativeReflectConstruct() {
211
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
212
+ if (Reflect.construct.sham) return false;
213
+ if (typeof Proxy === "function") return true;
214
+
215
+ try {
216
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
217
+ return true;
218
+ } catch (e) {
219
+ return false;
220
+ }
221
+ }
222
+
223
+ function _construct(Parent, args, Class) {
224
+ if (_isNativeReflectConstruct()) {
225
+ _construct = Reflect.construct;
226
+ } else {
227
+ _construct = function _construct(Parent, args, Class) {
228
+ var a = [null];
229
+ a.push.apply(a, args);
230
+ var Constructor = Function.bind.apply(Parent, a);
231
+ var instance = new Constructor();
232
+ if (Class) _setPrototypeOf(instance, Class.prototype);
233
+ return instance;
234
+ };
235
+ }
236
+
237
+ return _construct.apply(null, arguments);
238
+ }
239
+
240
+ function _assertThisInitialized(self) {
241
+ if (self === void 0) {
242
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
243
+ }
244
+
245
+ return self;
246
+ }
247
+
248
+ function computable() {
249
+ var _ref;
250
+
251
+ if (arguments.length == 0)
252
+ throw new Error("computable requires at least a compute function to be passed in arguments.");
253
+ var compute = ((_ref = arguments.length - 1), _ref < 0 || arguments.length <= _ref ? undefined : arguments[_ref]);
254
+ if (typeof compute != "function") throw new Error("Last argument to the computable function should be a function.");
255
+ var inputs = [],
256
+ a;
257
+
258
+ for (var i = 0; i + 1 < arguments.length; i++) {
259
+ a = i < 0 || arguments.length <= i ? undefined : arguments[i];
260
+ if (isString(a) || isAccessorChain(a)) inputs.push(Binding.get(a.toString()).value);
261
+ else if (a.memoize) inputs.push(a.memoize());
262
+ else if (isFunction(a)) inputs.push(a);
263
+ else throw new Error("Invalid selector type '" + typeof a + "' received.");
264
+ }
265
+
266
+ function memoize(warmupData) {
267
+ var lastValue,
268
+ lastArgs =
269
+ warmupData &&
270
+ inputs.map(function(s) {
271
+ return s(warmupData);
272
+ });
273
+ return function(data) {
274
+ var dirty = false;
275
+
276
+ if (!lastArgs) {
277
+ lastArgs = Array.from({
278
+ length: inputs.length
279
+ });
280
+ dirty = true;
281
+ }
282
+
283
+ for (var _i = 0; _i < inputs.length; _i++) {
284
+ var v = inputs[_i](data);
285
+
286
+ if (v === lastArgs[_i]) continue;
287
+ lastArgs[_i] = v;
288
+ dirty = true;
289
+ }
290
+
291
+ if (dirty) lastValue = compute.apply(null, lastArgs);
292
+ return lastValue;
293
+ };
294
+ }
295
+
296
+ var selector = function selector(data) {
297
+ return compute.apply(
298
+ null,
299
+ inputs.map(function(s) {
300
+ return s(data);
301
+ })
302
+ );
303
+ };
304
+
305
+ selector.memoize = memoize;
306
+ return selector;
307
+ }
308
+
309
+ /*
310
+ Helper usage example
311
+
312
+ Expression.registerHelper('_', _);
313
+ let e = Expression.compile('_.min({data})');
314
+ */
315
+
316
+ var expCache = {},
317
+ helpers = {},
318
+ helperNames = [],
319
+ helperValues = [],
320
+ expFatArrows = null;
321
+
322
+ function getExpr(expr) {
323
+ if (expr.memoize) return expr;
324
+
325
+ function memoize() {
326
+ var lastValue,
327
+ lastRunBindings = {},
328
+ lastRunResults = {},
329
+ getters = {},
330
+ currentData,
331
+ len = -1;
332
+
333
+ var get = function get(bindingWithFormat) {
334
+ var getter = getters[bindingWithFormat];
335
+
336
+ if (!getter) {
337
+ var binding = bindingWithFormat,
338
+ format;
339
+ var colonIndex = bindingWithFormat.indexOf(":");
340
+
341
+ if (colonIndex != -1) {
342
+ format = Format.parse(bindingWithFormat.substring(colonIndex + 1));
343
+ binding = bindingWithFormat.substring(0, colonIndex);
344
+ } else {
345
+ var nullSeparatorIndex = bindingWithFormat.indexOf(":");
346
+
347
+ if (nullSeparatorIndex != -1) {
348
+ format = Format.parse(bindingWithFormat.substring(nullSeparatorIndex));
349
+ binding = bindingWithFormat.substring(0, nullSeparatorIndex - 1);
350
+ }
351
+ }
352
+
353
+ var b = Binding.get(binding);
354
+
355
+ getter = function getter(data) {
356
+ var value = b.value(data);
357
+ lastRunBindings[len] = b.value;
358
+ lastRunResults[len] = value;
359
+ len++;
360
+ return value;
361
+ };
362
+
363
+ if (format) {
364
+ var valueGetter = getter;
365
+
366
+ getter = function getter(data) {
367
+ return format(valueGetter(data));
368
+ };
369
+ }
370
+
371
+ getters[bindingWithFormat] = getter;
372
+ }
373
+
374
+ return getter(currentData);
375
+ };
376
+
377
+ return function(data) {
378
+ var i = 0;
379
+
380
+ for (; i < len; i++) {
381
+ if (lastRunBindings[i](data) !== lastRunResults[i]) break;
382
+ }
383
+
384
+ if (i !== len) {
385
+ len = 0;
386
+ currentData = data;
387
+ lastValue = expr(get);
388
+ }
389
+
390
+ return lastValue;
391
+ };
392
+ }
393
+
394
+ var result = memoize();
395
+ result.memoize = memoize;
396
+ return result;
397
+ }
398
+
399
+ function expression(str) {
400
+ if (isFunction(str)) return getExpr(str);
401
+ var r = expCache[str];
402
+ if (r) return r;
403
+ var quote = false;
404
+ var termStart = -1,
405
+ curlyBrackets = 0,
406
+ percentExpression;
407
+ var fb = ["return ("];
408
+ var args = {};
409
+ var formats = [];
410
+ var subExpr = 0;
411
+
412
+ for (var i = 0; i < str.length; i++) {
413
+ var c = str[i];
414
+
415
+ switch (c) {
416
+ case "{":
417
+ if (curlyBrackets > 0) curlyBrackets++;
418
+ else {
419
+ if (!quote && termStart < 0 && (str[i + 1] != "{" || str[i - 1] == "%")) {
420
+ termStart = i + 1;
421
+ curlyBrackets = 1;
422
+ percentExpression = str[i - 1] == "%";
423
+ if (percentExpression) fb.pop(); //%
424
+ } else if (str[i - 1] != "{") fb.push(c);
425
+ }
426
+ break;
427
+
428
+ case "}":
429
+ if (termStart >= 0) {
430
+ if (--curlyBrackets == 0) {
431
+ var term = str.substring(termStart, i);
432
+ var formatStart = 0;
433
+ if (term[0] == "[") formatStart = term.indexOf("]");
434
+ var colon = term.indexOf(":", formatStart > 0 ? formatStart : 0);
435
+ var binding = colon == -1 ? term : term.substring(0, colon);
436
+ var format = colon == -1 ? null : term.substring(colon + 1);
437
+
438
+ if (colon == -1) {
439
+ var nullSepIndex = binding.indexOf("|", formatStart);
440
+
441
+ if (nullSepIndex != -1) {
442
+ format = binding.substring(nullSepIndex);
443
+ binding = binding.substring(0, nullSepIndex);
444
+ }
445
+ }
446
+
447
+ var argName = binding.replace(/\./g, "_");
448
+ if (isDigit(argName[0])) argName = "$" + argName;
449
+
450
+ if (percentExpression || (binding[0] == "[" && binding[binding.length - 1] == "]")) {
451
+ argName = "expr" + ++subExpr;
452
+ args[argName] = expression(percentExpression ? binding : binding.substring(1, binding.length - 1));
453
+ } else args[argName] = binding;
454
+
455
+ if (format) {
456
+ var formatter = "fmt" + formats.length;
457
+ fb.push(formatter, "(", argName, ", ", quoteStr(format), ")");
458
+ formats.push(Format.parse(format));
459
+ } else fb.push(argName);
460
+
461
+ termStart = -1;
462
+ }
463
+ } else fb.push(c);
464
+
465
+ break;
466
+
467
+ case '"':
468
+ case "'":
469
+ if (curlyBrackets == 0) {
470
+ if (!quote) quote = c;
471
+ else if (str[i - 1] != "\\" && quote == c) quote = false;
472
+ fb.push(c);
473
+ }
474
+
475
+ break;
476
+
477
+ default:
478
+ if (termStart < 0) fb.push(c);
479
+ break;
480
+ }
481
+ }
482
+
483
+ fb.push(")");
484
+ var body = fb.join("");
485
+ if (expFatArrows) body = expFatArrows(body); //console.log(body);
486
+
487
+ var keys = Object.keys(args);
488
+
489
+ try {
490
+ var _Function;
491
+
492
+ var compute = (_Function = _construct(
493
+ Function,
494
+ formats
495
+ .map(function(f, i) {
496
+ return "fmt" + i;
497
+ })
498
+ .concat(keys, helperNames, [body])
499
+ )).bind.apply(_Function, [Format].concat(formats, helperValues));
500
+
501
+ var selector = computable.apply(
502
+ void 0,
503
+ keys
504
+ .map(function(k) {
505
+ return args[k];
506
+ })
507
+ .concat([compute])
508
+ );
509
+ expCache[str] = selector;
510
+ return selector;
511
+ } catch (err) {
512
+ throw new Error("Failed to parse expression: '" + str + "'. Error: " + err.message);
513
+ }
514
+ }
515
+ var Expression = {
516
+ get: function get(str) {
517
+ return expression(str);
518
+ },
519
+ compile: function compile(str) {
520
+ return this.get(str).memoize();
521
+ },
522
+ registerHelper: function registerHelper(name, helper) {
523
+ helpers[name] = helper;
524
+ helperNames = Object.keys(helpers);
525
+ helperValues = helperNames.map(function(n) {
526
+ return helpers[n];
527
+ });
528
+ }
529
+ };
530
+ function plugFatArrowExpansion(impl) {
531
+ expFatArrows = impl;
532
+ }
533
+ function invalidateExpressionCache() {
534
+ expCache = {};
535
+ }
536
+
537
+ function plus(str) {
538
+ return str.length ? str + " + " : str;
539
+ }
540
+
541
+ var tplCache = {};
542
+ function stringTemplate(str) {
543
+ var expr = tplCache[str];
544
+ if (expr) return expr;
545
+ expr = "";
546
+ var termStart = -1,
547
+ quoteStart = 0,
548
+ term,
549
+ bracketsOpen = 0,
550
+ percentSign;
551
+
552
+ for (var i = 0; i < str.length; i++) {
553
+ var c = str[i];
554
+
555
+ switch (c) {
556
+ case "{":
557
+ if (termStart < 0) {
558
+ if (str[i + 1] == "{" && str[i - 1] != "%") {
559
+ expr = plus(expr) + quoteStr(str.substring(quoteStart, i) + "{");
560
+ i++;
561
+ quoteStart = i + 1;
562
+ } else {
563
+ termStart = i + 1;
564
+ percentSign = str[i - 1] == "%";
565
+ if (i > quoteStart) expr = plus(expr) + quoteStr(str.substring(quoteStart, percentSign ? i - 1 : i));
566
+ bracketsOpen = 1;
567
+ }
568
+ } else bracketsOpen++;
569
+
570
+ break;
571
+
572
+ case "}":
573
+ if (termStart >= 0) {
574
+ if (--bracketsOpen == 0) {
575
+ term = str.substring(termStart, i);
576
+
577
+ if (term.indexOf(":") == -1) {
578
+ var nullSepIndex = term.indexOf("|");
579
+ if (nullSepIndex == -1) term += ":s";
580
+ else term = term.substring(0, nullSepIndex) + ":s" + term.substring(nullSepIndex);
581
+ }
582
+
583
+ expr = plus(expr) + (percentSign ? "%{" : "{") + term + "}";
584
+ termStart = -1;
585
+ quoteStart = i + 1;
586
+ bracketsOpen = 0;
587
+ }
588
+ } else if (str[i + 1] == "}") {
589
+ expr = plus(expr) + quoteStr(str.substring(quoteStart, i) + "}");
590
+ i++;
591
+ quoteStart = i + 1;
592
+ }
593
+
594
+ break;
595
+ }
596
+ }
597
+
598
+ if (quoteStart < str.length) expr = plus(expr) + quoteStr(str.substring(quoteStart)); //console.log(expr);
599
+
600
+ return (tplCache[str] = expression(expr));
601
+ }
602
+ var StringTemplate = {
603
+ get: function get(str) {
604
+ return stringTemplate(str);
605
+ },
606
+ compile: function compile(str) {
607
+ return stringTemplate(str).memoize();
608
+ },
609
+ format: function format(_format) {
610
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
611
+ args[_key - 1] = arguments[_key];
612
+ }
613
+
614
+ return stringTemplate(_format)(args);
615
+ }
616
+ };
617
+ function invalidateStringTemplateCache() {
618
+ tplCache = {};
619
+ }
620
+
621
+ var Ref = /*#__PURE__*/ (function(_Component) {
622
+ _inheritsLoose(Ref, _Component);
623
+
624
+ function Ref(config) {
625
+ var _this;
626
+
627
+ _this = _Component.call(this, config) || this;
628
+ _this.get = _this.get.bind(_assertThisInitialized(_this));
629
+ if (_this.set) _this.set = _this.set.bind(_assertThisInitialized(_this));
630
+ return _this;
631
+ }
632
+
633
+ var _proto = Ref.prototype;
634
+
635
+ _proto.get = function get() {
636
+ throw new Error("Ref's get method is not implemented.");
637
+ };
638
+
639
+ _proto.init = function init(value) {
640
+ if (this.get() === undefined) this.set(value);
641
+ };
642
+
643
+ _proto.toggle = function toggle() {
644
+ this.set(!this.get());
645
+ };
646
+
647
+ _proto.update = function update(cb) {
648
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
649
+ args[_key - 1] = arguments[_key];
650
+ }
651
+
652
+ this.set(cb.apply(void 0, [this.get()].concat(args)));
653
+ };
654
+
655
+ _proto.as = function as(config) {
656
+ return Ref.create(config, {
657
+ get: this.get,
658
+ set: this.set
659
+ });
660
+ };
661
+
662
+ _proto.ref = function ref(path) {
663
+ var _this2 = this;
664
+
665
+ var binding = Binding.get(path);
666
+ return Ref.create({
667
+ get: function get() {
668
+ return binding.value(_this2.get());
669
+ },
670
+ set: function set(value) {
671
+ var data = _this2.get();
672
+
673
+ var newData = binding.set(data, value);
674
+ if (data === newData) return false;
675
+ return _this2.set(newData);
676
+ }
677
+ });
678
+ }; //allows the function to be passed as a selector, e.g. to computable or addTrigger
679
+
680
+ _proto.memoize = function memoize() {
681
+ return this.get;
682
+ };
683
+
684
+ return Ref;
685
+ })(Component);
686
+ Ref.prototype.isRef = true;
687
+
688
+ Ref.factory = function(alias, config, more) {
689
+ if (isFunction(alias)) {
690
+ var cfg = _objectSpread2(_objectSpread2({}, config), more);
691
+
692
+ if (cfg.store) Object.assign(cfg, cfg.store.getMethods());
693
+ var result = alias(cfg);
694
+ if (result instanceof Ref) return result;
695
+ return this.create(_objectSpread2(_objectSpread2(_objectSpread2({}, config), more), result));
696
+ }
697
+
698
+ return this.create(_objectSpread2(_objectSpread2({}, config), more));
699
+ };
700
+
701
+ var StoreRef = /*#__PURE__*/ (function(_Ref) {
702
+ _inheritsLoose(StoreRef, _Ref);
703
+
704
+ function StoreRef(config) {
705
+ var _this;
706
+
707
+ _this = _Ref.call(this, config) || this;
708
+ if (isAccessorChain(_this.path)) _this.path = _this.path.toString();
709
+ return _this;
710
+ }
711
+
712
+ var _proto = StoreRef.prototype;
713
+
714
+ _proto.get = function get() {
715
+ return this.store.get(this.path);
716
+ };
717
+
718
+ _proto.set = function set(value) {
719
+ return this.store.set(this.path, value);
720
+ };
721
+
722
+ _proto.init = function init(value) {
723
+ return this.store.init(this.path, value);
724
+ };
725
+
726
+ _proto.toggle = function toggle() {
727
+ return this.store.toggle(this.path);
728
+ };
729
+
730
+ _proto["delete"] = function _delete() {
731
+ return this.store["delete"](this.path);
732
+ };
733
+
734
+ _proto.update = function update() {
735
+ var _this$store;
736
+
737
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
738
+ args[_key] = arguments[_key];
739
+ }
740
+
741
+ return (_this$store = this.store).update.apply(_this$store, [this.path].concat(args));
742
+ }; //allows the function to be passed as a selector, e.g. to computable or addTrigger
743
+
744
+ _proto.memoize = function memoize() {
745
+ return this.get;
746
+ };
747
+
748
+ _proto.ref = function ref(path) {
749
+ return new StoreRef({
750
+ path: this.path + "." + path,
751
+ store: this.store
752
+ });
753
+ };
754
+
755
+ _proto.as = function as(config) {
756
+ return StoreRef.create(config, {
757
+ path: this.path,
758
+ store: this.store,
759
+ get: this.get,
760
+ set: this.set
761
+ });
762
+ };
763
+
764
+ return StoreRef;
765
+ })(Ref);
766
+
767
+ var View = /*#__PURE__*/ (function() {
768
+ function View(config) {
769
+ Object.assign(this, config);
770
+ this.cache = {
771
+ version: -1
772
+ };
773
+ if (this.store) this.setStore(this.store);
774
+ }
775
+
776
+ var _proto = View.prototype;
777
+
778
+ _proto.getData = function getData() {
779
+ throw new Error("abstract method");
780
+ };
781
+
782
+ _proto.init = function init(path, value) {
783
+ if (typeof path == "object" && path != null) {
784
+ var changed = false;
785
+
786
+ for (var key in path) {
787
+ if (path.hasOwnProperty(key) && this.get(key) === undefined && this.setItem(key, path[key])) changed = true;
788
+ }
789
+
790
+ return changed;
791
+ }
792
+
793
+ var binding = Binding.get(path);
794
+ if (this.get(binding.path) === undefined) return this.setItem(binding.path, value);
795
+ return false;
796
+ };
797
+
798
+ _proto.set = function set(path, value) {
799
+ if (isObject(path)) {
800
+ var changed = false;
801
+
802
+ for (var key in path) {
803
+ if (path.hasOwnProperty(key) && this.setItem(key, path[key])) changed = true;
804
+ }
805
+
806
+ return changed;
807
+ }
808
+
809
+ var binding = Binding.get(path);
810
+ return this.setItem(binding.path, value);
811
+ };
812
+
813
+ _proto.copy = function copy(from, to) {
814
+ var value = this.get(from);
815
+ this.set(to, value);
816
+ };
817
+
818
+ _proto.move = function move(from, to) {
819
+ var _this = this;
820
+
821
+ this.batch(function() {
822
+ _this.copy(from, to);
823
+
824
+ _this["delete"](from);
825
+ });
826
+ }; //protected
827
+
828
+ _proto.setItem = function setItem(path, value) {
829
+ if (this.store) return this.store.setItem(path, value);
830
+ throw new Error("abstract method");
831
+ };
832
+
833
+ _proto["delete"] = function _delete(path) {
834
+ var _this2 = this;
835
+
836
+ if (arguments.length > 1) path = Array.from(arguments);
837
+ if (isArray(path))
838
+ return path
839
+ .map(function(arg) {
840
+ return _this2["delete"](arg);
841
+ })
842
+ .some(Boolean);
843
+ var binding = Binding.get(path);
844
+ return this.deleteItem(binding.path);
845
+ }; //protected
846
+
847
+ _proto.deleteItem = function deleteItem(path) {
848
+ if (this.store) return this.store.deleteItem(path);
849
+ throw new Error("abstract method");
850
+ };
851
+
852
+ _proto.clear = function clear() {
853
+ if (this.store) return this.store.clear();
854
+ throw new Error("abstract method");
855
+ };
856
+
857
+ _proto.get = function get(path) {
858
+ var storeData = this.getData();
859
+ if (arguments.length > 1) path = Array.from(arguments);
860
+ if (isArray(path))
861
+ return path.map(function(arg) {
862
+ return Binding.get(arg).value(storeData);
863
+ });
864
+ return Binding.get(path).value(storeData);
865
+ };
866
+
867
+ _proto.toggle = function toggle(path) {
868
+ return this.set(path, !this.get(path));
869
+ };
870
+
871
+ _proto.update = function update(path, updateFn) {
872
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
873
+ args[_key - 2] = arguments[_key];
874
+ }
875
+
876
+ if (arguments.length == 1 && isFunction(path))
877
+ return this.load(path.apply(null, [this.getData(), updateFn].concat(args)));
878
+ return this.set(path, updateFn.apply(null, [this.get(path)].concat(args)));
879
+ };
880
+
881
+ _proto.batch = function batch(callback) {
882
+ var dirty = this.silently(callback);
883
+ if (dirty) this.notify();
884
+ return dirty;
885
+ };
886
+
887
+ _proto.silently = function silently(callback) {
888
+ if (this.store) return this.store.silently(callback);
889
+ throw new Error("abstract method");
890
+ };
891
+
892
+ _proto.notify = function notify(path) {
893
+ if (this.notificationsSuspended) this.dirty = true;
894
+ else this.doNotify(path);
895
+ };
896
+
897
+ _proto.doNotify = function doNotify(path) {
898
+ if (this.store) return this.store.notify(path);
899
+ throw new Error("abstract method");
900
+ };
901
+
902
+ _proto.subscribe = function subscribe(callback) {
903
+ if (this.store) return this.store.subscribe(callback);
904
+ throw new Error("abstract method");
905
+ };
906
+
907
+ _proto.load = function load(data) {
908
+ return this.batch(function(store) {
909
+ for (var key in data) {
910
+ store.set(key, data[key]);
911
+ }
912
+ });
913
+ };
914
+
915
+ _proto.dispatch = function dispatch(action) {
916
+ if (this.store) return this.store.dispatch(action);
917
+ throw new Error("The underlying store doesn't support dispatch.");
918
+ };
919
+
920
+ _proto.getMeta = function getMeta() {
921
+ return this.meta;
922
+ };
923
+
924
+ _proto.setStore = function setStore(store) {
925
+ this.store = store;
926
+ this.meta = store.getMeta();
927
+ };
928
+
929
+ _proto.ref = function ref(path, defaultValue) {
930
+ if (isDefined(defaultValue)) this.init(path, defaultValue);
931
+ return StoreRef.create({
932
+ store: this,
933
+ path: path
934
+ });
935
+ };
936
+
937
+ _proto.getMethods = function getMethods() {
938
+ return {
939
+ getData: this.getData.bind(this),
940
+ set: this.set.bind(this),
941
+ get: this.get.bind(this),
942
+ update: this.update.bind(this),
943
+ delete: this["delete"].bind(this),
944
+ toggle: this.toggle.bind(this),
945
+ init: this.init.bind(this),
946
+ ref: this.ref.bind(this),
947
+ mutate: this.ref.bind(this)
948
+ };
949
+ };
950
+
951
+ return View;
952
+ })();
953
+ View.prototype.sealed = false; //indicate that data should be copied before virtual items are added
954
+ //Immer integration point
955
+
956
+ View.prototype.mutate = function() {
957
+ throw new Error(
958
+ "Mutate requires Immer. Please install 'immer' and 'cx-immer' packages and enable store mutation by calling enableImmerMutate()."
959
+ );
960
+ };
961
+
962
+ var SubscribableView = /*#__PURE__*/ (function(_View) {
963
+ _inheritsLoose(SubscribableView, _View);
964
+
965
+ function SubscribableView(config) {
966
+ var _this;
967
+
968
+ _this = _View.call(this, config) || this;
969
+ _this.subscribers = new SubscriberList();
970
+ _this.changes = [];
971
+ return _this;
972
+ }
973
+
974
+ var _proto = SubscribableView.prototype;
975
+
976
+ _proto.subscribe = function subscribe(callback) {
977
+ return this.subscribers.subscribe(callback);
978
+ };
979
+
980
+ _proto.unsubscribeAll = function unsubscribeAll() {
981
+ this.subscribers.clear();
982
+ };
983
+
984
+ _proto.doNotify = function doNotify(path) {
985
+ var _this2 = this;
986
+
987
+ if (this.notificationsSuspended) return;
988
+
989
+ if (!this.async) {
990
+ this.subscribers.notify([path]);
991
+ } else {
992
+ this.changes.push(path || "");
993
+
994
+ if (!this.scheduled) {
995
+ this.scheduled = true;
996
+ setTimeout(function() {
997
+ _this2.scheduled = false;
998
+ var changes = _this2.changes;
999
+ _this2.changes = [];
1000
+
1001
+ _this2.subscribers.notify(changes);
1002
+ }, 0);
1003
+ }
1004
+ }
1005
+ };
1006
+
1007
+ _proto.silently = function silently(callback) {
1008
+ this.notificationsSuspended = (this.notificationsSuspended || 0) + 1;
1009
+ var wasDirty = this.dirty,
1010
+ dirty;
1011
+ this.dirty = false;
1012
+
1013
+ try {
1014
+ callback(this);
1015
+ } finally {
1016
+ this.notificationsSuspended--;
1017
+ dirty = this.dirty;
1018
+ this.dirty = wasDirty;
1019
+ }
1020
+
1021
+ return dirty;
1022
+ };
1023
+
1024
+ return SubscribableView;
1025
+ })(View);
1026
+ SubscribableView.prototype.async = false;
1027
+
1028
+ var Store = /*#__PURE__*/ (function(_SubscribableView) {
1029
+ _inheritsLoose(Store, _SubscribableView);
1030
+
1031
+ function Store(config) {
1032
+ var _this;
1033
+
1034
+ if (config === void 0) {
1035
+ config = {};
1036
+ }
1037
+
1038
+ _this = _SubscribableView.call(this, config) || this;
1039
+ _this.data = config.data || {};
1040
+ _this.meta = {
1041
+ version: 0
1042
+ };
1043
+ return _this;
1044
+ }
1045
+
1046
+ var _proto = Store.prototype;
1047
+
1048
+ _proto.getData = function getData() {
1049
+ return this.data;
1050
+ };
1051
+
1052
+ _proto.setItem = function setItem(path, value) {
1053
+ var next = Binding.get(path).set(this.data, value);
1054
+
1055
+ if (next != this.data) {
1056
+ this.data = next;
1057
+ this.meta.version++;
1058
+ this.notify(path);
1059
+ return true;
1060
+ }
1061
+
1062
+ return false;
1063
+ };
1064
+
1065
+ _proto.deleteItem = function deleteItem(path) {
1066
+ var next = Binding.get(path)["delete"](this.data);
1067
+
1068
+ if (next != this.data) {
1069
+ this.data = next;
1070
+ this.meta.version++;
1071
+ this.notify(path);
1072
+ return true;
1073
+ }
1074
+
1075
+ return false;
1076
+ };
1077
+
1078
+ _proto.clear = function clear() {
1079
+ this.data = {};
1080
+ this.meta.version++;
1081
+ this.notify();
1082
+ };
1083
+
1084
+ return Store;
1085
+ })(SubscribableView);
1086
+ Store.prototype.async = false;
1087
+
1088
+ var ExposedRecordView = /*#__PURE__*/ (function(_View) {
1089
+ _inheritsLoose(ExposedRecordView, _View);
1090
+
1091
+ function ExposedRecordView() {
1092
+ return _View.apply(this, arguments) || this;
1093
+ }
1094
+
1095
+ var _proto = ExposedRecordView.prototype;
1096
+
1097
+ _proto.getData = function getData() {
1098
+ if (this.sealed && this.meta.version === this.cache.version && this.cache.itemIndex === this.itemIndex)
1099
+ return this.cache.result;
1100
+ this.cache.result = this.embed(this.store.getData());
1101
+ this.cache.version = this.meta.version;
1102
+ this.cache.itemIndex = this.itemIndex;
1103
+ return this.cache.result;
1104
+ };
1105
+
1106
+ _proto.embed = function embed(data) {
1107
+ var collection = this.collectionBinding.value(data);
1108
+ var record = collection[this.itemIndex];
1109
+ var copy = this.sealed || this.immutable || this.store.sealed ? _objectSpread2({}, data) : data;
1110
+ copy[this.recordName] = record;
1111
+ if (this.indexName) copy[this.indexName] = this.itemIndex;
1112
+ return copy;
1113
+ };
1114
+
1115
+ _proto.setIndex = function setIndex(index) {
1116
+ this.itemIndex = index;
1117
+ };
1118
+
1119
+ _proto.setItem = function setItem(path, value) {
1120
+ if (path == this.recordName || path.indexOf(this.recordName + ".") == 0) {
1121
+ var storeData = this.store.getData();
1122
+ var collection = this.collectionBinding.value(storeData);
1123
+ var data = this.embed(storeData);
1124
+ var d = Binding.get(path).set(data, value);
1125
+ if (d === data) return false;
1126
+ var record = d[this.recordName];
1127
+ var newCollection = [].concat(
1128
+ collection.slice(0, this.itemIndex),
1129
+ [record],
1130
+ collection.slice(this.itemIndex + 1)
1131
+ );
1132
+ return this.store.setItem(this.collectionBinding.path, newCollection);
1133
+ }
1134
+
1135
+ return this.store.setItem(path, value);
1136
+ };
1137
+
1138
+ _proto.deleteItem = function deleteItem(path) {
1139
+ var storeData, collection, newCollection;
1140
+
1141
+ if (path == this.recordName) {
1142
+ storeData = this.store.getData();
1143
+ collection = this.collectionBinding.value(storeData);
1144
+ newCollection = [].concat(collection.slice(0, this.itemIndex), collection.slice(this.itemIndex + 1));
1145
+ return this.store.setItem(this.collectionBinding.path, newCollection);
1146
+ } else if (path.indexOf(this.recordName + ".") == 0) {
1147
+ storeData = this.store.getData();
1148
+ collection = this.collectionBinding.value(storeData);
1149
+ var data = this.embed(storeData);
1150
+ var d = Binding.get(path)["delete"](data);
1151
+ if (d === data) return false;
1152
+ var record = d[this.recordName];
1153
+ newCollection = [].concat(collection.slice(0, this.itemIndex), [record], collection.slice(this.itemIndex + 1));
1154
+ return this.store.setItem(this.collectionBinding.path, newCollection);
1155
+ }
1156
+
1157
+ return this.store.deleteItem(path);
1158
+ };
1159
+
1160
+ return ExposedRecordView;
1161
+ })(View);
1162
+ ExposedRecordView.prototype.immutable = false;
1163
+
1164
+ var ExposedValueView = /*#__PURE__*/ (function(_View) {
1165
+ _inheritsLoose(ExposedValueView, _View);
1166
+
1167
+ function ExposedValueView() {
1168
+ return _View.apply(this, arguments) || this;
1169
+ }
1170
+
1171
+ var _proto = ExposedValueView.prototype;
1172
+
1173
+ _proto.getData = function getData() {
1174
+ if (this.sealed && this.meta.version === this.cache.version && this.cache.key === this.key)
1175
+ return this.cache.result;
1176
+ var data = this.store.getData();
1177
+ var container = this.containerBinding.value(data) || {};
1178
+ var record = container[this.key];
1179
+ this.cache.version = this.meta.version;
1180
+ this.cache.key = this.key;
1181
+ this.cache.result = this.sealed || this.immutable || this.store.sealed ? _objectSpread2({}, data) : data;
1182
+ this.cache.result[this.recordName] = record;
1183
+ return this.cache.result;
1184
+ };
1185
+
1186
+ _proto.setKey = function setKey(key) {
1187
+ this.key = key;
1188
+ };
1189
+
1190
+ _proto.getKey = function getKey() {
1191
+ return this.key;
1192
+ };
1193
+
1194
+ _proto.setItem = function setItem(path, value) {
1195
+ if (path == this.recordName || path.indexOf(this.recordName + ".") == 0) {
1196
+ var data = this.getData();
1197
+ var d = Binding.get(path).set(data, value);
1198
+ if (d === data) return false;
1199
+ var container = this.containerBinding.value(d);
1200
+ var record = d[this.recordName];
1201
+ var newContainer = Object.assign({}, container);
1202
+ newContainer[this.key] = record;
1203
+ return this.store.setItem(this.containerBinding.path, newContainer);
1204
+ }
1205
+
1206
+ return this.store.setItem(path, value);
1207
+ };
1208
+
1209
+ _proto.deleteItem = function deleteItem(path) {
1210
+ var data, container, newContainer;
1211
+
1212
+ if (path == this.recordName) {
1213
+ data = this.getData();
1214
+ container = this.containerBinding.value(data);
1215
+ if (!container || !container.hasOwnProperty(path)) return false;
1216
+ newContainer = Object.assign({}, container);
1217
+ delete newContainer[this.key];
1218
+ this.store.set(this.containerBinding.path, newContainer);
1219
+ } else if (path.indexOf(this.recordName + ".") == 0) {
1220
+ data = this.getData();
1221
+ var d = Binding.get(path)["delete"](data);
1222
+ if (d === data) return false;
1223
+ container = this.containerBinding.value(d);
1224
+ var record = d[this.recordName];
1225
+ newContainer = Object.assign({}, container);
1226
+ newContainer[this.key] = record;
1227
+ return this.store.setItem(this.containerBinding.path, newContainer);
1228
+ }
1229
+
1230
+ return this.store.deleteItem(path);
1231
+ };
1232
+
1233
+ return ExposedValueView;
1234
+ })(View);
1235
+ ExposedValueView.prototype.immutable = false;
1236
+
1237
+ var ReadOnlyDataView = /*#__PURE__*/ (function(_View) {
1238
+ _inheritsLoose(ReadOnlyDataView, _View);
1239
+
1240
+ function ReadOnlyDataView() {
1241
+ return _View.apply(this, arguments) || this;
1242
+ }
1243
+
1244
+ var _proto = ReadOnlyDataView.prototype;
1245
+
1246
+ _proto.getData = function getData() {
1247
+ if (this.sealed && this.meta.version === this.cache.version && this.cache.data === this.data)
1248
+ return this.cache.result;
1249
+ var data = this.store.getData();
1250
+ this.cache.result =
1251
+ this.sealed || this.immutable || this.store.sealed
1252
+ ? Object.assign({}, data, this.getAdditionalData(data))
1253
+ : Object.assign(data, this.getAdditionalData(data));
1254
+ this.cache.version = this.meta.version;
1255
+ this.cache.data = this.data;
1256
+ return this.cache.result;
1257
+ };
1258
+
1259
+ _proto.getAdditionalData = function getAdditionalData() {
1260
+ return this.data;
1261
+ };
1262
+
1263
+ _proto.setData = function setData(data) {
1264
+ this.data = data;
1265
+ };
1266
+
1267
+ return ReadOnlyDataView;
1268
+ })(View);
1269
+ ReadOnlyDataView.prototype.immutable = false;
1270
+
1271
+ var AugmentedViewBase = /*#__PURE__*/ (function(_View) {
1272
+ _inheritsLoose(AugmentedViewBase, _View);
1273
+
1274
+ function AugmentedViewBase() {
1275
+ return _View.apply(this, arguments) || this;
1276
+ }
1277
+
1278
+ var _proto = AugmentedViewBase.prototype;
1279
+
1280
+ _proto.getData = function getData() {
1281
+ if (this.meta.version === this.cache.version && this.sealed) return this.cache.result;
1282
+ var parentStoreData = this.store.getData();
1283
+ var result = this.getBaseData(parentStoreData);
1284
+ this.embedAugmentData(result, parentStoreData);
1285
+ this.cache.result = result;
1286
+ this.cache.parentStoreData = parentStoreData;
1287
+ this.cache.version = this.meta.version;
1288
+ return this.cache.result;
1289
+ };
1290
+
1291
+ _proto.getBaseData = function getBaseData(parentStoreData) {
1292
+ if (this.sealed || this.immutable || this.store.sealed) return _objectSpread2({}, parentStoreData);
1293
+ return parentStoreData;
1294
+ };
1295
+
1296
+ _proto.embedAugmentData = function embedAugmentData(result, parentStoreData) {
1297
+ throw new Error("abstract");
1298
+ };
1299
+
1300
+ _proto.isExtraKey = function isExtraKey(key) {
1301
+ throw new Error("abstract");
1302
+ };
1303
+
1304
+ _proto.setExtraKeyValue = function setExtraKeyValue(key, value) {
1305
+ throw new Error("abstract");
1306
+ };
1307
+
1308
+ _proto.deleteExtraKeyValue = function deleteExtraKeyValue(key) {
1309
+ throw new Error("abstract");
1310
+ };
1311
+
1312
+ _proto.setItem = function setItem(path, value) {
1313
+ var binding = Binding.get(path);
1314
+
1315
+ if (this.isExtraKey(binding.parts[0])) {
1316
+ var bindingRoot = binding.parts[0];
1317
+ var newValue = value;
1318
+
1319
+ if (binding.parts.length > 1) {
1320
+ var data = {};
1321
+ this.embedAugmentData(data, this.store.getData());
1322
+ newValue = binding.set(data, value)[bindingRoot];
1323
+ }
1324
+
1325
+ return this.setExtraKeyValue(bindingRoot, newValue);
1326
+ }
1327
+
1328
+ return _View.prototype.setItem.call(this, path, value);
1329
+ };
1330
+
1331
+ _proto.deleteItem = function deleteItem(path) {
1332
+ var binding = Binding.get(path);
1333
+
1334
+ if (this.isExtraKey(binding.parts[0])) {
1335
+ var bindingRoot = binding.parts[0];
1336
+ if (binding.parts.length == 1) return this.deleteExtraKeyValue(bindingRoot);
1337
+ var data = {};
1338
+ this.embedAugmentData(data, this.store.getData());
1339
+ var newValue = binding["delete"](data)[bindingRoot];
1340
+ return this.setExtraKeyValue(bindingRoot, newValue);
1341
+ }
1342
+
1343
+ return _View.prototype.deleteItem.call(this, path);
1344
+ };
1345
+
1346
+ return AugmentedViewBase;
1347
+ })(View);
1348
+ AugmentedViewBase.prototype.immutable = false;
1349
+
1350
+ var NestedDataView = /*#__PURE__*/ (function(_AugmentedViewBase) {
1351
+ _inheritsLoose(NestedDataView, _AugmentedViewBase);
1352
+
1353
+ function NestedDataView() {
1354
+ return _AugmentedViewBase.apply(this, arguments) || this;
1355
+ }
1356
+
1357
+ var _proto = NestedDataView.prototype;
1358
+
1359
+ _proto.embedAugmentData = function embedAugmentData(result, parentStoreData) {
1360
+ if (this.nestedData) {
1361
+ var nested = this.nestedData.getSelector()(parentStoreData);
1362
+
1363
+ for (var key in nested) {
1364
+ result[key] = nested[key];
1365
+ }
1366
+ }
1367
+ };
1368
+
1369
+ _proto.isExtraKey = function isExtraKey(key) {
1370
+ return this.nestedData && this.nestedData.containsKey(key);
1371
+ };
1372
+
1373
+ _proto.setExtraKeyValue = function setExtraKeyValue(key, value) {
1374
+ this.nestedData.setItem(key, value);
1375
+ };
1376
+
1377
+ _proto.deleteExtraKeyValue = function deleteExtraKeyValue(key) {
1378
+ this.setExtraKeyValue(key, undefined);
1379
+ };
1380
+
1381
+ return NestedDataView;
1382
+ })(AugmentedViewBase);
1383
+
1384
+ var ZoomIntoPropertyView = /*#__PURE__*/ (function(_NestedDataView) {
1385
+ _inheritsLoose(ZoomIntoPropertyView, _NestedDataView);
1386
+
1387
+ function ZoomIntoPropertyView() {
1388
+ return _NestedDataView.apply(this, arguments) || this;
1389
+ }
1390
+
1391
+ var _proto = ZoomIntoPropertyView.prototype;
1392
+
1393
+ _proto.getBaseData = function getBaseData(parentStoreData) {
1394
+ var x = this.binding.value(parentStoreData);
1395
+ if (x != null && typeof x != "object") throw new Error("Zoomed value must be an object.");
1396
+ return _objectSpread2({}, x);
1397
+ };
1398
+
1399
+ _proto.embedAugmentData = function embedAugmentData(result, parentStoreData) {
1400
+ result[this.rootName] = parentStoreData;
1401
+
1402
+ _NestedDataView.prototype.embedAugmentData.call(this, result, parentStoreData);
1403
+ };
1404
+
1405
+ _proto.setItem = function setItem(path, value) {
1406
+ if (path.indexOf(this.rootName + ".") == 0) this.store.setItem(path.substring(this.rootName.length + 1), value);
1407
+ else if (this.isExtraKey(Binding.get(path).parts[0])) _NestedDataView.prototype.setItem.call(this, path, value);
1408
+ else _NestedDataView.prototype.setItem.call(this, this.binding.path + "." + path, value);
1409
+ };
1410
+
1411
+ _proto.deleteItem = function deleteItem(path) {
1412
+ if (path.indexOf(this.rootName + ".") == 0) this.store.deleteItem(path.substring(this.rootName.length + 1));
1413
+ else if (this.isExtraKey(Binding.get(path).parts[0])) _NestedDataView.prototype.deleteItem.call(this, path);
1414
+ else _NestedDataView.prototype.deleteItem.call(this, this.binding.path + "." + path);
1415
+ };
1416
+
1417
+ return ZoomIntoPropertyView;
1418
+ })(NestedDataView);
1419
+ ZoomIntoPropertyView.prototype.rootName = "$root";
1420
+
1421
+ function createStructuredSelector(selector, constants) {
1422
+ var keys = Object.keys(selector);
1423
+ if (keys.length == 0)
1424
+ return function() {
1425
+ return constants;
1426
+ };
1427
+
1428
+ function memoize() {
1429
+ var lastResult = Object.assign({}, constants);
1430
+ var memoizedSelectors = {};
1431
+ keys.forEach(function(key) {
1432
+ memoizedSelectors[key] = selector[key].memoize ? selector[key].memoize() : selector[key];
1433
+ lastResult[key] = undefined;
1434
+ });
1435
+ return function(data) {
1436
+ var result = lastResult,
1437
+ k,
1438
+ v,
1439
+ i;
1440
+
1441
+ for (i = 0; i < keys.length; i++) {
1442
+ k = keys[i];
1443
+ v = memoizedSelectors[k](data);
1444
+
1445
+ if (result === lastResult) {
1446
+ if (v === lastResult[k]) continue;
1447
+ result = Object.assign({}, lastResult);
1448
+ }
1449
+
1450
+ result[k] = v;
1451
+ }
1452
+
1453
+ return (lastResult = result);
1454
+ };
1455
+ }
1456
+
1457
+ function evaluate(data) {
1458
+ var result = Object.assign({}, constants);
1459
+
1460
+ for (var i = 0; i < keys.length; i++) {
1461
+ result[keys[i]] = selector[keys[i]](data);
1462
+ }
1463
+
1464
+ return result;
1465
+ }
1466
+
1467
+ evaluate.memoize = memoize;
1468
+ return evaluate;
1469
+ }
1470
+
1471
+ function isSelector(config) {
1472
+ if (config == null) return true;
1473
+
1474
+ switch (typeof config) {
1475
+ case "object":
1476
+ if (config.type || config.$type) return false;
1477
+ return !!(config.bind || config.tpl || config.expr || config.get);
1478
+
1479
+ case "function":
1480
+ return true;
1481
+
1482
+ case "string":
1483
+ return true;
1484
+
1485
+ case "number":
1486
+ return true;
1487
+
1488
+ case "boolean":
1489
+ return true;
1490
+ }
1491
+
1492
+ return false;
1493
+ }
1494
+
1495
+ var undefinedF = function undefinedF() {
1496
+ return undefined;
1497
+ };
1498
+
1499
+ var nullF = function nullF() {
1500
+ return null;
1501
+ };
1502
+
1503
+ function getSelector(config) {
1504
+ if (config === undefined) return undefinedF;
1505
+ if (config === null) return nullF;
1506
+
1507
+ switch (typeof config) {
1508
+ case "object":
1509
+ if (isArray(config)) {
1510
+ var _selectors = config.map(function(x) {
1511
+ return getSelector(x);
1512
+ });
1513
+
1514
+ return function(data) {
1515
+ return _selectors.map(function(elementSelector) {
1516
+ return elementSelector(data);
1517
+ });
1518
+ };
1519
+ } //toString converts accessor chains to binding paths
1520
+
1521
+ if (config.bind) return Binding.get(config.bind.toString()).value;
1522
+ if (config.tpl) return StringTemplate.get(config.tpl);
1523
+ if (config.expr) return Expression.get(config.expr);
1524
+ if (config.get) return config.get;
1525
+ var selectors = {};
1526
+ var constants = {};
1527
+
1528
+ for (var key in config) {
1529
+ if (isSelector(config[key])) selectors[key] = getSelector(config[key]);
1530
+ else constants[key] = config[key];
1531
+ }
1532
+
1533
+ return createStructuredSelector(selectors, constants);
1534
+
1535
+ case "function":
1536
+ if (isAccessorChain(config)) return Binding.get(config.toString()).value;
1537
+ return config;
1538
+
1539
+ default:
1540
+ return function() {
1541
+ return config;
1542
+ };
1543
+ }
1544
+ }
1545
+
1546
+ function defaultValue(pv) {
1547
+ if (typeof pv == "object" && pv && pv.structured) return pv.defaultValue;
1548
+ return pv;
1549
+ }
1550
+
1551
+ function getSelectorConfig(props, values, nameMap) {
1552
+ var functions = {},
1553
+ structures = {},
1554
+ defaultValues = {},
1555
+ constants,
1556
+ p,
1557
+ v,
1558
+ pv,
1559
+ constant = true;
1560
+
1561
+ for (p in props) {
1562
+ v = values[p];
1563
+ pv = props[p];
1564
+ if (isUndefined(v) && pv && (pv.bind || pv.tpl || pv.expr)) v = pv;
1565
+
1566
+ if (v === null) {
1567
+ if (!constants) constants = {};
1568
+ constants[p] = null;
1569
+ } else if (typeof v == "object") {
1570
+ if (v.bind) {
1571
+ if (isUndefined(v.defaultValue) && v != pv) v.defaultValue = defaultValue(pv);
1572
+ if (isDefined(v.defaultValue)) defaultValues[v.bind] = v.defaultValue;
1573
+ nameMap[p] = v.bind;
1574
+ functions[p] = Binding.get(v.bind).value;
1575
+ constant = false;
1576
+ } else if (v.expr) {
1577
+ functions[p] = Expression.get(v.expr);
1578
+ constant = false;
1579
+ } else if (v.get) {
1580
+ functions[p] = v.get;
1581
+ constant = false;
1582
+ } else if (v.tpl) {
1583
+ functions[p] = StringTemplate.get(v.tpl);
1584
+ constant = false;
1585
+ } else if (pv && typeof pv == "object" && pv.structured) {
1586
+ if (isArray(v)) functions[p] = getSelector(v);
1587
+ else {
1588
+ var s = getSelectorConfig(v, v, {});
1589
+ structures[p] = s;
1590
+ Object.assign(defaultValues, s.defaultValues);
1591
+ }
1592
+ constant = false;
1593
+ } else {
1594
+ if (!constants) constants = {};
1595
+ constants[p] = v;
1596
+ }
1597
+ } else if (isFunction(v)) {
1598
+ if (isAccessorChain(v)) {
1599
+ var path = v.toString();
1600
+ nameMap[p] = path;
1601
+ functions[p] = Binding.get(path).value;
1602
+ } else functions[p] = v;
1603
+
1604
+ constant = false;
1605
+ } else {
1606
+ if (isUndefined(v)) {
1607
+ if (isUndefined(pv)) continue;
1608
+ v = defaultValue(pv);
1609
+ }
1610
+
1611
+ if (isUndefined(v)) continue;
1612
+ if (!constants) constants = {};
1613
+ constants[p] = v;
1614
+ }
1615
+ }
1616
+
1617
+ return {
1618
+ functions: functions,
1619
+ structures: structures,
1620
+ defaultValues: defaultValues,
1621
+ constants: constants,
1622
+ constant: constant
1623
+ };
1624
+ }
1625
+
1626
+ function createSelector(_ref) {
1627
+ var functions = _ref.functions,
1628
+ structures = _ref.structures,
1629
+ constants = _ref.constants,
1630
+ defaultValues = _ref.defaultValues;
1631
+ var selector = {};
1632
+
1633
+ for (var n in functions) {
1634
+ selector[n] = functions[n];
1635
+ }
1636
+
1637
+ for (var _n in structures) {
1638
+ selector[_n] = createSelector(structures[_n]);
1639
+ }
1640
+
1641
+ return createStructuredSelector(selector, constants);
1642
+ }
1643
+
1644
+ var StructuredSelector = /*#__PURE__*/ (function() {
1645
+ function StructuredSelector(_ref2) {
1646
+ var props = _ref2.props,
1647
+ values = _ref2.values;
1648
+ this.nameMap = {};
1649
+ this.config = getSelectorConfig(props, values, this.nameMap);
1650
+ }
1651
+
1652
+ var _proto = StructuredSelector.prototype;
1653
+
1654
+ _proto.init = function init(store) {
1655
+ store.init(this.config.defaultValues);
1656
+ };
1657
+
1658
+ _proto.create = function create() {
1659
+ var selector = createSelector(this.config);
1660
+ if (selector.memoize) return selector.memoize();
1661
+ return selector;
1662
+ };
1663
+
1664
+ _proto.createStoreSelector = function createStoreSelector() {
1665
+ if (this.config.constant) {
1666
+ var result = _objectSpread2({}, this.config.constants);
1667
+
1668
+ return function() {
1669
+ return result;
1670
+ };
1671
+ }
1672
+
1673
+ var selector = this.create();
1674
+ return function(store) {
1675
+ return selector(store.getData());
1676
+ };
1677
+ };
1678
+
1679
+ return StructuredSelector;
1680
+ })();
1681
+
1682
+ var AggregateFunction = /*#__PURE__*/ (function() {
1683
+ function AggregateFunction() {}
1684
+
1685
+ AggregateFunction.sum = function sum() {
1686
+ return new Sum();
1687
+ };
1688
+
1689
+ AggregateFunction.avg = function avg() {
1690
+ return new Avg();
1691
+ };
1692
+
1693
+ AggregateFunction.count = function count() {
1694
+ return new Count();
1695
+ };
1696
+
1697
+ AggregateFunction.distinct = function distinct() {
1698
+ return new Distinct();
1699
+ };
1700
+
1701
+ AggregateFunction.min = function min() {
1702
+ return new Min();
1703
+ };
1704
+
1705
+ AggregateFunction.max = function max() {
1706
+ return new Max();
1707
+ };
1708
+
1709
+ return AggregateFunction;
1710
+ })();
1711
+
1712
+ var Sum = /*#__PURE__*/ (function() {
1713
+ function Sum() {}
1714
+
1715
+ var _proto = Sum.prototype;
1716
+
1717
+ _proto.process = function process(value) {
1718
+ this.empty = false;
1719
+ if (!isNaN(value)) this.result += value;
1720
+ else this.invalid = true;
1721
+ };
1722
+
1723
+ _proto.getResult = function getResult() {
1724
+ if (this.invalid) return null;
1725
+ return this.result;
1726
+ };
1727
+
1728
+ return Sum;
1729
+ })();
1730
+
1731
+ Sum.prototype.result = 0;
1732
+ Sum.prototype.empty = true;
1733
+
1734
+ var Avg = /*#__PURE__*/ (function() {
1735
+ function Avg() {}
1736
+
1737
+ var _proto2 = Avg.prototype;
1738
+
1739
+ _proto2.process = function process(value, count) {
1740
+ if (count === void 0) {
1741
+ count = 1;
1742
+ }
1743
+
1744
+ this.empty = false;
1745
+
1746
+ if (!isNaN(value) && !isNaN(count)) {
1747
+ this.result += value * count;
1748
+ this.count += count;
1749
+ } else this.invalid = true;
1750
+ };
1751
+
1752
+ _proto2.getResult = function getResult() {
1753
+ if (this.empty || this.invalid || this.count == 0) return null;
1754
+ return this.result / this.count;
1755
+ };
1756
+
1757
+ return Avg;
1758
+ })();
1759
+
1760
+ Avg.prototype.result = 0;
1761
+ Avg.prototype.count = 0;
1762
+ Avg.prototype.empty = true;
1763
+
1764
+ var Count = /*#__PURE__*/ (function() {
1765
+ function Count() {}
1766
+
1767
+ var _proto3 = Count.prototype;
1768
+
1769
+ _proto3.process = function process(value) {
1770
+ if (value != null) this.result++;
1771
+ };
1772
+
1773
+ _proto3.getResult = function getResult() {
1774
+ return this.result;
1775
+ };
1776
+
1777
+ return Count;
1778
+ })();
1779
+
1780
+ Count.prototype.result = 0;
1781
+
1782
+ var Distinct = /*#__PURE__*/ (function() {
1783
+ function Distinct() {
1784
+ this.values = {};
1785
+ }
1786
+
1787
+ var _proto4 = Distinct.prototype;
1788
+
1789
+ _proto4.process = function process(value) {
1790
+ if (value == null || this.values[value]) return;
1791
+ this.values[value] = true;
1792
+ this.empty = false;
1793
+ this.result++;
1794
+ };
1795
+
1796
+ _proto4.getResult = function getResult() {
1797
+ if (this.empty || this.invalid) return null;
1798
+ return this.result;
1799
+ };
1800
+
1801
+ return Distinct;
1802
+ })();
1803
+
1804
+ Distinct.prototype.result = 0;
1805
+ Distinct.prototype.empty = true;
1806
+
1807
+ var Max = /*#__PURE__*/ (function() {
1808
+ function Max() {}
1809
+
1810
+ var _proto5 = Max.prototype;
1811
+
1812
+ _proto5.process = function process(value) {
1813
+ if (!isNaN(value)) {
1814
+ if (this.empty) this.result = value;
1815
+ else if (value > this.result) this.result = value;
1816
+ this.empty = false;
1817
+ } else if (value != null) this.invalid = true;
1818
+ };
1819
+
1820
+ _proto5.getResult = function getResult() {
1821
+ if (this.empty || this.invalid) return null;
1822
+ return this.result;
1823
+ };
1824
+
1825
+ return Max;
1826
+ })();
1827
+
1828
+ Max.prototype.result = 0;
1829
+ Max.prototype.empty = true;
1830
+
1831
+ var Min = /*#__PURE__*/ (function() {
1832
+ function Min() {}
1833
+
1834
+ var _proto6 = Min.prototype;
1835
+
1836
+ _proto6.process = function process(value) {
1837
+ if (!isNaN(value)) {
1838
+ if (this.empty) this.result = value;
1839
+ else if (value < this.result) this.result = value;
1840
+ this.empty = false;
1841
+ } else if (value != null) this.invalid = true;
1842
+ };
1843
+
1844
+ _proto6.getResult = function getResult() {
1845
+ if (this.empty || this.invalid) return null;
1846
+ return this.result;
1847
+ };
1848
+
1849
+ return Min;
1850
+ })();
1851
+
1852
+ Min.prototype.result = 0;
1853
+ Min.prototype.empty = true;
1854
+
1855
+ /*
1856
+ 'column': {
1857
+ index: 0,
1858
+ sort: 'asc',
1859
+ group: true
1860
+ aggregate: 'count'
1861
+ }
1862
+ */
1863
+
1864
+ function transform(o, f) {
1865
+ var res = {};
1866
+
1867
+ for (var k in o) {
1868
+ res[k] = f(o[k], k);
1869
+ }
1870
+
1871
+ return res;
1872
+ }
1873
+
1874
+ var Grouper = /*#__PURE__*/ (function() {
1875
+ function Grouper(key, aggregates, dataGetter, nameGetter) {
1876
+ this.keys = Object.keys(key).map(function(k) {
1877
+ return {
1878
+ name: k,
1879
+ value: getSelector(key[k])
1880
+ };
1881
+ });
1882
+ if (nameGetter) this.nameGetter = getSelector(nameGetter);
1883
+
1884
+ this.dataGetter =
1885
+ dataGetter ||
1886
+ function(x) {
1887
+ return x;
1888
+ };
1889
+
1890
+ this.aggregates =
1891
+ aggregates &&
1892
+ transform(aggregates, function(prop) {
1893
+ if (!AggregateFunction[prop.type]) throw new Error("Unknown aggregate function '" + prop.type + "'.");
1894
+ return {
1895
+ value: getSelector(prop.value),
1896
+ weight: getSelector(prop.weight || 1),
1897
+ type: prop.type
1898
+ };
1899
+ });
1900
+ this.reset();
1901
+ }
1902
+
1903
+ var _proto = Grouper.prototype;
1904
+
1905
+ _proto.reset = function reset() {
1906
+ this.groups = this.initGroup(this.keys.length == 0);
1907
+ };
1908
+
1909
+ _proto.initGroup = function initGroup(leaf) {
1910
+ if (!leaf) return {};
1911
+ return {
1912
+ records: [],
1913
+ indexes: [],
1914
+ aggregates:
1915
+ this.aggregates &&
1916
+ transform(this.aggregates, function(prop) {
1917
+ var f = AggregateFunction[prop.type];
1918
+ return {
1919
+ processor: f(),
1920
+ value: prop.value,
1921
+ weight: prop.weight
1922
+ };
1923
+ })
1924
+ };
1925
+ };
1926
+
1927
+ _proto.process = function process(record, index) {
1928
+ var data = this.dataGetter(record);
1929
+ var key = this.keys.map(function(k) {
1930
+ return k.value(data);
1931
+ });
1932
+ var g = this.groups;
1933
+
1934
+ for (var i = 0; i < key.length; i++) {
1935
+ var sg = g[key[i]];
1936
+
1937
+ if (!sg) {
1938
+ sg = g[key[i]] = this.initGroup(i + 1 == key.length);
1939
+ if (this.nameGetter) sg.name = this.nameGetter(data);
1940
+ }
1941
+
1942
+ g = sg;
1943
+ }
1944
+
1945
+ g.records.push(record);
1946
+ g.indexes.push(index);
1947
+
1948
+ if (g.aggregates) {
1949
+ for (var k in g.aggregates) {
1950
+ g.aggregates[k].processor.process(g.aggregates[k].value(data), g.aggregates[k].weight(data));
1951
+ }
1952
+ }
1953
+ };
1954
+
1955
+ _proto.processAll = function processAll(records, indexes) {
1956
+ var _this = this;
1957
+
1958
+ if (indexes) {
1959
+ for (var i = 0; i < records.length; i++) {
1960
+ this.process(records[i], indexes[i]);
1961
+ }
1962
+ } else
1963
+ records.forEach(function(r, i) {
1964
+ return _this.process(r, i);
1965
+ });
1966
+ };
1967
+
1968
+ _proto.report = function report(g, path, level, results) {
1969
+ var _this2 = this;
1970
+
1971
+ if (level == this.keys.length) {
1972
+ var key = {};
1973
+ this.keys.forEach(function(k, i) {
1974
+ return (key[k.name] = path[i]);
1975
+ });
1976
+ results.push({
1977
+ key: key,
1978
+ name: g.name,
1979
+ records: g.records,
1980
+ indexes: g.indexes,
1981
+ aggregates: transform(g.aggregates, function(p) {
1982
+ return p.processor.getResult();
1983
+ })
1984
+ });
1985
+ } else {
1986
+ Object.keys(g).forEach(function(k) {
1987
+ return _this2.report(g[k], [].concat(path, [k]), level + 1, results);
1988
+ });
1989
+ }
1990
+ };
1991
+
1992
+ _proto.getResults = function getResults() {
1993
+ var g = this.groups;
1994
+ var results = [];
1995
+ this.report(g, [], 0, results);
1996
+ return results;
1997
+ };
1998
+
1999
+ return Grouper;
2000
+ })();
2001
+
2002
+ function defaultCompare(av, bv) {
2003
+ if (av == null) {
2004
+ if (bv == null) return 0;
2005
+ return -1;
2006
+ }
2007
+
2008
+ if (bv == null || av > bv) return 1;
2009
+ if (av < bv) return -1;
2010
+ return 0;
2011
+ }
2012
+
2013
+ function getComparer(sorters, dataAccessor, comparer) {
2014
+ var data = (sorters || []).map(function(s) {
2015
+ var selector = isDefined(s.value)
2016
+ ? getSelector(s.value)
2017
+ : s.field
2018
+ ? function(x) {
2019
+ return x[s.field];
2020
+ }
2021
+ : function() {
2022
+ return null;
2023
+ };
2024
+ return {
2025
+ getter: dataAccessor
2026
+ ? function(x) {
2027
+ return selector(dataAccessor(x));
2028
+ }
2029
+ : selector,
2030
+ factor: s.direction && s.direction[0].toLowerCase() == "d" ? -1 : 1,
2031
+ compare: s.comparer || s.compare || comparer || defaultCompare
2032
+ };
2033
+ });
2034
+ return function(a, b) {
2035
+ var d, av, bv;
2036
+
2037
+ for (var i = 0; i < data.length; i++) {
2038
+ d = data[i];
2039
+ av = d.getter(a);
2040
+ bv = d.getter(b); // show nulls always on the bottom
2041
+
2042
+ if (av == null) return bv == null ? 0 : 1;
2043
+ if (bv == null) return -1;
2044
+ var r = d.compare(av, bv);
2045
+ if (r == 0) continue;
2046
+ return d.factor * r;
2047
+ }
2048
+
2049
+ return 0;
2050
+ };
2051
+ }
2052
+ function indexSorter(sorters, dataAccessor, compare) {
2053
+ var cmp = getComparer(sorters, dataAccessor, compare);
2054
+ return function(data) {
2055
+ var result = Array.from(
2056
+ {
2057
+ length: data.length
2058
+ },
2059
+ function(v, k) {
2060
+ return k;
2061
+ }
2062
+ );
2063
+ result.sort(function(ia, ib) {
2064
+ return cmp(data[ia], data[ib]);
2065
+ });
2066
+ return result;
2067
+ };
2068
+ }
2069
+ function sorter(sorters, dataAccessor, compare) {
2070
+ var cmp = getComparer(sorters, dataAccessor, compare);
2071
+ return function(data) {
2072
+ var result = [].concat(data);
2073
+ result.sort(cmp);
2074
+ return result;
2075
+ };
2076
+ }
2077
+
2078
+ function enableFatArrowExpansion() {
2079
+ plugFatArrowExpansion(expandFatArrows);
2080
+ }
2081
+
2082
+ function append(array) {
2083
+ for (var _len = arguments.length, items = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
2084
+ items[_key - 1] = arguments[_key];
2085
+ }
2086
+
2087
+ if (items.length == 0) return array;
2088
+ if (!array) return items;
2089
+ return [].concat(array, items);
2090
+ }
2091
+
2092
+ function merge(item, data) {
2093
+ var result = item;
2094
+ if (data)
2095
+ for (var key in data) {
2096
+ result = Binding.get(key).set(result, data[key]);
2097
+ }
2098
+ return result;
2099
+ }
2100
+
2101
+ function filter(array, callback) {
2102
+ if (array == null) return array;
2103
+ var result = array.filter(callback);
2104
+ if (result.length == array.length) return array;
2105
+ return result;
2106
+ }
2107
+
2108
+ function updateArray(array, updateCallback, itemFilter, removeFilter) {
2109
+ if (!array) return array;
2110
+ var newArray = [];
2111
+ var dirty = false;
2112
+
2113
+ for (var index = 0; index < array.length; index++) {
2114
+ var item = array[index];
2115
+
2116
+ if (removeFilter && removeFilter(item, index)) {
2117
+ dirty = true;
2118
+ continue;
2119
+ }
2120
+
2121
+ if (!itemFilter || itemFilter(item, index)) {
2122
+ var newItem = updateCallback(item, index);
2123
+ newArray.push(newItem);
2124
+ if (newItem !== item) dirty = true;
2125
+ } else newArray.push(item);
2126
+ }
2127
+
2128
+ return dirty ? newArray : array;
2129
+ }
2130
+
2131
+ function updateTree(array, updateCallback, itemFilter, childrenField, removeFilter) {
2132
+ return updateArray(
2133
+ array,
2134
+ function(item) {
2135
+ var _objectSpread2$1;
2136
+
2137
+ if (!itemFilter || itemFilter(item)) item = updateCallback(item);
2138
+ var children = item[childrenField];
2139
+ if (!Array.isArray(children)) return item;
2140
+ var updatedChildren = updateTree(children, updateCallback, itemFilter, childrenField, removeFilter);
2141
+ if (updatedChildren != children)
2142
+ return _objectSpread2(
2143
+ _objectSpread2({}, item),
2144
+ {},
2145
+ ((_objectSpread2$1 = {}), (_objectSpread2$1[childrenField] = updatedChildren), _objectSpread2$1)
2146
+ );
2147
+ return item;
2148
+ },
2149
+ null,
2150
+ removeFilter
2151
+ );
2152
+ }
2153
+
2154
+ function removeTreeNodes(array, criteria, childrenField) {
2155
+ if (childrenField === void 0) {
2156
+ childrenField = "$children";
2157
+ }
2158
+
2159
+ return updateTree(
2160
+ array,
2161
+ null,
2162
+ function() {
2163
+ return false;
2164
+ },
2165
+ childrenField,
2166
+ criteria
2167
+ );
2168
+ }
2169
+
2170
+ function findTreeNode(array, criteria, childrenField) {
2171
+ if (childrenField === void 0) {
2172
+ childrenField = "$children";
2173
+ }
2174
+
2175
+ if (!Array.isArray(array)) return false;
2176
+
2177
+ for (var i = 0; i < array.length; i++) {
2178
+ if (criteria(array[i])) return array[i];
2179
+ var child = findTreeNode(array[i][childrenField], criteria, childrenField);
2180
+ if (child) return child;
2181
+ }
2182
+
2183
+ return false;
2184
+ }
2185
+
2186
+ function moveElement(array, sourceIndex, targetIndex) {
2187
+ if (targetIndex == sourceIndex) return array;
2188
+ var el = array[sourceIndex];
2189
+ var res = [].concat(array);
2190
+
2191
+ if (sourceIndex < targetIndex) {
2192
+ for (var i = sourceIndex; i + 1 < targetIndex; i++) {
2193
+ res[i] = res[i + 1];
2194
+ }
2195
+
2196
+ targetIndex--;
2197
+ } else {
2198
+ for (var _i = sourceIndex; _i > targetIndex; _i--) {
2199
+ res[_i] = res[_i - 1];
2200
+ }
2201
+ }
2202
+
2203
+ res[targetIndex] = el;
2204
+ return res;
2205
+ }
2206
+
2207
+ function insertElement(array, index) {
2208
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
2209
+ args[_key - 2] = arguments[_key];
2210
+ }
2211
+
2212
+ return [].concat(array.slice(0, index), args, array.slice(index));
2213
+ }
2214
+
2215
+ function diffArrays(oldArray, newArray, keyFn) {
2216
+ if (!keyFn)
2217
+ keyFn = function keyFn(e) {
2218
+ return e;
2219
+ };
2220
+ var map = new Map();
2221
+
2222
+ for (var i = 0; i < oldArray.length; i++) {
2223
+ map.set(keyFn(oldArray[i]), oldArray[i]);
2224
+ }
2225
+
2226
+ var added = [],
2227
+ changed = [],
2228
+ unchanged = [];
2229
+
2230
+ for (var _i = 0; _i < newArray.length; _i++) {
2231
+ var el = newArray[_i];
2232
+ var k = keyFn(el);
2233
+ var old = map.get(k);
2234
+ if (isUndefined(old)) added.push(el);
2235
+ else {
2236
+ map["delete"](k);
2237
+ if (el == old) unchanged.push(el);
2238
+ else
2239
+ changed.push({
2240
+ before: old,
2241
+ after: el
2242
+ });
2243
+ }
2244
+ }
2245
+
2246
+ var removed = Array.from(map.values());
2247
+ return {
2248
+ added: added,
2249
+ changed: changed,
2250
+ unchanged: unchanged,
2251
+ removed: removed
2252
+ };
2253
+ }
2254
+
2255
+ var ArrayRef = /*#__PURE__*/ (function(_Ref) {
2256
+ _inheritsLoose(ArrayRef, _Ref);
2257
+
2258
+ function ArrayRef() {
2259
+ return _Ref.apply(this, arguments) || this;
2260
+ }
2261
+
2262
+ var _proto = ArrayRef.prototype;
2263
+
2264
+ _proto.append = function append$1() {
2265
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2266
+ args[_key] = arguments[_key];
2267
+ }
2268
+
2269
+ this.update.apply(this, [append].concat(args));
2270
+ };
2271
+
2272
+ _proto.insert = function insert(index) {
2273
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
2274
+ args[_key2 - 1] = arguments[_key2];
2275
+ }
2276
+
2277
+ this.update.apply(this, [insertElement].concat(args));
2278
+ };
2279
+
2280
+ _proto.filter = function filter(predicate) {
2281
+ this.update(function(array) {
2282
+ return array.filter(function(a) {
2283
+ return predicate(a);
2284
+ });
2285
+ });
2286
+ };
2287
+
2288
+ _proto.move = function move(fromIndex, toIndex) {
2289
+ this.update(moveElement, fromIndex, toIndex);
2290
+ };
2291
+
2292
+ _proto.clear = function clear() {
2293
+ this.set([]);
2294
+ };
2295
+
2296
+ _proto.sort = function sort(compare) {
2297
+ var data = this.get();
2298
+ if (!data) return;
2299
+ var x = [].concat(data);
2300
+ x.sort(compare);
2301
+ this.set(x);
2302
+ };
2303
+
2304
+ return ArrayRef;
2305
+ })(Ref);
2306
+
2307
+ var StoreProxy = /*#__PURE__*/ (function(_View) {
2308
+ _inheritsLoose(StoreProxy, _View);
2309
+
2310
+ function StoreProxy(getStore) {
2311
+ var _this;
2312
+
2313
+ _this =
2314
+ _View.call(this, {
2315
+ store: getStore()
2316
+ }) || this;
2317
+ Object.defineProperty(_assertThisInitialized(_this), "store", {
2318
+ get: getStore
2319
+ });
2320
+ return _this;
2321
+ }
2322
+
2323
+ var _proto = StoreProxy.prototype;
2324
+
2325
+ _proto.getData = function getData() {
2326
+ return this.store.getData();
2327
+ };
2328
+
2329
+ return StoreProxy;
2330
+ })(View);
2331
+
2332
+ var ArrayElementView = /*#__PURE__*/ (function(_AugmentedViewBase) {
2333
+ _inheritsLoose(ArrayElementView, _AugmentedViewBase);
2334
+
2335
+ function ArrayElementView() {
2336
+ return _AugmentedViewBase.apply(this, arguments) || this;
2337
+ }
2338
+
2339
+ var _proto = ArrayElementView.prototype;
2340
+
2341
+ _proto.isExtraKey = function isExtraKey(key) {
2342
+ return key == this.recordAlias || key == this.indexAlias || key == this.lengthAlias;
2343
+ };
2344
+
2345
+ _proto.deleteExtraKeyValue = function deleteExtraKeyValue(key) {
2346
+ if (key != this.recordAlias) throw new Error("Field " + key + " cannot be deleted.");
2347
+ var array = this.arrayAccessor.get(this.store.getData());
2348
+ if (!array) return false;
2349
+ var newArray = [].concat(array.slice(0, this.itemIndex), array.slice(this.itemIndex + 1));
2350
+ return this.arrayAccessor.set(newArray, this.store);
2351
+ };
2352
+
2353
+ _proto.setExtraKeyValue = function setExtraKeyValue(key, value) {
2354
+ if (key != this.recordAlias) throw new Error("Field " + key + " is read-only.");
2355
+ var array = this.arrayAccessor.get(this.store.getData());
2356
+ if (!array || value === array[this.itemIndex]) return false;
2357
+ var newArray = [].concat(array.slice(0, this.itemIndex), [value], array.slice(this.itemIndex + 1));
2358
+ return this.arrayAccessor.set(newArray, this.store);
2359
+ };
2360
+
2361
+ _proto.embedAugmentData = function embedAugmentData(result, parentStoreData) {
2362
+ var array = this.arrayAccessor.get(parentStoreData);
2363
+ if (!isArray(array)) return;
2364
+ result[this.recordAlias] = array[this.itemIndex];
2365
+ result[this.indexAlias] = this.itemIndex;
2366
+ result[this.lengthAlias] = array.length;
2367
+ };
2368
+
2369
+ _proto.setIndex = function setIndex(itemIndex) {
2370
+ this.itemIndex = itemIndex;
2371
+ };
2372
+
2373
+ return ArrayElementView;
2374
+ })(AugmentedViewBase);
2375
+ ArrayElementView.prototype.recordAlias = "$record";
2376
+ ArrayElementView.prototype.indexAlias = "$index";
2377
+ ArrayElementView.prototype.lengthAlias = "$length";
2378
+
2379
+ /*
2380
+ Accessor provides a common ground between refs and bindings.
2381
+ Refs offer simplicity, bindings have better performance with more arguments.
2382
+ Accessor works as a common interface which works with both patterns.
2383
+ */
2384
+
2385
+ function getAccessor(accessor, options) {
2386
+ if (accessor == null) return null;
2387
+
2388
+ if (isObject(accessor)) {
2389
+ if (accessor.isAccessor || accessor.isRef) return accessor;
2390
+
2391
+ if (isBinding(accessor)) {
2392
+ var binding = Binding.get(accessor);
2393
+ return {
2394
+ get: binding.value,
2395
+ set: function set(v, store) {
2396
+ return store.set(binding.path, v);
2397
+ },
2398
+ isAccessor: true
2399
+ };
2400
+ }
2401
+ }
2402
+
2403
+ if (isAccessorChain(accessor)) {
2404
+ var _binding = Binding.get(accessor);
2405
+
2406
+ return {
2407
+ get: _binding.value,
2408
+ set: function set(v, store) {
2409
+ return store.set(_binding.path, v);
2410
+ },
2411
+ isAccessor: true
2412
+ };
2413
+ }
2414
+
2415
+ if (isSelector(accessor)) {
2416
+ var selector = getSelector(accessor);
2417
+ if (accessor && accessor.set)
2418
+ return {
2419
+ get: selector,
2420
+ isAccessor: true,
2421
+ bindInstance: function bindInstance(instance) {
2422
+ return {
2423
+ get: selector,
2424
+ set: function set(value) {
2425
+ return accessor.set(value, instance);
2426
+ },
2427
+ isAccessor: true
2428
+ };
2429
+ }
2430
+ };
2431
+ return {
2432
+ get: selector,
2433
+ isAccessor: true
2434
+ };
2435
+ }
2436
+
2437
+ return {
2438
+ get: function get() {
2439
+ return accessor;
2440
+ }
2441
+ };
2442
+ }
2443
+
2444
+ export {
2445
+ ArrayElementView,
2446
+ ArrayRef,
2447
+ AugmentedViewBase,
2448
+ Binding,
2449
+ ExposedRecordView,
2450
+ ExposedValueView,
2451
+ Expression,
2452
+ Grouper,
2453
+ NestedDataView,
2454
+ ReadOnlyDataView,
2455
+ Ref,
2456
+ Store,
2457
+ StoreProxy,
2458
+ StringTemplate,
2459
+ StructuredSelector,
2460
+ SubscribableView,
2461
+ View,
2462
+ ZoomIntoPropertyView,
2463
+ append,
2464
+ computable,
2465
+ createAccessorModelProxy,
2466
+ defaultCompare,
2467
+ diffArrays,
2468
+ enableFatArrowExpansion,
2469
+ expression,
2470
+ filter,
2471
+ findTreeNode,
2472
+ getAccessor,
2473
+ getComparer,
2474
+ getSelector,
2475
+ indexSorter,
2476
+ insertElement,
2477
+ invalidateExpressionCache,
2478
+ invalidateStringTemplateCache,
2479
+ isAccessorChain,
2480
+ isBinding,
2481
+ isSelector,
2482
+ merge,
2483
+ moveElement,
2484
+ plugFatArrowExpansion,
2485
+ removeTreeNodes,
2486
+ sorter,
2487
+ stringTemplate,
2488
+ updateArray,
2489
+ updateTree
2490
+ };