@mwater/visualization 5.4.0 → 5.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (271) hide show
  1. package/lib/ColorComponent.js +2 -1
  2. package/lib/IdSelection.d.ts +16 -0
  3. package/lib/IdSelection.js +59 -0
  4. package/lib/MWaterAddRelatedIndicatorComponent.js +2 -2
  5. package/lib/MWaterCompleteTableSelectComponent.d.ts +3 -8
  6. package/lib/MWaterCompleteTableSelectComponent.js +36 -42
  7. package/lib/MWaterLoaderComponent.d.ts +11 -10
  8. package/lib/MWaterLoaderComponent.js +1 -1
  9. package/lib/MWaterResponsesFilterComponent.js +1 -1
  10. package/lib/MWaterTableSelectComponent.d.ts +0 -1
  11. package/lib/MWaterTableSelectComponent.js +4 -6
  12. package/lib/autotranslate.d.ts +20 -0
  13. package/lib/autotranslate.js +122 -0
  14. package/lib/axes/AxisBuilder.js +3 -3
  15. package/lib/axes/AxisColorEditorComponent.js +4 -0
  16. package/lib/axes/AxisComponent.d.ts +8 -12
  17. package/lib/axes/AxisComponent.js +32 -80
  18. package/lib/axes/CategoryMapComponent.js +4 -4
  19. package/lib/axes/RangesComponent.js +2 -2
  20. package/lib/dashboards/DashboardComponent.d.ts +6 -0
  21. package/lib/dashboards/DashboardComponent.js +44 -12
  22. package/lib/dashboards/DashboardDesign.d.ts +11 -2
  23. package/lib/dashboards/DashboardUtils.d.ts +5 -0
  24. package/lib/dashboards/DashboardUtils.js +30 -0
  25. package/lib/dashboards/DashboardViewComponent.d.ts +2 -0
  26. package/lib/dashboards/DashboardViewComponent.js +16 -3
  27. package/lib/dashboards/ServerDashboardDataSource.js +2 -1
  28. package/lib/dashboards/SettingsModalComponent.d.ts +1 -1
  29. package/lib/dashboards/SettingsModalComponent.js +256 -19
  30. package/lib/dashboards/WidgetComponent.d.ts +6 -3
  31. package/lib/dashboards/WidgetComponent.js +3 -1
  32. package/lib/datagrids/CellEditor.d.ts +19 -0
  33. package/lib/datagrids/CellEditor.js +223 -0
  34. package/lib/datagrids/DatagridComponent.d.ts +18 -87
  35. package/lib/datagrids/DatagridComponent.js +304 -222
  36. package/lib/datagrids/DatagridViewComponent.d.ts +15 -53
  37. package/lib/datagrids/DatagridViewComponent.js +256 -257
  38. package/lib/datagrids/DirectDatagridDataSource.js +2 -3
  39. package/lib/datagrids/ExprCellComponent.d.ts +8 -15
  40. package/lib/datagrids/ExprCellComponent.js +11 -15
  41. package/lib/datagrids/FindReplaceModalComponent.d.ts +4 -6
  42. package/lib/datagrids/FindReplaceModalComponent.js +38 -75
  43. package/lib/index.css +1 -1
  44. package/lib/index.d.ts +0 -1
  45. package/lib/index.js +0 -1
  46. package/lib/layouts/blocks/HorizontalBlockComponent.js +2 -2
  47. package/lib/mWaterLoader.d.ts +1 -1
  48. package/lib/maps/BufferLayer.d.ts +7 -5
  49. package/lib/maps/BufferLayer.js +69 -48
  50. package/lib/maps/BufferLayerDesign.d.ts +21 -14
  51. package/lib/maps/BufferLayerDesignerComponent.d.ts +16 -31
  52. package/lib/maps/BufferLayerDesignerComponent.js +68 -102
  53. package/lib/maps/ChoroplethLayer.d.ts +5 -4
  54. package/lib/maps/ChoroplethLayer.js +32 -9
  55. package/lib/maps/ChoroplethLayerDesign.d.ts +6 -2
  56. package/lib/maps/ChoroplethLayerDesigner.js +4 -2
  57. package/lib/maps/ClusterLayer.d.ts +3 -4
  58. package/lib/maps/ClusterLayer.js +2 -1
  59. package/lib/maps/DetailLevelSelectComponent.js +1 -1
  60. package/lib/maps/DirectMapDataSource.js +2 -1
  61. package/lib/maps/EditPopupComponent.js +5 -3
  62. package/lib/maps/GridLayer.d.ts +3 -4
  63. package/lib/maps/GridLayer.js +2 -1
  64. package/lib/maps/GridLayerDesigner.js +5 -3
  65. package/lib/maps/HoverContent.d.ts +11 -3
  66. package/lib/maps/HoverContent.js +25 -9
  67. package/lib/maps/Layer.d.ts +24 -3
  68. package/lib/maps/Layer.js +5 -1
  69. package/lib/maps/LayerFactory.js +0 -8
  70. package/lib/maps/LayerLegendComponent.js +0 -1
  71. package/lib/maps/LayerSwitcherComponent.d.ts +1 -0
  72. package/lib/maps/LayerSwitcherComponent.js +1 -1
  73. package/lib/maps/LeafletMapComponent.js +3 -1
  74. package/lib/maps/LegendComponent.d.ts +1 -0
  75. package/lib/maps/LegendComponent.js +9 -1
  76. package/lib/maps/MWaterServerLayer.d.ts +2 -2
  77. package/lib/maps/MWaterServerLayer.js +2 -2
  78. package/lib/maps/MapComponent.js +3 -3
  79. package/lib/maps/MapDesign.d.ts +2 -0
  80. package/lib/maps/MapDesignerComponent.d.ts +4 -3
  81. package/lib/maps/MapDesignerComponent.js +68 -74
  82. package/lib/maps/MapLayerViewDesignerComponent.js +2 -2
  83. package/lib/maps/MapUtils.d.ts +4 -0
  84. package/lib/maps/MapUtils.js +19 -0
  85. package/lib/maps/MapViewComponent.d.ts +8 -3
  86. package/lib/maps/MarkersLayer.d.ts +5 -4
  87. package/lib/maps/MarkersLayer.js +33 -7
  88. package/lib/maps/MarkersLayerDesign.d.ts +19 -16
  89. package/lib/maps/PopupFilterJoinsUtils.d.ts +6 -3
  90. package/lib/maps/PopupFilterJoinsUtils.js +0 -6
  91. package/lib/maps/RasterMapViewComponent.d.ts +3 -31
  92. package/lib/maps/RasterMapViewComponent.js +7 -2
  93. package/lib/maps/ServerMapDataSource.js +2 -1
  94. package/lib/maps/SwitchableTileUrlLayer.d.ts +3 -3
  95. package/lib/maps/SwitchableTileUrlLayer.js +2 -1
  96. package/lib/maps/TileUrlLayer.d.ts +4 -5
  97. package/lib/maps/TileUrlLayer.js +2 -1
  98. package/lib/maps/VectorMapViewComponent.d.ts +5 -37
  99. package/lib/maps/VectorMapViewComponent.js +19 -8
  100. package/lib/maps/maps.d.ts +3 -0
  101. package/lib/quickfilter/QuickfiltersComponent.d.ts +2 -0
  102. package/lib/quickfilter/QuickfiltersComponent.js +9 -7
  103. package/lib/quickfilter/QuickfiltersDesignComponent.d.ts +1 -1
  104. package/lib/quickfilter/QuickfiltersDesignComponent.js +19 -35
  105. package/lib/richtext/ExprItemsHtmlConverter.d.ts +5 -2
  106. package/lib/richtext/ExprItemsHtmlConverter.js +4 -4
  107. package/lib/richtext/ExprItemsTranslator.d.ts +5 -0
  108. package/lib/richtext/ExprItemsTranslator.js +149 -0
  109. package/lib/richtext/ItemsHtmlConverter.d.ts +1 -1
  110. package/lib/richtext/ItemsHtmlConverter.js +31 -15
  111. package/lib/wellknown.js +12 -9
  112. package/lib/widgets/IFrameWidget.d.ts +4 -4
  113. package/lib/widgets/ImageWidget.d.ts +7 -4
  114. package/lib/widgets/ImageWidget.js +9 -1
  115. package/lib/widgets/ImageWidgetComponent.d.ts +1 -0
  116. package/lib/widgets/ImageWidgetComponent.js +1 -1
  117. package/lib/widgets/MapWidget.d.ts +5 -48
  118. package/lib/widgets/MapWidget.js +26 -63
  119. package/lib/widgets/MarkdownWidget.d.ts +3 -0
  120. package/lib/widgets/MarkdownWidget.js +3 -0
  121. package/lib/widgets/TOCWidget.d.ts +15 -27
  122. package/lib/widgets/TOCWidget.js +107 -183
  123. package/lib/widgets/Widget.d.ts +18 -7
  124. package/lib/widgets/Widget.js +4 -0
  125. package/lib/widgets/WidgetScopesViewComponent.js +1 -1
  126. package/lib/widgets/charts/Chart.d.ts +10 -1
  127. package/lib/widgets/charts/Chart.js +22 -11
  128. package/lib/widgets/charts/ChartViewComponent.d.ts +4 -0
  129. package/lib/widgets/charts/ChartViewComponent.js +6 -3
  130. package/lib/widgets/charts/ChartWidget.d.ts +2 -0
  131. package/lib/widgets/charts/ChartWidget.js +9 -1
  132. package/lib/widgets/charts/ChartWidgetComponent.d.ts +4 -0
  133. package/lib/widgets/charts/ChartWidgetComponent.js +2 -2
  134. package/lib/widgets/charts/calendar/CalendarChart.d.ts +1 -0
  135. package/lib/widgets/charts/calendar/CalendarChart.js +26 -0
  136. package/lib/widgets/charts/calendar/CalendarChartViewComponent.js +3 -1
  137. package/lib/widgets/charts/imagemosaic/ImageMosaicChart.d.ts +1 -0
  138. package/lib/widgets/charts/imagemosaic/ImageMosaicChart.js +8 -0
  139. package/lib/widgets/charts/layered/LayeredChart.d.ts +2 -0
  140. package/lib/widgets/charts/layered/LayeredChart.js +63 -3
  141. package/lib/widgets/charts/layered/LayeredChartCompiler.d.ts +1 -1
  142. package/lib/widgets/charts/layered/LayeredChartCompiler.js +3 -3
  143. package/lib/widgets/charts/layered/LayeredChartDesignerComponent.js +2 -2
  144. package/lib/widgets/charts/layered/LayeredChartViewComponent.js +8 -3
  145. package/lib/widgets/charts/pivot/PivotChart.d.ts +1 -0
  146. package/lib/widgets/charts/pivot/PivotChart.js +63 -0
  147. package/lib/widgets/charts/pivot/PivotChartDesignerComponent.d.ts +1 -0
  148. package/lib/widgets/charts/pivot/PivotChartLayoutComponent.js +1 -1
  149. package/lib/widgets/charts/pivot/SegmentDesignerComponent.d.ts +6 -0
  150. package/lib/widgets/charts/pivot/SegmentDesignerComponent.js +7 -4
  151. package/lib/widgets/charts/table/OrderingsComponent.js +1 -1
  152. package/lib/widgets/charts/table/TableChart.d.ts +1 -0
  153. package/lib/widgets/charts/table/TableChart.js +15 -0
  154. package/lib/widgets/text/TextComponent.d.ts +11 -4
  155. package/lib/widgets/text/TextComponent.js +11 -8
  156. package/lib/widgets/text/TextWidget.d.ts +6 -3
  157. package/lib/widgets/text/TextWidget.js +7 -1
  158. package/lib/widgets/text/TextWidgetComponent.d.ts +4 -0
  159. package/lib/widgets/text/TextWidgetComponent.js +7 -1
  160. package/lib/widgets/text/TextWidgetDesign.d.ts +2 -4
  161. package/lib/widgets/text/TextWidgetDesign.js +1 -1
  162. package/package.json +7 -8
  163. package/src/ColorComponent.tsx +1 -2
  164. package/src/IdSelection.ts +62 -0
  165. package/src/MWaterAddRelatedIndicatorComponent.ts +3 -2
  166. package/src/MWaterCompleteTableSelectComponent.tsx +36 -46
  167. package/src/MWaterLoaderComponent.ts +28 -26
  168. package/src/MWaterResponsesFilterComponent.ts +5 -2
  169. package/src/MWaterTableSelectComponent.tsx +5 -9
  170. package/src/autotranslate.ts +141 -0
  171. package/src/axes/AxisBuilder.ts +3 -3
  172. package/src/axes/AxisColorEditorComponent.tsx +5 -0
  173. package/src/axes/{AxisComponent.ts → AxisComponent.tsx} +106 -106
  174. package/src/axes/CategoryMapComponent.ts +4 -4
  175. package/src/axes/RangesComponent.ts +3 -2
  176. package/src/dashboards/DashboardComponent.tsx +79 -14
  177. package/src/dashboards/DashboardDesign.ts +9 -2
  178. package/src/dashboards/DashboardUtils.ts +39 -0
  179. package/src/dashboards/DashboardViewComponent.tsx +22 -3
  180. package/src/dashboards/ServerDashboardDataSource.ts +2 -1
  181. package/src/dashboards/SettingsModalComponent.tsx +450 -35
  182. package/src/dashboards/WidgetComponent.tsx +12 -6
  183. package/src/datagrids/CellEditor.tsx +354 -0
  184. package/src/datagrids/DatagridComponent.tsx +646 -0
  185. package/src/datagrids/DatagridViewComponent.tsx +539 -0
  186. package/src/datagrids/DirectDatagridDataSource.ts +2 -3
  187. package/src/datagrids/{ExprCellComponent.ts → ExprCellComponent.tsx} +28 -23
  188. package/src/datagrids/{FindReplaceModalComponent.ts → FindReplaceModalComponent.tsx} +109 -122
  189. package/src/index.css +1 -1
  190. package/src/index.ts +0 -1
  191. package/src/layouts/blocks/HorizontalBlockComponent.ts +2 -2
  192. package/src/mWaterLoader.ts +1 -1
  193. package/src/maps/BufferLayer.ts +83 -60
  194. package/src/maps/BufferLayerDesign.ts +20 -14
  195. package/src/maps/BufferLayerDesignerComponent.tsx +309 -0
  196. package/src/maps/ChoroplethLayer.ts +40 -19
  197. package/src/maps/ChoroplethLayerDesign.ts +4 -2
  198. package/src/maps/ChoroplethLayerDesigner.tsx +4 -2
  199. package/src/maps/ClusterLayer.ts +4 -10
  200. package/src/maps/DetailLevelSelectComponent.ts +1 -1
  201. package/src/maps/DirectMapDataSource.ts +2 -1
  202. package/src/maps/EditPopupComponent.ts +7 -3
  203. package/src/maps/GridLayer.ts +4 -10
  204. package/src/maps/GridLayerDesigner.tsx +5 -3
  205. package/src/maps/HoverContent.tsx +40 -16
  206. package/src/maps/Layer.ts +28 -10
  207. package/src/maps/LayerFactory.ts +0 -8
  208. package/src/maps/LayerLegendComponent.ts +2 -4
  209. package/src/maps/LayerSwitcherComponent.tsx +6 -2
  210. package/src/maps/LeafletMapComponent.tsx +3 -1
  211. package/src/maps/LegendComponent.tsx +10 -1
  212. package/src/maps/MWaterServerLayer.ts +3 -3
  213. package/src/maps/MapComponent.ts +3 -3
  214. package/src/maps/MapDesign.ts +3 -0
  215. package/src/maps/MapDesignerComponent.tsx +165 -162
  216. package/src/maps/MapLayerViewDesignerComponent.ts +2 -2
  217. package/src/maps/MapUtils.ts +24 -0
  218. package/src/maps/MapViewComponent.tsx +11 -3
  219. package/src/maps/MarkersLayer.ts +44 -18
  220. package/src/maps/MarkersLayerDesign.ts +19 -16
  221. package/src/maps/PopupFilterJoinsUtils.ts +6 -2
  222. package/src/maps/RasterMapViewComponent.ts +9 -45
  223. package/src/maps/ServerMapDataSource.ts +2 -2
  224. package/src/maps/SwitchableTileUrlLayer.tsx +4 -10
  225. package/src/maps/TileUrlLayer.tsx +4 -10
  226. package/src/maps/VectorMapViewComponent.tsx +28 -55
  227. package/src/maps/maps.ts +3 -0
  228. package/src/quickfilter/QuickfiltersComponent.ts +13 -7
  229. package/src/quickfilter/QuickfiltersDesignComponent.tsx +56 -74
  230. package/src/richtext/ExprItemsHtmlConverter.ts +9 -5
  231. package/src/richtext/ExprItemsTranslator.ts +176 -0
  232. package/src/richtext/ItemsHtmlConverter.ts +33 -18
  233. package/src/wellknown.ts +33 -30
  234. package/src/widgets/ImageWidget.ts +10 -1
  235. package/src/widgets/ImageWidgetComponent.ts +3 -2
  236. package/src/widgets/{MapWidget.ts → MapWidget.tsx} +90 -101
  237. package/src/widgets/MarkdownWidget.ts +3 -0
  238. package/src/widgets/TOCWidget.tsx +281 -0
  239. package/src/widgets/Widget.ts +25 -5
  240. package/src/widgets/WidgetScopesViewComponent.ts +2 -1
  241. package/src/widgets/charts/Chart.ts +31 -12
  242. package/src/widgets/charts/ChartViewComponent.ts +13 -3
  243. package/src/widgets/charts/ChartWidget.ts +11 -1
  244. package/src/widgets/charts/ChartWidgetComponent.tsx +9 -1
  245. package/src/widgets/charts/calendar/CalendarChart.ts +29 -0
  246. package/src/widgets/charts/calendar/CalendarChartViewComponent.tsx +3 -1
  247. package/src/widgets/charts/imagemosaic/ImageMosaicChart.ts +9 -0
  248. package/src/widgets/charts/layered/LayeredChart.ts +71 -3
  249. package/src/widgets/charts/layered/LayeredChartCompiler.ts +4 -4
  250. package/src/widgets/charts/layered/LayeredChartDesignerComponent.tsx +4 -2
  251. package/src/widgets/charts/layered/LayeredChartViewComponent.ts +10 -4
  252. package/src/widgets/charts/pivot/PivotChart.ts +73 -0
  253. package/src/widgets/charts/pivot/PivotChartLayoutComponent.tsx +1 -1
  254. package/src/widgets/charts/pivot/SegmentDesignerComponent.tsx +6 -4
  255. package/src/widgets/charts/table/OrderingsComponent.tsx +2 -1
  256. package/src/widgets/charts/table/TableChart.ts +17 -0
  257. package/src/widgets/text/TextComponent.tsx +22 -12
  258. package/src/widgets/text/TextWidget.ts +9 -2
  259. package/src/widgets/text/TextWidgetComponent.tsx +16 -1
  260. package/src/widgets/text/TextWidgetDesign.ts +4 -7
  261. package/test/IdSelectionTests.ts +54 -0
  262. package/test/LayeredChartCompilerTests.ts +0 -2
  263. package/test/richtext/ExprItemsTranslatorTests.ts +144 -0
  264. package/test/wellknownTests.ts +144 -0
  265. package/src/datagrids/DatagridComponent.ts +0 -478
  266. package/src/datagrids/DatagridViewComponent.ts +0 -464
  267. package/src/datagrids/EditExprCellComponent.tsx +0 -305
  268. package/src/datagrids/README.md +0 -3
  269. package/src/maps/BufferLayerDesignerComponent.ts +0 -311
  270. package/src/widgets/TOCWidget.ts +0 -326
  271. package/test/LegoLayoutEngineTests.ts +0 -69
