@marimo-team/frontend 0.16.0 → 0.16.1
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/assets/ConnectedDataExplorerComponent-2wVcyvDj.js +19 -0
- package/dist/assets/{ImageComparisonComponent-fTHv1Ih0.js → ImageComparisonComponent-D2j6i0hv.js} +1 -1
- package/dist/assets/{VegaLite-Bdi-TyfY.js → VegaLite-BckFaf2D.js} +1 -1
- package/dist/assets/_baseEach-CvTX9w0Y.js +1 -0
- package/dist/assets/_baseMap-CtlwA90f.js +1 -0
- package/dist/assets/_baseUniq-BKktIGQ1.js +1 -0
- package/dist/assets/{_createAggregator-DcD0kTA5.js → _createAggregator-C5CVY-0t.js} +1 -1
- package/dist/assets/{agent-panel-Crv430aI.js → agent-panel-RGLNjkYe.js} +76 -57
- package/dist/assets/{any-language-editor-CQh552Wu.js → any-language-editor-DjuXwGCA.js} +1 -1
- package/dist/assets/{architectureDiagram-W76B3OCA-BAJeBxzt.js → architectureDiagram-W76B3OCA-Dyj4ds_R.js} +1 -1
- package/dist/assets/{between-horizontal-start-Boxgxbt_.js → between-horizontal-start-Dt2aKpPf.js} +1 -1
- package/dist/assets/{blockDiagram-QIGZ2CNN-CL-1svEK.js → blockDiagram-QIGZ2CNN-o-i7DDvN.js} +1 -1
- package/dist/assets/{c4Diagram-FPNF74CW-BbEqbCTl.js → c4Diagram-FPNF74CW-DGHEwWrx.js} +1 -1
- package/dist/assets/channel-Co6iMgWq.js +1 -0
- package/dist/assets/chat-panel-9alr8FS4.js +3 -0
- package/dist/assets/{chunk-4BX2VUAB-C--8TXeE.js → chunk-4BX2VUAB-BJecb-Ri.js} +1 -1
- package/dist/assets/{chunk-55IACEB6-Bj00HDqq.js → chunk-55IACEB6-CAATkc4w.js} +1 -1
- package/dist/assets/{chunk-FMBD7UC4-C-lhB6hN.js → chunk-FMBD7UC4-DPuNbQ-f.js} +1 -1
- package/dist/assets/{chunk-K7UQS3LO-B-pGTXPt.js → chunk-K7UQS3LO-C8TWVLiH.js} +1 -1
- package/dist/assets/{chunk-QN33PNHL-DqUzGhvm.js → chunk-QN33PNHL-DiZZ09q4.js} +1 -1
- package/dist/assets/{chunk-QZHKN3VN-TntJHfSk.js → chunk-QZHKN3VN-BIUM7usu.js} +1 -1
- package/dist/assets/{chunk-TVAH2DTR-HUJb1psV.js → chunk-TVAH2DTR-vGTArPBG.js} +1 -1
- package/dist/assets/{chunk-TZMSLE5B-BK3C__t3.js → chunk-TZMSLE5B-D2KRqp_x.js} +1 -1
- package/dist/assets/{circle-play-DBLOv1Yu.js → circle-play-cjeNez0N.js} +1 -1
- package/dist/assets/classDiagram-KNZD7YFC-BbJ0rY3y.js +1 -0
- package/dist/assets/classDiagram-v2-RKCZMP56-BbJ0rY3y.js +1 -0
- package/dist/assets/{clear-button-BeoFbEKH.js → clear-button-C97JtAez.js} +1 -1
- package/dist/assets/clone-BMP0PsTa.js +1 -0
- package/dist/assets/{command-palette-CXZiSv0I.js → command-palette-B93Pjcky.js} +1 -1
- package/dist/assets/{common-C7oJcmCT.js → common-Du9rSOwD.js} +1 -1
- package/dist/assets/{compile-7L0MwhyI.js → compile-CZXqyOxa.js} +1 -1
- package/dist/assets/{cose-bilkent-S5V4N54A-BMkGLcVC.js → cose-bilkent-S5V4N54A-CqUN5Y9b.js} +1 -1
- package/dist/assets/{dagre-5GWH7T2D-BJtRienS.js → dagre-5GWH7T2D-RJqTI9DM.js} +1 -1
- package/dist/assets/{data-grid-overlay-editor-DBkmGtNs.js → data-grid-overlay-editor-DZN0q1LV.js} +1 -1
- package/dist/assets/datasources-panel-v7H3cR0p.js +1 -0
- package/dist/assets/{dependency-graph-panel-DEdOxp2X.js → dependency-graph-panel-CEog_O7V.js} +1 -1
- package/dist/assets/{diagram-N5W7TBWH-CmECY3nb.js → diagram-N5W7TBWH-D-l4zZ9d.js} +1 -1
- package/dist/assets/{diagram-QEK2KX5R-DMOVSNKD.js → diagram-QEK2KX5R-CCOmBUt-.js} +1 -1
- package/dist/assets/{diagram-S2PKOQOG-BiJ96PNQ.js → diagram-S2PKOQOG-C_I_9jnZ.js} +1 -1
- package/dist/assets/{documentation-panel-xULhaEv3.js → documentation-panel-C1BtMZ3M.js} +1 -1
- package/dist/assets/edit-page-B-oevUZ9.js +129 -0
- package/dist/assets/{ellipsis-vertical-BBqXIlc2.js → ellipsis-vertical-BEb-J8z6.js} +1 -1
- package/dist/assets/{empty-state-B3dA3G5P.js → empty-state-C99UyDE3.js} +1 -1
- package/dist/assets/{erDiagram-AWTI2OKA-MP1DiFRo.js → erDiagram-AWTI2OKA-BePOLi5M.js} +1 -1
- package/dist/assets/{error-panel-Cc1sv-Ag.js → error-panel-Bs34jXFh.js} +1 -1
- package/dist/assets/file-explorer-panel-Ck6UL861.js +1 -0
- package/dist/assets/{flowDiagram-PVAE7QVJ-BX7caPp7.js → flowDiagram-PVAE7QVJ-BgjFu5l7.js} +1 -1
- package/dist/assets/{ganttDiagram-OWAHRB6G-B462g4Yf.js → ganttDiagram-OWAHRB6G-YOPb3XSV.js} +4 -4
- package/dist/assets/{gitGraphDiagram-NY62KEGX-CGgvZ9-9.js → gitGraphDiagram-NY62KEGX-CGhqaDTy.js} +1 -1
- package/dist/assets/{glide-data-editor-C0gUFZON.js → glide-data-editor-9QUH6iso.js} +11 -11
- package/dist/assets/{graph-CHRVBzY5.js → graph-DQQFGrho.js} +1 -1
- package/dist/assets/home-page-DRKpPCrF.js +9 -0
- package/dist/assets/{index-C1v_Z9et.js → index-2252nrk6.js} +1 -1
- package/dist/assets/{index-CQDrxQ0j.js → index-Aeo6WiK7.js} +1 -1
- package/dist/assets/{index-C4Tn5NvJ.js → index-B8jXZ12t.js} +1 -1
- package/dist/assets/{index-DoRmcrKM.js → index-BAbIIxHU.js} +1 -1
- package/dist/assets/{index-BY93Ejhl.js → index-BJNCMUmG.js} +1 -1
- package/dist/assets/{index-CpTPJo4k.js → index-BW3k9Gss.js} +1 -1
- package/dist/assets/{index-D1vmG6DS.js → index-BjgnbONl.js} +1 -1
- package/dist/assets/{index-z9bohSQJ.js → index-BprjMYH5.js} +1 -1
- package/dist/assets/{index-BVgAenPd.js → index-C1ez98sk.js} +1 -1
- package/dist/assets/{index-D9UKkrr2.js → index-C2MD0vgD.js} +1 -1
- package/dist/assets/index-C7CoaNFb.js +578 -0
- package/dist/assets/{index-C-GhZ7ti.js → index-CFKO7WXI.js} +1 -1
- package/dist/assets/{index-lYa_leQE.js → index-CUFv_thQ.js} +1 -1
- package/dist/assets/{index-vmICa5KN.js → index-C_tkBKNO.js} +1 -1
- package/dist/assets/{index-C77h_TXN.js → index-CfaDbEdi.js} +1 -1
- package/dist/assets/{index-DEQvTChO.js → index-ClzeQrN7.js} +1 -1
- package/dist/assets/index-DadI618h.css +1 -0
- package/dist/assets/{index-DRMm6SNo.js → index-DdnKZNxM.js} +1 -1
- package/dist/assets/{index-CWMgowgL.js → index-G5QZppK2.js} +1 -1
- package/dist/assets/{index-Clbi_Yaq.js → index-SGLNXrGP.js} +1 -1
- package/dist/assets/{index-C-8WADat.js → index-aE43R74q.js} +1 -1
- package/dist/assets/infoDiagram-STP46IZ2-CJLOpSAf.js +2 -0
- package/dist/assets/{isEmpty-DU_ogP_D.js → isEmpty-D-4c7sMv.js} +1 -1
- package/dist/assets/{journeyDiagram-BIP6EPQ6-C6EgLP_Q.js → journeyDiagram-BIP6EPQ6-C94u3Mv3.js} +1 -1
- package/dist/assets/{kanban-definition-6OIFK2YF-BXzYO1yj.js → kanban-definition-6OIFK2YF-BEXYFzz7.js} +1 -1
- package/dist/assets/{layout-jihVw5-i.js → layout-Bz2BJ2ru.js} +1 -1
- package/dist/assets/{linear-C4blANlC.js → linear-D8s7K76e.js} +1 -1
- package/dist/assets/links-BpXlz1GG.js +7 -0
- package/dist/assets/{logs-panel-D401qzZh.js → logs-panel-DC7wpmPz.js} +1 -1
- package/dist/assets/{markdown-renderer-Cd9eYyaL.js → markdown-renderer-DRdSWR9X.js} +20 -20
- package/dist/assets/{mermaid-BEVuRz_O.js → mermaid-Y3x4hmD0.js} +1 -1
- package/dist/assets/{mermaid.core-CaSnaLH0.js → mermaid.core-DzthE35Y.js} +4 -4
- package/dist/assets/min-BBO3-1Hg.js +1 -0
- package/dist/assets/{mindmap-definition-Q6HEUPPD-BXUM5MT2.js → mindmap-definition-Q6HEUPPD-DktvuLe1.js} +1 -1
- package/dist/assets/{number-overlay-editor-4uWXGlPG.js → number-overlay-editor-BEfwI1IT.js} +1 -1
- package/dist/assets/outline-panel-CdsnAy2w.js +1 -0
- package/dist/assets/{packages-panel-CJL0MVlj.js → packages-panel-DiTA-d_D.js} +1 -1
- package/dist/assets/{pieDiagram-ADFJNKIX-Dxt5PVNo.js → pieDiagram-ADFJNKIX-DQDNQ-de.js} +1 -1
- package/dist/assets/{quadrantDiagram-LMRXKWRM-D4pUaA31.js → quadrantDiagram-LMRXKWRM-0kgIXc2-.js} +1 -1
- package/dist/assets/{react-plotly-cJZ0VWBq.js → react-plotly-DJqqfM7c.js} +1 -1
- package/dist/assets/{requirementDiagram-4UW4RH46-DVRTjgas.js → requirementDiagram-4UW4RH46-B5rb0ypd.js} +1 -1
- package/dist/assets/{run-page-BUEnMC9w.js → run-page-CFmLrv1R.js} +1 -1
- package/dist/assets/{sankeyDiagram-GR3RE2ED-CVFnD9C-.js → sankeyDiagram-GR3RE2ED-Dom7IlnF.js} +1 -1
- package/dist/assets/{scratchpad-panel-BIgRENkI.js → scratchpad-panel-CuHWpHO8.js} +1 -1
- package/dist/assets/{secrets-panel-xY5-V_BD.js → secrets-panel-CfHc5YD0.js} +1 -1
- package/dist/assets/{sequenceDiagram-C3RYC4MD-_lY4ZN_S.js → sequenceDiagram-C3RYC4MD-PNJWXQbw.js} +1 -1
- package/dist/assets/{slides-component-DMjQomc3.css → slides-component-C-LoGC1U.css} +1 -1
- package/dist/assets/{slides-component-Xjymwj7X.js → slides-component-CJgaTRZ0.js} +1 -1
- package/dist/assets/snippets-panel-B2EC1txM.js +1 -0
- package/dist/assets/sortBy-DZnlX29-.js +1 -0
- package/dist/assets/{state-C4NiC9tO.js → state-CWict9RU.js} +1 -1
- package/dist/assets/{stateDiagram-KXAO66HF-Da0JQWCn.js → stateDiagram-KXAO66HF-BE58aJnr.js} +1 -1
- package/dist/assets/stateDiagram-v2-UMBNRL4Z-CdThjimL.js +1 -0
- package/dist/assets/storage-DRaR04wR.js +26 -0
- package/dist/assets/{terminal-BPwTkXae.js → terminal-BX3Su5q7.js} +1 -1
- package/dist/assets/{time-Dv5_Ouz_.js → time-hUzZfpNE.js} +1 -1
- package/dist/assets/{timeline-definition-XQNQX7LJ-Dxh5Zu2e.js → timeline-definition-XQNQX7LJ-CqQP9t51.js} +1 -1
- package/dist/assets/tracing-B10Q1n-L.js +2 -0
- package/dist/assets/{tracing-panel-DAzrzNmm.js → tracing-panel-Du8WCnno.js} +2 -2
- package/dist/assets/{trash-Dc6DSjz_.js → trash-B81GTiv6.js} +1 -1
- package/dist/assets/{tree-jheoerAX.js → tree-6vW2ogkh.js} +1 -1
- package/dist/assets/{treemap-75Q7IDZK-IgpxeGaf.js → treemap-75Q7IDZK-CdwDwwsz.js} +27 -27
- package/dist/assets/variable-panel-D5qgJI7k.js +1 -0
- package/dist/assets/{vega-component-BpfpiPKI.js → vega-component-DJaJWMJM.js} +1 -1
- package/dist/assets/worker-fHbtoWvT.js +1 -0
- package/dist/assets/{xychartDiagram-6GGTOJPD-CmNigJ31.js → xychartDiagram-6GGTOJPD-WFtXqaM9.js} +1 -1
- package/dist/index.html +2 -2
- package/package.json +3 -2
- package/src/components/app-config/user-config-form.tsx +46 -1
- package/src/components/chat/acp/__tests__/__snapshots__/prompt.test.ts.snap +62 -43
- package/src/components/chat/acp/__tests__/atoms.test.ts +1 -1
- package/src/components/chat/acp/__tests__/state.test.ts +36 -36
- package/src/components/chat/acp/agent-panel.tsx +24 -27
- package/src/components/chat/acp/blocks.tsx +6 -6
- package/src/components/chat/acp/prompt.ts +62 -43
- package/src/components/chat/chat-panel.tsx +5 -1
- package/src/components/chat/markdown-renderer.tsx +6 -10
- package/src/components/chat/tool-call-accordion.tsx +52 -20
- package/src/components/data-table/SearchBar.tsx +8 -7
- package/src/components/data-table/__tests__/column_formatting.test.ts +50 -35
- package/src/components/data-table/__tests__/data-table.test.tsx +39 -1
- package/src/components/data-table/cell-hover-template/feature.ts +14 -0
- package/src/components/data-table/cell-hover-template/types.ts +11 -0
- package/src/components/data-table/charts/components/form-fields.tsx +41 -37
- package/src/components/data-table/charts/forms/common-chart.tsx +2 -2
- package/src/components/data-table/column-explorer-panel/column-explorer.tsx +5 -2
- package/src/components/data-table/column-formatting/feature.ts +62 -29
- package/src/components/data-table/column-formatting/types.ts +1 -0
- package/src/components/data-table/column-header.tsx +3 -1
- package/src/components/data-table/column-summary/chart-spec-model.tsx +24 -7
- package/src/components/data-table/column-summary/column-summary.tsx +18 -9
- package/src/components/data-table/columns.tsx +42 -18
- package/src/components/data-table/data-table.tsx +10 -2
- package/src/components/data-table/date-popover.tsx +85 -75
- package/src/components/data-table/filter-pills.tsx +14 -9
- package/src/components/data-table/header-items.tsx +5 -1
- package/src/components/data-table/pagination.tsx +20 -13
- package/src/components/data-table/renderers.tsx +28 -0
- package/src/components/data-table/row-viewer-panel/row-viewer.tsx +10 -8
- package/src/components/datasources/column-preview.tsx +6 -2
- package/src/components/datasources/datasources.tsx +8 -12
- package/src/components/editor/ai/transport/chat-transport.tsx +4 -1
- package/src/components/editor/cell/CellStatus.tsx +23 -20
- package/src/components/editor/cell/CreateCellButton.tsx +3 -4
- package/src/components/editor/cell/code/language-toggle.tsx +3 -4
- package/src/components/editor/chrome/wrapper/footer-items/machine-stats.tsx +39 -28
- package/src/components/editor/controls/notebook-menu-dropdown.tsx +4 -2
- package/src/components/editor/file-tree/requesting-tree.tsx +14 -8
- package/src/components/editor/renderers/CellArray.tsx +3 -4
- package/src/components/editor/renderers/slides-layout/slides-layout.tsx +3 -3
- package/src/components/editor/renderers/slides-layout/types.ts +1 -0
- package/src/components/pages/home-page.tsx +4 -1
- package/src/components/slides/slides-component.tsx +1 -1
- package/src/components/slides/slides.css +6 -0
- package/src/components/terminal/theme.tsx +1 -0
- package/src/components/tracing/tracing-spec.ts +5 -4
- package/src/components/ui/range-slider.tsx +4 -2
- package/src/components/ui/slider.tsx +3 -1
- package/src/components/variables/variables-table.tsx +3 -0
- package/src/core/MarimoApp.tsx +9 -6
- package/src/core/ai/context/__tests__/registry.test.ts +6 -4
- package/src/core/ai/context/providers/cell-output.ts +3 -2
- package/src/core/ai/context/providers/error.ts +3 -1
- package/src/core/ai/context/providers/file.ts +7 -2
- package/src/core/ai/context/providers/tables.ts +3 -2
- package/src/core/ai/context/providers/variable.ts +6 -4
- package/src/core/ai/staged-cells.ts +34 -1
- package/src/core/cells/__tests__/add-missing-import.test.ts +67 -22
- package/src/core/cells/add-missing-import.ts +24 -7
- package/src/core/cells/cells.ts +26 -27
- package/src/core/cells/logs.ts +1 -1
- package/src/core/codemirror/find-replace/search-highlight.ts +3 -1
- package/src/core/codemirror/language/LanguageAdapters.ts +9 -3
- package/src/core/codemirror/lsp/notebook-lsp.ts +8 -2
- package/src/core/codemirror/readonly/__tests__/extension.test.ts +1 -1
- package/src/core/codemirror/rtc/loro/awareness.ts +52 -17
- package/src/core/codemirror/rtc/loro/sync.ts +12 -4
- package/src/core/config/config-schema.ts +1 -0
- package/src/core/config/config.ts +4 -0
- package/src/core/hotkeys/hotkeys.ts +8 -4
- package/src/core/i18n/__tests__/locale-provider.test.tsx +176 -0
- package/src/core/i18n/locale-provider.tsx +35 -0
- package/src/core/i18n/with-locale.tsx +12 -0
- package/src/core/islands/components/web-components.tsx +13 -10
- package/src/core/kernel/RuntimeState.ts +4 -1
- package/src/core/kernel/messages.ts +2 -2
- package/src/core/network/DeferredRequestRegistry.ts +16 -4
- package/src/core/runtime/runtime.ts +5 -4
- package/src/core/wasm/bridge.ts +5 -1
- package/src/core/wasm/store.ts +4 -1
- package/src/core/wasm/worker/message-buffer.ts +3 -2
- package/src/core/websocket/types.ts +22 -16
- package/src/hooks/useFormatting.ts +97 -0
- package/src/hooks/useTimer.ts +8 -5
- package/src/plugins/core/registerReactComponent.tsx +16 -10
- package/src/plugins/impl/DataTablePlugin.tsx +4 -0
- package/src/plugins/impl/RangeSliderPlugin.tsx +5 -3
- package/src/plugins/impl/SliderPlugin.tsx +3 -1
- package/src/plugins/impl/anywidget/model.ts +16 -5
- package/src/plugins/impl/data-editor/types.ts +7 -5
- package/src/plugins/impl/data-explorer/components/column-summary.tsx +20 -13
- package/src/plugins/impl/panel/utils.ts +6 -4
- package/src/plugins/layout/OutlinePlugin.tsx +69 -0
- package/src/plugins/layout/StatPlugin.tsx +4 -1
- package/src/plugins/plugins.ts +2 -0
- package/src/utils/__tests__/dates.test.ts +45 -24
- package/src/utils/__tests__/numbers.test.ts +42 -30
- package/src/utils/__tests__/once.test.ts +187 -0
- package/src/utils/dates.ts +15 -10
- package/src/utils/edit-distance.ts +8 -6
- package/src/utils/errors.ts +1 -1
- package/src/utils/id-tree.tsx +21 -10
- package/src/utils/localStorage.ts +13 -4
- package/src/utils/numbers.ts +11 -11
- package/src/utils/once.ts +32 -0
- package/src/utils/paths.ts +4 -1
- package/src/utils/pluralize.ts +12 -5
- package/src/utils/python-poet/poet.ts +30 -15
- package/src/utils/time.ts +5 -1
- package/dist/assets/ConnectedDataExplorerComponent-BErMbWvG.js +0 -19
- package/dist/assets/_baseEach-CNBxBxvS.js +0 -1
- package/dist/assets/_baseMap-D1WHjKrd.js +0 -1
- package/dist/assets/_baseUniq-CCgDNtZb.js +0 -1
- package/dist/assets/channel-_2eNSz0n.js +0 -1
- package/dist/assets/chat-panel-CXh5Wl6C.js +0 -3
- package/dist/assets/classDiagram-KNZD7YFC-BGmh9POF.js +0 -1
- package/dist/assets/classDiagram-v2-RKCZMP56-BGmh9POF.js +0 -1
- package/dist/assets/clone-BFDSPAj3.js +0 -1
- package/dist/assets/datasources-panel-B7FbYLiy.js +0 -1
- package/dist/assets/edit-page-BrYda9VE.js +0 -129
- package/dist/assets/file-explorer-panel-Bw59Kva1.js +0 -1
- package/dist/assets/home-page-Fb2osjys.js +0 -9
- package/dist/assets/index-Cx0bsY1w.css +0 -1
- package/dist/assets/index-DKEudB02.js +0 -578
- package/dist/assets/infoDiagram-STP46IZ2-CVyrdLc8.js +0 -2
- package/dist/assets/links-D59GIweI.js +0 -7
- package/dist/assets/min-DUMu_zeK.js +0 -1
- package/dist/assets/outline-panel-DIzkvm2I.js +0 -1
- package/dist/assets/snippets-panel-CTPYW41n.js +0 -1
- package/dist/assets/sortBy-BNZKwiq_.js +0 -1
- package/dist/assets/stateDiagram-v2-UMBNRL4Z-D5lYZOOt.js +0 -1
- package/dist/assets/storage-CMdLzB_c.js +0 -26
- package/dist/assets/tracing-BCIurUfa.js +0 -2
- package/dist/assets/variable-panel-DYAiLBmF.js +0 -1
- package/dist/assets/worker-X5rxzQGQ.js +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* Copyright 2024 Marimo. All rights reserved. */
|
|
2
2
|
import { type JSX, useEffect, useId, useState } from "react";
|
|
3
|
+
import { useLocale } from "react-aria";
|
|
3
4
|
import { z } from "zod";
|
|
4
5
|
import { NumberField } from "@/components/ui/number-field";
|
|
5
6
|
import { cn } from "@/utils/cn";
|
|
@@ -85,6 +86,7 @@ const SliderComponent = ({
|
|
|
85
86
|
disabled,
|
|
86
87
|
}: SliderProps): JSX.Element => {
|
|
87
88
|
const id = useId();
|
|
89
|
+
const { locale } = useLocale();
|
|
88
90
|
|
|
89
91
|
// Hold internal value
|
|
90
92
|
const [internalValue, setInternalValue] = useState(value);
|
|
@@ -138,7 +140,7 @@ const SliderComponent = ({
|
|
|
138
140
|
/>
|
|
139
141
|
{showValue && (
|
|
140
142
|
<div className="text-xs text-muted-foreground min-w-[16px]">
|
|
141
|
-
{prettyScientificNumber(valueMap(internalValue))}
|
|
143
|
+
{prettyScientificNumber(valueMap(internalValue), { locale })}
|
|
142
144
|
</div>
|
|
143
145
|
)}
|
|
144
146
|
{includeInput && (
|
|
@@ -17,8 +17,10 @@ export type EventHandler = (...args: any[]) => void;
|
|
|
17
17
|
|
|
18
18
|
class ModelManager {
|
|
19
19
|
private models = new Map<string, Deferred<Model<any>>>();
|
|
20
|
-
|
|
21
|
-
constructor(
|
|
20
|
+
private timeout: number;
|
|
21
|
+
constructor(timeout = 10_000) {
|
|
22
|
+
this.timeout = timeout;
|
|
23
|
+
}
|
|
22
24
|
|
|
23
25
|
get(key: string): Promise<Model<any>> {
|
|
24
26
|
let deferred = this.models.get(key);
|
|
@@ -64,16 +66,25 @@ export class Model<T extends Record<string, any>> implements AnyModel<T> {
|
|
|
64
66
|
private ANY_CHANGE_EVENT = "change";
|
|
65
67
|
private dirtyFields;
|
|
66
68
|
public static _modelManager: ModelManager = MODEL_MANAGER;
|
|
69
|
+
private data: T;
|
|
70
|
+
private onChange: (value: Partial<T>) => void;
|
|
71
|
+
private sendToWidget: (req: {
|
|
72
|
+
content?: any;
|
|
73
|
+
buffers?: ArrayBuffer[] | ArrayBufferView[];
|
|
74
|
+
}) => Promise<null | undefined>;
|
|
67
75
|
|
|
68
76
|
constructor(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
77
|
+
data: T,
|
|
78
|
+
onChange: (value: Partial<T>) => void,
|
|
79
|
+
sendToWidget: (req: {
|
|
72
80
|
content?: any;
|
|
73
81
|
buffers?: ArrayBuffer[] | ArrayBufferView[];
|
|
74
82
|
}) => Promise<null | undefined>,
|
|
75
83
|
initialDirtyFields: Set<keyof T>,
|
|
76
84
|
) {
|
|
85
|
+
this.data = data;
|
|
86
|
+
this.onChange = onChange;
|
|
87
|
+
this.sendToWidget = sendToWidget;
|
|
77
88
|
this.dirtyFields = new Set(initialDirtyFields);
|
|
78
89
|
}
|
|
79
90
|
|
|
@@ -10,11 +10,13 @@ export interface PositionalEdit {
|
|
|
10
10
|
value: unknown;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export
|
|
14
|
-
Insert
|
|
15
|
-
Remove
|
|
16
|
-
Rename
|
|
17
|
-
}
|
|
13
|
+
export const BulkEdit = {
|
|
14
|
+
Insert: "insert",
|
|
15
|
+
Remove: "remove",
|
|
16
|
+
Rename: "rename",
|
|
17
|
+
} as const;
|
|
18
|
+
|
|
19
|
+
type BulkEdit = (typeof BulkEdit)[keyof typeof BulkEdit];
|
|
18
20
|
|
|
19
21
|
export interface RowEdit {
|
|
20
22
|
rowIdx: number;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import type { Schema } from "compassql/build/src/schema";
|
|
4
4
|
import { BarChartBigIcon } from "lucide-react";
|
|
5
5
|
import React, { useState } from "react";
|
|
6
|
+
import { useDateFormatter, useNumberFormatter } from "react-aria";
|
|
6
7
|
import { Button } from "@/components/ui/button";
|
|
7
8
|
import {
|
|
8
9
|
Select,
|
|
@@ -131,7 +132,9 @@ export const ColumnSummary: React.FC<Props> = ({ schema }) => {
|
|
|
131
132
|
{STAT_KEYS.map((key) => (
|
|
132
133
|
<div key={key} className="flex flex-row gap-2 min-w-[100px]">
|
|
133
134
|
<span className="font-semibold">{key}</span>
|
|
134
|
-
<span>
|
|
135
|
+
<span>
|
|
136
|
+
<FormatStat value={stats?.[key]} />
|
|
137
|
+
</span>
|
|
135
138
|
</div>
|
|
136
139
|
))}
|
|
137
140
|
</div>
|
|
@@ -151,24 +154,28 @@ const STAT_KEYS = [
|
|
|
151
154
|
"stdev",
|
|
152
155
|
];
|
|
153
156
|
|
|
154
|
-
|
|
157
|
+
const FormatStat = ({ value }: { value: unknown }) => {
|
|
158
|
+
// Decimal .2
|
|
159
|
+
const numberFormatter = useNumberFormatter({
|
|
160
|
+
maximumFractionDigits: 2,
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// Just day, month, year
|
|
164
|
+
const dateFormatter = useDateFormatter({
|
|
165
|
+
year: "numeric",
|
|
166
|
+
month: "short",
|
|
167
|
+
day: "numeric",
|
|
168
|
+
});
|
|
169
|
+
|
|
155
170
|
if (typeof value === "number") {
|
|
156
|
-
|
|
157
|
-
return new Intl.NumberFormat("en-US", {
|
|
158
|
-
maximumFractionDigits: 2,
|
|
159
|
-
}).format(value);
|
|
171
|
+
return numberFormatter.format(value);
|
|
160
172
|
}
|
|
161
173
|
if (typeof value === "string") {
|
|
162
174
|
return value;
|
|
163
175
|
}
|
|
164
176
|
if (typeof value === "object" && value instanceof Date) {
|
|
165
|
-
|
|
166
|
-
return new Intl.DateTimeFormat("en-US", {
|
|
167
|
-
year: "numeric",
|
|
168
|
-
month: "short",
|
|
169
|
-
day: "numeric",
|
|
170
|
-
}).format(value);
|
|
177
|
+
return dateFormatter.format(value);
|
|
171
178
|
}
|
|
172
179
|
|
|
173
180
|
return String(value);
|
|
174
|
-
}
|
|
181
|
+
};
|
|
@@ -57,11 +57,13 @@ export class EventBuffer<T> {
|
|
|
57
57
|
private buffer: T[] = [];
|
|
58
58
|
private isBlocked = false;
|
|
59
59
|
private timeout: number | null = null;
|
|
60
|
+
private processEvents: () => void;
|
|
61
|
+
private blockDuration: number;
|
|
60
62
|
|
|
61
|
-
constructor(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
constructor(processEvents: () => void, blockDuration = 200) {
|
|
64
|
+
this.processEvents = processEvents;
|
|
65
|
+
this.blockDuration = blockDuration;
|
|
66
|
+
}
|
|
65
67
|
|
|
66
68
|
add(event: T) {
|
|
67
69
|
this.buffer.push(event);
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/* Copyright 2024 Marimo. All rights reserved. */
|
|
2
|
+
import { Provider, useAtomValue } from "jotai";
|
|
3
|
+
import type { JSX } from "react";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { notebookOutline } from "@/core/cells/cells";
|
|
6
|
+
import { store } from "@/core/state/jotai";
|
|
7
|
+
import { OutlineList } from "../../components/editor/chrome/panels/outline/floating-outline";
|
|
8
|
+
import {
|
|
9
|
+
findOutlineElements,
|
|
10
|
+
useActiveOutline,
|
|
11
|
+
} from "../../components/editor/chrome/panels/outline/useActiveOutline";
|
|
12
|
+
import type {
|
|
13
|
+
IStatelessPlugin,
|
|
14
|
+
IStatelessPluginProps,
|
|
15
|
+
} from "../stateless-plugin";
|
|
16
|
+
|
|
17
|
+
interface Data {
|
|
18
|
+
label?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const OutlineContent: React.FC<{ label?: string }> = ({ label }) => {
|
|
22
|
+
const { items } = useAtomValue(notebookOutline);
|
|
23
|
+
const headerElements = findOutlineElements(items);
|
|
24
|
+
const { activeHeaderId, activeOccurrences } =
|
|
25
|
+
useActiveOutline(headerElements);
|
|
26
|
+
|
|
27
|
+
if (items.length === 0) {
|
|
28
|
+
return (
|
|
29
|
+
<div className="text-muted-foreground text-sm p-4 border border-dashed border-border rounded-lg">
|
|
30
|
+
No outline found. Add markdown headings to your notebook to create an
|
|
31
|
+
outline.
|
|
32
|
+
</div>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<div className="border border-border rounded-lg">
|
|
38
|
+
{label && (
|
|
39
|
+
<div className="px-4 py-2 border-b border-border font-medium text-sm">
|
|
40
|
+
{label}
|
|
41
|
+
</div>
|
|
42
|
+
)}
|
|
43
|
+
<OutlineList
|
|
44
|
+
className="max-h-[400px]"
|
|
45
|
+
items={items}
|
|
46
|
+
activeHeaderId={activeHeaderId}
|
|
47
|
+
activeOccurrences={activeOccurrences}
|
|
48
|
+
/>
|
|
49
|
+
</div>
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export class OutlinePlugin implements IStatelessPlugin<Data> {
|
|
54
|
+
tagName = "marimo-outline";
|
|
55
|
+
|
|
56
|
+
validator = z.object({
|
|
57
|
+
label: z.string().optional(),
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
render(props: IStatelessPluginProps<Data>): JSX.Element {
|
|
61
|
+
const { label } = props.data;
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<Provider store={store}>
|
|
65
|
+
<OutlineContent label={label} />
|
|
66
|
+
</Provider>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { TriangleIcon } from "lucide-react";
|
|
4
4
|
import type { JSX } from "react";
|
|
5
|
+
import { useLocale } from "react-aria";
|
|
5
6
|
import { z } from "zod";
|
|
6
7
|
import { cn } from "@/utils/cn";
|
|
7
8
|
import { prettyNumber } from "@/utils/numbers";
|
|
@@ -41,6 +42,8 @@ export const StatComponent: React.FC<Data> = ({
|
|
|
41
42
|
bordered,
|
|
42
43
|
direction,
|
|
43
44
|
}) => {
|
|
45
|
+
const { locale } = useLocale();
|
|
46
|
+
|
|
44
47
|
const renderPrettyValue = () => {
|
|
45
48
|
if (value == null) {
|
|
46
49
|
return <i>No value</i>;
|
|
@@ -51,7 +54,7 @@ export const StatComponent: React.FC<Data> = ({
|
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
if (typeof value === "number") {
|
|
54
|
-
return prettyNumber(value);
|
|
57
|
+
return prettyNumber(value, locale);
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
if (typeof value === "boolean") {
|
package/src/plugins/plugins.ts
CHANGED
|
@@ -45,6 +45,7 @@ import { JsonOutputPlugin } from "./layout/JsonOutputPlugin";
|
|
|
45
45
|
import { LazyPlugin } from "./layout/LazyPlugin";
|
|
46
46
|
import { MimeRendererPlugin } from "./layout/MimeRenderPlugin";
|
|
47
47
|
import { MermaidPlugin } from "./layout/mermaid/MermaidPlugin";
|
|
48
|
+
import { OutlinePlugin } from "./layout/OutlinePlugin";
|
|
48
49
|
import { ProgressPlugin } from "./layout/ProgressPlugin";
|
|
49
50
|
import { RoutesPlugin } from "./layout/RoutesPlugin";
|
|
50
51
|
import { StatPlugin } from "./layout/StatPlugin";
|
|
@@ -99,6 +100,7 @@ const LAYOUT_PLUGINS: Array<IStatelessPlugin<unknown>> = [
|
|
|
99
100
|
new MimeRendererPlugin(),
|
|
100
101
|
new MermaidPlugin(),
|
|
101
102
|
new NavigationMenuPlugin(),
|
|
103
|
+
new OutlinePlugin(),
|
|
102
104
|
new ProgressPlugin(),
|
|
103
105
|
new RoutesPlugin(),
|
|
104
106
|
new StatPlugin(),
|
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
timeAgo,
|
|
9
9
|
} from "../dates";
|
|
10
10
|
|
|
11
|
+
const locale = "en-US";
|
|
12
|
+
|
|
11
13
|
describe("dates", () => {
|
|
12
14
|
// Save original timezone
|
|
13
15
|
let originalTimezone: string | undefined;
|
|
@@ -25,36 +27,38 @@ describe("dates", () => {
|
|
|
25
27
|
|
|
26
28
|
describe("prettyDate", () => {
|
|
27
29
|
it("returns empty string for null or undefined", () => {
|
|
28
|
-
expect(prettyDate(null, "date")).toBe("");
|
|
29
|
-
expect(prettyDate(undefined, "date")).toBe("");
|
|
30
|
+
expect(prettyDate(null, "date", locale)).toBe("");
|
|
31
|
+
expect(prettyDate(undefined, "date", locale)).toBe("");
|
|
30
32
|
});
|
|
31
33
|
|
|
32
34
|
it("formats date correctly", () => {
|
|
33
35
|
const date = new Date("2023-05-15T12:00:00Z");
|
|
34
36
|
// Using a regex to match the pattern since exact format may vary by locale
|
|
35
|
-
expect(prettyDate(date.toISOString(), "date")).toMatch(
|
|
37
|
+
expect(prettyDate(date.toISOString(), "date", locale)).toMatch(
|
|
38
|
+
/May 15, 2023/,
|
|
39
|
+
);
|
|
36
40
|
});
|
|
37
41
|
|
|
38
42
|
it("formats datetime correctly", () => {
|
|
39
43
|
const date = new Date("2023-05-15T12:00:00Z");
|
|
40
|
-
expect(prettyDate(date.toISOString(), "datetime")).toMatch(
|
|
44
|
+
expect(prettyDate(date.toISOString(), "datetime", locale)).toMatch(
|
|
41
45
|
/May 15, 2023/,
|
|
42
46
|
);
|
|
43
47
|
});
|
|
44
48
|
|
|
45
49
|
it("handles errors gracefully", () => {
|
|
46
|
-
expect(prettyDate("invalid-date", "date")).toBe("Invalid Date");
|
|
50
|
+
expect(prettyDate("invalid-date", "date", locale)).toBe("Invalid Date");
|
|
47
51
|
});
|
|
48
52
|
|
|
49
53
|
it("handles numeric timestamp input", () => {
|
|
50
54
|
const timestamp = 1_684_152_000_000; // 2023-05-15T12:00:00Z in milliseconds
|
|
51
|
-
expect(prettyDate(timestamp, "date")).toMatch(/May 15, 2023/);
|
|
55
|
+
expect(prettyDate(timestamp, "date", locale)).toMatch(/May 15, 2023/);
|
|
52
56
|
});
|
|
53
57
|
|
|
54
58
|
it("preserves timezone for datetime type", () => {
|
|
55
59
|
// This date is in winter time to avoid daylight saving time issues
|
|
56
60
|
const date = new Date("2023-01-15T15:30:00Z");
|
|
57
|
-
expect(prettyDate(date.toISOString(), "datetime")).toMatch(
|
|
61
|
+
expect(prettyDate(date.toISOString(), "datetime", locale)).toMatch(
|
|
58
62
|
/Jan 15, 2023/,
|
|
59
63
|
);
|
|
60
64
|
});
|
|
@@ -62,7 +66,9 @@ describe("dates", () => {
|
|
|
62
66
|
it("drops timezone for date type by using UTC", () => {
|
|
63
67
|
// Create a date that would be different days in different timezones
|
|
64
68
|
const date = new Date("2023-05-15T23:30:00Z"); // Late in the day UTC
|
|
65
|
-
expect(prettyDate(date.toISOString(), "date")).toMatch(
|
|
69
|
+
expect(prettyDate(date.toISOString(), "date", locale)).toMatch(
|
|
70
|
+
/May 15, 2023/,
|
|
71
|
+
);
|
|
66
72
|
});
|
|
67
73
|
|
|
68
74
|
describe("with different locales", () => {
|
|
@@ -86,7 +92,9 @@ describe("dates", () => {
|
|
|
86
92
|
};
|
|
87
93
|
|
|
88
94
|
const date = new Date("2023-05-15T12:00:00Z");
|
|
89
|
-
expect(prettyDate(date.toISOString(), "date")).toBe(
|
|
95
|
+
expect(prettyDate(date.toISOString(), "date", locale)).toBe(
|
|
96
|
+
"15 mai 2023",
|
|
97
|
+
);
|
|
90
98
|
});
|
|
91
99
|
});
|
|
92
100
|
});
|
|
@@ -94,34 +102,42 @@ describe("dates", () => {
|
|
|
94
102
|
describe("exactDateTime", () => {
|
|
95
103
|
it("formats date without milliseconds", () => {
|
|
96
104
|
const date = new Date("2023-05-15T12:00:00.000Z");
|
|
97
|
-
expect(exactDateTime(date, undefined)).toBe(
|
|
105
|
+
expect(exactDateTime(date, undefined, locale)).toBe(
|
|
106
|
+
"2023-05-15 12:00:00",
|
|
107
|
+
);
|
|
98
108
|
});
|
|
99
109
|
|
|
100
110
|
it("formats date with milliseconds", () => {
|
|
101
111
|
const date = new Date("2023-05-15T12:00:00.123Z");
|
|
102
|
-
expect(exactDateTime(date, undefined)).toBe(
|
|
112
|
+
expect(exactDateTime(date, undefined, locale)).toBe(
|
|
113
|
+
"2023-05-15 12:00:00.123",
|
|
114
|
+
);
|
|
103
115
|
});
|
|
104
116
|
|
|
105
117
|
it("formats date in UTC when renderInUTC is true", () => {
|
|
106
118
|
const date = new Date("2023-05-15T12:00:00.000Z");
|
|
107
|
-
expect(exactDateTime(date, "UTC")).toBe(
|
|
119
|
+
expect(exactDateTime(date, "UTC", locale)).toBe(
|
|
120
|
+
"2023-05-15 12:00:00 UTC",
|
|
121
|
+
);
|
|
108
122
|
});
|
|
109
123
|
|
|
110
124
|
it("formats date with milliseconds in UTC when renderInUTC is true", () => {
|
|
111
125
|
const date = new Date("2023-05-15T12:00:00.123Z");
|
|
112
|
-
expect(exactDateTime(date, "UTC")).toBe(
|
|
126
|
+
expect(exactDateTime(date, "UTC", locale)).toBe(
|
|
127
|
+
"2023-05-15 12:00:00.123 UTC",
|
|
128
|
+
);
|
|
113
129
|
});
|
|
114
130
|
|
|
115
131
|
it("formats date in America/New_York timezone", () => {
|
|
116
132
|
const date = new Date("2023-05-15T12:00:00.000Z");
|
|
117
|
-
expect(exactDateTime(date, "America/New_York")).toBe(
|
|
133
|
+
expect(exactDateTime(date, "America/New_York", locale)).toBe(
|
|
118
134
|
"2023-05-15 08:00:00 EDT",
|
|
119
135
|
);
|
|
120
136
|
});
|
|
121
137
|
|
|
122
138
|
it("formats date with milliseconds in America/New_York timezone", () => {
|
|
123
139
|
const date = new Date("2023-05-15T12:00:00.123Z");
|
|
124
|
-
expect(exactDateTime(date, "America/New_York")).toBe(
|
|
140
|
+
expect(exactDateTime(date, "America/New_York", locale)).toBe(
|
|
125
141
|
"2023-05-15 08:00:00.123 EDT",
|
|
126
142
|
);
|
|
127
143
|
});
|
|
@@ -129,42 +145,47 @@ describe("dates", () => {
|
|
|
129
145
|
|
|
130
146
|
describe("timeAgo", () => {
|
|
131
147
|
it("returns empty string for null, undefined, or 0", () => {
|
|
132
|
-
expect(timeAgo(null)).toBe("");
|
|
133
|
-
expect(timeAgo(undefined)).toBe("");
|
|
134
|
-
expect(timeAgo(0)).toBe("");
|
|
148
|
+
expect(timeAgo(null, locale)).toBe("");
|
|
149
|
+
expect(timeAgo(undefined, locale)).toBe("");
|
|
150
|
+
expect(timeAgo(0, locale)).toBe("");
|
|
135
151
|
});
|
|
136
152
|
|
|
137
153
|
it("formats today's date correctly", () => {
|
|
138
154
|
const today = new Date();
|
|
139
|
-
const result = timeAgo(today.toISOString());
|
|
155
|
+
const result = timeAgo(today.toISOString(), locale);
|
|
140
156
|
expect(result).toMatch(/Today at/);
|
|
141
157
|
});
|
|
142
158
|
|
|
143
159
|
it("formats yesterday's date correctly", () => {
|
|
144
160
|
const yesterday = new Date();
|
|
145
161
|
yesterday.setDate(yesterday.getDate() - 1);
|
|
146
|
-
const result = timeAgo(yesterday.toISOString());
|
|
162
|
+
const result = timeAgo(yesterday.toISOString(), locale);
|
|
147
163
|
expect(result).toMatch(/Yesterday at/);
|
|
148
164
|
});
|
|
149
165
|
|
|
150
166
|
it("formats older dates correctly", () => {
|
|
151
167
|
const oldDate = new Date("2020-01-01T12:00:00Z");
|
|
152
|
-
const result = timeAgo(oldDate.toISOString());
|
|
168
|
+
const result = timeAgo(oldDate.toISOString(), locale);
|
|
153
169
|
expect(result).toMatch(/Jan 1, 2020 at/);
|
|
154
170
|
});
|
|
155
171
|
|
|
156
172
|
it("handles errors gracefully", () => {
|
|
157
|
-
expect(timeAgo("invalid-date")).toBe(
|
|
173
|
+
expect(timeAgo("invalid-date", locale)).toBe(
|
|
174
|
+
"Invalid Date at Invalid Date",
|
|
175
|
+
);
|
|
158
176
|
});
|
|
159
177
|
});
|
|
160
178
|
|
|
161
179
|
describe("getShortTimeZone", () => {
|
|
162
180
|
it("returns the short timezone", () => {
|
|
163
|
-
expect(getShortTimeZone("America/New_York")).toBeOneOf([
|
|
181
|
+
expect(getShortTimeZone("America/New_York", locale)).toBeOneOf([
|
|
182
|
+
"EDT",
|
|
183
|
+
"EST",
|
|
184
|
+
]);
|
|
164
185
|
});
|
|
165
186
|
|
|
166
187
|
it("handles errors gracefully", () => {
|
|
167
|
-
expect(getShortTimeZone("MarimoLand")).toBe("MarimoLand");
|
|
188
|
+
expect(getShortTimeZone("MarimoLand", locale)).toBe("MarimoLand");
|
|
168
189
|
});
|
|
169
190
|
});
|
|
170
191
|
|
|
@@ -6,24 +6,32 @@ import {
|
|
|
6
6
|
prettyScientificNumber,
|
|
7
7
|
} from "../numbers";
|
|
8
8
|
|
|
9
|
+
const locale = "en-US";
|
|
10
|
+
|
|
9
11
|
describe("prettyNumber", () => {
|
|
10
12
|
it("should format numbers", () => {
|
|
11
|
-
expect(prettyNumber(123_456_789)).toBe("123,456,789");
|
|
12
|
-
expect(prettyNumber(1234.567_89)).toBe("1,234.57");
|
|
13
|
-
expect(prettyNumber(0)).toBe("0");
|
|
13
|
+
expect(prettyNumber(123_456_789, locale)).toBe("123,456,789");
|
|
14
|
+
expect(prettyNumber(1234.567_89, locale)).toBe("1,234.57");
|
|
15
|
+
expect(prettyNumber(0, locale)).toBe("0");
|
|
14
16
|
});
|
|
15
17
|
});
|
|
16
18
|
|
|
19
|
+
const options = { locale };
|
|
20
|
+
|
|
17
21
|
describe("prettyScientificNumber", () => {
|
|
18
22
|
it("should handle special cases", () => {
|
|
19
|
-
expect(prettyScientificNumber(0)).toBe("0");
|
|
20
|
-
expect(prettyScientificNumber(Number.NaN)).toBe("NaN");
|
|
21
|
-
expect(prettyScientificNumber(Number.POSITIVE_INFINITY)).toBe(
|
|
22
|
-
|
|
23
|
+
expect(prettyScientificNumber(0, options)).toBe("0");
|
|
24
|
+
expect(prettyScientificNumber(Number.NaN, options)).toBe("NaN");
|
|
25
|
+
expect(prettyScientificNumber(Number.POSITIVE_INFINITY, options)).toBe(
|
|
26
|
+
"Infinity",
|
|
27
|
+
);
|
|
28
|
+
expect(prettyScientificNumber(Number.NEGATIVE_INFINITY, options)).toBe(
|
|
29
|
+
"-Infinity",
|
|
30
|
+
);
|
|
23
31
|
});
|
|
24
32
|
|
|
25
33
|
it("should format decimals with scientific notation, ignoring integer part rounding", () => {
|
|
26
|
-
const opts = { shouldRound: true };
|
|
34
|
+
const opts = { shouldRound: true, locale };
|
|
27
35
|
expect(prettyScientificNumber(123_456, opts)).toBe("123,456");
|
|
28
36
|
expect(prettyScientificNumber(123_456.7, opts)).toBe("123,456.7");
|
|
29
37
|
expect(prettyScientificNumber(12_345.6789, opts)).toBe("12,345.68");
|
|
@@ -40,10 +48,10 @@ describe("prettyScientificNumber", () => {
|
|
|
40
48
|
});
|
|
41
49
|
|
|
42
50
|
it("should not round numbers when shouldRound is false", () => {
|
|
43
|
-
expect(prettyScientificNumber(123_456)).toBe("123,456");
|
|
44
|
-
expect(prettyScientificNumber(123_456.7)).toBe("123,456.7");
|
|
45
|
-
expect(prettyScientificNumber(12_345.6789)).toBe("12,345.6789");
|
|
46
|
-
expect(prettyScientificNumber(1.234_567_891_011_12)).toBe(
|
|
51
|
+
expect(prettyScientificNumber(123_456, options)).toBe("123,456");
|
|
52
|
+
expect(prettyScientificNumber(123_456.7, options)).toBe("123,456.7");
|
|
53
|
+
expect(prettyScientificNumber(12_345.6789, options)).toBe("12,345.6789");
|
|
54
|
+
expect(prettyScientificNumber(1.234_567_891_011_12, options)).toBe(
|
|
47
55
|
"1.23456789101112",
|
|
48
56
|
);
|
|
49
57
|
});
|
|
@@ -51,26 +59,30 @@ describe("prettyScientificNumber", () => {
|
|
|
51
59
|
|
|
52
60
|
describe("prettyEngineeringNumber", () => {
|
|
53
61
|
it("should handle special cases", () => {
|
|
54
|
-
expect(prettyEngineeringNumber(0)).toBe("0");
|
|
55
|
-
expect(prettyEngineeringNumber(-0)).toBe("0"); // Test with negative zero
|
|
56
|
-
expect(prettyEngineeringNumber(Number.NaN)).toBe("NaN");
|
|
57
|
-
expect(prettyEngineeringNumber(Number.POSITIVE_INFINITY)).toBe(
|
|
58
|
-
|
|
62
|
+
expect(prettyEngineeringNumber(0, locale)).toBe("0");
|
|
63
|
+
expect(prettyEngineeringNumber(-0, locale)).toBe("0"); // Test with negative zero
|
|
64
|
+
expect(prettyEngineeringNumber(Number.NaN, locale)).toBe("NaN");
|
|
65
|
+
expect(prettyEngineeringNumber(Number.POSITIVE_INFINITY, locale)).toBe(
|
|
66
|
+
"Infinity",
|
|
67
|
+
);
|
|
68
|
+
expect(prettyEngineeringNumber(Number.NEGATIVE_INFINITY, locale)).toBe(
|
|
69
|
+
"-Infinity",
|
|
70
|
+
);
|
|
59
71
|
});
|
|
60
72
|
|
|
61
73
|
it("should format decimals with engineering notation, ignoring integer part", () => {
|
|
62
|
-
expect(prettyEngineeringNumber(123_456)).toBe("123k");
|
|
63
|
-
expect(prettyEngineeringNumber(123_456.7)).toBe("123k");
|
|
64
|
-
expect(prettyEngineeringNumber(12_345.6789)).toBe("12.3k");
|
|
65
|
-
expect(prettyEngineeringNumber(1.2345)).toBe("1.23");
|
|
66
|
-
expect(prettyEngineeringNumber(1.000_001_234)).toBe("1");
|
|
67
|
-
expect(prettyEngineeringNumber(0.12)).toBe("120m");
|
|
68
|
-
expect(prettyEngineeringNumber(0.1234)).toBe("123m");
|
|
69
|
-
expect(prettyEngineeringNumber(0.000_123_4)).toBe("123µ");
|
|
70
|
-
expect(prettyEngineeringNumber(-1.2345)).toBe("-1.23"); // Test with negative numbers
|
|
71
|
-
expect(prettyEngineeringNumber(-1.000_001_234)).toBe("-1");
|
|
72
|
-
expect(prettyEngineeringNumber(-0.12)).toBe("-120m");
|
|
73
|
-
expect(prettyEngineeringNumber(-0.1234)).toBe("-123m");
|
|
74
|
-
expect(prettyEngineeringNumber(-0.000_123_4)).toBe("-123µ");
|
|
74
|
+
expect(prettyEngineeringNumber(123_456, locale)).toBe("123k");
|
|
75
|
+
expect(prettyEngineeringNumber(123_456.7, locale)).toBe("123k");
|
|
76
|
+
expect(prettyEngineeringNumber(12_345.6789, locale)).toBe("12.3k");
|
|
77
|
+
expect(prettyEngineeringNumber(1.2345, locale)).toBe("1.23");
|
|
78
|
+
expect(prettyEngineeringNumber(1.000_001_234, locale)).toBe("1");
|
|
79
|
+
expect(prettyEngineeringNumber(0.12, locale)).toBe("120m");
|
|
80
|
+
expect(prettyEngineeringNumber(0.1234, locale)).toBe("123m");
|
|
81
|
+
expect(prettyEngineeringNumber(0.000_123_4, locale)).toBe("123µ");
|
|
82
|
+
expect(prettyEngineeringNumber(-1.2345, locale)).toBe("-1.23"); // Test with negative numbers
|
|
83
|
+
expect(prettyEngineeringNumber(-1.000_001_234, locale)).toBe("-1");
|
|
84
|
+
expect(prettyEngineeringNumber(-0.12, locale)).toBe("-120m");
|
|
85
|
+
expect(prettyEngineeringNumber(-0.1234, locale)).toBe("-123m");
|
|
86
|
+
expect(prettyEngineeringNumber(-0.000_123_4, locale)).toBe("-123µ");
|
|
75
87
|
});
|
|
76
88
|
});
|