@marimo-team/frontend 0.25.3-dev39 → 0.25.3-dev40
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/CellStatus-BGIWF94J.js +1 -0
- package/dist/assets/{ConnectedDataExplorerComponent-DMdJT25t.js → ConnectedDataExplorerComponent-D9UK8o9A.js} +1 -1
- package/dist/assets/{ErrorBoundary-D1ozl9e0.js → ErrorBoundary-hliG40Pk.js} +2 -2
- package/dist/assets/{JsonOutput-Dqg7qwkl.js → JsonOutput-9tmC-p6h.js} +6 -6
- package/dist/assets/{LazyAnyLanguageCodeMirror-B4fCknq1.js → LazyAnyLanguageCodeMirror-BPYE76jR.js} +2 -2
- package/dist/assets/{MarimoErrorOutput-BYSTEwo1.js → MarimoErrorOutput-BaHdbtck.js} +1 -1
- package/dist/assets/{RenderHTML-B18UiW8r.js → RenderHTML-B1FzB5NY.js} +1 -1
- package/dist/assets/{RunButton-CWvRnb98.js → RunButton-DpGokdF1.js} +1 -1
- package/dist/assets/{add-cell-with-ai-C4pN_ho7.js → add-cell-with-ai-BYWG0iKO.js} +2 -2
- package/dist/assets/{add-connection-dialog-BErVOfUV.js → add-connection-dialog-BWbUVPJk.js} +1 -1
- package/dist/assets/{agent-panel-QQDTP8Vb.js → agent-panel-DKNiQrAl.js} +1 -1
- package/dist/assets/ai-model-dropdown-CIg9eu47.js +13 -0
- package/dist/assets/{alert-dialog-BaPGzeOK.js → alert-dialog-C-sWmKva.js} +1 -1
- package/dist/assets/any-language-editor-DUMe1UCk.js +1 -0
- package/dist/assets/{app-config-button-DBHN-U2l.js → app-config-button-BvkL2eSY.js} +1 -1
- package/dist/assets/arrays-0R2reF2y.js +1 -0
- package/dist/assets/{blob-DY_W1wFZ.js → blob-BQfLiwKr.js} +1 -1
- package/dist/assets/{button-COI-NGrx.js → button-D8gVKwe-.js} +1 -1
- package/dist/assets/{cache-panel-DTY1dqvi.js → cache-panel-Byolv2ht.js} +1 -1
- package/dist/assets/{capabilities-BJvf-MD4.js → capabilities-Pq1YNPlK.js} +1 -1
- package/dist/assets/{cell-editor-CCFDuQIT.js → cell-editor-BKKUv4d5.js} +2 -2
- package/dist/assets/{cell-link-BOqoitvE.js → cell-link-B_QkRkm-.js} +1 -1
- package/dist/assets/{cells-CN1I_0eH.js → cells-CdH98VSn.js} +2 -2
- package/dist/assets/{chat-display-D1_UV6v7.js → chat-display-CNbRSebo.js} +1 -1
- package/dist/assets/{chat-panel-C4OJDIt6.js → chat-panel-HbEKDf0c.js} +1 -1
- package/dist/assets/{chat-ui-wuDYPZ-w.js → chat-ui-BwMev8Bf.js} +1 -1
- package/dist/assets/{circle-DXf-VWZG.js → circle-B6D_6D8w.js} +1 -1
- package/dist/assets/{code-visibility-CnU9xZw7.js → code-visibility-sQ37CBNo.js} +1 -1
- package/dist/assets/{column-preview-z4bqk4HW.js → column-preview-CsEBzIUE.js} +1 -1
- package/dist/assets/{command-palette-TblDi15Q.js → command-palette-BzZ86pUz.js} +1 -1
- package/dist/assets/{common-Cbk0KIh7.js → common-S2v8dsEy.js} +1 -1
- package/dist/assets/{components-C88UxBXz.js → components-D-TnFWjo.js} +1 -1
- package/dist/assets/{components-CskjK6xZ.js → components-DrU8dOzy.js} +1 -1
- package/dist/assets/{components-YBmtV0p6.js → components-lDm0qi2t.js} +1 -1
- package/dist/assets/{config-DEzFV5-l.js → config-BoBwH7CU.js} +1 -1
- package/dist/assets/{config-MaHeMC9o.js → config-CYsbZpwa.js} +2 -2
- package/dist/assets/{config-CA1V-wjh.js → config-DGX7JYor.js} +1 -1
- package/dist/assets/{copy-D8O_CYCG.js → copy-KlhazlhB.js} +1 -1
- package/dist/assets/{copy-icon-BIiRXh_3.js → copy-icon-8-a5vovc.js} +1 -1
- package/dist/assets/{createReducer-DgRODTW6.js → createReducer-HKXUbqyz.js} +1 -1
- package/dist/assets/{datasource-DZJ6qqVI.js → datasource-BA7YF4eo.js} +1 -1
- package/dist/assets/{dates-CfmdTL6B.js → dates-CQMwFko2.js} +1 -1
- package/dist/assets/{dependency-graph-panel-DeZ66gIo.js → dependency-graph-panel-DsjI61Qa.js} +1 -1
- package/dist/assets/{dist-iaThVDkA.js → dist-jlhMTKo_.js} +1 -1
- package/dist/assets/{documentation-panel-Tl5G1cPt.js → documentation-panel-hk3IdeXy.js} +1 -1
- package/dist/assets/{download-s8iwxGDb.js → download-CCZkq0y4.js} +1 -1
- package/dist/assets/{dropdown-menu-C1rnl-0o.js → dropdown-menu-DS6umAnH.js} +1 -1
- package/dist/assets/{edit-page-CjoAJvyN.js → edit-page-BgS6tjth.js} +4 -4
- package/dist/assets/{error-banner-COZ7SfYV.js → error-banner-B5kzVf_0.js} +1 -1
- package/dist/assets/{error-entries-D11Bn1Hk.js → error-entries-BVXrGOTZ.js} +1 -1
- package/dist/assets/{error-panel-kfxFDscu.js → error-panel-DYethUUR.js} +1 -1
- package/dist/assets/{es-Cqst59WX.js → es-N9SHpmG7.js} +1 -1
- package/dist/assets/feedback-button-DDzObtF2.js +1 -0
- package/dist/assets/{feedback-button-DVABjD9Y.js → feedback-button-DaNc3uJa.js} +1 -1
- package/dist/assets/{file-explorer-panel-CvmK-rEU.js → file-explorer-panel-CqnzSSYc.js} +1 -1
- package/dist/assets/{file-name-input-DAj9a3RQ.js → file-name-input-D4AvwZV9.js} +1 -1
- package/dist/assets/{floating-outline-DDavqWJx.js → floating-outline-CTy-Iakk.js} +1 -1
- package/dist/assets/{formats-BkelUASr.js → formats-zylfwejq.js} +1 -1
- package/dist/assets/{formatting-BqrP-n49.js → formatting-uom1es4b.js} +1 -1
- package/dist/assets/{fullscreen-B9tHcfpV.js → fullscreen-BWTs8pYZ.js} +1 -1
- package/dist/assets/{gallery-page-xP6VqDyd.js → gallery-page-ByjlvM6k.js} +1 -1
- package/dist/assets/{glide-data-editor-32vBJJf8.js → glide-data-editor-CABBj2b0.js} +2 -2
- package/dist/assets/{glide-utils-CIrAxdjv.js → glide-utils-HFqhvWHI.js} +2 -2
- package/dist/assets/{home-page-CvGzjVr4.js → home-page-DejRSjeJ.js} +3 -3
- package/dist/assets/{hooks-C1_gQ8kr.js → hooks-BJgCcVXZ.js} +1 -1
- package/dist/assets/{html-to-image-DK9Zl1lU.js → html-to-image-D_0rd3_B.js} +1 -1
- package/dist/assets/{index-6b4mf8Ai.css → index-ChfDZJzP.css} +1 -1
- package/dist/assets/index-PDJQd7X6.js +30 -0
- package/dist/assets/{input-BoBxR50a.js → input-ByHt6aoV.js} +1 -1
- package/dist/assets/{kiosk-mode-BZECfg9k.js → kiosk-mode-BGmMSc7A.js} +1 -1
- package/dist/assets/{layout-BccvBeZy.js → layout-Ct0rjb-5.js} +3 -3
- package/dist/assets/links-CXcpNIM0.js +1 -0
- package/dist/assets/{logs-panel-BhXo1sVJ.js → logs-panel-TyeqEvOY.js} +1 -1
- package/dist/assets/{markdown-renderer-D2dafr8r.js → markdown-renderer-BFyD6Jhs.js} +1 -1
- package/dist/assets/{menu-items-BrwnTgyK.js → menu-items-BgUyNUpu.js} +1 -1
- package/dist/assets/{mermaid-D2FUGQeW.js → mermaid-B6mqMm5_.js} +1 -1
- package/dist/assets/{name-cell-input-SHvgfcBR.js → name-cell-input-D-0VF3qd.js} +1 -1
- package/dist/assets/numbers-CsZVw3Dc.js +1 -0
- package/dist/assets/{objects-snlMn4yk.js → objects-rLPlQ3X_.js} +1 -1
- package/dist/assets/{once-Haz_uxEL.js → once-6KNTRW0u.js} +1 -1
- package/dist/assets/{outline-panel-CpY3FH-u.js → outline-panel-DMTjk2WC.js} +1 -1
- package/dist/assets/{packages-panel-oZ0qZBec.js → packages-panel-DrT69k9L.js} +1 -1
- package/dist/assets/{panel-accordion-state-ChFIY2WQ.js → panel-accordion-state-Ban6j---.js} +1 -1
- package/dist/assets/{panels-91ywfwgc.js → panels-BLYQRkEc.js} +1 -1
- package/dist/assets/process-output-DzpQYlpY.js +1 -0
- package/dist/assets/{readonly-code-display-C1eH5BDP.js → readonly-code-display-Cyn3k5TX.js} +1 -1
- package/dist/assets/{readonly-python-code-BaElyj-4.js → readonly-python-code-DrXDDAnA.js} +1 -1
- package/dist/assets/{renderShortcut-C1JwYcqW.js → renderShortcut-H60uiHBp.js} +1 -1
- package/dist/assets/{reveal-component-FCuqfC5H.js → reveal-component-_lKImPWP.js} +1 -1
- package/dist/assets/{run-page-CbyMlRt1.js → run-page-7UNg--Rj.js} +1 -1
- package/dist/assets/{runs-BLp5jezv.js → runs-6lJxKV1w.js} +1 -1
- package/dist/assets/{runtime-details-state-Bpn67vTN.js → runtime-details-state-CKOKhMhv.js} +1 -1
- package/dist/assets/{scratchpad-panel-OF9_e0l_.js → scratchpad-panel-C7h4MgqN.js} +1 -1
- package/dist/assets/{scroll-to-bottom-button-1FyowpWV.js → scroll-to-bottom-button-CIkON2WJ.js} +1 -1
- package/dist/assets/{secrets-panel-D7KN4tVs.js → secrets-panel-CmLZsNfp.js} +1 -1
- package/dist/assets/{select-DTBn5eTb.js → select-3CVGlYrC.js} +1 -1
- package/dist/assets/{session-DqoWmb7X.js → session-B8Y-GJnS.js} +1 -1
- package/dist/assets/{session-panel-CExxjkjV.js → session-panel-CLiWXc5y.js} +1 -1
- package/dist/assets/{snippets-panel-DfRtTFJ-.js → snippets-panel-Wrqaorxa.js} +1 -1
- package/dist/assets/{spec-BfSBcO5B.js → spec-uCpVvaAR.js} +1 -1
- package/dist/assets/{state-uwRvJLb8.js → state-BY4_P6ko.js} +1 -1
- package/dist/assets/{state-BAJYRhmO.js → state-C0irhlOZ.js} +1 -1
- package/dist/assets/{state-DxQnC_1I.js → state-Ck7FMD5A.js} +1 -1
- package/dist/assets/{state-C3oDoyFe.js → state-DaWgt-rn.js} +1 -1
- package/dist/assets/{state-BUqF6L9e.js → state-TVREh4u4.js} +1 -1
- package/dist/assets/{state-CHojzKpZ.js → state-_uXVmwuN.js} +1 -1
- package/dist/assets/{strings-B2vv-ENv.js → strings-C25fhMR_.js} +1 -1
- package/dist/assets/{swiper-component-a07domrZ.js → swiper-component-CRGRy5_O.js} +1 -1
- package/dist/assets/{switch-CTaiAjrz.js → switch-1h011wlH.js} +1 -1
- package/dist/assets/{tabs-BuQlZFbt.js → tabs-CY8E4r9U.js} +1 -1
- package/dist/assets/{terminal--4gDbK7q.js → terminal-Dp5gyJ7l.js} +1 -1
- package/dist/assets/{toast-BGzLGnvw.js → toast-Gzxi-le_.js} +1 -1
- package/dist/assets/{tooltip-BsSdc1NQ.js → tooltip-Brya4Ghn.js} +1 -1
- package/dist/assets/{tooltip-C9TuY18o.js → tooltip-CkGm8X7m.js} +1 -1
- package/dist/assets/tracing-fUNLyKuj.js +1 -0
- package/dist/assets/{tracing-panel-DNabsbtA.js → tracing-panel-Cx4OqOoP.js} +2 -2
- package/dist/assets/{tree-actions-BXvnBv45.js → tree-actions-B1vsdenY.js} +1 -1
- package/dist/assets/{use-restore-focus-BxEGwIbk.js → use-restore-focus-DdS7Tl0F.js} +1 -1
- package/dist/assets/{useAddCell-6ECZ0xPG.js → useAddCell-DZ-50qEG.js} +1 -1
- package/dist/assets/useAsyncData-DhhdOGGd.js +1 -0
- package/dist/assets/{useBoolean-BvAx9Qrr.js → useBoolean-5g-bBaYF.js} +1 -1
- package/dist/assets/{useCellActionButton-Djyiwayj.js → useCellActionButton-DINnRstv.js} +1 -1
- package/dist/assets/{useDeleteCell-KX6SEwki.js → useDeleteCell-CREJXVNp.js} +1 -1
- package/dist/assets/{useDependencyPanelTab-B8ke9iTY.js → useDependencyPanelTab-Cw5VT16Q.js} +1 -1
- package/dist/assets/{useEventListener-D9cftcHj.js → useEventListener-CjDeLqFC.js} +1 -1
- package/dist/assets/{useIframeCapabilities-CwTkczVN.js → useIframeCapabilities-Czr9e4uG.js} +1 -1
- package/dist/assets/{useInstallPackage-C9-icL78.js → useInstallPackage-Cw0dVELh.js} +1 -1
- package/dist/assets/{useInterval--x3s1VpI.js → useInterval-DJdQmXnq.js} +1 -1
- package/dist/assets/{useNotebookActions-CluLEhAd.js → useNotebookActions-B4av4mLc.js} +1 -1
- package/dist/assets/{useRunCells-B847kPLO.js → useRunCells-BHBMk9zW.js} +1 -1
- package/dist/assets/{useSplitCell-CnvTmIw7.js → useSplitCell-DAgwZV0q.js} +1 -1
- package/dist/assets/{useTheme-n8Dj1zH7.js → useTheme-DLtPc-39.js} +1 -1
- package/dist/assets/{utils-CaQYvazl.js → utils-DfElfBpz.js} +1 -1
- package/dist/assets/vega-component-pQE2mKc1.js +1 -0
- package/dist/assets/{vega-embed-container-CxuIHhsS.js → vega-embed-container-DtArSJz1.js} +1 -1
- package/dist/assets/{write-secret-modal-DzKAInL2.js → write-secret-modal-usRSi1bb.js} +1 -1
- package/dist/index.html +68 -68
- package/package.json +1 -1
- package/src/components/app-config/ai-config.tsx +5 -1
- package/src/components/data-table/__tests__/date-popover.test.tsx +72 -0
- package/src/components/data-table/column-visibility-dropdown.tsx +8 -13
- package/src/components/data-table/columns.tsx +2 -1
- package/src/components/data-table/date-popover.tsx +6 -4
- package/src/components/data-table/row-viewer-panel/row-viewer.tsx +2 -2
- package/src/components/editor/ai/add-cell-with-ai.tsx +3 -3
- package/src/components/editor/connections/components.tsx +1 -1
- package/src/components/editor/output/MarimoTracebackOutput.tsx +1 -1
- package/src/components/pages/home-page.tsx +4 -4
- package/src/components/tracing/tracing.tsx +2 -2
- package/src/core/cells/pending-delete-service.ts +2 -6
- package/src/core/datasets/__tests__/data-source-discovery.test.ts +4 -4
- package/src/core/datasets/data-source-discovery.ts +4 -6
- package/src/core/hotkeys/actions.ts +2 -4
- package/src/core/runtime/runtime.ts +3 -4
- package/src/hooks/__tests__/useAsyncData.test.tsx +148 -0
- package/src/hooks/useAsyncData.ts +3 -3
- package/src/hooks/useDataSourceDiscovery.ts +6 -4
- package/src/hooks/useElapsedTime.ts +3 -3
- package/src/plugins/core/registerReactComponent.tsx +1 -1
- package/src/plugins/impl/DropdownPlugin.tsx +2 -6
- package/src/plugins/impl/FormPlugin.tsx +1 -1
- package/src/plugins/impl/code/any-language-editor.tsx +2 -2
- package/src/plugins/impl/data-editor/glide-data-editor.tsx +8 -5
- package/src/plugins/impl/data-editor/glide-utils.ts +3 -1
- package/src/plugins/impl/vega/make-selectable.ts +3 -6
- package/src/utils/__tests__/arrays.test.ts +35 -0
- package/src/utils/__tests__/numbers.test.ts +48 -1
- package/src/utils/__tests__/objects.test.ts +21 -0
- package/src/utils/arrays.ts +10 -0
- package/src/utils/numbers.ts +28 -17
- package/src/utils/objects.ts +3 -7
- package/dist/assets/CellStatus-wFCGHpDX.js +0 -1
- package/dist/assets/ai-model-dropdown-D5Fe5GS-.js +0 -13
- package/dist/assets/any-language-editor-BdTWdMCI.js +0 -1
- package/dist/assets/arrays-BqUx5USx.js +0 -1
- package/dist/assets/feedback-button-3bZHpuSh.js +0 -1
- package/dist/assets/index-Dtv0HH-7.js +0 -30
- package/dist/assets/links-DkkL9DVa.js +0 -1
- package/dist/assets/numbers-Mk3-CcoU.js +0 -1
- package/dist/assets/process-output-Dvq4b2kJ.js +0 -1
- package/dist/assets/tracing-BnfAB-BH.js +0 -1
- package/dist/assets/useAsyncData-C7aJJz0Y.js +0 -1
- package/dist/assets/vega-component-DAkdRNSF.js +0 -1
|
@@ -27,8 +27,8 @@ export function matchesDiscoveryGroup(
|
|
|
27
27
|
*/
|
|
28
28
|
export interface LiveConnectionSnapshot {
|
|
29
29
|
dialects: readonly string[];
|
|
30
|
-
storageProtocols:
|
|
31
|
-
storageBackendTypes:
|
|
30
|
+
storageProtocols: ReadonlySet<string>;
|
|
31
|
+
storageBackendTypes: ReadonlySet<string>;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/**
|
|
@@ -47,15 +47,13 @@ export function isDetectedSourceConnected(
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
if (
|
|
50
|
-
match.protocols.some((protocol) =>
|
|
51
|
-
snapshot.storageProtocols.includes(protocol),
|
|
52
|
-
)
|
|
50
|
+
match.protocols.some((protocol) => snapshot.storageProtocols.has(protocol))
|
|
53
51
|
) {
|
|
54
52
|
return true;
|
|
55
53
|
}
|
|
56
54
|
|
|
57
55
|
return match.backendTypes.some((backendType) =>
|
|
58
|
-
snapshot.storageBackendTypes.
|
|
56
|
+
snapshot.storageBackendTypes.has(backendType),
|
|
59
57
|
);
|
|
60
58
|
}
|
|
61
59
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { atom, useAtomValue, useSetAtom } from "jotai";
|
|
3
3
|
import useEvent from "react-use-event-hook";
|
|
4
4
|
import type { HotkeyAction } from "@/core/hotkeys/hotkeys";
|
|
5
|
+
import { Objects } from "@/utils/objects";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Map of registered keyboard shortcuts and their callbacks.
|
|
@@ -29,10 +30,7 @@ export function useSetRegisteredAction() {
|
|
|
29
30
|
},
|
|
30
31
|
),
|
|
31
32
|
unregisterAction: useEvent((shortcut: HotkeyAction) => {
|
|
32
|
-
set((actions) =>
|
|
33
|
-
const { [shortcut]: unused, ...rest } = actions;
|
|
34
|
-
return rest;
|
|
35
|
-
});
|
|
33
|
+
set((actions) => Objects.omit(actions, [shortcut]));
|
|
36
34
|
}),
|
|
37
35
|
};
|
|
38
36
|
}
|
|
@@ -10,6 +10,8 @@ import { isStaticNotebook } from "../static/static-state";
|
|
|
10
10
|
import { isWasm } from "../wasm/utils";
|
|
11
11
|
import type { RuntimeConfig } from "./types";
|
|
12
12
|
|
|
13
|
+
const knownQueryParams = new Set(Object.values(KnownQueryParams));
|
|
14
|
+
|
|
13
15
|
export class RuntimeManager {
|
|
14
16
|
private initialHealthyCheck = new Deferred<void>();
|
|
15
17
|
private config: RuntimeConfig;
|
|
@@ -72,10 +74,7 @@ export class RuntimeManager {
|
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
for (const [key, value] of currentParams.entries()) {
|
|
75
|
-
if (
|
|
76
|
-
restrictToKnownQueryParams &&
|
|
77
|
-
!Object.values(KnownQueryParams).includes(key)
|
|
78
|
-
) {
|
|
77
|
+
if (restrictToKnownQueryParams && !knownQueryParams.has(key)) {
|
|
79
78
|
continue;
|
|
80
79
|
}
|
|
81
80
|
baseUrl.searchParams.set(key, value);
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
import { act, render, renderHook, waitFor } from "@testing-library/react";
|
|
3
|
+
import { Activity } from "react";
|
|
4
|
+
import { describe, expect, it, vi } from "vitest";
|
|
5
|
+
import { Deferred } from "@/utils/Deferred";
|
|
6
|
+
import { useAsyncData } from "../useAsyncData";
|
|
7
|
+
|
|
8
|
+
function AsyncDataStatus({ fetch }: { fetch: () => Promise<string> }) {
|
|
9
|
+
const result = useAsyncData(fetch, []);
|
|
10
|
+
return (
|
|
11
|
+
<output
|
|
12
|
+
data-status={result.status}
|
|
13
|
+
data-fetching={result.isFetching}
|
|
14
|
+
data-error={result.error?.message ?? ""}
|
|
15
|
+
>
|
|
16
|
+
{result.data}
|
|
17
|
+
</output>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
describe("useAsyncData", () => {
|
|
22
|
+
it.each(["success", "error"] as const)(
|
|
23
|
+
"restarts fetching when Activity reopens after %s",
|
|
24
|
+
async (initialStatus) => {
|
|
25
|
+
const initial = new Deferred<string>();
|
|
26
|
+
const restarted = new Deferred<string>();
|
|
27
|
+
const fetch = vi
|
|
28
|
+
.fn(() => restarted.promise)
|
|
29
|
+
.mockImplementationOnce(() => initial.promise);
|
|
30
|
+
const view = render(
|
|
31
|
+
<Activity mode="visible">
|
|
32
|
+
<AsyncDataStatus fetch={fetch} />
|
|
33
|
+
</Activity>,
|
|
34
|
+
);
|
|
35
|
+
await act(async () => {
|
|
36
|
+
if (initialStatus === "success") {
|
|
37
|
+
initial.resolve("first");
|
|
38
|
+
} else {
|
|
39
|
+
initial.reject(new Error("offline"));
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
expect(view.getByRole("status").dataset.status).toBe(initialStatus);
|
|
43
|
+
|
|
44
|
+
view.rerender(
|
|
45
|
+
<Activity mode="hidden">
|
|
46
|
+
<AsyncDataStatus fetch={fetch} />
|
|
47
|
+
</Activity>,
|
|
48
|
+
);
|
|
49
|
+
view.rerender(
|
|
50
|
+
<Activity mode="visible">
|
|
51
|
+
<AsyncDataStatus fetch={fetch} />
|
|
52
|
+
</Activity>,
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
expect(fetch).toHaveBeenCalledTimes(2);
|
|
56
|
+
expect(view.getByRole("status").dataset).toMatchObject({
|
|
57
|
+
status: initialStatus === "success" ? "loading" : "pending",
|
|
58
|
+
error: "",
|
|
59
|
+
fetching: "true",
|
|
60
|
+
});
|
|
61
|
+
expect(view.getByRole("status").textContent).toBe(
|
|
62
|
+
initialStatus === "success" ? "first" : "",
|
|
63
|
+
);
|
|
64
|
+
await act(async () => restarted.resolve("latest"));
|
|
65
|
+
expect(view.getByRole("status").dataset).toMatchObject({
|
|
66
|
+
status: "success",
|
|
67
|
+
fetching: "false",
|
|
68
|
+
});
|
|
69
|
+
expect(view.getByRole("status").textContent).toBe("latest");
|
|
70
|
+
},
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
it("ignores a request canceled when Activity hides", async () => {
|
|
74
|
+
const canceled = new Deferred<string>();
|
|
75
|
+
const restarted = new Deferred<string>();
|
|
76
|
+
const fetch = vi
|
|
77
|
+
.fn(() => restarted.promise)
|
|
78
|
+
.mockImplementationOnce(() => canceled.promise);
|
|
79
|
+
const view = render(
|
|
80
|
+
<Activity mode="visible">
|
|
81
|
+
<AsyncDataStatus fetch={fetch} />
|
|
82
|
+
</Activity>,
|
|
83
|
+
);
|
|
84
|
+
view.rerender(
|
|
85
|
+
<Activity mode="hidden">
|
|
86
|
+
<AsyncDataStatus fetch={fetch} />
|
|
87
|
+
</Activity>,
|
|
88
|
+
);
|
|
89
|
+
view.rerender(
|
|
90
|
+
<Activity mode="visible">
|
|
91
|
+
<AsyncDataStatus fetch={fetch} />
|
|
92
|
+
</Activity>,
|
|
93
|
+
);
|
|
94
|
+
expect(fetch).toHaveBeenCalledTimes(2);
|
|
95
|
+
await act(async () => canceled.resolve("obsolete"));
|
|
96
|
+
expect(view.getByRole("status").dataset.status).toBe("pending");
|
|
97
|
+
expect(view.getByRole("status").textContent).toBe("");
|
|
98
|
+
await act(async () => restarted.resolve("latest"));
|
|
99
|
+
expect(view.getByRole("status").dataset.status).toBe("success");
|
|
100
|
+
expect(view.getByRole("status").textContent).toBe("latest");
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("preserves data while refetching and ignores obsolete requests", async () => {
|
|
104
|
+
const requests = [
|
|
105
|
+
new Deferred<string>(),
|
|
106
|
+
new Deferred<string>(),
|
|
107
|
+
new Deferred<string>(),
|
|
108
|
+
];
|
|
109
|
+
const fetch = vi
|
|
110
|
+
.fn(() => requests[0].promise)
|
|
111
|
+
.mockImplementationOnce(() => requests[0].promise)
|
|
112
|
+
.mockImplementationOnce(() => requests[1].promise)
|
|
113
|
+
.mockImplementationOnce(() => requests[2].promise);
|
|
114
|
+
const { result, rerender } = renderHook(
|
|
115
|
+
({ key }) => useAsyncData(fetch, [key]),
|
|
116
|
+
{ initialProps: { key: 0 } },
|
|
117
|
+
);
|
|
118
|
+
expect(result.current.status).toBe("pending");
|
|
119
|
+
await act(async () => requests[0].resolve("first"));
|
|
120
|
+
expect(result.current.data).toBe("first");
|
|
121
|
+
rerender({ key: 1 });
|
|
122
|
+
expect(result.current).toMatchObject({ status: "loading", data: "first" });
|
|
123
|
+
rerender({ key: 2 });
|
|
124
|
+
await act(async () => requests[1].resolve("obsolete"));
|
|
125
|
+
expect(result.current).toMatchObject({ status: "loading", data: "first" });
|
|
126
|
+
await act(async () => requests[2].resolve("latest"));
|
|
127
|
+
expect(result.current).toMatchObject({ status: "success", data: "latest" });
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("retries after errors and allows manual updates during a request", async () => {
|
|
131
|
+
const request = new Deferred<string>();
|
|
132
|
+
const fetch = vi
|
|
133
|
+
.fn<() => Promise<string>>()
|
|
134
|
+
.mockRejectedValueOnce(new Error("offline"))
|
|
135
|
+
.mockImplementation(() => request.promise);
|
|
136
|
+
const { result } = renderHook(() => useAsyncData(fetch, []));
|
|
137
|
+
await waitFor(() => expect(result.current.status).toBe("error"));
|
|
138
|
+
act(() => result.current.refetch());
|
|
139
|
+
expect(result.current.status).toBe("pending");
|
|
140
|
+
act(() => result.current.setData("manual"));
|
|
141
|
+
expect(result.current).toMatchObject({ status: "success", data: "manual" });
|
|
142
|
+
await act(async () => request.resolve("response"));
|
|
143
|
+
expect(result.current).toMatchObject({
|
|
144
|
+
status: "success",
|
|
145
|
+
data: "response",
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
});
|
|
@@ -322,7 +322,7 @@ export function useAsyncData<T>(
|
|
|
322
322
|
const [nonce, setNonce] = useState(0);
|
|
323
323
|
const [result, setResult] = useState<
|
|
324
324
|
PendingResult<T> | LoadingResult<T> | ErrorResult<T> | SuccessResult<T>
|
|
325
|
-
>(Result.pending());
|
|
325
|
+
>(() => Result.pending());
|
|
326
326
|
|
|
327
327
|
const asProps =
|
|
328
328
|
typeof loaderOrProps === "function"
|
|
@@ -339,12 +339,12 @@ export function useAsyncData<T>(
|
|
|
339
339
|
keepPrevious = true;
|
|
340
340
|
},
|
|
341
341
|
};
|
|
342
|
+
// Activity can restart this effect without changing dependencies, so
|
|
343
|
+
// loading state must follow the request lifecycle.
|
|
342
344
|
setResult((prevResult) => {
|
|
343
|
-
// If we have previous data, show reloading state
|
|
344
345
|
if (prevResult.status === "success" || prevResult.status === "loading") {
|
|
345
346
|
return Result.loading(prevResult.data);
|
|
346
347
|
}
|
|
347
|
-
// Otherwise, show initial loading state
|
|
348
348
|
return Result.pending();
|
|
349
349
|
});
|
|
350
350
|
fetchStable(context)
|
|
@@ -42,11 +42,13 @@ export function useDetectedDataSources(
|
|
|
42
42
|
dialects: [...connections.values()].map((connection) =>
|
|
43
43
|
connection.dialect.toLowerCase(),
|
|
44
44
|
),
|
|
45
|
-
storageProtocols:
|
|
46
|
-
namespace.protocol.toLowerCase(),
|
|
45
|
+
storageProtocols: new Set(
|
|
46
|
+
storageNamespaces.map((namespace) => namespace.protocol.toLowerCase()),
|
|
47
47
|
),
|
|
48
|
-
storageBackendTypes:
|
|
49
|
-
|
|
48
|
+
storageBackendTypes: new Set(
|
|
49
|
+
storageNamespaces.map((namespace) =>
|
|
50
|
+
namespace.backendType.toLowerCase(),
|
|
51
|
+
),
|
|
50
52
|
),
|
|
51
53
|
};
|
|
52
54
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
|
-
import { useEffect,
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
4
|
import { type Milliseconds, Time } from "@/utils/time";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Returns the elapsed time since mount, in milliseconds.
|
|
8
8
|
*/
|
|
9
9
|
export function useElapsedTime(initialStartTimeMs: Milliseconds) {
|
|
10
|
-
const startTime =
|
|
10
|
+
const [startTime] = useState(initialStartTimeMs);
|
|
11
11
|
const [endTime, setEndTime] = useState(initialStartTimeMs);
|
|
12
12
|
|
|
13
13
|
useEffect(() => {
|
|
@@ -21,5 +21,5 @@ export function useElapsedTime(initialStartTimeMs: Milliseconds) {
|
|
|
21
21
|
return () => clearInterval(interval);
|
|
22
22
|
}, []);
|
|
23
23
|
|
|
24
|
-
return endTime - startTime
|
|
24
|
+
return endTime - startTime;
|
|
25
25
|
}
|
|
@@ -104,7 +104,7 @@ function PluginSlotInternal<T>(
|
|
|
104
104
|
ref: React.Ref<PluginSlotHandle>,
|
|
105
105
|
): JSX.Element {
|
|
106
106
|
const [childNodes, setChildNodes] = useState<ReactNode>(children);
|
|
107
|
-
const [value, setValue] = useState<T>(getInitialValue
|
|
107
|
+
const [value, setValue] = useState<T>(getInitialValue);
|
|
108
108
|
const { theme } = useTheme();
|
|
109
109
|
|
|
110
110
|
const [parsedResult, setParsedResult] = useState(() => {
|
|
@@ -97,13 +97,9 @@ const Dropdown = (props: DropdownProps): JSX.Element => {
|
|
|
97
97
|
id={id}
|
|
98
98
|
disabled={disabled}
|
|
99
99
|
>
|
|
100
|
-
{allowSelectNone ?
|
|
101
|
-
<option value={EMPTY_VALUE} selected={value.length === 0}>
|
|
102
|
-
--
|
|
103
|
-
</option>
|
|
104
|
-
) : null}
|
|
100
|
+
{allowSelectNone ? <option value={EMPTY_VALUE}>--</option> : null}
|
|
105
101
|
{options.map((option) => (
|
|
106
|
-
<option value={option}
|
|
102
|
+
<option value={option} key={option}>
|
|
107
103
|
{option}
|
|
108
104
|
</option>
|
|
109
105
|
))}
|
|
@@ -212,7 +212,7 @@ const Form = ({
|
|
|
212
212
|
// wrapped plugin; this buffered value is in contrast to the actual
|
|
213
213
|
// value of the plugin, which is the value of the wrapped plugin when
|
|
214
214
|
// the submit button was last clicked/activated.
|
|
215
|
-
const [internalValue, setInternalValue] = useState<T>(
|
|
215
|
+
const [internalValue, setInternalValue] = useState<T>(() =>
|
|
216
216
|
UI_ELEMENT_REGISTRY.lookupValue(elementId),
|
|
217
217
|
);
|
|
218
218
|
|
|
@@ -53,14 +53,14 @@ const AnyLanguageCodeMirror: React.FC<
|
|
|
53
53
|
extensions?: readonly Extension[];
|
|
54
54
|
}
|
|
55
55
|
> = ({
|
|
56
|
-
language,
|
|
56
|
+
language: requestedLanguage,
|
|
57
57
|
hideUnsupportedLanguageErrors,
|
|
58
58
|
showCopyButton,
|
|
59
59
|
extensions = EMPTY_EXTENSIONS,
|
|
60
60
|
...props
|
|
61
61
|
}) => {
|
|
62
62
|
// Maybe normalize the language to the extension
|
|
63
|
-
language = LANGUAGE_MAP[
|
|
63
|
+
const language = LANGUAGE_MAP[requestedLanguage || ""] || requestedLanguage;
|
|
64
64
|
|
|
65
65
|
const isSupported = isSupportedLanguage(language);
|
|
66
66
|
if (!isSupported) {
|
|
@@ -73,12 +73,16 @@ export const GlideDataEditor = ({
|
|
|
73
73
|
});
|
|
74
74
|
|
|
75
75
|
const [columnWidths, setColumnWidths] = useState<Record<string, number>>({});
|
|
76
|
+
const editableColumnSet = useMemo(
|
|
77
|
+
() => (editableColumns === "all" ? null : new Set(editableColumns)),
|
|
78
|
+
[editableColumns],
|
|
79
|
+
);
|
|
76
80
|
|
|
77
81
|
const columns: ModifiedGridColumn[] = useMemo(() => {
|
|
78
82
|
const columns: ModifiedGridColumn[] = [];
|
|
79
83
|
for (const [columnName, fieldType] of columnFields) {
|
|
80
84
|
const editable =
|
|
81
|
-
|
|
85
|
+
editableColumnSet === null || editableColumnSet.has(columnName);
|
|
82
86
|
|
|
83
87
|
columns.push({
|
|
84
88
|
id: columnName,
|
|
@@ -100,7 +104,7 @@ export const GlideDataEditor = ({
|
|
|
100
104
|
}
|
|
101
105
|
|
|
102
106
|
return columns;
|
|
103
|
-
}, [columnFields, columnWidths,
|
|
107
|
+
}, [columnFields, columnWidths, editableColumnSet, theme]);
|
|
104
108
|
|
|
105
109
|
const getCellContent = useCallback(
|
|
106
110
|
(cell: Item): GridCell => {
|
|
@@ -110,8 +114,7 @@ export const GlideDataEditor = ({
|
|
|
110
114
|
const dataItem = dataRow[columns[col].title];
|
|
111
115
|
const columnKind = columns[col].kind;
|
|
112
116
|
const editable =
|
|
113
|
-
|
|
114
|
-
editableColumns.includes(columns[col].title);
|
|
117
|
+
editableColumnSet === null || editableColumnSet.has(columns[col].title);
|
|
115
118
|
|
|
116
119
|
if (columnKind === GridCellKind.Boolean) {
|
|
117
120
|
const value = Boolean(dataItem);
|
|
@@ -141,7 +144,7 @@ export const GlideDataEditor = ({
|
|
|
141
144
|
data: String(dataItem),
|
|
142
145
|
};
|
|
143
146
|
},
|
|
144
|
-
[columns, data,
|
|
147
|
+
[columns, data, editableColumnSet],
|
|
145
148
|
);
|
|
146
149
|
|
|
147
150
|
const onCellEdited = useCallback(
|
|
@@ -147,6 +147,8 @@ export function pasteCells(options: {
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
const edits: Edits["edits"] = [];
|
|
150
|
+
const editableColumnSet =
|
|
151
|
+
editableColumns === "all" ? null : new Set(editableColumns);
|
|
150
152
|
|
|
151
153
|
for (const [rowIndex, dataRow] of parsedData.entries()) {
|
|
152
154
|
if (!dataRow) {
|
|
@@ -175,7 +177,7 @@ export function pasteCells(options: {
|
|
|
175
177
|
const column = columns[targetColIdx];
|
|
176
178
|
const columnType = column.dataType;
|
|
177
179
|
const editable =
|
|
178
|
-
|
|
180
|
+
editableColumnSet === null || editableColumnSet.has(column.title);
|
|
179
181
|
|
|
180
182
|
if (!editable) {
|
|
181
183
|
continue;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import type { TopLevelSpec } from "vega-lite";
|
|
4
4
|
import type { NonNormalizedSpec } from "vega-lite/types_unstable/spec/index.js";
|
|
5
5
|
import type { TopLevelParameter } from "vega-lite/types_unstable/spec/toplevel.js";
|
|
6
|
+
import { Arrays } from "@/utils/arrays";
|
|
6
7
|
|
|
7
8
|
import { findEncodedFields, makeEncodingInteractive } from "./encodings";
|
|
8
9
|
import { Marks } from "./marks";
|
|
@@ -357,9 +358,7 @@ export function makeSelectable<T extends VegaLiteSpec>(
|
|
|
357
358
|
|
|
358
359
|
// If fieldSelection is an array, filter the fields
|
|
359
360
|
if (Array.isArray(fieldSelection)) {
|
|
360
|
-
legendFields =
|
|
361
|
-
fieldSelection.includes(field),
|
|
362
|
-
);
|
|
361
|
+
legendFields = Arrays.intersection(legendFields, fieldSelection);
|
|
363
362
|
}
|
|
364
363
|
}
|
|
365
364
|
|
|
@@ -420,9 +419,7 @@ function makeLegendSelectable(
|
|
|
420
419
|
let legendFields = findEncodedFields(spec);
|
|
421
420
|
// If fieldSelection is an array, we filter the fields
|
|
422
421
|
if (Array.isArray(fieldSelection)) {
|
|
423
|
-
legendFields =
|
|
424
|
-
fieldSelection.includes(field),
|
|
425
|
-
);
|
|
422
|
+
legendFields = Arrays.intersection(legendFields, fieldSelection);
|
|
426
423
|
}
|
|
427
424
|
|
|
428
425
|
const legendParams = legendFields.map((field) => Params.legend(field));
|
|
@@ -16,6 +16,41 @@ import {
|
|
|
16
16
|
} from "../arrays";
|
|
17
17
|
|
|
18
18
|
describe("arrays", () => {
|
|
19
|
+
describe.each([
|
|
20
|
+
["intersection", Arrays.intersection, [3, 3, 2], [Number.NaN]],
|
|
21
|
+
["difference", Arrays.difference, [1], [1]],
|
|
22
|
+
] as const)("%s", (_name, operation, expected, expectedWithNaN) => {
|
|
23
|
+
it("preserves order and duplicates without mutating readonly inputs", () => {
|
|
24
|
+
const values = Object.freeze([3, 1, 3, 2]);
|
|
25
|
+
const other = Object.freeze([2, 3, 3]);
|
|
26
|
+
expect(operation(values, other)).toEqual(expected);
|
|
27
|
+
expect(values).toEqual([3, 1, 3, 2]);
|
|
28
|
+
expect(other).toEqual([2, 3, 3]);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("uses the same equality as array membership, including NaN", () => {
|
|
32
|
+
expect(operation([Number.NaN, 1], [Number.NaN])).toEqual(expectedWithNaN);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("handles an empty source", () => {
|
|
36
|
+
expect(operation([], [1])).toEqual([]);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("handles empty membership lists", () => {
|
|
41
|
+
expect(Arrays.intersection([1, 1, 2], [])).toEqual([]);
|
|
42
|
+
expect(Arrays.difference([1, 1, 2], [])).toEqual([1, 1, 2]);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("compares objects by identity", () => {
|
|
46
|
+
const shared = { id: 1 };
|
|
47
|
+
const distinct = { id: 1 };
|
|
48
|
+
expect(Arrays.intersection([shared, distinct], [shared])).toEqual([shared]);
|
|
49
|
+
expect(Arrays.difference([shared, distinct], [shared])).toEqual([distinct]);
|
|
50
|
+
expect(Arrays.intersection([shared, distinct], [shared])[0]).toBe(shared);
|
|
51
|
+
expect(Arrays.difference([shared, distinct], [shared])[0]).toBe(distinct);
|
|
52
|
+
});
|
|
53
|
+
|
|
19
54
|
describe("arrayDelete", () => {
|
|
20
55
|
it("should delete an element at the specified index", () => {
|
|
21
56
|
expect(arrayDelete([1, 2, 3], 1)).toEqual([1, 3]);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { describe, expect, it, vi } from "vitest";
|
|
3
3
|
import {
|
|
4
4
|
countFractionDigits,
|
|
5
5
|
maxFractionDigitsForSteps,
|
|
@@ -20,6 +20,53 @@ describe("prettyNumber", () => {
|
|
|
20
20
|
|
|
21
21
|
const options = { locale };
|
|
22
22
|
|
|
23
|
+
describe("formatter reuse", () => {
|
|
24
|
+
it.each([
|
|
25
|
+
{
|
|
26
|
+
name: "scientific",
|
|
27
|
+
value: 0.000_123_4,
|
|
28
|
+
format: (value: number, locale: string) =>
|
|
29
|
+
prettyScientificNumber(value, { locale }),
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "rounded",
|
|
33
|
+
value: 1234.567,
|
|
34
|
+
format: (value: number, locale: string) =>
|
|
35
|
+
prettyScientificNumber(value, { locale, shouldRound: true }),
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: "engineering",
|
|
39
|
+
value: 12_345,
|
|
40
|
+
format: prettyEngineeringNumber,
|
|
41
|
+
},
|
|
42
|
+
])(
|
|
43
|
+
"reuses the $name formatter until the locale changes",
|
|
44
|
+
({ format, value }) => {
|
|
45
|
+
const NumberFormat = Intl.NumberFormat;
|
|
46
|
+
const constructor = vi
|
|
47
|
+
.spyOn(Intl, "NumberFormat")
|
|
48
|
+
.mockImplementation(function (locales, options) {
|
|
49
|
+
return new NumberFormat(locales, options);
|
|
50
|
+
});
|
|
51
|
+
try {
|
|
52
|
+
const first = format(value, "fr-FR");
|
|
53
|
+
expect(format(value, "fr-FR")).toBe(first);
|
|
54
|
+
format(value * 2, "fr-FR");
|
|
55
|
+
expect(constructor).toHaveBeenCalledTimes(1);
|
|
56
|
+
|
|
57
|
+
format(value, "de-DE");
|
|
58
|
+
expect(constructor).toHaveBeenCalledTimes(2);
|
|
59
|
+
expect(constructor).toHaveBeenLastCalledWith(
|
|
60
|
+
"de-DE",
|
|
61
|
+
expect.any(Object),
|
|
62
|
+
);
|
|
63
|
+
} finally {
|
|
64
|
+
constructor.mockRestore();
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
);
|
|
68
|
+
});
|
|
69
|
+
|
|
23
70
|
describe("prettyScientificNumber", () => {
|
|
24
71
|
it("should handle special cases", () => {
|
|
25
72
|
expect(prettyScientificNumber(0, options)).toBe("0");
|
|
@@ -204,6 +204,27 @@ describe("Objects", () => {
|
|
|
204
204
|
});
|
|
205
205
|
|
|
206
206
|
describe("filter", () => {
|
|
207
|
+
it.each([42, { base_url: "https://example.com" }])(
|
|
208
|
+
"preserves an own __proto__ property with value %j",
|
|
209
|
+
(value) => {
|
|
210
|
+
const obj = { ["__proto__"]: value, removed: value };
|
|
211
|
+
const result = Objects.filter(obj, (_, key) => key !== "removed");
|
|
212
|
+
|
|
213
|
+
expect(Object.entries(result)).toEqual([["__proto__", value]]);
|
|
214
|
+
expect(Object.getPrototypeOf(result)).toBe(Object.prototype);
|
|
215
|
+
expect(Object.getOwnPropertyDescriptor(result, "__proto__")).toEqual({
|
|
216
|
+
value,
|
|
217
|
+
writable: true,
|
|
218
|
+
enumerable: true,
|
|
219
|
+
configurable: true,
|
|
220
|
+
});
|
|
221
|
+
expect(Object.keys(obj)).toEqual(["__proto__", "removed"]);
|
|
222
|
+
expect(Objects.filter(obj, (_, key) => key !== "__proto__")).toEqual({
|
|
223
|
+
removed: value,
|
|
224
|
+
});
|
|
225
|
+
},
|
|
226
|
+
);
|
|
227
|
+
|
|
207
228
|
it("should filter object entries by predicate", () => {
|
|
208
229
|
const obj = { a: 1, b: 2, c: 3, d: 4 };
|
|
209
230
|
const result = Objects.filter(obj, (v) => v % 2 === 0);
|
package/src/utils/arrays.ts
CHANGED
|
@@ -55,6 +55,16 @@ export function arrayShallowEquals<T>(a: T[], b: T[]): boolean {
|
|
|
55
55
|
export const Arrays = {
|
|
56
56
|
// oxlint-disable-next-line typescript/no-explicit-any
|
|
57
57
|
EMPTY: [] as any,
|
|
58
|
+
/** Keep values present in both arrays, preserving the first array's order and duplicates. */
|
|
59
|
+
intersection<T>(values: readonly T[], included: readonly T[]): T[] {
|
|
60
|
+
const includedSet = new Set(included);
|
|
61
|
+
return values.filter((value) => includedSet.has(value));
|
|
62
|
+
},
|
|
63
|
+
/** Remove values present in the second array, preserving order and duplicates. */
|
|
64
|
+
difference<T>(values: readonly T[], excluded: readonly T[]): T[] {
|
|
65
|
+
const excludedSet = new Set(excluded);
|
|
66
|
+
return values.filter((value) => !excludedSet.has(value));
|
|
67
|
+
},
|
|
58
68
|
zip: <T, U>(a: T[], b: U[]): [T, U][] => {
|
|
59
69
|
invariant(a.length === b.length, "Arrays must be the same length");
|
|
60
70
|
return a.map((item, i) => [item, b[i]]);
|
package/src/utils/numbers.ts
CHANGED
|
@@ -23,6 +23,31 @@ export const maxFractionalDigits = memoizeLastValue((locale: string) => {
|
|
|
23
23
|
return 0;
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
+
const getScientificFormatter = memoizeLastValue(
|
|
27
|
+
(locale: string) =>
|
|
28
|
+
new Intl.NumberFormat(locale, {
|
|
29
|
+
minimumFractionDigits: 1,
|
|
30
|
+
maximumFractionDigits: 1,
|
|
31
|
+
notation: "scientific",
|
|
32
|
+
}),
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const getRoundedFormatter = memoizeLastValue(
|
|
36
|
+
(locale: string) =>
|
|
37
|
+
new Intl.NumberFormat(locale, {
|
|
38
|
+
minimumFractionDigits: 0,
|
|
39
|
+
maximumFractionDigits: 2,
|
|
40
|
+
}),
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const getEngineeringFormatter = memoizeLastValue(
|
|
44
|
+
(locale: string) =>
|
|
45
|
+
new Intl.NumberFormat(locale, {
|
|
46
|
+
notation: "engineering",
|
|
47
|
+
maximumSignificantDigits: 3,
|
|
48
|
+
}),
|
|
49
|
+
);
|
|
50
|
+
|
|
26
51
|
/** Decimal places needed to display `n` without float noise. */
|
|
27
52
|
export function countFractionDigits(n: number): number {
|
|
28
53
|
if (!Number.isFinite(n) || n === 0) {
|
|
@@ -108,23 +133,14 @@ export function prettyScientificNumber(
|
|
|
108
133
|
// Determine if the number should be in scientific notation
|
|
109
134
|
const absValue = Math.abs(value);
|
|
110
135
|
if (absValue < 1e-2 || absValue >= 1e6) {
|
|
111
|
-
return
|
|
112
|
-
minimumFractionDigits: 1,
|
|
113
|
-
maximumFractionDigits: 1,
|
|
114
|
-
notation: "scientific",
|
|
115
|
-
})
|
|
116
|
-
.format(value)
|
|
117
|
-
.toLowerCase();
|
|
136
|
+
return getScientificFormatter(opts.locale).format(value).toLowerCase();
|
|
118
137
|
}
|
|
119
138
|
|
|
120
139
|
const { shouldRound, locale } = opts;
|
|
121
140
|
|
|
122
141
|
if (shouldRound) {
|
|
123
142
|
// Number has an integer part, format with 2 decimal places
|
|
124
|
-
return
|
|
125
|
-
minimumFractionDigits: 0,
|
|
126
|
-
maximumFractionDigits: 2,
|
|
127
|
-
}).format(value);
|
|
143
|
+
return getRoundedFormatter(locale).format(value);
|
|
128
144
|
}
|
|
129
145
|
|
|
130
146
|
// Don't round
|
|
@@ -161,12 +177,7 @@ export function prettyEngineeringNumber(value: number, locale: string): string {
|
|
|
161
177
|
return specialCase;
|
|
162
178
|
}
|
|
163
179
|
|
|
164
|
-
const [mant, exp] =
|
|
165
|
-
notation: "engineering",
|
|
166
|
-
maximumSignificantDigits: 3,
|
|
167
|
-
})
|
|
168
|
-
.format(value)
|
|
169
|
-
.split("E");
|
|
180
|
+
const [mant, exp] = getEngineeringFormatter(locale).format(value).split("E");
|
|
170
181
|
|
|
171
182
|
if (exp in prefixes) {
|
|
172
183
|
return mant + prefixes[exp as keyof typeof prefixes];
|
package/src/utils/objects.ts
CHANGED
|
@@ -89,13 +89,9 @@ export const Objects = {
|
|
|
89
89
|
obj: Record<K, V>,
|
|
90
90
|
predicate: (value: V, key: K) => boolean,
|
|
91
91
|
): Record<K, V> {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
result[key] = obj[key];
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return result;
|
|
92
|
+
return Objects.fromEntries(
|
|
93
|
+
Objects.entries(obj).filter(([key, value]) => predicate(value, key)),
|
|
94
|
+
);
|
|
99
95
|
},
|
|
100
96
|
|
|
101
97
|
omit<V extends object, K extends keyof V>(
|