@marimo-team/islands 0.16.1 → 0.16.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/dist/{ConnectedDataExplorerComponent-DyqLQGPc.js → ConnectedDataExplorerComponent-KvtsEmcw.js} +2 -2
  2. package/dist/{ImageComparisonComponent-CQDGJfUA.js → ImageComparisonComponent-R2tjqLSx.js} +1 -1
  3. package/dist/{_baseUniq-B2Nna6Kt.js → _baseUniq-BykZEXIq.js} +1 -1
  4. package/dist/{any-language-editor-D-wq0tOG.js → any-language-editor-CMt4Y6oz.js} +1 -1
  5. package/dist/{architectureDiagram-W76B3OCA-C6tdnMBf.js → architectureDiagram-W76B3OCA-mQ3sJdEW.js} +4 -4
  6. package/dist/{blockDiagram-QIGZ2CNN-IagL8LCN.js → blockDiagram-QIGZ2CNN-BxLRv5EM.js} +5 -5
  7. package/dist/{c4Diagram-FPNF74CW-D3_lIWUP.js → c4Diagram-FPNF74CW-Cfz16aWq.js} +2 -2
  8. package/dist/{channel-DCJI_DKk.js → channel-zr1uJJ5g.js} +1 -1
  9. package/dist/{chunk-4BX2VUAB-B2DrODwN.js → chunk-4BX2VUAB-B8iHvpDe.js} +1 -1
  10. package/dist/{chunk-55IACEB6-BUWDsQ-t.js → chunk-55IACEB6-CJs4dL1H.js} +1 -1
  11. package/dist/{chunk-FMBD7UC4-BExPNFv1.js → chunk-FMBD7UC4-C5irHg20.js} +1 -1
  12. package/dist/{chunk-K7UQS3LO-Cixi-Yko.js → chunk-K7UQS3LO-B2XW75WS.js} +4 -4
  13. package/dist/{chunk-QN33PNHL-B83MtvER.js → chunk-QN33PNHL-BtwctqGa.js} +1 -1
  14. package/dist/{chunk-QZHKN3VN-CXvbu85X.js → chunk-QZHKN3VN-Sb8ZD0FY.js} +1 -1
  15. package/dist/{chunk-TVAH2DTR-CpiumCHg.js → chunk-TVAH2DTR-CEJ5zkLX.js} +3 -3
  16. package/dist/{chunk-TZMSLE5B-DIzaZjcI.js → chunk-TZMSLE5B-Ccm4T92V.js} +1 -1
  17. package/dist/{classDiagram-v2-RKCZMP56-DyN5HPdk.js → classDiagram-KNZD7YFC-DWTbT0ww.js} +2 -2
  18. package/dist/{classDiagram-KNZD7YFC-DyN5HPdk.js → classDiagram-v2-RKCZMP56-DWTbT0ww.js} +2 -2
  19. package/dist/{clone-DrJYap2i.js → clone-CDDiMerE.js} +1 -1
  20. package/dist/{cose-bilkent-S5V4N54A-D39b4WrQ.js → cose-bilkent-S5V4N54A-B74aLjZ_.js} +2 -2
  21. package/dist/{dagre-5GWH7T2D-BLjRxDpS.js → dagre-5GWH7T2D-Cie_wUzI.js} +6 -6
  22. package/dist/{data-grid-overlay-editor-DTALqerV.js → data-grid-overlay-editor-OsCMRzfP.js} +2 -2
  23. package/dist/{diagram-N5W7TBWH-MM8AIKGR.js → diagram-N5W7TBWH-CCeFeV2B.js} +5 -5
  24. package/dist/{diagram-QEK2KX5R-BZGarWuJ.js → diagram-QEK2KX5R-BPROiVV7.js} +3 -3
  25. package/dist/{diagram-S2PKOQOG-CnPinN9Q.js → diagram-S2PKOQOG-BkLFbUa_.js} +3 -3
  26. package/dist/{dockerfile-U8DnCJ4X.js → dockerfile-CuJXUZQ_.js} +1 -1
  27. package/dist/{erDiagram-AWTI2OKA-CvDVbxOO.js → erDiagram-AWTI2OKA-CpBWOTMK.js} +4 -4
  28. package/dist/{flowDiagram-PVAE7QVJ-C2uuBTZS.js → flowDiagram-PVAE7QVJ-C_X4bmq3.js} +5 -5
  29. package/dist/{ganttDiagram-OWAHRB6G-BEff10RF.js → ganttDiagram-OWAHRB6G-CruldwEp.js} +4 -4
  30. package/dist/{gitGraphDiagram-NY62KEGX-wggu0kb2.js → gitGraphDiagram-NY62KEGX-ZJnVxaQP.js} +4 -4
  31. package/dist/{glide-data-editor-Bqh5_dzJ.js → glide-data-editor-CnOBht4I.js} +3 -3
  32. package/dist/{graph-DKpp_wzf.js → graph-DjTtWtcG.js} +3 -3
  33. package/dist/{index-DzJ_YPCG.js → index-CZ9vIBEc.js} +3 -3
  34. package/dist/{index-DdfF_cLK.js → index-DSpjUDnr.js} +1 -1
  35. package/dist/{index-DW0BCGJE.js → index-DeOkA9fC.js} +1 -1
  36. package/dist/{index-4XruEJkp.js → index-saLjL5eo.js} +1 -1
  37. package/dist/{infoDiagram-STP46IZ2-DF7KW-Op.js → infoDiagram-STP46IZ2-RZgl96nR.js} +2 -2
  38. package/dist/{journeyDiagram-BIP6EPQ6-B_jmhmqd.js → journeyDiagram-BIP6EPQ6-9ytZy-zY.js} +3 -3
  39. package/dist/{kanban-definition-6OIFK2YF-B-M9FTyw.js → kanban-definition-6OIFK2YF-CpjPWkgX.js} +2 -2
  40. package/dist/{layout-C4oVYZZD.js → layout-BAvhX25D.js} +4 -4
  41. package/dist/{linear-C-HCGr0T.js → linear-BKZuvJrK.js} +1 -1
  42. package/dist/{main-B9x2-9f2.js → main-pE28kbH0.js} +37316 -36749
  43. package/dist/main.js +1 -1
  44. package/dist/{mermaid-BE4cM3Qs.js → mermaid-BGd7kEsf.js} +30 -30
  45. package/dist/{min-DTpHJ698.js → min-DmsBJf5S.js} +2 -2
  46. package/dist/{mindmap-definition-Q6HEUPPD-Cpd-hO1E.js → mindmap-definition-Q6HEUPPD-BerypnVD.js} +3 -3
  47. package/dist/{number-overlay-editor-CvURA2Ud.js → number-overlay-editor-A7ZQ6sSs.js} +2 -2
  48. package/dist/{pieDiagram-ADFJNKIX-D9f_f6fn.js → pieDiagram-ADFJNKIX-ChcQLZM2.js} +3 -3
  49. package/dist/{quadrantDiagram-LMRXKWRM-DgllE7xw.js → quadrantDiagram-LMRXKWRM-BOMxo-5G.js} +2 -2
  50. package/dist/{react-plotly-BU-JRJSi.js → react-plotly-8f0vAPdB.js} +1 -1
  51. package/dist/{requirementDiagram-4UW4RH46-Dk_G8eUb.js → requirementDiagram-4UW4RH46-rql0vkIr.js} +3 -3
  52. package/dist/{sankeyDiagram-GR3RE2ED-BhLIhDc1.js → sankeyDiagram-GR3RE2ED-BMz3hqw4.js} +1 -1
  53. package/dist/{sequenceDiagram-C3RYC4MD-DHoZdMFJ.js → sequenceDiagram-C3RYC4MD-DFK39LUK.js} +3 -3
  54. package/dist/{slides-component-DXAgdf7K.js → slides-component-BNsZuUgg.js} +1 -1
  55. package/dist/{stateDiagram-KXAO66HF-C1Ie-7Xf.js → stateDiagram-KXAO66HF-B_3SWOCl.js} +4 -4
  56. package/dist/{stateDiagram-v2-UMBNRL4Z--CRuIHtM.js → stateDiagram-v2-UMBNRL4Z-BWAYN6aU.js} +2 -2
  57. package/dist/style.css +1 -1
  58. package/dist/{time-yQjlGPwa.js → time-DCvYzQ5t.js} +2 -2
  59. package/dist/{timeline-definition-XQNQX7LJ-D_PjxB1B.js → timeline-definition-XQNQX7LJ-CSbxJ5mV.js} +1 -1
  60. package/dist/{treemap-75Q7IDZK--NYqQjUZ.js → treemap-75Q7IDZK-LMXGKln_.js} +5 -5
  61. package/dist/{vega-component-CCUOMM5K.js → vega-component-CRmon7pH.js} +2 -2
  62. package/dist/{xychartDiagram-6GGTOJPD-WLKsEnzs.js → xychartDiagram-6GGTOJPD-DaUD4dq3.js} +2 -2
  63. package/package.json +3 -3
  64. package/src/__mocks__/requests.ts +1 -0
  65. package/src/components/data-table/__tests__/columns.test.tsx +38 -0
  66. package/src/components/data-table/cell-hover-template/feature.ts +1 -1
  67. package/src/components/data-table/cell-hover-template/types.ts +1 -1
  68. package/src/components/data-table/columns.tsx +21 -2
  69. package/src/components/data-table/renderers.tsx +16 -8
  70. package/src/components/data-table/schemas.ts +16 -0
  71. package/src/components/editor/Cell.tsx +2 -0
  72. package/src/components/editor/errors/sql-validation-errors.tsx +34 -0
  73. package/src/components/editor/output/ConsoleOutput.tsx +13 -1
  74. package/src/components/editor/output/MarimoErrorOutput.tsx +60 -1
  75. package/src/core/ai/context/providers/cell-output.ts +1 -18
  76. package/src/core/codemirror/language/__tests__/extension.test.ts +24 -0
  77. package/src/core/codemirror/language/__tests__/sql-validation.test.ts +133 -0
  78. package/src/core/codemirror/language/languages/sql/sql-mode.ts +20 -0
  79. package/src/core/codemirror/language/languages/sql/sql.ts +90 -3
  80. package/src/core/codemirror/language/languages/sql/validation-errors.ts +79 -0
  81. package/src/core/codemirror/language/panel/panel.tsx +8 -2
  82. package/src/core/codemirror/language/panel/sql.tsx +81 -4
  83. package/src/core/config/feature-flag.tsx +3 -1
  84. package/src/core/datasets/request-registry.ts +17 -1
  85. package/src/core/islands/bridge.ts +1 -0
  86. package/src/core/islands/main.ts +1 -0
  87. package/src/core/kernel/messages.ts +1 -0
  88. package/src/core/network/requests-network.ts +7 -0
  89. package/src/core/network/requests-static.ts +1 -0
  90. package/src/core/network/requests-toasting.ts +1 -0
  91. package/src/core/network/types.ts +2 -0
  92. package/src/core/wasm/bridge.ts +5 -0
  93. package/src/core/websocket/useMarimoWebSocket.tsx +4 -0
  94. package/src/plugins/core/registerReactComponent.tsx +23 -19
  95. package/src/plugins/impl/DataTablePlugin.tsx +11 -4
  96. package/src/plugins/impl/data-frames/DataFramePlugin.tsx +17 -5
  97. package/src/stories/dataframe.stories.tsx +2 -0
  98. package/src/utils/__tests__/dom.test.ts +167 -0
  99. package/src/utils/dom.ts +55 -0
