@quantumwake/terminal-ux-dashboard-components 0.1.5 → 0.1.7

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/index.js CHANGED
@@ -8,6 +8,8 @@ import { ResponsiveHeatMap } from '@nivo/heatmap';
8
8
  import PivotTableUI from 'react-pivottable/PivotTableUI';
9
9
  import 'react-pivottable/pivottable.css';
10
10
  import { Loader2, Play, ChevronDown, AlertCircle, Rows3, BarChart3, PieChart, TrendingUp, ScatterChart, LayoutGrid, Code, Sparkles, X, Terminal, RefreshCw, Minimize2, Maximize2, Plus, Save, FolderOpen, Trash2, Filter, Database, Send, GripVertical } from 'lucide-react';
11
+ import CodeMirror, { EditorView, Prec, keymap } from '@uiw/react-codemirror';
12
+ import { sql } from '@codemirror/lang-sql';
11
13
 
12
14
  // src/context/DashboardContext.tsx
13
15
  var DashboardContext = createContext(null);
@@ -645,12 +647,12 @@ var renderCell = (v) => {
645
647
  };
646
648
  function SqlConsole({ columns = [], stateId, defaultColumnsOpen = false, defaultSql = DEFAULT_SQL, autoRun = false }) {
647
649
  const { theme, runQuery } = useDashboard();
648
- const [sql, setSql] = useState(defaultSql);
650
+ const [sql$1, setSql] = useState(defaultSql);
649
651
  const [result, setResult] = useState(null);
650
652
  const [error, setError] = useState(null);
651
653
  const [running, setRunning] = useState(false);
652
654
  const [columnsOpen, setColumnsOpen] = useState(defaultColumnsOpen);
653
- const run = async (text = sql) => {
655
+ const run = async (text = sql$1) => {
654
656
  if (running || !text.trim()) return;
655
657
  setRunning(true);
656
658
  setError(null);
@@ -669,12 +671,24 @@ function SqlConsole({ columns = [], stateId, defaultColumnsOpen = false, default
669
671
  setSql(defaultSql);
670
672
  void run(defaultSql);
671
673
  }, [stateId, autoRun, defaultSql]);
672
- const onKeyDown = (e) => {
673
- if ((e.metaKey || e.ctrlKey) && e.key === "Enter") {
674
- e.preventDefault();
675
- void run();
676
- }
674
+ const runRef = useRef(() => {
675
+ });
676
+ runRef.current = () => {
677
+ void run();
677
678
  };
679
+ const schemaKey = columns.map((c) => c.name).join(",");
680
+ const extensions = useMemo(
681
+ () => [
682
+ sql({ schema: { data: columns.map((c) => c.name) }, upperCaseKeywords: true }),
683
+ EditorView.lineWrapping,
684
+ Prec.highest(keymap.of([{ key: "Mod-Enter", run: () => {
685
+ runRef.current();
686
+ return true;
687
+ } }]))
688
+ ],
689
+ [schemaKey]
690
+ // eslint-disable-line react-hooks/exhaustive-deps
691
+ );
678
692
  const resultColumns = result?.columns || [];
679
693
  return /* @__PURE__ */ jsxs("div", { className: "flex flex-col h-full", children: [
680
694
  /* @__PURE__ */ jsxs("div", { className: `border-b ${theme.border} bg-midnight-elevated p-3 shrink-0`, children: [
@@ -687,7 +701,7 @@ function SqlConsole({ columns = [], stateId, defaultColumnsOpen = false, default
687
701
  "button",
688
702
  {
689
703
  onClick: () => void run(),
690
- disabled: running || !sql.trim(),
704
+ disabled: running || !sql$1.trim(),
691
705
  className: `flex items-center gap-1.5 px-3 py-1 border text-xs font-mono transition-colors ${running ? "border-midnight-border opacity-50" : "border-midnight-accent text-midnight-accent hover:bg-midnight-accent/10"}`,
692
706
  children: [
693
707
  running ? /* @__PURE__ */ jsx(Loader2, { className: "w-3.5 h-3.5 animate-spin" }) : /* @__PURE__ */ jsx(Play, { className: "w-3.5 h-3.5" }),
@@ -698,15 +712,16 @@ function SqlConsole({ columns = [], stateId, defaultColumnsOpen = false, default
698
712
  )
699
713
  ] }),
700
714
  /* @__PURE__ */ jsx(
701
- "textarea",
715
+ CodeMirror,
702
716
  {
703
- value: sql,
704
- onChange: (e) => setSql(e.target.value),
705
- onKeyDown,
706
- spellCheck: false,
707
- rows: 5,
708
- className: "w-full bg-midnight-surface border border-midnight-border px-3 py-2 text-sm font-mono outline-none text-midnight-text-body resize-y focus:border-midnight-accent transition-colors",
709
- placeholder: "SELECT ... FROM data"
717
+ value: sql$1,
718
+ onChange: setSql,
719
+ extensions,
720
+ theme: "dark",
721
+ basicSetup: { lineNumbers: false, foldGutter: false, highlightActiveLine: false },
722
+ height: "120px",
723
+ placeholder: "SELECT ... FROM data",
724
+ className: "border border-midnight-border text-sm overflow-hidden focus-within:border-midnight-accent"
710
725
  }
711
726
  ),
712
727
  columns.length > 0 && /* @__PURE__ */ jsxs("div", { className: "mt-2", children: [