cx 22.12.1 → 22.12.2

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