@devtable/dashboard 10.9.9 → 10.10.0

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 (682) hide show
  1. package/dist/api-caller/index.d.ts +1 -2
  2. package/dist/api-caller/request.d.ts +1 -1
  3. package/dist/api-caller/types.d.ts +1 -1
  4. package/dist/{filter → components/filter}/filter-checkbox/editor.d.ts +2 -2
  5. package/dist/{filter → components/filter}/filter-checkbox/render.d.ts +4 -4
  6. package/dist/{filter → components/filter}/filter-date-range/editor.d.ts +2 -2
  7. package/dist/{filter → components/filter}/filter-date-range/render.d.ts +2 -2
  8. package/dist/{filter → components/filter}/filter-multi-select/editor.d.ts +2 -2
  9. package/dist/components/filter/filter-multi-select/render/index.d.ts +10 -0
  10. package/dist/{filter → components/filter}/filter-select/editor.d.ts +2 -2
  11. package/dist/{filter → components/filter}/filter-select/render.d.ts +3 -4
  12. package/dist/{filter → components/filter}/filter-settings/filter-setting.d.ts +2 -2
  13. package/dist/{filter → components/filter}/filter-settings/preview-filter.d.ts +2 -2
  14. package/dist/{filter → components/filter}/filter-text-input/editor.d.ts +2 -2
  15. package/dist/components/filter/filter-text-input/render.d.ts +9 -0
  16. package/dist/{filter → components/filter}/filter-tree-select/editor.d.ts +2 -2
  17. package/dist/components/filter/filter-tree-select/render/index.d.ts +11 -0
  18. package/dist/{filter → components/filter}/filter.d.ts +2 -2
  19. package/dist/{filter → components/filter}/index.d.ts +2 -2
  20. package/dist/components/filter/use-update-filter-preview-values.d.ts +1 -0
  21. package/dist/components/panel/index.d.ts +2 -0
  22. package/dist/{panel/panel-dropdown-menu.d.ts → components/panel/panel-editor/dropdown-menu/index.d.ts} +2 -2
  23. package/dist/components/panel/panel-editor/index.d.ts +8 -0
  24. package/dist/components/panel/panel-render/dropdown-menu/index.d.ts +6 -0
  25. package/dist/components/panel/panel-render/full-screen-render/full-screen-panel.d.ts +7 -0
  26. package/dist/components/panel/panel-render/full-screen-render/index.d.ts +2 -0
  27. package/dist/{main → components/panel/panel-render/full-screen-render}/use-panel-full-screen.d.ts +347 -355
  28. package/dist/components/panel/panel-render/index.d.ts +4 -0
  29. package/dist/components/panel/panel-render/panel-render-base.d.ts +12 -0
  30. package/dist/components/panel/panel-render/panel-render.d.ts +9 -0
  31. package/dist/components/panel/panel-render/viz/index.d.ts +3 -0
  32. package/dist/{panel → components/panel/panel-render/viz}/panel-error-or-state-message.d.ts +2 -2
  33. package/dist/{panel → components/panel/panel-render/viz}/panel-viz-section.d.ts +2 -2
  34. package/dist/{panel → components/panel}/plugin-adaptor.d.ts +1 -1
  35. package/dist/{panel → components/panel}/settings/common/aggregation-selector.d.ts +1 -1
  36. package/dist/components/panel/use-config-viz-instance-service.d.ts +3 -0
  37. package/dist/components/panel/utils.d.ts +1 -0
  38. package/dist/{plugins → components/plugins}/color-manager/impl.d.ts +1 -1
  39. package/dist/{plugins → components/plugins}/controls/color-interpolation-select/index.d.ts +1 -1
  40. package/dist/{plugins → components/plugins}/instance-migrator/index.d.ts +2 -2
  41. package/dist/{plugins → components/plugins}/plugin-context.d.ts +358 -346
  42. package/dist/{plugins → components/plugins}/plugin-data-migrator/plugin-data-migrator.d.ts +1 -1
  43. package/dist/{service-locator → components/plugins/service/service-locator}/use-service-locator.d.ts +1 -1
  44. package/dist/components/plugins/service/use-top-level-services.d.ts +3 -0
  45. package/dist/{plugins → components/plugins}/viz-components/boxplot-chart/index.d.ts +1 -1
  46. package/dist/{plugins → components/plugins}/viz-components/boxplot-chart/type.d.ts +3 -3
  47. package/dist/{plugins → components/plugins}/viz-components/button/index.d.ts +1 -1
  48. package/dist/{plugins → components/plugins}/viz-components/button/viz-button-editor.d.ts +1 -1
  49. package/dist/{plugins → components/plugins}/viz-components/button/viz-button.d.ts +1 -1
  50. package/dist/{plugins → components/plugins}/viz-components/calendar-heatmap/index.d.ts +1 -1
  51. package/dist/{plugins → components/plugins}/viz-components/calendar-heatmap/type.d.ts +3 -3
  52. package/dist/{plugins → components/plugins}/viz-components/cartesian/index.d.ts +1 -1
  53. package/dist/{plugins → components/plugins}/viz-components/cartesian/migrators/index.d.ts +1 -1
  54. package/dist/{plugins → components/plugins}/viz-components/cartesian/option/regression.d.ts +1 -1
  55. package/dist/{plugins → components/plugins}/viz-components/cartesian/type.d.ts +3 -3
  56. package/dist/{plugins → components/plugins}/viz-components/funnel/index.d.ts +1 -1
  57. package/dist/{plugins → components/plugins}/viz-components/funnel/type.d.ts +2 -2
  58. package/dist/{plugins → components/plugins}/viz-components/funnel/viz-funnel-editor.d.ts +1 -1
  59. package/dist/{plugins → components/plugins}/viz-components/heatmap/index.d.ts +1 -1
  60. package/dist/{plugins → components/plugins}/viz-components/heatmap/type.d.ts +4 -4
  61. package/dist/{plugins → components/plugins}/viz-components/horizontal-bar-chart/index.d.ts +1 -1
  62. package/dist/{plugins → components/plugins}/viz-components/horizontal-bar-chart/option/x-axis.d.ts +1 -1
  63. package/dist/{plugins → components/plugins}/viz-components/horizontal-bar-chart/type.d.ts +3 -3
  64. package/dist/{plugins → components/plugins}/viz-components/horizontal-bar-chart/viz-horizontal-bar-chart-editor.d.ts +1 -1
  65. package/dist/{plugins → components/plugins}/viz-components/merico-estimation-chart/index.d.ts +1 -1
  66. package/dist/{plugins → components/plugins}/viz-components/merico-estimation-chart/option/series/index.d.ts +1 -1
  67. package/dist/{plugins → components/plugins}/viz-components/merico-estimation-chart/option/series/series-4.d.ts +1 -1
  68. package/dist/{plugins → components/plugins}/viz-components/merico-estimation-chart/option/y-axis.d.ts +1 -1
  69. package/dist/{plugins → components/plugins}/viz-components/merico-estimation-chart/type.d.ts +2 -2
  70. package/dist/{plugins → components/plugins}/viz-components/merico-estimation-chart/viz-merico-estimation-chart-editor.d.ts +1 -1
  71. package/dist/{plugins → components/plugins}/viz-components/merico-stats/type.d.ts +2 -2
  72. package/dist/{plugins → components/plugins}/viz-components/pareto-chart/index.d.ts +1 -1
  73. package/dist/{plugins → components/plugins}/viz-components/pareto-chart/type.d.ts +2 -2
  74. package/dist/{plugins → components/plugins}/viz-components/pareto-chart/viz-pareto-chart.d.ts +1 -1
  75. package/dist/{plugins → components/plugins}/viz-components/radar-chart/option/formatter.d.ts +1 -1
  76. package/dist/{plugins → components/plugins}/viz-components/radar-chart/type.d.ts +1 -1
  77. package/dist/{plugins → components/plugins}/viz-components/regression-chart/migrators/index.d.ts +1 -1
  78. package/dist/{plugins → components/plugins}/viz-components/regression-chart/option/regression-series.d.ts +1 -1
  79. package/dist/{plugins → components/plugins}/viz-components/regression-chart/type.d.ts +3 -3
  80. package/dist/{plugins → components/plugins}/viz-components/scatter-chart/index.d.ts +1 -1
  81. package/dist/{plugins → components/plugins}/viz-components/scatter-chart/type.d.ts +3 -3
  82. package/dist/{plugins → components/plugins}/viz-components/stats/update/index.d.ts +1 -1
  83. package/dist/{plugins → components/plugins}/viz-components/sunburst/type.d.ts +1 -1
  84. package/dist/{plugins → components/plugins}/viz-components/table/components/background-color-select.d.ts +1 -1
  85. package/dist/components/plugins/viz-components/text/index.d.ts +2 -0
  86. package/dist/{plugins → components/plugins}/viz-components/viz-merico-gqm/index.d.ts +1 -1
  87. package/dist/{plugins → components/plugins}/viz-components/viz-merico-gqm/viz-merico-gqm-editor.d.ts +1 -1
  88. package/dist/{plugins → components/plugins}/viz-components/viz-merico-gqm/viz-merico-gqm.d.ts +1 -1
  89. package/dist/{view → components/view}/layout/main-layout.d.ts +2 -2
  90. package/dist/{view → components/view}/layout/read-only-layout.d.ts +2 -2
  91. package/dist/{view → components/view}/view-component/preview/index.d.ts +2 -2
  92. package/dist/{view → components/view}/view-component/preview/modal.d.ts +2 -2
  93. package/dist/{view → components/view}/view-component/preview/tabs.d.ts +2 -2
  94. package/dist/{view → components/view}/view-component/render/index.d.ts +2 -2
  95. package/dist/{view → components/view}/view-component/render/modal.d.ts +2 -2
  96. package/dist/{view → components/view}/view-component/render/tabs.d.ts +2 -2
  97. package/dist/{view → components/view}/view-editor.d.ts +2 -2
  98. package/dist/{view → components/view}/view-render.d.ts +2 -2
  99. package/dist/contexts/index.d.ts +1 -1
  100. package/dist/contexts/layout-state-context.d.ts +0 -2
  101. package/dist/contexts/panel-context.d.ts +5657 -4
  102. package/dist/{main/dashboard-editor → dashboard-editor}/index.d.ts +3 -3
  103. package/dist/{model → dashboard-editor/model}/datasources/datasource.d.ts +4 -5
  104. package/dist/{model → dashboard-editor/model}/datasources/index.d.ts +7 -5
  105. package/dist/dashboard-editor/model/filters/index.d.ts +517 -0
  106. package/dist/dashboard-editor/model/index.d.ts +7 -0
  107. package/dist/dashboard-editor/model/panels/index.d.ts +2 -0
  108. package/dist/dashboard-editor/model/panels/panel.d.ts +1278 -0
  109. package/dist/dashboard-editor/model/panels/panels.d.ts +11201 -0
  110. package/dist/{model → dashboard-editor/model}/queries/index.d.ts +73 -68
  111. package/dist/{model → dashboard-editor/model}/sql-snippets/index.d.ts +16 -13
  112. package/dist/{model → dashboard-editor/model}/views/index.d.ts +39 -39
  113. package/dist/dashboard-editor/ui/index.d.ts +3 -0
  114. package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/db-explorer-modal/db-explorer/index.d.ts +1 -1
  115. package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/db-explorer-modal/db-explorer/structure/columns-table.d.ts +1 -1
  116. package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/db-explorer-modal/db-explorer/structure/index.d.ts +1 -1
  117. package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/db-explorer-modal/db-explorer/structure/indexes-table.d.ts +1 -1
  118. package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/db-explorer-modal/db-explorer/table-data/index.d.ts +1 -1
  119. package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/db-explorer-modal/db-explorer/table-data/pagination-control.d.ts +1 -1
  120. package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/db-explorer-modal/db-explorer/table-nav-links.d.ts +1 -1
  121. package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/db-explorer-modal/index.d.ts +1 -1
  122. package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-panel/change-view-of-panel.d.ts +1 -1
  123. package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-panel/panel-editor.d.ts +1 -1
  124. package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-panel/variable-config/model.d.ts +5 -6
  125. package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-panel/variable-config/variable-config-panel.d.ts +1 -1
  126. package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-query/query-editor-form/configurations.d.ts +2 -2
  127. package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-query/query-editor-form/delete-query.d.ts +2 -2
  128. package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-query/query-editor-form/index.d.ts +2 -2
  129. package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-query/query-editor-form/select-data-source.d.ts +1 -1
  130. package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-query/query-editor-form/tabs/http/index.d.ts +2 -2
  131. package/dist/dashboard-editor/ui/settings/content/edit-query/query-editor-form/tabs/sql/edit-sql.d.ts +7 -0
  132. package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-query/query-editor-form/tabs/sql/index.d.ts +2 -2
  133. package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-sql-snippet/item-editor.d.ts +2 -2
  134. package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-view/edit-view-form/config-fields/config.division.d.ts +2 -2
  135. package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-view/edit-view-form/config-fields/config.tabs.d.ts +2 -2
  136. package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-view/edit-view-form/config-fields/index.d.ts +2 -2
  137. package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-view/edit-view-form/config-fields/modal/index.d.ts +2 -2
  138. package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-view/edit-view-form/config-fields/modal/modal-title-editor/index.d.ts +1 -1
  139. package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-view/edit-view-form/index.d.ts +5 -6
  140. package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/utils.d.ts +1 -1
  141. package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/navbar/add-item-button/index.d.ts +1 -1
  142. package/dist/{main/dashboard-render → dashboard-render}/index.d.ts +3 -3
  143. package/dist/dashboard-render/model/index.d.ts +2 -0
  144. package/dist/dashboard.es.js +14482 -14219
  145. package/dist/dashboard.umd.js +151 -151
  146. package/dist/index.d.ts +5 -4
  147. package/dist/interactions/components/interaction-settings.d.ts +1 -1
  148. package/dist/interactions/hooks/use-current-interaction-manager.d.ts +1 -1
  149. package/dist/interactions/interactions-viewer/data/edges.d.ts +2 -2
  150. package/dist/interactions/interactions-viewer/data/index.d.ts +2 -2
  151. package/dist/interactions/interactions-viewer/data/nodes.d.ts +2 -2
  152. package/dist/interactions/interactions-viewer/data/types.d.ts +1 -1
  153. package/dist/interactions/temp-hack.d.ts +2 -1
  154. package/dist/model/index.d.ts +3 -8
  155. package/dist/model/meta-model/context/context.d.ts +31 -0
  156. package/dist/model/meta-model/context/index.d.ts +1 -0
  157. package/dist/model/{filters/filter/index.d.ts → meta-model/dashboard/content/filter/filter.d.ts} +4 -4
  158. package/dist/model/meta-model/dashboard/content/filter/index.d.ts +3 -0
  159. package/dist/model/meta-model/dashboard/content/filter/types.d.ts +8 -0
  160. package/dist/model/{filters/filter → meta-model/dashboard/content/filter/widgets}/checkbox.d.ts +3 -3
  161. package/dist/model/{filters/filter → meta-model/dashboard/content/filter/widgets}/date-range.d.ts +3 -3
  162. package/dist/model/meta-model/dashboard/content/filter/widgets/index.d.ts +6 -0
  163. package/dist/model/{filters/filter → meta-model/dashboard/content/filter/widgets}/multi-select.d.ts +3 -3
  164. package/dist/model/{filters/filter → meta-model/dashboard/content/filter/widgets}/select-base.d.ts +3 -3
  165. package/dist/model/{filters/filter → meta-model/dashboard/content/filter/widgets}/select.d.ts +3 -3
  166. package/dist/model/{filters/filter → meta-model/dashboard/content/filter/widgets}/text-input.d.ts +3 -3
  167. package/dist/model/{filters/filter → meta-model/dashboard/content/filter/widgets}/tree-select.d.ts +3 -3
  168. package/dist/model/meta-model/dashboard/content/index.d.ts +7 -0
  169. package/dist/model/meta-model/dashboard/content/mock-context/index.d.ts +1 -0
  170. package/dist/model/meta-model/dashboard/content/mock-context/mock-context.d.ts +14 -0
  171. package/dist/model/meta-model/dashboard/content/panel/index.d.ts +5 -0
  172. package/dist/model/{panels → meta-model/dashboard/content/panel}/layout.d.ts +1 -3
  173. package/dist/model/{panels → meta-model/dashboard/content/panel}/panel.d.ts +9 -164
  174. package/dist/model/{panels → meta-model/dashboard/content/panel}/style/border.d.ts +1 -3
  175. package/dist/model/{panels → meta-model/dashboard/content/panel}/style/index.d.ts +1 -3
  176. package/dist/model/{variables/index.d.ts → meta-model/dashboard/content/panel/variable.d.ts} +5 -11
  177. package/dist/model/{panels → meta-model/dashboard/content/panel}/viz.d.ts +1 -3
  178. package/dist/model/meta-model/dashboard/content/query/index.d.ts +2 -0
  179. package/dist/model/meta-model/dashboard/content/query/query.d.ts +37 -0
  180. package/dist/model/meta-model/dashboard/content/sql-snippet/index.d.ts +1 -0
  181. package/dist/model/meta-model/dashboard/content/sql-snippet/sql-snippet.d.ts +14 -0
  182. package/dist/model/meta-model/dashboard/content/types.d.ts +9 -0
  183. package/dist/model/meta-model/dashboard/content/view/index.d.ts +3 -0
  184. package/dist/model/meta-model/dashboard/content/view/types.d.ts +5 -0
  185. package/dist/model/{views/view/index.d.ts → meta-model/dashboard/content/view/view.d.ts} +5 -5
  186. package/dist/model/{views/view → meta-model/dashboard/content/view/widgets}/division.d.ts +5 -5
  187. package/dist/model/meta-model/dashboard/content/view/widgets/index.d.ts +3 -0
  188. package/dist/model/{views/view → meta-model/dashboard/content/view/widgets}/modal.d.ts +13 -5
  189. package/dist/model/{views/view → meta-model/dashboard/content/view/widgets}/tabs.d.ts +6 -7
  190. package/dist/model/meta-model/dashboard/index.d.ts +1 -0
  191. package/dist/model/meta-model/datasources/datasource.d.ts +10 -0
  192. package/dist/model/meta-model/datasources/datasources.d.ts +32 -0
  193. package/dist/model/meta-model/datasources/index.d.ts +2 -0
  194. package/dist/model/{global-sql-snippets → meta-model/global-sql-snippets}/global-sql-snippet.d.ts +1 -1
  195. package/dist/model/{global-sql-snippets/index.d.ts → meta-model/global-sql-snippets/global-sql-snippets.d.ts} +2 -2
  196. package/dist/model/meta-model/global-sql-snippets/index.d.ts +2 -0
  197. package/dist/model/meta-model/index.d.ts +4 -0
  198. package/dist/model/{filters/index.d.ts → render-model/dashboard/content/filters/filters.d.ts} +28 -51
  199. package/dist/model/render-model/dashboard/content/filters/index.d.ts +2 -0
  200. package/dist/model/render-model/dashboard/content/filters/types.d.ts +1 -0
  201. package/dist/model/render-model/dashboard/content/filters/utils.d.ts +4 -0
  202. package/dist/model/render-model/dashboard/content/index.d.ts +5 -0
  203. package/dist/model/render-model/dashboard/content/panels/index.d.ts +2 -0
  204. package/dist/model/render-model/dashboard/content/panels/panel.d.ts +1269 -0
  205. package/dist/model/{panels/index.d.ts → render-model/dashboard/content/panels/panels.d.ts} +1331 -1371
  206. package/dist/model/render-model/dashboard/content/queries/index.d.ts +3 -0
  207. package/dist/model/{queries → render-model/dashboard/content/queries}/mute-query.d.ts +12 -12
  208. package/dist/model/render-model/dashboard/content/queries/queries.d.ts +366 -0
  209. package/dist/model/{queries → render-model/dashboard/content/queries}/query.d.ts +14 -13
  210. package/dist/model/render-model/dashboard/content/sql-snippets/index.d.ts +4 -0
  211. package/dist/model/{sql-snippets → render-model/dashboard/content/sql-snippets}/sql-snippet.d.ts +5 -4
  212. package/dist/model/render-model/dashboard/content/sql-snippets/sql-snippets.d.ts +54 -0
  213. package/dist/model/render-model/dashboard/content/sql-snippets/types.d.ts +3 -0
  214. package/dist/model/render-model/dashboard/content/sql-snippets/utils.d.ts +3 -0
  215. package/dist/model/render-model/dashboard/content/views/index.d.ts +1 -0
  216. package/dist/model/render-model/dashboard/content/views/views.d.ts +3889 -0
  217. package/dist/model/render-model/dashboard/index.d.ts +1 -0
  218. package/dist/model/render-model/index.d.ts +1 -0
  219. package/dist/model/utils/draft.d.ts +10 -0
  220. package/dist/model/utils/index.d.ts +1 -0
  221. package/dist/stats.html +1 -1
  222. package/dist/style.css +1 -1
  223. package/dist/types/dashboard.d.ts +4 -11
  224. package/dist/types/filter.d.ts +1 -8
  225. package/dist/types/plugin/index.d.ts +2 -2
  226. package/dist/utils/error-boundary.d.ts +1 -1
  227. package/dist/utils/http-query.d.ts +2 -2
  228. package/dist/utils/sql.d.ts +1 -1
  229. package/dist/utils/template/types.d.ts +1 -1
  230. package/package.json +1 -1
  231. package/dist/filter/filter-multi-select/render/index.d.ts +0 -11
  232. package/dist/filter/filter-text-input/render.d.ts +0 -9
  233. package/dist/filter/filter-tree-select/render/index.d.ts +0 -11
  234. package/dist/main/dashboard-editor/settings/content/edit-view/edit-view-form/config-fields/modal/modal-title-editor/types.d.ts +0 -8
  235. package/dist/main/full-screen-panel.d.ts +0 -8
  236. package/dist/main/index.d.ts +0 -3
  237. package/dist/main/use-top-level-services.d.ts +0 -3
  238. package/dist/model/context.d.ts +0 -11
  239. package/dist/model/filters/filter/common.d.ts +0 -16
  240. package/dist/model/mock-context.d.ts +0 -11
  241. package/dist/model/sql-snippets/types.d.ts +0 -3
  242. package/dist/panel/index.d.ts +0 -9
  243. package/dist/panel/use-config-viz-instance-service.d.ts +0 -3
  244. package/dist/plugins/viz-components/text/index.d.ts +0 -2
  245. /package/dist/{filter → components/filter}/error-message-or-not-found.d.ts +0 -0
  246. /package/dist/{filter → components/filter}/filter-multi-select/render/widget.d.ts +0 -0
  247. /package/dist/{filter → components/filter}/filter-multi-select/render/widget.styles.d.ts +0 -0
  248. /package/dist/{filter → components/filter}/filter-tree-select/expected-structure.d.ts +0 -0
  249. /package/dist/{filter → components/filter}/filter-tree-select/render/query-data-to-tree.d.ts +0 -0
  250. /package/dist/{filter → components/filter}/filter-tree-select/render/switcher-icon.d.ts +0 -0
  251. /package/dist/{filter → components/filter}/filter-tree-select/render/tree-icon.d.ts +0 -0
  252. /package/dist/{filter → components/filter}/filter-tree-select/render/widget.d.ts +0 -0
  253. /package/dist/{filter → components/filter}/filter-tree-select/render/widget.styles.d.ts +0 -0
  254. /package/dist/{filter → components/filter}/filter-tree-select/types.d.ts +0 -0
  255. /package/dist/{filter → components/filter}/pick-query-for-filter/expected-structure-for-select.d.ts +0 -0
  256. /package/dist/{filter → components/filter}/pick-query-for-filter/index.d.ts +0 -0
  257. /package/dist/{filter → components/filter}/select-item.d.ts +0 -0
  258. /package/dist/{panel/panel-description.d.ts → components/panel/panel-render/description-popover/index.d.ts} +0 -0
  259. /package/dist/{panel/title-bar.d.ts → components/panel/panel-render/title-bar/index.d.ts} +0 -0
  260. /package/dist/{panel/viz/index.d.ts → components/panel/panel-render/viz/viz.d.ts} +0 -0
  261. /package/dist/{panel → components/panel}/settings/common/color-array-input.d.ts +0 -0
  262. /package/dist/{panel → components/panel}/settings/common/css-types.d.ts +0 -0
  263. /package/dist/{panel → components/panel}/settings/common/data-field-selector.d.ts +0 -0
  264. /package/dist/{panel → components/panel}/settings/common/mantine-color-swatches.d.ts +0 -0
  265. /package/dist/{panel → components/panel}/settings/common/mantine-color.d.ts +0 -0
  266. /package/dist/{panel → components/panel}/settings/common/mantine-font-weight.d.ts +0 -0
  267. /package/dist/{panel → components/panel}/settings/common/mantine-size-selector.d.ts +0 -0
  268. /package/dist/{panel → components/panel}/settings/common/numbro-format-selector.d.ts +0 -0
  269. /package/dist/{panel → components/panel}/settings/common/text-array-input.d.ts +0 -0
  270. /package/dist/{plugins → components/plugins}/color-manager/color-manager.d.ts +0 -0
  271. /package/dist/{plugins → components/plugins}/color-manager/index.d.ts +0 -0
  272. /package/dist/{plugins → components/plugins}/color-manager/multi-step-value-mapper.d.ts +0 -0
  273. /package/dist/{plugins → components/plugins}/color-manager/type.d.ts +0 -0
  274. /package/dist/{plugins → components/plugins}/colors/diverging-color.d.ts +0 -0
  275. /package/dist/{plugins → components/plugins}/colors/index.d.ts +0 -0
  276. /package/dist/{plugins → components/plugins}/colors/sequential-color.d.ts +0 -0
  277. /package/dist/{plugins → components/plugins}/common-echarts-fields/axis-label-overflow/axis-label-overflow-field.d.ts +0 -0
  278. /package/dist/{plugins → components/plugins}/common-echarts-fields/axis-label-overflow/index.d.ts +0 -0
  279. /package/dist/{plugins → components/plugins}/common-echarts-fields/axis-label-overflow/overflow-field.d.ts +0 -0
  280. /package/dist/{plugins → components/plugins}/common-echarts-fields/axis-label-overflow/overflow-option.d.ts +0 -0
  281. /package/dist/{plugins → components/plugins}/common-echarts-fields/axis-label-overflow/types.d.ts +0 -0
  282. /package/dist/{plugins → components/plugins}/common-echarts-fields/label-position/index.d.ts +0 -0
  283. /package/dist/{plugins → components/plugins}/common-echarts-fields/label-position/label-position-selector.d.ts +0 -0
  284. /package/dist/{plugins → components/plugins}/common-echarts-fields/label-position/types.d.ts +0 -0
  285. /package/dist/{plugins → components/plugins}/common-echarts-fields/number-or-dynamic-value/field/dynamic-function-editor.d.ts +0 -0
  286. /package/dist/{plugins → components/plugins}/common-echarts-fields/number-or-dynamic-value/field/dynamic.d.ts +0 -0
  287. /package/dist/{plugins → components/plugins}/common-echarts-fields/number-or-dynamic-value/field/index.d.ts +0 -0
  288. /package/dist/{plugins → components/plugins}/common-echarts-fields/number-or-dynamic-value/field/static.d.ts +0 -0
  289. /package/dist/{plugins → components/plugins}/common-echarts-fields/number-or-dynamic-value/get-number-or-dynamic-value.d.ts +0 -0
  290. /package/dist/{plugins → components/plugins}/common-echarts-fields/number-or-dynamic-value/index.d.ts +0 -0
  291. /package/dist/{plugins → components/plugins}/common-echarts-fields/number-or-dynamic-value/types.d.ts +0 -0
  292. /package/dist/{plugins → components/plugins}/common-echarts-fields/reference-area/field.d.ts +0 -0
  293. /package/dist/{plugins → components/plugins}/common-echarts-fields/reference-area/option.d.ts +0 -0
  294. /package/dist/{plugins → components/plugins}/common-echarts-fields/reference-area/types.d.ts +0 -0
  295. /package/dist/{plugins → components/plugins}/common-echarts-fields/regression-line/index.d.ts +0 -0
  296. /package/dist/{plugins → components/plugins}/common-echarts-fields/regression-line/option.d.ts +0 -0
  297. /package/dist/{plugins → components/plugins}/common-echarts-fields/regression-line/types.d.ts +0 -0
  298. /package/dist/{plugins → components/plugins}/common-echarts-fields/tooltip-metric/index.d.ts +0 -0
  299. /package/dist/{plugins → components/plugins}/common-echarts-fields/tooltip-metric/types.d.ts +0 -0
  300. /package/dist/{plugins → components/plugins}/common-echarts-fields/x-axis-label-formatter/function-editor.d.ts +0 -0
  301. /package/dist/{plugins → components/plugins}/common-echarts-fields/x-axis-label-formatter/get-echarts-x-axis-tick-label.d.ts +0 -0
  302. /package/dist/{plugins → components/plugins}/common-echarts-fields/x-axis-label-formatter/index.d.ts +0 -0
  303. /package/dist/{plugins → components/plugins}/common-echarts-fields/x-axis-label-formatter/types.d.ts +0 -0
  304. /package/dist/{plugins → components/plugins}/controls/color-mapping-editor/index.d.ts +0 -0
  305. /package/dist/{plugins → components/plugins}/controls/color-mapping-editor/style.d.ts +0 -0
  306. /package/dist/{plugins → components/plugins}/hooks/index.d.ts +0 -0
  307. /package/dist/{plugins → components/plugins}/hooks/use-channel-event.d.ts +0 -0
  308. /package/dist/{plugins → components/plugins}/hooks/use-row-data-map.d.ts +0 -0
  309. /package/dist/{plugins → components/plugins}/hooks/use-storage-data.d.ts +0 -0
  310. /package/dist/{plugins → components/plugins}/hooks/use-tab-state.d.ts +0 -0
  311. /package/dist/{plugins → components/plugins}/index.d.ts +0 -0
  312. /package/dist/{plugins → components/plugins}/json-plugin-storage.d.ts +0 -0
  313. /package/dist/{plugins → components/plugins}/message-channels.d.ts +0 -0
  314. /package/dist/{plugins → components/plugins}/plugin-data-migrator/index.d.ts +0 -0
  315. /package/dist/{plugins → components/plugins}/plugin-data-migrator/version-based-migrator.d.ts +0 -0
  316. /package/dist/{plugins → components/plugins}/plugin-manager.d.ts +0 -0
  317. /package/dist/{service-locator → components/plugins/service/service-locator}/index.d.ts +0 -0
  318. /package/dist/{plugins → components/plugins}/sub-tree-json-plugin-storage.d.ts +0 -0
  319. /package/dist/{plugins → components/plugins}/viz-components/bar-3d-chart/index.d.ts +0 -0
  320. /package/dist/{plugins → components/plugins}/viz-components/bar-3d-chart/type.d.ts +0 -0
  321. /package/dist/{plugins → components/plugins}/viz-components/bar-3d-chart/viz-bar-3d-chart-editor.d.ts +0 -0
  322. /package/dist/{plugins → components/plugins}/viz-components/bar-3d-chart/viz-bar-3d-chart.d.ts +0 -0
  323. /package/dist/{plugins → components/plugins}/viz-components/boxplot-chart/editors/reference-lines/index.d.ts +0 -0
  324. /package/dist/{plugins → components/plugins}/viz-components/boxplot-chart/editors/reference-lines/reference-line.d.ts +0 -0
  325. /package/dist/{plugins → components/plugins}/viz-components/boxplot-chart/editors/tooltip/index.d.ts +0 -0
  326. /package/dist/{plugins → components/plugins}/viz-components/boxplot-chart/editors/tooltip/metric.d.ts +0 -0
  327. /package/dist/{plugins → components/plugins}/viz-components/boxplot-chart/editors/tooltip/metrics.d.ts +0 -0
  328. /package/dist/{plugins → components/plugins}/viz-components/boxplot-chart/editors/x-axis.d.ts +0 -0
  329. /package/dist/{plugins → components/plugins}/viz-components/boxplot-chart/editors/y-axis.d.ts +0 -0
  330. /package/dist/{plugins → components/plugins}/viz-components/boxplot-chart/option/common.d.ts +0 -0
  331. /package/dist/{plugins → components/plugins}/viz-components/boxplot-chart/option/dataset.d.ts +0 -0
  332. /package/dist/{plugins → components/plugins}/viz-components/boxplot-chart/option/index.d.ts +0 -0
  333. /package/dist/{plugins → components/plugins}/viz-components/boxplot-chart/option/legend.d.ts +0 -0
  334. /package/dist/{plugins → components/plugins}/viz-components/boxplot-chart/option/reference-line.d.ts +0 -0
  335. /package/dist/{plugins → components/plugins}/viz-components/boxplot-chart/option/series.d.ts +0 -0
  336. /package/dist/{plugins → components/plugins}/viz-components/boxplot-chart/option/tooltip/boxplot.d.ts +0 -0
  337. /package/dist/{plugins → components/plugins}/viz-components/boxplot-chart/option/tooltip/index.d.ts +0 -0
  338. /package/dist/{plugins → components/plugins}/viz-components/boxplot-chart/option/tooltip/scatter.d.ts +0 -0
  339. /package/dist/{plugins → components/plugins}/viz-components/boxplot-chart/triggers/click-boxplot.d.ts +0 -0
  340. /package/dist/{plugins → components/plugins}/viz-components/boxplot-chart/triggers/index.d.ts +0 -0
  341. /package/dist/{plugins → components/plugins}/viz-components/boxplot-chart/viz-boxplot-chart-editor.d.ts +0 -0
  342. /package/dist/{plugins → components/plugins}/viz-components/boxplot-chart/viz-boxplot-chart.d.ts +0 -0
  343. /package/dist/{plugins → components/plugins}/viz-components/button/triggers/click-button.d.ts +0 -0
  344. /package/dist/{plugins → components/plugins}/viz-components/button/triggers/index.d.ts +0 -0
  345. /package/dist/{plugins → components/plugins}/viz-components/button/type.d.ts +0 -0
  346. /package/dist/{plugins → components/plugins}/viz-components/calendar-heatmap/editors/calendar/index.d.ts +0 -0
  347. /package/dist/{plugins → components/plugins}/viz-components/calendar-heatmap/editors/heat_block/index.d.ts +0 -0
  348. /package/dist/{plugins → components/plugins}/viz-components/calendar-heatmap/editors/tooltip/index.d.ts +0 -0
  349. /package/dist/{plugins → components/plugins}/viz-components/calendar-heatmap/editors/tooltip/metric.d.ts +0 -0
  350. /package/dist/{plugins → components/plugins}/viz-components/calendar-heatmap/editors/tooltip/metrics.d.ts +0 -0
  351. /package/dist/{plugins → components/plugins}/viz-components/calendar-heatmap/option/calendar.d.ts +0 -0
  352. /package/dist/{plugins → components/plugins}/viz-components/calendar-heatmap/option/formatters.d.ts +0 -0
  353. /package/dist/{plugins → components/plugins}/viz-components/calendar-heatmap/option/index.d.ts +0 -0
  354. /package/dist/{plugins → components/plugins}/viz-components/calendar-heatmap/option/legend.d.ts +0 -0
  355. /package/dist/{plugins → components/plugins}/viz-components/calendar-heatmap/option/series.d.ts +0 -0
  356. /package/dist/{plugins → components/plugins}/viz-components/calendar-heatmap/option/tooltip.d.ts +0 -0
  357. /package/dist/{plugins → components/plugins}/viz-components/calendar-heatmap/option/visual-map.d.ts +0 -0
  358. /package/dist/{plugins → components/plugins}/viz-components/calendar-heatmap/triggers/click-calendar-date.d.ts +0 -0
  359. /package/dist/{plugins → components/plugins}/viz-components/calendar-heatmap/triggers/index.d.ts +0 -0
  360. /package/dist/{plugins → components/plugins}/viz-components/calendar-heatmap/viz-calendar-heatmap-editor.d.ts +0 -0
  361. /package/dist/{plugins → components/plugins}/viz-components/calendar-heatmap/viz-calendar-heatmap.d.ts +0 -0
  362. /package/dist/{plugins → components/plugins}/viz-components/cartesian/editors/echarts-zooming-field/get-echarts-data-zoom-option.d.ts +0 -0
  363. /package/dist/{plugins → components/plugins}/viz-components/cartesian/editors/echarts-zooming-field/index.d.ts +0 -0
  364. /package/dist/{plugins → components/plugins}/viz-components/cartesian/editors/echarts-zooming-field/types.d.ts +0 -0
  365. /package/dist/{plugins → components/plugins}/viz-components/cartesian/editors/reference-areas/index.d.ts +0 -0
  366. /package/dist/{plugins → components/plugins}/viz-components/cartesian/editors/reference-areas/reference-area.d.ts +0 -0
  367. /package/dist/{plugins → components/plugins}/viz-components/cartesian/editors/reference-lines/index.d.ts +0 -0
  368. /package/dist/{plugins → components/plugins}/viz-components/cartesian/editors/reference-lines/reference-line.d.ts +0 -0
  369. /package/dist/{plugins → components/plugins}/viz-components/cartesian/editors/regressions/index.d.ts +0 -0
  370. /package/dist/{plugins → components/plugins}/viz-components/cartesian/editors/regressions/regression-item.d.ts +0 -0
  371. /package/dist/{plugins → components/plugins}/viz-components/cartesian/editors/scatter-size-select/dynamic-size-function-editor.d.ts +0 -0
  372. /package/dist/{plugins → components/plugins}/viz-components/cartesian/editors/scatter-size-select/dynamic.d.ts +0 -0
  373. /package/dist/{plugins → components/plugins}/viz-components/cartesian/editors/scatter-size-select/get-echarts-symbol-size.d.ts +0 -0
  374. /package/dist/{plugins → components/plugins}/viz-components/cartesian/editors/scatter-size-select/index.d.ts +0 -0
  375. /package/dist/{plugins → components/plugins}/viz-components/cartesian/editors/scatter-size-select/static.d.ts +0 -0
  376. /package/dist/{plugins → components/plugins}/viz-components/cartesian/editors/scatter-size-select/types.d.ts +0 -0
  377. /package/dist/{plugins → components/plugins}/viz-components/cartesian/editors/series/fields.bar.d.ts +0 -0
  378. /package/dist/{plugins → components/plugins}/viz-components/cartesian/editors/series/fields.line.d.ts +0 -0
  379. /package/dist/{plugins → components/plugins}/viz-components/cartesian/editors/series/fields.scatter.d.ts +0 -0
  380. /package/dist/{plugins → components/plugins}/viz-components/cartesian/editors/series/index.d.ts +0 -0
  381. /package/dist/{plugins → components/plugins}/viz-components/cartesian/editors/series/series-item.d.ts +0 -0
  382. /package/dist/{plugins → components/plugins}/viz-components/cartesian/editors/stats/index.d.ts +0 -0
  383. /package/dist/{plugins → components/plugins}/viz-components/cartesian/editors/x-axis/index.d.ts +0 -0
  384. /package/dist/{plugins → components/plugins}/viz-components/cartesian/editors/x-axis/x-axis-label-formatter/function-editor.d.ts +0 -0
  385. /package/dist/{plugins → components/plugins}/viz-components/cartesian/editors/x-axis/x-axis-label-formatter/get-echarts-x-axis-tick-label.d.ts +0 -0
  386. /package/dist/{plugins → components/plugins}/viz-components/cartesian/editors/x-axis/x-axis-label-formatter/index.d.ts +0 -0
  387. /package/dist/{plugins → components/plugins}/viz-components/cartesian/editors/x-axis/x-axis-label-formatter/types.d.ts +0 -0
  388. /package/dist/{plugins → components/plugins}/viz-components/cartesian/editors/y-axes.d.ts +0 -0
  389. /package/dist/{plugins → components/plugins}/viz-components/cartesian/option/events.d.ts +0 -0
  390. /package/dist/{plugins → components/plugins}/viz-components/cartesian/option/grid.d.ts +0 -0
  391. /package/dist/{plugins → components/plugins}/viz-components/cartesian/option/index.d.ts +0 -0
  392. /package/dist/{plugins → components/plugins}/viz-components/cartesian/option/legend.d.ts +0 -0
  393. /package/dist/{plugins → components/plugins}/viz-components/cartesian/option/series/data.d.ts +0 -0
  394. /package/dist/{plugins → components/plugins}/viz-components/cartesian/option/series/index.d.ts +0 -0
  395. /package/dist/{plugins → components/plugins}/viz-components/cartesian/option/series/reference_areas.d.ts +0 -0
  396. /package/dist/{plugins → components/plugins}/viz-components/cartesian/option/series/reference_lines.d.ts +0 -0
  397. /package/dist/{plugins → components/plugins}/viz-components/cartesian/option/series/series_items.d.ts +0 -0
  398. /package/dist/{plugins → components/plugins}/viz-components/cartesian/option/series/types.d.ts +0 -0
  399. /package/dist/{plugins → components/plugins}/viz-components/cartesian/option/tooltip.d.ts +0 -0
  400. /package/dist/{plugins → components/plugins}/viz-components/cartesian/option/utils/label-formatter.d.ts +0 -0
  401. /package/dist/{plugins → components/plugins}/viz-components/cartesian/option/utils/types.d.ts +0 -0
  402. /package/dist/{plugins → components/plugins}/viz-components/cartesian/option/utils/variables.d.ts +0 -0
  403. /package/dist/{plugins → components/plugins}/viz-components/cartesian/option/x-axis.d.ts +0 -0
  404. /package/dist/{plugins → components/plugins}/viz-components/cartesian/option/y-axis.d.ts +0 -0
  405. /package/dist/{plugins → components/plugins}/viz-components/cartesian/triggers/click-echart.d.ts +0 -0
  406. /package/dist/{plugins → components/plugins}/viz-components/cartesian/triggers/index.d.ts +0 -0
  407. /package/dist/{plugins → components/plugins}/viz-components/cartesian/viz-cartesian-chart.d.ts +0 -0
  408. /package/dist/{plugins → components/plugins}/viz-components/cartesian/viz-cartesian-editor.d.ts +0 -0
  409. /package/dist/{plugins → components/plugins}/viz-components/funnel/editors/series/index.d.ts +0 -0
  410. /package/dist/{plugins → components/plugins}/viz-components/funnel/editors/series/series-item.d.ts +0 -0
  411. /package/dist/{plugins → components/plugins}/viz-components/funnel/option/index.d.ts +0 -0
  412. /package/dist/{plugins → components/plugins}/viz-components/funnel/option/series.d.ts +0 -0
  413. /package/dist/{plugins → components/plugins}/viz-components/funnel/option/tooltip.d.ts +0 -0
  414. /package/dist/{plugins → components/plugins}/viz-components/funnel/viz-funnel-chart.d.ts +0 -0
  415. /package/dist/{plugins → components/plugins}/viz-components/heatmap/editors/heat_block/index.d.ts +0 -0
  416. /package/dist/{plugins → components/plugins}/viz-components/heatmap/editors/tooltip/index.d.ts +0 -0
  417. /package/dist/{plugins → components/plugins}/viz-components/heatmap/editors/tooltip/metric.d.ts +0 -0
  418. /package/dist/{plugins → components/plugins}/viz-components/heatmap/editors/tooltip/metrics.d.ts +0 -0
  419. /package/dist/{plugins → components/plugins}/viz-components/heatmap/editors/x-axis/index.d.ts +0 -0
  420. /package/dist/{plugins → components/plugins}/viz-components/heatmap/editors/x-axis/x-axis-label-formatter/function-editor.d.ts +0 -0
  421. /package/dist/{plugins → components/plugins}/viz-components/heatmap/editors/x-axis/x-axis-label-formatter/get-echarts-x-axis-tick-label.d.ts +0 -0
  422. /package/dist/{plugins → components/plugins}/viz-components/heatmap/editors/x-axis/x-axis-label-formatter/index.d.ts +0 -0
  423. /package/dist/{plugins → components/plugins}/viz-components/heatmap/editors/x-axis/x-axis-label-formatter/types.d.ts +0 -0
  424. /package/dist/{plugins → components/plugins}/viz-components/heatmap/editors/y-axis/index.d.ts +0 -0
  425. /package/dist/{plugins → components/plugins}/viz-components/heatmap/option/formatters.d.ts +0 -0
  426. /package/dist/{plugins → components/plugins}/viz-components/heatmap/option/grid.d.ts +0 -0
  427. /package/dist/{plugins → components/plugins}/viz-components/heatmap/option/index.d.ts +0 -0
  428. /package/dist/{plugins → components/plugins}/viz-components/heatmap/option/series.d.ts +0 -0
  429. /package/dist/{plugins → components/plugins}/viz-components/heatmap/option/tooltip.d.ts +0 -0
  430. /package/dist/{plugins → components/plugins}/viz-components/heatmap/option/visual-map.d.ts +0 -0
  431. /package/dist/{plugins → components/plugins}/viz-components/heatmap/option/x-axis.d.ts +0 -0
  432. /package/dist/{plugins → components/plugins}/viz-components/heatmap/option/y-axis.d.ts +0 -0
  433. /package/dist/{plugins → components/plugins}/viz-components/heatmap/triggers/click-heat-block.d.ts +0 -0
  434. /package/dist/{plugins → components/plugins}/viz-components/heatmap/triggers/index.d.ts +0 -0
  435. /package/dist/{plugins → components/plugins}/viz-components/heatmap/viz-heatmap-editor.d.ts +0 -0
  436. /package/dist/{plugins → components/plugins}/viz-components/heatmap/viz-heatmap.d.ts +0 -0
  437. /package/dist/{plugins → components/plugins}/viz-components/horizontal-bar-chart/editors/reference-lines/index.d.ts +0 -0
  438. /package/dist/{plugins → components/plugins}/viz-components/horizontal-bar-chart/editors/reference-lines/reference-line.d.ts +0 -0
  439. /package/dist/{plugins → components/plugins}/viz-components/horizontal-bar-chart/editors/series/fields.bar.d.ts +0 -0
  440. /package/dist/{plugins → components/plugins}/viz-components/horizontal-bar-chart/editors/series/index.d.ts +0 -0
  441. /package/dist/{plugins → components/plugins}/viz-components/horizontal-bar-chart/editors/series/series-item.d.ts +0 -0
  442. /package/dist/{plugins → components/plugins}/viz-components/horizontal-bar-chart/editors/x-axes/index.d.ts +0 -0
  443. /package/dist/{plugins → components/plugins}/viz-components/horizontal-bar-chart/editors/x-axes/x-axis.d.ts +0 -0
  444. /package/dist/{plugins → components/plugins}/viz-components/horizontal-bar-chart/editors/y-axis/index.d.ts +0 -0
  445. /package/dist/{plugins → components/plugins}/viz-components/horizontal-bar-chart/option/grid.d.ts +0 -0
  446. /package/dist/{plugins → components/plugins}/viz-components/horizontal-bar-chart/option/index.d.ts +0 -0
  447. /package/dist/{plugins → components/plugins}/viz-components/horizontal-bar-chart/option/legend.d.ts +0 -0
  448. /package/dist/{plugins → components/plugins}/viz-components/horizontal-bar-chart/option/series/data.d.ts +0 -0
  449. /package/dist/{plugins → components/plugins}/viz-components/horizontal-bar-chart/option/series/index.d.ts +0 -0
  450. /package/dist/{plugins → components/plugins}/viz-components/horizontal-bar-chart/option/series/reference_lines.d.ts +0 -0
  451. /package/dist/{plugins → components/plugins}/viz-components/horizontal-bar-chart/option/series/series_items.d.ts +0 -0
  452. /package/dist/{plugins → components/plugins}/viz-components/horizontal-bar-chart/option/series/types.d.ts +0 -0
  453. /package/dist/{plugins → components/plugins}/viz-components/horizontal-bar-chart/option/tooltip.d.ts +0 -0
  454. /package/dist/{plugins → components/plugins}/viz-components/horizontal-bar-chart/option/utils/label-formatter.d.ts +0 -0
  455. /package/dist/{plugins → components/plugins}/viz-components/horizontal-bar-chart/option/utils/types.d.ts +0 -0
  456. /package/dist/{plugins → components/plugins}/viz-components/horizontal-bar-chart/option/utils/variables.d.ts +0 -0
  457. /package/dist/{plugins → components/plugins}/viz-components/horizontal-bar-chart/option/y-axis.d.ts +0 -0
  458. /package/dist/{plugins → components/plugins}/viz-components/horizontal-bar-chart/viz-horizontal-bar-chart.d.ts +0 -0
  459. /package/dist/{plugins → components/plugins}/viz-components/merico-estimation-chart/editors/deviation.d.ts +0 -0
  460. /package/dist/{plugins → components/plugins}/viz-components/merico-estimation-chart/editors/metrics/index.d.ts +0 -0
  461. /package/dist/{plugins → components/plugins}/viz-components/merico-estimation-chart/editors/metrics/metric.d.ts +0 -0
  462. /package/dist/{plugins → components/plugins}/viz-components/merico-estimation-chart/editors/x_axis.d.ts +0 -0
  463. /package/dist/{plugins → components/plugins}/viz-components/merico-estimation-chart/option/data.d.ts +0 -0
  464. /package/dist/{plugins → components/plugins}/viz-components/merico-estimation-chart/option/grid.d.ts +0 -0
  465. /package/dist/{plugins → components/plugins}/viz-components/merico-estimation-chart/option/index.d.ts +0 -0
  466. /package/dist/{plugins → components/plugins}/viz-components/merico-estimation-chart/option/legend.d.ts +0 -0
  467. /package/dist/{plugins → components/plugins}/viz-components/merico-estimation-chart/option/series/series-1.d.ts +0 -0
  468. /package/dist/{plugins → components/plugins}/viz-components/merico-estimation-chart/option/series/series-2.d.ts +0 -0
  469. /package/dist/{plugins → components/plugins}/viz-components/merico-estimation-chart/option/series/series-3.d.ts +0 -0
  470. /package/dist/{plugins → components/plugins}/viz-components/merico-estimation-chart/option/series/utils.d.ts +0 -0
  471. /package/dist/{plugins → components/plugins}/viz-components/merico-estimation-chart/option/x-axis.d.ts +0 -0
  472. /package/dist/{plugins → components/plugins}/viz-components/merico-estimation-chart/toolbox/basis-metric-selector.d.ts +0 -0
  473. /package/dist/{plugins → components/plugins}/viz-components/merico-estimation-chart/toolbox/index.d.ts +0 -0
  474. /package/dist/{plugins → components/plugins}/viz-components/merico-estimation-chart/toolbox/metric-description.d.ts +0 -0
  475. /package/dist/{plugins → components/plugins}/viz-components/merico-estimation-chart/viz-merico-estimation-chart.d.ts +0 -0
  476. /package/dist/{plugins → components/plugins}/viz-components/merico-stats/editors/metrics/index.d.ts +0 -0
  477. /package/dist/{plugins → components/plugins}/viz-components/merico-stats/editors/metrics/metric.d.ts +0 -0
  478. /package/dist/{plugins → components/plugins}/viz-components/merico-stats/editors/styles/index.d.ts +0 -0
  479. /package/dist/{plugins → components/plugins}/viz-components/merico-stats/index.d.ts +0 -0
  480. /package/dist/{plugins → components/plugins}/viz-components/merico-stats/viz-merico-stats-editor.d.ts +0 -0
  481. /package/dist/{plugins → components/plugins}/viz-components/merico-stats/viz-merico-stats.d.ts +0 -0
  482. /package/dist/{plugins → components/plugins}/viz-components/pareto-chart/editors/bar.d.ts +0 -0
  483. /package/dist/{plugins → components/plugins}/viz-components/pareto-chart/editors/line.d.ts +0 -0
  484. /package/dist/{plugins → components/plugins}/viz-components/pareto-chart/editors/mark-line.d.ts +0 -0
  485. /package/dist/{plugins → components/plugins}/viz-components/pareto-chart/editors/x-axis.d.ts +0 -0
  486. /package/dist/{plugins → components/plugins}/viz-components/pareto-chart/editors/y-axis.d.ts +0 -0
  487. /package/dist/{plugins → components/plugins}/viz-components/pareto-chart/option/index.d.ts +0 -0
  488. /package/dist/{plugins → components/plugins}/viz-components/pareto-chart/option/mark-line.d.ts +0 -0
  489. /package/dist/{plugins → components/plugins}/viz-components/pareto-chart/option/series.d.ts +0 -0
  490. /package/dist/{plugins → components/plugins}/viz-components/pareto-chart/option/tooltip.d.ts +0 -0
  491. /package/dist/{plugins → components/plugins}/viz-components/pareto-chart/option/types.d.ts +0 -0
  492. /package/dist/{plugins → components/plugins}/viz-components/pareto-chart/option/utils.d.ts +0 -0
  493. /package/dist/{plugins → components/plugins}/viz-components/pareto-chart/option/x-axis.d.ts +0 -0
  494. /package/dist/{plugins → components/plugins}/viz-components/pareto-chart/option/y-axes.d.ts +0 -0
  495. /package/dist/{plugins → components/plugins}/viz-components/pareto-chart/triggers/click-pareto.d.ts +0 -0
  496. /package/dist/{plugins → components/plugins}/viz-components/pareto-chart/triggers/index.d.ts +0 -0
  497. /package/dist/{plugins → components/plugins}/viz-components/pareto-chart/viz-pareto-chart-editor.d.ts +0 -0
  498. /package/dist/{plugins → components/plugins}/viz-components/pie-chart/index.d.ts +0 -0
  499. /package/dist/{plugins → components/plugins}/viz-components/pie-chart/option/index.d.ts +0 -0
  500. /package/dist/{plugins → components/plugins}/viz-components/pie-chart/option/series.d.ts +0 -0
  501. /package/dist/{plugins → components/plugins}/viz-components/pie-chart/triggers/click-pie-chart.d.ts +0 -0
  502. /package/dist/{plugins → components/plugins}/viz-components/pie-chart/triggers/index.d.ts +0 -0
  503. /package/dist/{plugins → components/plugins}/viz-components/pie-chart/type.d.ts +0 -0
  504. /package/dist/{plugins → components/plugins}/viz-components/pie-chart/viz-pie-chart-editor.d.ts +0 -0
  505. /package/dist/{plugins → components/plugins}/viz-components/pie-chart/viz-pie-chart.d.ts +0 -0
  506. /package/dist/{plugins → components/plugins}/viz-components/radar-chart/editors/dimensions/dimension.d.ts +0 -0
  507. /package/dist/{plugins → components/plugins}/viz-components/radar-chart/editors/dimensions/index.d.ts +0 -0
  508. /package/dist/{plugins → components/plugins}/viz-components/radar-chart/index.d.ts +0 -0
  509. /package/dist/{plugins → components/plugins}/viz-components/radar-chart/option/index.d.ts +0 -0
  510. /package/dist/{plugins → components/plugins}/viz-components/radar-chart/option/series.label.d.ts +0 -0
  511. /package/dist/{plugins → components/plugins}/viz-components/radar-chart/option/tooltip.d.ts +0 -0
  512. /package/dist/{plugins → components/plugins}/viz-components/radar-chart/triggers/click-radar-chart.d.ts +0 -0
  513. /package/dist/{plugins → components/plugins}/viz-components/radar-chart/viz-radar-chart-editor.d.ts +0 -0
  514. /package/dist/{plugins → components/plugins}/viz-components/radar-chart/viz-radar-chart.d.ts +0 -0
  515. /package/dist/{plugins → components/plugins}/viz-components/regression-chart/editors/regression-field.d.ts +0 -0
  516. /package/dist/{plugins → components/plugins}/viz-components/regression-chart/editors/x-axis.d.ts +0 -0
  517. /package/dist/{plugins → components/plugins}/viz-components/regression-chart/editors/y-axis.d.ts +0 -0
  518. /package/dist/{plugins → components/plugins}/viz-components/regression-chart/index.d.ts +0 -0
  519. /package/dist/{plugins → components/plugins}/viz-components/regression-chart/option/index.d.ts +0 -0
  520. /package/dist/{plugins → components/plugins}/viz-components/regression-chart/option/series.d.ts +0 -0
  521. /package/dist/{plugins → components/plugins}/viz-components/regression-chart/option/tooltip.d.ts +0 -0
  522. /package/dist/{plugins → components/plugins}/viz-components/regression-chart/option/x-axis.d.ts +0 -0
  523. /package/dist/{plugins → components/plugins}/viz-components/regression-chart/toolbox/index.d.ts +0 -0
  524. /package/dist/{plugins → components/plugins}/viz-components/regression-chart/toolbox/regression-description/desc.d.ts +0 -0
  525. /package/dist/{plugins → components/plugins}/viz-components/regression-chart/toolbox/regression-description/index.d.ts +0 -0
  526. /package/dist/{plugins → components/plugins}/viz-components/regression-chart/viz-regression-chart-editor.d.ts +0 -0
  527. /package/dist/{plugins → components/plugins}/viz-components/regression-chart/viz-regression-chart.d.ts +0 -0
  528. /package/dist/{plugins → components/plugins}/viz-components/rich-text/index.d.ts +0 -0
  529. /package/dist/{plugins → components/plugins}/viz-components/rich-text/parse-rich-text-content.d.ts +0 -0
  530. /package/dist/{plugins → components/plugins}/viz-components/rich-text/type.d.ts +0 -0
  531. /package/dist/{plugins → components/plugins}/viz-components/rich-text/viz-rich-text-editor.d.ts +0 -0
  532. /package/dist/{plugins → components/plugins}/viz-components/rich-text/viz-rich-text.d.ts +0 -0
  533. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/editors/reference-areas/index.d.ts +0 -0
  534. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/editors/reference-lines/index.d.ts +0 -0
  535. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/editors/reference-lines/reference-line.d.ts +0 -0
  536. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/editors/scatter/index.d.ts +0 -0
  537. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/editors/scatter/label-overflow.d.ts +0 -0
  538. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/editors/scatter/scatter-size-select/dynamic-size-function-editor.d.ts +0 -0
  539. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/editors/scatter/scatter-size-select/dynamic.d.ts +0 -0
  540. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/editors/scatter/scatter-size-select/get-echarts-symbol-size.d.ts +0 -0
  541. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/editors/scatter/scatter-size-select/index.d.ts +0 -0
  542. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/editors/scatter/scatter-size-select/static.d.ts +0 -0
  543. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/editors/scatter/scatter-size-select/types.d.ts +0 -0
  544. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/editors/scatter/series-color-select/dynamic-color-function-editor.d.ts +0 -0
  545. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/editors/scatter/series-color-select/dynamic.d.ts +0 -0
  546. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/editors/scatter/series-color-select/get-series-color.d.ts +0 -0
  547. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/editors/scatter/series-color-select/index.d.ts +0 -0
  548. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/editors/scatter/series-color-select/static.d.ts +0 -0
  549. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/editors/scatter/series-color-select/types.d.ts +0 -0
  550. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/editors/stats/index.d.ts +0 -0
  551. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/editors/tooltip/index.d.ts +0 -0
  552. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/editors/tooltip/metric.d.ts +0 -0
  553. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/editors/tooltip/metrics.d.ts +0 -0
  554. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/editors/x-axis/index.d.ts +0 -0
  555. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/editors/x-axis/x-axis-label-formatter/function-editor.d.ts +0 -0
  556. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/editors/x-axis/x-axis-label-formatter/get-echarts-x-axis-tick-label.d.ts +0 -0
  557. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/editors/x-axis/x-axis-label-formatter/index.d.ts +0 -0
  558. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/editors/x-axis/x-axis-label-formatter/types.d.ts +0 -0
  559. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/editors/y-axes/index.d.ts +0 -0
  560. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/editors/y-axes/y-axis.d.ts +0 -0
  561. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/option/dataset.d.ts +0 -0
  562. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/option/grid.d.ts +0 -0
  563. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/option/index.d.ts +0 -0
  564. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/option/legend.d.ts +0 -0
  565. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/option/series.d.ts +0 -0
  566. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/option/tooltip.d.ts +0 -0
  567. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/option/x-axis.d.ts +0 -0
  568. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/option/y-axis.d.ts +0 -0
  569. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/triggers/click-scatter-chart.d.ts +0 -0
  570. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/triggers/index.d.ts +0 -0
  571. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/viz-scatter-chart-editor.d.ts +0 -0
  572. /package/dist/{plugins → components/plugins}/viz-components/scatter-chart/viz-scatter-chart.d.ts +0 -0
  573. /package/dist/{plugins → components/plugins}/viz-components/stats/index.d.ts +0 -0
  574. /package/dist/{plugins → components/plugins}/viz-components/stats/type.d.ts +0 -0
  575. /package/dist/{plugins → components/plugins}/viz-components/stats/viz-stats-editor.d.ts +0 -0
  576. /package/dist/{plugins → components/plugins}/viz-components/stats/viz-stats.d.ts +0 -0
  577. /package/dist/{plugins → components/plugins}/viz-components/sunburst/editors/data-field.d.ts +0 -0
  578. /package/dist/{plugins → components/plugins}/viz-components/sunburst/editors/levels/index.d.ts +0 -0
  579. /package/dist/{plugins → components/plugins}/viz-components/sunburst/editors/levels/level.d.ts +0 -0
  580. /package/dist/{plugins → components/plugins}/viz-components/sunburst/index.d.ts +0 -0
  581. /package/dist/{plugins → components/plugins}/viz-components/sunburst/option/array-to-tree.d.ts +0 -0
  582. /package/dist/{plugins → components/plugins}/viz-components/sunburst/option/data.d.ts +0 -0
  583. /package/dist/{plugins → components/plugins}/viz-components/sunburst/option/index.d.ts +0 -0
  584. /package/dist/{plugins → components/plugins}/viz-components/sunburst/option/levels.d.ts +0 -0
  585. /package/dist/{plugins → components/plugins}/viz-components/sunburst/option/tooltip.d.ts +0 -0
  586. /package/dist/{plugins → components/plugins}/viz-components/sunburst/option/types.d.ts +0 -0
  587. /package/dist/{plugins → components/plugins}/viz-components/sunburst/viz-sunburst-editor.d.ts +0 -0
  588. /package/dist/{plugins → components/plugins}/viz-components/sunburst/viz-sunburst.d.ts +0 -0
  589. /package/dist/{plugins → components/plugins}/viz-components/table/components/head-cell.d.ts +0 -0
  590. /package/dist/{plugins → components/plugins}/viz-components/table/editors/columns/column.d.ts +0 -0
  591. /package/dist/{plugins → components/plugins}/viz-components/table/editors/columns/func_content-editor.d.ts +0 -0
  592. /package/dist/{plugins → components/plugins}/viz-components/table/editors/columns/index.d.ts +0 -0
  593. /package/dist/{plugins → components/plugins}/viz-components/table/editors/styling.d.ts +0 -0
  594. /package/dist/{plugins → components/plugins}/viz-components/table/index.d.ts +0 -0
  595. /package/dist/{plugins → components/plugins}/viz-components/table/table-cell-context.d.ts +0 -0
  596. /package/dist/{plugins → components/plugins}/viz-components/table/triggers/click-cell-content.d.ts +0 -0
  597. /package/dist/{plugins → components/plugins}/viz-components/table/triggers/index.d.ts +0 -0
  598. /package/dist/{plugins → components/plugins}/viz-components/table/type.d.ts +0 -0
  599. /package/dist/{plugins → components/plugins}/viz-components/table/utils.d.ts +0 -0
  600. /package/dist/{plugins → components/plugins}/viz-components/table/value-type-selector.d.ts +0 -0
  601. /package/dist/{plugins → components/plugins}/viz-components/table/value.d.ts +0 -0
  602. /package/dist/{plugins → components/plugins}/viz-components/table/viz-table-editor.d.ts +0 -0
  603. /package/dist/{plugins → components/plugins}/viz-components/table/viz-table.d.ts +0 -0
  604. /package/dist/{plugins → components/plugins}/viz-components/table/viz-table.styles.d.ts +0 -0
  605. /package/dist/{plugins → components/plugins}/viz-components/text/editors/func-content/func-content-editor.d.ts +0 -0
  606. /package/dist/{plugins → components/plugins}/viz-components/text/editors/func-content/index.d.ts +0 -0
  607. /package/dist/{plugins → components/plugins}/viz-components/text/type.d.ts +0 -0
  608. /package/dist/{plugins → components/plugins}/viz-components/text/viz-text-editor.d.ts +0 -0
  609. /package/dist/{plugins → components/plugins}/viz-components/text/viz-text.d.ts +0 -0
  610. /package/dist/{plugins → components/plugins}/viz-components/viz-merico-gqm/error-figure.d.ts +0 -0
  611. /package/dist/{plugins → components/plugins}/viz-components/viz-merico-gqm/request/call-expert-system.d.ts +0 -0
  612. /package/dist/{plugins → components/plugins}/viz-components/viz-merico-gqm/type.d.ts +0 -0
  613. /package/dist/{plugins → components/plugins}/viz-manager/components.d.ts +0 -0
  614. /package/dist/{plugins → components/plugins}/viz-manager/impl.d.ts +0 -0
  615. /package/dist/{plugins → components/plugins}/viz-manager/index.d.ts +0 -0
  616. /package/dist/{plugins → components/plugins}/viz-manager/types.d.ts +0 -0
  617. /package/dist/{view → components/view}/index.d.ts +0 -0
  618. /package/dist/{view → components/view}/layout/index.d.ts +0 -0
  619. /package/dist/{view → components/view}/view-component/preview/division.d.ts +0 -0
  620. /package/dist/{view → components/view}/view-component/render/division.d.ts +0 -0
  621. /package/dist/components/{about-function-utils → widgets/about-function-utils}/index.d.ts +0 -0
  622. /package/dist/components/{function-editor.tsx → widgets/function-editor}/index.d.ts +0 -0
  623. /package/dist/components/{inline-function-input → widgets/inline-function-input}/index.d.ts +0 -0
  624. /package/dist/components/{minimal-monaco-editor.d.ts → widgets/minimal-monaco-editor.d.ts} +0 -0
  625. /package/dist/components/{rich-text-editor → widgets/rich-text-editor}/custom-rich-text-editor.d.ts +0 -0
  626. /package/dist/components/{rich-text-editor → widgets/rich-text-editor}/font-size-extension.d.ts +0 -0
  627. /package/dist/components/{rich-text-editor → widgets/rich-text-editor}/readonly-rich-text-editor.d.ts +0 -0
  628. /package/dist/{model → dashboard-editor/model}/datasources/columns.d.ts +0 -0
  629. /package/dist/{model → dashboard-editor/model}/datasources/indexes.d.ts +0 -0
  630. /package/dist/{model → dashboard-editor/model}/datasources/table-data.d.ts +0 -0
  631. /package/dist/{model → dashboard-editor/model}/datasources/tables.d.ts +0 -0
  632. /package/dist/{model → dashboard-editor/model}/editor/index.d.ts +0 -0
  633. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/header/header-menu.d.ts +0 -0
  634. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/header/index.d.ts +0 -0
  635. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/header/main-header.d.ts +0 -0
  636. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/header/save-changes-or-more.d.ts +0 -0
  637. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/header/sub-header.d.ts +0 -0
  638. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/navbar/index.d.ts +0 -0
  639. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/navbar/view-links.d.ts +0 -0
  640. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/data-preview/data-table.d.ts +0 -0
  641. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/data-preview/data-table.style.d.ts +0 -0
  642. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/data-preview/index.d.ts +0 -0
  643. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/data-preview/query-state-message.d.ts +0 -0
  644. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/db-explorer-modal/db-explorer/full-space-loading.d.ts +0 -0
  645. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/db-explorer-modal/db-explorer/structure/loading-skeleton.d.ts +0 -0
  646. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/db-explorer-modal/db-explorer/structure/tooltip-value.d.ts +0 -0
  647. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-filter/index.d.ts +0 -0
  648. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-mock-context/index.d.ts +0 -0
  649. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-panel/index.d.ts +0 -0
  650. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-panel/panel-config/description.d.ts +0 -0
  651. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-panel/panel-config/edit-style.d.ts +0 -0
  652. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-panel/panel-config/index.d.ts +0 -0
  653. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-panel/panel-config/title.d.ts +0 -0
  654. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-panel/pick-query/index.d.ts +0 -0
  655. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-panel/preview-panel.d.ts +0 -0
  656. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-panel/select-viz-type.d.ts +0 -0
  657. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-panel/variable-config/styles.d.ts +0 -0
  658. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-panel/variable-config/variable-field.d.ts +0 -0
  659. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-panel/viz-conf.d.ts +0 -0
  660. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-query/index.d.ts +0 -0
  661. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-query/query-editor-form/query-usage.d.ts +0 -0
  662. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-query/query-editor-form/tabs/sql/preview-sql-in-monaco-editor.d.ts +0 -0
  663. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-query/query-editor-form/tabs/sql/preview-sql.d.ts +0 -0
  664. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-sql-snippet/index.d.ts +0 -0
  665. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-sql-snippet/preview-snippet.d.ts +0 -0
  666. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-view/edit-view-form/config-fields/modal/modal-title-editor/function-editor.d.ts +0 -0
  667. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/edit-view/index.d.ts +0 -0
  668. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/index.d.ts +0 -0
  669. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/view-query-vars/global-sql-snippets-table.d.ts +0 -0
  670. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/view-query-vars/index.d.ts +0 -0
  671. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/view-query-vars/query-variables-guide.d.ts +0 -0
  672. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/content/view-query-vars/query-variables-modal.d.ts +0 -0
  673. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/index.d.ts +0 -0
  674. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/navbar/add-item-button/add-a-filter.d.ts +0 -0
  675. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/navbar/add-item-button/add-a-panel.d.ts +0 -0
  676. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/navbar/add-item-button/add-a-query.d.ts +0 -0
  677. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/navbar/add-item-button/add-a-sql-snippet.d.ts +0 -0
  678. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/navbar/add-item-button/add-a-view.d.ts +0 -0
  679. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/navbar/index.d.ts +0 -0
  680. /package/dist/{main/dashboard-editor → dashboard-editor/ui}/settings/navbar/nav-links.d.ts +0 -0
  681. /package/dist/{main/dashboard-editor → dashboard-editor}/utils/load-monaco-editor.d.ts +0 -0
  682. /package/dist/model/{queries → meta-model/dashboard/content/query}/types.d.ts +0 -0
@@ -1,4 +1,4 @@
1
- (function(M,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("react"),require("@mantine/core"),require("@mantine/modals"),require("ahooks"),require("mobx"),require("mobx-react-lite"),require("crypto-js"),require("dayjs"),require("lodash"),require("numbro"),require("d3-array"),require("mathjs"),require("@faker-js/faker"),require("axios"),require("mobx-state-tree"),require("performant-array-to-tree"),require("jszip"),require("file-saver"),require("@tabler/icons-react"),require("@mantine/hooks"),require("@tanstack/react-table"),require("react-virtual"),require("eventemitter2"),require("chroma-js"),require("echarts-gl"),require("echarts/core"),require("echarts/components"),require("echarts/renderers"),require("echarts-for-react/lib/core"),require("react-hook-form"),require("tabler-icons-react"),require("echarts/charts"),require("@mantine/notifications"),require("popmotion"),require("@monaco-editor/react"),require("d3-regression"),require("@mantine/prism"),require("@mantine/tiptap"),require("@tiptap/extension-color"),require("@tiptap/extension-highlight"),require("@tiptap/extension-placeholder"),require("@tiptap/extension-subscript"),require("@tiptap/extension-superscript"),require("@tiptap/extension-text-align"),require("@tiptap/extension-text-style"),require("@tiptap/extension-table"),require("@tiptap/extension-table-cell"),require("@tiptap/extension-table-header"),require("@tiptap/extension-table-row"),require("@tiptap/extension-underline"),require("@tiptap/react"),require("@tiptap/starter-kit"),require("prosemirror-keymap"),require("prosemirror-commands"),require("prosemirror-schema-list"),require("@mantine/dates"),require("rc-select"),require("rc-tree-select"),require("react-grid-layout"),require("react-router-dom"),require("reactflow")):typeof define=="function"&&define.amd?define(["exports","react","@mantine/core","@mantine/modals","ahooks","mobx","mobx-react-lite","crypto-js","dayjs","lodash","numbro","d3-array","mathjs","@faker-js/faker","axios","mobx-state-tree","performant-array-to-tree","jszip","file-saver","@tabler/icons-react","@mantine/hooks","@tanstack/react-table","react-virtual","eventemitter2","chroma-js","echarts-gl","echarts/core","echarts/components","echarts/renderers","echarts-for-react/lib/core","react-hook-form","tabler-icons-react","echarts/charts","@mantine/notifications","popmotion","@monaco-editor/react","d3-regression","@mantine/prism","@mantine/tiptap","@tiptap/extension-color","@tiptap/extension-highlight","@tiptap/extension-placeholder","@tiptap/extension-subscript","@tiptap/extension-superscript","@tiptap/extension-text-align","@tiptap/extension-text-style","@tiptap/extension-table","@tiptap/extension-table-cell","@tiptap/extension-table-header","@tiptap/extension-table-row","@tiptap/extension-underline","@tiptap/react","@tiptap/starter-kit","prosemirror-keymap","prosemirror-commands","prosemirror-schema-list","@mantine/dates","rc-select","rc-tree-select","react-grid-layout","react-router-dom","reactflow"],y):(M=typeof globalThis<"u"?globalThis:M||self,y(M.dashboard={},M.react,M["@mantine/core"],M["@mantine/modals"],M.ahooks,M.mobx,M["mobx-react-lite"],M.CryptoJS,M.dayjs,M._,M.numbro,M["d3-array"],M.mathjs,M["@faker-js/faker"],M.axios,M["mobx-state-tree"],M["performant-array-to-tree"],M.jszip,M["file-saver"],M["@tabler/icons-react"],M["@mantine/hooks"],M["@tanstack/react-table"],M["react-virtual"],M.eventemitter2,M["chroma-js"],M["echarts-gl"],M["echarts/core"],M["echarts/components"],M["echarts/renderers"],M["echarts-for-react/lib/core"],M["react-hook-form"],M["tabler-icons-react"],M["echarts/charts"],M["@mantine/notifications"],M.popmotion,M["@monaco-editor/react"],M["d3-regression"],M["@mantine/prism"],M["@mantine/tiptap"],M["@tiptap/extension-color"],M["@tiptap/extension-highlight"],M["@tiptap/extension-placeholder"],M["@tiptap/extension-subscript"],M["@tiptap/extension-superscript"],M["@tiptap/extension-text-align"],M["@tiptap/extension-text-style"],M["@tiptap/extension-table"],M["@tiptap/extension-table-cell"],M["@tiptap/extension-table-header"],M["@tiptap/extension-table-row"],M["@tiptap/extension-underline"],M["@tiptap/react"],M["@tiptap/starter-kit"],M["prosemirror-keymap"],M["prosemirror-commands"],M["prosemirror-schema-list"],M["@mantine/dates"],M["rc-select"],M["rc-tree-select"],M["react-grid-layout"],M["react-router-dom"],M.reactflow))})(this,function(M,y,s,Ue,X,ie,k,Sa,R,x,ee,Yt,Xl,Jl,pt,b,Zl,Hl,cr,L,Me,Xe,eu,_a,st,iD,tu,G,Ve,Ne,v,D,pe,hn,_t,Ie,nu,kt,J,ka,Ta,Da,Ma,Ia,Ea,Aa,za,$a,La,Oa,Pa,Ba,Va,aD,Te,dr,ru,Na,qa,fn,iu,Ee){"use strict";var nD=Object.defineProperty;var rD=(M,y,s)=>y in M?nD(M,y,{enumerable:!0,configurable:!0,writable:!0,value:s}):M[y]=s;var N=(M,y,s)=>(rD(M,typeof y!="symbol"?y+"":y,s),s);function gn(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:()=>t[n]})}}return e.default=t,Object.freeze(e)}const au=gn(Yt),mn=gn(Xl),le=gn(tu),ht=gn(nu);var ne=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},Qt={},su={get exports(){return Qt},set exports(t){Qt=t}},Kt={};/**
1
+ (function(M,b){typeof exports=="object"&&typeof module<"u"?b(exports,require("react"),require("@mantine/core"),require("@mantine/modals"),require("ahooks"),require("mobx"),require("mobx-react-lite"),require("crypto-js"),require("dayjs"),require("lodash"),require("numbro"),require("d3-array"),require("mathjs"),require("@faker-js/faker"),require("axios"),require("eventemitter2"),require("chroma-js"),require("echarts-gl"),require("echarts/core"),require("echarts/components"),require("echarts/renderers"),require("echarts-for-react/lib/core"),require("react-hook-form"),require("tabler-icons-react"),require("echarts/charts"),require("@tabler/icons-react"),require("@mantine/hooks"),require("@mantine/notifications"),require("popmotion"),require("@monaco-editor/react"),require("d3-regression"),require("@mantine/prism"),require("@mantine/tiptap"),require("@tiptap/extension-color"),require("@tiptap/extension-highlight"),require("@tiptap/extension-placeholder"),require("@tiptap/extension-subscript"),require("@tiptap/extension-superscript"),require("@tiptap/extension-text-align"),require("@tiptap/extension-text-style"),require("@tiptap/extension-table"),require("@tiptap/extension-table-cell"),require("@tiptap/extension-table-header"),require("@tiptap/extension-table-row"),require("@tiptap/extension-underline"),require("@tiptap/react"),require("@tiptap/starter-kit"),require("prosemirror-keymap"),require("prosemirror-commands"),require("prosemirror-schema-list"),require("@tanstack/react-table"),require("react-virtual"),require("@mantine/dates"),require("rc-select"),require("rc-tree-select"),require("react-grid-layout"),require("mobx-state-tree"),require("performant-array-to-tree"),require("jszip"),require("file-saver"),require("react-router-dom"),require("reactflow")):typeof define=="function"&&define.amd?define(["exports","react","@mantine/core","@mantine/modals","ahooks","mobx","mobx-react-lite","crypto-js","dayjs","lodash","numbro","d3-array","mathjs","@faker-js/faker","axios","eventemitter2","chroma-js","echarts-gl","echarts/core","echarts/components","echarts/renderers","echarts-for-react/lib/core","react-hook-form","tabler-icons-react","echarts/charts","@tabler/icons-react","@mantine/hooks","@mantine/notifications","popmotion","@monaco-editor/react","d3-regression","@mantine/prism","@mantine/tiptap","@tiptap/extension-color","@tiptap/extension-highlight","@tiptap/extension-placeholder","@tiptap/extension-subscript","@tiptap/extension-superscript","@tiptap/extension-text-align","@tiptap/extension-text-style","@tiptap/extension-table","@tiptap/extension-table-cell","@tiptap/extension-table-header","@tiptap/extension-table-row","@tiptap/extension-underline","@tiptap/react","@tiptap/starter-kit","prosemirror-keymap","prosemirror-commands","prosemirror-schema-list","@tanstack/react-table","react-virtual","@mantine/dates","rc-select","rc-tree-select","react-grid-layout","mobx-state-tree","performant-array-to-tree","jszip","file-saver","react-router-dom","reactflow"],b):(M=typeof globalThis<"u"?globalThis:M||self,b(M.dashboard={},M.react,M["@mantine/core"],M["@mantine/modals"],M.ahooks,M.mobx,M["mobx-react-lite"],M.CryptoJS,M.dayjs,M._,M.numbro,M["d3-array"],M.mathjs,M["@faker-js/faker"],M.axios,M.eventemitter2,M["chroma-js"],M["echarts-gl"],M["echarts/core"],M["echarts/components"],M["echarts/renderers"],M["echarts-for-react/lib/core"],M["react-hook-form"],M["tabler-icons-react"],M["echarts/charts"],M["@tabler/icons-react"],M["@mantine/hooks"],M["@mantine/notifications"],M.popmotion,M["@monaco-editor/react"],M["d3-regression"],M["@mantine/prism"],M["@mantine/tiptap"],M["@tiptap/extension-color"],M["@tiptap/extension-highlight"],M["@tiptap/extension-placeholder"],M["@tiptap/extension-subscript"],M["@tiptap/extension-superscript"],M["@tiptap/extension-text-align"],M["@tiptap/extension-text-style"],M["@tiptap/extension-table"],M["@tiptap/extension-table-cell"],M["@tiptap/extension-table-header"],M["@tiptap/extension-table-row"],M["@tiptap/extension-underline"],M["@tiptap/react"],M["@tiptap/starter-kit"],M["prosemirror-keymap"],M["prosemirror-commands"],M["prosemirror-schema-list"],M["@tanstack/react-table"],M["react-virtual"],M["@mantine/dates"],M["rc-select"],M["rc-tree-select"],M["react-grid-layout"],M["mobx-state-tree"],M["performant-array-to-tree"],M.jszip,M["file-saver"],M["react-router-dom"],M.reactflow))})(this,function(M,b,s,Ue,X,re,k,Ta,j,x,H,Qt,gu,mu,ht,Da,ot,OD,yu,G,Ve,Ne,v,T,pe,L,Ee,fn,kt,Ae,bu,Tt,J,Ma,Ia,Ea,Aa,za,$a,La,Oa,Pa,Ba,Va,Na,qa,Fa,PD,De,pr,Xe,vu,xu,Ga,Wa,gn,y,wu,Cu,hr,Su,ze){"use strict";var $D=Object.defineProperty;var LD=(M,b,s)=>b in M?$D(M,b,{enumerable:!0,configurable:!0,writable:!0,value:s}):M[b]=s;var N=(M,b,s)=>(LD(M,typeof b!="symbol"?b+"":b,s),s);function mn(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const _u=mn(Qt),yn=mn(gu),oe=mn(yu),ft=mn(bu);var te=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},Kt={},ku={get exports(){return Kt},set exports(e){Kt=e}},Ut={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.min.js
4
4
  *
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
- */var Fa;function ou(){if(Fa)return Kt;Fa=1;var t=y,e=Symbol.for("react.element"),n=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,a=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function l(u,c,d){var f,h={},g=null,m=null;d!==void 0&&(g=""+d),c.key!==void 0&&(g=""+c.key),c.ref!==void 0&&(m=c.ref);for(f in c)r.call(c,f)&&!o.hasOwnProperty(f)&&(h[f]=c[f]);if(u&&u.defaultProps)for(f in c=u.defaultProps,c)h[f]===void 0&&(h[f]=c[f]);return{$$typeof:e,type:u,key:g,ref:m,props:h,_owner:a.current}}return Kt.Fragment=n,Kt.jsx=l,Kt.jsxs=l,Kt}var Ut={};/**
9
+ */var Ra;function Tu(){if(Ra)return Ut;Ra=1;var e=b,t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,a=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function l(u,c,d){var f,h={},g=null,m=null;d!==void 0&&(g=""+d),c.key!==void 0&&(g=""+c.key),c.ref!==void 0&&(m=c.ref);for(f in c)r.call(c,f)&&!o.hasOwnProperty(f)&&(h[f]=c[f]);if(u&&u.defaultProps)for(f in c=u.defaultProps,c)h[f]===void 0&&(h[f]=c[f]);return{$$typeof:t,type:u,key:g,ref:m,props:h,_owner:a.current}}return Ut.Fragment=n,Ut.jsx=l,Ut.jsxs=l,Ut}var Xt={};/**
10
10
  * @license React
11
11
  * react-jsx-runtime.development.js
12
12
  *
@@ -14,29 +14,29 @@
14
14
  *
15
15
  * This source code is licensed under the MIT license found in the
16
16
  * LICENSE file in the root directory of this source tree.
17
- */var Ga;function lu(){return Ga||(Ga=1,process.env.NODE_ENV!=="production"&&function(){var t=y,e=Symbol.for("react.element"),n=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),a=Symbol.for("react.strict_mode"),o=Symbol.for("react.profiler"),l=Symbol.for("react.provider"),u=Symbol.for("react.context"),c=Symbol.for("react.forward_ref"),d=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),h=Symbol.for("react.memo"),g=Symbol.for("react.lazy"),m=Symbol.for("react.offscreen"),w=Symbol.iterator,C="@@iterator";function _(S){if(S===null||typeof S!="object")return null;var z=w&&S[w]||S[C];return typeof z=="function"?z:null}var T=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function I(S){{for(var z=arguments.length,P=new Array(z>1?z-1:0),Q=1;Q<z;Q++)P[Q-1]=arguments[Q];O("error",S,P)}}function O(S,z,P){{var Q=T.ReactDebugCurrentFrame,se=Q.getStackAddendum();se!==""&&(z+="%s",P=P.concat([se]));var de=P.map(function(re){return String(re)});de.unshift("Warning: "+z),Function.prototype.apply.call(console[S],console,de)}}var B=!1,$=!1,A=!1,E=!1,F=!1,U;U=Symbol.for("react.module.reference");function Y(S){return!!(typeof S=="string"||typeof S=="function"||S===r||S===o||F||S===a||S===d||S===f||E||S===m||B||$||A||typeof S=="object"&&S!==null&&(S.$$typeof===g||S.$$typeof===h||S.$$typeof===l||S.$$typeof===u||S.$$typeof===c||S.$$typeof===U||S.getModuleId!==void 0))}function Z(S,z,P){var Q=S.displayName;if(Q)return Q;var se=z.displayName||z.name||"";return se!==""?P+"("+se+")":P}function oe(S){return S.displayName||"Context"}function ue(S){if(S==null)return null;if(typeof S.tag=="number"&&I("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof S=="function")return S.displayName||S.name||null;if(typeof S=="string")return S;switch(S){case r:return"Fragment";case n:return"Portal";case o:return"Profiler";case a:return"StrictMode";case d:return"Suspense";case f:return"SuspenseList"}if(typeof S=="object")switch(S.$$typeof){case u:var z=S;return oe(z)+".Consumer";case l:var P=S;return oe(P._context)+".Provider";case c:return Z(S,S.render,"ForwardRef");case h:var Q=S.displayName||null;return Q!==null?Q:ue(S.type)||"Memo";case g:{var se=S,de=se._payload,re=se._init;try{return ue(re(de))}catch{return null}}}return null}var be=Object.assign,De=0,ge,xe,me,Oe,Qe,At,or;function lr(){}lr.__reactDisabledLog=!0;function ma(){{if(De===0){ge=console.log,xe=console.info,me=console.warn,Oe=console.error,Qe=console.group,At=console.groupCollapsed,or=console.groupEnd;var S={configurable:!0,enumerable:!0,value:lr,writable:!0};Object.defineProperties(console,{info:S,log:S,warn:S,error:S,group:S,groupCollapsed:S,groupEnd:S})}De++}}function ya(){{if(De--,De===0){var S={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:be({},S,{value:ge}),info:be({},S,{value:xe}),warn:be({},S,{value:me}),error:be({},S,{value:Oe}),group:be({},S,{value:Qe}),groupCollapsed:be({},S,{value:At}),groupEnd:be({},S,{value:or})})}De<0&&I("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var ln=T.ReactCurrentDispatcher,Ft;function wt(S,z,P){{if(Ft===void 0)try{throw Error()}catch(se){var Q=se.stack.trim().match(/\n( *(at )?)/);Ft=Q&&Q[1]||""}return`
18
- `+Ft+S}}var zt=!1,Ct;{var Gt=typeof WeakMap=="function"?WeakMap:Map;Ct=new Gt}function Wt(S,z){if(!S||zt)return"";{var P=Ct.get(S);if(P!==void 0)return P}var Q;zt=!0;var se=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var de;de=ln.current,ln.current=null,ma();try{if(z){var re=function(){throw Error()};if(Object.defineProperty(re.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(re,[])}catch(dt){Q=dt}Reflect.construct(S,[],re)}else{try{re.call()}catch(dt){Q=dt}S.call(re.prototype)}}else{try{throw Error()}catch(dt){Q=dt}S()}}catch(dt){if(dt&&Q&&typeof dt.stack=="string"){for(var te=dt.stack.split(`
19
- `),Be=Q.stack.split(`
20
- `),we=te.length-1,Se=Be.length-1;we>=1&&Se>=0&&te[we]!==Be[Se];)Se--;for(;we>=1&&Se>=0;we--,Se--)if(te[we]!==Be[Se]){if(we!==1||Se!==1)do if(we--,Se--,Se<0||te[we]!==Be[Se]){var Ke=`
21
- `+te[we].replace(" at new "," at ");return S.displayName&&Ke.includes("<anonymous>")&&(Ke=Ke.replace("<anonymous>",S.displayName)),typeof S=="function"&&Ct.set(S,Ke),Ke}while(we>=1&&Se>=0);break}}}finally{zt=!1,ln.current=de,ya(),Error.prepareStackTrace=se}var Rt=S?S.displayName||S.name:"",Ul=Rt?wt(Rt):"";return typeof S=="function"&&Ct.set(S,Ul),Ul}function un(S,z,P){return Wt(S,!1)}function cn(S){var z=S.prototype;return!!(z&&z.isReactComponent)}function St(S,z,P){if(S==null)return"";if(typeof S=="function")return Wt(S,cn(S));if(typeof S=="string")return wt(S);switch(S){case d:return wt("Suspense");case f:return wt("SuspenseList")}if(typeof S=="object")switch(S.$$typeof){case c:return un(S.render);case h:return St(S.type,z,P);case g:{var Q=S,se=Q._payload,de=Q._init;try{return St(de(se),z,P)}catch{}}}return""}var dn=Object.prototype.hasOwnProperty,Bl={},Vl=T.ReactDebugCurrentFrame;function ur(S){if(S){var z=S._owner,P=St(S.type,S._source,z?z.type:null);Vl.setExtraStackFrame(P)}else Vl.setExtraStackFrame(null)}function PT(S,z,P,Q,se){{var de=Function.call.bind(dn);for(var re in S)if(de(S,re)){var te=void 0;try{if(typeof S[re]!="function"){var Be=Error((Q||"React class")+": "+P+" type `"+re+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof S[re]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Be.name="Invariant Violation",Be}te=S[re](z,re,Q,P,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(we){te=we}te&&!(te instanceof Error)&&(ur(se),I("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",Q||"React class",P,re,typeof te),ur(null)),te instanceof Error&&!(te.message in Bl)&&(Bl[te.message]=!0,ur(se),I("Failed %s type: %s",P,te.message),ur(null))}}}var BT=Array.isArray;function ba(S){return BT(S)}function VT(S){{var z=typeof Symbol=="function"&&Symbol.toStringTag,P=z&&S[Symbol.toStringTag]||S.constructor.name||"Object";return P}}function NT(S){try{return Nl(S),!1}catch{return!0}}function Nl(S){return""+S}function ql(S){if(NT(S))return I("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",VT(S)),Nl(S)}var pn=T.ReactCurrentOwner,qT={key:!0,ref:!0,__self:!0,__source:!0},Fl,Gl,va;va={};function FT(S){if(dn.call(S,"ref")){var z=Object.getOwnPropertyDescriptor(S,"ref").get;if(z&&z.isReactWarning)return!1}return S.ref!==void 0}function GT(S){if(dn.call(S,"key")){var z=Object.getOwnPropertyDescriptor(S,"key").get;if(z&&z.isReactWarning)return!1}return S.key!==void 0}function WT(S,z){if(typeof S.ref=="string"&&pn.current&&z&&pn.current.stateNode!==z){var P=ue(pn.current.type);va[P]||(I('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',ue(pn.current.type),S.ref),va[P]=!0)}}function jT(S,z){{var P=function(){Fl||(Fl=!0,I("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",z))};P.isReactWarning=!0,Object.defineProperty(S,"key",{get:P,configurable:!0})}}function RT(S,z){{var P=function(){Gl||(Gl=!0,I("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",z))};P.isReactWarning=!0,Object.defineProperty(S,"ref",{get:P,configurable:!0})}}var YT=function(S,z,P,Q,se,de,re){var te={$$typeof:e,type:S,key:z,ref:P,props:re,_owner:de};return te._store={},Object.defineProperty(te._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(te,"_self",{configurable:!1,enumerable:!1,writable:!1,value:Q}),Object.defineProperty(te,"_source",{configurable:!1,enumerable:!1,writable:!1,value:se}),Object.freeze&&(Object.freeze(te.props),Object.freeze(te)),te};function QT(S,z,P,Q,se){{var de,re={},te=null,Be=null;P!==void 0&&(ql(P),te=""+P),GT(z)&&(ql(z.key),te=""+z.key),FT(z)&&(Be=z.ref,WT(z,se));for(de in z)dn.call(z,de)&&!qT.hasOwnProperty(de)&&(re[de]=z[de]);if(S&&S.defaultProps){var we=S.defaultProps;for(de in we)re[de]===void 0&&(re[de]=we[de])}if(te||Be){var Se=typeof S=="function"?S.displayName||S.name||"Unknown":S;te&&jT(re,Se),Be&&RT(re,Se)}return YT(S,te,Be,se,Q,pn.current,re)}}var xa=T.ReactCurrentOwner,Wl=T.ReactDebugCurrentFrame;function jt(S){if(S){var z=S._owner,P=St(S.type,S._source,z?z.type:null);Wl.setExtraStackFrame(P)}else Wl.setExtraStackFrame(null)}var wa;wa=!1;function Ca(S){return typeof S=="object"&&S!==null&&S.$$typeof===e}function jl(){{if(xa.current){var S=ue(xa.current.type);if(S)return`
17
+ */var ja;function Du(){return ja||(ja=1,process.env.NODE_ENV!=="production"&&function(){var e=b,t=Symbol.for("react.element"),n=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),a=Symbol.for("react.strict_mode"),o=Symbol.for("react.profiler"),l=Symbol.for("react.provider"),u=Symbol.for("react.context"),c=Symbol.for("react.forward_ref"),d=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),h=Symbol.for("react.memo"),g=Symbol.for("react.lazy"),m=Symbol.for("react.offscreen"),C=Symbol.iterator,w="@@iterator";function _(S){if(S===null||typeof S!="object")return null;var z=C&&S[C]||S[w];return typeof z=="function"?z:null}var D=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function E(S){{for(var z=arguments.length,P=new Array(z>1?z-1:0),K=1;K<z;K++)P[K-1]=arguments[K];O("error",S,P)}}function O(S,z,P){{var K=D.ReactDebugCurrentFrame,ae=K.getStackAddendum();ae!==""&&(z+="%s",P=P.concat([ae]));var de=P.map(function(ne){return String(ne)});de.unshift("Warning: "+z),Function.prototype.apply.call(console[S],console,de)}}var B=!1,$=!1,A=!1,I=!1,F=!1,U;U=Symbol.for("react.module.reference");function Q(S){return!!(typeof S=="string"||typeof S=="function"||S===r||S===o||F||S===a||S===d||S===f||I||S===m||B||$||A||typeof S=="object"&&S!==null&&(S.$$typeof===g||S.$$typeof===h||S.$$typeof===l||S.$$typeof===u||S.$$typeof===c||S.$$typeof===U||S.getModuleId!==void 0))}function Z(S,z,P){var K=S.displayName;if(K)return K;var ae=z.displayName||z.name||"";return ae!==""?P+"("+ae+")":P}function se(S){return S.displayName||"Context"}function le(S){if(S==null)return null;if(typeof S.tag=="number"&&E("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof S=="function")return S.displayName||S.name||null;if(typeof S=="string")return S;switch(S){case r:return"Fragment";case n:return"Portal";case o:return"Profiler";case a:return"StrictMode";case d:return"Suspense";case f:return"SuspenseList"}if(typeof S=="object")switch(S.$$typeof){case u:var z=S;return se(z)+".Consumer";case l:var P=S;return se(P._context)+".Provider";case c:return Z(S,S.render,"ForwardRef");case h:var K=S.displayName||null;return K!==null?K:le(S.type)||"Memo";case g:{var ae=S,de=ae._payload,ne=ae._init;try{return le(ne(de))}catch{return null}}}return null}var ye=Object.assign,Ie=0,fe,ve,ge,Oe,Qe,zt,ur;function cr(){}cr.__reactDisabledLog=!0;function va(){{if(Ie===0){fe=console.log,ve=console.info,ge=console.warn,Oe=console.error,Qe=console.group,zt=console.groupCollapsed,ur=console.groupEnd;var S={configurable:!0,enumerable:!0,value:cr,writable:!0};Object.defineProperties(console,{info:S,log:S,warn:S,error:S,group:S,groupCollapsed:S,groupEnd:S})}Ie++}}function xa(){{if(Ie--,Ie===0){var S={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:ye({},S,{value:fe}),info:ye({},S,{value:ve}),warn:ye({},S,{value:ge}),error:ye({},S,{value:Oe}),group:ye({},S,{value:Qe}),groupCollapsed:ye({},S,{value:zt}),groupEnd:ye({},S,{value:ur})})}Ie<0&&E("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var un=D.ReactCurrentDispatcher,Gt;function Ct(S,z,P){{if(Gt===void 0)try{throw Error()}catch(ae){var K=ae.stack.trim().match(/\n( *(at )?)/);Gt=K&&K[1]||""}return`
18
+ `+Gt+S}}var $t=!1,St;{var Wt=typeof WeakMap=="function"?WeakMap:Map;St=new Wt}function Rt(S,z){if(!S||$t)return"";{var P=St.get(S);if(P!==void 0)return P}var K;$t=!0;var ae=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var de;de=un.current,un.current=null,va();try{if(z){var ne=function(){throw Error()};if(Object.defineProperty(ne.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(ne,[])}catch(pt){K=pt}Reflect.construct(S,[],ne)}else{try{ne.call()}catch(pt){K=pt}S.call(ne.prototype)}}else{try{throw Error()}catch(pt){K=pt}S()}}catch(pt){if(pt&&K&&typeof pt.stack=="string"){for(var ee=pt.stack.split(`
19
+ `),Be=K.stack.split(`
20
+ `),xe=ee.length-1,Se=Be.length-1;xe>=1&&Se>=0&&ee[xe]!==Be[Se];)Se--;for(;xe>=1&&Se>=0;xe--,Se--)if(ee[xe]!==Be[Se]){if(xe!==1||Se!==1)do if(xe--,Se--,Se<0||ee[xe]!==Be[Se]){var Ke=`
21
+ `+ee[xe].replace(" at new "," at ");return S.displayName&&Ke.includes("<anonymous>")&&(Ke=Ke.replace("<anonymous>",S.displayName)),typeof S=="function"&&St.set(S,Ke),Ke}while(xe>=1&&Se>=0);break}}}finally{$t=!1,un.current=de,xa(),Error.prepareStackTrace=ae}var Yt=S?S.displayName||S.name:"",fu=Yt?Ct(Yt):"";return typeof S=="function"&&St.set(S,fu),fu}function cn(S,z,P){return Rt(S,!1)}function dn(S){var z=S.prototype;return!!(z&&z.isReactComponent)}function _t(S,z,P){if(S==null)return"";if(typeof S=="function")return Rt(S,dn(S));if(typeof S=="string")return Ct(S);switch(S){case d:return Ct("Suspense");case f:return Ct("SuspenseList")}if(typeof S=="object")switch(S.$$typeof){case c:return cn(S.render);case h:return _t(S.type,z,P);case g:{var K=S,ae=K._payload,de=K._init;try{return _t(de(ae),z,P)}catch{}}}return""}var pn=Object.prototype.hasOwnProperty,nu={},ru=D.ReactDebugCurrentFrame;function dr(S){if(S){var z=S._owner,P=_t(S.type,S._source,z?z.type:null);ru.setExtraStackFrame(P)}else ru.setExtraStackFrame(null)}function hD(S,z,P,K,ae){{var de=Function.call.bind(pn);for(var ne in S)if(de(S,ne)){var ee=void 0;try{if(typeof S[ne]!="function"){var Be=Error((K||"React class")+": "+P+" type `"+ne+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof S[ne]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Be.name="Invariant Violation",Be}ee=S[ne](z,ne,K,P,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(xe){ee=xe}ee&&!(ee instanceof Error)&&(dr(ae),E("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",K||"React class",P,ne,typeof ee),dr(null)),ee instanceof Error&&!(ee.message in nu)&&(nu[ee.message]=!0,dr(ae),E("Failed %s type: %s",P,ee.message),dr(null))}}}var fD=Array.isArray;function wa(S){return fD(S)}function gD(S){{var z=typeof Symbol=="function"&&Symbol.toStringTag,P=z&&S[Symbol.toStringTag]||S.constructor.name||"Object";return P}}function mD(S){try{return iu(S),!1}catch{return!0}}function iu(S){return""+S}function au(S){if(mD(S))return E("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",gD(S)),iu(S)}var hn=D.ReactCurrentOwner,yD={key:!0,ref:!0,__self:!0,__source:!0},su,ou,Ca;Ca={};function bD(S){if(pn.call(S,"ref")){var z=Object.getOwnPropertyDescriptor(S,"ref").get;if(z&&z.isReactWarning)return!1}return S.ref!==void 0}function vD(S){if(pn.call(S,"key")){var z=Object.getOwnPropertyDescriptor(S,"key").get;if(z&&z.isReactWarning)return!1}return S.key!==void 0}function xD(S,z){if(typeof S.ref=="string"&&hn.current&&z&&hn.current.stateNode!==z){var P=le(hn.current.type);Ca[P]||(E('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',le(hn.current.type),S.ref),Ca[P]=!0)}}function wD(S,z){{var P=function(){su||(su=!0,E("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",z))};P.isReactWarning=!0,Object.defineProperty(S,"key",{get:P,configurable:!0})}}function CD(S,z){{var P=function(){ou||(ou=!0,E("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",z))};P.isReactWarning=!0,Object.defineProperty(S,"ref",{get:P,configurable:!0})}}var SD=function(S,z,P,K,ae,de,ne){var ee={$$typeof:t,type:S,key:z,ref:P,props:ne,_owner:de};return ee._store={},Object.defineProperty(ee._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(ee,"_self",{configurable:!1,enumerable:!1,writable:!1,value:K}),Object.defineProperty(ee,"_source",{configurable:!1,enumerable:!1,writable:!1,value:ae}),Object.freeze&&(Object.freeze(ee.props),Object.freeze(ee)),ee};function _D(S,z,P,K,ae){{var de,ne={},ee=null,Be=null;P!==void 0&&(au(P),ee=""+P),vD(z)&&(au(z.key),ee=""+z.key),bD(z)&&(Be=z.ref,xD(z,ae));for(de in z)pn.call(z,de)&&!yD.hasOwnProperty(de)&&(ne[de]=z[de]);if(S&&S.defaultProps){var xe=S.defaultProps;for(de in xe)ne[de]===void 0&&(ne[de]=xe[de])}if(ee||Be){var Se=typeof S=="function"?S.displayName||S.name||"Unknown":S;ee&&wD(ne,Se),Be&&CD(ne,Se)}return SD(S,ee,Be,ae,K,hn.current,ne)}}var Sa=D.ReactCurrentOwner,lu=D.ReactDebugCurrentFrame;function jt(S){if(S){var z=S._owner,P=_t(S.type,S._source,z?z.type:null);lu.setExtraStackFrame(P)}else lu.setExtraStackFrame(null)}var _a;_a=!1;function ka(S){return typeof S=="object"&&S!==null&&S.$$typeof===t}function uu(){{if(Sa.current){var S=le(Sa.current.type);if(S)return`
22
22
 
23
- Check the render method of \``+S+"`."}return""}}function KT(S){{if(S!==void 0){var z=S.fileName.replace(/^.*[\\\/]/,""),P=S.lineNumber;return`
23
+ Check the render method of \``+S+"`."}return""}}function kD(S){{if(S!==void 0){var z=S.fileName.replace(/^.*[\\\/]/,""),P=S.lineNumber;return`
24
24
 
25
- Check your code at `+z+":"+P+"."}return""}}var Rl={};function UT(S){{var z=jl();if(!z){var P=typeof S=="string"?S:S.displayName||S.name;P&&(z=`
25
+ Check your code at `+z+":"+P+"."}return""}}var cu={};function TD(S){{var z=uu();if(!z){var P=typeof S=="string"?S:S.displayName||S.name;P&&(z=`
26
26
 
27
- Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(!S._store||S._store.validated||S.key!=null)return;S._store.validated=!0;var P=UT(z);if(Rl[P])return;Rl[P]=!0;var Q="";S&&S._owner&&S._owner!==xa.current&&(Q=" It was passed a child from "+ue(S._owner.type)+"."),jt(S),I('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',P,Q),jt(null)}}function Ql(S,z){{if(typeof S!="object")return;if(ba(S))for(var P=0;P<S.length;P++){var Q=S[P];Ca(Q)&&Yl(Q,z)}else if(Ca(S))S._store&&(S._store.validated=!0);else if(S){var se=_(S);if(typeof se=="function"&&se!==S.entries)for(var de=se.call(S),re;!(re=de.next()).done;)Ca(re.value)&&Yl(re.value,z)}}}function XT(S){{var z=S.type;if(z==null||typeof z=="string")return;var P;if(typeof z=="function")P=z.propTypes;else if(typeof z=="object"&&(z.$$typeof===c||z.$$typeof===h))P=z.propTypes;else return;if(P){var Q=ue(z);PT(P,S.props,"prop",Q,S)}else if(z.PropTypes!==void 0&&!wa){wa=!0;var se=ue(z);I("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",se||"Unknown")}typeof z.getDefaultProps=="function"&&!z.getDefaultProps.isReactClassApproved&&I("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function JT(S){{for(var z=Object.keys(S.props),P=0;P<z.length;P++){var Q=z[P];if(Q!=="children"&&Q!=="key"){jt(S),I("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",Q),jt(null);break}}S.ref!==null&&(jt(S),I("Invalid attribute `ref` supplied to `React.Fragment`."),jt(null))}}function Kl(S,z,P,Q,se,de){{var re=Y(S);if(!re){var te="";(S===void 0||typeof S=="object"&&S!==null&&Object.keys(S).length===0)&&(te+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var Be=KT(se);Be?te+=Be:te+=jl();var we;S===null?we="null":ba(S)?we="array":S!==void 0&&S.$$typeof===e?(we="<"+(ue(S.type)||"Unknown")+" />",te=" Did you accidentally export a JSX literal instead of a component?"):we=typeof S,I("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",we,te)}var Se=QT(S,z,P,se,de);if(Se==null)return Se;if(re){var Ke=z.children;if(Ke!==void 0)if(Q)if(ba(Ke)){for(var Rt=0;Rt<Ke.length;Rt++)Ql(Ke[Rt],S);Object.freeze&&Object.freeze(Ke)}else I("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Ql(Ke,S)}return S===r?JT(Se):XT(Se),Se}}function ZT(S,z,P){return Kl(S,z,P,!0)}function HT(S,z,P){return Kl(S,z,P,!1)}var eD=HT,tD=ZT;Ut.Fragment=r,Ut.jsx=eD,Ut.jsxs=tD}()),Ut}(function(t){process.env.NODE_ENV==="production"?t.exports=ou():t.exports=lu()})(su);const V=Qt.Fragment,i=Qt.jsx,p=Qt.jsxs,$t={CryptoJS:Sa,d3Array:au,dayjs:R,lodash:x,numbro:ee,mathjs:mn,faker:Jl.faker},uu=[{name:"CryptoJS",url:"https://github.com/brix/crypto-js",version:"4.1.1"},{name:"d3Array",url:"https://github.com/d3/d3-array",version:"3.2.0"},{name:"dayjs",url:"https://day.js.org/",version:"1.11.6"},{name:"lodash",url:"https://lodash.com/docs/4.17.15",version:"4.17.21"},{name:"mathjs",url:"https://mathjs.org/",version:"11.7.0"},{name:"numbro",url:"https://numbrojs.com/",version:"2.3.6"},{name:"faker",url:"https://fakerjs.dev/",version:"7.6.0"}],cu=t=>`
27
+ Check the top-level render call using <`+P+">.")}return z}}function du(S,z){{if(!S._store||S._store.validated||S.key!=null)return;S._store.validated=!0;var P=TD(z);if(cu[P])return;cu[P]=!0;var K="";S&&S._owner&&S._owner!==Sa.current&&(K=" It was passed a child from "+le(S._owner.type)+"."),jt(S),E('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',P,K),jt(null)}}function pu(S,z){{if(typeof S!="object")return;if(wa(S))for(var P=0;P<S.length;P++){var K=S[P];ka(K)&&du(K,z)}else if(ka(S))S._store&&(S._store.validated=!0);else if(S){var ae=_(S);if(typeof ae=="function"&&ae!==S.entries)for(var de=ae.call(S),ne;!(ne=de.next()).done;)ka(ne.value)&&du(ne.value,z)}}}function DD(S){{var z=S.type;if(z==null||typeof z=="string")return;var P;if(typeof z=="function")P=z.propTypes;else if(typeof z=="object"&&(z.$$typeof===c||z.$$typeof===h))P=z.propTypes;else return;if(P){var K=le(z);hD(P,S.props,"prop",K,S)}else if(z.PropTypes!==void 0&&!_a){_a=!0;var ae=le(z);E("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",ae||"Unknown")}typeof z.getDefaultProps=="function"&&!z.getDefaultProps.isReactClassApproved&&E("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function MD(S){{for(var z=Object.keys(S.props),P=0;P<z.length;P++){var K=z[P];if(K!=="children"&&K!=="key"){jt(S),E("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",K),jt(null);break}}S.ref!==null&&(jt(S),E("Invalid attribute `ref` supplied to `React.Fragment`."),jt(null))}}function hu(S,z,P,K,ae,de){{var ne=Q(S);if(!ne){var ee="";(S===void 0||typeof S=="object"&&S!==null&&Object.keys(S).length===0)&&(ee+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var Be=kD(ae);Be?ee+=Be:ee+=uu();var xe;S===null?xe="null":wa(S)?xe="array":S!==void 0&&S.$$typeof===t?(xe="<"+(le(S.type)||"Unknown")+" />",ee=" Did you accidentally export a JSX literal instead of a component?"):xe=typeof S,E("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",xe,ee)}var Se=_D(S,z,P,ae,de);if(Se==null)return Se;if(ne){var Ke=z.children;if(Ke!==void 0)if(K)if(wa(Ke)){for(var Yt=0;Yt<Ke.length;Yt++)pu(Ke[Yt],S);Object.freeze&&Object.freeze(Ke)}else E("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else pu(Ke,S)}return S===r?MD(Se):DD(Se),Se}}function ID(S,z,P){return hu(S,z,P,!0)}function ED(S,z,P){return hu(S,z,P,!1)}var AD=ED,zD=ID;Xt.Fragment=r,Xt.jsx=AD,Xt.jsxs=zD}()),Xt}(function(e){process.env.NODE_ENV==="production"?e.exports=Tu():e.exports=Du()})(ku);const V=Kt.Fragment,i=Kt.jsx,p=Kt.jsxs,Lt={CryptoJS:Ta,d3Array:_u,dayjs:j,lodash:x,numbro:H,mathjs:yn,faker:mu.faker},Mu=[{name:"CryptoJS",url:"https://github.com/brix/crypto-js",version:"4.1.1"},{name:"d3Array",url:"https://github.com/d3/d3-array",version:"3.2.0"},{name:"dayjs",url:"https://day.js.org/",version:"1.11.6"},{name:"lodash",url:"https://lodash.com/docs/4.17.15",version:"4.17.21"},{name:"mathjs",url:"https://mathjs.org/",version:"11.7.0"},{name:"numbro",url:"https://numbrojs.com/",version:"2.3.6"},{name:"faker",url:"https://fakerjs.dev/",version:"7.6.0"}],Iu=e=>`
28
28
  <tr>
29
- <td><code>${t.name}</code></td>
29
+ <td><code>${e.name}</code></td>
30
30
  <td>
31
31
  <a
32
32
  target="_blank"
33
33
  rel="noopener noreferrer nofollow"
34
- href="${t.url}"
35
- >${t.name}@${t.version}</a
34
+ href="${e.url}"
35
+ >${e.name}@${e.version}</a
36
36
  >
37
37
  </td>
38
38
  </tr>
39
- `,du=`
39
+ `,Eu=`
40
40
  <p>
41
41
  Parameter <code>utils</code> is <code>functionUtils</code>, which contains:
42
42
  </p>
@@ -48,128 +48,63 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
48
48
  </tr>
49
49
  </thead>
50
50
  <tbody>
51
- ${uu.map(cu).join("")}
51
+ ${Mu.map(Iu).join("")}
52
52
  </tbody>
53
53
  </table>
54
- `;function pr(t,e){const n=Object.keys(e),r=Object.values(e);try{return new Function(...n,`return \`${t}\`;`)(...r)}catch(a){throw n.length===0&&t.includes("$")?new Error("[formatSQL] insufficient payload"):a}}function hr(t,e){try{return pr(t,e)}catch(n){return console.error(n),n.message}}function pu({sql:t,pre_process:e}){if(!e.trim())return t;try{return new Function(`return ${e}`)()({sql:t},$t)}catch(n){return console.error(n),t}}function hu(t,e){if(!t.trim())return e;try{return new Function(`return ${t}`)()(e,$t)}catch(n){return console.error(n),e}}function fu(t){t=t||{};const e=Object.keys(t).sort(),n=[];for(let r=0;r<e.length;r++){const a=e[r];if(a!="authentication"&&t[a])n.push(e[r]+"="+(typeof t[a]=="object"?JSON.stringify(t[a]):t[a]));else{const o=Object.keys(t[a]).sort();for(let l=0;l<o.length;l++){const u=o[l];u!="sign"&&t[a][u]&&n.push(o[l]+"="+(typeof t[a][u]=="object"?JSON.stringify(t[a][u]):t[a][u]))}}}return n.sort().join("&")}function gu(t,e){let n=fu(t);return n+="&key="+e,Sa.MD5(n).toString().toUpperCase()}const qe={baseURL:"http://localhost:31200",app_id:"",app_secret:"",getAuthentication(t){if(!this.app_id||!this.app_secret)return;const e=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:e,sign:gu({app_id:this.app_id,nonce_str:e,...t},this.app_secret)}},getRequest(t,e){return(n,r,a={})=>{const o=window.localStorage.getItem("token"),l={"X-Requested-With":"XMLHttpRequest","Content-Type":a.string?"application/x-www-form-urlencoded":"application/json",authorization:o?`bearer ${o}`:"",...a.headers},u={baseURL:this.baseURL,method:t,url:n,params:t==="GET"?r:a.params,headers:l,signal:e};return["POST","PUT"].includes(t)&&(u.data=a.string?JSON.stringify(r):r,u.data.authentication=this.getAuthentication(u.data)),pt(u).then(c=>c.data).catch(c=>Promise.reject(c))}},makeQueryENV:null,query(t){return async(e,n={})=>{var r;return e.env||(e.env=((r=this.makeQueryENV)==null?void 0:r.call(this))??{error:"failed to run makeQueryENV"}),this.getRequest("POST",t)("/query",e,n)}}};function Wa(t){qe.baseURL!==t.apiBaseURL&&(qe.baseURL=t.apiBaseURL),t.app_id&&(qe.app_id=t.app_id),t.app_secret&&(qe.app_secret=t.app_secret),t.makeQueryENV&&(qe.makeQueryENV=t.makeQueryENV)}async function mu({query:t,payload:e},n){if(!t.sql)return[];const{type:r,key:a,sql:o,pre_process:l,post_process:u}=t,c=pr(o,e),d=pu({sql:c,pre_process:l});let f=await qe.query(n)({type:r,key:a,query:d},{});return f=hu(u,f),f}async function yu({type:t,key:e,configString:n},r){return await qe.query(r)({type:t,key:e,query:n},{})}async function fr(){try{return(await qe.getRequest("POST")("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}})).data}catch(t){return console.error(t),[]}}async function ja(){try{return(await qe.getRequest("POST")("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}})).data}catch(t){return console.error(t),[]}}const Ra=y.createContext(null),gr=Ra.Provider;function K(){const t=y.useContext(Ra);if(!t)throw new Error("Please use ContentModelContextProvider");return t}const bu={layoutFrozen:!1,freezeLayout:x.noop,inEditMode:!1},ft=y.createContext(bu),Ya=y.createContext(null),mr=Ya.Provider;function he(){const t=y.useContext(Ya);if(!t)throw new Error("Please use ModelContextProvider");return t}function Qa(t,e){y.useEffect(()=>{const n=r=>{console.log(r);const{viewID:a}=r.detail;if(!a){console.error(new Error("[Open View] Needs to pick a view first"));return}t.views.appendToVisibles(a),e&&t.views.setIDOfVIE(a)};return window.addEventListener("open-view",n),()=>{window.removeEventListener("open-view",n)}},[t,e]),y.useEffect(()=>{const n=r=>{console.log(r);const{dictionary:a,payload:o}=r.detail;if(!o||Object.keys(o).length===0){console.error(new Error("[Set Filter Values] payload is empty"));return}Object.entries(a).forEach(([l,u])=>{t.filters.setValueByKey(l,x.get(o,u))})};return window.addEventListener("set-filter-values",n),()=>{window.removeEventListener("set-filter-values",n)}},[t]),y.useEffect(()=>{function n(a){return Array.isArray(a)?[]:typeof a=="object"?{}:typeof a=="boolean"?!1:typeof a=="string"?"":typeof a=="number"?0:a}const r=a=>{console.log(a);const{filter_keys:o}=a.detail;o.forEach(l=>{const u=x.get(t.filters.values,l),c=n(u);console.log(`${l}: ${c}`),t.filters.setValueByKey(l,c)})};return window.addEventListener("clear-filter-values",r),()=>{window.removeEventListener("clear-filter-values",r)}},[t]),y.useEffect(()=>{const n=r=>{console.log(r);const{urlTemplate:a,openInNewTab:o,enableEncoding:l=!1,payload:u}=r.detail;if(!a){console.error(new Error("[Open Link] URL is empty"));return}function c(h){return x.cloneDeepWith(h,m=>{if(l&&typeof m=="string")return encodeURIComponent(m)})}const f=x.template(a||"")(c({...u,filters:t.payloadForSQL.filters,context:t.payloadForSQL.context}));window.open(f,o?"_blank":"_self","noopener")};return window.addEventListener("open-link",n),()=>{window.removeEventListener("open-link",n)}},[t])}const Ka=b.types.model("FilterConfigModel_Checkbox",{_name:b.types.literal("checkbox"),description:b.types.optional(b.types.string,""),default_value:b.types.boolean}).views(t=>({get json(){const{_name:e,description:n,default_value:r}=t;return{_name:e,description:n,default_value:r}},get isDescriptionEmpty(){const{description:e}=t;return e===""||e==="<p></p>"}})).actions(t=>({setDefaultValue(e){t.default_value=e},setDescription(e){t.description=e}})),vu=()=>Ka.create({_name:"checkbox",description:"",default_value:!1});var ye=(t=>(t.Postgresql="postgresql",t.MySQL="mysql",t.HTTP="http",t))(ye||{}),Ae=(t=>(t.Select="select",t.MultiSelect="multi-select",t.TreeSelect="tree-select",t.TextInput="text-input",t.Checkbox="checkbox",t.DateRange="date-range",t))(Ae||{});b.types.model({type:b.types.enumeration("DataSourceType",[ye.Postgresql,ye.MySQL,ye.HTTP]),key:b.types.string,sql:b.types.string});function Ua(t,e){return t.map(n=>{try{return n?R.tz(n,"UTC").format(e):null}catch{return console.log(`[date-range] failed parsing ${n}`),null}})}const xu=b.types.model("FilterConfigModel_DateRange",{_name:b.types.literal("date-range"),required:b.types.boolean,inputFormat:b.types.enumeration("DateRangeInputFormat",["YYYY","YYYYMM","YYYYMMDD","YYYY-MM","YYYY-MM-DD"]),default_value:b.types.optional(b.types.array(b.types.union(b.types.string,b.types.null)),[null,null]),clearable:b.types.boolean,max_days:b.types.optional(b.types.number,0),allowSingleDateInRange:b.types.optional(b.types.boolean,!1)}).views(t=>({get json(){const{_name:e,max_days:n,required:r,clearable:a,inputFormat:o,default_value:l,allowSingleDateInRange:u}=t;return{_name:e,max_days:n,required:r,clearable:a,inputFormat:o,default_value:Ua(l,o),allowSingleDateInRange:u}},truthy(e){return Array.isArray(e)&&e.length===2&&e.every(n=>!!n)}})).views(t=>({getMaxDate(e){const{max_days:n}=t;if(!(!n||!e))return R(e).startOf("day").add(n,"days").toDate()},getMinDate(e){const{max_days:n}=t;if(!(!n||!e))return R(e).startOf("day").subtract(n,"days").toDate()}})).actions(t=>({setFilterValue(e){try{const n=b.getParent(t);b.getRoot(t).filters.setValueByKey(n.key,e)}catch(n){console.error(n)}}})).actions(t=>({setRequired(e){t.required=e},setClearable(e){t.clearable=e},setInputFormat(e){t.inputFormat=e},setDefaultValue(e){t.default_value.length=0,t.default_value.push(...e),t.setFilterValue(e)},setMaxDays(e){t.max_days=e,e>0&&(t.clearable=!0)},setAllowSingleDateInRange(e){t.allowSingleDateInRange=e}})),Xa=b.types.snapshotProcessor(xu,{preProcessor({default_value:t,...e}){return{...e,default_value:t.map(n=>n===null?null:R.tz(n,"UTC").toISOString())}},postProcessor(t){const{default_value:e,...n}=t;return{...n,default_value:Ua(e,n.inputFormat)}}}),wu=()=>Xa.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),Cu=b.types.model({label:b.types.string,value:b.types.string}).actions(t=>({setLabel(e){t.label=e},setValue(e){t.value=e}})),yr=b.types.model("FilterConfigModel_BaseSelect",{static_options:b.types.optional(b.types.array(Cu),[]),options_query_id:b.types.optional(b.types.string,""),default_selection_count:b.types.optional(b.types.number,0)}).views(t=>({get usingQuery(){return!!t.options_query_id}})).views(t=>({get options(){if(!t.usingQuery)return t.static_options;const{data:e,state:n,error:r}=b.getRoot(t).content.getDataStuffByID(t.options_query_id);return n==="idle"?e:[]}})).actions(t=>({addStaticOption(e){t.static_options.push(e)},removeStaticOption(e){t.static_options.splice(e,1)},setDefaultSelectionCount(e){t.default_selection_count=e},setOptionsQueryID(e){t.options_query_id=e??""}})),yn=t=>x.cloneDeepWith(t,(e,n)=>{if(n!==void 0&&e)return ie.toJS(e)}),Ja=b.types.compose("FilterConfigModel_MultiSelect",b.types.model({_name:b.types.literal("multi-select"),min_width:b.types.optional(b.types.string,""),default_value:b.types.optional(b.types.array(b.types.string),[])}),yr).views(t=>({get json(){const{_name:e,default_value:n,min_width:r,static_options:a,options_query_id:o,default_selection_count:l}=t;return yn({_name:e,min_width:r,default_value:n,static_options:a,options_query_id:o,default_selection_count:l})},get default_selection(){return t.usingQuery?t.options.slice(0,t.default_selection_count).map(e=>e.value):t.default_value}})).actions(t=>({setDefaultValue(e){t.default_value=b.cast(e)},setMinWidth(e){t.min_width=e},setDefaultSelection(){const e=b.getRoot(t).content.filters,n=b.getParent(t).key;e.setValueByKey(n,t.default_selection)}})).actions(t=>({afterCreate(){b.addDisposer(t,ie.reaction(()=>ie.toJS(t.default_selection),t.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),Su=()=>Ja.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0});function _u(t){return Zl.arrayToTree(t,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}function ku(t){return t.map(e=>{const{label:n,description:r,...a}=e,o={...a,filterBasis:`${n}___${r??""}`,description:r,label:n};return r&&(o.label=y.createElement("div",{},[y.createElement(s.Text,{key:0,title:e.label},e.label),y.createElement(s.Text,{key:1,className:"rc-tree-select-tree-title-desc",color:"dimmed",title:e.description},e.description)])),o})}const Za=b.types.compose("FilterConfigModel_TreeSelect",b.types.model({_name:b.types.literal("tree-select"),min_width:b.types.optional(b.types.string,""),default_value:b.types.optional(b.types.array(b.types.string),[])}),yr).views(t=>({get json(){const{_name:e,default_value:n,min_width:r,static_options:a,options_query_id:o,default_selection_count:l}=t;return{_name:e,min_width:r,default_value:n,static_options:a,options_query_id:o,default_selection_count:l}},get treeData(){const{data:e}=b.getRoot(t).content.getDataStuffByID(t.options_query_id),n=ku(e);return _u(n)},get errorMessage(){const{error:e}=b.getRoot(t).content.getDataStuffByID(t.options_query_id);return e},get treeDataLoading(){const{state:e}=b.getRoot(t).content.getDataStuffByID(t.options_query_id);return e==="loading"},get defaultSelection(){const{default_selection_count:e}=t;return e?this.treeData.slice(0,e).map(r=>r.value):[]}})).actions(t=>({setDefaultValue(e){t.default_value=b.cast(e)},setMinWidth(e){t.min_width=e},applyDefaultSelection(){const e=b.getParent(t,1).key;b.getRoot(t).content.filters.setValueByKey(e,t.defaultSelection)},afterCreate(){b.addDisposer(t,ie.reaction(()=>JSON.stringify(t.defaultSelection),this.applyDefaultSelection,{fireImmediately:!0,delay:0}))}})),Tu=()=>Za.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),Ha=b.types.compose("FilterConfigModel_Select",b.types.model({_name:b.types.literal("select"),default_value:b.types.string,required:b.types.boolean,width:b.types.optional(b.types.string,"")}),yr).views(t=>({get json(){const{_name:e,default_value:n,required:r,width:a,static_options:o,options_query_id:l,default_selection_count:u}=t;return yn({_name:e,width:a,required:r,default_value:n,static_options:o,options_query_id:l,default_selection_count:u})},truthy(e){return!!e}})).actions(t=>({setRequired(e){t.required=e},setDefaultValue(e){t.default_value=e},setWidth(e){t.width=e}})),Du=()=>Ha.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),es=b.types.model("FilterConfigModel_TextInput",{_name:b.types.literal("text-input"),required:b.types.boolean,default_value:b.types.string}).views(t=>({get json(){const{_name:e,required:n,default_value:r}=t;return{_name:e,required:n,default_value:r}},truthy(e){return typeof e!="string"?!1:!!e.trim()}})).actions(t=>({setRequired(e){t.required=e},setDefaultValue(e){t.default_value=e}})),ts=()=>es.create({_name:"text-input",required:!1,default_value:""}),br=b.types.model("FilterModel",{id:b.types.identifier,key:b.types.string,label:b.types.string,order:b.types.number,visibleInViewsIDs:b.types.array(b.types.string),auto_submit:b.types.optional(b.types.boolean,!1),type:b.types.enumeration("DashboardFilterType",[Ae.Select,Ae.MultiSelect,Ae.TreeSelect,Ae.TextInput,Ae.Checkbox,Ae.DateRange]),config:b.types.union(Ha,Ja,Za,es,Ka,Xa)}).views(t=>({get plainDefaultValue(){const e=t.config.default_value;return Array.isArray(e)?[...e]:e},get usingDefaultValue(){return t.type!==Ae.TreeSelect},get auto_submit_supported(){return[Ae.Select,Ae.Checkbox,Ae.DateRange].includes(t.type)}})).views(t=>({get json(){const{id:e,key:n,label:r,order:a,visibleInViewsIDs:o,auto_submit:l,type:u,config:c}=t;return{id:e,key:n,type:u,label:r,order:a,config:c.json,auto_submit:l,visibleInViewsIDs:ie.toJS(o)}},get should_auto_submit(){return t.auto_submit_supported&&t.auto_submit},requiredAndPass(e){return x.get(t.config,"required",!1)?x.get(t.config,"truthy",()=>!0)(e):!1}})).actions(t=>({setKey(e){t.key=e},setLabel(e){t.label=e},setOrder(e){t.order=e},setType(e){switch(e){case Ae.Select:t.config=Du();break;case Ae.MultiSelect:t.config=Su();break;case Ae.TreeSelect:t.config=Tu();break;case Ae.TextInput:t.config=ts();break;case Ae.Checkbox:t.config=vu();break;case Ae.DateRange:t.config=wu();break}t.type=e},setVisibleInViewsIDs(e){t.visibleInViewsIDs.length=0,t.visibleInViewsIDs.push(...e)},setAutoSubmit(e){t.auto_submit=t.auto_submit_supported&&e}}));function ns(t,e){if(t===void 0)return t;if(e._name==="date-range")try{const[...n]=t;return n.map(r=>r===null?r:R.tz(r,"UTC").format(e.inputFormat)??r)}catch(n){return console.error(n),t}return t}function Mu(t){return t.reduce((e,n)=>(e[n.key]=ns(n.config.default_value,n.config),e),{})}function Iu(t,e,n){b.addDisposer(t,b.addMiddleware(t,(r,a)=>{a(r,()=>{b.getType(r.context)===e&&r.type==="action"&&n(r.name,r.context)})}))}const rs=b.types.model("FiltersModel",{current:b.types.optional(b.types.array(br),[]),values:b.types.optional(b.types.frozen(),{}),previewValues:b.types.optional(b.types.frozen(),{})}).views(t=>({get json(){return t.current.map(e=>e.json)},get firstID(){if(t.current.length!==0)return t.current[0].id},findByID(e){return t.current.find(n=>n.id===e)},get inOrder(){return x.sortBy(t.current,"order")},get options(){return t.current.map(e=>({label:e.label??e.id,value:e.id,_type:"filter"}))},get keyLabelOptions(){return t.current.map(e=>({label:e.label??e.key,value:e.key}))},get empty(){return t.current.length===0},visibleInView(e){return x.sortBy(t.current.filter(n=>n.visibleInViewsIDs.includes(e)),"order")},get firstFilterValueKey(){return Object.keys(t.values)[0]??""},get keyLabelMap(){return t.current.reduce((e,n)=>(e[n.key]=n.label,e),{})}})).actions(t=>({replace(e){t.current=b.cast(e)},append(e){t.current.push(e)},remove(e){t.current.splice(e,1)},removeByID(e){const n=t.current.findIndex(r=>r.id===e);n>=0&&t.current.splice(n,1)},setValues(e){t.values=e},setValueByKey(e,n){t.values={...t.values,[e]:n}},getValueByKey(e){return t.values[e]},updatePreviewValues(e){t.previewValues=e}})).actions(t=>{function e(){Iu(t.current,br,(n,r)=>{if(n==="setType"){const a=ns(r.config.default_value,r.config);t.setValueByKey(r.key,a),t.updatePreviewValues({...t.previewValues,[r.key]:a})}})}return{afterCreate(){e()}}});function is(t){return{current:t,values:Mu(t)}}const as="\uFEFF";function Eu(t,e){const n=new Blob([as+e],{type:"text/csv"});cr.saveAs(n,`${t}.csv`)}function Au(t,e){const n=new Blob([e],{type:"application/json"});cr.saveAs(n,`${t}.json`)}function ss(t){const e=new Hl;t.forEach(({id:n,data:r})=>{e.file(`${n}.csv`,ls(r))}),e.generateAsync({type:"blob"}).then(n=>{cr.saveAs(n,"dashboard_data.zip")})}function os(t){return typeof t=="string"&&t.includes(",")?`"${t}"`:t}function ls(t){if(!Array.isArray(t)||t.length===0)return"";const e=[],n=Object.keys(t[0]).map(os);return e.push(n.join(",")),t.forEach(r=>{const a=Object.values(r).map(os).join(",");e.push(a)}),as+e.join(`
55
- `)}const zu=b.types.model("QueryModel",{id:b.types.string,name:b.types.string,type:b.types.enumeration("DataSourceType",[ye.Postgresql,ye.MySQL,ye.HTTP]),key:b.types.string,sql:b.types.string,pre_process:b.types.optional(b.types.string,""),post_process:b.types.optional(b.types.string,""),run_by:b.types.optional(b.types.array(b.types.string),[]),react_to:b.types.optional(b.types.array(b.types.string),[])}).views(t=>({get valid(){return t.id&&t.type&&t.key&&t.name?t.type===ye.HTTP?!!t.pre_process:!!t.sql:!1},get json(){const{id:e,name:n,type:r,key:a,sql:o,run_by:l,react_to:u,pre_process:c,post_process:d}=t;return yn({id:e,key:a,sql:o,name:n,type:r,run_by:l,react_to:u,pre_process:c,post_process:d})},get conditionOptions(){if(!b.isAlive(t))return[];const{context:e,filters:n}=b.getRoot(t).content.payloadForSQL,r=Object.keys({...e}).map(l=>`context.${l}`),a=Object.keys(n).map(l=>`filters.${l}`);return[...r,...a].map(l=>({label:l.split(".")[1],value:l,group:x.capitalize(l.split(".")[0])}))},get unmetRunByConditions(){if(!b.isAlive(t))return[];const{run_by:e}=t;if(e.length===0)return[];const n=b.getRoot(t).content.payloadForSQL;return e.filter(r=>{const a=x.get(n,r);return Array.isArray(a)?a.length===0:typeof a=="number"?Number.isNaN(a):!a})}})).views(t=>({get reQueryKey(){const{react_to:e=[]}=t;if(e.length===0)return"";const n=b.getRoot(t).content.payloadForSQL,r=[...e].reduce((a,o)=>(a[o]=x.get(n,o),a),{});return JSON.stringify(r)},get runByConditionsMet(){return t.unmetRunByConditions.length===0},get conditionNames(){if(t.unmetRunByConditions.length===0)return{context:[],filters:[]};const{keyLabelMap:e}=b.getRoot(t).content.filters,n=t.unmetRunByConditions.filter(a=>a.startsWith("context.")).map(a=>a.split("context.")[0]),r=t.unmetRunByConditions.filter(a=>a.startsWith("filters.")).map(a=>x.get({filters:e},a)).filter(a=>!!a);return{context:n,filters:r}}})).actions(t=>({setName(e){t.name=e},setKey(e){t.key=e},setType(e){t.type=e},setSQL(e){t.sql=e},setRunBy(e){t.run_by.length=0,t.run_by.push(...e)},setReactTo(e){t.react_to.length=0,t.react_to.push(...e)},setPreProcess(e){t.pre_process=e},setPostProcess(e){t.post_process=e}}));function $u(t,e){return new Function(`return ${t}`)()(e,$t)}function Lu(t,e,n){return $u(t,{context:e,filters:n})}function Ou(t,e){try{return new Function(`return ${t.config.processing.pre}`)()(e,$t)}catch(n){return console.error(n),e}}function Pu(t,e){return new Function(`return ${t.config.processing.post}`)()(e,$t)}function Bu(t,e){return t?new Function(`return ${t}`)()(e,$t):e}const us=b.types.compose("QueryModel",zu,b.types.model({state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),data:b.types.optional(b.types.array(b.types.frozen()),[]),error:b.types.frozen()})).views(t=>({get formattedSQL(){const e=b.getRoot(t).content.payloadForSQL;return hr(t.sql,e)},get typedAsSQL(){return[ye.Postgresql,ye.MySQL].includes(t.type)},get typedAsHTTP(){return[ye.HTTP].includes(t.type)},get datasource(){const{key:e,type:n}=t;return b.getRoot(t).datasources.find({type:n,key:e})},get httpConfigString(){const{context:e,filters:n}=b.getRoot(t).content.payloadForSQL,{name:r,pre_process:a}=t.json,o=Lu(a,e,n);return console.groupCollapsed(`Request config for: ${r}`),console.log(o),console.groupEnd(),JSON.stringify(o)}})).views(t=>({get stateMessage(){if(t.state!=="idle")return"";if(!t.runByConditionsMet){const{context:e,filters:n}=t.conditionNames;if(e.length===0&&n.length===0)return"Waiting";const r=[];return e.length>0&&r.push(`context: ${e.join(", ")}`),n.length>0&&r.push(`filter${n.length>1?"s":""}: ${n.join(", ")}`),r.length===2&&r.splice(1,0,"and"),r.unshift("Waiting for"),r.join(" ")}return t.data.length>0?"":"Empty Data"}})).volatile(()=>({controller:new AbortController})).actions(t=>({runSQL:b.flow(function*(){var e;if(t.valid&&((e=t.controller)==null||e.abort(),!!t.runByConditionsMet)){t.controller=new AbortController,t.state="loading";try{const n=b.getRoot(t).content.payloadForSQL;t.data=yield*b.toGenerator(mu({payload:n,title:t.name,query:t.json},t.controller.signal)),t.state="idle",t.error=null}catch(n){if(!pt.isCancel(n)){t.data.length=0;const r=x.get(n,"message","unkown error");t.error=x.get(n,"response.data.detail.message",r),t.state="error"}}}}),runHTTP:b.flow(function*(){var e;if(!(!t.valid||!t.datasource)&&((e=t.controller)==null||e.abort(),!!t.runByConditionsMet)){t.controller=new AbortController,t.state="loading";try{const{type:n,key:r,post_process:a}=t.json;let o=JSON.parse(t.httpConfigString);o=Ou(t.datasource,o);const l=yield*b.toGenerator(yu({type:n,key:r,configString:JSON.stringify(o)},t.controller.signal));let u=Pu(t.datasource,l);u=Bu(a,u),t.data=u,t.state="idle",t.error=null}catch(n){if(console.error(n),!pt.isCancel(n)){t.data.length=0;const r=x.get(n,"message","unkown error");t.error=x.get(n,"response.data.detail.message",r),t.state="error"}}}})})).actions(t=>({fetchData:()=>t.typedAsHTTP?t.runHTTP():t.runSQL(),beforeDestroy(){var e;(e=t.controller)==null||e.abort()}})).actions(t=>({afterCreate(){b.addDisposer(t,ie.reaction(()=>{var e,n;return t.typedAsHTTP?`${t.id}--${t.key}--${t.reQueryKey}--${(e=t.datasource)==null?void 0:e.id}`:`${t.id}--${t.key}--${t.formattedSQL}--${t.pre_process}--${t.post_process}--${(n=t.datasource)==null?void 0:n.id}`},t.fetchData,{fireImmediately:!0,delay:0}))}})),cs=b.types.model("QueriesModel",{current:b.types.optional(b.types.array(us),[])}).views(t=>({get firstID(){if(t.current.length!==0)return t.current[0].id},findByID(e){return t.current.find(n=>n.id===e)},findByIDSet(e){return t.current.filter(n=>e.has(n.id))},get options(){const e=t.current.map(n=>({value:n.id,label:n.name,_type:"query"}));return x.sortBy(e,n=>n.label.toLowerCase())}})).views(t=>({get json(){return t.current.filter(e=>e.id).map(e=>e.json)}})).actions(t=>({replace(e){t.current=b.cast(e)},append(e){t.current.push(e)},remove(e){t.current.splice(e,1)},replaceByIndex(e,n){t.current.splice(e,1,n)},downloadAllData(){const e=t.current.map(({name:n,data:r})=>({id:n,data:r.toJSON()}));ss(e)},downloadDataByQueryIDs(e){const n=new Set(e),r=t.current.filter(a=>n.has(a.id)).map(({name:a,data:o})=>({id:a,data:o.toJSON()}));ss(r)},downloadDataByQueryID(e){const n=t.findByID(e);if(!n){console.log("[downloadDataByQueryID] query not found");return}const{name:r,data:a}=n,o=ls(a);Eu(r,o)},refetchDataByQueryID(e){const n=t.findByID(e);if(!n){console.error(new Error(`[downloadDataByQueryID] query by ID[${e}] not found`));return}return n.fetchData()},removeQuery(e){const n=t.current.find(r=>r.id===e);n&&(b.detach(n),t.current.remove(n))}})),ds=b.types.model("SQLSnippetModel",{key:b.types.string,value:b.types.string}).views(t=>({get json(){const{key:e,value:n}=t;return{key:e,value:n}},isADuplicatedKey(e){return!e||e===t.key?!1:!!b.getParent(t,2).findByKey(e)}})).actions(t=>({setKey(e){t.key=e},setValue(e){t.value=e}})),ps=b.types.model("SQLSnippetsModel",{current:b.types.optional(b.types.array(ds),[])}).views(t=>({get json(){return t.current.map(e=>e.json)},get options(){const e=t.current.map(n=>({label:n.key,value:n.key,_type:"sql_snippet"}));return x.sortBy(e,n=>n.label.toLowerCase())},get record(){return t.current.reduce((e,n)=>(e[n.key]=n.value,e),{})},get firstKey(){if(t.current.length!==0)return t.current[0].key},findByKey(e){return t.current.find(n=>n.key===e)}})).actions(t=>({replace(e){t.current=b.cast(e)},append(e){t.current.push(e)},remove(e){t.current.splice(e,1)},removeByKey(e){const n=t.current.findIndex(r=>r.key===e);n>=0&&t.current.splice(n,1)},replaceByIndex(e,n){t.current.splice(e,1,n)}})),hs=b.types.model("ContextModel",{current:b.types.optional(b.types.frozen(),{})}).views(t=>({get keys(){return Object.keys(t.current)},get entries(){return Object.entries(t.current)}})).actions(t=>({replace(e){t.current=e},get(e){return t.current[e]},set(e,n){t.current[e]=n}})),Vu=b.types.model({data:b.types.optional(b.types.frozen(),[]),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(t=>({get loading(){return t.state==="loading"},get empty(){return t.data.length===0},get sql(){const e=b.getParent(t,1),{type:n,table_name:r,table_schema:a}=e;if(n===ye.MySQL)return`
56
- SELECT ordinal_position, column_key, column_name, column_type, is_nullable, column_default, column_comment
57
- FROM information_schema.columns
58
- WHERE table_name = '${r}' AND table_schema = '${a}'
59
- `;if(n===ye.Postgresql){const o=`'${a}.${r}'::regclass`;return`
60
- SELECT
61
- ordinal_position,
62
- UPPER(pc.contype) AS column_key,
63
- pg_get_constraintdef(pc.oid) AS column_key_text,
64
- column_name,
65
- format_type(atttypid, atttypmod) AS column_type,
66
- is_nullable,
67
- column_default,
68
- pg_catalog.col_description(${o}, ordinal_position) AS column_comment
69
- FROM
70
- information_schema.columns
71
- JOIN pg_attribute pa ON pa.attrelid = ${o}
72
- AND attname = column_name
73
- LEFT JOIN pg_constraint pc ON pc.conrelid = ${o} AND ordinal_position = any(pc.conkey)
74
- WHERE
75
- table_name = '${r}' AND table_schema = '${a}';
76
- `}return""}})),Nu=b.types.model({data:b.types.optional(b.types.frozen(),[]),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(t=>({get loading(){return t.state==="loading"},get empty(){return t.data.length===0},get sql(){const e=b.getParent(t,1),{type:n,table_name:r,table_schema:a}=e;return n===ye.MySQL?`
77
- SELECT
78
- sub_part AS index_length,
79
- index_name AS index_name,
80
- index_type AS index_algorithm,
81
- CASE non_unique WHEN 0 THEN 'TRUE' ELSE 'FALSE' END AS is_unique,
82
- column_name AS column_name
83
- FROM
84
- information_schema.statistics
85
- WHERE
86
- table_name = '${r}' AND table_schema = '${a}'
87
- ORDER BY
88
- seq_in_index ASC;
89
- `:n===ye.Postgresql?`
90
- SELECT
91
- ix.relname AS index_name,
92
- upper(am.amname) AS index_algorithm,
93
- indisunique AS is_unique,
94
- pg_get_indexdef(indexrelid) AS index_definition,
95
- CASE WHEN position(' WHERE ' IN pg_get_indexdef(indexrelid)) > 0 THEN
96
- regexp_replace(pg_get_indexdef(indexrelid), '.+WHERE ', '')
97
- WHEN position(' WITH ' IN pg_get_indexdef(indexrelid)) > 0 THEN
98
- regexp_replace(pg_get_indexdef(indexrelid), '.+WITH ', '')
99
- ELSE
100
- ''
101
- END AS condition,
102
- pg_catalog.obj_description(i.indexrelid, 'pg_class') AS comment
103
- FROM
104
- pg_index i
105
- JOIN pg_class t ON t.oid = i.indrelid
106
- JOIN pg_class ix ON ix.oid = i.indexrelid
107
- JOIN pg_namespace n ON t.relnamespace = n.oid
108
- JOIN pg_am AS am ON ix.relam = am.oid
109
- WHERE
110
- t.relname = '${r}' AND n.nspname = '${a}';
111
- `:""}})),qu=b.types.model({data:b.types.optional(b.types.frozen(),{}),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(t=>({get loading(){return t.state==="loading"},get empty(){return Object.keys(t.data).length===0},get sql(){const e=b.getParent(t,1).type;return e===ye.MySQL||e===ye.Postgresql?"SELECT table_schema, table_name, table_type FROM information_schema.tables ORDER BY table_schema, table_name":""}})),Fu=b.types.model({page:b.types.optional(b.types.number,1),limit:b.types.optional(b.types.number,20),data:b.types.optional(b.types.frozen(),[]),total:b.types.optional(b.types.number,0),state:b.types.optional(b.types.enumeration(["idle","loading","error"]),"idle"),error:b.types.frozen()}).views(t=>({get keywords(){return b.getParent(t,1)},get keywordString(){const{table_name:e,table_schema:n}=b.getParent(t,1);return`${n}||${e}`}})).views(t=>({get loading(){return t.state==="loading"},get empty(){return t.data.length===0},get maxPage(){return Math.ceil(t.total/t.limit)},get sql(){const e=b.getParent(t,1),{table_name:n,table_schema:r}=e;return`
112
- SELECT *
113
- FROM ${r}.${n}
114
- LIMIT ${t.limit} OFFSET ${(t.page-1)*t.limit}
115
- `},get countSql(){const{table_name:e,table_schema:n}=t.keywords;return`
116
- SELECT count(*) AS total
117
- FROM ${n}.${e}
118
- `}})).actions(t=>({setPage(e){t.page=e},resetPage(){t.page=1},setLimit(e){t.limit=e}})).actions(t=>({afterCreate(){b.addDisposer(t,ie.reaction(()=>t.keywordString,t.resetPage,{fireImmediately:!1,delay:0})),b.addDisposer(t,ie.reaction(()=>t.limit,t.resetPage,{fireImmediately:!1,delay:0}))}})),Gu=b.types.model("DataSourceModel",{id:b.types.string,type:b.types.enumeration("DataSourceType",[ye.HTTP,ye.MySQL,ye.Postgresql]),key:b.types.string,config:b.types.frozen(),tables:b.types.optional(qu,{}),columns:b.types.optional(Vu,{}),tableData:b.types.optional(Fu,{}),indexes:b.types.optional(Nu,{}),table_schema:b.types.optional(b.types.string,""),table_name:b.types.optional(b.types.string,"")}).volatile(()=>({controllers:{tables:new AbortController,columns:new AbortController,indexes:new AbortController,tableData:new AbortController}})).actions(t=>({setKeywords(e,n){t.table_schema=e,t.table_name=n}})).actions(t=>({initKeywords(){if(t.tables.empty)return;const e=Object.keys(t.tables.data)[0],n=t.tables.data[e][0].table_name;t.setKeywords(e,n)}})).actions(t=>{const e=b.flow(function*(){var n;(n=t.controllers.tables)==null||n.abort(),t.controllers.tables=new AbortController,t.tables.state="loading";try{const r=yield*b.toGenerator(qe.query(t.controllers.tables.signal)({type:t.type,key:t.key,query:t.tables.sql},{}));t.tables.data=x.groupBy(r,"table_schema"),t.tables.state="idle",t.tables.error=null,t.initKeywords()}catch(r){if(!pt.isCancel(r)){t.tables.data={};const a=x.get(r,"message","unkown error");t.tables.error=x.get(r,"response.data.detail.message",a),t.tables.state="error"}}});return{loadTables:e,loadTablesIfEmpty(){t.tables.empty&&e()},loadColumns:b.flow(function*(){var n;(n=t.controllers.columns)==null||n.abort(),t.controllers.columns=new AbortController,t.columns.state="loading";try{t.columns.data=yield*b.toGenerator(qe.query(t.controllers.columns.signal)({type:t.type,key:t.key,query:t.columns.sql},{})),t.columns.state="idle",t.columns.error=null}catch(r){if(pt.isCancel(r))t.columns.state="idle",t.columns.error=null;else{t.columns.data=[];const a=x.get(r,"message","unkown error");t.columns.error=x.get(r,"response.data.detail.message",a),t.columns.state="error"}}}),loadIndexes:b.flow(function*(){var n;(n=t.controllers.indexes)==null||n.abort(),t.controllers.indexes=new AbortController,t.indexes.state="loading";try{t.indexes.data=yield*b.toGenerator(qe.query(t.controllers.indexes.signal)({type:t.type,key:t.key,query:t.indexes.sql},{})),t.indexes.state="idle",t.indexes.error=null}catch(r){if(pt.isCancel(r))t.indexes.state="idle",t.indexes.error=null;else{t.indexes.data=[];const a=x.get(r,"message","unkown error");t.indexes.error=x.get(r,"response.data.detail.message",a),t.indexes.state="error"}}}),loadTableData:b.flow(function*(){var r;(r=t.controllers.tableData)==null||r.abort(),t.controllers.tableData=new AbortController;const n=t.tableData;n.state="loading";try{n.data=yield*b.toGenerator(qe.query(t.controllers.tableData.signal)({type:t.type,key:t.key,query:n.sql},{}));const[{total:a}]=yield*b.toGenerator(qe.query(t.controllers.tableData.signal)({type:t.type,key:t.key,query:n.countSql},{}));n.total=Number(a),n.state="idle",n.error=null}catch(a){if(pt.isCancel(a))n.state="idle",n.error=null;else{n.data=[];const o=x.get(a,"message","unkown error");n.error=x.get(a,"response.data.detail.message",o),n.state="error"}}})}}).actions(t=>({afterCreate(){b.addDisposer(t,ie.reaction(()=>t.columns.sql,t.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(t=>({afterCreate(){b.addDisposer(t,ie.reaction(()=>t.indexes.sql,t.loadIndexes,{fireImmediately:!1,delay:500})),b.addDisposer(t,ie.reaction(()=>t.tableData.sql,t.loadTableData,{fireImmediately:!1,delay:0}))}})),Wu=b.types.model("DataSourcesModel",{list:b.types.optional(b.types.array(Gu),[])}).views(t=>({find({type:e,key:n}){return t.list.find(r=>r.key===n&&r.type===e)},get options(){return t.list.map(e=>({value:e.key,label:e.key}))}})).actions(t=>({replace(e){t.list.length=0,t.list.push(...e)}}));function bn(t){return{label:t,value:t,_type:"ACTION",_action_type:t,Icon:null,children:null}}function ju(t){switch(t._type){case"GROUP":case"ACTION":return null;case"query_variables":return["_QUERY_VARS_"];case"mock_context":return["_MOCK_CONTEXT_"];case"filter":return["_FILTERS_",t.value];case"sql_snippet":return["_SQL_SNIPPETS_",t.value];case"query":return["_QUERIES_",t.value];case"view":return["_VIEWS_",t.value];case"panel":return t.parentID?["_VIEWS_",t.parentID,"_PANELS_",t.value]:(console.error("[getPathFromOption] parentID is required"),null)}}const Ru=b.types.model("EditorModel",{path:b.types.optional(b.types.frozen(),[]),settings_open:b.types.optional(b.types.boolean,!1)}).views(t=>({get navOptions(){const{content:e}=b.getRoot(t),{filters:n,views:r,sqlSnippets:a,queries:o}=e;return[{label:"Query Variables",value:"_QUERY_VARS_",_type:"query_variables",Icon:L.IconVariable},{label:"Mock Context",value:"_MOCK_CONTEXT_",Icon:L.IconCodeDots,_type:"mock_context"},{label:"Filters",value:"_FILTERS_",Icon:L.IconFilter,children:[...n.options,bn("_Add_A_Filter_")],_type:"GROUP"},{label:"SQL Snippets",value:"_SQL_SNIPPETS_",Icon:L.IconCopy,children:[...a.options,bn("_Add_A_SQL_SNIPPET_")],_type:"GROUP"},{label:"Queries",value:"_QUERIES_",Icon:L.IconDatabase,children:[...o.options,bn("_Add_A_QUERY_")],_type:"GROUP"},{label:"Views",value:"_VIEWS_",Icon:L.IconBoxMultiple,children:[...r.editorOptions,bn("_Add_A_VIEW_")],_type:"GROUP"}]},isOptionActive(e,n){return e.length===0?!1:e[e.length-1]===n.value},isOptionOpened(e){const{path:n}=t;return n.length===0||!e.children||e.children.length===0?!1:n.includes(e.value)}})).actions(t=>({setPath(e){t.path=e},setSettingsOpen(e){t.settings_open=e}})).actions(t=>({open(e){t.setPath(e),t.setSettingsOpen(!0)},close(){t.setSettingsOpen(!1)},navigate(e){const n=ju(e);n&&t.setPath(n)}})),Yu=b.types.model("MockContextModel",{current:b.types.optional(b.types.frozen(),{})}).views(t=>({get keys(){return Object.keys(t.current)},get entries(){return Object.entries(t.current)}})).actions(t=>({replace(e){t.current=e},get(e){return t.current[e]},set(e,n){t.current[e]=n}})),Qu=b.types.model("VariableModel",{name:b.types.string,size:b.types.string,weight:b.types.string,color:b.types.union(b.types.model({type:b.types.literal("static"),staticColor:b.types.string}),b.types.model({type:b.types.literal("continuous"),valueRange:b.types.array(b.types.number),colorRange:b.types.array(b.types.string)}),b.types.model({type:b.types.literal("piecewise")})),formatter:b.types.model({output:b.types.enumeration("Output",["number","percent"]),average:b.types.optional(b.types.boolean,!1),mantissa:b.types.number,trimMantissa:b.types.optional(b.types.boolean,!1)}),data_field:b.types.string,aggregation:b.types.union(b.types.model({type:b.types.enumeration(["none","sum","mean","median","min","max","CV","std"]),config:b.types.frozen()}),b.types.model({type:b.types.literal("quantile"),config:b.types.model({p:b.types.number})}))}).views(t=>({get json(){const{name:e,size:n,weight:r,color:a,formatter:o,data_field:l,aggregation:u}=t;return x.cloneDeep({name:e,size:n,color:a,weight:r,formatter:o,data_field:l,aggregation:u})}}));class Ku{constructor(e){N(this,"origin");N(this,"copy");this.origin=e,this.copy=b.clone(e),ie.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!x.isEqual(b.getSnapshot(this.origin),b.getSnapshot(this.copy))}commit(){b.applySnapshot(this.origin,b.getSnapshot(this.copy))}update(e){b.applySnapshot(this.copy,e)}}const Uu=t=>new Ku(t);class Xu{constructor(){N(this,"migrations",[])}version(e,n){return this.migrations.push({version:e,handler:n}),this}run(e,n,r){var l;if(e.from===e.to)return n;if(e.from>e.to)throw new Error(`Can not downgrade from version '${e.from}' to (${e.to})`);const a=this.migrations.filter(u=>u.version>e.from&&u.version<=e.to),o=x.orderBy(a,"version","asc");if(((l=x.last(o))==null?void 0:l.version)!==e.to)throw new Error(`Migration to version ${e.to} not found`);return o.reduce((u,c)=>c.handler(u,r),n)}}class ve extends Xu{constructor(){super(),this.configVersions()}version(e,n){return super.version(e,(r,a)=>({version:e,...n(r,a)}))}async migrate({configData:e,panelModel:n}){const r=await e.getItem(null),a=x.get(r,"version",0),o=this.run({from:a,to:this.VERSION},r,{panelModel:n});await e.setItem(null,o)}async needMigration({configData:e}){const n=await e.getItem(null);return x.get(n,"version",0)<this.VERSION}}var Je=(t=>(t.string="string",t.number="number",t.eloc="eloc",t.percentage="percentage",t.custom="custom",t))(Je||{});const fs=["function text({ value }) {"," // your code goes here"," return value","}"].join(`
119
- `),gs={columns:[],fontSize:"14px",highlightOnHover:!0,horizontalSpacing:"14px",id_field:"",striped:!0,use_raw_columns:!0,verticalSpacing:"14px"};class Lt{constructor(e,n){this.root=e,this.path=n}async deleteItem(e){e===null&&await this.root.deleteItem(this.path);const n=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,x.omit(n,e))}async getItem(e){const n=await this.root.getItem(this.path);return e===null?n:x.get(n,e)}async setItem(e,n){if(e===null)await this.root.setItem(this.path,n);else{const r=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,{...r,[e]:n})}return await this.getItem(e)}watchItem(e,n,r){return e===null?this.root.watchItem(this.path,(a,o)=>{n(a,o)},r):this.root.watchItem(this.path,(a,o)=>{const l=x.get(a,e),u=x.get(o,e);l!==u&&n(l,u)},r)}}class vr{constructor(e,n,r){N(this,"attachmentStorage");this.instance=e,this.attachmentKey=n,this.constructInstance=r,this.attachmentStorage=new Lt(e.instanceData,n)}async getInstance(e){if(await this.attachmentStorage.getItem(e))return this.constructInstance(new Lt(this.attachmentStorage,e))}async create(e,n){return await this.attachmentStorage.setItem(e,n),this.constructInstance(new Lt(this.attachmentStorage,e))}async remove(e){await this.attachmentStorage.deleteItem(e)}async list(){const e=await this.attachmentStorage.getItem(null);return Promise.all(x.values(e).map(n=>this.constructInstance(new Lt(this.attachmentStorage,n.id))))}}class ms{constructor(e){N(this,"rootRef");this.rootRef=ie.observable({current:e})}async deleteItem(e){ie.runInAction(()=>{x.unset(this.rootRef.current,[e])})}getItem(e){const n=this.getValueFromRoot(e);return Promise.resolve(n)}getValueFromRoot(e){return e===null?ie.toJS(this.rootRef.current):x.get(this.rootRef.current,[e])}setItem(e,n){if(e===null)if(x.isObject(n))ie.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else ie.runInAction(()=>{x.set(this.rootRef.current,[e],n)});return Promise.resolve(this.getItem(e))}watchItem(e,n,r){return ie.reaction(()=>this.getValueFromRoot(e),(a,o)=>{n(a,o)},{requiresObservable:!0,fireImmediately:x.get(r,"fireImmediately",!1)})}}class Ju{constructor(){N(this,"channels",new Map);N(this,"globalChannel",new _a)}getChannel(e){const n=this.channels.get(e);if(n)return n;const r=new _a;return this.channels.set(e,r),r}}class Zu{constructor(e){N(this,"instances",new Map);this.pluginManager=e}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(e=>e.manifest.viz)}resolveComponent(e){return this.pluginManager.factory.viz(e)}getOrCreateInstance(e){const n=this.instances.get(e.id);if(n)return n;const r={id:e.id,name:e.viz.type,type:e.viz.type,messageChannels:new Ju,instanceData:new ms(e.viz.conf)};return this.instances.set(e.id,r),r}}function ys(t,e,n,r){return{vizManager:n,locale:"zh",msgChannels:t.messageChannels,instanceData:t.instanceData,pluginData:new ms({}),colorPalette:{getColor(){return()=>""}},data:e,variables:r}}const Hu=t=>{const{panel:e,vizManager:n,data:r,variables:a}=t,o=n.resolveComponent(e.viz.type),l=n.getOrCreateInstance(e),u={...ys(l,r,n,a),viewport:{width:e.layout.w,height:e.layout.h}},c=o.viewRender;return i(c,{context:u,instance:l,...x.omit(t,["panel","vizManager","data"])})},ec=t=>{const{vizManager:e,panel:n,panelInfoEditor:r,data:a,variables:o}=t,l=e.resolveComponent(n.viz.type),u=e.getOrCreateInstance(n),c={...ys(u,a,e,o),panelInfoEditor:r},d=l.configRender;return i(d,{context:c,instance:u,...x.omit(t,["panel","vizManager","data","panelInfoEditor"])})},bs=(t,e)=>{const n=st.bezier(t),r=st.bezier(e);return function(a){return a<50?n(a*2/100).hex():r((a-50)*2/100).hex()}},vn=t=>{const e=st.bezier(t);return function(n){return e(n/100).hex()}},tc={type:"interpolation",displayName:"Red / Green",getColor:bs(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},nc={type:"interpolation",displayName:"Yellow / Blue",getColor:bs(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},rc={type:"interpolation",displayName:"Red",getColor:vn(["#fff7f1","darkred"]),name:"red",category:"sequential"},ic={type:"interpolation",displayName:"Green",getColor:vn(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},ac={type:"interpolation",displayName:"Blue",getColor:vn(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},sc={type:"interpolation",displayName:"Orange",getColor:vn(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class oc{constructor(e){N(this,"symbol");this.symbol=Symbol(e)}}function ot(t){return new oc(t)}class xr{constructor(){N(this,"parent");N(this,"factoryRegistry",new Map);N(this,"instanceRegistry",new Map)}createScoped(){const e=new xr;return e.parent=this,e}getRequired(e){return this.get(e)}get(e){if(this.instanceRegistry.has(e.symbol))return this.instanceRegistry.get(e.symbol);const n=this.factoryRegistry.get(e.symbol);if(n){const r=n(this);return this.instanceRegistry.set(e.symbol,r),r}if(this.parent)return this.parent.get(e)}provideFactory(e,n){return this.factoryRegistry.has(e.symbol)?console.warn(`Token ${e.symbol.toString()} is already registered`):this.factoryRegistry.set(e.symbol,n),this}provideValue(e,n){return this.factoryRegistry.has(e.symbol)?console.warn(`Token ${e.symbol.toString()} is already registered`):this.factoryRegistry.set(e.symbol,()=>n),this}dispose(){this.instanceRegistry.forEach(e=>{const n=x.get(e,"dispose");x.isFunction(n)&&n.bind(e)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const vs="10.9.9",lc=Object.freeze(Object.defineProperty({__proto__:null,version:vs},Symbol.toStringTag,{value:"Module"}));class uc{constructor(e){N(this,"staticColors",new Map);N(this,"interpolations",new Map);e.installedPlugins.forEach(n=>{n.manifest.color.forEach(r=>{this.register(r)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(e){const n=this.encodeColor(e);e.type==="single"?(this.staticColors.has(n)&&console.warn(`the color '${e.name}' has been registered under '${e.category}', previous registered value will be overridden`),this.staticColors.set(n,e)):e.type==="interpolation"&&(this.interpolations.has(n)&&console.warn(`the interpolation '${e.name}' has been registered under '${e.category}', previous registered value will be overridden`,`the interpolation '${e.name}' has been registered under '${e.category}', previous registered value will be overridden`),this.interpolations.set(n,e))}decodeStaticColor(e){return this.staticColors.get(e)}encodeColor(e){return`\${${e.category}}.{${e.name}}`}decodeInterpolation(e){return this.interpolations.get(e)}getColorInterpolations(){return Array.from(this.interpolations.values())}}class cc{constructor(){N(this,"plugins",new Map);N(this,"vizComponents",new Map);N(this,"factory",{viz:e=>{const n=this.vizComponents.get(e);if(n)return n;throw new Error(`Viz Component (${e}) not found`)}})}install(e){if(this.plugins.has(e.id))throw new Error(`Plugin (${e.id}) has been installed before`);this.plugins.set(e.id,e);for(const n of e.manifest.viz){if(this.vizComponents.has(n.name))throw new Error(`Viz Component (${n.name}) has been installed before`);this.vizComponents.set(n.name,n)}}get installedPlugins(){return Array.from(this.plugins.values())}}const W=(t,e)=>{const[n,{setFalse:r}]=X.useBoolean(!0),[a,o]=y.useState();y.useEffect(()=>(t.getItem(e).then(u=>{o(u),r()}),t.watchItem(e,u=>{o(u)})));const l=y.useCallback(async u=>{await t.setItem(e,u),o(u)},[t,e]);return{loading:n,value:a,set:l}},wr={x_axis_data_key:"",y_axis_data_key:"",z_axis_data_key:"",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}};function q(t){const[e,n]=t.split(".");return{queryID:e,columnKey:n}}function lt(t,e){var a;const{queryID:n,columnKey:r}=q(e);return n?r?((a=t[n])==null?void 0:a.map(o=>o[r]))??[]:t[n]:[]}function xn(t,e){const{queryID:n}=q(e);return n?t[n]:[]}function dc(t){return Object.values(t)[0]}function wn(t,e){const{queryID:n,columnKey:r}=q(e);return t[r]}le.use([G.GridComponent,G.VisualMapComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function pc({context:t}){const{value:e}=W(t.instanceData,"config"),n=t.data,{width:r,height:a}=t.viewport,{x_axis_data_key:o,y_axis_data_key:l,z_axis_data_key:u,xAxis3D:c,yAxis3D:d,zAxis3D:f}=x.defaults({},e,wr),h=y.useMemo(()=>xn(n,o),[n,o]),{x:g,y:m,z:w}=y.useMemo(()=>({x:q(o),y:q(l),z:q(u)}),[o,l,u]),{min:C,max:_}=y.useMemo(()=>{const I=x.minBy(h,B=>B[w.columnKey]),O=x.maxBy(h,B=>B[w.columnKey]);return{min:x.get(I,w.columnKey),max:x.get(O,w.columnKey)}},[h,w]),T={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:C,max:_,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:c,yAxis3D:d,zAxis3D:f,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:h.map(I=>[I[g.columnKey],I[m.columnKey],I[w.columnKey]])}]};return e?i(Ne,{echarts:le,option:T,style:{width:r,height:a},notMerge:!0,theme:"merico-light"}):null}const xs=y.createContext({panel:null,data:{},loading:!1,errors:[]}),Cr=xs.Provider;function ze(){const t=y.useContext(xs);if(!t.panel)throw new Error("Please use PanelContextProvider");return t}const hc={fullScreenPanelID:"",setFullScreenPanelID:x.noop},Sr=y.createContext(hc);function ws(){const t=y.useContext(Sr);if(!t)throw new Error("Please use FullScreenPanelContext.Provider");return t}const j=k.observer(y.forwardRef(({label:t,required:e,value:n,onChange:r,clearable:a=!1,sx:o,...l},u)=>{const{panel:c}=ze(),d=y.useMemo(()=>{const f=[...c.dataFieldOptions];return a&&f.unshift({label:"unset",value:"",group:""}),f},[c.dataFieldOptions]);return i(s.Select,{ref:u,label:t,data:d,value:n,onChange:r,required:e,sx:o,...l})}));function fc({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=x.defaults({},e,wr),{control:a,handleSubmit:o,reset:l}=v.useForm({defaultValues:r});return y.useEffect(()=>{l(r)},[e]),e?i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[i(s.Text,{children:"X Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"x_axis_data_key",control:a,render:({field:u})=>i(j,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"xAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Text,{mt:"lg",children:"Y Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"y_axis_data_key",control:a,render:({field:u})=>i(j,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"yAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Text,{mt:"lg",children:"Z Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"z_axis_data_key",control:a,render:({field:u})=>i(j,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"zAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:p(s.Button,{color:"blue",type:"submit",children:[i(D.DeviceFloppy,{size:20}),i(s.Text,{ml:"md",children:"Save"})]})})]})}):null}function gc(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis_data_key:a,y_axis_data_key:o,z_axis_data_key:l,...u}=t;return{...u,x_axis_data_key:r(a),y_axis_data_key:r(o),z_axis_data_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class mc extends ve{constructor(){super(...arguments);N(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:gc(a,r)}})}}const yc={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new mc,name:"bar-3d",viewRender:pc,configRender:fc,createConfig(){return{version:2,config:x.cloneDeep(wr)}}};class Fe extends y.Component{constructor(e){super(e),this.state={error:null}}componentDidCatch(e){this.setState({error:e})}render(){var e;if(this.state.error){const n=()=>{this.setState({error:null})};return p(s.Box,{children:[i(s.Text,{size:"xs",children:(e=this.state.error)==null?void 0:e.message}),i(s.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:n,children:"Retry"})]})}return this.props.children}}const $e={mantissa:0,output:"number",trimMantissa:!1,average:!1};function bc({value:t,onChange:e},n){const r=u=>{e({...t,output:u})},a=u=>{const c=u===0?!1:t.trimMantissa;e({...t,mantissa:u,trimMantissa:c})},o=u=>{e({...t,trimMantissa:u.currentTarget.checked})},l=u=>{e({...t,average:u.currentTarget.checked})};return p(s.Stack,{ref:n,children:[p(s.Group,{grow:!0,children:[i(s.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:t.output,onChange:r,sx:{flexGrow:1}}),i(s.Switch,{label:p(s.Stack,{spacing:0,children:[i(s.Text,{children:"Average"}),i(s.Text,{size:12,color:"gray",children:"like 1.234k, 1.234m"})]}),checked:t.average,onChange:l,disabled:t.output!=="number",sx:{flexGrow:1},styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}}})]}),p(s.Group,{grow:!0,children:[i(s.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:t.mantissa,onChange:a}),i(s.Switch,{label:"Trim mantissa",checked:t.trimMantissa,onChange:o,disabled:t.mantissa===0,styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"}}})]}),p(s.Stack,{spacing:0,children:[i(s.Text,{weight:"bold",children:"Preview"}),i(Fe,{children:p(s.Group,{position:"apart",children:[p(s.Text,{size:12,color:"gray",children:["123456789 ",i(D.ArrowRight,{size:9})," ",ee(123456789).format(t)]}),p(s.Text,{size:12,color:"gray",children:["1234 ",i(D.ArrowRight,{size:9})," ",ee(1234).format(t)]}),p(s.Text,{size:12,color:"gray",children:["0.1234 ",i(D.ArrowRight,{size:9})," ",ee(.1234).format(t)]})]})})]})]})}const Re=y.forwardRef(bc),nt={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
120
- `)},Cs={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:xc,configRender:vc,payload:[{name:"type",description:"Always 'click'",valueType:"string"},{name:"seriesType",description:"'boxplot'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"Record of 'name', 'min', 'q1', 'median', 'q3', 'max'",valueType:"object"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function vc(t){return i(V,{})}function xc(t){return i(s.Text,{children:"Click chart's series"})}const wc=[{label:"Truncate",value:"truncate"},{label:"Break Line",value:"break"},{label:"Break Word",value:"breakAll"}],Cn=y.forwardRef(({sectionTitle:t,value:e,onChange:n},r)=>{const a=o=>l=>{const u=x.cloneDeep(e);x.set(u,o,l),n(u)};return p(s.Stack,{spacing:0,children:[t&&i(s.Divider,{mb:-5,mt:5,variant:"dotted",label:t,labelPosition:"right",labelProps:{color:"dimmed"}}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.NumberInput,{label:"Max Width",hideControls:!0,value:e.width,onChange:a("width")}),i(s.Select,{label:"Overflow",data:wc,value:e.overflow,onChange:a("overflow")}),i(s.TextInput,{label:"Ellipsis",value:e.ellipsis,disabled:!0})]})]})}),gt=y.forwardRef(({value:t,onChange:e},n)=>{const r=o=>{e({...t,on_axis:o})},a=o=>{e({...t,in_tooltip:o})};return p(s.Stack,{ref:n,spacing:0,children:[i(Cn,{sectionTitle:"Overflow on Axis",value:t.on_axis,onChange:r}),i(Cn,{sectionTitle:"Overflow in Tooltip",value:t.in_tooltip,onChange:a})]})}),Ze={on_axis:{width:80,overflow:"truncate",ellipsis:"..."},in_tooltip:{width:200,overflow:"break",ellipsis:"..."}};function mt({overflow:t,width:e}){const n={truncate:"initial",break:"break-all",breakAll:"break-word"}[t],r=t==="truncate"?"nowrap":"initial",a={truncate:"ellipsis",break:"clip",breakAll:"clip"}[t];return`
121
- max-width: ${e}px;
54
+ `;function fr(e,t){const n=Object.keys(t),r=Object.values(t);try{return new Function(...n,`return \`${e}\`;`)(...r)}catch(a){throw n.length===0&&e.includes("$")?new Error("[formatSQL] insufficient payload"):a}}function gr(e,t){try{return fr(e,t)}catch(n){return console.error(n),n.message}}function Au({sql:e,pre_process:t}){if(!t.trim())return e;try{return new Function(`return ${t}`)()({sql:e},Lt)}catch(n){return console.error(n),e}}function zu(e,t){if(!e.trim())return t;try{return new Function(`return ${e}`)()(t,Lt)}catch(n){return console.error(n),t}}function $u(e){e=e||{};const t=Object.keys(e).sort(),n=[];for(let r=0;r<t.length;r++){const a=t[r];if(a!="authentication"&&e[a])n.push(t[r]+"="+(typeof e[a]=="object"?JSON.stringify(e[a]):e[a]));else{const o=Object.keys(e[a]).sort();for(let l=0;l<o.length;l++){const u=o[l];u!="sign"&&e[a][u]&&n.push(o[l]+"="+(typeof e[a][u]=="object"?JSON.stringify(e[a][u]):e[a][u]))}}}return n.sort().join("&")}function Lu(e,t){let n=$u(e);return n+="&key="+t,Ta.MD5(n).toString().toUpperCase()}const qe={baseURL:"http://localhost:31200",app_id:"",app_secret:"",getAuthentication(e){if(!this.app_id||!this.app_secret)return;const t=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:t,sign:Lu({app_id:this.app_id,nonce_str:t,...e},this.app_secret)}},getRequest(e,t){return(n,r,a={})=>{const o=window.localStorage.getItem("token"),l={"X-Requested-With":"XMLHttpRequest","Content-Type":a.string?"application/x-www-form-urlencoded":"application/json",authorization:o?`bearer ${o}`:"",...a.headers},u={baseURL:this.baseURL,method:e,url:n,params:e==="GET"?r:a.params,headers:l,signal:t};return["POST","PUT"].includes(e)&&(u.data=a.string?JSON.stringify(r):r,u.data.authentication=this.getAuthentication(u.data)),ht(u).then(c=>c.data).catch(c=>Promise.reject(c))}},makeQueryENV:null,query(e){return async(t,n={})=>{var r;return t.env||(t.env=((r=this.makeQueryENV)==null?void 0:r.call(this))??{error:"failed to run makeQueryENV"}),this.getRequest("POST",e)("/query",t,n)}}};function Ya(e){qe.baseURL!==e.apiBaseURL&&(qe.baseURL=e.apiBaseURL),e.app_id&&(qe.app_id=e.app_id),e.app_secret&&(qe.app_secret=e.app_secret),e.makeQueryENV&&(qe.makeQueryENV=e.makeQueryENV)}async function Ou({query:e,payload:t},n){if(!e.sql)return[];const{type:r,key:a,sql:o,pre_process:l,post_process:u}=e,c=fr(o,t),d=Au({sql:c,pre_process:l});let f=await qe.query(n)({type:r,key:a,query:d},{});return f=zu(u,f),f}async function Pu({type:e,key:t,configString:n},r){return await qe.query(r)({type:e,key:t,query:n},{})}async function mr(){try{return(await qe.getRequest("POST")("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}})).data}catch(e){return console.error(e),[]}}async function Qa(){try{return(await qe.getRequest("POST")("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}})).data}catch(e){return console.error(e),[]}}class Ka{constructor(t){N(this,"rootRef");this.rootRef=re.observable({current:t})}async deleteItem(t){re.runInAction(()=>{x.unset(this.rootRef.current,[t])})}getItem(t){const n=this.getValueFromRoot(t);return Promise.resolve(n)}getValueFromRoot(t){return t===null?re.toJS(this.rootRef.current):x.get(this.rootRef.current,[t])}setItem(t,n){if(t===null)if(x.isObject(n))re.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else re.runInAction(()=>{x.set(this.rootRef.current,[t],n)});return Promise.resolve(this.getItem(t))}watchItem(t,n,r){return re.reaction(()=>this.getValueFromRoot(t),(a,o)=>{n(a,o)},{requiresObservable:!0,fireImmediately:x.get(r,"fireImmediately",!1)})}}class Bu{constructor(){N(this,"channels",new Map);N(this,"globalChannel",new Da)}getChannel(t){const n=this.channels.get(t);if(n)return n;const r=new Da;return this.channels.set(t,r),r}}class Vu{constructor(t){N(this,"instances",new Map);this.pluginManager=t}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(t=>t.manifest.viz)}resolveComponent(t){return this.pluginManager.factory.viz(t)}getOrCreateInstance(t){const n=this.instances.get(t.id);if(n)return n;const r={id:t.id,name:t.viz.type,type:t.viz.type,messageChannels:new Bu,instanceData:new Ka(t.viz.conf)};return this.instances.set(t.id,r),r}}function Ua(e,t,n,r){return{vizManager:n,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new Ka({}),colorPalette:{getColor(){return()=>""}},data:t,variables:r}}const Nu=e=>{const{panel:t,vizManager:n,data:r,variables:a}=e,o=n.resolveComponent(t.viz.type),l=n.getOrCreateInstance(t),u={...Ua(l,r,n,a),viewport:{width:t.layout.w,height:t.layout.h}},c=o.viewRender;return i(c,{context:u,instance:l,...x.omit(e,["panel","vizManager","data"])})},qu=e=>{const{vizManager:t,panel:n,panelInfoEditor:r,data:a,variables:o}=e,l=t.resolveComponent(n.viz.type),u=t.getOrCreateInstance(n),c={...Ua(u,a,t,o),panelInfoEditor:r},d=l.configRender;return i(d,{context:c,instance:u,...x.omit(e,["panel","vizManager","data","panelInfoEditor"])})},Xa=(e,t)=>{const n=ot.bezier(e),r=ot.bezier(t);return function(a){return a<50?n(a*2/100).hex():r((a-50)*2/100).hex()}},bn=e=>{const t=ot.bezier(e);return function(n){return t(n/100).hex()}},Fu={type:"interpolation",displayName:"Red / Green",getColor:Xa(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},Gu={type:"interpolation",displayName:"Yellow / Blue",getColor:Xa(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},Wu={type:"interpolation",displayName:"Red",getColor:bn(["#fff7f1","darkred"]),name:"red",category:"sequential"},Ru={type:"interpolation",displayName:"Green",getColor:bn(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},ju={type:"interpolation",displayName:"Blue",getColor:bn(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},Yu={type:"interpolation",displayName:"Orange",getColor:bn(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class Qu{constructor(t){N(this,"symbol");this.symbol=Symbol(t)}}function lt(e){return new Qu(e)}class yr{constructor(){N(this,"parent");N(this,"factoryRegistry",new Map);N(this,"instanceRegistry",new Map)}createScoped(){const t=new yr;return t.parent=this,t}getRequired(t){return this.get(t)}get(t){if(this.instanceRegistry.has(t.symbol))return this.instanceRegistry.get(t.symbol);const n=this.factoryRegistry.get(t.symbol);if(n){const r=n(this);return this.instanceRegistry.set(t.symbol,r),r}if(this.parent)return this.parent.get(t)}provideFactory(t,n){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,n),this}provideValue(t,n){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,()=>n),this}dispose(){this.instanceRegistry.forEach(t=>{const n=x.get(t,"dispose");x.isFunction(n)&&n.bind(t)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const Ja="10.10.0",Ku=Object.freeze(Object.defineProperty({__proto__:null,version:Ja},Symbol.toStringTag,{value:"Module"}));class Uu{constructor(t){N(this,"staticColors",new Map);N(this,"interpolations",new Map);t.installedPlugins.forEach(n=>{n.manifest.color.forEach(r=>{this.register(r)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(t){const n=this.encodeColor(t);t.type==="single"?(this.staticColors.has(n)&&console.warn(`the color '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.staticColors.set(n,t)):t.type==="interpolation"&&(this.interpolations.has(n)&&console.warn(`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`,`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.interpolations.set(n,t))}decodeStaticColor(t){return this.staticColors.get(t)}encodeColor(t){return`\${${t.category}}.{${t.name}}`}decodeInterpolation(t){return this.interpolations.get(t)}getColorInterpolations(){return Array.from(this.interpolations.values())}}class Xu{constructor(){N(this,"plugins",new Map);N(this,"vizComponents",new Map);N(this,"factory",{viz:t=>{const n=this.vizComponents.get(t);if(n)return n;throw new Error(`Viz Component (${t}) not found`)}})}install(t){if(this.plugins.has(t.id))throw new Error(`Plugin (${t.id}) has been installed before`);this.plugins.set(t.id,t);for(const n of t.manifest.viz){if(this.vizComponents.has(n.name))throw new Error(`Viz Component (${n.name}) has been installed before`);this.vizComponents.set(n.name,n)}}get installedPlugins(){return Array.from(this.plugins.values())}}class Ju{constructor(){N(this,"migrations",[])}version(t,n){return this.migrations.push({version:t,handler:n}),this}run(t,n,r){var l;if(t.from===t.to)return n;if(t.from>t.to)throw new Error(`Can not downgrade from version '${t.from}' to (${t.to})`);const a=this.migrations.filter(u=>u.version>t.from&&u.version<=t.to),o=x.orderBy(a,"version","asc");if(((l=x.last(o))==null?void 0:l.version)!==t.to)throw new Error(`Migration to version ${t.to} not found`);return o.reduce((u,c)=>c.handler(u,r),n)}}class be extends Ju{constructor(){super(),this.configVersions()}version(t,n){return super.version(t,(r,a)=>({version:t,...n(r,a)}))}async migrate({configData:t,panelModel:n}){const r=await t.getItem(null),a=x.get(r,"version",0),o=this.run({from:a,to:this.VERSION},r,{panelModel:n});await t.setItem(null,o)}async needMigration({configData:t}){const n=await t.getItem(null);return x.get(n,"version",0)<this.VERSION}}const W=(e,t)=>{const[n,{setFalse:r}]=X.useBoolean(!0),[a,o]=b.useState();b.useEffect(()=>(e.getItem(t).then(u=>{o(u),r()}),e.watchItem(t,u=>{o(u)})));const l=b.useCallback(async u=>{await e.setItem(t,u),o(u)},[e,t]);return{loading:n,value:a,set:l}},br={x_axis_data_key:"",y_axis_data_key:"",z_axis_data_key:"",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}};function q(e){const[t,n]=e.split(".");return{queryID:t,columnKey:n}}function ut(e,t){var a;const{queryID:n,columnKey:r}=q(t);return n?r?((a=e[n])==null?void 0:a.map(o=>o[r]))??[]:e[n]:[]}function vn(e,t){const{queryID:n}=q(t);return n?e[n]:[]}function Zu(e){return Object.values(e)[0]}function xn(e,t){const{queryID:n,columnKey:r}=q(t);return e[r]}oe.use([G.GridComponent,G.VisualMapComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function Hu({context:e}){const{value:t}=W(e.instanceData,"config"),n=e.data,{width:r,height:a}=e.viewport,{x_axis_data_key:o,y_axis_data_key:l,z_axis_data_key:u,xAxis3D:c,yAxis3D:d,zAxis3D:f}=x.defaults({},t,br),h=b.useMemo(()=>vn(n,o),[n,o]),{x:g,y:m,z:C}=b.useMemo(()=>({x:q(o),y:q(l),z:q(u)}),[o,l,u]),{min:w,max:_}=b.useMemo(()=>{const E=x.minBy(h,B=>B[C.columnKey]),O=x.maxBy(h,B=>B[C.columnKey]);return{min:x.get(E,C.columnKey),max:x.get(O,C.columnKey)}},[h,C]),D={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:w,max:_,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:c,yAxis3D:d,zAxis3D:f,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:h.map(E=>[E[g.columnKey],E[m.columnKey],E[C.columnKey]])}]};return t?i(Ne,{echarts:oe,option:D,style:{width:r,height:a},notMerge:!0,theme:"merico-light"}):null}const Za=b.createContext(null),vr=Za.Provider;function xr(){const e=b.useContext(Za);if(!e)throw new Error("Please use DashboardModelContextProvider");return e}const me=()=>xr(),Ha=()=>xr(),es=b.createContext(null),wr=es.Provider;function ts(){const e=b.useContext(es);if(!e)throw new Error("Please use ContentModelContextProvider");return e}const ue=()=>ts(),Me=()=>ts(),ec={inEditMode:!1},wn=b.createContext(ec),ns=b.createContext({panel:null,data:{},loading:!1,errors:[]}),Cr=ns.Provider;function rs(){const e=b.useContext(ns);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const gt=()=>rs(),Je=()=>rs(),tc={fullScreenPanelID:"",setFullScreenPanelID:x.noop},Sr=b.createContext(tc);function is(){const e=b.useContext(Sr);if(!e)throw new Error("Please use FullScreenPanelContext.Provider");return e}const R=k.observer(b.forwardRef(({label:e,required:t,value:n,onChange:r,clearable:a=!1,sx:o,...l},u)=>{const{panel:c}=Je(),d=b.useMemo(()=>{const f=[...c.dataFieldOptions];return a&&f.unshift({label:"unset",value:"",group:""}),f},[c.dataFieldOptions]);return i(s.Select,{ref:u,label:e,data:d,value:n,onChange:r,required:t,sx:o,...l})}));function nc({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),r=x.defaults({},t,br),{control:a,handleSubmit:o,reset:l}=v.useForm({defaultValues:r});return b.useEffect(()=>{l(r)},[t]),t?i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[i(s.Text,{children:"X Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"x_axis_data_key",control:a,render:({field:u})=>i(R,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"xAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Text,{mt:"lg",children:"Y Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"y_axis_data_key",control:a,render:({field:u})=>i(R,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"yAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Text,{mt:"lg",children:"Z Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"z_axis_data_key",control:a,render:({field:u})=>i(R,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"zAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:p(s.Button,{color:"blue",type:"submit",children:[i(T.DeviceFloppy,{size:20}),i(s.Text,{ml:"md",children:"Save"})]})})]})}):null}function rc(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis_data_key:a,y_axis_data_key:o,z_axis_data_key:l,...u}=e;return{...u,x_axis_data_key:r(a),y_axis_data_key:r(o),z_axis_data_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class ic extends be{constructor(){super(...arguments);N(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:rc(a,r)}})}}const ac={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new ic,name:"bar-3d",viewRender:Hu,configRender:nc,createConfig(){return{version:2,config:x.cloneDeep(br)}}};class Fe extends b.Component{constructor(t){super(t),this.state={error:null}}componentDidCatch(t){this.setState({error:t})}render(){var t;if(this.state.error){const n=()=>{this.setState({error:null})};return p(s.Box,{children:[i(s.Text,{size:"xs",children:(t=this.state.error)==null?void 0:t.message}),i(s.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:n,children:"Retry"})]})}return this.props.children}}const $e={mantissa:0,output:"number",trimMantissa:!1,average:!1};function sc({value:e,onChange:t},n){const r=u=>{t({...e,output:u})},a=u=>{const c=u===0?!1:e.trimMantissa;t({...e,mantissa:u,trimMantissa:c})},o=u=>{t({...e,trimMantissa:u.currentTarget.checked})},l=u=>{t({...e,average:u.currentTarget.checked})};return p(s.Stack,{ref:n,children:[p(s.Group,{grow:!0,children:[i(s.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:e.output,onChange:r,sx:{flexGrow:1}}),i(s.Switch,{label:p(s.Stack,{spacing:0,children:[i(s.Text,{children:"Average"}),i(s.Text,{size:12,color:"gray",children:"like 1.234k, 1.234m"})]}),checked:e.average,onChange:l,disabled:e.output!=="number",sx:{flexGrow:1},styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}}})]}),p(s.Group,{grow:!0,children:[i(s.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:e.mantissa,onChange:a}),i(s.Switch,{label:"Trim mantissa",checked:e.trimMantissa,onChange:o,disabled:e.mantissa===0,styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"}}})]}),p(s.Stack,{spacing:0,children:[i(s.Text,{weight:"bold",children:"Preview"}),i(Fe,{children:p(s.Group,{position:"apart",children:[p(s.Text,{size:12,color:"gray",children:["123456789 ",i(T.ArrowRight,{size:9})," ",H(123456789).format(e)]}),p(s.Text,{size:12,color:"gray",children:["1234 ",i(T.ArrowRight,{size:9})," ",H(1234).format(e)]}),p(s.Text,{size:12,color:"gray",children:["0.1234 ",i(T.ArrowRight,{size:9})," ",H(.1234).format(e)]})]})})]})]})}const je=b.forwardRef(sc),rt={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
55
+ `)},as={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:lc,configRender:oc,payload:[{name:"type",description:"Always 'click'",valueType:"string"},{name:"seriesType",description:"'boxplot'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"Record of 'name', 'min', 'q1', 'median', 'q3', 'max'",valueType:"object"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function oc(e){return i(V,{})}function lc(e){return i(s.Text,{children:"Click chart's series"})}const uc=[{label:"Truncate",value:"truncate"},{label:"Break Line",value:"break"},{label:"Break Word",value:"breakAll"}],Cn=b.forwardRef(({sectionTitle:e,value:t,onChange:n},r)=>{const a=o=>l=>{const u=x.cloneDeep(t);x.set(u,o,l),n(u)};return p(s.Stack,{spacing:0,children:[e&&i(s.Divider,{mb:-5,mt:5,variant:"dotted",label:e,labelPosition:"right",labelProps:{color:"dimmed"}}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.NumberInput,{label:"Max Width",hideControls:!0,value:t.width,onChange:a("width")}),i(s.Select,{label:"Overflow",data:uc,value:t.overflow,onChange:a("overflow")}),i(s.TextInput,{label:"Ellipsis",value:t.ellipsis,disabled:!0})]})]})}),mt=b.forwardRef(({value:e,onChange:t},n)=>{const r=o=>{t({...e,on_axis:o})},a=o=>{t({...e,in_tooltip:o})};return p(s.Stack,{ref:n,spacing:0,children:[i(Cn,{sectionTitle:"Overflow on Axis",value:e.on_axis,onChange:r}),i(Cn,{sectionTitle:"Overflow in Tooltip",value:e.in_tooltip,onChange:a})]})}),Ze={on_axis:{width:80,overflow:"truncate",ellipsis:"..."},in_tooltip:{width:200,overflow:"break",ellipsis:"..."}};function yt({overflow:e,width:t}){const n={truncate:"initial",break:"break-all",breakAll:"break-word"}[e],r=e==="truncate"?"nowrap":"initial",a={truncate:"ellipsis",break:"clip",breakAll:"clip"}[e];return`
56
+ max-width: ${t}px;
122
57
  word-break: ${n};
123
58
  white-space: ${r};
124
59
  overflow: hidden;
125
60
  text-overflow: ${a};
126
- `}function ut(t){return{width:t.width,overflow:t.overflow,ellipsis:t.ellipsis}}const _r={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...nt},overflow:Ze}},y_axis:{name:"Y Axis",data_key:"value",label_formatter:$e},tooltip:{metrics:[]},color:"#228be6",reference_lines:[]},He=(t,e)=>{const[n,r]=y.useState([]);return y.useEffect(()=>t.watchTriggerSnapshotList(a=>r(a.filter(o=>o.schemaRef===e))),[]),n},Ss=t=>{const{title:e="Variables",variables:n}=t,r=Me.useClipboard(),a=o=>{r.copy(o),hn.showNotification({color:"green",message:"Copied to clipboard"})};return p(s.Paper,{withBorder:!0,p:"sm",children:[i(s.Text,{size:"xs",color:"dimmed",mb:"sm",children:e}),i(s.Stack,{style:{maxHeight:"500px"},children:n.map(o=>p(s.Text,{size:"sm",children:[p(s.Code,{color:"teal",children:["// ",o.description]}),i("br",{}),p(s.Code,{onClick:()=>a(o.name),style:{cursor:"pointer"},children:[o.name," : ",o.valueType]})]},o.name))})]})};class Cc{constructor(e,n){N(this,"operationId");N(this,"operation");N(this,"operationSchema");N(this,"variables",[]);this.operationManager=e,this.instance=n,ie.makeAutoObservable(this)}get schemaList(){return this.operationManager.getOperationSchemaList()}async configOperation(e,n){const r=await this.operationManager.retrieveTrigger(e),a=this.operationManager.getOperationSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));ie.runInAction(()=>{this.operationId=e,this.operation=r,this.operationSchema=a,this.variables=n})}async changeSchema(e){this.operationId&&(await this.operationManager.createOrGetOperation(this.operationId,e),await this.configOperation(this.operationId,this.variables))}}function Sc(t){return!!t.operationId}const _c=k.observer(({model:t,onClick:e})=>{var r;const n=(r=t.operationSchema)==null?void 0:r.displayName;return i(s.Button,{variant:"outline",onClick:e,children:n})}),kc=k.observer(({model:t})=>{const e={operation:t.operation,instance:t.instance,variables:[]};return y.createElement(t.operationSchema.configRender,e)});function Tc({model:t}){const e=t.schemaList,n=e.map(a=>({label:a.displayName,value:a.id}));async function r(a){await t.changeSchema(e.find(o=>o.id===a))}return i(s.Select,{label:"Operation",data:n,onChange:r,value:t.operationSchema.id})}const Dc=k.observer(t=>{const[e,{setTrue:n,setFalse:r}]=X.useBoolean(!1),{operationManager:a,operationId:o,instance:l,variables:u}=t,c=X.useCreation(()=>new Cc(a,l),[a,l]);return X.useAsyncEffect(async()=>{await c.configOperation(o,u)},[o,c]),Sc(c)?p(V,{children:[i(_c,{model:c,onClick:n}),i(s.Modal,{size:600,opened:e,onClose:r,title:"Operation Settings",zIndex:320,children:p(s.Stack,{children:[i(Tc,{model:c}),p(s.Tabs,{defaultValue:"settings",children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"settings",children:"Settings"}),i(s.Tabs.Tab,{value:"variables",children:"Variables"})]}),i(s.Tabs.Panel,{value:"settings",pt:10,children:i(kc,{model:c})}),i(s.Tabs.Panel,{value:"variables",pt:10,children:i(Ss,{title:"Variables",variables:c.variables})})]})]})})]}):null});class Mc{constructor(e,n){N(this,"triggerId");N(this,"trigger");N(this,"triggerSchema");N(this,"sampleData");this.triggerManager=e,this.instance=n,ie.makeAutoObservable(this)}get schemaList(){return this.triggerManager.getTriggerSchemaList()}async configTrigger(e,n){const r=await this.triggerManager.retrieveTrigger(e),a=this.triggerManager.getTriggerSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));ie.runInAction(()=>{this.triggerId=e,this.trigger=r,this.triggerSchema=a,this.sampleData=n})}async changeSchema(e){this.triggerId&&(await this.triggerManager.createOrGetTrigger(this.triggerId,e),await this.configTrigger(this.triggerId,this.sampleData))}isReady(){return Ic(this)}}function Ic(t){return!!t.triggerId&&!!t.triggerSchema}function Ec(t,e){return X.useCreation(()=>new Mc(t,e),[t,e])}const Ac=k.observer(({model:t,onClick:e})=>{const n=t.triggerSchema.nameRender,r={trigger:t.trigger,instance:t.instance,sampleData:t.sampleData};return i(s.Button,{variant:"outline",onClick:e,children:y.createElement(n,r)})}),zc=k.observer(({model:t})=>{const e=t.schemaList,n=e.map(a=>({label:a.displayName,value:a.id}));async function r(a){await t.changeSchema(e.find(o=>o.id===a))}return i(s.Select,{label:"Trigger",data:n,value:t.triggerSchema.id,onChange:r})}),$c=k.observer(({model:t})=>{const e={trigger:t.trigger,instance:t.instance,sampleData:t.sampleData};return y.createElement(t.triggerSchema.configRender,e)}),Lc=k.observer(t=>{const[e,{setTrue:n,setFalse:r}]=X.useBoolean(!1),a=t.model;return p(V,{children:[i(s.Modal,{opened:e,onClose:r,title:"Setup Trigger",zIndex:320,children:p(s.Stack,{children:[i(zc,{model:a}),i($c,{model:a}),i(Ss,{title:"Payload",variables:a.triggerSchema.payload})]})}),i(Ac,{onClick:n,model:a})]})});function Oc(t,e){const[n,r]=y.useState([]);return X.useAsyncEffect(async()=>{const a=await t.getInteractionList();r(a)},[e,t]),n}const Pc=k.observer(({item:t,manager:e,instance:n,sampleData:r,variables:a,onRemove:o})=>{const{triggerRef:l,operationRef:u}=t,c=Ec(e.triggerManager,n);if(X.useAsyncEffect(async()=>{await c.configTrigger(l,r)},[c,l,r]),c.isReady()){const d=[...c.triggerSchema.payload,...a];return p(s.Group,{children:[i(Lc,{model:c}),i(Dc,{instance:n,operationId:u,variables:d,operationManager:e.operationManager}),i(s.ActionIcon,{"aria-label":"delete-interaction",variant:"filled",color:"red",onClick:()=>o(t),children:i(D.Trash,{size:16})})]})}return null}),Bc=t=>{const[e,n]=y.useState(0),{interactionManager:r,instance:a,sampleData:o,variables:l}=t,u=Oc(r,e),c=async()=>{const g=await r.triggerManager.createOrGetTrigger(Me.randomId(),r.triggerManager.getTriggerSchemaList()[0]),m=await r.operationManager.createOrGetOperation(Me.randomId(),r.operationManager.getOperationSchemaList()[0]);await r.addInteraction(g,m),n(w=>w+1)};async function d(g){await r.removeInteraction(g.id),n(m=>m+1)}const{data:f=0,loading:h}=X.useRequest(async()=>{try{return(await r.triggerManager.getTriggerSchemaList()).length}catch{return 0}});return p(s.Stack,{children:[i(s.LoadingOverlay,{visible:h}),f===0&&i(s.Alert,{icon:i(D.AlertCircle,{size:16}),title:"Unavailable",color:"gray",children:"This visualization does not have available interactions to choose from"}),u.map(g=>i(Pc,{onRemove:d,instance:a,sampleData:o,variables:l,item:g,manager:t.interactionManager},g.id)),i(s.Button,{style:{width:"fit-content"},onClick:()=>c(),disabled:f===0,children:"Add interaction"})]})},Vc=()=>{const{panel:t,data:e}=ze(),n=t.viz,{vizManager:r}=y.useContext(at),a=t.json,o=X.useCreation(()=>r.getOrCreateInstance(a),[r,a]),l=X.useCreation(()=>new yi(o,r.resolveComponent(n.type),Jn),[o,n.type]);return y.useEffect(()=>o.instanceData.watchItem(null,x.throttle(u=>{t.viz.setConf(u)},100,{leading:!1,trailing:!0})),[o]),{instance:o,vizManager:r,interactionManager:l,sampleData:e,variables:[]}},Nc=()=>{const t=Vc();return i(Bc,{...t})},_s="__TRIGGERS";class qc{constructor(e,n){N(this,"attachments");this.instance=e,this.component=n;const r=async a=>{const{id:o,schemaRef:l}=await a.getItem(null);return{id:o,schemaRef:l,triggerData:new Lt(a,"data")}};this.attachments=new vr(e,_s,r)}watchTriggerSnapshotList(e){return this.instance.instanceData.watchItem(_s,n=>{const r=x.values(n).map(a=>({id:x.get(a,"id"),schemaRef:x.get(a,"schemaRef"),config:ie.toJS(x.get(a,"data.config"))}));e(r)},{fireImmediately:!0})}async createOrGetTrigger(e,n,r={recreate:!1}){var u;if(!this.getTriggerSchemaList().some(c=>c.id===n.id))throw new Error(`Trigger schema '${n.id}' is not defined in component '${this.component.name}'`);const o=await this.attachments.getInstance(e);return!o||r.recreate||o.schemaRef!==n.id?await this.attachments.create(e,{id:e,schemaRef:n.id,data:((u=n==null?void 0:n.createDefaultConfig)==null?void 0:u.call(n))||{}}):o}async getTriggerList(){return await this.attachments.list()}getTriggerSchemaList(){return this.component.triggers||[]}async removeTrigger(e){await this.attachments.remove(e)}async retrieveTrigger(e){return await this.attachments.getInstance(e)}async getMigrationTasks(){const n=(await this.getTriggerList()).map(async r=>{const a=this.getTriggerSchemaList().find(u=>u.id===r.schemaRef),o=a==null?void 0:a.migrator,l={configData:r.triggerData};return o&&await o.needMigration(l)?()=>o.migrate(l):null});return Promise.all(n).then(r=>r.filter(a=>a))}async needMigration(){return(await this.getMigrationTasks()).length>0}async runMigration(){const e=await this.getMigrationTasks();await Promise.all(e.map(n=>n()))}}function Ot({enabled:t,func_content:e}){return(n,r)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function Fc(t,e){return Object.entries(t).map(([r,a])=>{const o=a.map(_=>_[e]).sort((_,T)=>_-T),l=Yt.quantile(o,.25)??0,u=Yt.quantile(o,.5)??0,c=Yt.quantile(o,.75)??0,d=c-l,f=l-1.5*d,h=c+1.5*d,g=Math.max(o[0],f),m=Math.min(x.last(o)??0,h),w=a.filter(_=>{const T=_[e];return T<g||T>m}).map(_=>[r,_[e],_]);return{name:r,min:g,q1:l,median:u,q3:c,max:m,outliers:w}})}function Gc(t,e){const{x_axis:n,y_axis:r}=t;if(!n.data_key||!r.data_key)return[];const a=q(n.data_key),o=q(r.data_key);if(a.queryID!==o.queryID)throw new Error("Please use the same query for X & Y axis");const l=x.groupBy(e[a.queryID],a.columnKey),u=Fc(l,o.columnKey),c=u.map(d=>d.outliers).flat();return[{source:u},{source:c}]}function Wc({config:t}){return{show:!0,top:0,right:10,type:"scroll",data:[{name:"Box",icon:"roundRect",itemStyle:{color:t.color}},{name:"Outlier",icon:"circle",itemStyle:{color:"#2F8CC0"}}]}}const kr=["max","q3","median","q1","min"];function jc(t){const{color:e}=t;return[{name:"Box",type:"boxplot",itemStyle:{color:e,borderColor:"#2F8CC0",borderWidth:2},emphasis:{disabled:!0},boxWidth:[10,40],datasetIndex:0,encode:{y:kr,x:"name",itemName:["name"],tooltip:kr}},{name:"Outlier",type:"scatter",symbolSize:5,itemStyle:{color:"#2F8CC0"},emphasis:{scale:2},datasetIndex:1}]}function Rc(t){const{outliers:e,min:n,max:r}=t,a=e.filter(u=>u[1]<n).length,o=e.filter(u=>u[1]>r).length,l=(u,c)=>`
61
+ `}function ct(e){return{width:e.width,overflow:e.overflow,ellipsis:e.ellipsis}}const _r={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...rt},overflow:Ze}},y_axis:{name:"Y Axis",data_key:"value",label_formatter:$e},tooltip:{metrics:[]},color:"#228be6",reference_lines:[]};function bt(e,t){return b.useMemo(()=>{const{queryID:n,columnKey:r}=q(t);return x.keyBy(e[n],r)},[e,t])}const He=(e,t)=>{const[n,r]=b.useState([]);return b.useEffect(()=>e.watchTriggerSnapshotList(a=>r(a.filter(o=>o.schemaRef===t))),[]),n};class Ot{constructor(t,n){this.root=t,this.path=n}async deleteItem(t){t===null&&await this.root.deleteItem(this.path);const n=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,x.omit(n,t))}async getItem(t){const n=await this.root.getItem(this.path);return t===null?n:x.get(n,t)}async setItem(t,n){if(t===null)await this.root.setItem(this.path,n);else{const r=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,{...r,[t]:n})}return await this.getItem(t)}watchItem(t,n,r){return t===null?this.root.watchItem(this.path,(a,o)=>{n(a,o)},r):this.root.watchItem(this.path,(a,o)=>{const l=x.get(a,t),u=x.get(o,t);l!==u&&n(l,u)},r)}}class kr{constructor(t,n,r){N(this,"attachmentStorage");this.instance=t,this.attachmentKey=n,this.constructInstance=r,this.attachmentStorage=new Ot(t.instanceData,n)}async getInstance(t){if(await this.attachmentStorage.getItem(t))return this.constructInstance(new Ot(this.attachmentStorage,t))}async create(t,n){return await this.attachmentStorage.setItem(t,n),this.constructInstance(new Ot(this.attachmentStorage,t))}async remove(t){await this.attachmentStorage.deleteItem(t)}async list(){const t=await this.attachmentStorage.getItem(null);return Promise.all(x.values(t).map(n=>this.constructInstance(new Ot(this.attachmentStorage,n.id))))}}function cc(e,t){const{value:n,set:r}=W(e.operation.operationData,"config"),[a,o]=b.useState(x.defaults({},n,t)),l=async()=>{await r(a)};return b.useEffect(()=>{o(x.defaults({},n,t))},[n]),{config:a,setConfig:o,commit:l}}function dc(e){const{config:t,setConfig:n,commit:r}=cc(e,{urlTemplate:"",openInNewTab:!0});async function a(){await r()}async function o(u){n({...t,openInNewTab:u}),await r()}const l=u=>n({...t,urlTemplate:u.currentTarget.value});return p(s.Stack,{children:[i(s.TextInput,{label:"Url",value:t.urlTemplate,onChange:l,onBlur:a}),i(s.Switch,{label:"Open in new Tab",checked:t.openInNewTab,onChange:u=>o(u.currentTarget.checked)})]})}async function pc(e,t){const{urlTemplate:n,openInNewTab:r}=await t.operationData.getItem("config");window.dispatchEvent(new CustomEvent("open-link",{detail:{urlTemplate:n,openInNewTab:r,payload:e}}))}class hc extends be{constructor(){super(...arguments);N(this,"VERSION",1)}configVersions(){this.version(1,n=>n)}}const fc={displayName:"Open Link",id:"builtin:op:open-link",configRender:dc,run:pc,migrator:new hc,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function gc(e){const{value:t,set:n}=W(e.operationData,"config"),r=a=>void n({template:a});return[(t==null?void 0:t.template)||"",r]}function mc(e){const[t,n]=gc(e.operation);return i(s.TextInput,{defaultValue:t,onBlur:r=>n(r.currentTarget.value),label:"console.log"})}async function yc(e,t){const n=await t.operationData.getItem("config"),r=x.template(n.template||"");console.log("run with payload",e),console.log(r(e))}const bc={displayName:"console.log (debug)",id:"builtin:op:debug",configRender:mc,run:yc},vc=k.observer(e=>{const t=ue(),{value:n,set:r}=W(e.operation.operationData,"config");console.log({value:n,viewID:n==null?void 0:n.viewID});const a=(n==null?void 0:n.viewID)||"",o=l=>void r({viewID:l});return i(s.Select,{defaultValue:a,value:a,onChange:o,label:"View",data:t.views.options})});async function xc(e,t){const r=(await t.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:r}}))}const wc={displayName:"Open View",id:"builtin:op:open_view",configRender:vc,run:xc},Cc={"tbody tr":{opacity:.5,transition:"opacity 200ms ease"},"tr[data-affected=true]":{opacity:1}},Sc=({value:e="",onChange:t})=>{const[n,r]=b.useState(e);b.useEffect(()=>{r(e)},[e]);const a=()=>{t(n)};return i(s.TextInput,{size:"xs",label:"",value:n,onChange:o=>r(o.currentTarget.value),sx:{flexGrow:1},rightSection:i(s.ActionIcon,{color:"green",size:"xs",onClick:a,disabled:n===e,children:i(L.IconDeviceFloppy,{})})})},_c={dictionary:{}},kc=k.observer(e=>{const t=ue(),{value:n=_c,set:r}=W(e.operation.operationData,"config"),{dictionary:a={}}=n;console.log({value:{...n},dictionary:{...a},filters:[...t.filters.keyLabelOptions]});const o=(l,u)=>{if(u===""){const c={...a};delete c[l],r({dictionary:c});return}r({dictionary:{...a,[l]:u}})};return p(s.Table,{sx:Cc,children:[i("thead",{children:p("tr",{children:[i("th",{children:"Set filter"}),i("th",{children:"with"})]})}),i("tbody",{children:[...t.filters.keyLabelOptions].map(l=>{const u=l.value in a;return p("tr",{"data-affected":u,children:[i("td",{children:l.label}),i("td",{children:i(Sc,{value:a[l.value],onChange:c=>o(l.value,c)})})]},l.value)})})]})});async function Tc(e,t){const r=(await t.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:r,payload:e}}))}const Dc={displayName:"Set Filter Values",id:"builtin:op:set_filter_values",configRender:kc,run:Tc},Mc={filter_keys:[]},Ic=k.observer(e=>{const t=ue(),{value:n=Mc,set:r}=W(e.operation.operationData,"config"),{filter_keys:a=[]}=n,o=u=>{r({filter_keys:[...u]})},l=b.useMemo(()=>t.filters.current.map(u=>({label:u.label,value:u.key})),[t.filters.values]);return i(s.Stack,{spacing:10,children:i(s.MultiSelect,{label:"Select Filters to Clear",data:l,value:a,onChange:o})})});async function Ec(e,t){const r=(await t.operationData.getItem("config")).filter_keys;window.dispatchEvent(new CustomEvent("clear-filter-values",{detail:{filter_keys:r,payload:e}}))}const Sn=[bc,fc,wc,Dc,{displayName:"Clear Filter Values",id:"builtin:op:clear_filter_values",configRender:Ic,run:Ec}];class Ac{constructor(t,n=Sn){N(this,"attachments");this.operations=n;const r=async a=>{const{id:o,schemaRef:l}=await a.getItem(null);return{id:o,schemaRef:l,operationData:new Ot(a,"data")}};this.attachments=new kr(t,"__OPERATIONS",r)}async runOperation(t,n){const r=await this.attachments.getInstance(t);if(!r){console.warn(`Operation '${t}' is not defined`);return}const a=this.tryGetSchema(r.schemaRef);if(!a){console.warn(`Operation schema '${r.schemaRef}' is not defined`);return}await a.run(n,r)}tryGetSchema(t){return this.operations.find(n=>n.id===t)}async needMigration(){const n=(await this.attachments.list()).map(async r=>{const a={configData:r.operationData},o=this.tryGetSchema(r.schemaRef),l=o==null?void 0:o.migrator;return l&&await l.needMigration(a)});return(await Promise.all(n)).some(r=>r)}async runMigration(){const n=(await this.attachments.list()).map(async r=>{const a={configData:r.operationData},o=this.tryGetSchema(r.schemaRef),l=o==null?void 0:o.migrator;l&&await l.needMigration(a)&&await l.migrate(a)});await Promise.all(n)}async createOrGetOperation(t,n){var l;if(!this.getOperationSchemaList().some(u=>u.id===n.id))throw new Error(`Operation schema '${n.id}' is not defined`);const a=await this.attachments.getInstance(t);return!a||a.schemaRef!==n.id?await this.attachments.create(t,{id:t,schemaRef:n.id,data:((l=n.createDefaultConfig)==null?void 0:l.call(n))??{}}):a}getOperationList(){return this.attachments.list()}getOperationSchemaList(){return this.operations}removeOperation(t){return this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}}const ss="__TRIGGERS";class zc{constructor(t,n){N(this,"attachments");this.instance=t,this.component=n;const r=async a=>{const{id:o,schemaRef:l}=await a.getItem(null);return{id:o,schemaRef:l,triggerData:new Ot(a,"data")}};this.attachments=new kr(t,ss,r)}watchTriggerSnapshotList(t){return this.instance.instanceData.watchItem(ss,n=>{const r=x.values(n).map(a=>({id:x.get(a,"id"),schemaRef:x.get(a,"schemaRef"),config:re.toJS(x.get(a,"data.config"))}));t(r)},{fireImmediately:!0})}async createOrGetTrigger(t,n,r={recreate:!1}){var u;if(!this.getTriggerSchemaList().some(c=>c.id===n.id))throw new Error(`Trigger schema '${n.id}' is not defined in component '${this.component.name}'`);const o=await this.attachments.getInstance(t);return!o||r.recreate||o.schemaRef!==n.id?await this.attachments.create(t,{id:t,schemaRef:n.id,data:((u=n==null?void 0:n.createDefaultConfig)==null?void 0:u.call(n))||{}}):o}async getTriggerList(){return await this.attachments.list()}getTriggerSchemaList(){return this.component.triggers||[]}async removeTrigger(t){await this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}async getMigrationTasks(){const n=(await this.getTriggerList()).map(async r=>{const a=this.getTriggerSchemaList().find(u=>u.id===r.schemaRef),o=a==null?void 0:a.migrator,l={configData:r.triggerData};return o&&await o.needMigration(l)?()=>o.migrate(l):null});return Promise.all(n).then(r=>r.filter(a=>a))}async needMigration(){return(await this.getMigrationTasks()).length>0}async runMigration(){const t=await this.getMigrationTasks();await Promise.all(t.map(n=>n()))}}class Tr{constructor(t,n,r){N(this,"operationManager");N(this,"triggerManager");N(this,"attachments");this.operationManager=new Ac(t,r),this.triggerManager=new zc(t,n);const a=async o=>{const{id:l,triggerRef:u,operationRef:c}=await o.getItem(null);return{id:l,triggerRef:u,operationRef:c}};this.attachments=new kr(t,"__INTERACTIONS",a)}async addInteraction(t,n){const r=t.id,a=n.id,o=`[${r}]:[${a}]`;await this.attachments.create(o,{id:o,triggerRef:r,operationRef:a})}getInteractionList(){return this.attachments.list()}async removeInteraction(t){const n=await this.attachments.getInstance(t);if(!n)return;const{triggerRef:r,operationRef:a}=n;await this.getTriggerRefCount(r)<=1&&await this.triggerManager.removeTrigger(r),await this.getOperationRefCount(a)<=1&&await this.operationManager.removeOperation(a),await this.attachments.remove(t)}async getOperationRefCount(t){return(await this.getInteractionList()).filter(r=>r.operationRef===t).length}async getTriggerRefCount(t){return(await this.getInteractionList()).filter(r=>r.triggerRef===t).length}async runInteraction(t,n){const a=(await this.getInteractionList()).filter(o=>o.triggerRef===t);await Promise.all(a.map(async o=>{try{return await this.operationManager.runOperation(o.operationRef,n)}catch(l){console.warn(`Failed to run operation '${o.operationRef}'`,l)}}))}}const et=({vizManager:e,instance:t})=>X.useCreation(()=>new Tr(t,e.resolveComponent(t.type),Sn),[t,e]),os=e=>{const{title:t="Variables",variables:n}=e,r=Ee.useClipboard(),a=o=>{r.copy(o),fn.showNotification({color:"green",message:"Copied to clipboard"})};return p(s.Paper,{withBorder:!0,p:"sm",children:[i(s.Text,{size:"xs",color:"dimmed",mb:"sm",children:t}),i(s.Stack,{style:{maxHeight:"500px"},children:n.map(o=>p(s.Text,{size:"sm",children:[p(s.Code,{color:"teal",children:["// ",o.description]}),i("br",{}),p(s.Code,{onClick:()=>a(o.name),style:{cursor:"pointer"},children:[o.name," : ",o.valueType]})]},o.name))})]})};class $c{constructor(t,n){N(this,"operationId");N(this,"operation");N(this,"operationSchema");N(this,"variables",[]);this.operationManager=t,this.instance=n,re.makeAutoObservable(this)}get schemaList(){return this.operationManager.getOperationSchemaList()}async configOperation(t,n){const r=await this.operationManager.retrieveTrigger(t),a=this.operationManager.getOperationSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));re.runInAction(()=>{this.operationId=t,this.operation=r,this.operationSchema=a,this.variables=n})}async changeSchema(t){this.operationId&&(await this.operationManager.createOrGetOperation(this.operationId,t),await this.configOperation(this.operationId,this.variables))}}function Lc(e){return!!e.operationId}const Oc=k.observer(({model:e,onClick:t})=>{var r;const n=(r=e.operationSchema)==null?void 0:r.displayName;return i(s.Button,{variant:"outline",onClick:t,children:n})}),Pc=k.observer(({model:e})=>{const t={operation:e.operation,instance:e.instance,variables:[]};return b.createElement(e.operationSchema.configRender,t)});function Bc({model:e}){const t=e.schemaList,n=t.map(a=>({label:a.displayName,value:a.id}));async function r(a){await e.changeSchema(t.find(o=>o.id===a))}return i(s.Select,{label:"Operation",data:n,onChange:r,value:e.operationSchema.id})}const Vc=k.observer(e=>{const[t,{setTrue:n,setFalse:r}]=X.useBoolean(!1),{operationManager:a,operationId:o,instance:l,variables:u}=e,c=X.useCreation(()=>new $c(a,l),[a,l]);return X.useAsyncEffect(async()=>{await c.configOperation(o,u)},[o,c]),Lc(c)?p(V,{children:[i(Oc,{model:c,onClick:n}),i(s.Modal,{size:600,opened:t,onClose:r,title:"Operation Settings",zIndex:320,children:p(s.Stack,{children:[i(Bc,{model:c}),p(s.Tabs,{defaultValue:"settings",children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"settings",children:"Settings"}),i(s.Tabs.Tab,{value:"variables",children:"Variables"})]}),i(s.Tabs.Panel,{value:"settings",pt:10,children:i(Pc,{model:c})}),i(s.Tabs.Panel,{value:"variables",pt:10,children:i(os,{title:"Variables",variables:c.variables})})]})]})})]}):null});class Nc{constructor(t,n){N(this,"triggerId");N(this,"trigger");N(this,"triggerSchema");N(this,"sampleData");this.triggerManager=t,this.instance=n,re.makeAutoObservable(this)}get schemaList(){return this.triggerManager.getTriggerSchemaList()}async configTrigger(t,n){const r=await this.triggerManager.retrieveTrigger(t),a=this.triggerManager.getTriggerSchemaList().find(o=>o.id===(r==null?void 0:r.schemaRef));re.runInAction(()=>{this.triggerId=t,this.trigger=r,this.triggerSchema=a,this.sampleData=n})}async changeSchema(t){this.triggerId&&(await this.triggerManager.createOrGetTrigger(this.triggerId,t),await this.configTrigger(this.triggerId,this.sampleData))}isReady(){return qc(this)}}function qc(e){return!!e.triggerId&&!!e.triggerSchema}function Fc(e,t){return X.useCreation(()=>new Nc(e,t),[e,t])}const Gc=k.observer(({model:e,onClick:t})=>{const n=e.triggerSchema.nameRender,r={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return i(s.Button,{variant:"outline",onClick:t,children:b.createElement(n,r)})}),Wc=k.observer(({model:e})=>{const t=e.schemaList,n=t.map(a=>({label:a.displayName,value:a.id}));async function r(a){await e.changeSchema(t.find(o=>o.id===a))}return i(s.Select,{label:"Trigger",data:n,value:e.triggerSchema.id,onChange:r})}),Rc=k.observer(({model:e})=>{const t={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return b.createElement(e.triggerSchema.configRender,t)}),jc=k.observer(e=>{const[t,{setTrue:n,setFalse:r}]=X.useBoolean(!1),a=e.model;return p(V,{children:[i(s.Modal,{opened:t,onClose:r,title:"Setup Trigger",zIndex:320,children:p(s.Stack,{children:[i(Wc,{model:a}),i(Rc,{model:a}),i(os,{title:"Payload",variables:a.triggerSchema.payload})]})}),i(Gc,{onClick:n,model:a})]})});function Yc(e,t){const[n,r]=b.useState([]);return X.useAsyncEffect(async()=>{const a=await e.getInteractionList();r(a)},[t,e]),n}const Qc=k.observer(({item:e,manager:t,instance:n,sampleData:r,variables:a,onRemove:o})=>{const{triggerRef:l,operationRef:u}=e,c=Fc(t.triggerManager,n);if(X.useAsyncEffect(async()=>{await c.configTrigger(l,r)},[c,l,r]),c.isReady()){const d=[...c.triggerSchema.payload,...a];return p(s.Group,{children:[i(jc,{model:c}),i(Vc,{instance:n,operationId:u,variables:d,operationManager:t.operationManager}),i(s.ActionIcon,{"aria-label":"delete-interaction",variant:"filled",color:"red",onClick:()=>o(e),children:i(T.Trash,{size:16})})]})}return null}),Kc=e=>{const[t,n]=b.useState(0),{interactionManager:r,instance:a,sampleData:o,variables:l}=e,u=Yc(r,t),c=async()=>{const g=await r.triggerManager.createOrGetTrigger(Ee.randomId(),r.triggerManager.getTriggerSchemaList()[0]),m=await r.operationManager.createOrGetOperation(Ee.randomId(),r.operationManager.getOperationSchemaList()[0]);await r.addInteraction(g,m),n(C=>C+1)};async function d(g){await r.removeInteraction(g.id),n(m=>m+1)}const{data:f=0,loading:h}=X.useRequest(async()=>{try{return(await r.triggerManager.getTriggerSchemaList()).length}catch{return 0}});return p(s.Stack,{children:[i(s.LoadingOverlay,{visible:h}),f===0&&i(s.Alert,{icon:i(T.AlertCircle,{size:16}),title:"Unavailable",color:"gray",children:"This visualization does not have available interactions to choose from"}),u.map(g=>i(Qc,{onRemove:d,instance:a,sampleData:o,variables:l,item:g,manager:e.interactionManager},g.id)),i(s.Button,{style:{width:"fit-content"},onClick:()=>c(),disabled:f===0,children:"Add interaction"})]})},Uc=()=>{const{panel:e,data:t}=gt(),n=e.viz,{vizManager:r}=b.useContext(st),a=e.json,o=X.useCreation(()=>r.getOrCreateInstance(a),[r,a]),l=X.useCreation(()=>new Tr(o,r.resolveComponent(n.type),Sn),[o,n.type]);return b.useEffect(()=>o.instanceData.watchItem(null,x.throttle(u=>{e.viz.setConf(u)},100,{leading:!1,trailing:!0})),[o]),{instance:o,vizManager:r,interactionManager:l,sampleData:t,variables:[]}},Xc=()=>{const e=Uc();return i(Kc,{...e})};function Pt({enabled:e,func_content:t}){return(n,r)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function Jc(e,t){return Object.entries(e).map(([r,a])=>{const o=a.map(_=>_[t]).sort((_,D)=>_-D),l=Qt.quantile(o,.25)??0,u=Qt.quantile(o,.5)??0,c=Qt.quantile(o,.75)??0,d=c-l,f=l-1.5*d,h=c+1.5*d,g=Math.max(o[0],f),m=Math.min(x.last(o)??0,h),C=a.filter(_=>{const D=_[t];return D<g||D>m}).map(_=>[r,_[t],_]);return{name:r,min:g,q1:l,median:u,q3:c,max:m,outliers:C}})}function Zc(e,t){const{x_axis:n,y_axis:r}=e;if(!n.data_key||!r.data_key)return[];const a=q(n.data_key),o=q(r.data_key);if(a.queryID!==o.queryID)throw new Error("Please use the same query for X & Y axis");const l=x.groupBy(t[a.queryID],a.columnKey),u=Jc(l,o.columnKey),c=u.map(d=>d.outliers).flat();return[{source:u},{source:c}]}function Hc({config:e}){return{show:!0,top:0,right:10,type:"scroll",data:[{name:"Box",icon:"roundRect",itemStyle:{color:e.color}},{name:"Outlier",icon:"circle",itemStyle:{color:"#2F8CC0"}}]}}const Dr=["max","q3","median","q1","min"];function ed(e){const{color:t}=e;return[{name:"Box",type:"boxplot",itemStyle:{color:t,borderColor:"#2F8CC0",borderWidth:2},emphasis:{disabled:!0},boxWidth:[10,40],datasetIndex:0,encode:{y:Dr,x:"name",itemName:["name"],tooltip:Dr}},{name:"Outlier",type:"scatter",symbolSize:5,itemStyle:{color:"#2F8CC0"},emphasis:{scale:2},datasetIndex:1}]}function td(e){const{outliers:t,min:n,max:r}=e,a=t.filter(u=>u[1]<n).length,o=t.filter(u=>u[1]>r).length,l=(u,c)=>`
127
62
  <tr>
128
63
  <th style="text-align: right; padding: 0 1em;">${u}</th>
129
64
  <td style="text-align: left; padding: 0 1em;">
130
65
  ${c}
131
66
  </td>
132
67
  </tr>
133
- `;return{greater:l("Outliers ⬆",o),less:l("Outliers ⬇",a)}}const Yc=(t,e)=>{const n=kr.map(l=>`
68
+ `;return{greater:l("Outliers ⬆",o),less:l("Outliers ⬇",a)}}const nd=(e,t)=>{const n=Dr.map(l=>`
134
69
  <tr>
135
70
  <th style="text-align: right; padding: 0 1em;">${x.capitalize(l)}</th>
136
71
  <td style="text-align: left; padding: 0 1em;">
137
- ${ee(e[l]).format(t.y_axis.label_formatter)}
72
+ ${H(t[l]).format(e.y_axis.label_formatter)}
138
73
  </td>
139
- </tr>`),r=Rc(e);return n.unshift(r.greater),n.push(r.less),`
74
+ </tr>`),r=td(t);return n.unshift(r.greater),n.push(r.less),`
140
75
  <div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
141
- <div style="${mt(t.x_axis.axisLabel.overflow.in_tooltip)}">${e.name}</div>
76
+ <div style="${yt(e.x_axis.axisLabel.overflow.in_tooltip)}">${t.name}</div>
142
77
  </div>
143
78
  <table style="width: auto">
144
79
  <tbody>
145
80
  ${n.join("")}
146
81
  </tbody>
147
82
  </table>
148
- `},Qc=t=>{try{return ee(t).format({trimMantissa:!0,mantissa:2})}catch{return t}};function Kc(t,e){const n=mt(t.x_axis.axisLabel.overflow.in_tooltip),r=[`<tr>
83
+ `},rd=e=>{try{return H(e).format({trimMantissa:!0,mantissa:2})}catch{return e}};function id(e,t){const n=yt(e.x_axis.axisLabel.overflow.in_tooltip),r=[`<tr>
149
84
  <th style="text-align: right; padding: 0 1em;">Outlier</th>
150
- <td style="text-align: left; padding: 0 1em;">${e[1]}</td>
85
+ <td style="text-align: left; padding: 0 1em;">${t[1]}</td>
151
86
  </tr>
152
- `],a=t.tooltip.metrics.map(l=>{const u=q(l.data_key);return`
87
+ `],a=e.tooltip.metrics.map(l=>{const u=q(l.data_key);return`
153
88
  <tr>
154
89
  <th style="text-align: right; padding: 0 1em;">${l.name}</th>
155
- <td style="text-align: left; padding: 0 1em;">${Qc(e[2][u.columnKey])}</td>
90
+ <td style="text-align: left; padding: 0 1em;">${rd(t[2][u.columnKey])}</td>
156
91
  </tr>`});return r.push(...a),`
157
92
  <div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
158
- <div style="${n}">${e[0]}</div>
93
+ <div style="${n}">${t[0]}</div>
159
94
  </div>
160
95
  <table>
161
96
  <tbody>
162
97
  ${r.join("")}
163
98
  </tbody>
164
99
  </table>
165
- `}const Uc=t=>e=>{const{componentSubType:n,value:r}=e;return n==="scatter"?Kc(t,r):Yc(t,r)};function Xc({config:t}){return{trigger:"item",confine:!0,formatter:Uc(t)}}const Xt=y.forwardRef(function({value:e,onChange:n,...r},a){return i(s.TextInput,{ref:a,value:e,onChange:n,...r})}),Jc=[{label:"None",value:"none"},{label:"Sum",value:"sum"},{label:"Mean",value:"mean"},{label:"Median",value:"median"},{label:"Max",value:"max"},{label:"Min",value:"min"},{label:"Coefficient of Variation",value:"CV"},{label:"Standard Variation",value:"std"},{label:"Quantile(99%, 95%, ...)",value:"quantile"}];function Zc({label:t,value:e,onChange:n,pt:r="sm"},a){y.useEffect(()=>{typeof e=="string"&&(console.log(e),n({type:e,config:{}}))},[e,n]);const o=u=>{n(u==="quantile"?{type:"quantile",config:{p:.99}}:{type:u,config:{}})},l=u=>{n({type:"quantile",config:{p:u}})};return p(s.Group,{grow:!0,noWrap:!0,pt:r,children:[i(s.Select,{ref:a,label:t,data:Jc,value:e.type,onChange:o}),e.type==="quantile"&&i(s.NumberInput,{label:"p",value:e.config.p,onChange:l,precision:2,min:.05,step:.05,max:1})]})}const Sn=y.forwardRef(Zc);function Hc({label:t,value:e,onChange:n},r){const[a,o]=y.useState(Array.isArray(e)?[...e]:[]),l=y.useCallback(()=>{o(g=>[...g,""])},[o]),u=y.useCallback(g=>{o(m=>(m.splice(g,1),[...m]))},[o]),c=y.useMemo(()=>!x.isEqual(a,e),[a,e]),d=()=>{n(a.map(g=>g.toString()))},f=s.useMantineTheme(),h=y.useMemo(()=>Object.entries(f.colors).map(([g,m])=>m[6]),[f]);return p(V,{children:[p(s.Group,{position:"left",ref:r,children:[i(s.Text,{children:t}),i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!c,onClick:d,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Group,{children:[a.map((g,m)=>i(s.ColorInput,{value:g,onChange:w=>{o(C=>(C.splice(m,1,w),[...C]))},swatches:h,rightSection:i(s.ActionIcon,{onClick:()=>u(m),color:"red",children:i(D.Trash,{size:14})}),sx:{width:"45%"}})),i(s.ActionIcon,{onClick:l,color:"blue",variant:"outline",children:i(D.PlaylistAdd,{size:20})})]})]})}const ed=y.forwardRef(Hc);function td({value:t,onChange:e},n){const{colorManager:r}=y.useContext(at),a=y.useMemo(()=>r.getStaticColors().map(u=>({label:u.name,group:u.category,value:u.value})),[r]),o=y.useMemo(()=>a.some(l=>l.value===t),[t,a]);return p(s.Group,{position:"apart",spacing:4,ref:n,children:[i(s.TextInput,{placeholder:"Set any color",value:o?"":t,onChange:l=>e(l.currentTarget.value),rightSection:i(s.ColorSwatch,{color:o?"transparent":t,radius:4}),variant:o?"filled":"default",sx:{maxWidth:"46%",flexGrow:1}}),i(s.Text,{sx:{flexGrow:0},children:"or"}),i(s.Select,{data:a,value:t,onChange:e,variant:o?"default":"filled",placeholder:"Pick a theme color",icon:i(s.ColorSwatch,{color:o?t:"transparent",radius:4}),sx:{maxWidth:"46%",flexGrow:1}})]})}const Pe=y.forwardRef(td),_n=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function nd({label:t,value:e,onChange:n},r){var l;const[a,o]=y.useState(((l=_n.find(u=>u.label===e))==null?void 0:l.value)??_n[0].value);return y.useEffect(()=>{const u=_n.find(c=>c.value===a);u&&n(u.label)},[a]),p(s.Stack,{spacing:0,mt:"sm",mb:"lg",children:[i(s.Text,{size:"sm",children:t}),i(s.Slider,{label:null,marks:_n,value:a,onChange:o,step:25,placeholder:"Pick a font size",px:"1em",ref:r})]})}const ks=y.forwardRef(nd);function rd({label:t,value:e,onChange:n,type:r},a){const[o,l]=y.useState(Array.isArray(e)?[...e]:[]),u=y.useCallback(()=>{l(h=>[...h,""])},[l]),c=y.useCallback(h=>{l(g=>(g.splice(h,1),[...g]))},[l]),d=y.useMemo(()=>!x.isEqual(o.map(String),e.map(String)),[o,e]),f=()=>{n(o.map(h=>r==="number"?Number(h):h.toString()))};return p(V,{children:[p(s.Group,{position:"left",ref:a,children:[i(s.Text,{children:t}),i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!d,onClick:f,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Group,{children:[o.map((h,g)=>i(s.TextInput,{type:r,value:h,onChange:m=>{const w=m.currentTarget.value;l(C=>(C.splice(g,1,w),[...C]))},rightSection:i(s.ActionIcon,{onClick:()=>c(g),color:"red",children:i(D.Trash,{size:14})}),sx:{width:"45%"}})),i(s.ActionIcon,{onClick:u,color:"blue",variant:"outline",children:i(D.PlaylistAdd,{size:20})})]})]})}const id=y.forwardRef(rd),Ts=y.forwardRef(function({value:e,onChange:n},r){const a=e.color.type,o=(l,u)=>{const c=x.cloneDeep(e);x.set(c,l,u),n(c)};return p(V,{children:[i(s.Divider,{my:"xs",label:"Typography",labelPosition:"center"}),i(s.Stack,{children:i(s.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},value:e.size,onChange:l=>o("size",l.currentTarget.value)})}),i(s.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:i(ks,{label:"Font Weight",value:e.weight,onChange:l=>o("weight",l)})}),i(s.Divider,{my:"xs",label:"Style",labelPosition:"center"}),p(s.Stack,{children:[i(s.Select,{label:"Color Type",data:[{label:"Static Color",value:"static"},{label:"Continuous Color",value:"continuous"}],value:e.color.type,onChange:l=>o("color.type",l)}),a==="static"&&i(Pe,{value:e.color.staticColor,onChange:l=>o("color.staticColor",l)}),a==="continuous"&&p(V,{children:[i(id,{label:"Value Range",value:e.color.valueRange,type:"number",onChange:l=>o("color.valueRange",l)}),i(ed,{label:"Color Range",value:e.color.colorRange,onChange:l=>o("color.colorRange",l)})]})]})]})});y.forwardRef(function({value:e,onChange:n,withStyle:r=!0},a){const o=(l,u)=>{const c=x.cloneDeep(e);x.set(c,l,u),n(c)};return p(s.Box,{px:"sm",py:"md",ref:a,children:[i(s.Text,{weight:"bold",pb:0,children:e.name}),i(s.Divider,{my:"xs",label:"Data",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.TextInput,{label:"Name",required:!0,value:e.name,onChange:l=>o("name",l.currentTarget.value)}),i(j,{label:"Data Field",required:!0,value:e.data_field,onChange:l=>o("data_field",l)})]}),i(Sn,{label:"Aggregation",value:e.aggregation,onChange:l=>o("aggregation",l)}),i(s.Divider,{my:"xs",label:"Format",labelPosition:"center"}),i(Re,{value:e.formatter,onChange:l=>o("formatter",l)}),r&&i(Ts,{value:e,onChange:n})]})});const Pt={type:"none",config:{}};function ad(t){const e=Array.from(t).sort((r,a)=>r-a),n=Math.floor(e.length/2);return e.length%2===0?(e[n-1]+e[n])/2:e[n]}function sd(t){const e=Number(t);return isFinite(e)?e:0}function od(t,e){switch(e.type){case"sum":return x.sum(t);case"mean":return x.mean(t);case"median":return ad(t);case"max":return x.max(t)??0;case"min":return x.min(t)??0;case"quantile":return Yt.quantile(t,e.config.p)??0;case"CV":const n=mn.std(...t),r=mn.mean(...t);return r?n/r:"N/A";case"std":return mn.std(...t);default:return t}}function Tr(t,e){const n=t.map(sd);return od(n,e)}function kn(t,e,n){try{return Tr(lt(t,e),n)}catch(r){return console.error(r),null}}class ld{constructor({valueRange:e,colorRange:n}){N(this,"mapper");this.mapper=_t.interpolate(e,n)}getColor(e){return this.mapper(e)}}function ud(t){return t===null?"null":t===void 0?"undefined":Array.isArray(t)?`Array(${t.length})`:t.toString()}function yt({data_field:t,aggregation:e},n){return kn(n,t,e)}function et({formatter:t},e){if(!["string","number"].includes(typeof e))return ud(e);try{return ee(e).format(t)}catch(n){return console.error(n),e}}function cd(t,e){if(t.type==="static")return t.staticColor;if(t.type==="continuous")try{if(typeof e!="number")throw new Error(`[getColorByColorConf] Invalid type of aggregated value: ${e}`);return new ld(t).getColor(e)}catch(n){return console.error(n),"black"}return"black"}function Ds(t,e){const{color:n,data_field:r,aggregation:a,size:o,weight:l}=t,u=kn(e,r,a),c=et(t,u);return i(s.Text,{sx:{fontSize:o,display:"inline"},color:cd(n,u),weight:l,children:c})}function dd(t,e){const n={};return t.forEach(r=>{const a=r.name;n[a]=Ds(r,e)}),n}function pd(t){return t.split(" ").map((e,n)=>p(y.Fragment,{children:[e," "]},n))}function hd(t){const n=t.replaceAll("<br />","<br/>").replaceAll(`
166
- `,"<br/>").split("<br/>");return n.map((a,o)=>{const l=[pd(a)];return o!==n.length-1&&l.push(i("br",{},`br-${o}`)),l}).flat().filter(a=>a!==void 0)}function Dr(t){return hd(t)}function Jt(t,e,n){const r=dd(e,n),a=/^\{(.+)\}(.*)$/;return t.split("$").map((o,l)=>{const u=a.exec(o);if(!u)return Dr(o);const c=r[u[1]];if(!c)return Dr(o);const d=u[2]??"";return p(y.Fragment,{children:[c,Dr(d)]},`${o}-${l}`)})}function fd(t,e){const n={};return t.forEach(r=>{const{name:a,data_field:o,aggregation:l}=r,u=kn(e,o,l);n[a]=et(r,u)}),n}function Tn(t,e,n){const r=fd(e,n),a=/^\{(.+)\}(.*)$/;return t.split("$").map(o=>{const l=a.exec(o);if(!l)return o;const u=r[l[1]];if(!u)return o;const c=l[2]??"";return`${u}${c}`}).join("")}function gd(t,e,n){const r=e.reduce((a,o)=>{const l=yt(o,n);return a[o.name]=et(o,l),a},{});return t.map(a=>({name:"refs",type:"scatter",data:[],markLine:{data:[{name:a.name,yAxis:Number(r[a.variable_key])}],silent:!0,symbol:["none","none"],label:{formatter:function(){return Tn(a.template,e,n)},position:"insideEndTop"}}}))}function md({config:t,data:e,variables:n}){const{x_axis:r,y_axis:a,reference_lines:o}=t,l=Gc(t,e),u=ut(r.axisLabel.overflow.on_axis),c=jc(t);return{grid:{top:30,left:20,right:15,bottom:25,containLabel:!0},dataset:l,legend:Wc({config:t}),tooltip:Xc({config:t}),xAxis:[{type:"category",name:r.name,nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold",align:"center"},axisTick:{show:!0,alignWithLabel:!0},axisLabel:{...r.axisLabel,...u,formatter:Ot(r.axisLabel.formatter)}}],yAxis:[{name:a.name,nameTextStyle:{fontWeight:"bold"},axisLine:{show:!0},axisLabel:{formatter:function(d){return ee(d).format(a.label_formatter)}}}],series:[...c,...gd(o,n,e)]}}function bt(t,e){return y.useMemo(()=>{const{queryID:n,columnKey:r}=q(e);return x.keyBy(t[n],r)},[t,e])}le.use([G.DataZoomComponent,pe.BoxplotChart,G.MarkLineComponent,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function yd({context:t,instance:e}){const{value:n}=W(t.instanceData,"config"),{variables:r}=t,a=t.data,{width:o,height:l}=t.viewport,u=x.defaults({},n,_r),c=tt({vizManager:t.vizManager,instance:e}),d=He(c.triggerManager,Cs.id),f=bt(a,u.x_axis.data_key),h=y.useCallback(w=>{const C=x.get(f,w.name,{error:"rowData is not found"});d.forEach(_=>{c.runInteraction(_.id,{...w,rowData:C})})},[f,d,c]),g=y.useMemo(()=>({click:h}),[h]),m=y.useMemo(()=>md({config:u,data:a,variables:r}),[u,a,r]);return!n||!o||!l?null:i(s.Box,{sx:{width:o,height:l,overflow:"hidden"},children:i(Ne,{echarts:le,option:m,style:{width:o,height:l},onEvents:g,notMerge:!0,theme:"merico-light"})})}function bd({control:t,index:e,remove:n,variableOptions:r}){return p(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${e}.name`,control:t,render:({field:a})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_lines.${e}.variable_key`,control:t,render:({field:a})=>i(s.Select,{label:"Value",required:!0,data:r,sx:{flex:1},...a})})]}),i(v.Controller,{name:`reference_lines.${e}.template`,control:t,render:({field:a})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",required:!0,sx:{flex:1},...a})}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(e),sx:{position:"absolute",top:15,right:5},children:i(D.Trash,{size:16})})]},e)}function vd({control:t,watch:e,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_lines"}),l=e("reference_lines"),u=r.map((f,h)=>({...f,...l[h]})),c=()=>a({name:"",template:"",variable_key:""}),d=y.useMemo(()=>n.map(f=>({label:f.name,value:f.name})),[n]);return p(s.Stack,{children:[u.map((f,h)=>i(bd,{control:t,index:h,remove:o,variableOptions:d},f.id)),i(s.Group,{position:"center",mt:"xs",children:i(s.Button,{onClick:c,children:"Add a Reference Line"})})]})}const xd=({disabled:t,value:e,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[t&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Ie,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},Dn=y.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:a,setFalse:o}]=X.useBoolean(),[l,u]=y.useState(t);y.useEffect(()=>{u(t)},[t]);const c=m=>{u({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:w}=l,C={enabled:m,func_content:w};u(C),e(C)},f=()=>{o(),u(t)},h=m=>{u(w=>({...w,func_content:m}))},g=()=>{h(nt.func_content)};return p(V,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Customize Label"}),i(s.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>c(m.currentTarget.checked)}),i(xd,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})}),wd=({control:t,watch:e})=>(e(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>i(j,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Dn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})})]})),Cd=({control:t,watch:e})=>(e(["y_axis"]),p(V,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Y Axis Name",sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.data_key",control:t,render:({field:n})=>i(j,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:"y_axis.label_formatter",control:t,render:({field:n})=>i(Re,{...n})})]})]})),Sd=({control:t,index:e,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,render:({field:r})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),_d=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=e("tooltip.metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(V,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(D.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Set additional metrics to show in scatter's tooltip"})]}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(Sd,{control:t,index:g,remove:a},h.id)},h.id))]})]})};function kd({control:t,watch:e}){return i(s.Stack,{children:i(_d,{control:t,watch:e})})}function Td({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),{variables:r}=t,a=y.useMemo(()=>x.defaults({},e,_r),[e]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]),u(["x_axis","y_axis","reference_lines","color"]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,e),[f,e]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),i(s.Tabs.Tab,{value:"Style",children:"Style"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(wd,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(Cd,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(kd,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Style",children:p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:"color",control:o,render:({field:g})=>i(Pe,{...g})})]})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(vd,{variables:r,control:o,watch:u})})]})]})})}function Dd(t){return x.omit(t,"variables")}function Md(t){const{label_formatter:e=$e,...n}=t.y_axis;return{...t,y_axis:{...n,label_formatter:e}}}function Id(t){const e={rotate:0,formatter:{...nt}},{axisLabel:n=e,...r}=t.x_axis;return{...t,x_axis:{...r,axisLabel:n}}}function Ed(t){const e={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(e,t)}function Ad(t){delete t.config;const{x_axis:e,tooltip:n}=t.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:e,in_tooltip:n}}}};return x.defaultsDeep(r,t)}function zd(t){const e={tooltip:{metrics:[]}};return x.defaultsDeep(e,t)}function $d(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,y_axis:o,tooltip:l,...u}=t;return{...u,x_axis:{...a,data_key:r(a.data_key)},y_axis:{...o,data_key:r(o.data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:r(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}class Ld extends ve{constructor(){super(...arguments);N(this,"VERSION",8)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,{panelModel:r})=>{const{config:a}=n;return(a.variables||[]).forEach(l=>{r.variables.find(u=>u.name===l.name)||r.addVariable(l)}),{...n,version:2,config:Dd(a)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:Md(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:Id(r)}}),this.version(5,n=>{const{config:r}=n;return{...n,version:5,config:Ed(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:Ad(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:zd(r)}}),this.version(8,(n,r)=>{const{config:a}=n;return{...n,version:8,config:$d(a,r)}})}}const Od={displayName:"Boxplot Chart",displayGroup:"ECharts-based charts",migrator:new Ld,name:"boxplot",viewRender:yd,configRender:Td,createConfig(){return{version:8,config:x.cloneDeep(_r)}},triggers:[Cs]},Ms={id:"builtin:button:click-button",displayName:"Click Button",nameRender:Bd,configRender:Pd,payload:[]};function Pd(t){return i(V,{})}function Bd(t){return i(s.Text,{children:"Click this button"})}const Mr={content:"Button",variant:"filled",color:"blue",size:"xs",compact:!1,horizontal_align:"left",vertical_align:"center"},Vd={left:"flex-start",center:"center",right:"flex-end"},Nd={top:"flex-start",center:"center",bottom:"flex-end"},qd=k.observer(({context:t,instance:e})=>{const n=tt({vizManager:t.vizManager,instance:e}),r=He(n.triggerManager,Ms.id),a=K(),{value:o}=W(t.instanceData,"config"),l=y.useMemo(()=>x.defaultsDeep({},o,Mr),[o]),{content:u,horizontal_align:c,vertical_align:d,...f}=l,{width:h,height:g}=t.viewport,m=a.payloadForSQL,w=()=>{r.forEach(C=>{n.runInteraction(C.id,{})})};return i(s.Center,{sx:{width:h,height:g,justifyContent:Vd[c],alignItems:Nd[d]},children:i(s.Button,{...f,onClick:w,children:x.template(u)(m)})})}),Fd=({value:t,onChange:e,label:n})=>{const r=s.useMantineTheme(),a=y.useCallback(l=>()=>e(l),[e]),o=l=>t===l;return p(s.Stack,{spacing:2,children:[i(s.Text,{size:14,sx:{fontWeight:500},children:n}),i(s.Group,{position:"left",spacing:"xs",children:Object.keys(r.colors).map(l=>{const u=r.colors[l][6];return i(s.ColorSwatch,{color:u,onClick:a(l),radius:4,size:26,sx:{cursor:"pointer"},children:o(l)&&i(s.CheckIcon,{width:10,color:"white"})},l)})})]})},Gd=s.MANTINE_SIZES.map(t=>({label:t.toUpperCase(),value:t})),Wd=({label:t,value:e,onChange:n})=>i(s.Select,{data:Gd,label:t,value:e,onChange:n}),jd=[{label:"Filled",value:"filled"},{label:"Outline",value:"outline"},{label:"Light",value:"light"},{label:"White",value:"white"},{label:"Default",value:"default"},{label:"Subtle",value:"subtle"},{label:"Gradient",value:"gradient",disabled:!0}],Rd=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Yd=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function Qd({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,Mr),[e]),a=r;y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return u(["content","variant","color","size","compact","horizontal_align","vertical_align"]),p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Stack,{children:[i(v.Controller,{control:o,name:"content",render:({field:g})=>i(s.TextInput,{label:"Content Template",description:"Filter values & context entries are supported",...g,required:!0})}),i(s.Divider,{mt:"xs",mb:0,label:"Styles",labelPosition:"center",variant:"dashed"}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"variant",render:({field:g})=>i(s.Select,{label:"Variant",data:jd,...g})}),i(v.Controller,{control:o,name:"color",render:({field:g})=>i(Fd,{label:"Theme",...g})})]}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"size",render:({field:g})=>i(Wd,{label:"Size",...g})}),i(v.Controller,{control:o,name:"compact",render:({field:g})=>i(s.Checkbox,{label:"Compact",checked:g.value,onChange:m=>g.onChange(m.currentTarget.checked),mt:26})})]}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"horizontal_align",render:({field:g})=>i(s.Select,{label:"Horizontal Alignment",data:Rd,...g})}),i(v.Controller,{control:o,name:"vertical_align",render:({field:g})=>i(s.Select,{label:"Vertical Alignment",data:Yd,...g})})]})]})]})}class Kd extends ve{constructor(){super(...arguments);N(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{horizontal_align:r="left",vertical_align:a="center",...o}=n.config;return{...n,version:2,config:{...o,horizontal_align:r,vertical_align:a}}})}}const Ud={displayName:"Button",displayGroup:"Others",migrator:new Kd,name:"button",viewRender:qd,configRender:Qd,createConfig(){return{version:2,config:x.cloneDeep(Mr)}},triggers:[Ms]},Ir={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:Jd,configRender:Xd,payload:[{name:"seriesType",description:"'line' | 'scatter' | 'bar'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function Xd(t){return i(V,{})}function Jd(t){return i(s.Text,{children:"Click chart's series"})}const Bt={x_axis_scroll:!1,y_axis_scroll:!1,x_axis_slider:!1,y_axis_slider:!1},Er={regressions:[],series:[],stats:{templates:{bottom:"",top:""}},x_axis:{type:"category",axisLabel:{rotate:0,formatter:{...nt},overflow:Ze}},x_axis_data_key:"",x_axis_name:"",y_axes:[{min:"",max:"",name:"Y Axis",show:!0,position:"left",nameAlignment:"center",label_formatter:$e}],reference_lines:[],reference_areas:[],dataZoom:Bt};function Ar(t){const e=[];return t.x_axis_scroll&&e.push({type:"inside",xAxisIndex:[0],filterMode:"none",minSpan:1}),t.y_axis_scroll&&e.push({type:"inside",yAxisIndex:[0],filterMode:"none",minSpan:1}),t.x_axis_slider&&e.push({type:"slider",xAxisIndex:[0],filterMode:"none",bottom:"auto",top:0,height:15,moveHandleSize:0,showDataShadow:!1,minSpan:1}),e}function Zd(t){const e=t.y_axes.some(a=>!!a.name);let n=15;e&&(n+=20),t.dataZoom.x_axis_slider&&(n+=20);let r=5;return t.x_axis_name&&(r+=15),t.series.some(a=>!a.hide_in_legend)&&(r+=20),{top:n,right:15,bottom:r,left:20,containLabel:!0}}function Hd(t){return t!=="line"?{}:{itemStyle:{opacity:0}}}function ep(t){switch(t){case"line":return;case"bar":return"roundRect";case"scatter":return"circle"}}function tp(t){const e={show:!0,bottom:0,left:"center",type:"scroll"};return e.data=t.filter(n=>!n.hide_in_legend).map(({name:n,type:r})=>({name:n,icon:ep(r),...Hd(r)})),e}function Mn(t,e){switch(t.config.method){case"linear":return[...ht.regressionLinear()(e)];case"exponential":return[...ht.regressionExp()(e)];case"logarithmic":return[...ht.regressionLog()(e)];case"polynomial":return[...ht.regressionPoly().order(t.config.order)(e)];default:return[]}}function np(t,e,n,r){const{transform:a,plot:o}=t,l={...o,name:e,data:Mn(a,r),showSymbol:!1,tooltip:{show:!1},smooth:!1,custom:{}};return n&&(l.custom={type:"regression-line",targetSeries:n}),l}function rp({regressions:t=[],x_axis_data_key:e},n){const r=[];if(Object.keys(n).length===0)return r;function a(o,l,u,c){const d=np(o,l,u,c);r.push(d)}return t.forEach(o=>{const{name:l,group_by_key:u}=o;if(!u||u===e){const h=lt(n,o.y_axis_data_key).map((g,m)=>[m,Number(g)]);a(o,l,"",h);return}const{columnKey:c}=q(o.y_axis_data_key),d=x.groupBy(xn(n,o.y_axis_data_key),u);Object.entries(d).forEach(([f,h])=>{const g=h.map((w,C)=>[C,Number(w[c])]);a(o,f,f,g)})}),r}function ip(t,e){return t.map(n=>({name:"",type:"line",hide_in_legend:!0,data:[],markArea:{itemStyle:{color:n.color},data:[[{yAxis:e[n.y_keys.upper]},{yAxis:e[n.y_keys.lower]}]],silent:!0}}))}function ap(t,e,n,r){return t.map(a=>{const o=a.orientation==="horizontal",l=o?"yAxis":"xAxis",u=o?"insideEndTop":"end";return{name:a.name,type:"line",hide_in_legend:!a.show_in_legend,yAxisIndex:a.yAxisIndex,data:[],lineStyle:a.lineStyle,markLine:{data:[{name:a.name,[l]:Number(n[a.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:a.lineStyle,label:{formatter:function(){return a.template?Tn(a.template,e,r):""},position:u}}}})}function sp({type:t,...e},n,r,a){if(!t)return 10;if(t==="static"){const{size:d}=e;return d}const{func_content:o}=e,{queryID:l,columnKey:u}=q(r),c=x.keyBy(xn(n,l),u);return(d,f)=>{let h;f.name?h=c[f.name]:h=n[f.dataIndex];try{return new Function(`return ${o}`)()({rowData:h,params:f,variables:a},{lodash:x,interpolate:_t.interpolate})}catch(g){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${g.message}`),10}}}function zr(t,e,n){const r=lt(t,e),a=lt(t,n);return x.zip(r,a)}function op(t,e,n,r){const a=zr(e,n,r);return x.unionBy(a,t,0)}function lp({dataTemplate:t,data:e,x_axis_data_key:n,y_axis_data_key:r,valueTypedXAxis:a}){return a?op(t,e,n,r):lt(e,r)}function up({dataTemplate:t,data:e,aggregation_on_value:n,x_axis_data_key:r,y_axis_data_key:a,valueTypedXAxis:o}){if(!n||n.type==="none")return lp({dataTemplate:t,data:e,x_axis_data_key:r,y_axis_data_key:a,valueTypedXAxis:o});const l=zr(e,r,a),u=x.groupBy(l,"0");return t.map(([d])=>{const h=u[d].map(m=>m[1]),g=Tr(h,n);return[d,g]})}function cp({group_by_key:t,data:e,x_axis_data_key:n,y_axis_data_key:r}){const{queryID:a,columnKey:o}=q(t),l=x.groupBy(e[a],o);return Object.entries(l).forEach(([u,c])=>{l[u]=zr({[a]:c},n,r)}),l}function dp({x_axis_data_key:t,x_axis:e},{y_axis_data_key:n,yAxisIndex:r,label_position:a,name:o,group_by_key:l,aggregation_on_value:u,stack:c,color:d,display_name_on_line:f,symbolSize:h,hide_in_legend:g,...m},w,C,_,T){const I=e.type!=="category",O={label:{show:!!a,position:a,formatter:T[r??"default"]},name:o,xAxisId:"main-x-axis",yAxisIndex:r,stack:c,color:d,symbolSize:sp(h,C,t,_),hide_in_legend:g,labelLayout:{hideOverlap:!0},...m};if(f&&(O.endLabel={show:!0,formatter:o,offset:[-12,12],align:"right"}),!l||l===t)return O.data=up({dataTemplate:w,data:C,aggregation_on_value:u,x_axis_data_key:t,y_axis_data_key:n,valueTypedXAxis:I}),O;const B=cp({group_by_key:l,data:C,x_axis_data_key:t,y_axis_data_key:n});return Object.entries(B).map(([$,A])=>{const E=x.cloneDeep(O);return E.name=$,E.color=void 0,E.data=A,E})}function pp(t,e,n,r,a,o){const l=e.map(c=>[c,0]);return t.series.map(c=>dp(t,c,l,n,o,r)).flat().concat(ap(t.reference_lines,a,o,n)).concat(ip(t.reference_areas,o))}function hp(t,e){const n=t.find(o=>o.axisDim==="x"&&o.axisId==="main-x-axis");if(!n)return"";const{axisValue:r,axisIndex:a}=n;return Ot(e.x_axis.axisLabel.formatter)(r,a)}function fp(t,e,n){const r=e.reduce((a,{yAxisIndex:o,name:l})=>(a[l]=o,a),{});return{trigger:"axis",confine:!0,formatter:function(a){const o=Array.isArray(a)?a:[a];if(o.length===0)return"";const l=o.map(({seriesName:d,marker:f,value:h})=>{if(Array.isArray(h)&&h.length===2&&(h=h[1]),!d)return h;const g=r[d],m=n[g]??n.default;return`
100
+ `}const ad=e=>t=>{const{componentSubType:n,value:r}=t;return n==="scatter"?id(e,r):nd(e,r)};function sd({config:e}){return{trigger:"item",confine:!0,formatter:ad(e)}}const Jt=b.forwardRef(function({value:t,onChange:n,...r},a){return i(s.TextInput,{ref:a,value:t,onChange:n,...r})}),od=[{label:"None",value:"none"},{label:"Sum",value:"sum"},{label:"Mean",value:"mean"},{label:"Median",value:"median"},{label:"Max",value:"max"},{label:"Min",value:"min"},{label:"Coefficient of Variation",value:"CV"},{label:"Standard Variation",value:"std"},{label:"Quantile(99%, 95%, ...)",value:"quantile"}];function ld({label:e,value:t,onChange:n,pt:r="sm"},a){b.useEffect(()=>{typeof t=="string"&&(console.log(t),n({type:t,config:{}}))},[t,n]);const o=u=>{n(u==="quantile"?{type:"quantile",config:{p:.99}}:{type:u,config:{}})},l=u=>{n({type:"quantile",config:{p:u}})};return p(s.Group,{grow:!0,noWrap:!0,pt:r,children:[i(s.Select,{ref:a,label:e,data:od,value:t.type,onChange:o}),t.type==="quantile"&&i(s.NumberInput,{label:"p",value:t.config.p,onChange:l,precision:2,min:.05,step:.05,max:1})]})}const _n=b.forwardRef(ld);function ud({label:e,value:t,onChange:n},r){const[a,o]=b.useState(Array.isArray(t)?[...t]:[]),l=b.useCallback(()=>{o(g=>[...g,""])},[o]),u=b.useCallback(g=>{o(m=>(m.splice(g,1),[...m]))},[o]),c=b.useMemo(()=>!x.isEqual(a,t),[a,t]),d=()=>{n(a.map(g=>g.toString()))},f=s.useMantineTheme(),h=b.useMemo(()=>Object.entries(f.colors).map(([g,m])=>m[6]),[f]);return p(V,{children:[p(s.Group,{position:"left",ref:r,children:[i(s.Text,{children:e}),i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!c,onClick:d,children:i(T.DeviceFloppy,{size:20})})]}),p(s.Group,{children:[a.map((g,m)=>i(s.ColorInput,{value:g,onChange:C=>{o(w=>(w.splice(m,1,C),[...w]))},swatches:h,rightSection:i(s.ActionIcon,{onClick:()=>u(m),color:"red",children:i(T.Trash,{size:14})}),sx:{width:"45%"}})),i(s.ActionIcon,{onClick:l,color:"blue",variant:"outline",children:i(T.PlaylistAdd,{size:20})})]})]})}const cd=b.forwardRef(ud);function dd({value:e,onChange:t},n){const{colorManager:r}=b.useContext(st),a=b.useMemo(()=>r.getStaticColors().map(u=>({label:u.name,group:u.category,value:u.value})),[r]),o=b.useMemo(()=>a.some(l=>l.value===e),[e,a]);return p(s.Group,{position:"apart",spacing:4,ref:n,children:[i(s.TextInput,{placeholder:"Set any color",value:o?"":e,onChange:l=>t(l.currentTarget.value),rightSection:i(s.ColorSwatch,{color:o?"transparent":e,radius:4}),variant:o?"filled":"default",sx:{maxWidth:"46%",flexGrow:1}}),i(s.Text,{sx:{flexGrow:0},children:"or"}),i(s.Select,{data:a,value:e,onChange:t,variant:o?"default":"filled",placeholder:"Pick a theme color",icon:i(s.ColorSwatch,{color:o?e:"transparent",radius:4}),sx:{maxWidth:"46%",flexGrow:1}})]})}const Pe=b.forwardRef(dd),kn=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function pd({label:e,value:t,onChange:n},r){var l;const[a,o]=b.useState(((l=kn.find(u=>u.label===t))==null?void 0:l.value)??kn[0].value);return b.useEffect(()=>{const u=kn.find(c=>c.value===a);u&&n(u.label)},[a]),p(s.Stack,{spacing:0,mt:"sm",mb:"lg",children:[i(s.Text,{size:"sm",children:e}),i(s.Slider,{label:null,marks:kn,value:a,onChange:o,step:25,placeholder:"Pick a font size",px:"1em",ref:r})]})}const ls=b.forwardRef(pd);function hd({label:e,value:t,onChange:n,type:r},a){const[o,l]=b.useState(Array.isArray(t)?[...t]:[]),u=b.useCallback(()=>{l(h=>[...h,""])},[l]),c=b.useCallback(h=>{l(g=>(g.splice(h,1),[...g]))},[l]),d=b.useMemo(()=>!x.isEqual(o.map(String),t.map(String)),[o,t]),f=()=>{n(o.map(h=>r==="number"?Number(h):h.toString()))};return p(V,{children:[p(s.Group,{position:"left",ref:a,children:[i(s.Text,{children:e}),i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!d,onClick:f,children:i(T.DeviceFloppy,{size:20})})]}),p(s.Group,{children:[o.map((h,g)=>i(s.TextInput,{type:r,value:h,onChange:m=>{const C=m.currentTarget.value;l(w=>(w.splice(g,1,C),[...w]))},rightSection:i(s.ActionIcon,{onClick:()=>c(g),color:"red",children:i(T.Trash,{size:14})}),sx:{width:"45%"}})),i(s.ActionIcon,{onClick:u,color:"blue",variant:"outline",children:i(T.PlaylistAdd,{size:20})})]})]})}const fd=b.forwardRef(hd),us=b.forwardRef(function({value:t,onChange:n},r){const a=t.color.type,o=(l,u)=>{const c=x.cloneDeep(t);x.set(c,l,u),n(c)};return p(V,{children:[i(s.Divider,{my:"xs",label:"Typography",labelPosition:"center"}),i(s.Stack,{children:i(s.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},value:t.size,onChange:l=>o("size",l.currentTarget.value)})}),i(s.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:i(ls,{label:"Font Weight",value:t.weight,onChange:l=>o("weight",l)})}),i(s.Divider,{my:"xs",label:"Style",labelPosition:"center"}),p(s.Stack,{children:[i(s.Select,{label:"Color Type",data:[{label:"Static Color",value:"static"},{label:"Continuous Color",value:"continuous"}],value:t.color.type,onChange:l=>o("color.type",l)}),a==="static"&&i(Pe,{value:t.color.staticColor,onChange:l=>o("color.staticColor",l)}),a==="continuous"&&p(V,{children:[i(fd,{label:"Value Range",value:t.color.valueRange,type:"number",onChange:l=>o("color.valueRange",l)}),i(cd,{label:"Color Range",value:t.color.colorRange,onChange:l=>o("color.colorRange",l)})]})]})]})});b.forwardRef(function({value:t,onChange:n,withStyle:r=!0},a){const o=(l,u)=>{const c=x.cloneDeep(t);x.set(c,l,u),n(c)};return p(s.Box,{px:"sm",py:"md",ref:a,children:[i(s.Text,{weight:"bold",pb:0,children:t.name}),i(s.Divider,{my:"xs",label:"Data",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.TextInput,{label:"Name",required:!0,value:t.name,onChange:l=>o("name",l.currentTarget.value)}),i(R,{label:"Data Field",required:!0,value:t.data_field,onChange:l=>o("data_field",l)})]}),i(_n,{label:"Aggregation",value:t.aggregation,onChange:l=>o("aggregation",l)}),i(s.Divider,{my:"xs",label:"Format",labelPosition:"center"}),i(je,{value:t.formatter,onChange:l=>o("formatter",l)}),r&&i(us,{value:t,onChange:n})]})});const Bt={type:"none",config:{}};function gd(e){const t=Array.from(e).sort((r,a)=>r-a),n=Math.floor(t.length/2);return t.length%2===0?(t[n-1]+t[n])/2:t[n]}function md(e){const t=Number(e);return isFinite(t)?t:0}function yd(e,t){switch(t.type){case"sum":return x.sum(e);case"mean":return x.mean(e);case"median":return gd(e);case"max":return x.max(e)??0;case"min":return x.min(e)??0;case"quantile":return Qt.quantile(e,t.config.p)??0;case"CV":const n=yn.std(...e),r=yn.mean(...e);return r?n/r:"N/A";case"std":return yn.std(...e);default:return e}}function Mr(e,t){const n=e.map(md);return yd(n,t)}function Tn(e,t,n){try{return Mr(ut(e,t),n)}catch(r){return console.error(r),null}}class bd{constructor({valueRange:t,colorRange:n}){N(this,"mapper");this.mapper=kt.interpolate(t,n)}getColor(t){return this.mapper(t)}}function vd(e){return e===null?"null":e===void 0?"undefined":Array.isArray(e)?`Array(${e.length})`:e.toString()}function vt({data_field:e,aggregation:t},n){return Tn(n,e,t)}function tt({formatter:e},t){if(!["string","number"].includes(typeof t))return vd(t);try{return H(t).format(e)}catch(n){return console.error(n),t}}function xd(e,t){if(e.type==="static")return e.staticColor;if(e.type==="continuous")try{if(typeof t!="number")throw new Error(`[getColorByColorConf] Invalid type of aggregated value: ${t}`);return new bd(e).getColor(t)}catch(n){return console.error(n),"black"}return"black"}function cs(e,t){const{color:n,data_field:r,aggregation:a,size:o,weight:l}=e,u=Tn(t,r,a),c=tt(e,u);return i(s.Text,{sx:{fontSize:o,display:"inline"},color:xd(n,u),weight:l,children:c})}function wd(e,t){const n={};return e.forEach(r=>{const a=r.name;n[a]=cs(r,t)}),n}function Cd(e){return e.split(" ").map((t,n)=>p(b.Fragment,{children:[t," "]},n))}function Sd(e){const n=e.replaceAll("<br />","<br/>").replaceAll(`
101
+ `,"<br/>").split("<br/>");return n.map((a,o)=>{const l=[Cd(a)];return o!==n.length-1&&l.push(i("br",{},`br-${o}`)),l}).flat().filter(a=>a!==void 0)}function Ir(e){return Sd(e)}function Zt(e,t,n){const r=wd(t,n),a=/^\{(.+)\}(.*)$/;return e.split("$").map((o,l)=>{const u=a.exec(o);if(!u)return Ir(o);const c=r[u[1]];if(!c)return Ir(o);const d=u[2]??"";return p(b.Fragment,{children:[c,Ir(d)]},`${o}-${l}`)})}function _d(e,t){const n={};return e.forEach(r=>{const{name:a,data_field:o,aggregation:l}=r,u=Tn(t,o,l);n[a]=tt(r,u)}),n}function Dn(e,t,n){const r=_d(t,n),a=/^\{(.+)\}(.*)$/;return e.split("$").map(o=>{const l=a.exec(o);if(!l)return o;const u=r[l[1]];if(!u)return o;const c=l[2]??"";return`${u}${c}`}).join("")}function kd(e,t,n){const r=t.reduce((a,o)=>{const l=vt(o,n);return a[o.name]=tt(o,l),a},{});return e.map(a=>({name:"refs",type:"scatter",data:[],markLine:{data:[{name:a.name,yAxis:Number(r[a.variable_key])}],silent:!0,symbol:["none","none"],label:{formatter:function(){return Dn(a.template,t,n)},position:"insideEndTop"}}}))}function Td({config:e,data:t,variables:n}){const{x_axis:r,y_axis:a,reference_lines:o}=e,l=Zc(e,t),u=ct(r.axisLabel.overflow.on_axis),c=ed(e);return{grid:{top:30,left:20,right:15,bottom:25,containLabel:!0},dataset:l,legend:Hc({config:e}),tooltip:sd({config:e}),xAxis:[{type:"category",name:r.name,nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold",align:"center"},axisTick:{show:!0,alignWithLabel:!0},axisLabel:{...r.axisLabel,...u,formatter:Pt(r.axisLabel.formatter)}}],yAxis:[{name:a.name,nameTextStyle:{fontWeight:"bold"},axisLine:{show:!0},axisLabel:{formatter:function(d){return H(d).format(a.label_formatter)}}}],series:[...c,...kd(o,n,t)]}}oe.use([G.DataZoomComponent,pe.BoxplotChart,G.MarkLineComponent,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function Dd({context:e,instance:t}){const{value:n}=W(e.instanceData,"config"),{variables:r}=e,a=e.data,{width:o,height:l}=e.viewport,u=x.defaults({},n,_r),c=et({vizManager:e.vizManager,instance:t}),d=He(c.triggerManager,as.id),f=bt(a,u.x_axis.data_key),h=b.useCallback(C=>{const w=x.get(f,C.name,{error:"rowData is not found"});d.forEach(_=>{c.runInteraction(_.id,{...C,rowData:w})})},[f,d,c]),g=b.useMemo(()=>({click:h}),[h]),m=b.useMemo(()=>Td({config:u,data:a,variables:r}),[u,a,r]);return!n||!o||!l?null:i(s.Box,{sx:{width:o,height:l,overflow:"hidden"},children:i(Ne,{echarts:oe,option:m,style:{width:o,height:l},onEvents:g,notMerge:!0,theme:"merico-light"})})}function Md({control:e,index:t,remove:n,variableOptions:r}){return p(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:a})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:a})=>i(s.Select,{label:"Value",required:!0,data:r,sx:{flex:1},...a})})]}),i(v.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:a})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",required:!0,sx:{flex:1},...a})}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(t),sx:{position:"absolute",top:15,right:5},children:i(T.Trash,{size:16})})]},t)}function Id({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=r.map((f,h)=>({...f,...l[h]})),c=()=>a({name:"",template:"",variable_key:""}),d=b.useMemo(()=>n.map(f=>({label:f.name,value:f.name})),[n]);return p(s.Stack,{children:[u.map((f,h)=>i(Md,{control:e,index:h,remove:o,variableOptions:d},f.id)),i(s.Group,{position:"center",mt:"xs",children:i(s.Button,{onClick:c,children:"Add a Reference Line"})})]})}const Ed=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Ae,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},Mn=b.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=X.useBoolean(),[l,u]=b.useState(e);b.useEffect(()=>{u(e)},[e]);const c=m=>{u({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:C}=l,w={enabled:m,func_content:C};u(w),t(w)},f=()=>{o(),u(e)},h=m=>{u(C=>({...C,func_content:m}))},g=()=>{h(rt.func_content)};return p(V,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Customize Label"}),i(s.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>c(m.currentTarget.checked)}),i(Ed,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(T.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})}),Ad=({control:e,watch:t})=>(t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(R,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>i(Mn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>i(mt,{...n})})]})),zd=({control:e,watch:t})=>(t(["y_axis"]),p(V,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Y Axis Name",sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>i(R,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:"y_axis.label_formatter",control:e,render:({field:n})=>i(je,{...n})})]})]})),$d=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>i(R,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),Ld=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,f]=b.useState(()=>c??null);return b.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(V,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(T.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Set additional metrics to show in scatter's tooltip"})]}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(T.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i($d,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function Od({control:e,watch:t}){return i(s.Stack,{children:i(Ld,{control:e,watch:t})})}function Pd({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),{variables:r}=e,a=b.useMemo(()=>x.defaults({},t,_r),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});b.useEffect(()=>{d(a)},[a]),u(["x_axis","y_axis","reference_lines","color"]);const f=c(),h=b.useMemo(()=>!x.isEqual(f,t),[f,t]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(T.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),i(s.Tabs.Tab,{value:"Style",children:"Style"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(Ad,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(zd,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(Od,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Style",children:p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:"color",control:o,render:({field:g})=>i(Pe,{...g})})]})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(Id,{variables:r,control:o,watch:u})})]})]})})}function Bd(e){return x.omit(e,"variables")}function Vd(e){const{label_formatter:t=$e,...n}=e.y_axis;return{...e,y_axis:{...n,label_formatter:t}}}function Nd(e){const t={rotate:0,formatter:{...rt}},{axisLabel:n=t,...r}=e.x_axis;return{...e,x_axis:{...r,axisLabel:n}}}function qd(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(t,e)}function Fd(e){delete e.config;const{x_axis:t,tooltip:n}=e.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:n}}}};return x.defaultsDeep(r,e)}function Gd(e){const t={tooltip:{metrics:[]}};return x.defaultsDeep(t,e)}function Wd(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,y_axis:o,tooltip:l,...u}=e;return{...u,x_axis:{...a,data_key:r(a.data_key)},y_axis:{...o,data_key:r(o.data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:r(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}class Rd extends be{constructor(){super(...arguments);N(this,"VERSION",8)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,{panelModel:r})=>{const{config:a}=n;return(a.variables||[]).forEach(l=>{r.variables.find(u=>u.name===l.name)||r.addVariable(l)}),{...n,version:2,config:Bd(a)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:Vd(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:Nd(r)}}),this.version(5,n=>{const{config:r}=n;return{...n,version:5,config:qd(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:Fd(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:Gd(r)}}),this.version(8,(n,r)=>{const{config:a}=n;return{...n,version:8,config:Wd(a,r)}})}}const jd={displayName:"Boxplot Chart",displayGroup:"ECharts-based charts",migrator:new Rd,name:"boxplot",viewRender:Dd,configRender:Pd,createConfig(){return{version:8,config:x.cloneDeep(_r)}},triggers:[as]},ds={id:"builtin:button:click-button",displayName:"Click Button",nameRender:Qd,configRender:Yd,payload:[]};function Yd(e){return i(V,{})}function Qd(e){return i(s.Text,{children:"Click this button"})}const Er={content:"Button",variant:"filled",color:"blue",size:"xs",compact:!1,horizontal_align:"left",vertical_align:"center"},Kd={left:"flex-start",center:"center",right:"flex-end"},Ud={top:"flex-start",center:"center",bottom:"flex-end"},Xd=k.observer(({context:e,instance:t})=>{const n=et({vizManager:e.vizManager,instance:t}),r=He(n.triggerManager,ds.id),a=Me(),{value:o}=W(e.instanceData,"config"),l=b.useMemo(()=>x.defaultsDeep({},o,Er),[o]),{content:u,horizontal_align:c,vertical_align:d,...f}=l,{width:h,height:g}=e.viewport,m=a.payloadForSQL,C=()=>{r.forEach(w=>{n.runInteraction(w.id,{})})};return i(s.Center,{sx:{width:h,height:g,justifyContent:Kd[c],alignItems:Ud[d]},children:i(s.Button,{...f,onClick:C,children:x.template(u)(m)})})}),Jd=({value:e,onChange:t,label:n})=>{const r=s.useMantineTheme(),a=b.useCallback(l=>()=>t(l),[t]),o=l=>e===l;return p(s.Stack,{spacing:2,children:[i(s.Text,{size:14,sx:{fontWeight:500},children:n}),i(s.Group,{position:"left",spacing:"xs",children:Object.keys(r.colors).map(l=>{const u=r.colors[l][6];return i(s.ColorSwatch,{color:u,onClick:a(l),radius:4,size:26,sx:{cursor:"pointer"},children:o(l)&&i(s.CheckIcon,{width:10,color:"white"})},l)})})]})},Zd=s.MANTINE_SIZES.map(e=>({label:e.toUpperCase(),value:e})),Hd=({label:e,value:t,onChange:n})=>i(s.Select,{data:Zd,label:e,value:t,onChange:n}),ep=[{label:"Filled",value:"filled"},{label:"Outline",value:"outline"},{label:"Light",value:"light"},{label:"White",value:"white"},{label:"Default",value:"default"},{label:"Subtle",value:"subtle"},{label:"Gradient",value:"gradient",disabled:!0}],tp=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],np=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function rp({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),r=b.useMemo(()=>x.defaultsDeep({},t,Er),[t]),a=r;b.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});b.useEffect(()=>{d(a)},[a]);const f=c(),h=b.useMemo(()=>!x.isEqual(f,r),[f,r]);return u(["content","variant","color","size","compact","horizontal_align","vertical_align"]),p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(T.DeviceFloppy,{size:20})})]}),p(s.Stack,{children:[i(v.Controller,{control:o,name:"content",render:({field:g})=>i(s.TextInput,{label:"Content Template",description:"Filter values & context entries are supported",...g,required:!0})}),i(s.Divider,{mt:"xs",mb:0,label:"Styles",labelPosition:"center",variant:"dashed"}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"variant",render:({field:g})=>i(s.Select,{label:"Variant",data:ep,...g})}),i(v.Controller,{control:o,name:"color",render:({field:g})=>i(Jd,{label:"Theme",...g})})]}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"size",render:({field:g})=>i(Hd,{label:"Size",...g})}),i(v.Controller,{control:o,name:"compact",render:({field:g})=>i(s.Checkbox,{label:"Compact",checked:g.value,onChange:m=>g.onChange(m.currentTarget.checked),mt:26})})]}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"horizontal_align",render:({field:g})=>i(s.Select,{label:"Horizontal Alignment",data:tp,...g})}),i(v.Controller,{control:o,name:"vertical_align",render:({field:g})=>i(s.Select,{label:"Vertical Alignment",data:np,...g})})]})]})]})}class ip extends be{constructor(){super(...arguments);N(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{horizontal_align:r="left",vertical_align:a="center",...o}=n.config;return{...n,version:2,config:{...o,horizontal_align:r,vertical_align:a}}})}}const ap={displayName:"Button",displayGroup:"Others",migrator:new ip,name:"button",viewRender:Xd,configRender:rp,createConfig(){return{version:2,config:x.cloneDeep(Er)}},triggers:[ds]},Ar={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:op,configRender:sp,payload:[{name:"seriesType",description:"'line' | 'scatter' | 'bar'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function sp(e){return i(V,{})}function op(e){return i(s.Text,{children:"Click chart's series"})}const Vt={x_axis_scroll:!1,y_axis_scroll:!1,x_axis_slider:!1,y_axis_slider:!1},zr={regressions:[],series:[],stats:{templates:{bottom:"",top:""}},x_axis:{type:"category",axisLabel:{rotate:0,formatter:{...rt},overflow:Ze}},x_axis_data_key:"",x_axis_name:"",y_axes:[{min:"",max:"",name:"Y Axis",show:!0,position:"left",nameAlignment:"center",label_formatter:$e}],reference_lines:[],reference_areas:[],dataZoom:Vt};function $r(e){const t=[];return e.x_axis_scroll&&t.push({type:"inside",xAxisIndex:[0],filterMode:"none",minSpan:1}),e.y_axis_scroll&&t.push({type:"inside",yAxisIndex:[0],filterMode:"none",minSpan:1}),e.x_axis_slider&&t.push({type:"slider",xAxisIndex:[0],filterMode:"none",bottom:"auto",top:0,height:15,moveHandleSize:0,showDataShadow:!1,minSpan:1}),t}function lp(e){const t=e.y_axes.some(a=>!!a.name);let n=15;t&&(n+=20),e.dataZoom.x_axis_slider&&(n+=20);let r=5;return e.x_axis_name&&(r+=15),e.series.some(a=>!a.hide_in_legend)&&(r+=20),{top:n,right:15,bottom:r,left:20,containLabel:!0}}function up(e){return e!=="line"?{}:{itemStyle:{opacity:0}}}function cp(e){switch(e){case"line":return;case"bar":return"roundRect";case"scatter":return"circle"}}function dp(e){const t={show:!0,bottom:0,left:"center",type:"scroll"};return t.data=e.filter(n=>!n.hide_in_legend).map(({name:n,type:r})=>({name:n,icon:cp(r),...up(r)})),t}function In(e,t){switch(e.config.method){case"linear":return[...ft.regressionLinear()(t)];case"exponential":return[...ft.regressionExp()(t)];case"logarithmic":return[...ft.regressionLog()(t)];case"polynomial":return[...ft.regressionPoly().order(e.config.order)(t)];default:return[]}}function pp(e,t,n,r){const{transform:a,plot:o}=e,l={...o,name:t,data:In(a,r),showSymbol:!1,tooltip:{show:!1},smooth:!1,custom:{}};return n&&(l.custom={type:"regression-line",targetSeries:n}),l}function hp({regressions:e=[],x_axis_data_key:t},n){const r=[];if(Object.keys(n).length===0)return r;function a(o,l,u,c){const d=pp(o,l,u,c);r.push(d)}return e.forEach(o=>{const{name:l,group_by_key:u}=o;if(!u||u===t){const h=ut(n,o.y_axis_data_key).map((g,m)=>[m,Number(g)]);a(o,l,"",h);return}const{columnKey:c}=q(o.y_axis_data_key),d=x.groupBy(vn(n,o.y_axis_data_key),u);Object.entries(d).forEach(([f,h])=>{const g=h.map((C,w)=>[w,Number(C[c])]);a(o,f,f,g)})}),r}function fp(e,t){return e.map(n=>({name:"",type:"line",hide_in_legend:!0,data:[],markArea:{itemStyle:{color:n.color},data:[[{yAxis:t[n.y_keys.upper]},{yAxis:t[n.y_keys.lower]}]],silent:!0}}))}function gp(e,t,n,r){return e.map(a=>{const o=a.orientation==="horizontal",l=o?"yAxis":"xAxis",u=o?"insideEndTop":"end";return{name:a.name,type:"line",hide_in_legend:!a.show_in_legend,yAxisIndex:a.yAxisIndex,data:[],lineStyle:a.lineStyle,markLine:{data:[{name:a.name,[l]:Number(n[a.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:a.lineStyle,label:{formatter:function(){return a.template?Dn(a.template,t,r):""},position:u}}}})}function mp({type:e,...t},n,r,a){if(!e)return 10;if(e==="static"){const{size:d}=t;return d}const{func_content:o}=t,{queryID:l,columnKey:u}=q(r),c=x.keyBy(vn(n,l),u);return(d,f)=>{let h;f.name?h=c[f.name]:h=n[f.dataIndex];try{return new Function(`return ${o}`)()({rowData:h,params:f,variables:a},{lodash:x,interpolate:kt.interpolate})}catch(g){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${g.message}`),10}}}function Lr(e,t,n){const r=ut(e,t),a=ut(e,n);return x.zip(r,a)}function yp(e,t,n,r){const a=Lr(t,n,r);return x.unionBy(a,e,0)}function bp({dataTemplate:e,data:t,x_axis_data_key:n,y_axis_data_key:r,valueTypedXAxis:a}){return a?yp(e,t,n,r):ut(t,r)}function vp({dataTemplate:e,data:t,aggregation_on_value:n,x_axis_data_key:r,y_axis_data_key:a,valueTypedXAxis:o}){if(!n||n.type==="none")return bp({dataTemplate:e,data:t,x_axis_data_key:r,y_axis_data_key:a,valueTypedXAxis:o});const l=Lr(t,r,a),u=x.groupBy(l,"0");return e.map(([d])=>{const h=u[d].map(m=>m[1]),g=Mr(h,n);return[d,g]})}function xp({group_by_key:e,data:t,x_axis_data_key:n,y_axis_data_key:r}){const{queryID:a,columnKey:o}=q(e),l=x.groupBy(t[a],o);return Object.entries(l).forEach(([u,c])=>{l[u]=Lr({[a]:c},n,r)}),l}function wp({x_axis_data_key:e,x_axis:t},{y_axis_data_key:n,yAxisIndex:r,label_position:a,name:o,group_by_key:l,aggregation_on_value:u,stack:c,color:d,display_name_on_line:f,symbolSize:h,hide_in_legend:g,...m},C,w,_,D){const E=t.type!=="category",O={label:{show:!!a,position:a,formatter:D[r??"default"]},name:o,xAxisId:"main-x-axis",yAxisIndex:r,stack:c,color:d,symbolSize:mp(h,w,e,_),hide_in_legend:g,labelLayout:{hideOverlap:!0},...m};if(f&&(O.endLabel={show:!0,formatter:o,offset:[-12,12],align:"right"}),!l||l===e)return O.data=vp({dataTemplate:C,data:w,aggregation_on_value:u,x_axis_data_key:e,y_axis_data_key:n,valueTypedXAxis:E}),O;const B=xp({group_by_key:l,data:w,x_axis_data_key:e,y_axis_data_key:n});return Object.entries(B).map(([$,A])=>{const I=x.cloneDeep(O);return I.name=$,I.color=void 0,I.data=A,I})}function Cp(e,t,n,r,a,o){const l=t.map(c=>[c,0]);return e.series.map(c=>wp(e,c,l,n,o,r)).flat().concat(gp(e.reference_lines,a,o,n)).concat(fp(e.reference_areas,o))}function Sp(e,t){const n=e.find(o=>o.axisDim==="x"&&o.axisId==="main-x-axis");if(!n)return"";const{axisValue:r,axisIndex:a}=n;return Pt(t.x_axis.axisLabel.formatter)(r,a)}function _p(e,t,n){const r=t.reduce((a,{yAxisIndex:o,name:l})=>(a[l]=o,a),{});return{trigger:"axis",confine:!0,formatter:function(a){const o=Array.isArray(a)?a:[a];if(o.length===0)return"";const l=o.map(({seriesName:d,marker:f,value:h})=>{if(Array.isArray(h)&&h.length===2&&(h=h[1]),!d)return h;const g=r[d],m=n[g]??n.default;return`
167
102
  <tr>
168
103
  <td>${f}</td>
169
104
  <th style="text-align: right; padding: 0 1em;">${d}</th>
170
105
  <td style="text-align: left; padding: 0 1em;">${m({value:h})}</td>
171
106
  </tr>
172
- `}),u=mt(t.x_axis.axisLabel.overflow.in_tooltip),c=hp(o,t);return`
107
+ `}),u=yt(e.x_axis.axisLabel.overflow.in_tooltip),c=Sp(o,e);return`
173
108
  <div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
174
109
  <div style="${u}">${c}</div>
175
110
  </div>
@@ -178,8 +113,8 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
178
113
  ${l.join("")}
179
114
  </tbody>
180
115
  </table>
181
- `}}}function gp(t){return t.y_axes.reduce((n,{label_formatter:r},a)=>(n[a]=function(l){let u=l;if(typeof l=="object"&&(Array.isArray(l.value)&&l.value.length===2?u=l.value[1]:u=l.value),!r)return u;try{return ee(u).format(r)}catch(c){return console.error(c),u}},n),{default:({value:n})=>n})}function Is(t,e){const n={};return e.map(r=>{const a=yt(r,t);n[r.name]=et(r,a)}),n}function mp(t,e){const{overflow:n,...r}=t.x_axis.axisLabel,a=ut(n.on_axis);return[{data:e,name:t.x_axis_name??"",id:"main-x-axis",axisTick:{show:!0,alignWithLabel:!0},type:t.x_axis.type,axisLabel:{...r,...a,formatter:Ot(r.formatter)}}]}function yp(t,e){return t.y_axes.map(({nameAlignment:n,min:r,max:a,show:o,...l},u)=>{let c=l.position;return c||(c=u>0?"right":"left"),{...l,show:o,min:r||void 0,max:a||void 0,position:c,axisLabel:{show:o,formatter:e[u]??e.default},axisLine:{show:o},nameTextStyle:{fontWeight:"bold",align:n},nameLocation:"end",nameGap:o?15:0,splitLine:{show:!1}}})}const bp={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}]};function vp(t,e,n){const r=Is(e,n),a=gp(t),o=x.uniq(lt(e,t.x_axis_data_key)),l=pp(t,o,e,a,n,r),u=rp(t,e),c={xAxis:mp(t,o),yAxis:yp(t,a),series:[...l,...u],tooltip:fp(t,l,a),grid:Zd(t),legend:tp(l),dataZoom:Ar(t.dataZoom)};return x.defaultsDeep({},c,bp)}function Es(t){const e=t.getModel(),n=e.getSeries().map(r=>{if(!r.option.custom)return r.option;const a=e.getColorFromPalette(r.option.custom.targetSeries,null);return r.option.color=a,r.option});t.setOption({...t.getOption(),series:n})}le.use([G.DataZoomComponent,pe.BarChart,pe.LineChart,pe.ScatterChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer,G.MarkLineComponent,G.MarkAreaComponent]);function As(t){return t.trim().length>0}function xp({conf:t,data:e,width:n,height:r,interactionManager:a,variables:o}){const l=bt(e,t.x_axis_data_key),u=He(a.triggerManager,Ir.id),c=y.useCallback(m=>{const w=x.get(l,m.name,{error:"rowData is not found"});u.forEach(C=>{a.runInteraction(C.id,{...m,rowData:w})})},[l,u,a]),d=y.useMemo(()=>vp(t,e,o),[t,e]),f=y.useRef(),h=y.useMemo(()=>({click:c}),[c]),g=m=>{f.current=m,Es(m)};return y.useEffect(()=>{f.current&&Es(f.current)},[d]),!n||!r?null:i(Ne,{echarts:le,option:d,style:{width:n,height:r},onEvents:h,onChartReady:g,notMerge:!0,theme:"merico-light"})}function wp({context:t,instance:e}){const n=tt({vizManager:t.vizManager,instance:e}),{value:r}=W(t.instanceData,"config"),{variables:a}=t,o=y.useMemo(()=>x.defaults({},r,Er),[r]),l=t.data,{width:u,height:c}=t.viewport,{ref:d,height:f}=Me.useElementSize(),{ref:h,height:g}=Me.useElementSize(),m=y.useMemo(()=>{const{stats:{templates:C}}=o;return{top:Jt(C.top,a,l),bottom:Jt(C.bottom,a,l)}},[o,l]),w=Math.max(0,c-f-g);return p(s.Box,{sx:{width:u,height:c,overflow:"hidden"},children:[i(s.Text,{ref:d,align:"left",size:"xs",pl:"sm",sx:{display:As(o.stats.templates.top)?"block":"none"},children:Object.values(m.top).map((C,_)=>i(y.Fragment,{children:C},_))}),i(xp,{variables:a,width:u,height:w,data:l,conf:o,interactionManager:n}),i(s.Text,{ref:h,align:"left",size:"xs",pl:"sm",sx:{display:As(o.stats.templates.bottom)?"block":"none"},children:Object.values(m.bottom).map((C,_)=>i(y.Fragment,{children:C},_))})]})}const $r=y.forwardRef(({value:t,onChange:e},n)=>{const r=a=>o=>{e({...t,[a]:o})};return p(s.Stack,{children:[i(s.Divider,{variant:"dashed",label:"Scroll to Zoom",labelPosition:"center"}),p(s.Group,{children:[i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Enable on X Axis",checked:t.x_axis_scroll,onChange:a=>r("x_axis_scroll")(a.currentTarget.checked)})}),i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Enable on Y Axis",checked:t.y_axis_scroll,onChange:a=>r("y_axis_scroll")(a.currentTarget.checked)})})]}),i(s.Divider,{variant:"dashed",label:"Slider for Zooming",labelPosition:"center"}),p(s.Group,{children:[i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Slider for X Axis",checked:t.x_axis_slider,onChange:a=>r("x_axis_slider")(a.currentTarget.checked)})}),i(s.Tooltip,{label:"Not available for now, will overlap y-axis's label",children:i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Slider for Y Axis",disabled:!t.y_axis_slider,checked:t.y_axis_slider,onChange:a=>r("y_axis_slider")(a.currentTarget.checked)})})})]})]})}),Cp=[{label:"Rectangle",value:"rectangle"}],Sp=[{label:"Horizontal",value:"horizontal"}];function _p({control:t,index:e,remove:n,variableOptions:r}){return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_areas.${e}.name`,control:t,render:({field:a})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${e}.color`,control:t,render:({field:a})=>i(s.TextInput,{label:"Color",required:!0,sx:{flex:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_areas.${e}.type`,control:t,render:({field:a})=>i(s.Select,{label:"Type",required:!0,data:Cp,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${e}.direction`,control:t,render:({field:a})=>i(s.Select,{label:"Direction",required:!0,data:Sp,sx:{flex:1},...a})})]}),i(s.Divider,{variant:"dashed",label:"Data",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_areas.${e}.y_keys.upper`,control:t,render:({field:a})=>i(s.Select,{label:"Upper Boundary",required:!0,data:r,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${e}.y_keys.lower`,control:t,render:({field:a})=>i(s.Select,{label:"Lower Boundary",required:!0,data:r,sx:{flex:1},...a})})]}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Reference Area"})]},e)}function kp({control:t,watch:e,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_areas"}),l=e("reference_areas"),u=r.map((f,h)=>({...f,...l[h]})),c=()=>a({name:"",color:"rgba(0,0,0,0.1)",type:"rectangle",direction:"horizontal",y_keys:{upper:"",lower:""}}),d=y.useMemo(()=>n.map(f=>({label:f.name,value:f.name})),[n]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"6px 0px 0px"}},children:[p(s.Tabs.List,{children:[u.map((f,h)=>i(s.Tabs.Tab,{value:h.toString(),children:h+1},h)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),u.map((f,h)=>i(s.Tabs.Panel,{value:h.toString(),children:i(_p,{control:t,index:h,remove:o,variableOptions:d})},h))]})}const Tp=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Dp=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Mp({control:t,index:e,remove:n,watch:r,variableOptions:a,yAxisOptions:o}){const l=r(`reference_lines.${e}.orientation`);return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${e}.name`,control:t,render:({field:u})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),i(v.Controller,{name:`reference_lines.${e}.variable_key`,control:t,render:({field:u})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),i(v.Controller,{name:`reference_lines.${e}.template`,control:t,render:({field:u})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),p(s.Group,{grow:!0,children:[p(s.Stack,{children:[i(v.Controller,{name:`reference_lines.${e}.orientation`,control:t,render:({field:u})=>i(s.Select,{label:"Orientation",data:Dp,required:!0,sx:{flex:1},...u})}),l==="vertical"&&i(s.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&i(v.Controller,{name:`reference_lines.${e}.yAxisIndex`,control:t,render:({field:{value:u,onChange:c,...d}})=>i(s.Select,{label:"Y Axis",data:o,disabled:o.length===0,...d,value:(u==null?void 0:u.toString())??"",onChange:f=>{if(!f){c(0);return}c(Number(f))},sx:{flex:1}})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`reference_lines.${e}.lineStyle.type`,control:t,render:({field:u})=>i(s.Select,{label:"Line Type",data:Tp,sx:{flexGrow:1},...u})}),i(v.Controller,{name:`reference_lines.${e}.lineStyle.width`,control:t,render:({field:u})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`reference_lines.${e}.lineStyle.color`,control:t,render:({field:u})=>i(Pe,{...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`reference_lines.${e}.show_in_legend`,control:t,render:({field:u})=>i(s.Checkbox,{label:"Show in legend",checked:u.value,onChange:c=>u.onChange(c.currentTarget.checked)})}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Reference Line"})]},e)}function Ip({control:t,watch:e,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_lines"}),l=e("reference_lines"),u=r.map((g,m)=>({...g,...l[m]})),c=()=>{a({name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,yAxisIndex:0})},d=y.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=e("y_axes"),h=y.useMemo(()=>f.map(({name:g},m)=>({label:g,value:m.toString()})),[f]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((g,m)=>i(s.Tabs.Tab,{value:m.toString(),children:m+1},m)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),u.map((g,m)=>i(s.Tabs.Panel,{value:m.toString(),children:i(Mp,{control:t,index:m,remove:o,watch:e,variableOptions:d,yAxisOptions:h})},m))]})}const Ep=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}],Ap=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function zp({control:t,regressionItem:e,index:n,remove:r,yAxisOptions:a}){const o=e.transform.config.method;return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:`regressions.${n}.name`,control:t,render:({field:l})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`regressions.${n}.group_by_key`,control:t,render:({field:l})=>i(j,{label:"Split into multiple regression lines by this key...",clearable:!0,sx:{flex:1},...l})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`regressions.${n}.y_axis_data_key`,control:t,render:({field:l})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`regressions.${n}.plot.yAxisIndex`,control:t,render:({field:{value:l,onChange:u,...c}})=>i(s.Select,{label:"Y Axis",data:a,disabled:a.length===0,...c,value:(l==null?void 0:l.toString())??"",onChange:d=>{if(!d){u(0);return}u(Number(d))},sx:{flex:1}})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`regressions.${n}.transform.config.method`,control:t,render:({field:l})=>i(s.Select,{label:"Method",data:Ep,sx:{flex:1},...l})}),o==="polynomial"&&i(v.Controller,{name:`regressions.${n}.transform.config.order`,control:t,render:({field:l})=>i(s.NumberInput,{label:"Order",sx:{flex:1},...l})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Line Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`regressions.${n}.plot.lineStyle.type`,control:t,render:({field:l})=>i(s.Select,{label:"Line Type",data:Ap,sx:{flexGrow:1},...l})}),i(v.Controller,{name:`regressions.${n}.plot.lineStyle.width`,control:t,render:({field:l})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...l})})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`regressions.${n}.plot.color`,control:t,render:({field:l})=>i(Pe,{...l})})]}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(n),sx:{top:15,right:5},children:"Delete this Regression Line"})]},n)}function $p({control:t,watch:e}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"regressions"}),o=e("regressions"),l=n.map((f,h)=>({...f,...o[h]})),u=e("y_axes"),c=y.useMemo(()=>u.map(({name:f},h)=>({label:f,value:h.toString()})),[u]),d=()=>r({transform:{type:"ecStat:regression",config:{method:"linear",order:1,formulaOn:"end"}},group_by_key:"",name:"",y_axis_data_key:"",plot:{type:"line",yAxisIndex:0,color:"#666666",lineStyle:{type:"solid",width:1}}});return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((f,h)=>i(s.Tabs.Tab,{value:h.toString(),children:h+1},h)),i(s.Tabs.Tab,{onClick:d,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((f,h)=>i(s.Tabs.Panel,{value:h.toString(),children:i(zp,{regressionItem:f,control:t,index:h,remove:a,yAxisOptions:c},h)},h))]})}const Lr={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
182
- `)}},Lp=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function Op({control:t,index:e,seriesItem:n}){const r=!!n.barWidth.trim();return p(V,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.stack`,control:t,render:({field:a})=>i(s.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barGap`,control:t,render:({field:a})=>i(s.Select,{label:"Bar Gap",data:Lp,sx:{flexGrow:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.barMinWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barMaxWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...a})})]})]})}const Pp=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return i(s.Box,{children:i(Ie,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Bp=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:a}]=X.useBoolean(),[o,l]=y.useState(t),u=()=>{a();const{type:h,func_content:g}=o,m={type:h,func_content:g};l(m),e(m)},c=()=>{a(),l(t)},d=h=>{l(g=>({...g,func_content:h}))},f=()=>{d(Lr.dynamic.func_content)};return p(V,{children:[i(s.Box,{sx:{width:"50%"},children:i(s.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),i(s.Modal,{size:800,title:"Setup dynamic size",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),i(Pp,{value:o.func_content,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},Vp=({value:t,onChange:e})=>t.type!=="dynamic"?null:i(Bp,{value:t,onChange:e}),Np=({value:t,onChange:e})=>{if(t.type!=="static")return null;const n=r=>{e({...t,size:r})};return i(V,{children:i(s.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:t.size,onChange:n})})},qp=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],zs=y.forwardRef(({label:t="Size",value:e,onChange:n},r)=>{const a=o=>{n({...Lr[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:t,data:qp,value:e.type,onChange:a,sx:{flexGrow:1}}),i(Np,{value:e,onChange:n}),i(Vp,{value:e,onChange:n})]})}),Fp=[{label:"off",value:"false"},{label:"start",value:"start"},{label:"middle",value:"middle"},{label:"end",value:"end"}],Gp=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function Wp({control:t,index:e,seriesItem:n}){const r=n.showSymbol;return p(V,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Line Settings",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`series.${e}.lineStyle.type`,control:t,render:({field:a})=>i(s.Select,{label:"Line Type",data:Gp,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.lineStyle.width`,control:t,render:({field:a})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...a})})]}),p(s.Group,{grow:!0,align:"center",children:[i(v.Controller,{name:`series.${e}.step`,control:t,render:({field:a})=>i(s.Select,{label:"Step",data:Fp,sx:{flexGrow:1,maxWidth:"48%"},...a,value:String(a.value),onChange:o=>{const l=o==="false"?!1:o;a.onChange(l)}})}),p(s.Stack,{children:[i(v.Controller,{name:`series.${e}.smooth`,control:t,render:({field:a})=>i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Smooth Line",checked:a.value,onChange:o=>a.onChange(o.currentTarget.checked)})})}),i(v.Controller,{name:`series.${e}.display_name_on_line`,control:t,render:({field:a})=>i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Display Name on Line",checked:a.value??!1,onChange:o=>a.onChange(o.currentTarget.checked)})})})]})]}),p(s.Stack,{children:[i(v.Controller,{name:`series.${e}.showSymbol`,control:t,render:({field:a})=>i(s.Box,{mt:10,mb:-10,sx:{flexGrow:1},children:i(s.Switch,{label:"Show Symbol on Line",checked:a.value,onChange:o=>a.onChange(o.currentTarget.checked)})})}),r&&i(v.Controller,{name:`series.${e}.symbolSize`,control:t,render:({field:a})=>i(zs,{label:"Symbol Size",...a})})]})]})}function jp({control:t,index:e}){return i(v.Controller,{name:`series.${e}.symbolSize`,control:t,render:({field:n})=>i(zs,{label:"Size",...n})})}const Rp=[{label:"off",value:""},{label:"top",value:"top"},{label:"left",value:"left"},{label:"right",value:"right"},{label:"bottom",value:"bottom"},{label:"inside",value:"inside"},{label:"insideLeft",value:"insideLeft"},{label:"insideRight",value:"insideRight"},{label:"insideTop",value:"insideTop"},{label:"insideBottom",value:"insideBottom"},{label:"insideTopLeft",value:"insideTopLeft"},{label:"insideBottomLeft",value:"insideBottomLeft"},{label:"insideTopRight",value:"insideTopRight"},{label:"insideBottomRight",value:"insideBottomRight"}];function Yp({control:t,index:e,remove:n,seriesItem:r,yAxisOptions:a}){const o=r.type;return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[i(s.Stack,{children:i(v.Controller,{name:`series.${e}.type`,control:t,render:({field:l})=>i(s.SegmentedControl,{data:[{label:"Line",value:"line"},{label:"Bar",value:"bar"},{label:"Scatter",value:"scatter"}],...l})})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.name`,control:t,render:({field:l})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`series.${e}.yAxisIndex`,control:t,render:({field:{value:l,onChange:u,...c}})=>i(s.Select,{label:"Y Axis",data:a,disabled:a.length===0,...c,value:(l==null?void 0:l.toString())??"",onChange:d=>{if(!d){u(0);return}u(Number(d))},sx:{flex:1}})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.y_axis_data_key`,control:t,render:({field:l})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`series.${e}.aggregation_on_value`,control:t,render:({field:l})=>i(Sn,{label:"Aggregation on Value",value:l.value??Pt,onChange:l.onChange,pt:0})})]}),i(s.Group,{grow:!0,children:i(v.Controller,{name:`series.${e}.group_by_key`,control:t,render:({field:l})=>i(j,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...l})})}),o==="line"&&i(Wp,{index:e,control:t,seriesItem:r}),o==="bar"&&i(Op,{index:e,control:t,seriesItem:r}),o==="scatter"&&i(jp,{index:e,control:t}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),i(v.Controller,{name:`series.${e}.label_position`,control:t,render:({field:l})=>i(s.Select,{label:"Label Position",data:Rp,...l})}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`series.${e}.color`,control:t,render:({field:l})=>i(Pe,{...l})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`series.${e}.hide_in_legend`,control:t,render:({field:l})=>i(s.Checkbox,{label:"Hide in legend",checked:l.value,onChange:u=>l.onChange(u.currentTarget.checked)})}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Series"})]},e)}function Qp({control:t,watch:e}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"series"}),o=e("series"),l=n.map((f,h)=>({...f,...o[h]})),u=()=>{const f={type:"bar",name:Me.randomId(),showSymbol:!1,symbolSize:Lr.static,y_axis_data_key:"value",yAxisIndex:0,label_position:"top",display_name_on_line:!1,stack:"",color:"#000",step:!1,smooth:!1,barMinWidth:"1",barWidth:"10%",barMaxWidth:"10",barGap:"0%",lineStyle:{type:"solid",width:1},hide_in_legend:!1,group_by_key:""};r(f)},c=e("y_axes"),d=y.useMemo(()=>c.map(({name:f},h)=>({label:f,value:h.toString()})),[c]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((f,h)=>i(s.Tabs.Tab,{value:h.toString(),children:h+1},f.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((f,h)=>i(s.Tabs.Panel,{value:h.toString(),children:i(Yp,{control:t,index:h,remove:a,seriesItem:f,yAxisOptions:d},f.id)},f.id))]})}function Kp({control:t,watch:e}){return e("stats"),i(s.Stack,{children:p(s.Stack,{spacing:0,children:[i(v.Controller,{name:"stats.templates.top",control:t,render:({field:n})=>i(Xt,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),i(v.Controller,{name:"stats.templates.bottom",control:t,render:({field:n})=>i(Xt,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const Up=()=>p(s.Group,{sx:{display:"inline-flex"},spacing:6,mr:14,children:[i(s.Text,{children:"X Axis Data Type"}),p(s.HoverCard,{width:340,shadow:"md",position:"top",children:[i(s.HoverCard.Target,{children:i(s.ActionIcon,{size:"xs",sx:{transform:"none !important"},children:i(L.IconInfoCircle,{})})}),i(s.HoverCard.Dropdown,{children:p(s.Text,{size:"sm",children:["Click",i(s.Anchor,{href:"https://echarts.apache.org/en/option.html#xAxis.type",target:"_blank",mx:4,children:"here"}),"to learn more about these options"]})})]})]}),Xp=[{label:"Value",value:"value"},{label:"Category",value:"category"},{label:"Time",value:"time"},{label:"Log",value:"log"}];function Jp({control:t,watch:e}){return e(["x_axis_data_key","x_axis_name","x_axis"]),p(s.Stack,{children:[i(v.Controller,{name:"x_axis_name",control:t,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis_data_key",control:t,render:({field:n})=>i(j,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.type",control:t,render:({field:n})=>i(s.Select,{label:i(Up,{}),required:!0,data:Xp,sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Dn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})})]})}const Zp=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],Hp=[{label:"left",value:"left"},{label:"right",value:"right"}];function eh({control:t,index:e,remove:n}){return p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[i(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`y_axes.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`y_axes.${e}.nameAlignment`,control:t,render:({field:r})=>i(s.Select,{label:"Align",required:!0,data:Zp,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`y_axes.${e}.position`,control:t,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:Hp,sx:{flex:1},...r})})}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:`y_axes.${e}.label_formatter`,control:t,render:({field:r})=>i(Re,{...r})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`y_axes.${e}.min`,control:t,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`y_axes.${e}.max`,control:t,render:({field:r})=>i(s.TextInput,{label:"Max",...r})})]})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`y_axes.${e}.show`,control:t,render:({field:r})=>i(s.Checkbox,{label:"Visible",checked:r.value,onChange:a=>r.onChange(a.currentTarget.checked)})}),i(s.Button,{mt:20,leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),disabled:e===0,children:"Delete this YAxis"})]})}function th({control:t,watch:e}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"y_axes"}),o=e("y_axes"),l=n.map((c,d)=>({...c,...o[d]})),u=()=>r({name:"",position:"left",nameAlignment:"left",label_formatter:$e,min:"",max:"",show:!0});return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map((c,d)=>i(s.Tabs.Tab,{value:d.toString(),children:d+1},d)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(eh,{control:t,index:d,remove:a})},d))]})}function nh({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),{variables:r}=t,a=y.useMemo(()=>x.defaultsDeep({},e,Er),[e]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,a),[f,a]);return u(["dataZoom"]),i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axes",children:"Y Axes"}),i(s.Tabs.Tab,{value:"Series",children:"Series"}),i(s.Tabs.Tab,{value:"Regression Lines",children:"Regression Lines"}),i(s.Tabs.Tab,{value:"Stats",children:"Stats"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),i(s.Tabs.Tab,{value:"Reference Areas",children:"Reference Areas"}),i(s.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(Jp,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axes",children:i(th,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Series",children:i(Qp,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Regression Lines",children:i($p,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Stats",children:i(Kp,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(Ip,{variables:r,control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Areas",children:i(kp,{variables:r,control:o,watch:u})}),i(s.Tabs.Panel,{value:"Zooming",children:i(v.Controller,{name:"dataZoom",control:o,render:({field:g})=>i($r,{...g})})})]})]})})}function rh(t){const e=x.cloneDeep(x.omit(t,"variables"));return e.stats=x.omit(e.stats,"variables"),e}function ih(t){const{rotate:e,formatter:n=nt}=t.x_axis.axisLabel;return{...t,x_axis:{...t.x_axis,axisLabel:{rotate:e,formatter:n}}}}function ah(t){const{dataZoom:e=Bt,...n}=t;return{...n,dataZoom:e}}function sh(t){const e={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(e,t)}function oh(t){const e=t.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:st.random().css()},show_in_legend:a=!1}=n;return{...n,lineStyle:r,show_in_legend:a}});return{...t,reference_lines:e}}function lh(t){const e=t.reference_lines.map(n=>{const{yAxisIndex:r=0}=n;return{...n,yAxisIndex:r}});return{...t,reference_lines:e}}function uh(t){const e=t.series.map(n=>{const{aggregation_on_group:r=Pt}=n;return{...n,aggregation_on_group:r}});return{...t,series:e}}function ch(t){const e=t.series.map(n=>{const{aggregation_on_value:r=Pt}=n;return{...n,aggregation_on_value:r}});return{...t,series:e}}function dh(t){delete t.config;const{x_axis:e,tooltip:n}=t.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:e,in_tooltip:n}}}};return x.defaultsDeep(r,t)}function ph(t){const{series:e,...n}=t;return{...n,series:e.map(r=>{const{barMinWidth:a,barWidth:o,barMaxWidth:l}=r;return a?{...r,barMinWidth:a,barWidth:"",barMaxWidth:l??o}:{...r,barMinWidth:"",barWidth:o,barMaxWidth:""}})}}function hh(t){const{y_axes:e,...n}=t;return{...n,y_axes:e.map(r=>{const{min:a="",max:o=""}=r;return{...r,min:a,max:o}})}}function fh(t){const{y_axes:e,...n}=t;return{...n,y_axes:e.map(r=>{const{nameAlignment:a="left"}=r;return{...r,nameAlignment:a}})}}function gh(t){const{y_axes:e,...n}=t;return{...n,y_axes:e.map(r=>{const{show:a=!0}=r;return{...r,show:a}})}}function mh(t){const{regressions:e,...n}=t;return{...n,regressions:e.map(r=>{const{group_by_key:a=""}=r;return{...r,group_by_key:a}})}}function yh(t){const{series:e,y_axes:n,...r}=t;return{...r,series:e.map(a=>{const{hide_in_legend:o=!1,aggregation_on_value:l=Pt}=a;return{...a,hide_in_legend:o,aggregation_on_value:l}}),y_axes:n.map(a=>{const{min:o="",max:l="",show:u=!0}=a;return{...a,min:o,max:l,show:u}})}}function bh(t){const{type:e="category",...n}=t.x_axis;return{...t,x_axis:{...n,type:e}}}function vh(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis_data_key:a,series:o,regressions:l,...u}=t;return{...u,x_axis_data_key:r(a),series:o.map(c=>({...c,y_axis_data_key:r(c.y_axis_data_key),group_by_key:r(c.group_by_key)})),regressions:l.map(c=>({...c,y_axis_data_key:r(c.y_axis_data_key),group_by_key:r(c.group_by_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class xh extends ve{constructor(){super(...arguments);N(this,"VERSION",18)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,{panelModel:r})=>{const{config:a}=n;return(a.variables||[]).forEach(u=>{r.variables.find(c=>c.name===u.name)||r.addVariable(u)}),(x.get(a,"stats.variables")||[]).forEach(u=>{r.variables.find(c=>c.name===u.name)||r.addVariable(u)}),{...n,version:2,config:rh(a)}}),this.version(3,n=>({...n,version:3,config:ih(n.config)})),this.version(4,n=>({...n,version:4,config:ah(n.config)})),this.version(5,n=>({...n,version:5,config:sh(n.config)})),this.version(6,n=>({...n,version:6,config:oh(n.config)})),this.version(7,n=>({...n,version:7,config:lh(n.config)})),this.version(8,n=>({...n,version:8,config:uh(n.config)})),this.version(9,n=>({...n,version:9,config:ch(n.config)})),this.version(10,n=>({...n,version:10,config:dh(n.config)})),this.version(11,n=>({...n,version:11,config:ph(n.config)})),this.version(12,n=>({...n,version:12,config:hh(n.config)})),this.version(13,n=>({...n,version:13,config:fh(n.config)})),this.version(14,n=>({...n,version:14,config:gh(n.config)})),this.version(15,n=>({...n,version:15,config:mh(n.config)})),this.version(16,n=>({...n,version:16,config:yh(n.config)})),this.version(17,n=>({...n,version:17,config:bh(n.config)})),this.version(18,(n,r)=>({...n,version:18,config:vh(n.config,r)}))}}const wh={displayName:"Cartesian Chart",displayGroup:"ECharts-based charts",migrator:new xh,name:"cartesian",viewRender:wp,configRender:nh,createConfig(){return{version:18,config:x.cloneDeep(Er)}},triggers:[Ir]};function Ch(t){if(t.enable_value)return t.value}function Sh(t){if(t.enable_value)return t.value}function _h(t){const e=t.axisLabel.overflow.on_axis.width,n=t.axisLabel.position,r={top:5,left:5,right:5,bottom:5};return t.orient==="vertical"&&x.get(r,n)&&n===t.funnelAlign&&x.set(r,n,e),r}function kh(t,e){return t.series.map(n=>{const{level_name_data_key:r,level_value_data_key:a,axisLabel:o,min:l,max:u,funnelAlign:c,orient:d,...f}=n;if(!r||!a)return{};const h=q(r),g=q(a),m=e[h.queryID].map(C=>({name:C[h.columnKey],value:C[g.columnKey]})),w=ut(o.overflow.on_axis);return{type:"funnel",..._h(n),min:Ch(l),max:Sh(u),minSize:l.size,maxSize:u.size,...f,label:{show:!0,position:o.position,...w},orient:d,funnelAlign:d==="horizontal"?"center":c,data:m}})}function Th({conf:t,params:e,max:n}){const{name:r,value:a}=e.data,o=ee(a/n).format({output:"percent",mantissa:2,trimMantissa:!0});return[{label:`${e.marker} ${r}`,value:`${a} (${o})`,style:{label:"",value:""}}]}function Dh(t,e){var o;const n=q(t.series[0].level_name_data_key),r=q(t.series[0].level_value_data_key),a=(o=x.maxBy(e[n.queryID],r.columnKey))==null?void 0:o[r.columnKey];return l=>{const c=Th({conf:t,params:l,max:a}).map(f=>`
116
+ `}}}function kp(e){return e.y_axes.reduce((n,{label_formatter:r},a)=>(n[a]=function(l){let u=l;if(typeof l=="object"&&(Array.isArray(l.value)&&l.value.length===2?u=l.value[1]:u=l.value),!r)return u;try{return H(u).format(r)}catch(c){return console.error(c),u}},n),{default:({value:n})=>n})}function ps(e,t){const n={};return t.map(r=>{const a=vt(r,e);n[r.name]=tt(r,a)}),n}function Tp(e,t){const{overflow:n,...r}=e.x_axis.axisLabel,a=ct(n.on_axis);return[{data:t,name:e.x_axis_name??"",id:"main-x-axis",axisTick:{show:!0,alignWithLabel:!0},type:e.x_axis.type,axisLabel:{...r,...a,formatter:Pt(r.formatter)}}]}function Dp(e,t){return e.y_axes.map(({nameAlignment:n,min:r,max:a,show:o,...l},u)=>{let c=l.position;return c||(c=u>0?"right":"left"),{...l,show:o,min:r||void 0,max:a||void 0,position:c,axisLabel:{show:o,formatter:t[u]??t.default},axisLine:{show:o},nameTextStyle:{fontWeight:"bold",align:n},nameLocation:"end",nameGap:o?15:0,splitLine:{show:!1}}})}const Mp={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}]};function Ip(e,t,n){const r=ps(t,n),a=kp(e),o=x.uniq(ut(t,e.x_axis_data_key)),l=Cp(e,o,t,a,n,r),u=hp(e,t),c={xAxis:Tp(e,o),yAxis:Dp(e,a),series:[...l,...u],tooltip:_p(e,l,a),grid:lp(e),legend:dp(l),dataZoom:$r(e.dataZoom)};return x.defaultsDeep({},c,Mp)}function hs(e){const t=e.getModel(),n=t.getSeries().map(r=>{if(!r.option.custom)return r.option;const a=t.getColorFromPalette(r.option.custom.targetSeries,null);return r.option.color=a,r.option});e.setOption({...e.getOption(),series:n})}oe.use([G.DataZoomComponent,pe.BarChart,pe.LineChart,pe.ScatterChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer,G.MarkLineComponent,G.MarkAreaComponent]);function fs(e){return e.trim().length>0}function Ep({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=bt(t,e.x_axis_data_key),u=He(a.triggerManager,Ar.id),c=b.useCallback(m=>{const C=x.get(l,m.name,{error:"rowData is not found"});u.forEach(w=>{a.runInteraction(w.id,{...m,rowData:C})})},[l,u,a]),d=b.useMemo(()=>Ip(e,t,o),[e,t]),f=b.useRef(),h=b.useMemo(()=>({click:c}),[c]),g=m=>{f.current=m,hs(m)};return b.useEffect(()=>{f.current&&hs(f.current)},[d]),!n||!r?null:i(Ne,{echarts:oe,option:d,style:{width:n,height:r},onEvents:h,onChartReady:g,notMerge:!0,theme:"merico-light"})}function Ap({context:e,instance:t}){const n=et({vizManager:e.vizManager,instance:t}),{value:r}=W(e.instanceData,"config"),{variables:a}=e,o=b.useMemo(()=>x.defaults({},r,zr),[r]),l=e.data,{width:u,height:c}=e.viewport,{ref:d,height:f}=Ee.useElementSize(),{ref:h,height:g}=Ee.useElementSize(),m=b.useMemo(()=>{const{stats:{templates:w}}=o;return{top:Zt(w.top,a,l),bottom:Zt(w.bottom,a,l)}},[o,l]),C=Math.max(0,c-f-g);return p(s.Box,{sx:{width:u,height:c,overflow:"hidden"},children:[i(s.Text,{ref:d,align:"left",size:"xs",pl:"sm",sx:{display:fs(o.stats.templates.top)?"block":"none"},children:Object.values(m.top).map((w,_)=>i(b.Fragment,{children:w},_))}),i(Ep,{variables:a,width:u,height:C,data:l,conf:o,interactionManager:n}),i(s.Text,{ref:h,align:"left",size:"xs",pl:"sm",sx:{display:fs(o.stats.templates.bottom)?"block":"none"},children:Object.values(m.bottom).map((w,_)=>i(b.Fragment,{children:w},_))})]})}const Or=b.forwardRef(({value:e,onChange:t},n)=>{const r=a=>o=>{t({...e,[a]:o})};return p(s.Stack,{children:[i(s.Divider,{variant:"dashed",label:"Scroll to Zoom",labelPosition:"center"}),p(s.Group,{children:[i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Enable on X Axis",checked:e.x_axis_scroll,onChange:a=>r("x_axis_scroll")(a.currentTarget.checked)})}),i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Enable on Y Axis",checked:e.y_axis_scroll,onChange:a=>r("y_axis_scroll")(a.currentTarget.checked)})})]}),i(s.Divider,{variant:"dashed",label:"Slider for Zooming",labelPosition:"center"}),p(s.Group,{children:[i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Slider for X Axis",checked:e.x_axis_slider,onChange:a=>r("x_axis_slider")(a.currentTarget.checked)})}),i(s.Tooltip,{label:"Not available for now, will overlap y-axis's label",children:i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Slider for Y Axis",disabled:!e.y_axis_slider,checked:e.y_axis_slider,onChange:a=>r("y_axis_slider")(a.currentTarget.checked)})})})]})]})}),zp=[{label:"Rectangle",value:"rectangle"}],$p=[{label:"Horizontal",value:"horizontal"}];function Lp({control:e,index:t,remove:n,variableOptions:r}){return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_areas.${t}.name`,control:e,render:({field:a})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${t}.color`,control:e,render:({field:a})=>i(s.TextInput,{label:"Color",required:!0,sx:{flex:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_areas.${t}.type`,control:e,render:({field:a})=>i(s.Select,{label:"Type",required:!0,data:zp,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${t}.direction`,control:e,render:({field:a})=>i(s.Select,{label:"Direction",required:!0,data:$p,sx:{flex:1},...a})})]}),i(s.Divider,{variant:"dashed",label:"Data",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_areas.${t}.y_keys.upper`,control:e,render:({field:a})=>i(s.Select,{label:"Upper Boundary",required:!0,data:r,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_areas.${t}.y_keys.lower`,control:e,render:({field:a})=>i(s.Select,{label:"Lower Boundary",required:!0,data:r,sx:{flex:1},...a})})]}),i(s.Button,{leftIcon:i(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Area"})]},t)}function Op({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_areas"}),l=t("reference_areas"),u=r.map((f,h)=>({...f,...l[h]})),c=()=>a({name:"",color:"rgba(0,0,0,0.1)",type:"rectangle",direction:"horizontal",y_keys:{upper:"",lower:""}}),d=b.useMemo(()=>n.map(f=>({label:f.name,value:f.name})),[n]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"6px 0px 0px"}},children:[p(s.Tabs.List,{children:[u.map((f,h)=>i(s.Tabs.Tab,{value:h.toString(),children:h+1},h)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(T.Plus,{size:18,color:"#228be6"})})]}),u.map((f,h)=>i(s.Tabs.Panel,{value:h.toString(),children:i(Lp,{control:e,index:h,remove:o,variableOptions:d})},h))]})}const Pp=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Bp=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Vp({control:e,index:t,remove:n,watch:r,variableOptions:a,yAxisOptions:o}){const l=r(`reference_lines.${t}.orientation`);return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:u})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:u})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),i(v.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:u})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),p(s.Group,{grow:!0,children:[p(s.Stack,{children:[i(v.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:u})=>i(s.Select,{label:"Orientation",data:Bp,required:!0,sx:{flex:1},...u})}),l==="vertical"&&i(s.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&i(v.Controller,{name:`reference_lines.${t}.yAxisIndex`,control:e,render:({field:{value:u,onChange:c,...d}})=>i(s.Select,{label:"Y Axis",data:o,disabled:o.length===0,...d,value:(u==null?void 0:u.toString())??"",onChange:f=>{if(!f){c(0);return}c(Number(f))},sx:{flex:1}})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:u})=>i(s.Select,{label:"Line Type",data:Pp,sx:{flexGrow:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:u})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:u})=>i(Pe,{...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`reference_lines.${t}.show_in_legend`,control:e,render:({field:u})=>i(s.Checkbox,{label:"Show in legend",checked:u.value,onChange:c=>u.onChange(c.currentTarget.checked)})}),i(s.Button,{leftIcon:i(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]},t)}function Np({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=r.map((g,m)=>({...g,...l[m]})),c=()=>{a({name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,yAxisIndex:0})},d=b.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=t("y_axes"),h=b.useMemo(()=>f.map(({name:g},m)=>({label:g,value:m.toString()})),[f]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((g,m)=>i(s.Tabs.Tab,{value:m.toString(),children:m+1},m)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(T.Plus,{size:18,color:"#228be6"})})]}),u.map((g,m)=>i(s.Tabs.Panel,{value:m.toString(),children:i(Vp,{control:e,index:m,remove:o,watch:t,variableOptions:d,yAxisOptions:h})},m))]})}const qp=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}],Fp=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function Gp({control:e,regressionItem:t,index:n,remove:r,yAxisOptions:a}){const o=t.transform.config.method;return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:`regressions.${n}.name`,control:e,render:({field:l})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`regressions.${n}.group_by_key`,control:e,render:({field:l})=>i(R,{label:"Split into multiple regression lines by this key...",clearable:!0,sx:{flex:1},...l})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`regressions.${n}.y_axis_data_key`,control:e,render:({field:l})=>i(R,{label:"Value Field",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`regressions.${n}.plot.yAxisIndex`,control:e,render:({field:{value:l,onChange:u,...c}})=>i(s.Select,{label:"Y Axis",data:a,disabled:a.length===0,...c,value:(l==null?void 0:l.toString())??"",onChange:d=>{if(!d){u(0);return}u(Number(d))},sx:{flex:1}})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`regressions.${n}.transform.config.method`,control:e,render:({field:l})=>i(s.Select,{label:"Method",data:qp,sx:{flex:1},...l})}),o==="polynomial"&&i(v.Controller,{name:`regressions.${n}.transform.config.order`,control:e,render:({field:l})=>i(s.NumberInput,{label:"Order",sx:{flex:1},...l})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Line Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`regressions.${n}.plot.lineStyle.type`,control:e,render:({field:l})=>i(s.Select,{label:"Line Type",data:Fp,sx:{flexGrow:1},...l})}),i(v.Controller,{name:`regressions.${n}.plot.lineStyle.width`,control:e,render:({field:l})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...l})})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`regressions.${n}.plot.color`,control:e,render:({field:l})=>i(Pe,{...l})})]}),i(s.Button,{leftIcon:i(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(n),sx:{top:15,right:5},children:"Delete this Regression Line"})]},n)}function Wp({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"regressions"}),o=t("regressions"),l=n.map((f,h)=>({...f,...o[h]})),u=t("y_axes"),c=b.useMemo(()=>u.map(({name:f},h)=>({label:f,value:h.toString()})),[u]),d=()=>r({transform:{type:"ecStat:regression",config:{method:"linear",order:1,formulaOn:"end"}},group_by_key:"",name:"",y_axis_data_key:"",plot:{type:"line",yAxisIndex:0,color:"#666666",lineStyle:{type:"solid",width:1}}});return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((f,h)=>i(s.Tabs.Tab,{value:h.toString(),children:h+1},h)),i(s.Tabs.Tab,{onClick:d,value:"add",children:i(T.Plus,{size:18,color:"#228be6"})})]}),l.map((f,h)=>i(s.Tabs.Panel,{value:h.toString(),children:i(Gp,{regressionItem:f,control:e,index:h,remove:a,yAxisOptions:c},h)},h))]})}const Pr={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
117
+ `)}},Rp=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function jp({control:e,index:t,seriesItem:n}){const r=!!n.barWidth.trim();return p(V,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.stack`,control:e,render:({field:a})=>i(s.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barGap`,control:e,render:({field:a})=>i(s.Select,{label:"Bar Gap",data:Rp,sx:{flexGrow:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.barMinWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barMaxWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...a})})]})]})}const Yp=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{children:i(Ae,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Qp=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=X.useBoolean(),[o,l]=b.useState(e),u=()=>{a();const{type:h,func_content:g}=o,m={type:h,func_content:g};l(m),t(m)},c=()=>{a(),l(e)},d=h=>{l(g=>({...g,func_content:h}))},f=()=>{d(Pr.dynamic.func_content)};return p(V,{children:[i(s.Box,{sx:{width:"50%"},children:i(s.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),i(s.Modal,{size:800,title:"Setup dynamic size",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),i(Yp,{value:o.func_content,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(T.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},Kp=({value:e,onChange:t})=>e.type!=="dynamic"?null:i(Qp,{value:e,onChange:t}),Up=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,size:r})};return i(V,{children:i(s.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:e.size,onChange:n})})},Xp=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],gs=b.forwardRef(({label:e="Size",value:t,onChange:n},r)=>{const a=o=>{n({...Pr[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:e,data:Xp,value:t.type,onChange:a,sx:{flexGrow:1}}),i(Up,{value:t,onChange:n}),i(Kp,{value:t,onChange:n})]})}),Jp=[{label:"off",value:"false"},{label:"start",value:"start"},{label:"middle",value:"middle"},{label:"end",value:"end"}],Zp=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}];function Hp({control:e,index:t,seriesItem:n}){const r=n.showSymbol;return p(V,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Line Settings",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`series.${t}.lineStyle.type`,control:e,render:({field:a})=>i(s.Select,{label:"Line Type",data:Zp,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.lineStyle.width`,control:e,render:({field:a})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...a})})]}),p(s.Group,{grow:!0,align:"center",children:[i(v.Controller,{name:`series.${t}.step`,control:e,render:({field:a})=>i(s.Select,{label:"Step",data:Jp,sx:{flexGrow:1,maxWidth:"48%"},...a,value:String(a.value),onChange:o=>{const l=o==="false"?!1:o;a.onChange(l)}})}),p(s.Stack,{children:[i(v.Controller,{name:`series.${t}.smooth`,control:e,render:({field:a})=>i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Smooth Line",checked:a.value,onChange:o=>a.onChange(o.currentTarget.checked)})})}),i(v.Controller,{name:`series.${t}.display_name_on_line`,control:e,render:({field:a})=>i(s.Box,{sx:{flexGrow:1},children:i(s.Switch,{label:"Display Name on Line",checked:a.value??!1,onChange:o=>a.onChange(o.currentTarget.checked)})})})]})]}),p(s.Stack,{children:[i(v.Controller,{name:`series.${t}.showSymbol`,control:e,render:({field:a})=>i(s.Box,{mt:10,mb:-10,sx:{flexGrow:1},children:i(s.Switch,{label:"Show Symbol on Line",checked:a.value,onChange:o=>a.onChange(o.currentTarget.checked)})})}),r&&i(v.Controller,{name:`series.${t}.symbolSize`,control:e,render:({field:a})=>i(gs,{label:"Symbol Size",...a})})]})]})}function eh({control:e,index:t}){return i(v.Controller,{name:`series.${t}.symbolSize`,control:e,render:({field:n})=>i(gs,{label:"Size",...n})})}const th=[{label:"off",value:""},{label:"top",value:"top"},{label:"left",value:"left"},{label:"right",value:"right"},{label:"bottom",value:"bottom"},{label:"inside",value:"inside"},{label:"insideLeft",value:"insideLeft"},{label:"insideRight",value:"insideRight"},{label:"insideTop",value:"insideTop"},{label:"insideBottom",value:"insideBottom"},{label:"insideTopLeft",value:"insideTopLeft"},{label:"insideBottomLeft",value:"insideBottomLeft"},{label:"insideTopRight",value:"insideTopRight"},{label:"insideBottomRight",value:"insideBottomRight"}];function nh({control:e,index:t,remove:n,seriesItem:r,yAxisOptions:a}){const o=r.type;return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[i(s.Stack,{children:i(v.Controller,{name:`series.${t}.type`,control:e,render:({field:l})=>i(s.SegmentedControl,{data:[{label:"Line",value:"line"},{label:"Bar",value:"bar"},{label:"Scatter",value:"scatter"}],...l})})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.name`,control:e,render:({field:l})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`series.${t}.yAxisIndex`,control:e,render:({field:{value:l,onChange:u,...c}})=>i(s.Select,{label:"Y Axis",data:a,disabled:a.length===0,...c,value:(l==null?void 0:l.toString())??"",onChange:d=>{if(!d){u(0);return}u(Number(d))},sx:{flex:1}})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.y_axis_data_key`,control:e,render:({field:l})=>i(R,{label:"Value Field",required:!0,sx:{flex:1},...l})}),i(v.Controller,{name:`series.${t}.aggregation_on_value`,control:e,render:({field:l})=>i(_n,{label:"Aggregation on Value",value:l.value??Bt,onChange:l.onChange,pt:0})})]}),i(s.Group,{grow:!0,children:i(v.Controller,{name:`series.${t}.group_by_key`,control:e,render:({field:l})=>i(R,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...l})})}),o==="line"&&i(Hp,{index:t,control:e,seriesItem:r}),o==="bar"&&i(jp,{index:t,control:e,seriesItem:r}),o==="scatter"&&i(eh,{index:t,control:e}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),i(v.Controller,{name:`series.${t}.label_position`,control:e,render:({field:l})=>i(s.Select,{label:"Label Position",data:th,...l})}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`series.${t}.color`,control:e,render:({field:l})=>i(Pe,{...l})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`series.${t}.hide_in_legend`,control:e,render:({field:l})=>i(s.Checkbox,{label:"Hide in legend",checked:l.value,onChange:u=>l.onChange(u.currentTarget.checked)})}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Series"})]},t)}function rh({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"series"}),o=t("series"),l=n.map((f,h)=>({...f,...o[h]})),u=()=>{const f={type:"bar",name:Ee.randomId(),showSymbol:!1,symbolSize:Pr.static,y_axis_data_key:"value",yAxisIndex:0,label_position:"top",display_name_on_line:!1,stack:"",color:"#000",step:!1,smooth:!1,barMinWidth:"1",barWidth:"10%",barMaxWidth:"10",barGap:"0%",lineStyle:{type:"solid",width:1},hide_in_legend:!1,group_by_key:""};r(f)},c=t("y_axes"),d=b.useMemo(()=>c.map(({name:f},h)=>({label:f,value:h.toString()})),[c]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((f,h)=>i(s.Tabs.Tab,{value:h.toString(),children:h+1},f.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(T.Plus,{size:18,color:"#228be6"})})]}),l.map((f,h)=>i(s.Tabs.Panel,{value:h.toString(),children:i(nh,{control:e,index:h,remove:a,seriesItem:f,yAxisOptions:d},f.id)},f.id))]})}function ih({control:e,watch:t}){return t("stats"),i(s.Stack,{children:p(s.Stack,{spacing:0,children:[i(v.Controller,{name:"stats.templates.top",control:e,render:({field:n})=>i(Jt,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),i(v.Controller,{name:"stats.templates.bottom",control:e,render:({field:n})=>i(Jt,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const ah=()=>p(s.Group,{sx:{display:"inline-flex"},spacing:6,mr:14,children:[i(s.Text,{children:"X Axis Data Type"}),p(s.HoverCard,{width:340,shadow:"md",position:"top",children:[i(s.HoverCard.Target,{children:i(s.ActionIcon,{size:"xs",sx:{transform:"none !important"},children:i(L.IconInfoCircle,{})})}),i(s.HoverCard.Dropdown,{children:p(s.Text,{size:"sm",children:["Click",i(s.Anchor,{href:"https://echarts.apache.org/en/option.html#xAxis.type",target:"_blank",mx:4,children:"here"}),"to learn more about these options"]})})]})]}),sh=[{label:"Value",value:"value"},{label:"Category",value:"category"},{label:"Time",value:"time"},{label:"Log",value:"log"}];function oh({control:e,watch:t}){return t(["x_axis_data_key","x_axis_name","x_axis"]),p(s.Stack,{children:[i(v.Controller,{name:"x_axis_name",control:e,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis_data_key",control:e,render:({field:n})=>i(R,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.type",control:e,render:({field:n})=>i(s.Select,{label:i(ah,{}),required:!0,data:sh,sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>i(Mn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>i(mt,{...n})})]})}const lh=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],uh=[{label:"left",value:"left"},{label:"right",value:"right"}];function ch({control:e,index:t,remove:n}){return p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[i(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`y_axes.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`y_axes.${t}.nameAlignment`,control:e,render:({field:r})=>i(s.Select,{label:"Align",required:!0,data:lh,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`y_axes.${t}.position`,control:e,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:uh,sx:{flex:1},...r})})}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:`y_axes.${t}.label_formatter`,control:e,render:({field:r})=>i(je,{...r})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`y_axes.${t}.min`,control:e,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`y_axes.${t}.max`,control:e,render:({field:r})=>i(s.TextInput,{label:"Max",...r})})]})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`y_axes.${t}.show`,control:e,render:({field:r})=>i(s.Checkbox,{label:"Visible",checked:r.value,onChange:a=>r.onChange(a.currentTarget.checked)})}),i(s.Button,{mt:20,leftIcon:i(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this YAxis"})]})}function dh({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"y_axes"}),o=t("y_axes"),l=n.map((c,d)=>({...c,...o[d]})),u=()=>r({name:"",position:"left",nameAlignment:"left",label_formatter:$e,min:"",max:"",show:!0});return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map((c,d)=>i(s.Tabs.Tab,{value:d.toString(),children:d+1},d)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(T.Plus,{size:18,color:"#228be6"})})]}),l.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(ch,{control:e,index:d,remove:a})},d))]})}function ph({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),{variables:r}=e,a=b.useMemo(()=>x.defaultsDeep({},t,zr),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});b.useEffect(()=>{d(a)},[a]);const f=c(),h=b.useMemo(()=>!x.isEqual(f,a),[f,a]);return u(["dataZoom"]),i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(T.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axes",children:"Y Axes"}),i(s.Tabs.Tab,{value:"Series",children:"Series"}),i(s.Tabs.Tab,{value:"Regression Lines",children:"Regression Lines"}),i(s.Tabs.Tab,{value:"Stats",children:"Stats"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),i(s.Tabs.Tab,{value:"Reference Areas",children:"Reference Areas"}),i(s.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(oh,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axes",children:i(dh,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Series",children:i(rh,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Regression Lines",children:i(Wp,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Stats",children:i(ih,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(Np,{variables:r,control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Areas",children:i(Op,{variables:r,control:o,watch:u})}),i(s.Tabs.Panel,{value:"Zooming",children:i(v.Controller,{name:"dataZoom",control:o,render:({field:g})=>i(Or,{...g})})})]})]})})}function hh(e){const t=x.cloneDeep(x.omit(e,"variables"));return t.stats=x.omit(t.stats,"variables"),t}function fh(e){const{rotate:t,formatter:n=rt}=e.x_axis.axisLabel;return{...e,x_axis:{...e.x_axis,axisLabel:{rotate:t,formatter:n}}}}function gh(e){const{dataZoom:t=Vt,...n}=e;return{...n,dataZoom:t}}function mh(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(t,e)}function yh(e){const t=e.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:ot.random().css()},show_in_legend:a=!1}=n;return{...n,lineStyle:r,show_in_legend:a}});return{...e,reference_lines:t}}function bh(e){const t=e.reference_lines.map(n=>{const{yAxisIndex:r=0}=n;return{...n,yAxisIndex:r}});return{...e,reference_lines:t}}function vh(e){const t=e.series.map(n=>{const{aggregation_on_group:r=Bt}=n;return{...n,aggregation_on_group:r}});return{...e,series:t}}function xh(e){const t=e.series.map(n=>{const{aggregation_on_value:r=Bt}=n;return{...n,aggregation_on_value:r}});return{...e,series:t}}function wh(e){delete e.config;const{x_axis:t,tooltip:n}=e.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:n}}}};return x.defaultsDeep(r,e)}function Ch(e){const{series:t,...n}=e;return{...n,series:t.map(r=>{const{barMinWidth:a,barWidth:o,barMaxWidth:l}=r;return a?{...r,barMinWidth:a,barWidth:"",barMaxWidth:l??o}:{...r,barMinWidth:"",barWidth:o,barMaxWidth:""}})}}function Sh(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{min:a="",max:o=""}=r;return{...r,min:a,max:o}})}}function _h(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{nameAlignment:a="left"}=r;return{...r,nameAlignment:a}})}}function kh(e){const{y_axes:t,...n}=e;return{...n,y_axes:t.map(r=>{const{show:a=!0}=r;return{...r,show:a}})}}function Th(e){const{regressions:t,...n}=e;return{...n,regressions:t.map(r=>{const{group_by_key:a=""}=r;return{...r,group_by_key:a}})}}function Dh(e){const{series:t,y_axes:n,...r}=e;return{...r,series:t.map(a=>{const{hide_in_legend:o=!1,aggregation_on_value:l=Bt}=a;return{...a,hide_in_legend:o,aggregation_on_value:l}}),y_axes:n.map(a=>{const{min:o="",max:l="",show:u=!0}=a;return{...a,min:o,max:l,show:u}})}}function Mh(e){const{type:t="category",...n}=e.x_axis;return{...e,x_axis:{...n,type:t}}}function Ih(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis_data_key:a,series:o,regressions:l,...u}=e;return{...u,x_axis_data_key:r(a),series:o.map(c=>({...c,y_axis_data_key:r(c.y_axis_data_key),group_by_key:r(c.group_by_key)})),regressions:l.map(c=>({...c,y_axis_data_key:r(c.y_axis_data_key),group_by_key:r(c.group_by_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class Eh extends be{constructor(){super(...arguments);N(this,"VERSION",18)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,{panelModel:r})=>{const{config:a}=n;return(a.variables||[]).forEach(u=>{r.variables.find(c=>c.name===u.name)||r.addVariable(u)}),(x.get(a,"stats.variables")||[]).forEach(u=>{r.variables.find(c=>c.name===u.name)||r.addVariable(u)}),{...n,version:2,config:hh(a)}}),this.version(3,n=>({...n,version:3,config:fh(n.config)})),this.version(4,n=>({...n,version:4,config:gh(n.config)})),this.version(5,n=>({...n,version:5,config:mh(n.config)})),this.version(6,n=>({...n,version:6,config:yh(n.config)})),this.version(7,n=>({...n,version:7,config:bh(n.config)})),this.version(8,n=>({...n,version:8,config:vh(n.config)})),this.version(9,n=>({...n,version:9,config:xh(n.config)})),this.version(10,n=>({...n,version:10,config:wh(n.config)})),this.version(11,n=>({...n,version:11,config:Ch(n.config)})),this.version(12,n=>({...n,version:12,config:Sh(n.config)})),this.version(13,n=>({...n,version:13,config:_h(n.config)})),this.version(14,n=>({...n,version:14,config:kh(n.config)})),this.version(15,n=>({...n,version:15,config:Th(n.config)})),this.version(16,n=>({...n,version:16,config:Dh(n.config)})),this.version(17,n=>({...n,version:17,config:Mh(n.config)})),this.version(18,(n,r)=>({...n,version:18,config:Ih(n.config,r)}))}}const Ah={displayName:"Cartesian Chart",displayGroup:"ECharts-based charts",migrator:new Eh,name:"cartesian",viewRender:Ap,configRender:ph,createConfig(){return{version:18,config:x.cloneDeep(zr)}},triggers:[Ar]};function zh(e){if(e.enable_value)return e.value}function $h(e){if(e.enable_value)return e.value}function Lh(e){const t=e.axisLabel.overflow.on_axis.width,n=e.axisLabel.position,r={top:5,left:5,right:5,bottom:5};return e.orient==="vertical"&&x.get(r,n)&&n===e.funnelAlign&&x.set(r,n,t),r}function Oh(e,t){return e.series.map(n=>{const{level_name_data_key:r,level_value_data_key:a,axisLabel:o,min:l,max:u,funnelAlign:c,orient:d,...f}=n;if(!r||!a)return{};const h=q(r),g=q(a),m=t[h.queryID].map(w=>({name:w[h.columnKey],value:w[g.columnKey]})),C=ct(o.overflow.on_axis);return{type:"funnel",...Lh(n),min:zh(l),max:$h(u),minSize:l.size,maxSize:u.size,...f,label:{show:!0,position:o.position,...C},orient:d,funnelAlign:d==="horizontal"?"center":c,data:m}})}function Ph({conf:e,params:t,max:n}){const{name:r,value:a}=t.data,o=H(a/n).format({output:"percent",mantissa:2,trimMantissa:!0});return[{label:`${t.marker} ${r}`,value:`${a} (${o})`,style:{label:"",value:""}}]}function Bh(e,t){var o;const n=q(e.series[0].level_name_data_key),r=q(e.series[0].level_value_data_key),a=(o=x.maxBy(t[n.queryID],r.columnKey))==null?void 0:o[r.columnKey];return l=>{const c=Ph({conf:e,params:l,max:a}).map(f=>`
183
118
  <tr>
184
119
  <th style="text-align: right;">
185
120
  <div style="${f.style.label}">${f.label}</div>
@@ -195,13 +130,13 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
195
130
  <table style="width: auto">
196
131
  <tbody>${c.join("")}</tbody>
197
132
  </table>
198
- `}}function Mh(t,e){return{trigger:"item",confine:!0,formatter:Dh(t,e)}}function Ih(t,e){return{grid:{top:0,left:0,right:0,bottom:0},tooltip:Mh(t,e),series:kh(t,e)}}function Eh(t){return t||(t=Date.now().toString()),{id:t,name:t,level_name_data_key:"",level_value_data_key:"",min:{value:0,enable_value:!1,size:"0%"},max:{value:0,enable_value:!1,size:"100%"},gap:2,axisLabel:{show:!0,position:"inside",overflow:Ze},sort:"descending",orient:"vertical",funnelAlign:"center"}}const Or={series:[Eh("Funnel")]};le.use([pe.FunnelChart,G.DataZoomComponent,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function Ah({conf:t,data:e,width:n,height:r}){const a=y.useMemo(()=>Ih(t,e),[t,e]);return!n||!r?null:i(Ne,{echarts:le,option:a,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function zh({context:t}){const{value:e}=W(t.instanceData,"config"),n=y.useMemo(()=>x.defaults({},e,Or),[e]),r=t.data,{width:a,height:o}=t.viewport;return i(s.Box,{children:i(Ah,{width:a,height:o,data:r,conf:n})})}const $h=[{label:"Top",value:"top"},{label:"Left",value:"left"},{label:"Right",value:"right"},{label:"Bottom",value:"bottom"},{label:"Outside",value:"outside"},{label:"Inside",value:"inside"},{label:"InsideLeft",value:"insideLeft"},{label:"InsideRight",value:"insideRight"},{label:"InsideTop",value:"insideTop"},{label:"InsideBottom",value:"insideBottom"},{label:"InsideTopLeft",value:"insideTopLeft"},{label:"InsideBottomLeft",value:"insideBottomLeft"},{label:"InsideTopRight",value:"insideTopRight"},{label:"InsideBottomRight",value:"insideBottomRight"}],Pr=y.forwardRef(({label:t,value:e,onChange:n,options:r=$h},a)=>i(s.Select,{ref:a,label:t,data:r,value:e,onChange:n})),Lh=[{label:"Ascending",value:"ascending"},{label:"Descending",value:"descending"},{label:"Use original data order",value:"0"}],Oh=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Ph=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}],Bh={horizontal:[{label:"Top",value:"top"},{label:"Inside Center",value:"inside"},{label:"Bottom",value:"bottom"}],vertical:[{label:"Left",value:"left"},{label:"Inside Left",value:"insideLeft"},{label:"Inside Center",value:"inside"},{label:"Inside Right",value:"insideRight"},{label:"Right",value:"right"}]},Vh=({item:t,control:e,index:n,remove:r})=>{const a=t.min.enable_value,o=t.max.enable_value,{orient:l}=t;return p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`series.${n}.name`,control:e,render:({field:u})=>i(s.TextInput,{label:"Series Name",...u})})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.level_name_data_key`,control:e,render:({field:u})=>i(j,{label:"Level Name Field",...u})}),i(v.Controller,{name:`series.${n}.level_value_data_key`,control:e,render:({field:u})=>i(j,{label:"Level Value Field",...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Funnel Style",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.min.value`,control:e,render:({field:u})=>i(s.NumberInput,{disabled:!a,labelProps:{display:"block"},label:p(s.Group,{position:"apart",pr:6,sx:{width:"100%"},children:[i(s.Text,{children:"Min Value"}),i(s.Tooltip,{label:"Check to enable specific min value",children:i(s.Box,{children:i(v.Controller,{name:`series.${n}.min.enable_value`,control:e,render:({field:c})=>i(s.Checkbox,{size:"xs",checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})})})})]}),...u})}),i(v.Controller,{name:`series.${n}.min.size`,control:e,render:({field:u})=>i(s.TextInput,{placeholder:"0%",label:"Min Size",...u})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.max.value`,control:e,render:({field:u})=>i(s.NumberInput,{disabled:!o,labelProps:{display:"block"},label:p(s.Group,{position:"apart",pr:6,sx:{width:"100%"},children:[i(s.Text,{children:"Max Value"}),i(s.Tooltip,{label:"Check to enable specific max value",children:i(s.Box,{children:i(v.Controller,{name:`series.${n}.max.enable_value`,control:e,render:({field:c})=>i(s.Checkbox,{size:"xs",checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})})})})]}),...u})}),i(v.Controller,{name:`series.${n}.max.size`,control:e,render:({field:u})=>i(s.TextInput,{placeholder:"100%",label:"Max Size",...u})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.orient`,control:e,render:({field:u})=>i(s.Select,{label:"Orientation",data:Ph,...u})}),i(v.Controller,{name:`series.${n}.sort`,control:e,render:({field:u})=>i(s.Select,{label:"Sort",data:Lh,...u})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.funnelAlign`,control:e,render:({field:u})=>i(s.Select,{label:"Align",disabled:l==="horizontal",data:Oh,...u})}),i(v.Controller,{name:`series.${n}.gap`,control:e,render:({field:u})=>i(s.NumberInput,{placeholder:"0, 5, 10...",label:"Gap",...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Label Style",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.axisLabel.position`,control:e,render:({field:u})=>i(Pr,{label:"Position",options:Bh[l],...u})}),i(s.Box,{})]}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`series.${n}.axisLabel.overflow`,control:e,render:({field:u})=>i(gt,{...u})})})]})},Nh=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"series"}),o=e("series"),l=n.map((f,h)=>({...f,...o[h]})),u=x.get(l,"0.id"),[c,d]=y.useState(u??null);return y.useEffect(()=>{u&&d(f=>f!==null?f:u)},[u]),p(s.Tabs,{value:c,onTabChange:f=>d(f),styles:{panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((f,h)=>i(s.Tabs.Tab,{value:f.id,children:f.name},f.id)),i(s.Tabs.Tab,{value:"add",disabled:!0,children:i(s.Tooltip,{label:"TODO",children:i(s.Center,{children:i(L.IconPlus,{size:18,color:"#228be6"})})})})]}),l.map((f,h)=>i(s.Tabs.Panel,{value:f.id,children:i(Vh,{item:f,control:t,index:h,remove:a})},f.id))]})};function qh({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,Or),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l([]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,r),[d,r]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Funnel Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(D.DeviceFloppy,{size:20})})]}),i(Nh,{control:a,watch:l})]})})}function Fh(t){return{series:t.series.map(e=>{const{min:n,minSize:r,max:a,maxSize:o,...l}=e;return{...l,min:{value:n,use_data_min:!1,size:r},max:{value:a,use_data_max:!1,size:o}}})}}function Gh(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=l=>l&&`${n}.${l}`,{series:a,...o}=t;return{...o,series:a.map(l=>({...l,level_name_data_key:r(l.level_name_data_key),level_value_data_key:r(l.level_value_data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class Wh extends ve{constructor(){super(...arguments);N(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{config:r}=n;return{...n,version:2,config:Fh(r)}}),this.version(3,(n,r)=>{const{config:a}=n;return{...n,version:3,config:Gh(a,r)}})}}const jh={displayName:"Funnel Chart",displayGroup:"ECharts-based charts",migrator:new Wh,name:"funnel",viewRender:zh,configRender:qh,createConfig:()=>({version:3,config:Or})};function $s({enabled:t,func_content:e}){return(n,r)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function Rh(t){const e=$s(t.x_axis.axisLabel.formatter),n=$s(t.y_axis.axisLabel.formatter);return{x_axis:e,y_axis:n}}function Yh(t){return{heat_block:function(r){if(!t.heat_block.value_formatter)return r;try{return ee(r).format(t.heat_block.value_formatter)}catch(a){return console.error(a),r}}}}function Qh(t){let e=0;return t.x_axis.name&&(e+=20),{top:45,left:5,right:5,bottom:e,containLabel:!0}}function Kh(t,e){const{x_axis:n,y_axis:r,heat_block:a}=t,o=q(n.data_key),l=q(r.data_key),u=q(a.data_key),c=e[o.queryID].map(d=>[x.get(d,o.columnKey),x.get(d,l.columnKey),x.get(d,u.columnKey)]);return{type:"heatmap",name:a.name,xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{borderColor:"white",borderWidth:2},data:c,label:a.label,labelLayout:{hideOverlap:!0}}}const Uh=t=>{try{return ee(t).format({trimMantissa:!0,mantissa:2})}catch{return t}};function Xh({conf:t,labelFormatters:e,valueFormatters:n,dataDict:r,params:a}){const{value:o,dataIndex:l}=a,[u,c,d]=o,f={label:t.x_axis.name?t.x_axis.name:"X Axis",value:e.x_axis(u,l),style:{label:"",value:mt(t.x_axis.axisLabel.overflow.in_tooltip)}},h={label:t.y_axis.name?t.y_axis.name:"Y Axis",value:e.y_axis(c,l),style:{label:"",value:mt(t.y_axis.axisLabel.overflow.in_tooltip)}},g={label:t.heat_block.name,value:n.heat_block(d),style:{label:"",value:""}},m=[f,h,g],w=r[`${u}---${c}`];return w&&t.tooltip.metrics.forEach(C=>{const _=q(C.data_key);m.push({label:C.name,value:Uh(x.get(w,_.columnKey,"")),style:{label:"",value:""}})}),m}function Jh(t,e,n,r){const{x_axis:a,y_axis:o,heat_block:l}=t,u=q(a.data_key),c=q(o.data_key);q(l.data_key);const d=x.keyBy(e[u.queryID],f=>`${f[u.columnKey]}---${f[c.columnKey]}`);return{confine:!0,formatter:function(f){const g=Xh({conf:t,labelFormatters:n,valueFormatters:r,dataDict:d,params:f}).map(w=>`
133
+ `}}function Vh(e,t){return{trigger:"item",confine:!0,formatter:Bh(e,t)}}function Nh(e,t){return{grid:{top:0,left:0,right:0,bottom:0},tooltip:Vh(e,t),series:Oh(e,t)}}function qh(e){return e||(e=Date.now().toString()),{id:e,name:e,level_name_data_key:"",level_value_data_key:"",min:{value:0,enable_value:!1,size:"0%"},max:{value:0,enable_value:!1,size:"100%"},gap:2,axisLabel:{show:!0,position:"inside",overflow:Ze},sort:"descending",orient:"vertical",funnelAlign:"center"}}const Br={series:[qh("Funnel")]};oe.use([pe.FunnelChart,G.DataZoomComponent,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function Fh({conf:e,data:t,width:n,height:r}){const a=b.useMemo(()=>Nh(e,t),[e,t]);return!n||!r?null:i(Ne,{echarts:oe,option:a,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function Gh({context:e}){const{value:t}=W(e.instanceData,"config"),n=b.useMemo(()=>x.defaults({},t,Br),[t]),r=e.data,{width:a,height:o}=e.viewport;return i(s.Box,{children:i(Fh,{width:a,height:o,data:r,conf:n})})}const Wh=[{label:"Top",value:"top"},{label:"Left",value:"left"},{label:"Right",value:"right"},{label:"Bottom",value:"bottom"},{label:"Outside",value:"outside"},{label:"Inside",value:"inside"},{label:"InsideLeft",value:"insideLeft"},{label:"InsideRight",value:"insideRight"},{label:"InsideTop",value:"insideTop"},{label:"InsideBottom",value:"insideBottom"},{label:"InsideTopLeft",value:"insideTopLeft"},{label:"InsideBottomLeft",value:"insideBottomLeft"},{label:"InsideTopRight",value:"insideTopRight"},{label:"InsideBottomRight",value:"insideBottomRight"}],Vr=b.forwardRef(({label:e,value:t,onChange:n,options:r=Wh},a)=>i(s.Select,{ref:a,label:e,data:r,value:t,onChange:n})),Rh=[{label:"Ascending",value:"ascending"},{label:"Descending",value:"descending"},{label:"Use original data order",value:"0"}],jh=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Yh=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}],Qh={horizontal:[{label:"Top",value:"top"},{label:"Inside Center",value:"inside"},{label:"Bottom",value:"bottom"}],vertical:[{label:"Left",value:"left"},{label:"Inside Left",value:"insideLeft"},{label:"Inside Center",value:"inside"},{label:"Inside Right",value:"insideRight"},{label:"Right",value:"right"}]},Kh=({item:e,control:t,index:n,remove:r})=>{const a=e.min.enable_value,o=e.max.enable_value,{orient:l}=e;return p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`series.${n}.name`,control:t,render:({field:u})=>i(s.TextInput,{label:"Series Name",...u})})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.level_name_data_key`,control:t,render:({field:u})=>i(R,{label:"Level Name Field",...u})}),i(v.Controller,{name:`series.${n}.level_value_data_key`,control:t,render:({field:u})=>i(R,{label:"Level Value Field",...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Funnel Style",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.min.value`,control:t,render:({field:u})=>i(s.NumberInput,{disabled:!a,labelProps:{display:"block"},label:p(s.Group,{position:"apart",pr:6,sx:{width:"100%"},children:[i(s.Text,{children:"Min Value"}),i(s.Tooltip,{label:"Check to enable specific min value",children:i(s.Box,{children:i(v.Controller,{name:`series.${n}.min.enable_value`,control:t,render:({field:c})=>i(s.Checkbox,{size:"xs",checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})})})})]}),...u})}),i(v.Controller,{name:`series.${n}.min.size`,control:t,render:({field:u})=>i(s.TextInput,{placeholder:"0%",label:"Min Size",...u})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.max.value`,control:t,render:({field:u})=>i(s.NumberInput,{disabled:!o,labelProps:{display:"block"},label:p(s.Group,{position:"apart",pr:6,sx:{width:"100%"},children:[i(s.Text,{children:"Max Value"}),i(s.Tooltip,{label:"Check to enable specific max value",children:i(s.Box,{children:i(v.Controller,{name:`series.${n}.max.enable_value`,control:t,render:({field:c})=>i(s.Checkbox,{size:"xs",checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})})})})]}),...u})}),i(v.Controller,{name:`series.${n}.max.size`,control:t,render:({field:u})=>i(s.TextInput,{placeholder:"100%",label:"Max Size",...u})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.orient`,control:t,render:({field:u})=>i(s.Select,{label:"Orientation",data:Yh,...u})}),i(v.Controller,{name:`series.${n}.sort`,control:t,render:({field:u})=>i(s.Select,{label:"Sort",data:Rh,...u})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.funnelAlign`,control:t,render:({field:u})=>i(s.Select,{label:"Align",disabled:l==="horizontal",data:jh,...u})}),i(v.Controller,{name:`series.${n}.gap`,control:t,render:({field:u})=>i(s.NumberInput,{placeholder:"0, 5, 10...",label:"Gap",...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Label Style",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${n}.axisLabel.position`,control:t,render:({field:u})=>i(Vr,{label:"Position",options:Qh[l],...u})}),i(s.Box,{})]}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`series.${n}.axisLabel.overflow`,control:t,render:({field:u})=>i(mt,{...u})})})]})},Uh=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"series"}),o=t("series"),l=n.map((f,h)=>({...f,...o[h]})),u=x.get(l,"0.id"),[c,d]=b.useState(u??null);return b.useEffect(()=>{u&&d(f=>f!==null?f:u)},[u]),p(s.Tabs,{value:c,onTabChange:f=>d(f),styles:{panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((f,h)=>i(s.Tabs.Tab,{value:f.id,children:f.name},f.id)),i(s.Tabs.Tab,{value:"add",disabled:!0,children:i(s.Tooltip,{label:"TODO",children:i(s.Center,{children:i(L.IconPlus,{size:18,color:"#228be6"})})})})]}),l.map((f,h)=>i(s.Tabs.Panel,{value:f.id,children:i(Kh,{item:f,control:e,index:h,remove:a})},f.id))]})};function Xh({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),r=b.useMemo(()=>x.defaultsDeep({},t,Br),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});b.useEffect(()=>{c(r)},[r]),l([]);const d=u(),f=b.useMemo(()=>!x.isEqual(d,r),[d,r]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Funnel Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(T.DeviceFloppy,{size:20})})]}),i(Uh,{control:a,watch:l})]})})}function Jh(e){return{series:e.series.map(t=>{const{min:n,minSize:r,max:a,maxSize:o,...l}=t;return{...l,min:{value:n,use_data_min:!1,size:r},max:{value:a,use_data_max:!1,size:o}}})}}function Zh(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=l=>l&&`${n}.${l}`,{series:a,...o}=e;return{...o,series:a.map(l=>({...l,level_name_data_key:r(l.level_name_data_key),level_value_data_key:r(l.level_value_data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class Hh extends be{constructor(){super(...arguments);N(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{config:r}=n;return{...n,version:2,config:Jh(r)}}),this.version(3,(n,r)=>{const{config:a}=n;return{...n,version:3,config:Zh(a,r)}})}}const ef={displayName:"Funnel Chart",displayGroup:"ECharts-based charts",migrator:new Hh,name:"funnel",viewRender:Gh,configRender:Xh,createConfig:()=>({version:3,config:Br})};function ms({enabled:e,func_content:t}){return(n,r)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function tf(e){const t=ms(e.x_axis.axisLabel.formatter),n=ms(e.y_axis.axisLabel.formatter);return{x_axis:t,y_axis:n}}function nf(e){return{heat_block:function(r){if(!e.heat_block.value_formatter)return r;try{return H(r).format(e.heat_block.value_formatter)}catch(a){return console.error(a),r}}}}function rf(e){let t=0;return e.x_axis.name&&(t+=20),{top:45,left:5,right:5,bottom:t,containLabel:!0}}function af(e,t){const{x_axis:n,y_axis:r,heat_block:a}=e,o=q(n.data_key),l=q(r.data_key),u=q(a.data_key),c=t[o.queryID].map(d=>[x.get(d,o.columnKey),x.get(d,l.columnKey),x.get(d,u.columnKey)]);return{type:"heatmap",name:a.name,xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{borderColor:"white",borderWidth:2},data:c,label:a.label,labelLayout:{hideOverlap:!0}}}const sf=e=>{try{return H(e).format({trimMantissa:!0,mantissa:2})}catch{return e}};function of({conf:e,labelFormatters:t,valueFormatters:n,dataDict:r,params:a}){const{value:o,dataIndex:l}=a,[u,c,d]=o,f={label:e.x_axis.name?e.x_axis.name:"X Axis",value:t.x_axis(u,l),style:{label:"",value:yt(e.x_axis.axisLabel.overflow.in_tooltip)}},h={label:e.y_axis.name?e.y_axis.name:"Y Axis",value:t.y_axis(c,l),style:{label:"",value:yt(e.y_axis.axisLabel.overflow.in_tooltip)}},g={label:e.heat_block.name,value:n.heat_block(d),style:{label:"",value:""}},m=[f,h,g],C=r[`${u}---${c}`];return C&&e.tooltip.metrics.forEach(w=>{const _=q(w.data_key);m.push({label:w.name,value:sf(x.get(C,_.columnKey,"")),style:{label:"",value:""}})}),m}function lf(e,t,n,r){const{x_axis:a,y_axis:o,heat_block:l}=e,u=q(a.data_key),c=q(o.data_key);q(l.data_key);const d=x.keyBy(t[u.queryID],f=>`${f[u.columnKey]}---${f[c.columnKey]}`);return{confine:!0,formatter:function(f){const g=of({conf:e,labelFormatters:n,valueFormatters:r,dataDict:d,params:f}).map(C=>`
199
134
  <tr>
200
135
  <th style="text-align: right;">
201
- <div style="${w.style.label}">${w.label}</div>
136
+ <div style="${C.style.label}">${C.label}</div>
202
137
  </th>
203
138
  <td style="text-align: right; padding: 0 1em;">
204
- <div style="${w.style.value}">${w.value}
139
+ <div style="${C.style.value}">${C.value}
205
140
  </td>
206
141
  </tr>
207
142
  `);return`
@@ -216,14 +151,14 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
216
151
  </thead>
217
152
  <tbody>${g.join("")}</tbody>
218
153
  </table>
219
- `}}}const Zh=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return i(s.Box,{children:i(Ie,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Ls={static:{type:"static",value:10},dynamic:{type:"dynamic",value:["function getValue({ variables }, { lodash, interpolate }) {"," // your code goes here"," return 100;","}"].join(`
220
- `)}},Hh=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:a}]=X.useBoolean(),[o,l]=y.useState(t),u=()=>{a();const{type:h,value:g}=o,m={type:h,value:g};l(m),e(m)},c=()=>{a(),l(t)},d=h=>{l(g=>({...g,value:h}))},f=()=>{d(Ls.dynamic.value)};return p(V,{children:[i(s.Box,{sx:{width:"50%"},children:i(s.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),i(s.Modal,{size:800,title:"Setup dynamic value",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),i(Zh,{value:o.value,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},ef=({value:t,onChange:e})=>t.type!=="dynamic"?null:i(Hh,{value:t,onChange:e}),tf=({value:t,onChange:e})=>{if(t.type!=="static")return null;const n=r=>{e({...t,value:r})};return i(s.NumberInput,{defaultValue:18,label:" ",hideControls:!0,value:t.value,onChange:n})},nf=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],In=y.forwardRef(({label:t="Value",value:e,onChange:n},r)=>{const a=o=>{n({...Ls[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:t,data:nf,value:e.type,onChange:a,sx:{flexGrow:1}}),i(tf,{value:e,onChange:n}),i(ef,{value:e,onChange:n})]})});function En(t,e,n){if(!t.type)return n;if(t.type==="static"){const{value:a}=t;return a}const{value:r}=t;try{return console.log("returning here"),new Function(`return ${r}`)()({variables:e},{lodash:x,interpolate:_t.interpolate})}catch(a){return console.error(`[getNumberOrDynamicValue] failed parsing custom function, error: ${a.message}`),10}}function rf(t,e){const n=En(t.heat_block.min,e),r=En(t.heat_block.max,e);return{min:n,max:r,calculable:!0,orient:"horizontal",left:"center",top:0,itemWidth:15}}function af(t,e,n){const r=q(t.x_axis.data_key),a=x.uniq(e[r.queryID].map(c=>c[r.columnKey])),{overflow:o,rotate:l}=t.x_axis.axisLabel,u=ut(o.on_axis);return{id:"main-x-axis",type:"category",data:a,name:t.x_axis.name??"",align:"center",axisTick:{show:!0,alignWithLabel:!0},axisLabel:{rotate:l,...u,formatter:n},splitArea:{show:!0},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:1}}function sf(t,e,n){const r=q(t.x_axis.data_key),a=q(t.y_axis.data_key),{nameAlignment:o,data_key:l,...u}=t.y_axis,c=x.uniq(e[r.queryID].map(g=>g[a.columnKey])),{overflow:d,rotate:f}=t.y_axis.axisLabel,h=ut(d.on_axis);return{...u,type:"category",data:c,axisLabel:{rotate:f,...h,formatter:n},axisLine:{show:!0,color:"blue"},axisTick:{show:!0,alignWithLabel:!0},splitArea:{show:!0},nameTextStyle:{fontWeight:"bold",align:o},nameLocation:"end",nameGap:15,z:1}}const of={tooltip:{confine:!0}};function lf(t,e,n){if(!t.x_axis.data_key||!t.y_axis.data_key||!t.heat_block.data_key)return{};const r=n.reduce((u,c)=>{const d=yt(c,e);return u[c.name]=et(c,d),u},{}),a=Rh(t),o=Yh(t),l={xAxis:af(t,e,a.x_axis),yAxis:sf(t,e,a.y_axis),series:Kh(t,e),tooltip:Jh(t,e,a,o),grid:Qh(t),visualMap:rf(t,r)};return x.defaultsDeep({},l,of)}function uf(t){return i(V,{})}function cf(t){return i(s.Text,{children:"Click heat block"})}const Os={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:cf,configRender:uf,payload:[{name:"seriesType",description:"'heatmap'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]},Br={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,overflow:Ze,formatter:{...nt}}},y_axis:{name:"Y Axis",data_key:"",nameAlignment:"center",axisLabel:{rotate:0,overflow:Ze,formatter:{...nt}}},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:$e,label:{show:!1,fontSize:10}},tooltip:{metrics:[]}};le.use([G.DataZoomComponent,pe.HeatmapChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,G.VisualMapComponent,Ve.CanvasRenderer]);function df({conf:t,data:e,width:n,height:r,interactionManager:a,variables:o}){const l=y.useMemo(()=>{const h=q(t.x_axis.data_key),g=q(t.y_axis.data_key);return x.keyBy(e[h.queryID],m=>`${m[h.columnKey]}---${m[g.columnKey]}`)},[e,t.x_axis.data_key,t.y_axis.data_key]),u=He(a.triggerManager,Os.id),c=y.useCallback(h=>{const[g,m]=h.value,w=x.get(l,`${g}---${m}`,{error:"rowData is not found"});u.forEach(C=>{a.runInteraction(C.id,{...h,rowData:w})})},[l,u,a]),d=y.useMemo(()=>({click:c}),[c]),f=y.useMemo(()=>lf(t,e,o),[t,e]);return!n||!r?null:i(Ne,{echarts:le,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function pf({context:t,instance:e}){const n=tt({vizManager:t.vizManager,instance:e}),{value:r}=W(t.instanceData,"config"),{variables:a}=t,o=y.useMemo(()=>x.defaults({},r,Br),[r]),l=t.data,{width:u,height:c}=t.viewport;return i(s.Box,{children:i(df,{variables:a,width:u,height:c,data:l,conf:o,interactionManager:n})})}function hf({control:t,watch:e}){e(["heat_block"]);const n=e("heat_block.label.show");return p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.data_key",control:t,render:({field:r})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:"heat_block.name",control:t,render:({field:r})=>i(s.TextInput,{label:"Name",sx:{flex:1},...r})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.min",control:t,render:({field:r})=>i(In,{label:"Min Value",...r})}),i(v.Controller,{name:"heat_block.max",control:t,render:({field:r})=>i(In,{label:"Max Value",...r})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),i(v.Controller,{name:"heat_block.value_formatter",control:t,render:({field:r})=>i(Re,{...r})}),i(s.Divider,{mb:-5,variant:"dashed",label:"Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.label.show",control:t,render:({field:r})=>i(s.Switch,{label:"Show label",checked:r.value,onChange:a=>r.onChange(a.currentTarget.checked),sx:{flexGrow:1}})}),i(v.Controller,{name:"heat_block.label.fontSize",control:t,render:({field:r})=>i(s.NumberInput,{size:"xs",icon:i(L.IconTextSize,{size:16}),disabled:!n,...r})})]})]})}const ff=({control:t,index:e,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,render:({field:r})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),gf=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=e("tooltip.metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(V,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(D.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),i(s.Divider,{variant:"dashed",my:10}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(ff,{control:t,index:g,remove:a},h.id)},h.id))]})]})};function mf({control:t,watch:e}){return i(gf,{control:t,watch:e})}const yf=({disabled:t,value:e,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[t&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Ie,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},bf={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
221
- `)},Ps=y.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:a,setFalse:o}]=X.useBoolean(),[l,u]=y.useState(t);y.useEffect(()=>{u(t)},[t]);const c=m=>{u({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:w}=l,C={enabled:m,func_content:w};u(C),e(C)},f=()=>{o(),u(t)},h=m=>{u(w=>({...w,func_content:m}))},g=()=>{h(bf.func_content)};return p(V,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Customize Label"}),i(s.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>c(m.currentTarget.checked)}),i(yf,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})});function vf({control:t,watch:e}){return e(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Ps,{...n})})]})]})}const xf=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function wf({control:t,watch:e}){return e(["y_axis"]),p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.data_key",control:t,render:({field:n})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...n})})]}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"y_axis.nameAlignment",control:t,render:({field:n})=>i(s.Select,{label:"Name Alignment",required:!0,data:xf,sx:{flex:1},...n})})}),i(s.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),i(v.Controller,{name:"y_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"y_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Ps,{...n})})]})]})}function Cf({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,Br),[e]),a=y.useMemo(()=>x.cloneDeep(r),[r]);y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return i("form",{onSubmit:l(n),style:{flexGrow:1},children:p(s.Stack,{spacing:"xs",sx:{height:"100%"},children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{root:{flexGrow:1},tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),i(s.Tabs.Tab,{value:"Heat Block",children:"Heat Block"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(vf,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(wf,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Heat Block",children:i(hf,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(mf,{control:o,watch:u})})]})]})})}function Sf(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=d=>d&&`${n}.${d}`,{x_axis:a,y_axis:o,heat_block:l,tooltip:u,...c}=t;return{...c,x_axis:{...a,data_key:r(a.data_key)},y_axis:{...o,data_key:r(o.data_key)},heat_block:{...l,data_key:r(l.data_key)},tooltip:{...u,metrics:u.metrics.map(d=>({...d,data_key:r(d.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function _f(t){return x.defaultsDeep({},t,{heat_block:{label:{show:!1,fontSize:10}}})}function kf(t){const{heat_block:e}=t;let{min:n,max:r}=e;return typeof n!="number"&&(n=0),typeof r!="number"&&(r=100),{...t,heat_block:{...e,min:{type:"static",value:n},max:{type:"static",value:r}}}}class Tf extends ve{constructor(){super(...arguments);N(this,"VERSION",4)}configVersions(){this.version(1,n=>(console.log("🟥 unexpected calling"),{version:1,config:n})),this.version(2,(n,r)=>({...n,version:2,config:Sf(n.config,r)})),this.version(3,n=>({...n,version:3,config:_f(n.config)})),this.version(4,n=>({...n,version:4,config:kf(n.config)}))}}const Df={displayName:"Heatmap",displayGroup:"ECharts-based charts",migrator:new Tf,name:"heatmap",viewRender:pf,configRender:Cf,createConfig:()=>({version:4,config:Br}),triggers:[Os]},Bs={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:If,configRender:Mf,payload:[{name:"type",description:"Always 'click'",valueType:"string"},{name:"seriesType",description:"'line' | 'bar'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function Mf(t){return i(V,{})}function If(t){return i(s.Text,{children:"Click chart's series"})}const Vs={label_template:"${percentage.x} of ${x_axis.name} causes ${percentage.y} of ${bar.name}",color:"rgba(0,0,0,0.3)"},Vr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...nt},overflow:Ze}},data_key:"value",bar:{name:"Value",nameAlignment:"left",color:"#228be6",label_formatter:$e},line:{name:"Value",nameAlignment:"right",color:"red"},dataZoom:Bt,markLine:Vs};function An(t){return ee(t).format({output:"percent",mantissa:0})}function Ef(t){const e=t.value[1];try{return An(e)}catch(n){return console.error(n),e}}function Af(t){function e(n){let r=n;if(typeof n=="object"&&(Array.isArray(n.value)&&n.value.length===2?r=n.value[1]:r=n.value),!t.bar.label_formatter)return r;try{return ee(r).format(t.bar.label_formatter)}catch(a){return console.error(a),r}}return{bar:e,line:Ef,lineValue:An}}function zf(t,e,n){const{label_template:r}=t.markLine;if(!r)return"";const a={...t,percentage:e,count:n},o=Object.keys(a),l=Object.values(a);return new Function(...o,`return \`${r}\`;`)(...l)}function $f(t,e){if(e.length===0)return{};const n=e.findIndex(u=>u[1]>=.8);if(n===-1)return{};const r=e[n],a={x:An((n+1)/e.length),y:An(r[1])},o={left:n+1,right:e.length-n-1},l=r[0];return l?{name:"",silent:!0,symbol:"triangle",symbolRotate:180,symbolSize:[10,8],data:[{name:"",symbol:"none",xAxis:l,lineStyle:{color:t.markLine.color},label:{formatter:zf(t,a,o)}}]}:{}}function Lf(t,e,n){const{x_axis:r,data_key:a}=t;if(!r.data_key||!a)return[];const o=q(r.data_key),l=q(a);if(o.queryID!==l.queryID)throw new Error("Please use the same query for X & Y axis");const u=e[o.queryID].map(h=>[h[o.columnKey],Number(h[l.columnKey])]).sort((h,g)=>g[1]-h[1]),c=u.reduce((h,g)=>h+g[1],0),d=u.reduce((h,g,m)=>{const w=m===0?0:h[m-1][1];return h.push([g[0],w+g[1]]),h},[]).map(h=>[h[0],h[1]/c]),f=$f(t,d);return[{name:t.bar.name,type:"bar",barMaxWidth:20,itemStyle:{color:t.bar.color},label:{show:!1,position:"top",formatter:n.bar},yAxisIndex:0,data:u},{name:t.line.name,type:"line",itemStyle:{color:t.line.color},symbolSize:2,lineStyle:{width:1},label:{show:!1,position:"top",formatter:n.line},yAxisIndex:1,data:d,markLine:f}]}const Of=(t,e)=>n=>{const r=Array.isArray(n)?n:[n];if(r.length===0)return"";const a=r.map((u,c)=>{const d=u.seriesName,[f,h]=u.value;if(!d)return h;const g=c===0?e.bar:e.lineValue;return`
154
+ `}}}const uf=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{children:i(Ae,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},ys={static:{type:"static",value:10},dynamic:{type:"dynamic",value:["function getValue({ variables }, { lodash, interpolate }) {"," // your code goes here"," return 100;","}"].join(`
155
+ `)}},cf=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=X.useBoolean(),[o,l]=b.useState(e),u=()=>{a();const{type:h,value:g}=o,m={type:h,value:g};l(m),t(m)},c=()=>{a(),l(e)},d=h=>{l(g=>({...g,value:h}))},f=()=>{d(ys.dynamic.value)};return p(V,{children:[i(s.Box,{sx:{width:"50%"},children:i(s.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),i(s.Modal,{size:800,title:"Setup dynamic value",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),i(uf,{value:o.value,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(T.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},df=({value:e,onChange:t})=>e.type!=="dynamic"?null:i(cf,{value:e,onChange:t}),pf=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,value:r})};return i(s.NumberInput,{defaultValue:18,label:" ",hideControls:!0,value:e.value,onChange:n})},hf=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],En=b.forwardRef(({label:e="Value",value:t,onChange:n},r)=>{const a=o=>{n({...ys[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:e,data:hf,value:t.type,onChange:a,sx:{flexGrow:1}}),i(pf,{value:t,onChange:n}),i(df,{value:t,onChange:n})]})});function An(e,t,n){if(!e.type)return n;if(e.type==="static"){const{value:a}=e;return a}const{value:r}=e;try{return console.log("returning here"),new Function(`return ${r}`)()({variables:t},{lodash:x,interpolate:kt.interpolate})}catch(a){return console.error(`[getNumberOrDynamicValue] failed parsing custom function, error: ${a.message}`),10}}function ff(e,t){const n=An(e.heat_block.min,t),r=An(e.heat_block.max,t);return{min:n,max:r,calculable:!0,orient:"horizontal",left:"center",top:0,itemWidth:15}}function gf(e,t,n){const r=q(e.x_axis.data_key),a=x.uniq(t[r.queryID].map(c=>c[r.columnKey])),{overflow:o,rotate:l}=e.x_axis.axisLabel,u=ct(o.on_axis);return{id:"main-x-axis",type:"category",data:a,name:e.x_axis.name??"",align:"center",axisTick:{show:!0,alignWithLabel:!0},axisLabel:{rotate:l,...u,formatter:n},splitArea:{show:!0},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:1}}function mf(e,t,n){const r=q(e.x_axis.data_key),a=q(e.y_axis.data_key),{nameAlignment:o,data_key:l,...u}=e.y_axis,c=x.uniq(t[r.queryID].map(g=>g[a.columnKey])),{overflow:d,rotate:f}=e.y_axis.axisLabel,h=ct(d.on_axis);return{...u,type:"category",data:c,axisLabel:{rotate:f,...h,formatter:n},axisLine:{show:!0,color:"blue"},axisTick:{show:!0,alignWithLabel:!0},splitArea:{show:!0},nameTextStyle:{fontWeight:"bold",align:o},nameLocation:"end",nameGap:15,z:1}}const yf={tooltip:{confine:!0}};function bf(e,t,n){if(!e.x_axis.data_key||!e.y_axis.data_key||!e.heat_block.data_key)return{};const r=n.reduce((u,c)=>{const d=vt(c,t);return u[c.name]=tt(c,d),u},{}),a=tf(e),o=nf(e),l={xAxis:gf(e,t,a.x_axis),yAxis:mf(e,t,a.y_axis),series:af(e,t),tooltip:lf(e,t,a,o),grid:rf(e),visualMap:ff(e,r)};return x.defaultsDeep({},l,yf)}function vf(e){return i(V,{})}function xf(e){return i(s.Text,{children:"Click heat block"})}const bs={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:xf,configRender:vf,payload:[{name:"seriesType",description:"'heatmap'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]},Nr={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,overflow:Ze,formatter:{...rt}}},y_axis:{name:"Y Axis",data_key:"",nameAlignment:"center",axisLabel:{rotate:0,overflow:Ze,formatter:{...rt}}},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:$e,label:{show:!1,fontSize:10}},tooltip:{metrics:[]}};oe.use([G.DataZoomComponent,pe.HeatmapChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,G.VisualMapComponent,Ve.CanvasRenderer]);function wf({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=b.useMemo(()=>{const h=q(e.x_axis.data_key),g=q(e.y_axis.data_key);return x.keyBy(t[h.queryID],m=>`${m[h.columnKey]}---${m[g.columnKey]}`)},[t,e.x_axis.data_key,e.y_axis.data_key]),u=He(a.triggerManager,bs.id),c=b.useCallback(h=>{const[g,m]=h.value,C=x.get(l,`${g}---${m}`,{error:"rowData is not found"});u.forEach(w=>{a.runInteraction(w.id,{...h,rowData:C})})},[l,u,a]),d=b.useMemo(()=>({click:c}),[c]),f=b.useMemo(()=>bf(e,t,o),[e,t]);return!n||!r?null:i(Ne,{echarts:oe,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function Cf({context:e,instance:t}){const n=et({vizManager:e.vizManager,instance:t}),{value:r}=W(e.instanceData,"config"),{variables:a}=e,o=b.useMemo(()=>x.defaults({},r,Nr),[r]),l=e.data,{width:u,height:c}=e.viewport;return i(s.Box,{children:i(wf,{variables:a,width:u,height:c,data:l,conf:o,interactionManager:n})})}function Sf({control:e,watch:t}){t(["heat_block"]);const n=t("heat_block.label.show");return p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.data_key",control:e,render:({field:r})=>i(R,{label:"Data Field",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:"heat_block.name",control:e,render:({field:r})=>i(s.TextInput,{label:"Name",sx:{flex:1},...r})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.min",control:e,render:({field:r})=>i(En,{label:"Min Value",...r})}),i(v.Controller,{name:"heat_block.max",control:e,render:({field:r})=>i(En,{label:"Max Value",...r})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),i(v.Controller,{name:"heat_block.value_formatter",control:e,render:({field:r})=>i(je,{...r})}),i(s.Divider,{mb:-5,variant:"dashed",label:"Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.label.show",control:e,render:({field:r})=>i(s.Switch,{label:"Show label",checked:r.value,onChange:a=>r.onChange(a.currentTarget.checked),sx:{flexGrow:1}})}),i(v.Controller,{name:"heat_block.label.fontSize",control:e,render:({field:r})=>i(s.NumberInput,{size:"xs",icon:i(L.IconTextSize,{size:16}),disabled:!n,...r})})]})]})}const _f=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>i(R,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),kf=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,f]=b.useState(()=>c??null);return b.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(V,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(T.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),i(s.Divider,{variant:"dashed",my:10}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(T.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(_f,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function Tf({control:e,watch:t}){return i(kf,{control:e,watch:t})}const Df=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Ae,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},Mf={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
156
+ `)},vs=b.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=X.useBoolean(),[l,u]=b.useState(e);b.useEffect(()=>{u(e)},[e]);const c=m=>{u({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:C}=l,w={enabled:m,func_content:C};u(w),t(w)},f=()=>{o(),u(e)},h=m=>{u(C=>({...C,func_content:m}))},g=()=>{h(Mf.func_content)};return p(V,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Customize Label"}),i(s.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>c(m.currentTarget.checked)}),i(Df,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(T.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})});function If({control:e,watch:t}){return t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(R,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>i(mt,{...n})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>i(vs,{...n})})]})]})}const Ef=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function Af({control:e,watch:t}){return t(["y_axis"]),p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>i(R,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...n})})]}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"y_axis.nameAlignment",control:e,render:({field:n})=>i(s.Select,{label:"Name Alignment",required:!0,data:Ef,sx:{flex:1},...n})})}),i(s.Divider,{mb:-15,variant:"dashed",label:"Tick Label",labelPosition:"center"}),i(v.Controller,{name:"y_axis.axisLabel.overflow",control:e,render:({field:n})=>i(mt,{...n})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.axisLabel.rotate",control:e,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"y_axis.axisLabel.formatter",control:e,render:({field:n})=>i(vs,{...n})})]})]})}function zf({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),r=b.useMemo(()=>x.defaultsDeep({},t,Nr),[t]),a=b.useMemo(()=>x.cloneDeep(r),[r]);b.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});b.useEffect(()=>{d(a)},[a]);const f=c(),h=b.useMemo(()=>!x.isEqual(f,r),[f,r]);return i("form",{onSubmit:l(n),style:{flexGrow:1},children:p(s.Stack,{spacing:"xs",sx:{height:"100%"},children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(T.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{root:{flexGrow:1},tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),i(s.Tabs.Tab,{value:"Heat Block",children:"Heat Block"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(If,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(Af,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Heat Block",children:i(Sf,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(Tf,{control:o,watch:u})})]})]})})}function $f(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=d=>d&&`${n}.${d}`,{x_axis:a,y_axis:o,heat_block:l,tooltip:u,...c}=e;return{...c,x_axis:{...a,data_key:r(a.data_key)},y_axis:{...o,data_key:r(o.data_key)},heat_block:{...l,data_key:r(l.data_key)},tooltip:{...u,metrics:u.metrics.map(d=>({...d,data_key:r(d.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function Lf(e){return x.defaultsDeep({},e,{heat_block:{label:{show:!1,fontSize:10}}})}function Of(e){const{heat_block:t}=e;let{min:n,max:r}=t;return typeof n!="number"&&(n=0),typeof r!="number"&&(r=100),{...e,heat_block:{...t,min:{type:"static",value:n},max:{type:"static",value:r}}}}class Pf extends be{constructor(){super(...arguments);N(this,"VERSION",4)}configVersions(){this.version(1,n=>(console.log("🟥 unexpected calling"),{version:1,config:n})),this.version(2,(n,r)=>({...n,version:2,config:$f(n.config,r)})),this.version(3,n=>({...n,version:3,config:Lf(n.config)})),this.version(4,n=>({...n,version:4,config:Of(n.config)}))}}const Bf={displayName:"Heatmap",displayGroup:"ECharts-based charts",migrator:new Pf,name:"heatmap",viewRender:Cf,configRender:zf,createConfig:()=>({version:4,config:Nr}),triggers:[bs]},xs={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:Nf,configRender:Vf,payload:[{name:"type",description:"Always 'click'",valueType:"string"},{name:"seriesType",description:"'line' | 'bar'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function Vf(e){return i(V,{})}function Nf(e){return i(s.Text,{children:"Click chart's series"})}const ws={label_template:"${percentage.x} of ${x_axis.name} causes ${percentage.y} of ${bar.name}",color:"rgba(0,0,0,0.3)"},qr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:{...rt},overflow:Ze}},data_key:"value",bar:{name:"Value",nameAlignment:"left",color:"#228be6",label_formatter:$e},line:{name:"Value",nameAlignment:"right",color:"red"},dataZoom:Vt,markLine:ws};function zn(e){return H(e).format({output:"percent",mantissa:0})}function qf(e){const t=e.value[1];try{return zn(t)}catch(n){return console.error(n),t}}function Ff(e){function t(n){let r=n;if(typeof n=="object"&&(Array.isArray(n.value)&&n.value.length===2?r=n.value[1]:r=n.value),!e.bar.label_formatter)return r;try{return H(r).format(e.bar.label_formatter)}catch(a){return console.error(a),r}}return{bar:t,line:qf,lineValue:zn}}function Gf(e,t,n){const{label_template:r}=e.markLine;if(!r)return"";const a={...e,percentage:t,count:n},o=Object.keys(a),l=Object.values(a);return new Function(...o,`return \`${r}\`;`)(...l)}function Wf(e,t){if(t.length===0)return{};const n=t.findIndex(u=>u[1]>=.8);if(n===-1)return{};const r=t[n],a={x:zn((n+1)/t.length),y:zn(r[1])},o={left:n+1,right:t.length-n-1},l=r[0];return l?{name:"",silent:!0,symbol:"triangle",symbolRotate:180,symbolSize:[10,8],data:[{name:"",symbol:"none",xAxis:l,lineStyle:{color:e.markLine.color},label:{formatter:Gf(e,a,o)}}]}:{}}function Rf(e,t,n){const{x_axis:r,data_key:a}=e;if(!r.data_key||!a)return[];const o=q(r.data_key),l=q(a);if(o.queryID!==l.queryID)throw new Error("Please use the same query for X & Y axis");const u=t[o.queryID].map(h=>[h[o.columnKey],Number(h[l.columnKey])]).sort((h,g)=>g[1]-h[1]),c=u.reduce((h,g)=>h+g[1],0),d=u.reduce((h,g,m)=>{const C=m===0?0:h[m-1][1];return h.push([g[0],C+g[1]]),h},[]).map(h=>[h[0],h[1]/c]),f=Wf(e,d);return[{name:e.bar.name,type:"bar",barMaxWidth:20,itemStyle:{color:e.bar.color},label:{show:!1,position:"top",formatter:n.bar},yAxisIndex:0,data:u},{name:e.line.name,type:"line",itemStyle:{color:e.line.color},symbolSize:2,lineStyle:{width:1},label:{show:!1,position:"top",formatter:n.line},yAxisIndex:1,data:d,markLine:f}]}const jf=(e,t)=>n=>{const r=Array.isArray(n)?n:[n];if(r.length===0)return"";const a=r.map((u,c)=>{const d=u.seriesName,[f,h]=u.value;if(!d)return h;const g=c===0?t.bar:t.lineValue;return`
222
157
  <tr>
223
158
  <th style="text-align: right; padding: 0 1em;">${d}</th>
224
159
  <td style="text-align: left; padding: 0 1em;">${g(h)}</td>
225
160
  </tr>
226
- `}),o=mt(t.x_axis.axisLabel.overflow.in_tooltip),l=r[0].name;return`
161
+ `}),o=yt(e.x_axis.axisLabel.overflow.in_tooltip),l=r[0].name;return`
227
162
  <div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
228
163
  <div style="${o}">${l}</div>
229
164
  </div>
@@ -232,7 +167,7 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
232
167
  ${a.join("")}
233
168
  </tbody>
234
169
  </table>
235
- `};function Pf(t,e){return{trigger:"axis",formatter:Of(t,e)}}function Bf(t){const{name:e,axisLabel:n}=t.x_axis,r=ut(n.overflow.on_axis);return[{type:"category",name:e,nameLocation:"middle",nameGap:30,nameTextStyle:{fontWeight:"bold",align:"right"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0},axisLabel:{...n,...r,formatter:Ot(n.formatter)}}]}function Vf(t,e){return[{name:t.bar.name,nameGap:20,nameTextStyle:{fontWeight:"bold",align:t.bar.nameAlignment},position:"left",axisLine:{show:!0},axisLabel:{show:!0,formatter:e.bar},splitLine:{show:!1}},{name:t.line.name,nameGap:20,nameTextStyle:{fontWeight:"bold",align:t.line.nameAlignment},position:"right",axisLine:{show:!0},axisLabel:{show:!0,formatter:e.lineValue},splitLine:{show:!1}}]}function Nf(t,e,n){const r=Af(t);return{dataZoom:Ar(t.dataZoom),tooltip:Pf(t,r),xAxis:Bf(t),yAxis:Vf(t,r),series:Lf(t,e,r),grid:{top:50,left:30,right:15,bottom:5,containLabel:!0}}}le.use([pe.BarChart,pe.LineChart,G.DataZoomComponent,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function qf({context:t,instance:e}){const{value:n}=W(t.instanceData,"config"),r=t.data,{width:a,height:o}=t.viewport,l=x.defaults({},n,Vr),u=Nf(l,r),c=tt({vizManager:t.vizManager,instance:e}),d=He(c.triggerManager,Bs.id),f=bt(r,l.x_axis.data_key),h=y.useCallback(m=>{const w=x.get(f,m.name,{error:"rowData is not found"});d.forEach(C=>{c.runInteraction(C.id,{...m,rowData:w})})},[f,d,c]),g=y.useMemo(()=>({click:h}),[h]);return!l||!a||!o?null:i(Ne,{echarts:le,option:u,style:{width:a,height:o},onEvents:g,notMerge:!0,theme:"merico-light"})}const Ff=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function Gf({control:t,watch:e}){return e(["bar"]),p(s.Stack,{children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:"bar.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Bar Name",sx:{flex:1},...n})}),i(v.Controller,{name:"bar.nameAlignment",control:t,render:({field:n})=>i(s.Select,{label:"Align",required:!0,data:Ff,sx:{flex:1},...n})})]}),p(s.Stack,{spacing:2,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:"bar.color",control:t,render:({field:n})=>i(Pe,{...n})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:"bar.label_formatter",control:t,render:({field:n})=>i(Re,{...n})})]})]})}const Wf=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function jf({control:t,watch:e}){return e(["line"]),p(s.Stack,{children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:"line.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Line Name",sx:{flex:1},...n})}),i(v.Controller,{name:"line.nameAlignment",control:t,render:({field:n})=>i(s.Select,{label:"Align",required:!0,data:Wf,sx:{flex:1},...n})})]}),p(s.Stack,{spacing:2,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:"line.color",control:t,render:({field:n})=>i(Pe,{...n})})]})]})}const Rf=`
170
+ `};function Yf(e,t){return{trigger:"axis",formatter:jf(e,t)}}function Qf(e){const{name:t,axisLabel:n}=e.x_axis,r=ct(n.overflow.on_axis);return[{type:"category",name:t,nameLocation:"middle",nameGap:30,nameTextStyle:{fontWeight:"bold",align:"right"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0},axisLabel:{...n,...r,formatter:Pt(n.formatter)}}]}function Kf(e,t){return[{name:e.bar.name,nameGap:20,nameTextStyle:{fontWeight:"bold",align:e.bar.nameAlignment},position:"left",axisLine:{show:!0},axisLabel:{show:!0,formatter:t.bar},splitLine:{show:!1}},{name:e.line.name,nameGap:20,nameTextStyle:{fontWeight:"bold",align:e.line.nameAlignment},position:"right",axisLine:{show:!0},axisLabel:{show:!0,formatter:t.lineValue},splitLine:{show:!1}}]}function Uf(e,t,n){const r=Ff(e);return{dataZoom:$r(e.dataZoom),tooltip:Yf(e,r),xAxis:Qf(e),yAxis:Kf(e,r),series:Rf(e,t,r),grid:{top:50,left:30,right:15,bottom:5,containLabel:!0}}}oe.use([pe.BarChart,pe.LineChart,G.DataZoomComponent,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function Xf({context:e,instance:t}){const{value:n}=W(e.instanceData,"config"),r=e.data,{width:a,height:o}=e.viewport,l=x.defaults({},n,qr),u=Uf(l,r),c=et({vizManager:e.vizManager,instance:t}),d=He(c.triggerManager,xs.id),f=bt(r,l.x_axis.data_key),h=b.useCallback(m=>{const C=x.get(f,m.name,{error:"rowData is not found"});d.forEach(w=>{c.runInteraction(w.id,{...m,rowData:C})})},[f,d,c]),g=b.useMemo(()=>({click:h}),[h]);return!l||!a||!o?null:i(Ne,{echarts:oe,option:u,style:{width:a,height:o},onEvents:g,notMerge:!0,theme:"merico-light"})}const Jf=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function Zf({control:e,watch:t}){return t(["bar"]),p(s.Stack,{children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:"bar.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Bar Name",sx:{flex:1},...n})}),i(v.Controller,{name:"bar.nameAlignment",control:e,render:({field:n})=>i(s.Select,{label:"Align",required:!0,data:Jf,sx:{flex:1},...n})})]}),p(s.Stack,{spacing:2,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:"bar.color",control:e,render:({field:n})=>i(Pe,{...n})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:"bar.label_formatter",control:e,render:({field:n})=>i(je,{...n})})]})]})}const Hf=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}];function eg({control:e,watch:t}){return t(["line"]),p(s.Stack,{children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:"line.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Line Name",sx:{flex:1},...n})}),i(v.Controller,{name:"line.nameAlignment",control:e,render:({field:n})=>i(s.Select,{label:"Align",required:!0,data:Hf,sx:{flex:1},...n})})]}),p(s.Stack,{spacing:2,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:"line.color",control:e,render:({field:n})=>i(Pe,{...n})})]})]})}const tg=`
236
171
  {
237
172
  // 80-20 line stuff
238
173
  percentage: {
@@ -255,8 +190,8 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
255
190
  name: string;
256
191
  };
257
192
  }
258
- `,Yf=()=>{const[t,e]=y.useState(!1);return p(V,{children:[i(s.Button,{variant:"subtle",compact:!0,onClick:()=>e(n=>!n),children:t?"Close":"Click to see params for Label Template"}),i(s.Collapse,{in:t,children:i(kt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:Rf})})]})};function Qf({control:t,watch:e}){return e(["markLine"]),p(s.Stack,{children:[p(s.Stack,{spacing:2,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:"markLine.color",control:t,render:({field:n})=>i(Pe,{...n})})]}),p(s.Stack,{spacing:4,children:[i(v.Controller,{name:"markLine.label_template",control:t,render:({field:n})=>i(s.Textarea,{autosize:!0,minRows:2,maxRows:4,label:"Label Template",sx:{flex:1},...n})}),i(Yf,{})]})]})}function Kf({control:t,watch:e}){return e(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Dn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})})]})}function Uf({control:t,watch:e}){return e(["data_key"]),i(s.Stack,{children:i(v.Controller,{name:"data_key",control:t,render:({field:n})=>i(j,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})})}function Xf({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaults({},e,Vr),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l(["x_axis","data_key","bar","line","dataZoom"]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,e),[d,e]);return p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),i(s.Tabs.Tab,{value:"Bar",children:"Bar"}),i(s.Tabs.Tab,{value:"Line",children:"Line"}),i(s.Tabs.Tab,{value:"80-20 Line",children:"80-20 Line"}),i(s.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(Kf,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(Uf,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Bar",children:i(Gf,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Line",children:i(jf,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"80-20 Line",children:i(Qf,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Zooming",children:i(v.Controller,{name:"dataZoom",control:a,render:({field:h})=>i($r,{...h})})})]})]})}function Jf(t){const{dataZoom:e=Bt,...n}=t;return{...n,dataZoom:e}}function Zf(t){const{markLine:e=Vs,...n}=t;return{...n,markLine:e}}function Hf(t){const e=x.defaultsDeep({},t.x_axis.axisLabel,{rotate:0,formatter:{...nt}});return{...t,x_axis:{...t.x_axis,axisLabel:e}}}function eg(t){const{label_formatter:e=$e}=t.bar;return{...t,bar:{...t.bar,label_formatter:e}}}function tg(t){const e={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(e,t)}function ng(t){const e={bar:{nameAlignment:"left"},line:{nameAlignment:"right"}};return x.defaultsDeep(e,t)}function rg(t){console.log(t);const{x_axis:e,tooltip:n}=t.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:e,in_tooltip:n}}}};return x.defaultsDeep(r,t)}function ig(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:a,data_key:o,...l}=t;return{...l,x_axis:{...a,data_key:r(a.data_key)},data_key:r(o)}}catch(n){throw console.error("[Migration failed]",n),n}}class ag extends ve{constructor(){super(...arguments);N(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Jf(n.config)})),this.version(3,n=>({...n,version:3,config:Zf(n.config)})),this.version(4,n=>({...n,version:4,config:Hf(n.config)})),this.version(5,n=>({...n,version:5,config:eg(n.config)})),this.version(6,n=>({...n,version:6,config:tg(n.config)})),this.version(7,n=>({...n,version:7,config:ng(n.config)})),this.version(8,n=>({...n,version:8,config:rg(n.config)})),this.version(9,(n,r)=>({...n,version:9,config:ig(n.config,r)}))}}const sg={displayName:"Pareto Chart",displayGroup:"ECharts-based charts",migrator:new ag,name:"paretoChart",viewRender:qf,configRender:Xf,createConfig(){return{version:9,config:x.cloneDeep(Vr)}},triggers:[Bs]},Nr={grid:{axis:"#97999D",scope:"rgba(47,140,192,0.1)",boundary:"#789AB4",reference:"#CFCFD8"},graphics:{compared:{blueDark:"#3E7CAB",blue:"#6398C7",blueLight:"#7CB0DF",blue10:"#6398C71a",redDark:"#AF5F6B",red:"#CD7C88",redLight:"#E794A0",red10:"#CD7C881a"},gradient:{distributed:"linear-gradient(90deg, #1babe6 0%, #2fc8c8 28.63%, #98d44b 48.86%, #ffd057 67.53%, #f5ae53 80.6%, #e76441 91.18%, #b90000 100%)",protrude:"linear-gradient(180deg, #ec73734d 0%, #ec737300 100%)"},level:{lv0:"#6398C7",lv1:"#61B5BF",lv2:"#54D4BB",lv3:"#F5D277",lv4:"#E8BB7F",lv5:"#DB9E84",lv6:"#CB8089"},depth:{dp0:"#FFF7F8",dp1:"#FFE1E1",dp2:"#FDBCBC",dp3:"#F39494",dp4:"#FA4242",dp5:"#E21212"},multiple:{c1:"#66B4DB",c2:"#E46464",c3:"#EEBA00",c4:"#33A678",c5:"#9D88CB",c6:"#939943",c7:"#E49792",c8:"#09A2B8",c9:"#AF5F6B",c10:"#6CA157",c11:"#3E7CAB",c12:"#6398C7",c13:"#E692BA",c14:"#97B566",c15:"#8CACE2",c16:"#CA79AC",c17:"#6DBC80",c18:"#B08F4B",c19:"#39BFA2",c20:"#826BAF"}}};function og(){le.registerTheme("merico-light",{color:Object.values(Nr.graphics.multiple),visualMap:{color:Object.values(Nr.graphics.depth).reverse()}})}function Ns(){og()}function*lg(t){const e=Nr.graphics[t];if(!e)throw new Error("Invalid palette key provided");const n=Object.values(e);let r=0;for(;;)yield n[r%n.length],r++}function ug(t,e,n){const{label_field:r,value_field:a,color_field:o}=t;if(!r||!a)return{};const l=q(r),u=q(a),c=q(o),d=e[l.queryID].map(h=>({name:h[l.columnKey],value:Number(h[u.columnKey]),color:c.columnKey?h[c.columnKey]:void 0})),f=lg("multiple");return{type:"pie",name:"pie",radius:["50%","80%"],itemStyle:{color:({data:h})=>h.color?h.color:f.next().value},label:{position:"outer",alignTo:"edge",formatter:`{name|{b}}
259
- {percentage|{d}%}`,minMargin:5,edgeDistance:10,lineHeight:15,rich:{percentage:{color:"#999"}},margin:20},labelLine:{length:15,length2:0,maxSurfaceAngle:80,showAbove:!0},labelLayout:function(h){const g=h.labelRect.x<n/2,m=h.labelLinePoints;return x.set(m,[2,0],g?h.labelRect.x:h.labelRect.x+h.labelRect.width),{labelLinePoints:m}},data:d,top:10,bottom:10,left:10,right:10}}function cg(t,e,n){return{tooltip:{show:!0,confine:!0},series:ug(t,e,n)}}const qs={id:"builtin:echarts:click-pie-chart:series",displayName:"Click Pie Series",nameRender:pg,configRender:dg,payload:[{name:"seriesType",description:"'line' | 'scatter' | 'bar'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"Value of the series clicked",valueType:"number"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function dg(t){return i(V,{})}function pg(t){return i(s.Text,{children:"Click chart's series"})}const qr={label_field:"",value_field:"",color_field:""};le.use([pe.PieChart,Ve.CanvasRenderer]);function hg({conf:t,data:e,width:n,height:r,interactionManager:a}){const o=bt(e,t.label_field),l=He(a.triggerManager,qs.id),u=y.useCallback(f=>{const h=x.get(o,f.name,{error:"rowData is not found"});l.forEach(g=>{a.runInteraction(g.id,{...f,rowData:h})})},[o,l,a]),c=y.useMemo(()=>cg(t,e,n),[t,e,n]),d=y.useMemo(()=>({click:u}),[u]);return!n||!r||!c.series.name?null:i(Ne,{echarts:le,option:c,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function fg({context:t,instance:e}){const n=tt({vizManager:t.vizManager,instance:e}),{value:r}=W(t.instanceData,"config"),a=y.useMemo(()=>x.defaults({},r,qr),[r]),o=t.data,{width:l,height:u}=t.viewport;return!l||!u?null:i(hg,{conf:a,width:l,height:u,data:o,interactionManager:n})}function gg({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,qr),[e]),a=y.useMemo(()=>x.clone(r),[r]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return u(["label_field","value_field","color_field"]),i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Pie Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Stack,{mt:"md",spacing:"xs",p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[i(v.Controller,{control:o,name:"label_field",render:({field:g})=>i(j,{label:"Label Key",required:!0,...g})}),i(v.Controller,{control:o,name:"value_field",render:({field:g})=>i(j,{label:"Value Key",required:!0,...g})}),i(v.Controller,{control:o,name:"color_field",render:({field:g})=>i(j,{label:"Color Key",clearable:!0,...g})})]})]})})}function mg(t){const{color_field:e="",...n}=t;return{...n,color_field:e}}function yg(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{label_field:a,value_field:o,color_field:l}=t;return{label_field:r(a),value_field:r(o),color_field:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class bg extends ve{constructor(){super(...arguments);N(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:mg(n.config)})),this.version(3,(n,r)=>({...n,version:3,config:yg(n.config,r)}))}}const vg={displayName:"Pie Chart",displayGroup:"ECharts-based charts",migrator:new bg,name:"pie",viewRender:fg,configRender:gg,createConfig(){return{version:3,config:x.cloneDeep(qr)}},triggers:[qs]};function xg(t){return i(V,{})}function wg(t){return i(s.Text,{children:"Click heat block"})}const Fs={id:"builtin:echarts:click-radar-chart:series",displayName:"Click radar chart series",nameRender:wg,configRender:xg,payload:[{name:"seriesType",description:"'radar'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]},zn={series_name_key:"",background:{enabled:!0},label:{enabled:!0},dimensions:[]};function Gs(t){return t?e=>{try{return ee(e).format(t)}catch(n){return console.error(n),e}}:e=>e}function Cg(t){return{show:t.label.enabled,formatter:({dimensionIndex:e,value:n})=>Gs(t.dimensions[e].formatter)(n)}}function Sg(t){return({name:e,marker:n,value:r})=>{if(r.length===0)return"";const a=r.map((o,l)=>{const u=t.dimensions[l],c=Gs(u.formatter);return`
193
+ `,ng=()=>{const[e,t]=b.useState(!1);return p(V,{children:[i(s.Button,{variant:"subtle",compact:!0,onClick:()=>t(n=>!n),children:e?"Close":"Click to see params for Label Template"}),i(s.Collapse,{in:e,children:i(Tt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:tg})})]})};function rg({control:e,watch:t}){return t(["markLine"]),p(s.Stack,{children:[p(s.Stack,{spacing:2,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:"markLine.color",control:e,render:({field:n})=>i(Pe,{...n})})]}),p(s.Stack,{spacing:4,children:[i(v.Controller,{name:"markLine.label_template",control:e,render:({field:n})=>i(s.Textarea,{autosize:!0,minRows:2,maxRows:4,label:"Label Template",sx:{flex:1},...n})}),i(ng,{})]})]})}function ig({control:e,watch:t}){return t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(R,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>i(Mn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>i(mt,{...n})})]})}function ag({control:e,watch:t}){return t(["data_key"]),i(s.Stack,{children:i(v.Controller,{name:"data_key",control:e,render:({field:n})=>i(R,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})})}function sg({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),r=b.useMemo(()=>x.defaults({},t,qr),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});b.useEffect(()=>{c(r)},[r]),l(["x_axis","data_key","bar","line","dataZoom"]);const d=u(),f=b.useMemo(()=>!x.isEqual(d,t),[d,t]);return p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(T.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),i(s.Tabs.Tab,{value:"Bar",children:"Bar"}),i(s.Tabs.Tab,{value:"Line",children:"Line"}),i(s.Tabs.Tab,{value:"80-20 Line",children:"80-20 Line"}),i(s.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(ig,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(ag,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Bar",children:i(Zf,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Line",children:i(eg,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"80-20 Line",children:i(rg,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Zooming",children:i(v.Controller,{name:"dataZoom",control:a,render:({field:h})=>i(Or,{...h})})})]})]})}function og(e){const{dataZoom:t=Vt,...n}=e;return{...n,dataZoom:t}}function lg(e){const{markLine:t=ws,...n}=e;return{...n,markLine:t}}function ug(e){const t=x.defaultsDeep({},e.x_axis.axisLabel,{rotate:0,formatter:{...rt}});return{...e,x_axis:{...e.x_axis,axisLabel:t}}}function cg(e){const{label_formatter:t=$e}=e.bar;return{...e,bar:{...e.bar,label_formatter:t}}}function dg(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(t,e)}function pg(e){const t={bar:{nameAlignment:"left"},line:{nameAlignment:"right"}};return x.defaultsDeep(t,e)}function hg(e){console.log(e);const{x_axis:t,tooltip:n}=e.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:n}}}};return x.defaultsDeep(r,e)}function fg(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:a,data_key:o,...l}=e;return{...l,x_axis:{...a,data_key:r(a.data_key)},data_key:r(o)}}catch(n){throw console.error("[Migration failed]",n),n}}class gg extends be{constructor(){super(...arguments);N(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:og(n.config)})),this.version(3,n=>({...n,version:3,config:lg(n.config)})),this.version(4,n=>({...n,version:4,config:ug(n.config)})),this.version(5,n=>({...n,version:5,config:cg(n.config)})),this.version(6,n=>({...n,version:6,config:dg(n.config)})),this.version(7,n=>({...n,version:7,config:pg(n.config)})),this.version(8,n=>({...n,version:8,config:hg(n.config)})),this.version(9,(n,r)=>({...n,version:9,config:fg(n.config,r)}))}}const mg={displayName:"Pareto Chart",displayGroup:"ECharts-based charts",migrator:new gg,name:"paretoChart",viewRender:Xf,configRender:sg,createConfig(){return{version:9,config:x.cloneDeep(qr)}},triggers:[xs]},Fr={grid:{axis:"#97999D",scope:"rgba(47,140,192,0.1)",boundary:"#789AB4",reference:"#CFCFD8"},graphics:{compared:{blueDark:"#3E7CAB",blue:"#6398C7",blueLight:"#7CB0DF",blue10:"#6398C71a",redDark:"#AF5F6B",red:"#CD7C88",redLight:"#E794A0",red10:"#CD7C881a"},gradient:{distributed:"linear-gradient(90deg, #1babe6 0%, #2fc8c8 28.63%, #98d44b 48.86%, #ffd057 67.53%, #f5ae53 80.6%, #e76441 91.18%, #b90000 100%)",protrude:"linear-gradient(180deg, #ec73734d 0%, #ec737300 100%)"},level:{lv0:"#6398C7",lv1:"#61B5BF",lv2:"#54D4BB",lv3:"#F5D277",lv4:"#E8BB7F",lv5:"#DB9E84",lv6:"#CB8089"},depth:{dp0:"#FFF7F8",dp1:"#FFE1E1",dp2:"#FDBCBC",dp3:"#F39494",dp4:"#FA4242",dp5:"#E21212"},multiple:{c1:"#66B4DB",c2:"#E46464",c3:"#EEBA00",c4:"#33A678",c5:"#9D88CB",c6:"#939943",c7:"#E49792",c8:"#09A2B8",c9:"#AF5F6B",c10:"#6CA157",c11:"#3E7CAB",c12:"#6398C7",c13:"#E692BA",c14:"#97B566",c15:"#8CACE2",c16:"#CA79AC",c17:"#6DBC80",c18:"#B08F4B",c19:"#39BFA2",c20:"#826BAF"}}};function yg(){oe.registerTheme("merico-light",{color:Object.values(Fr.graphics.multiple),visualMap:{color:Object.values(Fr.graphics.depth).reverse()}})}function Cs(){yg()}function*bg(e){const t=Fr.graphics[e];if(!t)throw new Error("Invalid palette key provided");const n=Object.values(t);let r=0;for(;;)yield n[r%n.length],r++}function vg(e,t,n){const{label_field:r,value_field:a,color_field:o}=e;if(!r||!a)return{};const l=q(r),u=q(a),c=q(o),d=t[l.queryID].map(h=>({name:h[l.columnKey],value:Number(h[u.columnKey]),color:c.columnKey?h[c.columnKey]:void 0})),f=bg("multiple");return{type:"pie",name:"pie",radius:["50%","80%"],itemStyle:{color:({data:h})=>h.color?h.color:f.next().value},label:{position:"outer",alignTo:"edge",formatter:`{name|{b}}
194
+ {percentage|{d}%}`,minMargin:5,edgeDistance:10,lineHeight:15,rich:{percentage:{color:"#999"}},margin:20},labelLine:{length:15,length2:0,maxSurfaceAngle:80,showAbove:!0},labelLayout:function(h){const g=h.labelRect.x<n/2,m=h.labelLinePoints;return x.set(m,[2,0],g?h.labelRect.x:h.labelRect.x+h.labelRect.width),{labelLinePoints:m}},data:d,top:10,bottom:10,left:10,right:10}}function xg(e,t,n){return{tooltip:{show:!0,confine:!0},series:vg(e,t,n)}}const Ss={id:"builtin:echarts:click-pie-chart:series",displayName:"Click Pie Series",nameRender:Cg,configRender:wg,payload:[{name:"seriesType",description:"'line' | 'scatter' | 'bar'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"Value of the series clicked",valueType:"number"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function wg(e){return i(V,{})}function Cg(e){return i(s.Text,{children:"Click chart's series"})}const Gr={label_field:"",value_field:"",color_field:""};oe.use([pe.PieChart,Ve.CanvasRenderer]);function Sg({conf:e,data:t,width:n,height:r,interactionManager:a}){const o=bt(t,e.label_field),l=He(a.triggerManager,Ss.id),u=b.useCallback(f=>{const h=x.get(o,f.name,{error:"rowData is not found"});l.forEach(g=>{a.runInteraction(g.id,{...f,rowData:h})})},[o,l,a]),c=b.useMemo(()=>xg(e,t,n),[e,t,n]),d=b.useMemo(()=>({click:u}),[u]);return!n||!r||!c.series.name?null:i(Ne,{echarts:oe,option:c,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function _g({context:e,instance:t}){const n=et({vizManager:e.vizManager,instance:t}),{value:r}=W(e.instanceData,"config"),a=b.useMemo(()=>x.defaults({},r,Gr),[r]),o=e.data,{width:l,height:u}=e.viewport;return!l||!u?null:i(Sg,{conf:a,width:l,height:u,data:o,interactionManager:n})}function kg({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),r=b.useMemo(()=>x.defaultsDeep({},t,Gr),[t]),a=b.useMemo(()=>x.clone(r),[r]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});b.useEffect(()=>{d(a)},[a]);const f=c(),h=b.useMemo(()=>!x.isEqual(f,r),[f,r]);return u(["label_field","value_field","color_field"]),i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Pie Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(T.DeviceFloppy,{size:20})})]}),p(s.Stack,{mt:"md",spacing:"xs",p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[i(v.Controller,{control:o,name:"label_field",render:({field:g})=>i(R,{label:"Label Key",required:!0,...g})}),i(v.Controller,{control:o,name:"value_field",render:({field:g})=>i(R,{label:"Value Key",required:!0,...g})}),i(v.Controller,{control:o,name:"color_field",render:({field:g})=>i(R,{label:"Color Key",clearable:!0,...g})})]})]})})}function Tg(e){const{color_field:t="",...n}=e;return{...n,color_field:t}}function Dg(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{label_field:a,value_field:o,color_field:l}=e;return{label_field:r(a),value_field:r(o),color_field:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class Mg extends be{constructor(){super(...arguments);N(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Tg(n.config)})),this.version(3,(n,r)=>({...n,version:3,config:Dg(n.config,r)}))}}const Ig={displayName:"Pie Chart",displayGroup:"ECharts-based charts",migrator:new Mg,name:"pie",viewRender:_g,configRender:kg,createConfig(){return{version:3,config:x.cloneDeep(Gr)}},triggers:[Ss]};function Eg(e){return i(V,{})}function Ag(e){return i(s.Text,{children:"Click heat block"})}const _s={id:"builtin:echarts:click-radar-chart:series",displayName:"Click radar chart series",nameRender:Ag,configRender:Eg,payload:[{name:"seriesType",description:"'radar'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]},$n={series_name_key:"",background:{enabled:!0},label:{enabled:!0},dimensions:[]};function ks(e){return e?t=>{try{return H(t).format(e)}catch(n){return console.error(n),t}}:t=>t}function zg(e){return{show:e.label.enabled,formatter:({dimensionIndex:t,value:n})=>ks(e.dimensions[t].formatter)(n)}}function $g(e){return({name:t,marker:n,value:r})=>{if(r.length===0)return"";const a=r.map((o,l)=>{const u=e.dimensions[l],c=ks(u.formatter);return`
260
195
  <tr>
261
196
  <td style="padding-left: 18px;">${u.name}</td>
262
197
  <td style="text-align: right; "><strong>${c(o)}</strong></td>
@@ -276,7 +211,7 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
276
211
  text-align: left;
277
212
  vertical-align: top;
278
213
  "
279
- >${e}</strong>
214
+ >${t}</strong>
280
215
  </th>
281
216
  </tr>
282
217
  </thead>
@@ -284,7 +219,7 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
284
219
  ${a.join("")}
285
220
  </tbody>
286
221
  </table>
287
- `}}const _g={legend:{show:!0,bottom:0,left:0},tooltip:{trigger:"item"}},kg=["#66B4DB","#39BFA2","#E46464","#33A678","#EEBA00","#9D88CB","#939943","#E49792","#09A2B8","#AF5F6B","#6CA157","#09A2B8","#6398C7","#E692BA","#97B566","#8CACE2","#CA79AC","#6DBC80","#B08F4B","#826BAF"];function Tg(t,e){const{series_name_key:n,dimensions:r}=t;if(!n||r.length===0)return{};const a=r.map(({name:c,max:d})=>({name:c,max:d})),o=q(n),l=e[o.queryID].map(c=>({value:r.map(({data_key:d})=>{const f=q(d);return c[f.columnKey]}),name:c[o.columnKey]})),u={radar:{indicator:a,splitArea:{show:!1}},tooltip:{confine:!0,backgroundColor:"rgba(255,255,255,0.6)",formatter:Sg(t)},legend:{show:!0,bottom:0,left:"center",type:"scroll"},series:{type:"radar",data:l,symbolSize:4,lineStyle:{width:1},emphasis:{lineStyle:{width:4}},areaStyle:t.background.enabled?{opacity:.4}:void 0,label:Cg(t)},color:kg};return x.merge({},_g,u)}le.use([pe.RadarChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function Dg({conf:t,data:e,width:n,height:r,interactionManager:a,variables:o}){const l=bt(e,t.series_name_key),u=He(a.triggerManager,Fs.id),c=y.useCallback(h=>{const g=x.get(l,h.name,{error:"rowData is not found"});u.forEach(m=>{a.runInteraction(m.id,{...h,rowData:g})})},[l,u,a]),d=y.useMemo(()=>({click:c}),[c]),f=y.useMemo(()=>Tg(x.defaultsDeep({},t,zn),e),[t,e]);return!n||!r?null:i(Ne,{echarts:le,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function Mg({context:t,instance:e}){const n=tt({vizManager:t.vizManager,instance:e}),{value:r}=W(t.instanceData,"config"),{variables:a}=t,o=y.useMemo(()=>x.defaults({},r,zn),[r]),l=t.data,{width:u,height:c}=t.viewport;return!u||!c||!o||x.isEmpty(o==null?void 0:o.dimensions)?null:i(s.Box,{children:i(Dg,{variables:a,width:u,height:c,data:l,conf:o,interactionManager:n})})}function Ig({control:t,index:e,remove:n}){return p(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`dimensions.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`dimensions.${e}.data_key`,control:t,render:({field:r})=>i(j,{label:"Data Key",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`dimensions.${e}.max`,control:t,render:({field:r})=>i(s.NumberInput,{label:"Max",hideControls:!0,required:!0,sx:{flex:1},...r})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Formatter",labelPosition:"center"}),i(v.Controller,{name:`dimensions.${e}.formatter`,control:t,render:({field:r})=>i(Re,{...r})})]}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(e),sx:{position:"absolute",top:15,right:5},disabled:e===0,children:i(D.Trash,{size:16})})]},e)}function Eg({control:t,watch:e}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"dimensions"}),o=e("dimensions"),l=n.map((g,m)=>({...g,...o[m]})),u=()=>{const g=new Date().getTime().toString();r({id:g,name:g,data_key:"",max:100,formatter:$e})},c=x.get(l,"0.id",null),[d,f]=y.useState(c);y.useEffect(()=>{f(g=>g||c)},[c]);const h=g=>{a(g);const m=x.get(l,"0.id",null);f(m)};return p(V,{children:[i(s.Divider,{mt:15,variant:"dashed",label:"Metrics",labelPosition:"center"}),p(s.Tabs,{value:d,onTabChange:f,styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map((g,m)=>i(s.Tabs.Tab,{value:g.id,children:g.name?g.name:m+1},m)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(L.IconPlus,{size:18,color:"#228be6"})})]}),l.map((g,m)=>i(s.Tabs.Panel,{value:g.id,children:i(Ig,{control:t,index:m,remove:h})},m))]})]})}function Ag({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,zn),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l(["series_name_key","background","label"]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,r),[d,r]);return i("form",{onSubmit:o(n),children:p(s.Stack,{spacing:"xs",children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Radar Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(D.DeviceFloppy,{size:20})})]}),i(s.Divider,{mt:15,variant:"dashed",label:"Basics",labelPosition:"center"}),i(v.Controller,{name:"series_name_key",control:a,render:({field:h})=>i(j,{label:"Series Name Field",required:!0,sx:{flex:1},...h})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"background.enabled",control:a,render:({field:h})=>i(s.Checkbox,{label:"Show background",checked:h.value,onChange:g=>h.onChange(g.currentTarget.checked)})}),i(v.Controller,{name:"label.enabled",control:a,render:({field:h})=>i(s.Checkbox,{label:"Show value label",checked:h.value,onChange:g=>h.onChange(g.currentTarget.checked)})})]}),i(Eg,{control:a,watch:l})]})})}function zg(t){const{dimensions:e=[],...n}=t;function r({name:a="",data_key:o="",max:l=10,formatter:u=$e}){return{name:a,data_key:o,max:l,formatter:u}}return{...n,dimensions:e.map(r)}}function $g(t){const{dimensions:e=[],...n}=t;return{...n,dimensions:e.map(r=>({...r,id:r.id??r.name}))}}function Lg(t){const e={background:{enabled:!0},label:{enabled:!0}};return x.defaultsDeep(e,t)}function Og(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{series_name_key:a,dimensions:o,...l}=t;return{...l,series_name_key:r(a),dimensions:o.map(u=>({...u,data_key:r(u.data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class Pg extends ve{constructor(){super(...arguments);N(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{config:r}=n;return{...n,version:2,config:zg(r)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:$g(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:Lg(r)}}),this.version(5,(n,r)=>{const{config:a}=n;return{...n,version:5,config:Og(a,r)}})}}const Bg={displayName:"Radar Chart",displayGroup:"ECharts-based charts",migrator:new Pg,name:"radar",viewRender:Mg,configRender:Ag,createConfig:()=>({version:5,config:zn}),triggers:[Fs]};function Vg(t,e){const{plot:n,transform:r}=t.regression;return e.map(a=>({...n,id:`reg-for-${a.name}`,name:a.name,data:Mn(r,a.data),color:a.color,showSymbol:!1,smooth:!0,tooltip:{show:!1},custom:{type:"regression-line",targetSeries:a.name}}))}function Ws(t,e){const n=q(t.x_axis.data_key),r=q(t.regression.y_axis_data_key);return x.uniqBy(e.map(a=>[a[n.columnKey],a[r.columnKey]]),0)}function Ng(t,e){const{plot:n,transform:r}=t.regression,a=Ws(t,e);return[{type:"scatter",name:t.y_axis.name,data:a,symbolSize:4,color:"red",markLine:{...n,data:[Mn(r,a)],color:"blue",smooth:!0,silent:!0,symbol:["none","none"]}}]}function qg(t,e){const{plot:n,transform:r,group_by_key:a}=t.regression,o=q(a),l=x.groupBy(e,o.columnKey);return Object.entries(l).map(([u,c])=>{const d=Ws(t,c);return{type:"scatter",name:u,data:d,symbolSize:4,markLine:{...n,data:[Mn(r,d)],smooth:!0,silent:!0,symbol:["none","none"]}}})}function Fg(t,e){if(e.length===0)return[];const{group_by_key:n}=t.regression;return n?qg(t,e):Ng(t,e)}function Gg(t){return Array.isArray(t)||(t=[t]),t.map(e=>({marker:e.marker,label:e.seriesName,x:e.value[0],y:e.value[1]}))}function Wg(t){return{confine:!0,trigger:"axis",formatter:e=>{const n=Gg(e);return n.length===0?"":`
222
+ `}}const Lg={legend:{show:!0,bottom:0,left:0},tooltip:{trigger:"item"}},Og=["#66B4DB","#39BFA2","#E46464","#33A678","#EEBA00","#9D88CB","#939943","#E49792","#09A2B8","#AF5F6B","#6CA157","#09A2B8","#6398C7","#E692BA","#97B566","#8CACE2","#CA79AC","#6DBC80","#B08F4B","#826BAF"];function Pg(e,t){const{series_name_key:n,dimensions:r}=e;if(!n||r.length===0)return{};const a=r.map(({name:c,max:d})=>({name:c,max:d})),o=q(n),l=t[o.queryID].map(c=>({value:r.map(({data_key:d})=>{const f=q(d);return c[f.columnKey]}),name:c[o.columnKey]})),u={radar:{indicator:a,splitArea:{show:!1}},tooltip:{confine:!0,backgroundColor:"rgba(255,255,255,0.6)",formatter:$g(e)},legend:{show:!0,bottom:0,left:"center",type:"scroll"},series:{type:"radar",data:l,symbolSize:4,lineStyle:{width:1},emphasis:{lineStyle:{width:4}},areaStyle:e.background.enabled?{opacity:.4}:void 0,label:zg(e)},color:Og};return x.merge({},Lg,u)}oe.use([pe.RadarChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function Bg({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=bt(t,e.series_name_key),u=He(a.triggerManager,_s.id),c=b.useCallback(h=>{const g=x.get(l,h.name,{error:"rowData is not found"});u.forEach(m=>{a.runInteraction(m.id,{...h,rowData:g})})},[l,u,a]),d=b.useMemo(()=>({click:c}),[c]),f=b.useMemo(()=>Pg(x.defaultsDeep({},e,$n),t),[e,t]);return!n||!r?null:i(Ne,{echarts:oe,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function Vg({context:e,instance:t}){const n=et({vizManager:e.vizManager,instance:t}),{value:r}=W(e.instanceData,"config"),{variables:a}=e,o=b.useMemo(()=>x.defaults({},r,$n),[r]),l=e.data,{width:u,height:c}=e.viewport;return!u||!c||!o||x.isEmpty(o==null?void 0:o.dimensions)?null:i(s.Box,{children:i(Bg,{variables:a,width:u,height:c,data:l,conf:o,interactionManager:n})})}function Ng({control:e,index:t,remove:n}){return p(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`dimensions.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`dimensions.${t}.data_key`,control:e,render:({field:r})=>i(R,{label:"Data Key",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`dimensions.${t}.max`,control:e,render:({field:r})=>i(s.NumberInput,{label:"Max",hideControls:!0,required:!0,sx:{flex:1},...r})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Formatter",labelPosition:"center"}),i(v.Controller,{name:`dimensions.${t}.formatter`,control:e,render:({field:r})=>i(je,{...r})})]}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(t),sx:{position:"absolute",top:15,right:5},disabled:t===0,children:i(T.Trash,{size:16})})]},t)}function qg({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"dimensions"}),o=t("dimensions"),l=n.map((g,m)=>({...g,...o[m]})),u=()=>{const g=new Date().getTime().toString();r({id:g,name:g,data_key:"",max:100,formatter:$e})},c=x.get(l,"0.id",null),[d,f]=b.useState(c);b.useEffect(()=>{f(g=>g||c)},[c]);const h=g=>{a(g);const m=x.get(l,"0.id",null);f(m)};return p(V,{children:[i(s.Divider,{mt:15,variant:"dashed",label:"Metrics",labelPosition:"center"}),p(s.Tabs,{value:d,onTabChange:f,styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map((g,m)=>i(s.Tabs.Tab,{value:g.id,children:g.name?g.name:m+1},m)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(L.IconPlus,{size:18,color:"#228be6"})})]}),l.map((g,m)=>i(s.Tabs.Panel,{value:g.id,children:i(Ng,{control:e,index:m,remove:h})},m))]})]})}function Fg({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),r=b.useMemo(()=>x.defaultsDeep({},t,$n),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});b.useEffect(()=>{c(r)},[r]),l(["series_name_key","background","label"]);const d=u(),f=b.useMemo(()=>!x.isEqual(d,r),[d,r]);return i("form",{onSubmit:o(n),children:p(s.Stack,{spacing:"xs",children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Radar Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(T.DeviceFloppy,{size:20})})]}),i(s.Divider,{mt:15,variant:"dashed",label:"Basics",labelPosition:"center"}),i(v.Controller,{name:"series_name_key",control:a,render:({field:h})=>i(R,{label:"Series Name Field",required:!0,sx:{flex:1},...h})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"background.enabled",control:a,render:({field:h})=>i(s.Checkbox,{label:"Show background",checked:h.value,onChange:g=>h.onChange(g.currentTarget.checked)})}),i(v.Controller,{name:"label.enabled",control:a,render:({field:h})=>i(s.Checkbox,{label:"Show value label",checked:h.value,onChange:g=>h.onChange(g.currentTarget.checked)})})]}),i(qg,{control:a,watch:l})]})})}function Gg(e){const{dimensions:t=[],...n}=e;function r({name:a="",data_key:o="",max:l=10,formatter:u=$e}){return{name:a,data_key:o,max:l,formatter:u}}return{...n,dimensions:t.map(r)}}function Wg(e){const{dimensions:t=[],...n}=e;return{...n,dimensions:t.map(r=>({...r,id:r.id??r.name}))}}function Rg(e){const t={background:{enabled:!0},label:{enabled:!0}};return x.defaultsDeep(t,e)}function jg(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{series_name_key:a,dimensions:o,...l}=e;return{...l,series_name_key:r(a),dimensions:o.map(u=>({...u,data_key:r(u.data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class Yg extends be{constructor(){super(...arguments);N(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{config:r}=n;return{...n,version:2,config:Gg(r)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:Wg(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:Rg(r)}}),this.version(5,(n,r)=>{const{config:a}=n;return{...n,version:5,config:jg(a,r)}})}}const Qg={displayName:"Radar Chart",displayGroup:"ECharts-based charts",migrator:new Yg,name:"radar",viewRender:Vg,configRender:Fg,createConfig:()=>({version:5,config:$n}),triggers:[_s]};function Kg(e,t){const{plot:n,transform:r}=e.regression;return t.map(a=>({...n,id:`reg-for-${a.name}`,name:a.name,data:In(r,a.data),color:a.color,showSymbol:!1,smooth:!0,tooltip:{show:!1},custom:{type:"regression-line",targetSeries:a.name}}))}function Ts(e,t){const n=q(e.x_axis.data_key),r=q(e.regression.y_axis_data_key);return x.uniqBy(t.map(a=>[a[n.columnKey],a[r.columnKey]]),0)}function Ug(e,t){const{plot:n,transform:r}=e.regression,a=Ts(e,t);return[{type:"scatter",name:e.y_axis.name,data:a,symbolSize:4,color:"red",markLine:{...n,data:[In(r,a)],color:"blue",smooth:!0,silent:!0,symbol:["none","none"]}}]}function Xg(e,t){const{plot:n,transform:r,group_by_key:a}=e.regression,o=q(a),l=x.groupBy(t,o.columnKey);return Object.entries(l).map(([u,c])=>{const d=Ts(e,c);return{type:"scatter",name:u,data:d,symbolSize:4,markLine:{...n,data:[In(r,d)],smooth:!0,silent:!0,symbol:["none","none"]}}})}function Jg(e,t){if(t.length===0)return[];const{group_by_key:n}=e.regression;return n?Xg(e,t):Ug(e,t)}function Zg(e){return Array.isArray(e)||(e=[e]),e.map(t=>({marker:t.marker,label:t.seriesName,x:t.value[0],y:t.value[1]}))}function Hg(e){return{confine:!0,trigger:"axis",formatter:t=>{const n=Zg(t);return n.length===0?"":`
288
223
  <table style="width: auto">
289
224
  <thead>
290
225
  <tr>
@@ -294,51 +229,51 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
294
229
  </thead>
295
230
  <tbody>
296
231
  <tr>
297
- <th style="text-align: left; padding: 0 .5em;">${t.x_axis.name}</th>
232
+ <th style="text-align: left; padding: 0 .5em;">${e.x_axis.name}</th>
298
233
  ${n.map(({x:a})=>`<td style="text-align: right; padding: 0 .5em;">${a}</td>`).join("")}
299
234
  </tr>
300
235
  <tr>
301
- <th style="text-align: left; padding: 0 .5em;">${t.y_axis.name}</th>
236
+ <th style="text-align: left; padding: 0 .5em;">${e.y_axis.name}</th>
302
237
  ${n.map(({y:a})=>`<td style="text-align: right; padding: 0 .5em;">${a}</td>`).join("")}
303
238
  </tr>
304
239
  </tbody>
305
240
  </table>
306
- `}}}function js({enabled:t,func_content:e}){return(n,r)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function jg(t){const{overflow:e,format:n,formatter:r,...a}=t.x_axis.axisLabel,o=ut(e.on_axis);return{type:"value",name:t.x_axis.name??"",nameLocation:"middle",nameGap:25,axisTick:{show:!0,alignWithLabel:!0},axisLabel:{...a,...o,formatter:(l,u)=>{let c=l;try{c=ee(l).format(n)}catch{}return js(r)(c,u)}}}}const Rg={tooltip:{trigger:"axis"},grid:{top:50,left:5,right:10,bottom:20,containLabel:!0},dataZoom:[{type:"inside",xAxisIndex:[0]},{type:"inside",yAxisIndex:[0]}]};function Yg(t,e){const n=Fg(t,e),r=Vg(t,n),a={xAxis:jg(t),yAxis:{name:t.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"left"},nameGap:5,axisLine:{show:!0}},series:[...n,...r],tooltip:Wg(t),legend:{show:!0,type:"scroll",orient:"horizontal",align:"left",right:0,top:0,left:"auto",itemGap:20,padding:[4,8,0,140],data:n.map(o=>o.name)}};return x.defaultsDeep({},a,Rg)}function $n(t,e,n){return 1-(1-t)*(e-1)/(e-n-1)}function Qg(t,e,n,r){const{x_axis:a,y_axis:o}=r,l=ht.regressionLinear()(n),{a:u,b:c,rSquared:d}=l;return{name:t,expression:p(s.Group,{position:"center",noWrap:!0,spacing:10,children:[i(s.Text,{children:o.name}),i(s.Text,{children:"="}),i(s.Text,{weight:"bold",color:"red",children:ee(c).format({mantissa:2,trimMantissa:!0})}),i(s.Text,{children:"+"}),i(s.Text,{weight:"bold",color:"red",children:ee(u).format({mantissa:2,trimMantissa:!0})}),i(s.Text,{children:"×"}),i(s.Text,{children:a.name})]}),rSquared:d,adjustedRSquared:$n(d,e.length,1)}}function Kg(t,e,n,r){const{x_axis:a,y_axis:o}=r,{a:l,b:u,rSquared:c}=ht.regressionExp()(n);return{name:t,expression:p(s.Group,{position:"center",noWrap:!0,spacing:10,children:[i(s.Text,{children:o.name}),i(s.Text,{children:"="}),i(s.Text,{weight:"bold",color:"gray",children:l}),i(s.Text,{children:"×"}),p(s.Group,{position:"left",noWrap:!0,spacing:2,children:[i(s.Text,{children:"Math.exp("}),i(s.Text,{weight:"bold",color:"gray",children:u}),i(s.Text,{children:"×"}),i(s.Text,{children:a.name}),i(s.Text,{children:")"})]})]}),rSquared:c,adjustedRSquared:$n(c,e.length,1)}}function Ug(t,e,n,r){const{x_axis:a,y_axis:o}=r,{a:l,b:u,rSquared:c}=ht.regressionLog()(n);return{name:t,expression:p(s.Group,{position:"center",noWrap:!0,spacing:10,children:[i(s.Text,{children:o.name}),i(s.Text,{children:"="}),i(s.Text,{weight:"bold",color:"gray",children:l}),i(s.Text,{children:"×"}),p(s.Group,{position:"left",noWrap:!0,spacing:2,children:[i(s.Text,{children:"Math.log("}),i(s.Text,{children:a.name}),i(s.Text,{children:")"}),i(s.Text,{children:"+"}),i(s.Text,{weight:"bold",color:"gray",children:u})]})]}),rSquared:c,adjustedRSquared:$n(c,e.length,1)}}function Xg(t,e,n,r){const{x_axis:a,y_axis:o,regression:l}=r,u=ht.regressionPoly().order(l.transform.config.order)(n),{rSquared:c}=u;return console.log(u),{name:t,expression:"",rSquared:c,adjustedRSquared:$n(c,e.length,1)}}function Rs(t,e,n){const{regression:r,x_axis:a}=n,o=q(a.data_key),l=q(r.y_axis_data_key),u=e.map(c=>[c[o.columnKey],c[l.columnKey]]);return r.transform.config.method==="linear"?Qg(t,e,u,n):r.transform.config.method==="exponential"?Kg(t,e,u,n):r.transform.config.method==="logarithmic"?Ug(t,e,u,n):r.transform.config.method==="polynomial"?Xg(t,e,u,n):{name:t,expression:"",rSquared:0,adjustedRSquared:0}}function Jg(t,e){if(!e)return[{name:"",expression:"",rSquared:0,adjustedRSquared:0}];if(!e.regression.group_by_key)return[Rs("",t,e)];const n=q(e.regression.group_by_key),r=x.groupBy(t,n.columnKey);return Object.entries(r).map(([a,o])=>Rs(a,o,e))}const Zg={marginTop:"10px","tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function Ys({desc:t}){const{expression:e,rSquared:n,adjustedRSquared:r}=t;return e?i(s.Table,{fontSize:14,sx:Zg,children:p("tbody",{children:[i("tr",{children:i("td",{colSpan:2,children:i(s.Text,{align:"center",children:e})})}),p("tr",{children:[i("td",{children:"R-Sq"}),i("td",{style:{textAlign:"right"},children:ee(n).format({output:"percent",mantissa:1})})]}),p("tr",{children:[i("td",{children:"R-Sq(Adjusted)"}),i("td",{style:{textAlign:"right"},children:ee(r).format({output:"percent",mantissa:1})})]})]})}):i(s.Text,{children:"Unavailable for this regression method"})}function Hg({conf:t,queryData:e}){var r;const n=y.useMemo(()=>Jg(e,t),[t,e]);return t.regression.group_by_key?(console.log(n),p(s.Tabs,{defaultValue:(r=n[0])==null?void 0:r.name,color:"gray",children:[i(s.Tabs.List,{grow:!0,children:n.map(a=>i(s.Tabs.Tab,{value:a.name,children:a.name},a.name))}),n.map(a=>i(s.Tabs.Panel,{value:a.name,children:i(Ys,{desc:a})},a.name))]})):i(Ys,{desc:n[0]})}function em({conf:t,queryData:e}){return p(s.HoverCard,{shadow:"md",withinPortal:!0,zIndex:320,children:[i(s.HoverCard.Target,{children:i(s.Button,{size:"xs",variant:"subtle",compact:!0,leftIcon:i(L.IconInfoCircle,{size:14}),children:"Regression Info"})}),i(s.HoverCard.Dropdown,{children:i(Fe,{children:i(Hg,{conf:t,queryData:e})})})]})}function tm(t){return i(s.Group,{position:"apart",sx:{position:"absolute",top:0,left:0,height:"22px",zIndex:1},children:i(em,{...t})})}const Ln={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
307
- `)},Fr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,format:$e,overflow:Ze,formatter:{...Ln}}},y_axis:{name:"Y Axis"},regression:{transform:{type:"ecStat:regression",config:{method:"linear",order:1,formulaOn:"end"}},plot:{type:"line",yAxisIndex:0,color:"#228be6",lineStyle:{type:"solid",width:1}},name:"regression",group_by_key:"",y_axis_data_key:"value"}};le.use([G.DataZoomComponent,pe.ScatterChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function nm({context:t}){const{value:e}=W(t.instanceData,"config"),{width:n,height:r}=t.viewport,a=y.useMemo(()=>{var m;const c=t.data,d=e==null?void 0:e.x_axis.data_key,f=(m=e==null?void 0:e.regression)==null?void 0:m.y_axis_data_key;if(!d||!f)return[];const h=q(d),g=q(f);return c[h.queryID].map(w=>typeof w[g.columnKey]=="number"?w:{...w,[g.columnKey]:Number(w[g.columnKey])})},[t.data,e==null?void 0:e.regression.y_axis_data_key]),o=y.useMemo(()=>Yg(x.defaultsDeep({},e,Fr),a),[e,a]),l=y.useRef(null),u=c=>{l.current=c};return!n||!r||!e?null:p(s.Box,{sx:{position:"relative"},children:[i(tm,{conf:e,queryData:a}),i(Ne,{echarts:le,onChartReady:u,option:o,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})]})}const rm=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}];function im({control:t,watch:e}){e("regression");const n=e("regression.transform.config.method"),r=e("regression.group_by_key");return p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"regression.name",control:t,render:({field:a})=>i(s.TextInput,{label:"回归线名称",sx:{flex:1},...a})})}),i(v.Controller,{name:"regression.group_by_key",control:t,render:({field:a})=>i(j,{label:"按此字段将数据分为多个系列",clearable:!0,sx:{flex:1},...a})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"regression.transform.config.method",control:t,render:({field:a})=>i(s.Select,{label:"回归方法",data:rm,sx:{flex:1},...a})}),n==="polynomial"&&i(v.Controller,{name:"regression.transform.config.order",control:t,render:({field:a})=>i(s.NumberInput,{label:"次",sx:{flex:1},...a})})]}),!r&&p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"颜色"}),i(v.Controller,{name:"regression.plot.color",control:t,render:({field:a})=>i(Pe,{...a})})]})]})}const am=({disabled:t,value:e,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[t&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Ie,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},Qs=y.forwardRef(({value:t,onChange:e,triggerButtonText:n="Customize Label"},r)=>{const[a,{setTrue:o,setFalse:l}]=X.useBoolean(),[u,c]=y.useState(t);y.useEffect(()=>{c(t)},[t]);const d=w=>{c({...u,enabled:w})},f=()=>{l();const{enabled:w,func_content:C}=u,_={enabled:w,func_content:C};c(_),e(_)},h=()=>{l(),c(t)},g=w=>{c(C=>({...C,func_content:w}))},m=()=>{g(Ln.func_content)};return p(V,{children:[i(s.Button,{variant:"filled",mt:24,onClick:o,sx:{flexGrow:0},children:n}),i(s.Modal,{size:800,title:"Customize label content",opened:a,onClose:l,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:a&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:u.enabled,onChange:w=>d(w.currentTarget.checked)}),i(am,{value:u.func_content,onChange:g,disabled:!u.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:m,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:h,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:f,children:"OK"})]})]})]})})]})});function sm({control:t,watch:e}){return e(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"X轴名称",sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>i(j,{label:"X轴数据字段",required:!0,sx:{flex:1},...n})})]}),i(s.Divider,{variant:"dashed",labelPosition:"center",label:"格式化数据"}),i(s.Stack,{children:i(v.Controller,{name:"x_axis.axisLabel.format",control:t,render:({field:n})=>i(Re,{...n})})}),i(s.Divider,{variant:"dashed",labelPosition:"center",label:"标签文案样式"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Qs,{triggerButtonText:"自定义标签文案内容",...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})})]})}function om({control:t,watch:e}){return e(["y_axis","regression.y_axis_data_key"]),i(s.Stack,{children:p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Y轴名称",sx:{flex:1},...n})}),i(v.Controller,{name:"regression.y_axis_data_key",control:t,render:({field:n})=>i(j,{label:"Y轴数据字段",required:!0,sx:{flex:1},...n})})]})})}function lm({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaults({},e,Fr),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l(["x_axis","y_axis","regression"]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,e),[d,e]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X轴",orientation:"vertical",styles:{panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X轴",children:"X轴"}),i(s.Tabs.Tab,{value:"Y轴",children:"Y轴"}),i(s.Tabs.Tab,{value:"回归",children:"回归"})]}),i(s.Tabs.Panel,{value:"X轴",children:i(sm,{watch:l,control:a})}),i(s.Tabs.Panel,{value:"Y轴",children:i(om,{watch:l,control:a})}),i(s.Tabs.Panel,{value:"回归",children:i(im,{control:a,watch:l})})]})]})})}function um(t){const e={x_axis:{axisLabel:{rotate:0,format:$e,overflow:Ze,formatter:Ln}},regression:{group_by_key:""}};return x.defaultsDeep(e,t)}function cm(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:a,regression:o,...l}=t;return{...l,x_axis:{...a,data_key:r(a.data_key)},regression:{...o,group_by_key:r(o.group_by_key),y_axis_data_key:r(o.y_axis_data_key)}}}catch(n){throw console.error("[Migration failed]",n),n}}class dm extends ve{constructor(){super(...arguments);N(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:um(n.config)})),this.version(3,(n,r)=>{const{config:a}=n;return{...n,version:3,config:cm(a,r)}})}}const pm={displayName:"Regression Chart",displayGroup:"Merico suite",migrator:new dm,name:"regressionChart",viewRender:nm,configRender:lm,createConfig(){return{version:3,config:x.cloneDeep(Fr)}}},On={content:""},Gr={fontSize:"14px",lineHeight:"32px",color:"#3D3E45",ul:{paddingLeft:"2em",margin:"6px 0 0"},p:{margin:0},a:{WebkitTapHighlightColor:"transparent",color:"rgb(34, 139, 230)",textDecoration:"none","&:hover":{textDecoration:"underline"},"&:active, &:hover":{outlineWidth:0}},table:{tr:{"th, td":{padding:"0 .5em"}}},"table.rich-text-table-render, div.tableWrapper table":{"th, td":{border:"1px solid #eaeaea"},"tr:last-of-type td":{borderBottom:"1px solid #eaeaea"}},".resize-cursor":{cursor:"col-resize"},details:{summary:{listStyle:"none",cursor:"pointer",transition:"color 300ms ease",userSelect:"none"},"summary::-webkit-details-marker":{display:"none"},"summary:hover":{color:"black","&::before":{opacity:1}},"summary::before":{content:'"►"',fontSize:"10px",margin:"0px 5px",opacity:.5,display:"inline-block",transition:"opacity 300ms ease, transform 300ms ease"}},"details[open] summary::before":{transform:"rotate(90deg)"},"details + details":{marginTop:"10px"},blockquote:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45",margin:"0 0 14px"}};function Ks(t,e,n){for(let r=0;;r++){if(r==t.childCount||r==e.childCount)return t.childCount==e.childCount?null:n;let a=t.child(r),o=e.child(r);if(a==o){n+=a.nodeSize;continue}if(!a.sameMarkup(o))return n;if(a.isText&&a.text!=o.text){for(let l=0;a.text[l]==o.text[l];l++)n++;return n}if(a.content.size||o.content.size){let l=Ks(a.content,o.content,n+1);if(l!=null)return l}n+=a.nodeSize}}function Us(t,e,n,r){for(let a=t.childCount,o=e.childCount;;){if(a==0||o==0)return a==o?null:{a:n,b:r};let l=t.child(--a),u=e.child(--o),c=l.nodeSize;if(l==u){n-=c,r-=c;continue}if(!l.sameMarkup(u))return{a:n,b:r};if(l.isText&&l.text!=u.text){let d=0,f=Math.min(l.text.length,u.text.length);for(;d<f&&l.text[l.text.length-d-1]==u.text[u.text.length-d-1];)d++,n--,r--;return{a:n,b:r}}if(l.content.size||u.content.size){let d=Us(l.content,u.content,n-1,r-1);if(d)return d}n-=c,r-=c}}class ae{constructor(e,n){if(this.content=e,this.size=n||0,n==null)for(let r=0;r<e.length;r++)this.size+=e[r].nodeSize}nodesBetween(e,n,r,a=0,o){for(let l=0,u=0;u<n;l++){let c=this.content[l],d=u+c.nodeSize;if(d>e&&r(c,a+u,o||null,l)!==!1&&c.content.size){let f=u+1;c.nodesBetween(Math.max(0,e-f),Math.min(c.content.size,n-f),r,a+f)}u=d}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,r,a){let o="",l=!0;return this.nodesBetween(e,n,(u,c)=>{u.isText?(o+=u.text.slice(Math.max(e,c)-c,n-c),l=!r):u.isLeaf?(a?o+=typeof a=="function"?a(u):a:u.type.spec.leafText&&(o+=u.type.spec.leafText(u)),l=!r):!l&&u.isBlock&&(o+=r,l=!0)},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,r=e.firstChild,a=this.content.slice(),o=0;for(n.isText&&n.sameMarkup(r)&&(a[a.length-1]=n.withText(n.text+r.text),o=1);o<e.content.length;o++)a.push(e.content[o]);return new ae(a,this.size+e.size)}cut(e,n=this.size){if(e==0&&n==this.size)return this;let r=[],a=0;if(n>e)for(let o=0,l=0;l<n;o++){let u=this.content[o],c=l+u.nodeSize;c>e&&((l<e||c>n)&&(u.isText?u=u.cut(Math.max(0,e-l),Math.min(u.text.length,n-l)):u=u.cut(Math.max(0,e-l-1),Math.min(u.content.size,n-l-1))),r.push(u),a+=u.nodeSize),l=c}return new ae(r,a)}cutByIndex(e,n){return e==n?ae.empty:e==0&&n==this.content.length?this:new ae(this.content.slice(e,n))}replaceChild(e,n){let r=this.content[e];if(r==n)return this;let a=this.content.slice(),o=this.size+n.nodeSize-r.nodeSize;return a[e]=n,new ae(a,o)}addToStart(e){return new ae([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new ae(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let n=0;n<this.content.length;n++)if(!this.content[n].eq(e.content[n]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let n=this.content[e];if(!n)throw new RangeError("Index "+e+" out of range for "+this);return n}maybeChild(e){return this.content[e]||null}forEach(e){for(let n=0,r=0;n<this.content.length;n++){let a=this.content[n];e(a,r,n),r+=a.nodeSize}}findDiffStart(e,n=0){return Ks(this,e,n)}findDiffEnd(e,n=this.size,r=e.size){return Us(this,e,n,r)}findIndex(e,n=-1){if(e==0)return Pn(0,e);if(e==this.size)return Pn(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,a=0;;r++){let o=this.child(r),l=a+o.nodeSize;if(l>=e)return l==e||n>0?Pn(r+1,l):Pn(r,a);a=l}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,n){if(!n)return ae.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new ae(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return ae.empty;let n,r=0;for(let a=0;a<e.length;a++){let o=e[a];r+=o.nodeSize,a&&o.isText&&e[a-1].sameMarkup(o)?(n||(n=e.slice(0,a)),n[n.length-1]=o.withText(n[n.length-1].text+o.text)):n&&n.push(o)}return new ae(n||e,r)}static from(e){if(!e)return ae.empty;if(e instanceof ae)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new ae([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}ae.empty=new ae([],0);const Wr={index:0,offset:0};function Pn(t,e){return Wr.index=t,Wr.offset=e,Wr}function jr(t,e){if(t===e)return!0;if(!(t&&typeof t=="object")||!(e&&typeof e=="object"))return!1;let n=Array.isArray(t);if(Array.isArray(e)!=n)return!1;if(n){if(t.length!=e.length)return!1;for(let r=0;r<t.length;r++)if(!jr(t[r],e[r]))return!1}else{for(let r in t)if(!(r in e)||!jr(t[r],e[r]))return!1;for(let r in e)if(!(r in t))return!1}return!0}class We{constructor(e,n){this.type=e,this.attrs=n}addToSet(e){let n,r=!1;for(let a=0;a<e.length;a++){let o=e[a];if(this.eq(o))return e;if(this.type.excludes(o.type))n||(n=e.slice(0,a));else{if(o.type.excludes(this.type))return e;!r&&o.type.rank>this.type.rank&&(n||(n=e.slice(0,a)),n.push(this),r=!0),n&&n.push(o)}}return n||(n=e.slice()),r||n.push(this),n}removeFromSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return e.slice(0,n).concat(e.slice(n+1));return e}isInSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return!0;return!1}eq(e){return this==e||this.type==e.type&&jr(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Mark.fromJSON");let r=e.marks[n.type];if(!r)throw new RangeError(`There is no mark type ${n.type} in this schema`);return r.create(n.attrs)}static sameSet(e,n){if(e==n)return!0;if(e.length!=n.length)return!1;for(let r=0;r<e.length;r++)if(!e[r].eq(n[r]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return We.none;if(e instanceof We)return[e];let n=e.slice();return n.sort((r,a)=>r.type.rank-a.type.rank),n}}We.none=[];class hm extends Error{}class ce{constructor(e,n,r){this.content=e,this.openStart=n,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,n){let r=Js(this.content,e+this.openStart,n);return r&&new ce(r,this.openStart,this.openEnd)}removeBetween(e,n){return new ce(Xs(this.content,e+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,n){if(!n)return ce.empty;let r=n.openStart||0,a=n.openEnd||0;if(typeof r!="number"||typeof a!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new ce(ae.fromJSON(e,n.content),r,a)}static maxOpen(e,n=!0){let r=0,a=0;for(let o=e.firstChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.lastChild)a++;return new ce(e,r,a)}}ce.empty=new ce(ae.empty,0,0);function Xs(t,e,n){let{index:r,offset:a}=t.findIndex(e),o=t.maybeChild(r),{index:l,offset:u}=t.findIndex(n);if(a==e||o.isText){if(u!=n&&!t.child(l).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(r!=l)throw new RangeError("Removing non-flat range");return t.replaceChild(r,o.copy(Xs(o.content,e-a-1,n-a-1)))}function Js(t,e,n,r){let{index:a,offset:o}=t.findIndex(e),l=t.maybeChild(a);if(o==e||l.isText)return r&&!r.canReplace(a,a,n)?null:t.cut(0,e).append(n).append(t.cut(e));let u=Js(l.content,e-o-1,n);return u&&t.replaceChild(a,l.copy(u))}class Bn{constructor(e,n){this.schema=e,this.rules=n,this.tags=[],this.styles=[],n.forEach(r=>{r.tag?this.tags.push(r):r.style&&this.styles.push(r)}),this.normalizeLists=!this.tags.some(r=>{if(!/^(ul|ol)\b/.test(r.tag)||!r.node)return!1;let a=e.nodes[r.node];return a.contentMatch.matchType(a)})}parse(e,n={}){let r=new to(this,n,!1);return r.addAll(e,n.from,n.to),r.finish()}parseSlice(e,n={}){let r=new to(this,n,!0);return r.addAll(e,n.from,n.to),ce.maxOpen(r.finish())}matchTag(e,n,r){for(let a=r?this.tags.indexOf(r)+1:0;a<this.tags.length;a++){let o=this.tags[a];if(mm(e,o.tag)&&(o.namespace===void 0||e.namespaceURI==o.namespace)&&(!o.context||n.matchesContext(o.context))){if(o.getAttrs){let l=o.getAttrs(e);if(l===!1)continue;o.attrs=l||void 0}return o}}}matchStyle(e,n,r,a){for(let o=a?this.styles.indexOf(a)+1:0;o<this.styles.length;o++){let l=this.styles[o],u=l.style;if(!(u.indexOf(e)!=0||l.context&&!r.matchesContext(l.context)||u.length>e.length&&(u.charCodeAt(e.length)!=61||u.slice(e.length+1)!=n))){if(l.getAttrs){let c=l.getAttrs(n);if(c===!1)continue;l.attrs=c||void 0}return l}}}static schemaRules(e){let n=[];function r(a){let o=a.priority==null?50:a.priority,l=0;for(;l<n.length;l++){let u=n[l];if((u.priority==null?50:u.priority)<o)break}n.splice(l,0,a)}for(let a in e.marks){let o=e.marks[a].spec.parseDOM;o&&o.forEach(l=>{r(l=no(l)),l.mark||l.ignore||l.clearMark||(l.mark=a)})}for(let a in e.nodes){let o=e.nodes[a].spec.parseDOM;o&&o.forEach(l=>{r(l=no(l)),l.node||l.ignore||l.mark||(l.node=a)})}return n}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new Bn(e,Bn.schemaRules(e)))}}const Zs={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},fm={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Hs={ol:!0,ul:!0},Vn=1,Nn=2,Zt=4;function eo(t,e,n){return e!=null?(e?Vn:0)|(e==="full"?Nn:0):t&&t.whitespace=="pre"?Vn|Nn:n&~Zt}class qn{constructor(e,n,r,a,o,l,u){this.type=e,this.attrs=n,this.marks=r,this.pendingMarks=a,this.solid=o,this.options=u,this.content=[],this.activeMarks=We.none,this.stashMarks=[],this.match=l||(u&Zt?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(ae.from(e));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,a;return(a=r.findWrapping(e.type))?(this.match=r,a):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Vn)){let r=this.content[this.content.length-1],a;if(r&&r.isText&&(a=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==a[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-a[0].length))}}let n=ae.from(this.content);return!e&&this.match&&(n=n.append(this.match.fillBefore(ae.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}popFromStashMark(e){for(let n=this.stashMarks.length-1;n>=0;n--)if(e.eq(this.stashMarks[n]))return this.stashMarks.splice(n,1)[0]}applyPending(e){for(let n=0,r=this.pendingMarks;n<r.length;n++){let a=r[n];(this.type?this.type.allowsMarkType(a.type):bm(a.type,e))&&!a.isInSet(this.activeMarks)&&(this.activeMarks=a.addToSet(this.activeMarks),this.pendingMarks=a.removeFromSet(this.pendingMarks))}}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Zs.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class to{constructor(e,n,r){this.parser=e,this.options=n,this.isOpen=r,this.open=0;let a=n.topNode,o,l=eo(null,n.preserveWhitespace,0)|(r?Zt:0);a?o=new qn(a.type,a.attrs,We.none,We.none,!0,n.topMatch||a.type.contentMatch,l):r?o=new qn(null,null,We.none,We.none,!0,null,l):o=new qn(e.schema.topNodeType,null,We.none,We.none,!0,null,l),this.nodes=[o],this.find=n.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e){if(e.nodeType==3)this.addTextNode(e);else if(e.nodeType==1){let n=e.getAttribute("style");if(!n)this.addElement(e);else{let r=this.readStyles(ym(n));if(!r)return;let[a,o]=r,l=this.top;for(let u=0;u<o.length;u++)this.removePendingMark(o[u],l);for(let u=0;u<a.length;u++)this.addPendingMark(a[u]);this.addElement(e);for(let u=0;u<a.length;u++)this.removePendingMark(a[u],l);for(let u=0;u<o.length;u++)this.addPendingMark(o[u])}}}addTextNode(e){let n=e.nodeValue,r=this.top;if(r.options&Nn||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(r.options&Vn)r.options&Nn?n=n.replace(/\r\n?/g,`
308
- `):n=n.replace(/\r?\n|\r/g," ");else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let a=r.content[r.content.length-1],o=e.previousSibling;(!a||o&&o.nodeName=="BR"||a.isText&&/[ \t\r\n\u000c]$/.test(a.text))&&(n=n.slice(1))}n&&this.insertNode(this.parser.schema.text(n)),this.findInText(e)}else this.findInside(e)}addElement(e,n){let r=e.nodeName.toLowerCase(),a;Hs.hasOwnProperty(r)&&this.parser.normalizeLists&&gm(e);let o=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(a=this.parser.matchTag(e,this,n));if(o?o.ignore:fm.hasOwnProperty(r))this.findInside(e),this.ignoreFallback(e);else if(!o||o.skip||o.closeParent){o&&o.closeParent?this.open=Math.max(0,this.open-1):o&&o.skip.nodeType&&(e=o.skip);let l,u=this.top,c=this.needsBlock;if(Zs.hasOwnProperty(r))u.content.length&&u.content[0].isInline&&this.open&&(this.open--,u=this.top),l=!0,u.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e);return}this.addAll(e),l&&this.sync(u),this.needsBlock=c}else this.addElementByRule(e,o,o.consuming===!1?a:void 0)}leafFallback(e){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
309
- `))}ignoreFallback(e){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(e){let n=We.none,r=We.none;for(let a=0;a<e.length;a+=2)for(let o=void 0;;){let l=this.parser.matchStyle(e[a],e[a+1],this,o);if(!l)break;if(l.ignore)return null;if(l.clearMark?this.top.pendingMarks.concat(this.top.activeMarks).forEach(u=>{l.clearMark(u)&&(r=u.addToSet(r))}):n=this.parser.schema.marks[l.mark].create(l.attrs).addToSet(n),l.consuming===!1)o=l;else break}return[n,r]}addElementByRule(e,n,r){let a,o,l;n.node?(o=this.parser.schema.nodes[n.node],o.isLeaf?this.insertNode(o.create(n.attrs))||this.leafFallback(e):a=this.enter(o,n.attrs||null,n.preserveWhitespace)):(l=this.parser.schema.marks[n.mark].create(n.attrs),this.addPendingMark(l));let u=this.top;if(o&&o.isLeaf)this.findInside(e);else if(r)this.addElement(e,r);else if(n.getContent)this.findInside(e),n.getContent(e,this.parser.schema).forEach(c=>this.insertNode(c));else{let c=e;typeof n.contentElement=="string"?c=e.querySelector(n.contentElement):typeof n.contentElement=="function"?c=n.contentElement(e):n.contentElement&&(c=n.contentElement),this.findAround(e,c,!0),this.addAll(c)}a&&this.sync(u)&&this.open--,l&&this.removePendingMark(l,u)}addAll(e,n,r){let a=n||0;for(let o=n?e.childNodes[n]:e.firstChild,l=r==null?null:e.childNodes[r];o!=l;o=o.nextSibling,++a)this.findAtPoint(e,a),this.addDOM(o);this.findAtPoint(e,a)}findPlace(e){let n,r;for(let a=this.open;a>=0;a--){let o=this.nodes[a],l=o.findWrapping(e);if(l&&(!n||n.length>l.length)&&(n=l,r=o,!l.length)||o.solid)break}if(!n)return!1;this.sync(r);for(let a=0;a<n.length;a++)this.enterInner(n[a],null,!1);return!0}insertNode(e){if(e.isInline&&this.needsBlock&&!this.top.type){let n=this.textblockFromContext();n&&this.enterInner(n)}if(this.findPlace(e)){this.closeExtra();let n=this.top;n.applyPending(e.type),n.match&&(n.match=n.match.matchType(e.type));let r=n.activeMarks;for(let a=0;a<e.marks.length;a++)(!n.type||n.type.allowsMarkType(e.marks[a].type))&&(r=e.marks[a].addToSet(r));return n.content.push(e.mark(r)),!0}return!1}enter(e,n,r){let a=this.findPlace(e.create(n));return a&&this.enterInner(e,n,!0,r),a}enterInner(e,n=null,r=!1,a){this.closeExtra();let o=this.top;o.applyPending(e),o.match=o.match&&o.match.matchType(e);let l=eo(e,a,o.options);o.options&Zt&&o.content.length==0&&(l|=Zt),this.nodes.push(new qn(e,n,o.activeMarks,o.pendingMarks,r,null,l)),this.open++}closeExtra(e=!1){let n=this.nodes.length-1;if(n>this.open){for(;n>this.open;n--)this.nodes[n-1].content.push(this.nodes[n].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let n=this.open;n>=0;n--)if(this.nodes[n]==e)return this.open=n,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let n=this.open;n>=0;n--){let r=this.nodes[n].content;for(let a=r.length-1;a>=0;a--)e+=r[a].nodeSize;n&&e++}return e}findAtPoint(e,n){if(this.find)for(let r=0;r<this.find.length;r++)this.find[r].node==e&&this.find[r].offset==n&&(this.find[r].pos=this.currentPos)}findInside(e){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].pos==null&&e.nodeType==1&&e.contains(this.find[n].node)&&(this.find[n].pos=this.currentPos)}findAround(e,n,r){if(e!=n&&this.find)for(let a=0;a<this.find.length;a++)this.find[a].pos==null&&e.nodeType==1&&e.contains(this.find[a].node)&&n.compareDocumentPosition(this.find[a].node)&(r?2:4)&&(this.find[a].pos=this.currentPos)}findInText(e){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&(this.find[n].pos=this.currentPos-(e.nodeValue.length-this.find[n].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let n=e.split("/"),r=this.options.context,a=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(a?0:1),l=(u,c)=>{for(;u>=0;u--){let d=n[u];if(d==""){if(u==n.length-1||u==0)continue;for(;c>=o;c--)if(l(u-1,c))return!0;return!1}else{let f=c>0||c==0&&a?this.nodes[c].type:r&&c>=o?r.node(c-o).type:null;if(!f||f.name!=d&&f.groups.indexOf(d)==-1)return!1;c--}}return!0};return l(n.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let n=e.depth;n>=0;n--){let r=e.node(n).contentMatchAt(e.indexAfter(n)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let n in this.parser.schema.nodes){let r=this.parser.schema.nodes[n];if(r.isTextblock&&r.defaultAttrs)return r}}addPendingMark(e){let n=vm(e,this.top.pendingMarks);n&&this.top.stashMarks.push(n),this.top.pendingMarks=e.addToSet(this.top.pendingMarks)}removePendingMark(e,n){for(let r=this.open;r>=0;r--){let a=this.nodes[r];if(a.pendingMarks.lastIndexOf(e)>-1)a.pendingMarks=e.removeFromSet(a.pendingMarks);else{a.activeMarks=e.removeFromSet(a.activeMarks);let l=a.popFromStashMark(e);l&&a.type&&a.type.allowsMarkType(l.type)&&(a.activeMarks=l.addToSet(a.activeMarks))}if(a==n)break}}}function gm(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&Hs.hasOwnProperty(r)&&n?(n.appendChild(e),e=n):r=="li"?n=e:r&&(n=null)}}function mm(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function ym(t){let e=/\s*([\w-]+)\s*:\s*([^;]+)/g,n,r=[];for(;n=e.exec(t);)r.push(n[1],n[2].trim());return r}function no(t){let e={};for(let n in t)e[n]=t[n];return e}function bm(t,e){let n=e.schema.nodes;for(let r in n){let a=n[r];if(!a.allowsMarkType(t))continue;let o=[],l=u=>{o.push(u);for(let c=0;c<u.edgeCount;c++){let{type:d,next:f}=u.edge(c);if(d==e||o.indexOf(f)<0&&l(f))return!0}};if(l(a.contentMatch))return!0}}function vm(t,e){for(let n=0;n<e.length;n++)if(t.eq(e[n]))return e[n]}const ro=65535,io=Math.pow(2,16);function xm(t,e){return t+e*io}function ao(t){return t&ro}function wm(t){return(t-(t&ro))/io}const so=1,oo=2,Fn=4,lo=8;class uo{constructor(e,n,r){this.pos=e,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&lo)>0}get deletedBefore(){return(this.delInfo&(so|Fn))>0}get deletedAfter(){return(this.delInfo&(oo|Fn))>0}get deletedAcross(){return(this.delInfo&Fn)>0}}class Ye{constructor(e,n=!1){if(this.ranges=e,this.inverted=n,!e.length&&Ye.empty)return Ye.empty}recover(e){let n=0,r=ao(e);if(!this.inverted)for(let a=0;a<r;a++)n+=this.ranges[a*3+2]-this.ranges[a*3+1];return this.ranges[r*3]+n+wm(e)}mapResult(e,n=1){return this._map(e,n,!1)}map(e,n=1){return this._map(e,n,!0)}_map(e,n,r){let a=0,o=this.inverted?2:1,l=this.inverted?1:2;for(let u=0;u<this.ranges.length;u+=3){let c=this.ranges[u]-(this.inverted?a:0);if(c>e)break;let d=this.ranges[u+o],f=this.ranges[u+l],h=c+d;if(e<=h){let g=d?e==c?-1:e==h?1:n:n,m=c+a+(g<0?0:f);if(r)return m;let w=e==(n<0?c:h)?null:xm(u/3,e-c),C=e==c?oo:e==h?so:Fn;return(n<0?e!=c:e!=h)&&(C|=lo),new uo(m,C,w)}a+=f-d}return r?e+a:new uo(e+a,0,null)}touches(e,n){let r=0,a=ao(n),o=this.inverted?2:1,l=this.inverted?1:2;for(let u=0;u<this.ranges.length;u+=3){let c=this.ranges[u]-(this.inverted?r:0);if(c>e)break;let d=this.ranges[u+o],f=c+d;if(e<=f&&u==a*3)return!0;r+=this.ranges[u+l]-d}return!1}forEach(e){let n=this.inverted?2:1,r=this.inverted?1:2;for(let a=0,o=0;a<this.ranges.length;a+=3){let l=this.ranges[a],u=l-(this.inverted?o:0),c=l+(this.inverted?0:o),d=this.ranges[a+n],f=this.ranges[a+r];e(u,u+d,c,c+f),o+=f-d}}invert(){return new Ye(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?Ye.empty:new Ye(e<0?[0,-e,0]:[0,0,e])}}Ye.empty=new Ye([]);const Rr=Object.create(null);class Ge{getMap(){return Ye.empty}merge(e){return null}static fromJSON(e,n){if(!n||!n.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=Rr[n.stepType];if(!r)throw new RangeError(`No step type ${n.stepType} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in Rr)throw new RangeError("Duplicate use of step JSON ID "+e);return Rr[e]=n,n.prototype.jsonID=e,n}}class _e{constructor(e,n){this.doc=e,this.failed=n}static ok(e){return new _e(e,null)}static fail(e){return new _e(null,e)}static fromReplace(e,n,r,a){try{return _e.ok(e.replace(n,r,a))}catch(o){if(o instanceof hm)return _e.fail(o.message);throw o}}}function Yr(t,e,n){let r=[];for(let a=0;a<t.childCount;a++){let o=t.child(a);o.content.size&&(o=o.copy(Yr(o.content,e,o))),o.isInline&&(o=e(o,n,a)),r.push(o)}return ae.fromArray(r)}class Tt extends Ge{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=e.resolve(this.from),a=r.node(r.sharedDepth(this.to)),o=new ce(Yr(n.content,(l,u)=>!l.isAtom||!u.type.allowsMarkType(this.mark.type)?l:l.mark(this.mark.addToSet(l.marks)),a),n.openStart,n.openEnd);return _e.fromReplace(e,this.from,this.to,o)}invert(){return new Dt(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new Tt(n.pos,r.pos,this.mark)}merge(e){return e instanceof Tt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Tt(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Tt(n.from,n.to,e.markFromJSON(n.mark))}}Ge.jsonID("addMark",Tt);class Dt extends Ge{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=new ce(Yr(n.content,a=>a.mark(this.mark.removeFromSet(a.marks)),e),n.openStart,n.openEnd);return _e.fromReplace(e,this.from,this.to,r)}invert(){return new Tt(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new Dt(n.pos,r.pos,this.mark)}merge(e){return e instanceof Dt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Dt(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new Dt(n.from,n.to,e.markFromJSON(n.mark))}}Ge.jsonID("removeMark",Dt);class Mt extends Ge{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return _e.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return _e.fromReplace(e,this.pos,this.pos+1,new ce(ae.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);if(n){let r=this.mark.addToSet(n.marks);if(r.length==n.marks.length){for(let a=0;a<n.marks.length;a++)if(!n.marks[a].isInSet(r))return new Mt(this.pos,n.marks[a]);return new Mt(this.pos,this.mark)}}return new Ht(this.pos,this.mark)}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new Mt(n.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new Mt(n.pos,e.markFromJSON(n.mark))}}Ge.jsonID("addNodeMark",Mt);class Ht extends Ge{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return _e.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.removeFromSet(n.marks));return _e.fromReplace(e,this.pos,this.pos+1,new ce(ae.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);return!n||!this.mark.isInSet(n.marks)?this:new Mt(this.pos,this.mark)}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new Ht(n.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new Ht(n.pos,e.markFromJSON(n.mark))}}Ge.jsonID("removeNodeMark",Ht);class rt extends Ge{constructor(e,n,r,a=!1){super(),this.from=e,this.to=n,this.slice=r,this.structure=a}apply(e){return this.structure&&Qr(e,this.from,this.to)?_e.fail("Structure replace would overwrite content"):_e.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new Ye([this.from,this.to-this.from,this.slice.size])}invert(e){return new rt(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deletedAcross&&r.deletedAcross?null:new rt(n.pos,Math.max(n.pos,r.pos),this.slice)}merge(e){if(!(e instanceof rt)||e.structure||this.structure)return null;if(this.from+this.slice.size==e.from&&!this.slice.openEnd&&!e.slice.openStart){let n=this.slice.size+e.slice.size==0?ce.empty:new ce(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new rt(this.from,this.to+(e.to-e.from),n,this.structure)}else if(e.to==this.from&&!this.slice.openStart&&!e.slice.openEnd){let n=this.slice.size+e.slice.size==0?ce.empty:new ce(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new rt(e.from,this.to,n,this.structure)}else return null}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new rt(n.from,n.to,ce.fromJSON(e,n.slice),!!n.structure)}}Ge.jsonID("replace",rt);class It extends Ge{constructor(e,n,r,a,o,l,u=!1){super(),this.from=e,this.to=n,this.gapFrom=r,this.gapTo=a,this.slice=o,this.insert=l,this.structure=u}apply(e){if(this.structure&&(Qr(e,this.from,this.gapFrom)||Qr(e,this.gapTo,this.to)))return _e.fail("Structure gap-replace would overwrite content");let n=e.slice(this.gapFrom,this.gapTo);if(n.openStart||n.openEnd)return _e.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,n.content);return r?_e.fromReplace(e,this.from,this.to,r):_e.fail("Content does not fit in gap")}getMap(){return new Ye([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let n=this.gapTo-this.gapFrom;return new It(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1),a=e.map(this.gapFrom,-1),o=e.map(this.gapTo,1);return n.deletedAcross&&r.deletedAcross||a<n.pos||o>r.pos?null:new It(n.pos,r.pos,a,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new It(n.from,n.to,n.gapFrom,n.gapTo,ce.fromJSON(e,n.slice),n.insert,!!n.structure)}}Ge.jsonID("replaceAround",It);function Qr(t,e,n){let r=t.resolve(e),a=n-e,o=r.depth;for(;a>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,a--;if(a>0){let l=r.node(o).maybeChild(r.indexAfter(o));for(;a>0;){if(!l||l.isLeaf)return!0;l=l.firstChild,a--}}return!1}function Cm(t,e,n){return(e==0||t.canReplace(e,t.childCount))&&(n==t.childCount||t.canReplace(0,n))}function Sm(t){let n=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let r=t.depth;;--r){let a=t.$from.node(r),o=t.$from.index(r),l=t.$to.indexAfter(r);if(r<t.depth&&a.canReplace(o,l,n))return r;if(r==0||a.type.spec.isolating||!Cm(a,o,l))break}return null}function Gn(t,e,n=1,r){let a=t.resolve(e),o=a.depth-n,l=r&&r[r.length-1]||a.parent;if(o<0||a.parent.type.spec.isolating||!a.parent.canReplace(a.index(),a.parent.childCount)||!l.type.validContent(a.parent.content.cutByIndex(a.index(),a.parent.childCount)))return!1;for(let d=a.depth-1,f=n-2;d>o;d--,f--){let h=a.node(d),g=a.index(d);if(h.type.spec.isolating)return!1;let m=h.content.cutByIndex(g,h.childCount),w=r&&r[f+1];w&&(m=m.replaceChild(0,w.type.create(w.attrs)));let C=r&&r[f]||h;if(!h.canReplace(g+1,h.childCount)||!C.type.validContent(m))return!1}let u=a.indexAfter(o),c=r&&r[0];return a.node(o).canReplaceWith(u,u,c?c.type:a.node(o+1).type)}function co(t,e){let n=t.resolve(e),r=n.index();return _m(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function _m(t,e){return!!(t&&e&&!t.isLeaf&&t.canAppend(e))}class en extends Ge{constructor(e,n,r){super(),this.pos=e,this.attr=n,this.value=r}apply(e){let n=e.nodeAt(this.pos);if(!n)return _e.fail("No node at attribute step's position");let r=Object.create(null);for(let o in n.attrs)r[o]=n.attrs[o];r[this.attr]=this.value;let a=n.type.create(r,null,n.marks);return _e.fromReplace(e,this.pos,this.pos+1,new ce(ae.from(a),0,n.isLeaf?0:1))}getMap(){return Ye.empty}invert(e){return new en(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new en(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new en(n.pos,n.attr,n.value)}}Ge.jsonID("attr",en);let tn=class extends Error{};tn=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n},tn.prototype=Object.create(Error.prototype),tn.prototype.constructor=tn,tn.prototype.name="TransformError";const Kr=Object.create(null);class fe{constructor(e,n,r){this.$anchor=e,this.$head=n,this.ranges=r||[new km(e.min(n),e.max(n))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let n=0;n<e.length;n++)if(e[n].$from.pos!=e[n].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,n=ce.empty){let r=n.content.lastChild,a=null;for(let u=0;u<n.openEnd;u++)a=r,r=r.lastChild;let o=e.steps.length,l=this.ranges;for(let u=0;u<l.length;u++){let{$from:c,$to:d}=l[u],f=e.mapping.slice(o);e.replaceRange(f.map(c.pos),f.map(d.pos),u?ce.empty:n),u==0&&fo(e,o,(r?r.isInline:a&&a.isTextblock)?-1:1)}}replaceWith(e,n){let r=e.steps.length,a=this.ranges;for(let o=0;o<a.length;o++){let{$from:l,$to:u}=a[o],c=e.mapping.slice(r),d=c.map(l.pos),f=c.map(u.pos);o?e.deleteRange(d,f):(e.replaceRangeWith(d,f,n),fo(e,r,n.isInline?-1:1))}}static findFrom(e,n,r=!1){let a=e.parent.inlineContent?new ke(e):Vt(e.node(0),e.parent,e.pos,e.index(),n,r);if(a)return a;for(let o=e.depth-1;o>=0;o--){let l=n<0?Vt(e.node(0),e.node(o),e.before(o+1),e.index(o),n,r):Vt(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,n,r);if(l)return l}return null}static near(e,n=1){return this.findFrom(e,n)||this.findFrom(e,-n)||new ct(e.node(0))}static atStart(e){return Vt(e,e,0,0,1)||new ct(e)}static atEnd(e){return Vt(e,e,e.content.size,e.childCount,-1)||new ct(e)}static fromJSON(e,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=Kr[n.type];if(!r)throw new RangeError(`No selection type ${n.type} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in Kr)throw new RangeError("Duplicate use of selection JSON ID "+e);return Kr[e]=n,n.prototype.jsonID=e,n}getBookmark(){return ke.between(this.$anchor,this.$head).getBookmark()}}fe.prototype.visible=!0;class km{constructor(e,n){this.$from=e,this.$to=n}}let po=!1;function ho(t){!po&&!t.parent.inlineContent&&(po=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}class ke extends fe{constructor(e,n=e){ho(e),ho(n),super(e,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,n){let r=e.resolve(n.map(this.head));if(!r.parent.inlineContent)return fe.near(r);let a=e.resolve(n.map(this.anchor));return new ke(a.parent.inlineContent?a:r,r)}replace(e,n=ce.empty){if(super.replace(e,n),n==ce.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof ke&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Wn(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,n){if(typeof n.anchor!="number"||typeof n.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new ke(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,r=n){let a=e.resolve(n);return new this(a,r==n?a:e.resolve(r))}static between(e,n,r){let a=e.pos-n.pos;if((!r||a)&&(r=a>=0?1:-1),!n.parent.inlineContent){let o=fe.findFrom(n,r,!0)||fe.findFrom(n,-r,!0);if(o)n=o.$head;else return fe.near(n,r)}return e.parent.inlineContent||(a==0?e=n:(e=(fe.findFrom(e,-r,!0)||fe.findFrom(e,r,!0)).$anchor,e.pos<n.pos!=a<0&&(e=n))),new ke(e,n)}}fe.jsonID("text",ke);class Wn{constructor(e,n){this.anchor=e,this.head=n}map(e){return new Wn(e.map(this.anchor),e.map(this.head))}resolve(e){return ke.between(e.resolve(this.anchor),e.resolve(this.head))}}class je extends fe{constructor(e){let n=e.nodeAfter,r=e.node(0).resolve(e.pos+n.nodeSize);super(e,r),this.node=n}map(e,n){let{deleted:r,pos:a}=n.mapResult(this.anchor),o=e.resolve(a);return r?fe.near(o):new je(o)}content(){return new ce(ae.from(this.node),0,0)}eq(e){return e instanceof je&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Ur(this.anchor)}static fromJSON(e,n){if(typeof n.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new je(e.resolve(n.anchor))}static create(e,n){return new je(e.resolve(n))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}}je.prototype.visible=!1,fe.jsonID("node",je);class Ur{constructor(e){this.anchor=e}map(e){let{deleted:n,pos:r}=e.mapResult(this.anchor);return n?new Wn(r,r):new Ur(r)}resolve(e){let n=e.resolve(this.anchor),r=n.nodeAfter;return r&&je.isSelectable(r)?new je(n):fe.near(n)}}class ct extends fe{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,n=ce.empty){if(n==ce.empty){e.delete(0,e.doc.content.size);let r=fe.atStart(e.doc);r.eq(e.selection)||e.setSelection(r)}else super.replace(e,n)}toJSON(){return{type:"all"}}static fromJSON(e){return new ct(e)}map(e){return new ct(e)}eq(e){return e instanceof ct}getBookmark(){return Tm}}fe.jsonID("all",ct);const Tm={map(){return this},resolve(t){return new ct(t)}};function Vt(t,e,n,r,a,o=!1){if(e.inlineContent)return ke.create(t,n);for(let l=r-(a>0?0:1);a>0?l<e.childCount:l>=0;l+=a){let u=e.child(l);if(u.isAtom){if(!o&&je.isSelectable(u))return je.create(t,n-(a<0?u.nodeSize:0))}else{let c=Vt(t,u,n+a,a<0?u.childCount:0,a,o);if(c)return c}n+=u.nodeSize*a}return null}function fo(t,e,n){let r=t.steps.length-1;if(r<e)return;let a=t.steps[r];if(!(a instanceof rt||a instanceof It))return;let o=t.mapping.maps[r],l;o.forEach((u,c,d,f)=>{l==null&&(l=f)}),t.setSelection(fe.near(t.doc.resolve(l),n))}function go(t,e){return!e||!t?t:t.bind(e)}class jn{constructor(e,n,r){this.name=e,this.init=go(n.init,r),this.apply=go(n.apply,r)}}new jn("doc",{init(t){return t.doc||t.schema.topNodeType.createAndFill()},apply(t){return t.doc}}),new jn("selection",{init(t,e){return t.selection||fe.atStart(e.doc)},apply(t){return t.selection}}),new jn("storedMarks",{init(t){return t.storedMarks||null},apply(t,e,n,r){return r.selection.$cursor?t.storedMarks:null}}),new jn("scrollToSelection",{init(){return 0},apply(t,e){return t.scrolledIntoView?e+1:e}});function mo(t,e,n){for(let r in t){let a=t[r];a instanceof Function?a=a.bind(e):r=="handleDOMEvents"&&(a=mo(a,e,{})),n[r]=a}return n}class nn{constructor(e){this.spec=e,this.props={},e.props&&mo(e.props,this,this.props),this.key=e.key?e.key.key:yo("plugin")}getState(e){return e[this.key]}}const Xr=Object.create(null);function yo(t){return t in Xr?t+"$"+ ++Xr[t]:(Xr[t]=0,t+"$")}class rn{constructor(e="key"){this.key=yo(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}function bo(t){const{state:e,transaction:n}=t;let{selection:r}=n,{doc:a}=n,{storedMarks:o}=n;return{...e,apply:e.apply.bind(e),applyTransaction:e.applyTransaction.bind(e),filterTransaction:e.filterTransaction,plugins:e.plugins,schema:e.schema,reconfigure:e.reconfigure.bind(e),toJSON:e.toJSON.bind(e),get storedMarks(){return o},get selection(){return r},get doc(){return a},get tr(){return r=n.selection,a=n.doc,o=n.storedMarks,n}}}class Dm{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:e,editor:n,state:r}=this,{view:a}=n,{tr:o}=r,l=this.buildProps(o);return Object.fromEntries(Object.entries(e).map(([u,c])=>[u,(...f)=>{const h=c(...f)(l);return!o.getMeta("preventDispatch")&&!this.hasCustomState&&a.dispatch(o),h}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,n=!0){const{rawCommands:r,editor:a,state:o}=this,{view:l}=a,u=[],c=!!e,d=e||o.tr,f=()=>(!c&&n&&!d.getMeta("preventDispatch")&&!this.hasCustomState&&l.dispatch(d),u.every(g=>g===!0)),h={...Object.fromEntries(Object.entries(r).map(([g,m])=>[g,(...C)=>{const _=this.buildProps(d,n),T=m(...C)(_);return u.push(T),h}])),run:f};return h}createCan(e){const{rawCommands:n,state:r}=this,a=!1,o=e||r.tr,l=this.buildProps(o,a);return{...Object.fromEntries(Object.entries(n).map(([c,d])=>[c,(...f)=>d(...f)({...l,dispatch:void 0})])),chain:()=>this.createChain(o,a)}}buildProps(e,n=!0){const{rawCommands:r,editor:a,state:o}=this,{view:l}=a;o.storedMarks&&e.setStoredMarks(o.storedMarks);const u={tr:e,editor:a,view:l,state:bo({state:o,transaction:e}),dispatch:n?()=>{}:void 0,chain:()=>this.createChain(e),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(r).map(([c,d])=>[c,(...f)=>d(...f)(u)]))}};return u}}function vt(t,e,n){return t.config[e]===void 0&&t.parent?vt(t.parent,e,n):typeof t.config[e]=="function"?t.config[e].bind({...n,parent:t.parent?vt(t.parent,e,n):null}):t.config[e]}function Mm(t){const e=t.filter(a=>a.type==="extension"),n=t.filter(a=>a.type==="node"),r=t.filter(a=>a.type==="mark");return{baseExtensions:e,nodeExtensions:n,markExtensions:r}}function Le(t,e){if(typeof t=="string"){if(!e.nodes[t])throw Error(`There is no node type named '${t}'. Maybe you forgot to add the extension?`);return e.nodes[t]}return t}function Im(t){return typeof t=="function"}function Nt(t,e=void 0,...n){return Im(t)?e?t.bind(e)(...n):t(...n):t}function Em(t){return Object.prototype.toString.call(t)==="[object RegExp]"}function Am(t){return Object.prototype.toString.call(t).slice(8,-1)}function Jr(t){return Am(t)!=="Object"?!1:t.constructor===Object&&Object.getPrototypeOf(t)===Object.prototype}function vo(t,e){const n={...t};return Jr(t)&&Jr(e)&&Object.keys(e).forEach(r=>{Jr(e[r])?r in t?n[r]=vo(t[r],e[r]):Object.assign(n,{[r]:e[r]}):Object.assign(n,{[r]:e[r]})}),n}class it{constructor(e={}){this.type="extension",this.name="extension",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=Nt(vt(this,"addOptions",{name:this.name}))),this.storage=Nt(vt(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new it(e)}configure(e={}){const n=this.extend();return n.options=vo(this.options,e),n.storage=Nt(vt(n,"addStorage",{name:n.name,options:n.options})),n}extend(e={}){const n=new it(e);return n.parent=this,this.child=n,n.name=e.name?e.name:n.parent.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${n.name}".`),n.options=Nt(vt(n,"addOptions",{name:n.name})),n.storage=Nt(vt(n,"addStorage",{name:n.name,options:n.options})),n}}function zm(t,e,n){const{from:r,to:a}=e,{blockSeparator:o=`
241
+ `}}}function Ds({enabled:e,func_content:t}){return(n,r)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function em(e){const{overflow:t,format:n,formatter:r,...a}=e.x_axis.axisLabel,o=ct(t.on_axis);return{type:"value",name:e.x_axis.name??"",nameLocation:"middle",nameGap:25,axisTick:{show:!0,alignWithLabel:!0},axisLabel:{...a,...o,formatter:(l,u)=>{let c=l;try{c=H(l).format(n)}catch{}return Ds(r)(c,u)}}}}const tm={tooltip:{trigger:"axis"},grid:{top:50,left:5,right:10,bottom:20,containLabel:!0},dataZoom:[{type:"inside",xAxisIndex:[0]},{type:"inside",yAxisIndex:[0]}]};function nm(e,t){const n=Jg(e,t),r=Kg(e,n),a={xAxis:em(e),yAxis:{name:e.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"left"},nameGap:5,axisLine:{show:!0}},series:[...n,...r],tooltip:Hg(e),legend:{show:!0,type:"scroll",orient:"horizontal",align:"left",right:0,top:0,left:"auto",itemGap:20,padding:[4,8,0,140],data:n.map(o=>o.name)}};return x.defaultsDeep({},a,tm)}function Ln(e,t,n){return 1-(1-e)*(t-1)/(t-n-1)}function rm(e,t,n,r){const{x_axis:a,y_axis:o}=r,l=ft.regressionLinear()(n),{a:u,b:c,rSquared:d}=l;return{name:e,expression:p(s.Group,{position:"center",noWrap:!0,spacing:10,children:[i(s.Text,{children:o.name}),i(s.Text,{children:"="}),i(s.Text,{weight:"bold",color:"red",children:H(c).format({mantissa:2,trimMantissa:!0})}),i(s.Text,{children:"+"}),i(s.Text,{weight:"bold",color:"red",children:H(u).format({mantissa:2,trimMantissa:!0})}),i(s.Text,{children:"×"}),i(s.Text,{children:a.name})]}),rSquared:d,adjustedRSquared:Ln(d,t.length,1)}}function im(e,t,n,r){const{x_axis:a,y_axis:o}=r,{a:l,b:u,rSquared:c}=ft.regressionExp()(n);return{name:e,expression:p(s.Group,{position:"center",noWrap:!0,spacing:10,children:[i(s.Text,{children:o.name}),i(s.Text,{children:"="}),i(s.Text,{weight:"bold",color:"gray",children:l}),i(s.Text,{children:"×"}),p(s.Group,{position:"left",noWrap:!0,spacing:2,children:[i(s.Text,{children:"Math.exp("}),i(s.Text,{weight:"bold",color:"gray",children:u}),i(s.Text,{children:"×"}),i(s.Text,{children:a.name}),i(s.Text,{children:")"})]})]}),rSquared:c,adjustedRSquared:Ln(c,t.length,1)}}function am(e,t,n,r){const{x_axis:a,y_axis:o}=r,{a:l,b:u,rSquared:c}=ft.regressionLog()(n);return{name:e,expression:p(s.Group,{position:"center",noWrap:!0,spacing:10,children:[i(s.Text,{children:o.name}),i(s.Text,{children:"="}),i(s.Text,{weight:"bold",color:"gray",children:l}),i(s.Text,{children:"×"}),p(s.Group,{position:"left",noWrap:!0,spacing:2,children:[i(s.Text,{children:"Math.log("}),i(s.Text,{children:a.name}),i(s.Text,{children:")"}),i(s.Text,{children:"+"}),i(s.Text,{weight:"bold",color:"gray",children:u})]})]}),rSquared:c,adjustedRSquared:Ln(c,t.length,1)}}function sm(e,t,n,r){const{x_axis:a,y_axis:o,regression:l}=r,u=ft.regressionPoly().order(l.transform.config.order)(n),{rSquared:c}=u;return console.log(u),{name:e,expression:"",rSquared:c,adjustedRSquared:Ln(c,t.length,1)}}function Ms(e,t,n){const{regression:r,x_axis:a}=n,o=q(a.data_key),l=q(r.y_axis_data_key),u=t.map(c=>[c[o.columnKey],c[l.columnKey]]);return r.transform.config.method==="linear"?rm(e,t,u,n):r.transform.config.method==="exponential"?im(e,t,u,n):r.transform.config.method==="logarithmic"?am(e,t,u,n):r.transform.config.method==="polynomial"?sm(e,t,u,n):{name:e,expression:"",rSquared:0,adjustedRSquared:0}}function om(e,t){if(!t)return[{name:"",expression:"",rSquared:0,adjustedRSquared:0}];if(!t.regression.group_by_key)return[Ms("",e,t)];const n=q(t.regression.group_by_key),r=x.groupBy(e,n.columnKey);return Object.entries(r).map(([a,o])=>Ms(a,o,t))}const lm={marginTop:"10px","tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function Is({desc:e}){const{expression:t,rSquared:n,adjustedRSquared:r}=e;return t?i(s.Table,{fontSize:14,sx:lm,children:p("tbody",{children:[i("tr",{children:i("td",{colSpan:2,children:i(s.Text,{align:"center",children:t})})}),p("tr",{children:[i("td",{children:"R-Sq"}),i("td",{style:{textAlign:"right"},children:H(n).format({output:"percent",mantissa:1})})]}),p("tr",{children:[i("td",{children:"R-Sq(Adjusted)"}),i("td",{style:{textAlign:"right"},children:H(r).format({output:"percent",mantissa:1})})]})]})}):i(s.Text,{children:"Unavailable for this regression method"})}function um({conf:e,queryData:t}){var r;const n=b.useMemo(()=>om(t,e),[e,t]);return e.regression.group_by_key?(console.log(n),p(s.Tabs,{defaultValue:(r=n[0])==null?void 0:r.name,color:"gray",children:[i(s.Tabs.List,{grow:!0,children:n.map(a=>i(s.Tabs.Tab,{value:a.name,children:a.name},a.name))}),n.map(a=>i(s.Tabs.Panel,{value:a.name,children:i(Is,{desc:a})},a.name))]})):i(Is,{desc:n[0]})}function cm({conf:e,queryData:t}){return p(s.HoverCard,{shadow:"md",withinPortal:!0,zIndex:320,children:[i(s.HoverCard.Target,{children:i(s.Button,{size:"xs",variant:"subtle",compact:!0,leftIcon:i(L.IconInfoCircle,{size:14}),children:"Regression Info"})}),i(s.HoverCard.Dropdown,{children:i(Fe,{children:i(um,{conf:e,queryData:t})})})]})}function dm(e){return i(s.Group,{position:"apart",sx:{position:"absolute",top:0,left:0,height:"22px",zIndex:1},children:i(cm,{...e})})}const On={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
242
+ `)},Wr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,format:$e,overflow:Ze,formatter:{...On}}},y_axis:{name:"Y Axis"},regression:{transform:{type:"ecStat:regression",config:{method:"linear",order:1,formulaOn:"end"}},plot:{type:"line",yAxisIndex:0,color:"#228be6",lineStyle:{type:"solid",width:1}},name:"regression",group_by_key:"",y_axis_data_key:"value"}};oe.use([G.DataZoomComponent,pe.ScatterChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer]);function pm({context:e}){const{value:t}=W(e.instanceData,"config"),{width:n,height:r}=e.viewport,a=b.useMemo(()=>{var m;const c=e.data,d=t==null?void 0:t.x_axis.data_key,f=(m=t==null?void 0:t.regression)==null?void 0:m.y_axis_data_key;if(!d||!f)return[];const h=q(d),g=q(f);return c[h.queryID].map(C=>typeof C[g.columnKey]=="number"?C:{...C,[g.columnKey]:Number(C[g.columnKey])})},[e.data,t==null?void 0:t.regression.y_axis_data_key]),o=b.useMemo(()=>nm(x.defaultsDeep({},t,Wr),a),[t,a]),l=b.useRef(null),u=c=>{l.current=c};return!n||!r||!t?null:p(s.Box,{sx:{position:"relative"},children:[i(dm,{conf:t,queryData:a}),i(Ne,{echarts:oe,onChartReady:u,option:o,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})]})}const hm=[{label:"Linear",value:"linear"},{label:"Exponential",value:"exponential"},{label:"Logarithmic",value:"logarithmic"},{label:"Polynomial",value:"polynomial"}];function fm({control:e,watch:t}){t("regression");const n=t("regression.transform.config.method"),r=t("regression.group_by_key");return p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"regression.name",control:e,render:({field:a})=>i(s.TextInput,{label:"回归线名称",sx:{flex:1},...a})})}),i(v.Controller,{name:"regression.group_by_key",control:e,render:({field:a})=>i(R,{label:"按此字段将数据分为多个系列",clearable:!0,sx:{flex:1},...a})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"regression.transform.config.method",control:e,render:({field:a})=>i(s.Select,{label:"回归方法",data:hm,sx:{flex:1},...a})}),n==="polynomial"&&i(v.Controller,{name:"regression.transform.config.order",control:e,render:({field:a})=>i(s.NumberInput,{label:"次",sx:{flex:1},...a})})]}),!r&&p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"颜色"}),i(v.Controller,{name:"regression.plot.color",control:e,render:({field:a})=>i(Pe,{...a})})]})]})}const gm=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Ae,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},Es=b.forwardRef(({value:e,onChange:t,triggerButtonText:n="Customize Label"},r)=>{const[a,{setTrue:o,setFalse:l}]=X.useBoolean(),[u,c]=b.useState(e);b.useEffect(()=>{c(e)},[e]);const d=C=>{c({...u,enabled:C})},f=()=>{l();const{enabled:C,func_content:w}=u,_={enabled:C,func_content:w};c(_),t(_)},h=()=>{l(),c(e)},g=C=>{c(w=>({...w,func_content:C}))},m=()=>{g(On.func_content)};return p(V,{children:[i(s.Button,{variant:"filled",mt:24,onClick:o,sx:{flexGrow:0},children:n}),i(s.Modal,{size:800,title:"Customize label content",opened:a,onClose:l,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:a&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:u.enabled,onChange:C=>d(C.currentTarget.checked)}),i(gm,{value:u.func_content,onChange:g,disabled:!u.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:m,color:"red",leftIcon:i(T.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:h,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:f,children:"OK"})]})]})]})})]})});function mm({control:e,watch:t}){return t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"X轴名称",sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(R,{label:"X轴数据字段",required:!0,sx:{flex:1},...n})})]}),i(s.Divider,{variant:"dashed",labelPosition:"center",label:"格式化数据"}),i(s.Stack,{children:i(v.Controller,{name:"x_axis.axisLabel.format",control:e,render:({field:n})=>i(je,{...n})})}),i(s.Divider,{variant:"dashed",labelPosition:"center",label:"标签文案样式"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>i(s.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>i(Es,{triggerButtonText:"自定义标签文案内容",...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>i(mt,{...n})})]})}function ym({control:e,watch:t}){return t(["y_axis","regression.y_axis_data_key"]),i(s.Stack,{children:p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Y轴名称",sx:{flex:1},...n})}),i(v.Controller,{name:"regression.y_axis_data_key",control:e,render:({field:n})=>i(R,{label:"Y轴数据字段",required:!0,sx:{flex:1},...n})})]})})}function bm({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),r=b.useMemo(()=>x.defaults({},t,Wr),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});b.useEffect(()=>{c(r)},[r]),l(["x_axis","y_axis","regression"]);const d=u(),f=b.useMemo(()=>!x.isEqual(d,t),[d,t]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(T.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X轴",orientation:"vertical",styles:{panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X轴",children:"X轴"}),i(s.Tabs.Tab,{value:"Y轴",children:"Y轴"}),i(s.Tabs.Tab,{value:"回归",children:"回归"})]}),i(s.Tabs.Panel,{value:"X轴",children:i(mm,{watch:l,control:a})}),i(s.Tabs.Panel,{value:"Y轴",children:i(ym,{watch:l,control:a})}),i(s.Tabs.Panel,{value:"回归",children:i(fm,{control:a,watch:l})})]})]})})}function vm(e){const t={x_axis:{axisLabel:{rotate:0,format:$e,overflow:Ze,formatter:On}},regression:{group_by_key:""}};return x.defaultsDeep(t,e)}function xm(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis:a,regression:o,...l}=e;return{...l,x_axis:{...a,data_key:r(a.data_key)},regression:{...o,group_by_key:r(o.group_by_key),y_axis_data_key:r(o.y_axis_data_key)}}}catch(n){throw console.error("[Migration failed]",n),n}}class wm extends be{constructor(){super(...arguments);N(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:vm(n.config)})),this.version(3,(n,r)=>{const{config:a}=n;return{...n,version:3,config:xm(a,r)}})}}const Cm={displayName:"Regression Chart",displayGroup:"Merico suite",migrator:new wm,name:"regressionChart",viewRender:pm,configRender:bm,createConfig(){return{version:3,config:x.cloneDeep(Wr)}}},Pn={content:""},Rr={fontSize:"14px",lineHeight:"32px",color:"#3D3E45",ul:{paddingLeft:"2em",margin:"6px 0 0"},p:{margin:0},a:{WebkitTapHighlightColor:"transparent",color:"rgb(34, 139, 230)",textDecoration:"none","&:hover":{textDecoration:"underline"},"&:active, &:hover":{outlineWidth:0}},table:{tr:{"th, td":{padding:"0 .5em"}}},"table.rich-text-table-render, div.tableWrapper table":{"th, td":{border:"1px solid #eaeaea"},"tr:last-of-type td":{borderBottom:"1px solid #eaeaea"}},".resize-cursor":{cursor:"col-resize"},details:{summary:{listStyle:"none",cursor:"pointer",transition:"color 300ms ease",userSelect:"none"},"summary::-webkit-details-marker":{display:"none"},"summary:hover":{color:"black","&::before":{opacity:1}},"summary::before":{content:'"►"',fontSize:"10px",margin:"0px 5px",opacity:.5,display:"inline-block",transition:"opacity 300ms ease, transform 300ms ease"}},"details[open] summary::before":{transform:"rotate(90deg)"},"details + details":{marginTop:"10px"},blockquote:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45",margin:"0 0 14px"}};function As(e,t,n){for(let r=0;;r++){if(r==e.childCount||r==t.childCount)return e.childCount==t.childCount?null:n;let a=e.child(r),o=t.child(r);if(a==o){n+=a.nodeSize;continue}if(!a.sameMarkup(o))return n;if(a.isText&&a.text!=o.text){for(let l=0;a.text[l]==o.text[l];l++)n++;return n}if(a.content.size||o.content.size){let l=As(a.content,o.content,n+1);if(l!=null)return l}n+=a.nodeSize}}function zs(e,t,n,r){for(let a=e.childCount,o=t.childCount;;){if(a==0||o==0)return a==o?null:{a:n,b:r};let l=e.child(--a),u=t.child(--o),c=l.nodeSize;if(l==u){n-=c,r-=c;continue}if(!l.sameMarkup(u))return{a:n,b:r};if(l.isText&&l.text!=u.text){let d=0,f=Math.min(l.text.length,u.text.length);for(;d<f&&l.text[l.text.length-d-1]==u.text[u.text.length-d-1];)d++,n--,r--;return{a:n,b:r}}if(l.content.size||u.content.size){let d=zs(l.content,u.content,n-1,r-1);if(d)return d}n-=c,r-=c}}class ie{constructor(t,n){if(this.content=t,this.size=n||0,n==null)for(let r=0;r<t.length;r++)this.size+=t[r].nodeSize}nodesBetween(t,n,r,a=0,o){for(let l=0,u=0;u<n;l++){let c=this.content[l],d=u+c.nodeSize;if(d>t&&r(c,a+u,o||null,l)!==!1&&c.content.size){let f=u+1;c.nodesBetween(Math.max(0,t-f),Math.min(c.content.size,n-f),r,a+f)}u=d}}descendants(t){this.nodesBetween(0,this.size,t)}textBetween(t,n,r,a){let o="",l=!0;return this.nodesBetween(t,n,(u,c)=>{u.isText?(o+=u.text.slice(Math.max(t,c)-c,n-c),l=!r):u.isLeaf?(a?o+=typeof a=="function"?a(u):a:u.type.spec.leafText&&(o+=u.type.spec.leafText(u)),l=!r):!l&&u.isBlock&&(o+=r,l=!0)},0),o}append(t){if(!t.size)return this;if(!this.size)return t;let n=this.lastChild,r=t.firstChild,a=this.content.slice(),o=0;for(n.isText&&n.sameMarkup(r)&&(a[a.length-1]=n.withText(n.text+r.text),o=1);o<t.content.length;o++)a.push(t.content[o]);return new ie(a,this.size+t.size)}cut(t,n=this.size){if(t==0&&n==this.size)return this;let r=[],a=0;if(n>t)for(let o=0,l=0;l<n;o++){let u=this.content[o],c=l+u.nodeSize;c>t&&((l<t||c>n)&&(u.isText?u=u.cut(Math.max(0,t-l),Math.min(u.text.length,n-l)):u=u.cut(Math.max(0,t-l-1),Math.min(u.content.size,n-l-1))),r.push(u),a+=u.nodeSize),l=c}return new ie(r,a)}cutByIndex(t,n){return t==n?ie.empty:t==0&&n==this.content.length?this:new ie(this.content.slice(t,n))}replaceChild(t,n){let r=this.content[t];if(r==n)return this;let a=this.content.slice(),o=this.size+n.nodeSize-r.nodeSize;return a[t]=n,new ie(a,o)}addToStart(t){return new ie([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new ie(this.content.concat(t),this.size+t.nodeSize)}eq(t){if(this.content.length!=t.content.length)return!1;for(let n=0;n<this.content.length;n++)if(!this.content[n].eq(t.content[n]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(t){let n=this.content[t];if(!n)throw new RangeError("Index "+t+" out of range for "+this);return n}maybeChild(t){return this.content[t]||null}forEach(t){for(let n=0,r=0;n<this.content.length;n++){let a=this.content[n];t(a,r,n),r+=a.nodeSize}}findDiffStart(t,n=0){return As(this,t,n)}findDiffEnd(t,n=this.size,r=t.size){return zs(this,t,n,r)}findIndex(t,n=-1){if(t==0)return Bn(0,t);if(t==this.size)return Bn(this.content.length,t);if(t>this.size||t<0)throw new RangeError(`Position ${t} outside of fragment (${this})`);for(let r=0,a=0;;r++){let o=this.child(r),l=a+o.nodeSize;if(l>=t)return l==t||n>0?Bn(r+1,l):Bn(r,a);a=l}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(t=>t.toJSON()):null}static fromJSON(t,n){if(!n)return ie.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new ie(n.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return ie.empty;let n,r=0;for(let a=0;a<t.length;a++){let o=t[a];r+=o.nodeSize,a&&o.isText&&t[a-1].sameMarkup(o)?(n||(n=t.slice(0,a)),n[n.length-1]=o.withText(n[n.length-1].text+o.text)):n&&n.push(o)}return new ie(n||t,r)}static from(t){if(!t)return ie.empty;if(t instanceof ie)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new ie([t],t.nodeSize);throw new RangeError("Can not convert "+t+" to a Fragment"+(t.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}ie.empty=new ie([],0);const jr={index:0,offset:0};function Bn(e,t){return jr.index=e,jr.offset=t,jr}function Yr(e,t){if(e===t)return!0;if(!(e&&typeof e=="object")||!(t&&typeof t=="object"))return!1;let n=Array.isArray(e);if(Array.isArray(t)!=n)return!1;if(n){if(e.length!=t.length)return!1;for(let r=0;r<e.length;r++)if(!Yr(e[r],t[r]))return!1}else{for(let r in e)if(!(r in t)||!Yr(e[r],t[r]))return!1;for(let r in t)if(!(r in e))return!1}return!0}class We{constructor(t,n){this.type=t,this.attrs=n}addToSet(t){let n,r=!1;for(let a=0;a<t.length;a++){let o=t[a];if(this.eq(o))return t;if(this.type.excludes(o.type))n||(n=t.slice(0,a));else{if(o.type.excludes(this.type))return t;!r&&o.type.rank>this.type.rank&&(n||(n=t.slice(0,a)),n.push(this),r=!0),n&&n.push(o)}}return n||(n=t.slice()),r||n.push(this),n}removeFromSet(t){for(let n=0;n<t.length;n++)if(this.eq(t[n]))return t.slice(0,n).concat(t.slice(n+1));return t}isInSet(t){for(let n=0;n<t.length;n++)if(this.eq(t[n]))return!0;return!1}eq(t){return this==t||this.type==t.type&&Yr(this.attrs,t.attrs)}toJSON(){let t={type:this.type.name};for(let n in this.attrs){t.attrs=this.attrs;break}return t}static fromJSON(t,n){if(!n)throw new RangeError("Invalid input for Mark.fromJSON");let r=t.marks[n.type];if(!r)throw new RangeError(`There is no mark type ${n.type} in this schema`);return r.create(n.attrs)}static sameSet(t,n){if(t==n)return!0;if(t.length!=n.length)return!1;for(let r=0;r<t.length;r++)if(!t[r].eq(n[r]))return!1;return!0}static setFrom(t){if(!t||Array.isArray(t)&&t.length==0)return We.none;if(t instanceof We)return[t];let n=t.slice();return n.sort((r,a)=>r.type.rank-a.type.rank),n}}We.none=[];class Sm extends Error{}class ce{constructor(t,n,r){this.content=t,this.openStart=n,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,n){let r=Ls(this.content,t+this.openStart,n);return r&&new ce(r,this.openStart,this.openEnd)}removeBetween(t,n){return new ce($s(this.content,t+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(t){return this.content.eq(t.content)&&this.openStart==t.openStart&&this.openEnd==t.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let t={content:this.content.toJSON()};return this.openStart>0&&(t.openStart=this.openStart),this.openEnd>0&&(t.openEnd=this.openEnd),t}static fromJSON(t,n){if(!n)return ce.empty;let r=n.openStart||0,a=n.openEnd||0;if(typeof r!="number"||typeof a!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new ce(ie.fromJSON(t,n.content),r,a)}static maxOpen(t,n=!0){let r=0,a=0;for(let o=t.firstChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=t.lastChild;o&&!o.isLeaf&&(n||!o.type.spec.isolating);o=o.lastChild)a++;return new ce(t,r,a)}}ce.empty=new ce(ie.empty,0,0);function $s(e,t,n){let{index:r,offset:a}=e.findIndex(t),o=e.maybeChild(r),{index:l,offset:u}=e.findIndex(n);if(a==t||o.isText){if(u!=n&&!e.child(l).isText)throw new RangeError("Removing non-flat range");return e.cut(0,t).append(e.cut(n))}if(r!=l)throw new RangeError("Removing non-flat range");return e.replaceChild(r,o.copy($s(o.content,t-a-1,n-a-1)))}function Ls(e,t,n,r){let{index:a,offset:o}=e.findIndex(t),l=e.maybeChild(a);if(o==t||l.isText)return r&&!r.canReplace(a,a,n)?null:e.cut(0,t).append(n).append(e.cut(t));let u=Ls(l.content,t-o-1,n);return u&&e.replaceChild(a,l.copy(u))}class Vn{constructor(t,n){this.schema=t,this.rules=n,this.tags=[],this.styles=[],n.forEach(r=>{r.tag?this.tags.push(r):r.style&&this.styles.push(r)}),this.normalizeLists=!this.tags.some(r=>{if(!/^(ul|ol)\b/.test(r.tag)||!r.node)return!1;let a=t.nodes[r.node];return a.contentMatch.matchType(a)})}parse(t,n={}){let r=new Vs(this,n,!1);return r.addAll(t,n.from,n.to),r.finish()}parseSlice(t,n={}){let r=new Vs(this,n,!0);return r.addAll(t,n.from,n.to),ce.maxOpen(r.finish())}matchTag(t,n,r){for(let a=r?this.tags.indexOf(r)+1:0;a<this.tags.length;a++){let o=this.tags[a];if(Tm(t,o.tag)&&(o.namespace===void 0||t.namespaceURI==o.namespace)&&(!o.context||n.matchesContext(o.context))){if(o.getAttrs){let l=o.getAttrs(t);if(l===!1)continue;o.attrs=l||void 0}return o}}}matchStyle(t,n,r,a){for(let o=a?this.styles.indexOf(a)+1:0;o<this.styles.length;o++){let l=this.styles[o],u=l.style;if(!(u.indexOf(t)!=0||l.context&&!r.matchesContext(l.context)||u.length>t.length&&(u.charCodeAt(t.length)!=61||u.slice(t.length+1)!=n))){if(l.getAttrs){let c=l.getAttrs(n);if(c===!1)continue;l.attrs=c||void 0}return l}}}static schemaRules(t){let n=[];function r(a){let o=a.priority==null?50:a.priority,l=0;for(;l<n.length;l++){let u=n[l];if((u.priority==null?50:u.priority)<o)break}n.splice(l,0,a)}for(let a in t.marks){let o=t.marks[a].spec.parseDOM;o&&o.forEach(l=>{r(l=Ns(l)),l.mark||l.ignore||l.clearMark||(l.mark=a)})}for(let a in t.nodes){let o=t.nodes[a].spec.parseDOM;o&&o.forEach(l=>{r(l=Ns(l)),l.node||l.ignore||l.mark||(l.node=a)})}return n}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new Vn(t,Vn.schemaRules(t)))}}const Os={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},_m={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Ps={ol:!0,ul:!0},Nn=1,qn=2,Ht=4;function Bs(e,t,n){return t!=null?(t?Nn:0)|(t==="full"?qn:0):e&&e.whitespace=="pre"?Nn|qn:n&~Ht}class Fn{constructor(t,n,r,a,o,l,u){this.type=t,this.attrs=n,this.marks=r,this.pendingMarks=a,this.solid=o,this.options=u,this.content=[],this.activeMarks=We.none,this.stashMarks=[],this.match=l||(u&Ht?null:t.contentMatch)}findWrapping(t){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(ie.from(t));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,a;return(a=r.findWrapping(t.type))?(this.match=r,a):null}}return this.match.findWrapping(t.type)}finish(t){if(!(this.options&Nn)){let r=this.content[this.content.length-1],a;if(r&&r.isText&&(a=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==a[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-a[0].length))}}let n=ie.from(this.content);return!t&&this.match&&(n=n.append(this.match.fillBefore(ie.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}popFromStashMark(t){for(let n=this.stashMarks.length-1;n>=0;n--)if(t.eq(this.stashMarks[n]))return this.stashMarks.splice(n,1)[0]}applyPending(t){for(let n=0,r=this.pendingMarks;n<r.length;n++){let a=r[n];(this.type?this.type.allowsMarkType(a.type):Mm(a.type,t))&&!a.isInSet(this.activeMarks)&&(this.activeMarks=a.addToSet(this.activeMarks),this.pendingMarks=a.removeFromSet(this.pendingMarks))}}inlineContext(t){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:t.parentNode&&!Os.hasOwnProperty(t.parentNode.nodeName.toLowerCase())}}class Vs{constructor(t,n,r){this.parser=t,this.options=n,this.isOpen=r,this.open=0;let a=n.topNode,o,l=Bs(null,n.preserveWhitespace,0)|(r?Ht:0);a?o=new Fn(a.type,a.attrs,We.none,We.none,!0,n.topMatch||a.type.contentMatch,l):r?o=new Fn(null,null,We.none,We.none,!0,null,l):o=new Fn(t.schema.topNodeType,null,We.none,We.none,!0,null,l),this.nodes=[o],this.find=n.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(t){if(t.nodeType==3)this.addTextNode(t);else if(t.nodeType==1){let n=t.getAttribute("style");if(!n)this.addElement(t);else{let r=this.readStyles(Dm(n));if(!r)return;let[a,o]=r,l=this.top;for(let u=0;u<o.length;u++)this.removePendingMark(o[u],l);for(let u=0;u<a.length;u++)this.addPendingMark(a[u]);this.addElement(t);for(let u=0;u<a.length;u++)this.removePendingMark(a[u],l);for(let u=0;u<o.length;u++)this.addPendingMark(o[u])}}}addTextNode(t){let n=t.nodeValue,r=this.top;if(r.options&qn||r.inlineContext(t)||/[^ \t\r\n\u000c]/.test(n)){if(r.options&Nn)r.options&qn?n=n.replace(/\r\n?/g,`
243
+ `):n=n.replace(/\r?\n|\r/g," ");else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let a=r.content[r.content.length-1],o=t.previousSibling;(!a||o&&o.nodeName=="BR"||a.isText&&/[ \t\r\n\u000c]$/.test(a.text))&&(n=n.slice(1))}n&&this.insertNode(this.parser.schema.text(n)),this.findInText(t)}else this.findInside(t)}addElement(t,n){let r=t.nodeName.toLowerCase(),a;Ps.hasOwnProperty(r)&&this.parser.normalizeLists&&km(t);let o=this.options.ruleFromNode&&this.options.ruleFromNode(t)||(a=this.parser.matchTag(t,this,n));if(o?o.ignore:_m.hasOwnProperty(r))this.findInside(t),this.ignoreFallback(t);else if(!o||o.skip||o.closeParent){o&&o.closeParent?this.open=Math.max(0,this.open-1):o&&o.skip.nodeType&&(t=o.skip);let l,u=this.top,c=this.needsBlock;if(Os.hasOwnProperty(r))u.content.length&&u.content[0].isInline&&this.open&&(this.open--,u=this.top),l=!0,u.type||(this.needsBlock=!0);else if(!t.firstChild){this.leafFallback(t);return}this.addAll(t),l&&this.sync(u),this.needsBlock=c}else this.addElementByRule(t,o,o.consuming===!1?a:void 0)}leafFallback(t){t.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(t.ownerDocument.createTextNode(`
244
+ `))}ignoreFallback(t){t.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(t){let n=We.none,r=We.none;for(let a=0;a<t.length;a+=2)for(let o=void 0;;){let l=this.parser.matchStyle(t[a],t[a+1],this,o);if(!l)break;if(l.ignore)return null;if(l.clearMark?this.top.pendingMarks.concat(this.top.activeMarks).forEach(u=>{l.clearMark(u)&&(r=u.addToSet(r))}):n=this.parser.schema.marks[l.mark].create(l.attrs).addToSet(n),l.consuming===!1)o=l;else break}return[n,r]}addElementByRule(t,n,r){let a,o,l;n.node?(o=this.parser.schema.nodes[n.node],o.isLeaf?this.insertNode(o.create(n.attrs))||this.leafFallback(t):a=this.enter(o,n.attrs||null,n.preserveWhitespace)):(l=this.parser.schema.marks[n.mark].create(n.attrs),this.addPendingMark(l));let u=this.top;if(o&&o.isLeaf)this.findInside(t);else if(r)this.addElement(t,r);else if(n.getContent)this.findInside(t),n.getContent(t,this.parser.schema).forEach(c=>this.insertNode(c));else{let c=t;typeof n.contentElement=="string"?c=t.querySelector(n.contentElement):typeof n.contentElement=="function"?c=n.contentElement(t):n.contentElement&&(c=n.contentElement),this.findAround(t,c,!0),this.addAll(c)}a&&this.sync(u)&&this.open--,l&&this.removePendingMark(l,u)}addAll(t,n,r){let a=n||0;for(let o=n?t.childNodes[n]:t.firstChild,l=r==null?null:t.childNodes[r];o!=l;o=o.nextSibling,++a)this.findAtPoint(t,a),this.addDOM(o);this.findAtPoint(t,a)}findPlace(t){let n,r;for(let a=this.open;a>=0;a--){let o=this.nodes[a],l=o.findWrapping(t);if(l&&(!n||n.length>l.length)&&(n=l,r=o,!l.length)||o.solid)break}if(!n)return!1;this.sync(r);for(let a=0;a<n.length;a++)this.enterInner(n[a],null,!1);return!0}insertNode(t){if(t.isInline&&this.needsBlock&&!this.top.type){let n=this.textblockFromContext();n&&this.enterInner(n)}if(this.findPlace(t)){this.closeExtra();let n=this.top;n.applyPending(t.type),n.match&&(n.match=n.match.matchType(t.type));let r=n.activeMarks;for(let a=0;a<t.marks.length;a++)(!n.type||n.type.allowsMarkType(t.marks[a].type))&&(r=t.marks[a].addToSet(r));return n.content.push(t.mark(r)),!0}return!1}enter(t,n,r){let a=this.findPlace(t.create(n));return a&&this.enterInner(t,n,!0,r),a}enterInner(t,n=null,r=!1,a){this.closeExtra();let o=this.top;o.applyPending(t),o.match=o.match&&o.match.matchType(t);let l=Bs(t,a,o.options);o.options&Ht&&o.content.length==0&&(l|=Ht),this.nodes.push(new Fn(t,n,o.activeMarks,o.pendingMarks,r,null,l)),this.open++}closeExtra(t=!1){let n=this.nodes.length-1;if(n>this.open){for(;n>this.open;n--)this.nodes[n-1].content.push(this.nodes[n].finish(t));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(t){for(let n=this.open;n>=0;n--)if(this.nodes[n]==t)return this.open=n,!0;return!1}get currentPos(){this.closeExtra();let t=0;for(let n=this.open;n>=0;n--){let r=this.nodes[n].content;for(let a=r.length-1;a>=0;a--)t+=r[a].nodeSize;n&&t++}return t}findAtPoint(t,n){if(this.find)for(let r=0;r<this.find.length;r++)this.find[r].node==t&&this.find[r].offset==n&&(this.find[r].pos=this.currentPos)}findInside(t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].pos==null&&t.nodeType==1&&t.contains(this.find[n].node)&&(this.find[n].pos=this.currentPos)}findAround(t,n,r){if(t!=n&&this.find)for(let a=0;a<this.find.length;a++)this.find[a].pos==null&&t.nodeType==1&&t.contains(this.find[a].node)&&n.compareDocumentPosition(this.find[a].node)&(r?2:4)&&(this.find[a].pos=this.currentPos)}findInText(t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==t&&(this.find[n].pos=this.currentPos-(t.nodeValue.length-this.find[n].offset))}matchesContext(t){if(t.indexOf("|")>-1)return t.split(/\s*\|\s*/).some(this.matchesContext,this);let n=t.split("/"),r=this.options.context,a=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(a?0:1),l=(u,c)=>{for(;u>=0;u--){let d=n[u];if(d==""){if(u==n.length-1||u==0)continue;for(;c>=o;c--)if(l(u-1,c))return!0;return!1}else{let f=c>0||c==0&&a?this.nodes[c].type:r&&c>=o?r.node(c-o).type:null;if(!f||f.name!=d&&f.groups.indexOf(d)==-1)return!1;c--}}return!0};return l(n.length-1,this.open)}textblockFromContext(){let t=this.options.context;if(t)for(let n=t.depth;n>=0;n--){let r=t.node(n).contentMatchAt(t.indexAfter(n)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let n in this.parser.schema.nodes){let r=this.parser.schema.nodes[n];if(r.isTextblock&&r.defaultAttrs)return r}}addPendingMark(t){let n=Im(t,this.top.pendingMarks);n&&this.top.stashMarks.push(n),this.top.pendingMarks=t.addToSet(this.top.pendingMarks)}removePendingMark(t,n){for(let r=this.open;r>=0;r--){let a=this.nodes[r];if(a.pendingMarks.lastIndexOf(t)>-1)a.pendingMarks=t.removeFromSet(a.pendingMarks);else{a.activeMarks=t.removeFromSet(a.activeMarks);let l=a.popFromStashMark(t);l&&a.type&&a.type.allowsMarkType(l.type)&&(a.activeMarks=l.addToSet(a.activeMarks))}if(a==n)break}}}function km(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let r=t.nodeType==1?t.nodeName.toLowerCase():null;r&&Ps.hasOwnProperty(r)&&n?(n.appendChild(t),t=n):r=="li"?n=t:r&&(n=null)}}function Tm(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function Dm(e){let t=/\s*([\w-]+)\s*:\s*([^;]+)/g,n,r=[];for(;n=t.exec(e);)r.push(n[1],n[2].trim());return r}function Ns(e){let t={};for(let n in e)t[n]=e[n];return t}function Mm(e,t){let n=t.schema.nodes;for(let r in n){let a=n[r];if(!a.allowsMarkType(e))continue;let o=[],l=u=>{o.push(u);for(let c=0;c<u.edgeCount;c++){let{type:d,next:f}=u.edge(c);if(d==t||o.indexOf(f)<0&&l(f))return!0}};if(l(a.contentMatch))return!0}}function Im(e,t){for(let n=0;n<t.length;n++)if(e.eq(t[n]))return t[n]}const qs=65535,Fs=Math.pow(2,16);function Em(e,t){return e+t*Fs}function Gs(e){return e&qs}function Am(e){return(e-(e&qs))/Fs}const Ws=1,Rs=2,Gn=4,js=8;class Ys{constructor(t,n,r){this.pos=t,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&js)>0}get deletedBefore(){return(this.delInfo&(Ws|Gn))>0}get deletedAfter(){return(this.delInfo&(Rs|Gn))>0}get deletedAcross(){return(this.delInfo&Gn)>0}}class Ye{constructor(t,n=!1){if(this.ranges=t,this.inverted=n,!t.length&&Ye.empty)return Ye.empty}recover(t){let n=0,r=Gs(t);if(!this.inverted)for(let a=0;a<r;a++)n+=this.ranges[a*3+2]-this.ranges[a*3+1];return this.ranges[r*3]+n+Am(t)}mapResult(t,n=1){return this._map(t,n,!1)}map(t,n=1){return this._map(t,n,!0)}_map(t,n,r){let a=0,o=this.inverted?2:1,l=this.inverted?1:2;for(let u=0;u<this.ranges.length;u+=3){let c=this.ranges[u]-(this.inverted?a:0);if(c>t)break;let d=this.ranges[u+o],f=this.ranges[u+l],h=c+d;if(t<=h){let g=d?t==c?-1:t==h?1:n:n,m=c+a+(g<0?0:f);if(r)return m;let C=t==(n<0?c:h)?null:Em(u/3,t-c),w=t==c?Rs:t==h?Ws:Gn;return(n<0?t!=c:t!=h)&&(w|=js),new Ys(m,w,C)}a+=f-d}return r?t+a:new Ys(t+a,0,null)}touches(t,n){let r=0,a=Gs(n),o=this.inverted?2:1,l=this.inverted?1:2;for(let u=0;u<this.ranges.length;u+=3){let c=this.ranges[u]-(this.inverted?r:0);if(c>t)break;let d=this.ranges[u+o],f=c+d;if(t<=f&&u==a*3)return!0;r+=this.ranges[u+l]-d}return!1}forEach(t){let n=this.inverted?2:1,r=this.inverted?1:2;for(let a=0,o=0;a<this.ranges.length;a+=3){let l=this.ranges[a],u=l-(this.inverted?o:0),c=l+(this.inverted?0:o),d=this.ranges[a+n],f=this.ranges[a+r];t(u,u+d,c,c+f),o+=f-d}}invert(){return new Ye(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(t){return t==0?Ye.empty:new Ye(t<0?[0,-t,0]:[0,0,t])}}Ye.empty=new Ye([]);const Qr=Object.create(null);class Ge{getMap(){return Ye.empty}merge(t){return null}static fromJSON(t,n){if(!n||!n.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=Qr[n.stepType];if(!r)throw new RangeError(`No step type ${n.stepType} defined`);return r.fromJSON(t,n)}static jsonID(t,n){if(t in Qr)throw new RangeError("Duplicate use of step JSON ID "+t);return Qr[t]=n,n.prototype.jsonID=t,n}}class _e{constructor(t,n){this.doc=t,this.failed=n}static ok(t){return new _e(t,null)}static fail(t){return new _e(null,t)}static fromReplace(t,n,r,a){try{return _e.ok(t.replace(n,r,a))}catch(o){if(o instanceof Sm)return _e.fail(o.message);throw o}}}function Kr(e,t,n){let r=[];for(let a=0;a<e.childCount;a++){let o=e.child(a);o.content.size&&(o=o.copy(Kr(o.content,t,o))),o.isInline&&(o=t(o,n,a)),r.push(o)}return ie.fromArray(r)}class Dt extends Ge{constructor(t,n,r){super(),this.from=t,this.to=n,this.mark=r}apply(t){let n=t.slice(this.from,this.to),r=t.resolve(this.from),a=r.node(r.sharedDepth(this.to)),o=new ce(Kr(n.content,(l,u)=>!l.isAtom||!u.type.allowsMarkType(this.mark.type)?l:l.mark(this.mark.addToSet(l.marks)),a),n.openStart,n.openEnd);return _e.fromReplace(t,this.from,this.to,o)}invert(){return new Mt(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new Dt(n.pos,r.pos,this.mark)}merge(t){return t instanceof Dt&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new Dt(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Dt(n.from,n.to,t.markFromJSON(n.mark))}}Ge.jsonID("addMark",Dt);class Mt extends Ge{constructor(t,n,r){super(),this.from=t,this.to=n,this.mark=r}apply(t){let n=t.slice(this.from,this.to),r=new ce(Kr(n.content,a=>a.mark(this.mark.removeFromSet(a.marks)),t),n.openStart,n.openEnd);return _e.fromReplace(t,this.from,this.to,r)}invert(){return new Dt(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new Mt(n.pos,r.pos,this.mark)}merge(t){return t instanceof Mt&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new Mt(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new Mt(n.from,n.to,t.markFromJSON(n.mark))}}Ge.jsonID("removeMark",Mt);class It extends Ge{constructor(t,n){super(),this.pos=t,this.mark=n}apply(t){let n=t.nodeAt(this.pos);if(!n)return _e.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return _e.fromReplace(t,this.pos,this.pos+1,new ce(ie.from(r),0,n.isLeaf?0:1))}invert(t){let n=t.nodeAt(this.pos);if(n){let r=this.mark.addToSet(n.marks);if(r.length==n.marks.length){for(let a=0;a<n.marks.length;a++)if(!n.marks[a].isInSet(r))return new It(this.pos,n.marks[a]);return new It(this.pos,this.mark)}}return new en(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new It(n.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new It(n.pos,t.markFromJSON(n.mark))}}Ge.jsonID("addNodeMark",It);class en extends Ge{constructor(t,n){super(),this.pos=t,this.mark=n}apply(t){let n=t.nodeAt(this.pos);if(!n)return _e.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.removeFromSet(n.marks));return _e.fromReplace(t,this.pos,this.pos+1,new ce(ie.from(r),0,n.isLeaf?0:1))}invert(t){let n=t.nodeAt(this.pos);return!n||!this.mark.isInSet(n.marks)?this:new It(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new en(n.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new en(n.pos,t.markFromJSON(n.mark))}}Ge.jsonID("removeNodeMark",en);class it extends Ge{constructor(t,n,r,a=!1){super(),this.from=t,this.to=n,this.slice=r,this.structure=a}apply(t){return this.structure&&Ur(t,this.from,this.to)?_e.fail("Structure replace would overwrite content"):_e.fromReplace(t,this.from,this.to,this.slice)}getMap(){return new Ye([this.from,this.to-this.from,this.slice.size])}invert(t){return new it(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deletedAcross&&r.deletedAcross?null:new it(n.pos,Math.max(n.pos,r.pos),this.slice)}merge(t){if(!(t instanceof it)||t.structure||this.structure)return null;if(this.from+this.slice.size==t.from&&!this.slice.openEnd&&!t.slice.openStart){let n=this.slice.size+t.slice.size==0?ce.empty:new ce(this.slice.content.append(t.slice.content),this.slice.openStart,t.slice.openEnd);return new it(this.from,this.to+(t.to-t.from),n,this.structure)}else if(t.to==this.from&&!this.slice.openStart&&!t.slice.openEnd){let n=this.slice.size+t.slice.size==0?ce.empty:new ce(t.slice.content.append(this.slice.content),t.slice.openStart,this.slice.openEnd);return new it(t.from,this.to,n,this.structure)}else return null}toJSON(){let t={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new it(n.from,n.to,ce.fromJSON(t,n.slice),!!n.structure)}}Ge.jsonID("replace",it);class Et extends Ge{constructor(t,n,r,a,o,l,u=!1){super(),this.from=t,this.to=n,this.gapFrom=r,this.gapTo=a,this.slice=o,this.insert=l,this.structure=u}apply(t){if(this.structure&&(Ur(t,this.from,this.gapFrom)||Ur(t,this.gapTo,this.to)))return _e.fail("Structure gap-replace would overwrite content");let n=t.slice(this.gapFrom,this.gapTo);if(n.openStart||n.openEnd)return _e.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,n.content);return r?_e.fromReplace(t,this.from,this.to,r):_e.fail("Content does not fit in gap")}getMap(){return new Ye([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(t){let n=this.gapTo-this.gapFrom;return new Et(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1),a=t.map(this.gapFrom,-1),o=t.map(this.gapTo,1);return n.deletedAcross&&r.deletedAcross||a<n.pos||o>r.pos?null:new Et(n.pos,r.pos,a,o,this.slice,this.insert,this.structure)}toJSON(){let t={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Et(n.from,n.to,n.gapFrom,n.gapTo,ce.fromJSON(t,n.slice),n.insert,!!n.structure)}}Ge.jsonID("replaceAround",Et);function Ur(e,t,n){let r=e.resolve(t),a=n-t,o=r.depth;for(;a>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,a--;if(a>0){let l=r.node(o).maybeChild(r.indexAfter(o));for(;a>0;){if(!l||l.isLeaf)return!0;l=l.firstChild,a--}}return!1}function zm(e,t,n){return(t==0||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function $m(e){let n=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let r=e.depth;;--r){let a=e.$from.node(r),o=e.$from.index(r),l=e.$to.indexAfter(r);if(r<e.depth&&a.canReplace(o,l,n))return r;if(r==0||a.type.spec.isolating||!zm(a,o,l))break}return null}function Wn(e,t,n=1,r){let a=e.resolve(t),o=a.depth-n,l=r&&r[r.length-1]||a.parent;if(o<0||a.parent.type.spec.isolating||!a.parent.canReplace(a.index(),a.parent.childCount)||!l.type.validContent(a.parent.content.cutByIndex(a.index(),a.parent.childCount)))return!1;for(let d=a.depth-1,f=n-2;d>o;d--,f--){let h=a.node(d),g=a.index(d);if(h.type.spec.isolating)return!1;let m=h.content.cutByIndex(g,h.childCount),C=r&&r[f+1];C&&(m=m.replaceChild(0,C.type.create(C.attrs)));let w=r&&r[f]||h;if(!h.canReplace(g+1,h.childCount)||!w.type.validContent(m))return!1}let u=a.indexAfter(o),c=r&&r[0];return a.node(o).canReplaceWith(u,u,c?c.type:a.node(o+1).type)}function Qs(e,t){let n=e.resolve(t),r=n.index();return Lm(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function Lm(e,t){return!!(e&&t&&!e.isLeaf&&e.canAppend(t))}class tn extends Ge{constructor(t,n,r){super(),this.pos=t,this.attr=n,this.value=r}apply(t){let n=t.nodeAt(this.pos);if(!n)return _e.fail("No node at attribute step's position");let r=Object.create(null);for(let o in n.attrs)r[o]=n.attrs[o];r[this.attr]=this.value;let a=n.type.create(r,null,n.marks);return _e.fromReplace(t,this.pos,this.pos+1,new ce(ie.from(a),0,n.isLeaf?0:1))}getMap(){return Ye.empty}invert(t){return new tn(this.pos,this.attr,t.nodeAt(this.pos).attrs[this.attr])}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new tn(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new tn(n.pos,n.attr,n.value)}}Ge.jsonID("attr",tn);let nn=class extends Error{};nn=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n},nn.prototype=Object.create(Error.prototype),nn.prototype.constructor=nn,nn.prototype.name="TransformError";const Xr=Object.create(null);class he{constructor(t,n,r){this.$anchor=t,this.$head=n,this.ranges=r||[new Om(t.min(n),t.max(n))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let t=this.ranges;for(let n=0;n<t.length;n++)if(t[n].$from.pos!=t[n].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(t,n=ce.empty){let r=n.content.lastChild,a=null;for(let u=0;u<n.openEnd;u++)a=r,r=r.lastChild;let o=t.steps.length,l=this.ranges;for(let u=0;u<l.length;u++){let{$from:c,$to:d}=l[u],f=t.mapping.slice(o);t.replaceRange(f.map(c.pos),f.map(d.pos),u?ce.empty:n),u==0&&Xs(t,o,(r?r.isInline:a&&a.isTextblock)?-1:1)}}replaceWith(t,n){let r=t.steps.length,a=this.ranges;for(let o=0;o<a.length;o++){let{$from:l,$to:u}=a[o],c=t.mapping.slice(r),d=c.map(l.pos),f=c.map(u.pos);o?t.deleteRange(d,f):(t.replaceRangeWith(d,f,n),Xs(t,r,n.isInline?-1:1))}}static findFrom(t,n,r=!1){let a=t.parent.inlineContent?new ke(t):Nt(t.node(0),t.parent,t.pos,t.index(),n,r);if(a)return a;for(let o=t.depth-1;o>=0;o--){let l=n<0?Nt(t.node(0),t.node(o),t.before(o+1),t.index(o),n,r):Nt(t.node(0),t.node(o),t.after(o+1),t.index(o)+1,n,r);if(l)return l}return null}static near(t,n=1){return this.findFrom(t,n)||this.findFrom(t,-n)||new dt(t.node(0))}static atStart(t){return Nt(t,t,0,0,1)||new dt(t)}static atEnd(t){return Nt(t,t,t.content.size,t.childCount,-1)||new dt(t)}static fromJSON(t,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=Xr[n.type];if(!r)throw new RangeError(`No selection type ${n.type} defined`);return r.fromJSON(t,n)}static jsonID(t,n){if(t in Xr)throw new RangeError("Duplicate use of selection JSON ID "+t);return Xr[t]=n,n.prototype.jsonID=t,n}getBookmark(){return ke.between(this.$anchor,this.$head).getBookmark()}}he.prototype.visible=!0;class Om{constructor(t,n){this.$from=t,this.$to=n}}let Ks=!1;function Us(e){!Ks&&!e.parent.inlineContent&&(Ks=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+e.parent.type.name+")"))}class ke extends he{constructor(t,n=t){Us(t),Us(n),super(t,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(t,n){let r=t.resolve(n.map(this.head));if(!r.parent.inlineContent)return he.near(r);let a=t.resolve(n.map(this.anchor));return new ke(a.parent.inlineContent?a:r,r)}replace(t,n=ce.empty){if(super.replace(t,n),n==ce.empty){let r=this.$from.marksAcross(this.$to);r&&t.ensureMarks(r)}}eq(t){return t instanceof ke&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new Rn(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(t,n){if(typeof n.anchor!="number"||typeof n.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new ke(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,r=n){let a=t.resolve(n);return new this(a,r==n?a:t.resolve(r))}static between(t,n,r){let a=t.pos-n.pos;if((!r||a)&&(r=a>=0?1:-1),!n.parent.inlineContent){let o=he.findFrom(n,r,!0)||he.findFrom(n,-r,!0);if(o)n=o.$head;else return he.near(n,r)}return t.parent.inlineContent||(a==0?t=n:(t=(he.findFrom(t,-r,!0)||he.findFrom(t,r,!0)).$anchor,t.pos<n.pos!=a<0&&(t=n))),new ke(t,n)}}he.jsonID("text",ke);class Rn{constructor(t,n){this.anchor=t,this.head=n}map(t){return new Rn(t.map(this.anchor),t.map(this.head))}resolve(t){return ke.between(t.resolve(this.anchor),t.resolve(this.head))}}class Re extends he{constructor(t){let n=t.nodeAfter,r=t.node(0).resolve(t.pos+n.nodeSize);super(t,r),this.node=n}map(t,n){let{deleted:r,pos:a}=n.mapResult(this.anchor),o=t.resolve(a);return r?he.near(o):new Re(o)}content(){return new ce(ie.from(this.node),0,0)}eq(t){return t instanceof Re&&t.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Jr(this.anchor)}static fromJSON(t,n){if(typeof n.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new Re(t.resolve(n.anchor))}static create(t,n){return new Re(t.resolve(n))}static isSelectable(t){return!t.isText&&t.type.spec.selectable!==!1}}Re.prototype.visible=!1,he.jsonID("node",Re);class Jr{constructor(t){this.anchor=t}map(t){let{deleted:n,pos:r}=t.mapResult(this.anchor);return n?new Rn(r,r):new Jr(r)}resolve(t){let n=t.resolve(this.anchor),r=n.nodeAfter;return r&&Re.isSelectable(r)?new Re(n):he.near(n)}}class dt extends he{constructor(t){super(t.resolve(0),t.resolve(t.content.size))}replace(t,n=ce.empty){if(n==ce.empty){t.delete(0,t.doc.content.size);let r=he.atStart(t.doc);r.eq(t.selection)||t.setSelection(r)}else super.replace(t,n)}toJSON(){return{type:"all"}}static fromJSON(t){return new dt(t)}map(t){return new dt(t)}eq(t){return t instanceof dt}getBookmark(){return Pm}}he.jsonID("all",dt);const Pm={map(){return this},resolve(e){return new dt(e)}};function Nt(e,t,n,r,a,o=!1){if(t.inlineContent)return ke.create(e,n);for(let l=r-(a>0?0:1);a>0?l<t.childCount:l>=0;l+=a){let u=t.child(l);if(u.isAtom){if(!o&&Re.isSelectable(u))return Re.create(e,n-(a<0?u.nodeSize:0))}else{let c=Nt(e,u,n+a,a<0?u.childCount:0,a,o);if(c)return c}n+=u.nodeSize*a}return null}function Xs(e,t,n){let r=e.steps.length-1;if(r<t)return;let a=e.steps[r];if(!(a instanceof it||a instanceof Et))return;let o=e.mapping.maps[r],l;o.forEach((u,c,d,f)=>{l==null&&(l=f)}),e.setSelection(he.near(e.doc.resolve(l),n))}function Js(e,t){return!t||!e?e:e.bind(t)}class jn{constructor(t,n,r){this.name=t,this.init=Js(n.init,r),this.apply=Js(n.apply,r)}}new jn("doc",{init(e){return e.doc||e.schema.topNodeType.createAndFill()},apply(e){return e.doc}}),new jn("selection",{init(e,t){return e.selection||he.atStart(t.doc)},apply(e){return e.selection}}),new jn("storedMarks",{init(e){return e.storedMarks||null},apply(e,t,n,r){return r.selection.$cursor?e.storedMarks:null}}),new jn("scrollToSelection",{init(){return 0},apply(e,t){return e.scrolledIntoView?t+1:t}});function Zs(e,t,n){for(let r in e){let a=e[r];a instanceof Function?a=a.bind(t):r=="handleDOMEvents"&&(a=Zs(a,t,{})),n[r]=a}return n}class rn{constructor(t){this.spec=t,this.props={},t.props&&Zs(t.props,this,this.props),this.key=t.key?t.key.key:Hs("plugin")}getState(t){return t[this.key]}}const Zr=Object.create(null);function Hs(e){return e in Zr?e+"$"+ ++Zr[e]:(Zr[e]=0,e+"$")}class an{constructor(t="key"){this.key=Hs(t)}get(t){return t.config.pluginsByKey[this.key]}getState(t){return t[this.key]}}function eo(e){const{state:t,transaction:n}=e;let{selection:r}=n,{doc:a}=n,{storedMarks:o}=n;return{...t,apply:t.apply.bind(t),applyTransaction:t.applyTransaction.bind(t),filterTransaction:t.filterTransaction,plugins:t.plugins,schema:t.schema,reconfigure:t.reconfigure.bind(t),toJSON:t.toJSON.bind(t),get storedMarks(){return o},get selection(){return r},get doc(){return a},get tr(){return r=n.selection,a=n.doc,o=n.storedMarks,n}}}class Bm{constructor(t){this.editor=t.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=t.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:t,editor:n,state:r}=this,{view:a}=n,{tr:o}=r,l=this.buildProps(o);return Object.fromEntries(Object.entries(t).map(([u,c])=>[u,(...f)=>{const h=c(...f)(l);return!o.getMeta("preventDispatch")&&!this.hasCustomState&&a.dispatch(o),h}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(t,n=!0){const{rawCommands:r,editor:a,state:o}=this,{view:l}=a,u=[],c=!!t,d=t||o.tr,f=()=>(!c&&n&&!d.getMeta("preventDispatch")&&!this.hasCustomState&&l.dispatch(d),u.every(g=>g===!0)),h={...Object.fromEntries(Object.entries(r).map(([g,m])=>[g,(...w)=>{const _=this.buildProps(d,n),D=m(...w)(_);return u.push(D),h}])),run:f};return h}createCan(t){const{rawCommands:n,state:r}=this,a=!1,o=t||r.tr,l=this.buildProps(o,a);return{...Object.fromEntries(Object.entries(n).map(([c,d])=>[c,(...f)=>d(...f)({...l,dispatch:void 0})])),chain:()=>this.createChain(o,a)}}buildProps(t,n=!0){const{rawCommands:r,editor:a,state:o}=this,{view:l}=a;o.storedMarks&&t.setStoredMarks(o.storedMarks);const u={tr:t,editor:a,view:l,state:eo({state:o,transaction:t}),dispatch:n?()=>{}:void 0,chain:()=>this.createChain(t),can:()=>this.createCan(t),get commands(){return Object.fromEntries(Object.entries(r).map(([c,d])=>[c,(...f)=>d(...f)(u)]))}};return u}}function xt(e,t,n){return e.config[t]===void 0&&e.parent?xt(e.parent,t,n):typeof e.config[t]=="function"?e.config[t].bind({...n,parent:e.parent?xt(e.parent,t,n):null}):e.config[t]}function Vm(e){const t=e.filter(a=>a.type==="extension"),n=e.filter(a=>a.type==="node"),r=e.filter(a=>a.type==="mark");return{baseExtensions:t,nodeExtensions:n,markExtensions:r}}function Le(e,t){if(typeof e=="string"){if(!t.nodes[e])throw Error(`There is no node type named '${e}'. Maybe you forgot to add the extension?`);return t.nodes[e]}return e}function Nm(e){return typeof e=="function"}function qt(e,t=void 0,...n){return Nm(e)?t?e.bind(t)(...n):e(...n):e}function qm(e){return Object.prototype.toString.call(e)==="[object RegExp]"}function Fm(e){return Object.prototype.toString.call(e).slice(8,-1)}function Hr(e){return Fm(e)!=="Object"?!1:e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype}function to(e,t){const n={...e};return Hr(e)&&Hr(t)&&Object.keys(t).forEach(r=>{Hr(t[r])?r in e?n[r]=to(e[r],t[r]):Object.assign(n,{[r]:t[r]}):Object.assign(n,{[r]:t[r]})}),n}class at{constructor(t={}){this.type="extension",this.name="extension",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...t},this.name=this.config.name,t.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=qt(xt(this,"addOptions",{name:this.name}))),this.storage=qt(xt(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(t={}){return new at(t)}configure(t={}){const n=this.extend();return n.options=to(this.options,t),n.storage=qt(xt(n,"addStorage",{name:n.name,options:n.options})),n}extend(t={}){const n=new at(t);return n.parent=this,this.child=n,n.name=t.name?t.name:n.parent.name,t.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${n.name}".`),n.options=qt(xt(n,"addOptions",{name:n.name})),n.storage=qt(xt(n,"addStorage",{name:n.name,options:n.options})),n}}function Gm(e,t,n){const{from:r,to:a}=t,{blockSeparator:o=`
310
245
 
311
- `,textSerializers:l={}}=n||{};let u="",c=!0;return t.nodesBetween(r,a,(d,f,h,g)=>{var m;const w=l==null?void 0:l[d.type.name];w?(d.isBlock&&!c&&(u+=o,c=!0),h&&(u+=w({node:d,pos:f,parent:h,index:g,range:e}))):d.isText?(u+=(m=d==null?void 0:d.text)===null||m===void 0?void 0:m.slice(Math.max(r,f)-f,a-f),c=!1):d.isBlock&&!c&&(u+=o,c=!0)}),u}function $m(t){return Object.fromEntries(Object.entries(t.nodes).filter(([,e])=>e.spec.toText).map(([e,n])=>[e,n.spec.toText]))}it.create({name:"clipboardTextSerializer",addProseMirrorPlugins(){return[new nn({key:new rn("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:t}=this,{state:e,schema:n}=t,{doc:r,selection:a}=e,{ranges:o}=a,l=Math.min(...o.map(f=>f.$from.pos)),u=Math.max(...o.map(f=>f.$to.pos)),c=$m(n);return zm(r,{from:l,to:u},{textSerializers:c})}}})]}});const Lm=()=>({editor:t,view:e})=>(requestAnimationFrame(()=>{var n;t.isDestroyed||(e.dom.blur(),(n=window==null?void 0:window.getSelection())===null||n===void 0||n.removeAllRanges())}),!0),Om=(t=!1)=>({commands:e})=>e.setContent("",t),Pm=()=>({state:t,tr:e,dispatch:n})=>{const{selection:r}=e,{ranges:a}=r;return n&&a.forEach(({$from:o,$to:l})=>{t.doc.nodesBetween(o.pos,l.pos,(u,c)=>{if(u.type.isText)return;const{doc:d,mapping:f}=e,h=d.resolve(f.map(c)),g=d.resolve(f.map(c+u.nodeSize)),m=h.blockRange(g);if(!m)return;const w=Sm(m);if(u.type.isTextblock){const{defaultType:C}=h.parent.contentMatchAt(h.index());e.setNodeMarkup(m.start,C)}(w||w===0)&&e.lift(m,w)})}),!0},Bm=t=>e=>t(e),Vm=()=>({state:t,dispatch:e})=>Te.createParagraphNear(t,e),Nm=()=>({tr:t,dispatch:e})=>{const{selection:n}=t,r=n.$anchor.node();if(r.content.size>0)return!1;const a=t.selection.$anchor;for(let o=a.depth;o>0;o-=1)if(a.node(o).type===r.type){if(e){const u=a.before(o),c=a.after(o);t.delete(u,c).scrollIntoView()}return!0}return!1},qm=t=>({tr:e,state:n,dispatch:r})=>{const a=Le(t,n.schema),o=e.selection.$anchor;for(let l=o.depth;l>0;l-=1)if(o.node(l).type===a){if(r){const c=o.before(l),d=o.after(l);e.delete(c,d).scrollIntoView()}return!0}return!1},Fm=t=>({tr:e,dispatch:n})=>{const{from:r,to:a}=t;return n&&e.delete(r,a),!0},Gm=()=>({state:t,dispatch:e})=>Te.deleteSelection(t,e),Wm=()=>({commands:t})=>t.keyboardShortcut("Enter"),jm=()=>({state:t,dispatch:e})=>Te.exitCode(t,e);function Rn(t,e,n={strict:!0}){const r=Object.keys(e);return r.length?r.every(a=>n.strict?e[a]===t[a]:Em(e[a])?e[a].test(t[a]):e[a]===t[a]):!0}function Zr(t,e,n={}){return t.find(r=>r.type===e&&Rn(r.attrs,n))}function Rm(t,e,n={}){return!!Zr(t,e,n)}function xo(t,e,n={}){if(!t||!e)return;let r=t.parent.childAfter(t.parentOffset);if(t.parentOffset===r.offset&&r.offset!==0&&(r=t.parent.childBefore(t.parentOffset)),!r.node)return;const a=Zr([...r.node.marks],e,n);if(!a)return;let o=r.index,l=t.start()+r.offset,u=o+1,c=l+r.node.nodeSize;for(Zr([...r.node.marks],e,n);o>0&&a.isInSet(t.parent.child(o-1).marks);)o-=1,l-=t.parent.child(o).nodeSize;for(;u<t.parent.childCount&&Rm([...t.parent.child(u).marks],e,n);)c+=t.parent.child(u).nodeSize,u+=1;return{from:l,to:c}}function xt(t,e){if(typeof t=="string"){if(!e.marks[t])throw Error(`There is no mark type named '${t}'. Maybe you forgot to add the extension?`);return e.marks[t]}return t}const Ym=(t,e={})=>({tr:n,state:r,dispatch:a})=>{const o=xt(t,r.schema),{doc:l,selection:u}=n,{$from:c,from:d,to:f}=u;if(a){const h=xo(c,o,e);if(h&&h.from<=d&&h.to>=f){const g=ke.create(l,h.from,h.to);n.setSelection(g)}}return!0},Qm=t=>e=>{const n=typeof t=="function"?t(e):t;for(let r=0;r<n.length;r+=1)if(n[r](e))return!0;return!1};function wo(t){return t instanceof ke}function Et(t=0,e=0,n=0){return Math.min(Math.max(t,e),n)}function Km(t,e=null){if(!e)return null;const n=fe.atStart(t),r=fe.atEnd(t);if(e==="start"||e===!0)return n;if(e==="end")return r;const a=n.from,o=r.to;return e==="all"?ke.create(t,Et(0,a,o),Et(t.content.size,a,o)):ke.create(t,Et(e,a,o),Et(e,a,o))}function Hr(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}const Um=(t=null,e={})=>({editor:n,view:r,tr:a,dispatch:o})=>{e={scrollIntoView:!0,...e};const l=()=>{Hr()&&r.dom.focus(),requestAnimationFrame(()=>{n.isDestroyed||(r.focus(),e!=null&&e.scrollIntoView&&n.commands.scrollIntoView())})};if(r.hasFocus()&&t===null||t===!1)return!0;if(o&&t===null&&!wo(n.state.selection))return l(),!0;const u=Km(a.doc,t)||n.state.selection,c=n.state.selection.eq(u);return o&&(c||a.setSelection(u),c&&a.storedMarks&&a.setStoredMarks(a.storedMarks),l()),!0},Xm=(t,e)=>n=>t.every((r,a)=>e(r,{...n,index:a})),Jm=(t,e)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},t,e);function Co(t){const e=`<body>${t}</body>`;return new window.DOMParser().parseFromString(e,"text/html").body}function Yn(t,e,n){if(n={slice:!0,parseOptions:{},...n},typeof t=="object"&&t!==null)try{return Array.isArray(t)&&t.length>0?ae.fromArray(t.map(r=>e.nodeFromJSON(r))):e.nodeFromJSON(t)}catch(r){return console.warn("[tiptap warn]: Invalid content.","Passed value:",t,"Error:",r),Yn("",e,n)}if(typeof t=="string"){const r=Bn.fromSchema(e);return n.slice?r.parseSlice(Co(t),n.parseOptions).content:r.parse(Co(t),n.parseOptions)}return Yn("",e,n)}function Zm(t,e,n){const r=t.steps.length-1;if(r<e)return;const a=t.steps[r];if(!(a instanceof rt||a instanceof It))return;const o=t.mapping.maps[r];let l=0;o.forEach((u,c,d,f)=>{l===0&&(l=f)}),t.setSelection(fe.near(t.doc.resolve(l),n))}const Hm=t=>t.toString().startsWith("<"),ey=(t,e,n)=>({tr:r,dispatch:a,editor:o})=>{if(a){n={parseOptions:{},updateSelection:!0,...n};const l=Yn(e,o.schema,{parseOptions:{preserveWhitespace:"full",...n.parseOptions}});if(l.toString()==="<>")return!0;let{from:u,to:c}=typeof t=="number"?{from:t,to:t}:t,d=!0,f=!0;if((Hm(l)?l:[l]).forEach(g=>{g.check(),d=d?g.isText&&g.marks.length===0:!1,f=f?g.isBlock:!1}),u===c&&f){const{parent:g}=r.doc.resolve(u);g.isTextblock&&!g.type.spec.code&&!g.childCount&&(u-=1,c+=1)}d?Array.isArray(e)?r.insertText(e.map(g=>g.text||"").join(""),u,c):typeof e=="object"&&e&&e.text?r.insertText(e.text,u,c):r.insertText(e,u,c):r.replaceWith(u,c,l),n.updateSelection&&Zm(r,r.steps.length-1,-1)}return!0},ty=()=>({state:t,dispatch:e})=>Te.joinUp(t,e),ny=()=>({state:t,dispatch:e})=>Te.joinDown(t,e),ry=()=>({state:t,dispatch:e})=>Te.joinBackward(t,e),iy=()=>({state:t,dispatch:e})=>Te.joinForward(t,e);function So(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function ay(t){const e=t.split(/-(?!$)/);let n=e[e.length-1];n==="Space"&&(n=" ");let r,a,o,l;for(let u=0;u<e.length-1;u+=1){const c=e[u];if(/^(cmd|meta|m)$/i.test(c))l=!0;else if(/^a(lt)?$/i.test(c))r=!0;else if(/^(c|ctrl|control)$/i.test(c))a=!0;else if(/^s(hift)?$/i.test(c))o=!0;else if(/^mod$/i.test(c))Hr()||So()?l=!0:a=!0;else throw new Error(`Unrecognized modifier name: ${c}`)}return r&&(n=`Alt-${n}`),a&&(n=`Ctrl-${n}`),l&&(n=`Meta-${n}`),o&&(n=`Shift-${n}`),n}const sy=t=>({editor:e,view:n,tr:r,dispatch:a})=>{const o=ay(t).split(/-(?!$)/),l=o.find(d=>!["Alt","Ctrl","Meta","Shift"].includes(d)),u=new KeyboardEvent("keydown",{key:l==="Space"?" ":l,altKey:o.includes("Alt"),ctrlKey:o.includes("Ctrl"),metaKey:o.includes("Meta"),shiftKey:o.includes("Shift"),bubbles:!0,cancelable:!0}),c=e.captureTransaction(()=>{n.someProp("handleKeyDown",d=>d(n,u))});return c==null||c.steps.forEach(d=>{const f=d.map(r.mapping);f&&a&&r.maybeStep(f)}),!0};function ei(t,e,n={}){const{from:r,to:a,empty:o}=t.selection,l=e?Le(e,t.schema):null,u=[];t.doc.nodesBetween(r,a,(h,g)=>{if(h.isText)return;const m=Math.max(r,g),w=Math.min(a,g+h.nodeSize);u.push({node:h,from:m,to:w})});const c=a-r,d=u.filter(h=>l?l.name===h.node.type.name:!0).filter(h=>Rn(h.node.attrs,n,{strict:!1}));return o?!!d.length:d.reduce((h,g)=>h+g.to-g.from,0)>=c}const oy=(t,e={})=>({state:n,dispatch:r})=>{const a=Le(t,n.schema);return ei(n,a,e)?Te.lift(n,r):!1},ly=()=>({state:t,dispatch:e})=>Te.liftEmptyBlock(t,e),uy=t=>({state:e,dispatch:n})=>{const r=Le(t,e.schema);return dr.liftListItem(r)(e,n)},cy=()=>({state:t,dispatch:e})=>Te.newlineInCode(t,e);function _o(t,e){return e.nodes[t]?"node":e.marks[t]?"mark":null}function ko(t,e){const n=typeof e=="string"?[e]:e;return Object.keys(t).reduce((r,a)=>(n.includes(a)||(r[a]=t[a]),r),{})}const dy=(t,e)=>({tr:n,state:r,dispatch:a})=>{let o=null,l=null;const u=_o(typeof t=="string"?t:t.name,r.schema);return u?(u==="node"&&(o=Le(t,r.schema)),u==="mark"&&(l=xt(t,r.schema)),a&&n.selection.ranges.forEach(c=>{r.doc.nodesBetween(c.$from.pos,c.$to.pos,(d,f)=>{o&&o===d.type&&n.setNodeMarkup(f,void 0,ko(d.attrs,e)),l&&d.marks.length&&d.marks.forEach(h=>{l===h.type&&n.addMark(f,f+d.nodeSize,l.create(ko(h.attrs,e)))})})}),!0):!1},py=()=>({tr:t,dispatch:e})=>(e&&t.scrollIntoView(),!0),hy=()=>({tr:t,commands:e})=>e.setTextSelection({from:0,to:t.doc.content.size}),fy=()=>({state:t,dispatch:e})=>Te.selectNodeBackward(t,e),gy=()=>({state:t,dispatch:e})=>Te.selectNodeForward(t,e),my=()=>({state:t,dispatch:e})=>Te.selectParentNode(t,e),yy=()=>({state:t,dispatch:e})=>Te.selectTextblockEnd(t,e),by=()=>({state:t,dispatch:e})=>Te.selectTextblockStart(t,e);function vy(t,e,n={}){return Yn(t,e,{slice:!1,parseOptions:n})}const xy=(t,e=!1,n={})=>({tr:r,editor:a,dispatch:o})=>{const{doc:l}=r,u=vy(t,a.schema,n);return o&&r.replaceWith(0,l.content.size,u).setMeta("preventUpdate",!e),!0};function wy(t){for(let e=0;e<t.edgeCount;e+=1){const{type:n}=t.edge(e);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}function Cy(t,e){for(let n=t.depth;n>0;n-=1){const r=t.node(n);if(e(r))return{pos:n>0?t.before(n):0,start:t.start(n),depth:n,node:r}}}function ti(t){return e=>Cy(e.$from,t)}function Sy(t,e){const n=xt(e,t.schema),{from:r,to:a,empty:o}=t.selection,l=[];o?(t.storedMarks&&l.push(...t.storedMarks),l.push(...t.selection.$head.marks())):t.doc.nodesBetween(r,a,c=>{l.push(...c.marks)});const u=l.find(c=>c.type.name===n.name);return u?{...u.attrs}:{}}function Qn(t,e,n){return Object.fromEntries(Object.entries(n).filter(([r])=>{const a=t.find(o=>o.type===e&&o.name===r);return a?a.attribute.keepOnSplit:!1}))}function _y(t,e,n={}){const{empty:r,ranges:a}=t.selection,o=e?xt(e,t.schema):null;if(r)return!!(t.storedMarks||t.selection.$from.marks()).filter(h=>o?o.name===h.type.name:!0).find(h=>Rn(h.attrs,n,{strict:!1}));let l=0;const u=[];if(a.forEach(({$from:h,$to:g})=>{const m=h.pos,w=g.pos;t.doc.nodesBetween(m,w,(C,_)=>{if(!C.isText&&!C.marks.length)return;const T=Math.max(m,_),I=Math.min(w,_+C.nodeSize),O=I-T;l+=O,u.push(...C.marks.map(B=>({mark:B,from:T,to:I})))})}),l===0)return!1;const c=u.filter(h=>o?o.name===h.mark.type.name:!0).filter(h=>Rn(h.mark.attrs,n,{strict:!1})).reduce((h,g)=>h+g.to-g.from,0),d=u.filter(h=>o?h.mark.type!==o&&h.mark.type.excludes(o):!0).reduce((h,g)=>h+g.to-g.from,0);return(c>0?c+d:c)>=l}function To(t,e){const{nodeExtensions:n}=Mm(e),r=n.find(l=>l.name===t);if(!r)return!1;const a={name:r.name,options:r.options,storage:r.storage},o=Nt(vt(r,"group",a));return typeof o!="string"?!1:o.split(" ").includes("list")}function ky(t,e,n){var r;const{selection:a}=e;let o=null;if(wo(a)&&(o=a.$cursor),o){const u=(r=t.storedMarks)!==null&&r!==void 0?r:o.marks();return!!n.isInSet(u)||!u.some(c=>c.type.excludes(n))}const{ranges:l}=a;return l.some(({$from:u,$to:c})=>{let d=u.depth===0?t.doc.inlineContent&&t.doc.type.allowsMarkType(n):!1;return t.doc.nodesBetween(u.pos,c.pos,(f,h,g)=>{if(d)return!1;if(f.isInline){const m=!g||g.type.allowsMarkType(n),w=!!n.isInSet(f.marks)||!f.marks.some(C=>C.type.excludes(n));d=m&&w}return!d}),d})}const Ty=(t,e={})=>({tr:n,state:r,dispatch:a})=>{const{selection:o}=n,{empty:l,ranges:u}=o,c=xt(t,r.schema);if(a)if(l){const d=Sy(r,c);n.addStoredMark(c.create({...d,...e}))}else u.forEach(d=>{const f=d.$from.pos,h=d.$to.pos;r.doc.nodesBetween(f,h,(g,m)=>{const w=Math.max(m,f),C=Math.min(m+g.nodeSize,h);g.marks.find(T=>T.type===c)?g.marks.forEach(T=>{c===T.type&&n.addMark(w,C,c.create({...T.attrs,...e}))}):n.addMark(w,C,c.create(e))})});return ky(r,n,c)},Dy=(t,e)=>({tr:n})=>(n.setMeta(t,e),!0),My=(t,e={})=>({state:n,dispatch:r,chain:a})=>{const o=Le(t,n.schema);return o.isTextblock?a().command(({commands:l})=>Te.setBlockType(o,e)(n)?!0:l.clearNodes()).command(({state:l})=>Te.setBlockType(o,e)(l,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},Iy=t=>({tr:e,dispatch:n})=>{if(n){const{doc:r}=e,a=Et(t,0,r.content.size),o=je.create(r,a);e.setSelection(o)}return!0},Ey=t=>({tr:e,dispatch:n})=>{if(n){const{doc:r}=e,{from:a,to:o}=typeof t=="number"?{from:t,to:t}:t,l=ke.atStart(r).from,u=ke.atEnd(r).to,c=Et(a,l,u),d=Et(o,l,u),f=ke.create(r,c,d);e.setSelection(f)}return!0},Ay=t=>({state:e,dispatch:n})=>{const r=Le(t,e.schema);return dr.sinkListItem(r)(e,n)};function Do(t,e){const n=t.storedMarks||t.selection.$to.parentOffset&&t.selection.$from.marks();if(n){const r=n.filter(a=>e==null?void 0:e.includes(a.type.name));t.tr.ensureMarks(r)}}const zy=({keepMarks:t=!0}={})=>({tr:e,state:n,dispatch:r,editor:a})=>{const{selection:o,doc:l}=e,{$from:u,$to:c}=o,d=a.extensionManager.attributes,f=Qn(d,u.node().type.name,u.node().attrs);if(o instanceof je&&o.node.isBlock)return!u.parentOffset||!Gn(l,u.pos)?!1:(r&&(t&&Do(n,a.extensionManager.splittableMarks),e.split(u.pos).scrollIntoView()),!0);if(!u.parent.isBlock)return!1;if(r){const h=c.parentOffset===c.parent.content.size;o instanceof ke&&e.deleteSelection();const g=u.depth===0?void 0:wy(u.node(-1).contentMatchAt(u.indexAfter(-1)));let m=h&&g?[{type:g,attrs:f}]:void 0,w=Gn(e.doc,e.mapping.map(u.pos),1,m);if(!m&&!w&&Gn(e.doc,e.mapping.map(u.pos),1,g?[{type:g}]:void 0)&&(w=!0,m=g?[{type:g,attrs:f}]:void 0),w&&(e.split(e.mapping.map(u.pos),1,m),g&&!h&&!u.parentOffset&&u.parent.type!==g)){const C=e.mapping.map(u.before()),_=e.doc.resolve(C);u.node(-1).canReplaceWith(_.index(),_.index()+1,g)&&e.setNodeMarkup(e.mapping.map(u.before()),g)}t&&Do(n,a.extensionManager.splittableMarks),e.scrollIntoView()}return!0},$y=t=>({tr:e,state:n,dispatch:r,editor:a})=>{var o;const l=Le(t,n.schema),{$from:u,$to:c}=n.selection,d=n.selection.node;if(d&&d.isBlock||u.depth<2||!u.sameParent(c))return!1;const f=u.node(-1);if(f.type!==l)return!1;const h=a.extensionManager.attributes;if(u.parent.content.size===0&&u.node(-1).childCount===u.indexAfter(-1)){if(u.depth===2||u.node(-3).type!==l||u.index(-2)!==u.node(-2).childCount-1)return!1;if(r){let _=ae.empty;const T=u.index(-1)?1:u.index(-2)?2:3;for(let E=u.depth-T;E>=u.depth-3;E-=1)_=ae.from(u.node(E).copy(_));const I=u.indexAfter(-1)<u.node(-2).childCount?1:u.indexAfter(-2)<u.node(-3).childCount?2:3,O=Qn(h,u.node().type.name,u.node().attrs),B=((o=l.contentMatch.defaultType)===null||o===void 0?void 0:o.createAndFill(O))||void 0;_=_.append(ae.from(l.createAndFill(null,B)||void 0));const $=u.before(u.depth-(T-1));e.replace($,u.after(-I),new ce(_,4-T,0));let A=-1;e.doc.nodesBetween($,e.doc.content.size,(E,F)=>{if(A>-1)return!1;E.isTextblock&&E.content.size===0&&(A=F+1)}),A>-1&&e.setSelection(ke.near(e.doc.resolve(A))),e.scrollIntoView()}return!0}const g=c.pos===u.end()?f.contentMatchAt(0).defaultType:null,m=Qn(h,f.type.name,f.attrs),w=Qn(h,u.node().type.name,u.node().attrs);e.delete(u.pos,c.pos);const C=g?[{type:l,attrs:m},{type:g,attrs:w}]:[{type:l,attrs:m}];if(!Gn(e.doc,u.pos,2))return!1;if(r){const{selection:_,storedMarks:T}=n,{splittableMarks:I}=a.extensionManager,O=T||_.$to.parentOffset&&_.$from.marks();if(e.split(u.pos,2,C).scrollIntoView(),!O||!r)return!0;const B=O.filter($=>I.includes($.type.name));e.ensureMarks(B)}return!0},ni=(t,e)=>{const n=ti(l=>l.type===e)(t.selection);if(!n)return!0;const r=t.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(r===void 0)return!0;const a=t.doc.nodeAt(r);return n.node.type===(a==null?void 0:a.type)&&co(t.doc,n.pos)&&t.join(n.pos),!0},ri=(t,e)=>{const n=ti(l=>l.type===e)(t.selection);if(!n)return!0;const r=t.doc.resolve(n.start).after(n.depth);if(r===void 0)return!0;const a=t.doc.nodeAt(r);return n.node.type===(a==null?void 0:a.type)&&co(t.doc,r)&&t.join(r),!0};var Ly=Object.freeze({__proto__:null,blur:Lm,clearContent:Om,clearNodes:Pm,command:Bm,createParagraphNear:Vm,deleteCurrentNode:Nm,deleteNode:qm,deleteRange:Fm,deleteSelection:Gm,enter:Wm,exitCode:jm,extendMarkRange:Ym,first:Qm,focus:Um,forEach:Xm,insertContent:Jm,insertContentAt:ey,joinUp:ty,joinDown:ny,joinBackward:ry,joinForward:iy,keyboardShortcut:sy,lift:oy,liftEmptyBlock:ly,liftListItem:uy,newlineInCode:cy,resetAttributes:dy,scrollIntoView:py,selectAll:hy,selectNodeBackward:fy,selectNodeForward:gy,selectParentNode:my,selectTextblockEnd:yy,selectTextblockStart:by,setContent:xy,setMark:Ty,setMeta:Dy,setNode:My,setNodeSelection:Iy,setTextSelection:Ey,sinkListItem:Ay,splitBlock:zy,splitListItem:$y,toggleList:(t,e,n,r={})=>({editor:a,tr:o,state:l,dispatch:u,chain:c,commands:d,can:f})=>{const{extensions:h,splittableMarks:g}=a.extensionManager,m=Le(t,l.schema),w=Le(e,l.schema),{selection:C,storedMarks:_}=l,{$from:T,$to:I}=C,O=T.blockRange(I),B=_||C.$to.parentOffset&&C.$from.marks();if(!O)return!1;const $=ti(A=>To(A.type.name,h))(C);if(O.depth>=1&&$&&O.depth-$.depth<=1){if($.node.type===m)return d.liftListItem(w);if(To($.node.type.name,h)&&m.validContent($.node.content)&&u)return c().command(()=>(o.setNodeMarkup($.pos,m),!0)).command(()=>ni(o,m)).command(()=>ri(o,m)).run()}return!n||!B||!u?c().command(()=>f().wrapInList(m,r)?!0:d.clearNodes()).wrapInList(m,r).command(()=>ni(o,m)).command(()=>ri(o,m)).run():c().command(()=>{const A=f().wrapInList(m,r),E=B.filter(F=>g.includes(F.type.name));return o.ensureMarks(E),A?!0:d.clearNodes()}).wrapInList(m,r).command(()=>ni(o,m)).command(()=>ri(o,m)).run()},toggleMark:(t,e={},n={})=>({state:r,commands:a})=>{const{extendEmptyMarkRange:o=!1}=n,l=xt(t,r.schema);return _y(r,l,e)?a.unsetMark(l,{extendEmptyMarkRange:o}):a.setMark(l,e)},toggleNode:(t,e,n={})=>({state:r,commands:a})=>{const o=Le(t,r.schema),l=Le(e,r.schema);return ei(r,o,n)?a.setNode(l):a.setNode(o,n)},toggleWrap:(t,e={})=>({state:n,commands:r})=>{const a=Le(t,n.schema);return ei(n,a,e)?r.lift(a):r.wrapIn(a,e)},undoInputRule:()=>({state:t,dispatch:e})=>{const n=t.plugins;for(let r=0;r<n.length;r+=1){const a=n[r];let o;if(a.spec.isInputRules&&(o=a.getState(t))){if(e){const l=t.tr,u=o.transform;for(let c=u.steps.length-1;c>=0;c-=1)l.step(u.steps[c].invert(u.docs[c]));if(o.text){const c=l.doc.resolve(o.from).marks();l.replaceWith(o.from,o.to,t.schema.text(o.text,c))}else l.delete(o.from,o.to)}return!0}}return!1},unsetAllMarks:()=>({tr:t,dispatch:e})=>{const{selection:n}=t,{empty:r,ranges:a}=n;return r||e&&a.forEach(o=>{t.removeMark(o.$from.pos,o.$to.pos)}),!0},unsetMark:(t,e={})=>({tr:n,state:r,dispatch:a})=>{var o;const{extendEmptyMarkRange:l=!1}=e,{selection:u}=n,c=xt(t,r.schema),{$from:d,empty:f,ranges:h}=u;if(!a)return!0;if(f&&l){let{from:g,to:m}=u;const w=(o=d.marks().find(_=>_.type===c))===null||o===void 0?void 0:o.attrs,C=xo(d,c,w);C&&(g=C.from,m=C.to),n.removeMark(g,m,c)}else h.forEach(g=>{n.removeMark(g.$from.pos,g.$to.pos,c)});return n.removeStoredMark(c),!0},updateAttributes:(t,e={})=>({tr:n,state:r,dispatch:a})=>{let o=null,l=null;const u=_o(typeof t=="string"?t:t.name,r.schema);return u?(u==="node"&&(o=Le(t,r.schema)),u==="mark"&&(l=xt(t,r.schema)),a&&n.selection.ranges.forEach(c=>{const d=c.$from.pos,f=c.$to.pos;r.doc.nodesBetween(d,f,(h,g)=>{o&&o===h.type&&n.setNodeMarkup(g,void 0,{...h.attrs,...e}),l&&h.marks.length&&h.marks.forEach(m=>{if(l===m.type){const w=Math.max(g,d),C=Math.min(g+h.nodeSize,f);n.addMark(w,C,l.create({...m.attrs,...e}))}})})}),!0):!1},wrapIn:(t,e={})=>({state:n,dispatch:r})=>{const a=Le(t,n.schema);return Te.wrapIn(a,e)(n,r)},wrapInList:(t,e={})=>({state:n,dispatch:r})=>{const a=Le(t,n.schema);return dr.wrapInList(a,e)(n,r)}});it.create({name:"commands",addCommands(){return{...Ly}}}),it.create({name:"editable",addProseMirrorPlugins(){return[new nn({key:new rn("editable"),props:{editable:()=>this.editor.options.editable}})]}}),it.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:t}=this;return[new nn({key:new rn("focusEvents"),props:{handleDOMEvents:{focus:(e,n)=>{t.isFocused=!0;const r=t.state.tr.setMeta("focus",{event:n}).setMeta("addToHistory",!1);return e.dispatch(r),!1},blur:(e,n)=>{t.isFocused=!1;const r=t.state.tr.setMeta("blur",{event:n}).setMeta("addToHistory",!1);return e.dispatch(r),!1}}}})]}}),it.create({name:"keymap",addKeyboardShortcuts(){const t=()=>this.editor.commands.first(({commands:l})=>[()=>l.undoInputRule(),()=>l.command(({tr:u})=>{const{selection:c,doc:d}=u,{empty:f,$anchor:h}=c,{pos:g,parent:m}=h,w=fe.atStart(d).from===g;return!f||!w||!m.type.isTextblock||m.textContent.length?!1:l.clearNodes()}),()=>l.deleteSelection(),()=>l.joinBackward(),()=>l.selectNodeBackward()]),e=()=>this.editor.commands.first(({commands:l})=>[()=>l.deleteSelection(),()=>l.deleteCurrentNode(),()=>l.joinForward(),()=>l.selectNodeForward()]),r={Enter:()=>this.editor.commands.first(({commands:l})=>[()=>l.newlineInCode(),()=>l.createParagraphNear(),()=>l.liftEmptyBlock(),()=>l.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:t,"Mod-Backspace":t,"Shift-Backspace":t,Delete:e,"Mod-Delete":e,"Mod-a":()=>this.editor.commands.selectAll()},a={...r},o={...r,"Ctrl-h":t,"Alt-Backspace":t,"Ctrl-d":e,"Ctrl-Alt-Backspace":e,"Alt-Delete":e,"Alt-d":e,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return Hr()||So()?o:a},addProseMirrorPlugins(){return[new nn({key:new rn("clearDocument"),appendTransaction:(t,e,n)=>{if(!(t.some(w=>w.docChanged)&&!e.doc.eq(n.doc)))return;const{empty:a,from:o,to:l}=e.selection,u=fe.atStart(e.doc).from,c=fe.atEnd(e.doc).to;if(a||!(o===u&&l===c)||!(n.doc.textBetween(0,n.doc.content.size," "," ").length===0))return;const h=n.tr,g=bo({state:n,transaction:h}),{commands:m}=new Dm({editor:this.editor,state:g});if(m.clearNodes(),!!h.steps.length)return h}})]}}),it.create({name:"tabindex",addProseMirrorPlugins(){return[new nn({key:new rn("tabindex"),props:{attributes:this.editor.isEditable?{tabindex:"0"}:{}}})]}});const Mo=it.create({name:"fontSize",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontSize:{default:null,parseHTML:t=>t.style.fontSize.replace(/['"]+/g,""),renderHTML:t=>t.fontSize?{style:`font-size: ${t.fontSize}`}:{}}}}]},addCommands(){return{setFontSize:t=>({chain:e})=>e().setMark("textStyle",{fontSize:t}).run(),unsetFontSize:()=>({chain:t})=>t().setMark("textStyle",{fontSize:null}).removeEmptyTextStyle().run()}}}),Oy=["8","10","12","14","16","18","20","24","30","36","48","60","72"].map(t=>`${t}px`),Py=[{label:"auto",value:""}].concat(Oy.map(t=>({label:t,value:t}))),By={input:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important"}},Vy=({editor:t})=>{const e=t.getAttributes("textStyle").fontSize;return i(J.RichTextEditor.ControlsGroup,{children:i(s.NativeSelect,{size:"xs",icon:i(L.IconTextSize,{stroke:1.5,size:16}),data:Py,styles:By,value:e||"",onChange:n=>{const r=n.currentTarget.value;r?t.chain().focus().setFontSize(r).run():t.chain().focus().unsetFontSize().run()}})})},Kn=({value:t,styles:e={}})=>{const n=Ba.useEditor({extensions:[Va,Pa,J.Link,Ia,Ma,Ta,za.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),Oa,La,$a,Ea.configure({types:["heading","paragraph"]}),Da.configure({placeholder:"This is placeholder"}),Aa,ka.Color,Mo],content:t,editable:!1});y.useEffect(()=>{n==null||n.commands.setContent(t)},[t,n]);const r=y.useMemo(()=>x.defaultsDeep({},{content:Gr},e),[e]);return i(J.RichTextEditor,{editor:n,styles:r,children:i(J.RichTextEditor.Content,{})})};function Ny(t,e){const n={};return t.forEach(r=>{const{name:a,data_field:o,aggregation:l}=r,u=kn(e,o,l);n[a]=et(r,u)}),n}function qy(t){const e=document.createElement("span");return e.innerHTML=t,e.innerText}function Fy(t,e,n){try{return new Function("payload",`
246
+ `,textSerializers:l={}}=n||{};let u="",c=!0;return e.nodesBetween(r,a,(d,f,h,g)=>{var m;const C=l==null?void 0:l[d.type.name];C?(d.isBlock&&!c&&(u+=o,c=!0),h&&(u+=C({node:d,pos:f,parent:h,index:g,range:t}))):d.isText?(u+=(m=d==null?void 0:d.text)===null||m===void 0?void 0:m.slice(Math.max(r,f)-f,a-f),c=!1):d.isBlock&&!c&&(u+=o,c=!0)}),u}function Wm(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,t])=>t.spec.toText).map(([t,n])=>[t,n.spec.toText]))}at.create({name:"clipboardTextSerializer",addProseMirrorPlugins(){return[new rn({key:new an("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:e}=this,{state:t,schema:n}=e,{doc:r,selection:a}=t,{ranges:o}=a,l=Math.min(...o.map(f=>f.$from.pos)),u=Math.max(...o.map(f=>f.$to.pos)),c=Wm(n);return Gm(r,{from:l,to:u},{textSerializers:c})}}})]}});const Rm=()=>({editor:e,view:t})=>(requestAnimationFrame(()=>{var n;e.isDestroyed||(t.dom.blur(),(n=window==null?void 0:window.getSelection())===null||n===void 0||n.removeAllRanges())}),!0),jm=(e=!1)=>({commands:t})=>t.setContent("",e),Ym=()=>({state:e,tr:t,dispatch:n})=>{const{selection:r}=t,{ranges:a}=r;return n&&a.forEach(({$from:o,$to:l})=>{e.doc.nodesBetween(o.pos,l.pos,(u,c)=>{if(u.type.isText)return;const{doc:d,mapping:f}=t,h=d.resolve(f.map(c)),g=d.resolve(f.map(c+u.nodeSize)),m=h.blockRange(g);if(!m)return;const C=$m(m);if(u.type.isTextblock){const{defaultType:w}=h.parent.contentMatchAt(h.index());t.setNodeMarkup(m.start,w)}(C||C===0)&&t.lift(m,C)})}),!0},Qm=e=>t=>e(t),Km=()=>({state:e,dispatch:t})=>De.createParagraphNear(e,t),Um=()=>({tr:e,dispatch:t})=>{const{selection:n}=e,r=n.$anchor.node();if(r.content.size>0)return!1;const a=e.selection.$anchor;for(let o=a.depth;o>0;o-=1)if(a.node(o).type===r.type){if(t){const u=a.before(o),c=a.after(o);e.delete(u,c).scrollIntoView()}return!0}return!1},Xm=e=>({tr:t,state:n,dispatch:r})=>{const a=Le(e,n.schema),o=t.selection.$anchor;for(let l=o.depth;l>0;l-=1)if(o.node(l).type===a){if(r){const c=o.before(l),d=o.after(l);t.delete(c,d).scrollIntoView()}return!0}return!1},Jm=e=>({tr:t,dispatch:n})=>{const{from:r,to:a}=e;return n&&t.delete(r,a),!0},Zm=()=>({state:e,dispatch:t})=>De.deleteSelection(e,t),Hm=()=>({commands:e})=>e.keyboardShortcut("Enter"),ey=()=>({state:e,dispatch:t})=>De.exitCode(e,t);function Yn(e,t,n={strict:!0}){const r=Object.keys(t);return r.length?r.every(a=>n.strict?t[a]===e[a]:qm(t[a])?t[a].test(e[a]):t[a]===e[a]):!0}function ei(e,t,n={}){return e.find(r=>r.type===t&&Yn(r.attrs,n))}function ty(e,t,n={}){return!!ei(e,t,n)}function no(e,t,n={}){if(!e||!t)return;let r=e.parent.childAfter(e.parentOffset);if(e.parentOffset===r.offset&&r.offset!==0&&(r=e.parent.childBefore(e.parentOffset)),!r.node)return;const a=ei([...r.node.marks],t,n);if(!a)return;let o=r.index,l=e.start()+r.offset,u=o+1,c=l+r.node.nodeSize;for(ei([...r.node.marks],t,n);o>0&&a.isInSet(e.parent.child(o-1).marks);)o-=1,l-=e.parent.child(o).nodeSize;for(;u<e.parent.childCount&&ty([...e.parent.child(u).marks],t,n);)c+=e.parent.child(u).nodeSize,u+=1;return{from:l,to:c}}function wt(e,t){if(typeof e=="string"){if(!t.marks[e])throw Error(`There is no mark type named '${e}'. Maybe you forgot to add the extension?`);return t.marks[e]}return e}const ny=(e,t={})=>({tr:n,state:r,dispatch:a})=>{const o=wt(e,r.schema),{doc:l,selection:u}=n,{$from:c,from:d,to:f}=u;if(a){const h=no(c,o,t);if(h&&h.from<=d&&h.to>=f){const g=ke.create(l,h.from,h.to);n.setSelection(g)}}return!0},ry=e=>t=>{const n=typeof e=="function"?e(t):e;for(let r=0;r<n.length;r+=1)if(n[r](t))return!0;return!1};function ro(e){return e instanceof ke}function At(e=0,t=0,n=0){return Math.min(Math.max(e,t),n)}function iy(e,t=null){if(!t)return null;const n=he.atStart(e),r=he.atEnd(e);if(t==="start"||t===!0)return n;if(t==="end")return r;const a=n.from,o=r.to;return t==="all"?ke.create(e,At(0,a,o),At(e.content.size,a,o)):ke.create(e,At(t,a,o),At(t,a,o))}function ti(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}const ay=(e=null,t={})=>({editor:n,view:r,tr:a,dispatch:o})=>{t={scrollIntoView:!0,...t};const l=()=>{ti()&&r.dom.focus(),requestAnimationFrame(()=>{n.isDestroyed||(r.focus(),t!=null&&t.scrollIntoView&&n.commands.scrollIntoView())})};if(r.hasFocus()&&e===null||e===!1)return!0;if(o&&e===null&&!ro(n.state.selection))return l(),!0;const u=iy(a.doc,e)||n.state.selection,c=n.state.selection.eq(u);return o&&(c||a.setSelection(u),c&&a.storedMarks&&a.setStoredMarks(a.storedMarks),l()),!0},sy=(e,t)=>n=>e.every((r,a)=>t(r,{...n,index:a})),oy=(e,t)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},e,t);function io(e){const t=`<body>${e}</body>`;return new window.DOMParser().parseFromString(t,"text/html").body}function Qn(e,t,n){if(n={slice:!0,parseOptions:{},...n},typeof e=="object"&&e!==null)try{return Array.isArray(e)&&e.length>0?ie.fromArray(e.map(r=>t.nodeFromJSON(r))):t.nodeFromJSON(e)}catch(r){return console.warn("[tiptap warn]: Invalid content.","Passed value:",e,"Error:",r),Qn("",t,n)}if(typeof e=="string"){const r=Vn.fromSchema(t);return n.slice?r.parseSlice(io(e),n.parseOptions).content:r.parse(io(e),n.parseOptions)}return Qn("",t,n)}function ly(e,t,n){const r=e.steps.length-1;if(r<t)return;const a=e.steps[r];if(!(a instanceof it||a instanceof Et))return;const o=e.mapping.maps[r];let l=0;o.forEach((u,c,d,f)=>{l===0&&(l=f)}),e.setSelection(he.near(e.doc.resolve(l),n))}const uy=e=>e.toString().startsWith("<"),cy=(e,t,n)=>({tr:r,dispatch:a,editor:o})=>{if(a){n={parseOptions:{},updateSelection:!0,...n};const l=Qn(t,o.schema,{parseOptions:{preserveWhitespace:"full",...n.parseOptions}});if(l.toString()==="<>")return!0;let{from:u,to:c}=typeof e=="number"?{from:e,to:e}:e,d=!0,f=!0;if((uy(l)?l:[l]).forEach(g=>{g.check(),d=d?g.isText&&g.marks.length===0:!1,f=f?g.isBlock:!1}),u===c&&f){const{parent:g}=r.doc.resolve(u);g.isTextblock&&!g.type.spec.code&&!g.childCount&&(u-=1,c+=1)}d?Array.isArray(t)?r.insertText(t.map(g=>g.text||"").join(""),u,c):typeof t=="object"&&t&&t.text?r.insertText(t.text,u,c):r.insertText(t,u,c):r.replaceWith(u,c,l),n.updateSelection&&ly(r,r.steps.length-1,-1)}return!0},dy=()=>({state:e,dispatch:t})=>De.joinUp(e,t),py=()=>({state:e,dispatch:t})=>De.joinDown(e,t),hy=()=>({state:e,dispatch:t})=>De.joinBackward(e,t),fy=()=>({state:e,dispatch:t})=>De.joinForward(e,t);function ao(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function gy(e){const t=e.split(/-(?!$)/);let n=t[t.length-1];n==="Space"&&(n=" ");let r,a,o,l;for(let u=0;u<t.length-1;u+=1){const c=t[u];if(/^(cmd|meta|m)$/i.test(c))l=!0;else if(/^a(lt)?$/i.test(c))r=!0;else if(/^(c|ctrl|control)$/i.test(c))a=!0;else if(/^s(hift)?$/i.test(c))o=!0;else if(/^mod$/i.test(c))ti()||ao()?l=!0:a=!0;else throw new Error(`Unrecognized modifier name: ${c}`)}return r&&(n=`Alt-${n}`),a&&(n=`Ctrl-${n}`),l&&(n=`Meta-${n}`),o&&(n=`Shift-${n}`),n}const my=e=>({editor:t,view:n,tr:r,dispatch:a})=>{const o=gy(e).split(/-(?!$)/),l=o.find(d=>!["Alt","Ctrl","Meta","Shift"].includes(d)),u=new KeyboardEvent("keydown",{key:l==="Space"?" ":l,altKey:o.includes("Alt"),ctrlKey:o.includes("Ctrl"),metaKey:o.includes("Meta"),shiftKey:o.includes("Shift"),bubbles:!0,cancelable:!0}),c=t.captureTransaction(()=>{n.someProp("handleKeyDown",d=>d(n,u))});return c==null||c.steps.forEach(d=>{const f=d.map(r.mapping);f&&a&&r.maybeStep(f)}),!0};function ni(e,t,n={}){const{from:r,to:a,empty:o}=e.selection,l=t?Le(t,e.schema):null,u=[];e.doc.nodesBetween(r,a,(h,g)=>{if(h.isText)return;const m=Math.max(r,g),C=Math.min(a,g+h.nodeSize);u.push({node:h,from:m,to:C})});const c=a-r,d=u.filter(h=>l?l.name===h.node.type.name:!0).filter(h=>Yn(h.node.attrs,n,{strict:!1}));return o?!!d.length:d.reduce((h,g)=>h+g.to-g.from,0)>=c}const yy=(e,t={})=>({state:n,dispatch:r})=>{const a=Le(e,n.schema);return ni(n,a,t)?De.lift(n,r):!1},by=()=>({state:e,dispatch:t})=>De.liftEmptyBlock(e,t),vy=e=>({state:t,dispatch:n})=>{const r=Le(e,t.schema);return pr.liftListItem(r)(t,n)},xy=()=>({state:e,dispatch:t})=>De.newlineInCode(e,t);function so(e,t){return t.nodes[e]?"node":t.marks[e]?"mark":null}function oo(e,t){const n=typeof t=="string"?[t]:t;return Object.keys(e).reduce((r,a)=>(n.includes(a)||(r[a]=e[a]),r),{})}const wy=(e,t)=>({tr:n,state:r,dispatch:a})=>{let o=null,l=null;const u=so(typeof e=="string"?e:e.name,r.schema);return u?(u==="node"&&(o=Le(e,r.schema)),u==="mark"&&(l=wt(e,r.schema)),a&&n.selection.ranges.forEach(c=>{r.doc.nodesBetween(c.$from.pos,c.$to.pos,(d,f)=>{o&&o===d.type&&n.setNodeMarkup(f,void 0,oo(d.attrs,t)),l&&d.marks.length&&d.marks.forEach(h=>{l===h.type&&n.addMark(f,f+d.nodeSize,l.create(oo(h.attrs,t)))})})}),!0):!1},Cy=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),Sy=()=>({tr:e,commands:t})=>t.setTextSelection({from:0,to:e.doc.content.size}),_y=()=>({state:e,dispatch:t})=>De.selectNodeBackward(e,t),ky=()=>({state:e,dispatch:t})=>De.selectNodeForward(e,t),Ty=()=>({state:e,dispatch:t})=>De.selectParentNode(e,t),Dy=()=>({state:e,dispatch:t})=>De.selectTextblockEnd(e,t),My=()=>({state:e,dispatch:t})=>De.selectTextblockStart(e,t);function Iy(e,t,n={}){return Qn(e,t,{slice:!1,parseOptions:n})}const Ey=(e,t=!1,n={})=>({tr:r,editor:a,dispatch:o})=>{const{doc:l}=r,u=Iy(e,a.schema,n);return o&&r.replaceWith(0,l.content.size,u).setMeta("preventUpdate",!t),!0};function Ay(e){for(let t=0;t<e.edgeCount;t+=1){const{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}function zy(e,t){for(let n=e.depth;n>0;n-=1){const r=e.node(n);if(t(r))return{pos:n>0?e.before(n):0,start:e.start(n),depth:n,node:r}}}function ri(e){return t=>zy(t.$from,e)}function $y(e,t){const n=wt(t,e.schema),{from:r,to:a,empty:o}=e.selection,l=[];o?(e.storedMarks&&l.push(...e.storedMarks),l.push(...e.selection.$head.marks())):e.doc.nodesBetween(r,a,c=>{l.push(...c.marks)});const u=l.find(c=>c.type.name===n.name);return u?{...u.attrs}:{}}function Kn(e,t,n){return Object.fromEntries(Object.entries(n).filter(([r])=>{const a=e.find(o=>o.type===t&&o.name===r);return a?a.attribute.keepOnSplit:!1}))}function Ly(e,t,n={}){const{empty:r,ranges:a}=e.selection,o=t?wt(t,e.schema):null;if(r)return!!(e.storedMarks||e.selection.$from.marks()).filter(h=>o?o.name===h.type.name:!0).find(h=>Yn(h.attrs,n,{strict:!1}));let l=0;const u=[];if(a.forEach(({$from:h,$to:g})=>{const m=h.pos,C=g.pos;e.doc.nodesBetween(m,C,(w,_)=>{if(!w.isText&&!w.marks.length)return;const D=Math.max(m,_),E=Math.min(C,_+w.nodeSize),O=E-D;l+=O,u.push(...w.marks.map(B=>({mark:B,from:D,to:E})))})}),l===0)return!1;const c=u.filter(h=>o?o.name===h.mark.type.name:!0).filter(h=>Yn(h.mark.attrs,n,{strict:!1})).reduce((h,g)=>h+g.to-g.from,0),d=u.filter(h=>o?h.mark.type!==o&&h.mark.type.excludes(o):!0).reduce((h,g)=>h+g.to-g.from,0);return(c>0?c+d:c)>=l}function lo(e,t){const{nodeExtensions:n}=Vm(t),r=n.find(l=>l.name===e);if(!r)return!1;const a={name:r.name,options:r.options,storage:r.storage},o=qt(xt(r,"group",a));return typeof o!="string"?!1:o.split(" ").includes("list")}function Oy(e,t,n){var r;const{selection:a}=t;let o=null;if(ro(a)&&(o=a.$cursor),o){const u=(r=e.storedMarks)!==null&&r!==void 0?r:o.marks();return!!n.isInSet(u)||!u.some(c=>c.type.excludes(n))}const{ranges:l}=a;return l.some(({$from:u,$to:c})=>{let d=u.depth===0?e.doc.inlineContent&&e.doc.type.allowsMarkType(n):!1;return e.doc.nodesBetween(u.pos,c.pos,(f,h,g)=>{if(d)return!1;if(f.isInline){const m=!g||g.type.allowsMarkType(n),C=!!n.isInSet(f.marks)||!f.marks.some(w=>w.type.excludes(n));d=m&&C}return!d}),d})}const Py=(e,t={})=>({tr:n,state:r,dispatch:a})=>{const{selection:o}=n,{empty:l,ranges:u}=o,c=wt(e,r.schema);if(a)if(l){const d=$y(r,c);n.addStoredMark(c.create({...d,...t}))}else u.forEach(d=>{const f=d.$from.pos,h=d.$to.pos;r.doc.nodesBetween(f,h,(g,m)=>{const C=Math.max(m,f),w=Math.min(m+g.nodeSize,h);g.marks.find(D=>D.type===c)?g.marks.forEach(D=>{c===D.type&&n.addMark(C,w,c.create({...D.attrs,...t}))}):n.addMark(C,w,c.create(t))})});return Oy(r,n,c)},By=(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),Vy=(e,t={})=>({state:n,dispatch:r,chain:a})=>{const o=Le(e,n.schema);return o.isTextblock?a().command(({commands:l})=>De.setBlockType(o,t)(n)?!0:l.clearNodes()).command(({state:l})=>De.setBlockType(o,t)(l,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},Ny=e=>({tr:t,dispatch:n})=>{if(n){const{doc:r}=t,a=At(e,0,r.content.size),o=Re.create(r,a);t.setSelection(o)}return!0},qy=e=>({tr:t,dispatch:n})=>{if(n){const{doc:r}=t,{from:a,to:o}=typeof e=="number"?{from:e,to:e}:e,l=ke.atStart(r).from,u=ke.atEnd(r).to,c=At(a,l,u),d=At(o,l,u),f=ke.create(r,c,d);t.setSelection(f)}return!0},Fy=e=>({state:t,dispatch:n})=>{const r=Le(e,t.schema);return pr.sinkListItem(r)(t,n)};function uo(e,t){const n=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();if(n){const r=n.filter(a=>t==null?void 0:t.includes(a.type.name));e.tr.ensureMarks(r)}}const Gy=({keepMarks:e=!0}={})=>({tr:t,state:n,dispatch:r,editor:a})=>{const{selection:o,doc:l}=t,{$from:u,$to:c}=o,d=a.extensionManager.attributes,f=Kn(d,u.node().type.name,u.node().attrs);if(o instanceof Re&&o.node.isBlock)return!u.parentOffset||!Wn(l,u.pos)?!1:(r&&(e&&uo(n,a.extensionManager.splittableMarks),t.split(u.pos).scrollIntoView()),!0);if(!u.parent.isBlock)return!1;if(r){const h=c.parentOffset===c.parent.content.size;o instanceof ke&&t.deleteSelection();const g=u.depth===0?void 0:Ay(u.node(-1).contentMatchAt(u.indexAfter(-1)));let m=h&&g?[{type:g,attrs:f}]:void 0,C=Wn(t.doc,t.mapping.map(u.pos),1,m);if(!m&&!C&&Wn(t.doc,t.mapping.map(u.pos),1,g?[{type:g}]:void 0)&&(C=!0,m=g?[{type:g,attrs:f}]:void 0),C&&(t.split(t.mapping.map(u.pos),1,m),g&&!h&&!u.parentOffset&&u.parent.type!==g)){const w=t.mapping.map(u.before()),_=t.doc.resolve(w);u.node(-1).canReplaceWith(_.index(),_.index()+1,g)&&t.setNodeMarkup(t.mapping.map(u.before()),g)}e&&uo(n,a.extensionManager.splittableMarks),t.scrollIntoView()}return!0},Wy=e=>({tr:t,state:n,dispatch:r,editor:a})=>{var o;const l=Le(e,n.schema),{$from:u,$to:c}=n.selection,d=n.selection.node;if(d&&d.isBlock||u.depth<2||!u.sameParent(c))return!1;const f=u.node(-1);if(f.type!==l)return!1;const h=a.extensionManager.attributes;if(u.parent.content.size===0&&u.node(-1).childCount===u.indexAfter(-1)){if(u.depth===2||u.node(-3).type!==l||u.index(-2)!==u.node(-2).childCount-1)return!1;if(r){let _=ie.empty;const D=u.index(-1)?1:u.index(-2)?2:3;for(let I=u.depth-D;I>=u.depth-3;I-=1)_=ie.from(u.node(I).copy(_));const E=u.indexAfter(-1)<u.node(-2).childCount?1:u.indexAfter(-2)<u.node(-3).childCount?2:3,O=Kn(h,u.node().type.name,u.node().attrs),B=((o=l.contentMatch.defaultType)===null||o===void 0?void 0:o.createAndFill(O))||void 0;_=_.append(ie.from(l.createAndFill(null,B)||void 0));const $=u.before(u.depth-(D-1));t.replace($,u.after(-E),new ce(_,4-D,0));let A=-1;t.doc.nodesBetween($,t.doc.content.size,(I,F)=>{if(A>-1)return!1;I.isTextblock&&I.content.size===0&&(A=F+1)}),A>-1&&t.setSelection(ke.near(t.doc.resolve(A))),t.scrollIntoView()}return!0}const g=c.pos===u.end()?f.contentMatchAt(0).defaultType:null,m=Kn(h,f.type.name,f.attrs),C=Kn(h,u.node().type.name,u.node().attrs);t.delete(u.pos,c.pos);const w=g?[{type:l,attrs:m},{type:g,attrs:C}]:[{type:l,attrs:m}];if(!Wn(t.doc,u.pos,2))return!1;if(r){const{selection:_,storedMarks:D}=n,{splittableMarks:E}=a.extensionManager,O=D||_.$to.parentOffset&&_.$from.marks();if(t.split(u.pos,2,w).scrollIntoView(),!O||!r)return!0;const B=O.filter($=>E.includes($.type.name));t.ensureMarks(B)}return!0},ii=(e,t)=>{const n=ri(l=>l.type===t)(e.selection);if(!n)return!0;const r=e.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(r===void 0)return!0;const a=e.doc.nodeAt(r);return n.node.type===(a==null?void 0:a.type)&&Qs(e.doc,n.pos)&&e.join(n.pos),!0},ai=(e,t)=>{const n=ri(l=>l.type===t)(e.selection);if(!n)return!0;const r=e.doc.resolve(n.start).after(n.depth);if(r===void 0)return!0;const a=e.doc.nodeAt(r);return n.node.type===(a==null?void 0:a.type)&&Qs(e.doc,r)&&e.join(r),!0};var Ry=Object.freeze({__proto__:null,blur:Rm,clearContent:jm,clearNodes:Ym,command:Qm,createParagraphNear:Km,deleteCurrentNode:Um,deleteNode:Xm,deleteRange:Jm,deleteSelection:Zm,enter:Hm,exitCode:ey,extendMarkRange:ny,first:ry,focus:ay,forEach:sy,insertContent:oy,insertContentAt:cy,joinUp:dy,joinDown:py,joinBackward:hy,joinForward:fy,keyboardShortcut:my,lift:yy,liftEmptyBlock:by,liftListItem:vy,newlineInCode:xy,resetAttributes:wy,scrollIntoView:Cy,selectAll:Sy,selectNodeBackward:_y,selectNodeForward:ky,selectParentNode:Ty,selectTextblockEnd:Dy,selectTextblockStart:My,setContent:Ey,setMark:Py,setMeta:By,setNode:Vy,setNodeSelection:Ny,setTextSelection:qy,sinkListItem:Fy,splitBlock:Gy,splitListItem:Wy,toggleList:(e,t,n,r={})=>({editor:a,tr:o,state:l,dispatch:u,chain:c,commands:d,can:f})=>{const{extensions:h,splittableMarks:g}=a.extensionManager,m=Le(e,l.schema),C=Le(t,l.schema),{selection:w,storedMarks:_}=l,{$from:D,$to:E}=w,O=D.blockRange(E),B=_||w.$to.parentOffset&&w.$from.marks();if(!O)return!1;const $=ri(A=>lo(A.type.name,h))(w);if(O.depth>=1&&$&&O.depth-$.depth<=1){if($.node.type===m)return d.liftListItem(C);if(lo($.node.type.name,h)&&m.validContent($.node.content)&&u)return c().command(()=>(o.setNodeMarkup($.pos,m),!0)).command(()=>ii(o,m)).command(()=>ai(o,m)).run()}return!n||!B||!u?c().command(()=>f().wrapInList(m,r)?!0:d.clearNodes()).wrapInList(m,r).command(()=>ii(o,m)).command(()=>ai(o,m)).run():c().command(()=>{const A=f().wrapInList(m,r),I=B.filter(F=>g.includes(F.type.name));return o.ensureMarks(I),A?!0:d.clearNodes()}).wrapInList(m,r).command(()=>ii(o,m)).command(()=>ai(o,m)).run()},toggleMark:(e,t={},n={})=>({state:r,commands:a})=>{const{extendEmptyMarkRange:o=!1}=n,l=wt(e,r.schema);return Ly(r,l,t)?a.unsetMark(l,{extendEmptyMarkRange:o}):a.setMark(l,t)},toggleNode:(e,t,n={})=>({state:r,commands:a})=>{const o=Le(e,r.schema),l=Le(t,r.schema);return ni(r,o,n)?a.setNode(l):a.setNode(o,n)},toggleWrap:(e,t={})=>({state:n,commands:r})=>{const a=Le(e,n.schema);return ni(n,a,t)?r.lift(a):r.wrapIn(a,t)},undoInputRule:()=>({state:e,dispatch:t})=>{const n=e.plugins;for(let r=0;r<n.length;r+=1){const a=n[r];let o;if(a.spec.isInputRules&&(o=a.getState(e))){if(t){const l=e.tr,u=o.transform;for(let c=u.steps.length-1;c>=0;c-=1)l.step(u.steps[c].invert(u.docs[c]));if(o.text){const c=l.doc.resolve(o.from).marks();l.replaceWith(o.from,o.to,e.schema.text(o.text,c))}else l.delete(o.from,o.to)}return!0}}return!1},unsetAllMarks:()=>({tr:e,dispatch:t})=>{const{selection:n}=e,{empty:r,ranges:a}=n;return r||t&&a.forEach(o=>{e.removeMark(o.$from.pos,o.$to.pos)}),!0},unsetMark:(e,t={})=>({tr:n,state:r,dispatch:a})=>{var o;const{extendEmptyMarkRange:l=!1}=t,{selection:u}=n,c=wt(e,r.schema),{$from:d,empty:f,ranges:h}=u;if(!a)return!0;if(f&&l){let{from:g,to:m}=u;const C=(o=d.marks().find(_=>_.type===c))===null||o===void 0?void 0:o.attrs,w=no(d,c,C);w&&(g=w.from,m=w.to),n.removeMark(g,m,c)}else h.forEach(g=>{n.removeMark(g.$from.pos,g.$to.pos,c)});return n.removeStoredMark(c),!0},updateAttributes:(e,t={})=>({tr:n,state:r,dispatch:a})=>{let o=null,l=null;const u=so(typeof e=="string"?e:e.name,r.schema);return u?(u==="node"&&(o=Le(e,r.schema)),u==="mark"&&(l=wt(e,r.schema)),a&&n.selection.ranges.forEach(c=>{const d=c.$from.pos,f=c.$to.pos;r.doc.nodesBetween(d,f,(h,g)=>{o&&o===h.type&&n.setNodeMarkup(g,void 0,{...h.attrs,...t}),l&&h.marks.length&&h.marks.forEach(m=>{if(l===m.type){const C=Math.max(g,d),w=Math.min(g+h.nodeSize,f);n.addMark(C,w,l.create({...m.attrs,...t}))}})})}),!0):!1},wrapIn:(e,t={})=>({state:n,dispatch:r})=>{const a=Le(e,n.schema);return De.wrapIn(a,t)(n,r)},wrapInList:(e,t={})=>({state:n,dispatch:r})=>{const a=Le(e,n.schema);return pr.wrapInList(a,t)(n,r)}});at.create({name:"commands",addCommands(){return{...Ry}}}),at.create({name:"editable",addProseMirrorPlugins(){return[new rn({key:new an("editable"),props:{editable:()=>this.editor.options.editable}})]}}),at.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:e}=this;return[new rn({key:new an("focusEvents"),props:{handleDOMEvents:{focus:(t,n)=>{e.isFocused=!0;const r=e.state.tr.setMeta("focus",{event:n}).setMeta("addToHistory",!1);return t.dispatch(r),!1},blur:(t,n)=>{e.isFocused=!1;const r=e.state.tr.setMeta("blur",{event:n}).setMeta("addToHistory",!1);return t.dispatch(r),!1}}}})]}}),at.create({name:"keymap",addKeyboardShortcuts(){const e=()=>this.editor.commands.first(({commands:l})=>[()=>l.undoInputRule(),()=>l.command(({tr:u})=>{const{selection:c,doc:d}=u,{empty:f,$anchor:h}=c,{pos:g,parent:m}=h,C=he.atStart(d).from===g;return!f||!C||!m.type.isTextblock||m.textContent.length?!1:l.clearNodes()}),()=>l.deleteSelection(),()=>l.joinBackward(),()=>l.selectNodeBackward()]),t=()=>this.editor.commands.first(({commands:l})=>[()=>l.deleteSelection(),()=>l.deleteCurrentNode(),()=>l.joinForward(),()=>l.selectNodeForward()]),r={Enter:()=>this.editor.commands.first(({commands:l})=>[()=>l.newlineInCode(),()=>l.createParagraphNear(),()=>l.liftEmptyBlock(),()=>l.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:e,"Mod-Backspace":e,"Shift-Backspace":e,Delete:t,"Mod-Delete":t,"Mod-a":()=>this.editor.commands.selectAll()},a={...r},o={...r,"Ctrl-h":e,"Alt-Backspace":e,"Ctrl-d":t,"Ctrl-Alt-Backspace":t,"Alt-Delete":t,"Alt-d":t,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return ti()||ao()?o:a},addProseMirrorPlugins(){return[new rn({key:new an("clearDocument"),appendTransaction:(e,t,n)=>{if(!(e.some(C=>C.docChanged)&&!t.doc.eq(n.doc)))return;const{empty:a,from:o,to:l}=t.selection,u=he.atStart(t.doc).from,c=he.atEnd(t.doc).to;if(a||!(o===u&&l===c)||!(n.doc.textBetween(0,n.doc.content.size," "," ").length===0))return;const h=n.tr,g=eo({state:n,transaction:h}),{commands:m}=new Bm({editor:this.editor,state:g});if(m.clearNodes(),!!h.steps.length)return h}})]}}),at.create({name:"tabindex",addProseMirrorPlugins(){return[new rn({key:new an("tabindex"),props:{attributes:this.editor.isEditable?{tabindex:"0"}:{}}})]}});const co=at.create({name:"fontSize",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontSize:{default:null,parseHTML:e=>e.style.fontSize.replace(/['"]+/g,""),renderHTML:e=>e.fontSize?{style:`font-size: ${e.fontSize}`}:{}}}}]},addCommands(){return{setFontSize:e=>({chain:t})=>t().setMark("textStyle",{fontSize:e}).run(),unsetFontSize:()=>({chain:e})=>e().setMark("textStyle",{fontSize:null}).removeEmptyTextStyle().run()}}}),jy=["8","10","12","14","16","18","20","24","30","36","48","60","72"].map(e=>`${e}px`),Yy=[{label:"auto",value:""}].concat(jy.map(e=>({label:e,value:e}))),Qy={input:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important"}},Ky=({editor:e})=>{const t=e.getAttributes("textStyle").fontSize;return i(J.RichTextEditor.ControlsGroup,{children:i(s.NativeSelect,{size:"xs",icon:i(L.IconTextSize,{stroke:1.5,size:16}),data:Yy,styles:Qy,value:t||"",onChange:n=>{const r=n.currentTarget.value;r?e.chain().focus().setFontSize(r).run():e.chain().focus().unsetFontSize().run()}})})},Un=({value:e,styles:t={}})=>{const n=qa.useEditor({extensions:[Fa,Na,J.Link,za,Aa,Ia,Oa.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),Va,Ba,Pa,$a.configure({types:["heading","paragraph"]}),Ea.configure({placeholder:"This is placeholder"}),La,Ma.Color,co],content:e,editable:!1});b.useEffect(()=>{n==null||n.commands.setContent(e)},[e,n]);const r=b.useMemo(()=>x.defaultsDeep({},{content:Rr},t),[t]);return i(J.RichTextEditor,{editor:n,styles:r,children:i(J.RichTextEditor.Content,{})})};function Uy(e,t){const n={};return e.forEach(r=>{const{name:a,data_field:o,aggregation:l}=r,u=Tn(t,o,l);n[a]=tt(r,u)}),n}function Xy(e){const t=document.createElement("span");return t.innerHTML=e,t.innerText}function Jy(e,t,n){try{return new Function("payload",`
312
247
  const filters = payload.filters;
313
248
  const context = payload.context;
314
- ${Object.entries(e).map(([r,a])=>`const ${r} = '${a}';`).join(`
249
+ ${Object.entries(t).map(([r,a])=>`const ${r} = '${a}';`).join(`
315
250
  `)}
316
- return ${t};
317
- `)(n)}catch(r){return console.error(r),console.log(t),t}}function Gy(t,e,n,r){const a=Ny(e,r),o=/^(.+)\}\}(.*)$/;return t.split("{{").map(l=>{const u=o.exec(l);if(!u)return l;const c=a[u[1]];if(c){const f=u[2]??"";return`${c}${f}`}const d=qy(u[1]);return`${Fy(d,a,n)}${u[2]}`}).join("")}const Wy=k.observer(({context:t})=>{const e=K(),{value:n}=W(t.instanceData,"config"),{variables:r,data:a}=t,o=y.useMemo(()=>{const l=x.defaults({},n,On);return l.content?Gy(l.content,r,e.payloadForViz,a):""},[n,r,e.payloadForViz]);return o?i(Kn,{value:o,styles:{root:{border:"none",height:"100%"},content:{padding:0}}}):null});function jy(){const{editor:t}=J.useRichTextEditorContext();return i(J.RichTextEditor.Control,{onClick:()=>t==null?void 0:t.commands.insertTable({rows:3,cols:3,withHeaderRow:!0}),"aria-label":"Insert table",title:"Insert table",children:i(L.IconBorderAll,{stroke:1.5,size:16})})}const ii=y.forwardRef(({value:t,onChange:e,styles:n={},label:r,onSubmit:a},o)=>{const[l,u]=y.useState(t),c=Ba.useEditor({extensions:[Va,Pa,J.Link,Ia,Ma,Ta,za.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),Oa,La,$a,Ea.configure({types:["heading","paragraph"]}),Da.configure({placeholder:"This is placeholder"}),Aa,ka.Color,Mo],content:l,onUpdate:({editor:g})=>{u(g.getHTML())}});y.useEffect(()=>{u(t),c==null||c.commands.setContent(t)},[t]);const d=()=>{e(l),a==null||a()},f=t!==l,h=y.useMemo(()=>x.defaultsDeep({},{content:Gr},n),[n]);return c?p(s.Stack,{spacing:4,sx:{flexGrow:1,position:"relative"},children:[p(s.Group,{align:"center",children:[i(s.Text,{size:14,fw:500,children:r}),i(s.ActionIcon,{color:"blue",disabled:!f,onClick:d,children:i(L.IconDeviceFloppy,{size:18})})]}),p(J.RichTextEditor,{editor:c,styles:h,children:[p(J.RichTextEditor.Toolbar,{sticky:!0,stickyOffset:0,children:[i(J.RichTextEditor.ControlsGroup,{children:i(J.RichTextEditor.ColorPicker,{colors:["#25262b","#868e96","#fa5252","#e64980","#be4bdb","#7950f2","#4c6ef5","#228be6","#15aabf","#12b886","#40c057","#82c91e","#fab005","#fd7e14"],popoverProps:{zIndex:320}})}),p(J.RichTextEditor.ControlsGroup,{children:[i(J.RichTextEditor.Bold,{}),i(J.RichTextEditor.Italic,{}),i(J.RichTextEditor.Underline,{}),i(J.RichTextEditor.ClearFormatting,{}),i(J.RichTextEditor.Highlight,{}),i(J.RichTextEditor.Code,{})]}),p(J.RichTextEditor.ControlsGroup,{children:[i(J.RichTextEditor.H1,{}),i(J.RichTextEditor.H2,{}),i(J.RichTextEditor.H3,{}),i(J.RichTextEditor.H4,{})]}),p(J.RichTextEditor.ControlsGroup,{children:[i(J.RichTextEditor.Blockquote,{}),i(J.RichTextEditor.Hr,{}),i(J.RichTextEditor.BulletList,{}),i(J.RichTextEditor.OrderedList,{}),i(J.RichTextEditor.Subscript,{}),i(J.RichTextEditor.Superscript,{})]}),p(J.RichTextEditor.ControlsGroup,{children:[i(J.RichTextEditor.Link,{}),i(J.RichTextEditor.Unlink,{})]}),p(J.RichTextEditor.ControlsGroup,{children:[i(J.RichTextEditor.AlignLeft,{}),i(J.RichTextEditor.AlignCenter,{}),i(J.RichTextEditor.AlignJustify,{}),i(J.RichTextEditor.AlignRight,{})]}),i(J.RichTextEditor.ControlsGroup,{children:i(jy,{})}),i(Vy,{editor:c})]}),i(J.RichTextEditor.Content,{})]})]}):null});function Ry({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaults({},e,On),[e]),{control:a,handleSubmit:o,watch:l,reset:u}=v.useForm({defaultValues:r});l("content"),y.useEffect(()=>{u(r)},[r]);const c=y.useRef(null),d=()=>{var f;return(f=c.current)==null?void 0:f.click()};return i("form",{onSubmit:o(n),style:{flexGrow:1,display:"flex",flexDirection:"column"},children:p(s.Stack,{spacing:"xs",sx:{flexGrow:1},children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",display:"none"},children:[i(s.Text,{children:"Content"}),i(s.ActionIcon,{ref:c,type:"submit",mr:5,variant:"filled",color:"blue",children:i(D.DeviceFloppy,{size:20})})]}),i(v.Controller,{name:"content",control:a,render:({field:f})=>i(ii,{...f,styles:{root:{flexGrow:1}},label:"Content",onSubmit:d})})]})})}class Yy extends ve{constructor(){super(...arguments);N(this,"VERSION",1)}fixMalformedConfig(n){return x.defaults({},n,On)}configVersions(){this.version(1,n=>({version:1,config:this.fixMalformedConfig(n)}))}}const Qy={displayName:"Rich Text",displayGroup:"Others",migrator:new Yy,name:"richText",viewRender:Wy,configRender:Ry,createConfig(){return{version:1,config:x.cloneDeep(On)}}},an={static:{type:"static",color:st.random().css()},dynamic:{type:"dynamic",func_content:["function getColor({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here",' // return "blue"',"}"].join(`
318
- `)}},Io={id:"builtin:echarts:click-scatter-chart:series",displayName:"Click Scatter",nameRender:Uy,configRender:Ky,payload:[{name:"seriesType",description:"'scatter'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function Ky(t){return i(V,{})}function Uy(t){return i(s.Text,{children:"Click scatter"})}const Eo={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
319
- `)},Ao={label:Ze.on_axis,tooltip:Ze.in_tooltip},ai={scatter:{y_data_key:"",name_data_key:"",symbolSize:{type:"static",size:10},color:an.static,label_position:"right",label_overflow:Ao},stats:{templates:{top:"",bottom:""}},x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...Eo}}},y_axes:[{name:"Y Axis",position:"left",nameAlignment:"center",label_formatter:$e,min:"",max:"",show:!0}],tooltip:{trigger:"item",metrics:[]},reference_lines:[],reference_areas:[],dataZoom:Bt};function Xy(t,e){if(!t.x_axis.data_key)return[];const n=q(t.x_axis.data_key);return[{source:e[n.queryID]}]}function Jy(t){const e=t.y_axes.some(a=>!!a.name);let n=15;e&&(n+=20),t.dataZoom.x_axis_slider&&(n+=20);let r=5;return t.x_axis.name&&(r+=15),{top:n,bottom:r}}function Zy(){return{show:!1,bottom:0,left:"center",type:"scroll"}}function Un(t,e){if(t)return e[t]??void 0}function Hy({reference_areas:t,variableValueMap:e}){const n=t.map(r=>[{name:r.content.text,value:r.content.text,itemStyle:r.itemStyle,label:r.label,xAxis:Un(r.leftBottomPoint.x_data_key,e),yAxis:Un(r.leftBottomPoint.y_data_key,e)},{xAxis:Un(r.rightTopPoint.x_data_key,e),yAxis:Un(r.rightTopPoint.y_data_key,e)}]);return{type:"scatter",name:"ref_areas",silent:!0,data:[],markArea:{data:n}}}function eb({type:t,...e},n){if(!t)return 10;if(t==="static"){const{size:a}=e;return a}const{func_content:r}=e;return(a,o)=>{const l=o.data;try{return new Function(`return ${r}`)()({rowData:l,params:o,variables:n},{lodash:x,interpolate:_t.interpolate})}catch(u){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${u.message}`),10}}}function tb({type:t,...e},n){if(!t)return an.static.color;if(t==="static"){const{color:a}=e;return a}const{func_content:r}=e;return({value:a})=>{try{return new Function(`return ${r}`)()({rowData:a,variables:n},{lodash:x,interpolate:_t.interpolate})}catch(o){return console.error(`[getSeriesColor] failed parsing custom function, error: ${o.message}`),10}}}function nb(t,e,n,r){return t.map(a=>{const o=a.orientation==="horizontal",l=o?"yAxis":"xAxis",u=o?"insideEndTop":"end";return{name:a.name,type:"line",hide_in_legend:!a.show_in_legend,yAxisIndex:a.yAxisIndex,data:[],lineStyle:a.lineStyle,markLine:{data:[{name:a.name,[l]:Number(n[a.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:a.lineStyle,label:{formatter:function(){return a.template?Tn(a.template,e,r):""},position:u}}}})}function rb({x_axis:t,scatter:e},n){const r=q(t.data_key),a=q(e.y_data_key),o=q(e.name_data_key);return{label:{show:!!e.label_position,position:e.label_position,...ut(e.label_overflow.label),formatter:({value:l})=>l[o.columnKey]},type:"scatter",name:"",xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{color:tb(e.color,n)},symbolSize:eb(e.symbolSize,n),encode:{x:r.columnKey,y:a.columnKey}}}function ib(t,e,n,r){return[rb(t,r)].concat(nb(t.reference_lines,n,r,e)).concat(Hy({reference_areas:t.reference_areas,variableValueMap:r}))}function zo({enabled:t,func_content:e}){return(n,r)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function $o(t,e,n){const{x_axis:r}=n;return r.axisLabel.formatter.enabled?zo(r.axisLabel.formatter)(t,e):t}function ab(t,e){const{x_axis:n,tooltip:r}=e;if(r.trigger==="item"){const u=wn(t[0].data,n.data_key);return $o(u,0,e)}const a=t.find(u=>u.axisDim==="x"&&u.axisId==="main-x-axis");if(!a)return"";const{axisValue:o,axisIndex:l}=a;return $o(o,l,e)}const sb=t=>{try{return ee(t).format({trimMantissa:!0,mantissa:2})}catch{return t}};function ob(t,e){const{scatter:n,tooltip:r}=t;return{confine:!0,trigger:r.trigger,formatter:function(a){const o=e[0]??e.default,l=Array.isArray(a)?a:[a];if(l.length===0)return"";const u=ab(l,t),c=mt(t.scatter.label_overflow.tooltip),d=l.map(({value:m})=>`
251
+ return ${e};
252
+ `)(n)}catch(r){return console.error(r),console.log(e),e}}function Zy(e,t,n,r){const a=Uy(t,r),o=/^(.+)\}\}(.*)$/;return e.split("{{").map(l=>{const u=o.exec(l);if(!u)return l;const c=a[u[1]];if(c){const f=u[2]??"";return`${c}${f}`}const d=Xy(u[1]);return`${Jy(d,a,n)}${u[2]}`}).join("")}const Hy=k.observer(({context:e})=>{const t=Me(),{value:n}=W(e.instanceData,"config"),{variables:r,data:a}=e,o=b.useMemo(()=>{const l=x.defaults({},n,Pn);return l.content?Zy(l.content,r,t.payloadForViz,a):""},[n,r,t.payloadForViz]);return o?i(Un,{value:o,styles:{root:{border:"none",height:"100%"},content:{padding:0}}}):null});function eb(){const{editor:e}=J.useRichTextEditorContext();return i(J.RichTextEditor.Control,{onClick:()=>e==null?void 0:e.commands.insertTable({rows:3,cols:3,withHeaderRow:!0}),"aria-label":"Insert table",title:"Insert table",children:i(L.IconBorderAll,{stroke:1.5,size:16})})}const si=b.forwardRef(({value:e,onChange:t,styles:n={},label:r,onSubmit:a},o)=>{const[l,u]=b.useState(e),c=qa.useEditor({extensions:[Fa,Na,J.Link,za,Aa,Ia,Oa.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),Va,Ba,Pa,$a.configure({types:["heading","paragraph"]}),Ea.configure({placeholder:"This is placeholder"}),La,Ma.Color,co],content:l,onUpdate:({editor:g})=>{u(g.getHTML())}});b.useEffect(()=>{u(e),c==null||c.commands.setContent(e)},[e]);const d=()=>{t(l),a==null||a()},f=e!==l,h=b.useMemo(()=>x.defaultsDeep({},{content:Rr},n),[n]);return c?p(s.Stack,{spacing:4,sx:{flexGrow:1,position:"relative"},children:[p(s.Group,{align:"center",children:[i(s.Text,{size:14,fw:500,children:r}),i(s.ActionIcon,{color:"blue",disabled:!f,onClick:d,children:i(L.IconDeviceFloppy,{size:18})})]}),p(J.RichTextEditor,{editor:c,styles:h,children:[p(J.RichTextEditor.Toolbar,{sticky:!0,stickyOffset:0,children:[i(J.RichTextEditor.ControlsGroup,{children:i(J.RichTextEditor.ColorPicker,{colors:["#25262b","#868e96","#fa5252","#e64980","#be4bdb","#7950f2","#4c6ef5","#228be6","#15aabf","#12b886","#40c057","#82c91e","#fab005","#fd7e14"],popoverProps:{zIndex:320}})}),p(J.RichTextEditor.ControlsGroup,{children:[i(J.RichTextEditor.Bold,{}),i(J.RichTextEditor.Italic,{}),i(J.RichTextEditor.Underline,{}),i(J.RichTextEditor.ClearFormatting,{}),i(J.RichTextEditor.Highlight,{}),i(J.RichTextEditor.Code,{})]}),p(J.RichTextEditor.ControlsGroup,{children:[i(J.RichTextEditor.H1,{}),i(J.RichTextEditor.H2,{}),i(J.RichTextEditor.H3,{}),i(J.RichTextEditor.H4,{})]}),p(J.RichTextEditor.ControlsGroup,{children:[i(J.RichTextEditor.Blockquote,{}),i(J.RichTextEditor.Hr,{}),i(J.RichTextEditor.BulletList,{}),i(J.RichTextEditor.OrderedList,{}),i(J.RichTextEditor.Subscript,{}),i(J.RichTextEditor.Superscript,{})]}),p(J.RichTextEditor.ControlsGroup,{children:[i(J.RichTextEditor.Link,{}),i(J.RichTextEditor.Unlink,{})]}),p(J.RichTextEditor.ControlsGroup,{children:[i(J.RichTextEditor.AlignLeft,{}),i(J.RichTextEditor.AlignCenter,{}),i(J.RichTextEditor.AlignJustify,{}),i(J.RichTextEditor.AlignRight,{})]}),i(J.RichTextEditor.ControlsGroup,{children:i(eb,{})}),i(Ky,{editor:c})]}),i(J.RichTextEditor.Content,{})]})]}):null});function tb({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),r=b.useMemo(()=>x.defaults({},t,Pn),[t]),{control:a,handleSubmit:o,watch:l,reset:u}=v.useForm({defaultValues:r});l("content"),b.useEffect(()=>{u(r)},[r]);const c=b.useRef(null),d=()=>{var f;return(f=c.current)==null?void 0:f.click()};return i("form",{onSubmit:o(n),style:{flexGrow:1,display:"flex",flexDirection:"column"},children:p(s.Stack,{spacing:"xs",sx:{flexGrow:1},children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",display:"none"},children:[i(s.Text,{children:"Content"}),i(s.ActionIcon,{ref:c,type:"submit",mr:5,variant:"filled",color:"blue",children:i(T.DeviceFloppy,{size:20})})]}),i(v.Controller,{name:"content",control:a,render:({field:f})=>i(si,{...f,styles:{root:{flexGrow:1}},label:"Content",onSubmit:d})})]})})}class nb extends be{constructor(){super(...arguments);N(this,"VERSION",1)}fixMalformedConfig(n){return x.defaults({},n,Pn)}configVersions(){this.version(1,n=>({version:1,config:this.fixMalformedConfig(n)}))}}const rb={displayName:"Rich Text",displayGroup:"Others",migrator:new nb,name:"richText",viewRender:Hy,configRender:tb,createConfig(){return{version:1,config:x.cloneDeep(Pn)}}},sn={static:{type:"static",color:ot.random().css()},dynamic:{type:"dynamic",func_content:["function getColor({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here",' // return "blue"',"}"].join(`
253
+ `)}},po={id:"builtin:echarts:click-scatter-chart:series",displayName:"Click Scatter",nameRender:ab,configRender:ib,payload:[{name:"seriesType",description:"'scatter'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function ib(e){return i(V,{})}function ab(e){return i(s.Text,{children:"Click scatter"})}const ho={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
254
+ `)},fo={label:Ze.on_axis,tooltip:Ze.in_tooltip},oi={scatter:{y_data_key:"",name_data_key:"",symbolSize:{type:"static",size:10},color:sn.static,label_position:"right",label_overflow:fo},stats:{templates:{top:"",bottom:""}},x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...ho}}},y_axes:[{name:"Y Axis",position:"left",nameAlignment:"center",label_formatter:$e,min:"",max:"",show:!0}],tooltip:{trigger:"item",metrics:[]},reference_lines:[],reference_areas:[],dataZoom:Vt};function sb(e,t){if(!e.x_axis.data_key)return[];const n=q(e.x_axis.data_key);return[{source:t[n.queryID]}]}function ob(e){const t=e.y_axes.some(a=>!!a.name);let n=15;t&&(n+=20),e.dataZoom.x_axis_slider&&(n+=20);let r=5;return e.x_axis.name&&(r+=15),{top:n,bottom:r}}function lb(){return{show:!1,bottom:0,left:"center",type:"scroll"}}function Xn(e,t){if(e)return t[e]??void 0}function ub({reference_areas:e,variableValueMap:t}){const n=e.map(r=>[{name:r.content.text,value:r.content.text,itemStyle:r.itemStyle,label:r.label,xAxis:Xn(r.leftBottomPoint.x_data_key,t),yAxis:Xn(r.leftBottomPoint.y_data_key,t)},{xAxis:Xn(r.rightTopPoint.x_data_key,t),yAxis:Xn(r.rightTopPoint.y_data_key,t)}]);return{type:"scatter",name:"ref_areas",silent:!0,data:[],markArea:{data:n}}}function cb({type:e,...t},n){if(!e)return 10;if(e==="static"){const{size:a}=t;return a}const{func_content:r}=t;return(a,o)=>{const l=o.data;try{return new Function(`return ${r}`)()({rowData:l,params:o,variables:n},{lodash:x,interpolate:kt.interpolate})}catch(u){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${u.message}`),10}}}function db({type:e,...t},n){if(!e)return sn.static.color;if(e==="static"){const{color:a}=t;return a}const{func_content:r}=t;return({value:a})=>{try{return new Function(`return ${r}`)()({rowData:a,variables:n},{lodash:x,interpolate:kt.interpolate})}catch(o){return console.error(`[getSeriesColor] failed parsing custom function, error: ${o.message}`),10}}}function pb(e,t,n,r){return e.map(a=>{const o=a.orientation==="horizontal",l=o?"yAxis":"xAxis",u=o?"insideEndTop":"end";return{name:a.name,type:"line",hide_in_legend:!a.show_in_legend,yAxisIndex:a.yAxisIndex,data:[],lineStyle:a.lineStyle,markLine:{data:[{name:a.name,[l]:Number(n[a.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:a.lineStyle,label:{formatter:function(){return a.template?Dn(a.template,t,r):""},position:u}}}})}function hb({x_axis:e,scatter:t},n){const r=q(e.data_key),a=q(t.y_data_key),o=q(t.name_data_key);return{label:{show:!!t.label_position,position:t.label_position,...ct(t.label_overflow.label),formatter:({value:l})=>l[o.columnKey]},type:"scatter",name:"",xAxisId:"main-x-axis",yAxisIndex:0,datasetIndex:0,itemStyle:{color:db(t.color,n)},symbolSize:cb(t.symbolSize,n),encode:{x:r.columnKey,y:a.columnKey}}}function fb(e,t,n,r){return[hb(e,r)].concat(pb(e.reference_lines,n,r,t)).concat(ub({reference_areas:e.reference_areas,variableValueMap:r}))}function go({enabled:e,func_content:t}){return(n,r)=>{if(!e)return n;try{return new Function(`return ${t}`)()(n,r)}catch(a){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${a.message}`),n}}}function mo(e,t,n){const{x_axis:r}=n;return r.axisLabel.formatter.enabled?go(r.axisLabel.formatter)(e,t):e}function gb(e,t){const{x_axis:n,tooltip:r}=t;if(r.trigger==="item"){const u=xn(e[0].data,n.data_key);return mo(u,0,t)}const a=e.find(u=>u.axisDim==="x"&&u.axisId==="main-x-axis");if(!a)return"";const{axisValue:o,axisIndex:l}=a;return mo(o,l,t)}const mb=e=>{try{return H(e).format({trimMantissa:!0,mantissa:2})}catch{return e}};function yb(e,t){const{scatter:n,tooltip:r}=e;return{confine:!0,trigger:r.trigger,formatter:function(a){const o=t[0]??t.default,l=Array.isArray(a)?a:[a];if(l.length===0)return"";const u=gb(l,e),c=yt(e.scatter.label_overflow.tooltip),d=l.map(({value:m})=>`
320
255
  <th style="text-align: right; padding-right: 1em">
321
- <div style="${c}">${wn(m,n.name_data_key)}</div>
256
+ <div style="${c}">${xn(m,n.name_data_key)}</div>
322
257
  </th>
323
258
  `);d.unshift("<th></th>");const f=[`<tr>
324
- <th style="text-align: right;">${t.x_axis.name}</th>
259
+ <th style="text-align: right;">${e.x_axis.name}</th>
325
260
  ${l.map(m=>`<td style="text-align: right; padding: 0 1em;">${u}</td>`).join("")}
326
261
  </tr>`,`<tr>
327
- <th style="text-align: right;">${t.y_axes[0].name}</th>
262
+ <th style="text-align: right;">${e.y_axes[0].name}</th>
328
263
  ${l.map(({value:m})=>`
329
264
  <td style="text-align: right; padding: 0 1em;">
330
- ${o(wn(m,n.y_data_key))}
265
+ ${o(xn(m,n.y_data_key))}
331
266
  </td>`).join("")}
332
- </tr>`],h=t.tooltip.metrics.map(m=>`<tr>
267
+ </tr>`],h=e.tooltip.metrics.map(m=>`<tr>
333
268
  <th style="text-align: right;">${m.name}</th>
334
- ${l.map(({value:w})=>`<td style="text-align: right; padding: 0 1em;">${sb(wn(w,m.data_key))}</td>`).join("")}
269
+ ${l.map(({value:C})=>`<td style="text-align: right; padding: 0 1em;">${mb(xn(C,m.data_key))}</td>`).join("")}
335
270
  </tr>`);return f.push(...h),`
336
271
  <table style="width: auto">
337
272
  <thead><tr>${d.join("")}</tr></thead>
338
273
  <tbody>${f.join("")}</tbody>
339
274
  </table>
340
- `}}}function lb(t,e){const n=e.every(a=>!Number.isNaN(Number(a))),{axisLabel:r}=t.x_axis;return[{data:e,name:t.x_axis.name??"",id:"main-x-axis",axisTick:{show:!0,alignWithLabel:!0},type:n?"value":"category",axisLabel:{...r,formatter:zo(r.formatter)}}]}function ub(t,e){return t.y_axes.map(({nameAlignment:n,min:r,max:a,...o},l)=>{let u=o.position;return u||(u=l>0?"right":"left"),{...o,min:r||void 0,max:a||void 0,position:u,axisLabel:{show:!0,formatter:e[l]??e.default},axisLine:{show:!0},nameTextStyle:{fontWeight:"bold",align:n},nameLocation:"end",nameGap:15,splitLine:{show:!1}}})}const cb={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}],grid:{top:10,left:20,right:15,bottom:25,containLabel:!0}};function db(t,e,n){const r=n.reduce((c,d)=>{const f=yt(d,e);return c[d.name]=et(d,f),c},{}),a=t.y_axes.reduce((c,{label_formatter:d},f)=>(c[f]=function(g){let m=g;if(typeof g=="object"&&(Array.isArray(g.value)&&g.value.length===2?m=g.value[1]:m=g.value),!d)return m;try{return ee(m).format(d)}catch(w){return console.error(w),m}},c),{default:({value:c})=>c}),o=x.uniq(lt(e,t.x_axis.data_key)),l=ib(t,e,n,r),u={xAxis:lb(t,o),yAxis:ub(t,a),series:l,dataset:Xy(t,e),tooltip:ob(t,a),grid:Jy(t),legend:Zy(),dataZoom:Ar(t.dataZoom)};return x.defaultsDeep({},u,cb)}le.use([G.DataZoomComponent,pe.BarChart,pe.LineChart,pe.ScatterChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer,G.MarkLineComponent,G.MarkAreaComponent]);function Lo(t){return t.trim().length>0}function pb({conf:t,data:e,width:n,height:r,interactionManager:a,variables:o}){const l=bt(e,t.x_axis.data_key),u=He(a.triggerManager,Io.id),c=y.useCallback(h=>{const g=h.data;u.forEach(m=>{a.runInteraction(m.id,{...h,rowData:g})})},[l,u,a]),d=y.useMemo(()=>({click:c}),[c]),f=y.useMemo(()=>db(t,e,o),[t,e]);return i(Ne,{echarts:le,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function hb({context:t,instance:e}){const n=tt({vizManager:t.vizManager,instance:e}),{value:r}=W(t.instanceData,"config"),{variables:a}=t,o=y.useMemo(()=>x.defaults({},r,ai),[r]),l=t.data,{width:u,height:c}=t.viewport,{ref:d,height:f}=Me.useElementSize(),{ref:h,height:g}=Me.useElementSize(),m=y.useMemo(()=>{const{stats:{templates:C}}=o;return{top:Jt(C.top,a,l),bottom:Jt(C.bottom,a,l)}},[o,l]),w=Math.max(0,c-f-g);return!u||!c?null:p(s.Box,{children:[i(s.Text,{ref:d,align:"left",size:"xs",pl:"sm",sx:{display:Lo(o.stats.templates.top)?"block":"none"},children:Object.values(m.top).map(C=>C)}),i(pb,{variables:a,width:u,height:w,data:l,conf:o,interactionManager:n}),i(s.Text,{ref:h,align:"left",size:"xs",pl:"sm",sx:{display:Lo(o.stats.templates.bottom)?"block":"none"},children:Object.values(m.bottom).map(C=>C)})]})}const fb=y.forwardRef(({value:t,onChange:e,xAxisOptions:n,yAxisOptions:r,variableOptions:a},o)=>{const l=(u,c)=>{const d=x.cloneDeep(t);x.set(d,u,c),e(d)};return p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Content",labelPosition:"right"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.TextInput,{label:"Content Text",value:t.content.text,onChange:u=>l("content.text",u.currentTarget.value)}),i(Pr,{label:"Text Position",value:t.label.position,onChange:u=>l("label.position",u)})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Endpoints",labelPosition:"right"}),p(s.Group,{grow:!0,noWrap:!0,children:[n&&i(s.Select,{label:"X Axis",data:n,value:t.xAxisIndex,onChange:u=>l("xAxisIndex",u)}),r&&i(s.Select,{label:"Y Axis",data:r,value:t.yAxisIndex,onChange:u=>l("xAxisIndex",u)})]}),p(s.Stack,{spacing:0,children:[i(s.Text,{size:14,color:"#212529",fw:500,children:"Left-Bottom Point"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.Select,{icon:i(s.Text,{children:"x"}),data:a,value:t.leftBottomPoint.x_data_key,onChange:u=>l("leftBottomPoint.x_data_key",u??""),clearable:!0}),i(s.Select,{icon:i(s.Text,{children:"y"}),data:a,value:t.leftBottomPoint.y_data_key,onChange:u=>l("leftBottomPoint.y_data_key",u??""),clearable:!0})]})]}),p(s.Stack,{spacing:0,children:[i(s.Text,{size:14,color:"#212529",fw:500,children:"Right-Top Point"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.Select,{icon:i(s.Text,{children:"x"}),data:a,value:t.rightTopPoint.x_data_key,onChange:u=>l("rightTopPoint.x_data_key",u??""),clearable:!0}),i(s.Select,{icon:i(s.Text,{children:"y"}),data:a,value:t.rightTopPoint.y_data_key,onChange:u=>l("rightTopPoint.y_data_key",u??""),clearable:!0})]})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Style",labelPosition:"right"}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:14,children:"Background Color"}),i(Pe,{value:t.itemStyle.color,onChange:u=>l("itemStyle.color",u)})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:14,children:"Text Color"}),i(Pe,{value:t.label.color,onChange:u=>l("label.color",u)})]})]})});function gb(){const t=new Date().getTime().toString();return{id:t,content:{text:t},itemStyle:{color:"rgba(0,0,0,0.05)"},label:{position:"inside",color:"rgba(0,0,0,0.5)"},leftBottomPoint:{x_data_key:"",y_data_key:""},rightTopPoint:{x_data_key:"",y_data_key:""},xAxisIndex:"0",yAxisIndex:"0"}}function mb({control:t,watch:e,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_areas"}),l=e("reference_areas"),u=r.map((g,m)=>({...g,...l[m]})),c=()=>{const g=gb();a(g)},d=y.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=e("y_axes"),h=y.useMemo(()=>f.map(({name:g},m)=>({label:g,value:m.toString()})),[f]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((g,m)=>i(s.Tabs.Tab,{value:m.toString(),children:m+1},m)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),u.map((g,m)=>i(s.Tabs.Panel,{value:m.toString(),children:i(v.Controller,{name:`reference_areas.${m}`,control:t,render:({field:w})=>p(s.Stack,{children:[i(fb,{variableOptions:d,yAxisOptions:h,...w}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(L.IconTrash,{size:16}),color:"red",variant:"light",onClick:()=>o(m),children:"Delete this Reference Area"})]})})},m))]})}const yb=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],bb=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function vb({control:t,index:e,remove:n,watch:r,variableOptions:a,yAxisOptions:o}){const l=r(`reference_lines.${e}.orientation`);return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${e}.name`,control:t,render:({field:u})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),i(v.Controller,{name:`reference_lines.${e}.variable_key`,control:t,render:({field:u})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),i(v.Controller,{name:`reference_lines.${e}.template`,control:t,render:({field:u})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),p(s.Group,{grow:!0,children:[p(s.Stack,{children:[i(v.Controller,{name:`reference_lines.${e}.orientation`,control:t,render:({field:u})=>i(s.Select,{label:"Orientation",data:bb,required:!0,sx:{flex:1},...u})}),l==="vertical"&&i(s.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&i(v.Controller,{name:`reference_lines.${e}.yAxisIndex`,control:t,render:({field:{value:u,onChange:c,...d}})=>i(s.Select,{label:"Y Axis",data:o,disabled:o.length===0,...d,value:(u==null?void 0:u.toString())??"",onChange:f=>{if(!f){c(0);return}c(Number(f))},sx:{flex:1}})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`reference_lines.${e}.lineStyle.type`,control:t,render:({field:u})=>i(s.Select,{label:"Line Type",data:yb,sx:{flexGrow:1},...u})}),i(v.Controller,{name:`reference_lines.${e}.lineStyle.width`,control:t,render:({field:u})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`reference_lines.${e}.lineStyle.color`,control:t,render:({field:u})=>i(Pe,{...u})})]}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Reference Line"})]},e)}function xb({control:t,watch:e,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_lines"}),l=e("reference_lines"),u=r.map((g,m)=>({...g,...l[m]})),c=()=>{const g={name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:st.random().css()},show_in_legend:!1,yAxisIndex:0};a(g)},d=y.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=e("y_axes"),h=y.useMemo(()=>f.map(({name:g},m)=>({label:g,value:m.toString()})),[f]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((g,m)=>i(s.Tabs.Tab,{value:m.toString(),children:m+1},m)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),u.map((g,m)=>i(s.Tabs.Panel,{value:m.toString(),children:i(vb,{control:t,index:m,remove:o,watch:e,variableOptions:d,yAxisOptions:h})},m))]})}const wb=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return i(s.Box,{children:i(Ie,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Cb=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:a}]=X.useBoolean(),[o,l]=y.useState(t),u=()=>{a();const{type:h,func_content:g}=o,m={type:h,func_content:g};l(m),e(m)},c=()=>{a(),l(t)},d=h=>{l(g=>({...g,func_content:h}))},f=()=>{d(an.dynamic.func_content)};return p(V,{children:[i(s.Box,{sx:{width:"50%"},children:i(s.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),i(s.Modal,{size:800,title:"Setup dynamic color",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),i(wb,{value:o.func_content,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},Sb=({value:t,onChange:e})=>t.type!=="dynamic"?null:i(Cb,{value:t,onChange:e}),_b=({value:t,onChange:e})=>{if(t.type!=="static")return null;const n=r=>{e({...t,color:r})};return i(s.ColorInput,{label:" ",format:"rgb",value:t.color,onChange:n})},kb=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Tb=y.forwardRef(({label:t="Color",value:e,onChange:n},r)=>{const a=o=>{n({...an[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:t,data:kb,value:e.type,onChange:a,sx:{flexGrow:1}}),i(_b,{value:e,onChange:n}),i(Sb,{value:e,onChange:n})]})}),Db=y.forwardRef(({value:t,onChange:e},n)=>{const r=o=>{e({...t,label:o})},a=o=>{e({...t,tooltip:o})};return p(s.Stack,{ref:n,spacing:0,children:[i(Cn,{sectionTitle:"Overflow on Chart",value:t.label,onChange:r}),i(Cn,{sectionTitle:"Overflow in Tooltip",value:t.tooltip,onChange:a})]})}),Mb=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return i(s.Box,{children:i(Ie,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Oo={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
341
- `)}},Ib=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:a}]=X.useBoolean(),[o,l]=y.useState(t),u=()=>{a();const{type:h,func_content:g}=o,m={type:h,func_content:g};l(m),e(m)},c=()=>{a(),l(t)},d=h=>{l(g=>({...g,func_content:h}))},f=()=>{d(Oo.dynamic.func_content)};return p(V,{children:[i(s.Box,{sx:{width:"50%"},children:i(s.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),i(s.Modal,{size:800,title:"Setup dynamic size",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),i(Mb,{value:o.func_content,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},Eb=({value:t,onChange:e})=>t.type!=="dynamic"?null:i(Ib,{value:t,onChange:e}),Ab=({value:t,onChange:e})=>{if(t.type!=="static")return null;const n=r=>{e({...t,size:r})};return i(V,{children:i(s.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:t.size,onChange:n})})},zb=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],$b=y.forwardRef(({label:t="Size",value:e,onChange:n},r)=>{const a=o=>{n({...Oo[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:t,data:zb,value:e.type,onChange:a,sx:{flexGrow:1}}),i(Ab,{value:e,onChange:n}),i(Eb,{value:e,onChange:n})]})}),Lb=[{label:"off",value:""},{label:"top",value:"top"},{label:"left",value:"left"},{label:"right",value:"right"},{label:"bottom",value:"bottom"},{label:"inside",value:"inside"},{label:"insideLeft",value:"insideLeft"},{label:"insideRight",value:"insideRight"},{label:"insideTop",value:"insideTop"},{label:"insideBottom",value:"insideBottom"},{label:"insideTopLeft",value:"insideTopLeft"},{label:"insideBottomLeft",value:"insideBottomLeft"},{label:"insideTopRight",value:"insideTopRight"},{label:"insideBottomRight",value:"insideBottomRight"}];function Ob({control:t,watch:e}){return e(["scatter"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"scatter.name_data_key",control:t,render:({field:n})=>i(j,{label:"Name Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"scatter.y_data_key",control:t,render:({field:n})=>i(j,{label:"Value Data Field",required:!0,sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Style",labelPosition:"center"}),i(v.Controller,{name:"scatter.symbolSize",control:t,render:({field:n})=>i($b,{label:"Size",...n})}),i(v.Controller,{name:"scatter.color",control:t,render:({field:n})=>i(Tb,{...n})}),i(s.Divider,{mb:-15,label:"Label",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"scatter.label_position",control:t,render:({field:n})=>i(s.Select,{label:"Label Position",data:Lb,...n})})}),i(v.Controller,{name:"scatter.label_overflow",control:t,render:({field:n})=>i(Db,{...n})})]})}function Pb({control:t,watch:e}){return e("stats"),i(s.Stack,{children:p(s.Stack,{spacing:0,children:[i(v.Controller,{name:"stats.templates.top",control:t,render:({field:n})=>i(Xt,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),i(v.Controller,{name:"stats.templates.bottom",control:t,render:({field:n})=>i(Xt,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const Bb=({control:t,index:e,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,render:({field:r})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),Vb=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=e("tooltip.metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(V,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(D.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(Bb,{control:t,index:g,remove:a},h.id)},h.id))]})]})},Nb=[{label:"Scatter Point",value:"item"},{label:"X Axis",value:"axis"}];function qb({control:t,watch:e}){return e("tooltip.trigger"),p(s.Stack,{children:[i(v.Controller,{name:"tooltip.trigger",control:t,render:({field:n})=>i(s.Select,{label:"Trigger",data:Nb,sx:{flexGrow:1},...n})}),i(s.Divider,{variant:"dashed"}),i(Vb,{control:t,watch:e})]})}const Fb=({disabled:t,value:e,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[t&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Ie,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},Gb=y.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:a,setFalse:o}]=X.useBoolean(),[l,u]=y.useState(t);y.useEffect(()=>{u(t)},[t]);const c=m=>{u({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:w}=l,C={enabled:m,func_content:w};u(C),e(C)},f=()=>{o(),u(t)},h=m=>{u(w=>({...w,func_content:m}))},g=()=>{h(Eo.func_content)};return p(V,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Customize Label"}),i(s.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>c(m.currentTarget.checked)}),i(Fb,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})});function Wb({control:t,watch:e}){return e(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Gb,{...n})})]})]})}const jb=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],Rb=[{label:"left",value:"left"},{label:"right",value:"right"}];function Yb({control:t,index:e,remove:n}){return p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[i(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`y_axes.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`y_axes.${e}.nameAlignment`,control:t,render:({field:r})=>i(s.Select,{label:"Align",required:!0,data:jb,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`y_axes.${e}.position`,control:t,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:Rb,sx:{flex:1},...r})})}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:`y_axes.${e}.label_formatter`,control:t,render:({field:r})=>i(Re,{...r})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`y_axes.${e}.min`,control:t,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`y_axes.${e}.max`,control:t,render:({field:r})=>i(s.TextInput,{label:"Max",...r})})]})]}),i(s.Button,{mt:20,leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),disabled:e===0,children:"Delete this YAxis"})]})}function Qb({control:t,watch:e}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"y_axes"}),o=e("y_axes"),l=n.map((c,d)=>({...c,...o[d]})),u=()=>r({name:"",label_formatter:$e,min:"",max:"",show:!0,position:"right",nameAlignment:"right"});return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map((c,d)=>i(s.Tabs.Tab,{value:d.toString(),children:d+1},d)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(Yb,{control:t,index:d,remove:a})},d))]})}function Kb(t){return t||{templates:{top:"",bottom:""}}}function Ub({reference_lines:t=[],stats:e,...n}){return{reference_lines:t,stats:Kb(e),...n}}function Xb({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),{variables:r}=t,a=y.useMemo(()=>x.defaultsDeep({},e,ai),[e]),o=y.useMemo(()=>Ub(a),[a]);y.useEffect(()=>{!x.isEqual(a,o)&&(console.log("config malformed, resetting to defaults",a,o),n(o))},[a,o]);const{control:l,handleSubmit:u,watch:c,getValues:d,reset:f}=v.useForm({defaultValues:o});y.useEffect(()=>{f(o)},[o]);const h=d(),g=y.useMemo(()=>!x.isEqual(h,a),[h,a]);return c(["dataZoom"]),i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:u(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!g,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axes",children:"Y Axes"}),i(s.Tabs.Tab,{value:"Scatter",children:"Scatter"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),i(s.Tabs.Tab,{value:"Stats",children:"Stats"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),i(s.Tabs.Tab,{value:"Reference Areas",children:"Reference Areas"}),i(s.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(Wb,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Y Axes",children:i(Qb,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Scatter",children:i(Ob,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(qb,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Stats",children:i(Pb,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(xb,{variables:r,control:l,watch:c})}),i(s.Tabs.Panel,{value:"Reference Areas",children:i(mb,{variables:r,control:l,watch:c})}),i(s.Tabs.Panel,{value:"Zooming",children:i(v.Controller,{name:"dataZoom",control:l,render:({field:m})=>i($r,{...m})})})]})]})})}function Jb(t){const{dataZoom:e=Bt,...n}=t;return{...n,dataZoom:e}}function Zb(t){const e={scatter:{label_overflow:Ao}};return x.defaultsDeep(e,t)}function Hb(t){const{color:e}=t.scatter;return typeof e=="string"?{...t,scatter:{...t.scatter,color:{...an.static,color:e}}}:t}function ev(t){const e=t.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:st.random().css()},show_in_legend:a=!1,yAxisIndex:o=0}=n;return{...n,lineStyle:r,show_in_legend:a,yAxisIndex:o}});return{...t,reference_lines:e}}function tv(t){const e={tooltip:{trigger:"item"}};return x.defaultsDeep({},t,e)}function nv(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,scatter:o,tooltip:l,...u}=t;return{...u,x_axis:{...a,data_key:r(a.data_key)},scatter:{...o,y_data_key:r(o.y_data_key),name_data_key:r(o.name_data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:r(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}class rv extends ve{constructor(){super(...arguments);N(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{tooltip:r={metrics:[]},...a}=n.config;return{...n,version:2,config:{...a,tooltip:r}}}),this.version(3,n=>({...n,version:3,config:Jb(n.config)})),this.version(4,n=>{const{config:r}=n;return{...n,version:5,config:Zb(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:Hb(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:ev(r)}}),this.version(8,n=>{const{config:r}=n;return{...n,version:8,config:tv(r)}}),this.version(9,(n,r)=>{const{config:a}=n;return{...n,version:9,config:nv(a,r)}})}}const iv={displayName:"Scatter Chart",displayGroup:"ECharts-based charts",migrator:new rv,name:"scatterChart",viewRender:hb,configRender:Xb,createConfig(){return{version:9,config:x.cloneDeep(ai)}},triggers:[Io]},si={template:"The variable ${value} is defined in Variables section",vertical_align:"center",horizontal_align:"left"};function av(t){if("variables"in t)return t;const{align:e,size:n,weight:r,color:a,content:{prefix:o="",data_field:l="value",formatter:u={output:"number",mantissa:0},postfix:c=""}={}}=t;return{align:e,template:`${o} \${value} ${c}`,variables:[{name:"value",data_field:l,aggregation:{type:"none",config:{}},formatter:u,color:a,weight:r,size:n}]}}function sv(t){return x.omit(t,["variables"])}function ov(t){const{align:e,...n}=t;return{horizontal_align:e,vertical_align:"center",...n}}function lv(t){const e=x.cloneDeep(t),n=x.get(e,"color.valueRange");return n!==void 0&&x.set(e,"color.valueRange",n.map(r=>Number(r))),e}class uv extends ve{constructor(){super(...arguments);N(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:av(n)})),this.version(2,(n,{panelModel:r})=>{const{config:a}=n;return(a.variables||[]).forEach(l=>{r.variables.find(u=>u.name===l.name)||r.addVariable(lv(l))}),{...n,version:2,config:sv(a)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:ov(r)}})}}const cv={left:"flex-start",center:"center",right:"flex-end"},dv={top:"flex-start",center:"center",bottom:"flex-end"},pv=k.observer(({context:t})=>{const e=K(),{value:n=si}=W(t.instanceData,"config"),{variables:r}=t,{template:a,horizontal_align:o,vertical_align:l}=n,{width:u,height:c}=t.viewport,d=y.useMemo(()=>{try{return x.template(a)(e.payloadForSQL)}catch{return a}},[e.payloadForSQL,a]),f=y.useMemo(()=>Jt(d,r,t.data),[d,r,t.data,t]);return i(s.Center,{sx:{width:u,height:c,justifyContent:cv[o],alignItems:dv[l]},children:i(s.Box,{children:Object.values(f).map((h,g)=>i(y.Fragment,{children:h},g))})})}),hv=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],fv=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function gv({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,si),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l(["template","horizontal_align","vertical_align"]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,e),[d,e]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{weight:500,children:"Stats Configurations"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(D.DeviceFloppy,{size:20})})]}),i(v.Controller,{name:"template",control:a,render:({field:h})=>i(Xt,{label:"Template",py:"md",sx:{flexGrow:1},...h})}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{name:"horizontal_align",control:a,render:({field:h})=>i(s.Select,{label:"Horizontal Alignment",data:hv,...h})}),i(v.Controller,{control:a,name:"vertical_align",render:({field:h})=>i(s.Select,{label:"Vertical Alignment",data:fv,...h})})]})]})})}const mv={createConfig(){return{version:3,config:si}},displayName:"Stats",displayGroup:"Others",migrator:new uv,name:"stats",viewRender:pv,configRender:gv},oi={label_key:"",value_key:"",group_key:"",levels:[]};function yv(t){const e=new Set(t.map(r=>r.parent_id)),n=new Set(t.map(r=>r.id));return e.forEach(r=>{r===null||n.has(r)||t.push({id:r,name:r,parent_id:null})}),t}function bv(t){const e=yv(t).map(a=>({...a,children:[]})),n=x.keyBy(e,a=>a.id),r=[];return e.forEach(a=>{if(!a.parent_id||!n[a.parent_id]){r.push(a);return}n[a.parent_id].children.push(a)}),r}function vv(t,e){const{label_key:n,value_key:r,group_key:a}=t;if(!n||!r)return[];const o=q(n),l=q(r),u=q(a),c=e[o.queryID].map(d=>({...d,id:d[o.columnKey],parent_id:d[u.columnKey],name:d[o.columnKey],value:d[l.columnKey]?Number(d[l.columnKey]):d[l.columnKey]}));return a?bv(c):c}const xv=t=>({treePathInfo:e,name:n,value:r})=>{if(e.length===1||!t)return n;try{const a=e[e.length-2].value;if(r/a<t)return" "}catch{return n}};function wv(t){const{levels:e}=t;return e.map(n=>{const{show_label_tolerance:r,...a}=n.label;return{...n,label:{...a,formatter:xv(r)}}})}function Cv(){return({treePathInfo:t,name:e,value:n,color:r,marker:a,...o})=>{const l=t.slice(0,t.length-1),u=[`<tr>
275
+ `}}}function bb(e,t){const n=t.every(a=>!Number.isNaN(Number(a))),{axisLabel:r}=e.x_axis;return[{data:t,name:e.x_axis.name??"",id:"main-x-axis",axisTick:{show:!0,alignWithLabel:!0},type:n?"value":"category",axisLabel:{...r,formatter:go(r.formatter)}}]}function vb(e,t){return e.y_axes.map(({nameAlignment:n,min:r,max:a,...o},l)=>{let u=o.position;return u||(u=l>0?"right":"left"),{...o,min:r||void 0,max:a||void 0,position:u,axisLabel:{show:!0,formatter:t[l]??t.default},axisLine:{show:!0},nameTextStyle:{fontWeight:"bold",align:n},nameLocation:"end",nameGap:15,splitLine:{show:!1}}})}const xb={xAxis:[{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"},splitLine:{show:!1},axisTick:{show:!0,alignWithLabel:!0}}],grid:{top:10,left:20,right:15,bottom:25,containLabel:!0}};function wb(e,t,n){const r=n.reduce((c,d)=>{const f=vt(d,t);return c[d.name]=tt(d,f),c},{}),a=e.y_axes.reduce((c,{label_formatter:d},f)=>(c[f]=function(g){let m=g;if(typeof g=="object"&&(Array.isArray(g.value)&&g.value.length===2?m=g.value[1]:m=g.value),!d)return m;try{return H(m).format(d)}catch(C){return console.error(C),m}},c),{default:({value:c})=>c}),o=x.uniq(ut(t,e.x_axis.data_key)),l=fb(e,t,n,r),u={xAxis:bb(e,o),yAxis:vb(e,a),series:l,dataset:sb(e,t),tooltip:yb(e,a),grid:ob(e),legend:lb(),dataZoom:$r(e.dataZoom)};return x.defaultsDeep({},u,xb)}oe.use([G.DataZoomComponent,pe.BarChart,pe.LineChart,pe.ScatterChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer,G.MarkLineComponent,G.MarkAreaComponent]);function yo(e){return e.trim().length>0}function Cb({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=bt(t,e.x_axis.data_key),u=He(a.triggerManager,po.id),c=b.useCallback(h=>{const g=h.data;u.forEach(m=>{a.runInteraction(m.id,{...h,rowData:g})})},[l,u,a]),d=b.useMemo(()=>({click:c}),[c]),f=b.useMemo(()=>wb(e,t,o),[e,t]);return i(Ne,{echarts:oe,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function Sb({context:e,instance:t}){const n=et({vizManager:e.vizManager,instance:t}),{value:r}=W(e.instanceData,"config"),{variables:a}=e,o=b.useMemo(()=>x.defaults({},r,oi),[r]),l=e.data,{width:u,height:c}=e.viewport,{ref:d,height:f}=Ee.useElementSize(),{ref:h,height:g}=Ee.useElementSize(),m=b.useMemo(()=>{const{stats:{templates:w}}=o;return{top:Zt(w.top,a,l),bottom:Zt(w.bottom,a,l)}},[o,l]),C=Math.max(0,c-f-g);return!u||!c?null:p(s.Box,{children:[i(s.Text,{ref:d,align:"left",size:"xs",pl:"sm",sx:{display:yo(o.stats.templates.top)?"block":"none"},children:Object.values(m.top).map(w=>w)}),i(Cb,{variables:a,width:u,height:C,data:l,conf:o,interactionManager:n}),i(s.Text,{ref:h,align:"left",size:"xs",pl:"sm",sx:{display:yo(o.stats.templates.bottom)?"block":"none"},children:Object.values(m.bottom).map(w=>w)})]})}const _b=b.forwardRef(({value:e,onChange:t,xAxisOptions:n,yAxisOptions:r,variableOptions:a},o)=>{const l=(u,c)=>{const d=x.cloneDeep(e);x.set(d,u,c),t(d)};return p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Content",labelPosition:"right"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.TextInput,{label:"Content Text",value:e.content.text,onChange:u=>l("content.text",u.currentTarget.value)}),i(Vr,{label:"Text Position",value:e.label.position,onChange:u=>l("label.position",u)})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Endpoints",labelPosition:"right"}),p(s.Group,{grow:!0,noWrap:!0,children:[n&&i(s.Select,{label:"X Axis",data:n,value:e.xAxisIndex,onChange:u=>l("xAxisIndex",u)}),r&&i(s.Select,{label:"Y Axis",data:r,value:e.yAxisIndex,onChange:u=>l("xAxisIndex",u)})]}),p(s.Stack,{spacing:0,children:[i(s.Text,{size:14,color:"#212529",fw:500,children:"Left-Bottom Point"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.Select,{icon:i(s.Text,{children:"x"}),data:a,value:e.leftBottomPoint.x_data_key,onChange:u=>l("leftBottomPoint.x_data_key",u??""),clearable:!0}),i(s.Select,{icon:i(s.Text,{children:"y"}),data:a,value:e.leftBottomPoint.y_data_key,onChange:u=>l("leftBottomPoint.y_data_key",u??""),clearable:!0})]})]}),p(s.Stack,{spacing:0,children:[i(s.Text,{size:14,color:"#212529",fw:500,children:"Right-Top Point"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.Select,{icon:i(s.Text,{children:"x"}),data:a,value:e.rightTopPoint.x_data_key,onChange:u=>l("rightTopPoint.x_data_key",u??""),clearable:!0}),i(s.Select,{icon:i(s.Text,{children:"y"}),data:a,value:e.rightTopPoint.y_data_key,onChange:u=>l("rightTopPoint.y_data_key",u??""),clearable:!0})]})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Style",labelPosition:"right"}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:14,children:"Background Color"}),i(Pe,{value:e.itemStyle.color,onChange:u=>l("itemStyle.color",u)})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:14,children:"Text Color"}),i(Pe,{value:e.label.color,onChange:u=>l("label.color",u)})]})]})});function kb(){const e=new Date().getTime().toString();return{id:e,content:{text:e},itemStyle:{color:"rgba(0,0,0,0.05)"},label:{position:"inside",color:"rgba(0,0,0,0.5)"},leftBottomPoint:{x_data_key:"",y_data_key:""},rightTopPoint:{x_data_key:"",y_data_key:""},xAxisIndex:"0",yAxisIndex:"0"}}function Tb({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_areas"}),l=t("reference_areas"),u=r.map((g,m)=>({...g,...l[m]})),c=()=>{const g=kb();a(g)},d=b.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=t("y_axes"),h=b.useMemo(()=>f.map(({name:g},m)=>({label:g,value:m.toString()})),[f]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((g,m)=>i(s.Tabs.Tab,{value:m.toString(),children:m+1},m)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(T.Plus,{size:18,color:"#228be6"})})]}),u.map((g,m)=>i(s.Tabs.Panel,{value:m.toString(),children:i(v.Controller,{name:`reference_areas.${m}`,control:e,render:({field:C})=>p(s.Stack,{children:[i(_b,{variableOptions:d,yAxisOptions:h,...C}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(L.IconTrash,{size:16}),color:"red",variant:"light",onClick:()=>o(m),children:"Delete this Reference Area"})]})})},m))]})}const Db=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Mb=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Ib({control:e,index:t,remove:n,watch:r,variableOptions:a,yAxisOptions:o}){const l=r(`reference_lines.${t}.orientation`);return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:u})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:u})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),i(v.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:u})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),p(s.Group,{grow:!0,children:[p(s.Stack,{children:[i(v.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:u})=>i(s.Select,{label:"Orientation",data:Mb,required:!0,sx:{flex:1},...u})}),l==="vertical"&&i(s.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&i(v.Controller,{name:`reference_lines.${t}.yAxisIndex`,control:e,render:({field:{value:u,onChange:c,...d}})=>i(s.Select,{label:"Y Axis",data:o,disabled:o.length===0,...d,value:(u==null?void 0:u.toString())??"",onChange:f=>{if(!f){c(0);return}c(Number(f))},sx:{flex:1}})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:u})=>i(s.Select,{label:"Line Type",data:Db,sx:{flexGrow:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:u})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:u})=>i(Pe,{...u})})]}),i(s.Button,{leftIcon:i(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]},t)}function Eb({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=r.map((g,m)=>({...g,...l[m]})),c=()=>{const g={name:"",template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:ot.random().css()},show_in_legend:!1,yAxisIndex:0};a(g)},d=b.useMemo(()=>n.map(g=>({label:g.name,value:g.name})),[n]),f=t("y_axes"),h=b.useMemo(()=>f.map(({name:g},m)=>({label:g,value:m.toString()})),[f]);return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((g,m)=>i(s.Tabs.Tab,{value:m.toString(),children:m+1},m)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(T.Plus,{size:18,color:"#228be6"})})]}),u.map((g,m)=>i(s.Tabs.Panel,{value:m.toString(),children:i(Ib,{control:e,index:m,remove:o,watch:t,variableOptions:d,yAxisOptions:h})},m))]})}const Ab=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{children:i(Ae,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},zb=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=X.useBoolean(),[o,l]=b.useState(e),u=()=>{a();const{type:h,func_content:g}=o,m={type:h,func_content:g};l(m),t(m)},c=()=>{a(),l(e)},d=h=>{l(g=>({...g,func_content:h}))},f=()=>{d(sn.dynamic.func_content)};return p(V,{children:[i(s.Box,{sx:{width:"50%"},children:i(s.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),i(s.Modal,{size:800,title:"Setup dynamic color",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),i(Ab,{value:o.func_content,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(T.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},$b=({value:e,onChange:t})=>e.type!=="dynamic"?null:i(zb,{value:e,onChange:t}),Lb=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,color:r})};return i(s.ColorInput,{label:" ",format:"rgb",value:e.color,onChange:n})},Ob=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Pb=b.forwardRef(({label:e="Color",value:t,onChange:n},r)=>{const a=o=>{n({...sn[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:e,data:Ob,value:t.type,onChange:a,sx:{flexGrow:1}}),i(Lb,{value:t,onChange:n}),i($b,{value:t,onChange:n})]})}),Bb=b.forwardRef(({value:e,onChange:t},n)=>{const r=o=>{t({...e,label:o})},a=o=>{t({...e,tooltip:o})};return p(s.Stack,{ref:n,spacing:0,children:[i(Cn,{sectionTitle:"Overflow on Chart",value:e.label,onChange:r}),i(Cn,{sectionTitle:"Overflow in Tooltip",value:e.tooltip,onChange:a})]})}),Vb=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{children:i(Ae,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},bo={static:{type:"static",size:10},dynamic:{type:"dynamic",func_content:["function getSize({ rowData, params, variables }, { lodash, interpolate }) {"," // your code goes here"," // return 10","}"].join(`
276
+ `)}},Nb=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=X.useBoolean(),[o,l]=b.useState(e),u=()=>{a();const{type:h,func_content:g}=o,m={type:h,func_content:g};l(m),t(m)},c=()=>{a(),l(e)},d=h=>{l(g=>({...g,func_content:h}))},f=()=>{d(bo.dynamic.func_content)};return p(V,{children:[i(s.Box,{sx:{width:"50%"},children:i(s.Button,{variant:"filled",mt:24,onClick:r,sx:{flexGrow:0},children:"Setup"})}),i(s.Modal,{size:800,title:"Setup dynamic size",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Divider,{mt:10,mb:-10,label:"Dynamic by a custom function",labelPosition:"center",variant:"dashed"}),i(Vb,{value:o.func_content,onChange:d}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(T.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:c,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:u,children:"OK"})]})]})]})})]})},qb=({value:e,onChange:t})=>e.type!=="dynamic"?null:i(Nb,{value:e,onChange:t}),Fb=({value:e,onChange:t})=>{if(e.type!=="static")return null;const n=r=>{t({...e,size:r})};return i(V,{children:i(s.NumberInput,{defaultValue:18,placeholder:"1 ~ 100",label:" ",hideControls:!0,value:e.size,onChange:n})})},Gb=[{label:"Static",value:"static"},{label:"Dynamic",value:"dynamic"}],Wb=b.forwardRef(({label:e="Size",value:t,onChange:n},r)=>{const a=o=>{n({...bo[o]})};return p(s.SimpleGrid,{cols:2,children:[i(s.Select,{ref:r,label:e,data:Gb,value:t.type,onChange:a,sx:{flexGrow:1}}),i(Fb,{value:t,onChange:n}),i(qb,{value:t,onChange:n})]})}),Rb=[{label:"off",value:""},{label:"top",value:"top"},{label:"left",value:"left"},{label:"right",value:"right"},{label:"bottom",value:"bottom"},{label:"inside",value:"inside"},{label:"insideLeft",value:"insideLeft"},{label:"insideRight",value:"insideRight"},{label:"insideTop",value:"insideTop"},{label:"insideBottom",value:"insideBottom"},{label:"insideTopLeft",value:"insideTopLeft"},{label:"insideBottomLeft",value:"insideBottomLeft"},{label:"insideTopRight",value:"insideTopRight"},{label:"insideBottomRight",value:"insideBottomRight"}];function jb({control:e,watch:t}){return t(["scatter"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"scatter.name_data_key",control:e,render:({field:n})=>i(R,{label:"Name Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"scatter.y_data_key",control:e,render:({field:n})=>i(R,{label:"Value Data Field",required:!0,sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Style",labelPosition:"center"}),i(v.Controller,{name:"scatter.symbolSize",control:e,render:({field:n})=>i(Wb,{label:"Size",...n})}),i(v.Controller,{name:"scatter.color",control:e,render:({field:n})=>i(Pb,{...n})}),i(s.Divider,{mb:-15,label:"Label",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"scatter.label_position",control:e,render:({field:n})=>i(s.Select,{label:"Label Position",data:Rb,...n})})}),i(v.Controller,{name:"scatter.label_overflow",control:e,render:({field:n})=>i(Bb,{...n})})]})}function Yb({control:e,watch:t}){return t("stats"),i(s.Stack,{children:p(s.Stack,{spacing:0,children:[i(v.Controller,{name:"stats.templates.top",control:e,render:({field:n})=>i(Jt,{label:"Template for stats above the chart",py:"md",sx:{flexGrow:1},...n})}),i(v.Controller,{name:"stats.templates.bottom",control:e,render:({field:n})=>i(Jt,{label:"Template for stats under the chart",py:"md",sx:{flexGrow:1},...n})})]})})}const Qb=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>i(R,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),Kb=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,f]=b.useState(()=>c??null);return b.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(V,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(T.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(T.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(Qb,{control:e,index:g,remove:a},h.id)},h.id))]})]})},Ub=[{label:"Scatter Point",value:"item"},{label:"X Axis",value:"axis"}];function Xb({control:e,watch:t}){return t("tooltip.trigger"),p(s.Stack,{children:[i(v.Controller,{name:"tooltip.trigger",control:e,render:({field:n})=>i(s.Select,{label:"Trigger",data:Ub,sx:{flexGrow:1},...n})}),i(s.Divider,{variant:"dashed"}),i(Kb,{control:e,watch:t})]})}const Jb=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Ae,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},Zb=b.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=X.useBoolean(),[l,u]=b.useState(e);b.useEffect(()=>{u(e)},[e]);const c=m=>{u({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:C}=l,w={enabled:m,func_content:C};u(w),t(w)},f=()=>{o(),u(e)},h=m=>{u(C=>({...C,func_content:m}))},g=()=>{h(ho.func_content)};return p(V,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Customize Label"}),i(s.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>c(m.currentTarget.checked)}),i(Jb,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(T.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})});function Hb({control:e,watch:t}){return t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(R,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>i(Zb,{...n})})]})]})}const ev=[{label:"left",value:"left"},{label:"center",value:"center"},{label:"right",value:"right"}],tv=[{label:"left",value:"left"},{label:"right",value:"right"}];function nv({control:e,index:t,remove:n}){return p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[i(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`y_axes.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`y_axes.${t}.nameAlignment`,control:e,render:({field:r})=>i(s.Select,{label:"Align",required:!0,data:ev,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`y_axes.${t}.position`,control:e,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:tv,sx:{flex:1},...r})})}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:`y_axes.${t}.label_formatter`,control:e,render:({field:r})=>i(je,{...r})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`y_axes.${t}.min`,control:e,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`y_axes.${t}.max`,control:e,render:({field:r})=>i(s.TextInput,{label:"Max",...r})})]})]}),i(s.Button,{mt:20,leftIcon:i(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this YAxis"})]})}function rv({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"y_axes"}),o=t("y_axes"),l=n.map((c,d)=>({...c,...o[d]})),u=()=>r({name:"",label_formatter:$e,min:"",max:"",show:!0,position:"right",nameAlignment:"right"});return p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map((c,d)=>i(s.Tabs.Tab,{value:d.toString(),children:d+1},d)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(T.Plus,{size:18,color:"#228be6"})})]}),l.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(nv,{control:e,index:d,remove:a})},d))]})}function iv(e){return e||{templates:{top:"",bottom:""}}}function av({reference_lines:e=[],stats:t,...n}){return{reference_lines:e,stats:iv(t),...n}}function sv({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),{variables:r}=e,a=b.useMemo(()=>x.defaultsDeep({},t,oi),[t]),o=b.useMemo(()=>av(a),[a]);b.useEffect(()=>{!x.isEqual(a,o)&&(console.log("config malformed, resetting to defaults",a,o),n(o))},[a,o]);const{control:l,handleSubmit:u,watch:c,getValues:d,reset:f}=v.useForm({defaultValues:o});b.useEffect(()=>{f(o)},[o]);const h=d(),g=b.useMemo(()=>!x.isEqual(h,a),[h,a]);return c(["dataZoom"]),i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:u(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!g,children:i(T.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axes",children:"Y Axes"}),i(s.Tabs.Tab,{value:"Scatter",children:"Scatter"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),i(s.Tabs.Tab,{value:"Stats",children:"Stats"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"}),i(s.Tabs.Tab,{value:"Reference Areas",children:"Reference Areas"}),i(s.Tabs.Tab,{value:"Zooming",children:"Zooming"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(Hb,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Y Axes",children:i(rv,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Scatter",children:i(jb,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(Xb,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Stats",children:i(Yb,{control:l,watch:c})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(Eb,{variables:r,control:l,watch:c})}),i(s.Tabs.Panel,{value:"Reference Areas",children:i(Tb,{variables:r,control:l,watch:c})}),i(s.Tabs.Panel,{value:"Zooming",children:i(v.Controller,{name:"dataZoom",control:l,render:({field:m})=>i(Or,{...m})})})]})]})})}function ov(e){const{dataZoom:t=Vt,...n}=e;return{...n,dataZoom:t}}function lv(e){const t={scatter:{label_overflow:fo}};return x.defaultsDeep(t,e)}function uv(e){const{color:t}=e.scatter;return typeof t=="string"?{...e,scatter:{...e.scatter,color:{...sn.static,color:t}}}:e}function cv(e){const t=e.reference_lines.map(n=>{const{lineStyle:r={type:"dashed",width:1,color:ot.random().css()},show_in_legend:a=!1,yAxisIndex:o=0}=n;return{...n,lineStyle:r,show_in_legend:a,yAxisIndex:o}});return{...e,reference_lines:t}}function dv(e){const t={tooltip:{trigger:"item"}};return x.defaultsDeep({},e,t)}function pv(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,scatter:o,tooltip:l,...u}=e;return{...u,x_axis:{...a,data_key:r(a.data_key)},scatter:{...o,y_data_key:r(o.y_data_key),name_data_key:r(o.name_data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:r(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}class hv extends be{constructor(){super(...arguments);N(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{tooltip:r={metrics:[]},...a}=n.config;return{...n,version:2,config:{...a,tooltip:r}}}),this.version(3,n=>({...n,version:3,config:ov(n.config)})),this.version(4,n=>{const{config:r}=n;return{...n,version:5,config:lv(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:uv(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:cv(r)}}),this.version(8,n=>{const{config:r}=n;return{...n,version:8,config:dv(r)}}),this.version(9,(n,r)=>{const{config:a}=n;return{...n,version:9,config:pv(a,r)}})}}const fv={displayName:"Scatter Chart",displayGroup:"ECharts-based charts",migrator:new hv,name:"scatterChart",viewRender:Sb,configRender:sv,createConfig(){return{version:9,config:x.cloneDeep(oi)}},triggers:[po]},li={template:"The variable ${value} is defined in Variables section",vertical_align:"center",horizontal_align:"left"};function gv(e){if("variables"in e)return e;const{align:t,size:n,weight:r,color:a,content:{prefix:o="",data_field:l="value",formatter:u={output:"number",mantissa:0},postfix:c=""}={}}=e;return{align:t,template:`${o} \${value} ${c}`,variables:[{name:"value",data_field:l,aggregation:{type:"none",config:{}},formatter:u,color:a,weight:r,size:n}]}}function mv(e){return x.omit(e,["variables"])}function yv(e){const{align:t,...n}=e;return{horizontal_align:t,vertical_align:"center",...n}}function bv(e){const t=x.cloneDeep(e),n=x.get(t,"color.valueRange");return n!==void 0&&x.set(t,"color.valueRange",n.map(r=>Number(r))),t}class vv extends be{constructor(){super(...arguments);N(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:gv(n)})),this.version(2,(n,{panelModel:r})=>{const{config:a}=n;return(a.variables||[]).forEach(l=>{r.variables.find(u=>u.name===l.name)||r.addVariable(bv(l))}),{...n,version:2,config:mv(a)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:yv(r)}})}}const xv={left:"flex-start",center:"center",right:"flex-end"},wv={top:"flex-start",center:"center",bottom:"flex-end"},Cv=k.observer(({context:e})=>{const t=Me(),{value:n=li}=W(e.instanceData,"config"),{variables:r}=e,{template:a,horizontal_align:o,vertical_align:l}=n,{width:u,height:c}=e.viewport,d=b.useMemo(()=>{try{return x.template(a)(t.payloadForSQL)}catch{return a}},[t.payloadForSQL,a]),f=b.useMemo(()=>Zt(d,r,e.data),[d,r,e.data,e]);return i(s.Center,{sx:{width:u,height:c,justifyContent:xv[o],alignItems:wv[l]},children:i(s.Box,{children:Object.values(f).map((h,g)=>i(b.Fragment,{children:h},g))})})}),Sv=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],_v=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function kv({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),r=b.useMemo(()=>x.defaultsDeep({},t,li),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});b.useEffect(()=>{c(r)},[r]),l(["template","horizontal_align","vertical_align"]);const d=u(),f=b.useMemo(()=>!x.isEqual(d,t),[d,t]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{weight:500,children:"Stats Configurations"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(T.DeviceFloppy,{size:20})})]}),i(v.Controller,{name:"template",control:a,render:({field:h})=>i(Jt,{label:"Template",py:"md",sx:{flexGrow:1},...h})}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{name:"horizontal_align",control:a,render:({field:h})=>i(s.Select,{label:"Horizontal Alignment",data:Sv,...h})}),i(v.Controller,{control:a,name:"vertical_align",render:({field:h})=>i(s.Select,{label:"Vertical Alignment",data:_v,...h})})]})]})})}const Tv={createConfig(){return{version:3,config:li}},displayName:"Stats",displayGroup:"Others",migrator:new vv,name:"stats",viewRender:Cv,configRender:kv},ui={label_key:"",value_key:"",group_key:"",levels:[]};function Dv(e){const t=new Set(e.map(r=>r.parent_id)),n=new Set(e.map(r=>r.id));return t.forEach(r=>{r===null||n.has(r)||e.push({id:r,name:r,parent_id:null})}),e}function Mv(e){const t=Dv(e).map(a=>({...a,children:[]})),n=x.keyBy(t,a=>a.id),r=[];return t.forEach(a=>{if(!a.parent_id||!n[a.parent_id]){r.push(a);return}n[a.parent_id].children.push(a)}),r}function Iv(e,t){const{label_key:n,value_key:r,group_key:a}=e;if(!n||!r)return[];const o=q(n),l=q(r),u=q(a),c=t[o.queryID].map(d=>({...d,id:d[o.columnKey],parent_id:d[u.columnKey],name:d[o.columnKey],value:d[l.columnKey]?Number(d[l.columnKey]):d[l.columnKey]}));return a?Mv(c):c}const Ev=e=>({treePathInfo:t,name:n,value:r})=>{if(t.length===1||!e)return n;try{const a=t[t.length-2].value;if(r/a<e)return" "}catch{return n}};function Av(e){const{levels:t}=e;return t.map(n=>{const{show_label_tolerance:r,...a}=n.label;return{...n,label:{...a,formatter:Ev(r)}}})}function zv(){return({treePathInfo:e,name:t,value:n,color:r,marker:a,...o})=>{const l=e.slice(0,e.length-1),u=[`<tr>
342
277
  <th style="text-align: right; padding: 0 1em;">Value</th>
343
278
  <td style="text-align: left; padding: 0 1em;">${n}</td>
344
279
  </tr>
@@ -346,18 +281,19 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
346
281
  <tr>
347
282
  <th style="text-align: right; padding: 0 1em;">${f||"Total"}</th>
348
283
  <td style="text-align: left; padding: 0 1em;">
349
- ${ee(n/d).format({output:"percent",mantissa:2,trimMantissa:!0})}
284
+ ${H(n/d).format({output:"percent",mantissa:2,trimMantissa:!0})}
350
285
  </td>
351
286
  </tr>
352
287
  `)}),`
353
288
  <div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
354
- <div>${a} ${e}</div>
289
+ <div>${a} ${t}</div>
355
290
  </div>
356
291
  <table style="width: auto">
357
292
  <tbody>${u.join("")}</tbody>
358
293
  </table>
359
- `}}function Sv(){return{show:!0,trigger:"item",confine:!0,formatter:Cv()}}const _v={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function kv(t,e,n){n.reduce((o,l)=>{const u=yt(l,e);return o[l.name]=et(l,u),o},{});const a={series:{data:vv(t,e),levels:wv(t)},tooltip:Sv()};return x.defaultsDeep({},a,_v)}le.use([pe.SunburstChart,Ve.CanvasRenderer]);function Tv({context:t}){const{variables:e}=t,{value:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaults({},n,oi),[n]),a=t.data,{width:o,height:l}=t.viewport,u=y.useMemo(()=>kv(r,a,e),[r,a,e]);return!o||!l?null:i(Ne,{echarts:le,option:u,style:{width:o,height:l},notMerge:!0,theme:"merico-light"})}function Dv({control:t,watch:e}){return e(["label_key","value_key","group_key"]),p(s.Stack,{children:[i(v.Controller,{name:"label_key",control:t,render:({field:n})=>i(j,{label:"Label Key",required:!0,...n})}),i(v.Controller,{name:"value_key",control:t,render:({field:n})=>i(j,{label:"Value Key",required:!0,...n})}),i(v.Controller,{name:"group_key",control:t,render:({field:n})=>i(j,{label:"Group Key",clearable:!0,...n})})]})}const Mv=[{label:"Radial",value:"radial"},{label:"Tangential",value:"tangential"},{label:"None",value:"0"}],Iv=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Ev=({control:t,index:e,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`levels.${e}.r0`,control:t,render:({field:r})=>i(s.TextInput,{label:"Inside Radius",placeholder:"0%",...r})}),i(v.Controller,{name:`levels.${e}.r`,control:t,render:({field:r})=>i(s.TextInput,{label:"Outside Radius",placeholder:"50%",...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Label Style",labelPosition:"center"}),i(v.Controller,{name:`levels.${e}.label.show_label_tolerance`,control:t,render:({field:r})=>i(s.NumberInput,{label:"Hide label when its percentage is less than...",precision:4,step:5e-4,min:0,max:1,...r})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`levels.${e}.label.rotate`,control:t,render:({field:r})=>i(s.Select,{label:"Rotate",data:Mv,...r})}),i(v.Controller,{name:`levels.${e}.label.align`,control:t,render:({field:r})=>i(s.Select,{label:"Align",data:Iv,...r})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`levels.${e}.label.position`,control:t,render:({field:r})=>i(Pr,{label:"Position",...r})}),i(v.Controller,{name:`levels.${e}.label.padding`,control:t,render:({field:r})=>i(s.NumberInput,{label:"Padding",min:0,hideControls:!0,...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Level"})]}),Av=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"levels"}),o=e("levels"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),r0:"",r:"",label:{show_label_tolerance:.001,rotate:"0",align:"center",position:"inside",padding:0}}),c=e("levels.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(V,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(D.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure ring style on each level"})]}),i(s.Divider,{variant:"dashed",my:10}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(Ev,{control:t,index:g,remove:a},h.id)},h.id))]})]})};function zv({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,oi),[e]),a=y.useMemo(()=>x.clone(r),[r]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);u(["label_key","value_key","group_key","levels"]);const[g,m]=y.useState("Data");return i("form",{onSubmit:l(n),children:p(s.Stack,{spacing:"xs",children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Sunburst Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{value:g,onTabChange:m,orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Data",children:"Data"}),i(s.Tabs.Tab,{value:"Levels",children:"Levels"})]}),i(s.Tabs.Panel,{value:"Data",children:i(Dv,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Levels",children:i(Av,{control:o,watch:u})})]})]})})}function $v(t){const{label_field:e,value_field:n,...r}=t;return{...r,label_key:e,value_key:n}}function Lv(t){const{group_key:e="",...n}=t;return{...n,group_key:e}}function Ov(t){const{levels:e=[],...n}=t;return{...n,levels:e}}function Pv(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{label_key:a,value_key:o,group_key:l,...u}=t;return{...u,label_key:r(a),value_key:r(o),group_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class Bv extends ve{constructor(){super(...arguments);N(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:$v(n.config)})),this.version(3,n=>({...n,version:3,config:Lv(n.config)})),this.version(4,n=>({...n,version:4,config:Ov(n.config)})),this.version(5,(n,r)=>({...n,version:5,config:Pv(n.config,r)}))}}const Vv={displayName:"Sunburst Chart",displayGroup:"ECharts-based charts",migrator:new Bv,name:"sunburst",viewRender:Tv,configRender:zv,createConfig(){return{version:5,config:x.cloneDeep(oi)}}},Po=["function text({ data, variables, filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
360
- `),li={func_content:Po,horizontal_align:"left",font_size:"14px",font_weight:"normal"},Nv=k.observer(({context:t})=>{const e=K(),{value:n=li}=W(t.instanceData,"config"),{variables:r}=t,a=t.data,{func_content:o,horizontal_align:l,font_size:u,font_weight:c}=n,d=y.useMemo(()=>r.reduce((h,g)=>{const m=yt(g,a);return h[g.name]=et(g,m),h},{}),[r,a]),f=y.useMemo(()=>new Function(`return ${o}`)()({data:a,variables:d,filters:e.payloadForSQL.filters,context:e.payloadForSQL.context}),[o,a,d,e.payloadForSQL]);return i(s.Text,{align:l,weight:c,sx:{fontSize:u},children:f})}),qv=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return i(s.Box,{sx:{position:"relative"},children:i(Ie,{height:"500px",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Fv=y.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:a,setFalse:o}]=X.useBoolean(),[l,u]=y.useState(t),c=()=>{o(),e(l)},d=()=>{o(),u(t)},f=()=>{u(Po)};return y.useEffect(()=>{u(t)},[t]),p(V,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Edit Content"}),i(s.Modal,{size:800,title:"Text content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(qv,{value:l,onChange:u}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})}),Gv=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}];function Wv({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,li),[e]),a=y.useMemo(()=>{const{func_content:g,horizontal_align:m,font_size:w,font_weight:C}=r;return{func_content:g,horizontal_align:m,font_size:w,font_weight:C}},[r]);y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]),u(["func_content","horizontal_align","font_size","font_weight"]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{weight:500,children:"Configurations"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Stack,{spacing:10,children:[i(v.Controller,{name:"func_content",control:o,render:({field:g})=>i(Fv,{...g})}),i(s.Divider,{mt:10,mb:-10,variant:"dashed",label:"Style",labelPosition:"center"}),i(v.Controller,{name:"horizontal_align",control:o,render:({field:g})=>i(s.Select,{label:"Horizontal Alignment",data:Gv,...g})}),i(v.Controller,{name:"font_size",control:o,render:({field:g})=>i(s.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},...g})}),i(s.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:i(v.Controller,{name:"font_weight",control:o,render:({field:g})=>i(ks,{label:"Font Weight",...g})})})]})]})})}class jv extends ve{constructor(){super(...arguments);N(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const Rv={displayName:"Text",displayGroup:"Others",migrator:new jv,name:"text",viewRender:Nv,configRender:Wv,createConfig(){return{version:1,config:x.cloneDeep(li)}}},Yv=()=>p("svg",{width:"64",height:"64",viewBox:"0 0 64 64",fill:"none",children:[i("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M22.49 27.79H14.47C13.55 27.79 12.81 28.53 12.81 29.45C12.81 30.37 13.55 31.11 14.47 31.11H22.49C23.41 31.11 24.15 30.37 24.15 29.45C24.15 28.54 23.41 27.79 22.49 27.79ZM34.32 31.28C35.22 31.32 35.7 31.82 35.74 32.76C35.78 33.54 35.37 34.3 34.51 35.04C33.52 35.9 33.03 36.95 33.03 38.19V38.81H34.82V38.25C34.78 37.59 35.07 37.02 35.68 36.52C37.12 35.41 37.82 34.15 37.78 32.75C37.66 30.53 36.5 29.35 34.32 29.23C32.3 29.23 31.05 30.46 30.55 32.93L32.53 33.55C32.82 32.04 33.42 31.28 34.32 31.28ZM35 39.93H32.84V42.21H35V39.93ZM14.83 36.42H18.54C19.46 36.42 20.2 37.17 20.2 38.08C20.2 39 19.46 39.74 18.54 39.74H10.52C9.6 39.74 8.86 39 8.86 38.08C8.86 37.61 9.06 37.19 9.37 36.89H5.66C4.74 36.89 4 36.15 4 35.23C4 34.31 4.74 33.57 5.66 33.57H13.68C14.6 33.57 15.34 34.31 15.34 35.23C15.34 35.7 15.14 36.12 14.83 36.42ZM50.94 36.85H58.74C59.66 36.85 60.4 37.59 60.41 38.51C60.41 39.43 59.67 40.17 58.75 40.17H54.26C54.56 40.47 54.74 40.88 54.74 41.34C54.74 42.26 54 43 53.08 43H50.94V36.85Z",fill:"#B8C0CC"}),i("path",{d:"M18.39 32.28H16.51V35.02H18.39V32.28Z",fill:"#9399A5"}),i("path",{d:"M46.87 15H20.69C18.38 15 16.5 16.88 16.5 19.19V26.22H18.38V23.45H49.18V47.68H18.38V41.07H16.5V49.55H51.05V19.19C51.06 16.88 49.18 15 46.87 15ZM39.46 20.73C38.81 20.73 38.29 20.2 38.29 19.56C38.29 18.92 38.82 18.39 39.46 18.39C40.11 18.39 40.63 18.92 40.63 19.56C40.63 20.2 40.11 20.73 39.46 20.73ZM43.22 20.73C42.57 20.73 42.05 20.2 42.05 19.56C42.05 18.92 42.58 18.39 43.22 18.39C43.87 18.39 44.39 18.92 44.39 19.56C44.39 20.2 43.87 20.73 43.22 20.73ZM46.97 20.73C46.32 20.73 45.8 20.2 45.8 19.56C45.8 18.92 46.33 18.39 46.97 18.39C47.62 18.39 48.14 18.92 48.14 19.56C48.14 20.2 47.62 20.73 46.97 20.73Z",fill:"#9399A5"})]});function Bo(t,e){const n=x.get(t,e,"");if(n)throw new Error(n)}async function Qv(t,e,n,r={}){const a={"X-Requested-With":"XMLHttpRequest","Content-Type":r.string?"application/x-www-form-urlencoded":"application/json",...r.headers},o={baseURL:t,method:"POST",url:e,params:r.params,headers:a};return o.data=r.string?JSON.stringify(n):n,pt(o).then(l=>l.data).catch(l=>Promise.reject(l))}const Kv=({conf:t,panelData:e})=>async()=>{const{expertSystemURL:n,path:r,goal:a,question:o}=t;if(!r||!a||!o)return;const l=dc(e);if(!l)return;const u={dashboard:a,panel:o,data:l};try{const c=n.startsWith("http")?n:window.location.origin;return await Qv(c,`/expert/v3/devtable/${r}`,u,{})}catch(c){throw Bo(c,"response.data.detail"),Bo(c,"response.data.error"),console.error(c),c}},ui={expertSystemURL:"",path:"",goal:"",question:""},ci={height:"100%",overflowY:"auto",...Gr},Vo=({message:t})=>i(s.Box,{sx:ci,children:i("div",{dangerouslySetInnerHTML:{__html:t},style:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45"}})}),Uv=({error:t,width:e,height:n})=>{const r=t.message;if(r.startsWith("<"))return i(Vo,{message:r});const o=n-25-20-30;return i(s.Center,{sx:{width:"100%",height:o},children:p(s.Stack,{align:"center",spacing:20,children:[i(Yv,{}),i(Vo,{message:r})]})})};function Xv({context:t}){const{value:e}=W(t.instanceData,"config"),n=y.useMemo(()=>x.defaultsDeep({},e,ui),[e]),{width:r,height:a}=t.viewport,o=t.data,{data:l,error:u,loading:c}=X.useRequest(Kv({conf:n,panelData:o}),{refreshDeps:[o,n]});return!r||!a||!n?null:c?i(s.Box,{sx:{position:"relative",height:a},children:i(s.LoadingOverlay,{visible:!0})}):u?i(s.Box,{sx:ci,"data-enable-scrollbar":!0,children:i(Uv,{error:u,width:r,height:a})}):!l||!Array.isArray(l.replies)||l.replies.length===0?null:i(s.Box,{sx:ci,"data-enable-scrollbar":!0,children:l.replies.map((d,f)=>i("div",{dangerouslySetInnerHTML:{__html:d.interpretation.html}},f))})}function Jv({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,ui),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l(["expertSystemURL","goal","path","question"]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,r),[d,r]);return i("form",{onSubmit:o(n),children:p(s.Stack,{children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:"expertSystemURL",control:a,render:({field:h})=>i(s.TextInput,{label:"Expert System URL",...h})}),i(v.Controller,{name:"path",control:a,render:({field:h})=>i(s.TextInput,{label:"Path",required:!0,...h})})]}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:"goal",control:a,render:({field:h})=>i(s.TextInput,{label:"Goal",required:!0,...h})}),i(v.Controller,{name:"question",control:a,render:({field:h})=>i(s.TextInput,{label:"Question",required:!0,...h})})]}),i(s.Divider,{variant:"dashed",mt:16,mb:8}),i(s.Button,{type:"submit",variant:"filled",color:"blue",leftIcon:i(D.DeviceFloppy,{size:20}),disabled:!f,sx:{alignSelf:"flex-end"},children:"Submit Changes"})]})})}class Zv extends ve{constructor(){super(...arguments);N(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const Hv={displayName:"Merico GQM",displayGroup:"Merico suite",migrator:new Zv,name:"mericoGQM",viewRender:Xv,configRender:Jv,createConfig(){return{version:1,config:x.cloneDeep(ui)}}};function ex(t,e,n){if(!t)return n[0];try{return[e,R(e).add(1,"year").subtract(1,"day").valueOf()]}catch(r){return console.error(r),n[0]}}function tx(t,e,n){const r=ex(t,e,n);return{top:50,left:25,right:5,cellSize:["auto",13],range:r,itemStyle:{borderColor:"#eee"},splitLine:{show:!0},dayLabel:{firstDay:1},monthLabel:{position:"end"},yearLabel:{show:!0}}}function nx(t){return{heat_block:function(r){if(!t.heat_block.value_formatter)return r;try{return ee(r).format(t.heat_block.value_formatter)}catch(a){return console.error(a),r}}}}function rx(t,e){return{show:!t,selectedMode:"single",top:5,right:5,data:e.map(n=>({name:n,icon:"circle"}))}}function ix(t,e,n,r){const{calendar:a,heat_block:o}=t,l=q(a.data_key),u=q(o.data_key);return e?{type:"heatmap",name:"heatmap",coordinateSystem:"calendar",calendarIndex:0,data:r[l.queryID].map(c=>[x.get(c,l.columnKey),x.get(c,u.columnKey)])}:Object.entries(n).map(([c,d])=>({type:"heatmap",name:c,coordinateSystem:"calendar",calendarIndex:0,data:d.map(f=>[x.get(f,l.columnKey),x.get(f,u.columnKey)])}))}const ax=t=>{try{return ee(t).format({trimMantissa:!0,mantissa:2})}catch{return t}};function sx({conf:t,valueFormatters:e,dataDict:n,params:r}){const{value:a}=r,[o,l]=a,c=[{label:t.heat_block.name,value:e.heat_block(l),style:{label:"",value:""}}],d=n[o];return d&&t.tooltip.metrics.forEach(f=>{const h=q(f.data_key);c.push({label:f.name,value:ax(x.get(d,h.columnKey,"")),style:{label:"",value:""}})}),c}function ox(t,e,n){const r=q(t.calendar.data_key),a=x.keyBy(e[r.queryID],r.columnKey);return{confine:!0,formatter:function(o){const u=sx({conf:t,valueFormatters:n,dataDict:a,params:o}).map(f=>`
294
+ `}}function $v(){return{show:!0,trigger:"item",confine:!0,formatter:zv()}}const Lv={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function Ov(e,t,n){n.reduce((o,l)=>{const u=vt(l,t);return o[l.name]=tt(l,u),o},{});const a={series:{data:Iv(e,t),levels:Av(e)},tooltip:$v()};return x.defaultsDeep({},a,Lv)}oe.use([pe.SunburstChart,Ve.CanvasRenderer]);function Pv({context:e}){const{variables:t}=e,{value:n}=W(e.instanceData,"config"),r=b.useMemo(()=>x.defaults({},n,ui),[n]),a=e.data,{width:o,height:l}=e.viewport,u=b.useMemo(()=>Ov(r,a,t),[r,a,t]);return!o||!l?null:i(Ne,{echarts:oe,option:u,style:{width:o,height:l},notMerge:!0,theme:"merico-light"})}function Bv({control:e,watch:t}){return t(["label_key","value_key","group_key"]),p(s.Stack,{children:[i(v.Controller,{name:"label_key",control:e,render:({field:n})=>i(R,{label:"Label Key",required:!0,...n})}),i(v.Controller,{name:"value_key",control:e,render:({field:n})=>i(R,{label:"Value Key",required:!0,...n})}),i(v.Controller,{name:"group_key",control:e,render:({field:n})=>i(R,{label:"Group Key",clearable:!0,...n})})]})}const Vv=[{label:"Radial",value:"radial"},{label:"Tangential",value:"tangential"},{label:"None",value:"0"}],Nv=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],qv=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`levels.${t}.r0`,control:e,render:({field:r})=>i(s.TextInput,{label:"Inside Radius",placeholder:"0%",...r})}),i(v.Controller,{name:`levels.${t}.r`,control:e,render:({field:r})=>i(s.TextInput,{label:"Outside Radius",placeholder:"50%",...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Label Style",labelPosition:"center"}),i(v.Controller,{name:`levels.${t}.label.show_label_tolerance`,control:e,render:({field:r})=>i(s.NumberInput,{label:"Hide label when its percentage is less than...",precision:4,step:5e-4,min:0,max:1,...r})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`levels.${t}.label.rotate`,control:e,render:({field:r})=>i(s.Select,{label:"Rotate",data:Vv,...r})}),i(v.Controller,{name:`levels.${t}.label.align`,control:e,render:({field:r})=>i(s.Select,{label:"Align",data:Nv,...r})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`levels.${t}.label.position`,control:e,render:({field:r})=>i(Vr,{label:"Position",...r})}),i(v.Controller,{name:`levels.${t}.label.padding`,control:e,render:({field:r})=>i(s.NumberInput,{label:"Padding",min:0,hideControls:!0,...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Level"})]}),Fv=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"levels"}),o=t("levels"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),r0:"",r:"",label:{show_label_tolerance:.001,rotate:"0",align:"center",position:"inside",padding:0}}),c=t("levels.0.id"),[d,f]=b.useState(()=>c??null);return b.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(V,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(T.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure ring style on each level"})]}),i(s.Divider,{variant:"dashed",my:10}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(T.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(qv,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function Gv({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),r=b.useMemo(()=>x.defaultsDeep({},t,ui),[t]),a=b.useMemo(()=>x.clone(r),[r]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});b.useEffect(()=>{d(a)},[a]);const f=c(),h=b.useMemo(()=>!x.isEqual(f,r),[f,r]);u(["label_key","value_key","group_key","levels"]);const[g,m]=b.useState("Data");return i("form",{onSubmit:l(n),children:p(s.Stack,{spacing:"xs",children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Sunburst Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(T.DeviceFloppy,{size:20})})]}),p(s.Tabs,{value:g,onTabChange:m,orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Data",children:"Data"}),i(s.Tabs.Tab,{value:"Levels",children:"Levels"})]}),i(s.Tabs.Panel,{value:"Data",children:i(Bv,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Levels",children:i(Fv,{control:o,watch:u})})]})]})})}function Wv(e){const{label_field:t,value_field:n,...r}=e;return{...r,label_key:t,value_key:n}}function Rv(e){const{group_key:t="",...n}=e;return{...n,group_key:t}}function jv(e){const{levels:t=[],...n}=e;return{...n,levels:t}}function Yv(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{label_key:a,value_key:o,group_key:l,...u}=e;return{...u,label_key:r(a),value_key:r(o),group_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class Qv extends be{constructor(){super(...arguments);N(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>({...n,version:2,config:Wv(n.config)})),this.version(3,n=>({...n,version:3,config:Rv(n.config)})),this.version(4,n=>({...n,version:4,config:jv(n.config)})),this.version(5,(n,r)=>({...n,version:5,config:Yv(n.config,r)}))}}const Kv={displayName:"Sunburst Chart",displayGroup:"ECharts-based charts",migrator:new Qv,name:"sunburst",viewRender:Pv,configRender:Gv,createConfig(){return{version:5,config:x.cloneDeep(ui)}}};var nt=(e=>(e.string="string",e.number="number",e.eloc="eloc",e.percentage="percentage",e.custom="custom",e))(nt||{});const vo=["function text({ value }) {"," // your code goes here"," return value","}"].join(`
295
+ `),xo={columns:[],fontSize:"14px",highlightOnHover:!0,horizontalSpacing:"14px",id_field:"",striped:!0,use_raw_columns:!0,verticalSpacing:"14px"},wo={left:"flex-start",center:"center",right:"flex-end"},Uv=({header:e,cx:t})=>{const n=x.get(e.column.columnDef.meta,"align","left");return p(s.Text,{className:t("table-head-cell",{"table-head-cell--sortable":e.column.getCanSort()}),onClick:e.column.getToggleSortingHandler(),align:n,sx:{justifyContent:wo[n]},children:[e.isPlaceholder?null:Xe.flexRender(e.column.columnDef.header,e.getContext()),i(Xv,{direction:e.column.getIsSorted()})]})},Xv=({direction:e})=>{switch(e){case"asc":return i(L.IconArrowUp,{size:16});case"desc":return i(L.IconArrowDown,{size:"1em"});default:return null}},ci={id:"builtin:table:click-cell-content",displayName:"Click Cell Content",nameRender:ex,configRender:Zv,payload:[{name:"row_index",description:"Index of the row that the cell belongs to",valueType:"number"},{name:"col_index",description:"Index of the column that the cell belongs to",valueType:"number"},{name:"row_data",description:"Data of the row that the cell belongs to",valueType:"object"}]},Jv={column:""};function Co(e,t){const{value:n}=W(e.instanceData,"config"),r={columnsFromConfig:[],columnsFromData:[]};if(n&&(r.columnsFromConfig=n.columns.map((a,o)=>({label:a.label,value:o.toString()}))),!t)return r;if(n!=null&&n.id_field){const a=vn(t,n.id_field);(a==null?void 0:a.length)>0&&(r.columnsFromData=Object.keys(a[0]).map(o=>({label:o,value:o})))}return r}function Zv(e){const{columnsFromConfig:t,columnsFromData:n}=Co(e.instance,e.sampleData),r=t.length>0?t:n,{value:a,set:o}=W(e.trigger.triggerData,"config"),{column:l}=x.defaults({},a,Jv),u=c=>{isNaN(+c)?o({column:c}):o({column:+c})};return i(s.Select,{clearable:!1,data:r,label:"Choose a column",value:l.toString(),onChange:u})}function Hv(e,t){return e?x.isNumber(e.column)?`Click cell of ${t[e.column].label}`:`Click cell of ${e.column}`:"Click cell content (click to config)"}function ex(e){const{columnsFromConfig:t}=Co(e.instance),{value:n}=W(e.trigger.triggerData,"config");return i(s.Text,{children:Hv(n,t)})}const tx=s.createStyles(e=>({root:{overflow:"auto",position:"relative","& .table-head-cell":{display:"flex",flexFlow:"row nowrap",alignItems:"center",whiteSpace:"nowrap","&.table-head-cell--sortable":{cursor:"pointer",userSelect:"none"}},"&.table-highlight-on-hover tr":{transition:"background-color 0.2s","&:hover":{backgroundColor:e.colorScheme==="dark"?e.colors.dark[5]:e.colors.gray[0]}}},thead:{background:e.colorScheme==="dark"?e.colors.dark[7]:e.white,position:"sticky",top:24,transform:"translateY(-1px)",zIndex:10},info_bar:{position:"sticky",top:0,left:0,right:0,zIndex:10,background:"white"}})),nx={tableLayout:"fixed","thead, tbody":{tr:{"th, td":{padding:"2px 10px",div:{overflow:"hidden",textOverflow:"ellipsis"},"&:first-of-type":{paddingLeft:2,paddingRight:2}}}}};function So(e,t,n){return Math.min(Math.max(e,t),n)}class rx{constructor(t){this.steps=t;const n=[],r=new Set;for(const a of t)r.has(a.to)||(n.push(a),r.add(a.to));if(n.sort((a,o)=>a.from-o.from),n.length<2)throw new Error("MultiStepValueMapper requires at least 2 steps");this.steps=n}getLinearFunction(t,n){const r=(n.to-t.to)/(n.from-t.from),a=t.to-r*t.from;return o=>r*o+a}getStepFunctionForValue(t){let n=x.findLastIndex(this.steps,r=>r.from<=t);return n=So(n,0,this.steps.length-2),this.getLinearFunction(this.steps[n],this.steps[n+1])}mapValue(t){return So(this.getStepFunctionForValue(t)(t),0,100)}}class ix{constructor(t,n,r,a,o){this.getColIndex=t,this.cell=n,this.triggers=r,this.interactionManager=a,this.colorManager=o}getClickHandler(){const t=this.getRelatedTrigger();if(t.length!==0)return()=>{const n={row_data:this.cell.row.original,row_index:this.cell.row.index,col_index:this.getColIndex(this.cell)};for(const r of t)this.interactionManager.runInteraction(r.id,n)}}getRelatedTrigger(){return this.triggers.filter(n=>n.schemaRef===ci.id).filter(n=>{const r=this.getColIndex(this.cell),a=x.get(this.cell.column.columnDef.meta,"value_field"),o=x.get(n.config,"column");return o==r||o==a})}isClickable(){return this.getRelatedTrigger().length>0}get columnConf(){return this.cell.column.columnDef.meta}get bgColor(){const t=this.columnConf.cellBackgroundColor;if(!t||t==="none")return;if(x.isString(t))return t;const n=+this.cell.getValue();if(isFinite(n)){const r=this.colorManager.decodeInterpolation(t.interpolation),o=new rx(t.steps).mapValue(n);return r==null?void 0:r.getColor(o)}}}const ax=s.createStyles((e,t)=>({content:{display:"flex",alignItems:"center",justifyContent:wo[t.align],".table-cell-text":{whiteSpace:"nowrap",cursor:t.clickable?"pointer":"default",textDecoration:t.clickable?"underline":"none"}}}));function sx(e){return e?ot(e).oklch()[0]>.7?"black":"white":"inherit"}function ox(e){const t=e.tableCellContext.bgColor;return{backgroundColor:t,color:sx(t)}}function Ft(e){const t=e.tableCellContext.isClickable(),n=ax({clickable:t,align:e.align});return i("div",{className:n.classes.content,style:{...ox(e)},children:i(s.Text,{className:"table-cell-text",onClick:e.tableCellContext.getClickHandler(),children:i("span",{title:e.children,children:e.children})})})}function lx(e){return i(Ft,{...e,children:e.value})}function ux(e){const t=H(e.value).format({average:!0,mantissa:2,trimMantissa:!0});return i(Ft,{...e,children:t})}function cx(e){const t=H(e.value).format({thousandSeparated:!0});return i(Ft,{...e,children:t})}function dx(e){const t=H(e.value).format({output:"percent",mantissa:3});return i(Ft,{...e,children:t})}function px(e){const t=e.value,n=e.func_content;if(!n)return i(Ft,{...e,children:t});const r=new Function(`return ${n}`)()({value:t});return i(Ft,{...e,children:r})}function hx(e){switch(e.type){case nt.string:return i(lx,{...e});case nt.eloc:return i(ux,{...e});case nt.number:return i(cx,{...e});case nt.percentage:return i(dx,{...e});case nt.custom:return i(px,{...e})}}const fx=e=>{const t=et(e),n=He(t.triggerManager,ci.id),{colorManager:r}=b.useContext(st);return b.useCallback(a=>new ix(e.getColIndex,a,n,t,r),[n,t,e.getColIndex])};function gx({data:e,width:t,height:n,conf:r,context:a,instance:o}){var ye,Ie;const{id_field:l,use_raw_columns:u,columns:c,...d}=r,{classes:f,cx:h}=tx(),g=b.useMemo(()=>{if(!l)return[];const fe=q(l);return e[fe.queryID]},[e,l]),m=b.useMemo(()=>u?!Array.isArray(g)||g.length===0?[]:Object.keys(g[0]).map(fe=>({id:fe,label:fe,value_field:fe,value_type:nt.string,align:"left",width:"",cellBackgroundColor:""})):c,[u,c,g]),C=fx({getColIndex:b.useCallback(fe=>m.indexOf(fe.column.columnDef.meta),[m]),vizManager:a.vizManager,instance:o}),w=b.useMemo(()=>{const fe=Xe.createColumnHelper();return m.map(ge=>{const Oe=q(ge.value_field);return fe.accessor(Oe.columnKey,{cell:Qe=>i(hx,{tableCellContext:C(Qe.cell),value:Qe.getValue(),type:ge.value_type,...ge}),header:ge.label,enableSorting:!0,meta:ge,size:typeof ge.width=="number"?ge.width:void 0,minSize:typeof ge.width=="number"?ge.width:void 0})})},[m,C]),[_,D]=b.useState([]),E=Xe.useReactTable({data:g,state:{sorting:_},onSortingChange:D,columns:w,getCoreRowModel:Xe.getCoreRowModel(),getSortedRowModel:Xe.getSortedRowModel()}),{rows:O}=E.getRowModel(),B=b.useRef(null),$=vu.useVirtual({parentRef:B,size:O.length,estimateSize:b.useCallback(()=>28,[]),overscan:20}),{virtualItems:A,totalSize:I}=$,F=A.length>0&&((ye=A==null?void 0:A[0])==null?void 0:ye.start)||0,U=A.length>0?I-(((Ie=A==null?void 0:A[A.length-1])==null?void 0:Ie.end)||0):0,Q=O.length,Z=Q>0,se=Z?n-22:n,le=Z?22:0;return!Array.isArray(g)||g.length===0?i(s.Text,{color:"gray",align:"center",children:"Empty Data"}):p("div",{ref:B,style:{height:n,width:t},"data-enable-scrollbar":!0,className:h(f.root,{"table-highlight-on-hover":r.highlightOnHover}),children:[Q>0&&i(s.Box,{className:f.info_bar,sx:{height:22},children:p(s.Text,{align:"right",pr:6,size:14,color:"dimmed",fw:"normal",children:["Total: ",Q]})}),p(s.Table,{sx:{...nx,maxHeight:se},...d,striped:r.striped,children:[i("thead",{className:f.thead,style:{top:le},children:E.getHeaderGroups().map(fe=>i("tr",{children:fe.headers.map(ve=>i("th",{style:{width:ve.getSize()},children:i(Uv,{header:ve,cx:h})},ve.id))},fe.id))}),p("tbody",{children:[F>0&&i("tr",{children:i("td",{style:{height:`${F}px`}})}),A.map(fe=>{const ve=O[fe.index];return i("tr",{children:ve.getVisibleCells().map(ge=>i("td",{children:Xe.flexRender(ge.column.columnDef.cell,ge.getContext())},ge.id))},ve.id)}),U>0&&i("tr",{children:i("td",{style:{height:`${U}px`}})})]})]})]})}function mx({context:e,instance:t}){const n=e.data,{height:r,width:a}=e.viewport,{value:o}=W(e.instanceData,"config");return o?o.id_field?i(gx,{data:n,width:a,height:r,conf:o,context:e,instance:t}):i(s.Text,{color:"red",align:"center",children:"ID Field is not set, can't render a table without it"}):null}const _o=s.createStyles(()=>({palette:{display:"flex",flexFlow:"row nowrap"},paletteItem:{".palette-value":{height:24,overflow:"visible",width:36},".palette-item":{width:"36px",height:36*.618,cursor:"pointer",transition:"transform 100ms ease-in-out","&:hover":{boxShadow:"0 0 0 2px var(--shadow-color)",borderRadius:2,transform:"scale(1.2)"}}}})),yx=[{from:0,to:0},{from:100,to:100}];class bx{constructor(){N(this,"steps",new Map);N(this,"interpolation");N(this,"onChange");re.makeAutoObservable(this,{steps:re.observable},{deep:!1}),re.reaction(()=>re.toJS(this.steps),()=>{this.notifyStepChange()})}setSteps(t){for(const n of t)this.steps.set(n.to,n.from)}notifyStepChange(){var t;(t=this.onChange)==null||t.call(this,Array.from(this.steps.entries()).map(([n,r])=>({to:n,from:r})).sort((n,r)=>n.to-r.to||n.from-r.from))}fromProps(t){t.steps.length<2?this.setSteps(yx):this.setSteps(t.steps),this.interpolation=t.interpolation,this.onChange=t.onChange}changeStep(t,n){t==null?this.steps.delete(n):this.steps.set(n,t)}getStepFromValue(t){return this.steps.get(t)}}function vx(e){const{onChange:t,color:n,index:r,value:a}=e,{classes:o}=_o(),[l,u]=b.useState(a),[c,{setTrue:d,setFalse:f}]=X.useBoolean(!1),h=r%2===1,g=h&&a!=null,m=!h&&a!=null,C=`map ${a} to color ${r}`,w=()=>{u(a),f()},_=()=>{f(),t==null||t(l)},D=H(a).format({average:!0});return p("div",{"data-testid":`palette-item-${r}`,className:o.paletteItem,children:[i(s.Text,{title:C,style:{opacity:g?1:0},color:"dimmed",size:"sm",className:"palette-value--up palette-value",children:D}),p(s.Popover,{width:200,trapFocus:!0,opened:c,onClose:f,children:[i(s.Popover.Target,{children:i("div",{"data-testid":"palette-item-target",className:"palette-item",onClick:d,style:{"--shadow-color":ot(n).alpha(.5).hex(),backgroundColor:n}})}),i(s.Popover.Dropdown,{children:p(s.Stack,{children:[i(s.NumberInput,{size:"xs",label:"Map a value to this color",value:l,onChange:u}),p(s.Group,{position:"right",children:[i(s.Button,{variant:"subtle",size:"xs",onClick:w,children:"Cancel"}),i(s.Button,{"data-testid":"palette-item-ok",size:"xs",onClick:_,children:"OK"})]})]})})]}),i(s.Text,{title:C,style:{opacity:m?1:0},color:"dimmed",size:"sm",className:"palette-value--bottom palette-value",children:D})]})}const xx=k.observer(({model:e})=>{const{classes:t}=_o(),n=x.range(0,13,1).map(r=>100/12*r).map(r=>[e.interpolation.getColor(r),r]);return i("div",{className:t.palette,children:n.map(([r,a],o)=>i(vx,{index:o,color:r,value:e.getStepFromValue(a),onChange:l=>e.changeStep(l,a)},r))})}),wx=k.observer(function(t){const n=X.useCreation(()=>new bx,[]);return b.useEffect(()=>{n.fromProps(t)}),n.interpolation==null?null:i(xx,{model:n})}),Cx=e=>{const{value:t,onChange:n,colorManager:r}=e,a=r.getColorInterpolations(),[o,l]=b.useState(t),u=r.decodeInterpolation(o.interpolation)||a[0],[c,{setTrue:d,setFalse:f}]=X.useBoolean(),h=a.map(_=>({label:_.displayName,value:r.encodeColor(_),group:_.category}));function g(_){_&&l(D=>({...D,interpolation:_}))}const m=()=>{f(),n==null||n(re.toJS(o))};function C(_){l(D=>({...D,steps:_}))}const w=()=>{f(),l(t)};return p(V,{children:[i(s.Button,{variant:"outline",onClick:d,children:u==null?void 0:u.displayName}),i(s.Modal,{size:508,title:"Setup color interpolation",opened:c,onClose:f,zIndex:320,children:c&&p(s.Stack,{"data-testid":"color-interpolation-modal",children:[i(s.Select,{label:"Color style",value:o.interpolation,data:h,onChange:g}),i(wx,{steps:o.steps,interpolation:u,onChange:C}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:w,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:m,children:"OK"})]})]})})]})},Sx=["static","interpolation","none"].map(e=>({label:x.capitalize(e),value:e})),_x=[{from:0,to:0},{from:100,to:100}];function ko(e){return e?x.isString(e)?e==="none"?"none":"static":"interpolation":"none"}function kx(e,t){var n;return ko(t)==="static"?t:(n=e.getStaticColors()[0])==null?void 0:n.value}function Tx(e,t){return x.isObject(t)?t:{steps:_x,interpolation:e.encodeColor(e.getColorInterpolations()[0])}}const Dx=b.forwardRef((e,t)=>{const{colorManager:n}=b.useContext(st),[r,a]=b.useState(ko(e.value)),[o,l]=b.useState(kx(n,e.value)),u=X.useLatest(o),[c,d]=b.useState(Tx(n,e.value)),f=X.useLatest(c),h=C=>{var w,_,D;a(C||"none"),C==="static"?(w=e.onChange)==null||w.call(e,u.current):C==="none"||!C?(_=e.onChange)==null||_.call(e,"none"):(D=e.onChange)==null||D.call(e,f.current)},g=C=>{var w;l(C),(w=e.onChange)==null||w.call(e,C)},m=C=>{var w;d(C),(w=e.onChange)==null||w.call(e,C)};return p(s.Stack,{align:"stretch",children:[i(s.Select,{label:"Cell background",value:r||"none",onChange:h,data:Sx}),r==="static"&&i(Pe,{value:o,onChange:g}),r==="interpolation"&&i(Cx,{colorManager:n,value:c,onChange:m})]})}),Mx={[nt.eloc]:"ELOC"},Ix=Object.values(nt).map(e=>({label:x.get(Mx,e,x.capitalize(e)),value:e})),Ex=b.forwardRef(({label:e,value:t,onChange:n,sx:r},a)=>i(s.Select,{ref:a,label:e,data:Ix,value:t,onChange:n,sx:r})),Ax=b.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=X.useBoolean(),[l,u]=b.useState(e),c=()=>{o(),t(l)},d=()=>{o(),u(e)},f=()=>{u(vo)};return b.useEffect(()=>{u(e)},[e]),p(V,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Custom Cell Content"}),i(s.Modal,{size:800,title:"Custom cell content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(s.Box,{sx:{position:"relative"},children:i(Ae,{height:"500px",defaultLanguage:"javascript",value:l,onChange:h=>u(h??""),theme:"vs-dark",options:{minimap:{enabled:!1}}})}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(T.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})}),zx=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],di=()=>i(s.Text,{color:"dimmed",size:12,children:"px"}),$x=({control:e,index:t,watch:n,remove:r,column:a})=>{const o=n(`columns.${t}.value_type`);return p(s.Stack,{my:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:`columns.${t}.label`,control:e,render:({field:l})=>i(s.TextInput,{label:"Label",required:!0,id:`col-label-${t}`,sx:{flex:1},...l})}),i(v.Controller,{name:`columns.${t}.value_field`,control:e,render:({field:l})=>i(R,{label:"Value Field",required:!0,...l})})]}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`columns.${t}.value_type`,control:e,render:({field:l})=>i(Ex,{label:"Value Type",sx:{flex:1},...l})}),o===nt.custom&&i(v.Controller,{name:`columns.${t}.func_content`,control:e,render:({field:l})=>i(Ax,{value:l.value??vo,onChange:u=>l.onChange(u??"")})})]}),i(s.Divider,{mb:-10,variant:"dashed",label:"Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(s.NumberInput,{hideControls:!0,label:"Min Width",rightSection:i(di,{}),disabled:!0}),i(v.Controller,{name:`columns.${t}.width`,control:e,render:({field:l})=>i(s.NumberInput,{hideControls:!0,label:"Width",rightSection:i(di,{}),...l})}),i(s.NumberInput,{hideControls:!0,label:"Max Width",rightSection:i(di,{}),disabled:!0})]}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`columns.${t}.align`,control:e,render:({field:l})=>i(s.Select,{label:"Alignment",data:zx,...l})})}),i(v.Controller,{name:`columns.${t}.cellBackgroundColor`,control:e,render:({field:l})=>i(Dx,{...l})}),i(s.Divider,{mb:4,mt:12,variant:"dashed"}),i(s.Button,{leftIcon:i(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(t),children:"Delete this column"})]})},Lx=({control:e,watch:t})=>{const{fields:n,append:r,remove:a,update:o}=v.useFieldArray({control:e,name:"columns"}),l=()=>{const c=Ee.randomId();r({id:c,label:c,align:"center",value_field:"",value_type:nt.string,width:""})};t("columns");const u=t("use_raw_columns");return p(V,{children:[i(v.Controller,{name:"use_raw_columns",control:e,render:({field:c})=>i(s.Switch,{mt:20,mb:20,label:"Use Original Data Columns",checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})}),!u&&i(s.Stack,{children:p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[n.map((c,d)=>i(s.Tabs.Tab,{value:d.toString(),children:d+1},c.id)),i(s.Tabs.Tab,{onClick:l,value:"add",children:i(T.Plus,{size:18,color:"#228be6"})})]}),n.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i($x,{control:e,watch:t,index:d,column:c,remove:a},d)},c.id))]})})]})};function Ox({control:e,watch:t}){return t(["horizontalSpacing","verticalSpacing","fontSize","striped","highlightOnHover"]),p(s.Stack,{spacing:"xs",children:[p(s.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:[i(v.Controller,{name:"horizontalSpacing",control:e,render:({field:n})=>i(s.TextInput,{label:"Horizontal Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"verticalSpacing",control:e,render:({field:n})=>i(s.TextInput,{label:"Vertical Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})})]}),i(s.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:i(v.Controller,{name:"fontSize",control:e,render:({field:n})=>i(s.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})})}),p(s.Group,{position:"apart",grow:!0,children:[i(v.Controller,{name:"striped",control:e,render:({field:n})=>i(s.Switch,{label:"Striped",checked:n.value,onChange:r=>n.onChange(r.currentTarget.checked)})}),i(v.Controller,{name:"highlightOnHover",control:e,render:({field:n})=>i(s.Switch,{label:"Highlight on hover",checked:n.value,onChange:r=>n.onChange(r.currentTarget.checked)})})]})]})}function Px({columns:e,...t}){return{...t,columns:e.map(({id:n,...r})=>({id:n??Ee.randomId(),...r}))}}function Bx({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),r=b.useMemo(()=>x.defaultsDeep({},t,xo),[t]),a=b.useMemo(()=>Px(r),[r]);b.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});b.useEffect(()=>{d(a)},[a]);const f=c(),h=b.useMemo(()=>!x.isEqual(f,r),[f,r]);return u(["id_field"]),p("form",{onSubmit:l(n),children:[p(s.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Table Config"}),i(s.ActionIcon,{type:"submit","aria-label":"save config",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(T.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Columns",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Columns",children:"Columns"}),i(s.Tabs.Tab,{value:"Style",children:"Style"})]}),p(s.Tabs.Panel,{value:"Columns",children:[i(v.Controller,{name:"id_field",control:o,render:({field:g})=>i(R,{label:"ID Field",required:!0,...g})}),i(s.Divider,{mt:20,mb:10,variant:"dashed"}),i(Lx,{control:o,watch:u})]}),i(s.Tabs.Panel,{value:"Style",children:i(Ox,{control:o,watch:u})})]})]})}function Vx(e){const{columns:t,...n}=e;return{...e,columns:t.map(r=>({...r,align:r.align??"left"}))}}function Nx(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{id_field:a,columns:o,...l}=e;return{...l,id_field:r(a),columns:o.map(u=>({...u,value_field:r(u.value_field)}))}}catch(n){throw console.error("[Migration failed]",n),n}}function qx(e){const{columns:t,...n}=e;return{...n,columns:t.map(r=>({...r,align:r.align??"left",cellBackgroundColor:r.cellBackgroundColor??"",width:r.width??""}))}}class Fx extends be{constructor(){super(...arguments);N(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{columns:r,...a}=n.config;return{...n,version:2,config:{...a,columns:r.map(({id:o,...l})=>({id:o??Ee.randomId(),...l}))}}}),this.version(3,n=>({...n,version:3,config:Vx(n.config)})),this.version(4,(n,r)=>({...n,version:4,config:Nx(n.config,r)})),this.version(5,n=>({...n,version:5,config:qx(n.config)}))}}const pi={createConfig(){return{version:5,config:x.cloneDeep(xo)}},displayName:"Table",displayGroup:"Others",migrator:new Fx,name:"table",viewRender:mx,configRender:Bx,triggers:[ci]},To=["function text({ data, variables, filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
296
+ `),hi={func_content:To,horizontal_align:"left",font_size:"14px",font_weight:"normal"},Gx=k.observer(({context:e})=>{const t=Me(),{value:n=hi}=W(e.instanceData,"config"),{variables:r}=e,a=e.data,{func_content:o,horizontal_align:l,font_size:u,font_weight:c}=n,d=b.useMemo(()=>r.reduce((h,g)=>{const m=vt(g,a);return h[g.name]=tt(g,m),h},{}),[r,a]),f=b.useMemo(()=>new Function(`return ${o}`)()({data:a,variables:d,filters:t.payloadForSQL.filters,context:t.payloadForSQL.context}),[o,a,d,t.payloadForSQL]);return i(s.Text,{align:l,weight:c,sx:{fontSize:u},children:f})}),Wx=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{sx:{position:"relative"},children:i(Ae,{height:"500px",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},Rx=b.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=X.useBoolean(),[l,u]=b.useState(e),c=()=>{o(),t(l)},d=()=>{o(),u(e)},f=()=>{u(To)};return b.useEffect(()=>{u(e)},[e]),p(V,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Edit Content"}),i(s.Modal,{size:800,title:"Text content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(Wx,{value:l,onChange:u}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(T.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})}),jx=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}];function Yx({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),r=b.useMemo(()=>x.defaultsDeep({},t,hi),[t]),a=b.useMemo(()=>{const{func_content:g,horizontal_align:m,font_size:C,font_weight:w}=r;return{func_content:g,horizontal_align:m,font_size:C,font_weight:w}},[r]);b.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});b.useEffect(()=>{d(a)},[a]),u(["func_content","horizontal_align","font_size","font_weight"]);const f=c(),h=b.useMemo(()=>!x.isEqual(f,r),[f,r]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{weight:500,children:"Configurations"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(T.DeviceFloppy,{size:20})})]}),p(s.Stack,{spacing:10,children:[i(v.Controller,{name:"func_content",control:o,render:({field:g})=>i(Rx,{...g})}),i(s.Divider,{mt:10,mb:-10,variant:"dashed",label:"Style",labelPosition:"center"}),i(v.Controller,{name:"horizontal_align",control:o,render:({field:g})=>i(s.Select,{label:"Horizontal Alignment",data:jx,...g})}),i(v.Controller,{name:"font_size",control:o,render:({field:g})=>i(s.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},...g})}),i(s.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:i(v.Controller,{name:"font_weight",control:o,render:({field:g})=>i(ls,{label:"Font Weight",...g})})})]})]})})}class Qx extends be{constructor(){super(...arguments);N(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const Kx={displayName:"Text",displayGroup:"Others",migrator:new Qx,name:"text",viewRender:Gx,configRender:Yx,createConfig(){return{version:1,config:x.cloneDeep(hi)}}},Ux=()=>p("svg",{width:"64",height:"64",viewBox:"0 0 64 64",fill:"none",children:[i("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M22.49 27.79H14.47C13.55 27.79 12.81 28.53 12.81 29.45C12.81 30.37 13.55 31.11 14.47 31.11H22.49C23.41 31.11 24.15 30.37 24.15 29.45C24.15 28.54 23.41 27.79 22.49 27.79ZM34.32 31.28C35.22 31.32 35.7 31.82 35.74 32.76C35.78 33.54 35.37 34.3 34.51 35.04C33.52 35.9 33.03 36.95 33.03 38.19V38.81H34.82V38.25C34.78 37.59 35.07 37.02 35.68 36.52C37.12 35.41 37.82 34.15 37.78 32.75C37.66 30.53 36.5 29.35 34.32 29.23C32.3 29.23 31.05 30.46 30.55 32.93L32.53 33.55C32.82 32.04 33.42 31.28 34.32 31.28ZM35 39.93H32.84V42.21H35V39.93ZM14.83 36.42H18.54C19.46 36.42 20.2 37.17 20.2 38.08C20.2 39 19.46 39.74 18.54 39.74H10.52C9.6 39.74 8.86 39 8.86 38.08C8.86 37.61 9.06 37.19 9.37 36.89H5.66C4.74 36.89 4 36.15 4 35.23C4 34.31 4.74 33.57 5.66 33.57H13.68C14.6 33.57 15.34 34.31 15.34 35.23C15.34 35.7 15.14 36.12 14.83 36.42ZM50.94 36.85H58.74C59.66 36.85 60.4 37.59 60.41 38.51C60.41 39.43 59.67 40.17 58.75 40.17H54.26C54.56 40.47 54.74 40.88 54.74 41.34C54.74 42.26 54 43 53.08 43H50.94V36.85Z",fill:"#B8C0CC"}),i("path",{d:"M18.39 32.28H16.51V35.02H18.39V32.28Z",fill:"#9399A5"}),i("path",{d:"M46.87 15H20.69C18.38 15 16.5 16.88 16.5 19.19V26.22H18.38V23.45H49.18V47.68H18.38V41.07H16.5V49.55H51.05V19.19C51.06 16.88 49.18 15 46.87 15ZM39.46 20.73C38.81 20.73 38.29 20.2 38.29 19.56C38.29 18.92 38.82 18.39 39.46 18.39C40.11 18.39 40.63 18.92 40.63 19.56C40.63 20.2 40.11 20.73 39.46 20.73ZM43.22 20.73C42.57 20.73 42.05 20.2 42.05 19.56C42.05 18.92 42.58 18.39 43.22 18.39C43.87 18.39 44.39 18.92 44.39 19.56C44.39 20.2 43.87 20.73 43.22 20.73ZM46.97 20.73C46.32 20.73 45.8 20.2 45.8 19.56C45.8 18.92 46.33 18.39 46.97 18.39C47.62 18.39 48.14 18.92 48.14 19.56C48.14 20.2 47.62 20.73 46.97 20.73Z",fill:"#9399A5"})]});function Do(e,t){const n=x.get(e,t,"");if(n)throw new Error(n)}async function Xx(e,t,n,r={}){const a={"X-Requested-With":"XMLHttpRequest","Content-Type":r.string?"application/x-www-form-urlencoded":"application/json",...r.headers},o={baseURL:e,method:"POST",url:t,params:r.params,headers:a};return o.data=r.string?JSON.stringify(n):n,ht(o).then(l=>l.data).catch(l=>Promise.reject(l))}const Jx=({conf:e,panelData:t})=>async()=>{const{expertSystemURL:n,path:r,goal:a,question:o}=e;if(!r||!a||!o)return;const l=Zu(t);if(!l)return;const u={dashboard:a,panel:o,data:l};try{const c=n.startsWith("http")?n:window.location.origin;return await Xx(c,`/expert/v3/devtable/${r}`,u,{})}catch(c){throw Do(c,"response.data.detail"),Do(c,"response.data.error"),console.error(c),c}},fi={expertSystemURL:"",path:"",goal:"",question:""},gi={height:"100%",overflowY:"auto",...Rr},Mo=({message:e})=>i(s.Box,{sx:gi,children:i("div",{dangerouslySetInnerHTML:{__html:e},style:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45"}})}),Zx=({error:e,width:t,height:n})=>{const r=e.message;if(r.startsWith("<"))return i(Mo,{message:r});const o=n-25-20-30;return i(s.Center,{sx:{width:"100%",height:o},children:p(s.Stack,{align:"center",spacing:20,children:[i(Ux,{}),i(Mo,{message:r})]})})};function Hx({context:e}){const{value:t}=W(e.instanceData,"config"),n=b.useMemo(()=>x.defaultsDeep({},t,fi),[t]),{width:r,height:a}=e.viewport,o=e.data,{data:l,error:u,loading:c}=X.useRequest(Jx({conf:n,panelData:o}),{refreshDeps:[o,n]});return!r||!a||!n?null:c?i(s.Box,{sx:{position:"relative",height:a},children:i(s.LoadingOverlay,{visible:!0})}):u?i(s.Box,{sx:gi,"data-enable-scrollbar":!0,children:i(Zx,{error:u,width:r,height:a})}):!l||!Array.isArray(l.replies)||l.replies.length===0?null:i(s.Box,{sx:gi,"data-enable-scrollbar":!0,children:l.replies.map((d,f)=>i("div",{dangerouslySetInnerHTML:{__html:d.interpretation.html}},f))})}function e0({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),r=b.useMemo(()=>x.defaultsDeep({},t,fi),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});b.useEffect(()=>{c(r)},[r]),l(["expertSystemURL","goal","path","question"]);const d=u(),f=b.useMemo(()=>!x.isEqual(d,r),[d,r]);return i("form",{onSubmit:o(n),children:p(s.Stack,{children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:"expertSystemURL",control:a,render:({field:h})=>i(s.TextInput,{label:"Expert System URL",...h})}),i(v.Controller,{name:"path",control:a,render:({field:h})=>i(s.TextInput,{label:"Path",required:!0,...h})})]}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:"goal",control:a,render:({field:h})=>i(s.TextInput,{label:"Goal",required:!0,...h})}),i(v.Controller,{name:"question",control:a,render:({field:h})=>i(s.TextInput,{label:"Question",required:!0,...h})})]}),i(s.Divider,{variant:"dashed",mt:16,mb:8}),i(s.Button,{type:"submit",variant:"filled",color:"blue",leftIcon:i(T.DeviceFloppy,{size:20}),disabled:!f,sx:{alignSelf:"flex-end"},children:"Submit Changes"})]})})}class t0 extends be{constructor(){super(...arguments);N(this,"VERSION",1)}configVersions(){this.version(1,n=>({version:1,config:n}))}}const n0={displayName:"Merico GQM",displayGroup:"Merico suite",migrator:new t0,name:"mericoGQM",viewRender:Hx,configRender:e0,createConfig(){return{version:1,config:x.cloneDeep(fi)}}};function r0(e,t,n){if(!e)return n[0];try{return[t,j(t).add(1,"year").subtract(1,"day").valueOf()]}catch(r){return console.error(r),n[0]}}function i0(e,t,n){const r=r0(e,t,n);return{top:50,left:25,right:5,cellSize:["auto",13],range:r,itemStyle:{borderColor:"#eee"},splitLine:{show:!0},dayLabel:{firstDay:1},monthLabel:{position:"end"},yearLabel:{show:!0}}}function a0(e){return{heat_block:function(r){if(!e.heat_block.value_formatter)return r;try{return H(r).format(e.heat_block.value_formatter)}catch(a){return console.error(a),r}}}}function s0(e,t){return{show:!e,selectedMode:"single",top:5,right:5,data:t.map(n=>({name:n,icon:"circle"}))}}function o0(e,t,n,r){const{calendar:a,heat_block:o}=e,l=q(a.data_key),u=q(o.data_key);return t?{type:"heatmap",name:"heatmap",coordinateSystem:"calendar",calendarIndex:0,data:r[l.queryID].map(c=>[x.get(c,l.columnKey),x.get(c,u.columnKey)])}:Object.entries(n).map(([c,d])=>({type:"heatmap",name:c,coordinateSystem:"calendar",calendarIndex:0,data:d.map(f=>[x.get(f,l.columnKey),x.get(f,u.columnKey)])}))}const l0=e=>{try{return H(e).format({trimMantissa:!0,mantissa:2})}catch{return e}};function u0({conf:e,valueFormatters:t,dataDict:n,params:r}){const{value:a}=r,[o,l]=a,c=[{label:e.heat_block.name,value:t.heat_block(l),style:{label:"",value:""}}],d=n[o];return d&&e.tooltip.metrics.forEach(f=>{const h=q(f.data_key);c.push({label:f.name,value:l0(x.get(d,h.columnKey,"")),style:{label:"",value:""}})}),c}function c0(e,t,n){const r=q(e.calendar.data_key),a=x.keyBy(t[r.queryID],r.columnKey);return{confine:!0,formatter:function(o){const u=u0({conf:e,valueFormatters:n,dataDict:a,params:o}).map(f=>`
361
297
  <tr>
362
298
  <th style="text-align: right;">
363
299
  <div style="${f.style.label}">${f.label}</div>
@@ -383,13 +319,13 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
383
319
  </thead>
384
320
  <tbody>${u.join("")}</tbody>
385
321
  </table>
386
- `}}}function lx(t,e,n){const r=En(t.heat_block.min,n),a=En(t.heat_block.max,n);return{min:r,max:a,calculable:!0,orient:"horizontal",left:e?"center":5,top:0,itemWidth:15}}const ux={tooltip:{confine:!0},grid:{containLabel:!0}},cx=t=>R(t).get("year");function dx(t,e){const n=q(t.calendar.data_key),r=e[n.queryID],a=x.groupBy(r,d=>cx(d[n.columnKey])),o=Object.keys(a),l=r.map(d=>R(d[n.columnKey]).valueOf()),u=x.min(l),c=x.max(l);return{minDate:u??0,maxDate:c??0,dateSpan:R(c).diff(u,"day"),dataByYear:a,years:o}}function px(t,e,n){const r=n.reduce((h,g)=>{const m=yt(g,e);return h[g.name]=et(g,m),h},{}),a=nx(t),{dateSpan:o,minDate:l,dataByYear:u,years:c}=dx(t,e),d=o<=366,f={calendar:tx(d,l,c),series:ix(t,d,u,e),tooltip:ox(t,e,a),visualMap:lx(t,d,r),legend:rx(d,c)};return x.defaultsDeep({},f,ux)}function hx(t){return i(V,{})}function fx(t){return i(s.Text,{children:"Click heat block"})}const No={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:fx,configRender:hx,payload:[{name:"seriesType",description:"'heatmap'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]},di={calendar:{data_key:"",locale:"EN"},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:$e},tooltip:{metrics:[]}};le.use([G.DataZoomComponent,pe.BarChart,pe.LineChart,pe.HeatmapChart,G.CalendarComponent,G.GridComponent,G.LegendComponent,G.TooltipComponent,G.VisualMapComponent,Ve.CanvasRenderer]);function gx({name:t},e){const n=e.getOption();n.calendar.forEach(r=>{r.range=t}),e.setOption(n)}function mx({conf:t,data:e,width:n,height:r,interactionManager:a,variables:o}){const l=bt(e,t.calendar.data_key),u=He(a.triggerManager,No.id),c=y.useCallback(h=>{const[g,m]=h.value,w=x.get(l,g,{error:"rowData is not found"});u.forEach(C=>{a.runInteraction(C.id,{...h,rowData:w})})},[l,u,a]),d=y.useMemo(()=>({click:c,legendselectchanged:gx}),[c]),f=y.useMemo(()=>px(t,e,o),[t,e]);return!n||!r?null:i(Ne,{echarts:le,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,opts:{locale:t.calendar.locale},theme:"merico-light"})}function yx({context:t,instance:e}){const n=tt({vizManager:t.vizManager,instance:e}),{value:r}=W(t.instanceData,"config"),{variables:a}=t,o=y.useMemo(()=>x.defaults({},r,di),[r]),l=t.data,{width:u,height:c}=t.viewport;return!o.calendar.data_key||!o.heat_block.data_key?null:i(s.Box,{children:i(mx,{variables:a,width:u,height:c,data:l,conf:o,interactionManager:n})})}function bx({control:t,watch:e}){return e(["heat_block"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.data_key",control:t,render:({field:n})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"heat_block.name",control:t,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.min",control:t,render:({field:n})=>i(In,{label:"Min Value",...n})}),i(v.Controller,{name:"heat_block.max",control:t,render:({field:n})=>i(In,{label:"Max Value",...n})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),i(v.Controller,{name:"heat_block.value_formatter",control:t,render:({field:n})=>i(Re,{...n})})]})}const vx=({control:t,index:e,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${e}.data_key`,control:t,render:({field:r})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),xx=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"tooltip.metrics"}),o=e("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=e("tooltip.metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(V,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(D.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),i(s.Divider,{variant:"dashed",my:10}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(vx,{control:t,index:g,remove:a},h.id)},h.id))]})]})};function wx({control:t,watch:e}){return i(xx,{control:t,watch:e})}const Cx=[{label:"Chinese",value:"ZH"},{label:"English",value:"EN"}];function Sx({control:t,watch:e}){return e(["calendar"]),p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"calendar.data_key",control:t,render:({field:n})=>i(j,{label:"Data Field",required:!0,sx:{flex:1},...n})})}),i(v.Controller,{name:"calendar.locale",control:t,render:({field:n})=>i(s.Select,{label:"Language",required:!0,data:Cx,sx:{flex:1},...n})})]})}function _x({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,di),[e]),a=y.useMemo(()=>x.cloneDeep(r),[r]);y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Calendar Heatmap Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Calendar",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Calendar",children:"Calendar"}),i(s.Tabs.Tab,{value:"Heat Block",children:"Heat Block"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"})]}),i(s.Tabs.Panel,{value:"Calendar",children:i(Sx,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Heat Block",children:i(bx,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(wx,{control:o,watch:u})})]})]})})}function kx(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{calendar:a,heat_block:o,tooltip:l,...u}=t;return{...u,calendar:{...a,data_key:r(a.data_key)},heat_block:{...o,data_key:r(o.data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:r(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function Tx(t){const{heat_block:e}=t;let{min:n,max:r}=e;return typeof n!="number"&&(n=0),typeof r!="number"&&(r=100),{...t,heat_block:{...e,min:{type:"static",value:n},max:{type:"static",value:r}}}}class Dx extends ve{constructor(){super(...arguments);N(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>({...n,version:2,config:kx(n.config,r)})),this.version(3,n=>({...n,version:3,config:Tx(n.config)}))}}const Mx={displayName:"Heatmap(Calendar)",displayGroup:"ECharts-based charts",migrator:new Dx,name:"calendarHeatmap",viewRender:yx,configRender:_x,createConfig:()=>({version:3,config:di}),triggers:[No]},pi={x_axes:[{id:"initial-x",min:"",max:"",name:"X Axis",data_key:"",position:"bottom",label_formatter:$e,show:!0}],y_axis:{name:"Y Axis",data_key:"",axisLabel:{formatter:{...nt},overflow:Ze},nameAlignment:"center"},series:[],tooltip:{metrics:[]},reference_lines:[]};function Ix(){const t=new Date().getTime().toString();return{id:t,min:"",max:"",name:t,data_key:"",position:"bottom",label_formatter:$e,show:!0}}function Ex(){const t=new Date().getTime().toString();return{id:t,type:"bar",name:t,stack:"",color:"",barGap:"0%",data_key:"",barWidth:"",barMinWidth:"1",barMaxWidth:"10",group_by_key:"",hide_in_legend:!1,invisible:!1,label_position:"right",aggregation_on_value:Pt,xAxisIndex:"0"}}function Ax(){const t=new Date().getTime().toString();return{id:t,name:t,template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,xAxisIndex:"0"}}function zx(t){const e=t.x_axes.some(o=>o.position==="top"&&!!o.name&&o.show);let n=0;e&&(n+=15);const r=t.x_axes.some(o=>o.position==="bottom"&&!!o.name&&o.show);let a=0;return r&&(a+=15),t.series.some(o=>!o.hide_in_legend)&&(a+=20),{top:n,right:5,bottom:a,left:5,containLabel:!0}}function $x(t){switch(t){case"bar":return"roundRect";case"scatter":return"circle"}}function Lx(t){const e={show:!0,bottom:0,left:"center",type:"scroll"};return e.data=t.filter(n=>!n.hide_in_legend).map(({name:n,type:r})=>({name:n,icon:$x(r)})),e}function Ox(t,e,n,r){return t.map(a=>{const o=a.orientation==="horizontal",l=o?"yAxis":"xAxis",u=o?"insideEndTop":"end";return{name:a.name,type:"line",hide_in_legend:!a.show_in_legend,xAxisIndex:a.xAxisIndex,data:[],lineStyle:a.lineStyle,markLine:{data:[{name:a.name,[l]:Number(n[a.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:a.lineStyle,label:{formatter:function(){return a.template?Tn(a.template,e,r):""},position:u}}}})}function Xn(t,e,n){const r=lt(t,e),a=lt(t,n);return x.zip(a,r)}function Px(t,e,n,r){const a=Xn(e,n,r);return x.unionBy(a,t,0)}function Bx({dataTemplate:t,data:e,name_data_key:n,value_data_key:r,valueTypedXAxis:a}){return a?Px(t,e,n,r):Xn(e,n,r)}function Vx({dataTemplate:t,data:e,aggregation_on_value:n,name_data_key:r,value_data_key:a,valueTypedXAxis:o}){if(!n||n.type==="none")return Bx({dataTemplate:t,data:e,name_data_key:r,value_data_key:a,valueTypedXAxis:o});const l=Xn(e,r,a),u=x.groupBy(l,"0");return t.map(([d])=>{const h=u[d].map(m=>m[1]),g=Tr(h,n);return[d,g]})}function Nx({group_by_key:t,data:e,value_data_key:n,name_data_key:r}){const{queryID:a,columnKey:o}=q(t),l=x.groupBy(e[a],o);return Object.entries(l).forEach(([u,c])=>{l[u]=Xn({[a]:c},r,n)}),l}function qx({y_axis:t},{data_key:e,xAxisIndex:n,label_position:r,name:a,group_by_key:o,aggregation_on_value:l,stack:u,color:c,hide_in_legend:d,invisible:f,id:h,...g},m,w,C,_,T){const I={label:{show:!!r,position:r,formatter:T[n??"default"]},name:a,yAxisId:"main-y-axis",xAxisIndex:n,stack:u,color:f?"transparent":c,hide_in_legend:d,labelLayout:{hideOverlap:!0},emphasis:{disabled:!0},...g};if(!o||o===t.data_key)return I.data=Vx({dataTemplate:m,data:C,aggregation_on_value:l,name_data_key:t.data_key,value_data_key:e,valueTypedXAxis:w}),I;const O=Nx({group_by_key:o,data:C,name_data_key:t.data_key,value_data_key:e});return Object.entries(O).map(([B,$])=>{const A=x.cloneDeep(I);return A.name=B,A.color=void 0,A.data=$,A})}function Fx(t,e,n,r,a,o,l){const u=e.map(d=>[d,0]);return t.series.map(d=>qx(t,d,u,n,r,l,a)).flat().concat(Ox(t.reference_lines,o,l,r))}function Gx(t,e){const n=t.find(u=>u.axisDim==="y"&&u.axisId==="main-y-axis");if(!n)return"";const{name:r,axisType:a,axisValue:o,axisIndex:l}=n;return a==="yAxis.category"?r:Ot(e.y_axis.axisLabel.formatter)(o,l)}function Wx(t,e,n){const r=e.reduce((a,{xAxisIndex:o,name:l})=>(a[l]=o,a),{});return{trigger:"axis",axisPointer:{type:"shadow"},formatter:function(a){const o=Array.isArray(a)?a:[a];if(o.length===0)return"";const l=o.map(({seriesName:d,marker:f,value:h})=>{if(Array.isArray(h)&&h.length===2&&(h=h[0]),!d)return h;const g=r[d],m=n[g]??n.default;return`
322
+ `}}}function d0(e,t,n){const r=An(e.heat_block.min,n),a=An(e.heat_block.max,n);return{min:r,max:a,calculable:!0,orient:"horizontal",left:t?"center":5,top:0,itemWidth:15}}const p0={tooltip:{confine:!0},grid:{containLabel:!0}},h0=e=>j(e).get("year");function f0(e,t){const n=q(e.calendar.data_key),r=t[n.queryID],a=x.groupBy(r,d=>h0(d[n.columnKey])),o=Object.keys(a),l=r.map(d=>j(d[n.columnKey]).valueOf()),u=x.min(l),c=x.max(l);return{minDate:u??0,maxDate:c??0,dateSpan:j(c).diff(u,"day"),dataByYear:a,years:o}}function g0(e,t,n){const r=n.reduce((h,g)=>{const m=vt(g,t);return h[g.name]=tt(g,m),h},{}),a=a0(e),{dateSpan:o,minDate:l,dataByYear:u,years:c}=f0(e,t),d=o<=366,f={calendar:i0(d,l,c),series:o0(e,d,u,t),tooltip:c0(e,t,a),visualMap:d0(e,d,r),legend:s0(d,c)};return x.defaultsDeep({},f,p0)}function m0(e){return i(V,{})}function y0(e){return i(s.Text,{children:"Click heat block"})}const Io={id:"builtin:echarts:click-heatmap:heat-block",displayName:"Click Heat Block",nameRender:y0,configRender:m0,payload:[{name:"seriesType",description:"'heatmap'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]},mi={calendar:{data_key:"",locale:"EN"},heat_block:{min:{type:"static",value:0},max:{type:"static",value:100},name:"Value",data_key:"",value_formatter:$e},tooltip:{metrics:[]}};oe.use([G.DataZoomComponent,pe.BarChart,pe.LineChart,pe.HeatmapChart,G.CalendarComponent,G.GridComponent,G.LegendComponent,G.TooltipComponent,G.VisualMapComponent,Ve.CanvasRenderer]);function b0({name:e},t){const n=t.getOption();n.calendar.forEach(r=>{r.range=e}),t.setOption(n)}function v0({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=bt(t,e.calendar.data_key),u=He(a.triggerManager,Io.id),c=b.useCallback(h=>{const[g,m]=h.value,C=x.get(l,g,{error:"rowData is not found"});u.forEach(w=>{a.runInteraction(w.id,{...h,rowData:C})})},[l,u,a]),d=b.useMemo(()=>({click:c,legendselectchanged:b0}),[c]),f=b.useMemo(()=>g0(e,t,o),[e,t]);return!n||!r?null:i(Ne,{echarts:oe,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,opts:{locale:e.calendar.locale},theme:"merico-light"})}function x0({context:e,instance:t}){const n=et({vizManager:e.vizManager,instance:t}),{value:r}=W(e.instanceData,"config"),{variables:a}=e,o=b.useMemo(()=>x.defaults({},r,mi),[r]),l=e.data,{width:u,height:c}=e.viewport;return!o.calendar.data_key||!o.heat_block.data_key?null:i(s.Box,{children:i(v0,{variables:a,width:u,height:c,data:l,conf:o,interactionManager:n})})}function w0({control:e,watch:t}){return t(["heat_block"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.data_key",control:e,render:({field:n})=>i(R,{label:"Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"heat_block.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Name",sx:{flex:1},...n})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"heat_block.min",control:e,render:({field:n})=>i(En,{label:"Min Value",...n})}),i(v.Controller,{name:"heat_block.max",control:e,render:({field:n})=>i(En,{label:"Max Value",...n})})]}),i(s.Divider,{mb:-15,variant:"dashed",label:"Value Format",labelPosition:"center"}),i(v.Controller,{name:"heat_block.value_formatter",control:e,render:({field:n})=>i(je,{...n})})]})}const C0=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>i(R,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),S0=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,f]=b.useState(()=>c??null);return b.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(V,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(T.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Configure additional metrics to show in tooltip"})]}),i(s.Divider,{variant:"dashed",my:10}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(T.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(C0,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function _0({control:e,watch:t}){return i(S0,{control:e,watch:t})}const k0=[{label:"Chinese",value:"ZH"},{label:"English",value:"EN"}];function T0({control:e,watch:t}){return t(["calendar"]),p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"calendar.data_key",control:e,render:({field:n})=>i(R,{label:"Data Field",required:!0,sx:{flex:1},...n})})}),i(v.Controller,{name:"calendar.locale",control:e,render:({field:n})=>i(s.Select,{label:"Language",required:!0,data:k0,sx:{flex:1},...n})})]})}function D0({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),r=b.useMemo(()=>x.defaultsDeep({},t,mi),[t]),a=b.useMemo(()=>x.cloneDeep(r),[r]);b.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});b.useEffect(()=>{d(a)},[a]);const f=c(),h=b.useMemo(()=>!x.isEqual(f,r),[f,r]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Calendar Heatmap Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(T.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Calendar",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Calendar",children:"Calendar"}),i(s.Tabs.Tab,{value:"Heat Block",children:"Heat Block"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"})]}),i(s.Tabs.Panel,{value:"Calendar",children:i(T0,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Heat Block",children:i(w0,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(_0,{control:o,watch:u})})]})]})})}function M0(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{calendar:a,heat_block:o,tooltip:l,...u}=e;return{...u,calendar:{...a,data_key:r(a.data_key)},heat_block:{...o,data_key:r(o.data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:r(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function I0(e){const{heat_block:t}=e;let{min:n,max:r}=t;return typeof n!="number"&&(n=0),typeof r!="number"&&(r=100),{...e,heat_block:{...t,min:{type:"static",value:n},max:{type:"static",value:r}}}}class E0 extends be{constructor(){super(...arguments);N(this,"VERSION",3)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>({...n,version:2,config:M0(n.config,r)})),this.version(3,n=>({...n,version:3,config:I0(n.config)}))}}const A0={displayName:"Heatmap(Calendar)",displayGroup:"ECharts-based charts",migrator:new E0,name:"calendarHeatmap",viewRender:x0,configRender:D0,createConfig:()=>({version:3,config:mi}),triggers:[Io]},yi={x_axes:[{id:"initial-x",min:"",max:"",name:"X Axis",data_key:"",position:"bottom",label_formatter:$e,show:!0}],y_axis:{name:"Y Axis",data_key:"",axisLabel:{formatter:{...rt},overflow:Ze},nameAlignment:"center"},series:[],tooltip:{metrics:[]},reference_lines:[]};function z0(){const e=new Date().getTime().toString();return{id:e,min:"",max:"",name:e,data_key:"",position:"bottom",label_formatter:$e,show:!0}}function $0(){const e=new Date().getTime().toString();return{id:e,type:"bar",name:e,stack:"",color:"",barGap:"0%",data_key:"",barWidth:"",barMinWidth:"1",barMaxWidth:"10",group_by_key:"",hide_in_legend:!1,invisible:!1,label_position:"right",aggregation_on_value:Bt,xAxisIndex:"0"}}function L0(){const e=new Date().getTime().toString();return{id:e,name:e,template:"",variable_key:"",orientation:"horizontal",lineStyle:{type:"dashed",width:1,color:"#868E96"},show_in_legend:!1,xAxisIndex:"0"}}function O0(e){const t=e.x_axes.some(o=>o.position==="top"&&!!o.name&&o.show);let n=0;t&&(n+=15);const r=e.x_axes.some(o=>o.position==="bottom"&&!!o.name&&o.show);let a=0;return r&&(a+=15),e.series.some(o=>!o.hide_in_legend)&&(a+=20),{top:n,right:5,bottom:a,left:5,containLabel:!0}}function P0(e){switch(e){case"bar":return"roundRect";case"scatter":return"circle"}}function B0(e){const t={show:!0,bottom:0,left:"center",type:"scroll"};return t.data=e.filter(n=>!n.hide_in_legend).map(({name:n,type:r})=>({name:n,icon:P0(r)})),t}function V0(e,t,n,r){return e.map(a=>{const o=a.orientation==="horizontal",l=o?"yAxis":"xAxis",u=o?"insideEndTop":"end";return{name:a.name,type:"line",hide_in_legend:!a.show_in_legend,xAxisIndex:a.xAxisIndex,data:[],lineStyle:a.lineStyle,markLine:{data:[{name:a.name,[l]:Number(n[a.variable_key])}],silent:!0,symbol:["none","none"],lineStyle:a.lineStyle,label:{formatter:function(){return a.template?Dn(a.template,t,r):""},position:u}}}})}function Jn(e,t,n){const r=ut(e,t),a=ut(e,n);return x.zip(a,r)}function N0(e,t,n,r){const a=Jn(t,n,r);return x.unionBy(a,e,0)}function q0({dataTemplate:e,data:t,name_data_key:n,value_data_key:r,valueTypedXAxis:a}){return a?N0(e,t,n,r):Jn(t,n,r)}function F0({dataTemplate:e,data:t,aggregation_on_value:n,name_data_key:r,value_data_key:a,valueTypedXAxis:o}){if(!n||n.type==="none")return q0({dataTemplate:e,data:t,name_data_key:r,value_data_key:a,valueTypedXAxis:o});const l=Jn(t,r,a),u=x.groupBy(l,"0");return e.map(([d])=>{const h=u[d].map(m=>m[1]),g=Mr(h,n);return[d,g]})}function G0({group_by_key:e,data:t,value_data_key:n,name_data_key:r}){const{queryID:a,columnKey:o}=q(e),l=x.groupBy(t[a],o);return Object.entries(l).forEach(([u,c])=>{l[u]=Jn({[a]:c},r,n)}),l}function W0({y_axis:e},{data_key:t,xAxisIndex:n,label_position:r,name:a,group_by_key:o,aggregation_on_value:l,stack:u,color:c,hide_in_legend:d,invisible:f,id:h,...g},m,C,w,_,D){const E={label:{show:!!r,position:r,formatter:D[n??"default"]},name:a,yAxisId:"main-y-axis",xAxisIndex:n,stack:u,color:f?"transparent":c,hide_in_legend:d,labelLayout:{hideOverlap:!0},emphasis:{disabled:!0},...g};if(!o||o===e.data_key)return E.data=F0({dataTemplate:m,data:w,aggregation_on_value:l,name_data_key:e.data_key,value_data_key:t,valueTypedXAxis:C}),E;const O=G0({group_by_key:o,data:w,name_data_key:e.data_key,value_data_key:t});return Object.entries(O).map(([B,$])=>{const A=x.cloneDeep(E);return A.name=B,A.color=void 0,A.data=$,A})}function R0(e,t,n,r,a,o,l){const u=t.map(d=>[d,0]);return e.series.map(d=>W0(e,d,u,n,r,l,a)).flat().concat(V0(e.reference_lines,o,l,r))}function j0(e,t){const n=e.find(u=>u.axisDim==="y"&&u.axisId==="main-y-axis");if(!n)return"";const{name:r,axisType:a,axisValue:o,axisIndex:l}=n;return a==="yAxis.category"?r:Pt(t.y_axis.axisLabel.formatter)(o,l)}function Y0(e,t,n){const r=t.reduce((a,{xAxisIndex:o,name:l})=>(a[l]=o,a),{});return{trigger:"axis",axisPointer:{type:"shadow"},formatter:function(a){const o=Array.isArray(a)?a:[a];if(o.length===0)return"";const l=o.map(({seriesName:d,marker:f,value:h})=>{if(Array.isArray(h)&&h.length===2&&(h=h[0]),!d)return h;const g=r[d],m=n[g]??n.default;return`
387
323
  <tr>
388
324
  <td>${f}</td>
389
325
  <th style="text-align: right; padding: 0 1em;">${d}</th>
390
326
  <td style="text-align: left; padding: 0 1em;">${m({value:h})}</td>
391
327
  </tr>
392
- `}),u=mt(t.y_axis.axisLabel.overflow.in_tooltip),c=Gx(o,t);return`
328
+ `}),u=yt(e.y_axis.axisLabel.overflow.in_tooltip),c=j0(o,e);return`
393
329
  <div style="text-align: left; margin-bottom: .5em; padding: 0 1em .5em; font-weight: bold; border-bottom: 1px dashed #ddd;">
394
330
  <div style="${u}">${c}</div>
395
331
  </div>
@@ -398,7 +334,7 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
398
334
  ${l.join("")}
399
335
  </tbody>
400
336
  </table>
401
- `}}}function jx(t){return t.x_axes.reduce((n,{label_formatter:r},a)=>(n[a]=function(l){let u=l;if(typeof l=="object"&&(Array.isArray(l.value)&&l.value.length===2?u=l.value[0]:u=l.value),!r)return u;try{return ee(u).format(r)}catch(c){return console.error(c),u}},n),{default:({value:n})=>n})}function Rx(t,e){const n={};return e.map(r=>{const a=yt(r,t);n[r.name]=et(r,a)}),n}function Yx(t,e){return t.x_axes.map(({min:n,max:r,...a},o)=>{let l=a.position;return l||(l=o>0?"bottom":"top"),{...a,type:"value",min:n||void 0,max:r||void 0,position:l,axisLabel:{show:!0,margin:2,formatter:e[o]??e.default},axisLine:{show:!0},axisTick:{show:!1},splitLine:{show:!0},nameTextStyle:{fontWeight:"bold"},nameLocation:"center",nameGap:15}})}function Qx(t,e){const n=e.every(l=>!Number.isNaN(Number(l))),{overflow:r,...a}=t.y_axis.axisLabel,o=ut(r.on_axis);return[{data:e,name:t.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"center",fontWeight:"bold"},id:"main-y-axis",axisTick:{show:!0,alignWithLabel:!0},type:n?"value":"category",axisLabel:{...a,...o,formatter:Ot(a.formatter)},z:5}]}function Kx(t,e,n){if(!t.y_axis.data_key)return{};const r=Rx(e,n),a=jx(t),o=q(t.y_axis.data_key),l=x.uniq(e[o.queryID].map(f=>f[o.columnKey])),u=l.every(f=>!Number.isNaN(Number(f))),c=Fx(t,l,u,e,a,n,r);return{xAxis:Yx(t,a),yAxis:Qx(t,l),series:c,tooltip:Wx(t,c,a),grid:zx(t),legend:Lx(c)}}le.use([G.DataZoomComponent,pe.BarChart,pe.LineChart,pe.ScatterChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer,G.MarkLineComponent,G.MarkAreaComponent]);function Ux({conf:t,data:e,width:n,height:r,interactionManager:a,variables:o}){const l=bt(e,t.y_axis.data_key),u=He(a.triggerManager,Ir.id),c=y.useCallback(h=>{const g=x.get(l,h.name,{error:"rowData is not found"});u.forEach(m=>{a.runInteraction(m.id,{...h,rowData:g})})},[l,u,a]),d=y.useMemo(()=>({click:c}),[c]),f=y.useMemo(()=>Kx(t,e,o),[t,e]);return!n||!r?null:i(Ne,{echarts:le,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function Xx({context:t,instance:e}){const n=tt({vizManager:t.vizManager,instance:e}),{value:r}=W(t.instanceData,"config"),{variables:a}=t,o=y.useMemo(()=>x.defaults({},r,pi),[r]),l=t.data,{width:u,height:c}=t.viewport;return i(s.Box,{children:i(Ux,{variables:a,width:u,height:c,data:l,conf:o,interactionManager:n})})}const Jx=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],Zx=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function Hx({control:t,index:e,remove:n,watch:r,variableOptions:a,xAxisOptions:o}){const l=r(`reference_lines.${e}.orientation`);return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${e}.name`,control:t,render:({field:u})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),i(v.Controller,{name:`reference_lines.${e}.variable_key`,control:t,render:({field:u})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),i(v.Controller,{name:`reference_lines.${e}.template`,control:t,render:({field:u})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),p(s.Group,{grow:!0,children:[p(s.Stack,{children:[i(v.Controller,{name:`reference_lines.${e}.orientation`,control:t,render:({field:u})=>i(s.Select,{label:"Orientation",data:Zx,required:!0,sx:{flex:1},...u})}),l==="vertical"&&i(s.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&i(v.Controller,{name:`reference_lines.${e}.xAxisIndex`,control:t,render:({field:u})=>i(s.Select,{label:"X Axis",data:o,disabled:o.length===0,sx:{flex:1},...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`reference_lines.${e}.lineStyle.type`,control:t,render:({field:u})=>i(s.Select,{label:"Line Type",data:Jx,sx:{flexGrow:1},...u})}),i(v.Controller,{name:`reference_lines.${e}.lineStyle.width`,control:t,render:({field:u})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`reference_lines.${e}.lineStyle.color`,control:t,render:({field:u})=>i(Pe,{...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`reference_lines.${e}.show_in_legend`,control:t,render:({field:u})=>i(s.Checkbox,{label:"Show in legend",checked:u.value,onChange:c=>u.onChange(c.currentTarget.checked)})}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Reference Line"})]},e)}function e0({control:t,watch:e,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:t,name:"reference_lines"}),l=e("reference_lines"),u=r.map((m,w)=>({...m,...l[w]})),c=()=>{const m=Ax();a(m)},d=y.useMemo(()=>n.map(m=>({label:m.name,value:m.name})),[n]),f=e("x_axes"),h=y.useMemo(()=>f.map(({name:m},w)=>({label:m,value:w.toString()})),[f]),g=u.length>0?u[0].id:"0";return p(s.Tabs,{defaultValue:g,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((m,w)=>i(s.Tabs.Tab,{value:m.id,children:m.name},w)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),u.map((m,w)=>i(s.Tabs.Panel,{value:m.id,children:i(Hx,{control:t,index:w,remove:o,watch:e,variableOptions:d,xAxisOptions:h})},w))]})}function t0(t){const[e,n]=y.useState(t);return y.useEffect(()=>{n(t)},[t]),{tab:e,setTab:n}}const n0=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function r0({control:t,index:e,seriesItem:n}){const r=!!n.barWidth.trim();return p(V,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.stack`,control:t,render:({field:a})=>i(s.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barGap`,control:t,render:({field:a})=>i(s.Select,{label:"Bar Gap",data:n0,sx:{flexGrow:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.barMinWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${e}.barMaxWidth`,control:t,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...a})})]})]})}const i0=[{label:"off",value:""},{label:"top",value:"top"},{label:"left",value:"left"},{label:"right",value:"right"},{label:"bottom",value:"bottom"},{label:"inside",value:"inside"},{label:"insideLeft",value:"insideLeft"},{label:"insideRight",value:"insideRight"},{label:"insideTop",value:"insideTop"},{label:"insideBottom",value:"insideBottom"},{label:"insideTopLeft",value:"insideTopLeft"},{label:"insideBottomLeft",value:"insideBottomLeft"},{label:"insideTopRight",value:"insideTopRight"},{label:"insideBottomRight",value:"insideBottomRight"}];function a0({control:t,index:e,remove:n,seriesItem:r,xAxisOptions:a}){return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.name`,control:t,render:({field:o})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`series.${e}.xAxisIndex`,control:t,render:({field:o})=>i(s.Select,{label:"X Axis",data:a,disabled:a.length===0,sx:{flex:1},...o})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${e}.data_key`,control:t,render:({field:o})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`series.${e}.aggregation_on_value`,control:t,render:({field:o})=>i(Sn,{label:"Aggregation on Value",value:o.value??Pt,onChange:o.onChange,pt:0})})]}),i(s.Group,{grow:!0,children:i(v.Controller,{name:`series.${e}.group_by_key`,control:t,render:({field:o})=>i(j,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...o})})}),i(r0,{index:e,control:t,seriesItem:r}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),i(v.Controller,{name:`series.${e}.label_position`,control:t,render:({field:o})=>i(s.Select,{label:"Label Position",data:i0,...o})}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`series.${e}.color`,control:t,render:({field:o})=>i(Pe,{...o})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`series.${e}.hide_in_legend`,control:t,render:({field:o})=>i(s.Checkbox,{label:"Hide in legend",checked:o.value,onChange:l=>o.onChange(l.currentTarget.checked)})}),i(v.Controller,{name:`series.${e}.invisible`,control:t,render:({field:o})=>i(s.Checkbox,{label:"Invisible",checked:o.value,onChange:l=>o.onChange(l.currentTarget.checked)})}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Series"})]},e)}function s0({control:t,watch:e}){var g;const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"series"}),o=e("series"),l=n.map((m,w)=>({...m,...o[w]})),u=()=>{const m=Ex();r(m)},c=e("x_axes"),d=y.useMemo(()=>c.map(({name:m},w)=>({label:m,value:w.toString()})),[c]),{tab:f,setTab:h}=t0((g=l[0])==null?void 0:g.id);return p(s.Tabs,{value:f,onTabChange:h,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map(m=>i(s.Tabs.Tab,{value:m.id,children:m.name},m.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((m,w)=>i(s.Tabs.Panel,{value:m.id,children:i(a0,{control:t,index:w,remove:a,seriesItem:m,xAxisOptions:d},m.id)},m.id))]})}const o0=[{label:"Top",value:"top"},{label:"Bottom",value:"bottom"}];function l0({control:t,index:e,remove:n}){return p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[i(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`x_axes.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})})}),i(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`x_axes.${e}.position`,control:t,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:o0,sx:{flex:1},...r})})}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:`x_axes.${e}.label_formatter`,control:t,render:({field:r})=>i(Re,{...r})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`x_axes.${e}.min`,control:t,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`x_axes.${e}.max`,control:t,render:({field:r})=>i(s.TextInput,{label:"Max",...r})})]})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`x_axes.${e}.show`,control:t,render:({field:r})=>i(s.Checkbox,{label:"Visible",checked:r.value,onChange:a=>r.onChange(a.currentTarget.checked)})}),i(s.Button,{mt:20,leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),disabled:e===0,children:"Delete this X Axis"})]})}function u0({control:t,watch:e}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"x_axes"}),o=e("x_axes"),l=n.map((d,f)=>({...d,...o[f]})),u=()=>{const d=Ix();r(d)},c=l.length>0?l[0].id:"0";return p(s.Tabs,{defaultValue:c,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map(d=>i(s.Tabs.Tab,{value:d.id,children:d.name},d.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((d,f)=>i(s.Tabs.Panel,{value:d.id,children:i(l0,{control:t,index:f,remove:a})},d.id))]})}function c0({control:t,watch:e}){return e(["y_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.data_key",control:t,render:({field:n})=>i(j,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"y_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Dn,{...n})})}),i(v.Controller,{name:"y_axis.axisLabel.overflow",control:t,render:({field:n})=>i(gt,{...n})})]})}function d0({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),{variables:r}=t,a=y.useMemo(()=>x.defaultsDeep({},e,pi),[e]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]),u([]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,a),[f,a]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Horizontal Bar Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axes",children:"X Axes"}),i(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),i(s.Tabs.Tab,{value:"Series",children:"Series"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"})]}),i(s.Tabs.Panel,{value:"X Axes",children:i(u0,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(c0,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Series",children:i(s0,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(e0,{variables:r,control:o,watch:u})})]})]})})}function p0(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,y_axis:o,series:l,...u}=t;return{...u,x_axis:{...a,data_key:r(a.data_key)},y_axis:{...o,data_key:r(o.data_key)},series:l.map(c=>({...c,data_key:r(c.data_key),group_by_key:r(c.group_by_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class h0 extends ve{constructor(){super(...arguments);N(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:p0(a,r)}})}}const f0={displayName:"Horizontal Bar Chart",displayGroup:"ECharts-based charts",migrator:new h0,name:"horizontalBarChart",viewRender:Xx,configRender:d0,createConfig:()=>({version:2,config:pi})},hi={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...Ln}}},deviation:{name:"",data_keys:{estimated_value:"",actual_value:""}},metrics:[]};function g0(){return[{top:20,left:30,right:60,height:40,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{top:70,left:30,right:60,height:100,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{top:180,left:30,right:60,bottom:130,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{left:30,right:60,bottom:20,height:100,containLabel:!1,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0}]}const qo=({value:t})=>{try{return ee(t[2]).format({output:"percent",mantissa:0})}catch(e){return console.error(e),t}};function m0(t,e,n){return{type:"heatmap",name:"准确估算比例",xAxisIndex:0,yAxisIndex:0,data:e.map(a=>{const o=n[a].length,c=(x.countBy(n[a],d=>d.level.diff===0).true??0)/o;return[a,"_y",c]}),label:{show:!0,formatter:qo},labelLayout:{hideOverlap:!0},visualMapIndex:0,tooltip:{trigger:"item",formatter:({color:a,value:o})=>`
337
+ `}}}function Q0(e){return e.x_axes.reduce((n,{label_formatter:r},a)=>(n[a]=function(l){let u=l;if(typeof l=="object"&&(Array.isArray(l.value)&&l.value.length===2?u=l.value[0]:u=l.value),!r)return u;try{return H(u).format(r)}catch(c){return console.error(c),u}},n),{default:({value:n})=>n})}function K0(e,t){const n={};return t.map(r=>{const a=vt(r,e);n[r.name]=tt(r,a)}),n}function U0(e,t){return e.x_axes.map(({min:n,max:r,...a},o)=>{let l=a.position;return l||(l=o>0?"bottom":"top"),{...a,type:"value",min:n||void 0,max:r||void 0,position:l,axisLabel:{show:!0,margin:2,formatter:t[o]??t.default},axisLine:{show:!0},axisTick:{show:!1},splitLine:{show:!0},nameTextStyle:{fontWeight:"bold"},nameLocation:"center",nameGap:15}})}function X0(e,t){const n=t.every(l=>!Number.isNaN(Number(l))),{overflow:r,...a}=e.y_axis.axisLabel,o=ct(r.on_axis);return[{data:t,name:e.y_axis.name??"",nameLocation:"end",nameTextStyle:{align:"center",fontWeight:"bold"},id:"main-y-axis",axisTick:{show:!0,alignWithLabel:!0},type:n?"value":"category",axisLabel:{...a,...o,formatter:Pt(a.formatter)},z:5}]}function J0(e,t,n){if(!e.y_axis.data_key)return{};const r=K0(t,n),a=Q0(e),o=q(e.y_axis.data_key),l=x.uniq(t[o.queryID].map(f=>f[o.columnKey])),u=l.every(f=>!Number.isNaN(Number(f))),c=R0(e,l,u,t,a,n,r);return{xAxis:U0(e,a),yAxis:X0(e,l),series:c,tooltip:Y0(e,c,a),grid:O0(e),legend:B0(c)}}oe.use([G.DataZoomComponent,pe.BarChart,pe.LineChart,pe.ScatterChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer,G.MarkLineComponent,G.MarkAreaComponent]);function Z0({conf:e,data:t,width:n,height:r,interactionManager:a,variables:o}){const l=bt(t,e.y_axis.data_key),u=He(a.triggerManager,Ar.id),c=b.useCallback(h=>{const g=x.get(l,h.name,{error:"rowData is not found"});u.forEach(m=>{a.runInteraction(m.id,{...h,rowData:g})})},[l,u,a]),d=b.useMemo(()=>({click:c}),[c]),f=b.useMemo(()=>J0(e,t,o),[e,t]);return!n||!r?null:i(Ne,{echarts:oe,option:f,style:{width:n,height:r},onEvents:d,notMerge:!0,theme:"merico-light"})}function H0({context:e,instance:t}){const n=et({vizManager:e.vizManager,instance:t}),{value:r}=W(e.instanceData,"config"),{variables:a}=e,o=b.useMemo(()=>x.defaults({},r,yi),[r]),l=e.data,{width:u,height:c}=e.viewport;return i(s.Box,{children:i(Z0,{variables:a,width:u,height:c,data:l,conf:o,interactionManager:n})})}const ew=[{label:"solid",value:"solid"},{label:"dashed",value:"dashed"},{label:"dotted",value:"dotted"}],tw=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}];function nw({control:e,index:t,remove:n,watch:r,variableOptions:a,xAxisOptions:o}){const l=r(`reference_lines.${t}.orientation`);return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:u})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:u})=>i(s.Select,{label:"Value",required:!0,data:a,sx:{flex:1},...u})})]}),i(v.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:u})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",sx:{flex:1},...u})}),p(s.Group,{grow:!0,children:[p(s.Stack,{children:[i(v.Controller,{name:`reference_lines.${t}.orientation`,control:e,render:({field:u})=>i(s.Select,{label:"Orientation",data:tw,required:!0,sx:{flex:1},...u})}),l==="vertical"&&i(s.Text,{mt:-10,color:"dimmed",size:12,children:"Works only when xAxis values are numbers"})]}),l==="horizontal"&&i(v.Controller,{name:`reference_lines.${t}.xAxisIndex`,control:e,render:({field:u})=>i(s.Select,{label:"X Axis",data:o,disabled:o.length===0,sx:{flex:1},...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`reference_lines.${t}.lineStyle.type`,control:e,render:({field:u})=>i(s.Select,{label:"Line Type",data:ew,sx:{flexGrow:1},...u})}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.width`,control:e,render:({field:u})=>i(s.NumberInput,{label:"Line Width",min:1,max:10,sx:{flexGrow:1},...u})})]}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`reference_lines.${t}.lineStyle.color`,control:e,render:({field:u})=>i(Pe,{...u})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`reference_lines.${t}.show_in_legend`,control:e,render:({field:u})=>i(s.Checkbox,{label:"Show in legend",checked:u.value,onChange:c=>u.onChange(c.currentTarget.checked)})}),i(s.Button,{leftIcon:i(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Reference Line"})]},t)}function rw({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=r.map((m,C)=>({...m,...l[C]})),c=()=>{const m=L0();a(m)},d=b.useMemo(()=>n.map(m=>({label:m.name,value:m.name})),[n]),f=t("x_axes"),h=b.useMemo(()=>f.map(({name:m},C)=>({label:m,value:C.toString()})),[f]),g=u.length>0?u[0].id:"0";return p(s.Tabs,{defaultValue:g,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((m,C)=>i(s.Tabs.Tab,{value:m.id,children:m.name},C)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(T.Plus,{size:18,color:"#228be6"})})]}),u.map((m,C)=>i(s.Tabs.Panel,{value:m.id,children:i(nw,{control:e,index:C,remove:o,watch:t,variableOptions:d,xAxisOptions:h})},C))]})}function iw(e){const[t,n]=b.useState(e);return b.useEffect(()=>{n(e)},[e]),{tab:t,setTab:n}}const aw=[{label:"No gap between bars",value:"0%"},{label:"Bars overlapping on each other",value:"-100%"}];function sw({control:e,index:t,seriesItem:n}){const r=!!n.barWidth.trim();return p(V,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.stack`,control:e,render:({field:a})=>i(s.TextInput,{label:"Stack",placeholder:"Stack bars by this ID",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barGap`,control:e,render:({field:a})=>i(s.Select,{label:"Bar Gap",data:aw,sx:{flexGrow:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.barMinWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Min)",disabled:r,sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width",sx:{flexGrow:1},...a})}),i(v.Controller,{name:`series.${t}.barMaxWidth`,control:e,render:({field:a})=>i(s.TextInput,{label:"Bar Width(Max)",disabled:r,sx:{flexGrow:1},...a})})]})]})}const ow=[{label:"off",value:""},{label:"top",value:"top"},{label:"left",value:"left"},{label:"right",value:"right"},{label:"bottom",value:"bottom"},{label:"inside",value:"inside"},{label:"insideLeft",value:"insideLeft"},{label:"insideRight",value:"insideRight"},{label:"insideTop",value:"insideTop"},{label:"insideBottom",value:"insideBottom"},{label:"insideTopLeft",value:"insideTopLeft"},{label:"insideBottomLeft",value:"insideBottomLeft"},{label:"insideTopRight",value:"insideTopRight"},{label:"insideBottomRight",value:"insideBottomRight"}];function lw({control:e,index:t,remove:n,seriesItem:r,xAxisOptions:a}){return p(s.Stack,{my:0,p:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.name`,control:e,render:({field:o})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`series.${t}.xAxisIndex`,control:e,render:({field:o})=>i(s.Select,{label:"X Axis",data:a,disabled:a.length===0,sx:{flex:1},...o})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`series.${t}.data_key`,control:e,render:({field:o})=>i(R,{label:"Value Field",required:!0,sx:{flex:1},...o})}),i(v.Controller,{name:`series.${t}.aggregation_on_value`,control:e,render:({field:o})=>i(_n,{label:"Aggregation on Value",value:o.value??Bt,onChange:o.onChange,pt:0})})]}),i(s.Group,{grow:!0,children:i(v.Controller,{name:`series.${t}.group_by_key`,control:e,render:({field:o})=>i(R,{label:"Split into multiple series by this key...",clearable:!0,sx:{flex:1},...o})})}),i(sw,{index:t,control:e,seriesItem:r}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Style",labelPosition:"center"}),i(v.Controller,{name:`series.${t}.label_position`,control:e,render:({field:o})=>i(s.Select,{label:"Label Position",data:ow,...o})}),p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:`series.${t}.color`,control:e,render:({field:o})=>i(Pe,{...o})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`series.${t}.hide_in_legend`,control:e,render:({field:o})=>i(s.Checkbox,{label:"Hide in legend",checked:o.value,onChange:l=>o.onChange(l.currentTarget.checked)})}),i(v.Controller,{name:`series.${t}.invisible`,control:e,render:({field:o})=>i(s.Checkbox,{label:"Invisible",checked:o.value,onChange:l=>o.onChange(l.currentTarget.checked)})}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Series"})]},t)}function uw({control:e,watch:t}){var g;const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"series"}),o=t("series"),l=n.map((m,C)=>({...m,...o[C]})),u=()=>{const m=$0();r(m)},c=t("x_axes"),d=b.useMemo(()=>c.map(({name:m},C)=>({label:m,value:C.toString()})),[c]),{tab:f,setTab:h}=iw((g=l[0])==null?void 0:g.id);return p(s.Tabs,{value:f,onTabChange:h,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map(m=>i(s.Tabs.Tab,{value:m.id,children:m.name},m.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(T.Plus,{size:18,color:"#228be6"})})]}),l.map((m,C)=>i(s.Tabs.Panel,{value:m.id,children:i(lw,{control:e,index:C,remove:a,seriesItem:m,xAxisOptions:d},m.id)},m.id))]})}const cw=[{label:"Top",value:"top"},{label:"Bottom",value:"bottom"}];function dw({control:e,index:t,remove:n}){return p(s.Stack,{my:0,p:"0",sx:{position:"relative"},children:[i(s.Divider,{mb:-15,mt:15,variant:"dashed",label:"Name",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`x_axes.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})})}),i(s.Divider,{mb:-15,variant:"dashed",label:"Layout",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`x_axes.${t}.position`,control:e,render:({field:r})=>i(s.Select,{label:"Position",required:!0,data:cw,sx:{flex:1},...r})})}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:`x_axes.${t}.label_formatter`,control:e,render:({field:r})=>i(je,{...r})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Value Range",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`x_axes.${t}.min`,control:e,render:({field:r})=>i(s.TextInput,{label:"Min",...r})}),i(v.Controller,{name:`x_axes.${t}.max`,control:e,render:({field:r})=>i(s.TextInput,{label:"Max",...r})})]})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed",label:"Behavior",labelPosition:"center"}),i(v.Controller,{name:`x_axes.${t}.show`,control:e,render:({field:r})=>i(s.Checkbox,{label:"Visible",checked:r.value,onChange:a=>r.onChange(a.currentTarget.checked)})}),i(s.Button,{mt:20,leftIcon:i(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),disabled:t===0,children:"Delete this X Axis"})]})}function pw({control:e,watch:t}){const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"x_axes"}),o=t("x_axes"),l=n.map((d,f)=>({...d,...o[f]})),u=()=>{const d=z0();r(d)},c=l.length>0?l[0].id:"0";return p(s.Tabs,{defaultValue:c,styles:{tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[l.map(d=>i(s.Tabs.Tab,{value:d.id,children:d.name},d.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(T.Plus,{size:18,color:"#228be6"})})]}),l.map((d,f)=>i(s.Tabs.Panel,{value:d.id,children:i(dw,{control:e,index:f,remove:a})},d.id))]})}function hw({control:e,watch:t}){return t(["y_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>i(R,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"y_axis.axisLabel.formatter",control:e,render:({field:n})=>i(Mn,{...n})})}),i(v.Controller,{name:"y_axis.axisLabel.overflow",control:e,render:({field:n})=>i(mt,{...n})})]})}function fw({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),{variables:r}=e,a=b.useMemo(()=>x.defaultsDeep({},t,yi),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});b.useEffect(()=>{d(a)},[a]),u([]);const f=c(),h=b.useMemo(()=>!x.isEqual(f,a),[f,a]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Horizontal Bar Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(T.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Series",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axes",children:"X Axes"}),i(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),i(s.Tabs.Tab,{value:"Series",children:"Series"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"})]}),i(s.Tabs.Panel,{value:"X Axes",children:i(pw,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(hw,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Series",children:i(uw,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(rw,{variables:r,control:o,watch:u})})]})]})})}function gw(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,y_axis:o,series:l,...u}=e;return{...u,x_axis:{...a,data_key:r(a.data_key)},y_axis:{...o,data_key:r(o.data_key)},series:l.map(c=>({...c,data_key:r(c.data_key),group_by_key:r(c.group_by_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class mw extends be{constructor(){super(...arguments);N(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:gw(a,r)}})}}const yw={displayName:"Horizontal Bar Chart",displayGroup:"ECharts-based charts",migrator:new mw,name:"horizontalBarChart",viewRender:H0,configRender:fw,createConfig:()=>({version:2,config:yi})},bi={x_axis:{name:"",data_key:"",axisLabel:{rotate:0,formatter:{...On}}},deviation:{name:"",data_keys:{estimated_value:"",actual_value:""}},metrics:[]};function bw(){return[{top:20,left:30,right:60,height:40,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{top:70,left:30,right:60,height:100,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{top:180,left:30,right:60,bottom:130,containLabel:!0,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0},{left:30,right:60,bottom:20,height:100,containLabel:!1,backgroundColor:"rgba(235, 235, 255, 0.5)",borderWidth:0,show:!0}]}const Eo=({value:e})=>{try{return H(e[2]).format({output:"percent",mantissa:0})}catch(t){return console.error(t),e}};function vw(e,t,n){return{type:"heatmap",name:"准确估算比例",xAxisIndex:0,yAxisIndex:0,data:t.map(a=>{const o=n[a].length,c=(x.countBy(n[a],d=>d.level.diff===0).true??0)/o;return[a,"_y",c]}),label:{show:!0,formatter:Eo},labelLayout:{hideOverlap:!0},visualMapIndex:0,tooltip:{trigger:"item",formatter:({color:a,value:o})=>`
402
338
  <table style="width: auto">
403
339
  <thead>
404
340
  <tr colspan="2">
@@ -416,17 +352,17 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
416
352
  <tbody>
417
353
  <tr>
418
354
  <th style="text-align: right;">准确估算比例</th>
419
- <td style="text-align: left; padding: 0 1em;">${qo({value:o})}</td>
355
+ <td style="text-align: left; padding: 0 1em;">${Eo({value:o})}</td>
420
356
  </tr>
421
357
  </tbody>
422
358
  </table>
423
- `},show_in_legend:!1}}function Fo(t){const e=[`background-color: ${t}`];return t==="rgba(255, 255, 255, 1)"&&e.push("box-shadow: 0px 0px 1px 0px rgba(0,0,0,.5)"),e.join(";")}function y0([t,e]){const n={x:t,v:`${e}`};try{n.v=ee(e).format({output:"number",mantissa:2,trimMantissa:!0})}catch{}return n}function b0(t,e,n,r){var c,d;const a=e.map(f=>{const h=n[f],g=x.sumBy(h,m=>m.level.diff);return[f,g/h.length]}),o=Number(((c=x.maxBy(a,f=>f[1]))==null?void 0:c[1])??0),l=Number(((d=x.minBy(a,f=>f[1]))==null?void 0:d[1])??0),u=_t.interpolate([o,0,l],["#D15A40","#FFF","#418AAF"]);return{type:"bar",name:"平均偏差",xAxisIndex:1,yAxisIndex:1,...r,data:a,itemStyle:{color:({value:f})=>{try{return u(f[1])}catch{return"#FFF"}}},label:{position:"outside",show:!0,formatter:({value:f})=>{try{return ee(f[1]).format({output:"number",mantissa:1,trimMantissa:!0})}catch{return f[1]}}},tooltip:{trigger:"item",formatter:({color:f,value:h})=>{const{x:g,v:m}=y0(h);return`
359
+ `},show_in_legend:!1}}function Ao(e){const t=[`background-color: ${e}`];return e==="rgba(255, 255, 255, 1)"&&t.push("box-shadow: 0px 0px 1px 0px rgba(0,0,0,.5)"),t.join(";")}function xw([e,t]){const n={x:e,v:`${t}`};try{n.v=H(t).format({output:"number",mantissa:2,trimMantissa:!0})}catch{}return n}function ww(e,t,n,r){var c,d;const a=t.map(f=>{const h=n[f],g=x.sumBy(h,m=>m.level.diff);return[f,g/h.length]}),o=Number(((c=x.maxBy(a,f=>f[1]))==null?void 0:c[1])??0),l=Number(((d=x.minBy(a,f=>f[1]))==null?void 0:d[1])??0),u=kt.interpolate([o,0,l],["#D15A40","#FFF","#418AAF"]);return{type:"bar",name:"平均偏差",xAxisIndex:1,yAxisIndex:1,...r,data:a,itemStyle:{color:({value:f})=>{try{return u(f[1])}catch{return"#FFF"}}},label:{position:"outside",show:!0,formatter:({value:f})=>{try{return H(f[1]).format({output:"number",mantissa:1,trimMantissa:!0})}catch{return f[1]}}},tooltip:{trigger:"item",formatter:({color:f,value:h})=>{const{x:g,v:m}=xw(h);return`
424
360
  <table style="width: auto">
425
361
  <thead>
426
362
  <tr colspan="2">
427
363
  <div style="
428
364
  width: 100%; height: 4px; border-radius: 2px; margin-bottom: 6px;
429
- ${Fo(f)}
365
+ ${Ao(f)}
430
366
  "/>
431
367
  </tr>
432
368
  <tr>
@@ -442,13 +378,13 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
442
378
  </tr>
443
379
  </tbody>
444
380
  </table>
445
- `}},show_in_legend:!1}}function v0([t,e,n,r]){const a={x:t,percentage:`${e}`,count:n,sum:r};try{a.percentage=ee(e).format({output:"percent",mantissa:2,trimMantissa:!0})}catch{}return a}function x0(t,e,n,r){const a={};e.forEach(f=>{const h=x.countBy(n[f],m=>m.level.diff),g=x.sum(Object.values(h));Object.entries(h).forEach(([m,w])=>{a[m]||(a[m]=[]);const C=w/g;a[m].push([f,C,w,g])})});const o=Object.entries(a).map(([f])=>Number(f)).sort((f,h)=>f-h),l=Math.max(...o),u=Math.min(...o),c=_t.interpolate([l,0,u],["#D15A40","#FFF","#418AAF"]);return o.map(f=>({type:"bar",name:f,xAxisIndex:2,yAxisIndex:2,stack:1,...r,color:c(f),data:a[f],tooltip:{trigger:"item",formatter:({color:h,value:g})=>{const{x:m,percentage:w,count:C,sum:_}=v0(g);return`
381
+ `}},show_in_legend:!1}}function Cw([e,t,n,r]){const a={x:e,percentage:`${t}`,count:n,sum:r};try{a.percentage=H(t).format({output:"percent",mantissa:2,trimMantissa:!0})}catch{}return a}function Sw(e,t,n,r){const a={};t.forEach(f=>{const h=x.countBy(n[f],m=>m.level.diff),g=x.sum(Object.values(h));Object.entries(h).forEach(([m,C])=>{a[m]||(a[m]=[]);const w=C/g;a[m].push([f,w,C,g])})});const o=Object.entries(a).map(([f])=>Number(f)).sort((f,h)=>f-h),l=Math.max(...o),u=Math.min(...o),c=kt.interpolate([l,0,u],["#D15A40","#FFF","#418AAF"]);return o.map(f=>({type:"bar",name:f,xAxisIndex:2,yAxisIndex:2,stack:1,...r,color:c(f),data:a[f],tooltip:{trigger:"item",formatter:({color:h,value:g})=>{const{x:m,percentage:C,count:w,sum:_}=Cw(g);return`
446
382
  <table style="width: auto">
447
383
  <thead>
448
384
  <tr colspan="2">
449
385
  <div style="
450
386
  width: 100%; height: 4px; border-radius: 2px; margin-bottom: 6px;
451
- ${Fo(h)}
387
+ ${Ao(h)}
452
388
  "
453
389
  />
454
390
  </tr>
@@ -465,11 +401,11 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
465
401
  </tr>
466
402
  <tr>
467
403
  <th style="text-align: right;">占比</th>
468
- <td style="text-align: left; padding: 0 1em;">${w}</td>
404
+ <td style="text-align: left; padding: 0 1em;">${C}</td>
469
405
  </tr>
470
406
  <tr>
471
407
  <th style="text-align: right;">数量</th>
472
- <td style="text-align: left; padding: 0 1em;">${C}</td>
408
+ <td style="text-align: left; padding: 0 1em;">${w}</td>
473
409
  </tr>
474
410
  <tr>
475
411
  <th style="text-align: right;">总数</th>
@@ -477,15 +413,79 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
477
413
  </tr>
478
414
  </tbody>
479
415
  </table>
480
- `}},show_in_legend:!0}))}function w0(t,e,n,r){const a=q(e.data_key),o=e.name,l=n.map(u=>{const c=x.sumBy(r[u],a.columnKey);return[u,c]});return{type:"line",name:o,xAxisIndex:3,yAxisIndex:3,color:"#b41529",data:l,show_in_legend:!1}}function C0(t,e,n,r){const l={barMinWidth:5,barMaxWidth:20};return[m0(t,n,r),b0(t,n,r,l),...x0(t,n,r,l),w0(t,e,n,r)]}function S0(t,e){const{axisLabel:n}=t.x_axis;return[{data:e,id:"准确估算比例",gridIndex:0,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:e,id:"平均偏差",gridIndex:1,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!0,lineStyle:{color:"#FFFFFF",width:2}},type:"category"},{data:e,id:"数量占比",gridIndex:2,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:e,id:"代码当量",gridIndex:3,axisTick:{show:!1},type:"category",axisLabel:{...n,formatter:js(n.formatter)},axisLine:{show:!1}}]}function _0(t){return[{type:"category",name:"准确估算比例",nameRotate:0,nameGap:5,nameLocation:"end",nameTextStyle:{align:"left"},gridIndex:0,axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:"平均偏差",nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:1,boundaryGap:[1,1],axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:"数量占比",nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:2,axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1},min:0,max:1},{type:"value",gridIndex:3,position:"right",splitNumber:3,axisLabel:{show:!0,verticalAlign:"top",showMinLabel:!1,lineHeight:14},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:t.name,nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:3,position:"left",axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}}]}function fi(t){return t==1||t==2?1:fi(t-2)+fi(t-1)}const k0=Array.from(new Array(20),(t,e)=>fi(e+1));function Go(t){return t<=1?t:k0.findIndex(e=>t<=e)-1}function T0(t,e){const{x_axis:n,deviation:r}=t,a=q(n.data_key),o=q(r.data_keys.estimated_value),l=q(r.data_keys.actual_value);return e[a.queryID].map(u=>{const c=Go(u[o.columnKey]),d=Go(u[l.columnKey]),f=c-d;return{...u,level:{estimated:c,actual:d,diff:f}}})}function D0(t){return t==="rgba(255, 255, 255, 1)"?{borderColor:"rgba(0,0,0,.1)",borderWidth:1}:{}}function M0(t){return{show:!0,orient:"vertical",top:"middle",right:0,data:t.filter(n=>n.show_in_legend).reverse().map(n=>({name:`${n.name}`,color:n.color,itemStyle:D0(n.color)})),tooltip:{show:!0,formatter:"档位偏差:{a}"}}}const I0={tooltip:{trigger:"axis"}};function E0(t,e){const{deviation:n,metrics:r}=t,a=r.find(l=>l.data_key===e);if(a)return a;const o=n.data_keys.actual_value;return{id:o,name:n.name,data_key:o}}function A0(t,e,n){const r=T0(t,n),a=q(t.x_axis.data_key),o=x.uniqBy(n[a.queryID],a.columnKey).map(f=>f[a.columnKey]),l=x.groupBy(r,a.columnKey),u=E0(t,e),c=C0(t,u,o,l),d={xAxis:S0(t,o),yAxis:_0(u),series:c,grid:g0(),visualMap:[{min:0,max:1,calculable:!0,show:!1,seriesIndex:0,color:["#F0F0F0","#418AAF"]}],legend:M0(c)};return x.defaultsDeep({},d,I0)}const z0={input:{border:"none !important",paddingLeft:0,lineHeight:"1.55 !important"}},$0=({conf:t,metricKey:e,setMetricKey:n})=>{const{deviation:r,metrics:a}=t,o=y.useMemo(()=>{const l=a.map(u=>({label:u.name,value:u.data_key}));return l.push({label:r.name?r.name:r.data_keys.actual_value,value:r.data_keys.actual_value}),l},[r,a]);return p(s.Group,{spacing:1,children:[i(s.Text,{size:12,color:"dimmed",sx:{cursor:"default",userSelect:"none"},children:"基线指标"}),i(s.NativeSelect,{size:"xs",data:o,value:e,onChange:l=>n(l.currentTarget.value),styles:z0})]})},L0={"tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function O0(){return p(s.HoverCard,{width:400,shadow:"md",children:[i(s.HoverCard.Target,{children:i(s.Button,{size:"xs",variant:"subtle",compact:!0,leftIcon:i(L.IconInfoCircle,{size:14}),children:"指标说明"})}),i(s.HoverCard.Dropdown,{children:i(s.Table,{fontSize:14,sx:L0,children:p("tbody",{children:[p("tr",{children:[i("th",{children:"估算偏差"}),i("td",{children:"使用斐波那契数列(1,2,3,5,8,13)估算故事点,每个数位为一个档位,计算issue实际故事点与估算故事点的档位偏差,即为估算偏差。如估算故事点为5,实际故事点为8,则估算偏差为-1。"})]}),p("tr",{children:[i("th",{children:"准确估算比例"}),i("td",{children:"偏差在 ± 1 档位内的 issue 均为准确估算,以此计算准确估算的比例。"})]})]})})})]})}function P0(t){return p(s.Group,{position:"apart",children:[i(O0,{}),i($0,{...t})]})}le.use([pe.BarChart,pe.LineChart,pe.HeatmapChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer,G.VisualMapComponent]);function B0({conf:t,data:e,width:n,height:r,metricKey:a}){const o=y.useMemo(()=>A0(t,a,e),[t,e,a]);return i(Ne,{echarts:le,option:o,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function V0({context:t}){const{value:e}=W(t.instanceData,"config"),n=y.useMemo(()=>x.defaults({},e,hi),[e]),r=t.data,{width:a,height:o}=t.viewport,{x_axis:l,deviation:u}=n,{estimated_value:c,actual_value:d}=u.data_keys,[f,h]=y.useState(d);if(y.useEffect(()=>{h(w=>w||d)},[d]),!l.data_key||!c||!d||!a||!o)return null;const g=Math.max(a,300),m=Math.max(o,370);return p(s.Box,{sx:{overflow:"hidden",height:m,width:g},children:[i(P0,{conf:n,metricKey:f,setMetricKey:h}),i(B0,{width:g,height:m-30,data:r,conf:n,metricKey:f})]})}function N0({control:t,watch:e}){return e(["deviation"]),p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"deviation.name",control:t,render:({field:n})=>i(s.TextInput,{label:"指标名称",sx:{flex:1},...n})})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"deviation.data_keys.estimated_value",control:t,render:({field:n})=>i(j,{label:"估算值字段",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"deviation.data_keys.actual_value",control:t,render:({field:n})=>i(j,{label:"实际值字段",required:!0,sx:{flex:1},...n})})]})]})}const q0=({control:t,index:e,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`metrics.${e}.name`,control:t,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`metrics.${e}.data_key`,control:t,render:({field:r})=>i(j,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(e),sx:{top:15,right:5},children:"Delete this Metric"})]}),F0=({control:t,watch:e})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:t,name:"metrics"}),o=e("metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=e("metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(V,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(D.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"设置可以展示在基线图的指标,例如代码当量"})]}),i(s.Divider,{variant:"dashed",my:10}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(q0,{control:t,index:g,remove:a},h.id)},h.id))]})]})};function G0({control:t,watch:e}){return e(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:t,render:({field:n})=>i(j,{label:"数据字段",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:t,render:({field:n})=>i(s.TextInput,{label:"X轴名称",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"点位文案",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:t,render:({field:n})=>i(s.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:t,render:({field:n})=>i(Qs,{...n})})]})]})}function W0({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,hi),[e]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});y.useEffect(()=>{c(r)},[r]),l([]);const d=u(),f=y.useMemo(()=>!x.isEqual(d,r),[d,r]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Merico Estimation Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"12px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X 轴"}),i(s.Tabs.Tab,{value:"Deviation",children:"偏差"}),i(s.Tabs.Tab,{value:"Additional Metrics",children:"指标"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(G0,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Deviation",children:i(N0,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Additional Metrics",children:i(F0,{control:a,watch:l})})]})]})})}function j0(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,deviation:o,metrics:l,...u}=t;return{...u,x_axis:{...a,data_key:r(a.data_key)},deviation:{...o,data_keys:{estimated_value:r(o.data_keys.estimated_value),actual_value:r(o.data_keys.actual_value)}},metrics:l.map(c=>({...c,data_key:r(c.data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class R0 extends ve{constructor(){super(...arguments);N(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:j0(a,r)}})}}const Y0={displayName:"Merico Estimation Chart",displayGroup:"Merico suite",migrator:new R0,name:"mericoEstimationChart",viewRender:V0,configRender:W0,createConfig:()=>({version:2,config:hi})},gi={styles:{justify:"space-around",align:"start"},metrics:[]};function Q0(){return{id:new Date().getTime().toString(),names:{value:"Value",basis:"Basis"},data_keys:{value:"",basis:""},formatter:$e}}function K0({context:t,instance:e}){const{value:n}=W(t.instanceData,"config"),{variables:r}=t,a=y.useMemo(()=>x.defaults({},n,gi),[n]),o=t.data,l=y.useMemo(()=>Is(o,r),[r,o]),{width:u,height:c}=t.viewport;return!u||!c||!a?null:i(s.Flex,{w:`${u}px`,h:`${c}px`,justify:a.styles.justify,align:a.styles.align,direction:"row",wrap:"nowrap",sx:{overflow:"hidden"},children:a.metrics.map(d=>p(s.Stack,{spacing:18,children:[p(s.Stack,{spacing:12,children:[i(s.Text,{size:"14px",color:"#818388",children:d.names.value}),i(s.Text,{size:"24px",color:"#000000",sx:{lineHeight:1},children:ee(l[d.data_keys.value]).format(d.formatter)})]}),p(s.Stack,{spacing:12,children:[i(s.Text,{size:"14px",color:"#818388",children:d.names.basis}),i(s.Text,{size:"12px",color:"#000000",sx:{lineHeight:1},children:ee(l[d.data_keys.basis]).format(d.formatter)})]})]},d.id))})}function U0({control:t,index:e,remove:n,variableOptions:r}){return p(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`metrics.${e}.names.value`,control:t,render:({field:a})=>i(s.TextInput,{label:"Metric Name",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`metrics.${e}.data_keys.value`,control:t,render:({field:a})=>i(s.Select,{label:"Metric Data",required:!0,data:r,sx:{flex:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`metrics.${e}.names.basis`,control:t,render:({field:a})=>i(s.TextInput,{label:"Basis Name",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`metrics.${e}.data_keys.basis`,control:t,render:({field:a})=>i(s.Select,{label:"Basis Data",required:!0,data:r,sx:{flex:1},...a})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Format",labelPosition:"center"}),i(v.Controller,{name:`metrics.${e}.formatter`,control:t,render:({field:a})=>i(Re,{...a})})]}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(e),sx:{position:"absolute",top:15,right:5},disabled:e===0,children:i(D.Trash,{size:16})})]},e)}function X0({control:t,watch:e,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:t,name:"metrics"}),l=e("metrics"),u=r.map((w,C)=>({...w,...l[C]})),c=()=>{a(Q0())},d=y.useMemo(()=>n.map(w=>({label:w.name,value:w.name})),[n]),f=x.get(u,"0.id",null),[h,g]=y.useState(f);y.useEffect(()=>{g(w=>w||f)},[f]);const m=w=>{o(w);const C=x.get(u,"0.id",null);g(C)};return p(V,{children:[i(s.Divider,{mt:15,variant:"dashed",label:"Metrics",labelPosition:"center"}),p(s.Tabs,{value:h,onTabChange:g,styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((w,C)=>i(s.Tabs.Tab,{value:w.id,children:w.names.value?w.names.value:C+1},C)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(L.IconPlus,{size:18,color:"#228be6"})})]}),u.map((w,C)=>i(s.Tabs.Panel,{value:w.id,children:i(U0,{control:t,index:C,remove:m,variableOptions:d})},C))]})]})}const J0=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"},{label:"Space Between",value:"space-between"},{label:"Space Around",value:"space-around"},{label:"Space Evenly",value:"space-evenly"}],Z0=[{label:"Start",value:"start"},{label:"Center",value:"center"},{label:"End",value:"end"},{label:"Stretch",value:"stretch"}];function H0({control:t,watch:e}){return e("styles"),p(V,{children:[i(s.Divider,{mt:15,variant:"dashed",label:"Styles",labelPosition:"center"}),p(s.Group,{children:[i(v.Controller,{name:"styles.justify",control:t,render:({field:n})=>i(s.Select,{label:"Justify Content",required:!0,data:J0,sx:{flex:1},...n})}),i(v.Controller,{name:"styles.align",control:t,render:({field:n})=>i(s.Select,{label:"Align",required:!0,data:Z0,sx:{flex:1},...n})})]})]})}function ew({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),{variables:r}=t,a=y.useMemo(()=>x.defaultsDeep({},e,gi),[e]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,a),[f,a]);return i("form",{onSubmit:l(n),children:p(s.Stack,{spacing:"xs",children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Merico Stats Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),i(H0,{control:o,watch:u}),i(X0,{control:o,watch:u,variables:r})]})})}class tw extends ve{constructor(){super(...arguments);N(this,"VERSION",1)}configVersions(){this.version(1,n=>({...n,version:1,config:n.config}))}}const nw={displayName:"Merico Stats",displayGroup:"Merico suite",migrator:new tw,name:"merico-stats",viewRender:K0,configRender:ew,createConfig:()=>({version:1,config:gi})},rw=[{value:"#25262B",name:"Dark"},{value:"#868E96",name:"Gray"},{value:"#FA5252",name:"Red"},{value:"#E64980",name:"Pink"},{value:"#BE4BDB",name:"Grape"},{value:"#7950F2",name:"Violet"},{value:"#4C6EF5",name:"Indigo"},{value:"#228BE6",name:"Blue"},{value:"#15AABF",name:"Cyan"},{value:"#12B886",name:"Teal"},{value:"#40C057",name:"Green"},{value:"#82C91E",name:"Lime"},{value:"#FAB005",name:"Yellow"},{value:"#FD7E14",name:"Orange"}].map(t=>({name:t.name,value:t.value,type:"single",category:"basic"})),iw=[tc,nc,ac,ic,rc,sc],Wo=()=>({id:"dashboard",version:vs,manifest:{viz:[xi,mv,Rv,Qy,Vv,vg,f0,yc,Od,jh,Df,Mx,sg,wh,iv,Bg,pm,Hv,Y0,nw,Ud],color:[...rw,...iw]}}),sn=new cc,Ce={pluginManager:ot("pluginManager"),vizManager:ot("vizManager"),colorManager:ot("colorManager"),instanceScope:{panelModel:ot("panelModel"),vizInstance:ot("vizInstance"),interactionManager:ot("interactionManager"),migrator:ot("migrator"),operationManager:ot("operationManager"),triggerManager:ot("triggerManager")}},mi=()=>{try{sn.install(Wo())}catch{}const t=new Zu(sn),e=new uc(sn);return{pluginManager:sn,vizManager:t,colorManager:e}},at=y.createContext(mi());try{sn.install(Wo())}catch{}function aw(t,e){const{value:n,set:r}=W(t.operation.operationData,"config"),[a,o]=y.useState(x.defaults({},n,e)),l=async()=>{await r(a)};return y.useEffect(()=>{o(x.defaults({},n,e))},[n]),{config:a,setConfig:o,commit:l}}function sw(t){const{config:e,setConfig:n,commit:r}=aw(t,{urlTemplate:"",openInNewTab:!0});async function a(){await r()}async function o(u){n({...e,openInNewTab:u}),await r()}const l=u=>n({...e,urlTemplate:u.currentTarget.value});return p(s.Stack,{children:[i(s.TextInput,{label:"Url",value:e.urlTemplate,onChange:l,onBlur:a}),i(s.Switch,{label:"Open in new Tab",checked:e.openInNewTab,onChange:u=>o(u.currentTarget.checked)})]})}async function ow(t,e){const{urlTemplate:n,openInNewTab:r}=await e.operationData.getItem("config");window.dispatchEvent(new CustomEvent("open-link",{detail:{urlTemplate:n,openInNewTab:r,payload:t}}))}class lw extends ve{constructor(){super(...arguments);N(this,"VERSION",1)}configVersions(){this.version(1,n=>n)}}const uw={displayName:"Open Link",id:"builtin:op:open-link",configRender:sw,run:ow,migrator:new lw,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function cw(t){const{value:e,set:n}=W(t.operationData,"config"),r=a=>void n({template:a});return[(e==null?void 0:e.template)||"",r]}function dw(t){const[e,n]=cw(t.operation);return i(s.TextInput,{defaultValue:e,onBlur:r=>n(r.currentTarget.value),label:"console.log"})}async function pw(t,e){const n=await e.operationData.getItem("config"),r=x.template(n.template||"");console.log("run with payload",t),console.log(r(t))}const hw={displayName:"console.log (debug)",id:"builtin:op:debug",configRender:dw,run:pw},fw=k.observer(t=>{const e=K(),{value:n,set:r}=W(t.operation.operationData,"config");console.log({value:n,viewID:n==null?void 0:n.viewID});const a=(n==null?void 0:n.viewID)||"",o=l=>void r({viewID:l});return i(s.Select,{defaultValue:a,value:a,onChange:o,label:"View",data:e.views.options})});async function gw(t,e){const r=(await e.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:r}}))}const mw={displayName:"Open View",id:"builtin:op:open_view",configRender:fw,run:gw},yw={"tbody tr":{opacity:.5,transition:"opacity 200ms ease"},"tr[data-affected=true]":{opacity:1}},bw=({value:t="",onChange:e})=>{const[n,r]=y.useState(t);y.useEffect(()=>{r(t)},[t]);const a=()=>{e(n)};return i(s.TextInput,{size:"xs",label:"",value:n,onChange:o=>r(o.currentTarget.value),sx:{flexGrow:1},rightSection:i(s.ActionIcon,{color:"green",size:"xs",onClick:a,disabled:n===t,children:i(L.IconDeviceFloppy,{})})})},vw={dictionary:{}},xw=k.observer(t=>{const e=K(),{value:n=vw,set:r}=W(t.operation.operationData,"config"),{dictionary:a={}}=n;console.log({value:{...n},dictionary:{...a},filters:[...e.filters.keyLabelOptions]});const o=(l,u)=>{if(u===""){const c={...a};delete c[l],r({dictionary:c});return}r({dictionary:{...a,[l]:u}})};return p(s.Table,{sx:yw,children:[i("thead",{children:p("tr",{children:[i("th",{children:"Set filter"}),i("th",{children:"with"})]})}),i("tbody",{children:[...e.filters.keyLabelOptions].map(l=>{const u=l.value in a;return p("tr",{"data-affected":u,children:[i("td",{children:l.label}),i("td",{children:i(bw,{value:a[l.value],onChange:c=>o(l.value,c)})})]},l.value)})})]})});async function ww(t,e){const r=(await e.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:r,payload:t}}))}const Cw={displayName:"Set Filter Values",id:"builtin:op:set_filter_values",configRender:xw,run:ww},Sw={filter_keys:[]},_w=k.observer(t=>{const e=K(),{value:n=Sw,set:r}=W(t.operation.operationData,"config"),{filter_keys:a=[]}=n,o=u=>{r({filter_keys:[...u]})},l=y.useMemo(()=>e.filters.current.map(u=>({label:u.label,value:u.key})),[e.filters.values]);return i(s.Stack,{spacing:10,children:i(s.MultiSelect,{label:"Select Filters to Clear",data:l,value:a,onChange:o})})});async function kw(t,e){const r=(await e.operationData.getItem("config")).filter_keys;window.dispatchEvent(new CustomEvent("clear-filter-values",{detail:{filter_keys:r,payload:t}}))}const Jn=[hw,uw,mw,Cw,{displayName:"Clear Filter Values",id:"builtin:op:clear_filter_values",configRender:_w,run:kw}];class Tw{constructor(e,n=Jn){N(this,"attachments");this.operations=n;const r=async a=>{const{id:o,schemaRef:l}=await a.getItem(null);return{id:o,schemaRef:l,operationData:new Lt(a,"data")}};this.attachments=new vr(e,"__OPERATIONS",r)}async runOperation(e,n){const r=await this.attachments.getInstance(e);if(!r){console.warn(`Operation '${e}' is not defined`);return}const a=this.tryGetSchema(r.schemaRef);if(!a){console.warn(`Operation schema '${r.schemaRef}' is not defined`);return}await a.run(n,r)}tryGetSchema(e){return this.operations.find(n=>n.id===e)}async needMigration(){const n=(await this.attachments.list()).map(async r=>{const a={configData:r.operationData},o=this.tryGetSchema(r.schemaRef),l=o==null?void 0:o.migrator;return l&&await l.needMigration(a)});return(await Promise.all(n)).some(r=>r)}async runMigration(){const n=(await this.attachments.list()).map(async r=>{const a={configData:r.operationData},o=this.tryGetSchema(r.schemaRef),l=o==null?void 0:o.migrator;l&&await l.needMigration(a)&&await l.migrate(a)});await Promise.all(n)}async createOrGetOperation(e,n){var l;if(!this.getOperationSchemaList().some(u=>u.id===n.id))throw new Error(`Operation schema '${n.id}' is not defined`);const a=await this.attachments.getInstance(e);return!a||a.schemaRef!==n.id?await this.attachments.create(e,{id:e,schemaRef:n.id,data:((l=n.createDefaultConfig)==null?void 0:l.call(n))??{}}):a}getOperationList(){return this.attachments.list()}getOperationSchemaList(){return this.operations}removeOperation(e){return this.attachments.remove(e)}async retrieveTrigger(e){return await this.attachments.getInstance(e)}}class yi{constructor(e,n,r){N(this,"operationManager");N(this,"triggerManager");N(this,"attachments");this.operationManager=new Tw(e,r),this.triggerManager=new qc(e,n);const a=async o=>{const{id:l,triggerRef:u,operationRef:c}=await o.getItem(null);return{id:l,triggerRef:u,operationRef:c}};this.attachments=new vr(e,"__INTERACTIONS",a)}async addInteraction(e,n){const r=e.id,a=n.id,o=`[${r}]:[${a}]`;await this.attachments.create(o,{id:o,triggerRef:r,operationRef:a})}getInteractionList(){return this.attachments.list()}async removeInteraction(e){const n=await this.attachments.getInstance(e);if(!n)return;const{triggerRef:r,operationRef:a}=n;await this.getTriggerRefCount(r)<=1&&await this.triggerManager.removeTrigger(r),await this.getOperationRefCount(a)<=1&&await this.operationManager.removeOperation(a),await this.attachments.remove(e)}async getOperationRefCount(e){return(await this.getInteractionList()).filter(r=>r.operationRef===e).length}async getTriggerRefCount(e){return(await this.getInteractionList()).filter(r=>r.triggerRef===e).length}async runInteraction(e,n){const a=(await this.getInteractionList()).filter(o=>o.triggerRef===e);await Promise.all(a.map(async o=>{try{return await this.operationManager.runOperation(o.operationRef,n)}catch(l){console.warn(`Failed to run operation '${o.operationRef}'`,l)}}))}}const tt=({vizManager:t,instance:e})=>X.useCreation(()=>new yi(e,t.resolveComponent(e.type),Jn),[e,t]),jo={left:"flex-start",center:"center",right:"flex-end"},Dw=({header:t,cx:e})=>{const n=x.get(t.column.columnDef.meta,"align","left");return p(s.Text,{className:e("table-head-cell",{"table-head-cell--sortable":t.column.getCanSort()}),onClick:t.column.getToggleSortingHandler(),align:n,sx:{justifyContent:jo[n]},children:[t.isPlaceholder?null:Xe.flexRender(t.column.columnDef.header,t.getContext()),i(Mw,{direction:t.column.getIsSorted()})]})},Mw=({direction:t})=>{switch(t){case"asc":return i(L.IconArrowUp,{size:16});case"desc":return i(L.IconArrowDown,{size:"1em"});default:return null}},bi={id:"builtin:table:click-cell-content",displayName:"Click Cell Content",nameRender:zw,configRender:Ew,payload:[{name:"row_index",description:"Index of the row that the cell belongs to",valueType:"number"},{name:"col_index",description:"Index of the column that the cell belongs to",valueType:"number"},{name:"row_data",description:"Data of the row that the cell belongs to",valueType:"object"}]},Iw={column:""};function Ro(t,e){const{value:n}=W(t.instanceData,"config"),r={columnsFromConfig:[],columnsFromData:[]};if(n&&(r.columnsFromConfig=n.columns.map((a,o)=>({label:a.label,value:o.toString()}))),!e)return r;if(n!=null&&n.id_field){const a=xn(e,n.id_field);(a==null?void 0:a.length)>0&&(r.columnsFromData=Object.keys(a[0]).map(o=>({label:o,value:o})))}return r}function Ew(t){const{columnsFromConfig:e,columnsFromData:n}=Ro(t.instance,t.sampleData),r=e.length>0?e:n,{value:a,set:o}=W(t.trigger.triggerData,"config"),{column:l}=x.defaults({},a,Iw),u=c=>{isNaN(+c)?o({column:c}):o({column:+c})};return i(s.Select,{clearable:!1,data:r,label:"Choose a column",value:l.toString(),onChange:u})}function Aw(t,e){return t?x.isNumber(t.column)?`Click cell of ${e[t.column].label}`:`Click cell of ${t.column}`:"Click cell content (click to config)"}function zw(t){const{columnsFromConfig:e}=Ro(t.instance),{value:n}=W(t.trigger.triggerData,"config");return i(s.Text,{children:Aw(n,e)})}const $w=s.createStyles(t=>({root:{overflow:"auto",position:"relative","& .table-head-cell":{display:"flex",flexFlow:"row nowrap",alignItems:"center",whiteSpace:"nowrap","&.table-head-cell--sortable":{cursor:"pointer",userSelect:"none"}},"&.table-highlight-on-hover tr":{transition:"background-color 0.2s","&:hover":{backgroundColor:t.colorScheme==="dark"?t.colors.dark[5]:t.colors.gray[0]}}},thead:{background:t.colorScheme==="dark"?t.colors.dark[7]:t.white,position:"sticky",top:24,transform:"translateY(-1px)",zIndex:10},info_bar:{position:"sticky",top:0,left:0,right:0,zIndex:10,background:"white"}})),Lw={tableLayout:"fixed","thead, tbody":{tr:{"th, td":{padding:"2px 10px",div:{overflow:"hidden",textOverflow:"ellipsis"},"&:first-of-type":{paddingLeft:2,paddingRight:2}}}}};function Yo(t,e,n){return Math.min(Math.max(t,e),n)}class Ow{constructor(e){this.steps=e;const n=[],r=new Set;for(const a of e)r.has(a.to)||(n.push(a),r.add(a.to));if(n.sort((a,o)=>a.from-o.from),n.length<2)throw new Error("MultiStepValueMapper requires at least 2 steps");this.steps=n}getLinearFunction(e,n){const r=(n.to-e.to)/(n.from-e.from),a=e.to-r*e.from;return o=>r*o+a}getStepFunctionForValue(e){let n=x.findLastIndex(this.steps,r=>r.from<=e);return n=Yo(n,0,this.steps.length-2),this.getLinearFunction(this.steps[n],this.steps[n+1])}mapValue(e){return Yo(this.getStepFunctionForValue(e)(e),0,100)}}class Pw{constructor(e,n,r,a,o){this.getColIndex=e,this.cell=n,this.triggers=r,this.interactionManager=a,this.colorManager=o}getClickHandler(){const e=this.getRelatedTrigger();if(e.length!==0)return()=>{const n={row_data:this.cell.row.original,row_index:this.cell.row.index,col_index:this.getColIndex(this.cell)};for(const r of e)this.interactionManager.runInteraction(r.id,n)}}getRelatedTrigger(){return this.triggers.filter(n=>n.schemaRef===bi.id).filter(n=>{const r=this.getColIndex(this.cell),a=x.get(this.cell.column.columnDef.meta,"value_field"),o=x.get(n.config,"column");return o==r||o==a})}isClickable(){return this.getRelatedTrigger().length>0}get columnConf(){return this.cell.column.columnDef.meta}get bgColor(){const e=this.columnConf.cellBackgroundColor;if(!e||e==="none")return;if(x.isString(e))return e;const n=+this.cell.getValue();if(isFinite(n)){const r=this.colorManager.decodeInterpolation(e.interpolation),o=new Ow(e.steps).mapValue(n);return r==null?void 0:r.getColor(o)}}}const Bw=s.createStyles((t,e)=>({content:{display:"flex",alignItems:"center",justifyContent:jo[e.align],".table-cell-text":{whiteSpace:"nowrap",cursor:e.clickable?"pointer":"default",textDecoration:e.clickable?"underline":"none"}}}));function Vw(t){return t?st(t).oklch()[0]>.7?"black":"white":"inherit"}function Nw(t){const e=t.tableCellContext.bgColor;return{backgroundColor:e,color:Vw(e)}}function qt(t){const e=t.tableCellContext.isClickable(),n=Bw({clickable:e,align:t.align});return i("div",{className:n.classes.content,style:{...Nw(t)},children:i(s.Text,{className:"table-cell-text",onClick:t.tableCellContext.getClickHandler(),children:i("span",{title:t.children,children:t.children})})})}function qw(t){return i(qt,{...t,children:t.value})}function Fw(t){const e=ee(t.value).format({average:!0,mantissa:2,trimMantissa:!0});return i(qt,{...t,children:e})}function Gw(t){const e=ee(t.value).format({thousandSeparated:!0});return i(qt,{...t,children:e})}function Ww(t){const e=ee(t.value).format({output:"percent",mantissa:3});return i(qt,{...t,children:e})}function jw(t){const e=t.value,n=t.func_content;if(!n)return i(qt,{...t,children:e});const r=new Function(`return ${n}`)()({value:e});return i(qt,{...t,children:r})}function Rw(t){switch(t.type){case Je.string:return i(qw,{...t});case Je.eloc:return i(Fw,{...t});case Je.number:return i(Gw,{...t});case Je.percentage:return i(Ww,{...t});case Je.custom:return i(jw,{...t})}}const Yw=t=>{const e=tt(t),n=He(e.triggerManager,bi.id),{colorManager:r}=y.useContext(at);return y.useCallback(a=>new Pw(t.getColIndex,a,n,e,r),[n,e,t.getColIndex])};function Qw({data:t,width:e,height:n,conf:r,context:a,instance:o}){var be,De;const{id_field:l,use_raw_columns:u,columns:c,...d}=r,{classes:f,cx:h}=$w(),g=y.useMemo(()=>{if(!l)return[];const ge=q(l);return t[ge.queryID]},[t,l]),m=y.useMemo(()=>u?!Array.isArray(g)||g.length===0?[]:Object.keys(g[0]).map(ge=>({id:ge,label:ge,value_field:ge,value_type:Je.string,align:"left",width:"",cellBackgroundColor:""})):c,[u,c,g]),w=Yw({getColIndex:y.useCallback(ge=>m.indexOf(ge.column.columnDef.meta),[m]),vizManager:a.vizManager,instance:o}),C=y.useMemo(()=>{const ge=Xe.createColumnHelper();return m.map(me=>{const Oe=q(me.value_field);return ge.accessor(Oe.columnKey,{cell:Qe=>i(Rw,{tableCellContext:w(Qe.cell),value:Qe.getValue(),type:me.value_type,...me}),header:me.label,enableSorting:!0,meta:me,size:typeof me.width=="number"?me.width:void 0,minSize:typeof me.width=="number"?me.width:void 0})})},[m,w]),[_,T]=y.useState([]),I=Xe.useReactTable({data:g,state:{sorting:_},onSortingChange:T,columns:C,getCoreRowModel:Xe.getCoreRowModel(),getSortedRowModel:Xe.getSortedRowModel()}),{rows:O}=I.getRowModel(),B=y.useRef(null),$=eu.useVirtual({parentRef:B,size:O.length,estimateSize:y.useCallback(()=>28,[]),overscan:20}),{virtualItems:A,totalSize:E}=$,F=A.length>0&&((be=A==null?void 0:A[0])==null?void 0:be.start)||0,U=A.length>0?E-(((De=A==null?void 0:A[A.length-1])==null?void 0:De.end)||0):0,Y=O.length,Z=Y>0,oe=Z?n-22:n,ue=Z?22:0;return!Array.isArray(g)||g.length===0?i(s.Text,{color:"gray",align:"center",children:"Empty Data"}):p("div",{ref:B,style:{height:n,width:e},"data-enable-scrollbar":!0,className:h(f.root,{"table-highlight-on-hover":r.highlightOnHover}),children:[Y>0&&i(s.Box,{className:f.info_bar,sx:{height:22},children:p(s.Text,{align:"right",pr:6,size:14,color:"dimmed",fw:"normal",children:["Total: ",Y]})}),p(s.Table,{sx:{...Lw,maxHeight:oe},...d,striped:r.striped,children:[i("thead",{className:f.thead,style:{top:ue},children:I.getHeaderGroups().map(ge=>i("tr",{children:ge.headers.map(xe=>i("th",{style:{width:xe.getSize()},children:i(Dw,{header:xe,cx:h})},xe.id))},ge.id))}),p("tbody",{children:[F>0&&i("tr",{children:i("td",{style:{height:`${F}px`}})}),A.map(ge=>{const xe=O[ge.index];return i("tr",{children:xe.getVisibleCells().map(me=>i("td",{children:Xe.flexRender(me.column.columnDef.cell,me.getContext())},me.id))},xe.id)}),U>0&&i("tr",{children:i("td",{style:{height:`${U}px`}})})]})]})]})}function Kw({context:t,instance:e}){const n=t.data,{height:r,width:a}=t.viewport,{value:o}=W(t.instanceData,"config");return o?o.id_field?i(Qw,{data:n,width:a,height:r,conf:o,context:t,instance:e}):(console.group("🔴 what the fuck"),console.log(o),console.groupEnd(),i(s.Text,{color:"red",align:"center",children:"ID Field is not set, can't render a table without it"})):null}const Qo=s.createStyles(()=>({palette:{display:"flex",flexFlow:"row nowrap"},paletteItem:{".palette-value":{height:24,overflow:"visible",width:36},".palette-item":{width:"36px",height:36*.618,cursor:"pointer",transition:"transform 100ms ease-in-out","&:hover":{boxShadow:"0 0 0 2px var(--shadow-color)",borderRadius:2,transform:"scale(1.2)"}}}})),Uw=[{from:0,to:0},{from:100,to:100}];class Xw{constructor(){N(this,"steps",new Map);N(this,"interpolation");N(this,"onChange");ie.makeAutoObservable(this,{steps:ie.observable},{deep:!1}),ie.reaction(()=>ie.toJS(this.steps),()=>{this.notifyStepChange()})}setSteps(e){for(const n of e)this.steps.set(n.to,n.from)}notifyStepChange(){var e;(e=this.onChange)==null||e.call(this,Array.from(this.steps.entries()).map(([n,r])=>({to:n,from:r})).sort((n,r)=>n.to-r.to||n.from-r.from))}fromProps(e){e.steps.length<2?this.setSteps(Uw):this.setSteps(e.steps),this.interpolation=e.interpolation,this.onChange=e.onChange}changeStep(e,n){e==null?this.steps.delete(n):this.steps.set(n,e)}getStepFromValue(e){return this.steps.get(e)}}function Jw(t){const{onChange:e,color:n,index:r,value:a}=t,{classes:o}=Qo(),[l,u]=y.useState(a),[c,{setTrue:d,setFalse:f}]=X.useBoolean(!1),h=r%2===1,g=h&&a!=null,m=!h&&a!=null,w=`map ${a} to color ${r}`,C=()=>{u(a),f()},_=()=>{f(),e==null||e(l)},T=ee(a).format({average:!0});return p("div",{"data-testid":`palette-item-${r}`,className:o.paletteItem,children:[i(s.Text,{title:w,style:{opacity:g?1:0},color:"dimmed",size:"sm",className:"palette-value--up palette-value",children:T}),p(s.Popover,{width:200,trapFocus:!0,opened:c,onClose:f,children:[i(s.Popover.Target,{children:i("div",{"data-testid":"palette-item-target",className:"palette-item",onClick:d,style:{"--shadow-color":st(n).alpha(.5).hex(),backgroundColor:n}})}),i(s.Popover.Dropdown,{children:p(s.Stack,{children:[i(s.NumberInput,{size:"xs",label:"Map a value to this color",value:l,onChange:u}),p(s.Group,{position:"right",children:[i(s.Button,{variant:"subtle",size:"xs",onClick:C,children:"Cancel"}),i(s.Button,{"data-testid":"palette-item-ok",size:"xs",onClick:_,children:"OK"})]})]})})]}),i(s.Text,{title:w,style:{opacity:m?1:0},color:"dimmed",size:"sm",className:"palette-value--bottom palette-value",children:T})]})}const Zw=k.observer(({model:t})=>{const{classes:e}=Qo(),n=x.range(0,13,1).map(r=>100/12*r).map(r=>[t.interpolation.getColor(r),r]);return i("div",{className:e.palette,children:n.map(([r,a],o)=>i(Jw,{index:o,color:r,value:t.getStepFromValue(a),onChange:l=>t.changeStep(l,a)},r))})}),Hw=k.observer(function(e){const n=X.useCreation(()=>new Xw,[]);return y.useEffect(()=>{n.fromProps(e)}),n.interpolation==null?null:i(Zw,{model:n})}),eC=t=>{const{value:e,onChange:n,colorManager:r}=t,a=r.getColorInterpolations(),[o,l]=y.useState(e),u=r.decodeInterpolation(o.interpolation)||a[0],[c,{setTrue:d,setFalse:f}]=X.useBoolean(),h=a.map(_=>({label:_.displayName,value:r.encodeColor(_),group:_.category}));function g(_){_&&l(T=>({...T,interpolation:_}))}const m=()=>{f(),n==null||n(ie.toJS(o))};function w(_){l(T=>({...T,steps:_}))}const C=()=>{f(),l(e)};return p(V,{children:[i(s.Button,{variant:"outline",onClick:d,children:u==null?void 0:u.displayName}),i(s.Modal,{size:508,title:"Setup color interpolation",opened:c,onClose:f,zIndex:320,children:c&&p(s.Stack,{"data-testid":"color-interpolation-modal",children:[i(s.Select,{label:"Color style",value:o.interpolation,data:h,onChange:g}),i(Hw,{steps:o.steps,interpolation:u,onChange:w}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:C,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:m,children:"OK"})]})]})})]})},tC=["static","interpolation","none"].map(t=>({label:x.capitalize(t),value:t})),nC=[{from:0,to:0},{from:100,to:100}];function Ko(t){return t?x.isString(t)?t==="none"?"none":"static":"interpolation":"none"}function rC(t,e){var n;return Ko(e)==="static"?e:(n=t.getStaticColors()[0])==null?void 0:n.value}function iC(t,e){return x.isObject(e)?e:{steps:nC,interpolation:t.encodeColor(t.getColorInterpolations()[0])}}const aC=y.forwardRef((t,e)=>{const{colorManager:n}=y.useContext(at),[r,a]=y.useState(Ko(t.value)),[o,l]=y.useState(rC(n,t.value)),u=X.useLatest(o),[c,d]=y.useState(iC(n,t.value)),f=X.useLatest(c),h=w=>{var C,_,T;a(w||"none"),w==="static"?(C=t.onChange)==null||C.call(t,u.current):w==="none"||!w?(_=t.onChange)==null||_.call(t,"none"):(T=t.onChange)==null||T.call(t,f.current)},g=w=>{var C;l(w),(C=t.onChange)==null||C.call(t,w)},m=w=>{var C;d(w),(C=t.onChange)==null||C.call(t,w)};return p(s.Stack,{align:"stretch",children:[i(s.Select,{label:"Cell background",value:r||"none",onChange:h,data:tC}),r==="static"&&i(Pe,{value:o,onChange:g}),r==="interpolation"&&i(eC,{colorManager:n,value:c,onChange:m})]})}),sC={[Je.eloc]:"ELOC"},oC=Object.values(Je).map(t=>({label:x.get(sC,t,x.capitalize(t)),value:t})),lC=y.forwardRef(({label:t,value:e,onChange:n,sx:r},a)=>i(s.Select,{ref:a,label:t,data:oC,value:e,onChange:n,sx:r})),uC=y.forwardRef(({value:t,onChange:e},n)=>{const[r,{setTrue:a,setFalse:o}]=X.useBoolean(),[l,u]=y.useState(t),c=()=>{o(),e(l)},d=()=>{o(),u(t)},f=()=>{u(fs)};return y.useEffect(()=>{u(t)},[t]),p(V,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Custom Cell Content"}),i(s.Modal,{size:800,title:"Custom cell content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(s.Box,{sx:{position:"relative"},children:i(Ie,{height:"500px",defaultLanguage:"javascript",value:l,onChange:h=>u(h??""),theme:"vs-dark",options:{minimap:{enabled:!1}}})}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:f,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})}),cC=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],vi=()=>i(s.Text,{color:"dimmed",size:12,children:"px"}),dC=({control:t,index:e,watch:n,remove:r,column:a})=>{const o=n(`columns.${e}.value_type`);return p(s.Stack,{my:0,sx:{position:"relative"},children:[p(s.Group,{grow:!0,children:[i(v.Controller,{name:`columns.${e}.label`,control:t,render:({field:l})=>i(s.TextInput,{label:"Label",required:!0,id:`col-label-${e}`,sx:{flex:1},...l})}),i(v.Controller,{name:`columns.${e}.value_field`,control:t,render:({field:l})=>i(j,{label:"Value Field",required:!0,...l})})]}),p(s.Group,{grow:!0,children:[i(v.Controller,{name:`columns.${e}.value_type`,control:t,render:({field:l})=>i(lC,{label:"Value Type",sx:{flex:1},...l})}),o===Je.custom&&i(v.Controller,{name:`columns.${e}.func_content`,control:t,render:({field:l})=>i(uC,{value:l.value??fs,onChange:u=>l.onChange(u??"")})})]}),i(s.Divider,{mb:-10,variant:"dashed",label:"Style",labelPosition:"center"}),p(s.Group,{grow:!0,children:[i(s.NumberInput,{hideControls:!0,label:"Min Width",rightSection:i(vi,{}),disabled:!0}),i(v.Controller,{name:`columns.${e}.width`,control:t,render:({field:l})=>i(s.NumberInput,{hideControls:!0,label:"Width",rightSection:i(vi,{}),...l})}),i(s.NumberInput,{hideControls:!0,label:"Max Width",rightSection:i(vi,{}),disabled:!0})]}),i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:`columns.${e}.align`,control:t,render:({field:l})=>i(s.Select,{label:"Alignment",data:cC,...l})})}),i(v.Controller,{name:`columns.${e}.cellBackgroundColor`,control:t,render:({field:l})=>i(aC,{...l})}),i(s.Divider,{mb:4,mt:12,variant:"dashed"}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:()=>r(e),children:"Delete this column"})]})},pC=({control:t,watch:e})=>{const{fields:n,append:r,remove:a,update:o}=v.useFieldArray({control:t,name:"columns"}),l=()=>{const c=Me.randomId();r({id:c,label:c,align:"center",value_field:"",value_type:Je.string,width:""})};e("columns");const u=e("use_raw_columns");return p(V,{children:[i(v.Controller,{name:"use_raw_columns",control:t,render:({field:c})=>i(s.Switch,{mt:20,mb:20,label:"Use Original Data Columns",checked:c.value,onChange:d=>c.onChange(d.currentTarget.checked)})}),!u&&i(s.Stack,{children:p(s.Tabs,{defaultValue:"0",styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[n.map((c,d)=>i(s.Tabs.Tab,{value:d.toString(),children:d+1},c.id)),i(s.Tabs.Tab,{onClick:l,value:"add",children:i(D.Plus,{size:18,color:"#228be6"})})]}),n.map((c,d)=>i(s.Tabs.Panel,{value:d.toString(),children:i(dC,{control:t,watch:e,index:d,column:c,remove:a},d)},c.id))]})})]})};function hC({control:t,watch:e}){return e(["horizontalSpacing","verticalSpacing","fontSize","striped","highlightOnHover"]),p(s.Stack,{spacing:"xs",children:[p(s.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:[i(v.Controller,{name:"horizontalSpacing",control:t,render:({field:n})=>i(s.TextInput,{label:"Horizontal Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"verticalSpacing",control:t,render:({field:n})=>i(s.TextInput,{label:"Vertical Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})})]}),i(s.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:i(v.Controller,{name:"fontSize",control:t,render:({field:n})=>i(s.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1},...n})})}),p(s.Group,{position:"apart",grow:!0,children:[i(v.Controller,{name:"striped",control:t,render:({field:n})=>i(s.Switch,{label:"Striped",checked:n.value,onChange:r=>n.onChange(r.currentTarget.checked)})}),i(v.Controller,{name:"highlightOnHover",control:t,render:({field:n})=>i(s.Switch,{label:"Highlight on hover",checked:n.value,onChange:r=>n.onChange(r.currentTarget.checked)})})]})]})}function fC({columns:t,...e}){return{...e,columns:t.map(({id:n,...r})=>({id:n??Me.randomId(),...r}))}}function gC({context:t}){const{value:e,set:n}=W(t.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},e,gs),[e]),a=y.useMemo(()=>fC(r),[r]);y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return u(["id_field"]),p("form",{onSubmit:l(n),children:[p(s.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Table Config"}),i(s.ActionIcon,{type:"submit","aria-label":"save config",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(D.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"Columns",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Columns",children:"Columns"}),i(s.Tabs.Tab,{value:"Style",children:"Style"})]}),p(s.Tabs.Panel,{value:"Columns",children:[i(v.Controller,{name:"id_field",control:o,render:({field:g})=>i(j,{label:"ID Field",required:!0,...g})}),i(s.Divider,{mt:20,mb:10,variant:"dashed"}),i(pC,{control:o,watch:u})]}),i(s.Tabs.Panel,{value:"Style",children:i(hC,{control:o,watch:u})})]})]})}function mC(t){const{columns:e,...n}=t;return{...t,columns:e.map(r=>({...r,align:r.align??"left"}))}}function yC(t,{panelModel:e}){try{const n=e.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{id_field:a,columns:o,...l}=t;return{...l,id_field:r(a),columns:o.map(u=>({...u,value_field:r(u.value_field)}))}}catch(n){throw console.error("[Migration failed]",n),n}}function bC(t){const{columns:e,...n}=t;return{...n,columns:e.map(r=>({...r,align:r.align??"left",cellBackgroundColor:r.cellBackgroundColor??"",width:r.width??""}))}}class vC extends ve{constructor(){super(...arguments);N(this,"VERSION",5)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{columns:r,...a}=n.config;return{...n,version:2,config:{...a,columns:r.map(({id:o,...l})=>({id:o??Me.randomId(),...l}))}}}),this.version(3,n=>({...n,version:3,config:mC(n.config)})),this.version(4,(n,r)=>({...n,version:4,config:yC(n.config,r)})),this.version(5,n=>({...n,version:5,config:bC(n.config)}))}}const xi={createConfig(){return{version:5,config:x.cloneDeep(gs)}},displayName:"Table",displayGroup:"Others",migrator:new vC,name:"table",viewRender:Kw,configRender:gC,triggers:[bi]},xC=b.types.model("PanelLayoutModel",{x:b.types.number,y:b.types.maybeNull(b.types.number),w:b.types.number,h:b.types.number,moved:b.types.optional(b.types.boolean,!1),static:b.types.optional(b.types.boolean,!1)}).views(t=>({get json(){const{x:e,y:n,w:r,h:a,moved:o}=t;return{h:a,w:r,x:e,y:n===null?0:n,moved:o,static:t.static}}})).actions(t=>({set(e){const{x:n,y:r,w:a,h:o,moved:l}=e;t.x=n,t.y=r,t.w=a,t.h=o,t.moved=!!l,t.static=!!e.static}})),wC=b.types.model("PanelStyleBorderModel",{enabled:b.types.boolean}).views(t=>({get json(){const{enabled:e}=t;return{enabled:e}}})).actions(t=>({setEnabled(e){t.enabled=e}})),CC=b.types.model("PanelStyleModel",{border:wC}).views(t=>({get json(){const{border:e}=t;return{border:e.json}}})).actions(t=>({})),SC=b.types.model("PanelVizModel",{type:b.types.string,conf:b.types.frozen()}).views(t=>({get json(){return{conf:t.conf,type:t.type}}})).actions(t=>({setType(e){t.type=e},setConf(e){t.conf=e}})),Uo=b.types.model({id:b.types.string,title:b.types.string,description:b.types.string,layout:xC,queryIDs:b.types.array(b.types.string),viz:SC,style:CC,variables:b.types.optional(b.types.array(Qu),[])}).views(t=>({get contentModel(){return b.getParentOfType(t,Zn)}})).views(t=>({get queryIDSet(){return new Set(t.queryIDs)},get queries(){return t.contentModel.queries.findByIDSet(this.queryIDSet)},get data(){return this.queries.reduce((e,n)=>(e[n.id]=n.data.toJSON(),e),{})},get dataLoading(){return this.queries.some(e=>e.state==="loading")},get queryStateMessages(){return this.queries.map(e=>e.stateMessage).filter(e=>!!e)},get queryErrors(){return this.queries.map(e=>e.error).filter(e=>!!e)},get canRenderViz(){return this.queryErrors.length===0&&this.queryStateMessages.length===0&&!this.dataLoading},get json(){const{id:e,title:n,description:r,queryIDs:a}=t;return{id:e,viz:t.viz.json,style:t.style.json,title:n,layout:t.layout.json,queryIDs:[...a],variables:t.variables.map(o=>o.json),description:r}},get dataFieldOptions(){return t.queryIDs.length===0?[]:this.queries.map(e=>{const n=e.data;return n.length===0?[]:Object.keys(n[0]).map(a=>({label:a,value:`${e.id}.${a}`,group:e.name}))}).flat()}})).actions(t=>({setID(e){t.id=e},setTitle(e){t.title=e},setDescription(e){t.description=e},addQueryID(e){t.queryIDSet.has(e)||t.queryIDs.push(e)},removeQueryID(e){if(!t.queryIDSet.has(e))return;const n=new Set(t.queryIDSet);n.delete(e),t.queryIDs=b.cast(Array.from(n))},setQueryIDs(e){t.queryIDs=b.cast(e)},addVariable(e){t.variables.push(e)},removeVariable(e){t.variables.remove(e)},removeSelf(){b.getParent(t,2).removeByID(t.id)}})).actions(t=>({moveToView(e,n){b.getRoot(t).content.views.findByID(e).removePanelID(t.id),b.getRoot(t).content.views.findByID(n).appendPanelID(t.id),b.getRoot(t).editor.setPath(["_VIEWS_",n,"_PANELS_",t.id])},refreshData(){t.queries.forEach(e=>e.fetchData())},downloadData(){b.getRoot(t).content.queries.downloadDataByQueryIDs(t.queryIDs)}}));function Xo(t){return{id:t,layout:{x:0,y:1/0,w:18,h:300},title:t,description:"<p></p>",queryIDs:[],viz:{type:xi.name,conf:xi.createConfig()},style:{border:{enabled:!0}}}}const Jo=b.types.model("PanelsModel",{list:b.types.optional(b.types.array(Uo),[])}).views(t=>({get json(){return t.list.map(e=>e.json)},findByID(e){return t.list.find(n=>n.id===e)},get idMap(){const e=new Map;return t.list.forEach(n=>{e.set(n.id,n)}),e}})).views(t=>({panelsByIDs(e){const n=[];e.forEach(a=>{const o=t.idMap.get(a);o?n.push(o):console.warn(`Panel is not found, id:${a}`)});const r=n.map(a=>({...a.layout.json,i:a.id}));return{panels:n,layouts:r}}})).views(t=>({editorOptions(e,n){const{panels:r}=t.panelsByIDs(n);r.length!==n.length&&console.warn(`Unfulfilled panels for View[${e}]`);const a=r.map(l=>({label:l.title?l.title:x.capitalize(l.viz.type),value:l.id,_type:"panel",parentID:e})),o="_Add_A_PANEL_";return a.push({label:o,value:o,_type:"ACTION",_action_type:o,parentID:e,Icon:null,children:null}),a}})).actions(t=>({replace(e){t.list=b.castToSnapshot(e)},append(e){t.list.push(e)},remove(e){t.list.splice(e,1)},removeByID(e){const n=t.list.findIndex(r=>r.id===e);n!==-1&&t.list.splice(n,1)},duplicateByID(e){const n=t.list.find(a=>a.id===e);if(!n){console.error(new Error(`[duplicate panel] Can't find a panel by id[${e}]`));return}const r=new Date().getTime().toString();return t.list.push({...n.json,id:r,layout:{...n.layout,y:1/0,moved:!1}}),r},replaceByIndex(e,n){t.list.splice(e,1,n)}}));var Zo=(t=>(t.Use="use",t.Edit="edit",t))(Zo||{}),H=(t=>(t.Division="div",t.Modal="modal",t.Tabs="tabs",t))(H||{});const _C={div:"Division",tabs:"Tabs",modal:"Modal"},Ho={div:"rgba(255, 0, 0, 0.2)",modal:"rgba(0, 0, 0, 0.2)",tabs:"rgba(255, 200, 100, 0.4)"},kC={div:"#ff4000",modal:"#000",tabs:"#ffad18"},TC={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:"div",config:{},panelIDs:[]}],panels:[],filters:[],version:"9.19.0"};var wi=(t=>(t.Select="select",t.TreeSelect="tree-select",t.MultiSelect="multi-select",t.TextInput="text-input",t.Checkbox="checkbox",t.DateRange="date-range",t))(wi||{});const el=b.types.model("ViewModel_Division",{_name:b.types.literal(H.Division)}).views(t=>({get json(){const{_name:e}=t;return{_name:e}}})).actions(t=>({})),DC=()=>el.create({_name:H.Division}),Ci={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
481
- `)},MC=b.types.model("CustomModalTitleModel",{enabled:b.types.optional(b.types.boolean,!1),func_content:b.types.optional(b.types.string,"")}).views(t=>({get json(){const{enabled:e,func_content:n}=t;return{enabled:e,func_content:n}},get value(){const{enabled:e,func_content:n}=t,r=b.getParent(t,2),a=b.getRoot(t);if(!e)return r.name;try{const o={filters:a.content.filters.values,context:a.context.current};return new Function(`return ${n}`)()(o)}catch(o){return console.error(o),r.name}}})).actions(t=>({setEnabled(e){t.enabled=e},setFuncContent(e){t.func_content=e},replace({enabled:e,func_content:n}){t.enabled=e,t.func_content=n}})),tl=b.types.model("ViewModel_Modal",{_name:b.types.literal(H.Modal),width:b.types.string,height:b.types.string,custom_modal_title:b.types.optional(MC,Ci)}).views(t=>({get json(){const{_name:e,width:n,height:r,custom_modal_title:a}=t;return{_name:e,width:n,height:r,custom_modal_title:a.json}}})).actions(t=>({setWidth(e){t.width=e},setHeight(e){t.height=e}})),IC=()=>tl.create({_name:H.Modal,width:"90vw",height:"90vh"}),EC=b.types.model("ViewModel_Tabs_Tab",{id:b.types.identifier,name:b.types.string,view_id:b.types.string,color:b.types.optional(b.types.string,"")}).views(t=>({get json(){const{id:e,name:n,view_id:r,color:a}=t;return{id:e,name:n,color:a,view_id:r}}})).actions(t=>({setName(e){t.name=e},setViewID(e){t.view_id=e},setColor(e){t.color=e}})),nl=b.types.model("ViewModel_Tabs",{_name:b.types.literal(H.Modal),tabs:b.types.optional(b.types.array(EC),[]),variant:b.types.optional(b.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:b.types.optional(b.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:b.types.optional(b.types.boolean,!1)}).views(t=>({get json(){const{_name:e,variant:n,orientation:r,tabs:a,grow:o}=t;return{grow:o,tabs:a.map(l=>l.json),_name:e,variant:n,orientation:r}}})).actions(t=>({setVariant(e){t.variant=e},setOrientation(e){t.orientation=e},setGrow(e){t.grow=e},setTabs(e){t.tabs.length=0,t.tabs=b.cast(e)},addTab(){const e=Me.randomId(),n={id:e,name:e,view_id:""};t.tabs.push(n)},removeTab(e){t.tabs.splice(e,1)}})),AC=()=>nl.create({_name:H.Modal,tabs:[]}),rl=b.types.model({id:b.types.identifier,name:b.types.string,type:b.types.enumeration("EViewComponentType",[H.Division,H.Modal,H.Tabs]),config:b.types.union(el,tl,nl),panelIDs:b.types.optional(b.types.array(b.types.string),[])}).views(t=>({get json(){const{id:e,name:n,type:r,config:a}=t;return{id:e,name:n,type:r,config:a.json,panelIDs:t.panelIDs}}})).actions(t=>({setName(e){t.name=e},setType(e){if(t.type!==e){switch(e){case H.Division:t.config=DC();break;case H.Modal:t.config=IC();break;case H.Tabs:t.config=AC();break}t.type=e}},appendPanelID(e){t.panelIDs.push(e)},removePanelID(e){const n=t.panelIDs.filter(r=>r!==e);t.panelIDs.length=0,t.panelIDs.push(...n)}})).actions(t=>({})),il=b.types.model("ViewsModel",{current:b.types.optional(b.types.array(rl),[]),visibleViewIDs:b.types.array(b.types.string),idOfVIE:b.types.string}).views(t=>({get json(){return t.current.map(e=>yn(e.json))},get idMap(){const e=new Map;return t.current.forEach(n=>{e.set(n.id,n)}),e},findByID(e){return t.current.find(n=>n.id===e)},get isVIETheFirstView(){return t.current.length===0||!t.idOfVIE?!1:t.current[0].id===t.idOfVIE},get firstVisibleView(){const[e]=t.visibleViewIDs;return t.current.find(({id:n})=>n===e)},get visibleViews(){const e=new Set(t.visibleViewIDs);return t.current.filter(({id:n})=>e.has(n))},get VIE(){return t.current.find(({id:e})=>e===t.idOfVIE)},get options(){return t.current.map(e=>({label:e.name,value:e.id,type:e.type}))},get editorOptions(){const e=b.getRoot(t).content.panels;return t.current.map(n=>({label:n.name,value:n.id,_type:"view",children:e.editorOptions(n.id,n.panelIDs)}))}})).actions(t=>({replace(e){t.current.replace(e)},addANewView(e,n,r,a){t.current.push({id:e,name:n,type:r,config:a,panelIDs:[]})},append(e){t.current.push(e)},remove(e){t.current.splice(e,1)},removeByID(e){const n=t.current.findIndex(r=>r.id===e);n!==-1&&t.current.splice(n,1)},replaceByIndex(e,n){t.current.splice(e,1,n)},setIDOfVIE(e){t.idOfVIE=e,t.visibleViewIDs.length=0,t.visibleViewIDs.push(e)},appendToVisibles(e){new Set(t.visibleViewIDs.map(r=>r)).has(e)||t.visibleViewIDs.push(e)}})).actions(t=>({addARandomNewView(){const e=new Date().getTime().toString();t.addANewView(e,H.Division,H.Division,{_name:H.Division}),t.setIDOfVIE(e)},removeVIE(){t.current.length!==1&&(t.removeByID(t.idOfVIE),t.setIDOfVIE(t.current[0].id))},rmVisibleViewID(e){const n=t.visibleViewIDs.findIndex(r=>r===e);n!==-1&&t.visibleViewIDs.splice(n,1)}}));function Si(t){const e=t.length>0?[t[0].id]:[],n=t.length>0?t[0].id:"";return{current:t.map(a=>{const{_name:o=a.type}=a.config;return{...a,config:{...a.config,_name:o},panelIDs:a.panelIDs}}),visibleViewIDs:e,idOfVIE:n}}function al(t,e,n,r){return t.reduce((a,o)=>(a[o[e]]=pr(o[n],r),a),{})}const zC=b.types.model({id:b.types.string,name:b.types.string,dashboard_id:b.types.string,create_time:b.types.string,update_time:b.types.string,version:b.types.string,filters:rs,queries:cs,sqlSnippets:ps,views:il,panels:Jo,mock_context:Yu,origin:b.types.maybe(b.types.frozen())}).views(t=>({get json(){return{id:t.id,name:t.name,create_time:t.create_time,update_time:t.update_time,dashboard_id:t.dashboard_id,content:{views:t.views.json,panels:t.panels.json,filters:t.filters.json,version:t.version,definition:{queries:t.queries.json,sqlSnippets:t.sqlSnippets.json,mock_context:t.mock_context.current}}}},get filtersChanged(){const e="filters.current";return!x.isEqual(b.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get queriesChanged(){const e="queries.current",n=b.getSnapshot(x.get(t,e)).map(r=>x.pick(r,["id","name","key","type","sql","run_by","react_to","pre_process","post_process"]));return!x.isEqual(n,x.get(t.origin,e))},get sqlSnippetsChanged(){const e="sqlSnippets.current";return!x.isEqual(b.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get viewsChanged(){const e="views.current";return!x.isEqual(b.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get panelsChanged(){const e="panels.list";return!x.isEqual(b.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get mockContextChanged(){const e="mock_context.current";return!x.isEqual(x.get(t,e),x.get(t.origin,e))},get payloadForSQL(){const e=b.getParent(t).context.current,n=b.getParent(t).globalSQLSnippets,r={context:{...t.mock_context.current,...e},filters:t.filters.values};return{...r,sql_snippets:al(t.sqlSnippets.current,"key","value",r),global_sql_snippets:al(n.list,"id","content",r)}},get payloadForViz(){const e=b.getParent(t).context.current;return{context:{...t.mock_context.current,...e},filters:t.filters.values}},get changed(){return this.filtersChanged||this.queriesChanged||this.sqlSnippetsChanged||this.viewsChanged||this.panelsChanged||this.mockContextChanged},get data(){return t.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(e){const n=t.queries.findByID(e);return n?{data:n.data.toJSON(),len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).views(t=>({findQueryUsage(e){const n=t.panels.idMap,r=t.views.current.flatMap(l=>l.panelIDs.map(u=>n.get(u)).filter(u=>(u==null?void 0:u.queryIDSet.has(e))??!1).map(u=>({type:"panel",id:u.id,label:u.title?u.title:u.viz.type,views:[{id:l.id,label:l.name}]}))),a=t.views.idMap,o=t.filters.current.filter(l=>x.get(l,"config.options_query_id")===e).map(l=>({type:"filter",id:l.id,label:l.label,views:l.visibleInViewsIDs.map(u=>{var c;return{id:u,label:((c=a.get(u))==null?void 0:c.name)??u}})}));return r.concat(o)}})).actions(t=>({duplicatePanelByID(e,n){var a;const r=t.panels.duplicateByID(e);r&&((a=t.views.findByID(n))==null||a.appendPanelID(r))},removePanelByID(e,n){var r;t.panels.removeByID(e),(r=t.views.findByID(n))==null||r.removePanelID(e)},addANewPanel(e){var r;const n=new Date().getTime().toString();t.panels.append(Xo(n)),(r=t.views.findByID(e))==null||r.appendPanelID(n)}})).actions(t=>({reset(){b.applySnapshot(t.filters.current,t.origin.filters.current),b.applySnapshot(t.queries.current,t.origin.queries.current),b.applySnapshot(t.sqlSnippets.current,t.origin.sqlSnippets.current),b.applySnapshot(t.views.current,t.origin.views.current),b.applySnapshot(t.panels.list,t.origin.panels.list),t.mock_context.current=t.origin.mock_context.current},resetFilters(){b.applySnapshot(t.filters.current,t.origin.filters.current)},updateCurrent(e){const{id:n,name:r,content:a}=e;if(!a)throw new Error("unexpected null content when updating a content model");const{version:o,filters:l,views:u,panels:c,definition:{queries:d,sqlSnippets:f,mock_context:h={}}}=a;t.id=n,t.name=r,t.version=o,b.applySnapshot(t.filters.current,l),b.applySnapshot(t.views.current,Si(u).current),b.applySnapshot(t.panels.list,c),b.applySnapshot(t.queries.current,d),b.applySnapshot(t.sqlSnippets.current,f),t.mock_context.current=h}})),Zn=b.types.snapshotProcessor(zC,{preProcessor(t){return{...t,origin:t}},postProcessor(t){delete t.origin;const e=b.castToSnapshot(t.queries.current.map(n=>x.pick(n,["id","key","type","sql"])));return x.defaults({},{queries:{current:e}},t)}});function $C(t,e){e.filters&&b.applySnapshot(t.filters.current,e.filters)}function sl({id:t,name:e,dashboard_id:n,create_time:r,update_time:a,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:l,filters:u,views:c,panels:d,definition:{queries:f,sqlSnippets:h,mock_context:g={}}}=o;return Zn.create({id:t,name:e,dashboard_id:n,create_time:r,update_time:a,version:l,filters:is(u),queries:{current:f},sqlSnippets:{current:h},mock_context:{current:g},views:Si(c),panels:{list:d}})}const LC=b.types.model({id:b.types.string,content:b.types.string,create_time:b.types.string,update_time:b.types.string,is_preset:b.types.boolean}),OC=b.types.model("GlobalSQLSnippetsModel",{list:b.types.optional(b.types.array(LC),[])}).views(t=>({find(e){return t.list.find(n=>n.id===e)},get options(){return t.list.map(e=>({value:e.id,label:e.id}))}})).actions(t=>({replace(e){t.list.length=0,t.list.push(...e)}})),ol=b.types.model({id:b.types.identifier,name:b.types.string,group:b.types.string,content:Zn,content_id:b.types.string,datasources:Wu,globalSQLSnippets:OC,context:hs,editor:Ru}).views(t=>({get json(){return{id:t.id,name:t.name,group:t.group,content_id:t.content_id}}})).actions(t=>({updateCurrentContent(e){t.content.updateCurrent(e)},updateCurrent(e,n){const{id:r,name:a,group:o,content_id:l}=e;t.id=r,t.name=a,t.group=o,t.content_id=l,this.updateCurrentContent(n)}}));function _i({id:t,name:e,group:n,content_id:r},a,o,l,u){return ol.create({id:t,name:e,group:n,content_id:r,content:sl(a),datasources:{list:o},globalSQLSnippets:{list:l},context:{current:u},editor:{}})}const ki=y.createContext(null);function Hn(t){const e=y.useContext(ki),n=X.useCreation(()=>t.configure(e||new xr),[t.configure]),r=X.usePrevious(n);return r&&r!==n&&r.dispose(),i(ki.Provider,{value:n,children:t.children})}function ll(){return y.useContext(ki)}const PC={viewPanelInFullScreen:x.noop,inFullScreen:!1},Ti=y.createContext(PC),BC=({description:t,isDescriptionEmpty:e})=>e?null:i(s.Tooltip,{color:"white",label:i(Kn,{value:t,styles:{root:{border:"none"},content:{padding:0}}}),styles:{tooltip:{border:"0.0625rem solid rgb(233, 236, 239)",boxShadow:"rgb(0 0 0 / 5%) 0px 0.0625rem 0.1875rem, rgb(0 0 0 / 5%) 0px 1.25rem 1.5625rem -0.3125rem, rgb(0 0 0 / 4%) 0px 0.625rem 0.625rem -0.3125rem"}},withArrow:!0,children:i(s.Box,{sx:{height:"16px",alignSelf:"center"},children:i(L.IconInfoCircle,{size:16,color:"gray"})})}),VC=k.observer(({label:t,config:{default_value:e,description:n,isDescriptionEmpty:r,...a},value:o,onChange:l})=>p(s.Box,{children:[i(s.Text,{children:" "}),i(s.Checkbox,{label:p(s.Group,{noWrap:!0,position:"apart",align:"middle",spacing:6,children:[i(s.Box,{sx:{flexGrow:1},children:t}),i(BC,{description:n,isDescriptionEmpty:r})]}),checked:o||!1,onChange:u=>l(u.currentTarget.checked),...a,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),ul=k.observer(({label:t,config:e,value:n=[null,null],onChange:r})=>{const{inputFormat:a,...o}=e,l=Array.isArray(n)?n.map(f=>f?R(f).toDate():null):[null,null],u=f=>{r(f.map(h=>h&&R(h).format(a)))},c=e.getMinDate(l[0]),d=e.getMaxDate(l[0]);return i(ru.DatePickerInput,{type:"range",label:t,value:l,onChange:u,icon:i(D.Calendar,{size:16}),sx:{minWidth:"16em"},minDate:c,maxDate:d,valueFormat:a,styles:{input:{borderColor:"#e9ecef"}},...o})}),NC=s.createStyles((t,{radius:e=4})=>({root:{borderRadius:t.fn.radius(e),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-select.rc-select-open":{borderColor:"#228be6 !important",".rc-select-selection-overflow-item-rest":{display:"none"},".rc-select-selection-overflow-item-suffix":{display:"block"}},".rc-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-select-selection-search-mirror":{display:"none"},".rc-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:t.fontSizes.sm,fontWeight:500,color:"#212529"},dropdown:{fontSize:t.fontSizes.xs,zIndex:300,backgroundColor:"#fff",border:"1px solid #e9ecef",marginTop:6,padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px","&.rc-select-dropdown-slide-up-leave-active":{display:"none"},".rc-select-item-empty":{padding:"8px 12px"},".rc-select-item-option":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px 8px 2px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},flexDirection:"row-reverse",".rc-select-item-option-state":{flexGrow:0,flexShrink:0,width:"30px",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},".rc-select-item-option-content":{flexGrow:1}}}})),cl=({errorMessage:t})=>t?i(s.Text,{color:"red",size:12,children:t}):i(s.Text,{color:"dimmed",size:12,children:"Not found"}),qC=({disabled:t,classNames:e,styles:n,unstyled:r,radius:a,style:o,label:l,value:u,onChange:c,options:d,errorMessage:f})=>{const{classes:h,cx:g}=NC({radius:a},{name:"MultiSelectWidget",classNames:e,styles:n,unstyled:r}),[m,w]=y.useState(!1),C=B=>{w(B)},_=m&&(u==null?void 0:u.length)>0,[T,I]=y.useState(""),O=y.useMemo(()=>{if(!T)return d;const B=T.toLowerCase(),$=A=>{var E;return((E=A.description)==null?void 0:E.toLowerCase().includes(B))||A.label.toLowerCase().includes(B)};return d.filter($)},[T,d]);return p(s.Stack,{spacing:3,children:[p(s.Group,{position:"apart",children:[i(s.Text,{className:h.label,children:l}),_&&i(s.Tooltip,{label:`${u.length} selected`,children:i(s.Badge,{children:u.length})})]}),i(Na,{disabled:t,allowClear:!0,className:g(h.root,"check-select"),dropdownClassName:g(h.dropdown,""),onDropdownVisibleChange:C,transitionName:"rc-select-dropdown-slide-up",choiceTransitionName:"rc-select-selection__choice-zoom",style:o,clearIcon:()=>i(s.CloseButton,{}),value:u,onChange:c,onSelect:console.log,mode:"multiple",maxTagCount:0,notFoundContent:i(cl,{errorMessage:f}),maxTagTextLength:10,maxTagPlaceholder:B=>`${B.length} selected`,searchValue:T,onSearch:I,filterOption:!1,children:O.map(B=>i(Na.Option,{children:i(s.Group,{noWrap:!0,children:p("div",{children:[i(s.Text,{size:"sm","data-role":"label",children:B.label}),B.description&&i(s.Text,{size:"xs",color:"dimmed","data-role":"description",children:B.description})]})})},B.value))})]})},FC=k.observer(({label:t,config:e,value:n,onChange:r})=>{const a=K(),o=!!e.options_query_id,{state:l,error:u}=a.getDataStuffByID(e.options_query_id),c=l==="loading",d=e.min_width?e.min_width:"200px",f=o?c:!1,h=g=>r(g,!1);return i(qC,{label:t,options:e.options,style:{minWidth:"160px",width:d,maxWidth:f?d:"unset",borderColor:"#e9ecef"},disabled:f,value:n,onChange:h,errorMessage:u})}),GC=y.forwardRef(({label:t,description:e,...n},r)=>i("div",{ref:r,...n,children:i(s.Group,{noWrap:!0,children:p("div",{children:[i(s.Text,{size:"sm","data-role":"label",children:t}),i(s.Text,{size:"xs",color:"dimmed","data-role":"description",children:e})]})})})),WC=k.observer(({label:t,config:e,value:n,onChange:r})=>{const a=K(),o=!!e.options_query_id,{state:l,error:u}=a.getDataStuffByID(e.options_query_id),c=l==="loading";return y.useEffect(()=>{var h;const{default_selection_count:d}=e;if(!d)return;const f=((h=e.options[0])==null?void 0:h.value)??"";console.log("Selecting the first option by default. New value: ",f),r(f,!0)},[e.default_selection_count,e.options]),i(s.Select,{label:t,data:e.options,disabled:o?c:!1,value:n,onChange:r,error:!!u,placeholder:u,maxDropdownHeight:500,styles:{root:{width:e.width?e.width:"200px"},input:{borderColor:"#e9ecef"}},sx:{".mantine-Select-item[data-selected] .mantine-Text-root[data-role=description]":{color:"rgba(255,255,255,.7)"}},itemComponent:GC})});function jC({label:t,config:e,value:n,onChange:r}){return i(s.TextInput,{label:t,value:n||"",onChange:a=>r(a.currentTarget.value),...e,styles:{input:{borderColor:"#e9ecef"}}})}const RC=({rotate:t,onClick:e})=>i("svg",{onClick:e,className:"caret-icon",viewBox:"0 0 1024 1024",focusable:"false","data-icon":"caret-down",width:"14px",height:"14px",fill:"currentColor","aria-hidden":"true",transform:`rotate(${t})`,children:i("path",{d:"M840.4 300H183.6c-19.7 0-30.7 20.8-18.5 35l328.4 380.8c9.4 10.9 27.5 10.9 37 0L858.9 335c12.2-14.2 1.2-35-18.5-35z"})}),YC=({expanded:t,isLeaf:e,value:n,onClick:r,...a})=>(n==="0-0-value"&&console.log(a),e?i("span",{style:{width:"14px",display:"inline-block"}}):i(RC,{rotate:t?"0":"-90",onClick:r,...a})),QC=({onClick:t})=>p("svg",{onClick:t,className:"checkbox-icon",width:"16",height:"16",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[i("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),i("rect",{className:"border",x:"4",y:"4",width:"16",height:"16",rx:"2"}),i("rect",{className:"checkmark-indeterminate",x:"8",y:"8",width:"8",height:"8",rx:"2",stroke:"none"}),i("path",{className:"checkmark-checked",d:"M9 12l2 2l4 -4"})]}),KC=({onClick:t,...e})=>i(QC,{onClick:t,...e}),UC=s.createStyles((t,{radius:e=4})=>({root:{borderRadius:t.fn.radius(e),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-tree-select.rc-tree-select-open":{borderColor:"#228be6 !important",".rc-tree-select-selection-overflow-item-rest":{display:"none"},".rc-tree-select-selection-overflow-item-suffix":{display:"block"}},".rc-tree-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-tree-select-selection-search-mirror":{display:"none"},".rc-tree-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-tree-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-tree-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-tree-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-tree-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-tree-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-tree-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-tree-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:t.fontSizes.sm,fontWeight:500,color:"#212529"},dropdown:{fontSize:t.fontSizes.xs,zIndex:300,paddingTop:"6px","&.rc-tree-select-dropdown-slide-up-leave-active":{display:"none"},".rc-tree-select-tree-list .rc-tree-select-tree-list-holder":{},".rc-tree-select-tree-list, .rc-tree-select-empty":{backgroundColor:"#fff",border:"1px solid #e9ecef",padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px"},".rc-tree-select-empty":{padding:"8px 12px"},".rc-tree-select-tree-treenode":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},"&.rc-tree-select-tree-treenode-checkbox-checked":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-checked":{stroke:"rgb(64, 192, 87)",animation:"check 200ms linear forwards"}},"&.rc-tree-select-tree-treenode-checkbox-indeterminate":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-indeterminate":{fill:"rgb(64, 192, 87)"}},".rc-tree-select-tree-switcher":{height:"16px",alignSelf:"center",paddingRight:"2px",transition:"color 200ms ease","&:hover":{color:"#228be6","svg.caret-icon":{color:"#228be6"}},"svg.caret-icon":{color:"#ced4da",transition:"all 200ms ease"}},".rc-tree-select-tree-node-content-wrapper":{display:"flex",flexWrap:"nowrap",overflow:"hidden",alignItems:"center",gap:"8px",transition:"color 200ms ease","&:hover":{color:"#228be6"}},".rc-tree-select-tree-iconEle":{height:"16px","svg .border":{stroke:"#ced4da"},".checkbox-icon .checkmark-indeterminate":{fill:"transparent",transition:"fill 200ms ease"},".checkbox-icon .checkmark-checked":{transform:"scale(1.2)",transformOrigin:"center center",strokeDasharray:10,strokeDashoffset:-10},"@keyframes check":{"0%":{strokeDashoffset:10},"100%":{strokeDashoffset:0}}},".rc-tree-select-tree-title":{textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden",".rc-tree-select-tree-title-desc":{fontSize:"12px",maxWidth:"100%",textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"}},".rc-tree-select-tree-indent":{flexGrow:0,height:0,verticalAlign:"bottom"},".rc-tree-select-tree-indent-unit":{display:"inline-block",width:"1em"}}}})),XC=({disabled:t,classNames:e,styles:n,unstyled:r,radius:a,style:o,label:l,value:u,onChange:c,treeData:d,errorMessage:f})=>{const{classes:h,cx:g}=UC({radius:a},{name:"FilterTreeSelectWidget",classNames:e,styles:n,unstyled:r}),[m,w]=y.useState(!1),C=T=>{w(T)},_=m&&(u==null?void 0:u.length)>0;return p(s.Stack,{spacing:3,children:[p(s.Group,{position:"apart",children:[i(s.Text,{className:h.label,children:l}),_&&i(s.Tooltip,{label:`${u.length} selected`,children:i(s.Badge,{children:u.length})})]}),i(qa,{disabled:t,allowClear:!0,className:g(h.root,"check-select"),dropdownClassName:g(h.dropdown,""),onDropdownVisibleChange:C,transitionName:"rc-tree-select-dropdown-slide-up",choiceTransitionName:"rc-tree-select-selection__choice-zoom",style:o,treeLine:!0,clearIcon:()=>i(s.CloseButton,{}),switcherIcon:YC,treeIcon:KC,maxTagTextLength:10,value:u,treeData:d,notFoundContent:i(cl,{errorMessage:f}),treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:qa.SHOW_PARENT,onChange:c,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:T=>`${T.length} selected`})]})},JC=k.observer(({label:t,config:e,value:n,onChange:r})=>{const{treeData:a,treeDataLoading:o,errorMessage:l}=e,u=e.min_width?e.min_width:"200px",d=!!e.options_query_id?o:!1;return i(XC,{disabled:d,style:{minWidth:"160px",width:u,maxWidth:d?u:"unset",borderColor:"#e9ecef"},value:n,onChange:f=>r(f,!1),treeData:a,errorMessage:l,label:t})}),ZC=k.observer(({filter:{type:t,config:e,key:n,...r},formFieldProps:a})=>{switch(t){case"select":return i(WC,{...r,...a,config:e});case"multi-select":return i(FC,{...r,...a,config:e});case"tree-select":return i(JC,{...r,...a,config:e});case"text-input":return i(jC,{...r,...a,config:e});case"date-range":return i(ul,{...r,...a,config:e});case"checkbox":return i(VC,{...r,...a,config:e});default:return null}}),dl=k.observer(y.forwardRef(({filter:t,...e},n)=>i("div",{className:"filter-root",ref:n,children:i(Fe,{children:i(ZC,{filter:t,formFieldProps:e})})}))),pl=k.observer(function({view:e}){const n=K(),{control:r,handleSubmit:a,reset:o}=v.useForm({defaultValues:n.filters.values,reValidateMode:"onBlur"}),l=v.useWatch({control:r});y.useEffect(()=>{o(n.filters.values)},[n.filters.values,o]),y.useEffect(()=>{n.filters.updatePreviewValues(l)},[l]);const u=n.filters.visibleInView(e.id),c=y.useMemo(()=>u.every(g=>g.should_auto_submit),[u]),d=y.useMemo(()=>u.filter(g=>x.get(g,"config.required",!1)),[u]),f=y.useMemo(()=>d.length===0?!1:d.some(g=>!g.requiredAndPass(l[g.key])),[l,d]);if(u.length===0)return null;const h=(g,m)=>(w,C)=>{m(w),(g.should_auto_submit||C)&&n.filters.setValueByKey(g.key,w)};return i("form",{onSubmit:a(n.filters.setValues),children:p(s.Group,{className:"dashboard-filters",position:"apart",noWrap:!0,sx:c?{}:{border:"1px solid #e9ecef",borderRadius:"4px",padding:"16px"},children:[i(s.Group,{align:"flex-start",children:u.map(g=>i(v.Controller,{name:g.key,control:r,render:({field:m})=>i(dl,{filter:g,value:m.value,onChange:h(g,m.onChange)})},g.id))}),!c&&i(s.Group,{sx:{alignSelf:"flex-end"},children:i(s.Button,{color:"blue",size:"sm",type:"submit",disabled:f,children:"Search"})})]})})}),yD="";function HC(t){return t?["<p><br></p>","<p></p>"].includes(t):!0}const hl=k.observer(()=>{const{freezeLayout:t}=y.useContext(ft),[e,n]=y.useState(!1),{panel:r}=ze();return y.useEffect(()=>{t(e)},[e]),HC(r.description)?null:p(V,{children:[i(s.Modal,{opened:e,onClose:()=>n(!1),title:r.title,withCloseButton:!1,withinPortal:!0,zIndex:310,children:i(Kn,{value:r.description,styles:{root:{border:"none"},content:{padding:0}}})}),i(s.Tooltip,{label:"Click to see description",position:"top-start",withinPortal:!0,children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>n(a=>!a),sx:{verticalAlign:"baseline",cursor:"pointer"},children:i(D.InfoCircle,{size:20})})})]})}),e1=k.observer(({view:t})=>{const e=he(),n=K(),r=Ue.useModals(),{panel:a}=ze(),{id:o}=a,{inEditMode:l}=y.useContext(ft),{viewPanelInFullScreen:u,inFullScreen:c}=y.useContext(Ti),d=()=>{n.duplicatePanelByID(o,t.id)},f=()=>{e.editor.open(["_VIEWS_",t.id,"_PANELS_",o])},h=()=>r.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.removePanelByID(o,t.id),confirmProps:{color:"red"},zIndex:320}),g=y.useCallback(()=>{u(o)},[o,u]),m=!c&&t.type!==H.Modal;return i(V,{children:i(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:p(s.Menu,{withinPortal:!0,children:[i(s.Menu.Target,{children:i(s.Box,{className:"panel-dropdown-target",sx:{width:"100%",height:"25px"}})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{onClick:a.refreshData,icon:i(D.Refresh,{size:14}),children:"Refresh"}),i(s.Menu.Item,{onClick:a.downloadData,icon:i(D.Download,{size:14}),children:"Download Data"}),m&&i(s.Menu.Item,{onClick:g,icon:i(D.ArrowsMaximize,{size:14}),disabled:l,children:"Full Screen"}),l&&p(V,{children:[i(s.Divider,{label:"Edit",labelPosition:"center"}),i(s.Menu.Item,{onClick:f,icon:i(D.Settings,{size:14}),children:"Settings"}),i(s.Menu.Item,{onClick:d,icon:i(D.Copy,{size:14}),children:"Duplicate"}),i(s.Menu.Item,{color:"red",onClick:h,icon:i(D.Trash,{size:14}),children:"Delete"})]})]})]})})})}),t1=k.observer(({panel:t})=>p(s.Stack,{children:[t.queryErrors.map((e,n)=>i(s.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e},`${n}-${e}`)),t.queryStateMessages.map((e,n)=>i(s.Text,{color:"gray",align:"center",children:e},`${n}-${e}`))]}));var fl=(t=>(t.migrated="migrated",t.nothingToMigrate="nothingToMigrate",t.checkFailed="checkFailed",t.migrationFailed="migrationFailed",t))(fl||{}),er=(t=>(t.notStarted="notStarted",t.inProgress="inProgress",t.done="done",t))(er||{});class n1{constructor(e){N(this,"vizInstance");N(this,"operationManager");N(this,"triggerManager");N(this,"vizManager");N(this,"runningMigration");N(this,"panelModel");N(this,"status","notStarted");this.panelModel=e.getRequired(Ce.instanceScope.panelModel),this.vizInstance=e.getRequired(Ce.instanceScope.vizInstance),this.operationManager=e.getRequired(Ce.instanceScope.operationManager),this.triggerManager=e.getRequired(Ce.instanceScope.triggerManager),this.vizManager=e.getRequired(Ce.vizManager)}async createMigrationTask(){const e=[];try{await this.instanceNeedMigration()&&e.push(()=>this.runInstanceMigration()),await this.interactionNeedMigration()&&e.push(()=>this.runInteractionMigration())}catch(n){return console.warn("check migration failed",n),"checkFailed"}if(e.length===0)return"nothingToMigrate";try{return await Promise.all(e.map(n=>n())),"migrated"}catch(n){return console.warn("migration failed",n),"migrationFailed"}}async runMigration(){return this.runningMigration||(this.status="inProgress",this.runningMigration=this.createMigrationTask().then(e=>(this.status="done",e))),this.runningMigration}async runInteractionMigration(){await this.operationManager.runMigration(),await this.triggerManager.runMigration()}async runInstanceMigration(){const e=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData,panelModel:this.panelModel};await e.migrator.migrate(n)}async instanceNeedMigration(){const e=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData};return e.migrator.needMigration(n)}async interactionNeedMigration(){return await this.operationManager.needMigration()||await this.triggerManager.needMigration()}}function gl(t){const{panel:e}=ze();return y.useCallback(n=>{const r=n.getRequired(Ce.vizManager),a=r.resolveComponent(t.viz.type);return n.createScoped().provideFactory(Ce.instanceScope.vizInstance,()=>r.getOrCreateInstance(t)).provideFactory(Ce.instanceScope.interactionManager,o=>{const l=o.getRequired(Ce.instanceScope.vizInstance);return new yi(l,a,Jn)}).provideFactory(Ce.instanceScope.operationManager,o=>o.getRequired(Ce.instanceScope.interactionManager).operationManager).provideFactory(Ce.instanceScope.triggerManager,o=>o.getRequired(Ce.instanceScope.interactionManager).triggerManager).provideValue(Ce.instanceScope.panelModel,e).provideFactory(Ce.instanceScope.migrator,o=>new n1(o))},[t.viz.type,t.viz.conf])}function ml(t){const[e,n]=y.useState(!1),r=ll().getRequired(Ce.instanceScope.migrator);return X.useAsyncEffect(async()=>{const a=r.status===er.notStarted;n(r.status===er.done),r.status===er.notStarted&&r.runMigration().then(o=>{o===fl.migrated&&a&&(t==null||t())}).finally(()=>{n(!0)})},[r]),e}function yl(t,e){const n=ll().getRequired(Ce.instanceScope.vizInstance);return y.useEffect(()=>(n.instanceData.setItem(null,e.viz.conf),n.instanceData.watchItem(null,r=>{t(r)})),[t,e.viz.type]),n}function r1({setVizConf:t,...e}){const{panel:n}=e,r=yl(t,n),a=ml(()=>{hn.showNotification({title:`${n.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return X.useAsyncEffect(async()=>{await r.instanceData.setItem(null,n.viz.conf)},[r,n.viz.type]),a?i(ec,{...e}):i(s.Text,{children:"Checking update..."})}function i1(t){const{panel:e,setVizConf:n}=t;yl(n,e);const{inEditMode:r}=y.useContext(ft);return ml(()=>{r&&hn.showNotification({title:`${e.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?i(Hu,{...t}):i(s.Text,{children:"Checking update"})}const bD="";function a1(t,e){const{vizManager:n}=y.useContext(at),{panel:{viz:r,title:a,id:o,description:l,queryIDs:u,variables:c}}=ze(),d={title:a,id:o,description:l,queryIDs:u,viz:r,layout:e},f=gl(d);try{return n.resolveComponent(r.type),i(Hn,{configure:f,children:i(i1,{setVizConf:r.setConf,panel:d,data:t,variables:c,vizManager:n})})}catch(h){return console.info(x.get(h,"message")),null}}const s1=k.observer(function({data:e}){const{ref:n,width:r,height:a}=Me.useElementSize(),o=a1(e,{w:r,h:a}),l=r>0&&a>0;return i("div",{className:"viz-root",ref:n,children:l&&i(Fe,{children:o})})}),bl=k.observer(({panel:t,height:e})=>p(s.Flex,{direction:"column",sx:{height:e,position:"relative",width:"100%"},children:[i(s.LoadingOverlay,{visible:t.dataLoading,exitTransitionDuration:0}),!t.canRenderViz&&i(t1,{panel:t}),t.canRenderViz&&i(s1,{data:t.data})]})),vD="",o1=k.observer(function(){const{panel:e}=ze(),{title:n}=e;return n?i(s.Group,{grow:!0,position:"center",px:20,className:"panel-title-wrapper",sx:{flexGrow:1},children:i(s.Text,{align:"center",lineClamp:1,weight:"bold",children:n})}):null});function l1(t){return!["richText","button"].includes(t)}const u1={border:"1px solid #e9ecef"},c1={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function d1(t,e){return t.style.border.enabled?u1:e?c1:{border:"1px dashed transparent"}}const tr=k.observer(function({panel:e,view:n}){const{inEditMode:r}=y.useContext(ft),a=e.title?"calc(100% - 25px - 5px)":"100%",o=d1(e,r),u=l1(e.viz.type)||r;return i(Cr,{value:{panel:e,data:e.data,loading:e.dataLoading,errors:e.queryErrors},children:p(s.Box,{className:"panel-root",p:5,pt:0,sx:{...o},children:[i(s.Box,{sx:{position:"absolute",left:0,top:0,height:28,zIndex:310},children:i(hl,{})}),u&&i(e1,{view:n}),i(o1,{}),i(bl,{panel:e,height:a})]})})}),xD="",p1=y.forwardRef(({h:t},e)=>i(s.ActionIcon,{ref:e,className:"react-grid-customDragHandle",sx:{userSelect:"none",cursor:"grab",position:"absolute",top:5,right:t>38?5:20,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",children:i(D.ArrowsMove,{size:16})})),h1=y.forwardRef(({handleAxis:t,...e},n)=>i(s.ActionIcon,{ref:n,className:"react-grid-customResizeHandle",sx:{userSelect:"none",cursor:"nwse-resize",position:"absolute",bottom:0,right:0,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",...e,children:i(D.ChevronDownRight,{size:16})})),f1=fn.WidthProvider(fn),g1=k.observer(({view:t,className:e="layout"})=>{const n=K(),{panels:r,layouts:a}=n.panels.panelsByIDs(t.panelIDs),o=y.useCallback(u=>{u.forEach(({i:c,...d})=>{const f=n.panels.findByID(c);f&&f.layout.set(d)})},[n]),l=(u,c,d,f)=>{d.h<30&&(d.h=30,f.h=30),d.w<4&&(d.w=4,f.w=4)};return i(f1,{onLayoutChange:o,className:`dashboard-layout ${e}`,rowHeight:1,cols:36,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,layout:a,draggableHandle:".react-grid-customDragHandle",resizeHandle:i(h1,{}),onResize:l,children:r.map((u,c)=>p("div",{"data-grid":{...u.layout},className:"panel-grid-item",children:[i(p1,{h:u.layout.h}),i(tr,{view:t,panel:u})]},u.id))})}),m1=fn.WidthProvider(fn),y1=k.observer(function({view:e,className:n="layout"}){const{panels:r,layouts:a}=K().panels.panelsByIDs(e.panelIDs);return i(m1,{className:`dashboard-layout ${n}`,cols:36,rowHeight:1,margin:[0,0],isDraggable:!1,isResizable:!1,layout:a,children:r.map(o=>i("div",{"data-grid":{...o.layout},className:"panel-grid-item",children:i(tr,{view:e,panel:o})},o.id))})}),b1=k.observer(({children:t})=>i(s.Box,{pt:10,pb:100,children:t}));function vl(t){return t.replace(/(vw|vh)/,"%")}const v1=k.observer(({children:t,view:e})=>{const n=e.config,{width:r,height:a}=y.useMemo(()=>({width:vl(n.width),height:vl(n.height)}),[n.width,n.height]);return i(s.Box,{sx:{height:"100%","> div:not(.mantine-Modal-root)":{height:"100%"}},children:i(s.Modal,{size:n.width,opened:!0,onClose:x.noop,withCloseButton:!1,title:n.custom_modal_title.value,trapFocus:!0,onDragStart:o=>{o.stopPropagation()},styles:{root:{position:"relative",height:"100%"},overlay:{position:"absolute !important"},inner:{position:"relative",top:"50%",left:"50%",right:"unset",bottom:"unset",transform:"translate(-50%, -50%)",width:r,height:a},content:{border:"1px solid #efefef"},body:{maxHeight:"calc(100vh - 325px)"}},withinPortal:!1,transitionProps:{duration:0},children:t})})}),x1=({variant:t,orientation:e})=>{const n={tab:{},panel:{padding:"16px"}};return t==="pills"&&e==="horizontal"&&(n.tab.paddingTop="6px",n.tab.paddingBottom="6px"),e==="vertical"&&(n.tab["&.add-a-tab"]={paddingTop:"1px",paddingBottom:"1px"},n.tab["&.add-a-tab .mantine-Tabs-tabLabel"]={marginLeft:"auto",marginRight:"auto"}),n},w1=t=>t.color?{"&[data-active], &[data-active]:hover":{borderColor:t.color?t.color:"..."}}:{},C1=k.observer(({children:t,view:e})=>{const n=Ue.useModals(),r=K(),a=y.useMemo(()=>r.views.options.filter(c=>c.type===H.Division),[e.id,r.views.options]),o=e.config,l=c=>n.openConfirmModal({title:"Delete this tab?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{o.removeTab(c)},confirmProps:{color:"red"},zIndex:320}),u=o.tabs.length===0;return p(s.Box,{className:"preview-view-tabs",children:[p(s.Tabs,{variant:o.variant,orientation:o.orientation,defaultValue:o.tabs.length>0?o.tabs[0].id:"0",styles:x1(o),children:[p(s.Tabs.List,{grow:o.grow,children:[o.tabs.map(c=>i(s.Tabs.Tab,{value:c.id,sx:w1(c),children:c.name??c.id},c.id)),i(s.Tabs.Tab,{onClick:o.addTab,value:"add",className:"add-a-tab",children:i(D.Plus,{size:18,color:"#228be6"})})]}),o.tabs.map((c,d)=>{const f=r.views.findByID(c.view_id);return p(s.Tabs.Panel,{value:c.id,sx:{position:"relative"},children:[p(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:200},children:[i(s.Overlay,{opacity:.8,color:"#FFF",blur:10,zIndex:100}),p(s.Stack,{mx:"auto",mt:100,sx:{width:"300px",position:"relative",zIndex:200},children:[i(s.TextInput,{label:"Tab Name",value:c.name,onChange:h=>c.setName(h.currentTarget.value)}),i(s.Select,{label:"View",value:c.view_id,onChange:c.setViewID,data:a}),i(s.ColorInput,{label:"Color",value:c.color,onChange:c.setColor,disabled:o.variant!=="default"}),f&&p(s.Button,{mt:20,variant:"gradient",leftIcon:i(L.IconArrowsLeftRight,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>r.views.setIDOfVIE(f.id),children:["Swith to View: ",f.name]}),i(s.Button,{mt:20,variant:"subtle",color:"red",onClick:()=>l(d),disabled:u,leftIcon:i(L.IconTrash,{size:14}),children:"Delete This Tab"})]})]}),f&&i(nr,{view:f})]},c.id)})]}),t]})}),S1=k.observer(({view:t,children:e})=>{switch(t.type){case H.Modal:return i(v1,{view:t,children:e});case H.Tabs:return i(C1,{view:t,children:e});case H.Division:default:return i(b1,{children:e})}}),xl=k.observer(function({view:e}){return i(Ti.Provider,{value:{viewPanelInFullScreen:x.noop,inFullScreen:!1},children:i(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:i(S1,{view:e,children:p(s.Box,{sx:{position:"relative"},children:[i(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:i(pl,{view:e})}),i(g1,{view:e})]})})})})}),_1={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},k1=k.observer(function({view:e,panel:n,exitFullScreen:r}){return i(s.Modal,{opened:!0,fullScreen:!0,onClose:r,title:i(s.Button,{color:"blue",size:"xs",onClick:r,leftIcon:i(D.ArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:_1,children:i(s.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:i(tr,{view:e,panel:n})})})});function T1(t,e,n){const{panels:r}=K(),a=t.id==="Main",[o,l]=y.useState(()=>a&&r.findByID(e)?e:null),u=y.useCallback(h=>{l(h),a&&n(h)},[a,n]),c=y.useCallback(()=>{l(null),a&&n("")},[a,n]),d=o?r.findByID(o):null;return{viewPanelInFullScreen:u,exitFullScreen:c,inFullScreen:!!d,fullScreenPanel:d}}const D1=k.observer(({children:t})=>i(s.Box,{children:t})),M1=k.observer(({children:t,view:e})=>{const n=K(),r=e.config,a=n.views.visibleViewIDs.includes(e.id),o=()=>n.views.rmVisibleViewID(e.id);return i(s.Modal,{size:r.width,centered:!0,opened:a,onClose:o,withCloseButton:!1,title:r.custom_modal_title.value,trapFocus:!0,onDragStart:l=>{l.stopPropagation()},styles:{root:{position:"fixed",zIndex:200,inset:0},overlay:{zIndex:"unset"},inner:{zIndex:"unset"},content:{border:"1px solid #efefef"},body:{maxHeight:r.height,overflow:"auto"}},transitionProps:{duration:0},children:t})}),I1=t=>t.color?{"&[data-active], &[data-active]:hover":{borderColor:t.color?t.color:"..."}}:{},E1=k.observer(({children:t,view:e})=>{const n=K(),r=e.config;return p(s.Box,{className:"render-view-tabs",children:[p(s.Tabs,{variant:r.variant,orientation:r.orientation,defaultValue:r.tabs.length>0?r.tabs[0].id:"0",styles:{panel:{padding:r.orientation==="horizontal"?"16px 0px":"0"}},keepMounted:!1,children:[i(s.Tabs.List,{grow:r.grow,children:r.tabs.map(a=>i(s.Tabs.Tab,{value:a.id,sx:I1(a),disabled:!a.view_id,children:a.name??a.id},a.id))}),r.tabs.map(a=>{const o=n.views.findByID(a.view_id);return o?i(s.Tabs.Panel,{value:a.id,children:i(nr,{view:o})},a.id):null})]}),t]})}),A1=k.observer(({view:t,children:e})=>{switch(t.type){case H.Modal:return i(M1,{view:t,children:e});case H.Tabs:return i(E1,{view:t,children:e});case H.Division:default:return i(D1,{children:e})}}),nr=k.observer(function({view:e}){const{fullScreenPanelID:n,setFullScreenPanelID:r}=ws(),{viewPanelInFullScreen:a,exitFullScreen:o,inFullScreen:l,fullScreenPanel:u}=T1(e,n,r);return i(Ti.Provider,{value:{viewPanelInFullScreen:a,inFullScreen:l},children:p(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:[l&&i(k1,{view:e,panel:u,exitFullScreen:o}),i(A1,{view:e,children:p(s.Box,{sx:{position:"relative"},children:[!l&&i(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:i(pl,{view:e})}),!l&&i(y1,{view:e})]})})]})})});function Di(t){return y.useCallback(e=>e.provideValue(Ce.pluginManager,t.pluginManager).provideValue(Ce.vizManager,t.vizManager).provideValue(Ce.colorManager,t.colorManager),[])}const z1=k.observer(({headerMenuItems:t=null})=>{const e=he(),n=K(),r=()=>{const a=JSON.stringify(n.json,null,2),o=`${e.name}__${n.name}`;Au(o,a)};return p(s.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:310,children:[i(s.Menu.Target,{children:i(s.ActionIcon,{variant:"light",color:"blue",children:i(L.IconMenu2,{size:14})})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{icon:i(L.IconDownload,{size:14}),onClick:n.queries.downloadAllData,children:"Download Data"}),i(s.Menu.Item,{icon:i(L.IconCode,{size:14}),onClick:r,children:"Download Schema"}),t]})]})}),$1=k.observer(({saveDashboardChanges:t})=>{const e=Ue.useModals(),n=K(),r=()=>{e.openConfirmModal({title:p(s.Group,{position:"left",children:[i(L.IconAlertTriangle,{size:18,color:"red"}),i(s.Text,{children:"You are reverting changes"})]}),labels:{confirm:"Confirm",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.reset(),zIndex:320,withCloseButton:!1})},a=n.changed;return p(s.Group,{spacing:0,children:[i(s.Button,{color:"green",variant:"filled",size:"xs",leftIcon:i(L.IconDeviceFloppy,{size:18}),onClick:t,disabled:!a,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:"Save Changes"}),p(s.Menu,{width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:320,disabled:!a,children:[i(s.Menu.Target,{children:i(s.ActionIcon,{variant:"default",disabled:!a,sx:{height:"30px",borderTopLeftRadius:0,borderBottomLeftRadius:0,svg:{fill:"rgb(173, 181, 189)",stroke:"none"}},children:i(L.IconCaretDown,{size:18})})}),i(s.Menu.Dropdown,{children:i(s.Menu.Item,{icon:i(L.IconRecycle,{size:14,color:"red"}),disabled:!a,onClick:r,children:"Revert Changes"})})]})]})}),L1=k.observer(({saveDashboardChanges:t,headerSlot:e=null,headerMenuItems:n})=>{const r=iu.useNavigate(),a=he(),o=()=>{r(`/dashboard/${a.id}`)},l=Ue.useModals(),u=()=>{l.openConfirmModal({title:p(s.Group,{position:"left",children:[i(L.IconAlertTriangle,{size:18,color:"red"}),i(s.Text,{children:"There are unsaved changes"})]}),labels:{confirm:"Discard",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:o,zIndex:320,withCloseButton:!1})},c=a.content.changed;return i(s.Header,{height:60,px:"md",py:0,sx:{zIndex:299},children:p(s.Group,{position:"apart",sx:{height:60,minWidth:"1000px",position:"relative"},children:[p(s.Group,{children:[i(s.Button,{size:"xs",color:c?"red":"green",leftIcon:i(L.IconArrowLeft,{size:20}),onClick:c?u:o,children:p(s.Group,{spacing:4,children:["End Editing",i(s.Text,{td:"underline",children:a.name})]})}),i($1,{saveDashboardChanges:t})]}),p(s.Group,{position:"right",sx:{flexGrow:1},children:[e,i(z1,{headerMenuItems:n})]})]})})}),O1={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},P1=k.observer(()=>{const t=K();return i(s.Box,{sx:O1,pl:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},children:p(s.Group,{position:"apart",align:"center",sx:{height:"30px"},pr:16,children:[i(s.Button,{variant:"outline",color:"blue",radius:0,size:"xs",disabled:!t.views.VIE,onClick:()=>t.addANewPanel(t.views.idOfVIE),leftIcon:i(L.IconPlaylistAdd,{size:20}),sx:{height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef",background:"rgb(231, 245, 255)"},children:"Add a Panel"}),i(s.Box,{}),i(s.Box,{})]})})}),B1=k.observer(t=>p(V,{children:[i(L1,{...t}),i(P1,{})]})),wD="",CD="";function V1(t,e,n){const r=[];return t.filter(a=>"__INTERACTIONS"in a.viz.conf).forEach((a,o)=>{const l=e[a.id];l.data.interactions=x.get(l,"data.interactions",[]);const{__INTERACTIONS:u,__OPERATIONS:c,__TRIGGERS:d}=a.viz.conf;Object.entries(c).forEach(([f,h])=>{const{schemaRef:g,data:m}=h,{config:w}=m;switch(g){case"builtin:op:open-link":let C=w.urlTemplate.substring(0,100);w.urlTemplate.length>=20&&(C+="..."),l.type="interaction",l.data.interactions.push({schemaRef:g,urlTemplate:w.urlTemplate,shortURLTemplate:C});return;case"builtin:op:open_view":r.push({id:`OPERATION--${f}`,source:a.id,target:w.viewID,label:"Open View",style:{stroke:"rgba(0,0,0,0.8)"},type:"default"});return;case"builtin:op:set_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:g,filters:Object.keys(w.dictionary).map(_=>({key:_,label:n[_]}))});return;case"builtin:op:clear_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:g,filters:w.filter_keys.map(_=>({key:_,label:n[_]}))});return;default:return}})}),r}function N1(t,e){const n=t.filters.keyLabelMap;return{edges:V1(t.panels.list,e,n),edgeNodes:[]}}function wl(t,e,n){return t*e+t*n}function q1(t,e,n){return t*e+(t-1)*n}const rr=25,Mi=40,Cl=25,Ii=350,F1=150,G1=150,Sl=150,_l=300,ir=40,kl=25,W1=300;function j1(t,e){const n=x.keyBy(e,a=>a.id),r=[];return t.current.forEach((a,o)=>{a.panelIDs.forEach((l,u)=>{const c=wl(u,ir,kl)+Mi,d=n[l];if(!d){r.push({id:l,_node_type:"panel",parentNode:a.id,data:{label:`!: ${l}`},position:{x:rr,y:c},sourcePosition:Ee.Position.Right,targetPosition:Ee.Position.Left,style:{width:_l,height:ir}});return}const f=d.title.trim()?`${d.title}`:d.viz.type;r.push({id:d.id,_node_type:"panel",parentNode:a.id,data:{label:f},position:{x:rr,y:c},sourcePosition:Ee.Position.Right,targetPosition:Ee.Position.Left,style:{width:_l,height:ir}})})}),r}const R1={[H.Division]:"Div",[H.Modal]:"Modal",[H.Tabs]:"Tabs"},Y1=Ho;function Q1(t){return t.current.map((n,r)=>{const a=q1(n.panelIDs.length,ir,kl)+Mi+Cl;let o=[];return n.type===H.Tabs&&(o=n.config.tabs.map(u=>u.view_id)),{id:n.id,_node_type:"view-root",_view_type:n.type,_view_level:0,_sub_view_ids:[],_tab_view_ids:o,data:{label:`${R1[n.type]}:${n.name}`},position:{x:0,y:0},sourcePosition:Ee.Position.Right,targetPosition:Ee.Position.Left,className:"light",style:{backgroundColor:Y1[n.type],width:Ii,height:a}}})}function K1(t){const e=x.keyBy(t,n=>n.id);t.forEach(n=>{n._node_type!=="view-root"||n._view_type!==H.Tabs||n._tab_view_ids.forEach(r=>{e[r].parentNode=n.id})})}function U1(t){const e=Q1(t.views);K1(e);const n=j1(t.views,t.panels.list);return[...e,...n]}function X1({nodeMap:t,nodes:e,edges:n}){e.forEach(r=>{r._node_type!=="view-root"||r._view_type!==H.Tabs||(r.sourcePosition=Ee.Position.Bottom,r.style.width=Ii+rr*2,r.style.height=Cl+r._tab_view_ids.reduce((a,o)=>{const l=t[o];l.position.y=a,l.position.x=rr;const u=l.style.height;return a+u+20},Mi))})}function J1({nodeMap:t,nodes:e,edges:n}){n.filter(r=>r.label==="Open View").forEach(r=>{const a=t[r.source],o=t[r.target];if(!a||!o||!a.parentNode)return;const l=t[a.parentNode];l._node_type!=="view-root"||o._node_type!=="view-root"||(o._view_level+=1+l._view_level,l._sub_view_ids.push(o.id))}),e.sort((r,a)=>r._node_type==="view-root"&&a._node_type==="view-root"?r._view_level-a._view_level:r._node_type!=="view-root"&&a._node_type!=="view-root"?0:r._node_type==="view-root"?-1:1)}function Z1({nodeMap:t,nodes:e,edges:n}){const r={};n.forEach(a=>{if(a.label!=="Open View")return;const o=t[a.source],l=t[a.target];if(o&&l&&o.parentNode){const u=t[o.parentNode],c=u.position.x,d=Number(x.get(l,"style.height",0)),f=Number(u.style.width);l.position.x=c+f+W1,u._view_level===0&&l._sub_view_ids.length===0&&(o.sourcePosition=Ee.Position.Left,l.targetPosition=Ee.Position.Right,l.position.x*=-1);const g=l.position.x,m=x.get(r,g,0);l.position.y=m,r[g]=m+d+Sl}})}function H1({nodeMap:t,nodes:e,edges:n}){const r=new Set,a=new Set;n.forEach(l=>{r.add(l.source),a.add(l.target)}),e.filter(l=>l._node_type!=="view-root"||l.id==="Main"||l.parentNode?!1:!r.has(l.id)&&!a.has(l.id)).forEach((l,u)=>{l.position.x=wl(u,Ii,G1),l.position.y=0-F1-Sl})}function eS({nodeMap:t,nodes:e,edges:n}){const r={nodeMap:t,nodes:e,edges:n};return H1(r),J1(r),X1(r),Z1(r),{nodes:e,edges:n}}function tS(t){const e=U1(t),n=x.keyBy(e,c=>c.id),{edges:r,edgeNodes:a}=N1(t,n),o=[...e,...a],l=x.keyBy(o,c=>c.id),u={edges:x.uniqBy(r,c=>c.id),nodes:o,nodeMap:l};return eS(u)}const SD="",Ei={"builtin:op:open-link":i(s.ThemeIcon,{color:"blue",size:20,radius:"xl",children:i(L.IconCircleDashed,{size:14})}),"builtin:op:set_filter_values":i(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:i(L.IconCircleDot,{size:14})}),"builtin:op:clear_filter_values":i(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:i(L.IconCircleOff,{size:14})})};function nS(t){const e=[];return t.forEach(n=>{switch(n.schemaRef){case"builtin:op:open-link":e.push({key:n.urlTemplate,icon:Ei[n.schemaRef],text:p(s.Group,{spacing:4,children:[i(s.Text,{children:"Open: "}),i(s.Text,{color:"dimmed",children:n.shortURLTemplate})]})});return;case"builtin:op:set_filter_values":n.filters.forEach(({key:r,label:a})=>{e.push({key:n.schemaRef+r,icon:Ei[n.schemaRef],text:i(s.Group,{spacing:4,children:p(s.Text,{children:["Set Filter: ",a]})})})});return;case"builtin:op:clear_filter_values":n.filters.forEach(({key:r,label:a})=>{e.push({key:n.schemaRef+r,icon:Ei[n.schemaRef],text:i(s.Group,{spacing:4,children:p(s.Text,{children:["Clear Filter: ",a]})})})});return}}),e}const rS=y.memo(({data:t,isConnectable:e,sourcePosition:n=Ee.Position.Right,targetPosition:r=Ee.Position.Left,...a})=>{const o=y.useMemo(()=>nS(t.interactions),[t.interactions]);return p(V,{children:[i(Ee.Handle,{type:"target",position:r,isConnectable:e}),i(s.Box,{sx:{position:"absolute",top:0,right:0},children:i(D.ChevronsUpRight,{size:12})}),p(s.HoverCard,{shadow:"xl",withinPortal:!0,children:[i(s.HoverCard.Target,{children:i(s.Text,{children:t.label})}),i(s.HoverCard.Dropdown,{children:i(s.List,{spacing:"xs",size:"sm",center:!0,children:o.map(l=>i(s.List.Item,{icon:l.icon,children:l.text},l.key))})})]}),i(Ee.Handle,{type:"source",position:n,isConnectable:e})]})}),_D="",iS={interaction:rS},aS=k.observer(()=>{const t=K(),{edges:e,nodes:n}=tS(t);return p(Ee,{nodes:n,edges:e,onNodesChange:x.noop,onEdgesChange:x.noop,onConnect:x.noop,className:"interactions-viewer",fitView:!0,nodeTypes:iS,children:[i(Ee.MiniMap,{}),i(Ee.Controls,{}),i(Ee.Background,{})]})}),sS=k.observer(({opened:t,close:e})=>{const{freezeLayout:n}=y.useContext(ft);return y.useEffect(()=>{n(t)},[t]),i(s.Modal,{size:"96vw",opened:t,onClose:e,title:"Interactions",trapFocus:!0,onDragStart:r=>{r.stopPropagation()},styles:{body:{height:"90vh"},content:{transform:"none !important"}},zIndex:300,children:i(aS,{})})}),oS={"> button":{"&:first-of-type":{borderTopRightRadius:0,borderBottomRightRadius:0,borderRightWidth:.5},":not(:first-of-type):not(:last-of-type)":{borderTopRightRadius:0,borderBottomRightRadius:0,borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:.5,borderRightWidth:.5},"&:last-of-type":{borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:.5}}};function lS({onClick:t,name:e,active:n,openSettings:r}){return p(s.Box,{sx:{position:"relative"},children:[i(s.UnstyledButton,{sx:a=>({display:"block",width:"100%",padding:a.spacing.xs,borderRadius:0,position:"relative",color:a.black,"&:hover":{backgroundColor:a.colors.gray[0]},backgroundColor:n?a.colors.gray[2]:"transparent"}),children:i(s.Group,{sx:{width:"calc(100% - 28px)"},onClick:t,children:i(s.Text,{size:"sm",children:e})})}),n&&i(s.Tooltip,{label:"Edit",position:"right",withinPortal:!0,children:i(s.ActionIcon,{onClick:r,variant:"light",color:"blue",sx:{position:"absolute",top:0,bottom:0,height:"100%",right:0,zIndex:0,borderRadius:0},children:i(L.IconAdjustments,{size:16})})})]})}const uS=k.observer(()=>{const t=he(),e=K(),n=y.useCallback(a=>()=>e.views.setIDOfVIE(a),[e]),r=a=>{t.editor.open(["_VIEWS_",a])};return p(s.Box,{sx:{position:"relative"},children:[e.views.options.map(a=>i(lS,{active:e.views.idOfVIE===a.value,name:a.label,onClick:n(a.value),openSettings:()=>r(a.value)},a.value)),i(s.Divider,{variant:"dashed"}),i(s.Button,{variant:"subtle",rightIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",color:"blue",onClick:e.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"space-between"}},children:"Add a View"})]})}),cS=k.observer(()=>{const t=he(),e=K(),n=()=>{if(!e.queries.firstID){t.editor.open(["_QUERIES_",""]);return}t.editor.open(["_QUERIES_",e.queries.firstID])},r=()=>{if(!e.filters.firstID){t.editor.open(["_FILTERS_",""]);return}t.editor.open(["_FILTERS_",e.filters.firstID])},[a,o]=y.useState(!1),l=()=>o(!0),u=()=>o(!1);return p(s.Navbar,{p:0,width:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},zIndex:299,children:[p(s.Navbar.Section,{children:[p(s.Group,{grow:!0,spacing:0,sx:{...oS,button:{borderWidth:0,borderBottomWidth:1,borderColor:"#e9ecef"}},children:[i(s.Tooltip,{label:"Filters",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:r,children:i(L.IconFilter,{size:18})})}),i(s.Tooltip,{label:"Queries",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:n,children:i(L.IconDatabase,{size:18})})}),i(s.Tooltip,{label:"Interactions Viewer",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:l,children:i(L.IconLink,{size:18})})})]}),i(sS,{opened:a,close:u})]}),i(s.Navbar.Section,{py:5,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Views"})}),i(s.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:i(uS,{})}),i(s.Navbar.Section,{children:i(s.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:i(s.Button,{size:"xs",leftIcon:i(L.IconSettings,{size:20}),onClick:()=>t.editor.open([]),children:"Settings"})})})]})}),dS=k.observer(function({config:e}){return p(V,{children:[i(s.Checkbox,{checked:e.default_value,onChange:n=>e.setDefaultValue(n.currentTarget.checked),label:"Default Checked"}),i(ii,{label:"Description",value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}})]})}),pS=[{label:"2022",value:"YYYY"},{label:"202201",value:"YYYYMM"},{label:"20220101",value:"YYYYMMDD"},{label:"2022-01",value:"YYYY-MM"},{label:"2022-01-01",value:"YYYY-MM-DD"}],hS=k.observer(function({config:e}){return p(V,{children:[p(s.Group,{children:[i(s.Checkbox,{checked:e.required,onChange:n=>e.setRequired(n.currentTarget.checked),label:"Required"}),i(s.Checkbox,{checked:e.clearable,onChange:n=>e.setClearable(n.currentTarget.checked),disabled:e.max_days>0,label:"Clearable"}),i(s.Checkbox,{checked:e.allowSingleDateInRange,onChange:n=>e.setAllowSingleDateInRange(n.currentTarget.checked),label:"Allow choosing 1 day"})]}),i(s.Select,{data:pS,label:"Display Format",value:e.inputFormat,onChange:e.setInputFormat}),i(ul,{label:"Default Value",config:e,value:e.default_value,onChange:e.setDefaultValue}),i(s.NumberInput,{label:"Max Days",description:p(s.Group,{position:"apart",children:[i(s.Text,{children:"Set 0 to disable."}),p(s.Group,{spacing:4,children:[i(s.Text,{children:"This feature requires"}),i(s.Text,{color:"blue",children:"Clearable"}),i(s.Text,{children:"to be checked"})]})]}),min:0,value:e.max_days,onChange:e.setMaxDays,hideControls:!0})]})}),Ai=k.observer(({value:t,onChange:e})=>{const n=K(),r=y.useMemo(()=>n.queries.options,[n.queries.current]),a=r.length===0;return i(s.Select,{label:"Pick a query",data:r,value:t,onChange:e,allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:a,error:a?"You need to add a query in Data Settings":void 0})}),fS=`
416
+ `}},show_in_legend:!0}))}function _w(e,t,n,r){const a=q(t.data_key),o=t.name,l=n.map(u=>{const c=x.sumBy(r[u],a.columnKey);return[u,c]});return{type:"line",name:o,xAxisIndex:3,yAxisIndex:3,color:"#b41529",data:l,show_in_legend:!1}}function kw(e,t,n,r){const l={barMinWidth:5,barMaxWidth:20};return[vw(e,n,r),ww(e,n,r,l),...Sw(e,n,r,l),_w(e,t,n,r)]}function Tw(e,t){const{axisLabel:n}=e.x_axis;return[{data:t,id:"准确估算比例",gridIndex:0,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:t,id:"平均偏差",gridIndex:1,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!0,lineStyle:{color:"#FFFFFF",width:2}},type:"category"},{data:t,id:"数量占比",gridIndex:2,axisTick:{show:!1},axisLabel:{show:!1},axisLine:{show:!1},type:"category"},{data:t,id:"代码当量",gridIndex:3,axisTick:{show:!1},type:"category",axisLabel:{...n,formatter:Ds(n.formatter)},axisLine:{show:!1}}]}function Dw(e){return[{type:"category",name:"准确估算比例",nameRotate:0,nameGap:5,nameLocation:"end",nameTextStyle:{align:"left"},gridIndex:0,axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:"平均偏差",nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:1,boundaryGap:[1,1],axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:"数量占比",nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:2,axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1},min:0,max:1},{type:"value",gridIndex:3,position:"right",splitNumber:3,axisLabel:{show:!0,verticalAlign:"top",showMinLabel:!1,lineHeight:14},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}},{type:"value",name:e.name,nameGap:5,nameRotate:90,nameLocation:"middle",gridIndex:3,position:"left",axisLabel:{show:!1},axisTick:{show:!1},axisLine:{show:!1},splitLine:{show:!1}}]}function vi(e){return e==1||e==2?1:vi(e-2)+vi(e-1)}const Mw=Array.from(new Array(20),(e,t)=>vi(t+1));function zo(e){return e<=1?e:Mw.findIndex(t=>e<=t)-1}function Iw(e,t){const{x_axis:n,deviation:r}=e,a=q(n.data_key),o=q(r.data_keys.estimated_value),l=q(r.data_keys.actual_value);return t[a.queryID].map(u=>{const c=zo(u[o.columnKey]),d=zo(u[l.columnKey]),f=c-d;return{...u,level:{estimated:c,actual:d,diff:f}}})}function Ew(e){return e==="rgba(255, 255, 255, 1)"?{borderColor:"rgba(0,0,0,.1)",borderWidth:1}:{}}function Aw(e){return{show:!0,orient:"vertical",top:"middle",right:0,data:e.filter(n=>n.show_in_legend).reverse().map(n=>({name:`${n.name}`,color:n.color,itemStyle:Ew(n.color)})),tooltip:{show:!0,formatter:"档位偏差:{a}"}}}const zw={tooltip:{trigger:"axis"}};function $w(e,t){const{deviation:n,metrics:r}=e,a=r.find(l=>l.data_key===t);if(a)return a;const o=n.data_keys.actual_value;return{id:o,name:n.name,data_key:o}}function Lw(e,t,n){const r=Iw(e,n),a=q(e.x_axis.data_key),o=x.uniqBy(n[a.queryID],a.columnKey).map(f=>f[a.columnKey]),l=x.groupBy(r,a.columnKey),u=$w(e,t),c=kw(e,u,o,l),d={xAxis:Tw(e,o),yAxis:Dw(u),series:c,grid:bw(),visualMap:[{min:0,max:1,calculable:!0,show:!1,seriesIndex:0,color:["#F0F0F0","#418AAF"]}],legend:Aw(c)};return x.defaultsDeep({},d,zw)}const Ow={input:{border:"none !important",paddingLeft:0,lineHeight:"1.55 !important"}},Pw=({conf:e,metricKey:t,setMetricKey:n})=>{const{deviation:r,metrics:a}=e,o=b.useMemo(()=>{const l=a.map(u=>({label:u.name,value:u.data_key}));return l.push({label:r.name?r.name:r.data_keys.actual_value,value:r.data_keys.actual_value}),l},[r,a]);return p(s.Group,{spacing:1,children:[i(s.Text,{size:12,color:"dimmed",sx:{cursor:"default",userSelect:"none"},children:"基线指标"}),i(s.NativeSelect,{size:"xs",data:o,value:t,onChange:l=>n(l.currentTarget.value),styles:Ow})]})},Bw={"tbody th, tbody td":{padding:"7px 10px"},"tbody tr:not(:first-of-type) th":{borderTop:"1px solid #dee2e6"}};function Vw(){return p(s.HoverCard,{width:400,shadow:"md",children:[i(s.HoverCard.Target,{children:i(s.Button,{size:"xs",variant:"subtle",compact:!0,leftIcon:i(L.IconInfoCircle,{size:14}),children:"指标说明"})}),i(s.HoverCard.Dropdown,{children:i(s.Table,{fontSize:14,sx:Bw,children:p("tbody",{children:[p("tr",{children:[i("th",{children:"估算偏差"}),i("td",{children:"使用斐波那契数列(1,2,3,5,8,13)估算故事点,每个数位为一个档位,计算issue实际故事点与估算故事点的档位偏差,即为估算偏差。如估算故事点为5,实际故事点为8,则估算偏差为-1。"})]}),p("tr",{children:[i("th",{children:"准确估算比例"}),i("td",{children:"偏差在 ± 1 档位内的 issue 均为准确估算,以此计算准确估算的比例。"})]})]})})})]})}function Nw(e){return p(s.Group,{position:"apart",children:[i(Vw,{}),i(Pw,{...e})]})}oe.use([pe.BarChart,pe.LineChart,pe.HeatmapChart,G.GridComponent,G.LegendComponent,G.TooltipComponent,Ve.CanvasRenderer,G.VisualMapComponent]);function qw({conf:e,data:t,width:n,height:r,metricKey:a}){const o=b.useMemo(()=>Lw(e,a,t),[e,t,a]);return i(Ne,{echarts:oe,option:o,style:{width:n,height:r},notMerge:!0,theme:"merico-light"})}function Fw({context:e}){const{value:t}=W(e.instanceData,"config"),n=b.useMemo(()=>x.defaults({},t,bi),[t]),r=e.data,{width:a,height:o}=e.viewport,{x_axis:l,deviation:u}=n,{estimated_value:c,actual_value:d}=u.data_keys,[f,h]=b.useState(d);if(b.useEffect(()=>{h(C=>C||d)},[d]),!l.data_key||!c||!d||!a||!o)return null;const g=Math.max(a,300),m=Math.max(o,370);return p(s.Box,{sx:{overflow:"hidden",height:m,width:g},children:[i(Nw,{conf:n,metricKey:f,setMetricKey:h}),i(qw,{width:g,height:m-30,data:r,conf:n,metricKey:f})]})}function Gw({control:e,watch:t}){return t(["deviation"]),p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,children:i(v.Controller,{name:"deviation.name",control:e,render:({field:n})=>i(s.TextInput,{label:"指标名称",sx:{flex:1},...n})})}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"deviation.data_keys.estimated_value",control:e,render:({field:n})=>i(R,{label:"估算值字段",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"deviation.data_keys.actual_value",control:e,render:({field:n})=>i(R,{label:"实际值字段",required:!0,sx:{flex:1},...n})})]})]})}const Ww=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`metrics.${t}.data_key`,control:e,render:({field:r})=>i(R,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),Rw=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"metrics"}),o=t("metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("metrics.0.id"),[d,f]=b.useState(()=>c??null);return b.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(V,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(T.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"设置可以展示在基线图的指标,例如代码当量"})]}),i(s.Divider,{variant:"dashed",my:10}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(T.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(Ww,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function jw({control:e,watch:t}){return t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(R,{label:"数据字段",required:!0,sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"X轴名称",sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"点位文案",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>i(s.NumberInput,{label:"旋转",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"度"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>i(Es,{...n})})]})]})}function Yw({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),r=b.useMemo(()=>x.defaultsDeep({},t,bi),[t]),{control:a,handleSubmit:o,watch:l,getValues:u,reset:c}=v.useForm({defaultValues:r});b.useEffect(()=>{c(r)},[r]),l([]);const d=u(),f=b.useMemo(()=>!x.isEqual(d,r),[d,r]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Merico Estimation Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!f,children:i(T.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"12px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X 轴"}),i(s.Tabs.Tab,{value:"Deviation",children:"偏差"}),i(s.Tabs.Tab,{value:"Additional Metrics",children:"指标"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(jw,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Deviation",children:i(Gw,{control:a,watch:l})}),i(s.Tabs.Panel,{value:"Additional Metrics",children:i(Rw,{control:a,watch:l})})]})]})})}function Qw(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,deviation:o,metrics:l,...u}=e;return{...u,x_axis:{...a,data_key:r(a.data_key)},deviation:{...o,data_keys:{estimated_value:r(o.data_keys.estimated_value),actual_value:r(o.data_keys.actual_value)}},metrics:l.map(c=>({...c,data_key:r(c.data_key)}))}}catch(n){throw console.error("[Migration failed]",n),n}}class Kw extends be{constructor(){super(...arguments);N(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:Qw(a,r)}})}}const Uw={displayName:"Merico Estimation Chart",displayGroup:"Merico suite",migrator:new Kw,name:"mericoEstimationChart",viewRender:Fw,configRender:Yw,createConfig:()=>({version:2,config:bi})},xi={styles:{justify:"space-around",align:"start"},metrics:[]};function Xw(){return{id:new Date().getTime().toString(),names:{value:"Value",basis:"Basis"},data_keys:{value:"",basis:""},formatter:$e}}function Jw({context:e,instance:t}){const{value:n}=W(e.instanceData,"config"),{variables:r}=e,a=b.useMemo(()=>x.defaults({},n,xi),[n]),o=e.data,l=b.useMemo(()=>ps(o,r),[r,o]),{width:u,height:c}=e.viewport;return!u||!c||!a?null:i(s.Flex,{w:`${u}px`,h:`${c}px`,justify:a.styles.justify,align:a.styles.align,direction:"row",wrap:"nowrap",sx:{overflow:"hidden"},children:a.metrics.map(d=>p(s.Stack,{spacing:18,children:[p(s.Stack,{spacing:12,children:[i(s.Text,{size:"14px",color:"#818388",children:d.names.value}),i(s.Text,{size:"24px",color:"#000000",sx:{lineHeight:1},children:H(l[d.data_keys.value]).format(d.formatter)})]}),p(s.Stack,{spacing:12,children:[i(s.Text,{size:"14px",color:"#818388",children:d.names.basis}),i(s.Text,{size:"12px",color:"#000000",sx:{lineHeight:1},children:H(l[d.data_keys.basis]).format(d.formatter)})]})]},d.id))})}function Zw({control:e,index:t,remove:n,variableOptions:r}){return p(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`metrics.${t}.names.value`,control:e,render:({field:a})=>i(s.TextInput,{label:"Metric Name",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`metrics.${t}.data_keys.value`,control:e,render:({field:a})=>i(s.Select,{label:"Metric Data",required:!0,data:r,sx:{flex:1},...a})})]}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`metrics.${t}.names.basis`,control:e,render:({field:a})=>i(s.TextInput,{label:"Basis Name",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`metrics.${t}.data_keys.basis`,control:e,render:({field:a})=>i(s.Select,{label:"Basis Data",required:!0,data:r,sx:{flex:1},...a})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Format",labelPosition:"center"}),i(v.Controller,{name:`metrics.${t}.formatter`,control:e,render:({field:a})=>i(je,{...a})})]}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(t),sx:{position:"absolute",top:15,right:5},disabled:t===0,children:i(T.Trash,{size:16})})]},t)}function Hw({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"metrics"}),l=t("metrics"),u=r.map((C,w)=>({...C,...l[w]})),c=()=>{a(Xw())},d=b.useMemo(()=>n.map(C=>({label:C.name,value:C.name})),[n]),f=x.get(u,"0.id",null),[h,g]=b.useState(f);b.useEffect(()=>{g(C=>C||f)},[f]);const m=C=>{o(C);const w=x.get(u,"0.id",null);g(w)};return p(V,{children:[i(s.Divider,{mt:15,variant:"dashed",label:"Metrics",labelPosition:"center"}),p(s.Tabs,{value:h,onTabChange:g,styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px"}},children:[p(s.Tabs.List,{children:[u.map((C,w)=>i(s.Tabs.Tab,{value:C.id,children:C.names.value?C.names.value:w+1},w)),i(s.Tabs.Tab,{onClick:c,value:"add",children:i(L.IconPlus,{size:18,color:"#228be6"})})]}),u.map((C,w)=>i(s.Tabs.Panel,{value:C.id,children:i(Zw,{control:e,index:w,remove:m,variableOptions:d})},w))]})]})}const eC=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"},{label:"Space Between",value:"space-between"},{label:"Space Around",value:"space-around"},{label:"Space Evenly",value:"space-evenly"}],tC=[{label:"Start",value:"start"},{label:"Center",value:"center"},{label:"End",value:"end"},{label:"Stretch",value:"stretch"}];function nC({control:e,watch:t}){return t("styles"),p(V,{children:[i(s.Divider,{mt:15,variant:"dashed",label:"Styles",labelPosition:"center"}),p(s.Group,{children:[i(v.Controller,{name:"styles.justify",control:e,render:({field:n})=>i(s.Select,{label:"Justify Content",required:!0,data:eC,sx:{flex:1},...n})}),i(v.Controller,{name:"styles.align",control:e,render:({field:n})=>i(s.Select,{label:"Align",required:!0,data:tC,sx:{flex:1},...n})})]})]})}function rC({context:e}){const{value:t,set:n}=W(e.instanceData,"config"),{variables:r}=e,a=b.useMemo(()=>x.defaultsDeep({},t,xi),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});b.useEffect(()=>{d(a)},[a]);const f=c(),h=b.useMemo(()=>!x.isEqual(f,a),[f,a]);return i("form",{onSubmit:l(n),children:p(s.Stack,{spacing:"xs",children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Merico Stats Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(T.DeviceFloppy,{size:20})})]}),i(nC,{control:o,watch:u}),i(Hw,{control:o,watch:u,variables:r})]})})}class iC extends be{constructor(){super(...arguments);N(this,"VERSION",1)}configVersions(){this.version(1,n=>({...n,version:1,config:n.config}))}}const aC={displayName:"Merico Stats",displayGroup:"Merico suite",migrator:new iC,name:"merico-stats",viewRender:Jw,configRender:rC,createConfig:()=>({version:1,config:xi})},sC=[{value:"#25262B",name:"Dark"},{value:"#868E96",name:"Gray"},{value:"#FA5252",name:"Red"},{value:"#E64980",name:"Pink"},{value:"#BE4BDB",name:"Grape"},{value:"#7950F2",name:"Violet"},{value:"#4C6EF5",name:"Indigo"},{value:"#228BE6",name:"Blue"},{value:"#15AABF",name:"Cyan"},{value:"#12B886",name:"Teal"},{value:"#40C057",name:"Green"},{value:"#82C91E",name:"Lime"},{value:"#FAB005",name:"Yellow"},{value:"#FD7E14",name:"Orange"}].map(e=>({name:e.name,value:e.value,type:"single",category:"basic"})),oC=[Fu,Gu,ju,Ru,Wu,Yu],$o=()=>({id:"dashboard",version:Ja,manifest:{viz:[pi,Tv,Kx,rb,Kv,Ig,yw,ac,jd,ef,Bf,A0,mg,Ah,fv,Qg,Cm,n0,Uw,aC,ap],color:[...sC,...oC]}}),on=new Xu,we={pluginManager:lt("pluginManager"),vizManager:lt("vizManager"),colorManager:lt("colorManager"),instanceScope:{panelModel:lt("panelModel"),vizInstance:lt("vizInstance"),interactionManager:lt("interactionManager"),migrator:lt("migrator"),operationManager:lt("operationManager"),triggerManager:lt("triggerManager")}},wi=()=>{try{on.install($o())}catch{}const e=new Vu(on),t=new Uu(on);return{pluginManager:on,vizManager:e,colorManager:t}},st=b.createContext(wi());try{on.install($o())}catch{}const Ci=b.createContext(null);function Zn(e){const t=b.useContext(Ci),n=X.useCreation(()=>e.configure(t||new yr),[e.configure]),r=X.usePrevious(n);return r&&r!==n&&r.dispose(),i(Ci.Provider,{value:n,children:e.children})}function Lo(){return b.useContext(Ci)}const lC={viewPanelInFullScreen:x.noop,inFullScreen:!1},Hn=b.createContext(lC),uC=({description:e,isDescriptionEmpty:t})=>t?null:i(s.Tooltip,{color:"white",label:i(Un,{value:e,styles:{root:{border:"none"},content:{padding:0}}}),styles:{tooltip:{border:"0.0625rem solid rgb(233, 236, 239)",boxShadow:"rgb(0 0 0 / 5%) 0px 0.0625rem 0.1875rem, rgb(0 0 0 / 5%) 0px 1.25rem 1.5625rem -0.3125rem, rgb(0 0 0 / 4%) 0px 0.625rem 0.625rem -0.3125rem"}},withArrow:!0,children:i(s.Box,{sx:{height:"16px",alignSelf:"center"},children:i(L.IconInfoCircle,{size:16,color:"gray"})})}),cC=k.observer(({label:e,config:{default_value:t,description:n,isDescriptionEmpty:r,...a},value:o,onChange:l})=>p(s.Box,{children:[i(s.Text,{children:" "}),i(s.Checkbox,{label:p(s.Group,{noWrap:!0,position:"apart",align:"middle",spacing:6,children:[i(s.Box,{sx:{flexGrow:1},children:e}),i(uC,{description:n,isDescriptionEmpty:r})]}),checked:o||!1,onChange:u=>l(u.currentTarget.checked),...a,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),Oo=k.observer(({label:e,config:t,value:n=[null,null],onChange:r})=>{const{inputFormat:a,...o}=t,l=Array.isArray(n)?n.map(f=>f?j(f).toDate():null):[null,null],u=f=>{r(f.map(h=>h&&j(h).format(a)))},c=t.getMinDate(l[0]),d=t.getMaxDate(l[0]);return i(xu.DatePickerInput,{type:"range",label:e,value:l,onChange:u,icon:i(T.Calendar,{size:16}),sx:{minWidth:"16em"},minDate:c,maxDate:d,valueFormat:a,styles:{input:{borderColor:"#e9ecef"}},...o})}),dC=s.createStyles((e,{radius:t=4})=>({root:{borderRadius:e.fn.radius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-select.rc-select-open":{borderColor:"#228be6 !important",".rc-select-selection-overflow-item-rest":{display:"none"},".rc-select-selection-overflow-item-suffix":{display:"block"}},".rc-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-select-selection-search-mirror":{display:"none"},".rc-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,backgroundColor:"#fff",border:"1px solid #e9ecef",marginTop:6,padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px","&.rc-select-dropdown-slide-up-leave-active":{display:"none"},".rc-select-item-empty":{padding:"8px 12px"},".rc-select-item-option":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px 8px 2px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},flexDirection:"row-reverse",".rc-select-item-option-state":{flexGrow:0,flexShrink:0,width:"30px",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},".rc-select-item-option-content":{flexGrow:1}}}})),Po=({errorMessage:e})=>e?i(s.Text,{color:"red",size:12,children:e}):i(s.Text,{color:"dimmed",size:12,children:"Not found"}),pC=({disabled:e,classNames:t,styles:n,unstyled:r,radius:a,style:o,label:l,value:u,onChange:c,options:d,errorMessage:f})=>{const{classes:h,cx:g}=dC({radius:a},{name:"MultiSelectWidget",classNames:t,styles:n,unstyled:r}),[m,C]=b.useState(!1),w=B=>{C(B)},_=m&&(u==null?void 0:u.length)>0,[D,E]=b.useState(""),O=b.useMemo(()=>{if(!D)return d;const B=D.toLowerCase(),$=A=>{var I;return((I=A.description)==null?void 0:I.toLowerCase().includes(B))||A.label.toLowerCase().includes(B)};return d.filter($)},[D,d]);return p(s.Stack,{spacing:3,children:[p(s.Group,{position:"apart",children:[i(s.Text,{className:h.label,children:l}),_&&i(s.Tooltip,{label:`${u.length} selected`,children:i(s.Badge,{children:u.length})})]}),i(Ga,{disabled:e,allowClear:!0,className:g(h.root,"check-select"),dropdownClassName:g(h.dropdown,""),onDropdownVisibleChange:w,transitionName:"rc-select-dropdown-slide-up",choiceTransitionName:"rc-select-selection__choice-zoom",style:o,clearIcon:()=>i(s.CloseButton,{}),value:u,onChange:c,onSelect:console.log,mode:"multiple",maxTagCount:0,notFoundContent:i(Po,{errorMessage:f}),maxTagTextLength:10,maxTagPlaceholder:B=>`${B.length} selected`,searchValue:D,onSearch:E,filterOption:!1,children:O.map(B=>i(Ga.Option,{children:i(s.Group,{noWrap:!0,children:p("div",{children:[i(s.Text,{size:"sm","data-role":"label",children:B.label}),B.description&&i(s.Text,{size:"xs",color:"dimmed","data-role":"description",children:B.description})]})})},B.value))})]})},hC=k.observer(({label:e,config:t,value:n,onChange:r})=>{const a=Me(),o=!!t.options_query_id,{state:l,error:u}=a.getDataStuffByID(t.options_query_id),c=l==="loading",d=t.min_width?t.min_width:"200px",f=o?c:!1,h=g=>r(g,!1);return i(pC,{label:e,options:t.options,style:{minWidth:"160px",width:d,maxWidth:f?d:"unset",borderColor:"#e9ecef"},disabled:f,value:n,onChange:h,errorMessage:u})}),fC=b.forwardRef(({label:e,description:t,...n},r)=>i("div",{ref:r,...n,children:i(s.Group,{noWrap:!0,children:p("div",{children:[i(s.Text,{size:"sm","data-role":"label",children:e}),i(s.Text,{size:"xs",color:"dimmed","data-role":"description",children:t})]})})})),gC=k.observer(({label:e,config:t,value:n,onChange:r})=>{const a=Me(),o=!!t.options_query_id,{state:l,error:u}=a.getDataStuffByID(t.options_query_id),c=l==="loading";return b.useEffect(()=>{var h;const{default_selection_count:d}=t;if(!d)return;const f=((h=t.options[0])==null?void 0:h.value)??"";console.log("Selecting the first option by default. New value: ",f),r(f,!0)},[t.default_selection_count,t.options]),i(s.Select,{label:e,data:t.options,disabled:o?c:!1,value:n,onChange:r,error:!!u,placeholder:u,maxDropdownHeight:500,styles:{root:{width:t.width?t.width:"200px"},input:{borderColor:"#e9ecef"}},sx:{".mantine-Select-item[data-selected] .mantine-Text-root[data-role=description]":{color:"rgba(255,255,255,.7)"}},itemComponent:fC})});function mC({label:e,config:t,value:n,onChange:r}){return i(s.TextInput,{label:e,value:n||"",onChange:a=>r(a.currentTarget.value),...t,styles:{input:{borderColor:"#e9ecef"}}})}const yC=({rotate:e,onClick:t})=>i("svg",{onClick:t,className:"caret-icon",viewBox:"0 0 1024 1024",focusable:"false","data-icon":"caret-down",width:"14px",height:"14px",fill:"currentColor","aria-hidden":"true",transform:`rotate(${e})`,children:i("path",{d:"M840.4 300H183.6c-19.7 0-30.7 20.8-18.5 35l328.4 380.8c9.4 10.9 27.5 10.9 37 0L858.9 335c12.2-14.2 1.2-35-18.5-35z"})}),bC=({expanded:e,isLeaf:t,value:n,onClick:r,...a})=>(n==="0-0-value"&&console.log(a),t?i("span",{style:{width:"14px",display:"inline-block"}}):i(yC,{rotate:e?"0":"-90",onClick:r,...a})),vC=({onClick:e})=>p("svg",{onClick:e,className:"checkbox-icon",width:"16",height:"16",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[i("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),i("rect",{className:"border",x:"4",y:"4",width:"16",height:"16",rx:"2"}),i("rect",{className:"checkmark-indeterminate",x:"8",y:"8",width:"8",height:"8",rx:"2",stroke:"none"}),i("path",{className:"checkmark-checked",d:"M9 12l2 2l4 -4"})]}),xC=({onClick:e,...t})=>i(vC,{onClick:e,...t}),wC=s.createStyles((e,{radius:t=4})=>({root:{borderRadius:e.fn.radius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-tree-select.rc-tree-select-open":{borderColor:"#228be6 !important",".rc-tree-select-selection-overflow-item-rest":{display:"none"},".rc-tree-select-selection-overflow-item-suffix":{display:"block"}},".rc-tree-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-tree-select-selection-search-mirror":{display:"none"},".rc-tree-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-tree-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-tree-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-tree-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-tree-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-tree-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-tree-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-tree-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,paddingTop:"6px","&.rc-tree-select-dropdown-slide-up-leave-active":{display:"none"},".rc-tree-select-tree-list .rc-tree-select-tree-list-holder":{},".rc-tree-select-tree-list, .rc-tree-select-empty":{backgroundColor:"#fff",border:"1px solid #e9ecef",padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px"},".rc-tree-select-empty":{padding:"8px 12px"},".rc-tree-select-tree-treenode":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},"&.rc-tree-select-tree-treenode-checkbox-checked":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-checked":{stroke:"rgb(64, 192, 87)",animation:"check 200ms linear forwards"}},"&.rc-tree-select-tree-treenode-checkbox-indeterminate":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-indeterminate":{fill:"rgb(64, 192, 87)"}},".rc-tree-select-tree-switcher":{height:"16px",alignSelf:"center",paddingRight:"2px",transition:"color 200ms ease","&:hover":{color:"#228be6","svg.caret-icon":{color:"#228be6"}},"svg.caret-icon":{color:"#ced4da",transition:"all 200ms ease"}},".rc-tree-select-tree-node-content-wrapper":{display:"flex",flexWrap:"nowrap",overflow:"hidden",alignItems:"center",gap:"8px",transition:"color 200ms ease","&:hover":{color:"#228be6"}},".rc-tree-select-tree-iconEle":{height:"16px","svg .border":{stroke:"#ced4da"},".checkbox-icon .checkmark-indeterminate":{fill:"transparent",transition:"fill 200ms ease"},".checkbox-icon .checkmark-checked":{transform:"scale(1.2)",transformOrigin:"center center",strokeDasharray:10,strokeDashoffset:-10},"@keyframes check":{"0%":{strokeDashoffset:10},"100%":{strokeDashoffset:0}}},".rc-tree-select-tree-title":{textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden",".rc-tree-select-tree-title-desc":{fontSize:"12px",maxWidth:"100%",textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"}},".rc-tree-select-tree-indent":{flexGrow:0,height:0,verticalAlign:"bottom"},".rc-tree-select-tree-indent-unit":{display:"inline-block",width:"1em"}}}})),CC=({disabled:e,classNames:t,styles:n,unstyled:r,radius:a,style:o,label:l,value:u,onChange:c,treeData:d,errorMessage:f})=>{const{classes:h,cx:g}=wC({radius:a},{name:"FilterTreeSelectWidget",classNames:t,styles:n,unstyled:r}),[m,C]=b.useState(!1),w=D=>{C(D)},_=m&&(u==null?void 0:u.length)>0;return p(s.Stack,{spacing:3,children:[p(s.Group,{position:"apart",children:[i(s.Text,{className:h.label,children:l}),_&&i(s.Tooltip,{label:`${u.length} selected`,children:i(s.Badge,{children:u.length})})]}),i(Wa,{disabled:e,allowClear:!0,className:g(h.root,"check-select"),dropdownClassName:g(h.dropdown,""),onDropdownVisibleChange:w,transitionName:"rc-tree-select-dropdown-slide-up",choiceTransitionName:"rc-tree-select-selection__choice-zoom",style:o,treeLine:!0,clearIcon:()=>i(s.CloseButton,{}),switcherIcon:bC,treeIcon:xC,maxTagTextLength:10,value:u,treeData:d,notFoundContent:i(Po,{errorMessage:f}),treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:Wa.SHOW_PARENT,onChange:c,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:D=>`${D.length} selected`})]})},SC=k.observer(({label:e,config:t,value:n,onChange:r})=>{const{treeData:a,treeDataLoading:o,errorMessage:l}=t,u=t.min_width?t.min_width:"200px",d=!!t.options_query_id?o:!1;return i(CC,{disabled:d,style:{minWidth:"160px",width:u,maxWidth:d?u:"unset",borderColor:"#e9ecef"},value:n,onChange:f=>r(f,!1),treeData:a,errorMessage:l,label:e})}),_C=k.observer(({filter:{type:e,config:t,key:n,...r},formFieldProps:a})=>{switch(e){case"select":return i(gC,{...r,...a,config:t});case"multi-select":return i(hC,{...r,...a,config:t});case"tree-select":return i(SC,{...r,...a,config:t});case"text-input":return i(mC,{...r,...a,config:t});case"date-range":return i(Oo,{...r,...a,config:t});case"checkbox":return i(cC,{...r,...a,config:t});default:return null}}),Bo=k.observer(b.forwardRef(({filter:e,...t},n)=>i("div",{className:"filter-root",ref:n,children:i(Fe,{children:i(_C,{filter:e,formFieldProps:t})})})));function kC(e){const t=ue();b.useEffect(()=>{var n,r;(r=(n=t.filters).updatePreviewValues)==null||r.call(n,e)},[e])}const Vo=k.observer(function({view:t}){const n=Me(),{control:r,handleSubmit:a,reset:o}=v.useForm({defaultValues:n.filters.values,reValidateMode:"onBlur"}),l=v.useWatch({control:r});b.useEffect(()=>{o(n.filters.values)},[n.filters.values,o]),kC(l);const u=n.filters.visibleInView(t.id),c=b.useMemo(()=>u.every(g=>g.should_auto_submit),[u]),d=b.useMemo(()=>u.filter(g=>x.get(g,"config.required",!1)),[u]),f=b.useMemo(()=>d.length===0?!1:d.some(g=>!g.requiredAndPass(l[g.key])),[l,d]);if(u.length===0)return null;const h=(g,m)=>(C,w)=>{m(C),(g.should_auto_submit||w)&&n.filters.setValueByKey(g.key,C)};return i("form",{onSubmit:a(n.filters.setValues),children:p(s.Group,{className:"dashboard-filters",position:"apart",noWrap:!0,sx:c?{}:{border:"1px solid #e9ecef",borderRadius:"4px",padding:"16px"},children:[i(s.Group,{align:"flex-start",children:u.map(g=>i(v.Controller,{name:g.key,control:r,render:({field:m})=>i(Bo,{filter:g,value:m.value,onChange:h(g,m.onChange)})},g.id))}),!c&&i(s.Group,{sx:{alignSelf:"flex-end"},children:i(s.Button,{color:"blue",size:"sm",type:"submit",disabled:f,children:"Search"})})]})})}),No=y.types.model("MockContextMeta",{current:y.types.optional(y.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},get(t){return e.current[t]},set(t,n){e.current[t]=n}}));function qo(e){return{current:e}}const TC=y.types.model("PanelLayoutMeta",{x:y.types.number,y:y.types.maybeNull(y.types.number),w:y.types.number,h:y.types.number,moved:y.types.optional(y.types.boolean,!1),static:y.types.optional(y.types.boolean,!1)}).views(e=>({get json(){const{x:t,y:n,w:r,h:a,moved:o}=e;return{h:a,w:r,x:t,y:n===null?0:n,moved:o,static:e.static}}})).actions(e=>({set(t){const{x:n,y:r,w:a,h:o,moved:l}=t;e.x=n,e.y=r,e.w=a,e.h=o,e.moved=!!l,e.static=!!t.static}})),DC=y.types.model("PanelStyleBorderMeta",{enabled:y.types.boolean}).views(e=>({get json(){const{enabled:t}=e;return{enabled:t}}})).actions(e=>({setEnabled(t){e.enabled=t}})),MC=y.types.model("PanelStyleMeta",{border:DC}).views(e=>({get json(){const{border:t}=e;return{border:t.json}}})).actions(e=>({})),IC=y.types.model("VariableMeta",{name:y.types.string,size:y.types.string,weight:y.types.string,color:y.types.union(y.types.model({type:y.types.literal("static"),staticColor:y.types.string}),y.types.model({type:y.types.literal("continuous"),valueRange:y.types.array(y.types.number),colorRange:y.types.array(y.types.string)}),y.types.model({type:y.types.literal("piecewise")})),formatter:y.types.model({output:y.types.enumeration("Output",["number","percent"]),average:y.types.optional(y.types.boolean,!1),mantissa:y.types.number,trimMantissa:y.types.optional(y.types.boolean,!1)}),data_field:y.types.string,aggregation:y.types.union(y.types.model({type:y.types.enumeration(["none","sum","mean","median","min","max","CV","std"]),config:y.types.frozen()}),y.types.model({type:y.types.literal("quantile"),config:y.types.model({p:y.types.number})}))}).views(e=>({get json(){const{name:t,size:n,weight:r,color:a,formatter:o,data_field:l,aggregation:u}=e;return x.cloneDeep({name:t,size:n,color:a,weight:r,formatter:o,data_field:l,aggregation:u})}})),EC=y.types.model("PanelVizMeta",{type:y.types.string,conf:y.types.frozen()}).views(e=>({get json(){return{conf:e.conf,type:e.type}}})).actions(e=>({setType(t){e.type=t},setConf(t){e.conf=t}})),AC=y.types.model({id:y.types.string,title:y.types.string,description:y.types.string,layout:TC,queryIDs:y.types.array(y.types.string),viz:EC,style:MC,variables:y.types.optional(y.types.array(IC),[])}).views(e=>({get json(){const{id:t,title:n,description:r,queryIDs:a}=e;return{id:t,viz:e.viz.json,style:e.style.json,title:n,layout:e.layout.json,queryIDs:[...a],variables:e.variables.map(o=>o.json),description:r}},get queryIDSet(){return new Set(e.queryIDs)}})).actions(e=>({setID(t){e.id=t},setTitle(t){e.title=t},setDescription(t){e.description=t},addQueryID(t){e.queryIDSet.has(t)||e.queryIDs.push(t)},removeQueryID(t){if(!e.queryIDSet.has(t))return;const n=new Set(e.queryIDSet);n.delete(t),e.queryIDs=y.cast(Array.from(n))},setQueryIDs(t){e.queryIDs=y.cast(t)},addVariable(t){e.variables.push(t)},removeVariable(t){e.variables.remove(t)}})),er=e=>x.cloneDeepWith(e,(t,n)=>{if(n!==void 0&&t)return re.toJS(t)});var Ce=(e=>(e.Postgresql="postgresql",e.MySQL="mysql",e.HTTP="http",e))(Ce||{});const zC=y.types.model("QueryMeta",{id:y.types.string,name:y.types.string,type:y.types.enumeration("DataSourceType",[Ce.Postgresql,Ce.MySQL,Ce.HTTP]),key:y.types.string,sql:y.types.string,pre_process:y.types.optional(y.types.string,""),post_process:y.types.optional(y.types.string,""),run_by:y.types.optional(y.types.array(y.types.string),[]),react_to:y.types.optional(y.types.array(y.types.string),[])}).views(e=>({get valid(){return e.id&&e.type&&e.key&&e.name?e.type===Ce.HTTP?!!e.pre_process:!!e.sql:!1},get json(){const{id:t,name:n,type:r,key:a,sql:o,run_by:l,react_to:u,pre_process:c,post_process:d}=e;return er({id:t,key:a,sql:o,name:n,type:r,run_by:l,react_to:u,pre_process:c,post_process:d})}})).actions(e=>({setName(t){e.name=t},setKey(t){e.key=t},setType(t){e.type=t},setSQL(t){e.sql=t},setRunBy(t){e.run_by.length=0,e.run_by.push(...t)},setReactTo(t){e.react_to.length=0,e.react_to.push(...t)},setPreProcess(t){e.pre_process=t},setPostProcess(t){e.post_process=t}})),$C=y.types.model("SQLSnippetMeta",{key:y.types.string,value:y.types.string}).views(e=>({get json(){const{key:t,value:n}=e;return{key:t,value:n}}})).actions(e=>({setKey(t){e.key=t},setValue(t){e.value=t}}));var Te=(e=>(e.Select="select",e.MultiSelect="multi-select",e.TreeSelect="tree-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(Te||{});const Fo=y.types.model("FilterCheckboxConfigMeta",{_name:y.types.literal("checkbox"),description:y.types.optional(y.types.string,""),default_value:y.types.boolean}).views(e=>({get json(){const{_name:t,description:n,default_value:r}=e;return{_name:t,description:n,default_value:r}},get isDescriptionEmpty(){const{description:t}=e;return t===""||t==="<p></p>"}})).actions(e=>({setDefaultValue(t){e.default_value=t},setDescription(t){e.description=t}})),LC=()=>Fo.create({_name:"checkbox",description:"",default_value:!1});function Go(e,t){return e.map(n=>{try{return n?j.tz(n,"UTC").format(t):null}catch{return console.log(`[date-range] failed parsing ${n}`),null}})}const OC=y.types.model("FilterDateRangeConfigMeta",{_name:y.types.literal("date-range"),required:y.types.boolean,inputFormat:y.types.enumeration("DateRangeInputFormat",["YYYY","YYYYMM","YYYYMMDD","YYYY-MM","YYYY-MM-DD"]),default_value:y.types.optional(y.types.array(y.types.union(y.types.string,y.types.null)),[null,null]),clearable:y.types.boolean,max_days:y.types.optional(y.types.number,0),allowSingleDateInRange:y.types.optional(y.types.boolean,!1)}).views(e=>({get json(){const{_name:t,max_days:n,required:r,clearable:a,inputFormat:o,default_value:l,allowSingleDateInRange:u}=e;return{_name:t,max_days:n,required:r,clearable:a,inputFormat:o,default_value:Go(l,o),allowSingleDateInRange:u}},truthy(t){return Array.isArray(t)&&t.length===2&&t.every(n=>!!n)}})).views(e=>({getMaxDate(t){const{max_days:n}=e;if(!(!n||!t))return j(t).startOf("day").add(n,"days").toDate()},getMinDate(t){const{max_days:n}=e;if(!(!n||!t))return j(t).startOf("day").subtract(n,"days").toDate()}})).actions(e=>({setFilterValue(t){try{const n=y.getParent(e);y.getRoot(e).filters.setValueByKey(n.key,t)}catch(n){console.error(n)}}})).actions(e=>({setRequired(t){e.required=t},setClearable(t){e.clearable=t},setInputFormat(t){e.inputFormat=t},setDefaultValue(t){e.default_value.length=0,e.default_value.push(...t),e.setFilterValue(t)},setMaxDays(t){e.max_days=t,t>0&&(e.clearable=!0)},setAllowSingleDateInRange(t){e.allowSingleDateInRange=t}})),Wo=y.types.snapshotProcessor(OC,{preProcessor({default_value:e,...t}){return{...t,default_value:e.map(n=>n===null?null:j.tz(n,"UTC").toISOString())}},postProcessor(e){const{default_value:t,...n}=e;return{...n,default_value:Go(t,n.inputFormat)}}}),PC=()=>Wo.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),BC=y.types.model({label:y.types.string,value:y.types.string}).actions(e=>({setLabel(t){e.label=t},setValue(t){e.value=t}})),Si=y.types.model("FilterConfigModel_BaseSelect",{static_options:y.types.optional(y.types.array(BC),[]),options_query_id:y.types.optional(y.types.string,""),default_selection_count:y.types.optional(y.types.number,0)}).views(e=>({get usingQuery(){return!!e.options_query_id}})).views(e=>({get options(){if(!e.usingQuery)return e.static_options;const{data:t,state:n,error:r}=y.getRoot(e).content.getDataStuffByID(e.options_query_id);return n==="idle"?t:[]}})).actions(e=>({addStaticOption(t){e.static_options.push(t)},removeStaticOption(t){e.static_options.splice(t,1)},setDefaultSelectionCount(t){e.default_selection_count=t},setOptionsQueryID(t){e.options_query_id=t??""}})),Ro=y.types.compose("FilterMultiSelectConfigMeta",y.types.model({_name:y.types.literal("multi-select"),min_width:y.types.optional(y.types.string,""),default_value:y.types.optional(y.types.array(y.types.string),[])}),Si).views(e=>({get json(){const{_name:t,default_value:n,min_width:r,static_options:a,options_query_id:o,default_selection_count:l}=e;return er({_name:t,min_width:r,default_value:n,static_options:a,options_query_id:o,default_selection_count:l})},get default_selection(){return e.usingQuery?e.options.slice(0,e.default_selection_count).map(t=>t.value):e.default_value}})).actions(e=>({setDefaultValue(t){e.default_value=y.cast(t)},setMinWidth(t){e.min_width=t},setDefaultSelection(){const t=y.getRoot(e).content.filters,n=y.getParent(e).key;t.setValueByKey(n,e.default_selection)}})).actions(e=>({afterCreate(){y.addDisposer(e,re.reaction(()=>re.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!0,delay:0}))}})),VC=()=>Ro.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),jo=y.types.compose("FilterConfigModel_Select",y.types.model({_name:y.types.literal("select"),default_value:y.types.string,required:y.types.boolean,width:y.types.optional(y.types.string,"")}),Si).views(e=>({get json(){const{_name:t,default_value:n,required:r,width:a,static_options:o,options_query_id:l,default_selection_count:u}=e;return er({_name:t,width:a,required:r,default_value:n,static_options:o,options_query_id:l,default_selection_count:u})},truthy(t){return!!t}})).actions(e=>({setRequired(t){e.required=t},setDefaultValue(t){e.default_value=t},setWidth(t){e.width=t}})),NC=()=>jo.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),Yo=y.types.model("FilterTextInputConfigMeta",{_name:y.types.literal("text-input"),required:y.types.boolean,default_value:y.types.string}).views(e=>({get json(){const{_name:t,required:n,default_value:r}=e;return{_name:t,required:n,default_value:r}},truthy(t){return typeof t!="string"?!1:!!t.trim()}})).actions(e=>({setRequired(t){e.required=t},setDefaultValue(t){e.default_value=t}})),Qo=()=>Yo.create({_name:"text-input",required:!1,default_value:""});function qC(e){return wu.arrayToTree(e,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}function FC(e){return e.map(t=>{const{label:n,description:r,...a}=t,o={...a,filterBasis:`${n}___${r??""}`,description:r,label:n};return r&&(o.label=b.createElement("div",{},[b.createElement(s.Text,{key:0,title:t.label},t.label),b.createElement(s.Text,{key:1,className:"rc-tree-select-tree-title-desc",color:"dimmed",title:t.description},t.description)])),o})}const Ko=y.types.compose("FilterTreeSelectConfigMeta",y.types.model({_name:y.types.literal("tree-select"),min_width:y.types.optional(y.types.string,""),default_value:y.types.optional(y.types.array(y.types.string),[])}),Si).views(e=>({get json(){const{_name:t,default_value:n,min_width:r,static_options:a,options_query_id:o,default_selection_count:l}=e;return{_name:t,min_width:r,default_value:n,static_options:a,options_query_id:o,default_selection_count:l}},get treeData(){const{data:t}=y.getRoot(e).content.getDataStuffByID(e.options_query_id),n=FC(t);return qC(n)},get errorMessage(){const{error:t}=y.getRoot(e).content.getDataStuffByID(e.options_query_id);return t},get treeDataLoading(){const{state:t}=y.getRoot(e).content.getDataStuffByID(e.options_query_id);return t==="loading"},get defaultSelection(){const{default_selection_count:t}=e;return t?this.treeData.slice(0,t).map(r=>r.value):[]}})).actions(e=>({setDefaultValue(t){e.default_value=y.cast(t)},setMinWidth(t){e.min_width=t},applyDefaultSelection(){const t=y.getParent(e,1).key;y.getRoot(e).content.filters.setValueByKey(t,e.defaultSelection)},afterCreate(){y.addDisposer(e,re.reaction(()=>JSON.stringify(e.defaultSelection),this.applyDefaultSelection,{fireImmediately:!0,delay:0}))}})),GC=()=>Ko.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),Uo=y.types.model("FilterMeta",{id:y.types.identifier,key:y.types.string,label:y.types.string,order:y.types.number,visibleInViewsIDs:y.types.array(y.types.string),auto_submit:y.types.optional(y.types.boolean,!1),type:y.types.enumeration("DashboardFilterType",[Te.Select,Te.MultiSelect,Te.TreeSelect,Te.TextInput,Te.Checkbox,Te.DateRange]),config:y.types.union(jo,Ro,Ko,Yo,Fo,Wo)}).views(e=>({get plainDefaultValue(){const t=e.config.default_value;return Array.isArray(t)?[...t]:t},get usingDefaultValue(){return e.type!==Te.TreeSelect},get auto_submit_supported(){return[Te.Select,Te.Checkbox,Te.DateRange].includes(e.type)}})).views(e=>({get json(){const{id:t,key:n,label:r,order:a,visibleInViewsIDs:o,auto_submit:l,type:u,config:c}=e;return{id:t,key:n,type:u,label:r,order:a,config:c.json,auto_submit:l,visibleInViewsIDs:re.toJS(o)}},get should_auto_submit(){return e.auto_submit_supported&&e.auto_submit},requiredAndPass(t){return x.get(e.config,"required",!1)?x.get(e.config,"truthy",()=>!0)(t):!1}})).actions(e=>({setKey(t){e.key=t},setLabel(t){e.label=t},setOrder(t){e.order=t},setType(t){switch(t){case Te.Select:e.config=NC();break;case Te.MultiSelect:e.config=VC();break;case Te.TreeSelect:e.config=GC();break;case Te.TextInput:e.config=Qo();break;case Te.Checkbox:e.config=LC();break;case Te.DateRange:e.config=PC();break}e.type=t},setVisibleInViewsIDs(t){e.visibleInViewsIDs.length=0,e.visibleInViewsIDs.push(...t)},setAutoSubmit(t){e.auto_submit=e.auto_submit_supported&&t}}));var Y=(e=>(e.Division="div",e.Modal="modal",e.Tabs="tabs",e))(Y||{});const Xo=y.types.model("ViewDivisionConfig",{_name:y.types.literal(Y.Division)}).views(e=>({get json(){const{_name:t}=e;return{_name:t}}})),WC=()=>Xo.create({_name:Y.Division}),RC=y.types.model("CustomModalTitleModel",{enabled:y.types.optional(y.types.boolean,!1),func_content:y.types.optional(y.types.string,"")}).views(e=>({get json(){const{enabled:t,func_content:n}=e;return{enabled:t,func_content:n}},get value(){const{enabled:t,func_content:n}=e,r=y.getParent(e,2),a=y.getRoot(e);if(!t)return r.name;try{const o={filters:a.content.filters.values,context:a.context.current};return new Function(`return ${n}`)()(o)}catch(o){return console.error(o),r.name}}})).actions(e=>({setEnabled(t){e.enabled=t},setFuncContent(t){e.func_content=t},replace({enabled:t,func_content:n}){e.enabled=t,e.func_content=n}})),_i={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
417
+ `)},Jo=y.types.model("ViewModalConfig",{_name:y.types.literal(Y.Modal),width:y.types.string,height:y.types.string,custom_modal_title:y.types.optional(RC,_i)}).views(e=>({get json(){const{_name:t,width:n,height:r,custom_modal_title:a}=e;return{_name:t,width:n,height:r,custom_modal_title:a.json}}})).actions(e=>({setWidth(t){e.width=t},setHeight(t){e.height=t}})),jC=()=>Jo.create({_name:Y.Modal,width:"90vw",height:"90vh"}),YC=y.types.model("ViewTabsTabModel",{id:y.types.identifier,name:y.types.string,view_id:y.types.string,color:y.types.optional(y.types.string,"")}).views(e=>({get json(){const{id:t,name:n,view_id:r,color:a}=e;return{id:t,name:n,color:a,view_id:r}}})).actions(e=>({setName(t){e.name=t},setViewID(t){e.view_id=t},setColor(t){e.color=t}})),Zo=y.types.model("ViewTabsConfig",{_name:y.types.literal(Y.Modal),tabs:y.types.optional(y.types.array(YC),[]),variant:y.types.optional(y.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:y.types.optional(y.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:y.types.optional(y.types.boolean,!1)}).views(e=>({get json(){const{_name:t,variant:n,orientation:r,tabs:a,grow:o}=e;return{grow:o,tabs:a.map(l=>l.json),_name:t,variant:n,orientation:r}}})).actions(e=>({setVariant(t){e.variant=t},setOrientation(t){e.orientation=t},setGrow(t){e.grow=t},setTabs(t){e.tabs.length=0,e.tabs=y.cast(t)},addTab(){const t=Ee.randomId(),n={id:t,name:t,view_id:""};e.tabs.push(n)},removeTab(t){e.tabs.splice(t,1)}})),QC=()=>Zo.create({_name:Y.Modal,tabs:[]}),KC=y.types.model({id:y.types.identifier,name:y.types.string,type:y.types.enumeration("EViewComponentType",[Y.Division,Y.Modal,Y.Tabs]),config:y.types.union(Xo,Jo,Zo),panelIDs:y.types.optional(y.types.array(y.types.string),[])}).views(e=>({get json(){const{id:t,name:n,type:r,config:a}=e;return{id:t,name:n,type:r,config:a.json,panelIDs:e.panelIDs}}})).actions(e=>({setName(t){e.name=t},setType(t){if(e.type!==t){switch(t){case Y.Division:e.config=WC();break;case Y.Modal:e.config=jC();break;case Y.Tabs:e.config=QC();break}e.type=t}},appendPanelID(t){e.panelIDs.push(t)},removePanelID(t){const n=e.panelIDs.filter(r=>r!==t);e.panelIDs.length=0,e.panelIDs.push(...n)}})),Ho=y.types.model("DataSourceMetaModel",{id:y.types.string,type:y.types.enumeration("DataSourceType",[Ce.HTTP,Ce.MySQL,Ce.Postgresql]),key:y.types.string,config:y.types.frozen()}),UC=y.types.model("DataSourcesMetaModel",{list:y.types.optional(y.types.array(Ho),[])}).views(e=>({find({type:t,key:n}){return e.list.find(r=>r.key===n&&r.type===t)},get options(){return e.list.map(t=>({value:t.key,label:t.key}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}})),XC=y.types.model({id:y.types.string,content:y.types.string,create_time:y.types.string,update_time:y.types.string,is_preset:y.types.boolean}),el=y.types.model("GlobalSQLSnippetsMeta",{list:y.types.optional(y.types.array(XC),[])}).views(e=>({find(t){return e.list.find(n=>n.id===t)},get options(){return e.list.map(t=>({value:t.id,label:t.id}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}})),ki=y.types.model("ContextMeta",{current:y.types.optional(y.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},get(t){return e.current[t]},set(t,n){e.current[t]=n}}));function tl(e){return ki.create({current:e})}const nl=y.types.model("ViewsRenderModel",{current:y.types.optional(y.types.array(KC),[]),visibleViewIDs:y.types.array(y.types.string)}).views(e=>({get json(){return e.current.map(t=>er(t.json))},get idMap(){const t=new Map;return e.current.forEach(n=>{t.set(n.id,n)}),t},findByID(t){return e.current.find(n=>n.id===t)},get firstVisibleView(){const[t]=e.visibleViewIDs;return e.current.find(({id:n})=>n===t)},get visibleViews(){const t=new Set(e.visibleViewIDs);return e.current.filter(({id:n})=>t.has(n))}})).actions(e=>({appendToVisibles(t){new Set(e.visibleViewIDs.map(r=>r)).has(t)||e.visibleViewIDs.push(t)},rmVisibleViewID(t){const n=e.visibleViewIDs.findIndex(r=>r===t);n!==-1&&e.visibleViewIDs.splice(n,1)}}));function JC(e){const t=e.length>0?[e[0].id]:[];return{current:e.map(r=>{const{_name:a=r.type}=r.config;return{...r,config:{...r.config,_name:a},panelIDs:r.panelIDs}}),visibleViewIDs:t}}const rl=AC.views(e=>({get contentModel(){return y.getRoot(e).content}})).views(e=>({get queries(){return e.contentModel.queries.findByIDSet(e.queryIDSet)},get data(){return this.queries.reduce((t,n)=>(t[n.id]=n.data.toJSON(),t),{})},get dataLoading(){return this.queries.some(t=>t.state==="loading")},get queryStateMessages(){return this.queries.map(t=>t.stateMessage).filter(t=>!!t)},get queryErrors(){return this.queries.map(t=>t.error).filter(t=>!!t)},get canRenderViz(){return this.queryErrors.length===0&&this.queryStateMessages.length===0&&!this.dataLoading}})).actions(e=>({refreshData(){e.queries.forEach(t=>t.fetchData())},downloadData(){y.getRoot(e).content.queries.downloadDataByQueryIDs(e.queryIDs)}}));function ZC(e){return{id:e,layout:{x:0,y:1/0,w:18,h:300},title:e,description:"<p></p>",queryIDs:[],viz:{type:pi.name,conf:pi.createConfig()},style:{border:{enabled:!0}}}}const il=y.types.model("PanelsRenderModel",{list:y.types.optional(y.types.array(rl),[])}).views(e=>({get json(){return e.list.map(t=>t.json)},findByID(t){return e.list.find(n=>n.id===t)},get idMap(){const t=new Map;return e.list.forEach(n=>{t.set(n.id,n)}),t}})).views(e=>({panelsByIDs(t){const n=[];t.forEach(a=>{const o=e.idMap.get(a);o?n.push(o):console.warn(`Panel is not found, id:${a}`)});const r=n.map(a=>({...a.layout.json,i:a.id}));return{panels:n,layouts:r}}}));function al(e,t){if(e===void 0)return e;if(t._name==="date-range")try{const[...n]=e;return n.map(r=>r===null?r:j.tz(r,"UTC").format(t.inputFormat)??r)}catch(n){return console.error(n),e}return e}function HC(e){return e.reduce((t,n)=>(t[n.key]=al(n.config.default_value,n.config),t),{})}const sl=y.types.model("FiltersRenderModel",{current:y.types.optional(y.types.array(Uo),[]),values:y.types.optional(y.types.frozen(),{})}).views(e=>({get json(){return e.current.map(t=>t.json)},get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(n=>n.id===t)},get inOrder(){return x.sortBy(e.current,"order")},get empty(){return e.current.length===0},visibleInView(t){return x.sortBy(e.current.filter(n=>n.visibleInViewsIDs.includes(t)),"order")},get firstFilterValueKey(){return Object.keys(e.values)[0]??""},get keyLabelMap(){return e.current.reduce((t,n)=>(t[n.key]=n.label,t),{})}})).actions(e=>({setValues(t){e.values=t},setValueByKey(t,n){e.values={...e.values,[t]:n}},getValueByKey(t){return e.values[t]}}));function ol(e){return{current:e,values:HC(e)}}const e1=zC.views(e=>({get conditionOptions(){if(!y.isAlive(e))return[];const{context:t,filters:n}=y.getRoot(e).content.payloadForSQL,r=Object.keys({...t}).map(l=>`context.${l}`),a=Object.keys(n).map(l=>`filters.${l}`);return[...r,...a].map(l=>({label:l.split(".")[1],value:l,group:x.capitalize(l.split(".")[0])}))},get unmetRunByConditions(){if(!y.isAlive(e))return[];const{run_by:t}=e;if(t.length===0)return[];const n=y.getRoot(e).content.payloadForSQL;return t.filter(r=>{const a=x.get(n,r);return Array.isArray(a)?a.length===0:typeof a=="number"?Number.isNaN(a):!a})}})).views(e=>({get reQueryKey(){const{react_to:t=[]}=e;if(t.length===0)return"";const n=y.getRoot(e).content.payloadForSQL,r=[...t].reduce((a,o)=>(a[o]=x.get(n,o),a),{});return JSON.stringify(r)},get runByConditionsMet(){return e.unmetRunByConditions.length===0},get conditionNames(){if(e.unmetRunByConditions.length===0)return{context:[],filters:[]};const{keyLabelMap:t}=y.getRoot(e).content.filters,n=e.unmetRunByConditions.filter(a=>a.startsWith("context.")).map(a=>a.split("context.")[0]),r=e.unmetRunByConditions.filter(a=>a.startsWith("filters.")).map(a=>x.get({filters:t},a)).filter(a=>!!a);return{context:n,filters:r}}}));function t1(e,t){return new Function(`return ${e}`)()(t,Lt)}function n1(e,t,n){return t1(e,{context:t,filters:n})}function r1(e,t){try{return new Function(`return ${e.config.processing.pre}`)()(t,Lt)}catch(n){return console.error(n),t}}function i1(e,t){return new Function(`return ${e.config.processing.post}`)()(t,Lt)}function a1(e,t){return e?new Function(`return ${e}`)()(t,Lt):t}const s1=y.types.compose("QueryRenderModel",e1,y.types.model({state:y.types.optional(y.types.enumeration(["idle","loading","error"]),"idle"),data:y.types.optional(y.types.array(y.types.frozen()),[]),error:y.types.frozen()})).views(e=>({get formattedSQL(){const t=y.getRoot(e).content.payloadForSQL;return gr(e.sql,t)},get typedAsSQL(){return[Ce.Postgresql,Ce.MySQL].includes(e.type)},get typedAsHTTP(){return[Ce.HTTP].includes(e.type)},get datasource(){const{key:t,type:n}=e;return y.getRoot(e).datasources.find({type:n,key:t})},get httpConfigString(){const{context:t,filters:n}=y.getRoot(e).content.payloadForSQL,{name:r,pre_process:a}=e.json,o=n1(a,t,n);return console.groupCollapsed(`Request config for: ${r}`),console.log(o),console.groupEnd(),JSON.stringify(o)}})).views(e=>({get stateMessage(){if(e.state!=="idle")return"";if(!e.runByConditionsMet){const{context:t,filters:n}=e.conditionNames;if(t.length===0&&n.length===0)return"Waiting";const r=[];return t.length>0&&r.push(`context: ${t.join(", ")}`),n.length>0&&r.push(`filter${n.length>1?"s":""}: ${n.join(", ")}`),r.length===2&&r.splice(1,0,"and"),r.unshift("Waiting for"),r.join(" ")}return e.data.length>0?"":"Empty Data"}})).volatile(()=>({controller:new AbortController})).actions(e=>({runSQL:y.flow(function*(){var t;if(e.valid&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const n=y.getRoot(e).content.payloadForSQL;e.data=yield*y.toGenerator(Ou({payload:n,title:e.name,query:e.json},e.controller.signal)),e.state="idle",e.error=null}catch(n){if(!ht.isCancel(n)){e.data.length=0;const r=x.get(n,"message","unkown error");e.error=x.get(n,"response.data.detail.message",r),e.state="error"}}}}),runHTTP:y.flow(function*(){var t;if(!(!e.valid||!e.datasource)&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const{type:n,key:r,post_process:a}=e.json;let o=JSON.parse(e.httpConfigString);o=r1(e.datasource,o);const l=yield*y.toGenerator(Pu({type:n,key:r,configString:JSON.stringify(o)},e.controller.signal));let u=i1(e.datasource,l);u=a1(a,u),e.data=u,e.state="idle",e.error=null}catch(n){if(console.error(n),!ht.isCancel(n)){e.data.length=0;const r=x.get(n,"message","unkown error");e.error=x.get(n,"response.data.detail.message",r),e.state="error"}}}})})).actions(e=>({fetchData:()=>e.typedAsHTTP?e.runHTTP():e.runSQL(),beforeDestroy(){var t;(t=e.controller)==null||t.abort()}})).actions(e=>({afterCreate(){y.addDisposer(e,re.reaction(()=>{var t,n;return e.typedAsHTTP?`${e.id}--${e.key}--${e.reQueryKey}--${(t=e.datasource)==null?void 0:t.id}`:`${e.id}--${e.key}--${e.formattedSQL}--${e.pre_process}--${e.post_process}--${(n=e.datasource)==null?void 0:n.id}`},e.fetchData,{fireImmediately:!0,delay:0}))}})),ll="\uFEFF";function o1(e,t){const n=new Blob([ll+t],{type:"text/csv"});hr.saveAs(n,`${e}.csv`)}function l1(e,t){const n=new Blob([t],{type:"application/json"});hr.saveAs(n,`${e}.json`)}function ul(e){const t=new Cu;e.forEach(({id:n,data:r})=>{t.file(`${n}.csv`,dl(r))}),t.generateAsync({type:"blob"}).then(n=>{hr.saveAs(n,"dashboard_data.zip")})}function cl(e){return typeof e=="string"&&e.includes(",")?`"${e}"`:e}function dl(e){if(!Array.isArray(e)||e.length===0)return"";const t=[],n=Object.keys(e[0]).map(cl);return t.push(n.join(",")),e.forEach(r=>{const a=Object.values(r).map(cl).join(",");t.push(a)}),ll+t.join(`
418
+ `)}const pl=y.types.model("QueriesRenderModel",{current:y.types.optional(y.types.array(s1),[])}).views(e=>({get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(n=>n.id===t)},findByIDSet(t){return e.current.filter(n=>t.has(n.id))},get json(){return e.current.filter(t=>t.id).map(t=>t.json)}})).actions(e=>({downloadAllData(){const t=e.current.map(({name:n,data:r})=>({id:n,data:r.toJSON()}));ul(t)},downloadDataByQueryIDs(t){const n=new Set(t),r=e.current.filter(a=>n.has(a.id)).map(({name:a,data:o})=>({id:a,data:o.toJSON()}));ul(r)},downloadDataByQueryID(t){const n=e.findByID(t);if(!n){console.log("[downloadDataByQueryID] query not found");return}const{name:r,data:a}=n,o=dl(a);o1(r,o)},refetchDataByQueryID(t){const n=e.findByID(t);if(!n){console.error(new Error(`[downloadDataByQueryID] query by ID[${t}] not found`));return}return n.fetchData()}}));function u1(e){return{current:e}}const c1=$C.views(e=>({isADuplicatedKey(t){return!t||t===e.key?!1:!!y.getParent(e,2).findByKey(t)}})),hl=y.types.model("SQLSnippetsRenderModel",{current:y.types.optional(y.types.array(c1),[])}).views(e=>({get json(){return e.current.map(t=>t.json)},get record(){return e.current.reduce((t,n)=>(t[n.key]=n.value,t),{})},get firstKey(){if(e.current.length!==0)return e.current[0].key},findByKey(t){return e.current.find(n=>n.key===t)}}));function d1(e){return{current:e}}function tr(e,t,n,r){return e.reduce((a,o)=>(a[o[t]]=fr(o[n],r),a),{})}class p1{constructor(t){N(this,"origin");N(this,"copy");this.origin=t,this.copy=y.clone(t),re.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!x.isEqual(y.getSnapshot(this.origin),y.getSnapshot(this.copy))}commit(){y.applySnapshot(this.origin,y.getSnapshot(this.copy))}update(t){y.applySnapshot(this.copy,t)}}const h1=e=>new p1(e),f1=k.observer(({view:e})=>{const t=me(),n=ue(),r=Ue.useModals(),{panel:a}=Je(),{id:o}=a,{viewPanelInFullScreen:l,inFullScreen:u}=b.useContext(Hn),c=()=>{n.duplicatePanelByID(o,e.id)},d=()=>{t.editor.open(["_VIEWS_",e.id,"_PANELS_",o])},f=()=>r.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.removePanelByID(o,e.id),confirmProps:{color:"red"},zIndex:320}),h=b.useCallback(()=>{l(o)},[o,l]),g=!u&&e.type!==Y.Modal;return i(V,{children:i(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:p(s.Menu,{withinPortal:!0,children:[i(s.Menu.Target,{children:i(s.Box,{className:"panel-dropdown-target",sx:{width:"100%",height:"25px"}})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{onClick:a.refreshData,icon:i(T.Refresh,{size:14}),children:"Refresh"}),i(s.Menu.Item,{onClick:a.downloadData,icon:i(T.Download,{size:14}),children:"Download Data"}),g&&i(s.Menu.Item,{onClick:h,icon:i(T.ArrowsMaximize,{size:14}),disabled:!0,children:"Full Screen"}),i(s.Divider,{label:"Edit",labelPosition:"center"}),i(s.Menu.Item,{onClick:d,icon:i(T.Settings,{size:14}),children:"Settings"}),i(s.Menu.Item,{onClick:c,icon:i(T.Copy,{size:14}),children:"Duplicate"}),i(s.Menu.Item,{color:"red",onClick:f,icon:i(T.Trash,{size:14}),children:"Delete"})]})]})})})});function g1(e){return e?["<p><br></p>","<p></p>"].includes(e):!0}const Ti=k.observer(()=>{const[e,t]=b.useState(!1),{panel:n}=gt();return g1(n.description)?null:p(V,{children:[i(s.Modal,{opened:e,onClose:()=>t(!1),title:n.title,withCloseButton:!1,withinPortal:!0,zIndex:310,children:i(Un,{value:n.description,styles:{root:{border:"none"},content:{padding:0}}})}),i(s.Tooltip,{label:"Click to see description",position:"top-start",withinPortal:!0,children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>t(r=>!r),sx:{verticalAlign:"baseline",cursor:"pointer"},children:i(T.InfoCircle,{size:20})})})]})}),KD="",UD="",m1=k.observer(function(){const{panel:t}=gt(),{title:n}=t;return n?i(s.Group,{grow:!0,position:"center",px:20,className:"panel-title-wrapper",sx:{flexGrow:1},children:i(s.Text,{align:"center",lineClamp:1,weight:"bold",children:n})}):null});var fl=(e=>(e.migrated="migrated",e.nothingToMigrate="nothingToMigrate",e.checkFailed="checkFailed",e.migrationFailed="migrationFailed",e))(fl||{}),nr=(e=>(e.notStarted="notStarted",e.inProgress="inProgress",e.done="done",e))(nr||{});class y1{constructor(t){N(this,"vizInstance");N(this,"operationManager");N(this,"triggerManager");N(this,"vizManager");N(this,"runningMigration");N(this,"panelModel");N(this,"status","notStarted");this.panelModel=t.getRequired(we.instanceScope.panelModel),this.vizInstance=t.getRequired(we.instanceScope.vizInstance),this.operationManager=t.getRequired(we.instanceScope.operationManager),this.triggerManager=t.getRequired(we.instanceScope.triggerManager),this.vizManager=t.getRequired(we.vizManager)}async createMigrationTask(){const t=[];try{await this.instanceNeedMigration()&&t.push(()=>this.runInstanceMigration()),await this.interactionNeedMigration()&&t.push(()=>this.runInteractionMigration())}catch(n){return console.warn("check migration failed",n),"checkFailed"}if(t.length===0)return"nothingToMigrate";try{return await Promise.all(t.map(n=>n())),"migrated"}catch(n){return console.warn("migration failed",n),"migrationFailed"}}async runMigration(){return this.runningMigration||(this.status="inProgress",this.runningMigration=this.createMigrationTask().then(t=>(this.status="done",t))),this.runningMigration}async runInteractionMigration(){await this.operationManager.runMigration(),await this.triggerManager.runMigration()}async runInstanceMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData,panelModel:this.panelModel};await t.migrator.migrate(n)}async instanceNeedMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData};return t.migrator.needMigration(n)}async interactionNeedMigration(){return await this.operationManager.needMigration()||await this.triggerManager.needMigration()}}function gl(e){const{panel:t}=gt();return b.useCallback(n=>{const r=n.getRequired(we.vizManager),a=r.resolveComponent(e.viz.type);return n.createScoped().provideFactory(we.instanceScope.vizInstance,()=>r.getOrCreateInstance(e)).provideFactory(we.instanceScope.interactionManager,o=>{const l=o.getRequired(we.instanceScope.vizInstance);return new Tr(l,a,Sn)}).provideFactory(we.instanceScope.operationManager,o=>o.getRequired(we.instanceScope.interactionManager).operationManager).provideFactory(we.instanceScope.triggerManager,o=>o.getRequired(we.instanceScope.interactionManager).triggerManager).provideValue(we.instanceScope.panelModel,t).provideFactory(we.instanceScope.migrator,o=>new y1(o))},[e.viz.type,e.viz.conf])}function ml(e){const[t,n]=b.useState(!1),r=Lo().getRequired(we.instanceScope.migrator);return X.useAsyncEffect(async()=>{const a=r.status===nr.notStarted;n(r.status===nr.done),r.status===nr.notStarted&&r.runMigration().then(o=>{o===fl.migrated&&a&&(e==null||e())}).finally(()=>{n(!0)})},[r]),t}function yl(e,t){const n=Lo().getRequired(we.instanceScope.vizInstance);return b.useEffect(()=>(n.instanceData.setItem(null,t.viz.conf),n.instanceData.watchItem(null,r=>{e(r)})),[e,t.viz.type]),n}function b1({setVizConf:e,...t}){const{panel:n}=t,r=yl(e,n),a=ml(()=>{fn.showNotification({title:`${n.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return X.useAsyncEffect(async()=>{await r.instanceData.setItem(null,n.viz.conf)},[r,n.viz.type]),a?i(qu,{...t}):i(s.Text,{children:"Checking update..."})}function v1(e){const{panel:t,setVizConf:n}=e;yl(n,t);const{inEditMode:r}=b.useContext(wn);return ml(()=>{r&&fn.showNotification({title:`${t.title} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?i(Nu,{...e}):i(s.Text,{children:"Checking update"})}const XD="";function x1(e,t){const{vizManager:n}=b.useContext(st),{panel:{viz:r,title:a,id:o,description:l,queryIDs:u,variables:c}}=gt(),d={title:a,id:o,description:l,queryIDs:u,viz:r,layout:t},f=gl(d);try{return n.resolveComponent(r.type),i(Zn,{configure:f,children:i(v1,{setVizConf:r.setConf,panel:d,data:e,variables:c,vizManager:n})})}catch(h){return console.info(x.get(h,"message")),null}}const bl=k.observer(function({data:t}){const{ref:n,width:r,height:a}=Ee.useElementSize(),o=x1(t,{w:r,h:a}),l=r>0&&a>0;return i("div",{className:"viz-root",ref:n,children:l&&i(Fe,{children:o})})}),vl=k.observer(({panel:e})=>p(s.Stack,{children:[e.queryErrors.map((t,n)=>i(s.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:t},`${n}-${t}`)),e.queryStateMessages.map((t,n)=>i(s.Text,{color:"gray",align:"center",children:t},`${n}-${t}`))]})),Di=k.observer(({panel:e,height:t})=>p(s.Flex,{direction:"column",sx:{height:t,position:"relative",width:"100%"},children:[i(s.LoadingOverlay,{visible:e.dataLoading,exitTransitionDuration:0}),!e.canRenderViz&&i(vl,{panel:e}),e.canRenderViz&&i(bl,{data:e.data})]})),w1={border:"1px solid #e9ecef"},xl=k.observer(({panel:e,panelStyle:t,dropdownContent:n})=>{const r=e.title?"calc(100% - 25px - 5px)":"100%";return i(Cr,{value:{panel:e,data:e.data,loading:e.dataLoading,errors:e.queryErrors},children:p(s.Box,{className:"panel-root",p:5,pt:0,sx:{...w1,...t},children:[i(s.Box,{sx:{position:"absolute",left:0,top:0,height:28,zIndex:310},children:i(Ti,{})}),n,i(m1,{}),i(Di,{panel:e,height:r})]})})}),C1={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function S1(e){return e.style.border.enabled?{}:C1}const Mi=k.observer(function({panel:t,view:n}){const r=S1(t);return i(xl,{panel:t,panelStyle:r,dropdownContent:i(f1,{view:n})})});function _1(e){return!["richText","button"].includes(e)}const k1=k.observer(({view:e})=>{const{panel:t}=gt(),{id:n}=t,{viewPanelInFullScreen:r,inFullScreen:a}=b.useContext(Hn),o=b.useCallback(()=>{r(n)},[n,r]),l=!a&&e.type!==Y.Modal;return _1(t.viz.type)?i(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:p(s.Menu,{withinPortal:!0,children:[i(s.Menu.Target,{children:i(s.Box,{className:"panel-dropdown-target",sx:{width:"100%",height:"25px"}})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{onClick:t.refreshData,icon:i(T.Refresh,{size:14}),children:"Refresh"}),i(s.Menu.Item,{onClick:t.downloadData,icon:i(T.Download,{size:14}),children:"Download Data"}),l&&i(s.Menu.Item,{onClick:o,icon:i(T.ArrowsMaximize,{size:14}),children:"Full Screen"})]})]})}):null});function T1(e){return e.style.border.enabled?{}:{border:"1px dashed transparent"}}const wl=k.observer(({panel:e,view:t})=>{const n=T1(e);return i(xl,{panel:e,panelStyle:n,dropdownContent:i(k1,{view:t})})}),D1={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},Cl=k.observer(function({view:t,panel:n,exitFullScreen:r}){return i(s.Modal,{opened:!0,fullScreen:!0,onClose:r,title:i(s.Button,{color:"blue",size:"xs",onClick:r,leftIcon:i(T.ArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:D1,children:i(s.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:i(wl,{view:t,panel:n})})})});function Sl(e,t,n){const{panels:r}=Me(),a=e.id==="Main",[o,l]=b.useState(()=>a&&r.findByID(t)?t:null),u=b.useCallback(h=>{l(h),a&&n(h)},[a,n]),c=b.useCallback(()=>{l(null),a&&n("")},[a,n]),d=o?r.findByID(o):null;return{viewPanelInFullScreen:u,exitFullScreen:c,inFullScreen:!!d,fullScreenPanel:d}}const JD="",M1=b.forwardRef(({h:e},t)=>i(s.ActionIcon,{ref:t,className:"react-grid-customDragHandle",sx:{userSelect:"none",cursor:"grab",position:"absolute",top:5,right:e>38?5:20,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",children:i(T.ArrowsMove,{size:16})})),I1=b.forwardRef(({handleAxis:e,...t},n)=>i(s.ActionIcon,{ref:n,className:"react-grid-customResizeHandle",sx:{userSelect:"none",cursor:"nwse-resize",position:"absolute",bottom:0,right:0,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",...t,children:i(T.ChevronDownRight,{size:16})})),E1=gn.WidthProvider(gn),A1=k.observer(({view:e,className:t="layout"})=>{const n=Me(),{panels:r,layouts:a}=n.panels.panelsByIDs(e.panelIDs),o=b.useCallback(u=>{u.forEach(({i:c,...d})=>{const f=n.panels.findByID(c);f&&f.layout.set(d)})},[n]),l=(u,c,d,f)=>{d.h<30&&(d.h=30,f.h=30),d.w<4&&(d.w=4,f.w=4)};return i(E1,{onLayoutChange:o,className:`dashboard-layout ${t}`,rowHeight:1,cols:36,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,layout:a,draggableHandle:".react-grid-customDragHandle",resizeHandle:i(I1,{}),onResize:l,children:r.map((u,c)=>p("div",{"data-grid":{...u.layout},className:"panel-grid-item",children:[i(M1,{h:u.layout.h}),i(Mi,{view:e,panel:u})]},u.id))})}),z1=gn.WidthProvider(gn),$1=k.observer(function({view:t,className:n="layout"}){const{panels:r,layouts:a}=Me().panels.panelsByIDs(t.panelIDs);return i(z1,{className:`dashboard-layout ${n}`,cols:36,rowHeight:1,margin:[0,0],isDraggable:!1,isResizable:!1,layout:a,children:r.map(o=>i("div",{"data-grid":{...o.layout},className:"panel-grid-item",children:i(Mi,{view:t,panel:o})},o.id))})}),L1=k.observer(({children:e})=>i(s.Box,{pt:10,pb:100,children:e}));function _l(e){return e.replace(/(vw|vh)/,"%")}const O1=k.observer(({children:e,view:t})=>{const n=t.config,{width:r,height:a}=b.useMemo(()=>({width:_l(n.width),height:_l(n.height)}),[n.width,n.height]);return i(s.Box,{sx:{height:"100%","> div:not(.mantine-Modal-root)":{height:"100%"}},children:i(s.Modal,{size:n.width,opened:!0,onClose:x.noop,withCloseButton:!1,title:n.custom_modal_title.value,trapFocus:!0,onDragStart:o=>{o.stopPropagation()},styles:{root:{position:"relative",height:"100%"},overlay:{position:"absolute !important"},inner:{position:"relative",top:"50%",left:"50%",right:"unset",bottom:"unset",transform:"translate(-50%, -50%)",padding:"0 !important",width:r,height:a,maxHeight:a},content:{border:"1px solid #efefef",height:"100%"},body:{maxHeight:"calc(100% - 48px)",overflow:"auto"}},withinPortal:!1,transitionProps:{duration:0},children:e})})}),P1=({variant:e,orientation:t})=>{const n={tab:{},panel:{padding:"16px"}};return e==="pills"&&t==="horizontal"&&(n.tab.paddingTop="6px",n.tab.paddingBottom="6px"),t==="vertical"&&(n.tab["&.add-a-tab"]={paddingTop:"1px",paddingBottom:"1px"},n.tab["&.add-a-tab .mantine-Tabs-tabLabel"]={marginLeft:"auto",marginRight:"auto"}),n},B1=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},V1=k.observer(({children:e,view:t})=>{const n=Ue.useModals(),r=ue(),a=b.useMemo(()=>r.views.options.filter(c=>c.type===Y.Division),[t.id,r.views.options]),o=t.config,l=c=>n.openConfirmModal({title:"Delete this tab?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{o.removeTab(c)},confirmProps:{color:"red"},zIndex:320}),u=o.tabs.length===0;return p(s.Box,{className:"preview-view-tabs",children:[p(s.Tabs,{variant:o.variant,orientation:o.orientation,defaultValue:o.tabs.length>0?o.tabs[0].id:"0",styles:P1(o),children:[p(s.Tabs.List,{grow:o.grow,children:[o.tabs.map(c=>i(s.Tabs.Tab,{value:c.id,sx:B1(c),children:c.name??c.id},c.id)),i(s.Tabs.Tab,{onClick:o.addTab,value:"add",className:"add-a-tab",children:i(T.Plus,{size:18,color:"#228be6"})})]}),o.tabs.map((c,d)=>{const f=r.views.findByID(c.view_id);return p(s.Tabs.Panel,{value:c.id,sx:{position:"relative"},children:[p(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:200},children:[i(s.Overlay,{opacity:.8,color:"#FFF",blur:10,zIndex:100}),p(s.Stack,{mx:"auto",mt:100,sx:{width:"300px",position:"relative",zIndex:200},children:[i(s.TextInput,{label:"Tab Name",value:c.name,onChange:h=>c.setName(h.currentTarget.value)}),i(s.Select,{label:"View",value:c.view_id,onChange:c.setViewID,data:a}),i(s.ColorInput,{label:"Color",value:c.color,onChange:c.setColor,disabled:o.variant!=="default"}),f&&p(s.Button,{mt:20,variant:"gradient",leftIcon:i(L.IconArrowsLeftRight,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>r.views.setIDOfVIE(f.id),children:["Swith to View: ",f.name]}),i(s.Button,{mt:20,variant:"subtle",color:"red",onClick:()=>l(d),disabled:u,leftIcon:i(L.IconTrash,{size:14}),children:"Delete This Tab"})]})]}),f&&i(rr,{view:f})]},c.id)})]}),e]})}),N1=k.observer(({view:e,children:t})=>{switch(e.type){case Y.Modal:return i(O1,{view:e,children:t});case Y.Tabs:return i(V1,{view:e,children:t});case Y.Division:default:return i(L1,{children:t})}}),kl=k.observer(function({view:t}){return i(Hn.Provider,{value:{viewPanelInFullScreen:x.noop,inFullScreen:!1},children:i(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:i(N1,{view:t,children:p(s.Box,{sx:{position:"relative"},children:[i(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:i(Vo,{view:t})}),i(A1,{view:t})]})})})})}),q1=k.observer(({children:e})=>i(s.Box,{children:e})),F1=k.observer(({children:e,view:t})=>{const n=Me(),r=t.config,a=n.views.visibleViewIDs.includes(t.id),o=()=>n.views.rmVisibleViewID(t.id);return i(s.Modal,{size:r.width,centered:!0,opened:a,onClose:o,withCloseButton:!1,title:r.custom_modal_title.value,trapFocus:!0,onDragStart:l=>{l.stopPropagation()},styles:{root:{position:"fixed",zIndex:200,inset:0},overlay:{zIndex:"unset"},inner:{zIndex:"unset",padding:"0 !important"},content:{border:"1px solid #efefef"},body:{maxHeight:r.height,overflow:"auto"}},transitionProps:{duration:0},children:e})}),G1=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},W1=k.observer(({children:e,view:t})=>{const n=Me(),r=t.config;return p(s.Box,{className:"render-view-tabs",children:[p(s.Tabs,{variant:r.variant,orientation:r.orientation,defaultValue:r.tabs.length>0?r.tabs[0].id:"0",styles:{panel:{padding:r.orientation==="horizontal"?"16px 0px":"0"}},keepMounted:!1,children:[i(s.Tabs.List,{grow:r.grow,children:r.tabs.map(a=>i(s.Tabs.Tab,{value:a.id,sx:G1(a),disabled:!a.view_id,children:a.name??a.id},a.id))}),r.tabs.map(a=>{const o=n.views.findByID(a.view_id);return o?i(s.Tabs.Panel,{value:a.id,children:i(rr,{view:o})},a.id):null})]}),e]})}),R1=k.observer(({view:e,children:t})=>{switch(e.type){case Y.Modal:return i(F1,{view:e,children:t});case Y.Tabs:return i(W1,{view:e,children:t});case Y.Division:default:return i(q1,{children:t})}}),rr=k.observer(function({view:t}){const{fullScreenPanelID:n,setFullScreenPanelID:r}=is(),{viewPanelInFullScreen:a,exitFullScreen:o,inFullScreen:l,fullScreenPanel:u}=Sl(t,n,r);return i(Hn.Provider,{value:{viewPanelInFullScreen:a,inFullScreen:l},children:p(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,children:[l&&i(Cl,{view:t,panel:u,exitFullScreen:o}),i(R1,{view:t,children:p(s.Box,{sx:{position:"relative"},children:[!l&&i(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:i(Vo,{view:t})}),!l&&i($1,{view:t})]})})]})})});function j1(e,t,n){y.addDisposer(e,y.addMiddleware(e,(r,a)=>{a(r,()=>{y.getType(r.context)===t&&r.type==="action"&&n(r.name,r.context)})}))}const Tl=y.types.compose("FiltersModel",sl,y.types.model("FiltersModel",{previewValues:y.types.optional(y.types.frozen(),{})})).views(e=>({get options(){return e.current.map(t=>({label:t.label??t.id,value:t.id,_type:"filter"}))},get keyLabelOptions(){return e.current.map(t=>({label:t.label??t.key,value:t.key}))}})).actions(e=>({replace(t){e.current=y.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const n=e.current.findIndex(r=>r.id===t);n>=0&&e.current.splice(n,1)},updatePreviewValues(t){e.previewValues=t}})).actions(e=>{function t(){j1(e.current,Uo,(n,r)=>{if(n==="setType"){const a=al(r.config.default_value,r.config);e.setValueByKey(r.key,a),e.updatePreviewValues({...e.previewValues,[r.key]:a})}})}return{afterCreate(){t()}}}),Dl=pl.views(e=>({get options(){const t=e.current.map(n=>({value:n.id,label:n.name,_type:"query"}));return x.sortBy(t,n=>n.label.toLowerCase())}})).actions(e=>({replace(t){e.current=y.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},replaceByIndex(t,n){e.current.splice(t,1,n)},removeQuery(t){const n=e.current.find(r=>r.id===t);n&&(y.detach(n),e.current.remove(n))}})),Ml=hl.views(e=>({get options(){const t=e.current.map(n=>({label:n.key,value:n.key,_type:"sql_snippet"}));return x.sortBy(t,n=>n.label.toLowerCase())}})).actions(e=>({replace(t){e.current=y.cast(t)},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByKey(t){const n=e.current.findIndex(r=>r.key===t);n>=0&&e.current.splice(n,1)},replaceByIndex(t,n){e.current.splice(t,1,n)}})),Y1=y.types.model({data:y.types.optional(y.types.frozen(),[]),state:y.types.optional(y.types.enumeration(["idle","loading","error"]),"idle"),error:y.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0},get sql(){const t=y.getParent(e,1),{type:n,table_name:r,table_schema:a}=t;if(n===Ce.MySQL)return`
419
+ SELECT ordinal_position, column_key, column_name, column_type, is_nullable, column_default, column_comment
420
+ FROM information_schema.columns
421
+ WHERE table_name = '${r}' AND table_schema = '${a}'
422
+ `;if(n===Ce.Postgresql){const o=`'${a}.${r}'::regclass`;return`
423
+ SELECT
424
+ ordinal_position,
425
+ UPPER(pc.contype) AS column_key,
426
+ pg_get_constraintdef(pc.oid) AS column_key_text,
427
+ column_name,
428
+ format_type(atttypid, atttypmod) AS column_type,
429
+ is_nullable,
430
+ column_default,
431
+ pg_catalog.col_description(${o}, ordinal_position) AS column_comment
432
+ FROM
433
+ information_schema.columns
434
+ JOIN pg_attribute pa ON pa.attrelid = ${o}
435
+ AND attname = column_name
436
+ LEFT JOIN pg_constraint pc ON pc.conrelid = ${o} AND ordinal_position = any(pc.conkey)
437
+ WHERE
438
+ table_name = '${r}' AND table_schema = '${a}';
439
+ `}return""}})),Q1=y.types.model({data:y.types.optional(y.types.frozen(),[]),state:y.types.optional(y.types.enumeration(["idle","loading","error"]),"idle"),error:y.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0},get sql(){const t=y.getParent(e,1),{type:n,table_name:r,table_schema:a}=t;return n===Ce.MySQL?`
440
+ SELECT
441
+ sub_part AS index_length,
442
+ index_name AS index_name,
443
+ index_type AS index_algorithm,
444
+ CASE non_unique WHEN 0 THEN 'TRUE' ELSE 'FALSE' END AS is_unique,
445
+ column_name AS column_name
446
+ FROM
447
+ information_schema.statistics
448
+ WHERE
449
+ table_name = '${r}' AND table_schema = '${a}'
450
+ ORDER BY
451
+ seq_in_index ASC;
452
+ `:n===Ce.Postgresql?`
453
+ SELECT
454
+ ix.relname AS index_name,
455
+ upper(am.amname) AS index_algorithm,
456
+ indisunique AS is_unique,
457
+ pg_get_indexdef(indexrelid) AS index_definition,
458
+ CASE WHEN position(' WHERE ' IN pg_get_indexdef(indexrelid)) > 0 THEN
459
+ regexp_replace(pg_get_indexdef(indexrelid), '.+WHERE ', '')
460
+ WHEN position(' WITH ' IN pg_get_indexdef(indexrelid)) > 0 THEN
461
+ regexp_replace(pg_get_indexdef(indexrelid), '.+WITH ', '')
462
+ ELSE
463
+ ''
464
+ END AS condition,
465
+ pg_catalog.obj_description(i.indexrelid, 'pg_class') AS comment
466
+ FROM
467
+ pg_index i
468
+ JOIN pg_class t ON t.oid = i.indrelid
469
+ JOIN pg_class ix ON ix.oid = i.indexrelid
470
+ JOIN pg_namespace n ON t.relnamespace = n.oid
471
+ JOIN pg_am AS am ON ix.relam = am.oid
472
+ WHERE
473
+ t.relname = '${r}' AND n.nspname = '${a}';
474
+ `:""}})),K1=y.types.model({page:y.types.optional(y.types.number,1),limit:y.types.optional(y.types.number,20),data:y.types.optional(y.types.frozen(),[]),total:y.types.optional(y.types.number,0),state:y.types.optional(y.types.enumeration(["idle","loading","error"]),"idle"),error:y.types.frozen()}).views(e=>({get keywords(){return y.getParent(e,1)},get keywordString(){const{table_name:t,table_schema:n}=y.getParent(e,1);return`${n}||${t}`}})).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0},get maxPage(){return Math.ceil(e.total/e.limit)},get sql(){const t=y.getParent(e,1),{table_name:n,table_schema:r}=t;return`
475
+ SELECT *
476
+ FROM ${r}.${n}
477
+ LIMIT ${e.limit} OFFSET ${(e.page-1)*e.limit}
478
+ `},get countSql(){const{table_name:t,table_schema:n}=e.keywords;return`
479
+ SELECT count(*) AS total
480
+ FROM ${n}.${t}
481
+ `}})).actions(e=>({setPage(t){e.page=t},resetPage(){e.page=1},setLimit(t){e.limit=t}})).actions(e=>({afterCreate(){y.addDisposer(e,re.reaction(()=>e.keywordString,e.resetPage,{fireImmediately:!1,delay:0})),y.addDisposer(e,re.reaction(()=>e.limit,e.resetPage,{fireImmediately:!1,delay:0}))}})),U1=y.types.model({data:y.types.optional(y.types.frozen(),{}),state:y.types.optional(y.types.enumeration(["idle","loading","error"]),"idle"),error:y.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return Object.keys(e.data).length===0},get sql(){const t=y.getParent(e,1).type;return t===Ce.MySQL||t===Ce.Postgresql?"SELECT table_schema, table_name, table_type FROM information_schema.tables ORDER BY table_schema, table_name":""}})),X1=y.types.compose("DataSourceModel",Ho,y.types.model({tables:y.types.optional(U1,{}),columns:y.types.optional(Y1,{}),tableData:y.types.optional(K1,{}),indexes:y.types.optional(Q1,{}),table_schema:y.types.optional(y.types.string,""),table_name:y.types.optional(y.types.string,"")})).volatile(()=>({controllers:{tables:new AbortController,columns:new AbortController,indexes:new AbortController,tableData:new AbortController}})).actions(e=>({setKeywords(t,n){e.table_schema=t,e.table_name=n}})).actions(e=>({initKeywords(){if(e.tables.empty)return;const t=Object.keys(e.tables.data)[0],n=e.tables.data[t][0].table_name;e.setKeywords(t,n)}})).actions(e=>{const t=y.flow(function*(){var n;(n=e.controllers.tables)==null||n.abort(),e.controllers.tables=new AbortController,e.tables.state="loading";try{const r=yield*y.toGenerator(qe.query(e.controllers.tables.signal)({type:e.type,key:e.key,query:e.tables.sql},{}));e.tables.data=x.groupBy(r,"table_schema"),e.tables.state="idle",e.tables.error=null,e.initKeywords()}catch(r){if(!ht.isCancel(r)){e.tables.data={};const a=x.get(r,"message","unkown error");e.tables.error=x.get(r,"response.data.detail.message",a),e.tables.state="error"}}});return{loadTables:t,loadTablesIfEmpty(){e.tables.empty&&t()},loadColumns:y.flow(function*(){var n;(n=e.controllers.columns)==null||n.abort(),e.controllers.columns=new AbortController,e.columns.state="loading";try{e.columns.data=yield*y.toGenerator(qe.query(e.controllers.columns.signal)({type:e.type,key:e.key,query:e.columns.sql},{})),e.columns.state="idle",e.columns.error=null}catch(r){if(ht.isCancel(r))e.columns.state="idle",e.columns.error=null;else{e.columns.data=[];const a=x.get(r,"message","unkown error");e.columns.error=x.get(r,"response.data.detail.message",a),e.columns.state="error"}}}),loadIndexes:y.flow(function*(){var n;(n=e.controllers.indexes)==null||n.abort(),e.controllers.indexes=new AbortController,e.indexes.state="loading";try{e.indexes.data=yield*y.toGenerator(qe.query(e.controllers.indexes.signal)({type:e.type,key:e.key,query:e.indexes.sql},{})),e.indexes.state="idle",e.indexes.error=null}catch(r){if(ht.isCancel(r))e.indexes.state="idle",e.indexes.error=null;else{e.indexes.data=[];const a=x.get(r,"message","unkown error");e.indexes.error=x.get(r,"response.data.detail.message",a),e.indexes.state="error"}}}),loadTableData:y.flow(function*(){var r;(r=e.controllers.tableData)==null||r.abort(),e.controllers.tableData=new AbortController;const n=e.tableData;n.state="loading";try{n.data=yield*y.toGenerator(qe.query(e.controllers.tableData.signal)({type:e.type,key:e.key,query:n.sql},{}));const[{total:a}]=yield*y.toGenerator(qe.query(e.controllers.tableData.signal)({type:e.type,key:e.key,query:n.countSql},{}));n.total=Number(a),n.state="idle",n.error=null}catch(a){if(ht.isCancel(a))n.state="idle",n.error=null;else{n.data=[];const o=x.get(a,"message","unkown error");n.error=x.get(a,"response.data.detail.message",o),n.state="error"}}})}}).actions(e=>({afterCreate(){y.addDisposer(e,re.reaction(()=>e.columns.sql,e.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(e=>({afterCreate(){y.addDisposer(e,re.reaction(()=>e.indexes.sql,e.loadIndexes,{fireImmediately:!1,delay:500})),y.addDisposer(e,re.reaction(()=>e.tableData.sql,e.loadTableData,{fireImmediately:!1,delay:0}))}})),J1=y.types.model("DataSourcesModel",{list:y.types.optional(y.types.array(X1),[])}).views(e=>({find({type:t,key:n}){return e.list.find(r=>r.key===n&&r.type===t)},get options(){return e.list.map(t=>({value:t.key,label:t.key}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}}));function ir(e){return{label:e,value:e,_type:"ACTION",_action_type:e,Icon:null,children:null}}function Z1(e){switch(e._type){case"GROUP":case"ACTION":return null;case"query_variables":return["_QUERY_VARS_"];case"mock_context":return["_MOCK_CONTEXT_"];case"filter":return["_FILTERS_",e.value];case"sql_snippet":return["_SQL_SNIPPETS_",e.value];case"query":return["_QUERIES_",e.value];case"view":return["_VIEWS_",e.value];case"panel":return e.parentID?["_VIEWS_",e.parentID,"_PANELS_",e.value]:(console.error("[getPathFromOption] parentID is required"),null)}}const H1=y.types.model("EditorModel",{path:y.types.optional(y.types.frozen(),[]),settings_open:y.types.optional(y.types.boolean,!1)}).views(e=>({get navOptions(){const{content:t}=y.getRoot(e),{filters:n,views:r,sqlSnippets:a,queries:o}=t;return[{label:"Query Variables",value:"_QUERY_VARS_",_type:"query_variables",Icon:L.IconVariable},{label:"Mock Context",value:"_MOCK_CONTEXT_",Icon:L.IconCodeDots,_type:"mock_context"},{label:"Filters",value:"_FILTERS_",Icon:L.IconFilter,children:[...n.options,ir("_Add_A_Filter_")],_type:"GROUP"},{label:"SQL Snippets",value:"_SQL_SNIPPETS_",Icon:L.IconCopy,children:[...a.options,ir("_Add_A_SQL_SNIPPET_")],_type:"GROUP"},{label:"Queries",value:"_QUERIES_",Icon:L.IconDatabase,children:[...o.options,ir("_Add_A_QUERY_")],_type:"GROUP"},{label:"Views",value:"_VIEWS_",Icon:L.IconBoxMultiple,children:[...r.editorOptions,ir("_Add_A_VIEW_")],_type:"GROUP"}]},isOptionActive(t,n){return t.length===0?!1:t[t.length-1]===n.value},isOptionOpened(t){const{path:n}=e;return n.length===0||!t.children||t.children.length===0?!1:n.includes(t.value)}})).actions(e=>({setPath(t){e.path=t},setSettingsOpen(t){e.settings_open=t}})).actions(e=>({open(t){e.setPath(t),e.setSettingsOpen(!0)},close(){e.setSettingsOpen(!1)},navigate(t){const n=Z1(t);n&&e.setPath(n)}})),Il=rl.views(e=>({get dataFieldOptions(){return e.queryIDs.length===0?[]:e.queries.map(t=>{const n=t.data;return n.length===0?[]:Object.keys(n[0]).map(a=>({label:a,value:`${t.id}.${a}`,group:t.name}))}).flat()}})).actions(e=>({removeSelf(){y.getParent(e,2).removeByID(e.id)}})).actions(e=>({moveToView(t,n){y.getRoot(e).content.views.findByID(t).removePanelID(e.id),y.getRoot(e).content.views.findByID(n).appendPanelID(e.id),y.getRoot(e).editor.setPath(["_VIEWS_",n,"_PANELS_",e.id])}})),El=y.types.compose("PanelsModel",il,y.types.model({list:y.types.optional(y.types.array(Il),[])})).views(e=>({editorOptions(t,n){const{panels:r}=e.panelsByIDs(n);r.length!==n.length&&console.warn(`Unfulfilled panels for View[${t}]`);const a=r.map(l=>({label:l.title?l.title:x.capitalize(l.viz.type),value:l.id,_type:"panel",parentID:t})),o="_Add_A_PANEL_";return a.push({label:o,value:o,_type:"ACTION",_action_type:o,parentID:t,Icon:null,children:null}),a}})).actions(e=>({replace(t){e.list=y.castToSnapshot(t)},append(t){e.list.push(t)},remove(t){e.list.splice(t,1)},removeByID(t){const n=e.list.findIndex(r=>r.id===t);n!==-1&&e.list.splice(n,1)},duplicateByID(t){const n=e.list.find(a=>a.id===t);if(!n){console.error(new Error(`[duplicate panel] Can't find a panel by id[${t}]`));return}const r=new Date().getTime().toString();return e.list.push({...n.json,id:r,layout:{...n.layout,y:1/0,moved:!1}}),r},replaceByIndex(t,n){e.list.splice(t,1,n)}})),Al=y.types.compose("ViewsModel",nl,y.types.model({idOfVIE:y.types.string})).views(e=>({get isVIETheFirstView(){return e.current.length===0||!e.idOfVIE?!1:e.current[0].id===e.idOfVIE},get VIE(){return e.current.find(({id:t})=>t===e.idOfVIE)},get options(){return e.current.map(t=>({label:t.name,value:t.id,type:t.type}))},get editorOptions(){const t=y.getRoot(e).content.panels;return e.current.map(n=>({label:n.name,value:n.id,_type:"view",children:t.editorOptions(n.id,n.panelIDs)}))}})).actions(e=>({setIDOfVIE(t){e.idOfVIE=t,e.visibleViewIDs.length=0,e.visibleViewIDs.push(t)},replace(t){e.current.replace(t)},addANewView(t,n,r,a){e.current.push({id:t,name:n,type:r,config:a,panelIDs:[]})},append(t){e.current.push(t)},remove(t){e.current.splice(t,1)},removeByID(t){const n=e.current.findIndex(r=>r.id===t);n!==-1&&e.current.splice(n,1)},replaceByIndex(t,n){e.current.splice(t,1,n)},addARandomNewView(){const t=new Date().getTime().toString();this.addANewView(t,Y.Division,Y.Division,{_name:Y.Division}),this.setIDOfVIE(t)},removeVIE(){e.current.length!==1&&(this.removeByID(e.idOfVIE),this.setIDOfVIE(e.current[0].id))}}));function Ii(e){const t=e.length>0?[e[0].id]:[],n=e.length>0?e[0].id:"";return{current:e.map(a=>{const{_name:o=a.type}=a.config;return{...a,config:{...a.config,_name:o},panelIDs:a.panelIDs}}),visibleViewIDs:t,idOfVIE:n}}const eS=y.types.model({id:y.types.string,name:y.types.string,dashboard_id:y.types.string,create_time:y.types.string,update_time:y.types.string,version:y.types.string,filters:Tl,queries:Dl,sqlSnippets:Ml,views:Al,panels:El,mock_context:No,origin:y.types.maybe(y.types.frozen())}).views(e=>({get json(){return{id:e.id,name:e.name,create_time:e.create_time,update_time:e.update_time,dashboard_id:e.dashboard_id,content:{views:e.views.json,panels:e.panels.json,filters:e.filters.json,version:e.version,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get filtersChanged(){const t="filters.current";return!x.isEqual(y.getSnapshot(x.get(e,t)),x.get(e.origin,t))},get queriesChanged(){const t="queries.current",n=y.getSnapshot(x.get(e,t)).map(r=>x.pick(r,["id","name","key","type","sql","run_by","react_to","pre_process","post_process"]));return!x.isEqual(n,x.get(e.origin,t))},get sqlSnippetsChanged(){const t="sqlSnippets.current";return!x.isEqual(y.getSnapshot(x.get(e,t)),x.get(e.origin,t))},get viewsChanged(){const t="views.current";return!x.isEqual(y.getSnapshot(x.get(e,t)),x.get(e.origin,t))},get panelsChanged(){const t="panels.list";return!x.isEqual(y.getSnapshot(x.get(e,t)),x.get(e.origin,t))},get mockContextChanged(){const t="mock_context.current";return!x.isEqual(x.get(e,t),x.get(e.origin,t))},get payloadForSQL(){const t=y.getParent(e).context.current,n=y.getParent(e).globalSQLSnippets,r={context:{...e.mock_context.current,...t},filters:e.filters.values};return{...r,sql_snippets:tr(e.sqlSnippets.current,"key","value",r),global_sql_snippets:tr(n.list,"id","content",r)}},get payloadForViz(){const t=y.getParent(e).context.current;return{context:{...e.mock_context.current,...t},filters:e.filters.values}},get changed(){return this.filtersChanged||this.queriesChanged||this.sqlSnippetsChanged||this.viewsChanged||this.panelsChanged||this.mockContextChanged},get data(){return e.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(t){const n=e.queries.findByID(t);return n?{data:n.data.toJSON(),len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).views(e=>({findQueryUsage(t){const n=e.panels.idMap,r=e.views.current.flatMap(l=>l.panelIDs.map(u=>n.get(u)).filter(u=>(u==null?void 0:u.queryIDSet.has(t))??!1).map(u=>({type:"panel",id:u.id,label:u.title?u.title:u.viz.type,views:[{id:l.id,label:l.name}]}))),a=e.views.idMap,o=e.filters.current.filter(l=>x.get(l,"config.options_query_id")===t).map(l=>({type:"filter",id:l.id,label:l.label,views:l.visibleInViewsIDs.map(u=>{var c;return{id:u,label:((c=a.get(u))==null?void 0:c.name)??u}})}));return r.concat(o)}})).actions(e=>({duplicatePanelByID(t,n){var a;const r=e.panels.duplicateByID(t);r&&((a=e.views.findByID(n))==null||a.appendPanelID(r))},removePanelByID(t,n){var r;e.panels.removeByID(t),(r=e.views.findByID(n))==null||r.removePanelID(t)},addANewPanel(t){var r;const n=new Date().getTime().toString();e.panels.append(ZC(n)),(r=e.views.findByID(t))==null||r.appendPanelID(n)}})).actions(e=>({reset(){y.applySnapshot(e.filters.current,e.origin.filters.current),y.applySnapshot(e.queries.current,e.origin.queries.current),y.applySnapshot(e.sqlSnippets.current,e.origin.sqlSnippets.current),y.applySnapshot(e.views.current,e.origin.views.current),y.applySnapshot(e.panels.list,e.origin.panels.list),e.mock_context.current=e.origin.mock_context.current},resetFilters(){y.applySnapshot(e.filters.current,e.origin.filters.current)},updateCurrent(t){const{id:n,name:r,content:a}=t;if(!a)throw new Error("unexpected null content when updating a content model");const{version:o,filters:l,views:u,panels:c,definition:{queries:d,sqlSnippets:f,mock_context:h={}}}=a;e.id=n,e.name=r,e.version=o,y.applySnapshot(e.filters.current,l),y.applySnapshot(e.views.current,Ii(u).current),y.applySnapshot(e.panels.list,c),y.applySnapshot(e.queries.current,d),y.applySnapshot(e.sqlSnippets.current,f),e.mock_context.current=h}})),Ei=y.types.snapshotProcessor(eS,{preProcessor(e){return{...e,origin:e}},postProcessor(e){delete e.origin;const t=y.castToSnapshot(e.queries.current.map(n=>x.pick(n,["id","key","type","sql"])));return x.defaults({},{queries:{current:t}},e)}});function tS(e,t){t.filters&&y.applySnapshot(e.filters.current,t.filters)}function zl({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:l,filters:u,views:c,panels:d,definition:{queries:f,sqlSnippets:h,mock_context:g={}}}=o;return Ei.create({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,version:l,filters:ol(u),queries:{current:f},sqlSnippets:{current:h},mock_context:qo(g),views:Ii(c),panels:{list:d}})}const $l=y.types.model({id:y.types.identifier,name:y.types.string,group:y.types.string,content:Ei,content_id:y.types.string,datasources:J1,globalSQLSnippets:el,context:ki,editor:H1}).views(e=>({get json(){return{id:e.id,name:e.name,group:e.group,content_id:e.content_id}}})).actions(e=>({updateCurrentContent(t){e.content.updateCurrent(t)},updateCurrent(t,n){const{id:r,name:a,group:o,content_id:l}=t;e.id=r,e.name=a,e.group=o,e.content_id=l,this.updateCurrentContent(n)}}));function Ll({id:e,name:t,group:n,content_id:r},a,o,l,u){return $l.create({id:e,name:t,group:n,content_id:r,content:zl(a),datasources:{list:o},globalSQLSnippets:{list:l},context:tl(u),editor:{}})}function Ol(e,t){b.useEffect(()=>{const n=r=>{console.log(r);const{viewID:a}=r.detail;if(!a){console.error(new Error("[Open View] Needs to pick a view first"));return}e.views.appendToVisibles(a),t&&e.views.setIDOfVIE(a)};return window.addEventListener("open-view",n),()=>{window.removeEventListener("open-view",n)}},[e,t]),b.useEffect(()=>{const n=r=>{console.log(r);const{dictionary:a,payload:o}=r.detail;if(!o||Object.keys(o).length===0){console.error(new Error("[Set Filter Values] payload is empty"));return}Object.entries(a).forEach(([l,u])=>{e.filters.setValueByKey(l,x.get(o,u))})};return window.addEventListener("set-filter-values",n),()=>{window.removeEventListener("set-filter-values",n)}},[e]),b.useEffect(()=>{function n(a){return Array.isArray(a)?[]:typeof a=="object"?{}:typeof a=="boolean"?!1:typeof a=="string"?"":typeof a=="number"?0:a}const r=a=>{console.log(a);const{filter_keys:o}=a.detail;o.forEach(l=>{const u=x.get(e.filters.values,l),c=n(u);console.log(`${l}: ${c}`),e.filters.setValueByKey(l,c)})};return window.addEventListener("clear-filter-values",r),()=>{window.removeEventListener("clear-filter-values",r)}},[e]),b.useEffect(()=>{const n=r=>{console.log(r);const{urlTemplate:a,openInNewTab:o,enableEncoding:l=!1,payload:u}=r.detail;if(!a){console.error(new Error("[Open Link] URL is empty"));return}function c(h){return x.cloneDeepWith(h,m=>{if(l&&typeof m=="string")return encodeURIComponent(m)})}const f=x.template(a||"")(c({...u,filters:e.payloadForSQL.filters,context:e.payloadForSQL.context}));window.open(f,o?"_blank":"_self","noopener")};return window.addEventListener("open-link",n),()=>{window.removeEventListener("open-link",n)}},[e])}function Pl(e){return b.useCallback(t=>t.provideValue(we.pluginManager,e.pluginManager).provideValue(we.vizManager,e.vizManager).provideValue(we.colorManager,e.colorManager),[])}const ZD="",nS=k.observer(({headerMenuItems:e=null})=>{const t=Ha(),n=ue(),r=()=>{const a=JSON.stringify(n.json,null,2),o=`${t.name}__${n.name}`;l1(o,a)};return p(s.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:310,children:[i(s.Menu.Target,{children:i(s.ActionIcon,{variant:"light",color:"blue",children:i(L.IconMenu2,{size:14})})}),p(s.Menu.Dropdown,{children:[i(s.Menu.Item,{icon:i(L.IconDownload,{size:14}),onClick:n.queries.downloadAllData,children:"Download Data"}),i(s.Menu.Item,{icon:i(L.IconCode,{size:14}),onClick:r,children:"Download Schema"}),e]})]})}),rS=k.observer(({saveDashboardChanges:e})=>{const t=Ue.useModals(),n=ue(),r=()=>{t.openConfirmModal({title:p(s.Group,{position:"left",children:[i(L.IconAlertTriangle,{size:18,color:"red"}),i(s.Text,{children:"You are reverting changes"})]}),labels:{confirm:"Confirm",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:()=>n.reset(),zIndex:320,withCloseButton:!1})},a=n.changed;return p(s.Group,{spacing:0,children:[i(s.Button,{color:"green",variant:"filled",size:"xs",leftIcon:i(L.IconDeviceFloppy,{size:18}),onClick:e,disabled:!a,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:"Save Changes"}),p(s.Menu,{width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:320,disabled:!a,children:[i(s.Menu.Target,{children:i(s.ActionIcon,{variant:"default",disabled:!a,sx:{height:"30px",borderTopLeftRadius:0,borderBottomLeftRadius:0,svg:{fill:"rgb(173, 181, 189)",stroke:"none"}},children:i(L.IconCaretDown,{size:18})})}),i(s.Menu.Dropdown,{children:i(s.Menu.Item,{icon:i(L.IconRecycle,{size:14,color:"red"}),disabled:!a,onClick:r,children:"Revert Changes"})})]})]})}),iS=k.observer(({saveDashboardChanges:e,headerSlot:t=null,headerMenuItems:n})=>{const r=Su.useNavigate(),a=me(),o=()=>{r(`/dashboard/${a.id}`)},l=Ue.useModals(),u=()=>{l.openConfirmModal({title:p(s.Group,{position:"left",children:[i(L.IconAlertTriangle,{size:18,color:"red"}),i(s.Text,{children:"There are unsaved changes"})]}),labels:{confirm:"Discard",cancel:"Cancel"},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:o,zIndex:320,withCloseButton:!1})},c=a.content.changed;return i(s.Header,{height:60,px:"md",py:0,sx:{zIndex:299},children:p(s.Group,{position:"apart",sx:{height:60,minWidth:"1000px",position:"relative"},children:[p(s.Group,{children:[i(s.Button,{size:"xs",color:c?"red":"green",leftIcon:i(L.IconArrowLeft,{size:20}),onClick:c?u:o,children:p(s.Group,{spacing:4,children:["End Editing",i(s.Text,{td:"underline",children:a.name})]})}),i(rS,{saveDashboardChanges:e})]}),p(s.Group,{position:"right",sx:{flexGrow:1},children:[t,i(nS,{headerMenuItems:n})]})]})})}),aS={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},sS=k.observer(()=>{const e=ue();return i(s.Box,{sx:aS,pl:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},children:p(s.Group,{position:"apart",align:"center",sx:{height:"30px"},pr:16,children:[i(s.Button,{variant:"outline",color:"blue",radius:0,size:"xs",disabled:!e.views.VIE,onClick:()=>e.addANewPanel(e.views.idOfVIE),leftIcon:i(L.IconPlaylistAdd,{size:20}),sx:{height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef",background:"rgb(231, 245, 255)"},children:"Add a Panel"}),i(s.Box,{}),i(s.Box,{})]})})}),oS=k.observer(e=>p(V,{children:[i(iS,{...e}),i(sS,{})]})),HD="";function lS(e,t,n){const r=[];return e.filter(a=>"__INTERACTIONS"in a.viz.conf).forEach((a,o)=>{const l=t[a.id];l.data.interactions=x.get(l,"data.interactions",[]);const{__INTERACTIONS:u,__OPERATIONS:c,__TRIGGERS:d}=a.viz.conf;Object.entries(c).forEach(([f,h])=>{const{schemaRef:g,data:m}=h,{config:C}=m;switch(g){case"builtin:op:open-link":let w=C.urlTemplate.substring(0,100);C.urlTemplate.length>=20&&(w+="..."),l.type="interaction",l.data.interactions.push({schemaRef:g,urlTemplate:C.urlTemplate,shortURLTemplate:w});return;case"builtin:op:open_view":r.push({id:`OPERATION--${f}`,source:a.id,target:C.viewID,label:"Open View",style:{stroke:"rgba(0,0,0,0.8)"},type:"default"});return;case"builtin:op:set_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:g,filters:Object.keys(C.dictionary).map(_=>({key:_,label:n[_]}))});return;case"builtin:op:clear_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:g,filters:C.filter_keys.map(_=>({key:_,label:n[_]}))});return;default:return}})}),r}function uS(e,t){const n=e.filters.keyLabelMap;return{edges:lS(e.panels.list,t,n),edgeNodes:[]}}var Bl=(e=>(e.Use="use",e.Edit="edit",e))(Bl||{});const cS={[Y.Division]:"Division",[Y.Tabs]:"Tabs",[Y.Modal]:"Modal"},Vl={[Y.Division]:"rgba(255, 0, 0, 0.2)",[Y.Modal]:"rgba(0, 0, 0, 0.2)",[Y.Tabs]:"rgba(255, 200, 100, 0.4)"},dS={[Y.Division]:"#ff4000",[Y.Modal]:"#000",[Y.Tabs]:"#ffad18"},pS={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:Y.Division,config:{},panelIDs:[]}],panels:[],filters:[],version:"9.19.0"};function Nl(e,t,n){return e*t+e*n}function hS(e,t,n){return e*t+(e-1)*n}const ar=25,Ai=40,ql=25,zi=350,fS=150,gS=150,Fl=150,Gl=300,sr=40,Wl=25,mS=300;function yS(e,t){const n=x.keyBy(t,a=>a.id),r=[];return e.current.forEach((a,o)=>{a.panelIDs.forEach((l,u)=>{const c=Nl(u,sr,Wl)+Ai,d=n[l];if(!d){r.push({id:l,_node_type:"panel",parentNode:a.id,data:{label:`!: ${l}`},position:{x:ar,y:c},sourcePosition:ze.Position.Right,targetPosition:ze.Position.Left,style:{width:Gl,height:sr}});return}const f=d.title.trim()?`${d.title}`:d.viz.type;r.push({id:d.id,_node_type:"panel",parentNode:a.id,data:{label:f},position:{x:ar,y:c},sourcePosition:ze.Position.Right,targetPosition:ze.Position.Left,style:{width:Gl,height:sr}})})}),r}const bS={[Y.Division]:"Div",[Y.Modal]:"Modal",[Y.Tabs]:"Tabs"},vS=Vl;function xS(e){return e.current.map((n,r)=>{const a=hS(n.panelIDs.length,sr,Wl)+Ai+ql;let o=[];return n.type===Y.Tabs&&(o=n.config.tabs.map(u=>u.view_id)),{id:n.id,_node_type:"view-root",_view_type:n.type,_view_level:0,_sub_view_ids:[],_tab_view_ids:o,data:{label:`${bS[n.type]}:${n.name}`},position:{x:0,y:0},sourcePosition:ze.Position.Right,targetPosition:ze.Position.Left,className:"light",style:{backgroundColor:vS[n.type],width:zi,height:a}}})}function wS(e){const t=x.keyBy(e,n=>n.id);e.forEach(n=>{n._node_type!=="view-root"||n._view_type!==Y.Tabs||n._tab_view_ids.forEach(r=>{t[r].parentNode=n.id})})}function CS(e){const t=xS(e.views);wS(t);const n=yS(e.views,e.panels.list);return[...t,...n]}function SS({nodeMap:e,nodes:t,edges:n}){t.forEach(r=>{r._node_type!=="view-root"||r._view_type!==Y.Tabs||(r.sourcePosition=ze.Position.Bottom,r.style.width=zi+ar*2,r.style.height=ql+r._tab_view_ids.reduce((a,o)=>{const l=e[o];l.position.y=a,l.position.x=ar;const u=l.style.height;return a+u+20},Ai))})}function _S({nodeMap:e,nodes:t,edges:n}){n.filter(r=>r.label==="Open View").forEach(r=>{const a=e[r.source],o=e[r.target];if(!a||!o||!a.parentNode)return;const l=e[a.parentNode];l._node_type!=="view-root"||o._node_type!=="view-root"||(o._view_level+=1+l._view_level,l._sub_view_ids.push(o.id))}),t.sort((r,a)=>r._node_type==="view-root"&&a._node_type==="view-root"?r._view_level-a._view_level:r._node_type!=="view-root"&&a._node_type!=="view-root"?0:r._node_type==="view-root"?-1:1)}function kS({nodeMap:e,nodes:t,edges:n}){const r={};n.forEach(a=>{if(a.label!=="Open View")return;const o=e[a.source],l=e[a.target];if(o&&l&&o.parentNode){const u=e[o.parentNode],c=u.position.x,d=Number(x.get(l,"style.height",0)),f=Number(u.style.width);l.position.x=c+f+mS,u._view_level===0&&l._sub_view_ids.length===0&&(o.sourcePosition=ze.Position.Left,l.targetPosition=ze.Position.Right,l.position.x*=-1);const g=l.position.x,m=x.get(r,g,0);l.position.y=m,r[g]=m+d+Fl}})}function TS({nodeMap:e,nodes:t,edges:n}){const r=new Set,a=new Set;n.forEach(l=>{r.add(l.source),a.add(l.target)}),t.filter(l=>l._node_type!=="view-root"||l.id==="Main"||l.parentNode?!1:!r.has(l.id)&&!a.has(l.id)).forEach((l,u)=>{l.position.x=Nl(u,zi,gS),l.position.y=0-fS-Fl})}function DS({nodeMap:e,nodes:t,edges:n}){const r={nodeMap:e,nodes:t,edges:n};return TS(r),_S(r),SS(r),kS(r),{nodes:t,edges:n}}function MS(e){const t=CS(e),n=x.keyBy(t,c=>c.id),{edges:r,edgeNodes:a}=uS(e,n),o=[...t,...a],l=x.keyBy(o,c=>c.id),u={edges:x.uniqBy(r,c=>c.id),nodes:o,nodeMap:l};return DS(u)}const eM="",$i={"builtin:op:open-link":i(s.ThemeIcon,{color:"blue",size:20,radius:"xl",children:i(L.IconCircleDashed,{size:14})}),"builtin:op:set_filter_values":i(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:i(L.IconCircleDot,{size:14})}),"builtin:op:clear_filter_values":i(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:i(L.IconCircleOff,{size:14})})};function IS(e){const t=[];return e.forEach(n=>{switch(n.schemaRef){case"builtin:op:open-link":t.push({key:n.urlTemplate,icon:$i[n.schemaRef],text:p(s.Group,{spacing:4,children:[i(s.Text,{children:"Open: "}),i(s.Text,{color:"dimmed",children:n.shortURLTemplate})]})});return;case"builtin:op:set_filter_values":n.filters.forEach(({key:r,label:a})=>{t.push({key:n.schemaRef+r,icon:$i[n.schemaRef],text:i(s.Group,{spacing:4,children:p(s.Text,{children:["Set Filter: ",a]})})})});return;case"builtin:op:clear_filter_values":n.filters.forEach(({key:r,label:a})=>{t.push({key:n.schemaRef+r,icon:$i[n.schemaRef],text:i(s.Group,{spacing:4,children:p(s.Text,{children:["Clear Filter: ",a]})})})});return}}),t}const ES=b.memo(({data:e,isConnectable:t,sourcePosition:n=ze.Position.Right,targetPosition:r=ze.Position.Left,...a})=>{const o=b.useMemo(()=>IS(e.interactions),[e.interactions]);return p(V,{children:[i(ze.Handle,{type:"target",position:r,isConnectable:t}),i(s.Box,{sx:{position:"absolute",top:0,right:0},children:i(T.ChevronsUpRight,{size:12})}),p(s.HoverCard,{shadow:"xl",withinPortal:!0,children:[i(s.HoverCard.Target,{children:i(s.Text,{children:e.label})}),i(s.HoverCard.Dropdown,{children:i(s.List,{spacing:"xs",size:"sm",center:!0,children:o.map(l=>i(s.List.Item,{icon:l.icon,children:l.text},l.key))})})]}),i(ze.Handle,{type:"source",position:n,isConnectable:t})]})}),tM="",AS={interaction:ES},zS=k.observer(()=>{const e=Me(),{edges:t,nodes:n}=MS(e);return p(ze,{nodes:n,edges:t,onNodesChange:x.noop,onEdgesChange:x.noop,onConnect:x.noop,className:"interactions-viewer",fitView:!0,nodeTypes:AS,children:[i(ze.MiniMap,{}),i(ze.Controls,{}),i(ze.Background,{})]})}),$S=k.observer(({opened:e,close:t})=>i(s.Modal,{size:"96vw",opened:e,onClose:t,title:"Interactions",trapFocus:!0,onDragStart:n=>{n.stopPropagation()},styles:{body:{height:"90vh"},content:{transform:"none !important"}},zIndex:300,children:i(zS,{})})),LS={"> button":{"&:first-of-type":{borderTopRightRadius:0,borderBottomRightRadius:0,borderRightWidth:.5},":not(:first-of-type):not(:last-of-type)":{borderTopRightRadius:0,borderBottomRightRadius:0,borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:.5,borderRightWidth:.5},"&:last-of-type":{borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:.5}}};function OS({onClick:e,name:t,active:n,openSettings:r}){return p(s.Box,{sx:{position:"relative"},children:[i(s.UnstyledButton,{sx:a=>({display:"block",width:"100%",padding:a.spacing.xs,borderRadius:0,position:"relative",color:a.black,"&:hover":{backgroundColor:a.colors.gray[0]},backgroundColor:n?a.colors.gray[2]:"transparent"}),children:i(s.Group,{sx:{width:"calc(100% - 28px)"},onClick:e,children:i(s.Text,{size:"sm",children:t})})}),n&&i(s.Tooltip,{label:"Edit",position:"right",withinPortal:!0,children:i(s.ActionIcon,{onClick:r,variant:"light",color:"blue",sx:{position:"absolute",top:0,bottom:0,height:"100%",right:0,zIndex:0,borderRadius:0},children:i(L.IconAdjustments,{size:16})})})]})}const PS=k.observer(()=>{const e=me(),t=ue(),n=b.useCallback(a=>()=>t.views.setIDOfVIE(a),[t]),r=a=>{e.editor.open(["_VIEWS_",a])};return p(s.Box,{sx:{position:"relative"},children:[t.views.options.map(a=>i(OS,{active:t.views.idOfVIE===a.value,name:a.label,onClick:n(a.value),openSettings:()=>r(a.value)},a.value)),i(s.Divider,{variant:"dashed"}),i(s.Button,{variant:"subtle",rightIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",color:"blue",onClick:t.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"space-between"}},children:"Add a View"})]})}),BS=k.observer(()=>{const e=me(),t=ue(),n=()=>{if(!t.queries.firstID){e.editor.open(["_QUERIES_",""]);return}e.editor.open(["_QUERIES_",t.queries.firstID])},r=()=>{if(!t.filters.firstID){e.editor.open(["_FILTERS_",""]);return}e.editor.open(["_FILTERS_",t.filters.firstID])},[a,o]=b.useState(!1),l=()=>o(!0),u=()=>o(!1);return p(s.Navbar,{p:0,width:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},zIndex:299,children:[p(s.Navbar.Section,{children:[p(s.Group,{grow:!0,spacing:0,sx:{...LS,button:{borderWidth:0,borderBottomWidth:1,borderColor:"#e9ecef"}},children:[i(s.Tooltip,{label:"Filters",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:r,children:i(L.IconFilter,{size:18})})}),i(s.Tooltip,{label:"Queries",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:n,children:i(L.IconDatabase,{size:18})})}),i(s.Tooltip,{label:"Interactions Viewer",withinPortal:!0,children:i(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:l,children:i(L.IconLink,{size:18})})})]}),i($S,{opened:a,close:u})]}),i(s.Navbar.Section,{py:5,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Views"})}),i(s.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:i(PS,{})}),i(s.Navbar.Section,{children:i(s.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:i(s.Button,{size:"xs",leftIcon:i(L.IconSettings,{size:20}),onClick:()=>e.editor.open([]),children:"Settings"})})})]})}),VS=k.observer(function({config:t}){return p(V,{children:[i(s.Checkbox,{checked:t.default_value,onChange:n=>t.setDefaultValue(n.currentTarget.checked),label:"Default Checked"}),i(si,{label:"Description",value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}})]})}),NS=[{label:"2022",value:"YYYY"},{label:"202201",value:"YYYYMM"},{label:"20220101",value:"YYYYMMDD"},{label:"2022-01",value:"YYYY-MM"},{label:"2022-01-01",value:"YYYY-MM-DD"}],qS=k.observer(function({config:t}){return p(V,{children:[p(s.Group,{children:[i(s.Checkbox,{checked:t.required,onChange:n=>t.setRequired(n.currentTarget.checked),label:"Required"}),i(s.Checkbox,{checked:t.clearable,onChange:n=>t.setClearable(n.currentTarget.checked),disabled:t.max_days>0,label:"Clearable"}),i(s.Checkbox,{checked:t.allowSingleDateInRange,onChange:n=>t.setAllowSingleDateInRange(n.currentTarget.checked),label:"Allow choosing 1 day"})]}),i(s.Select,{data:NS,label:"Display Format",value:t.inputFormat,onChange:t.setInputFormat}),i(Oo,{label:"Default Value",config:t,value:t.default_value,onChange:t.setDefaultValue}),i(s.NumberInput,{label:"Max Days",description:p(s.Group,{position:"apart",children:[i(s.Text,{children:"Set 0 to disable."}),p(s.Group,{spacing:4,children:[i(s.Text,{children:"This feature requires"}),i(s.Text,{color:"blue",children:"Clearable"}),i(s.Text,{children:"to be checked"})]})]}),min:0,value:t.max_days,onChange:t.setMaxDays,hideControls:!0})]})}),Li=k.observer(({value:e,onChange:t})=>{const n=ue(),r=b.useMemo(()=>n.queries.options,[n.queries.current]),a=r.length===0;return i(s.Select,{label:"Pick a query",data:r,value:e,onChange:t,allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:a,error:a?"You need to add a query in Data Settings":void 0})}),FS=`
482
482
  // row
483
483
  {
484
484
  label: string;
485
485
  value: string;
486
486
  description?: string; // optional
487
487
  }
488
- `,Tl=()=>{const[t,e]=y.useState(!1);return p(V,{children:[i(s.Button,{variant:"subtle",compact:!0,onClick:()=>e(n=>!n),children:t?"Close":"Click to see expected data structure"}),i(s.Collapse,{in:t,children:i(kt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:fS})})]})},gS=k.observer(function({config:e}){const n=()=>{e.addStaticOption({label:"",value:""})},r=e.static_options,a=[...r];return p(V,{children:[i(s.TextInput,{label:"Width",description:"At least 160px",value:e.min_width,onChange:o=>e.setMinWidth(o.currentTarget.value),placeholder:"default: 200px"}),i(s.Divider,{label:"Configure options",labelPosition:"center"}),p(s.Stack,{spacing:10,sx:{position:"relative",minHeight:"50px"},children:[e.usingQuery&&p(V,{children:[i(s.Overlay,{opacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),i(s.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:i(s.Text,{color:"white",size:16,children:"Using query"})})]}),r.length>0&&i(s.MultiSelect,{label:"Default Selection",data:a,value:[...e.default_value],onChange:e.setDefaultValue}),r.map((o,l)=>p(s.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[i(s.TextInput,{label:"Label",required:!0,value:e.static_options[l].label,onChange:u=>{e.static_options[l].setLabel(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.TextInput,{label:"Value",required:!0,value:e.static_options[l].value,onChange:u=>{e.static_options[l].setValue(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>e.removeStaticOption(l),sx:{position:"absolute",top:28,right:5},children:i(D.Trash,{size:16})})]},l)),i(s.Button,{mt:10,size:"xs",color:"blue",leftIcon:i(D.PlaylistAdd,{size:20}),onClick:n,sx:{width:"50%"},mx:"auto",children:"Add an Option"})]}),i(s.Divider,{label:"Or fetch options from database",labelPosition:"center"}),i(s.NumberInput,{value:e.default_selection_count,onChange:e.setDefaultSelectionCount,label:"Select first N options by default"}),i(Ai,{value:e.options_query_id,onChange:e.setOptionsQueryID}),i(Tl,{})]})}),mS=k.observer(function({config:e}){const n=()=>{e.addStaticOption({label:"",value:""})},r=e.static_options,a=[{label:"No default selection",value:""},...r];return p(V,{children:[i(s.Checkbox,{checked:e.required,onChange:o=>e.setRequired(o.currentTarget.checked),label:"Required"}),i(s.TextInput,{label:"Width",value:e.width,onChange:o=>e.setWidth(o.currentTarget.value),placeholder:"200px"}),i(s.Divider,{label:"Configure options",labelPosition:"center"}),p(s.Stack,{spacing:10,sx:{position:"relative",minHeight:"50px"},children:[e.usingQuery&&p(V,{children:[i(s.Overlay,{opacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),i(s.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:i(s.Text,{color:"white",size:16,children:"Using query"})})]}),r.length>0&&i(s.Select,{label:"Default Selection",data:a,value:e.default_value,onChange:e.setDefaultValue}),r.map((o,l)=>p(s.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[i(s.TextInput,{label:"Label",required:!0,value:e.static_options[l].label,onChange:u=>{e.static_options[l].setLabel(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.TextInput,{label:"Value",required:!0,value:e.static_options[l].value,onChange:u=>{e.static_options[l].setValue(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>e.removeStaticOption(l),sx:{position:"absolute",top:28,right:5},children:i(D.Trash,{size:16})})]},l)),i(s.Button,{size:"xs",color:"blue",leftIcon:i(D.PlaylistAdd,{size:20}),onClick:n,sx:{width:"50%"},mx:"auto",children:"Add an Option"})]}),i(s.Divider,{label:"Or fetch options from database",labelPosition:"center"}),i(s.Checkbox,{checked:e.default_selection_count===1,onChange:o=>e.setDefaultSelectionCount(o.currentTarget.checked?1:0),label:"Select the first option by default"}),i(Ai,{value:e.options_query_id,onChange:e.setOptionsQueryID}),i(Tl,{})]})}),yS=k.observer(function({config:e}){return p(V,{children:[i(s.TextInput,{label:"Default Value",value:e.default_value,onChange:n=>{e.setDefaultValue(n.currentTarget.value)}}),i(s.Checkbox,{checked:e.required,onChange:n=>e.setRequired(n.currentTarget.checked),label:"Required"})]})}),bS=`
488
+ `,Rl=()=>{const[e,t]=b.useState(!1);return p(V,{children:[i(s.Button,{variant:"subtle",compact:!0,onClick:()=>t(n=>!n),children:e?"Close":"Click to see expected data structure"}),i(s.Collapse,{in:e,children:i(Tt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:FS})})]})},GS=k.observer(function({config:t}){const n=()=>{t.addStaticOption({label:"",value:""})},r=t.static_options,a=[...r];return p(V,{children:[i(s.TextInput,{label:"Width",description:"At least 160px",value:t.min_width,onChange:o=>t.setMinWidth(o.currentTarget.value),placeholder:"default: 200px"}),i(s.Divider,{label:"Configure options",labelPosition:"center"}),p(s.Stack,{spacing:10,sx:{position:"relative",minHeight:"50px"},children:[t.usingQuery&&p(V,{children:[i(s.Overlay,{opacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),i(s.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:i(s.Text,{color:"white",size:16,children:"Using query"})})]}),r.length>0&&i(s.MultiSelect,{label:"Default Selection",data:a,value:[...t.default_value],onChange:t.setDefaultValue}),r.map((o,l)=>p(s.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[i(s.TextInput,{label:"Label",required:!0,value:t.static_options[l].label,onChange:u=>{t.static_options[l].setLabel(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.TextInput,{label:"Value",required:!0,value:t.static_options[l].value,onChange:u=>{t.static_options[l].setValue(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>t.removeStaticOption(l),sx:{position:"absolute",top:28,right:5},children:i(T.Trash,{size:16})})]},l)),i(s.Button,{mt:10,size:"xs",color:"blue",leftIcon:i(T.PlaylistAdd,{size:20}),onClick:n,sx:{width:"50%"},mx:"auto",children:"Add an Option"})]}),i(s.Divider,{label:"Or fetch options from database",labelPosition:"center"}),i(s.NumberInput,{value:t.default_selection_count,onChange:t.setDefaultSelectionCount,label:"Select first N options by default"}),i(Li,{value:t.options_query_id,onChange:t.setOptionsQueryID}),i(Rl,{})]})}),WS=k.observer(function({config:t}){const n=()=>{t.addStaticOption({label:"",value:""})},r=t.static_options,a=[{label:"No default selection",value:""},...r];return p(V,{children:[i(s.Checkbox,{checked:t.required,onChange:o=>t.setRequired(o.currentTarget.checked),label:"Required"}),i(s.TextInput,{label:"Width",value:t.width,onChange:o=>t.setWidth(o.currentTarget.value),placeholder:"200px"}),i(s.Divider,{label:"Configure options",labelPosition:"center"}),p(s.Stack,{spacing:10,sx:{position:"relative",minHeight:"50px"},children:[t.usingQuery&&p(V,{children:[i(s.Overlay,{opacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),i(s.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:i(s.Text,{color:"white",size:16,children:"Using query"})})]}),r.length>0&&i(s.Select,{label:"Default Selection",data:a,value:t.default_value,onChange:t.setDefaultValue}),r.map((o,l)=>p(s.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[i(s.TextInput,{label:"Label",required:!0,value:t.static_options[l].label,onChange:u=>{t.static_options[l].setLabel(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.TextInput,{label:"Value",required:!0,value:t.static_options[l].value,onChange:u=>{t.static_options[l].setValue(u.currentTarget.value)},sx:{flexGrow:1}}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>t.removeStaticOption(l),sx:{position:"absolute",top:28,right:5},children:i(T.Trash,{size:16})})]},l)),i(s.Button,{size:"xs",color:"blue",leftIcon:i(T.PlaylistAdd,{size:20}),onClick:n,sx:{width:"50%"},mx:"auto",children:"Add an Option"})]}),i(s.Divider,{label:"Or fetch options from database",labelPosition:"center"}),i(s.Checkbox,{checked:t.default_selection_count===1,onChange:o=>t.setDefaultSelectionCount(o.currentTarget.checked?1:0),label:"Select the first option by default"}),i(Li,{value:t.options_query_id,onChange:t.setOptionsQueryID}),i(Rl,{})]})}),RS=k.observer(function({config:t}){return p(V,{children:[i(s.TextInput,{label:"Default Value",value:t.default_value,onChange:n=>{t.setDefaultValue(n.currentTarget.value)}}),i(s.Checkbox,{checked:t.required,onChange:n=>t.setRequired(n.currentTarget.checked),label:"Required"})]})}),jS=`
489
489
  // row
490
490
  {
491
491
  label: string;
@@ -493,7 +493,7 @@ Check the top-level render call using <`+P+">.")}return z}}function Yl(S,z){{if(
493
493
  parent_value: string;
494
494
  description?: string;
495
495
  }
496
- `,vS=()=>{const[t,e]=y.useState(!1);return p(V,{children:[i(s.Button,{variant:"subtle",compact:!0,onClick:()=>e(n=>!n),children:t?"Close":"Click to see expected data structure"}),i(s.Collapse,{in:t,children:i(kt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:bS})})]})},xS=k.observer(function({config:e}){return p(V,{children:[i(s.TextInput,{label:"Min-width",value:e.min_width,onChange:n=>e.setMinWidth(n.currentTarget.value),placeholder:"200px"}),i(s.Divider,{label:"Fetch options from database",labelPosition:"center"}),i(s.NumberInput,{value:e.default_selection_count,onChange:e.setDefaultSelectionCount,label:"Select first N options by default"}),i(Ai,{value:e.options_query_id,onChange:e.setOptionsQueryID}),i(vS,{})]})}),wS=k.observer(function({filter:e}){const[n,r]=y.useState(e.plainDefaultValue);return y.useEffect(()=>{r(e.plainDefaultValue)},[e]),p(s.Box,{sx:{maxWidth:"480px"},children:[i(s.Text,{pb:"md",color:"gray",children:"Preview"}),i(dl,{filter:e,value:n,onChange:r}),i(s.Text,{pt:"lg",pb:"md",color:"gray",children:"Config"}),i(kt.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(e,null,4)})]})}),CS={select:mS,"multi-select":gS,"tree-select":xS,"text-input":yS,checkbox:dS,"date-range":hS},SS=[{label:"Select",value:"select"},{label:"Multi Select",value:"multi-select"},{label:"Tree Select",value:"tree-select"},{label:"Text Input",value:"text-input"},{label:"Checkbox",value:"checkbox"},{label:"Date Range",value:"date-range"}],_S=k.observer(function({filter:e}){const n=K(),r=y.useMemo(()=>CS[e.type],[e.type]);return p(s.Group,{grow:!0,spacing:20,align:"top",children:[p(s.Box,{sx:{maxWidth:"600px"},children:[i(s.Text,{pb:"md",color:"gray",children:"Edit"}),p(s.Stack,{children:[p(s.Group,{noWrap:!0,children:[i(s.NumberInput,{label:"Placement Order",required:!0,value:e.order,onChange:e.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),e.auto_submit_supported&&i(s.Checkbox,{label:"Submit automatically",checked:e.auto_submit,onChange:a=>e.setAutoSubmit(a.currentTarget.checked),mt:22})]}),i(s.MultiSelect,{label:"Visible in...",data:n.views.options,value:[...e.visibleInViewsIDs],onChange:e.setVisibleInViewsIDs}),i(s.TextInput,{label:"Key",placeholder:"A unique key to refer",required:!0,value:e.key,onChange:a=>{e.setKey(a.currentTarget.value)}}),i(s.TextInput,{label:"Label",placeholder:"Label for this field",required:!0,value:e.label,onChange:a=>{e.setLabel(a.currentTarget.value)}}),i(s.Select,{label:"Widget",data:SS,required:!0,value:e.type,onChange:e.setType}),i(r,{config:e.config})]})]}),i(wS,{filter:e})]})}),kS=k.observer(({id:t})=>{const e=Ue.useModals(),n=he(),r=K();if(t==="")return null;const a=r.filters.findByID(t);if(!a)return p(s.Text,{size:14,children:["Filter by ID[",t,"] is not found"]});const o=()=>{n.editor.setPath(["_FILTERS_",""])},l=()=>{e.openConfirmModal({title:"Delete this filter?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.filters.removeByID(t),o()},confirmProps:{color:"red"},zIndex:320})};return p(s.Stack,{sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",pb:30,children:[i(s.Group,{position:"right",pt:10,children:i(s.Button,{size:"xs",color:"red",leftIcon:i(D.Trash,{size:16}),onClick:l,children:"Delete this filter"})}),i(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:i(_S,{filter:a})})]})}),TS=k.observer(()=>{const t=K(),[e,n]=y.useState(()=>JSON.stringify(t.mock_context.current,null,4)),r=()=>{try{t.mock_context.replace(JSON.parse(e))}catch(o){hn.showNotification({title:"Failed",message:o.message,color:"red"})}},a=y.useMemo(()=>{try{return JSON.stringify(JSON.parse(e))!==JSON.stringify(t.mock_context.current)}catch{return!1}},[e,t.mock_context.current]);return p(s.Stack,{sx:{border:"1px solid #eee",borderLeft:"none",borderRight:"none",flexGrow:1,maxWidth:"unset"},children:[i(s.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:i(s.Text,{weight:500,children:"Mock Context"})}),p(s.Group,{grow:!0,px:"md",pb:"md",pt:0,sx:{flexGrow:1,position:"relative",alignItems:"flex-start"},children:[p(s.Stack,{spacing:10,sx:{maxWidth:"unset !important"},children:[i(s.Text,{children:"A valid json string is required"}),i(s.JsonInput,{validationError:"Invalid json",formatOnBlur:!0,autosize:!0,minRows:30,value:e,onChange:n,sx:{flexGrow:1}})]}),i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",sx:{position:"absolute",right:12,top:0},disabled:!a,onClick:r,children:i(D.DeviceFloppy,{size:20})})]})]})}),DS=k.observer(()=>{const{panel:t}=ze();return i(ii,{label:"Description",value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1}}})}),MS=k.observer(()=>{const{panel:t}=ze(),{style:e}=t;return i(V,{children:i(s.Switch,{label:"Border",checked:e.border.enabled,onChange:n=>e.border.setEnabled(n.currentTarget.checked)})})}),IS=k.observer(()=>{const{panel:t}=ze(),{title:e,setTitle:n}=t,[r,a]=Me.useInputState(e),o=e!==r,l=y.useCallback(()=>{o&&n(r)},[o,r]);return y.useEffect(()=>{a(e)},[e]),i(s.TextInput,{value:r,onChange:a,label:p(s.Group,{children:[i(s.Text,{children:"Panel Title"}),i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:!o,onClick:l,children:i(D.DeviceFloppy,{size:20})})]}),styles:{label:{display:"block",paddingBottom:"4px"}}})});function ES(){return p(s.Stack,{sx:{height:"100%"},children:[i(s.Divider,{label:"Style",labelPosition:"center",variant:"dashed"}),i(MS,{}),i(s.Divider,{label:"Info",labelPosition:"center",variant:"dashed"}),i(IS,{}),i(DS,{})]})}const AS=({queryID:t})=>{const e=K(),{state:n,error:r}=e.getDataStuffByID(t),a=y.useMemo(()=>e.queries.findByID(t),[e,t]);return n==="loading"?null:r?i(s.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:r}):a!=null&&a.stateMessage?i(s.Text,{color:"gray",align:"center",children:a.stateMessage}):null},zS={width:"fit-content",minWidth:"100%",tableLayout:"fixed",tr:{width:"fit-content"},th:{position:"relative"},"th, td":{wordBreak:"break-word"},".resizer":{position:"absolute",right:0,top:"50%",transform:"translateY(-50%)",cursor:"col-resize",userSelect:"none",touchAction:"none"},".resizer.isResizing":{color:"#228be6",opacity:"1"},"@media (hover: hover)":{".resizer":{opacity:"0"},"*:hover > .resizer":{color:"#228be6",opacity:"1"}}};function Dl({data:t}){const e=y.useMemo(()=>{if(!Array.isArray(t)||t.length===0)return[];const r=Xe.createColumnHelper();return Object.keys(t[0]).map(a=>r.accessor(a,{cell:o=>o.getValue()}))},[t]),n=Xe.useReactTable({data:t,columns:e,columnResizeMode:"onChange",getCoreRowModel:Xe.getCoreRowModel()});return t.length===0?i(s.Box,{sx:{height:"5em"}}):i(Fe,{children:p(s.Table,{sx:zS,children:[i("thead",{children:n.getHeaderGroups().map(r=>i("tr",{children:r.headers.map(a=>p("th",{style:{width:a.getSize()},children:[a.isPlaceholder?null:Xe.flexRender(a.column.columnDef.header,a.getContext()),i(s.ActionIcon,{onMouseDown:a.getResizeHandler(),onTouchStart:a.getResizeHandler(),className:`resizer ${a.column.getIsResizing()?"isResizing":""}`,children:i(D.ArrowBarToRight,{})})]},a.id))},r.id))}),i("tbody",{children:n.getRowModel().rows.map(r=>i("tr",{children:r.getVisibleCells().map(a=>i("td",{children:i(Fe,{children:Xe.flexRender(a.column.columnDef.cell,a.getContext())})},a.id))},r.id))})]})})}const zi=k.observer(function({id:e,moreActions:n=null}){const r=K(),{data:a,state:o}=r.getDataStuffByID(e),l=o==="loading",u=()=>{r.queries.refetchDataByQueryID(e)},c=()=>{r.queries.downloadDataByQueryID(e)},d=y.useMemo(()=>Array.isArray(a)?a.slice(0,10):[],[a]),f=!Array.isArray(a)||a.length===0;return p(s.Stack,{sx:{border:"1px solid #eee"},children:[p(s.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[p(s.Group,{position:"left",children:[i(s.Text,{weight:500,children:"Preview Data"}),a.length>10&&p(s.Text,{size:"sm",color:"gray",children:["Showing 10 rows of ",a.length]})]}),p(s.Group,{pr:15,children:[n,i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:l,onClick:u,children:i(D.Refresh,{size:16})}),i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:l||f,onClick:c,children:i(D.Download,{size:16})})]})]}),p(s.Box,{sx:{position:"relative",overflow:"auto"},children:[i(s.LoadingOverlay,{visible:l}),i(AS,{queryID:e}),i(Dl,{data:d})]})]})}),$S=k.observer(function(){const e=he(),n=K(),{panel:r}=ze(),[a,o]=y.useState(!1),l=u=>{e.editor.setPath(["_QUERIES_",u])};return p(V,{children:[i(s.Drawer,{opened:a,onClose:()=>o(!1),title:"Choose queries",padding:"xl",size:500,zIndex:320,children:i(s.Checkbox.Group,{value:[...r.queryIDs],onChange:r.setQueryIDs,children:i(s.Stack,{spacing:"lg",children:n.queries.options.map(u=>i(s.Checkbox,{label:u.label,value:u.value},u.value))})})}),p(s.Stack,{spacing:6,children:[i(s.Group,{position:"right",children:i(s.Button,{variant:"light",size:"sm",leftIcon:i(L.IconLine,{size:16}),onClick:()=>o(!0),children:"Click me to choose queries for this panel"})}),r.queryIDs.length===1&&i(zi,{id:r.queryIDs[0],moreActions:i(s.Tooltip,{label:"Open this query",children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(r.queryIDs[0]),children:i(L.IconArrowCurveRight,{size:16})})})}),r.queryIDs.length>1&&p(s.Tabs,{defaultValue:r.queryIDs[0],children:[i(s.Tabs.List,{children:r.queries.map(u=>i(s.Tabs.Tab,{value:u.id,children:u.name},u.id))}),r.queries.map(u=>i(s.Tabs.Panel,{value:u.id,children:i(zi,{id:u.id,moreActions:i(s.Tooltip,{label:"Open this query",children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(u.id),children:i(L.IconArrowCurveRight,{size:16})})})})},u.id))]})]})]})}),LS=k.observer(()=>{const{panel:t}=ze();return i(Fe,{children:i(s.Box,{sx:{height:"100%",flexGrow:0,flexShrink:0,width:"600px"},children:p(s.Stack,{mt:24,spacing:5,sx:{width:"600px",height:"450px",background:"transparent",borderRadius:"5px",border:"1px solid #e9ecef",borderWidth:t.style.border.enabled?"1px":"0px"},children:[p(s.Group,{position:"apart",noWrap:!0,sx:{flexGrow:0,flexShrink:0},children:[i(s.Group,{children:i(hl,{})}),i(s.Group,{grow:!0,position:"center",children:i(s.Text,{lineClamp:1,weight:"bold",children:t.title})}),i(s.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),i(s.Group,{px:5,pb:5,sx:{flexGrow:1},children:i(bl,{panel:t,height:"410px"})})]})})})}),$i={name:"new_var",size:"1rem",weight:"initial",color:{type:"static",staticColor:"Red"},data_field:"",aggregation:{type:"sum",config:{}},formatter:{output:"number",mantissa:0,trimMantissa:!1,average:!1}};class OS{constructor(e){N(this,"panel");N(this,"selected");this.panel=e,ie.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}addNew(){const e=this.panel.variables.filter(n=>n.name.startsWith($i.name)).length;this.panel.addVariable(x.cloneDeep({...$i,name:`${$i.name}${e||""}`})),this.selected=x.last(this.panel.variables)}select(e){this.selected=e}remove(e){this.selected===e&&(this.selected=void 0);const n=this.panel.variables.indexOf(e);if(this.panel.removeVariable(e),!this.selected&&!x.isEmpty(this.panel.variables)){const r=Math.min(this.panel.variables.length-1,n);this.selected=this.panel.variables[r]}}}function PS(){const{panel:t}=ze();return X.useCreation(()=>new OS(t),[t])}const Ml=s.createStyles(t=>({root:{height:"100%",overflow:"hidden",".var-list-container":{"& > *":{height:"100%"},width:250,height:"100%"},".var-list-actions":{height:"fit-content",flexShrink:0,width:"100%"},".var-list":{flex:"1 1 auto",overflow:"auto",minHeight:0,"& > *":{flex:"0 0 auto"}}},config:{height:"100%",overflow:"auto",paddingRight:10}})),BS=y.forwardRef(function({value:e,onChange:n,data:r,withStyle:a=!0},o){const l=(u,c)=>{const d=x.cloneDeep(e);x.set(d,u,c),n(d)};return p(s.Box,{px:"sm",py:"md",ref:o,children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(s.TextInput,{label:"Name",required:!0,value:e.name,onChange:u=>l("name",u.currentTarget.value)}),i(j,{label:"Data Field",required:!0,value:e.data_field,onChange:u=>l("data_field",u)})]}),i(Sn,{label:"Aggregation",value:e.aggregation,onChange:u=>l("aggregation",u)}),i(s.Divider,{my:"xs",label:"Format",labelPosition:"center"}),i(Re,{value:e.formatter,onChange:u=>l("formatter",u)}),a&&i(Ts,{value:e,onChange:n})]})}),VS=t=>{const{uiModel:e}=t;return i(s.Stack,{className:"var-list",children:e.variables.map(n=>i(s.Button,{variant:e.selected===n?"filled":"subtle",color:"gray",onClick:()=>e.select(n),children:n.name},n.name))})},NS=k.observer(VS),qS=({variable:t,data:e})=>i(s.Group,{style:{minHeight:0,height:"calc(100% - 68px)"},children:i(s.Paper,{withBorder:!0,p:"md",children:Ds(t,e)})}),FS=k.observer(qS),GS=t=>{const e=X.useCreation(()=>Uu(t.variable),[t.variable]),{classes:n}=Ml(),{data:r}=ze();return p(s.Group,{style:{height:"100%"},align:"start",children:[p(s.Stack,{"data-testid":"variable-editor",align:"stretch",className:n.config,children:[p(s.Group,{position:"right",children:[i(s.ActionIcon,{variant:"filled",disabled:!e.changed,color:"primary",onClick:e.commit,children:i(L.IconDeviceFloppy,{size:18})}),i(s.ActionIcon,{color:"red",onClick:()=>t.uiModel.remove(t.variable),children:i(L.IconTrash,{size:18})})]}),i(BS,{value:b.getSnapshot(e.copy),onChange:e.update,data:r})]}),i(FS,{variable:b.getSnapshot(e.copy),data:r})]})},WS=k.observer(GS),jS=()=>{const t=PS(),{classes:e}=Ml();return p(s.Group,{className:e.root,noWrap:!0,align:"start",children:[i(s.Paper,{withBorder:!0,p:"md",className:"var-list-container",children:p(s.Stack,{justify:"space-between",children:[i(s.Box,{className:"var-list-actions",children:i(s.Button,{variant:"light",size:"sm",onClick:t.addNew,fullWidth:!0,children:"Add Variable"})}),i(NS,{uiModel:t})]})}),t.selected?i(V,{children:i(WS,{uiModel:t,variable:t.selected})}):i("span",{children:"Select or create a new variable on right side"})]})},RS=k.observer(jS);function YS(){const{vizManager:t}=y.useContext(at);return y.useMemo(()=>{const e=t.availableVizList.map(n=>({value:n.name,label:n.displayName??n.name,group:n.displayGroup??""}));return x.orderBy(e,[n=>n.group,n=>n.label],["asc","asc"])},[t])}const QS=k.observer(({value:t,submit:e})=>{const[n,r]=Me.useInputState(t);y.useEffect(()=>{r(t)},[t]);const a=YS(),o=t!==n;return i(s.Select,{label:"Visualization",value:n,searchable:!0,onChange:r,data:a,rightSection:i(s.ActionIcon,{disabled:!o,onClick:()=>e(n),children:i(D.DeviceFloppy,{size:20})}),maxDropdownHeight:600})}),Il=[];function KS(t,e){try{return t.resolveComponent(e).createConfig()}catch{return null}}function US(){const{data:t,panel:{variables:e,viz:n,title:r,queryIDs:a,description:o,setDescription:l,setTitle:u,addQueryID:c,removeQueryID:d,id:f}}=ze(),{vizManager:h}=y.useContext(at),g={title:r,description:o,viz:n,queryIDs:a,id:f},m={setDescription:l,addQueryID:c,removeQueryID:d,setTitle:u},w=gl(g);try{return h.resolveComponent(g.viz.type),i(Hn,{configure:w,children:i(r1,{variables:e,setVizConf:n.setConf,panel:g,panelInfoEditor:m,vizManager:h,data:t})})}catch(C){return console.info(x.get(C,"message")),null}}const XS=k.observer(()=>{const{data:t,panel:{viz:e}}=ze(),{vizManager:n}=y.useContext(at),r=y.useCallback(d=>{if(d===e.type)return;const f=KS(n,d);e.setType(d),e.setConf(f||{})},[e.type]),a=d=>{try{e.setConf(JSON.parse(d))}catch(f){console.error(f)}},o=y.useMemo(()=>{var d;return(d=Il.find(f=>f.value===e.type))==null?void 0:d.Panel},[e.type,Il]),l=US(),u=o?y.createElement(o,{data:t,conf:e.conf,setConf:e.setConf}):null,c=l||u;return p(s.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[i(QS,{submit:r,value:e.type}),p(Fe,{children:[i(s.Stack,{pb:10,sx:{flexGrow:1,maxHeight:"100%",overflow:"auto"},children:c}),!c&&i(s.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(e.conf,null,2),onChange:a})]})]})}),JS=k.observer(({panel:t,sourceViewID:e})=>{const n=K(),[r,a]=y.useState(e);y.useEffect(()=>{a(e)},[e]);const[o,{open:l,close:u}]=Me.useDisclosure(!1),c=()=>{t.moveToView(e,r),u()};return p(V,{children:[i(s.Button,{size:"xs",variant:"subtle",color:"blue",onClick:l,leftIcon:i(L.IconBoxMultiple,{size:14}),children:"Move into Another View"}),i(s.Modal,{opened:o,onClose:u,title:"Move panel into another view",zIndex:320,children:p(s.Stack,{sx:{maxHeight:"calc(100vh - 185px)",overflow:"hidden"},children:[i(s.Radio.Group,{value:r,onChange:a,pb:10,sx:{flexGrow:1,maxHeight:"calc(100vh - 185px - 30px)",overflow:"auto"},children:i(s.Stack,{spacing:"xs",children:n.views.options.map(d=>i(s.Radio,{value:d.value,label:d.label},d.value))})}),p(s.Group,{noWrap:!0,position:"apart",sx:{flexGrow:0,flexShrink:0},children:[i(s.Button,{size:"xs",color:"red",leftIcon:i(L.IconX,{size:14}),onClick:u,children:"Cancel"}),i(s.Button,{size:"xs",color:"blue",leftIcon:i(L.IconDeviceFloppy,{size:14}),onClick:c,disabled:r===e,children:"Confirm"})]})]})})]})}),ZS={root:{flexGrow:1,width:"100%",overflow:"hidden"},panel:{width:"100%",height:"calc(100% - 44px)",padding:10,overflow:"scroll"}},El=({children:t})=>p(s.Group,{noWrap:!0,grow:!0,position:"left",spacing:20,sx:{width:"100%",height:"100%"},children:[i(s.Box,{sx:{maxWidth:"calc(100% - 610px - 10px)",height:"100%",overflow:"auto"},children:t}),i(LS,{})]});function HS(t){return!["richText","button"].includes(t)}const e_=k.observer(({panel:t})=>{const e=Ue.useModals(),n=he(),r=K(),[a,o]=y.useState("Data"),l=t.queries,c=HS(t.viz.type)&&t.dataLoading,d=c||t.queryErrors.length>0||t.queryStateMessages.length>0||l.length===0,f=n.editor.path[1];y.useEffect(()=>{o(m=>d&&m==="Visualization"?"Data":m)},[t.id,d]);const h=()=>{n.editor.setPath(["_VIEWS_",f])},g=()=>e.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.removePanelByID(t.id,f),h()},confirmProps:{color:"red"},zIndex:320});return p(Cr,{value:{panel:t,data:t.data,loading:c,errors:t.queryErrors},children:[p(s.Group,{px:16,position:"apart",sx:{borderBottom:"1px solid #eee"},children:[p(s.Text,{pt:9,pb:8,children:[t.title?t.title:t.viz.type," "]}),p(s.Group,{position:"right",noWrap:!0,children:[i(JS,{panel:t,sourceViewID:f}),i(s.Button,{size:"xs",variant:"subtle",color:"red",onClick:g,leftIcon:i(L.IconTrash,{size:14}),children:"Delete This Panel"})]})]}),p(s.Tabs,{value:a,onTabChange:o,keepMounted:!1,styles:ZS,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Data",disabled:c,children:"Data"}),i(s.Tabs.Tab,{value:"Panel",children:"Panel"}),i(s.Tabs.Tab,{value:"Variables",disabled:d,children:i(s.Tooltip,{label:"Requires data",disabled:!d,withinPortal:!0,zIndex:310,children:i(s.Text,{children:"Variables"})})}),i(s.Tabs.Tab,{value:"Visualization",disabled:d,children:i(s.Tooltip,{label:"Requires data",disabled:!d,withinPortal:!0,zIndex:310,children:i(s.Text,{children:"Visualization"})})}),i(s.Tabs.Tab,{value:"Interactions",children:"Interactions"})]}),p(s.Tabs.Panel,{value:"Data",children:[i(s.LoadingOverlay,{visible:c,exitTransitionDuration:0}),i($S,{})]}),i(s.Tabs.Panel,{value:"Panel",children:i(El,{children:i(ES,{})})}),i(s.Tabs.Panel,{value:"Variables",children:i(RS,{})}),i(s.Tabs.Panel,{value:"Visualization",children:i(Fe,{children:i(El,{children:i(XS,{})})})}),i(s.Tabs.Panel,{value:"Interactions",children:i(Fe,{children:i(Nc,{})})})]})]})}),t_=k.observer(({viewID:t,panelID:e})=>{const n=K();if(!n.views.findByID(t))return p(s.Text,{size:14,children:["View by ID[",t,"] is not found"]});const a=n.panels.findByID(e);return a?i(e_,{panel:a}):p(s.Text,{size:14,children:["Panel by ID[",e,"] is not found"]})}),Al=({width:t="calc(100% - 32px)",lastWidth:e="50%",height:n,count:r,spacing:a=16,pl:o=0})=>p(s.Stack,{spacing:a,mt:6,pl:o,children:[Array.from(new Array(r-1),(l,u)=>i(s.Skeleton,{width:t,height:n,radius:"xs"},u)),i(s.Skeleton,{width:e,height:n,radius:"xs"})]}),on=({value:t})=>t===null||t===""?null:i(s.Tooltip,{label:t,disabled:!t,multiline:!0,children:i(s.ActionIcon,{children:i(L.IconInfoCircle,{size:14})})}),n_=({column:t})=>{const{column_key:e,column_key_text:n}=t;return e?i(s.Tooltip,{label:n,disabled:!n,children:i(s.Badge,{children:e})}):null},r_=k.observer(({dataSource:t})=>{const{columns:e}=t;return e.loading?i(Al,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):e.empty?null:p(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"1000px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[i("col",{style:{width:50}}),i("col",{style:{minWidth:300}}),i("col",{style:{width:30}}),i("col",{style:{width:70}}),i("col",{style:{minWidth:300}}),i("col",{style:{minWidth:80,width:80}}),i("col",{style:{minWidth:120,width:120}})]}),i("thead",{children:p("tr",{children:[i("th",{children:"#"}),i("th",{children:"Column Name"}),i("th",{}),i("th",{}),i("th",{children:"Type"}),i("th",{children:"Nullable"}),i("th",{children:"Default Value"})]})}),i("tbody",{children:e.data.map(n=>p("tr",{children:[i("td",{children:n.ordinal_position}),i("td",{children:n.column_name}),i("td",{children:i(on,{value:n.column_comment})}),i("td",{children:i(n_,{column:n})}),i("td",{children:n.column_type}),i("td",{children:n.is_nullable}),i("td",{children:i(on,{value:n.column_default})})]},n.column_name))})]})}),i_=k.observer(({dataSource:t})=>{const{indexes:e}=t,n=e.data;return p(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"950px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[i("col",{style:{width:100}}),i("col",{style:{minWidth:300}}),i("col",{style:{width:150}}),i("col",{style:{width:150}}),i("col",{style:{width:250}})]}),i("thead",{children:p("tr",{children:[i("th",{children:"Index Length"}),i("th",{children:"Index Name"}),i("th",{children:"Index Algorithm"}),i("th",{children:"Unique"}),i("th",{children:"Column Name"})]})}),i("tbody",{children:n.map(r=>p("tr",{children:[i("td",{children:r.index_length}),i("td",{children:r.index_name}),i("td",{children:r.index_algorithm}),i("td",{children:r.is_unique?"YES":"NO"}),i("td",{children:r.column_name})]},r.index_name))})]})}),a_=k.observer(({dataSource:t})=>{const{indexes:e}=t,n=e.data;return p(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"850px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[i("col",{style:{minWidth:300}}),i("col",{style:{width:150}}),i("col",{style:{width:100}}),i("col",{style:{width:100}}),i("col",{style:{width:100}}),i("col",{style:{width:100}})]}),i("thead",{children:p("tr",{children:[i("th",{children:"Index Name"}),i("th",{children:"Index Algorithm"}),i("th",{children:"Unique"}),i("th",{children:"Definition"}),i("th",{children:"Condition"}),i("th",{children:"Comment"})]})}),i("tbody",{children:n.map(r=>p("tr",{children:[i("td",{children:r.index_name}),i("td",{children:r.index_algorithm}),i("td",{children:r.is_unique?"YES":"NO"}),i("td",{children:i(on,{value:r.index_definition})}),i("td",{children:i(on,{value:r.condition})}),i("td",{children:i(on,{value:r.comment})})]},r.index_name))})]})}),s_=k.observer(({dataSource:t})=>{const{indexes:e}=t;return e.loading||e.empty?null:t.type===ye.MySQL?i(i_,{dataSource:t}):t.type===ye.Postgresql?i(a_,{dataSource:t}):null}),o_=k.observer(({dataSource:t})=>p(s.Stack,{spacing:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[i(Fe,{children:i(r_,{dataSource:t})}),i(Fe,{children:i(s_,{dataSource:t})})]}));function l_({table_type:t}){return t==="VIEW"?i(L.IconEye,{size:14}):t==="BASE TABLE"?i(L.IconTable,{size:14}):null}const u_=k.observer(({dataSource:t})=>{const{tables:e}=t;return e.loading?i(Al,{height:"24px",lastWidth:"50%",count:15}):i(s.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(e.data).map(([n,r])=>i(s.NavLink,{label:n,icon:i(L.IconDatabase,{size:14}),defaultOpened:t.table_schema===n,pl:0,childrenOffset:14,children:r.map(a=>i(s.NavLink,{label:a.table_name,icon:i(l_,{table_type:a.table_type}),onClick:()=>{t.setKeywords(n,a.table_name)},active:t.table_name===a.table_name},a.table_name))},n))})}),c_=({visible:t})=>i(s.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:i(s.LoadingOverlay,{visible:t})}),d_=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],p_={icon:{width:"50px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"50px"}}},h_=k.observer(({dataSource:t})=>{const{tableData:e}=t;return p(s.Group,{pt:10,px:10,position:"apart",children:[p(s.Group,{position:"left",children:[e.maxPage>1&&i(s.Pagination,{size:"sm",value:e.page,onChange:e.setPage,total:e.maxPage,withEdges:e.maxPage>7,styles:{control:{height:"30px"}}}),i(s.Select,{icon:i(s.Text,{ta:"center",color:"dimmed",size:14,children:"Limit"}),size:"xs",styles:p_,data:d_,value:String(e.limit),onChange:n=>e.setLimit(Number(n))})]}),i(s.Group,{position:"right",children:p(s.Text,{color:"dimmed",my:0,size:14,children:["Total ",e.total," rows"]})})]})}),f_=k.observer(({dataSource:t})=>{const e=t.tableData;return e.maxPage===0?i(s.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:"This table is empty"}):e.error?i(s.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e.error}):e.page===1&&e.loading?i(c_,{visible:!0}):p(Fe,{children:[i(h_,{dataSource:t}),p(s.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[i(s.LoadingOverlay,{visible:e.loading,overlayBlur:2}),i(Dl,{data:e.data})]})]})}),g_={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},m_=k.observer(({dataSource:t})=>(y.useEffect(()=>{t.loadTablesIfEmpty()},[t]),t.tables.error?i(s.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:t.tables.error}):p(s.Flex,{sx:{height:"100%"},children:[i(s.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:i(Fe,{children:i(u_,{dataSource:t})})}),p(s.Tabs,{defaultValue:"structure",styles:g_,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"structure",icon:i(L.IconColumns,{size:14}),children:"Structure"}),i(s.Tabs.Tab,{value:"data",icon:i(L.IconDatabase,{size:14}),children:"Data"})]}),i(s.Tabs.Panel,{value:"structure",children:i(o_,{dataSource:t})}),i(s.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:i(f_,{dataSource:t})})]})]}))),y_={modal:{paddingLeft:"0px !important",paddingRight:"0px !important"},header:{marginBottom:0,padding:"20px 20px 10px",borderBottom:"1px solid #efefef",gap:"20px"},title:{flexGrow:1},body:{padding:"0 0 0 20px"}},zl=k.observer(({dataSource:t,triggerButtonProps:e={}})=>{const[n,r]=y.useState(!1);return t.type==="http"?null:p(V,{children:[i(s.Modal,{opened:n,onClose:()=>r(!1),title:p(s.Group,{position:"apart",sx:{flexGrow:1},children:[i(s.Text,{fw:500,children:"Explorer Data Source"}),p(s.Group,{spacing:7,children:[i(s.Badge,{variant:"gradient",gradient:{from:"indigo",to:"cyan"},children:t.key}),i(s.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:t.type})]})]}),zIndex:320,size:"96vw",styles:y_,children:i(s.Box,{sx:{height:"calc(100vh - 220px)"},children:i(m_,{dataSource:t})})}),i(s.Button,{variant:"subtle",onClick:()=>r(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...e,children:"See Table Structure"})]})}),b_=y.forwardRef(({label:t,type:e,...n},r)=>p(s.Group,{position:"apart",ref:r,...n,children:[i(s.Text,{children:t}),i(s.Text,{children:e})]})),v_=k.observer(({value:t,onChange:e})=>{const n=he(),{data:r=[],loading:a}=X.useRequest(fr,{refreshDeps:[]},[]),o=y.useMemo(()=>r.map(d=>({label:d.key,value:d.key,type:d.type})),[r]),l=y.useMemo(()=>o.reduce((d,f)=>(d[f.value]=f.type,d),{}),[o]),u=d=>{d!==null&&e({key:d,type:l[d]})},c=y.useMemo(()=>n.datasources.find(t),[n,t]);return i(s.Select,{data:o,label:p(s.Group,{position:"apart",children:[i(s.Box,{children:"Data Source"}),c&&i(zl,{dataSource:c,triggerButtonProps:{compact:!0,size:"xs",px:10}})]}),itemComponent:b_,rightSection:c?i(s.Text,{size:"xs",color:"dimmed",children:c.type}):void 0,rightSectionWidth:85,maxDropdownHeight:280,styles:{root:{flex:1},label:{display:"block"},rightSection:{pointerEvents:"none",justifyContent:"flex-end",paddingRight:"10px",".mantine-Text-root":{userSelect:"none"}}},disabled:a,value:t.key,onChange:u})}),x_=t=>{const{queryModel:e}=t,n=he(),r=K(),o=r.findQueryUsage(e.id).length>0,l=Ue.useModals(),u=()=>{l.openConfirmModal({title:"Delete this query?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.queries.removeQuery(e.id),n.editor.setPath(["_QUERIES_",""])},confirmProps:{color:"red"},zIndex:320})};return o?i(s.Tooltip,{label:"Can't delete this query for it's being used, check out Usage tab for details",withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,children:i(s.Button,{color:"gray",size:"xs",leftIcon:i(L.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})}):i(s.Button,{color:"red",size:"xs",onClick:u,leftIcon:i(L.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})},w_=k.observer(x_),C_=k.observer(({queryModel:t})=>{const[e,n]=y.useState(t.name);return y.useEffect(()=>{n(t.name)},[t.name]),i(s.Center,{ml:20,mt:20,sx:{maxWidth:"600px"},children:p(s.Stack,{spacing:10,sx:{width:"100%"},children:[i(s.Divider,{mb:-10,variant:"dashed",label:"Basics",labelPosition:"center"}),i(s.TextInput,{placeholder:"A unique name",label:"Name",required:!0,sx:{flex:1},value:e,onChange:r=>{n(r.currentTarget.value)},rightSection:i(s.ActionIcon,{variant:"filled",color:"blue",size:"sm",onClick:()=>t.setName(e),disabled:e===t.name,children:i(L.IconDeviceFloppy,{size:16})}),onBlur:()=>{t.setName(e)}}),i(v_,{value:{type:t.type,key:t.key},onChange:({type:r,key:a})=>{t.setKey(a),t.setType(r)}}),i(s.Divider,{mt:10,mb:-10,variant:"dashed",label:"Conditions",labelPosition:"center"}),i(s.MultiSelect,{label:"Run query when these are truthy",placeholder:"Always run this query on load",data:t.conditionOptions,value:[...t.run_by],onChange:t.setRunBy}),t.typedAsHTTP&&i(s.MultiSelect,{label:"Re-run query when these changed",placeholder:"Leave it empty to never re-run this query",data:t.conditionOptions,value:[...t.react_to],onChange:t.setReactTo}),i(s.Divider,{mt:20,mb:10,variant:"dashed"}),i(w_,{queryModel:t})]})})});function S_(){const[t,{open:e,close:n}]=Me.useDisclosure(!1);return p(V,{children:[i(s.Modal,{opened:t,onClose:n,title:"About FunctionUtils",zIndex:320,children:i(Kn,{value:du,styles:{root:{border:"none"},content:{padding:0,table:{marginBottom:0}}}})}),i(s.Button,{variant:"light",color:"violet",size:"xs",onClick:e,leftIcon:i(L.IconInfoCircle,{size:16}),children:"About parameter 'utils'"})]})}const __=({value:t,onChange:e})=>{const n=r=>{r&&e(r)};return i(s.Box,{sx:{position:"relative",flexGrow:1},children:i(Ie,{className:"function-editor",height:"100%",defaultLanguage:"javascript",value:t,onChange:n,theme:"vs-dark",options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1}}})})},ar=y.forwardRef(({value:t,onChange:e,label:n,defaultValue:r},a)=>{const[o,l]=y.useState(t),u=()=>{e(o)},c=()=>{l(t)},d=()=>{l(r)};y.useEffect(()=>{l(t)},[t]);const f=o!==t;return p(s.Stack,{spacing:4,sx:{height:"100%"},children:[p(s.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[i(s.Group,{position:"left",children:i(S_,{})}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,size:"xs",variant:"default",leftIcon:i(L.IconPlayerSkipBack,{size:16}),children:"Reset to default"}),i(s.Button,{onClick:c,color:"red",size:"xs",disabled:!f,leftIcon:i(L.IconRecycle,{size:16}),children:"Revert Changes"}),i(s.Button,{size:"xs",onClick:u,disabled:!f,leftIcon:i(L.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),i(s.Text,{size:14,children:n}),i(__,{value:o,onChange:l})]})});function k_({content:t}){return p(s.HoverCard,{width:"60vw",shadow:"md",children:[i(s.HoverCard.Target,{children:i(s.ActionIcon,{size:16,color:"blue",children:i(L.IconEye,{})})}),i(s.HoverCard.Dropdown,{children:i(kt.Prism,{language:"sql",noCopy:!0,withLineNumbers:!0,children:t})})]})}const T_=k.observer(()=>{const e=[...he().globalSQLSnippets.list];return e.length===0?null:p(s.Table,{horizontalSpacing:"xs",verticalSpacing:"xs",fontSize:"sm",highlightOnHover:!0,children:[i("thead",{children:p("tr",{children:[i("th",{children:"Key"}),i("th",{children:"Value"})]})}),i("tbody",{children:e.map(n=>{const{id:r,content:a}=n;return p("tr",{children:[i("td",{children:r}),i("td",{width:200,children:i(k_,{content:a})})]},r)})})]})}),D_=`
496
+ `,YS=()=>{const[e,t]=b.useState(!1);return p(V,{children:[i(s.Button,{variant:"subtle",compact:!0,onClick:()=>t(n=>!n),children:e?"Close":"Click to see expected data structure"}),i(s.Collapse,{in:e,children:i(Tt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:jS})})]})},QS=k.observer(function({config:t}){return p(V,{children:[i(s.TextInput,{label:"Min-width",value:t.min_width,onChange:n=>t.setMinWidth(n.currentTarget.value),placeholder:"200px"}),i(s.Divider,{label:"Fetch options from database",labelPosition:"center"}),i(s.NumberInput,{value:t.default_selection_count,onChange:t.setDefaultSelectionCount,label:"Select first N options by default"}),i(Li,{value:t.options_query_id,onChange:t.setOptionsQueryID}),i(YS,{})]})}),KS=k.observer(function({filter:t}){const[n,r]=b.useState(t.plainDefaultValue);return b.useEffect(()=>{r(t.plainDefaultValue)},[t]),p(s.Box,{sx:{maxWidth:"480px"},children:[i(s.Text,{pb:"md",color:"gray",children:"Preview"}),i(Bo,{filter:t,value:n,onChange:r}),i(s.Text,{pt:"lg",pb:"md",color:"gray",children:"Config"}),i(Tt.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(t,null,4)})]})}),US={select:WS,"multi-select":GS,"tree-select":QS,"text-input":RS,checkbox:VS,"date-range":qS},XS=[{label:"Select",value:"select"},{label:"Multi Select",value:"multi-select"},{label:"Tree Select",value:"tree-select"},{label:"Text Input",value:"text-input"},{label:"Checkbox",value:"checkbox"},{label:"Date Range",value:"date-range"}],JS=k.observer(function({filter:t}){const n=ue(),r=b.useMemo(()=>US[t.type],[t.type]);return p(s.Group,{grow:!0,spacing:20,align:"top",children:[p(s.Box,{sx:{maxWidth:"600px"},children:[i(s.Text,{pb:"md",color:"gray",children:"Edit"}),p(s.Stack,{children:[p(s.Group,{noWrap:!0,children:[i(s.NumberInput,{label:"Placement Order",required:!0,value:t.order,onChange:t.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),t.auto_submit_supported&&i(s.Checkbox,{label:"Submit automatically",checked:t.auto_submit,onChange:a=>t.setAutoSubmit(a.currentTarget.checked),mt:22})]}),i(s.MultiSelect,{label:"Visible in...",data:n.views.options,value:[...t.visibleInViewsIDs],onChange:t.setVisibleInViewsIDs}),i(s.TextInput,{label:"Key",placeholder:"A unique key to refer",required:!0,value:t.key,onChange:a=>{t.setKey(a.currentTarget.value)}}),i(s.TextInput,{label:"Label",placeholder:"Label for this field",required:!0,value:t.label,onChange:a=>{t.setLabel(a.currentTarget.value)}}),i(s.Select,{label:"Widget",data:XS,required:!0,value:t.type,onChange:t.setType}),i(r,{config:t.config})]})]}),i(KS,{filter:t})]})}),ZS=k.observer(({id:e})=>{const t=Ue.useModals(),n=me(),r=ue();if(e==="")return null;const a=r.filters.findByID(e);if(!a)return p(s.Text,{size:14,children:["Filter by ID[",e,"] is not found"]});const o=()=>{n.editor.setPath(["_FILTERS_",""])},l=()=>{t.openConfirmModal({title:"Delete this filter?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.filters.removeByID(e),o()},confirmProps:{color:"red"},zIndex:320})};return p(s.Stack,{sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",pb:30,children:[i(s.Group,{position:"right",pt:10,children:i(s.Button,{size:"xs",color:"red",leftIcon:i(T.Trash,{size:16}),onClick:l,children:"Delete this filter"})}),i(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:i(JS,{filter:a})})]})}),HS=k.observer(()=>{const e=ue(),[t,n]=b.useState(()=>JSON.stringify(e.mock_context.current,null,4)),r=()=>{try{e.mock_context.replace(JSON.parse(t))}catch(o){fn.showNotification({title:"Failed",message:o.message,color:"red"})}},a=b.useMemo(()=>{try{return JSON.stringify(JSON.parse(t))!==JSON.stringify(e.mock_context.current)}catch{return!1}},[t,e.mock_context.current]);return p(s.Stack,{sx:{border:"1px solid #eee",borderLeft:"none",borderRight:"none",flexGrow:1,maxWidth:"unset"},children:[i(s.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:i(s.Text,{weight:500,children:"Mock Context"})}),p(s.Group,{grow:!0,px:"md",pb:"md",pt:0,sx:{flexGrow:1,position:"relative",alignItems:"flex-start"},children:[p(s.Stack,{spacing:10,sx:{maxWidth:"unset !important"},children:[i(s.Text,{children:"A valid json string is required"}),i(s.JsonInput,{validationError:"Invalid json",formatOnBlur:!0,autosize:!0,minRows:30,value:t,onChange:n,sx:{flexGrow:1}})]}),i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",sx:{position:"absolute",right:12,top:0},disabled:!a,onClick:r,children:i(T.DeviceFloppy,{size:20})})]})]})}),e_=k.observer(()=>{const{panel:e}=Je();return i(si,{label:"Description",value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1}}})}),t_=k.observer(()=>{const{panel:e}=Je(),{style:t}=e;return i(V,{children:i(s.Switch,{label:"Border",checked:t.border.enabled,onChange:n=>t.border.setEnabled(n.currentTarget.checked)})})}),n_=k.observer(()=>{const{panel:e}=Je(),{title:t,setTitle:n}=e,[r,a]=Ee.useInputState(t),o=t!==r,l=b.useCallback(()=>{o&&n(r)},[o,r]);return b.useEffect(()=>{a(t)},[t]),i(s.TextInput,{value:r,onChange:a,label:p(s.Group,{children:[i(s.Text,{children:"Panel Title"}),i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:!o,onClick:l,children:i(T.DeviceFloppy,{size:20})})]}),styles:{label:{display:"block",paddingBottom:"4px"}}})});function r_(){return p(s.Stack,{sx:{height:"100%"},children:[i(s.Divider,{label:"Style",labelPosition:"center",variant:"dashed"}),i(t_,{}),i(s.Divider,{label:"Info",labelPosition:"center",variant:"dashed"}),i(n_,{}),i(e_,{})]})}const i_={width:"fit-content",minWidth:"100%",tableLayout:"fixed",tr:{width:"fit-content"},th:{position:"relative"},"th, td":{wordBreak:"break-word"},".resizer":{position:"absolute",right:0,top:"50%",transform:"translateY(-50%)",cursor:"col-resize",userSelect:"none",touchAction:"none"},".resizer.isResizing":{color:"#228be6",opacity:"1"},"@media (hover: hover)":{".resizer":{opacity:"0"},"*:hover > .resizer":{color:"#228be6",opacity:"1"}}};function jl({data:e}){const t=b.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const r=Xe.createColumnHelper();return Object.keys(e[0]).map(a=>r.accessor(a,{cell:o=>o.getValue()}))},[e]),n=Xe.useReactTable({data:e,columns:t,columnResizeMode:"onChange",getCoreRowModel:Xe.getCoreRowModel()});return e.length===0?i(s.Box,{sx:{height:"5em"}}):i(Fe,{children:p(s.Table,{sx:i_,children:[i("thead",{children:n.getHeaderGroups().map(r=>i("tr",{children:r.headers.map(a=>p("th",{style:{width:a.getSize()},children:[a.isPlaceholder?null:Xe.flexRender(a.column.columnDef.header,a.getContext()),i(s.ActionIcon,{onMouseDown:a.getResizeHandler(),onTouchStart:a.getResizeHandler(),className:`resizer ${a.column.getIsResizing()?"isResizing":""}`,children:i(T.ArrowBarToRight,{})})]},a.id))},r.id))}),i("tbody",{children:n.getRowModel().rows.map(r=>i("tr",{children:r.getVisibleCells().map(a=>i("td",{children:i(Fe,{children:Xe.flexRender(a.column.columnDef.cell,a.getContext())})},a.id))},r.id))})]})})}const a_=({queryID:e})=>{const t=Me(),{state:n,error:r}=t.getDataStuffByID(e),a=b.useMemo(()=>t.queries.findByID(e),[t,e]);return n==="loading"?null:r?i(s.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:r}):a!=null&&a.stateMessage?i(s.Text,{color:"gray",align:"center",children:a.stateMessage}):null},Oi=k.observer(function({id:t,moreActions:n=null}){const r=Me(),{data:a,state:o}=r.getDataStuffByID(t),l=o==="loading",u=()=>{r.queries.refetchDataByQueryID(t)},c=()=>{r.queries.downloadDataByQueryID(t)},d=b.useMemo(()=>Array.isArray(a)?a.slice(0,10):[],[a]),f=!Array.isArray(a)||a.length===0;return p(s.Stack,{sx:{border:"1px solid #eee"},children:[p(s.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[p(s.Group,{position:"left",children:[i(s.Text,{weight:500,children:"Preview Data"}),a.length>10&&p(s.Text,{size:"sm",color:"gray",children:["Showing 10 rows of ",a.length]})]}),p(s.Group,{pr:15,children:[n,i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:l,onClick:u,children:i(T.Refresh,{size:16})}),i(s.ActionIcon,{variant:"subtle",color:"blue",disabled:l||f,onClick:c,children:i(T.Download,{size:16})})]})]}),p(s.Box,{sx:{position:"relative",overflow:"auto"},children:[i(s.LoadingOverlay,{visible:l}),i(a_,{queryID:t}),i(jl,{data:d})]})]})}),s_=k.observer(function(){const t=me(),n=ue(),{panel:r}=Je(),[a,o]=b.useState(!1),l=u=>{t.editor.setPath(["_QUERIES_",u])};return p(V,{children:[i(s.Drawer,{opened:a,onClose:()=>o(!1),title:"Choose queries",padding:"xl",size:500,zIndex:320,children:i(s.Checkbox.Group,{value:[...r.queryIDs],onChange:r.setQueryIDs,children:i(s.Stack,{spacing:"lg",children:n.queries.options.map(u=>i(s.Checkbox,{label:u.label,value:u.value},u.value))})})}),p(s.Stack,{spacing:6,children:[i(s.Group,{position:"right",children:i(s.Button,{variant:"light",size:"sm",leftIcon:i(L.IconLine,{size:16}),onClick:()=>o(!0),children:"Click me to choose queries for this panel"})}),r.queryIDs.length===1&&i(Oi,{id:r.queryIDs[0],moreActions:i(s.Tooltip,{label:"Open this query",children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(r.queryIDs[0]),children:i(L.IconArrowCurveRight,{size:16})})})}),r.queryIDs.length>1&&p(s.Tabs,{defaultValue:r.queryIDs[0],children:[i(s.Tabs.List,{children:r.queries.map(u=>i(s.Tabs.Tab,{value:u.id,children:u.name},u.id))}),r.queries.map(u=>i(s.Tabs.Panel,{value:u.id,children:i(Oi,{id:u.id,moreActions:i(s.Tooltip,{label:"Open this query",children:i(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(u.id),children:i(L.IconArrowCurveRight,{size:16})})})})},u.id))]})]})]})}),o_=k.observer(()=>{const{panel:e}=gt();return i(Fe,{children:i(s.Box,{sx:{height:"100%",flexGrow:0,flexShrink:0,width:"600px"},children:p(s.Stack,{mt:24,spacing:5,sx:{width:"600px",height:"450px",background:"transparent",borderRadius:"5px",border:"1px solid #e9ecef",borderWidth:e.style.border.enabled?"1px":"0px"},children:[p(s.Group,{position:"apart",noWrap:!0,sx:{flexGrow:0,flexShrink:0},children:[i(s.Group,{children:i(Ti,{})}),i(s.Group,{grow:!0,position:"center",children:i(s.Text,{lineClamp:1,weight:"bold",children:e.title})}),i(s.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),i(s.Group,{px:5,pb:5,sx:{flexGrow:1},children:i(Di,{panel:e,height:"410px"})})]})})})}),Pi={name:"new_var",size:"1rem",weight:"initial",color:{type:"static",staticColor:"Red"},data_field:"",aggregation:{type:"sum",config:{}},formatter:{output:"number",mantissa:0,trimMantissa:!1,average:!1}};class l_{constructor(t){N(this,"panel");N(this,"selected");this.panel=t,re.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}addNew(){const t=this.panel.variables.filter(n=>n.name.startsWith(Pi.name)).length;this.panel.addVariable(x.cloneDeep({...Pi,name:`${Pi.name}${t||""}`})),this.selected=x.last(this.panel.variables)}select(t){this.selected=t}remove(t){this.selected===t&&(this.selected=void 0);const n=this.panel.variables.indexOf(t);if(this.panel.removeVariable(t),!this.selected&&!x.isEmpty(this.panel.variables)){const r=Math.min(this.panel.variables.length-1,n);this.selected=this.panel.variables[r]}}}function u_(){const{panel:e}=Je();return X.useCreation(()=>new l_(e),[e])}const Yl=s.createStyles(e=>({root:{height:"100%",overflow:"hidden",".var-list-container":{"& > *":{height:"100%"},width:250,height:"100%"},".var-list-actions":{height:"fit-content",flexShrink:0,width:"100%"},".var-list":{flex:"1 1 auto",overflow:"auto",minHeight:0,"& > *":{flex:"0 0 auto"}}},config:{height:"100%",overflow:"auto",paddingRight:10}})),c_=b.forwardRef(function({value:t,onChange:n,data:r,withStyle:a=!0},o){const l=(u,c)=>{const d=x.cloneDeep(t);x.set(d,u,c),n(d)};return p(s.Box,{px:"sm",py:"md",ref:o,children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(s.TextInput,{label:"Name",required:!0,value:t.name,onChange:u=>l("name",u.currentTarget.value)}),i(R,{label:"Data Field",required:!0,value:t.data_field,onChange:u=>l("data_field",u)})]}),i(_n,{label:"Aggregation",value:t.aggregation,onChange:u=>l("aggregation",u)}),i(s.Divider,{my:"xs",label:"Format",labelPosition:"center"}),i(je,{value:t.formatter,onChange:u=>l("formatter",u)}),a&&i(us,{value:t,onChange:n})]})}),d_=e=>{const{uiModel:t}=e;return i(s.Stack,{className:"var-list",children:t.variables.map(n=>i(s.Button,{variant:t.selected===n?"filled":"subtle",color:"gray",onClick:()=>t.select(n),children:n.name},n.name))})},p_=k.observer(d_),h_=({variable:e,data:t})=>i(s.Group,{style:{minHeight:0,height:"calc(100% - 68px)"},children:i(s.Paper,{withBorder:!0,p:"md",children:cs(e,t)})}),f_=k.observer(h_),g_=e=>{const t=X.useCreation(()=>h1(e.variable),[e.variable]),{classes:n}=Yl(),{data:r}=Je();return p(s.Group,{style:{height:"100%"},align:"start",children:[p(s.Stack,{"data-testid":"variable-editor",align:"stretch",className:n.config,children:[p(s.Group,{position:"right",children:[i(s.ActionIcon,{variant:"filled",disabled:!t.changed,color:"primary",onClick:t.commit,children:i(L.IconDeviceFloppy,{size:18})}),i(s.ActionIcon,{color:"red",onClick:()=>e.uiModel.remove(e.variable),children:i(L.IconTrash,{size:18})})]}),i(c_,{value:y.getSnapshot(t.copy),onChange:t.update,data:r})]}),i(f_,{variable:y.getSnapshot(t.copy),data:r})]})},m_=k.observer(g_),y_=()=>{const e=u_(),{classes:t}=Yl();return p(s.Group,{className:t.root,noWrap:!0,align:"start",children:[i(s.Paper,{withBorder:!0,p:"md",className:"var-list-container",children:p(s.Stack,{justify:"space-between",children:[i(s.Box,{className:"var-list-actions",children:i(s.Button,{variant:"light",size:"sm",onClick:e.addNew,fullWidth:!0,children:"Add Variable"})}),i(p_,{uiModel:e})]})}),e.selected?i(V,{children:i(m_,{uiModel:e,variable:e.selected})}):i("span",{children:"Select or create a new variable on right side"})]})},b_=k.observer(y_);function v_(){const{vizManager:e}=b.useContext(st);return b.useMemo(()=>{const t=e.availableVizList.map(n=>({value:n.name,label:n.displayName??n.name,group:n.displayGroup??""}));return x.orderBy(t,[n=>n.group,n=>n.label],["asc","asc"])},[e])}const x_=k.observer(({value:e,submit:t})=>{const[n,r]=Ee.useInputState(e);b.useEffect(()=>{r(e)},[e]);const a=v_(),o=e!==n;return i(s.Select,{label:"Visualization",value:n,searchable:!0,onChange:r,data:a,rightSection:i(s.ActionIcon,{disabled:!o,onClick:()=>t(n),children:i(T.DeviceFloppy,{size:20})}),maxDropdownHeight:600})}),Ql=[];function w_(e,t){try{return e.resolveComponent(t).createConfig()}catch{return null}}function C_(){const{data:e,panel:{variables:t,viz:n,title:r,queryIDs:a,description:o,setDescription:l,setTitle:u,addQueryID:c,removeQueryID:d,id:f}}=Je(),{vizManager:h}=b.useContext(st),g={title:r,description:o,viz:n,queryIDs:a,id:f},m={setDescription:l,addQueryID:c,removeQueryID:d,setTitle:u},C=gl(g);try{return h.resolveComponent(g.viz.type),i(Zn,{configure:C,children:i(b1,{variables:t,setVizConf:n.setConf,panel:g,panelInfoEditor:m,vizManager:h,data:e})})}catch(w){return console.info(x.get(w,"message")),null}}const S_=k.observer(()=>{const{data:e,panel:{viz:t}}=Je(),{vizManager:n}=b.useContext(st),r=b.useCallback(d=>{if(d===t.type)return;const f=w_(n,d);t.setType(d),t.setConf(f||{})},[t.type]),a=d=>{try{t.setConf(JSON.parse(d))}catch(f){console.error(f)}},o=b.useMemo(()=>{var d;return(d=Ql.find(f=>f.value===t.type))==null?void 0:d.Panel},[t.type,Ql]),l=C_(),u=o?b.createElement(o,{data:e,conf:t.conf,setConf:t.setConf}):null,c=l||u;return p(s.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[i(x_,{submit:r,value:t.type}),p(Fe,{children:[i(s.Stack,{pb:10,sx:{flexGrow:1,maxHeight:"100%",overflow:"auto"},children:c}),!c&&i(s.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(t.conf,null,2),onChange:a})]})]})}),__=k.observer(({panel:e,sourceViewID:t})=>{const n=ue(),[r,a]=b.useState(t);b.useEffect(()=>{a(t)},[t]);const[o,{open:l,close:u}]=Ee.useDisclosure(!1),c=()=>{e.moveToView(t,r),u()};return p(V,{children:[i(s.Button,{size:"xs",variant:"subtle",color:"blue",onClick:l,leftIcon:i(L.IconBoxMultiple,{size:14}),children:"Move into Another View"}),i(s.Modal,{opened:o,onClose:u,title:"Move panel into another view",zIndex:320,children:p(s.Stack,{sx:{maxHeight:"calc(100vh - 185px)",overflow:"hidden"},children:[i(s.Radio.Group,{value:r,onChange:a,pb:10,sx:{flexGrow:1,maxHeight:"calc(100vh - 185px - 30px)",overflow:"auto"},children:i(s.Stack,{spacing:"xs",children:n.views.options.map(d=>i(s.Radio,{value:d.value,label:d.label},d.value))})}),p(s.Group,{noWrap:!0,position:"apart",sx:{flexGrow:0,flexShrink:0},children:[i(s.Button,{size:"xs",color:"red",leftIcon:i(L.IconX,{size:14}),onClick:u,children:"Cancel"}),i(s.Button,{size:"xs",color:"blue",leftIcon:i(L.IconDeviceFloppy,{size:14}),onClick:c,disabled:r===t,children:"Confirm"})]})]})})]})}),k_={root:{flexGrow:1,width:"100%",overflow:"hidden"},panel:{width:"100%",height:"calc(100% - 44px)",padding:10,overflow:"scroll"}},Kl=({children:e})=>p(s.Group,{noWrap:!0,grow:!0,position:"left",spacing:20,sx:{width:"100%",height:"100%"},children:[i(s.Box,{sx:{maxWidth:"calc(100% - 610px - 10px)",height:"100%",overflow:"auto"},children:e}),i(o_,{})]});function T_(e){return!["richText","button"].includes(e)}const D_=k.observer(({panel:e})=>{const t=Ue.useModals(),n=me(),r=ue(),[a,o]=b.useState("Data"),l=e.queries,c=T_(e.viz.type)&&e.dataLoading,d=c||e.queryErrors.length>0||e.queryStateMessages.length>0||l.length===0,f=n.editor.path[1];b.useEffect(()=>{o(m=>d&&m==="Visualization"?"Data":m)},[e.id,d]);const h=()=>{n.editor.setPath(["_VIEWS_",f])},g=()=>t.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.removePanelByID(e.id,f),h()},confirmProps:{color:"red"},zIndex:320});return p(Cr,{value:{panel:e,data:e.data,loading:c,errors:e.queryErrors},children:[p(s.Group,{px:16,position:"apart",sx:{borderBottom:"1px solid #eee"},children:[p(s.Text,{pt:9,pb:8,children:[e.title?e.title:e.viz.type," "]}),p(s.Group,{position:"right",noWrap:!0,children:[i(__,{panel:e,sourceViewID:f}),i(s.Button,{size:"xs",variant:"subtle",color:"red",onClick:g,leftIcon:i(L.IconTrash,{size:14}),children:"Delete This Panel"})]})]}),p(s.Tabs,{value:a,onTabChange:o,keepMounted:!1,styles:k_,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Data",disabled:c,children:"Data"}),i(s.Tabs.Tab,{value:"Panel",children:"Panel"}),i(s.Tabs.Tab,{value:"Variables",disabled:d,children:i(s.Tooltip,{label:"Requires data",disabled:!d,withinPortal:!0,zIndex:310,children:i(s.Text,{children:"Variables"})})}),i(s.Tabs.Tab,{value:"Visualization",disabled:d,children:i(s.Tooltip,{label:"Requires data",disabled:!d,withinPortal:!0,zIndex:310,children:i(s.Text,{children:"Visualization"})})}),i(s.Tabs.Tab,{value:"Interactions",children:"Interactions"})]}),p(s.Tabs.Panel,{value:"Data",children:[i(s.LoadingOverlay,{visible:c,exitTransitionDuration:0}),i(s_,{})]}),i(s.Tabs.Panel,{value:"Panel",children:i(Kl,{children:i(r_,{})})}),i(s.Tabs.Panel,{value:"Variables",children:i(b_,{})}),i(s.Tabs.Panel,{value:"Visualization",children:i(Fe,{children:i(Kl,{children:i(S_,{})})})}),i(s.Tabs.Panel,{value:"Interactions",children:i(Fe,{children:i(Xc,{})})})]})]})}),M_=k.observer(({viewID:e,panelID:t})=>{const n=ue();if(!n.views.findByID(e))return p(s.Text,{size:14,children:["View by ID[",e,"] is not found"]});const a=n.panels.findByID(t);return a?i(D_,{panel:a}):p(s.Text,{size:14,children:["Panel by ID[",t,"] is not found"]})}),I_=e=>{const{queryModel:t}=e,n=me(),r=ue(),o=r.findQueryUsage(t.id).length>0,l=Ue.useModals(),u=()=>{l.openConfirmModal({title:"Delete this query?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.queries.removeQuery(t.id),n.editor.setPath(["_QUERIES_",""])},confirmProps:{color:"red"},zIndex:320})};return o?i(s.Tooltip,{label:"Can't delete this query for it's being used, check out Usage tab for details",withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,children:i(s.Button,{color:"gray",size:"xs",leftIcon:i(L.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})}):i(s.Button,{color:"red",size:"xs",onClick:u,leftIcon:i(L.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})},E_=k.observer(I_),Ul=({width:e="calc(100% - 32px)",lastWidth:t="50%",height:n,count:r,spacing:a=16,pl:o=0})=>p(s.Stack,{spacing:a,mt:6,pl:o,children:[Array.from(new Array(r-1),(l,u)=>i(s.Skeleton,{width:e,height:n,radius:"xs"},u)),i(s.Skeleton,{width:t,height:n,radius:"xs"})]}),ln=({value:e})=>e===null||e===""?null:i(s.Tooltip,{label:e,disabled:!e,multiline:!0,children:i(s.ActionIcon,{children:i(L.IconInfoCircle,{size:14})})}),A_=({column:e})=>{const{column_key:t,column_key_text:n}=e;return t?i(s.Tooltip,{label:n,disabled:!n,children:i(s.Badge,{children:t})}):null},z_=k.observer(({dataSource:e})=>{const{columns:t}=e;return t.loading?i(Ul,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):t.empty?null:p(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"1000px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[i("col",{style:{width:50}}),i("col",{style:{minWidth:300}}),i("col",{style:{width:30}}),i("col",{style:{width:70}}),i("col",{style:{minWidth:300}}),i("col",{style:{minWidth:80,width:80}}),i("col",{style:{minWidth:120,width:120}})]}),i("thead",{children:p("tr",{children:[i("th",{children:"#"}),i("th",{children:"Column Name"}),i("th",{}),i("th",{}),i("th",{children:"Type"}),i("th",{children:"Nullable"}),i("th",{children:"Default Value"})]})}),i("tbody",{children:t.data.map(n=>p("tr",{children:[i("td",{children:n.ordinal_position}),i("td",{children:n.column_name}),i("td",{children:i(ln,{value:n.column_comment})}),i("td",{children:i(A_,{column:n})}),i("td",{children:n.column_type}),i("td",{children:n.is_nullable}),i("td",{children:i(ln,{value:n.column_default})})]},n.column_name))})]})}),$_=k.observer(({dataSource:e})=>{const{indexes:t}=e,n=t.data;return p(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"950px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[i("col",{style:{width:100}}),i("col",{style:{minWidth:300}}),i("col",{style:{width:150}}),i("col",{style:{width:150}}),i("col",{style:{width:250}})]}),i("thead",{children:p("tr",{children:[i("th",{children:"Index Length"}),i("th",{children:"Index Name"}),i("th",{children:"Index Algorithm"}),i("th",{children:"Unique"}),i("th",{children:"Column Name"})]})}),i("tbody",{children:n.map(r=>p("tr",{children:[i("td",{children:r.index_length}),i("td",{children:r.index_name}),i("td",{children:r.index_algorithm}),i("td",{children:r.is_unique?"YES":"NO"}),i("td",{children:r.column_name})]},r.index_name))})]})}),L_=k.observer(({dataSource:e})=>{const{indexes:t}=e,n=t.data;return p(s.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"850px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[p("colgroup",{children:[i("col",{style:{minWidth:300}}),i("col",{style:{width:150}}),i("col",{style:{width:100}}),i("col",{style:{width:100}}),i("col",{style:{width:100}}),i("col",{style:{width:100}})]}),i("thead",{children:p("tr",{children:[i("th",{children:"Index Name"}),i("th",{children:"Index Algorithm"}),i("th",{children:"Unique"}),i("th",{children:"Definition"}),i("th",{children:"Condition"}),i("th",{children:"Comment"})]})}),i("tbody",{children:n.map(r=>p("tr",{children:[i("td",{children:r.index_name}),i("td",{children:r.index_algorithm}),i("td",{children:r.is_unique?"YES":"NO"}),i("td",{children:i(ln,{value:r.index_definition})}),i("td",{children:i(ln,{value:r.condition})}),i("td",{children:i(ln,{value:r.comment})})]},r.index_name))})]})}),O_=k.observer(({dataSource:e})=>{const{indexes:t}=e;return t.loading||t.empty?null:e.type===Ce.MySQL?i($_,{dataSource:e}):e.type===Ce.Postgresql?i(L_,{dataSource:e}):null}),P_=k.observer(({dataSource:e})=>p(s.Stack,{spacing:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[i(Fe,{children:i(z_,{dataSource:e})}),i(Fe,{children:i(O_,{dataSource:e})})]}));function B_({table_type:e}){return e==="VIEW"?i(L.IconEye,{size:14}):e==="BASE TABLE"?i(L.IconTable,{size:14}):null}const V_=k.observer(({dataSource:e})=>{const{tables:t}=e;return t.loading?i(Ul,{height:"24px",lastWidth:"50%",count:15}):i(s.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(t.data).map(([n,r])=>i(s.NavLink,{label:n,icon:i(L.IconDatabase,{size:14}),defaultOpened:e.table_schema===n,pl:0,childrenOffset:14,children:r.map(a=>i(s.NavLink,{label:a.table_name,icon:i(B_,{table_type:a.table_type}),onClick:()=>{e.setKeywords(n,a.table_name)},active:e.table_name===a.table_name},a.table_name))},n))})}),N_=({visible:e})=>i(s.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:i(s.LoadingOverlay,{visible:e})}),q_=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],F_={icon:{width:"50px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"50px"}}},G_=k.observer(({dataSource:e})=>{const{tableData:t}=e;return p(s.Group,{pt:10,px:10,position:"apart",children:[p(s.Group,{position:"left",children:[t.maxPage>1&&i(s.Pagination,{size:"sm",value:t.page,onChange:t.setPage,total:t.maxPage,withEdges:t.maxPage>7,styles:{control:{height:"30px"}}}),i(s.Select,{icon:i(s.Text,{ta:"center",color:"dimmed",size:14,children:"Limit"}),size:"xs",styles:F_,data:q_,value:String(t.limit),onChange:n=>t.setLimit(Number(n))})]}),i(s.Group,{position:"right",children:p(s.Text,{color:"dimmed",my:0,size:14,children:["Total ",t.total," rows"]})})]})}),W_=k.observer(({dataSource:e})=>{const t=e.tableData;return t.maxPage===0?i(s.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:"This table is empty"}):t.error?i(s.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:t.error}):t.page===1&&t.loading?i(N_,{visible:!0}):p(Fe,{children:[i(G_,{dataSource:e}),p(s.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[i(s.LoadingOverlay,{visible:t.loading,overlayBlur:2}),i(jl,{data:t.data})]})]})}),R_={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},j_=k.observer(({dataSource:e})=>(b.useEffect(()=>{e.loadTablesIfEmpty()},[e]),e.tables.error?i(s.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e.tables.error}):p(s.Flex,{sx:{height:"100%"},children:[i(s.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:i(Fe,{children:i(V_,{dataSource:e})})}),p(s.Tabs,{defaultValue:"structure",styles:R_,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"structure",icon:i(L.IconColumns,{size:14}),children:"Structure"}),i(s.Tabs.Tab,{value:"data",icon:i(L.IconDatabase,{size:14}),children:"Data"})]}),i(s.Tabs.Panel,{value:"structure",children:i(P_,{dataSource:e})}),i(s.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:i(W_,{dataSource:e})})]})]}))),Y_={modal:{paddingLeft:"0px !important",paddingRight:"0px !important"},header:{marginBottom:0,padding:"20px 20px 10px",borderBottom:"1px solid #efefef",gap:"20px"},title:{flexGrow:1},body:{padding:"0 0 0 20px"}},Xl=k.observer(({dataSource:e,triggerButtonProps:t={}})=>{const[n,r]=b.useState(!1);return e.type==="http"?null:p(V,{children:[i(s.Modal,{opened:n,onClose:()=>r(!1),title:p(s.Group,{position:"apart",sx:{flexGrow:1},children:[i(s.Text,{fw:500,children:"Explorer Data Source"}),p(s.Group,{spacing:7,children:[i(s.Badge,{variant:"gradient",gradient:{from:"indigo",to:"cyan"},children:e.key}),i(s.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:e.type})]})]}),zIndex:320,size:"96vw",styles:Y_,children:i(s.Box,{sx:{height:"calc(100vh - 220px)"},children:i(j_,{dataSource:e})})}),i(s.Button,{variant:"subtle",onClick:()=>r(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...t,children:"See Table Structure"})]})}),Q_=b.forwardRef(({label:e,type:t,...n},r)=>p(s.Group,{position:"apart",ref:r,...n,children:[i(s.Text,{children:e}),i(s.Text,{children:t})]})),K_=k.observer(({value:e,onChange:t})=>{const n=me(),{data:r=[],loading:a}=X.useRequest(mr,{refreshDeps:[]},[]),o=b.useMemo(()=>r.map(d=>({label:d.key,value:d.key,type:d.type})),[r]),l=b.useMemo(()=>o.reduce((d,f)=>(d[f.value]=f.type,d),{}),[o]),u=d=>{d!==null&&t({key:d,type:l[d]})},c=b.useMemo(()=>n.datasources.find(e),[n,e]);return i(s.Select,{data:o,label:p(s.Group,{position:"apart",children:[i(s.Box,{children:"Data Source"}),c&&i(Xl,{dataSource:c,triggerButtonProps:{compact:!0,size:"xs",px:10}})]}),itemComponent:Q_,rightSection:c?i(s.Text,{size:"xs",color:"dimmed",children:c.type}):void 0,rightSectionWidth:85,maxDropdownHeight:280,styles:{root:{flex:1},label:{display:"block"},rightSection:{pointerEvents:"none",justifyContent:"flex-end",paddingRight:"10px",".mantine-Text-root":{userSelect:"none"}}},disabled:a,value:e.key,onChange:u})}),U_=k.observer(({queryModel:e})=>{const[t,n]=b.useState(e.name);return b.useEffect(()=>{n(e.name)},[e.name]),i(s.Center,{ml:20,mt:20,sx:{maxWidth:"600px"},children:p(s.Stack,{spacing:10,sx:{width:"100%"},children:[i(s.Divider,{mb:-10,variant:"dashed",label:"Basics",labelPosition:"center"}),i(s.TextInput,{placeholder:"A unique name",label:"Name",required:!0,sx:{flex:1},value:t,onChange:r=>{n(r.currentTarget.value)},rightSection:i(s.ActionIcon,{variant:"filled",color:"blue",size:"sm",onClick:()=>e.setName(t),disabled:t===e.name,children:i(L.IconDeviceFloppy,{size:16})}),onBlur:()=>{e.setName(t)}}),i(K_,{value:{type:e.type,key:e.key},onChange:({type:r,key:a})=>{e.setKey(a),e.setType(r)}}),i(s.Divider,{mt:10,mb:-10,variant:"dashed",label:"Conditions",labelPosition:"center"}),i(s.MultiSelect,{label:"Run query when these are truthy",placeholder:"Always run this query on load",data:e.conditionOptions,value:[...e.run_by],onChange:e.setRunBy}),e.typedAsHTTP&&i(s.MultiSelect,{label:"Re-run query when these changed",placeholder:"Leave it empty to never re-run this query",data:e.conditionOptions,value:[...e.react_to],onChange:e.setReactTo}),i(s.Divider,{mt:20,mb:10,variant:"dashed"}),i(E_,{queryModel:e})]})})});function X_(){const[e,{open:t,close:n}]=Ee.useDisclosure(!1);return p(V,{children:[i(s.Modal,{opened:e,onClose:n,title:"About FunctionUtils",zIndex:320,children:i(Un,{value:Eu,styles:{root:{border:"none"},content:{padding:0,table:{marginBottom:0}}}})}),i(s.Button,{variant:"light",color:"violet",size:"xs",onClick:t,leftIcon:i(L.IconInfoCircle,{size:16}),children:"About parameter 'utils'"})]})}const J_=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{sx:{position:"relative",flexGrow:1},children:i(Ae,{className:"function-editor",height:"100%",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1}}})})},or=b.forwardRef(({value:e,onChange:t,label:n,defaultValue:r},a)=>{const[o,l]=b.useState(e),u=()=>{t(o)},c=()=>{l(e)},d=()=>{l(r)};b.useEffect(()=>{l(e)},[e]);const f=o!==e;return p(s.Stack,{spacing:4,sx:{height:"100%"},children:[p(s.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[i(s.Group,{position:"left",children:i(X_,{})}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,size:"xs",variant:"default",leftIcon:i(L.IconPlayerSkipBack,{size:16}),children:"Reset to default"}),i(s.Button,{onClick:c,color:"red",size:"xs",disabled:!f,leftIcon:i(L.IconRecycle,{size:16}),children:"Revert Changes"}),i(s.Button,{size:"xs",onClick:u,disabled:!f,leftIcon:i(L.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),i(s.Text,{size:14,children:n}),i(J_,{value:o,onChange:l})]})});function Z_({content:e}){return p(s.HoverCard,{width:"60vw",shadow:"md",children:[i(s.HoverCard.Target,{children:i(s.ActionIcon,{size:16,color:"blue",children:i(L.IconEye,{})})}),i(s.HoverCard.Dropdown,{children:i(Tt.Prism,{language:"sql",noCopy:!0,withLineNumbers:!0,children:e})})]})}const H_=k.observer(()=>{const t=[...me().globalSQLSnippets.list];return t.length===0?null:p(s.Table,{horizontalSpacing:"xs",verticalSpacing:"xs",fontSize:"sm",highlightOnHover:!0,children:[i("thead",{children:p("tr",{children:[i("th",{children:"Key"}),i("th",{children:"Value"})]})}),i("tbody",{children:t.map(n=>{const{id:r,content:a}=n;return p("tr",{children:[i("td",{children:r}),i("td",{width:200,children:i(Z_,{content:a})})]},r)})})]})}),ek=`
497
497
  -- You may reference query variables in SQL or VizConfig.
498
498
  SELECT *
499
499
  FROM commit
@@ -506,8 +506,8 @@ WHERE
506
506
  AND \${sql_snippets.author_email_condition}
507
507
  -- Global SQL snippets (shared between dashboards)
508
508
  AND \${global_sql_snippets.account_condition}
509
- `,$l=k.observer(function({showSQLSnippets:e=!0,sx:n={}}){const r=he(),a=K(),o=r.context.current,l=(()=>{const u={context:{...a.mock_context.current,...o},filters:a.filters.previewValues};return e&&(u.sql_snippets=a.sqlSnippets.record),JSON.stringify(u,null,2)})();return i(s.Stack,{sx:{overflow:"hidden",...n},children:p(s.Tabs,{defaultValue:"guide",keepMounted:!1,children:[p(s.Tabs.List,{grow:!0,children:[i(s.Tabs.Tab,{value:"guide",icon:i(L.IconAlertCircle,{size:14}),children:"Guide"}),i(s.Tabs.Tab,{value:"local_query_vars",icon:i(L.IconVariable,{size:14}),children:"Variables in this dashboard"}),i(s.Tabs.Tab,{value:"global_sql_snippets",icon:i(L.IconVariablePlus,{size:14}),children:"Global SQL Snippets"})]}),i(s.Tabs.Panel,{value:"guide",pt:"xs",children:i(kt.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:D_})}),i(s.Tabs.Panel,{value:"local_query_vars",pt:"xs",children:i(kt.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:l})}),i(s.Tabs.Panel,{value:"global_sql_snippets",pt:"xs",children:p(s.Stack,{spacing:10,children:[i(s.Alert,{icon:i(L.IconAlertCircle,{size:16}),title:"Global SQL Snippets",children:"SQL snippets worth sharing between dashboards are managed in System Settings by admins."}),i(T_,{})]})})]})})}),Li=k.observer(()=>{const[t,e]=y.useState(!1);return p(V,{children:[i(s.Modal,{opened:t,onClose:()=>e(!1),title:"Query Variables",zIndex:320,size:"800px",children:i($l,{})}),i(s.Button,{variant:"subtle",onClick:()=>e(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},children:"See Query Variables"})]})}),Ll={pre:["function build_request({ context, filters }, utils) {"," // build the quest"," return { method: 'POST', url: '/', params: {}, headers: {}, data: {} }","}"].join(`
509
+ `,Jl=k.observer(function({showSQLSnippets:t=!0,sx:n={}}){const r=me(),a=ue(),o=r.context.current,l=(()=>{const u={context:{...a.mock_context.current,...o},filters:a.filters.previewValues};return t&&(u.sql_snippets=a.sqlSnippets.record),JSON.stringify(u,null,2)})();return i(s.Stack,{sx:{overflow:"hidden",...n},children:p(s.Tabs,{defaultValue:"guide",keepMounted:!1,children:[p(s.Tabs.List,{grow:!0,children:[i(s.Tabs.Tab,{value:"guide",icon:i(L.IconAlertCircle,{size:14}),children:"Guide"}),i(s.Tabs.Tab,{value:"local_query_vars",icon:i(L.IconVariable,{size:14}),children:"Variables in this dashboard"}),i(s.Tabs.Tab,{value:"global_sql_snippets",icon:i(L.IconVariablePlus,{size:14}),children:"Global SQL Snippets"})]}),i(s.Tabs.Panel,{value:"guide",pt:"xs",children:i(Tt.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:ek})}),i(s.Tabs.Panel,{value:"local_query_vars",pt:"xs",children:i(Tt.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:l})}),i(s.Tabs.Panel,{value:"global_sql_snippets",pt:"xs",children:p(s.Stack,{spacing:10,children:[i(s.Alert,{icon:i(L.IconAlertCircle,{size:16}),title:"Global SQL Snippets",children:"SQL snippets worth sharing between dashboards are managed in System Settings by admins."}),i(H_,{})]})})]})})}),Bi=k.observer(()=>{const[e,t]=b.useState(!1);return p(V,{children:[i(s.Modal,{opened:e,onClose:()=>t(!1),title:"Query Variables",zIndex:320,size:"800px",children:i(Jl,{})}),i(s.Button,{variant:"subtle",onClick:()=>t(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},children:"See Query Variables"})]})}),Zl={pre:["function build_request({ context, filters }, utils) {"," // build the quest"," return { method: 'POST', url: '/', params: {}, headers: {}, data: {} }","}"].join(`
510
510
  `),post:["function process_result(res, utils) {"," // your code goes here"," return data","}"].join(`
511
- `)},M_=k.observer(({queryModel:t})=>t.typedAsHTTP?p(s.Tabs,{defaultValue:"pre_process",orientation:"vertical",sx:{flexGrow:1},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"pre_process",children:"Build Request"}),i(s.Tabs.Tab,{value:"post_process",children:"Process Result"}),i(Li,{})]}),i(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:i(ar,{label:"",value:t.pre_process,onChange:t.setPreProcess,defaultValue:Ll.pre})}),i(s.Tabs.Panel,{value:"post_process",p:"sm",children:i(ar,{label:"",value:t.post_process,onChange:t.setPostProcess,defaultValue:Ll.post})})]}):null),I_=k.observer(({queryID:t,usage:e})=>{const n=he().editor,r=o=>{if(o.type==="filter"){n.setPath(["_FILTERS_",o.id]);return}if(o.type==="panel"){const l=o.views[0].id;n.setPath(["_VIEWS_",l,"_PANELS_",o.id]);return}},a=o=>{n.setPath(["_VIEWS_",o])};return i(s.Stack,{py:"sm",px:"md",children:p(s.Table,{highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[i("thead",{children:p("tr",{children:[i("th",{style:{width:100},children:"Type"}),i("th",{style:{width:"calc(50% - 50px)"},children:"Name"}),i("th",{children:"In View(s)"})]})}),i("tbody",{children:e.map(o=>p("tr",{children:[i("td",{children:x.capitalize(o.type)}),i("td",{children:i(s.Anchor,{component:"button",type:"button",onClick:()=>r(o),children:o.label})}),i("td",{children:p(s.Stack,{align:"flex-start",justify:"flex-start",spacing:2,children:[o.views.map(l=>i(s.Anchor,{component:"button",type:"button",onClick:()=>a(l.id),children:i(s.Box,{children:l.label})})),o.views.length===0&&i(s.Box,{children:"--"})]})})]},o.id))})]})})}),Oi=({value:t,onChange:e,height:n="200px",defaultLanguage:r="sql",theme:a="vs-dark"})=>{const o=u=>{console.log("changing"),e==null||e(u??"")},l=!e;return i(Ie,{className:"minimal-monaco-editor",height:n,defaultLanguage:r,value:t,onChange:l?void 0:o,theme:a,options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1},readOnly:l||!e,"semanticHighlighting.enabled":!0}})},E_=({value:t,height:e="200px",defaultLanguage:n="sql"})=>i(Ie,{className:"preview-sql-in-monaco-editor",height:e,defaultLanguage:n,value:t,onChange:void 0,theme:"vs-light",options:{lineNumbers:"on",folding:!0,lineDecorationsWidth:20,wordWrap:"on",minimap:{enabled:!1},readOnly:!0}}),A_=k.observer(({value:t})=>{const n=K().payloadForSQL,r=y.useMemo(()=>hr(t,n),[t,n]);return i(E_,{height:"100%",value:r})}),Ol={pre:["function process_request({ context, filters, sql }, utils) {"," // modify and return sql"," return sql","}"].join(`
511
+ `)},tk=k.observer(({queryModel:e})=>e.typedAsHTTP?p(s.Tabs,{defaultValue:"pre_process",orientation:"vertical",sx:{flexGrow:1},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"pre_process",children:"Build Request"}),i(s.Tabs.Tab,{value:"post_process",children:"Process Result"}),i(Bi,{})]}),i(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:i(or,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:Zl.pre})}),i(s.Tabs.Panel,{value:"post_process",p:"sm",children:i(or,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:Zl.post})})]}):null),nk=k.observer(({queryID:e,usage:t})=>{const n=me().editor,r=o=>{if(o.type==="filter"){n.setPath(["_FILTERS_",o.id]);return}if(o.type==="panel"){const l=o.views[0].id;n.setPath(["_VIEWS_",l,"_PANELS_",o.id]);return}},a=o=>{n.setPath(["_VIEWS_",o])};return i(s.Stack,{py:"sm",px:"md",children:p(s.Table,{highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[i("thead",{children:p("tr",{children:[i("th",{style:{width:100},children:"Type"}),i("th",{style:{width:"calc(50% - 50px)"},children:"Name"}),i("th",{children:"In View(s)"})]})}),i("tbody",{children:t.map(o=>p("tr",{children:[i("td",{children:x.capitalize(o.type)}),i("td",{children:i(s.Anchor,{component:"button",type:"button",onClick:()=>r(o),children:o.label})}),i("td",{children:p(s.Stack,{align:"flex-start",justify:"flex-start",spacing:2,children:[o.views.map(l=>i(s.Anchor,{component:"button",type:"button",onClick:()=>a(l.id),children:i(s.Box,{children:l.label})})),o.views.length===0&&i(s.Box,{children:"--"})]})})]},o.id))})]})})}),Vi=({value:e,onChange:t,height:n="200px",defaultLanguage:r="sql",theme:a="vs-dark"})=>{const o=u=>{t==null||t(u??"")},l=!t;return i(Ae,{className:"minimal-monaco-editor",height:n,defaultLanguage:r,value:e,onChange:l?void 0:o,theme:a,options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1},readOnly:l||!t,"semanticHighlighting.enabled":!0}})},rk=({value:e,onChange:t,defaultValue:n})=>{const[r,a]=b.useState(e),o=()=>{t(r)},l=()=>{a(e)},u=()=>{a(n)};b.useEffect(()=>{a(e)},[e]);const c=r!==e;return p(s.Stack,{spacing:4,sx:{height:"100%"},children:[p(s.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[i(s.Group,{position:"left",children:i(s.Button,{onClick:u,size:"xs",variant:"default",leftIcon:i(L.IconPlayerSkipBack,{size:16}),children:"Reset to default"})}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:l,color:"red",size:"xs",disabled:!c,leftIcon:i(L.IconRecycle,{size:16}),children:"Revert Changes"}),i(s.Button,{size:"xs",onClick:o,disabled:!c,leftIcon:i(L.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),i(Vi,{height:"100%",value:r,onChange:a,theme:"sql-dark",defaultLanguage:"sql"})]})},ik=({value:e,height:t="200px",defaultLanguage:n="sql"})=>i(Ae,{className:"preview-sql-in-monaco-editor",height:t,defaultLanguage:n,value:e,onChange:void 0,theme:"vs-light",options:{lineNumbers:"on",folding:!0,lineDecorationsWidth:20,wordWrap:"on",minimap:{enabled:!1},readOnly:!0}}),ak=k.observer(({value:e})=>{const n=Me().payloadForSQL,r=b.useMemo(()=>gr(e,n),[e,n]);return i(ik,{height:"100%",value:r})}),Hl={pre:["function process_request({ context, filters, sql }, utils) {"," // modify and return sql"," return sql","}"].join(`
512
512
  `),post:["function process_result(data, utils) {"," // process data and return the result"," return data","}"].join(`
513
- `)},z_=k.observer(({queryModel:t})=>{const[e,n]=y.useState(t.sql);y.useEffect(()=>{n(o=>o!==t.sql?t.sql:o)},[t.sql]);const r=e!==t.sql,a=()=>{t.setSQL(e)};return t.typedAsSQL?p(s.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Edit",children:p(s.Group,{spacing:14,position:"apart",children:["Edit SQL",i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!r,onClick:a,children:i(D.DeviceFloppy,{size:20})})]})}),i(s.Tabs.Tab,{value:"Preview",children:"Preview SQL"}),i(s.Tabs.Tab,{value:"pre_process",children:"Process Request"}),i(s.Tabs.Tab,{value:"post_process",children:"Process Result"}),i(Li,{}),t.datasource&&i(zl,{dataSource:t.datasource})]}),i(s.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:i(Oi,{height:"100%",value:e,onChange:n,theme:"sql-dark",defaultLanguage:"sql"})}),i(s.Tabs.Panel,{value:"Preview",p:0,pl:4,children:i(A_,{value:t.sql})}),i(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:i(ar,{label:"",value:t.pre_process,onChange:t.setPreProcess,defaultValue:Ol.pre})}),i(s.Tabs.Panel,{value:"post_process",p:"sm",children:i(ar,{label:"",value:t.post_process,onChange:t.setPostProcess,defaultValue:Ol.post})})]}):null}),sr={height:"calc(100% - 44px)",padding:0},$_=k.observer(({queryModel:t})=>{const e=K(),n=y.useMemo(()=>t.datasource?t.typedAsHTTP?"HTTP":"SQL":"Configurations",[t.datasource,t.typedAsHTTP]),[r,a]=y.useState(n);y.useEffect(()=>{a(u=>u!=="Configurations"&&n==="Configurations"?"Configurations":u)},[n]);const o=e.findQueryUsage(t.id),l=o.length===0;return i(s.Stack,{sx:{flexGrow:1},my:0,p:0,children:p(s.Tabs,{value:r,onTabChange:a,defaultValue:n,orientation:"horizontal",keepMounted:!1,sx:{flexGrow:1},children:[p(s.Tabs.List,{grow:!0,children:[i(s.Tabs.Tab,{value:"Configurations",children:"Configurations"}),t.typedAsSQL&&i(s.Tabs.Tab,{value:"SQL",children:"Request"}),t.typedAsHTTP&&i(s.Tabs.Tab,{value:"HTTP",children:"Request"}),i(s.Tabs.Tab,{value:"Data",disabled:!t.datasource,children:i(s.Tooltip,{label:"Need to pick a Data Source first",disabled:t.datasource,withinPortal:!0,children:i(s.Text,{children:"Data"})})}),i(s.Tabs.Tab,{value:"Usage",disabled:l,children:i(s.Tooltip,{label:"This query is not used for any filter or panel",disabled:!l,withinPortal:!0,children:i(s.Text,{children:"Usage"})})})]}),i(s.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:i(C_,{queryModel:t})}),t.typedAsSQL&&i(s.Tabs.Panel,{value:"SQL",sx:sr,children:i(s.Stack,{sx:{height:"100%"},children:i(z_,{queryModel:t})})}),t.typedAsHTTP&&i(s.Tabs.Panel,{value:"HTTP",sx:sr,children:i(s.Stack,{sx:{height:"100%"},children:i(M_,{queryModel:t})})}),i(s.Tabs.Panel,{value:"Data",sx:{...sr,overflow:"hidden"},children:i(zi,{id:t.id})}),i(s.Tabs.Panel,{value:"Usage",sx:{...sr,overflow:"hidden"},children:i(I_,{queryID:t.id,usage:o})})]})})}),L_=k.observer(({id:t})=>{const n=K().queries.findByID(t);return t===""?null:n?i(s.Stack,{sx:{height:"100%"},spacing:"sm",children:i($_,{queryModel:n})}):i(s.Text,{size:14,color:"red",children:"Invalid Query ID"})}),O_=k.observer(({value:t})=>{const n=K().payloadForSQL,r=y.useMemo(()=>hr(t,n),[t,n]);return i(Oi,{height:"100%",value:r})}),P_=k.observer(({item:t,remove:e,onKeyChanged:n})=>{const[r,a]=y.useState("SQL"),[o,l]=y.useState(t.key),u=()=>{t.setKey(o),n(o)},c=o!==t.key,d=t.isADuplicatedKey(o),[f,h]=y.useState(t.value),g=()=>{t.setValue(f)};y.useEffect(()=>{l(t.key),h(t.value)},[t]);const m=f!==t.value,w=Ue.useModals(),C=()=>{w.openConfirmModal({title:"Delete this SQL snippet?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:e,confirmProps:{color:"red"},zIndex:320})};return p(s.Stack,{p:20,sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",children:[p(s.Group,{sx:{alignItems:"end"},spacing:40,children:[i(s.TextInput,{label:d?"This key is occupied by another snippet":"Key",value:o,onChange:_=>{l(_.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:i(s.ActionIcon,{color:"blue",variant:"subtle",onClick:u,disabled:!c||d,children:i(D.DeviceFloppy,{size:16})}),error:d}),i(s.Button,{leftIcon:i(D.Trash,{size:16}),color:"red",variant:"light",onClick:C,children:"Delete this SQL Snippet"})]}),p(s.Tabs,{value:r,onTabChange:a,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[p(s.Tabs.List,{sx:{position:"relative"},children:[i(s.Tabs.Tab,{value:"SQL",children:"SQL"}),i(s.Tabs.Tab,{value:"Preview",children:"Preview"}),i(Li,{}),i(s.ActionIcon,{color:"blue",variant:"filled",onClick:g,disabled:!m,sx:{position:"absolute",top:0,right:10},children:i(D.DeviceFloppy,{size:18})})]}),i(s.Tabs.Panel,{value:"SQL",pt:"sm",children:i(Oi,{height:"100%",value:f,onChange:h,defaultLanguage:"sql",theme:"sql-dark"})}),i(s.Tabs.Panel,{value:"Preview",pt:"sm",children:i(O_,{value:f})})]})]})}),B_=k.observer(({id:t})=>{const e=he(),n=K(),r=y.useMemo(()=>n.sqlSnippets.findByKey(t),[t]);if(!t)return null;if(!r)return p(s.Text,{size:14,children:["SQL Snippet by key[",t,"] is not found"]});const a=()=>{e.editor.setPath(["_SQL_SNIPPETS_",""])};return i(P_,{item:r,remove:()=>{n.sqlSnippets.removeByKey(t),a()},onKeyChanged:u=>{e.editor.setPath(["_SQL_SNIPPETS_",u])}})}),V_=k.observer(({view:t})=>!t||t.type!==H.Division?null:p(s.Stack,{children:[i(s.Divider,{mt:8,mb:0,label:"Division settings",labelPosition:"center"}),i(s.Text,{align:"center",size:"xs",color:"dimmed",children:"Under construction"})]})),N_=[{value:"default",label:"Default"},{value:"outline",label:"Outline"},{value:"pills",label:"Pills"}],q_=[{value:"horizontal",label:"Horizontal"},{value:"vertical",label:"Vertical"}],F_=k.observer(({view:t})=>{if(!t||t.type!==H.Tabs)return null;const e=t.config;return p(s.Stack,{children:[i(s.Divider,{mt:8,mb:0,label:"Tabs settings",labelPosition:"center"}),i(s.Select,{label:"Variant",value:e.variant,onChange:e.setVariant,data:N_}),i(s.Select,{label:"Orientation",value:e.orientation,onChange:e.setOrientation,data:q_}),i(s.Switch,{label:"Grow Tabs",checked:e.grow,onChange:n=>e.setGrow(n.currentTarget.checked)})]})}),G_=({disabled:t,value:e,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[t&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Ie,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},W_=({value:t,onChange:e})=>{const[n,{setTrue:r,setFalse:a}]=X.useBoolean(),[o,l]=y.useState(t??Ci),u=g=>{l({...o,enabled:g})},c=()=>{a();const{enabled:g,func_content:m}=o,w={enabled:g,func_content:m};l(w),e(w)},d=()=>{a(),l(t)},f=g=>{l(m=>({...m,func_content:g}))},h=()=>{f(Ci.func_content)};return p(V,{children:[i(s.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:r,sx:{flexGrow:0},children:i(D.Settings,{size:14})}),i(s.Modal,{size:800,title:"Customize modal title",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:o.enabled,onChange:g=>u(g.currentTarget.checked)}),i(G_,{value:o.func_content,onChange:f,disabled:!o.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:h,color:"red",leftIcon:i(D.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})},j_=k.observer(({view:t})=>{if(!t||t.type!==H.Modal)return null;const e=t.config,n=e.custom_modal_title.value;return p(s.Stack,{children:[i(s.Divider,{mt:8,label:"Modal settings",labelPosition:"center"}),p(s.Flex,{gap:10,children:[i(s.TextInput,{label:"Modal Title",value:n,onChange:x.noop,disabled:!0,sx:{flexGrow:1}}),i(W_,{value:e.custom_modal_title,onChange:e.custom_modal_title.replace})]}),p(s.Group,{grow:!0,children:[i(s.TextInput,{label:"Width",value:e.width,onChange:r=>e.setWidth(r.currentTarget.value),placeholder:"600px / 50vw"}),i(s.TextInput,{label:"Height",value:e.height,onChange:r=>e.setHeight(r.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),R_=k.observer(({view:t})=>p(V,{children:[i(V_,{view:t}),i(j_,{view:t}),i(F_,{view:t})]})),Y_=[{label:"Division",value:H.Division},{label:"Modal",value:H.Modal},{label:"Tabs",value:H.Tabs}],Q_=k.observer(({view:t})=>t?p(s.Stack,{sx:{position:"relative"},children:[i(s.TextInput,{label:"Name",value:t.name,onChange:e=>{t.setName(e.currentTarget.value)}}),i(s.Select,{label:"Type",withinPortal:!0,zIndex:320,value:t.type,onChange:t.setType,data:Y_}),i(R_,{view:t})]}):null),K_=k.observer(({id:t})=>{const e=Ue.useModals(),n=he(),r=K();if(t==="")return null;const a=r.views.findByID(t);if(!a)return p(s.Text,{size:14,children:["View by ID[",t,"] is not found"]});const o=()=>{n.editor.setPath(["_VIEWS_",""])},l=()=>{e.openConfirmModal({title:"Delete this view?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.views.removeByID(t),o()},zIndex:320})};return p(s.Stack,{sx:{maxWidth:"600px",height:"100%"},spacing:"sm",children:[i(s.Group,{position:"right",pt:10,children:i(s.Button,{size:"xs",color:"red",leftIcon:i(D.Trash,{size:16}),onClick:l,children:"Delete this view"})}),i(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:i(Q_,{view:a})})]})});function U_(t){return t.length===1&&t[0]==="_QUERY_VARS_"}function X_(t){return t.length===1&&t[0]==="_MOCK_CONTEXT_"}function J_(t){return t.length===2&&t[0]==="_FILTERS_"}function Z_(t){return t.length===2&&t[0]==="_SQL_SNIPPETS_"}function H_(t){return t.length===2&&t[0]==="_QUERIES_"}function ek(t){return t.length===2&&t[0]==="_VIEWS_"}function tk(t){return t.length===4&&t[0]==="_VIEWS_"&&t[2]==="_PANELS_"}const nk=k.observer(()=>i(s.Stack,{sx:{height:"100%"},p:"sm",children:i($l,{})})),rk=k.observer(()=>{const t=he().editor,e=t.path;return U_(e)?i(nk,{}):X_(e)?i(TS,{}):J_(e)?i(s.Box,{p:"xs",pl:20,children:i(kS,{id:e[1]})}):Z_(e)?i(B_,{id:e[1]}):H_(e)?i(L_,{id:e[1]}):ek(e)?i(s.Box,{p:"xs",pl:20,children:i(K_,{id:e[1]})}):tk(e)?i(t_,{viewID:e[1],panelID:e[3]}):i(s.Box,{children:t.path})}),ik=k.observer(()=>i(rk,{})),ak=k.observer(()=>{const t=he(),e=()=>{const n=new Date().getTime().toString(),r={id:n,key:n,label:n,order:t.content.filters.current.length+1,type:wi.TextInput,config:ts(),visibleInViewsIDs:["Main"],auto_submit:!1};t.content.filters.append(r),t.editor.setPath(["_FILTERS_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:e,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Filter"})}),sk=k.observer(({parentID:t})=>{const e=K();if(!t)return null;const n=e.views.findByID(t);return n?i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:()=>e.addANewPanel(n.id),sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Panel"}):null}),ok=k.observer(()=>{const t=he(),e=()=>{const n=new Date().getTime().toString(),r={id:n,name:n,type:ye.Postgresql,key:"",sql:""};t.content.queries.append(r),t.editor.setPath(["_QUERIES_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:e,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Query"})}),lk=k.observer(()=>{const t=he(),e=()=>{const n=new Date().getTime().toString(),r={key:n,value:""};t.content.sqlSnippets.append(r),t.editor.setPath(["_SQL_SNIPPETS_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:e,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a SQL Snippet"})}),uk=k.observer(()=>{const t=K();return i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a View"})}),ck=k.observer(({action_type:t,parentID:e})=>(K(),t==="_Add_A_Filter_"?i(ak,{}):t==="_Add_A_SQL_SNIPPET_"?i(lk,{}):t==="_Add_A_QUERY_"?i(ok,{}):t==="_Add_A_VIEW_"?i(uk,{}):t==="_Add_A_PANEL_"?i(sk,{parentID:e}):null)),Pl=k.observer(({option:t})=>{var d;const e=he().editor,n=e.isOptionActive,r=n(e.path,t),a=e.isOptionOpened,o=e.navigate,l=a(t),[u,c]=y.useState(l);return y.useEffect(()=>{c(l)},[l]),i(s.NavLink,{active:r,defaultOpened:l,opened:u,onChange:c,label:t.label,onClick:()=>o(t),icon:t.Icon?i(t.Icon,{size:18}):null,children:(d=t.children)==null?void 0:d.map(f=>f._type==="ACTION"?i(ck,{action_type:f._action_type,parentID:f.parentID},`_ADD_${f.value}_`):i(Pl,{option:f},f.value))},t.label)}),dk=k.observer(()=>{const t=he();return i(s.Box,{sx:{position:"relative"},children:t.editor.navOptions.map(e=>i(Pl,{option:e},e.value))})}),pk=k.observer(()=>{const t=he();return p(s.Navbar,{p:0,width:{base:200,xs:200,sm:220,md:240,lg:280,xl:300},sx:{height:"100vh - 60px - 60px"},children:[i(s.Navbar.Section,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Settings"})}),i(s.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:i(dk,{})}),i(s.Navbar.Section,{children:i(s.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:i(s.Button,{size:"xs",color:"red",leftIcon:i(L.IconX,{size:18}),onClick:()=>t.editor.close(),children:"Close"})})})]})}),hk={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1,nav:{top:0,height:"100vh"}},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:0,height:"100vh"}},fk=k.observer(()=>{const t=he().editor;return i(s.Modal,{onClose:()=>t.setSettingsOpen(!1),closeOnEscape:!1,closeOnClickOutside:!1,opened:t.settings_open,fullScreen:!0,title:null,transitionProps:{duration:0},withCloseButton:!1,withinPortal:!0,zIndex:300,styles:{body:{padding:"0 !important"}},children:i(s.AppShell,{padding:0,navbar:i(pk,{}),styles:hk,children:i(ik,{})})})}),gk=t=>t.replace(/([^:])(\/\/+)/g,"$1/");function mk(t){y.useEffect(()=>{if(Ie.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const n=gk(t);Ie.loader.config({paths:{vs:n}}),Ie.loader.init().then(r=>console.log("monaco instance:",r))},[])}Ns();const yk={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},bk=({context:t,dashboard:e,content:n,update:r,className:a="dashboard",config:o,onChange:l,headerSlot:u,headerMenuItems:c},d)=>{mk(o.monacoPath),Wa(o);const{data:f=[]}=X.useRequest(fr),{data:h=[]}=X.useRequest(ja),[g,m]=y.useState(!1),w=y.useMemo(()=>_i(e,n,f,h,t),[e,n]);y.useImperativeHandle(d,()=>w,[w]),Qa(w.content,!0),y.useEffect(()=>{w.context.replace(t)},[t]),y.useEffect(()=>{w.datasources.replace(f)},[f]),y.useEffect(()=>{w.globalSQLSnippets.replace(h)},[h]),y.useEffect(()=>ie.reaction(()=>ie.toJS(w.json),I=>{l==null||l(I)}),[w]);const C=async()=>{await r(w.json,w.content.json)},_=X.useCreation(mi,[]),T=Di(_);return i(Ue.ModalsProvider,{children:i(mr,{value:w,children:i(gr,{value:w.content,children:i(ft.Provider,{value:{layoutFrozen:g,freezeLayout:m,inEditMode:!0},children:i(at.Provider,{value:_,children:p(Hn,{configure:T,children:[i(s.AppShell,{padding:0,header:i(B1,{saveDashboardChanges:C,headerSlot:u,headerMenuItems:c}),navbar:i(cS,{}),styles:yk,children:i(s.Box,{className:`${a} dashboard-root`,sx:{position:"relative"},children:w.content.views.visibleViews.map(I=>i(xl,{view:I},I.id))})}),i(fk,{})]})})})})})})},vk=k.observer(y.forwardRef(bk)),kD="";Ns();const xk=k.observer(({context:t,dashboard:e,content:n,className:r="dashboard",config:a,fullScreenPanelID:o,setFullScreenPanelID:l})=>{Wa(a);const{data:u=[]}=X.useRequest(fr),{data:c=[]}=X.useRequest(ja),d=y.useMemo(()=>_i(e,n,u,c,t),[e,n]);Qa(d.content,!1),y.useEffect(()=>{d.context.replace(t)},[t]),y.useEffect(()=>{d.datasources.replace(u)},[u]),y.useEffect(()=>{d.globalSQLSnippets.replace(c)},[c]);const f=X.useCreation(mi,[]),h=Di(f);return i(Ue.ModalsProvider,{children:i(mr,{value:d,children:i(gr,{value:d.content,children:i(Sr.Provider,{value:{fullScreenPanelID:o,setFullScreenPanelID:l},children:i(ft.Provider,{value:{layoutFrozen:!0,freezeLayout:x.noop,inEditMode:!1},children:i(s.Box,{className:`${r} dashboard-root`,children:i(at.Provider,{value:f,children:i(Hn,{configure:h,children:d.content.views.visibleViews.map(g=>i(nr,{view:g},g.id))})})})})})})})})});var Pi={},wk={get exports(){return Pi},set exports(t){Pi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){var a=r.prototype,o=a.format;a.format=function(l){var u=this,c=this.$locale();if(!this.isValid())return o.bind(this)(l);var d=this.$utils(),f=(l||"YYYY-MM-DDTHH:mm:ssZ").replace(/\[([^\]]+)]|Q|wo|ww|w|WW|W|zzz|z|gggg|GGGG|Do|X|x|k{1,2}|S/g,function(h){switch(h){case"Q":return Math.ceil((u.$M+1)/3);case"Do":return c.ordinal(u.$D);case"gggg":return u.weekYear();case"GGGG":return u.isoWeekYear();case"wo":return c.ordinal(u.week(),"W");case"w":case"ww":return d.s(u.week(),h==="w"?1:2,"0");case"W":case"WW":return d.s(u.isoWeek(),h==="W"?1:2,"0");case"k":case"kk":return d.s(String(u.$H===0?24:u.$H),h==="k"?1:2,"0");case"X":return Math.floor(u.$d.getTime()/1e3);case"x":return u.$d.getTime();case"z":return"["+u.offsetName()+"]";case"zzz":return"["+u.offsetName("long")+"]";default:return h}});return o.bind(this)(f)}}})})(wk);const Ck=Pi;var Bi={},Sk={get exports(){return Bi},set exports(t){Bi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){var o=r.prototype,l=function(c){var d=c.date,f=c.utc;return Array.isArray(d)?f?d.length?new Date(Date.UTC.apply(null,d)):new Date:d.length===1?a(String(d[0])).toDate():new(Function.prototype.bind.apply(Date,[null].concat(d))):d},u=o.parse;o.parse=function(c){c.date=l.bind(this)(c),u.bind(this)(c)}}})})(Sk);const _k=Bi;var Vi={},kk={get exports(){return Vi},set exports(t){Vi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){var a=r.prototype;a.$g=function(g,m,w){return this.$utils().u(g)?this[m]:this.$set(w,g)},a.set=function(g,m){return this.$set(g,m)};var o=a.startOf;a.startOf=function(g,m){return this.$d=o.bind(this)(g,m).toDate(),this.init(),this};var l=a.add;a.add=function(g,m){return this.$d=l.bind(this)(g,m).toDate(),this.init(),this};var u=a.locale;a.locale=function(g,m){return g?(this.$L=u.bind(this)(g,m).$L,this):this.$L};var c=a.daysInMonth;a.daysInMonth=function(){return c.bind(this.clone())()};var d=a.isSame;a.isSame=function(g,m){return d.bind(this.clone())(g,m)};var f=a.isBefore;a.isBefore=function(g,m){return f.bind(this.clone())(g,m)};var h=a.isAfter;a.isAfter=function(g,m){return h.bind(this.clone())(g,m)}}})})(kk);const Tk=Vi;var Ni={},Dk={get exports(){return Ni},set exports(t){Ni=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){var a=r.prototype,o=a.format;a.format=function(l){var u=this,c=(l||"YYYY-MM-DDTHH:mm:ssZ").replace(/(\[[^\]]+])|BBBB|BB/g,function(d,f){var h,g=String(u.$y+543),m=d==="BB"?[g.slice(-2),2]:[g,4];return f||(h=u.$utils()).s.apply(h,m.concat(["0"]))});return o.bind(this)(c)}}})})(Dk);const Mk=Ni;var qi={},Ik={get exports(){return qi},set exports(t){qi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){var o="h:mm A",l={lastDay:"[Yesterday at] "+o,sameDay:"[Today at] "+o,nextDay:"[Tomorrow at] "+o,nextWeek:"dddd [at] "+o,lastWeek:"[Last] dddd [at] "+o,sameElse:"MM/DD/YYYY"};r.prototype.calendar=function(u,c){var d=c||this.$locale().calendar||l,f=a(u||void 0).startOf("d"),h=this.diff(f,"d",!0),g="sameElse",m=h<-6?g:h<-1?"lastWeek":h<0?"lastDay":h<1?"sameDay":h<2?"nextDay":h<7?"nextWeek":g,w=d[m]||l[m];return typeof w=="function"?w.call(this,a()):this.format(w)}}})})(Ik);const Ek=qi;var Fi={},Ak={get exports(){return Fi},set exports(t){Fi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},r=/(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,a=/\d\d/,o=/\d\d?/,l=/\d*[^-_:/,()\s\d]+/,u={},c=function(C){return(C=+C)+(C>68?1900:2e3)},d=function(C){return function(_){this[C]=+_}},f=[/[+-]\d\d:?(\d\d)?|Z/,function(C){(this.zone||(this.zone={})).offset=function(_){if(!_||_==="Z")return 0;var T=_.match(/([+-]|\d\d)/g),I=60*T[1]+(+T[2]||0);return I===0?0:T[0]==="+"?-I:I}(C)}],h=function(C){var _=u[C];return _&&(_.indexOf?_:_.s.concat(_.f))},g=function(C,_){var T,I=u.meridiem;if(I){for(var O=1;O<=24;O+=1)if(C.indexOf(I(O,0,_))>-1){T=O>12;break}}else T=C===(_?"pm":"PM");return T},m={A:[l,function(C){this.afternoon=g(C,!1)}],a:[l,function(C){this.afternoon=g(C,!0)}],S:[/\d/,function(C){this.milliseconds=100*+C}],SS:[a,function(C){this.milliseconds=10*+C}],SSS:[/\d{3}/,function(C){this.milliseconds=+C}],s:[o,d("seconds")],ss:[o,d("seconds")],m:[o,d("minutes")],mm:[o,d("minutes")],H:[o,d("hours")],h:[o,d("hours")],HH:[o,d("hours")],hh:[o,d("hours")],D:[o,d("day")],DD:[a,d("day")],Do:[l,function(C){var _=u.ordinal,T=C.match(/\d+/);if(this.day=T[0],_)for(var I=1;I<=31;I+=1)_(I).replace(/\[|\]/g,"")===C&&(this.day=I)}],M:[o,d("month")],MM:[a,d("month")],MMM:[l,function(C){var _=h("months"),T=(h("monthsShort")||_.map(function(I){return I.slice(0,3)})).indexOf(C)+1;if(T<1)throw new Error;this.month=T%12||T}],MMMM:[l,function(C){var _=h("months").indexOf(C)+1;if(_<1)throw new Error;this.month=_%12||_}],Y:[/[+-]?\d+/,d("year")],YY:[a,function(C){this.year=c(C)}],YYYY:[/\d{4}/,d("year")],Z:f,ZZ:f};function w(C){var _,T;_=C,T=u&&u.formats;for(var I=(C=_.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(U,Y,Z){var oe=Z&&Z.toUpperCase();return Y||T[Z]||n[Z]||T[oe].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(ue,be,De){return be||De.slice(1)})})).match(r),O=I.length,B=0;B<O;B+=1){var $=I[B],A=m[$],E=A&&A[0],F=A&&A[1];I[B]=F?{regex:E,parser:F}:$.replace(/^\[|\]$/g,"")}return function(U){for(var Y={},Z=0,oe=0;Z<O;Z+=1){var ue=I[Z];if(typeof ue=="string")oe+=ue.length;else{var be=ue.regex,De=ue.parser,ge=U.slice(oe),xe=be.exec(ge)[0];De.call(Y,xe),U=U.replace(xe,"")}}return function(me){var Oe=me.afternoon;if(Oe!==void 0){var Qe=me.hours;Oe?Qe<12&&(me.hours+=12):Qe===12&&(me.hours=0),delete me.afternoon}}(Y),Y}}return function(C,_,T){T.p.customParseFormat=!0,C&&C.parseTwoDigitYear&&(c=C.parseTwoDigitYear);var I=_.prototype,O=I.parse;I.parse=function(B){var $=B.date,A=B.utc,E=B.args;this.$u=A;var F=E[1];if(typeof F=="string"){var U=E[2]===!0,Y=E[3]===!0,Z=U||Y,oe=E[2];Y&&(oe=E[2]),u=this.$locale(),!U&&oe&&(u=T.Ls[oe]),this.$d=function(ge,xe,me){try{if(["x","X"].indexOf(xe)>-1)return new Date((xe==="X"?1e3:1)*ge);var Oe=w(xe)(ge),Qe=Oe.year,At=Oe.month,or=Oe.day,lr=Oe.hours,ma=Oe.minutes,ya=Oe.seconds,ln=Oe.milliseconds,Ft=Oe.zone,wt=new Date,zt=or||(Qe||At?1:wt.getDate()),Ct=Qe||wt.getFullYear(),Gt=0;Qe&&!At||(Gt=At>0?At-1:wt.getMonth());var Wt=lr||0,un=ma||0,cn=ya||0,St=ln||0;return Ft?new Date(Date.UTC(Ct,Gt,zt,Wt,un,cn,St+60*Ft.offset*1e3)):me?new Date(Date.UTC(Ct,Gt,zt,Wt,un,cn,St)):new Date(Ct,Gt,zt,Wt,un,cn,St)}catch{return new Date("")}}($,F,A),this.init(),oe&&oe!==!0&&(this.$L=this.locale(oe).$L),Z&&$!=this.format(F)&&(this.$d=new Date("")),u={}}else if(F instanceof Array)for(var ue=F.length,be=1;be<=ue;be+=1){E[1]=F[be-1];var De=T.apply(this,E);if(De.isValid()){this.$d=De.$d,this.$L=De.$L,this.init();break}be===ue&&(this.$d=new Date(""))}else O.call(this,B)}}})})(Ak);const zk=Fi;var Gi={},$k={get exports(){return Gi},set exports(t){Gi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){r.prototype.dayOfYear=function(o){var l=Math.round((a(this).startOf("day")-a(this).startOf("year"))/864e5)+1;return o==null?l:this.add(o-l,"day")}}})})($k);const Lk=Gi;var Wi={},Ok={get exports(){return Wi},set exports(t){Wi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n,r,a=1e3,o=6e4,l=36e5,u=864e5,c=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,d=31536e6,f=2592e6,h=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,g={years:d,months:f,days:u,hours:l,minutes:o,seconds:a,milliseconds:1,weeks:6048e5},m=function($){return $ instanceof B},w=function($,A,E){return new B($,E,A.$l)},C=function($){return r.p($)+"s"},_=function($){return $<0},T=function($){return _($)?Math.ceil($):Math.floor($)},I=function($){return Math.abs($)},O=function($,A){return $?_($)?{negative:!0,format:""+I($)+A}:{negative:!1,format:""+$+A}:{negative:!1,format:""}},B=function(){function $(E,F,U){var Y=this;if(this.$d={},this.$l=U,E===void 0&&(this.$ms=0,this.parseFromMilliseconds()),F)return w(E*g[C(F)],this);if(typeof E=="number")return this.$ms=E,this.parseFromMilliseconds(),this;if(typeof E=="object")return Object.keys(E).forEach(function(ue){Y.$d[C(ue)]=E[ue]}),this.calMilliseconds(),this;if(typeof E=="string"){var Z=E.match(h);if(Z){var oe=Z.slice(2).map(function(ue){return ue!=null?Number(ue):0});return this.$d.years=oe[0],this.$d.months=oe[1],this.$d.weeks=oe[2],this.$d.days=oe[3],this.$d.hours=oe[4],this.$d.minutes=oe[5],this.$d.seconds=oe[6],this.calMilliseconds(),this}}return this}var A=$.prototype;return A.calMilliseconds=function(){var E=this;this.$ms=Object.keys(this.$d).reduce(function(F,U){return F+(E.$d[U]||0)*g[U]},0)},A.parseFromMilliseconds=function(){var E=this.$ms;this.$d.years=T(E/d),E%=d,this.$d.months=T(E/f),E%=f,this.$d.days=T(E/u),E%=u,this.$d.hours=T(E/l),E%=l,this.$d.minutes=T(E/o),E%=o,this.$d.seconds=T(E/a),E%=a,this.$d.milliseconds=E},A.toISOString=function(){var E=O(this.$d.years,"Y"),F=O(this.$d.months,"M"),U=+this.$d.days||0;this.$d.weeks&&(U+=7*this.$d.weeks);var Y=O(U,"D"),Z=O(this.$d.hours,"H"),oe=O(this.$d.minutes,"M"),ue=this.$d.seconds||0;this.$d.milliseconds&&(ue+=this.$d.milliseconds/1e3);var be=O(ue,"S"),De=E.negative||F.negative||Y.negative||Z.negative||oe.negative||be.negative,ge=Z.format||oe.format||be.format?"T":"",xe=(De?"-":"")+"P"+E.format+F.format+Y.format+ge+Z.format+oe.format+be.format;return xe==="P"||xe==="-P"?"P0D":xe},A.toJSON=function(){return this.toISOString()},A.format=function(E){var F=E||"YYYY-MM-DDTHH:mm:ss",U={Y:this.$d.years,YY:r.s(this.$d.years,2,"0"),YYYY:r.s(this.$d.years,4,"0"),M:this.$d.months,MM:r.s(this.$d.months,2,"0"),D:this.$d.days,DD:r.s(this.$d.days,2,"0"),H:this.$d.hours,HH:r.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:r.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:r.s(this.$d.seconds,2,"0"),SSS:r.s(this.$d.milliseconds,3,"0")};return F.replace(c,function(Y,Z){return Z||String(U[Y])})},A.as=function(E){return this.$ms/g[C(E)]},A.get=function(E){var F=this.$ms,U=C(E);return U==="milliseconds"?F%=1e3:F=U==="weeks"?T(F/g[U]):this.$d[U],F===0?0:F},A.add=function(E,F,U){var Y;return Y=F?E*g[C(F)]:m(E)?E.$ms:w(E,this).$ms,w(this.$ms+Y*(U?-1:1),this)},A.subtract=function(E,F){return this.add(E,F,!0)},A.locale=function(E){var F=this.clone();return F.$l=E,F},A.clone=function(){return w(this.$ms,this)},A.humanize=function(E){return n().add(this.$ms,"ms").locale(this.$l).fromNow(!E)},A.milliseconds=function(){return this.get("milliseconds")},A.asMilliseconds=function(){return this.as("milliseconds")},A.seconds=function(){return this.get("seconds")},A.asSeconds=function(){return this.as("seconds")},A.minutes=function(){return this.get("minutes")},A.asMinutes=function(){return this.as("minutes")},A.hours=function(){return this.get("hours")},A.asHours=function(){return this.as("hours")},A.days=function(){return this.get("days")},A.asDays=function(){return this.as("days")},A.weeks=function(){return this.get("weeks")},A.asWeeks=function(){return this.as("weeks")},A.months=function(){return this.get("months")},A.asMonths=function(){return this.as("months")},A.years=function(){return this.get("years")},A.asYears=function(){return this.as("years")},$}();return function($,A,E){n=E,r=E().$utils(),E.duration=function(Y,Z){var oe=E.locale();return w(Y,{$l:oe},Z)},E.isDuration=m;var F=A.prototype.add,U=A.prototype.subtract;A.prototype.add=function(Y,Z){return m(Y)&&(Y=Y.asMilliseconds()),F.bind(this)(Y,Z)},A.prototype.subtract=function(Y,Z){return m(Y)&&(Y=Y.asMilliseconds()),U.bind(this)(Y,Z)}}})})(Ok);const Pk=Wi;var ji={},Bk={get exports(){return ji},set exports(t){ji=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){r.prototype.isBetween=function(o,l,u,c){var d=a(o),f=a(l),h=(c=c||"()")[0]==="(",g=c[1]===")";return(h?this.isAfter(d,u):!this.isBefore(d,u))&&(g?this.isBefore(f,u):!this.isAfter(f,u))||(h?this.isBefore(d,u):!this.isAfter(d,u))&&(g?this.isAfter(f,u):!this.isBefore(f,u))}}})})(Bk);const Vk=ji;var Ri={},Nk={get exports(){return Ri},set exports(t){Ri=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.isLeapYear=function(){return this.$y%4==0&&this.$y%100!=0||this.$y%400==0}}})})(Nk);const qk=Ri;var Yi={},Fk={get exports(){return Yi},set exports(t){Yi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){a.isMoment=function(o){return a.isDayjs(o)}}})})(Fk);const Gk=Yi;var Qi={},Wk={get exports(){return Qi},set exports(t){Qi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n="day";return function(r,a,o){var l=function(d){return d.add(4-d.isoWeekday(),n)},u=a.prototype;u.isoWeekYear=function(){return l(this).year()},u.isoWeek=function(d){if(!this.$utils().u(d))return this.add(7*(d-this.isoWeek()),n);var f,h,g,m,w=l(this),C=(f=this.isoWeekYear(),h=this.$u,g=(h?o.utc:o)().year(f).startOf("year"),m=4-g.isoWeekday(),g.isoWeekday()>4&&(m+=7),g.add(m,n));return w.diff(C,"week")+1},u.isoWeekday=function(d){return this.$utils().u(d)?this.day()||7:this.day(this.day()%7?d:d-7)};var c=u.startOf;u.startOf=function(d,f){var h=this.$utils(),g=!!h.u(f)||f;return h.p(d)==="isoweek"?g?this.date(this.date()-(this.isoWeekday()-1)).startOf("day"):this.date(this.date()-1-(this.isoWeekday()-1)+7).endOf("day"):c.bind(this)(d,f)}}})})(Wk);const jk=Qi;var Ki={},Rk={get exports(){return Ki},set exports(t){Ki=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.isoWeeksInYear=function(){var a=this.isLeapYear(),o=this.endOf("y").day();return o===4||a&&o===5?53:52}}})})(Rk);const Yk=Ki;var Ui={},Qk={get exports(){return Ui},set exports(t){Ui=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.isSameOrAfter=function(a,o){return this.isSame(a,o)||this.isAfter(a,o)}}})})(Qk);const Kk=Ui;var Xi={},Uk={get exports(){return Xi},set exports(t){Xi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.isSameOrBefore=function(a,o){return this.isSame(a,o)||this.isBefore(a,o)}}})})(Uk);const Xk=Xi;var Ji={},Jk={get exports(){return Ji},set exports(t){Ji=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){r.prototype.isToday=function(){var o="YYYY-MM-DD",l=a();return this.format(o)===l.format(o)}}})})(Jk);const Zk=Ji;var Zi={},Hk={get exports(){return Zi},set exports(t){Zi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){r.prototype.isTomorrow=function(){var o="YYYY-MM-DD",l=a().add(1,"day");return this.format(o)===l.format(o)}}})})(Hk);const eT=Zi;var Hi={},tT={get exports(){return Hi},set exports(t){Hi=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){r.prototype.isYesterday=function(){var o="YYYY-MM-DD",l=a().subtract(1,"day");return this.format(o)===l.format(o)}}})})(tT);const nT=Hi;var ea={},rT={get exports(){return ea},set exports(t){ea=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){var o=r.prototype,l=function(h){return h&&(h.indexOf?h:h.s)},u=function(h,g,m,w,C){var _=h.name?h:h.$locale(),T=l(_[g]),I=l(_[m]),O=T||I.map(function($){return $.slice(0,w)});if(!C)return O;var B=_.weekStart;return O.map(function($,A){return O[(A+(B||0))%7]})},c=function(){return a.Ls[a.locale()]},d=function(h,g){return h.formats[g]||function(m){return m.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(w,C,_){return C||_.slice(1)})}(h.formats[g.toUpperCase()])},f=function(){var h=this;return{months:function(g){return g?g.format("MMMM"):u(h,"months")},monthsShort:function(g){return g?g.format("MMM"):u(h,"monthsShort","months",3)},firstDayOfWeek:function(){return h.$locale().weekStart||0},weekdays:function(g){return g?g.format("dddd"):u(h,"weekdays")},weekdaysMin:function(g){return g?g.format("dd"):u(h,"weekdaysMin","weekdays",2)},weekdaysShort:function(g){return g?g.format("ddd"):u(h,"weekdaysShort","weekdays",3)},longDateFormat:function(g){return d(h.$locale(),g)},meridiem:this.$locale().meridiem,ordinal:this.$locale().ordinal}};o.localeData=function(){return f.bind(this)()},a.localeData=function(){var h=c();return{firstDayOfWeek:function(){return h.weekStart||0},weekdays:function(){return a.weekdays()},weekdaysShort:function(){return a.weekdaysShort()},weekdaysMin:function(){return a.weekdaysMin()},months:function(){return a.months()},monthsShort:function(){return a.monthsShort()},longDateFormat:function(g){return d(h,g)},meridiem:h.meridiem,ordinal:h.ordinal}},a.months=function(){return u(c(),"months")},a.monthsShort=function(){return u(c(),"monthsShort","months",3)},a.weekdays=function(h){return u(c(),"weekdays",null,null,h)},a.weekdaysShort=function(h){return u(c(),"weekdaysShort","weekdays",3,h)},a.weekdaysMin=function(h){return u(c(),"weekdaysMin","weekdays",2,h)}}})})(rT);const iT=ea;var ta={},aT={get exports(){return ta},set exports(t){ta=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"};return function(r,a,o){var l=a.prototype,u=l.format;o.en.formats=n,l.format=function(c){c===void 0&&(c="YYYY-MM-DDTHH:mm:ssZ");var d=this.$locale().formats,f=function(h,g){return h.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(m,w,C){var _=C&&C.toUpperCase();return w||g[C]||n[C]||g[_].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(T,I,O){return I||O.slice(1)})})}(c,d===void 0?{}:d);return u.call(this,f)}}})})(aT);const sT=ta;var na={},oT={get exports(){return na},set exports(t){na=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){var o=function(l,u){if(!u||!u.length||!u[0]||u.length===1&&!u[0].length)return null;var c;u.length===1&&u[0].length>0&&(u=u[0]),c=u[0];for(var d=1;d<u.length;d+=1)u[d].isValid()&&!u[d][l](c)||(c=u[d]);return c};a.max=function(){var l=[].slice.call(arguments,0);return o("isAfter",l)},a.min=function(){var l=[].slice.call(arguments,0);return o("isBefore",l)}}})})(oT);const lT=na;var ra={},uT={get exports(){return ra},set exports(t){ra=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){var o=r.prototype,l=function(g){var m,w=g.date,C=g.utc,_={};if(!((m=w)instanceof Date||m instanceof Array||o.$utils().u(m)||m.constructor.name!=="Object")){if(!Object.keys(w).length)return new Date;var T=C?a.utc():a();Object.keys(w).forEach(function(U){var Y,Z;_[Y=U,Z=o.$utils().p(Y),Z==="date"?"day":Z]=w[U]});var I=_.day||(_.year||_.month>=0?1:T.date()),O=_.year||T.year(),B=_.month>=0?_.month:_.year||_.day?0:T.month(),$=_.hour||0,A=_.minute||0,E=_.second||0,F=_.millisecond||0;return C?new Date(Date.UTC(O,B,I,$,A,E,F)):new Date(O,B,I,$,A,E,F)}return w},u=o.parse;o.parse=function(g){g.date=l.bind(this)(g),u.bind(this)(g)};var c=o.set,d=o.add,f=o.subtract,h=function(g,m,w,C){C===void 0&&(C=1);var _=Object.keys(m),T=this;return _.forEach(function(I){T=g.bind(T)(m[I]*C,I)}),T};o.set=function(g,m){return m=m===void 0?g:m,g.constructor.name==="Object"?h.bind(this)(function(w,C){return c.bind(this)(C,w)},m,g):c.bind(this)(g,m)},o.add=function(g,m){return g.constructor.name==="Object"?h.bind(this)(d,g,m):d.bind(this)(g,m)},o.subtract=function(g,m){return g.constructor.name==="Object"?h.bind(this)(d,g,m,-1):f.bind(this)(g,m)}}})})(uT);const cT=ra;var ia={},dT={get exports(){return ia},set exports(t){ia=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){var a=r.prototype;["milliseconds","seconds","minutes","hours","days","weeks","isoWeeks","months","quarters","years","dates"].forEach(function(o){a[o]=a[o.replace(/s$/,"")]})}})})(dT);const pT=ia;var aa={},hT={get exports(){return aa},set exports(t){aa=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){var a=r.prototype.parse;r.prototype.parse=function(u){if(typeof u.date=="string"){var c=this.$locale();u.date=c&&c.preparse?c.preparse(u.date):u.date}return a.bind(this)(u)};var o=r.prototype.format;r.prototype.format=function(){for(var u=arguments.length,c=new Array(u),d=0;d<u;d++)c[d]=arguments[d];var f=o.call.apply(o,[this].concat(c)),h=this.$locale();return h&&h.postformat?h.postformat(f):f};var l=r.prototype.fromToBase;l&&(r.prototype.fromToBase=function(u,c,d,f){var h=this.$locale()||d.$locale();return l.call(this,u,c,d,f,h&&h.postformat)})}})})(hT);const fT=aa;var sa={},gT={get exports(){return sa},set exports(t){sa=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n="month",r="quarter";return function(a,o){var l=o.prototype;l.quarter=function(d){return this.$utils().u(d)?Math.ceil((this.month()+1)/3):this.month(this.month()%3+3*(d-1))};var u=l.add;l.add=function(d,f){return d=Number(d),this.$utils().p(f)===r?this.add(3*d,n):u.bind(this)(d,f)};var c=l.startOf;l.startOf=function(d,f){var h=this.$utils(),g=!!h.u(f)||f;if(h.p(d)===r){var m=this.quarter()-1;return g?this.month(3*m).startOf(n).startOf("day"):this.month(3*m+2).endOf(n).endOf("day")}return c.bind(this)(d,f)}}})})(gT);const mT=sa;var oa={},yT={get exports(){return oa},set exports(t){oa=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){n=n||{};var o=r.prototype,l={future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"};function u(d,f,h,g){return o.fromToBase(d,f,h,g)}a.en.relativeTime=l,o.fromToBase=function(d,f,h,g,m){for(var w,C,_,T=h.$locale().relativeTime||l,I=n.thresholds||[{l:"s",r:44,d:"second"},{l:"m",r:89},{l:"mm",r:44,d:"minute"},{l:"h",r:89},{l:"hh",r:21,d:"hour"},{l:"d",r:35},{l:"dd",r:25,d:"day"},{l:"M",r:45},{l:"MM",r:10,d:"month"},{l:"y",r:17},{l:"yy",d:"year"}],O=I.length,B=0;B<O;B+=1){var $=I[B];$.d&&(w=g?a(d).diff(h,$.d,!0):h.diff(d,$.d,!0));var A=(n.rounding||Math.round)(Math.abs(w));if(_=w>0,A<=$.r||!$.r){A<=1&&B>0&&($=I[B-1]);var E=T[$.l];m&&(A=m(""+A)),C=typeof E=="string"?E.replace("%d",A):E(A,f,$.l,_);break}}if(f)return C;var F=_?T.future:T.past;return typeof F=="function"?F(C):F.replace("%s",C)},o.to=function(d,f){return u(d,f,this,!0)},o.from=function(d,f){return u(d,f,this)};var c=function(d){return d.$u?a.utc():a()};o.toNow=function(d){return this.to(c(this),d)},o.fromNow=function(d){return this.from(c(this),d)}}})})(yT);const bT=oa;var la={},vT={get exports(){return la},set exports(t){la=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n={year:0,month:1,day:2,hour:3,minute:4,second:5},r={};return function(a,o,l){var u,c=function(g,m,w){w===void 0&&(w={});var C=new Date(g),_=function(T,I){I===void 0&&(I={});var O=I.timeZoneName||"short",B=T+"|"+O,$=r[B];return $||($=new Intl.DateTimeFormat("en-US",{hour12:!1,timeZone:T,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:O}),r[B]=$),$}(m,w);return _.formatToParts(C)},d=function(g,m){for(var w=c(g,m),C=[],_=0;_<w.length;_+=1){var T=w[_],I=T.type,O=T.value,B=n[I];B>=0&&(C[B]=parseInt(O,10))}var $=C[3],A=$===24?0:$,E=C[0]+"-"+C[1]+"-"+C[2]+" "+A+":"+C[4]+":"+C[5]+":000",F=+g;return(l.utc(E).valueOf()-(F-=F%1e3))/6e4},f=o.prototype;f.tz=function(g,m){g===void 0&&(g=u);var w=this.utcOffset(),C=this.toDate(),_=C.toLocaleString("en-US",{timeZone:g}),T=Math.round((C-new Date(_))/1e3/60),I=l(_).$set("millisecond",this.$ms).utcOffset(15*-Math.round(C.getTimezoneOffset()/15)-T,!0);if(m){var O=I.utcOffset();I=I.add(w-O,"minute")}return I.$x.$timezone=g,I},f.offsetName=function(g){var m=this.$x.$timezone||l.tz.guess(),w=c(this.valueOf(),m,{timeZoneName:g}).find(function(C){return C.type.toLowerCase()==="timezonename"});return w&&w.value};var h=f.startOf;f.startOf=function(g,m){if(!this.$x||!this.$x.$timezone)return h.call(this,g,m);var w=l(this.format("YYYY-MM-DD HH:mm:ss:SSS"));return h.call(w,g,m).tz(this.$x.$timezone,!0)},l.tz=function(g,m,w){var C=w&&m,_=w||m||u,T=d(+l(),_);if(typeof g!="string")return l(g).tz(_);var I=function(A,E,F){var U=A-60*E*1e3,Y=d(U,F);if(E===Y)return[U,E];var Z=d(U-=60*(Y-E)*1e3,F);return Y===Z?[U,Y]:[A-60*Math.min(Y,Z)*1e3,Math.max(Y,Z)]}(l.utc(g,C).valueOf(),T,_),O=I[0],B=I[1],$=l(O).utcOffset(B);return $.$x.$timezone=_,$},l.tz.guess=function(){return Intl.DateTimeFormat().resolvedOptions().timeZone},l.tz.setDefault=function(g){u=g}}})})(vT);const xT=la;var ua={},wT={get exports(){return ua},set exports(t){ua=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.toArray=function(){return[this.$y,this.$M,this.$D,this.$H,this.$m,this.$s,this.$ms]}}})})(wT);const CT=ua;var ca={},ST={get exports(){return ca},set exports(t){ca=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.toObject=function(){return{years:this.$y,months:this.$M,date:this.$D,hours:this.$H,minutes:this.$m,seconds:this.$s,milliseconds:this.$ms}}}})})(ST);const _T=ca;var da={},kT={get exports(){return da},set exports(t){da=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r,a){a.updateLocale=function(o,l){var u=a.Ls[o];if(u)return(l?Object.keys(l):[]).forEach(function(c){u[c]=l[c]}),u}}})})(kT);const TT=da;var pa={},DT={get exports(){return pa},set exports(t){pa=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n="minute",r=/[+-]\d\d(?::?\d\d)?/g,a=/([+-]|\d\d)/g;return function(o,l,u){var c=l.prototype;u.utc=function(C){var _={date:C,utc:!0,args:arguments};return new l(_)},c.utc=function(C){var _=u(this.toDate(),{locale:this.$L,utc:!0});return C?_.add(this.utcOffset(),n):_},c.local=function(){return u(this.toDate(),{locale:this.$L,utc:!1})};var d=c.parse;c.parse=function(C){C.utc&&(this.$u=!0),this.$utils().u(C.$offset)||(this.$offset=C.$offset),d.call(this,C)};var f=c.init;c.init=function(){if(this.$u){var C=this.$d;this.$y=C.getUTCFullYear(),this.$M=C.getUTCMonth(),this.$D=C.getUTCDate(),this.$W=C.getUTCDay(),this.$H=C.getUTCHours(),this.$m=C.getUTCMinutes(),this.$s=C.getUTCSeconds(),this.$ms=C.getUTCMilliseconds()}else f.call(this)};var h=c.utcOffset;c.utcOffset=function(C,_){var T=this.$utils().u;if(T(C))return this.$u?0:T(this.$offset)?h.call(this):this.$offset;if(typeof C=="string"&&(C=function($){$===void 0&&($="");var A=$.match(r);if(!A)return null;var E=(""+A[0]).match(a)||["-",0,0],F=E[0],U=60*+E[1]+ +E[2];return U===0?0:F==="+"?U:-U}(C),C===null))return this;var I=Math.abs(C)<=16?60*C:C,O=this;if(_)return O.$offset=I,O.$u=C===0,O;if(C!==0){var B=this.$u?this.toDate().getTimezoneOffset():-1*this.utcOffset();(O=this.local().add(I+B,n)).$offset=I,O.$x.$localOffset=B}else O=this.utc();return O};var g=c.format;c.format=function(C){var _=C||(this.$u?"YYYY-MM-DDTHH:mm:ss[Z]":"");return g.call(this,_)},c.valueOf=function(){var C=this.$utils().u(this.$offset)?0:this.$offset+(this.$x.$localOffset||this.$d.getTimezoneOffset());return this.$d.valueOf()-6e4*C},c.isUTC=function(){return!!this.$u},c.toISOString=function(){return this.toDate().toISOString()},c.toString=function(){return this.toDate().toUTCString()};var m=c.toDate;c.toDate=function(C){return C==="s"&&this.$offset?u(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate():m.call(this)};var w=c.diff;c.diff=function(C,_,T){if(C&&this.$u===C.$u)return w.call(this,C,_,T);var I=this.local(),O=u(C).local();return w.call(I,O,_,T)}}})})(DT);const MT=pa;var ha={},IT={get exports(){return ha},set exports(t){ha=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.weekday=function(a){var o=this.$locale().weekStart||0,l=this.$W,u=(l<o?l+7:l)-o;return this.$utils().u(a)?u:this.subtract(u,"day").add(a,"day")}}})})(IT);const ET=ha;var fa={},AT={get exports(){return fa},set exports(t){fa=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){var n="week",r="year";return function(a,o,l){var u=o.prototype;u.week=function(c){if(c===void 0&&(c=null),c!==null)return this.add(7*(c-this.week()),"day");var d=this.$locale().yearStart||1;if(this.month()===11&&this.date()>25){var f=l(this).startOf(r).add(1,r).date(d),h=l(this).endOf(n);if(f.isBefore(h))return 1}var g=l(this).startOf(r).date(d).startOf(n).subtract(1,"millisecond"),m=this.diff(g,n,!0);return m<0?l(this).startOf("week").week():Math.ceil(m)},u.weeks=function(c){return c===void 0&&(c=null),this.week(c)}}})})(AT);const zT=fa;var ga={},$T={get exports(){return ga},set exports(t){ga=t}};(function(t,e){(function(n,r){t.exports=r()})(ne,function(){return function(n,r){r.prototype.weekYear=function(){var a=this.month(),o=this.week(),l=this.year();return o===1&&a===11?l+1:a===0&&o>=52?l-1:l}}})})($T);const LT=ga;R.extend(Ck),R.extend(_k),R.extend(Tk),R.extend(Mk),R.extend(Ek),R.extend(zk),R.extend(Lk),R.extend(Pk),R.extend(Vk),R.extend(qk),R.extend(Gk),R.extend(Kk),R.extend(Xk),R.extend(Zk),R.extend(eT),R.extend(nT),R.extend(jk),R.extend(Yk),R.extend(iT),R.extend(sT),R.extend(lT),R.extend(cT),R.extend(pT),R.extend(fT),R.extend(mT),R.extend(bT),R.extend(xT),R.extend(CT),R.extend(_T),R.extend(TT),R.extend(MT),R.extend(zT),R.extend(LT),R.extend(ET),R.tz.setDefault("UTC");const OT=()=>Promise.resolve().then(()=>lc).then(({version:t})=>(console.log(`[@devtable/dashboard] version: ${t}`),t));M.ContentModel=Zn,M.ContentModelContextProvider=gr,M.ContextModel=hs,M.DashboardEditor=vk,M.DashboardFilterType=wi,M.DashboardMode=Zo,M.DashboardModel=ol,M.DashboardViewEditor=xl,M.DashboardViewRender=nr,M.EViewComponentType=H,M.FilterModel=br,M.FiltersModel=rs,M.FullScreenPanelContext=Sr,M.LayoutStateContext=ft,M.ModelContextProvider=mr,M.Panel=tr,M.PanelContextProvider=Cr,M.PanelModel=Uo,M.PanelsModel=Jo,M.QueriesModel=cs,M.QueryModel=us,M.ReadOnlyDashboard=xk,M.SQLSnippetModel=ds,M.SQLSnippetsModel=ps,M.ViewComponentTypeBackground=Ho,M.ViewComponentTypeColor=kC,M.ViewComponentTypeName=_C,M.ViewModel=rl,M.ViewsModel=il,M.applyPartialDashboard=$C,M.createContentModel=sl,M.createDashboardModel=_i,M.createDashboardViewsModel=Si,M.getInitialFiltersPayload=is,M.getNewPanel=Xo,M.getVersion=OT,M.initialDashboardContent=TC,M.useContentModelContext=K,M.useFullScreenPanelContext=ws,M.useModelContext=he,M.usePanelContext=ze,M.useTopLevelServices=Di,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})});
513
+ `)},sk=k.observer(({queryModel:e})=>e.typedAsSQL?p(s.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"Edit",children:i(s.Group,{spacing:14,position:"apart",children:"Edit SQL"})}),i(s.Tabs.Tab,{value:"Preview",children:"Preview SQL"}),i(s.Tabs.Tab,{value:"pre_process",children:"Process Request"}),i(s.Tabs.Tab,{value:"post_process",children:"Process Result"}),i(Bi,{}),e.datasource&&i(Xl,{dataSource:e.datasource})]}),i(s.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:i(rk,{value:e.sql,onChange:e.setSQL,defaultValue:"SELECT 1"})}),i(s.Tabs.Panel,{value:"Preview",p:0,pl:4,children:i(ak,{value:e.sql})}),i(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:i(or,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:Hl.pre})}),i(s.Tabs.Panel,{value:"post_process",p:"sm",children:i(or,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:Hl.post})})]}):null),lr={height:"calc(100% - 44px)",padding:0},ok=k.observer(({queryModel:e})=>{const t=ue(),n=b.useMemo(()=>e.datasource?e.typedAsHTTP?"HTTP":"SQL":"Configurations",[e.datasource,e.typedAsHTTP]),[r,a]=b.useState(n);b.useEffect(()=>{a(u=>u!=="Configurations"&&n==="Configurations"?"Configurations":u)},[n]);const o=t.findQueryUsage(e.id),l=o.length===0;return i(s.Stack,{sx:{flexGrow:1},my:0,p:0,children:p(s.Tabs,{value:r,onTabChange:a,defaultValue:n,orientation:"horizontal",keepMounted:!1,sx:{flexGrow:1},children:[p(s.Tabs.List,{grow:!0,children:[i(s.Tabs.Tab,{value:"Configurations",children:"Configurations"}),e.typedAsSQL&&i(s.Tabs.Tab,{value:"SQL",children:"Request"}),e.typedAsHTTP&&i(s.Tabs.Tab,{value:"HTTP",children:"Request"}),i(s.Tabs.Tab,{value:"Data",disabled:!e.datasource,children:i(s.Tooltip,{label:"Need to pick a Data Source first",disabled:e.datasource,withinPortal:!0,children:i(s.Text,{children:"Data"})})}),i(s.Tabs.Tab,{value:"Usage",disabled:l,children:i(s.Tooltip,{label:"This query is not used for any filter or panel",disabled:!l,withinPortal:!0,children:i(s.Text,{children:"Usage"})})})]}),i(s.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:i(U_,{queryModel:e})}),e.typedAsSQL&&i(s.Tabs.Panel,{value:"SQL",sx:lr,children:i(s.Stack,{sx:{height:"100%"},children:i(sk,{queryModel:e})})}),e.typedAsHTTP&&i(s.Tabs.Panel,{value:"HTTP",sx:lr,children:i(s.Stack,{sx:{height:"100%"},children:i(tk,{queryModel:e})})}),i(s.Tabs.Panel,{value:"Data",sx:{...lr,overflow:"hidden"},children:i(Oi,{id:e.id})}),i(s.Tabs.Panel,{value:"Usage",sx:{...lr,overflow:"hidden"},children:i(nk,{queryID:e.id,usage:o})})]})})}),lk=k.observer(({id:e})=>{const n=ue().queries.findByID(e);return e===""?null:n?i(s.Stack,{sx:{height:"100%"},spacing:"sm",children:i(ok,{queryModel:n})}):i(s.Text,{size:14,color:"red",children:"Invalid Query ID"})}),uk=k.observer(({value:e})=>{const n=Me().payloadForSQL,r=b.useMemo(()=>gr(e,n),[e,n]);return i(Vi,{height:"100%",value:r})}),ck=k.observer(({item:e,remove:t,onKeyChanged:n})=>{const[r,a]=b.useState("SQL"),[o,l]=b.useState(e.key),u=()=>{e.setKey(o),n(o)},c=o!==e.key,d=e.isADuplicatedKey(o),[f,h]=b.useState(e.value),g=()=>{e.setValue(f)};b.useEffect(()=>{l(e.key),h(e.value)},[e]);const m=f!==e.value,C=Ue.useModals(),w=()=>{C.openConfirmModal({title:"Delete this SQL snippet?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:t,confirmProps:{color:"red"},zIndex:320})};return p(s.Stack,{p:20,sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",children:[p(s.Group,{sx:{alignItems:"end"},spacing:40,children:[i(s.TextInput,{label:d?"This key is occupied by another snippet":"Key",value:o,onChange:_=>{l(_.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:i(s.ActionIcon,{color:"blue",variant:"subtle",onClick:u,disabled:!c||d,children:i(T.DeviceFloppy,{size:16})}),error:d}),i(s.Button,{leftIcon:i(T.Trash,{size:16}),color:"red",variant:"light",onClick:w,children:"Delete this SQL Snippet"})]}),p(s.Tabs,{value:r,onTabChange:a,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[p(s.Tabs.List,{sx:{position:"relative"},children:[i(s.Tabs.Tab,{value:"SQL",children:"SQL"}),i(s.Tabs.Tab,{value:"Preview",children:"Preview"}),i(Bi,{}),i(s.ActionIcon,{color:"blue",variant:"filled",onClick:g,disabled:!m,sx:{position:"absolute",top:0,right:10},children:i(T.DeviceFloppy,{size:18})})]}),i(s.Tabs.Panel,{value:"SQL",pt:"sm",children:i(Vi,{height:"100%",value:f,onChange:h,defaultLanguage:"sql",theme:"sql-dark"})}),i(s.Tabs.Panel,{value:"Preview",pt:"sm",children:i(uk,{value:f})})]})]})}),dk=k.observer(({id:e})=>{const t=me(),n=ue(),r=b.useMemo(()=>n.sqlSnippets.findByKey(e),[e]);if(!e)return null;if(!r)return p(s.Text,{size:14,children:["SQL Snippet by key[",e,"] is not found"]});const a=()=>{t.editor.setPath(["_SQL_SNIPPETS_",""])};return i(ck,{item:r,remove:()=>{n.sqlSnippets.removeByKey(e),a()},onKeyChanged:u=>{t.editor.setPath(["_SQL_SNIPPETS_",u])}})}),pk=k.observer(({view:e})=>!e||e.type!==Y.Division?null:p(s.Stack,{children:[i(s.Divider,{mt:8,mb:0,label:"Division settings",labelPosition:"center"}),i(s.Text,{align:"center",size:"xs",color:"dimmed",children:"Under construction"})]})),hk=[{value:"default",label:"Default"},{value:"outline",label:"Outline"},{value:"pills",label:"Pills"}],fk=[{value:"horizontal",label:"Horizontal"},{value:"vertical",label:"Vertical"}],gk=k.observer(({view:e})=>{if(!e||e.type!==Y.Tabs)return null;const t=e.config;return p(s.Stack,{children:[i(s.Divider,{mt:8,mb:0,label:"Tabs settings",labelPosition:"center"}),i(s.Select,{label:"Variant",value:t.variant,onChange:t.setVariant,data:hk}),i(s.Select,{label:"Orientation",value:t.orientation,onChange:t.setOrientation,data:fk}),i(s.Switch,{label:"Grow Tabs",checked:t.grow,onChange:n=>t.setGrow(n.currentTarget.checked)})]})}),mk=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Ae,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},yk=({value:e,onChange:t})=>{const[n,{setTrue:r,setFalse:a}]=X.useBoolean(),[o,l]=b.useState(e??_i),u=g=>{l({...o,enabled:g})},c=()=>{a();const{enabled:g,func_content:m}=o,C={enabled:g,func_content:m};l(C),t(C)},d=()=>{a(),l(e)},f=g=>{l(m=>({...m,func_content:g}))},h=()=>{f(_i.func_content)};return p(V,{children:[i(s.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:r,sx:{flexGrow:0},children:i(T.Settings,{size:14})}),i(s.Modal,{size:800,title:"Customize modal title",opened:n,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:n&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:o.enabled,onChange:g=>u(g.currentTarget.checked)}),i(mk,{value:o.func_content,onChange:f,disabled:!o.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:h,color:"red",leftIcon:i(T.Recycle,{size:20}),children:"Rest"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:c,children:"OK"})]})]})]})})]})},bk=k.observer(({view:e})=>{if(!e||e.type!==Y.Modal)return null;const t=e.config,n=t.custom_modal_title.value;return p(s.Stack,{children:[i(s.Divider,{mt:8,label:"Modal settings",labelPosition:"center"}),p(s.Flex,{gap:10,children:[i(s.TextInput,{label:"Modal Title",value:n,onChange:x.noop,disabled:!0,sx:{flexGrow:1}}),i(yk,{value:t.custom_modal_title,onChange:t.custom_modal_title.replace})]}),p(s.Group,{grow:!0,children:[i(s.TextInput,{label:"Width",value:t.width,onChange:r=>t.setWidth(r.currentTarget.value),placeholder:"600px / 50vw"}),i(s.TextInput,{label:"Height",value:t.height,onChange:r=>t.setHeight(r.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),vk=k.observer(({view:e})=>p(V,{children:[i(pk,{view:e}),i(bk,{view:e}),i(gk,{view:e})]})),xk=[{label:"Division",value:Y.Division},{label:"Modal",value:Y.Modal},{label:"Tabs",value:Y.Tabs}],wk=k.observer(({view:e})=>e?p(s.Stack,{sx:{position:"relative"},children:[i(s.TextInput,{label:"Name",value:e.name,onChange:t=>{e.setName(t.currentTarget.value)}}),i(s.Select,{label:"Type",withinPortal:!0,zIndex:320,value:e.type,onChange:e.setType,data:xk}),i(vk,{view:e})]}):null),Ck=k.observer(({id:e})=>{const t=Ue.useModals(),n=me(),r=ue();if(e==="")return null;const a=r.views.findByID(e);if(!a)return p(s.Text,{size:14,children:["View by ID[",e,"] is not found"]});const o=()=>{n.editor.setPath(["_VIEWS_",""])},l=()=>{t.openConfirmModal({title:"Delete this view?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.views.removeByID(e),o()},zIndex:320})};return p(s.Stack,{sx:{maxWidth:"600px",height:"100%"},spacing:"sm",children:[i(s.Group,{position:"right",pt:10,children:i(s.Button,{size:"xs",color:"red",leftIcon:i(T.Trash,{size:16}),onClick:l,children:"Delete this view"})}),i(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:i(wk,{view:a})})]})});function Sk(e){return e.length===1&&e[0]==="_QUERY_VARS_"}function _k(e){return e.length===1&&e[0]==="_MOCK_CONTEXT_"}function kk(e){return e.length===2&&e[0]==="_FILTERS_"}function Tk(e){return e.length===2&&e[0]==="_SQL_SNIPPETS_"}function Dk(e){return e.length===2&&e[0]==="_QUERIES_"}function Mk(e){return e.length===2&&e[0]==="_VIEWS_"}function Ik(e){return e.length===4&&e[0]==="_VIEWS_"&&e[2]==="_PANELS_"}const Ek=k.observer(()=>i(s.Stack,{sx:{height:"100%"},p:"sm",children:i(Jl,{})})),Ak=k.observer(()=>{const e=me().editor,t=e.path;return Sk(t)?i(Ek,{}):_k(t)?i(HS,{}):kk(t)?i(s.Box,{p:"xs",pl:20,children:i(ZS,{id:t[1]})}):Tk(t)?i(dk,{id:t[1]}):Dk(t)?i(lk,{id:t[1]}):Mk(t)?i(s.Box,{p:"xs",pl:20,children:i(Ck,{id:t[1]})}):Ik(t)?i(M_,{viewID:t[1],panelID:t[3]}):i(s.Box,{children:e.path})}),zk=k.observer(()=>i(Ak,{})),$k=k.observer(()=>{const e=me(),t=()=>{const n=new Date().getTime().toString(),r={id:n,key:n,label:n,order:e.content.filters.current.length+1,type:Te.TextInput,config:Qo(),visibleInViewsIDs:["Main"],auto_submit:!1};e.content.filters.append(r),e.editor.setPath(["_FILTERS_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Filter"})}),Lk=k.observer(({parentID:e})=>{const t=ue();if(!e)return null;const n=t.views.findByID(e);return n?i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:()=>t.addANewPanel(n.id),sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Panel"}):null}),Ok=k.observer(()=>{const e=me(),t=()=>{const n=new Date().getTime().toString(),r={id:n,name:n,type:Ce.Postgresql,key:"",sql:""};e.content.queries.append(r),e.editor.setPath(["_QUERIES_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Query"})}),Pk=k.observer(()=>{const e=me(),t=()=>{const n=new Date().getTime().toString(),r={key:n,value:""};e.content.sqlSnippets.append(r),e.editor.setPath(["_SQL_SNIPPETS_",n])};return i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a SQL Snippet"})}),Bk=k.observer(()=>{const e=ue();return i(s.Button,{variant:"subtle",leftIcon:i(L.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:e.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a View"})}),Vk=k.observer(({action_type:e,parentID:t})=>e==="_Add_A_Filter_"?i($k,{}):e==="_Add_A_SQL_SNIPPET_"?i(Pk,{}):e==="_Add_A_QUERY_"?i(Ok,{}):e==="_Add_A_VIEW_"?i(Bk,{}):e==="_Add_A_PANEL_"?i(Lk,{parentID:t}):null),eu=k.observer(({option:e})=>{var d;const t=me().editor,n=t.isOptionActive,r=n(t.path,e),a=t.isOptionOpened,o=t.navigate,l=a(e),[u,c]=b.useState(l);return b.useEffect(()=>{c(l)},[l]),i(s.NavLink,{active:r,defaultOpened:l,opened:u,onChange:c,label:e.label,onClick:()=>o(e),icon:e.Icon?i(e.Icon,{size:18}):null,children:(d=e.children)==null?void 0:d.map(f=>f._type==="ACTION"?i(Vk,{action_type:f._action_type,parentID:f.parentID},`_ADD_${f.value}_`):i(eu,{option:f},f.value))},e.label)}),Nk=k.observer(()=>{const e=me();return i(s.Box,{sx:{position:"relative"},children:e.editor.navOptions.map(t=>i(eu,{option:t},t.value))})}),qk=k.observer(()=>{const e=me();return p(s.Navbar,{p:0,width:{base:200,xs:200,sm:220,md:240,lg:280,xl:300},sx:{height:"100vh - 60px - 60px"},children:[i(s.Navbar.Section,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:i(s.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Settings"})}),i(s.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:i(Nk,{})}),i(s.Navbar.Section,{children:i(s.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:i(s.Button,{size:"xs",color:"red",leftIcon:i(L.IconX,{size:18}),onClick:()=>e.editor.close(),children:"Close"})})})]})}),Fk={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1,nav:{top:0,height:"100vh"}},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:0,height:"100vh"}},Gk=k.observer(()=>{const e=me().editor;return i(s.Modal,{onClose:()=>e.setSettingsOpen(!1),closeOnEscape:!1,closeOnClickOutside:!1,opened:e.settings_open,fullScreen:!0,title:null,transitionProps:{duration:0},withCloseButton:!1,withinPortal:!0,zIndex:300,styles:{body:{padding:"0 !important"}},children:i(s.AppShell,{padding:0,navbar:i(qk,{}),styles:Fk,children:i(zk,{})})})}),Wk=e=>e.replace(/([^:])(\/\/+)/g,"$1/");function Rk(e){b.useEffect(()=>{if(Ae.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const n=Wk(e);Ae.loader.config({paths:{vs:n}}),Ae.loader.init().then(r=>console.log("monaco instance:",r))},[])}Cs();const jk={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},Yk=({context:e,dashboard:t,content:n,update:r,className:a="dashboard",config:o,onChange:l,headerSlot:u,headerMenuItems:c},d)=>{Rk(o.monacoPath),Ya(o);const{data:f=[]}=X.useRequest(mr),{data:h=[]}=X.useRequest(Qa),g=b.useMemo(()=>Ll(t,n,f,h,e),[t,n]);b.useImperativeHandle(d,()=>g,[g]),Ol(g.content,!0),b.useEffect(()=>{g.context.replace(e)},[e]),b.useEffect(()=>{g.datasources.replace(f)},[f]),b.useEffect(()=>{g.globalSQLSnippets.replace(h)},[h]),b.useEffect(()=>re.reaction(()=>re.toJS(g.json),_=>{l==null||l(_)}),[g]);const m=async()=>{await r(g.json,g.content.json)},C=X.useCreation(wi,[]),w=Pl(C);return i(Ue.ModalsProvider,{children:i(vr,{value:g,children:i(wr,{value:g.content,children:i(wn.Provider,{value:{inEditMode:!0},children:i(st.Provider,{value:C,children:p(Zn,{configure:w,children:[i(s.AppShell,{padding:0,header:i(oS,{saveDashboardChanges:m,headerSlot:u,headerMenuItems:c}),navbar:i(BS,{}),styles:jk,children:i(s.Box,{className:`${a} dashboard-root`,sx:{position:"relative"},children:g.content.views.visibleViews.map(_=>i(kl,{view:_},_.id))})}),i(Gk,{})]})})})})})})},Qk=k.observer(b.forwardRef(Yk)),nM="",tu=y.types.model({id:y.types.string,name:y.types.string,dashboard_id:y.types.string,create_time:y.types.string,update_time:y.types.string,version:y.types.string,filters:sl,queries:pl,sqlSnippets:hl,views:nl,panels:il,mock_context:No}).views(e=>({get payloadForSQL(){const t=y.getParent(e).context.current,n=y.getParent(e).globalSQLSnippets,r={context:{...e.mock_context.current,...t},filters:e.filters.values};return{...r,sql_snippets:tr(e.sqlSnippets.current,"key","value",r),global_sql_snippets:tr(n.list,"id","content",r)}},get payloadForViz(){const t=y.getParent(e).context.current;return{context:{...e.mock_context.current,...t},filters:e.filters.values}},get data(){return e.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(t){const n=e.queries.findByID(t);return n?{data:n.data.toJSON(),len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).actions(e=>({}));function Kk({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:l,filters:u,views:c,panels:d,definition:{queries:f,sqlSnippets:h,mock_context:g={}}}=o;return tu.create({id:e,name:t,dashboard_id:n,create_time:r,update_time:a,version:l,filters:ol(u),queries:u1(f),sqlSnippets:d1(h),mock_context:qo(g),views:JC(c),panels:{list:d}})}const Uk=y.types.model({id:y.types.identifier,name:y.types.string,group:y.types.string,content:tu,content_id:y.types.string,datasources:UC,globalSQLSnippets:el,context:ki});function Xk({id:e,name:t,group:n,content_id:r},a,o,l,u){return Uk.create({id:e,name:t,group:n,content_id:r,content:Kk(a),datasources:{list:o},globalSQLSnippets:{list:l},context:tl(u)})}Cs();const Jk=k.observer(({context:e,dashboard:t,content:n,className:r="dashboard",config:a,fullScreenPanelID:o,setFullScreenPanelID:l})=>{Ya(a);const{data:u=[]}=X.useRequest(mr),{data:c=[]}=X.useRequest(Qa),d=b.useMemo(()=>Xk(t,n,u,c,e),[t,n]);Ol(d.content,!1),b.useEffect(()=>{d.context.replace(e)},[e]),b.useEffect(()=>{d.datasources.replace(u)},[u]),b.useEffect(()=>{d.globalSQLSnippets.replace(c)},[c]);const f=X.useCreation(wi,[]),h=Pl(f);return i(Ue.ModalsProvider,{children:i(vr,{value:d,children:i(wr,{value:d.content,children:i(Sr.Provider,{value:{fullScreenPanelID:o,setFullScreenPanelID:l},children:i(wn.Provider,{value:{inEditMode:!1},children:i(s.Box,{className:`${r} dashboard-root`,children:i(st.Provider,{value:f,children:i(Zn,{configure:h,children:d.content.views.visibleViews.map(g=>i(rr,{view:g},g.id))})})})})})})})})});var Ni={},Zk={get exports(){return Ni},set exports(e){Ni=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){var a=r.prototype,o=a.format;a.format=function(l){var u=this,c=this.$locale();if(!this.isValid())return o.bind(this)(l);var d=this.$utils(),f=(l||"YYYY-MM-DDTHH:mm:ssZ").replace(/\[([^\]]+)]|Q|wo|ww|w|WW|W|zzz|z|gggg|GGGG|Do|X|x|k{1,2}|S/g,function(h){switch(h){case"Q":return Math.ceil((u.$M+1)/3);case"Do":return c.ordinal(u.$D);case"gggg":return u.weekYear();case"GGGG":return u.isoWeekYear();case"wo":return c.ordinal(u.week(),"W");case"w":case"ww":return d.s(u.week(),h==="w"?1:2,"0");case"W":case"WW":return d.s(u.isoWeek(),h==="W"?1:2,"0");case"k":case"kk":return d.s(String(u.$H===0?24:u.$H),h==="k"?1:2,"0");case"X":return Math.floor(u.$d.getTime()/1e3);case"x":return u.$d.getTime();case"z":return"["+u.offsetName()+"]";case"zzz":return"["+u.offsetName("long")+"]";default:return h}});return o.bind(this)(f)}}})})(Zk);const Hk=Ni;var qi={},eT={get exports(){return qi},set exports(e){qi=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){var o=r.prototype,l=function(c){var d=c.date,f=c.utc;return Array.isArray(d)?f?d.length?new Date(Date.UTC.apply(null,d)):new Date:d.length===1?a(String(d[0])).toDate():new(Function.prototype.bind.apply(Date,[null].concat(d))):d},u=o.parse;o.parse=function(c){c.date=l.bind(this)(c),u.bind(this)(c)}}})})(eT);const tT=qi;var Fi={},nT={get exports(){return Fi},set exports(e){Fi=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){var a=r.prototype;a.$g=function(g,m,C){return this.$utils().u(g)?this[m]:this.$set(C,g)},a.set=function(g,m){return this.$set(g,m)};var o=a.startOf;a.startOf=function(g,m){return this.$d=o.bind(this)(g,m).toDate(),this.init(),this};var l=a.add;a.add=function(g,m){return this.$d=l.bind(this)(g,m).toDate(),this.init(),this};var u=a.locale;a.locale=function(g,m){return g?(this.$L=u.bind(this)(g,m).$L,this):this.$L};var c=a.daysInMonth;a.daysInMonth=function(){return c.bind(this.clone())()};var d=a.isSame;a.isSame=function(g,m){return d.bind(this.clone())(g,m)};var f=a.isBefore;a.isBefore=function(g,m){return f.bind(this.clone())(g,m)};var h=a.isAfter;a.isAfter=function(g,m){return h.bind(this.clone())(g,m)}}})})(nT);const rT=Fi;var Gi={},iT={get exports(){return Gi},set exports(e){Gi=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){var a=r.prototype,o=a.format;a.format=function(l){var u=this,c=(l||"YYYY-MM-DDTHH:mm:ssZ").replace(/(\[[^\]]+])|BBBB|BB/g,function(d,f){var h,g=String(u.$y+543),m=d==="BB"?[g.slice(-2),2]:[g,4];return f||(h=u.$utils()).s.apply(h,m.concat(["0"]))});return o.bind(this)(c)}}})})(iT);const aT=Gi;var Wi={},sT={get exports(){return Wi},set exports(e){Wi=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){var o="h:mm A",l={lastDay:"[Yesterday at] "+o,sameDay:"[Today at] "+o,nextDay:"[Tomorrow at] "+o,nextWeek:"dddd [at] "+o,lastWeek:"[Last] dddd [at] "+o,sameElse:"MM/DD/YYYY"};r.prototype.calendar=function(u,c){var d=c||this.$locale().calendar||l,f=a(u||void 0).startOf("d"),h=this.diff(f,"d",!0),g="sameElse",m=h<-6?g:h<-1?"lastWeek":h<0?"lastDay":h<1?"sameDay":h<2?"nextDay":h<7?"nextWeek":g,C=d[m]||l[m];return typeof C=="function"?C.call(this,a()):this.format(C)}}})})(sT);const oT=Wi;var Ri={},lT={get exports(){return Ri},set exports(e){Ri=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){var n={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},r=/(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,a=/\d\d/,o=/\d\d?/,l=/\d*[^-_:/,()\s\d]+/,u={},c=function(w){return(w=+w)+(w>68?1900:2e3)},d=function(w){return function(_){this[w]=+_}},f=[/[+-]\d\d:?(\d\d)?|Z/,function(w){(this.zone||(this.zone={})).offset=function(_){if(!_||_==="Z")return 0;var D=_.match(/([+-]|\d\d)/g),E=60*D[1]+(+D[2]||0);return E===0?0:D[0]==="+"?-E:E}(w)}],h=function(w){var _=u[w];return _&&(_.indexOf?_:_.s.concat(_.f))},g=function(w,_){var D,E=u.meridiem;if(E){for(var O=1;O<=24;O+=1)if(w.indexOf(E(O,0,_))>-1){D=O>12;break}}else D=w===(_?"pm":"PM");return D},m={A:[l,function(w){this.afternoon=g(w,!1)}],a:[l,function(w){this.afternoon=g(w,!0)}],S:[/\d/,function(w){this.milliseconds=100*+w}],SS:[a,function(w){this.milliseconds=10*+w}],SSS:[/\d{3}/,function(w){this.milliseconds=+w}],s:[o,d("seconds")],ss:[o,d("seconds")],m:[o,d("minutes")],mm:[o,d("minutes")],H:[o,d("hours")],h:[o,d("hours")],HH:[o,d("hours")],hh:[o,d("hours")],D:[o,d("day")],DD:[a,d("day")],Do:[l,function(w){var _=u.ordinal,D=w.match(/\d+/);if(this.day=D[0],_)for(var E=1;E<=31;E+=1)_(E).replace(/\[|\]/g,"")===w&&(this.day=E)}],M:[o,d("month")],MM:[a,d("month")],MMM:[l,function(w){var _=h("months"),D=(h("monthsShort")||_.map(function(E){return E.slice(0,3)})).indexOf(w)+1;if(D<1)throw new Error;this.month=D%12||D}],MMMM:[l,function(w){var _=h("months").indexOf(w)+1;if(_<1)throw new Error;this.month=_%12||_}],Y:[/[+-]?\d+/,d("year")],YY:[a,function(w){this.year=c(w)}],YYYY:[/\d{4}/,d("year")],Z:f,ZZ:f};function C(w){var _,D;_=w,D=u&&u.formats;for(var E=(w=_.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(U,Q,Z){var se=Z&&Z.toUpperCase();return Q||D[Z]||n[Z]||D[se].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(le,ye,Ie){return ye||Ie.slice(1)})})).match(r),O=E.length,B=0;B<O;B+=1){var $=E[B],A=m[$],I=A&&A[0],F=A&&A[1];E[B]=F?{regex:I,parser:F}:$.replace(/^\[|\]$/g,"")}return function(U){for(var Q={},Z=0,se=0;Z<O;Z+=1){var le=E[Z];if(typeof le=="string")se+=le.length;else{var ye=le.regex,Ie=le.parser,fe=U.slice(se),ve=ye.exec(fe)[0];Ie.call(Q,ve),U=U.replace(ve,"")}}return function(ge){var Oe=ge.afternoon;if(Oe!==void 0){var Qe=ge.hours;Oe?Qe<12&&(ge.hours+=12):Qe===12&&(ge.hours=0),delete ge.afternoon}}(Q),Q}}return function(w,_,D){D.p.customParseFormat=!0,w&&w.parseTwoDigitYear&&(c=w.parseTwoDigitYear);var E=_.prototype,O=E.parse;E.parse=function(B){var $=B.date,A=B.utc,I=B.args;this.$u=A;var F=I[1];if(typeof F=="string"){var U=I[2]===!0,Q=I[3]===!0,Z=U||Q,se=I[2];Q&&(se=I[2]),u=this.$locale(),!U&&se&&(u=D.Ls[se]),this.$d=function(fe,ve,ge){try{if(["x","X"].indexOf(ve)>-1)return new Date((ve==="X"?1e3:1)*fe);var Oe=C(ve)(fe),Qe=Oe.year,zt=Oe.month,ur=Oe.day,cr=Oe.hours,va=Oe.minutes,xa=Oe.seconds,un=Oe.milliseconds,Gt=Oe.zone,Ct=new Date,$t=ur||(Qe||zt?1:Ct.getDate()),St=Qe||Ct.getFullYear(),Wt=0;Qe&&!zt||(Wt=zt>0?zt-1:Ct.getMonth());var Rt=cr||0,cn=va||0,dn=xa||0,_t=un||0;return Gt?new Date(Date.UTC(St,Wt,$t,Rt,cn,dn,_t+60*Gt.offset*1e3)):ge?new Date(Date.UTC(St,Wt,$t,Rt,cn,dn,_t)):new Date(St,Wt,$t,Rt,cn,dn,_t)}catch{return new Date("")}}($,F,A),this.init(),se&&se!==!0&&(this.$L=this.locale(se).$L),Z&&$!=this.format(F)&&(this.$d=new Date("")),u={}}else if(F instanceof Array)for(var le=F.length,ye=1;ye<=le;ye+=1){I[1]=F[ye-1];var Ie=D.apply(this,I);if(Ie.isValid()){this.$d=Ie.$d,this.$L=Ie.$L,this.init();break}ye===le&&(this.$d=new Date(""))}else O.call(this,B)}}})})(lT);const uT=Ri;var ji={},cT={get exports(){return ji},set exports(e){ji=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){r.prototype.dayOfYear=function(o){var l=Math.round((a(this).startOf("day")-a(this).startOf("year"))/864e5)+1;return o==null?l:this.add(o-l,"day")}}})})(cT);const dT=ji;var Yi={},pT={get exports(){return Yi},set exports(e){Yi=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){var n,r,a=1e3,o=6e4,l=36e5,u=864e5,c=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,d=31536e6,f=2592e6,h=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,g={years:d,months:f,days:u,hours:l,minutes:o,seconds:a,milliseconds:1,weeks:6048e5},m=function($){return $ instanceof B},C=function($,A,I){return new B($,I,A.$l)},w=function($){return r.p($)+"s"},_=function($){return $<0},D=function($){return _($)?Math.ceil($):Math.floor($)},E=function($){return Math.abs($)},O=function($,A){return $?_($)?{negative:!0,format:""+E($)+A}:{negative:!1,format:""+$+A}:{negative:!1,format:""}},B=function(){function $(I,F,U){var Q=this;if(this.$d={},this.$l=U,I===void 0&&(this.$ms=0,this.parseFromMilliseconds()),F)return C(I*g[w(F)],this);if(typeof I=="number")return this.$ms=I,this.parseFromMilliseconds(),this;if(typeof I=="object")return Object.keys(I).forEach(function(le){Q.$d[w(le)]=I[le]}),this.calMilliseconds(),this;if(typeof I=="string"){var Z=I.match(h);if(Z){var se=Z.slice(2).map(function(le){return le!=null?Number(le):0});return this.$d.years=se[0],this.$d.months=se[1],this.$d.weeks=se[2],this.$d.days=se[3],this.$d.hours=se[4],this.$d.minutes=se[5],this.$d.seconds=se[6],this.calMilliseconds(),this}}return this}var A=$.prototype;return A.calMilliseconds=function(){var I=this;this.$ms=Object.keys(this.$d).reduce(function(F,U){return F+(I.$d[U]||0)*g[U]},0)},A.parseFromMilliseconds=function(){var I=this.$ms;this.$d.years=D(I/d),I%=d,this.$d.months=D(I/f),I%=f,this.$d.days=D(I/u),I%=u,this.$d.hours=D(I/l),I%=l,this.$d.minutes=D(I/o),I%=o,this.$d.seconds=D(I/a),I%=a,this.$d.milliseconds=I},A.toISOString=function(){var I=O(this.$d.years,"Y"),F=O(this.$d.months,"M"),U=+this.$d.days||0;this.$d.weeks&&(U+=7*this.$d.weeks);var Q=O(U,"D"),Z=O(this.$d.hours,"H"),se=O(this.$d.minutes,"M"),le=this.$d.seconds||0;this.$d.milliseconds&&(le+=this.$d.milliseconds/1e3);var ye=O(le,"S"),Ie=I.negative||F.negative||Q.negative||Z.negative||se.negative||ye.negative,fe=Z.format||se.format||ye.format?"T":"",ve=(Ie?"-":"")+"P"+I.format+F.format+Q.format+fe+Z.format+se.format+ye.format;return ve==="P"||ve==="-P"?"P0D":ve},A.toJSON=function(){return this.toISOString()},A.format=function(I){var F=I||"YYYY-MM-DDTHH:mm:ss",U={Y:this.$d.years,YY:r.s(this.$d.years,2,"0"),YYYY:r.s(this.$d.years,4,"0"),M:this.$d.months,MM:r.s(this.$d.months,2,"0"),D:this.$d.days,DD:r.s(this.$d.days,2,"0"),H:this.$d.hours,HH:r.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:r.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:r.s(this.$d.seconds,2,"0"),SSS:r.s(this.$d.milliseconds,3,"0")};return F.replace(c,function(Q,Z){return Z||String(U[Q])})},A.as=function(I){return this.$ms/g[w(I)]},A.get=function(I){var F=this.$ms,U=w(I);return U==="milliseconds"?F%=1e3:F=U==="weeks"?D(F/g[U]):this.$d[U],F===0?0:F},A.add=function(I,F,U){var Q;return Q=F?I*g[w(F)]:m(I)?I.$ms:C(I,this).$ms,C(this.$ms+Q*(U?-1:1),this)},A.subtract=function(I,F){return this.add(I,F,!0)},A.locale=function(I){var F=this.clone();return F.$l=I,F},A.clone=function(){return C(this.$ms,this)},A.humanize=function(I){return n().add(this.$ms,"ms").locale(this.$l).fromNow(!I)},A.milliseconds=function(){return this.get("milliseconds")},A.asMilliseconds=function(){return this.as("milliseconds")},A.seconds=function(){return this.get("seconds")},A.asSeconds=function(){return this.as("seconds")},A.minutes=function(){return this.get("minutes")},A.asMinutes=function(){return this.as("minutes")},A.hours=function(){return this.get("hours")},A.asHours=function(){return this.as("hours")},A.days=function(){return this.get("days")},A.asDays=function(){return this.as("days")},A.weeks=function(){return this.get("weeks")},A.asWeeks=function(){return this.as("weeks")},A.months=function(){return this.get("months")},A.asMonths=function(){return this.as("months")},A.years=function(){return this.get("years")},A.asYears=function(){return this.as("years")},$}();return function($,A,I){n=I,r=I().$utils(),I.duration=function(Q,Z){var se=I.locale();return C(Q,{$l:se},Z)},I.isDuration=m;var F=A.prototype.add,U=A.prototype.subtract;A.prototype.add=function(Q,Z){return m(Q)&&(Q=Q.asMilliseconds()),F.bind(this)(Q,Z)},A.prototype.subtract=function(Q,Z){return m(Q)&&(Q=Q.asMilliseconds()),U.bind(this)(Q,Z)}}})})(pT);const hT=Yi;var Qi={},fT={get exports(){return Qi},set exports(e){Qi=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){r.prototype.isBetween=function(o,l,u,c){var d=a(o),f=a(l),h=(c=c||"()")[0]==="(",g=c[1]===")";return(h?this.isAfter(d,u):!this.isBefore(d,u))&&(g?this.isBefore(f,u):!this.isAfter(f,u))||(h?this.isBefore(d,u):!this.isAfter(d,u))&&(g?this.isAfter(f,u):!this.isBefore(f,u))}}})})(fT);const gT=Qi;var Ki={},mT={get exports(){return Ki},set exports(e){Ki=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){r.prototype.isLeapYear=function(){return this.$y%4==0&&this.$y%100!=0||this.$y%400==0}}})})(mT);const yT=Ki;var Ui={},bT={get exports(){return Ui},set exports(e){Ui=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){a.isMoment=function(o){return a.isDayjs(o)}}})})(bT);const vT=Ui;var Xi={},xT={get exports(){return Xi},set exports(e){Xi=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){var n="day";return function(r,a,o){var l=function(d){return d.add(4-d.isoWeekday(),n)},u=a.prototype;u.isoWeekYear=function(){return l(this).year()},u.isoWeek=function(d){if(!this.$utils().u(d))return this.add(7*(d-this.isoWeek()),n);var f,h,g,m,C=l(this),w=(f=this.isoWeekYear(),h=this.$u,g=(h?o.utc:o)().year(f).startOf("year"),m=4-g.isoWeekday(),g.isoWeekday()>4&&(m+=7),g.add(m,n));return C.diff(w,"week")+1},u.isoWeekday=function(d){return this.$utils().u(d)?this.day()||7:this.day(this.day()%7?d:d-7)};var c=u.startOf;u.startOf=function(d,f){var h=this.$utils(),g=!!h.u(f)||f;return h.p(d)==="isoweek"?g?this.date(this.date()-(this.isoWeekday()-1)).startOf("day"):this.date(this.date()-1-(this.isoWeekday()-1)+7).endOf("day"):c.bind(this)(d,f)}}})})(xT);const wT=Xi;var Ji={},CT={get exports(){return Ji},set exports(e){Ji=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){r.prototype.isoWeeksInYear=function(){var a=this.isLeapYear(),o=this.endOf("y").day();return o===4||a&&o===5?53:52}}})})(CT);const ST=Ji;var Zi={},_T={get exports(){return Zi},set exports(e){Zi=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){r.prototype.isSameOrAfter=function(a,o){return this.isSame(a,o)||this.isAfter(a,o)}}})})(_T);const kT=Zi;var Hi={},TT={get exports(){return Hi},set exports(e){Hi=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){r.prototype.isSameOrBefore=function(a,o){return this.isSame(a,o)||this.isBefore(a,o)}}})})(TT);const DT=Hi;var ea={},MT={get exports(){return ea},set exports(e){ea=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){r.prototype.isToday=function(){var o="YYYY-MM-DD",l=a();return this.format(o)===l.format(o)}}})})(MT);const IT=ea;var ta={},ET={get exports(){return ta},set exports(e){ta=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){r.prototype.isTomorrow=function(){var o="YYYY-MM-DD",l=a().add(1,"day");return this.format(o)===l.format(o)}}})})(ET);const AT=ta;var na={},zT={get exports(){return na},set exports(e){na=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){r.prototype.isYesterday=function(){var o="YYYY-MM-DD",l=a().subtract(1,"day");return this.format(o)===l.format(o)}}})})(zT);const $T=na;var ra={},LT={get exports(){return ra},set exports(e){ra=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){var o=r.prototype,l=function(h){return h&&(h.indexOf?h:h.s)},u=function(h,g,m,C,w){var _=h.name?h:h.$locale(),D=l(_[g]),E=l(_[m]),O=D||E.map(function($){return $.slice(0,C)});if(!w)return O;var B=_.weekStart;return O.map(function($,A){return O[(A+(B||0))%7]})},c=function(){return a.Ls[a.locale()]},d=function(h,g){return h.formats[g]||function(m){return m.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(C,w,_){return w||_.slice(1)})}(h.formats[g.toUpperCase()])},f=function(){var h=this;return{months:function(g){return g?g.format("MMMM"):u(h,"months")},monthsShort:function(g){return g?g.format("MMM"):u(h,"monthsShort","months",3)},firstDayOfWeek:function(){return h.$locale().weekStart||0},weekdays:function(g){return g?g.format("dddd"):u(h,"weekdays")},weekdaysMin:function(g){return g?g.format("dd"):u(h,"weekdaysMin","weekdays",2)},weekdaysShort:function(g){return g?g.format("ddd"):u(h,"weekdaysShort","weekdays",3)},longDateFormat:function(g){return d(h.$locale(),g)},meridiem:this.$locale().meridiem,ordinal:this.$locale().ordinal}};o.localeData=function(){return f.bind(this)()},a.localeData=function(){var h=c();return{firstDayOfWeek:function(){return h.weekStart||0},weekdays:function(){return a.weekdays()},weekdaysShort:function(){return a.weekdaysShort()},weekdaysMin:function(){return a.weekdaysMin()},months:function(){return a.months()},monthsShort:function(){return a.monthsShort()},longDateFormat:function(g){return d(h,g)},meridiem:h.meridiem,ordinal:h.ordinal}},a.months=function(){return u(c(),"months")},a.monthsShort=function(){return u(c(),"monthsShort","months",3)},a.weekdays=function(h){return u(c(),"weekdays",null,null,h)},a.weekdaysShort=function(h){return u(c(),"weekdaysShort","weekdays",3,h)},a.weekdaysMin=function(h){return u(c(),"weekdaysMin","weekdays",2,h)}}})})(LT);const OT=ra;var ia={},PT={get exports(){return ia},set exports(e){ia=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){var n={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"};return function(r,a,o){var l=a.prototype,u=l.format;o.en.formats=n,l.format=function(c){c===void 0&&(c="YYYY-MM-DDTHH:mm:ssZ");var d=this.$locale().formats,f=function(h,g){return h.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(m,C,w){var _=w&&w.toUpperCase();return C||g[w]||n[w]||g[_].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(D,E,O){return E||O.slice(1)})})}(c,d===void 0?{}:d);return u.call(this,f)}}})})(PT);const BT=ia;var aa={},VT={get exports(){return aa},set exports(e){aa=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){var o=function(l,u){if(!u||!u.length||!u[0]||u.length===1&&!u[0].length)return null;var c;u.length===1&&u[0].length>0&&(u=u[0]),c=u[0];for(var d=1;d<u.length;d+=1)u[d].isValid()&&!u[d][l](c)||(c=u[d]);return c};a.max=function(){var l=[].slice.call(arguments,0);return o("isAfter",l)},a.min=function(){var l=[].slice.call(arguments,0);return o("isBefore",l)}}})})(VT);const NT=aa;var sa={},qT={get exports(){return sa},set exports(e){sa=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){var o=r.prototype,l=function(g){var m,C=g.date,w=g.utc,_={};if(!((m=C)instanceof Date||m instanceof Array||o.$utils().u(m)||m.constructor.name!=="Object")){if(!Object.keys(C).length)return new Date;var D=w?a.utc():a();Object.keys(C).forEach(function(U){var Q,Z;_[Q=U,Z=o.$utils().p(Q),Z==="date"?"day":Z]=C[U]});var E=_.day||(_.year||_.month>=0?1:D.date()),O=_.year||D.year(),B=_.month>=0?_.month:_.year||_.day?0:D.month(),$=_.hour||0,A=_.minute||0,I=_.second||0,F=_.millisecond||0;return w?new Date(Date.UTC(O,B,E,$,A,I,F)):new Date(O,B,E,$,A,I,F)}return C},u=o.parse;o.parse=function(g){g.date=l.bind(this)(g),u.bind(this)(g)};var c=o.set,d=o.add,f=o.subtract,h=function(g,m,C,w){w===void 0&&(w=1);var _=Object.keys(m),D=this;return _.forEach(function(E){D=g.bind(D)(m[E]*w,E)}),D};o.set=function(g,m){return m=m===void 0?g:m,g.constructor.name==="Object"?h.bind(this)(function(C,w){return c.bind(this)(w,C)},m,g):c.bind(this)(g,m)},o.add=function(g,m){return g.constructor.name==="Object"?h.bind(this)(d,g,m):d.bind(this)(g,m)},o.subtract=function(g,m){return g.constructor.name==="Object"?h.bind(this)(d,g,m,-1):f.bind(this)(g,m)}}})})(qT);const FT=sa;var oa={},GT={get exports(){return oa},set exports(e){oa=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){var a=r.prototype;["milliseconds","seconds","minutes","hours","days","weeks","isoWeeks","months","quarters","years","dates"].forEach(function(o){a[o]=a[o.replace(/s$/,"")]})}})})(GT);const WT=oa;var la={},RT={get exports(){return la},set exports(e){la=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){var a=r.prototype.parse;r.prototype.parse=function(u){if(typeof u.date=="string"){var c=this.$locale();u.date=c&&c.preparse?c.preparse(u.date):u.date}return a.bind(this)(u)};var o=r.prototype.format;r.prototype.format=function(){for(var u=arguments.length,c=new Array(u),d=0;d<u;d++)c[d]=arguments[d];var f=o.call.apply(o,[this].concat(c)),h=this.$locale();return h&&h.postformat?h.postformat(f):f};var l=r.prototype.fromToBase;l&&(r.prototype.fromToBase=function(u,c,d,f){var h=this.$locale()||d.$locale();return l.call(this,u,c,d,f,h&&h.postformat)})}})})(RT);const jT=la;var ua={},YT={get exports(){return ua},set exports(e){ua=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){var n="month",r="quarter";return function(a,o){var l=o.prototype;l.quarter=function(d){return this.$utils().u(d)?Math.ceil((this.month()+1)/3):this.month(this.month()%3+3*(d-1))};var u=l.add;l.add=function(d,f){return d=Number(d),this.$utils().p(f)===r?this.add(3*d,n):u.bind(this)(d,f)};var c=l.startOf;l.startOf=function(d,f){var h=this.$utils(),g=!!h.u(f)||f;if(h.p(d)===r){var m=this.quarter()-1;return g?this.month(3*m).startOf(n).startOf("day"):this.month(3*m+2).endOf(n).endOf("day")}return c.bind(this)(d,f)}}})})(YT);const QT=ua;var ca={},KT={get exports(){return ca},set exports(e){ca=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){n=n||{};var o=r.prototype,l={future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"};function u(d,f,h,g){return o.fromToBase(d,f,h,g)}a.en.relativeTime=l,o.fromToBase=function(d,f,h,g,m){for(var C,w,_,D=h.$locale().relativeTime||l,E=n.thresholds||[{l:"s",r:44,d:"second"},{l:"m",r:89},{l:"mm",r:44,d:"minute"},{l:"h",r:89},{l:"hh",r:21,d:"hour"},{l:"d",r:35},{l:"dd",r:25,d:"day"},{l:"M",r:45},{l:"MM",r:10,d:"month"},{l:"y",r:17},{l:"yy",d:"year"}],O=E.length,B=0;B<O;B+=1){var $=E[B];$.d&&(C=g?a(d).diff(h,$.d,!0):h.diff(d,$.d,!0));var A=(n.rounding||Math.round)(Math.abs(C));if(_=C>0,A<=$.r||!$.r){A<=1&&B>0&&($=E[B-1]);var I=D[$.l];m&&(A=m(""+A)),w=typeof I=="string"?I.replace("%d",A):I(A,f,$.l,_);break}}if(f)return w;var F=_?D.future:D.past;return typeof F=="function"?F(w):F.replace("%s",w)},o.to=function(d,f){return u(d,f,this,!0)},o.from=function(d,f){return u(d,f,this)};var c=function(d){return d.$u?a.utc():a()};o.toNow=function(d){return this.to(c(this),d)},o.fromNow=function(d){return this.from(c(this),d)}}})})(KT);const UT=ca;var da={},XT={get exports(){return da},set exports(e){da=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){var n={year:0,month:1,day:2,hour:3,minute:4,second:5},r={};return function(a,o,l){var u,c=function(g,m,C){C===void 0&&(C={});var w=new Date(g),_=function(D,E){E===void 0&&(E={});var O=E.timeZoneName||"short",B=D+"|"+O,$=r[B];return $||($=new Intl.DateTimeFormat("en-US",{hour12:!1,timeZone:D,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:O}),r[B]=$),$}(m,C);return _.formatToParts(w)},d=function(g,m){for(var C=c(g,m),w=[],_=0;_<C.length;_+=1){var D=C[_],E=D.type,O=D.value,B=n[E];B>=0&&(w[B]=parseInt(O,10))}var $=w[3],A=$===24?0:$,I=w[0]+"-"+w[1]+"-"+w[2]+" "+A+":"+w[4]+":"+w[5]+":000",F=+g;return(l.utc(I).valueOf()-(F-=F%1e3))/6e4},f=o.prototype;f.tz=function(g,m){g===void 0&&(g=u);var C=this.utcOffset(),w=this.toDate(),_=w.toLocaleString("en-US",{timeZone:g}),D=Math.round((w-new Date(_))/1e3/60),E=l(_).$set("millisecond",this.$ms).utcOffset(15*-Math.round(w.getTimezoneOffset()/15)-D,!0);if(m){var O=E.utcOffset();E=E.add(C-O,"minute")}return E.$x.$timezone=g,E},f.offsetName=function(g){var m=this.$x.$timezone||l.tz.guess(),C=c(this.valueOf(),m,{timeZoneName:g}).find(function(w){return w.type.toLowerCase()==="timezonename"});return C&&C.value};var h=f.startOf;f.startOf=function(g,m){if(!this.$x||!this.$x.$timezone)return h.call(this,g,m);var C=l(this.format("YYYY-MM-DD HH:mm:ss:SSS"));return h.call(C,g,m).tz(this.$x.$timezone,!0)},l.tz=function(g,m,C){var w=C&&m,_=C||m||u,D=d(+l(),_);if(typeof g!="string")return l(g).tz(_);var E=function(A,I,F){var U=A-60*I*1e3,Q=d(U,F);if(I===Q)return[U,I];var Z=d(U-=60*(Q-I)*1e3,F);return Q===Z?[U,Q]:[A-60*Math.min(Q,Z)*1e3,Math.max(Q,Z)]}(l.utc(g,w).valueOf(),D,_),O=E[0],B=E[1],$=l(O).utcOffset(B);return $.$x.$timezone=_,$},l.tz.guess=function(){return Intl.DateTimeFormat().resolvedOptions().timeZone},l.tz.setDefault=function(g){u=g}}})})(XT);const JT=da;var pa={},ZT={get exports(){return pa},set exports(e){pa=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){r.prototype.toArray=function(){return[this.$y,this.$M,this.$D,this.$H,this.$m,this.$s,this.$ms]}}})})(ZT);const HT=pa;var ha={},eD={get exports(){return ha},set exports(e){ha=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){r.prototype.toObject=function(){return{years:this.$y,months:this.$M,date:this.$D,hours:this.$H,minutes:this.$m,seconds:this.$s,milliseconds:this.$ms}}}})})(eD);const tD=ha;var fa={},nD={get exports(){return fa},set exports(e){fa=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r,a){a.updateLocale=function(o,l){var u=a.Ls[o];if(u)return(l?Object.keys(l):[]).forEach(function(c){u[c]=l[c]}),u}}})})(nD);const rD=fa;var ga={},iD={get exports(){return ga},set exports(e){ga=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){var n="minute",r=/[+-]\d\d(?::?\d\d)?/g,a=/([+-]|\d\d)/g;return function(o,l,u){var c=l.prototype;u.utc=function(w){var _={date:w,utc:!0,args:arguments};return new l(_)},c.utc=function(w){var _=u(this.toDate(),{locale:this.$L,utc:!0});return w?_.add(this.utcOffset(),n):_},c.local=function(){return u(this.toDate(),{locale:this.$L,utc:!1})};var d=c.parse;c.parse=function(w){w.utc&&(this.$u=!0),this.$utils().u(w.$offset)||(this.$offset=w.$offset),d.call(this,w)};var f=c.init;c.init=function(){if(this.$u){var w=this.$d;this.$y=w.getUTCFullYear(),this.$M=w.getUTCMonth(),this.$D=w.getUTCDate(),this.$W=w.getUTCDay(),this.$H=w.getUTCHours(),this.$m=w.getUTCMinutes(),this.$s=w.getUTCSeconds(),this.$ms=w.getUTCMilliseconds()}else f.call(this)};var h=c.utcOffset;c.utcOffset=function(w,_){var D=this.$utils().u;if(D(w))return this.$u?0:D(this.$offset)?h.call(this):this.$offset;if(typeof w=="string"&&(w=function($){$===void 0&&($="");var A=$.match(r);if(!A)return null;var I=(""+A[0]).match(a)||["-",0,0],F=I[0],U=60*+I[1]+ +I[2];return U===0?0:F==="+"?U:-U}(w),w===null))return this;var E=Math.abs(w)<=16?60*w:w,O=this;if(_)return O.$offset=E,O.$u=w===0,O;if(w!==0){var B=this.$u?this.toDate().getTimezoneOffset():-1*this.utcOffset();(O=this.local().add(E+B,n)).$offset=E,O.$x.$localOffset=B}else O=this.utc();return O};var g=c.format;c.format=function(w){var _=w||(this.$u?"YYYY-MM-DDTHH:mm:ss[Z]":"");return g.call(this,_)},c.valueOf=function(){var w=this.$utils().u(this.$offset)?0:this.$offset+(this.$x.$localOffset||this.$d.getTimezoneOffset());return this.$d.valueOf()-6e4*w},c.isUTC=function(){return!!this.$u},c.toISOString=function(){return this.toDate().toISOString()},c.toString=function(){return this.toDate().toUTCString()};var m=c.toDate;c.toDate=function(w){return w==="s"&&this.$offset?u(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate():m.call(this)};var C=c.diff;c.diff=function(w,_,D){if(w&&this.$u===w.$u)return C.call(this,w,_,D);var E=this.local(),O=u(w).local();return C.call(E,O,_,D)}}})})(iD);const aD=ga;var ma={},sD={get exports(){return ma},set exports(e){ma=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){r.prototype.weekday=function(a){var o=this.$locale().weekStart||0,l=this.$W,u=(l<o?l+7:l)-o;return this.$utils().u(a)?u:this.subtract(u,"day").add(a,"day")}}})})(sD);const oD=ma;var ya={},lD={get exports(){return ya},set exports(e){ya=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){var n="week",r="year";return function(a,o,l){var u=o.prototype;u.week=function(c){if(c===void 0&&(c=null),c!==null)return this.add(7*(c-this.week()),"day");var d=this.$locale().yearStart||1;if(this.month()===11&&this.date()>25){var f=l(this).startOf(r).add(1,r).date(d),h=l(this).endOf(n);if(f.isBefore(h))return 1}var g=l(this).startOf(r).date(d).startOf(n).subtract(1,"millisecond"),m=this.diff(g,n,!0);return m<0?l(this).startOf("week").week():Math.ceil(m)},u.weeks=function(c){return c===void 0&&(c=null),this.week(c)}}})})(lD);const uD=ya;var ba={},cD={get exports(){return ba},set exports(e){ba=e}};(function(e,t){(function(n,r){e.exports=r()})(te,function(){return function(n,r){r.prototype.weekYear=function(){var a=this.month(),o=this.week(),l=this.year();return o===1&&a===11?l+1:a===0&&o>=52?l-1:l}}})})(cD);const dD=ba;j.extend(Hk),j.extend(tT),j.extend(rT),j.extend(aT),j.extend(oT),j.extend(uT),j.extend(dT),j.extend(hT),j.extend(gT),j.extend(yT),j.extend(vT),j.extend(kT),j.extend(DT),j.extend(IT),j.extend(AT),j.extend($T),j.extend(wT),j.extend(ST),j.extend(OT),j.extend(BT),j.extend(NT),j.extend(FT),j.extend(WT),j.extend(jT),j.extend(QT),j.extend(UT),j.extend(JT),j.extend(HT),j.extend(tD),j.extend(rD),j.extend(aD),j.extend(uD),j.extend(dD),j.extend(oD),j.tz.setDefault("UTC");const pD=()=>Promise.resolve().then(()=>Ku).then(({version:e})=>(console.log(`[@devtable/dashboard] version: ${e}`),e));M.ContentModel=Ei,M.ContentModelContextProvider=wr,M.DashboardEditor=Qk,M.DashboardFilterType=Te,M.DashboardMode=Bl,M.DashboardModel=$l,M.DashboardModelContextProvider=vr,M.DashboardViewEditor=kl,M.DashboardViewRender=rr,M.DescriptionPopover=Ti,M.FiltersModel=Tl,M.FullScreenPanel=Cl,M.FullScreenPanelContext=Sr,M.LayoutStateContext=wn,M.Panel=Mi,M.PanelContextProvider=Cr,M.PanelErrorOrStateMessage=vl,M.PanelModel=Il,M.PanelRender=wl,M.PanelVizSection=Di,M.PanelsModel=El,M.QueriesModel=Dl,M.ReadOnlyDashboard=Jk,M.SQLSnippetsModel=Ml,M.ViewComponentTypeBackground=Vl,M.ViewComponentTypeColor=dS,M.ViewComponentTypeName=cS,M.ViewsModel=Al,M.Viz=bl,M.applyPartialDashboard=tS,M.createContentModel=zl,M.createDashboardModel=Ll,M.getInitialDashboardViewsModel=Ii,M.getVersion=pD,M.initialDashboardContent=pS,M.useDashboardContext=xr,M.useEditContentModelContext=ue,M.useEditDashboardContext=me,M.useEditPanelContext=Je,M.useFullScreenPanelContext=is,M.usePanelFullScreen=Sl,M.useRenderContentModelContext=Me,M.useRenderDashboardContext=Ha,M.useRenderPanelContext=gt,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})});