@marimo-team/islands 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/{ConnectedDataExplorerComponent-7EaP9VWb.js → ConnectedDataExplorerComponent-COS3f8io.js} +14 -14
- package/dist/{ErrorBoundary-CWOZCRt2.js → ErrorBoundary-C7__jAZL.js} +8 -8
- package/dist/{abnfDiagram-VCTEODGH-z_OSynK8.js → abnfDiagram-VCTEODGH-DQ4bKxYa.js} +2 -2
- package/dist/any-language-editor-DQItQSua.js +75 -0
- package/dist/{architectureDiagram-5GKGNRK7-Cs8J8BZr.js → architectureDiagram-5GKGNRK7-BA7-SI7Q.js} +1 -1
- package/dist/{arrays-CN1djC4k.js → arrays-R6JsImiT.js} +8 -0
- package/dist/{button-CvjkwdSk.js → button-BxB3RDjN.js} +1 -1
- package/dist/{capabilities-CQ5IjhzL.js → capabilities-BgR0osfN.js} +2 -2
- package/dist/{chat-ui-BeKQyQQI.js → chat-ui-DGpBSln7.js} +15 -15
- package/dist/{check-BMKBBrdc.js → check-C209OH-W.js} +1 -1
- package/dist/{chunk-IMKFNOWR-aoSFasqF.js → chunk-IMKFNOWR-DPY3kqOV.js} +1 -1
- package/dist/{chunk-SHT3W25Y-CMaybO3O.js → chunk-SHT3W25Y-C14Ikodf.js} +1 -1
- package/dist/{chunk-SVP7TREG-BNBrTAw1.js → chunk-SVP7TREG-BKu0HO4I.js} +1 -1
- package/dist/{chunk-TICWLB2K-DXNxvUJn.js → chunk-TICWLB2K-iJDDWGtE.js} +1 -1
- package/dist/{classDiagram-ZZMXUADV-DXdCCDOg.js → classDiagram-ZZMXUADV-HuJXQI0F.js} +2 -2
- package/dist/{classDiagram-v2-VYDZK3BY-DyZqrtLP.js → classDiagram-v2-VYDZK3BY-CpmmpTbC.js} +2 -2
- package/dist/{code-visibility-Bt5UEhes.js → code-visibility-DO4MlViW.js} +6 -6
- package/dist/{common-qCKxRBN9.js → common-Ci7TC3e0.js} +89 -87
- package/dist/{copy-icon-BgUO8jsi.js → copy-icon-L-mFk59e.js} +3 -3
- package/dist/{cynefinDiagram-5FMLGOSQ-DWHuKJs8.js → cynefinDiagram-5FMLGOSQ-uh0puAW2.js} +1 -1
- package/dist/{dagre-GXQ25YYZ-DYLu-OCU.js → dagre-GXQ25YYZ-4LBeAAMz.js} +1 -1
- package/dist/{data-grid-overlay-editor-Do-9e8zr.js → data-grid-overlay-editor-DpH_AKdC.js} +1 -1
- package/dist/{diagram-S7CK7UJ4-PwwcUOHP.js → diagram-S7CK7UJ4-BXPmZ2sX.js} +1 -1
- package/dist/{diagram-UQ7AKVKN-CvJbL_IM.js → diagram-UQ7AKVKN--Xz9UNpC.js} +1 -1
- package/dist/{diagram-VX7I27RA-B5RkqnzN.js → diagram-VX7I27RA-rt8VIRNT.js} +1 -1
- package/dist/{diagram-Z3DM3KII-CyijwTR2.js → diagram-Z3DM3KII-Cs1GqfDD.js} +1 -1
- package/dist/{dialog-Cc479ZEH.js → dialog-CDbPtWUD.js} +3 -3
- package/dist/{dropdown-menu-BuE2b8Yb.js → dropdown-menu-ugNoZmKx.js} +76 -76
- package/dist/{ebnfDiagram-PWID7BFC-DG90ELFp.js → ebnfDiagram-PWID7BFC-CgTsgbmZ.js} +2 -2
- package/dist/{erDiagram-RLTQ6QDP-FMo_SpyX.js → erDiagram-RLTQ6QDP-CFoADGzT.js} +1 -1
- package/dist/{error-banner-CFPHFw4h.js → error-banner-DMIrHA-R.js} +2 -2
- package/dist/{error-entries-CnqKxhU9.js → error-entries-D576fzV9.js} +18 -18
- package/dist/{feedback-button-_v2ibEJ2.js → feedback-button-BV5AJ3nl.js} +9 -9
- package/dist/{flowDiagram-HODETNUW-DQ4JuadE.js → flowDiagram-HODETNUW-BM2lvKuH.js} +2 -2
- package/dist/{formats-DRHUWwSK.js → formats-DIVMVjeV.js} +3 -3
- package/dist/{glide-data-editor-D0KMp00B.js → glide-data-editor-CRK-O0KE.js} +326 -324
- package/dist/{glide-utils-pisbYVjH.js → glide-utils-Q2ZsuA3h.js} +15 -15
- package/dist/{globals-BCavQNmT.js → globals-H_ILLmr7.js} +3 -3
- package/dist/{html-to-image-BsG_zyNW.js → html-to-image-D3m5Ob5H.js} +11 -11
- package/dist/{infoDiagram-27XIBGKW-CRSDtRrd.js → infoDiagram-27XIBGKW-Crwjiywp.js} +1 -1
- package/dist/{ishikawaDiagram-5VMMS53U-DxLEUldB.js → ishikawaDiagram-5VMMS53U-D4US2ShV.js} +1 -1
- package/dist/{kanban-definition-UXKFOSKX-BLhvu8o4.js → kanban-definition-UXKFOSKX-Bk097CUX.js} +1 -1
- package/dist/{label-DoysmLMW.js → label-CuEjBqYP.js} +2 -2
- package/dist/{loader-BPdQhmlq.js → loader-Bm8cy3e8.js} +3 -3
- package/dist/main.js +2009 -1959
- package/dist/{mermaid-Bjm6C1qN.js → mermaid-6EkeBlhr.js} +36 -36
- package/dist/{mindmap-definition-YA3MSWOX-g2LwxnYQ.js → mindmap-definition-YA3MSWOX-DmORzfXQ.js} +1 -1
- package/dist/{number-overlay-editor-BHxF9uGj.js → number-overlay-editor-BQ2UqdED.js} +1 -1
- package/dist/{objects-CzUgoMIF.js → objects-DCmMvZtn.js} +1 -3
- package/dist/{once-BtE-wKRL.js → once-eG8Vmvjd.js} +1 -1
- package/dist/{pegDiagram-XKGWAZYB-CpMAt3Qs.js → pegDiagram-XKGWAZYB-DT5TL02S.js} +2 -2
- package/dist/{pieDiagram-E7YTZNPT-CVTthoZo.js → pieDiagram-E7YTZNPT-B1NwGcuH.js} +1 -1
- package/dist/{process-output-DgQrilBD.js → process-output-C6qc7hPS.js} +4 -4
- package/dist/{railroadDiagram-O6MQD6OU-ao8cqqFB.js → railroadDiagram-O6MQD6OU-BxoycdEu.js} +2 -2
- package/dist/{react-vega-BDpbvBCb.js → react-vega-C4T9Rb_w.js} +1 -1
- package/dist/{requirementDiagram-BXWQKSXE--J8vyfm-.js → requirementDiagram-BXWQKSXE-DHq_eRrm.js} +1 -1
- package/dist/{reveal-component-DNMX2D3g.js → reveal-component-Cs-0GwxY.js} +10 -10
- package/dist/{select-DemoKT4G.js → select-D2iqeJYk.js} +4 -4
- package/dist/{sequenceDiagram-WJ2MYXX4-CiQbn62x.js → sequenceDiagram-WJ2MYXX4-Ba11BAOu.js} +1 -1
- package/dist/{spec-D_u2ipzF.js → spec-BCCcvWPS.js} +4 -4
- package/dist/{stateDiagram-D77RDMKH-DVEeGs5b.js → stateDiagram-D77RDMKH-OHQbvkbP.js} +2 -2
- package/dist/{stateDiagram-v2-MP3YSRHH-1OQRe6iA.js → stateDiagram-v2-MP3YSRHH-BlIquvFJ.js} +2 -2
- package/dist/style.css +1 -1
- package/dist/{swimlanes-42K2YHIH-CqkGoGqn.js → swimlanes-42K2YHIH-DSlitS4s.js} +1 -1
- package/dist/{swimlanesDiagram-VR7AAH4N-CszjkrKo.js → swimlanesDiagram-VR7AAH4N-ClwuzFNO.js} +2 -2
- package/dist/{swiper-component-DKntyn8p.js → swiper-component-DfhRvAFi.js} +2 -2
- package/dist/{timeline-definition-24CTP7MA-DLRUNVAx.js → timeline-definition-24CTP7MA-hAzc5VkT.js} +1 -1
- package/dist/{toDate-gyi35XS2.js → toDate-CSY-j1Fi.js} +24 -24
- package/dist/{toast-PkdZraM8.js → toast-DxVfYlCp.js} +4 -4
- package/dist/{tooltip-CtBZ5q8p.js → tooltip-BCntm-jf.js} +2 -2
- package/dist/{use-restore-focus-CKjfFjLM.js → use-restore-focus-BhXhsNLV.js} +1 -1
- package/dist/{useAsyncData-BneN349z.js → useAsyncData-BbuzBAUp.js} +15 -14
- package/dist/{useDateFormatter-DkajGwwd.js → useDateFormatter-6AHbIR-J.js} +2 -2
- package/dist/{useDeepCompareMemoize-Z_7R8wTt.js → useDeepCompareMemoize-da5A3c-Y.js} +1 -1
- package/dist/{useIframeCapabilities-DBETvvPl.js → useIframeCapabilities-BkdeVdXC.js} +1 -1
- package/dist/{useLifecycle-Dfq8UD-b.js → useLifecycle-C3nT1kwI.js} +3 -3
- package/dist/{useTheme-Bu5bBgrh.js → useTheme-BC8Lof0B.js} +2 -2
- package/dist/{vega-component-1lFfDE_8.js → vega-component-Df45z17m.js} +147 -147
- package/dist/{vega-embed-container-BgKnsDbB.js → vega-embed-container--LYZqguO.js} +2 -2
- package/dist/{vega-loader.browser-CpbZAXub.js → vega-loader.browser-B9Pz0EGP.js} +1 -1
- package/dist/{vennDiagram-4TSXK5OY-CypgoBVZ.js → vennDiagram-4TSXK5OY-CINKaJgr.js} +1 -1
- package/dist/{wardleyDiagram-VM6X3IG4-B6xjiQ_g.js → wardleyDiagram-VM6X3IG4-KG2tlXg_.js} +1 -1
- package/dist/{xychartDiagram-S5SC5T6Z-e0PefDVs.js → xychartDiagram-S5SC5T6Z-XIH5cwgI.js} +1 -1
- 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/any-language-editor-D4q-IFcM.js +0 -76
|
@@ -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>(
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import "./rolldown-runtime-Cb76FRpK.js";
|
|
2
|
-
import { g as e } from "./button-CvjkwdSk.js";
|
|
3
|
-
import { t } from "./react-sHtZdjeP.js";
|
|
4
|
-
import { t as n } from "./compiler-runtime-CldRdSsv.js";
|
|
5
|
-
import { t as r } from "./copy-icon-BgUO8jsi.js";
|
|
6
|
-
import { t as i } from "./jsx-runtime-3BD1kT0s.js";
|
|
7
|
-
import { n as a } from "./error-banner-CFPHFw4h.js";
|
|
8
|
-
import { t as o } from "./esm-AMFssoNp.js";
|
|
9
|
-
import { n as s, t as c } from "./esm-D2gTsXEV.js";
|
|
10
|
-
//#region src/plugins/impl/code/any-language-editor.tsx
|
|
11
|
-
var l = n();
|
|
12
|
-
t();
|
|
13
|
-
var u = i(), d = {
|
|
14
|
-
python: "py",
|
|
15
|
-
python3: "py",
|
|
16
|
-
javascript: "js",
|
|
17
|
-
typescript: "ts",
|
|
18
|
-
shell: "sh",
|
|
19
|
-
bash: "sh",
|
|
20
|
-
unknown: "text",
|
|
21
|
-
undefined: "text"
|
|
22
|
-
}, f = [];
|
|
23
|
-
function p(e) {
|
|
24
|
-
return e ? e in c : !1;
|
|
25
|
-
}
|
|
26
|
-
var m = (t) => {
|
|
27
|
-
let n = (0, l.c)(29), i, m, h, g, _, v;
|
|
28
|
-
if (n[0] !== t) {
|
|
29
|
-
let { language: e, hideUnsupportedLanguageErrors: r, showCopyButton: a, extensions: o, ...s } = t;
|
|
30
|
-
m = r, _ = a, g = s, h = e, i = o === void 0 ? f : o, h = d[h || ""] || h, v = p(h), n[0] = t, n[1] = i, n[2] = m, n[3] = h, n[4] = g, n[5] = _, n[6] = v;
|
|
31
|
-
} else i = n[1], m = n[2], h = n[3], g = n[4], _ = n[5], v = n[6];
|
|
32
|
-
let y = v;
|
|
33
|
-
y || e.warn(`Language ${h} not found in CodeMirror.`);
|
|
34
|
-
let b;
|
|
35
|
-
bb0: {
|
|
36
|
-
if (!p(h)) {
|
|
37
|
-
b = i;
|
|
38
|
-
break bb0;
|
|
39
|
-
}
|
|
40
|
-
let e;
|
|
41
|
-
n[7] === h ? e = n[8] : (e = s(h), n[7] = h, n[8] = e);
|
|
42
|
-
let t;
|
|
43
|
-
n[9] !== i || n[10] !== e ? (t = [e, ...i].filter(Boolean), n[9] = i, n[10] = e, n[11] = t) : t = n[11], b = t;
|
|
44
|
-
}
|
|
45
|
-
let x = b, S;
|
|
46
|
-
n[12] !== m || n[13] !== y || n[14] !== h ? (S = !y && !m && /* @__PURE__ */ (0, u.jsx)(a, {
|
|
47
|
-
className: "mb-1 rounded-sm",
|
|
48
|
-
error: `Language ${h} not supported. Supported languages are: ${Object.keys(c).join(", ")}`
|
|
49
|
-
}), n[12] = m, n[13] = y, n[14] = h, n[15] = S) : S = n[15];
|
|
50
|
-
let C;
|
|
51
|
-
n[16] !== y || n[17] !== g || n[18] !== _ ? (C = _ && y && /* @__PURE__ */ (0, u.jsx)(r, {
|
|
52
|
-
tooltip: !1,
|
|
53
|
-
buttonClassName: "absolute top-2 right-2 z-10 hover-action",
|
|
54
|
-
className: "h-4 w-4 text-muted-foreground",
|
|
55
|
-
value: g.value || "",
|
|
56
|
-
toastTitle: "Copied to clipboard"
|
|
57
|
-
}), n[16] = y, n[17] = g, n[18] = _, n[19] = C) : C = n[19];
|
|
58
|
-
let w;
|
|
59
|
-
n[20] === x ? w = n[21] : (w = [...x], n[20] = x, n[21] = w);
|
|
60
|
-
let T;
|
|
61
|
-
n[22] !== g || n[23] !== w ? (T = /* @__PURE__ */ (0, u.jsx)(o, {
|
|
62
|
-
...g,
|
|
63
|
-
extensions: w
|
|
64
|
-
}), n[22] = g, n[23] = w, n[24] = T) : T = n[24];
|
|
65
|
-
let E;
|
|
66
|
-
return n[25] !== S || n[26] !== C || n[27] !== T ? (E = /* @__PURE__ */ (0, u.jsxs)("div", {
|
|
67
|
-
className: "relative w-full group hover-actions-parent",
|
|
68
|
-
children: [
|
|
69
|
-
S,
|
|
70
|
-
C,
|
|
71
|
-
T
|
|
72
|
-
]
|
|
73
|
-
}), n[25] = S, n[26] = C, n[27] = T, n[28] = E) : E = n[28], E;
|
|
74
|
-
};
|
|
75
|
-
//#endregion
|
|
76
|
-
export { d as LANGUAGE_MAP, m as default };
|