@@ -0,0 +1,20 @@
1
+ /* Copyright 2024 Marimo. All rights reserved. */
2
+
3
+ import { useAtom } from "jotai";
4
+ import { atomWithStorage } from "jotai/utils";
5
+ import { store } from "@/core/state/jotai";
6
+
7
+ const BASE_KEY = "marimo:notebook-sql-mode";
8
+
9
+ export type SQLMode = "validate" | "default";
10
+
11
+ const sqlModeAtom = atomWithStorage<SQLMode>(BASE_KEY, "default");
12
+
13
+ export function useSQLMode() {
14
+ const [sqlMode, setSQLMode] = useAtom(sqlModeAtom);
15
+ return { sqlMode, setSQLMode };
16
+ }
17
+
18
+ export function getSQLMode() {
19
+ return store.get(sqlModeAtom);
20
+ }
@@ -5,7 +5,7 @@ import { insertTab } from "@codemirror/commands";
5
5
  import { type SQLDialect, type SQLNamespace, sql } from "@codemirror/lang-sql";
6
6
  import type { EditorState, Extension } from "@codemirror/state";
7
7
  import { Compartment } from "@codemirror/state";
8
- import { type EditorView, keymap } from "@codemirror/view";
8
+ import { EditorView, keymap } from "@codemirror/view";
9
9
  import type { SyntaxNode, TreeCursor } from "@lezer/common";
