@duckcodeailabs/dql-cli 0.2.0 → 0.2.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.
@@ -1,312 +0,0 @@
1
- import{r as be,a as Te,g as Re}from"./react-CRB3T2We.js";import{k as Ae,i as Oe,d as _e,E as V,o as Fe,s as De,l as $e,h as Ie,a as Ne}from"./codemirror-CHXCUnwU.js";(function(){const o=document.createElement("link").relList;if(o&&o.supports&&o.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))r(i);new MutationObserver(i=>{for(const l of i)if(l.type==="childList")for(const a of l.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&r(a)}).observe(document,{childList:!0,subtree:!0});function n(i){const l={};return i.integrity&&(l.integrity=i.integrity),i.referrerPolicy&&(l.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?l.credentials="include":i.crossOrigin==="anonymous"?l.credentials="omit":l.credentials="same-origin",l}function r(i){if(i.ep)return;i.ep=!0;const l=n(i);fetch(i.href,l)}})();var Y={exports:{}},P={};/**
2
- * @license React
3
- * react-jsx-runtime.production.min.js
4
- *
5
- * Copyright (c) Facebook, Inc. and its affiliates.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */var le;function He(){if(le)return P;le=1;var t=be(),o=Symbol.for("react.element"),n=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,i=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,l={key:!0,ref:!0,__self:!0,__source:!0};function a(s,c,h){var d,p={},u=null,g=null;h!==void 0&&(u=""+h),c.key!==void 0&&(u=""+c.key),c.ref!==void 0&&(g=c.ref);for(d in c)r.call(c,d)&&!l.hasOwnProperty(d)&&(p[d]=c[d]);if(s&&s.defaultProps)for(d in c=s.defaultProps,c)p[d]===void 0&&(p[d]=c[d]);return{$$typeof:o,type:s,key:u,ref:g,props:p,_owner:i.current}}return P.Fragment=n,P.jsx=a,P.jsxs=a,P}var se;function ze(){return se||(se=1,Y.exports=He()),Y.exports}var e=ze(),U={},ae;function Pe(){if(ae)return U;ae=1;var t=Te();return U.createRoot=t.createRoot,U.hydrateRoot=t.hydrateRoot,U}var We=Pe(),f=be();const Q=Re(f),qe={themeMode:"dark",sidebarPanel:"files",sidebarOpen:!0,files:[],filesLoading:!1,activeFile:null,cells:[],notebookTitle:"",notebookDirty:!1,schemaTables:[],schemaLoading:!1,devPanelOpen:!1,devPanelTab:"logs",queryLog:[],newNotebookModalOpen:!1,executionCounter:0,savingFile:!1};function Ze(t,o){switch(o.type){case"SET_THEME":return{...t,themeMode:o.mode};case"SET_SIDEBAR_PANEL":return{...t,sidebarPanel:o.panel,sidebarOpen:o.panel!==null};case"TOGGLE_SIDEBAR":return{...t,sidebarOpen:!t.sidebarOpen};case"SET_FILES":return{...t,files:o.files};case"SET_FILES_LOADING":return{...t,filesLoading:o.loading};case"OPEN_FILE":return{...t,activeFile:o.file,cells:o.cells,notebookTitle:o.title,notebookDirty:!1};case"SET_CELLS":return{...t,cells:o.cells,notebookDirty:!0};case"ADD_CELL":{if(!o.afterId)return{...t,cells:[...t.cells,o.cell],notebookDirty:!0};const n=t.cells.findIndex(i=>i.id===o.afterId);if(n===-1)return{...t,cells:[...t.cells,o.cell],notebookDirty:!0};const r=[...t.cells];return r.splice(n+1,0,o.cell),{...t,cells:r,notebookDirty:!0}}case"UPDATE_CELL":{const n=t.cells.map(i=>i.id===o.id?{...i,...o.updates}:i),r=o.updates.executionCount!==void 0?t.executionCounter+1:t.executionCounter;return{...t,cells:n,notebookDirty:!0,executionCounter:r}}case"DELETE_CELL":return{...t,cells:t.cells.filter(n=>n.id!==o.id),notebookDirty:!0};case"MOVE_CELL":{const n=t.cells.findIndex(i=>i.id===o.id);if(n===-1)return t;const r=[...t.cells];return o.direction==="up"&&n>0?[r[n-1],r[n]]=[r[n],r[n-1]]:o.direction==="down"&&n<r.length-1&&([r[n],r[n+1]]=[r[n+1],r[n]]),{...t,cells:r,notebookDirty:!0}}case"SET_SCHEMA":return{...t,schemaTables:o.tables};case"SET_SCHEMA_LOADING":return{...t,schemaLoading:o.loading};case"TOGGLE_SCHEMA_TABLE":return{...t,schemaTables:t.schemaTables.map(n=>n.name===o.tableName?{...n,expanded:!n.expanded}:n)};case"TOGGLE_DEV_PANEL":return{...t,devPanelOpen:!t.devPanelOpen};case"SET_DEV_PANEL_TAB":return{...t,devPanelTab:o.tab};case"APPEND_QUERY_LOG":return{...t,queryLog:[...t.queryLog,o.entry]};case"OPEN_NEW_NOTEBOOK_MODAL":return{...t,newNotebookModalOpen:!0};case"CLOSE_NEW_NOTEBOOK_MODAL":return{...t,newNotebookModalOpen:!1};case"SET_NOTEBOOK_DIRTY":return{...t,notebookDirty:o.dirty};case"SET_SAVING":return{...t,savingFile:o.saving};case"FILE_ADDED":return{...t,files:[...t.files,o.file]};case"SET_TABLE_COLUMNS":return{...t,schemaTables:t.schemaTables.map(n=>n.name===o.tableName?{...n,columns:o.columns}:n)};case"SET_PARAM_VALUE":return{...t,cells:t.cells.map(n=>n.id===o.id?{...n,paramValue:o.value}:n),notebookDirty:!0};default:return t}}const ve=f.createContext(null);function Ve({children:t}){const[o,n]=f.useReducer(Ze,qe);return e.jsx(ve.Provider,{value:{state:o,dispatch:n},children:t})}function w(){const t=f.useContext(ve);if(!t)throw new Error("useNotebook must be used within NotebookProvider");return t}function F(){return`cell_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function A(t,o=""){const n={id:F(),type:t,content:o,status:"idle"};return t==="param"&&(n.content="",n.paramConfig={paramType:"text",label:"Parameter",defaultValue:"",options:[]}),n}const Ue={appBg:"#0d1117",sidebarBg:"#161b22",activityBarBg:"#0d1117",headerBg:"#161b22",headerBorder:"#21262d",cellBg:"#161b22",cellBorder:"#30363d",cellBorderActive:"#388bfd",cellBorderRunning:"#56d364",textPrimary:"#e6edf3",textSecondary:"#8b949e",textMuted:"#484f58",editorBg:"#0d1117",editorBorder:"#30363d",tableBorder:"#30363d",tableHeaderBg:"#1c2128",tableRowHover:"#21262d",accent:"#388bfd",accentHover:"#58a6ff",success:"#56d364",error:"#f85149",warning:"#e3b341",btnBg:"#21262d",btnBorder:"#30363d",btnHover:"#30363d",sidebarItemHover:"#21262d",sidebarItemActive:"#1f2d3d",scrollbarThumb:"#30363d",modalBg:"#161b22",modalOverlay:"rgba(0,0,0,0.7)",inputBg:"#0d1117",inputBorder:"#30363d",pillBg:"#21262d",font:"Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif",fontMono:"'JetBrains Mono', 'Fira Code', Consolas, monospace",fontSerif:"Georgia, 'Times New Roman', serif"},Qe={appBg:"#ffffff",sidebarBg:"#f6f8fa",activityBarBg:"#eff1f3",headerBg:"#ffffff",headerBorder:"#d0d7de",cellBg:"#ffffff",cellBorder:"#d0d7de",cellBorderActive:"#0969da",cellBorderRunning:"#1f883d",textPrimary:"#1f2328",textSecondary:"#57606a",textMuted:"#8c959f",editorBg:"#f6f8fa",editorBorder:"#d0d7de",tableBorder:"#d0d7de",tableHeaderBg:"#f6f8fa",tableRowHover:"#f6f8fa",accent:"#0969da",accentHover:"#0550ae",success:"#1f883d",error:"#cf222e",warning:"#9a6700",btnBg:"#f6f8fa",btnBorder:"#d0d7de",btnHover:"#eaeef2",sidebarItemHover:"#eaeef2",sidebarItemActive:"#dbeafe",scrollbarThumb:"#d0d7de",modalBg:"#ffffff",modalOverlay:"rgba(0,0,0,0.4)",inputBg:"#ffffff",inputBorder:"#d0d7de",pillBg:"#eaeef2",font:"Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif",fontMono:"'JetBrains Mono', 'Fira Code', Consolas, monospace",fontSerif:"Georgia, 'Times New Roman', serif"},S={dark:Ue,light:Qe};function H({title:t,active:o,onClick:n,children:r,t:i}){const[l,a]=f.useState(!1);return e.jsx("button",{title:t,onClick:n,onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",background:"transparent",border:"none",borderLeft:o?`2px solid ${i.accent}`:"2px solid transparent",cursor:"pointer",color:o?i.textPrimary:l?i.textSecondary:i.textMuted,transition:"color 0.15s, border-color 0.15s",padding:0,flexShrink:0},children:r})}function Ge(){return e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M1.75 1A1.75 1.75 0 0 0 0 2.75v10.5C0 14.216.784 15 1.75 15h12.5A1.75 1.75 0 0 0 16 13.25v-8.5A1.75 1.75 0 0 0 14.25 3H7.5a.25.25 0 0 1-.2-.1l-.9-1.2C6.07 1.26 5.55 1 5 1H1.75Z"})})}function Ye(){return e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M8 0C3.58 0 0 1.567 0 3.5v9C0 14.433 3.58 16 8 16s8-1.567 8-3.5v-9C16 1.567 12.42 0 8 0ZM1.5 7.784V5.716C3.05 6.51 5.404 7 8 7s4.95-.49 6.5-1.284v2.068C12.95 8.578 10.596 9 8 9s-4.95-.422-6.5-1.216ZM8 1.5c3.17 0 5.854 1.116 6.357 2.5H1.643C2.146 2.616 4.83 1.5 8 1.5Zm0 13c-3.17 0-5.854-1.116-6.357-2.5h12.714C13.854 13.384 11.17 14.5 8 14.5Zm6.5-3.284C12.95 11.01 10.596 11.5 8 11.5s-4.95-.49-6.5-1.284V8.216C3.05 9.01 5.404 9.5 8 9.5s4.95-.49 6.5-1.284v2.5Z"})})}function Ke(){return e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M2 2h12a1 1 0 0 1 0 2H2a1 1 0 0 1 0-2Zm0 4h8a1 1 0 0 1 0 2H2a1 1 0 0 1 0-2Zm0 4h10a1 1 0 0 1 0 2H2a1 1 0 0 1 0-2Z"})})}function Je(){return e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M1 2.75C1 1.784 1.784 1 2.75 1h2.5C6.216 1 7 1.784 7 2.75v2.5C7 6.216 6.216 7 5.25 7h-2.5C1.784 7 1 6.216 1 5.25Zm1.75-.25a.25.25 0 0 0-.25.25v2.5c0 .138.112.25.25.25h2.5A.25.25 0 0 0 6 5.25v-2.5A.25.25 0 0 0 5.25 2.5ZM9 2.75C9 1.784 9.784 1 10.75 1h2.5C14.216 1 15 1.784 15 2.75v2.5C15 6.216 14.216 7 13.25 7h-2.5C9.784 7 9 6.216 9 5.25Zm1.75-.25a.25.25 0 0 0-.25.25v2.5c0 .138.112.25.25.25h2.5a.25.25 0 0 0 .25-.25v-2.5a.25.25 0 0 0-.25-.25ZM1 10.75C1 9.784 1.784 9 2.75 9h2.5C6.216 9 7 9.784 7 10.75v2.5C7 14.216 6.216 15 5.25 15h-2.5C1.784 15 1 14.216 1 13.25Zm1.75-.25a.25.25 0 0 0-.25.25v2.5c0 .138.112.25.25.25h2.5a.25.25 0 0 0 .25-.25v-2.5a.25.25 0 0 0-.25-.25ZM13 9.75a.75.75 0 0 1 .75.75v1.75H15.5a.75.75 0 0 1 0 1.5h-1.75V15.5a.75.75 0 0 1-1.5 0v-1.75H10.5a.75.75 0 0 1 0-1.5h1.75V10.5A.75.75 0 0 1 13 9.75Z"})})}function Xe(){return e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M0 1.75A.75.75 0 0 1 .75 1h4.253c1.227 0 2.317.59 3 1.501A3.743 3.743 0 0 1 11.006 1h4.245a.75.75 0 0 1 .75.75v10.5a.75.75 0 0 1-.75.75h-4.507a2.25 2.25 0 0 0-1.591.659l-.622.621a.75.75 0 0 1-1.06 0l-.622-.621A2.25 2.25 0 0 0 5.258 13H.75a.75.75 0 0 1-.75-.75Zm7.251 10.324.004-5.073-.002-2.253A2.25 2.25 0 0 0 5.003 2.5H1.5v9h3.757a3.75 3.75 0 0 1 1.994.574ZM8.755 4.75l-.004 7.322a3.752 3.752 0 0 1 1.992-.572H14.5v-9h-3.495a2.25 2.25 0 0 0-2.25 2.25Z"})})}function et(){return e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.92 6.085h.001a.749.749 0 1 1-1.342-.67C6.03 4.26 6.88 3.75 8 3.75c1.463 0 2.5 1.008 2.5 2.25 0 1.133-.67 1.8-1.4 2.25-.487.3-.6.47-.6.75V9.5a.75.75 0 0 1-1.5 0v-.5c0-.833.585-1.33 1.1-1.65.387-.24.9-.597.9-1.35 0-.65-.53-1.25-1.5-1.25-.74 0-1.163.353-1.58.835ZM8 12a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z"})})}function tt(){return e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M8 0a8.2 8.2 0 0 1 .701.031C9.444.095 9.99.645 10.16 1.29l.288 1.107c.018.066.079.158.212.224.231.114.454.243.668.386.123.082.233.09.299.071l1.103-.303c.644-.176 1.392.021 1.82.63.27.385.506.792.704 1.218.315.675.111 1.422-.364 1.891l-.814.806c-.049.048-.098.147-.088.294.016.257.016.515 0 .772-.01.147.038.246.088.294l.814.806c.475.469.679 1.216.364 1.891a7.977 7.977 0 0 1-.704 1.217c-.428.61-1.176.807-1.82.63l-1.103-.303c-.066-.019-.176-.011-.299.071a5.909 5.909 0 0 1-.668.386c-.133.066-.194.158-.211.224l-.29 1.106c-.168.646-.715 1.196-1.458 1.26a8.006 8.006 0 0 1-1.402 0c-.743-.064-1.289-.614-1.458-1.26l-.289-1.106c-.018-.066-.079-.158-.212-.224a5.738 5.738 0 0 1-.668-.386c-.123-.082-.233-.09-.299-.071l-1.103.303c-.644.176-1.392-.021-1.82-.63a8.12 8.12 0 0 1-.704-1.218c-.315-.675-.111-1.422.363-1.891l.815-.806c.05-.048.098-.147.088-.294a6.214 6.214 0 0 1 0-.772c.01-.147-.038-.246-.088-.294l-.815-.806C.635 6.045.431 5.298.746 4.623a7.92 7.92 0 0 1 .704-1.217c.428-.61 1.176-.807 1.82-.63l1.103.303c.066.019.176.011.299-.071.214-.143.437-.272.668-.386.133-.066.194-.158.211-.224l.29-1.106C6.009.645 6.556.095 7.299.03 7.53.01 7.764 0 8 0Zm-.571 1.525c-.036.003-.108.036-.137.146l-.289 1.105c-.147.561-.549.967-.998 1.189-.173.086-.34.183-.5.29-.417.278-.97.423-1.529.27l-1.103-.303c-.109-.03-.175.016-.195.045-.22.312-.412.644-.573.99-.014.031-.021.11.059.19l.815.806c.411.406.562.957.53 1.456a4.709 4.709 0 0 0 0 .582c.032.499-.119 1.05-.53 1.456l-.815.806c-.081.08-.073.159-.059.19.162.346.353.677.573.989.02.03.085.076.195.046l1.102-.303c.56-.153 1.113-.008 1.53.27.161.107.328.204.501.29.447.222.85.629.997 1.189l.289 1.105c.029.109.101.143.137.146a6.6 6.6 0 0 0 1.142 0c.036-.003.108-.036.137-.146l.289-1.105c.147-.561.549-.967.998-1.189.173-.086.34-.183.5-.29.417-.278.97-.423 1.529-.27l1.103.303c.109.029.175-.016.195-.045.22-.313.411-.644.573-.99.014-.031.021-.11-.059-.19l-.815-.806c-.411-.406-.562-.957-.53-1.456a4.709 4.709 0 0 0 0-.582c-.032-.499.119-1.05.53-1.456l.815-.806c.081-.08.073-.159.059-.19a6.464 6.464 0 0 0-.573-.989c-.02-.03-.085-.076-.195-.046l-1.102.303c-.56.153-1.113.008-1.53-.27a4.44 4.44 0 0 0-.501-.29c-.447-.222-.85-.629-.997-1.189l-.289-1.105c-.029-.11-.101-.143-.137-.147a6.6 6.6 0 0 0-1.142 0ZM8 5.5a2.5 2.5 0 1 1 0 5 2.5 2.5 0 0 1 0-5ZM8 7a1 1 0 1 0 0 2 1 1 0 0 0 0-2Z"})})}function nt(){const{state:t,dispatch:o}=w(),n=S[t.themeMode];function r(i){t.sidebarPanel===i&&t.sidebarOpen?o({type:"TOGGLE_SIDEBAR"}):o({type:"SET_SIDEBAR_PANEL",panel:i})}return e.jsxs("div",{style:{width:32,flexShrink:0,background:n.activityBarBg,borderRight:`1px solid ${n.headerBorder}`,display:"flex",flexDirection:"column",alignItems:"center",paddingTop:8,paddingBottom:8,gap:2,userSelect:"none"},children:[e.jsx(H,{title:"Files",active:t.sidebarPanel==="files"&&t.sidebarOpen,onClick:()=>r("files"),t:n,children:e.jsx(Ge,{})}),e.jsx(H,{title:"Schema",active:t.sidebarPanel==="schema"&&t.sidebarOpen,onClick:()=>r("schema"),t:n,children:e.jsx(Ye,{})}),e.jsx(H,{title:"Outline",active:t.sidebarPanel==="outline"&&t.sidebarOpen,onClick:()=>r("outline"),t:n,children:e.jsx(Ke,{})}),e.jsx(H,{title:"Connection",active:t.sidebarPanel==="connection"&&t.sidebarOpen,onClick:()=>r("connection"),t:n,children:e.jsx(Je,{})}),e.jsx(H,{title:"Reference",active:t.sidebarPanel==="reference"&&t.sidebarOpen,onClick:()=>r("reference"),t:n,children:e.jsx(Xe,{})}),e.jsx("div",{style:{flex:1}}),e.jsx(H,{title:"Help",active:!1,onClick:()=>{},t:n,children:e.jsx(et,{})}),e.jsx(H,{title:"Settings",active:!1,onClick:()=>{},t:n,children:e.jsx(tt,{})})]})}const K={notebooks:"Notebooks",workbooks:"Workbooks",blocks:"Blocks",dashboards:"Dashboards"};function ot({type:t}){switch(t){case"notebook":return e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M0 1.75A.75.75 0 0 1 .75 1h4.253c1.227 0 2.317.59 3 1.501A3.743 3.743 0 0 1 11.006 1h4.245a.75.75 0 0 1 .75.75v10.5a.75.75 0 0 1-.75.75h-4.507a2.25 2.25 0 0 0-1.591.659l-.622.621a.75.75 0 0 1-1.063 0L7.597 13.66A2.25 2.25 0 0 0 6.007 13H.75a.75.75 0 0 1-.75-.75Zm7.251 10.324.004-5.073-.002-2.253A2.25 2.25 0 0 0 5.003 2.5H1.5v9h4.507c.656 0 1.287.169 1.744.324Zm1.499.004c.457-.155 1.088-.324 1.744-.324H15v-9h-3.495a2.25 2.25 0 0 0-2.252 2.247l-.002 9.077Z"})});case"workbook":return e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M2 1.75C2 .784 2.784 0 3.75 0h8.5C13.216 0 14 .784 14 1.75v12.5A1.75 1.75 0 0 1 12.25 16h-8.5A1.75 1.75 0 0 1 2 14.25Zm1.75-.25a.25.25 0 0 0-.25.25v12.5c0 .138.112.25.25.25h8.5a.25.25 0 0 0 .25-.25V1.75a.25.25 0 0 0-.25-.25Zm2 3.5a.75.75 0 0 1 .75-.75h3a.75.75 0 0 1 0 1.5h-3a.75.75 0 0 1-.75-.75ZM6.5 7.25a.75.75 0 0 0 0 1.5h3a.75.75 0 0 0 0-1.5Zm-.75 3.5a.75.75 0 0 1 .75-.75h3a.75.75 0 0 1 0 1.5h-3a.75.75 0 0 1-.75-.75Z"})});case"block":return e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M10.5 0l5.25 4-5.25 4V6H9.25A1.75 1.75 0 0 0 7.5 7.75v2.5A1.75 1.75 0 0 0 9.25 12h1.25v8H9v-6.5A3.25 3.25 0 0 1 5.75 10h-2A3.25 3.25 0 0 1 .5 6.75v-2.5A3.25 3.25 0 0 1 3.75 1h2A3.25 3.25 0 0 1 9 4.5V6h1.5V0z"})});default:return e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M.24 2.375C.24 1.064 1.225.001 2.409.001h6.451a1.17 1.17 0 0 1 .828.344l3.311 3.312a1.17 1.17 0 0 1 .344.828v9.14c0 1.31-.985 2.374-2.169 2.374H2.41C1.225 16 .24 14.937.24 13.625Zm2.169-1a.846.846 0 0 0-.844.86v11.39c0 .47.38.86.844.86h8.774a.847.847 0 0 0 .844-.86V5.157L8.688 1.373H2.41Z"})})}}function rt({expanded:t}){return e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"currentColor",children:t?e.jsx("path",{d:"M1.75 2.5a.25.25 0 0 0-.25.25v10.5c0 .138.112.25.25.25h12.5a.25.25 0 0 0 .25-.25V4.25a.25.25 0 0 0-.25-.25H7.5A1.75 1.75 0 0 1 5.75 2.5h-4ZM0 2.75C0 1.784.784 1 1.75 1h4c.966 0 1.75.784 1.75 1.75H14.25c.966 0 1.75.784 1.75 1.75v8.5A1.75 1.75 0 0 1 14.25 14H1.75A1.75 1.75 0 0 1 0 12.25Z"}):e.jsx("path",{d:"M1.75 2.5a.25.25 0 0 0-.25.25v10.5c0 .138.112.25.25.25h12.5a.25.25 0 0 0 .25-.25V4.25a.25.25 0 0 0-.25-.25H7.5A1.75 1.75 0 0 1 5.75 2.5h-4ZM0 2.75C0 1.784.784 1 1.75 1h4c.966 0 1.75.784 1.75 1.75H14.25c.966 0 1.75.784 1.75 1.75v8.5A1.75 1.75 0 0 1 14.25 14H1.75A1.75 1.75 0 0 1 0 12.25Z"})})}function it(t){return t.name.replace(/\.(dqlnb|dql)$/,"")}function lt({onOpenFile:t}){const{state:o,dispatch:n}=w(),r=S[o.themeMode],[i,l]=f.useState({notebooks:!0,workbooks:!0,blocks:!1,dashboards:!1}),[a,s]=f.useState(!1),c={notebooks:[],workbooks:[],blocks:[],dashboards:[]};for(const d of o.files){const p=d.folder.toLowerCase();p in c&&c[p].push(d)}const h=d=>{l(p=>({...p,[d]:!p[d]}))};return e.jsxs("div",{style:{flex:1,overflow:"auto",padding:"8px 0",display:"flex",flexDirection:"column",gap:0},children:[e.jsx("div",{style:{padding:"0 8px 8px"},children:e.jsxs("button",{onClick:()=>n({type:"OPEN_NEW_NOTEBOOK_MODAL"}),onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),style:{width:"100%",height:30,background:"transparent",border:`1px dashed ${a?r.accent:r.cellBorder}`,borderRadius:6,color:a?r.accent:r.textSecondary,cursor:"pointer",fontSize:12,fontFamily:r.font,fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",gap:6,transition:"border-color 0.15s, color 0.15s"},children:[e.jsx("span",{style:{fontSize:16,lineHeight:1},children:"+"}),"New Notebook"]})}),o.filesLoading&&e.jsx("div",{style:{padding:"8px 14px",color:r.textMuted,fontSize:12,fontFamily:r.font},children:"Loading files…"}),Object.keys(K).map(d=>{const p=c[d],u=i[d];return e.jsxs("div",{children:[e.jsx(st,{label:K[d],count:p.length,expanded:u,onToggle:()=>h(d),t:r}),u&&e.jsx("div",{children:p.length===0?e.jsxs("div",{style:{padding:"4px 14px 4px 32px",fontSize:12,color:r.textMuted,fontFamily:r.font,fontStyle:"italic"},children:["No ",K[d].toLowerCase()]}):p.map(g=>{var x;return e.jsx(at,{file:g,active:((x=o.activeFile)==null?void 0:x.path)===g.path,onClick:()=>t(g),t:r},g.path)})})]},d)})]})}function st({label:t,count:o,expanded:n,onToggle:r,t:i}){const[l,a]=f.useState(!1);return e.jsxs("button",{onClick:r,onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),style:{width:"100%",display:"flex",alignItems:"center",gap:6,padding:"3px 8px 3px 10px",background:l?i.sidebarItemHover:"transparent",border:"none",cursor:"pointer",color:i.textSecondary,fontSize:11,fontWeight:600,fontFamily:i.font,letterSpacing:"0.04em",textTransform:"uppercase",textAlign:"left",transition:"background 0.1s"},children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"currentColor",style:{transform:n?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.15s",flexShrink:0},children:e.jsx("path",{d:"M3 2l4 3-4 3V2Z"})}),e.jsx(rt,{expanded:n}),e.jsx("span",{style:{flex:1},children:t}),o>0&&e.jsx("span",{style:{background:i.pillBg,color:i.textMuted,borderRadius:10,padding:"0 5px",fontSize:10,fontWeight:500},children:o})]})}function at({file:t,active:o,onClick:n,t:r}){const[i,l]=f.useState(!1);return e.jsxs("button",{onClick:n,onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),style:{width:"100%",display:"flex",alignItems:"center",gap:6,padding:"4px 8px 4px 26px",background:o?r.sidebarItemActive:i?r.sidebarItemHover:"transparent",border:"none",borderLeft:o?`2px solid ${r.accent}`:"2px solid transparent",cursor:"pointer",color:o||i?r.textPrimary:r.textSecondary,fontSize:13,fontFamily:r.font,textAlign:"left",transition:"background 0.1s, color 0.1s",overflow:"hidden"},children:[e.jsx("span",{style:{flexShrink:0,color:o?r.accent:r.textMuted},children:e.jsx(ot,{type:t.type})}),e.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:it(t)}),t.isNew&&e.jsx("span",{style:{fontSize:9,fontWeight:600,color:r.accent,background:r.sidebarItemActive,borderRadius:4,padding:"1px 4px",flexShrink:0},children:"NEW"})]})}const dt=window.location.origin;async function _(t,o){const n=await fetch(`${dt}${t}`,{headers:{"Content-Type":"application/json"},...o});if(!n.ok){const r=await n.text().catch(()=>n.statusText);throw new Error(r||`HTTP ${n.status}`)}if(n.status!==204)return n.json()}const B={async listNotebooks(){try{return await _("/api/notebooks")}catch{return[]}},async readNotebook(t){return _(`/api/notebook-content?path=${encodeURIComponent(t)}`)},async createNotebook(t,o){return _("/api/notebooks",{method:"POST",body:JSON.stringify({name:t,template:o})})},async saveNotebook(t,o){return _("/api/notebook-content",{method:"PUT",body:JSON.stringify({path:t,content:o})})},async executeQuery(t){return _("/api/query",{method:"POST",body:JSON.stringify({sql:t})})},async getSchema(){try{return await _("/api/schema")}catch{return[]}},async getConnections(){try{return await _("/api/connections")}catch{return{default:"unknown",connections:{}}}},async testConnection(){try{return await _("/api/test-connection",{method:"POST",body:JSON.stringify({})})}catch(t){return{ok:!1,message:t.message??"Connection failed"}}},async describeTable(t){const n=`DESCRIBE SELECT * FROM read_csv_auto('${t.replace(/'/g,"''")}') LIMIT 0`;try{return(await _("/api/query",{method:"POST",body:JSON.stringify({sql:n})})).rows.map(i=>({name:String(i.column_name??i.Field??""),type:String(i.column_type??i.Type??"")}))}catch{return[]}}},ct={varchar:"#388bfd",text:"#388bfd",string:"#388bfd",char:"#388bfd",integer:"#56d364",int:"#56d364",bigint:"#56d364",smallint:"#56d364",float:"#56d364",double:"#56d364",decimal:"#56d364",numeric:"#56d364",real:"#56d364",date:"#e3b341",timestamp:"#e3b341",datetime:"#e3b341",time:"#e3b341",boolean:"#f778ba",bool:"#f778ba",json:"#79c0ff",jsonb:"#79c0ff",uuid:"#d2a8ff",bytea:"#ffa657",binary:"#ffa657"};function de(t,o){const n=t.toLowerCase().split("(")[0].trim();return ct[n]??o}function ut({t}){return e.jsxs("div",{style:{padding:"8px 12px",display:"flex",flexDirection:"column",gap:8},children:[[1,2,3].map(o=>e.jsx("div",{style:{height:28,borderRadius:4,background:t.pillBg,opacity:.6,animation:"pulse 1.5s ease-in-out infinite"}},o)),e.jsx("style",{children:"@keyframes pulse { 0%,100%{opacity:.6} 50%{opacity:.3} }"})]})}function pt(){const{state:t,dispatch:o}=w(),n=S[t.themeMode],[r,i]=f.useState(!1),l=async()=>{o({type:"SET_SCHEMA_LOADING",loading:!0});try{const a=await B.getSchema();o({type:"SET_SCHEMA",tables:a})}catch(a){console.error("Schema refresh failed:",a)}finally{o({type:"SET_SCHEMA_LOADING",loading:!1})}};return e.jsxs("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{padding:"8px 10px",display:"flex",alignItems:"center",gap:6,borderBottom:`1px solid ${n.headerBorder}`},children:[e.jsxs("span",{style:{flex:1,fontSize:11,color:n.textMuted,fontFamily:n.font},children:[t.schemaTables.length," tables"]}),e.jsxs("button",{onClick:l,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),title:"Refresh schema",style:{background:r?n.btnHover:"transparent",border:`1px solid ${r?n.btnBorder:"transparent"}`,borderRadius:4,cursor:"pointer",color:r?n.textSecondary:n.textMuted,fontSize:11,fontFamily:n.font,padding:"2px 6px",display:"flex",alignItems:"center",gap:4,transition:"all 0.15s"},children:[e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M1.705 8.005a.75.75 0 0 1 .834.656 5.5 5.5 0 0 0 9.592 2.97l-1.204-1.204a.25.25 0 0 1 .177-.427h3.646a.25.25 0 0 1 .25.25v3.646a.25.25 0 0 1-.427.177l-1.38-1.38A7.002 7.002 0 0 1 1.05 8.84a.75.75 0 0 1 .656-.834ZM8 2.5a5.487 5.487 0 0 0-4.131 1.869l1.204 1.204A.25.25 0 0 1 4.896 6H1.25A.25.25 0 0 1 1 5.75V2.104a.25.25 0 0 1 .427-.177l1.38 1.38A7.002 7.002 0 0 1 14.95 7.16a.75.75 0 0 1-1.49.178A5.5 5.5 0 0 0 8 2.5Z"})}),"Refresh"]})]}),t.schemaLoading?e.jsx(ut,{t:n}):t.schemaTables.length===0?e.jsxs("div",{style:{padding:"24px 14px",color:n.textMuted,fontSize:12,fontFamily:n.font,textAlign:"center",fontStyle:"italic"},children:["No tables found.",e.jsx("br",{}),"Connect a data source to explore schema."]}):e.jsx("div",{style:{overflow:"auto",flex:1},children:t.schemaTables.map(a=>e.jsx(ft,{table:a,t:n},a.name))})]})}function ft({table:t,t:o}){const{dispatch:n}=w(),[r,i]=f.useState(!1),[l,a]=f.useState(!1),s=async()=>{if(n({type:"TOGGLE_SCHEMA_TABLE",tableName:t.name}),!t.expanded&&t.columns.length===0){a(!0);try{const c=await B.describeTable(t.path);c.length>0&&n({type:"SET_TABLE_COLUMNS",tableName:t.name,columns:c})}catch(c){console.error("describeTable failed:",c)}finally{a(!1)}}};return e.jsxs("div",{children:[e.jsxs("button",{onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),onClick:s,style:{width:"100%",display:"flex",alignItems:"center",gap:6,padding:"5px 10px",background:r?o.sidebarItemHover:"transparent",border:"none",cursor:"pointer",color:o.textPrimary,fontSize:12,fontFamily:o.font,fontWeight:500,textAlign:"left",transition:"background 0.1s"},children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"currentColor",style:{transform:t.expanded?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.15s",flexShrink:0,color:o.textMuted},children:e.jsx("path",{d:"M3 2l4 3-4 3V2Z"})}),e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"currentColor",style:{color:o.accent,flexShrink:0},children:e.jsx("path",{d:"M0 1.75C0 .784.784 0 1.75 0h12.5C15.216 0 16 .784 16 1.75v1.5A1.75 1.75 0 0 1 14.25 5H1.75A1.75 1.75 0 0 1 0 3.25Zm1.75-.25a.25.25 0 0 0-.25.25v1.5c0 .138.112.25.25.25h12.5a.25.25 0 0 0 .25-.25v-1.5a.25.25 0 0 0-.25-.25Zm-1.75 6C0 6.784.784 6 1.75 6h12.5c.966 0 1.75.784 1.75 1.75v1.5A1.75 1.75 0 0 1 14.25 11H1.75A1.75 1.75 0 0 1 0 9.25Zm1.75-.25a.25.25 0 0 0-.25.25v1.5c0 .138.112.25.25.25h12.5a.25.25 0 0 0 .25-.25v-1.5a.25.25 0 0 0-.25-.25Zm-1.75 6c0-.966.784-1.75 1.75-1.75h12.5c.966 0 1.75.784 1.75 1.75v1.5A1.75 1.75 0 0 1 14.25 16H1.75A1.75 1.75 0 0 1 0 14.25Zm1.75-.25a.25.25 0 0 0-.25.25v1.5c0 .138.112.25.25.25h12.5a.25.25 0 0 0 .25-.25v-1.5a.25.25 0 0 0-.25-.25Z"})}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.name}),t.columns.length>0&&e.jsx("span",{style:{fontSize:10,color:o.textMuted,background:o.pillBg,borderRadius:8,padding:"1px 5px",flexShrink:0},children:t.columns.length})]}),t.expanded&&e.jsx("div",{style:{paddingLeft:26},children:l?e.jsx("div",{style:{padding:"4px 10px",fontSize:11,color:o.textMuted,fontFamily:o.font,fontStyle:"italic"},children:"..."}):t.columns.length===0?e.jsx("div",{style:{padding:"4px 10px",fontSize:11,color:o.textMuted,fontFamily:o.font,fontStyle:"italic"},children:"No columns"}):t.columns.map(c=>e.jsx(ht,{col:c,t:o},c.name))})]})}function ht({col:t,t:o}){const[n,r]=f.useState(!1);return e.jsxs("div",{onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:8,padding:"3px 10px 3px 8px",background:n?o.sidebarItemHover:"transparent",cursor:"default",transition:"background 0.1s"},children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 16 16",fill:"currentColor",style:{color:o.textMuted,flexShrink:0},children:e.jsx("path",{d:"M8 0a8 8 0 1 1 0 16A8 8 0 0 1 8 0ZM1.5 8a6.5 6.5 0 1 0 13 0 6.5 6.5 0 0 0-13 0Zm7-3.25v2.992l2.028.812a.75.75 0 0 1-.557 1.392l-2.5-1A.751.751 0 0 1 7 8.25v-3.5a.75.75 0 0 1 1.5 0Z"})}),e.jsx("span",{style:{flex:1,fontSize:11,fontFamily:o.fontMono,color:o.textSecondary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.name}),e.jsx("span",{style:{fontSize:10,fontFamily:o.fontMono,color:de(t.type,o.accent),background:`${de(t.type,o.accent)}18`,borderRadius:4,padding:"1px 5px",flexShrink:0},children:t.type.toLowerCase()})]})}function xt(t){if(t.type==="markdown"){const o=t.content.match(/^#{1,6}\s+(.+)$/m);if(o)return o[1];const n=t.content.split(`
10
- `).find(r=>r.trim());return(n==null?void 0:n.trim())||null}return t.name?t.name:null}function Se(t){if(t.type!=="markdown")return 0;const o=t.content.match(/^(#{1,6})\s/m);return o?o[1].length:0}function gt({cell:t,t:o}){if(t.type==="markdown")return e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"currentColor",style:{color:o.textMuted,flexShrink:0},children:[e.jsx("path",{d:"M14.85 3H7.39L6.74.translateX(.5.25C6.45.11 6.23 0 6 0H1.75A1.75 1.75 0 0 0 0 1.75v12.5C0 15.216.784 16 1.75 16h12.5A1.75 1.75 0 0 0 16 14.25V4.75A1.75 1.75 0 0 0 14.25 3ZM1.5 1.75a.25.25 0 0 1 .25-.25H6l.5 1.5H1.5Z"}),e.jsx("path",{d:"M2 2h12v12H2z",fill:"none",stroke:"currentColor",strokeWidth:"1.5"})]});const n=t.type==="sql"?o.accent:o.warning;return e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"currentColor",style:{color:n,flexShrink:0},children:e.jsx("path",{d:"M0 5.75C0 4.784.784 4 1.75 4h12.5c.966 0 1.75.784 1.75 1.75v4.5A1.75 1.75 0 0 1 14.25 12H1.75A1.75 1.75 0 0 1 0 10.25Zm1.75-.25a.25.25 0 0 0-.25.25v4.5c0 .138.112.25.25.25h12.5a.25.25 0 0 0 .25-.25v-4.5a.25.25 0 0 0-.25-.25Z"})})}function mt({onNavigate:t}){const{state:o}=w(),n=S[o.themeMode];if(!o.activeFile)return e.jsx("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",padding:20,textAlign:"center"},children:e.jsxs("div",{children:[e.jsx("svg",{width:"32",height:"32",viewBox:"0 0 16 16",fill:"currentColor",style:{color:n.textMuted,marginBottom:8},children:e.jsx("path",{d:"M0 1.75C0 .784.784 0 1.75 0h12.5C15.216 0 16 .784 16 1.75v12.5A1.75 1.75 0 0 1 14.25 16H1.75A1.75 1.75 0 0 1 0 14.25ZM1.75 1.5a.25.25 0 0 0-.25.25v12.5c0 .138.112.25.25.25h12.5a.25.25 0 0 0 .25-.25V1.75a.25.25 0 0 0-.25-.25ZM3.5 6.25a.75.75 0 0 1 .75-.75h7a.75.75 0 0 1 0 1.5h-7a.75.75 0 0 1-.75-.75Zm.75 2.25h4a.75.75 0 0 1 0 1.5h-4a.75.75 0 0 1 0-1.5Z"})}),e.jsx("div",{style:{fontSize:12,color:n.textMuted,fontFamily:n.font,lineHeight:1.5},children:"Open a notebook to see its outline."})]})});const r=o.cells.map(i=>({cell:i,label:xt(i)})).filter(i=>i.label!==null);return r.length===0?e.jsxs("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",padding:20,color:n.textMuted,fontSize:12,fontFamily:n.font,fontStyle:"italic",textAlign:"center"},children:["No named cells or headings yet.",e.jsx("br",{}),"Name your cells or add markdown headings."]}):e.jsx("div",{style:{flex:1,overflow:"auto",padding:"6px 0"},children:r.map(({cell:i,label:l})=>{const a=Se(i),s=i.type==="markdown"?Math.max(0,(a-1)*12):0;return e.jsx(yt,{cell:i,label:l,indent:s,onClick:()=>t(i.id),t:n},i.id)})})}function yt({cell:t,label:o,indent:n,onClick:r,t:i}){const[l,a]=f.useState(!1);return e.jsxs("button",{onClick:r,onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),style:{width:"100%",display:"flex",alignItems:"center",gap:6,padding:`4px 10px 4px ${14+n}px`,background:l?i.sidebarItemHover:"transparent",border:"none",cursor:"pointer",color:l?i.textPrimary:i.textSecondary,fontSize:12,fontFamily:t.type==="markdown"?i.font:i.fontMono,textAlign:"left",transition:"background 0.1s, color 0.1s",overflow:"hidden"},children:[e.jsx(gt,{cell:t,t:i}),e.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,fontWeight:t.type==="markdown"&&Se(t)===1?600:400},children:o})]})}const bt={duckdb:"DuckDB",file:"Local File / DuckDB",postgres:"PostgreSQL",bigquery:"BigQuery",snowflake:"Snowflake",sqlite:"SQLite"},vt={duckdb:"#f4bc00",file:"#f4bc00",postgres:"#336791",bigquery:"#4285f4",snowflake:"#29b5e8",sqlite:"#003b57"};function St(){const{state:t}=w(),o=S[t.themeMode],[n,r]=f.useState(null),[i,l]=f.useState(!1),[a,s]=f.useState(null);f.useEffect(()=>{B.getConnections().then(r)},[]);const c=async()=>{l(!0),s(null);const g=await B.testConnection();s(g),l(!1)},h={fontSize:10,fontWeight:600,letterSpacing:"0.07em",textTransform:"uppercase",color:o.textMuted,fontFamily:o.font,marginBottom:6},d={background:o.cellBg,border:`1px solid ${o.cellBorder}`,borderRadius:7,padding:"10px 12px",marginBottom:10},p=(n==null?void 0:n.connections)??{},u=(n==null?void 0:n.default)??"";return e.jsxs("div",{style:{flex:1,overflow:"auto",padding:"12px 12px 20px"},children:[e.jsx("div",{style:h,children:"Active Connection"}),n===null?e.jsx("div",{style:{fontSize:12,color:o.textMuted,fontFamily:o.font},children:"Loading…"}):Object.entries(p).map(([g,x])=>{const m=(x==null?void 0:x.driver)??(x==null?void 0:x.type)??"unknown",y=g===u||Object.keys(p).length===1,k=vt[m]??o.accent;return e.jsxs("div",{style:{...d,borderLeft:y?`3px solid ${k}`:`1px solid ${o.cellBorder}`},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:6},children:[e.jsx("span",{style:{fontSize:10,fontWeight:700,fontFamily:o.fontMono,color:k,background:`${k}18`,border:`1px solid ${k}40`,borderRadius:4,padding:"1px 6px",letterSpacing:"0.05em",textTransform:"uppercase"},children:bt[m]??m}),y&&e.jsx("span",{style:{fontSize:10,color:o.textMuted,fontFamily:o.font},children:"default"})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:3},children:Object.entries(x??{}).filter(([j])=>j!=="driver"&&j!=="type").map(([j,E])=>e.jsxs("div",{style:{display:"flex",gap:6,alignItems:"baseline"},children:[e.jsx("span",{style:{fontSize:11,color:o.textMuted,fontFamily:o.fontMono,minWidth:70,flexShrink:0},children:j}),e.jsx("span",{style:{fontSize:11,color:o.textSecondary,fontFamily:o.fontMono,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:j.toLowerCase().includes("password")?"••••••••":String(E)})]},j))})]},g)}),e.jsx("button",{onClick:c,disabled:i,style:{width:"100%",padding:"7px 0",borderRadius:6,border:`1px solid ${o.btnBorder}`,background:o.btnBg,color:o.textSecondary,fontSize:12,fontFamily:o.font,fontWeight:500,cursor:i?"not-allowed":"pointer",marginBottom:8,opacity:i?.7:1,transition:"all 0.15s"},children:i?"Testing…":"Test Connection"}),a&&e.jsxs("div",{style:{fontSize:12,fontFamily:o.font,color:a.ok?o.success:o.error,background:a.ok?`${o.success}12`:`${o.error}12`,border:`1px solid ${a.ok?o.success:o.error}40`,borderRadius:6,padding:"7px 10px",marginBottom:12},children:[a.ok?"✓ ":"✗ ",a.message]}),e.jsx("div",{style:{...h,marginTop:4},children:"Change Connection"}),e.jsxs("div",{style:{...d,fontSize:12,fontFamily:o.font,color:o.textSecondary,lineHeight:1.6},children:["Edit ",e.jsx("code",{style:{fontFamily:o.fontMono,color:o.accent,fontSize:11},children:"dql.config.json"})," in your project root to add or switch connections. Supported drivers:",e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4,marginTop:8},children:[{driver:"duckdb / file",desc:"Local CSV, Parquet, DuckDB"},{driver:"postgres",desc:"PostgreSQL / Supabase / RDS"},{driver:"bigquery",desc:"Google BigQuery"},{driver:"snowflake",desc:"Snowflake"}].map(({driver:g,desc:x})=>e.jsxs("div",{style:{display:"flex",gap:8,alignItems:"baseline"},children:[e.jsx("code",{style:{fontSize:10,fontFamily:o.fontMono,color:o.textMuted,minWidth:80,flexShrink:0},children:g}),e.jsx("span",{style:{fontSize:11,color:o.textMuted},children:x})]},g))})]}),e.jsx("div",{style:{...h,marginTop:4},children:"Example Config"}),e.jsx("pre",{style:{background:o.cellBg,border:`1px solid ${o.cellBorder}`,borderRadius:7,padding:"10px 12px",fontSize:11,fontFamily:o.fontMono,color:o.textSecondary,overflow:"auto",lineHeight:1.6,margin:0},children:`{
11
- "connections": {
12
- "default": {
13
- "driver": "duckdb",
14
- "path": ":memory:"
15
- },
16
- "prod": {
17
- "driver": "postgres",
18
- "host": "localhost",
19
- "port": 5432,
20
- "database": "analytics",
21
- "user": "analyst",
22
- "password": "..."
23
- }
24
- }
25
- }`})]})}function W({title:t,defaultOpen:o=!1,children:n,t:r}){const[i,l]=f.useState(o),[a,s]=f.useState(!1);return e.jsxs("div",{style:{borderBottom:`1px solid ${r.headerBorder}`},children:[e.jsxs("button",{onClick:()=>l(c=>!c),onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),style:{width:"100%",padding:"7px 12px",display:"flex",alignItems:"center",gap:6,background:a?r.sidebarItemHover:"transparent",border:"none",cursor:"pointer",textAlign:"left",transition:"background 0.1s"},children:[e.jsx("span",{style:{fontSize:9,color:r.textMuted,display:"inline-block",transition:"transform 0.15s",transform:i?"rotate(90deg)":"rotate(0deg)",lineHeight:1},children:"▶"}),e.jsx("span",{style:{fontSize:11,fontWeight:600,fontFamily:r.font,color:r.textSecondary,letterSpacing:"0.04em"},children:t})]}),i&&e.jsx("div",{style:{padding:"4px 12px 10px"},children:n})]})}function jt({code:t,t:o}){const[n,r]=f.useState(!1);async function i(){try{await navigator.clipboard.writeText(t)}catch{const l=document.createElement("textarea");l.value=t,document.body.appendChild(l),l.select(),document.execCommand("copy"),document.body.removeChild(l)}r(!0),setTimeout(()=>r(!1),1500)}return e.jsx("button",{onClick:i,title:"Copy to clipboard",style:{position:"absolute",top:6,right:6,padding:"2px 6px",fontSize:10,fontFamily:o.font,background:n?`${o.success}20`:o.btnBg,border:`1px solid ${n?o.success+"50":o.btnBorder}`,borderRadius:4,cursor:"pointer",color:n?o.success:o.textMuted,transition:"all 0.15s"},children:n?"✓":"Copy"})}function J({code:t,t:o}){return e.jsxs("div",{style:{position:"relative",marginTop:6},children:[e.jsx("pre",{style:{margin:0,padding:"8px 10px",paddingRight:52,background:o.editorBg,border:`1px solid ${o.cellBorder}`,borderRadius:6,fontFamily:o.fontMono,fontSize:11,color:o.textPrimary,lineHeight:1.6,whiteSpace:"pre",overflowX:"auto"},children:t}),e.jsx(jt,{code:t,t:o})]})}function ce({rows:t,t:o}){return e.jsx("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:11,fontFamily:o.font,marginTop:6},children:e.jsx("tbody",{children:t.map(([n,r],i)=>e.jsxs("tr",{style:{borderBottom:`1px solid ${o.tableBorder}`},children:[e.jsx("td",{style:{padding:"5px 6px 5px 0",fontFamily:o.fontMono,fontSize:11,color:o.accent,whiteSpace:"nowrap",verticalAlign:"top",width:"45%"},children:n}),e.jsx("td",{style:{padding:"5px 0",color:o.textSecondary,verticalAlign:"top",lineHeight:1.5},children:r})]},i))})})}const wt=`block "My Block" {
26
- domain = "analytics"
27
- type = "custom"
28
- description = "Describe what this block does"
29
- owner = "data-team"
30
- tags = ["analytics"]
31
-
32
- query = """
33
- SELECT *
34
- FROM read_csv_auto('data/filename.csv')
35
- LIMIT 100
36
- """
37
-
38
- visualization {
39
- chart = "table"
40
- }
41
- }`;function kt({themeMode:t}){const o=S[t];return e.jsxs("div",{style:{flex:1,overflowY:"auto",fontFamily:o.font},children:[e.jsx(W,{title:"SQL Essentials",defaultOpen:!0,t:o,children:e.jsx(J,{t:o,code:`-- Basic select
42
- SELECT col1, col2
43
- FROM table_name
44
- WHERE condition
45
- ORDER BY col1 DESC
46
- LIMIT 100
47
-
48
- -- GROUP BY
49
- SELECT col, COUNT(*), SUM(val)
50
- FROM table_name
51
- GROUP BY col
52
-
53
- -- JOIN
54
- SELECT a.*, b.col
55
- FROM table_a AS a
56
- JOIN table_b AS b ON a.id = b.id
57
-
58
- -- CTE (WITH)
59
- WITH cte AS (
60
- SELECT * FROM table_name WHERE val > 0
61
- )
62
- SELECT * FROM cte
63
-
64
- -- Window function
65
- SELECT *,
66
- ROW_NUMBER() OVER (
67
- PARTITION BY group_col
68
- ORDER BY val DESC
69
- ) AS rank
70
- FROM table_name`})}),e.jsx(W,{title:"DuckDB Functions",defaultOpen:!1,t:o,children:e.jsx(ce,{t:o,rows:[["read_csv_auto(path)","Auto-detect CSV schema and load"],["read_parquet(path)","Load a Parquet file"],["strftime(date, fmt)","Format date as string (e.g. '%Y-%m')"],["date_trunc(part, date)","Truncate date to part ('month', 'year'…)"],["CURRENT_DATE","Today's date"],["epoch_ms(ts)","Convert epoch milliseconds to timestamp"],["array_agg(col)","Aggregate column values into an array"],["string_agg(col, sep)","Concatenate values with separator"]]})}),e.jsx(W,{title:"DQL Block Structure",defaultOpen:!0,t:o,children:e.jsx(J,{t:o,code:wt})}),e.jsxs(W,{title:"DQL Chart Types",defaultOpen:!1,t:o,children:[e.jsx(ce,{t:o,rows:[["table","Tabular data grid (default)"],["bar","Bar chart — set x and y fields"],["line","Line chart — set x and y fields"],["kpi","Single big-number KPI card"]]}),e.jsxs("div",{style:{marginTop:8,fontSize:11,color:o.textMuted,fontFamily:o.font,lineHeight:1.6},children:["Set chart type inside the"," ",e.jsx("code",{style:{fontFamily:o.fontMono,color:o.accent,fontSize:11},children:'visualization { chart = "bar" }'})," ","block."]})]}),e.jsxs(W,{title:"Variable References",defaultOpen:!1,t:o,children:[e.jsxs("div",{style:{fontSize:12,color:o.textSecondary,lineHeight:1.7,fontFamily:o.font,marginBottom:8},children:["Use"," ",e.jsx("code",{style:{fontFamily:o.fontMono,color:o.accent,fontSize:11},children:"{{cell_name}}"})," ","to reference other cells:",e.jsxs("ul",{style:{margin:"6px 0 0",paddingLeft:18},children:[e.jsxs("li",{children:[e.jsx("strong",{children:"Param cell"})," → substituted as a SQL literal value"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"SQL cell"})," → injected as a CTE"]})]})]}),e.jsx(J,{t:o,code:`-- Param cell named "start_date" holds '2024-01-01'
71
- SELECT *
72
- FROM read_csv_auto('data/sales.csv')
73
- WHERE date >= {{start_date}}
74
-
75
- -- SQL cell named "base_query" used as CTE
76
- SELECT segment, SUM(revenue) AS total
77
- FROM {{base_query}}
78
- GROUP BY segment`})]})]})}const Et={files:"Explorer",schema:"Schema",outline:"Outline",connection:"Connection",reference:"Quick Reference"};function Ct({onOpenFile:t,onNavigateToCell:o}){const{state:n,dispatch:r}=w(),i=S[n.themeMode],[l,a]=f.useState(!1),s=n.sidebarPanel;return e.jsxs("div",{style:{width:240,flexShrink:0,background:i.sidebarBg,borderRight:`1px solid ${i.headerBorder}`,display:"flex",flexDirection:"column",overflow:"hidden"},children:[e.jsxs("div",{style:{height:36,flexShrink:0,display:"flex",alignItems:"center",justifyContent:"space-between",padding:"0 10px 0 14px",borderBottom:`1px solid ${i.headerBorder}`},children:[e.jsx("span",{style:{fontSize:11,fontWeight:600,letterSpacing:"0.06em",textTransform:"uppercase",color:i.textSecondary,fontFamily:i.font},children:Et[s??""]??""}),e.jsx("button",{title:"Collapse sidebar",onClick:()=>r({type:"TOGGLE_SIDEBAR"}),onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),style:{background:"transparent",border:"none",cursor:"pointer",color:l?i.textPrimary:i.textMuted,padding:"2px 4px",borderRadius:4,fontSize:14,lineHeight:1,transition:"color 0.15s",display:"flex",alignItems:"center"},children:"‹"})]}),e.jsxs("div",{style:{flex:1,overflow:"hidden",display:"flex",flexDirection:"column"},children:[s==="files"&&e.jsx(lt,{onOpenFile:t}),s==="schema"&&e.jsx(pt,{}),s==="outline"&&e.jsx(mt,{onNavigate:o}),s==="connection"&&e.jsx(St,{}),s==="reference"&&e.jsx(kt,{themeMode:n.themeMode})]})]})}function Mt(t){try{const o=t.match(/workbook\s+"([^"]+)"/i),n=o?o[1]:"Untitled Workbook",r=[],i=/page\s+"([^"]+)"\s*\{([\s\S]*?)\}/gi;let l;for(;(l=i.exec(t))!==null;){const a=l[1],s=l[2].trim();r.push({id:F(),type:"markdown",content:`# ${a}`,status:"idle"}),s&&r.push({id:F(),type:"dql",name:a.toLowerCase().replace(/\s+/g,"_"),content:s,status:"idle"})}return r.length===0&&r.push({id:F(),type:"dql",content:t.trim(),status:"idle"}),{title:n,cells:r}}catch{return{title:"Untitled Workbook",cells:[{id:F(),type:"dql",content:t.trim(),status:"idle"}]}}}function Lt(t){var o;try{const n=JSON.parse(t),r=n.title||((o=n.metadata)==null?void 0:o.title)||"Untitled",i=(n.cells||[]).map(l=>({id:l.id||F(),type:l.type||"sql",content:l.content??l.source??"",name:l.name||l.title,status:"idle",...l.paramConfig?{paramConfig:l.paramConfig}:{},...l.paramValue!==void 0?{paramValue:l.paramValue}:{}}));return{title:r,cells:i}}catch{return{title:"Untitled",cells:[{id:F(),type:"sql",content:t,status:"idle"}]}}}function Bt(t,o){const n={version:1,title:t,cells:o.map(r=>({id:r.id,type:r.type,content:r.content,...r.name?{name:r.name}:{},...r.paramConfig?{paramConfig:r.paramConfig}:{},...r.paramValue!==void 0?{paramValue:r.paramValue}:{}}))};return JSON.stringify(n,null,2)}function Tt(t,o){return t.endsWith(".dql")?Mt(o):Lt(o)}function Rt(t,o){if(!o.columns.length||!o.rows.length)return`${t} AS (SELECT 1 WHERE 1=0)`;const n=o.columns,i=o.rows.slice(0,5e3).map(a=>`(${n.map(c=>{const h=a[c];return h==null?"NULL":typeof h=="number"?String(h):typeof h=="boolean"?h?"TRUE":"FALSE":`'${String(h).replace(/'/g,"''")}'`}).join(", ")})`).join(`,
79
- `),l=n.map(a=>`"${a.replace(/"/g,'""')}"`).join(", ");return`${t} AS (
80
- SELECT * FROM (VALUES
81
- ${i}
82
- ) AS _t(${l})
83
- )`}function At(t,o){if(o==="number"){const n=Number(t);return isNaN(n)?`'${t.replace(/'/g,"''")}'`:String(n)}return`'${t.replace(/'/g,"''")}'`}function Ot(){const{state:t}=w();return{substituteVariables:f.useCallback(n=>{var d;const r=/\{\{([a-zA-Z_][a-zA-Z0-9_]*)\}\}/g,i=[...n.matchAll(r)];if(i.length===0)return{sql:n,substituted:[]};const l=[],a=[];let s=n;const c=new Map,h=new Map;for(const p of t.cells){const u=(d=p.name)==null?void 0:d.trim();u&&(p.type==="param"?c.set(u,p):p.status==="success"&&p.result&&h.set(u,p.result))}for(const p of i){const u=p[1];if(c.has(u)){const g=c.get(u),x=g.paramConfig,m=g.paramValue??(x==null?void 0:x.defaultValue)??"",y=(x==null?void 0:x.paramType)??"text",k=At(m,y);s=s.replace(p[0],k),l.push(u)}else h.has(u)&&(a.push(Rt(u,h.get(u))),s=s.replace(p[0],`"${u}"`),l.push(u))}if(a.length===0&&l.length===0)return{sql:n,substituted:[]};if(a.length>0){const p=s.trimStart();/^WITH\s+/i.test(p)?s=s.replace(/^(\s*WITH\s+)/i,`$1${a.join(`,
84
- `)},
85
- `):s=`WITH ${a.join(`,
86
- `)}
87
- ${s}`}return{sql:s,substituted:l}},[t.cells])}}function _t(t){if(t.type==="markdown")return null;if(t.type==="sql")return t.content.trim()||null;const o=t.content.trim();if(!o)return null;const n=o.match(/\b(SELECT|WITH|INSERT|UPDATE|DELETE|CREATE|DROP|ALTER|SHOW|DESCRIBE|EXPLAIN)\b[\s\S]*/i);return n?n[0].trim():o}function ie(){const{state:t,dispatch:o}=w(),{substituteVariables:n}=Ot(),r=f.useCallback(async l=>{const a=t.cells.find(d=>d.id===l);if(!a)return;const s=_t(a);if(!s)return;const{sql:c}=n(s),h=Date.now();o({type:"UPDATE_CELL",id:l,updates:{status:"running",error:void 0,result:void 0}});try{const d=await B.executeQuery(c),p=Date.now()-h,u=(a.executionCount??0)+1;o({type:"UPDATE_CELL",id:l,updates:{status:"success",result:{...d,executionTime:d.executionTime??p,rowCount:d.rowCount??d.rows.length},executionCount:u}}),o({type:"APPEND_QUERY_LOG",entry:{id:F(),cellName:a.name??a.id,rows:d.rowCount??d.rows.length,time:d.executionTime??p,ts:new Date}}),setTimeout(()=>{o({type:"UPDATE_CELL",id:l,updates:{status:"idle"}})},2e3)}catch(d){const p=Date.now()-h,u=d instanceof Error?d.message:String(d);o({type:"UPDATE_CELL",id:l,updates:{status:"error",error:u,executionCount:(a.executionCount??0)+1}}),o({type:"APPEND_QUERY_LOG",entry:{id:F(),cellName:a.name??a.id,rows:0,time:p,ts:new Date,error:u}})}},[t.cells,o]),i=f.useCallback(async()=>{for(const l of t.cells)l.type!=="markdown"&&await r(l.id)},[t.cells,r]);return{executeCell:r,executeAll:i}}function L(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function Ft(t){return typeof t=="number"?Math.abs(t)>=1e6?`${(t/1e6).toFixed(1)}M`:Math.abs(t)>=1e3?`${(t/1e3).toFixed(1)}K`:Number.isInteger(t)?String(t):t.toFixed(2):""}function Dt(t){const o=t.split(`
88
- `),n=[];let r=!1,i=!1;for(const l of o){const a=l;if(a.startsWith("```")){i&&(n.push("</ul>"),i=!1),r?(n.push("</code></pre>"),r=!1):(n.push("<pre><code>"),r=!0);continue}if(r){n.push(L(a));continue}if(a.startsWith("### ")){i&&(n.push("</ul>"),i=!1),n.push(`<h3>${L(a.slice(4))}</h3>`);continue}if(a.startsWith("## ")){i&&(n.push("</ul>"),i=!1),n.push(`<h2>${L(a.slice(3))}</h2>`);continue}if(a.startsWith("# ")){i&&(n.push("</ul>"),i=!1),n.push(`<h1>${L(a.slice(2))}</h1>`);continue}if(a.startsWith("> ")){i&&(n.push("</ul>"),i=!1),n.push(`<blockquote><p>${L(a.slice(2))}</p></blockquote>`);continue}if(a.startsWith("- ")||a.startsWith("* ")){i||(n.push("<ul>"),i=!0),n.push(`<li>${ue(a.slice(2))}</li>`);continue}if(i&&(n.push("</ul>"),i=!1),a.trim()===""){n.push("<br>");continue}n.push(`<p>${ue(a)}</p>`)}return i&&n.push("</ul>"),r&&n.push("</code></pre>"),n.join(`
89
- `)}function ue(t){return L(t).replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>").replace(/\*(.+?)\*/g,"<em>$1</em>").replace(/`(.+?)`/g,"<code>$1</code>")}function $t(t){const{columns:o,rows:n}=t,r=n.slice(0,200),i=n.length>200,l=o.map(s=>`<th>${L(s)}</th>`).join(""),a=r.map(s=>`<tr>${o.map(h=>{const d=s[h],p=typeof d=="number",u=d==null?"—":String(d);return`<td${p?' class="num"':""}>${L(u)}</td>`}).join("")}</tr>`).join("");return`
90
- <div class="table-wrap">
91
- <table>
92
- <thead><tr>${l}</tr></thead>
93
- <tbody>${a}</tbody>
94
- </table>
95
- ${i?`<p class="truncated">Showing first 200 of ${n.length.toLocaleString()} rows</p>`:""}
96
- </div>`}function It(t){const{columns:o,rows:n}=t;if(o.length<2||n.length===0)return null;const r=o.find(l=>typeof n[0][l]=="number"),i=o.find(l=>l!==r);return!r||!i?null:{labelCol:i,valueCol:r}}function Nt(t){const o=It(t);if(!o)return null;const n=t.rows.slice(0,20).map(d=>({label:String(d[o.labelCol]??""),value:Number(d[o.valueCol]??0)})),r=Math.max(...n.map(d=>d.value),1),i=28,l=6,a=140,s=440,c=n.length*(i+l)+40,h=n.map((d,p)=>{const u=p*(i+l)+20,g=Math.max(d.value/r*s,2);return`
97
- <text x="${a-6}" y="${u+i/2+4}" text-anchor="end" font-size="11" fill="#8b949e">${L(d.label.slice(0,20))}</text>
98
- <rect x="${a}" y="${u}" width="${g}" height="${i}" rx="3" fill="#388bfd" />
99
- <text x="${a+g+5}" y="${u+i/2+4}" font-size="11" fill="#e6edf3">${Ft(d.value)}</text>`}).join("");return`<svg xmlns="http://www.w3.org/2000/svg" width="${a+s+80}" height="${c}" style="max-width:100%">${h}</svg>`}function Ht(t,o){const n=o.map(r=>{if(r.type==="markdown")return`<section class="cell md-cell">${Dt(r.content)}</section>`;const i=r.name?`<div class="cell-header"><span class="cell-type">${r.type.toUpperCase()}</span><span class="cell-name">${L(r.name)}</span></div>`:`<div class="cell-header"><span class="cell-type">${r.type.toUpperCase()}</span></div>`,l=`<pre class="cell-code"><code>${L(r.content)}</code></pre>`;let a="";if(r.result&&r.result.rows.length>0){const s=Nt(r.result),c=$t(r.result);a=`<div class="cell-output">${`<div class="output-meta">${r.result.rows.length.toLocaleString()} rows${r.result.executionTime?` · ${r.result.executionTime}ms`:""}</div>`}${s??""}${s?"":c}</div>`}else r.error&&(a=`<div class="cell-error">⚠ ${L(r.error)}</div>`);return`<section class="cell sql-cell">${i}${l}${a}</section>`}).join(`
100
- `);return`<!DOCTYPE html>
101
- <html lang="en">
102
- <head>
103
- <meta charset="UTF-8">
104
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
105
- <title>${L(t)}</title>
106
- <style>
107
- *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
108
- body {
109
- font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
110
- background: #0d1117; color: #e6edf3;
111
- line-height: 1.6; padding: 0;
112
- }
113
- .page-header {
114
- background: #161b22; border-bottom: 1px solid #21262d;
115
- padding: 16px 32px; display: flex; align-items: center; gap: 12px;
116
- }
117
- .logo {
118
- width: 28px; height: 28px; border-radius: 6px;
119
- background: linear-gradient(135deg, #388bfd, #1f6feb);
120
- display: flex; align-items: center; justify-content: center;
121
- font-size: 10px; font-weight: 700; color: #fff;
122
- font-family: monospace; letter-spacing: -0.5px; flex-shrink: 0;
123
- }
124
- .page-title { font-size: 18px; font-weight: 600; color: #e6edf3; }
125
- .page-meta { font-size: 12px; color: #8b949e; margin-left: auto; }
126
- .content { max-width: 900px; margin: 0 auto; padding: 32px 24px; display: flex; flex-direction: column; gap: 24px; }
127
- .cell { border-radius: 8px; overflow: hidden; }
128
- .md-cell { padding: 4px 0; }
129
- .md-cell h1 { font-size: 26px; font-weight: 700; color: #e6edf3; margin: 0 0 12px; }
130
- .md-cell h2 { font-size: 20px; font-weight: 600; color: #e6edf3; margin: 20px 0 10px; }
131
- .md-cell h3 { font-size: 16px; font-weight: 600; color: #e6edf3; margin: 16px 0 8px; }
132
- .md-cell p { color: #c9d1d9; margin-bottom: 8px; }
133
- .md-cell ul { padding-left: 20px; color: #c9d1d9; margin-bottom: 8px; }
134
- .md-cell code { background: #21262d; padding: 2px 6px; border-radius: 4px; font-family: monospace; font-size: 13px; }
135
- .md-cell pre { background: #161b22; border: 1px solid #30363d; border-radius: 6px; padding: 14px; overflow-x: auto; margin-bottom: 8px; }
136
- .md-cell pre code { background: none; padding: 0; }
137
- .md-cell blockquote { border-left: 3px solid #388bfd; padding-left: 14px; color: #8b949e; }
138
- .sql-cell { background: #161b22; border: 1px solid #30363d; }
139
- .cell-header { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-bottom: 1px solid #21262d; background: #1c2128; }
140
- .cell-type { font-size: 10px; font-weight: 600; letter-spacing: 0.05em; color: #8b949e; background: #21262d; padding: 2px 6px; border-radius: 4px; font-family: monospace; }
141
- .cell-name { font-size: 12px; color: #388bfd; font-family: monospace; }
142
- .cell-code { background: #0d1117; padding: 14px; font-size: 12px; font-family: 'JetBrains Mono', monospace; color: #c9d1d9; overflow-x: auto; border-bottom: 1px solid #21262d; line-height: 1.55; white-space: pre; }
143
- .cell-output { padding: 14px; }
144
- .output-meta { font-size: 11px; color: #8b949e; margin-bottom: 10px; }
145
- .table-wrap { overflow-x: auto; }
146
- table { width: 100%; border-collapse: collapse; font-size: 12px; }
147
- th { background: #1c2128; color: #8b949e; font-weight: 600; text-align: left; padding: 7px 12px; border-bottom: 1px solid #30363d; white-space: nowrap; }
148
- td { padding: 6px 12px; border-bottom: 1px solid #21262d; color: #e6edf3; }
149
- td.num { text-align: right; font-family: monospace; }
150
- tr:last-child td { border-bottom: none; }
151
- .truncated { font-size: 11px; color: #8b949e; margin-top: 8px; }
152
- .cell-error { padding: 12px 14px; background: #3d1a1a; border-top: 1px solid #f85149; color: #f85149; font-size: 13px; }
153
- .exported-by { text-align: center; color: #484f58; font-size: 11px; padding: 40px 0 24px; }
154
- </style>
155
- </head>
156
- <body>
157
- <div class="page-header">
158
- <div class="logo">DQL</div>
159
- <span class="page-title">${L(t)}</span>
160
- <span class="page-meta">Exported ${new Date().toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"})}</span>
161
- </div>
162
- <div class="content">
163
- ${n}
164
- </div>
165
- <p class="exported-by">Built with DQL Notebook</p>
166
- </body>
167
- </html>`}function zt(t,o){const n=Ht(t,o),r=new Blob([n],{type:"text/html;charset=utf-8"}),i=URL.createObjectURL(r),l=document.createElement("a");l.href=i,l.download=`${t.toLowerCase().replace(/[^a-z0-9]+/g,"-")}-dashboard.html`,document.body.appendChild(l),l.click(),document.body.removeChild(l),URL.revokeObjectURL(i)}function Pt(t,o){var l,a;const n=[];n.push(`workbook "${t}" {`);let r=0,i=0;for(const s of o)if(s.type!=="param"){if(s.type==="markdown"){i++;const c=`Markdown ${i}`;n.push(""),n.push(` page "${c}" {`);const h=s.content.split(`
168
- `);for(const d of h)n.push(` // ${d}`);n.push(" }")}else if(s.type==="sql"){r++;const c=((l=s.name)==null?void 0:l.trim())||`Query ${r}`;n.push(""),n.push(` page "${c}" {`);const d=s.content.trim().split(`
169
- `).map(p=>` ${p}`).join(`
170
- `);n.push(" chart.table("),n.push(d+","),n.push(` title = "${c}"`),n.push(" )"),n.push(" }")}else if(s.type==="dql"){r++;const c=((a=s.name)==null?void 0:a.trim())||`Query ${r}`;n.push(""),n.push(` page "${c}" {`);const h=s.content.trim().split(`
171
- `);for(const d of h)n.push(` ${d}`);n.push(" }")}}return n.push("}"),n.join(`
172
- `)}function Wt(t,o){const n=Pt(t,o),r=new Blob([n],{type:"text/plain;charset=utf-8"}),i=URL.createObjectURL(r),l=document.createElement("a"),a=t.replace(/[^a-zA-Z0-9_-]/g,"_")+".dql";l.href=i,l.download=a,document.body.appendChild(l),l.click(),document.body.removeChild(l),URL.revokeObjectURL(i)}function qt({t}){return e.jsx("div",{style:{width:28,height:28,borderRadius:6,background:"linear-gradient(135deg, #388bfd 0%, #1f6feb 100%)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx("span",{style:{color:"#ffffff",fontSize:10,fontWeight:700,fontFamily:t.fontMono,letterSpacing:"-0.5px"},children:"DQL"})})}function Zt(){const{state:t,dispatch:o}=w(),n=S[t.themeMode],{executeAll:r}=ie(),[i,l]=f.useState(!1),[a,s]=f.useState(""),[c,h]=f.useState(!1),[d,p]=f.useState(!1),[u,g]=f.useState(!1),[x,m]=f.useState(!1),[y,k]=f.useState(!1),[j,E]=f.useState(!1),T=f.useRef(null),R=f.useRef(null);f.useEffect(()=>{i&&R.current&&(R.current.focus(),R.current.select())},[i]),f.useEffect(()=>{if(!j)return;function M(G){T.current&&!T.current.contains(G.target)&&E(!1)}return document.addEventListener("mousedown",M),()=>document.removeEventListener("mousedown",M)},[j]);const O=()=>{s(t.notebookTitle),l(!0)},D=()=>{l(!1),a.trim()&&a!==t.notebookTitle&&o({type:"SET_NOTEBOOK_DIRTY",dirty:!0})},z=f.useCallback(async()=>{if(t.activeFile){o({type:"SET_SAVING",saving:!0});try{const M=Bt(t.notebookTitle,t.cells);await B.saveNotebook(t.activeFile.path,M),o({type:"SET_NOTEBOOK_DIRTY",dirty:!1}),h(!0),setTimeout(()=>h(!1),2e3)}catch(M){console.error("Save failed:",M)}finally{o({type:"SET_SAVING",saving:!1})}}},[t.activeFile,t.notebookTitle,t.cells,o]),$=()=>{o({type:"SET_THEME",mode:t.themeMode==="dark"?"light":"dark"})},v={height:28,padding:"0 10px",borderRadius:6,border:`1px solid ${n.btnBorder}`,cursor:"pointer",fontSize:12,fontWeight:500,fontFamily:n.font,display:"flex",alignItems:"center",gap:4,transition:"background 0.15s, color 0.15s",whiteSpace:"nowrap"};return e.jsxs("div",{style:{height:48,flexShrink:0,background:n.headerBg,borderBottom:`1px solid ${n.headerBorder}`,display:"flex",alignItems:"center",padding:"0 12px",gap:8,userSelect:"none"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[e.jsx(qt,{t:n}),e.jsx("div",{style:{width:1,height:20,background:n.headerBorder,flexShrink:0}}),t.activeFile?i?e.jsx("input",{ref:R,value:a,onChange:M=>s(M.target.value),onBlur:D,onKeyDown:M=>{M.key==="Enter"&&D(),M.key==="Escape"&&l(!1)},style:{background:"transparent",border:`1px solid ${n.cellBorderActive}`,borderRadius:4,color:n.textPrimary,fontSize:13,fontWeight:500,fontFamily:n.font,padding:"2px 6px",outline:"none",minWidth:120,maxWidth:320}}):e.jsxs("span",{onClick:O,title:"Click to rename",style:{color:n.textPrimary,fontSize:13,fontWeight:500,fontFamily:n.font,cursor:"text",maxWidth:320,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",padding:"2px 4px",borderRadius:4,border:"1px solid transparent"},children:[t.notebookTitle||"Untitled",t.notebookDirty&&e.jsx("span",{style:{color:n.textMuted,marginLeft:4},children:"●"})]}):e.jsx("span",{style:{color:n.textSecondary,fontSize:13,fontFamily:n.font,padding:"2px 4px"},children:"DQL Notebook"})]}),e.jsx("div",{style:{flex:1}}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsxs("button",{onClick:r,disabled:!t.activeFile,onMouseEnter:()=>p(!0),onMouseLeave:()=>p(!1),style:{...v,background:(d&&t.activeFile,n.accent),color:"#ffffff",border:`1px solid ${n.accent}`,opacity:t.activeFile?d?.9:1:.4},children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"currentColor",children:e.jsx("path",{d:"M1.5 1.5l7 3.5-7 3.5V1.5Z"})}),"Run All"]}),e.jsx("div",{style:{width:1,height:20,background:n.headerBorder}}),e.jsx("button",{onClick:$,onMouseEnter:()=>m(!0),onMouseLeave:()=>m(!1),title:t.themeMode==="dark"?"Switch to light mode":"Switch to dark mode",style:{...v,background:x?n.btnHover:n.btnBg,color:n.textSecondary,padding:"0 8px",fontSize:14},children:t.themeMode==="dark"?"☀":"☾"}),e.jsx("button",{onClick:z,disabled:!t.activeFile||t.savingFile,onMouseEnter:()=>g(!0),onMouseLeave:()=>g(!1),style:{...v,background:u&&t.activeFile?n.btnHover:n.btnBg,color:c?n.success:n.textSecondary,opacity:t.activeFile?1:.4},children:t.savingFile?e.jsxs(e.Fragment,{children:[e.jsx(Vt,{}),"Saving…"]}):c?e.jsx(e.Fragment,{children:"✓ Saved"}):e.jsx(e.Fragment,{children:"Save"})}),e.jsx("div",{style:{width:1,height:20,background:n.headerBorder}}),e.jsxs("div",{ref:T,style:{position:"relative"},children:[e.jsxs("button",{onClick:()=>{t.activeFile&&E(M=>!M)},disabled:!t.activeFile,onMouseEnter:()=>k(!0),onMouseLeave:()=>k(!1),title:"Export options",style:{...v,background:(y||j)&&t.activeFile?n.btnHover:n.btnBg,color:n.textSecondary,opacity:t.activeFile?1:.4},children:[e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 16 16",fill:"currentColor",children:[e.jsx("path",{d:"M2.75 14A1.75 1.75 0 0 1 1 12.25v-2.5a.75.75 0 0 1 1.5 0v2.5c0 .138.112.25.25.25h10.5a.25.25 0 0 0 .25-.25v-2.5a.75.75 0 0 1 1.5 0v2.5A1.75 1.75 0 0 1 13.25 14Z"}),e.jsx("path",{d:"M7.25 7.689V2a.75.75 0 0 1 1.5 0v5.689l1.97-1.97a.749.749 0 1 1 1.06 1.06l-3.25 3.25a.749.749 0 0 1-1.06 0L4.22 6.779a.749.749 0 1 1 1.06-1.06l1.97 1.97Z"})]}),"Export",e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"currentColor",style:{marginLeft:1},children:e.jsx("path",{d:"M1 2.5l3 3 3-3",stroke:"currentColor",fill:"none",strokeWidth:"1.2",strokeLinecap:"round"})})]}),j&&e.jsxs("div",{style:{position:"absolute",top:32,right:0,zIndex:200,background:n.modalBg,border:`1px solid ${n.cellBorder}`,borderRadius:8,boxShadow:"0 8px 24px rgba(0,0,0,0.3)",padding:4,minWidth:160,display:"flex",flexDirection:"column",gap:2},children:[e.jsx(pe,{label:"Export HTML",description:"Standalone dashboard",t:n,onClick:()=>{zt(t.notebookTitle||"dashboard",t.cells),E(!1)}}),e.jsx(pe,{label:"Export .dql",description:"DQL workbook file",t:n,onClick:()=>{Wt(t.notebookTitle||"notebook",t.cells),E(!1)}})]})]})]})]})}function pe({label:t,description:o,t:n,onClick:r}){const[i,l]=f.useState(!1);return e.jsxs("button",{onClick:r,onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),style:{background:i?n.btnHover:"transparent",border:"none",borderRadius:5,cursor:"pointer",padding:"6px 10px",textAlign:"left",display:"flex",flexDirection:"column",gap:1,transition:"background 0.12s"},children:[e.jsx("span",{style:{fontSize:12,fontWeight:500,color:n.textPrimary,fontFamily:n.font},children:t}),e.jsx("span",{style:{fontSize:10,color:n.textMuted,fontFamily:n.font},children:o})]})}function Vt(){return e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",style:{animation:"spin 0.8s linear infinite"},children:[e.jsx("style",{children:"@keyframes spin { to { transform: rotate(360deg); } }"}),e.jsx("circle",{cx:"6",cy:"6",r:"4.5",stroke:"currentColor",strokeWidth:"1.5",strokeDasharray:"14 7"})]})}function Ut(t){return t.toTimeString().slice(0,8)}function Qt(t){return t<1e3?`${t}ms`:`${(t/1e3).toFixed(2)}s`}function Gt(){const{state:t,dispatch:o}=w(),n=S[t.themeMode],[r,i]=f.useState(!1),l=t.queryLog.filter(s=>s.error),a=s=>o({type:"SET_DEV_PANEL_TAB",tab:s});return e.jsxs("div",{style:{height:t.devPanelOpen?180:0,flexShrink:0,background:n.sidebarBg,borderTop:`1px solid ${n.headerBorder}`,display:"flex",flexDirection:"column",overflow:"hidden",transition:"height 0.2s ease",position:"relative"},children:[t.devPanelOpen&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{height:32,flexShrink:0,display:"flex",alignItems:"center",borderBottom:`1px solid ${n.headerBorder}`,padding:"0 8px",gap:2},children:[["logs","errors"].map(s=>e.jsx(Yt,{label:s==="errors"?`Errors${l.length>0?` (${l.length})`:""}`:`Logs (${t.queryLog.length})`,active:t.devPanelTab===s,onClick:()=>a(s),t:n},s)),e.jsx("div",{style:{flex:1}}),e.jsx("button",{onClick:()=>o({type:"SET_CELLS",cells:t.cells}),title:"Clear logs",style:{background:"transparent",border:"none",cursor:"pointer",color:n.textMuted,fontSize:11,fontFamily:n.font,padding:"2px 6px",borderRadius:4},children:"Clear"})]}),e.jsxs("div",{style:{flex:1,overflow:"auto",padding:"4px 0"},children:[t.devPanelTab==="logs"&&(t.queryLog.length===0?e.jsx(fe,{t:n,message:"No queries executed yet."}):[...t.queryLog].reverse().map(s=>e.jsx(he,{entry:s,t:n},s.id))),t.devPanelTab==="errors"&&(l.length===0?e.jsx(fe,{t:n,message:"No errors."}):[...l].reverse().map(s=>e.jsx(he,{entry:s,t:n},s.id)))]})]}),e.jsxs("button",{onClick:()=>o({type:"TOGGLE_DEV_PANEL"}),onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),title:t.devPanelOpen?"Close panel":"Open dev panel",style:{position:"absolute",bottom:t.devPanelOpen?4:-28,right:8,height:22,padding:"0 8px",borderRadius:"4px 4px 0 0",border:`1px solid ${n.headerBorder}`,borderBottom:t.devPanelOpen?`1px solid ${n.sidebarBg}`:void 0,background:r?n.btnHover:n.sidebarBg,color:n.textMuted,cursor:"pointer",fontSize:11,fontFamily:n.font,display:"flex",alignItems:"center",gap:4,transition:"background 0.15s, bottom 0.2s ease",zIndex:10},children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"currentColor",children:e.jsx("path",{d:t.devPanelOpen?"M1 7l4-4 4 4":"M1 3l4 4 4-4",strokeWidth:"1.5",stroke:"currentColor",fill:"none"})}),"Dev"]})]})}function Yt({label:t,active:o,onClick:n,t:r}){const[i,l]=f.useState(!1);return e.jsx("button",{onClick:n,onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),style:{background:"transparent",border:"none",borderBottom:o?`2px solid ${r.accent}`:"2px solid transparent",cursor:"pointer",color:o?r.textPrimary:i?r.textSecondary:r.textMuted,fontSize:12,fontFamily:r.font,fontWeight:o?500:400,padding:"4px 8px",height:32,transition:"color 0.15s"},children:t})}function fe({t,message:o}){return e.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",color:t.textMuted,fontSize:12,fontFamily:t.font,fontStyle:"italic"},children:o})}function he({entry:t,t:o}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"3px 12px",fontSize:11,fontFamily:o.fontMono,color:t.error?o.error:o.textSecondary,borderLeft:t.error?`2px solid ${o.error}`:"2px solid transparent"},children:[e.jsx("span",{style:{color:o.textMuted,flexShrink:0},children:Ut(t.ts)}),e.jsx("span",{style:{flexShrink:0,color:o.textPrimary,maxWidth:160,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.cellName}),t.error?e.jsx("span",{style:{color:o.error,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.error}):e.jsxs(e.Fragment,{children:[e.jsxs("span",{style:{color:o.textMuted},children:[t.rows.toLocaleString()," rows"]}),e.jsx("span",{style:{color:o.textMuted},children:Qt(t.time)})]})]})}function Kt({onOpenFile:t}){const{state:o,dispatch:n}=w(),r=S[o.themeMode],i=o.files.slice(0,3);return e.jsx("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",background:r.appBg,padding:40,overflow:"auto"},children:e.jsxs("div",{style:{maxWidth:720,width:"100%",display:"flex",flexDirection:"column",alignItems:"center",gap:48},children:[e.jsxs("div",{style:{textAlign:"center",display:"flex",flexDirection:"column",alignItems:"center",gap:16},children:[e.jsx("div",{style:{width:72,height:72,borderRadius:16,background:"linear-gradient(135deg, #388bfd 0%, #1f6feb 60%, #0d419d 100%)",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 8px 32px rgba(56,139,253,0.3)"},children:e.jsx("span",{style:{color:"#fff",fontSize:26,fontWeight:800,fontFamily:r.fontMono,letterSpacing:"-1px"},children:"DQL"})}),e.jsxs("div",{children:[e.jsx("h1",{style:{fontSize:32,fontWeight:700,color:r.textPrimary,fontFamily:r.font,marginBottom:8,letterSpacing:"-0.5px"},children:"DQL Notebook"}),e.jsx("p",{style:{fontSize:15,color:r.textSecondary,fontFamily:r.font,letterSpacing:"0.02em"},children:"Analytics as Code"})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:16,width:"100%"},children:[e.jsx(xe,{title:"New Notebook",description:"Start a fresh analysis with an empty notebook.",icon:e.jsx(en,{}),accent:r.accent,onClick:()=>n({type:"OPEN_NEW_NOTEBOOK_MODAL"}),t:r}),e.jsx(Jt,{recentFiles:i,onOpenFile:t,t:r}),e.jsx(xe,{title:"Browse Examples",description:"Explore sample notebooks and DQL workbooks.",icon:e.jsx(nn,{}),accent:r.success,onClick:()=>{const l=o.files.find(a=>a.folder.toLowerCase()==="notebooks");l&&t(l)},t:r})]}),e.jsxs("div",{style:{width:"100%",borderRadius:10,border:`1px solid ${r.cellBorder}`,padding:"16px 20px",background:r.cellBg},children:[e.jsx("div",{style:{fontSize:11,fontWeight:600,letterSpacing:"0.08em",textTransform:"uppercase",color:r.textMuted,fontFamily:r.font,marginBottom:12},children:"Quick Tips"}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:8},children:[["Shift + Enter","Run cell"],["Click +","Add a new cell"],["Double-click MD cell","Edit markdown"],["Header title","Click to rename notebook"]].map(([l,a])=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("kbd",{style:{background:r.pillBg,border:`1px solid ${r.cellBorder}`,borderRadius:4,padding:"2px 6px",fontSize:11,fontFamily:r.fontMono,color:r.textSecondary,whiteSpace:"nowrap"},children:l}),e.jsx("span",{style:{fontSize:12,color:r.textMuted,fontFamily:r.font},children:a})]},l))})]})]})})}function xe({title:t,description:o,icon:n,accent:r,onClick:i,t:l}){const[a,s]=f.useState(!1);return e.jsxs("button",{onClick:i,onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),style:{background:a?l.cellBg:"transparent",border:`1px solid ${a?r:l.cellBorder}`,borderRadius:10,padding:"20px 16px",cursor:"pointer",textAlign:"left",display:"flex",flexDirection:"column",gap:10,transition:"border-color 0.2s, background 0.2s, box-shadow 0.2s",boxShadow:a?`0 0 0 1px ${r}30, 0 4px 16px rgba(0,0,0,0.15)`:"none"},children:[e.jsx("div",{style:{width:36,height:36,borderRadius:8,background:`${r}18`,display:"flex",alignItems:"center",justifyContent:"center",color:r},children:n}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:13,fontWeight:600,color:l.textPrimary,fontFamily:l.font,marginBottom:4},children:t}),e.jsx("div",{style:{fontSize:12,color:l.textSecondary,fontFamily:l.font,lineHeight:1.5},children:o})]})]})}function Jt({recentFiles:t,onOpenFile:o,t:n}){const[r,i]=f.useState(!1);return e.jsxs("div",{onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),style:{background:r?n.cellBg:"transparent",border:`1px solid ${r?n.textMuted:n.cellBorder}`,borderRadius:10,padding:"20px 16px",textAlign:"left",display:"flex",flexDirection:"column",gap:10,transition:"border-color 0.2s, background 0.2s"},children:[e.jsx("div",{style:{width:36,height:36,borderRadius:8,background:`${n.warning}18`,display:"flex",alignItems:"center",justifyContent:"center",color:n.warning},children:e.jsx(tn,{})}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:13,fontWeight:600,color:n.textPrimary,fontFamily:n.font,marginBottom:8},children:"Open Recent"}),t.length===0?e.jsx("div",{style:{fontSize:12,color:n.textMuted,fontFamily:n.font,fontStyle:"italic"},children:"No recent files."}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:t.map(l=>e.jsx(Xt,{file:l,onClick:()=>o(l),t:n},l.path))})]})]})}function Xt({file:t,onClick:o,t:n}){const[r,i]=f.useState(!1);return e.jsx("button",{onClick:o,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),style:{background:"transparent",border:"none",cursor:"pointer",color:r?n.accent:n.textSecondary,fontSize:12,fontFamily:n.font,textAlign:"left",padding:"2px 0",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",transition:"color 0.15s"},children:t.name.replace(/\.(dqlnb|dql)$/,"")})}function en(){return e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M2 1.75C2 .784 2.784 0 3.75 0h6.586c.464 0 .909.184 1.237.513l2.914 2.914c.329.328.513.773.513 1.237v9.586A1.75 1.75 0 0 1 13.25 16h-9.5A1.75 1.75 0 0 1 2 14.25Zm1.75-.25a.25.25 0 0 0-.25.25v12.5c0 .138.112.25.25.25h9.5a.25.25 0 0 0 .25-.25V6h-2.75A1.75 1.75 0 0 1 8.75 4.25V1.5ZM8.75 5.5h2.836L10.25 3.664V4.25c0 .138.112.25.25.25H8.75Zm.5 3.25a.75.75 0 0 1 .75.75v.75h.75a.75.75 0 0 1 0 1.5H10v.75a.75.75 0 0 1-1.5 0V11.5H7.75a.75.75 0 0 1 0-1.5H8.5V9.5a.75.75 0 0 1 .75-.75Z"})})}function tn(){return e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M8 0a8 8 0 1 1 0 16A8 8 0 0 1 8 0ZM1.5 8a6.5 6.5 0 1 0 13 0 6.5 6.5 0 0 0-13 0Zm7-3.25v2.992l2.028.812a.75.75 0 0 1-.557 1.392l-2.5-1A.751.751 0 0 1 7 8.25v-3.5a.75.75 0 0 1 1.5 0Z"})})}function nn(){return e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M.24 2.375C.24 1.064 1.225.001 2.409.001h6.451a1.17 1.17 0 0 1 .828.344l3.311 3.312a1.17 1.17 0 0 1 .344.828v9.14c0 1.31-.985 2.374-2.169 2.374H2.41C1.225 16 .24 14.937.24 13.625ZM2.41 1.376a.846.846 0 0 0-.844.86v11.39c0 .47.38.86.844.86h8.774a.847.847 0 0 0 .844-.86V5.157L8.688 1.373H2.41Z"})})}function je({value:t,onChange:o,onRun:n,themeMode:r,autoFocus:i}){const l=S[r],a=f.useRef(null),s=f.useRef(null),c=f.useRef(n),h=f.useRef(o);return c.current=n,h.current=o,f.useEffect(()=>{if(!a.current)return;const d=Ae.of([{key:"Shift-Enter",run:()=>(c.current(),!0)},{key:"Ctrl-Enter",mac:"Cmd-Enter",run:()=>(c.current(),!0)},Oe,..._e]),p=V.updateListener.of(y=>{y.docChanged&&h.current(y.state.doc.toString())}),u=V.theme({"&":{background:l.editorBg,fontFamily:l.fontMono,fontSize:"13px",minHeight:"80px",maxHeight:"400px"},".cm-scroller":{overflow:"auto",fontFamily:"inherit"},".cm-content":{padding:"10px 0",minHeight:"80px"},".cm-focused":{outline:"none"},".cm-editor":{border:"none"}}),g=[d,p,u,De(),$e(),Ie(),V.lineWrapping,...r==="dark"?[Fe]:[]],x=Ne.create({doc:t,extensions:g}),m=new V({state:x,parent:a.current});return s.current=m,i&&m.focus(),()=>{m.destroy(),s.current=null}},[r]),f.useEffect(()=>{const d=s.current;if(!d)return;const p=d.state.doc.toString();p!==t&&d.dispatch({changes:{from:0,to:p.length,insert:t}})},[t]),e.jsx("div",{ref:a,style:{background:l.editorBg,minHeight:80}})}je.displayName="SQLCellEditor";function on(t,o){const n=t.split(`
173
- `),r=[];let i=0;for(;i<n.length;){const l=n[i],a=l.match(/^(#{1,6})\s+(.+)$/);if(a){const s=a[1].length,c=a[2],d=[28,22,18,16,14,13][s-1];r.push(e.jsx("div",{style:{fontSize:d,fontWeight:s<=2?700:600,color:o.textPrimary,fontFamily:o.font,lineHeight:1.3,marginBottom:s===1?12:8,marginTop:i>0?s===1?16:10:0,borderBottom:s===1?`1px solid ${o.cellBorder}`:void 0,paddingBottom:s===1?8:void 0},children:q(c,o)},i)),i++;continue}if(/^[-*_]{3,}$/.test(l.trim())){r.push(e.jsx("hr",{style:{border:"none",borderTop:`1px solid ${o.cellBorder}`,margin:"12px 0"}},i)),i++;continue}if(l.startsWith("> ")){r.push(e.jsx("div",{style:{borderLeft:`3px solid ${o.textMuted}`,paddingLeft:12,marginLeft:4,color:o.textSecondary,fontStyle:"italic",fontFamily:o.fontSerif,fontSize:14},children:q(l.slice(2),o)},i)),i++;continue}if(l.startsWith("```")){const s=[];for(i++;i<n.length&&!n[i].startsWith("```");)s.push(n[i]),i++;r.push(e.jsx("pre",{style:{background:o.editorBg,border:`1px solid ${o.cellBorder}`,borderRadius:6,padding:"10px 12px",fontSize:12,fontFamily:o.fontMono,color:o.textPrimary,overflow:"auto",margin:"8px 0",lineHeight:1.6},children:s.join(`
174
- `)},i)),i++;continue}if(/^[-*+]\s/.test(l)){const s=[];for(;i<n.length&&/^[-*+]\s/.test(n[i]);)s.push(n[i].replace(/^[-*+]\s/,"")),i++;r.push(e.jsx("ul",{style:{paddingLeft:20,marginBottom:8,color:o.textSecondary},children:s.map((c,h)=>e.jsx("li",{style:{fontSize:14,fontFamily:o.font,lineHeight:1.6,marginBottom:2},children:q(c,o)},h))},i));continue}if(/^\d+\.\s/.test(l)){const s=[];for(;i<n.length&&/^\d+\.\s/.test(n[i]);)s.push(n[i].replace(/^\d+\.\s/,"")),i++;r.push(e.jsx("ol",{style:{paddingLeft:20,marginBottom:8,color:o.textSecondary},children:s.map((c,h)=>e.jsx("li",{style:{fontSize:14,fontFamily:o.font,lineHeight:1.6,marginBottom:2},children:q(c,o)},h))},i));continue}if(!l.trim()){r.push(e.jsx("div",{style:{height:8}},i)),i++;continue}r.push(e.jsx("p",{style:{fontSize:14,lineHeight:1.7,fontFamily:o.fontSerif,color:o.textSecondary,marginBottom:6},children:q(l,o)},i)),i++}return r}function q(t,o){const n=[];let r=t,i=0;for(;r.length>0;){const l=r.match(/\*{3}(.+?)\*{3}/),a=r.match(/\*{2}(.+?)\*{2}/),s=r.match(/\*(.+?)\*/),c=r.match(/`(.+?)`/),h=r.match(/\[(.+?)\]\((.+?)\)/),d=[l?{match:l,type:"boldItalic"}:null,a?{match:a,type:"bold"}:null,s?{match:s,type:"italic"}:null,c?{match:c,type:"code"}:null,h?{match:h,type:"link"}:null].filter(Boolean);if(d.length===0){n.push(e.jsx(Q.Fragment,{children:r},i++));break}const p=d.reduce((g,x)=>(g.match.index??0)<(x.match.index??0)?g:x),u=p.match.index??0;switch(u>0&&n.push(e.jsx(Q.Fragment,{children:r.slice(0,u)},i++)),p.type){case"boldItalic":n.push(e.jsx("strong",{style:{fontStyle:"italic"},children:p.match[1]},i++));break;case"bold":n.push(e.jsx("strong",{children:p.match[1]},i++));break;case"italic":n.push(e.jsx("em",{children:p.match[1]},i++));break;case"code":n.push(e.jsx("code",{style:{background:o.editorBg,border:`1px solid ${o.cellBorder}`,borderRadius:4,padding:"1px 5px",fontSize:"0.9em",fontFamily:o.fontMono,color:o.accent},children:p.match[1]},i++));break;case"link":n.push(e.jsx("a",{href:p.match[2],target:"_blank",rel:"noopener noreferrer",style:{color:o.accent,textDecoration:"underline"},children:p.match[1]},i++));break}r=r.slice(u+p.match[0].length)}return e.jsx(e.Fragment,{children:n})}function rn({value:t,onChange:o,onRun:n,themeMode:r}){const i=S[r],[l,a]=f.useState(!1),s=f.useRef(null);f.useEffect(()=>{if(l&&s.current){s.current.focus();const p=s.current;p.style.height="auto",p.style.height=`${Math.max(p.scrollHeight,80)}px`}},[l]);const c=()=>{a(!1)},h=p=>{if(p.key==="Escape"&&a(!1),p.key==="Enter"&&p.shiftKey&&(p.preventDefault(),a(!1),n==null||n()),p.key==="Tab"){p.preventDefault();const u=p.currentTarget,g=u.selectionStart,x=u.selectionEnd,m=t.slice(0,g)+" "+t.slice(x);o(m),requestAnimationFrame(()=>{u.selectionStart=u.selectionEnd=g+2})}},d=p=>{o(p.target.value);const u=p.target;u.style.height="auto",u.style.height=`${Math.max(u.scrollHeight,80)}px`};return l?e.jsx("textarea",{ref:s,value:t,onChange:d,onBlur:c,onKeyDown:h,placeholder:"Write markdown here...",spellCheck:!1,style:{display:"block",width:"100%",minHeight:80,padding:"12px 16px",background:i.editorBg,color:i.textPrimary,border:"none",outline:"none",resize:"none",fontFamily:i.fontMono,fontSize:13,lineHeight:"20px",borderRadius:0,caretColor:i.accent}}):t.trim()?e.jsx("div",{onDoubleClick:()=>a(!0),title:"Double-click to edit",style:{padding:"12px 16px",cursor:"text",minHeight:48},children:on(t,i)}):e.jsx("div",{onDoubleClick:()=>a(!0),style:{padding:"12px 16px",color:i.textMuted,fontFamily:i.font,fontSize:13,fontStyle:"italic",cursor:"text",minHeight:48,display:"flex",alignItems:"center"},children:"Double-click to add markdown..."})}function ln({cell:t,themeMode:o}){const{dispatch:n}=w(),r=S[o],[i,l]=f.useState(!1),a=t.paramConfig??{paramType:"text",label:"Parameter",defaultValue:"",options:[]},s=t.paramValue??a.defaultValue,c=u=>{n({type:"UPDATE_CELL",id:t.id,updates:{paramConfig:{...a,...u}}})},h=u=>{n({type:"SET_PARAM_VALUE",id:t.id,value:u})},d=(a.options??[]).map(u=>u.trim()).filter(Boolean),p=t.name?`{{${t.name}}}`:null;return e.jsxs("div",{style:{background:r.cellBg,border:`1px solid ${r.cellBorder}`,borderLeft:"3px solid #e3b341",borderRadius:8,overflow:"hidden"},children:[i&&e.jsxs("div",{style:{background:r.tableHeaderBg,borderBottom:`1px solid ${r.cellBorder}`,padding:"12px 14px",display:"flex",flexDirection:"column",gap:10},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:2},children:[e.jsx("span",{style:{fontSize:11,fontWeight:600,letterSpacing:"0.06em",color:"#e3b341",fontFamily:r.fontMono,textTransform:"uppercase"},children:"Configure Parameter"}),e.jsx("button",{onClick:()=>l(!1),title:"Done",style:{background:"#e3b341",border:"none",borderRadius:5,cursor:"pointer",color:"#000",fontSize:11,fontWeight:700,fontFamily:r.font,padding:"3px 10px",display:"flex",alignItems:"center",gap:4},children:"✓ Done"})]}),e.jsxs("div",{style:{display:"flex",gap:10,flexWrap:"wrap"},children:[e.jsxs("label",{style:{display:"flex",flexDirection:"column",gap:3,flex:"1 1 120px"},children:[e.jsx("span",{style:{fontSize:10,color:r.textMuted,fontFamily:r.font},children:"Variable name"}),e.jsx("input",{value:t.name??"",onChange:u=>n({type:"UPDATE_CELL",id:t.id,updates:{name:u.target.value||void 0}}),placeholder:"e.g. start_date",style:{background:r.inputBg,border:`1px solid ${r.inputBorder}`,borderRadius:4,color:r.textPrimary,fontSize:12,fontFamily:r.fontMono,padding:"4px 7px",outline:"none"}})]}),e.jsxs("label",{style:{display:"flex",flexDirection:"column",gap:3,flex:"1 1 120px"},children:[e.jsx("span",{style:{fontSize:10,color:r.textMuted,fontFamily:r.font},children:"Display label"}),e.jsx("input",{value:a.label,onChange:u=>c({label:u.target.value}),placeholder:"e.g. Start Date",style:{background:r.inputBg,border:`1px solid ${r.inputBorder}`,borderRadius:4,color:r.textPrimary,fontSize:12,fontFamily:r.font,padding:"4px 7px",outline:"none"}})]}),e.jsxs("label",{style:{display:"flex",flexDirection:"column",gap:3,flex:"1 1 100px"},children:[e.jsx("span",{style:{fontSize:10,color:r.textMuted,fontFamily:r.font},children:"Type"}),e.jsxs("select",{value:a.paramType,onChange:u=>c({paramType:u.target.value}),style:{background:r.inputBg,border:`1px solid ${r.inputBorder}`,borderRadius:4,color:r.textPrimary,fontSize:12,fontFamily:r.font,padding:"4px 7px",outline:"none"},children:[e.jsx("option",{value:"text",children:"Text"}),e.jsx("option",{value:"number",children:"Number"}),e.jsx("option",{value:"date",children:"Date"}),e.jsx("option",{value:"select",children:"Select"})]})]}),e.jsxs("label",{style:{display:"flex",flexDirection:"column",gap:3,flex:"1 1 120px"},children:[e.jsx("span",{style:{fontSize:10,color:r.textMuted,fontFamily:r.font},children:"Default value"}),e.jsx("input",{type:a.paramType==="number"?"number":a.paramType==="date"?"date":"text",value:a.defaultValue,onChange:u=>c({defaultValue:u.target.value}),style:{background:r.inputBg,border:`1px solid ${r.inputBorder}`,borderRadius:4,color:r.textPrimary,fontSize:12,fontFamily:r.font,padding:"4px 7px",outline:"none"}})]})]}),a.paramType==="select"&&e.jsxs("label",{style:{display:"flex",flexDirection:"column",gap:3},children:[e.jsx("span",{style:{fontSize:10,color:r.textMuted,fontFamily:r.font},children:"Options (one per line)"}),e.jsx("textarea",{value:(a.options??[]).join(`
175
- `),onChange:u=>c({options:u.target.value.split(`
176
- `)}),rows:4,placeholder:`Option A
177
- Option B
178
- Option C`,style:{background:r.inputBg,border:`1px solid ${r.inputBorder}`,borderRadius:4,color:r.textPrimary,fontSize:12,fontFamily:r.fontMono,padding:"5px 7px",outline:"none",resize:"vertical"}})]})]}),e.jsxs("div",{style:{padding:"12px 14px",display:"flex",alignItems:"center",gap:12,flexWrap:"wrap"},children:[e.jsx("button",{onClick:()=>l(u=>!u),title:i?"Close config":"Configure parameter",style:{background:i?"#e3b34118":"transparent",border:`1px solid ${i?"#e3b341":r.cellBorder}`,borderRadius:5,cursor:"pointer",color:i?"#e3b341":r.textMuted,width:26,height:26,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,transition:"all 0.15s"},children:i?e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M13.78 4.22a.75.75 0 0 1 0 1.06l-7.25 7.25a.75.75 0 0 1-1.06 0L2.22 9.28a.749.749 0 1 1 1.06-1.06L6 10.94l6.72-6.72a.75.75 0 0 1 1.06 0Z"})}):e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M8 0a8.2 8.2 0 0 1 .701.031C9.444.095 9.99.645 10.16 1.29l.288 1.107c.018.066.079.158.212.224.231.114.454.243.668.386.123.082.233.09.299.071l1.103-.303c.644-.176 1.392.021 1.82.63.27.385.506.792.704 1.218.315.675.111 1.422-.364 1.891l-.814.806c-.049.048-.098.147-.088.294.016.257.016.515 0 .772-.01.147.038.246.088.294l.814.806c.475.469.679 1.216.364 1.891a7.977 7.977 0 0 1-.704 1.217c-.428.61-1.176.807-1.82.63l-1.102-.302c-.067-.019-.177-.011-.3.071a5.909 5.909 0 0 1-.668.386c-.133.066-.194.158-.211.224l-.29 1.106c-.168.646-.715 1.196-1.458 1.26a8.006 8.006 0 0 1-1.402 0c-.743-.064-1.289-.614-1.458-1.26l-.289-1.106c-.018-.066-.079-.158-.212-.224a5.738 5.738 0 0 1-.668-.386c-.123-.082-.233-.09-.299-.071l-1.103.303c-.644.176-1.392-.021-1.82-.63a8.12 8.12 0 0 1-.704-1.218c-.315-.675-.111-1.422.363-1.891l.815-.806c.05-.048.098-.147.088-.294a6.214 6.214 0 0 1 0-.772c.01-.147-.038-.246-.088-.294l-.815-.806C.635 6.045.431 5.298.746 4.623a7.92 7.92 0 0 1 .704-1.217c.428-.61 1.176-.807 1.82-.63l1.102.302c.067.019.177.011.3-.071.214-.143.437-.272.668-.386.133-.066.194-.158.211-.224l.29-1.106C6.009.645 6.556.095 7.299.03 7.53.01 7.764 0 8 0Zm-.571 1.525c-.036.003-.108.036-.137.146l-.289 1.105c-.147.561-.549.967-.998 1.189-.173.086-.34.183-.5.29-.417.278-.97.423-1.529.27l-1.103-.303c-.109-.03-.175.016-.195.045-.22.312-.412.644-.573.99-.014.031-.021.11.059.19l.815.806c.411.406.562.957.53 1.456a4.709 4.709 0 0 0 0 .582c.032.499-.119 1.05-.53 1.456l-.815.806c-.081.08-.073.159-.059.19.162.346.353.677.573.989.02.03.085.076.195.046l1.102-.303c.56-.153 1.113-.008 1.53.27.161.107.328.204.501.29.447.222.85.629.997 1.189l.289 1.105c.029.109.101.143.137.146a6.6 6.6 0 0 0 1.142 0c.036-.003.108-.036.137-.146l.289-1.105c.147-.561.549-.967.998-1.189.173-.086.34-.183.5-.29.417-.278.97-.423 1.529-.27l1.103.303c.109.029.175-.016.195-.045.22-.313.411-.644.573-.99.014-.031.021-.11-.059-.19l-.815-.806c-.411-.406-.562-.957-.53-1.456a4.709 4.709 0 0 0 0-.582c-.032-.499.119-1.05.53-1.456l.815-.806c.081-.08.073-.159.059-.19a6.464 6.464 0 0 0-.573-.989c-.02-.03-.085-.076-.195-.046l-1.102.303c-.56.153-1.113.008-1.53-.27a4.44 4.44 0 0 0-.501-.29c-.447-.222-.85-.629-.997-1.189l-.289-1.105c-.029-.11-.101-.143-.137-.146a6.6 6.6 0 0 0-1.142 0ZM8 5.5a2.5 2.5 0 1 1 0 5 2.5 2.5 0 0 1 0-5ZM8 7a1 1 0 1 0 0 2 1 1 0 0 0 0-2Z"})})}),e.jsx("span",{style:{fontSize:13,fontWeight:500,fontFamily:r.font,color:r.textSecondary,flexShrink:0},children:a.label}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:3},children:[a.paramType==="select"?e.jsx("select",{value:s,onChange:u=>h(u.target.value),style:{background:r.inputBg,border:`1px solid ${r.inputBorder}`,borderRadius:5,color:r.textPrimary,fontSize:13,fontFamily:r.font,padding:"5px 10px",outline:"none",minWidth:160},children:d.length===0?e.jsx("option",{value:"",children:"— no options configured —"}):d.map(u=>e.jsx("option",{value:u,children:u},u))}):e.jsx("input",{type:a.paramType,value:s,onChange:u=>h(u.target.value),style:{background:r.inputBg,border:`1px solid ${r.inputBorder}`,borderRadius:5,color:r.textPrimary,fontSize:13,fontFamily:a.paramType==="number"?r.fontMono:r.font,padding:"5px 10px",outline:"none",minWidth:160}}),p&&e.jsx("span",{style:{fontSize:10,fontFamily:r.fontMono,color:"#e3b341",opacity:.8},children:p})]}),s&&e.jsx("span",{style:{fontSize:12,fontFamily:r.fontMono,color:r.textPrimary,background:"#e3b34118",border:"1px solid #e3b34140",borderRadius:4,padding:"2px 8px",flexShrink:0},children:s})]})]})}const sn=[{id:"select-all",label:"Select all rows",description:"Read all rows from a CSV file with a row limit",category:"SQL",code:"SELECT * FROM read_csv_auto('data/filename.csv') LIMIT 100"},{id:"group-by",label:"Group and aggregate",description:"Group rows and compute count + sum",category:"SQL",code:`SELECT
179
- category,
180
- COUNT(*) AS count,
181
- SUM(amount) AS total
182
- FROM read_csv_auto('data/filename.csv')
183
- GROUP BY category
184
- ORDER BY total DESC`},{id:"filter-date",label:"Filter by date range",description:"Filter rows between two dates",category:"SQL",code:`SELECT *
185
- FROM read_csv_auto('data/filename.csv')
186
- WHERE date_column >= '2024-01-01'
187
- AND date_column < '2025-01-01'`},{id:"window-rank",label:"Window function: rank",description:"Rank rows within groups using ROW_NUMBER()",category:"SQL",code:`SELECT
188
- *,
189
- ROW_NUMBER() OVER (PARTITION BY category ORDER BY amount DESC) AS rank
190
- FROM read_csv_auto('data/filename.csv')`},{id:"cte",label:"CTE (WITH clause)",description:"Define a named subquery with WITH",category:"SQL",code:`WITH base AS (
191
- SELECT *
192
- FROM read_csv_auto('data/filename.csv')
193
- WHERE amount > 0
194
- )
195
- SELECT
196
- category,
197
- SUM(amount) AS total
198
- FROM base
199
- GROUP BY category`},{id:"join",label:"Join two tables",description:"Join two CSV files on a shared key",category:"SQL",code:`SELECT a.*, b.name
200
- FROM read_csv_auto('data/table_a.csv') AS a
201
- JOIN read_csv_auto('data/table_b.csv') AS b
202
- ON a.id = b.id`},{id:"pivot",label:"Pivot / unpivot",description:"Pivot a column into multiple columns",category:"SQL",code:`SELECT *
203
- FROM (
204
- SELECT category, quarter, amount
205
- FROM read_csv_auto('data/filename.csv')
206
- ) PIVOT (SUM(amount) FOR quarter IN ('Q1', 'Q2', 'Q3', 'Q4'))`},{id:"dql-block",label:"DQL block (basic)",description:"Minimal DQL block with a table visualization",category:"DQL",code:`block "My Block" {
207
- domain = "analytics"
208
- type = "custom"
209
- description = "Describe what this block does"
210
- owner = "data-team"
211
- tags = ["analytics"]
212
-
213
- query = """
214
- SELECT *
215
- FROM read_csv_auto('data/filename.csv')
216
- LIMIT 100
217
- """
218
-
219
- visualization {
220
- chart = "table"
221
- }
222
- }`},{id:"dql-block-bar",label:"DQL block with bar chart",description:"DQL block with params, bar chart, and a test assertion",category:"DQL",code:`block "Revenue by Segment" {
223
- domain = "revenue"
224
- type = "custom"
225
- description = "Revenue grouped by segment"
226
- owner = "data-team"
227
- tags = ["revenue"]
228
-
229
- params {
230
- period = "current_quarter"
231
- }
232
-
233
- query = """
234
- SELECT
235
- segment_tier AS segment,
236
- SUM(amount) AS revenue
237
- FROM read_csv_auto('data/revenue.csv')
238
- WHERE fiscal_period = \${period}
239
- GROUP BY segment_tier
240
- ORDER BY revenue DESC
241
- """
242
-
243
- visualization {
244
- chart = "bar"
245
- x = segment
246
- y = revenue
247
- }
248
-
249
- tests {
250
- assert row_count > 0
251
- }
252
- }`},{id:"revenue-by-segment",label:"Revenue by segment",description:"Aggregate revenue totals, deal count, and average deal size per segment",category:"Analysis",code:`SELECT
253
- segment_tier,
254
- SUM(amount) AS total_revenue,
255
- COUNT(*) AS deals,
256
- ROUND(AVG(amount), 0) AS avg_deal
257
- FROM read_csv_auto('data/revenue.csv')
258
- GROUP BY segment_tier
259
- ORDER BY total_revenue DESC`},{id:"quarterly-trend",label:"Quarterly trend",description:"Revenue totals grouped by fiscal year and quarter",category:"Analysis",code:`SELECT
260
- fiscal_year || ' ' || fiscal_quarter AS period,
261
- SUM(amount) AS revenue
262
- FROM read_csv_auto('data/revenue.csv')
263
- GROUP BY fiscal_year, fiscal_quarter
264
- ORDER BY fiscal_year, fiscal_quarter`}];function an({onInsert:t,themeMode:o,cellType:n}){const r=S[o],[i,l]=f.useState(!1),[a,s]=f.useState(null),c=f.useRef(null),h=sn.filter(u=>n==="dql"?u.category==="DQL":u.category==="SQL"||u.category==="Analysis"),d=Array.from(new Set(h.map(u=>u.category)));f.useEffect(()=>{if(!i)return;function u(g){c.current&&!c.current.contains(g.target)&&l(!1)}return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[i]);function p(u){t(u),l(!1)}return e.jsxs("div",{ref:c,style:{position:"relative",display:"inline-block"},children:[e.jsxs("button",{title:"Insert template snippet",onClick:()=>l(u=>!u),style:{height:22,padding:"0 8px",fontSize:10,fontFamily:r.font,fontWeight:600,letterSpacing:"0.04em",color:i?r.accent:r.textMuted,background:i?`${r.accent}15`:"transparent",border:`1px solid ${i?r.accent+"50":r.btnBorder}`,borderRadius:4,cursor:"pointer",display:"flex",alignItems:"center",gap:4,transition:"all 0.15s",whiteSpace:"nowrap"},children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M2 2.5A2.5 2.5 0 0 1 4.5 0h8.75a.75.75 0 0 1 .75.75v12.5a.75.75 0 0 1-.75.75h-2.5a.75.75 0 0 1 0-1.5h1.75v-2h-8a1 1 0 0 0-.714 1.7.75.75 0 1 1-1.072 1.05A2.495 2.495 0 0 1 2 11.5Zm10.5-1h-8a1 1 0 0 0-1 1v6.708A2.486 2.486 0 0 1 4.5 9h8ZM5 12.25a.25.25 0 0 1 .25-.25h3.5a.25.25 0 0 1 .25.25v3.25a.25.25 0 0 1-.4.2l-1.45-1.087a.249.249 0 0 0-.3 0L5.4 15.7a.25.25 0 0 1-.4-.2Z"})}),"Templates"]}),i&&e.jsx("div",{style:{position:"absolute",top:"calc(100% + 4px)",left:0,zIndex:300,width:300,maxHeight:360,overflowY:"auto",background:r.modalBg,border:`1px solid ${r.cellBorder}`,borderRadius:8,boxShadow:"0 8px 24px rgba(0,0,0,0.3)",padding:"6px 0"},children:d.map(u=>e.jsxs("div",{children:[e.jsx("div",{style:{padding:"6px 12px 4px",fontSize:10,fontWeight:700,fontFamily:r.font,letterSpacing:"0.08em",textTransform:"uppercase",color:r.textMuted},children:u}),h.filter(g=>g.category===u).map(g=>e.jsxs("button",{onMouseEnter:()=>s(g.id),onMouseLeave:()=>s(null),onClick:()=>p(g.code),style:{width:"100%",padding:"7px 12px",textAlign:"left",background:a===g.id?r.sidebarItemHover:"transparent",border:"none",cursor:"pointer",display:"flex",flexDirection:"column",gap:2,transition:"background 0.1s"},children:[e.jsx("span",{style:{fontSize:12,fontWeight:600,fontFamily:r.font,color:r.textPrimary,lineHeight:1.4},children:g.label}),e.jsx("span",{style:{fontSize:11,fontFamily:r.font,color:r.textMuted,lineHeight:1.4},children:g.description})]},g.id))]},u))})]})}const X=500;function dn(t){return typeof t=="number"?!0:typeof t=="string"?!isNaN(Number(t))&&t.trim()!=="":!1}function cn(t){return t==null?"":typeof t=="object"?JSON.stringify(t):String(t)}function we({result:t,themeMode:o}){const n=S[o],[r,i]=f.useState(null),l=t.rows.slice(0,X),a=t.rows.length>X;return t.columns.length===0?e.jsx("div",{style:{padding:"12px 16px",color:n.textMuted,fontSize:12,fontFamily:n.font,fontStyle:"italic"},children:"Query executed successfully. No columns to display."}):e.jsxs("div",{style:{maxHeight:400,overflow:"auto",position:"relative"},children:[e.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",tableLayout:"auto",fontSize:12,fontFamily:n.fontMono},children:[e.jsx("thead",{children:e.jsx("tr",{children:t.columns.map(s=>e.jsx("th",{style:{background:n.tableHeaderBg,color:n.textSecondary,fontWeight:600,fontSize:11,textAlign:"left",padding:"6px 12px",borderBottom:`1px solid ${n.tableBorder}`,borderRight:`1px solid ${n.tableBorder}`,minWidth:80,maxWidth:300,whiteSpace:"nowrap",position:"sticky",top:0,zIndex:1,fontFamily:n.font,letterSpacing:"0.03em",overflow:"hidden",textOverflow:"ellipsis"},children:s},s))})}),e.jsx("tbody",{children:l.map((s,c)=>e.jsx("tr",{onMouseEnter:()=>i(c),onMouseLeave:()=>i(null),style:{background:r===c?n.tableRowHover:"transparent",transition:"background 0.1s"},children:t.columns.map(h=>{const d=s[h],p=d==null,u=dn(d);return e.jsx("td",{style:{padding:"5px 12px",borderBottom:`1px solid ${n.tableBorder}`,borderRight:`1px solid ${n.tableBorder}`,color:p?n.textMuted:n.textPrimary,fontStyle:p?"italic":"normal",textAlign:u?"right":"left",whiteSpace:"nowrap",maxWidth:300,overflow:"hidden",textOverflow:"ellipsis"},children:p?"—":cn(d)},h)})},c))})]}),a&&e.jsxs("div",{style:{padding:"8px 12px",color:n.textMuted,fontSize:11,fontFamily:n.font,borderTop:`1px solid ${n.tableBorder}`,background:n.tableHeaderBg,fontStyle:"italic"},children:["Showing ",X.toLocaleString()," of ",t.rows.length.toLocaleString()," rows"]})]})}const un=/date|time|at|day|month|year/i,ke=/^(label|name|category)$/i,Ee=/^(value|count|total|revenue|amount)$/i;function ge(t){return typeof t=="number"?!0:typeof t=="string"?t.trim()!==""&&!isNaN(Number(t)):!1}function pn(t){return typeof t=="string"||typeof t=="number"}function oe(t){const{columns:o,rows:n}=t;if(o.length<2||n.length===0)return"table";const r=o[0],i=o[1],l=n.slice(0,5),a=l.every(d=>ge(d[i])),s=l.every(d=>pn(d[r]));if(un.test(r)&&a&&s)return"line";const c=o.find(d=>ke.test(d)),h=o.find(d=>Ee.test(d));return c&&h&&l.every(p=>ge(p[h]))||o.length===2&&s&&a?"bar":"table"}function re(t){return Math.abs(t)>=1e6?`${(t/1e6).toFixed(1)}M`:Math.abs(t)>=1e3?`${(t/1e3).toFixed(1)}K`:t.toLocaleString(void 0,{maximumFractionDigits:2})}const ee=20;function fn({result:t,themeMode:o}){const n=S[o],[r,i]=f.useState(null),l=t.columns.find(y=>ke.test(y))??t.columns[0],a=t.columns.find(y=>Ee.test(y))??t.columns[1],s=t.rows.slice(0,ee).map(y=>({label:String(y[l]??""),value:Number(y[a]??0)})),c=t.rows.length>ee,h=Math.max(...s.map(y=>y.value),1),d=28,p=120,u=60,g=6,x=12,m=s.length*(d+g)+x*2;return e.jsxs("div",{style:{padding:"8px 0"},children:[e.jsx("svg",{width:"100%",height:m,style:{display:"block",overflow:"visible"},viewBox:`0 0 600 ${m}`,preserveAspectRatio:"xMidYMid meet",children:s.map((y,k)=>{const j=x+k*(d+g),E=600-p-u-24,T=Math.max(y.value/h*E,2),R=r===k;return e.jsxs("g",{onMouseEnter:()=>i(k),onMouseLeave:()=>i(null),style:{cursor:"default"},children:[e.jsx("text",{x:p-8,y:j+d/2+4,textAnchor:"end",fontSize:11,fontFamily:n.font,fill:n.textSecondary,children:y.label.length>16?y.label.slice(0,15)+"…":y.label}),e.jsx("rect",{x:p,y:j,width:T,height:d,rx:3,fill:R?n.accentHover:n.accent,style:{transition:"fill 0.15s"}}),e.jsx("text",{x:p+T+6,y:j+d/2+4,textAnchor:"start",fontSize:11,fontFamily:n.fontMono,fill:n.textMuted,children:re(y.value)})]},k)})}),c&&e.jsxs("div",{style:{fontSize:11,color:n.textMuted,fontFamily:n.font,fontStyle:"italic",padding:"4px 12px"},children:["Showing ",ee," of ",t.rows.length," rows"]})]})}function hn(t){const o=new Date(t);if(!isNaN(o.getTime())){if(/^\d{4}-\d{2}-\d{2}/.test(t))return o.toLocaleDateString("en-US",{month:"short",day:"numeric"});if(/^\d{4}-\d{2}$/.test(t))return o.toLocaleDateString("en-US",{year:"numeric",month:"short"})}return String(t).length>8?String(t).slice(0,8):String(t)}function xn({result:t,themeMode:o}){const n=S[o],[r,i]=f.useState(null),l=t.columns[0],a=t.columns[1],s=t.rows.map(b=>({label:String(b[l]??""),value:Number(b[a]??0)}));if(s.length<2)return null;const c=560,h=200,d=52,p=16,u=16,g=36,x=c-d-p,m=h-u-g,y=Math.min(...s.map(b=>b.value)),j=Math.max(...s.map(b=>b.value))-y||1,E=x/(s.length-1),T=b=>d+b*E,R=b=>u+m-(b-y)/j*m,O=s.map((b,C)=>({x:T(C),y:R(b.value)})),D=O.reduce((b,C,I)=>{if(I===0)return`M ${C.x},${C.y}`;const N=O[I-1],Ce=N.x+(C.x-N.x)/2,Me=N.y,Le=N.x+(C.x-N.x)/2,Be=C.y;return`${b} C ${Ce},${Me} ${Le},${Be} ${C.x},${C.y}`},""),z=`${D} L ${O[O.length-1].x},${u+m} L ${d},${u+m} Z`,$=5,v=Array.from({length:$+1},(b,C)=>{const I=y+j*C/$,N=R(I);return{val:I,y:N}}),M=Math.ceil(s.length/8),G=s.filter((b,C)=>C%M===0||C===s.length-1);return e.jsx("div",{style:{position:"relative",padding:"8px 0"},children:e.jsxs("svg",{width:"100%",height:h,viewBox:`0 0 ${c} ${h}`,preserveAspectRatio:"xMidYMid meet",style:{display:"block",overflow:"visible"},onMouseLeave:()=>i(null),children:[v.map((b,C)=>e.jsxs("g",{children:[e.jsx("line",{x1:d,y1:b.y,x2:d+x,y2:b.y,stroke:n.tableBorder,strokeWidth:.5}),e.jsx("text",{x:d-6,y:b.y+4,textAnchor:"end",fontSize:10,fontFamily:n.fontMono,fill:n.textMuted,children:re(b.val)})]},C)),e.jsx("path",{d:z,fill:n.accent,opacity:.15}),e.jsx("path",{d:D,fill:"none",stroke:n.accent,strokeWidth:2,strokeLinejoin:"round"}),O.map((b,C)=>e.jsx("circle",{cx:b.x,cy:b.y,r:3,fill:n.accent,style:{cursor:"crosshair"},onMouseEnter:()=>i({x:b.x,y:b.y,label:s[C].label,value:s[C].value})},C)),G.map((b,C)=>{const I=s.indexOf(b);return e.jsx("text",{x:T(I),y:u+m+16,textAnchor:"middle",fontSize:10,fontFamily:n.font,fill:n.textMuted,children:hn(b.label)},C)}),e.jsx("line",{x1:d,y1:u,x2:d,y2:u+m,stroke:n.tableBorder,strokeWidth:1}),e.jsx("line",{x1:d,y1:u+m,x2:d+x,y2:u+m,stroke:n.tableBorder,strokeWidth:1}),r&&e.jsxs("g",{children:[e.jsx("rect",{x:r.x+8,y:r.y-20,width:90,height:32,rx:4,fill:n.cellBg,stroke:n.cellBorder,strokeWidth:1}),e.jsx("text",{x:r.x+13,y:r.y-8,fontSize:10,fontFamily:n.font,fill:n.textSecondary,children:r.label.length>10?r.label.slice(0,10)+"…":r.label}),e.jsx("text",{x:r.x+13,y:r.y+6,fontSize:11,fontFamily:n.fontMono,fill:n.textPrimary,fontWeight:600,children:re(r.value)})]})]})})}function gn({result:t,themeMode:o}){const n=S[o],r=oe(t),[i,l]=f.useState(r!=="table"?"chart":"table"),a=r!=="table";return e.jsxs("div",{children:[a&&e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",alignItems:"center",padding:"4px 12px",gap:4,borderBottom:`1px solid ${n.cellBorder}`,background:`${n.tableHeaderBg}60`},children:[e.jsx("span",{style:{fontSize:10,color:n.textMuted,fontFamily:n.font,marginRight:4},children:"View:"}),["chart","table"].map(s=>e.jsx("button",{onClick:()=>l(s),style:{padding:"2px 8px",fontSize:10,fontFamily:n.font,borderRadius:4,border:`1px solid ${i===s?n.accent:n.btnBorder}`,background:i===s?`${n.accent}20`:"transparent",color:i===s?n.accent:n.textMuted,cursor:"pointer",transition:"all 0.15s",textTransform:"capitalize"},children:s==="chart"?r==="line"?"Line":"Chart":"Table"},s))]}),i==="table"||!a?e.jsx(we,{result:t,themeMode:o}):r==="line"?e.jsx(xn,{result:t,themeMode:o}):e.jsx(fn,{result:t,themeMode:o})]})}function mn(t){let o=t;try{const h=JSON.parse(t);h&&typeof h.error=="string"&&(o=h.error)}catch{}o=o.replace(/^DuckDB query failed:\s*/i,"").trim();let n="Error";/Parser Error/i.test(o)?n="Syntax Error":/Binder Error/i.test(o)?n="Reference Error":/Conversion Error/i.test(o)?n="Type Error":/Invalid Input Error/i.test(o)?n="Input Error":/IO Error/i.test(o)?n="File Error":/Constraint Error/i.test(o)&&(n="Constraint Error");let r;const i=o.match(/LINE\s+(\d+):/i)??o.match(/\bline\s+(\d+)\b/i);i&&(r=parseInt(i[1],10));let l;const a=o.match(/at or near "([^"]+)"/i);a?l=a[1]:/at end of input/i.test(o)&&(l="end of input");let s;n==="Syntax Error"?l==='"""'||o.includes('"""')?s="Triple-quoted strings are DQL block syntax. Use a DQL cell for block syntax, or plain SQL in a SQL cell.":l==="end of input"||/at end of input/i.test(o)?s="Query is incomplete — check for unclosed parentheses, missing keywords, or a dangling comma.":(l===")"||l==="(")&&(s="Mismatched parentheses — check that every opening ( has a closing )."):n==="Reference Error"?/column.*not found|Referenced column/i.test(o)?s="Column not found — check the column name in the Schema panel (left sidebar).":/table.*not found|Table.*does not exist/i.test(o)&&(s="Table not found — make sure the file path is correct and the file exists in your data/ folder."):n==="Input Error"?/No files found/i.test(o)&&(s="File not found — check the path. Use read_csv_auto('data/filename.csv') relative to your project root."):n==="File Error"?s="File could not be read — check the path and make sure the file exists.":n==="Type Error"&&(s="Type mismatch — you may be comparing or casting incompatible types (e.g. text vs number).");const c=o.replace(/^(Parser Error|Binder Error|Conversion Error|Invalid Input Error|IO Error|Constraint Error):\s*/i,"").trim();return{type:n,message:c,line:r,near:l,hint:s}}function yn({message:t,themeMode:o}){const n=S[o],r=mn(t);return e.jsxs("div",{style:{padding:"12px 14px",background:`${n.error}10`,borderLeft:`3px solid ${n.error}`,display:"flex",flexDirection:"column",gap:8},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[e.jsx("div",{style:{flexShrink:0,color:n.error,display:"flex",alignItems:"center"},children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M4.47.22A.749.749 0 0 1 5 0h6c.199 0 .389.079.53.22l4.25 4.25c.141.14.22.331.22.53v6a.749.749 0 0 1-.22.53l-4.25 4.25A.749.749 0 0 1 11 16H5a.749.749 0 0 1-.53-.22L.22 11.53A.749.749 0 0 1 0 11V5c0-.199.079-.389.22-.53Zm.84 1.28L1.5 5.31v5.38l3.81 3.81h5.38l3.81-3.81V5.31L10.69 1.5ZM8 4a.75.75 0 0 1 .75.75v3.5a.75.75 0 0 1-1.5 0v-3.5A.75.75 0 0 1 8 4Zm0 8a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z"})})}),e.jsx("span",{style:{fontSize:10,fontWeight:700,fontFamily:n.fontMono,letterSpacing:"0.06em",textTransform:"uppercase",color:n.error,background:`${n.error}18`,border:`1px solid ${n.error}40`,borderRadius:4,padding:"1px 7px",flexShrink:0},children:r.type}),r.line!==void 0&&e.jsxs("span",{style:{fontSize:10,fontWeight:600,fontFamily:n.fontMono,color:n.textSecondary,background:`${n.textMuted}18`,border:`1px solid ${n.textMuted}30`,borderRadius:4,padding:"1px 7px",flexShrink:0},children:["Line ",r.line]}),r.near&&e.jsxs("span",{style:{fontSize:11,fontFamily:n.fontMono,color:n.textSecondary,flexShrink:0},children:["near ",e.jsxs("span",{style:{color:n.error},children:["“",r.near,"”"]})]})]}),e.jsx("pre",{style:{margin:0,fontFamily:n.fontMono,fontSize:12,color:n.error,lineHeight:1.6,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:r.message}),r.hint&&e.jsxs("div",{style:{marginTop:2,padding:"8px 12px",background:`${n.warning}12`,border:`1px solid ${n.warning}40`,borderRadius:6,display:"flex",alignItems:"flex-start",gap:8},children:[e.jsx("span",{style:{flexShrink:0,fontSize:13,lineHeight:1.5},children:"💡"}),e.jsx("span",{style:{fontSize:12,fontFamily:n.font,color:n.warning,lineHeight:1.6},children:r.hint})]})]})}const bn={sql:"SQL",markdown:"MD",dql:"DQL",param:"PARAM"},te={sql:"#388bfd",markdown:"#56d364",dql:"#e3b341",param:"#e3b341"};function vn(t,o){switch(t.status){case"running":return o.cellBorderRunning;case"success":return o.success;case"error":return o.error;default:return o.cellBorder}}function Sn({cell:t,t:o}){let n="",r=o.textMuted;return t.status==="running"?(n="[*]",r=o.cellBorderRunning):t.status==="error"?(n="[!]",r=o.error):t.executionCount!==void 0?(n=`[${t.executionCount}]`,r=o.textMuted):(n="[ ]",r=o.textMuted),e.jsx("div",{style:{width:40,display:"flex",alignItems:"flex-start",justifyContent:"center",paddingTop:12,flexShrink:0},children:e.jsx("span",{style:{fontFamily:o.fontMono,fontSize:11,color:r,lineHeight:1.4,userSelect:"none",transition:"color 0.2s"},children:n})})}function jn({cell:t,index:o}){const{state:n,dispatch:r}=w(),i=S[n.themeMode],{executeCell:l}=ie(),[a,s]=f.useState(!1),[c,h]=f.useState(!1),[d,p]=f.useState(t.name??""),[u,g]=f.useState(!0),[x,m]=f.useState("table"),y=vn(t,i),k=t.type!=="markdown"&&t.type!=="param";if(t.type==="param")return e.jsxs("div",{onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),style:{display:"flex",gap:0,marginBottom:2},children:[e.jsx("div",{style:{width:40,flexShrink:0}}),e.jsx("div",{style:{flex:1,minWidth:0},children:e.jsx(ln,{cell:t,themeMode:n.themeMode})})]});f.useEffect(()=>{if(t.status==="success"&&t.result){const v=oe(t.result);m(v!=="table"?"chart":"table")}},[t.status,t.result]);const j=f.useCallback(()=>{k&&l(t.id)},[t.id,l,k]),E=f.useCallback(v=>{r({type:"UPDATE_CELL",id:t.id,updates:{content:v}})},[t.id,r]),T=()=>{r({type:"DELETE_CELL",id:t.id})},R=()=>{r({type:"MOVE_CELL",id:t.id,direction:"up"})},O=()=>{r({type:"MOVE_CELL",id:t.id,direction:"down"})},D=()=>{h(!1),r({type:"UPDATE_CELL",id:t.id,updates:{name:d.trim()||void 0}})},z=(t.result||t.error)&&t.type!=="markdown",$=t.result?oe(t.result)!=="table":!1;return e.jsxs("div",{onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),style:{display:"flex",gap:0,marginBottom:2},children:[e.jsx(Sn,{cell:t,t:i}),e.jsxs("div",{style:{flex:1,minWidth:0,borderRadius:8,border:`1px solid ${a||t.status!=="idle"?y:i.cellBorder}`,borderLeft:`2px solid ${y}`,background:i.cellBg,overflow:"hidden",transition:"border-color 0.2s"},children:[e.jsxs("div",{style:{height:32,display:"flex",alignItems:"center",padding:"0 8px 0 10px",gap:8,borderBottom:`1px solid ${i.cellBorder}`,background:`${i.tableHeaderBg}80`},children:[e.jsx("span",{style:{fontSize:10,fontWeight:700,fontFamily:i.fontMono,letterSpacing:"0.08em",color:te[t.type]??i.accent,background:`${te[t.type]??i.accent}18`,border:`1px solid ${te[t.type]??i.accent}40`,borderRadius:4,padding:"1px 6px",flexShrink:0,textTransform:"uppercase"},children:bn[t.type]}),a&&(t.type==="sql"||t.type==="dql")&&e.jsx(an,{themeMode:n.themeMode,cellType:t.type,onInsert:v=>E(v)}),c?e.jsx("input",{autoFocus:!0,value:d,onChange:v=>p(v.target.value),onBlur:D,onKeyDown:v=>{v.key==="Enter"&&D(),v.key==="Escape"&&h(!1)},style:{background:"transparent",border:`1px solid ${i.cellBorderActive}`,borderRadius:4,color:i.textSecondary,fontSize:12,fontFamily:i.fontMono,padding:"1px 6px",outline:"none",width:140}}):t.name&&e.jsx("span",{onClick:()=>{p(t.name??""),h(!0)},title:"Click to rename",style:{color:i.textSecondary,fontSize:12,fontFamily:i.fontMono,cursor:"text",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:200},children:t.name}),e.jsx("div",{style:{flex:1}}),a&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:2},children:[!t.name&&!c&&e.jsx(Z,{title:"Name this cell",onClick:()=>{p(""),h(!0)},t:i,children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M11.013 1.427a1.75 1.75 0 0 1 2.474 0l1.086 1.086a1.75 1.75 0 0 1 0 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 0 1-.927-.928l.929-3.25c.081-.286.235-.547.445-.758l8.61-8.61Zm.176 4.823L9.75 4.81l-6.286 6.287a.253.253 0 0 0-.064.108l-.558 1.953 1.953-.558a.253.253 0 0 0 .108-.064Zm1.238-3.763a.25.25 0 0 0-.354 0L10.811 3.75l1.439 1.44 1.263-1.263a.25.25 0 0 0 0-.354Z"})})}),k&&e.jsx(Z,{title:"Run cell (Shift+Enter)",onClick:j,t:i,accent:!0,children:e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 10 10",fill:"currentColor",children:e.jsx("path",{d:"M1.5 1.5l7 3.5-7 3.5V1.5Z"})})}),e.jsx(Z,{title:"Move up",onClick:R,t:i,children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M3.47 7.78a.75.75 0 0 1 0-1.06l4.25-4.25a.75.75 0 0 1 1.06 0l4.25 4.25a.75.75 0 0 1-1.06 1.06L8.75 4.81v7.44a.75.75 0 0 1-1.5 0V4.81L4.53 7.78a.75.75 0 0 1-1.06 0Z"})})}),e.jsx(Z,{title:"Move down",onClick:O,t:i,children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M12.53 8.22a.75.75 0 0 1 0 1.06l-4.25 4.25a.75.75 0 0 1-1.06 0L2.97 9.28a.75.75 0 0 1 1.06-1.06l2.72 2.97V3.75a.75.75 0 0 1 1.5 0v7.44l2.72-2.97a.75.75 0 0 1 1.06 0Z"})})}),e.jsx(Z,{title:"Delete cell",onClick:T,t:i,danger:!0,children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M11 1.75V3h2.25a.75.75 0 0 1 0 1.5H2.75a.75.75 0 0 1 0-1.5H5V1.75C5 .784 5.784 0 6.75 0h2.5C10.216 0 11 .784 11 1.75ZM4.496 6.675l.66 6.6a.25.25 0 0 0 .249.225h5.19a.25.25 0 0 0 .249-.225l.66-6.6a.75.75 0 0 1 1.492.149l-.66 6.6A1.748 1.748 0 0 1 10.595 15h-5.19a1.75 1.75 0 0 1-1.741-1.575l-.66-6.6a.75.75 0 1 1 1.492-.15ZM6.5 1.75V3h3V1.75a.25.25 0 0 0-.25-.25h-2.5a.25.25 0 0 0-.25.25Z"})})})]})]}),t.type==="markdown"?e.jsx(rn,{value:t.content,onChange:E,themeMode:n.themeMode}):e.jsx(je,{value:t.content,onChange:E,onRun:j,themeMode:n.themeMode}),z&&e.jsxs("div",{style:{borderTop:`1px solid ${i.cellBorder}`},children:[e.jsxs("div",{style:{height:28,display:"flex",alignItems:"center",padding:"0 12px",gap:10,borderBottom:t.result&&u?`1px solid ${i.cellBorder}`:"none",background:`${i.tableHeaderBg}60`},children:[t.result&&e.jsxs("span",{style:{fontSize:11,fontFamily:i.font,color:i.textMuted},children:[(t.result.rowCount??t.result.rows.length).toLocaleString()," rows",t.result.executionTime!==void 0&&e.jsxs(e.Fragment,{children:[" · ",t.result.executionTime<1e3?`${t.result.executionTime}ms`:`${(t.result.executionTime/1e3).toFixed(2)}s`]})]}),t.error&&e.jsx("span",{style:{fontSize:11,fontFamily:i.font,color:i.error},children:"Error"}),e.jsx("div",{style:{flex:1}}),t.result&&$&&u&&e.jsx("div",{style:{display:"flex",alignItems:"center",gap:3},children:["chart","table"].map(v=>e.jsx("button",{onClick:()=>m(v),style:{padding:"1px 7px",fontSize:10,fontFamily:i.font,borderRadius:3,border:`1px solid ${x===v?i.accent:i.btnBorder}`,background:x===v?`${i.accent}20`:"transparent",color:x===v?i.accent:i.textMuted,cursor:"pointer",transition:"all 0.15s",textTransform:"capitalize"},children:v==="chart"?"Chart":"Table"},v))}),e.jsxs("button",{onClick:()=>g(v=>!v),style:{background:"transparent",border:"none",cursor:"pointer",color:i.textMuted,fontSize:11,fontFamily:i.font,padding:"2px 4px",display:"flex",alignItems:"center",gap:4},children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"currentColor",style:{transform:u?"rotate(0deg)":"rotate(-90deg)",transition:"transform 0.15s"},children:e.jsx("path",{d:"M1 3l4 4 4-4",stroke:"currentColor",fill:"none",strokeWidth:"1.5"})}),u?"Hide":"Show"]})]}),u&&e.jsxs(e.Fragment,{children:[t.error&&e.jsx(yn,{message:t.error,themeMode:n.themeMode}),t.result&&!t.error&&(x==="chart"&&$?e.jsx(gn,{result:t.result,themeMode:n.themeMode}):e.jsx(we,{result:t.result,themeMode:n.themeMode}))]})]})]})]})}function Z({title:t,onClick:o,children:n,t:r,accent:i,danger:l}){const[a,s]=f.useState(!1);return e.jsx("button",{title:t,onClick:o,onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),style:{width:24,height:24,display:"flex",alignItems:"center",justifyContent:"center",background:a?l?`${r.error}18`:i?`${r.accent}18`:r.btnHover:"transparent",border:"none",borderRadius:4,cursor:"pointer",color:a?l?r.error:i?r.accent:r.textSecondary:r.textMuted,transition:"all 0.15s",padding:0},children:n})}const wn=[{type:"sql",label:"SQL",color:"#388bfd"},{type:"markdown",label:"Markdown",color:"#56d364"},{type:"dql",label:"DQL",color:"#e3b341"},{type:"param",label:"Param",color:"#e3b341"}];function ne({afterId:t}){const{state:o,dispatch:n}=w(),r=S[o.themeMode],[i,l]=f.useState(!1),[a,s]=f.useState(!1),c=f.useRef(null);f.useEffect(()=>{if(!a)return;function d(p){c.current&&!c.current.contains(p.target)&&s(!1)}return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[a]);const h=d=>{const p=A(d);n({type:"ADD_CELL",cell:p,afterId:t}),s(!1)};return e.jsxs("div",{ref:c,onMouseEnter:()=>l(!0),onMouseLeave:()=>{l(!1)},style:{position:"relative",height:28,display:"flex",alignItems:"center",justifyContent:"center",cursor:"default"},children:[e.jsx("div",{style:{position:"absolute",left:0,right:0,height:1,background:i||a?r.cellBorderActive:"transparent",transition:"background 0.15s"}}),(i||a)&&e.jsxs("button",{onClick:()=>s(d=>!d),style:{position:"relative",zIndex:2,height:22,padding:"0 10px",borderRadius:11,border:`1px solid ${r.cellBorderActive}`,background:`${r.accent}18`,color:r.accent,cursor:"pointer",fontSize:12,fontFamily:r.font,fontWeight:500,display:"flex",alignItems:"center",gap:4,transition:"background 0.15s"},children:[e.jsx("span",{style:{fontSize:14,lineHeight:1,marginTop:-1},children:"+"}),"Add cell"]}),a&&e.jsx("div",{style:{position:"absolute",top:26,left:"50%",transform:"translateX(-50%)",zIndex:100,background:r.modalBg,border:`1px solid ${r.cellBorder}`,borderRadius:8,boxShadow:"0 8px 24px rgba(0,0,0,0.3)",padding:4,display:"flex",gap:4},children:wn.map(({type:d,label:p,color:u})=>e.jsx(kn,{label:p,color:u,onClick:()=>h(d),t:r},d))})]})}function kn({label:t,color:o,onClick:n,t:r}){const[i,l]=f.useState(!1);return e.jsx("button",{onClick:n,onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),style:{background:i?`${o}18`:"transparent",border:`1px solid ${i?o:r.cellBorder}`,borderRadius:6,cursor:"pointer",color:i?o:r.textSecondary,fontSize:11,fontFamily:r.fontMono,fontWeight:600,padding:"4px 10px",letterSpacing:"0.04em",transition:"all 0.15s",whiteSpace:"nowrap"},children:t})}function En({registerCellRef:t}){const{state:o,dispatch:n}=w(),{executeCell:r}=ie(),i=S[o.themeMode],[l,a]=f.useState(null),s=f.useRef(0);return f.useCallback(c=>{a(c)},[]),f.useEffect(()=>{function c(h){var g;if(!l)return;const d=h.target;if(d.tagName==="TEXTAREA"||d.tagName==="INPUT"||d.isContentEditable||d.closest(".cm-editor")){a(null);return}const p=o.cells,u=p.findIndex(x=>x.id===l);if(u!==-1)switch(h.key){case"a":{h.preventDefault();const x=A("sql");if(u===0)n({type:"ADD_CELL",cell:x,afterId:p[0].id}),n({type:"MOVE_CELL",id:x.id,direction:"up"});else{const m=p[u-1].id;n({type:"ADD_CELL",cell:x,afterId:m})}a(x.id);break}case"b":{h.preventDefault();const x=A("sql");n({type:"ADD_CELL",cell:x,afterId:l}),a(x.id);break}case"d":{h.preventDefault();const x=Date.now();if(x-s.current<=500){if(n({type:"DELETE_CELL",id:l}),p.length>1){const m=u>0?u-1:1;a(((g=p[m])==null?void 0:g.id)??null)}else a(null);s.current=0}else s.current=x;break}case"Enter":{if(h.shiftKey){h.preventDefault();const x=p[u];x&&x.type!=="markdown"&&r(x.id)}break}}}return document.addEventListener("keydown",c),()=>document.removeEventListener("keydown",c)},[l,o.cells,n,r]),f.useEffect(()=>{function c(h){h.target.closest("[data-cell-id]")||a(null)}return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[]),o.cells.length===0?e.jsxs("div",{style:{maxWidth:1200,margin:"0 auto",padding:"0 24px",display:"flex",flexDirection:"column"},children:[e.jsx(ne,{}),e.jsx(Cn,{t:i})]}):e.jsxs("div",{style:{maxWidth:1200,margin:"0 auto",padding:"0 24px",display:"flex",flexDirection:"column"},children:[e.jsx(ne,{afterId:void 0}),o.cells.map((c,h)=>e.jsxs(Q.Fragment,{children:[e.jsx("div",{ref:d=>t(c.id,d),"data-cell-id":c.id,onClick:d=>{const p=d.target;!p.closest(".cm-editor")&&!p.closest("textarea")&&!p.closest("input")&&a(c.id)},style:{outline:l===c.id?`2px solid ${i.accent}40`:"none",outlineOffset:2,borderRadius:10,transition:"outline 0.1s"},children:e.jsx(jn,{cell:c,index:h})}),e.jsx(ne,{afterId:c.id})]},c.id))]})}function Cn({t}){return e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"48px 0",gap:12,color:t.textMuted},children:[e.jsx("svg",{width:"40",height:"40",viewBox:"0 0 16 16",fill:"currentColor",style:{opacity:.3},children:e.jsx("path",{d:"M2 1.75C2 .784 2.784 0 3.75 0h6.586c.464 0 .909.184 1.237.513l2.914 2.914c.329.328.513.773.513 1.237v9.586A1.75 1.75 0 0 1 13.25 16h-9.5A1.75 1.75 0 0 1 2 14.25Zm1.75-.25a.25.25 0 0 0-.25.25v12.5c0 .138.112.25.25.25h9.5a.25.25 0 0 0 .25-.25V6h-2.75A1.75 1.75 0 0 1 8.75 4.25V1.5ZM8.75 5.5h2.836L10.25 3.664V4.25c0 .138.112.25.25.25H8.75Z"})}),e.jsx("span",{style:{fontSize:13,fontFamily:t.font},children:"Empty notebook. Click + to add your first cell."})]})}function Mn({onOpenFile:t,registerCellRef:o}){const{state:n}=w(),r=S[n.themeMode];return n.activeFile?e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",background:r.appBg},children:[e.jsx(Ln,{t:r}),e.jsx("div",{style:{flex:1,overflow:"auto",padding:"24px 0 40px"},children:e.jsx(En,{registerCellRef:o})})]}):e.jsx(Kt,{onOpenFile:t})}function Ln({t}){const{state:o}=w(),n=o.cells.length;return e.jsxs("div",{style:{height:32,flexShrink:0,borderBottom:`1px solid ${t.headerBorder}`,background:t.cellBg,display:"flex",alignItems:"center",padding:"0 16px",gap:12},children:[e.jsx(Bn,{t}),e.jsx("div",{style:{flex:1}}),e.jsxs("span",{style:{fontSize:11,color:t.textMuted,fontFamily:t.font,display:"flex",alignItems:"center",gap:12},children:[e.jsxs("span",{children:[n," ",n===1?"cell":"cells"]}),o.notebookDirty&&e.jsx("span",{style:{color:t.warning},children:"● unsaved"})]})]})}function Bn({t}){const{state:o}=w();if(!o.activeFile)return null;const n=o.activeFile.path.split("/").filter(Boolean);return e.jsx("div",{style:{display:"flex",alignItems:"center",gap:4,fontSize:12,fontFamily:t.fontMono,color:t.textMuted,overflow:"hidden"},children:n.map((r,i)=>e.jsxs(Q.Fragment,{children:[i>0&&e.jsx("span",{style:{color:t.textMuted,opacity:.5},children:"/"}),e.jsx("span",{style:{color:i===n.length-1?t.textSecondary:t.textMuted,fontWeight:i===n.length-1?500:400,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:i===n.length-1?200:100},children:r})]},i))})}const me={blank:"Blank",revenue:"Revenue Analysis",pipeline:"Pipeline Health"},Tn={blank:"Start with an empty notebook.",revenue:"Pre-built queries for revenue metrics and trends.",pipeline:"Templates for data pipeline health monitoring."};function ye(t){return t.toLowerCase().replace(/[^a-z0-9\-_\s]/g,"").replace(/\s+/g,"-").replace(/-+/g,"-").slice(0,64)}function Rn(t){return t.trim()?/^[a-zA-Z0-9\-_ ]+$/.test(t)?null:"Only letters, numbers, hyphens, underscores, and spaces allowed.":"Name is required."}function An(t){switch(t){case"revenue":return[A("markdown",`# Revenue Analysis
265
-
266
- This notebook analyzes revenue metrics and trends over time.`),{...A("sql",`SELECT
267
- DATE_TRUNC('month', order_date) AS month,
268
- SUM(amount) AS revenue
269
- FROM orders
270
- GROUP BY 1
271
- ORDER BY 1`),name:"monthly_revenue"},{...A("sql",`SELECT
272
- product_category,
273
- SUM(amount) AS total_revenue,
274
- COUNT(*) AS orders
275
- FROM orders
276
- GROUP BY 1
277
- ORDER BY 2 DESC`),name:"revenue_by_category"}];case"pipeline":return[A("markdown",`# Pipeline Health
278
-
279
- Monitor data pipeline performance, SLA compliance, and error rates.`),{...A("sql",`SELECT
280
- pipeline_name,
281
- COUNT(*) AS runs,
282
- AVG(duration_seconds) AS avg_duration,
283
- SUM(CASE WHEN status = 'failed' THEN 1 ELSE 0 END) AS failures
284
- FROM pipeline_runs
285
- GROUP BY 1
286
- ORDER BY 4 DESC`),name:"pipeline_summary"},{...A("sql",`SELECT
287
- *
288
- FROM pipeline_runs
289
- WHERE status = 'failed'
290
- AND run_date >= CURRENT_DATE - INTERVAL '7 days'
291
- ORDER BY run_date DESC`),name:"recent_failures"}];default:return[A("sql")]}}function On({onFileOpened:t}){const{state:o,dispatch:n}=w(),r=S[o.themeMode],[i,l]=f.useState(""),[a,s]=f.useState("blank"),[c,h]=f.useState(null),[d,p]=f.useState(!1),u=f.useRef(null);f.useEffect(()=>{var m;(m=u.current)==null||m.focus()},[]),f.useEffect(()=>{const m=y=>{y.key==="Escape"&&n({type:"CLOSE_NEW_NOTEBOOK_MODAL"})};return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[n]);const g=async()=>{const m=Rn(i);if(m){h(m);return}p(!0),h(null);const y=ye(i),k=An(a);try{const j=await B.createNotebook(y,a),E={name:`${y}.dqlnb`,path:j.path,type:"notebook",folder:"notebooks",isNew:!0};n({type:"FILE_ADDED",file:E}),n({type:"OPEN_FILE",file:E,cells:k,title:i.trim()}),n({type:"CLOSE_NEW_NOTEBOOK_MODAL"}),t(E)}catch{const j=`notebooks/${y}.dqlnb`,E={name:`${y}.dqlnb`,path:j,type:"notebook",folder:"notebooks",isNew:!0};n({type:"FILE_ADDED",file:E}),n({type:"OPEN_FILE",file:E,cells:k,title:i.trim()}),n({type:"CLOSE_NEW_NOTEBOOK_MODAL"}),t(E)}finally{p(!1)}},x=m=>{m.target===m.currentTarget&&n({type:"CLOSE_NEW_NOTEBOOK_MODAL"})};return e.jsx("div",{onClick:x,style:{position:"fixed",inset:0,background:r.modalOverlay,display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3,backdropFilter:"blur(4px)"},children:e.jsxs("div",{style:{background:r.modalBg,border:`1px solid ${r.cellBorder}`,borderRadius:12,width:480,maxWidth:"calc(100vw - 48px)",boxShadow:"0 20px 60px rgba(0,0,0,0.5)",overflow:"hidden"},children:[e.jsxs("div",{style:{padding:"20px 24px 0",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx("h2",{style:{fontSize:16,fontWeight:600,color:r.textPrimary,fontFamily:r.font,margin:0},children:"New Notebook"}),e.jsx("button",{onClick:()=>n({type:"CLOSE_NEW_NOTEBOOK_MODAL"}),style:{background:"transparent",border:"none",cursor:"pointer",color:r.textMuted,fontSize:18,lineHeight:1,padding:"2px 4px",borderRadius:4},children:"×"})]}),e.jsxs("div",{style:{padding:"20px 24px 24px",display:"flex",flexDirection:"column",gap:20},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[e.jsx("label",{style:{fontSize:12,fontWeight:500,color:r.textSecondary,fontFamily:r.font},children:"Name"}),e.jsx("input",{ref:u,value:i,onChange:m=>{l(m.target.value),h(null)},onKeyDown:m=>{m.key==="Enter"&&g()},placeholder:"my-analysis",style:{background:r.inputBg,border:`1px solid ${c?r.error:r.inputBorder}`,borderRadius:6,color:r.textPrimary,fontSize:13,fontFamily:r.font,padding:"8px 12px",outline:"none",transition:"border-color 0.15s"}}),c&&e.jsx("span",{style:{fontSize:11,color:r.error,fontFamily:r.font},children:c}),i&&!c&&e.jsxs("span",{style:{fontSize:11,color:r.textMuted,fontFamily:r.fontMono},children:["File: ",ye(i),".dqlnb"]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[e.jsx("label",{style:{fontSize:12,fontWeight:500,color:r.textSecondary,fontFamily:r.font},children:"Template"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:Object.keys(me).map(m=>e.jsx(_n,{value:m,selected:a===m,onSelect:()=>s(m),label:me[m],description:Tn[m],t:r},m))})]})]}),e.jsxs("div",{style:{padding:"14px 24px",borderTop:`1px solid ${r.cellBorder}`,display:"flex",justifyContent:"flex-end",gap:10},children:[e.jsx("button",{onClick:()=>n({type:"CLOSE_NEW_NOTEBOOK_MODAL"}),style:{background:r.btnBg,border:`1px solid ${r.btnBorder}`,borderRadius:6,color:r.textSecondary,cursor:"pointer",fontSize:13,fontFamily:r.font,fontWeight:500,padding:"7px 16px"},children:"Cancel"}),e.jsx("button",{onClick:g,disabled:d||!i.trim(),style:{background:r.accent,border:`1px solid ${r.accent}`,borderRadius:6,color:"#ffffff",cursor:d||!i.trim()?"not-allowed":"pointer",fontSize:13,fontFamily:r.font,fontWeight:500,padding:"7px 20px",opacity:d||!i.trim()?.6:1,display:"flex",alignItems:"center",gap:6},children:d?"Creating…":"Create Notebook"})]})]})})}function _n({value:t,selected:o,onSelect:n,label:r,description:i,t:l}){const[a,s]=f.useState(!1);return e.jsxs("div",{onClick:n,onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),style:{display:"flex",alignItems:"flex-start",gap:10,padding:"10px 12px",borderRadius:8,border:`1px solid ${o?l.cellBorderActive:a?l.textMuted:l.inputBorder}`,background:o?`${l.cellBorderActive}10`:a?l.sidebarItemHover:"transparent",cursor:"pointer",transition:"all 0.15s"},children:[e.jsx("div",{style:{width:16,height:16,borderRadius:8,border:`2px solid ${o?l.accent:l.textMuted}`,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,marginTop:1,transition:"border-color 0.15s"},children:o&&e.jsx("div",{style:{width:8,height:8,borderRadius:4,background:l.accent}})}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:13,fontWeight:500,color:l.textPrimary,fontFamily:l.font,marginBottom:2},children:r}),e.jsx("div",{style:{fontSize:12,color:l.textSecondary,fontFamily:l.font},children:i})]})]})}function Fn(){const{state:t,dispatch:o}=w(),n=S[t.themeMode],r=f.useRef({}),i=f.useCallback(async s=>{try{const{content:c}=await B.readNotebook(s.path),{title:h,cells:d}=Tt(s.path,c);o({type:"OPEN_FILE",file:s,cells:d,title:h}),t.sidebarPanel!=="files"&&o({type:"SET_SIDEBAR_PANEL",panel:"files"})}catch(c){console.error("Failed to open file:",c),o({type:"OPEN_FILE",file:s,cells:[A("sql")],title:s.name})}},[o,t.sidebarPanel]),l=f.useCallback(s=>{const c=r.current[s];c&&c.scrollIntoView({behavior:"smooth",block:"start"})},[]),a=f.useCallback((s,c)=>{c?r.current[s]=c:delete r.current[s]},[]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100vh",width:"100vw",background:n.appBg,fontFamily:n.font,color:n.textPrimary,overflow:"hidden"},children:[e.jsx(Zt,{}),e.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[e.jsx(nt,{}),t.sidebarOpen&&e.jsx(Ct,{onOpenFile:i,onNavigateToCell:l}),e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minWidth:0},children:[e.jsx(Mn,{onOpenFile:i,registerCellRef:a}),e.jsx(Gt,{})]})]}),t.newNotebookModalOpen&&e.jsx(On,{onFileOpened:i})]})}function Dn(){const{state:t,dispatch:o}=w(),n=f.useRef(null),r=f.useRef(null);f.useEffect(()=>{var i;n.current=((i=t.activeFile)==null?void 0:i.path)??null},[t.activeFile]),f.useEffect(()=>{if(typeof EventSource>"u")return;const i=()=>{const l=new EventSource(`${window.location.origin}/api/watch`);r.current=l,l.addEventListener("change",a=>{try{const s=JSON.parse(a.data);(s.type==="file-added"||s.type==="file-deleted")&&B.listNotebooks().then(c=>{o({type:"SET_FILES",files:c})}),s.type==="file-changed"&&B.listNotebooks().then(c=>{o({type:"SET_FILES",files:c})})}catch{}}),l.addEventListener("error",()=>{l.close(),setTimeout(i,5e3)})};return i(),()=>{var l;(l=r.current)==null||l.close(),r.current=null}},[o])}function $n(){const{state:t,dispatch:o}=w(),n=S[t.themeMode];return f.useEffect(()=>{const r="dql-global-styles";let i=document.getElementById(r);i||(i=document.createElement("style"),i.id=r,document.head.appendChild(i)),i.textContent=`
292
- * { margin: 0; padding: 0; box-sizing: border-box; }
293
- body {
294
- font-family: ${n.font};
295
- overflow: hidden;
296
- background: ${n.appBg};
297
- color: ${n.textPrimary};
298
- }
299
- ::-webkit-scrollbar { width: 6px; height: 6px; }
300
- ::-webkit-scrollbar-track { background: transparent; }
301
- ::-webkit-scrollbar-thumb {
302
- background: ${n.scrollbarThumb};
303
- border-radius: 3px;
304
- }
305
- ::-webkit-scrollbar-thumb:hover {
306
- background: ${n.textMuted};
307
- }
308
- ::selection {
309
- background: ${n.accent}40;
310
- color: ${n.textPrimary};
311
- }
312
- `},[n]),f.useEffect(()=>{o({type:"SET_FILES_LOADING",loading:!0}),B.listNotebooks().then(r=>{o({type:"SET_FILES",files:r}),o({type:"SET_FILES_LOADING",loading:!1})})},[o]),f.useEffect(()=>{o({type:"SET_SCHEMA_LOADING",loading:!0}),B.getSchema().then(r=>{o({type:"SET_SCHEMA",tables:r}),o({type:"SET_SCHEMA_LOADING",loading:!1})})},[o]),Dn(),e.jsx(Fn,{})}function In(){return e.jsx(Ve,{children:e.jsx($n,{})})}We.createRoot(document.getElementById("root")).render(e.jsx(In,{}));