@marimo-team/frontend 0.25.2 → 0.25.3-dev10
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-BP2mavAq.js → CellStatus-nZpuDkm7.js} +1 -1
- package/dist/assets/{ErrorBoundary-Gl5nCA8C.js → ErrorBoundary-B4n9EnHB.js} +2 -2
- package/dist/assets/JsonOutput-BxB0NL8w.js +11 -0
- package/dist/assets/MarimoErrorOutput-BTy4MOzX.js +10 -0
- package/dist/assets/{RenderHTML-BbOqmHy3.js → RenderHTML-9bMgbYmo.js} +1 -1
- package/dist/assets/{RunButton-CK3LhnP5.js → RunButton-CFQUNN5c.js} +1 -1
- package/dist/assets/{add-cell-with-ai-8UBC0xwR.js → add-cell-with-ai-f_MnLCwI.js} +9 -9
- package/dist/assets/{add-connection-dialog-DXQnd6eB.js → add-connection-dialog-CoE_PhuD.js} +1 -1
- package/dist/assets/{agent-panel-D7kMZLG-.js → agent-panel-BWZz24jK.js} +5 -5
- package/dist/assets/ai-model-dropdown-zm-2fXzf.js +13 -0
- package/dist/assets/{app-config-button-BKEG4x9u.js → app-config-button-BhU0ulYs.js} +1 -1
- package/dist/assets/{blob-D5nfNHOo.js → blob-iOBwGaP9.js} +1 -1
- package/dist/assets/{cell-editor-ADVfycpN.js → cell-editor-CAj1UKxx.js} +9 -9
- package/dist/assets/{cell-link-LSth_8hT.js → cell-link-1CynTVGQ.js} +1 -1
- package/dist/assets/{cells-BRkCaSsh.js → cells-rA_jsZCj.js} +1 -1
- package/dist/assets/{chat-display-Dnagy4Nv.js → chat-display-BmEPmhDP.js} +1 -1
- package/dist/assets/{chat-panel-DQ6HkWEF.js → chat-panel-Ce2Xh7dM.js} +2 -2
- package/dist/assets/{chat-ui-Df8Vcj6n.js → chat-ui-DTy98rP3.js} +1 -1
- package/dist/assets/{column-preview-Cm2D6vyX.js → column-preview-DU6dT80y.js} +1 -1
- package/dist/assets/{command-palette-DTSQ7gOC.js → command-palette-BMqFKXVr.js} +1 -1
- package/dist/assets/{common-Cu6CDbuw.js → common-lisZ0l6a.js} +1 -1
- package/dist/assets/{components-CGw16R_N.js → components-Dvd1GnD6.js} +1 -1
- package/dist/assets/config-DJLAC21v.js +1 -0
- package/dist/assets/{datasource-Cq6x_5ML.js → datasource-Dr1xNKUn.js} +1 -1
- package/dist/assets/{dates-BbFQ2oE4.js → dates-CfmdTL6B.js} +1 -1
- package/dist/assets/{dependency-graph-panel--Kgtktcw.js → dependency-graph-panel-B0uP-_id.js} +1 -1
- package/dist/assets/{documentation-panel-BHmbeznw.js → documentation-panel-DVl_ebWy.js} +1 -1
- package/dist/assets/{download-DCJXy66H.js → download-Bx55LMki.js} +1 -1
- package/dist/assets/edit-page-DlfCLUaq.js +9 -0
- package/dist/assets/{error-entries-Dk3VZ-OK.js → error-entries-DOWpdGvI.js} +1 -1
- package/dist/assets/{error-panel-BPRYmC5J.js → error-panel-DpbNKSLs.js} +1 -1
- package/dist/assets/{feedback-button-Bik2-e33.js → feedback-button-B99ThNJW.js} +1 -1
- package/dist/assets/feedback-button-DlqZkJwz.js +1 -0
- package/dist/assets/{file-explorer-panel-BEEK5lcl.js → file-explorer-panel-Bo9eN3rW.js} +1 -1
- package/dist/assets/{file-name-input-Cdc-TVqO.js → file-name-input-ChnBsDE_.js} +1 -1
- package/dist/assets/{floating-outline-XD9FAV-f.js → floating-outline-MYqQW4Vp.js} +1 -1
- package/dist/assets/{gallery-page-Dm6mGwBi.js → gallery-page-DSL0J4md.js} +1 -1
- package/dist/assets/{glide-data-editor-J9CAb70d.js → glide-data-editor-B1MWlKeM.js} +1 -1
- package/dist/assets/{home-page-DMHnsRxm.js → home-page-KrhQ55Vg.js} +1 -1
- package/dist/assets/{hooks-93IwHd2u.js → hooks-BIogTGCr.js} +1 -1
- package/dist/assets/index-6b4mf8Ai.css +2 -0
- package/dist/assets/{index-s-M1OXjs.js → index-B3fcrmuf.js} +8 -7
- package/dist/assets/{layout-DmcNEu3P.js → layout-DOpdUwym.js} +3 -3
- package/dist/assets/{logs-panel-ABM16htT.js → logs-panel-y0XnfulJ.js} +1 -1
- package/dist/assets/{markdown-renderer-BG3sp2rs.js → markdown-renderer-Q5AhbRU3.js} +1 -1
- package/dist/assets/{name-cell-input-BgEBmqyL.js → name-cell-input-BNOnF6-0.js} +1 -1
- package/dist/assets/{outline-panel-DCXQ3_F6.js → outline-panel-Be7stWwv.js} +1 -1
- package/dist/assets/{packages-panel-BMGOmZkR.js → packages-panel-ClxOAEGy.js} +1 -1
- package/dist/assets/{panel-accordion-state-C1sdPp0m.js → panel-accordion-state-GeMEdCPw.js} +1 -1
- package/dist/assets/panels-DfCmzLtT.js +4 -0
- package/dist/assets/{process-output-D0KGq04R.js → process-output-DNFKMODr.js} +1 -1
- package/dist/assets/{readonly-code-display-Do50PHI8.js → readonly-code-display-YULOXf4h.js} +1 -1
- package/dist/assets/{readonly-python-code-DCSMIsTX.js → readonly-python-code-CadgXgRu.js} +1 -1
- package/dist/assets/{reveal-component-ltaepAqw.js → reveal-component-BVAR7ayZ.js} +1 -1
- package/dist/assets/{run-page-DF3c5cDk.js → run-page-Cxu1yV8Q.js} +1 -1
- package/dist/assets/{runtime-details-state-CSPobEdR.js → runtime-details-state-DuChzsA6.js} +1 -1
- package/dist/assets/{scratchpad-panel-Dwd6W5PE.js → scratchpad-panel-By-ybhjg.js} +1 -1
- package/dist/assets/session-panel-BmW6PH4z.js +1 -0
- package/dist/assets/{snippets-panel-Bh1oTw4m.js → snippets-panel-CQ1dn3lA.js} +1 -1
- package/dist/assets/{state-XsPO8hNi.js → state-Bfh_2SLl.js} +1 -1
- package/dist/assets/state-z3dlofZB.js +3 -0
- package/dist/assets/{tracing-Di6pUmX8.js → tracing-BARlJ_Dk.js} +1 -1
- package/dist/assets/{tracing-panel-PeRXHD8_.js → tracing-panel-dgnr2fIN.js} +2 -2
- package/dist/assets/{tree-actions-GM5E_bUs.js → tree-actions-DAd80MbP.js} +1 -1
- package/dist/assets/{useAddCell-GR7eEQrT.js → useAddCell-DGstJK0S.js} +1 -1
- package/dist/assets/{useCellActionButton-B-9eG5z_.js → useCellActionButton-DY9RlJTb.js} +1 -1
- package/dist/assets/{useDeleteCell-2_bMClHd.js → useDeleteCell-DFBGlSQk.js} +1 -1
- package/dist/assets/{useDependencyPanelTab-k3C3M18S.js → useDependencyPanelTab-DydxsE5d.js} +1 -1
- package/dist/assets/{useNotebookActions-NHN6A-cN.js → useNotebookActions-DfvB7RD_.js} +1 -1
- package/dist/assets/{useRunCells-B2vUhREg.js → useRunCells-BFjFX3hz.js} +1 -1
- package/dist/assets/{useSplitCell-DEb03htp.js → useSplitCell-Tqv5pPtL.js} +1 -1
- package/dist/index.html +24 -25
- package/package.json +5 -2
- package/src/__tests__/fixtures/{pair-preview.ts → pair-config.ts} +3 -2
- package/src/__tests__/host-imports.test.ts +100 -0
- package/src/__tests__/mount.test.ts +8 -8
- package/src/components/data-table/__tests__/context-menu.test.ts +176 -0
- package/src/components/data-table/__tests__/date-filter-inputs.test.tsx +24 -1
- package/src/components/data-table/__tests__/export-actions.test.tsx +329 -6
- package/src/components/data-table/context-menu.tsx +125 -26
- package/src/components/data-table/date-filter-inputs.tsx +15 -42
- package/src/components/data-table/export-actions.tsx +192 -116
- package/src/components/data-table/schemas.ts +14 -36
- package/src/components/data-table/utils.ts +18 -0
- package/src/components/editor/Output.tsx +9 -2
- package/src/components/editor/actions/__tests__/pair-with-agent-commands.test.ts +80 -252
- package/src/components/editor/actions/__tests__/pair-with-agent-modal.test.tsx +186 -34
- package/src/components/editor/actions/pair-with-agent-commands.ts +42 -51
- package/src/components/editor/actions/pair-with-agent-modal.tsx +96 -36
- package/src/components/editor/chrome/panels/error-panel.tsx +1 -0
- package/src/components/editor/chrome/wrapper/__tests__/attachment-status.test.tsx +372 -0
- package/src/components/editor/chrome/wrapper/footer-item.tsx +32 -24
- package/src/components/editor/chrome/wrapper/footer-items/attachment-status.tsx +237 -0
- package/src/components/editor/chrome/wrapper/footer.tsx +2 -0
- package/src/components/editor/errors/__tests__/send-error-report-button.test.tsx +548 -0
- package/src/components/editor/errors/send-error-report-button.tsx +69 -0
- package/src/components/editor/output/MarimoErrorOutput.tsx +21 -5
- package/src/components/editor/output/MarimoTracebackOutput.tsx +35 -20
- package/src/components/editor/output/__tests__/ansi-reduce.test.ts +18 -0
- package/src/components/editor/output/ansi-reduce.ts +6 -0
- package/src/core/attachments/__tests__/toast.test.tsx +58 -0
- package/src/core/attachments/state.ts +21 -0
- package/src/core/attachments/toast.ts +15 -0
- package/src/core/cells/__tests__/cells.test.ts +52 -0
- package/src/core/cells/__tests__/error-report.test.ts +139 -0
- package/src/core/cells/__tests__/session.test.ts +50 -1
- package/src/core/cells/error-report.ts +63 -0
- package/src/core/cells/session.ts +28 -1
- package/src/core/config/pair.ts +5 -3
- package/src/core/host/AGENTS.md +6 -0
- package/src/core/host/__tests__/protocol.test.ts +214 -0
- package/src/core/host/protocol.ts +1943 -0
- package/src/core/islands/__tests__/bootstrap.test.ts +26 -0
- package/src/core/islands/bootstrap.ts +1 -0
- package/src/core/websocket/__tests__/useMarimoKernelConnection.hook.test.tsx +193 -0
- package/src/core/websocket/useMarimoKernelConnection.tsx +9 -0
- package/src/mount.tsx +3 -3
- package/src/plugins/impl/__tests__/DataTablePlugin.test.tsx +84 -0
- package/src/utils/__tests__/dates.test.ts +116 -0
- package/src/utils/dates.ts +94 -0
- package/dist/assets/JsonOutput-D6HIIsCb.js +0 -11
- package/dist/assets/MarimoErrorOutput-D60XkCny.js +0 -6
- package/dist/assets/ai-model-dropdown-B0z6-zhp.js +0 -5
- package/dist/assets/api-BeC_VSGv.js +0 -1
- package/dist/assets/config-BOKzA3tF.js +0 -1
- package/dist/assets/edit-page-ChcSgpke.js +0 -9
- package/dist/assets/feedback-button-B2gKC5cn.js +0 -1
- package/dist/assets/index-Bcdzex-3.css +0 -2
- package/dist/assets/pair-CaQyK6En.js +0 -1
- package/dist/assets/panels-CxVG8-v2.js +0 -4
- package/dist/assets/session-panel-VdDhEBa-.js +0 -1
- package/dist/assets/state-_Qai_QyX.js +0 -3
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
import { createStore } from "jotai";
|
|
4
4
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
5
5
|
import { RuntimeState } from "@/core/kernel/RuntimeState";
|
|
6
|
+
import { attachmentsAtom } from "@/core/attachments/state";
|
|
7
|
+
import { Logger } from "@/utils/Logger";
|
|
6
8
|
import { initializeIslands } from "../bootstrap";
|
|
7
9
|
import type { IslandsPyodideBridge } from "../bridge";
|
|
8
10
|
import { islandsHydratedAtom, islandsPendingInitialRunsAtom } from "../state";
|
|
@@ -48,6 +50,30 @@ describe("initializeIslands", () => {
|
|
|
48
50
|
expect(store.get(islandsHydratedAtom)).toBe(false);
|
|
49
51
|
store.set(islandsPendingInitialRunsAtom, new Set([1, 2]));
|
|
50
52
|
|
|
53
|
+
const errors = vi.spyOn(Logger, "error");
|
|
54
|
+
consumeMessage?.({
|
|
55
|
+
sessionGeneration: 1,
|
|
56
|
+
message: JSON.stringify({
|
|
57
|
+
op: "attachments",
|
|
58
|
+
data: {
|
|
59
|
+
op: "attachments",
|
|
60
|
+
attachments: [
|
|
61
|
+
{
|
|
62
|
+
id: "a1",
|
|
63
|
+
kind: "agent",
|
|
64
|
+
name: "Pi",
|
|
65
|
+
since: "2026-10-14T00:00:00Z",
|
|
66
|
+
notebook_id: "nb-test",
|
|
67
|
+
identity: "pi-thread",
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
}) as IslandsKernelMessage["message"],
|
|
72
|
+
});
|
|
73
|
+
expect(errors).not.toHaveBeenCalled();
|
|
74
|
+
expect(store.get(attachmentsAtom)).toEqual([]);
|
|
75
|
+
expect(store.get(islandsPendingInitialRunsAtom)).toEqual(new Set([1, 2]));
|
|
76
|
+
|
|
51
77
|
consumeMessage?.(completedRun(1));
|
|
52
78
|
expect(store.get(islandsHydratedAtom)).toBe(false);
|
|
53
79
|
|
|
@@ -43,6 +43,11 @@ vi.mock("@/core/runtime/config", async () => {
|
|
|
43
43
|
import { MockNotebook } from "@/__mocks__/notebook";
|
|
44
44
|
import { cellId } from "@/__tests__/branded";
|
|
45
45
|
import { alertAtom, getPackageAlert } from "@/core/alerts/state";
|
|
46
|
+
import {
|
|
47
|
+
type Attachment,
|
|
48
|
+
attachmentsAtom,
|
|
49
|
+
agentAttachmentsAtom,
|
|
50
|
+
} from "@/core/attachments/state";
|
|
46
51
|
import { notebookAtom } from "@/core/cells/cells";
|
|
47
52
|
import { AppConfigSchema } from "@/core/config/config-schema";
|
|
48
53
|
import { ConnectionNotice } from "@/components/editor/alerts/connection-notice";
|
|
@@ -184,6 +189,46 @@ describe("useMarimoKernelConnection.reconnect()", () => {
|
|
|
184
189
|
});
|
|
185
190
|
|
|
186
191
|
describe("useMarimoKernelConnection messages", () => {
|
|
192
|
+
it("replaces attachment snapshots, including the last detach", () => {
|
|
193
|
+
const store = createStore();
|
|
194
|
+
vi.mocked(useConnectionTransport).mockReturnValue(
|
|
195
|
+
makeTransport(WebSocket.OPEN),
|
|
196
|
+
);
|
|
197
|
+
vi.mocked(useRuntimeManager).mockReturnValue(
|
|
198
|
+
makeRuntimeManager() as unknown as ReturnType<typeof useRuntimeManager>,
|
|
199
|
+
);
|
|
200
|
+
renderConnectionHook(store);
|
|
201
|
+
const options = vi.mocked(useConnectionTransport).mock.calls.at(-1)![0];
|
|
202
|
+
const agent: Attachment = {
|
|
203
|
+
id: "a1",
|
|
204
|
+
kind: "agent",
|
|
205
|
+
name: "Pi",
|
|
206
|
+
since: "2026-10-14T00:00:00Z",
|
|
207
|
+
notebook_id: "nb-test",
|
|
208
|
+
identity: "pi-thread",
|
|
209
|
+
};
|
|
210
|
+
const client: Attachment = {
|
|
211
|
+
id: "c1",
|
|
212
|
+
kind: "client",
|
|
213
|
+
name: null,
|
|
214
|
+
since: "2026-10-14T00:00:01Z",
|
|
215
|
+
notebook_id: "nb-test",
|
|
216
|
+
};
|
|
217
|
+
for (const attachments of [[agent, client], [client], []]) {
|
|
218
|
+
act(() =>
|
|
219
|
+
options.onMessage(
|
|
220
|
+
new MessageEvent("message", {
|
|
221
|
+
data: JSON.stringify({
|
|
222
|
+
op: "attachments",
|
|
223
|
+
data: { op: "attachments", attachments },
|
|
224
|
+
}),
|
|
225
|
+
}),
|
|
226
|
+
),
|
|
227
|
+
);
|
|
228
|
+
expect(store.get(attachmentsAtom)).toEqual(attachments);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
|
|
187
232
|
it("records completion of the initial run", () => {
|
|
188
233
|
const store = createStore();
|
|
189
234
|
vi.mocked(useConnectionTransport).mockClear();
|
|
@@ -211,6 +256,101 @@ describe("useMarimoKernelConnection messages", () => {
|
|
|
211
256
|
});
|
|
212
257
|
});
|
|
213
258
|
|
|
259
|
+
describe("attachment snapshots across browser connections", () => {
|
|
260
|
+
const agent: Attachment = {
|
|
261
|
+
id: "a1",
|
|
262
|
+
kind: "agent",
|
|
263
|
+
name: "Pi",
|
|
264
|
+
since: "2026-10-14T00:00:00Z",
|
|
265
|
+
notebook_id: "nb-test",
|
|
266
|
+
identity: "pi-thread",
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
function connectedSession() {
|
|
270
|
+
const store = createStore();
|
|
271
|
+
store.set(connectionAtom, { state: ConnectionState.OPEN });
|
|
272
|
+
store.set(attachmentsAtom, [agent]);
|
|
273
|
+
const transport = makeTransport(WebSocket.OPEN);
|
|
274
|
+
vi.mocked(useConnectionTransport).mockReturnValue(transport);
|
|
275
|
+
vi.mocked(useRuntimeManager).mockReturnValue(
|
|
276
|
+
makeRuntimeManager() as unknown as ReturnType<typeof useRuntimeManager>,
|
|
277
|
+
);
|
|
278
|
+
renderConnectionHook(store);
|
|
279
|
+
const options = vi.mocked(useConnectionTransport).mock.calls.at(-1)![0];
|
|
280
|
+
const receive = (data: NotificationPayload["data"]) =>
|
|
281
|
+
act(() => {
|
|
282
|
+
options.onMessage(
|
|
283
|
+
new MessageEvent("message", {
|
|
284
|
+
data: JSON.stringify({ op: data.op, data }),
|
|
285
|
+
}),
|
|
286
|
+
);
|
|
287
|
+
});
|
|
288
|
+
return { store, transport, options, receive };
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
it.each([
|
|
292
|
+
"MARIMO_NO_FILE_KEY",
|
|
293
|
+
"MARIMO_NO_SESSION_ID",
|
|
294
|
+
"MARIMO_NO_SESSION",
|
|
295
|
+
"MARIMO_SHUTDOWN",
|
|
296
|
+
"MARIMO_KERNEL_STARTUP_ERROR",
|
|
297
|
+
"MARIMO_UNAUTHORIZED",
|
|
298
|
+
"MARIMO_KIOSK_NOT_ALLOWED",
|
|
299
|
+
"MARIMO_TRANSPORT_EXHAUSTED",
|
|
300
|
+
])("clears cached attachments on %s", (reason) => {
|
|
301
|
+
const { store, transport, options } = connectedSession();
|
|
302
|
+
act(() => options.onClose(new CloseEvent("close", { reason })));
|
|
303
|
+
expect(store.get(attachmentsAtom)).toEqual([]);
|
|
304
|
+
expect(store.get(agentAttachmentsAtom)).toEqual([]);
|
|
305
|
+
expect(store.get(connectionAtom).state).toBe(ConnectionState.CLOSED);
|
|
306
|
+
expect(transport.reconnect).not.toHaveBeenCalled();
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it("clears the snapshot on transport error", () => {
|
|
310
|
+
const { store, options } = connectedSession();
|
|
311
|
+
act(() => options.onError(new Event("error")));
|
|
312
|
+
expect(store.get(attachmentsAtom)).toEqual([]);
|
|
313
|
+
expect(store.get(agentAttachmentsAtom)).toEqual([]);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it("waits for a fresh snapshot after a transient reconnect", async () => {
|
|
317
|
+
const { store, transport, options, receive } = connectedSession();
|
|
318
|
+
act(() => options.onClose(new CloseEvent("close")));
|
|
319
|
+
expect(store.get(attachmentsAtom)).toEqual([]);
|
|
320
|
+
expect(store.get(connectionAtom).state).toBe(ConnectionState.CONNECTING);
|
|
321
|
+
expect(transport.reconnect).toHaveBeenCalledOnce();
|
|
322
|
+
|
|
323
|
+
await act(async () => options.onOpen(new Event("open")));
|
|
324
|
+
receive({ op: "reconnected" });
|
|
325
|
+
expect(store.get(connectionAtom).state).toBe(ConnectionState.OPEN);
|
|
326
|
+
expect(store.get(agentAttachmentsAtom)).toEqual([]);
|
|
327
|
+
|
|
328
|
+
const refreshed = { ...agent, id: "a2", name: "Codex" };
|
|
329
|
+
receive({ op: "attachments", attachments: [refreshed] });
|
|
330
|
+
expect(store.get(agentAttachmentsAtom)).toEqual([refreshed]);
|
|
331
|
+
receive({ op: "attachments", attachments: [] });
|
|
332
|
+
expect(store.get(agentAttachmentsAtom)).toEqual([]);
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
it("keeps a fresh snapshot hidden until the session is ready", async () => {
|
|
336
|
+
const { store, options, receive } = connectedSession();
|
|
337
|
+
act(() => options.onClose(new CloseEvent("close")));
|
|
338
|
+
await act(async () => options.onOpen(new Event("open")));
|
|
339
|
+
receive({ op: "attachments", attachments: [agent] });
|
|
340
|
+
expect(store.get(attachmentsAtom)).toEqual([agent]);
|
|
341
|
+
expect(store.get(agentAttachmentsAtom)).toEqual([]);
|
|
342
|
+
receive({ op: "reconnected" });
|
|
343
|
+
expect(store.get(agentAttachmentsAtom)).toEqual([agent]);
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
it("invalidates an old snapshot when a new transport opens", async () => {
|
|
347
|
+
const { store, options } = connectedSession();
|
|
348
|
+
await act(async () => options.onOpen(new Event("open")));
|
|
349
|
+
expect(store.get(attachmentsAtom)).toEqual([]);
|
|
350
|
+
expect(store.get(agentAttachmentsAtom)).toEqual([]);
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
|
|
214
354
|
it.each(["kernel-ready", "reconnected"])(
|
|
215
355
|
"waits for %s before marking the session connected",
|
|
216
356
|
async (op) => {
|
|
@@ -261,6 +401,59 @@ it.each(["kernel-ready", "reconnected"])(
|
|
|
261
401
|
},
|
|
262
402
|
);
|
|
263
403
|
|
|
404
|
+
it.each([true, false])(
|
|
405
|
+
"keeps attachments only when kernel-ready resumes the session: %s",
|
|
406
|
+
(resumed) => {
|
|
407
|
+
const store = createStore();
|
|
408
|
+
const attachments: Attachment[] = [
|
|
409
|
+
{
|
|
410
|
+
id: "a1",
|
|
411
|
+
kind: "agent",
|
|
412
|
+
name: "Pi",
|
|
413
|
+
since: "2026-10-14T00:00:00Z",
|
|
414
|
+
notebook_id: "nb-test",
|
|
415
|
+
identity: "pi-thread",
|
|
416
|
+
},
|
|
417
|
+
];
|
|
418
|
+
store.set(attachmentsAtom, attachments);
|
|
419
|
+
vi.mocked(useConnectionTransport).mockReturnValue(
|
|
420
|
+
makeTransport(WebSocket.OPEN),
|
|
421
|
+
);
|
|
422
|
+
vi.mocked(useRuntimeManager).mockReturnValue(
|
|
423
|
+
makeRuntimeManager() as unknown as ReturnType<typeof useRuntimeManager>,
|
|
424
|
+
);
|
|
425
|
+
renderConnectionHook(store);
|
|
426
|
+
const options = vi.mocked(useConnectionTransport).mock.calls.at(-1)![0];
|
|
427
|
+
act(() =>
|
|
428
|
+
options.onMessage(
|
|
429
|
+
new MessageEvent("message", {
|
|
430
|
+
data: JSON.stringify({
|
|
431
|
+
op: "kernel-ready",
|
|
432
|
+
data: {
|
|
433
|
+
op: "kernel-ready",
|
|
434
|
+
cell_ids: [],
|
|
435
|
+
codes: [],
|
|
436
|
+
names: [],
|
|
437
|
+
configs: [],
|
|
438
|
+
layout: null,
|
|
439
|
+
resumed,
|
|
440
|
+
ui_values: {},
|
|
441
|
+
last_executed_code: {},
|
|
442
|
+
last_execution_time: {},
|
|
443
|
+
app_config: { width: "normal" },
|
|
444
|
+
kiosk: false,
|
|
445
|
+
capabilities: { terminal: false },
|
|
446
|
+
auto_instantiated: true,
|
|
447
|
+
consumer_capabilities: { edit: true, interact: true },
|
|
448
|
+
},
|
|
449
|
+
}),
|
|
450
|
+
}),
|
|
451
|
+
),
|
|
452
|
+
);
|
|
453
|
+
expect(store.get(attachmentsAtom)).toEqual(resumed ? attachments : []);
|
|
454
|
+
},
|
|
455
|
+
);
|
|
456
|
+
|
|
264
457
|
describe("connection notice", () => {
|
|
265
458
|
beforeEach(() => vi.useFakeTimers());
|
|
266
459
|
afterEach(() => vi.useRealTimers());
|
|
@@ -5,6 +5,7 @@ import { useAtom, useAtomValue, useSetAtom } from "jotai";
|
|
|
5
5
|
import { useRef } from "react";
|
|
6
6
|
import { useErrorBoundary } from "react-error-boundary";
|
|
7
7
|
import { toast } from "@/components/ui/use-toast";
|
|
8
|
+
import { attachmentsAtom } from "@/core/attachments/state";
|
|
8
9
|
import { getNotebook, useCellActions } from "@/core/cells/cells";
|
|
9
10
|
import { applyTransactionChanges } from "@/core/cells/document-changes";
|
|
10
11
|
import { AUTOCOMPLETER } from "@/core/codemirror/completion/Autocompleter";
|
|
@@ -236,6 +237,7 @@ export function useMarimoKernelConnection(opts: {
|
|
|
236
237
|
} = useAlertActions();
|
|
237
238
|
const setKioskMode = useSetAtom(kioskModeAtom);
|
|
238
239
|
const setStableSessionId = useSetAtom(stableSessionIdAtom);
|
|
240
|
+
const setAttachments = useSetAtom(attachmentsAtom);
|
|
239
241
|
const setCapabilities = useSetAtom(capabilitiesAtom);
|
|
240
242
|
const runtimeManager = useRuntimeManager();
|
|
241
243
|
const transportType = useAtomValue(connectionTransportTypeAtom);
|
|
@@ -252,6 +254,9 @@ export function useMarimoKernelConnection(opts: {
|
|
|
252
254
|
case "reload":
|
|
253
255
|
reloadSafe();
|
|
254
256
|
return;
|
|
257
|
+
case "attachments":
|
|
258
|
+
setAttachments(msg.data.attachments);
|
|
259
|
+
return;
|
|
255
260
|
case "startup-progress": {
|
|
256
261
|
const { phase } = msg.data;
|
|
257
262
|
updateStartupProgress(msg.data);
|
|
@@ -283,6 +288,7 @@ export function useMarimoKernelConnection(opts: {
|
|
|
283
288
|
existingCells,
|
|
284
289
|
});
|
|
285
290
|
if (!msg.data.resumed) {
|
|
291
|
+
setAttachments([]);
|
|
286
292
|
// A freshly started kernel may expose a different environment
|
|
287
293
|
// (e.g. new env vars); re-run discovery instead of reusing stale
|
|
288
294
|
// suggestions from the previous kernel instance.
|
|
@@ -561,6 +567,7 @@ export function useMarimoKernelConnection(opts: {
|
|
|
561
567
|
*/
|
|
562
568
|
onOpen: async () => {
|
|
563
569
|
updateStartupProgress(null);
|
|
570
|
+
setAttachments([]);
|
|
564
571
|
// If we are open, we can reset our reconnecting flag.
|
|
565
572
|
shouldTryReconnecting.current = true;
|
|
566
573
|
},
|
|
@@ -603,6 +610,7 @@ export function useMarimoKernelConnection(opts: {
|
|
|
603
610
|
*/
|
|
604
611
|
onClose: (e) => {
|
|
605
612
|
Logger.warn("WebSocket closed", e.code, e.reason);
|
|
613
|
+
setAttachments([]);
|
|
606
614
|
const decision = classifyCloseEvent(e);
|
|
607
615
|
setConnection((previous) => {
|
|
608
616
|
const status = decision.status;
|
|
@@ -641,6 +649,7 @@ export function useMarimoKernelConnection(opts: {
|
|
|
641
649
|
*/
|
|
642
650
|
onError: (e) => {
|
|
643
651
|
Logger.warn("WebSocket error", e);
|
|
652
|
+
setAttachments([]);
|
|
644
653
|
setConnection({
|
|
645
654
|
state: ConnectionState.CLOSED,
|
|
646
655
|
code: WebSocketClosedReason.KERNEL_DISCONNECTED,
|
package/src/mount.tsx
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
userConfigAtom,
|
|
11
11
|
} from "@/core/config/config";
|
|
12
12
|
import { KnownQueryParams } from "@/core/constants";
|
|
13
|
-
import {
|
|
13
|
+
import { pairConfigAtom, pairConfigSchema } from "@/core/config/pair";
|
|
14
14
|
import { getFilenameFromDOM } from "@/core/dom/htmlUtils";
|
|
15
15
|
import { getMarimoCode } from "@/core/meta/globals";
|
|
16
16
|
import {
|
|
@@ -209,7 +209,7 @@ const mountOptionsSchema = z.object({
|
|
|
209
209
|
* marimo config overrides
|
|
210
210
|
*/
|
|
211
211
|
configOverrides: passthroughObject,
|
|
212
|
-
|
|
212
|
+
pairConfig: pairConfigSchema.optional(),
|
|
213
213
|
/**
|
|
214
214
|
* marimo app config
|
|
215
215
|
*/
|
|
@@ -347,7 +347,7 @@ function initStore(options: unknown) {
|
|
|
347
347
|
);
|
|
348
348
|
store.set(userConfigAtom, parseUserConfig(parsedOptions.data.config));
|
|
349
349
|
store.set(appConfigAtom, parseAppConfig(parsedOptions.data.appConfig));
|
|
350
|
-
store.set(
|
|
350
|
+
store.set(pairConfigAtom, parsedOptions.data.pairConfig);
|
|
351
351
|
|
|
352
352
|
// Runtime config
|
|
353
353
|
if (parsedOptions.data.runtimeConfig.length > 0) {
|
|
@@ -136,6 +136,90 @@ describe("LoadingDataTableComponent", () => {
|
|
|
136
136
|
expect(downloadGeoJSON).toHaveBeenCalledTimes(1);
|
|
137
137
|
});
|
|
138
138
|
|
|
139
|
+
it("refreshes export metadata when a dataframe transform changes the data", async () => {
|
|
140
|
+
const host = document.createElement("div");
|
|
141
|
+
const metadataFor = (name: string) => ({
|
|
142
|
+
geometry_columns: [{ name, encoding: "objects", crs: "EPSG:4326" }],
|
|
143
|
+
primary_geometry_column: name,
|
|
144
|
+
default_geometry_column: name,
|
|
145
|
+
formats: {
|
|
146
|
+
parquet: { available: true, reason: null, missing_packages: [] },
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
const getExportMetadata = vi
|
|
150
|
+
.fn()
|
|
151
|
+
.mockResolvedValueOnce(metadataFor("before"))
|
|
152
|
+
.mockResolvedValueOnce(metadataFor("after"));
|
|
153
|
+
const view = (data: string) => (
|
|
154
|
+
<Provider store={store}>
|
|
155
|
+
<TooltipProvider>
|
|
156
|
+
<LoadingDataTableComponent
|
|
157
|
+
label={null}
|
|
158
|
+
totalRows={1}
|
|
159
|
+
pagination={false}
|
|
160
|
+
pageSize={10}
|
|
161
|
+
selection={null}
|
|
162
|
+
showDownload={true}
|
|
163
|
+
showFilters={false}
|
|
164
|
+
showColumnSummaries={false}
|
|
165
|
+
showDataTypes={false}
|
|
166
|
+
showPageSizeSelector={false}
|
|
167
|
+
showColumnExplorer={false}
|
|
168
|
+
showRowExplorer={false}
|
|
169
|
+
showChartBuilder={false}
|
|
170
|
+
rowHeaders={[]}
|
|
171
|
+
fieldTypes={undefined}
|
|
172
|
+
totalColumns={1}
|
|
173
|
+
maxColumns="all"
|
|
174
|
+
hasStableRowId={false}
|
|
175
|
+
lazy={false}
|
|
176
|
+
host={host}
|
|
177
|
+
showSearch={false}
|
|
178
|
+
value={[]}
|
|
179
|
+
setValue={vi.fn()}
|
|
180
|
+
data={data}
|
|
181
|
+
search={vi.fn().mockResolvedValue({
|
|
182
|
+
data,
|
|
183
|
+
total_rows: 1,
|
|
184
|
+
cell_styles: null,
|
|
185
|
+
cell_hover_texts: null,
|
|
186
|
+
})}
|
|
187
|
+
download_as={vi.fn()}
|
|
188
|
+
download_geojson={vi.fn()}
|
|
189
|
+
get_export_metadata={getExportMetadata}
|
|
190
|
+
get_column_summaries={vi.fn()}
|
|
191
|
+
get_data_url={vi.fn() as GetDataUrl}
|
|
192
|
+
get_row_ids={vi.fn() as GetRowIds}
|
|
193
|
+
get_size_bytes={vi.fn().mockResolvedValue({ size_bytes: null })}
|
|
194
|
+
/>
|
|
195
|
+
</TooltipProvider>
|
|
196
|
+
</Provider>
|
|
197
|
+
);
|
|
198
|
+
const { rerender } = render(
|
|
199
|
+
view(JSON.stringify([{ before: "POINT (1 2)" }])),
|
|
200
|
+
);
|
|
201
|
+
await waitFor(() =>
|
|
202
|
+
expect(
|
|
203
|
+
screen.getByRole("columnheader", { name: "before" }),
|
|
204
|
+
).toBeInTheDocument(),
|
|
205
|
+
);
|
|
206
|
+
fireEvent.click(screen.getByTestId("export-button"));
|
|
207
|
+
await waitFor(() =>
|
|
208
|
+
expect(screen.getByTestId("export-summary-parquet")).toHaveTextContent(
|
|
209
|
+
"before",
|
|
210
|
+
),
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
rerender(view(JSON.stringify([{ after: "POINT (3 4)" }])));
|
|
214
|
+
|
|
215
|
+
await waitFor(() =>
|
|
216
|
+
expect(screen.getByTestId("export-summary-parquet")).toHaveTextContent(
|
|
217
|
+
"after",
|
|
218
|
+
),
|
|
219
|
+
);
|
|
220
|
+
expect(getExportMetadata).toHaveBeenCalledTimes(2);
|
|
221
|
+
});
|
|
222
|
+
|
|
139
223
|
it("does not log duplicate keys when a pivot becomes empty", async () => {
|
|
140
224
|
const host = document.createElement("div");
|
|
141
225
|
const consoleError = vi
|
|
@@ -4,6 +4,9 @@ import {
|
|
|
4
4
|
exactDateTime,
|
|
5
5
|
getDateFormat,
|
|
6
6
|
getShortTimeZone,
|
|
7
|
+
parseLocalISODate,
|
|
8
|
+
parseLocalISODateTime,
|
|
9
|
+
parseTimeToDate,
|
|
7
10
|
prettyDate,
|
|
8
11
|
timeAgo,
|
|
9
12
|
} from "../dates";
|
|
@@ -191,6 +194,119 @@ describe("dates", () => {
|
|
|
191
194
|
});
|
|
192
195
|
});
|
|
193
196
|
|
|
197
|
+
describe("parseTimeToDate", () => {
|
|
198
|
+
it("parses 24-hour times", () => {
|
|
199
|
+
expect(parseTimeToDate("14:30")).toEqual(new Date(1970, 0, 1, 14, 30));
|
|
200
|
+
expect(parseTimeToDate("14:30:05")).toEqual(
|
|
201
|
+
new Date(1970, 0, 1, 14, 30, 5),
|
|
202
|
+
);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it("parses times with an am/pm suffix", () => {
|
|
206
|
+
expect(parseTimeToDate("2:30 PM")).toEqual(new Date(1970, 0, 1, 14, 30));
|
|
207
|
+
expect(parseTimeToDate("12:00 am")).toEqual(new Date(1970, 0, 1, 0, 0));
|
|
208
|
+
expect(parseTimeToDate("12:00 pm")).toEqual(new Date(1970, 0, 1, 12, 0));
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("rejects an out-of-range hour instead of letting Date normalize it", () => {
|
|
212
|
+
// new Date(1970, 0, 1, 25, 0) would silently become 01:00 the next day.
|
|
213
|
+
expect(parseTimeToDate("25:00")).toBeUndefined();
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it("rejects an out-of-range minute instead of letting Date normalize it", () => {
|
|
217
|
+
// new Date(1970, 0, 1, 12, 99) would silently become 13:39.
|
|
218
|
+
expect(parseTimeToDate("12:99")).toBeUndefined();
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("rejects an out-of-range second", () => {
|
|
222
|
+
expect(parseTimeToDate("12:30:99")).toBeUndefined();
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it("requires an hour from 1 to 12 with an am/pm suffix", () => {
|
|
226
|
+
expect(parseTimeToDate("0:30 am")).toBeUndefined();
|
|
227
|
+
expect(parseTimeToDate("13:30 pm")).toBeUndefined();
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it("parses milliseconds", () => {
|
|
231
|
+
expect(parseTimeToDate("14:30:05.123")).toEqual(
|
|
232
|
+
new Date(1970, 0, 1, 14, 30, 5, 123),
|
|
233
|
+
);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it("pads a short millisecond fraction and truncates a long one", () => {
|
|
237
|
+
expect(parseTimeToDate("14:30:05.5")).toEqual(
|
|
238
|
+
new Date(1970, 0, 1, 14, 30, 5, 500),
|
|
239
|
+
);
|
|
240
|
+
expect(parseTimeToDate("14:30:05.123456")).toEqual(
|
|
241
|
+
new Date(1970, 0, 1, 14, 30, 5, 123),
|
|
242
|
+
);
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
describe("parseLocalISODate", () => {
|
|
247
|
+
it("parses a date-only string into local midnight", () => {
|
|
248
|
+
expect(parseLocalISODate("2024-01-15")).toEqual(new Date(2024, 0, 15));
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it("returns undefined for a non-date-only string", () => {
|
|
252
|
+
expect(parseLocalISODate("2024-01-15T00:00:00")).toBeUndefined();
|
|
253
|
+
expect(parseLocalISODate("")).toBeUndefined();
|
|
254
|
+
expect(parseLocalISODate("not-a-date")).toBeUndefined();
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it("returns undefined for a calendar date that doesn't exist", () => {
|
|
258
|
+
expect(parseLocalISODate("2024-02-30")).toBeUndefined();
|
|
259
|
+
expect(parseLocalISODate("2024-13-01")).toBeUndefined();
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
describe("parseLocalISODateTime", () => {
|
|
264
|
+
it("parses a 'T'-separated datetime into local wall-clock time", () => {
|
|
265
|
+
expect(parseLocalISODateTime("2024-01-15T08:30:00")).toEqual(
|
|
266
|
+
new Date(2024, 0, 15, 8, 30, 0),
|
|
267
|
+
);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it("parses a space-separated datetime", () => {
|
|
271
|
+
expect(parseLocalISODateTime("2024-01-15 08:30:00")).toEqual(
|
|
272
|
+
new Date(2024, 0, 15, 8, 30, 0),
|
|
273
|
+
);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it("defaults seconds to 0 when omitted", () => {
|
|
277
|
+
expect(parseLocalISODateTime("2024-01-15T08:30")).toEqual(
|
|
278
|
+
new Date(2024, 0, 15, 8, 30, 0),
|
|
279
|
+
);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it("ignores a trailing Z instead of shifting to UTC", () => {
|
|
283
|
+
expect(parseLocalISODateTime("2024-01-15T08:30:00Z")).toEqual(
|
|
284
|
+
new Date(2024, 0, 15, 8, 30, 0),
|
|
285
|
+
);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it("ignores a trailing UTC offset instead of shifting the time", () => {
|
|
289
|
+
expect(parseLocalISODateTime("2024-01-15T08:30:00+05:00")).toEqual(
|
|
290
|
+
new Date(2024, 0, 15, 8, 30, 0),
|
|
291
|
+
);
|
|
292
|
+
expect(parseLocalISODateTime("2024-01-15T08:30:00-0500")).toEqual(
|
|
293
|
+
new Date(2024, 0, 15, 8, 30, 0),
|
|
294
|
+
);
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it("ignores sub-second precision", () => {
|
|
298
|
+
expect(parseLocalISODateTime("2024-01-15T08:30:00.123")).toEqual(
|
|
299
|
+
new Date(2024, 0, 15, 8, 30, 0),
|
|
300
|
+
);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it("returns undefined for a date-only or unparsable string", () => {
|
|
304
|
+
expect(parseLocalISODateTime("2024-01-15")).toBeUndefined();
|
|
305
|
+
expect(parseLocalISODateTime("not-a-datetime")).toBeUndefined();
|
|
306
|
+
expect(parseLocalISODateTime("")).toBeUndefined();
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
|
|
194
310
|
describe("getDateFormat", () => {
|
|
195
311
|
it("returns the correct format for date", () => {
|
|
196
312
|
expect(getDateFormat("2023-05-15")).toBe("yyyy-MM-dd");
|
package/src/utils/dates.ts
CHANGED
|
@@ -165,6 +165,44 @@ export function dateToLocalISOTime(d: Date): string {
|
|
|
165
165
|
return `${pad2(d.getHours())}:${pad2(d.getMinutes())}:${pad2(d.getSeconds())}`;
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
+
/**
|
|
169
|
+
* Parse a time string into a Date anchored at the Unix epoch day. Supports
|
|
170
|
+
* the backend's wire format (`HH:MM:SS`, as produced by `dateToLocalISOTime`)
|
|
171
|
+
* as well as looser pasted text: optional seconds, optional milliseconds,
|
|
172
|
+
* and an optional `am`/`pm` suffix (e.g. `"14:30"`, `"2:30 PM"`,
|
|
173
|
+
* `"14:30:00.123"`).
|
|
174
|
+
*/
|
|
175
|
+
export function parseTimeToDate(value: string): Date | undefined {
|
|
176
|
+
const match = /^(\d{1,2}):(\d{2})(?::(\d{2}))?(?:\.(\d+))?\s*(am|pm)?$/i.exec(
|
|
177
|
+
value.trim(),
|
|
178
|
+
);
|
|
179
|
+
if (!match) {
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
const [, hStr, mStr, sStr, msStr, ampm] = match;
|
|
183
|
+
let hour = Number.parseInt(hStr, 10);
|
|
184
|
+
const minute = Number.parseInt(mStr, 10);
|
|
185
|
+
const second = sStr ? Number.parseInt(sStr, 10) : 0;
|
|
186
|
+
const ms = msStr ? Number.parseInt(msStr.padEnd(3, "0").slice(0, 3), 10) : 0;
|
|
187
|
+
if (minute > 59 || second > 59) {
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
190
|
+
if (ampm) {
|
|
191
|
+
if (hour < 1 || hour > 12) {
|
|
192
|
+
return undefined;
|
|
193
|
+
}
|
|
194
|
+
const isPm = ampm.toLowerCase() === "pm";
|
|
195
|
+
if (hour === 12) {
|
|
196
|
+
hour = isPm ? 12 : 0;
|
|
197
|
+
} else if (isPm) {
|
|
198
|
+
hour += 12;
|
|
199
|
+
}
|
|
200
|
+
} else if (hour > 23) {
|
|
201
|
+
return undefined;
|
|
202
|
+
}
|
|
203
|
+
return new Date(1970, 0, 1, hour, minute, second, ms);
|
|
204
|
+
}
|
|
205
|
+
|
|
168
206
|
/**
|
|
169
207
|
* Format a Date as `YYYY-MM-DDTHH:MM:SS` (no timezone suffix) using local
|
|
170
208
|
* fields. See `dateToLocalISODate` for the rationale on local vs UTC.
|
|
@@ -173,6 +211,62 @@ export function dateToLocalISODateTime(d: Date): string {
|
|
|
173
211
|
return `${dateToLocalISODate(d)}T${dateToLocalISOTime(d)}`;
|
|
174
212
|
}
|
|
175
213
|
|
|
214
|
+
/**
|
|
215
|
+
* Parse a `YYYY-MM-DD` string into a Date anchored at local midnight.
|
|
216
|
+
*
|
|
217
|
+
* Unlike `new Date("YYYY-MM-DD")`, which the spec parses as UTC midnight,
|
|
218
|
+
* this treats the string as a calendar date in the viewer's own timezone.
|
|
219
|
+
* Returns undefined if the string doesn't match, or encodes a calendar
|
|
220
|
+
* date that doesn't exist (e.g. month 13, Feb 30), since `Date` would
|
|
221
|
+
* otherwise silently roll those over into a different date.
|
|
222
|
+
*/
|
|
223
|
+
export function parseLocalISODate(value: string): Date | undefined {
|
|
224
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value.trim());
|
|
225
|
+
if (!match) {
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
228
|
+
const [, yStr, mStr, dStr] = match;
|
|
229
|
+
const year = Number.parseInt(yStr, 10);
|
|
230
|
+
const month = Number.parseInt(mStr, 10);
|
|
231
|
+
const day = Number.parseInt(dStr, 10);
|
|
232
|
+
const date = new Date(year, month - 1, day);
|
|
233
|
+
if (
|
|
234
|
+
date.getFullYear() !== year ||
|
|
235
|
+
date.getMonth() !== month - 1 ||
|
|
236
|
+
date.getDate() !== day
|
|
237
|
+
) {
|
|
238
|
+
return undefined;
|
|
239
|
+
}
|
|
240
|
+
return date;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Parse an ISO-ish `YYYY-MM-DD[T ]HH:MM[:SS[.sss]][Z|+HH:MM]` datetime string
|
|
245
|
+
* as wall-clock local time, ignoring any trailing `Z` or UTC offset.
|
|
246
|
+
*
|
|
247
|
+
* This keeps pasted datetimes consistent with the date/time pickers' local-
|
|
248
|
+
* time basis: pasting `2024-01-15T08:30:00Z` displays `08:30` instead of
|
|
249
|
+
* being shifted by the viewer's timezone.
|
|
250
|
+
*/
|
|
251
|
+
export function parseLocalISODateTime(value: string): Date | undefined {
|
|
252
|
+
const match =
|
|
253
|
+
/^(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?$/.exec(
|
|
254
|
+
value.trim(),
|
|
255
|
+
);
|
|
256
|
+
if (!match) {
|
|
257
|
+
return undefined;
|
|
258
|
+
}
|
|
259
|
+
const [, yStr, moStr, dStr, hStr, miStr, sStr] = match;
|
|
260
|
+
return new Date(
|
|
261
|
+
Number.parseInt(yStr, 10),
|
|
262
|
+
Number.parseInt(moStr, 10) - 1,
|
|
263
|
+
Number.parseInt(dStr, 10),
|
|
264
|
+
Number.parseInt(hStr, 10),
|
|
265
|
+
Number.parseInt(miStr, 10),
|
|
266
|
+
sStr ? Number.parseInt(sStr, 10) : 0,
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
176
270
|
export const supportedDateFormats = ["yyyy", "yyyy-MM", "yyyy-MM-dd"] as const;
|
|
177
271
|
export type DateFormat = (typeof supportedDateFormats)[number];
|
|
178
272
|
|