@parca/profile 0.19.140 → 0.19.142

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 (253) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/dist/GraphTooltipArrow/Content.js +224 -30
  3. package/dist/GraphTooltipArrow/DockedGraphTooltip/index.js +192 -33
  4. package/dist/GraphTooltipArrow/ExpandOnHoverValue.js +53 -3
  5. package/dist/GraphTooltipArrow/index.d.ts.map +1 -1
  6. package/dist/GraphTooltipArrow/index.js +86 -56
  7. package/dist/GraphTooltipArrow/useGraphTooltip/index.js +37 -37
  8. package/dist/GraphTooltipArrow/useGraphTooltipMetaInfo/index.d.ts.map +1 -1
  9. package/dist/GraphTooltipArrow/useGraphTooltipMetaInfo/index.js +104 -72
  10. package/dist/MatchersInput/SuggestionItem.js +91 -12
  11. package/dist/MatchersInput/SuggestionsList.d.ts +2 -1
  12. package/dist/MatchersInput/SuggestionsList.d.ts.map +1 -1
  13. package/dist/MatchersInput/SuggestionsList.js +371 -157
  14. package/dist/MatchersInput/SuggestionsList.test.d.ts +2 -0
  15. package/dist/MatchersInput/SuggestionsList.test.d.ts.map +1 -0
  16. package/dist/MatchersInput/index.js +308 -115
  17. package/dist/MetricsCircle/index.js +39 -3
  18. package/dist/MetricsGraph/MetricsContextMenu/index.js +119 -19
  19. package/dist/MetricsGraph/MetricsInfoPanel/index.js +81 -20
  20. package/dist/MetricsGraph/MetricsTooltip/index.d.ts.map +1 -1
  21. package/dist/MetricsGraph/MetricsTooltip/index.js +107 -74
  22. package/dist/MetricsGraph/index.js +552 -203
  23. package/dist/MetricsGraph/useMetricsGraphDimensions.js +46 -25
  24. package/dist/MetricsGraph/utils/colorMapping.js +24 -17
  25. package/dist/MetricsSeries/index.js +70 -7
  26. package/dist/PreSelectedMatchers/index.d.ts.map +1 -1
  27. package/dist/PreSelectedMatchers/index.js +249 -102
  28. package/dist/ProfileExplorer/ProfileExplorerCompare.d.ts.map +1 -1
  29. package/dist/ProfileExplorer/ProfileExplorerCompare.js +241 -45
  30. package/dist/ProfileExplorer/ProfileExplorerSingle.js +98 -11
  31. package/dist/ProfileExplorer/index.js +183 -32
  32. package/dist/ProfileFlameChart/SamplesStrips/SamplesGraph/index.js +333 -148
  33. package/dist/ProfileFlameChart/SamplesStrips/SamplesStrips.stories.js +69 -35
  34. package/dist/ProfileFlameChart/SamplesStrips/index.d.ts +2 -2
  35. package/dist/ProfileFlameChart/SamplesStrips/index.d.ts.map +1 -1
  36. package/dist/ProfileFlameChart/SamplesStrips/index.js +645 -134
  37. package/dist/ProfileFlameChart/SamplesStrips/labelSetUtils.js +114 -55
  38. package/dist/ProfileFlameChart/index.d.ts.map +1 -1
  39. package/dist/ProfileFlameChart/index.js +267 -129
  40. package/dist/ProfileFlameGraph/FlameGraphArrow/ContextMenu.d.ts.map +1 -1
  41. package/dist/ProfileFlameGraph/FlameGraphArrow/ContextMenu.js +288 -89
  42. package/dist/ProfileFlameGraph/FlameGraphArrow/ContextMenuWrapper.js +56 -20
  43. package/dist/ProfileFlameGraph/FlameGraphArrow/FlameGraphNodes.js +211 -140
  44. package/dist/ProfileFlameGraph/FlameGraphArrow/MemoizedTooltip.js +133 -38
  45. package/dist/ProfileFlameGraph/FlameGraphArrow/MiniMap.js +261 -216
  46. package/dist/ProfileFlameGraph/FlameGraphArrow/TextWithEllipsis.d.ts.map +1 -1
  47. package/dist/ProfileFlameGraph/FlameGraphArrow/TextWithEllipsis.js +72 -47
  48. package/dist/ProfileFlameGraph/FlameGraphArrow/TooltipContext.d.ts.map +1 -1
  49. package/dist/ProfileFlameGraph/FlameGraphArrow/TooltipContext.js +58 -28
  50. package/dist/ProfileFlameGraph/FlameGraphArrow/ZoomControls.d.ts.map +1 -1
  51. package/dist/ProfileFlameGraph/FlameGraphArrow/ZoomControls.js +59 -8
  52. package/dist/ProfileFlameGraph/FlameGraphArrow/index.js +396 -179
  53. package/dist/ProfileFlameGraph/FlameGraphArrow/useBatchedRendering.d.ts.map +1 -1
  54. package/dist/ProfileFlameGraph/FlameGraphArrow/useBatchedRendering.js +68 -50
  55. package/dist/ProfileFlameGraph/FlameGraphArrow/useMappingList.js +62 -38
  56. package/dist/ProfileFlameGraph/FlameGraphArrow/useNodeColor.js +14 -6
  57. package/dist/ProfileFlameGraph/FlameGraphArrow/useScrollViewport.js +124 -82
  58. package/dist/ProfileFlameGraph/FlameGraphArrow/useVisibleNodes.js +160 -98
  59. package/dist/ProfileFlameGraph/FlameGraphArrow/useZoom.js +232 -112
  60. package/dist/ProfileFlameGraph/FlameGraphArrow/utils.js +137 -114
  61. package/dist/ProfileFlameGraph/benchmarks/benchdata/populateData.js +85 -0
  62. package/dist/ProfileFlameGraph/index.d.ts.map +1 -1
  63. package/dist/ProfileFlameGraph/index.js +324 -150
  64. package/dist/ProfileMetricsGraph/hooks/useQueryRange.js +140 -32
  65. package/dist/ProfileMetricsGraph/index.d.ts.map +1 -1
  66. package/dist/ProfileMetricsGraph/index.js +519 -258
  67. package/dist/ProfileSelector/CompareButton.js +132 -12
  68. package/dist/ProfileSelector/MetricsGraphSection.d.ts.map +1 -1
  69. package/dist/ProfileSelector/MetricsGraphSection.js +236 -64
  70. package/dist/ProfileSelector/index.d.ts.map +1 -1
  71. package/dist/ProfileSelector/index.js +727 -141
  72. package/dist/ProfileSelector/useAutoQuerySelector.js +249 -130
  73. package/dist/ProfileSource.js +230 -163
  74. package/dist/ProfileTypeSelector/index.js +214 -125
  75. package/dist/ProfileView/components/ActionButtons/GroupByDropdown.js +50 -4
  76. package/dist/ProfileView/components/ActionButtons/SortByDropdown.d.ts.map +1 -1
  77. package/dist/ProfileView/components/ActionButtons/SortByDropdown.js +141 -35
  78. package/dist/ProfileView/components/ColorStackLegend.d.ts.map +1 -1
  79. package/dist/ProfileView/components/ColorStackLegend.js +185 -55
  80. package/dist/ProfileView/components/DashboardItems/index.js +87 -28
  81. package/dist/ProfileView/components/DashboardLayout/index.js +108 -16
  82. package/dist/ProfileView/components/DiffLegend.js +172 -29
  83. package/dist/ProfileView/components/GroupByLabelsDropdown/index.js +199 -55
  84. package/dist/ProfileView/components/InvertCallStack/index.d.ts.map +1 -1
  85. package/dist/ProfileView/components/InvertCallStack/index.js +100 -12
  86. package/dist/ProfileView/components/ProfileFilters/filterPresets.js +260 -315
  87. package/dist/ProfileView/components/ProfileFilters/index.js +518 -215
  88. package/dist/ProfileView/components/ProfileFilters/useProfileFilters.js +370 -306
  89. package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.d.ts +2 -1
  90. package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.d.ts.map +1 -1
  91. package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.js +188 -118
  92. package/dist/ProfileView/components/ProfileHeader/index.js +105 -11
  93. package/dist/ProfileView/components/ShareButton/ResultBox.js +119 -16
  94. package/dist/ProfileView/components/ShareButton/index.js +352 -62
  95. package/dist/ProfileView/components/Toolbars/MultiLevelDropdown.d.ts.map +1 -1
  96. package/dist/ProfileView/components/Toolbars/MultiLevelDropdown.js +678 -194
  97. package/dist/ProfileView/components/Toolbars/SwitchMenuItem.js +94 -7
  98. package/dist/ProfileView/components/Toolbars/TableColumnsDropdown.d.ts.map +1 -1
  99. package/dist/ProfileView/components/Toolbars/TableColumnsDropdown.js +199 -157
  100. package/dist/ProfileView/components/Toolbars/index.d.ts +2 -2
  101. package/dist/ProfileView/components/Toolbars/index.d.ts.map +1 -1
  102. package/dist/ProfileView/components/Toolbars/index.js +441 -21
  103. package/dist/ProfileView/components/ViewSelector/Dropdown.js +233 -22
  104. package/dist/ProfileView/components/ViewSelector/index.d.ts.map +1 -1
  105. package/dist/ProfileView/components/ViewSelector/index.js +212 -86
  106. package/dist/ProfileView/components/VisualizationContainer/index.d.ts.map +1 -1
  107. package/dist/ProfileView/components/VisualizationContainer/index.js +52 -7
  108. package/dist/ProfileView/components/VisualizationPanel.js +185 -8
  109. package/dist/ProfileView/context/DashboardContext.d.ts.map +1 -1
  110. package/dist/ProfileView/context/DashboardContext.js +85 -29
  111. package/dist/ProfileView/context/ProfileViewContext.js +56 -15
  112. package/dist/ProfileView/hooks/useAutoSelectDimension.js +71 -41
  113. package/dist/ProfileView/hooks/useProfileMetadata.js +50 -18
  114. package/dist/ProfileView/hooks/useResetFlameGraphState.d.ts.map +1 -1
  115. package/dist/ProfileView/hooks/useResetFlameGraphState.js +32 -12
  116. package/dist/ProfileView/hooks/useResetStateOnProfileTypeChange.d.ts.map +1 -1
  117. package/dist/ProfileView/hooks/useResetStateOnProfileTypeChange.js +71 -27
  118. package/dist/ProfileView/hooks/useResetStateOnSeriesChange.d.ts.map +1 -1
  119. package/dist/ProfileView/hooks/useResetStateOnSeriesChange.js +40 -19
  120. package/dist/ProfileView/hooks/useVisualizationState.d.ts +3 -3
  121. package/dist/ProfileView/hooks/useVisualizationState.d.ts.map +1 -1
  122. package/dist/ProfileView/hooks/useVisualizationState.js +258 -67
  123. package/dist/ProfileView/index.js +383 -45
  124. package/dist/ProfileView/types/visualization.js +1 -13
  125. package/dist/ProfileView/utils/colorUtils.js +8 -7
  126. package/dist/ProfileViewWithData.d.ts.map +1 -1
  127. package/dist/ProfileViewWithData.js +332 -228
  128. package/dist/QueryControls/index.js +418 -47
  129. package/dist/Sandwich/components/CalleesSection.js +54 -4
  130. package/dist/Sandwich/components/CallersSection.js +97 -27
  131. package/dist/Sandwich/components/TableSection.js +77 -4
  132. package/dist/Sandwich/index.d.ts.map +1 -1
  133. package/dist/Sandwich/index.js +126 -14
  134. package/dist/Sandwich/utils/processRowData.js +48 -39
  135. package/dist/SelectWithRefresh/index.js +102 -28
  136. package/dist/SimpleMatchers/Select.js +520 -187
  137. package/dist/SimpleMatchers/index.js +590 -288
  138. package/dist/SourceView/Highlighter.js +230 -70
  139. package/dist/SourceView/LineNo.js +72 -17
  140. package/dist/SourceView/index.d.ts.map +1 -1
  141. package/dist/SourceView/index.js +178 -104
  142. package/dist/SourceView/lang-detector/ext-to-lang.json +798 -798
  143. package/dist/SourceView/lang-detector/index.js +28 -14
  144. package/dist/SourceView/useSelectedLineRange.d.ts.map +1 -1
  145. package/dist/SourceView/useSelectedLineRange.js +99 -23
  146. package/dist/Table/ColorCell.js +42 -1
  147. package/dist/Table/ColumnsVisibility.js +114 -6
  148. package/dist/Table/MoreDropdown.d.ts.map +1 -1
  149. package/dist/Table/MoreDropdown.js +122 -25
  150. package/dist/Table/TableContextMenu.d.ts.map +1 -1
  151. package/dist/Table/TableContextMenu.js +151 -137
  152. package/dist/Table/TableContextMenuWrapper.js +59 -14
  153. package/dist/Table/hooks/useColorManagement.js +58 -16
  154. package/dist/Table/hooks/useTableConfiguration.d.ts.map +1 -1
  155. package/dist/Table/hooks/useTableConfiguration.js +333 -169
  156. package/dist/Table/index.d.ts.map +1 -1
  157. package/dist/Table/index.js +222 -128
  158. package/dist/Table/utils/functions.js +169 -144
  159. package/dist/Table/utils/topAndBottomExpandedRowModel.js +69 -52
  160. package/dist/TimelineGuide/index.js +209 -16
  161. package/dist/TopTable/benchmarks/benchdata/populateData.js +91 -0
  162. package/dist/TopTable/index.d.ts.map +1 -1
  163. package/dist/TopTable/index.js +342 -123
  164. package/dist/contexts/LabelsQueryProvider.js +94 -32
  165. package/dist/contexts/UnifiedLabelsContext.js +114 -49
  166. package/dist/contexts/utils.js +37 -15
  167. package/dist/hooks/useCompareModeMeta.d.ts.map +1 -1
  168. package/dist/hooks/useCompareModeMeta.js +158 -64
  169. package/dist/hooks/useLabels.js +295 -52
  170. package/dist/hooks/useQueryState.d.ts +3 -3
  171. package/dist/hooks/useQueryState.d.ts.map +1 -1
  172. package/dist/hooks/useQueryState.js +373 -332
  173. package/dist/index.d.ts +2 -3
  174. package/dist/index.d.ts.map +1 -1
  175. package/dist/index.js +22 -8
  176. package/dist/testdata/fg-diff.json +3750 -0
  177. package/dist/testdata/fg-simple.json +1879 -0
  178. package/dist/testdata/link_data.json +56 -0
  179. package/dist/testdata/tabular.json +30 -0
  180. package/dist/testdata/test_flamegraph.json +26846 -0
  181. package/dist/testdata/test_graph.json +53 -0
  182. package/dist/useDelayedLoader.js +32 -18
  183. package/dist/useGrpcQuery/index.js +71 -11
  184. package/dist/useHasProfileData.js +90 -12
  185. package/dist/useQuery.js +205 -64
  186. package/dist/useSumBy.d.ts +1 -1
  187. package/dist/useSumBy.d.ts.map +1 -1
  188. package/dist/useSumBy.js +294 -138
  189. package/dist/utils.js +62 -30
  190. package/package.json +9 -10
  191. package/src/GraphTooltipArrow/index.tsx +3 -0
  192. package/src/GraphTooltipArrow/useGraphTooltipMetaInfo/index.ts +13 -11
  193. package/src/MatchersInput/SuggestionsList.test.tsx +70 -0
  194. package/src/MatchersInput/SuggestionsList.tsx +11 -10
  195. package/src/MatchersInput/index.tsx +1 -1
  196. package/src/MetricsGraph/MetricsTooltip/index.tsx +22 -34
  197. package/src/PreSelectedMatchers/index.tsx +3 -0
  198. package/src/ProfileExplorer/ProfileExplorerCompare.tsx +9 -4
  199. package/src/ProfileFlameChart/SamplesStrips/index.tsx +2 -2
  200. package/src/ProfileFlameChart/index.tsx +28 -21
  201. package/src/ProfileFlameGraph/FlameGraphArrow/ContextMenu.tsx +9 -10
  202. package/src/ProfileFlameGraph/FlameGraphArrow/TextWithEllipsis.tsx +6 -5
  203. package/src/ProfileFlameGraph/FlameGraphArrow/TooltipContext.tsx +3 -0
  204. package/src/ProfileFlameGraph/FlameGraphArrow/ZoomControls.tsx +3 -0
  205. package/src/ProfileFlameGraph/FlameGraphArrow/useBatchedRendering.ts +3 -0
  206. package/src/ProfileFlameGraph/index.tsx +9 -6
  207. package/src/ProfileMetricsGraph/index.tsx +8 -6
  208. package/src/ProfileSelector/MetricsGraphSection.tsx +10 -5
  209. package/src/ProfileSelector/index.tsx +61 -39
  210. package/src/ProfileView/components/ActionButtons/SortByDropdown.tsx +6 -10
  211. package/src/ProfileView/components/ColorStackLegend.tsx +4 -2
  212. package/src/ProfileView/components/InvertCallStack/index.tsx +4 -5
  213. package/src/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.test.tsx +192 -94
  214. package/src/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.ts +21 -21
  215. package/src/ProfileView/components/Toolbars/MultiLevelDropdown.tsx +28 -24
  216. package/src/ProfileView/components/Toolbars/TableColumnsDropdown.tsx +5 -4
  217. package/src/ProfileView/components/Toolbars/index.tsx +3 -3
  218. package/src/ProfileView/components/ViewSelector/index.tsx +16 -9
  219. package/src/ProfileView/components/VisualizationContainer/index.tsx +3 -0
  220. package/src/ProfileView/context/DashboardContext.tsx +6 -6
  221. package/src/ProfileView/hooks/useResetFlameGraphState.ts +4 -6
  222. package/src/ProfileView/hooks/useResetStateOnProfileTypeChange.ts +26 -24
  223. package/src/ProfileView/hooks/useResetStateOnSeriesChange.ts +8 -16
  224. package/src/ProfileView/hooks/useVisualizationState.ts +69 -61
  225. package/src/ProfileViewWithData.tsx +35 -29
  226. package/src/Sandwich/index.tsx +3 -4
  227. package/src/SourceView/index.tsx +2 -4
  228. package/src/SourceView/useSelectedLineRange.ts +19 -34
  229. package/src/Table/MoreDropdown.tsx +11 -9
  230. package/src/Table/TableContextMenu.tsx +13 -10
  231. package/src/Table/hooks/useTableConfiguration.tsx +11 -16
  232. package/src/Table/index.tsx +21 -12
  233. package/src/TopTable/index.tsx +4 -3
  234. package/src/hooks/useCompareModeMeta.ts +91 -61
  235. package/src/hooks/useQueryState.test.tsx +345 -275
  236. package/src/hooks/useQueryState.ts +118 -136
  237. package/src/index.tsx +15 -16
  238. package/src/useDelayedLoader.ts +10 -10
  239. package/src/useSumBy.ts +15 -21
  240. package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.test.js +0 -455
  241. package/dist/hooks/urlParsers.d.ts +0 -18
  242. package/dist/hooks/urlParsers.d.ts.map +0 -1
  243. package/dist/hooks/urlParsers.js +0 -32
  244. package/dist/hooks/useColorBy.d.ts +0 -5
  245. package/dist/hooks/useColorBy.d.ts.map +0 -1
  246. package/dist/hooks/useColorBy.js +0 -26
  247. package/dist/hooks/useDashboardItems.d.ts +0 -5
  248. package/dist/hooks/useDashboardItems.d.ts.map +0 -1
  249. package/dist/hooks/useDashboardItems.js +0 -27
  250. package/dist/hooks/useQueryState.test.js +0 -868
  251. package/src/hooks/urlParsers.ts +0 -38
  252. package/src/hooks/useColorBy.ts +0 -42
  253. package/src/hooks/useDashboardItems.ts +0 -46