10
10
  import { parser } from "@lezer/python";
11
11
  import {
@@ -16,12 +16,19 @@ import {
16
16
  } from "@marimo-team/codemirror-sql";
17
17
  import { DuckDBDialect } from "@marimo-team/codemirror-sql/dialects";
18
18
  import dedent from "string-dedent";
19
+ import { cellIdState } from "@/core/codemirror/cells/state";
19
20
  import { getFeatureFlag } from "@/core/config/feature-flag";
20
21
  import {
21
22
  dataSourceConnectionsAtom,
22
23
  setLatestEngineSelected,
23
24
  } from "@/core/datasets/data-source-connections";
24
- import { type ConnectionName, DUCKDB_ENGINE } from "@/core/datasets/engines";
25
+ import {
26
+ type ConnectionName,
27
+ DUCKDB_ENGINE,
28
+ INTERNAL_SQL_ENGINES,
29
+ } from "@/core/datasets/engines";
30
+ import { ValidateSQL } from "@/core/datasets/request-registry";
31
+ import type { ValidateSQLResult } from "@/core/kernel/messages";
25
32
  import { store } from "@/core/state/jotai";
26
33
  import { resolvedThemeAtom } from "@/theme/useTheme";
27
34
  import { Logger } from "@/utils/Logger";
@@ -37,6 +44,11 @@ import {
37
44
  tablesCompletionSource,
38
45
  } from "./completion-sources";
39
46
  import { SCHEMA_CACHE } from "./completion-store";
47
+ import { getSQLMode } from "./sql-mode";
48
+ import {
49
+ clearSqlValidationError,
50
+ setSqlValidationError,
51
+ } from "./validation-errors";
40
52
 
41
53
  const DEFAULT_DIALECT = DuckDBDialect;
42
54
  const DEFAULT_PARSER_DIALECT = "DuckDB";
@@ -64,12 +76,15 @@ export class SQLLanguageAdapter
64
76
  {
65
77
  readonly type = "sql";
66
78
  sqlLinterEnabled: boolean;
79
+ sqlModeEnabled: boolean;
67
80
 
68
81
  constructor() {
69
82
  try {
70
83
  this.sqlLinterEnabled = getFeatureFlag("sql_linter");
84
+ this.sqlModeEnabled = getFeatureFlag("sql_mode");
71
85
  } catch {
72
86
  this.sqlLinterEnabled = false;
87
+ this.sqlModeEnabled = false;
73
88
  }
74
89
  }
75
90
 
@@ -265,6 +280,10 @@ export class SQLLanguageAdapter
265
280
  );
266
281
  }
