cx 22.3.3 → 22.3.4

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