@perses-dev/components 0.55.0-beta.9 → 0.55.0-rc.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 (97) hide show
  1. package/dist/DragAndDrop/DragAndDropList.d.ts +10 -2
  2. package/dist/DragAndDrop/DragAndDropList.d.ts.map +1 -1
  3. package/dist/DragAndDrop/DragAndDropList.js +6 -4
  4. package/dist/DragAndDrop/DragAndDropList.js.map +1 -1
  5. package/dist/EChart/EChart.d.ts +1 -1
  6. package/dist/EChart/EChart.d.ts.map +1 -1
  7. package/dist/EChart/EChart.js +12 -25
  8. package/dist/EChart/EChart.js.map +1 -1
  9. package/dist/FormatControls/FormatControls.d.ts.map +1 -1
  10. package/dist/FormatControls/FormatControls.js +42 -4
  11. package/dist/FormatControls/FormatControls.js.map +1 -1
  12. package/dist/FormatControls/UnitSelector.js +4 -4
  13. package/dist/FormatControls/UnitSelector.js.map +1 -1
  14. package/dist/Legend/TableLegend.d.ts.map +1 -1
  15. package/dist/Legend/TableLegend.js +2 -1
  16. package/dist/Legend/TableLegend.js.map +1 -1
  17. package/dist/LinksEditor/LinkEditorForm.d.ts +1 -0
  18. package/dist/LinksEditor/LinkEditorForm.d.ts.map +1 -1
  19. package/dist/LinksEditor/LinkEditorForm.js +1 -0
  20. package/dist/LinksEditor/LinkEditorForm.js.map +1 -1
  21. package/dist/OptionsEditorLayout/OptionsEditorControl.d.ts.map +1 -1
  22. package/dist/OptionsEditorLayout/OptionsEditorControl.js +2 -3
  23. package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -1
  24. package/dist/SettingsAutocomplete/SettingsAutocomplete.d.ts.map +1 -1
  25. package/dist/SettingsAutocomplete/SettingsAutocomplete.js +6 -3
  26. package/dist/SettingsAutocomplete/SettingsAutocomplete.js.map +1 -1
  27. package/dist/Table/Table.d.ts.map +1 -1
  28. package/dist/Table/Table.js +3 -0
  29. package/dist/Table/Table.js.map +1 -1
  30. package/dist/Table/TableToolbar.d.ts.map +1 -1
  31. package/dist/Table/TableToolbar.js +1 -0
  32. package/dist/Table/TableToolbar.js.map +1 -1
  33. package/dist/Table/VirtualizedTable.d.ts +1 -1
  34. package/dist/Table/VirtualizedTable.d.ts.map +1 -1
  35. package/dist/Table/VirtualizedTable.js +10 -19
  36. package/dist/Table/VirtualizedTable.js.map +1 -1
  37. package/dist/Table/model/table-model.d.ts +6 -2
  38. package/dist/Table/model/table-model.d.ts.map +1 -1
  39. package/dist/Table/model/table-model.js.map +1 -1
  40. package/dist/ThresholdsEditor/ThresholdsEditor.js +1 -3
  41. package/dist/ThresholdsEditor/ThresholdsEditor.js.map +1 -1
  42. package/dist/TimeRangeSelector/DateTimeRangePicker.js +1 -1
  43. package/dist/TimeRangeSelector/DateTimeRangePicker.js.map +1 -1
  44. package/dist/TimeRangeSelector/TimeRangeSelector.js +4 -4
  45. package/dist/TimeRangeSelector/TimeRangeSelector.js.map +1 -1
  46. package/dist/TimeSeriesTooltip/TimeChartTooltip.d.ts.map +1 -1
  47. package/dist/TimeSeriesTooltip/TimeChartTooltip.js +27 -16
  48. package/dist/TimeSeriesTooltip/TimeChartTooltip.js.map +1 -1
  49. package/dist/TimeSeriesTooltip/utils.d.ts.map +1 -1
  50. package/dist/TimeSeriesTooltip/utils.js +6 -2
  51. package/dist/TimeSeriesTooltip/utils.js.map +1 -1
  52. package/dist/TransformsEditor/TransformEditor.d.ts.map +1 -1
  53. package/dist/TransformsEditor/TransformEditor.js +89 -0
  54. package/dist/TransformsEditor/TransformEditor.js.map +1 -1
  55. package/dist/controls/TextField.d.ts.map +1 -1
  56. package/dist/controls/TextField.js +15 -10
  57. package/dist/controls/TextField.js.map +1 -1
  58. package/dist/model/custom.d.ts +22 -0
  59. package/dist/model/custom.d.ts.map +1 -0
  60. package/dist/model/custom.js +243 -0
  61. package/dist/model/custom.js.map +1 -0
  62. package/dist/model/index.d.ts +1 -0
  63. package/dist/model/index.d.ts.map +1 -1
  64. package/dist/model/index.js +1 -0
  65. package/dist/model/index.js.map +1 -1
  66. package/dist/model/transforms.d.ts +22 -1
  67. package/dist/model/transforms.d.ts.map +1 -1
  68. package/dist/model/transforms.js +2 -1
  69. package/dist/model/transforms.js.map +1 -1
  70. package/dist/model/units.d.ts +12 -10
  71. package/dist/model/units.d.ts.map +1 -1
  72. package/dist/model/units.js +33 -28
  73. package/dist/model/units.js.map +1 -1
  74. package/dist/utils/index.d.ts +0 -2
  75. package/dist/utils/index.d.ts.map +1 -1
  76. package/dist/utils/index.js +0 -2
  77. package/dist/utils/index.js.map +1 -1
  78. package/dist/utils/text.d.ts.map +1 -1
  79. package/dist/utils/text.js +14 -18
  80. package/dist/utils/text.js.map +1 -1
  81. package/dist/utils/transform-data.d.ts +5 -0
  82. package/dist/utils/transform-data.d.ts.map +1 -1
  83. package/dist/utils/transform-data.js +96 -0
  84. package/dist/utils/transform-data.js.map +1 -1
  85. package/dist/utils/variable-interpolation.d.ts +11 -0
  86. package/dist/utils/variable-interpolation.d.ts.map +1 -1
  87. package/dist/utils/variable-interpolation.js +64 -0
  88. package/dist/utils/variable-interpolation.js.map +1 -1
  89. package/package.json +3 -3
  90. package/dist/utils/component-ids.d.ts +0 -8
  91. package/dist/utils/component-ids.d.ts.map +0 -1
  92. package/dist/utils/component-ids.js +0 -27
  93. package/dist/utils/component-ids.js.map +0 -1
  94. package/dist/utils/memo.d.ts +0 -13
  95. package/dist/utils/memo.d.ts.map +0 -1
  96. package/dist/utils/memo.js +0 -50
  97. package/dist/utils/memo.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import type { ReactElement, ReactNode } from 'react';