267
282
 
283
+ if (this.sqlModeEnabled) {
284
+ extensions.push(sqlValidationExtension());
285
+ }
286
+
268
287
  return extensions;
269
288
  }
270
289
  }
@@ -315,9 +334,14 @@ function getSchema(view: EditorView): SQLNamespace {
315
334
  function guessParserDialect(state: EditorState): ParserDialects | null {
316
335
  const metadata = getSQLMetadata(state);
317
336
  const connectionName = metadata.engine;
337
+ return connectionNameToParserDialect(connectionName);
338
+ }
339
+
340
+ function connectionNameToParserDialect(
341
+ connectionName: ConnectionName,
342
+ ): ParserDialects | null {
318
343
  const dialect =
319
344
  SCHEMA_CACHE.getInternalDialect(connectionName)?.toLowerCase();
320
-
321
345
  switch (dialect) {
322
346
  case "postgresql":
323
347
  case "postgres":
@@ -543,3 +567,66 @@ function safeDedent(code: string): string {
543
567
  return code;
544
568
  }
545
569
  }
570
+
571
+ function sqlValidationExtension(): Extension {
572
+ let debounceTimeout: NodeJS.Timeout | null = null;
573
+ let lastValidationRequest: string | null = null;
574
+
575
+ return EditorView.updateListener.of((update) => {
576
+ const sqlMode = getSQLMode();
577
+ if (sqlMode !== "validate") {
578
+ return;
579
+ }
580
+
581
+ const metadata = getSQLMetadata(update.state);
582
+ const connectionName = metadata.engine;
583
+ if (!INTERNAL_SQL_ENGINES.has(connectionName)) {
584
+ // Currently only internal engines are supported
585
+ return;
586
+ }
587
+
588
+ if (!update.docChanged) {
589
+ return;
590
+ }
591
+
592
+ const doc = update.state.doc;
593
+ const sqlContent = doc.toString();
594
+
595
+ // Clear existing timeout
596
+ if (debounceTimeout) {
597
+ clearTimeout(debounceTimeout);
598
+ }
599
+
600
+ // Debounce the validation call
601
+ debounceTimeout = setTimeout(async () => {
602
+ // Skip if content hasn't changed since last validation
603
+ if (lastValidationRequest === sqlContent) {
604
+ return;
605
+ }
606
+
607
+ lastValidationRequest = sqlContent;
608
+ const cellId = update.view.state.facet(cellIdState);
609
+
610
+ if (sqlContent === "") {
611
+ clearSqlValidationError(cellId);
612
+ return;
613
+ }
614
+
615
+ try {
616
+ const result: ValidateSQLResult = await ValidateSQL.request({
617
+ engine: connectionName,
618
+ query: sqlContent,
619
+ });
620
+
621
+ if (result.error) {
622
+ const dialect = connectionNameToParserDialect(connectionName);
623
+ setSqlValidationError({ cellId, error: result.error, dialect });
624
+ } else {
625
+ clearSqlValidationError(cellId);
626
+ }
627
+ } catch (error) {
628
+ Logger.warn("Failed to validate SQL", { error });
629
+ }
630
+ }, 300);
631
+ });
632
+ }
@@ -0,0 +1,79 @@
1
+ /* Copyright 2024 Marimo. All rights reserved. */
2
+
3
+ import type { SupportedDialects } from "@marimo-team/codemirror-sql";
4
+ import { atom, useAtomValue } from "jotai";
5
+ import type { CellId } from "@/core/cells/ids";
6
+ import { store } from "@/core/state/jotai";
7
+
8
+ export interface SQLValidationError {
9
+ errorType: string;
10
+ errorMessage: string;
11
+ codeblock?: string; // Code block that caused the error
12
+ }
13
+
14
+ type CellToSQLErrors = Map<CellId, SQLValidationError>;
15
+
16
+ export const sqlValidationErrorsAtom = atom<CellToSQLErrors>(
17
+ new Map<CellId, SQLValidationError>(),
18
+ );
19
+
20
+ export const useSqlValidationErrorsForCell = (cellId: CellId) => {
21
+ const sqlValidationErrors = useAtomValue(sqlValidationErrorsAtom);
22
+ return sqlValidationErrors.get(cellId);
23
+ };
24
+
25
+ export function clearSqlValidationError(cellId: CellId) {
26
+ const sqlValidationErrors = store.get(sqlValidationErrorsAtom);
27
+ const newErrors = new Map(sqlValidationErrors);
28
+ newErrors.delete(cellId);
29
+ store.set(sqlValidationErrorsAtom, newErrors);
30
+ }
31
+
32
+ export function setSqlValidationError({
33
+ cellId,
34
+ error,
35
+ dialect,
36
+ }: {
37
+ cellId: CellId;
38
+ error: string;
39
+ dialect: SupportedDialects | null;
40
+ }) {
41
+ const sqlValidationErrors = store.get(sqlValidationErrorsAtom);
42
+ const newErrors = new Map(sqlValidationErrors);
43
+
44
+ const errorResult: SQLValidationError =
45
+ dialect === "DuckDB" ? handleDuckdbError(error) : splitErrorMessage(error);
46
+
47
+ newErrors.set(cellId, errorResult);
48
+ store.set(sqlValidationErrorsAtom, newErrors);
49
+ }
50
+
51
+ function handleDuckdbError(error: string): SQLValidationError {
52
+ const { errorType, errorMessage } = splitErrorMessage(error);
53
+ let newErrorMessage = errorMessage;
54
+
55
+ // Extract the LINE and the rest of the message as codeblock, keep errorMessage as whatever is before
56
+ let codeblock: string | undefined;
57
+ const lineIndex = errorMessage.indexOf("LINE ");
58
+ if (lineIndex !== -1) {
59
+ codeblock = errorMessage.slice(Math.max(0, lineIndex)).trim();
60
+ newErrorMessage = errorMessage.slice(0, Math.max(0, lineIndex)).trim();
61
+ }
62
+
63
+ return {
64
+ errorType,
65
+ errorMessage: newErrorMessage,
66
+ codeblock,
67
+ };
68
+ }
69
+
70
+ function splitErrorMessage(error: string) {
71
+ const errorType = error.split(":")[0].trim();
72
+ const errorMessage = error.split(":").slice(1).join(":").trim();
73
+ return { errorType, errorMessage };
74
+ }
75
+
76
+ export const exportedForTesting = {
77
+ splitErrorMessage,
78
+ handleDuckdbError,
79
+ };
@@ -5,7 +5,8 @@ import { Button } from "@/components/ui/button";
5
5
  import { Checkbox } from "@/components/ui/checkbox";
6
6
  import { Tooltip, TooltipProvider } from "@/components/ui/tooltip";
7
7
  import { normalizeName } from "@/core/cells/names";
8
- import type { ConnectionName } from "@/core/datasets/engines";
8
+ import { getFeatureFlag } from "@/core/config/feature-flag";
9
+ import { type ConnectionName, DUCKDB_ENGINE } from "@/core/datasets/engines";
9
10
  import { useAutoGrowInputProps } from "@/hooks/useAutoGrowInputProps";
10
11
  import { formatSQL } from "../../format";
11
12
  import { languageAdapterState } from "../extension";
@@ -22,7 +23,7 @@ import {
22
23
  import type { LanguageMetadataOf } from "../types";
23
24
  import type { QuotePrefixKind } from "../utils/quotes";
24
25
  import { getQuotePrefix, MarkdownQuotePrefixTooltip } from "./markdown";
25
- import { SQLEngineSelect } from "./sql";
26
+ import { SQLEngineSelect, SQLModeSelect } from "./sql";
26
27
 
27
28
  const Divider = () => <div className="h-4 border-r border-border" />;
28
29
 
@@ -70,6 +71,8 @@ export const LanguagePanelComponent: React.FC<{
70
71
  updateSQLDialectFromConnection(view, engine);
71
72
  };
72
73
 
74
+ const sqlModeEnabled = getFeatureFlag("sql_mode");
75
+
73
76
  actions = (
74
77
  <div className="flex flex-1 gap-2 items-center">
75
78
  <label className="flex gap-2 items-center">
@@ -95,6 +98,9 @@ export const LanguagePanelComponent: React.FC<{
95
98
  onChange={switchEngine}
96
99
  />
97
100
  <div className="flex items-center gap-2 ml-auto">
101
+ {sqlModeEnabled && metadata.engine === DUCKDB_ENGINE && (
102
+ <SQLModeSelect />
103
+ )}
98
104
  <Tooltip content="Format SQL">
99
105
  <Button
100
106
  variant="text"
@@ -1,9 +1,16 @@
1
1
  /* Copyright 2024 Marimo. All rights reserved. */
2
2
 
3
+ import type { SelectTriggerProps } from "@radix-ui/react-select";
3
4
  import { useAtomValue } from "jotai";
4
- import { AlertCircle, CircleHelpIcon } from "lucide-react";
5
+ import {
6
+ AlertCircle,
7
+ CircleHelpIcon,
8
+ DatabaseBackup,
9
+ SearchCheck,
10
+ } from "lucide-react";
5
11
  import { transformDisplayName } from "@/components/databases/display";
6
12
  import { DatabaseLogo } from "@/components/databases/icon";
13
+ import { Button } from "@/components/ui/button";
7
14
  import {
8
15
  Select,
9
16
  SelectContent,
@@ -14,6 +21,7 @@ import {
14
21
  SelectTrigger,
15
22
  SelectValue,
16
23
  } from "@/components/ui/select";
24
+ import { Tooltip } from "@/components/ui/tooltip";
17
25
  import {
18
26
  dataConnectionsMapAtom,
19
27
  setLatestEngineSelected,
@@ -24,6 +32,7 @@ import {
24
32
  } from "@/core/datasets/engines";
25
33
  import type { DataSourceConnection } from "@/core/kernel/messages";
26
34
  import { useNonce } from "@/hooks/useNonce";
35
+ import { type SQLMode, useSQLMode } from "../languages/sql/sql-mode";
27
36
 
28
37
  interface SelectProps {
29
38
  selectedEngine: ConnectionName;
@@ -77,7 +86,7 @@ export const SQLEngineSelect: React.FC<SelectProps> = ({
77
86
  <SelectItem key={connection.name} value={connection.name}>
78
87
  <div className="flex items-center gap-1">
79
88
  <DatabaseLogo className="h-3 w-3" name={connection.dialect} />
80
- <span className="truncate">
89
+ <span className="truncate ml-0.5">
81
90
  {transformDisplayName(connection.display_name)}
82
91
  </span>
83
92
  </div>
@@ -88,9 +97,9 @@ export const SQLEngineSelect: React.FC<SelectProps> = ({
88
97
  return (
89
98
  <div className="flex flex-row gap-1 items-center">
90
99
  <Select value={selectedEngine} onValueChange={handleSelectEngine}>
91
- <SelectTrigger className="text-xs border-border shadow-none! ring-0! h-4.5 px-1.5">
100
+ <SQLSelectTrigger>
92
101
  <SelectValue placeholder="Select an engine" />
93
- </SelectTrigger>
102
+ </SQLSelectTrigger>
94
103
  <SelectContent>
95
104
  <SelectGroup>
96
105
  <SelectLabel>Database connections</SelectLabel>
@@ -130,3 +139,71 @@ export const SQLEngineSelect: React.FC<SelectProps> = ({
130
139
  const HELP_KEY = "__help__";
131
140
  const HELP_URL =
132
141
  "http://docs.marimo.io/guides/working_with_data/sql/#connecting-to-a-custom-database";
142
+
143
+ export const SQLModeSelect: React.FC = () => {
144
+ const { sqlMode, setSQLMode } = useSQLMode();
145
+
146
+ const handleToggleMode = () => {
147
+ setSQLMode(sqlMode === "validate" ? "default" : "validate");
148
+ };
149
+
150
+ const getModeIcon = (mode: SQLMode) => {
151
+ return mode === "validate" ? (
152
+ <SearchCheck className="h-3 w-3" />
153
+ ) : (
154
+ <DatabaseBackup className="h-3 w-3" />
155
+ );
156
+ };
157
+
158
+ const getTooltipContent = (mode: SQLMode) => {
159
+ return mode === "validate" ? (
160
+ <div className="text-xs">
161
+ <div className="font-semibold mb-1 flex flex-row items-center gap-1">
162
+ <SearchCheck className="h-3 w-3" />
163
+ Validate Mode
164
+ </div>
165
+ <p>Queries are validated as you write them</p>
166
+ </div>
167
+ ) : (
168
+ <div className="text-xs">
169
+ <div className="font-semibold mb-1 flex flex-row items-center gap-1">
170
+ <DatabaseBackup className="h-3 w-3" />
171
+ Default Mode
172
+ </div>
173
+ <p>Standard editing</p>
174
+ </div>
175
+ );
176
+ };
177
+
178
+ return (
179
+ <div className="flex flex-row gap-1 items-center">
180
+ <Tooltip delayDuration={300} content={getTooltipContent(sqlMode)}>
181
+ <Button
182
+ variant="ghost"
183
+ size="sm"
184
+ onClick={handleToggleMode}
185
+ className="h-5 px-1.5 text-xs border-border shadow-none hover:bg-accent"
186
+ >
187
+ {getModeIcon(sqlMode)}
188
+ <span className="ml-1">
189
+ {sqlMode === "validate" ? "Validate" : "Default"}
190
+ </span>
191
+ </Button>
192
+ </Tooltip>
193
+ </div>
194
+ );
195
+ };
196
+
197
+ const SQLSelectTrigger: React.FC<SelectTriggerProps> = ({
198
+ children,
199
+ ...props
200
+ }) => {
201
+ return (
202
+ <SelectTrigger
203
+ className="text-xs border-border shadow-none! ring-0! h-5 px-1.5 hover:bg-accent transition-colors"
204
+ {...props}
205
+ >
206
+ {children}
207
+ </SelectTrigger>
208
+ );
209
+ };
@@ -14,6 +14,7 @@ export interface ExperimentalFeatures {
14
14
  mcp_docs: boolean;
15
15
  sql_linter: boolean;
16
16
  external_agents: boolean;
17
+ sql_mode: boolean;
17
18
  // Add new feature flags here
18
19
  }
19
20
 
@@ -26,13 +27,14 @@ const defaultValues: ExperimentalFeatures = {
26
27
  mcp_docs: false,
27
28
  sql_linter: false,
28
29
  external_agents: import.meta.env.DEV,
30
+ sql_mode: false,
29
31
  };
30
32
 
31
33
  export function getFeatureFlag<T extends keyof ExperimentalFeatures>(
32
34
  feature: T,
33
35
  ): ExperimentalFeatures[T] {
34
36
  return (
35
- (getResolvedMarimoConfig().experimental?.[
37
+ (getResolvedMarimoConfig()?.experimental?.[
36
38
  feature
37
39
  ] as ExperimentalFeatures[T]) ?? defaultValues[feature]
38
40
  );
@@ -1,10 +1,15 @@
1
1
  /* Copyright 2024 Marimo. All rights reserved. */
2
- import type { SQLTableListPreview, SQLTablePreview } from "../kernel/messages";
2
+ import type {
3
+ SQLTableListPreview,
4
+ SQLTablePreview,
5
+ ValidateSQLResult,
6
+ } from "../kernel/messages";
3
7
  import { DeferredRequestRegistry } from "../network/DeferredRequestRegistry";
4
8
  import { getRequestClient } from "../network/requests";
5
9
  import type {
6
10
  PreviewSQLTableListRequest,
7
11
  PreviewSQLTableRequest,
12
+ ValidateSQLRequest,
8
13
  } from "../network/types";
9
14
 
10
15
  // We make a request to the backend to preview the table, passing in Engine, DB, Schema, and Table
@@ -32,3 +37,14 @@ export const PreviewSQLTableList = new DeferredRequestRegistry<
32
37
  ...req,
33
38
  });
34
39
  });
40
+
41
+ export const ValidateSQL = new DeferredRequestRegistry<
42
+ Omit<ValidateSQLRequest, "requestId">,
43
+ ValidateSQLResult
44
+ >("validate-sql", async (requestId, req) => {
45
+ const client = getRequestClient();
46
+ await client.validateSQL({
47
+ requestId: requestId,
48
+ ...req,
49
+ });
50
+ });
@@ -153,6 +153,7 @@ export class IslandsPyodideBridge implements RunRequests, EditRequests {
153
153
  previewSQLTable = throwNotImplemented;
154
154
  previewSQLTableList = throwNotImplemented;
155
155
  previewDataSourceConnection = throwNotImplemented;
156
+ validateSQL = throwNotImplemented;
156
157
  openFile = throwNotImplemented;
157
158
  sendListFiles = throwNotImplemented;
158
159
  sendSearchFiles = throwNotImplemented;
@@ -119,6 +119,7 @@ export async function initialize() {
119
119
  case "sql-table-list-preview":
120
120
  case "datasets":
121
121
  case "data-source-connections":
122
+ case "validate-sql-result":
122
123
  case "secret-keys-result":
123
124
  case "startup-logs":
124
125
  // Unsupported
@@ -38,6 +38,7 @@ export type DataColumnPreview = OperationMessageData<"data-column-preview">;
38
38
  export type SQLTablePreview = OperationMessageData<"sql-table-preview">;
39
39
  export type SQLTableListPreview =
40
40
  OperationMessageData<"sql-table-list-preview">;
41
+ export type ValidateSQLResult = OperationMessageData<"validate-sql-result">;
41
42
  export type SecretKeysResult = OperationMessageData<"secret-keys-result">;
42
43
  export type StartupLogs = OperationMessageData<"startup-logs">;
43
44
  export type CellMessage = OperationMessageData<"cell-op">;
@@ -207,6 +207,13 @@ export function createNetworkRequests(): EditRequests & RunRequests {
207
207
  })
208
208
  .then(handleResponseReturnNull);
209
209
  },
210
+ validateSQL: (request) => {
211
+ return getClient()
212
+ .POST("/api/sql/validate", {
213
+ body: request,
214
+ })
215
+ .then(handleResponseReturnNull);
216
+ },
210
217
  openFile: async (request) => {
211
218
  await waitForConnectionOpen();
212
219
  await getClient()
@@ -57,6 +57,7 @@ export function createStaticRequests(): EditRequests & RunRequests {
57
57
  previewSQLTable: throwNotInEditMode,
58
58
  previewSQLTableList: throwNotInEditMode,
59
59
  previewDataSourceConnection: throwNotInEditMode,
60
+ validateSQL: throwNotInEditMode,
60
61
  openFile: throwNotInEditMode,
61
62
  getUsageStats: throwNotInEditMode,
62
63
  sendListFiles: throwNotInEditMode,
@@ -35,6 +35,7 @@ export function createErrorToastingRequests(
35
35
  previewSQLTable: "Failed to fetch SQL table",
36
36
  previewSQLTableList: "Failed to fetch SQL table list",
37
37
  previewDataSourceConnection: "Failed to preview data source connection",
38
+ validateSQL: "Failed to validate SQL",
38
39
  openFile: "Failed to open file",
39
40
  getUsageStats: "", // No toast
40
41
  sendListFiles: "Failed to list files",
@@ -62,6 +62,7 @@ export type PreviewSQLTableRequest = schemas["PreviewSQLTableRequest"];
62
62
  export type PreviewSQLTableListRequest = schemas["PreviewSQLTableListRequest"];
63
63
  export type PreviewDataSourceConnectionRequest =
64
64
  schemas["PreviewDataSourceConnectionRequest"];
65
+ export type ValidateSQLRequest = schemas["ValidateSQLRequest"];
65
66
  export type PdbRequest = schemas["PdbRequest"];
66
67
  export type ReadCodeResponse = schemas["ReadCodeResponse"];
67
68
  export type RecentFilesResponse = schemas["RecentFilesResponse"];
@@ -140,6 +141,7 @@ export interface EditRequests {
140
141
  previewDataSourceConnection: (
141
142
  request: PreviewDataSourceConnectionRequest,
142
143
  ) => Promise<null>;
144
+ validateSQL: (request: ValidateSQLRequest) => Promise<null>;
143
145
  openFile: (request: { path: string }) => Promise<null>;
144
146
  getUsageStats: () => Promise<UsageResponse>;
145
147
  // Debugger
@@ -496,6 +496,11 @@ export class PyodideBridge implements RunRequests, EditRequests {
496
496
  return null;
497
497
  };
498
498
 
499
+ validateSQL: EditRequests["validateSQL"] = async (request) => {
500
+ await this.putControlRequest(request);
501
+ return null;
502
+ };
503
+
499
504
  sendModelValue: RunRequests["sendModelValue"] = async (request) => {
500
505
  await this.putControlRequest(request);
501
506
  return null;
@@ -32,6 +32,7 @@ import type { ConnectionName } from "../datasets/engines";
32
32
  import {
33
33
  PreviewSQLTable,
34
34
  PreviewSQLTableList,
35
+ ValidateSQL,
35
36
  } from "../datasets/request-registry";
36
37
  import { useDatasetsActions } from "../datasets/state";
37
38
  import { UI_ELEMENT_REGISTRY } from "../dom/uiregistry";
@@ -238,6 +239,9 @@ export function useMarimoWebSocket(opts: {
238
239
  case "sql-table-list-preview":
239
240
  PreviewSQLTableList.resolve(msg.data.request_id as RequestId, msg.data);
240
241
  return;
242
+ case "validate-sql-result":
243
+ ValidateSQL.resolve(msg.data.request_id as RequestId, msg.data);
244
+ return;
241
245
  case "secret-keys-result":
242
246
  SECRETS_REGISTRY.resolve(msg.data.request_id as RequestId, msg.data);
243
247
  return;
@@ -24,7 +24,7 @@ import ReactDOM, { type Root } from "react-dom/client";
24
24
  import useEvent from "react-use-event-hook";
25
25
  import type { ZodSchema } from "zod";
26
26
  import { notebookAtom } from "@/core/cells/cells.ts";
27
- import { findCellId } from "@/core/cells/ids.ts";
27
+ import { HTMLCellId } from "@/core/cells/ids.ts";
28
28
  import { isUninstantiated } from "@/core/cells/utils";
29
29
  import { createInputEvent, MarimoValueUpdateEvent } from "@/core/dom/events";
30
30
  import { getUIElementObjectId } from "@/core/dom/ui-element";
@@ -182,24 +182,28 @@ function PluginSlotInternal<T>(
182
182
  const objectId = getUIElementObjectId(hostElement);
183
183
  invariant(objectId, "Object ID should exist");
184
184
 
185
- const cellId = findCellId(hostElement);
186
- invariant(cellId, "Cell ID should exist");
187
-
188
- const notebookState = store.get(notebookAtom);
189
- const cellRuntime = notebookState.cellRuntime[cellId];
190
- const cellData = notebookState.cellData[cellId];
191
-
192
- const cellNotInitialized = isUninstantiated({
193
- executionTime:
194
- cellRuntime.runElapsedTimeMs ?? cellData.lastExecutionTime,
195
- status: cellRuntime.status,
196
- errored: cellRuntime.errored,
197
- interrupted: cellRuntime.interrupted,
198
- stopped: cellRuntime.stopped,
199
- });
200
-
201
- if (cellNotInitialized) {
202
- throw new CellNotInitializedError();
185
+ const htmlId = HTMLCellId.findElementThroughShadowDOMs(hostElement)?.id;
186
+ const cellId = htmlId ? HTMLCellId.parse(htmlId) : null;
187
+ if (cellId) {
188
+ // If the cell is not initialized, throw an error
189
+ const notebookState = store.get(notebookAtom);
190
+ const cellRuntime = notebookState.cellRuntime[cellId];
191
+ const cellData = notebookState.cellData[cellId];
192
+
193
+ const cellNotInitialized = isUninstantiated({
194
+ executionTime:
195
+ cellRuntime.runElapsedTimeMs ?? cellData.lastExecutionTime,
196
+ status: cellRuntime.status,
197
+ errored: cellRuntime.errored,
198
+ interrupted: cellRuntime.interrupted,
199
+ stopped: cellRuntime.stopped,
200
+ });
201
+
202
+ if (cellNotInitialized) {
203
+ throw new CellNotInitializedError();
204
+ }
205
+ } else {
206
+ Logger.warn(`Cell ID ${cellId} cannot be found`);
203
207
  }
204
208
 
205
209
  const response = await FUNCTIONS_REGISTRY.request({