@@ -1,4 +1,13 @@
1
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
1
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
2
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
4
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
5
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
6
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
8
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
9
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
2
11
  // Copyright 2022 The Parca Authors
3
12
  // Licensed under the Apache License, Version 2.0 (the "License");
4
13
  // you may not use this file except in compliance with the License.
@@ -11,121 +20,186 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
11
20
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
21
  // See the License for the specific language governing permissions and
13
22
  // limitations under the License.
23
+
14
24
  import React, { useCallback, useEffect, useMemo } from 'react';
15
25
  import { tableFromIPC } from '@uwdata/flechette';
16
26
  import { AnimatePresence, motion } from 'framer-motion';
17
- import { useQueryState } from 'nuqs';
18
27
  import { Item, Menu, useContextMenu } from 'react-contexify';
19
- import { SourceSkeleton, useParcaContext } from '@parca/components';
28
+ import { SourceSkeleton, useParcaContext, useURLState } from '@parca/components';
20
29
  import { ExpandOnHover } from '../GraphTooltipArrow/ExpandOnHoverValue';
21
- import { stringParam } from '../hooks/urlParsers';
22
30
  import { alignedUint8Array, truncateStringReverse } from '../utils';
23
31
  import { Highlighter, profileAwareRenderer } from './Highlighter';