@@ -13,6 +13,7 @@ import ActionCancelModalComponent from "@mwater/react-library/lib/ActionCancelMo
13
13
  import { FormGroup } from "@mwater/react-library/lib/bootstrap"
14
14
  import ColorComponent from "../../ColorComponent"
15
15
  import { Select } from "@mwater/react-library/lib/bootstrap"
16
+ import { translateHtmlItems } from "../../richtext/ExprItemsTranslator"
16
17
 
17
18
  export interface TextWidgetComponentProps {
18
19
  design: TextWidgetDesign
@@ -28,8 +29,15 @@ export interface TextWidgetComponentProps {
28
29
  /** Table that is filtered to have one row */
29
30
  singleRowTable?: string
30
31
  namedStrings?: any
32
+
31
33
  /** A key that changes when the widget should be refreshed */
32
34
  refreshKey?: any
35
+
36
+ /** Locale to use for display */
37
+ locale: string
38
+
39
+ /** Translate function to use for display. Returns same string when editing. */
40
+ translate: (input: string) => string
33
41
  }
34
42
 
35
43
  // Widget which displays styled text with embedded expressions
@@ -200,9 +208,15 @@ export default class TextWidgetComponent extends AsyncLoadComponent<TextWidgetCo
200
208
 
201
209
  const padding = this.props.design.padding ?? 0
202
210
 
211
+ // Translate items if needed
212
+ const translatedDesign = this.props.onDesignChange ? this.props.design : {
213
+ ...this.props.design,
214
+ items: translateHtmlItems(this.props.design.items || [], this.props.translate)
215
+ }
216
+
203
217
  return (
204
218
  <TextComponent
205
- design={this.props.design}
219
+ design={translatedDesign}
206
220
  onDesignChange={this.props.onDesignChange}
207
221
  schema={this.props.schema}
208
222
  dataSource={this.props.dataSource}
@@ -211,6 +225,7 @@ export default class TextWidgetComponent extends AsyncLoadComponent<TextWidgetCo
211
225
  height={this.props.height ? this.props.height - padding * 2 : undefined}
212
226
  singleRowTable={this.props.singleRowTable}
213
227
  namedStrings={this.props.namedStrings}
228
+ locale={this.props.locale}
214
229
  />
215
230
  )
216
231
  }
