@perses-dev/components 0.54.0-beta.0 → 0.54.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AlignSelector/AlignSelector.js +1 -1
- package/dist/AlignSelector/AlignSelector.js.map +1 -1
- package/dist/ColorPicker/ColorPicker.js +1 -1
- package/dist/ColorPicker/ColorPicker.js.map +1 -1
- package/dist/ColorPicker/OptionsColorPicker.js +1 -1
- package/dist/ColorPicker/OptionsColorPicker.js.map +1 -1
- package/dist/ContentWithLegend/ContentWithLegend.js +1 -1
- package/dist/ContentWithLegend/ContentWithLegend.js.map +1 -1
- package/dist/ContentWithLegend/model/content-with-legend-model.d.ts +1 -1
- package/dist/ContentWithLegend/model/content-with-legend-model.d.ts.map +1 -1
- package/dist/ContentWithLegend/model/content-with-legend-model.js +1 -1
- package/dist/ContentWithLegend/model/content-with-legend-model.js.map +1 -1
- package/dist/Dialog/DiscardChangesConfirmationDialog.js +1 -1
- package/dist/Dialog/DiscardChangesConfirmationDialog.js.map +1 -1
- package/dist/DragAndDrop/DragAndDropList.js +1 -1
- package/dist/DragAndDrop/DragAndDropList.js.map +1 -1
- package/dist/DragAndDrop/DragButton.js +1 -1
- package/dist/DragAndDrop/DragButton.js.map +1 -1
- package/dist/DragAndDrop/DropIndicator.js +1 -1
- package/dist/DragAndDrop/DropIndicator.js.map +1 -1
- package/dist/Drawer/Drawer.js +1 -1
- package/dist/Drawer/Drawer.js.map +1 -1
- package/dist/EChart/EChart.js +1 -1
- package/dist/EChart/EChart.js.map +1 -1
- package/dist/ErrorAlert.js +1 -1
- package/dist/ErrorAlert.js.map +1 -1
- package/dist/FormEditor/FormActions.d.ts +1 -1
- package/dist/FormEditor/FormActions.d.ts.map +1 -1
- package/dist/FormEditor/FormActions.js +1 -1
- package/dist/FormEditor/FormActions.js.map +1 -1
- package/dist/FormatControls/FormatControls.d.ts +1 -1
- package/dist/FormatControls/FormatControls.d.ts.map +1 -1
- package/dist/FormatControls/FormatControls.js +2 -2
- package/dist/FormatControls/FormatControls.js.map +1 -1
- package/dist/FormatControls/UnitSelector.d.ts +1 -1
- package/dist/FormatControls/UnitSelector.d.ts.map +1 -1
- package/dist/FormatControls/UnitSelector.js +1 -1
- package/dist/FormatControls/UnitSelector.js.map +1 -1
- package/dist/JSONEditor.js +1 -1
- package/dist/JSONEditor.js.map +1 -1
- package/dist/Legend/CompactLegend.js +1 -1
- package/dist/Legend/CompactLegend.js.map +1 -1
- package/dist/Legend/Legend.js +2 -2
- package/dist/Legend/Legend.js.map +1 -1
- package/dist/Legend/LegendColorBadge.js +1 -1
- package/dist/Legend/LegendColorBadge.js.map +1 -1
- package/dist/Legend/ListLegend.js +1 -1
- package/dist/Legend/ListLegend.js.map +1 -1
- package/dist/Legend/ListLegendItem.js +1 -1
- package/dist/Legend/ListLegendItem.js.map +1 -1
- package/dist/Legend/TableLegend.d.ts.map +1 -1
- package/dist/Legend/TableLegend.js +18 -4
- package/dist/Legend/TableLegend.js.map +1 -1
- package/dist/Legend/legend-model.d.ts +1 -1
- package/dist/Legend/legend-model.d.ts.map +1 -1
- package/dist/Legend/legend-model.js.map +1 -1
- package/dist/LinksEditor/LinkEditorForm.js +1 -1
- package/dist/LinksEditor/LinkEditorForm.js.map +1 -1
- package/dist/LinksEditor/LinksEditor.js +1 -1
- package/dist/LinksEditor/LinksEditor.js.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorColumn.js +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorColumn.js.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorControl.js +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorGrid.js +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorGrid.js.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorGroup.js +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorGroup.js.map +1 -1
- package/dist/Overlay/Overlay.js +1 -1
- package/dist/Overlay/Overlay.js.map +1 -1
- package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js +1 -1
- package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js.map +1 -1
- package/dist/SettingsAutocomplete/SettingsAutocomplete.js +1 -1
- package/dist/SettingsAutocomplete/SettingsAutocomplete.js.map +1 -1
- package/dist/SortSelector/SortSelectorButtons.js +1 -1
- package/dist/SortSelector/SortSelectorButtons.js.map +1 -1
- package/dist/Table/InnerTable.js +1 -1
- package/dist/Table/InnerTable.js.map +1 -1
- package/dist/Table/Table.d.ts +1 -1
- package/dist/Table/Table.d.ts.map +1 -1
- package/dist/Table/Table.js +47 -14
- package/dist/Table/Table.js.map +1 -1
- package/dist/Table/TableBody.js +1 -1
- package/dist/Table/TableBody.js.map +1 -1
- package/dist/Table/TableCell.js +1 -1
- package/dist/Table/TableCell.js.map +1 -1
- package/dist/Table/TableCheckbox.js +1 -1
- package/dist/Table/TableCheckbox.js.map +1 -1
- package/dist/Table/TableFoot.js +1 -1
- package/dist/Table/TableFoot.js.map +1 -1
- package/dist/Table/TableHead.js +1 -1
- package/dist/Table/TableHead.js.map +1 -1
- package/dist/Table/TableHeaderCell.d.ts +20 -1
- package/dist/Table/TableHeaderCell.d.ts.map +1 -1
- package/dist/Table/TableHeaderCell.js +56 -24
- package/dist/Table/TableHeaderCell.js.map +1 -1
- package/dist/Table/TableRow.js +1 -1
- package/dist/Table/TableRow.js.map +1 -1
- package/dist/Table/TableToolbar.d.ts +46 -0
- package/dist/Table/TableToolbar.d.ts.map +1 -0
- package/dist/Table/TableToolbar.js +138 -0
- package/dist/Table/TableToolbar.js.map +1 -0
- package/dist/Table/VirtualizedTable.d.ts +7 -3
- package/dist/Table/VirtualizedTable.d.ts.map +1 -1
- package/dist/Table/VirtualizedTable.js +157 -123
- package/dist/Table/VirtualizedTable.js.map +1 -1
- package/dist/Table/VirtualizedTableContainer.d.ts.map +1 -1
- package/dist/Table/VirtualizedTableContainer.js +6 -2
- package/dist/Table/VirtualizedTableContainer.js.map +1 -1
- package/dist/Table/hooks/useFuzzySearch.d.ts +14 -0
- package/dist/Table/hooks/useFuzzySearch.d.ts.map +1 -0
- package/dist/Table/hooks/useFuzzySearch.js +62 -0
- package/dist/Table/hooks/useFuzzySearch.js.map +1 -0
- package/dist/Table/model/table-model.d.ts +78 -4
- package/dist/Table/model/table-model.d.ts.map +1 -1
- package/dist/Table/model/table-model.js +37 -19
- package/dist/Table/model/table-model.js.map +1 -1
- package/dist/ThresholdsEditor/ThresholdInput.d.ts +1 -1
- package/dist/ThresholdsEditor/ThresholdInput.d.ts.map +1 -1
- package/dist/ThresholdsEditor/ThresholdInput.js +1 -1
- package/dist/ThresholdsEditor/ThresholdInput.js.map +1 -1
- package/dist/ThresholdsEditor/ThresholdsEditor.d.ts +1 -1
- package/dist/ThresholdsEditor/ThresholdsEditor.d.ts.map +1 -1
- package/dist/ThresholdsEditor/ThresholdsEditor.js +1 -1
- package/dist/ThresholdsEditor/ThresholdsEditor.js.map +1 -1
- package/dist/TimeRangeSelector/DateTimeRangePicker.js +1 -1
- package/dist/TimeRangeSelector/DateTimeRangePicker.js.map +1 -1
- package/dist/TimeRangeSelector/TimeRangeSelector.d.ts.map +1 -1
- package/dist/TimeRangeSelector/TimeRangeSelector.js +25 -2
- package/dist/TimeRangeSelector/TimeRangeSelector.js.map +1 -1
- package/dist/TimeSeriesTooltip/SeriesInfo.js +1 -1
- package/dist/TimeSeriesTooltip/SeriesInfo.js.map +1 -1
- package/dist/TimeSeriesTooltip/SeriesLabelsStack.js +1 -1
- package/dist/TimeSeriesTooltip/SeriesLabelsStack.js.map +1 -1
- package/dist/TimeSeriesTooltip/SeriesMarker.js +1 -1
- package/dist/TimeSeriesTooltip/SeriesMarker.js.map +1 -1
- package/dist/TimeSeriesTooltip/TimeChartTooltip.d.ts +1 -2
- package/dist/TimeSeriesTooltip/TimeChartTooltip.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/TimeChartTooltip.js +1 -1
- package/dist/TimeSeriesTooltip/TimeChartTooltip.js.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipContent.js +1 -1
- package/dist/TimeSeriesTooltip/TooltipContent.js.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipHeader.js +1 -1
- package/dist/TimeSeriesTooltip/TooltipHeader.js.map +1 -1
- package/dist/TimeSeriesTooltip/nearby-series.d.ts +2 -2
- package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/nearby-series.js +1 -2
- package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -1
- package/dist/TimeZoneSelector.js +1 -1
- package/dist/TimeZoneSelector.js.map +1 -1
- package/dist/ToolbarIconButton/ToolbarIconButton.js +1 -1
- package/dist/ToolbarIconButton/ToolbarIconButton.js.map +1 -1
- package/dist/TransformsEditor/TransformEditor.d.ts +1 -1
- package/dist/TransformsEditor/TransformEditor.d.ts.map +1 -1
- package/dist/TransformsEditor/TransformEditor.js +1 -1
- package/dist/TransformsEditor/TransformEditor.js.map +1 -1
- package/dist/TransformsEditor/TransformEditorContainer.d.ts.map +1 -1
- package/dist/TransformsEditor/TransformEditorContainer.js +2 -2
- package/dist/TransformsEditor/TransformEditorContainer.js.map +1 -1
- package/dist/TransformsEditor/TransformsEditor.d.ts +1 -1
- package/dist/TransformsEditor/TransformsEditor.d.ts.map +1 -1
- package/dist/TransformsEditor/TransformsEditor.js +1 -1
- package/dist/TransformsEditor/TransformsEditor.js.map +1 -1
- package/dist/ValueMappingEditor/ValueMappingEditor.d.ts +1 -1
- package/dist/ValueMappingEditor/ValueMappingEditor.d.ts.map +1 -1
- package/dist/ValueMappingEditor/ValueMappingEditor.js +1 -1
- package/dist/ValueMappingEditor/ValueMappingEditor.js.map +1 -1
- package/dist/ValueMappingEditor/ValueMappingsEditor.d.ts +1 -1
- package/dist/ValueMappingEditor/ValueMappingsEditor.d.ts.map +1 -1
- package/dist/ValueMappingEditor/ValueMappingsEditor.js +1 -1
- package/dist/ValueMappingEditor/ValueMappingsEditor.js.map +1 -1
- package/dist/YAxisLabel.js +1 -1
- package/dist/YAxisLabel.js.map +1 -1
- package/dist/cjs/ContentWithLegend/ContentWithLegend.js +2 -2
- package/dist/cjs/ContentWithLegend/model/content-with-legend-model.js +2 -2
- package/dist/cjs/FormatControls/FormatControls.js +4 -4
- package/dist/cjs/FormatControls/UnitSelector.js +3 -3
- package/dist/cjs/Legend/Legend.js +2 -2
- package/dist/cjs/Legend/TableLegend.js +16 -2
- package/dist/cjs/Table/Table.js +44 -11
- package/dist/cjs/Table/TableHeaderCell.js +54 -22
- package/dist/cjs/Table/TableToolbar.js +151 -0
- package/dist/cjs/Table/VirtualizedTable.js +155 -121
- package/dist/cjs/Table/VirtualizedTableContainer.js +5 -1
- package/dist/cjs/Table/hooks/useFuzzySearch.js +67 -0
- package/dist/cjs/Table/model/table-model.js +43 -19
- package/dist/cjs/TimeRangeSelector/TimeRangeSelector.js +23 -0
- package/dist/cjs/TimeSeriesTooltip/nearby-series.js +2 -3
- package/dist/cjs/TransformsEditor/TransformEditorContainer.js +2 -2
- package/dist/cjs/model/action.js +43 -0
- package/dist/cjs/model/bits.js +113 -0
- package/dist/cjs/model/bytes.js +115 -0
- package/dist/cjs/model/constants.js +23 -0
- package/dist/cjs/model/currency.js +126 -0
- package/dist/cjs/model/date.js +297 -0
- package/dist/cjs/model/decimal.js +72 -0
- package/dist/cjs/model/formatterCache.js +120 -0
- package/dist/cjs/model/index.js +17 -0
- package/dist/cjs/model/legend.js +101 -0
- package/dist/cjs/model/percent.js +82 -0
- package/dist/cjs/model/temperature.js +72 -0
- package/dist/cjs/model/thresholds.js +16 -0
- package/dist/cjs/model/throughput.js +161 -0
- package/dist/cjs/model/time.js +178 -0
- package/dist/cjs/model/transforms.js +29 -0
- package/dist/cjs/model/types.js +16 -0
- package/dist/cjs/model/units.js +186 -0
- package/dist/cjs/model/utils.js +48 -0
- package/dist/cjs/model/value-mapping.js +16 -0
- package/dist/cjs/theme/typography.js +1 -1
- package/dist/cjs/utils/axis.js +5 -5
- package/dist/cjs/utils/format.js +20 -0
- package/dist/cjs/utils/index.js +1 -0
- package/dist/cjs/utils/request-interpolation.js +49 -0
- package/dist/context/ChartsProvider.js +1 -1
- package/dist/context/ChartsProvider.js.map +1 -1
- package/dist/context/ItemActionsProvider.js +1 -1
- package/dist/context/ItemActionsProvider.js.map +1 -1
- package/dist/context/SelectionProvider.js +1 -1
- package/dist/context/SelectionProvider.js.map +1 -1
- package/dist/context/SnackbarProvider.js +1 -1
- package/dist/context/SnackbarProvider.js.map +1 -1
- package/dist/context/TimeZoneProvider.js +1 -1
- package/dist/context/TimeZoneProvider.js.map +1 -1
- package/dist/controls/TextField.js +1 -1
- package/dist/controls/TextField.js.map +1 -1
- package/dist/model/action.d.ts +4 -0
- package/dist/model/action.d.ts.map +1 -0
- package/dist/model/action.js +27 -0
- package/dist/model/action.js.map +1 -0
- package/dist/model/bits.d.ts +12 -0
- package/dist/model/bits.d.ts.map +1 -0
- package/dist/model/bits.js +89 -0
- package/dist/model/bits.js.map +1 -0
- package/dist/model/bytes.d.ts +12 -0
- package/dist/model/bytes.d.ts.map +1 -0
- package/dist/model/bytes.js +91 -0
- package/dist/model/bytes.js.map +1 -0
- package/dist/model/constants.d.ts +2 -0
- package/dist/model/constants.d.ts.map +1 -0
- package/dist/model/constants.js +15 -0
- package/dist/model/constants.js.map +1 -0
- package/dist/model/currency.d.ts +11 -0
- package/dist/model/currency.d.ts.map +1 -0
- package/dist/model/currency.js +107 -0
- package/dist/model/currency.js.map +1 -0
- package/dist/model/date.d.ts +28 -0
- package/dist/model/date.d.ts.map +1 -0
- package/dist/model/date.js +278 -0
- package/dist/model/date.js.map +1 -0
- package/dist/model/decimal.d.ts +12 -0
- package/dist/model/decimal.d.ts.map +1 -0
- package/dist/model/decimal.js +53 -0
- package/dist/model/decimal.js.map +1 -0
- package/dist/model/formatterCache.d.ts +11 -0
- package/dist/model/formatterCache.d.ts.map +1 -0
- package/dist/model/formatterCache.js +104 -0
- package/dist/model/formatterCache.js.map +1 -0
- package/dist/model/index.d.ts +17 -0
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +17 -0
- package/dist/model/index.js.map +1 -1
- package/dist/model/legend.d.ts +19 -0
- package/dist/model/legend.d.ts.map +1 -0
- package/dist/model/legend.js +61 -0
- package/dist/model/legend.js.map +1 -0
- package/dist/model/percent.d.ts +11 -0
- package/dist/model/percent.d.ts.map +1 -0
- package/dist/model/percent.js +63 -0
- package/dist/model/percent.js.map +1 -0
- package/dist/model/temperature.d.ts +11 -0
- package/dist/model/temperature.d.ts.map +1 -0
- package/dist/model/temperature.js +53 -0
- package/dist/model/temperature.js.map +1 -0
- package/dist/model/theme.d.ts +1 -1
- package/dist/model/theme.d.ts.map +1 -1
- package/dist/model/theme.js.map +1 -1
- package/dist/model/thresholds.d.ts +16 -0
- package/dist/model/thresholds.d.ts.map +1 -0
- package/dist/model/thresholds.js +15 -0
- package/dist/model/thresholds.js.map +1 -0
- package/dist/model/throughput.d.ts +12 -0
- package/dist/model/throughput.d.ts.map +1 -0
- package/dist/model/throughput.js +142 -0
- package/dist/model/throughput.js.map +1 -0
- package/dist/model/time.d.ts +23 -0
- package/dist/model/time.d.ts.map +1 -0
- package/dist/model/time.js +158 -0
- package/dist/model/time.js.map +1 -0
- package/dist/model/transforms.d.ts +43 -0
- package/dist/model/transforms.d.ts.map +1 -0
- package/dist/model/transforms.js +22 -0
- package/dist/model/transforms.js.map +1 -0
- package/dist/model/types.d.ts +56 -0
- package/dist/model/types.d.ts.map +1 -0
- package/dist/model/types.js +15 -0
- package/dist/model/types.js.map +1 -0
- package/dist/model/units.d.ts +105 -0
- package/dist/model/units.d.ts.map +1 -0
- package/dist/model/units.js +132 -0
- package/dist/model/units.js.map +1 -0
- package/dist/model/utils.d.ts +4 -0
- package/dist/model/utils.d.ts.map +1 -0
- package/dist/model/utils.js +32 -0
- package/dist/model/utils.js.map +1 -0
- package/dist/model/value-mapping.d.ts +35 -0
- package/dist/model/value-mapping.d.ts.map +1 -0
- package/dist/model/value-mapping.js +15 -0
- package/dist/model/value-mapping.js.map +1 -0
- package/dist/test/render.js +1 -1
- package/dist/test/render.js.map +1 -1
- package/dist/theme/typography.js +1 -1
- package/dist/theme/typography.js.map +1 -1
- package/dist/utils/axis.d.ts +1 -1
- package/dist/utils/axis.d.ts.map +1 -1
- package/dist/utils/axis.js +1 -1
- package/dist/utils/axis.js.map +1 -1
- package/dist/utils/format.d.ts +1 -0
- package/dist/utils/format.d.ts.map +1 -1
- package/dist/utils/format.js +17 -0
- package/dist/utils/format.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/request-interpolation.d.ts +6 -0
- package/dist/utils/request-interpolation.d.ts.map +1 -0
- package/dist/utils/request-interpolation.js +33 -0
- package/dist/utils/request-interpolation.js.map +1 -0
- package/package.json +4 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context/ItemActionsProvider.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 { createContext, ReactElement, ReactNode, useCallback, useContext, useMemo, useState } from 'react';\n\nexport interface ItemActionStatus {\n loading: boolean;\n error?: Error;\n success?: boolean;\n}\n\nexport interface ActionStatus {\n loading: boolean;\n error?: Error;\n success?: boolean;\n itemStatuses?: Map<unknown, ItemActionStatus>;\n}\n\nexport interface ActionState<Id = unknown> {\n actionStatuses: Map<string, ActionStatus>;\n setActionStatus: (actionName: string, status: Partial<ActionStatus>, itemId?: Id) => void;\n clearActionStatus: (actionName?: string) => void;\n}\n\nexport interface ItemActionsProviderProps {\n children: ReactNode;\n}\n\nconst ItemActionsContext = createContext<ActionState<unknown> | undefined>(undefined);\n\nexport function ItemActionsProvider({ children }: ItemActionsProviderProps): ReactElement {\n const [actionStatuses, setActionStatuses] = useState(new Map<string, ActionStatus>());\n\n const setActionStatus = useCallback((actionName: string, status: Partial<ActionStatus>, itemId?: unknown) => {\n setActionStatuses((prev) => {\n const newMap = new Map(prev);\n const existingStatus = newMap.get(actionName) || { loading: false };\n\n if (itemId !== undefined) {\n // Update item-level status for individual actions\n const itemStatuses = new Map(existingStatus.itemStatuses || new Map());\n const existingItemStatus = itemStatuses.get(itemId) || { loading: false };\n itemStatuses.set(itemId, { ...existingItemStatus, ...status } as ItemActionStatus);\n newMap.set(actionName, { ...existingStatus, itemStatuses });\n } else {\n // Update action-level status for batch actions\n newMap.set(actionName, { ...existingStatus, ...status });\n }\n\n return newMap;\n });\n }, []);\n\n const clearActionStatus = useCallback((actionName?: string) => {\n setActionStatuses((prev) => {\n if (actionName === undefined) {\n return new Map();\n }\n if (!prev.has(actionName)) return prev;\n const newMap = new Map(prev);\n newMap.delete(actionName);\n return newMap;\n });\n }, []);\n\n const ctx = useMemo<ActionState<unknown>>(\n () => ({\n actionStatuses,\n setActionStatus,\n clearActionStatus,\n }),\n [actionStatuses, setActionStatus, clearActionStatus]\n );\n\n return <ItemActionsContext.Provider value={ctx}>{children}</ItemActionsContext.Provider>;\n}\n\nconst noOp = (): void => {};\nconst emptyActionStatuses = new Map<string, ActionStatus>();\nconst defaultState: ActionState<unknown> & { hasContext: false } = {\n actionStatuses: emptyActionStatuses,\n setActionStatus: noOp,\n clearActionStatus: noOp,\n hasContext: false,\n};\n\nexport function useItemActions<Id = string | number>(): ActionState<Id> & { hasContext: boolean } {\n const ctx = useContext(ItemActionsContext);\n\n const memoizedResult = useMemo(() => {\n if (!ctx) return defaultState as ActionState<Id> & { hasContext: false };\n\n return { ...ctx, hasContext: true } as ActionState<Id> & { hasContext: true };\n }, [ctx]);\n\n return memoizedResult;\n}\n"],"names":["createContext","useCallback","useContext","useMemo","useState","ItemActionsContext","undefined","ItemActionsProvider","children","actionStatuses","setActionStatuses","Map","setActionStatus","actionName","status","itemId","prev","newMap","existingStatus","get","loading","itemStatuses","existingItemStatus","set","clearActionStatus","has","delete","ctx","Provider","value","noOp","emptyActionStatuses","defaultState","hasContext","useItemActions","memoizedResult"],"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
|
|
1
|
+
{"version":3,"sources":["../../src/context/ItemActionsProvider.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 { createContext, ReactElement, ReactNode, useCallback, useContext, useMemo, useState } from 'react';\n\nexport interface ItemActionStatus {\n loading: boolean;\n error?: Error;\n success?: boolean;\n}\n\nexport interface ActionStatus {\n loading: boolean;\n error?: Error;\n success?: boolean;\n itemStatuses?: Map<unknown, ItemActionStatus>;\n}\n\nexport interface ActionState<Id = unknown> {\n actionStatuses: Map<string, ActionStatus>;\n setActionStatus: (actionName: string, status: Partial<ActionStatus>, itemId?: Id) => void;\n clearActionStatus: (actionName?: string) => void;\n}\n\nexport interface ItemActionsProviderProps {\n children: ReactNode;\n}\n\nconst ItemActionsContext = createContext<ActionState<unknown> | undefined>(undefined);\n\nexport function ItemActionsProvider({ children }: ItemActionsProviderProps): ReactElement {\n const [actionStatuses, setActionStatuses] = useState(new Map<string, ActionStatus>());\n\n const setActionStatus = useCallback((actionName: string, status: Partial<ActionStatus>, itemId?: unknown) => {\n setActionStatuses((prev) => {\n const newMap = new Map(prev);\n const existingStatus = newMap.get(actionName) || { loading: false };\n\n if (itemId !== undefined) {\n // Update item-level status for individual actions\n const itemStatuses = new Map(existingStatus.itemStatuses || new Map());\n const existingItemStatus = itemStatuses.get(itemId) || { loading: false };\n itemStatuses.set(itemId, { ...existingItemStatus, ...status } as ItemActionStatus);\n newMap.set(actionName, { ...existingStatus, itemStatuses });\n } else {\n // Update action-level status for batch actions\n newMap.set(actionName, { ...existingStatus, ...status });\n }\n\n return newMap;\n });\n }, []);\n\n const clearActionStatus = useCallback((actionName?: string) => {\n setActionStatuses((prev) => {\n if (actionName === undefined) {\n return new Map();\n }\n if (!prev.has(actionName)) return prev;\n const newMap = new Map(prev);\n newMap.delete(actionName);\n return newMap;\n });\n }, []);\n\n const ctx = useMemo<ActionState<unknown>>(\n () => ({\n actionStatuses,\n setActionStatus,\n clearActionStatus,\n }),\n [actionStatuses, setActionStatus, clearActionStatus]\n );\n\n return <ItemActionsContext.Provider value={ctx}>{children}</ItemActionsContext.Provider>;\n}\n\nconst noOp = (): void => {};\nconst emptyActionStatuses = new Map<string, ActionStatus>();\nconst defaultState: ActionState<unknown> & { hasContext: false } = {\n actionStatuses: emptyActionStatuses,\n setActionStatus: noOp,\n clearActionStatus: noOp,\n hasContext: false,\n};\n\nexport function useItemActions<Id = string | number>(): ActionState<Id> & { hasContext: boolean } {\n const ctx = useContext(ItemActionsContext);\n\n const memoizedResult = useMemo(() => {\n if (!ctx) return defaultState as ActionState<Id> & { hasContext: false };\n\n return { ...ctx, hasContext: true } as ActionState<Id> & { hasContext: true };\n }, [ctx]);\n\n return memoizedResult;\n}\n"],"names":["createContext","useCallback","useContext","useMemo","useState","ItemActionsContext","undefined","ItemActionsProvider","children","actionStatuses","setActionStatuses","Map","setActionStatus","actionName","status","itemId","prev","newMap","existingStatus","get","loading","itemStatuses","existingItemStatus","set","clearActionStatus","has","delete","ctx","Provider","value","noOp","emptyActionStatuses","defaultState","hasContext","useItemActions","memoizedResult"],"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,aAAa,EAA2BC,WAAW,EAAEC,UAAU,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAyB3G,MAAMC,mCAAqBL,cAAgDM;AAE3E,OAAO,SAASC,oBAAoB,EAAEC,QAAQ,EAA4B;IACxE,MAAM,CAACC,gBAAgBC,kBAAkB,GAAGN,SAAS,IAAIO;IAEzD,MAAMC,kBAAkBX,YAAY,CAACY,YAAoBC,QAA+BC;QACtFL,kBAAkB,CAACM;YACjB,MAAMC,SAAS,IAAIN,IAAIK;YACvB,MAAME,iBAAiBD,OAAOE,GAAG,CAACN,eAAe;gBAAEO,SAAS;YAAM;YAElE,IAAIL,WAAWT,WAAW;gBACxB,kDAAkD;gBAClD,MAAMe,eAAe,IAAIV,IAAIO,eAAeG,YAAY,IAAI,IAAIV;gBAChE,MAAMW,qBAAqBD,aAAaF,GAAG,CAACJ,WAAW;oBAAEK,SAAS;gBAAM;gBACxEC,aAAaE,GAAG,CAACR,QAAQ;oBAAE,GAAGO,kBAAkB;oBAAE,GAAGR,MAAM;gBAAC;gBAC5DG,OAAOM,GAAG,CAACV,YAAY;oBAAE,GAAGK,cAAc;oBAAEG;gBAAa;YAC3D,OAAO;gBACL,+CAA+C;gBAC/CJ,OAAOM,GAAG,CAACV,YAAY;oBAAE,GAAGK,cAAc;oBAAE,GAAGJ,MAAM;gBAAC;YACxD;YAEA,OAAOG;QACT;IACF,GAAG,EAAE;IAEL,MAAMO,oBAAoBvB,YAAY,CAACY;QACrCH,kBAAkB,CAACM;YACjB,IAAIH,eAAeP,WAAW;gBAC5B,OAAO,IAAIK;YACb;YACA,IAAI,CAACK,KAAKS,GAAG,CAACZ,aAAa,OAAOG;YAClC,MAAMC,SAAS,IAAIN,IAAIK;YACvBC,OAAOS,MAAM,CAACb;YACd,OAAOI;QACT;IACF,GAAG,EAAE;IAEL,MAAMU,MAAMxB,QACV,IAAO,CAAA;YACLM;YACAG;YACAY;QACF,CAAA,GACA;QAACf;QAAgBG;QAAiBY;KAAkB;IAGtD,qBAAO,KAACnB,mBAAmBuB,QAAQ;QAACC,OAAOF;kBAAMnB;;AACnD;AAEA,MAAMsB,OAAO,KAAa;AAC1B,MAAMC,sBAAsB,IAAIpB;AAChC,MAAMqB,eAA6D;IACjEvB,gBAAgBsB;IAChBnB,iBAAiBkB;IACjBN,mBAAmBM;IACnBG,YAAY;AACd;AAEA,OAAO,SAASC;IACd,MAAMP,MAAMzB,WAAWG;IAEvB,MAAM8B,iBAAiBhC,QAAQ;QAC7B,IAAI,CAACwB,KAAK,OAAOK;QAEjB,OAAO;YAAE,GAAGL,GAAG;YAAEM,YAAY;QAAK;IACpC,GAAG;QAACN;KAAI;IAER,OAAOQ;AACT"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
2
|
// Copyright The Perses Authors
|
|
2
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -10,7 +11,6 @@
|
|
|
10
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
12
|
// See the License for the specific language governing permissions and
|
|
12
13
|
// limitations under the License.
|
|
13
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
15
15
|
const SelectionContext = /*#__PURE__*/ createContext(undefined);
|
|
16
16
|
const defaultGetId = (_item, index)=>index;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context/SelectionProvider.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 {\n createContext,\n ReactElement,\n ReactNode,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nexport type GetIdFn<T, Id> = (item: T, index: number) => Id;\n\nexport interface SelectionState<T, Id = unknown> {\n selectionMap: Map<Id, T>;\n setSelection: (items: Array<{ id: Id; item: T }>) => void;\n toggleSelection: (item: T, id: Id) => void;\n removeFromSelection: (id: Id) => void;\n clearSelection: () => void;\n isSelected: (item: T, index: number) => boolean;\n}\n\nexport interface SelectionProviderProps {\n children: ReactNode;\n}\n\nexport interface UseSelectionOptions<T, Id = string | number> {\n getId?: GetIdFn<T, Id>;\n}\n\ninterface InternalState<T, Id> extends SelectionState<T, Id> {\n registerGetId: (fn: GetIdFn<T, Id>) => void;\n}\n\nconst SelectionContext = createContext<InternalState<unknown, unknown> | undefined>(undefined);\n\nconst defaultGetId = (_item: unknown, index: number): unknown => index;\n\n/**\n * Provides selection state to descendant components.\n */\nexport function SelectionProvider({ children }: SelectionProviderProps): ReactElement {\n const [selectionMap, setSelectionMap] = useState(new Map<unknown, unknown>());\n const getIdRef = useRef<GetIdFn<unknown, unknown>>(defaultGetId);\n\n // Allows consumers to register their own getId function. by default we use the index.\n const registerGetId = useCallback((fn: GetIdFn<unknown, unknown>) => {\n getIdRef.current = fn;\n }, []);\n\n const setSelection = useCallback((items: Array<{ id: unknown; item: unknown }>) => {\n const newMap = new Map<unknown, unknown>();\n items.forEach(({ item, id }) => newMap.set(id, item));\n setSelectionMap(newMap);\n }, []);\n\n const toggleSelection = useCallback((item: unknown, id: unknown) => {\n setSelectionMap((prev) => {\n const newMap = new Map(prev);\n if (newMap.has(id)) {\n newMap.delete(id);\n } else {\n newMap.set(id, item);\n }\n return newMap;\n });\n }, []);\n\n const removeFromSelection = useCallback((id: unknown) => {\n setSelectionMap((prev) => {\n if (!prev.has(id)) return prev;\n const newMap = new Map(prev);\n newMap.delete(id);\n return newMap;\n });\n }, []);\n\n const clearSelection = useCallback(() => setSelectionMap(new Map()), []);\n\n const isSelected = useCallback(\n (item: unknown, index: number) => selectionMap.has(getIdRef.current(item, index)),\n [selectionMap]\n );\n\n const ctx = useMemo<InternalState<unknown, unknown>>(\n () => ({\n selectionMap,\n setSelection,\n toggleSelection,\n removeFromSelection,\n clearSelection,\n isSelected,\n registerGetId,\n }),\n [selectionMap, setSelection, toggleSelection, removeFromSelection, clearSelection, isSelected, registerGetId]\n );\n\n return <SelectionContext.Provider value={ctx}>{children}</SelectionContext.Provider>;\n}\n\n/**\n * No-op functions and empty map for when there is no context available.\n * This allows components to use the hook without crashing given the optional nature of the provider.\n */\nconst noOp = (): void => {};\nconst noOpIsSelected = (): boolean => false;\nconst emptyMap = new Map<unknown, unknown>();\nconst defaultState: SelectionState<unknown, unknown> & { hasContext: false } = {\n selectionMap: emptyMap,\n setSelection: noOp,\n toggleSelection: noOp,\n removeFromSelection: noOp,\n clearSelection: noOp,\n isSelected: noOpIsSelected,\n hasContext: false,\n};\n\n/**\n * Hook to access selection state from context.\n * If used outside of a SelectionProvider, returns no-op functions and an empty selection map.\n *\n * @param options Optional configuration for the selection hook.\n * @param options.getId Function to get the unique identifier for an item, this allows the selection state to identify items.\n */\nexport function useSelection<T, Id = string | number>(\n options?: UseSelectionOptions<T, Id>\n): SelectionState<T, Id> & { hasContext: boolean } {\n const ctx = useContext(SelectionContext);\n\n useEffect(() => {\n if (ctx && options?.getId) {\n ctx.registerGetId(options.getId as GetIdFn<unknown, unknown>);\n }\n }, [ctx, options?.getId]);\n\n const memoizedResult = useMemo(() => {\n if (!ctx) return defaultState as SelectionState<T, Id> & { hasContext: false };\n\n const { registerGetId: _, ...rest } = ctx;\n return { ...rest, hasContext: true } as SelectionState<T, Id> & { hasContext: true };\n }, [ctx]);\n\n return memoizedResult;\n}\n"],"names":["createContext","useCallback","useContext","useEffect","useMemo","useRef","useState","SelectionContext","undefined","defaultGetId","_item","index","SelectionProvider","children","selectionMap","setSelectionMap","Map","getIdRef","registerGetId","fn","current","setSelection","items","newMap","forEach","item","id","set","toggleSelection","prev","has","delete","removeFromSelection","clearSelection","isSelected","ctx","Provider","value","noOp","noOpIsSelected","emptyMap","defaultState","hasContext","useSelection","options","getId","memoizedResult","_","rest"],"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
|
|
1
|
+
{"version":3,"sources":["../../src/context/SelectionProvider.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 {\n createContext,\n ReactElement,\n ReactNode,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nexport type GetIdFn<T, Id> = (item: T, index: number) => Id;\n\nexport interface SelectionState<T, Id = unknown> {\n selectionMap: Map<Id, T>;\n setSelection: (items: Array<{ id: Id; item: T }>) => void;\n toggleSelection: (item: T, id: Id) => void;\n removeFromSelection: (id: Id) => void;\n clearSelection: () => void;\n isSelected: (item: T, index: number) => boolean;\n}\n\nexport interface SelectionProviderProps {\n children: ReactNode;\n}\n\nexport interface UseSelectionOptions<T, Id = string | number> {\n getId?: GetIdFn<T, Id>;\n}\n\ninterface InternalState<T, Id> extends SelectionState<T, Id> {\n registerGetId: (fn: GetIdFn<T, Id>) => void;\n}\n\nconst SelectionContext = createContext<InternalState<unknown, unknown> | undefined>(undefined);\n\nconst defaultGetId = (_item: unknown, index: number): unknown => index;\n\n/**\n * Provides selection state to descendant components.\n */\nexport function SelectionProvider({ children }: SelectionProviderProps): ReactElement {\n const [selectionMap, setSelectionMap] = useState(new Map<unknown, unknown>());\n const getIdRef = useRef<GetIdFn<unknown, unknown>>(defaultGetId);\n\n // Allows consumers to register their own getId function. by default we use the index.\n const registerGetId = useCallback((fn: GetIdFn<unknown, unknown>) => {\n getIdRef.current = fn;\n }, []);\n\n const setSelection = useCallback((items: Array<{ id: unknown; item: unknown }>) => {\n const newMap = new Map<unknown, unknown>();\n items.forEach(({ item, id }) => newMap.set(id, item));\n setSelectionMap(newMap);\n }, []);\n\n const toggleSelection = useCallback((item: unknown, id: unknown) => {\n setSelectionMap((prev) => {\n const newMap = new Map(prev);\n if (newMap.has(id)) {\n newMap.delete(id);\n } else {\n newMap.set(id, item);\n }\n return newMap;\n });\n }, []);\n\n const removeFromSelection = useCallback((id: unknown) => {\n setSelectionMap((prev) => {\n if (!prev.has(id)) return prev;\n const newMap = new Map(prev);\n newMap.delete(id);\n return newMap;\n });\n }, []);\n\n const clearSelection = useCallback(() => setSelectionMap(new Map()), []);\n\n const isSelected = useCallback(\n (item: unknown, index: number) => selectionMap.has(getIdRef.current(item, index)),\n [selectionMap]\n );\n\n const ctx = useMemo<InternalState<unknown, unknown>>(\n () => ({\n selectionMap,\n setSelection,\n toggleSelection,\n removeFromSelection,\n clearSelection,\n isSelected,\n registerGetId,\n }),\n [selectionMap, setSelection, toggleSelection, removeFromSelection, clearSelection, isSelected, registerGetId]\n );\n\n return <SelectionContext.Provider value={ctx}>{children}</SelectionContext.Provider>;\n}\n\n/**\n * No-op functions and empty map for when there is no context available.\n * This allows components to use the hook without crashing given the optional nature of the provider.\n */\nconst noOp = (): void => {};\nconst noOpIsSelected = (): boolean => false;\nconst emptyMap = new Map<unknown, unknown>();\nconst defaultState: SelectionState<unknown, unknown> & { hasContext: false } = {\n selectionMap: emptyMap,\n setSelection: noOp,\n toggleSelection: noOp,\n removeFromSelection: noOp,\n clearSelection: noOp,\n isSelected: noOpIsSelected,\n hasContext: false,\n};\n\n/**\n * Hook to access selection state from context.\n * If used outside of a SelectionProvider, returns no-op functions and an empty selection map.\n *\n * @param options Optional configuration for the selection hook.\n * @param options.getId Function to get the unique identifier for an item, this allows the selection state to identify items.\n */\nexport function useSelection<T, Id = string | number>(\n options?: UseSelectionOptions<T, Id>\n): SelectionState<T, Id> & { hasContext: boolean } {\n const ctx = useContext(SelectionContext);\n\n useEffect(() => {\n if (ctx && options?.getId) {\n ctx.registerGetId(options.getId as GetIdFn<unknown, unknown>);\n }\n }, [ctx, options?.getId]);\n\n const memoizedResult = useMemo(() => {\n if (!ctx) return defaultState as SelectionState<T, Id> & { hasContext: false };\n\n const { registerGetId: _, ...rest } = ctx;\n return { ...rest, hasContext: true } as SelectionState<T, Id> & { hasContext: true };\n }, [ctx]);\n\n return memoizedResult;\n}\n"],"names":["createContext","useCallback","useContext","useEffect","useMemo","useRef","useState","SelectionContext","undefined","defaultGetId","_item","index","SelectionProvider","children","selectionMap","setSelectionMap","Map","getIdRef","registerGetId","fn","current","setSelection","items","newMap","forEach","item","id","set","toggleSelection","prev","has","delete","removeFromSelection","clearSelection","isSelected","ctx","Provider","value","noOp","noOpIsSelected","emptyMap","defaultState","hasContext","useSelection","options","getId","memoizedResult","_","rest"],"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,SACEA,aAAa,EAGbC,WAAW,EACXC,UAAU,EACVC,SAAS,EACTC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACH,QAAQ;AAyBf,MAAMC,iCAAmBP,cAA2DQ;AAEpF,MAAMC,eAAe,CAACC,OAAgBC,QAA2BA;AAEjE;;CAEC,GACD,OAAO,SAASC,kBAAkB,EAAEC,QAAQ,EAA0B;IACpE,MAAM,CAACC,cAAcC,gBAAgB,GAAGT,SAAS,IAAIU;IACrD,MAAMC,WAAWZ,OAAkCI;IAEnD,sFAAsF;IACtF,MAAMS,gBAAgBjB,YAAY,CAACkB;QACjCF,SAASG,OAAO,GAAGD;IACrB,GAAG,EAAE;IAEL,MAAME,eAAepB,YAAY,CAACqB;QAChC,MAAMC,SAAS,IAAIP;QACnBM,MAAME,OAAO,CAAC,CAAC,EAAEC,IAAI,EAAEC,EAAE,EAAE,GAAKH,OAAOI,GAAG,CAACD,IAAID;QAC/CV,gBAAgBQ;IAClB,GAAG,EAAE;IAEL,MAAMK,kBAAkB3B,YAAY,CAACwB,MAAeC;QAClDX,gBAAgB,CAACc;YACf,MAAMN,SAAS,IAAIP,IAAIa;YACvB,IAAIN,OAAOO,GAAG,CAACJ,KAAK;gBAClBH,OAAOQ,MAAM,CAACL;YAChB,OAAO;gBACLH,OAAOI,GAAG,CAACD,IAAID;YACjB;YACA,OAAOF;QACT;IACF,GAAG,EAAE;IAEL,MAAMS,sBAAsB/B,YAAY,CAACyB;QACvCX,gBAAgB,CAACc;YACf,IAAI,CAACA,KAAKC,GAAG,CAACJ,KAAK,OAAOG;YAC1B,MAAMN,SAAS,IAAIP,IAAIa;YACvBN,OAAOQ,MAAM,CAACL;YACd,OAAOH;QACT;IACF,GAAG,EAAE;IAEL,MAAMU,iBAAiBhC,YAAY,IAAMc,gBAAgB,IAAIC,QAAQ,EAAE;IAEvE,MAAMkB,aAAajC,YACjB,CAACwB,MAAed,QAAkBG,aAAagB,GAAG,CAACb,SAASG,OAAO,CAACK,MAAMd,SAC1E;QAACG;KAAa;IAGhB,MAAMqB,MAAM/B,QACV,IAAO,CAAA;YACLU;YACAO;YACAO;YACAI;YACAC;YACAC;YACAhB;QACF,CAAA,GACA;QAACJ;QAAcO;QAAcO;QAAiBI;QAAqBC;QAAgBC;QAAYhB;KAAc;IAG/G,qBAAO,KAACX,iBAAiB6B,QAAQ;QAACC,OAAOF;kBAAMtB;;AACjD;AAEA;;;CAGC,GACD,MAAMyB,OAAO,KAAa;AAC1B,MAAMC,iBAAiB,IAAe;AACtC,MAAMC,WAAW,IAAIxB;AACrB,MAAMyB,eAAyE;IAC7E3B,cAAc0B;IACdnB,cAAciB;IACdV,iBAAiBU;IACjBN,qBAAqBM;IACrBL,gBAAgBK;IAChBJ,YAAYK;IACZG,YAAY;AACd;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,aACdC,OAAoC;IAEpC,MAAMT,MAAMjC,WAAWK;IAEvBJ,UAAU;QACR,IAAIgC,OAAOS,SAASC,OAAO;YACzBV,IAAIjB,aAAa,CAAC0B,QAAQC,KAAK;QACjC;IACF,GAAG;QAACV;QAAKS,SAASC;KAAM;IAExB,MAAMC,iBAAiB1C,QAAQ;QAC7B,IAAI,CAAC+B,KAAK,OAAOM;QAEjB,MAAM,EAAEvB,eAAe6B,CAAC,EAAE,GAAGC,MAAM,GAAGb;QACtC,OAAO;YAAE,GAAGa,IAAI;YAAEN,YAAY;QAAK;IACrC,GAAG;QAACP;KAAI;IAER,OAAOW;AACT"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
2
|
// Copyright The Perses Authors
|
|
2
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -10,7 +11,6 @@
|
|
|
10
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
12
|
// See the License for the specific language governing permissions and
|
|
12
13
|
// limitations under the License.
|
|
13
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
import React, { useCallback } from 'react';
|
|
15
15
|
import { styled } from '@mui/material/styles';
|
|
16
16
|
import { SnackbarProvider as NotistackProvider, useSnackbar as useNotistack, MaterialDesignContent } from 'notistack';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context/SnackbarProvider.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 React, { useCallback } from 'react';\nimport { styled } from '@mui/material/styles';\nimport {\n SnackbarProvider as NotistackProvider,\n ProviderContext as NotistackContext,\n useSnackbar as useNotistack,\n SnackbarMessage,\n OptionsObject,\n SnackbarKey,\n MaterialDesignContent,\n} from 'notistack';\n\nexport interface SnackbarContext extends NotistackContext {\n errorSnackbar: EnqueueFunction;\n infoSnackbar: EnqueueFunction;\n warningSnackbar: EnqueueFunction;\n successSnackbar: EnqueueFunction;\n\n /**\n * Useful for catch blocks where the error will be of type `unknown`, tries\n * to show the `message` property if passed an instance of `Error`.\n */\n exceptionSnackbar: (error: unknown, options?: SnackbarOptions) => SnackbarKey;\n}\n\ntype EnqueueFunction = (message: SnackbarMessage, options?: SnackbarOptions) => SnackbarKey;\n\ntype SnackbarOptions = Omit<OptionsObject, 'variant'>;\n\n/**\n * Application-wide provider for showing snackbars/toasts.\n * Customized to preserve formatting in error messages.\n */\nexport function SnackbarProvider({\n children,\n ...props\n}: React.ComponentProps<typeof NotistackProvider>): React.ReactElement {\n return (\n <NotistackProvider\n {...props}\n Components={{\n error: styled(MaterialDesignContent)(() => ({\n '&.notistack-MuiContent-error': {\n whiteSpace: 'pre-wrap',\n },\n })),\n }}\n >\n {children}\n </NotistackProvider>\n );\n}\n\n/**\n * Gets the SnackbarContext with methods for displaying snackbars/toasts.\n */\nexport function useSnackbar(): SnackbarContext {\n const { enqueueSnackbar, closeSnackbar } = useNotistack();\n\n // Create variant-specific callbacks\n const errorSnackbar = useEnqueueFunction(enqueueSnackbar, 'error');\n const infoSnackbar = useEnqueueFunction(enqueueSnackbar, 'info');\n const warningSnackbar = useEnqueueFunction(enqueueSnackbar, 'warning');\n const successSnackbar = useEnqueueFunction(enqueueSnackbar, 'success');\n\n const exceptionSnackbar: SnackbarContext['exceptionSnackbar'] = useCallback(\n (error, options) => {\n // Try to use message prop, but fallback to a default message that\n // will just stringify the error provided\n const message = error instanceof Error ? error.message : `An unexpected error occurred: ${error}`;\n\n return errorSnackbar(message, options);\n },\n [errorSnackbar]\n );\n\n return {\n enqueueSnackbar,\n closeSnackbar,\n errorSnackbar,\n infoSnackbar,\n warningSnackbar,\n successSnackbar,\n exceptionSnackbar,\n };\n}\n\n// Helper to create a variant-specific enqueue function\nfunction useEnqueueFunction(\n enqueueSnackbar: NotistackContext['enqueueSnackbar'],\n variant: OptionsObject['variant']\n): EnqueueFunction {\n return useCallback(\n (message, options) => {\n const allOptions: OptionsObject = {\n ...options,\n variant,\n };\n return enqueueSnackbar(message, allOptions);\n },\n [enqueueSnackbar, variant]\n );\n}\n"],"names":["React","useCallback","styled","SnackbarProvider","NotistackProvider","useSnackbar","useNotistack","MaterialDesignContent","children","props","Components","error","whiteSpace","enqueueSnackbar","closeSnackbar","errorSnackbar","useEnqueueFunction","infoSnackbar","warningSnackbar","successSnackbar","exceptionSnackbar","options","message","Error","variant","allOptions"],"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
|
|
1
|
+
{"version":3,"sources":["../../src/context/SnackbarProvider.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 React, { useCallback } from 'react';\nimport { styled } from '@mui/material/styles';\nimport {\n SnackbarProvider as NotistackProvider,\n ProviderContext as NotistackContext,\n useSnackbar as useNotistack,\n SnackbarMessage,\n OptionsObject,\n SnackbarKey,\n MaterialDesignContent,\n} from 'notistack';\n\nexport interface SnackbarContext extends NotistackContext {\n errorSnackbar: EnqueueFunction;\n infoSnackbar: EnqueueFunction;\n warningSnackbar: EnqueueFunction;\n successSnackbar: EnqueueFunction;\n\n /**\n * Useful for catch blocks where the error will be of type `unknown`, tries\n * to show the `message` property if passed an instance of `Error`.\n */\n exceptionSnackbar: (error: unknown, options?: SnackbarOptions) => SnackbarKey;\n}\n\ntype EnqueueFunction = (message: SnackbarMessage, options?: SnackbarOptions) => SnackbarKey;\n\ntype SnackbarOptions = Omit<OptionsObject, 'variant'>;\n\n/**\n * Application-wide provider for showing snackbars/toasts.\n * Customized to preserve formatting in error messages.\n */\nexport function SnackbarProvider({\n children,\n ...props\n}: React.ComponentProps<typeof NotistackProvider>): React.ReactElement {\n return (\n <NotistackProvider\n {...props}\n Components={{\n error: styled(MaterialDesignContent)(() => ({\n '&.notistack-MuiContent-error': {\n whiteSpace: 'pre-wrap',\n },\n })),\n }}\n >\n {children}\n </NotistackProvider>\n );\n}\n\n/**\n * Gets the SnackbarContext with methods for displaying snackbars/toasts.\n */\nexport function useSnackbar(): SnackbarContext {\n const { enqueueSnackbar, closeSnackbar } = useNotistack();\n\n // Create variant-specific callbacks\n const errorSnackbar = useEnqueueFunction(enqueueSnackbar, 'error');\n const infoSnackbar = useEnqueueFunction(enqueueSnackbar, 'info');\n const warningSnackbar = useEnqueueFunction(enqueueSnackbar, 'warning');\n const successSnackbar = useEnqueueFunction(enqueueSnackbar, 'success');\n\n const exceptionSnackbar: SnackbarContext['exceptionSnackbar'] = useCallback(\n (error, options) => {\n // Try to use message prop, but fallback to a default message that\n // will just stringify the error provided\n const message = error instanceof Error ? error.message : `An unexpected error occurred: ${error}`;\n\n return errorSnackbar(message, options);\n },\n [errorSnackbar]\n );\n\n return {\n enqueueSnackbar,\n closeSnackbar,\n errorSnackbar,\n infoSnackbar,\n warningSnackbar,\n successSnackbar,\n exceptionSnackbar,\n };\n}\n\n// Helper to create a variant-specific enqueue function\nfunction useEnqueueFunction(\n enqueueSnackbar: NotistackContext['enqueueSnackbar'],\n variant: OptionsObject['variant']\n): EnqueueFunction {\n return useCallback(\n (message, options) => {\n const allOptions: OptionsObject = {\n ...options,\n variant,\n };\n return enqueueSnackbar(message, allOptions);\n },\n [enqueueSnackbar, variant]\n );\n}\n"],"names":["React","useCallback","styled","SnackbarProvider","NotistackProvider","useSnackbar","useNotistack","MaterialDesignContent","children","props","Components","error","whiteSpace","enqueueSnackbar","closeSnackbar","errorSnackbar","useEnqueueFunction","infoSnackbar","warningSnackbar","successSnackbar","exceptionSnackbar","options","message","Error","variant","allOptions"],"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,OAAOA,SAASC,WAAW,QAAQ,QAAQ;AAC3C,SAASC,MAAM,QAAQ,uBAAuB;AAC9C,SACEC,oBAAoBC,iBAAiB,EAErCC,eAAeC,YAAY,EAI3BC,qBAAqB,QAChB,YAAY;AAmBnB;;;CAGC,GACD,OAAO,SAASJ,iBAAiB,EAC/BK,QAAQ,EACR,GAAGC,OAC4C;IAC/C,qBACE,KAACL;QACE,GAAGK,KAAK;QACTC,YAAY;YACVC,OAAOT,OAAOK,uBAAuB,IAAO,CAAA;oBAC1C,gCAAgC;wBAC9BK,YAAY;oBACd;gBACF,CAAA;QACF;kBAECJ;;AAGP;AAEA;;CAEC,GACD,OAAO,SAASH;IACd,MAAM,EAAEQ,eAAe,EAAEC,aAAa,EAAE,GAAGR;IAE3C,oCAAoC;IACpC,MAAMS,gBAAgBC,mBAAmBH,iBAAiB;IAC1D,MAAMI,eAAeD,mBAAmBH,iBAAiB;IACzD,MAAMK,kBAAkBF,mBAAmBH,iBAAiB;IAC5D,MAAMM,kBAAkBH,mBAAmBH,iBAAiB;IAE5D,MAAMO,oBAA0DnB,YAC9D,CAACU,OAAOU;QACN,kEAAkE;QAClE,yCAAyC;QACzC,MAAMC,UAAUX,iBAAiBY,QAAQZ,MAAMW,OAAO,GAAG,CAAC,8BAA8B,EAAEX,OAAO;QAEjG,OAAOI,cAAcO,SAASD;IAChC,GACA;QAACN;KAAc;IAGjB,OAAO;QACLF;QACAC;QACAC;QACAE;QACAC;QACAC;QACAC;IACF;AACF;AAEA,uDAAuD;AACvD,SAASJ,mBACPH,eAAoD,EACpDW,OAAiC;IAEjC,OAAOvB,YACL,CAACqB,SAASD;QACR,MAAMI,aAA4B;YAChC,GAAGJ,OAAO;YACVG;QACF;QACA,OAAOX,gBAAgBS,SAASG;IAClC,GACA;QAACZ;QAAiBW;KAAQ;AAE9B"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
2
|
// Copyright The Perses Authors
|
|
2
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -10,7 +11,6 @@
|
|
|
10
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
12
|
// See the License for the specific language governing permissions and
|
|
12
13
|
// limitations under the License.
|
|
13
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
import React, { createContext, useContext } from 'react';
|
|
15
15
|
import { formatWithTimeZone, dateFormatOptionsWithTimeZone } from '../utils';
|
|
16
16
|
export const TimeZoneContext = /*#__PURE__*/ createContext(undefined);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context/TimeZoneProvider.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 React, { createContext, ReactElement, useContext } from 'react';\nimport { formatWithTimeZone, dateFormatOptionsWithTimeZone } from '../utils';\n\nexport const TimeZoneContext = createContext<string | undefined>(undefined);\n\nexport interface TimeZoneProviderProps {\n timeZone?: string;\n children?: React.ReactNode;\n}\n\nexport function TimeZoneProvider(props: TimeZoneProviderProps): ReactElement {\n const { children, timeZone } = props;\n return <TimeZoneContext.Provider value={timeZone}>{children}</TimeZoneContext.Provider>;\n}\n\nexport function useTimeZone(): {\n timeZone: string;\n formatWithUserTimeZone: (date: Date, formatString: string) => string;\n dateFormatOptionsWithUserTimeZone: (dateFormatOptions: Intl.DateTimeFormatOptions) => Intl.DateTimeFormatOptions;\n} {\n const timeZone = useContext(TimeZoneContext);\n return {\n // fallback to \"local\" timezone if TimeZoneProvider is not present in the React tree\n timeZone: timeZone ?? 'local',\n formatWithUserTimeZone(date: Date, formatString: string): string {\n return formatWithTimeZone(date, formatString, timeZone);\n },\n dateFormatOptionsWithUserTimeZone(dateFormatOptions: Intl.DateTimeFormatOptions): Intl.DateTimeFormatOptions {\n return dateFormatOptionsWithTimeZone(dateFormatOptions, timeZone);\n },\n };\n}\n"],"names":["React","createContext","useContext","formatWithTimeZone","dateFormatOptionsWithTimeZone","TimeZoneContext","undefined","TimeZoneProvider","props","children","timeZone","Provider","value","useTimeZone","formatWithUserTimeZone","date","formatString","dateFormatOptionsWithUserTimeZone","dateFormatOptions"],"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
|
|
1
|
+
{"version":3,"sources":["../../src/context/TimeZoneProvider.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 React, { createContext, ReactElement, useContext } from 'react';\nimport { formatWithTimeZone, dateFormatOptionsWithTimeZone } from '../utils';\n\nexport const TimeZoneContext = createContext<string | undefined>(undefined);\n\nexport interface TimeZoneProviderProps {\n timeZone?: string;\n children?: React.ReactNode;\n}\n\nexport function TimeZoneProvider(props: TimeZoneProviderProps): ReactElement {\n const { children, timeZone } = props;\n return <TimeZoneContext.Provider value={timeZone}>{children}</TimeZoneContext.Provider>;\n}\n\nexport function useTimeZone(): {\n timeZone: string;\n formatWithUserTimeZone: (date: Date, formatString: string) => string;\n dateFormatOptionsWithUserTimeZone: (dateFormatOptions: Intl.DateTimeFormatOptions) => Intl.DateTimeFormatOptions;\n} {\n const timeZone = useContext(TimeZoneContext);\n return {\n // fallback to \"local\" timezone if TimeZoneProvider is not present in the React tree\n timeZone: timeZone ?? 'local',\n formatWithUserTimeZone(date: Date, formatString: string): string {\n return formatWithTimeZone(date, formatString, timeZone);\n },\n dateFormatOptionsWithUserTimeZone(dateFormatOptions: Intl.DateTimeFormatOptions): Intl.DateTimeFormatOptions {\n return dateFormatOptionsWithTimeZone(dateFormatOptions, timeZone);\n },\n };\n}\n"],"names":["React","createContext","useContext","formatWithTimeZone","dateFormatOptionsWithTimeZone","TimeZoneContext","undefined","TimeZoneProvider","props","children","timeZone","Provider","value","useTimeZone","formatWithUserTimeZone","date","formatString","dateFormatOptionsWithUserTimeZone","dateFormatOptions"],"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,OAAOA,SAASC,aAAa,EAAgBC,UAAU,QAAQ,QAAQ;AACvE,SAASC,kBAAkB,EAAEC,6BAA6B,QAAQ,WAAW;AAE7E,OAAO,MAAMC,gCAAkBJ,cAAkCK,WAAW;AAO5E,OAAO,SAASC,iBAAiBC,KAA4B;IAC3D,MAAM,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,GAAGF;IAC/B,qBAAO,KAACH,gBAAgBM,QAAQ;QAACC,OAAOF;kBAAWD;;AACrD;AAEA,OAAO,SAASI;IAKd,MAAMH,WAAWR,WAAWG;IAC5B,OAAO;QACL,oFAAoF;QACpFK,UAAUA,YAAY;QACtBI,wBAAuBC,IAAU,EAAEC,YAAoB;YACrD,OAAOb,mBAAmBY,MAAMC,cAAcN;QAChD;QACAO,mCAAkCC,iBAA6C;YAC7E,OAAOd,8BAA8Bc,mBAAmBR;QAC1D;IACF;AACF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
2
|
// Copyright The Perses Authors
|
|
2
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -10,7 +11,6 @@
|
|
|
10
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
12
|
// See the License for the specific language governing permissions and
|
|
12
13
|
// limitations under the License.
|
|
13
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
import { TextField as MuiTextField } from '@mui/material';
|
|
15
15
|
import { forwardRef, useCallback, useMemo, useState } from 'react';
|
|
16
16
|
import debounce from 'lodash/debounce';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/controls/TextField.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 { TextFieldProps as MuiTextFieldProps, TextField as MuiTextField } from '@mui/material';\nimport { ChangeEvent, ForwardedRef, forwardRef, useCallback, useMemo, useState } from 'react';\nimport debounce from 'lodash/debounce';\n\ntype TextFieldProps = Omit<MuiTextFieldProps, 'onChange'> & { debounceMs?: number; onChange?: (value: string) => void };\n\nexport const TextField = forwardRef(function (\n { debounceMs = 250, value, onChange, ...props }: TextFieldProps,\n ref: ForwardedRef<HTMLDivElement>\n) {\n const [currentValue, setCurrentValue] = useState(value);\n\n function handleChange(event: ChangeEvent<HTMLInputElement>): void {\n setCurrentValue(event.target.value);\n debounceFn(event.target.value);\n }\n\n const handleDebounceFn = useCallback(\n (inputValue: string) => {\n onChange?.(inputValue);\n },\n [onChange]\n );\n\n const debounceFn = useMemo(() => debounce(handleDebounceFn, debounceMs), [debounceMs, handleDebounceFn]);\n\n return <MuiTextField ref={ref} value={currentValue} onChange={handleChange} {...props} />;\n});\nTextField.displayName = 'TextField';\n"],"names":["TextField","MuiTextField","forwardRef","useCallback","useMemo","useState","debounce","debounceMs","value","onChange","props","ref","currentValue","setCurrentValue","handleChange","event","target","debounceFn","handleDebounceFn","inputValue","displayName"],"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
|
|
1
|
+
{"version":3,"sources":["../../src/controls/TextField.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 { TextFieldProps as MuiTextFieldProps, TextField as MuiTextField } from '@mui/material';\nimport { ChangeEvent, ForwardedRef, forwardRef, useCallback, useMemo, useState } from 'react';\nimport debounce from 'lodash/debounce';\n\ntype TextFieldProps = Omit<MuiTextFieldProps, 'onChange'> & { debounceMs?: number; onChange?: (value: string) => void };\n\nexport const TextField = forwardRef(function (\n { debounceMs = 250, value, onChange, ...props }: TextFieldProps,\n ref: ForwardedRef<HTMLDivElement>\n) {\n const [currentValue, setCurrentValue] = useState(value);\n\n function handleChange(event: ChangeEvent<HTMLInputElement>): void {\n setCurrentValue(event.target.value);\n debounceFn(event.target.value);\n }\n\n const handleDebounceFn = useCallback(\n (inputValue: string) => {\n onChange?.(inputValue);\n },\n [onChange]\n );\n\n const debounceFn = useMemo(() => debounce(handleDebounceFn, debounceMs), [debounceMs, handleDebounceFn]);\n\n return <MuiTextField ref={ref} value={currentValue} onChange={handleChange} {...props} />;\n});\nTextField.displayName = 'TextField';\n"],"names":["TextField","MuiTextField","forwardRef","useCallback","useMemo","useState","debounce","debounceMs","value","onChange","props","ref","currentValue","setCurrentValue","handleChange","event","target","debounceFn","handleDebounceFn","inputValue","displayName"],"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,SAA8CA,aAAaC,YAAY,QAAQ,gBAAgB;AAC/F,SAAoCC,UAAU,EAAEC,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAC9F,OAAOC,cAAc,kBAAkB;AAIvC,OAAO,MAAMN,0BAAYE,WAAW,SAClC,EAAEK,aAAa,GAAG,EAAEC,KAAK,EAAEC,QAAQ,EAAE,GAAGC,OAAuB,EAC/DC,GAAiC;IAEjC,MAAM,CAACC,cAAcC,gBAAgB,GAAGR,SAASG;IAEjD,SAASM,aAAaC,KAAoC;QACxDF,gBAAgBE,MAAMC,MAAM,CAACR,KAAK;QAClCS,WAAWF,MAAMC,MAAM,CAACR,KAAK;IAC/B;IAEA,MAAMU,mBAAmBf,YACvB,CAACgB;QACCV,WAAWU;IACb,GACA;QAACV;KAAS;IAGZ,MAAMQ,aAAab,QAAQ,IAAME,SAASY,kBAAkBX,aAAa;QAACA;QAAYW;KAAiB;IAEvG,qBAAO,KAACjB;QAAaU,KAAKA;QAAKH,OAAOI;QAAcH,UAAUK;QAAe,GAAGJ,KAAK;;AACvF,GAAG;AACHV,UAAUoB,WAAW,GAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../../src/model/action.ts"],"names":[],"mappings":"AAaA,MAAM,MAAM,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,GAAG,CAAC;AAEnE,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAMvE;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAKtE"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Copyright The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
export function getTitleAction(action, isDraft) {
|
|
14
|
+
if (action === 'read') return 'View';
|
|
15
|
+
if (isDraft && action === 'create') return 'Add';
|
|
16
|
+
if (!isDraft && action === 'create') return 'Create';
|
|
17
|
+
if (action === 'update') return 'Edit';
|
|
18
|
+
return '';
|
|
19
|
+
}
|
|
20
|
+
export function getSubmitText(action, isDraft) {
|
|
21
|
+
if (isDraft && action === 'create') return 'Add';
|
|
22
|
+
if (isDraft && action === 'update') return 'Apply';
|
|
23
|
+
if (!isDraft) return 'Save';
|
|
24
|
+
return '';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/model/action.ts"],"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\nexport type Action = 'create' | 'read' | 'update' | 'delete' | '*';\n\nexport function getTitleAction(action: Action, isDraft: boolean): string {\n if (action === 'read') return 'View';\n if (isDraft && action === 'create') return 'Add';\n if (!isDraft && action === 'create') return 'Create';\n if (action === 'update') return 'Edit';\n return '';\n}\n\nexport function getSubmitText(action: Action, isDraft: boolean): string {\n if (isDraft && action === 'create') return 'Add';\n if (isDraft && action === 'update') return 'Apply';\n if (!isDraft) return 'Save';\n return '';\n}\n"],"names":["getTitleAction","action","isDraft","getSubmitText"],"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;AAIjC,OAAO,SAASA,eAAeC,MAAc,EAAEC,OAAgB;IAC7D,IAAID,WAAW,QAAQ,OAAO;IAC9B,IAAIC,WAAWD,WAAW,UAAU,OAAO;IAC3C,IAAI,CAACC,WAAWD,WAAW,UAAU,OAAO;IAC5C,IAAIA,WAAW,UAAU,OAAO;IAChC,OAAO;AACT;AAEA,OAAO,SAASE,cAAcF,MAAc,EAAEC,OAAgB;IAC5D,IAAIA,WAAWD,WAAW,UAAU,OAAO;IAC3C,IAAIC,WAAWD,WAAW,UAAU,OAAO;IAC3C,IAAI,CAACC,SAAS,OAAO;IACrB,OAAO;AACT"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { UnitGroupConfig, UnitConfig } from './types';
|
|
2
|
+
type BitsUnit = 'bits' | 'decbits';
|
|
3
|
+
export type BitsFormatOptions = {
|
|
4
|
+
unit?: BitsUnit;
|
|
5
|
+
decimalPlaces?: number;
|
|
6
|
+
shortValues?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare const BITS_GROUP_CONFIG: UnitGroupConfig;
|
|
9
|
+
export declare const BITS_UNIT_CONFIG: Readonly<Record<BitsUnit, UnitConfig>>;
|
|
10
|
+
export declare function formatBits(bits: number, { unit, shortValues, decimalPlaces }: BitsFormatOptions): string;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=bits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bits.d.ts","sourceRoot":"","sources":["../../src/model/bits.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAoBtD,KAAK,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC;AAEnC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,eAI/B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,CASnE,CAAC;AAEF,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,IAAa,EAAE,WAAW,EAAE,aAAa,EAAE,EAAE,iBAAiB,GAAG,MAAM,CA4DjH"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Copyright The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import numbro from 'numbro';
|
|
14
|
+
import { MAX_SIGNIFICANT_DIGITS } from './constants';
|
|
15
|
+
import { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';
|
|
16
|
+
import { getFormatterFromCache } from './formatterCache';
|
|
17
|
+
/**
|
|
18
|
+
* We support both SI (decimal) and IEC (binary) units for bits:
|
|
19
|
+
*
|
|
20
|
+
* SI/decimal (unit: 'decbits'):
|
|
21
|
+
* 1 Kb = 1000 bits (1000^1 bits)
|
|
22
|
+
* 1 Mb = 1,000,000 bits (1000^2 bits)
|
|
23
|
+
* etc.
|
|
24
|
+
*
|
|
25
|
+
* IEC/binary (unit: 'bits'):
|
|
26
|
+
* 1 Kib = 1024 bits (1024^1 bits)
|
|
27
|
+
* 1 Mib = 1,048,576 bits (1024^2 bits)
|
|
28
|
+
* etc.
|
|
29
|
+
*/ const DEFAULT_NUMBRO_MANTISSA = 2;
|
|
30
|
+
export const BITS_GROUP_CONFIG = {
|
|
31
|
+
label: 'Bits',
|
|
32
|
+
decimalPlaces: true,
|
|
33
|
+
shortValues: true
|
|
34
|
+
};
|
|
35
|
+
export const BITS_UNIT_CONFIG = {
|
|
36
|
+
bits: {
|
|
37
|
+
group: 'Bits',
|
|
38
|
+
label: 'Bits (IEC)'
|
|
39
|
+
},
|
|
40
|
+
decbits: {
|
|
41
|
+
group: 'Bits',
|
|
42
|
+
label: 'Bits (SI)'
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
export function formatBits(bits, { unit = 'bits', shortValues, decimalPlaces }) {
|
|
46
|
+
const isDecimal = unit === 'decbits';
|
|
47
|
+
const threshold = isDecimal ? 1000 : 1024;
|
|
48
|
+
// If we're showing the entire value, we can use Intl.NumberFormat.
|
|
49
|
+
if (!shouldShortenValues(shortValues) || Math.abs(bits) < threshold) {
|
|
50
|
+
const formatterOptions = {
|
|
51
|
+
style: 'decimal',
|
|
52
|
+
useGrouping: true
|
|
53
|
+
};
|
|
54
|
+
if (hasDecimalPlaces(decimalPlaces)) {
|
|
55
|
+
formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);
|
|
56
|
+
formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);
|
|
57
|
+
} else {
|
|
58
|
+
// This can happen if bits is between -threshold and threshold (1000 for SI, 1024 for IEC)
|
|
59
|
+
if (shouldShortenValues(shortValues)) {
|
|
60
|
+
formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const key = [
|
|
64
|
+
formatterOptions.style,
|
|
65
|
+
formatterOptions.useGrouping,
|
|
66
|
+
formatterOptions.maximumSignificantDigits,
|
|
67
|
+
decimalPlaces,
|
|
68
|
+
shortValues,
|
|
69
|
+
unit
|
|
70
|
+
];
|
|
71
|
+
return `${getFormatterFromCache(key, 'bits', formatterOptions, 'en-US')(bits)} bits`;
|
|
72
|
+
}
|
|
73
|
+
// If we're showing the shorten value, we use numbro.
|
|
74
|
+
// numbro is able to add units like Kb, Mb, Gb, etc. correctly.
|
|
75
|
+
const formatted = numbro(bits).format({
|
|
76
|
+
output: 'byte',
|
|
77
|
+
base: isDecimal ? 'decimal' : 'binary',
|
|
78
|
+
spaceSeparated: true,
|
|
79
|
+
mantissa: hasDecimalPlaces(decimalPlaces) ? decimalPlaces : DEFAULT_NUMBRO_MANTISSA,
|
|
80
|
+
// trimMantissa trims trailing 0s
|
|
81
|
+
trimMantissa: !hasDecimalPlaces(decimalPlaces),
|
|
82
|
+
// optionalMantissa excludes all the decimal places if they're all zeros
|
|
83
|
+
optionalMantissa: !hasDecimalPlaces(decimalPlaces)
|
|
84
|
+
});
|
|
85
|
+
// Replace byte units with bit units
|
|
86
|
+
return formatted.replace(/KB/g, 'Kb').replace(/MB/g, 'Mb').replace(/GB/g, 'Gb').replace(/TB/g, 'Tb').replace(/PB/g, 'Pb').replace(/EB/g, 'Eb').replace(/KiB/g, 'Kib').replace(/MiB/g, 'Mib').replace(/GiB/g, 'Gib').replace(/TiB/g, 'Tib').replace(/PiB/g, 'Pib').replace(/EiB/g, 'Eib');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
//# sourceMappingURL=bits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/model/bits.ts"],"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 numbro from 'numbro';\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';\nimport { getFormatterFromCache } from './formatterCache';\n\n/**\n * We support both SI (decimal) and IEC (binary) units for bits:\n *\n * SI/decimal (unit: 'decbits'):\n * 1 Kb = 1000 bits (1000^1 bits)\n * 1 Mb = 1,000,000 bits (1000^2 bits)\n * etc.\n *\n * IEC/binary (unit: 'bits'):\n * 1 Kib = 1024 bits (1024^1 bits)\n * 1 Mib = 1,048,576 bits (1024^2 bits)\n * etc.\n */\n\nconst DEFAULT_NUMBRO_MANTISSA = 2;\n\ntype BitsUnit = 'bits' | 'decbits';\n\nexport type BitsFormatOptions = {\n unit?: BitsUnit;\n decimalPlaces?: number;\n shortValues?: boolean;\n};\n\nexport const BITS_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Bits',\n decimalPlaces: true,\n shortValues: true,\n};\n\nexport const BITS_UNIT_CONFIG: Readonly<Record<BitsUnit, UnitConfig>> = {\n bits: {\n group: 'Bits',\n label: 'Bits (IEC)',\n },\n decbits: {\n group: 'Bits',\n label: 'Bits (SI)',\n },\n};\n\nexport function formatBits(bits: number, { unit = 'bits', shortValues, decimalPlaces }: BitsFormatOptions): string {\n const isDecimal = unit === 'decbits';\n const threshold = isDecimal ? 1000 : 1024;\n\n // If we're showing the entire value, we can use Intl.NumberFormat.\n if (!shouldShortenValues(shortValues) || Math.abs(bits) < threshold) {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'decimal',\n useGrouping: true,\n };\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n // This can happen if bits is between -threshold and threshold (1000 for SI, 1024 for IEC)\n if (shouldShortenValues(shortValues)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n\n const key = [\n formatterOptions.style,\n formatterOptions.useGrouping,\n formatterOptions.maximumSignificantDigits,\n decimalPlaces,\n shortValues,\n unit,\n ];\n\n return `${getFormatterFromCache(key, 'bits', formatterOptions, 'en-US')(bits)} bits`;\n }\n\n // If we're showing the shorten value, we use numbro.\n // numbro is able to add units like Kb, Mb, Gb, etc. correctly.\n const formatted = numbro(bits).format({\n output: 'byte', // numbro uses 'byte' output for bit formatting\n base: isDecimal ? 'decimal' : 'binary',\n spaceSeparated: true,\n mantissa: hasDecimalPlaces(decimalPlaces) ? decimalPlaces : DEFAULT_NUMBRO_MANTISSA,\n // trimMantissa trims trailing 0s\n trimMantissa: !hasDecimalPlaces(decimalPlaces),\n // optionalMantissa excludes all the decimal places if they're all zeros\n optionalMantissa: !hasDecimalPlaces(decimalPlaces),\n });\n\n // Replace byte units with bit units\n return formatted\n .replace(/KB/g, 'Kb')\n .replace(/MB/g, 'Mb')\n .replace(/GB/g, 'Gb')\n .replace(/TB/g, 'Tb')\n .replace(/PB/g, 'Pb')\n .replace(/EB/g, 'Eb')\n .replace(/KiB/g, 'Kib')\n .replace(/MiB/g, 'Mib')\n .replace(/GiB/g, 'Gib')\n .replace(/TiB/g, 'Tib')\n .replace(/PiB/g, 'Pib')\n .replace(/EiB/g, 'Eib');\n}\n"],"names":["numbro","MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","shouldShortenValues","getFormatterFromCache","DEFAULT_NUMBRO_MANTISSA","BITS_GROUP_CONFIG","label","decimalPlaces","shortValues","BITS_UNIT_CONFIG","bits","group","decbits","formatBits","unit","isDecimal","threshold","Math","abs","formatterOptions","style","useGrouping","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","key","formatted","format","output","base","spaceSeparated","mantissa","trimMantissa","optionalMantissa","replace"],"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,OAAOA,YAAY,SAAS;AAE5B,SAASC,sBAAsB,QAAQ,cAAc;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,EAAEC,mBAAmB,QAAQ,UAAU;AACpF,SAASC,qBAAqB,QAAQ,mBAAmB;AAEzD;;;;;;;;;;;;CAYC,GAED,MAAMC,0BAA0B;AAUhC,OAAO,MAAMC,oBAAqC;IAChDC,OAAO;IACPC,eAAe;IACfC,aAAa;AACf,EAAE;AAEF,OAAO,MAAMC,mBAA2D;IACtEC,MAAM;QACJC,OAAO;QACPL,OAAO;IACT;IACAM,SAAS;QACPD,OAAO;QACPL,OAAO;IACT;AACF,EAAE;AAEF,OAAO,SAASO,WAAWH,IAAY,EAAE,EAAEI,OAAO,MAAM,EAAEN,WAAW,EAAED,aAAa,EAAqB;IACvG,MAAMQ,YAAYD,SAAS;IAC3B,MAAME,YAAYD,YAAY,OAAO;IAErC,mEAAmE;IACnE,IAAI,CAACb,oBAAoBM,gBAAgBS,KAAKC,GAAG,CAACR,QAAQM,WAAW;QACnE,MAAMG,mBAA6C;YACjDC,OAAO;YACPC,aAAa;QACf;QAEA,IAAIrB,iBAAiBO,gBAAgB;YACnCY,iBAAiBG,qBAAqB,GAAGrB,mBAAmBM;YAC5DY,iBAAiBI,qBAAqB,GAAGtB,mBAAmBM;QAC9D,OAAO;YACL,0FAA0F;YAC1F,IAAIL,oBAAoBM,cAAc;gBACpCW,iBAAiBK,wBAAwB,GAAGzB;YAC9C;QACF;QAEA,MAAM0B,MAAM;YACVN,iBAAiBC,KAAK;YACtBD,iBAAiBE,WAAW;YAC5BF,iBAAiBK,wBAAwB;YACzCjB;YACAC;YACAM;SACD;QAED,OAAO,GAAGX,sBAAsBsB,KAAK,QAAQN,kBAAkB,SAAST,MAAM,KAAK,CAAC;IACtF;IAEA,qDAAqD;IACrD,+DAA+D;IAC/D,MAAMgB,YAAY5B,OAAOY,MAAMiB,MAAM,CAAC;QACpCC,QAAQ;QACRC,MAAMd,YAAY,YAAY;QAC9Be,gBAAgB;QAChBC,UAAU/B,iBAAiBO,iBAAiBA,gBAAgBH;QAC5D,iCAAiC;QACjC4B,cAAc,CAAChC,iBAAiBO;QAChC,wEAAwE;QACxE0B,kBAAkB,CAACjC,iBAAiBO;IACtC;IAEA,oCAAoC;IACpC,OAAOmB,UACJQ,OAAO,CAAC,OAAO,MACfA,OAAO,CAAC,OAAO,MACfA,OAAO,CAAC,OAAO,MACfA,OAAO,CAAC,OAAO,MACfA,OAAO,CAAC,OAAO,MACfA,OAAO,CAAC,OAAO,MACfA,OAAO,CAAC,QAAQ,OAChBA,OAAO,CAAC,QAAQ,OAChBA,OAAO,CAAC,QAAQ,OAChBA,OAAO,CAAC,QAAQ,OAChBA,OAAO,CAAC,QAAQ,OAChBA,OAAO,CAAC,QAAQ;AACrB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { UnitGroupConfig, UnitConfig } from './types';
|
|
2
|
+
type BytesUnit = 'bytes' | 'decbytes';
|
|
3
|
+
export type BytesFormatOptions = {
|
|
4
|
+
unit?: BytesUnit;
|
|
5
|
+
decimalPlaces?: number;
|
|
6
|
+
shortValues?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare const BYTES_GROUP_CONFIG: UnitGroupConfig;
|
|
9
|
+
export declare const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnit, UnitConfig>>;
|
|
10
|
+
export declare function formatBytes(bytes: number, { unit, shortValues, decimalPlaces }: BytesFormatOptions): string;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=bytes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../src/model/bytes.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAoBtD,KAAK,SAAS,GAAG,OAAO,GAAG,UAAU,CAAC;AAEtC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AACF,eAAO,MAAM,kBAAkB,EAAE,eAIhC,CAAC;AACF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,CASrE,CAAC;AAEF,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAc,EAAE,WAAW,EAAE,aAAa,EAAE,EAAE,kBAAkB,GAAG,MAAM,CAiDrH"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Copyright The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import numbro from 'numbro';
|
|
14
|
+
import { MAX_SIGNIFICANT_DIGITS } from './constants';
|
|
15
|
+
import { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';
|
|
16
|
+
import { getFormatterFromCache } from './formatterCache';
|
|
17
|
+
/**
|
|
18
|
+
* We support both SI (decimal) and IEC (binary) units for bytes:
|
|
19
|
+
*
|
|
20
|
+
* SI/decimal (unit: 'decbytes'):
|
|
21
|
+
* 1 KB = 1000 bytes (1000^1 bytes)
|
|
22
|
+
* 1 MB = 1,000,000 bytes (1000^2 bytes)
|
|
23
|
+
* etc.
|
|
24
|
+
*
|
|
25
|
+
* IEC/binary (unit: 'bytes'):
|
|
26
|
+
* 1 KiB = 1024 bytes (1024^1 bytes)
|
|
27
|
+
* 1 MiB = 1,048,576 bytes (1024^2 bytes)
|
|
28
|
+
* etc.
|
|
29
|
+
*/ const DEFAULT_NUMBRO_MANTISSA = 2;
|
|
30
|
+
export const BYTES_GROUP_CONFIG = {
|
|
31
|
+
label: 'Bytes',
|
|
32
|
+
decimalPlaces: true,
|
|
33
|
+
shortValues: true
|
|
34
|
+
};
|
|
35
|
+
export const BYTES_UNIT_CONFIG = {
|
|
36
|
+
bytes: {
|
|
37
|
+
group: 'Bytes',
|
|
38
|
+
label: 'Bytes (IEC)'
|
|
39
|
+
},
|
|
40
|
+
decbytes: {
|
|
41
|
+
group: 'Bytes',
|
|
42
|
+
label: 'Bytes (SI)'
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
export function formatBytes(bytes, { unit = 'bytes', shortValues, decimalPlaces }) {
|
|
46
|
+
const isDecimal = unit === 'decbytes';
|
|
47
|
+
const threshold = isDecimal ? 1000 : 1024;
|
|
48
|
+
// If we're showing the entire value, we can use Intl.NumberFormat.
|
|
49
|
+
if (!shouldShortenValues(shortValues) || Math.abs(bytes) < threshold) {
|
|
50
|
+
const formatterOptions = {
|
|
51
|
+
style: 'unit',
|
|
52
|
+
unit: 'byte',
|
|
53
|
+
unitDisplay: 'long',
|
|
54
|
+
useGrouping: true
|
|
55
|
+
};
|
|
56
|
+
if (hasDecimalPlaces(decimalPlaces)) {
|
|
57
|
+
formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);
|
|
58
|
+
formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);
|
|
59
|
+
} else {
|
|
60
|
+
// This can happen if bytes is between -threshold and threshold (1000 for SI, 1024 for IEC)
|
|
61
|
+
if (shouldShortenValues(shortValues)) {
|
|
62
|
+
formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const key = [
|
|
66
|
+
formatterOptions.style,
|
|
67
|
+
formatterOptions.unit,
|
|
68
|
+
formatterOptions.unitDisplay,
|
|
69
|
+
formatterOptions.useGrouping,
|
|
70
|
+
formatterOptions.maximumSignificantDigits,
|
|
71
|
+
decimalPlaces,
|
|
72
|
+
shortValues,
|
|
73
|
+
unit
|
|
74
|
+
];
|
|
75
|
+
return getFormatterFromCache(key, 'bytes', formatterOptions, 'en-US')(bytes);
|
|
76
|
+
}
|
|
77
|
+
// If we're showing the shorten value, we use numbro.
|
|
78
|
+
// numbro is able to add units like KB, MB, GB, etc. correctly.
|
|
79
|
+
return numbro(bytes).format({
|
|
80
|
+
output: 'byte',
|
|
81
|
+
base: isDecimal ? 'decimal' : 'binary',
|
|
82
|
+
spaceSeparated: true,
|
|
83
|
+
mantissa: hasDecimalPlaces(decimalPlaces) ? decimalPlaces : DEFAULT_NUMBRO_MANTISSA,
|
|
84
|
+
// trimMantissa trims trailing 0s
|
|
85
|
+
trimMantissa: !hasDecimalPlaces(decimalPlaces),
|
|
86
|
+
// optionalMantissa excludes all the decimal places if they're all zeros
|
|
87
|
+
optionalMantissa: !hasDecimalPlaces(decimalPlaces)
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
//# sourceMappingURL=bytes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/model/bytes.ts"],"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 numbro from 'numbro';\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';\nimport { getFormatterFromCache } from './formatterCache';\n\n/**\n * We support both SI (decimal) and IEC (binary) units for bytes:\n *\n * SI/decimal (unit: 'decbytes'):\n * 1 KB = 1000 bytes (1000^1 bytes)\n * 1 MB = 1,000,000 bytes (1000^2 bytes)\n * etc.\n *\n * IEC/binary (unit: 'bytes'):\n * 1 KiB = 1024 bytes (1024^1 bytes)\n * 1 MiB = 1,048,576 bytes (1024^2 bytes)\n * etc.\n */\n\nconst DEFAULT_NUMBRO_MANTISSA = 2;\n\ntype BytesUnit = 'bytes' | 'decbytes';\n\nexport type BytesFormatOptions = {\n unit?: BytesUnit;\n decimalPlaces?: number;\n shortValues?: boolean;\n};\nexport const BYTES_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Bytes',\n decimalPlaces: true,\n shortValues: true,\n};\nexport const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnit, UnitConfig>> = {\n bytes: {\n group: 'Bytes',\n label: 'Bytes (IEC)',\n },\n decbytes: {\n group: 'Bytes',\n label: 'Bytes (SI)',\n },\n};\n\nexport function formatBytes(bytes: number, { unit = 'bytes', shortValues, decimalPlaces }: BytesFormatOptions): string {\n const isDecimal = unit === 'decbytes';\n const threshold = isDecimal ? 1000 : 1024;\n\n // If we're showing the entire value, we can use Intl.NumberFormat.\n if (!shouldShortenValues(shortValues) || Math.abs(bytes) < threshold) {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'unit',\n unit: 'byte',\n unitDisplay: 'long',\n useGrouping: true,\n };\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n // This can happen if bytes is between -threshold and threshold (1000 for SI, 1024 for IEC)\n if (shouldShortenValues(shortValues)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n\n const key = [\n formatterOptions.style,\n formatterOptions.unit,\n formatterOptions.unitDisplay,\n formatterOptions.useGrouping,\n formatterOptions.maximumSignificantDigits,\n decimalPlaces,\n shortValues,\n unit,\n ];\n\n return getFormatterFromCache(key, 'bytes', formatterOptions, 'en-US')(bytes);\n }\n\n // If we're showing the shorten value, we use numbro.\n // numbro is able to add units like KB, MB, GB, etc. correctly.\n return numbro(bytes).format({\n output: 'byte',\n base: isDecimal ? 'decimal' : 'binary',\n spaceSeparated: true,\n mantissa: hasDecimalPlaces(decimalPlaces) ? decimalPlaces : DEFAULT_NUMBRO_MANTISSA,\n // trimMantissa trims trailing 0s\n trimMantissa: !hasDecimalPlaces(decimalPlaces),\n // optionalMantissa excludes all the decimal places if they're all zeros\n optionalMantissa: !hasDecimalPlaces(decimalPlaces),\n });\n}\n"],"names":["numbro","MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","shouldShortenValues","getFormatterFromCache","DEFAULT_NUMBRO_MANTISSA","BYTES_GROUP_CONFIG","label","decimalPlaces","shortValues","BYTES_UNIT_CONFIG","bytes","group","decbytes","formatBytes","unit","isDecimal","threshold","Math","abs","formatterOptions","style","unitDisplay","useGrouping","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","key","format","output","base","spaceSeparated","mantissa","trimMantissa","optionalMantissa"],"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,OAAOA,YAAY,SAAS;AAE5B,SAASC,sBAAsB,QAAQ,cAAc;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,EAAEC,mBAAmB,QAAQ,UAAU;AACpF,SAASC,qBAAqB,QAAQ,mBAAmB;AAEzD;;;;;;;;;;;;CAYC,GAED,MAAMC,0BAA0B;AAShC,OAAO,MAAMC,qBAAsC;IACjDC,OAAO;IACPC,eAAe;IACfC,aAAa;AACf,EAAE;AACF,OAAO,MAAMC,oBAA6D;IACxEC,OAAO;QACLC,OAAO;QACPL,OAAO;IACT;IACAM,UAAU;QACRD,OAAO;QACPL,OAAO;IACT;AACF,EAAE;AAEF,OAAO,SAASO,YAAYH,KAAa,EAAE,EAAEI,OAAO,OAAO,EAAEN,WAAW,EAAED,aAAa,EAAsB;IAC3G,MAAMQ,YAAYD,SAAS;IAC3B,MAAME,YAAYD,YAAY,OAAO;IAErC,mEAAmE;IACnE,IAAI,CAACb,oBAAoBM,gBAAgBS,KAAKC,GAAG,CAACR,SAASM,WAAW;QACpE,MAAMG,mBAA6C;YACjDC,OAAO;YACPN,MAAM;YACNO,aAAa;YACbC,aAAa;QACf;QAEA,IAAItB,iBAAiBO,gBAAgB;YACnCY,iBAAiBI,qBAAqB,GAAGtB,mBAAmBM;YAC5DY,iBAAiBK,qBAAqB,GAAGvB,mBAAmBM;QAC9D,OAAO;YACL,2FAA2F;YAC3F,IAAIL,oBAAoBM,cAAc;gBACpCW,iBAAiBM,wBAAwB,GAAG1B;YAC9C;QACF;QAEA,MAAM2B,MAAM;YACVP,iBAAiBC,KAAK;YACtBD,iBAAiBL,IAAI;YACrBK,iBAAiBE,WAAW;YAC5BF,iBAAiBG,WAAW;YAC5BH,iBAAiBM,wBAAwB;YACzClB;YACAC;YACAM;SACD;QAED,OAAOX,sBAAsBuB,KAAK,SAASP,kBAAkB,SAAST;IACxE;IAEA,qDAAqD;IACrD,+DAA+D;IAC/D,OAAOZ,OAAOY,OAAOiB,MAAM,CAAC;QAC1BC,QAAQ;QACRC,MAAMd,YAAY,YAAY;QAC9Be,gBAAgB;QAChBC,UAAU/B,iBAAiBO,iBAAiBA,gBAAgBH;QAC5D,iCAAiC;QACjC4B,cAAc,CAAChC,iBAAiBO;QAChC,wEAAwE;QACxE0B,kBAAkB,CAACjC,iBAAiBO;IACtC;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/model/constants.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,sBAAsB,IAAI,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
export const MAX_SIGNIFICANT_DIGITS = 3;
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/model/constants.ts"],"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\nexport const MAX_SIGNIFICANT_DIGITS = 3;\n"],"names":["MAX_SIGNIFICANT_DIGITS"],"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,OAAO,MAAMA,yBAAyB,EAAE"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { UnitConfig, UnitGroupConfig } from './types';
|
|
2
|
+
type CurrencyUnits = 'aud' | 'cad' | 'chf' | 'cny' | 'eur' | 'gbp' | 'hkd' | 'inr' | 'jpy' | 'krw' | 'nok' | 'nzd' | 'sek' | 'sgd' | 'usd';
|
|
3
|
+
export type CurrencyFormatOptions = {
|
|
4
|
+
unit: CurrencyUnits;
|
|
5
|
+
decimalPlaces?: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const CURRENCY_GROUP_CONFIG: UnitGroupConfig;
|
|
8
|
+
export declare const CURRENCY_UNIT_CONFIG: Readonly<Record<CurrencyUnits, UnitConfig>>;
|
|
9
|
+
export declare function formatCurrency(value: number, { unit, decimalPlaces }: CurrencyFormatOptions): string;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=currency.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currency.d.ts","sourceRoot":"","sources":["../../src/model/currency.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAMtD,KAAK,aAAa,GACd,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,CAAC;AACV,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,EAAE,aAAa,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAGF,eAAO,MAAM,qBAAqB,EAAE,eAGnC,CAAC;AACF,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,aAAa,EAAE,UAAU,CAAC,CA6D5E,CAAC;AAEF,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE,qBAAqB,GAAG,MAAM,CAwBpG"}
|