24
32
  import useLineRange from './useSelectedLineRange';
25
- const MENU_ID = 'source-view-context-menu';
26
- export const SourceView = React.memo(function SourceView({ data, loading, total, filtered, setActionButtons, }) {
27
- const [sourceFileName] = useQueryState('source_filename', stringParam);
28
- const { isDarkMode, sourceViewContextMenuItems = [] } = useParcaContext();
29
- const sourceCode = useMemo(() => {
30
- if (data === undefined) {
31
- return [''];
32
- }
33
- // To use the array index as line number
34
- return ['', ...data.source.split('\n')];
35
- }, [data]);
36
- const { show } = useContextMenu({
37
- id: MENU_ID,
33
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
34
+ var MENU_ID = 'source-view-context-menu';
35
+ export var SourceView = /*#__PURE__*/React.memo(function SourceView(_ref) {
36
+ var data = _ref.data,
37
+ loading = _ref.loading,
38
+ total = _ref.total,
39
+ filtered = _ref.filtered,
40
+ setActionButtons = _ref.setActionButtons;
41
+ var _useURLState = useURLState('source_filename'),
42
+ _useURLState2 = _slicedToArray(_useURLState, 1),
43
+ sourceFileName = _useURLState2[0];
44
+ var _useParcaContext = useParcaContext(),
45
+ isDarkMode = _useParcaContext.isDarkMode,
46
+ _useParcaContext$sour = _useParcaContext.sourceViewContextMenuItems,
47
+ sourceViewContextMenuItems = _useParcaContext$sour === void 0 ? [] : _useParcaContext$sour;
48
+ var sourceCode = useMemo(function () {
49
+ if (data === undefined) {
50
+ return [''];
51
+ }
52
+ // To use the array index as line number
53
+ return [''].concat(_toConsumableArray(data.source.split('\n')));
54
+ }, [data]);
55
+ var _useContextMenu = useContextMenu({
56
+ id: MENU_ID
57
+ }),
58
+ show = _useContextMenu.show;
59
+ var _useLineRange = useLineRange(),
60
+ startLine = _useLineRange.startLine,
61
+ endLine = _useLineRange.endLine;
62
+ var sourceTable = useMemo(function () {
63
+ if (data === undefined) {
64
+ return null;
65
+ }
66
+ var table = tableFromIPC(alignedUint8Array(data.record), {
67
+ useBigInt: true
38
68
  });
39
- const { startLine, endLine } = useLineRange();
40
- const sourceTable = useMemo(() => {
41
- if (data === undefined) {
42
- return null;
43
- }
44
- const table = tableFromIPC(alignedUint8Array(data.record), { useBigInt: true });
45
- return {
46
- numRows: table.numRows,
47
- lineNumbers: table.getChild('line_number'),
48
- cumulative: table.getChild('cumulative'),
49
- flat: table.getChild('flat'),
50
- };
51
- }, [data]);
52
- const getLineData = useCallback((lineNumber) => {
53
- if (sourceTable === null || sourceTable.lineNumbers === null) {
54
- return undefined;
55
- }
56
- const { numRows, lineNumbers, cumulative, flat } = sourceTable;
57
- let lo = 0;
58
- let hi = numRows - 1;
59
- while (lo <= hi) {
60
- const mid = (lo + hi) >>> 1;
61
- const midVal = Number(lineNumbers.get(mid));
62
- if (midVal === lineNumber) {
63
- return {
64
- cumulative: cumulative?.get(mid) ?? 0n,
65
- flat: flat?.get(mid) ?? 0n,
66
- };
67
- }
68
- if (midVal < lineNumber) {
69
- lo = mid + 1;
70
- }
71
- else {
72
- hi = mid - 1;
73
- }
74
- }
75
- return undefined;
76
- }, [sourceTable]);
77
- const getProfileDataForLine = useCallback((line) => {
78
- const data = getLineData(line);
79
- if (data === undefined) {
80
- return undefined;
81
- }
82
- if (data.cumulative === 0n && data.flat === 0n) {
83
- return undefined;
84
- }
69
+ return {
70
+ numRows: table.numRows,
71
+ lineNumbers: table.getChild('line_number'),
72
+ cumulative: table.getChild('cumulative'),
73
+ flat: table.getChild('flat')
74
+ };
75
+ }, [data]);
76
+ var getLineData = useCallback(function (lineNumber) {
77
+ if (sourceTable === null || sourceTable.lineNumbers === null) {
78
+ return undefined;
79
+ }
80
+ var numRows = sourceTable.numRows,
81
+ lineNumbers = sourceTable.lineNumbers,
82
+ cumulative = sourceTable.cumulative,
83
+ flat = sourceTable.flat;
84
+ var lo = 0;
85
+ var hi = numRows - 1;
86
+ while (lo <= hi) {
87
+ var mid = lo + hi >>> 1;
88
+ var midVal = Number(lineNumbers.get(mid));
89
+ if (midVal === lineNumber) {
90
+ var _ref2, _ref3;
85
91
  return {
86
- line,
87
- cumulative: Number(data.cumulative),
88
- flat: Number(data.flat),
92
+ cumulative: (_ref2 = cumulative === null || cumulative === void 0 ? void 0 : cumulative.get(mid)) !== null && _ref2 !== void 0 ? _ref2 : 0n,
93
+ flat: (_ref3 = flat === null || flat === void 0 ? void 0 : flat.get(mid)) !== null && _ref3 !== void 0 ? _ref3 : 0n
89
94
  };
90
- }, [getLineData]);
91
- const [selectedCode, profileData] = useMemo(() => {
92
- if (startLine === -1 && endLine === -1) {
93
- return ['', []];
94
- }
95
- if (startLine === endLine) {
96
- const profileData = [];
97
- const profileDataForLine = getProfileDataForLine(startLine);
98
- if (profileDataForLine != null) {
99
- profileData.push(profileDataForLine);
100
- }
101
- return [sourceCode[startLine - 1], profileData];
102
- }
103
- let code = '';
104
- const profileData = [];
105
- for (let i = startLine; i <= endLine; i++) {
106
- code += sourceCode[i] + '\n';
107
- const profileDataForLine = getProfileDataForLine(i);
108
- if (profileDataForLine != null) {
109
- profileData.push(profileDataForLine);
110
- }
111
- }
112
- return [code, profileData];
113
- }, [startLine, endLine, sourceCode, getProfileDataForLine]);
114
- useEffect(() => {
115
- setActionButtons?.(_jsx("div", { className: "px-2", children: _jsx(ExpandOnHover, { value: sourceFileName, displayValue: truncateStringReverse(sourceFileName, 50) }) }));
116
- }, [sourceFileName, setActionButtons]);
117
- if (loading) {
118
- return (_jsx("div", { className: "h-auto overflow-clip", children: _jsx(SourceSkeleton, { isDarkMode: isDarkMode }) }));
95
+ }
96
+ if (midVal < lineNumber) {
97
+ lo = mid + 1;
98
+ } else {
99
+ hi = mid - 1;
100
+ }
119
101
  }
120
- if (data === undefined) {
121
- return _jsx(_Fragment, { children: "Source code not uploaded for this build." });
102
+ return undefined;
103
+ }, [sourceTable]);
104
+ var getProfileDataForLine = useCallback(function (line) {
105
+ var data_0 = getLineData(line);
106
+ if (data_0 === undefined) {
107
+ return undefined;
122
108
  }
123
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
124
- const onContextMenu = (event) => {
125
- show({
126
- event,
127
- });
109
+ if (data_0.cumulative === 0n && data_0.flat === 0n) {
110
+ return undefined;
111
+ }
112
+ return {
113
+ line: line,
114
+ cumulative: Number(data_0.cumulative),
115
+ flat: Number(data_0.flat)
128
116
  };
129
- return (_jsx(AnimatePresence, { children: _jsxs(motion.div, { className: "h-full w-full", initial: { display: 'none', opacity: 0 }, animate: { display: 'block', opacity: 1 }, transition: { duration: 0.5 }, children: [_jsx(Highlighter, { file: sourceFileName, content: data.source, renderer: profileAwareRenderer(getLineData, total, filtered, onContextMenu) }), sourceViewContextMenuItems.length > 0 ? (_jsx(Menu, { id: MENU_ID, children: sourceViewContextMenuItems.map(item => (_jsx(Item, { onClick: () => item.action(selectedCode, profileData), children: item.label }, item.id))) })) : null] }, "source-view-loaded") }));
117
+ }, [getLineData]);
118
+ var _useMemo = useMemo(function () {
119
+ if (startLine === -1 && endLine === -1) {
120
+ return ['', []];
121
+ }
122
+ if (startLine === endLine) {
123
+ var profileData = [];
124
+ var profileDataForLine = getProfileDataForLine(startLine);
125
+ if (profileDataForLine != null) {
126
+ profileData.push(profileDataForLine);
127
+ }
128
+ return [sourceCode[startLine - 1], profileData];
129
+ }
130
+ var code = '';
131
+ var profileData_0 = [];
132
+ for (var i = startLine; i <= endLine; i++) {
133
+ code += sourceCode[i] + '\n';
134
+ var profileDataForLine_0 = getProfileDataForLine(i);
135
+ if (profileDataForLine_0 != null) {
136
+ profileData_0.push(profileDataForLine_0);
137
+ }
138
+ }
139
+ return [code, profileData_0];
140
+ }, [startLine, endLine, sourceCode, getProfileDataForLine]),
141
+ _useMemo2 = _slicedToArray(_useMemo, 2),
142
+ selectedCode = _useMemo2[0],
143
+ profileData_1 = _useMemo2[1];
144
+ useEffect(function () {
145
+ setActionButtons === null || setActionButtons === void 0 || setActionButtons(/*#__PURE__*/_jsx("div", {
146
+ className: "px-2",
147
+ children: /*#__PURE__*/_jsx(ExpandOnHover, {
148
+ value: sourceFileName,
149
+ displayValue: truncateStringReverse(sourceFileName, 50)
150
+ })
151
+ }));
152
+ }, [sourceFileName, setActionButtons]);
153
+ if (loading) {
154
+ return /*#__PURE__*/_jsx("div", {
155
+ className: "h-auto overflow-clip",
156
+ children: /*#__PURE__*/_jsx(SourceSkeleton, {
157
+ isDarkMode: isDarkMode
158
+ })
159
+ });
160
+ }
161
+ if (data === undefined) {
162
+ return /*#__PURE__*/_jsx(_Fragment, {
163
+ children: "Source code not uploaded for this build."
164
+ });
165
+ }
166
+
167
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
168
+ var onContextMenu = function onContextMenu(event) {
169
+ show({
170
+ event: event
171
+ });
172
+ };
173
+ return /*#__PURE__*/_jsx(AnimatePresence, {
174
+ children: /*#__PURE__*/_jsxs(motion.div, {
175
+ className: "h-full w-full",
176
+ initial: {
177
+ display: 'none',
178
+ opacity: 0
179
+ },
180
+ animate: {
181
+ display: 'block',
182
+ opacity: 1
183
+ },
184
+ transition: {
185
+ duration: 0.5
186
+ },
187
+ children: [/*#__PURE__*/_jsx(Highlighter, {
188
+ file: sourceFileName,
189
+ content: data.source,
190
+ renderer: profileAwareRenderer(getLineData, total, filtered, onContextMenu)
191
+ }), sourceViewContextMenuItems.length > 0 ? /*#__PURE__*/_jsx(Menu, {
192
+ id: MENU_ID,
193
+ children: sourceViewContextMenuItems.map(function (item) {
194
+ return /*#__PURE__*/_jsx(Item, {
195
+ onClick: function onClick() {
196
+ return item.action(selectedCode, profileData_1);
197
+ },
198
+ children: item.label
199
+ }, item.id);
200
+ })
201
+ }) : null]
202
+ }, "source-view-loaded")
203
+ });
130
204
  });
131
- export default SourceView;
205
+ export default SourceView;