@@ -1,11 +1,8 @@
1
- import { HtmlItemExpr } from "../../richtext/ExprItemsHtmlConverter"
2
- import { HtmlItem } from "../../richtext/ItemsHtmlConverter"
3
-
4
- export type TextWidgetItem = HtmlItem | HtmlItemExpr
1
+ import { HtmlItemOrExpr } from "../../richtext/ExprItemsHtmlConverter"
5
2
 
6
3
  export interface TextWidgetDesign {
7
4
  /** Text widget stores its content as array of items. See ItemsHtmlConverter TODO */
8
- items: TextWidgetItem[]
5
+ items?: HtmlItemOrExpr[]
9
6
 
10
7
  /** "title" for title block. default is "default" */
11
8
  style?: "title" | "default" | "header" | "footer"
@@ -29,5 +26,5 @@ export interface TextWidgetDesign {
29
26
 
30
27
  /** Returns true if the text widget design is empty. */
31
28
  export function isEmptyTextWidgetDesign(design: TextWidgetDesign | undefined): boolean {
32
- return design == null || design.items.length === 0
33
- }
29
+ return design == null || (design.items != null && design.items.length === 0)
30
+ }
@@ -0,0 +1,54 @@
1
+ import { assert } from "chai"
2
+ import IdSelection from "../src/IdSelection"
3
+
4
+ describe("IdSelection", function () {
5
+ beforeEach(function(this: any) {
6
+ this.sel = new IdSelection()
7
+ })
8
+
9
+ it("adds id", function(this: any) {
10
+ const sel = this.sel.add("1")
11
+ assert.isTrue(sel.isSelected("1"))
12
+ assert.isFalse(sel.isSelected("2"))
13
+ })
14
+
15
+ it("removes id", function(this: any) {
16
+ let sel = this.sel.add("1")
17
+ sel = sel.remove("1")
18
+ assert.isFalse(sel.isSelected("1"))
19
+ assert.isFalse(sel.isSelected("2"))
20
+ })
21
+
22
+ it("toggles id", function(this: any) {
23
+ let sel = this.sel.toggle("1")
24
+ assert.isTrue(sel.isSelected("1"))
25
+ sel = sel.toggle("1")
26
+ assert.isFalse(sel.isSelected("1"))
27
+ })
28
+
29
+ it("inverts", function(this: any) {
30
+ let sel = this.sel.add("1")
31
+ sel = sel.invert()
32
+ assert.isTrue(sel.isSelected("2"))
33
+ assert.isFalse(sel.isSelected("1"))
34
+ })
35
+
36
+ it("adds in inverts", function(this: any) {
37
+ let sel = this.sel.add("1")
38
+ sel = sel.invert()
39
+ sel = sel.add("1")
40
+ assert.isTrue(sel.isSelected("1"))
41
+ })
42
+
43
+ it("none", function(this: any) {
44
+ let sel = this.sel.add("1")
45
+ sel = sel.none()
46
+ assert.isFalse(sel.isSelected("1"))
47
+ })
48
+
49
+ return it("all", function(this: any) {
50
+ const sel = this.sel.all("1")
51
+ assert.isTrue(sel.isSelected("1"))
52
+ assert.isTrue(sel.isSelected("2"))
53
+ })
54
+ })
@@ -1,5 +1,3 @@
1
- // TODO: This file was created by bulk-decaffeinate.
2
- // Sanity-check the conversion and remove this comment.
3
1
  import _ from "lodash"
4
2
  import { assert } from "chai"
5
3
  import * as fixtures from "./fixtures"
@@ -0,0 +1,144 @@
1
+ import { assert } from "chai"
2
+ import { translateHtmlItems, getHtmlItemsStrings } from "../../src/richtext/ExprItemsTranslator"
3
+ import { HtmlItemElement } from "../../src/richtext/ItemsHtmlConverter"
4
+ import { HtmlItemExpr, HtmlItemOrExpr } from "../../src/richtext/ExprItemsHtmlConverter"
5
+
6
+ describe("ExprItemsTranslator", function () {
7
+ describe("translateHtmlItems", function () {
8
+ it("should translate simple strings", function () {
9
+ const items: HtmlItemOrExpr[] = ["Hello ", "World"]
10
+ const translatedItems = translateHtmlItems(items, (input) => input.toUpperCase())
11
+ assert.deepEqual(translatedItems, ["HELLO WORLD"])
12
+ })
13
+
14
+ it("should translate nested items", function () {
15
+ const items: HtmlItemOrExpr[] = [
16
+ {
17
+ type: "element",
18
+ tag: "p",
19
+ items: ["Hello", { type: "element", tag: "b", items: ["World"] } as HtmlItemElement]
20
+ } as HtmlItemElement
21
+ ]
22
+ const translatedItems = translateHtmlItems(items, (input) => input.toUpperCase())
23
+ assert.deepEqual(translatedItems, [
24
+ {
25
+ type: "element",
26
+ tag: "p",
27
+ items: ["HELLO", { type: "element", tag: "b", items: ["WORLD"] } as HtmlItemElement]
28
+ } as HtmlItemElement
29
+ ])
30
+ })
31
+
32
+ it("should translate expression items", function () {
33
+ const items: HtmlItemOrExpr[] = [
34
+ {
35
+ type: "expr",
36
+ id: "1",
37
+ expr: { type: "literal", valueType: "text", value: "Hello" },
38
+ labelText: "Greeting"
39
+ } as HtmlItemExpr
40
+ ]
41
+ const translatedItems = translateHtmlItems(items, (input) => input.toUpperCase())
42
+ assert.deepEqual(translatedItems, [
43
+ {
44
+ type: "expr",
45
+ id: "1",
46
+ expr: { type: "literal", valueType: "text", value: "Hello" },
47
+ labelText: "GREETING"
48
+ } as HtmlItemExpr
49
+ ])
50
+ })
51
+
52
+ it("should translate expression items within a string", function () {
53
+ const items: HtmlItemOrExpr[] = [
54
+ "Hello, ",
55
+ {
56
+ type: "expr",
57
+ id: "1",
58
+ expr: { type: "literal", valueType: "text", value: "Hello" },
59
+ labelText: "Greeting"
60
+ } as HtmlItemExpr,
61
+ "!"
62
+ ]
63
+ const translatedItems = translateHtmlItems(items, (input) => input.toUpperCase())
64
+ assert.deepEqual(translatedItems, [
65
+ "HELLO, ",
66
+ {
67
+ type: "expr",
68
+ id: "1",
69
+ expr: { type: "literal", valueType: "text", value: "Hello" },
70
+ labelText: "GREETING"
71
+ } as HtmlItemExpr,
72
+ "!"
73
+ ])
74
+ })
75
+
76
+ it("should translate links while preserving the href", function () {
77
+ const items: HtmlItemOrExpr[] = [
78
+ "Hello, ",
79
+ {
80
+ type: "element",
81
+ tag: "a",
82
+ items: ["there"],
83
+ href: "https://example.com"
84
+ } as HtmlItemElement,
85
+ "!"
86
+ ]
87
+ const translatedItems = translateHtmlItems(items, (input) => input.toUpperCase())
88
+ assert.deepEqual(translatedItems, [
89
+ "HELLO, ",
90
+ {
91
+ type: "element",
92
+ tag: "a",
93
+ items: ["THERE"],
94
+ href: "HTTPS://EXAMPLE.COM"
95
+ } as HtmlItemElement,
96
+ "!"
97
+ ])
98
+ })
99
+
100
+ it("should collect all unique strings", function () {
101
+ const items: HtmlItemOrExpr[] = [
102
+ "Start ",
103
+ {
104
+ type: "element",
105
+ tag: "p",
106
+ items: ["Hello ", { type: "element", tag: "b", items: ["World"] }]
107
+ } as HtmlItemElement,
108
+ " This is a ",
109
+ {
110
+ type: "expr",
111
+ id: "1",
112
+ expr: { type: "literal", valueType: "text", value: "Hello" },
113
+ labelText: "Greeting"
114
+ } as HtmlItemExpr,
115
+ "!"
116
+ ]
117
+ const strings = getHtmlItemsStrings(items)
118
+ assert.deepEqual(strings, ["Start", "Hello <b>World</b>", "Greeting", "This is a {0}!"])
119
+ })
120
+ })
121
+
122
+ describe("getHtmlItemsStrings", function () {
123
+ it("should collect all unique strings", function () {
124
+ const items: HtmlItemOrExpr[] = [
125
+ "Start ",
126
+ {
127
+ type: "element",
128
+ tag: "p",
129
+ items: ["Hello ", { type: "element", tag: "b", items: ["World"] }]
130
+ } as HtmlItemElement,
131
+ " This is a ",
132
+ {
133
+ type: "expr",
134
+ id: "1",
135
+ expr: { type: "literal", valueType: "text", value: "Hello" },
136
+ labelText: "Greeting"
137
+ } as HtmlItemExpr,
138
+ "!"
139
+ ]
140
+ const strings = getHtmlItemsStrings(items)
141
+ assert.deepEqual(strings, ["Start", "Hello <b>World</b>", "Greeting", "This is a {0}!"])
142
+ })
143
+ })
144
+ })
@@ -0,0 +1,144 @@
1
+ import { assert } from "chai"
2
+ import { parse, stringify } from "../src/wellknown"
3
+
4
+ describe("WellKnown", () => {
5
+ describe("parse", () => {
6
+ it("parses a point", () => {
7
+ const result = parse("POINT (1 2)")
8
+ assert.deepEqual(result, {
9
+ type: "Point",
10
+ coordinates: [1, 2]
11
+ })
12
+ })
13
+
14
+ it("parses a linestring", () => {
15
+ const result = parse("LINESTRING (1 2, 3 4)")
16
+ assert.deepEqual(result, {
17
+ type: "LineString",
18
+ coordinates: [[1, 2], [3, 4]]
19
+ })
20
+ })
21
+
22
+ it("parses a polygon", () => {
23
+ const result = parse("POLYGON ((1 2, 3 4, 5 6, 1 2))")
24
+ assert.deepEqual(result, {
25
+ type: "Polygon",
26
+ coordinates: [[[1, 2], [3, 4], [5, 6], [1, 2]]]
27
+ })
28
+ })
29
+
30
+ it("parses a polygon with hole", () => {
31
+ const result = parse("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (2 2, 8 2, 8 8, 2 8, 2 2))")
32
+ assert.deepEqual(result, {
33
+ type: "Polygon",
34
+ coordinates: [
35
+ [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]],
36
+ [[2, 2], [8, 2], [8, 8], [2, 8], [2, 2]]
37
+ ]
38
+ })
39
+ })
40
+
41
+ it("parses a multipoint", () => {
42
+ const result = parse("MULTIPOINT ((1 2), (3 4))")
43
+ assert.deepEqual(result, {
44
+ type: "MultiPoint",
45
+ coordinates: [[1, 2], [3, 4]]
46
+ })
47
+ })
48
+
49
+ it("handles SRID", () => {
50
+ const result = parse("SRID=4326;POINT (1 2)")
51
+ assert.deepEqual(result, {
52
+ type: "Point",
53
+ coordinates: [1, 2],
54
+ crs: {
55
+ type: "name",
56
+ properties: {
57
+ name: "urn:ogc:def:crs:EPSG::4326"
58
+ }
59
+ }
60
+ })
61
+ })
62
+
63
+ it("returns null for invalid input", () => {
64
+ const result = parse("POINT (not a point)")
65
+ assert.isNull(result)
66
+ })
67
+
68
+ it("parses a multilinestring", () => {
69
+ const result = parse("MULTILINESTRING ((1 2, 3 4), (5 6, 7 8))")
70
+ assert.deepEqual(result, {
71
+ type: "MultiLineString",
72
+ coordinates: [
73
+ [[1, 2], [3, 4]],
74
+ [[5, 6], [7, 8]]
75
+ ]
76
+ })
77
+ })
78
+
79
+ it("parses a multilinestring with z coordinate", () => {
80
+ const result = parse("MULTILINESTRING Z ((1 2 10, 3 4 11), (5 6 12, 7 8 13))")
81
+ assert.deepEqual(result, {
82
+ type: "MultiLineString",
83
+ coordinates: [
84
+ [[1, 2, 10], [3, 4, 11]],
85
+ [[5, 6, 12], [7, 8, 13]]
86
+ ]
87
+ })
88
+ })
89
+
90
+ it("parses a multilinestring with zm coordinate, ignoring m", () => {
91
+ const result = parse("MULTILINESTRING ZM ((1 2 10 100, 3 4 11 101), (5 6 12 102, 7 8 13 103))")
92
+ assert.deepEqual(result, {
93
+ type: "MultiLineString",
94
+ coordinates: [
95
+ [[1, 2, 10], [3, 4, 11]],
96
+ [[5, 6, 12], [7, 8, 13]]
97
+ ]
98
+ })
99
+ })
100
+ })
101
+
102
+ describe("stringify", () => {
103
+ it("stringifies a point", () => {
104
+ const point = {
105
+ type: "Point",
106
+ coordinates: [1, 2]
107
+ }
108
+ assert.equal(stringify(point), "POINT (1 2)")
109
+ })
110
+
111
+ it("stringifies a linestring", () => {
112
+ const linestring = {
113
+ type: "LineString",
114
+ coordinates: [[1, 2], [3, 4]]
115
+ }
116
+ assert.equal(stringify(linestring), "LINESTRING (1 2, 3 4)")
117
+ })
118
+
119
+ it("stringifies a polygon", () => {
120
+ const polygon = {
121
+ type: "Polygon",
122
+ coordinates: [[[1, 2], [3, 4], [5, 6], [1, 2]]]
123
+ }
124
+ assert.equal(stringify(polygon), "POLYGON ((1 2, 3 4, 5 6, 1 2))")
125
+ })
126
+
127
+ it("stringifies a multilinestring", () => {
128
+ const multilinestring = {
129
+ type: "MultiLineString",
130
+ coordinates: [
131
+ [[1, 2], [3, 4]],
132
+ [[5, 6], [7, 8]]
133
+ ]
134
+ }
135
+ assert.equal(stringify(multilinestring), "MULTILINESTRING ((1 2, 3 4), (5 6, 7 8))")
136
+ })
137
+
138
+ it("throws error for invalid input", () => {
139
+ assert.throws(() => {
140
+ stringify({ type: "Invalid" })
141
+ }, "stringify requires a valid GeoJSON Feature or geometry object as input")
142
+ })
143
+ })
144
+ })