1
+ import type { ReactElement, ReactNode, RefObject } from 'react';
2
2
  interface MonitorElementsProps {
3
3
  elements: Array<Record<string, unknown>>;
4
4
  accessKey: string;
@@ -18,7 +18,15 @@ export declare function useDragAndDropMonitor({ elements, accessKey, axis, onCha
18
18
  export interface DragAndDropElementProps {
19
19
  children: ReactNode;
20
20
  data: Record<string, unknown>;
21
+ /**
22
+ * Ref of the element used as drag handle (e.g. a `DragButton`). When provided, the drag can only be started from
23
+ * this element. Otherwise, the drag can be started from anywhere in the element.
24
+ */
25
+ dragHandleRef?: RefObject<HTMLElement | null>;
21
26
  }
22
- export declare function DragAndDropElement({ children, data }: DragAndDropElementProps): ReactElement;
27
+ /**
28
+ * This component wraps the children that should be draggable.
29
+ */
30
+ export declare function DragAndDropElement({ children, data, dragHandleRef }: DragAndDropElementProps): ReactElement;
23
31
  export {};
24
32
  //# sourceMappingURL=DragAndDropList.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DragAndDropList.d.ts","sourceRoot":"","sources":["../../src/DragAndDrop/DragAndDropList.tsx"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAOrD,UAAU,oBAAoB;IAC5B,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,UAAU,GAAG,YAAY,CAAC;IACjC,QAAQ,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,KAAK,IAAI,CAAC;CAC9D;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,QAAQ,EACR,SAAS,EACT,IAAiB,EACjB,QAAQ,GACT,EAAE,oBAAoB,GAAG,IAAI,CAiC7B;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,SAAS,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAKD,wBAAgB,kBAAkB,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,uBAAuB,GAAG,YAAY,CA4E5F"}
1
+ {"version":3,"file":"DragAndDropList.d.ts","sourceRoot":"","sources":["../../src/DragAndDrop/DragAndDropList.tsx"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAOhE,UAAU,oBAAoB;IAC5B,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,UAAU,GAAG,YAAY,CAAC;IACjC,QAAQ,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,KAAK,IAAI,CAAC;CAC9D;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,QAAQ,EACR,SAAS,EACT,IAAiB,EACjB,QAAQ,GACT,EAAE,oBAAoB,GAAG,IAAI,CAiC7B;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,SAAS,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B;;;OAGG;IACH,aAAa,CAAC,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;CAC/C;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE,uBAAuB,GAAG,YAAY,CA6E3G"}
@@ -59,9 +59,9 @@ import { idle } from "./model.js";
59
59
  onChange
60
60
  ]);
61
61
  }
62
- /*
63
- * This component wraps the children that should be draggable
64
- */ export function DragAndDropElement({ children, data }) {
62
+ /**
63
+ * This component wraps the children that should be draggable.
64
+ */ export function DragAndDropElement({ children, data, dragHandleRef }) {
65
65
  const ref = useRef(null);
66
66
  const [state, setState] = useState(idle);
67
67
  useEffect(()=>{
@@ -71,6 +71,7 @@ import { idle } from "./model.js";
71
71
  }
72
72
  return combine(draggable({
73
73
  element,
74
+ dragHandle: dragHandleRef?.current ?? undefined,
74
75
  getInitialData () {
75
76
  return data;
76
77
  },
@@ -134,7 +135,8 @@ import { idle } from "./model.js";
134
135
  }
135
136
  }));
136
137
  }, [
137
- data
138
+ data,
139
+ dragHandleRef
138
140
  ]);
139
141
  return /*#__PURE__*/ _jsxs(Stack, {
140
142
  ref: ref,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/DragAndDrop/DragAndDropList.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { attachClosestEdge, extractClosestEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge';\nimport { reorderWithEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/util/reorder-with-edge';\nimport { combine } from '@atlaskit/pragmatic-drag-and-drop/combine';\nimport {\n monitorForElements,\n draggable,\n dropTargetForElements,\n} from '@atlaskit/pragmatic-drag-and-drop/element/adapter';\nimport { Stack } from '@mui/material';\nimport type { ReactElement, ReactNode } from 'react';\nimport { useEffect, useRef, useState } from 'react';\n\nimport { DropIndicator } from './DropIndicator';\nimport type { State } from './model';\nimport { idle } from './model';\n\ninterface MonitorElementsProps {\n elements: Array<Record<string, unknown>>;\n accessKey: string;\n axis?: 'vertical' | 'horizontal';\n onChange: (elements: Array<Record<string, unknown>>) => void;\n}\n\n/**\n * This hook is responsible for monitoring the drag and drop of elements.\n * It will call the onChange function with the new order of elements when a drop is detected.\n *\n * @param elements - The list of elements to monitor\n * @param accessKey - The key to use to identify the elements (key of the object)\n * @param axis - The axis to monitor the drag and drop on\n * @param onChange - The function to call when a drop is detected\n */\nexport function useDragAndDropMonitor({\n elements,\n accessKey,\n axis = 'vertical',\n onChange,\n}: MonitorElementsProps): void {\n return useEffect(() => {\n return monitorForElements({\n onDrop({ location, source }) {\n const target = location.current.dropTargets[0];\n if (!target) {\n return;\n }\n\n const sourceData = source.data;\n const targetData = target.data;\n\n const indexOfSource = elements.findIndex((column) => column[accessKey] === sourceData[accessKey]);\n const indexOfTarget = elements.findIndex((column) => column[accessKey] === targetData[accessKey]);\n\n if (indexOfTarget < 0 || indexOfSource < 0) {\n return;\n }\n\n const closestEdgeOfTarget = extractClosestEdge(targetData);\n\n onChange(\n reorderWithEdge({\n list: elements,\n startIndex: indexOfSource,\n indexOfTarget,\n closestEdgeOfTarget,\n axis: axis,\n }),\n );\n },\n });\n }, [accessKey, axis, elements, onChange]);\n}\n\nexport interface DragAndDropElementProps {\n children: ReactNode;\n data: Record<string, unknown>;\n}\n\n/*\n * This component wraps the children that should be draggable\n */\nexport function DragAndDropElement({ children, data }: DragAndDropElementProps): ReactElement {\n const ref = useRef<HTMLDivElement>(null);\n const [state, setState] = useState<State>(idle);\n\n useEffect(() => {\n const element = ref.current;\n if (!element) {\n return;\n }\n\n return combine(\n draggable({\n element,\n getInitialData() {\n return data;\n },\n onDragStart() {\n setState({ type: 'is-dragging' });\n },\n onDrop() {\n setState(idle);\n },\n }),\n dropTargetForElements({\n element,\n canDrop({ source }) {\n // not allowing dropping on yourself\n if (source.element === element) {\n return false;\n }\n // only allowing tasks to be dropped on me\n return true;\n },\n getData({ input }) {\n return attachClosestEdge(data, {\n element,\n input,\n allowedEdges: ['top', 'bottom'],\n });\n },\n getIsSticky() {\n return true;\n },\n onDragEnter({ self }) {\n const closestEdge = extractClosestEdge(self.data);\n setState({ type: 'is-dragging-over', closestEdge });\n },\n onDrag({ self }) {\n const closestEdge = extractClosestEdge(self.data);\n\n // Only need to update react state if nothing has changed.\n // Prevents re-rendering.\n setState((current) => {\n if (current.type === 'is-dragging-over' && current.closestEdge === closestEdge) {\n return current;\n }\n return { type: 'is-dragging-over', closestEdge };\n });\n },\n onDragLeave() {\n setState(idle);\n },\n onDrop() {\n setState(idle);\n },\n }),\n );\n }, [data]);\n\n return (\n <Stack ref={ref} spacing={1} style={{ opacity: state.type === 'is-dragging' ? 0.5 : 'unset' }}>\n {state.type === 'is-dragging-over' && state.closestEdge === 'top' ? <DropIndicator /> : null}\n {children}\n {state.type === 'is-dragging-over' && state.closestEdge === 'bottom' ? <DropIndicator /> : null}\n </Stack>\n );\n}\n"],"names":["attachClosestEdge","extractClosestEdge","reorderWithEdge","combine","monitorForElements","draggable","dropTargetForElements","Stack","useEffect","useRef","useState","DropIndicator","idle","useDragAndDropMonitor","elements","accessKey","axis","onChange","onDrop","location","source","target","current","dropTargets","sourceData","data","targetData","indexOfSource","findIndex","column","indexOfTarget","closestEdgeOfTarget","list","startIndex","DragAndDropElement","children","ref","state","setState","element","getInitialData","onDragStart","type","canDrop","getData","input","allowedEdges","getIsSticky","onDragEnter","self","closestEdge","onDrag","onDragLeave","spacing","style","opacity"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,iBAAiB,EAAEC,kBAAkB,QAAQ,wDAAwD;AAC9G,SAASC,eAAe,QAAQ,kEAAkE;AAClG,SAASC,OAAO,QAAQ,4CAA4C;AACpE,SACEC,kBAAkB,EAClBC,SAAS,EACTC,qBAAqB,QAChB,oDAAoD;AAC3D,SAASC,KAAK,QAAQ,gBAAgB;AAEtC,SAASC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAEpD,SAASC,aAAa,QAAQ,qBAAkB;AAEhD,SAASC,IAAI,QAAQ,aAAU;AAS/B;;;;;;;;CAQC,GACD,OAAO,SAASC,sBAAsB,EACpCC,QAAQ,EACRC,SAAS,EACTC,OAAO,UAAU,EACjBC,QAAQ,EACa;IAC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gBAC1C,OAAO;YACT;YACAK,SAAQ,EAAEC,KAAK,EAAE;gBACf,OAAO7C,kBAAkByB,MAAM;oBAC7Bc;oBACAM;oBACAC,cAAc;wBAAC;wBAAO;qBAAS;gBACjC;YACF;YACAC;gBACE,OAAO;YACT;YACAC,aAAY,EAAEC,IAAI,EAAE;gBAClB,MAAMC,cAAcjD,mBAAmBgD,KAAKxB,IAAI;gBAChDa,SAAS;oBAAEI,MAAM;oBAAoBQ;gBAAY;YACnD;YACAC,QAAO,EAAEF,IAAI,EAAE;gBACb,MAAMC,cAAcjD,mBAAmBgD,KAAKxB,IAAI;gBAEhD,0DAA0D;gBAC1D,yBAAyB;gBACzBa,SAAS,CAAChB;oBACR,IAAIA,QAAQoB,IAAI,KAAK,sBAAsBpB,QAAQ4B,WAAW,KAAKA,aAAa;wBAC9E,OAAO5B;oBACT;oBACA,OAAO;wBAAEoB,MAAM;wBAAoBQ;oBAAY;gBACjD;YACF;YACAE;gBACEd,SAAS1B;YACX;YACAM;gBACEoB,SAAS1B;YACX;QACF;IAEJ,GAAG;QAACa;KAAK;IAET,qBACE,MAAClB;QAAM6B,KAAKA;QAAKiB,SAAS;QAAGC,OAAO;YAAEC,SAASlB,MAAMK,IAAI,KAAK,gBAAgB,MAAM;QAAQ;;YACzFL,MAAMK,IAAI,KAAK,sBAAsBL,MAAMa,WAAW,KAAK,sBAAQ,KAACvC,qBAAmB;YACvFwB;YACAE,MAAMK,IAAI,KAAK,sBAAsBL,MAAMa,WAAW,KAAK,yBAAW,KAACvC,qBAAmB;;;AAGjG"}
1
+ {"version":3,"sources":["../../src/DragAndDrop/DragAndDropList.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { attachClosestEdge, extractClosestEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge';\nimport { reorderWithEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/util/reorder-with-edge';\nimport { combine } from '@atlaskit/pragmatic-drag-and-drop/combine';\nimport {\n monitorForElements,\n draggable,\n dropTargetForElements,\n} from '@atlaskit/pragmatic-drag-and-drop/element/adapter';\nimport { Stack } from '@mui/material';\nimport type { ReactElement, ReactNode, RefObject } from 'react';\nimport { useEffect, useRef, useState } from 'react';\n\nimport { DropIndicator } from './DropIndicator';\nimport type { State } from './model';\nimport { idle } from './model';\n\ninterface MonitorElementsProps {\n elements: Array<Record<string, unknown>>;\n accessKey: string;\n axis?: 'vertical' | 'horizontal';\n onChange: (elements: Array<Record<string, unknown>>) => void;\n}\n\n/**\n * This hook is responsible for monitoring the drag and drop of elements.\n * It will call the onChange function with the new order of elements when a drop is detected.\n *\n * @param elements - The list of elements to monitor\n * @param accessKey - The key to use to identify the elements (key of the object)\n * @param axis - The axis to monitor the drag and drop on\n * @param onChange - The function to call when a drop is detected\n */\nexport function useDragAndDropMonitor({\n elements,\n accessKey,\n axis = 'vertical',\n onChange,\n}: MonitorElementsProps): void {\n return useEffect(() => {\n return monitorForElements({\n onDrop({ location, source }) {\n const target = location.current.dropTargets[0];\n if (!target) {\n return;\n }\n\n const sourceData = source.data;\n const targetData = target.data;\n\n const indexOfSource = elements.findIndex((column) => column[accessKey] === sourceData[accessKey]);\n const indexOfTarget = elements.findIndex((column) => column[accessKey] === targetData[accessKey]);\n\n if (indexOfTarget < 0 || indexOfSource < 0) {\n return;\n }\n\n const closestEdgeOfTarget = extractClosestEdge(targetData);\n\n onChange(\n reorderWithEdge({\n list: elements,\n startIndex: indexOfSource,\n indexOfTarget,\n closestEdgeOfTarget,\n axis: axis,\n }),\n );\n },\n });\n }, [accessKey, axis, elements, onChange]);\n}\n\nexport interface DragAndDropElementProps {\n children: ReactNode;\n data: Record<string, unknown>;\n /**\n * Ref of the element used as drag handle (e.g. a `DragButton`). When provided, the drag can only be started from\n * this element. Otherwise, the drag can be started from anywhere in the element.\n */\n dragHandleRef?: RefObject<HTMLElement | null>;\n}\n\n/**\n * This component wraps the children that should be draggable.\n */\nexport function DragAndDropElement({ children, data, dragHandleRef }: DragAndDropElementProps): ReactElement {\n const ref = useRef<HTMLDivElement>(null);\n const [state, setState] = useState<State>(idle);\n\n useEffect(() => {\n const element = ref.current;\n if (!element) {\n return;\n }\n\n return combine(\n draggable({\n element,\n dragHandle: dragHandleRef?.current ?? undefined,\n getInitialData() {\n return data;\n },\n onDragStart() {\n setState({ type: 'is-dragging' });\n },\n onDrop() {\n setState(idle);\n },\n }),\n dropTargetForElements({\n element,\n canDrop({ source }) {\n // not allowing dropping on yourself\n if (source.element === element) {\n return false;\n }\n // only allowing tasks to be dropped on me\n return true;\n },\n getData({ input }) {\n return attachClosestEdge(data, {\n element,\n input,\n allowedEdges: ['top', 'bottom'],\n });\n },\n getIsSticky() {\n return true;\n },\n onDragEnter({ self }) {\n const closestEdge = extractClosestEdge(self.data);\n setState({ type: 'is-dragging-over', closestEdge });\n },\n onDrag({ self }) {\n const closestEdge = extractClosestEdge(self.data);\n\n // Only need to update react state if nothing has changed.\n // Prevents re-rendering.\n setState((current) => {\n if (current.type === 'is-dragging-over' && current.closestEdge === closestEdge) {\n return current;\n }\n return { type: 'is-dragging-over', closestEdge };\n });\n },\n onDragLeave() {\n setState(idle);\n },\n onDrop() {\n setState(idle);\n },\n }),\n );\n }, [data, dragHandleRef]);\n\n return (\n <Stack ref={ref} spacing={1} style={{ opacity: state.type === 'is-dragging' ? 0.5 : 'unset' }}>\n {state.type === 'is-dragging-over' && state.closestEdge === 'top' ? <DropIndicator /> : null}\n {children}\n {state.type === 'is-dragging-over' && state.closestEdge === 'bottom' ? <DropIndicator /> : null}\n </Stack>\n );\n}\n"],"names":["attachClosestEdge","extractClosestEdge","reorderWithEdge","combine","monitorForElements","draggable","dropTargetForElements","Stack","useEffect","useRef","useState","DropIndicator","idle","useDragAndDropMonitor","elements","accessKey","axis","onChange","onDrop","location","source","target","current","dropTargets","sourceData","data","targetData","indexOfSource","findIndex","column","indexOfTarget","closestEdgeOfTarget","list","startIndex","DragAndDropElement","children","dragHandleRef","ref","state","setState","element","dragHandle","undefined","getInitialData","onDragStart","type","canDrop","getData","input","allowedEdges","getIsSticky","onDragEnter","self","closestEdge","onDrag","onDragLeave","spacing","style","opacity"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,iBAAiB,EAAEC,kBAAkB,QAAQ,wDAAwD;AAC9G,SAASC,eAAe,QAAQ,kEAAkE;AAClG,SAASC,OAAO,QAAQ,4CAA4C;AACpE,SACEC,kBAAkB,EAClBC,SAAS,EACTC,qBAAqB,QAChB,oDAAoD;AAC3D,SAASC,KAAK,QAAQ,gBAAgB;AAEtC,SAASC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAEpD,SAASC,aAAa,QAAQ,qBAAkB;AAEhD,SAASC,IAAI,QAAQ,aAAU;AAS/B;;;;;;;;CAQC,GACD,OAAO,SAASC,sBAAsB,EACpCC,QAAQ,EACRC,SAAS,EACTC,OAAO,UAAU,EACjBC,QAAQ,EACa;IACrB,OAAOT,UAAU;QACf,OAAOJ,mBAAmB;YACxBc,QAAO,EAAEC,QAAQ,EAAEC,MAAM,EAAE;gBACzB,MAAMC,SAASF,SAASG,OAAO,CAACC,WAAW,CAAC,EAAE;gBAC9C,IAAI,CAACF,QAAQ;oBACX;gBACF;gBAEA,MAAMG,aAAaJ,OAAOK,IAAI;gBAC9B,MAAMC,aAAaL,OAAOI,I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ClB,MAAMC,cAAcpD,mBAAmBmD,KAAK3B,IAAI;gBAChDc,SAAS;oBAAEM,MAAM;oBAAoBQ;gBAAY;YACnD;YACAC,QAAO,EAAEF,IAAI,EAAE;gBACb,MAAMC,cAAcpD,mBAAmBmD,KAAK3B,IAAI;gBAEhD,0DAA0D;gBAC1D,yBAAyB;gBACzBc,SAAS,CAACjB;oBACR,IAAIA,QAAQuB,IAAI,KAAK,sBAAsBvB,QAAQ+B,WAAW,KAAKA,aAAa;wBAC9E,OAAO/B;oBACT;oBACA,OAAO;wBAAEuB,MAAM;wBAAoBQ;oBAAY;gBACjD;YACF;YACAE;gBACEhB,SAAS3B;YACX;YACAM;gBACEqB,SAAS3B;YACX;QACF;IAEJ,GAAG;QAACa;QAAMW;KAAc;IAExB,qBACE,MAAC7B;QAAM8B,KAAKA;QAAKmB,SAAS;QAAGC,OAAO;YAAEC,SAASpB,MAAMO,IAAI,KAAK,gBAAgB,MAAM;QAAQ;;YACzFP,MAAMO,IAAI,KAAK,sBAAsBP,MAAMe,WAAW,KAAK,sBAAQ,KAAC1C,qBAAmB;YACvFwB;YACAG,MAAMO,IAAI,KAAK,sBAAsBP,MAAMe,WAAW,KAAK,yBAAW,KAAC1C,qBAAmB;;;AAGjG"}
@@ -58,6 +58,6 @@ export interface EChartsProps<T> {
58
58
  syncGroup?: string;
59
59
  onChartInitialized?: (instance: ECharts) => void;
60
60
  }
61
- export declare const EChart: import("react").MemoExoticComponent<<T>({ option, theme, renderer, sx, style, onEvents, _instance, syncGroup, onChartInitialized, }: EChartsProps<T>) => import("react/jsx-runtime").JSX.Element>;
61
+ export declare const EChart: import("react").MemoExoticComponent<<T>({ option, theme, renderer, sx, style, onEvents, _instance: instanceRef, syncGroup, onChartInitialized, }: EChartsProps<T>) => import("react/jsx-runtime").JSX.Element>;
62
62
  export {};
63
63
  //# sourceMappingURL=EChart.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"EChart.d.ts","sourceRoot":"","sources":["../../src/EChart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AAM,EAAE,iBAAiB,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,GAAG,YAAY,CAAC;IAC9B,QAAQ,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAC;IAC5B,EAAE,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACpB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,QAAQ,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAC3B,SAAS,CAAC,EAAE,KAAK,CAAC,gBAAgB,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC;IACxD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;CAClD;AAED,eAAO,MAAM,MAAM,uCAAwB,CAAC,4GAUzC,YAAY,CAAC,CAAC,CAAC,6CAuEhB,CAAC"}
@@ -58,7 +58,7 @@ const batchEvents = [
58
58
  'downplay',
59
59
  'highlight'
60
60
  ];
61
- export const EChart = /*#__PURE__*/ memo(function EChart({ option, theme, renderer, sx, style, onEvents, _instance, syncGroup, onChartInitialized }) {
61
+ export const EChart = /*#__PURE__*/ memo(function EChart({ option, theme, renderer, sx, style, onEvents, _instance: instanceRef, syncGroup, onChartInitialized }) {
62
62
  const initialOption = useRef(option);
63
63
  const prevOption = useRef(option);
64
64
  const containerRef = useRef(null);
@@ -72,8 +72,8 @@ export const EChart = /*#__PURE__*/ memo(function EChart({ option, theme, render
72
72
  if (chartElement.current === undefined) return;
73
73
  chartElement.current.setOption(initialOption.current, true);
74
74
  onChartInitialized?.(chartElement.current);
75
- if (_instance !== undefined) {
76
- _instance.current = chartElement.current;
75
+ if (instanceRef !== undefined) {
76
+ instanceRef.current = chartElement.current;
77
77
  }
78
78
  return ()=>{
79
79
  if (chartElement.current === null) return;
@@ -81,7 +81,7 @@ export const EChart = /*#__PURE__*/ memo(function EChart({ option, theme, render
81
81
  chartElement.current = null;
82
82
  };
83
83
  }, [
84
- _instance,
84
+ instanceRef,
85
85
  onChartInitialized,
86
86
  theme,
87
87
  renderer
@@ -106,16 +106,21 @@ export const EChart = /*#__PURE__*/ memo(function EChart({ option, theme, render
106
106
  }, [
107
107
  option
108
108
  ]);
109
- // Resize chart, cleanup listener on unmount
109
+ // Observe actual container size, including layout and style changes.
110
110
  useLayoutEffect(()=>{
111
+ const container = containerRef.current;
112
+ if (!container) return;
111
113
  const updateSize = debounce(()=>{
112
- if (!chartElement.current) return;
113
- chartElement.current.resize();
114
+ chartElement.current?.resize();
114
115
  }, 200);
116
+ const observer = new ResizeObserver(updateSize);
117
+ observer.observe(container);
115
118
  window.addEventListener('resize', updateSize);
116
119
  updateSize();
117
120
  return ()=>{
121
+ observer.disconnect();
118
122
  window.removeEventListener('resize', updateSize);
123
+ updateSize.cancel();
119
124
  };
120
125
  }, []);
121
126
  // Bind and unbind chart events passed as prop
@@ -133,24 +138,6 @@ export const EChart = /*#__PURE__*/ memo(function EChart({ option, theme, render
133
138
  }, [
134
139
  onEvents
135
140
  ]);
136
- // TODO: re-evaluate how this is triggered. It's technically working right
137
- // now because the sx prop is an object that gets re-created, but that also
138
- // means it runs unnecessarily some of the time and theoretically might
139
- // not run in some other cases. Maybe it should use a resize observer?
140
- useEffect(()=>{
141
- // TODO: fix this debouncing. This likely isn't working as intended because
142
- // the debounced function is re-created every time this useEffect is called.
143
- const updateSize = debounce(()=>{
144
- if (!chartElement.current) return;
145
- chartElement.current.resize();
146
- }, 200, {
147
- leading: true
148
- });
149
- updateSize();
150
- }, [
151
- sx,
152
- style
153
- ]);
154
141
  return /*#__PURE__*/ _jsx(Box, {
155
142
  ref: containerRef,
156
143
  sx: sx,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/EChart/EChart.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { SxProps, Theme } from '@mui/material';\nimport { Box } from '@mui/material';\nimport {\n BarChart as EChartsBarChart,\n LineChart as EChartsLineChart,\n GaugeChart as EChartsGaugeChart,\n PieChart as EChartsPieChart,\n ScatterChart as EChartsScatterChart,\n CustomChart as EChartsCustomChart,\n HeatmapChart as EChartsHeatmapChart,\n} from 'echarts/charts';\nimport {\n DatasetComponent,\n DataZoomComponent,\n LegendComponent,\n GridComponent,\n TitleComponent,\n TooltipComponent,\n VisualMapComponent,\n ToolboxComponent,\n MarkPointComponent,\n MarkAreaComponent,\n MarkLineComponent,\n} from 'echarts/components';\nimport type { ECharts, EChartsCoreOption } from 'echarts/core';\nimport { init, connect, use as registerEChartsComponents } from 'echarts/core';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport debounce from 'lodash/debounce';\nimport isEqual from 'lodash/isEqual';\nimport type { CSSProperties } from 'react';\nimport { memo, useEffect, useLayoutEffect, useRef } from 'react';\n\nimport type { EChartsTheme } from '../model';\n\n// Loading the ECharts extensions should happen in the respective plugins.\n// This is a workaround for https://github.com/perses/plugins/issues/83.\nregisterEChartsComponents([\n DatasetComponent,\n DataZoomComponent,\n LegendComponent,\n EChartsBarChart,\n EChartsLineChart,\n EChartsGaugeChart,\n EChartsPieChart,\n EChartsScatterChart,\n EChartsCustomChart,\n EChartsHeatmapChart,\n GridComponent,\n TitleComponent,\n ToolboxComponent,\n TooltipComponent,\n CanvasRenderer,\n VisualMapComponent,\n MarkAreaComponent,\n MarkLineComponent,\n MarkPointComponent,\n]);\n\n// see docs for info about each property: https://echarts.apache.org/en/api.html#events\nexport interface MouseEventsParameters<T> {\n componentType: string;\n seriesType: string;\n seriesIndex: number;\n seriesName: string;\n name: string;\n dataIndex: number;\n data: Record<string, unknown> & T;\n dataType: string;\n value: number | number[];\n color: string;\n info: Record<string, unknown>;\n}\n\ntype OnEventFunction<T> = (\n params: MouseEventsParameters<T>,\n // This is potentially undefined for testing purposes\n instance?: ECharts,\n) => void;\n\nconst mouseEvents = [\n 'click',\n 'dblclick',\n 'mousedown',\n 'mousemove',\n 'mouseup',\n 'mouseover',\n 'mouseout',\n 'globalout',\n 'contextmenu',\n] as const;\n\nexport type MouseEventName = (typeof mouseEvents)[number];\n\n// batch event types\nexport interface DataZoomPayloadBatchItem {\n dataZoomId: string;\n // start and end not returned unless dataZoom is based on percentProp,\n // which is for cases when a dataZoom component controls multiple axes\n start?: number;\n end?: number;\n // startValue and endValue return data index for 'category' axes,\n // for axis types 'value' and 'time', actual values are returned\n startValue?: number;\n endValue?: number;\n}\n\nexport interface HighlightPayloadBatchItem {\n dataIndex: number;\n dataIndexInside: number;\n seriesIndex: number;\n // highlight action can effect multiple connected charts\n escapeConnect?: boolean;\n // whether blur state was triggered\n notBlur?: boolean;\n}\n\nexport interface BatchEventsParameters {\n type: BatchEventName;\n batch: DataZoomPayloadBatchItem[] & HighlightPayloadBatchItem[];\n}\n\ntype OnBatchEventFunction = (params: BatchEventsParameters) => void;\n\nconst batchEvents = ['datazoom', 'downplay', 'highlight'] as const;\n\nexport type BatchEventName = (typeof batchEvents)[number];\n\ntype ChartEventName = 'finished';\n\ntype EventName = MouseEventName | ChartEventName | BatchEventName;\n\nexport type OnEventsType<T> = {\n [mouseEventName in MouseEventName]?: OnEventFunction<T>;\n} & {\n [batchEventName in BatchEventName]?: OnBatchEventFunction;\n} & {\n [eventName in ChartEventName]?: () => void;\n};\n\nexport interface EChartsProps<T> {\n option: EChartsCoreOption;\n theme?: string | EChartsTheme;\n renderer?: 'canvas' | 'svg';\n sx?: SxProps<Theme>;\n style?: CSSProperties;\n onEvents?: OnEventsType<T>;\n _instance?: React.MutableRefObject<ECharts | undefined>;\n syncGroup?: string;\n onChartInitialized?: (instance: ECharts) => void;\n}\n\nexport const EChart = memo(function EChart<T>({\n option,\n theme,\n renderer,\n sx,\n style,\n onEvents,\n _instance,\n syncGroup,\n onChartInitialized,\n}: EChartsProps<T>) {\n const initialOption = useRef<EChartsCoreOption>(option);\n const prevOption = useRef<EChartsCoreOption>(option);\n const containerRef = useRef<HTMLDivElement | null>(null);\n const chartElement = useRef<ECharts | null>(null);\n\n // Initialize chart, dispose on unmount\n useLayoutEffect(() => {\n if (containerRef.current === null || chartElement.current !== null) return;\n chartElement.current = init(containerRef.current, theme, { renderer: renderer ?? 'canvas' });\n if (chartElement.current === undefined) return;\n chartElement.current.setOption(initialOption.current, true);\n onChartInitialized?.(chartElement.current);\n if (_instance !== undefined) {\n _instance.current = chartElement.current;\n }\n return (): void => {\n if (chartElement.current === null) return;\n chartElement.current.dispose();\n chartElement.current = null;\n };\n }, [_instance, onChartInitialized, theme, renderer]);\n\n // When syncGroup is explicitly set, charts within same group share interactions such as crosshair\n useEffect(() => {\n if (!chartElement.current || !syncGroup) return;\n chartElement.current.group = syncGroup;\n connect([chartElement.current]); // more info: https://echarts.apache.org/en/api.html#echarts.connect\n }, [syncGroup, chartElement]);\n\n // Update chart data when option changes\n useEffect(() => {\n if (prevOption.current === undefined || isEqual(prevOption.current, option)) return;\n if (!chartElement.current) return;\n chartElement.current.setOption(option, true);\n prevOption.current = option;\n }, [option]);\n\n // Resize chart, cleanup listener on unmount\n useLayoutEffect(() => {\n const updateSize = debounce(() => {\n if (!chartElement.current) return;\n chartElement.current.resize();\n }, 200);\n window.addEventListener('resize', updateSize);\n updateSize();\n return (): void => {\n window.removeEventListener('resize', updateSize);\n };\n }, []);\n\n // Bind and unbind chart events passed as prop\n useEffect(() => {\n const chart = chartElement.current;\n if (!chart || onEvents === undefined) return;\n bindEvents(chart, onEvents);\n return (): void => {\n if (chart === undefined) return;\n if (chart.isDisposed() === true) return;\n for (const event in onEvents) {\n chart.off(event);\n }\n };\n }, [onEvents]);\n\n // TODO: re-evaluate how this is triggered. It's technically working right\n // now because the sx prop is an object that gets re-created, but that also\n // means it runs unnecessarily some of the time and theoretically might\n // not run in some other cases. Maybe it should use a resize observer?\n useEffect(() => {\n // TODO: fix this debouncing. This likely isn't working as intended because\n // the debounced function is re-created every time this useEffect is called.\n const updateSize = debounce(\n () => {\n if (!chartElement.current) return;\n chartElement.current.resize();\n },\n 200,\n {\n leading: true,\n },\n );\n updateSize();\n }, [sx, style]);\n\n return <Box ref={containerRef} sx={sx} style={style}></Box>;\n});\n\n// Validate event config and bind custom events\nfunction bindEvents<T>(instance: ECharts, events?: OnEventsType<T>): void {\n if (events === undefined) return;\n\n function bindEvent(eventName: EventName, OnEventFunction: unknown): void {\n if (typeof OnEventFunction === 'function') {\n if (isMouseEvent(eventName)) {\n instance.on(eventName, (params) => OnEventFunction(params, instance));\n } else if (isBatchEvent(eventName)) {\n instance.on(eventName, (params) => OnEventFunction(params));\n } else {\n instance.on(eventName, () => OnEventFunction(null, instance));\n }\n }\n }\n\n for (const eventName in events) {\n if (Object.prototype.hasOwnProperty.call(events, eventName)) {\n const customEvent = events[eventName as EventName] ?? null;\n if (customEvent) {\n bindEvent(eventName as EventName, customEvent);\n }\n }\n }\n}\n\nfunction isMouseEvent(eventName: EventName): eventName is MouseEventName {\n return (mouseEvents as readonly string[]).includes(eventName);\n}\n\nfunction isBatchEvent(eventName: EventName): eventName is BatchEventName {\n return (batchEvents as readonly string[]).includes(eventName);\n}\n"],"names":["Box","BarChart","EChartsBarChart","LineChart","EChartsLineChart","GaugeChart","EChartsGaugeChart","PieChart","EChartsPieChart","ScatterChart","EChartsScatterChart","CustomChart","EChartsCustomChart","HeatmapChart","EChartsHeatmapChart","DatasetComponent","DataZoomComponent","LegendComponent","GridComponent","TitleComponent","TooltipComponent","VisualMapComponent","ToolboxComponent","MarkPointComponent","MarkAreaComponent","MarkLineComponent","init","connect","use","registerEChartsComponents","CanvasRenderer","debounce","isEqual","memo","useEffect","useLayoutEffect","useRef","mouseEvents","batchEvents","EChart","option","theme","renderer","sx","style","onEvents","_instance","syncGroup","onChartInitialized","initialOption","prevOption","containerRef","chartElement","current","undefined","setOption","dispose","group","updateSize","resize","window","addEventListener","removeEventListener","chart","bindEvents","isDisposed","event","off","leading","ref","instance","events","bindEvent","eventName","OnEventFunction","isMouseEvent","on","params","isBatchEvent","Object","prototype","hasOwnProperty","call","customEvent","includes"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAGjC,SAASA,GAAG,QAAQ,gBAAgB;AACpC,SACEC,YAAYC,eAAe,EAC3BC,aAAaC,gBAAgB,EAC7BC,cAAcC,iBAAiB,EAC/BC,YAAYC,eAAe,EAC3BC,gBAAgBC,mBAAmB,EACnCC,eAAeC,kBAAkB,EACjCC,gBAAgBC,mBAAmB,QAC9B,iBAAiB;AACxB,SACEC,gBAAgB,EAChBC,iBAAiB,EACjBC,eAAe,EACfC,aAAa,EACbC,cAAc,EACdC,gBAAgB,EAChBC,kBAAkB,EAClBC,gBAAgB,EAChBC,kBAAkB,EAClBC,iBAAiB,EACjBC,iBAAiB,QACZ,qBAAqB;AAE5B,SAASC,IAAI,EAAEC,OAAO,EAAEC,OAAOC,yBAAyB,QAAQ,eAAe;AAC/E,SAASC,cAAc,QAAQ,oBAAoB;AACnD,OAAOC,cAAc,kBAAkB;AACvC,OAAOC,aAAa,iBAAiB;AAErC,SAASC,IAAI,EAAEC,SAAS,EAAEC,eAAe,EAAEC,MAAM,QAAQ,QAAQ;AAIjE,0EAA0E;AAC1E,wEAAwE;AACxEP,0BAA0B;IACxBd;IACAC;IACAC;IACAf;IACAE;IACAE;IACAE;IACAE;IACAE;IACAE;IACAI;IACAC;IACAG;IACAF;IACAU;IACAT;IACAG;IACAC;IACAF;CACD;AAuBD,MAAMc,cAAc;IAClB;IACA;IACA;IACA;IAC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SAASM,EAAE,CAACH,WAAW,CAACI,SAAWH,gBAAgBG,QAAQP;YAC7D,OAAO,IAAIQ,aAAaL,YAAY;gBAClCH,SAASM,EAAE,CAACH,WAAW,CAACI,SAAWH,gBAAgBG;YACrD,OAAO;gBACLP,SAASM,EAAE,CAACH,WAAW,IAAMC,gBAAgB,MAAMJ;YACrD;QACF;IACF;IAEA,IAAK,MAAMG,aAAaF,OAAQ;QAC9B,IAAIQ,OAAOC,SAAS,CAACC,cAAc,CAACC,IAAI,CAACX,QAAQE,YAAY;YAC3D,MAAMU,cAAcZ,MAAM,CAACE,UAAuB,IAAI;YACtD,IAAIU,aAAa;gBACfX,UAAUC,WAAwBU;YACpC;QACF;IACF;AACF;AAEA,SAASR,aAAaF,SAAoB;IACxC,OAAO,AAACpC,YAAkC+C,QAAQ,CAACX;AACrD;AAEA,SAASK,aAAaL,SAAoB;IACxC,OAAO,AAACnC,YAAkC8C,QAAQ,CAACX;AACrD"}
1
+ {"version":3,"sources":["../../src/EChart/EChart.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { SxProps, Theme } from '@mui/material';\nimport { Box } from '@mui/material';\nimport {\n BarChart as EChartsBarChart,\n LineChart as EChartsLineChart,\n GaugeChart as EChartsGaugeChart,\n PieChart as EChartsPieChart,\n ScatterChart as EChartsScatterChart,\n CustomChart as EChartsCustomChart,\n HeatmapChart as EChartsHeatmapChart,\n} from 'echarts/charts';\nimport {\n DatasetComponent,\n DataZoomComponent,\n LegendComponent,\n GridComponent,\n TitleComponent,\n TooltipComponent,\n VisualMapComponent,\n ToolboxComponent,\n MarkPointComponent,\n MarkAreaComponent,\n MarkLineComponent,\n} from 'echarts/components';\nimport type { ECharts, EChartsCoreOption } from 'echarts/core';\nimport { init, connect, use as registerEChartsComponents } from 'echarts/core';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport debounce from 'lodash/debounce';\nimport isEqual from 'lodash/isEqual';\nimport type { CSSProperties } from 'react';\nimport { memo, useEffect, useLayoutEffect, useRef } from 'react';\n\nimport type { EChartsTheme } from '../model';\n\n// Loading the ECharts extensions should happen in the respective plugins.\n// This is a workaround for https://github.com/perses/plugins/issues/83.\nregisterEChartsComponents([\n DatasetComponent,\n DataZoomComponent,\n LegendComponent,\n EChartsBarChart,\n EChartsLineChart,\n EChartsGaugeChart,\n EChartsPieChart,\n EChartsScatterChart,\n EChartsCustomChart,\n EChartsHeatmapChart,\n GridComponent,\n TitleComponent,\n ToolboxComponent,\n TooltipComponent,\n CanvasRenderer,\n VisualMapComponent,\n MarkAreaComponent,\n MarkLineComponent,\n MarkPointComponent,\n]);\n\n// see docs for info about each property: https://echarts.apache.org/en/api.html#events\nexport interface MouseEventsParameters<T> {\n componentType: string;\n seriesType: string;\n seriesIndex: number;\n seriesName: string;\n name: string;\n dataIndex: number;\n data: Record<string, unknown> & T;\n dataType: string;\n value: number | number[];\n color: string;\n info: Record<string, unknown>;\n}\n\ntype OnEventFunction<T> = (\n params: MouseEventsParameters<T>,\n // This is potentially undefined for testing purposes\n instance?: ECharts,\n) => void;\n\nconst mouseEvents = [\n 'click',\n 'dblclick',\n 'mousedown',\n 'mousemove',\n 'mouseup',\n 'mouseover',\n 'mouseout',\n 'globalout',\n 'contextmenu',\n] as const;\n\nexport type MouseEventName = (typeof mouseEvents)[number];\n\n// batch event types\nexport interface DataZoomPayloadBatchItem {\n dataZoomId: string;\n // start and end not returned unless dataZoom is based on percentProp,\n // which is for cases when a dataZoom component controls multiple axes\n start?: number;\n end?: number;\n // startValue and endValue return data index for 'category' axes,\n // for axis types 'value' and 'time', actual values are returned\n startValue?: number;\n endValue?: number;\n}\n\nexport interface HighlightPayloadBatchItem {\n dataIndex: number;\n dataIndexInside: number;\n seriesIndex: number;\n // highlight action can effect multiple connected charts\n escapeConnect?: boolean;\n // whether blur state was triggered\n notBlur?: boolean;\n}\n\nexport interface BatchEventsParameters {\n type: BatchEventName;\n batch: DataZoomPayloadBatchItem[] & HighlightPayloadBatchItem[];\n}\n\ntype OnBatchEventFunction = (params: BatchEventsParameters) => void;\n\nconst batchEvents = ['datazoom', 'downplay', 'highlight'] as const;\n\nexport type BatchEventName = (typeof batchEvents)[number];\n\ntype ChartEventName = 'finished';\n\ntype EventName = MouseEventName | ChartEventName | BatchEventName;\n\nexport type OnEventsType<T> = {\n [mouseEventName in MouseEventName]?: OnEventFunction<T>;\n} & {\n [batchEventName in BatchEventName]?: OnBatchEventFunction;\n} & {\n [eventName in ChartEventName]?: () => void;\n};\n\nexport interface EChartsProps<T> {\n option: EChartsCoreOption;\n theme?: string | EChartsTheme;\n renderer?: 'canvas' | 'svg';\n sx?: SxProps<Theme>;\n style?: CSSProperties;\n onEvents?: OnEventsType<T>;\n _instance?: React.MutableRefObject<ECharts | undefined>;\n syncGroup?: string;\n onChartInitialized?: (instance: ECharts) => void;\n}\n\nexport const EChart = memo(function EChart<T>({\n option,\n theme,\n renderer,\n sx,\n style,\n onEvents,\n _instance: instanceRef,\n syncGroup,\n onChartInitialized,\n}: EChartsProps<T>) {\n const initialOption = useRef<EChartsCoreOption>(option);\n const prevOption = useRef<EChartsCoreOption>(option);\n const containerRef = useRef<HTMLDivElement | null>(null);\n const chartElement = useRef<ECharts | null>(null);\n\n // Initialize chart, dispose on unmount\n useLayoutEffect(() => {\n if (containerRef.current === null || chartElement.current !== null) return;\n chartElement.current = init(containerRef.current, theme, { renderer: renderer ?? 'canvas' });\n if (chartElement.current === undefined) return;\n chartElement.current.setOption(initialOption.current, true);\n onChartInitialized?.(chartElement.current);\n if (instanceRef !== undefined) {\n instanceRef.current = chartElement.current;\n }\n return (): void => {\n if (chartElement.current === null) return;\n chartElement.current.dispose();\n chartElement.current = null;\n };\n }, [instanceRef, onChartInitialized, theme, renderer]);\n\n // When syncGroup is explicitly set, charts within same group share interactions such as crosshair\n useEffect(() => {\n if (!chartElement.current || !syncGroup) return;\n chartElement.current.group = syncGroup;\n connect([chartElement.current]); // more info: https://echarts.apache.org/en/api.html#echarts.connect\n }, [syncGroup, chartElement]);\n\n // Update chart data when option changes\n useEffect(() => {\n if (prevOption.current === undefined || isEqual(prevOption.current, option)) return;\n if (!chartElement.current) return;\n chartElement.current.setOption(option, true);\n prevOption.current = option;\n }, [option]);\n\n // Observe actual container size, including layout and style changes.\n useLayoutEffect(() => {\n const container = containerRef.current;\n if (!container) return;\n const updateSize = debounce(() => {\n chartElement.current?.resize();\n }, 200);\n const observer = new ResizeObserver(updateSize);\n observer.observe(container);\n window.addEventListener('resize', updateSize);\n updateSize();\n return (): void => {\n observer.disconnect();\n window.removeEventListener('resize', updateSize);\n updateSize.cancel();\n };\n }, []);\n\n // Bind and unbind chart events passed as prop\n useEffect(() => {\n const chart = chartElement.current;\n if (!chart || onEvents === undefined) return;\n bindEvents(chart, onEvents);\n return (): void => {\n if (chart === undefined) return;\n if (chart.isDisposed() === true) return;\n for (const event in onEvents) {\n chart.off(event);\n }\n };\n }, [onEvents]);\n\n return <Box ref={containerRef} sx={sx} style={style}></Box>;\n});\n\n// Validate event config and bind custom events\nfunction bindEvents<T>(instance: ECharts, events?: OnEventsType<T>): void {\n if (events === undefined) return;\n\n function bindEvent(eventName: EventName, OnEventFunction: unknown): void {\n if (typeof OnEventFunction === 'function') {\n if (isMouseEvent(eventName)) {\n instance.on(eventName, (params) => OnEventFunction(params, instance));\n } else if (isBatchEvent(eventName)) {\n instance.on(eventName, (params) => OnEventFunction(params));\n } else {\n instance.on(eventName, () => OnEventFunction(null, instance));\n }\n }\n }\n\n for (const eventName in events) {\n if (Object.prototype.hasOwnProperty.call(events, eventName)) {\n const customEvent = events[eventName as EventName] ?? null;\n if (customEvent) {\n bindEvent(eventName as EventName, customEvent);\n }\n }\n }\n}\n\nfunction isMouseEvent(eventName: EventName): eventName is MouseEventName {\n return (mouseEvents as readonly string[]).includes(eventName);\n}\n\nfunction isBatchEvent(eventName: EventName): eventName is BatchEventName {\n return (batchEvents as readonly string[]).includes(eventName);\n}\n"],"names":["Box","BarChart","EChartsBarChart","LineChart","EChartsLineChart","GaugeChart","EChartsGaugeChart","PieChart","EChartsPieChart","ScatterChart","EChartsScatterChart","CustomChart","EChartsCustomChart","HeatmapChart","EChartsHeatmapChart","DatasetComponent","DataZoomComponent","LegendComponent","GridComponent","TitleComponent","TooltipComponent","VisualMapComponent","ToolboxComponent","MarkPointComponent","MarkAreaComponent","MarkLineComponent","init","connect","use","registerEChartsComponents","CanvasRenderer","debounce","isEqual","memo","useEffect","useLayoutEffect","useRef","mouseEvents","batchEvents","EChart","option","theme","renderer","sx","style","onEvents","_instance","instanceRef","syncGroup","onChartInitialized","initialOption","prevOption","containerRef","chartElement","current","undefined","setOption","dispose","group","container","updateSize","resize","observer","ResizeObserver","observe","window","addEventListener","disconnect","removeEventListener","cancel","chart","bindEvents","isDisposed","event","off","ref","instance","events","bindEvent","eventName","OnEventFunction","isMouseEvent","on","params","isBatchEvent","Object","prototype","hasOwnProperty","call","customEvent","includes"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAGjC,SAASA,GAAG,QAAQ,gBAAgB;AACpC,SACEC,YAAYC,eAAe,EAC3BC,aAAaC,gBAAgB,EAC7BC,cAAcC,iBAAiB,EAC/BC,YAAYC,eAAe,EAC3BC,gBAAgBC,mBAAmB,EACnCC,eAAeC,kBAAkB,EACjCC,gBAAgBC,mBAAmB,QAC9B,iBAAiB;AACxB,SACEC,gBAAgB,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B;QAClB,OAAO;YACL,IAAIyB,UAAUf,WAAW;YACzB,IAAIe,MAAME,UAAU,OAAO,MAAM;YACjC,IAAK,MAAMC,SAAS5B,SAAU;gBAC5ByB,MAAMI,GAAG,CAACD;YACZ;QACF;IACF,GAAG;QAAC5B;KAAS;IAEb,qBAAO,KAAC7C;QAAI2E,KAAKvB;QAAcT,IAAIA;QAAIC,OAAOA;;AAChD,GAAG;AAEH,+CAA+C;AAC/C,SAAS2B,WAAcK,QAAiB,EAAEC,MAAwB;IAChE,IAAIA,WAAWtB,WAAW;IAE1B,SAASuB,UAAUC,SAAoB,EAAEC,eAAwB;QAC/D,IAAI,OAAOA,oBAAoB,YAAY;YACzC,IAAIC,aAAaF,YAAY;gBAC3BH,SAASM,EAAE,CAACH,WAAW,CAACI,SAAWH,gBAAgBG,QAAQP;YAC7D,OAAO,IAAIQ,aAAaL,YAAY;gBAClCH,SAASM,EAAE,CAACH,WAAW,CAACI,SAAWH,gBAAgBG;YACrD,OAAO;gBACLP,SAASM,EAAE,CAACH,WAAW,IAAMC,gBAAgB,MAAMJ;YACrD;QACF;IACF;IAEA,IAAK,MAAMG,aAAaF,OAAQ;QAC9B,IAAIQ,OAAOC,SAAS,CAACC,cAAc,CAACC,IAAI,CAACX,QAAQE,YAAY;YAC3D,MAAMU,cAAcZ,MAAM,CAACE,UAAuB,IAAI;YACtD,IAAIU,aAAa;gBACfX,UAAUC,WAAwBU;YACpC;QACF;IACF;AACF;AAEA,SAASR,aAAaF,SAAoB;IACxC,OAAO,AAAC1C,YAAkCqD,QAAQ,CAACX;AACrD;AAEA,SAASK,aAAaL,SAAoB;IACxC,OAAO,AAACzC,YAAkCoD,QAAQ,CAACX;AACrD"}
@@ -1 +1 @@
1
- {"version":3,"file":"FormatControls.d.ts","sourceRoot":"","sources":["../../src/FormatControls/FormatControls.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAM9C,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,aAAa,CAAC;IACrB,QAAQ,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,IAAI,CAAC;IACxC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAiBD,wBAAgB,cAAc,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAgB,EAAE,EAAE,mBAAmB,GAAG,YAAY,CA+DvG"}
1
+ {"version":3,"file":"FormatControls.d.ts","sourceRoot":"","sources":["../../src/FormatControls/FormatControls.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAM9C,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,aAAa,CAAC;IACrB,QAAQ,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,IAAI,CAAC;IACxC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAiBD,wBAAgB,cAAc,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAgB,EAAE,EAAE,mBAAmB,GAAG,YAAY,CAkGvG"}
@@ -11,8 +11,8 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
14
- import { Switch } from "@mui/material";
15
- import { isUnitWithDecimalPlaces, isUnitWithShortValues, shouldShortenValues } from "../model/index.js";
14
+ import { Switch, TextField } from "@mui/material";
15
+ import { isUnitWithDecimalPlaces, isUnitWithShortValues, shouldShortenValues, supportsCustomLabel } from "../model/index.js";
16
16
  import { OptionsEditorControl } from "../OptionsEditorLayout/index.js";
17
17
  import { SettingsAutocomplete } from "../SettingsAutocomplete/index.js";
18
18
  import { UnitSelector } from "./UnitSelector.js";
@@ -55,10 +55,21 @@ export function FormatControls({ value, onChange, disabled = false }) {
55
55
  const hasDecimalPlaces = isUnitWithDecimalPlaces(value);
56
56
  const hasShortValues = isUnitWithShortValues(value);
57
57
  const handleUnitChange = (newValue)=>{
58
- onChange(newValue || {
58
+ const next = newValue || {
59
59
  unit: 'decimal'
60
- }); // Fallback to 'decimal' if undefined
60
+ };
61
+ const customLabel = value.customLabel?.trim();
62
+ // Keep label only when the new unit supports customLabel (whitelist).
63
+ if (customLabel && supportsCustomLabel(next.unit)) {
64
+ onChange({
65
+ ...next,
66
+ customLabel: value.customLabel
67
+ });
68
+ return;
69
+ }
70
+ onChange(next);
61
71
  };
72
+ const showCustomLabel = supportsCustomLabel(value.unit);
62
73
  const handleDecimalPlacesChange = ({ decimalPlaces })=>{
63
74
  if (hasDecimalPlaces) {
64
75
  onChange({
@@ -75,6 +86,18 @@ export function FormatControls({ value, onChange, disabled = false }) {
75
86
  });
76
87
  }
77
88
  };
89
+ const handleCustomLabelChange = (raw)=>{
90
+ // Keep raw input while typing (spaces allowed). Trim only when clearing / display.
91
+ if (raw === '') {
92
+ const { customLabel: _removed, ...rest } = value;
93
+ onChange(rest);
94
+ return;
95
+ }
96
+ onChange({
97
+ ...value,
98
+ customLabel: raw
99
+ });
100
+ };
78
101
  return /*#__PURE__*/ _jsxs(_Fragment, {
79
102
  children: [
80
103
  /*#__PURE__*/ _jsx(OptionsEditorControl, {
@@ -93,6 +116,21 @@ export function FormatControls({ value, onChange, disabled = false }) {
93
116
  disabled: disabled
94
117
  })
95
118
  }),
119
+ showCustomLabel && /*#__PURE__*/ _jsx(OptionsEditorControl, {
120
+ label: "Custom label",
121
+ control: /*#__PURE__*/ _jsx(TextField, {
122
+ size: "small",
123
+ fullWidth: true,
124
+ value: value.customLabel ?? '',
125
+ onChange: (e)=>handleCustomLabelChange(e.target.value),
126
+ placeholder: "Optional display override (e.g. pnr/mn)",
127
+ disabled: disabled,
128
+ inputProps: {
129
+ 'aria-label': 'custom unit label',
130
+ maxLength: 32
131
+ }
132
+ })
133
+ }),
96
134
  /*#__PURE__*/ _jsx(OptionsEditorControl, {
97
135
  label: "Decimals",
98
136
  control: /*#__PURE__*/ _jsx(SettingsAutocomplete, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/FormatControls/FormatControls.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\nimport type { SwitchProps } from '@mui/material';\nimport { Switch } from '@mui/material';\nimport type { ReactElement } from 'react';\n\nimport type { FormatOptions } from '../model';\nimport { isUnitWithDecimalPlaces, isUnitWithShortValues, shouldShortenValues } from '../model';\nimport { OptionsEditorControl } from '../OptionsEditorLayout';\nimport { SettingsAutocomplete } from '../SettingsAutocomplete';\nimport { UnitSelector } from './UnitSelector';\n\nexport interface FormatControlsProps {\n value: FormatOptions;\n onChange: (unit: FormatOptions) => void;\n disabled?: boolean;\n}\n\nconst DECIMAL_PLACES_OPTIONS: Array<{ id: string; label: string; decimalPlaces?: number }> = [\n { id: 'default', label: 'Default', decimalPlaces: undefined },\n { id: '0', label: '0', decimalPlaces: 0 },\n { id: '1', label: '1', decimalPlaces: 1 },\n { id: '2', label: '2', decimalPlaces: 2 },\n { id: '3', label: '3', decimalPlaces: 3 },\n { id: '4', label: '4', decimalPlaces: 4 },\n];\n\nfunction getOptionByDecimalPlaces(\n decimalPlaces?: number,\n): { id: string; label: string; decimalPlaces?: number } | undefined {\n return DECIMAL_PLACES_OPTIONS.find((o) => o.decimalPlaces === decimalPlaces);\n}\n\nexport function FormatControls({ value, onChange, disabled = false }: FormatControlsProps): ReactElement {\n const hasDecimalPlaces = isUnitWithDecimalPlaces(value);\n const hasShortValues = isUnitWithShortValues(value);\n\n const handleUnitChange = (newValue: FormatOptions | undefined): void => {\n onChange(newValue || { unit: 'decimal' }); // Fallback to 'decimal' if undefined\n };\n\n const handleDecimalPlacesChange = ({\n decimalPlaces,\n }: {\n id: string;\n label: string;\n decimalPlaces?: number;\n }): void => {\n if (hasDecimalPlaces) {\n onChange({\n ...value,\n decimalPlaces: decimalPlaces,\n });\n }\n };\n\n const handleShortValuesChange: SwitchProps['onChange'] = (_: unknown, checked: boolean) => {\n if (hasShortValues) {\n onChange({\n ...value,\n shortValues: checked,\n });\n }\n };\n\n return (\n <>\n <OptionsEditorControl\n label=\"Short values\"\n control={\n <Switch\n checked={hasShortValues ? shouldShortenValues(value.shortValues) : false}\n onChange={handleShortValuesChange}\n disabled={!hasShortValues}\n />\n }\n />\n <OptionsEditorControl\n label=\"Unit\"\n control={<UnitSelector value={value} onChange={handleUnitChange} disabled={disabled} />}\n />\n <OptionsEditorControl\n label=\"Decimals\"\n control={\n <SettingsAutocomplete\n value={getOptionByDecimalPlaces(value.decimalPlaces)}\n options={DECIMAL_PLACES_OPTIONS}\n getOptionLabel={(o) => o.label}\n onChange={(_, value) => handleDecimalPlacesChange(value)}\n disabled={!hasDecimalPlaces}\n disableClearable\n />\n }\n />\n </>\n );\n}\n"],"names":["Switch","isUnitWithDecimalPlaces","isUnitWithShortValues","shouldShortenValues","OptionsEditorControl","SettingsAutocomplete","UnitSelector","DECIMAL_PLACES_OPTIONS","id","label","decimalPlaces","undefined","getOptionByDecimalPlaces","find","o","FormatControls","value","onChange","disabled","hasDecimalPlaces","hasShortValues","handleUnitChange","newValue","unit","handleDecimalPlacesChange","handleShortValuesChange","_","checked","shortValues","control","options","getOptionLabel","disableClearable"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AAC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AAiBjB,oBAAoBa,MAAMY,WAAW,IAAI;oBACnEX,UAAUQ;oBACVP,UAAU,CAACE;;;0BAIjB,KAAChB;gBACCK,OAAM;gBACNoB,uBAAS,KAACvB;oBAAaU,OAAOA;oBAAOC,UAAUI;oBAAkBH,UAAUA;;;0BAE7E,KAACd;gBACCK,OAAM;gBACNoB,uBACE,KAACxB;oBACCW,OAAOJ,yBAAyBI,MAAMN,aAAa;oBACnDoB,SAASvB;oBACTwB,gBAAgB,CAACjB,IAAMA,EAAEL,KAAK;oBAC9BQ,UAAU,CAACS,GAAGV,QAAUQ,0BAA0BR;oBAClDE,UAAU,CAACC;oBACXa,gBAAgB;;;;;AAM5B"}
1
+ {"version":3,"sources":["../../src/FormatControls/FormatControls.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\nimport type { SwitchProps } from '@mui/material';\nimport { Switch, TextField } from '@mui/material';\nimport type { ReactElement } from 'react';\n\nimport type { FormatOptions } from '../model';\nimport { isUnitWithDecimalPlaces, isUnitWithShortValues, shouldShortenValues, supportsCustomLabel } from '../model';\nimport { OptionsEditorControl } from '../OptionsEditorLayout';\nimport { SettingsAutocomplete } from '../SettingsAutocomplete';\nimport { UnitSelector } from './UnitSelector';\n\nexport interface FormatControlsProps {\n value: FormatOptions;\n onChange: (unit: FormatOptions) => void;\n disabled?: boolean;\n}\n\nconst DECIMAL_PLACES_OPTIONS: Array<{ id: string; label: string; decimalPlaces?: number }> = [\n { id: 'default', label: 'Default', decimalPlaces: undefined },\n { id: '0', label: '0', decimalPlaces: 0 },\n { id: '1', label: '1', decimalPlaces: 1 },\n { id: '2', label: '2', decimalPlaces: 2 },\n { id: '3', label: '3', decimalPlaces: 3 },\n { id: '4', label: '4', decimalPlaces: 4 },\n];\n\nfunction getOptionByDecimalPlaces(\n decimalPlaces?: number,\n): { id: string; label: string; decimalPlaces?: number } | undefined {\n return DECIMAL_PLACES_OPTIONS.find((o) => o.decimalPlaces === decimalPlaces);\n}\n\nexport function FormatControls({ value, onChange, disabled = false }: FormatControlsProps): ReactElement {\n const hasDecimalPlaces = isUnitWithDecimalPlaces(value);\n const hasShortValues = isUnitWithShortValues(value);\n\n const handleUnitChange = (newValue: FormatOptions | undefined): void => {\n const next = newValue || { unit: 'decimal' };\n const customLabel = value.customLabel?.trim();\n // Keep label only when the new unit supports customLabel (whitelist).\n if (customLabel && supportsCustomLabel(next.unit)) {\n onChange({ ...next, customLabel: value.customLabel });\n return;\n }\n onChange(next);\n };\n\n const showCustomLabel = supportsCustomLabel(value.unit);\n\n const handleDecimalPlacesChange = ({\n decimalPlaces,\n }: {\n id: string;\n label: string;\n decimalPlaces?: number;\n }): void => {\n if (hasDecimalPlaces) {\n onChange({\n ...value,\n decimalPlaces: decimalPlaces,\n });\n }\n };\n\n const handleShortValuesChange: SwitchProps['onChange'] = (_: unknown, checked: boolean) => {\n if (hasShortValues) {\n onChange({\n ...value,\n shortValues: checked,\n });\n }\n };\n\n const handleCustomLabelChange = (raw: string): void => {\n // Keep raw input while typing (spaces allowed). Trim only when clearing / display.\n if (raw === '') {\n const { customLabel: _removed, ...rest } = value;\n onChange(rest as FormatOptions);\n return;\n }\n onChange({ ...value, customLabel: raw });\n };\n\n return (\n <>\n <OptionsEditorControl\n label=\"Short values\"\n control={\n <Switch\n checked={hasShortValues ? shouldShortenValues(value.shortValues) : false}\n onChange={handleShortValuesChange}\n disabled={!hasShortValues}\n />\n }\n />\n <OptionsEditorControl\n label=\"Unit\"\n control={<UnitSelector value={value} onChange={handleUnitChange} disabled={disabled} />}\n />\n {showCustomLabel && (\n <OptionsEditorControl\n label=\"Custom label\"\n control={\n <TextField\n size=\"small\"\n fullWidth\n value={value.customLabel ?? ''}\n onChange={(e) => handleCustomLabelChange(e.target.value)}\n placeholder=\"Optional display override (e.g. pnr/mn)\"\n disabled={disabled}\n inputProps={{ 'aria-label': 'custom unit label', maxLength: 32 }}\n />\n }\n />\n )}\n <OptionsEditorControl\n label=\"Decimals\"\n control={\n <SettingsAutocomplete\n value={getOptionByDecimalPlaces(value.decimalPlaces)}\n options={DECIMAL_PLACES_OPTIONS}\n getOptionLabel={(o) => o.label}\n onChange={(_, value) => handleDecimalPlacesChange(value)}\n disabled={!hasDecimalPlaces}\n disableClearable\n />\n }\n />\n </>\n );\n}\n"],"names":["Switch","TextField","isUnitWithDecimalPlaces","isUnitWithShortValues","shouldShortenValues","supportsCustomLabel","OptionsEditorControl","SettingsAutocomplete","UnitSelector","DECIMAL_PLACES_OPTIONS","id","label","decimalPlaces","undefined","getOptionByDecimalPlaces","find","o","FormatControls","value","onChange","disabled","hasDecimalPlaces","hasShortValues","handleUnitChange","newValue","next","unit","customLabel","trim","showCustomLabel","handleDecimalPlacesChange","handleShortValuesChange","_","checked","shortValues","handleCustomLabelChange","raw","_removed","rest","control","size","fullWidth","e","target","placeholder","inputProps","maxLength","options","getOptionLabel","disableClearable"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,MAAM,EAAEC,SAAS,QAAQ,gBAAgB;AAIlD,SAASC,uBAAuB,EAAEC,qBAAqB,EAAEC,mBAAmB,EAAEC,mBAAmB,QAAQ,oBAAW;AACpH,SAASC,oBAAoB,QAAQ,kCAAyB;AAC9D,SAASC,oBAAoB,QAAQ,mCAA0B;AAC/D,SAASC,YAAY,QAAQ,oBAAiB;AAQ9C,MAAMC,yBAAuF;IA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aU,QAAQ,EAAE,GAAGC,MAAM,GAAGpB;YAC3CC,SAASmB;YACT;QACF;QACAnB,SAAS;YAAE,GAAGD,KAAK;YAAES,aAAaS;QAAI;IACxC;IAEA,qBACE;;0BACE,KAAC9B;gBACCK,OAAM;gBACN4B,uBACE,KAACvC;oBACCiC,SAASX,iBAAiBlB,oBAAoBc,MAAMgB,WAAW,IAAI;oBACnEf,UAAUY;oBACVX,UAAU,CAACE;;;0BAIjB,KAAChB;gBACCK,OAAM;gBACN4B,uBAAS,KAAC/B;oBAAaU,OAAOA;oBAAOC,UAAUI;oBAAkBH,UAAUA;;;YAE5ES,iCACC,KAACvB;gBACCK,OAAM;gBACN4B,uBACE,KAACtC;oBACCuC,MAAK;oBACLC,SAAS;oBACTvB,OAAOA,MAAMS,WAAW,IAAI;oBAC5BR,UAAU,CAACuB,IAAMP,wBAAwBO,EAAEC,MAAM,CAACzB,KAAK;oBACvD0B,aAAY;oBACZxB,UAAUA;oBACVyB,YAAY;wBAAE,cAAc;wBAAqBC,WAAW;oBAAG;;;0BAKvE,KAACxC;gBACCK,OAAM;gBACN4B,uBACE,KAAChC;oBACCW,OAAOJ,yBAAyBI,MAAMN,aAAa;oBACnDmC,SAAStC;oBACTuC,gBAAgB,CAAChC,IAAMA,EAAEL,KAAK;oBAC9BQ,UAAU,CAACa,GAAGd,QAAUY,0BAA0BZ;oBAClDE,UAAU,CAACC;oBACX4B,gBAAgB;;;;;AAM5B"}
@@ -27,11 +27,11 @@ export function UnitSelector({ value, onChange, disabled = false, ...otherProps
27
27
  const handleChange = (_, newValue)=>{
28
28
  if (newValue === null) {
29
29
  onChange(undefined);
30
- } else {
31
- onChange({
32
- unit: newValue.id
33
- });
30
+ return;
34
31
  }
32
+ onChange({
33
+ unit: newValue.id
34
+ });
35
35
  };
36
36
  return /*#__PURE__*/ _jsx(SettingsAutocomplete, {
37
37
  value: {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/FormatControls/UnitSelector.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { IconButton, InputAdornment, TextField } from '@mui/material';\nimport ClearIcon from 'mdi-material-ui/Close';\nimport type { ReactElement } from 'react';\n\nimport type { FormatOptions, UnitConfig } from '../model';\nimport { UNIT_CONFIG } from '../model';\nimport { SettingsAutocomplete } from '../SettingsAutocomplete';\n\nexport interface UnitSelectorProps {\n value?: FormatOptions;\n onChange: (format: FormatOptions | undefined) => void;\n disabled?: boolean;\n}\n\ntype AutocompleteUnitOption = UnitConfig & {\n id: NonNullable<FormatOptions['unit']>;\n};\n\nconst KIND_OPTIONS: readonly AutocompleteUnitOption[] = Object.entries(UNIT_CONFIG)\n .map<AutocompleteUnitOption>(([id, config]) => {\n return {\n ...config,\n id: id as AutocompleteUnitOption['id'],\n group: config.group || 'Decimal',\n };\n })\n .filter((config) => !config.disableSelectorOption);\n\nexport function UnitSelector({ value, onChange, disabled = false, ...otherProps }: UnitSelectorProps): ReactElement {\n const unitConfig = UNIT_CONFIG[value?.unit || 'decimal'];\n\n const handleChange = (_: unknown, newValue: AutocompleteUnitOption | null): void => {\n if (newValue === null) {\n onChange(undefined);\n } else {\n onChange({ unit: newValue.id } as FormatOptions);\n }\n };\n\n return (\n <SettingsAutocomplete<AutocompleteUnitOption, false, true>\n value={{ id: value?.unit || 'decimal', ...unitConfig }}\n options={KIND_OPTIONS}\n groupBy={(option) => option.group ?? 'Decimal'}\n onChange={handleChange}\n disabled={disabled}\n disableClearable\n renderInput={({ InputProps, ...params }) => (\n <TextField\n {...params}\n slotProps={{\n input: {\n ...InputProps,\n endAdornment: (\n <>\n {InputProps.endAdornment}\n <InputAdornment position=\"end\">\n <IconButton\n size=\"small\"\n aria-label=\"clear unit\"\n onClick={() => onChange(undefined)}\n disabled={disabled}\n tabIndex={-1}\n >\n <ClearIcon fontSize=\"small\" />\n </IconButton>\n </InputAdornment>\n </>\n ),\n },\n }}\n />\n )}\n {...otherProps}\n />\n );\n}\n"],"names":["IconButton","InputAdornment","TextField","ClearIcon","UNIT_CONFIG","SettingsAutocomplete","KIND_OPTIONS","Object","entries","map","id","config","group","filter","disableSelectorOption","UnitSelector","value","onChange","disabled","otherProps","unitConfig","unit","handleChange","_","newValue","undefined","options","groupBy","option","disableClearable","renderInput","InputProps","params","slotProps","input","endAdornment","position","size","aria-label","onClick","tabIndex","fontSize"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,UAAU,EAAEC,cAAc,EAAEC,SAAS,QAAQ,gBAAgB;AACtE,OAAOC,eAAe,wBAAwB;AAI9C,SAASC,WAAW,QAAQ,oBAAW;AACvC,SAASC,oBAAoB,QAAQ,mCAA0B;AAY/D,MAAMC,eAAkDC,OAAOC,OAAO,CAACJ,aACpEK,GAAG,CAAyB,CAAC,CAACC,IAAIC,OAAO;IACxC,OAAO;QACL,GAAGA,MAAM;QACTD,IAAIA;QACJE,OAAOD,OAAOC,KAAK,IAAI;IACzB;AACF,GACCC,MAAM,CAAC,CAACF,SAAW,CAACA,OAAOG,qBAAqB;AAEnD,OAAO,SAASC,aAAa,EAAEC,KAAK,EAAEC,QAAQ,EAAEC,WAAW,KAAK,EAAE,GAAGC,YAA+B;IAClG,MAAMC,aAAahB,WAAW,CAACY,OAAOK,QAAQ,UAAU;IAExD,MAAMC,eAAe,CAACC,GAAYC;QAChC,IAAIA,aAAa,MAAM;YACrBP,SAASQ;QACX,OAAO;YACLR,SAAS;gBAAEI,MAAMG,SAASd,EAAE;YAAC;QAC/B;IACF;IAEA,qBACE,KAACL;QACCW,OAAO;YAAEN,IAAIM,OAAOK,QAAQ;YAAW,GAAGD,UAAU;QAAC;QACrDM,SAASpB;QACTqB,SAAS,CAACC,SAAWA,OAAOhB,KAAK,IAAI;QACrCK,UAAUK;QACVJ,UAAUA;QACVW,gBAAgB;QAChBC,aAAa,CAAC,EAAEC,UAAU,EAAE,GAAGC,QAAQ,iBACrC,KAAC9B;gBACE,GAAG8B,MAAM;gBACVC,WAAW;oBACTC,OAAO;wBACL,GAAGH,UAAU;wBACbI,4BACE;;gCACGJ,WAAWI,YAAY;8CACxB,KAAClC;oCAAemC,UAAS;8CACvB,cAAA,KAACpC;wCACCqC,MAAK;wCACLC,cAAW;wCACXC,SAAS,IAAMtB,SAASQ;wCACxBP,UAAUA;wCACVsB,UAAU,CAAC;kDAEX,cAAA,KAACrC;4CAAUsC,UAAS;;;;;;oBAK9B;gBACF;;QAGH,GAAGtB,UAAU;;AAGpB"}
1
+ {"version":3,"sources":["../../src/FormatControls/UnitSelector.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { IconButton, InputAdornment, TextField } from '@mui/material';\nimport ClearIcon from 'mdi-material-ui/Close';\nimport type { ReactElement } from 'react';\n\nimport type { FormatOptions, UnitConfig } from '../model';\nimport { UNIT_CONFIG } from '../model';\nimport { SettingsAutocomplete } from '../SettingsAutocomplete';\n\nexport interface UnitSelectorProps {\n value?: FormatOptions;\n onChange: (format: FormatOptions | undefined) => void;\n disabled?: boolean;\n}\n\ntype AutocompleteUnitOption = UnitConfig & {\n id: NonNullable<FormatOptions['unit']>;\n};\n\nconst KIND_OPTIONS: readonly AutocompleteUnitOption[] = Object.entries(UNIT_CONFIG)\n .map<AutocompleteUnitOption>(([id, config]) => {\n return {\n ...config,\n id: id as AutocompleteUnitOption['id'],\n group: config.group || 'Decimal',\n };\n })\n .filter((config) => !config.disableSelectorOption);\n\nexport function UnitSelector({ value, onChange, disabled = false, ...otherProps }: UnitSelectorProps): ReactElement {\n const unitConfig = UNIT_CONFIG[value?.unit || 'decimal'];\n\n const handleChange = (_: unknown, newValue: AutocompleteUnitOption | null): void => {\n if (newValue === null) {\n onChange(undefined);\n return;\n }\n onChange({ unit: newValue.id } as FormatOptions);\n };\n\n return (\n <SettingsAutocomplete<AutocompleteUnitOption, false, true>\n value={{ id: value?.unit || 'decimal', ...unitConfig }}\n options={KIND_OPTIONS}\n groupBy={(option) => option.group ?? 'Decimal'}\n onChange={handleChange}\n disabled={disabled}\n disableClearable\n renderInput={({ InputProps, ...params }) => (\n <TextField\n {...params}\n slotProps={{\n input: {\n ...InputProps,\n endAdornment: (\n <>\n {InputProps.endAdornment}\n <InputAdornment position=\"end\">\n <IconButton\n size=\"small\"\n aria-label=\"clear unit\"\n onClick={() => onChange(undefined)}\n disabled={disabled}\n tabIndex={-1}\n >\n <ClearIcon fontSize=\"small\" />\n </IconButton>\n </InputAdornment>\n </>\n ),\n },\n }}\n />\n )}\n {...otherProps}\n />\n );\n}\n"],"names":["IconButton","InputAdornment","TextField","ClearIcon","UNIT_CONFIG","SettingsAutocomplete","KIND_OPTIONS","Object","entries","map","id","config","group","filter","disableSelectorOption","UnitSelector","value","onChange","disabled","otherProps","unitConfig","unit","handleChange","_","newValue","undefined","options","groupBy","option","disableClearable","renderInput","InputProps","params","slotProps","input","endAdornment","position","size","aria-label","onClick","tabIndex","fontSize"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CA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Root":"","sources":["../../src/Legend/TableLegend.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAG1C,OAAO,KAAK,EAAE,UAAU,EAAqB,MAAM,UAAU,CAAC;AAE9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,MAAM,WAAW,gBAAiB,SAAQ,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,SAAS,GAAG,iBAAiB,CAAC;IACnG,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC,cAAc,CAAC,GAAG,KAAK,CAAC;IAC9D,qBAAqB,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC,sBAAsB,CAAC,CAAC;IACtE,eAAe,CAAC,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC,gBAAgB,CAAC,CAAC;IAC3D,cAAc,CAAC,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC,eAAe,CAAC,CAAC;IACzD,OAAO,CAAC,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,CAAC;CAC7C;AA4BD,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EACL,aAAa,EAAE,gBAAgB,EAC/B,qBAAqB,EACrB,eAAe,EACf,cAAc,EACd,MAAM,EACN,KAAK,EACL,OAAO,EAAE,iBAAiC,EAC1C,OAAO,EACP,eAAe,GAChB,EAAE,gBAAgB,GAAG,YAAY,CAyDjC"}
@@ -36,7 +36,8 @@ const getCheckboxColor = (data)=>{
36
36
  };
37
37
  // This is a rough estimate of value that needs to be subtracted from the total width to avoid horizontal scrolling on initial render
38
38
  const TABLE_PADDING = 45;
39
- export function TableLegend({ items, selectedItems: initRowSelection, onSelectedItemsChange, onItemMouseOver, onItemMouseOut, height, width, columns: additionalColumns = [], sorting, onSortingChange }) {
39
+ const EMPTY_COLUMNS = [];
40
+ export function TableLegend({ items, selectedItems: initRowSelection, onSelectedItemsChange, onItemMouseOver, onItemMouseOut, height, width, columns: additionalColumns = EMPTY_COLUMNS, sorting, onSortingChange }) {
40
41
  const rowSelection = useMemo(()=>{
41
42
  return typeof initRowSelection !== 'string' ? initRowSelection : // items for checkboxes.
42
43
  // TODO: clean this up if we switch to also using checkboxes in list legend.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Legend/TableLegend.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { ReactElement } from 'react';\nimport { useMemo } from 'react';\n\nimport type { TableProps, TableColumnConfig } from '../Table';\nimport { Table, DEFAULT_COLUMN_WIDTH, DEFAULT_COLUMN_MIN_WIDTH } from '../Table';\nimport type { LegendItem } from './legend-model';\n\nexport interface TableLegendProps extends Pick<TableProps<LegendItem>, 'sorting' | 'onSortingChange'> {\n items: LegendItem[];\n height: number;\n width: number;\n selectedItems: TableProps<LegendItem>['rowSelection'] | 'ALL';\n onSelectedItemsChange: TableProps<LegendItem>['onRowSelectionChange'];\n onItemMouseOver?: TableProps<LegendItem>['onRowMouseOver'];\n onItemMouseOut?: TableProps<LegendItem>['onRowMouseOut'];\n columns?: TableProps<LegendItem>['columns'];\n}\n\nconst COLUMNS: Array<TableColumnConfig<LegendItem>> = [\n {\n accessorKey: 'label',\n header: 'Name',\n enableSorting: true,\n enableResizing: true,\n\n // Starting with `title` attr instead of a tooltip because it is easier to\n // implement. We should try adding a tooltip in the future, but we'll need\n // to be very careful about performance when doing so with large tables.\n cell: ({ getValue }) => <span title={getValue()}>{getValue()}</span>,\n },\n];\n\nconst getRowId: NonNullable<TableProps<LegendItem>['getRowId']> = (data) => {\n return data.id;\n};\n\nconst getCheckboxColor: TableProps<LegendItem>['getCheckboxColor'] = (data) => {\n return data.color;\n};\n\n// This is a rough estimate of value that needs to be subtracted from the total width to avoid horizontal scrolling on initial render\nconst TABLE_PADDING = 45;\n\nexport function TableLegend({\n items,\n selectedItems: initRowSelection,\n onSelectedItemsChange,\n onItemMouseOver,\n onItemMouseOut,\n height,\n width,\n columns: additionalColumns = [],\n sorting,\n onSortingChange,\n}: TableLegendProps): ReactElement {\n const rowSelection = useMemo(() => {\n return typeof initRowSelection !== 'string'\n ? initRowSelection\n : // Turn \"ALL\" state into a table component friendly map of all of the selected\n // items for checkboxes.\n // TODO: clean this up if we switch to also using checkboxes in list legend.\n items.reduce(\n (allRowSelection, item, index) => {\n allRowSelection[getRowId(item, index)] = true;\n return allRowSelection;\n },\n {} as Record<string, boolean>,\n );\n }, [initRowSelection, items]);\n\n const columns = useMemo(() => {\n // Calculate column widths to fit the container on initial render, avoiding unnecessary horizontal scrolling.\n // Falls back to a default width if available width is too small; the user can resize columns as needed.\n const additionalColumnsLength =\n additionalColumns?.reduce((colWidth, col) => {\n return colWidth + (typeof col.width === 'number' ? col.width : DEFAULT_COLUMN_WIDTH);\n }, 0) ?? 0;\n const availableWidth = Math.max(\n width - additionalColumnsLength - TABLE_PADDING,\n DEFAULT_COLUMN_MIN_WIDTH * COLUMNS.length,\n );\n const columnWidth = availableWidth / COLUMNS.length;\n return [\n ...COLUMNS.map((column) => ({\n ...column,\n width: columnWidth,\n })),\n ...additionalColumns,\n ];\n }, [additionalColumns, width]);\n\n return (\n <Table\n height={height}\n width={width}\n rowSelection={rowSelection}\n onRowSelectionChange={onSelectedItemsChange}\n onRowMouseOver={onItemMouseOver}\n onRowMouseOut={onItemMouseOut}\n sorting={sorting}\n onSortingChange={onSortingChange}\n data={items}\n columns={columns}\n density=\"compact\"\n defaultColumnWidth=\"auto\"\n getRowId={getRowId}\n getCheckboxColor={getCheckboxColor}\n checkboxSelection\n rowSelectionVariant=\"legend\"\n />\n );\n}\n"],"names":["useMemo","Table","DEFAULT_COLUMN_WIDTH","DEFAULT_COLUMN_MIN_WIDTH","COLUMNS","accessorKey","header","enableSorting","enableResizing","cell","getValue","span","title","getRowId","data","id","getCheckboxColor","color","TABLE_PADDING","TableLegend","items","selectedItems","initRowSelection","onSelectedItemsChange","onItemMouseOver","onItemMouseOut","height","width","columns","additionalColumns","sorting","onSortingChange","rowSelection","reduce","allRowSelection","item","index","additionalColumnsLength","colWidth","col","availableWidth","Math","max","length","columnWidth","map","column","onRowSelectionChange","onRowMouseOver","onRowMouseOut","density","defaultColumnWidth","checkboxSelection","rowSelectionVariant"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAGjC,SAASA,OAAO,QAAQ,QAAQ;AAGhC,SAASC,KAAK,EAAEC,oBAAoB,EAAEC,wBAAwB,QAAQ,oBAAW;AAcjF,MAAMC,UAAgD;IACpD;QACEC,aAAa;QACbC,QAAQ;QACRC,eAAe;QACfC,gBAAgB;QAEhB,0EAA0E;QAC1E,0EAA0E;QAC1E,wEAAwE;QACxEC,MAAM,CAAC,EAAEC,QAAQ,EAAE,iBAAK,KAACC;gBAAKC,OAAOF;0BAAaA;;IACpD;CACD;AAED,MAAMG,WAA4D,CAACC;IACjE,OAAOA,KAAKC,EAAE;AAChB;AAEA,MAAMC,mBAA+D,CAACF;IACpE,OAAOA,KAAKG,KAAK;AACnB;AAEA,qIAAqI;AACrI,MAAMC,gBAAgB;AAEtB,OAAO,SAASC,YAAY,EAC1BC,KAAK,EACLC,eAAeC,gBAAgB,EAC/BC,qBAAqB,EACrBC,eAAe,EACfC,cAAc,EACdC,MAAM,EACNC,KAAK,EACLC,SAASC,oBAAoB,EAAE,EAC/BC,OAAO,EACPC,eAAe,EACE;IACjB,MAAMC,eAAehC,QAAQ;QAC3B,OAAO,OAAOsB,qBAAqB,WAC/BA,mBAEA,wBAAwB;QACxB,4EAA4E;QAC5EF,MAAMa,MAAM,CACV,CAACC,iBAAiBC,MAAMC;YACtBF,eAAe,CAACrB,SAASsB,MAAMC,OAAO,GAAG;YACzC,OAAOF;QACT,GACA,CAAC;IAET,GAAG;QAACZ;QAAkBF;KAAM;IAE5B,MAAMQ,UAAU5B,QAAQ;QACtB,6GAA6G;QAC7G,wGAAwG;QACxG,MAAMqC,0BACJR,mBAAmBI,OAAO,CAACK,UAAUC;YACnC,OAAOD,WAAY,CAAA,OAAOC,IAAIZ,KAAK,KAAK,WAAWY,IAAIZ,KAAK,GAAGzB,oBAAmB;QACpF,GAAG,MAAM;QACX,MAAMsC,iBAAiBC,KAAKC,GAAG,CAC7Bf,QAAQU,0BAA0BnB,eAClCf,2BAA2BC,QAAQuC,MAAM;QAE3C,MAAMC,cAAcJ,iBAAiBpC,QAAQuC,MAAM;QACnD,OAAO;eACFvC,QAAQyC,GAAG,CAAC,CAACC,SAAY,CAAA;oBAC1B,GAAGA,MAAM;oBACTnB,OAAOiB;gBACT,CAAA;eACGf;SACJ;IACH,GAAG;QAACA;QAAmBF;KAAM;IAE7B,qBACE,KAAC1B;QACCyB,QAAQA;QACRC,OAAOA;QACPK,cAAcA;QACde,sBAAsBxB;QACtByB,gBAAgBxB;QAChByB,eAAexB;QACfK,SAASA;QACTC,iBAAiBA;QACjBjB,MAAMM;QACNQ,SAASA;QACTsB,SAAQ;QACRC,oBAAmB;QACnBtC,UAAUA;QACVG,kBAAkBA;QAClBoC,iBAAiB;QACjBC,qBAAoB;;AAG1B"}
1
+ {"version":3,"sources":["../../src/Legend/TableLegend.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { ReactElement } from 'react';\nimport { useMemo } from 'react';\n\nimport type { TableProps, TableColumnConfig } from '../Table';\nimport { Table, DEFAULT_COLUMN_WIDTH, DEFAULT_COLUMN_MIN_WIDTH } from '../Table';\nimport type { LegendItem } from './legend-model';\n\nexport interface TableLegendProps extends Pick<TableProps<LegendItem>, 'sorting' | 'onSortingChange'> {\n items: LegendItem[];\n height: number;\n width: number;\n selectedItems: TableProps<LegendItem>['rowSelection'] | 'ALL';\n onSelectedItemsChange: TableProps<LegendItem>['onRowSelectionChange'];\n onItemMouseOver?: TableProps<LegendItem>['onRowMouseOver'];\n onItemMouseOut?: TableProps<LegendItem>['onRowMouseOut'];\n columns?: TableProps<LegendItem>['columns'];\n}\n\nconst COLUMNS: Array<TableColumnConfig<LegendItem>> = [\n {\n accessorKey: 'label',\n header: 'Name',\n enableSorting: true,\n enableResizing: true,\n\n // Starting with `title` attr instead of a tooltip because it is easier to\n // implement. We should try adding a tooltip in the future, but we'll need\n // to be very careful about performance when doing so with large tables.\n cell: ({ getValue }) => <span title={getValue<string>()}>{getValue<string>()}</span>,\n },\n];\n\nconst getRowId: NonNullable<TableProps<LegendItem>['getRowId']> = (data) => {\n return data.id;\n};\n\nconst getCheckboxColor: TableProps<LegendItem>['getCheckboxColor'] = (data) => {\n return data.color;\n};\n\n// This is a rough estimate of value that needs to be subtracted from the total width to avoid horizontal scrolling on initial render\nconst TABLE_PADDING = 45;\nconst EMPTY_COLUMNS: Array<TableColumnConfig<LegendItem>> = [];\n\nexport function TableLegend({\n items,\n selectedItems: initRowSelection,\n onSelectedItemsChange,\n onItemMouseOver,\n onItemMouseOut,\n height,\n width,\n columns: additionalColumns = EMPTY_COLUMNS,\n sorting,\n onSortingChange,\n}: TableLegendProps): ReactElement {\n const rowSelection = useMemo(() => {\n return typeof initRowSelection !== 'string'\n ? initRowSelection\n : // Turn \"ALL\" state into a table component friendly map of all of the selected\n // items for checkboxes.\n // TODO: clean this up if we switch to also using checkboxes in list legend.\n items.reduce(\n (allRowSelection, item, index) => {\n allRowSelection[getRowId(item, index)] = true;\n return allRowSelection;\n },\n {} as Record<string, boolean>,\n );\n }, [initRowSelection, items]);\n\n const columns = useMemo(() => {\n // Calculate column widths to fit the container on initial render, avoiding unnecessary horizontal scrolling.\n // Falls back to a default width if available width is too small; the user can resize columns as needed.\n const additionalColumnsLength =\n additionalColumns?.reduce((colWidth, col) => {\n return colWidth + (typeof col.width === 'number' ? col.width : DEFAULT_COLUMN_WIDTH);\n }, 0) ?? 0;\n const availableWidth = Math.max(\n width - additionalColumnsLength - TABLE_PADDING,\n DEFAULT_COLUMN_MIN_WIDTH * COLUMNS.length,\n );\n const columnWidth = availableWidth / COLUMNS.length;\n return [\n ...COLUMNS.map((column) => ({\n ...column,\n width: columnWidth,\n })),\n ...additionalColumns,\n ];\n }, [additionalColumns, width]);\n\n return (\n <Table\n height={height}\n width={width}\n rowSelection={rowSelection}\n onRowSelectionChange={onSelectedItemsChange}\n onRowMouseOver={onItemMouseOver}\n onRowMouseOut={onItemMouseOut}\n sorting={sorting}\n onSortingChange={onSortingChange}\n data={items}\n columns={columns}\n density=\"compact\"\n defaultColumnWidth=\"auto\"\n getRowId={getRowId}\n getCheckboxColor={getCheckboxColor}\n checkboxSelection\n rowSelectionVariant=\"legend\"\n />\n );\n}\n"],"names":["useMemo","Table","DEFAULT_COLUMN_WIDTH","DEFAULT_COLUMN_MIN_WIDTH","COLUMNS","accessorKey","header","enableSorting","enableResizing","cell","getValue","span","title","getRowId","data","id","getCheckboxColor","color","TABLE_PADDING","EMPTY_COLUMNS","TableLegend","items","selectedItems","initRowSelection","onSelectedItemsChange","onItemMouseOver","onItemMouseOut","height","width","columns","additionalColumns","sorting","onSortingChange","rowSelection","reduce","allRowSelection","item","index","additionalColumnsLength","colWidth","col","availableWidth","Math","max","length","columnWidth","map","column","onRowSelectionChange","onRowMouseOver","onRowMouseOut","density","defaultColumnWidth","checkboxSelection","rowSelectionVariant"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAGjC,SAASA,OAAO,QAAQ,QAAQ;AAGhC,SAASC,KAAK,EAAEC,oBAAoB,EAAEC,wBAAwB,QAAQ,oBAAW;AAcjF,MAAMC,UAAgD;IACpD;QACEC,aAAa;QACbC,QAAQ;QACRC,eAAe;QACfC,gBAAgB;QAEhB,0EAA0E;QAC1E,0EAA0E;QAC1E,wEAAwE;QACxEC,MAAM,CAAC,EAAEC,QAAQ,EAAE,iBAAK,KAACC;gBAAKC,OAAOF;0BAAqBA;;IAC5D;CACD;AAED,MAAMG,WAA4D,CAACC;IACjE,OAAOA,KAAKC,EAAE;AAChB;AAEA,MAAMC,mBAA+D,CAACF;IACpE,OAAOA,KAAKG,KAAK;AACnB;AAEA,qIAAqI;AACrI,MAAMC,gBAAgB;AACtB,MAAMC,gBAAsD,EAAE;AAE9D,OAAO,SAASC,YAAY,EAC1BC,KAAK,EACLC,eAAeC,gBAAgB,EAC/BC,qBAAqB,EACrBC,eAAe,EACfC,cAAc,EACdC,MAAM,EACNC,KAAK,EACLC,SAASC,oBAAoBX,aAAa,EAC1CY,OAAO,EACPC,eAAe,EACE;IACjB,MAAMC,eAAejC,QAAQ;QAC3B,OAAO,OAAOuB,qBAAqB,WAC/BA,mBAEA,wBAAwB;QACxB,4EAA4E;QAC5EF,MAAMa,MAAM,CACV,CAACC,iBAAiBC,MAAMC;YACtBF,eAAe,CAACtB,SAASuB,MAAMC,OAAO,GAAG;YACzC,OAAOF;QACT,GACA,CAAC;IAET,GAAG;QAACZ;QAAkBF;KAAM;IAE5B,MAAMQ,UAAU7B,QAAQ;QACtB,6GAA6G;QAC7G,wGAAwG;QACxG,MAAMsC,0BACJR,mBAAmBI,OAAO,CAACK,UAAUC;YACnC,OAAOD,WAAY,CAAA,OAAOC,IAAIZ,KAAK,KAAK,WAAWY,IAAIZ,KAAK,GAAG1B,oBAAmB;QACpF,GAAG,MAAM;QACX,MAAMuC,iBAAiBC,KAAKC,GAAG,CAC7Bf,QAAQU,0BAA0BpB,eAClCf,2BAA2BC,QAAQwC,MAAM;QAE3C,MAAMC,cAAcJ,iBAAiBrC,QAAQwC,MAAM;QACnD,OAAO;eACFxC,QAAQ0C,GAAG,CAAC,CAACC,SAAY,CAAA;oBAC1B,GAAGA,MAAM;oBACTnB,OAAOiB;gBACT,CAAA;eACGf;SACJ;IACH,GAAG;QAACA;QAAmBF;KAAM;IAE7B,qBACE,KAAC3B;QACC0B,QAAQA;QACRC,OAAOA;QACPK,cAAcA;QACde,sBAAsBxB;QACtByB,gBAAgBxB;QAChByB,eAAexB;QACfK,SAASA;QACTC,iBAAiBA;QACjBlB,MAAMO;QACNQ,SAASA;QACTsB,SAAQ;QACRC,oBAAmB;QACnBvC,UAAUA;QACVG,kBAAkBA;QAClBqC,iBAAiB;QACjBC,qBAAoB;;AAG1B"}
@@ -2,6 +2,7 @@ import type { ReactElement } from 'react';
2
2
  export interface LinkEditorFormField<T> {
3
3
  value: T;
4
4
  onChange: (value: T) => void;
5
+ onBlur?: () => void;
5
6
  placeholder?: string;
6
7
  label: string;
7
8
  error: {
@@ -1 +1 @@
1
- {"version":3,"file":"LinkEditorForm.d.ts","sourceRoot":"","sources":["../../src/LinksEditor/LinkEditorForm.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAI1C,MAAM,WAAW,mBAAmB,CAAC,CAAC;IACp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AC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACpD;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,QAAQ,GAAG,eAAe,CAAC;IACjC,GAAG,EAAE,mBAAmB,CAAC,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;IAClD,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;IACrD,UAAU,EAAE,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;IACxD,eAAe,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;CAC/D;AAED,eAAO,MAAM,cAAc,UAAW,mBAAmB,KAAG,YAqE3D,CAAC"}
@@ -25,6 +25,7 @@ export const LinkEditorForm = (props)=>{
25
25
  error: url.error?.hasError,
26
26
  helperText: url.error?.helperText,
27
27
  onChange: url.onChange,
28
+ onBlur: url.onBlur,
28
29
  placeholder: url.placeholder,
29
30
  multiline: true,
30
31
  maxRows: 5,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/LinksEditor/LinkEditorForm.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Checkbox, FormControlLabel, Stack } from '@mui/material';\nimport type { ReactElement } from 'react';\n\nimport { TextField } from '../controls';\n\nexport interface LinkEditorFormField<T> {\n value: T;\n onChange: (value: T) => void;\n placeholder?: string;\n label: string;\n error: { hasError?: boolean; helperText?: string };\n}\n\nexport interface LinkEditorFormProps {\n mode: 'inline' | 'modalEmbedded';\n url: LinkEditorFormField<string>;\n name?: Omit<LinkEditorFormField<string>, 'error'>;\n tooltip?: Omit<LinkEditorFormField<string>, 'error'>;\n newTabOpen: Omit<LinkEditorFormField<boolean>, 'error'>;\n renderVariables?: Omit<LinkEditorFormField<boolean>, 'error'>;\n}\n\nexport const LinkEditorForm = (props: LinkEditorFormProps): ReactElement => {\n const { mode, url, name, newTabOpen, renderVariables, tooltip } = props;\n\n return (\n <Stack direction=\"column\" gap={2} flexGrow={1}>\n <TextField\n label={url.label}\n error={url.error?.hasError}\n helperText={url.error?.helperText}\n onChange={url.onChange}\n placeholder={url.placeholder}\n multiline\n maxRows={5}\n required\n fullWidth\n value={url.value}\n />\n {(name || tooltip) && (\n <Stack gap={1} direction={mode === 'inline' ? 'row' : 'column'}>\n {name && (\n <TextField\n sx={{ flexGrow: '1' }}\n label={name.label}\n onChange={name?.onChange}\n placeholder={name?.placeholder}\n value={name?.value}\n />\n )}\n {tooltip && (\n <TextField\n sx={{ flexGrow: '1' }}\n label={tooltip.label}\n onChange={tooltip?.onChange}\n placeholder={tooltip?.placeholder}\n value={tooltip?.value}\n />\n )}\n </Stack>\n )}\n <Stack direction=\"row\" gap={1}>\n {renderVariables && (\n <FormControlLabel\n label={renderVariables.label}\n control={\n <Checkbox\n checked={renderVariables.value}\n onChange={(e) => {\n renderVariables?.onChange(e.target.checked);\n }}\n />\n }\n />\n )}\n\n <FormControlLabel\n label={newTabOpen.label}\n control={\n <Checkbox\n checked={newTabOpen.value}\n onChange={(e) => {\n newTabOpen?.onChange(e.target.checked);\n }}\n />\n }\n />\n </Stack>\n </Stack>\n );\n};\n"],"names":["Checkbox","FormControlLabel","Stack","TextField","LinkEditorForm","props","mode","url","name","newTabOpen","renderVariables","tooltip","direction","gap","flexGrow","label","error","hasError","helperText","onChange","placeholder","multiline","maxRows","required","fullWidth","value","s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BACCc,OAAOL,gBAAgBK,KAAK;wBAC5BY,uBACE,KAAC3B;4BACC4B,SAASlB,gBAAgBe,KAAK;4BAC9BN,UAAU,CAACU;gCACTnB,iBAAiBS,SAASU,EAAEC,MAAM,CAACF,OAAO;4BAC5C;;;kCAMR,KAAC3B;wBACCc,OAAON,WAAWM,KAAK;wBACvBY,uBACE,KAAC3B;4BACC4B,SAASnB,WAAWgB,KAAK;4BACzBN,UAAU,CAACU;gCACTpB,YAAYU,SAASU,EAAEC,MAAM,CAACF,OAAO;4BACvC;;;;;;;AAOd,EAAE"}
1
+ {"version":3,"sources":["../../src/LinksEditor/LinkEditorForm.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Checkbox, FormControlLabel, Stack } from '@mui/material';\nimport type { ReactElement } from 'react';\n\nimport { TextField } from '../controls';\n\nexport interface LinkEditorFormField<T> {\n value: T;\n onChange: (value: T) => void;\n onBlur?: () => void;\n placeholder?: string;\n label: string;\n error: { hasError?: boolean; helperText?: string };\n}\n\nexport interface LinkEditorFormProps {\n mode: 'inline' | 'modalEmbedded';\n url: LinkEditorFormField<string>;\n name?: Omit<LinkEditorFormField<string>, 'error'>;\n tooltip?: Omit<LinkEditorFormField<string>, 'error'>;\n newTabOpen: Omit<LinkEditorFormField<boolean>, 'error'>;\n renderVariables?: Omit<LinkEditorFormField<boolean>, 'error'>;\n}\n\nexport const LinkEditorForm = (props: LinkEditorFormProps): ReactElement => {\n const { mode, url, name, newTabOpen, renderVariables, tooltip } = props;\n\n return (\n <Stack direction=\"column\" gap={2} flexGrow={1}>\n <TextField\n label={url.label}\n error={url.error?.hasError}\n helperText={url.error?.helperText}\n onChange={url.onChange}\n onBlur={url.onBlur}\n placeholder={url.placeholder}\n multiline\n maxRows={5}\n required\n fullWidth\n value={url.value}\n />\n {(name || tooltip) && (\n <Stack gap={1} direction={mode === 'inline' ? 'row' : 'column'}>\n {name && (\n <TextField\n sx={{ flexGrow: '1' }}\n label={name.label}\n onChange={name?.onChange}\n placeholder={name?.placeholder}\n value={name?.value}\n />\n )}\n {tooltip && (\n <TextField\n sx={{ flexGrow: '1' }}\n label={tooltip.label}\n onChange={tooltip?.onChange}\n placeholder={tooltip?.placeholder}\n value={tooltip?.value}\n />\n )}\n </Stack>\n )}\n <Stack direction=\"row\" gap={1}>\n {renderVariables && (\n <FormControlLabel\n label={renderVariables.label}\n control={\n <Checkbox\n checked={renderVariables.value}\n onChange={(e) => {\n renderVariables?.onChange(e.target.checked);\n }}\n />\n }\n />\n )}\n\n <FormControlLabel\n label={newTabOpen.label}\n control={\n <Checkbox\n checked={newTabOpen.value}\n onChange={(e) => {\n newTabOpen?.onChange(e.target.checked);\n }}\n />\n }\n />\n </Stack>\n </Stack>\n );\n};\n"],"names":["Checkbox","FormControlLabel","Stack","TextField","LinkEditorForm","props","mode","url","name","newTabOpen","renderVariables","tooltip","direction","gap","flexGrow","label","error","hasError","helperText","onChange","onBlur","placeholder","multiline","maxRows","required","fullWidth","value","sx","control","checked","e","target"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,QAAQ,EAAEC,gBAAgB,EAAEC,KAAK,QAAQ,gBAAgB;AAGlE,SAASC,SAAS,QAAQ,uBAAc;AAoBxC,OAAO,MAAMC,iBAAiB,CAACC;IAC7B,MAAM,EAAEC,IAAI,EAAEC,GAAG,EAAEC,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EAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"OptionsEditorControl.d.ts","sourceRoot":"","sources":["../../src/OptionsEditorLayout/OptionsEditorControl.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAG3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAM1C,MAAM,MAAM,yBAAyB,GAAG,IAAI,CAAC,qBAAqB,EAAE,OAAO,GAAG,SAAS,CAAC,GAAG;IACzF,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,oBAAoB,oCAAqC,yBAAyB,KAAG,YAuCjG,CAAC"}
1
+ {"version":3,"file":"OptionsEditorControl.d.ts","sourceRoot":"","sources":["../../src/OptionsEditorLayout/OptionsEditorControl.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAG3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAK1C,MAAM,MAAM,yBAAyB,GAAG,IAAI,CAAC,qBAAqB,EAAE,OAAO,GAAG,SAAS,CAAC,GAAG;IACzF,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,oBAAoB,oCAAqC,yBAAyB,KAAG,YAuCjG,CAAC"}